diff --git a/.gitignore b/.gitignore index 5f1e24109df622591bdd31536d0316d2bb2c5450..65e03e1933b6aa23718c9e58cc193794a19564ea 100644 --- a/.gitignore +++ b/.gitignore @@ -127,4 +127,5 @@ tools/THANKS tools/NEWS tools/COPYING tools/BUGS -tools/taos-tools \ No newline at end of file +tools/taos-tools +tools/taosws-rs diff --git a/cmake/cmake.define b/cmake/cmake.define index 5d64815a9aa90741a0d6aca7e51518d2263932a2..78eab0a59ad091bbded966700f5d734dd5412321 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -117,8 +117,8 @@ ELSE () SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-literal-suffix -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=shift-base -fno-sanitize=alignment -g3 -Wformat=0") MESSAGE(STATUS "Will compile with Address Sanitizer!") ELSE () - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3 -Wformat=0") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-literal-suffix -Werror=return-type -fPIC -gdwarf-2 -g3 -Wformat=0") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3 -Wformat=2 -Wno-format-nonliteral -Wno-format-truncation -Wno-format-y2k") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-literal-suffix -Werror=return-type -fPIC -gdwarf-2 -g3 -Wformat=2 -Wno-format-nonliteral -Wno-format-truncation -Wno-format-y2k") ENDIF () MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}") diff --git a/cmake/cmake.version b/cmake/cmake.version index 05094f10cccea02ecb6a9cc4b9283335cb4424b6..1a83126cd7d1ce3257cc6d3c811bd4e2f49a0371 100644 --- a/cmake/cmake.version +++ b/cmake/cmake.version @@ -2,7 +2,7 @@ IF (DEFINED VERNUMBER) SET(TD_VER_NUMBER ${VERNUMBER}) ELSE () - SET(TD_VER_NUMBER "3.0.1.4") + SET(TD_VER_NUMBER "3.0.1.5") ENDIF () IF (DEFINED VERCOMPATIBLE) diff --git a/cmake/taostools_CMakeLists.txt.in b/cmake/taostools_CMakeLists.txt.in index 49e94896cdf82516b6c5b4a7240a347c2217b2b5..c19928c7a917aa4f2da8014f53168d29626087a3 100644 --- a/cmake/taostools_CMakeLists.txt.in +++ b/cmake/taostools_CMakeLists.txt.in @@ -2,7 +2,7 @@ # taos-tools ExternalProject_Add(taos-tools GIT_REPOSITORY https://github.com/taosdata/taos-tools.git - GIT_TAG 9284147 + GIT_TAG cc973e0 SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools" BINARY_DIR "" #BUILD_IN_SOURCE TRUE diff --git a/cmake/taosws_CMakeLists.txt.in b/cmake/taosws_CMakeLists.txt.in index ca8fff8da511ef86baa699af8246822d91982238..67a23b32b0a7390c2087666a0af71754d07bb56f 100644 --- a/cmake/taosws_CMakeLists.txt.in +++ b/cmake/taosws_CMakeLists.txt.in @@ -2,7 +2,7 @@ # taosws-rs ExternalProject_Add(taosws-rs GIT_REPOSITORY https://github.com/taosdata/taos-connector-rust.git - GIT_TAG 1bdfca3 + GIT_TAG 0373a70 SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosws-rs" BINARY_DIR "" #BUILD_IN_SOURCE TRUE diff --git a/docs/en/12-taos-sql/05-insert.md b/docs/en/12-taos-sql/05-insert.md index da21896866d74c141b933f85cbe87952f53c7fc4..9141211db5239cb6a035f4a01a831adf9f50aa77 100644 --- a/docs/en/12-taos-sql/05-insert.md +++ b/docs/en/12-taos-sql/05-insert.md @@ -108,11 +108,11 @@ INSERT INTO d21001 USING meters TAGS ('California.SanFrancisco', 2) VALUES ('202 ## Insert Rows From A File -Besides using `VALUES` to insert one or multiple rows, the data to be inserted can also be prepared in a CSV file with comma as separator and each field value quoted by single quotes. Table definition is not required in the CSV file. For example, if file "/tmp/csvfile.csv" contains the below data: +Besides using `VALUES` to insert one or multiple rows, the data to be inserted can also be prepared in a CSV file with comma as separator and timestamp and string field value quoted by single quotes. Table definition is not required in the CSV file. For example, if file "/tmp/csvfile.csv" contains the below data: ``` -'2021-07-13 14:07:34.630', '10.2', '219', '0.32' -'2021-07-13 14:07:35.779', '10.15', '217', '0.33' +'2021-07-13 14:07:34.630', 10.2, 219, 0.32 +'2021-07-13 14:07:35.779', 10.15, 217, 0.33 ``` Then data in this file can be inserted by the SQL statement below: diff --git a/docs/en/12-taos-sql/10-function.md b/docs/en/12-taos-sql/10-function.md index 48bc5e743e5b79b476be1f6c2e14acdbe3b94b27..6145d8c00c97a411699f7decf731399c238ff84e 100644 --- a/docs/en/12-taos-sql/10-function.md +++ b/docs/en/12-taos-sql/10-function.md @@ -863,6 +863,7 @@ INTERP(expr) - `INTERP` is used to get the value that matches the specified time slice from a column. If no such value exists an interpolation value will be returned based on `FILL` parameter. - The input data of `INTERP` is the value of the specified column and a `where` clause can be used to filter the original data. If no `where` condition is specified then all original data is the input. +- `INTERP` must be used along with `RANGE`, `EVERY`, `FILL` keywords. - The output time range of `INTERP` is specified by `RANGE(timestamp1,timestamp2)` parameter, with timestamp1<=timestamp2. timestamp1 is the starting point of the output time range and must be specified. timestamp2 is the ending point of the output time range and must be specified. - The number of rows in the result set of `INTERP` is determined by the parameter `EVERY`. Starting from timestamp1, one interpolation is performed for every time interval specified `EVERY` parameter. The parameter `EVERY` must be an integer, with no quotes, with a time unit of: b(nanosecond), u(microsecond), a(millisecond)), s(second), m(minute), h(hour), d(day), or w(week). For example, `EVERY(500a)` will interpolate every 500 milliseconds. - Interpolation is performed based on `FILL` parameter. diff --git a/docs/en/12-taos-sql/21-node.md b/docs/en/12-taos-sql/21-node.md index 81a7931cbfbc25d7be5f6cadd345631c4145bd7f..d9d06a00a4ab3d6b836239c1054db6c238ab16b5 100644 --- a/docs/en/12-taos-sql/21-node.md +++ b/docs/en/12-taos-sql/21-node.md @@ -64,6 +64,12 @@ dnode_option: { The parameters that you can modify through this statement are the same as those located in the dnode configuration file. Modifications that you make through this statement take effect immediately, while modifications to the configuration file take effect when the dnode restarts. +`value` is the value of the parameter, which needs to be in character format. For example, modify the log output level of dnode 1 to debug: + +```sql +ALTER DNODE 1 'debugFlag' '143'; +``` + ## Add an Mnode ```sql diff --git a/docs/en/14-reference/05-taosbenchmark.md b/docs/en/14-reference/05-taosbenchmark.md index 6295d8553d54033ee08413696d45503416394f27..b114f92a41241bd21f5dc7ca5ea5709b8c2ffbd3 100644 --- a/docs/en/14-reference/05-taosbenchmark.md +++ b/docs/en/14-reference/05-taosbenchmark.md @@ -112,6 +112,9 @@ taosBenchmark -f - **-u/--user ** : User name to connect to the TDengine server. Default is root. +- **-U/--supplement-insert ** : + Supplementally insert data without create database and table, optional, default is off. + - **-p/--password ** : The default password to connect to the TDengine server is `taosdata`. @@ -148,6 +151,9 @@ taosBenchmark -f - **-l/--columns ** : specify the number of columns in the super table. If both this parameter and `-b/--data-type` is set, the final result number of columns is the greater of the two. If the number specified by this parameter is greater than the number of columns specified by `-b/--data-type`, the unspecified column type defaults to INT, for example: `-l 5 -b float,double`, then the final column is `FLOAT,DOUBLE,INT,INT,INT`. If the number of columns specified is less than or equal to the number of columns specified by `-b/--data-type`, then the result is the column and type specified by `-b/--data-type`, e.g.: `-l 3 -b float,double,float,bigint`. The last column is `FLOAT,DOUBLE, FLOAT,BIGINT`. +- **-L/--partial-col-num ** : + Specify first numbers of columns has data. Rest of columns' data are NULL. Default is all columns have data. + - **-A/--tag-type ** : The tag column type of the super table. nchar and binary types can both set the length, for example: diff --git a/docs/en/28-releases/01-tdengine.md b/docs/en/28-releases/01-tdengine.md index 808a21474ebc843b2e6b6081507b64c510f79797..14096bd40011ef514b522fe29060c85a69ab0670 100644 --- a/docs/en/28-releases/01-tdengine.md +++ b/docs/en/28-releases/01-tdengine.md @@ -6,6 +6,10 @@ description: TDengine release history, Release Notes and download links. import Release from "/components/ReleaseV3"; +## 3.0.1.5 + + + ## 3.0.1.4 diff --git a/docs/en/28-releases/02-tools.md b/docs/en/28-releases/02-tools.md index 5d6693ae73dbe9348c6dcfad6f88ed1602acd957..a7446be4e39489e02e333f03c2c4f6f47503617a 100644 --- a/docs/en/28-releases/02-tools.md +++ b/docs/en/28-releases/02-tools.md @@ -6,6 +6,10 @@ description: taosTools release history, Release Notes, download links. import Release from "/components/ReleaseV3"; +## 2.2.6 + + + ## 2.2.4 diff --git a/docs/zh/07-develop/07-tmq.mdx b/docs/zh/07-develop/07-tmq.mdx index d9a35ab4eb545872a0f9a8e10e6e40dcf6ee4ec7..1f5a089aaa2a051e238eedc0315c37cad643b33f 100644 --- a/docs/zh/07-develop/07-tmq.mdx +++ b/docs/zh/07-develop/07-tmq.mdx @@ -247,7 +247,7 @@ CREATE TOPIC topic_name as subquery - 该类型 TOPIC 一旦创建则订阅数据的结构确定。 - 被订阅或用于计算的列或标签不可被删除(`ALTER table DROP`)、修改(`ALTER table MODIFY`)。 -- 若发生表结构变更,新增的列不出现在结果中,若发生列删除则会报错。 +- 若发生表结构变更,新增的列不出现在结果中。 ### 超级表订阅 @@ -269,10 +269,10 @@ CREATE TOPIC topic_name AS STABLE stb_name 语法: ```sql -CREATE TOPIC topic_name [WITH META] AS DATABASE db_name; +CREATE TOPIC topic_name AS DATABASE db_name; ``` -通过该语句可创建一个包含数据库所有表数据的订阅,`WITH META` 可选择将数据库结构变动信息加入到订阅消息流,TMQ 将消费当前数据库下所有表结构的变动,包括超级表的创建与删除,列添加、删除或修改,子表的创建、删除及 TAG 变动信息等等。消费者可通过 API 来判断具体的消息类型。这一点也是与 Kafka 不同的地方。 +通过该语句可创建一个包含数据库所有表数据的订阅 ## 创建消费者 *consumer* @@ -282,16 +282,16 @@ CREATE TOPIC topic_name [WITH META] AS DATABASE db_name; | :----------------------------: | :-----: | -------------------------------------------------------- | ------------------------------------------- | | `td.connect.ip` | string | 用于创建连接,同 `taos_connect` | | | `td.connect.user` | string | 用于创建连接,同 `taos_connect` | | -| `td.connect.pass` | string | 用于创建连接,同 `taos_connect` | -| `td.connect.port` | integer | 用于创建连接,同 `taos_connect` | +| `td.connect.pass` | string | 用于创建连接,同 `taos_connect` | | +| `td.connect.port` | integer | 用于创建连接,同 `taos_connect` | | | `group.id` | string | 消费组 ID,同一消费组共享消费进度 | **必填项**。最大长度:192。 | | `client.id` | string | 客户端 ID | 最大长度:192。 | -| `auto.offset.reset` | enum | 消费组订阅的初始位置 | 可选:`earliest`, `latest`, `none`(default) | -| `enable.auto.commit` | boolean | 启用自动提交 | 合法值:`true`, `false`。 | -| `auto.commit.interval.ms` | integer | 以毫秒为单位的自动提交时间间隔 | -| `enable.heartbeat.background` | boolean | 启用后台心跳,启用后即使长时间不 poll 消息也不会造成离线 | | -| `experimental.snapshot.enable` | boolean | 从 WAL 开始消费,还是从 TSBS 开始消费 | | -| `msg.with.table.name` | boolean | 是否允许从消息中解析表名 | +| `auto.offset.reset` | enum | 消费组订阅的初始位置 | 可选:`earliest`(default), `latest`, `none` | +| `enable.auto.commit` | boolean | 是否启用消费位点自动提交 | 合法值:`true`, `false`。 | +| `auto.commit.interval.ms` | integer | 以毫秒为单位的消费记录自动提交消费位点时间间 | 默认 5000 m | +| `enable.heartbeat.background` | boolean | 启用后台心跳,启用后即使长时间不 poll 消息也不会造成离线 | 默认开启 | +| `experimental.snapshot.enable` | boolean | 是否允许从 TSDB 消费数据 | 实验功能,默认关闭 | +| `msg.with.table.name` | boolean | 是否允许从消息中解析表名, 不适用于列订阅(列订阅时可将 tbname 作为列写入 subquery 语句) | | 对于不同编程语言,其设置方式如下: @@ -420,7 +420,18 @@ let mut consumer = tmq.build()?; -Python 使用以下配置项创建一个 Consumer 实例。 +Python 语言下引入 `taos` 库的 `TaosConsumer` 类,创建一个 Consumer 示例: + +```python +from taos.tmq import TaosConsumer + +# Syntax: `consumer = TaosConsumer(*topics, **args)` +# +# Example: +consumer = TaosConsumer('topic1', 'topic2', td_connect_ip = "127.0.0.1", group_id = "local") +``` + +其中,元组类型参数被视为 *Topics*,字典类型参数用于以下订阅配置设置: | 参数名称 | 类型 | 参数说明 | 备注 | | :----------------------------: | :----: | -------------------------------------------------------- | ------------------------------------------- | @@ -430,13 +441,13 @@ Python 使用以下配置项创建一个 Consumer 实例。 | `td_connect_port` | string | 用于创建连接,同 `taos_connect` | | | `group_id` | string | 消费组 ID,同一消费组共享消费进度 | **必填项**。最大长度:192。 | | `client_id` | string | 客户端 ID | 最大长度:192。 | -| `auto_offset_reset` | string | 消费组订阅的初始位置 | 可选:`earliest`, `latest`, `none`(default) | -| `enable_auto_commit` | string | 启用自动提交 | 合法值:`true`, `false`。 | -| `auto_commit_interval_ms` | string | 以毫秒为单位的自动提交时间间隔 | | +| `auto_offset_reset` | string | 消费组订阅的初始位置 | 可选:`earliest`(default), `latest`, `none` | +| `enable_auto_commit` | string | 启用自动提交 | 合法值:`true`, `false`,默认为 true | +| `auto_commit_interval_ms` | string | 以毫秒为单位的自动提交时间间隔 | 默认值:5000 ms | | `enable_heartbeat_background` | string | 启用后台心跳,启用后即使长时间不 poll 消息也不会造成离线 | 合法值:`true`, `false` | -| `experimental_snapshot_enable` | string | 从 WAL 开始消费,还是从 TSBS 开始消费 | 合法值:`true`, `false` | -| `msg_with_table_name` | string | 是否允许从消息中解析表名 | 合法值:`true`, `false` | -| `timeout` | int | 消费者拉去的超时时间 | | +| `experimental_snapshot_enable` | string | 是否允许从 TSDB 消费数据 | 合法值:`true`, `false` | +| `msg_with_table_name` | string | 是否允许从消息中解析表名,不适用于列订阅 | 合法值:`true`, `false` | +| `timeout` | int | 消费者拉取数据的超时时间 | | diff --git a/docs/zh/12-taos-sql/05-insert.md b/docs/zh/12-taos-sql/05-insert.md index 5e64827a8f13cd9fd5de1f27129ad4859ad3cd27..ccb8f40b21f7f0082f7bf420643e88a618d83f0e 100644 --- a/docs/zh/12-taos-sql/05-insert.md +++ b/docs/zh/12-taos-sql/05-insert.md @@ -109,11 +109,11 @@ INSERT INTO d21001 USING meters TAGS ('California.SanFrancisco', 2) VALUES ('202 ## 插入来自文件的数据记录 -除了使用 VALUES 关键字插入一行或多行数据外,也可以把要写入的数据放在 CSV 文件中(英文逗号分隔、英文单引号括住每个值)供 SQL 指令读取。其中 CSV 文件无需表头。例如,如果 /tmp/csvfile.csv 文件的内容为: +除了使用 VALUES 关键字插入一行或多行数据外,也可以把要写入的数据放在 CSV 文件中(英文逗号分隔、时间戳和字符串类型的值需要用英文单引号括住)供 SQL 指令读取。其中 CSV 文件无需表头。例如,如果 /tmp/csvfile.csv 文件的内容为: ``` -'2021-07-13 14:07:34.630', '10.2', '219', '0.32' -'2021-07-13 14:07:35.779', '10.15', '217', '0.33' +'2021-07-13 14:07:34.630', 10.2, 219, 0.32 +'2021-07-13 14:07:35.779', 10.15, 217, 0.33 ``` 那么通过如下指令可以把这个文件中的数据写入子表中: diff --git a/docs/zh/12-taos-sql/10-function.md b/docs/zh/12-taos-sql/10-function.md index e7ed74631d1b0a4395ec8647f450c10c2878d22f..68c7fe6f3082e06cd8539df32bbf5ac8bbce6cee 100644 --- a/docs/zh/12-taos-sql/10-function.md +++ b/docs/zh/12-taos-sql/10-function.md @@ -864,8 +864,9 @@ INTERP(expr) - INTERP 用于在指定时间断面获取指定列的记录值,如果该时间断面不存在符合条件的行数据,那么会根据 FILL 参数的设定进行插值。 - INTERP 的输入数据为指定列的数据,可以通过条件语句(where 子句)来对原始列数据进行过滤,如果没有指定过滤条件则输入为全部数据。 +- INTERP 需要同时与 RANGE,EVERY 和 FILL 关键字一起使用。 - INTERP 的输出时间范围根据 RANGE(timestamp1,timestamp2)字段来指定,需满足 timestamp1<=timestamp2。其中 timestamp1(必选值)为输出时间范围的起始值,即如果 timestamp1 时刻符合插值条件则 timestamp1 为输出的第一条记录,timestamp2(必选值)为输出时间范围的结束值,即输出的最后一条记录的 timestamp 不能大于 timestamp2。 -- INTERP 根据 EVERY 字段来确定输出时间范围内的结果条数,即从 timestamp1 开始每隔固定长度的时间(EVERY 值)进行插值。如果没有指定 EVERY,则默认窗口大小为无穷大,即从 timestamp1 开始只有一个窗口。 +- INTERP 根据 EVERY 字段来确定输出时间范围内的结果条数,即从 timestamp1 开始每隔固定长度的时间(EVERY 值)进行插值。 - INTERP 根据 FILL 字段来决定在每个符合输出条件的时刻如何进行插值。 - INTERP 只能在一个时间序列内进行插值,因此当作用于超级表时必须跟 partition by tbname 一起使用。 - INTERP 可以与伪列 _irowts 一起使用,返回插值点所对应的时间戳(3.0.1.4版本以后支持)。 diff --git a/docs/zh/12-taos-sql/21-node.md b/docs/zh/12-taos-sql/21-node.md index ab6a49ea96ccaabb5a0f09a4a90d91835c2ef319..5b9279406ab6e96c57d59bcf7c4cd4193fb83058 100644 --- a/docs/zh/12-taos-sql/21-node.md +++ b/docs/zh/12-taos-sql/21-node.md @@ -65,6 +65,12 @@ dnode_option: { 上面语法中的这些可修改配置项其配置方式与 dnode 配置文件中的配置方式相同,区别是修改是动态的立即生效,且不需要重启 dnode。 +value 是参数的值,需要是字符格式。如修改 dnode 1 的日志输出级别为 debug: + +```sql +ALTER DNODE 1 'debugFlag' '143'; +``` + ## 添加管理节点 ```sql diff --git a/docs/zh/14-reference/05-taosbenchmark.md b/docs/zh/14-reference/05-taosbenchmark.md index e067c646b23db8080251ab7b51e693337436cfcc..afc050298f3be6c09fa0c09fbc3ba678cdd2e89d 100644 --- a/docs/zh/14-reference/05-taosbenchmark.md +++ b/docs/zh/14-reference/05-taosbenchmark.md @@ -112,6 +112,9 @@ taosBenchmark -f - **-u/--user ** : 用于连接 TDengine 服务端的用户名,默认为 root 。 +- **-U/--supplement-insert ** : + 写入数据而不提前建数据库和表,默认关闭。 + - **-p/--password ** : 用于连接 TDengine 服务端的密码,默认值为 taosdata。 @@ -148,6 +151,9 @@ taosBenchmark -f - **-l/--columns ** : 超级表的数据列的总数量。如果同时设置了该参数和 `-b/--data-type`,则最后的结果列数为两者取大。如果本参数指定的数量大于 `-b/--data-type` 指定的列数,则未指定的列类型默认为 INT, 例如: `-l 5 -b float,double`, 那么最后的列为 `FLOAT,DOUBLE,INT,INT,INT`。如果 columns 指定的数量小于或等于 `-b/--data-type` 指定的列数,则结果为 `-b/--data-type` 指定的列和类型,例如: `-l 3 -b float,double,float,bigint`,那么最后的列为 `FLOAT,DOUBLE,FLOAT,BIGINT` 。 +- **-L/--partial-col-num **: + 指定某些列写入数据,其他列数据为 NULL。默认所有列都写入数据。 + - **-A/--tag-type ** : 超级表的标签列类型。nchar 和 binary 类型可以同时设置长度,例如: diff --git a/docs/zh/14-reference/12-config/index.md b/docs/zh/14-reference/12-config/index.md index 8c19ac78f5762b96acc721aa92666f6218c2afca..74af793f9f7a6a5d0fb08a6b4980ed95c111ebf8 100644 --- a/docs/zh/14-reference/12-config/index.md +++ b/docs/zh/14-reference/12-config/index.md @@ -70,11 +70,11 @@ taos --dump-config ### serverPort -| 属性 | 说明 | -| -------- | ----------------------------------------------------------------------------------------------------------------------- | -| 适用范围 | 仅服务端适用 | -| 含义 | taosd 启动后,对外服务的端口号 | -| 缺省值 | 6030 | +| 属性 | 说明 | +| -------- | ------------------------------ | +| 适用范围 | 仅服务端适用 | +| 含义 | taosd 启动后,对外服务的端口号 | +| 缺省值 | 6030 | :::note 确保集群中所有主机在端口 6030 上的 TCP 协议能够互通。(详细的端口情况请参见下表) @@ -173,7 +173,6 @@ taos --dump-config 1: 表示使用 sma index,对符合的语句,直接从预计算的结果进行查询 | - ### maxNumOfDistinctRes | 属性 | 说明 | @@ -625,7 +624,7 @@ charset 的有效值是 UTF-8。 | 适用范围 | 仅客户端适用 | | 含义 | schemaless tag 为空时默认的 tag 名字 | | 类型 | 字符串 | -| 缺省值 | _tag_null | +| 缺省值 | \_tag_null | ### smlDataFormat @@ -658,173 +657,178 @@ charset 的有效值是 UTF-8。 | 缺省值 | 1 | ## 2.X 与 3.0 配置参数对比 -| # | **参数** | **适用于 2.X 版本** | **适用于 3.0 版本** | -| --- | :-----------------: | --------------- | --------------- | -| 1 | firstEp | 是 | 是 | -| 2 | secondEp | 是 | 是 | -| 3 | fqdn | 是 | 是 | -| 4 | serverPort | 是 | 是 | -| 5 | maxShellConns | 是 | 是 | -| 6 | monitor | 是 | 是 | -| 7 | monitorFqdn | 否 | 是 | -| 8 | monitorPort | 否 | 是 | -| 9 | monitorInterval | 是 | 是 | -| 10 | monitorMaxLogs | 否 | 是 | -| 11 | monitorComp | 否 | 是 | -| 12 | telemetryReporting | 是 | 是 | -| 13 | telemetryInterval | 否 | 是 | -| 14 | telemetryServer | 否 | 是 | -| 15 | telemetryPort | 否 | 是 | -| 16 | queryPolicy | 否 | 是 | -| 17 | querySmaOptimize | 否 | 是 | -| 18 | queryRsmaTolerance | 否 | 是 | -| 19 | queryBufferSize | 是 | 是 | -| 20 | maxNumOfDistinctRes | 是 | 是 | -| 21 | minSlidingTime | 是 | 是 | -| 22 | minIntervalTime | 是 | 是 | -| 23 | countAlwaysReturnValue | 是 | 是 | -| 24 | dataDir | 是 | 是 | -| 25 | minimalDataDirGB | 是 | 是 | -| 26 | supportVnodes | 否 | 是 | -| 27 | tempDir | 是 | 是 | -| 28 | minimalTmpDirGB | 是 | 是 | -| 29 | compressMsgSize | 是 | 是 | -| 30 | compressColData | 是 | 是 | -| 31 | smlChildTableName | 是 | 是 | -| 32 | smlTagName | 是 | 是 | -| 33 | smlDataFormat | 否 | 是 | -| 34 | statusInterval | 是 | 是 | -| 35 | shellActivityTimer | 是 | 是 | -| 36 | transPullupInterval | 否 | 是 | -| 37 | mqRebalanceInterval | 否 | 是 | -| 38 | ttlUnit | 否 | 是 | -| 39 | ttlPushInterval | 否 | 是 | -| 40 | numOfTaskQueueThreads | 否 | 是 | -| 41 | numOfRpcThreads | 否 | 是 | -| 42 | numOfCommitThreads | 是 | 是 | -| 43 | numOfMnodeReadThreads | 否 | 是 | -| 44 | numOfVnodeQueryThreads | 否 | 是 | -| 45 | numOfVnodeStreamThreads | 否 | 是 | -| 46 | numOfVnodeFetchThreads | 否 | 是 | -| 47 | numOfVnodeWriteThreads | 否 | 是 | -| 48 | numOfVnodeSyncThreads | 否 | 是 | -| 49 | numOfVnodeRsmaThreads | 否 | 是 | -| 50 | numOfQnodeQueryThreads | 否 | 是 | -| 51 | numOfQnodeFetchThreads | 否 | 是 | -| 52 | numOfSnodeSharedThreads | 否 | 是 | -| 53 | numOfSnodeUniqueThreads | 否 | 是 | -| 54 | rpcQueueMemoryAllowed | 否 | 是 | -| 55 | logDir | 是 | 是 | -| 56 | minimalLogDirGB | 是 | 是 | -| 57 | numOfLogLines | 是 | 是 | -| 58 | asyncLog | 是 | 是 | -| 59 | logKeepDays | 是 | 是 | -| 60 | debugFlag | 是 | 是 | -| 61 | tmrDebugFlag | 是 | 是 | -| 62 | uDebugFlag | 是 | 是 | -| 63 | rpcDebugFlag | 是 | 是 | -| 64 | jniDebugFlag | 是 | 是 | -| 65 | qDebugFlag | 是 | 是 | -| 66 | cDebugFlag | 是 | 是 | -| 67 | dDebugFlag | 是 | 是 | -| 68 | vDebugFlag | 是 | 是 | -| 69 | mDebugFlag | 是 | 是 | -| 70 | wDebugFlag | 是 | 是 | -| 71 | sDebugFlag | 是 | 是 | -| 72 | tsdbDebugFlag | 是 | 是 | -| 73 | tqDebugFlag | 否 | 是 | -| 74 | fsDebugFlag | 是 | 是 | -| 75 | udfDebugFlag | 否 | 是 | -| 76 | smaDebugFlag | 否 | 是 | -| 77 | idxDebugFlag | 否 | 是 | -| 78 | tdbDebugFlag | 否 | 是 | -| 79 | metaDebugFlag | 否 | 是 | -| 80 | timezone | 是 | 是 | -| 81 | locale | 是 | 是 | -| 82 | charset | 是 | 是 | -| 83 | udf | 是 | 是 | -| 84 | enableCoreFile | 是 | 是 | -| 85 | arbitrator | 是 | 否 | -| 86 | numOfThreadsPerCore | 是 | 否 | -| 87 | numOfMnodes | 是 | 否 | -| 88 | vnodeBak | 是 | 否 | -| 89 | balance | 是 | 否 | -| 90 | balanceInterval | 是 | 否 | -| 91 | offlineThreshold | 是 | 否 | -| 92 | role | 是 | 否 | -| 93 | dnodeNopLoop | 是 | 否 | -| 94 | keepTimeOffset | 是 | 否 | -| 95 | rpcTimer | 是 | 否 | -| 96 | rpcMaxTime | 是 | 否 | -| 97 | rpcForceTcp | 是 | 否 | -| 98 | tcpConnTimeout | 是 | 否 | -| 99 | syncCheckInterval | 是 | 否 | -| 100 | maxTmrCtrl | 是 | 否 | -| 101 | monitorReplica | 是 | 否 | -| 102 | smlTagNullName | 是 | 否 | -| 103 | keepColumnName | 是 | 否 | -| 104 | ratioOfQueryCores | 是 | 否 | -| 105 | maxStreamCompDelay | 是 | 否 | -| 106 | maxFirstStreamCompDelay | 是 | 否 | -| 107 | retryStreamCompDelay | 是 | 否 | -| 108 | streamCompDelayRatio | 是 | 否 | -| 109 | maxVgroupsPerDb | 是 | 否 | -| 110 | maxTablesPerVnode | 是 | 否 | -| 111 | minTablesPerVnode | 是 | 否 | -| 112 | tableIncStepPerVnode | 是 | 否 | -| 113 | cache | 是 | 否 | -| 114 | blocks | 是 | 否 | -| 115 | days | 是 | 否 | -| 116 | keep | 是 | 否 | -| 117 | minRows | 是 | 否 | -| 118 | maxRows | 是 | 否 | -| 119 | quorum | 是 | 否 | -| 120 | comp | 是 | 否 | -| 121 | walLevel | 是 | 否 | -| 122 | fsync | 是 | 否 | -| 123 | replica | 是 | 否 | -| 124 | partitions | 是 | 否 | -| 125 | quorum | 是 | 否 | -| 126 | update | 是 | 否 | -| 127 | cachelast | 是 | 否 | -| 128 | maxSQLLength | 是 | 否 | -| 129 | maxWildCardsLength | 是 | 否 | -| 130 | maxRegexStringLen | 是 | 否 | -| 131 | maxNumOfOrderedRes | 是 | 否 | -| 132 | maxConnections | 是 | 否 | -| 133 | mnodeEqualVnodeNum | 是 | 否 | -| 134 | http | 是 | 否 | -| 135 | httpEnableRecordSql | 是 | 否 | -| 136 | httpMaxThreads | 是 | 否 | -| 137 | restfulRowLimit | 是 | 否 | -| 138 | httpDbNameMandatory | 是 | 否 | -| 139 | httpKeepAlive | 是 | 否 | -| 140 | enableRecordSql | 是 | 否 | -| 141 | maxBinaryDisplayWidth | 是 | 否 | -| 142 | stream | 是 | 否 | -| 143 | retrieveBlockingModel | 是 | 否 | -| 144 | tsdbMetaCompactRatio | 是 | 否 | -| 145 | defaultJSONStrType | 是 | 否 | -| 146 | walFlushSize | 是 | 否 | -| 147 | keepTimeOffset | 是 | 否 | -| 148 | flowctrl | 是 | 否 | -| 149 | slaveQuery | 是 | 否 | -| 150 | adjustMaster | 是 | 否 | -| 151 | topicBinaryLen | 是 | 否 | -| 152 | telegrafUseFieldNum | 是 | 否 | -| 153 | deadLockKillQuery | 是 | 否 | -| 154 | clientMerge | 是 | 否 | -| 155 | sdbDebugFlag | 是 | 否 | -| 156 | odbcDebugFlag | 是 | 否 | -| 157 | httpDebugFlag | 是 | 否 | -| 158 | monDebugFlag | 是 | 否 | -| 159 | cqDebugFlag | 是 | 否 | -| 160 | shortcutFlag | 是 | 否 | -| 161 | probeSeconds | 是 | 否 | -| 162 | probeKillSeconds | 是 | 否 | -| 163 | probeInterval | 是 | 否 | -| 164 | lossyColumns | 是 | 否 | -| 165 | fPrecision | 是 | 否 | -| 166 | dPrecision | 是 | 否 | -| 167 | maxRange | 是 | 否 | -| 168 | range | 是 | 否 | + +:::note +对于 2.x 版本中适用但在 3.0 版本中废弃的参数,其当前行为会有特别说明 + +::: + +| # | **参数** | **适用于 2.X ** | **适用于 3.0 ** | 3.0 版本的当前行为 | +| --- | :---------------------: | --------------- | --------------- | ------------------------------------------------- | +| 1 | firstEp | 是 | 是 | | +| 2 | secondEp | 是 | 是 | | +| 3 | fqdn | 是 | 是 | | +| 4 | serverPort | 是 | 是 | | +| 5 | maxShellConns | 是 | 是 | | +| 6 | monitor | 是 | 是 | | +| 7 | monitorFqdn | 否 | 是 | | +| 8 | monitorPort | 否 | 是 | | +| 9 | monitorInterval | 是 | 是 | | +| 10 | monitorMaxLogs | 否 | 是 | | +| 11 | monitorComp | 否 | 是 | | +| 12 | telemetryReporting | 是 | 是 | | +| 13 | telemetryInterval | 否 | 是 | | +| 14 | telemetryServer | 否 | 是 | | +| 15 | telemetryPort | 否 | 是 | | +| 16 | queryPolicy | 否 | 是 | | +| 17 | querySmaOptimize | 否 | 是 | | +| 18 | queryRsmaTolerance | 否 | 是 | | +| 19 | queryBufferSize | 是 | 是 | | +| 20 | maxNumOfDistinctRes | 是 | 是 | | +| 21 | minSlidingTime | 是 | 是 | | +| 22 | minIntervalTime | 是 | 是 | | +| 23 | countAlwaysReturnValue | 是 | 是 | | +| 24 | dataDir | 是 | 是 | | +| 25 | minimalDataDirGB | 是 | 是 | | +| 26 | supportVnodes | 否 | 是 | | +| 27 | tempDir | 是 | 是 | | +| 28 | minimalTmpDirGB | 是 | 是 | | +| 29 | compressMsgSize | 是 | 是 | | +| 30 | compressColData | 是 | 是 | | +| 31 | smlChildTableName | 是 | 是 | | +| 32 | smlTagName | 是 | 是 | | +| 33 | smlDataFormat | 否 | 是 | | +| 34 | statusInterval | 是 | 是 | | +| 35 | shellActivityTimer | 是 | 是 | | +| 36 | transPullupInterval | 否 | 是 | | +| 37 | mqRebalanceInterval | 否 | 是 | | +| 38 | ttlUnit | 否 | 是 | | +| 39 | ttlPushInterval | 否 | 是 | | +| 40 | numOfTaskQueueThreads | 否 | 是 | | +| 41 | numOfRpcThreads | 否 | 是 | | +| 42 | numOfCommitThreads | 是 | 是 | | +| 43 | numOfMnodeReadThreads | 否 | 是 | | +| 44 | numOfVnodeQueryThreads | 否 | 是 | | +| 45 | numOfVnodeStreamThreads | 否 | 是 | | +| 46 | numOfVnodeFetchThreads | 否 | 是 | | +| 47 | numOfVnodeWriteThreads | 否 | 是 | | +| 48 | numOfVnodeSyncThreads | 否 | 是 | | +| 49 | numOfVnodeRsmaThreads | 否 | 是 | | +| 50 | numOfQnodeQueryThreads | 否 | 是 | | +| 51 | numOfQnodeFetchThreads | 否 | 是 | | +| 52 | numOfSnodeSharedThreads | 否 | 是 | | +| 53 | numOfSnodeUniqueThreads | 否 | 是 | | +| 54 | rpcQueueMemoryAllowed | 否 | 是 | | +| 55 | logDir | 是 | 是 | | +| 56 | minimalLogDirGB | 是 | 是 | | +| 57 | numOfLogLines | 是 | 是 | | +| 58 | asyncLog | 是 | 是 | | +| 59 | logKeepDays | 是 | 是 | | +| 60 | debugFlag | 是 | 是 | | +| 61 | tmrDebugFlag | 是 | 是 | | +| 62 | uDebugFlag | 是 | 是 | | +| 63 | rpcDebugFlag | 是 | 是 | | +| 64 | jniDebugFlag | 是 | 是 | | +| 65 | qDebugFlag | 是 | 是 | | +| 66 | cDebugFlag | 是 | 是 | | +| 67 | dDebugFlag | 是 | 是 | | +| 68 | vDebugFlag | 是 | 是 | | +| 69 | mDebugFlag | 是 | 是 | | +| 70 | wDebugFlag | 是 | 是 | | +| 71 | sDebugFlag | 是 | 是 | | +| 72 | tsdbDebugFlag | 是 | 是 | | +| 73 | tqDebugFlag | 否 | 是 | | +| 74 | fsDebugFlag | 是 | 是 | | +| 75 | udfDebugFlag | 否 | 是 | | +| 76 | smaDebugFlag | 否 | 是 | | +| 77 | idxDebugFlag | 否 | 是 | | +| 78 | tdbDebugFlag | 否 | 是 | | +| 79 | metaDebugFlag | 否 | 是 | | +| 80 | timezone | 是 | 是 | | +| 81 | locale | 是 | 是 | | +| 82 | charset | 是 | 是 | | +| 83 | udf | 是 | 是 | | +| 84 | enableCoreFile | 是 | 是 | | +| 85 | arbitrator | 是 | 否 | 通过 RAFT 协议选主 | +| 86 | numOfThreadsPerCore | 是 | 否 | 有其它参数设置多种线程池的大小 | +| 87 | numOfMnodes | 是 | 否 | 通过 create mnode 命令动态创建 mnode | +| 88 | vnodeBak | 是 | 否 | 3.0 行为未知 | +| 89 | balance | 是 | 否 | 负载均衡功能由 split/merge vgroups 实现 | +| 90 | balanceInterval | 是 | 否 | 随着 balance 参数失效 | +| 91 | offlineThreshold | 是 | 否 | 3.0 行为未知 | +| 92 | role | 是 | 否 | 由 supportVnode 决定是否能够创建 | +| 93 | dnodeNopLoop | 是 | 否 | 2.6 文档中未找到此参数 | +| 94 | keepTimeOffset | 是 | 否 | 2.6 文档中未找到此参数 | +| 95 | rpcTimer | 是 | 否 | 3.0 行为未知 | +| 96 | rpcMaxTime | 是 | 否 | 3.0 行为未知 | +| 97 | rpcForceTcp | 是 | 否 | 默认为 TCP | +| 98 | tcpConnTimeout | 是 | 否 | 3.0 行为未知 | +| 99 | syncCheckInterval | 是 | 否 | 3.0 行为未知 | +| 100 | maxTmrCtrl | 是 | 否 | 3.0 行为未知 | +| 101 | monitorReplica | 是 | 否 | 由 RAFT 协议管理多副本 | +| 102 | smlTagNullName | 是 | 否 | 3.0 行为未知 | +| 103 | keepColumnName | 是 | 否 | 3.0 行为未知 | +| 104 | ratioOfQueryCores | 是 | 否 | 由 线程池 相关配置参数决定 | +| 105 | maxStreamCompDelay | 是 | 否 | 3.0 行为未知 | +| 106 | maxFirstStreamCompDelay | 是 | 否 | 3.0 行为未知 | +| 107 | retryStreamCompDelay | 是 | 否 | 3.0 行为未知 | +| 108 | streamCompDelayRatio | 是 | 否 | 3.0 行为未知 | +| 109 | maxVgroupsPerDb | 是 | 否 | 由 create db 的参数 vgroups 指定实际 vgroups 数量 | +| 110 | maxTablesPerVnode | 是 | 否 | DB 中的所有表近似平均分配到各个 vgroup | +| 111 | minTablesPerVnode | 是 | 否 | DB 中的所有表近似平均分配到各个 vgroup | +| 112 | tableIncStepPerVnode | 是 | 否 | DB 中的所有表近似平均分配到各个 vgroup | +| 113 | cache | 是 | 否 | 由 buffer 代替 cache\*blocks | +| 114 | blocks | 是 | 否 | 由 buffer 代替 cache\*blocks | +| 115 | days | 是 | 否 | 由 create db 的参数 duration 取代 | +| 116 | keep | 是 | 否 | 由 create db 的参数 keep 取代 | +| 117 | minRows | 是 | 否 | 由 create db 的参数 minRows 取代 | +| 118 | maxRows | 是 | 否 | 由 create db 的参数 maxRows 取代 | +| 119 | quorum | 是 | 否 | 由 RAFT 协议决定 | +| 120 | comp | 是 | 否 | 由 create db 的参数 comp 取代 | +| 121 | walLevel | 是 | 否 | 由 create db 的参数 wal_level 取代 | +| 122 | fsync | 是 | 否 | 由 create db 的参数 wal_fsync_period 取代 | +| 123 | replica | 是 | 否 | 由 create db 的参数 replica 取代 | +| 124 | partitions | 是 | 否 | 3.0 行为未知 | +| 125 | update | 是 | 否 | 允许更新部分列 | +| 126 | cachelast | 是 | 否 | 由 create db 的参数 cacheModel 取代 | +| 127 | maxSQLLength | 是 | 否 | SQL 上限为 1MB,无需参数控制 | +| 128 | maxWildCardsLength | 是 | 否 | 3.0 行为未知 | +| 129 | maxRegexStringLen | 是 | 否 | 3.0 行为未知 | +| 130 | maxNumOfOrderedRes | 是 | 否 | 3.0 行为未知 | +| 131 | maxConnections | 是 | 否 | 取决于系统配置和系统处理能力,详见后面的 Note | +| 132 | mnodeEqualVnodeNum | 是 | 否 | 3.0 行为未知 | +| 133 | http | 是 | 否 | http 服务由 taosAdapter 提供 | +| 134 | httpEnableRecordSql | 是 | 否 | taosd 不提供 http 服务 | +| 135 | httpMaxThreads | 是 | 否 | taosd 不提供 http 服务 | +| 136 | restfulRowLimit | 是 | 否 | taosd 不提供 http 服务 | +| 137 | httpDbNameMandatory | 是 | 否 | taosd 不提供 http 服务 | +| 138 | httpKeepAlive | 是 | 否 | taosd 不提供 http 服务 | +| 139 | enableRecordSql | 是 | 否 | 3.0 行为未知 | +| 140 | maxBinaryDisplayWidth | 是 | 否 | 3.0 行为未知 | +| 141 | stream | 是 | 否 | 默认启用连续查询 | +| 142 | retrieveBlockingModel | 是 | 否 | 3.0 行为未知 | +| 143 | tsdbMetaCompactRatio | 是 | 否 | 3.0 行为未知 | +| 144 | defaultJSONStrType | 是 | 否 | 3.0 行为未知 | +| 145 | walFlushSize | 是 | 否 | 3.0 行为未知 | +| 146 | keepTimeOffset | 是 | 否 | 3.0 行为未知 | +| 147 | flowctrl | 是 | 否 | 3.0 行为未知 | +| 148 | slaveQuery | 是 | 否 | 3.0 行为未知: slave vnode 是否能够处理查询? | +| 149 | adjustMaster | 是 | 否 | 3.0 行为未知 | +| 150 | topicBinaryLen | 是 | 否 | 3.0 行为未知 | +| 151 | telegrafUseFieldNum | 是 | 否 | 3.0 行为未知 | +| 152 | deadLockKillQuery | 是 | 否 | 3.0 行为未知 | +| 153 | clientMerge | 是 | 否 | 3.0 行为未知 | +| 154 | sdbDebugFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 | +| 155 | odbcDebugFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 | +| 156 | httpDebugFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 | +| 157 | monDebugFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 | +| 158 | cqDebugFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 | +| 159 | shortcutFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 | +| 160 | probeSeconds | 是 | 否 | 3.0 行为未知 | +| 161 | probeKillSeconds | 是 | 否 | 3.0 行为未知 | +| 162 | probeInterval | 是 | 否 | 3.0 行为未知 | +| 163 | lossyColumns | 是 | 否 | 3.0 行为未知 | +| 164 | fPrecision | 是 | 否 | 3.0 行为未知 | +| 165 | dPrecision | 是 | 否 | 3.0 行为未知 | +| 166 | maxRange | 是 | 否 | 3.0 行为未知 | +| 167 | range | 是 | 否 | 3.0 行为未知 | diff --git a/docs/zh/21-tdinternal/01-arch.md b/docs/zh/21-tdinternal/01-arch.md index 782e4bcdd8bd3451ce2558567ed5faf2002327ce..6150f2e7579fdd64c562b0c18f9963a6eed20d9d 100644 --- a/docs/zh/21-tdinternal/01-arch.md +++ b/docs/zh/21-tdinternal/01-arch.md @@ -240,7 +240,7 @@ dataDir /mnt/data6 2 0 ## 数据查询 -TDengine 提供了多种多样针对表和超级表的查询处理功能,除了常规的聚合查询之外,还提供针对时序数据的窗口查询、统计聚合等功能。TDengine 的查询处理需要客户端、vnode、qnode、mnode 节点协同完成,一个复杂的超级表聚合查询可能需要多个 vnode 和 qnode 节点公共分担查询和计算任务。 +TDengine 提供了多种多样针对表和超级表的查询处理功能,除了常规的聚合查询之外,还提供针对时序数据的窗口查询、统计聚合等功能。TDengine 的查询处理需要客户端、vnode、qnode、mnode 节点协同完成,一个复杂的超级表聚合查询可能需要多个 vnode 和 qnode 节点共同分担查询和计算任务。 ### 查询基本流程 diff --git a/docs/zh/28-releases/01-tdengine.md b/docs/zh/28-releases/01-tdengine.md index 59e0d0f76174d567eeb5b597256a78ff098a351e..a5b35342508d2e9f234bdf9fb9daae48ee3e90c7 100644 --- a/docs/zh/28-releases/01-tdengine.md +++ b/docs/zh/28-releases/01-tdengine.md @@ -6,6 +6,10 @@ description: TDengine 发布历史、Release Notes 及下载链接 import Release from "/components/ReleaseV3"; +## 3.0.1.5 + + + ## 3.0.1.4 diff --git a/docs/zh/28-releases/02-tools.md b/docs/zh/28-releases/02-tools.md index 83ccdec3873bd6df23beaddd3408b3a3ede6559e..e86481435c1a9cc8c7c99fdae11464fcb4d87caf 100644 --- a/docs/zh/28-releases/02-tools.md +++ b/docs/zh/28-releases/02-tools.md @@ -6,6 +6,10 @@ description: taosTools 的发布历史、Release Notes 和下载链接 import Release from "/components/ReleaseV3"; +## 2.2.6 + + + ## 2.2.4 diff --git a/include/client/taos.h b/include/client/taos.h index 1182a9c2f7d4ff085d04ae72238644314d50e03b..44443752c50abcadfc64ae5373d654824022e109 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -126,6 +126,22 @@ typedef struct setConfRet { char retMsg[RET_MSG_LENGTH]; } setConfRet; +typedef struct TAOS_VGROUP_HASH_INFO { + int32_t vgId; + uint32_t hashBegin; + uint32_t hashEnd; +} TAOS_VGROUP_HASH_INFO ; + +typedef struct TAOS_DB_ROUTE_INFO { + int32_t routeVersion; + int16_t hashPrefix; + int16_t hashSuffix; + int8_t hashMethod; + int32_t vgNum; + TAOS_VGROUP_HASH_INFO *vgHash; +} TAOS_DB_ROUTE_INFO ; + + DLL_EXPORT void taos_cleanup(void); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); DLL_EXPORT setConfRet taos_set_config(const char *config); @@ -196,6 +212,9 @@ DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, vo DLL_EXPORT void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param); DLL_EXPORT const void *taos_get_raw_block(TAOS_RES *res); +DLL_EXPORT int taos_get_db_route_info(TAOS* taos, const char* db, TAOS_DB_ROUTE_INFO* dbInfo); +DLL_EXPORT int taos_get_table_vgId(TAOS* taos, const char* db, const char* table, int* vgId); + DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList); DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision); DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw(TAOS* taos, char* lines, int len, int32_t *totalRows, int protocol, int precision); diff --git a/include/common/tcommon.h b/include/common/tcommon.h index bb2519bea329bd21a185361c39c5660b8bb2b35c..32626ca233b3ca632cb88c4bfac0d3565fb598d3 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -83,6 +83,27 @@ typedef struct { int32_t exprIdx; } STupleKey; +typedef struct STuplePos { + union { + struct { + int32_t pageId; + int32_t offset; + }; + STupleKey streamTupleKey; + }; +} STuplePos; + +typedef struct SFirstLastRes { + bool hasResult; + // used for last_row function only, isNullRes in SResultRowEntry can not be passed to downstream.So, + // this attribute is required + bool isNull; + int32_t bytes; + int64_t ts; + STuplePos pos; + char buf[]; +} SFirstLastRes; + static inline int STupleKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) { STupleKey* pTuple1 = (STupleKey*)pKey1; STupleKey* pTuple2 = (STupleKey*)pKey2; diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index a1fefa6902b60d3c25f67d34e6c4fd09ad741104..c0c3fc7fbc931246597a2d7c3fed8bc0febdf96f 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -234,8 +234,6 @@ struct STag { // Imported since 3.0 and use bitmap to demonstrate None/Null/Norm, while use Null/Norm below 3.0 without of bitmap. #define TD_SUPPORT_BITMAP -#define TASSERT(x) ASSERT(x) - #define STR_TO_VARSTR(x, str) \ do { \ VarDataLenT __len = (VarDataLenT)strlen(str); \ diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 2d196be44cd6bd626541551a322dc962370a2c40..4a2e14eb78a6d79aff12279c4170167ea6e80b0b 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -45,14 +45,6 @@ extern bool tsPrintAuth; extern int64_t tsTickPerMin[3]; extern int32_t tsCountAlwaysReturnValue; -// multi-process -extern int32_t tsMultiProcess; -extern int32_t tsMnodeShmSize; -extern int32_t tsVnodeShmSize; -extern int32_t tsQnodeShmSize; -extern int32_t tsSnodeShmSize; -extern int32_t tsNumOfShmThreads; - // queue & threads extern int32_t tsNumOfRpcThreads; extern int32_t tsNumOfCommitThreads; diff --git a/include/common/tmsg.h b/include/common/tmsg.h index e25fbe6201fcd6c51bff78f3e098a3fb9d0b60b4..a0f78d0d590c05938e046a6487655ac98d6b3647 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -343,6 +343,8 @@ typedef struct { } SSchemaWrapper; static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) { + if (pSchemaWrapper->pSchema == NULL) return NULL; + SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper)); if (pSW == NULL) return pSW; pSW->nCols = pSchemaWrapper->nCols; @@ -352,6 +354,7 @@ static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* p taosMemoryFree(pSW); return NULL; } + memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema)); return pSW; } @@ -889,6 +892,7 @@ typedef struct { int32_t numOfVgroups; int32_t numOfStables; int32_t buffer; + int32_t cacheSize; int32_t pageSize; int32_t pages; int32_t daysPerFile; @@ -1071,7 +1075,8 @@ typedef struct { typedef struct { int32_t vgId; - int32_t syncState; + int8_t syncState; + int8_t syncRestore; int64_t cacheUsage; int64_t numOfTables; int64_t numOfTimeSeries; @@ -1086,7 +1091,8 @@ typedef struct { } SVnodeLoad; typedef struct { - int32_t syncState; + int8_t syncState; + int8_t syncRestore; } SMnodeLoad; typedef struct { @@ -1186,7 +1192,6 @@ typedef struct { int8_t strict; int8_t cacheLast; int8_t isTsma; - int8_t standby; int8_t replica; int8_t selfIndex; SReplica replicas[TSDB_MAX_REPLICA]; @@ -1201,6 +1206,7 @@ typedef struct { int16_t hashPrefix; int16_t hashSuffix; int32_t tsdbPageSize; + int64_t reserved[8]; } SCreateVnodeReq; int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq); @@ -1212,6 +1218,7 @@ typedef struct { int32_t dnodeId; int64_t dbUid; char db[TSDB_DB_FNAME_LEN]; + int64_t reserved[8]; } SDropVnodeReq; int32_t tSerializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq); @@ -1220,32 +1227,43 @@ int32_t tDeserializeSDropVnodeReq(void* buf, int32_t bufLen, SDropVnodeReq* pReq typedef struct { int64_t dbUid; char db[TSDB_DB_FNAME_LEN]; + int64_t reserved[8]; } SCompactVnodeReq; int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq); int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq); typedef struct { - int32_t vgVersion; - int32_t buffer; - int32_t pageSize; - int32_t pages; - int32_t cacheLastSize; - int32_t daysPerFile; - int32_t daysToKeep0; - int32_t daysToKeep1; - int32_t daysToKeep2; - int32_t walFsyncPeriod; - int8_t walLevel; + int32_t vgVersion; + int32_t buffer; + int32_t pageSize; + int32_t pages; + int32_t cacheLastSize; + int32_t daysPerFile; + int32_t daysToKeep0; + int32_t daysToKeep1; + int32_t daysToKeep2; + int32_t walFsyncPeriod; + int8_t walLevel; + int8_t strict; + int8_t cacheLast; + int64_t reserved[8]; +} SAlterVnodeConfigReq; + +int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq); +int32_t tDeserializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq); + +typedef struct { + int32_t vgId; int8_t strict; - int8_t cacheLast; int8_t selfIndex; int8_t replica; SReplica replicas[TSDB_MAX_REPLICA]; -} SAlterVnodeReq; + int64_t reserved[8]; +} SAlterVnodeReplicaReq; -int32_t tSerializeSAlterVnodeReq(void* buf, int32_t bufLen, SAlterVnodeReq* pReq); -int32_t tDeserializeSAlterVnodeReq(void* buf, int32_t bufLen, SAlterVnodeReq* pReq); +int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq); +int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq); typedef struct { SMsgHead header; @@ -1498,14 +1516,6 @@ typedef struct { int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq); int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq); -typedef struct { - int32_t dnodeId; - int8_t standby; -} SSetStandbyReq; - -int32_t tSerializeSSetStandbyReq(void* buf, int32_t bufLen, SSetStandbyReq* pReq); -int32_t tDeserializeSSetStandbyReq(void* buf, int32_t bufLen, SSetStandbyReq* pReq); - typedef struct { char queryStrId[TSDB_QUERY_ID_LEN]; } SKillQueryReq; @@ -1721,13 +1731,14 @@ typedef struct { char name[TSDB_STREAM_FNAME_LEN]; char sourceDB[TSDB_DB_FNAME_LEN]; char targetStbFullName[TSDB_TABLE_FNAME_LEN]; - int8_t igExists; char* sql; char* ast; + int8_t igExists; int8_t triggerType; + int8_t igExpired; + int8_t fillHistory; // process data inserted before creating stream int64_t maxDelay; int64_t watermark; - int8_t igExpired; int32_t numOfTags; SArray* pTags; // array of SField } SCMCreateStreamReq; @@ -3054,7 +3065,7 @@ static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) { } static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) { - taosArrayDestroyEx(pRsp->topics, (void (*)(void*))tDeleteSMqSubTopicEp); + taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteSMqSubTopicEp); } #define TD_AUTO_CREATE_TABLE 0x1 diff --git a/include/common/tmsgcb.h b/include/common/tmsgcb.h index c13c50e1616146e43d3a74dc4145a5e7c7ffccf3..b5b997dac0a18c6ca83e07d5f5c597004df8a913 100644 --- a/include/common/tmsgcb.h +++ b/include/common/tmsgcb.h @@ -34,6 +34,7 @@ typedef enum { WRITE_QUEUE, APPLY_QUEUE, SYNC_QUEUE, + SYNC_CTRL_QUEUE, STREAM_QUEUE, QUEUE_MAX, } EQueueType; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 1a8865bf83028a6d7dda87702d25de18e662e653..1cd02e2a281328ab2dda316a8b97ec1534274878 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -239,13 +239,6 @@ enum { TD_DEF_MSG_TYPE(TDMT_STREAM_MAX_MSG, "stream-max", NULL, NULL) TD_NEW_MSG_SEG(TDMT_MON_MSG) - TD_DEF_MSG_TYPE(TDMT_MON_MM_INFO, "monitor-minfo", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MON_VM_INFO, "monitor-vinfo", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MON_QM_INFO, "monitor-qinfo", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MON_SM_INFO, "monitor-sinfo", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MON_VM_LOAD, "monitor-vload", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MON_MM_LOAD, "monitor-mload", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MON_QM_LOAD, "monitor-qload", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MON_MAX_MSG, "monitor-max", NULL, NULL) TD_NEW_MSG_SEG(TDMT_SYNC_MSG) @@ -269,8 +262,8 @@ enum { TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_SEND, "sync-snapshot-send", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_RSP, "sync-snapshot-rsp", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_LEADER_TRANSFER, "sync-leader-transfer", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_SYNC_SET_MNODE_STANDBY, "set-mnode-standby", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_SYNC_SET_VNODE_STANDBY, "set-vnode-standby", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_SYNC_SET_MNODE_STANDBY, "set-mnode-standby", NULL, NULL) // no longer used + TD_DEF_MSG_TYPE(TDMT_SYNC_SET_VNODE_STANDBY, "set-vnode-standby", NULL, NULL) // no longer used TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT, "sync-heartbeat", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT_REPLY, "sync-heartbeat-reply", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_MAX_MSG, "sync-max", NULL, NULL) diff --git a/include/common/trow.h b/include/common/trow.h index 3680a82594c2fb679ae0b1d9afbb294f247b82d0..c5293fa45fde603c74da3416db4108e3c2f196aa 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -30,7 +30,7 @@ extern "C" { #endif -typedef struct { +typedef struct STSRow { TSKEY ts; union { uint32_t info; @@ -255,7 +255,7 @@ static FORCE_INLINE void *tdGetBitmapAddrKv(STSRow *pRow, col_id_t nKvCols) { void *tdGetBitmapAddr(STSRow *pRow, uint8_t rowType, uint32_t flen, col_id_t nKvCols); int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType, int8_t bitmapMode); int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT valType); -bool tdIsBitmapValTypeNorm(const void *pBitmap, int16_t idx, int8_t bitmapMode); +// bool tdIsBitmapValTypeNorm(const void *pBitmap, int16_t idx, int8_t bitmapMode); int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode); // ----------------- Tuple row structure(STpRow) diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 14e9a5af8797c1809caf304252fdd74f7bfab933..9ff315fc2e97f079f3b7dcbd31d36a69d21bae41 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -337,21 +337,12 @@ typedef struct tDataTypeDescriptor { int32_t nBuf); int32_t (*decompFunc)(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf, int32_t nBuf); - void (*statisFunc)(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numofrow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minindex, int16_t *maxindex, int16_t *numofnull); } tDataTypeDescriptor; extern tDataTypeDescriptor tDataTypes[TSDB_DATA_TYPE_MAX]; - -bool isValidDataType(int32_t type); - -void setVardataNull(void *val, int32_t type); -void setNull(void *val, int32_t type, int32_t bytes); -void setNullN(void *val, int32_t type, int32_t bytes, int32_t numOfElems); -const void *getNullValue(int32_t type); +bool isValidDataType(int32_t type); void assignVal(char *val, const char *src, int32_t len, int32_t type); -void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void *buf); void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type); void *getDataMin(int32_t type); void *getDataMax(int32_t type); diff --git a/include/common/tvariant.h b/include/common/tvariant.h index 9728e5ecd5a537d0224093edcda87c3bab0391cb..0507934e6a9f87ce9e6418aeea81345589c981d5 100644 --- a/include/common/tvariant.h +++ b/include/common/tvariant.h @@ -39,8 +39,6 @@ typedef struct SVariant { int32_t toInteger(const char *z, int32_t n, int32_t base, int64_t *value); int32_t toUInteger(const char *z, int32_t n, int32_t base, uint64_t *value); -bool taosVariantIsValid(SVariant *pVar); - void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type); void taosVariantDestroy(SVariant *pV); @@ -49,15 +47,6 @@ void taosVariantAssign(SVariant *pDst, const SVariant *pSrc); int32_t taosVariantCompare(const SVariant *p1, const SVariant *p2); -int32_t taosVariantToString(SVariant *pVar, char *dst); - -int32_t taosVariantDump(SVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix); - -#if 0 -int32_t taosVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix, bool *converted, char *extInfo); -#endif - -int32_t taosVariantTypeSetType(SVariant *pVariant, char type); char *taosVariantGet(SVariant *pVar, int32_t type); #ifdef __cplusplus diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index fe1692c50fc181c969b3dcea0dd751868666468d..82823e3f5762cf96479f740554e1520801969351 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -25,10 +25,9 @@ extern "C" { /** * @brief Initialize the dnode * - * @param rtype for internal debug usage, default is 0 * @return int32_t 0 for success and -1 for failure */ -int32_t dmInit(int8_t rtype); +int32_t dmInit(); /** * @brief Cleanup the dnode diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index cdb1642a5c313767fe6a6d5ad53d6202f8c677a6..c9e47c25b7b9d99e48fc26a956bff6365a7d323d 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -99,6 +99,7 @@ int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad); */ int32_t mndProcessRpcMsg(SRpcMsg *pMsg); int32_t mndProcessSyncMsg(SRpcMsg *pMsg); +int32_t mndProcessSyncCtrlMsg(SRpcMsg *pMsg); int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg); void mndPostProcessQueryMsg(SRpcMsg *pMsg); diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index d66c8c5949f99c39851f34e530bcba8600592072..9f1513d100f9ab610d9ce08af74610979d36a891 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -163,7 +163,9 @@ int32_t catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* vers * @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller) * @return error code */ -int32_t catalogGetDBVgInfo(SCatalog* pCatalog, SRequestConnInfo* pConn, const char* pDBName, SArray** pVgroupList); +int32_t catalogGetDBVgList(SCatalog* pCatalog, SRequestConnInfo* pConn, const char* pDBName, SArray** pVgroupList); + +int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, TAOS_DB_ROUTE_INFO* pInfo); int32_t catalogUpdateDBVgInfo(SCatalog* pCatalog, const char* dbName, uint64_t dbId, SDBVgInfo* dbInfo); diff --git a/include/libs/executor/dataSinkMgt.h b/include/libs/executor/dataSinkMgt.h index 816a53ad9626a8a49da940c62cd231aa6aa90da3..8a02f372d1d605b359482b5e27810e6f95488433 100644 --- a/include/libs/executor/dataSinkMgt.h +++ b/include/libs/executor/dataSinkMgt.h @@ -84,7 +84,7 @@ typedef struct SOutputData { * @param pHandle output * @return error code */ -int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam); +int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam, const char* id); int32_t dsDataSinkGetCacheSize(SDataSinkStat* pStat); diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 569c16675ddc1c221f61b1566db9da66d99a28c5..6968f1712c2743b648012f0a95118a9521aa53b9 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -129,6 +129,7 @@ typedef enum EFunctionType { FUNCTION_TYPE_TO_COLUMN, FUNCTION_TYPE_GROUP_KEY, FUNCTION_TYPE_CACHE_LAST_ROW, + FUNCTION_TYPE_CACHE_LAST, // distributed splitting functions FUNCTION_TYPE_APERCENTILE_PARTIAL = 4000, @@ -216,6 +217,8 @@ bool fmIsKeepOrderFunc(int32_t funcId); bool fmIsCumulativeFunc(int32_t funcId); bool fmIsInterpPseudoColumnFunc(int32_t funcId); +void getLastCacheDataType(SDataType* pType); + int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc); typedef enum EFuncDataRequired { diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index 12e465e0f88d68ba494a349c9dfa464928ee270b..3dee59ab14a0ac780f18f731a5abb6dbe559b6fd 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -161,10 +161,6 @@ typedef struct { SMonLogs log; } SMonMmInfo; -int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo); -int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo); -void tFreeSMonMmInfo(SMonMmInfo *pInfo); - typedef struct { SArray *datadirs; // array of SMonDiskDesc } SMonDiskInfo; @@ -176,56 +172,31 @@ typedef struct { SMonLogs log; } SMonVmInfo; -int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); -int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); -void tFreeSMonVmInfo(SMonVmInfo *pInfo); - typedef struct { SMonSysInfo sys; SMonLogs log; SQnodeLoad load; } SMonQmInfo; -int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); -int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); -void tFreeSMonQmInfo(SMonQmInfo *pInfo); - typedef struct { SMonSysInfo sys; SMonLogs log; } SMonSmInfo; -int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); -int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); -void tFreeSMonSmInfo(SMonSmInfo *pInfo); typedef struct { SMonSysInfo sys; SMonLogs log; } SMonBmInfo; -int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); -int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); -void tFreeSMonBmInfo(SMonBmInfo *pInfo); - typedef struct { SArray *pVloads; // SVnodeLoad } SMonVloadInfo; -int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo); -int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo); -void tFreeSMonVloadInfo(SMonVloadInfo *pInfo); - typedef struct { int8_t isMnode; SMnodeLoad load; } SMonMloadInfo; -int32_t tSerializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo); -int32_t tDeserializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo); - -int32_t tSerializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo); -int32_t tDeserializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo); - typedef struct { const char *server; uint16_t port; @@ -245,6 +216,12 @@ void monSetSmInfo(SMonSmInfo *pInfo); void monSetBmInfo(SMonBmInfo *pInfo); void monSendReport(); +void tFreeSMonMmInfo(SMonMmInfo *pInfo); +void tFreeSMonVmInfo(SMonVmInfo *pInfo); +void tFreeSMonQmInfo(SMonQmInfo *pInfo); +void tFreeSMonSmInfo(SMonSmInfo *pInfo); +void tFreeSMonBmInfo(SMonBmInfo *pInfo); + #ifdef __cplusplus } #endif diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 075251295190c95e80580d122b6a728ce93ced80..ae550e0c08c19a762913e3f9b34ca8af6619acff 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -34,7 +34,7 @@ extern "C" { #define SHOW_CREATE_TB_RESULT_COLS 2 #define SHOW_CREATE_TB_RESULT_FIELD1_LEN (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) -#define SHOW_CREATE_TB_RESULT_FIELD2_LEN (TSDB_MAX_BINARY_LEN + VARSTR_HEADER_SIZE) +#define SHOW_CREATE_TB_RESULT_FIELD2_LEN (TSDB_MAX_ALLOWED_SQL_LEN * 3) #define SHOW_LOCAL_VARIABLES_RESULT_COLS 2 #define SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN (TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE) diff --git a/include/libs/stream/streamState.h b/include/libs/stream/streamState.h index ec68e8ed718c2a5065d7171bc43c3db3db5f306c..3d59a69deaa7e45fb4e68d663b7f60934462dec4 100644 --- a/include/libs/stream/streamState.h +++ b/include/libs/stream/streamState.h @@ -68,9 +68,10 @@ int32_t streamStateSessionClear(SStreamState* pState); int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, const void** pVal, int32_t* pVLen); int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen, state_key_cmpr_fn fn, void** pVal, int32_t* pVLen); +int32_t streamStateSessionGetKey(SStreamState* pState, const SSessionKey* key, SSessionKey* curKey); SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSessionKey* key); -SStreamStateCur* streamStateSessionSeekKeyPrev(SStreamState* pState, const SSessionKey* key); +SStreamStateCur* streamStateSessionSeekKeyCurrentPrev(SStreamState* pState, const SSessionKey* key); SStreamStateCur* streamStateSessionGetCur(SStreamState* pState, const SSessionKey* key); int32_t streamStateFillPut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen); diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index bdc12f7e3f1c03c88ea87233f3bf708b86800c5b..2ab0dc828e51e8deb875a7390cf6b495660e464a 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -36,6 +36,7 @@ typedef struct SStreamTask SStreamTask; enum { STREAM_STATUS__NORMAL = 0, STREAM_STATUS__STOP, + STREAM_STATUS__INIT, STREAM_STATUS__FAILED, STREAM_STATUS__RECOVER, }; @@ -291,6 +292,9 @@ typedef struct SStreamTask { int64_t recoverSnapVer; int64_t startVer; + // fill history + int8_t fillHistory; + // children info SArray* childEpInfo; // SArray int32_t nextCheckId; @@ -534,7 +538,7 @@ typedef struct SStreamMeta { SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandFunc); void streamMetaClose(SStreamMeta* streamMeta); -int32_t streamMetaAddTask(SStreamMeta* pMeta, SStreamTask* pTask); +// int32_t streamMetaAddTask(SStreamMeta* pMeta, SStreamTask* pTask); int32_t streamMetaAddSerializedTask(SStreamMeta* pMeta, int64_t startVer, char* msg, int32_t msgLen); int32_t streamMetaRemoveTask(SStreamMeta* pMeta, int32_t taskId); SStreamTask* streamMetaGetTask(SStreamMeta* pMeta, int32_t taskId); diff --git a/include/libs/stream/tstreamUpdate.h b/include/libs/stream/tstreamUpdate.h index c186430f3ff3123bf39b38fd61ec81008e8a69c2..1c490852f92ed9244aeea173c5f2b33d58453326 100644 --- a/include/libs/stream/tstreamUpdate.h +++ b/include/libs/stream/tstreamUpdate.h @@ -17,6 +17,7 @@ #include "taosdef.h" #include "tarray.h" +#include "tcommon.h" #include "tmsg.h" #include "tscalablebf.h" @@ -24,6 +25,11 @@ extern "C" { #endif +typedef struct SUpdateKey { + int64_t tbUid; + TSKEY ts; +} SUpdateKey; + typedef struct SUpdateInfo { SArray *pTsBuckets; uint64_t numBuckets; @@ -41,6 +47,7 @@ typedef struct SUpdateInfo { SUpdateInfo *updateInfoInitP(SInterval *pInterval, int64_t watermark); SUpdateInfo *updateInfoInit(int64_t interval, int32_t precision, int64_t watermark); +void updateInfoFillBlockData(SUpdateInfo *pInfo, SSDataBlock *pBlock, int32_t primaryTsCol); bool updateInfoIsUpdated(SUpdateInfo *pInfo, uint64_t tableId, TSKEY ts); bool updateInfoIsTableInserted(SUpdateInfo *pInfo, int64_t tbUid); void updateInfoSetScanRange(SUpdateInfo *pInfo, STimeWindow *pWin, uint64_t groupId, uint64_t version); diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 0f8220f19ccc1bc01a69c37a054f1621aef0e0c2..ff14e637d0c90a80c2a232ab209dd23549cd4ca1 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -35,7 +35,12 @@ extern bool gRaftDetailLog; #define SYNC_MAX_PROGRESS_WAIT_MS 4000 #define SYNC_MAX_START_TIME_RANGE_MS (1000 * 20) #define SYNC_MAX_RECV_TIME_RANGE_MS 1200 +#define SYNC_DEL_WAL_MS (1000 * 60) #define SYNC_ADD_QUORUM_COUNT 3 +#define SYNC_MNODE_LOG_RETENTION 10000 +#define SYNC_VNODE_LOG_RETENTION 500 + +#define SYNC_APPEND_ENTRIES_TIMEOUT_MS 10000 #define SYNC_MAX_BATCH_SIZE 1 #define SYNC_INDEX_BEGIN 0 @@ -157,32 +162,15 @@ typedef struct SSyncLogStore { SLRUCache* pCache; void* data; - // append one log entry - int32_t (*appendEntry)(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry); - - // get one log entry, user need to free pEntry->pCont - SSyncRaftEntry* (*getEntry)(struct SSyncLogStore* pLogStore, SyncIndex index); - - // truncate log with index, entries after the given index (>=index) will be deleted - int32_t (*truncate)(struct SSyncLogStore* pLogStore, SyncIndex fromIndex); - - // return index of last entry - SyncIndex (*getLastIndex)(struct SSyncLogStore* pLogStore); - - // return term of last entry - SyncTerm (*getLastTerm)(struct SSyncLogStore* pLogStore); - - // update log store commit index with "index" - int32_t (*updateCommitIndex)(struct SSyncLogStore* pLogStore, SyncIndex index); - - // return commit index of log - SyncIndex (*getCommitIndex)(struct SSyncLogStore* pLogStore); + int32_t (*syncLogUpdateCommitIndex)(struct SSyncLogStore* pLogStore, SyncIndex index); + SyncIndex (*syncLogCommitIndex)(struct SSyncLogStore* pLogStore); SyncIndex (*syncLogBeginIndex)(struct SSyncLogStore* pLogStore); SyncIndex (*syncLogEndIndex)(struct SSyncLogStore* pLogStore); - bool (*syncLogIsEmpty)(struct SSyncLogStore* pLogStore); + int32_t (*syncLogEntryCount)(struct SSyncLogStore* pLogStore); int32_t (*syncLogRestoreFromSnapshot)(struct SSyncLogStore* pLogStore, SyncIndex index); + bool (*syncLogIsEmpty)(struct SSyncLogStore* pLogStore); bool (*syncLogExist)(struct SSyncLogStore* pLogStore, SyncIndex index); SyncIndex (*syncLogWriteIndex)(struct SSyncLogStore* pLogStore); @@ -207,6 +195,7 @@ typedef struct SSyncInfo { SMsgCb* msgcb; int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg); int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); + int32_t (*FpEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); } SSyncInfo; int32_t syncInit(); @@ -217,7 +206,6 @@ void syncStop(int64_t rid); int32_t syncSetStandby(int64_t rid); ESyncState syncGetMyRole(int64_t rid); bool syncIsReady(int64_t rid); -bool syncIsReadyForRead(int64_t rid); const char* syncGetMyRoleStr(int64_t rid); bool syncRestoreFinish(int64_t rid); SyncTerm syncGetMyTerm(int64_t rid); @@ -227,7 +215,7 @@ SyncGroupId syncGetVgId(int64_t rid); void syncGetEpSet(int64_t rid, SEpSet* pEpSet); void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet); int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak); -int32_t syncProposeBatch(int64_t rid, SRpcMsg** pMsgPArr, bool* pIsWeakArr, int32_t arrSize); +// int32_t syncProposeBatch(int64_t rid, SRpcMsg** pMsgPArr, bool* pIsWeakArr, int32_t arrSize); bool syncEnvIsStart(); const char* syncStr(ESyncState state); bool syncIsRestoreFinish(int64_t rid); @@ -241,6 +229,9 @@ int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg int32_t syncLeaderTransfer(int64_t rid); int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader); +int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex); +int32_t syncEndSnapshot(int64_t rid); + #ifdef __cplusplus } #endif diff --git a/include/libs/sync/syncTools.h b/include/libs/sync/syncTools.h index de2271554d2b9166ec240ea07e91dea9d017ef92..d5c015bfb2aa688bbd12fee325ac28cb4956707d 100644 --- a/include/libs/sync/syncTools.h +++ b/include/libs/sync/syncTools.h @@ -157,6 +157,8 @@ typedef enum ESyncTimeoutType { SYNC_TIMEOUT_HEARTBEAT, } ESyncTimeoutType; +const char* syncTimerTypeStr(enum ESyncTimeoutType timerType); + typedef struct SyncTimeout { uint32_t bytes; int32_t vgId; @@ -423,6 +425,7 @@ typedef struct SyncAppendEntriesReply { SyncTerm privateTerm; bool success; SyncIndex matchIndex; + SyncIndex lastSendIndex; int64_t startTime; } SyncAppendEntriesReply; @@ -456,6 +459,8 @@ typedef struct SyncHeartbeat { SyncTerm term; SyncIndex commitIndex; SyncTerm privateTerm; + SyncTerm minMatchIndex; + } SyncHeartbeat; SyncHeartbeat* syncHeartbeatBuild(int32_t vgId); @@ -676,24 +681,20 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg); // on message ---------------------- int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg); int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg); -int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg); -int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex); -int32_t syncNodeOnClientRequestBatchCb(SSyncNode* ths, SyncClientRequestBatch* pMsg); -int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg); -int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg); -int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg); -int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg); - -int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg); -int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteReply* pMsg); -int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMsg); -int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg); +int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg); -int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatch* pMsg); -int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntriesReply* pMsg); +int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg); +int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg); +int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex); +int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg); +int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg); +int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg); +int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg); +int32_t syncNodeOnSnapshot(SSyncNode* ths, SyncSnapshotSend* pMsg); +int32_t syncNodeOnSnapshotReply(SSyncNode* ths, SyncSnapshotRsp* pMsg); -int32_t syncNodeOnSnapshotSendCb(SSyncNode* ths, SyncSnapshotSend* pMsg); -int32_t syncNodeOnSnapshotRspCb(SSyncNode* ths, SyncSnapshotRsp* pMsg); +int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg); +int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg); // ----------------------------------------- typedef int32_t (*FpOnPingCb)(SSyncNode* ths, SyncPing* pMsg); @@ -704,8 +705,8 @@ typedef int32_t (*FpOnRequestVoteReplyCb)(SSyncNode* ths, SyncRequestVoteReply* typedef int32_t (*FpOnAppendEntriesCb)(SSyncNode* ths, SyncAppendEntries* pMsg); typedef int32_t (*FpOnAppendEntriesReplyCb)(SSyncNode* ths, SyncAppendEntriesReply* pMsg); typedef int32_t (*FpOnTimeoutCb)(SSyncNode* pSyncNode, SyncTimeout* pMsg); -typedef int32_t (*FpOnSnapshotSendCb)(SSyncNode* ths, SyncSnapshotSend* pMsg); -typedef int32_t (*FpOnSnapshotRspCb)(SSyncNode* ths, SyncSnapshotRsp* pMsg); +typedef int32_t (*FpOnSnapshotCb)(SSyncNode* ths, SyncSnapshotSend* pMsg); +typedef int32_t (*FpOnSnapshotReplyCb)(SSyncNode* ths, SyncSnapshotRsp* pMsg); // option ---------------------------------- bool syncNodeSnapshotEnable(SSyncNode* pSyncNode); diff --git a/include/os/os.h b/include/os/os.h index 28a3ebee81228380c35f5d400235641ae6df2b6f..e780611c41235b159c119780ee60cd0a0eb5593f 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -94,10 +94,8 @@ extern "C" { #include "osLz4.h" #include "osMath.h" #include "osMemory.h" -#include "osProc.h" #include "osRand.h" #include "osSemaphore.h" -#include "osShm.h" #include "osSignal.h" #include "osSleep.h" #include "osSocket.h" diff --git a/include/os/osEnv.h b/include/os/osEnv.h index d4e94d6173a813e44e68355bb6a0ead964823ba1..c1fdc9e404c35dba510dafb76e2130ecbcc6ae05 100644 --- a/include/os/osEnv.h +++ b/include/os/osEnv.h @@ -60,6 +60,7 @@ bool osTempSpaceSufficient(); void osSetTimezone(const char *timezone); void osSetSystemLocale(const char *inLocale, const char *inCharSet); +void osSetProcPath(int32_t argc, char **argv); #ifdef __cplusplus } diff --git a/include/os/osProc.h b/include/os/osProc.h deleted file mode 100644 index f09b695ef4e55f0ab9bb9b0113cc1befff58daa0..0000000000000000000000000000000000000000 --- a/include/os/osProc.h +++ /dev/null @@ -1,34 +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 . - */ - -#ifndef _TD_OS_PROC_H_ -#define _TD_OS_PROC_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t taosNewProc(char **args); -void taosWaitProc(int32_t pid); -void taosKillProc(int32_t pid); -bool taosProcExist(int32_t pid); -void taosSetProcName(int32_t argc, char **argv, const char *name); -void taosSetProcPath(int32_t argc, char **argv); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_OS_PROC_H_*/ diff --git a/include/os/osShm.h b/include/os/osShm.h deleted file mode 100644 index 87efb1ab16e8978294b2a286d8c1093d406c82a8..0000000000000000000000000000000000000000 --- a/include/os/osShm.h +++ /dev/null @@ -1,37 +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 . - */ - -#ifndef _TD_OS_SHM_H_ -#define _TD_OS_SHM_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - int32_t id; - int32_t size; - void *ptr; -} SShm; - -int32_t taosCreateShm(SShm *pShm, int32_t key, int32_t shmsize); -void taosDropShm(SShm *pShm); -int32_t taosAttachShm(SShm *pShm); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_OS_SHM_H_*/ diff --git a/include/util/tdef.h b/include/util/tdef.h index bb7f908ad40a5bd6e3f48064bf3dad2781c65cbc..936fbdf0d58656f61c2f1019d70f71e604636363 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -237,7 +237,6 @@ typedef enum ELogicConditionType { #define TSDB_MAX_BYTES_PER_ROW 49151 #define TSDB_MAX_TAGS_LEN 16384 #define TSDB_MAX_TAGS 128 -#define TSDB_MAX_TAG_CONDITIONS 1024 #define TSDB_MAX_COL_TAG_NUM (TSDB_MAX_COLUMNS + TSDB_MAX_TAGS) #define TSDB_MAX_JSON_TAG_LEN 16384 @@ -274,8 +273,6 @@ typedef enum ELogicConditionType { #define TSDB_PAYLOAD_SIZE TSDB_DEFAULT_PKT_SIZE #define TSDB_DEFAULT_PAYLOAD_SIZE 5120 // default payload size, greater than PATH_MAX value -#define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth -#define TSDB_CQ_SQL_SIZE 1024 #define TSDB_MIN_VNODES 16 #define TSDB_MAX_VNODES 512 @@ -285,10 +282,7 @@ typedef enum ELogicConditionType { #define TSDB_MAX_REPLICA 5 -#define TSDB_TBNAME_COLUMN_INDEX (-1) -#define TSDB_UD_COLUMN_INDEX (-1000) -#define TSDB_RES_COL_ID (-5000) - +#define TSDB_TBNAME_COLUMN_INDEX (-1) #define TSDB_MULTI_TABLEMETA_MAX_NUM 100000 // maximum batch size allowed to load table meta #define TSDB_MIN_VNODES_PER_DB 1 @@ -398,9 +392,6 @@ typedef enum ELogicConditionType { #define TSDB_MAX_EXPLAIN_RATIO 1 #define TSDB_DEFAULT_EXPLAIN_RATIO 0.001 -#define TSDB_MAX_JOIN_TABLE_NUM 10 -#define TSDB_MAX_UNION_CLAUSE 5 - #define TSDB_DEFAULT_EXPLAIN_VERBOSE false #define TSDB_EXPLAIN_RESULT_ROW_SIZE (16 * 1024) @@ -419,7 +410,6 @@ typedef enum ELogicConditionType { #endif #define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type -#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode #define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default diff --git a/include/util/thash.h b/include/util/thash.h index 2be5f4a047162c4095821a2d650e576ca2581c58..08caad495d8e35b85d59fb5c49cc923ea37d0e35 100644 --- a/include/util/thash.h +++ b/include/util/thash.h @@ -50,6 +50,9 @@ uint64_t MurmurHash3_64(const char *key, uint32_t len); uint32_t taosIntHash_32(const char *key, uint32_t len); uint32_t taosIntHash_64(const char *key, uint32_t len); +uint32_t taosFastHash(const char *key, uint32_t len); +uint32_t taosDJB2Hash(const char *key, uint32_t len); + _hash_fn_t taosGetDefaultHashFunction(int32_t type); _equal_fn_t taosGetDefaultEqualFunction(int32_t type); diff --git a/include/util/tutil.h b/include/util/tutil.h index 2a3f0dcb020666fc3b80b8d4f3d304dc13c8544c..de963001557519b7dd9355187122535c77b3f17a 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -83,6 +83,12 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen, } } +#define TSDB_CHECK_CODE(CODE, LINO, LABEL) \ + if (CODE) { \ + LINO = __LINE__; \ + goto LABEL; \ + } + #ifdef __cplusplus } #endif diff --git a/packaging/tools/post.sh b/packaging/tools/post.sh index 708a93c4fa9471718e410b49e4bffba7bbce002d..37307f0543f334fad0557868a83c3ad8b9b596ec 100755 --- a/packaging/tools/post.sh +++ b/packaging/tools/post.sh @@ -118,6 +118,7 @@ function kill_taosd() { } function install_include() { + ${csudo}mkdir -p ${inc_link_dir} ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/taosudf.h || : [ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h ||: diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index b3c5565cfb63bde7c5b659d929e6d634e693f7a8..be0e6d50dc66f272c03fed5eab79edc84b36b247 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -338,7 +338,7 @@ void doDestroyRequest(void *p) { SRequestObj *pRequest = (SRequestObj *)p; - int64_t reqId = pRequest->self; + uint64_t reqId = pRequest->requestId; tscTrace("begin to destroy request %" PRIx64 " p:%p", reqId, pRequest); taosHashRemove(pRequest->pTscObj->pRequests, &pRequest->self, sizeof(pRequest->self)); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 45d2de4a7aace01a31fdc7c213c6854ea4e6bf01..0bf254e45591068204452a6257d87c5ccb612c9d 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -186,8 +186,8 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, STscObj* pTscObj = (*pRequest)->pTscObj; if (taosHashPut(pTscObj->pRequests, &(*pRequest)->self, sizeof((*pRequest)->self), &(*pRequest)->self, sizeof((*pRequest)->self))) { - tscError("%" PRIx64 " failed to add to request container, reqId:0x%" PRIu64 ", conn:%" PRIx64 ", %s", (*pRequest)->self, - (*pRequest)->requestId, pTscObj->id, sql); + tscError("%" PRId64 " failed to add to request container, reqId:0x%" PRIx64 ", conn:%" PRId64 ", %s", + (*pRequest)->self, (*pRequest)->requestId, pTscObj->id, sql); taosMemoryFree(param); destroyRequest(*pRequest); @@ -199,9 +199,8 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, if (tsQueryUseNodeAllocator && !qIsInsertValuesSql((*pRequest)->sqlstr, (*pRequest)->sqlLen)) { if (TSDB_CODE_SUCCESS != nodesCreateAllocator((*pRequest)->requestId, tsQueryNodeChunkSize, &((*pRequest)->allocatorRefId))) { - tscError("%d failed to create node allocator, reqId:0x%" PRIx64 ", conn:%" PRId64 ", %s", (*pRequest)->self, - (*pRequest)->requestId, pTscObj->id, sql); - + tscError("%" PRId64 " failed to create node allocator, reqId:0x%" PRIx64 ", conn:%" PRId64 ", %s", + (*pRequest)->self, (*pRequest)->requestId, pTscObj->id, sql); destroyRequest(*pRequest); *pRequest = NULL; return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -370,8 +369,8 @@ int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList) { if (pNodeList) { pInfo->pQnodeList = taosArrayDup(pNodeList); taosArraySort(pInfo->pQnodeList, compareQueryNodeLoad); - tscDebug("QnodeList updated in cluster 0x%" PRIx64 ", num:%d", pInfo->clusterId, - (int)taosArrayGetSize(pInfo->pQnodeList)); + tscDebug("QnodeList updated in cluster 0x%" PRIx64 ", num:%ld", pInfo->clusterId, + taosArrayGetSize(pInfo->pQnodeList)); } taosThreadMutexUnlock(&pInfo->qnodeMutex); @@ -644,7 +643,7 @@ int32_t buildSyncExecNodeList(SRequestObj* pRequest, SArray** pNodeList, SArray* .requestObjRefId = pRequest->self, .mgmtEps = getEpSet_s(&pInst->mgmtEp)}; - code = catalogGetDBVgInfo(pCtg, &conn, dbFName, &pVgList); + code = catalogGetDBVgList(pCtg, &conn, dbFName, &pVgList); if (code) { goto _return; } @@ -1040,39 +1039,39 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat SSqlCallbackWrapper* pWrapper) { pRequest->type = pQuery->msgType; - SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad)); + SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad)); SPlanContext cxt = {.queryId = pRequest->requestId, - .acctId = pRequest->pTscObj->acctId, - .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp), - .pAstRoot = pQuery->pRoot, - .showRewrite = pQuery->showRewrite, - .pMsg = pRequest->msgBuf, - .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE, - .pUser = pRequest->pTscObj->user, - .sysInfo = pRequest->pTscObj->sysInfo, - .allocatorId = pRequest->allocatorRefId}; - - SAppInstInfo* pAppInfo = getAppInfo(pRequest); - SQueryPlan* pDag = NULL; + .acctId = pRequest->pTscObj->acctId, + .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp), + .pAstRoot = pQuery->pRoot, + .showRewrite = pQuery->showRewrite, + .pMsg = pRequest->msgBuf, + .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE, + .pUser = pRequest->pTscObj->user, + .sysInfo = pRequest->pTscObj->sysInfo, + .allocatorId = pRequest->allocatorRefId}; + + SAppInstInfo* pAppInfo = getAppInfo(pRequest); + SQueryPlan* pDag = NULL; int64_t st = taosGetTimestampUs(); int32_t code = qCreateQueryPlan(&cxt, &pDag, pMnodeList); - if (code) { - tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code), - pRequest->requestId); - } else { - pRequest->body.subplanNum = pDag->numOfSubplans; - } + if (code) { + tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code), + pRequest->requestId); + } else { + pRequest->body.subplanNum = pDag->numOfSubplans; + } - pRequest->metric.planEnd = taosGetTimestampUs(); + pRequest->metric.planEnd = taosGetTimestampUs(); if (code == TSDB_CODE_SUCCESS) { tscDebug("0x%" PRIx64 " create query plan success, elapsed time:%.2f ms, 0x%" PRIx64, pRequest->self, - (pRequest->metric.planEnd - st)/1000.0, pRequest->requestId); + (pRequest->metric.planEnd - st) / 1000.0, pRequest->requestId); } - if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) { - SArray* pNodeList = NULL; - buildAsyncExecNodeList(pRequest, &pNodeList, pMnodeList, pResultMeta); + if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) { + SArray* pNodeList = NULL; + buildAsyncExecNodeList(pRequest, &pNodeList, pMnodeList, pResultMeta); SRequestConnInfo conn = {.pTrans = getAppInfo(pRequest)->pTransporter, .requestId = pRequest->requestId, @@ -1898,7 +1897,7 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 // check fields for (int32_t i = 0; i < numOfCols; ++i) { - int16_t type = *(int16_t*)p; + int8_t type = *(int8_t*)p; p += sizeof(int8_t); int32_t bytes = *(int32_t*)p; @@ -2262,7 +2261,7 @@ void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, if (fp) { fp(param, NULL, terrno); } - + return; } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 286fb853734ff6721871cf9679087d85bd8e881f..8036e50545573bb9084f3c877e942f47a14284cc 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -989,6 +989,106 @@ const void *taos_get_raw_block(TAOS_RES *res) { return pRequest->body.resInfo.pData; } +int taos_get_db_route_info(TAOS* taos, const char* db, TAOS_DB_ROUTE_INFO* dbInfo) { + if (NULL == taos) { + terrno = TSDB_CODE_TSC_DISCONNECTED; + return terrno; + } + + if (NULL == db || NULL == dbInfo) { + tscError("invalid input param, db:%p, dbInfo:%p", db, dbInfo); + terrno = TSDB_CODE_TSC_INVALID_INPUT; + return terrno; + } + + int64_t connId = *(int64_t *)taos; + SRequestObj *pRequest = NULL; + char *sql = "taos_get_db_route_info"; + int32_t code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + return terrno; + } + + STscObj *pTscObj = pRequest->pTscObj; + SCatalog *pCtg = NULL; + code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCtg); + if (code != TSDB_CODE_SUCCESS) { + goto _return; + } + + SRequestConnInfo conn = { + .pTrans = pTscObj->pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self}; + + conn.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); + + char dbFName[TSDB_DB_FNAME_LEN] = {0}; + snprintf(dbFName, sizeof(dbFName), "%d.%s", pTscObj->acctId, db); + + code = catalogGetDBVgInfo(pCtg, &conn, dbFName, dbInfo); + if (code) { + goto _return; + } + +_return: + + terrno = code; + + destroyRequest(pRequest); + return code; +} + +int taos_get_table_vgId(TAOS* taos, const char* db, const char* table, int* vgId) { + if (NULL == taos) { + terrno = TSDB_CODE_TSC_DISCONNECTED; + return terrno; + } + + if (NULL == db || NULL == table || NULL == vgId) { + tscError("invalid input param, db:%p, table:%p, vgId:%p", db, table, vgId); + terrno = TSDB_CODE_TSC_INVALID_INPUT; + return terrno; + } + + int64_t connId = *(int64_t *)taos; + SRequestObj *pRequest = NULL; + char *sql = "taos_get_table_vgId"; + int32_t code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest); + if (code != TSDB_CODE_SUCCESS) { + return terrno; + } + + STscObj *pTscObj = pRequest->pTscObj; + SCatalog *pCtg = NULL; + code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCtg); + if (code != TSDB_CODE_SUCCESS) { + goto _return; + } + + SRequestConnInfo conn = { + .pTrans = pTscObj->pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self}; + + conn.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); + + SName tableName; + toName(pTscObj->acctId, db, table, &tableName); + + SVgroupInfo vgInfo; + code = catalogGetTableHashVgroup(pCtg, &conn, &tableName, &vgInfo); + if (code) { + goto _return; + } + + *vgId = vgInfo.vgId; + +_return: + + terrno = code; + + destroyRequest(pRequest); + return code; +} + int taos_load_table_info(TAOS *taos, const char *tableNameList) { if (NULL == taos) { terrno = TSDB_CODE_TSC_DISCONNECTED; diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 945562ef36499e5bdfe34ed2e375b78fa7b0cea7..e586018c190765bdf632cae272dc111eba2a7b7e 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -46,38 +46,38 @@ int32_t genericRspCallback(void* param, SDataBuf* pMsg, int32_t code) { int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; + if (code != TSDB_CODE_SUCCESS) { - taosMemoryFree(pMsg->pEpSet); - taosMemoryFree(pMsg->pData); setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); - return code; + goto End; } STscObj* pTscObj = pRequest->pTscObj; SConnectRsp connectRsp = {0}; - tDeserializeSConnectRsp(pMsg->pData, pMsg->len, &connectRsp); + if (tDeserializeSConnectRsp(pMsg->pData, pMsg->len, &connectRsp) != 0) { + code = TSDB_CODE_TSC_INVALID_VERSION; + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + goto End; + } int32_t now = taosGetTimestampSec(); int32_t delta = abs(now - connectRsp.svrTimestamp); if (delta > timestampDeltaLimit) { code = TSDB_CODE_TIME_UNSYNCED; tscError("time diff:%ds is too big", delta); - taosMemoryFree(pMsg->pEpSet); - taosMemoryFree(pMsg->pData); setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); - return code; + goto End; } /*assert(connectRsp.epSet.numOfEps > 0);*/ if (connectRsp.epSet.numOfEps == 0) { - taosMemoryFree(pMsg->pEpSet); - taosMemoryFree(pMsg->pData); setErrno(pRequest, TSDB_CODE_MND_APP_ERROR); tsem_post(&pRequest->body.rspSem); - return code; + goto End; } if (connectRsp.dnodeNum == 1) { @@ -113,14 +113,15 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType); - // pRequest->body.resInfo.pRspMsg = pMsg->pData; tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId, pTscObj->pAppInfo->numOfConns); - taosMemoryFree(pMsg->pData); - taosMemoryFree(pMsg->pEpSet); tsem_post(&pRequest->body.rspSem); - return 0; +End: + + taosMemoryFree(pMsg->pEpSet); + taosMemoryFree(pMsg->pData); + return code; } SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pRequest) { @@ -194,7 +195,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { SUseDbRsp usedbRsp = {0}; tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); - if(strlen(usedbRsp.db) == 0){ + if (strlen(usedbRsp.db) == 0) { return TSDB_CODE_MND_DB_NOT_EXIST; } @@ -292,7 +293,7 @@ int32_t processDropDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp); struct SCatalog* pCatalog = NULL; - int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); + int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); if (TSDB_CODE_SUCCESS == code) { catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid); } diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index 1dc319be94e8ab880aaf87259f8b7166a900e871..dfcd8c4a7901e510d2caf70d7b807e732eeb802c 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -1071,8 +1071,8 @@ static int32_t taosDeleteData(TAOS* taos, void* meta, int32_t metaLen) { // getTbName(req.tableFName); char sql[256] = {0}; - sprintf(sql, "delete from `%s` where `%s` >= %" PRId64 " and `%s` <= %" PRId64, req.tableFName, req.tsColName, - req.skey, req.tsColName, req.ekey); + snprintf(sql, sizeof(sql), "delete from `%s` where `%s` >= %" PRId64 " and `%s` <= %" PRId64, req.tableFName, + req.tsColName, req.skey, req.tsColName, req.ekey); printf("delete sql:%s\n", sql); TAOS_RES* res = taos_query(taos, sql); diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 2c48eae59f7ba412759c6aa94b75ba8171dc1b12..5b8266b1cb9f0592c4e8145983dcbe241efd739f 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -2394,7 +2394,7 @@ static int32_t smlParseLine(SSmlHandle *info, char *lines[], char* rawLine, char code = smlParseJSON(info, rawLine); } if (code != TSDB_CODE_SUCCESS) { - uError("SML:0x%" PRIx64 " smlParseJSON failed:%s", info->id, *lines); + uError("SML:0x%" PRIx64 " smlParseJSON failed:%s", info->id, lines?*lines:rawLine); return code; } return code; diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index 0bc33739c6b46b6426421ca728df7d29791b1e37..6e3e274052d28d42733f4bf54da1761b7a6cd80e 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -638,7 +638,7 @@ static int32_t tmqCommitConsumerImpl(tmq_t* tmq, int8_t automatic, int8_t async, pVg->vgId); if (pVg->currentOffset.type > 0 && !tOffsetEqual(&pVg->currentOffset, &pVg->committedOffset)) { - tscDebug("consumer: %ld, vg:%d, current %ld, committed %ld", tmq->consumerId, pVg->vgId, + tscDebug("consumer: %" PRId64 ", vg:%d, current %" PRId64 ", committed %" PRId64 "", tmq->consumerId, pVg->vgId, pVg->currentOffset.version, pVg->committedOffset.version); if (tmqSendCommitReq(tmq, pVg, pTopic, pParamSet) < 0) { continue; @@ -979,10 +979,11 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { const SArray* container = &topic_list->container; int32_t sz = taosArrayGetSize(container); void* buf = NULL; + SMsgSendInfo* sendInfo = NULL; SCMSubscribeReq req = {0}; int32_t code = -1; - tscDebug("call tmq subscribe, consumer: %ld, topic num %d", tmq->consumerId, sz); + tscDebug("call tmq subscribe, consumer: %" PRId64 ", topic num %d", tmq->consumerId, sz); req.consumerId = tmq->consumerId; tstrncpy(req.clientId, tmq->clientId, 256); @@ -990,6 +991,8 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { req.topicNames = taosArrayInit(sz, sizeof(void*)); if (req.topicNames == NULL) goto FAIL; + tscDebug("call tmq subscribe, consumer: %" PRId64 ", topic num %d", tmq->consumerId, sz); + for (int32_t i = 0; i < sz; i++) { char* topic = taosArrayGetP(container, i); @@ -1014,7 +1017,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { void* abuf = buf; tSerializeSCMSubscribeReq(&abuf, &req); - SMsgSendInfo* sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); + sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (sendInfo == NULL) goto FAIL; SMqSubscribeCbParam param = { @@ -1044,6 +1047,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { // avoid double free if msg is sent buf = NULL; + sendInfo = NULL; tsem_wait(¶m.rspSem); tsem_destroy(¶m.rspSem); @@ -1076,8 +1080,9 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { code = 0; FAIL: - if (req.topicNames != NULL) taosArrayDestroyP(req.topicNames, taosMemoryFree); + taosArrayDestroyP(req.topicNames, taosMemoryFree); taosMemoryFree(buf); + taosMemoryFree(sendInfo); return code; } @@ -1201,7 +1206,7 @@ CREATE_MSG_FAIL: return -1; } -bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) { +bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) { bool set = false; int32_t topicNumGet = taosArrayGetSize(pRsp->topics); @@ -1594,6 +1599,7 @@ int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspWrapper* rspWrapper, bool* pReset) SMqAskEpRsp* rspMsg = &pEpRspWrapper->msg; tmqUpdateEp(tmq, rspWrapper->epoch, rspMsg); /*tmqClearUnhandleMsg(tmq);*/ + tDeleteSMqAskEpRsp(rspMsg); *pReset = true; } else { *pReset = false; @@ -1611,7 +1617,11 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { if (rspWrapper == NULL) { taosReadAllQitems(tmq->mqueue, tmq->qall); taosGetQitem(tmq->qall, (void**)&rspWrapper); - if (rspWrapper == NULL) return NULL; + + if (rspWrapper == NULL) { + tscDebug("consumer %" PRId64 " mqueue empty", tmq->consumerId); + return NULL; + } } if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__END_RSP) { @@ -1620,7 +1630,7 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { return NULL; } else if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__POLL_RSP) { SMqPollRspWrapper* pollRspWrapper = (SMqPollRspWrapper*)rspWrapper; - tscDebug("consumer %ld actual process poll rsp", tmq->consumerId); + tscDebug("consumer %" PRId64 " actual process poll rsp", tmq->consumerId); /*atomic_sub_fetch_32(&tmq->readyRequest, 1);*/ int32_t consumerEpoch = atomic_load_32(&tmq->epoch); if (pollRspWrapper->dataRsp.head.epoch == consumerEpoch) { @@ -1709,6 +1719,8 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) { void* rspObj; int64_t startTime = taosGetTimestampMs(); + tscDebug("consumer:%" PRId64 ", start poll at %" PRId64, tmq->consumerId, startTime); + #if 0 tmqHandleAllDelayedTask(tmq); tmqPollImpl(tmq, timeout); @@ -1743,15 +1755,18 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) { rspObj = tmqHandleAllRsp(tmq, timeout, false); if (rspObj) { + tscDebug("consumer:%" PRId64 ", return rsp", tmq->consumerId); return (TAOS_RES*)rspObj; } else if (terrno == TSDB_CODE_TQ_NO_COMMITTED_OFFSET) { + tscDebug("consumer:%" PRId64 ", return null since no committed offset", tmq->consumerId); return NULL; } if (timeout != -1) { int64_t endTime = taosGetTimestampMs(); int64_t leftTime = endTime - startTime; if (leftTime > timeout) { - tscDebug("consumer:%" PRId64 ", (epoch %d) timeout, no rsp", tmq->consumerId, tmq->epoch); + tscDebug("consumer:%" PRId64 ", (epoch %d) timeout, no rsp, start time %" PRId64 ", end time %" PRId64, + tmq->consumerId, tmq->epoch, startTime, endTime); return NULL; } tsem_timewait(&tmq->rspSem, leftTime * 1000); diff --git a/source/client/src/clientTmqConnector.c b/source/client/src/clientTmqConnector.c index 6edf76124e5940b9120d9e8ccdd4c1c4ec537fcb..42988b16fe5e9dce30a5e295288a65794e940098 100644 --- a/source/client/src/clientTmqConnector.c +++ b/source/client/src/clientTmqConnector.c @@ -73,8 +73,8 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqConfDestroyImp if (conf == NULL) { jniDebug("jobj:%p, tmq config is already destroyed", jobj); } else { - tmq_conf_destroy(conf); jniDebug("jobj:%p, config:%p, tmq successfully destroy config", jobj, conf); + tmq_conf_destroy(conf); } } @@ -206,6 +206,7 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitAsync(JN tmq_t *tmq = (tmq_t *)jtmq; if (tmq == NULL) { jniError("jobj:%p, tmq is closed", jobj); + return; } TAOS_RES *res = (TAOS_RES *)jres; consumer = (*env)->NewGlobalRef(env, consumer); @@ -252,6 +253,7 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTopicNam TAOS_RES *res = (TAOS_RES *)jres; if (res == NULL) { jniDebug("jobj:%p, invalid res handle", jobj); + return NULL; } return (*env)->NewStringUTF(env, tmq_get_topic_name(res)); } @@ -259,6 +261,7 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetDbName(J TAOS_RES *res = (TAOS_RES *)jres; if (res == NULL) { jniDebug("jobj:%p, invalid res handle", jobj); + return NULL; } return (*env)->NewStringUTF(env, tmq_get_db_name(res)); } @@ -266,6 +269,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetVgroupId(JN TAOS_RES *res = (TAOS_RES *)jres; if (res == NULL) { jniDebug("jobj:%p, invalid res handle", jobj); + return -1; } return tmq_get_vgroup_id(res); } @@ -275,6 +279,7 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTableNam TAOS_RES *res = (TAOS_RES *)jres; if (res == NULL) { jniDebug("jobj:%p, invalid res handle", jobj); + return NULL; } return (*env)->NewStringUTF(env, tmq_get_table_name(res)); } diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 62706db980312a98e6b48f45e2c8ecaab8148941..64f56212af0d3818b9f91004029194d55600eb5a 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -1836,10 +1836,10 @@ void blockDebugShowDataBlocks(const SArray* dataBlocks, const char* flag) { printf(" %15u |", *(uint32_t*)var); break; case TSDB_DATA_TYPE_BIGINT: - printf(" %15ld |", *(int64_t*)var); + printf(" %15" PRId64 " |", *(int64_t*)var); break; case TSDB_DATA_TYPE_UBIGINT: - printf(" %15lu |", *(uint64_t*)var); + printf(" %15" PRIu64 " |", *(uint64_t*)var); break; case TSDB_DATA_TYPE_FLOAT: printf(" %15f |", *(float*)var); @@ -1858,7 +1858,7 @@ void blockDebugShowDataBlocks(const SArray* dataBlocks, const char* flag) { char* pData = colDataGetVarData(pColInfoData, j); int32_t dataSize = TMIN(sizeof(pBuf), varDataLen(pData)); memset(pBuf, 0, dataSize); - taosUcs4ToMbs((TdUcs4*)varDataVal(pData), dataSize, pBuf); + (void)taosUcs4ToMbs((TdUcs4*)varDataVal(pData), dataSize, pBuf); printf(" %15s |", pBuf); } break; default: @@ -1915,11 +1915,11 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf) if (len >= size - 1) return dumpBuf; break; case TSDB_DATA_TYPE_BIGINT: - len += snprintf(dumpBuf + len, size - len, " %15ld |", *(int64_t*)var); + len += snprintf(dumpBuf + len, size - len, " %15" PRId64 " |", *(int64_t*)var); if (len >= size - 1) return dumpBuf; break; case TSDB_DATA_TYPE_UBIGINT: - len += snprintf(dumpBuf + len, size - len, " %15lu |", *(uint64_t*)var); + len += snprintf(dumpBuf + len, size - len, " %15" PRIu64 " |", *(uint64_t*)var); if (len >= size - 1) return dumpBuf; break; case TSDB_DATA_TYPE_FLOAT: @@ -1946,7 +1946,7 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf) char* pData = colDataGetVarData(pColInfoData, j); int32_t dataSize = TMIN(sizeof(pBuf), varDataLen(pData)); memset(pBuf, 0, sizeof(pBuf)); - taosUcs4ToMbs((TdUcs4*)varDataVal(pData), dataSize, pBuf); + (void)taosUcs4ToMbs((TdUcs4*)varDataVal(pData), dataSize, pBuf); len += snprintf(dumpBuf + len, size - len, " %15s |", pBuf); if (len >= size - 1) return dumpBuf; } break; @@ -2030,21 +2030,24 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataB tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var, true, offset, k); + } else if (colDataIsNull_s(pColInfoData, j)) { + tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NULL, NULL, + false, offset, k); } else { tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var, true, offset, k); } break; - case TSDB_DATA_TYPE_NCHAR: { - void* data = colDataGetData(pColInfoData, j); - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_NCHAR, TD_VTYPE_NORM, data, true, - offset, k); - break; - } + case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_VARCHAR: { // TSDB_DATA_TYPE_BINARY - void* data = colDataGetData(pColInfoData, j); - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_VARCHAR, TD_VTYPE_NORM, data, true, - offset, k); + if (colDataIsNull_s(pColInfoData, j)) { + tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pColInfoData->info.type, TD_VTYPE_NULL, NULL, + false, offset, k); + } else { + void* data = colDataGetData(pColInfoData, j); + tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pColInfoData->info.type, TD_VTYPE_NORM, data, + true, offset, k); + } break; } case TSDB_DATA_TYPE_VARBINARY: @@ -2053,11 +2056,14 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataB case TSDB_DATA_TYPE_JSON: case TSDB_DATA_TYPE_MEDIUMBLOB: uError("the column type %" PRIi16 " is defined but not implemented yet", pColInfoData->info.type); - TASSERT(0); + ASSERT(0); break; default: if (pColInfoData->info.type < TSDB_DATA_TYPE_MAX && pColInfoData->info.type > TSDB_DATA_TYPE_NULL) { - if (pCol->type == pColInfoData->info.type) { + if (colDataIsNull_s(pColInfoData, j)) { + tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NULL, NULL, false, offset, + k); + } else if (pCol->type == pColInfoData->info.type) { tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, var, true, offset, k); } else { @@ -2084,7 +2090,7 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataB } } else { uError("the column type %" PRIi16 " is undefined\n", pColInfoData->info.type); - TASSERT(0); + ASSERT(0); } break; } diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 7967b6885a1413c19fd620394a4e5c96715b0683..513c54c7e9a5a7fbc513cfe55e397e48f6018b9e 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -114,7 +114,7 @@ static void setBitMap(uint8_t *pb, uint8_t v, int32_t idx, uint8_t flags) { ((uint32_t *)(p))[i] = (n); \ } \ } while (0) - +#if 0 int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow) { int32_t code = 0; #if 0 @@ -432,7 +432,6 @@ void tTSRowFree(STSRow2 *pRow) { } void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) { -#if 0 uint8_t isTuple = ((pRow->flags & 0xf0) == 0) ? 1 : 0; STColumn *pTColumn = &pTSchema->columns[iCol]; uint8_t flags = pRow->flags & (uint8_t)0xf; @@ -577,12 +576,10 @@ _return_null: _return_value: *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, value); return; -#endif } int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray) { int32_t code = 0; -#if 0 SColVal cv; (*ppArray) = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)); @@ -596,11 +593,11 @@ int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray) { taosArrayPush(*ppArray, &cv); } -#endif + _exit: return code; } - +#endif int32_t tPutTSRow(uint8_t *p, STSRow2 *pRow) { int32_t n = 0; @@ -896,16 +893,26 @@ void tTagFree(STag *pTag) { } char *tTagValToData(const STagVal *value, bool isJson) { - if (!value) return NULL; + if (!value) { + return NULL; + } + char *data = NULL; int8_t typeBytes = 0; if (isJson) { typeBytes = CHAR_BYTES; } + if (IS_VAR_DATA_TYPE(value->type)) { data = taosMemoryCalloc(1, typeBytes + VARSTR_HEADER_SIZE + value->nData); - if (data == NULL) return NULL; - if (isJson) *data = value->type; + if (data == NULL) { + return NULL; + } + + if (isJson) { + *data = value->type; + } + varDataLen(data + typeBytes) = value->nData; memcpy(varDataVal(data + typeBytes), value->pData, value->nData); } else { diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 2b64d3f1eed3fdf0d9a378881bdd9a6bc0e8a8ee..5025cbcac581604b64bfe1f3abe2c9fd335560ed 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -40,14 +40,6 @@ int32_t tsMaxShellConns = 50000; int32_t tsShellActivityTimer = 3; // second bool tsPrintAuth = false; -// multi process -int32_t tsMultiProcess = 0; -int32_t tsMnodeShmSize = TSDB_MAX_MSG_SIZE * 2 + 1024; -int32_t tsVnodeShmSize = TSDB_MAX_MSG_SIZE * 10 + 1024; -int32_t tsQnodeShmSize = TSDB_MAX_MSG_SIZE * 4 + 1024; -int32_t tsSnodeShmSize = TSDB_MAX_MSG_SIZE * 4 + 1024; -int32_t tsNumOfShmThreads = 1; - // queue & threads int32_t tsNumOfRpcThreads = 1; int32_t tsNumOfCommitThreads = 2; @@ -57,7 +49,7 @@ int32_t tsNumOfMnodeFetchThreads = 1; int32_t tsNumOfMnodeReadThreads = 1; int32_t tsNumOfVnodeQueryThreads = 4; int32_t tsNumOfVnodeStreamThreads = 2; -int32_t tsNumOfVnodeFetchThreads = 1; +int32_t tsNumOfVnodeFetchThreads = 4; int32_t tsNumOfVnodeWriteThreads = 2; int32_t tsNumOfVnodeSyncThreads = 2; int32_t tsNumOfVnodeRsmaThreads = 2; @@ -352,13 +344,6 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1; if (cfgAddInt32(pCfg, "queryRspPolicy", tsQueryRspPolicy, 0, 1, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "multiProcess", tsMultiProcess, 0, 2, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "mnodeShmSize", tsMnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "vnodeShmSize", tsVnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "qnodeShmSize", tsQnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "snodeShmSize", tsSnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "numOfShmThreads", tsNumOfShmThreads, 1, 1024, 0) != 0) return -1; - tsNumOfRpcThreads = tsNumOfCores / 2; tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 1, 4); if (cfgAddInt32(pCfg, "numOfRpcThreads", tsNumOfRpcThreads, 1, 1024, 0) != 0) return -1; @@ -379,8 +364,9 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { tsNumOfVnodeStreamThreads = TMAX(tsNumOfVnodeStreamThreads, 4); if (cfgAddInt32(pCfg, "numOfVnodeStreamThreads", tsNumOfVnodeStreamThreads, 4, 1024, 0) != 0) return -1; - // tsNumOfVnodeFetchThreads = 1; - // if (cfgAddInt32(pCfg, "numOfVnodeFetchThreads", tsNumOfVnodeFetchThreads, 1, 1, 0) != 0) return -1; + tsNumOfVnodeFetchThreads = tsNumOfCores / 4; + tsNumOfVnodeFetchThreads = TMAX(tsNumOfVnodeFetchThreads, 4); + if (cfgAddInt32(pCfg, "numOfVnodeFetchThreads", tsNumOfVnodeFetchThreads, 4, 1024, 0) != 0) return -1; tsNumOfVnodeWriteThreads = tsNumOfCores; tsNumOfVnodeWriteThreads = TMAX(tsNumOfVnodeWriteThreads, 1); @@ -502,15 +488,13 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - /* - pItem = cfgGetItem(tsCfg, "numOfVnodeFetchThreads"); - if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsNumOfVnodeFetchThreads = numOfCores / 4; - tsNumOfVnodeFetchThreads = TMAX(tsNumOfVnodeFetchThreads, 4); - pItem->i32 = tsNumOfVnodeFetchThreads; - pItem->stype = stype; - } - */ + pItem = cfgGetItem(tsCfg, "numOfVnodeFetchThreads"); + if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { + tsNumOfVnodeFetchThreads = numOfCores / 4; + tsNumOfVnodeFetchThreads = TMAX(tsNumOfVnodeFetchThreads, 4); + pItem->i32 = tsNumOfVnodeFetchThreads; + pItem->stype = stype; + } pItem = cfgGetItem(tsCfg, "numOfVnodeWriteThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { @@ -698,20 +682,12 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsQueryBufferSize = cfgGetItem(pCfg, "queryBufferSize")->i32; tsPrintAuth = cfgGetItem(pCfg, "printAuth")->bval; -#if !defined(WINDOWS) && !defined(DARWIN) - tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->bval; -#endif - tsMnodeShmSize = cfgGetItem(pCfg, "mnodeShmSize")->i32; - tsVnodeShmSize = cfgGetItem(pCfg, "vnodeShmSize")->i32; - tsQnodeShmSize = cfgGetItem(pCfg, "qnodeShmSize")->i32; - tsSnodeShmSize = cfgGetItem(pCfg, "snodeShmSize")->i32; - tsNumOfRpcThreads = cfgGetItem(pCfg, "numOfRpcThreads")->i32; tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32; tsNumOfMnodeReadThreads = cfgGetItem(pCfg, "numOfMnodeReadThreads")->i32; tsNumOfVnodeQueryThreads = cfgGetItem(pCfg, "numOfVnodeQueryThreads")->i32; tsNumOfVnodeStreamThreads = cfgGetItem(pCfg, "numOfVnodeStreamThreads")->i32; - // tsNumOfVnodeFetchThreads = cfgGetItem(pCfg, "numOfVnodeFetchThreads")->i32; + tsNumOfVnodeFetchThreads = cfgGetItem(pCfg, "numOfVnodeFetchThreads")->i32; tsNumOfVnodeWriteThreads = cfgGetItem(pCfg, "numOfVnodeWriteThreads")->i32; tsNumOfVnodeSyncThreads = cfgGetItem(pCfg, "numOfVnodeSyncThreads")->i32; tsNumOfVnodeRsmaThreads = cfgGetItem(pCfg, "numOfVnodeRsmaThreads")->i32; @@ -903,12 +879,6 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { } break; } - case 'n': { - if (strcasecmp("mnodeShmSize", name) == 0) { - tsMnodeShmSize = cfgGetItem(pCfg, "mnodeShmSize")->i32; - } - break; - } case 'o': { if (strcasecmp("monitor", name) == 0) { tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval; @@ -932,11 +902,7 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { break; } case 'u': { - if (strcasecmp("multiProcess", name) == 0) { -#if !defined(WINDOWS) && !defined(DARWIN) - tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->bval; -#endif - } else if (strcasecmp("udfDebugFlag", name) == 0) { + if (strcasecmp("udfDebugFlag", name) == 0) { udfDebugFlag = cfgGetItem(pCfg, "udfDebugFlag")->i32; } break; @@ -999,8 +965,6 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { if (tsQueryBufferSize >= 0) { tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; } - } else if (strcasecmp("qnodeShmSize", name) == 0) { - tsQnodeShmSize = cfgGetItem(pCfg, "qnodeShmSize")->i32; } else if (strcasecmp("qDebugFlag", name) == 0) { qDebugFlag = cfgGetItem(pCfg, "qDebugFlag")->i32; } else if (strcasecmp("queryPlannerTrace", name) == 0) { @@ -1041,8 +1005,6 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { tsNumOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32; } else if (strcasecmp("statusInterval", name) == 0) { tsStatusInterval = cfgGetItem(pCfg, "statusInterval")->i32; - } else if (strcasecmp("snodeShmSize", name) == 0) { - tsSnodeShmSize = cfgGetItem(pCfg, "snodeShmSize")->i32; } else if (strcasecmp("serverPort", name) == 0) { tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN); tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; @@ -1110,9 +1072,7 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { break; } case 'v': { - if (strcasecmp("vnodeShmSize", name) == 0) { - tsVnodeShmSize = cfgGetItem(pCfg, "vnodeShmSize")->i32; - } else if (strcasecmp("vDebugFlag", name) == 0) { + if (strcasecmp("vDebugFlag", name) == 0) { vDebugFlag = cfgGetItem(pCfg, "vDebugFlag")->i32; } break; @@ -1235,6 +1195,7 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile if (cfgLoadFromArray(tsCfg, pArgs) != 0) { uError("failed to load cfg from array since %s", terrstr()); cfgCleanup(tsCfg); + tsCfg = NULL; return -1; } diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 44a3f27983a34f5fe61ba9f854b1973552c7556b..6784b05e84293fef20e026cddf73c2d99744194b 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -993,7 +993,8 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { for (int32_t i = 0; i < vlen; ++i) { SVnodeLoad *pload = taosArrayGet(pReq->pVloads, i); if (tEncodeI32(&encoder, pload->vgId) < 0) return -1; - if (tEncodeI32(&encoder, pload->syncState) < 0) return -1; + if (tEncodeI8(&encoder, pload->syncState) < 0) return -1; + if (tEncodeI8(&encoder, pload->syncRestore) < 0) return -1; if (tEncodeI64(&encoder, pload->cacheUsage) < 0) return -1; if (tEncodeI64(&encoder, pload->numOfTables) < 0) return -1; if (tEncodeI64(&encoder, pload->numOfTimeSeries) < 0) return -1; @@ -1003,7 +1004,8 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { } // mnode loads - if (tEncodeI32(&encoder, pReq->mload.syncState) < 0) return -1; + if (tEncodeI8(&encoder, pReq->mload.syncState) < 0) return -1; + if (tEncodeI8(&encoder, pReq->mload.syncRestore) < 0) return -1; if (tEncodeI32(&encoder, pReq->qload.dnodeId) < 0) return -1; if (tEncodeI64(&encoder, pReq->qload.numOfProcessedQuery) < 0) return -1; @@ -1063,7 +1065,8 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { for (int32_t i = 0; i < vlen; ++i) { SVnodeLoad vload = {0}; if (tDecodeI32(&decoder, &vload.vgId) < 0) return -1; - if (tDecodeI32(&decoder, &vload.syncState) < 0) return -1; + if (tDecodeI8(&decoder, &vload.syncState) < 0) return -1; + if (tDecodeI8(&decoder, &vload.syncRestore) < 0) return -1; if (tDecodeI64(&decoder, &vload.cacheUsage) < 0) return -1; if (tDecodeI64(&decoder, &vload.numOfTables) < 0) return -1; if (tDecodeI64(&decoder, &vload.numOfTimeSeries) < 0) return -1; @@ -1076,7 +1079,8 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { } } - if (tDecodeI32(&decoder, &pReq->mload.syncState) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->mload.syncState) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->mload.syncRestore) < 0) return -1; if (tDecodeI32(&decoder, &pReq->qload.dnodeId) < 0) return -1; if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedQuery) < 0) return -1; @@ -2761,6 +2765,7 @@ int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) { if (tEncodeI32(&encoder, pRsp->numOfVgroups) < 0) return -1; if (tEncodeI32(&encoder, pRsp->numOfStables) < 0) return -1; if (tEncodeI32(&encoder, pRsp->buffer) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->cacheSize) < 0) return -1; if (tEncodeI32(&encoder, pRsp->pageSize) < 0) return -1; if (tEncodeI32(&encoder, pRsp->pages) < 0) return -1; if (tEncodeI32(&encoder, pRsp->daysPerFile) < 0) return -1; @@ -2800,6 +2805,7 @@ int32_t tDeserializeSDbCfgRsp(void *buf, int32_t bufLen, SDbCfgRsp *pRsp) { if (tDecodeI32(&decoder, &pRsp->numOfVgroups) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->numOfStables) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->buffer) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->cacheSize) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->pageSize) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->pages) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->daysPerFile) < 0) return -1; @@ -3762,7 +3768,6 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR if (tEncodeI8(&encoder, pReq->compression) < 0) return -1; if (tEncodeI8(&encoder, pReq->strict) < 0) return -1; if (tEncodeI8(&encoder, pReq->cacheLast) < 0) return -1; - if (tEncodeI8(&encoder, pReq->standby) < 0) return -1; if (tEncodeI8(&encoder, pReq->replica) < 0) return -1; if (tEncodeI8(&encoder, pReq->selfIndex) < 0) return -1; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { @@ -3791,6 +3796,9 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR if (tEncodeI16(&encoder, pReq->hashPrefix) < 0) return -1; if (tEncodeI16(&encoder, pReq->hashSuffix) < 0) return -1; if (tEncodeI32(&encoder, pReq->tsdbPageSize) < 0) return -1; + for (int32_t i = 0; i < 8; ++i) { + if (tEncodeI64(&encoder, pReq->reserved[i]) < 0) return -1; + } tEndEncode(&encoder); @@ -3828,7 +3836,6 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq * if (tDecodeI8(&decoder, &pReq->compression) < 0) return -1; if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1; if (tDecodeI8(&decoder, &pReq->cacheLast) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->standby) < 0) return -1; if (tDecodeI8(&decoder, &pReq->replica) < 0) return -1; if (tDecodeI8(&decoder, &pReq->selfIndex) < 0) return -1; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { @@ -3867,6 +3874,9 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq * if (tDecodeI16(&decoder, &pReq->hashPrefix) < 0) return -1; if (tDecodeI16(&decoder, &pReq->hashSuffix) < 0) return -1; if (tDecodeI32(&decoder, &pReq->tsdbPageSize) < 0) return -1; + for (int32_t i = 0; i < 8; ++i) { + if (tDecodeI64(&decoder, &pReq->reserved[i]) < 0) return -1; + } tEndDecode(&decoder); tDecoderClear(&decoder); @@ -3888,6 +3898,9 @@ int32_t tSerializeSDropVnodeReq(void *buf, int32_t bufLen, SDropVnodeReq *pReq) if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1; if (tEncodeI64(&encoder, pReq->dbUid) < 0) return -1; if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; + for (int32_t i = 0; i < 8; ++i) { + if (tEncodeI64(&encoder, pReq->reserved[i]) < 0) return -1; + } tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -3904,6 +3917,9 @@ int32_t tDeserializeSDropVnodeReq(void *buf, int32_t bufLen, SDropVnodeReq *pReq if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1; if (tDecodeI64(&decoder, &pReq->dbUid) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; + for (int32_t i = 0; i < 8; ++i) { + if (tDecodeI64(&decoder, &pReq->reserved[i]) < 0) return -1; + } tEndDecode(&decoder); tDecoderClear(&decoder); @@ -3917,6 +3933,9 @@ int32_t tSerializeSCompactVnodeReq(void *buf, int32_t bufLen, SCompactVnodeReq * if (tStartEncode(&encoder) < 0) return -1; if (tEncodeI64(&encoder, pReq->dbUid) < 0) return -1; if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; + for (int32_t i = 0; i < 8; ++i) { + if (tEncodeI64(&encoder, pReq->reserved[i]) < 0) return -1; + } tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -3931,13 +3950,16 @@ int32_t tDeserializeSCompactVnodeReq(void *buf, int32_t bufLen, SCompactVnodeReq if (tStartDecode(&decoder) < 0) return -1; if (tDecodeI64(&decoder, &pReq->dbUid) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; + for (int32_t i = 0; i < 8; ++i) { + if (tDecodeI64(&decoder, &pReq->reserved[i]) < 0) return -1; + } tEndDecode(&decoder); tDecoderClear(&decoder); return 0; } -int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq) { +int32_t tSerializeSAlterVnodeConfigReq(void *buf, int32_t bufLen, SAlterVnodeConfigReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); @@ -3955,11 +3977,8 @@ int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1; if (tEncodeI8(&encoder, pReq->strict) < 0) return -1; if (tEncodeI8(&encoder, pReq->cacheLast) < 0) return -1; - if (tEncodeI8(&encoder, pReq->selfIndex) < 0) return -1; - if (tEncodeI8(&encoder, pReq->replica) < 0) return -1; - for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { - SReplica *pReplica = &pReq->replicas[i]; - if (tEncodeSReplica(&encoder, pReplica) < 0) return -1; + for (int32_t i = 0; i < 8; ++i) { + if (tEncodeI64(&encoder, pReq->reserved[i]) < 0) return -1; } tEndEncode(&encoder); @@ -3968,7 +3987,7 @@ int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq return tlen; } -int32_t tDeserializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq) { +int32_t tDeserializeSAlterVnodeConfigReq(void *buf, int32_t bufLen, SAlterVnodeConfigReq *pReq) { SDecoder decoder = {0}; tDecoderInit(&decoder, buf, bufLen); @@ -3986,12 +4005,54 @@ int32_t tDeserializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pR if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1; if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1; if (tDecodeI8(&decoder, &pReq->cacheLast) < 0) return -1; + for (int32_t i = 0; i < 8; ++i) { + if (tDecodeI64(&decoder, &pReq->reserved[i]) < 0) return -1; + } + + tEndDecode(&decoder); + tDecoderClear(&decoder); + return 0; +} + +int32_t tSerializeSAlterVnodeReplicaReq(void *buf, int32_t bufLen, SAlterVnodeReplicaReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeI32(&encoder, pReq->vgId) < 0) return -1; + if (tEncodeI8(&encoder, pReq->strict) < 0) return -1; + if (tEncodeI8(&encoder, pReq->selfIndex) < 0) return -1; + if (tEncodeI8(&encoder, pReq->replica) < 0) return -1; + for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { + SReplica *pReplica = &pReq->replicas[i]; + if (tEncodeSReplica(&encoder, pReplica) < 0) return -1; + } + for (int32_t i = 0; i < 8; ++i) { + if (tEncodeI64(&encoder, pReq->reserved[i]) < 0) return -1; + } + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSAlterVnodeReplicaReq(void *buf, int32_t bufLen, SAlterVnodeReplicaReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->vgId) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1; if (tDecodeI8(&decoder, &pReq->selfIndex) < 0) return -1; if (tDecodeI8(&decoder, &pReq->replica) < 0) return -1; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { SReplica *pReplica = &pReq->replicas[i]; if (tDecodeSReplica(&decoder, pReplica) < 0) return -1; } + for (int32_t i = 0; i < 8; ++i) { + if (tDecodeI64(&decoder, &pReq->reserved[i]) < 0) return -1; + } tEndDecode(&decoder); tDecoderClear(&decoder); @@ -4214,33 +4275,6 @@ int32_t tDeserializeSDCreateMnodeReq(void *buf, int32_t bufLen, SDCreateMnodeReq return 0; } -int32_t tSerializeSSetStandbyReq(void *buf, int32_t bufLen, SSetStandbyReq *pReq) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1; - if (tEncodeI8(&encoder, pReq->standby) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSSetStandbyReq(void *buf, int32_t bufLen, SSetStandbyReq *pReq) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->standby) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - int32_t tSerializeSAuthReq(void *buf, int32_t bufLen, SAuthReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); diff --git a/source/common/src/trow.c b/source/common/src/trow.c index e1085ce5d81a0c7f33ff5721ef1f69a0f128abab..b007075efe863943020f9d2bc4f1b771c93115c4 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -41,286 +41,6 @@ static bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, col_id_t colIdx, SCe static void tdSCellValPrint(SCellVal *pVal, int8_t colType); // implementation -/** - * @brief Compress bitmap bytes comprised of 2-bits to counterpart of 1-bit. - * e.g. - * TD_VTYPE_NORM 0x00U(00000000) to 00000000 Normal - * TD_VTYPE_NULL 0x01U(00000001) to 00000001 Null - * TD_VTYPE_NONE 0x02U(00000010) to 00000001 Null - * - * 00000000 0x00 0x00 - * 01000000 0x40 0x08 - * 10000000 0x80 0x08 - * ... - * @param byte - * @return uint8_t - */ -static uint8_t tdGetMergedBitmapByte(uint8_t byte) { - switch (byte) { - case 0x00: - return 0x00; - case 0x40: - return 0x08; - case 0x80: - return 0x08; - case 0x10: - return 0x04; - case 0x50: - return 0x0c; - case 0x90: - return 0x0c; - case 0x20: - return 0x04; - case 0x60: - return 0x0c; - case 0xa0: - return 0x0c; - case 0x04: - return 0x02; - case 0x44: - return 0x0a; - case 0x84: - return 0x0a; - case 0x14: - return 0x06; - case 0x54: - return 0x0e; - case 0x94: - return 0x0e; - case 0x24: - return 0x06; - case 0x64: - return 0x0e; - case 0xa4: - return 0x0e; - case 0x08: - return 0x02; - case 0x48: - return 0x0a; - case 0x88: - return 0x0a; - case 0x18: - return 0x06; - case 0x58: - return 0x0e; - case 0x98: - return 0x0e; - case 0x28: - return 0x06; - case 0x68: - return 0x0e; - case 0xa8: - return 0x0e; - case 0x01: - return 0x01; - case 0x41: - return 0x09; - case 0x81: - return 0x09; - case 0x11: - return 0x05; - case 0x51: - return 0x0d; - case 0x91: - return 0x0d; - case 0x21: - return 0x05; - case 0x61: - return 0x0d; - case 0xa1: - return 0x0d; - case 0x05: - return 0x03; - case 0x45: - return 0x0b; - case 0x85: - return 0x0b; - case 0x15: - return 0x07; - case 0x55: - return 0x0f; - case 0x95: - return 0x0f; - case 0x25: - return 0x07; - case 0x65: - return 0x0f; - case 0xa5: - return 0x0f; - case 0x09: - return 0x03; - case 0x49: - return 0x0b; - case 0x89: - return 0x0b; - case 0x19: - return 0x07; - case 0x59: - return 0x0f; - case 0x99: - return 0x0f; - case 0x29: - return 0x07; - case 0x69: - return 0x0f; - case 0xa9: - return 0x0f; - case 0x02: - return 0x01; - case 0x42: - return 0x09; - case 0x82: - return 0x09; - case 0x12: - return 0x05; - case 0x52: - return 0x0d; - case 0x92: - return 0x0d; - case 0x22: - return 0x05; - case 0x62: - return 0x0d; - case 0xa2: - return 0x0d; - case 0x06: - return 0x03; - case 0x46: - return 0x0b; - case 0x86: - return 0x0b; - case 0x16: - return 0x07; - case 0x56: - return 0x0f; - case 0x96: - return 0x0f; - case 0x26: - return 0x07; - case 0x66: - return 0x0f; - case 0xa6: - return 0x0f; - case 0x0a: - return 0x03; - case 0x4a: - return 0x0b; - case 0x8a: - return 0x0b; - case 0x1a: - return 0x07; - case 0x5a: - return 0x0f; - case 0x9a: - return 0x0f; - case 0x2a: - return 0x07; - case 0x6a: - return 0x0f; - case 0xaa: - return 0x0f; - default: - // make sure the bitmap area is set to 0 firstly - ASSERT(0); - return 0x0f; // return NULL bitmap for exception - } -} - -/** - * @brief Merge bitmap from 2 bits to 1 bit, and the memory buffer should be guaranteed by the invoker. - * - * @param srcBitmap - * @param nBits - * @param dstBitmap - */ -void tdMergeBitmap(uint8_t *srcBitmap, int32_t nBits, uint8_t *dstBitmap) { - int32_t i = 0, j = 0; - int32_t nBytes = TD_BITMAP_BYTES(nBits); - int32_t nRoundBytes = nBits / 4; - int32_t nRemainderBits = nBits - nRoundBytes * 4; - - switch (nRemainderBits) { - case 0: - // NOTHING TODO - break; - case 1: { - void *lastByte = POINTER_SHIFT(srcBitmap, nRoundBytes); - *(uint8_t *)lastByte &= 0xC0; - } break; - case 2: { - void *lastByte = POINTER_SHIFT(srcBitmap, nRoundBytes); - *(uint8_t *)lastByte &= 0xF0; - } break; - case 3: { - void *lastByte = POINTER_SHIFT(srcBitmap, nRoundBytes); - *(uint8_t *)lastByte &= 0xFC; - } break; - default: - ASSERT(0); - } - - if (nBytes > 0) { - dstBitmap[j] = (tdGetMergedBitmapByte(srcBitmap[i]) << 4); - } - - while ((++i) < nBytes) { - if ((i & 1) == 0) { - dstBitmap[j] = (tdGetMergedBitmapByte(srcBitmap[i]) << 4); - } else { - dstBitmap[j] |= tdGetMergedBitmapByte(srcBitmap[i]); - ++j; - } - } -} - -/** - * @brief Set bitmap area by byte preferentially and then by bit. - * - * @param pBitmap - * @param nEle - * @param valType - * @param bitmapMode 0 for 2 bits, 1 for 1 bit - * @return int32_t - */ -int32_t tdSetBitmapValTypeN(void *pBitmap, int16_t nEle, TDRowValT valType, int8_t bitmapMode) { - TASSERT(valType < TD_VTYPE_MAX); - int32_t nBytes = (bitmapMode == 0 ? nEle / TD_VTYPE_PARTS : nEle / TD_VTYPE_PARTS_I); - uint8_t vTypeByte = tdVTypeByte[bitmapMode][valType]; - for (int i = 0; i < nBytes; ++i) { - *(uint8_t *)pBitmap = vTypeByte; - pBitmap = POINTER_SHIFT(pBitmap, 1); - } - - int32_t nLeft = nEle - nBytes * (bitmapMode == 0 ? TD_VTYPE_BITS : TD_VTYPE_BITS_I); - for (int j = 0; j < nLeft; ++j) { - tdSetBitmapValType(pBitmap, j, valType, bitmapMode); - } - return TSDB_CODE_SUCCESS; -} - -bool tdIsBitmapBlkNorm(const void *pBitmap, int32_t numOfBits, int8_t bitmapMode) { - int32_t nBytes = (bitmapMode == 0 ? numOfBits / TD_VTYPE_PARTS : numOfBits / TD_VTYPE_PARTS_I); - uint8_t vTypeByte = tdVTypeByte[bitmapMode][TD_VTYPE_NORM]; - uint8_t *qBitmap = (uint8_t *)pBitmap; - for (int i = 0; i < nBytes; ++i) { - if (*qBitmap != vTypeByte) { - return false; - } - qBitmap = (uint8_t *)POINTER_SHIFT(pBitmap, i); - } - - int32_t nLeft = numOfBits - nBytes * (bitmapMode == 0 ? TD_VTYPE_BITS : TD_VTYPE_BITS_I); - - for (int j = 0; j < nLeft; ++j) { - uint8_t vType; - tdGetBitmapValType(qBitmap, j, &vType, bitmapMode); - if (vType != TD_VTYPE_NORM) { - return false; - } - } - return true; -} - STSRow *tdRowDup(STSRow *row) { STSRow *trow = taosMemoryMalloc(TD_ROW_LEN(row)); if (trow == NULL) return NULL; @@ -761,7 +481,7 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCell int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) { if (!pBitmap || colIdx < 0) { - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -783,7 +503,7 @@ int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pVa *pValType = ((*pDestByte) & 0x03); break; default: - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -792,7 +512,7 @@ int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pVa int32_t tdGetBitmapValTypeI(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) { if (!pBitmap || colIdx < 0) { - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -826,7 +546,7 @@ int32_t tdGetBitmapValTypeI(const void *pBitmap, int16_t colIdx, TDRowValT *pVal *pValType = ((*pDestByte) & 0x01); break; default: - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -835,7 +555,7 @@ int32_t tdGetBitmapValTypeI(const void *pBitmap, int16_t colIdx, TDRowValT *pVal int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT valType) { if (!pBitmap || colIdx < 0) { - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -878,7 +598,7 @@ int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT valType) { // *pDestByte |= (valType); break; default: - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -887,7 +607,7 @@ int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT valType) { int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int32_t offset, int16_t colIdx) { #ifdef TD_SUPPORT_BITMAP - TASSERT(colIdx < tdRowGetNCols(pRow) - 1); + ASSERT(colIdx < tdRowGetNCols(pRow) - 1); if (tdGetBitmapValType(pBitmap, colIdx, &output->valType, 0) != TSDB_CODE_SUCCESS) { output->valType = TD_VTYPE_NONE; return terrno; @@ -901,7 +621,7 @@ int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int32_ output->val = POINTER_SHIFT(pRow, offset); } #else - TASSERT(0); + ASSERT(0); if (offset < 0) { terrno = TSDB_CODE_INVALID_PARA; output->valType = TD_VTYPE_NONE; @@ -951,7 +671,7 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp return terrno; } #else - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; #endif @@ -989,7 +709,7 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val, bool isCopyVarData, int8_t colType, int16_t colIdx, int32_t offset, col_id_t colId) { if ((offset < (int32_t)sizeof(SKvRowIdx)) || (colIdx < 1)) { - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -1078,7 +798,7 @@ int32_t tdSRowSetExtendedInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBou pBuilder->nCols = nCols; pBuilder->nBoundCols = nBoundCols; if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) { - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -1100,7 +820,7 @@ int32_t tdSRowSetExtendedInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBou int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) { pBuilder->pBuf = (STSRow *)pBuf; if (!pBuilder->pBuf) { - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -1111,7 +831,7 @@ int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) { TD_ROW_SET_INFO(pBuilder->pBuf, 0); TD_ROW_SET_TYPE(pBuilder->pBuf, pBuilder->rowType); - TASSERT(pBuilder->nBitmaps > 0 && pBuilder->flen > 0); + ASSERT(pBuilder->nBitmaps > 0 && pBuilder->flen > 0); uint32_t len = 0; switch (pBuilder->rowType) { @@ -1137,7 +857,7 @@ int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) { TD_ROW_SET_NCOLS(pBuilder->pBuf, pBuilder->nBoundCols); break; default: - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -1148,12 +868,12 @@ int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) { int32_t tdSRowGetBuf(SRowBuilder *pBuilder, void *pBuf) { pBuilder->pBuf = (STSRow *)pBuf; if (!pBuilder->pBuf) { - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } - TASSERT(pBuilder->nBitmaps > 0 && pBuilder->flen > 0); + ASSERT(pBuilder->nBitmaps > 0 && pBuilder->flen > 0); uint32_t len = 0; switch (pBuilder->rowType) { @@ -1168,7 +888,7 @@ int32_t tdSRowGetBuf(SRowBuilder *pBuilder, void *pBuf) { #endif break; default: - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -1188,7 +908,7 @@ int32_t tdSRowSetTpInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t flen) { pBuilder->flen = flen; pBuilder->nCols = nCols; if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) { - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -1207,7 +927,7 @@ int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols, pBuilder->nCols = nCols; pBuilder->nBoundCols = nBoundCols; if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) { - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -1236,13 +956,13 @@ int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValT tdGetBitmapValTypeI(pBitmap, colIdx, pValType); break; default: - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return TSDB_CODE_FAILED; } return TSDB_CODE_SUCCESS; } - +#if 0 bool tdIsBitmapValTypeNorm(const void *pBitmap, int16_t idx, int8_t bitmapMode) { TDRowValT valType = 0; tdGetBitmapValType(pBitmap, idx, &valType, bitmapMode); @@ -1251,10 +971,11 @@ bool tdIsBitmapValTypeNorm(const void *pBitmap, int16_t idx, int8_t bitmapMode) } return false; } +#endif int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT valType) { if (!pBitmap || colIdx < 0) { - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -1281,7 +1002,7 @@ int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT valType) { // *pDestByte |= (valType); break; default: - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -1298,7 +1019,7 @@ int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType, int tdSetBitmapValTypeI(pBitmap, colIdx, valType); break; default: - TASSERT(0); + ASSERT(0); terrno = TSDB_CODE_INVALID_PARA; return TSDB_CODE_FAILED; } diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index bb82863e738c1a2e4ed801892a9c2ae9f1fd4da1..e0cc5bd311926a7beb76a1bf9cf6e257a7805fa4 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -244,8 +244,7 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) { * 2013-04-12T15:52:01.123+0800 */ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, char delim) { - int64_t factor = - (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); + int64_t factor = TSDB_TICK_PER_SECOND(timePrec); int64_t tzOffset = 0; struct tm tm = {0}; @@ -339,8 +338,8 @@ static FORCE_INLINE bool validateTm(struct tm* pTm) { return true; } -int32_t parseLocaltime(char* timestr, int32_t len, int64_t* time, int32_t timePrec, char delim) { - *time = 0; +int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) { + *utime = 0; struct tm tm = {0}; char* str; @@ -378,15 +377,12 @@ int32_t parseLocaltime(char* timestr, int32_t len, int64_t* time, int32_t timePr } } - int64_t factor = - (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); - *time = factor * seconds + fraction; - + *utime = TSDB_TICK_PER_SECOND(timePrec) * seconds + fraction; return 0; } -int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* time, int32_t timePrec, char delim) { - *time = 0; +int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) { + *utime = 0; struct tm tm = {0}; tm.tm_isdst = -1; @@ -411,7 +407,6 @@ int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* time, int32_t tim int64_t seconds = taosMktime(&tm); int64_t fraction = 0; - if (*str == '.') { /* parse the second fraction part */ if ((fraction = parseFraction(str + 1, &str, timePrec)) < 0) { @@ -419,9 +414,7 @@ int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* time, int32_t tim } } - int64_t factor = - (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); - *time = factor * seconds + fraction; + *utime = TSDB_TICK_PER_SECOND(timePrec) * seconds + fraction; return 0; } @@ -437,58 +430,61 @@ char getPrecisionUnit(int32_t precision) { } } -int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision) { - assert(fromPrecision == TSDB_TIME_PRECISION_MILLI || fromPrecision == TSDB_TIME_PRECISION_MICRO || +int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPrecision) { + ASSERT(fromPrecision == TSDB_TIME_PRECISION_MILLI || fromPrecision == TSDB_TIME_PRECISION_MICRO || fromPrecision == TSDB_TIME_PRECISION_NANO); - assert(toPrecision == TSDB_TIME_PRECISION_MILLI || toPrecision == TSDB_TIME_PRECISION_MICRO || + ASSERT(toPrecision == TSDB_TIME_PRECISION_MILLI || toPrecision == TSDB_TIME_PRECISION_MICRO || toPrecision == TSDB_TIME_PRECISION_NANO); - double tempResult = (double)time; + + double tempResult = (double)utime; + switch (fromPrecision) { case TSDB_TIME_PRECISION_MILLI: { switch (toPrecision) { case TSDB_TIME_PRECISION_MILLI: - return time; + return utime; case TSDB_TIME_PRECISION_MICRO: tempResult *= 1000; - time *= 1000; + utime *= 1000; goto end_; case TSDB_TIME_PRECISION_NANO: tempResult *= 1000000; - time *= 1000000; + utime *= 1000000; goto end_; } } // end from milli case TSDB_TIME_PRECISION_MICRO: { switch (toPrecision) { case TSDB_TIME_PRECISION_MILLI: - return time / 1000; + return utime / 1000; case TSDB_TIME_PRECISION_MICRO: - return time; + return utime; case TSDB_TIME_PRECISION_NANO: tempResult *= 1000; - time *= 1000; + utime *= 1000; goto end_; } } // end from micro case TSDB_TIME_PRECISION_NANO: { switch (toPrecision) { case TSDB_TIME_PRECISION_MILLI: - return time / 1000000; + return utime / 1000000; case TSDB_TIME_PRECISION_MICRO: - return time / 1000; + return utime / 1000; case TSDB_TIME_PRECISION_NANO: - return time; + return utime; } } // end from nano default: { assert(0); - return time; // only to pass windows compilation + return utime; // only to pass windows compilation } } // end switch fromPrecision + end_: if (tempResult >= (double)INT64_MAX) return INT64_MAX; if (tempResult <= (double)INT64_MIN) return INT64_MIN; // INT64_MIN means NULL - return time; + return utime; } // !!!!notice:there are precision problems, double lose precison if time is too large, for example: diff --git a/source/common/src/ttypes.c b/source/common/src/ttypes.c index fee89e2f37e3afeec0959b1d78b9a73745573edc..a4e7a12ce4eb10c6a3dd380ea8a88611232f9d7f 100644 --- a/source/common/src/ttypes.c +++ b/source/common/src/ttypes.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "ttypes.h" #include "tcompression.h" -#include "trow.h" const int32_t TYPE_BYTES[16] = { -1, // TSDB_DATA_TYPE_NULL @@ -37,394 +36,30 @@ const int32_t TYPE_BYTES[16] = { TSDB_MAX_JSON_TAG_LEN, // TSDB_DATA_TYPE_JSON }; -#define DO_STATICS(__sum, __min, __max, __minIndex, __maxIndex, _list, _index) \ - do { \ - (__sum) += (_list)[(_index)]; \ - if ((__min) > (_list)[(_index)]) { \ - (__min) = (_list)[(_index)]; \ - (__minIndex) = (_index); \ - } \ - \ - if ((__max) < (_list)[(_index)]) { \ - (__max) = (_list)[(_index)]; \ - (__maxIndex) = (_index); \ - } \ - } while (0) - -static void getStatics_bool(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - int8_t *data = (int8_t *)pData; - *min = INT64_MAX; - *max = INT64_MIN; - *minIndex = 0; - *maxIndex = 0; - - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if (data[i] == TSDB_DATA_BOOL_NULL) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - continue; - } - - DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i); - } -} - -static void getStatics_i8(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - int8_t *data = (int8_t *)pData; - *min = INT64_MAX; - *max = INT64_MIN; - *minIndex = 0; - *maxIndex = 0; - - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if (((uint8_t)data[i]) == TSDB_DATA_TINYINT_NULL) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - continue; - } - - DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i); - } -} - -static void getStatics_u8(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - uint8_t *data = (uint8_t *)pData; - uint64_t _min = UINT64_MAX; - uint64_t _max = 0; - uint64_t _sum = 0; - - *minIndex = 0; - *maxIndex = 0; - - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if (((uint8_t)data[i]) == TSDB_DATA_UTINYINT_NULL) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - continue; - } - - DO_STATICS(_sum, _min, _max, *minIndex, *maxIndex, data, i); - } - - *min = _min; - *max = _max; - *sum = _sum; -} - -static void getStatics_i16(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - int16_t *data = (int16_t *)pData; - *min = INT64_MAX; - *max = INT64_MIN; - *minIndex = 0; - *maxIndex = 0; - - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if (((uint16_t)data[i]) == TSDB_DATA_SMALLINT_NULL) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - continue; - } - - DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i); - } -} - -static void getStatics_u16(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - uint16_t *data = (uint16_t *)pData; - uint64_t _min = UINT64_MAX; - uint64_t _max = 0; - uint64_t _sum = 0; - - *minIndex = 0; - *maxIndex = 0; - - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if (((uint16_t)data[i]) == TSDB_DATA_USMALLINT_NULL) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - continue; - } - - DO_STATICS(_sum, _min, _max, *minIndex, *maxIndex, data, i); - } - - *min = _min; - *max = _max; - *sum = _sum; -} - -static void getStatics_i32(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - int32_t *data = (int32_t *)pData; - *min = INT64_MAX; - *max = INT64_MIN; - *minIndex = 0; - *maxIndex = 0; - - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if (((uint32_t)data[i]) == TSDB_DATA_INT_NULL) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - continue; - } - - DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i); - } -} - -static void getStatics_u32(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - uint32_t *data = (uint32_t *)pData; - uint64_t _min = UINT64_MAX; - uint64_t _max = 0; - uint64_t _sum = 0; - - *minIndex = 0; - *maxIndex = 0; - - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if (((uint32_t)data[i]) == TSDB_DATA_UINT_NULL) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - continue; - } - - DO_STATICS(_sum, _min, _max, *minIndex, *maxIndex, data, i); - } - - *min = _min; - *max = _max; - *sum = _sum; -} - -static void getStatics_i64(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - int64_t *data = (int64_t *)pData; - *min = INT64_MAX; - *max = INT64_MIN; - *minIndex = 0; - *maxIndex = 0; - - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if (((uint64_t)data[i]) == TSDB_DATA_BIGINT_NULL) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - continue; - } - - DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i); - } -} - -static void getStatics_u64(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - uint64_t *data = (uint64_t *)pData; - uint64_t _min = UINT64_MAX; - uint64_t _max = 0; - uint64_t _sum = 0; - - *minIndex = 0; - *maxIndex = 0; - - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if (((uint64_t)data[i]) == TSDB_DATA_UBIGINT_NULL) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - continue; - } - - DO_STATICS(_sum, _min, _max, *minIndex, *maxIndex, data, i); - } - - *min = _min; - *max = _max; - *sum = _sum; -} - -static void getStatics_f(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - float *data = (float *)pData; - float fmin = FLT_MAX; - float fmax = -FLT_MAX; - double dsum = 0; - *minIndex = 0; - *maxIndex = 0; - - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if ((*(uint32_t *)&(data[i])) == TSDB_DATA_FLOAT_NULL) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - continue; - } - - float fv = GET_FLOAT_VAL((const char *)&(data[i])); - - dsum += fv; - if (fmin > fv) { - fmin = fv; - *minIndex = i; - } - - if (fmax < fv) { - fmax = fv; - *maxIndex = i; - } - } - - SET_DOUBLE_VAL(sum, dsum); - SET_DOUBLE_VAL(max, fmax); - SET_DOUBLE_VAL(min, fmin); -} - -static void getStatics_d(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - double *data = (double *)pData; - double dmin = DBL_MAX; - double dmax = -DBL_MAX; - double dsum = 0; - *minIndex = 0; - *maxIndex = 0; - - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if ((*(uint64_t *)&(data[i])) == TSDB_DATA_DOUBLE_NULL) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - continue; - } - - double dv = 0; - dv = GET_DOUBLE_VAL((const char *)&(data[i])); - dsum += dv; - if (dmin > dv) { - dmin = dv; - *minIndex = i; - } - - if (dmax < dv) { - dmax = dv; - *maxIndex = i; - } - } - - SET_DOUBLE_PTR(sum, &dsum); - SET_DOUBLE_PTR(max, &dmax); - SET_DOUBLE_PTR(min, &dmin); -} - -static void getStatics_bin(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - const char *data = pData; - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if (isNull(data, TSDB_DATA_TYPE_BINARY)) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - } - - data += varDataTLen(data); - } - - *sum = 0; - *max = 0; - *min = 0; - *minIndex = 0; - *maxIndex = 0; -} - -static void getStatics_nchr(int8_t bitmapMode, const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, - int64_t *max, int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) { - const char *data = pData; - assert(numOfRow <= INT16_MAX); - - for (int32_t i = 0; i < numOfRow; ++i) { - // if (isNull(data, TSDB_DATA_TYPE_NCHAR)) { - if (!tdIsBitmapValTypeNorm(pBitmap, i, bitmapMode)) { - (*numOfNull) += 1; - } - - data += varDataTLen(data); - } - - *sum = 0; - *max = 0; - *min = 0; - *minIndex = 0; - *maxIndex = 0; -} - tDataTypeDescriptor tDataTypes[TSDB_DATA_TYPE_MAX] = { - {TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE", 0, 0, NULL, NULL, NULL}, - {TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", false, true, tsCompressBool, tsDecompressBool, getStatics_bool}, - {TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT", INT8_MIN, INT8_MAX, tsCompressTinyint, tsDecompressTinyint, - getStatics_i8}, + {TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE", 0, 0, NULL, NULL}, + {TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", false, true, tsCompressBool, tsDecompressBool}, + {TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT", INT8_MIN, INT8_MAX, tsCompressTinyint, tsDecompressTinyint}, {TSDB_DATA_TYPE_SMALLINT, 8, SHORT_BYTES, "SMALLINT", INT16_MIN, INT16_MAX, tsCompressSmallint, - tsDecompressSmallint, getStatics_i16}, - {TSDB_DATA_TYPE_INT, 3, INT_BYTES, "INT", INT32_MIN, INT32_MAX, tsCompressInt, tsDecompressInt, getStatics_i32}, - {TSDB_DATA_TYPE_BIGINT, 6, LONG_BYTES, "BIGINT", INT64_MIN, INT64_MAX, tsCompressBigint, tsDecompressBigint, - getStatics_i64}, - {TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT", 0, 0, tsCompressFloat, tsDecompressFloat, getStatics_f}, - {TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE", 0, 0, tsCompressDouble, tsDecompressDouble, getStatics_d}, - {TSDB_DATA_TYPE_VARCHAR, 6, 1, "VARCHAR", 0, 0, tsCompressString, tsDecompressString, getStatics_bin}, + tsDecompressSmallint}, + {TSDB_DATA_TYPE_INT, 3, INT_BYTES, "INT", INT32_MIN, INT32_MAX, tsCompressInt, tsDecompressInt}, + {TSDB_DATA_TYPE_BIGINT, 6, LONG_BYTES, "BIGINT", INT64_MIN, INT64_MAX, tsCompressBigint, tsDecompressBigint}, + {TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT", 0, 0, tsCompressFloat, tsDecompressFloat}, + {TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE", 0, 0, tsCompressDouble, tsDecompressDouble}, + {TSDB_DATA_TYPE_VARCHAR, 6, 1, "VARCHAR", 0, 0, tsCompressString, tsDecompressString}, {TSDB_DATA_TYPE_TIMESTAMP, 9, LONG_BYTES, "TIMESTAMP", INT64_MIN, INT64_MAX, tsCompressTimestamp, - tsDecompressTimestamp, getStatics_i64}, - {TSDB_DATA_TYPE_NCHAR, 5, 1, "NCHAR", 0, 0, tsCompressString, tsDecompressString, getStatics_nchr}, - {TSDB_DATA_TYPE_UTINYINT, 16, CHAR_BYTES, "TINYINT UNSIGNED", 0, UINT8_MAX, tsCompressTinyint, tsDecompressTinyint, - getStatics_u8}, + tsDecompressTimestamp}, + {TSDB_DATA_TYPE_NCHAR, 5, 1, "NCHAR", 0, 0, tsCompressString, tsDecompressString}, + {TSDB_DATA_TYPE_UTINYINT, 16, CHAR_BYTES, "TINYINT UNSIGNED", 0, UINT8_MAX, tsCompressTinyint, tsDecompressTinyint}, {TSDB_DATA_TYPE_USMALLINT, 17, SHORT_BYTES, "SMALLINT UNSIGNED", 0, UINT16_MAX, tsCompressSmallint, - tsDecompressSmallint, getStatics_u16}, - {TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", 0, UINT32_MAX, tsCompressInt, tsDecompressInt, getStatics_u32}, - {TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", 0, UINT64_MAX, tsCompressBigint, tsDecompressBigint, - getStatics_u64}, - {TSDB_DATA_TYPE_JSON, 4, TSDB_MAX_JSON_TAG_LEN, "JSON", 0, 0, tsCompressString, tsDecompressString, - getStatics_nchr}, + tsDecompressSmallint}, + {TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", 0, UINT32_MAX, tsCompressInt, tsDecompressInt}, + {TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", 0, UINT64_MAX, tsCompressBigint, tsDecompressBigint}, + {TSDB_DATA_TYPE_JSON, 4, TSDB_MAX_JSON_TAG_LEN, "JSON", 0, 0, tsCompressString, tsDecompressString}, }; -char tTokenTypeSwitcher[13] = { - TSDB_DATA_TYPE_NULL, // no type - TSDB_DATA_TYPE_BINARY, // TK_ID - TSDB_DATA_TYPE_BOOL, // TK_BOOL - TSDB_DATA_TYPE_BIGINT, // TK_TINYINT - TSDB_DATA_TYPE_BIGINT, // TK_SMALLINT - TSDB_DATA_TYPE_BIGINT, // TK_INTEGER - TSDB_DATA_TYPE_BIGINT, // TK_BIGINT - TSDB_DATA_TYPE_DOUBLE, // TK_FLOAT - TSDB_DATA_TYPE_DOUBLE, // TK_DOUBLE - TSDB_DATA_TYPE_BINARY, // TK_STRING - TSDB_DATA_TYPE_BIGINT, // TK_TIMESTAMP - TSDB_DATA_TYPE_VARCHAR, // TK_BINARY - TSDB_DATA_TYPE_NCHAR, // TK_NCHAR -}; - -float floatMin = -FLT_MAX, floatMax = FLT_MAX; -double doubleMin = -DBL_MAX, doubleMax = DBL_MAX; +static float floatMin = -FLT_MAX, floatMax = FLT_MAX; +static double doubleMin = -DBL_MAX, doubleMax = DBL_MAX; FORCE_INLINE void *getDataMin(int32_t type) { switch (type) { @@ -450,119 +85,8 @@ FORCE_INLINE void *getDataMax(int32_t type) { bool isValidDataType(int32_t type) { return type >= TSDB_DATA_TYPE_NULL && type < TSDB_DATA_TYPE_MAX; } -void setVardataNull(void *val, int32_t type) { - if (type == TSDB_DATA_TYPE_BINARY) { - varDataSetLen(val, sizeof(int8_t)); - *(uint8_t *)varDataVal(val) = TSDB_DATA_BINARY_NULL; - } else if (type == TSDB_DATA_TYPE_NCHAR) { - varDataSetLen(val, sizeof(int32_t)); - *(uint32_t *)varDataVal(val) = TSDB_DATA_NCHAR_NULL; - } else { - assert(0); - } -} - -void setNull(void *val, int32_t type, int32_t bytes) { setNullN(val, type, bytes, 1); } - #define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b))) -void setNullN(void *val, int32_t type, int32_t bytes, int32_t numOfElems) { - switch (type) { - case TSDB_DATA_TYPE_BOOL: - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint8_t *)(POINTER_SHIFT(val, i * tDataTypes[type].bytes)) = TSDB_DATA_BOOL_NULL; - } - break; - case TSDB_DATA_TYPE_TINYINT: - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint8_t *)(POINTER_SHIFT(val, i * tDataTypes[type].bytes)) = TSDB_DATA_TINYINT_NULL; - } - break; - case TSDB_DATA_TYPE_SMALLINT: - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint16_t *)(POINTER_SHIFT(val, i * tDataTypes[type].bytes)) = TSDB_DATA_SMALLINT_NULL; - } - break; - case TSDB_DATA_TYPE_INT: - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint32_t *)(POINTER_SHIFT(val, i * tDataTypes[type].bytes)) = TSDB_DATA_INT_NULL; - } - break; - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_TIMESTAMP: - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint64_t *)(POINTER_SHIFT(val, i * tDataTypes[type].bytes)) = TSDB_DATA_BIGINT_NULL; - } - break; - case TSDB_DATA_TYPE_UTINYINT: - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint8_t *)(POINTER_SHIFT(val, i * tDataTypes[type].bytes)) = TSDB_DATA_UTINYINT_NULL; - } - break; - case TSDB_DATA_TYPE_USMALLINT: - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint16_t *)(POINTER_SHIFT(val, i * tDataTypes[type].bytes)) = TSDB_DATA_USMALLINT_NULL; - } - break; - case TSDB_DATA_TYPE_UINT: - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint32_t *)(POINTER_SHIFT(val, i * tDataTypes[type].bytes)) = TSDB_DATA_UINT_NULL; - } - break; - case TSDB_DATA_TYPE_UBIGINT: - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint64_t *)(POINTER_SHIFT(val, i * tDataTypes[type].bytes)) = TSDB_DATA_UBIGINT_NULL; - } - break; - case TSDB_DATA_TYPE_FLOAT: - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint32_t *)(POINTER_SHIFT(val, i * tDataTypes[type].bytes)) = TSDB_DATA_FLOAT_NULL; - } - break; - case TSDB_DATA_TYPE_DOUBLE: - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint64_t *)(POINTER_SHIFT(val, i * tDataTypes[type].bytes)) = TSDB_DATA_DOUBLE_NULL; - } - break; - case TSDB_DATA_TYPE_NCHAR: - case TSDB_DATA_TYPE_BINARY: - for (int32_t i = 0; i < numOfElems; ++i) { - setVardataNull(POINTER_SHIFT(val, i * bytes), type); - } - break; - default: { - for (int32_t i = 0; i < numOfElems; ++i) { - *(uint32_t *)(POINTER_SHIFT(val, i * tDataTypes[TSDB_DATA_TYPE_INT].bytes)) = TSDB_DATA_INT_NULL; - } - break; - } - } -} - -static uint8_t nullBool = TSDB_DATA_BOOL_NULL; -static uint8_t nullTinyInt = TSDB_DATA_TINYINT_NULL; -static uint16_t nullSmallInt = TSDB_DATA_SMALLINT_NULL; -static uint32_t nullInt = TSDB_DATA_INT_NULL; -static uint64_t nullBigInt = TSDB_DATA_BIGINT_NULL; -static uint32_t nullFloat = TSDB_DATA_FLOAT_NULL; -static uint64_t nullDouble = TSDB_DATA_DOUBLE_NULL; -static uint8_t nullTinyIntu = TSDB_DATA_UTINYINT_NULL; -static uint16_t nullSmallIntu = TSDB_DATA_USMALLINT_NULL; -static uint32_t nullIntu = TSDB_DATA_UINT_NULL; -static uint64_t nullBigIntu = TSDB_DATA_UBIGINT_NULL; -static SBinaryNullT nullBinary = {1, TSDB_DATA_BINARY_NULL}; -static SNCharNullT nullNchar = {4, TSDB_DATA_NCHAR_NULL}; - -static const void *nullValues[] = { - &nullBool, &nullTinyInt, &nullSmallInt, &nullInt, &nullBigInt, &nullFloat, &nullDouble, - &nullBinary, &nullBigInt, &nullNchar, &nullTinyIntu, &nullSmallIntu, &nullIntu, &nullBigIntu, -}; - -const void *getNullValue(int32_t type) { - assert(type >= TSDB_DATA_TYPE_BOOL && type <= TSDB_DATA_TYPE_UBIGINT); // TODO: extend the types - return nullValues[type - 1]; -} - void assignVal(char *val, const char *src, int32_t len, int32_t type) { switch (type) { case TSDB_DATA_TYPE_BOOL: @@ -648,48 +172,3 @@ void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type) { assert(0); } } - -void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void *buf) { - switch (type) { - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_UINT: { - TSWAP(*(int32_t *)(pLeft), *(int32_t *)(pRight)); - break; - } - - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: - case TSDB_DATA_TYPE_TIMESTAMP: { - TSWAP(*(int64_t *)(pLeft), *(int64_t *)(pRight)); - break; - } - case TSDB_DATA_TYPE_DOUBLE: { - TSWAP(*(double *)(pLeft), *(double *)(pRight)); - break; - } - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_USMALLINT: { - TSWAP(*(int16_t *)(pLeft), *(int16_t *)(pRight)); - break; - } - - case TSDB_DATA_TYPE_FLOAT: { - TSWAP(*(float *)(pLeft), *(float *)(pRight)); - break; - } - - case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: { - TSWAP(*(int8_t *)(pLeft), *(int8_t *)(pRight)); - break; - } - - default: { - memcpy(buf, pLeft, size); - memcpy(pLeft, pRight, size); - memcpy(pRight, buf, size); - break; - } - } -} diff --git a/source/common/src/tvariant.c b/source/common/src/tvariant.c index 9660a37f48f36ac55b7fca3caaa16257a925f08f..8d4c17a82132bf63f646de52885ec0d7a25ad61e 100644 --- a/source/common/src/tvariant.c +++ b/source/common/src/tvariant.c @@ -19,22 +19,6 @@ #include "ttokendef.h" #include "tvariant.h" -#define SET_EXT_INFO(converted, res, minv, maxv, exti) \ - do { \ - if (converted == NULL || exti == NULL || *converted == false) { \ - break; \ - } \ - if ((res) < (minv)) { \ - *exti = -1; \ - break; \ - } \ - if ((res) > (maxv)) { \ - *exti = 1; \ - break; \ - } \ - assert(0); \ - } while (0) - int32_t toInteger(const char *z, int32_t n, int32_t base, int64_t *value) { errno = 0; char *endPtr = NULL; @@ -53,8 +37,8 @@ int32_t toUInteger(const char *z, int32_t n, int32_t base, uint64_t *value) { char *endPtr = NULL; const char *p = z; - while (*p != 0 && *p == ' ') p++; - if (*p != 0 && *p == '-') { + while (*p == ' ') p++; + if (*p == '-') { return -1; } @@ -176,11 +160,6 @@ void taosVariantDestroy(SVariant *pVar) { } } -bool taosVariantIsValid(SVariant *pVar) { - assert(pVar != NULL); - return isValidDataType(pVar->nType); -} - void taosVariantAssign(SVariant *pDst, const SVariant *pSrc) { if (pSrc == NULL || pDst == NULL) return; @@ -265,702 +244,6 @@ int32_t taosVariantCompare(const SVariant *p1, const SVariant *p2) { } } -int32_t taosVariantToString(SVariant *pVar, char *dst) { - if (pVar == NULL || dst == NULL) return 0; - - switch (pVar->nType) { - case TSDB_DATA_TYPE_BINARY: { - int32_t len = sprintf(dst, "\'%s\'", pVar->pz); - assert(len <= pVar->nLen + sizeof("\'") * 2); // two more chars - return len; - } - - case TSDB_DATA_TYPE_NCHAR: { - dst[0] = '\''; - taosUcs4ToMbs(pVar->ucs4, (taosUcs4len(pVar->ucs4) + 1) * TSDB_NCHAR_SIZE, dst + 1); - int32_t len = (int32_t)strlen(dst); - dst[len] = '\''; - dst[len + 1] = 0; - return len + 1; - } - - case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_UTINYINT: - case TSDB_DATA_TYPE_USMALLINT: - case TSDB_DATA_TYPE_UINT: - return sprintf(dst, "%d", (int32_t)pVar->i); - - case TSDB_DATA_TYPE_BIGINT: - return sprintf(dst, "%" PRId64, pVar->i); - case TSDB_DATA_TYPE_UBIGINT: - return sprintf(dst, "%" PRIu64, pVar->u); - case TSDB_DATA_TYPE_FLOAT: - case TSDB_DATA_TYPE_DOUBLE: - return sprintf(dst, "%.9lf", pVar->d); - - default: - return 0; - } -} - -static FORCE_INLINE int32_t convertToBoolImpl(char *pStr, int32_t len) { - if ((strncasecmp(pStr, "true", len) == 0) && (len == 4)) { - return TSDB_TRUE; - } else if ((strncasecmp(pStr, "false", len) == 0) && (len == 5)) { - return TSDB_FALSE; - } else if (strcasecmp(pStr, TSDB_DATA_NULL_STR_L) == 0) { - return TSDB_DATA_BOOL_NULL; - } else { - return -1; - } -} - -static FORCE_INLINE int32_t wcsconvertToBoolImpl(TdUcs4 *pstr, int32_t len) { - if ((wcsncasecmp(pstr, L"true", len) == 0) && (len == 4)) { - return TSDB_TRUE; - } else if (wcsncasecmp(pstr, L"false", len) == 0 && (len == 5)) { - return TSDB_FALSE; - } else if (memcmp(pstr, L"null", wcslen(L"null")) == 0) { - return TSDB_DATA_BOOL_NULL; - } else { - return -1; - } -} - -static int32_t toBinary(SVariant *pVariant, char **pDest, int32_t *pDestSize) { - const int32_t INITIAL_ALLOC_SIZE = 40; - char *pBuf = NULL; - - // it is a in-place convert type for SVariant, local buffer is needed - if (*pDest == pVariant->pz) { - pBuf = taosMemoryCalloc(1, INITIAL_ALLOC_SIZE); - } - - if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { - size_t newSize = pVariant->nLen * TSDB_NCHAR_SIZE; - if (pBuf != NULL) { - if (newSize >= INITIAL_ALLOC_SIZE) { - pBuf = taosMemoryRealloc(pBuf, newSize + 1); - } - - taosUcs4ToMbs(pVariant->ucs4, (int32_t)newSize, pBuf); - taosMemoryFree(pVariant->ucs4); - pBuf[newSize] = 0; - } else { - taosUcs4ToMbs(pVariant->ucs4, (int32_t)newSize, *pDest); - } - - } else { - if (IS_SIGNED_NUMERIC_TYPE(pVariant->nType)) { - sprintf(pBuf == NULL ? *pDest : pBuf, "%" PRId64, pVariant->i); - } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { - sprintf(pBuf == NULL ? *pDest : pBuf, "%lf", pVariant->d); - } else if (pVariant->nType == TSDB_DATA_TYPE_BOOL) { - sprintf(pBuf == NULL ? *pDest : pBuf, "%s", (pVariant->i == TSDB_TRUE) ? "TRUE" : "FALSE"); - } else if (pVariant->nType == 0) { // null data - setNull(pBuf == NULL ? *pDest : pBuf, TSDB_DATA_TYPE_BINARY, 0); - } - } - - if (pBuf != NULL) { - taosMemoryFree(pVariant->pz); - *pDest = pBuf; - } - - *pDestSize = (int32_t)strlen(*pDest); - return 0; -} - -static int32_t toNchar(SVariant *pVariant, char **pDest, int32_t *pDestSize) { - char tmpBuf[40] = {0}; - - char *pDst = tmpBuf; - int32_t nLen = 0; - - // convert the number to string, than convert it to wchar string. - if (IS_SIGNED_NUMERIC_TYPE(pVariant->nType)) { - nLen = sprintf(pDst, "%" PRId64, pVariant->i); - } else if (IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) { - nLen = sprintf(pDst, "%" PRIu64, pVariant->u); - } else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) { - nLen = sprintf(pDst, "%lf", pVariant->d); - } else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - pDst = pVariant->pz; - nLen = pVariant->nLen; - } else if (pVariant->nType == TSDB_DATA_TYPE_BOOL) { - nLen = sprintf(pDst, "%s", (pVariant->i == TSDB_TRUE) ? "TRUE" : "FALSE"); - } - - if (*pDest == pVariant->pz) { - TdUcs4 *pWStr = taosMemoryCalloc(1, (nLen + 1) * TSDB_NCHAR_SIZE); - bool ret = taosMbsToUcs4(pDst, nLen, pWStr, (nLen + 1) * TSDB_NCHAR_SIZE, NULL); - if (!ret) { - taosMemoryFreeClear(pWStr); - return -1; - } - - // free the binary buffer in the first place - if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - taosMemoryFree(pVariant->ucs4); - } - - pVariant->ucs4 = pWStr; - *pDestSize = taosUcs4len(pVariant->ucs4); - - // shrink the allocate memory, no need to check here. - char *tmp = taosMemoryRealloc(pVariant->ucs4, (*pDestSize + 1) * TSDB_NCHAR_SIZE); - assert(tmp != NULL); - - pVariant->ucs4 = (TdUcs4 *)tmp; - } else { - int32_t output = 0; - - bool ret = taosMbsToUcs4(pDst, nLen, (TdUcs4 *)*pDest, (nLen + 1) * TSDB_NCHAR_SIZE, &output); - if (!ret) { - return -1; - } - - if (pDestSize != NULL) { - *pDestSize = output; - } - } - - return 0; -} - -static FORCE_INLINE int32_t convertToDouble(char *pStr, int32_t len, double *value) { - // SToken stoken = {.z = pStr, .n = len}; - // if (TK_ILLEGAL == tGetNumericStringType(&stoken)) { - // return -1; - // } - // - // *value = taosStr2Double(pStr, NULL); - return 0; -} - -static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result, int32_t type, bool issigned, - bool releaseVariantPtr, bool *converted) { - if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - setNull((char *)result, type, tDataTypes[type].bytes); - return 0; - } - - if (IS_SIGNED_NUMERIC_TYPE(pVariant->nType) || (pVariant->nType == TSDB_DATA_TYPE_BOOL)) { - *result = pVariant->i; - } else if (IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) { - *result = pVariant->u; - } else if (IS_FLOAT_TYPE(pVariant->nType)) { - *result = (int64_t)pVariant->d; - } else { - // TODO: handling var types - } -#if 0 - errno = 0; - if (IS_SIGNED_NUMERIC_TYPE(pVariant->nType) || (pVariant->nType == TSDB_DATA_TYPE_BOOL)) { - *result = pVariant->i; - } else if (IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) { - *result = pVariant->u; - } else if (IS_FLOAT_TYPE(pVariant->nType)) { - *result = (int64_t) pVariant->d; - } else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - SToken token = {.z = pVariant->pz, .n = pVariant->nLen}; - /*int32_t n = */tGetToken(pVariant->pz, &token.type); - - if (token.type == TK_NULL) { - if (releaseVariantPtr) { - taosMemoryFree(pVariant->pz); - pVariant->nLen = 0; - } - - setNull((char *)result, type, tDataTypes[type].bytes); - return 0; - } - - // decide if it is a valid number - token.type = tGetNumericStringType(&token); - if (token.type == TK_ILLEGAL) { - return -1; - } - - int64_t res = 0; - int32_t t = tStrToInteger(token.z, token.type, token.n, &res, issigned); - if (t != 0) { - return -1; - } - - if (releaseVariantPtr) { - taosMemoryFree(pVariant->pz); - pVariant->nLen = 0; - } - - *result = res; - } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { - errno = 0; - TdUcs4 *endPtr = NULL; - - SToken token = {0}; - token.n = tGetToken(pVariant->pz, &token.type); - - if (token.type == TK_MINUS || token.type == TK_PLUS) { - token.n = tGetToken(pVariant->pz + token.n, &token.type); - } - - if (token.type == TK_FLOAT) { - double v = wcstod(pVariant->ucs4, &endPtr); - if (releaseVariantPtr) { - taosMemoryFree(pVariant->pz); - pVariant->nLen = 0; - } - - if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { - return -1; - } - - *result = (int64_t)v; - } else if (token.type == TK_NULL) { - if (releaseVariantPtr) { - taosMemoryFree(pVariant->pz); - pVariant->nLen = 0; - } - setNull((char *)result, type, tDataTypes[type].bytes); - return 0; - } else { - int64_t val = wcstoll(pVariant->ucs4, &endPtr, 10); - if (releaseVariantPtr) { - taosMemoryFree(pVariant->pz); - pVariant->nLen = 0; - } - - if (errno == ERANGE) { - return -1; // data overflow - } - - *result = val; - } - } - - if (converted) { - *converted = true; - } - - bool code = false; - - uint64_t ui = 0; - switch(type) { - case TSDB_DATA_TYPE_TINYINT: - code = IS_VALID_TINYINT(*result); break; - case TSDB_DATA_TYPE_SMALLINT: - code = IS_VALID_SMALLINT(*result); break; - case TSDB_DATA_TYPE_INT: - code = IS_VALID_INT(*result); break; - case TSDB_DATA_TYPE_BIGINT: - code = IS_VALID_BIGINT(*result); break; - case TSDB_DATA_TYPE_UTINYINT: - ui = *result; - code = IS_VALID_UTINYINT(ui); break; - case TSDB_DATA_TYPE_USMALLINT: - ui = *result; - code = IS_VALID_USMALLINT(ui); break; - case TSDB_DATA_TYPE_UINT: - ui = *result; - code = IS_VALID_UINT(ui); break; - case TSDB_DATA_TYPE_UBIGINT: - ui = *result; - code = IS_VALID_UBIGINT(ui); break; - } - - - return code? 0:-1; -#endif - return 0; -} - -static int32_t convertToBool(SVariant *pVariant, int64_t *pDest) { - if (pVariant->nType == TSDB_DATA_TYPE_BOOL) { - *pDest = pVariant->i; // in order to be compatible to null of bool - } else if (IS_NUMERIC_TYPE(pVariant->nType)) { - *pDest = ((pVariant->i != 0) ? TSDB_TRUE : TSDB_FALSE); - } else if (pVariant->nType == TSDB_DATA_TYPE_FLOAT || pVariant->nType == TSDB_DATA_TYPE_DOUBLE) { - *pDest = ((pVariant->d != 0) ? TSDB_TRUE : TSDB_FALSE); - } else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - int32_t ret = 0; - if ((ret = convertToBoolImpl(pVariant->pz, pVariant->nLen)) < 0) { - return ret; - } - - *pDest = ret; - } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { - int32_t ret = 0; - if ((ret = wcsconvertToBoolImpl(pVariant->ucs4, pVariant->nLen)) < 0) { - return ret; - } - *pDest = ret; - } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *pDest = TSDB_DATA_BOOL_NULL; - } - - assert(*pDest == TSDB_TRUE || *pDest == TSDB_FALSE || *pDest == TSDB_DATA_BOOL_NULL); - return 0; -} - -/* - * transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType - * to column type defined in schema - */ -int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix, bool *converted, - char *extInfo) { - if (converted) { - *converted = false; - } - - if (pVariant == NULL || (pVariant->nType != 0 && !isValidDataType(pVariant->nType))) { - return -1; - } - - errno = 0; // reset global error code - int64_t result = 0; - - switch (type) { - case TSDB_DATA_TYPE_BOOL: { - if (convertToBool(pVariant, &result) < 0) { - return -1; - } - - *(int8_t *)payload = (int8_t)result; - break; - } - - case TSDB_DATA_TYPE_TINYINT: { - if (convertToInteger(pVariant, &result, type, true, false, converted) < 0) { - SET_EXT_INFO(converted, result, INT8_MIN + 1, INT8_MAX, extInfo); - return -1; - } - *((int8_t *)payload) = (int8_t)result; - break; - } - - case TSDB_DATA_TYPE_UTINYINT: { - if (convertToInteger(pVariant, &result, type, false, false, converted) < 0) { - SET_EXT_INFO(converted, result, 0, UINT8_MAX - 1, extInfo); - return -1; - } - *((uint8_t *)payload) = (uint8_t)result; - break; - } - - case TSDB_DATA_TYPE_SMALLINT: { - if (convertToInteger(pVariant, &result, type, true, false, converted) < 0) { - SET_EXT_INFO(converted, result, INT16_MIN + 1, INT16_MAX, extInfo); - return -1; - } - *((int16_t *)payload) = (int16_t)result; - break; - } - - case TSDB_DATA_TYPE_USMALLINT: { - if (convertToInteger(pVariant, &result, type, false, false, converted) < 0) { - SET_EXT_INFO(converted, result, 0, UINT16_MAX - 1, extInfo); - return -1; - } - *((uint16_t *)payload) = (uint16_t)result; - break; - } - - case TSDB_DATA_TYPE_INT: { - if (convertToInteger(pVariant, &result, type, true, false, converted) < 0) { - SET_EXT_INFO(converted, result, INT32_MIN + 1, INT32_MAX, extInfo); - return -1; - } - *((int32_t *)payload) = (int32_t)result; - break; - } - - case TSDB_DATA_TYPE_UINT: { - if (convertToInteger(pVariant, &result, type, false, false, converted) < 0) { - SET_EXT_INFO(converted, result, 0, UINT32_MAX - 1, extInfo); - return -1; - } - *((uint32_t *)payload) = (uint32_t)result; - break; - } - - case TSDB_DATA_TYPE_BIGINT: { - if (convertToInteger(pVariant, &result, type, true, false, converted) < 0) { - SET_EXT_INFO(converted, result, INT64_MIN + 1, INT64_MAX, extInfo); - return -1; - } - *((int64_t *)payload) = (int64_t)result; - break; - } - - case TSDB_DATA_TYPE_UBIGINT: { - if (convertToInteger(pVariant, &result, type, false, false, converted) < 0) { - SET_EXT_INFO(converted, result, 0, UINT64_MAX - 1, extInfo); - return -1; - } - *((uint64_t *)payload) = (uint64_t)result; - break; - } - - case TSDB_DATA_TYPE_FLOAT: { - if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - if (strncasecmp(TSDB_DATA_NULL_STR_L, pVariant->pz, pVariant->nLen) == 0 && - strlen(TSDB_DATA_NULL_STR_L) == pVariant->nLen) { - *((int32_t *)payload) = TSDB_DATA_FLOAT_NULL; - return 0; - } else { - double value = -1; - int32_t ret = convertToDouble(pVariant->pz, pVariant->nLen, &value); - if ((errno == ERANGE && (float)value == -1) || (ret != 0)) { - return -1; - } - - if (converted) { - *converted = true; - } - - if (value > FLT_MAX || value < -FLT_MAX) { - SET_EXT_INFO(converted, value, -FLT_MAX, FLT_MAX, extInfo); - return -1; - } - SET_FLOAT_VAL(payload, value); - } - } else if (pVariant->nType == TSDB_DATA_TYPE_BOOL || IS_SIGNED_NUMERIC_TYPE(pVariant->nType) || - IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) { - if (converted) { - *converted = true; - } - - if (pVariant->i > FLT_MAX || pVariant->i < -FLT_MAX) { - SET_EXT_INFO(converted, pVariant->i, -FLT_MAX, FLT_MAX, extInfo); - return -1; - } - - SET_FLOAT_VAL(payload, pVariant->i); - } else if (IS_FLOAT_TYPE(pVariant->nType)) { - if (converted) { - *converted = true; - } - - if (pVariant->d > FLT_MAX || pVariant->d < -FLT_MAX) { - SET_EXT_INFO(converted, pVariant->d, -FLT_MAX, FLT_MAX, extInfo); - return -1; - } - - SET_FLOAT_VAL(payload, pVariant->d); - } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *((uint32_t *)payload) = TSDB_DATA_FLOAT_NULL; - return 0; - } - - float fv = GET_FLOAT_VAL(payload); - if (isinf(fv) || isnan(fv) || fv > FLT_MAX || fv < -FLT_MAX) { - return -1; - } - break; - } - case TSDB_DATA_TYPE_DOUBLE: { - if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - if (strncasecmp(TSDB_DATA_NULL_STR_L, pVariant->pz, pVariant->nLen) == 0 && - strlen(TSDB_DATA_NULL_STR_L) == pVariant->nLen) { - *((int64_t *)payload) = TSDB_DATA_DOUBLE_NULL; - return 0; - } else { - double value = 0; - int32_t ret; - ret = convertToDouble(pVariant->pz, pVariant->nLen, &value); - if ((errno == ERANGE && value == -1) || (ret != 0)) { - return -1; - } - - SET_DOUBLE_VAL(payload, value); - } - } else if (pVariant->nType == TSDB_DATA_TYPE_BOOL || IS_SIGNED_NUMERIC_TYPE(pVariant->nType) || - IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) { - SET_DOUBLE_VAL(payload, pVariant->i); - } else if (IS_FLOAT_TYPE(pVariant->nType)) { - SET_DOUBLE_VAL(payload, pVariant->d); - } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *((int64_t *)payload) = TSDB_DATA_DOUBLE_NULL; - return 0; - } - - double dv = GET_DOUBLE_VAL(payload); - if (errno == ERANGE || isinf(dv) || isnan(dv)) { - return -1; - } - - break; - } - - case TSDB_DATA_TYPE_BINARY: { - if (!includeLengthPrefix) { - if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *(uint8_t *)payload = TSDB_DATA_BINARY_NULL; - } else { - if (pVariant->nType != TSDB_DATA_TYPE_BINARY) { - toBinary(pVariant, &payload, &pVariant->nLen); - } else { - strncpy(payload, pVariant->pz, pVariant->nLen); - } - } - } else { - if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - setVardataNull(payload, TSDB_DATA_TYPE_BINARY); - } else { - char *p = varDataVal(payload); - - if (pVariant->nType != TSDB_DATA_TYPE_BINARY) { - toBinary(pVariant, &p, &pVariant->nLen); - } else { - strncpy(p, pVariant->pz, pVariant->nLen); - } - - varDataSetLen(payload, pVariant->nLen); - assert(p == varDataVal(payload)); - } - } - break; - } - case TSDB_DATA_TYPE_TIMESTAMP: { - if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *((int64_t *)payload) = TSDB_DATA_BIGINT_NULL; - } else { - *((int64_t *)payload) = pVariant->i; - } - break; - } - case TSDB_DATA_TYPE_NCHAR: { - int32_t newlen = 0; - if (!includeLengthPrefix) { - if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - *(uint32_t *)payload = TSDB_DATA_NCHAR_NULL; - } else { - if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) { - if (toNchar(pVariant, &payload, &newlen) != 0) { - return -1; - } - } else { - tasoUcs4Copy((TdUcs4 *)payload, pVariant->ucs4, pVariant->nLen); - } - } - } else { - if (pVariant->nType == TSDB_DATA_TYPE_NULL) { - setVardataNull(payload, TSDB_DATA_TYPE_NCHAR); - } else { - char *p = varDataVal(payload); - - if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) { - if (toNchar(pVariant, &p, &newlen) != 0) { - return -1; - } - } else { - memcpy(p, pVariant->ucs4, pVariant->nLen); - newlen = pVariant->nLen; - } - - varDataSetLen(payload, newlen); // the length may be changed after toNchar function called - assert(p == varDataVal(payload)); - } - } - - break; - } - } - - return 0; -} - -/* - * transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType - * to column type defined in schema - */ -int32_t taosVariantDump(SVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix) { - return tVariantDumpEx(pVariant, payload, type, includeLengthPrefix, NULL, NULL); -} - -/* - * In variant, bool/smallint/tinyint/int/bigint share the same attribution of - * structure, also ignore the convert the type required - * - * It is actually the bigint/binary/bool/nchar type transfer - */ -int32_t taosVariantTypeSetType(SVariant *pVariant, char type) { - if (pVariant == NULL || pVariant->nType == 0) { // value is not set - return 0; - } - - switch (type) { - case TSDB_DATA_TYPE_BOOL: { // bool - if (convertToBool(pVariant, &pVariant->i) < 0) { - return -1; - } - - pVariant->nType = type; - break; - } - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_SMALLINT: { - convertToInteger(pVariant, &(pVariant->i), type, true, true, NULL); - pVariant->nType = TSDB_DATA_TYPE_BIGINT; - break; - } - case TSDB_DATA_TYPE_FLOAT: - case TSDB_DATA_TYPE_DOUBLE: { - if (pVariant->nType == TSDB_DATA_TYPE_BINARY) { - errno = 0; - double v = taosStr2Double(pVariant->pz, NULL); - if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { - taosMemoryFree(pVariant->pz); - return -1; - } - - taosMemoryFree(pVariant->pz); - pVariant->d = v; - } else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { - errno = 0; - double v = wcstod(pVariant->ucs4, NULL); - if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) { - taosMemoryFree(pVariant->pz); - return -1; - } - - taosMemoryFree(pVariant->pz); - pVariant->d = v; - } else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { - double tmp = (double)pVariant->i; - pVariant->d = tmp; - } - - pVariant->nType = TSDB_DATA_TYPE_DOUBLE; - break; - } - case TSDB_DATA_TYPE_BINARY: { - if (pVariant->nType != TSDB_DATA_TYPE_BINARY) { - toBinary(pVariant, &pVariant->pz, &pVariant->nLen); - } - pVariant->nType = type; - break; - } - case TSDB_DATA_TYPE_NCHAR: { - if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) { - if (toNchar(pVariant, &pVariant->pz, &pVariant->nLen) != 0) { - return -1; - } - } - pVariant->nType = type; - break; - } - } - - return 0; -} - char *taosVariantGet(SVariant *pVar, int32_t type) { switch (type) { case TSDB_DATA_TYPE_BOOL: diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index acc3fc56581420a1a2d253dd1db40fc760a2c7c9..188677656a512be254815709532611013b805745 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -25,7 +25,6 @@ #define DM_SDB_INFO "Dump sdb info." #define DM_ENV_CMD "The env cmd variable string to use when configuring the server, such as: -e 'TAOS_FQDN=td1'." #define DM_ENV_FILE "The env variable file path to use when configuring the server, default is './.env', .env text can be 'TAOS_FQDN=td1'." -#define DM_NODE_TYPE "Startup type of the node, default is 0." #define DM_MACHINE_CODE "Get machine code." #define DM_VERSION "Print program version." #define DM_EMAIL "" @@ -44,7 +43,6 @@ static struct { char apolloUrl[PATH_MAX]; const char **envCmd; SArray *pArgs; // SConfigPair - EDndNodeType ntype; } global = {0}; static void dmStopDnode(int signum, void *info, void *ctx) { dmStop(); } @@ -59,13 +57,6 @@ static void dmSetSignalHandle() { taosSetSignal(SIGTSTP, dmStopDnode); taosSetSignal(SIGQUIT, dmStopDnode); #endif - - if (!tsMultiProcess) { - } else if (global.ntype == DNODE || global.ntype == NODE_END) { - taosIgnSignal(SIGCHLD); - } else { - taosKillChildOnParentStopped(); - } } static int32_t dmParseArgs(int32_t argc, char const *argv[]) { @@ -91,12 +82,6 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { global.dumpSdb = true; } else if (strcmp(argv[i], "-E") == 0) { tstrncpy(global.envFile, argv[++i], PATH_MAX); - } else if (strcmp(argv[i], "-n") == 0) { - global.ntype = atoi(argv[++i]); - if (global.ntype <= DNODE || global.ntype > NODE_END) { - printf("'-n' range is [1 - %d], default is 0\n", NODE_END - 1); - return -1; - } } else if (strcmp(argv[i], "-k") == 0) { global.generateGrant = true; } else if (strcmp(argv[i], "-C") == 0) { @@ -142,7 +127,6 @@ static void dmPrintHelp() { printf("%s%s%s%s\n", indent, "-C,", indent, DM_DMP_CFG); printf("%s%s%s%s\n", indent, "-e,", indent, DM_ENV_CMD); printf("%s%s%s%s\n", indent, "-E,", indent, DM_ENV_FILE); - printf("%s%s%s%s\n", indent, "-n,", indent, DM_NODE_TYPE); printf("%s%s%s%s\n", indent, "-k,", indent, DM_MACHINE_CODE); printf("%s%s%s%s\n", indent, "-V,", indent, DM_VERSION); @@ -155,17 +139,7 @@ static void dmDumpCfg() { } static int32_t dmInitLog() { - char logName[12] = {0}; - snprintf(logName, sizeof(logName), "%slog", dmNodeLogName(global.ntype)); - return taosCreateLog(logName, 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0); -} - -static void dmSetProcInfo(int32_t argc, char **argv) { - taosSetProcPath(argc, argv); - if (global.ntype != DNODE && global.ntype != NODE_END) { - const char *name = dmNodeProcName(global.ntype); - taosSetProcName(argc, argv, name); - } + return taosCreateLog("taosdlog", 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0); } static void taosCleanupArgs() { @@ -234,6 +208,7 @@ int mainWindows(int argc, char **argv) { taosCleanupCfg(); taosCloseLog(); taosCleanupArgs(); + taosConvDestroy(); return 0; } @@ -242,13 +217,14 @@ int mainWindows(int argc, char **argv) { taosCleanupCfg(); taosCloseLog(); taosCleanupArgs(); + taosConvDestroy(); return 0; } - dmSetProcInfo(argc, (char **)argv); + osSetProcPath(argc, (char **)argv); taosCleanupArgs(); - if (dmInit(global.ntype) != 0) { + if (dmInit() != 0) { dError("failed to init dnode since %s", terrstr()); return -1; } diff --git a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h index 17cbde437b2e94d8d111c76600ddef8fb7767818..b47742b4ed8db0cf55df46118b20a07bf00bd6bd 100644 --- a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h +++ b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h @@ -34,7 +34,7 @@ typedef struct SMnodeMgmt { SSingleWorker readWorker; SSingleWorker writeWorker; SSingleWorker syncWorker; - SSingleWorker monitorWorker; + SSingleWorker syncCtrlWorker; bool stopped; int32_t refCount; TdThreadRwlock lock; @@ -48,18 +48,16 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption); SArray *mmGetMsgHandles(); int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg); int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg); -int32_t mmProcessGetMonitorInfoReq(SMnodeMgmt *pMgmt, SRpcMsg *pMsg); -int32_t mmProcessGetLoadsReq(SMnodeMgmt *pMgmt, SRpcMsg *pMsg); // mmWorker.c int32_t mmStartWorker(SMnodeMgmt *pMgmt); void mmStopWorker(SMnodeMgmt *pMgmt); int32_t mmPutMsgToWriteQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t mmPutMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg); +int32_t mmPutMsgToSyncCtrlQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t mmPutMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t mmPutMsgToFetchQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg); -int32_t mmPutMsgToMonitorQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc); #ifdef __cplusplus diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index 105b6e542eb38bbcf4d5e06dc6132ffb2ccc3971..89b68febd515e86df269ed14bdbe51dae7b3a37a 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -20,58 +20,11 @@ void mmGetMonitorInfo(SMnodeMgmt *pMgmt, SMonMmInfo *pInfo) { mndGetMonitorInfo(pMgmt->pMnode, &pInfo->cluster, &pInfo->vgroup, &pInfo->stb, &pInfo->grant); } -int32_t mmProcessGetMonitorInfoReq(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { - SMonMmInfo mmInfo = {0}; - mmGetMonitorInfo(pMgmt, &mmInfo); - dmGetMonitorSystemInfo(&mmInfo.sys); - monGetLogs(&mmInfo.log); - - int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo); - pMsg->info.rsp = pRsp; - pMsg->info.rspLen = rspLen; - tFreeSMonMmInfo(&mmInfo); - return 0; -} - void mmGetMnodeLoads(SMnodeMgmt *pMgmt, SMonMloadInfo *pInfo) { pInfo->isMnode = 1; mndGetLoad(pMgmt->pMnode, &pInfo->load); } -int32_t mmProcessGetLoadsReq(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { - SMonMloadInfo mloads = {0}; - mmGetMnodeLoads(pMgmt, &mloads); - - int32_t rspLen = tSerializeSMonMloadInfo(NULL, 0, &mloads); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonMloadInfo(pRsp, rspLen, &mloads); - pMsg->info.rsp = pRsp; - pMsg->info.rspLen = rspLen; - return 0; -} - int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) { const STraceId *trace = &pMsg->info.traceId; SDCreateMnodeReq createReq = {0}; @@ -230,9 +183,6 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_HASHRANGE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_COMPACT_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MON_MM_INFO, mmPutMsgToMonitorQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MON_MM_LOAD, mmPutMsgToMonitorQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_SYNC_TIMEOUT, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_PING, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_PING_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER; @@ -246,10 +196,9 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_SYNC_SET_MNODE_STANDBY, mmPutMsgToSyncQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_SYNC_SET_MNODE_STANDBY_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_SYNC_SET_VNODE_STANDBY_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT_REPLY, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER; code = 0; diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c index 849d3ef39019fcb5ce9dfb987cac4772e91839a7..e0a39a6bf18a97f690261335b3d7455e47cb97bc 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c @@ -46,22 +46,12 @@ static inline void mmSendRsp(SRpcMsg *pMsg, int32_t code) { static void mmProcessRpcMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) { SMnodeMgmt *pMgmt = pInfo->ahandle; - int32_t code = -1; + pMsg->info.node = pMgmt->pMnode; const STraceId *trace = &pMsg->info.traceId; dGTrace("msg:%p, get from mnode queue", pMsg); - switch (pMsg->msgType) { - case TDMT_MON_MM_INFO: - code = mmProcessGetMonitorInfoReq(pMgmt, pMsg); - break; - case TDMT_MON_MM_LOAD: - code = mmProcessGetLoadsReq(pMgmt, pMsg); - break; - default: - pMsg->info.node = pMgmt->pMnode; - code = mndProcessRpcMsg(pMsg); - } + int32_t code = mndProcessRpcMsg(pMsg); if (IsReq(pMsg) && pMsg->info.handle != NULL && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != 0 && terrno != 0) code = terrno; @@ -77,6 +67,24 @@ static void mmProcessRpcMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) { taosFreeQitem(pMsg); } +static void mmProcessSyncCtrlMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) { + SMnodeMgmt *pMgmt = pInfo->ahandle; + pMsg->info.node = pMgmt->pMnode; + + const STraceId *trace = &pMsg->info.traceId; + dGTrace("msg:%p, get from mnode-sync-ctrl queue", pMsg); + + SMsgHead *pHead = pMsg->pCont; + pHead->contLen = ntohl(pHead->contLen); + pHead->vgId = ntohl(pHead->vgId); + + int32_t code = mndProcessSyncCtrlMsg(pMsg); + + dGTrace("msg:%p, is freed, code:0x%x", pMsg, code); + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); +} + static void mmProcessSyncMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) { SMnodeMgmt *pMgmt = pInfo->ahandle; pMsg->info.node = pMgmt->pMnode; @@ -118,6 +126,10 @@ int32_t mmPutMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { return mmPutMsgToWorker(pMgmt, &pMgmt->syncWorker, pMsg); } +int32_t mmPutMsgToSyncCtrlQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { + return mmPutMsgToWorker(pMgmt, &pMgmt->syncCtrlWorker, pMsg); +} + int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { return mmPutMsgToWorker(pMgmt, &pMgmt->readWorker, pMsg); } @@ -136,10 +148,6 @@ int32_t mmPutMsgToFetchQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { return mmPutMsgToWorker(pMgmt, &pMgmt->fetchWorker, pMsg); } -int32_t mmPutMsgToMonitorQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { - return mmPutMsgToWorker(pMgmt, &pMgmt->monitorWorker, pMsg); -} - int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) { SSingleWorker *pWorker = NULL; switch (qtype) { @@ -158,6 +166,9 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) { case SYNC_QUEUE: pWorker = &pMgmt->syncWorker; break; + case SYNC_CTRL_QUEUE: + pWorker = &pMgmt->syncCtrlWorker; + break; default: terrno = TSDB_CODE_INVALID_PARA; } @@ -237,15 +248,15 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) { return -1; } - SSingleWorkerCfg mCfg = { + SSingleWorkerCfg scCfg = { .min = 1, .max = 1, - .name = "mnode-monitor", - .fp = (FItem)mmProcessRpcMsg, + .name = "mnode-sync-ctrl", + .fp = (FItem)mmProcessSyncCtrlMsg, .param = pMgmt, }; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) { - dError("failed to start mnode mnode-monitor worker since %s", terrstr()); + if (tSingleWorkerInit(&pMgmt->syncCtrlWorker, &scCfg) != 0) { + dError("failed to start mnode mnode-sync-ctrl worker since %s", terrstr()); return -1; } @@ -256,11 +267,11 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) { void mmStopWorker(SMnodeMgmt *pMgmt) { while (pMgmt->refCount > 0) taosMsleep(10); - tSingleWorkerCleanup(&pMgmt->monitorWorker); tSingleWorkerCleanup(&pMgmt->queryWorker); tSingleWorkerCleanup(&pMgmt->fetchWorker); tSingleWorkerCleanup(&pMgmt->readWorker); tSingleWorkerCleanup(&pMgmt->writeWorker); tSingleWorkerCleanup(&pMgmt->syncWorker); + tSingleWorkerCleanup(&pMgmt->syncCtrlWorker); dDebug("mnode workers are closed"); } diff --git a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h index 56bf56f25e85a57140566bb20b9b252dae5b521a..c6c239bdcc8b3fa81830c5bed96f237767aabbb2 100644 --- a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h +++ b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h @@ -32,14 +32,12 @@ typedef struct SQnodeMgmt { const char *name; SSingleWorker queryWorker; SSingleWorker fetchWorker; - SSingleWorker monitorWorker; } SQnodeMgmt; // qmHandle.c SArray *qmGetMsgHandles(); int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg); int32_t qmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg); -int32_t qmProcessGetMonitorInfoReq(SQnodeMgmt *pMgmt, SRpcMsg *pMsg); // qmWorker.c int32_t qmPutRpcMsgToQueue(SQnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pMsg); @@ -49,7 +47,6 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt); void qmStopWorker(SQnodeMgmt *pMgmt); int32_t qmPutNodeMsgToQueryQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t qmPutNodeMsgToFetchQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg); -int32_t qmPutNodeMsgToMonitorQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t qndPreprocessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg); diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c index 0573be90ea84cd2173d5492e5aaa2d6f6cf076b5..5017ad7b741a5854e02433061f70b1967a038e62 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c @@ -29,31 +29,6 @@ void qmGetQnodeLoads(SQnodeMgmt *pMgmt, SQnodeLoad *pInfo) { pInfo->dnodeId = pMgmt->pData->dnodeId; } -int32_t qmProcessGetMonitorInfoReq(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) { - SMonQmInfo qmInfo = {0}; - qmGetMonitorInfo(pMgmt, &qmInfo); - dmGetMonitorSystemInfo(&qmInfo.sys); - monGetLogs(&qmInfo.log); - - int32_t rspLen = tSerializeSMonQmInfo(NULL, 0, &qmInfo); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonQmInfo(pRsp, rspLen, &qmInfo); - pMsg->info.rsp = pRsp; - pMsg->info.rspLen = rspLen; - tFreeSMonQmInfo(&qmInfo); - return 0; -} - int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) { SDCreateQnodeReq createReq = {0}; if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) { @@ -103,8 +78,6 @@ SArray *qmGetMsgHandles() { SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle)); if (pArray == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MON_QM_INFO, qmPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER; - // Requests handled by VNODE if (dmSetMgmtHandle(pArray, TDMT_SCH_QUERY, qmPutNodeMsgToQueryQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SCH_MERGE_QUERY, qmPutNodeMsgToQueryQueue, 1) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c b/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c index 66386b0ee0bc7fac510a0e9ceb1d1bab4ac649be..edbe9882a43232d48eee63966cc6ea3a3f61536e 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c @@ -28,18 +28,9 @@ static inline void qmSendRsp(SRpcMsg *pMsg, int32_t code) { static void qmProcessQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { SQnodeMgmt *pMgmt = pInfo->ahandle; - int32_t code = -1; dTrace("msg:%p, get from qnode queue", pMsg); - switch (pMsg->msgType) { - case TDMT_MON_QM_INFO: - code = qmProcessGetMonitorInfoReq(pMgmt, pMsg); - break; - default: - code = qndProcessQueryMsg(pMgmt->pQnode, pInfo->timestamp, pMsg); - break; - } - + int32_t code = qndProcessQueryMsg(pMgmt->pQnode, pInfo->timestamp, pMsg); if (IsReq(pMsg) && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != 0 && terrno != 0) code = terrno; qmSendRsp(pMsg, code); @@ -66,10 +57,6 @@ int32_t qmPutNodeMsgToFetchQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) { return qmPutNodeMsgToWorker(&pMgmt->fetchWorker, pMsg); } -int32_t qmPutNodeMsgToMonitorQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) { - return qmPutNodeMsgToWorker(&pMgmt->monitorWorker, pMsg); -} - int32_t qmPutRpcMsgToQueue(SQnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) { SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM); if (pMsg == NULL) return -1; @@ -136,24 +123,11 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) { return -1; } - SSingleWorkerCfg mCfg = { - .min = 1, - .max = 1, - .name = "qnode-monitor", - .fp = (FItem)qmProcessQueue, - .param = pMgmt, - }; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) { - dError("failed to start qnode-monitor worker since %s", terrstr()); - return -1; - } - dDebug("qnode workers are initialized"); return 0; } void qmStopWorker(SQnodeMgmt *pMgmt) { - tSingleWorkerCleanup(&pMgmt->monitorWorker); tSingleWorkerCleanup(&pMgmt->queryWorker); tSingleWorkerCleanup(&pMgmt->fetchWorker); dDebug("qnode workers are closed"); diff --git a/source/dnode/mgmt/mgmt_snode/inc/smInt.h b/source/dnode/mgmt/mgmt_snode/inc/smInt.h index fbf63dda430cc6ead7fa9ea43e3ab010f265d512..4efe1c997b578a3397f1ab0fbcc39b612af123a8 100644 --- a/source/dnode/mgmt/mgmt_snode/inc/smInt.h +++ b/source/dnode/mgmt/mgmt_snode/inc/smInt.h @@ -33,14 +33,12 @@ typedef struct SSnodeMgmt { int8_t uniqueWorkerInUse; SArray *uniqueWorkers; // SArray SSingleWorker sharedWorker; - SSingleWorker monitorWorker; } SSnodeMgmt; // smHandle.c SArray *smGetMsgHandles(); int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg); int32_t smProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg); -int32_t smProcessGetMonitorInfoReq(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); // smWorker.c int32_t smStartWorker(SSnodeMgmt *pMgmt); @@ -49,7 +47,6 @@ int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t smPutNodeMsgToUniqueQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t smPutNodeMsgToSharedQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t smPutNodeMsgToExecQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); -int32_t smPutNodeMsgToMonitorQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/mgmt_snode/src/smHandle.c b/source/dnode/mgmt/mgmt_snode/src/smHandle.c index c6e3b3611f5e264f14a7da7261e2f1b89ff58c28..65c96767ab33edf6f1ddcb04aa76d276dc17e92f 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smHandle.c +++ b/source/dnode/mgmt/mgmt_snode/src/smHandle.c @@ -18,31 +18,6 @@ void smGetMonitorInfo(SSnodeMgmt *pMgmt, SMonSmInfo *smInfo) {} -int32_t smProcessGetMonitorInfoReq(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { - SMonSmInfo smInfo = {0}; - smGetMonitorInfo(pMgmt, &smInfo); - dmGetMonitorSystemInfo(&smInfo.sys); - monGetLogs(&smInfo.log); - - int32_t rspLen = tSerializeSMonSmInfo(NULL, 0, &smInfo); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonSmInfo(pRsp, rspLen, &smInfo); - pMsg->info.rsp = pRsp; - pMsg->info.rspLen = rspLen; - tFreeSMonSmInfo(&smInfo); - return 0; -} - int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) { SDCreateSnodeReq createReq = {0}; if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) { @@ -92,8 +67,6 @@ SArray *smGetMsgHandles() { SArray *pArray = taosArrayInit(4, sizeof(SMgmtHandle)); if (pArray == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MON_SM_INFO, smPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_snode/src/smWorker.c b/source/dnode/mgmt/mgmt_snode/src/smWorker.c index 19c1b9b5c7afd9d1726b364ee69d94619f471d2d..ad56d57f69472f5101c7149118fbb95c4a05b5f2 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smWorker.c +++ b/source/dnode/mgmt/mgmt_snode/src/smWorker.c @@ -26,27 +26,6 @@ static inline void smSendRsp(SRpcMsg *pMsg, int32_t code) { tmsgSendRsp(&rsp); } -static void smProcessMonitorQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { - SSnodeMgmt *pMgmt = pInfo->ahandle; - int32_t code = -1; - dTrace("msg:%p, get from snode-monitor queue", pMsg); - - if (pMsg->msgType == TDMT_MON_SM_INFO) { - code = smProcessGetMonitorInfoReq(pMgmt, pMsg); - } else { - terrno = TSDB_CODE_MSG_NOT_PROCESSED; - } - - if (IsReq(pMsg)) { - if (code != 0 && terrno != 0) code = terrno; - smSendRsp(pMsg, code); - } - - dTrace("msg:%p, is freed, code:0x%x", pMsg, code); - rpcFreeCont(pMsg->pCont); - taosFreeQitem(pMsg); -} - static void smProcessUniqueQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { SSnodeMgmt *pMgmt = pInfo->ahandle; @@ -123,24 +102,11 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) { return -1; } - SSingleWorkerCfg mCfg = { - .min = 1, - .max = 1, - .name = "snode-monitor", - .fp = (FItem)smProcessMonitorQueue, - .param = pMgmt, - }; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) { - dError("failed to start snode-monitor worker since %s", terrstr()); - return -1; - } - dDebug("snode workers are initialized"); return 0; } void smStopWorker(SSnodeMgmt *pMgmt) { - tSingleWorkerCleanup(&pMgmt->monitorWorker); for (int32_t i = 0; i < taosArrayGetSize(pMgmt->uniqueWorkers); i++) { SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, i); tMultiWorkerCleanup(pWorker); @@ -175,14 +141,6 @@ int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { return 0; } -int32_t smPutNodeMsgToMonitorQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { - SSingleWorker *pWorker = &pMgmt->monitorWorker; - - dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - taosWriteQitem(pWorker->queue, pMsg); - return 0; -} - int32_t smPutNodeMsgToUniqueQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { int32_t index = smGetSWIdFromMsg(pMsg); SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, index); diff --git a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h index 30f54831987999daccac93f5b6cbd0ccc2dfbf28..bf1ccc1a7b6abf167515ed91fff82b612e1d64c4 100644 --- a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h +++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h @@ -34,10 +34,10 @@ typedef struct SVnodeMgmt { SQWorkerPool streamPool; SWWorkerPool fetchPool; SWWorkerPool syncPool; + SWWorkerPool syncCtrlPool; SWWorkerPool writePool; SWWorkerPool applyPool; SSingleWorker mgmtWorker; - SSingleWorker monitorWorker; SHashObj *hash; TdThreadRwlock lock; SVnodesStat state; @@ -60,6 +60,7 @@ typedef struct { SVnode *pImpl; STaosQueue *pWriteQ; STaosQueue *pSyncQ; + STaosQueue *pSyncCtrlQ; STaosQueue *pApplyQ; STaosQueue *pQueryQ; STaosQueue *pStreamQ; @@ -87,8 +88,7 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode); SArray *vmGetMsgHandles(); int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t vmProcessDropVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); -int32_t vmProcessGetMonitorInfoReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); -int32_t vmProcessGetLoadsReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); +int32_t vmProcessAlterVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); // vmFile.c int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes); @@ -106,12 +106,12 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc); int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); +int32_t vmPutMsgToSyncCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t vmPutMsgToMergeQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); -int32_t vmPutMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 0e53b7ca80fad5db6fedec880e495965b90e25a6..d682fa9cc58339e6e8d9a926a50e08d2cd9d42d2 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -66,7 +66,7 @@ void vmGetMonitorInfo(SVnodeMgmt *pMgmt, SMonVmInfo *pInfo) { pInfo->vstat.totalVnodes = totalVnodes; pInfo->vstat.masterNum = masterNum; - pInfo->vstat.numOfSelectReqs = numOfSelectReqs - pMgmt->state.numOfSelectReqs; + pInfo->vstat.numOfSelectReqs = numOfSelectReqs; pInfo->vstat.numOfInsertReqs = numOfInsertReqs; // delta pInfo->vstat.numOfInsertSuccessReqs = numOfInsertSuccessReqs; // delta pInfo->vstat.numOfBatchInsertReqs = numOfBatchInsertReqs; // delta @@ -83,54 +83,6 @@ void vmGetMonitorInfo(SVnodeMgmt *pMgmt, SMonVmInfo *pInfo) { taosArrayDestroy(pVloads); } -int32_t vmProcessGetMonitorInfoReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { - SMonVmInfo vmInfo = {0}; - vmGetMonitorInfo(pMgmt, &vmInfo); - dmGetMonitorSystemInfo(&vmInfo.sys); - monGetLogs(&vmInfo.log); - - int32_t rspLen = tSerializeSMonVmInfo(NULL, 0, &vmInfo); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonVmInfo(pRsp, rspLen, &vmInfo); - pMsg->info.rsp = pRsp; - pMsg->info.rspLen = rspLen; - tFreeSMonVmInfo(&vmInfo); - return 0; -} - -int32_t vmProcessGetLoadsReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { - SMonVloadInfo vloads = {0}; - vmGetVnodeLoads(pMgmt, &vloads, false); - - int32_t rspLen = tSerializeSMonVloadInfo(NULL, 0, &vloads); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonVloadInfo(pRsp, rspLen, &vloads); - pMsg->info.rsp = pRsp; - pMsg->info.rspLen = rspLen; - tFreeSMonVloadInfo(&vloads); - return 0; -} - static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { memcpy(pCfg, &vnodeCfgDefault, sizeof(SVnodeCfg)); @@ -236,7 +188,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { req.walRollPeriod, req.walSegmentSize, req.hashMethod, req.hashBegin, req.hashEnd, req.hashPrefix, req.hashSuffix, req.replica, req.selfIndex, req.strict); for (int32_t i = 0; i < req.replica; ++i) { - dInfo("vgId:%d, replica:%d fqdn:%s port:%u", req.vgId, req.replicas[i].id, req.replicas[i].fqdn, + dInfo("vgId:%d, replica:%d id:%d fqdn:%s port:%u", req.vgId, i, req.replicas[i].id, req.replicas[i].fqdn, req.replicas[i].port); } vmGenerateVnodeCfg(&req, &vnodeCfg); @@ -313,6 +265,72 @@ _OVER: return code; } +int32_t vmProcessAlterVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { + SAlterVnodeReplicaReq alterReq = {0}; + if (tDeserializeSAlterVnodeReplicaReq(pMsg->pCont, pMsg->contLen, &alterReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + int32_t vgId = alterReq.vgId; + dInfo("vgId:%d, start to alter vnode, replica:%d selfIndex:%d strict:%d", alterReq.vgId, alterReq.replica, + alterReq.selfIndex, alterReq.strict); + for (int32_t i = 0; i < alterReq.replica; ++i) { + dInfo("vgId:%d, replica:%d ep:%s:%u", alterReq.vgId, i, alterReq.replicas[i].fqdn, alterReq.replicas[i].port); + } + + if (alterReq.replica <= 0 || alterReq.selfIndex < 0 || alterReq.selfIndex >= alterReq.replica) { + terrno = TSDB_CODE_INVALID_MSG; + dError("vgId:%d, failed to alter replica since invalid msg", alterReq.vgId); + return -1; + } + + SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId); + if (pVnode == NULL) { + dError("vgId:%d, failed to alter replica since %s", vgId, terrstr()); + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; + return -1; + } + + dInfo("vgId:%d, start to close vnode", vgId); + SWrapperCfg wrapperCfg = { + .dropped = pVnode->dropped, + .vgId = pVnode->vgId, + .vgVersion = pVnode->vgVersion, + }; + tstrncpy(wrapperCfg.path, pVnode->path, sizeof(wrapperCfg.path)); + vmCloseVnode(pMgmt, pVnode); + + char path[TSDB_FILENAME_LEN] = {0}; + snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, vgId); + + dInfo("vgId:%d, start to alter vnode replica at %s", vgId, path); + if (vnodeAlter(path, &alterReq, pMgmt->pTfs) < 0) { + dError("vgId:%d, failed to alter vnode at %s since %s", vgId, path, terrstr()); + return -1; + } + + dInfo("vgId:%d, start to open vnode", vgId); + SVnode *pImpl = vnodeOpen(path, pMgmt->pTfs, pMgmt->msgCb); + if (pImpl == NULL) { + dError("vgId:%d, failed to open vnode at %s since %s", vgId, path, terrstr()); + return -1; + } + + if (vmOpenVnode(pMgmt, &wrapperCfg, pImpl) != 0) { + dError("vgId:%d, failed to open vnode mgmt since %s", vgId, terrstr()); + return -1; + } + + if (vnodeStart(pImpl) != 0) { + dError("vgId:%d, failed to start sync since %s", vgId, terrstr()); + return -1; + } + + dInfo("vgId:%d, vnode config is altered", vgId); + return 0; +} + int32_t vmProcessDropVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { SDropVnodeReq dropReq = {0}; if (tDeserializeSDropVnodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) { @@ -348,9 +366,6 @@ SArray *vmGetMsgHandles() { SArray *pArray = taosArrayInit(32, sizeof(SMgmtHandle)); if (pArray == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MON_VM_INFO, vmPutMsgToMonitorQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MON_VM_LOAD, vmPutMsgToMonitorQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SCH_QUERY, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SCH_MERGE_QUERY, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER; @@ -399,7 +414,7 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIRM, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_HASHRANGE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; @@ -421,7 +436,8 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_SYNC_SET_VNODE_STANDBY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT, vmPutMsgToSyncCtrlQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT_REPLY, vmPutMsgToSyncCtrlQueue, 0) == NULL) goto _OVER; code = 0; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index bcc2e358d6a1f4d1c4b1b7d2352734ff78df609c..f36604eb27a299822bb57d578256a1b590762ba0 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -217,17 +217,82 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) { } } +static void *vmCloseVnodeInThread(void *param) { + SVnodeThread *pThread = param; + SVnodeMgmt *pMgmt = pThread->pMgmt; + + dInfo("thread:%d, start to close %d vnodes", pThread->threadIndex, pThread->vnodeNum); + setThreadName("close-vnodes"); + + for (int32_t v = 0; v < pThread->vnodeNum; ++v) { + SVnodeObj *pVnode = pThread->ppVnodes[v]; + + char stepDesc[TSDB_STEP_DESC_LEN] = {0}; + snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to close, %d of %d have been closed", pVnode->vgId, + pMgmt->state.openVnodes, pMgmt->state.totalVnodes); + tmsgReportStartup("vnode-close", stepDesc); + + vmCloseVnode(pMgmt, pVnode); + } + + dInfo("thread:%d, numOfVnodes:%d is closed", pThread->threadIndex, pThread->vnodeNum); + return NULL; +} + static void vmCloseVnodes(SVnodeMgmt *pMgmt) { dInfo("start to close all vnodes"); + tSingleWorkerCleanup(&pMgmt->mgmtWorker); + dInfo("vnodes mgmt worker is stopped"); int32_t numOfVnodes = 0; SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes); - for (int32_t i = 0; i < numOfVnodes; ++i) { - if (ppVnodes == NULL || ppVnodes[i] == NULL) continue; - vmCloseVnode(pMgmt, ppVnodes[i]); + int32_t threadNum = tsNumOfCores / 2; + if (threadNum < 1) threadNum = 1; + int32_t vnodesPerThread = numOfVnodes / threadNum + 1; + + SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread)); + for (int32_t t = 0; t < threadNum; ++t) { + threads[t].threadIndex = t; + threads[t].pMgmt = pMgmt; + threads[t].ppVnodes = taosMemoryCalloc(vnodesPerThread, sizeof(SVnode *)); + } + + for (int32_t v = 0; v < numOfVnodes; ++v) { + int32_t t = v % threadNum; + SVnodeThread *pThread = &threads[t]; + if (pThread->ppVnodes != NULL && ppVnodes != NULL) { + pThread->ppVnodes[pThread->vnodeNum++] = ppVnodes[v]; + } } + pMgmt->state.openVnodes = 0; + dInfo("close %d vnodes with %d threads", numOfVnodes, threadNum); + + for (int32_t t = 0; t < threadNum; ++t) { + SVnodeThread *pThread = &threads[t]; + if (pThread->vnodeNum == 0) continue; + + TdThreadAttr thAttr; + taosThreadAttrInit(&thAttr); + taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + if (taosThreadCreate(&pThread->thread, &thAttr, vmCloseVnodeInThread, pThread) != 0) { + dError("thread:%d, failed to create thread to close vnode since %s", pThread->threadIndex, strerror(errno)); + } + + taosThreadAttrDestroy(&thAttr); + } + + for (int32_t t = 0; t < threadNum; ++t) { + SVnodeThread *pThread = &threads[t]; + if (pThread->vnodeNum > 0 && taosCheckPthreadValid(pThread->thread)) { + taosThreadJoin(pThread->thread, NULL); + taosThreadClear(&pThread->thread); + } + taosMemoryFree(pThread->ppVnodes); + } + taosMemoryFree(threads); + if (ppVnodes != NULL) { taosMemoryFree(ppVnodes); } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index d7df30bc7587cada18a308176e2fc739c1679afa..76d181761bce42135bd8e79b0ba022b0f5088193 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -34,18 +34,15 @@ static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { dGTrace("msg:%p, get from vnode-mgmt queue", pMsg); switch (pMsg->msgType) { - case TDMT_MON_VM_INFO: - code = vmProcessGetMonitorInfoReq(pMgmt, pMsg); - break; - case TDMT_MON_VM_LOAD: - code = vmProcessGetLoadsReq(pMgmt, pMsg); - break; case TDMT_DND_CREATE_VNODE: code = vmProcessCreateVnodeReq(pMgmt, pMsg); break; case TDMT_DND_DROP_VNODE: code = vmProcessDropVnodeReq(pMgmt, pMsg); break; + case TDMT_VND_ALTER_REPLICA: + code = vmProcessAlterVnodeReq(pMgmt, pMsg); + break; default: terrno = TSDB_CODE_MSG_NOT_PROCESSED; dGError("msg:%p, not processed in vnode-mgmt queue", pMsg); @@ -136,6 +133,22 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf } } +static void vmProcessSyncCtrlQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { + SVnodeObj *pVnode = pInfo->ahandle; + SRpcMsg *pMsg = NULL; + + for (int32_t i = 0; i < numOfMsgs; ++i) { + if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; + const STraceId *trace = &pMsg->info.traceId; + dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg); + + int32_t code = vnodeProcessSyncCtrlMsg(pVnode->pImpl, pMsg, NULL); // no response here + dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); + } +} + static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) { const STraceId *trace = &pMsg->info.traceId; SMsgHead *pHead = pMsg->pCont; @@ -203,6 +216,10 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg); taosWriteQitem(pVnode->pSyncQ, pMsg); break; + case SYNC_CTRL_QUEUE: + dGTrace("vgId:%d, msg:%p put into vnode-sync-ctrl queue", pVnode->vgId, pMsg); + taosWriteQitem(pVnode->pSyncCtrlQ, pMsg); + break; case APPLY_QUEUE: dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg); taosWriteQitem(pVnode->pApplyQ, pMsg); @@ -217,6 +234,8 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp return code; } +int32_t vmPutMsgToSyncCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_CTRL_QUEUE); } + int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); } int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); } @@ -234,13 +253,6 @@ int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return 0; } -int32_t vmPutMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { - const STraceId *trace = &pMsg->info.traceId; - dGTrace("msg:%p, put into vnode-monitor queue", pMsg); - taosWriteQitem(pMgmt->monitorWorker.queue, pMsg); - return 0; -} - int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) { SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM); if (pMsg == NULL) { @@ -301,6 +313,7 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) { int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { pVnode->pWriteQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode->pImpl, (FItems)vnodeProposeWriteMsg); pVnode->pSyncQ = tWWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FItems)vmProcessSyncQueue); + pVnode->pSyncCtrlQ = tWWorkerAllocQueue(&pMgmt->syncCtrlPool, pVnode, (FItems)vmProcessSyncCtrlQueue); pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->applyPool, pVnode->pImpl, (FItems)vnodeApplyWriteMsg); pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue); pVnode->pStreamQ = tQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue); @@ -325,6 +338,7 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { tWWorkerFreeQueue(&pMgmt->writePool, pVnode->pWriteQ); tWWorkerFreeQueue(&pMgmt->applyPool, pVnode->pApplyQ); tWWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ); + tWWorkerFreeQueue(&pMgmt->syncCtrlPool, pVnode->pSyncCtrlQ); tQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ); tQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ); tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ); @@ -370,6 +384,11 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) { pSPool->max = tsNumOfVnodeSyncThreads; if (tWWorkerInit(pSPool) != 0) return -1; + SWWorkerPool *pSCPool = &pMgmt->syncCtrlPool; + pSCPool->name = "vnode-sync-ctrl"; + pSCPool->max = tsNumOfVnodeSyncThreads; + if (tWWorkerInit(pSCPool) != 0) return -1; + SSingleWorkerCfg mgmtCfg = { .min = 1, .max = 1, @@ -379,25 +398,15 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) { }; if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg) != 0) return -1; - SSingleWorkerCfg monitorCfg = { - .min = 1, - .max = 1, - .name = "vnode-monitor", - .fp = (FItem)vmProcessMgmtQueue, - .param = pMgmt, - }; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &monitorCfg) != 0) return -1; - dDebug("vnode workers are initialized"); return 0; } void vmStopWorker(SVnodeMgmt *pMgmt) { - tSingleWorkerCleanup(&pMgmt->monitorWorker); - tSingleWorkerCleanup(&pMgmt->mgmtWorker); tWWorkerCleanup(&pMgmt->writePool); tWWorkerCleanup(&pMgmt->applyPool); tWWorkerCleanup(&pMgmt->syncPool); + tWWorkerCleanup(&pMgmt->syncCtrlPool); tQWorkerCleanup(&pMgmt->queryPool); tQWorkerCleanup(&pMgmt->streamPool); tWWorkerCleanup(&pMgmt->fetchPool); diff --git a/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h b/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h index adde0557965fb7651c66a8b4791d4a671db91201..7e85e6b72239260d13aba44306309cd2528c3364 100644 --- a/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h +++ b/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h @@ -25,44 +25,6 @@ extern "C" { #endif -typedef struct SMgmtWrapper SMgmtWrapper; - -#define SINGLE_PROC 0 -#define CHILD_PROC 1 -#define PARENT_PROC 2 -#define TEST_PROC 3 -#define OnlyInSingleProc(wrapper) ((wrapper)->proc.ptype == SINGLE_PROC) -#define OnlyInChildProc(wrapper) ((wrapper)->proc.ptype == CHILD_PROC) -#define OnlyInParentProc(wrapper) ((wrapper)->proc.ptype == PARENT_PROC) -#define InChildProc(wrapper) ((wrapper)->proc.ptype & CHILD_PROC) -#define InParentProc(wrapper) ((wrapper)->proc.ptype & PARENT_PROC) - -typedef struct { - int32_t head; - int32_t tail; - int32_t total; - int32_t avail; - int32_t items; - char name[8]; - TdThreadMutex mutex; - tsem_t sem; - char pBuffer[]; -} SProcQueue; - -typedef struct { - SMgmtWrapper *wrapper; - const char *name; - SHashObj *hash; - SProcQueue *pqueue; - SProcQueue *cqueue; - TdThread pthread; - TdThread cthread; - SShm shm; - int32_t pid; - EDndProcType ptype; - bool stop; -} SProc; - typedef struct SMgmtWrapper { SMgmtFunc func; struct SDnode *pDnode; @@ -74,7 +36,6 @@ typedef struct SMgmtWrapper { EDndNodeType ntype; bool deployed; bool required; - SProc proc; NodeMsgFp msgFps[TDMT_MAX]; } SMgmtWrapper; @@ -111,8 +72,6 @@ typedef struct SUdfdData { typedef struct SDnode { int8_t once; bool stop; - EDndProcType ptype; - EDndNodeType rtype; EDndRunStatus status; SStartupInfo startup; SDnodeTrans trans; @@ -128,7 +87,7 @@ SDnode *dmInstance(); void dmReportStartup(const char *pName, const char *pDesc); // dmMgmt.c -int32_t dmInitDnode(SDnode *pDnode, EDndNodeType rtype); +int32_t dmInitDnode(SDnode *pDnode); void dmCleanupDnode(SDnode *pDnode); SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType); int32_t dmMarkWrapper(SMgmtWrapper *pWrapper); @@ -145,16 +104,6 @@ void dmStopNode(SMgmtWrapper *pWrapper); void dmCloseNode(SMgmtWrapper *pWrapper); int32_t dmRunDnode(SDnode *pDnode); -// dmProc.c -int32_t dmInitProc(struct SMgmtWrapper *pWrapper); -void dmCleanupProc(struct SMgmtWrapper *pWrapper); -int32_t dmRunProc(SProc *proc); -void dmStopProc(SProc *proc); -void dmRemoveProcRpcHandle(SProc *proc, void *handle); -void dmCloseProcRpcHandles(SProc *proc); -int32_t dmPutToProcCQueue(SProc *proc, SRpcMsg *pMsg, EProcFuncType ftype); -void dmPutToProcPQueue(SProc *proc, SRpcMsg *pMsg, EProcFuncType ftype); - // dmTransport.c int32_t dmInitServer(SDnode *pDnode); void dmCleanupServer(SDnode *pDnode); diff --git a/source/dnode/mgmt/node_mgmt/src/dmEnv.c b/source/dnode/mgmt/node_mgmt/src/dmEnv.c index 5a7f149bc6e22f544ea5414be07f0829c264bb5f..a222ad3f7da738c8f2f9a84ac4f9463ae309b5d5 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmEnv.c +++ b/source/dnode/mgmt/node_mgmt/src/dmEnv.c @@ -53,13 +53,19 @@ static bool dmCheckDiskSpace() { osUpdate(); // sufficiency if (!osDataSpaceSufficient()) { - dWarn("free data disk size: %f GB, not sufficient, expected %f GB at least", (double)tsDataSpace.size.avail / 1024.0 / 1024.0 / 1024.0, (double)tsDataSpace.reserved / 1024.0 / 1024.0 / 1024.0); + dWarn("free data disk size: %f GB, not sufficient, expected %f GB at least", + (double)tsDataSpace.size.avail / 1024.0 / 1024.0 / 1024.0, + (double)tsDataSpace.reserved / 1024.0 / 1024.0 / 1024.0); } if (!osLogSpaceSufficient()) { - dWarn("free log disk size: %f GB, not sufficient, expected %f GB at least", (double)tsLogSpace.size.avail / 1024.0 / 1024.0 / 1024.0, (double)tsLogSpace.reserved / 1024.0 / 1024.0 / 1024.0); + dWarn("free log disk size: %f GB, not sufficient, expected %f GB at least", + (double)tsLogSpace.size.avail / 1024.0 / 1024.0 / 1024.0, + (double)tsLogSpace.reserved / 1024.0 / 1024.0 / 1024.0); } if (!osTempSpaceSufficient()) { - dWarn("free temp disk size: %f GB, not sufficient, expected %f GB at least", (double)tsTempSpace.size.avail / 1024.0 / 1024.0 / 1024.0, (double)tsTempSpace.reserved / 1024.0 / 1024.0 / 1024.0); + dWarn("free temp disk size: %f GB, not sufficient, expected %f GB at least", + (double)tsTempSpace.size.avail / 1024.0 / 1024.0 / 1024.0, + (double)tsTempSpace.reserved / 1024.0 / 1024.0 / 1024.0); } // availability bool ret = true; @@ -82,7 +88,7 @@ static bool dmCheckDiskSpace() { } static bool dmCheckDataDirVersion() { - char checkDataDirJsonFileName[PATH_MAX]; + char checkDataDirJsonFileName[PATH_MAX] = {0}; snprintf(checkDataDirJsonFileName, PATH_MAX, "%s/dnode/dnodeCfg.json", tsDataDir); if (taosCheckExistFile(checkDataDirJsonFileName)) { dError("The default data directory %s contains old data of tdengine 2.x, please clear it before running!", @@ -92,14 +98,14 @@ static bool dmCheckDataDirVersion() { return true; } -int32_t dmInit(int8_t rtype) { +int32_t dmInit() { dInfo("start to init dnode env"); if (!dmCheckDataDirVersion()) return -1; if (!dmCheckDiskSpace()) return -1; if (dmCheckRepeatInit(dmInstance()) != 0) return -1; if (dmInitSystem() != 0) return -1; if (dmInitMonitor() != 0) return -1; - if (dmInitDnode(dmInstance(), rtype) != 0) return -1; + if (dmInitDnode(dmInstance()) != 0) return -1; dInfo("dnode env is initialized"); return 0; @@ -126,8 +132,8 @@ void dmCleanup() { taosStopCacheRefreshWorker(); dInfo("dnode env is cleaned up"); - taosCloseLog(); taosCleanupCfg(); + taosCloseLog(); } void dmStop() { @@ -174,7 +180,6 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) { } pWrapper->deployed = true; pWrapper->required = true; - pWrapper->proc.ptype = pDnode->ptype; } taosThreadMutexUnlock(&pDnode->mutex); diff --git a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c index 75c76a1f54cfbf45cee7fa9006d7588fe5644d8e..2c9020b668550a914cdd7e235ad2c5242af36057 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c @@ -26,47 +26,14 @@ static bool dmRequireNode(SDnode *pDnode, SMgmtWrapper *pWrapper) { int32_t code = (*pWrapper->func.requiredFp)(&input, &required); if (!required) { dDebug("node:%s, does not require startup", pWrapper->name); - } - - if (pWrapper->ntype == DNODE) { - if (pDnode->rtype != DNODE && pDnode->rtype != NODE_END) { - required = false; - dDebug("node:%s, does not require startup in child process", pWrapper->name); - } } else { - if (OnlyInChildProc(pWrapper)) { - if (pWrapper->ntype != pDnode->rtype) { - dDebug("node:%s, does not require startup in child process", pWrapper->name); - required = false; - } - } - } - - if (required) { dDebug("node:%s, required to startup", pWrapper->name); } return required; } -static int32_t dmInitVars(SDnode *pDnode, EDndNodeType rtype) { - pDnode->rtype = rtype; - - if (tsMultiProcess == 0) { - pDnode->ptype = DND_PROC_SINGLE; - dInfo("dnode will run in single-process mode"); - } else if (tsMultiProcess > 1) { - pDnode->ptype = DND_PROC_TEST; - dInfo("dnode will run in multi-process test mode"); - } else if (pDnode->rtype == DNODE || pDnode->rtype == NODE_END) { - pDnode->ptype = DND_PROC_PARENT; - dInfo("dnode will run in parent-process mode"); - } else { - pDnode->ptype = DND_PROC_CHILD; - SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->rtype]; - dInfo("dnode will run in child-process mode, node:%s", dmNodeName(pDnode->rtype)); - } - +static int32_t dmInitVars(SDnode *pDnode) { SDnodeData *pData = &pDnode->data; pData->dnodeId = 0; pData->clusterId = 0; @@ -127,12 +94,12 @@ static void dmClearVars(SDnode *pDnode) { memset(&pDnode->mutex, 0, sizeof(pDnode->mutex)); } -int32_t dmInitDnode(SDnode *pDnode, EDndNodeType rtype) { +int32_t dmInitDnode(SDnode *pDnode) { dDebug("start to create dnode"); int32_t code = -1; char path[PATH_MAX + 100] = {0}; - if (dmInitVars(pDnode, rtype) != 0) { + if (dmInitVars(pDnode) != 0) { goto _OVER; } @@ -147,13 +114,6 @@ int32_t dmInitDnode(SDnode *pDnode, EDndNodeType rtype) { pWrapper->pDnode = pDnode; pWrapper->name = dmNodeName(ntype); pWrapper->ntype = ntype; - pWrapper->proc.wrapper = pWrapper; - pWrapper->proc.shm.id = -1; - pWrapper->proc.pid = -1; - pWrapper->proc.ptype = pDnode->ptype; - if (ntype == DNODE) { - pWrapper->proc.ptype = DND_PROC_SINGLE; - } taosThreadRwlockInit(&pWrapper->lock, NULL); snprintf(path, sizeof(path), "%s%s%s", tsDataDir, TD_DIRSEP, pWrapper->name); @@ -164,11 +124,6 @@ int32_t dmInitDnode(SDnode *pDnode, EDndNodeType rtype) { } pWrapper->required = dmRequireNode(pDnode, pWrapper); - - if (ntype != DNODE && dmReadShmFile(pWrapper->path, pWrapper->name, pDnode->rtype, &pWrapper->proc.shm) != 0) { - dError("node:%s, failed to read shm file since %s", pWrapper->name, terrstr()); - goto _OVER; - } } if (dmInitMsgHandle(pDnode) != 0) { @@ -176,16 +131,14 @@ int32_t dmInitDnode(SDnode *pDnode, EDndNodeType rtype) { goto _OVER; } - if (pDnode->ptype == SINGLE_PROC || (pDnode->ptype & PARENT_PROC)) { - pDnode->lockfile = dmCheckRunning(tsDataDir); - if (pDnode->lockfile == NULL) { - goto _OVER; - } + pDnode->lockfile = dmCheckRunning(tsDataDir); + if (pDnode->lockfile == NULL) { + goto _OVER; + } - if (dmInitServer(pDnode) != 0) { - dError("failed to init transport since %s", terrstr()); - goto _OVER; - } + if (dmInitServer(pDnode) != 0) { + dError("failed to init transport since %s", terrstr()); + goto _OVER; } if (dmInitClient(pDnode) != 0) { @@ -248,7 +201,7 @@ int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) { int32_t code = 0; taosThreadRwlockRdlock(&pWrapper->lock); - if (pWrapper->deployed || (InParentProc(pWrapper) && pWrapper->required)) { + if (pWrapper->deployed) { int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); // dTrace("node:%s, is marked, ref:%d", pWrapper->name, refCount); } else { diff --git a/source/dnode/mgmt/node_mgmt/src/dmMonitor.c b/source/dnode/mgmt/node_mgmt/src/dmMonitor.c index be1de02e6a1f1b1c5dbaaf9a02a8370881287619..4ab56ed682c4c868d6db45dded6345e81d8c8915 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMonitor.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMonitor.c @@ -17,18 +17,6 @@ #include "dmMgmt.h" #include "dmNodes.h" -#define dmSendLocalRecv(pDnode, mtype, func, pInfo) \ - SRpcMsg rsp = {0}; \ - SRpcMsg req = {.msgType = mtype}; \ - SEpSet epset = {.inUse = 0, .numOfEps = 1}; \ - tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); \ - epset.eps[0].port = tsServerPort; \ - rpcSendRecv(pDnode->trans.clientRpc, &epset, &req, &rsp); \ - if (rsp.code == 0 && rsp.contLen > 0) { \ - func(rsp.pCont, rsp.contLen, pInfo); \ - } \ - rpcFreeCont(rsp.pCont); - static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) { pInfo->protocol = 1; pInfo->dnode_id = pDnode->data.dnodeId; @@ -59,9 +47,7 @@ static void dmGetMmMonitorInfo(SDnode *pDnode) { SMgmtWrapper *pWrapper = &pDnode->wrappers[MNODE]; if (dmMarkWrapper(pWrapper) == 0) { SMonMmInfo mmInfo = {0}; - if (tsMultiProcess) { - dmSendLocalRecv(pDnode, TDMT_MON_MM_INFO, tDeserializeSMonMmInfo, &mmInfo); - } else if (pWrapper->pMgmt != NULL) { + if (pWrapper->pMgmt != NULL) { mmGetMonitorInfo(pWrapper->pMgmt, &mmInfo); } dmReleaseWrapper(pWrapper); @@ -74,9 +60,7 @@ static void dmGetVmMonitorInfo(SDnode *pDnode) { SMgmtWrapper *pWrapper = &pDnode->wrappers[VNODE]; if (dmMarkWrapper(pWrapper) == 0) { SMonVmInfo vmInfo = {0}; - if (tsMultiProcess) { - dmSendLocalRecv(pDnode, TDMT_MON_VM_INFO, tDeserializeSMonVmInfo, &vmInfo); - } else if (pWrapper->pMgmt != NULL) { + if (pWrapper->pMgmt != NULL) { vmGetMonitorInfo(pWrapper->pMgmt, &vmInfo); } dmReleaseWrapper(pWrapper); @@ -89,9 +73,7 @@ static void dmGetQmMonitorInfo(SDnode *pDnode) { SMgmtWrapper *pWrapper = &pDnode->wrappers[QNODE]; if (dmMarkWrapper(pWrapper) == 0) { SMonQmInfo qmInfo = {0}; - if (tsMultiProcess) { - dmSendLocalRecv(pDnode, TDMT_MON_QM_INFO, tDeserializeSMonQmInfo, &qmInfo); - } else if (pWrapper->pMgmt != NULL) { + if (pWrapper->pMgmt != NULL) { qmGetMonitorInfo(pWrapper->pMgmt, &qmInfo); } dmReleaseWrapper(pWrapper); @@ -104,9 +86,7 @@ static void dmGetSmMonitorInfo(SDnode *pDnode) { SMgmtWrapper *pWrapper = &pDnode->wrappers[SNODE]; if (dmMarkWrapper(pWrapper) == 0) { SMonSmInfo smInfo = {0}; - if (tsMultiProcess) { - dmSendLocalRecv(pDnode, TDMT_MON_SM_INFO, tDeserializeSMonSmInfo, &smInfo); - } else if (pWrapper->pMgmt != NULL) { + if (pWrapper->pMgmt != NULL) { smGetMonitorInfo(pWrapper->pMgmt, &smInfo); } dmReleaseWrapper(pWrapper); @@ -132,9 +112,7 @@ void dmGetVnodeLoads(SMonVloadInfo *pInfo) { SDnode *pDnode = dmInstance(); SMgmtWrapper *pWrapper = &pDnode->wrappers[VNODE]; if (dmMarkWrapper(pWrapper) == 0) { - if (tsMultiProcess) { - dmSendLocalRecv(pDnode, TDMT_MON_VM_LOAD, tDeserializeSMonVloadInfo, pInfo); - } else if (pWrapper->pMgmt != NULL) { + if (pWrapper->pMgmt != NULL) { vmGetVnodeLoads(pWrapper->pMgmt, pInfo, false); } dmReleaseWrapper(pWrapper); @@ -145,9 +123,7 @@ void dmGetMnodeLoads(SMonMloadInfo *pInfo) { SDnode *pDnode = dmInstance(); SMgmtWrapper *pWrapper = &pDnode->wrappers[MNODE]; if (dmMarkWrapper(pWrapper) == 0) { - if (tsMultiProcess) { - dmSendLocalRecv(pDnode, TDMT_MON_MM_LOAD, tDeserializeSMonMloadInfo, pInfo); - } else if (pWrapper->pMgmt != NULL) { + if (pWrapper->pMgmt != NULL) { mmGetMnodeLoads(pWrapper->pMgmt, pInfo); } dmReleaseWrapper(pWrapper); @@ -158,9 +134,7 @@ void dmGetQnodeLoads(SQnodeLoad *pInfo) { SDnode *pDnode = dmInstance(); SMgmtWrapper *pWrapper = &pDnode->wrappers[QNODE]; if (dmMarkWrapper(pWrapper) == 0) { - if (tsMultiProcess) { - dmSendLocalRecv(pDnode, TDMT_MON_QM_LOAD, tDeserializeSQnodeLoad, pInfo); - } else if (pWrapper->pMgmt != NULL) { + if (pWrapper->pMgmt != NULL) { qmGetQnodeLoads(pWrapper->pMgmt, pInfo); } dmReleaseWrapper(pWrapper); diff --git a/source/dnode/mgmt/node_mgmt/src/dmNodes.c b/source/dnode/mgmt/node_mgmt/src/dmNodes.c index ec5f3589e018e55df5921230d5f6936326dc8651..6893e486bb29837f599b4f2226efbc25b61fdb85 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmNodes.c +++ b/source/dnode/mgmt/node_mgmt/src/dmNodes.c @@ -16,53 +16,6 @@ #define _DEFAULT_SOURCE #include "dmMgmt.h" -static int32_t dmCreateShm(SMgmtWrapper *pWrapper) { - int32_t shmsize = tsMnodeShmSize; - if (pWrapper->ntype == VNODE) { - shmsize = tsVnodeShmSize; - } else if (pWrapper->ntype == QNODE) { - shmsize = tsQnodeShmSize; - } else if (pWrapper->ntype == SNODE) { - shmsize = tsSnodeShmSize; - } else if (pWrapper->ntype == MNODE) { - shmsize = tsMnodeShmSize; - } else { - return -1; - } - - if (taosCreateShm(&pWrapper->proc.shm, pWrapper->ntype, shmsize) != 0) { - terrno = TAOS_SYSTEM_ERROR(terrno); - dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr()); - return -1; - } - - dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->proc.shm.id, shmsize); - return 0; -} - -static int32_t dmNewProc(SMgmtWrapper *pWrapper, EDndNodeType ntype) { - char tstr[8] = {0}; - char *args[6] = {0}; - snprintf(tstr, sizeof(tstr), "%d", ntype); - args[1] = "-c"; - args[2] = configDir; - args[3] = "-n"; - args[4] = tstr; - args[5] = NULL; - - int32_t pid = taosNewProc(args); - if (pid <= 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr()); - return -1; - } - - taosIgnSignal(SIGCHLD); - pWrapper->proc.pid = pid; - dInfo("node:%s, continue running in new pid:%d", pWrapper->name, pid); - return 0; -} - int32_t dmOpenNode(SMgmtWrapper *pWrapper) { SDnode *pDnode = pWrapper->pDnode; @@ -75,64 +28,14 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) { SMgmtOutputOpt output = {0}; SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper); - if (pWrapper->ntype == DNODE || InChildProc(pWrapper)) { - tmsgSetDefault(&input.msgCb); - } - - if (OnlyInSingleProc(pWrapper)) { - dInfo("node:%s, start to open", pWrapper->name); - if ((*pWrapper->func.openFp)(&input, &output) != 0) { - dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); - return -1; - } - dInfo("node:%s, has been opened", pWrapper->name); - pWrapper->deployed = true; - } - - if (InParentProc(pWrapper)) { - dDebug("node:%s, start to open", pWrapper->name); - if (dmCreateShm(pWrapper) != 0) { - return -1; - } - if (dmWriteShmFile(pWrapper->path, pWrapper->name, &pWrapper->proc.shm) != 0) { - return -1; - } - - if (OnlyInParentProc(pWrapper)) { - if (dmInitProc(pWrapper) != 0) { - dError("node:%s, failed to init proc since %s", pWrapper->name, terrstr()); - return -1; - } - if (pDnode->rtype == NODE_END) { - dInfo("node:%s, should be started manually in child process", pWrapper->name); - } else { - if (dmNewProc(pWrapper, pWrapper->ntype) != 0) { - return -1; - } - } - if (dmRunProc(&pWrapper->proc) != 0) { - dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); - return -1; - } - } - dDebug("node:%s, has been opened in parent process", pWrapper->name); - } - - if (InChildProc(pWrapper)) { - dDebug("node:%s, start to open", pWrapper->name); - if ((*pWrapper->func.openFp)(&input, &output) != 0) { - dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); - return -1; - } - if (dmInitProc(pWrapper) != 0) { - return -1; - } - if (dmRunProc(&pWrapper->proc) != 0) { - return -1; - } - dDebug("node:%s, has been opened in child process", pWrapper->name); - pWrapper->deployed = true; + dInfo("node:%s, start to open", pWrapper->name); + tmsgSetDefault(&input.msgCb); + if ((*pWrapper->func.openFp)(&input, &output) != 0) { + dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); + return -1; } + dInfo("node:%s, has been opened", pWrapper->name); + pWrapper->deployed = true; if (output.pMgmt != NULL) { pWrapper->pMgmt = output.pMgmt; @@ -143,7 +46,6 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) { } int32_t dmStartNode(SMgmtWrapper *pWrapper) { - if (OnlyInParentProc(pWrapper)) return 0; if (pWrapper->func.startFp != NULL) { dDebug("node:%s, start to start", pWrapper->name); if ((*pWrapper->func.startFp)(pWrapper->pMgmt) != 0) { @@ -173,17 +75,6 @@ void dmCloseNode(SMgmtWrapper *pWrapper) { taosMsleep(10); } - if (OnlyInParentProc(pWrapper)) { - int32_t pid = pWrapper->proc.pid; - if (pid > 0 && taosProcExist(pid)) { - dInfo("node:%s, send kill signal to the child pid:%d", pWrapper->name, pid); - taosKillProc(pid); - dInfo("node:%s, wait for child pid:%d to stop", pWrapper->name, pid); - taosWaitProc(pid); - dInfo("node:%s, child pid:%d is stopped", pWrapper->name, pid); - } - } - taosThreadRwlockWrlock(&pWrapper->lock); if (pWrapper->pMgmt != NULL) { (*pWrapper->func.closeFp)(pWrapper->pMgmt); @@ -191,10 +82,6 @@ void dmCloseNode(SMgmtWrapper *pWrapper) { } taosThreadRwlockUnlock(&pWrapper->lock); - if (!OnlyInSingleProc(pWrapper)) { - dmCleanupProc(pWrapper); - } - dInfo("node:%s, has been closed", pWrapper->name); } @@ -241,29 +128,8 @@ static void dmCloseNodes(SDnode *pDnode) { } } -static void dmWatchNodes(SDnode *pDnode) { - if (pDnode->ptype != PARENT_PROC) return; - if (pDnode->rtype == NODE_END) return; - - taosThreadMutexLock(&pDnode->mutex); - for (EDndNodeType ntype = DNODE + 1; ntype < NODE_END; ++ntype) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - SProc *proc = &pWrapper->proc; - - if (!pWrapper->required) continue; - if (!OnlyInParentProc(pWrapper)) continue; - - if (proc->pid <= 0 || !taosProcExist(proc->pid)) { - dError("node:%s, pid:%d is killed and needs to restart", pWrapper->name, proc->pid); - dmCloseProcRpcHandles(&pWrapper->proc); - dmNewProc(pWrapper, ntype); - } - } - taosThreadMutexUnlock(&pDnode->mutex); -} - int32_t dmRunDnode(SDnode *pDnode) { - int count = 0; + int32_t count = 0; if (dmOpenNodes(pDnode) != 0) { dError("failed to open nodes since %s", terrstr()); return -1; @@ -273,6 +139,7 @@ int32_t dmRunDnode(SDnode *pDnode) { dError("failed to start nodes since %s", terrstr()); return -1; } + while (1) { if (pDnode->stop) { dInfo("TDengine is about to stop"); @@ -282,8 +149,8 @@ int32_t dmRunDnode(SDnode *pDnode) { return 0; } - dmWatchNodes(pDnode); if (count == 0) osUpdate(); + count %= 10; count++; taosMsleep(100); diff --git a/source/dnode/mgmt/node_mgmt/src/dmProc.c b/source/dnode/mgmt/node_mgmt/src/dmProc.c deleted file mode 100644 index dc07455e6bd5abd99e890348232a8fb33491c1b1..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/node_mgmt/src/dmProc.c +++ /dev/null @@ -1,486 +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 . - */ - -#define _DEFAULT_SOURCE -#include "dmMgmt.h" - -static inline int32_t CEIL8(int32_t v) { return ceil((float)(v) / 8) * 8; } - -static int32_t dmInitProcMutex(SProcQueue *queue) { - TdThreadMutexAttr mattr = {0}; - - if (taosThreadMutexAttrInit(&mattr) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to init mutex while init attr since %s", queue->name, terrstr()); - return -1; - } - - if (taosThreadMutexAttrSetPshared(&mattr, PTHREAD_PROCESS_SHARED) != 0) { - taosThreadMutexAttrDestroy(&mattr); - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to init mutex while set shared since %s", queue->name, terrstr()); - return -1; - } - - if (taosThreadMutexInit(&queue->mutex, &mattr) != 0) { - taosThreadMutexAttrDestroy(&mattr); - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to init mutex since %s", queue->name, terrstr()); - return -1; - } - - taosThreadMutexAttrDestroy(&mattr); - return 0; -} - -static int32_t dmInitProcSem(SProcQueue *queue) { - if (tsem_init(&queue->sem, 1, 0) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to init sem since %s", queue->name, terrstr()); - return -1; - } - - return 0; -} - -static SProcQueue *dmInitProcQueue(SProc *proc, char *ptr, int32_t size) { - SProcQueue *queue = (SProcQueue *)(ptr); - - int32_t bufSize = size - CEIL8(sizeof(SProcQueue)); - if (bufSize <= 1024) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } - - if (proc->ptype & DND_PROC_PARENT) { - memset(ptr, 0, sizeof(SProcQueue)); - if (dmInitProcMutex(queue) != 0) { - return NULL; - } - - if (dmInitProcSem(queue) != 0) { - return NULL; - } - - tstrncpy(queue->name, proc->name, sizeof(queue->name)); - - taosThreadMutexLock(&queue->mutex); - // queue->head = 0; - // queue->tail = 0; - queue->total = bufSize; - queue->avail = bufSize; - // queue->items = 0; - taosThreadMutexUnlock(&queue->mutex); - } - - return queue; -} - -static void dmCleanupProcQueue(SProcQueue *queue) {} - -static inline int32_t dmPushToProcQueue(SProc *proc, SProcQueue *queue, SRpcMsg *pMsg, EProcFuncType ftype) { - const void *pHead = pMsg; - const void *pBody = pMsg->pCont; - const int16_t rawHeadLen = sizeof(SRpcMsg); - const int32_t rawBodyLen = pMsg->contLen; - const int16_t headLen = CEIL8(rawHeadLen); - const int32_t bodyLen = CEIL8(rawBodyLen); - const int32_t fullLen = headLen + bodyLen + 8; - const int64_t handle = (int64_t)pMsg->info.handle; - - if (fullLen > queue->total) { - terrno = TSDB_CODE_OUT_OF_RANGE; - return -1; - } - - taosThreadMutexLock(&queue->mutex); - if (fullLen > queue->avail) { - taosThreadMutexUnlock(&queue->mutex); - terrno = TSDB_CODE_OUT_OF_SHM_MEM; - return -1; - } - - if (ftype == DND_FUNC_REQ && IsReq(pMsg) && pMsg->code == 0 && handle != 0 && pMsg->info.noResp == 0) { - if (taosHashPut(proc->hash, &handle, sizeof(int64_t), &pMsg->info, sizeof(SRpcConnInfo)) != 0) { - taosThreadMutexUnlock(&queue->mutex); - return -1; - } - } - - const int32_t pos = queue->tail; - if (queue->tail < queue->total) { - *(int16_t *)(queue->pBuffer + queue->tail) = rawHeadLen; - *(int8_t *)(queue->pBuffer + queue->tail + 2) = (int8_t)ftype; - *(int32_t *)(queue->pBuffer + queue->tail + 4) = rawBodyLen; - } else { - *(int16_t *)(queue->pBuffer) = rawHeadLen; - *(int8_t *)(queue->pBuffer + 2) = (int8_t)ftype; - *(int32_t *)(queue->pBuffer + 4) = rawBodyLen; - } - - if (queue->tail < queue->head) { - memcpy(queue->pBuffer + queue->tail + 8, pHead, rawHeadLen); - if (rawBodyLen > 0) memcpy(queue->pBuffer + queue->tail + 8 + headLen, pBody, rawBodyLen); - queue->tail = queue->tail + 8 + headLen + bodyLen; - } else { - int32_t remain = queue->total - queue->tail; - if (remain == 0) { - memcpy(queue->pBuffer + 8, pHead, rawHeadLen); - if (rawBodyLen > 0) memcpy(queue->pBuffer + 8 + headLen, pBody, rawBodyLen); - queue->tail = 8 + headLen + bodyLen; - } else if (remain == 8) { - memcpy(queue->pBuffer, pHead, rawHeadLen); - if (rawBodyLen > 0) memcpy(queue->pBuffer + headLen, pBody, rawBodyLen); - queue->tail = headLen + bodyLen; - } else if (remain < 8 + headLen) { - memcpy(queue->pBuffer + queue->tail + 8, pHead, remain - 8); - memcpy(queue->pBuffer, (char *)pHead + remain - 8, rawHeadLen - (remain - 8)); - if (rawBodyLen > 0) memcpy(queue->pBuffer + headLen - (remain - 8), pBody, rawBodyLen); - queue->tail = headLen - (remain - 8) + bodyLen; - } else if (remain < 8 + headLen + bodyLen) { - memcpy(queue->pBuffer + queue->tail + 8, pHead, rawHeadLen); - if (rawBodyLen > 0) memcpy(queue->pBuffer + queue->tail + 8 + headLen, pBody, remain - 8 - headLen); - if (rawBodyLen > 0) - memcpy(queue->pBuffer, (char *)pBody + remain - 8 - headLen, rawBodyLen - (remain - 8 - headLen)); - queue->tail = bodyLen - (remain - 8 - headLen); - } else { - memcpy(queue->pBuffer + queue->tail + 8, pHead, rawHeadLen); - if (rawBodyLen > 0) memcpy(queue->pBuffer + queue->tail + headLen + 8, pBody, rawBodyLen); - queue->tail = queue->tail + headLen + bodyLen + 8; - } - } - - queue->avail -= fullLen; - queue->items++; - taosThreadMutexUnlock(&queue->mutex); - tsem_post(&queue->sem); - - dTrace("node:%s, push %s msg:%p type:%d handle:%p len:%d code:0x%x, pos:%d remain:%d", queue->name, dmFuncStr(ftype), - pMsg, pMsg->msgType, pMsg->info.handle, pMsg->contLen, pMsg->code, pos, queue->items); - return 0; -} - -static inline int32_t dmPopFromProcQueue(SProcQueue *queue, SRpcMsg **ppMsg, EProcFuncType *pFuncType) { - tsem_wait(&queue->sem); - - taosThreadMutexLock(&queue->mutex); - if (queue->total - queue->avail <= 0) { - taosThreadMutexUnlock(&queue->mutex); - terrno = TSDB_CODE_OUT_OF_SHM_MEM; - return 0; - } - - int16_t rawHeadLen = 0; - int8_t ftype = 0; - int32_t rawBodyLen = 0; - if (queue->head < queue->total) { - rawHeadLen = *(int16_t *)(queue->pBuffer + queue->head); - ftype = *(int8_t *)(queue->pBuffer + queue->head + 2); - rawBodyLen = *(int32_t *)(queue->pBuffer + queue->head + 4); - } else { - rawHeadLen = *(int16_t *)(queue->pBuffer); - ftype = *(int8_t *)(queue->pBuffer + 2); - rawBodyLen = *(int32_t *)(queue->pBuffer + 4); - } - int16_t headLen = CEIL8(rawHeadLen); - int32_t bodyLen = CEIL8(rawBodyLen); - - void *pHead = taosAllocateQitem(headLen, DEF_QITEM); - void *pBody = NULL; - if (bodyLen > 0) pBody = rpcMallocCont(bodyLen); - if (pHead == NULL || (bodyLen > 0 && pBody == NULL)) { - taosThreadMutexUnlock(&queue->mutex); - tsem_post(&queue->sem); - taosFreeQitem(pHead); - rpcFreeCont(pBody); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - const int32_t pos = queue->head; - if (queue->head < queue->tail) { - memcpy(pHead, queue->pBuffer + queue->head + 8, headLen); - if (bodyLen > 0) memcpy(pBody, queue->pBuffer + queue->head + 8 + headLen, bodyLen); - queue->head = queue->head + 8 + headLen + bodyLen; - } else { - int32_t remain = queue->total - queue->head; - if (remain == 0) { - memcpy(pHead, queue->pBuffer + 8, headLen); - if (bodyLen > 0) memcpy(pBody, queue->pBuffer + 8 + headLen, bodyLen); - queue->head = 8 + headLen + bodyLen; - } else if (remain == 8) { - memcpy(pHead, queue->pBuffer, headLen); - if (bodyLen > 0) memcpy(pBody, queue->pBuffer + headLen, bodyLen); - queue->head = headLen + bodyLen; - } else if (remain < 8 + headLen) { - memcpy(pHead, queue->pBuffer + queue->head + 8, remain - 8); - memcpy((char *)pHead + remain - 8, queue->pBuffer, headLen - (remain - 8)); - if (bodyLen > 0) memcpy(pBody, queue->pBuffer + headLen - (remain - 8), bodyLen); - queue->head = headLen - (remain - 8) + bodyLen; - } else if (remain < 8 + headLen + bodyLen) { - memcpy(pHead, queue->pBuffer + queue->head + 8, headLen); - if (bodyLen > 0) memcpy(pBody, queue->pBuffer + queue->head + 8 + headLen, remain - 8 - headLen); - if (bodyLen > 0) memcpy((char *)pBody + remain - 8 - headLen, queue->pBuffer, bodyLen - (remain - 8 - headLen)); - queue->head = bodyLen - (remain - 8 - headLen); - } else { - memcpy(pHead, queue->pBuffer + queue->head + 8, headLen); - if (bodyLen > 0) memcpy(pBody, queue->pBuffer + queue->head + headLen + 8, bodyLen); - queue->head = queue->head + headLen + bodyLen + 8; - } - } - - queue->avail = queue->avail + headLen + bodyLen + 8; - queue->items--; - taosThreadMutexUnlock(&queue->mutex); - - *ppMsg = pHead; - (*ppMsg)->pCont = pBody; - *pFuncType = (EProcFuncType)ftype; - - dTrace("node:%s, pop %s msg:%p type:%d handle:%p len:%d code:0x%x, pos:%d remain:%d", queue->name, dmFuncStr(ftype), - (*ppMsg), (*ppMsg)->msgType, (*ppMsg)->info.handle, (*ppMsg)->contLen, (*ppMsg)->code, pos, queue->items); - return 1; -} - -int32_t dmInitProc(struct SMgmtWrapper *pWrapper) { - SProc *proc = &pWrapper->proc; - if (proc->name != NULL) return 0; - - proc->wrapper = pWrapper; - proc->name = pWrapper->name; - - SShm *shm = &proc->shm; - int32_t cstart = 0; - int32_t csize = CEIL8(shm->size / 2); - int32_t pstart = csize; - int32_t psize = CEIL8(shm->size - pstart); - if (pstart + psize > shm->size) { - psize -= 8; - } - - proc->hash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); - proc->cqueue = dmInitProcQueue(proc, (char *)shm->ptr + cstart, csize); - proc->pqueue = dmInitProcQueue(proc, (char *)shm->ptr + pstart, psize); - if (proc->cqueue == NULL || proc->pqueue == NULL || proc->hash == NULL) { - dmCleanupProcQueue(proc->cqueue); - dmCleanupProcQueue(proc->pqueue); - taosHashCleanup(proc->hash); - return -1; - } - - dDebug("node:%s, proc is initialized, cqueue:%p pqueue:%p", proc->name, proc->cqueue, proc->pqueue); - return 0; -} - -static void *dmConsumChildQueue(void *param) { - SProc *proc = param; - SMgmtWrapper *pWrapper = proc->wrapper; - SProcQueue *queue = proc->cqueue; - int32_t numOfMsgs = 0; - int32_t code = 0; - EProcFuncType ftype = DND_FUNC_REQ; - SRpcMsg *pMsg = NULL; - - dDebug("node:%s, start to consume from cqueue", proc->name); - do { - numOfMsgs = dmPopFromProcQueue(queue, &pMsg, &ftype); - if (numOfMsgs == 0) { - dDebug("node:%s, get no msg from cqueue and exit thread", proc->name); - break; - } - - if (numOfMsgs < 0) { - dError("node:%s, get no msg from cqueue since %s", proc->name, terrstr()); - taosMsleep(1); - continue; - } - - if (ftype != DND_FUNC_REQ) { - dError("node:%s, invalid ftype:%d from cqueue", proc->name, ftype); - rpcFreeCont(pMsg->pCont); - taosFreeQitem(pMsg); - continue; - } - - code = dmProcessNodeMsg(pWrapper, pMsg); - if (code != 0) { - dError("node:%s, failed to process msg:%p since %s, put into pqueue", proc->name, pMsg, terrstr()); - SRpcMsg rsp = {.code = (terrno != 0 ? terrno : code), .info = pMsg->info}; - dmPutToProcPQueue(proc, &rsp, DND_FUNC_RSP); - rpcFreeCont(pMsg->pCont); - taosFreeQitem(pMsg); - } - } while (1); - - return NULL; -} - -static void *dmConsumParentQueue(void *param) { - SProc *proc = param; - SMgmtWrapper *pWrapper = proc->wrapper; - SProcQueue *queue = proc->pqueue; - int32_t numOfMsgs = 0; - int32_t code = 0; - EProcFuncType ftype = DND_FUNC_REQ; - SRpcMsg *pMsg = NULL; - - dDebug("node:%s, start to consume from pqueue", proc->name); - do { - numOfMsgs = dmPopFromProcQueue(queue, &pMsg, &ftype); - if (numOfMsgs == 0) { - dDebug("node:%s, get no msg from pqueue and exit thread", proc->name); - break; - } - - if (numOfMsgs < 0) { - dError("node:%s, get no msg from pqueue since %s", proc->name, terrstr()); - taosMsleep(1); - continue; - } - - if (ftype == DND_FUNC_RSP) { - dmRemoveProcRpcHandle(proc, pMsg->info.handle); - rpcSendResponse(pMsg); - } else if (ftype == DND_FUNC_REGIST) { - rpcRegisterBrokenLinkArg(pMsg); - } else if (ftype == DND_FUNC_RELEASE) { - dmRemoveProcRpcHandle(proc, pMsg->info.handle); - rpcReleaseHandle(&pMsg->info, TAOS_CONN_SERVER); - } else { - dError("node:%s, invalid ftype:%d from pqueue", proc->name, ftype); - rpcFreeCont(pMsg->pCont); - } - - taosFreeQitem(pMsg); - } while (1); - - return NULL; -} - -int32_t dmRunProc(SProc *proc) { - TdThreadAttr thAttr = {0}; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); - - if (proc->ptype & DND_PROC_PARENT) { - if (taosThreadCreate(&proc->pthread, &thAttr, dmConsumParentQueue, proc) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to create pthread since %s", proc->name, terrstr()); - return -1; - } - dDebug("node:%s, thread:%" PRId64 " is created to consume pqueue", proc->name, proc->pthread); - } - - if (proc->ptype & DND_PROC_CHILD) { - if (taosThreadCreate(&proc->cthread, &thAttr, dmConsumChildQueue, proc) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to create cthread since %s", proc->name, terrstr()); - return -1; - } - dDebug("node:%s, thread:%" PRId64 " is created to consume cqueue", proc->name, proc->cthread); - } - - taosThreadAttrDestroy(&thAttr); - return 0; -} - -void dmStopProc(SProc *proc) { - proc->stop = true; - if (taosCheckPthreadValid(proc->pthread)) { - dDebug("node:%s, start to join pthread:%" PRId64, proc->name, proc->pthread); - tsem_post(&proc->pqueue->sem); - taosThreadJoin(proc->pthread, NULL); - taosThreadClear(&proc->pthread); - } - - if (taosCheckPthreadValid(proc->cthread)) { - dDebug("node:%s, start to join cthread:%" PRId64, proc->name, proc->cthread); - tsem_post(&proc->cqueue->sem); - taosThreadJoin(proc->cthread, NULL); - taosThreadClear(&proc->cthread); - } -} - -void dmCleanupProc(struct SMgmtWrapper *pWrapper) { - SProc *proc = &pWrapper->proc; - if (proc->name == NULL) return; - - dDebug("node:%s, start to cleanup proc", pWrapper->name); - dmStopProc(proc); - dmCleanupProcQueue(proc->cqueue); - dmCleanupProcQueue(proc->pqueue); - taosHashCleanup(proc->hash); - proc->hash = NULL; - dDebug("node:%s, proc is cleaned up", pWrapper->name); -} - -void dmRemoveProcRpcHandle(SProc *proc, void *handle) { - int64_t h = (int64_t)handle; - taosThreadMutexLock(&proc->cqueue->mutex); - taosHashRemove(proc->hash, &h, sizeof(int64_t)); - taosThreadMutexUnlock(&proc->cqueue->mutex); -} - -void dmCloseProcRpcHandles(SProc *proc) { - taosThreadMutexLock(&proc->cqueue->mutex); - SRpcHandleInfo *pInfo = taosHashIterate(proc->hash, NULL); - while (pInfo != NULL) { - dError("node:%s, the child process dies and send an offline rsp to handle:%p", proc->name, pInfo->handle); - SRpcMsg rpcMsg = {.code = TSDB_CODE_NODE_OFFLINE, .info = *pInfo}; - rpcSendResponse(&rpcMsg); - pInfo = taosHashIterate(proc->hash, pInfo); - } - taosHashClear(proc->hash); - taosThreadMutexUnlock(&proc->cqueue->mutex); -} - -void dmPutToProcPQueue(SProc *proc, SRpcMsg *pMsg, EProcFuncType ftype) { - int32_t retry = 0; - while (1) { - if (dmPushToProcQueue(proc, proc->pqueue, pMsg, ftype) == 0) { - break; - } - - if (terrno != TSDB_CODE_OUT_OF_SHM_MEM) { - pMsg->code = terrno; - if (pMsg->contLen > 0) { - rpcFreeCont(pMsg->pCont); - pMsg->pCont = NULL; - pMsg->contLen = 0; - } - dError("node:%s, failed to push %s msg:%p type:%d handle:%p then discard data and return error", proc->name, - dmFuncStr(ftype), pMsg, pMsg->msgType, pMsg->info.handle); - } else { - dError("node:%s, failed to push %s msg:%p type:%d handle:%p len:%d since %s, retry:%d", proc->name, - dmFuncStr(ftype), pMsg, pMsg->msgType, pMsg->info.handle, pMsg->contLen, terrstr(), retry); - retry++; - taosMsleep(retry); - } - } - - rpcFreeCont(pMsg->pCont); - pMsg->pCont = NULL; - pMsg->contLen = 0; -} - -int32_t dmPutToProcCQueue(SProc *proc, SRpcMsg *pMsg, EProcFuncType ftype) { - int32_t code = dmPushToProcQueue(proc, proc->cqueue, pMsg, ftype); - if (code == 0) { - dTrace("msg:%p, is freed after push to cqueue", pMsg); - rpcFreeCont(pMsg->pCont); - taosFreeQitem(pMsg); - } - return code; -} diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 542baaec091b5d9bf8ce04a10ee4edc8463fc203..7ad24be258ee23b547543f0296cc27ea281ee89f 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -17,14 +17,7 @@ #include "dmMgmt.h" #include "qworker.h" -static inline void dmSendRsp(SRpcMsg *pMsg) { - SMgmtWrapper *pWrapper = pMsg->info.wrapper; - if (InChildProc(pWrapper)) { - dmPutToProcPQueue(&pWrapper->proc, pMsg, DND_FUNC_RSP); - } else { - rpcSendResponse(pMsg); - } -} +static inline void dmSendRsp(SRpcMsg *pMsg) { rpcSendResponse(pMsg); } static inline void dmBuildMnodeRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) { SEpSet epSet = {0}; @@ -157,11 +150,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) { memcpy(pMsg, pRpc, sizeof(SRpcMsg)); dGTrace("msg:%p, is created, type:%s handle:%p", pMsg, TMSG_INFO(pRpc->msgType), pMsg->info.handle); - if (InParentProc(pWrapper)) { - code = dmPutToProcCQueue(&pWrapper->proc, pMsg, DND_FUNC_REQ); - } else { - code = dmProcessNodeMsg(pWrapper, pMsg); - } + code = dmProcessNodeMsg(pWrapper, pMsg); _OVER: if (code != 0) { @@ -233,24 +222,9 @@ static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) { } } -static inline void dmRegisterBrokenLinkArg(SRpcMsg *pMsg) { - SMgmtWrapper *pWrapper = pMsg->info.wrapper; - if (InChildProc(pWrapper)) { - dmPutToProcPQueue(&pWrapper->proc, pMsg, DND_FUNC_REGIST); - } else { - rpcRegisterBrokenLinkArg(pMsg); - } -} +static inline void dmRegisterBrokenLinkArg(SRpcMsg *pMsg) { rpcRegisterBrokenLinkArg(pMsg); } -static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) { - SMgmtWrapper *pWrapper = pHandle->wrapper; - if (InChildProc(pWrapper)) { - SRpcMsg msg = {.code = type, .info = *pHandle}; - dmPutToProcPQueue(&pWrapper->proc, &msg, DND_FUNC_RELEASE); - } else { - rpcReleaseHandle(pHandle, type); - } -} +static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) { rpcReleaseHandle(pHandle, type); } static bool rpcRfp(int32_t code, tmsg_t msgType) { if (code == TSDB_CODE_RPC_REDIRECT || code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_NODE_NOT_DEPLOYED || diff --git a/source/dnode/mgmt/node_util/inc/dmUtil.h b/source/dnode/mgmt/node_util/inc/dmUtil.h index 2f9c0aff2f9bd94638587fa18362bbb4a6312934..8719e988e7acd44548708a83f9e846d981170712 100644 --- a/source/dnode/mgmt/node_util/inc/dmUtil.h +++ b/source/dnode/mgmt/node_util/inc/dmUtil.h @@ -83,20 +83,6 @@ typedef enum { DND_ENV_CLEANUP, } EDndEnvStatus; -typedef enum { - DND_PROC_SINGLE, - DND_PROC_CHILD, - DND_PROC_PARENT, - DND_PROC_TEST, -} EDndProcType; - -typedef enum { - DND_FUNC_REQ = 1, - DND_FUNC_RSP = 2, - DND_FUNC_REGIST = 3, - DND_FUNC_RELEASE = 4, -} EProcFuncType; - typedef int32_t (*ProcessCreateNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg); typedef int32_t (*ProcessDropNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg); typedef void (*SendMonitorReportFp)(); @@ -165,11 +151,7 @@ typedef struct { // dmUtil.c const char *dmStatStr(EDndRunStatus stype); -const char *dmNodeLogName(EDndNodeType ntype); -const char *dmNodeProcName(EDndNodeType ntype); const char *dmNodeName(EDndNodeType ntype); -const char *dmProcStr(EDndProcType ptype); -const char *dmFuncStr(EProcFuncType etype); void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId); void dmGetMonitorSystemInfo(SMonSysInfo *pInfo); @@ -177,8 +159,6 @@ void dmGetMonitorSystemInfo(SMonSysInfo *pInfo); int32_t dmReadFile(const char *path, const char *name, bool *pDeployed); int32_t dmWriteFile(const char *path, const char *name, bool deployed); TdFilePtr dmCheckRunning(const char *dataDir); -int32_t dmReadShmFile(const char *path, const char *name, EDndNodeType runType, SShm *pShm); -int32_t dmWriteShmFile(const char *path, const char *name, const SShm *pShm); // dmEps.c int32_t dmReadEps(SDnodeData *pData); diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c index 9ec17a18b57ac2ce28dfb7c65704748719bc2e0a..d387fe4a3f52400e3dcb5521d4c7a94c8802d607 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -148,114 +148,3 @@ TdFilePtr dmCheckRunning(const char *dataDir) { dDebug("lock file:%s to prevent repeated starts", filepath); return pFile; } - -int32_t dmReadShmFile(const char *path, const char *name, EDndNodeType runType, SShm *pShm) { - int32_t code = -1; - char content[MAXLEN + 1] = {0}; - char file[PATH_MAX] = {0}; - cJSON *root = NULL; - TdFilePtr pFile = NULL; - - snprintf(file, sizeof(file), "%s%sshmfile", path, TD_DIRSEP); - pFile = taosOpenFile(file, TD_FILE_READ); - if (pFile == NULL) { - code = 0; - goto _OVER; - } - - if (taosReadFile(pFile, content, MAXLEN) > 0) { - root = cJSON_Parse(content); - if (root == NULL) { - terrno = TSDB_CODE_INVALID_JSON_FORMAT; - dError("node:%s, failed to read %s since invalid json format", name, file); - goto _OVER; - } - - cJSON *shmid = cJSON_GetObjectItem(root, "shmid"); - if (shmid && shmid->type == cJSON_Number) { - pShm->id = shmid->valueint; - } - - cJSON *shmsize = cJSON_GetObjectItem(root, "shmsize"); - if (shmsize && shmsize->type == cJSON_Number) { - pShm->size = shmsize->valueint; - } - } - - if (!tsMultiProcess || runType == DNODE || runType == NODE_END) { - if (pShm->id >= 0) { - dDebug("node:%s, shmid:%d, is closed, size:%d", name, pShm->id, pShm->size); - taosDropShm(pShm); - } - } else { - if (taosAttachShm(pShm) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("shmid:%d, failed to attach shm since %s", pShm->id, terrstr()); - goto _OVER; - } - dInfo("node:%s, shmid:%d is attached, size:%d", name, pShm->id, pShm->size); - } - - dDebug("node:%s, successed to load %s", name, file); - code = 0; - -_OVER: - if (root != NULL) cJSON_Delete(root); - if (pFile != NULL) taosCloseFile(&pFile); - - return code; -} - -int32_t dmWriteShmFile(const char *path, const char *name, const SShm *pShm) { - int32_t code = -1; - int32_t len = 0; - char content[MAXLEN + 1] = {0}; - char file[PATH_MAX] = {0}; - char realfile[PATH_MAX] = {0}; - TdFilePtr pFile = NULL; - - snprintf(file, sizeof(file), "%s%sshmfile.bak", path, TD_DIRSEP); - snprintf(realfile, sizeof(realfile), "%s%sshmfile", path, TD_DIRSEP); - - pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); - if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to open file:%s since %s", name, file, terrstr()); - goto _OVER; - } - - len += snprintf(content + len, MAXLEN - len, "{\n"); - len += snprintf(content + len, MAXLEN - len, " \"shmid\":%d,\n", pShm->id); - len += snprintf(content + len, MAXLEN - len, " \"shmsize\":%d\n", pShm->size); - len += snprintf(content + len, MAXLEN - len, "}\n"); - - if (taosWriteFile(pFile, content, len) != len) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to write file:%s since %s", name, file, terrstr()); - goto _OVER; - } - - if (taosFsyncFile(pFile) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to fsync file:%s since %s", name, file, terrstr()); - goto _OVER; - } - - taosCloseFile(&pFile); - - if (taosRenameFile(file, realfile) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to rename %s to %s since %s", name, file, realfile, terrstr()); - return -1; - } - - dInfo("node:%s, successed to write %s", name, realfile); - code = 0; - -_OVER: - if (pFile != NULL) { - taosCloseFile(&pFile); - } - - return code; -} diff --git a/source/dnode/mgmt/node_util/src/dmUtil.c b/source/dnode/mgmt/node_util/src/dmUtil.c index f5364b3195ebf9637df6fc86cbe536041df14756..80bb8debd28db2a6f15fbeb243702b267dd38676 100644 --- a/source/dnode/mgmt/node_util/src/dmUtil.c +++ b/source/dnode/mgmt/node_util/src/dmUtil.c @@ -29,36 +29,6 @@ const char *dmStatStr(EDndRunStatus stype) { } } -const char *dmNodeLogName(EDndNodeType ntype) { - switch (ntype) { - case VNODE: - return "vnode"; - case QNODE: - return "qnode"; - case SNODE: - return "snode"; - case MNODE: - return "mnode"; - default: - return "taosd"; - } -} - -const char *dmNodeProcName(EDndNodeType ntype) { - switch (ntype) { - case VNODE: - return "taosv"; - case QNODE: - return "taosq"; - case SNODE: - return "taoss"; - case MNODE: - return "taosm"; - default: - return "taosd"; - } -} - const char *dmNodeName(EDndNodeType ntype) { switch (ntype) { case VNODE: @@ -74,36 +44,6 @@ const char *dmNodeName(EDndNodeType ntype) { } } -const char *dmProcStr(EDndProcType etype) { - switch (etype) { - case DND_PROC_SINGLE: - return "start"; - case DND_PROC_CHILD: - return "stop"; - case DND_PROC_PARENT: - return "child"; - case DND_PROC_TEST: - return "test"; - default: - return "UNKNOWN"; - } -} - -const char *dmFuncStr(EProcFuncType etype) { - switch (etype) { - case DND_FUNC_REQ: - return "req"; - case DND_FUNC_RSP: - return "rsp"; - case DND_FUNC_REGIST: - return "regist"; - case DND_FUNC_RELEASE: - return "release"; - default: - return "UNKNOWN"; - } -} - void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool needCheckVgId) { SMgmtHandle handle = { .msgType = msgType, diff --git a/source/dnode/mgmt/test/sut/src/server.cpp b/source/dnode/mgmt/test/sut/src/server.cpp index de35b06b05bb2034340f441036f01e6f928c5b08..98c59a1614303c4c8a342d1d63ab39e9116214fd 100644 --- a/source/dnode/mgmt/test/sut/src/server.cpp +++ b/source/dnode/mgmt/test/sut/src/server.cpp @@ -16,7 +16,7 @@ #include "sut.h" void* serverLoop(void* param) { - dmInit(0); + dmInit(); dmRun(); dmCleanup(); return NULL; diff --git a/source/dnode/mgmt/test/vnode/vnode.cpp b/source/dnode/mgmt/test/vnode/vnode.cpp index 520d844dbd2abaf07346bb1a1269c2e1ad85ad8d..8a8e3322891c60d067941cd886b8b6498c8346b1 100644 --- a/source/dnode/mgmt/test/vnode/vnode.cpp +++ b/source/dnode/mgmt/test/vnode/vnode.cpp @@ -70,7 +70,7 @@ TEST_F(DndTestVnode, 01_Create_Vnode) { TEST_F(DndTestVnode, 02_Alter_Vnode) { for (int i = 0; i < 3; ++i) { - SAlterVnodeReq alterReq = {0}; + SAlterVnodeConfigReq alterReq = {0}; alterReq.vgVersion = 2; alterReq.daysPerFile = 10; alterReq.daysToKeep0 = 3650; diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 48eea7daeacd75ea5219ee627e5e11293579b2d8..74a92c9fcd1e021ccef13c86556b96a228e02feb 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -204,7 +204,8 @@ typedef struct { int32_t id; int64_t createdTime; int64_t updateTime; - ESyncState state; + ESyncState syncState; + bool syncRestore; int64_t stateStartTime; SDnodeObj* pDnode; } SMnodeObj; @@ -324,7 +325,8 @@ typedef struct { typedef struct { int32_t dnodeId; - ESyncState role; + ESyncState syncState; + bool syncRestore; } SVnodeGid; typedef struct { @@ -611,6 +613,7 @@ typedef struct { // config int8_t igExpired; int8_t trigger; + int8_t fillHistory; int64_t triggerParam; int64_t watermark; // source and target diff --git a/source/dnode/mnode/impl/inc/mndVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h index ad5fbef34cc9b94273d10cd4be88c17d1c940182..76c351980804840382fa8916e8aa4be868901056 100644 --- a/source/dnode/mnode/impl/inc/mndVgroup.h +++ b/source/dnode/mnode/impl/inc/mndVgroup.h @@ -38,7 +38,7 @@ int32_t mndAllocSmaVgroup(SMnode *, SDbObj *pDb, SVgObj *pVgroup); int32_t mndAllocVgroup(SMnode *, SDbObj *pDb, SVgObj **ppVgroups); int32_t mndAddVnodeToVgroup(SMnode *, SVgObj *pVgroup, SArray *pArray); int32_t mndRemoveVnodeFromVgroup(SMnode *, SVgObj *pVgroup, SArray *pArray, SVnodeGid *pDelVgid); -int32_t mndAddCreateVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, bool standby); +int32_t mndAddCreateVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid); int32_t mndAddAlterVnodeConfirmAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup); int32_t mndAddAlterVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, tmsg_t msgType); int32_t mndAddDropVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, bool isRedo); @@ -47,9 +47,8 @@ int32_t mndSetMoveVgroupsInfoToTrans(SMnode *, STrans *pTrans, int32_t dropDnode int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb, SVgObj *pVgroup, SArray *pArray); -void *mndBuildCreateVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *cntlen, bool standby); +void *mndBuildCreateVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen); void *mndBuildDropVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen); -void *mndBuildAlterVnodeReq(SMnode *, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen); bool mndVgroupInDb(SVgObj *pVgroup, int64_t dbUid); #ifdef __cplusplus diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 46aaa7ffe16c9d684229480ac88a29e0469987b3..77f91b6d29a37ceaf9ade6ecda5b917ed4a3773f 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -278,7 +278,7 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) { SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, consumerId); if (pConsumer == NULL) { - mError("consumer %ld not exist", consumerId); + mError("consumer %" PRId64 " not exist", consumerId); terrno = TSDB_CODE_MND_CONSUMER_NOT_EXIST; return -1; } @@ -288,7 +288,7 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) { int32_t status = atomic_load_32(&pConsumer->status); if (status == MQ_CONSUMER_STATUS__LOST_REBD) { - mInfo("try to recover consumer %ld", consumerId); + mInfo("try to recover consumer %" PRId64 "", consumerId); SMqConsumerRecoverMsg *pRecoverMsg = rpcMallocCont(sizeof(SMqConsumerRecoverMsg)); pRecoverMsg->consumerId = consumerId; @@ -327,7 +327,7 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) { #if 1 if (status == MQ_CONSUMER_STATUS__LOST_REBD) { - mInfo("try to recover consumer %ld", consumerId); + mInfo("try to recover consumer %" PRId64 "", consumerId); SMqConsumerRecoverMsg *pRecoverMsg = rpcMallocCont(sizeof(SMqConsumerRecoverMsg)); pRecoverMsg->consumerId = consumerId; @@ -341,7 +341,7 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) { #endif if (status != MQ_CONSUMER_STATUS__READY) { - mInfo("consumer %ld not ready, status: %s", consumerId, mndConsumerStatusName(status)); + mInfo("consumer %" PRId64 " not ready, status: %s", consumerId, mndConsumerStatusName(status)); terrno = TSDB_CODE_MND_CONSUMER_NOT_READY; return -1; } diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 3b3187385771da81d703a270c3f9f07e3171505e..1fa886b722bacfc4ac15b0ed2700769b55c6d3e3 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -113,7 +113,7 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { SDB_SET_INT8(pRaw, dataPos, pDb->cfg.hashMethod, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfRetensions, _OVER) for (int32_t i = 0; i < pDb->cfg.numOfRetensions; ++i) { - TASSERT(taosArrayGetSize(pDb->cfg.pRetensions) == pDb->cfg.numOfRetensions); + ASSERT(taosArrayGetSize(pDb->cfg.pRetensions) == pDb->cfg.numOfRetensions); SRetention *pRetension = taosArrayGet(pDb->cfg.pRetensions, i); SDB_SET_INT64(pRaw, dataPos, pRetension->freq, _OVER) SDB_SET_INT64(pRaw, dataPos, pRetension->keep, _OVER) @@ -447,7 +447,7 @@ static int32_t mndSetCreateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj for (int32_t vn = 0; vn < pVgroup->replica; ++vn) { SVnodeGid *pVgid = pVgroup->vnodeGid + vn; - if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pVgid, false) != 0) { + if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pVgid) != 0) { return -1; } } @@ -631,29 +631,18 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) { terrno = TSDB_CODE_MND_DB_OPTION_UNCHANGED; if (pAlter->buffer > 0 && pAlter->buffer != pDb->cfg.buffer) { -#if 0 - terrno = TSDB_CODE_OPS_NOT_SUPPORT; - return terrno; -#else pDb->cfg.buffer = pAlter->buffer; terrno = 0; -#endif } if (pAlter->pages > 0 && pAlter->pages != pDb->cfg.pages) { -#if 0 - terrno = TSDB_CODE_OPS_NOT_SUPPORT; - return terrno; -#else pDb->cfg.pages = pAlter->pages; terrno = 0; -#endif } if (pAlter->pageSize > 0 && pAlter->pageSize != pDb->cfg.pageSize) { #if 1 terrno = TSDB_CODE_OPS_NOT_SUPPORT; - return terrno; #else pDb->cfg.pageSize = pAlter->pageSize; terrno = 0; @@ -710,13 +699,9 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) { } if (pAlter->replications > 0 && pAlter->replications != pDb->cfg.replications) { -#if 1 - terrno = TSDB_CODE_OPS_NOT_SUPPORT; -#else pDb->cfg.replications = pAlter->replications; pDb->vgVersion++; terrno = 0; -#endif } return terrno; @@ -863,6 +848,7 @@ static int32_t mndProcessGetDbCfgReq(SRpcMsg *pReq) { cfgRsp.numOfVgroups = pDb->cfg.numOfVgroups; cfgRsp.numOfStables = pDb->cfg.numOfStables; cfgRsp.buffer = pDb->cfg.buffer; + cfgRsp.cacheSize = pDb->cfg.cacheLastSize; cfgRsp.pageSize = pDb->cfg.pageSize; cfgRsp.pages = pDb->cfg.pages; cfgRsp.daysPerFile = pDb->cfg.daysPerFile; @@ -1157,7 +1143,7 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) { pEp->port = pDnode->port; } mndReleaseDnode(pMnode, pDnode); - if (pVgid->role == TAOS_SYNC_STATE_LEADER) { + if (pVgid->syncState == TAOS_SYNC_STATE_LEADER) { vgInfo.epSet.inUse = gid; } } @@ -1553,7 +1539,7 @@ bool mndIsDbReady(SMnode *pMnode, SDbObj *pDb) { if (pVgroup->dbUid == pDb->uid && pVgroup->replica > 1) { bool hasLeader = false; for (int32_t i = 0; i < pVgroup->replica; ++i) { - if (pVgroup->vnodeGid[i].role == TAOS_SYNC_STATE_LEADER) { + if (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_LEADER) { hasLeader = true; } } diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index 462b068a738b5ca95fc77b8ca86186b9d37c3e1a..143131bac84c984e8f3133cf2a01e74391b8f128 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -18,6 +18,7 @@ #include "mndConsumer.h" int32_t tEncodeSStreamObj(SEncoder *pEncoder, const SStreamObj *pObj) { + if (tStartEncode(pEncoder) < 0) return -1; if (tEncodeCStr(pEncoder, pObj->name) < 0) return -1; if (tEncodeI64(pEncoder, pObj->createTime) < 0) return -1; @@ -31,6 +32,7 @@ int32_t tEncodeSStreamObj(SEncoder *pEncoder, const SStreamObj *pObj) { if (tEncodeI8(pEncoder, pObj->igExpired) < 0) return -1; if (tEncodeI8(pEncoder, pObj->trigger) < 0) return -1; + if (tEncodeI8(pEncoder, pObj->fillHistory) < 0) return -1; if (tEncodeI64(pEncoder, pObj->triggerParam) < 0) return -1; if (tEncodeI64(pEncoder, pObj->watermark) < 0) return -1; @@ -74,10 +76,12 @@ int32_t tEncodeSStreamObj(SEncoder *pEncoder, const SStreamObj *pObj) { if (tEncodeSSchemaWrapper(pEncoder, &pObj->outputSchema) < 0) return -1; + tEndEncode(pEncoder); return pEncoder->pos; } int32_t tDecodeSStreamObj(SDecoder *pDecoder, SStreamObj *pObj) { + if (tStartDecode(pDecoder) < 0) return -1; if (tDecodeCStrTo(pDecoder, pObj->name) < 0) return -1; if (tDecodeI64(pDecoder, &pObj->createTime) < 0) return -1; @@ -91,6 +95,7 @@ int32_t tDecodeSStreamObj(SDecoder *pDecoder, SStreamObj *pObj) { if (tDecodeI8(pDecoder, &pObj->igExpired) < 0) return -1; if (tDecodeI8(pDecoder, &pObj->trigger) < 0) return -1; + if (tDecodeI8(pDecoder, &pObj->fillHistory) < 0) return -1; if (tDecodeI64(pDecoder, &pObj->triggerParam) < 0) return -1; if (tDecodeI64(pDecoder, &pObj->watermark) < 0) return -1; @@ -134,6 +139,7 @@ int32_t tDecodeSStreamObj(SDecoder *pDecoder, SStreamObj *pObj) { if (tDecodeSSchemaWrapper(pDecoder, &pObj->outputSchema) < 0) return -1; + tEndDecode(pDecoder); return 0; } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index fba1fd94d6b537a9f587d898c062f01a0b47df19..264b8d979b7a00de55ae7b10b422ee27889854fc 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -361,10 +361,12 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { bool roleChanged = false; for (int32_t vg = 0; vg < pVgroup->replica; ++vg) { if (pVgroup->vnodeGid[vg].dnodeId == statusReq.dnodeId) { - if (pVgroup->vnodeGid[vg].role != pVload->syncState) { + if (pVgroup->vnodeGid[vg].syncState != pVload->syncState || + pVgroup->vnodeGid[vg].syncRestore != pVload->syncRestore) { + pVgroup->vnodeGid[vg].syncState = pVload->syncState; + pVgroup->vnodeGid[vg].syncRestore = pVload->syncRestore; roleChanged = true; } - pVgroup->vnodeGid[vg].role = pVload->syncState; break; } } @@ -378,10 +380,11 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { SMnodeObj *pObj = mndAcquireMnode(pMnode, pDnode->id); if (pObj != NULL) { - if (pObj->state != statusReq.mload.syncState) { - mInfo("dnode:%d, mnode syncstate from %s to %s", pObj->id, syncStr(pObj->state), - syncStr(statusReq.mload.syncState)); - pObj->state = statusReq.mload.syncState; + if (pObj->syncState != statusReq.mload.syncState || pObj->syncRestore != statusReq.mload.syncRestore) { + mInfo("dnode:%d, mnode syncState from %s to %s, restoreState from %d to %d", pObj->id, syncStr(pObj->syncState), + syncStr(statusReq.mload.syncState), pObj->syncRestore, statusReq.mload.syncRestore); + pObj->syncState = statusReq.mload.syncState; + pObj->syncRestore = statusReq.mload.syncRestore; pObj->stateStartTime = taosGetTimestampMs(); } mndReleaseMnode(pMnode, pObj); diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 4eb2e2978bb77af92d8883139e7b7e5f379eba86..fbfa1b73be6cae79c547b3f21248e25af5cddf3b 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -250,6 +250,7 @@ static int32_t mndInitSdb(SMnode *pMnode) { opt.path = pMnode->path; opt.pMnode = pMnode; opt.pWal = pMnode->pWal; + opt.sync = pMnode->syncMgmt.sync; pMnode->pSdb = sdbInit(&opt); if (pMnode->pSdb == NULL) { @@ -381,6 +382,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { mError("failed to open mnode since %s", terrstr()); return NULL; } + memset(pMnode, 0, sizeof(SMnode)); char timestr[24] = "1970-01-01 00:00:00.00"; (void)taosParseTime(timestr, &pMnode->checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); @@ -474,6 +476,45 @@ void mndStop(SMnode *pMnode) { mndCleanupTimer(pMnode); } +int32_t mndProcessSyncCtrlMsg(SRpcMsg *pMsg) { + SMnode *pMnode = pMsg->info.node; + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + int32_t code = 0; + + mInfo("vgId:%d, process sync ctrl msg", 1); + + if (!syncEnvIsStart()) { + mError("failed to process sync msg:%p type:%s since syncEnv stop", pMsg, TMSG_INFO(pMsg->msgType)); + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + return -1; + } + + SSyncNode *pSyncNode = syncNodeAcquire(pMgmt->sync); + if (pSyncNode == NULL) { + mError("failed to process sync msg:%p type:%s since syncNode is null", pMsg, TMSG_INFO(pMsg->msgType)); + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + return -1; + } + + if (pMsg->msgType == TDMT_SYNC_HEARTBEAT) { + SyncHeartbeat *pSyncMsg = syncHeartbeatFromRpcMsg2(pMsg); + code = syncNodeOnHeartbeat(pSyncNode, pSyncMsg); + syncHeartbeatDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_HEARTBEAT_REPLY) { + SyncHeartbeatReply *pSyncMsg = syncHeartbeatReplyFromRpcMsg2(pMsg); + code = syncNodeOnHeartbeatReply(pSyncNode, pSyncMsg); + syncHeartbeatReplyDestroy(pSyncMsg); + } + + syncNodeRelease(pSyncNode); + + if (code != 0) { + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + } + return code; +} + int32_t mndProcessSyncMsg(SRpcMsg *pMsg) { SMnode *pMnode = pMsg->info.node; SSyncMgmt *pMgmt = &pMnode->syncMgmt; @@ -492,97 +533,64 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) { return -1; } - // ToDo: ugly! use function pointer - if (syncNodeStrategy(pSyncNode) == SYNC_STRATEGY_STANDARD_SNAPSHOT) { - if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { - SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); - code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg); - syncTimeoutDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_PING) { - SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg); - code = syncNodeOnPingCb(pSyncNode, pSyncMsg); - syncPingDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) { - SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg); - code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); - syncPingReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { - SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg); - code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL); - syncClientRequestDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { - SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg); - code = syncNodeOnRequestVoteSnapshotCb(pSyncNode, pSyncMsg); - syncRequestVoteDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { - SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg); - code = syncNodeOnRequestVoteReplySnapshotCb(pSyncNode, pSyncMsg); - syncRequestVoteReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { - SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg); - code = syncNodeOnAppendEntriesSnapshotCb(pSyncNode, pSyncMsg); - syncAppendEntriesDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { - SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg); - code = syncNodeOnAppendEntriesReplySnapshotCb(pSyncNode, pSyncMsg); - syncAppendEntriesReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) { - SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg); - code = syncNodeOnSnapshotSendCb(pSyncNode, pSyncMsg); - syncSnapshotSendDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) { - SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg); - code = syncNodeOnSnapshotRspCb(pSyncNode, pSyncMsg); - syncSnapshotRspDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_SET_MNODE_STANDBY) { - code = syncSetStandby(pMgmt->sync); - SRpcMsg rsp = {.code = code, .info = pMsg->info}; - tmsgSendRsp(&rsp); - } else { - mError("failed to process msg:%p since invalid type:%s", pMsg, TMSG_INFO(pMsg->msgType)); - code = -1; - } + if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { + SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); + code = syncNodeOnTimer(pSyncNode, pSyncMsg); + syncTimeoutDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_PING) { + SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg); + code = syncNodeOnPingCb(pSyncNode, pSyncMsg); + syncPingDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) { + SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg); + code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); + syncPingReplyDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { + SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg); + code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, NULL); + syncClientRequestDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { + SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg); + code = syncNodeOnRequestVote(pSyncNode, pSyncMsg); + syncRequestVoteDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { + SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg); + code = syncNodeOnRequestVoteReply(pSyncNode, pSyncMsg); + syncRequestVoteReplyDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { + SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg); + code = syncNodeOnAppendEntries(pSyncNode, pSyncMsg); + syncAppendEntriesDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { + SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg); + code = syncNodeOnAppendEntriesReply(pSyncNode, pSyncMsg); + syncAppendEntriesReplyDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) { + SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg); + code = syncNodeOnSnapshot(pSyncNode, pSyncMsg); + syncSnapshotSendDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) { + SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg); + code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg); + syncSnapshotRspDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_SET_MNODE_STANDBY) { + code = syncSetStandby(pMgmt->sync); + SRpcMsg rsp = {.code = code, .info = pMsg->info}; + tmsgSendRsp(&rsp); + } else { - if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { - SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); - code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg); - syncTimeoutDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_PING) { - SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg); - code = syncNodeOnPingCb(pSyncNode, pSyncMsg); - syncPingDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) { - SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg); - code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); - syncPingReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { - SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg); - code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL); - syncClientRequestDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { - SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg); - code = syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg); - syncRequestVoteDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { - SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg); - code = syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg); - syncRequestVoteReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { - SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg); - code = syncNodeOnAppendEntriesCb(pSyncNode, pSyncMsg); - syncAppendEntriesDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { - SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg); - code = syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg); - syncAppendEntriesReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_SET_MNODE_STANDBY) { - code = syncSetStandby(pMgmt->sync); - SRpcMsg rsp = {.code = code, .info = pMsg->info}; - tmsgSendRsp(&rsp); - } else { - mError("failed to process msg:%p since invalid type:%s", pMsg, TMSG_INFO(pMsg->msgType)); - code = -1; - } + mError("failed to process msg:%p since invalid type:%s", pMsg, TMSG_INFO(pMsg->msgType)); + code = -1; } syncNodeRelease(pSyncNode); @@ -765,7 +773,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr // pClusterInfo->master_uptime = (ms - pObj->stateStartTime) / (86400000.0f); tstrncpy(desc.role, syncStr(TAOS_SYNC_STATE_LEADER), sizeof(desc.role)); } else { - tstrncpy(desc.role, syncStr(pObj->state), sizeof(desc.role)); + tstrncpy(desc.role, syncStr(pObj->syncState), sizeof(desc.role)); } taosArrayPush(pClusterInfo->mnodes, &desc); sdbRelease(pSdb, pObj); @@ -795,12 +803,12 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr SVnodeGid *pVgid = &pVgroup->vnodeGid[i]; SMonVnodeDesc *pVnDesc = &desc.vnodes[i]; pVnDesc->dnode_id = pVgid->dnodeId; - tstrncpy(pVnDesc->vnode_role, syncStr(pVgid->role), sizeof(pVnDesc->vnode_role)); - if (pVgid->role == TAOS_SYNC_STATE_LEADER) { + tstrncpy(pVnDesc->vnode_role, syncStr(pVgid->syncState), sizeof(pVnDesc->vnode_role)); + if (pVgid->syncState == TAOS_SYNC_STATE_LEADER) { tstrncpy(desc.status, "ready", sizeof(desc.status)); pClusterInfo->vgroups_alive++; } - if (pVgid->role != TAOS_SYNC_STATE_ERROR) { + if (pVgid->syncState != TAOS_SYNC_STATE_ERROR) { pClusterInfo->vnodes_alive++; } pClusterInfo->vnodes_total++; @@ -845,7 +853,8 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) { pLoad->syncState = syncGetMyRole(pMnode->syncMgmt.sync); - mTrace("mnode current syncstate is %s", syncStr(pLoad->syncState)); + pLoad->syncRestore = pMnode->restored; + mTrace("mnode current syncState is %s, syncRestore:%d", syncStr(pLoad->syncState), pLoad->syncRestore); return 0; } diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index f6ea81c5654a0b51a9edb51044e5893785444743..5889a162f83659cb1e94cb0a9cbcbec1ab077ede 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -56,8 +56,6 @@ int32_t mndInitMnode(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_ALTER_MNODE_RSP, mndTransProcessRsp); mndSetMsgHandle(pMnode, TDMT_MND_DROP_MNODE, mndProcessDropMnodeReq); mndSetMsgHandle(pMnode, TDMT_DND_DROP_MNODE_RSP, mndTransProcessRsp); - mndSetMsgHandle(pMnode, TDMT_SYNC_SET_MNODE_STANDBY_RSP, mndTransProcessRsp); - mndSetMsgHandle(pMnode, TDMT_SYNC_SET_VNODE_STANDBY_RSP, mndTransProcessRsp); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_MNODE, mndRetrieveMnodes); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_MNODE, mndCancelGetNextMnode); @@ -187,7 +185,7 @@ static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) { return -1; } - pObj->state = TAOS_SYNC_STATE_ERROR; + pObj->syncState = TAOS_SYNC_STATE_ERROR; mndReloadSyncConfig(pSdb->pMnode); return 0; } @@ -604,19 +602,19 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, b1, false); - const char *roles = "offline"; + char role[20] = "offline"; if (pObj->id == pMnode->selfDnodeId) { - roles = syncStr(TAOS_SYNC_STATE_LEADER); + snprintf(role, sizeof(role), "%s%s", syncStr(TAOS_SYNC_STATE_LEADER), pMnode->restored ? "" : "*"); } if (mndIsDnodeOnline(pObj->pDnode, curMs)) { - roles = syncStr(pObj->state); - if (pObj->state == TAOS_SYNC_STATE_LEADER && pObj->id != pMnode->selfDnodeId) { - roles = syncStr(TAOS_SYNC_STATE_ERROR); + tstrncpy(role, syncStr(pObj->syncState), sizeof(role)); + if (pObj->syncState == TAOS_SYNC_STATE_LEADER && pObj->id != pMnode->selfDnodeId) { + tstrncpy(role, syncStr(TAOS_SYNC_STATE_ERROR), sizeof(role)); mError("mnode:%d, is leader too", pObj->id); } } char b2[12 + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(b2, roles, pShow->pMeta->pSchemas[cols].bytes); + STR_WITH_MAXSIZE_TO_VARSTR(b2, role, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)b2, false); diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 1c8ec0a302a03bd133531bccd86ee107c593ff07..6c54d41818255269e9523463b60e612e49fb894c 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -239,6 +239,7 @@ int32_t mndAddShuffleSinkTasksToStream(SMnode* pMnode, SStreamObj* pStream) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } + pTask->fillHistory = pStream->fillHistory; mndAddTaskToTaskSet(tasks, pTask); pTask->nodeId = pVgroup->vgId; @@ -270,6 +271,7 @@ int32_t mndAddFixedSinkTaskToStream(SMnode* pMnode, SStreamObj* pStream) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } + pTask->fillHistory = pStream->fillHistory; mndAddTaskToTaskSet(tasks, pTask); ASSERT(pStream->fixedSinkVg.vgId == pStream->fixedSinkVgId); @@ -356,6 +358,7 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) { qDestroyQueryPlan(pPlan); return -1; } + pInnerTask->fillHistory = pStream->fillHistory; mndAddTaskToTaskSet(taskInnerLevel, pInnerTask); pInnerTask->childEpInfo = taosArrayInit(0, sizeof(void*)); @@ -422,6 +425,7 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) { qDestroyQueryPlan(pPlan); return -1; } + pTask->fillHistory = pStream->fillHistory; mndAddTaskToTaskSet(taskSourceLevel, pTask); pTask->triggerParam = 0; diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index da548cd3ebfee591132ed1235d4b158c3ea54565..56e725fac75a1e59a1de3d5135c0abd975d6abcd 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -454,7 +454,7 @@ static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans, pVgroup->pTsma = pSmaReq; int32_t contLen = 0; - void *pReq = mndBuildCreateVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen, false); + void *pReq = mndBuildCreateVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen); taosMemoryFreeClear(pSmaReq); if (pReq == NULL) return -1; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 8a3179b2a9bc0700c8180666b6eb4c8c58f83017..4b1906ba7039213f3507488c91dafff8c1795497 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -2555,7 +2555,7 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc int32_t rollupNum = (int32_t)taosArrayGetSize(pStb->pFuncs); char *sep = ", "; int32_t sepLen = strlen(sep); - int32_t rollupLen = sizeof(rollup) - 2; + int32_t rollupLen = sizeof(rollup) - VARSTR_HEADER_SIZE - 2; for (int32_t i = 0; i < rollupNum; ++i) { char *funcName = taosArrayGet(pStb->pFuncs, i); if (i) { diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index ce6b3b065641aea8f85715427e788e62ea4391aa..3ff989e6707e840c7bea8a21471111b381df3831 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -143,8 +143,10 @@ SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw) { SDecoder decoder; tDecoderInit(&decoder, buf, tlen + 1); if (tDecodeSStreamObj(&decoder, pStream) < 0) { + tDecoderClear(&decoder); goto STREAM_DECODE_OVER; } + tDecoderClear(&decoder); terrno = TSDB_CODE_SUCCESS; @@ -280,6 +282,7 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, pObj->trigger = pCreate->triggerType; pObj->triggerParam = pCreate->maxDelay; pObj->watermark = pCreate->watermark; + pObj->fillHistory = pCreate->fillHistory; memcpy(pObj->sourceDb, pCreate->sourceDB, TSDB_DB_FNAME_LEN); SDbObj *pSourceDb = mndAcquireDb(pMnode, pCreate->sourceDB); @@ -686,7 +689,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) { mError("stream:%s, failed to create since %s", createStreamReq.name, terrstr()); goto _OVER; } - mndTransSetDbName(pTrans, createStreamReq.sourceDB, streamObj.targetDb); // hack way + mndTransSetDbName(pTrans, createStreamReq.sourceDB, streamObj.targetDb); mInfo("trans:%d, used to create stream:%s", pTrans->id, createStreamReq.name); // create stb for stream diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index b797bfb4b2e6006ae608e6b15a47efd4e5f62aa7..eea79c533584d7aede84b834ce568500a22afe12 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -426,10 +426,10 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR if (pIter == NULL) break; SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter; int32_t sz = taosArrayGetSize(pConsumerEp->vgs); - mInfo("mq rebalance: final cfg: consumer %ld has %d vg", pConsumerEp->consumerId, sz); + mInfo("mq rebalance: final cfg: consumer %" PRId64 " has %d vg", pConsumerEp->consumerId, sz); for (int32_t i = 0; i < sz; i++) { SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, i); - mInfo("mq rebalance: final cfg: vg %d to consumer %ld", pVgEp->vgId, pConsumerEp->consumerId); + mInfo("mq rebalance: final cfg: vg %d to consumer %" PRId64 "", pVgEp->vgId, pConsumerEp->consumerId); } } } @@ -550,7 +550,7 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu // 6. execution if (mndTransPrepare(pMnode, pTrans) != 0) { - ASSERT(0); + mError("failed to prepare trans rebalance since %s", terrstr()); goto REB_FAIL; } diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index ac95dd2795b5fb90b4cd1cf657aa151850035af8..df4b526775539996f1895cf34f334367a01e9f9e 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -71,8 +71,8 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM mInfo("trans:%d, is proposed and post sem", transId); } pMgmt->transId = 0; - taosWUnLockLatch(&pMgmt->lock); tsem_post(&pMgmt->syncSem); + taosWUnLockLatch(&pMgmt->lock); } else { taosWUnLockLatch(&pMgmt->lock); STrans *pTrans = mndAcquireTrans(pMnode, transId); @@ -113,27 +113,7 @@ void mndRestoreFinish(struct SSyncFSM *pFsm) { } } -void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta *cbMeta) { - SMnode *pMnode = pFsm->data; - SSyncMgmt *pMgmt = &pMnode->syncMgmt; - - pMgmt->errCode = cbMeta->code; - mInfo("trans:-1, sync reconfig is proposed, saved:%d code:0x%x, index:%" PRId64 " term:%" PRId64, pMgmt->transId, - cbMeta->code, cbMeta->index, cbMeta->term); - - taosWLockLatch(&pMgmt->lock); - if (pMgmt->transId == -1) { - if (pMgmt->errCode != 0) { - mError("trans:-1, failed to propose sync reconfig since %s, post sem", tstrerror(pMgmt->errCode)); - } else { - mInfo("trans:-1, sync reconfig is proposed, saved:%d code:0x%x, index:%" PRId64 " term:%" PRId64 " post sem", - pMgmt->transId, cbMeta->code, cbMeta->index, cbMeta->term); - } - pMgmt->transId = 0; - tsem_post(&pMgmt->syncSem); - } - taosWUnLockLatch(&pMgmt->lock); -} +void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta *cbMeta) {} int32_t mndSnapshotStartRead(struct SSyncFSM *pFsm, void *pParam, void **ppReader) { mInfo("start to read snapshot from sdb"); @@ -179,11 +159,14 @@ void mndLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cb static void mndBecomeFollower(struct SSyncFSM *pFsm) { SMnode *pMnode = pFsm->data; - mInfo("vgId:1, become follower and post sem"); + mInfo("vgId:1, become follower"); taosWLockLatch(&pMnode->syncMgmt.lock); if (pMnode->syncMgmt.transId != 0) { + mInfo("vgId:1, become follower and post sem, trans:%d, failed to propose since not leader", + pMnode->syncMgmt.transId); pMnode->syncMgmt.transId = 0; + pMnode->syncMgmt.errCode = TSDB_CODE_SYN_NOT_LEADER; tsem_post(&pMnode->syncMgmt.syncSem); } taosWUnLockLatch(&pMnode->syncMgmt.lock); @@ -221,13 +204,21 @@ int32_t mndInitSync(SMnode *pMnode) { taosInitRWLatch(&pMgmt->lock); pMgmt->transId = 0; - SSyncInfo syncInfo = {.vgId = 1, .FpSendMsg = mndSyncSendMsg, .FpEqMsg = mndSyncEqMsg}; + SSyncInfo syncInfo = { + .snapshotStrategy = SYNC_STRATEGY_STANDARD_SNAPSHOT, + .batchSize = 1, + .vgId = 1, + .pWal = pMnode->pWal, + .msgcb = NULL, + .FpSendMsg = mndSyncSendMsg, + .FpEqMsg = mndSyncEqMsg, + .FpEqCtrlMsg = NULL, + }; + snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", pMnode->path, TD_DIRSEP); - syncInfo.pWal = pMnode->pWal; syncInfo.pFsm = mndSyncMakeFsm(pMnode); - syncInfo.snapshotStrategy = SYNC_STRATEGY_STANDARD_SNAPSHOT; - mInfo("vgId:1, start to open sync, selfIndex:%d replica:%d", pMgmt->selfIndex, pMgmt->numOfReplicas); + mInfo("vgId:1, start to open sync, replica:%d selfIndex:%d", pMgmt->numOfReplicas, pMgmt->selfIndex); SSyncCfg *pCfg = &syncInfo.syncCfg; pCfg->replicaNum = pMgmt->numOfReplicas; pCfg->myIndex = pMgmt->selfIndex; @@ -292,6 +283,7 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) { int32_t code = syncPropose(pMgmt->sync, &req, isWeak); if (code == 0) { + mInfo("trans:%d, is proposing and wait sem", pMgmt->transId); tsem_wait(&pMgmt->syncSem); } else if (code > 0) { mInfo("trans:%d, confirm at once since replica is 1, continue execute", transId); @@ -301,12 +293,16 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) { sdbWriteWithoutFree(pMnode->pSdb, pRaw); sdbSetApplyInfo(pMnode->pSdb, req.info.conn.applyIndex, req.info.conn.applyTerm, SYNC_INDEX_INVALID); code = 0; - } else if (code == -1 && terrno == TSDB_CODE_SYN_NOT_LEADER) { - terrno = TSDB_CODE_APP_NOT_READY; - } else if (code == -1 && terrno == TSDB_CODE_SYN_INTERNAL_ERROR) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; } else { - terrno = TSDB_CODE_APP_ERROR; + taosWLockLatch(&pMgmt->lock); + mInfo("trans:%d, failed to proposed since %s", transId, terrstr()); + pMgmt->transId = 0; + taosWUnLockLatch(&pMgmt->lock); + if (terrno == TSDB_CODE_SYN_NOT_LEADER) { + terrno = TSDB_CODE_APP_NOT_READY; + } else { + terrno = TSDB_CODE_APP_ERROR; + } } rpcFreeCont(req.pCont); @@ -315,6 +311,7 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) { return code; } + if (pMgmt->errCode != 0) terrno = pMgmt->errCode; return pMgmt->errCode; } @@ -328,6 +325,7 @@ void mndSyncStart(SMnode *pMnode) { void mndSyncStop(SMnode *pMnode) { taosWLockLatch(&pMnode->syncMgmt.lock); if (pMnode->syncMgmt.transId != 0) { + mInfo("vgId:1, is stopped and post sem, trans:%d", pMnode->syncMgmt.transId); pMnode->syncMgmt.transId = 0; tsem_post(&pMnode->syncMgmt.syncSem); } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index a64b07fdbd6491bb16b7854758029bde06b14808..6f430ad3e426dbb23cb204603f2d4100f6d70cc3 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -323,7 +323,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER) action.pRaw = taosMemoryMalloc(dataLen); if (action.pRaw == NULL) goto _OVER; - mTrace("raw:%p, is created", pData); + mTrace("raw:%p, is created", action.pRaw); SDB_GET_BINARY(pRaw, dataPos, (void *)action.pRaw, dataLen, _OVER); if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto _OVER; action.pRaw = NULL; @@ -778,7 +778,7 @@ static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) { mInfo("trans:%d, sync to other mnodes, stage:%s", pTrans->id, mndTransStr(pTrans->stage)); int32_t code = mndSyncPropose(pMnode, pRaw, pTrans->id); if (code != 0) { - mError("trans:%d, failed to sync since %s", pTrans->id, terrstr()); + mError("trans:%d, failed to sync, errno:%s code:%s", pTrans->id, terrstr(), tstrerror(code)); sdbFreeRaw(pRaw); return -1; } diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 4ab80b0a40e73584696d6678f2b6eeefdc261f15..3f2c6ac2a86ccc7362d988132f8cf80890538628 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -142,7 +142,7 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) { SVnodeGid *pVgid = &pVgroup->vnodeGid[i]; SDB_GET_INT32(pRaw, dataPos, &pVgid->dnodeId, _OVER) if (pVgroup->replica == 1) { - pVgid->role = TAOS_SYNC_STATE_LEADER; + pVgid->syncState = TAOS_SYNC_STATE_LEADER; } } SDB_GET_RESERVE(pRaw, dataPos, VGROUP_RESERVE_SIZE, _OVER) @@ -196,8 +196,7 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) { sdbRelease(pSdb, pVgroup); } -void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen, - bool standby) { +void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen) { SCreateVnodeReq createReq = {0}; createReq.vgId = pVgroup->vgId; memcpy(createReq.db, pDb->name, TSDB_DB_FNAME_LEN); @@ -227,7 +226,6 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg createReq.hashMethod = pDb->cfg.hashMethod; createReq.numOfRetensions = pDb->cfg.numOfRetensions; createReq.pRetensions = pDb->cfg.pRetensions; - createReq.standby = standby; createReq.isTsma = pVgroup->isTsma; createReq.pTsma = pVgroup->pTsma; createReq.walRetentionPeriod = pDb->cfg.walRetentionPeriod; @@ -279,8 +277,8 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg return pReq; } -void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen) { - SAlterVnodeReq alterReq = {0}; +static void *mndBuildAlterVnodeConfigReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen) { + SAlterVnodeConfigReq alterReq = {0}; alterReq.vgVersion = pVgroup->version; alterReq.buffer = pDb->cfg.buffer; alterReq.pageSize = pDb->cfg.pageSize; @@ -294,23 +292,8 @@ void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_ alterReq.walLevel = pDb->cfg.walLevel; alterReq.strict = pDb->cfg.strict; alterReq.cacheLast = pDb->cfg.cacheLast; - alterReq.replica = pVgroup->replica; - - for (int32_t v = 0; v < pVgroup->replica; ++v) { - SReplica *pReplica = &alterReq.replicas[v]; - SVnodeGid *pVgid = &pVgroup->vnodeGid[v]; - SDnodeObj *pVgidDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); - if (pVgidDnode == NULL) { - return NULL; - } - pReplica->id = pVgidDnode->id; - pReplica->port = pVgidDnode->port; - memcpy(pReplica->fqdn, pVgidDnode->fqdn, TSDB_FQDN_LEN); - mndReleaseDnode(pMnode, pVgidDnode); - } - - int32_t contLen = tSerializeSAlterVnodeReq(NULL, 0, &alterReq); + int32_t contLen = tSerializeSAlterVnodeConfigReq(NULL, 0, &alterReq); if (contLen < 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -327,34 +310,62 @@ void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_ pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - tSerializeSAlterVnodeReq((char *)pReq + sizeof(SMsgHead), contLen, &alterReq); + tSerializeSAlterVnodeConfigReq((char *)pReq + sizeof(SMsgHead), contLen, &alterReq); *pContLen = contLen; return pReq; } -void *mndBuildSetVnodeStandbyReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen) { - SSetStandbyReq standbyReq = {0}; - standbyReq.dnodeId = pDnode->id; - standbyReq.standby = 1; +static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_t dnodeId, + int32_t *pContLen) { + SAlterVnodeReplicaReq alterReq = { + alterReq.vgId = pVgroup->vgId, + alterReq.strict = pDb->cfg.strict, + alterReq.replica = pVgroup->replica, + alterReq.selfIndex = -1, + }; + + for (int32_t v = 0; v < pVgroup->replica; ++v) { + SReplica *pReplica = &alterReq.replicas[v]; + SVnodeGid *pVgid = &pVgroup->vnodeGid[v]; + SDnodeObj *pVgidDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); + if (pVgidDnode == NULL) { + return NULL; + } + + pReplica->id = pVgidDnode->id; + pReplica->port = pVgidDnode->port; + memcpy(pReplica->fqdn, pVgidDnode->fqdn, TSDB_FQDN_LEN); + mndReleaseDnode(pMnode, pVgidDnode); + + if (dnodeId == pVgid->dnodeId) { + alterReq.selfIndex = v; + } + } + alterReq.replica = pVgroup->replica; + mInfo("vgId:%d, start to alter vnode, replica:%d selfIndex:%d strict:%d", alterReq.vgId, alterReq.replica, + alterReq.selfIndex, alterReq.strict); + for (int32_t i = 0; i < alterReq.replica; ++i) { + mInfo("vgId:%d, replica:%d ep:%s:%u", alterReq.vgId, i, alterReq.replicas[i].fqdn, alterReq.replicas[i].port); + } + + if (alterReq.selfIndex == -1) { + terrno = TSDB_CODE_MND_APP_ERROR; + return NULL; + } - int32_t contLen = tSerializeSSetStandbyReq(NULL, 0, &standbyReq); + int32_t contLen = tSerializeSAlterVnodeReplicaReq(NULL, 0, &alterReq); if (contLen < 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - contLen += sizeof(SMsgHead); void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - tSerializeSSetStandbyReq((char *)pReq + sizeof(SMsgHead), contLen, &standbyReq); - SMsgHead *pHead = pReq; - pHead->contLen = htonl(contLen); - pHead->vgId = htonl(pVgroup->vgId); - + tSerializeSAlterVnodeReplicaReq(pReq, contLen, &alterReq); *pContLen = contLen; return pReq; } @@ -485,9 +496,9 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup pVgid->dnodeId = pDnode->id; if (pVgroup->replica == 1) { - pVgid->role = TAOS_SYNC_STATE_LEADER; + pVgid->syncState = TAOS_SYNC_STATE_LEADER; } else { - pVgid->role = TAOS_SYNC_STATE_FOLLOWER; + pVgid->syncState = TAOS_SYNC_STATE_FOLLOWER; } mInfo("db:%s, vgId:%d, vn:%d is alloced, memory:%" PRId64 ", dnode:%d avail:%" PRId64 " used:%" PRId64, @@ -587,7 +598,7 @@ SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup) { SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); if (pDnode == NULL) continue; - if (pVgid->role == TAOS_SYNC_STATE_LEADER) { + if (pVgid->syncState == TAOS_SYNC_STATE_LEADER) { epset.inUse = epset.numOfEps; } @@ -681,8 +692,12 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p mndReleaseDnode(pMnode, pDnode); } - char buf1[20] = {0}; - const char *role = online ? syncStr(pVgroup->vnodeGid[i].role) : "offline"; + char buf1[20] = {0}; + char role[20] = "offline"; + if (online) { + bool show = (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_LEADER && !pVgroup->vnodeGid[i].syncRestore); + snprintf(role, sizeof(role), "%s%s", syncStr(pVgroup->vnodeGid[i].syncState), show ? "*" : ""); + } STR_WITH_MAXSIZE_TO_VARSTR(buf1, role, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -809,7 +824,7 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB colDataAppend(pColInfo, numOfRows, (const char *)&pVgroup->replica, false); char buf[20] = {0}; - STR_TO_VARSTR(buf, syncStr(pVgid->role)); + STR_TO_VARSTR(buf, syncStr(pVgid->syncState)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)buf, false); @@ -887,7 +902,7 @@ int32_t mndAddVnodeToVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray) { } pVgid->dnodeId = pDnode->id; - pVgid->role = TAOS_SYNC_STATE_ERROR; + pVgid->syncState = TAOS_SYNC_STATE_ERROR; mInfo("db:%s, vgId:%d, vn:%d is added, memory:%" PRId64 ", dnode:%d avail:%" PRId64 " used:%" PRId64, pVgroup->dbName, pVgroup->vgId, pVgroup->replica, vgMem, pVgid->dnodeId, pDnode->memAvail, pDnode->memUsed); @@ -944,8 +959,7 @@ _OVER: return 0; } -int32_t mndAddCreateVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, - bool standby) { +int32_t mndAddCreateVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid) { STransAction action = {0}; SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); @@ -954,7 +968,7 @@ int32_t mndAddCreateVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVg mndReleaseDnode(pMnode, pDnode); int32_t contLen = 0; - void *pReq = mndBuildCreateVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen, standby); + void *pReq = mndBuildCreateVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen); if (pReq == NULL) return -1; action.pCont = pReq; @@ -998,17 +1012,19 @@ int32_t mndAddAlterVnodeConfirmAction(SMnode *pMnode, STrans *pTrans, SDbObj *pD return 0; } -int32_t mndAddAlterVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, tmsg_t msgType) { +int32_t mndAddAlterVnodeHashRangeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) { return 0; } + +int32_t mndAddAlterVnodeConfigAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) { STransAction action = {0}; action.epSet = mndGetVgroupEpset(pMnode, pVgroup); int32_t contLen = 0; - void *pReq = mndBuildAlterVnodeReq(pMnode, pDb, pVgroup, &contLen); + void *pReq = mndBuildAlterVnodeConfigReq(pMnode, pDb, pVgroup, &contLen); if (pReq == NULL) return -1; action.pCont = pReq; action.contLen = contLen; - action.msgType = msgType; + action.msgType = TDMT_VND_ALTER_CONFIG; if (mndTransAppendRedoAction(pTrans, &action) != 0) { taosMemoryFree(pReq); @@ -1018,36 +1034,25 @@ int32_t mndAddAlterVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgO return 0; } -static int32_t mndAddSetVnodeStandByAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, - SVnodeGid *pVgid, bool isRedo) { - STransAction action = {0}; - - SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); +int32_t mndAddAlterVnodeReplicaAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t dnodeId) { + SDnodeObj *pDnode = mndAcquireDnode(pMnode, dnodeId); if (pDnode == NULL) return -1; + + STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); mndReleaseDnode(pMnode, pDnode); int32_t contLen = 0; - void *pReq = mndBuildSetVnodeStandbyReq(pMnode, pDnode, pDb, pVgroup, &contLen); + void *pReq = mndBuildAlterVnodeReplicaReq(pMnode, pDb, pVgroup, dnodeId, &contLen); if (pReq == NULL) return -1; action.pCont = pReq; action.contLen = contLen; - action.msgType = TDMT_SYNC_SET_VNODE_STANDBY; - action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED; - // Keep retrying until the target vnode is not the leader - action.retryCode = TSDB_CODE_SYN_IS_LEADER; + action.msgType = TDMT_VND_ALTER_REPLICA; - if (isRedo) { - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(pReq); - return -1; - } - } else { - if (mndTransAppendUndoAction(pTrans, &action) != 0) { - taosMemoryFree(pReq); - return -1; - } + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + taosMemoryFree(pReq); + return -1; } return 0; @@ -1098,8 +1103,8 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, mInfo("vgId:%d, will add 1 vnodes", pVgroup->vgId); if (mndAddVnodeToVgroup(pMnode, &newVg, pArray) != 0) return -1; - if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[newVg.replica - 1], true) != 0) return -1; - if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg, TDMT_VND_ALTER_REPLICA) != 0) return -1; + if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[newVg.replica - 1]) != 0) return -1; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, -1) != 0) return -1; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; mInfo("vgId:%d, will remove 1 vnodes", pVgroup->vgId); @@ -1107,8 +1112,7 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVnodeGid del = newVg.vnodeGid[vnIndex]; newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica]; memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid)); - if (mndAddSetVnodeStandByAction(pMnode, pTrans, pDb, pVgroup, &del, true) != 0) return -1; - if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg, TDMT_VND_ALTER_REPLICA) != 0) return -1; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, -1) != 0) return -1; if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; @@ -1179,10 +1183,10 @@ static int32_t mndAddIncVgroupReplicaToTrans(SMnode *pMnode, STrans *pTrans, SDb SVnodeGid *pGid = &pVgroup->vnodeGid[pVgroup->replica]; pVgroup->replica++; pGid->dnodeId = newDnodeId; - pGid->role = TAOS_SYNC_STATE_ERROR; + pGid->syncState = TAOS_SYNC_STATE_ERROR; - if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pGid, true) != 0) return -1; - if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, pVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1; + if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pGid) != 0) return -1; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, -1) != 0) return -1; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1; return 0; @@ -1208,8 +1212,7 @@ static int32_t mndAddDecVgroupReplicaFromTrans(SMnode *pMnode, STrans *pTrans, S memcpy(pGid, &pVgroup->vnodeGid[pVgroup->replica], sizeof(SVnodeGid)); memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid)); - if (mndAddSetVnodeStandByAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1; - if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, pVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, -1) != 0) return -1; if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1; @@ -1233,7 +1236,7 @@ static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, mInfo("vgId:%d, vgroup info before redistribute, replica:%d", newVg.vgId, newVg.replica); for (int32_t i = 0; i < newVg.replica; ++i) { mInfo("vgId:%d, vnode:%d dnode:%d role:%s", newVg.vgId, i, newVg.vnodeGid[i].dnodeId, - syncStr(newVg.vnodeGid[i].role)); + syncStr(newVg.vnodeGid[i].syncState)); } if (pNew1 != NULL && pOld1 != NULL) { @@ -1569,43 +1572,41 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb memcpy(&newVgroup, pVgroup, sizeof(SVgObj)); if (pVgroup->replica <= 0 || pVgroup->replica == pNewDb->cfg.replications) { - if (mndAddAlterVnodeAction(pMnode, pTrans, pNewDb, pVgroup, TDMT_VND_ALTER_CONFIG) != 0) return -1; + if (mndAddAlterVnodeConfigAction(pMnode, pTrans, pNewDb, pVgroup) != 0) return -1; if (mndCheckDnodeMemory(pMnode, pOldDb, pNewDb, &newVgroup, pVgroup, pArray) != 0) return -1; return 0; } mndTransSetSerial(pTrans); - if (newVgroup.replica < pNewDb->cfg.replications) { - mInfo("db:%s, vgId:%d, vn:0 dnode:%d, will add 2 vnodes", pVgroup->dbName, pVgroup->vgId, + if (newVgroup.replica == 1 && pNewDb->cfg.replications == 3) { + mInfo("db:%s, vgId:%d, will add 2 vnodes, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId); if (mndAddVnodeToVgroup(pMnode, &newVgroup, pArray) != 0) return -1; - if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[1], true) != 0) return -1; - if (mndAddAlterVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1; - if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1; - if (mndAddVnodeToVgroup(pMnode, &newVgroup, pArray) != 0) return -1; - if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[2], true) != 0) return -1; - if (mndAddAlterVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1; + if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[1]) != 0) return -1; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0) + return -1; + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1; + if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[2]) != 0) return -1; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1; - } else if (newVgroup.replica > pNewDb->cfg.replications) { - mInfo("db:%s, vgId:%d, will remove 2 vnodes", pVgroup->dbName, pVgroup->vgId); + } else if (newVgroup.replica == 3 && pNewDb->cfg.replications == 1) { + mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName, + pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId); SVnodeGid del1 = {0}; + SVnodeGid del2 = {0}; if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del1) != 0) return -1; - if (mndAddSetVnodeStandByAction(pMnode, pTrans, pNewDb, pVgroup, &del1, true) != 0) return -1; - if (mndAddAlterVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1; + if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del2) != 0) return -1; if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del1, true) != 0) return -1; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1; - - SVnodeGid del2 = {0}; - if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del2) != 0) return -1; - if (mndAddSetVnodeStandByAction(pMnode, pTrans, pNewDb, pVgroup, &del2, true) != 0) return -1; - if (mndAddAlterVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1; if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del2, true) != 0) return -1; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0) + return -1; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1; } else { + return -1; } { @@ -1656,14 +1657,13 @@ static int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj if (newVg1.replica == 1) { if (mndAddVnodeToVgroup(pMnode, &newVg1, pArray) != 0) goto _OVER; - if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg1, &newVg1.vnodeGid[1], true) != 0) goto _OVER; - if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg1, TDMT_VND_ALTER_REPLICA) != 0) goto _OVER; + if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg1, &newVg1.vnodeGid[1]) != 0) goto _OVER; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg1, -1) != 0) goto _OVER; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg1) != 0) goto _OVER; } else if (newVg1.replica == 3) { SVnodeGid del1 = {0}; if (mndRemoveVnodeFromVgroup(pMnode, &newVg1, pArray, &del1) != 0) goto _OVER; - if (mndAddSetVnodeStandByAction(pMnode, pTrans, pDb, pVgroup, &del1, true) != 0) goto _OVER; - if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg1, TDMT_VND_ALTER_REPLICA) != 0) goto _OVER; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg1, -1) != 0) goto _OVER; if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg1, &del1, true) != 0) goto _OVER; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg1) != 0) goto _OVER; } else { @@ -1681,8 +1681,8 @@ static int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj memcpy(&newVg2.vnodeGid[0], &newVg2.vnodeGid[1], sizeof(SVnodeGid)); memset(&newVg1.vnodeGid[1], 0, sizeof(SVnodeGid)); - if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg1, TDMT_VND_ALTER_HASHRANGE) != 0) goto _OVER; - if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg2, TDMT_VND_ALTER_HASHRANGE) != 0) goto _OVER; + if (mndAddAlterVnodeHashRangeAction(pMnode, pTrans, pDb, &newVg1) != 0) goto _OVER; + if (mndAddAlterVnodeHashRangeAction(pMnode, pTrans, pDb, &newVg2) != 0) goto _OVER; // adjust vgroup if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg1, pArray) != 0) goto _OVER; diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt index 7db84855618270985335418cb6470f870e93446f..a002b20bde44248dd0b5da962676863d99865043 100644 --- a/source/dnode/mnode/impl/test/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -1,7 +1,7 @@ enable_testing() add_subdirectory(acct) -add_subdirectory(db) +#add_subdirectory(db) #add_subdirectory(dnode) add_subdirectory(func) #add_subdirectory(mnode) @@ -14,4 +14,4 @@ add_subdirectory(snode) add_subdirectory(stb) add_subdirectory(topic) add_subdirectory(trans) -add_subdirectory(user) +#add_subdirectory(user) diff --git a/source/dnode/mnode/impl/test/user/CMakeLists.txt b/source/dnode/mnode/impl/test/user/CMakeLists.txt index b39ea0e73f728cacc648f6eb0723328e028c05f4..6e2301fca0027c2552943cca7eb0f652c513dbfc 100644 --- a/source/dnode/mnode/impl/test/user/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/user/CMakeLists.txt @@ -5,7 +5,8 @@ target_link_libraries( PUBLIC sut ) -add_test( - NAME userTest - COMMAND userTest -) + +#add_test( +# NAME userTest +# COMMAND userTest +#) diff --git a/source/dnode/mnode/sdb/CMakeLists.txt b/source/dnode/mnode/sdb/CMakeLists.txt index 2001a70da217d67e8a3b63137f40fbce9eaf6192..186c85004ab2e2acc4471fd268f3979894c32b58 100644 --- a/source/dnode/mnode/sdb/CMakeLists.txt +++ b/source/dnode/mnode/sdb/CMakeLists.txt @@ -5,5 +5,5 @@ target_include_directories( PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( - sdb os common util wal -) \ No newline at end of file + sdb os common util wal sync +) diff --git a/source/dnode/mnode/sdb/inc/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h index d4db4709caa2f7a7a3d7c31e1aaf475acc067897..a6d81ecc0d85d468cbf880cb1904918ee8ddc024 100644 --- a/source/dnode/mnode/sdb/inc/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -169,6 +169,7 @@ typedef struct SSdbRow { typedef struct SSdb { SMnode *pMnode; SWal *pWal; + int64_t sync; char *currDir; char *tmpDir; int64_t commitIndex; @@ -212,6 +213,7 @@ typedef struct SSdbOpt { const char *path; SMnode *pMnode; SWal *pWal; + int64_t sync; } SSdbOpt; /** diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index e73fd28e71258adc85c9a2822b8a6b810bafbcdc..648ccff432dffe3b460a488940de3dcd953a8db8 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -53,6 +53,7 @@ SSdb *sdbInit(SSdbOpt *pOption) { } pSdb->pWal = pOption->pWal; + pSdb->sync = pOption->sync; pSdb->applyIndex = -1; pSdb->applyTerm = -1; pSdb->applyConfig = -1; diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 5eedcc545a526dc1bb657f0173c54a1f03440de2..f2a18b7212c0c89bebc2fa48ec79f70a02af0771 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "sdb.h" +#include "sync.h" #include "tchecksum.h" #include "wal.h" @@ -456,14 +457,25 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) { taosThreadMutexLock(&pSdb->filelock); if (pSdb->pWal != NULL) { - code = walBeginSnapshot(pSdb->pWal, pSdb->applyIndex); + // code = walBeginSnapshot(pSdb->pWal, pSdb->applyIndex); + if (pSdb->sync == 0) { + code = 0; + } else { + code = syncBeginSnapshot(pSdb->sync, pSdb->applyIndex); + } } if (code == 0) { code = sdbWriteFileImp(pSdb); } if (code == 0) { if (pSdb->pWal != NULL) { - code = walEndSnapshot(pSdb->pWal); + // code = walEndSnapshot(pSdb->pWal); + + if (pSdb->sync == 0) { + code = 0; + } else { + code = syncEndSnapshot(pSdb->sync); + } } } if (code != 0) { diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 54d5d9eec25e0a6fa8c6a80961c9a1ea6b5ee4e1..099a039b15dc13ede2ea9bfda7e8020ad2892aaa 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -50,6 +50,7 @@ extern const SVnodeCfg vnodeCfgDefault; int32_t vnodeInit(int32_t nthreads); void vnodeCleanup(); int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs); +int32_t vnodeAlter(const char *path, SAlterVnodeReplicaReq *pReq, STfs *pTfs); void vnodeDestroy(const char *path, STfs *pTfs); SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb); void vnodePreClose(SVnode *pVnode); @@ -82,6 +83,7 @@ int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp); int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); +int32_t vnodeProcessSyncCtrlMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo); void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs); @@ -118,7 +120,11 @@ typedef struct SMetaFltParam { } SMetaFltParam; +// TODO, refactor later int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *results); +int32_t metaFilterCreateTime(SMeta *pMeta, SMetaFltParam *parm, SArray *pUids); +int32_t metaFilterTableName(SMeta *pMeta, SMetaFltParam *param, SArray *pUids); +int32_t metaFilterTtl(SMeta *pMeta, SMetaFltParam *param, SArray *pUids); #if 1 // refact APIs below (TODO) typedef SVCreateTbReq STbCfg; diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index dbe2f80150a021c29e2b7c02153675ec63d332e6..9e2fe4aaf004d8bc730242f34228c5903f7bc817 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -86,8 +86,12 @@ struct SMeta { TTB* pSuidIdx; // ivt idx and idx void* pTagIvtIdx; - TTB* pTagIdx; - TTB* pTtlIdx; + + TTB* pTagIdx; + TTB* pTtlIdx; + + TTB* pCtimeIdx; // table created time idx + TTB* pNcolIdx; // ncol of table idx, normal table only TTB* pSmaIdx; @@ -142,6 +146,16 @@ typedef struct { int64_t smaUid; } SSmaIdxKey; +typedef struct { + int64_t ctime; + tb_uid_t uid; +} SCtimeIdxKey; + +typedef struct { + int64_t ncol; + tb_uid_t uid; +} SNcolIdxKey; + // metaTable ================== int metaCreateTagIdxKey(tb_uid_t suid, int32_t cid, const void* pTagData, int32_t nTagData, int8_t type, tb_uid_t uid, STagIdxKey** ppTagIdxKey, int32_t* nTagIdxKey); diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index bf110f1ae33eafeadc343fecb2a50cd073ed1b49..dfbbd8fbd0e094e1cfe89edf4df1cc856afcf4ea 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -32,12 +32,6 @@ extern "C" { #define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSD ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) // clang-format on -#define TSDB_CHECK_CODE(CODE, LINO, LABEL) \ - if (CODE) { \ - LINO = __LINE__; \ - goto LABEL; \ - } - typedef struct TSDBROW TSDBROW; typedef struct TABLEID TABLEID; typedef struct TSDBKEY TSDBKEY; @@ -247,18 +241,17 @@ void tsdbSmaFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SSmaFile *pSmaF, ch // SDelFile void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]); // tsdbFS.c ============================================================================================== -int32_t tsdbFSOpen(STsdb *pTsdb); +int32_t tsdbFSOpen(STsdb *pTsdb, int8_t rollback); int32_t tsdbFSClose(STsdb *pTsdb); int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS); void tsdbFSDestroy(STsdbFS *pFS); int32_t tDFileSetCmprFn(const void *p1, const void *p2); -int32_t tsdbFSCommit1(STsdb *pTsdb, STsdbFS *pFS); -int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFS); +int32_t tsdbFSCommit(STsdb *pTsdb); +int32_t tsdbFSRollback(STsdb *pTsdb); +int32_t tsdbFSPrepareCommit(STsdb *pTsdb, STsdbFS *pFS); int32_t tsdbFSRef(STsdb *pTsdb, STsdbFS *pFS); void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS); -int32_t tsdbFSRollback(STsdbFS *pFS); - int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet); int32_t tsdbFSUpsertDelFile(STsdbFS *pFS, SDelFile *pDelFile); // tsdbReaderWriter.c ============================================================================================== @@ -306,6 +299,11 @@ int32_t tsdbMerge(STsdb *pTsdb); #define TSDB_CACHE_LAST(c) (((c).cacheLast & 2) > 0) // tsdbCache ============================================================================================== +typedef struct { + TSKEY ts; + SColVal colVal; +} SLastCol; + int32_t tsdbOpenCache(STsdb *pTsdb); void tsdbCloseCache(STsdb *pTsdb); int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb *pTsdb); diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index aca99ecd2f31d43b98ed38ddfc2940e3079225ba..988ecc5dd3c0046c142ffde9a3d902f2b9904cd3 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -87,11 +87,13 @@ int32_t vnodeGetBatchMeta(SVnode* pVnode, SRpcMsg* pMsg); int32_t vnodeBegin(SVnode* pVnode); int32_t vnodeShouldCommit(SVnode* pVnode); int32_t vnodeCommit(SVnode* pVnode); +void vnodeRollback(SVnode* pVnode); int32_t vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg); int32_t vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo); int32_t vnodeLoadInfo(const char* dir, SVnodeInfo* pInfo); int32_t vnodeSyncCommit(SVnode* pVnode); int32_t vnodeAsyncCommit(SVnode* pVnode); +bool vnodeShouldRollback(SVnode* pVnode); // vnodeSync.c int32_t vnodeSyncOpen(SVnode* pVnode, char* path); diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 712f8bd15b9b3e189ba7649a486743d284c9fd15..a5dc4431ab711307834dc73affbe81718b6b641c 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -97,10 +97,11 @@ typedef struct SMCtbCursor SMCtbCursor; typedef struct SMStbCursor SMStbCursor; typedef struct STbUidStore STbUidStore; -int metaOpen(SVnode* pVnode, SMeta** ppMeta); +int metaOpen(SVnode* pVnode, SMeta** ppMeta, int8_t rollback); int metaClose(SMeta* pMeta); int metaBegin(SMeta* pMeta, int8_t fromSys); int metaCommit(SMeta* pMeta); +int metaFinishCommit(SMeta* pMeta); int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq); int metaAlterSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq); int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq, SArray* tbUidList); @@ -149,10 +150,12 @@ typedef struct { int32_t metaGetStbStats(SMeta* pMeta, int64_t uid, SMetaStbStats* pInfo); // tsdb -int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg); +int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg, int8_t rollback); int tsdbClose(STsdb** pTsdb); int32_t tsdbBegin(STsdb* pTsdb); int32_t tsdbCommit(STsdb* pTsdb); +int32_t tsdbFinishCommit(STsdb* pTsdb); +int32_t tsdbRollbackCommit(STsdb* pTsdb); int32_t tsdbDoRetention(STsdb* pTsdb, int64_t now); int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq* pMsg); int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp); @@ -200,15 +203,16 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem // sma int32_t smaInit(); void smaCleanUp(); -int32_t smaOpen(SVnode* pVnode); +int32_t smaOpen(SVnode* pVnode, int8_t rollback); int32_t smaClose(SSma* pSma); int32_t smaBegin(SSma* pSma); int32_t smaSyncPreCommit(SSma* pSma); int32_t smaSyncCommit(SSma* pSma); int32_t smaSyncPostCommit(SSma* pSma); -int32_t smaAsyncPreCommit(SSma* pSma); -int32_t smaAsyncCommit(SSma* pSma); -int32_t smaAsyncPostCommit(SSma* pSma); +int32_t smaPreCommit(SSma* pSma); +int32_t smaCommit(SSma* pSma); +int32_t smaFinishCommit(SSma* pSma); +int32_t smaPostCommit(SSma* pSma); int32_t smaDoRetention(SSma* pSma, int64_t now); int32_t tdProcessTSmaCreate(SSma* pSma, int64_t version, const char* msg); diff --git a/source/dnode/vnode/src/meta/metaCache.c b/source/dnode/vnode/src/meta/metaCache.c index 6f19d43e6943996c52a24a4b1b9e90b2ceeb7a52..356aa78c220eb0c3d7c755c1913131a26990e2f5 100644 --- a/source/dnode/vnode/src/meta/metaCache.c +++ b/source/dnode/vnode/src/meta/metaCache.c @@ -120,7 +120,7 @@ _err2: _err: taosMemoryFree(pCache); - metaError("vgId:%d meta open cache failed since %s", TD_VID(pMeta->pVnode), tstrerror(code)); + metaError("vgId:%d, meta open cache failed since %s", TD_VID(pMeta->pVnode), tstrerror(code)); return code; } diff --git a/source/dnode/vnode/src/meta/metaCommit.c b/source/dnode/vnode/src/meta/metaCommit.c index 85ed40970c796ddeaa5332f95f691e4892c6f14b..01ad833d203023b59f69e2f985d964d21a213972 100644 --- a/source/dnode/vnode/src/meta/metaCommit.c +++ b/source/dnode/vnode/src/meta/metaCommit.c @@ -34,6 +34,7 @@ int metaBegin(SMeta *pMeta, int8_t fromSys) { // commit the meta txn int metaCommit(SMeta *pMeta) { return tdbCommit(pMeta->pEnv, &pMeta->txn); } +int metaFinishCommit(SMeta *pMeta) { return tdbPostCommit(pMeta->pEnv, &pMeta->txn); } // abort the meta txn int metaAbort(SMeta *pMeta) { return tdbAbort(pMeta->pEnv, &pMeta->txn); } diff --git a/source/dnode/vnode/src/meta/metaEntry.c b/source/dnode/vnode/src/meta/metaEntry.c index b7bdadec03a184a8debc7c2f9a0366fa1ec80734..72f7365a1e3304c8fa5c387eea24a968ebb87c14 100644 --- a/source/dnode/vnode/src/meta/metaEntry.c +++ b/source/dnode/vnode/src/meta/metaEntry.c @@ -21,7 +21,7 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) { if (tEncodeI64(pCoder, pME->version) < 0) return -1; if (tEncodeI8(pCoder, pME->type) < 0) return -1; if (tEncodeI64(pCoder, pME->uid) < 0) return -1; - if (tEncodeCStr(pCoder, pME->name) < 0) return -1; + if (pME->name == NULL || tEncodeCStr(pCoder, pME->name) < 0) return -1; if (pME->type == TSDB_SUPER_TABLE) { if (tEncodeI8(pCoder, pME->flags) < 0) return -1; // TODO: need refactor? diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c index 515fd31e9d0930296c04a29f2945d7923ea542e2..1b5f74255948da71938eb274fe3cfd05700d8aa9 100644 --- a/source/dnode/vnode/src/meta/metaOpen.c +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -24,10 +24,13 @@ static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); +static int ctimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); +static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); + static int32_t metaInitLock(SMeta *pMeta) { return taosThreadRwlockInit(&pMeta->lock, NULL); } static int32_t metaDestroyLock(SMeta *pMeta) { return taosThreadRwlockDestroy(&pMeta->lock); } -int metaOpen(SVnode *pVnode, SMeta **ppMeta) { +int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) { SMeta *pMeta = NULL; int ret; int slen; @@ -60,49 +63,49 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) { taosMkDir(pMeta->path); // open env - ret = tdbOpen(pMeta->path, pVnode->config.szPage, pVnode->config.szCache, &pMeta->pEnv); + ret = tdbOpen(pMeta->path, pVnode->config.szPage, pVnode->config.szCache, &pMeta->pEnv, rollback); if (ret < 0) { metaError("vgId:%d, failed to open meta env since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pTbDb - ret = tdbTbOpen("table.db", sizeof(STbDbKey), -1, tbDbKeyCmpr, pMeta->pEnv, &pMeta->pTbDb); + ret = tdbTbOpen("table.db", sizeof(STbDbKey), -1, tbDbKeyCmpr, pMeta->pEnv, &pMeta->pTbDb, 0); if (ret < 0) { metaError("vgId:%d, failed to open meta table db since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pSkmDb - ret = tdbTbOpen("schema.db", sizeof(SSkmDbKey), -1, skmDbKeyCmpr, pMeta->pEnv, &pMeta->pSkmDb); + ret = tdbTbOpen("schema.db", sizeof(SSkmDbKey), -1, skmDbKeyCmpr, pMeta->pEnv, &pMeta->pSkmDb, 0); if (ret < 0) { metaError("vgId:%d, failed to open meta schema db since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pUidIdx - ret = tdbTbOpen("uid.idx", sizeof(tb_uid_t), sizeof(SUidIdxVal), uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pUidIdx); + ret = tdbTbOpen("uid.idx", sizeof(tb_uid_t), sizeof(SUidIdxVal), uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pUidIdx, 0); if (ret < 0) { metaError("vgId:%d, failed to open meta uid idx since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pNameIdx - ret = tdbTbOpen("name.idx", -1, sizeof(tb_uid_t), NULL, pMeta->pEnv, &pMeta->pNameIdx); + ret = tdbTbOpen("name.idx", -1, sizeof(tb_uid_t), NULL, pMeta->pEnv, &pMeta->pNameIdx, 0); if (ret < 0) { metaError("vgId:%d, failed to open meta name index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pCtbIdx - ret = tdbTbOpen("ctb.idx", sizeof(SCtbIdxKey), -1, ctbIdxKeyCmpr, pMeta->pEnv, &pMeta->pCtbIdx); + ret = tdbTbOpen("ctb.idx", sizeof(SCtbIdxKey), -1, ctbIdxKeyCmpr, pMeta->pEnv, &pMeta->pCtbIdx, 0); if (ret < 0) { metaError("vgId:%d, failed to open meta child table index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pSuidIdx - ret = tdbTbOpen("suid.idx", sizeof(tb_uid_t), 0, uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pSuidIdx); + ret = tdbTbOpen("suid.idx", sizeof(tb_uid_t), 0, uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pSuidIdx, 0); if (ret < 0) { metaError("vgId:%d, failed to open meta super table index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; @@ -119,27 +122,41 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) { goto _err; } - ret = tdbTbOpen("tag.idx", -1, 0, tagIdxKeyCmpr, pMeta->pEnv, &pMeta->pTagIdx); + ret = tdbTbOpen("tag.idx", -1, 0, tagIdxKeyCmpr, pMeta->pEnv, &pMeta->pTagIdx, 0); if (ret < 0) { metaError("vgId:%d, failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pTtlIdx - ret = tdbTbOpen("ttl.idx", sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, pMeta->pEnv, &pMeta->pTtlIdx); + ret = tdbTbOpen("ttl.idx", sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, pMeta->pEnv, &pMeta->pTtlIdx, 0); if (ret < 0) { metaError("vgId:%d, failed to open meta ttl index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pSmaIdx - ret = tdbTbOpen("sma.idx", sizeof(SSmaIdxKey), 0, smaIdxKeyCmpr, pMeta->pEnv, &pMeta->pSmaIdx); + ret = tdbTbOpen("sma.idx", sizeof(SSmaIdxKey), 0, smaIdxKeyCmpr, pMeta->pEnv, &pMeta->pSmaIdx, 0); if (ret < 0) { metaError("vgId:%d, failed to open meta sma index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } - ret = tdbTbOpen("stream.task.db", sizeof(int64_t), -1, taskIdxKeyCmpr, pMeta->pEnv, &pMeta->pStreamDb); + // idx table create time + ret = tdbTbOpen("ctime.idx", sizeof(SCtimeIdxKey), 0, ctimeIdxCmpr, pMeta->pEnv, &pMeta->pCtimeIdx, 0); + if (ret < 0) { + metaError("vgId:%d, failed to open meta ctime index since %s", TD_VID(pVnode), tstrerror(terrno)); + goto _err; + } + + // idx num of col, normal table only + ret = tdbTbOpen("ncol.idx", sizeof(SNcolIdxKey), 0, ncolIdxCmpr, pMeta->pEnv, &pMeta->pNcolIdx, 0); + if (ret < 0) { + metaError("vgId:%d, failed to open meta ncol index since %s", TD_VID(pVnode), tstrerror(terrno)); + goto _err; + } + + ret = tdbTbOpen("stream.task.db", sizeof(int64_t), -1, taskIdxKeyCmpr, pMeta->pEnv, &pMeta->pStreamDb, 0); if (ret < 0) { metaError("vgId:%d, failed to open meta stream task index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; @@ -166,6 +183,8 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) { _err: if (pMeta->pIdx) metaCloseIdx(pMeta); if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb); + if (pMeta->pNcolIdx) tdbTbClose(pMeta->pNcolIdx); + if (pMeta->pCtimeIdx) tdbTbClose(pMeta->pCtimeIdx); if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx); if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx); if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx); @@ -187,6 +206,8 @@ int metaClose(SMeta *pMeta) { if (pMeta->pCache) metaCacheClose(pMeta); if (pMeta->pIdx) metaCloseIdx(pMeta); if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb); + if (pMeta->pNcolIdx) tdbTbClose(pMeta->pNcolIdx); + if (pMeta->pCtimeIdx) tdbTbClose(pMeta->pCtimeIdx); if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx); if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx); if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx); @@ -391,6 +412,43 @@ static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL return 0; } +static int ctimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { + SCtimeIdxKey *pCtimeIdxKey1 = (SCtimeIdxKey *)pKey1; + SCtimeIdxKey *pCtimeIdxKey2 = (SCtimeIdxKey *)pKey2; + if (pCtimeIdxKey1->ctime > pCtimeIdxKey2->ctime) { + return 1; + } else if (pCtimeIdxKey1->ctime < pCtimeIdxKey2->ctime) { + return -1; + } + + if (pCtimeIdxKey1->uid > pCtimeIdxKey2->uid) { + return 1; + } else if (pCtimeIdxKey1->uid < pCtimeIdxKey2->uid) { + return -1; + } + + return 0; +} + +static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { + SNcolIdxKey *pNcolIdxKey1 = (SNcolIdxKey *)pKey1; + SNcolIdxKey *pNcolIdxKey2 = (SNcolIdxKey *)pKey2; + + if (pNcolIdxKey1->ncol > pNcolIdxKey2->ncol) { + return 1; + } else if (pNcolIdxKey1->ncol < pNcolIdxKey2->ncol) { + return -1; + } + + if (pNcolIdxKey1->uid > pNcolIdxKey2->uid) { + return 1; + } else if (pNcolIdxKey1->uid < pNcolIdxKey2->uid) { + return -1; + } + + return 0; +} + static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { SSmaIdxKey *pSmaIdxKey1 = (SSmaIdxKey *)pKey1; SSmaIdxKey *pSmaIdxKey2 = (SSmaIdxKey *)pKey2; diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index efd0220a7ec30a4e8615ebecd6f3847ab858332d..0727d3267442270e01b839d135260ae82e3eb65f 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -687,7 +687,12 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv SSchema *pSchema = pSchemaWrapper->pSchema + i; tdAddColToSchema(&sb, pSchema->type, pSchema->flags, pSchema->colId, pSchema->bytes); } + STSchema *pTSchema = tdGetSchemaFromBuilder(&sb); + if (pTSchema == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + tdDestroyTSchemaBuilder(&sb); *ppTSchema = pTSchema; @@ -1033,6 +1038,143 @@ typedef struct { int32_t vLen; } SIdxCursor; +int32_t metaFilterCreateTime(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { + int32_t ret = 0; + + SIdxCursor *pCursor = NULL; + pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor)); + pCursor->pMeta = pMeta; + pCursor->suid = param->suid; + pCursor->cid = param->cid; + pCursor->type = param->type; + + metaRLock(pMeta); + ret = tdbTbcOpen(pMeta->pCtimeIdx, &pCursor->pCur, NULL); + if (ret != 0) { + goto END; + } + int64_t uidLimit = param->reverse ? INT64_MAX : 0; + + SCtimeIdxKey ctimeKey = {.ctime = *(int64_t *)(param->val), .uid = uidLimit}; + SCtimeIdxKey *pCtimeKey = &ctimeKey; + + int cmp = 0; + if (tdbTbcMoveTo(pCursor->pCur, &ctimeKey, sizeof(ctimeKey), &cmp) < 0) { + goto END; + } + bool first = true; + int32_t valid = 0; + while (1) { + void *entryKey = NULL; + int32_t nEntryKey = -1; + valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, NULL, NULL); + if (valid < 0) break; + + SCtimeIdxKey *p = entryKey; + + int32_t cmp = (*param->filterFunc)((void *)&p->ctime, (void *)&pCtimeKey->ctime, param->type); + if (cmp == 0) taosArrayPush(pUids, &p->uid); + if (cmp == -1) break; + valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur); + if (valid < 0) break; + } + +END: + if (pCursor->pMeta) metaULock(pCursor->pMeta); + if (pCursor->pCur) tdbTbcClose(pCursor->pCur); + taosMemoryFree(pCursor); + return ret; +} + +int32_t metaFilterTableName(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { + int32_t ret = 0; + char *buf = NULL; + + STagIdxKey *pKey = NULL; + int32_t nKey = 0; + + SIdxCursor *pCursor = NULL; + pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor)); + pCursor->pMeta = pMeta; + pCursor->suid = param->suid; + pCursor->cid = param->cid; + pCursor->type = param->type; + + char *pName = param->val; + + metaRLock(pMeta); + ret = tdbTbcOpen(pMeta->pNameIdx, &pCursor->pCur, NULL); + if (ret != 0) { + goto END; + } + + int cmp = 0; + if (tdbTbcMoveTo(pCursor->pCur, pName, strlen(pName) + 1, &cmp) < 0) { + goto END; + } + bool first = true; + int32_t valid = 0; + while (1) { + void *pEntryKey = NULL, *pEntryVal = NULL; + int32_t nEntryKey = -1, nEntryVal = 0; + valid = tdbTbcGet(pCursor->pCur, (const void **)pEntryKey, &nEntryKey, (const void **)&pEntryVal, &nEntryVal); + if (valid < 0) break; + + char *pTableKey = (char *)pEntryKey; + int32_t cmp = (*param->filterFunc)(pTableKey, pName, pCursor->type); + if (cmp == 0) { + tb_uid_t tuid = *(tb_uid_t *)pEntryVal; + taosArrayPush(pUids, &tuid); + } else if (cmp == 1) { + // next + } else { + break; + } + valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur); + if (valid < 0) { + break; + } + } + +END: + if (pCursor->pMeta) metaULock(pCursor->pMeta); + if (pCursor->pCur) tdbTbcClose(pCursor->pCur); + taosMemoryFree(buf); + taosMemoryFree(pKey); + + taosMemoryFree(pCursor); + + return ret; +} +int32_t metaFilterTtl(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { + int32_t ret = 0; + char *buf = NULL; + + STtlIdxKey *pKey = NULL; + int32_t nKey = 0; + + SIdxCursor *pCursor = NULL; + pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor)); + pCursor->pMeta = pMeta; + pCursor->suid = param->suid; + pCursor->cid = param->cid; + pCursor->type = param->type; + + metaRLock(pMeta); + ret = tdbTbcOpen(pMeta->pTtlIdx, &pCursor->pCur, NULL); + +END: + if (pCursor->pMeta) metaULock(pCursor->pMeta); + if (pCursor->pCur) tdbTbcClose(pCursor->pCur); + taosMemoryFree(buf); + taosMemoryFree(pKey); + + taosMemoryFree(pCursor); + + return ret; + // impl later + return 0; +} int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { int32_t ret = 0; char *buf = NULL; @@ -1048,7 +1190,7 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { pCursor->type = param->type; metaRLock(pMeta); - ret = tdbTbcOpen(pMeta->pTagIdx, &pCursor->pCur, NULL); + ret = tdbTbcOpen(pMeta->pCtimeIdx, &pCursor->pCur, NULL); if (ret < 0) { goto END; } @@ -1059,6 +1201,7 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { if (param->val == NULL) { metaError("vgId:%d, failed to filter NULL data", TD_VID(pMeta->pVnode)); + ret = -1; goto END; } else { if (IS_VAR_DATA_TYPE(param->type)) { @@ -1099,9 +1242,11 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, (const void **)&entryVal, &nEntryVal); if (valid < 0) { + tdbFree(entryVal); break; } STagIdxKey *p = entryKey; + if (p == NULL) break; if (p->type != pCursor->type) { if (first) { valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur); @@ -1111,7 +1256,7 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { break; } } - if (p == NULL || p->suid != pKey->suid) { + if (p->suid != pKey->suid) { break; } first = false; diff --git a/source/dnode/vnode/src/meta/metaSnapshot.c b/source/dnode/vnode/src/meta/metaSnapshot.c index a40bbd7d87c8255358e2f6b9c112239faabd42a2..5c5b49ece57bd2a2a9b787c356108fc108cee4a4 100644 --- a/source/dnode/vnode/src/meta/metaSnapshot.c +++ b/source/dnode/vnode/src/meta/metaSnapshot.c @@ -165,6 +165,8 @@ int32_t metaSnapWriterClose(SMetaSnapWriter** ppWriter, int8_t rollback) { } else { code = metaCommit(pWriter->pMeta); if (code) goto _err; + code = metaFinishCommit(pWriter->pMeta); + if (code) goto _err; } taosMemoryFree(pWriter); *ppWriter = NULL; diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 2d055acd2fbcb137cc7cc6ca5361cb2ea96e90c1..9974e2257293013c99d45c17bbbffd28d6e4dcb1 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -15,17 +15,23 @@ #include "meta.h" -static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema); -static int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema); -static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME); -static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry); -static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type); +static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema); +static int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema); +static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry); +static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type); +static void metaDestroyTagIdxKey(STagIdxKey *pTagIdxKey); +// opt ins_tables query +static int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaDeleteCtimeIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME); static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) { pInfo->uid = pEntry->uid; @@ -550,6 +556,26 @@ static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME) { ttlKey->dtime = ctime / 1000 + ttlDays * tsTtlUnit; ttlKey->uid = pME->uid; } +static int metaBuildCtimeIdxKey(SCtimeIdxKey *ctimeKey, const SMetaEntry *pME) { + int64_t ctime; + if (pME->type == TSDB_CHILD_TABLE) { + ctime = pME->ctbEntry.ctime; + } else if (pME->type == TSDB_NORMAL_TABLE) { + ctime = pME->ntbEntry.ctime; + } else { + return -1; + } + + ctimeKey->ctime = ctime; + ctimeKey->uid = pME->uid; + return 0; +} + +static int metaBuildNColIdxKey(SNcolIdxKey *ncolKey, const SMetaEntry *pME) { + ncolKey->ncol = pME->ntbEntry.schemaRow.nCols; + ncolKey->uid = pME->uid; + return 0; +} static int metaDeleteTtlIdx(SMeta *pMeta, const SMetaEntry *pME) { STtlIdxKey ttlKey = {0}; @@ -574,7 +600,11 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData); tDecoderInit(&dc, pData, nData); - metaDecodeEntry(&dc, &e); + rc = metaDecodeEntry(&dc, &e); + if (rc < 0) { + tDecoderClear(&dc); + return -1; + } if (type) *type = e.type; @@ -594,6 +624,28 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { const SSchema *pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[0]; if (pTagColumn->type == TSDB_DATA_TYPE_JSON) { metaDelJsonVarFromIdx(pMeta, &e, pTagColumn); + } else { + STagIdxKey *pTagIdxKey = NULL; + int32_t nTagIdxKey; + + const void *pTagData = NULL; + int32_t nTagData = 0; + + STagVal tagVal = {.cid = pTagColumn->colId}; + tTagGet((const STag *)e.ctbEntry.pTags, &tagVal); + if (IS_VAR_DATA_TYPE(pTagColumn->type)) { + pTagData = tagVal.pData; + nTagData = (int32_t)tagVal.nData; + } else { + pTagData = &(tagVal.i64); + nTagData = tDataTypes[pTagColumn->type].bytes; + } + + if (metaCreateTagIdxKey(e.ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type, uid, + &pTagIdxKey, &nTagIdxKey) == 0) { + tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, &pMeta->txn); + } + metaDestroyTagIdxKey(pTagIdxKey); } tDecoderClear(&tdc); } @@ -605,6 +657,9 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn); tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn); + if (e.type == TSDB_CHILD_TABLE || e.type == TSDB_NORMAL_TABLE) metaDeleteCtimeIdx(pMeta, &e); + if (e.type == TSDB_NORMAL_TABLE) metaDeleteNcolIdx(pMeta, &e); + if (e.type != TSDB_SUPER_TABLE) metaDeleteTtlIdx(pMeta, &e); if (e.type == TSDB_CHILD_TABLE) { @@ -631,6 +686,37 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { return 0; } +// opt ins_tables +int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) { + SCtimeIdxKey ctimeKey = {0}; + if (metaBuildCtimeIdxKey(&ctimeKey, pME) < 0) { + return 0; + } + return tdbTbInsert(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), NULL, 0, &pMeta->txn); +} + +int metaDeleteCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) { + SCtimeIdxKey ctimeKey = {0}; + if (metaBuildCtimeIdxKey(&ctimeKey, pME) < 0) { + return 0; + } + return tdbTbDelete(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), &pMeta->txn); +} +int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME) { + SNcolIdxKey ncolKey = {0}; + if (metaBuildNColIdxKey(&ncolKey, pME) < 0) { + return 0; + } + return tdbTbInsert(pMeta->pNcolIdx, &ncolKey, sizeof(ncolKey), NULL, 0, &pMeta->txn); +} + +int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME) { + SNcolIdxKey ncolKey = {0}; + if (metaBuildNColIdxKey(&ncolKey, pME) < 0) { + return 0; + } + return tdbTbDelete(pMeta->pNcolIdx, &ncolKey, sizeof(ncolKey), &pMeta->txn); +} static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq, STableMetaRsp *pMetaRsp) { void *pVal = NULL; @@ -645,6 +731,11 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl SSchemaWrapper *pSchema; int c; + if (pAlterTbReq->colName == NULL) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + // search name index ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal); if (ret < 0) { @@ -762,6 +853,10 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl pColumn->bytes = pAlterTbReq->colModBytes; break; case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME: + if (pAlterTbReq->colNewName == NULL) { + terrno = TSDB_CODE_INVALID_MSG; + goto _err; + } if (pColumn == NULL) { terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS; goto _err; @@ -1221,7 +1316,10 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData); tDecoderInit(&dc, pData, nData); - metaDecodeEntry(&dc, &stbEntry); + ret = metaDecodeEntry(&dc, &stbEntry); + if (ret < 0) { + goto end; + } pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[0]; @@ -1243,12 +1341,14 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { ret = metaSaveJsonVarToIdx(pMeta, pCtbEntry, pTagColumn); goto end; } - if (metaCreateTagIdxKey(pCtbEntry->ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type, - pCtbEntry->uid, &pTagIdxKey, &nTagIdxKey) < 0) { - ret = -1; - goto end; + if (pTagData != NULL) { + if (metaCreateTagIdxKey(pCtbEntry->ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type, + pCtbEntry->uid, &pTagIdxKey, &nTagIdxKey) < 0) { + ret = -1; + goto end; + } + tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, &pMeta->txn); } - tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, &pMeta->txn); end: metaDestroyTagIdxKey(pTagIdxKey); tDecoderClear(&dc); @@ -1335,6 +1435,12 @@ int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) { } } + if (metaUpdateCtimeIdx(pMeta, pME) < 0) goto _err; + + if (pME->type == TSDB_NORMAL_TABLE) { + if (metaUpdateNcolIdx(pMeta, pME) < 0) goto _err; + } + if (pME->type != TSDB_SUPER_TABLE) { if (metaUpdateTtlIdx(pMeta, pME) < 0) goto _err; } diff --git a/source/dnode/vnode/src/sma/smaCommit.c b/source/dnode/vnode/src/sma/smaCommit.c index 6168a00815a5e44387cb11f767579bc8aa56a6ac..a79ae35d79f2725d0765cd5bcee9108b178c57f0 100644 --- a/source/dnode/vnode/src/sma/smaCommit.c +++ b/source/dnode/vnode/src/sma/smaCommit.c @@ -54,62 +54,93 @@ int32_t smaSyncPostCommit(SSma *pSma) { return tdProcessRSmaSyncPostCommitImpl(p #endif /** - * @brief Only applicable to Rollup SMA + * @brief async commit, only applicable to Rollup SMA * * @param pSma * @return int32_t */ -int32_t smaAsyncPreCommit(SSma *pSma) { return tdProcessRSmaAsyncPreCommitImpl(pSma); } +int32_t smaPreCommit(SSma *pSma) { return tdProcessRSmaAsyncPreCommitImpl(pSma); } /** - * @brief Only applicable to Rollup SMA + * @brief async commit, only applicable to Rollup SMA * * @param pSma * @return int32_t */ -int32_t smaAsyncCommit(SSma *pSma) { return tdProcessRSmaAsyncCommitImpl(pSma); } +int32_t smaCommit(SSma *pSma) { return tdProcessRSmaAsyncCommitImpl(pSma); } /** - * @brief Only applicable to Rollup SMA + * @brief async commit, only applicable to Rollup SMA * * @param pSma * @return int32_t */ -int32_t smaAsyncPostCommit(SSma *pSma) { return tdProcessRSmaAsyncPostCommitImpl(pSma); } +int32_t smaPostCommit(SSma *pSma) { return tdProcessRSmaAsyncPostCommitImpl(pSma); } /** - * @brief set rsma trigger stat active + * @brief prepare rsma1/2, and set rsma trigger stat active * * @param pSma * @return int32_t */ int32_t smaBegin(SSma *pSma) { + int32_t code = 0; + SVnode *pVnode = pSma->pVnode; + + if ((code = tsdbBegin(VND_RSMA1(pVnode))) < 0) { + smaError("vgId:%d, failed to begin rsma1 since %s", TD_VID(pVnode), tstrerror(code)); + goto _exit; + } + + if ((code = tsdbBegin(VND_RSMA2(pVnode))) < 0) { + smaError("vgId:%d, failed to begin rsma2 since %s", TD_VID(pVnode), tstrerror(code)); + goto _exit; + } + + // set trigger stat SSmaEnv *pSmaEnv = SMA_RSMA_ENV(pSma); if (!pSmaEnv) { - return TSDB_CODE_SUCCESS; + goto _exit; } - SRSmaStat *pRSmaStat = (SRSmaStat *)SMA_ENV_STAT(pSmaEnv); - - int8_t rsmaTriggerStat = + int8_t rsmaTriggerStat = atomic_val_compare_exchange_8(RSMA_TRIGGER_STAT(pRSmaStat), TASK_TRIGGER_STAT_PAUSED, TASK_TRIGGER_STAT_ACTIVE); switch (rsmaTriggerStat) { case TASK_TRIGGER_STAT_PAUSED: { - smaDebug("vgId:%d, rsma trigger stat from paused to active", SMA_VID(pSma)); + smaDebug("vgId:%d, rsma trigger stat from paused to active", TD_VID(pVnode)); break; } case TASK_TRIGGER_STAT_INIT: { atomic_store_8(RSMA_TRIGGER_STAT(pRSmaStat), TASK_TRIGGER_STAT_ACTIVE); - smaDebug("vgId:%d, rsma trigger stat from init to active", SMA_VID(pSma)); + smaDebug("vgId:%d, rsma trigger stat from init to active", TD_VID(pVnode)); break; } default: { atomic_store_8(RSMA_TRIGGER_STAT(pRSmaStat), TASK_TRIGGER_STAT_ACTIVE); - smaError("vgId:%d, rsma trigger stat %" PRIi8 " is unexpected", SMA_VID(pSma), rsmaTriggerStat); + smaWarn("vgId:%d, rsma trigger stat %" PRIi8 " is unexpected", TD_VID(pVnode), rsmaTriggerStat); break; } } - return TSDB_CODE_SUCCESS; +_exit: + terrno = code; + return code; +} + +int32_t smaFinishCommit(SSma *pSma) { + int32_t code = 0; + SVnode *pVnode = pSma->pVnode; + + if (VND_RSMA1(pVnode) && (code = tsdbFinishCommit(VND_RSMA1(pVnode))) < 0) { + smaError("vgId:%d, failed to finish commit tsdb rsma1 since %s", TD_VID(pVnode), tstrerror(code)); + goto _exit; + } + if (VND_RSMA2(pVnode) && (code = tsdbFinishCommit(VND_RSMA2(pVnode))) < 0) { + smaError("vgId:%d, failed to finish commit tsdb rsma2 since %s", TD_VID(pVnode), tstrerror(code)); + goto _exit; + } +_exit: + terrno = code; + return code; } #if 0 @@ -309,15 +340,6 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) { * 1) This is high cost task and should not put in asyncPreCommit originally. * 2) But, if put in asyncCommit, would trigger taskInfo cloning frequently. */ - nLoops = 0; - while (atomic_load_64(&pRSmaStat->nBufItems) > 0) { - ++nLoops; - if (nLoops > 1000) { - sched_yield(); - nLoops = 0; - } - } - smaInfo("vgId:%d, rsma commit, wait for all items to be consumed, TID:%p", SMA_VID(pSma), (void *)taosGetSelfPthreadId()); nLoops = 0; @@ -366,10 +388,8 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) { * @return int32_t */ static int32_t tdProcessRSmaAsyncCommitImpl(SSma *pSma) { - SSmaEnv *pSmaEnv = SMA_RSMA_ENV(pSma); - if (!pSmaEnv) { - return TSDB_CODE_SUCCESS; - } + int32_t code = 0; + SVnode *pVnode = pSma->pVnode; #if 0 SRSmaStat *pRSmaStat = (SRSmaStat *)SMA_ENV_STAT(pSmaEnv); @@ -379,7 +399,17 @@ static int32_t tdProcessRSmaAsyncCommitImpl(SSma *pSma) { } #endif - return TSDB_CODE_SUCCESS; + if ((code = tsdbCommit(VND_RSMA1(pVnode))) < 0) { + smaError("vgId:%d, failed to commit tsdb rsma1 since %s", TD_VID(pVnode), tstrerror(code)); + goto _exit; + } + if ((code = tsdbCommit(VND_RSMA2(pVnode))) < 0) { + smaError("vgId:%d, failed to commit tsdb rsma2 since %s", TD_VID(pVnode), tstrerror(code)); + goto _exit; + } +_exit: + terrno = code; + return code; } /** diff --git a/source/dnode/vnode/src/sma/smaEnv.c b/source/dnode/vnode/src/sma/smaEnv.c index 64e5e49d0b116a7bed6d8ad5be49388db14bbd96..a272f5fc97883943e95d8ee7feb1c60ec90d49cb 100644 --- a/source/dnode/vnode/src/sma/smaEnv.c +++ b/source/dnode/vnode/src/sma/smaEnv.c @@ -455,7 +455,7 @@ static int32_t tdRsmaStopExecutor(const SSma *pSma) { for (int32_t i = 0; i < tsNumOfVnodeRsmaThreads; ++i) { if (taosCheckPthreadValid(pthread[i])) { - smaDebug("vgId:%d, start to join pthread for rsma:%" PRId64, SMA_VID(pSma), pthread[i]); + smaDebug("vgId:%d, start to join pthread for rsma:%" PRId64 "", SMA_VID(pSma), taosGetPthreadId(pthread[i])); taosThreadJoin(pthread[i], NULL); } } @@ -463,4 +463,4 @@ static int32_t tdRsmaStopExecutor(const SSma *pSma) { smaInfo("vgId:%d, rsma executor stopped, number:%d", SMA_VID(pSma), tsNumOfVnodeRsmaThreads); } return 0; -} \ No newline at end of file +} diff --git a/source/dnode/vnode/src/sma/smaOpen.c b/source/dnode/vnode/src/sma/smaOpen.c index ef0d51f0eb7382350da103129df2566f4bc18d15..2a769b68fe0ff93caa48a6a22030ca02b2af7023 100644 --- a/source/dnode/vnode/src/sma/smaOpen.c +++ b/source/dnode/vnode/src/sma/smaOpen.c @@ -29,19 +29,19 @@ static int32_t rsmaRestore(SSma *pSma); pKeepCfg->days = smaEvalDays(v, pCfg->retentions, l, pCfg->precision, pCfg->days); \ } while (0) -#define SMA_OPEN_RSMA_IMPL(v, l) \ - do { \ - SRetention *r = (SRetention *)VND_RETENTIONS(v) + l; \ - if (!RETENTION_VALID(r)) { \ - if (l == 0) { \ - goto _err; \ - } \ - break; \ - } \ - smaSetKeepCfg(v, &keepCfg, pCfg, TSDB_TYPE_RSMA_L##l); \ - if (tsdbOpen(v, &SMA_RSMA_TSDB##l(pSma), VNODE_RSMA##l##_DIR, &keepCfg) < 0) { \ - goto _err; \ - } \ +#define SMA_OPEN_RSMA_IMPL(v, l) \ + do { \ + SRetention *r = (SRetention *)VND_RETENTIONS(v) + l; \ + if (!RETENTION_VALID(r)) { \ + if (l == 0) { \ + goto _err; \ + } \ + break; \ + } \ + smaSetKeepCfg(v, &keepCfg, pCfg, TSDB_TYPE_RSMA_L##l); \ + if (tsdbOpen(v, &SMA_RSMA_TSDB##l(pSma), VNODE_RSMA##l##_DIR, &keepCfg, rollback) < 0) { \ + goto _err; \ + } \ } while (0) /** @@ -92,8 +92,7 @@ static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t p days = freqDuration; } end: - smaInfo("vgId:%d, evaluated duration for level %" PRIi8 " is %d, raw val:%d", TD_VID(pVnode), level + 1, days, - duration); + smaInfo("vgId:%d, evaluated duration for level %d is %d, raw val:%d", TD_VID(pVnode), level + 1, days, duration); return days; } @@ -119,7 +118,7 @@ int smaSetKeepCfg(SVnode *pVnode, STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg, int ty return 0; } -int32_t smaOpen(SVnode *pVnode) { +int32_t smaOpen(SVnode *pVnode, int8_t rollback) { STsdbCfg *pCfg = &pVnode->config.tsdbCfg; ASSERT(!pVnode->pSma); @@ -186,4 +185,4 @@ int32_t tdRSmaRestore(SSma *pSma, int8_t type, int64_t committedVer) { ASSERT(VND_IS_RSMA(pSma->pVnode)); return tdRSmaProcessRestoreImpl(pSma, type, committedVer); -} \ No newline at end of file +} diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index 77c595509867c00c94de0bfeea7c9f28161cacaa..c56b32514a3195f311d504c28d66609f937e8545 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -342,7 +342,7 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat smaInfo("vgId:%d, item:%p table:%" PRIi64 " level:%" PRIi8 " maxdelay:%" PRIi64 " watermark:%" PRIi64 ", finally maxdelay:%" PRIi32, - TD_VID(pVnode), pItem, pRSmaInfo->suid, idx + 1, param->maxdelay[idx], param->watermark[idx], + TD_VID(pVnode), pItem, pRSmaInfo->suid, (int8_t)(idx + 1), param->maxdelay[idx], param->watermark[idx], pItem->maxDelay); } return TSDB_CODE_SUCCESS; @@ -1387,7 +1387,7 @@ static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo) { } if ((++pItem->nScanned * pItem->maxDelay) > RSMA_FETCH_DELAY_MAX) { - smaDebug("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " nScanned:%" PRIi8 " maxDelay:%d, fetch executed", + smaDebug("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " nScanned:%" PRIi16 " maxDelay:%d, fetch executed", SMA_VID(pSma), pInfo->suid, i, pItem->nScanned, pItem->maxDelay); } else { int64_t curMs = taosGetTimestampMs(); @@ -1411,10 +1411,10 @@ static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo) { goto _err; } - smaDebug("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " nScanned:%" PRIi8 " maxDelay:%d, fetch finished", + smaDebug("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " nScanned:%" PRIi16 " maxDelay:%d, fetch finished", SMA_VID(pSma), pInfo->suid, i, pItem->nScanned, pItem->maxDelay); } else { - smaDebug("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " nScanned:%" PRIi8 + smaDebug("vgId:%d, suid:%" PRIi64 " level:%" PRIi8 " nScanned:%" PRIi16 " maxDelay:%d, fetch not executed as fetch level is %" PRIi8, SMA_VID(pSma), pInfo->suid, i, pItem->nScanned, pItem->maxDelay, pItem->fetchLevel); } @@ -1513,7 +1513,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) { int32_t qallItemSize = taosQallItemSize(pInfo->qall); if (qallItemSize > 0) { tdRSmaBatchExec(pSma, pInfo, pInfo->qall, pSubmitArr, type); - smaDebug("vgId:%d, batchSize:%d, execType:%" PRIi8, SMA_VID(pSma), qallItemSize, type); + smaDebug("vgId:%d, batchSize:%d, execType:%" PRIi32, SMA_VID(pSma), qallItemSize, type); } if (RSMA_INFO_ITEM(pInfo, 0)->fetchLevel || RSMA_INFO_ITEM(pInfo, 1)->fetchLevel) { diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 6d71496008c80f30bdc666d9b9911e36f1412772..da22d0d951c34fc704a33355c74a01c0d987239b 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -564,7 +564,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { pPushEntry->dataRsp.head.epoch = reqEpoch; pPushEntry->dataRsp.head.mqMsgType = TMQ_MSG_TYPE__POLL_RSP; taosHashPut(pTq->pPushMgr, pHandle->subKey, strlen(pHandle->subKey) + 1, &pPushEntry, sizeof(void*)); - tqDebug("tmq poll: consumer %ld, subkey %s, vg %d save handle to push mgr", consumerId, pHandle->subKey, + tqDebug("tmq poll: consumer %" PRId64 ", subkey %s, vg %d save handle to push mgr", consumerId, pHandle->subKey, TD_VID(pTq->pVnode)); // unlock taosWUnLockLatch(&pTq->pushLock); @@ -578,7 +578,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { code = -1; } - tqDebug("tmq poll: consumer %ld, subkey %s, vg %d, send data blockNum:%d, offset type:%d, uid:%ld, version:%ld", + tqDebug("tmq poll: consumer %" PRId64 ", subkey %s, vg %d, send data blockNum:%d, offset type:%d, uid:%" PRId64 + ", version:%" PRId64 "", consumerId, pHandle->subKey, TD_VID(pTq->pVnode), dataRsp.blockNum, dataRsp.rspOffset.type, dataRsp.rspOffset.uid, dataRsp.rspOffset.version); @@ -601,8 +602,9 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { if (tqSendMetaPollRsp(pTq, pMsg, pReq, &metaRsp) < 0) { code = -1; } - tqDebug("tmq poll: consumer %ld, subkey %s, vg %d, send meta offset type:%d,uid:%ld,version:%ld", consumerId, - pHandle->subKey, TD_VID(pTq->pVnode), metaRsp.rspOffset.type, metaRsp.rspOffset.uid, + tqDebug("tmq poll: consumer %" PRId64 ", subkey %s, vg %d, send meta offset type:%d,uid:%" PRId64 + ",version:%" PRId64 "", + consumerId, pHandle->subKey, TD_VID(pTq->pVnode), metaRsp.rspOffset.type, metaRsp.rspOffset.uid, metaRsp.rspOffset.version); taosMemoryFree(metaRsp.metaRsp); tDeleteSTaosxRsp(&taosxRsp); @@ -619,7 +621,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { fetchOffsetNew = taosxRsp.rspOffset; } - tqDebug("taosx poll: consumer %ld, subkey %s, vg %d, send data blockNum:%d, offset type:%d,uid:%ld,version:%ld", + tqDebug("taosx poll: consumer %" PRId64 ", subkey %s, vg %d, send data blockNum:%d, offset type:%d,uid:%" PRId64 + ",version:%" PRId64 "", consumerId, pHandle->subKey, TD_VID(pTq->pVnode), taosxRsp.blockNum, taosxRsp.rspOffset.type, taosxRsp.rspOffset.uid, taosxRsp.rspOffset.version); } @@ -769,11 +772,11 @@ int32_t tqProcessVgChangeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLe STqHandle* pHandle = taosHashGet(pTq->pHandle, req.subKey, strlen(req.subKey)); if (pHandle == NULL) { if (req.oldConsumerId != -1) { - tqError("vgId:%d, build new consumer handle %s for consumer %ld, but old consumerId is %ld", req.vgId, req.subKey, - req.newConsumerId, req.oldConsumerId); + tqError("vgId:%d, build new consumer handle %s for consumer %" PRId64 ", but old consumerId is %" PRId64 "", + req.vgId, req.subKey, req.newConsumerId, req.oldConsumerId); } if (req.newConsumerId == -1) { - tqError("vgId:%d, tq invalid rebalance request, new consumerId %ld", req.vgId, req.newConsumerId); + tqError("vgId:%d, tq invalid rebalance request, new consumerId %" PRId64 "", req.vgId, req.newConsumerId); return 0; } STqHandle tqHandle = {0}; diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c index 8e4bc34e0cf016878595117e65539ced34440c37..b852acb936450dcdeda2db1c22ea3a240b2f3105 100644 --- a/source/dnode/vnode/src/tq/tqMeta.c +++ b/source/dnode/vnode/src/tq/tqMeta.c @@ -70,17 +70,17 @@ int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle) { } int32_t tqMetaOpen(STQ* pTq) { - if (tdbOpen(pTq->path, 16 * 1024, 1, &pTq->pMetaDB) < 0) { + if (tdbOpen(pTq->path, 16 * 1024, 1, &pTq->pMetaDB, 0) < 0) { ASSERT(0); return -1; } - if (tdbTbOpen("tq.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pExecStore) < 0) { + if (tdbTbOpen("tq.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pExecStore, 0) < 0) { ASSERT(0); return -1; } - if (tdbTbOpen("tq.check.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pCheckStore) < 0) { + if (tdbTbOpen("tq.check.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pCheckStore, 0) < 0) { ASSERT(0); return -1; } @@ -193,8 +193,8 @@ int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle) { tEncodeSize(tEncodeSTqHandle, pHandle, vlen, code); ASSERT(code == 0); - tqDebug("tq save %s(%d) consumer %ld vgId:%d", pHandle->subKey, (int32_t)strlen(pHandle->subKey), pHandle->consumerId, - TD_VID(pTq->pVnode)); + tqDebug("tq save %s(%d) consumer %" PRId64 " vgId:%d", pHandle->subKey, (int32_t)strlen(pHandle->subKey), + pHandle->consumerId, TD_VID(pTq->pVnode)); void* buf = taosMemoryCalloc(1, vlen); if (buf == NULL) { diff --git a/source/dnode/vnode/src/tq/tqPush.c b/source/dnode/vnode/src/tq/tqPush.c index 4083a1a0aeef2f9a783bdace02fb89bdfeb1fe9c..35cb305042b73fa4cfaa49aa9d398473f2bed52c 100644 --- a/source/dnode/vnode/src/tq/tqPush.c +++ b/source/dnode/vnode/src/tq/tqPush.c @@ -213,12 +213,12 @@ int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_ #endif int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) { - tqDebug("vgId:%d tq push msg ver %ld, type: %s", pTq->pVnode->config.vgId, ver, TMSG_INFO(msgType)); + tqDebug("vgId:%d, tq push msg ver %" PRId64 ", type: %s", pTq->pVnode->config.vgId, ver, TMSG_INFO(msgType)); if (msgType == TDMT_VND_SUBMIT) { // lock push mgr to avoid potential msg lost taosWLockLatch(&pTq->pushLock); - tqDebug("vgId:%d push handle num %d", pTq->pVnode->config.vgId, taosHashGetSize(pTq->pPushMgr)); + tqDebug("vgId:%d, push handle num %d", pTq->pVnode->config.vgId, taosHashGetSize(pTq->pPushMgr)); if (taosHashGetSize(pTq->pPushMgr) != 0) { SArray* cachedKeys = taosArrayInit(0, sizeof(void*)); SArray* cachedKeyLens = taosArrayInit(0, sizeof(size_t)); @@ -242,12 +242,12 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) STqHandle* pHandle = taosHashGet(pTq->pHandle, pPushEntry->subKey, strlen(pPushEntry->subKey)); if (pHandle == NULL) { - tqDebug("vgId:%d cannot find handle %s", pTq->pVnode->config.vgId, pPushEntry->subKey); + tqDebug("vgId:%d, cannot find handle %s", pTq->pVnode->config.vgId, pPushEntry->subKey); continue; } if (pPushEntry->dataRsp.reqOffset.version >= ver) { - tqDebug("vgId:%d push entry req version %ld, while push version %ld, skip", pTq->pVnode->config.vgId, - pPushEntry->dataRsp.reqOffset.version, ver); + tqDebug("vgId:%d, push entry req version %" PRId64 ", while push version %" PRId64 ", skip", + pTq->pVnode->config.vgId, pPushEntry->dataRsp.reqOffset.version, ver); continue; } STqExecHandle* pExec = &pHandle->execHandle; @@ -274,7 +274,7 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) pRsp->blockNum++; } - tqDebug("vgId:%d tq handle push, subkey: %s, block num: %d", pTq->pVnode->config.vgId, pPushEntry->subKey, + tqDebug("vgId:%d, tq handle push, subkey: %s, block num: %d", pTq->pVnode->config.vgId, pPushEntry->subKey, pRsp->blockNum); if (pRsp->blockNum > 0) { // set offset diff --git a/source/dnode/vnode/src/tq/tqSink.c b/source/dnode/vnode/src/tq/tqSink.c index 79d7e27642bb8d56882f4525d614d244ba1df0d2..3e59e0fd45097ccebf67d2019e07cf5e6942d5d1 100644 --- a/source/dnode/vnode/src/tq/tqSink.c +++ b/source/dnode/vnode/src/tq/tqSink.c @@ -36,7 +36,7 @@ int32_t tqBuildDeleteReq(SVnode* pVnode, const char* stbFullName, const SSDataBl } else { name = buildCtbNameByGroupId(stbFullName, groupId); } - tqDebug("stream delete msg: groupId :%ld, name: %s", groupId, name); + tqDebug("stream delete msg: groupId :%" PRId64 ", name: %s", groupId, name); SMetaReader mr = {0}; metaReaderInit(&mr, pVnode->pMeta, 0); if (metaGetTableEntryByName(&mr, name) < 0) { @@ -435,7 +435,8 @@ void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* d continue; } if (mr.me.ctbEntry.suid != suid) { - tqError("vgId:%d, failed to write into %s, since suid mismatch, expect suid: %ld, actual suid %ld", + tqError("vgId:%d, failed to write into %s, since suid mismatch, expect suid: %" PRId64 + ", actual suid %" PRId64 "", TD_VID(pVnode), ctbName, suid, mr.me.ctbEntry.suid); metaReaderClear(&mr); taosMemoryFree(ctbName); @@ -446,7 +447,8 @@ void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* d uid = mr.me.uid; metaReaderClear(&mr); - tqDebug("vgId:%d, stream write, table %s, uid %ld already exist, skip create", TD_VID(pVnode), ctbName, uid); + tqDebug("vgId:%d, stream write, table %s, uid %" PRId64 " already exist, skip create", TD_VID(pVnode), ctbName, + uid); taosMemoryFreeClear(ctbName); } diff --git a/source/dnode/vnode/src/tq/tqStreamStateSnap.c b/source/dnode/vnode/src/tq/tqStreamStateSnap.c index 21172134baecaee806489ddb6d20e07293f172c2..92e5f8df7adc3c2061a39979ad51f2e238a88097 100644 --- a/source/dnode/vnode/src/tq/tqStreamStateSnap.c +++ b/source/dnode/vnode/src/tq/tqStreamStateSnap.c @@ -52,13 +52,13 @@ int32_t tqSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapReader** p goto _err; } - tqInfo("vgId:%d vnode snapshot tq reader opened", TD_VID(pTq->pVnode)); + tqInfo("vgId:%d, vnode snapshot tq reader opened", TD_VID(pTq->pVnode)); *ppReader = pReader; return code; _err: - tqError("vgId:%d vnode snapshot tq reader open failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); + tqError("vgId:%d, vnode snapshot tq reader open failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); *ppReader = NULL; return code; } @@ -113,14 +113,14 @@ int32_t tqSnapRead(STqSnapReader* pReader, uint8_t** ppData) { pHdr->size = vLen; memcpy(pHdr->data, pVal, vLen); - tqInfo("vgId:%d vnode snapshot tq read data, version:%" PRId64 " subKey: %s vLen:%d", TD_VID(pReader->pTq->pVnode), + tqInfo("vgId:%d, vnode snapshot tq read data, version:%" PRId64 " subKey: %s vLen:%d", TD_VID(pReader->pTq->pVnode), handle.snapshotVer, handle.subKey, vLen); _exit: return code; _err: - tqError("vgId:%d vnode snapshot tq read data failed since %s", TD_VID(pReader->pTq->pVnode), tstrerror(code)); + tqError("vgId:%d, vnode snapshot tq read data failed since %s", TD_VID(pReader->pTq->pVnode), tstrerror(code)); return code; } @@ -154,7 +154,7 @@ int32_t tqSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapWriter** p return code; _err: - tqError("vgId:%d tq snapshot writer open failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); + tqError("vgId:%d, tq snapshot writer open failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); *ppWriter = NULL; return code; } @@ -167,7 +167,7 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) { if (rollback) { ASSERT(0); } else { - code = tdbCommit(pWriter->pTq->pMetaStore, &pWriter->txn); + code = tdbCommit(pWriter->pTq->pMetaDB, &pWriter->txn); if (code) goto _err; } @@ -182,7 +182,7 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) { return code; _err: - tqError("vgId:%d tq snapshot writer close failed since %s", TD_VID(pWriter->pTq->pVnode), tstrerror(code)); + tqError("vgId:%d, tq snapshot writer close failed since %s", TD_VID(pWriter->pTq->pVnode), tstrerror(code)); return code; } @@ -204,6 +204,6 @@ int32_t tqSnapWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData) { _err: tDecoderClear(pDecoder); - tqError("vgId:%d vnode snapshot tq write failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); + tqError("vgId:%d, vnode snapshot tq write failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); return code; } diff --git a/source/dnode/vnode/src/tq/tqStreamTaskSnap.c b/source/dnode/vnode/src/tq/tqStreamTaskSnap.c index 21172134baecaee806489ddb6d20e07293f172c2..b4a7ce7737e5f599dac051f33e275918e7709c0d 100644 --- a/source/dnode/vnode/src/tq/tqStreamTaskSnap.c +++ b/source/dnode/vnode/src/tq/tqStreamTaskSnap.c @@ -52,13 +52,13 @@ int32_t tqSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapReader** p goto _err; } - tqInfo("vgId:%d vnode snapshot tq reader opened", TD_VID(pTq->pVnode)); + tqInfo("vgId:%d, vnode snapshot tq reader opened", TD_VID(pTq->pVnode)); *ppReader = pReader; return code; _err: - tqError("vgId:%d vnode snapshot tq reader open failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); + tqError("vgId:%d, vnode snapshot tq reader open failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); *ppReader = NULL; return code; } @@ -113,14 +113,14 @@ int32_t tqSnapRead(STqSnapReader* pReader, uint8_t** ppData) { pHdr->size = vLen; memcpy(pHdr->data, pVal, vLen); - tqInfo("vgId:%d vnode snapshot tq read data, version:%" PRId64 " subKey: %s vLen:%d", TD_VID(pReader->pTq->pVnode), + tqInfo("vgId:%d, vnode snapshot tq read data, version:%" PRId64 " subKey: %s vLen:%d", TD_VID(pReader->pTq->pVnode), handle.snapshotVer, handle.subKey, vLen); _exit: return code; _err: - tqError("vgId:%d vnode snapshot tq read data failed since %s", TD_VID(pReader->pTq->pVnode), tstrerror(code)); + tqError("vgId:%d, vnode snapshot tq read data failed since %s", TD_VID(pReader->pTq->pVnode), tstrerror(code)); return code; } @@ -154,7 +154,7 @@ int32_t tqSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapWriter** p return code; _err: - tqError("vgId:%d tq snapshot writer open failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); + tqError("vgId:%d, tq snapshot writer open failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); *ppWriter = NULL; return code; } @@ -182,7 +182,7 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) { return code; _err: - tqError("vgId:%d tq snapshot writer close failed since %s", TD_VID(pWriter->pTq->pVnode), tstrerror(code)); + tqError("vgId:%d, tq snapshot writer close failed since %s", TD_VID(pWriter->pTq->pVnode), tstrerror(code)); return code; } @@ -204,6 +204,6 @@ int32_t tqSnapWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData) { _err: tDecoderClear(pDecoder); - tqError("vgId:%d vnode snapshot tq write failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); + tqError("vgId:%d, vnode snapshot tq write failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 0ee2e310970179f89229836c2d66735fa3083943..101a6786dea82ce0e26ce9bf000540fcdb80774b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -15,11 +15,6 @@ #include "tsdb.h" -typedef struct { - TSKEY ts; - SColVal colVal; -} SLastCol; - int32_t tsdbOpenCache(STsdb *pTsdb) { int32_t code = 0; SLRUCache *pCache = NULL; @@ -61,9 +56,18 @@ static void getTableCacheKey(tb_uid_t uid, int cacheType, char *key, int *len) { *len = sizeof(uint64_t); } -static void deleteTableCacheLastrow(const void *key, size_t keyLen, void *value) { taosMemoryFree(value); } +static void deleteTableCacheLast(const void *key, size_t keyLen, void *value) { + SArray *pLastArray = (SArray *)value; + int16_t nCol = taosArrayGetSize(pLastArray); + for (int16_t iCol = 0; iCol < nCol; ++iCol) { + SLastCol *pLastCol = (SLastCol *)taosArrayGet(pLastArray, iCol); + if (IS_VAR_DATA_TYPE(pLastCol->colVal.type) && pLastCol->colVal.value.nData > 0) { + taosMemoryFree(pLastCol->colVal.value.pData); + } + } -static void deleteTableCacheLast(const void *key, size_t keyLen, void *value) { taosArrayDestroy(value); } + taosArrayDestroy(value); +} int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { int32_t code = 0; @@ -75,13 +79,23 @@ int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { getTableCacheKey(uid, 0, key, &keyLen); LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); if (h) { - STSRow *pRow = (STSRow *)taosLRUCacheValue(pCache, h); - if (pRow->ts <= eKey) { + SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h); + bool invalidate = false; + int16_t nCol = taosArrayGetSize(pLast); + + for (int16_t iCol = 0; iCol < nCol; ++iCol) { + SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol); + if (eKey >= tTsVal->ts) { + invalidate = true; + break; + } + } + + if (invalidate) { taosLRUCacheRelease(pCache, h, true); } else { taosLRUCacheRelease(pCache, h, false); } - // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); } @@ -130,14 +144,23 @@ int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { getTableCacheKey(uid, 0, key, &keyLen); LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); if (h) { - STSRow *pRow = (STSRow *)taosLRUCacheValue(pCache, h); - if (pRow->ts <= eKey) { + SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h); + bool invalidate = false; + int16_t nCol = taosArrayGetSize(pLast); + + for (int16_t iCol = 0; iCol < nCol; ++iCol) { + SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol); + if (eKey >= tTsVal->ts) { + invalidate = true; + break; + } + } + + if (invalidate) { taosLRUCacheRelease(pCache, h, true); } else { taosLRUCacheRelease(pCache, h, false); } - - // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); } // getTableCacheKey(uid, "l", key, &keyLen); @@ -177,6 +200,46 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST getTableCacheKey(uid, 0, key, &keyLen); LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); if (h) { + STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1, 1); + TSKEY keyTs = row->ts; + bool invalidate = false; + + SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h); + int16_t nCol = taosArrayGetSize(pLast); + int16_t iCol = 0; + + SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol); + if (keyTs > tTsVal->ts) { + STColumn *pTColumn = &pTSchema->columns[0]; + SColVal tColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = keyTs}); + + taosArraySet(pLast, iCol, &(SLastCol){.ts = keyTs, .colVal = tColVal}); + } + + for (++iCol; iCol < nCol; ++iCol) { + SLastCol *tTsVal1 = (SLastCol *)taosArrayGet(pLast, iCol); + if (keyTs >= tTsVal1->ts) { + SColVal *tColVal = &tTsVal1->colVal; + + SColVal colVal = {0}; + tTSRowGetVal(row, pTSchema, iCol, &colVal); + if (!COL_VAL_IS_NONE(&colVal)) { + if (keyTs == tTsVal1->ts && !COL_VAL_IS_NONE(tColVal)) { + invalidate = true; + + break; + } + } else { + taosArraySet(pLast, iCol, &(SLastCol){.ts = keyTs, .colVal = colVal}); + } + } + } + + _invalidate: + taosMemoryFreeClear(pTSchema); + + taosLRUCacheRelease(pCache, h, invalidate); + /* cacheRow = (STSRow *)taosLRUCacheValue(pCache, h); if (row->ts >= cacheRow->ts) { if (row->ts == cacheRow->ts) { @@ -218,9 +281,9 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST if (status != TAOS_LRU_STATUS_OK) { code = -1; } - /* tsdbCacheInsertLastrow(pCache, uid, row, dup); */ + // tsdbCacheInsertLastrow(pCache, uid, row, dup); } - } + }*/ } /*else { if (dup) { cacheRow = tdRowDup(row); @@ -456,6 +519,11 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow) { return code; } + if (state->pDataFReader != NULL) { + tsdbDataFReaderClose(&state->pDataFReader); + state->pDataFReader = NULL; + } + code = tsdbDataFReaderOpen(&state->pDataFReader, state->pTsdb, pFileSet); if (code) goto _err; @@ -599,6 +667,8 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) { */ state->pBlockIdx = taosArraySearch(state->aBlockIdx, state->pBlockIdxExp, tCmprBlockIdx, TD_EQ); if (!state->pBlockIdx) { + tsdbDataFReaderClose(&state->pDataFReader); + state->pDataFReader = NULL; goto _next_fileset; } @@ -1049,7 +1119,7 @@ _err: return code; } -static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRow) { +static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, SArray **ppColArray) { int32_t code = 0; STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1, 1); @@ -1057,7 +1127,7 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo int16_t iCol = 0; int16_t noneCol = 0; bool setNoneCol = false; - SArray *pColArray = taosArrayInit(nCol, sizeof(SColVal)); + SArray *pColArray = taosArrayInit(nCol, sizeof(SLastCol)); SColVal *pColVal = &(SColVal){0}; TSKEY lastRowTs = TSKEY_MAX; @@ -1073,12 +1143,15 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo break; } + TSKEY rowTs = TSDBROW_TS(pRow); + if (lastRowTs == TSKEY_MAX) { - lastRowTs = TSDBROW_TS(pRow); + lastRowTs = rowTs; STColumn *pTColumn = &pTSchema->columns[0]; *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = lastRowTs}); - if (taosArrayPush(pColArray, pColVal) == NULL) { + if (taosArrayPush(pColArray, &(SLastCol){.ts = lastRowTs, .colVal = *pColVal}) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } @@ -1086,7 +1159,18 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo for (iCol = 1; iCol < nCol; ++iCol) { tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); - if (taosArrayPush(pColArray, pColVal) == NULL) { + SLastCol lastCol = {.ts = lastRowTs, .colVal = *pColVal}; + if (IS_VAR_DATA_TYPE(pColVal->type) && pColVal->value.nData > 0) { + lastCol.colVal.value.pData = taosMemoryMalloc(lastCol.colVal.value.nData); + if (lastCol.colVal.value.pData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + memcpy(lastCol.colVal.value.pData, pColVal->value.pData, pColVal->value.nData); + } + + if (taosArrayPush(pColArray, &lastCol) == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } @@ -1097,15 +1181,15 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo } } if (!setNoneCol) { - // goto build the result ts row + // done, goto return pColArray break; } else { continue; } } - if ((TSDBROW_TS(pRow) < lastRowTs)) { - // goto build the result ts row + if ((rowTs < lastRowTs)) { + // done, goto return pColArray break; } @@ -1117,7 +1201,21 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); if (COL_VAL_IS_NONE(tColVal) && !COL_VAL_IS_NONE(pColVal)) { - taosArraySet(pColArray, iCol, pColVal); + SLastCol lastCol = {.ts = rowTs, .colVal = *pColVal}; + if (IS_VAR_DATA_TYPE(pColVal->type) && pColVal->value.nData > 0) { + SLastCol *pLastCol = (SLastCol *)taosArrayGet(pColArray, iCol); + taosMemoryFree(pLastCol->colVal.value.pData); + + lastCol.colVal.value.pData = taosMemoryMalloc(lastCol.colVal.value.nData); + if (lastCol.colVal.value.pData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + memcpy(lastCol.colVal.value.pData, pColVal->value.pData, pColVal->value.nData); + } + + taosArraySet(pColArray, iCol, &lastCol); } else if (COL_VAL_IS_NONE(tColVal) && COL_VAL_IS_NONE(pColVal) && !setNoneCol) { noneCol = iCol; setNoneCol = true; @@ -1127,15 +1225,14 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo // build the result ts row here *dup = false; - if (taosArrayGetSize(pColArray) == nCol) { - code = tdSTSRowNew(pColArray, pTSchema, ppRow); - if (code) goto _err; + if (taosArrayGetSize(pColArray) != nCol) { + *ppColArray = NULL; + taosArrayDestroy(pColArray); } else { - *ppRow = NULL; + *ppColArray = pColArray; } nextRowIterClose(&iter); - taosArrayDestroy(pColArray); taosMemoryFreeClear(pTSchema); return code; @@ -1185,7 +1282,18 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) { for (iCol = 1; iCol < nCol; ++iCol) { tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); - if (taosArrayPush(pColArray, &(SLastCol){.ts = lastRowTs, .colVal = *pColVal}) == NULL) { + SLastCol lastCol = {.ts = lastRowTs, .colVal = *pColVal}; + if (IS_VAR_DATA_TYPE(pColVal->type) && pColVal->value.nData > 0) { + lastCol.colVal.value.pData = taosMemoryMalloc(lastCol.colVal.value.nData); + if (lastCol.colVal.value.pData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + memcpy(lastCol.colVal.value.pData, pColVal->value.pData, pColVal->value.nData); + } + + if (taosArrayPush(pColArray, &lastCol) == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } @@ -1196,7 +1304,7 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) { } } if (!setNoneCol) { - // goto build the result ts row + // done, goto return pColArray break; } else { continue; @@ -1207,11 +1315,26 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) { setNoneCol = false; for (iCol = noneCol; iCol < nCol; ++iCol) { // high version's column value - SColVal *tColVal = (SColVal *)taosArrayGet(pColArray, iCol); + SLastCol *lastColVal = (SLastCol *)taosArrayGet(pColArray, iCol); + SColVal *tColVal = &lastColVal->colVal; tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); if (!COL_VAL_IS_VALUE(tColVal) && COL_VAL_IS_VALUE(pColVal)) { - taosArraySet(pColArray, iCol, &(SLastCol){.ts = rowTs, .colVal = *pColVal}); + SLastCol lastCol = {.ts = rowTs, .colVal = *pColVal}; + if (IS_VAR_DATA_TYPE(pColVal->type) && pColVal->value.nData > 0) { + SLastCol *pLastCol = (SLastCol *)taosArrayGet(pColArray, iCol); + taosMemoryFree(pLastCol->colVal.value.pData); + + lastCol.colVal.value.pData = taosMemoryMalloc(lastCol.colVal.value.nData); + if (lastCol.colVal.value.pData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + memcpy(lastCol.colVal.value.pData, pColVal->value.pData, pColVal->value.nData); + } + + taosArraySet(pColArray, iCol, &lastCol); } else if (!COL_VAL_IS_VALUE(tColVal) && !COL_VAL_IS_VALUE(pColVal) && !setNoneCol) { noneCol = iCol; setNoneCol = true; @@ -1219,7 +1342,6 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) { } } while (setNoneCol); - // build the result ts row here if (taosArrayGetSize(pColArray) <= 0) { *ppLastArray = NULL; taosArrayDestroy(pColArray); @@ -1252,13 +1374,13 @@ int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUH h = taosLRUCacheLookup(pCache, key, keyLen); if (!h) { - STSRow *pRow = NULL; + SArray *pArray = NULL; bool dup = false; // which is always false for now - code = mergeLastRow(uid, pTsdb, &dup, &pRow); + code = mergeLastRow(uid, pTsdb, &dup, &pArray); // if table's empty or error, return code of -1 - if (code < 0 || pRow == NULL) { - if (!dup && pRow) { - taosMemoryFree(pRow); + if (code < 0 || pArray == NULL) { + if (!dup && pArray) { + taosArrayDestroy(pArray); } taosThreadMutexUnlock(&pTsdb->lruMutex); @@ -1268,9 +1390,9 @@ int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUH return 0; } - _taos_lru_deleter_t deleter = deleteTableCacheLastrow; - LRUStatus status = - taosLRUCacheInsert(pCache, key, keyLen, pRow, TD_ROW_LEN(pRow), deleter, NULL, TAOS_LRU_PRIORITY_LOW); + size_t charge = pArray->capacity * pArray->elemSize + sizeof(*pArray); + _taos_lru_deleter_t deleter = deleteTableCacheLast; + LRUStatus status = taosLRUCacheInsert(pCache, key, keyLen, pArray, charge, deleter, NULL, TAOS_LRU_PRIORITY_LOW); if (status != TAOS_LRU_STATUS_OK) { code = -1; } @@ -1328,15 +1450,17 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHand SArray *pLastArray = NULL; code = mergeLast(uid, pTsdb, &pLastArray); // if table's empty or error, return code of -1 - // if (code < 0 || pRow == NULL) { if (code < 0 || pLastArray == NULL) { + taosThreadMutexUnlock(&pTsdb->lruMutex); + *handle = NULL; return 0; } + size_t charge = pLastArray->capacity * pLastArray->elemSize + sizeof(*pLastArray); _taos_lru_deleter_t deleter = deleteTableCacheLast; - LRUStatus status = taosLRUCacheInsert(pCache, key, keyLen, pLastArray, pLastArray->capacity, deleter, NULL, - TAOS_LRU_PRIORITY_LOW); + LRUStatus status = + taosLRUCacheInsert(pCache, key, keyLen, pLastArray, charge, deleter, NULL, TAOS_LRU_PRIORITY_LOW); if (status != TAOS_LRU_STATUS_OK) { code = -1; } @@ -1368,4 +1492,11 @@ void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity) { size_t tsdbCacheGetCapacity(SVnode *pVnode) { return taosLRUCacheGetCapacity(pVnode->pTsdb->lruCache); } -size_t tsdbCacheGetUsage(SVnode *pVnode) { return taosLRUCacheGetUsage(pVnode->pTsdb->lruCache); } +size_t tsdbCacheGetUsage(SVnode *pVnode) { + size_t usage = 0; + if (pVnode->pTsdb != NULL) { + usage = taosLRUCacheGetUsage(pVnode->pTsdb->lruCache); + } + + return usage; +} diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index 81219e1442261e79ee8d63754c7eaeb29af4d79d..905150cab090663a40f8bb808591432ecef2a174 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -29,36 +29,83 @@ typedef struct SCacheRowsReader { SArray* pTableList; // table id list } SCacheRowsReader; -static void saveOneRow(STSRow* pRow, SSDataBlock* pBlock, SCacheRowsReader* pReader, const int32_t* slotIds) { +#define HASTYPE(_type, _t) (((_type) & (_t)) == (_t)) + +static void saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* pReader, const int32_t* slotIds, + void** pRes) { ASSERT(pReader->numOfCols <= taosArrayGetSize(pBlock->pDataBlock)); int32_t numOfRows = pBlock->info.rows; - SColVal colVal = {0}; - for (int32_t i = 0; i < pReader->numOfCols; ++i) { - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); + if (HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST)) { + bool allNullRow = true; + + for (int32_t i = 0; i < pReader->numOfCols; ++i) { + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); + SFirstLastRes* p = (SFirstLastRes*)varDataVal(pRes[i]); + + if (slotIds[i] == -1) { // the primary timestamp + SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, 0); + p->ts = pColVal->ts; + p->bytes = TSDB_KEYSIZE; + *(int64_t*)p->buf = pColVal->ts; + allNullRow = false; + } else { + int32_t slotId = slotIds[i]; + SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, slotId); + + p->ts = pColVal->ts; + p->isNull = !COL_VAL_IS_VALUE(&pColVal->colVal); + allNullRow = p->isNull & allNullRow; + + if (!p->isNull) { + if (IS_VAR_DATA_TYPE(pColVal->colVal.type)) { + varDataSetLen(p->buf, pColVal->colVal.value.nData); + memcpy(varDataVal(p->buf), pColVal->colVal.value.pData, pColVal->colVal.value.nData); + p->bytes = pColVal->colVal.value.nData + VARSTR_HEADER_SIZE; // binary needs to plus the header size + } else { + memcpy(p->buf, &pColVal->colVal.value, pReader->pSchema->columns[slotId].bytes); + p->bytes = pReader->pSchema->columns[slotId].bytes; + } + } + } + + // pColInfoData->info.bytes includes the VARSTR_HEADER_SIZE, need to substruct it + p->hasResult = true; + varDataSetLen(pRes[i], pColInfoData->info.bytes - VARSTR_HEADER_SIZE); + colDataAppend(pColInfoData, numOfRows, (const char*)pRes[i], false); + } - if (slotIds[i] == -1) { - colDataAppend(pColInfoData, numOfRows, (const char*)&pRow->ts, false); - } else { - int32_t slotId = slotIds[i]; + pBlock->info.rows += allNullRow? 0:1; + } else { + ASSERT(HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST_ROW)); - tTSRowGetVal(pRow, pReader->pSchema, slotId, &colVal); + for (int32_t i = 0; i < pReader->numOfCols; ++i) { + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); - if (IS_VAR_DATA_TYPE(colVal.type)) { - if (!COL_VAL_IS_VALUE(&colVal)) { - colDataAppendNULL(pColInfoData, numOfRows); + if (slotIds[i] == -1) { + SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, 0); + colDataAppend(pColInfoData, numOfRows, (const char*)&pColVal->ts, false); + } else { + int32_t slotId = slotIds[i]; + SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, slotId); + SColVal* pVal = &pColVal->colVal; + + if (IS_VAR_DATA_TYPE(pColVal->colVal.type)) { + if (!COL_VAL_IS_VALUE(&pColVal->colVal)) { + colDataAppendNULL(pColInfoData, numOfRows); + } else { + varDataSetLen(pReader->transferBuf[slotId], pVal->value.nData); + memcpy(varDataVal(pReader->transferBuf[slotId]), pVal->value.pData, pVal->value.nData); + colDataAppend(pColInfoData, numOfRows, pReader->transferBuf[slotId], false); + } } else { - varDataSetLen(pReader->transferBuf[slotId], colVal.value.nData); - memcpy(varDataVal(pReader->transferBuf[slotId]), colVal.value.pData, colVal.value.nData); - colDataAppend(pColInfoData, numOfRows, pReader->transferBuf[slotId], false); + colDataAppend(pColInfoData, numOfRows, (const char*)&pVal->value.val, !COL_VAL_IS_VALUE(pVal)); } - } else { - colDataAppend(pColInfoData, numOfRows, (const char*)&colVal.value, !COL_VAL_IS_VALUE(&colVal)); } } - } - pBlock->info.rows += 1; + pBlock->info.rows += 1; + } } int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t numOfCols, void** pReader) { @@ -84,6 +131,7 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList p->transferBuf = taosMemoryCalloc(p->pSchema->numOfCols, POINTER_BYTES); if (p->transferBuf == NULL) { + tsdbCacherowsReaderClose(p); return TSDB_CODE_OUT_OF_MEMORY; } @@ -117,35 +165,36 @@ void* tsdbCacherowsReaderClose(void* pReader) { return NULL; } -static int32_t doExtractCacheRow(SCacheRowsReader* pr, SLRUCache* lruCache, uint64_t uid, STSRow** pRow, +static int32_t doExtractCacheRow(SCacheRowsReader* pr, SLRUCache* lruCache, uint64_t uid, SArray** pRow, LRUHandle** h) { int32_t code = TSDB_CODE_SUCCESS; - if ((pr->type & CACHESCAN_RETRIEVE_LAST_ROW) == CACHESCAN_RETRIEVE_LAST_ROW) { - code = tsdbCacheGetLastrowH(lruCache, uid, pr->pVnode->pTsdb, h); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + *pRow = NULL; - // no data in the table of Uid - if (*h != NULL) { - *pRow = (STSRow*)taosLRUCacheValue(lruCache, *h); - } + if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_LAST_ROW)) { + code = tsdbCacheGetLastrowH(lruCache, uid, pr->pVnode->pTsdb, h); } else { code = tsdbCacheGetLastH(lruCache, uid, pr->pVnode->pTsdb, h); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + } - // no data in the table of Uid - if (*h != NULL) { - SArray* pLast = (SArray*)taosLRUCacheValue(lruCache, *h); - tsdbCacheLastArray2Row(pLast, pRow, pr->pSchema); - } + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + // no data in the table of Uid + if (*h != NULL) { + *pRow = (SArray*)taosLRUCacheValue(lruCache, *h); } return code; } +static void freeItem(void* pItem) { + SLastCol* pCol = (SLastCol*) pItem; + if (IS_VAR_DATA_TYPE(pCol->colVal.type)) { + taosMemoryFree(pCol->colVal.value.pData); + } +} + int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32_t* slotIds, SArray* pTableUidList) { if (pReader == NULL || pResBlock == NULL) { return TSDB_CODE_INVALID_PARA; @@ -156,13 +205,41 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 int32_t code = TSDB_CODE_SUCCESS; SLRUCache* lruCache = pr->pVnode->pTsdb->lruCache; LRUHandle* h = NULL; - STSRow* pRow = NULL; + SArray* pRow = NULL; size_t numOfTables = taosArrayGetSize(pr->pTableList); + bool hasRes = false; + SArray* pLastCols = NULL; + + void** pRes = taosMemoryCalloc(pr->numOfCols, POINTER_BYTES); + if (pRes == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _end; + } + + for (int32_t j = 0; j < pr->numOfCols; ++j) { + pRes[j] = taosMemoryCalloc(1, sizeof(SFirstLastRes) + pr->pSchema->columns[slotIds[j]].bytes + VARSTR_HEADER_SIZE); + SFirstLastRes* p = (SFirstLastRes*)varDataVal(pRes[j]); + p->ts = INT64_MIN; + } + + pLastCols = taosArrayInit(pr->pSchema->numOfCols, sizeof(SLastCol)); + if (pLastCols == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _end; + } + + for (int32_t i = 0; i < pr->pSchema->numOfCols; ++i) { + struct STColumn* pCol = &pr->pSchema->columns[i]; + SLastCol p = {.ts = INT64_MIN, .colVal.type = pCol->type}; + + if (IS_VAR_DATA_TYPE(pCol->type)) { + p.colVal.value.pData = taosMemoryCalloc(pCol->bytes, sizeof(char)); + } + taosArrayPush(pLastCols, &p); + } // retrieve the only one last row of all tables in the uid list. - if ((pr->type & CACHESCAN_RETRIEVE_TYPE_SINGLE) == CACHESCAN_RETRIEVE_TYPE_SINGLE) { - int64_t lastKey = INT64_MIN; - bool internalResult = false; + if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_TYPE_SINGLE)) { for (int32_t i = 0; i < numOfTables; ++i) { STableKeyInfo* pKeyInfo = taosArrayGet(pr->pTableList, i); @@ -175,25 +252,61 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 continue; } - if (pRow->ts > lastKey) { - // Set result row into the same rowIndex repeatly, so we need to check if the internal result row has already - // appended or not. - if (internalResult) { - pResBlock->info.rows -= 1; - taosArrayClear(pTableUidList); + { + for (int32_t k = 0; k < pr->numOfCols; ++k) { + int32_t slotId = slotIds[k]; + + if (slotId == -1) { // the primary timestamp + SLastCol* p = taosArrayGet(pLastCols, 0); + SLastCol* pCol = (SLastCol*)taosArrayGet(pRow, 0); + if (pCol->ts > p->ts) { + hasRes = true; + p->ts = pCol->ts; + p->colVal = pCol->colVal; + + // only set value for last row query + if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_LAST_ROW)) { + if (taosArrayGetSize(pTableUidList) == 0) { + taosArrayPush(pTableUidList, &pKeyInfo->uid); + } else { + taosArraySet(pTableUidList, 0, &pKeyInfo->uid); + } + } + } + } else { + SLastCol* p = taosArrayGet(pLastCols, slotId); + SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, slotId); + + if (pColVal->ts > p->ts) { + if (!COL_VAL_IS_VALUE(&pColVal->colVal) && HASTYPE(pr->type, CACHESCAN_RETRIEVE_LAST)) { + continue; + } + + hasRes = true; + p->ts = pColVal->ts; + + uint8_t* px = p->colVal.value.pData; + p->colVal = pColVal->colVal; + + if (COL_VAL_IS_VALUE(&pColVal->colVal) && IS_VAR_DATA_TYPE(pColVal->colVal.type)) { + p->colVal.value.pData = px; + memcpy(px, pColVal->colVal.value.pData, pColVal->colVal.value.nData); + } + } + } } - - saveOneRow(pRow, pResBlock, pr, slotIds); - taosArrayPush(pTableUidList, &pKeyInfo->uid); - internalResult = true; - lastKey = pRow->ts; } tsdbCacheRelease(lruCache, h); } - } else if ((pr->type & CACHESCAN_RETRIEVE_TYPE_ALL) == CACHESCAN_RETRIEVE_TYPE_ALL) { + + if (hasRes) { + saveOneRow(pLastCols, pResBlock, pr, slotIds, pRes); + } + + } else if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_TYPE_ALL)) { for (int32_t i = pr->tableIndex; i < numOfTables; ++i) { - STableKeyInfo* pKeyInfo = taosArrayGet(pr->pTableList, i); + STableKeyInfo* pKeyInfo = (STableKeyInfo*) taosArrayGet(pr->pTableList, i); code = doExtractCacheRow(pr, lruCache, pKeyInfo->uid, &pRow, &h); if (code != TSDB_CODE_SUCCESS) { return code; @@ -203,19 +316,27 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 continue; } - saveOneRow(pRow, pResBlock, pr, slotIds); - taosArrayPush(pTableUidList, &pKeyInfo->uid); + saveOneRow(pRow, pResBlock, pr, slotIds, pRes); + // TODO reset the pRes + taosArrayPush(pTableUidList, &pKeyInfo->uid); tsdbCacheRelease(lruCache, h); pr->tableIndex += 1; if (pResBlock->info.rows >= pResBlock->info.capacity) { - return TSDB_CODE_SUCCESS; + goto _end; } } } else { - return TSDB_CODE_INVALID_PARA; + code = TSDB_CODE_INVALID_PARA; } - return TSDB_CODE_SUCCESS; + _end: + for (int32_t j = 0; j < pr->numOfCols; ++j) { + taosMemoryFree(pRes[j]); + } + + taosMemoryFree(pRes); + taosArrayDestroyEx(pLastCols, freeItem); + return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index a4d993bc6c318967d2624aed82ce66918a778d00..578473c79a5ce65d70058e1ed2fe939bcac2a9f6 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -145,7 +145,7 @@ int32_t tsdbBegin(STsdb *pTsdb) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } @@ -186,7 +186,7 @@ int32_t tsdbCommit(STsdb *pTsdb) { _exit: if (code) { tsdbEndCommit(&commith, code); - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } @@ -479,7 +479,7 @@ static int32_t tsdbOpenCommitIter(SCommitter *pCommitter) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; @@ -567,7 +567,7 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } @@ -619,7 +619,7 @@ int32_t tsdbWriteDataBlock(SDataFWriter *pWriter, SBlockData *pBlockData, SMapDa _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } @@ -662,7 +662,7 @@ int32_t tsdbWriteSttBlock(SDataFWriter *pWriter, SBlockData *pBlockData, SArray _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } @@ -702,7 +702,7 @@ static int32_t tsdbCommitSttBlk(SDataFWriter *pWriter, SDiskDataBuilder *pBuilde _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } @@ -738,7 +738,7 @@ static int32_t tsdbCommitFileDataEnd(SCommitter *pCommitter) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; @@ -764,7 +764,7 @@ static int32_t tsdbMoveCommitData(SCommitter *pCommitter, TABLEID toTable) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; @@ -791,7 +791,7 @@ static int32_t tsdbCommitFileData(SCommitter *pCommitter) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); tsdbDataFReaderClose(&pCommitter->dReader.pReader); tsdbDataFWriterClose(&pCommitter->dWriter.pWriter, 0); } @@ -829,7 +829,7 @@ static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitter *pCommitter) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } @@ -886,7 +886,7 @@ static int32_t tsdbCommitDataStart(SCommitter *pCommitter) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; @@ -945,7 +945,7 @@ static int32_t tsdbCommitData(SCommitter *pCommitter) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } @@ -1031,9 +1031,9 @@ static int32_t tsdbCommitDel(SCommitter *pCommitter) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); } else { - tsdbDebug("vgId:%d commit del done, nDel:%" PRId64, TD_VID(pTsdb->pVnode), pMemTable->nDel); + tsdbDebug("vgId:%d, commit del done, nDel:%" PRId64, TD_VID(pTsdb->pVnode), pMemTable->nDel); } return code; } @@ -1041,41 +1041,24 @@ _exit: static int32_t tsdbEndCommit(SCommitter *pCommitter, int32_t eno) { int32_t code = 0; int32_t lino = 0; + STsdb *pTsdb = pCommitter->pTsdb; - STsdb *pTsdb = pCommitter->pTsdb; - SMemTable *pMemTable = pTsdb->imem; - - ASSERT(eno == 0 && - "tsdbCommit failure" - "Restart taosd"); - - code = tsdbFSCommit1(pTsdb, &pCommitter->fs); - TSDB_CHECK_CODE(code, lino, _exit); - - // lock - taosThreadRwlockWrlock(&pTsdb->rwLock); - - // commit or rollback - code = tsdbFSCommit2(pTsdb, &pCommitter->fs); - if (code) { - taosThreadRwlockUnlock(&pTsdb->rwLock); + if (eno) { + code = eno; + TSDB_CHECK_CODE(code, lino, _exit); + } else { + code = tsdbFSPrepareCommit(pCommitter->pTsdb, &pCommitter->fs); TSDB_CHECK_CODE(code, lino, _exit); } - pTsdb->imem = NULL; - - // unlock - taosThreadRwlockUnlock(&pTsdb->rwLock); - - tsdbUnrefMemTable(pMemTable); +_exit: tsdbFSDestroy(&pCommitter->fs); taosArrayDestroy(pCommitter->aTbDataP); - -_exit: - if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + pCommitter->aTbDataP = NULL; + if (code || eno) { + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); } else { - tsdbInfo("vgId:%d tsdb end commit", TD_VID(pTsdb->pVnode)); + tsdbInfo("vgId:%d, tsdb end commit", TD_VID(pTsdb->pVnode)); } return code; } @@ -1167,7 +1150,7 @@ static int32_t tsdbNextCommitRow(SCommitter *pCommitter) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; @@ -1215,7 +1198,7 @@ static int32_t tsdbCommitAheadBlock(SCommitter *pCommitter, SDataBlk *pDataBlk) _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; @@ -1302,7 +1285,7 @@ static int32_t tsdbCommitMergeBlock(SCommitter *pCommitter, SDataBlk *pDataBlk) _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; @@ -1377,7 +1360,7 @@ static int32_t tsdbMergeTableData(SCommitter *pCommitter, TABLEID id) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; @@ -1426,7 +1409,7 @@ static int32_t tsdbInitSttBlockBuilderIfNeed(SCommitter *pCommitter, TABLEID id) _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; @@ -1470,7 +1453,7 @@ static int32_t tsdbAppendLastBlock(SCommitter *pCommitter) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; @@ -1574,7 +1557,7 @@ static int32_t tsdbCommitTableData(SCommitter *pCommitter, TABLEID id) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; @@ -1641,8 +1624,55 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) { _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pCommitter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } + +int32_t tsdbFinishCommit(STsdb *pTsdb) { + int32_t code = 0; + int32_t lino = 0; + SMemTable *pMemTable = pTsdb->imem; + + // lock + taosThreadRwlockWrlock(&pTsdb->rwLock); + + code = tsdbFSCommit(pTsdb); + if (code) { + taosThreadRwlockUnlock(&pTsdb->rwLock); + TSDB_CHECK_CODE(code, lino, _exit); + } + + pTsdb->imem = NULL; + + // unlock + taosThreadRwlockUnlock(&pTsdb->rwLock); + if (pMemTable) { + tsdbUnrefMemTable(pMemTable); + } + +_exit: + if (code) { + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + } else { + tsdbInfo("vgId:%d, tsdb finish commit", TD_VID(pTsdb->pVnode)); + } + return code; +} + +int32_t tsdbRollbackCommit(STsdb *pTsdb) { + int32_t code = 0; + int32_t lino = 0; + + code = tsdbFSRollback(pTsdb); + TSDB_CHECK_CODE(code, lino, _exit); + +_exit: + if (code) { + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + } else { + tsdbInfo("vgId:%d, tsdb rollback commit", TD_VID(pTsdb->pVnode)); + } + return code; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 6fd562959229fd4c75b4f333f118caa86a66555c..72d9c4f69ef19908a84e27d9ecfe03b1aa776337 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -16,7 +16,7 @@ #include "tsdb.h" // ================================================================================================= -static int32_t tsdbEncodeFS(uint8_t *p, STsdbFS *pFS) { +static int32_t tsdbFSToBinary(uint8_t *p, STsdbFS *pFS) { int32_t n = 0; int8_t hasDel = pFS->pDelFile ? 1 : 0; uint32_t nSet = taosArrayGetSize(pFS->aDFileSet); @@ -39,218 +39,117 @@ static int32_t tsdbEncodeFS(uint8_t *p, STsdbFS *pFS) { return n; } -static int32_t tsdbGnrtCurrent(STsdb *pTsdb, STsdbFS *pFS, char *fname) { - int32_t code = 0; - int64_t n; - int64_t size; - uint8_t *pData = NULL; - TdFilePtr pFD = NULL; +static int32_t tsdbBinaryToFS(uint8_t *pData, int64_t nData, STsdbFS *pFS) { + int32_t code = 0; + int32_t n = 0; - // to binary - size = tsdbEncodeFS(NULL, pFS) + sizeof(TSCKSUM); - pData = taosMemoryMalloc(size); + // version + n += tGetI8(pData + n, NULL); + + // SDelFile + int8_t hasDel = 0; + n += tGetI8(pData + n, &hasDel); + if (hasDel) { + pFS->pDelFile = (SDelFile *)taosMemoryCalloc(1, sizeof(SDelFile)); + if (pFS->pDelFile == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + n += tGetDelFile(pData + n, pFS->pDelFile); + pFS->pDelFile->nRef = 1; + } else { + pFS->pDelFile = NULL; + } + + // aDFileSet + taosArrayClear(pFS->aDFileSet); + uint32_t nSet = 0; + n += tGetU32v(pData + n, &nSet); + for (uint32_t iSet = 0; iSet < nSet; iSet++) { + SDFileSet fSet = {0}; + + int32_t nt = tGetDFileSet(pData + n, &fSet); + if (nt < 0) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + n += nt; + if (taosArrayPush(pFS->aDFileSet, &fSet) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + } + + ASSERT(n + sizeof(TSCKSUM) == nData); + +_exit: + return code; +} + +static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) { + int32_t code = 0; + int32_t lino = 0; + + // encode to binary + int32_t size = tsdbFSToBinary(NULL, pFS) + sizeof(TSCKSUM); + uint8_t *pData = taosMemoryMalloc(size); if (pData == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } - n = tsdbEncodeFS(pData, pFS); - ASSERT(n + sizeof(TSCKSUM) == size); + tsdbFSToBinary(pData, pFS); taosCalcChecksumAppend(0, pData, size); - // create and write - pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); + // save to file + TdFilePtr pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); if (pFD == NULL) { code = TAOS_SYSTEM_ERROR(errno); - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } - n = taosWriteFile(pFD, pData, size); + int64_t n = taosWriteFile(pFD, pData, size); if (n < 0) { code = TAOS_SYSTEM_ERROR(errno); - goto _err; + taosCloseFile(&pFD); + TSDB_CHECK_CODE(code, lino, _exit); } if (taosFsyncFile(pFD) < 0) { code = TAOS_SYSTEM_ERROR(errno); - goto _err; + taosCloseFile(&pFD); + TSDB_CHECK_CODE(code, lino, _exit); } taosCloseFile(&pFD); +_exit: if (pData) taosMemoryFree(pData); + if (code) { + tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname); + } return code; +} -_err: - tsdbError("vgId:%d, tsdb gnrt current failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); - if (pData) taosMemoryFree(pData); +int32_t tsdbFSCreate(STsdbFS *pFS) { + int32_t code = 0; + + pFS->pDelFile = NULL; + pFS->aDFileSet = taosArrayInit(0, sizeof(SDFileSet)); + if (pFS->aDFileSet == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + +_exit: return code; } -// static int32_t tsdbApplyDFileSetChange(STsdbFS *pFS, SDFileSet *pFrom, SDFileSet *pTo) { -// int32_t code = 0; -// char fname[TSDB_FILENAME_LEN]; - -// if (pFrom && pTo) { -// bool isSameDisk = (pFrom->diskId.level == pTo->diskId.level) && (pFrom->diskId.id == pTo->diskId.id); - -// // head -// if (isSameDisk && pFrom->pHeadF->commitID == pTo->pHeadF->commitID) { -// ASSERT(pFrom->pHeadF->size == pTo->pHeadF->size); -// ASSERT(pFrom->pHeadF->offset == pTo->pHeadF->offset); -// } else { -// tsdbHeadFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pHeadF, fname); -// taosRemoveFile(fname); -// } - -// // data -// if (isSameDisk && pFrom->pDataF->commitID == pTo->pDataF->commitID) { -// if (pFrom->pDataF->size > pTo->pDataF->size) { -// code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_DATA_FILE); -// if (code) goto _err; -// } -// } else { -// tsdbDataFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pDataF, fname); -// taosRemoveFile(fname); -// } - -// // stt -// if (isSameDisk && pFrom->pLastF->commitID == pTo->pLastF->commitID) { -// if (pFrom->pLastF->size > pTo->pLastF->size) { -// code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_LAST_FILE); -// if (code) goto _err; -// } -// } else { -// tsdbLastFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pLastF, fname); -// taosRemoveFile(fname); -// } - -// // sma -// if (isSameDisk && pFrom->pSmaF->commitID == pTo->pSmaF->commitID) { -// if (pFrom->pSmaF->size > pTo->pSmaF->size) { -// code = tsdbDFileRollback(pFS->pTsdb, pTo, TSDB_SMA_FILE); -// if (code) goto _err; -// } -// } else { -// tsdbSmaFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pSmaF, fname); -// taosRemoveFile(fname); -// } -// } else if (pFrom) { -// // head -// tsdbHeadFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pHeadF, fname); -// taosRemoveFile(fname); - -// // data -// tsdbDataFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pDataF, fname); -// taosRemoveFile(fname); - -// // stt -// tsdbLastFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pLastF, fname); -// taosRemoveFile(fname); - -// // fsm -// tsdbSmaFileName(pFS->pTsdb, pFrom->diskId, pFrom->fid, pFrom->pSmaF, fname); -// taosRemoveFile(fname); -// } - -// return code; - -// _err: -// tsdbError("vgId:%d, tsdb apply disk file set change failed since %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code)); -// return code; -// } - -// static int32_t tsdbApplyDelFileChange(STsdbFS *pFS, SDelFile *pFrom, SDelFile *pTo) { -// int32_t code = 0; -// char fname[TSDB_FILENAME_LEN]; - -// if (pFrom && pTo) { -// if (!tsdbDelFileIsSame(pFrom, pTo)) { -// tsdbDelFileName(pFS->pTsdb, pFrom, fname); -// if (taosRemoveFile(fname) < 0) { -// code = TAOS_SYSTEM_ERROR(errno); -// goto _err; -// } -// } -// } else if (pFrom) { -// tsdbDelFileName(pFS->pTsdb, pFrom, fname); -// if (taosRemoveFile(fname) < 0) { -// code = TAOS_SYSTEM_ERROR(errno); -// goto _err; -// } -// } else { -// // do nothing -// } - -// return code; - -// _err: -// tsdbError("vgId:%d, tsdb apply del file change failed since %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code)); -// return code; -// } - -// static int32_t tsdbFSApplyDiskChange(STsdbFS *pFS, STsdbFSState *pFrom, STsdbFSState *pTo) { -// int32_t code = 0; -// int32_t iFrom = 0; -// int32_t nFrom = taosArrayGetSize(pFrom->aDFileSet); -// int32_t iTo = 0; -// int32_t nTo = taosArrayGetSize(pTo->aDFileSet); -// SDFileSet *pDFileSetFrom; -// SDFileSet *pDFileSetTo; - -// // SDelFile -// code = tsdbApplyDelFileChange(pFS, pFrom->pDelFile, pTo->pDelFile); -// if (code) goto _err; - -// // SDFileSet -// while (iFrom < nFrom && iTo < nTo) { -// pDFileSetFrom = (SDFileSet *)taosArrayGet(pFrom->aDFileSet, iFrom); -// pDFileSetTo = (SDFileSet *)taosArrayGet(pTo->aDFileSet, iTo); - -// if (pDFileSetFrom->fid == pDFileSetTo->fid) { -// code = tsdbApplyDFileSetChange(pFS, pDFileSetFrom, pDFileSetTo); -// if (code) goto _err; - -// iFrom++; -// iTo++; -// } else if (pDFileSetFrom->fid < pDFileSetTo->fid) { -// code = tsdbApplyDFileSetChange(pFS, pDFileSetFrom, NULL); -// if (code) goto _err; - -// iFrom++; -// } else { -// iTo++; -// } -// } - -// while (iFrom < nFrom) { -// pDFileSetFrom = (SDFileSet *)taosArrayGet(pFrom->aDFileSet, iFrom); -// code = tsdbApplyDFileSetChange(pFS, pDFileSetFrom, NULL); -// if (code) goto _err; - -// iFrom++; -// } - -// #if 0 -// // do noting -// while (iTo < nTo) { -// pDFileSetTo = (SDFileSet *)taosArrayGetP(pTo->aDFileSet, iTo); -// code = tsdbApplyDFileSetChange(pFS, NULL, pDFileSetTo); -// if (code) goto _err; - -// iTo++; -// } -// #endif - -// return code; - -// _err: -// tsdbError("vgId:%d, tsdb fs apply disk change failed sicne %s", TD_VID(pFS->pTsdb->pVnode), tstrerror(code)); -// return code; -// } - void tsdbFSDestroy(STsdbFS *pFS) { if (pFS->pDelFile) { taosMemoryFree(pFS->pDelFile); + pFS->pDelFile = NULL; } for (int32_t iSet = 0; iSet < taosArrayGetSize(pFS->aDFileSet); iSet++) { @@ -264,80 +163,86 @@ void tsdbFSDestroy(STsdbFS *pFS) { } taosArrayDestroy(pFS->aDFileSet); + pFS->aDFileSet = NULL; } static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { int32_t code = 0; - int64_t size; - char fname[TSDB_FILENAME_LEN]; + int32_t lino = 0; + int64_t size = 0; + char fname[TSDB_FILENAME_LEN] = {0}; // SDelFile if (pTsdb->fs.pDelFile) { tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname); if (taosStatFile(fname, &size, NULL)) { code = TAOS_SYSTEM_ERROR(errno); - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } if (size != tsdbLogicToFileSize(pTsdb->fs.pDelFile->size, pTsdb->pVnode->config.tsdbPageSize)) { code = TSDB_CODE_FILE_CORRUPTED; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } } // SArray + int32_t fid = 0; for (int32_t iSet = 0; iSet < taosArrayGetSize(pTsdb->fs.aDFileSet); iSet++) { SDFileSet *pSet = (SDFileSet *)taosArrayGet(pTsdb->fs.aDFileSet, iSet); + fid = pSet->fid; // head ========= tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname); if (taosStatFile(fname, &size, NULL)) { code = TAOS_SYSTEM_ERROR(errno); - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } if (size != tsdbLogicToFileSize(pSet->pHeadF->size, pTsdb->pVnode->config.tsdbPageSize)) { code = TSDB_CODE_FILE_CORRUPTED; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } // data ========= tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname); if (taosStatFile(fname, &size, NULL)) { code = TAOS_SYSTEM_ERROR(errno); - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } if (size < tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) { code = TSDB_CODE_FILE_CORRUPTED; - goto _err; - } else if (size > tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) { - code = tsdbDFileRollback(pTsdb, pSet, TSDB_DATA_FILE); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } + // else if (size > tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) { + // code = tsdbDFileRollback(pTsdb, pSet, TSDB_DATA_FILE); + // TSDB_CHECK_CODE(code, lino, _exit); + // } // sma ============= tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname); if (taosStatFile(fname, &size, NULL)) { code = TAOS_SYSTEM_ERROR(errno); - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } if (size < tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) { code = TSDB_CODE_FILE_CORRUPTED; - goto _err; - } else if (size > tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) { - code = tsdbDFileRollback(pTsdb, pSet, TSDB_SMA_FILE); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } + // else if (size > tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) { + // code = tsdbDFileRollback(pTsdb, pSet, TSDB_SMA_FILE); + // TSDB_CHECK_CODE(code, lino, _exit); + // } // stt =========== for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) { tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname); if (taosStatFile(fname, &size, NULL)) { code = TAOS_SYSTEM_ERROR(errno); - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } if (size != tsdbLogicToFileSize(pSet->aSttF[iStt]->size, pTsdb->pVnode->config.tsdbPageSize)) { code = TSDB_CODE_FILE_CORRUPTED; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } } } @@ -346,10 +251,11 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { // remove those invalid files (todo) } - return code; - -_err: - tsdbError("vgId:%d, tsdb scan and try fix fs failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); +_exit: + if (code) { + tsdbError("vgId:%d, %s failed at line %d since %s, fid:%d", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code), + fid); + } return code; } @@ -363,141 +269,531 @@ int32_t tDFileSetCmprFn(const void *p1, const void *p2) { return 0; } -static int32_t tsdbRecoverFS(STsdb *pTsdb, uint8_t *pData, int64_t nData) { +static void tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t) { + SVnode *pVnode = pTsdb->pVnode; + if (pVnode->pTfs) { + if (current) { + snprintf(current, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP, + pTsdb->path, TD_DIRSEP); + } + if (current_t) { + snprintf(current_t, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT.t", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP, + pTsdb->path, TD_DIRSEP); + } + } else { + if (current) { + snprintf(current, TSDB_FILENAME_LEN - 1, "%s%sCURRENT", pTsdb->path, TD_DIRSEP); + } + if (current_t) { + snprintf(current_t, TSDB_FILENAME_LEN - 1, "%s%sCURRENT.t", pTsdb->path, TD_DIRSEP); + } + } +} + +static int32_t tsdbLoadFSFromFile(const char *fname, STsdbFS *pFS) { int32_t code = 0; - int8_t hasDel; - uint32_t nSet; - int32_t n = 0; + int32_t lino = 0; + uint8_t *pData = NULL; - // version - n += tGetI8(pData + n, NULL); + // load binary + TdFilePtr pFD = taosOpenFile(fname, TD_FILE_READ); + if (pFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + TSDB_CHECK_CODE(code, lino, _exit); + } - // SDelFile - n += tGetI8(pData + n, &hasDel); - if (hasDel) { - pTsdb->fs.pDelFile = (SDelFile *)taosMemoryMalloc(sizeof(SDelFile)); - if (pTsdb->fs.pDelFile == NULL) { + int64_t size; + if (taosFStatFile(pFD, &size, NULL) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + taosCloseFile(&pFD); + TSDB_CHECK_CODE(code, lino, _exit); + } + + pData = taosMemoryMalloc(size); + if (pData == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + taosCloseFile(&pFD); + TSDB_CHECK_CODE(code, lino, _exit); + } + + if (taosReadFile(pFD, pData, size) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + taosCloseFile(&pFD); + TSDB_CHECK_CODE(code, lino, _exit); + } + + if (!taosCheckChecksumWhole(pData, size)) { + code = TSDB_CODE_FILE_CORRUPTED; + taosCloseFile(&pFD); + TSDB_CHECK_CODE(code, lino, _exit); + } + + taosCloseFile(&pFD); + + // decode binary + code = tsdbBinaryToFS(pData, size, pFS); + TSDB_CHECK_CODE(code, lino, _exit); + +_exit: + if (pData) taosMemoryFree(pData); + if (code) { + tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname); + } + return code; +} + +static int32_t tsdbRemoveFileSet(STsdb *pTsdb, SDFileSet *pSet) { + int32_t code = 0; + char fname[TSDB_FILENAME_LEN] = {0}; + + int32_t nRef = atomic_sub_fetch_32(&pSet->pHeadF->nRef, 1); + if (nRef == 0) { + tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname); + (void)taosRemoveFile(fname); + taosMemoryFree(pSet->pHeadF); + } + + nRef = atomic_sub_fetch_32(&pSet->pDataF->nRef, 1); + if (nRef == 0) { + tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname); + (void)taosRemoveFile(fname); + taosMemoryFree(pSet->pDataF); + } + + nRef = atomic_sub_fetch_32(&pSet->pSmaF->nRef, 1); + if (nRef == 0) { + tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname); + (void)taosRemoveFile(fname); + taosMemoryFree(pSet->pSmaF); + } + + for (int8_t iStt = 0; iStt < pSet->nSttF; iStt++) { + nRef = atomic_sub_fetch_32(&pSet->aSttF[iStt]->nRef, 1); + if (nRef == 0) { + tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname); + (void)taosRemoveFile(fname); + taosMemoryFree(pSet->aSttF[iStt]); + } + } + +_exit: + return code; +} + +static int32_t tsdbNewFileSet(STsdb *pTsdb, SDFileSet *pSetTo, SDFileSet *pSetFrom) { + int32_t code = 0; + int32_t lino = 0; + + *pSetTo = (SDFileSet){.diskId = pSetFrom->diskId, .fid = pSetFrom->fid, .nSttF = 0}; + + // head + pSetTo->pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile)); + if (pSetTo->pHeadF == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } + *pSetTo->pHeadF = *pSetFrom->pHeadF; + pSetTo->pHeadF->nRef = 1; + + // data + pSetTo->pDataF = (SDataFile *)taosMemoryMalloc(sizeof(SDataFile)); + if (pSetTo->pDataF == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } + *pSetTo->pDataF = *pSetFrom->pDataF; + pSetTo->pDataF->nRef = 1; + + // sma + pSetTo->pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile)); + if (pSetTo->pSmaF == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } + *pSetTo->pSmaF = *pSetFrom->pSmaF; + pSetTo->pSmaF->nRef = 1; + + // stt + for (int32_t iStt = 0; iStt < pSetFrom->nSttF; iStt++) { + pSetTo->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); + if (pSetTo->aSttF[iStt] == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } + + pSetTo->nSttF++; + *pSetTo->aSttF[iStt] = *pSetFrom->aSttF[iStt]; + pSetTo->aSttF[iStt]->nRef = 1; + } + +_exit: + if (code) { + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + } + return code; +} + +static int32_t tsdbMergeFileSet(STsdb *pTsdb, SDFileSet *pSetOld, SDFileSet *pSetNew) { + int32_t code = 0; + int32_t lino = 0; + int32_t nRef = 0; + bool sameDisk = ((pSetOld->diskId.level == pSetNew->diskId.level) && (pSetOld->diskId.id == pSetNew->diskId.id)); + char fname[TSDB_FILENAME_LEN] = {0}; + + // head + SHeadFile *pHeadF = pSetOld->pHeadF; + if ((!sameDisk) || (pHeadF->commitID != pSetNew->pHeadF->commitID)) { + pSetOld->pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile)); + if (pSetOld->pHeadF == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } + *pSetOld->pHeadF = *pSetNew->pHeadF; + pSetOld->pHeadF->nRef = 1; + + nRef = atomic_sub_fetch_32(&pHeadF->nRef, 1); + if (nRef == 0) { + tsdbHeadFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pHeadF, fname); + (void)taosRemoveFile(fname); + taosMemoryFree(pHeadF); + } + } else { + nRef = pHeadF->nRef; + *pHeadF = *pSetNew->pHeadF; + pHeadF->nRef = nRef; + } + + // data + SDataFile *pDataF = pSetOld->pDataF; + if ((!sameDisk) || (pDataF->commitID != pSetNew->pDataF->commitID)) { + pSetOld->pDataF = (SDataFile *)taosMemoryMalloc(sizeof(SDataFile)); + if (pSetOld->pDataF == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } + *pSetOld->pDataF = *pSetNew->pDataF; + pSetOld->pDataF->nRef = 1; + + nRef = atomic_sub_fetch_32(&pDataF->nRef, 1); + if (nRef == 0) { + tsdbDataFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pDataF, fname); + (void)taosRemoveFile(fname); + taosMemoryFree(pDataF); + } + } else { + nRef = pDataF->nRef; + *pDataF = *pSetNew->pDataF; + pDataF->nRef = nRef; + } + + // sma + SSmaFile *pSmaF = pSetOld->pSmaF; + if ((!sameDisk) || (pSmaF->commitID != pSetNew->pSmaF->commitID)) { + pSetOld->pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile)); + if (pSetOld->pSmaF == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } + *pSetOld->pSmaF = *pSetNew->pSmaF; + pSetOld->pSmaF->nRef = 1; + + nRef = atomic_sub_fetch_32(&pSmaF->nRef, 1); + if (nRef == 0) { + tsdbSmaFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSmaF, fname); + (void)taosRemoveFile(fname); + taosMemoryFree(pSmaF); + } + } else { + nRef = pSmaF->nRef; + *pSmaF = *pSetNew->pSmaF; + pSmaF->nRef = nRef; + } + + // stt + if (sameDisk) { + if (pSetNew->nSttF > pSetOld->nSttF) { + ASSERT(pSetNew->nSttF == pSetOld->nSttF + 1); + pSetOld->aSttF[pSetOld->nSttF] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); + if (pSetOld->aSttF[pSetOld->nSttF] == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } + *pSetOld->aSttF[pSetOld->nSttF] = *pSetNew->aSttF[pSetOld->nSttF]; + pSetOld->aSttF[pSetOld->nSttF]->nRef = 1; + pSetOld->nSttF++; + } else if (pSetNew->nSttF < pSetOld->nSttF) { + ASSERT(pSetNew->nSttF == 1); + for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) { + SSttFile *pSttFile = pSetOld->aSttF[iStt]; + nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1); + if (nRef == 0) { + tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname); + (void)taosRemoveFile(fname); + taosMemoryFree(pSttFile); + } + pSetOld->aSttF[iStt] = NULL; + } + + pSetOld->nSttF = 1; + pSetOld->aSttF[0] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); + if (pSetOld->aSttF[0] == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } + *pSetOld->aSttF[0] = *pSetNew->aSttF[0]; + pSetOld->aSttF[0]->nRef = 1; + } else { + for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) { + if (pSetOld->aSttF[iStt]->commitID != pSetNew->aSttF[iStt]->commitID) { + SSttFile *pSttFile = pSetOld->aSttF[iStt]; + nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1); + if (nRef == 0) { + tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname); + (void)taosRemoveFile(fname); + taosMemoryFree(pSttFile); + } + + pSetOld->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); + if (pSetOld->aSttF[iStt] == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } + *pSetOld->aSttF[iStt] = *pSetNew->aSttF[iStt]; + pSetOld->aSttF[iStt]->nRef = 1; + } else { + ASSERT(pSetOld->aSttF[iStt]->size == pSetOld->aSttF[iStt]->size); + ASSERT(pSetOld->aSttF[iStt]->offset == pSetOld->aSttF[iStt]->offset); + } + } + } + } else { + for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) { + SSttFile *pSttFile = pSetOld->aSttF[iStt]; + nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1); + if (nRef == 0) { + tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname); + (void)taosRemoveFile(fname); + taosMemoryFree(pSttFile); + } + } + + pSetOld->nSttF = 0; + for (int32_t iStt = 0; iStt < pSetNew->nSttF; iStt++) { + pSetOld->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); + if (pSetOld->aSttF[iStt] == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } + + *pSetOld->aSttF[iStt] = *pSetNew->aSttF[iStt]; + pSetOld->aSttF[iStt]->nRef = 1; + + pSetOld->nSttF++; + } + } + + if (!sameDisk) { + pSetOld->diskId = pSetNew->diskId; + } + +_exit: + if (code) { + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + } + return code; +} + +static int32_t tsdbFSApplyChange(STsdb *pTsdb, STsdbFS *pFS) { + int32_t code = 0; + int32_t lino = 0; + + int32_t nRef = 0; + char fname[TSDB_FILENAME_LEN] = {0}; + + // SDelFile + if (pFS->pDelFile) { + SDelFile *pDelFile = pTsdb->fs.pDelFile; + + if (pDelFile == NULL || (pDelFile->commitID != pFS->pDelFile->commitID)) { + pTsdb->fs.pDelFile = (SDelFile *)taosMemoryMalloc(sizeof(SDelFile)); + if (pTsdb->fs.pDelFile == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } + + *pTsdb->fs.pDelFile = *pFS->pDelFile; + pTsdb->fs.pDelFile->nRef = 1; + + if (pDelFile) { + nRef = atomic_sub_fetch_32(&pDelFile->nRef, 1); + if (nRef == 0) { + tsdbDelFileName(pTsdb, pDelFile, fname); + (void)taosRemoveFile(fname); + taosMemoryFree(pDelFile); + } + } + } + } else { + ASSERT(pTsdb->fs.pDelFile == NULL); + } + + // aDFileSet + int32_t iOld = 0; + int32_t iNew = 0; + while (true) { + int32_t nOld = taosArrayGetSize(pTsdb->fs.aDFileSet); + int32_t nNew = taosArrayGetSize(pFS->aDFileSet); + SDFileSet fSet = {0}; + int8_t sameDisk = 0; + + if (iOld >= nOld && iNew >= nNew) break; + + SDFileSet *pSetOld = (iOld < nOld) ? taosArrayGet(pTsdb->fs.aDFileSet, iOld) : NULL; + SDFileSet *pSetNew = (iNew < nNew) ? taosArrayGet(pFS->aDFileSet, iNew) : NULL; + + if (pSetOld && pSetNew) { + if (pSetOld->fid == pSetNew->fid) { + code = tsdbMergeFileSet(pTsdb, pSetOld, pSetNew); + TSDB_CHECK_CODE(code, lino, _exit); - pTsdb->fs.pDelFile->nRef = 1; - n += tGetDelFile(pData + n, pTsdb->fs.pDelFile); - } else { - pTsdb->fs.pDelFile = NULL; - } + iOld++; + iNew++; + } else if (pSetOld->fid < pSetNew->fid) { + code = tsdbRemoveFileSet(pTsdb, pSetOld); + TSDB_CHECK_CODE(code, lino, _exit); + taosArrayRemove(pTsdb->fs.aDFileSet, iOld); + } else { + code = tsdbNewFileSet(pTsdb, &fSet, pSetNew); + TSDB_CHECK_CODE(code, lino, _exit) - // SArray - taosArrayClear(pTsdb->fs.aDFileSet); - n += tGetU32v(pData + n, &nSet); - for (uint32_t iSet = 0; iSet < nSet; iSet++) { - SDFileSet fSet = {0}; + if (taosArrayInsert(pTsdb->fs.aDFileSet, iOld, &fSet) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } - int32_t nt = tGetDFileSet(pData + n, &fSet); - if (nt < 0) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } + iOld++; + iNew++; + } + } else if (pSetOld) { + code = tsdbRemoveFileSet(pTsdb, pSetOld); + TSDB_CHECK_CODE(code, lino, _exit); + taosArrayRemove(pTsdb->fs.aDFileSet, iOld); + } else { + code = tsdbNewFileSet(pTsdb, &fSet, pSetNew); + TSDB_CHECK_CODE(code, lino, _exit) - n += nt; + if (taosArrayInsert(pTsdb->fs.aDFileSet, iOld, &fSet) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } - if (taosArrayPush(pTsdb->fs.aDFileSet, &fSet) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + iOld++; + iNew++; } } - ASSERT(n + sizeof(TSCKSUM) == nData); - return code; - -_err: +_exit: + if (code) { + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + } return code; } // EXPOSED APIS ==================================================================================== -int32_t tsdbFSOpen(STsdb *pTsdb) { +int32_t tsdbFSCommit(STsdb *pTsdb) { int32_t code = 0; - SVnode *pVnode = pTsdb->pVnode; + int32_t lino = 0; + STsdbFS fs = {0}; - // open handle - pTsdb->fs.pDelFile = NULL; - pTsdb->fs.aDFileSet = taosArrayInit(0, sizeof(SDFileSet)); - if (pTsdb->fs.aDFileSet == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } + char current[TSDB_FILENAME_LEN] = {0}; + char current_t[TSDB_FILENAME_LEN] = {0}; + tsdbGetCurrentFName(pTsdb, current, current_t); - // load fs or keep empty - char fname[TSDB_FILENAME_LEN]; + if (!taosCheckExistFile(current_t)) goto _exit; - if (pVnode->pTfs) { - snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP, - pTsdb->path, TD_DIRSEP); - } else { - snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%sCURRENT", pTsdb->path, TD_DIRSEP); + // rename the file + if (taosRenameFile(current_t, current) < 0) { + code = TAOS_SYSTEM_ERROR(errno); + TSDB_CHECK_CODE(code, lino, _exit); } - if (!taosCheckExistFile(fname)) { - // empty one - code = tsdbGnrtCurrent(pTsdb, &pTsdb->fs, fname); - if (code) goto _err; - } else { - // read - TdFilePtr pFD = taosOpenFile(fname, TD_FILE_READ); - if (pFD == NULL) { - code = TAOS_SYSTEM_ERROR(errno); - goto _err; - } + // Load the new FS + code = tsdbFSCreate(&fs); + TSDB_CHECK_CODE(code, lino, _exit); - int64_t size; - if (taosFStatFile(pFD, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); - taosCloseFile(&pFD); - goto _err; - } + code = tsdbLoadFSFromFile(current, &fs); + TSDB_CHECK_CODE(code, lino, _exit); - uint8_t *pData = taosMemoryMalloc(size); - if (pData == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - taosCloseFile(&pFD); - goto _err; - } + // apply file change + code = tsdbFSApplyChange(pTsdb, &fs); + TSDB_CHECK_CODE(code, lino, _exit); - int64_t n = taosReadFile(pFD, pData, size); - if (n < 0) { - code = TAOS_SYSTEM_ERROR(errno); - taosMemoryFree(pData); - taosCloseFile(&pFD); - goto _err; - } +_exit: + tsdbFSDestroy(&fs); + if (code) { + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + } + return code; +} - if (!taosCheckChecksumWhole(pData, size)) { - code = TSDB_CODE_FILE_CORRUPTED; - taosMemoryFree(pData); - taosCloseFile(&pFD); - goto _err; - } +int32_t tsdbFSRollback(STsdb *pTsdb) { + int32_t code = 0; + int32_t lino = 0; - taosCloseFile(&pFD); + char current_t[TSDB_FILENAME_LEN] = {0}; + tsdbGetCurrentFName(pTsdb, NULL, current_t); + (void)taosRemoveFile(current_t); + +_exit: + if (code) { + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(errno)); + } + return code; +} - // recover fs - code = tsdbRecoverFS(pTsdb, pData, size); - if (code) { - taosMemoryFree(pData); - goto _err; +int32_t tsdbFSOpen(STsdb *pTsdb, int8_t rollback) { + int32_t code = 0; + int32_t lino = 0; + SVnode *pVnode = pTsdb->pVnode; + + // open handle + code = tsdbFSCreate(&pTsdb->fs); + TSDB_CHECK_CODE(code, lino, _exit); + + // open impl + char current[TSDB_FILENAME_LEN] = {0}; + char current_t[TSDB_FILENAME_LEN] = {0}; + tsdbGetCurrentFName(pTsdb, current, current_t); + + if (taosCheckExistFile(current)) { + code = tsdbLoadFSFromFile(current, &pTsdb->fs); + TSDB_CHECK_CODE(code, lino, _exit); + + if (taosCheckExistFile(current_t)) { + if (rollback) { + code = tsdbFSRollback(pTsdb); + TSDB_CHECK_CODE(code, lino, _exit); + } else { + code = tsdbFSCommit(pTsdb); + TSDB_CHECK_CODE(code, lino, _exit); + } } + } else { + // empty one + code = tsdbSaveFSToFile(&pTsdb->fs, current); + TSDB_CHECK_CODE(code, lino, _exit); - taosMemoryFree(pData); + ASSERT(!rollback); } // scan and fix FS code = tsdbScanAndTryFixFS(pTsdb); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); - return code; - -_err: - tsdbError("vgId:%d, tsdb fs open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); +_exit: + if (code) { + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + } return code; } @@ -538,19 +834,24 @@ int32_t tsdbFSClose(STsdb *pTsdb) { int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) { int32_t code = 0; + int32_t lino = 0; pFS->pDelFile = NULL; - pFS->aDFileSet = taosArrayInit(taosArrayGetSize(pTsdb->fs.aDFileSet), sizeof(SDFileSet)); - if (pFS->aDFileSet == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; + if (pFS->aDFileSet) { + taosArrayClear(pFS->aDFileSet); + } else { + pFS->aDFileSet = taosArrayInit(taosArrayGetSize(pTsdb->fs.aDFileSet), sizeof(SDFileSet)); + if (pFS->aDFileSet == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit); + } } if (pTsdb->fs.pDelFile) { pFS->pDelFile = (SDelFile *)taosMemoryMalloc(sizeof(SDelFile)); if (pFS->pDelFile == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; + TSDB_CHECK_CODE(code, lino, _exit); } *pFS->pDelFile = *pTsdb->fs.pDelFile; @@ -564,7 +865,7 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) { fSet.pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile)); if (fSet.pHeadF == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; + TSDB_CHECK_CODE(code, lino, _exit); } *fSet.pHeadF = *pSet->pHeadF; @@ -572,7 +873,7 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) { fSet.pDataF = (SDataFile *)taosMemoryMalloc(sizeof(SDataFile)); if (fSet.pDataF == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; + TSDB_CHECK_CODE(code, lino, _exit); } *fSet.pDataF = *pSet->pDataF; @@ -580,7 +881,7 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) { fSet.pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile)); if (fSet.pSmaF == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; + TSDB_CHECK_CODE(code, lino, _exit); } *fSet.pSmaF = *pSet->pSmaF; @@ -589,26 +890,21 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) { fSet.aSttF[fSet.nSttF] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); if (fSet.aSttF[fSet.nSttF] == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; + TSDB_CHECK_CODE(code, lino, _exit); } *fSet.aSttF[fSet.nSttF] = *pSet->aSttF[fSet.nSttF]; } if (taosArrayPush(pFS->aDFileSet, &fSet) == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; + TSDB_CHECK_CODE(code, lino, _exit); } } _exit: - return code; -} - -int32_t tsdbFSRollback(STsdbFS *pFS) { - int32_t code = 0; - - ASSERT(0); - + if (code) { + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + } return code; } @@ -714,336 +1010,21 @@ _exit: return code; } -int32_t tsdbFSCommit1(STsdb *pTsdb, STsdbFS *pFSNew) { +int32_t tsdbFSPrepareCommit(STsdb *pTsdb, STsdbFS *pFSNew) { int32_t code = 0; + int32_t lino = 0; char tfname[TSDB_FILENAME_LEN]; - char fname[TSDB_FILENAME_LEN]; - snprintf(tfname, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT.t", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP, - pTsdb->path, TD_DIRSEP); - snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP, - pTsdb->path, TD_DIRSEP); + tsdbGetCurrentFName(pTsdb, NULL, tfname); // gnrt CURRENT.t - code = tsdbGnrtCurrent(pTsdb, pFSNew, tfname); - if (code) goto _err; + code = tsdbSaveFSToFile(pFSNew, tfname); + TSDB_CHECK_CODE(code, lino, _exit); - // rename - code = taosRenameFile(tfname, fname); +_exit: if (code) { - code = TAOS_SYSTEM_ERROR(code); - goto _err; - } - - return code; - -_err: - tsdbError("vgId:%d, tsdb fs commit phase 1 failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); - return code; -} - -int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) { - int32_t code = 0; - int32_t nRef; - char fname[TSDB_FILENAME_LEN]; - - // del - if (pFSNew->pDelFile) { - SDelFile *pDelFile = pTsdb->fs.pDelFile; - - if (pDelFile == NULL || (pDelFile->commitID != pFSNew->pDelFile->commitID)) { - pTsdb->fs.pDelFile = (SDelFile *)taosMemoryMalloc(sizeof(SDelFile)); - if (pTsdb->fs.pDelFile == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - - *pTsdb->fs.pDelFile = *pFSNew->pDelFile; - pTsdb->fs.pDelFile->nRef = 1; - - if (pDelFile) { - nRef = atomic_sub_fetch_32(&pDelFile->nRef, 1); - if (nRef == 0) { - tsdbDelFileName(pTsdb, pDelFile, fname); - taosRemoveFile(fname); - taosMemoryFree(pDelFile); - } - } - } - } else { - ASSERT(pTsdb->fs.pDelFile == NULL); - } - - // data - int32_t iOld = 0; - int32_t iNew = 0; - while (true) { - int32_t nOld = taosArrayGetSize(pTsdb->fs.aDFileSet); - int32_t nNew = taosArrayGetSize(pFSNew->aDFileSet); - SDFileSet fSet; - int8_t sameDisk; - - if (iOld >= nOld && iNew >= nNew) break; - - SDFileSet *pSetOld = (iOld < nOld) ? taosArrayGet(pTsdb->fs.aDFileSet, iOld) : NULL; - SDFileSet *pSetNew = (iNew < nNew) ? taosArrayGet(pFSNew->aDFileSet, iNew) : NULL; - - if (pSetOld && pSetNew) { - if (pSetOld->fid == pSetNew->fid) { - goto _merge_old_and_new; - } else if (pSetOld->fid < pSetNew->fid) { - goto _remove_old; - } else { - goto _add_new; - } - } else if (pSetOld) { - goto _remove_old; - } else { - goto _add_new; - } - - _merge_old_and_new: - sameDisk = ((pSetOld->diskId.level == pSetNew->diskId.level) && (pSetOld->diskId.id == pSetNew->diskId.id)); - - // head - fSet.pHeadF = pSetOld->pHeadF; - if ((!sameDisk) || (pSetOld->pHeadF->commitID != pSetNew->pHeadF->commitID)) { - pSetOld->pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile)); - if (pSetOld->pHeadF == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - *pSetOld->pHeadF = *pSetNew->pHeadF; - pSetOld->pHeadF->nRef = 1; - - nRef = atomic_sub_fetch_32(&fSet.pHeadF->nRef, 1); - if (nRef == 0) { - tsdbHeadFileName(pTsdb, pSetOld->diskId, pSetOld->fid, fSet.pHeadF, fname); - (void)taosRemoveFile(fname); - taosMemoryFree(fSet.pHeadF); - } - } else { - ASSERT(fSet.pHeadF->size == pSetNew->pHeadF->size); - ASSERT(fSet.pHeadF->offset == pSetNew->pHeadF->offset); - } - - // data - fSet.pDataF = pSetOld->pDataF; - if ((!sameDisk) || (pSetOld->pDataF->commitID != pSetNew->pDataF->commitID)) { - pSetOld->pDataF = (SDataFile *)taosMemoryMalloc(sizeof(SDataFile)); - if (pSetOld->pDataF == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - *pSetOld->pDataF = *pSetNew->pDataF; - pSetOld->pDataF->nRef = 1; - - nRef = atomic_sub_fetch_32(&fSet.pDataF->nRef, 1); - if (nRef == 0) { - tsdbDataFileName(pTsdb, pSetOld->diskId, pSetOld->fid, fSet.pDataF, fname); - taosRemoveFile(fname); - taosMemoryFree(fSet.pDataF); - } - } else { - ASSERT(pSetOld->pDataF->size <= pSetNew->pDataF->size); - pSetOld->pDataF->size = pSetNew->pDataF->size; - } - - // sma - fSet.pSmaF = pSetOld->pSmaF; - if ((!sameDisk) || (pSetOld->pSmaF->commitID != pSetNew->pSmaF->commitID)) { - pSetOld->pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile)); - if (pSetOld->pSmaF == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - *pSetOld->pSmaF = *pSetNew->pSmaF; - pSetOld->pSmaF->nRef = 1; - - nRef = atomic_sub_fetch_32(&fSet.pSmaF->nRef, 1); - if (nRef == 0) { - tsdbSmaFileName(pTsdb, pSetOld->diskId, pSetOld->fid, fSet.pSmaF, fname); - (void)taosRemoveFile(fname); - taosMemoryFree(fSet.pSmaF); - } - } else { - ASSERT(pSetOld->pSmaF->size <= pSetNew->pSmaF->size); - pSetOld->pSmaF->size = pSetNew->pSmaF->size; - } - - // stt - if (sameDisk) { - if (pSetNew->nSttF > pSetOld->nSttF) { - ASSERT(pSetNew->nSttF == pSetOld->nSttF + 1); - pSetOld->aSttF[pSetOld->nSttF] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); - if (pSetOld->aSttF[pSetOld->nSttF] == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - *pSetOld->aSttF[pSetOld->nSttF] = *pSetNew->aSttF[pSetOld->nSttF]; - pSetOld->aSttF[pSetOld->nSttF]->nRef = 1; - pSetOld->nSttF++; - } else if (pSetNew->nSttF < pSetOld->nSttF) { - ASSERT(pSetNew->nSttF == 1); - for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) { - SSttFile *pSttFile = pSetOld->aSttF[iStt]; - nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1); - if (nRef == 0) { - tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname); - taosRemoveFile(fname); - taosMemoryFree(pSttFile); - } - pSetOld->aSttF[iStt] = NULL; - } - - pSetOld->nSttF = 1; - pSetOld->aSttF[0] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); - if (pSetOld->aSttF[0] == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - *pSetOld->aSttF[0] = *pSetNew->aSttF[0]; - pSetOld->aSttF[0]->nRef = 1; - } else { - for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) { - if (pSetOld->aSttF[iStt]->commitID != pSetNew->aSttF[iStt]->commitID) { - SSttFile *pSttFile = pSetOld->aSttF[iStt]; - nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1); - if (nRef == 0) { - tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname); - taosRemoveFile(fname); - taosMemoryFree(pSttFile); - } - - pSetOld->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); - if (pSetOld->aSttF[iStt] == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - *pSetOld->aSttF[iStt] = *pSetNew->aSttF[iStt]; - pSetOld->aSttF[iStt]->nRef = 1; - } else { - ASSERT(pSetOld->aSttF[iStt]->size == pSetOld->aSttF[iStt]->size); - ASSERT(pSetOld->aSttF[iStt]->offset == pSetOld->aSttF[iStt]->offset); - } - } - } - } else { - ASSERT(pSetOld->nSttF == pSetNew->nSttF); - for (int32_t iStt = 0; iStt < pSetOld->nSttF; iStt++) { - SSttFile *pSttFile = pSetOld->aSttF[iStt]; - nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1); - if (nRef == 0) { - tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname); - taosRemoveFile(fname); - taosMemoryFree(pSttFile); - } - - pSetOld->aSttF[iStt] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); - if (pSetOld->aSttF[iStt] == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - *pSetOld->aSttF[iStt] = *pSetNew->aSttF[iStt]; - pSetOld->aSttF[iStt]->nRef = 1; - } - } - - if (!sameDisk) { - pSetOld->diskId = pSetNew->diskId; - } - - iOld++; - iNew++; - continue; - - _remove_old: - nRef = atomic_sub_fetch_32(&pSetOld->pHeadF->nRef, 1); - if (nRef == 0) { - tsdbHeadFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->pHeadF, fname); - (void)taosRemoveFile(fname); - taosMemoryFree(pSetOld->pHeadF); - } - - nRef = atomic_sub_fetch_32(&pSetOld->pDataF->nRef, 1); - if (nRef == 0) { - tsdbDataFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->pDataF, fname); - taosRemoveFile(fname); - taosMemoryFree(pSetOld->pDataF); - } - - nRef = atomic_sub_fetch_32(&pSetOld->pSmaF->nRef, 1); - if (nRef == 0) { - tsdbSmaFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->pSmaF, fname); - taosRemoveFile(fname); - taosMemoryFree(pSetOld->pSmaF); - } - - for (int8_t iStt = 0; iStt < pSetOld->nSttF; iStt++) { - nRef = atomic_sub_fetch_32(&pSetOld->aSttF[iStt]->nRef, 1); - if (nRef == 0) { - tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->aSttF[iStt], fname); - taosRemoveFile(fname); - taosMemoryFree(pSetOld->aSttF[iStt]); - } - } - - taosArrayRemove(pTsdb->fs.aDFileSet, iOld); - continue; - - _add_new: - fSet = (SDFileSet){.diskId = pSetNew->diskId, .fid = pSetNew->fid, .nSttF = 1}; - - // head - fSet.pHeadF = (SHeadFile *)taosMemoryMalloc(sizeof(SHeadFile)); - if (fSet.pHeadF == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - *fSet.pHeadF = *pSetNew->pHeadF; - fSet.pHeadF->nRef = 1; - - // data - fSet.pDataF = (SDataFile *)taosMemoryMalloc(sizeof(SDataFile)); - if (fSet.pDataF == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - *fSet.pDataF = *pSetNew->pDataF; - fSet.pDataF->nRef = 1; - - // sma - fSet.pSmaF = (SSmaFile *)taosMemoryMalloc(sizeof(SSmaFile)); - if (fSet.pSmaF == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - *fSet.pSmaF = *pSetNew->pSmaF; - fSet.pSmaF->nRef = 1; - - // stt - ASSERT(pSetNew->nSttF == 1); - fSet.aSttF[0] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); - if (fSet.aSttF[0] == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - *fSet.aSttF[0] = *pSetNew->aSttF[0]; - fSet.aSttF[0]->nRef = 1; - - if (taosArrayInsert(pTsdb->fs.aDFileSet, iOld, &fSet) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - iOld++; - iNew++; - continue; + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); } - - return code; - -_err: - tsdbError("vgId:%d, tsdb fs commit phase 2 failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); return code; } @@ -1123,7 +1104,7 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) { ASSERT(nRef >= 0); if (nRef == 0) { tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname); - taosRemoveFile(fname); + (void)taosRemoveFile(fname); taosMemoryFree(pSet->pDataF); } @@ -1132,7 +1113,7 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) { ASSERT(nRef >= 0); if (nRef == 0) { tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname); - taosRemoveFile(fname); + (void)taosRemoveFile(fname); taosMemoryFree(pSet->pSmaF); } @@ -1142,7 +1123,7 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) { ASSERT(nRef >= 0); if (nRef == 0) { tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname); - taosRemoveFile(fname); + (void)taosRemoveFile(fname); taosMemoryFree(pSet->aSttF[iStt]); /* code */ } diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index 2f4fdfc5f8882d6b69425d0f9c14853424c36eb3..92de870d4d41cedb05ddf80f931699c5eacc7e53 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -120,44 +120,46 @@ static SBlockData *loadLastBlock(SLDataIter *pIter, const char *idStr) { return &pInfo->blockData[1]; } - pInfo->currentLoadBlockIndex ^= 1; - if (pIter->pSttBlk != NULL) { // current block not loaded yet - int64_t st = taosGetTimestampUs(); + if (pIter->pSttBlk == NULL) { + return NULL; + } - SBlockData *pBlock = &pInfo->blockData[pInfo->currentLoadBlockIndex]; + // current block not loaded yet + pInfo->currentLoadBlockIndex ^= 1; + int64_t st = taosGetTimestampUs(); - TABLEID id = {0}; - if (pIter->pSttBlk->suid != 0) { - id.suid = pIter->pSttBlk->suid; - } else { - id.uid = pIter->uid; - } + SBlockData *pBlock = &pInfo->blockData[pInfo->currentLoadBlockIndex]; - code = tBlockDataInit(pBlock, &id, pInfo->pSchema, pInfo->colIds, pInfo->numOfCols); - if (code != TSDB_CODE_SUCCESS) { - goto _exit; - } + TABLEID id = {0}; + if (pIter->pSttBlk->suid != 0) { + id.suid = pIter->pSttBlk->suid; + } else { + id.uid = pIter->uid; + } - code = tsdbReadSttBlock(pIter->pReader, pIter->iStt, pIter->pSttBlk, pBlock); - if (code != TSDB_CODE_SUCCESS) { - goto _exit; - } + code = tBlockDataInit(pBlock, &id, pInfo->pSchema, pInfo->colIds, pInfo->numOfCols); + if (code != TSDB_CODE_SUCCESS) { + goto _exit; + } - double el = (taosGetTimestampUs() - st) / 1000.0; - pInfo->elapsedTime += el; - pInfo->loadBlocks += 1; + code = tsdbReadSttBlock(pIter->pReader, pIter->iStt, pIter->pSttBlk, pBlock); + if (code != TSDB_CODE_SUCCESS) { + goto _exit; + } - tsdbDebug("read last block, total load:%d, trigger by uid:%" PRIu64 - ", last file index:%d, last block index:%d, entry:%d, %p, elapsed time:%.2f ms, %s", - pInfo->loadBlocks, pIter->uid, pIter->iStt, pIter->iSttBlk, pInfo->currentLoadBlockIndex, pBlock, el, - idStr); + double el = (taosGetTimestampUs() - st) / 1000.0; + pInfo->elapsedTime += el; + pInfo->loadBlocks += 1; - pInfo->blockIndex[pInfo->currentLoadBlockIndex] = pIter->iSttBlk; - tsdbDebug("last block index list:%d, %d, %s", pInfo->blockIndex[0], pInfo->blockIndex[1], idStr); + tsdbDebug("read last block, total load:%d, trigger by uid:%" PRIu64 + ", last file index:%d, last block index:%d, entry:%d, %p, elapsed time:%.2f ms, %s", + pInfo->loadBlocks, pIter->uid, pIter->iStt, pIter->iSttBlk, pInfo->currentLoadBlockIndex, pBlock, el, + idStr); - pIter->iRow = (pIter->backward) ? pInfo->blockData[pInfo->currentLoadBlockIndex].nRow : -1; - } + pInfo->blockIndex[pInfo->currentLoadBlockIndex] = pIter->iSttBlk; + tsdbDebug("last block index list:%d, %d, %s", pInfo->blockIndex[0], pInfo->blockIndex[1], idStr); + pIter->iRow = (pIter->backward) ? pInfo->blockData[pInfo->currentLoadBlockIndex].nRow : -1; return &pInfo->blockData[pInfo->currentLoadBlockIndex]; _exit: @@ -259,7 +261,8 @@ static int32_t binarySearchForStartRowIndex(uint64_t *uidList, int32_t num, uint int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t iStt, int8_t backward, uint64_t suid, uint64_t uid, STimeWindow *pTimeWindow, SVersionRange *pRange, SSttBlockLoadInfo *pBlockLoadInfo, const char *idStr) { - int32_t code = 0; + int32_t code = TSDB_CODE_SUCCESS; + *pIter = taosMemoryCalloc(1, sizeof(SLDataIter)); if (*pIter == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -336,7 +339,10 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t (*pIter)->iRow = ((*pIter)->backward) ? (*pIter)->pSttBlk->nRow : -1; } + return code; + _exit: + taosMemoryFree(*pIter); return code; } @@ -473,7 +479,7 @@ bool tLDataIterNextRow(SLDataIter *pIter, const char *idStr) { int32_t iBlockL = pIter->iSttBlk; SBlockData *pBlockData = loadLastBlock(pIter, idStr); - if (pBlockData == NULL && terrno != TSDB_CODE_SUCCESS) { + if (pBlockData == NULL || terrno != TSDB_CODE_SUCCESS) { goto _exit; } @@ -530,6 +536,10 @@ static FORCE_INLINE int32_t tLDataIterCmprFn(const SRBTreeNode *p1, const SRBTre } } +static FORCE_INLINE int32_t tLDataIterDescCmprFn(const SRBTreeNode *p1, const SRBTreeNode *p2) { + return -1 * tLDataIterCmprFn(p1, p2); +} + int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFReader, uint64_t suid, uint64_t uid, STimeWindow *pTimeWindow, SVersionRange *pVerRange, SSttBlockLoadInfo *pBlockLoadInfo, bool destroyLoadInfo, const char *idStr) { @@ -541,8 +551,11 @@ int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFRead } pMTree->idStr = idStr; - - tRBTreeCreate(&pMTree->rbt, tLDataIterCmprFn); + if (!pMTree->backward) { // asc + tRBTreeCreate(&pMTree->rbt, tLDataIterCmprFn); + } else { // desc + tRBTreeCreate(&pMTree->rbt, tLDataIterDescCmprFn); + } int32_t code = TSDB_CODE_SUCCESS; pMTree->pLoadInfo = pBlockLoadInfo; diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c index 51978234901a6a4e26f78d0c7d867818d64fa7eb..efc74b68ba31db362441002589998d6ed04cfde9 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOpen.c +++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c @@ -33,7 +33,7 @@ int32_t tsdbSetKeepCfg(STsdb *pTsdb, STsdbCfg *pCfg) { * @param dir * @return int */ -int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKeepCfg) { +int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKeepCfg, int8_t rollback) { STsdb *pTsdb = NULL; int slen = 0; @@ -66,7 +66,7 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee } // open tsdb - if (tsdbFSOpen(pTsdb) < 0) { + if (tsdbFSOpen(pTsdb, rollback) < 0) { goto _err; } diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 3f88d478e292df6f092a774416f8c8865ac015e9..257a7d0baa4dc71f5b2b05fe672c5f7f3ead6f7b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -340,7 +340,7 @@ static int32_t initFilesetIterator(SFilesetIter* pIter, SArray* aDFileSet, STsdb pIter->pLastBlockReader = taosMemoryCalloc(1, sizeof(struct SLastBlockReader)); if (pIter->pLastBlockReader == NULL) { int32_t code = TSDB_CODE_OUT_OF_MEMORY; - tsdbError("failed to prepare the last block iterator, code:%s %s", tstrerror(code), pReader->idStr); + tsdbError("failed to prepare the last block iterator, since:%s %s", tstrerror(code), pReader->idStr); return code; } } @@ -645,11 +645,11 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN int32_t total = pBlockNum->numOfLastFiles + pBlockNum->numOfBlocks; double el = (taosGetTimestampUs() - st) / 1000.0; - tsdbDebug("load block of %" PRIzu - " tables completed, blocks:%d in %d tables, last-files:%d, block-info-size:%.2f Kb, elapsed " - "time:%.2f ms %s", - numOfTables, pBlockNum->numOfBlocks, numOfQTable, pBlockNum->numOfLastFiles, sizeInDisk / 1000.0, el, - pReader->idStr); + tsdbDebug( + "load block of %ld tables completed, blocks:%d in %d tables, last-files:%d, block-info-size:%.2f Kb, elapsed " + "time:%.2f ms %s", + numOfTables, pBlockNum->numOfBlocks, numOfQTable, pBlockNum->numOfLastFiles, sizeInDisk / 1000.0, el, + pReader->idStr); pReader->cost.numOfBlocks += total; pReader->cost.headFileLoadTime += el; @@ -1047,11 +1047,16 @@ static int32_t fileDataBlockOrderCompar(const void* pLeft, const void* pRight, v return pLeftBlock->offset > pRightBlock->offset ? 1 : -1; } -static int32_t doSetCurrentBlock(SDataBlockIter* pBlockIter) { +static int32_t doSetCurrentBlock(SDataBlockIter* pBlockIter, const char* idStr) { SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter); if (pBlockInfo != NULL) { STableBlockScanInfo* pScanInfo = taosHashGet(pBlockIter->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid)); - int32_t* mapDataIndex = taosArrayGet(pScanInfo->pBlockList, pBlockInfo->tbBlockIdx); + if (pScanInfo == NULL) { + tsdbError("failed to locate the uid:%"PRIu64" in query table uid list, %s", pBlockInfo->uid, idStr); + return TSDB_CODE_INVALID_PARA; + } + + int32_t* mapDataIndex = taosArrayGet(pScanInfo->pBlockList, pBlockInfo->tbBlockIdx); tMapDataGetItemByIdx(&pScanInfo->mapData, *mapDataIndex, &pBlockIter->block, tGetDataBlk); } @@ -1135,7 +1140,7 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte pBlockIter->index = asc ? 0 : (numOfBlocks - 1); cleanupBlockOrderSupporter(&sup); - doSetCurrentBlock(pBlockIter); + doSetCurrentBlock(pBlockIter, pReader->idStr); return TSDB_CODE_SUCCESS; } @@ -1175,12 +1180,12 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte taosMemoryFree(pTree); pBlockIter->index = asc ? 0 : (numOfBlocks - 1); - doSetCurrentBlock(pBlockIter); + doSetCurrentBlock(pBlockIter, pReader->idStr); return TSDB_CODE_SUCCESS; } -static bool blockIteratorNext(SDataBlockIter* pBlockIter) { +static bool blockIteratorNext(SDataBlockIter* pBlockIter, const char* idStr) { bool asc = ASCENDING_TRAVERSE(pBlockIter->order); int32_t step = asc ? 1 : -1; @@ -1189,7 +1194,7 @@ static bool blockIteratorNext(SDataBlockIter* pBlockIter) { } pBlockIter->index += step; - doSetCurrentBlock(pBlockIter); + doSetCurrentBlock(pBlockIter, idStr); return true; } @@ -1260,7 +1265,7 @@ static int32_t setFileBlockActiveInBlockIter(SDataBlockIter* pBlockIter, int32_t ASSERT(pBlockInfo->uid == fblock.uid && pBlockInfo->tbBlockIdx == fblock.tbBlockIdx); } - doSetCurrentBlock(pBlockIter); + doSetCurrentBlock(pBlockIter, ""); return TSDB_CODE_SUCCESS; } @@ -1518,9 +1523,9 @@ static FORCE_INLINE STSchema* doGetSchemaForTSRow(int32_t sversion, STsdbReader* return pReader->pMemSchema; } - taosMemoryFree(pReader->pMemSchema); + taosMemoryFreeClear(pReader->pMemSchema); int32_t code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, sversion, &pReader->pMemSchema); - if (code != TSDB_CODE_SUCCESS) { + if (code != TSDB_CODE_SUCCESS || pReader->pMemSchema == NULL) { terrno = code; return NULL; } else { @@ -1886,6 +1891,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* } else { init = true; STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid); + if (pSchema == NULL) { + return code; + } + code = tRowMergerInit(&merge, piRow, pSchema); if (code != TSDB_CODE_SUCCESS) { return code; @@ -2190,6 +2199,8 @@ static int32_t buildComposedDataBlockImpl(STsdbReader* pReader, STableBlockScanI } static int32_t buildComposedDataBlock(STsdbReader* pReader) { + int32_t code = TSDB_CODE_SUCCESS; + SSDataBlock* pResBlock = pReader->pResBlock; SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pReader->status.blockIter); @@ -2200,6 +2211,13 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) { STableBlockScanInfo* pBlockScanInfo = NULL; if (pBlockInfo != NULL) { pBlockScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid)); + if (pBlockScanInfo == NULL) { + code = TSDB_CODE_INVALID_PARA; + tsdbError("failed to locate the uid:%"PRIu64" in query table uid list, total tables:%d, %s", + pBlockInfo->uid, taosHashGetSize(pReader->status.pTableMap), pReader->idStr); + goto _end; + } + SDataBlk* pBlock = getCurrentBlock(&pReader->status.blockIter); TSDBKEY keyInBuf = getCurrentKeyInBuf(pBlockScanInfo, pReader); @@ -2260,7 +2278,7 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) { } _end: - pResBlock->info.uid = pBlockScanInfo->uid; + pResBlock->info.uid = (pBlockScanInfo != NULL)? pBlockScanInfo->uid:0; blockDataUpdateTsWindow(pResBlock, 0); setComposedBlockFlag(pReader, true); @@ -2272,11 +2290,11 @@ _end: if (pResBlock->info.rows > 0) { tsdbDebug("%p uid:%" PRIu64 ", composed data block created, brange:%" PRIu64 "-%" PRIu64 " rows:%d, elapsed time:%.2f ms %s", - pReader, pBlockScanInfo->uid, pResBlock->info.window.skey, pResBlock->info.window.ekey, + pReader, pResBlock->info.uid, pResBlock->info.window.skey, pResBlock->info.window.ekey, pResBlock->info.rows, el, pReader->idStr); } - return TSDB_CODE_SUCCESS; + return code; } void setComposedBlockFlag(STsdbReader* pReader, bool composed) { pReader->status.composedDataBlock = composed; } @@ -2554,6 +2572,12 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) { pScanInfo = pReader->status.pTableIter; } + if (pScanInfo == NULL) { + tsdbError("failed to get table scan-info, %s", pReader->idStr); + code = TSDB_CODE_INVALID_PARA; + return code; + } + if (pBlockInfo != NULL) { pBlock = getCurrentBlock(pBlockIter); } @@ -2726,7 +2750,7 @@ static int32_t buildBlockFromFiles(STsdbReader* pReader) { // current block are exhausted, try the next file block if (pDumpInfo->allDumped) { // try next data block in current file - bool hasNext = blockIteratorNext(&pReader->status.blockIter); + bool hasNext = blockIteratorNext(&pReader->status.blockIter, pReader->idStr); if (hasNext) { // check for the next block in the block accessed order list initBlockDumpInfo(pReader, pBlockIter); } else { @@ -3652,10 +3676,6 @@ void tsdbReaderClose(STsdbReader* pReader) { taosMemoryFree(pLReader); } - if (pReader->innerReader[0] != 0) { - tsdbUntakeReadSnap(pReader->innerReader[0]->pTsdb, pReader->innerReader[0]->pReadSnap, pReader->idStr); - } - tsdbDebug( "%p :io-cost summary: head-file:%" PRIu64 ", head-file time:%.2f ms, SMA:%" PRId64 " SMA-time:%.2f ms, fileBlocks:%" PRId64 @@ -3843,8 +3863,14 @@ static SArray* doRetrieveDataBlock(STsdbReader* pReader) { return pReader->pResBlock->pDataBlock; } - SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(&pStatus->blockIter); - STableBlockScanInfo* pBlockScanInfo = taosHashGet(pStatus->pTableMap, &pFBlock->uid, sizeof(pFBlock->uid)); + SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pStatus->blockIter); + STableBlockScanInfo* pBlockScanInfo = taosHashGet(pStatus->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid)); + if (pBlockScanInfo == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, total tables:%d, %s", pBlockInfo->uid, + taosHashGetSize(pReader->status.pTableMap), pReader->idStr); + return NULL; + } int32_t code = doLoadFileBlockData(pReader, &pStatus->blockIter, &pStatus->fileBlockData, pBlockScanInfo->uid); if (code != TSDB_CODE_SUCCESS) { @@ -3973,7 +3999,7 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa int32_t bucketIndex = getBucketIndex(pTableBlockInfo->defMinRows, bucketRange, numOfRows); pTableBlockInfo->blockRowsHisto[bucketIndex]++; - hasNext = blockIteratorNext(&pStatus->blockIter); + hasNext = blockIteratorNext(&pStatus->blockIter, pReader->idStr); } else { code = initForFirstBlockInFile(pReader, pBlockIter); if ((code != TSDB_CODE_SUCCESS) || (pReader->status.loadFromFile == false)) { diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index 84b3afe72c70147a28bdb55446c806a1f1ebd70e..27beb22165cbfb619f6cddd5d7eccfc55d80a43e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -415,7 +415,7 @@ int32_t tsdbWriteBlockIdx(SDataFWriter *pWriter, SArray *aBlockIdx) { pHeadFile->size += size; _exit: - // tsdbTrace("vgId:%d write block idx, offset:%" PRId64 " size:%" PRId64 " nBlockIdx:%d", + // tsdbTrace("vgId:%d, write block idx, offset:%" PRId64 " size:%" PRId64 " nBlockIdx:%d", // TD_VID(pWriter->pTsdb->pVnode), // pHeadFile->offset, size, taosArrayGetSize(aBlockIdx)); return code; @@ -498,12 +498,12 @@ int32_t tsdbWriteSttBlk(SDataFWriter *pWriter, SArray *aSttBlk) { pSttFile->size += size; _exit: - tsdbTrace("vgId:%d tsdb write stt block, loffset:%" PRId64 " size:%" PRId64, TD_VID(pWriter->pTsdb->pVnode), + tsdbTrace("vgId:%d, tsdb write stt block, loffset:%" PRId64 " size:%" PRId64, TD_VID(pWriter->pTsdb->pVnode), pSttFile->offset, size); return code; _err: - tsdbError("vgId:%d tsdb write blockl failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + tsdbError("vgId:%d, tsdb write blockl failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); return code; } @@ -539,7 +539,7 @@ static int32_t tsdbWriteBlockSma(SDataFWriter *pWriter, SBlockData *pBlockData, return code; _err: - tsdbError("vgId:%d tsdb write block sma failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + tsdbError("vgId:%d, tsdb write block sma failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); return code; } @@ -601,13 +601,13 @@ int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, SBlock } _exit: - tsdbTrace("vgId:%d tsdb write block data, suid:%" PRId64 " uid:%" PRId64 " nRow:%d, offset:%" PRId64 " size:%d", + tsdbTrace("vgId:%d, tsdb write block data, suid:%" PRId64 " uid:%" PRId64 " nRow:%d, offset:%" PRId64 " size:%d", TD_VID(pWriter->pTsdb->pVnode), pBlockData->suid, pBlockData->uid, pBlockData->nRow, pBlkInfo->offset, pBlkInfo->szBlock); return code; _err: - tsdbError("vgId:%d tsdb write block data failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + tsdbError("vgId:%d, tsdb write block data failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); return code; } @@ -732,7 +732,7 @@ int32_t tsdbWriteDiskData(SDataFWriter *pWriter, const SDiskData *pDiskData, SBl _exit: if (code) { - tsdbError("vgId:%d %s failed at %d since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at %d since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } @@ -882,7 +882,7 @@ int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pS _exit: if (code) { *ppReader = NULL; - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); if (pReader) { for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) tsdbCloseFile(&pReader->aSttFD[iStt]); @@ -995,7 +995,7 @@ int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk) { return code; _err: - tsdbError("vgId:%d read stt blk failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + tsdbError("vgId:%d, read stt blk failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); return code; } @@ -1058,7 +1058,7 @@ int32_t tsdbReadBlockSma(SDataFReader *pReader, SDataBlk *pDataBlk, SArray *aCol return code; _err: - tsdbError("vgId:%d tsdb read block sma failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + tsdbError("vgId:%d, tsdb read block sma failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); return code; } @@ -1177,7 +1177,7 @@ _exit: return code; _err: - tsdbError("vgId:%d tsdb read block data impl failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + tsdbError("vgId:%d, tsdb read block data impl failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); return code; } @@ -1200,7 +1200,7 @@ int32_t tsdbReadDataBlockEx(SDataFReader *pReader, SDataBlk *pDataBlk, SBlockDat return code; _err: - tsdbError("vgId:%d tsdb read data block ex failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + tsdbError("vgId:%d, tsdb read data block ex failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); return code; } @@ -1258,7 +1258,7 @@ int32_t tsdbReadDataBlock(SDataFReader *pReader, SDataBlk *pDataBlk, SBlockData return code; _err: - tsdbError("vgId:%d tsdb read data block failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); + tsdbError("vgId:%d, tsdb read data block failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); return code; } @@ -1271,7 +1271,7 @@ int32_t tsdbReadSttBlock(SDataFReader *pReader, int32_t iStt, SSttBlk *pSttBlk, _exit: if (code) { - tsdbError("vgId:%d %s failed at %d since %s", TD_VID(pReader->pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at %d since %s", TD_VID(pReader->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } @@ -1294,7 +1294,7 @@ int32_t tsdbReadSttBlockEx(SDataFReader *pReader, int32_t iStt, SSttBlk *pSttBlk _exit: if (code) { - tsdbError("vgId:%d %s failed at %d since %s", TD_VID(pReader->pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at %d since %s", TD_VID(pReader->pTsdb->pVnode), __func__, lino, tstrerror(code)); } return code; } @@ -1334,11 +1334,11 @@ int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb _exit: if (code) { if (pDelFWriter) { - taosMemoryFree(pDelFWriter); tsdbCloseFile(&pDelFWriter->pWriteH); + taosMemoryFree(pDelFWriter); } *ppWriter = NULL; - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(errno)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(errno)); } else { *ppWriter = pDelFWriter; } @@ -1502,7 +1502,7 @@ int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb _exit: if (code) { *ppReader = NULL; - tsdbError("vgId:%d %s failed at %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); } else { *ppReader = pDelFReader; } diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c index 2c68c571765f063c79898f4b7bc722a675cb1a08..c6e1ed99f18a511cf60c12ec045044b4023354c5 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRetention.c +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -47,7 +47,7 @@ int32_t tsdbDoRetention(STsdb *pTsdb, int64_t now) { } // do retention - STsdbFS fs; + STsdbFS fs = {0}; code = tsdbFSCopy(pTsdb, &fs); if (code) goto _err; @@ -86,12 +86,12 @@ int32_t tsdbDoRetention(STsdb *pTsdb, int64_t now) { } // do change fs - code = tsdbFSCommit1(pTsdb, &fs); + code = tsdbFSPrepareCommit(pTsdb, &fs); if (code) goto _err; taosThreadRwlockWrlock(&pTsdb->rwLock); - code = tsdbFSCommit2(pTsdb, &fs); + code = tsdbFSCommit(pTsdb); if (code) { taosThreadRwlockUnlock(&pTsdb->rwLock); goto _err; diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index 74c704598d891d5c50e0fd17766834401891e96d..ec89bed17a8c9ee002d751ee0c43bb5c0f5170e2 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -174,7 +174,7 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) { return code; _err: - tsdbError("vgId:%d vnode snapshot tsdb snap read open file failed since %s", TD_VID(pReader->pTsdb->pVnode), + tsdbError("vgId:%d, vnode snapshot tsdb snap read open file failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); return code; } @@ -517,8 +517,8 @@ int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, int8_t type _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s, TSDB path: %s", TD_VID(pTsdb->pVnode), lino, tstrerror(code), - pTsdb->path); + tsdbError("vgId:%d, %s failed at line %d since %s, TSDB path: %s", TD_VID(pTsdb->pVnode), __func__, lino, + tstrerror(code), pTsdb->path); *ppReader = NULL; if (pReader) { @@ -738,7 +738,7 @@ static int32_t tsdbSnapWriteTableDataStart(STsdbSnapWriter* pWriter, TABLEID* pI return code; _err: - tsdbError("vgId:%d %s failed since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, tstrerror(code)); + tsdbError("vgId:%d, %s failed since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, tstrerror(code)); return code; } @@ -991,7 +991,7 @@ _exit: return code; _err: - tsdbError("vgId:%d %s failed since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, tstrerror(code)); + tsdbError("vgId:%d, %s failed since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, tstrerror(code)); return code; } @@ -1072,7 +1072,7 @@ _exit: return code; _err: - tsdbError("vgId:%d %s failed since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, tstrerror(code)); + tsdbError("vgId:%d, %s failed since %s", TD_VID(pWriter->pTsdb->pVnode), __func__, tstrerror(code)); return code; } @@ -1338,7 +1338,7 @@ int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapWr _exit: if (code) { - tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); *ppWriter = NULL; if (pWriter) { @@ -1380,13 +1380,13 @@ int32_t tsdbSnapWriterClose(STsdbSnapWriter** ppWriter, int8_t rollback) { code = tsdbSnapWriteDelEnd(pWriter); if (code) goto _err; - code = tsdbFSCommit1(pWriter->pTsdb, &pWriter->fs); + code = tsdbFSPrepareCommit(pWriter->pTsdb, &pWriter->fs); if (code) goto _err; // lock taosThreadRwlockWrlock(&pTsdb->rwLock); - code = tsdbFSCommit2(pWriter->pTsdb, &pWriter->fs); + code = tsdbFSCommit(pWriter->pTsdb); if (code) { taosThreadRwlockUnlock(&pTsdb->rwLock); goto _err; diff --git a/source/dnode/vnode/src/vnd/vnodeBufPool.c b/source/dnode/vnode/src/vnd/vnodeBufPool.c index 682f2b4225d6f8151a0061a1a420eca753ede3c3..6ac2ce1c16f39e325b055546168e6113489ee2fe 100644 --- a/source/dnode/vnode/src/vnd/vnodeBufPool.c +++ b/source/dnode/vnode/src/vnd/vnodeBufPool.c @@ -174,12 +174,12 @@ void vnodeBufPoolUnRef(SVBufPool *pPool) { if (pPool->node.size != size) { SVBufPool *pPoolT = NULL; if (vnodeBufPoolCreate(pVnode, size, &pPoolT) < 0) { - vWarn("vgId:%d try to change buf pools size from %" PRId64 " to %" PRId64 " since %s", TD_VID(pVnode), + vWarn("vgId:%d, try to change buf pools size from %" PRId64 " to %" PRId64 " since %s", TD_VID(pVnode), pPool->node.size, size, tstrerror(errno)); } else { vnodeBufPoolDestroy(pPool); pPool = pPoolT; - vDebug("vgId:%d change buf pools size from %" PRId64 " to %" PRId64, TD_VID(pVnode), pPool->node.size, size); + vDebug("vgId:%d, change buf pools size from %" PRId64 " to %" PRId64, TD_VID(pVnode), pPool->node.size, size); } } diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 07c4c32955ece956b44beaba5ca78bcd0877e916..e593bbd602e598707a02ffa228f839b4582751ea 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -15,13 +15,11 @@ #include "vnd.h" -#define VND_INFO_FNAME "vnode.json" +#define VND_INFO_FNAME "vnode.json" #define VND_INFO_FNAME_TMP "vnode_tmp.json" static int vnodeEncodeInfo(const SVnodeInfo *pInfo, char **ppData); static int vnodeDecodeInfo(uint8_t *pData, SVnodeInfo *pInfo); -static int vnodeStartCommit(SVnode *pVnode); -static int vnodeEndCommit(SVnode *pVnode); static int vnodeCommitImpl(void *arg); static void vnodeWaitCommit(SVnode *pVnode); @@ -53,20 +51,11 @@ int vnodeBegin(SVnode *pVnode) { return -1; } - if (pVnode->pSma) { - if (VND_RSMA1(pVnode) && tsdbBegin(VND_RSMA1(pVnode)) < 0) { - vError("vgId:%d, failed to begin rsma1 since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } - - if (VND_RSMA2(pVnode) && tsdbBegin(VND_RSMA2(pVnode)) < 0) { - vError("vgId:%d, failed to begin rsma2 since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } - } - // begin sma - smaBegin(pVnode->pSma); // TODO: refactor to include the rsma1/rsma2 tsdbBegin() after tsdb_refact branch merged + if (VND_IS_RSMA(pVnode) && smaBegin(pVnode->pSma) < 0) { + vError("vgId:%d, failed to begin sma since %s", TD_VID(pVnode), tstrerror(terrno)); + return -1; + } return 0; } @@ -118,7 +107,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) { // free info binary taosMemoryFree(data); - vInfo("vgId:%d, vnode info is saved, fname:%s", pInfo->config.vgId, fname); + vInfo("vgId:%d, vnode info is saved, fname:%s replica:%d", pInfo->config.vgId, fname, pInfo->config.syncCfg.replicaNum); return 0; @@ -215,6 +204,8 @@ int vnodeSyncCommit(SVnode *pVnode) { } int vnodeCommit(SVnode *pVnode) { + int32_t code = 0; + int32_t lino = 0; SVnodeInfo info = {0}; char dir[TSDB_FILENAME_LEN]; @@ -234,81 +225,93 @@ int vnodeCommit(SVnode *pVnode) { snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path); } if (vnodeSaveInfo(dir, &info) < 0) { - vError("vgId:%d, failed to save vnode info since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; + code = terrno; + TSDB_CHECK_CODE(code, lino, _exit); } - walBeginSnapshot(pVnode->pWal, pVnode->state.applied); - // preCommit - // smaSyncPreCommit(pVnode->pSma); - if(smaAsyncPreCommit(pVnode->pSma) < 0){ - vError("vgId:%d, failed to async pre-commit sma since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } + // walBeginSnapshot(pVnode->pWal, pVnode->state.applied); + syncBeginSnapshot(pVnode->sync, pVnode->state.applied); + + code = smaPreCommit(pVnode->pSma); + TSDB_CHECK_CODE(code, lino, _exit); vnodeBufPoolUnRef(pVnode->inUse); pVnode->inUse = NULL; // commit each sub-system if (metaCommit(pVnode->pMeta) < 0) { - vError("vgId:%d, failed to commit meta since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; + code = TSDB_CODE_FAILED; + TSDB_CHECK_CODE(code, lino, _exit); } + code = tsdbCommit(pVnode->pTsdb); + TSDB_CHECK_CODE(code, lino, _exit); + if (VND_IS_RSMA(pVnode)) { - if (smaAsyncCommit(pVnode->pSma) < 0) { - vError("vgId:%d, failed to async commit sma since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } - - if (tsdbCommit(VND_RSMA0(pVnode)) < 0) { - vError("vgId:%d, failed to commit tsdb rsma0 since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } - if (tsdbCommit(VND_RSMA1(pVnode)) < 0) { - vError("vgId:%d, failed to commit tsdb rsma1 since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } - if (tsdbCommit(VND_RSMA2(pVnode)) < 0) { - vError("vgId:%d, failed to commit tsdb rsma2 since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } - } else { - if (tsdbCommit(pVnode->pTsdb) < 0) { - vError("vgId:%d, failed to commit tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; - } + code = smaCommit(pVnode->pSma); + TSDB_CHECK_CODE(code, lino, _exit); } if (tqCommit(pVnode->pTq) < 0) { - vError("vgId:%d, failed to commit tq since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; + code = TSDB_CODE_FAILED; + TSDB_CHECK_CODE(code, lino, _exit); } - // walCommit (TODO) // commit info if (vnodeCommitInfo(dir, &info) < 0) { - vError("vgId:%d, failed to commit vnode info since %s", TD_VID(pVnode), tstrerror(terrno)); - return -1; + code = terrno; + TSDB_CHECK_CODE(code, lino, _exit); + } + + code = tsdbFinishCommit(pVnode->pTsdb); + TSDB_CHECK_CODE(code, lino, _exit); + + if (VND_IS_RSMA(pVnode)) { + code = smaFinishCommit(pVnode->pSma); + TSDB_CHECK_CODE(code, lino, _exit); + } + + if (metaFinishCommit(pVnode->pMeta) < 0) { + code = terrno; + TSDB_CHECK_CODE(code, lino, _exit); } pVnode->state.committed = info.state.committed; - // postCommit - // smaSyncPostCommit(pVnode->pSma); - if (smaAsyncPostCommit(pVnode->pSma) < 0) { - vError("vgId:%d, failed to async post-commit sma since %s", TD_VID(pVnode), tstrerror(terrno)); + if (smaPostCommit(pVnode->pSma) < 0) { + vError("vgId:%d, failed to post-commit sma since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } // apply the commit (TODO) - walEndSnapshot(pVnode->pWal); - - vInfo("vgId:%d, commit end", TD_VID(pVnode)); + // walEndSnapshot(pVnode->pWal); + syncEndSnapshot(pVnode->sync); +_exit: + if (code) { + vError("vgId:%d, %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code)); + } else { + vInfo("vgId:%d, commit end", TD_VID(pVnode)); + } return 0; } +bool vnodeShouldRollback(SVnode *pVnode) { + char tFName[TSDB_FILENAME_LEN] = {0}; + snprintf(tFName, TSDB_FILENAME_LEN, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP, + VND_INFO_FNAME_TMP); + + return taosCheckExistFile(tFName); +} + +void vnodeRollback(SVnode *pVnode) { + char tFName[TSDB_FILENAME_LEN] = {0}; + snprintf(tFName, TSDB_FILENAME_LEN, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP, + VND_INFO_FNAME_TMP); + + (void)taosRemoveFile(tFName); +} + static int vnodeCommitImpl(void *arg) { SVnode *pVnode = (SVnode *)arg; @@ -321,16 +324,6 @@ static int vnodeCommitImpl(void *arg) { return 0; } -static int vnodeStartCommit(SVnode *pVnode) { - // TODO - return 0; -} - -static int vnodeEndCommit(SVnode *pVnode) { - // TODO - return 0; -} - static FORCE_INLINE void vnodeWaitCommit(SVnode *pVnode) { tsem_wait(&pVnode->canCommit); } static int vnodeEncodeState(const void *pObj, SJson *pJson) { diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index 001bb5f7f209f14887d637103574c9e79ab5878d..0696ec090178b56f85bcc757532cc81e00c41457 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -15,11 +15,9 @@ #include "vnd.h" -int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { +int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { SVnodeInfo info = {0}; - char dir[TSDB_FILENAME_LEN]; - - // TODO: check if directory exists + char dir[TSDB_FILENAME_LEN] = {0}; // check config if (vnodeCheckCfg(pCfg) < 0) { @@ -56,18 +54,67 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { } vInfo("vgId:%d, vnode is created", info.config.vgId); + return 0; +} + +int32_t vnodeAlter(const char *path, SAlterVnodeReplicaReq *pReq, STfs *pTfs) { + SVnodeInfo info = {0}; + char dir[TSDB_FILENAME_LEN] = {0}; + int32_t ret = 0; + + if (pTfs) { + snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, path); + } else { + snprintf(dir, TSDB_FILENAME_LEN, "%s", path); + } + + ret = vnodeLoadInfo(dir, &info); + if (ret < 0) { + vError("vgId:%d, failed to read vnode config from %s since %s", pReq->vgId, path, tstrerror(terrno)); + return -1; + } + + SSyncCfg *pCfg = &info.config.syncCfg; + pCfg->myIndex = pReq->selfIndex; + pCfg->replicaNum = pReq->replica; + memset(&pCfg->nodeInfo, 0, sizeof(pCfg->nodeInfo)); + + vInfo("vgId:%d, save config, replicas:%d selfIndex:%d", pReq->vgId, pCfg->replicaNum, pCfg->myIndex); + for (int i = 0; i < pReq->replica; ++i) { + SNodeInfo *pNode = &pCfg->nodeInfo[i]; + pNode->nodePort = pReq->replicas[i].port; + tstrncpy(pNode->nodeFqdn, pReq->replicas[i].fqdn, sizeof(pNode->nodeFqdn)); + vInfo("vgId:%d, save config, replica:%d ep:%s:%u", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort); + } + + info.config.syncCfg = *pCfg; + ret = vnodeSaveInfo(dir, &info); + if (ret < 0) { + vError("vgId:%d, failed to save vnode config since %s", pReq->vgId, tstrerror(terrno)); + return -1; + } + ret = vnodeCommitInfo(dir, &info); + if (ret < 0) { + vError("vgId:%d, failed to commit vnode config since %s", pReq->vgId, tstrerror(terrno)); + return -1; + } + + vInfo("vgId:%d, vnode config is saved", info.config.vgId); return 0; } -void vnodeDestroy(const char *path, STfs *pTfs) { tfsRmdir(pTfs, path); } +void vnodeDestroy(const char *path, STfs *pTfs) { + vInfo("path:%s is removed while destroy vnode", path); + tfsRmdir(pTfs, path); +} SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { SVnode *pVnode = NULL; SVnodeInfo info = {0}; - char dir[TSDB_FILENAME_LEN]; - char tdir[TSDB_FILENAME_LEN * 2]; - int ret; + char dir[TSDB_FILENAME_LEN] = {0}; + char tdir[TSDB_FILENAME_LEN * 2] = {0}; + int32_t ret = 0; if (pTfs) { snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, path); @@ -85,7 +132,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { } // create handle - pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode) + strlen(path) + 1); + pVnode = taosMemoryCalloc(1, sizeof(*pVnode) + strlen(path) + 1); if (pVnode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; vError("vgId:%d, failed to open vnode since %s", info.config.vgId, tstrerror(terrno)); @@ -110,6 +157,8 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { taosThreadMutexInit(&pVnode->mutex, NULL); taosThreadCondInit(&pVnode->poolNotEmpty, NULL); + int8_t rollback = vnodeShouldRollback(pVnode); + // open buffer pool if (vnodeOpenBufPool(pVnode) < 0) { vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno)); @@ -117,19 +166,19 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { } // open meta - if (metaOpen(pVnode, &pVnode->pMeta) < 0) { + if (metaOpen(pVnode, &pVnode->pMeta, rollback) < 0) { vError("vgId:%d, failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open tsdb - if (!VND_IS_RSMA(pVnode) && tsdbOpen(pVnode, &VND_TSDB(pVnode), VNODE_TSDB_DIR, NULL) < 0) { + if (!VND_IS_RSMA(pVnode) && tsdbOpen(pVnode, &VND_TSDB(pVnode), VNODE_TSDB_DIR, NULL, rollback) < 0) { vError("vgId:%d, failed to open vnode tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open sma - if (smaOpen(pVnode)) { + if (smaOpen(pVnode, rollback)) { vError("vgId:%d, failed to open vnode sma since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } @@ -153,14 +202,12 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { goto _err; } -#if !VNODE_AS_LIB // open query if (vnodeQueryOpen(pVnode)) { vError("vgId:%d, failed to open vnode query since %s", TD_VID(pVnode), tstrerror(terrno)); terrno = TSDB_CODE_OUT_OF_MEMORY; goto _err; } -#endif // vnode begin if (vnodeBegin(pVnode) < 0) { @@ -169,13 +216,15 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { goto _err; } -#if !VNODE_AS_LIB // open sync if (vnodeSyncOpen(pVnode, dir)) { vError("vgId:%d, failed to open sync since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } -#endif + + if (rollback) { + vnodeRollback(pVnode); + } return pVnode; diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 64df3aa1ebd70d66b597c3d04469a169fa8cb22e..f1bbb2d4b36b1f487af42e1424a95d6f00c1da82 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -15,10 +15,13 @@ #include "vnd.h" -#define VNODE_GET_LOAD_RESET_VALS(pVar, oVal, vType) \ - do { \ - int##vType##_t newVal = atomic_sub_fetch_##vType(&(pVar), (oVal)); \ - ASSERT(newVal >= 0); \ +#define VNODE_GET_LOAD_RESET_VALS(pVar, oVal, vType, tags) \ + do { \ + int##vType##_t newVal = atomic_sub_fetch_##vType(&(pVar), (oVal)); \ + ASSERT(newVal >= 0); \ + if (newVal < 0) { \ + vWarn("vgId:%d %s, abnormal val:%" PRIi64 ", old val:%" PRIi64, TD_VID(pVnode), tags, newVal, (oVal)); \ + } \ } while (0) int vnodeQueryOpen(SVnode *pVnode) { @@ -285,15 +288,43 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) { } for (int32_t i = 0; i < msgNum; ++i) { + if (offset >= pMsg->contLen) { + qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen); + terrno = TSDB_CODE_MSG_NOT_PROCESSED; + taosArrayDestroy(batchRsp); + return -1; + } + req.msgIdx = ntohl(*(int32_t *)((char *)pMsg->pCont + offset)); offset += sizeof(req.msgIdx); + if (offset >= pMsg->contLen) { + qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen); + terrno = TSDB_CODE_MSG_NOT_PROCESSED; + taosArrayDestroy(batchRsp); + return -1; + } + req.msgType = ntohl(*(int32_t *)((char *)pMsg->pCont + offset)); offset += sizeof(req.msgType); + if (offset >= pMsg->contLen) { + qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen); + terrno = TSDB_CODE_MSG_NOT_PROCESSED; + taosArrayDestroy(batchRsp); + return -1; + } + req.msgLen = ntohl(*(int32_t *)((char *)pMsg->pCont + offset)); offset += sizeof(req.msgLen); + if (offset >= pMsg->contLen) { + qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen); + terrno = TSDB_CODE_MSG_NOT_PROCESSED; + taosArrayDestroy(batchRsp); + return -1; + } + req.msg = (char *)pMsg->pCont + offset; offset += req.msgLen; @@ -385,6 +416,7 @@ _exit: int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { pLoad->vgId = TD_VID(pVnode); pLoad->syncState = syncGetMyRole(pVnode->sync); + pLoad->syncRestore = pVnode->restored; pLoad->cacheUsage = tsdbCacheGetUsage(pVnode); pLoad->numOfTables = metaGetTbNum(pVnode->pMeta); pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta); @@ -406,10 +438,10 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { * @param pLoad */ void vnodeResetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { - VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsert, pLoad->numOfInsertReqs, 64); - VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsertSuccess, pLoad->numOfInsertSuccessReqs, 64); - VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsert, pLoad->numOfBatchInsertReqs, 64); - VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsertSuccess, pLoad->numOfBatchInsertSuccessReqs, 64); + VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsert, pLoad->numOfInsertReqs, 64, "nInsert"); + VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsertSuccess, pLoad->numOfInsertSuccessReqs, 64, "nInsertSuccess"); + VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsert, pLoad->numOfBatchInsertReqs, 64, "nBatchInsert"); + VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsertSuccess, pLoad->numOfBatchInsertSuccessReqs, 64, "nBatchInsertSuccess"); } void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId) { diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index 9cbb1b8af491ea1567c8d9a3ada47614749503bc..e8cdf9513f8fc80d479114273a5bf4984bb71337 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -219,7 +219,7 @@ _exit: return code; _err: - vError("vgId:%d vnode snapshot read failed since %s", TD_VID(pReader->pVnode), tstrerror(code)); + vError("vgId:%d, vnode snapshot read failed since %s", TD_VID(pReader->pVnode), tstrerror(code)); return code; } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index d0a00a8b6de0a337fa2d9971c88369cad2da2e8b..c8089ead9963d76ca6a39aa3c4d883f3f3b86806 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -53,7 +53,10 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) { for (int32_t iReq = 0; iReq < nReqs; iReq++) { tb_uid_t uid = tGenIdPI64(); char *name = NULL; - tStartDecode(&dc); + if (tStartDecode(&dc) < 0) { + code = TSDB_CODE_INVALID_MSG; + goto _err; + } if (tDecodeI32v(&dc, NULL) < 0) { code = TSDB_CODE_INVALID_MSG; @@ -1065,20 +1068,20 @@ static int32_t vnodeProcessAlterHashRangeReq(SVnode *pVnode, int64_t version, vo } static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { - SAlterVnodeReq req = {0}; - bool walChanged = false; - bool tsdbChanged = false; + bool walChanged = false; + bool tsdbChanged = false; - if (tDeserializeSAlterVnodeReq(pReq, len, &req) != 0) { + SAlterVnodeConfigReq req = {0}; + if (tDeserializeSAlterVnodeConfigReq(pReq, len, &req) != 0) { terrno = TSDB_CODE_INVALID_MSG; return TSDB_CODE_INVALID_MSG; } vInfo("vgId:%d, start to alter vnode config, page:%d pageSize:%d buffer:%d szPage:%d szBuf:%" PRIu64 - " cacheLast:%d cacheLastSize:%d days:%d keep0:%d keep1:%d keep2:%d fsync:%d level:%d strict:%d", + " cacheLast:%d cacheLastSize:%d days:%d keep0:%d keep1:%d keep2:%d fsync:%d level:%d", TD_VID(pVnode), req.pages, req.pageSize, req.buffer, req.pageSize * 1024, (uint64_t)req.buffer * 1024 * 1024, req.cacheLast, req.cacheLastSize, req.daysPerFile, req.daysToKeep0, req.daysToKeep1, req.daysToKeep2, - req.walFsyncPeriod, req.walLevel, req.strict); + req.walFsyncPeriod, req.walLevel); if (pVnode->config.cacheLastSize != req.cacheLastSize) { pVnode->config.cacheLastSize = req.cacheLastSize; @@ -1086,18 +1089,18 @@ static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t version, void } if (pVnode->config.szBuf != req.buffer * 1024LL * 1024LL) { - vInfo("vgId:%d vnode buffer is changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pVnode->config.szBuf, - req.buffer * 1024LL * 1024LL); + vInfo("vgId:%d, vnode buffer is changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pVnode->config.szBuf, + (uint64_t)(req.buffer * 1024LL * 1024LL)); pVnode->config.szBuf = req.buffer * 1024LL * 1024LL; } if (pVnode->config.szCache != req.pages) { if (metaAlterCache(pVnode->pMeta, req.pages) < 0) { - vError("vgId:%d failed to change vnode pages from %d to %d failed since %s", TD_VID(pVnode), + vError("vgId:%d, failed to change vnode pages from %d to %d failed since %s", TD_VID(pVnode), pVnode->config.szCache, req.pages, tstrerror(errno)); return errno; } else { - vInfo("vgId:%d vnode pages is changed from %d to %d", TD_VID(pVnode), pVnode->config.szCache, req.pages); + vInfo("vgId:%d, vnode pages is changed from %d to %d", TD_VID(pVnode), pVnode->config.szCache, req.pages); pVnode->config.szCache = req.pages; } } diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c index ab7fb001f017e2f6917d1407aa102fbb86434b02..d3ae1015d007da53005bedb11f4b3677798744b2 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -20,7 +20,7 @@ static inline bool vnodeIsMsgBlock(tmsg_t type) { return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) || - (type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_REPLICA); + (type == TDMT_VND_UPDATE_TAG_VAL); } static inline bool vnodeIsMsgWeak(tmsg_t type) { return false; } @@ -53,76 +53,6 @@ static inline void vnodePostBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) { } } -static int32_t vnodeSetStandBy(SVnode *pVnode) { - vInfo("vgId:%d, start to set standby", TD_VID(pVnode)); - - if (syncSetStandby(pVnode->sync) == 0) { - vInfo("vgId:%d, set standby success", TD_VID(pVnode)); - return 0; - } else if (terrno != TSDB_CODE_SYN_IS_LEADER) { - vError("vgId:%d, failed to set standby since %s", TD_VID(pVnode), terrstr()); - return -1; - } - - vInfo("vgId:%d, start to transfer leader", TD_VID(pVnode)); - if (syncLeaderTransfer(pVnode->sync) != 0) { - vError("vgId:%d, failed to transfer leader since:%s", TD_VID(pVnode), terrstr()); - return -1; - } else { - vInfo("vgId:%d, transfer leader success", TD_VID(pVnode)); - } - - if (syncSetStandby(pVnode->sync) == 0) { - vInfo("vgId:%d, set standby success", TD_VID(pVnode)); - return 0; - } else { - vError("vgId:%d, failed to set standby after leader transfer since %s", TD_VID(pVnode), terrstr()); - return -1; - } -} - -static int32_t vnodeProcessAlterReplicaReq(SVnode *pVnode, SRpcMsg *pMsg) { - SAlterVnodeReq req = {0}; - if (tDeserializeSAlterVnodeReq((char *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead), &req) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return TSDB_CODE_INVALID_MSG; - } - - const STraceId *trace = &pMsg->info.traceId; - vGTrace("vgId:%d, start to alter vnode replica to %d, handle:%p", TD_VID(pVnode), req.replica, pMsg->info.handle); - - SSyncCfg cfg = {.replicaNum = req.replica, .myIndex = req.selfIndex}; - for (int32_t r = 0; r < req.replica; ++r) { - SNodeInfo *pNode = &cfg.nodeInfo[r]; - tstrncpy(pNode->nodeFqdn, req.replicas[r].fqdn, sizeof(pNode->nodeFqdn)); - pNode->nodePort = req.replicas[r].port; - vInfo("vgId:%d, replica:%d %s:%u", TD_VID(pVnode), r, pNode->nodeFqdn, pNode->nodePort); - } - - SRpcMsg rpcMsg = {.info = pMsg->info}; - if (syncReconfigBuild(pVnode->sync, &cfg, &rpcMsg) != 0) { - vError("vgId:%d, failed to build reconfig msg since %s", TD_VID(pVnode), terrstr()); - return -1; - } - - int32_t code = syncPropose(pVnode->sync, &rpcMsg, false); - if (code != 0) { - if (terrno != 0) code = terrno; - - vInfo("vgId:%d, failed to propose reconfig msg since %s", TD_VID(pVnode), terrstr()); - if (terrno == TSDB_CODE_SYN_IS_LEADER) { - if (syncLeaderTransfer(pVnode->sync) != 0) { - vError("vgId:%d, failed to transfer leader since %s", TD_VID(pVnode), terrstr()); - } else { - vInfo("vgId:%d, transfer leader success", TD_VID(pVnode)); - } - } - } - - terrno = code; - return code; -} - void vnodeRedirectRpcMsg(SVnode *pVnode, SRpcMsg *pMsg) { SEpSet newEpSet = {0}; syncGetRetryEpSet(pVnode->sync, &newEpSet); @@ -169,24 +99,6 @@ static void vnodeHandleProposeError(SVnode *pVnode, SRpcMsg *pMsg, int32_t code) } } -static void vnodeHandleAlterReplicaReq(SVnode *pVnode, SRpcMsg *pMsg) { - int32_t code = vnodeProcessAlterReplicaReq(pVnode, pMsg); - - if (code > 0) { - ASSERT(0); - } else if (code == 0) { - vnodeWaitBlockMsg(pVnode, pMsg); - } else { - if (terrno != 0) code = terrno; - vnodeHandleProposeError(pVnode, pMsg, code); - } - - const STraceId *trace = &pMsg->info.traceId; - vGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->config.vgId, pMsg, code); - rpcFreeCont(pMsg->pCont); - taosFreeQitem(pMsg); -} - static void inline vnodeProposeBatchMsg(SVnode *pVnode, SRpcMsg **pMsgArr, bool *pIsWeakArr, int32_t *arrSize) { if (*arrSize <= 0) return; @@ -265,11 +177,6 @@ void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) continue; } - if (pMsg->msgType == TDMT_VND_ALTER_REPLICA) { - vnodeHandleAlterReplicaReq(pVnode, pMsg); - continue; - } - if (isBlock || BATCH_DISABLE) { vnodeProposeBatchMsg(pVnode, pMsgArr, pIsWeakArr, &arrayPos); } @@ -323,6 +230,49 @@ void vnodeApplyWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { } } +int32_t vnodeProcessSyncCtrlMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { + int32_t code = 0; + const STraceId *trace = &pMsg->info.traceId; + + if (!syncEnvIsStart()) { + vGError("vgId:%d, msg:%p failed to process since sync env not start", pVnode->config.vgId, pMsg); + terrno = TSDB_CODE_APP_ERROR; + return -1; + } + + SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync); + if (pSyncNode == NULL) { + vGError("vgId:%d, msg:%p failed to process since invalid sync node", pVnode->config.vgId, pMsg); + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + return -1; + } + + vGTrace("vgId:%d, sync msg:%p will be processed, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType)); + + if (pMsg->msgType == TDMT_SYNC_HEARTBEAT) { + SyncHeartbeat *pSyncMsg = syncHeartbeatFromRpcMsg2(pMsg); + code = syncNodeOnHeartbeat(pSyncNode, pSyncMsg); + syncHeartbeatDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_HEARTBEAT_REPLY) { + SyncHeartbeatReply *pSyncMsg = syncHeartbeatReplyFromRpcMsg2(pMsg); + code = syncNodeOnHeartbeatReply(pSyncNode, pSyncMsg); + syncHeartbeatReplyDestroy(pSyncMsg); + + } else { + vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType); + code = -1; + } + + vTrace("vgId:%d, sync msg:%p is processed, type:%s code:0x%x", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType), + code); + syncNodeRelease(pSyncNode); + if (code != 0 && terrno == 0) { + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + } + return code; +} + int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { int32_t code = 0; const STraceId *trace = &pMsg->info.traceId; @@ -342,126 +292,67 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { vGTrace("vgId:%d, sync msg:%p will be processed, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType)); - if (syncNodeStrategy(pSyncNode) == SYNC_STRATEGY_NO_SNAPSHOT) { - if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { - SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg); - syncTimeoutDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_PING) { - SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnPingCb(pSyncNode, pSyncMsg); - syncPingDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) { - SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); - syncPingReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { - SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL); - syncClientRequestDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST_BATCH) { - SyncClientRequestBatch *pSyncMsg = syncClientRequestBatchFromRpcMsg(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnClientRequestBatchCb(pSyncNode, pSyncMsg); - syncClientRequestBatchDestroyDeep(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { - SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg); - syncRequestVoteDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { - SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg); - syncRequestVoteReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { - SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnAppendEntriesCb(pSyncNode, pSyncMsg); - syncAppendEntriesDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { - SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg); - syncAppendEntriesReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_SET_VNODE_STANDBY) { - code = vnodeSetStandBy(pVnode); - if (code != 0 && terrno != 0) code = terrno; - SRpcMsg rsp = {.code = code, .info = pMsg->info}; - tmsgSendRsp(&rsp); - } else { - vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType); - code = -1; - } + if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { + SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnTimer(pSyncNode, pSyncMsg); + syncTimeoutDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_PING) { + SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnPingCb(pSyncNode, pSyncMsg); + syncPingDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) { + SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); + syncPingReplyDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { + SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, NULL); + syncClientRequestDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { + SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnRequestVote(pSyncNode, pSyncMsg); + syncRequestVoteDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { + SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnRequestVoteReply(pSyncNode, pSyncMsg); + syncRequestVoteReplyDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { + SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnAppendEntries(pSyncNode, pSyncMsg); + syncAppendEntriesDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { + SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg); + ASSERT(pSyncMsg != NULL); + code = syncNodeOnAppendEntriesReply(pSyncNode, pSyncMsg); + syncAppendEntriesReplyDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) { + SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg); + code = syncNodeOnSnapshot(pSyncNode, pSyncMsg); + syncSnapshotSendDestroy(pSyncMsg); + + } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) { + SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg); + code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg); + syncSnapshotRspDestroy(pSyncMsg); - } else if (syncNodeStrategy(pSyncNode) == SYNC_STRATEGY_WAL_FIRST) { - // use wal first strategy - if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { - SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg); - syncTimeoutDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_PING) { - SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnPingCb(pSyncNode, pSyncMsg); - syncPingDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) { - SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); - syncPingReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { - SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL); - syncClientRequestDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST_BATCH) { - SyncClientRequestBatch *pSyncMsg = syncClientRequestBatchFromRpcMsg(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnClientRequestBatchCb(pSyncNode, pSyncMsg); - syncClientRequestBatchDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { - SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnRequestVoteSnapshotCb(pSyncNode, pSyncMsg); - syncRequestVoteDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { - SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnRequestVoteReplySnapshotCb(pSyncNode, pSyncMsg); - syncRequestVoteReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_BATCH) { - SyncAppendEntriesBatch *pSyncMsg = syncAppendEntriesBatchFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnAppendEntriesSnapshot2Cb(pSyncNode, pSyncMsg); - syncAppendEntriesBatchDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { - SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnAppendEntriesReplySnapshot2Cb(pSyncNode, pSyncMsg); - syncAppendEntriesReplyDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) { - SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg); - code = syncNodeOnSnapshotSendCb(pSyncNode, pSyncMsg); - syncSnapshotSendDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) { - SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg); - code = syncNodeOnSnapshotRspCb(pSyncNode, pSyncMsg); - syncSnapshotRspDestroy(pSyncMsg); - } else if (pMsg->msgType == TDMT_SYNC_SET_VNODE_STANDBY) { - code = vnodeSetStandBy(pVnode); - if (code != 0 && terrno != 0) code = terrno; - SRpcMsg rsp = {.code = code, .info = pMsg->info}; - tmsgSendRsp(&rsp); - } else { - vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType); - code = -1; - } + } else { + vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType); + code = -1; } vTrace("vgId:%d, sync msg:%p is processed, type:%s code:0x%x", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType), @@ -473,6 +364,19 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { return code; } +static int32_t vnodeSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { + if (msgcb == NULL) { + return -1; + } + + int32_t code = tmsgPutToQueue(msgcb, SYNC_CTRL_QUEUE, pMsg); + if (code != 0) { + rpcFreeCont(pMsg->pCont); + pMsg->pCont = NULL; + } + return code; +} + static int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { if (msgcb == NULL) { return -1; @@ -500,22 +404,7 @@ static int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) { return 0; } -static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta *cbMeta) { - SVnode *pVnode = pFsm->data; - - SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen}; - syncGetAndDelRespRpc(pVnode->sync, cbMeta->newCfgSeqNum, &rpcMsg.info); - rpcMsg.info.conn.applyIndex = cbMeta->index; - - const STraceId *trace = (STraceId *)&pMsg->info.traceId; - vGTrace("vgId:%d, alter vnode replica is confirmed, type:%s contLen:%d seq:%" PRIu64 " handle:%p", TD_VID(pVnode), - TMSG_INFO(pMsg->msgType), pMsg->contLen, cbMeta->seqNum, rpcMsg.info.handle); - if (rpcMsg.info.handle != NULL) { - tmsgSendRsp(&rpcMsg); - } - - vnodePostBlockMsg(pVnode, pMsg); -} +static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta *cbMeta) {} static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { if (cbMeta.isWeak == 0) { @@ -674,9 +563,7 @@ static int32_t vnodeSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void * #endif } -static void vnodeLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { - SVnode *pVnode = pFsm->data; -} +static void vnodeLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {} static void vnodeRestoreFinish(struct SSyncFSM *pFsm) { SVnode *pVnode = pFsm->data; @@ -716,12 +603,14 @@ static void vnodeBecomeLeader(struct SSyncFSM *pFsm) { SVnode *pVnode = pFsm->data; vDebug("vgId:%d, become leader", pVnode->config.vgId); - // taosThreadMutexLock(&pVnode->lock); - // if (pVnode->blocked) { - // pVnode->blocked = false; - // tsem_post(&pVnode->syncSem); - // } - // taosThreadMutexUnlock(&pVnode->lock); +#if 0 + taosThreadMutexLock(&pVnode->lock); + if (pVnode->blocked) { + pVnode->blocked = false; + tsem_post(&pVnode->syncSem); + } + taosThreadMutexUnlock(&pVnode->lock); +#endif } static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) { @@ -749,20 +638,26 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) { int32_t vnodeSyncOpen(SVnode *pVnode, char *path) { SSyncInfo syncInfo = { .snapshotStrategy = SYNC_STRATEGY_WAL_FIRST, - //.snapshotStrategy = SYNC_STRATEGY_NO_SNAPSHOT, .batchSize = 1, .vgId = pVnode->config.vgId, - .isStandBy = pVnode->config.standby, .syncCfg = pVnode->config.syncCfg, .pWal = pVnode->pWal, .msgcb = NULL, .FpSendMsg = vnodeSyncSendMsg, .FpEqMsg = vnodeSyncEqMsg, + .FpEqCtrlMsg = vnodeSyncEqCtrlMsg, }; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", path, TD_DIRSEP); syncInfo.pFsm = vnodeSyncMakeFsm(pVnode); + SSyncCfg *pCfg = &syncInfo.syncCfg; + vInfo("vgId:%d, start to open sync, replica:%d selfIndex:%d", pVnode->config.vgId, pCfg->replicaNum, pCfg->myIndex); + for (int32_t i = 0; i < pCfg->replicaNum; ++i) { + SNodeInfo *pNode = &pCfg->nodeInfo[i]; + vInfo("vgId:%d, index:%d ep:%s:%u", pVnode->config.vgId, i, pNode->nodeFqdn, pNode->nodePort); + } + pVnode->sync = syncOpen(&syncInfo); if (pVnode->sync <= 0) { vError("vgId:%d, failed to open sync since %s", pVnode->config.vgId, terrstr()); @@ -776,11 +671,15 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) { } void vnodeSyncStart(SVnode *pVnode) { + vDebug("vgId:%d, start sync", pVnode->config.vgId); syncSetMsgCb(pVnode->sync, &pVnode->msgCb); syncStart(pVnode->sync); } -void vnodeSyncClose(SVnode *pVnode) { syncStop(pVnode->sync); } +void vnodeSyncClose(SVnode *pVnode) { + vDebug("vgId:%d, close sync", pVnode->config.vgId); + syncStop(pVnode->sync); +} bool vnodeIsRoleLeader(SVnode *pVnode) { return syncGetMyRole(pVnode->sync) == TAOS_SYNC_STATE_LEADER; } diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index fe71987103aedbee555b67e99c95a7fb6fb2fb0e..0786321686a5ae6f5b7f7937f4c5ec425f6d6c31 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -505,6 +505,7 @@ typedef struct SCtgOperation { #define CTG_FLAG_UNKNOWN_STB 0x4 #define CTG_FLAG_SYS_DB 0x8 #define CTG_FLAG_FORCE_UPDATE 0x10 +#define CTG_FLAG_ONLY_CACHE 0x20 #define CTG_FLAG_SET(_flag, _v) ((_flag) |= (_v)) @@ -783,7 +784,7 @@ void ctgFreeQNode(SCtgQNode* node); void ctgClearHandle(SCatalog* pCtg); void ctgFreeTbCacheImpl(SCtgTbCache* pCache); int32_t ctgRemoveTbMeta(SCatalog* pCtg, SName* pTableName); -int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup); +int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists); SName* ctgGetFetchName(SArray* pNames, SCtgFetch* pFetch); extern SCatalogMgmt gCtgMgmt; diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 218a86ed5cad6979afd483394906969df5ff0dc0..a1dc2e9a58d41654ed8e0142a2e1741c3778a61d 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -23,12 +23,21 @@ SCatalogMgmt gCtgMgmt = {0}; int32_t ctgGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SCtgDBCache** dbCache, - SDBVgInfo** pInfo) { + SDBVgInfo** pInfo, bool* exists) { int32_t code = 0; CTG_ERR_RET(ctgAcquireVgInfoFromCache(pCtg, dbFName, dbCache)); if (*dbCache) { + if (exists) { + *exists = true; + } + + return TSDB_CODE_SUCCESS; + } + + if (exists) { + *exists = false; return TSDB_CODE_SUCCESS; } @@ -94,7 +103,7 @@ int32_t ctgRefreshTbMeta(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetaCtx* int32_t code = 0; if (!CTG_FLAG_IS_SYS_DB(ctx->flag)) { - CTG_ERR_RET(ctgGetTbHashVgroup(pCtg, pConn, ctx->pName, &vgroupInfo)); + CTG_ERR_RET(ctgGetTbHashVgroup(pCtg, pConn, ctx->pName, &vgroupInfo, NULL)); } STableMetaOutput moutput = {0}; @@ -194,7 +203,7 @@ int32_t ctgGetTbMeta(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetaCtx* ctx STableMetaOutput* output = NULL; CTG_ERR_RET(ctgGetTbMetaFromCache(pCtg, pConn, ctx, pTableMeta)); - if (*pTableMeta) { + if (*pTableMeta || (ctx->flag & CTG_FLAG_ONLY_CACHE)) { goto _return; } @@ -415,7 +424,7 @@ int32_t ctgGetTbCfg(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName, CTG_ERR_RET(ctgGetTableCfgFromMnode(pCtg, pConn, pTableName, pCfg, NULL)); } else { SVgroupInfo vgroupInfo = {0}; - CTG_ERR_RET(ctgGetTbHashVgroup(pCtg, pConn, pTableName, &vgroupInfo)); + CTG_ERR_RET(ctgGetTbHashVgroup(pCtg, pConn, pTableName, &vgroupInfo, NULL)); CTG_ERR_RET(ctgGetTableCfgFromVnode(pCtg, pConn, pTableName, &vgroupInfo, pCfg, NULL)); } @@ -441,7 +450,7 @@ int32_t ctgGetTbDistVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTabl tNameGetFullDbName(pTableName, db); SHashObj* vgHash = NULL; - CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, db, &dbCache, &vgInfo)); + CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, db, &dbCache, &vgInfo, NULL)); if (dbCache) { vgHash = dbCache->vgCache.vgInfo->vgHash; @@ -501,7 +510,7 @@ _return: CTG_RET(code); } -int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup) { +int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists) { if (IS_SYS_DBNAME(pTableName->dbname)) { ctgError("no valid vgInfo for db, dbname:%s", pTableName->dbname); CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); @@ -513,8 +522,13 @@ int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* tNameGetFullDbName(pTableName, db); SDBVgInfo* vgInfo = NULL; - CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, db, &dbCache, &vgInfo)); + CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, db, &dbCache, &vgInfo, exists)); + if (exists && false == *exists) { + ctgDebug("db %s vgInfo not in cache", pTableName->dbname); + return TSDB_CODE_SUCCESS; + } + CTG_ERR_JRET(ctgGetVgInfoFromHashValue(pCtg, vgInfo ? vgInfo : dbCache->vgCache.vgInfo, pTableName, pVgroup)); _return: @@ -725,7 +739,7 @@ _return: CTG_API_LEAVE(code); } -int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SArray** vgroupList) { +int32_t catalogGetDBVgList(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SArray** vgroupList) { CTG_API_ENTER(); if (NULL == pCtg || NULL == dbFName || NULL == pConn || NULL == vgroupList) { @@ -737,7 +751,7 @@ int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* SArray* vgList = NULL; SHashObj* vgHash = NULL; SDBVgInfo* vgInfo = NULL; - CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, dbFName, &dbCache, &vgInfo)); + CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, dbFName, &dbCache, &vgInfo, NULL)); if (dbCache) { vgHash = dbCache->vgCache.vgInfo->vgHash; } else { @@ -764,6 +778,64 @@ _return: CTG_API_LEAVE(code); } +int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, TAOS_DB_ROUTE_INFO* pInfo) { + CTG_API_ENTER(); + + if (NULL == pCtg || NULL == dbFName || NULL == pConn || NULL == pInfo) { + CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); + } + + SCtgDBCache* dbCache = NULL; + int32_t code = 0; + SDBVgInfo* dbInfo = NULL; + CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, dbFName, &dbCache, &dbInfo, NULL)); + if (dbCache) { + dbInfo = dbCache->vgCache.vgInfo; + } + + pInfo->routeVersion = dbInfo->vgVersion; + pInfo->hashPrefix = dbInfo->hashPrefix; + pInfo->hashSuffix = dbInfo->hashSuffix; + pInfo->hashMethod = dbInfo->hashMethod; + pInfo->vgNum = taosHashGetSize(dbInfo->vgHash); + if (pInfo->vgNum <= 0) { + ctgError("invalid vgNum %d in db %s's vgHash", pInfo->vgNum, dbFName); + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + + pInfo->vgHash = taosMemoryCalloc(pInfo->vgNum, sizeof(TAOS_VGROUP_HASH_INFO)); + if (NULL == pInfo->vgHash) { + CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + } + + SVgroupInfo* vgInfo = NULL; + int32_t i = 0; + void* pIter = taosHashIterate(dbInfo->vgHash, NULL); + while (pIter) { + vgInfo = pIter; + + pInfo->vgHash[i].vgId = vgInfo->vgId; + pInfo->vgHash[i].hashBegin = vgInfo->hashBegin; + pInfo->vgHash[i].hashEnd = vgInfo->hashEnd; + + pIter = taosHashIterate(dbInfo->vgHash, pIter); + vgInfo = NULL; + ++i; + } + +_return: + + if (dbCache) { + ctgRUnlockVgInfo(dbCache); + ctgReleaseDBCache(pCtg, dbCache); + } else if (dbInfo) { + taosHashCleanup(dbInfo->vgHash); + taosMemoryFreeClear(dbInfo); + } + + CTG_API_LEAVE(code); +} + int32_t catalogUpdateDBVgInfo(SCatalog* pCtg, const char* dbFName, uint64_t dbId, SDBVgInfo* dbInfo) { CTG_API_ENTER(); @@ -880,6 +952,17 @@ int32_t catalogGetTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta)); } +int32_t catalogGetCachedTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableMeta** pTableMeta) { + CTG_API_ENTER(); + + SCtgTbMetaCtx ctx = {0}; + ctx.pName = (SName*)pTableName; + ctx.flag = CTG_FLAG_UNKNOWN_STB | CTG_FLAG_ONLY_CACHE; + + CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta)); +} + + int32_t catalogGetSTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableMeta** pTableMeta) { CTG_API_ENTER(); @@ -891,6 +974,18 @@ int32_t catalogGetSTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SNam CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta)); } +int32_t catalogGetCachedSTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, + STableMeta** pTableMeta) { + CTG_API_ENTER(); + + SCtgTbMetaCtx ctx = {0}; + ctx.pName = (SName*)pTableName; + ctx.flag = CTG_FLAG_STB | CTG_FLAG_ONLY_CACHE; + + CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta)); +} + + int32_t catalogUpdateTableMeta(SCatalog* pCtg, STableMetaRsp* pMsg) { CTG_API_ENTER(); @@ -1009,7 +1104,14 @@ int32_t catalogGetTableHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SVgroupInfo* pVgroup) { CTG_API_ENTER(); - CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, pConn, pTableName, pVgroup)); + CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, pConn, pTableName, pVgroup, NULL)); +} + +int32_t catalogGetCachedTableHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, + SVgroupInfo* pVgroup, bool* exists) { + CTG_API_ENTER(); + + CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, pConn, pTableName, pVgroup, exists)); } int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalogReq* pReq, SMetaData* pRsp) { diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 93d36bc4b363269e7b8688377b3fcdf8aeaec651..1f1a210699b8611f68bf3e0db410087cd4d2e949 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -70,8 +70,8 @@ int32_t ctgInitGetTbMetasTask(SCtgJob* pJob, int32_t taskIdx, void* param) { taosArrayPush(pJob->pTasks, &task); - qDebug("QID:0x%" PRIx64 " the %dth task type %s initialized, dbNum:%d, tbNum:%d", pJob->queryId, taskIdx, - ctgTaskTypeStr(task.type), (int32_t)taosArrayGetSize(ctx->pNames), pJob->tbMetaNum); + qDebug("QID:0x%" PRIx64 " the %dth task type %s initialized, dbNum:%lu, tbNum:%d", pJob->queryId, taskIdx, + ctgTaskTypeStr(task.type), taosArrayGetSize(ctx->pNames), pJob->tbMetaNum); return TSDB_CODE_SUCCESS; } @@ -201,8 +201,8 @@ int32_t ctgInitGetTbHashsTask(SCtgJob* pJob, int32_t taskIdx, void* param) { taosArrayPush(pJob->pTasks, &task); - qDebug("QID:0x%" PRIx64 " the %dth task type %s initialized, dbNum:%d, tbNum:%d", pJob->queryId, taskIdx, - ctgTaskTypeStr(task.type), (int32_t)taosArrayGetSize(ctx->pNames), pJob->tbHashNum); + qDebug("QID:0x%" PRIx64 " the %dth task type %s initialized, dbNum:%lu, tbNum:%d", pJob->queryId, taskIdx, + ctgTaskTypeStr(task.type), taosArrayGetSize(ctx->pNames), pJob->tbHashNum); return TSDB_CODE_SUCCESS; } @@ -1667,7 +1667,7 @@ int32_t ctgLaunchGetTbMetasTask(SCtgTask* pTask) { int32_t baseResIdx = 0; for (int32_t i = 0; i < dbNum; ++i) { STablesReq* pReq = taosArrayGet(pCtx->pNames, i); - ctgDebug("start to check tb metas in db %s, tbNum %d", pReq->dbFName, (int32_t)taosArrayGetSize(pReq->pTables)); + ctgDebug("start to check tb metas in db %s, tbNum %ld", pReq->dbFName, taosArrayGetSize(pReq->pTables)); CTG_ERR_RET(ctgGetTbMetasFromCache(pCtg, pConn, pCtx, i, &fetchIdx, baseResIdx, pReq->pTables)); baseResIdx += taosArrayGetSize(pReq->pTables); } diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index bb4fd04aac51564144ce8c25d43662b8746aaa62..065c6234f69fba49e01156326ca20d4540db0595 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -778,7 +778,7 @@ void *ctgTestGetDbVgroupThread(void *param) { int32_t n = 0; while (!ctgTestStop) { - code = catalogGetDBVgInfo(pCtg, mockPointer, ctgTestDbname, &vgList); + code = catalogGetDBVgList(pCtg, mockPointer, ctgTestDbname, &vgList); if (code) { assert(0); } @@ -2063,7 +2063,7 @@ TEST(dbVgroup, getSetDbVgroupCase) { strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); - code = catalogGetDBVgInfo(pCtg, mockPointer, ctgTestDbname, &vgList); + code = catalogGetDBVgList(pCtg, mockPointer, ctgTestDbname, &vgList); ASSERT_EQ(code, 0); ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), ctgTestVgNum); diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 095d2b093d83e2c67f4aefc7c2fcbd222786bdfd..47a904bba210ef157b048515e4b0cb0528ae9f32 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -268,10 +268,10 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbFName, S len += sprintf( buf2 + VARSTR_HEADER_SIZE, - "CREATE DATABASE `%s` BUFFER %d CACHEMODEL '%s' COMP %d DURATION %dm " + "CREATE DATABASE `%s` BUFFER %d CACHESIZE %d CACHEMODEL '%s' COMP %d DURATION %dm " "WAL_FSYNC_PERIOD %d MAXROWS %d MINROWS %d KEEP %dm,%dm,%dm PAGES %d PAGESIZE %d PRECISION '%s' REPLICA %d " "STRICT '%s' WAL_LEVEL %d VGROUPS %d SINGLE_STABLE %d", - dbFName, pCfg->buffer, cacheModelStr(pCfg->cacheLast), pCfg->compression, pCfg->daysPerFile, pCfg->walFsyncPeriod, + dbFName, pCfg->buffer, pCfg->cacheSize, cacheModelStr(pCfg->cacheLast), pCfg->compression, pCfg->daysPerFile, pCfg->walFsyncPeriod, pCfg->maxRows, pCfg->minRows, pCfg->daysToKeep0, pCfg->daysToKeep1, pCfg->daysToKeep2, pCfg->pages, pCfg->pageSize, prec, pCfg->replications, strictStr(pCfg->strict), pCfg->walLevel, pCfg->numOfVgroups, 1 == pCfg->numOfStables); @@ -496,7 +496,12 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p colDataAppend(pCol1, 0, buf1, false); SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1); - char buf2[SHOW_CREATE_TB_RESULT_FIELD2_LEN] = {0}; + char* buf2 = taosMemoryMalloc(SHOW_CREATE_TB_RESULT_FIELD2_LEN); + if (NULL == buf2) { + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + return terrno; + } + int32_t len = 0; if (TSDB_SUPER_TABLE == pCfg->tableType) { @@ -512,6 +517,7 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ") TAGS ("); code = appendTagValues(buf2, &len, pCfg); if (code) { + taosMemoryFree(buf2); return code; } len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ")"); @@ -527,6 +533,8 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p colDataAppend(pCol2, 0, buf2, false); + taosMemoryFree(buf2); + return TSDB_CODE_SUCCESS; } diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 47450328be02da3e6cc84f79d00bae7d7c0aa93c..5e387d2bd3e66d7aa341e50c6166d82fa58889a7 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -162,6 +162,8 @@ typedef struct { SQueryTableDataCond tableCond; int64_t recoverStartVer; int64_t recoverEndVer; + int64_t fillHistoryVer1; + int64_t fillHistoryVer2; SStreamState* pState; } SStreamTaskInfo; @@ -539,6 +541,12 @@ typedef struct { SSnapContext* sContext; } SStreamRawScanInfo; +typedef struct SSysTableIndex { + int8_t init; + SArray *uids; + int32_t lastIdx; +} SSysTableIndex; + typedef struct SSysTableScanInfo { SRetrieveMetaTableRsp* pRsp; SRetrieveTableReq req; @@ -551,6 +559,7 @@ typedef struct SSysTableScanInfo { bool showRewrite; SNode* pCondition; // db_name filter condition, to discard data that are not in current database SMTbCursor* pCur; // cursor for iterate the local table meta store. + SSysTableIndex* pIdx; // idx for local table meta SArray* scanCols; // SArray scan column id list SName name; SSDataBlock* pRes; @@ -677,22 +686,20 @@ typedef struct SFillOperatorInfo { uint64_t curGroupId; // current handled group id SExprInfo* pExprInfo; int32_t numOfExpr; - SExprInfo* pNotFillExprInfo; - int32_t numOfNotFillExpr; + SExprSupp noFillExprSupp; } SFillOperatorInfo; typedef struct SGroupbyOperatorInfo { SOptrBasicInfo binfo; SAggSupporter aggSup; - - SArray* pGroupCols; // group by columns, SArray - SArray* pGroupColVals; // current group column values, SArray - SNode* pCondition; - bool isInit; // denote if current val is initialized or not - char* keyBuf; // group by keys for hash - int32_t groupKeyLen; // total group by column width - SGroupResInfo groupResInfo; - SExprSupp scalarSup; + SArray* pGroupCols; // group by columns, SArray + SArray* pGroupColVals; // current group column values, SArray + SNode* pCondition; + bool isInit; // denote if current val is initialized or not + char* keyBuf; // group by keys for hash + int32_t groupKeyLen; // total group by column width + SGroupResInfo groupResInfo; + SExprSupp scalarSup; } SGroupbyOperatorInfo; typedef struct SDataGroupInfo { @@ -889,8 +896,7 @@ typedef struct SJoinOperatorInfo { void doDestroyExchangeOperatorInfo(void* param); SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t streamFn, - __optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_encode_fn_t encode, - __optr_decode_fn_t decode, __optr_explain_fn_t explain); + __optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_explain_fn_t explain); int32_t operatorDummyOpenFn(SOperatorInfo* pOperator); int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num); @@ -954,9 +960,7 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode* pScanPhyNode, const char* pUser, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResultBlock, SNode* pCondition, SExprInfo* pScalarExprInfo, - int32_t numOfScalarExpr, bool mergeResult, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pNode, SExecTaskInfo* pTaskInfo); SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pNode, SExecTaskInfo* pTaskInfo); @@ -968,9 +972,7 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** dowStreams, size_ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pTableScanNode, SReadHandle* readHandle, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId, - STimeWindowAggSupp* pTwAggSupp, SIntervalPhysiNode* pPhyNode, +SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, bool isStream); SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SMergeIntervalPhysiNode* pIntervalPhyNode, SExecTaskInfo* pTaskInfo); @@ -980,9 +982,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, SExecTaskInfo* pTaskInfo, int32_t numOfChild); SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionWinodwPhysiNode* pSessionNode, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResultBlock, SArray* pGroupColList, SNode* pCondition, - SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode *pAggNode, SExecTaskInfo* pTaskInfo); SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* readHandle, uint64_t uid, SBlockDistScanPhysiNode* pBlockScanNode, SExecTaskInfo* pTaskInfo); @@ -1020,8 +1020,7 @@ SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFi int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, int32_t numOfOutput, SArray* pPseudoList); -void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order, - int32_t scanFlag, bool createDummyCol); +void setInputDataBlock(SExprSupp* pExprSupp, SSDataBlock* pBlock, int32_t order, int32_t scanFlag, bool createDummyCol); bool isTaskKilled(SExecTaskInfo* pTaskInfo); int32_t checkForQueryBuf(size_t numOfTables); @@ -1095,7 +1094,7 @@ void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput); int32_t buildDataBlockFromGroupRes(SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock, SExprSupp* pSup, SGroupResInfo* pGroupResInfo); int32_t saveSessionDiscBuf(SStreamState* pState, SSessionKey* key, void* buf, int32_t size); -int32_t buildSessionResultDataBlock(SExecTaskInfo* pTaskInfo, SStreamState* pState, SSDataBlock* pBlock, +int32_t buildSessionResultDataBlock(SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock, SExprSupp* pSup, SGroupResInfo* pGroupResInfo); int32_t setOutputBuf(SStreamState* pState, STimeWindow* win, SResultRow** pResult, int64_t tableGroupId, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset, SAggSupporter* pAggSup); diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c index ebf23ba6bc61e99832125bf652c84713d5eed4ed..00a338cc419a4f7b0a2918afbf35a06992a2750f 100644 --- a/source/libs/executor/src/cachescanoperator.c +++ b/source/libs/executor/src/cachescanoperator.c @@ -27,7 +27,8 @@ static SSDataBlock* doScanCache(SOperatorInfo* pOperator); static void destroyLastrowScanOperator(void* param); -static int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds); +static int32_t extractCacheScanSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds); +static SArray* removeRedundantTsCol(SLastRowScanPhysiNode* pScanNode, SArray* pColMatchInfo); SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SReadHandle* readHandle, SExecTaskInfo* pTaskInfo) { @@ -40,12 +41,15 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe } pInfo->readHandle = *readHandle; - pInfo->pRes = createResDataBlock(pScanNode->scan.node.pOutputDataBlockDesc); + + SDataBlockDescNode* pDescNode = pScanNode->scan.node.pOutputDataBlockDesc; + pInfo->pRes = createResDataBlock(pDescNode); int32_t numOfCols = 0; - pInfo->pColMatchInfo = extractColMatchInfo(pScanNode->scan.pScanCols, pScanNode->scan.node.pOutputDataBlockDesc, - &numOfCols, COL_MATCH_FROM_COL_ID); - code = extractTargetSlotId(pInfo->pColMatchInfo, pTaskInfo, &pInfo->pSlotIds); + SArray* pColMatchInfo = extractColMatchInfo(pScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID); + pInfo->pColMatchInfo = removeRedundantTsCol(pScanNode, pColMatchInfo); + + code = extractCacheScanSlotId(pInfo->pColMatchInfo, pTaskInfo, &pInfo->pSlotIds); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -58,7 +62,7 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe // partition by tbname if (taosArrayGetSize(pTableList->pGroupList) == taosArrayGetSize(pTableList->pTableList)) { - pInfo->retrieveType = CACHESCAN_RETRIEVE_TYPE_ALL | CACHESCAN_RETRIEVE_LAST_ROW; + pInfo->retrieveType = CACHESCAN_RETRIEVE_TYPE_ALL|(pScanNode->ignoreNull? CACHESCAN_RETRIEVE_LAST:CACHESCAN_RETRIEVE_LAST_ROW); code = tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pTableList->pTableList, taosArrayGetSize(pInfo->pColMatchInfo), &pInfo->pLastrowReader); if (code != TSDB_CODE_SUCCESS) { @@ -67,16 +71,14 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe pInfo->pBufferredRes = createOneDataBlock(pInfo->pRes, false); blockDataEnsureCapacity(pInfo->pBufferredRes, pOperator->resultInfo.capacity); - } else { // by tags - pInfo->retrieveType = CACHESCAN_RETRIEVE_TYPE_SINGLE | CACHESCAN_RETRIEVE_LAST_ROW; + } else { // by tags + pInfo->retrieveType = CACHESCAN_RETRIEVE_TYPE_SINGLE|(pScanNode->ignoreNull? CACHESCAN_RETRIEVE_LAST:CACHESCAN_RETRIEVE_LAST_ROW); } if (pScanNode->scan.pScanPseudoCols != NULL) { - SExprSupp* pPseudoExpr = &pInfo->pseudoExprSup; - - pPseudoExpr->pExprInfo = createExprInfo(pScanNode->scan.pScanPseudoCols, NULL, &pPseudoExpr->numOfExprs); - pPseudoExpr->pCtx = - createSqlFunctionCtx(pPseudoExpr->pExprInfo, pPseudoExpr->numOfExprs, &pPseudoExpr->rowEntryInfoOffset); + SExprSupp* p = &pInfo->pseudoExprSup; + p->pExprInfo = createExprInfo(pScanNode->scan.pScanPseudoCols, NULL, &p->numOfExprs); + p->pCtx = createSqlFunctionCtx(p->pExprInfo, p->numOfExprs, &p->rowEntryInfoOffset); } pOperator->name = "LastrowScanOperator"; @@ -88,7 +90,7 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock); pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doScanCache, NULL, NULL, destroyLastrowScanOperator, NULL, NULL, NULL); + createOperatorFpSet(operatorDummyOpenFn, doScanCache, NULL, NULL, destroyLastrowScanOperator, NULL); pOperator->cost.openCost = 0; return pOperator; @@ -130,7 +132,9 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { // check for tag values int32_t resultRows = pInfo->pBufferredRes->info.rows; - ASSERT(resultRows == taosArrayGetSize(pInfo->pUidList)); + + // the results may be null, if last values are all null + ASSERT(resultRows == 0 || resultRows == taosArrayGetSize(pInfo->pUidList)); pInfo->indexOfBufferedRes = 0; } @@ -162,7 +166,9 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { if (pTableList->map != NULL) { int64_t* groupId = taosHashGet(pTableList->map, &pInfo->pRes->info.uid, sizeof(int64_t)); - pInfo->pRes->info.groupId = *groupId; + if (groupId != NULL) { + pInfo->pRes->info.groupId = *groupId; + } } else { ASSERT(taosArrayGetSize(pTableList->pTableList) == 1); STableKeyInfo* pKeyInfo = taosArrayGet(pTableList->pTableList, 0); @@ -196,16 +202,20 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { if (pInfo->pRes->info.rows > 0) { if (pInfo->pseudoExprSup.numOfExprs > 0) { SExprSupp* pSup = &pInfo->pseudoExprSup; - pInfo->pRes->info.uid = *(tb_uid_t*)taosArrayGet(pInfo->pUidList, 0); STableKeyInfo* pKeyInfo = taosArrayGet(pGroupTableList, 0); pInfo->pRes->info.groupId = pKeyInfo->groupId; - code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pInfo->pRes, - GET_TASKID(pTaskInfo)); - if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; - return NULL; + if (taosArrayGetSize(pInfo->pUidList) > 0) { + ASSERT((pInfo->retrieveType & CACHESCAN_RETRIEVE_LAST_ROW) == CACHESCAN_RETRIEVE_LAST_ROW); + + pInfo->pRes->info.uid = *(tb_uid_t*)taosArrayGet(pInfo->pUidList, 0); + code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pInfo->pRes, + GET_TASKID(pTaskInfo)); + if (code != TSDB_CODE_SUCCESS) { + pTaskInfo->code = code; + return NULL; + } } } @@ -234,7 +244,7 @@ void destroyLastrowScanOperator(void* param) { taosMemoryFreeClear(param); } -int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds) { +int32_t extractCacheScanSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds) { size_t numOfCols = taosArrayGetSize(pColMatchInfo); *pSlotIds = taosMemoryMalloc(numOfCols * sizeof(int32_t)); @@ -242,16 +252,18 @@ int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInf return TSDB_CODE_OUT_OF_MEMORY; } + SSchemaWrapper* pWrapper = pTaskInfo->schemaInfo.sw; + for (int32_t i = 0; i < numOfCols; ++i) { SColMatchInfo* pColMatch = taosArrayGet(pColMatchInfo, i); - for (int32_t j = 0; j < pTaskInfo->schemaInfo.sw->nCols; ++j) { - if (pColMatch->colId == pTaskInfo->schemaInfo.sw->pSchema[j].colId && + for (int32_t j = 0; j < pWrapper->nCols; ++j) { + if (pColMatch->colId == pWrapper->pSchema[j].colId && pColMatch->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { (*pSlotIds)[pColMatch->targetSlotId] = -1; break; } - if (pColMatch->colId == pTaskInfo->schemaInfo.sw->pSchema[j].colId) { + if (pColMatch->colId == pWrapper->pSchema[j].colId) { (*pSlotIds)[pColMatch->targetSlotId] = j; break; } @@ -259,4 +271,27 @@ int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInf } return TSDB_CODE_SUCCESS; +} + +SArray* removeRedundantTsCol(SLastRowScanPhysiNode* pScanNode, SArray* pColMatchInfo) { + if (!pScanNode->ignoreNull) { // retrieve cached last value + return pColMatchInfo; + } + + SArray* pMatchInfo = taosArrayInit(taosArrayGetSize(pColMatchInfo), sizeof(SColMatchInfo)); + + for (int32_t i = 0; i < taosArrayGetSize(pColMatchInfo); ++i) { + SColMatchInfo* pColInfo = taosArrayGet(pColMatchInfo, i); + + int32_t slotId = pColInfo->targetSlotId; + SNodeList* pList = pScanNode->scan.node.pOutputDataBlockDesc->pSlots; + + SSlotDescNode* pDesc = (SSlotDescNode*)nodesListGetNode(pList, slotId); + if (pDesc->dataType.type != TSDB_DATA_TYPE_TIMESTAMP) { + taosArrayPush(pMatchInfo, pColInfo); + } + } + + taosArrayDestroy(pColMatchInfo); + return pMatchInfo; } \ No newline at end of file diff --git a/source/libs/executor/src/dataDeleter.c b/source/libs/executor/src/dataDeleter.c index 55978855d16100481a301ccf59ea852e68e30b64..2ed83a6469645f685bd1be50b5896e14331e15bb 100644 --- a/source/libs/executor/src/dataDeleter.c +++ b/source/libs/executor/src/dataDeleter.c @@ -103,7 +103,7 @@ static void toDataCacheEntry(SDataDeleterHandle* pHandle, const SInputData* pInp pRes->ekey = pHandle->pDeleter->deleteTimeRange.ekey; } - qDebug("delete %ld rows, from %ld to %ld", pRes->affectedRows, pRes->skey, pRes->ekey); + qDebug("delete %" PRId64 " rows, from %" PRId64 " to %" PRId64 "", pRes->affectedRows, pRes->skey, pRes->ekey); pBuf->useSize += pEntry->dataLen; @@ -150,9 +150,15 @@ static int32_t getStatus(SDataDeleterHandle* pDeleter) { static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) { SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle; SDataDeleterBuf* pBuf = taosAllocateQitem(sizeof(SDataDeleterBuf), DEF_QITEM); - if (NULL == pBuf || !allocBuf(pDeleter, pInput, pBuf)) { + if (NULL == pBuf) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } + + if (!allocBuf(pDeleter, pInput, pBuf)) { + taosFreeQitem(pBuf); + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + toDataCacheEntry(pDeleter, pInput, pBuf); taosWriteQitem(pDeleter->pDataBlocks, pBuf); *pContinue = (DS_BUF_LOW == updateStatus(pDeleter) ? true : false); @@ -177,6 +183,7 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, bool* pQueryE SDataDeleterBuf* pBuf = NULL; taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf); + ASSERT(NULL != pBuf); memcpy(&pDeleter->nextOutput, pBuf, sizeof(SDataDeleterBuf)); taosFreeQitem(pBuf); @@ -227,8 +234,11 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { while (!taosQueueEmpty(pDeleter->pDataBlocks)) { SDataDeleterBuf* pBuf = NULL; taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf); - taosMemoryFreeClear(pBuf->pData); - taosFreeQitem(pBuf); + + if (pBuf != NULL) { + taosMemoryFreeClear(pBuf->pData); + taosFreeQitem(pBuf); + } } taosCloseQueue(pDeleter->pDataBlocks); taosThreadMutexDestroy(&pDeleter->mutex); @@ -244,10 +254,12 @@ static int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) { int32_t createDataDeleter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam) { + int32_t code = TSDB_CODE_SUCCESS; + SDataDeleterHandle* deleter = taosMemoryCalloc(1, sizeof(SDataDeleterHandle)); if (NULL == deleter) { - terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; - return TSDB_CODE_QRY_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _end; } SDataDeleterNode* pDeleterNode = (SDataDeleterNode*)pDataSink; @@ -260,17 +272,30 @@ int32_t createDataDeleter(SDataSinkManager* pManager, const SDataSinkNode* pData deleter->pManager = pManager; deleter->pDeleter = pDeleterNode; deleter->pSchema = pDataSink->pInputDataBlockDesc; + + if(pParam == NULL) { + code = TSDB_CODE_QRY_INVALID_INPUT; + qError("invalid input param in creating data deleter, code%s", tstrerror(code)); + goto _end; + } + deleter->pParam = pParam; deleter->status = DS_BUF_EMPTY; deleter->queryEnd = false; deleter->pDataBlocks = taosOpenQueue(); taosThreadMutexInit(&deleter->mutex, NULL); if (NULL == deleter->pDataBlocks) { - terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _end; + } + + *pHandle = deleter; + return code; + + _end: + if (deleter != NULL) { destroyDataSinker((SDataSinkHandle*)deleter); taosMemoryFree(deleter); - return TSDB_CODE_QRY_OUT_OF_MEMORY; } - *pHandle = deleter; - return TSDB_CODE_SUCCESS; + return code; } diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index ffdcf48d48c704eccbb430c3bddd843f704d80f7..b758e4b1dd9dd36ac0f668729b9aa74e9b095c4d 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -231,8 +231,10 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { while (!taosQueueEmpty(pDispatcher->pDataBlocks)) { SDataDispatchBuf* pBuf = NULL; taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf); - taosMemoryFreeClear(pBuf->pData); - taosFreeQitem(pBuf); + if (pBuf != NULL) { + taosMemoryFreeClear(pBuf->pData); + taosFreeQitem(pBuf); + } } taosCloseQueue(pDispatcher->pDataBlocks); taosThreadMutexDestroy(&pDispatcher->mutex); diff --git a/source/libs/executor/src/dataInserter.c b/source/libs/executor/src/dataInserter.c index ed455e5e75b07ebe78149d77395368afc6c89808..78afdd16b79bc45879b50aa031b2008cb8fcfba2 100644 --- a/source/libs/executor/src/dataInserter.c +++ b/source/libs/executor/src/dataInserter.c @@ -324,10 +324,13 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat tsdbGetTableSchema(inserter->pParam->readHandle->vnode, pInserterNode->tableId, &inserter->pSchema, &suid); if (code) { destroyDataSinker((SDataSinkHandle*)inserter); + taosMemoryFree(inserter); return code; } if (pInserterNode->stableId != suid) { + destroyDataSinker((SDataSinkHandle*)inserter); + taosMemoryFree(inserter); terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; return terrno; } @@ -335,6 +338,8 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat inserter->pDataBlocks = taosArrayInit(1, POINTER_BYTES); taosThreadMutexInit(&inserter->mutex, NULL); if (NULL == inserter->pDataBlocks) { + destroyDataSinker((SDataSinkHandle*)inserter); + taosMemoryFree(inserter); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return TSDB_CODE_QRY_OUT_OF_MEMORY; } diff --git a/source/libs/executor/src/dataSinkMgt.c b/source/libs/executor/src/dataSinkMgt.c index 206f3719fa0ad7a175d630c1caa346a8cd203c4c..2b50be33ad29d4cb11d764dd090d2126c1fb13a0 100644 --- a/source/libs/executor/src/dataSinkMgt.c +++ b/source/libs/executor/src/dataSinkMgt.c @@ -33,7 +33,7 @@ int32_t dsDataSinkGetCacheSize(SDataSinkStat* pStat) { return 0; } -int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam) { +int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam, const char* id) { switch ((int)nodeType(pDataSink)) { case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return createDataDispatcher(&gDataSinkManager, pDataSink, pHandle); @@ -42,7 +42,9 @@ int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHand case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: return createDataInserter(&gDataSinkManager, pDataSink, pHandle, pParam); } - return TSDB_CODE_FAILED; + + qError("invalid input node type:%d, %s", nodeType(pDataSink), id); + return TSDB_CODE_QRY_INVALID_INPUT; } int32_t dsPutDataBlock(DataSinkHandle handle, const SInputData* pInput, bool* pContinue) { diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 79f6166079b4701e2399203cfd6bdd0f2d73b444..11d6665614c4a4075fbd7cc056cce2fcc107a946 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -122,7 +122,7 @@ void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, in if (order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC) { __compar_fn_t fn = (order == TSDB_ORDER_ASC) ? resultrowComparAsc : resultrowComparDesc; - int32_t size = POINTER_BYTES; + int32_t size = POINTER_BYTES; taosSort(pGroupResInfo->pRows->pData, taosArrayGetSize(pGroupResInfo->pRows), size, fn); } @@ -422,16 +422,6 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray* goto end; } } - /*else { - code = metaGetTableTagsByUids(metaHandle, suid, uidList, tags); - if (code != 0) { - terrno = code; - qError("failed to get table from meta idx, reason: %s, suid:%" PRId64, tstrerror(code), suid); - goto end; - } else { - qInfo("succ to get table from meta idx, suid:%" PRId64, suid); - } - }*/ int32_t rows = taosArrayGetSize(uidList); if (rows == 0) { @@ -762,8 +752,8 @@ end: } static int tableUidCompare(const void* a, const void* b) { - uint64_t u1 = *(uint64_t*)a; - uint64_t u2 = *(uint64_t*)b; + int64_t u1 = *(uint64_t*)a; + int64_t u2 = *(uint64_t*)b; if (u1 == u2) { return 0; } @@ -930,7 +920,7 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); int64_t* uid = taosArrayGet(res, i); - qDebug("tagfilter get uid:%ld, res:%d", *uid, *(bool*)var); + qDebug("tagfilter get uid:%" PRId64 ", res:%d", *uid, *(bool*)var); if (*(bool*)var == false) { taosArrayRemove(res, i); j++; @@ -952,7 +942,7 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, return TSDB_CODE_OUT_OF_MEMORY; } - qDebug("tagfilter get uid:%ld", info.uid); + qDebug("tagfilter get uid:%" PRId64 "", info.uid); } taosArrayDestroy(res); @@ -1212,11 +1202,10 @@ void createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) { #if 1 // todo refactor: add the parameter for tbname function const char* name = "tbname"; - int32_t len = strlen(name); + int32_t len = strlen(name); if (!pFuncNode->pParameterList && (memcmp(pExprNode->_function.functionName, name, len) == 0) && pExprNode->_function.functionName[len] == 0) { - pFuncNode->pParameterList = nodesMakeList(); ASSERT(LIST_LENGTH(pFuncNode->pParameterList) == 0); SValueNode* res = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); @@ -1261,13 +1250,13 @@ void createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) { } else if (type == QUERY_NODE_CASE_WHEN) { pExp->pExpr->nodeType = QUERY_NODE_OPERATOR; SCaseWhenNode* pCaseNode = (SCaseWhenNode*)pNode; - + pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam)); pExp->base.numOfParams = 1; - + SDataType* pType = &pCaseNode->node.resType; - pExp->base.resSchema = createResSchema(pType->type, pType->bytes, slotId, pType->scale, - pType->precision, pCaseNode->node.aliasName); + pExp->base.resSchema = + createResSchema(pType->type, pType->bytes, slotId, pType->scale, pType->precision, pCaseNode->node.aliasName); pExp->pExpr->_optrRoot.pRootNode = pNode; } else { ASSERT(0); diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 0d861c1fb94a93ad9524993ea582f558b941e19e..fb4248e886fdb3a1428f5aadd9966690fa3f0282 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -250,6 +250,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo qDebug(" %d qualified child tables added into stream scanner", (int32_t)taosArrayGetSize(qa)); code = tqReaderAddTbUidList(pScanInfo->tqReader, qa); if (code != TSDB_CODE_SUCCESS) { + taosArrayDestroy(qa); return code; } @@ -261,6 +262,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo assignUid = groupbyTbname(pScanInfo->pGroupTags); keyBuf = taosMemoryMalloc(bufLen); if (keyBuf == NULL) { + taosArrayDestroy(qa); return TSDB_CODE_OUT_OF_MEMORY; } } @@ -277,6 +279,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo &keyInfo.groupId); if (code != TSDB_CODE_SUCCESS) { taosMemoryFree(keyBuf); + taosArrayDestroy(qa); return code; } } @@ -298,8 +301,6 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo taosHashPut(pTaskInfo->tableqinfoList.map, uid, sizeof(*uid), &keyInfo.groupId, sizeof(keyInfo.groupId)); } - /*}*/ - if (keyBuf != NULL) { taosMemoryFree(keyBuf); } @@ -357,7 +358,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SDataSinkMgtCfg cfg = {.maxDataBlockNum = 10000, .maxDataBlockNumPerQuery = 5000}; code = dsDataSinkMgtInit(&cfg); if (code != TSDB_CODE_SUCCESS) { - qError("failed to dsDataSinkMgtInit, code: %s", tstrerror(code)); + qError("failed to dsDataSinkMgtInit, code:%s, %s", tstrerror(code), (*pTask)->id.str); goto _error; } @@ -365,11 +366,11 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, void* pSinkParam = NULL; code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, pTaskInfo, readHandle); if (code != TSDB_CODE_SUCCESS) { - qError("failed to createDataSinkParam, code: %s", tstrerror(code)); + qError("failed to createDataSinkParam, vgId:%d, code:%s, %s", vgId, tstrerror(code), (*pTask)->id.str); goto _error; } - code = dsCreateDataSinker(pSubplan->pDataSink, handle, pSinkParam); + code = dsCreateDataSinker(pSubplan->pDataSink, handle, pSinkParam, (*pTask)->id.str); if (code != TSDB_CODE_SUCCESS) { taosMemoryFreeClear(pSinkParam); } @@ -857,7 +858,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT tDeleteSSchemaWrapper(pTaskInfo->streamInfo.schema); pTaskInfo->streamInfo.schema = mtInfo.schema; - qDebug("tmqsnap qStreamPrepareScan snapshot data uid %ld ts %"PRId64, mtInfo.uid, pOffset->ts); + qDebug("tmqsnap qStreamPrepareScan snapshot data uid %" PRId64 " ts %" PRId64, mtInfo.uid, pOffset->ts); } else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_META) { SStreamRawScanInfo* pInfo = pOperator->info; SSnapContext* sContext = pInfo->sContext; @@ -865,7 +866,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT qError("setForSnapShot error. uid:%" PRIu64 " ,version:%" PRId64, pOffset->uid, pOffset->version); return -1; } - qDebug("tmqsnap qStreamPrepareScan snapshot meta uid %ld ts %"PRId64, pOffset->uid, pOffset->ts); + qDebug("tmqsnap qStreamPrepareScan snapshot meta uid %" PRId64 " ts %" PRId64, pOffset->uid, pOffset->ts); } else if (pOffset->type == TMQ_OFFSET__LOG) { SStreamRawScanInfo* pInfo = pOperator->info; tsdbReaderClose(pInfo->dataReader); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 641bcb0c5b0c22718182411c229019c72eaacf52..a1f7b700a4a6c86049d05b43ec0e241347c9f0e7 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -110,16 +110,13 @@ int32_t operatorDummyOpenFn(SOperatorInfo* pOperator) { } SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t streamFn, - __optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_encode_fn_t encode, - __optr_decode_fn_t decode, __optr_explain_fn_t explain) { + __optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_explain_fn_t explain) { SOperatorFpSet fpSet = { ._openFn = openFn, .getNextFn = nextFn, .getStreamResFn = streamFn, .cleanupFn = cleanup, .closeFn = closeFn, - .encodeResultRow = encode, - .decodeResultRow = decode, .getExplainFn = explain, }; @@ -403,25 +400,24 @@ void doApplyFunctions(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfo } } -static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order, - int32_t scanFlag, bool createDummyCol); +static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag, + bool createDummyCol); -static void doSetInputDataBlockInfo(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, - int32_t order) { - for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) { +static void doSetInputDataBlockInfo(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order) { + SqlFunctionCtx* pCtx = pExprSup->pCtx; + for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) { pCtx[i].order = order; pCtx[i].input.numOfRows = pBlock->info.rows; - setBlockSMAInfo(&pCtx[i], &pOperator->exprSupp.pExprInfo[i], pBlock); + setBlockSMAInfo(&pCtx[i], &pExprSup->pExprInfo[i], pBlock); pCtx[i].pSrcBlock = pBlock; } } -void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order, - int32_t scanFlag, bool createDummyCol) { +void setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag, bool createDummyCol) { if (pBlock->pBlockAgg != NULL) { - doSetInputDataBlockInfo(pOperator, pCtx, pBlock, order); + doSetInputDataBlockInfo(pExprSup, pBlock, order); } else { - doSetInputDataBlock(pOperator, pCtx, pBlock, order, scanFlag, createDummyCol); + doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol); } } @@ -462,16 +458,18 @@ static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunc for (int32_t i = 0; i < numOfRows; ++i) { colDataAppend(pColInfo, i, tmp, false); } + taosMemoryFree(tmp); } return TSDB_CODE_SUCCESS; } -static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order, - int32_t scanFlag, bool createDummyCol) { - int32_t code = TSDB_CODE_SUCCESS; +static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag, + bool createDummyCol) { + int32_t code = TSDB_CODE_SUCCESS; + SqlFunctionCtx* pCtx = pExprSup->pCtx; - for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) { + for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) { pCtx[i].order = order; pCtx[i].input.numOfRows = pBlock->info.rows; @@ -482,7 +480,7 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt pInput->uid = pBlock->info.uid; pInput->colDataAggIsSet = false; - SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i]; + SExprInfo* pOneExpr = &pExprSup->pExprInfo[i]; for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) { SFunctParam* pFuncParam = &pOneExpr->base.pParam[j]; if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) { @@ -568,7 +566,10 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc return TSDB_CODE_SUCCESS; } - pResult->info.groupId = pSrcBlock->info.groupId; + if (pResult != pSrcBlock) { + pResult->info.groupId = pSrcBlock->info.groupId; + memcpy(pResult->info.parTbName, pSrcBlock->info.parTbName, TSDB_TABLE_NAME_LEN); + } // if the source equals to the destination, it is to create a new column as the result of scalar // function or some operators. @@ -1774,7 +1775,7 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { } else { taosMemoryFree(pMsg->pData); pSourceDataInfo->code = code; - qDebug("%s fetch rsp received, index:%d, code:%s", pSourceDataInfo->taskId, index, tstrerror(code)); + qDebug("%s fetch rsp received, index:%d, error:%s", pSourceDataInfo->taskId, index, tstrerror(code)); } pSourceDataInfo->status = EX_SOURCE_DATA_READY; @@ -2301,7 +2302,7 @@ SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, NULL, - destroyExchangeOperatorInfo, NULL, NULL, NULL); + destroyExchangeOperatorInfo, NULL); return pOperator; _error: @@ -2433,7 +2434,7 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) { // the pDataBlock are always the same one, no need to call this again setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.groupId); - setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, scanFlag, true); + setInputDataBlock(pSup, pBlock, order, scanFlag, true); code = doAggregateImpl(pOperator, pSup->pCtx); if (code != 0) { T_LONG_JMP(pTaskInfo->env, code); @@ -2732,28 +2733,16 @@ static void doHandleRemainBlockFromNewGroup(SOperatorInfo* pOperator, SFillOpera static void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag) { SFillOperatorInfo* pInfo = pOperator->info; SExprSupp* pSup = &pOperator->exprSupp; - SSDataBlock* pResBlock = pInfo->pFinalRes; - - setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, scanFlag, false); + setInputDataBlock(pSup, pBlock, order, scanFlag, false); projectApplyFunctions(pSup->pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, pSup->numOfExprs, NULL); - pInfo->pRes->info.groupId = pBlock->info.groupId; - SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, pInfo->primaryTsCol); - SColumnInfoData* pSrc = taosArrayGet(pBlock->pDataBlock, pInfo->primarySrcSlotId); - colDataAssign(pDst, pSrc, pInfo->pRes->info.rows, &pResBlock->info); + // reset the row value before applying the no-fill functions to the input data block, which is "pBlock" in this case. + pInfo->pRes->info.rows = 0; + SExprSupp* pNoFillSupp = &pInfo->noFillExprSupp; + setInputDataBlock(pNoFillSupp, pBlock, order, scanFlag, false); - for (int32_t i = 0; i < pInfo->numOfNotFillExpr; ++i) { - SFillColInfo* pCol = &pInfo->pFillInfo->pFillCol[i + pInfo->numOfExpr]; - ASSERT(pCol->notFillCol); - - SExprInfo* pExpr = pCol->pExpr; - int32_t srcSlotId = pExpr->base.pParam[0].pCol->slotId; - int32_t dstSlotId = pExpr->base.resSchema.slotId; - - SColumnInfoData* pDst1 = taosArrayGet(pInfo->pRes->pDataBlock, dstSlotId); - SColumnInfoData* pSrc1 = taosArrayGet(pBlock->pDataBlock, srcSlotId); - colDataAssign(pDst1, pSrc1, pInfo->pRes->info.rows, &pResBlock->info); - } + projectApplyFunctions(pNoFillSupp->pExprInfo, pInfo->pRes, pBlock, pNoFillSupp->pCtx, pNoFillSupp->numOfExprs, NULL); + pInfo->pRes->info.groupId = pBlock->info.groupId; } static SSDataBlock* doFillImpl(SOperatorInfo* pOperator) { @@ -3046,32 +3035,41 @@ void cleanupExprSupp(SExprSupp* pSupp) { taosMemoryFree(pSupp->rowEntryInfoOffset); } -SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResultBlock, SNode* pCondition, SExprInfo* pScalarExprInfo, - int32_t numOfScalarExpr, bool mergeResult, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, + SExecTaskInfo* pTaskInfo) { SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + SSDataBlock* pResBlock = createResDataBlock(pAggNode->node.pOutputDataBlockDesc); + initBasicInfo(&pInfo->binfo, pResBlock); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; initResultSizeInfo(&pOperator->resultInfo, 4096); - int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); + + int32_t num = 0; + SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num); + int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } - initBasicInfo(&pInfo->binfo, pResultBlock); + int32_t numOfScalarExpr = 0; + SExprInfo* pScalarExprInfo = NULL; + if (pAggNode->pExprs != NULL) { + pScalarExprInfo = createExprInfo(pAggNode->pExprs, NULL, &numOfScalarExpr); + } + code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr); if (code != TSDB_CODE_SUCCESS) { goto _error; } - pInfo->binfo.mergeResultBlock = mergeResult; + pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock; pInfo->groupId = UINT64_MAX; - pInfo->pCondition = pCondition; + pInfo->pCondition = pAggNode->node.pConditions; pOperator->name = "TableAggregate"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_HASH_AGG; pOperator->blocking = true; @@ -3080,7 +3078,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(doOpenAggregateOptr, getAggregateResult, NULL, NULL, destroyAggOperatorInfo, - aggEncodeResultRow, aggDecodeResultRow, NULL); + NULL); if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) { STableScanInfo* pTableScanInfo = downstream->info; @@ -3100,7 +3098,9 @@ _error: destroyAggOperatorInfo(pInfo); } + cleanupExprSupp(&pOperator->exprSupp); taosMemoryFreeClear(pOperator); + pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -3133,10 +3133,7 @@ void destroyFillOperatorInfo(void* param) { pInfo->pRes = blockDataDestroy(pInfo->pRes); pInfo->pFinalRes = blockDataDestroy(pInfo->pFinalRes); - if (pInfo->pNotFillExprInfo != NULL) { - destroyExprInfo(pInfo->pNotFillExprInfo, pInfo->numOfNotFillExpr); - taosMemoryFree(pInfo->pNotFillExprInfo); - } + cleanupExprSupp(&pInfo->noFillExprSupp); taosMemoryFreeClear(pInfo->p); taosArrayDestroy(pInfo->pColMatchColInfo); @@ -3201,11 +3198,12 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t } static bool isWstartColumnExist(SFillOperatorInfo* pInfo) { - if (pInfo->numOfNotFillExpr == 0) { + if (pInfo->noFillExprSupp.numOfExprs == 0) { return false; } - for (int32_t i = 0; i < pInfo->numOfNotFillExpr; ++i) { - SExprInfo* exprInfo = pInfo->pNotFillExprInfo + i; + + for (int32_t i = 0; i < pInfo->noFillExprSupp.numOfExprs; ++i) { + SExprInfo* exprInfo = pInfo->noFillExprSupp.pExprInfo + i; if (exprInfo->pExpr->nodeType == QUERY_NODE_COLUMN && exprInfo->base.numOfParams == 1 && exprInfo->base.pParam[0].pCol->colType == COLUMN_TYPE_WINDOW_START) { return true; @@ -3214,25 +3212,24 @@ static bool isWstartColumnExist(SFillOperatorInfo* pInfo) { return false; } -static int32_t createWStartTsAsNotFillExpr(SFillOperatorInfo* pInfo, SFillPhysiNode* pPhyFillNode) { +static int32_t createPrimaryTsExprIfNeeded(SFillOperatorInfo* pInfo, SFillPhysiNode* pPhyFillNode, SExprSupp* pExprSupp, + const char* idStr) { bool wstartExist = isWstartColumnExist(pInfo); + if (wstartExist == false) { if (pPhyFillNode->pWStartTs->type != QUERY_NODE_TARGET) { - qError("pWStartTs of fill physical node is not a target node"); + qError("pWStartTs of fill physical node is not a target node, %s", idStr); return TSDB_CODE_QRY_SYS_ERROR; } - SExprInfo* notFillExprs = - taosMemoryRealloc(pInfo->pNotFillExprInfo, (pInfo->numOfNotFillExpr + 1) * sizeof(SExprInfo)); - if (notFillExprs == NULL) { + SExprInfo* pExpr = taosMemoryRealloc(pExprSupp->pExprInfo, (pExprSupp->numOfExprs + 1) * sizeof(SExprInfo)); + if (pExpr == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - createExprFromTargetNode(notFillExprs + pInfo->numOfNotFillExpr, (STargetNode*)pPhyFillNode->pWStartTs); - - ++pInfo->numOfNotFillExpr; - pInfo->pNotFillExprInfo = notFillExprs; - return TSDB_CODE_SUCCESS; + createExprFromTargetNode(&pExpr[pExprSupp->numOfExprs], (STargetNode*)pPhyFillNode->pWStartTs); + pExprSupp->numOfExprs += 1; + pExprSupp->pExprInfo = pExpr; } return TSDB_CODE_SUCCESS; @@ -3250,8 +3247,14 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* SExprInfo* pExprInfo = createExprInfo(pPhyFillNode->pFillExprs, NULL, &pInfo->numOfExpr); pOperator->exprSupp.pExprInfo = pExprInfo; - pInfo->pNotFillExprInfo = createExprInfo(pPhyFillNode->pNotFillExprs, NULL, &pInfo->numOfNotFillExpr); - int32_t code = createWStartTsAsNotFillExpr(pInfo, pPhyFillNode); + SExprSupp* pNoFillSupp = &pInfo->noFillExprSupp; + pNoFillSupp->pExprInfo = createExprInfo(pPhyFillNode->pNotFillExprs, NULL, &pNoFillSupp->numOfExprs); + int32_t code = createPrimaryTsExprIfNeeded(pInfo, pPhyFillNode, pNoFillSupp, pTaskInfo->id.str); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + + code = initExprSupp(pNoFillSupp, pNoFillSupp->pExprInfo, pNoFillSupp->numOfExprs); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -3280,7 +3283,7 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pInfo->pColMatchColInfo = extractColMatchInfo(pPhyFillNode->pFillExprs, pPhyFillNode->node.pOutputDataBlockDesc, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID); - code = initFillInfo(pInfo, pExprInfo, pInfo->numOfExpr, pInfo->pNotFillExprInfo, pInfo->numOfNotFillExpr, + code = initFillInfo(pInfo, pExprInfo, pInfo->numOfExpr, pNoFillSupp->pExprInfo, pNoFillSupp->numOfExprs, (SNodeListNode*)pPhyFillNode->pValues, pPhyFillNode->timeRange, pResultInfo->capacity, pTaskInfo->id.str, pInterval, type, order); if (code != TSDB_CODE_SUCCESS) { @@ -3300,7 +3303,7 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doFill, NULL, NULL, destroyFillOperatorInfo, NULL, NULL, NULL); + createOperatorFpSet(operatorDummyOpenFn, doFill, NULL, NULL, destroyFillOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); return pOperator; @@ -3330,8 +3333,6 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPT return pTaskInfo; } -static SArray* extractColumnInfo(SNodeList* pNodeList); - SSchemaWrapper* extractQueriedColumnSchema(SScanPhysiNode* pScanNode); int32_t extractTableSchemaInfo(SReadHandle* pHandle, SScanPhysiNode* pScanNode, SExecTaskInfo* pTaskInfo) { @@ -3708,48 +3709,16 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo pOptr = createProjectOperatorInfo(ops[0], (SProjectPhysiNode*)pPhyNode, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_AGG == type) { SAggPhysiNode* pAggNode = (SAggPhysiNode*)pPhyNode; - SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num); - SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc); - - int32_t numOfScalarExpr = 0; - SExprInfo* pScalarExprInfo = NULL; - if (pAggNode->pExprs != NULL) { - pScalarExprInfo = createExprInfo(pAggNode->pExprs, NULL, &numOfScalarExpr); - } - if (pAggNode->pGroupKeys != NULL) { - SArray* pColList = extractColumnInfo(pAggNode->pGroupKeys); - pOptr = createGroupOperatorInfo(ops[0], pExprInfo, num, pResBlock, pColList, pAggNode->node.pConditions, - pScalarExprInfo, numOfScalarExpr, pTaskInfo); + pOptr = createGroupOperatorInfo(ops[0], pAggNode, pTaskInfo); } else { - pOptr = createAggregateOperatorInfo(ops[0], pExprInfo, num, pResBlock, pAggNode->node.pConditions, - pScalarExprInfo, numOfScalarExpr, pAggNode->mergeDataBlock, pTaskInfo); + pOptr = createAggregateOperatorInfo(ops[0], pAggNode, pTaskInfo); } } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL == type) { SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode; - SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &num); - SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc); - - SInterval interval = {.interval = pIntervalPhyNode->interval, - .sliding = pIntervalPhyNode->sliding, - .intervalUnit = pIntervalPhyNode->intervalUnit, - .slidingUnit = pIntervalPhyNode->slidingUnit, - .offset = pIntervalPhyNode->offset, - .precision = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->node.resType.precision}; - - STimeWindowAggSupp as = { - .waterMark = pIntervalPhyNode->window.watermark, - .calTrigger = pIntervalPhyNode->window.triggerType, - .maxTs = INT64_MIN, - }; - ASSERT(as.calTrigger != STREAM_TRIGGER_MAX_DELAY); - - int32_t tsSlotId = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId; - bool isStream = (QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL == type); - pOptr = createIntervalOperatorInfo(ops[0], pExprInfo, num, pResBlock, &interval, tsSlotId, &as, pIntervalPhyNode, - pTaskInfo, isStream); - + bool isStream = (QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL == type); + pOptr = createIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo, isStream); } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL == type) { pOptr = createStreamIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL == type) { @@ -3813,39 +3782,6 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo return pOptr; } -SArray* extractColumnInfo(SNodeList* pNodeList) { - size_t numOfCols = LIST_LENGTH(pNodeList); - SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn)); - if (pList == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } - - for (int32_t i = 0; i < numOfCols; ++i) { - STargetNode* pNode = (STargetNode*)nodesListGetNode(pNodeList, i); - - if (nodeType(pNode->pExpr) == QUERY_NODE_COLUMN) { - SColumnNode* pColNode = (SColumnNode*)pNode->pExpr; - - SColumn c = extractColumnFromColumnNode(pColNode); - taosArrayPush(pList, &c); - } else if (nodeType(pNode->pExpr) == QUERY_NODE_VALUE) { - SValueNode* pValNode = (SValueNode*)pNode->pExpr; - SColumn c = {0}; - c.slotId = pNode->slotId; - c.colId = pNode->slotId; - c.type = pValNode->node.type; - c.bytes = pValNode->node.resType.bytes; - c.scale = pValNode->node.resType.scale; - c.precision = pValNode->node.resType.precision; - - taosArrayPush(pList, &c); - } - } - - return pList; -} - static int32_t extractTbscanInStreamOpTree(SOperatorInfo* pOperator, STableScanInfo** ppInfo) { if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { if (pOperator->numOfDownstream == 0) { @@ -4069,6 +4005,7 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead (*pTaskInfo)->sql = sql; sql = NULL; + (*pTaskInfo)->pSubplan = pPlan; (*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, &(*pTaskInfo)->tableqinfoList, pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user); @@ -4312,8 +4249,9 @@ int32_t saveSessionDiscBuf(SStreamState* pState, SSessionKey* key, void* buf, in return TSDB_CODE_SUCCESS; } -int32_t buildSessionResultDataBlock(SExecTaskInfo* pTaskInfo, SStreamState* pState, SSDataBlock* pBlock, +int32_t buildSessionResultDataBlock(SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock, SExprSupp* pSup, SGroupResInfo* pGroupResInfo) { + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SExprInfo* pExprInfo = pSup->pExprInfo; int32_t numOfExprs = pSup->numOfExprs; int32_t* rowEntryOffset = pSup->rowEntryInfoOffset; @@ -4327,6 +4265,10 @@ int32_t buildSessionResultDataBlock(SExecTaskInfo* pTaskInfo, SStreamState* pSta void* pVal = NULL; int32_t code = streamStateSessionGet(pState, pKey, &pVal, &size); ASSERT(code == 0); + if (code == -1) { + // coverity scan + continue; + } SResultRow* pRow = (SResultRow*)pVal; doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset); // no results, continue to check the next one @@ -4338,6 +4280,31 @@ int32_t buildSessionResultDataBlock(SExecTaskInfo* pTaskInfo, SStreamState* pSta if (pBlock->info.groupId == 0) { pBlock->info.groupId = pKey->groupId; + + if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE) { + SStreamStateAggOperatorInfo* pInfo = pOperator->info; + + char* tbname = taosHashGet(pInfo->pGroupIdTbNameMap, &pBlock->info.groupId, sizeof(int64_t)); + if (tbname != NULL) { + memcpy(pBlock->info.parTbName, tbname, TSDB_TABLE_NAME_LEN); + } else { + pBlock->info.parTbName[0] = 0; + } + } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION || + pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION || + pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) { + SStreamSessionAggOperatorInfo* pInfo = pOperator->info; + + char* tbname = taosHashGet(pInfo->pGroupIdTbNameMap, &pBlock->info.groupId, sizeof(int64_t)); + if (tbname != NULL) { + memcpy(pBlock->info.parTbName, tbname, TSDB_TABLE_NAME_LEN); + } else { + pBlock->info.parTbName[0] = 0; + } + } else { + ASSERT(0); + } + } else { // current value belongs to different group, it can't be packed into one datablock if (pBlock->info.groupId != pKey->groupId) { @@ -4383,4 +4350,4 @@ int32_t buildSessionResultDataBlock(SExecTaskInfo* pTaskInfo, SStreamState* pSta } blockDataUpdateTsWindow(pBlock, 0); return TSDB_CODE_SUCCESS; -} \ No newline at end of file +} diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index e62f72c8f8f1394adf3ae9a50816e4ba4057bc95..644f02f60dff5af916d40c1a20a0f2f583157319 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -30,6 +30,7 @@ static void* getCurrentDataGroupInfo(const SPartitionOperatorInfo* pInfo, SDa static int32_t* setupColumnOffset(const SSDataBlock* pBlock, int32_t rowCapacity); static int32_t setGroupResultOutputBuf(SOperatorInfo* pOperator, SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t bytes, uint64_t groupId, SDiskbasedBuf* pBuf, SAggSupporter* pAggSup); +static SArray* extractColumnInfo(SNodeList* pNodeList); static void freeGroupKey(void* param) { SGroupKeys* pKey = (SGroupKeys*)param; @@ -61,7 +62,7 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** int32_t numOfGroupCols = taosArrayGetSize(pGroupColList); for (int32_t i = 0; i < numOfGroupCols; ++i) { - SColumn* pCol = taosArrayGet(pGroupColList, i); + SColumn* pCol = (SColumn*) taosArrayGet(pGroupColList, i); (*keyLen) += pCol->bytes; // actual data + null_flag SGroupKeys key = {0}; @@ -359,7 +360,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) { } // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pOperator->exprSupp.pCtx, pBlock, order, scanFlag, true); + setInputDataBlock(&pOperator->exprSupp, pBlock, order, scanFlag, true); // there is an scalar expression that needs to be calculated right before apply the group aggregation. if (pInfo->scalarSup.pExprInfo != NULL) { @@ -396,46 +397,53 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) { return buildGroupResultDataBlock(pOperator); } -SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResultBlock, SArray* pGroupColList, SNode* pCondition, - SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode *pAggNode, SExecTaskInfo* pTaskInfo) { SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - pInfo->pGroupCols = pGroupColList; - pInfo->pCondition = pCondition; + SSDataBlock* pResBlock = createResDataBlock(pAggNode->node.pOutputDataBlockDesc); + initBasicInfo(&pInfo->binfo, pResBlock); + + int32_t numOfScalarExpr = 0; + SExprInfo* pScalarExprInfo = NULL; + if (pAggNode->pExprs != NULL) { + pScalarExprInfo = createExprInfo(pAggNode->pExprs, NULL, &numOfScalarExpr); + } + + pInfo->pGroupCols = extractColumnInfo(pAggNode->pGroupKeys); + pInfo->pCondition = pAggNode->node.pConditions; int32_t code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr); if (code != TSDB_CODE_SUCCESS) { goto _error; } - code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pGroupColList); + initResultSizeInfo(&pOperator->resultInfo, 4096); + code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pInfo->pGroupCols); if (code != TSDB_CODE_SUCCESS) { goto _error; } - initResultSizeInfo(&pOperator->resultInfo, 4096); - code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, pInfo->groupKeyLen, pTaskInfo->id.str); + int32_t num = 0; + SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num); + code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, pInfo->groupKeyLen, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } - initBasicInfo(&pInfo->binfo, pResultBlock); initResultRowInfo(&pInfo->binfo.resultRowInfo); pOperator->name = "GroupbyAggOperator"; pOperator->blocking = true; pOperator->status = OP_NOT_OPENED; - // pOperator->operatorType = OP_Groupby; pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, hashGroupbyAggregate, NULL, NULL, - destroyGroupOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); + destroyGroupOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -445,14 +453,14 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx _error: pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; - destroyGroupOperatorInfo(pInfo); + if (pInfo != NULL) { + destroyGroupOperatorInfo(pInfo); + } taosMemoryFreeClear(pOperator); return NULL; } static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) { - // SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - SPartitionOperatorInfo* pInfo = pOperator->info; for (int32_t j = 0; j < pBlock->info.rows; ++j) { @@ -757,11 +765,9 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition goto _error; } - SSDataBlock* pResBlock = createResDataBlock(pPartNode->node.pOutputDataBlockDesc); int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pPartNode->pTargets, NULL, &numOfCols); - pInfo->pGroupCols = extractPartitionColInfo(pPartNode->pPartitionKeys); if (pPartNode->pExprs != NULL) { @@ -781,7 +787,9 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition uint32_t defaultPgsz = 0; uint32_t defaultBufsz = 0; - getBufferPgSize(pResBlock->info.rowSize, &defaultPgsz, &defaultBufsz); + + pInfo->binfo.pRes = createResDataBlock(pPartNode->node.pOutputDataBlockDesc); + getBufferPgSize(pInfo->binfo.pRes->info.rowSize, &defaultPgsz, &defaultBufsz); if (!osTempSpaceAvailable()) { terrno = TSDB_CODE_NO_AVAIL_DISK; @@ -789,13 +797,14 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition qError("Create partition operator info failed since %s", terrstr(terrno)); goto _error; } + int32_t code = createDiskbasedBuf(&pInfo->pBuf, defaultPgsz, defaultBufsz, pTaskInfo->id.str, tsTempDir); if (code != TSDB_CODE_SUCCESS) { goto _error; } - pInfo->rowCapacity = blockDataGetCapacityInRow(pResBlock, getBufPageSize(pInfo->pBuf)); - pInfo->columnOffset = setupColumnOffset(pResBlock, pInfo->rowCapacity); + pInfo->rowCapacity = blockDataGetCapacityInRow(pInfo->binfo.pRes, getBufPageSize(pInfo->pBuf)); + pInfo->columnOffset = setupColumnOffset(pInfo->binfo.pRes, pInfo->rowCapacity); code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pInfo->pGroupCols); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -805,21 +814,22 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition pOperator->blocking = true; pOperator->status = OP_NOT_OPENED; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PARTITION; - pInfo->binfo.pRes = pResBlock; pOperator->exprSupp.numOfExprs = numOfCols; pOperator->exprSupp.pExprInfo = pExprInfo; pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, hashPartition, NULL, NULL, destroyPartitionOperatorInfo, - NULL, NULL, NULL); + NULL); code = appendDownstream(pOperator, &downstream, 1); return pOperator; _error: pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; - taosMemoryFreeClear(pInfo); + if (pInfo != NULL) { + destroyPartitionOperatorInfo(pInfo); + } taosMemoryFreeClear(pOperator); return NULL; } @@ -1085,7 +1095,7 @@ SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStr pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamHashPartition, NULL, NULL, - destroyStreamPartitionOperatorInfo, NULL, NULL, NULL); + destroyStreamPartitionOperatorInfo, NULL); initParDownStream(downstream, &pInfo->partitionSup, &pInfo->scalarSup); code = appendDownstream(pOperator, &downstream, 1); @@ -1097,3 +1107,37 @@ _error: taosMemoryFreeClear(pOperator); return NULL; } + + +SArray* extractColumnInfo(SNodeList* pNodeList) { + size_t numOfCols = LIST_LENGTH(pNodeList); + SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn)); + if (pList == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + for (int32_t i = 0; i < numOfCols; ++i) { + STargetNode* pNode = (STargetNode*)nodesListGetNode(pNodeList, i); + + if (nodeType(pNode->pExpr) == QUERY_NODE_COLUMN) { + SColumnNode* pColNode = (SColumnNode*)pNode->pExpr; + + SColumn c = extractColumnFromColumnNode(pColNode); + taosArrayPush(pList, &c); + } else if (nodeType(pNode->pExpr) == QUERY_NODE_VALUE) { + SValueNode* pValNode = (SValueNode*)pNode->pExpr; + SColumn c = {0}; + c.slotId = pNode->slotId; + c.colId = pNode->slotId; + c.type = pValNode->node.type; + c.bytes = pValNode->node.resType.bytes; + c.scale = pValNode->node.resType.scale; + c.precision = pValNode->node.resType.precision; + + taosArrayPush(pList, &c); + } + } + + return pList; +} diff --git a/source/libs/executor/src/joinoperator.c b/source/libs/executor/src/joinoperator.c index 53cfa6c27a880230aa919b245a8a16687498000c..8dac44684f0ffd992974bbf3f72b59e8d3f9efe9 100644 --- a/source/libs/executor/src/joinoperator.c +++ b/source/libs/executor/src/joinoperator.c @@ -59,15 +59,16 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t SSortMergeJoinPhysiNode* pJoinNode, SExecTaskInfo* pTaskInfo) { SJoinOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SJoinOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + + int32_t code = TSDB_CODE_SUCCESS; if (pOperator == NULL || pInfo == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; goto _error; } + int32_t numOfCols = 0; SSDataBlock* pResBlock = createResDataBlock(pJoinNode->node.pOutputDataBlockDesc); - - int32_t numOfCols = 0; - SExprInfo* pExprInfo = createExprInfo(pJoinNode->pTargets, NULL, &numOfCols); - + SExprInfo* pExprInfo = createExprInfo(pJoinNode->pTargets, NULL, &numOfCols); initResultSizeInfo(&pOperator->resultInfo, 4096); pInfo->pRes = pResBlock; @@ -84,8 +85,18 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t if (pJoinNode->pOnConditions != NULL && pJoinNode->node.pConditions != NULL) { pInfo->pCondAfterMerge = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); + if (pInfo->pCondAfterMerge == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _error; + } + SLogicConditionNode* pLogicCond = (SLogicConditionNode*)(pInfo->pCondAfterMerge); pLogicCond->pParameterList = nodesMakeList(); + if (pLogicCond->pParameterList == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _error; + } + nodesListMakeAppend(&pLogicCond->pParameterList, nodesCloneNode(pJoinNode->pOnConditions)); nodesListMakeAppend(&pLogicCond->pParameterList, nodesCloneNode(pJoinNode->node.pConditions)); pLogicCond->condType = LOGIC_COND_TYPE_AND; @@ -105,8 +116,8 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t } pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, NULL, destroyMergeJoinOperator, NULL, NULL, NULL); - int32_t code = appendDownstream(pOperator, pDownstream, numOfDownstream); + createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, NULL, destroyMergeJoinOperator, NULL); + code = appendDownstream(pOperator, pDownstream, numOfDownstream); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -114,9 +125,12 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t return pOperator; _error: - taosMemoryFree(pInfo); + if (pInfo != NULL) { + destroyMergeJoinOperator(pInfo); + } + taosMemoryFree(pOperator); - pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; + pTaskInfo->code = code; return NULL; } diff --git a/source/libs/executor/src/projectoperator.c b/source/libs/executor/src/projectoperator.c index ddb6d73aab2671cf8deb7ccbc867137b3a7fbd9f..b3ea7a5573049492ee0bb4d728928e804703351b 100644 --- a/source/libs/executor/src/projectoperator.c +++ b/source/libs/executor/src/projectoperator.c @@ -105,7 +105,7 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys pOperator->info = pInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doProjectOperation, NULL, NULL, - destroyProjectOperatorInfo, NULL, NULL, NULL); + destroyProjectOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -285,7 +285,7 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { T_LONG_JMP(pTaskInfo->env, code); } - setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, scanFlag, false); + setInputDataBlock(pSup, pBlock, order, scanFlag, false); blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); code = projectApplyFunctions(pSup->pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, pSup->numOfExprs, @@ -405,7 +405,7 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy pOperator->info = pInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doApplyIndefinitFunction, NULL, NULL, - destroyIndefinitOperatorInfo, NULL, NULL, NULL); + destroyIndefinitOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -446,7 +446,7 @@ static void doHandleDataBlock(SOperatorInfo* pOperator, SSDataBlock* pBlock, SOp } } - setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, scanFlag, false); + setInputDataBlock(pSup, pBlock, order, scanFlag, false); blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); code = projectApplyFunctions(pSup->pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, pSup->numOfExprs, diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 7385e9bb922ccefbdd4a81fb67af9dd3fc4d3f7d..f24c782a9ee2771ff5420a3481f4b956f4a1dc64 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -39,6 +39,64 @@ static int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capac static int32_t buildDbTableInfoBlock(bool sysInfo, const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size, const char* dbName); +static char* SYSTABLE_IDX_COLUMN[] = {"table_name", "db_name", "create_time", "columns", + "ttl", "stable_name", "vgroup_id', 'uid", "type"}; + +static char* SYSTABLE_IDX_EXCEPT[] = {"db_name", "vgroup_id"}; + +typedef int32_t (*__sys_filte)(void* pMeta, SNode* cond, SArray* result); +typedef int32_t (*__sys_check)(SNode* cond); + +typedef struct { + const char* name; + __sys_check chkFunc; + __sys_filte fltFunc; +} SSTabFltFuncDef; + +typedef struct { + void* pMeta; + void* pVnode; +} SSTabFltArg; + +static int32_t sysChkFilter__Comm(SNode* pNode); +static int32_t sysChkFilter__DBName(SNode* pNode); +static int32_t sysChkFilter__VgroupId(SNode* pNode); +static int32_t sysChkFilter__TableName(SNode* pNode); +static int32_t sysChkFilter__CreateTime(SNode* pNode); +static int32_t sysChkFilter__Ncolumn(SNode* pNode); +static int32_t sysChkFilter__Ttl(SNode* pNode); +static int32_t sysChkFilter__STableName(SNode* pNode); +static int32_t sysChkFilter__Uid(SNode* pNode); +static int32_t sysChkFilter__Type(SNode* pNode); + +static int32_t sysFilte__DbName(void* pMeta, SNode* pNode, SArray* result); +static int32_t sysFilte__VgroupId(void* pMeta, SNode* pNode, SArray* result); +static int32_t sysFilte__TableName(void* pMeta, SNode* pNode, SArray* result); +static int32_t sysFilte__CreateTime(void* pMeta, SNode* pNode, SArray* result); +static int32_t sysFilte__Ncolumn(void* pMeta, SNode* pNode, SArray* result); +static int32_t sysFilte__Ttl(void* pMeta, SNode* pNode, SArray* result); +static int32_t sysFilte__STableName(void* pMeta, SNode* pNode, SArray* result); +static int32_t sysFilte__Uid(void* pMeta, SNode* pNode, SArray* result); +static int32_t sysFilte__Type(void* pMeta, SNode* pNode, SArray* result); + +const SSTabFltFuncDef filterDict[] = { + {.name = "table_name", .chkFunc = sysChkFilter__TableName, .fltFunc = sysFilte__TableName}, + {.name = "db_name", .chkFunc = sysChkFilter__DBName, .fltFunc = sysFilte__DbName}, + {.name = "create_time", .chkFunc = sysChkFilter__CreateTime, .fltFunc = sysFilte__CreateTime}, + {.name = "columns", .chkFunc = sysChkFilter__Ncolumn, .fltFunc = sysFilte__Ncolumn}, + {.name = "ttl", .chkFunc = sysChkFilter__Ttl, .fltFunc = sysFilte__Ttl}, + {.name = "stable_name", .chkFunc = sysChkFilter__STableName, .fltFunc = sysFilte__STableName}, + {.name = "vgroup_id", .chkFunc = sysChkFilter__VgroupId, .fltFunc = sysFilte__VgroupId}, + {.name = "uid", .chkFunc = sysChkFilter__Uid, .fltFunc = sysFilte__Uid}, + {.name = "type", .chkFunc = sysChkFilter__Type, .fltFunc = sysFilte__Type}}; + +#define SYSTAB_FILTER_DICT_SIZE (sizeof(filterDict) / sizeof(filterDict[0])) + +static int32_t optSysTabFilte(void* arg, SNode* cond, SArray* result); +static int32_t optSysTabFilteImpl(void* arg, SNode* cond, SArray* result); +static int32_t optSysCheckOper(SNode* pOpear); +static int32_t optSysMergeRslt(SArray* multiRslt, SArray* reslt); + static bool processBlockWithProbability(const SSampleExecInfo* pInfo); static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo, SMetaReader* smrSuperTable, @@ -284,7 +342,6 @@ static bool doLoadBlockSMA(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, return true; } - static void doSetTagColumnData(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) { if (pTableScanInfo->pseudoSup.numOfExprs > 0) { SExprSupp* pSup = &pTableScanInfo->pseudoSup; @@ -466,16 +523,14 @@ int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int colDataAppendNNULL(pColInfoData, 0, pBlock->info.rows); } else if (pColInfoData->info.type != TSDB_DATA_TYPE_JSON) { colDataAppendNItems(pColInfoData, 0, data, pBlock->info.rows); + if (IS_VAR_DATA_TYPE(((const STagVal*)p)->type)) { + taosMemoryFree(data); + } } else { // todo opt for json tag for (int32_t i = 0; i < pBlock->info.rows; ++i) { colDataAppend(pColInfoData, i, data, false); } } - - if (data && (pColInfoData->info.type != TSDB_DATA_TYPE_JSON) && p != NULL && - IS_VAR_DATA_TYPE(((const STagVal*)p)->type)) { - taosMemoryFree(data); - } } } @@ -494,7 +549,13 @@ void setTbNameColData(void* pMeta, const SSDataBlock* pBlock, SColumnInfoData* p SScalarParam srcParam = {.numOfRows = pBlock->info.rows, .param = pMeta, .columnData = &infoData}; SScalarParam param = {.columnData = pColInfoData}; - fpSet.process(&srcParam, 1, ¶m); + + if (fpSet.process != NULL) { + fpSet.process(&srcParam, 1, ¶m); + } else { + qError("failed to get the corresponding callback function, functionId:%d", functionId); + } + colDataDestroy(&infoData); } @@ -737,7 +798,8 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc; int32_t numOfCols = 0; - SArray* pColList = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID); + pInfo->pColMatchInfo = + extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID); int32_t code = initQueryTableDataCond(&pInfo->cond, pTableScanNode); if (code != TSDB_CODE_SUCCESS) { @@ -765,7 +827,6 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, } pInfo->scanFlag = MAIN_SCAN; - pInfo->pColMatchInfo = pColList; pInfo->currentGroupId = -1; pInfo->assignBlockUid = pTableScanNode->assignBlockUid; @@ -778,7 +839,7 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScan, NULL, NULL, destroyTableScanOperatorInfo, - NULL, NULL, getTableScannerExecInfo); + getTableScannerExecInfo); // for non-blocking operator, the open cost is always 0 pOperator->cost.openCost = 0; @@ -806,7 +867,7 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo* pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScanImpl, NULL, NULL, NULL, NULL, NULL, NULL); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScanImpl, NULL, NULL, NULL, NULL); return pOperator; } @@ -927,7 +988,7 @@ SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* re pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doBlockInfoScan, NULL, NULL, - destroyBlockDistScanOperatorInfo, NULL, NULL, NULL); + destroyBlockDistScanOperatorInfo, NULL); return pOperator; _error: @@ -1550,7 +1611,7 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) { tsdbReaderClose(pTSInfo->dataReader); pTSInfo->dataReader = NULL; tqOffsetResetToLog(&pTaskInfo->streamInfo.prepareStatus, pTaskInfo->streamInfo.snapshotVer); - qDebug("queue scan tsdb over, switch to wal ver %"PRId64, pTaskInfo->streamInfo.snapshotVer + 1); + qDebug("queue scan tsdb over, switch to wal ver %" PRId64 "", pTaskInfo->streamInfo.snapshotVer + 1); if (tqSeekVer(pInfo->tqReader, pTaskInfo->streamInfo.snapshotVer + 1) < 0) { return NULL; } @@ -1708,9 +1769,12 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { } #endif +#if 1 if (pTaskInfo->streamInfo.recoverStep == STREAM_RECOVER_STEP__PREPARE) { STableScanInfo* pTSInfo = pInfo->pTableScanOp->info; memcpy(&pTSInfo->cond, &pTaskInfo->streamInfo.tableCond, sizeof(SQueryTableDataCond)); + pTSInfo->cond.startVersion = -1; + pTSInfo->cond.endVersion = pTaskInfo->streamInfo.fillHistoryVer1; pTSInfo->scanTimes = 0; pTSInfo->currentGroupId = -1; pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__SCAN; @@ -1719,12 +1783,14 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { if (pTaskInfo->streamInfo.recoverStep == STREAM_RECOVER_STEP__SCAN) { SSDataBlock* pBlock = doTableScan(pInfo->pTableScanOp); if (pBlock != NULL) { + calBlockTbName(&pInfo->tbnameCalSup, pBlock); + updateInfoFillBlockData(pInfo->pUpdateInfo, pBlock, pInfo->primaryTsIndex); return pBlock; } - // TODO fill in bloom filter pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__NONE; return NULL; } +#endif size_t total = taosArrayGetSize(pInfo->pBlockLists); // TODO: refactor @@ -1768,8 +1834,9 @@ FETCH_NEXT_BLOCK: generateDeleteResultBlock(pInfo, pDelBlock, pInfo->pDeleteDataRes); pInfo->pDeleteDataRes->info.type = STREAM_DELETE_RESULT; printDataBlock(pDelBlock, "stream scan delete result"); + blockDataDestroy(pDelBlock); + if (pInfo->pDeleteDataRes->info.rows > 0) { - blockDataDestroy(pDelBlock); return pInfo->pDeleteDataRes; } else { goto FETCH_NEXT_BLOCK; @@ -1982,7 +2049,7 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) { longjmp(pTaskInfo->env, terrno); } - qDebug("tmqsnap doRawScan get data uid:%ld", pBlock->info.uid); + qDebug("tmqsnap doRawScan get data uid:%" PRId64 "", pBlock->info.uid); pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_DATA; pTaskInfo->streamInfo.lastStatus.uid = pBlock->info.uid; pTaskInfo->streamInfo.lastStatus.ts = pBlock->info.window.ekey; @@ -1998,7 +2065,7 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) { } else { pTaskInfo->streamInfo.prepareStatus.uid = mtInfo.uid; pTaskInfo->streamInfo.prepareStatus.ts = INT64_MIN; - qDebug("tmqsnap change get data uid:%ld", mtInfo.uid); + qDebug("tmqsnap change get data uid:%" PRId64 "", mtInfo.uid); qStreamPrepareScan(pTaskInfo, &pTaskInfo->streamInfo.prepareStatus, pInfo->sContext->subType); } tDeleteSSchemaWrapper(mtInfo.schema); @@ -2090,24 +2157,30 @@ SOperatorInfo* createRawScanOperatorInfo(SReadHandle* pHandle, SExecTaskInfo* pT // create meta reader // create tq reader + int32_t code = TSDB_CODE_SUCCESS; + SStreamRawScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamRawScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { - terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; - return NULL; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _end; } pInfo->vnode = pHandle->vnode; pInfo->sContext = pHandle->sContext; pOperator->name = "RawStreamScanOperator"; - // pOperator->blocking = false; - // pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = createOperatorFpSet(NULL, doRawScan, NULL, NULL, destroyRawScanOperatorInfo, NULL, NULL, NULL); + pOperator->fpSet = createOperatorFpSet(NULL, doRawScan, NULL, NULL, destroyRawScanOperatorInfo, NULL); return pOperator; + +_end: + taosMemoryFree(pInfo); + taosMemoryFree(pOperator); + pTaskInfo->code = code; + return NULL; } static void destroyStreamScanOperatorInfo(void* param) { @@ -2280,12 +2353,19 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys __optr_fn_t nextFn = pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM ? doStreamScan : doQueueScan; pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, nextFn, NULL, NULL, destroyStreamScanOperatorInfo, NULL, NULL, NULL); + createOperatorFpSet(operatorDummyOpenFn, nextFn, NULL, NULL, destroyStreamScanOperatorInfo, NULL); return pOperator; _error: - taosMemoryFreeClear(pInfo); + if (pColIds != NULL) { + taosArrayDestroy(pColIds); + } + + if (pInfo != NULL) { + destroyStreamScanOperatorInfo(pInfo); + } + taosMemoryFreeClear(pOperator); return NULL; } @@ -2301,6 +2381,11 @@ static void destroySysScanOperator(void* param) { metaCloseTbCursor(pInfo->pCur); pInfo->pCur = NULL; } + if (pInfo->pIdx) { + taosArrayDestroy(pInfo->pIdx->uids); + taosMemoryFree(pInfo->pIdx); + pInfo->pIdx = NULL; + } taosArrayDestroy(pInfo->scanCols); taosMemoryFreeClear(pInfo->pUser); @@ -2768,174 +2853,768 @@ static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo, return TSDB_CODE_SUCCESS; } -static SSDataBlock* sysTableScanUserTables(SOperatorInfo* pOperator) { - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - SSysTableScanInfo* pInfo = pOperator->info; - if (pOperator->status == OP_EXEC_DONE) { - return NULL; +typedef int (*__optSysFilter)(void* a, void* b, int16_t dtype); + +int optSysDoCompare(__compar_fn_t func, int8_t comparType, void* a, void* b) { + int32_t cmp = func(a, b); + switch (comparType) { + case OP_TYPE_LOWER_THAN: + if (cmp < 0) return 0; + break; + case OP_TYPE_LOWER_EQUAL: { + if (cmp <= 0) return 0; + break; + } + case OP_TYPE_GREATER_THAN: { + if (cmp > 0) return 0; + break; + } + case OP_TYPE_GREATER_EQUAL: { + if (cmp >= 0) return 0; + break; + } + case OP_TYPE_EQUAL: { + if (cmp == 0) return 0; + break; + } + default: + return -1; } + return 1; +} - // the retrieve is executed on the mnode, so return tables that belongs to the information schema database. - if (pInfo->readHandle.mnd != NULL) { - buildSysDbTableInfo(pInfo, pOperator->resultInfo.capacity); +static int optSysFilterFuncImpl__LowerThan(void* a, void* b, int16_t dtype) { + __compar_fn_t func = getComparFunc(dtype, 0); + return optSysDoCompare(func, OP_TYPE_LOWER_THAN, a, b); +} +static int optSysFilterFuncImpl__LowerEqual(void* a, void* b, int16_t dtype) { + __compar_fn_t func = getComparFunc(dtype, 0); + return optSysDoCompare(func, OP_TYPE_LOWER_EQUAL, a, b); +} +static int optSysFilterFuncImpl__GreaterThan(void* a, void* b, int16_t dtype) { + __compar_fn_t func = getComparFunc(dtype, 0); + return optSysDoCompare(func, OP_TYPE_GREATER_THAN, a, b); +} +static int optSysFilterFuncImpl__GreaterEqual(void* a, void* b, int16_t dtype) { + __compar_fn_t func = getComparFunc(dtype, 0); + return optSysDoCompare(func, OP_TYPE_GREATER_EQUAL, a, b); +} +static int optSysFilterFuncImpl__Equal(void* a, void* b, int16_t dtype) { + __compar_fn_t func = getComparFunc(dtype, 0); + return optSysDoCompare(func, OP_TYPE_EQUAL, a, b); +} - doFilterResult(pInfo); - pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; +static int optSysFilterFuncImpl__NoEqual(void* a, void* b, int16_t dtype) { + __compar_fn_t func = getComparFunc(dtype, 0); + return optSysDoCompare(func, OP_TYPE_NOT_EQUAL, a, b); +} +static __optSysFilter optSysGetFilterFunc(int32_t ctype, bool* reverse) { + if (ctype == OP_TYPE_LOWER_EQUAL || ctype == OP_TYPE_LOWER_THAN) { + *reverse = true; + } + if (ctype == OP_TYPE_LOWER_THAN) + return optSysFilterFuncImpl__LowerThan; + else if (ctype == OP_TYPE_LOWER_EQUAL) + return optSysFilterFuncImpl__LowerEqual; + else if (ctype == OP_TYPE_GREATER_THAN) + return optSysFilterFuncImpl__GreaterThan; + else if (ctype == OP_TYPE_GREATER_EQUAL) + return optSysFilterFuncImpl__GreaterEqual; + else if (ctype == OP_TYPE_EQUAL) + return optSysFilterFuncImpl__Equal; + else if (ctype == OP_TYPE_NOT_EQUAL) + return optSysFilterFuncImpl__NoEqual; + return NULL; +} +static int32_t sysFilte__DbName(void* arg, SNode* pNode, SArray* result) { + void* pVnode = ((SSTabFltArg*)arg)->pVnode; - doSetOperatorCompleted(pOperator); - return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; - } else { - if (pInfo->pCur == NULL) { - pInfo->pCur = metaOpenTbCursor(pInfo->readHandle.meta); + const char* db = NULL; + vnodeGetInfo(pVnode, &db, NULL); + + SName sn = {0}; + char dbname[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; + tNameFromString(&sn, db, T_NAME_ACCT | T_NAME_DB); + + tNameGetDbName(&sn, varDataVal(dbname)); + varDataSetLen(dbname, strlen(varDataVal(dbname))); + + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + + bool reverse = false; + __optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse); + if (func == NULL) return -1; + + int ret = func(dbname, pVal->datum.p, TSDB_DATA_TYPE_VARCHAR); + if (ret == 0) return 0; + + return -2; +} +static int32_t sysFilte__VgroupId(void* arg, SNode* pNode, SArray* result) { + void* pVnode = ((SSTabFltArg*)arg)->pVnode; + + int64_t vgId = 0; + vnodeGetInfo(pVnode, NULL, (int32_t*)&vgId); + + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + + bool reverse = false; + + __optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse); + if (func == NULL) return -1; + + int ret = func(&vgId, &pVal->datum.i, TSDB_DATA_TYPE_BIGINT); + if (ret == 0) return 0; + + return -1; +} +static int32_t sysFilte__TableName(void* arg, SNode* pNode, SArray* result) { + void* pMeta = ((SSTabFltArg*)arg)->pMeta; + + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + bool reverse = false; + + __optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse); + if (func == NULL) return -1; + + SMetaFltParam param = {.suid = 0, + .cid = 0, + .type = TSDB_DATA_TYPE_VARCHAR, + .val = pVal->datum.p, + .reverse = reverse, + .filterFunc = func}; + + int32_t ret = metaFilterCreateTime(pMeta, ¶m, result); + if (ret == 0) return 0; + + return -1; +} + +static int32_t sysFilte__CreateTime(void* arg, SNode* pNode, SArray* result) { + void* pMeta = ((SSTabFltArg*)arg)->pMeta; + + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + bool reverse = false; + + __optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse); + SMetaFltParam param = {.suid = 0, + .cid = 0, + .type = TSDB_DATA_TYPE_BIGINT, + .val = &pVal->datum.i, + .reverse = reverse, + .filterFunc = func}; + int32_t ret = metaFilterCreateTime(pMeta, ¶m, result); + if (func == NULL) return -1; + return 0; +} +static int32_t sysFilte__Ncolumn(void* arg, SNode* pNode, SArray* result) { + void* pMeta = ((SSTabFltArg*)arg)->pMeta; + + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + bool reverse = false; + + __optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse); + if (func == NULL) return -1; + return -1; +} + +static int32_t sysFilte__Ttl(void* arg, SNode* pNode, SArray* result) { + void* pMeta = ((SSTabFltArg*)arg)->pMeta; + + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + bool reverse = false; + + __optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse); + if (func == NULL) return -1; + return -1; +} +static int32_t sysFilte__STableName(void* arg, SNode* pNode, SArray* result) { + void* pMeta = ((SSTabFltArg*)arg)->pMeta; + + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + bool reverse = false; + + __optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse); + if (func == NULL) return -1; + return -1; +} +static int32_t sysFilte__Uid(void* arg, SNode* pNode, SArray* result) { + void* pMeta = ((SSTabFltArg*)arg)->pMeta; + + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + bool reverse = false; + + __optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse); + if (func == NULL) return -1; + return -1; +} +static int32_t sysFilte__Type(void* arg, SNode* pNode, SArray* result) { + void* pMeta = ((SSTabFltArg*)arg)->pMeta; + + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + bool reverse = false; + + __optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse); + if (func == NULL) return -1; + return -1; +} +static int32_t sysChkFilter__Comm(SNode* pNode) { + // impl + SOperatorNode* pOper = (SOperatorNode*)pNode; + EOperatorType opType = pOper->opType; + if (opType != OP_TYPE_EQUAL && opType != OP_TYPE_LOWER_EQUAL && opType != OP_TYPE_LOWER_THAN && + OP_TYPE_GREATER_EQUAL && opType != OP_TYPE_GREATER_THAN) { + return -1; + } + return 0; +} + +static int32_t sysChkFilter__DBName(SNode* pNode) { + SOperatorNode* pOper = (SOperatorNode*)pNode; + + if (pOper->opType != OP_TYPE_EQUAL && pOper->opType != OP_TYPE_NOT_EQUAL) { + return -1; + } + + SValueNode* pVal = (SValueNode*)pOper->pRight; + if (!IS_STR_DATA_TYPE(pVal->node.resType.type)) { + return -1; + } + + return 0; +} +static int32_t sysChkFilter__VgroupId(SNode* pNode) { + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + if (!IS_INTEGER_TYPE(pVal->node.resType.type)) { + return -1; + } + return sysChkFilter__Comm(pNode); +} +static int32_t sysChkFilter__TableName(SNode* pNode) { + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + if (!IS_STR_DATA_TYPE(pVal->node.resType.type)) { + return -1; + } + return sysChkFilter__Comm(pNode); +} +static int32_t sysChkFilter__CreateTime(SNode* pNode) { + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + + if (!IS_TIMESTAMP_TYPE(pVal->node.resType.type)) { + return -1; + } + return sysChkFilter__Comm(pNode); +} + +static int32_t sysChkFilter__Ncolumn(SNode* pNode) { + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + + if (!IS_INTEGER_TYPE(pVal->node.resType.type)) { + return -1; + } + return sysChkFilter__Comm(pNode); +} +static int32_t sysChkFilter__Ttl(SNode* pNode) { + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + + if (!IS_INTEGER_TYPE(pVal->node.resType.type)) { + return -1; + } + return sysChkFilter__Comm(pNode); +} +static int32_t sysChkFilter__STableName(SNode* pNode) { + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + if (!IS_STR_DATA_TYPE(pVal->node.resType.type)) { + return -1; + } + return sysChkFilter__Comm(pNode); +} +static int32_t sysChkFilter__Uid(SNode* pNode) { + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + if (!IS_INTEGER_TYPE(pVal->node.resType.type)) { + return -1; + } + return sysChkFilter__Comm(pNode); +} +static int32_t sysChkFilter__Type(SNode* pNode) { + SOperatorNode* pOper = (SOperatorNode*)pNode; + SValueNode* pVal = (SValueNode*)pOper->pRight; + if (!IS_INTEGER_TYPE(pVal->node.resType.type)) { + return -1; + } + return sysChkFilter__Comm(pNode); +} +static int32_t optSysTabFilteImpl(void* arg, SNode* cond, SArray* result) { + if (optSysCheckOper(cond) != 0) return -1; + + SOperatorNode* pNode = (SOperatorNode*)cond; + + int8_t i = 0; + for (; i < SYSTAB_FILTER_DICT_SIZE; i++) { + if (strcmp(filterDict[i].name, ((SColumnNode*)(pNode->pLeft))->colName) == 0) { + break; } + } + if (i >= SYSTAB_FILTER_DICT_SIZE) return -1; - blockDataCleanup(pInfo->pRes); - int32_t numOfRows = 0; + if (filterDict[i].chkFunc(cond) != 0) return -1; - const char* db = NULL; - int32_t vgId = 0; - vnodeGetInfo(pInfo->readHandle.vnode, &db, &vgId); + return filterDict[i].fltFunc(arg, cond, result); +} - SName sn = {0}; - char dbname[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; - tNameFromString(&sn, db, T_NAME_ACCT | T_NAME_DB); +static int32_t optSysCheckOper(SNode* pOpear) { + if (nodeType(pOpear) != QUERY_NODE_OPERATOR) return -1; - tNameGetDbName(&sn, varDataVal(dbname)); - varDataSetLen(dbname, strlen(varDataVal(dbname))); + SOperatorNode* pOper = (SOperatorNode*)pOpear; + if (pOper->opType < OP_TYPE_GREATER_THAN || pOper->opType > OP_TYPE_NOT_EQUAL) { + return -1; + } - SSDataBlock* p = buildInfoSchemaTableMetaBlock(TSDB_INS_TABLE_TABLES); - blockDataEnsureCapacity(p, pOperator->resultInfo.capacity); + if (nodeType(pOper->pLeft) != QUERY_NODE_COLUMN || nodeType(pOper->pRight) != QUERY_NODE_VALUE) { + return -1; + } + return 0; +} - char n[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; +static int tableUidCompare(const void* a, const void* b) { + int64_t u1 = *(int64_t*)a; + int64_t u2 = *(int64_t*)b; + if (u1 == u2) { + return 0; + } + return u1 < u2 ? -1 : 1; +} +static int32_t optSysMergeRslt(SArray* mRslt, SArray* rslt) { + // TODO, find comm mem from mRslt + for (int i = 0; i < taosArrayGetSize(mRslt); i++) { + SArray* aRslt = taosArrayGetP(mRslt, i); + taosArrayAddAll(rslt, aRslt); + } + taosArraySort(rslt, tableUidCompare); + taosArrayRemoveDuplicate(rslt, tableUidCompare, NULL); - int32_t ret = 0; - while ((ret = metaTbCursorNext(pInfo->pCur)) == 0) { - STR_TO_VARSTR(n, pInfo->pCur->mr.me.name); + return 0; +} - // table name - SColumnInfoData* pColInfoData = taosArrayGet(p->pDataBlock, 0); - colDataAppend(pColInfoData, numOfRows, n, false); +static int32_t optSysTabFilte(void* arg, SNode* cond, SArray* result) { + int ret = -1; + if (nodeType(cond) == QUERY_NODE_OPERATOR) { + ret = optSysTabFilteImpl(arg, cond, result); + if (ret == 0) { + SOperatorNode* pOper = (SOperatorNode*)cond; + SColumnNode* pCol = (SColumnNode*)pOper->pLeft; + if (0 == strcmp(pCol->colName, "create_time")) { + return 0; + } + return -1; + } + return ret; + } - // database name - pColInfoData = taosArrayGet(p->pDataBlock, 1); - colDataAppend(pColInfoData, numOfRows, dbname, false); - - // vgId - pColInfoData = taosArrayGet(p->pDataBlock, 6); - colDataAppend(pColInfoData, numOfRows, (char*)&vgId, false); - - int32_t tableType = pInfo->pCur->mr.me.type; - if (tableType == TSDB_CHILD_TABLE) { - // create time - int64_t ts = pInfo->pCur->mr.me.ctbEntry.ctime; - pColInfoData = taosArrayGet(p->pDataBlock, 2); - colDataAppend(pColInfoData, numOfRows, (char*)&ts, false); - - SMetaReader mr = {0}; - metaReaderInit(&mr, pInfo->readHandle.meta, META_READER_NOLOCK); - - uint64_t suid = pInfo->pCur->mr.me.ctbEntry.suid; - int32_t code = metaGetTableEntryByUid(&mr, suid); - if (code != TSDB_CODE_SUCCESS) { - qError("failed to get super table meta, cname:%s, suid:0x%" PRIx64 ", code:%s, %s", pInfo->pCur->mr.me.name, - suid, tstrerror(terrno), GET_TASKID(pTaskInfo)); - metaReaderClear(&mr); - metaCloseTbCursor(pInfo->pCur); - pInfo->pCur = NULL; - T_LONG_JMP(pTaskInfo->env, terrno); - } + if (nodeType(cond) != QUERY_NODE_LOGIC_CONDITION || ((SLogicConditionNode*)cond)->condType != LOGIC_COND_TYPE_AND) { + return ret; + } + + SLogicConditionNode* pNode = (SLogicConditionNode*)cond; + SNodeList* pList = (SNodeList*)pNode->pParameterList; + + int32_t len = LIST_LENGTH(pList); + if (len <= 0) return ret; + + bool hasIdx = false; + bool hasRslt = true; + SArray* mRslt = taosArrayInit(len, POINTER_BYTES); + + SListCell* cell = pList->pHead; + for (int i = 0; i < len; i++) { + if (cell == NULL) break; + + SArray* aRslt = taosArrayInit(16, sizeof(int64_t)); + + ret = optSysTabFilteImpl(arg, cell->pNode, aRslt); + if (ret == 0) { + // has index + hasIdx = true; + taosArrayPush(mRslt, &aRslt); + } else if (ret == -2) { + // current vg + hasIdx = true; + hasRslt = false; + taosArrayDestroy(aRslt); + break; + } else { + taosArrayDestroy(aRslt); + } + cell = cell->pNext; + } + if (hasRslt && hasIdx) { + optSysMergeRslt(mRslt, result); + } + + for (int i = 0; i < taosArrayGetSize(mRslt); i++) { + SArray* aRslt = taosArrayGetP(mRslt, i); + taosArrayDestroy(aRslt); + } + taosArrayDestroy(mRslt); + if (hasRslt == false) { + return -2; + } + if (hasRslt && hasIdx) { + cell = pList->pHead; + for (int i = 0; i < len; i++) { + if (cell == NULL) break; + SOperatorNode* pOper = (SOperatorNode*)cell->pNode; + SColumnNode* pCol = (SColumnNode*)pOper->pLeft; + if (0 == strcmp(pCol->colName, "create_time")) { + return 0; + } + cell = cell->pNext; + } + return -1; + } + return -1; +} + +static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) { + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SSysTableScanInfo* pInfo = pOperator->info; + + SSysTableIndex* pIdx = pInfo->pIdx; + blockDataCleanup(pInfo->pRes); + int32_t numOfRows = 0; + + int ret = 0; + + const char* db = NULL; + int32_t vgId = 0; + vnodeGetInfo(pInfo->readHandle.vnode, &db, &vgId); + + SName sn = {0}; + char dbname[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; + tNameFromString(&sn, db, T_NAME_ACCT | T_NAME_DB); + + tNameGetDbName(&sn, varDataVal(dbname)); + varDataSetLen(dbname, strlen(varDataVal(dbname))); + + SSDataBlock* p = buildInfoSchemaTableMetaBlock(TSDB_INS_TABLE_TABLES); + blockDataEnsureCapacity(p, pOperator->resultInfo.capacity); + + char n[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + int32_t i = pIdx->lastIdx; + for (; i < taosArrayGetSize(pIdx->uids); i++) { + tb_uid_t* uid = taosArrayGet(pIdx->uids, i); + + SMetaReader mr = {0}; + metaReaderInit(&mr, pInfo->readHandle.meta, 0); + int32_t ret = metaGetTableEntryByUid(&mr, *uid); + if (ret < 0) { + metaReaderClear(&mr); + continue; + } + STR_TO_VARSTR(n, mr.me.name); + + // table name + SColumnInfoData* pColInfoData = taosArrayGet(p->pDataBlock, 0); + colDataAppend(pColInfoData, numOfRows, n, false); - // number of columns - pColInfoData = taosArrayGet(p->pDataBlock, 3); - colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.stbEntry.schemaRow.nCols, false); + // database name + pColInfoData = taosArrayGet(p->pDataBlock, 1); + colDataAppend(pColInfoData, numOfRows, dbname, false); - // super table name - STR_TO_VARSTR(n, mr.me.name); - pColInfoData = taosArrayGet(p->pDataBlock, 4); - colDataAppend(pColInfoData, numOfRows, n, false); + // vgId + pColInfoData = taosArrayGet(p->pDataBlock, 6); + colDataAppend(pColInfoData, numOfRows, (char*)&vgId, false); + + int32_t tableType = mr.me.type; + if (tableType == TSDB_CHILD_TABLE) { + // create time + int64_t ts = mr.me.ctbEntry.ctime; + pColInfoData = taosArrayGet(p->pDataBlock, 2); + colDataAppend(pColInfoData, numOfRows, (char*)&ts, false); + + SMetaReader mr1 = {0}; + metaReaderInit(&mr1, pInfo->readHandle.meta, META_READER_NOLOCK); + + int64_t suid = mr.me.ctbEntry.suid; + int32_t code = metaGetTableEntryByUid(&mr1, suid); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get super table meta, cname:%s, suid:0x%" PRIx64 ", code:%s, %s", pInfo->pCur->mr.me.name, + suid, tstrerror(terrno), GET_TASKID(pTaskInfo)); + metaReaderClear(&mr1); metaReaderClear(&mr); + T_LONG_JMP(pTaskInfo->env, terrno); + } + pColInfoData = taosArrayGet(p->pDataBlock, 3); + colDataAppend(pColInfoData, numOfRows, (char*)&mr1.me.stbEntry.schemaRow.nCols, false); - // table comment - pColInfoData = taosArrayGet(p->pDataBlock, 8); - if (pInfo->pCur->mr.me.ctbEntry.commentLen > 0) { - char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ctbEntry.comment); - colDataAppend(pColInfoData, numOfRows, comment, false); - } else if (pInfo->pCur->mr.me.ctbEntry.commentLen == 0) { - char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; - STR_TO_VARSTR(comment, ""); - colDataAppend(pColInfoData, numOfRows, comment, false); - } else { - colDataAppendNULL(pColInfoData, numOfRows); - } + // super table name + STR_TO_VARSTR(n, mr1.me.name); + pColInfoData = taosArrayGet(p->pDataBlock, 4); + colDataAppend(pColInfoData, numOfRows, n, false); + metaReaderClear(&mr1); + + // table comment + pColInfoData = taosArrayGet(p->pDataBlock, 8); + if (mr.me.ctbEntry.commentLen > 0) { + char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, mr.me.ctbEntry.comment); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else if (mr.me.ctbEntry.commentLen == 0) { + char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, ""); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else { + colDataAppendNULL(pColInfoData, numOfRows); + } + + // uid + pColInfoData = taosArrayGet(p->pDataBlock, 5); + colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.uid, false); - // uid - pColInfoData = taosArrayGet(p->pDataBlock, 5); - colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false); + // ttl + pColInfoData = taosArrayGet(p->pDataBlock, 7); + colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.ctbEntry.ttlDays, false); - // ttl - pColInfoData = taosArrayGet(p->pDataBlock, 7); - colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ctbEntry.ttlDays, false); + STR_TO_VARSTR(n, "CHILD_TABLE"); - STR_TO_VARSTR(n, "CHILD_TABLE"); - } else if (tableType == TSDB_NORMAL_TABLE) { - // create time - pColInfoData = taosArrayGet(p->pDataBlock, 2); - colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ctime, false); + } else if (tableType == TSDB_NORMAL_TABLE) { + // create time + pColInfoData = taosArrayGet(p->pDataBlock, 2); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ctime, false); - // number of columns - pColInfoData = taosArrayGet(p->pDataBlock, 3); - colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.schemaRow.nCols, false); + // number of columns + pColInfoData = taosArrayGet(p->pDataBlock, 3); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.schemaRow.nCols, false); - // super table name - pColInfoData = taosArrayGet(p->pDataBlock, 4); + // super table name + pColInfoData = taosArrayGet(p->pDataBlock, 4); + colDataAppendNULL(pColInfoData, numOfRows); + + // table comment + pColInfoData = taosArrayGet(p->pDataBlock, 8); + if (mr.me.ntbEntry.commentLen > 0) { + char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, mr.me.ntbEntry.comment); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else if (mr.me.ntbEntry.commentLen == 0) { + char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, ""); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else { colDataAppendNULL(pColInfoData, numOfRows); + } - // table comment - pColInfoData = taosArrayGet(p->pDataBlock, 8); - if (pInfo->pCur->mr.me.ntbEntry.commentLen > 0) { - char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ntbEntry.comment); - colDataAppend(pColInfoData, numOfRows, comment, false); - } else if (pInfo->pCur->mr.me.ntbEntry.commentLen == 0) { - char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; - STR_TO_VARSTR(comment, ""); - colDataAppend(pColInfoData, numOfRows, comment, false); - } else { - colDataAppendNULL(pColInfoData, numOfRows); - } + // uid + pColInfoData = taosArrayGet(p->pDataBlock, 5); + colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.uid, false); - // uid - pColInfoData = taosArrayGet(p->pDataBlock, 5); - colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false); + // ttl + pColInfoData = taosArrayGet(p->pDataBlock, 7); + colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.ntbEntry.ttlDays, false); - // ttl - pColInfoData = taosArrayGet(p->pDataBlock, 7); - colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ttlDays, false); + STR_TO_VARSTR(n, "NORMAL_TABLE"); + // impl later + } + + metaReaderClear(&mr); + + pColInfoData = taosArrayGet(p->pDataBlock, 9); + colDataAppend(pColInfoData, numOfRows, n, false); + + if (++numOfRows >= pOperator->resultInfo.capacity) { + p->info.rows = numOfRows; + pInfo->pRes->info.rows = numOfRows; + + relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock, false); + doFilterResult(pInfo); - STR_TO_VARSTR(n, "NORMAL_TABLE"); + blockDataCleanup(p); + numOfRows = 0; + + if (pInfo->pRes->info.rows > 0) { + break; } + } + } + + if (numOfRows > 0) { + p->info.rows = numOfRows; + pInfo->pRes->info.rows = numOfRows; + + relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock, false); + doFilterResult(pInfo); + + blockDataCleanup(p); + numOfRows = 0; + } + + if (i >= taosArrayGetSize(pIdx->uids)) { + doSetOperatorCompleted(pOperator); + } else { + pIdx->lastIdx = i + 1; + } + + blockDataDestroy(p); + + pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; + return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; +} +static SSDataBlock* sysTableBuildUserTables(SOperatorInfo* pOperator) { + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + qError("%p buildUserTable", pTaskInfo); + SSysTableScanInfo* pInfo = pOperator->info; + if (pInfo->pCur == NULL) { + pInfo->pCur = metaOpenTbCursor(pInfo->readHandle.meta); + } - pColInfoData = taosArrayGet(p->pDataBlock, 9); + blockDataCleanup(pInfo->pRes); + int32_t numOfRows = 0; + + const char* db = NULL; + int32_t vgId = 0; + vnodeGetInfo(pInfo->readHandle.vnode, &db, &vgId); + + SName sn = {0}; + char dbname[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; + tNameFromString(&sn, db, T_NAME_ACCT | T_NAME_DB); + + tNameGetDbName(&sn, varDataVal(dbname)); + varDataSetLen(dbname, strlen(varDataVal(dbname))); + + SSDataBlock* p = buildInfoSchemaTableMetaBlock(TSDB_INS_TABLE_TABLES); + blockDataEnsureCapacity(p, pOperator->resultInfo.capacity); + + char n[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + + int32_t ret = 0; + while ((ret = metaTbCursorNext(pInfo->pCur)) == 0) { + STR_TO_VARSTR(n, pInfo->pCur->mr.me.name); + + // table name + SColumnInfoData* pColInfoData = taosArrayGet(p->pDataBlock, 0); + colDataAppend(pColInfoData, numOfRows, n, false); + + // database name + pColInfoData = taosArrayGet(p->pDataBlock, 1); + colDataAppend(pColInfoData, numOfRows, dbname, false); + + // vgId + pColInfoData = taosArrayGet(p->pDataBlock, 6); + colDataAppend(pColInfoData, numOfRows, (char*)&vgId, false); + + int32_t tableType = pInfo->pCur->mr.me.type; + if (tableType == TSDB_CHILD_TABLE) { + // create time + int64_t ts = pInfo->pCur->mr.me.ctbEntry.ctime; + pColInfoData = taosArrayGet(p->pDataBlock, 2); + colDataAppend(pColInfoData, numOfRows, (char*)&ts, false); + + SMetaReader mr = {0}; + metaReaderInit(&mr, pInfo->readHandle.meta, META_READER_NOLOCK); + + uint64_t suid = pInfo->pCur->mr.me.ctbEntry.suid; + int32_t code = metaGetTableEntryByUid(&mr, suid); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get super table meta, cname:%s, suid:0x%" PRIx64 ", code:%s, %s", pInfo->pCur->mr.me.name, + suid, tstrerror(terrno), GET_TASKID(pTaskInfo)); + metaReaderClear(&mr); + metaCloseTbCursor(pInfo->pCur); + pInfo->pCur = NULL; + T_LONG_JMP(pTaskInfo->env, terrno); + } + + // number of columns + pColInfoData = taosArrayGet(p->pDataBlock, 3); + colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.stbEntry.schemaRow.nCols, false); + + // super table name + STR_TO_VARSTR(n, mr.me.name); + pColInfoData = taosArrayGet(p->pDataBlock, 4); colDataAppend(pColInfoData, numOfRows, n, false); + metaReaderClear(&mr); + + // table comment + pColInfoData = taosArrayGet(p->pDataBlock, 8); + if (pInfo->pCur->mr.me.ctbEntry.commentLen > 0) { + char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ctbEntry.comment); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else if (pInfo->pCur->mr.me.ctbEntry.commentLen == 0) { + char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, ""); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else { + colDataAppendNULL(pColInfoData, numOfRows); + } - if (++numOfRows >= pOperator->resultInfo.capacity) { - p->info.rows = numOfRows; - pInfo->pRes->info.rows = numOfRows; + // uid + pColInfoData = taosArrayGet(p->pDataBlock, 5); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false); - relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock, false); - doFilterResult(pInfo); + // ttl + pColInfoData = taosArrayGet(p->pDataBlock, 7); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ctbEntry.ttlDays, false); - blockDataCleanup(p); - numOfRows = 0; + STR_TO_VARSTR(n, "CHILD_TABLE"); + } else if (tableType == TSDB_NORMAL_TABLE) { + // create time + pColInfoData = taosArrayGet(p->pDataBlock, 2); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ctime, false); - if (pInfo->pRes->info.rows > 0) { - break; - } + // number of columns + pColInfoData = taosArrayGet(p->pDataBlock, 3); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.schemaRow.nCols, false); + + // super table name + pColInfoData = taosArrayGet(p->pDataBlock, 4); + colDataAppendNULL(pColInfoData, numOfRows); + + // table comment + pColInfoData = taosArrayGet(p->pDataBlock, 8); + if (pInfo->pCur->mr.me.ntbEntry.commentLen > 0) { + char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ntbEntry.comment); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else if (pInfo->pCur->mr.me.ntbEntry.commentLen == 0) { + char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, ""); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else { + colDataAppendNULL(pColInfoData, numOfRows); } + + // uid + pColInfoData = taosArrayGet(p->pDataBlock, 5); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false); + + // ttl + pColInfoData = taosArrayGet(p->pDataBlock, 7); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ttlDays, false); + + STR_TO_VARSTR(n, "NORMAL_TABLE"); } - if (numOfRows > 0) { + pColInfoData = taosArrayGet(p->pDataBlock, 9); + colDataAppend(pColInfoData, numOfRows, n, false); + + if (++numOfRows >= pOperator->resultInfo.capacity) { p->info.rows = numOfRows; pInfo->pRes->info.rows = numOfRows; @@ -2944,20 +3623,88 @@ static SSDataBlock* sysTableScanUserTables(SOperatorInfo* pOperator) { blockDataCleanup(p); numOfRows = 0; + + if (pInfo->pRes->info.rows > 0) { + break; + } } + } - blockDataDestroy(p); + if (numOfRows > 0) { + p->info.rows = numOfRows; + pInfo->pRes->info.rows = numOfRows; - // todo temporarily free the cursor here, the true reason why the free is not valid needs to be found - if (ret != 0) { - metaCloseTbCursor(pInfo->pCur); - pInfo->pCur = NULL; - doSetOperatorCompleted(pOperator); - } + relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock, false); + doFilterResult(pInfo); + + blockDataCleanup(p); + numOfRows = 0; + } + + blockDataDestroy(p); + + // todo temporarily free the cursor here, the true reason why the free is not valid needs to be found + if (ret != 0) { + metaCloseTbCursor(pInfo->pCur); + pInfo->pCur = NULL; + doSetOperatorCompleted(pOperator); + } + + pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; + return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; +} +static SSDataBlock* sysTableScanUserTables(SOperatorInfo* pOperator) { + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SSysTableScanInfo* pInfo = pOperator->info; + + SNode* pCondition = pInfo->pCondition; + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + // the retrieve is executed on the mnode, so return tables that belongs to the information schema database. + if (pInfo->readHandle.mnd != NULL) { + buildSysDbTableInfo(pInfo, pOperator->resultInfo.capacity); + + doFilterResult(pInfo); pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; + + doSetOperatorCompleted(pOperator); return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; + } else { + if (pInfo->showRewrite == false) { + if (pCondition != NULL && pInfo->pIdx == NULL) { + SSTabFltArg arg = {.pMeta = pInfo->readHandle.meta, .pVnode = pInfo->readHandle.vnode}; + + SSysTableIndex* idx = taosMemoryMalloc(sizeof(SSysTableIndex)); + idx->init = 0; + idx->uids = taosArrayInit(128, sizeof(int64_t)); + idx->lastIdx = 0; + + pInfo->pIdx = idx; // set idx arg + + int flt = optSysTabFilte(&arg, pCondition, idx->uids); + if (flt == 0) { + pInfo->pIdx->init = 1; + SSDataBlock* blk = sysTableBuildUserTablesByUids(pOperator); + return blk; + } else if (flt == -2) { + qDebug("%s failed to get sys table info by idx, empty result", GET_TASKID(pTaskInfo)); + return NULL; + } else if (flt == -1) { + // not idx + qDebug("%s failed to get sys table info by idx, scan sys table one by one", GET_TASKID(pTaskInfo)); + } + } else if (pCondition != NULL && (pInfo->pIdx != NULL && pInfo->pIdx->init == 1)) { + SSDataBlock* blk = sysTableBuildUserTablesByUids(pOperator); + return blk; + } + } + + return sysTableBuildUserTables(pOperator); } + return NULL; } static SSDataBlock* sysTableScanUserSTables(SOperatorInfo* pOperator) { @@ -3179,7 +3926,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, NULL, destroySysScanOperator, NULL, NULL, NULL); + createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, NULL, destroySysScanOperator, NULL); return pOperator; @@ -3316,7 +4063,7 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doTagScan, NULL, NULL, destroyTagScanOperatorInfo, NULL, NULL, NULL); + createOperatorFpSet(operatorDummyOpenFn, doTagScan, NULL, NULL, destroyTagScanOperatorInfo, NULL); return pOperator; @@ -3333,7 +4080,7 @@ int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags int64_t st = taosGetTimestampUs(); if (pHandle == NULL) { - qError("invalid handle, in creating operator tree", idStr); + qError("invalid handle, in creating operator tree, %s", idStr); return TSDB_CODE_INVALID_PARA; } @@ -3856,9 +4603,8 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN pOperator->pTaskInfo = pTaskInfo; initResultSizeInfo(&pOperator->resultInfo, 1024); - pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doTableMergeScan, NULL, NULL, destroyTableMergeScanOperatorInfo, NULL, - NULL, getTableMergeScanExplainExecInfo); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableMergeScan, NULL, NULL, + destroyTableMergeScanOperatorInfo, getTableMergeScanExplainExecInfo); pOperator->cost.openCost = 0; return pOperator; diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index 7ca3de5214cd18202b5dfe2293bcc495e6b08190..39987d4501a241fb69a5a46e800ca1f18d19cace 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -64,7 +64,7 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* // there are headers, so pageSize = rowSize + header pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer - pOperator->fpSet = createOperatorFpSet(doOpenSortOperator, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, + pOperator->fpSet = createOperatorFpSet(doOpenSortOperator, doSort, NULL, NULL, destroyOrderOperatorInfo, getExplainExecInfo); int32_t code = appendDownstream(pOperator, &downstream, 1); @@ -515,7 +515,7 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doGroupSort, NULL, NULL, destroyGroupSortOperatorInfo, - NULL, NULL, getGroupSortExplainExecInfo); + getGroupSortExplainExecInfo); int32_t code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -719,12 +719,16 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); SDataBlockDescNode* pDescNode = pPhyNode->pOutputDataBlockDesc; - pInfo->binfo.pRes = createResDataBlock(pDescNode); - int32_t rowSize = pInfo->binfo.pRes->info.rowSize; - if (pInfo == NULL || pOperator == NULL || rowSize > 100 * 1024 * 1024) { + int32_t code = TSDB_CODE_SUCCESS; + if (pInfo == NULL || pOperator == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; goto _error; } + pInfo->binfo.pRes = createResDataBlock(pDescNode); + int32_t rowSize = pInfo->binfo.pRes->info.rowSize; + ASSERT(rowSize < 100 * 1024 * 1024); + SArray* pSortInfo = createSortInfo(pMergePhyNode->pMergeKeys); int32_t numOfOutputCols = 0; SArray* pColMatchColInfo = @@ -737,6 +741,9 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size pInfo->pSortInfo = pSortInfo; pInfo->pColMatchInfo = pColMatchColInfo; pInfo->pInputBlock = pInputBlock; + pInfo->bufPageSize = getProperSortPageSize(rowSize); + pInfo->sortBufSize = pInfo->bufPageSize * (numStreams + 1); // one additional is reserved for merged result. + pOperator->name = "MultiwayMerge"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE; pOperator->blocking = false; @@ -744,15 +751,10 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; - pInfo->bufPageSize = getProperSortPageSize(rowSize); - - // one additional is reserved for merged result. - pInfo->sortBufSize = pInfo->bufPageSize * (numStreams + 1); - pOperator->fpSet = createOperatorFpSet(doOpenMultiwayMergeOperator, doMultiwayMerge, NULL, NULL, - destroyMultiwayMergeOperatorInfo, NULL, NULL, getMultiwayMergeExplainExecInfo); + destroyMultiwayMergeOperatorInfo, getMultiwayMergeExplainExecInfo); - int32_t code = appendDownstream(pOperator, downStreams, numStreams); + code = appendDownstream(pOperator, downStreams, numStreams); if (code != TSDB_CODE_SUCCESS) { goto _error; } diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c index e199cf840688914531203c0809e6c175aaac8c18..5d3f5e07d3f8b35e7c05e2a05973b36987fb1402 100644 --- a/source/libs/executor/src/tfill.c +++ b/source/libs/executor/src/tfill.c @@ -263,19 +263,14 @@ static void saveColData(SArray* rowBuf, int32_t columnIndex, const char* src, bo static void copyCurrentRowIntoBuf(SFillInfo* pFillInfo, int32_t rowIndex, SArray* pRow) { for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) { int32_t type = pFillInfo->pFillCol[i].pExpr->pExpr->nodeType; - if (type == QUERY_NODE_COLUMN) { + if (type == QUERY_NODE_COLUMN || type == QUERY_NODE_OPERATOR || type == QUERY_NODE_FUNCTION) { int32_t srcSlotId = GET_DEST_SLOT_ID(&pFillInfo->pFillCol[i]); SColumnInfoData* pSrcCol = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, srcSlotId); bool isNull = colDataIsNull_s(pSrcCol, rowIndex); char* p = colDataGetData(pSrcCol, rowIndex); - saveColData(pRow, i, p, isNull); - } else if (type == QUERY_NODE_OPERATOR) { - SColumnInfoData* pSrcCol = taosArrayGet(pFillInfo->pSrcBlock->pDataBlock, i); - bool isNull = colDataIsNull_s(pSrcCol, rowIndex); - char* p = colDataGetData(pSrcCol, rowIndex); saveColData(pRow, i, p, isNull); } else { ASSERT(0); @@ -467,9 +462,11 @@ struct SFillInfo* taosCreateFillInfo(TSKEY skey, int32_t numOfFillCols, int32_t case FILL_MODE_VALUE: pFillInfo->type = TSDB_FILL_SET_VALUE; break; - default: + default: { + taosMemoryFree(pFillInfo); terrno = TSDB_CODE_INVALID_PARA; return NULL; + } } pFillInfo->type = fillType; @@ -619,8 +616,8 @@ int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, SSDataBlock* p, int32_t ca int64_t getFillInfoStart(struct SFillInfo* pFillInfo) { return pFillInfo->start; } SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfFillExpr, SExprInfo* pNotFillExpr, - int32_t numOfNotFillExpr, const struct SNodeListNode* pValNode) { - SFillColInfo* pFillCol = taosMemoryCalloc(numOfFillExpr + numOfNotFillExpr, sizeof(SFillColInfo)); + int32_t numOfNoFillExpr, const struct SNodeListNode* pValNode) { + SFillColInfo* pFillCol = taosMemoryCalloc(numOfFillExpr + numOfNoFillExpr, sizeof(SFillColInfo)); if (pFillCol == NULL) { return NULL; } @@ -641,7 +638,7 @@ SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfFillExpr, SExprIn } } - for (int32_t i = 0; i < numOfNotFillExpr; ++i) { + for (int32_t i = 0; i < numOfNoFillExpr; ++i) { SExprInfo* pExprInfo = &pNotFillExpr[i]; pFillCol[i + numOfFillExpr].pExpr = pExprInfo; pFillCol[i + numOfFillExpr].notFillCol = true; @@ -1401,7 +1398,7 @@ static void doApplyStreamScalarCalculation(SOperatorInfo* pOperator, SSDataBlock blockDataCleanup(pDstBlock); blockDataEnsureCapacity(pDstBlock, pSrcBlock->info.rows); - setInputDataBlock(pOperator, pSup->pCtx, pSrcBlock, TSDB_ORDER_ASC, MAIN_SCAN, false); + setInputDataBlock(pSup, pSrcBlock, TSDB_ORDER_ASC, MAIN_SCAN, false); projectApplyFunctions(pSup->pExprInfo, pDstBlock, pSrcBlock, pSup->pCtx, pSup->numOfExprs, NULL); pDstBlock->info.groupId = pSrcBlock->info.groupId; @@ -1492,6 +1489,7 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) { case STREAM_NORMAL: case STREAM_INVALID: { doApplyStreamScalarCalculation(pOperator, pBlock, pInfo->pSrcBlock); + memcpy(pInfo->pSrcBlock->info.parTbName, pBlock->info.parTbName, TSDB_TABLE_NAME_LEN); pInfo->srcRowIndex = 0; } break; default: @@ -1502,6 +1500,7 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) { doStreamFillImpl(pOperator); doFilter(pInfo->pCondition, pInfo->pRes, pInfo->pColMatchColInfo, NULL); + memcpy(pInfo->pRes->info.parTbName, pInfo->pSrcBlock->info.parTbName, TSDB_TABLE_NAME_LEN); pOperator->resultInfo.totalRows += pInfo->pRes->info.rows; if (pInfo->pRes->info.rows > 0) { break; @@ -1549,8 +1548,8 @@ static SStreamFillSupporter* initStreamFillSup(SStreamFillPhysiNode* pPhyFillNod } pFillSup->numOfFillCols = numOfFillCols; int32_t numOfNotFillCols = 0; - SExprInfo* pNotFillExprInfo = createExprInfo(pPhyFillNode->pNotFillExprs, NULL, &numOfNotFillCols); - pFillSup->pAllColInfo = createFillColInfo(pFillExprInfo, pFillSup->numOfFillCols, pNotFillExprInfo, numOfNotFillCols, + SExprInfo* noFillExprInfo = createExprInfo(pPhyFillNode->pNotFillExprs, NULL, &numOfNotFillCols); + pFillSup->pAllColInfo = createFillColInfo(pFillExprInfo, pFillSup->numOfFillCols, noFillExprInfo, numOfNotFillCols, (const SNodeListNode*)(pPhyFillNode->pValues)); pFillSup->type = convertFillType(pPhyFillNode->mode); pFillSup->numOfAllCols = pFillSup->numOfFillCols + numOfNotFillCols; @@ -1625,7 +1624,6 @@ SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFi goto _error; } - SResultInfo* pResultInfo = &pOperator->resultInfo; initResultSizeInfo(&pOperator->resultInfo, 4096); pInfo->pRes = createResDataBlock(pPhyFillNode->node.pOutputDataBlockDesc); pInfo->pSrcBlock = createResDataBlock(pPhyFillNode->node.pOutputDataBlockDesc); @@ -1695,7 +1693,7 @@ SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFi pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamFill, NULL, NULL, destroyStreamFillOperatorInfo, - NULL, NULL, NULL); + NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 76fddc3982e25d83795e69f388f68d7c87f346e7..8e5f03c4acca08af71880b8c42e98421aa9266c2 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -1079,7 +1079,7 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { } // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pSup->pCtx, pBlock, pInfo->inputOrder, scanFlag, true); + setInputDataBlock(pSup, pBlock, pInfo->inputOrder, scanFlag, true); blockDataUpdateTsWindow(pBlock, pInfo->primaryTsIndex); hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, scanFlag); @@ -1209,7 +1209,7 @@ static int32_t openStateWindowAggOptr(SOperatorInfo* pOperator) { break; } - setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, MAIN_SCAN, true); + setInputDataBlock(pSup, pBlock, order, MAIN_SCAN, true); blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId); // there is an scalar expression that needs to be calculated right before apply the group aggregation. @@ -1751,9 +1751,7 @@ void initStreamFunciton(SqlFunctionCtx* pCtx, int32_t numOfExpr) { } } -SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId, - STimeWindowAggSupp* pTwAggSupp, SIntervalPhysiNode* pPhyNode, +SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, bool isStream) { SIntervalAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SIntervalAggOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); @@ -1761,46 +1759,63 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* goto _error; } + SSDataBlock* pResBlock = createResDataBlock(pPhyNode->window.node.pOutputDataBlockDesc); + initBasicInfo(&pInfo->binfo, pResBlock); + + SExprSupp* pSup = &pOperator->exprSupp; + pInfo->primaryTsIndex = ((SColumnNode*)pPhyNode->window.pTspk)->slotId; + + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + initResultSizeInfo(&pOperator->resultInfo, 4096); + + int32_t num = 0; + SExprInfo* pExprInfo = createExprInfo(pPhyNode->window.pFuncs, NULL, &num); + int32_t code = initAggInfo(pSup, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + + SInterval interval = {.interval = pPhyNode->interval, + .sliding = pPhyNode->sliding, + .intervalUnit = pPhyNode->intervalUnit, + .slidingUnit = pPhyNode->slidingUnit, + .offset = pPhyNode->offset, + .precision = ((SColumnNode*)pPhyNode->window.pTspk)->node.resType.precision}; + + STimeWindowAggSupp as = { + .waterMark = pPhyNode->window.watermark, + .calTrigger = pPhyNode->window.triggerType, + .maxTs = INT64_MIN, + }; + + ASSERT(as.calTrigger != STREAM_TRIGGER_MAX_DELAY); + pOperator->pTaskInfo = pTaskInfo; pInfo->win = pTaskInfo->window; pInfo->inputOrder = (pPhyNode->window.inputTsOrder == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; pInfo->resultTsOrder = (pPhyNode->window.outputTsOrder == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; - pInfo->interval = *pInterval; + pInfo->interval = interval; pInfo->execModel = pTaskInfo->execModel; - pInfo->twAggSup = *pTwAggSupp; + pInfo->twAggSup = as; pInfo->pCondition = pPhyNode->window.node.pConditions; pInfo->binfo.mergeResultBlock = pPhyNode->window.mergeDataBlock; if (pPhyNode->window.pExprs != NULL) { int32_t numOfScalar = 0; SExprInfo* pScalarExprInfo = createExprInfo(pPhyNode->window.pExprs, NULL, &numOfScalar); - int32_t code = initExprSupp(&pInfo->scalarSupp, pScalarExprInfo, numOfScalar); + code = initExprSupp(&pInfo->scalarSupp, pScalarExprInfo, numOfScalar); if (code != TSDB_CODE_SUCCESS) { goto _error; } } - pInfo->primaryTsIndex = primaryTsSlotId; - SExprSupp* pSup = &pOperator->exprSupp; - - size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(&pOperator->resultInfo, 4096); - - int32_t code = initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); - if (code != TSDB_CODE_SUCCESS) { - goto _error; - } - - initBasicInfo(&pInfo->binfo, pResBlock); - if (isStream) { - ASSERT(numOfCols > 0); + ASSERT(num > 0); initStreamFunciton(pSup->pCtx, pSup->numOfExprs); } initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pInfo->win); - - pInfo->timeWindowInterpo = timeWindowinterpNeeded(pSup->pCtx, numOfCols, pInfo); + pInfo->timeWindowInterpo = timeWindowinterpNeeded(pSup->pCtx, num, pInfo); if (pInfo->timeWindowInterpo) { pInfo->binfo.resultRowInfo.openWindow = tdListNew(sizeof(SOpenWindowInfo)); if (pInfo->binfo.resultRowInfo.openWindow == NULL) { @@ -1816,8 +1831,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; - pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, NULL, NULL, - destroyIntervalOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); + pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, NULL, NULL, destroyIntervalOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -1827,7 +1841,9 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* return pOperator; _error: - destroyIntervalOperatorInfo(pInfo); + if (pInfo != NULL) { + destroyIntervalOperatorInfo(pInfo); + } taosMemoryFreeClear(pOperator); pTaskInfo->code = code; return NULL; @@ -1944,7 +1960,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) { } // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, MAIN_SCAN, true); + setInputDataBlock(pSup, pBlock, order, MAIN_SCAN, true); blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId); doSessionWindowAggImpl(pOperator, pInfo, pBlock); @@ -2295,7 +2311,7 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { } // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, MAIN_SCAN, true); + setInputDataBlock(pSup, pBlock, order, MAIN_SCAN, true); SColumnInfoData* pTsCol = taosArrayGet(pBlock->pDataBlock, pSliceInfo->tsCol.slotId); for (int32_t i = 0; i < pBlock->info.rows; ++i) { @@ -2621,8 +2637,7 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SPhysiNode pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doTimeslice, NULL, NULL, destroyTimeSliceOperatorInfo, NULL, NULL, NULL); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTimeslice, NULL, NULL, destroyTimeSliceOperatorInfo, NULL); blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); @@ -2667,16 +2682,15 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWi size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - int32_t num = 0; - SExprInfo* pExprInfo = createExprInfo(pStateNode->window.pFuncs, NULL, &num); - SSDataBlock* pResBlock = createResDataBlock(pStateNode->window.node.pOutputDataBlockDesc); - + int32_t num = 0; + SExprInfo* pExprInfo = createExprInfo(pStateNode->window.pFuncs, NULL, &num); initResultSizeInfo(&pOperator->resultInfo, 4096); int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } + SSDataBlock* pResBlock = createResDataBlock(pStateNode->window.node.pOutputDataBlockDesc); initBasicInfo(&pInfo->binfo, pResBlock); initResultRowInfo(&pInfo->binfo.resultRowInfo); @@ -2694,7 +2708,7 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWi pOperator->info = pInfo; pOperator->fpSet = createOperatorFpSet(openStateWindowAggOptr, doStateWindowAgg, NULL, NULL, - destroyStateWindowOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); + destroyStateWindowOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -2704,7 +2718,10 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWi return pOperator; _error: - destroyStateWindowOperatorInfo(pInfo); + if (pInfo != NULL) { + destroyStateWindowOperatorInfo(pInfo); + } + taosMemoryFreeClear(pOperator); pTaskInfo->code = code; return NULL; @@ -2765,7 +2782,7 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionW pOperator->info = pInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSessionWindowAgg, NULL, NULL, - destroySWindowOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); + destroySWindowOperatorInfo, NULL); pOperator->pTaskInfo = pTaskInfo; code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -3147,6 +3164,7 @@ static void doStreamIntervalAggImpl(SOperatorInfo* pOperatorInfo, SSDataBlock* p static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { SStreamIntervalOperatorInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SOperatorInfo* downstream = pOperator->pDownstream[0]; TSKEY maxTs = INT64_MIN; @@ -3189,6 +3207,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { } else { deleteIntervalDiscBuf(pInfo->pState, pInfo->pPullDataMap, pInfo->twAggSup.maxTs - pInfo->twAggSup.deleteMark, &pInfo->interval, &pInfo->delKey); + streamStateCommit(pTaskInfo->streamInfo.pState); } return NULL; } else { @@ -3266,7 +3285,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { SExprSupp* pExprSup = &pInfo->scalarSupp; projectApplyFunctions(pExprSup->pExprInfo, pBlock, pBlock, pExprSup->pCtx, pExprSup->numOfExprs, NULL); } - setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); + setInputDataBlock(pSup, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); doStreamIntervalAggImpl(pOperator, pBlock, pBlock->info.groupId, pUpdatedMap); if (IS_FINAL_OP(pInfo)) { int32_t chIndex = getChildIndex(pBlock); @@ -3284,7 +3303,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { } SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, chIndex); SStreamIntervalOperatorInfo* pChInfo = pChildOp->info; - setInputDataBlock(pChildOp, pChildOp->exprSupp.pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); + setInputDataBlock(&pChildOp->exprSupp, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); doStreamIntervalAggImpl(pChildOp, pBlock, pBlock->info.groupId, NULL); } maxTs = TMAX(maxTs, pBlock->info.window.ekey); @@ -3444,8 +3463,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, pOperator->info = pInfo; pOperator->fpSet = - createOperatorFpSet(NULL, doStreamFinalIntervalAgg, NULL, NULL, destroyStreamFinalIntervalOperatorInfo, - aggEncodeResultRow, aggDecodeResultRow, NULL); + createOperatorFpSet(NULL, doStreamFinalIntervalAgg, NULL, NULL, destroyStreamFinalIntervalOperatorInfo, NULL); if (pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL) { initIntervalDownStream(downstream, pPhyNode->type, &pInfo->aggSup, &pInfo->interval, &pInfo->twAggSup); } @@ -3592,9 +3610,7 @@ void getCurSessionWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endT pKey->win.skey = startTs; pKey->win.ekey = endTs; pKey->groupId = groupId; - SStreamStateCur* pCur = streamStateSessionGetCur(pAggSup->pState, pKey); - int32_t code = streamStateSessionGetKVByCur(pCur, pKey, NULL, 0); - streamStateFreeCur(pCur); + int32_t code = streamStateSessionGetKey(pAggSup->pState, pKey, pKey); if (code != TSDB_CODE_SUCCESS) { SET_SESSION_WIN_KEY_INVALID(pKey); } @@ -3986,7 +4002,8 @@ int32_t closeSessionWindow(SSHashObj* pHashMap, STimeWindowAggSupp* pTwSup, SSHa return code; } } - tSimpleHashIterateRemove(pHashMap, &pWinInfo->sessionWin, sizeof(SSessionKey), &pIte, &iter); + SSessionKey* pKey = tSimpleHashGetKey(pIte, &keyLen); + tSimpleHashIterateRemove(pHashMap, pKey, sizeof(SSessionKey), &pIte, &iter); } } return TSDB_CODE_SUCCESS; @@ -4006,7 +4023,7 @@ int32_t getAllSessionWindow(SSHashObj* pHashMap, SSHashObj* pStUpdated) { void* pIte = NULL; int32_t iter = 0; while ((pIte = tSimpleHashIterate(pHashMap, pIte, &iter)) != NULL) { - SResultWindowInfo* pWinInfo = *(void**)pIte; + SResultWindowInfo* pWinInfo = pIte; saveResult(*pWinInfo, pStUpdated); } return TSDB_CODE_SUCCESS; @@ -4044,7 +4061,7 @@ void doBuildSessionResult(SOperatorInfo* pOperator, SStreamState* pState, SGroup // clear the existed group id pBlock->info.groupId = 0; - buildSessionResultDataBlock(pTaskInfo, pState, pBlock, &pOperator->exprSupp, pGroupResInfo); + buildSessionResultDataBlock(pOperator, pState, pBlock, &pOperator->exprSupp, pGroupResInfo); } static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { @@ -4088,6 +4105,12 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { /*printf("\n\n put tbname %s\n\n", pBlock->info.parTbName);*/ } + if (pBlock->info.parTbName[0]) { + taosHashPut(pInfo->pGroupIdTbNameMap, &pBlock->info.groupId, sizeof(int64_t), &pBlock->info.parTbName, + TSDB_TABLE_NAME_LEN); + /*printf("\n\n put tbname %s\n\n", pBlock->info.parTbName);*/ + } + if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT || pBlock->info.type == STREAM_CLEAR) { SArray* pWins = taosArrayInit(16, sizeof(SSessionKey)); @@ -4114,7 +4137,8 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { SExprSupp* pExprSup = &pInfo->scalarSupp; projectApplyFunctions(pExprSup->pExprInfo, pBlock, pBlock, pExprSup->pCtx, pExprSup->numOfExprs, NULL); } - setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); + // the pDataBlock are always the same one, no need to call this again + setInputDataBlock(pSup, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); doStreamSessionAggImpl(pOperator, pBlock, pStUpdated, pInfo->pStDeleted, IS_FINAL_OP(pInfo)); if (IS_FINAL_OP(pInfo)) { int32_t chIndex = getChildIndex(pBlock); @@ -4129,7 +4153,7 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { taosArrayPush(pInfo->pChildren, &pChildOp); } SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, chIndex); - setInputDataBlock(pChildOp, pChildOp->exprSupp.pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); + setInputDataBlock(&pChildOp->exprSupp, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); doStreamSessionAggImpl(pChildOp, pBlock, NULL, NULL, true); } maxTs = TMAX(maxTs, pBlock->info.window.ekey); @@ -4234,7 +4258,7 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh pOperator->info = pInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamSessionAgg, NULL, NULL, destroyStreamSessionAggOperatorInfo, - aggEncodeResultRow, aggDecodeResultRow, NULL); + NULL); if (downstream) { initDownStream(downstream, &pInfo->streamAggSup, pInfo->twAggSup.waterMark, pOperator->operatorType, pInfo->primaryTsIndex); @@ -4328,7 +4352,7 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) { projectApplyFunctions(pExprSup->pExprInfo, pBlock, pBlock, pExprSup->pCtx, pExprSup->numOfExprs, NULL); } // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); + setInputDataBlock(pSup, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); doStreamSessionAggImpl(pOperator, pBlock, pStUpdated, NULL, false); maxTs = TMAX(pInfo->twAggSup.maxTs, pBlock->info.window.ekey); } @@ -4381,7 +4405,7 @@ SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream pOperator->name = "StreamSessionSemiAggOperator"; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamSessionSemiAgg, NULL, NULL, - destroyStreamSessionAggOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); + destroyStreamSessionAggOperatorInfo, NULL); } pInfo->pGroupIdTbNameMap = @@ -4401,6 +4425,11 @@ SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream taosArrayPush(pInfo->pChildren, &pChildOp); } } + + if (!IS_FINAL_OP(pInfo) || numOfChild == 0) { + pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE; + } + return pOperator; _error: @@ -4577,6 +4606,12 @@ static void doStreamStateAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBl T_LONG_JMP(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } } + + if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) { + SSessionKey key = curWin.winInfo.sessionWin; + key.win.ekey = key.win.skey; + tSimpleHashPut(pAggSup->pResultRows, &key, sizeof(SSessionKey), &curWin.winInfo, sizeof(SResultWindowInfo)); + } } } @@ -4617,6 +4652,12 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) { } printDataBlock(pBlock, "single state recv"); + if (pBlock->info.parTbName[0]) { + taosHashPut(pInfo->pGroupIdTbNameMap, &pBlock->info.groupId, sizeof(int64_t), &pBlock->info.parTbName, + TSDB_TABLE_NAME_LEN); + /*printf("\n\n put tbname %s\n\n", pBlock->info.parTbName);*/ + } + if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT || pBlock->info.type == STREAM_CLEAR) { SArray* pWins = taosArrayInit(16, sizeof(SSessionKey)); @@ -4635,7 +4676,7 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) { projectApplyFunctions(pExprSup->pExprInfo, pBlock, pBlock, pExprSup->pCtx, pExprSup->numOfExprs, NULL); } // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); + setInputDataBlock(pSup, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); doStreamStateAggImpl(pOperator, pBlock, pSeUpdated, pInfo->pSeDeleted); maxTs = TMAX(maxTs, pBlock->info.window.ekey); } @@ -4733,7 +4774,7 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys pOperator->pTaskInfo = pTaskInfo; pOperator->info = pInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamStateAgg, NULL, NULL, - destroyStreamStateOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); + destroyStreamStateOperatorInfo, NULL); initDownStream(downstream, &pInfo->streamAggSup, pInfo->twAggSup.waterMark, pOperator->operatorType, pInfo->primaryTsIndex); code = appendDownstream(pOperator, &downstream, 1); @@ -4905,7 +4946,7 @@ static void doMergeAlignedIntervalAgg(SOperatorInfo* pOperator) { } getTableScanInfo(pOperator, &pIaInfo->inputOrder, &scanFlag); - setInputDataBlock(pOperator, pSup->pCtx, pBlock, pIaInfo->inputOrder, scanFlag, true); + setInputDataBlock(pSup, pBlock, pIaInfo->inputOrder, scanFlag, true); doMergeAlignedIntervalAggImpl(pOperator, &pIaInfo->binfo.resultRowInfo, pBlock, pRes); doFilter(pMiaInfo->pCondition, pRes, NULL, NULL); @@ -4961,10 +5002,6 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, goto _error; } - int32_t num = 0; - SExprInfo* pExprInfo = createExprInfo(pNode->window.pFuncs, NULL, &num); - SSDataBlock* pResBlock = createResDataBlock(pNode->window.node.pOutputDataBlockDesc); - SInterval interval = {.interval = pNode->interval, .sliding = pNode->sliding, .intervalUnit = pNode->intervalUnit, @@ -4987,11 +5024,14 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; initResultSizeInfo(&pOperator->resultInfo, 4096); - int32_t code = initAggInfo(&pOperator->exprSupp, &iaInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); + int32_t num = 0; + SExprInfo* pExprInfo = createExprInfo(pNode->window.pFuncs, NULL, &num); + int32_t code = initAggInfo(&pOperator->exprSupp, &iaInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } + SSDataBlock* pResBlock = createResDataBlock(pNode->window.node.pOutputDataBlockDesc); initBasicInfo(&iaInfo->binfo, pResBlock); initExecTimeWindowInfo(&iaInfo->twAggSup.timeWindowData, &iaInfo->win); @@ -5011,7 +5051,7 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, pOperator->info = miaInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, mergeAlignedIntervalAgg, NULL, NULL, - destroyMAIOperatorInfo, NULL, NULL, NULL); + destroyMAIOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -5233,7 +5273,7 @@ static SSDataBlock* doMergeIntervalAgg(SOperatorInfo* pOperator) { } getTableScanInfo(pOperator, &iaInfo->inputOrder, &scanFlag); - setInputDataBlock(pOperator, pExpSupp->pCtx, pBlock, iaInfo->inputOrder, scanFlag, true); + setInputDataBlock(pExpSupp, pBlock, iaInfo->inputOrder, scanFlag, true); doMergeIntervalAggImpl(pOperator, &iaInfo->binfo.resultRowInfo, pBlock, scanFlag, pRes); if (pRes->info.rows >= pOperator->resultInfo.threshold) { @@ -5323,7 +5363,7 @@ SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SMerge pOperator->info = pMergeIntervalInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doMergeIntervalAgg, NULL, NULL, - destroyMergeIntervalOperatorInfo, NULL, NULL, NULL); + destroyMergeIntervalOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -5368,6 +5408,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { deleteIntervalDiscBuf(pInfo->pState, NULL, pInfo->twAggSup.maxTs - pInfo->twAggSup.deleteMark, &pInfo->interval, &pInfo->delKey); doSetOperatorCompleted(pOperator); + streamStateCommit(pTaskInfo->streamInfo.pState); return NULL; } @@ -5412,7 +5453,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { // The timewindow that overlaps the timestamps of the input pBlock need to be recalculated and return to the // caller. Note that all the time window are not close till now. // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); + setInputDataBlock(pSup, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); if (pInfo->invertible) { setInverFunction(pSup->pCtx, pOperator->exprSupp.numOfExprs, pBlock->info.type); } @@ -5462,9 +5503,11 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys } SStreamIntervalPhysiNode* pIntervalPhyNode = (SStreamIntervalPhysiNode*)pPhyNode; + int32_t code = TSDB_CODE_SUCCESS; int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &numOfCols); ASSERT(numOfCols > 0); + SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc); SInterval interval = { .interval = pIntervalPhyNode->interval, @@ -5474,6 +5517,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys .offset = pIntervalPhyNode->offset, .precision = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->node.resType.precision, }; + STimeWindowAggSupp twAggSupp = { .waterMark = pIntervalPhyNode->window.watermark, .calTrigger = pIntervalPhyNode->window.triggerType, @@ -5481,6 +5525,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys .minTs = INT64_MAX, .deleteMark = INT64_MAX, }; + ASSERT(twAggSupp.calTrigger != STREAM_TRIGGER_MAX_DELAY); pOperator->pTaskInfo = pTaskInfo; pInfo->interval = interval; @@ -5488,16 +5533,25 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys pInfo->ignoreExpiredData = pIntervalPhyNode->window.igExpired; pInfo->isFinal = false; - pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId; - initResultSizeInfo(&pOperator->resultInfo, 4096); SExprSupp* pSup = &pOperator->exprSupp; - initBasicInfo(&pInfo->binfo, pResBlock); initStreamFunciton(pSup->pCtx, pSup->numOfExprs); initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window); - size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - int32_t code = initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); + pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId; + initResultSizeInfo(&pOperator->resultInfo, 4096); + + if (pIntervalPhyNode->window.pExprs != NULL) { + int32_t numOfScalar = 0; + SExprInfo* pScalarExprInfo = createExprInfo(pIntervalPhyNode->window.pExprs, NULL, &numOfScalar); + code = initExprSupp(&pInfo->scalarSupp, pScalarExprInfo, numOfScalar); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + } + + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + code = initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -5542,7 +5596,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys pOperator->info = pInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamIntervalAgg, NULL, NULL, destroyStreamFinalIntervalOperatorInfo, - aggEncodeResultRow, aggDecodeResultRow, NULL); + NULL); initIntervalDownStream(downstream, pPhyNode->type, &pInfo->aggSup, &pInfo->interval, &pInfo->twAggSup); code = appendDownstream(pOperator, &downstream, 1); diff --git a/source/libs/executor/src/tlinearhash.c b/source/libs/executor/src/tlinearhash.c index b133041fdce88bcb63338a6ba1b7f03628d9f158..42046925142f2d4957493679f3e0c62bcb31a943 100644 --- a/source/libs/executor/src/tlinearhash.c +++ b/source/libs/executor/src/tlinearhash.c @@ -251,6 +251,7 @@ SLHashObj* tHashInit(int32_t inMemPages, int32_t pageSize, _hash_fn_t fn, int32_ if (!osTempSpaceAvailable()) { terrno = TSDB_CODE_NO_AVAIL_DISK; printf("tHash Init failed since %s", terrstr(terrno)); + taosMemoryFree(pHashObj); return NULL; } diff --git a/source/libs/executor/src/tsimplehash.c b/source/libs/executor/src/tsimplehash.c index b66a6f67705feb73769f4948003fd675593a57c8..a5168d24ba6d933adfa01c0c85a607f7fd82d291 100644 --- a/source/libs/executor/src/tsimplehash.c +++ b/source/libs/executor/src/tsimplehash.c @@ -105,8 +105,8 @@ static void tSimpleHashTableResize(SSHashObj *pHashObj) { int32_t newCapacity = (int32_t)(pHashObj->capacity << 1u); if (newCapacity > HASH_MAX_CAPACITY) { - uDebug("current capacity:%"PRIzu", maximum capacity:%" PRIu64 ", no resize applied due to limitation is reached", - pHashObj->capacity, HASH_MAX_CAPACITY); + uDebug("current capacity:%" PRIzu ", maximum capacity:%" PRId32 ", no resize applied due to limitation is reached", + pHashObj->capacity, (int32_t)HASH_MAX_CAPACITY); return; } @@ -388,4 +388,4 @@ void *tSimpleHashIterate(const SSHashObj *pHashObj, void *data, int32_t *iter) { } return NULL; -} \ No newline at end of file +} diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 85582cbd39d1083b08482a2de1146cf5d91391a9..71fad2e27c8fb13da291460c92847a69a7191d9f 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -140,6 +140,7 @@ static int32_t doAddNewExternalMemSource(SDiskbasedBuf* pBuf, SArray* pAllSource int32_t* sourceId, SArray* pPageIdList) { SSortSource* pSource = taosMemoryCalloc(1, sizeof(SSortSource)); if (pSource == NULL) { + taosArrayDestroy(pPageIdList); return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -155,6 +156,7 @@ static int32_t doAddNewExternalMemSource(SDiskbasedBuf* pBuf, SArray* pAllSource int32_t numOfRows = (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(taosArrayGetSize(pBlock->pDataBlock))) / rowSize; ASSERT(numOfRows > 0); + return blockDataEnsureCapacity(pSource->src.pBlock, numOfRows); } @@ -181,6 +183,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { blockDataSplitRows(pDataBlock, pDataBlock->info.hasVarCol, start, &stop, pHandle->pageSize); SSDataBlock* p = blockDataExtractBlock(pDataBlock, start, stop - start + 1); if (p == NULL) { + taosArrayDestroy(pPageIdList); return terrno; } @@ -223,6 +226,22 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int int32_t code = 0; + // multi-pass internal merge sort is required + if (pHandle->pBuf == NULL) { + if (!osTempSpaceAvailable()) { + code = TSDB_CODE_NO_AVAIL_DISK; + qError("Sort compare init failed since %s", terrstr(code)); + return code; + } + + code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, + "sortComparInit", tsTempDir); + dBufSetPrintInfo(pHandle->pBuf); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + } + if (pHandle->type == SORT_SINGLESOURCE_SORT) { for (int32_t i = 0; i < cmpParam->numOfSources; ++i) { SSortSource* pSource = cmpParam->pSources[i]; @@ -244,22 +263,6 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int releaseBufPage(pHandle->pBuf, pPage); } } else { - // multi-pass internal merge sort is required - if (pHandle->pBuf == NULL) { - if (!osTempSpaceAvailable()) { - terrno = TSDB_CODE_NO_AVAIL_DISK; - code = terrno; - qError("Sort compare init failed since %s", terrstr(terrno)); - return code; - } - code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, - "sortComparInit", tsTempDir); - dBufSetPrintInfo(pHandle->pBuf); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - } - for (int32_t i = 0; i < cmpParam->numOfSources; ++i) { SSortSource* pSource = cmpParam->pSources[i]; pSource->src.pBlock = pHandle->fetchfp(pSource->param); @@ -422,7 +425,7 @@ int32_t msortComparFn(const void* pLeft, const void* pRight, void* param) { SColumnInfoData* pRightColInfoData = TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->slotId); bool rightNull = false; if (pRightColInfoData->hasNull) { - if (pLeftBlock->pBlockAgg == NULL) { + if (pRightBlock->pBlockAgg == NULL) { rightNull = colDataIsNull_s(pRightColInfoData, pRightSource->src.rowIndex); } else { rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, @@ -506,12 +509,14 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { int32_t code = sortComparInit(&pHandle->cmpParam, pHandle->pOrderedSource, i * numOfInputSources, end, pHandle); if (code != TSDB_CODE_SUCCESS) { + taosArrayDestroy(pResList); return code; } code = tMergeTreeCreate(&pHandle->pMergeTree, pHandle->cmpParam.numOfSources, &pHandle->cmpParam, pHandle->comparFn); if (code != TSDB_CODE_SUCCESS) { + taosArrayDestroy(pResList); return code; } @@ -525,6 +530,8 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { int32_t pageId = -1; void* pPage = getNewBufPage(pHandle->pBuf, &pageId); if (pPage == NULL) { + taosArrayDestroy(pResList); + taosArrayDestroy(pPageIdList); return terrno; } diff --git a/source/libs/function/inc/tudfInt.h b/source/libs/function/inc/tudfInt.h index c1b0941d4bd7c7e987999a16357263f87e34dbfc..c69d19b8a6187ad1d6817a6b5f8793b0905817e4 100644 --- a/source/libs/function/inc/tudfInt.h +++ b/source/libs/function/inc/tudfInt.h @@ -35,7 +35,7 @@ enum { }; typedef struct SUdfSetupRequest { - char udfName[TSDB_FUNC_NAME_LEN]; + char udfName[TSDB_FUNC_NAME_LEN + 1]; } SUdfSetupRequest; typedef struct SUdfSetupResponse { diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index cffe1700ed7c957fdddc150e21a434d9526a2123..96a14be4ccec2658d2755648251df8959a859062 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -2436,6 +2436,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .processFunc = cachedLastRowFunction, .finalizeFunc = firstLastFinalize }, + { + .name = "_cache_last", + .type = FUNCTION_TYPE_CACHE_LAST, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_FORBID_STREAM_FUNC, + .translateFunc = translateFirstLast, + .getEnvFunc = getFirstLastFuncEnv, + .initFunc = functionSetup, + .processFunc = lastFunctionMerge, + .finalizeFunc = firstLastFinalize + }, { .name = "_last_row_partial", .type = FUNCTION_TYPE_LAST_PARTIAL, diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 3ed894fe8d97db6ea9283dead8444a2962d7e6c1..88d820bc93e9b3c1d255a439115b6e42409b3d3e 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -57,16 +57,6 @@ typedef struct SAvgRes { int16_t type; // store the original input type, used in merge function } SAvgRes; -typedef struct STuplePos { - union { - struct { - int32_t pageId; - int32_t offset; - }; - STupleKey streamTupleKey; - }; -} STuplePos; - typedef struct SMinmaxResInfo { bool assign; // assign the first value or not int64_t v; @@ -93,17 +83,6 @@ typedef struct STopBotRes { STopBotResItem* pItems; } STopBotRes; -typedef struct SFirstLastRes { - bool hasResult; - // used for last_row function only, isNullRes in SResultRowEntry can not be passed to downstream.So, - // this attribute is required - bool isNull; - int32_t bytes; - int64_t ts; - STuplePos pos; - char buf[]; -} SFirstLastRes; - typedef struct SStddevRes { double result; int64_t count; @@ -1163,13 +1142,13 @@ static int32_t findRowIndex(int32_t start, int32_t num, SColumnInfoData* pCol, c // the data is loaded, not only the block SMA value for (int32_t i = start; i < num + start; ++i) { char* p = colDataGetData(pCol, i); - if (memcpy((void*)tval, p, pCol->info.bytes) == 0) { + if (memcmp((void*)tval, p, pCol->info.bytes) == 0) { return i; } } - ASSERT(0); - return 0; + // if reach here means real data of block SMA is not set in pCtx->input. + return -1; } int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { @@ -1211,7 +1190,9 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { pBuf->v = *(int64_t*)tval; if (pCtx->subsidiaries.num > 0) { index = findRowIndex(pInput->startRowIndex, pInput->numOfRows, pCol, tval); - pBuf->tuplePos = saveTupleData(pCtx, index, pCtx->pSrcBlock, NULL); + if (index >= 0) { + pBuf->tuplePos = saveTupleData(pCtx, index, pCtx->pSrcBlock, NULL); + } } } else { if (IS_SIGNED_NUMERIC_TYPE(type)) { @@ -1223,7 +1204,9 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { *(int64_t*)&pBuf->v = val; if (pCtx->subsidiaries.num > 0) { index = findRowIndex(pInput->startRowIndex, pInput->numOfRows, pCol, tval); - pBuf->tuplePos = saveTupleData(pCtx, index, pCtx->pSrcBlock, NULL); + if (index >= 0) { + pBuf->tuplePos = saveTupleData(pCtx, index, pCtx->pSrcBlock, NULL); + } } } } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { @@ -1235,7 +1218,9 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { *(uint64_t*)&pBuf->v = val; if (pCtx->subsidiaries.num > 0) { index = findRowIndex(pInput->startRowIndex, pInput->numOfRows, pCol, tval); - pBuf->tuplePos = saveTupleData(pCtx, index, pCtx->pSrcBlock, NULL); + if (index >= 0) { + pBuf->tuplePos = saveTupleData(pCtx, index, pCtx->pSrcBlock, NULL); + } } } } else if (type == TSDB_DATA_TYPE_DOUBLE) { @@ -1247,7 +1232,9 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { *(double*)&pBuf->v = val; if (pCtx->subsidiaries.num > 0) { index = findRowIndex(pInput->startRowIndex, pInput->numOfRows, pCol, tval); - pBuf->tuplePos = saveTupleData(pCtx, index, pCtx->pSrcBlock, NULL); + if (index >= 0) { + pBuf->tuplePos = saveTupleData(pCtx, index, pCtx->pSrcBlock, NULL); + } } } } else if (type == TSDB_DATA_TYPE_FLOAT) { @@ -1261,7 +1248,9 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { if (pCtx->subsidiaries.num > 0) { index = findRowIndex(pInput->startRowIndex, pInput->numOfRows, pCol, tval); - pBuf->tuplePos = saveTupleData(pCtx, index, pCtx->pSrcBlock, NULL); + if (index >= 0) { + pBuf->tuplePos = saveTupleData(pCtx, index, pCtx->pSrcBlock, NULL); + } } } } @@ -2545,7 +2534,7 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) { // might be a race condition here that pHisto can be overwritten or setup function // has not been called, need to relink the buffer pHisto points to. buildHistogramInfo(pInfo); - qDebug("%s before add %d elements into histogram, total:%d, numOfEntry:%d, pHisto:%p, elems: %p", __FUNCTION__, + qDebug("%s before add %d elements into histogram, total:%" PRId64 ", numOfEntry:%d, pHisto:%p, elems: %p", __FUNCTION__, numOfElems, pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries, pInfo->pHisto, pInfo->pHisto->elems); for (int32_t i = start; i < pInput->numOfRows + start; ++i) { if (colDataIsNull_f(pCol->nullbitmap, i)) { @@ -2559,8 +2548,9 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) { tHistogramAdd(&pInfo->pHisto, v); } - qDebug("%s after add %d elements into histogram, total:%d, numOfEntry:%d, pHisto:%p, elems: %p", __FUNCTION__, - numOfElems, pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries, pInfo->pHisto, pInfo->pHisto->elems); + qDebug("%s after add %d elements into histogram, total:%" PRId64 ", numOfEntry:%d, pHisto:%p, elems: %p", + __FUNCTION__, numOfElems, pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries, pInfo->pHisto, + pInfo->pHisto->elems); } SET_VAL(pResInfo, numOfElems, 1); @@ -2640,7 +2630,7 @@ int32_t apercentileFunctionMerge(SqlFunctionCtx* pCtx) { } if (pInfo->algo != APERCT_ALGO_TDIGEST) { - qDebug("%s after merge, total:%d, numOfEntry:%d, %p", __FUNCTION__, pInfo->pHisto->numOfElems, + qDebug("%s after merge, total:%" PRId64 ", numOfEntry:%d, %p", __FUNCTION__, pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries, pInfo->pHisto); } @@ -2998,8 +2988,6 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) { static void firstLastTransferInfo(SqlFunctionCtx* pCtx, SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst, int32_t rowIndex) { - SInputColumnInfoData* pColInfo = &pCtx->input; - if (pOutput->hasResult) { if (isFirst) { if (pInput->ts > pOutput->ts) { @@ -6187,99 +6175,6 @@ int32_t groupKeyFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return pResInfo->numOfRes; } -int32_t interpFunction(SqlFunctionCtx* pCtx) { -#if 0 - int32_t fillType = (int32_t) pCtx->param[2].i64; - //bool ascQuery = (pCtx->order == TSDB_ORDER_ASC); - - if (pCtx->start.key == pCtx->startTs) { - assert(pCtx->start.key != INT64_MIN); - - COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->start.val); - - goto interp_success_exit; - } else if (pCtx->end.key == pCtx->startTs && pCtx->end.key != INT64_MIN && fillType == TSDB_FILL_NEXT) { - COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->end.val); - - goto interp_success_exit; - } - - switch (fillType) { - case TSDB_FILL_NULL: - setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes); - break; - - case TSDB_FILL_SET_VALUE: - tVariantDump(&pCtx->param[1], pCtx->pOutput, pCtx->inputType, true); - break; - - case TSDB_FILL_LINEAR: - if (pCtx->start.key == INT64_MIN || pCtx->start.key > pCtx->startTs - || pCtx->end.key == INT64_MIN || pCtx->end.key < pCtx->startTs) { - goto interp_exit; - } - - double v1 = -1, v2 = -1; - GET_TYPED_DATA(v1, double, pCtx->inputType, &pCtx->start.val); - GET_TYPED_DATA(v2, double, pCtx->inputType, &pCtx->end.val); - - SPoint point1 = {.key = pCtx->start.key, .val = &v1}; - SPoint point2 = {.key = pCtx->end.key, .val = &v2}; - SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput}; - - int32_t srcType = pCtx->inputType; - if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) { - setNull(pCtx->pOutput, srcType, pCtx->inputBytes); - } else { - bool exceedMax = false, exceedMin = false; - taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax, &exceedMin); - if (exceedMax || exceedMin) { - __compar_fn_t func = getComparFunc((int32_t)pCtx->inputType, 0); - if (func(&pCtx->start.val, &pCtx->end.val) <= 0) { - COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, exceedMax ? &pCtx->start.val : &pCtx->end.val); - } else { - COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, exceedMax ? &pCtx->end.val : &pCtx->start.val); - } - } - } - break; - - case TSDB_FILL_PREV: - if (pCtx->start.key == INT64_MIN || pCtx->start.key > pCtx->startTs) { - goto interp_exit; - } - - COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->start.val); - break; - - case TSDB_FILL_NEXT: - if (pCtx->end.key == INT64_MIN || pCtx->end.key < pCtx->startTs) { - goto interp_exit; - } - - COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->end.val); - break; - - case TSDB_FILL_NONE: - // do nothing - default: - goto interp_exit; - } - - - interp_success_exit: - *(TSKEY*)pCtx->ptsOutputBuf = pCtx->startTs; - INC_INIT_VAL(pCtx, 1); - - interp_exit: - pCtx->start.key = INT64_MIN; - pCtx->end.key = INT64_MIN; - pCtx->endTs = pCtx->startTs; -#endif - - return TSDB_CODE_SUCCESS; -} - int32_t cachedLastRowFunction(SqlFunctionCtx* pCtx) { int32_t numOfElems = 0; diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index ca8ddbc60acc987735fc7b4f5a43c852e165fd20..fde9084ae302360878aedbf664016f4da2a1a53d 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -16,6 +16,7 @@ #include "functionMgt.h" #include "builtins.h" +#include "builtinsimpl.h" #include "functionMgtInt.h" #include "taos.h" #include "taoserror.h" @@ -314,6 +315,11 @@ bool fmIsSameInOutType(int32_t funcId) { return res; } +void getLastCacheDataType(SDataType* pType) { + pType->bytes = getFirstLastInfoSize(pType->bytes) + VARSTR_HEADER_SIZE; + pType->type = TSDB_DATA_TYPE_BINARY; +} + static int32_t getFuncInfo(SFunctionNode* pFunc) { char msg[128] = {0}; return fmGetFuncInfo(pFunc, msg, sizeof(msg)); @@ -324,7 +330,7 @@ static SFunctionNode* createFunction(const char* pName, SNodeList* pParameterLis if (NULL == pFunc) { return NULL; } - strcpy(pFunc->functionName, pName); + snprintf(pFunc->functionName, sizeof(pFunc->functionName), "%s", pName); pFunc->pParameterList = pParameterList; if (TSDB_CODE_SUCCESS != getFuncInfo(pFunc)) { pFunc->pParameterList = NULL; @@ -402,10 +408,6 @@ static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctio if (TSDB_CODE_SUCCESS == code) { *pMergeFunc = pFunc; } else { - if (NULL != pFunc) { - pFunc->pParameterList = NULL; - nodesDestroyNode((SNode*)pFunc); - } nodesDestroyList(pParameterList); } diff --git a/source/libs/function/src/tpercentile.c b/source/libs/function/src/tpercentile.c index c25d2d4a279301b4ee326895dfb32be3a66bafdf..092410647691546e8bfea5daf7a49cfdae8e183d 100644 --- a/source/libs/function/src/tpercentile.c +++ b/source/libs/function/src/tpercentile.c @@ -96,16 +96,19 @@ double findOnlyResult(tMemBucket *pMemBucket) { } int32_t groupId = getGroupId(pMemBucket->numOfSlots, i, pMemBucket->times); - SArray *list = *(SArray **)taosHashGet(pMemBucket->groupPagesMap, &groupId, sizeof(groupId)); - assert(list->size == 1); + SArray **pList = taosHashGet(pMemBucket->groupPagesMap, &groupId, sizeof(groupId)); + if (pList != NULL) { + SArray *list = *pList; + assert(list->size == 1); - int32_t *pageId = taosArrayGet(list, 0); - SFilePage *pPage = getBufPage(pMemBucket->pBuffer, *pageId); - assert(pPage->num == 1); + int32_t *pageId = taosArrayGet(list, 0); + SFilePage *pPage = getBufPage(pMemBucket->pBuffer, *pageId); + assert(pPage->num == 1); - double v = 0; - GET_TYPED_DATA(v, double, pMemBucket->type, pPage->data); - return v; + double v = 0; + GET_TYPED_DATA(v, double, pMemBucket->type, pPage->data); + return v; + } } return 0; diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index 14833945090c1ca9f6cf860e9d51253dcff5a182..ea59e92e98b5938dd4be954d2837128825c5a747 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -315,7 +315,7 @@ enum { UV_TASK_CONNECT = 0, UV_TASK_REQ_RSP = 1, UV_TASK_DISCONNECT = 2 }; int64_t gUdfTaskSeqNum = 0; typedef struct SUdfcFuncStub { - char udfName[TSDB_FUNC_NAME_LEN]; + char udfName[TSDB_FUNC_NAME_LEN + 1]; UdfcFuncHandle handle; int32_t refCount; int64_t lastRefTime; @@ -339,10 +339,11 @@ typedef struct SUdfcProxy { uv_mutex_t udfStubsMutex; SArray *udfStubs; // SUdfcFuncStub + uv_mutex_t udfcUvMutex; int8_t initialized; } SUdfcProxy; -SUdfcProxy gUdfdProxy = {0}; +SUdfcProxy gUdfcProxy = {0}; typedef struct SUdfcUvSession { SUdfcProxy *udfc; @@ -353,7 +354,7 @@ typedef struct SUdfcUvSession { int32_t outputLen; int32_t bufSize; - char udfName[TSDB_FUNC_NAME_LEN]; + char udfName[TSDB_FUNC_NAME_LEN + 1]; } SUdfcUvSession; typedef struct SClientUvTaskNode { @@ -896,73 +897,73 @@ int compareUdfcFuncSub(const void *elem1, const void *elem2) { int32_t acquireUdfFuncHandle(char *udfName, UdfcFuncHandle *pHandle) { int32_t code = 0; - uv_mutex_lock(&gUdfdProxy.udfStubsMutex); + uv_mutex_lock(&gUdfcProxy.udfStubsMutex); SUdfcFuncStub key = {0}; - strcpy(key.udfName, udfName); - int32_t stubIndex = taosArraySearchIdx(gUdfdProxy.udfStubs, &key, compareUdfcFuncSub, TD_EQ); + strncpy(key.udfName, udfName, TSDB_FUNC_NAME_LEN); + int32_t stubIndex = taosArraySearchIdx(gUdfcProxy.udfStubs, &key, compareUdfcFuncSub, TD_EQ); if (stubIndex != -1) { - SUdfcFuncStub *foundStub = taosArrayGet(gUdfdProxy.udfStubs, stubIndex); + SUdfcFuncStub *foundStub = taosArrayGet(gUdfcProxy.udfStubs, stubIndex); UdfcFuncHandle handle = foundStub->handle; if (handle != NULL && ((SUdfcUvSession *)handle)->udfUvPipe != NULL) { *pHandle = foundStub->handle; ++foundStub->refCount; foundStub->lastRefTime = taosGetTimestampUs(); - uv_mutex_unlock(&gUdfdProxy.udfStubsMutex); + uv_mutex_unlock(&gUdfcProxy.udfStubsMutex); return 0; } else { fnInfo("invalid handle for %s, refCount: %d, last ref time: %" PRId64 ". remove it from cache", udfName, foundStub->refCount, foundStub->lastRefTime); - taosArrayRemove(gUdfdProxy.udfStubs, stubIndex); + taosArrayRemove(gUdfcProxy.udfStubs, stubIndex); } } *pHandle = NULL; code = doSetupUdf(udfName, pHandle); if (code == TSDB_CODE_SUCCESS) { SUdfcFuncStub stub = {0}; - strcpy(stub.udfName, udfName); + strncpy(stub.udfName, udfName, TSDB_FUNC_NAME_LEN); stub.handle = *pHandle; ++stub.refCount; stub.lastRefTime = taosGetTimestampUs(); - taosArrayPush(gUdfdProxy.udfStubs, &stub); - taosArraySort(gUdfdProxy.udfStubs, compareUdfcFuncSub); + taosArrayPush(gUdfcProxy.udfStubs, &stub); + taosArraySort(gUdfcProxy.udfStubs, compareUdfcFuncSub); } else { *pHandle = NULL; } - uv_mutex_unlock(&gUdfdProxy.udfStubsMutex); + uv_mutex_unlock(&gUdfcProxy.udfStubsMutex); return code; } void releaseUdfFuncHandle(char *udfName) { - uv_mutex_lock(&gUdfdProxy.udfStubsMutex); + uv_mutex_lock(&gUdfcProxy.udfStubsMutex); SUdfcFuncStub key = {0}; - strcpy(key.udfName, udfName); - SUdfcFuncStub *foundStub = taosArraySearch(gUdfdProxy.udfStubs, &key, compareUdfcFuncSub, TD_EQ); + strncpy(key.udfName, udfName, TSDB_FUNC_NAME_LEN); + SUdfcFuncStub *foundStub = taosArraySearch(gUdfcProxy.udfStubs, &key, compareUdfcFuncSub, TD_EQ); if (!foundStub) { - uv_mutex_unlock(&gUdfdProxy.udfStubsMutex); + uv_mutex_unlock(&gUdfcProxy.udfStubsMutex); return; } if (foundStub->refCount > 0) { --foundStub->refCount; } - uv_mutex_unlock(&gUdfdProxy.udfStubsMutex); + uv_mutex_unlock(&gUdfcProxy.udfStubsMutex); } int32_t cleanUpUdfs() { - int8_t initialized = atomic_load_8(&gUdfdProxy.initialized); + int8_t initialized = atomic_load_8(&gUdfcProxy.initialized); if (!initialized) { return TSDB_CODE_SUCCESS; } - uv_mutex_lock(&gUdfdProxy.udfStubsMutex); - if (gUdfdProxy.udfStubs == NULL || taosArrayGetSize(gUdfdProxy.udfStubs) == 0) { - uv_mutex_unlock(&gUdfdProxy.udfStubsMutex); + uv_mutex_lock(&gUdfcProxy.udfStubsMutex); + if (gUdfcProxy.udfStubs == NULL || taosArrayGetSize(gUdfcProxy.udfStubs) == 0) { + uv_mutex_unlock(&gUdfcProxy.udfStubsMutex); return TSDB_CODE_SUCCESS; } SArray *udfStubs = taosArrayInit(16, sizeof(SUdfcFuncStub)); int32_t i = 0; - while (i < taosArrayGetSize(gUdfdProxy.udfStubs)) { - SUdfcFuncStub *stub = taosArrayGet(gUdfdProxy.udfStubs, i); + while (i < taosArrayGetSize(gUdfcProxy.udfStubs)) { + SUdfcFuncStub *stub = taosArrayGet(gUdfcProxy.udfStubs, i); if (stub->refCount == 0) { fnInfo("tear down udf. udf name: %s, handle: %p, ref count: %d", stub->udfName, stub->handle, stub->refCount); doTeardownUdf(stub->handle); @@ -979,9 +980,9 @@ int32_t cleanUpUdfs() { } ++i; } - taosArrayDestroy(gUdfdProxy.udfStubs); - gUdfdProxy.udfStubs = udfStubs; - uv_mutex_unlock(&gUdfdProxy.udfStubsMutex); + taosArrayDestroy(gUdfcProxy.udfStubs); + gUdfcProxy.udfStubs = udfStubs; + uv_mutex_unlock(&gUdfcProxy.udfStubsMutex); return 0; } @@ -1157,9 +1158,11 @@ void onUdfcPipeClose(uv_handle_t *handle) { QUEUE_REMOVE(&task->procTaskQueue); uv_sem_post(&task->taskSem); } + uv_mutex_lock(&gUdfcProxy.udfcUvMutex); if (conn->session != NULL) { conn->session->udfUvPipe = NULL; } + uv_mutex_unlock(&gUdfcProxy.udfcUvMutex); taosMemoryFree(conn->readBuf.buf); taosMemoryFree(conn); taosMemoryFree((uv_pipe_t *)handle); @@ -1269,7 +1272,7 @@ void udfcUvHandleRsp(SClientUvConn *conn) { SClientUvTaskNode *task = QUEUE_DATA(h, SClientUvTaskNode, connTaskQueue); while (h != &conn->taskQueue) { - fnDebug("udfc handle response iterate through queue. uvTask:%d-%p", task->seqNum, task); + fnDebug("udfc handle response iterate through queue. uvTask:%" PRId64 "-%p", task->seqNum, task); if (task->seqNum == seqNum) { if (found == false) { found = true; @@ -1446,6 +1449,7 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) { QUEUE_INSERT_TAIL(connTaskQueue, &uvTask->connTaskQueue); int err = uv_write(write, (uv_stream_t *)pipe, &uvTask->reqBuf, 1, onUdfcPipeWrite); if (err != 0) { + taosMemoryFree(write); fnError("udfc event loop start req_rsp task uv_write failed. uvtask: %p, code: %s", uvTask, uv_strerror(err)); } code = err; @@ -1552,11 +1556,11 @@ void constructUdfService(void *argsThread) { } int32_t udfcOpen() { - int8_t old = atomic_val_compare_exchange_8(&gUdfdProxy.initialized, 0, 1); + int8_t old = atomic_val_compare_exchange_8(&gUdfcProxy.initialized, 0, 1); if (old == 1) { return 0; } - SUdfcProxy *proxy = &gUdfdProxy; + SUdfcProxy *proxy = &gUdfcProxy; getUdfdPipeName(proxy->udfdPipeName, sizeof(proxy->udfdPipeName)); proxy->udfcState = UDFC_STATE_STARTNG; uv_barrier_init(&proxy->initBarrier, 2); @@ -1566,16 +1570,17 @@ int32_t udfcOpen() { uv_barrier_wait(&proxy->initBarrier); uv_mutex_init(&proxy->udfStubsMutex); proxy->udfStubs = taosArrayInit(8, sizeof(SUdfcFuncStub)); + uv_mutex_init(&proxy->udfcUvMutex); fnInfo("udfc initialized") return 0; } int32_t udfcClose() { - int8_t old = atomic_val_compare_exchange_8(&gUdfdProxy.initialized, 1, 0); + int8_t old = atomic_val_compare_exchange_8(&gUdfcProxy.initialized, 1, 0); if (old == 0) { return 0; } - SUdfcProxy *udfc = &gUdfdProxy; + SUdfcProxy *udfc = &gUdfcProxy; udfc->udfcState = UDFC_STATE_STOPPING; uv_async_send(&udfc->loopStopAsync); uv_thread_join(&udfc->loopThread); @@ -1583,6 +1588,7 @@ int32_t udfcClose() { uv_barrier_destroy(&udfc->initBarrier); taosArrayDestroy(udfc->udfStubs); uv_mutex_destroy(&udfc->udfStubsMutex); + uv_mutex_destroy(&udfc->udfcUvMutex); udfc->udfcState = UDFC_STATE_INITAL; fnInfo("udfc is cleaned up"); return 0; @@ -1610,13 +1616,13 @@ int32_t udfcRunUdfUvTask(SClientUdfTask *task, int8_t uvTaskType) { } int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle) { - if (gUdfdProxy.udfcState != UDFC_STATE_READY) { + if (gUdfcProxy.udfcState != UDFC_STATE_READY) { return TSDB_CODE_UDF_INVALID_STATE; } SClientUdfTask *task = taosMemoryCalloc(1, sizeof(SClientUdfTask)); task->errCode = 0; task->session = taosMemoryCalloc(1, sizeof(SUdfcUvSession)); - task->session->udfc = &gUdfdProxy; + task->session->udfc = &gUdfcProxy; task->type = UDF_TASK_SETUP; SUdfSetupRequest *req = &task->_setup.req; @@ -1624,7 +1630,7 @@ int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle) { int32_t errCode = udfcRunUdfUvTask(task, UV_TASK_CONNECT); if (errCode != 0) { - fnError("failed to connect to pipe. udfName: %s, pipe: %s", udfName, (&gUdfdProxy)->udfdPipeName); + fnError("failed to connect to pipe. udfName: %s, pipe: %s", udfName, (&gUdfcProxy)->udfdPipeName); taosMemoryFree(task->session); taosMemoryFree(task); return TSDB_CODE_UDF_PIPE_CONNECT_ERR; @@ -1637,7 +1643,7 @@ int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle) { task->session->outputType = rsp->outputType; task->session->outputLen = rsp->outputLen; task->session->bufSize = rsp->bufSize; - strcpy(task->session->udfName, udfName); + strncpy(task->session->udfName, udfName, TSDB_FUNC_NAME_LEN); if (task->errCode != 0) { fnError("failed to setup udf. udfname: %s, err: %d", udfName, task->errCode) } else { @@ -1798,10 +1804,12 @@ int32_t doTeardownUdf(UdfcFuncHandle handle) { fnInfo("tear down udf. udf name: %s, udf func handle: %p", session->udfName, handle); // TODO: synchronization refactor between libuv event loop and request thread + uv_mutex_lock(&gUdfcProxy.udfcUvMutex); if (session->udfUvPipe != NULL && session->udfUvPipe->data != NULL) { SClientUvConn *conn = session->udfUvPipe->data; conn->session = NULL; } + uv_mutex_unlock(&gUdfcProxy.udfcUvMutex); taosMemoryFree(session); taosMemoryFree(task); diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index a319b5a25b3bd168f7b52e365bf1b3ada8848077..f8c4f171ba8cfc75a5f5072ecb4cf1a371ef16a7 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -71,7 +71,7 @@ typedef struct SUdf { uv_cond_t condReady; bool resident; - char name[TSDB_FUNC_NAME_LEN]; + char name[TSDB_FUNC_NAME_LEN + 1]; int8_t funcType; int8_t scriptType; int8_t outputType; @@ -188,11 +188,12 @@ void udfdProcessSetupRequest(SUvUdfWork *uvUdf, SUdfRequest *request) { SUdf *udfNew = taosMemoryCalloc(1, sizeof(SUdf)); udfNew->refCount = 1; udfNew->state = UDF_STATE_INIT; - uv_mutex_init(&udfNew->lock); uv_cond_init(&udfNew->condReady); + udf = udfNew; - taosHashPut(global.udfsHash, request->setup.udfName, strlen(request->setup.udfName), &udfNew, sizeof(&udfNew)); + SUdf** pUdf = &udf; + taosHashPut(global.udfsHash, request->setup.udfName, strlen(request->setup.udfName), pUdf, POINTER_BYTES); uv_mutex_unlock(&global.udfsMutex); } @@ -246,7 +247,7 @@ void udfdProcessSetupRequest(SUvUdfWork *uvUdf, SUdfRequest *request) { void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request) { SUdfCallRequest *call = &request->call; - fnDebug("%" PRId64 "call request. call type %d, handle: %" PRIx64, request->seqNum, call->callType, call->udfHandle); + fnDebug("call request. call type %d, handle: %" PRIx64 ", seq num %" PRId64 , call->callType, call->udfHandle, request->seqNum); SUdfcFuncHandle * handle = (SUdfcFuncHandle *)(call->udfHandle); SUdf * udf = handle->udf; SUdfResponse response = {0}; @@ -372,7 +373,7 @@ void udfdProcessTeardownRequest(SUvUdfWork *uvUdf, SUdfRequest *request) { } taosMemoryFree(handle); - SUdfResponse response; + SUdfResponse response = {0}; SUdfResponse *rsp = &response; rsp->seqNum = request->seqNum; rsp->type = request->type; @@ -428,7 +429,9 @@ void udfdProcessRpcRsp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { } else if (msgInfo->rpcType == UDFD_RPC_RETRIVE_FUNC) { SRetrieveFuncRsp retrieveRsp = {0}; tDeserializeSRetrieveFuncRsp(pMsg->pCont, pMsg->contLen, &retrieveRsp); - + if (retrieveRsp.pFuncInfos == NULL) { + goto _return; + } SFuncInfo *pFuncInfo = (SFuncInfo *)taosArrayGet(retrieveRsp.pFuncInfos, 0); SUdf * udf = msgInfo->param; udf->funcType = pFuncInfo->funcType; @@ -540,7 +543,7 @@ int32_t udfdConnectToMnode() { } int32_t udfdLoadUdf(char *udfName, SUdf *udf) { - strcpy(udf->name, udfName); + strncpy(udf->name, udfName, TSDB_FUNC_NAME_LEN); int32_t err = 0; err = udfdFillUdfInfoFromMNode(global.clientRpc, udf->name, udf); @@ -880,6 +883,8 @@ static int32_t udfdUvInit() { uv_loop_t *loop = taosMemoryMalloc(sizeof(uv_loop_t)); if (loop) { uv_loop_init(loop); + } else { + return -1; } global.loop = loop; @@ -901,12 +906,12 @@ static int32_t udfdUvInit() { if ((r = uv_pipe_bind(&global.listeningPipe, global.listenPipeName))) { fnError("Bind error %s", uv_err_name(r)); removeListeningPipe(); - return -1; + return -2; } if ((r = uv_listen((uv_stream_t *)&global.listeningPipe, 128, udfdOnNewConnection))) { fnError("Listen error %s", uv_err_name(r)); removeListeningPipe(); - return -2; + return -3; } return 0; } @@ -962,6 +967,7 @@ int32_t udfdInitResidentFuncs() { while ((token = strtok_r(pSave, ",", &pSave)) != NULL) { char func[TSDB_FUNC_NAME_LEN+1] = {0}; strncpy(func, token, TSDB_FUNC_NAME_LEN); + fnInfo("udfd add resident function %s", func); taosArrayPush(global.residentFuncs, func); } diff --git a/source/libs/function/test/runUdf.c b/source/libs/function/test/runUdf.c index f1e3f4c60c281ebac963ac65c7d7d9f8437652cd..b5d1b1576b7b33d3ca6511e2bdf707daa8e78a41 100644 --- a/source/libs/function/test/runUdf.c +++ b/source/libs/function/test/runUdf.c @@ -110,8 +110,11 @@ int aggregateFuncTest() { taosArrayDestroy(pBlock->pDataBlock); doCallUdfAggFinalize(handle, &newBuf, &resultBuf); - fprintf(stderr, "agg result: %f\n", *(double *)resultBuf.buf); - + if (resultBuf.buf != NULL) { + fprintf(stderr, "agg result: %f\n", *(double *)resultBuf.buf); + } else { + fprintf(stderr, "result buffer is null"); + } freeUdfInterBuf(&buf); freeUdfInterBuf(&newBuf); freeUdfInterBuf(&resultBuf); diff --git a/source/libs/index/inc/indexFst.h b/source/libs/index/inc/indexFst.h index 4c5bca864a0be6b4926965fc1695a8e61d88feaa..ddeaee06ea024da687c44846c7d63fb0183bbbd0 100644 --- a/source/libs/index/inc/indexFst.h +++ b/source/libs/index/inc/indexFst.h @@ -290,21 +290,21 @@ bool fstVerify(Fst* fst); // refactor this function bool fstBuilderNodeCompileTo(FstBuilderNode* b, IdxFstFile* wrt, CompiledAddr lastAddr, CompiledAddr startAddr); -typedef struct StreamState { +typedef struct FstStreamState { FstNode* node; uint64_t trans; FstOutput out; void* autState; -} StreamState; +} FstStreamState; -void streamStateDestroy(void* s); +void fstStreamStateDestroy(void* s); typedef struct FStmSt { Fst* fst; FAutoCtx* aut; SArray* inp; FstOutput emptyOutput; - SArray* stack; // + SArray* stack; // FstBoundWithData* endAt; } FStmSt; @@ -317,14 +317,14 @@ typedef struct FStmStRslt { FStmStRslt* swsResultCreate(FstSlice* data, FstOutput fOut, void* state); void swsResultDestroy(FStmStRslt* result); -typedef void* (*StreamCallback)(void*); +typedef void* (*streamCallback__fn)(void*); FStmSt* stmStCreate(Fst* fst, FAutoCtx* automation, FstBoundWithData* min, FstBoundWithData* max); void stmStDestroy(FStmSt* sws); bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min); -FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback); +FStmStRslt* stmStNextWith(FStmSt* sws, streamCallback__fn callback); FStmBuilder* stmBuilderCreate(Fst* fst, FAutoCtx* aut); diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index 25036996fcf24ce4283d8269e6164b62efa95f6b..e3f140047ab1fa02b328813293300096386cc4d6 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -367,7 +367,7 @@ int32_t idxConvertData(void* src, int8_t type, void** dst) { tlen = taosEncodeBinary(dst, src, strlen(src)); break; default: - TASSERT(0); + ASSERT(0); break; } *dst = (char*)*dst - tlen; @@ -459,7 +459,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { *dst = (char*)*dst - tlen; break; default: - TASSERT(0); + ASSERT(0); break; } return tlen; diff --git a/source/libs/index/src/indexFst.c b/source/libs/index/src/indexFst.c index aed2ec3ee321011d9777b437ae9453296b6bbc62..bbffcfa6c17aa628b0afc79ba96746d764add523 100644 --- a/source/libs/index/src/indexFst.c +++ b/source/libs/index/src/indexFst.c @@ -1165,7 +1165,7 @@ FStmSt* stmStCreate(Fst* fst, FAutoCtx* automation, FstBoundWithData* min, FstBo sws->emptyOutput.null = true; sws->emptyOutput.out = 0; - sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState)); + sws->stack = (SArray*)taosArrayInit(256, sizeof(FstStreamState)); sws->endAt = max; stmStSeekMin(sws, min); @@ -1177,7 +1177,7 @@ void stmStDestroy(FStmSt* sws) { } taosArrayDestroy(sws->inp); - taosArrayDestroyEx(sws->stack, streamStateDestroy); + taosArrayDestroyEx(sws->stack, fstStreamStateDestroy); taosMemoryFree(sws); } @@ -1188,10 +1188,10 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { if (fstBoundWithDataIsIncluded(min)) { sws->emptyOutput.out = fstEmptyFinalOutput(sws->fst, &(sws->emptyOutput.null)); } - StreamState s = {.node = fstGetRoot(sws->fst), - .trans = 0, - .out = {.null = false, .out = 0}, - .autState = automFuncs[aut->type].start(aut)}; // auto.start callback + FstStreamState s = {.node = fstGetRoot(sws->fst), + .trans = 0, + .out = {.null = false, .out = 0}, + .autState = automFuncs[aut->type].start(aut)}; // auto.start callback taosArrayPush(sws->stack, &s); return true; } @@ -1223,7 +1223,7 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { autState = automFuncs[aut->type].accept(aut, preState, b); taosArrayPush(sws->inp, &b); - StreamState s = {.node = node, .trans = res + 1, .out = {.null = false, .out = out}, .autState = preState}; + FstStreamState s = {.node = node, .trans = res + 1, .out = {.null = false, .out = out}, .autState = preState}; node = NULL; taosArrayPush(sws->stack, &s); @@ -1244,7 +1244,7 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { } } - StreamState s = {.node = node, .trans = i, .out = {.null = false, .out = out}, .autState = autState}; + FstStreamState s = {.node = node, .trans = i, .out = {.null = false, .out = out}, .autState = autState}; taosArrayPush(sws->stack, &s); taosMemoryFree(trans); return true; @@ -1255,7 +1255,7 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { uint32_t sz = taosArrayGetSize(sws->stack); if (sz != 0) { - StreamState* s = taosArrayGet(sws->stack, sz - 1); + FstStreamState* s = taosArrayGet(sws->stack, sz - 1); if (inclusize) { s->trans -= 1; taosArrayPop(sws->inp); @@ -1264,7 +1264,7 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { uint64_t trans = s->trans; FstTransition trn; fstNodeGetTransitionAt(n, trans - 1, &trn); - StreamState s = { + FstStreamState s = { .node = fstGetNode(sws->fst, trn.addr), .trans = 0, .out = {.null = false, .out = out}, .autState = autState}; taosArrayPush(sws->stack, &s); return true; @@ -1274,14 +1274,14 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { return false; } -FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) { +FStmStRslt* stmStNextWith(FStmSt* sws, streamCallback__fn callback) { FAutoCtx* aut = sws->aut; FstOutput output = sws->emptyOutput; if (output.null == false) { FstSlice emptySlice = fstSliceCreate(NULL, 0); if (fstBoundWithDataExceededBy(sws->endAt, &emptySlice)) { - taosArrayDestroyEx(sws->stack, streamStateDestroy); - sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState)); + taosArrayDestroyEx(sws->stack, fstStreamStateDestroy); + sws->stack = (SArray*)taosArrayInit(256, sizeof(FstStreamState)); return NULL; } void* start = automFuncs[aut->type].start(aut); @@ -1292,12 +1292,12 @@ FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) { } SArray* nodes = taosArrayInit(8, sizeof(FstNode*)); while (taosArrayGetSize(sws->stack) > 0) { - StreamState* p = (StreamState*)taosArrayPop(sws->stack); + FstStreamState* p = (FstStreamState*)taosArrayPop(sws->stack); if (p->trans >= FST_NODE_LEN(p->node) || !automFuncs[aut->type].canMatch(aut, p->autState)) { if (FST_NODE_ADDR(p->node) != fstGetRootAddr(sws->fst)) { taosArrayPop(sws->inp); } - streamStateDestroy(p); + fstStreamStateDestroy(p); continue; } FstTransition trn; @@ -1318,10 +1318,10 @@ FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) { isMatch = automFuncs[aut->type].isMatch(aut, eofState); } } - StreamState s1 = {.node = p->node, .trans = p->trans + 1, .out = p->out, .autState = p->autState}; + FstStreamState s1 = {.node = p->node, .trans = p->trans + 1, .out = p->out, .autState = p->autState}; taosArrayPush(sws->stack, &s1); - StreamState s2 = {.node = nextNode, .trans = 0, .out = {.null = false, .out = out}, .autState = nextState}; + FstStreamState s2 = {.node = nextNode, .trans = 0, .out = {.null = false, .out = out}, .autState = nextState}; taosArrayPush(sws->stack, &s2); int32_t isz = taosArrayGetSize(sws->inp); @@ -1331,8 +1331,8 @@ FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) { } FstSlice slice = fstSliceCreate(buf, isz); if (fstBoundWithDataExceededBy(sws->endAt, &slice)) { - taosArrayDestroyEx(sws->stack, streamStateDestroy); - sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState)); + taosArrayDestroyEx(sws->stack, fstStreamStateDestroy); + sws->stack = (SArray*)taosArrayInit(256, sizeof(FstStreamState)); taosMemoryFreeClear(buf); fstSliceDestroy(&slice); taosArrayDestroy(nodes); @@ -1375,11 +1375,11 @@ void swsResultDestroy(FStmStRslt* result) { taosMemoryFree(result); } -void streamStateDestroy(void* s) { +void fstStreamStateDestroy(void* s) { if (NULL == s) { return; } - StreamState* ss = (StreamState*)s; + FstStreamState* ss = (FstStreamState*)s; fstNodeDestroy(ss->node); } diff --git a/source/libs/index/src/indexJson.c b/source/libs/index/src/indexJson.c index 8ce625dfb996dc88d67114eff79e12af56011275..32b794cb71d6d1e179b4f43cf041eff3e6d300a9 100644 --- a/source/libs/index/src/indexJson.c +++ b/source/libs/index/src/indexJson.c @@ -30,7 +30,7 @@ int indexJsonPut(SIndexJson *index, SIndexJsonMultiTerm *terms, uint64_t uid) { } else { p->colType = TSDB_DATA_TYPE_DOUBLE; } - IDX_TYPE_ADD_EXTERN_TYPE(p->colType, TSDB_DATA_TYPE_JSON); + IDX_TYPE_ADD_EXTERN_TYPE((p->colType), TSDB_DATA_TYPE_JSON); } // handle put return indexPut(index, terms, uid); diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index 890a59e4be29cdc66ca39c7803830eecb9b23a95..70792ee6111e60e6ba002aa1100f898add979d07 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -450,17 +450,10 @@ static void monGenDiskJson(SMonInfo *pMonitor) { } static const char *monLogLevelStr(ELogLevel level) { - switch (level) { - case DEBUG_ERROR: - return "error"; - case DEBUG_INFO: - return "info"; - case DEBUG_DEBUG: - return "debug"; - case DEBUG_TRACE: - return "trace"; - default: - return "undefine"; + if (level == DEBUG_ERROR) { + return "error"; + } else { + return "info"; } } diff --git a/source/libs/monitor/src/monMsg.c b/source/libs/monitor/src/monMsg.c index bbee8b1166903bfcafb611baf7b2bf8ed8b48699..c20055067e5b925306dfc7746d93db5a02c12d1e 100644 --- a/source/libs/monitor/src/monMsg.c +++ b/source/libs/monitor/src/monMsg.c @@ -18,272 +18,6 @@ #include "tcoding.h" #include "tencode.h" -static int32_t tEncodeSMonSysInfo(SEncoder *encoder, const SMonSysInfo *pInfo) { - if (tEncodeDouble(encoder, pInfo->cpu_engine) < 0) return -1; - if (tEncodeDouble(encoder, pInfo->cpu_system) < 0) return -1; - if (tEncodeFloat(encoder, pInfo->cpu_cores) < 0) return -1; - if (tEncodeI64(encoder, pInfo->mem_engine) < 0) return -1; - if (tEncodeI64(encoder, pInfo->mem_system) < 0) return -1; - if (tEncodeI64(encoder, pInfo->mem_total) < 0) return -1; - if (tEncodeI64(encoder, pInfo->disk_engine) < 0) return -1; - if (tEncodeI64(encoder, pInfo->disk_used) < 0) return -1; - if (tEncodeI64(encoder, pInfo->disk_total) < 0) return -1; - if (tEncodeI64(encoder, pInfo->net_in) < 0) return -1; - if (tEncodeI64(encoder, pInfo->net_out) < 0) return -1; - if (tEncodeI64(encoder, pInfo->io_read) < 0) return -1; - if (tEncodeI64(encoder, pInfo->io_write) < 0) return -1; - if (tEncodeI64(encoder, pInfo->io_read_disk) < 0) return -1; - if (tEncodeI64(encoder, pInfo->io_write_disk) < 0) return -1; - return 0; -} - -static int32_t tDecodeSMonSysInfo(SDecoder *decoder, SMonSysInfo *pInfo) { - if (tDecodeDouble(decoder, &pInfo->cpu_engine) < 0) return -1; - if (tDecodeDouble(decoder, &pInfo->cpu_system) < 0) return -1; - if (tDecodeFloat(decoder, &pInfo->cpu_cores) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->mem_engine) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->mem_system) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->mem_total) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->disk_engine) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->disk_used) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->disk_total) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->net_in) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->net_out) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->io_read) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->io_write) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->io_read_disk) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->io_write_disk) < 0) return -1; - return 0; -} - -int32_t tEncodeSMonLogs(SEncoder *encoder, const SMonLogs *pInfo) { - if (tEncodeI32(encoder, pInfo->numOfErrorLogs) < 0) return -1; - if (tEncodeI32(encoder, pInfo->numOfInfoLogs) < 0) return -1; - if (tEncodeI32(encoder, pInfo->numOfDebugLogs) < 0) return -1; - if (tEncodeI32(encoder, pInfo->numOfTraceLogs) < 0) return -1; - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->logs)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->logs); ++i) { - SMonLogItem *pLog = taosArrayGet(pInfo->logs, i); - if (tEncodeI64(encoder, pLog->ts) < 0) return -1; - if (tEncodeI8(encoder, pLog->level) < 0) return -1; - if (tEncodeCStr(encoder, pLog->content) < 0) return -1; - } - return 0; -} - -static int32_t tDecodeSMonLogs(SDecoder *decoder, SMonLogs *pInfo) { - if (tDecodeI32(decoder, &pInfo->numOfErrorLogs) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->numOfInfoLogs) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->numOfDebugLogs) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->numOfTraceLogs) < 0) return -1; - - int32_t arraySize = 0; - if (tDecodeI32(decoder, &arraySize) < 0) return -1; - - pInfo->logs = taosArrayInit(arraySize, sizeof(SMonLogItem)); - if (pInfo->logs == NULL) return -1; - - for (int32_t i = 0; i < arraySize; ++i) { - SMonLogItem desc = {0}; - if (tDecodeI64(decoder, &desc.ts) < 0) return -1; - int8_t level = 0; - if (tDecodeI8(decoder, &level) < 0) return -1; - desc.level = level; - if (tDecodeCStrTo(decoder, desc.content) < 0) return -1; - taosArrayPush(pInfo->logs, &desc); - } - - return 0; -} - -int32_t tEncodeSMonClusterInfo(SEncoder *encoder, const SMonClusterInfo *pInfo) { - if (tEncodeCStr(encoder, pInfo->first_ep) < 0) return -1; - if (tEncodeI32(encoder, pInfo->first_ep_dnode_id) < 0) return -1; - if (tEncodeCStr(encoder, pInfo->version) < 0) return -1; - if (tEncodeFloat(encoder, pInfo->master_uptime) < 0) return -1; - if (tEncodeI32(encoder, pInfo->monitor_interval) < 0) return -1; - if (tEncodeI32(encoder, pInfo->dbs_total) < 0) return -1; - if (tEncodeI32(encoder, pInfo->stbs_total) < 0) return -1; - if (tEncodeI64(encoder, pInfo->tbs_total) < 0) return -1; - if (tEncodeI32(encoder, pInfo->vgroups_total) < 0) return -1; - if (tEncodeI32(encoder, pInfo->vgroups_alive) < 0) return -1; - if (tEncodeI32(encoder, pInfo->vnodes_total) < 0) return -1; - if (tEncodeI32(encoder, pInfo->vnodes_alive) < 0) return -1; - if (tEncodeI32(encoder, pInfo->connections_total) < 0) return -1; - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->dnodes)) < 0) return -1; - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->mnodes)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->dnodes); ++i) { - SMonDnodeDesc *pDesc = taosArrayGet(pInfo->dnodes, i); - if (tEncodeI32(encoder, pDesc->dnode_id) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->dnode_ep) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->status) < 0) return -1; - } - for (int32_t i = 0; i < taosArrayGetSize(pInfo->mnodes); ++i) { - SMonMnodeDesc *pDesc = taosArrayGet(pInfo->mnodes, i); - if (tEncodeI32(encoder, pDesc->mnode_id) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->mnode_ep) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->role) < 0) return -1; - } - return 0; -} - -int32_t tDecodeSMonClusterInfo(SDecoder *decoder, SMonClusterInfo *pInfo) { - if (tDecodeCStrTo(decoder, pInfo->first_ep) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->first_ep_dnode_id) < 0) return -1; - if (tDecodeCStrTo(decoder, pInfo->version) < 0) return -1; - if (tDecodeFloat(decoder, &pInfo->master_uptime) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->monitor_interval) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->dbs_total) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->stbs_total) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->tbs_total) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->vgroups_total) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->vgroups_alive) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->vnodes_total) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->vnodes_alive) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->connections_total) < 0) return -1; - - int32_t dnodesSize = 0; - int32_t mnodesSize = 0; - if (tDecodeI32(decoder, &dnodesSize) < 0) return -1; - if (tDecodeI32(decoder, &mnodesSize) < 0) return -1; - - pInfo->dnodes = taosArrayInit(dnodesSize, sizeof(SMonDnodeDesc)); - pInfo->mnodes = taosArrayInit(mnodesSize, sizeof(SMonMnodeDesc)); - if (pInfo->dnodes == NULL || pInfo->mnodes == NULL) return -1; - - for (int32_t i = 0; i < dnodesSize; ++i) { - SMonDnodeDesc desc = {0}; - if (tDecodeI32(decoder, &desc.dnode_id) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.dnode_ep) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.status) < 0) return -1; - taosArrayPush(pInfo->dnodes, &desc); - } - - for (int32_t i = 0; i < mnodesSize; ++i) { - SMonMnodeDesc desc = {0}; - if (tDecodeI32(decoder, &desc.mnode_id) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.mnode_ep) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.role) < 0) return -1; - taosArrayPush(pInfo->mnodes, &desc); - } - return 0; -} - -int32_t tEncodeSMonVgroupInfo(SEncoder *encoder, const SMonVgroupInfo *pInfo) { - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->vgroups)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->vgroups); ++i) { - SMonVgroupDesc *pDesc = taosArrayGet(pInfo->vgroups, i); - if (tEncodeI32(encoder, pDesc->vgroup_id) < 0) return -1; - if (tEncodeI32(encoder, pDesc->tables_num) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->database_name) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->status) < 0) return -1; - for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) { - SMonVnodeDesc *pVDesc = &pDesc->vnodes[j]; - if (tEncodeI32(encoder, pVDesc->dnode_id) < 0) return -1; - if (tEncodeCStr(encoder, pVDesc->vnode_role) < 0) return -1; - } - } - return 0; -} - -int32_t tDecodeSMonVgroupInfo(SDecoder *decoder, SMonVgroupInfo *pInfo) { - int32_t arraySize = 0; - if (tDecodeI32(decoder, &arraySize) < 0) return -1; - - pInfo->vgroups = taosArrayInit(arraySize, sizeof(SMonVgroupDesc)); - if (pInfo->vgroups == NULL) return -1; - - for (int32_t i = 0; i < arraySize; ++i) { - SMonVgroupDesc desc = {0}; - if (tDecodeI32(decoder, &desc.vgroup_id) < 0) return -1; - if (tDecodeI32(decoder, &desc.tables_num) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.database_name) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.status) < 0) return -1; - for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) { - SMonVnodeDesc *pVDesc = &desc.vnodes[j]; - if (tDecodeI32(decoder, &pVDesc->dnode_id) < 0) return -1; - if (tDecodeCStrTo(decoder, pVDesc->vnode_role) < 0) return -1; - } - taosArrayPush(pInfo->vgroups, &desc); - } - return 0; -} - -int32_t tEncodeSMonStbInfo(SEncoder *encoder, const SMonStbInfo *pInfo) { - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->stbs)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->stbs); ++i) { - SMonStbDesc *pDesc = taosArrayGet(pInfo->stbs, i); - if (tEncodeCStr(encoder, pDesc->stb_name) < 0) return -1; - if (tEncodeCStr(encoder, pDesc->database_name) < 0) return -1; - } - return 0; -} - -int32_t tDecodeSMonStbInfo(SDecoder *decoder, SMonStbInfo *pInfo) { - int32_t arraySize = 0; - if (tDecodeI32(decoder, &arraySize) < 0) return -1; - - pInfo->stbs = taosArrayInit(arraySize, sizeof(SMonStbDesc)); - if (pInfo->stbs == NULL) return -1; - - for (int32_t i = 0; i < arraySize; ++i) { - SMonStbDesc desc = {0}; - if (tDecodeCStrTo(decoder, desc.stb_name) < 0) return -1; - if (tDecodeCStrTo(decoder, desc.database_name) < 0) return -1; - taosArrayPush(pInfo->stbs, &desc); - } - return 0; -} - -int32_t tEncodeSMonGrantInfo(SEncoder *encoder, const SMonGrantInfo *pInfo) { - if (tEncodeI32(encoder, pInfo->expire_time) < 0) return -1; - if (tEncodeI64(encoder, pInfo->timeseries_used) < 0) return -1; - if (tEncodeI64(encoder, pInfo->timeseries_total) < 0) return -1; - return 0; -} - -int32_t tDecodeSMonGrantInfo(SDecoder *decoder, SMonGrantInfo *pInfo) { - if (tDecodeI32(decoder, &pInfo->expire_time) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->timeseries_used) < 0) return -1; - if (tDecodeI64(decoder, &pInfo->timeseries_total) < 0) return -1; - return 0; -} - -int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeSMonClusterInfo(&encoder, &pInfo->cluster) < 0) return -1; - if (tEncodeSMonVgroupInfo(&encoder, &pInfo->vgroup) < 0) return -1; - if (tEncodeSMonStbInfo(&encoder, &pInfo->stb) < 0) return -1; - if (tEncodeSMonGrantInfo(&encoder, &pInfo->grant) < 0) return -1; - if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeSMonClusterInfo(&decoder, &pInfo->cluster) < 0) return -1; - if (tDecodeSMonVgroupInfo(&decoder, &pInfo->vgroup) < 0) return -1; - if (tDecodeSMonStbInfo(&decoder, &pInfo->stb) < 0) return -1; - if (tDecodeSMonGrantInfo(&decoder, &pInfo->grant) < 0) return -1; - if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - void tFreeSMonMmInfo(SMonMmInfo *pInfo) { taosArrayDestroy(pInfo->log.logs); taosArrayDestroy(pInfo->cluster.mnodes); @@ -297,106 +31,6 @@ void tFreeSMonMmInfo(SMonMmInfo *pInfo) { pInfo->log.logs = NULL; } -int32_t tEncodeSMonDiskDesc(SEncoder *encoder, const SMonDiskDesc *pDesc) { - if (tEncodeCStr(encoder, pDesc->name) < 0) return -1; - if (tEncodeI8(encoder, pDesc->level) < 0) return -1; - if (tEncodeI64(encoder, pDesc->size.total) < 0) return -1; - if (tEncodeI64(encoder, pDesc->size.used) < 0) return -1; - if (tEncodeI64(encoder, pDesc->size.avail) < 0) return -1; - return 0; -} - -static int32_t tDecodeSMonDiskDesc(SDecoder *decoder, SMonDiskDesc *pDesc) { - if (tDecodeCStrTo(decoder, pDesc->name) < 0) return -1; - if (tDecodeI8(decoder, &pDesc->level) < 0) return -1; - if (tDecodeI64(decoder, &pDesc->size.total) < 0) return -1; - if (tDecodeI64(decoder, &pDesc->size.used) < 0) return -1; - if (tDecodeI64(decoder, &pDesc->size.avail) < 0) return -1; - return 0; -} - -int32_t tEncodeSMonDiskInfo(SEncoder *encoder, const SMonDiskInfo *pInfo) { - if (tEncodeI32(encoder, taosArrayGetSize(pInfo->datadirs)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->datadirs); ++i) { - SMonDiskDesc *pDesc = taosArrayGet(pInfo->datadirs, i); - if (tEncodeSMonDiskDesc(encoder, pDesc) < 0) return -1; - } - return 0; -} - -static int32_t tDecodeSMonDiskInfo(SDecoder *decoder, SMonDiskInfo *pInfo) { - int32_t arraySize = 0; - if (tDecodeI32(decoder, &arraySize) < 0) return -1; - - pInfo->datadirs = taosArrayInit(arraySize, sizeof(SMonDiskDesc)); - if (pInfo->datadirs == NULL) return -1; - - for (int32_t i = 0; i < arraySize; ++i) { - SMonDiskDesc desc = {0}; - if (tDecodeSMonDiskDesc(decoder, &desc) < 0) return -1; - taosArrayPush(pInfo->datadirs, &desc); - } - - return 0; -} - -int32_t tEncodeSVnodesStat(SEncoder *encoder, const SVnodesStat *pStat) { - if (tEncodeI32(encoder, pStat->openVnodes) < 0) return -1; - if (tEncodeI32(encoder, pStat->totalVnodes) < 0) return -1; - if (tEncodeI32(encoder, pStat->masterNum) < 0) return -1; - if (tEncodeI64(encoder, pStat->numOfSelectReqs) < 0) return -1; - if (tEncodeI64(encoder, pStat->numOfInsertReqs) < 0) return -1; - if (tEncodeI64(encoder, pStat->numOfInsertSuccessReqs) < 0) return -1; - if (tEncodeI64(encoder, pStat->numOfBatchInsertReqs) < 0) return -1; - if (tEncodeI64(encoder, pStat->numOfBatchInsertSuccessReqs) < 0) return -1; - if (tEncodeI64(encoder, pStat->errors) < 0) return -1; - return 0; -} - -static int32_t tDecodeSVnodesStat(SDecoder *decoder, SVnodesStat *pStat) { - if (tDecodeI32(decoder, &pStat->openVnodes) < 0) return -1; - if (tDecodeI32(decoder, &pStat->totalVnodes) < 0) return -1; - if (tDecodeI32(decoder, &pStat->masterNum) < 0) return -1; - if (tDecodeI64(decoder, &pStat->numOfSelectReqs) < 0) return -1; - if (tDecodeI64(decoder, &pStat->numOfInsertReqs) < 0) return -1; - if (tDecodeI64(decoder, &pStat->numOfInsertSuccessReqs) < 0) return -1; - if (tDecodeI64(decoder, &pStat->numOfBatchInsertReqs) < 0) return -1; - if (tDecodeI64(decoder, &pStat->numOfBatchInsertSuccessReqs) < 0) return -1; - if (tDecodeI64(decoder, &pStat->errors) < 0) return -1; - return 0; -} - -int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeSMonDiskInfo(&encoder, &pInfo->tfs) < 0) return -1; - if (tEncodeSVnodesStat(&encoder, &pInfo->vstat) < 0) return -1; - if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeSMonDiskInfo(&decoder, &pInfo->tfs) < 0) return -1; - if (tDecodeSVnodesStat(&decoder, &pInfo->vstat) < 0) return -1; - if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - void tFreeSMonVmInfo(SMonVmInfo *pInfo) { taosArrayDestroy(pInfo->log.logs); taosArrayDestroy(pInfo->tfs.datadirs); @@ -404,239 +38,17 @@ void tFreeSMonVmInfo(SMonVmInfo *pInfo) { pInfo->tfs.datadirs = NULL; } -int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - void tFreeSMonQmInfo(SMonQmInfo *pInfo) { taosArrayDestroy(pInfo->log.logs); pInfo->log.logs = NULL; } -int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - void tFreeSMonSmInfo(SMonSmInfo *pInfo) { taosArrayDestroy(pInfo->log.logs); pInfo->log.logs = NULL; } -int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - void tFreeSMonBmInfo(SMonBmInfo *pInfo) { taosArrayDestroy(pInfo->log.logs); pInfo->log.logs = NULL; } - -int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeI32(&encoder, taosArrayGetSize(pInfo->pVloads)) < 0) return -1; - for (int32_t i = 0; i < taosArrayGetSize(pInfo->pVloads); ++i) { - SVnodeLoad *pLoad = taosArrayGet(pInfo->pVloads, i); - if (tEncodeI32(&encoder, pLoad->vgId) < 0) return -1; - if (tEncodeI32(&encoder, pLoad->syncState) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->cacheUsage) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfTables) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfTimeSeries) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->totalStorage) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->compStorage) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->pointsWritten) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfSelectReqs) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfInsertReqs) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfInsertSuccessReqs) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfBatchInsertReqs) < 0) return -1; - if (tEncodeI64(&encoder, pLoad->numOfBatchInsertSuccessReqs) < 0) return -1; - } - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - - int32_t arraySize = 0; - if (tDecodeI32(&decoder, &arraySize) < 0) return -1; - - pInfo->pVloads = taosArrayInit(arraySize, sizeof(SVnodeLoad)); - if (pInfo->pVloads == NULL) return -1; - - for (int32_t i = 0; i < arraySize; ++i) { - SVnodeLoad load = {0}; - if (tDecodeI32(&decoder, &load.vgId) < 0) return -1; - if (tDecodeI32(&decoder, &load.syncState) < 0) return -1; - if (tDecodeI64(&decoder, &load.cacheUsage) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfTables) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfTimeSeries) < 0) return -1; - if (tDecodeI64(&decoder, &load.totalStorage) < 0) return -1; - if (tDecodeI64(&decoder, &load.compStorage) < 0) return -1; - if (tDecodeI64(&decoder, &load.pointsWritten) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfSelectReqs) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfInsertReqs) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfInsertSuccessReqs) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfBatchInsertReqs) < 0) return -1; - if (tDecodeI64(&decoder, &load.numOfBatchInsertSuccessReqs) < 0) return -1; - taosArrayPush(pInfo->pVloads, &load); - } - - tEndDecode(&decoder); - tDecoderClear(&decoder); - return 0; -} - -void tFreeSMonVloadInfo(SMonVloadInfo *pInfo) { - taosArrayDestroy(pInfo->pVloads); - pInfo->pVloads = NULL; -} - -int32_t tSerializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeI8(&encoder, pInfo->isMnode) < 0) return -1; - if (tEncodeI32(&encoder, pInfo->load.syncState) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSMonMloadInfo(void *buf, int32_t bufLen, SMonMloadInfo *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeI8(&decoder, &pInfo->isMnode) < 0) return -1; - if (tDecodeI32(&decoder, &pInfo->load.syncState) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} - -int32_t tSerializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) { - SEncoder encoder = {0}; - tEncoderInit(&encoder, buf, bufLen); - - if (tStartEncode(&encoder) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedQuery) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedCQuery) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedFetch) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedDrop) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedHb) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfProcessedDelete) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->cacheDataSize) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfQueryInQueue) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->numOfFetchInQueue) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->timeInQueryQueue) < 0) return -1; - if (tEncodeI64(&encoder, pInfo->timeInFetchQueue) < 0) return -1; - tEndEncode(&encoder); - - int32_t tlen = encoder.pos; - tEncoderClear(&encoder); - return tlen; -} - -int32_t tDeserializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) { - SDecoder decoder = {0}; - tDecoderInit(&decoder, buf, bufLen); - - if (tStartDecode(&decoder) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedQuery) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedCQuery) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedFetch) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedDrop) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedHb) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfProcessedDelete) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->cacheDataSize) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfQueryInQueue) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->numOfFetchInQueue) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->timeInQueryQueue) < 0) return -1; - if (tDecodeI64(&decoder, &pInfo->timeInFetchQueue) < 0) return -1; - tEndDecode(&decoder); - - tDecoderClear(&decoder); - return 0; -} diff --git a/source/libs/nodes/src/nodesMsgFuncs.c b/source/libs/nodes/src/nodesMsgFuncs.c index 9e89955ae5394db0923ab8eb82d99bde755a8e53..5b10e11dedb7e1b32b32ce2b96cbbf4aca1de839 100644 --- a/source/libs/nodes/src/nodesMsgFuncs.c +++ b/source/libs/nodes/src/nodesMsgFuncs.c @@ -84,13 +84,12 @@ static void endTlvEncode(STlvEncoder* pEncoder, char** pMsg, int32_t* pLen) { *pMsg = pEncoder->pBuf; pEncoder->pBuf = NULL; *pLen = pEncoder->offset; - // nodesWarn("encode tlv count = %d, tl size = %d", pEncoder->tlvCount, sizeof(STlv) * pEncoder->tlvCount); } static int32_t tlvEncodeImpl(STlvEncoder* pEncoder, int16_t type, const void* pValue, int32_t len) { int32_t tlvLen = sizeof(STlv) + len; if (pEncoder->offset + tlvLen > pEncoder->allocSize) { - pEncoder->allocSize = TMAX(pEncoder->allocSize * 2, pEncoder->allocSize + pEncoder->offset + tlvLen); + pEncoder->allocSize = TMAX(pEncoder->allocSize * 2, pEncoder->allocSize + tlvLen); void* pNewBuf = taosMemoryRealloc(pEncoder->pBuf, pEncoder->allocSize); if (NULL == pNewBuf) { return TSDB_CODE_OUT_OF_MEMORY; @@ -241,6 +240,15 @@ static int32_t tlvEncodeObj(STlvEncoder* pEncoder, int16_t type, FToMsg func, co return TSDB_CODE_SUCCESS; } + if (pEncoder->offset + sizeof(STlv) > pEncoder->allocSize) { + pEncoder->allocSize = TMAX(pEncoder->allocSize * 2, pEncoder->allocSize + sizeof(STlv)); + void* pNewBuf = taosMemoryRealloc(pEncoder->pBuf, pEncoder->allocSize); + if (NULL == pNewBuf) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pEncoder->pBuf = pNewBuf; + } + int32_t start = pEncoder->offset; pEncoder->offset += sizeof(STlv); int32_t code = func(pObj, pEncoder); @@ -307,7 +315,7 @@ static int32_t tlvDecodeImpl(STlv* pTlv, void* pValue, int32_t len) { } static int32_t tlvDecodeValueImpl(STlvDecoder* pDecoder, void* pValue, int32_t len) { - if (pDecoder->offset + len > pDecoder->bufSize) { + if (len > pDecoder->bufSize - pDecoder->offset) { return TSDB_CODE_FAILED; } memcpy(pValue, pDecoder->pBuf + pDecoder->offset, len); @@ -911,6 +919,10 @@ static int32_t msgToDatum(STlv* pTlv, void* pObj) { case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: { + if (pTlv->len > pNode->node.resType.bytes + VARSTR_HEADER_SIZE) { + code = TSDB_CODE_FAILED; + break; + } pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pNode->datum.p) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -1957,7 +1969,7 @@ static int32_t msgToPhysiScanNode(STlvDecoder* pDecoder, void* pObj) { return code; } -enum { PHY_LAST_ROW_SCAN_CODE_SCAN = 1, PHY_LAST_ROW_SCAN_CODE_GROUP_TAGS, PHY_LAST_ROW_SCAN_CODE_GROUP_SORT }; +enum { PHY_LAST_ROW_SCAN_CODE_SCAN = 1, PHY_LAST_ROW_SCAN_CODE_GROUP_TAGS, PHY_LAST_ROW_SCAN_CODE_GROUP_SORT, PHY_LAST_ROW_SCAN_CODE_IGNULL }; static int32_t physiLastRowScanNodeToMsg(const void* pObj, STlvEncoder* pEncoder) { const SLastRowScanPhysiNode* pNode = (const SLastRowScanPhysiNode*)pObj; @@ -1969,6 +1981,9 @@ static int32_t physiLastRowScanNodeToMsg(const void* pObj, STlvEncoder* pEncoder if (TSDB_CODE_SUCCESS == code) { code = tlvEncodeBool(pEncoder, PHY_LAST_ROW_SCAN_CODE_GROUP_SORT, pNode->groupSort); } + if (TSDB_CODE_SUCCESS == code) { + code = tlvEncodeBool(pEncoder, PHY_LAST_ROW_SCAN_CODE_IGNULL, pNode->ignoreNull); + } return code; } @@ -1989,6 +2004,9 @@ static int32_t msgToPhysiLastRowScanNode(STlvDecoder* pDecoder, void* pObj) { case PHY_LAST_ROW_SCAN_CODE_GROUP_SORT: code = tlvDecodeBool(pTlv, &pNode->groupSort); break; + case PHY_LAST_ROW_SCAN_CODE_IGNULL: + code = tlvDecodeBool(pTlv, &pNode->ignoreNull); + break; default: break; } diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index bc0c4d42bbccc66e8a00179d523f86159f03e33e..aec4d0148a58dcc3c3b95e7301cc2a23d234e666 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -203,6 +203,7 @@ int32_t nodesReleaseAllocator(int64_t allocatorId) { return taosReleaseRef(g_allocatorReqRefPool, allocatorId); } + int64_t nodesMakeAllocatorWeakRef(int64_t allocatorId) { if (allocatorId <= 0) { return 0; @@ -1826,7 +1827,7 @@ static EDealRes collectFuncs(SNode* pNode, void* pContext) { if (QUERY_NODE_FUNCTION == nodeType(pNode) && pCxt->classifier(((SFunctionNode*)pNode)->funcId) && !(((SExprNode*)pNode)->orderAlias)) { SExprNode* pExpr = (SExprNode*)pNode; - if (NULL == taosHashGet(pCxt->pFuncsSet, &pExpr, POINTER_BYTES)) { + if (NULL == taosHashGet(pCxt->pFuncsSet, &pExpr, sizeof(SExprNode*))) { pCxt->errCode = nodesListStrictAppend(pCxt->pFuncs, nodesCloneNode(pNode)); taosHashPut(pCxt->pFuncsSet, &pExpr, POINTER_BYTES, &pExpr, POINTER_BYTES); } diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 3eefd7fb44bd766173e05610403500e4f0df9204..09dfa54df6ccf81b5e86e08ca03a88ea9c31b873 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -224,8 +224,8 @@ alter_db_option(A) ::= WAL_FSYNC_PERIOD NK_INTEGER(B). alter_db_option(A) ::= KEEP integer_list(B). { A.type = DB_OPTION_KEEP; A.pList = B; } alter_db_option(A) ::= KEEP variable_list(B). { A.type = DB_OPTION_KEEP; A.pList = B; } alter_db_option(A) ::= PAGES NK_INTEGER(B). { A.type = DB_OPTION_PAGES; A.val = B; } -//alter_db_option(A) ::= REPLICA NK_INTEGER(B). { A.type = DB_OPTION_REPLICA; A.val = B; } -//alter_db_option(A) ::= STRICT NK_STRING(B). { A.type = DB_OPTION_STRICT; A.val = B; } +alter_db_option(A) ::= REPLICA NK_INTEGER(B). { A.type = DB_OPTION_REPLICA; A.val = B; } +alter_db_option(A) ::= STRICT NK_STRING(B). { A.type = DB_OPTION_STRICT; A.val = B; } alter_db_option(A) ::= WAL_LEVEL NK_INTEGER(B). { A.type = DB_OPTION_WAL; A.val = B; } alter_db_option(A) ::= STT_TRIGGER NK_INTEGER(B). { A.type = DB_OPTION_STT_TRIGGER; A.val = B; } diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index 64aa017a68f7cfb04d0b69c5b526ebeea179b251..95db6b93c901fabd53368d58d2f1b6f0936952c9 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -455,8 +455,13 @@ static int32_t collectMetaKeyFromShowLicence(SCollectMetaKeyCxt* pCxt, SShowStmt } static int32_t collectMetaKeyFromShowVgroups(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) { - return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS, - pCxt->pMetaCache); + int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS, + pCxt->pMetaCache); + if (TSDB_CODE_SUCCESS == code) { + // just to verify whether the database exists + code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache); + } + return code; } static int32_t collectMetaKeyFromShowTopics(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) { diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index f59a6c7f9bdacc18f0acea1a96ce57705340a1ec..65cc44b1e9f403c8abe0cae4f9106999447d8b97 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -1365,8 +1365,12 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, TdFilePtr fp, STableDataB strtolower(pLine, pLine); char* pRawSql = pCxt->pSql; pCxt->pSql = pLine; - bool gotRow = false; - CHECK_CODE(parseOneRow(pCxt, pDataBlock, tinfo.precision, &gotRow, tmpTokenBuf)); + bool gotRow = false; + int32_t code = parseOneRow(pCxt, pDataBlock, tinfo.precision, &gotRow, tmpTokenBuf); + if (TSDB_CODE_SUCCESS != code) { + pCxt->pSql = pRawSql; + return code; + } if (gotRow) { pDataBlock->size += extendedRowSize; // len; (*numOfRows)++; diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index 09e40cad60221246261b4a9ce8913ad54ae058db..954c1b332a782fd212902753b2c2505ad29b50cf 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -222,6 +222,21 @@ int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq) return code; } +static void destroyDataBlock(STableDataBlocks* pDataBlock) { + if (pDataBlock == NULL) { + return; + } + + taosMemoryFreeClear(pDataBlock->pData); + // if (!pDataBlock->cloned) { + // free the refcount for metermeta + taosMemoryFreeClear(pDataBlock->pTableMeta); + + destroyBoundColumnInfo(&pDataBlock->boundColumnInfo); + // } + taosMemoryFreeClear(pDataBlock); +} + int32_t getDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, int32_t size, int32_t startOffset, int32_t rowSize, STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq) { @@ -240,11 +255,13 @@ int32_t getDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, int32 if (NULL != pCreateTbReq && NULL != pCreateTbReq->ctb.pTag) { ret = buildCreateTbMsg(*dataBlocks, pCreateTbReq); if (ret != TSDB_CODE_SUCCESS) { + destroyDataBlock(*dataBlocks); return ret; } } - taosHashPut(pHashList, id, idLen, dataBlocks, POINTER_BYTES); + // converting to 'const char*' is to handle coverity scan errors + taosHashPut(pHashList, (const char*)id, idLen, (const char*)dataBlocks, POINTER_BYTES); if (pBlockList) { taosArrayPush(pBlockList, dataBlocks); } @@ -266,21 +283,6 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) { return result; } -static void destroyDataBlock(STableDataBlocks* pDataBlock) { - if (pDataBlock == NULL) { - return; - } - - taosMemoryFreeClear(pDataBlock->pData); - // if (!pDataBlock->cloned) { - // free the refcount for metermeta - taosMemoryFreeClear(pDataBlock->pTableMeta); - - destroyBoundColumnInfo(&pDataBlock->boundColumnInfo); - // } - taosMemoryFreeClear(pDataBlock); -} - void destroyBlockArrayList(SArray* pDataBlockList) { if (pDataBlockList == NULL) { return; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 5a05440c73b92accf42e8ecce8ee6d6c194080f3..d942af9673aa201c2a8dd4fc92fa1f994b8c0ba8 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -417,11 +417,11 @@ static int32_t getDBVgInfoImpl(STranslateContext* pCxt, const SName* pName, SArr .requestId = pParCxt->requestId, .requestObjRefId = pParCxt->requestRid, .mgmtEps = pParCxt->mgmtEpSet}; - code = catalogGetDBVgInfo(pParCxt->pCatalog, &conn, fullDbName, pVgInfo); + code = catalogGetDBVgList(pParCxt->pCatalog, &conn, fullDbName, pVgInfo); } } if (TSDB_CODE_SUCCESS != code) { - parserError("0x%" PRIx64 " catalogGetDBVgInfo error, code:%s, dbFName:%s", pCxt->pParseCxt->requestId, + parserError("0x%" PRIx64 " catalogGetDBVgList error, code:%s, dbFName:%s", pCxt->pParseCxt->requestId, tstrerror(code), fullDbName); } return code; @@ -6212,6 +6212,20 @@ static int32_t rewriteShow(STranslateContext* pCxt, SQuery* pQuery) { return code; } +static int32_t checkShowVgroups(STranslateContext* pCxt, SShowStmt* pShow) { + // just to verify whether the database exists + SDbCfgInfo dbCfg = {0}; + return getDBCfg(pCxt, ((SValueNode*)pShow->pDbName)->literal, &dbCfg); +} + +static int32_t rewriteShowVgroups(STranslateContext* pCxt, SQuery* pQuery) { + int32_t code = checkShowVgroups(pCxt, (SShowStmt*)pQuery->pRoot); + if (TSDB_CODE_SUCCESS == code) { + code = rewriteShow(pCxt, pQuery); + } + return code; +} + static SNode* createTagsFunction() { SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); if (NULL == pFunc) { @@ -7358,7 +7372,6 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_STABLES_STMT: case QUERY_NODE_SHOW_USERS_STMT: case QUERY_NODE_SHOW_DNODES_STMT: - case QUERY_NODE_SHOW_VGROUPS_STMT: case QUERY_NODE_SHOW_MNODES_STMT: case QUERY_NODE_SHOW_MODULES_STMT: case QUERY_NODE_SHOW_QNODES_STMT: @@ -7378,6 +7391,9 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_TAGS_STMT: code = rewriteShow(pCxt, pQuery); break; + case QUERY_NODE_SHOW_VGROUPS_STMT: + code = rewriteShowVgroups(pCxt, pQuery); + break; case QUERY_NODE_SHOW_TABLE_TAGS_STMT: code = rewriteShowStableTags(pCxt, pQuery); break; diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 95eb094edb3e3f469c8be799e2e2a678bb24055b..d98d513d5d8891baed2a6bd30590fd2e6964aacb 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -248,8 +248,12 @@ int32_t getNumOfTags(const STableMeta* pTableMeta) { return getTableInfo(pTableM STableComInfo getTableInfo(const STableMeta* pTableMeta) { return pTableMeta->tableInfo; } STableMeta* tableMetaDup(const STableMeta* pTableMeta) { - size_t size = TABLE_META_SIZE(pTableMeta); + int32_t numOfFields = TABLE_TOTAL_COL_NUM(pTableMeta); + if (numOfFields > TSDB_MAX_COLUMNS || numOfFields < TSDB_MIN_COLUMNS) { + return NULL; + } + size_t size = sizeof(STableMeta) + numOfFields * sizeof(SSchema); STableMeta* p = taosMemoryMalloc(size); memcpy(p, pTableMeta, size); return p; diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 6daf06731f8204dcd478621c647567e69c0e32da..deb38a77e378600f6f79bbe742afede993de6f6d 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -139,17 +139,17 @@ typedef union { #define ParseCTX_FETCH #define ParseCTX_STORE #define YYFALLBACK 1 -#define YYNSTATE 694 -#define YYNRULE 522 +#define YYNSTATE 696 +#define YYNRULE 524 #define YYNTOKEN 317 -#define YY_MAX_SHIFT 693 -#define YY_MIN_SHIFTREDUCE 1025 -#define YY_MAX_SHIFTREDUCE 1546 -#define YY_ERROR_ACTION 1547 -#define YY_ACCEPT_ACTION 1548 -#define YY_NO_ACTION 1549 -#define YY_MIN_REDUCE 1550 -#define YY_MAX_REDUCE 2071 +#define YY_MAX_SHIFT 695 +#define YY_MIN_SHIFTREDUCE 1029 +#define YY_MAX_SHIFTREDUCE 1552 +#define YY_ERROR_ACTION 1553 +#define YY_ACCEPT_ACTION 1554 +#define YY_NO_ACTION 1555 +#define YY_MIN_REDUCE 1556 +#define YY_MAX_REDUCE 2079 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -218,288 +218,288 @@ typedef union { *********** Begin parsing tables **********************************************/ #define YY_ACTTAB_COUNT (2819) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 1873, 34, 267, 1873, 156, 1058, 1562, 1887, 62, 532, - /* 10 */ 1690, 1869, 44, 42, 1869, 446, 334, 447, 1585, 1799, - /* 20 */ 349, 1869, 1327, 43, 41, 40, 39, 38, 586, 157, - /* 30 */ 167, 1548, 1352, 1407, 1654, 1325, 1905, 1865, 1871, 337, - /* 40 */ 1865, 1871, 343, 1738, 587, 1062, 1063, 1865, 1871, 1855, - /* 50 */ 593, 599, 30, 593, 445, 1573, 1402, 449, 37, 36, - /* 60 */ 593, 17, 43, 41, 40, 39, 38, 1887, 1333, 44, - /* 70 */ 42, 1477, 1885, 1572, 503, 586, 1921, 349, 571, 1327, - /* 80 */ 97, 1886, 1888, 603, 1890, 1891, 598, 77, 593, 513, - /* 90 */ 1407, 364, 1325, 168, 1, 1974, 1905, 1855, 58, 342, - /* 100 */ 1970, 125, 46, 218, 600, 583, 58, 2042, 528, 1855, - /* 110 */ 1694, 599, 173, 1402, 463, 1855, 690, 506, 17, 1571, - /* 120 */ 2000, 500, 570, 171, 586, 1333, 217, 2043, 572, 2046, - /* 130 */ 1409, 1410, 601, 2047, 132, 583, 1921, 2042, 394, 1570, - /* 140 */ 98, 348, 1888, 603, 1890, 1891, 598, 454, 593, 447, - /* 150 */ 1585, 1, 2048, 171, 1075, 1974, 1074, 2043, 572, 314, - /* 160 */ 1970, 1855, 2042, 64, 132, 1474, 63, 58, 1481, 482, - /* 170 */ 2042, 130, 335, 690, 1352, 1328, 310, 1326, 2046, 219, - /* 180 */ 154, 1855, 2043, 2045, 1076, 570, 171, 1409, 1410, 1701, - /* 190 */ 2043, 572, 585, 169, 1982, 1983, 1353, 1987, 46, 1331, - /* 200 */ 1332, 121, 1382, 1383, 1385, 1386, 1387, 1388, 1389, 1390, - /* 210 */ 1391, 1392, 595, 591, 1400, 1401, 1403, 1404, 1405, 1406, - /* 220 */ 1408, 1411, 3, 264, 1982, 582, 1676, 581, 1745, 1746, - /* 230 */ 2042, 1417, 1328, 383, 1326, 79, 312, 1352, 388, 535, - /* 240 */ 174, 1503, 494, 493, 174, 570, 171, 387, 174, 386, - /* 250 */ 2043, 572, 174, 385, 381, 528, 1331, 1332, 58, 1382, - /* 260 */ 1383, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 595, - /* 270 */ 591, 1400, 1401, 1403, 1404, 1405, 1406, 1408, 1411, 3, - /* 280 */ 44, 42, 693, 181, 2042, 233, 234, 628, 349, 77, - /* 290 */ 1327, 558, 1501, 1502, 1504, 1505, 274, 545, 1887, 2048, - /* 300 */ 171, 1407, 545, 1325, 2043, 572, 1222, 1223, 1569, 52, - /* 310 */ 165, 1874, 1695, 174, 120, 683, 679, 675, 671, 272, - /* 320 */ 74, 484, 1869, 73, 1402, 220, 1699, 1905, 1729, 17, - /* 330 */ 354, 1699, 634, 1744, 1746, 600, 1333, 44, 42, 1075, - /* 340 */ 1855, 1074, 599, 312, 143, 349, 535, 1327, 1865, 1871, - /* 350 */ 1855, 145, 144, 631, 630, 629, 95, 1384, 1407, 240, - /* 360 */ 1325, 593, 1, 601, 451, 561, 545, 1921, 634, 1076, - /* 370 */ 1350, 294, 348, 1888, 603, 1890, 1891, 598, 120, 593, - /* 380 */ 47, 1402, 1551, 574, 690, 489, 17, 145, 144, 631, - /* 390 */ 630, 629, 542, 1333, 1568, 1699, 51, 453, 1409, 1410, - /* 400 */ 449, 2042, 1473, 110, 174, 1140, 109, 108, 107, 106, - /* 410 */ 105, 104, 103, 102, 101, 1352, 570, 171, 1989, 1, - /* 420 */ 1384, 2043, 572, 110, 229, 227, 109, 108, 107, 106, - /* 430 */ 105, 104, 103, 102, 101, 545, 1855, 545, 1142, 431, - /* 440 */ 545, 690, 1299, 1328, 222, 1326, 1986, 176, 1353, 392, - /* 450 */ 567, 562, 393, 37, 36, 1409, 1410, 43, 41, 40, - /* 460 */ 39, 38, 1567, 58, 1699, 81, 1699, 1331, 1332, 1699, - /* 470 */ 1382, 1383, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, - /* 480 */ 595, 591, 1400, 1401, 1403, 1404, 1405, 1406, 1408, 1411, - /* 490 */ 3, 11, 11, 9, 7, 185, 184, 40, 39, 38, - /* 500 */ 1328, 547, 1326, 1946, 1855, 325, 1180, 625, 624, 623, - /* 510 */ 1184, 622, 1186, 1187, 621, 1189, 618, 636, 1195, 615, - /* 520 */ 1197, 1198, 612, 609, 1331, 1332, 174, 1382, 1383, 1385, - /* 530 */ 1386, 1387, 1388, 1389, 1390, 1391, 1392, 595, 591, 1400, - /* 540 */ 1401, 1403, 1404, 1405, 1406, 1408, 1411, 3, 44, 42, - /* 550 */ 1751, 545, 1905, 498, 497, 496, 349, 336, 1327, 1550, - /* 560 */ 565, 126, 492, 403, 545, 326, 1749, 324, 323, 1407, - /* 570 */ 486, 1325, 491, 495, 488, 1352, 417, 1566, 490, 1565, - /* 580 */ 1699, 1887, 512, 119, 118, 117, 116, 115, 114, 113, - /* 590 */ 112, 111, 1402, 1699, 352, 510, 487, 508, 1384, 564, - /* 600 */ 1887, 1751, 154, 1564, 1333, 44, 42, 1412, 353, 174, - /* 610 */ 1905, 1701, 1543, 349, 2047, 1327, 355, 1749, 600, 1855, - /* 620 */ 1354, 1855, 1677, 1855, 154, 599, 1407, 1751, 1325, 1905, - /* 630 */ 8, 1354, 1802, 1701, 319, 2047, 11, 600, 232, 545, - /* 640 */ 13, 12, 1855, 1749, 599, 1855, 1885, 1561, 1675, 1402, - /* 650 */ 1921, 418, 690, 531, 158, 1886, 1888, 603, 1890, 1891, - /* 660 */ 598, 1333, 593, 1842, 2042, 1885, 1409, 1410, 1699, 1921, - /* 670 */ 528, 545, 571, 97, 1886, 1888, 603, 1890, 1891, 598, - /* 680 */ 2046, 593, 463, 461, 2043, 2044, 2062, 8, 1974, 1855, - /* 690 */ 94, 1438, 342, 1970, 1470, 550, 2011, 1305, 1306, 2042, - /* 700 */ 1699, 2042, 2008, 566, 127, 87, 1536, 1542, 636, 690, - /* 710 */ 371, 1328, 1691, 1326, 2048, 171, 570, 171, 532, 2043, - /* 720 */ 572, 2043, 572, 1409, 1410, 37, 36, 1692, 1800, 43, - /* 730 */ 41, 40, 39, 38, 1450, 1331, 1332, 1355, 1382, 1383, - /* 740 */ 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 595, 591, - /* 750 */ 1400, 1401, 1403, 1404, 1405, 1406, 1408, 1411, 3, 37, - /* 760 */ 36, 31, 266, 43, 41, 40, 39, 38, 1328, 1615, - /* 770 */ 1326, 1443, 1351, 266, 37, 36, 174, 32, 43, 41, - /* 780 */ 40, 39, 38, 37, 36, 1560, 1559, 43, 41, 40, - /* 790 */ 39, 38, 1331, 1332, 1558, 1382, 1383, 1385, 1386, 1387, - /* 800 */ 1388, 1389, 1390, 1391, 1392, 595, 591, 1400, 1401, 1403, - /* 810 */ 1404, 1405, 1406, 1408, 1411, 3, 44, 42, 549, 583, - /* 820 */ 1946, 661, 659, 1798, 349, 307, 1327, 1855, 1855, 1797, - /* 830 */ 395, 307, 498, 497, 496, 1333, 1855, 1407, 545, 1325, - /* 840 */ 126, 492, 545, 396, 1792, 1792, 1513, 1355, 132, 1887, - /* 850 */ 462, 491, 495, 1557, 1696, 179, 180, 490, 37, 36, - /* 860 */ 1402, 1493, 43, 41, 40, 39, 38, 1699, 1887, 1792, - /* 870 */ 545, 1699, 1333, 44, 42, 545, 1688, 545, 1905, 243, - /* 880 */ 183, 349, 137, 1327, 1751, 130, 600, 524, 1989, 529, - /* 890 */ 545, 1855, 154, 599, 1407, 1855, 1325, 1905, 8, 1699, - /* 900 */ 1750, 1702, 237, 545, 1699, 600, 1699, 170, 1982, 1983, - /* 910 */ 1855, 1987, 599, 1336, 1885, 541, 1985, 1402, 1921, 1699, - /* 920 */ 690, 1887, 159, 1886, 1888, 603, 1890, 1891, 598, 1333, - /* 930 */ 593, 488, 1699, 1885, 1409, 1410, 1556, 1921, 1555, 402, - /* 940 */ 545, 97, 1886, 1888, 603, 1890, 1891, 598, 128, 593, - /* 950 */ 1905, 1945, 356, 487, 2062, 1, 1974, 1989, 600, 545, - /* 960 */ 342, 1970, 578, 1855, 545, 599, 649, 648, 1669, 1699, - /* 970 */ 2036, 543, 545, 575, 573, 2063, 544, 690, 1855, 1328, - /* 980 */ 1855, 1326, 1674, 1602, 268, 1984, 1885, 72, 1699, 242, - /* 990 */ 1921, 1409, 1410, 1699, 159, 1886, 1888, 603, 1890, 1891, - /* 1000 */ 598, 1699, 593, 1331, 1332, 499, 1382, 1383, 1385, 1386, - /* 1010 */ 1387, 1388, 1389, 1390, 1391, 1392, 595, 591, 1400, 1401, - /* 1020 */ 1403, 1404, 1405, 1406, 1408, 1411, 3, 37, 36, 205, - /* 1030 */ 1684, 43, 41, 40, 39, 38, 1328, 632, 1326, 362, - /* 1040 */ 1742, 633, 45, 161, 1742, 1554, 1335, 2064, 480, 476, - /* 1050 */ 472, 468, 204, 1553, 279, 1339, 528, 1729, 1062, 1063, - /* 1060 */ 1331, 1332, 1612, 1382, 1383, 1385, 1386, 1387, 1388, 1389, - /* 1070 */ 1390, 1391, 1392, 595, 591, 1400, 1401, 1403, 1404, 1405, - /* 1080 */ 1406, 1408, 1411, 3, 309, 2042, 1350, 1855, 634, 78, - /* 1090 */ 1994, 1470, 202, 425, 1276, 1855, 436, 48, 4, 210, - /* 1100 */ 2048, 171, 208, 50, 527, 2043, 572, 145, 144, 631, - /* 1110 */ 630, 629, 1686, 410, 231, 437, 212, 412, 214, 211, - /* 1120 */ 216, 213, 138, 215, 226, 667, 666, 665, 664, 359, - /* 1130 */ 1682, 663, 662, 133, 657, 656, 655, 654, 653, 652, - /* 1140 */ 651, 650, 147, 646, 645, 644, 358, 357, 641, 640, - /* 1150 */ 639, 638, 637, 155, 201, 195, 1597, 200, 285, 322, - /* 1160 */ 1595, 459, 1545, 1546, 80, 642, 235, 142, 13, 12, - /* 1170 */ 590, 398, 283, 66, 538, 143, 65, 193, 501, 60, - /* 1180 */ 579, 153, 504, 247, 1327, 1876, 60, 1122, 1338, 576, - /* 1190 */ 223, 45, 189, 442, 440, 1887, 594, 1325, 2047, 435, - /* 1200 */ 45, 607, 430, 429, 428, 427, 424, 423, 422, 421, - /* 1210 */ 420, 416, 415, 414, 413, 407, 406, 405, 404, 239, - /* 1220 */ 400, 399, 321, 142, 1905, 523, 627, 1173, 143, 58, - /* 1230 */ 1333, 1500, 600, 1878, 1563, 250, 1655, 1855, 1444, 599, - /* 1240 */ 2014, 37, 36, 1393, 122, 43, 41, 40, 39, 38, - /* 1250 */ 37, 36, 278, 1201, 43, 41, 40, 39, 38, 1102, - /* 1260 */ 1885, 142, 643, 261, 1921, 559, 481, 96, 97, 1886, - /* 1270 */ 1888, 603, 1890, 1891, 598, 1205, 593, 1887, 690, 129, - /* 1280 */ 1212, 141, 1945, 1974, 1120, 26, 1591, 342, 1970, 255, - /* 1290 */ 1536, 1906, 1103, 360, 315, 1586, 1210, 1739, 2004, 93, - /* 1300 */ 584, 260, 71, 70, 391, 263, 1905, 178, 1428, 90, - /* 1310 */ 2, 332, 5, 146, 600, 365, 370, 320, 1292, 1855, - /* 1320 */ 182, 599, 275, 397, 308, 401, 1350, 379, 1887, 377, - /* 1330 */ 373, 369, 366, 363, 685, 419, 1436, 1328, 1794, 1326, - /* 1340 */ 426, 433, 1885, 432, 434, 583, 1921, 438, 1356, 439, - /* 1350 */ 301, 1886, 1888, 603, 1890, 1891, 598, 1905, 593, 186, - /* 1360 */ 1358, 1331, 1332, 441, 361, 587, 443, 444, 452, 455, - /* 1370 */ 1855, 192, 599, 456, 132, 174, 194, 516, 1357, 457, - /* 1380 */ 1359, 528, 458, 197, 199, 75, 76, 464, 460, 203, - /* 1390 */ 1437, 483, 485, 1885, 528, 100, 1689, 1921, 207, 1685, - /* 1400 */ 515, 97, 1886, 1888, 603, 1890, 1891, 598, 311, 593, - /* 1410 */ 2042, 130, 209, 148, 168, 221, 1974, 517, 1833, 276, - /* 1420 */ 342, 1970, 149, 2042, 1687, 2048, 171, 1683, 518, 150, - /* 1430 */ 2043, 572, 151, 172, 1982, 1983, 522, 1987, 2048, 171, - /* 1440 */ 519, 2001, 224, 2043, 572, 525, 1887, 530, 228, 557, - /* 1450 */ 331, 533, 1832, 139, 1804, 536, 140, 333, 539, 84, - /* 1460 */ 33, 346, 1431, 1432, 1433, 1434, 1435, 1439, 1440, 1441, - /* 1470 */ 1442, 540, 277, 1700, 86, 1905, 1355, 553, 560, 2005, - /* 1480 */ 2015, 6, 245, 600, 555, 556, 249, 338, 1855, 2020, - /* 1490 */ 599, 569, 563, 1996, 2019, 554, 552, 551, 259, 339, - /* 1500 */ 580, 577, 1470, 131, 1354, 57, 162, 254, 1955, 88, - /* 1510 */ 256, 1885, 1990, 1887, 605, 1921, 1743, 1670, 257, 97, - /* 1520 */ 1886, 1888, 603, 1890, 1891, 598, 258, 593, 280, 271, - /* 1530 */ 686, 687, 2062, 689, 1974, 1887, 2041, 292, 342, 1970, - /* 1540 */ 262, 306, 1905, 49, 2065, 282, 303, 302, 1993, 284, - /* 1550 */ 600, 1849, 1848, 68, 1847, 1855, 69, 599, 1846, 1843, - /* 1560 */ 367, 368, 1319, 1320, 1905, 177, 372, 1841, 374, 375, - /* 1570 */ 376, 1840, 600, 378, 1839, 380, 1838, 1855, 1885, 599, - /* 1580 */ 1837, 384, 1921, 382, 1295, 1294, 97, 1886, 1888, 603, - /* 1590 */ 1890, 1891, 598, 1887, 593, 1815, 1814, 389, 390, 1949, - /* 1600 */ 1885, 1974, 1813, 1812, 1921, 342, 1970, 134, 97, 1886, - /* 1610 */ 1888, 603, 1890, 1891, 598, 1887, 593, 1787, 1264, 345, - /* 1620 */ 344, 1947, 1905, 1974, 1786, 1784, 1783, 342, 1970, 1341, - /* 1630 */ 600, 1782, 1785, 135, 1781, 1855, 408, 599, 1780, 1779, - /* 1640 */ 1407, 1778, 1334, 1777, 1905, 1776, 409, 1775, 411, 1774, - /* 1650 */ 1773, 1772, 600, 1771, 1770, 1769, 1768, 1855, 1885, 599, - /* 1660 */ 1767, 1766, 1921, 1402, 1765, 1764, 97, 1886, 1888, 603, - /* 1670 */ 1890, 1891, 598, 1763, 593, 1333, 1762, 1761, 1760, 548, - /* 1680 */ 1885, 1974, 136, 1759, 1921, 342, 1970, 1148, 98, 1886, - /* 1690 */ 1888, 603, 1890, 1891, 598, 1758, 593, 1757, 1756, 1755, - /* 1700 */ 1754, 1266, 1753, 1974, 1752, 1617, 1616, 1973, 1970, 1614, - /* 1710 */ 1582, 190, 448, 187, 188, 166, 450, 1065, 1581, 123, - /* 1720 */ 124, 1064, 1887, 589, 191, 1828, 1822, 1811, 196, 198, - /* 1730 */ 1810, 1796, 1678, 1095, 1613, 1611, 465, 466, 1609, 470, - /* 1740 */ 1607, 474, 1605, 478, 1594, 1593, 469, 467, 1578, 473, - /* 1750 */ 1680, 1905, 471, 1679, 475, 477, 479, 1216, 1215, 600, - /* 1760 */ 1603, 1598, 59, 206, 1855, 502, 599, 658, 1139, 1132, - /* 1770 */ 1596, 660, 1138, 327, 1137, 1577, 1134, 328, 1133, 329, - /* 1780 */ 1576, 1131, 1342, 1575, 1337, 511, 99, 1885, 1311, 505, - /* 1790 */ 1887, 1921, 1827, 507, 509, 98, 1886, 1888, 603, 1890, - /* 1800 */ 1891, 598, 1821, 593, 53, 152, 1345, 1347, 1301, 1887, - /* 1810 */ 1974, 520, 1809, 25, 588, 1970, 1807, 2047, 1808, 1905, - /* 1820 */ 591, 1400, 1401, 1403, 1404, 1405, 1406, 597, 1309, 521, - /* 1830 */ 330, 1806, 1855, 225, 599, 1805, 1803, 1795, 1905, 526, - /* 1840 */ 83, 241, 537, 18, 238, 1419, 600, 230, 19, 20, - /* 1850 */ 534, 1855, 15, 599, 10, 1885, 236, 253, 82, 1921, - /* 1860 */ 90, 1876, 85, 300, 1886, 1888, 603, 1890, 1891, 598, - /* 1870 */ 596, 593, 546, 1939, 1885, 27, 1887, 1515, 1921, 246, - /* 1880 */ 244, 248, 98, 1886, 1888, 603, 1890, 1891, 598, 1497, - /* 1890 */ 593, 56, 1499, 1887, 160, 252, 29, 1974, 251, 61, - /* 1900 */ 22, 28, 1971, 1492, 89, 1905, 265, 1530, 1418, 1529, - /* 1910 */ 340, 1534, 1535, 597, 1536, 1533, 341, 1467, 1855, 1466, - /* 1920 */ 599, 55, 1905, 1875, 12, 163, 1343, 1924, 1429, 54, - /* 1930 */ 600, 164, 21, 1397, 592, 1855, 1887, 599, 1395, 35, - /* 1940 */ 14, 1885, 1375, 175, 1394, 1921, 1367, 604, 23, 300, - /* 1950 */ 1886, 1888, 603, 1890, 1891, 598, 1887, 593, 1885, 1940, - /* 1960 */ 24, 606, 1921, 1202, 351, 1905, 158, 1886, 1888, 603, - /* 1970 */ 1890, 1891, 598, 600, 593, 602, 608, 610, 1855, 1199, - /* 1980 */ 599, 611, 613, 1196, 614, 1905, 1190, 616, 617, 619, - /* 1990 */ 347, 1194, 620, 600, 1188, 1179, 91, 92, 1855, 626, - /* 2000 */ 599, 1885, 1211, 67, 1193, 1921, 269, 1887, 2012, 296, - /* 2010 */ 1886, 1888, 603, 1890, 1891, 598, 16, 593, 1192, 1191, - /* 2020 */ 1207, 1885, 1093, 635, 1128, 1921, 1127, 1126, 1125, 301, - /* 2030 */ 1886, 1888, 603, 1890, 1891, 598, 1905, 593, 1124, 1123, - /* 2040 */ 1121, 350, 1119, 1118, 600, 1117, 1146, 647, 1115, 1855, - /* 2050 */ 1114, 599, 270, 568, 1113, 1112, 1111, 1110, 1109, 1108, - /* 2060 */ 1141, 1105, 1143, 1104, 1101, 1100, 1099, 1610, 1098, 1608, - /* 2070 */ 668, 1606, 1885, 672, 669, 670, 1921, 676, 673, 674, - /* 2080 */ 301, 1886, 1888, 603, 1890, 1891, 598, 1887, 593, 678, - /* 2090 */ 677, 1604, 680, 681, 682, 1592, 684, 1055, 1574, 273, - /* 2100 */ 688, 1549, 1329, 281, 691, 1887, 692, 1549, 1549, 1549, - /* 2110 */ 1549, 1549, 1549, 1549, 1549, 1549, 1905, 1549, 1549, 1549, - /* 2120 */ 1549, 1549, 1549, 1549, 600, 1549, 1549, 1549, 1549, 1855, - /* 2130 */ 1549, 599, 1549, 1549, 1905, 1549, 1549, 1549, 1549, 1549, - /* 2140 */ 1549, 1549, 600, 1549, 1549, 1549, 1549, 1855, 1887, 599, - /* 2150 */ 1549, 1549, 514, 1549, 1549, 1549, 1921, 1549, 1549, 1549, - /* 2160 */ 294, 1886, 1888, 603, 1890, 1891, 598, 1887, 593, 1549, - /* 2170 */ 1885, 1549, 1549, 1549, 1921, 1549, 1549, 1905, 286, 1886, - /* 2180 */ 1888, 603, 1890, 1891, 598, 600, 593, 1549, 1549, 1549, - /* 2190 */ 1855, 1887, 599, 1549, 1549, 1549, 1905, 1549, 1549, 1549, - /* 2200 */ 1549, 1549, 1549, 1549, 600, 1549, 1549, 1549, 1549, 1855, - /* 2210 */ 1549, 599, 1549, 1885, 1549, 1549, 1549, 1921, 1549, 1549, - /* 2220 */ 1905, 287, 1886, 1888, 603, 1890, 1891, 598, 600, 593, - /* 2230 */ 1549, 1549, 1885, 1855, 1887, 599, 1921, 1549, 1549, 1549, - /* 2240 */ 288, 1886, 1888, 603, 1890, 1891, 598, 1549, 593, 1549, - /* 2250 */ 1549, 1887, 1549, 1549, 1549, 1549, 1885, 1549, 1549, 1549, - /* 2260 */ 1921, 1549, 1549, 1905, 295, 1886, 1888, 603, 1890, 1891, - /* 2270 */ 598, 600, 593, 1549, 1549, 1549, 1855, 1887, 599, 1549, - /* 2280 */ 1905, 1549, 1549, 1549, 1549, 1549, 1549, 1549, 600, 1549, - /* 2290 */ 1549, 1549, 1549, 1855, 1887, 599, 1549, 1549, 1549, 1885, - /* 2300 */ 1549, 1549, 1549, 1921, 1549, 1549, 1905, 297, 1886, 1888, - /* 2310 */ 603, 1890, 1891, 598, 600, 593, 1885, 1549, 1549, 1855, - /* 2320 */ 1921, 599, 1549, 1905, 289, 1886, 1888, 603, 1890, 1891, - /* 2330 */ 598, 600, 593, 1549, 1549, 1549, 1855, 1549, 599, 1549, - /* 2340 */ 1549, 1549, 1885, 1549, 1549, 1549, 1921, 1549, 1549, 1549, - /* 2350 */ 298, 1886, 1888, 603, 1890, 1891, 598, 1887, 593, 1885, - /* 2360 */ 1549, 1549, 1549, 1921, 1549, 1549, 1549, 290, 1886, 1888, - /* 2370 */ 603, 1890, 1891, 598, 1887, 593, 1549, 1549, 1549, 1549, - /* 2380 */ 1549, 1549, 1549, 1549, 1549, 1549, 1905, 1549, 1549, 1549, - /* 2390 */ 1549, 1549, 1549, 1549, 600, 1549, 1549, 1549, 1549, 1855, - /* 2400 */ 1549, 599, 1549, 1905, 1549, 1549, 1549, 1549, 1549, 1549, - /* 2410 */ 1549, 600, 1549, 1549, 1549, 1549, 1855, 1549, 599, 1549, - /* 2420 */ 1549, 1549, 1885, 1549, 1549, 1549, 1921, 1549, 1549, 1549, - /* 2430 */ 299, 1886, 1888, 603, 1890, 1891, 598, 1887, 593, 1885, - /* 2440 */ 1549, 1549, 1549, 1921, 1549, 1549, 1549, 291, 1886, 1888, - /* 2450 */ 603, 1890, 1891, 598, 1549, 593, 1549, 1549, 1549, 1549, - /* 2460 */ 1549, 1549, 1549, 1887, 1549, 1549, 1905, 1549, 1549, 1549, - /* 2470 */ 1549, 1549, 1549, 1549, 600, 1549, 1549, 1549, 1549, 1855, - /* 2480 */ 1549, 599, 1549, 1549, 1549, 1549, 1549, 1549, 1549, 1549, - /* 2490 */ 1549, 1549, 1905, 1549, 1549, 1549, 1549, 1549, 1549, 1549, - /* 2500 */ 600, 1549, 1885, 1549, 1549, 1855, 1921, 599, 1549, 1549, - /* 2510 */ 304, 1886, 1888, 603, 1890, 1891, 598, 1887, 593, 1549, - /* 2520 */ 1549, 1549, 1549, 1549, 1549, 1549, 1549, 1549, 1885, 1549, - /* 2530 */ 1549, 1549, 1921, 1549, 1887, 1549, 305, 1886, 1888, 603, - /* 2540 */ 1890, 1891, 598, 1549, 593, 1549, 1905, 1549, 1549, 1549, - /* 2550 */ 1549, 1549, 1549, 1549, 600, 1549, 1549, 1549, 1549, 1855, - /* 2560 */ 1549, 599, 1549, 1905, 1549, 1549, 1549, 1549, 1549, 1549, - /* 2570 */ 1549, 600, 1549, 1549, 1549, 1549, 1855, 1887, 599, 1549, - /* 2580 */ 1549, 1549, 1885, 1549, 1549, 1549, 1921, 1549, 1549, 1549, - /* 2590 */ 1899, 1886, 1888, 603, 1890, 1891, 598, 1887, 593, 1885, - /* 2600 */ 1549, 1549, 1549, 1921, 1549, 1549, 1905, 1898, 1886, 1888, - /* 2610 */ 603, 1890, 1891, 598, 600, 593, 1549, 1549, 1549, 1855, - /* 2620 */ 1549, 599, 1549, 1549, 1549, 1549, 1905, 1549, 1549, 1549, - /* 2630 */ 1549, 1549, 1549, 1549, 600, 1549, 1549, 1549, 1549, 1855, - /* 2640 */ 1887, 599, 1885, 1549, 1549, 1549, 1921, 1549, 1549, 1549, - /* 2650 */ 1897, 1886, 1888, 603, 1890, 1891, 598, 1887, 593, 1549, - /* 2660 */ 1549, 1549, 1885, 1549, 1549, 1549, 1921, 1549, 1549, 1905, - /* 2670 */ 316, 1886, 1888, 603, 1890, 1891, 598, 600, 593, 1549, - /* 2680 */ 1549, 1549, 1855, 1549, 599, 1549, 1905, 1549, 1549, 1549, - /* 2690 */ 1549, 1549, 1549, 1549, 600, 1549, 1549, 1549, 1549, 1855, - /* 2700 */ 1549, 599, 1549, 1549, 1549, 1885, 1549, 1549, 1549, 1921, - /* 2710 */ 1549, 1549, 1549, 317, 1886, 1888, 603, 1890, 1891, 598, - /* 2720 */ 1887, 593, 1885, 1549, 1549, 1549, 1921, 1549, 1549, 1549, - /* 2730 */ 313, 1886, 1888, 603, 1890, 1891, 598, 1887, 593, 1549, - /* 2740 */ 1549, 1549, 1549, 1549, 1549, 1549, 1549, 1549, 1549, 1905, - /* 2750 */ 1549, 1549, 1549, 1549, 1549, 1549, 1549, 600, 1549, 1549, - /* 2760 */ 1549, 1549, 1855, 1549, 599, 1549, 1905, 1549, 1549, 1549, - /* 2770 */ 1549, 1549, 1549, 1549, 600, 1549, 1549, 1549, 1549, 1855, - /* 2780 */ 1549, 599, 1549, 1549, 1549, 1885, 1549, 1549, 1549, 1921, - /* 2790 */ 1549, 1549, 1549, 318, 1886, 1888, 603, 1890, 1891, 598, - /* 2800 */ 1549, 593, 1885, 1549, 1549, 1549, 1921, 1549, 1549, 1549, - /* 2810 */ 293, 1886, 1888, 603, 1890, 1891, 598, 1549, 593, + /* 0 */ 1881, 34, 267, 1881, 157, 1062, 1568, 1895, 62, 534, + /* 10 */ 1698, 1877, 44, 42, 1877, 446, 334, 447, 1591, 1807, + /* 20 */ 349, 1877, 1333, 43, 41, 40, 39, 38, 588, 156, + /* 30 */ 167, 1554, 1358, 1413, 1660, 1331, 1913, 1873, 1879, 337, + /* 40 */ 1873, 1879, 343, 1746, 589, 1066, 1067, 1873, 1879, 1863, + /* 50 */ 595, 601, 30, 595, 445, 1579, 1408, 449, 37, 36, + /* 60 */ 595, 17, 43, 41, 40, 39, 38, 1895, 1339, 44, + /* 70 */ 42, 1483, 1893, 1578, 505, 588, 1929, 349, 573, 1333, + /* 80 */ 97, 1894, 1896, 605, 1898, 1899, 600, 77, 595, 515, + /* 90 */ 1413, 364, 1331, 168, 1, 1982, 1913, 1863, 58, 342, + /* 100 */ 1978, 125, 46, 218, 602, 585, 58, 2050, 530, 1863, + /* 110 */ 1702, 601, 173, 1408, 534, 1863, 692, 508, 17, 1577, + /* 120 */ 2008, 502, 572, 171, 1808, 1339, 217, 2051, 574, 1359, + /* 130 */ 1415, 1416, 603, 2055, 132, 585, 1929, 2050, 394, 1576, + /* 140 */ 98, 348, 1896, 605, 1898, 1899, 600, 454, 595, 447, + /* 150 */ 1591, 1, 2056, 171, 1079, 1982, 1078, 2051, 574, 314, + /* 160 */ 1978, 1863, 2050, 64, 132, 7, 63, 58, 1487, 482, + /* 170 */ 2050, 130, 335, 692, 1358, 1334, 310, 1332, 2054, 219, + /* 180 */ 154, 1863, 2051, 2053, 1080, 572, 171, 1415, 1416, 1709, + /* 190 */ 2051, 574, 587, 169, 1990, 1991, 1359, 1995, 463, 1337, + /* 200 */ 1338, 121, 1388, 1389, 1391, 1392, 1393, 1394, 1395, 1396, + /* 210 */ 1397, 1398, 597, 593, 1406, 1407, 1409, 1410, 1411, 1412, + /* 220 */ 1414, 1417, 3, 264, 1990, 584, 1684, 583, 1753, 1754, + /* 230 */ 2050, 1423, 1334, 383, 1332, 79, 312, 1358, 388, 537, + /* 240 */ 174, 1509, 496, 495, 174, 572, 171, 387, 174, 386, + /* 250 */ 2051, 574, 174, 385, 381, 530, 1337, 1338, 58, 1388, + /* 260 */ 1389, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 597, + /* 270 */ 593, 1406, 1407, 1409, 1410, 1411, 1412, 1414, 1417, 3, + /* 280 */ 44, 42, 695, 181, 2050, 233, 234, 1358, 349, 77, + /* 290 */ 1333, 560, 1507, 1508, 1510, 1511, 274, 547, 1895, 2056, + /* 300 */ 171, 1413, 547, 1331, 2051, 574, 1228, 1229, 2055, 52, + /* 310 */ 165, 1882, 1703, 174, 120, 685, 681, 677, 673, 272, + /* 320 */ 74, 484, 1877, 73, 1408, 220, 1707, 1913, 1737, 17, + /* 330 */ 354, 1707, 636, 1752, 1754, 602, 1339, 44, 42, 1079, + /* 340 */ 1863, 1078, 601, 312, 588, 349, 537, 1333, 1873, 1879, + /* 350 */ 563, 145, 144, 633, 632, 631, 95, 1390, 1413, 240, + /* 360 */ 1331, 595, 1, 603, 451, 1476, 547, 1929, 636, 1080, + /* 370 */ 1356, 294, 348, 1896, 605, 1898, 1899, 600, 120, 595, + /* 380 */ 47, 1408, 1557, 395, 692, 489, 17, 145, 144, 633, + /* 390 */ 632, 631, 544, 1339, 453, 1707, 396, 449, 1415, 1416, + /* 400 */ 1542, 2050, 1333, 110, 174, 431, 109, 108, 107, 106, + /* 410 */ 105, 104, 103, 102, 101, 1331, 572, 171, 46, 1, + /* 420 */ 1390, 2051, 574, 110, 229, 547, 109, 108, 107, 106, + /* 430 */ 105, 104, 103, 102, 101, 569, 564, 176, 500, 499, + /* 440 */ 498, 692, 1305, 1334, 222, 1332, 126, 494, 1339, 1575, + /* 450 */ 154, 493, 492, 1759, 1707, 1415, 1416, 491, 497, 1710, + /* 460 */ 336, 185, 184, 490, 1146, 1066, 1067, 1337, 1338, 1757, + /* 470 */ 1388, 1389, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, + /* 480 */ 597, 593, 1406, 1407, 1409, 1410, 1411, 1412, 1414, 1417, + /* 490 */ 3, 1863, 11, 40, 39, 38, 692, 1148, 2002, 1476, + /* 500 */ 1334, 1621, 1332, 232, 568, 1444, 1186, 627, 626, 625, + /* 510 */ 1190, 624, 1192, 1193, 623, 1195, 620, 638, 1201, 617, + /* 520 */ 1203, 1204, 614, 611, 1337, 1338, 174, 1388, 1389, 1391, + /* 530 */ 1392, 1393, 1394, 1395, 1396, 1397, 1398, 597, 593, 1406, + /* 540 */ 1407, 1409, 1410, 1411, 1412, 1414, 1417, 3, 44, 42, + /* 550 */ 1800, 352, 1913, 2055, 1997, 1334, 349, 1332, 1333, 154, + /* 560 */ 567, 179, 1311, 1312, 500, 499, 498, 630, 1709, 1413, + /* 570 */ 1360, 1331, 126, 494, 547, 31, 227, 493, 492, 1337, + /* 580 */ 1338, 1895, 1994, 491, 497, 1449, 392, 1685, 1810, 490, + /* 590 */ 37, 36, 1408, 1357, 43, 41, 40, 39, 38, 566, + /* 600 */ 1895, 1759, 577, 1707, 1339, 44, 42, 1418, 353, 547, + /* 610 */ 1913, 48, 4, 349, 58, 1333, 81, 1757, 602, 547, + /* 620 */ 11, 393, 9, 1863, 355, 601, 1413, 1759, 1331, 1913, + /* 630 */ 8, 403, 154, 128, 319, 2055, 1953, 602, 1707, 547, + /* 640 */ 1574, 1709, 1863, 1757, 601, 1542, 1893, 463, 1707, 1408, + /* 650 */ 1929, 417, 692, 533, 158, 1894, 1896, 605, 1898, 1899, + /* 660 */ 600, 1339, 595, 1480, 2050, 1893, 1415, 1416, 1707, 1929, + /* 670 */ 530, 547, 573, 97, 1894, 1896, 605, 1898, 1899, 600, + /* 680 */ 2054, 595, 1863, 418, 2051, 2052, 2070, 8, 1982, 549, + /* 690 */ 514, 1954, 342, 1978, 1759, 552, 2019, 663, 661, 2050, + /* 700 */ 1707, 2050, 2016, 512, 1683, 510, 551, 11, 1954, 692, + /* 710 */ 1758, 1334, 266, 1332, 2056, 171, 572, 171, 1358, 2051, + /* 720 */ 574, 2051, 574, 1415, 1416, 37, 36, 13, 12, 43, + /* 730 */ 41, 40, 39, 38, 1850, 1337, 1338, 1361, 1388, 1389, + /* 740 */ 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 597, 593, + /* 750 */ 1406, 1407, 1409, 1410, 1411, 1412, 1414, 1417, 3, 1556, + /* 760 */ 174, 1339, 1360, 1800, 638, 1806, 1800, 307, 1334, 651, + /* 770 */ 1332, 1677, 87, 325, 180, 650, 174, 183, 1573, 525, + /* 780 */ 1805, 371, 307, 119, 118, 117, 116, 115, 114, 113, + /* 790 */ 112, 111, 1337, 1338, 1700, 1388, 1389, 1391, 1392, 1393, + /* 800 */ 1394, 1395, 1396, 1397, 1398, 597, 593, 1406, 1407, 1409, + /* 810 */ 1410, 1411, 1412, 1414, 1417, 3, 44, 42, 578, 547, + /* 820 */ 1863, 1456, 634, 362, 349, 1750, 1333, 1997, 1997, 635, + /* 830 */ 1696, 461, 1750, 326, 1572, 324, 323, 1413, 486, 1331, + /* 840 */ 530, 361, 488, 94, 488, 1361, 37, 36, 1707, 1895, + /* 850 */ 43, 41, 40, 39, 38, 1993, 1992, 127, 530, 547, + /* 860 */ 1408, 1692, 2054, 547, 487, 1699, 487, 1571, 1895, 2050, + /* 870 */ 547, 462, 1339, 44, 42, 1704, 1863, 1694, 1913, 243, + /* 880 */ 143, 349, 137, 1333, 2056, 171, 602, 2050, 1707, 2051, + /* 890 */ 574, 1863, 1707, 601, 1413, 1690, 1331, 1913, 8, 1707, + /* 900 */ 1479, 1390, 2056, 171, 266, 602, 580, 2051, 574, 1863, + /* 910 */ 1863, 223, 601, 279, 1893, 1570, 1737, 1408, 1929, 547, + /* 920 */ 692, 1895, 159, 1894, 1896, 605, 1898, 1899, 600, 1339, + /* 930 */ 595, 526, 51, 1893, 1415, 1416, 1567, 1929, 1566, 547, + /* 940 */ 1608, 97, 1894, 1896, 605, 1898, 1899, 600, 1707, 595, + /* 950 */ 1913, 531, 50, 529, 2070, 1, 1982, 1863, 602, 547, + /* 960 */ 342, 1978, 501, 1863, 547, 601, 210, 596, 1707, 208, + /* 970 */ 2044, 237, 547, 629, 575, 2071, 543, 692, 1863, 1334, + /* 980 */ 1863, 1332, 1682, 592, 545, 1661, 1893, 242, 1707, 402, + /* 990 */ 1929, 1415, 1416, 1707, 159, 1894, 1896, 605, 1898, 1899, + /* 1000 */ 600, 1707, 595, 1337, 1338, 1549, 1388, 1389, 1391, 1392, + /* 1010 */ 1393, 1394, 1395, 1396, 1397, 1398, 597, 593, 1406, 1407, + /* 1020 */ 1409, 1410, 1411, 1412, 1414, 1417, 3, 37, 36, 205, + /* 1030 */ 547, 43, 41, 40, 39, 38, 1334, 72, 1332, 1551, + /* 1040 */ 1552, 212, 546, 161, 211, 1565, 2022, 2072, 480, 476, + /* 1050 */ 472, 468, 204, 1564, 214, 13, 12, 213, 1342, 1707, + /* 1060 */ 1337, 1338, 1618, 1388, 1389, 1391, 1392, 1393, 1394, 1395, + /* 1070 */ 1396, 1397, 1398, 597, 593, 1406, 1407, 1409, 1410, 1411, + /* 1080 */ 1412, 1414, 1417, 3, 309, 1569, 1356, 1863, 636, 78, + /* 1090 */ 226, 216, 202, 425, 215, 1863, 436, 1603, 37, 36, + /* 1100 */ 1548, 481, 43, 41, 40, 39, 38, 145, 144, 633, + /* 1110 */ 632, 631, 261, 410, 1519, 437, 576, 412, 1563, 503, + /* 1120 */ 1341, 1434, 1562, 1561, 581, 669, 668, 667, 666, 359, + /* 1130 */ 80, 665, 664, 133, 659, 658, 657, 656, 655, 654, + /* 1140 */ 653, 652, 147, 648, 647, 646, 358, 357, 643, 642, + /* 1150 */ 641, 640, 639, 155, 201, 195, 1560, 200, 285, 322, + /* 1160 */ 1863, 459, 37, 36, 1863, 1863, 43, 41, 40, 39, + /* 1170 */ 38, 398, 283, 66, 1601, 45, 65, 193, 255, 231, + /* 1180 */ 561, 138, 142, 1914, 1559, 1499, 143, 360, 60, 1592, + /* 1190 */ 1747, 247, 189, 442, 440, 1895, 506, 26, 1863, 435, + /* 1200 */ 1345, 60, 430, 429, 428, 427, 424, 423, 422, 421, + /* 1210 */ 420, 416, 415, 414, 413, 407, 406, 405, 404, 2012, + /* 1220 */ 400, 399, 321, 547, 1913, 263, 1863, 1282, 45, 58, + /* 1230 */ 1106, 235, 602, 540, 239, 268, 1597, 1863, 1179, 601, + /* 1240 */ 1506, 37, 36, 250, 32, 43, 41, 40, 39, 38, + /* 1250 */ 37, 36, 1707, 1450, 43, 41, 40, 39, 38, 260, + /* 1260 */ 1893, 586, 1344, 1107, 1929, 1884, 547, 96, 97, 1894, + /* 1270 */ 1896, 605, 1898, 1899, 600, 2, 595, 1895, 356, 129, + /* 1280 */ 1399, 141, 1953, 1982, 687, 37, 36, 342, 1978, 43, + /* 1290 */ 41, 40, 39, 38, 315, 1707, 45, 609, 93, 5, + /* 1300 */ 365, 518, 71, 70, 391, 370, 1913, 178, 90, 142, + /* 1310 */ 1298, 332, 143, 1886, 602, 644, 645, 122, 530, 1863, + /* 1320 */ 320, 601, 142, 275, 308, 182, 1356, 379, 1895, 377, + /* 1330 */ 373, 369, 366, 363, 397, 401, 1442, 1126, 1124, 419, + /* 1340 */ 1802, 426, 1893, 433, 585, 432, 1929, 2050, 278, 1207, + /* 1350 */ 301, 1894, 1896, 605, 1898, 1899, 600, 1913, 595, 434, + /* 1360 */ 585, 1211, 2056, 171, 1218, 589, 186, 2051, 574, 1216, + /* 1370 */ 1863, 439, 601, 132, 146, 174, 438, 441, 443, 1362, + /* 1380 */ 444, 452, 1364, 455, 192, 456, 1363, 194, 1365, 132, + /* 1390 */ 1443, 457, 458, 1893, 460, 197, 199, 1929, 464, 75, + /* 1400 */ 76, 97, 1894, 1896, 605, 1898, 1899, 600, 203, 595, + /* 1410 */ 130, 483, 99, 311, 168, 1841, 1982, 517, 485, 519, + /* 1420 */ 342, 1978, 1697, 207, 1693, 276, 130, 209, 148, 149, + /* 1430 */ 1695, 1691, 170, 1990, 1991, 150, 1995, 151, 221, 153, + /* 1440 */ 520, 2009, 521, 224, 527, 532, 1895, 524, 172, 1990, + /* 1450 */ 1991, 228, 1995, 331, 559, 535, 1840, 1812, 538, 139, + /* 1460 */ 33, 346, 1437, 1438, 1439, 1440, 1441, 1445, 1446, 1447, + /* 1470 */ 1448, 140, 333, 541, 542, 1913, 84, 86, 277, 1708, + /* 1480 */ 1361, 555, 562, 602, 2013, 2028, 245, 557, 1863, 558, + /* 1490 */ 601, 338, 2023, 565, 2027, 249, 571, 6, 553, 259, + /* 1500 */ 556, 162, 554, 2004, 339, 582, 579, 1476, 131, 2073, + /* 1510 */ 1360, 1893, 57, 1895, 88, 1929, 607, 1751, 1963, 97, + /* 1520 */ 1894, 1896, 605, 1898, 1899, 600, 1678, 595, 257, 254, + /* 1530 */ 256, 258, 2070, 1998, 1982, 1895, 280, 688, 342, 1978, + /* 1540 */ 271, 689, 1913, 691, 49, 2049, 306, 262, 2001, 292, + /* 1550 */ 602, 282, 303, 284, 302, 1863, 68, 601, 1857, 1856, + /* 1560 */ 1855, 1854, 69, 1851, 1913, 367, 368, 1325, 1326, 177, + /* 1570 */ 372, 1849, 602, 374, 375, 376, 1848, 1863, 1893, 601, + /* 1580 */ 378, 1847, 1929, 380, 1846, 1845, 97, 1894, 1896, 605, + /* 1590 */ 1898, 1899, 600, 1895, 595, 1823, 382, 384, 1301, 1957, + /* 1600 */ 1893, 1982, 1300, 1822, 1929, 342, 1978, 389, 97, 1894, + /* 1610 */ 1896, 605, 1898, 1899, 600, 1895, 595, 390, 1821, 345, + /* 1620 */ 344, 1955, 1913, 1982, 1820, 1270, 1795, 342, 1978, 1347, + /* 1630 */ 602, 1794, 1792, 134, 1791, 1863, 135, 601, 1790, 1793, + /* 1640 */ 1413, 1789, 1340, 1788, 1913, 1787, 1786, 1785, 1784, 409, + /* 1650 */ 408, 1783, 602, 411, 1782, 1781, 1780, 1863, 1893, 601, + /* 1660 */ 1779, 1778, 1929, 1408, 1777, 1776, 97, 1894, 1896, 605, + /* 1670 */ 1898, 1899, 600, 1775, 595, 1339, 1774, 1773, 1772, 550, + /* 1680 */ 1893, 1982, 1771, 1770, 1929, 342, 1978, 1154, 98, 1894, + /* 1690 */ 1896, 605, 1898, 1899, 600, 1769, 595, 1768, 1767, 136, + /* 1700 */ 1766, 1765, 1764, 1982, 1763, 1762, 1272, 1981, 1978, 1761, + /* 1710 */ 1760, 1623, 1622, 1620, 187, 188, 1588, 190, 123, 1587, + /* 1720 */ 1069, 1068, 1895, 591, 166, 124, 448, 1836, 191, 1830, + /* 1730 */ 1819, 450, 196, 198, 1818, 1804, 1686, 1619, 1617, 466, + /* 1740 */ 1615, 470, 467, 465, 1613, 1611, 474, 1600, 1599, 469, + /* 1750 */ 1584, 1913, 1099, 473, 471, 477, 475, 1688, 1222, 602, + /* 1760 */ 1687, 479, 1609, 1221, 1863, 59, 601, 206, 478, 660, + /* 1770 */ 1604, 1143, 1602, 504, 1145, 662, 1136, 1144, 1142, 1583, + /* 1780 */ 1582, 1141, 1348, 327, 1343, 328, 1138, 1893, 1137, 1581, + /* 1790 */ 1895, 1929, 53, 1135, 507, 98, 1894, 1896, 605, 1898, + /* 1800 */ 1899, 600, 1835, 595, 329, 513, 1351, 1353, 509, 1895, + /* 1810 */ 1982, 511, 100, 1307, 590, 1978, 1829, 522, 152, 1913, + /* 1820 */ 593, 1406, 1407, 1409, 1410, 1411, 1412, 599, 1317, 523, + /* 1830 */ 225, 1817, 1863, 1815, 601, 2055, 330, 1816, 1913, 1814, + /* 1840 */ 1813, 1315, 1811, 1803, 83, 241, 602, 230, 1425, 25, + /* 1850 */ 18, 1863, 19, 601, 10, 1893, 536, 20, 236, 1929, + /* 1860 */ 528, 15, 82, 300, 1894, 1896, 605, 1898, 1899, 600, + /* 1870 */ 598, 595, 548, 1947, 1893, 85, 1895, 56, 1929, 90, + /* 1880 */ 27, 244, 98, 1894, 1896, 605, 1898, 1899, 600, 1521, + /* 1890 */ 595, 539, 246, 1895, 248, 1424, 1503, 1982, 1505, 1498, + /* 1900 */ 252, 160, 1979, 29, 251, 1913, 28, 253, 1884, 89, + /* 1910 */ 61, 22, 21, 599, 1541, 1542, 1536, 1535, 1863, 340, + /* 1920 */ 601, 1540, 1913, 238, 1539, 341, 265, 12, 55, 54, + /* 1930 */ 602, 1473, 1349, 16, 1883, 1863, 1895, 601, 163, 1472, + /* 1940 */ 1932, 1893, 164, 1403, 594, 1929, 1401, 35, 14, 300, + /* 1950 */ 1894, 1896, 605, 1898, 1899, 600, 1895, 595, 1893, 1948, + /* 1960 */ 1400, 23, 1929, 175, 1373, 1913, 158, 1894, 1896, 605, + /* 1970 */ 1898, 1899, 600, 602, 595, 1381, 1435, 24, 1863, 606, + /* 1980 */ 601, 608, 1208, 351, 612, 1913, 1205, 610, 613, 604, + /* 1990 */ 347, 615, 1202, 602, 616, 618, 1196, 619, 1863, 1194, + /* 2000 */ 601, 1893, 621, 622, 1185, 1929, 1217, 1895, 2020, 296, + /* 2010 */ 1894, 1896, 605, 1898, 1899, 600, 1200, 595, 628, 269, + /* 2020 */ 1199, 1893, 91, 1198, 1197, 1929, 92, 67, 1213, 301, + /* 2030 */ 1894, 1896, 605, 1898, 1899, 600, 1913, 595, 1132, 1097, + /* 2040 */ 637, 350, 1131, 1130, 602, 1129, 1128, 1127, 1125, 1863, + /* 2050 */ 1123, 601, 1122, 570, 1121, 1152, 649, 270, 1119, 1118, + /* 2060 */ 1117, 1116, 1115, 1114, 1113, 1112, 1149, 1147, 1109, 1108, + /* 2070 */ 1105, 1104, 1893, 1103, 1102, 1616, 1929, 670, 671, 1614, + /* 2080 */ 301, 1894, 1896, 605, 1898, 1899, 600, 1895, 595, 672, + /* 2090 */ 674, 675, 676, 1612, 678, 679, 680, 1610, 682, 683, + /* 2100 */ 684, 1598, 686, 1059, 1580, 1895, 273, 690, 1555, 1335, + /* 2110 */ 281, 693, 694, 1555, 1555, 1555, 1913, 1555, 1555, 1555, + /* 2120 */ 1555, 1555, 1555, 1555, 602, 1555, 1555, 1555, 1555, 1863, + /* 2130 */ 1555, 601, 1555, 1555, 1913, 1555, 1555, 1555, 1555, 1555, + /* 2140 */ 1555, 1555, 602, 1555, 1555, 1555, 1555, 1863, 1895, 601, + /* 2150 */ 1555, 1555, 516, 1555, 1555, 1555, 1929, 1555, 1555, 1555, + /* 2160 */ 294, 1894, 1896, 605, 1898, 1899, 600, 1895, 595, 1555, + /* 2170 */ 1893, 1555, 1555, 1555, 1929, 1555, 1555, 1913, 286, 1894, + /* 2180 */ 1896, 605, 1898, 1899, 600, 602, 595, 1555, 1555, 1555, + /* 2190 */ 1863, 1895, 601, 1555, 1555, 1555, 1913, 1555, 1555, 1555, + /* 2200 */ 1555, 1555, 1555, 1555, 602, 1555, 1555, 1555, 1555, 1863, + /* 2210 */ 1555, 601, 1555, 1893, 1555, 1555, 1555, 1929, 1555, 1555, + /* 2220 */ 1913, 287, 1894, 1896, 605, 1898, 1899, 600, 602, 595, + /* 2230 */ 1555, 1555, 1893, 1863, 1895, 601, 1929, 1555, 1555, 1555, + /* 2240 */ 288, 1894, 1896, 605, 1898, 1899, 600, 1555, 595, 1555, + /* 2250 */ 1555, 1895, 1555, 1555, 1555, 1555, 1893, 1555, 1555, 1555, + /* 2260 */ 1929, 1555, 1555, 1913, 295, 1894, 1896, 605, 1898, 1899, + /* 2270 */ 600, 602, 595, 1555, 1555, 1555, 1863, 1895, 601, 1555, + /* 2280 */ 1913, 1555, 1555, 1555, 1555, 1555, 1555, 1555, 602, 1555, + /* 2290 */ 1555, 1555, 1555, 1863, 1895, 601, 1555, 1555, 1555, 1893, + /* 2300 */ 1555, 1555, 1555, 1929, 1555, 1555, 1913, 297, 1894, 1896, + /* 2310 */ 605, 1898, 1899, 600, 602, 595, 1893, 1555, 1555, 1863, + /* 2320 */ 1929, 601, 1555, 1913, 289, 1894, 1896, 605, 1898, 1899, + /* 2330 */ 600, 602, 595, 1555, 1555, 1555, 1863, 1555, 601, 1555, + /* 2340 */ 1555, 1555, 1893, 1555, 1555, 1555, 1929, 1555, 1555, 1555, + /* 2350 */ 298, 1894, 1896, 605, 1898, 1899, 600, 1895, 595, 1893, + /* 2360 */ 1555, 1555, 1555, 1929, 1555, 1555, 1555, 290, 1894, 1896, + /* 2370 */ 605, 1898, 1899, 600, 1895, 595, 1555, 1555, 1555, 1555, + /* 2380 */ 1555, 1555, 1555, 1555, 1555, 1555, 1913, 1555, 1555, 1555, + /* 2390 */ 1555, 1555, 1555, 1555, 602, 1555, 1555, 1555, 1555, 1863, + /* 2400 */ 1555, 601, 1555, 1913, 1555, 1555, 1555, 1555, 1555, 1555, + /* 2410 */ 1555, 602, 1555, 1555, 1555, 1555, 1863, 1555, 601, 1555, + /* 2420 */ 1555, 1555, 1893, 1555, 1555, 1555, 1929, 1555, 1555, 1555, + /* 2430 */ 299, 1894, 1896, 605, 1898, 1899, 600, 1895, 595, 1893, + /* 2440 */ 1555, 1555, 1555, 1929, 1555, 1555, 1555, 291, 1894, 1896, + /* 2450 */ 605, 1898, 1899, 600, 1555, 595, 1555, 1555, 1555, 1555, + /* 2460 */ 1555, 1555, 1555, 1895, 1555, 1555, 1913, 1555, 1555, 1555, + /* 2470 */ 1555, 1555, 1555, 1555, 602, 1555, 1555, 1555, 1555, 1863, + /* 2480 */ 1555, 601, 1555, 1555, 1555, 1555, 1555, 1555, 1555, 1555, + /* 2490 */ 1555, 1555, 1913, 1555, 1555, 1555, 1555, 1555, 1555, 1555, + /* 2500 */ 602, 1555, 1893, 1555, 1555, 1863, 1929, 601, 1555, 1555, + /* 2510 */ 304, 1894, 1896, 605, 1898, 1899, 600, 1895, 595, 1555, + /* 2520 */ 1555, 1555, 1555, 1555, 1555, 1555, 1555, 1555, 1893, 1555, + /* 2530 */ 1555, 1555, 1929, 1555, 1895, 1555, 305, 1894, 1896, 605, + /* 2540 */ 1898, 1899, 600, 1555, 595, 1555, 1913, 1555, 1555, 1555, + /* 2550 */ 1555, 1555, 1555, 1555, 602, 1555, 1555, 1555, 1555, 1863, + /* 2560 */ 1555, 601, 1555, 1913, 1555, 1555, 1555, 1555, 1555, 1555, + /* 2570 */ 1555, 602, 1555, 1555, 1555, 1555, 1863, 1895, 601, 1555, + /* 2580 */ 1555, 1555, 1893, 1555, 1555, 1555, 1929, 1555, 1555, 1555, + /* 2590 */ 1907, 1894, 1896, 605, 1898, 1899, 600, 1895, 595, 1893, + /* 2600 */ 1555, 1555, 1555, 1929, 1555, 1555, 1913, 1906, 1894, 1896, + /* 2610 */ 605, 1898, 1899, 600, 602, 595, 1555, 1555, 1555, 1863, + /* 2620 */ 1555, 601, 1555, 1555, 1555, 1555, 1913, 1555, 1555, 1555, + /* 2630 */ 1555, 1555, 1555, 1555, 602, 1555, 1555, 1555, 1555, 1863, + /* 2640 */ 1895, 601, 1893, 1555, 1555, 1555, 1929, 1555, 1555, 1555, + /* 2650 */ 1905, 1894, 1896, 605, 1898, 1899, 600, 1895, 595, 1555, + /* 2660 */ 1555, 1555, 1893, 1555, 1555, 1555, 1929, 1555, 1555, 1913, + /* 2670 */ 316, 1894, 1896, 605, 1898, 1899, 600, 602, 595, 1555, + /* 2680 */ 1555, 1555, 1863, 1555, 601, 1555, 1913, 1555, 1555, 1555, + /* 2690 */ 1555, 1555, 1555, 1555, 602, 1555, 1555, 1555, 1555, 1863, + /* 2700 */ 1555, 601, 1555, 1555, 1555, 1893, 1555, 1555, 1555, 1929, + /* 2710 */ 1555, 1555, 1555, 317, 1894, 1896, 605, 1898, 1899, 600, + /* 2720 */ 1895, 595, 1893, 1555, 1555, 1555, 1929, 1555, 1555, 1555, + /* 2730 */ 313, 1894, 1896, 605, 1898, 1899, 600, 1895, 595, 1555, + /* 2740 */ 1555, 1555, 1555, 1555, 1555, 1555, 1555, 1555, 1555, 1913, + /* 2750 */ 1555, 1555, 1555, 1555, 1555, 1555, 1555, 602, 1555, 1555, + /* 2760 */ 1555, 1555, 1863, 1555, 601, 1555, 1913, 1555, 1555, 1555, + /* 2770 */ 1555, 1555, 1555, 1555, 602, 1555, 1555, 1555, 1555, 1863, + /* 2780 */ 1555, 601, 1555, 1555, 1555, 1893, 1555, 1555, 1555, 1929, + /* 2790 */ 1555, 1555, 1555, 318, 1894, 1896, 605, 1898, 1899, 600, + /* 2800 */ 1555, 595, 1893, 1555, 1555, 1555, 1929, 1555, 1555, 1555, + /* 2810 */ 293, 1894, 1896, 605, 1898, 1899, 600, 1555, 595, }; static const YYCODETYPE yy_lookahead[] = { /* 0 */ 351, 409, 410, 351, 319, 4, 321, 320, 4, 364, @@ -513,15 +513,15 @@ static const YYCODETYPE yy_lookahead[] = { /* 80 */ 393, 394, 395, 396, 397, 398, 399, 332, 401, 19, /* 90 */ 33, 377, 35, 406, 94, 408, 349, 362, 94, 412, /* 100 */ 413, 346, 94, 33, 357, 328, 94, 423, 394, 362, - /* 110 */ 355, 364, 425, 56, 60, 362, 116, 47, 61, 320, - /* 120 */ 433, 51, 438, 439, 20, 68, 56, 443, 444, 3, + /* 110 */ 355, 364, 425, 56, 364, 362, 116, 47, 61, 320, + /* 120 */ 433, 51, 438, 439, 374, 68, 56, 443, 444, 20, /* 130 */ 130, 131, 385, 394, 357, 328, 389, 423, 328, 320, /* 140 */ 393, 394, 395, 396, 397, 398, 399, 324, 401, 326, /* 150 */ 327, 94, 438, 439, 20, 408, 22, 443, 444, 412, - /* 160 */ 413, 362, 423, 93, 357, 4, 96, 94, 14, 35, + /* 160 */ 413, 362, 423, 93, 357, 39, 96, 94, 14, 35, /* 170 */ 423, 394, 341, 116, 20, 175, 366, 177, 439, 126, /* 180 */ 349, 362, 443, 444, 50, 438, 439, 130, 131, 358, - /* 190 */ 443, 444, 415, 416, 417, 418, 20, 420, 94, 199, + /* 190 */ 443, 444, 415, 416, 417, 418, 20, 420, 60, 199, /* 200 */ 200, 394, 202, 203, 204, 205, 206, 207, 208, 209, /* 210 */ 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, /* 220 */ 220, 221, 222, 416, 417, 418, 0, 420, 363, 364, @@ -530,190 +530,190 @@ static const YYCODETYPE yy_lookahead[] = { /* 250 */ 443, 444, 240, 190, 191, 394, 199, 200, 94, 202, /* 260 */ 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, /* 270 */ 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, - /* 280 */ 12, 13, 19, 56, 423, 125, 126, 105, 20, 332, + /* 280 */ 12, 13, 19, 56, 423, 125, 126, 20, 20, 332, /* 290 */ 22, 249, 250, 251, 252, 253, 33, 328, 320, 438, - /* 300 */ 439, 33, 328, 35, 443, 444, 130, 131, 320, 340, + /* 300 */ 439, 33, 328, 35, 443, 444, 130, 131, 3, 340, /* 310 */ 47, 351, 355, 240, 340, 52, 53, 54, 55, 56, /* 320 */ 93, 347, 362, 96, 56, 342, 357, 349, 345, 61, /* 330 */ 360, 357, 106, 363, 364, 357, 68, 12, 13, 20, - /* 340 */ 362, 22, 364, 183, 43, 20, 186, 22, 388, 389, - /* 350 */ 362, 125, 126, 127, 128, 129, 93, 203, 33, 96, - /* 360 */ 35, 401, 94, 385, 14, 160, 328, 389, 106, 50, + /* 340 */ 362, 22, 364, 183, 20, 20, 186, 22, 388, 389, + /* 350 */ 160, 125, 126, 127, 128, 129, 93, 203, 33, 96, + /* 360 */ 35, 401, 94, 385, 14, 239, 328, 389, 106, 50, /* 370 */ 20, 393, 394, 395, 396, 397, 398, 399, 340, 401, - /* 380 */ 94, 56, 0, 257, 116, 347, 61, 125, 126, 127, - /* 390 */ 128, 129, 129, 68, 320, 357, 95, 325, 130, 131, - /* 400 */ 328, 423, 241, 21, 240, 35, 24, 25, 26, 27, - /* 410 */ 28, 29, 30, 31, 32, 20, 438, 439, 391, 94, - /* 420 */ 203, 443, 444, 21, 161, 56, 24, 25, 26, 27, - /* 430 */ 28, 29, 30, 31, 32, 328, 362, 328, 68, 78, - /* 440 */ 328, 116, 179, 175, 181, 177, 419, 340, 20, 340, - /* 450 */ 245, 246, 340, 8, 9, 130, 131, 12, 13, 14, - /* 460 */ 15, 16, 320, 94, 357, 96, 357, 199, 200, 357, + /* 380 */ 94, 56, 0, 22, 116, 347, 61, 125, 126, 127, + /* 390 */ 128, 129, 129, 68, 325, 357, 35, 328, 130, 131, + /* 400 */ 95, 423, 22, 21, 240, 78, 24, 25, 26, 27, + /* 410 */ 28, 29, 30, 31, 32, 35, 438, 439, 94, 94, + /* 420 */ 203, 443, 444, 21, 161, 328, 24, 25, 26, 27, + /* 430 */ 28, 29, 30, 31, 32, 245, 246, 340, 63, 64, + /* 440 */ 65, 116, 179, 175, 181, 177, 71, 72, 68, 320, + /* 450 */ 349, 76, 77, 349, 357, 130, 131, 82, 83, 358, + /* 460 */ 356, 134, 135, 88, 35, 44, 45, 199, 200, 365, /* 470 */ 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, /* 480 */ 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, - /* 490 */ 222, 224, 224, 226, 39, 134, 135, 14, 15, 16, - /* 500 */ 175, 405, 177, 407, 362, 37, 107, 108, 109, 110, + /* 490 */ 222, 362, 224, 14, 15, 16, 116, 68, 238, 239, + /* 500 */ 175, 0, 177, 125, 20, 157, 107, 108, 109, 110, /* 510 */ 111, 112, 113, 114, 115, 116, 117, 60, 119, 120, /* 520 */ 121, 122, 123, 124, 199, 200, 240, 202, 203, 204, /* 530 */ 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, /* 540 */ 215, 216, 217, 218, 219, 220, 221, 222, 12, 13, - /* 550 */ 349, 328, 349, 63, 64, 65, 20, 356, 22, 0, - /* 560 */ 357, 71, 72, 340, 328, 97, 365, 99, 100, 33, - /* 570 */ 102, 35, 82, 83, 106, 20, 340, 320, 88, 320, - /* 580 */ 357, 320, 21, 24, 25, 26, 27, 28, 29, 30, - /* 590 */ 31, 32, 56, 357, 341, 34, 128, 36, 203, 396, - /* 600 */ 320, 349, 349, 320, 68, 12, 13, 14, 356, 240, - /* 610 */ 349, 358, 167, 20, 3, 22, 341, 365, 357, 362, - /* 620 */ 20, 362, 0, 362, 349, 364, 33, 349, 35, 349, - /* 630 */ 94, 20, 0, 358, 356, 394, 224, 357, 125, 328, - /* 640 */ 1, 2, 362, 365, 364, 362, 385, 320, 0, 56, + /* 550 */ 357, 341, 349, 3, 391, 175, 20, 177, 22, 349, + /* 560 */ 357, 368, 184, 185, 63, 64, 65, 105, 358, 33, + /* 570 */ 20, 35, 71, 72, 328, 227, 56, 76, 77, 199, + /* 580 */ 200, 320, 419, 82, 83, 237, 340, 0, 0, 88, + /* 590 */ 8, 9, 56, 20, 12, 13, 14, 15, 16, 396, + /* 600 */ 320, 349, 43, 357, 68, 12, 13, 14, 356, 328, + /* 610 */ 349, 42, 43, 20, 94, 22, 96, 365, 357, 328, + /* 620 */ 224, 340, 226, 362, 341, 364, 33, 349, 35, 349, + /* 630 */ 94, 340, 349, 404, 356, 394, 407, 357, 357, 328, + /* 640 */ 320, 358, 362, 365, 364, 95, 385, 60, 357, 56, /* 650 */ 389, 340, 116, 377, 393, 394, 395, 396, 397, 398, - /* 660 */ 399, 68, 401, 0, 423, 385, 130, 131, 357, 389, + /* 660 */ 399, 68, 401, 4, 423, 385, 130, 131, 357, 389, /* 670 */ 394, 328, 394, 393, 394, 395, 396, 397, 398, 399, - /* 680 */ 439, 401, 60, 340, 443, 444, 406, 94, 408, 362, - /* 690 */ 330, 157, 412, 413, 239, 434, 435, 184, 185, 423, - /* 700 */ 357, 423, 422, 20, 344, 330, 95, 262, 60, 116, - /* 710 */ 47, 175, 352, 177, 438, 439, 438, 439, 364, 443, - /* 720 */ 444, 443, 444, 130, 131, 8, 9, 352, 374, 12, - /* 730 */ 13, 14, 15, 16, 95, 199, 200, 20, 202, 203, + /* 680 */ 439, 401, 362, 340, 443, 444, 406, 94, 408, 405, + /* 690 */ 21, 407, 412, 413, 349, 434, 435, 335, 336, 423, + /* 700 */ 357, 423, 422, 34, 0, 36, 405, 224, 407, 116, + /* 710 */ 365, 175, 162, 177, 438, 439, 438, 439, 20, 443, + /* 720 */ 444, 443, 444, 130, 131, 8, 9, 1, 2, 12, + /* 730 */ 13, 14, 15, 16, 0, 199, 200, 20, 202, 203, /* 740 */ 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, - /* 750 */ 214, 215, 216, 217, 218, 219, 220, 221, 222, 8, - /* 760 */ 9, 227, 162, 12, 13, 14, 15, 16, 175, 0, - /* 770 */ 177, 237, 20, 162, 8, 9, 240, 2, 12, 13, - /* 780 */ 14, 15, 16, 8, 9, 320, 320, 12, 13, 14, - /* 790 */ 15, 16, 199, 200, 320, 202, 203, 204, 205, 206, + /* 750 */ 214, 215, 216, 217, 218, 219, 220, 221, 222, 0, + /* 760 */ 240, 68, 20, 357, 60, 373, 357, 375, 175, 337, + /* 770 */ 177, 339, 330, 37, 368, 68, 240, 368, 320, 381, + /* 780 */ 373, 47, 375, 24, 25, 26, 27, 28, 29, 30, + /* 790 */ 31, 32, 199, 200, 352, 202, 203, 204, 205, 206, /* 800 */ 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, - /* 810 */ 217, 218, 219, 220, 221, 222, 12, 13, 405, 328, - /* 820 */ 407, 335, 336, 373, 20, 375, 22, 362, 362, 373, - /* 830 */ 22, 375, 63, 64, 65, 68, 362, 33, 328, 35, - /* 840 */ 71, 72, 328, 35, 357, 357, 95, 20, 357, 320, - /* 850 */ 340, 82, 83, 320, 340, 368, 368, 88, 8, 9, - /* 860 */ 56, 95, 12, 13, 14, 15, 16, 357, 320, 357, - /* 870 */ 328, 357, 68, 12, 13, 328, 350, 328, 349, 162, - /* 880 */ 368, 20, 340, 22, 349, 394, 357, 340, 391, 340, - /* 890 */ 328, 362, 349, 364, 33, 362, 35, 349, 94, 357, - /* 900 */ 365, 358, 340, 328, 357, 357, 357, 416, 417, 418, - /* 910 */ 362, 420, 364, 35, 385, 340, 419, 56, 389, 357, + /* 810 */ 217, 218, 219, 220, 221, 222, 12, 13, 259, 328, + /* 820 */ 362, 95, 359, 377, 20, 362, 22, 391, 391, 359, + /* 830 */ 350, 340, 362, 97, 320, 99, 100, 33, 102, 35, + /* 840 */ 394, 377, 106, 330, 106, 20, 8, 9, 357, 320, + /* 850 */ 12, 13, 14, 15, 16, 419, 419, 344, 394, 328, + /* 860 */ 56, 350, 3, 328, 128, 352, 128, 320, 320, 423, + /* 870 */ 328, 340, 68, 12, 13, 340, 362, 350, 349, 162, + /* 880 */ 43, 20, 340, 22, 438, 439, 357, 423, 357, 443, + /* 890 */ 444, 362, 357, 364, 33, 350, 35, 349, 94, 357, + /* 900 */ 241, 203, 438, 439, 162, 357, 43, 443, 444, 362, + /* 910 */ 362, 350, 364, 342, 385, 320, 345, 56, 389, 328, /* 920 */ 116, 320, 393, 394, 395, 396, 397, 398, 399, 68, - /* 930 */ 401, 106, 357, 385, 130, 131, 320, 389, 320, 105, - /* 940 */ 328, 393, 394, 395, 396, 397, 398, 399, 404, 401, - /* 950 */ 349, 407, 340, 128, 406, 94, 408, 391, 357, 328, - /* 960 */ 412, 413, 43, 362, 328, 364, 337, 68, 339, 357, - /* 970 */ 422, 340, 328, 43, 445, 446, 340, 116, 362, 175, - /* 980 */ 362, 177, 0, 0, 340, 419, 385, 153, 357, 162, + /* 930 */ 401, 340, 95, 385, 130, 131, 320, 389, 320, 328, + /* 940 */ 0, 393, 394, 395, 396, 397, 398, 399, 357, 401, + /* 950 */ 349, 340, 162, 163, 406, 94, 408, 362, 357, 328, + /* 960 */ 412, 413, 22, 362, 328, 364, 98, 350, 357, 101, + /* 970 */ 422, 340, 328, 350, 445, 446, 340, 116, 362, 175, + /* 980 */ 362, 177, 0, 61, 340, 338, 385, 162, 357, 105, /* 990 */ 389, 130, 131, 357, 393, 394, 395, 396, 397, 398, - /* 1000 */ 399, 357, 401, 199, 200, 22, 202, 203, 204, 205, + /* 1000 */ 399, 357, 401, 199, 200, 167, 202, 203, 204, 205, /* 1010 */ 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, /* 1020 */ 216, 217, 218, 219, 220, 221, 222, 8, 9, 33, - /* 1030 */ 350, 12, 13, 14, 15, 16, 175, 359, 177, 377, - /* 1040 */ 362, 359, 43, 47, 362, 320, 35, 446, 52, 53, - /* 1050 */ 54, 55, 56, 320, 342, 177, 394, 345, 44, 45, + /* 1030 */ 328, 12, 13, 14, 15, 16, 175, 153, 177, 130, + /* 1040 */ 131, 98, 340, 47, 101, 320, 392, 446, 52, 53, + /* 1050 */ 54, 55, 56, 320, 98, 1, 2, 101, 35, 357, /* 1060 */ 199, 200, 0, 202, 203, 204, 205, 206, 207, 208, /* 1070 */ 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, - /* 1080 */ 219, 220, 221, 222, 18, 423, 20, 362, 106, 93, - /* 1090 */ 238, 239, 96, 27, 95, 362, 30, 42, 43, 98, - /* 1100 */ 438, 439, 101, 162, 163, 443, 444, 125, 126, 127, - /* 1110 */ 128, 129, 350, 47, 43, 49, 98, 51, 98, 101, - /* 1120 */ 98, 101, 43, 101, 56, 63, 64, 65, 66, 67, - /* 1130 */ 350, 69, 70, 71, 72, 73, 74, 75, 76, 77, + /* 1080 */ 219, 220, 221, 222, 18, 321, 20, 362, 106, 93, + /* 1090 */ 56, 98, 96, 27, 101, 362, 30, 0, 8, 9, + /* 1100 */ 262, 329, 12, 13, 14, 15, 16, 125, 126, 127, + /* 1110 */ 128, 129, 447, 47, 95, 49, 257, 51, 320, 22, + /* 1120 */ 35, 199, 320, 320, 261, 63, 64, 65, 66, 67, + /* 1130 */ 96, 69, 70, 71, 72, 73, 74, 75, 76, 77, /* 1140 */ 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, - /* 1150 */ 88, 89, 90, 18, 158, 159, 0, 161, 23, 93, - /* 1160 */ 0, 165, 130, 131, 96, 13, 95, 43, 1, 2, - /* 1170 */ 61, 105, 37, 38, 95, 43, 41, 181, 22, 43, - /* 1180 */ 261, 162, 22, 43, 22, 46, 43, 35, 177, 259, - /* 1190 */ 350, 43, 57, 58, 59, 320, 350, 35, 3, 133, - /* 1200 */ 43, 43, 136, 137, 138, 139, 140, 141, 142, 143, - /* 1210 */ 144, 145, 146, 147, 148, 149, 150, 151, 152, 95, - /* 1220 */ 154, 155, 156, 43, 349, 381, 350, 95, 43, 94, - /* 1230 */ 68, 95, 357, 94, 321, 95, 338, 362, 95, 364, - /* 1240 */ 392, 8, 9, 95, 43, 12, 13, 14, 15, 16, - /* 1250 */ 8, 9, 95, 95, 12, 13, 14, 15, 16, 35, - /* 1260 */ 385, 43, 13, 447, 389, 436, 329, 132, 393, 394, - /* 1270 */ 395, 396, 397, 398, 399, 95, 401, 320, 116, 404, - /* 1280 */ 95, 406, 407, 408, 35, 43, 0, 412, 413, 430, - /* 1290 */ 95, 349, 68, 329, 61, 327, 95, 361, 392, 94, - /* 1300 */ 421, 414, 167, 168, 169, 440, 349, 172, 199, 104, - /* 1310 */ 424, 354, 242, 95, 357, 387, 47, 386, 173, 362, - /* 1320 */ 42, 364, 379, 369, 189, 369, 20, 192, 320, 194, - /* 1330 */ 195, 196, 197, 198, 48, 328, 103, 175, 328, 177, - /* 1340 */ 369, 157, 385, 367, 367, 328, 389, 92, 20, 334, - /* 1350 */ 393, 394, 395, 396, 397, 398, 399, 349, 401, 328, - /* 1360 */ 20, 199, 200, 328, 377, 357, 328, 322, 322, 383, - /* 1370 */ 362, 332, 364, 364, 357, 240, 332, 377, 20, 376, - /* 1380 */ 20, 394, 378, 332, 332, 332, 332, 328, 376, 332, - /* 1390 */ 157, 322, 349, 385, 394, 328, 349, 389, 349, 349, - /* 1400 */ 188, 393, 394, 395, 396, 397, 398, 399, 322, 401, - /* 1410 */ 423, 394, 349, 349, 406, 330, 408, 384, 362, 383, - /* 1420 */ 412, 413, 349, 423, 349, 438, 439, 349, 180, 349, - /* 1430 */ 443, 444, 349, 416, 417, 418, 364, 420, 438, 439, - /* 1440 */ 382, 433, 330, 443, 444, 328, 320, 328, 330, 247, - /* 1450 */ 376, 362, 362, 372, 362, 362, 372, 362, 159, 330, + /* 1150 */ 88, 89, 90, 18, 158, 159, 320, 161, 23, 93, + /* 1160 */ 362, 165, 8, 9, 362, 362, 12, 13, 14, 15, + /* 1170 */ 16, 105, 37, 38, 0, 43, 41, 181, 430, 43, + /* 1180 */ 436, 43, 43, 349, 320, 95, 43, 329, 43, 327, + /* 1190 */ 361, 43, 57, 58, 59, 320, 22, 43, 362, 133, + /* 1200 */ 177, 43, 136, 137, 138, 139, 140, 141, 142, 143, + /* 1210 */ 144, 145, 146, 147, 148, 149, 150, 151, 152, 392, + /* 1220 */ 154, 155, 156, 328, 349, 440, 362, 95, 43, 94, + /* 1230 */ 35, 95, 357, 95, 95, 340, 0, 362, 95, 364, + /* 1240 */ 95, 8, 9, 95, 2, 12, 13, 14, 15, 16, + /* 1250 */ 8, 9, 357, 95, 12, 13, 14, 15, 16, 414, + /* 1260 */ 385, 421, 177, 68, 389, 46, 328, 132, 393, 394, + /* 1270 */ 395, 396, 397, 398, 399, 424, 401, 320, 340, 404, + /* 1280 */ 95, 406, 407, 408, 48, 8, 9, 412, 413, 12, + /* 1290 */ 13, 14, 15, 16, 61, 357, 43, 43, 94, 242, + /* 1300 */ 387, 377, 167, 168, 169, 47, 349, 172, 104, 43, + /* 1310 */ 173, 354, 43, 94, 357, 13, 13, 43, 394, 362, + /* 1320 */ 386, 364, 43, 379, 189, 42, 20, 192, 320, 194, + /* 1330 */ 195, 196, 197, 198, 369, 369, 103, 35, 35, 328, + /* 1340 */ 328, 369, 385, 157, 328, 367, 389, 423, 95, 95, + /* 1350 */ 393, 394, 395, 396, 397, 398, 399, 349, 401, 367, + /* 1360 */ 328, 95, 438, 439, 95, 357, 328, 443, 444, 95, + /* 1370 */ 362, 334, 364, 357, 95, 240, 92, 328, 328, 20, + /* 1380 */ 322, 322, 20, 383, 332, 364, 20, 332, 20, 357, + /* 1390 */ 157, 376, 378, 385, 376, 332, 332, 389, 328, 332, + /* 1400 */ 332, 393, 394, 395, 396, 397, 398, 399, 332, 401, + /* 1410 */ 394, 322, 328, 322, 406, 362, 408, 188, 349, 384, + /* 1420 */ 412, 413, 349, 349, 349, 383, 394, 349, 349, 349, + /* 1430 */ 349, 349, 416, 417, 418, 349, 420, 349, 330, 162, + /* 1440 */ 180, 433, 382, 330, 328, 328, 320, 364, 416, 417, + /* 1450 */ 418, 330, 420, 376, 247, 362, 362, 362, 362, 372, /* 1460 */ 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, - /* 1470 */ 237, 370, 345, 357, 330, 349, 20, 362, 248, 392, - /* 1480 */ 392, 254, 372, 357, 362, 362, 372, 362, 362, 429, - /* 1490 */ 364, 166, 362, 432, 429, 256, 255, 243, 387, 263, - /* 1500 */ 260, 258, 239, 357, 20, 94, 429, 431, 411, 94, - /* 1510 */ 428, 385, 391, 320, 353, 389, 362, 339, 427, 393, - /* 1520 */ 394, 395, 396, 397, 398, 399, 426, 401, 328, 330, - /* 1530 */ 36, 323, 406, 322, 408, 320, 442, 343, 412, 413, - /* 1540 */ 441, 375, 349, 380, 448, 331, 343, 343, 422, 318, - /* 1550 */ 357, 0, 0, 182, 0, 362, 42, 364, 0, 0, - /* 1560 */ 35, 193, 35, 35, 349, 35, 193, 0, 35, 35, - /* 1570 */ 193, 0, 357, 193, 0, 35, 0, 362, 385, 364, - /* 1580 */ 0, 35, 389, 22, 177, 175, 393, 394, 395, 396, - /* 1590 */ 397, 398, 399, 320, 401, 0, 0, 171, 170, 406, - /* 1600 */ 385, 408, 0, 0, 389, 412, 413, 42, 393, 394, - /* 1610 */ 395, 396, 397, 398, 399, 320, 401, 0, 46, 12, - /* 1620 */ 13, 406, 349, 408, 0, 0, 0, 412, 413, 22, - /* 1630 */ 357, 0, 0, 42, 0, 362, 148, 364, 0, 0, - /* 1640 */ 33, 0, 35, 0, 349, 0, 35, 0, 148, 0, - /* 1650 */ 0, 0, 357, 0, 0, 0, 0, 362, 385, 364, + /* 1470 */ 237, 372, 362, 159, 370, 349, 330, 330, 345, 357, + /* 1480 */ 20, 362, 248, 357, 392, 429, 372, 362, 362, 362, + /* 1490 */ 364, 362, 392, 362, 429, 372, 166, 254, 243, 387, + /* 1500 */ 256, 429, 255, 432, 263, 260, 258, 239, 357, 448, + /* 1510 */ 20, 385, 94, 320, 94, 389, 353, 362, 411, 393, + /* 1520 */ 394, 395, 396, 397, 398, 399, 339, 401, 427, 431, + /* 1530 */ 428, 426, 406, 391, 408, 320, 328, 36, 412, 413, + /* 1540 */ 330, 323, 349, 322, 380, 442, 375, 441, 422, 343, + /* 1550 */ 357, 331, 343, 318, 343, 362, 182, 364, 0, 0, + /* 1560 */ 0, 0, 42, 0, 349, 35, 193, 35, 35, 35, + /* 1570 */ 193, 0, 357, 35, 35, 193, 0, 362, 385, 364, + /* 1580 */ 193, 0, 389, 35, 0, 0, 393, 394, 395, 396, + /* 1590 */ 397, 398, 399, 320, 401, 0, 22, 35, 177, 406, + /* 1600 */ 385, 408, 175, 0, 389, 412, 413, 171, 393, 394, + /* 1610 */ 395, 396, 397, 398, 399, 320, 401, 170, 0, 12, + /* 1620 */ 13, 406, 349, 408, 0, 46, 0, 412, 413, 22, + /* 1630 */ 357, 0, 0, 42, 0, 362, 42, 364, 0, 0, + /* 1640 */ 33, 0, 35, 0, 349, 0, 0, 0, 0, 35, + /* 1650 */ 148, 0, 357, 148, 0, 0, 0, 362, 385, 364, /* 1660 */ 0, 0, 389, 56, 0, 0, 393, 394, 395, 396, /* 1670 */ 397, 398, 399, 0, 401, 68, 0, 0, 0, 406, - /* 1680 */ 385, 408, 42, 0, 389, 412, 413, 35, 393, 394, - /* 1690 */ 395, 396, 397, 398, 399, 0, 401, 0, 0, 0, - /* 1700 */ 0, 22, 0, 408, 0, 0, 0, 412, 413, 0, - /* 1710 */ 0, 42, 46, 56, 56, 43, 46, 14, 0, 39, - /* 1720 */ 39, 14, 320, 116, 40, 0, 0, 0, 39, 166, - /* 1730 */ 0, 0, 0, 62, 0, 0, 35, 47, 0, 47, - /* 1740 */ 0, 47, 0, 47, 0, 0, 35, 39, 0, 35, - /* 1750 */ 0, 349, 39, 0, 39, 35, 39, 35, 22, 357, - /* 1760 */ 0, 0, 103, 101, 362, 49, 364, 43, 35, 22, - /* 1770 */ 0, 43, 35, 22, 35, 0, 35, 22, 35, 22, - /* 1780 */ 0, 35, 175, 0, 177, 22, 20, 385, 95, 35, - /* 1790 */ 320, 389, 0, 35, 35, 393, 394, 395, 396, 397, - /* 1800 */ 398, 399, 0, 401, 162, 178, 199, 200, 35, 320, - /* 1810 */ 408, 22, 0, 94, 412, 413, 0, 3, 0, 349, - /* 1820 */ 213, 214, 215, 216, 217, 218, 219, 357, 35, 162, - /* 1830 */ 162, 0, 362, 159, 364, 0, 0, 0, 349, 164, - /* 1840 */ 39, 46, 160, 94, 158, 223, 357, 95, 43, 43, - /* 1850 */ 187, 362, 244, 364, 225, 385, 94, 46, 94, 389, - /* 1860 */ 104, 46, 94, 393, 394, 395, 396, 397, 398, 399, - /* 1870 */ 400, 401, 402, 403, 385, 94, 320, 95, 389, 95, + /* 1680 */ 385, 408, 0, 0, 389, 412, 413, 35, 393, 394, + /* 1690 */ 395, 396, 397, 398, 399, 0, 401, 0, 0, 42, + /* 1700 */ 0, 0, 0, 408, 0, 0, 22, 412, 413, 0, + /* 1710 */ 0, 0, 0, 0, 56, 56, 0, 42, 39, 0, + /* 1720 */ 14, 14, 320, 116, 43, 39, 46, 0, 40, 0, + /* 1730 */ 0, 46, 39, 166, 0, 0, 0, 0, 0, 47, + /* 1740 */ 0, 47, 39, 35, 0, 0, 47, 0, 0, 35, + /* 1750 */ 0, 349, 62, 35, 39, 35, 39, 0, 35, 357, + /* 1760 */ 0, 39, 0, 22, 362, 103, 364, 101, 47, 43, + /* 1770 */ 0, 22, 0, 49, 35, 43, 22, 35, 35, 0, + /* 1780 */ 0, 35, 175, 22, 177, 22, 35, 385, 35, 0, + /* 1790 */ 320, 389, 162, 35, 35, 393, 394, 395, 396, 397, + /* 1800 */ 398, 399, 0, 401, 22, 22, 199, 200, 35, 320, + /* 1810 */ 408, 35, 20, 35, 412, 413, 0, 22, 178, 349, + /* 1820 */ 213, 214, 215, 216, 217, 218, 219, 357, 95, 162, + /* 1830 */ 159, 0, 362, 0, 364, 3, 162, 0, 349, 0, + /* 1840 */ 0, 35, 0, 0, 39, 46, 357, 95, 223, 94, + /* 1850 */ 94, 362, 43, 364, 225, 385, 187, 43, 94, 389, + /* 1860 */ 164, 244, 94, 393, 394, 395, 396, 397, 398, 399, + /* 1870 */ 400, 401, 402, 403, 385, 94, 320, 43, 389, 104, /* 1880 */ 94, 94, 393, 394, 395, 396, 397, 398, 399, 95, - /* 1890 */ 401, 43, 95, 320, 94, 43, 43, 408, 94, 3, - /* 1900 */ 43, 94, 413, 95, 94, 349, 46, 35, 223, 35, - /* 1910 */ 35, 35, 95, 357, 95, 35, 35, 95, 362, 95, - /* 1920 */ 364, 43, 349, 46, 2, 46, 22, 94, 199, 238, - /* 1930 */ 357, 46, 244, 95, 94, 362, 320, 364, 95, 94, - /* 1940 */ 94, 385, 22, 46, 95, 389, 95, 105, 94, 393, + /* 1890 */ 401, 160, 95, 320, 94, 223, 95, 408, 95, 95, + /* 1900 */ 43, 94, 413, 43, 94, 349, 94, 46, 46, 94, + /* 1910 */ 3, 43, 244, 357, 95, 95, 35, 35, 362, 35, + /* 1920 */ 364, 35, 349, 158, 35, 35, 46, 2, 43, 238, + /* 1930 */ 357, 95, 22, 244, 46, 362, 320, 364, 46, 95, + /* 1940 */ 94, 385, 46, 95, 94, 389, 95, 94, 94, 393, /* 1950 */ 394, 395, 396, 397, 398, 399, 320, 401, 385, 403, - /* 1960 */ 94, 35, 389, 95, 35, 349, 393, 394, 395, 396, - /* 1970 */ 397, 398, 399, 357, 401, 201, 94, 35, 362, 95, - /* 1980 */ 364, 94, 35, 95, 94, 349, 95, 35, 94, 35, - /* 1990 */ 354, 118, 94, 357, 95, 22, 94, 94, 362, 106, - /* 2000 */ 364, 385, 35, 94, 118, 389, 43, 320, 435, 393, - /* 2010 */ 394, 395, 396, 397, 398, 399, 244, 401, 118, 118, - /* 2020 */ 22, 385, 62, 61, 35, 389, 35, 35, 35, 393, - /* 2030 */ 394, 395, 396, 397, 398, 399, 349, 401, 35, 35, - /* 2040 */ 35, 354, 35, 35, 357, 35, 68, 91, 35, 362, - /* 2050 */ 35, 364, 43, 437, 22, 35, 22, 35, 35, 35, - /* 2060 */ 35, 35, 68, 35, 35, 35, 22, 0, 35, 0, - /* 2070 */ 35, 0, 385, 35, 47, 39, 389, 35, 47, 39, + /* 1960 */ 95, 94, 389, 46, 95, 349, 393, 394, 395, 396, + /* 1970 */ 397, 398, 399, 357, 401, 22, 199, 94, 362, 105, + /* 1980 */ 364, 35, 95, 35, 35, 349, 95, 94, 94, 201, + /* 1990 */ 354, 35, 95, 357, 94, 35, 95, 94, 362, 95, + /* 2000 */ 364, 385, 35, 94, 22, 389, 35, 320, 435, 393, + /* 2010 */ 394, 395, 396, 397, 398, 399, 118, 401, 106, 43, + /* 2020 */ 118, 385, 94, 118, 118, 389, 94, 94, 22, 393, + /* 2030 */ 394, 395, 396, 397, 398, 399, 349, 401, 35, 62, + /* 2040 */ 61, 354, 35, 35, 357, 35, 35, 35, 35, 362, + /* 2050 */ 35, 364, 35, 437, 35, 68, 91, 43, 35, 35, + /* 2060 */ 22, 35, 22, 35, 35, 35, 68, 35, 35, 35, + /* 2070 */ 35, 35, 385, 22, 35, 0, 389, 35, 47, 0, /* 2080 */ 393, 394, 395, 396, 397, 398, 399, 320, 401, 39, - /* 2090 */ 47, 0, 35, 47, 39, 0, 35, 35, 0, 22, - /* 2100 */ 21, 449, 22, 22, 21, 320, 20, 449, 449, 449, - /* 2110 */ 449, 449, 449, 449, 449, 449, 349, 449, 449, 449, + /* 2090 */ 35, 47, 39, 0, 35, 47, 39, 0, 35, 47, + /* 2100 */ 39, 0, 35, 35, 0, 320, 22, 21, 449, 22, + /* 2110 */ 22, 21, 20, 449, 449, 449, 349, 449, 449, 449, /* 2120 */ 449, 449, 449, 449, 357, 449, 449, 449, 449, 362, /* 2130 */ 449, 364, 449, 449, 349, 449, 449, 449, 449, 449, /* 2140 */ 449, 449, 357, 449, 449, 449, 449, 362, 320, 364, @@ -785,80 +785,80 @@ static const YYCODETYPE yy_lookahead[] = { /* 2800 */ 449, 401, 385, 449, 449, 449, 389, 449, 449, 449, /* 2810 */ 393, 394, 395, 396, 397, 398, 399, 449, 401, }; -#define YY_SHIFT_COUNT (693) +#define YY_SHIFT_COUNT (695) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (2098) +#define YY_SHIFT_MAX (2104) static const unsigned short int yy_shift_ofst[] = { /* 0 */ 1135, 0, 57, 268, 57, 325, 325, 325, 536, 325, /* 10 */ 325, 325, 325, 325, 593, 804, 804, 861, 804, 804, /* 20 */ 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, /* 30 */ 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, - /* 40 */ 804, 804, 804, 804, 804, 804, 8, 12, 104, 73, - /* 50 */ 369, 164, 286, 164, 104, 104, 1607, 1607, 164, 1607, + /* 40 */ 804, 804, 804, 804, 804, 804, 8, 12, 324, 73, + /* 50 */ 520, 164, 286, 164, 324, 324, 1607, 1607, 164, 1607, /* 60 */ 1607, 4, 164, 55, 55, 1, 1, 176, 55, 55, - /* 70 */ 55, 55, 55, 55, 55, 55, 55, 55, 54, 55, - /* 80 */ 55, 55, 428, 55, 55, 555, 55, 55, 555, 683, - /* 90 */ 55, 555, 555, 555, 55, 457, 1066, 1233, 1233, 402, - /* 100 */ 490, 1162, 1162, 1162, 1162, 1162, 1162, 1162, 1162, 1162, - /* 110 */ 1162, 1162, 1162, 1162, 1162, 1162, 1162, 1162, 1162, 1162, - /* 120 */ 468, 611, 176, 350, 350, 622, 370, 648, 267, 267, - /* 130 */ 600, 600, 600, 370, 752, 752, 752, 182, 428, 632, - /* 140 */ 632, 412, 555, 555, 767, 767, 182, 899, 399, 399, - /* 150 */ 399, 399, 399, 399, 399, 263, 382, 769, 717, 445, - /* 160 */ 42, 134, 205, 154, 217, 319, 1014, 825, 827, 852, - /* 170 */ 455, 126, 852, 1055, 161, 395, 1070, 1269, 1145, 1278, - /* 180 */ 1278, 1306, 1306, 1278, 1184, 1184, 1255, 1306, 1306, 1306, - /* 190 */ 1328, 1328, 1340, 54, 428, 54, 1358, 1360, 54, 1358, - /* 200 */ 54, 54, 54, 1306, 54, 1328, 555, 555, 555, 555, - /* 210 */ 555, 555, 555, 555, 555, 555, 555, 1306, 1328, 767, - /* 220 */ 1212, 1340, 457, 1248, 428, 457, 1306, 1306, 1358, 457, - /* 230 */ 1202, 767, 767, 767, 767, 1202, 767, 1299, 457, 182, - /* 240 */ 457, 752, 1456, 1456, 767, 1230, 1202, 767, 767, 1230, - /* 250 */ 1202, 767, 767, 555, 1227, 1325, 1230, 1239, 1241, 1254, - /* 260 */ 1070, 1236, 1240, 1243, 1263, 752, 1484, 1411, 1415, 767, - /* 270 */ 899, 1306, 457, 1494, 1328, 2819, 2819, 2819, 2819, 2819, - /* 280 */ 2819, 2819, 1062, 996, 559, 70, 751, 1242, 766, 50, - /* 290 */ 775, 1019, 226, 850, 850, 850, 850, 850, 850, 850, - /* 300 */ 850, 850, 982, 262, 11, 11, 53, 160, 63, 227, - /* 310 */ 361, 561, 513, 483, 639, 534, 483, 483, 483, 301, - /* 320 */ 663, 808, 834, 1001, 1018, 1020, 1022, 983, 1156, 1160, - /* 330 */ 1068, 941, 999, 1071, 1079, 1124, 1132, 1136, 1140, 1032, - /* 340 */ 930, 919, 1167, 1143, 878, 1011, 1109, 1148, 1195, 1139, - /* 350 */ 1157, 1158, 1180, 1185, 1201, 1218, 1205, 1152, 1249, 1224, - /* 360 */ 1286, 1551, 1552, 1371, 1554, 1558, 1514, 1559, 1525, 1368, - /* 370 */ 1527, 1528, 1530, 1373, 1567, 1533, 1534, 1377, 1571, 1380, - /* 380 */ 1574, 1540, 1576, 1561, 1580, 1546, 1407, 1410, 1595, 1596, - /* 390 */ 1426, 1428, 1602, 1603, 1572, 1617, 1624, 1625, 1565, 1626, - /* 400 */ 1631, 1632, 1591, 1634, 1638, 1639, 1641, 1643, 1645, 1488, - /* 410 */ 1611, 1647, 1500, 1649, 1650, 1651, 1653, 1654, 1655, 1656, - /* 420 */ 1660, 1661, 1664, 1665, 1673, 1676, 1677, 1640, 1678, 1683, - /* 430 */ 1695, 1697, 1698, 1679, 1699, 1700, 1702, 1704, 1652, 1705, - /* 440 */ 1657, 1706, 1658, 1709, 1710, 1669, 1680, 1672, 1703, 1666, - /* 450 */ 1707, 1670, 1718, 1684, 1681, 1725, 1726, 1727, 1689, 1563, - /* 460 */ 1730, 1731, 1732, 1671, 1734, 1735, 1701, 1690, 1708, 1738, - /* 470 */ 1711, 1692, 1713, 1740, 1714, 1694, 1715, 1742, 1720, 1696, - /* 480 */ 1717, 1744, 1745, 1748, 1750, 1659, 1662, 1722, 1736, 1753, - /* 490 */ 1733, 1737, 1739, 1724, 1728, 1741, 1743, 1747, 1746, 1760, - /* 500 */ 1751, 1761, 1755, 1716, 1770, 1757, 1754, 1775, 1758, 1780, - /* 510 */ 1759, 1783, 1763, 1766, 1693, 1719, 1792, 1642, 1773, 1802, - /* 520 */ 1627, 1789, 1667, 1674, 1812, 1816, 1668, 1675, 1814, 1818, - /* 530 */ 1831, 1835, 1749, 1752, 1793, 1663, 1836, 1762, 1682, 1764, - /* 540 */ 1837, 1801, 1686, 1768, 1756, 1795, 1805, 1622, 1629, 1685, - /* 550 */ 1806, 1608, 1781, 1782, 1786, 1784, 1794, 1787, 1848, 1797, - /* 560 */ 1800, 1804, 1807, 1808, 1852, 1811, 1815, 1810, 1853, 1688, - /* 570 */ 1817, 1819, 1896, 1857, 1772, 1872, 1874, 1875, 1876, 1880, - /* 580 */ 1881, 1822, 1824, 1860, 1691, 1878, 1877, 1879, 1922, 1904, - /* 590 */ 1729, 1833, 1838, 1840, 1843, 1845, 1849, 1885, 1846, 1854, - /* 600 */ 1897, 1851, 1920, 1774, 1866, 1842, 1868, 1926, 1929, 1882, - /* 610 */ 1884, 1942, 1887, 1888, 1947, 1890, 1891, 1952, 1894, 1899, - /* 620 */ 1954, 1898, 1873, 1886, 1900, 1901, 1973, 1893, 1902, 1903, - /* 630 */ 1967, 1909, 1963, 1963, 1998, 1960, 1962, 1989, 1991, 1992, - /* 640 */ 1993, 2003, 2004, 2005, 2007, 2008, 2010, 1978, 1956, 2009, - /* 650 */ 2013, 2015, 2032, 2020, 2034, 2022, 2023, 2024, 1994, 1724, - /* 660 */ 2025, 1728, 2026, 2028, 2029, 2030, 2044, 2033, 2067, 2035, - /* 670 */ 2027, 2036, 2069, 2038, 2031, 2040, 2071, 2042, 2043, 2050, - /* 680 */ 2091, 2057, 2046, 2055, 2095, 2061, 2062, 2098, 2077, 2079, - /* 690 */ 2080, 2081, 2083, 2086, + /* 70 */ 55, 55, 55, 55, 55, 55, 55, 55, 138, 55, + /* 80 */ 55, 55, 109, 55, 55, 267, 55, 55, 267, 484, + /* 90 */ 55, 267, 267, 267, 55, 457, 1066, 1233, 1233, 375, + /* 100 */ 402, 380, 380, 380, 380, 380, 380, 380, 380, 380, + /* 110 */ 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, + /* 120 */ 736, 550, 176, 350, 350, 587, 429, 704, 396, 396, + /* 130 */ 742, 742, 742, 429, 573, 573, 573, 462, 109, 588, + /* 140 */ 588, 483, 267, 267, 693, 693, 462, 707, 399, 399, + /* 150 */ 399, 399, 399, 399, 399, 263, 501, 382, 717, 838, + /* 160 */ 42, 134, 190, 154, 217, 319, 421, 738, 825, 260, + /* 170 */ 126, 859, 260, 569, 659, 698, 1057, 1258, 1137, 1283, + /* 180 */ 1283, 1306, 1306, 1283, 1186, 1186, 1284, 1306, 1306, 1306, + /* 190 */ 1359, 1359, 1362, 138, 109, 138, 1366, 1368, 138, 1366, + /* 200 */ 138, 138, 138, 1306, 138, 1359, 267, 267, 267, 267, + /* 210 */ 267, 267, 267, 267, 267, 267, 267, 1306, 1359, 693, + /* 220 */ 1229, 1362, 457, 1260, 109, 457, 1306, 1306, 1366, 457, + /* 230 */ 1207, 693, 693, 693, 693, 1207, 693, 1314, 457, 462, + /* 240 */ 457, 573, 1460, 1460, 693, 1234, 1207, 693, 693, 1234, + /* 250 */ 1207, 693, 693, 267, 1243, 1330, 1234, 1244, 1247, 1255, + /* 260 */ 1057, 1241, 1245, 1248, 1268, 573, 1490, 1418, 1420, 693, + /* 270 */ 707, 1306, 457, 1501, 1359, 2819, 2819, 2819, 2819, 2819, + /* 280 */ 2819, 2819, 1062, 996, 759, 70, 1019, 1154, 1090, 50, + /* 290 */ 1242, 1277, 226, 582, 582, 582, 582, 582, 582, 582, + /* 300 */ 582, 582, 982, 262, 11, 11, 53, 160, 63, 227, + /* 310 */ 327, 669, 378, 479, 726, 348, 479, 479, 479, 837, + /* 320 */ 734, 361, 884, 868, 943, 956, 993, 940, 1097, 1174, + /* 330 */ 1034, 790, 1132, 1136, 1138, 1139, 1143, 1145, 1148, 909, + /* 340 */ 559, 863, 1054, 1158, 1023, 1085, 922, 1185, 305, 1219, + /* 350 */ 1253, 1254, 1266, 1269, 1274, 1279, 1204, 1302, 1303, 1195, + /* 360 */ 1236, 1558, 1559, 1374, 1560, 1561, 1520, 1563, 1530, 1373, + /* 370 */ 1532, 1533, 1534, 1377, 1571, 1538, 1539, 1382, 1576, 1387, + /* 380 */ 1581, 1548, 1584, 1574, 1585, 1562, 1421, 1427, 1595, 1603, + /* 390 */ 1436, 1447, 1618, 1624, 1579, 1626, 1631, 1632, 1591, 1634, + /* 400 */ 1638, 1639, 1594, 1641, 1643, 1645, 1646, 1647, 1648, 1502, + /* 410 */ 1614, 1651, 1505, 1654, 1655, 1656, 1660, 1661, 1664, 1665, + /* 420 */ 1673, 1676, 1677, 1678, 1682, 1683, 1695, 1657, 1697, 1698, + /* 430 */ 1700, 1701, 1702, 1684, 1704, 1705, 1709, 1710, 1652, 1711, + /* 440 */ 1658, 1712, 1659, 1713, 1716, 1675, 1679, 1681, 1706, 1680, + /* 450 */ 1707, 1685, 1719, 1688, 1686, 1727, 1729, 1730, 1693, 1567, + /* 460 */ 1734, 1735, 1736, 1690, 1737, 1738, 1708, 1692, 1703, 1740, + /* 470 */ 1714, 1694, 1715, 1744, 1718, 1699, 1717, 1745, 1720, 1721, + /* 480 */ 1722, 1747, 1748, 1750, 1757, 1662, 1666, 1723, 1741, 1760, + /* 490 */ 1739, 1742, 1749, 1743, 1746, 1726, 1732, 1751, 1753, 1754, + /* 500 */ 1758, 1762, 1761, 1770, 1763, 1724, 1772, 1782, 1759, 1779, + /* 510 */ 1773, 1780, 1776, 1789, 1783, 1792, 1733, 1755, 1802, 1630, + /* 520 */ 1778, 1816, 1640, 1795, 1667, 1671, 1831, 1833, 1674, 1696, + /* 530 */ 1832, 1837, 1839, 1840, 1756, 1752, 1806, 1669, 1842, 1764, + /* 540 */ 1731, 1768, 1843, 1805, 1765, 1781, 1775, 1799, 1809, 1625, + /* 550 */ 1629, 1672, 1814, 1617, 1786, 1794, 1787, 1797, 1801, 1800, + /* 560 */ 1834, 1803, 1807, 1810, 1812, 1804, 1857, 1861, 1862, 1815, + /* 570 */ 1860, 1668, 1819, 1820, 1907, 1868, 1689, 1881, 1882, 1884, + /* 580 */ 1886, 1889, 1890, 1836, 1844, 1880, 1691, 1885, 1888, 1892, + /* 590 */ 1925, 1910, 1777, 1846, 1848, 1850, 1851, 1853, 1865, 1896, + /* 600 */ 1854, 1867, 1917, 1869, 1953, 1788, 1883, 1874, 1887, 1946, + /* 610 */ 1948, 1893, 1891, 1949, 1894, 1897, 1956, 1900, 1901, 1960, + /* 620 */ 1903, 1904, 1967, 1909, 1898, 1902, 1905, 1906, 1982, 1912, + /* 630 */ 1928, 1932, 1971, 1933, 1976, 1976, 2006, 1977, 1979, 2003, + /* 640 */ 2007, 2008, 2010, 2011, 2012, 2013, 2015, 2017, 2019, 1987, + /* 650 */ 1965, 2014, 2023, 2024, 2038, 2026, 2040, 2028, 2029, 2030, + /* 660 */ 1998, 1726, 2032, 1732, 2033, 2034, 2035, 2036, 2051, 2039, + /* 670 */ 2075, 2042, 2031, 2050, 2079, 2055, 2044, 2053, 2093, 2059, + /* 680 */ 2048, 2057, 2097, 2063, 2052, 2061, 2101, 2067, 2068, 2104, + /* 690 */ 2084, 2086, 2087, 2088, 2090, 2092, }; #define YY_REDUCE_COUNT (281) #define YY_REDUCE_MIN (-408) @@ -869,102 +869,102 @@ static const short yy_reduce_ofst[] = { /* 20 */ 1573, 1616, 601, 1636, 1687, 1767, 1785, 1828, 1847, 1871, /* 30 */ 1914, 1931, 1957, 1974, 2037, 2054, 2117, 2143, 2197, 2214, /* 40 */ 2257, 2277, 2320, 2337, 2400, 2417, -193, 278, -223, -139, - /* 50 */ 276, 662, 987, 1000, 491, 1017, -351, -348, -316, -341, - /* 60 */ -40, -261, 241, -26, 38, -309, -177, -30, -31, 107, - /* 70 */ 109, 112, 223, 236, 311, 343, 510, 514, -245, 542, - /* 80 */ 547, 549, -355, 562, 575, -169, 631, 636, 201, 203, - /* 90 */ 644, 253, 252, 275, 612, 360, -190, -408, -408, -315, - /* 100 */ -304, -265, -247, -201, -181, -12, 74, 142, 257, 259, - /* 110 */ 283, 327, 465, 466, 474, 533, 616, 618, 725, 733, - /* 120 */ -318, 27, -135, -271, 72, -43, -93, 375, 96, 413, - /* 130 */ 27, 497, 566, 486, 487, 488, 512, -17, 354, 450, - /* 140 */ 456, 544, 543, 535, 678, 682, 712, 629, 526, 680, - /* 150 */ 762, 780, 840, 846, 876, 844, 913, 898, 848, 816, - /* 160 */ 829, 937, 859, 942, 942, 964, 968, 936, 906, 879, - /* 170 */ 879, 865, 879, 887, 886, 942, 928, 931, 943, 954, - /* 180 */ 956, 1007, 1010, 971, 976, 977, 1015, 1031, 1035, 1038, - /* 190 */ 1045, 1046, 986, 1039, 1009, 1044, 1003, 1004, 1051, 1012, - /* 200 */ 1052, 1053, 1054, 1059, 1057, 1069, 1043, 1047, 1049, 1050, - /* 210 */ 1063, 1064, 1073, 1075, 1078, 1080, 1083, 1067, 1086, 1056, - /* 220 */ 1033, 1036, 1085, 1058, 1072, 1112, 1117, 1119, 1074, 1118, - /* 230 */ 1081, 1089, 1090, 1092, 1093, 1084, 1095, 1101, 1129, 1127, - /* 240 */ 1144, 1116, 1087, 1088, 1115, 1060, 1110, 1122, 1123, 1065, - /* 250 */ 1114, 1125, 1130, 942, 1061, 1076, 1077, 1082, 1091, 1100, - /* 260 */ 1111, 1096, 1094, 1099, 879, 1146, 1121, 1097, 1161, 1154, - /* 270 */ 1178, 1200, 1199, 1208, 1211, 1163, 1166, 1194, 1203, 1204, - /* 280 */ 1214, 1231, + /* 50 */ 276, 446, 464, 924, 1016, 1032, -351, -348, -316, -341, + /* 60 */ -40, -261, 241, -26, 38, -309, -177, -30, -31, 97, + /* 70 */ 246, 281, 291, 311, 343, 491, 531, 535, -245, 542, + /* 80 */ 591, 611, -355, 631, 636, -169, 644, 702, 104, 203, + /* 90 */ 895, 210, 252, 283, 938, 513, -190, -408, -408, -304, + /* 100 */ -315, -265, -247, -201, -181, 129, 320, 458, 514, 547, + /* 110 */ 595, 616, 618, 725, 733, 798, 802, 803, 836, 864, + /* 120 */ -318, 163, -135, -271, 69, -43, -93, 442, 284, 301, + /* 130 */ 163, 436, 437, 362, 193, 406, 409, -17, -250, 392, + /* 140 */ 407, 229, 101, 345, 463, 470, 571, 432, 480, 511, + /* 150 */ 527, 545, 561, 617, 623, 398, 647, 764, 654, 665, + /* 160 */ 744, 772, 748, 834, 834, 858, 862, 829, 827, 840, + /* 170 */ 840, 785, 840, 845, 851, 834, 913, 934, 944, 965, + /* 180 */ 966, 1011, 1012, 972, 978, 992, 1037, 1038, 1049, 1050, + /* 190 */ 1058, 1059, 1000, 1052, 1021, 1055, 1015, 1014, 1063, 1018, + /* 200 */ 1064, 1067, 1068, 1070, 1076, 1089, 1069, 1073, 1074, 1075, + /* 210 */ 1078, 1079, 1080, 1081, 1082, 1086, 1088, 1084, 1091, 1053, + /* 220 */ 1035, 1042, 1108, 1060, 1083, 1113, 1116, 1117, 1077, 1121, + /* 230 */ 1087, 1093, 1094, 1095, 1096, 1099, 1110, 1104, 1146, 1133, + /* 240 */ 1147, 1122, 1092, 1100, 1119, 1056, 1114, 1125, 1127, 1065, + /* 250 */ 1123, 1129, 1131, 834, 1071, 1098, 1072, 1102, 1101, 1105, + /* 260 */ 1112, 1061, 1103, 1106, 840, 1151, 1142, 1107, 1163, 1155, + /* 270 */ 1187, 1208, 1210, 1218, 1221, 1164, 1171, 1206, 1209, 1211, + /* 280 */ 1220, 1235, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 10 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 20 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 30 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 40 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 50 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 60 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 70 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1621, 1547, - /* 80 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 90 */ 1547, 1547, 1547, 1547, 1547, 1619, 1788, 1976, 1547, 1547, - /* 100 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 110 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 120 */ 1547, 1988, 1547, 1547, 1547, 1621, 1547, 1619, 1948, 1948, - /* 130 */ 1988, 1988, 1988, 1547, 1547, 1547, 1547, 1728, 1547, 1829, - /* 140 */ 1829, 1547, 1547, 1547, 1547, 1547, 1728, 1547, 1547, 1547, - /* 150 */ 1547, 1547, 1547, 1547, 1547, 1823, 1547, 1547, 2013, 2066, - /* 160 */ 1547, 1547, 2016, 1547, 1547, 1547, 1547, 1681, 2003, 1980, - /* 170 */ 1994, 2050, 1981, 1978, 1997, 1547, 2007, 1547, 1816, 1793, - /* 180 */ 1793, 1547, 1547, 1793, 1790, 1790, 1672, 1547, 1547, 1547, - /* 190 */ 1547, 1547, 1547, 1621, 1547, 1621, 1547, 1547, 1621, 1547, - /* 200 */ 1621, 1621, 1621, 1547, 1621, 1547, 1547, 1547, 1547, 1547, - /* 210 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 220 */ 1835, 1547, 1619, 1825, 1547, 1619, 1547, 1547, 1547, 1619, - /* 230 */ 2021, 1547, 1547, 1547, 1547, 2021, 1547, 1547, 1619, 1547, - /* 240 */ 1619, 1547, 1547, 1547, 1547, 2023, 2021, 1547, 1547, 2023, - /* 250 */ 2021, 1547, 1547, 1547, 2035, 2031, 2023, 2039, 2037, 2009, - /* 260 */ 2007, 2069, 2056, 2052, 1994, 1547, 1547, 1547, 1697, 1547, - /* 270 */ 1547, 1547, 1619, 1579, 1547, 1818, 1829, 1731, 1731, 1731, - /* 280 */ 1622, 1552, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 290 */ 1547, 1547, 1547, 1904, 1547, 2034, 2033, 1952, 1951, 1950, - /* 300 */ 1941, 1903, 1547, 1693, 1902, 1901, 1547, 1547, 1547, 1547, - /* 310 */ 1547, 1547, 1547, 1895, 1547, 1547, 1896, 1894, 1893, 1547, - /* 320 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 330 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 340 */ 2053, 2057, 1977, 1547, 1547, 1547, 1547, 1547, 1886, 1877, - /* 350 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 360 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 370 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 380 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 390 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 400 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 410 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 420 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 430 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 440 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1584, 1547, 1547, - /* 450 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 460 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 470 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 480 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 490 */ 1547, 1547, 1547, 1661, 1660, 1547, 1547, 1547, 1547, 1547, - /* 500 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 510 */ 1547, 1547, 1547, 1547, 1885, 1547, 1547, 1547, 1547, 1547, - /* 520 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 2049, 1547, - /* 530 */ 1547, 1547, 1547, 1547, 1547, 1547, 1833, 1547, 1547, 1547, - /* 540 */ 1547, 1547, 1547, 1547, 1547, 1547, 1938, 1547, 1547, 1547, - /* 550 */ 2010, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 560 */ 1547, 1547, 1547, 1547, 1547, 1547, 1877, 1547, 2032, 1547, - /* 570 */ 1547, 2047, 1547, 2051, 1547, 1547, 1547, 1547, 1547, 1547, - /* 580 */ 1547, 1987, 1983, 1547, 1547, 1979, 1876, 1547, 1972, 1547, - /* 590 */ 1547, 1923, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 600 */ 1547, 1885, 1547, 1889, 1547, 1547, 1547, 1547, 1547, 1725, - /* 610 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 620 */ 1547, 1547, 1710, 1708, 1707, 1706, 1547, 1703, 1547, 1547, - /* 630 */ 1547, 1547, 1734, 1733, 1547, 1547, 1547, 1547, 1547, 1547, - /* 640 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1641, - /* 650 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1632, - /* 660 */ 1547, 1631, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 670 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 680 */ 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, 1547, - /* 690 */ 1547, 1547, 1547, 1547, + /* 0 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 10 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 20 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 30 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 40 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 50 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 60 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 70 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1627, 1553, + /* 80 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 90 */ 1553, 1553, 1553, 1553, 1553, 1625, 1796, 1984, 1553, 1553, + /* 100 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 110 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 120 */ 1553, 1996, 1553, 1553, 1553, 1627, 1553, 1625, 1956, 1956, + /* 130 */ 1996, 1996, 1996, 1553, 1553, 1553, 1553, 1736, 1553, 1837, + /* 140 */ 1837, 1553, 1553, 1553, 1553, 1553, 1736, 1553, 1553, 1553, + /* 150 */ 1553, 1553, 1553, 1553, 1553, 1831, 1553, 1553, 2021, 2074, + /* 160 */ 1553, 1553, 2024, 1553, 1553, 1553, 1553, 1689, 2011, 1988, + /* 170 */ 2002, 2058, 1989, 1986, 2005, 1553, 2015, 1553, 1824, 1801, + /* 180 */ 1801, 1553, 1553, 1801, 1798, 1798, 1680, 1553, 1553, 1553, + /* 190 */ 1553, 1553, 1553, 1627, 1553, 1627, 1553, 1553, 1627, 1553, + /* 200 */ 1627, 1627, 1627, 1553, 1627, 1553, 1553, 1553, 1553, 1553, + /* 210 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 220 */ 1843, 1553, 1625, 1833, 1553, 1625, 1553, 1553, 1553, 1625, + /* 230 */ 2029, 1553, 1553, 1553, 1553, 2029, 1553, 1553, 1625, 1553, + /* 240 */ 1625, 1553, 1553, 1553, 1553, 2031, 2029, 1553, 1553, 2031, + /* 250 */ 2029, 1553, 1553, 1553, 2043, 2039, 2031, 2047, 2045, 2017, + /* 260 */ 2015, 2077, 2064, 2060, 2002, 1553, 1553, 1553, 1705, 1553, + /* 270 */ 1553, 1553, 1625, 1585, 1553, 1826, 1837, 1739, 1739, 1739, + /* 280 */ 1628, 1558, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 290 */ 1553, 1553, 1553, 1912, 1553, 2042, 2041, 1960, 1959, 1958, + /* 300 */ 1949, 1911, 1553, 1701, 1910, 1909, 1553, 1553, 1553, 1553, + /* 310 */ 1553, 1553, 1553, 1903, 1553, 1553, 1904, 1902, 1901, 1553, + /* 320 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 330 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 340 */ 2061, 2065, 1985, 1553, 1553, 1553, 1553, 1553, 1894, 1885, + /* 350 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 360 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 370 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 380 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 390 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 400 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 410 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 420 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 430 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 440 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1590, 1553, 1553, + /* 450 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 460 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 470 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 480 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 490 */ 1553, 1553, 1553, 1553, 1553, 1667, 1666, 1553, 1553, 1553, + /* 500 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 510 */ 1553, 1553, 1553, 1553, 1553, 1553, 1893, 1553, 1553, 1553, + /* 520 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 530 */ 2057, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1841, 1553, + /* 540 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1946, 1553, + /* 550 */ 1553, 1553, 2018, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 560 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1885, 1553, + /* 570 */ 2040, 1553, 1553, 2055, 1553, 2059, 1553, 1553, 1553, 1553, + /* 580 */ 1553, 1553, 1553, 1995, 1991, 1553, 1553, 1987, 1884, 1553, + /* 590 */ 1980, 1553, 1553, 1931, 1553, 1553, 1553, 1553, 1553, 1553, + /* 600 */ 1553, 1553, 1553, 1893, 1553, 1897, 1553, 1553, 1553, 1553, + /* 610 */ 1553, 1733, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 620 */ 1553, 1553, 1553, 1553, 1718, 1716, 1715, 1714, 1553, 1711, + /* 630 */ 1553, 1553, 1553, 1553, 1742, 1741, 1553, 1553, 1553, 1553, + /* 640 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 650 */ 1553, 1647, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 660 */ 1553, 1638, 1553, 1637, 1553, 1553, 1553, 1553, 1553, 1553, + /* 670 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 680 */ 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, 1553, + /* 690 */ 1553, 1553, 1553, 1553, 1553, 1553, }; /********** End of lemon-generated parsing tables *****************************/ @@ -1957,415 +1957,417 @@ static const char *const yyRuleName[] = { /* 110 */ "alter_db_option ::= KEEP integer_list", /* 111 */ "alter_db_option ::= KEEP variable_list", /* 112 */ "alter_db_option ::= PAGES NK_INTEGER", - /* 113 */ "alter_db_option ::= WAL_LEVEL NK_INTEGER", - /* 114 */ "alter_db_option ::= STT_TRIGGER NK_INTEGER", - /* 115 */ "integer_list ::= NK_INTEGER", - /* 116 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", - /* 117 */ "variable_list ::= NK_VARIABLE", - /* 118 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", - /* 119 */ "retention_list ::= retention", - /* 120 */ "retention_list ::= retention_list NK_COMMA retention", - /* 121 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", - /* 122 */ "speed_opt ::=", - /* 123 */ "speed_opt ::= MAX_SPEED NK_INTEGER", - /* 124 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", - /* 125 */ "cmd ::= CREATE TABLE multi_create_clause", - /* 126 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", - /* 127 */ "cmd ::= DROP TABLE multi_drop_clause", - /* 128 */ "cmd ::= DROP STABLE exists_opt full_table_name", - /* 129 */ "cmd ::= ALTER TABLE alter_table_clause", - /* 130 */ "cmd ::= ALTER STABLE alter_table_clause", - /* 131 */ "alter_table_clause ::= full_table_name alter_table_options", - /* 132 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", - /* 133 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", - /* 134 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", - /* 135 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", - /* 136 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", - /* 137 */ "alter_table_clause ::= full_table_name DROP TAG column_name", - /* 138 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", - /* 139 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", - /* 140 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal", - /* 141 */ "multi_create_clause ::= create_subtable_clause", - /* 142 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", - /* 143 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options", - /* 144 */ "multi_drop_clause ::= drop_table_clause", - /* 145 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", - /* 146 */ "drop_table_clause ::= exists_opt full_table_name", - /* 147 */ "specific_cols_opt ::=", - /* 148 */ "specific_cols_opt ::= NK_LP col_name_list NK_RP", - /* 149 */ "full_table_name ::= table_name", - /* 150 */ "full_table_name ::= db_name NK_DOT table_name", - /* 151 */ "column_def_list ::= column_def", - /* 152 */ "column_def_list ::= column_def_list NK_COMMA column_def", - /* 153 */ "column_def ::= column_name type_name", - /* 154 */ "column_def ::= column_name type_name COMMENT NK_STRING", - /* 155 */ "type_name ::= BOOL", - /* 156 */ "type_name ::= TINYINT", - /* 157 */ "type_name ::= SMALLINT", - /* 158 */ "type_name ::= INT", - /* 159 */ "type_name ::= INTEGER", - /* 160 */ "type_name ::= BIGINT", - /* 161 */ "type_name ::= FLOAT", - /* 162 */ "type_name ::= DOUBLE", - /* 163 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", - /* 164 */ "type_name ::= TIMESTAMP", - /* 165 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", - /* 166 */ "type_name ::= TINYINT UNSIGNED", - /* 167 */ "type_name ::= SMALLINT UNSIGNED", - /* 168 */ "type_name ::= INT UNSIGNED", - /* 169 */ "type_name ::= BIGINT UNSIGNED", - /* 170 */ "type_name ::= JSON", - /* 171 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", - /* 172 */ "type_name ::= MEDIUMBLOB", - /* 173 */ "type_name ::= BLOB", - /* 174 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", - /* 175 */ "type_name ::= DECIMAL", - /* 176 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", - /* 177 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", - /* 178 */ "tags_def_opt ::=", - /* 179 */ "tags_def_opt ::= tags_def", - /* 180 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", - /* 181 */ "table_options ::=", - /* 182 */ "table_options ::= table_options COMMENT NK_STRING", - /* 183 */ "table_options ::= table_options MAX_DELAY duration_list", - /* 184 */ "table_options ::= table_options WATERMARK duration_list", - /* 185 */ "table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP", - /* 186 */ "table_options ::= table_options TTL NK_INTEGER", - /* 187 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", - /* 188 */ "alter_table_options ::= alter_table_option", - /* 189 */ "alter_table_options ::= alter_table_options alter_table_option", - /* 190 */ "alter_table_option ::= COMMENT NK_STRING", - /* 191 */ "alter_table_option ::= TTL NK_INTEGER", - /* 192 */ "duration_list ::= duration_literal", - /* 193 */ "duration_list ::= duration_list NK_COMMA duration_literal", - /* 194 */ "rollup_func_list ::= rollup_func_name", - /* 195 */ "rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name", - /* 196 */ "rollup_func_name ::= function_name", - /* 197 */ "rollup_func_name ::= FIRST", - /* 198 */ "rollup_func_name ::= LAST", - /* 199 */ "col_name_list ::= col_name", - /* 200 */ "col_name_list ::= col_name_list NK_COMMA col_name", - /* 201 */ "col_name ::= column_name", - /* 202 */ "cmd ::= SHOW DNODES", - /* 203 */ "cmd ::= SHOW USERS", - /* 204 */ "cmd ::= SHOW DATABASES", - /* 205 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", - /* 206 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", - /* 207 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", - /* 208 */ "cmd ::= SHOW MNODES", - /* 209 */ "cmd ::= SHOW QNODES", - /* 210 */ "cmd ::= SHOW FUNCTIONS", - /* 211 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", - /* 212 */ "cmd ::= SHOW STREAMS", - /* 213 */ "cmd ::= SHOW ACCOUNTS", - /* 214 */ "cmd ::= SHOW APPS", - /* 215 */ "cmd ::= SHOW CONNECTIONS", - /* 216 */ "cmd ::= SHOW LICENCES", - /* 217 */ "cmd ::= SHOW GRANTS", - /* 218 */ "cmd ::= SHOW CREATE DATABASE db_name", - /* 219 */ "cmd ::= SHOW CREATE TABLE full_table_name", - /* 220 */ "cmd ::= SHOW CREATE STABLE full_table_name", - /* 221 */ "cmd ::= SHOW QUERIES", - /* 222 */ "cmd ::= SHOW SCORES", - /* 223 */ "cmd ::= SHOW TOPICS", - /* 224 */ "cmd ::= SHOW VARIABLES", - /* 225 */ "cmd ::= SHOW LOCAL VARIABLES", - /* 226 */ "cmd ::= SHOW DNODE NK_INTEGER VARIABLES", - /* 227 */ "cmd ::= SHOW BNODES", - /* 228 */ "cmd ::= SHOW SNODES", - /* 229 */ "cmd ::= SHOW CLUSTER", - /* 230 */ "cmd ::= SHOW TRANSACTIONS", - /* 231 */ "cmd ::= SHOW TABLE DISTRIBUTED full_table_name", - /* 232 */ "cmd ::= SHOW CONSUMERS", - /* 233 */ "cmd ::= SHOW SUBSCRIPTIONS", - /* 234 */ "cmd ::= SHOW TAGS FROM table_name_cond from_db_opt", - /* 235 */ "cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt", - /* 236 */ "cmd ::= SHOW VNODES NK_INTEGER", - /* 237 */ "cmd ::= SHOW VNODES NK_STRING", - /* 238 */ "db_name_cond_opt ::=", - /* 239 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 240 */ "like_pattern_opt ::=", - /* 241 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 242 */ "table_name_cond ::= table_name", - /* 243 */ "from_db_opt ::=", - /* 244 */ "from_db_opt ::= FROM db_name", - /* 245 */ "cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options", - /* 246 */ "cmd ::= DROP INDEX exists_opt full_table_name", - /* 247 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt", - /* 248 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt", - /* 249 */ "func_list ::= func", - /* 250 */ "func_list ::= func_list NK_COMMA func", - /* 251 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 252 */ "sma_stream_opt ::=", - /* 253 */ "sma_stream_opt ::= stream_options WATERMARK duration_literal", - /* 254 */ "sma_stream_opt ::= stream_options MAX_DELAY duration_literal", - /* 255 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery", - /* 256 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", - /* 257 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name", - /* 258 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", - /* 259 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name", - /* 260 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 261 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", - /* 262 */ "cmd ::= DESC full_table_name", - /* 263 */ "cmd ::= DESCRIBE full_table_name", - /* 264 */ "cmd ::= RESET QUERY CACHE", - /* 265 */ "cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery", - /* 266 */ "analyze_opt ::=", - /* 267 */ "analyze_opt ::= ANALYZE", - /* 268 */ "explain_options ::=", - /* 269 */ "explain_options ::= explain_options VERBOSE NK_BOOL", - /* 270 */ "explain_options ::= explain_options RATIO NK_FLOAT", - /* 271 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", - /* 272 */ "cmd ::= DROP FUNCTION exists_opt function_name", - /* 273 */ "agg_func_opt ::=", - /* 274 */ "agg_func_opt ::= AGGREGATE", - /* 275 */ "bufsize_opt ::=", - /* 276 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", - /* 277 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery", - /* 278 */ "cmd ::= DROP STREAM exists_opt stream_name", - /* 279 */ "stream_options ::=", - /* 280 */ "stream_options ::= stream_options TRIGGER AT_ONCE", - /* 281 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", - /* 282 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", - /* 283 */ "stream_options ::= stream_options WATERMARK duration_literal", - /* 284 */ "stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER", - /* 285 */ "subtable_opt ::=", - /* 286 */ "subtable_opt ::= SUBTABLE NK_LP expression NK_RP", - /* 287 */ "cmd ::= KILL CONNECTION NK_INTEGER", - /* 288 */ "cmd ::= KILL QUERY NK_STRING", - /* 289 */ "cmd ::= KILL TRANSACTION NK_INTEGER", - /* 290 */ "cmd ::= BALANCE VGROUP", - /* 291 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", - /* 292 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", - /* 293 */ "cmd ::= SPLIT VGROUP NK_INTEGER", - /* 294 */ "dnode_list ::= DNODE NK_INTEGER", - /* 295 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", - /* 296 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", - /* 297 */ "cmd ::= query_or_subquery", - /* 298 */ "cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery", - /* 299 */ "cmd ::= INSERT INTO full_table_name query_or_subquery", - /* 300 */ "literal ::= NK_INTEGER", - /* 301 */ "literal ::= NK_FLOAT", - /* 302 */ "literal ::= NK_STRING", - /* 303 */ "literal ::= NK_BOOL", - /* 304 */ "literal ::= TIMESTAMP NK_STRING", - /* 305 */ "literal ::= duration_literal", - /* 306 */ "literal ::= NULL", - /* 307 */ "literal ::= NK_QUESTION", - /* 308 */ "duration_literal ::= NK_VARIABLE", - /* 309 */ "signed ::= NK_INTEGER", - /* 310 */ "signed ::= NK_PLUS NK_INTEGER", - /* 311 */ "signed ::= NK_MINUS NK_INTEGER", - /* 312 */ "signed ::= NK_FLOAT", - /* 313 */ "signed ::= NK_PLUS NK_FLOAT", - /* 314 */ "signed ::= NK_MINUS NK_FLOAT", - /* 315 */ "signed_literal ::= signed", - /* 316 */ "signed_literal ::= NK_STRING", - /* 317 */ "signed_literal ::= NK_BOOL", - /* 318 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 319 */ "signed_literal ::= duration_literal", - /* 320 */ "signed_literal ::= NULL", - /* 321 */ "signed_literal ::= literal_func", - /* 322 */ "signed_literal ::= NK_QUESTION", - /* 323 */ "literal_list ::= signed_literal", - /* 324 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 325 */ "db_name ::= NK_ID", - /* 326 */ "table_name ::= NK_ID", - /* 327 */ "column_name ::= NK_ID", - /* 328 */ "function_name ::= NK_ID", - /* 329 */ "table_alias ::= NK_ID", - /* 330 */ "column_alias ::= NK_ID", - /* 331 */ "user_name ::= NK_ID", - /* 332 */ "topic_name ::= NK_ID", - /* 333 */ "stream_name ::= NK_ID", - /* 334 */ "cgroup_name ::= NK_ID", - /* 335 */ "expr_or_subquery ::= expression", - /* 336 */ "expr_or_subquery ::= subquery", - /* 337 */ "expression ::= literal", - /* 338 */ "expression ::= pseudo_column", - /* 339 */ "expression ::= column_reference", - /* 340 */ "expression ::= function_expression", - /* 341 */ "expression ::= case_when_expression", - /* 342 */ "expression ::= NK_LP expression NK_RP", - /* 343 */ "expression ::= NK_PLUS expr_or_subquery", - /* 344 */ "expression ::= NK_MINUS expr_or_subquery", - /* 345 */ "expression ::= expr_or_subquery NK_PLUS expr_or_subquery", - /* 346 */ "expression ::= expr_or_subquery NK_MINUS expr_or_subquery", - /* 347 */ "expression ::= expr_or_subquery NK_STAR expr_or_subquery", - /* 348 */ "expression ::= expr_or_subquery NK_SLASH expr_or_subquery", - /* 349 */ "expression ::= expr_or_subquery NK_REM expr_or_subquery", - /* 350 */ "expression ::= column_reference NK_ARROW NK_STRING", - /* 351 */ "expression ::= expr_or_subquery NK_BITAND expr_or_subquery", - /* 352 */ "expression ::= expr_or_subquery NK_BITOR expr_or_subquery", - /* 353 */ "expression_list ::= expr_or_subquery", - /* 354 */ "expression_list ::= expression_list NK_COMMA expr_or_subquery", - /* 355 */ "column_reference ::= column_name", - /* 356 */ "column_reference ::= table_name NK_DOT column_name", - /* 357 */ "pseudo_column ::= ROWTS", - /* 358 */ "pseudo_column ::= TBNAME", - /* 359 */ "pseudo_column ::= table_name NK_DOT TBNAME", - /* 360 */ "pseudo_column ::= QSTART", - /* 361 */ "pseudo_column ::= QEND", - /* 362 */ "pseudo_column ::= QDURATION", - /* 363 */ "pseudo_column ::= WSTART", - /* 364 */ "pseudo_column ::= WEND", - /* 365 */ "pseudo_column ::= WDURATION", - /* 366 */ "pseudo_column ::= IROWTS", - /* 367 */ "pseudo_column ::= QTAGS", - /* 368 */ "function_expression ::= function_name NK_LP expression_list NK_RP", - /* 369 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", - /* 370 */ "function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP", - /* 371 */ "function_expression ::= literal_func", - /* 372 */ "literal_func ::= noarg_func NK_LP NK_RP", - /* 373 */ "literal_func ::= NOW", - /* 374 */ "noarg_func ::= NOW", - /* 375 */ "noarg_func ::= TODAY", - /* 376 */ "noarg_func ::= TIMEZONE", - /* 377 */ "noarg_func ::= DATABASE", - /* 378 */ "noarg_func ::= CLIENT_VERSION", - /* 379 */ "noarg_func ::= SERVER_VERSION", - /* 380 */ "noarg_func ::= SERVER_STATUS", - /* 381 */ "noarg_func ::= CURRENT_USER", - /* 382 */ "noarg_func ::= USER", - /* 383 */ "star_func ::= COUNT", - /* 384 */ "star_func ::= FIRST", - /* 385 */ "star_func ::= LAST", - /* 386 */ "star_func ::= LAST_ROW", - /* 387 */ "star_func_para_list ::= NK_STAR", - /* 388 */ "star_func_para_list ::= other_para_list", - /* 389 */ "other_para_list ::= star_func_para", - /* 390 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", - /* 391 */ "star_func_para ::= expr_or_subquery", - /* 392 */ "star_func_para ::= table_name NK_DOT NK_STAR", - /* 393 */ "case_when_expression ::= CASE when_then_list case_when_else_opt END", - /* 394 */ "case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END", - /* 395 */ "when_then_list ::= when_then_expr", - /* 396 */ "when_then_list ::= when_then_list when_then_expr", - /* 397 */ "when_then_expr ::= WHEN common_expression THEN common_expression", - /* 398 */ "case_when_else_opt ::=", - /* 399 */ "case_when_else_opt ::= ELSE common_expression", - /* 400 */ "predicate ::= expr_or_subquery compare_op expr_or_subquery", - /* 401 */ "predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery", - /* 402 */ "predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery", - /* 403 */ "predicate ::= expr_or_subquery IS NULL", - /* 404 */ "predicate ::= expr_or_subquery IS NOT NULL", - /* 405 */ "predicate ::= expr_or_subquery in_op in_predicate_value", - /* 406 */ "compare_op ::= NK_LT", - /* 407 */ "compare_op ::= NK_GT", - /* 408 */ "compare_op ::= NK_LE", - /* 409 */ "compare_op ::= NK_GE", - /* 410 */ "compare_op ::= NK_NE", - /* 411 */ "compare_op ::= NK_EQ", - /* 412 */ "compare_op ::= LIKE", - /* 413 */ "compare_op ::= NOT LIKE", - /* 414 */ "compare_op ::= MATCH", - /* 415 */ "compare_op ::= NMATCH", - /* 416 */ "compare_op ::= CONTAINS", - /* 417 */ "in_op ::= IN", - /* 418 */ "in_op ::= NOT IN", - /* 419 */ "in_predicate_value ::= NK_LP literal_list NK_RP", - /* 420 */ "boolean_value_expression ::= boolean_primary", - /* 421 */ "boolean_value_expression ::= NOT boolean_primary", - /* 422 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 423 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 424 */ "boolean_primary ::= predicate", - /* 425 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 426 */ "common_expression ::= expr_or_subquery", - /* 427 */ "common_expression ::= boolean_value_expression", - /* 428 */ "from_clause_opt ::=", - /* 429 */ "from_clause_opt ::= FROM table_reference_list", - /* 430 */ "table_reference_list ::= table_reference", - /* 431 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 432 */ "table_reference ::= table_primary", - /* 433 */ "table_reference ::= joined_table", - /* 434 */ "table_primary ::= table_name alias_opt", - /* 435 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 436 */ "table_primary ::= subquery alias_opt", - /* 437 */ "table_primary ::= parenthesized_joined_table", - /* 438 */ "alias_opt ::=", - /* 439 */ "alias_opt ::= table_alias", - /* 440 */ "alias_opt ::= AS table_alias", - /* 441 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 442 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 443 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 444 */ "join_type ::=", - /* 445 */ "join_type ::= INNER", - /* 446 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 447 */ "set_quantifier_opt ::=", - /* 448 */ "set_quantifier_opt ::= DISTINCT", - /* 449 */ "set_quantifier_opt ::= ALL", - /* 450 */ "select_list ::= select_item", - /* 451 */ "select_list ::= select_list NK_COMMA select_item", - /* 452 */ "select_item ::= NK_STAR", - /* 453 */ "select_item ::= common_expression", - /* 454 */ "select_item ::= common_expression column_alias", - /* 455 */ "select_item ::= common_expression AS column_alias", - /* 456 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 457 */ "where_clause_opt ::=", - /* 458 */ "where_clause_opt ::= WHERE search_condition", - /* 459 */ "partition_by_clause_opt ::=", - /* 460 */ "partition_by_clause_opt ::= PARTITION BY partition_list", - /* 461 */ "partition_list ::= partition_item", - /* 462 */ "partition_list ::= partition_list NK_COMMA partition_item", - /* 463 */ "partition_item ::= expr_or_subquery", - /* 464 */ "partition_item ::= expr_or_subquery column_alias", - /* 465 */ "partition_item ::= expr_or_subquery AS column_alias", - /* 466 */ "twindow_clause_opt ::=", - /* 467 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 468 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP", - /* 469 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 470 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 471 */ "sliding_opt ::=", - /* 472 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 473 */ "fill_opt ::=", - /* 474 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 475 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 476 */ "fill_mode ::= NONE", - /* 477 */ "fill_mode ::= PREV", - /* 478 */ "fill_mode ::= NULL", - /* 479 */ "fill_mode ::= LINEAR", - /* 480 */ "fill_mode ::= NEXT", - /* 481 */ "group_by_clause_opt ::=", - /* 482 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 483 */ "group_by_list ::= expr_or_subquery", - /* 484 */ "group_by_list ::= group_by_list NK_COMMA expr_or_subquery", - /* 485 */ "having_clause_opt ::=", - /* 486 */ "having_clause_opt ::= HAVING search_condition", - /* 487 */ "range_opt ::=", - /* 488 */ "range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP", - /* 489 */ "every_opt ::=", - /* 490 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", - /* 491 */ "query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 492 */ "query_simple ::= query_specification", - /* 493 */ "query_simple ::= union_query_expression", - /* 494 */ "union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery", - /* 495 */ "union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery", - /* 496 */ "query_simple_or_subquery ::= query_simple", - /* 497 */ "query_simple_or_subquery ::= subquery", - /* 498 */ "query_or_subquery ::= query_expression", - /* 499 */ "query_or_subquery ::= subquery", - /* 500 */ "order_by_clause_opt ::=", - /* 501 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 502 */ "slimit_clause_opt ::=", - /* 503 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 504 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 505 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 506 */ "limit_clause_opt ::=", - /* 507 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 508 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 509 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 510 */ "subquery ::= NK_LP query_expression NK_RP", - /* 511 */ "subquery ::= NK_LP subquery NK_RP", - /* 512 */ "search_condition ::= common_expression", - /* 513 */ "sort_specification_list ::= sort_specification", - /* 514 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 515 */ "sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt", - /* 516 */ "ordering_specification_opt ::=", - /* 517 */ "ordering_specification_opt ::= ASC", - /* 518 */ "ordering_specification_opt ::= DESC", - /* 519 */ "null_ordering_opt ::=", - /* 520 */ "null_ordering_opt ::= NULLS FIRST", - /* 521 */ "null_ordering_opt ::= NULLS LAST", + /* 113 */ "alter_db_option ::= REPLICA NK_INTEGER", + /* 114 */ "alter_db_option ::= STRICT NK_STRING", + /* 115 */ "alter_db_option ::= WAL_LEVEL NK_INTEGER", + /* 116 */ "alter_db_option ::= STT_TRIGGER NK_INTEGER", + /* 117 */ "integer_list ::= NK_INTEGER", + /* 118 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", + /* 119 */ "variable_list ::= NK_VARIABLE", + /* 120 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", + /* 121 */ "retention_list ::= retention", + /* 122 */ "retention_list ::= retention_list NK_COMMA retention", + /* 123 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", + /* 124 */ "speed_opt ::=", + /* 125 */ "speed_opt ::= MAX_SPEED NK_INTEGER", + /* 126 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", + /* 127 */ "cmd ::= CREATE TABLE multi_create_clause", + /* 128 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", + /* 129 */ "cmd ::= DROP TABLE multi_drop_clause", + /* 130 */ "cmd ::= DROP STABLE exists_opt full_table_name", + /* 131 */ "cmd ::= ALTER TABLE alter_table_clause", + /* 132 */ "cmd ::= ALTER STABLE alter_table_clause", + /* 133 */ "alter_table_clause ::= full_table_name alter_table_options", + /* 134 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", + /* 135 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", + /* 136 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", + /* 137 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", + /* 138 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", + /* 139 */ "alter_table_clause ::= full_table_name DROP TAG column_name", + /* 140 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", + /* 141 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", + /* 142 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal", + /* 143 */ "multi_create_clause ::= create_subtable_clause", + /* 144 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", + /* 145 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options", + /* 146 */ "multi_drop_clause ::= drop_table_clause", + /* 147 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", + /* 148 */ "drop_table_clause ::= exists_opt full_table_name", + /* 149 */ "specific_cols_opt ::=", + /* 150 */ "specific_cols_opt ::= NK_LP col_name_list NK_RP", + /* 151 */ "full_table_name ::= table_name", + /* 152 */ "full_table_name ::= db_name NK_DOT table_name", + /* 153 */ "column_def_list ::= column_def", + /* 154 */ "column_def_list ::= column_def_list NK_COMMA column_def", + /* 155 */ "column_def ::= column_name type_name", + /* 156 */ "column_def ::= column_name type_name COMMENT NK_STRING", + /* 157 */ "type_name ::= BOOL", + /* 158 */ "type_name ::= TINYINT", + /* 159 */ "type_name ::= SMALLINT", + /* 160 */ "type_name ::= INT", + /* 161 */ "type_name ::= INTEGER", + /* 162 */ "type_name ::= BIGINT", + /* 163 */ "type_name ::= FLOAT", + /* 164 */ "type_name ::= DOUBLE", + /* 165 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", + /* 166 */ "type_name ::= TIMESTAMP", + /* 167 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", + /* 168 */ "type_name ::= TINYINT UNSIGNED", + /* 169 */ "type_name ::= SMALLINT UNSIGNED", + /* 170 */ "type_name ::= INT UNSIGNED", + /* 171 */ "type_name ::= BIGINT UNSIGNED", + /* 172 */ "type_name ::= JSON", + /* 173 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", + /* 174 */ "type_name ::= MEDIUMBLOB", + /* 175 */ "type_name ::= BLOB", + /* 176 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", + /* 177 */ "type_name ::= DECIMAL", + /* 178 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", + /* 179 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", + /* 180 */ "tags_def_opt ::=", + /* 181 */ "tags_def_opt ::= tags_def", + /* 182 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", + /* 183 */ "table_options ::=", + /* 184 */ "table_options ::= table_options COMMENT NK_STRING", + /* 185 */ "table_options ::= table_options MAX_DELAY duration_list", + /* 186 */ "table_options ::= table_options WATERMARK duration_list", + /* 187 */ "table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP", + /* 188 */ "table_options ::= table_options TTL NK_INTEGER", + /* 189 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", + /* 190 */ "alter_table_options ::= alter_table_option", + /* 191 */ "alter_table_options ::= alter_table_options alter_table_option", + /* 192 */ "alter_table_option ::= COMMENT NK_STRING", + /* 193 */ "alter_table_option ::= TTL NK_INTEGER", + /* 194 */ "duration_list ::= duration_literal", + /* 195 */ "duration_list ::= duration_list NK_COMMA duration_literal", + /* 196 */ "rollup_func_list ::= rollup_func_name", + /* 197 */ "rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name", + /* 198 */ "rollup_func_name ::= function_name", + /* 199 */ "rollup_func_name ::= FIRST", + /* 200 */ "rollup_func_name ::= LAST", + /* 201 */ "col_name_list ::= col_name", + /* 202 */ "col_name_list ::= col_name_list NK_COMMA col_name", + /* 203 */ "col_name ::= column_name", + /* 204 */ "cmd ::= SHOW DNODES", + /* 205 */ "cmd ::= SHOW USERS", + /* 206 */ "cmd ::= SHOW DATABASES", + /* 207 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", + /* 208 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", + /* 209 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", + /* 210 */ "cmd ::= SHOW MNODES", + /* 211 */ "cmd ::= SHOW QNODES", + /* 212 */ "cmd ::= SHOW FUNCTIONS", + /* 213 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", + /* 214 */ "cmd ::= SHOW STREAMS", + /* 215 */ "cmd ::= SHOW ACCOUNTS", + /* 216 */ "cmd ::= SHOW APPS", + /* 217 */ "cmd ::= SHOW CONNECTIONS", + /* 218 */ "cmd ::= SHOW LICENCES", + /* 219 */ "cmd ::= SHOW GRANTS", + /* 220 */ "cmd ::= SHOW CREATE DATABASE db_name", + /* 221 */ "cmd ::= SHOW CREATE TABLE full_table_name", + /* 222 */ "cmd ::= SHOW CREATE STABLE full_table_name", + /* 223 */ "cmd ::= SHOW QUERIES", + /* 224 */ "cmd ::= SHOW SCORES", + /* 225 */ "cmd ::= SHOW TOPICS", + /* 226 */ "cmd ::= SHOW VARIABLES", + /* 227 */ "cmd ::= SHOW LOCAL VARIABLES", + /* 228 */ "cmd ::= SHOW DNODE NK_INTEGER VARIABLES", + /* 229 */ "cmd ::= SHOW BNODES", + /* 230 */ "cmd ::= SHOW SNODES", + /* 231 */ "cmd ::= SHOW CLUSTER", + /* 232 */ "cmd ::= SHOW TRANSACTIONS", + /* 233 */ "cmd ::= SHOW TABLE DISTRIBUTED full_table_name", + /* 234 */ "cmd ::= SHOW CONSUMERS", + /* 235 */ "cmd ::= SHOW SUBSCRIPTIONS", + /* 236 */ "cmd ::= SHOW TAGS FROM table_name_cond from_db_opt", + /* 237 */ "cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt", + /* 238 */ "cmd ::= SHOW VNODES NK_INTEGER", + /* 239 */ "cmd ::= SHOW VNODES NK_STRING", + /* 240 */ "db_name_cond_opt ::=", + /* 241 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 242 */ "like_pattern_opt ::=", + /* 243 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 244 */ "table_name_cond ::= table_name", + /* 245 */ "from_db_opt ::=", + /* 246 */ "from_db_opt ::= FROM db_name", + /* 247 */ "cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options", + /* 248 */ "cmd ::= DROP INDEX exists_opt full_table_name", + /* 249 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt", + /* 250 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt", + /* 251 */ "func_list ::= func", + /* 252 */ "func_list ::= func_list NK_COMMA func", + /* 253 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 254 */ "sma_stream_opt ::=", + /* 255 */ "sma_stream_opt ::= stream_options WATERMARK duration_literal", + /* 256 */ "sma_stream_opt ::= stream_options MAX_DELAY duration_literal", + /* 257 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery", + /* 258 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", + /* 259 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name", + /* 260 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", + /* 261 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name", + /* 262 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 263 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", + /* 264 */ "cmd ::= DESC full_table_name", + /* 265 */ "cmd ::= DESCRIBE full_table_name", + /* 266 */ "cmd ::= RESET QUERY CACHE", + /* 267 */ "cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery", + /* 268 */ "analyze_opt ::=", + /* 269 */ "analyze_opt ::= ANALYZE", + /* 270 */ "explain_options ::=", + /* 271 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 272 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 273 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", + /* 274 */ "cmd ::= DROP FUNCTION exists_opt function_name", + /* 275 */ "agg_func_opt ::=", + /* 276 */ "agg_func_opt ::= AGGREGATE", + /* 277 */ "bufsize_opt ::=", + /* 278 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", + /* 279 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery", + /* 280 */ "cmd ::= DROP STREAM exists_opt stream_name", + /* 281 */ "stream_options ::=", + /* 282 */ "stream_options ::= stream_options TRIGGER AT_ONCE", + /* 283 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", + /* 284 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", + /* 285 */ "stream_options ::= stream_options WATERMARK duration_literal", + /* 286 */ "stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER", + /* 287 */ "subtable_opt ::=", + /* 288 */ "subtable_opt ::= SUBTABLE NK_LP expression NK_RP", + /* 289 */ "cmd ::= KILL CONNECTION NK_INTEGER", + /* 290 */ "cmd ::= KILL QUERY NK_STRING", + /* 291 */ "cmd ::= KILL TRANSACTION NK_INTEGER", + /* 292 */ "cmd ::= BALANCE VGROUP", + /* 293 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 294 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", + /* 295 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 296 */ "dnode_list ::= DNODE NK_INTEGER", + /* 297 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", + /* 298 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", + /* 299 */ "cmd ::= query_or_subquery", + /* 300 */ "cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery", + /* 301 */ "cmd ::= INSERT INTO full_table_name query_or_subquery", + /* 302 */ "literal ::= NK_INTEGER", + /* 303 */ "literal ::= NK_FLOAT", + /* 304 */ "literal ::= NK_STRING", + /* 305 */ "literal ::= NK_BOOL", + /* 306 */ "literal ::= TIMESTAMP NK_STRING", + /* 307 */ "literal ::= duration_literal", + /* 308 */ "literal ::= NULL", + /* 309 */ "literal ::= NK_QUESTION", + /* 310 */ "duration_literal ::= NK_VARIABLE", + /* 311 */ "signed ::= NK_INTEGER", + /* 312 */ "signed ::= NK_PLUS NK_INTEGER", + /* 313 */ "signed ::= NK_MINUS NK_INTEGER", + /* 314 */ "signed ::= NK_FLOAT", + /* 315 */ "signed ::= NK_PLUS NK_FLOAT", + /* 316 */ "signed ::= NK_MINUS NK_FLOAT", + /* 317 */ "signed_literal ::= signed", + /* 318 */ "signed_literal ::= NK_STRING", + /* 319 */ "signed_literal ::= NK_BOOL", + /* 320 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 321 */ "signed_literal ::= duration_literal", + /* 322 */ "signed_literal ::= NULL", + /* 323 */ "signed_literal ::= literal_func", + /* 324 */ "signed_literal ::= NK_QUESTION", + /* 325 */ "literal_list ::= signed_literal", + /* 326 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 327 */ "db_name ::= NK_ID", + /* 328 */ "table_name ::= NK_ID", + /* 329 */ "column_name ::= NK_ID", + /* 330 */ "function_name ::= NK_ID", + /* 331 */ "table_alias ::= NK_ID", + /* 332 */ "column_alias ::= NK_ID", + /* 333 */ "user_name ::= NK_ID", + /* 334 */ "topic_name ::= NK_ID", + /* 335 */ "stream_name ::= NK_ID", + /* 336 */ "cgroup_name ::= NK_ID", + /* 337 */ "expr_or_subquery ::= expression", + /* 338 */ "expr_or_subquery ::= subquery", + /* 339 */ "expression ::= literal", + /* 340 */ "expression ::= pseudo_column", + /* 341 */ "expression ::= column_reference", + /* 342 */ "expression ::= function_expression", + /* 343 */ "expression ::= case_when_expression", + /* 344 */ "expression ::= NK_LP expression NK_RP", + /* 345 */ "expression ::= NK_PLUS expr_or_subquery", + /* 346 */ "expression ::= NK_MINUS expr_or_subquery", + /* 347 */ "expression ::= expr_or_subquery NK_PLUS expr_or_subquery", + /* 348 */ "expression ::= expr_or_subquery NK_MINUS expr_or_subquery", + /* 349 */ "expression ::= expr_or_subquery NK_STAR expr_or_subquery", + /* 350 */ "expression ::= expr_or_subquery NK_SLASH expr_or_subquery", + /* 351 */ "expression ::= expr_or_subquery NK_REM expr_or_subquery", + /* 352 */ "expression ::= column_reference NK_ARROW NK_STRING", + /* 353 */ "expression ::= expr_or_subquery NK_BITAND expr_or_subquery", + /* 354 */ "expression ::= expr_or_subquery NK_BITOR expr_or_subquery", + /* 355 */ "expression_list ::= expr_or_subquery", + /* 356 */ "expression_list ::= expression_list NK_COMMA expr_or_subquery", + /* 357 */ "column_reference ::= column_name", + /* 358 */ "column_reference ::= table_name NK_DOT column_name", + /* 359 */ "pseudo_column ::= ROWTS", + /* 360 */ "pseudo_column ::= TBNAME", + /* 361 */ "pseudo_column ::= table_name NK_DOT TBNAME", + /* 362 */ "pseudo_column ::= QSTART", + /* 363 */ "pseudo_column ::= QEND", + /* 364 */ "pseudo_column ::= QDURATION", + /* 365 */ "pseudo_column ::= WSTART", + /* 366 */ "pseudo_column ::= WEND", + /* 367 */ "pseudo_column ::= WDURATION", + /* 368 */ "pseudo_column ::= IROWTS", + /* 369 */ "pseudo_column ::= QTAGS", + /* 370 */ "function_expression ::= function_name NK_LP expression_list NK_RP", + /* 371 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", + /* 372 */ "function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP", + /* 373 */ "function_expression ::= literal_func", + /* 374 */ "literal_func ::= noarg_func NK_LP NK_RP", + /* 375 */ "literal_func ::= NOW", + /* 376 */ "noarg_func ::= NOW", + /* 377 */ "noarg_func ::= TODAY", + /* 378 */ "noarg_func ::= TIMEZONE", + /* 379 */ "noarg_func ::= DATABASE", + /* 380 */ "noarg_func ::= CLIENT_VERSION", + /* 381 */ "noarg_func ::= SERVER_VERSION", + /* 382 */ "noarg_func ::= SERVER_STATUS", + /* 383 */ "noarg_func ::= CURRENT_USER", + /* 384 */ "noarg_func ::= USER", + /* 385 */ "star_func ::= COUNT", + /* 386 */ "star_func ::= FIRST", + /* 387 */ "star_func ::= LAST", + /* 388 */ "star_func ::= LAST_ROW", + /* 389 */ "star_func_para_list ::= NK_STAR", + /* 390 */ "star_func_para_list ::= other_para_list", + /* 391 */ "other_para_list ::= star_func_para", + /* 392 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", + /* 393 */ "star_func_para ::= expr_or_subquery", + /* 394 */ "star_func_para ::= table_name NK_DOT NK_STAR", + /* 395 */ "case_when_expression ::= CASE when_then_list case_when_else_opt END", + /* 396 */ "case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END", + /* 397 */ "when_then_list ::= when_then_expr", + /* 398 */ "when_then_list ::= when_then_list when_then_expr", + /* 399 */ "when_then_expr ::= WHEN common_expression THEN common_expression", + /* 400 */ "case_when_else_opt ::=", + /* 401 */ "case_when_else_opt ::= ELSE common_expression", + /* 402 */ "predicate ::= expr_or_subquery compare_op expr_or_subquery", + /* 403 */ "predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery", + /* 404 */ "predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery", + /* 405 */ "predicate ::= expr_or_subquery IS NULL", + /* 406 */ "predicate ::= expr_or_subquery IS NOT NULL", + /* 407 */ "predicate ::= expr_or_subquery in_op in_predicate_value", + /* 408 */ "compare_op ::= NK_LT", + /* 409 */ "compare_op ::= NK_GT", + /* 410 */ "compare_op ::= NK_LE", + /* 411 */ "compare_op ::= NK_GE", + /* 412 */ "compare_op ::= NK_NE", + /* 413 */ "compare_op ::= NK_EQ", + /* 414 */ "compare_op ::= LIKE", + /* 415 */ "compare_op ::= NOT LIKE", + /* 416 */ "compare_op ::= MATCH", + /* 417 */ "compare_op ::= NMATCH", + /* 418 */ "compare_op ::= CONTAINS", + /* 419 */ "in_op ::= IN", + /* 420 */ "in_op ::= NOT IN", + /* 421 */ "in_predicate_value ::= NK_LP literal_list NK_RP", + /* 422 */ "boolean_value_expression ::= boolean_primary", + /* 423 */ "boolean_value_expression ::= NOT boolean_primary", + /* 424 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 425 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 426 */ "boolean_primary ::= predicate", + /* 427 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 428 */ "common_expression ::= expr_or_subquery", + /* 429 */ "common_expression ::= boolean_value_expression", + /* 430 */ "from_clause_opt ::=", + /* 431 */ "from_clause_opt ::= FROM table_reference_list", + /* 432 */ "table_reference_list ::= table_reference", + /* 433 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 434 */ "table_reference ::= table_primary", + /* 435 */ "table_reference ::= joined_table", + /* 436 */ "table_primary ::= table_name alias_opt", + /* 437 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 438 */ "table_primary ::= subquery alias_opt", + /* 439 */ "table_primary ::= parenthesized_joined_table", + /* 440 */ "alias_opt ::=", + /* 441 */ "alias_opt ::= table_alias", + /* 442 */ "alias_opt ::= AS table_alias", + /* 443 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 444 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 445 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 446 */ "join_type ::=", + /* 447 */ "join_type ::= INNER", + /* 448 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 449 */ "set_quantifier_opt ::=", + /* 450 */ "set_quantifier_opt ::= DISTINCT", + /* 451 */ "set_quantifier_opt ::= ALL", + /* 452 */ "select_list ::= select_item", + /* 453 */ "select_list ::= select_list NK_COMMA select_item", + /* 454 */ "select_item ::= NK_STAR", + /* 455 */ "select_item ::= common_expression", + /* 456 */ "select_item ::= common_expression column_alias", + /* 457 */ "select_item ::= common_expression AS column_alias", + /* 458 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 459 */ "where_clause_opt ::=", + /* 460 */ "where_clause_opt ::= WHERE search_condition", + /* 461 */ "partition_by_clause_opt ::=", + /* 462 */ "partition_by_clause_opt ::= PARTITION BY partition_list", + /* 463 */ "partition_list ::= partition_item", + /* 464 */ "partition_list ::= partition_list NK_COMMA partition_item", + /* 465 */ "partition_item ::= expr_or_subquery", + /* 466 */ "partition_item ::= expr_or_subquery column_alias", + /* 467 */ "partition_item ::= expr_or_subquery AS column_alias", + /* 468 */ "twindow_clause_opt ::=", + /* 469 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 470 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP", + /* 471 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 472 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 473 */ "sliding_opt ::=", + /* 474 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 475 */ "fill_opt ::=", + /* 476 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 477 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 478 */ "fill_mode ::= NONE", + /* 479 */ "fill_mode ::= PREV", + /* 480 */ "fill_mode ::= NULL", + /* 481 */ "fill_mode ::= LINEAR", + /* 482 */ "fill_mode ::= NEXT", + /* 483 */ "group_by_clause_opt ::=", + /* 484 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 485 */ "group_by_list ::= expr_or_subquery", + /* 486 */ "group_by_list ::= group_by_list NK_COMMA expr_or_subquery", + /* 487 */ "having_clause_opt ::=", + /* 488 */ "having_clause_opt ::= HAVING search_condition", + /* 489 */ "range_opt ::=", + /* 490 */ "range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP", + /* 491 */ "every_opt ::=", + /* 492 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", + /* 493 */ "query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 494 */ "query_simple ::= query_specification", + /* 495 */ "query_simple ::= union_query_expression", + /* 496 */ "union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery", + /* 497 */ "union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery", + /* 498 */ "query_simple_or_subquery ::= query_simple", + /* 499 */ "query_simple_or_subquery ::= subquery", + /* 500 */ "query_or_subquery ::= query_expression", + /* 501 */ "query_or_subquery ::= subquery", + /* 502 */ "order_by_clause_opt ::=", + /* 503 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 504 */ "slimit_clause_opt ::=", + /* 505 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 506 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 507 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 508 */ "limit_clause_opt ::=", + /* 509 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 510 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 511 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 512 */ "subquery ::= NK_LP query_expression NK_RP", + /* 513 */ "subquery ::= NK_LP subquery NK_RP", + /* 514 */ "search_condition ::= common_expression", + /* 515 */ "sort_specification_list ::= sort_specification", + /* 516 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 517 */ "sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt", + /* 518 */ "ordering_specification_opt ::=", + /* 519 */ "ordering_specification_opt ::= ASC", + /* 520 */ "ordering_specification_opt ::= DESC", + /* 521 */ "null_ordering_opt ::=", + /* 522 */ "null_ordering_opt ::= NULLS FIRST", + /* 523 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -3087,415 +3089,417 @@ static const struct { { 338, -2 }, /* (110) alter_db_option ::= KEEP integer_list */ { 338, -2 }, /* (111) alter_db_option ::= KEEP variable_list */ { 338, -2 }, /* (112) alter_db_option ::= PAGES NK_INTEGER */ - { 338, -2 }, /* (113) alter_db_option ::= WAL_LEVEL NK_INTEGER */ - { 338, -2 }, /* (114) alter_db_option ::= STT_TRIGGER NK_INTEGER */ - { 335, -1 }, /* (115) integer_list ::= NK_INTEGER */ - { 335, -3 }, /* (116) integer_list ::= integer_list NK_COMMA NK_INTEGER */ - { 336, -1 }, /* (117) variable_list ::= NK_VARIABLE */ - { 336, -3 }, /* (118) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ - { 337, -1 }, /* (119) retention_list ::= retention */ - { 337, -3 }, /* (120) retention_list ::= retention_list NK_COMMA retention */ - { 339, -3 }, /* (121) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ - { 334, 0 }, /* (122) speed_opt ::= */ - { 334, -2 }, /* (123) speed_opt ::= MAX_SPEED NK_INTEGER */ - { 317, -9 }, /* (124) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 317, -3 }, /* (125) cmd ::= CREATE TABLE multi_create_clause */ - { 317, -9 }, /* (126) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 317, -3 }, /* (127) cmd ::= DROP TABLE multi_drop_clause */ - { 317, -4 }, /* (128) cmd ::= DROP STABLE exists_opt full_table_name */ - { 317, -3 }, /* (129) cmd ::= ALTER TABLE alter_table_clause */ - { 317, -3 }, /* (130) cmd ::= ALTER STABLE alter_table_clause */ - { 347, -2 }, /* (131) alter_table_clause ::= full_table_name alter_table_options */ - { 347, -5 }, /* (132) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 347, -4 }, /* (133) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 347, -5 }, /* (134) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 347, -5 }, /* (135) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 347, -5 }, /* (136) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 347, -4 }, /* (137) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 347, -5 }, /* (138) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 347, -5 }, /* (139) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 347, -6 }, /* (140) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ - { 344, -1 }, /* (141) multi_create_clause ::= create_subtable_clause */ - { 344, -2 }, /* (142) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 352, -10 }, /* (143) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ - { 346, -1 }, /* (144) multi_drop_clause ::= drop_table_clause */ - { 346, -2 }, /* (145) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 355, -2 }, /* (146) drop_table_clause ::= exists_opt full_table_name */ - { 353, 0 }, /* (147) specific_cols_opt ::= */ - { 353, -3 }, /* (148) specific_cols_opt ::= NK_LP col_name_list NK_RP */ - { 340, -1 }, /* (149) full_table_name ::= table_name */ - { 340, -3 }, /* (150) full_table_name ::= db_name NK_DOT table_name */ - { 341, -1 }, /* (151) column_def_list ::= column_def */ - { 341, -3 }, /* (152) column_def_list ::= column_def_list NK_COMMA column_def */ - { 358, -2 }, /* (153) column_def ::= column_name type_name */ - { 358, -4 }, /* (154) column_def ::= column_name type_name COMMENT NK_STRING */ - { 350, -1 }, /* (155) type_name ::= BOOL */ - { 350, -1 }, /* (156) type_name ::= TINYINT */ - { 350, -1 }, /* (157) type_name ::= SMALLINT */ - { 350, -1 }, /* (158) type_name ::= INT */ - { 350, -1 }, /* (159) type_name ::= INTEGER */ - { 350, -1 }, /* (160) type_name ::= BIGINT */ - { 350, -1 }, /* (161) type_name ::= FLOAT */ - { 350, -1 }, /* (162) type_name ::= DOUBLE */ - { 350, -4 }, /* (163) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 350, -1 }, /* (164) type_name ::= TIMESTAMP */ - { 350, -4 }, /* (165) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 350, -2 }, /* (166) type_name ::= TINYINT UNSIGNED */ - { 350, -2 }, /* (167) type_name ::= SMALLINT UNSIGNED */ - { 350, -2 }, /* (168) type_name ::= INT UNSIGNED */ - { 350, -2 }, /* (169) type_name ::= BIGINT UNSIGNED */ - { 350, -1 }, /* (170) type_name ::= JSON */ - { 350, -4 }, /* (171) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 350, -1 }, /* (172) type_name ::= MEDIUMBLOB */ - { 350, -1 }, /* (173) type_name ::= BLOB */ - { 350, -4 }, /* (174) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 350, -1 }, /* (175) type_name ::= DECIMAL */ - { 350, -4 }, /* (176) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 350, -6 }, /* (177) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 342, 0 }, /* (178) tags_def_opt ::= */ - { 342, -1 }, /* (179) tags_def_opt ::= tags_def */ - { 345, -4 }, /* (180) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 343, 0 }, /* (181) table_options ::= */ - { 343, -3 }, /* (182) table_options ::= table_options COMMENT NK_STRING */ - { 343, -3 }, /* (183) table_options ::= table_options MAX_DELAY duration_list */ - { 343, -3 }, /* (184) table_options ::= table_options WATERMARK duration_list */ - { 343, -5 }, /* (185) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ - { 343, -3 }, /* (186) table_options ::= table_options TTL NK_INTEGER */ - { 343, -5 }, /* (187) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 348, -1 }, /* (188) alter_table_options ::= alter_table_option */ - { 348, -2 }, /* (189) alter_table_options ::= alter_table_options alter_table_option */ - { 361, -2 }, /* (190) alter_table_option ::= COMMENT NK_STRING */ - { 361, -2 }, /* (191) alter_table_option ::= TTL NK_INTEGER */ - { 359, -1 }, /* (192) duration_list ::= duration_literal */ - { 359, -3 }, /* (193) duration_list ::= duration_list NK_COMMA duration_literal */ - { 360, -1 }, /* (194) rollup_func_list ::= rollup_func_name */ - { 360, -3 }, /* (195) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ - { 363, -1 }, /* (196) rollup_func_name ::= function_name */ - { 363, -1 }, /* (197) rollup_func_name ::= FIRST */ - { 363, -1 }, /* (198) rollup_func_name ::= LAST */ - { 356, -1 }, /* (199) col_name_list ::= col_name */ - { 356, -3 }, /* (200) col_name_list ::= col_name_list NK_COMMA col_name */ - { 365, -1 }, /* (201) col_name ::= column_name */ - { 317, -2 }, /* (202) cmd ::= SHOW DNODES */ - { 317, -2 }, /* (203) cmd ::= SHOW USERS */ - { 317, -2 }, /* (204) cmd ::= SHOW DATABASES */ - { 317, -4 }, /* (205) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 317, -4 }, /* (206) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 317, -3 }, /* (207) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 317, -2 }, /* (208) cmd ::= SHOW MNODES */ - { 317, -2 }, /* (209) cmd ::= SHOW QNODES */ - { 317, -2 }, /* (210) cmd ::= SHOW FUNCTIONS */ - { 317, -5 }, /* (211) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 317, -2 }, /* (212) cmd ::= SHOW STREAMS */ - { 317, -2 }, /* (213) cmd ::= SHOW ACCOUNTS */ - { 317, -2 }, /* (214) cmd ::= SHOW APPS */ - { 317, -2 }, /* (215) cmd ::= SHOW CONNECTIONS */ - { 317, -2 }, /* (216) cmd ::= SHOW LICENCES */ - { 317, -2 }, /* (217) cmd ::= SHOW GRANTS */ - { 317, -4 }, /* (218) cmd ::= SHOW CREATE DATABASE db_name */ - { 317, -4 }, /* (219) cmd ::= SHOW CREATE TABLE full_table_name */ - { 317, -4 }, /* (220) cmd ::= SHOW CREATE STABLE full_table_name */ - { 317, -2 }, /* (221) cmd ::= SHOW QUERIES */ - { 317, -2 }, /* (222) cmd ::= SHOW SCORES */ - { 317, -2 }, /* (223) cmd ::= SHOW TOPICS */ - { 317, -2 }, /* (224) cmd ::= SHOW VARIABLES */ - { 317, -3 }, /* (225) cmd ::= SHOW LOCAL VARIABLES */ - { 317, -4 }, /* (226) cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ - { 317, -2 }, /* (227) cmd ::= SHOW BNODES */ - { 317, -2 }, /* (228) cmd ::= SHOW SNODES */ - { 317, -2 }, /* (229) cmd ::= SHOW CLUSTER */ - { 317, -2 }, /* (230) cmd ::= SHOW TRANSACTIONS */ - { 317, -4 }, /* (231) cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ - { 317, -2 }, /* (232) cmd ::= SHOW CONSUMERS */ - { 317, -2 }, /* (233) cmd ::= SHOW SUBSCRIPTIONS */ - { 317, -5 }, /* (234) cmd ::= SHOW TAGS FROM table_name_cond from_db_opt */ - { 317, -6 }, /* (235) cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt */ - { 317, -3 }, /* (236) cmd ::= SHOW VNODES NK_INTEGER */ - { 317, -3 }, /* (237) cmd ::= SHOW VNODES NK_STRING */ - { 366, 0 }, /* (238) db_name_cond_opt ::= */ - { 366, -2 }, /* (239) db_name_cond_opt ::= db_name NK_DOT */ - { 367, 0 }, /* (240) like_pattern_opt ::= */ - { 367, -2 }, /* (241) like_pattern_opt ::= LIKE NK_STRING */ - { 368, -1 }, /* (242) table_name_cond ::= table_name */ - { 369, 0 }, /* (243) from_db_opt ::= */ - { 369, -2 }, /* (244) from_db_opt ::= FROM db_name */ - { 317, -8 }, /* (245) cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options */ - { 317, -4 }, /* (246) cmd ::= DROP INDEX exists_opt full_table_name */ - { 370, -10 }, /* (247) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ - { 370, -12 }, /* (248) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ - { 371, -1 }, /* (249) func_list ::= func */ - { 371, -3 }, /* (250) func_list ::= func_list NK_COMMA func */ - { 374, -4 }, /* (251) func ::= function_name NK_LP expression_list NK_RP */ - { 373, 0 }, /* (252) sma_stream_opt ::= */ - { 373, -3 }, /* (253) sma_stream_opt ::= stream_options WATERMARK duration_literal */ - { 373, -3 }, /* (254) sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ - { 317, -6 }, /* (255) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery */ - { 317, -7 }, /* (256) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ - { 317, -9 }, /* (257) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ - { 317, -7 }, /* (258) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ - { 317, -9 }, /* (259) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ - { 317, -4 }, /* (260) cmd ::= DROP TOPIC exists_opt topic_name */ - { 317, -7 }, /* (261) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ - { 317, -2 }, /* (262) cmd ::= DESC full_table_name */ - { 317, -2 }, /* (263) cmd ::= DESCRIBE full_table_name */ - { 317, -3 }, /* (264) cmd ::= RESET QUERY CACHE */ - { 317, -4 }, /* (265) cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery */ - { 379, 0 }, /* (266) analyze_opt ::= */ - { 379, -1 }, /* (267) analyze_opt ::= ANALYZE */ - { 380, 0 }, /* (268) explain_options ::= */ - { 380, -3 }, /* (269) explain_options ::= explain_options VERBOSE NK_BOOL */ - { 380, -3 }, /* (270) explain_options ::= explain_options RATIO NK_FLOAT */ - { 317, -10 }, /* (271) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ - { 317, -4 }, /* (272) cmd ::= DROP FUNCTION exists_opt function_name */ - { 381, 0 }, /* (273) agg_func_opt ::= */ - { 381, -1 }, /* (274) agg_func_opt ::= AGGREGATE */ - { 382, 0 }, /* (275) bufsize_opt ::= */ - { 382, -2 }, /* (276) bufsize_opt ::= BUFSIZE NK_INTEGER */ - { 317, -11 }, /* (277) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery */ - { 317, -4 }, /* (278) cmd ::= DROP STREAM exists_opt stream_name */ - { 375, 0 }, /* (279) stream_options ::= */ - { 375, -3 }, /* (280) stream_options ::= stream_options TRIGGER AT_ONCE */ - { 375, -3 }, /* (281) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ - { 375, -4 }, /* (282) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ - { 375, -3 }, /* (283) stream_options ::= stream_options WATERMARK duration_literal */ - { 375, -4 }, /* (284) stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */ - { 384, 0 }, /* (285) subtable_opt ::= */ - { 384, -4 }, /* (286) subtable_opt ::= SUBTABLE NK_LP expression NK_RP */ - { 317, -3 }, /* (287) cmd ::= KILL CONNECTION NK_INTEGER */ - { 317, -3 }, /* (288) cmd ::= KILL QUERY NK_STRING */ - { 317, -3 }, /* (289) cmd ::= KILL TRANSACTION NK_INTEGER */ - { 317, -2 }, /* (290) cmd ::= BALANCE VGROUP */ - { 317, -4 }, /* (291) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ - { 317, -4 }, /* (292) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ - { 317, -3 }, /* (293) cmd ::= SPLIT VGROUP NK_INTEGER */ - { 386, -2 }, /* (294) dnode_list ::= DNODE NK_INTEGER */ - { 386, -3 }, /* (295) dnode_list ::= dnode_list DNODE NK_INTEGER */ - { 317, -4 }, /* (296) cmd ::= DELETE FROM full_table_name where_clause_opt */ - { 317, -1 }, /* (297) cmd ::= query_or_subquery */ - { 317, -7 }, /* (298) cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */ - { 317, -4 }, /* (299) cmd ::= INSERT INTO full_table_name query_or_subquery */ - { 320, -1 }, /* (300) literal ::= NK_INTEGER */ - { 320, -1 }, /* (301) literal ::= NK_FLOAT */ - { 320, -1 }, /* (302) literal ::= NK_STRING */ - { 320, -1 }, /* (303) literal ::= NK_BOOL */ - { 320, -2 }, /* (304) literal ::= TIMESTAMP NK_STRING */ - { 320, -1 }, /* (305) literal ::= duration_literal */ - { 320, -1 }, /* (306) literal ::= NULL */ - { 320, -1 }, /* (307) literal ::= NK_QUESTION */ - { 362, -1 }, /* (308) duration_literal ::= NK_VARIABLE */ - { 388, -1 }, /* (309) signed ::= NK_INTEGER */ - { 388, -2 }, /* (310) signed ::= NK_PLUS NK_INTEGER */ - { 388, -2 }, /* (311) signed ::= NK_MINUS NK_INTEGER */ - { 388, -1 }, /* (312) signed ::= NK_FLOAT */ - { 388, -2 }, /* (313) signed ::= NK_PLUS NK_FLOAT */ - { 388, -2 }, /* (314) signed ::= NK_MINUS NK_FLOAT */ - { 351, -1 }, /* (315) signed_literal ::= signed */ - { 351, -1 }, /* (316) signed_literal ::= NK_STRING */ - { 351, -1 }, /* (317) signed_literal ::= NK_BOOL */ - { 351, -2 }, /* (318) signed_literal ::= TIMESTAMP NK_STRING */ - { 351, -1 }, /* (319) signed_literal ::= duration_literal */ - { 351, -1 }, /* (320) signed_literal ::= NULL */ - { 351, -1 }, /* (321) signed_literal ::= literal_func */ - { 351, -1 }, /* (322) signed_literal ::= NK_QUESTION */ - { 390, -1 }, /* (323) literal_list ::= signed_literal */ - { 390, -3 }, /* (324) literal_list ::= literal_list NK_COMMA signed_literal */ - { 328, -1 }, /* (325) db_name ::= NK_ID */ - { 357, -1 }, /* (326) table_name ::= NK_ID */ - { 349, -1 }, /* (327) column_name ::= NK_ID */ - { 364, -1 }, /* (328) function_name ::= NK_ID */ - { 391, -1 }, /* (329) table_alias ::= NK_ID */ - { 392, -1 }, /* (330) column_alias ::= NK_ID */ - { 322, -1 }, /* (331) user_name ::= NK_ID */ - { 376, -1 }, /* (332) topic_name ::= NK_ID */ - { 383, -1 }, /* (333) stream_name ::= NK_ID */ - { 378, -1 }, /* (334) cgroup_name ::= NK_ID */ - { 393, -1 }, /* (335) expr_or_subquery ::= expression */ - { 393, -1 }, /* (336) expr_or_subquery ::= subquery */ - { 385, -1 }, /* (337) expression ::= literal */ - { 385, -1 }, /* (338) expression ::= pseudo_column */ - { 385, -1 }, /* (339) expression ::= column_reference */ - { 385, -1 }, /* (340) expression ::= function_expression */ - { 385, -1 }, /* (341) expression ::= case_when_expression */ - { 385, -3 }, /* (342) expression ::= NK_LP expression NK_RP */ - { 385, -2 }, /* (343) expression ::= NK_PLUS expr_or_subquery */ - { 385, -2 }, /* (344) expression ::= NK_MINUS expr_or_subquery */ - { 385, -3 }, /* (345) expression ::= expr_or_subquery NK_PLUS expr_or_subquery */ - { 385, -3 }, /* (346) expression ::= expr_or_subquery NK_MINUS expr_or_subquery */ - { 385, -3 }, /* (347) expression ::= expr_or_subquery NK_STAR expr_or_subquery */ - { 385, -3 }, /* (348) expression ::= expr_or_subquery NK_SLASH expr_or_subquery */ - { 385, -3 }, /* (349) expression ::= expr_or_subquery NK_REM expr_or_subquery */ - { 385, -3 }, /* (350) expression ::= column_reference NK_ARROW NK_STRING */ - { 385, -3 }, /* (351) expression ::= expr_or_subquery NK_BITAND expr_or_subquery */ - { 385, -3 }, /* (352) expression ::= expr_or_subquery NK_BITOR expr_or_subquery */ - { 354, -1 }, /* (353) expression_list ::= expr_or_subquery */ - { 354, -3 }, /* (354) expression_list ::= expression_list NK_COMMA expr_or_subquery */ - { 396, -1 }, /* (355) column_reference ::= column_name */ - { 396, -3 }, /* (356) column_reference ::= table_name NK_DOT column_name */ - { 395, -1 }, /* (357) pseudo_column ::= ROWTS */ - { 395, -1 }, /* (358) pseudo_column ::= TBNAME */ - { 395, -3 }, /* (359) pseudo_column ::= table_name NK_DOT TBNAME */ - { 395, -1 }, /* (360) pseudo_column ::= QSTART */ - { 395, -1 }, /* (361) pseudo_column ::= QEND */ - { 395, -1 }, /* (362) pseudo_column ::= QDURATION */ - { 395, -1 }, /* (363) pseudo_column ::= WSTART */ - { 395, -1 }, /* (364) pseudo_column ::= WEND */ - { 395, -1 }, /* (365) pseudo_column ::= WDURATION */ - { 395, -1 }, /* (366) pseudo_column ::= IROWTS */ - { 395, -1 }, /* (367) pseudo_column ::= QTAGS */ - { 397, -4 }, /* (368) function_expression ::= function_name NK_LP expression_list NK_RP */ - { 397, -4 }, /* (369) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ - { 397, -6 }, /* (370) function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP */ - { 397, -1 }, /* (371) function_expression ::= literal_func */ - { 389, -3 }, /* (372) literal_func ::= noarg_func NK_LP NK_RP */ - { 389, -1 }, /* (373) literal_func ::= NOW */ - { 401, -1 }, /* (374) noarg_func ::= NOW */ - { 401, -1 }, /* (375) noarg_func ::= TODAY */ - { 401, -1 }, /* (376) noarg_func ::= TIMEZONE */ - { 401, -1 }, /* (377) noarg_func ::= DATABASE */ - { 401, -1 }, /* (378) noarg_func ::= CLIENT_VERSION */ - { 401, -1 }, /* (379) noarg_func ::= SERVER_VERSION */ - { 401, -1 }, /* (380) noarg_func ::= SERVER_STATUS */ - { 401, -1 }, /* (381) noarg_func ::= CURRENT_USER */ - { 401, -1 }, /* (382) noarg_func ::= USER */ - { 399, -1 }, /* (383) star_func ::= COUNT */ - { 399, -1 }, /* (384) star_func ::= FIRST */ - { 399, -1 }, /* (385) star_func ::= LAST */ - { 399, -1 }, /* (386) star_func ::= LAST_ROW */ - { 400, -1 }, /* (387) star_func_para_list ::= NK_STAR */ - { 400, -1 }, /* (388) star_func_para_list ::= other_para_list */ - { 402, -1 }, /* (389) other_para_list ::= star_func_para */ - { 402, -3 }, /* (390) other_para_list ::= other_para_list NK_COMMA star_func_para */ - { 403, -1 }, /* (391) star_func_para ::= expr_or_subquery */ - { 403, -3 }, /* (392) star_func_para ::= table_name NK_DOT NK_STAR */ - { 398, -4 }, /* (393) case_when_expression ::= CASE when_then_list case_when_else_opt END */ - { 398, -5 }, /* (394) case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END */ - { 404, -1 }, /* (395) when_then_list ::= when_then_expr */ - { 404, -2 }, /* (396) when_then_list ::= when_then_list when_then_expr */ - { 407, -4 }, /* (397) when_then_expr ::= WHEN common_expression THEN common_expression */ - { 405, 0 }, /* (398) case_when_else_opt ::= */ - { 405, -2 }, /* (399) case_when_else_opt ::= ELSE common_expression */ - { 408, -3 }, /* (400) predicate ::= expr_or_subquery compare_op expr_or_subquery */ - { 408, -5 }, /* (401) predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery */ - { 408, -6 }, /* (402) predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery */ - { 408, -3 }, /* (403) predicate ::= expr_or_subquery IS NULL */ - { 408, -4 }, /* (404) predicate ::= expr_or_subquery IS NOT NULL */ - { 408, -3 }, /* (405) predicate ::= expr_or_subquery in_op in_predicate_value */ - { 409, -1 }, /* (406) compare_op ::= NK_LT */ - { 409, -1 }, /* (407) compare_op ::= NK_GT */ - { 409, -1 }, /* (408) compare_op ::= NK_LE */ - { 409, -1 }, /* (409) compare_op ::= NK_GE */ - { 409, -1 }, /* (410) compare_op ::= NK_NE */ - { 409, -1 }, /* (411) compare_op ::= NK_EQ */ - { 409, -1 }, /* (412) compare_op ::= LIKE */ - { 409, -2 }, /* (413) compare_op ::= NOT LIKE */ - { 409, -1 }, /* (414) compare_op ::= MATCH */ - { 409, -1 }, /* (415) compare_op ::= NMATCH */ - { 409, -1 }, /* (416) compare_op ::= CONTAINS */ - { 410, -1 }, /* (417) in_op ::= IN */ - { 410, -2 }, /* (418) in_op ::= NOT IN */ - { 411, -3 }, /* (419) in_predicate_value ::= NK_LP literal_list NK_RP */ - { 412, -1 }, /* (420) boolean_value_expression ::= boolean_primary */ - { 412, -2 }, /* (421) boolean_value_expression ::= NOT boolean_primary */ - { 412, -3 }, /* (422) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 412, -3 }, /* (423) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 413, -1 }, /* (424) boolean_primary ::= predicate */ - { 413, -3 }, /* (425) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 406, -1 }, /* (426) common_expression ::= expr_or_subquery */ - { 406, -1 }, /* (427) common_expression ::= boolean_value_expression */ - { 414, 0 }, /* (428) from_clause_opt ::= */ - { 414, -2 }, /* (429) from_clause_opt ::= FROM table_reference_list */ - { 415, -1 }, /* (430) table_reference_list ::= table_reference */ - { 415, -3 }, /* (431) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 416, -1 }, /* (432) table_reference ::= table_primary */ - { 416, -1 }, /* (433) table_reference ::= joined_table */ - { 417, -2 }, /* (434) table_primary ::= table_name alias_opt */ - { 417, -4 }, /* (435) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 417, -2 }, /* (436) table_primary ::= subquery alias_opt */ - { 417, -1 }, /* (437) table_primary ::= parenthesized_joined_table */ - { 419, 0 }, /* (438) alias_opt ::= */ - { 419, -1 }, /* (439) alias_opt ::= table_alias */ - { 419, -2 }, /* (440) alias_opt ::= AS table_alias */ - { 420, -3 }, /* (441) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 420, -3 }, /* (442) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 418, -6 }, /* (443) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 421, 0 }, /* (444) join_type ::= */ - { 421, -1 }, /* (445) join_type ::= INNER */ - { 423, -12 }, /* (446) query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 424, 0 }, /* (447) set_quantifier_opt ::= */ - { 424, -1 }, /* (448) set_quantifier_opt ::= DISTINCT */ - { 424, -1 }, /* (449) set_quantifier_opt ::= ALL */ - { 425, -1 }, /* (450) select_list ::= select_item */ - { 425, -3 }, /* (451) select_list ::= select_list NK_COMMA select_item */ - { 433, -1 }, /* (452) select_item ::= NK_STAR */ - { 433, -1 }, /* (453) select_item ::= common_expression */ - { 433, -2 }, /* (454) select_item ::= common_expression column_alias */ - { 433, -3 }, /* (455) select_item ::= common_expression AS column_alias */ - { 433, -3 }, /* (456) select_item ::= table_name NK_DOT NK_STAR */ - { 387, 0 }, /* (457) where_clause_opt ::= */ - { 387, -2 }, /* (458) where_clause_opt ::= WHERE search_condition */ - { 426, 0 }, /* (459) partition_by_clause_opt ::= */ - { 426, -3 }, /* (460) partition_by_clause_opt ::= PARTITION BY partition_list */ - { 434, -1 }, /* (461) partition_list ::= partition_item */ - { 434, -3 }, /* (462) partition_list ::= partition_list NK_COMMA partition_item */ - { 435, -1 }, /* (463) partition_item ::= expr_or_subquery */ - { 435, -2 }, /* (464) partition_item ::= expr_or_subquery column_alias */ - { 435, -3 }, /* (465) partition_item ::= expr_or_subquery AS column_alias */ - { 430, 0 }, /* (466) twindow_clause_opt ::= */ - { 430, -6 }, /* (467) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 430, -4 }, /* (468) twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP */ - { 430, -6 }, /* (469) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 430, -8 }, /* (470) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 372, 0 }, /* (471) sliding_opt ::= */ - { 372, -4 }, /* (472) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 429, 0 }, /* (473) fill_opt ::= */ - { 429, -4 }, /* (474) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 429, -6 }, /* (475) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 436, -1 }, /* (476) fill_mode ::= NONE */ - { 436, -1 }, /* (477) fill_mode ::= PREV */ - { 436, -1 }, /* (478) fill_mode ::= NULL */ - { 436, -1 }, /* (479) fill_mode ::= LINEAR */ - { 436, -1 }, /* (480) fill_mode ::= NEXT */ - { 431, 0 }, /* (481) group_by_clause_opt ::= */ - { 431, -3 }, /* (482) group_by_clause_opt ::= GROUP BY group_by_list */ - { 437, -1 }, /* (483) group_by_list ::= expr_or_subquery */ - { 437, -3 }, /* (484) group_by_list ::= group_by_list NK_COMMA expr_or_subquery */ - { 432, 0 }, /* (485) having_clause_opt ::= */ - { 432, -2 }, /* (486) having_clause_opt ::= HAVING search_condition */ - { 427, 0 }, /* (487) range_opt ::= */ - { 427, -6 }, /* (488) range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP */ - { 428, 0 }, /* (489) every_opt ::= */ - { 428, -4 }, /* (490) every_opt ::= EVERY NK_LP duration_literal NK_RP */ - { 438, -4 }, /* (491) query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 439, -1 }, /* (492) query_simple ::= query_specification */ - { 439, -1 }, /* (493) query_simple ::= union_query_expression */ - { 443, -4 }, /* (494) union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery */ - { 443, -3 }, /* (495) union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery */ - { 444, -1 }, /* (496) query_simple_or_subquery ::= query_simple */ - { 444, -1 }, /* (497) query_simple_or_subquery ::= subquery */ - { 377, -1 }, /* (498) query_or_subquery ::= query_expression */ - { 377, -1 }, /* (499) query_or_subquery ::= subquery */ - { 440, 0 }, /* (500) order_by_clause_opt ::= */ - { 440, -3 }, /* (501) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 441, 0 }, /* (502) slimit_clause_opt ::= */ - { 441, -2 }, /* (503) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 441, -4 }, /* (504) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 441, -4 }, /* (505) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 442, 0 }, /* (506) limit_clause_opt ::= */ - { 442, -2 }, /* (507) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 442, -4 }, /* (508) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 442, -4 }, /* (509) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 394, -3 }, /* (510) subquery ::= NK_LP query_expression NK_RP */ - { 394, -3 }, /* (511) subquery ::= NK_LP subquery NK_RP */ - { 422, -1 }, /* (512) search_condition ::= common_expression */ - { 445, -1 }, /* (513) sort_specification_list ::= sort_specification */ - { 445, -3 }, /* (514) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 446, -3 }, /* (515) sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt */ - { 447, 0 }, /* (516) ordering_specification_opt ::= */ - { 447, -1 }, /* (517) ordering_specification_opt ::= ASC */ - { 447, -1 }, /* (518) ordering_specification_opt ::= DESC */ - { 448, 0 }, /* (519) null_ordering_opt ::= */ - { 448, -2 }, /* (520) null_ordering_opt ::= NULLS FIRST */ - { 448, -2 }, /* (521) null_ordering_opt ::= NULLS LAST */ + { 338, -2 }, /* (113) alter_db_option ::= REPLICA NK_INTEGER */ + { 338, -2 }, /* (114) alter_db_option ::= STRICT NK_STRING */ + { 338, -2 }, /* (115) alter_db_option ::= WAL_LEVEL NK_INTEGER */ + { 338, -2 }, /* (116) alter_db_option ::= STT_TRIGGER NK_INTEGER */ + { 335, -1 }, /* (117) integer_list ::= NK_INTEGER */ + { 335, -3 }, /* (118) integer_list ::= integer_list NK_COMMA NK_INTEGER */ + { 336, -1 }, /* (119) variable_list ::= NK_VARIABLE */ + { 336, -3 }, /* (120) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ + { 337, -1 }, /* (121) retention_list ::= retention */ + { 337, -3 }, /* (122) retention_list ::= retention_list NK_COMMA retention */ + { 339, -3 }, /* (123) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ + { 334, 0 }, /* (124) speed_opt ::= */ + { 334, -2 }, /* (125) speed_opt ::= MAX_SPEED NK_INTEGER */ + { 317, -9 }, /* (126) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 317, -3 }, /* (127) cmd ::= CREATE TABLE multi_create_clause */ + { 317, -9 }, /* (128) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 317, -3 }, /* (129) cmd ::= DROP TABLE multi_drop_clause */ + { 317, -4 }, /* (130) cmd ::= DROP STABLE exists_opt full_table_name */ + { 317, -3 }, /* (131) cmd ::= ALTER TABLE alter_table_clause */ + { 317, -3 }, /* (132) cmd ::= ALTER STABLE alter_table_clause */ + { 347, -2 }, /* (133) alter_table_clause ::= full_table_name alter_table_options */ + { 347, -5 }, /* (134) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 347, -4 }, /* (135) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 347, -5 }, /* (136) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 347, -5 }, /* (137) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 347, -5 }, /* (138) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 347, -4 }, /* (139) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 347, -5 }, /* (140) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 347, -5 }, /* (141) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 347, -6 }, /* (142) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ + { 344, -1 }, /* (143) multi_create_clause ::= create_subtable_clause */ + { 344, -2 }, /* (144) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 352, -10 }, /* (145) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ + { 346, -1 }, /* (146) multi_drop_clause ::= drop_table_clause */ + { 346, -2 }, /* (147) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 355, -2 }, /* (148) drop_table_clause ::= exists_opt full_table_name */ + { 353, 0 }, /* (149) specific_cols_opt ::= */ + { 353, -3 }, /* (150) specific_cols_opt ::= NK_LP col_name_list NK_RP */ + { 340, -1 }, /* (151) full_table_name ::= table_name */ + { 340, -3 }, /* (152) full_table_name ::= db_name NK_DOT table_name */ + { 341, -1 }, /* (153) column_def_list ::= column_def */ + { 341, -3 }, /* (154) column_def_list ::= column_def_list NK_COMMA column_def */ + { 358, -2 }, /* (155) column_def ::= column_name type_name */ + { 358, -4 }, /* (156) column_def ::= column_name type_name COMMENT NK_STRING */ + { 350, -1 }, /* (157) type_name ::= BOOL */ + { 350, -1 }, /* (158) type_name ::= TINYINT */ + { 350, -1 }, /* (159) type_name ::= SMALLINT */ + { 350, -1 }, /* (160) type_name ::= INT */ + { 350, -1 }, /* (161) type_name ::= INTEGER */ + { 350, -1 }, /* (162) type_name ::= BIGINT */ + { 350, -1 }, /* (163) type_name ::= FLOAT */ + { 350, -1 }, /* (164) type_name ::= DOUBLE */ + { 350, -4 }, /* (165) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 350, -1 }, /* (166) type_name ::= TIMESTAMP */ + { 350, -4 }, /* (167) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 350, -2 }, /* (168) type_name ::= TINYINT UNSIGNED */ + { 350, -2 }, /* (169) type_name ::= SMALLINT UNSIGNED */ + { 350, -2 }, /* (170) type_name ::= INT UNSIGNED */ + { 350, -2 }, /* (171) type_name ::= BIGINT UNSIGNED */ + { 350, -1 }, /* (172) type_name ::= JSON */ + { 350, -4 }, /* (173) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 350, -1 }, /* (174) type_name ::= MEDIUMBLOB */ + { 350, -1 }, /* (175) type_name ::= BLOB */ + { 350, -4 }, /* (176) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 350, -1 }, /* (177) type_name ::= DECIMAL */ + { 350, -4 }, /* (178) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 350, -6 }, /* (179) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 342, 0 }, /* (180) tags_def_opt ::= */ + { 342, -1 }, /* (181) tags_def_opt ::= tags_def */ + { 345, -4 }, /* (182) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 343, 0 }, /* (183) table_options ::= */ + { 343, -3 }, /* (184) table_options ::= table_options COMMENT NK_STRING */ + { 343, -3 }, /* (185) table_options ::= table_options MAX_DELAY duration_list */ + { 343, -3 }, /* (186) table_options ::= table_options WATERMARK duration_list */ + { 343, -5 }, /* (187) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ + { 343, -3 }, /* (188) table_options ::= table_options TTL NK_INTEGER */ + { 343, -5 }, /* (189) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 348, -1 }, /* (190) alter_table_options ::= alter_table_option */ + { 348, -2 }, /* (191) alter_table_options ::= alter_table_options alter_table_option */ + { 361, -2 }, /* (192) alter_table_option ::= COMMENT NK_STRING */ + { 361, -2 }, /* (193) alter_table_option ::= TTL NK_INTEGER */ + { 359, -1 }, /* (194) duration_list ::= duration_literal */ + { 359, -3 }, /* (195) duration_list ::= duration_list NK_COMMA duration_literal */ + { 360, -1 }, /* (196) rollup_func_list ::= rollup_func_name */ + { 360, -3 }, /* (197) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ + { 363, -1 }, /* (198) rollup_func_name ::= function_name */ + { 363, -1 }, /* (199) rollup_func_name ::= FIRST */ + { 363, -1 }, /* (200) rollup_func_name ::= LAST */ + { 356, -1 }, /* (201) col_name_list ::= col_name */ + { 356, -3 }, /* (202) col_name_list ::= col_name_list NK_COMMA col_name */ + { 365, -1 }, /* (203) col_name ::= column_name */ + { 317, -2 }, /* (204) cmd ::= SHOW DNODES */ + { 317, -2 }, /* (205) cmd ::= SHOW USERS */ + { 317, -2 }, /* (206) cmd ::= SHOW DATABASES */ + { 317, -4 }, /* (207) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 317, -4 }, /* (208) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 317, -3 }, /* (209) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 317, -2 }, /* (210) cmd ::= SHOW MNODES */ + { 317, -2 }, /* (211) cmd ::= SHOW QNODES */ + { 317, -2 }, /* (212) cmd ::= SHOW FUNCTIONS */ + { 317, -5 }, /* (213) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 317, -2 }, /* (214) cmd ::= SHOW STREAMS */ + { 317, -2 }, /* (215) cmd ::= SHOW ACCOUNTS */ + { 317, -2 }, /* (216) cmd ::= SHOW APPS */ + { 317, -2 }, /* (217) cmd ::= SHOW CONNECTIONS */ + { 317, -2 }, /* (218) cmd ::= SHOW LICENCES */ + { 317, -2 }, /* (219) cmd ::= SHOW GRANTS */ + { 317, -4 }, /* (220) cmd ::= SHOW CREATE DATABASE db_name */ + { 317, -4 }, /* (221) cmd ::= SHOW CREATE TABLE full_table_name */ + { 317, -4 }, /* (222) cmd ::= SHOW CREATE STABLE full_table_name */ + { 317, -2 }, /* (223) cmd ::= SHOW QUERIES */ + { 317, -2 }, /* (224) cmd ::= SHOW SCORES */ + { 317, -2 }, /* (225) cmd ::= SHOW TOPICS */ + { 317, -2 }, /* (226) cmd ::= SHOW VARIABLES */ + { 317, -3 }, /* (227) cmd ::= SHOW LOCAL VARIABLES */ + { 317, -4 }, /* (228) cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ + { 317, -2 }, /* (229) cmd ::= SHOW BNODES */ + { 317, -2 }, /* (230) cmd ::= SHOW SNODES */ + { 317, -2 }, /* (231) cmd ::= SHOW CLUSTER */ + { 317, -2 }, /* (232) cmd ::= SHOW TRANSACTIONS */ + { 317, -4 }, /* (233) cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ + { 317, -2 }, /* (234) cmd ::= SHOW CONSUMERS */ + { 317, -2 }, /* (235) cmd ::= SHOW SUBSCRIPTIONS */ + { 317, -5 }, /* (236) cmd ::= SHOW TAGS FROM table_name_cond from_db_opt */ + { 317, -6 }, /* (237) cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt */ + { 317, -3 }, /* (238) cmd ::= SHOW VNODES NK_INTEGER */ + { 317, -3 }, /* (239) cmd ::= SHOW VNODES NK_STRING */ + { 366, 0 }, /* (240) db_name_cond_opt ::= */ + { 366, -2 }, /* (241) db_name_cond_opt ::= db_name NK_DOT */ + { 367, 0 }, /* (242) like_pattern_opt ::= */ + { 367, -2 }, /* (243) like_pattern_opt ::= LIKE NK_STRING */ + { 368, -1 }, /* (244) table_name_cond ::= table_name */ + { 369, 0 }, /* (245) from_db_opt ::= */ + { 369, -2 }, /* (246) from_db_opt ::= FROM db_name */ + { 317, -8 }, /* (247) cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options */ + { 317, -4 }, /* (248) cmd ::= DROP INDEX exists_opt full_table_name */ + { 370, -10 }, /* (249) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ + { 370, -12 }, /* (250) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ + { 371, -1 }, /* (251) func_list ::= func */ + { 371, -3 }, /* (252) func_list ::= func_list NK_COMMA func */ + { 374, -4 }, /* (253) func ::= function_name NK_LP expression_list NK_RP */ + { 373, 0 }, /* (254) sma_stream_opt ::= */ + { 373, -3 }, /* (255) sma_stream_opt ::= stream_options WATERMARK duration_literal */ + { 373, -3 }, /* (256) sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ + { 317, -6 }, /* (257) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery */ + { 317, -7 }, /* (258) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ + { 317, -9 }, /* (259) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ + { 317, -7 }, /* (260) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ + { 317, -9 }, /* (261) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ + { 317, -4 }, /* (262) cmd ::= DROP TOPIC exists_opt topic_name */ + { 317, -7 }, /* (263) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ + { 317, -2 }, /* (264) cmd ::= DESC full_table_name */ + { 317, -2 }, /* (265) cmd ::= DESCRIBE full_table_name */ + { 317, -3 }, /* (266) cmd ::= RESET QUERY CACHE */ + { 317, -4 }, /* (267) cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery */ + { 379, 0 }, /* (268) analyze_opt ::= */ + { 379, -1 }, /* (269) analyze_opt ::= ANALYZE */ + { 380, 0 }, /* (270) explain_options ::= */ + { 380, -3 }, /* (271) explain_options ::= explain_options VERBOSE NK_BOOL */ + { 380, -3 }, /* (272) explain_options ::= explain_options RATIO NK_FLOAT */ + { 317, -10 }, /* (273) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ + { 317, -4 }, /* (274) cmd ::= DROP FUNCTION exists_opt function_name */ + { 381, 0 }, /* (275) agg_func_opt ::= */ + { 381, -1 }, /* (276) agg_func_opt ::= AGGREGATE */ + { 382, 0 }, /* (277) bufsize_opt ::= */ + { 382, -2 }, /* (278) bufsize_opt ::= BUFSIZE NK_INTEGER */ + { 317, -11 }, /* (279) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery */ + { 317, -4 }, /* (280) cmd ::= DROP STREAM exists_opt stream_name */ + { 375, 0 }, /* (281) stream_options ::= */ + { 375, -3 }, /* (282) stream_options ::= stream_options TRIGGER AT_ONCE */ + { 375, -3 }, /* (283) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ + { 375, -4 }, /* (284) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ + { 375, -3 }, /* (285) stream_options ::= stream_options WATERMARK duration_literal */ + { 375, -4 }, /* (286) stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */ + { 384, 0 }, /* (287) subtable_opt ::= */ + { 384, -4 }, /* (288) subtable_opt ::= SUBTABLE NK_LP expression NK_RP */ + { 317, -3 }, /* (289) cmd ::= KILL CONNECTION NK_INTEGER */ + { 317, -3 }, /* (290) cmd ::= KILL QUERY NK_STRING */ + { 317, -3 }, /* (291) cmd ::= KILL TRANSACTION NK_INTEGER */ + { 317, -2 }, /* (292) cmd ::= BALANCE VGROUP */ + { 317, -4 }, /* (293) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + { 317, -4 }, /* (294) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + { 317, -3 }, /* (295) cmd ::= SPLIT VGROUP NK_INTEGER */ + { 386, -2 }, /* (296) dnode_list ::= DNODE NK_INTEGER */ + { 386, -3 }, /* (297) dnode_list ::= dnode_list DNODE NK_INTEGER */ + { 317, -4 }, /* (298) cmd ::= DELETE FROM full_table_name where_clause_opt */ + { 317, -1 }, /* (299) cmd ::= query_or_subquery */ + { 317, -7 }, /* (300) cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */ + { 317, -4 }, /* (301) cmd ::= INSERT INTO full_table_name query_or_subquery */ + { 320, -1 }, /* (302) literal ::= NK_INTEGER */ + { 320, -1 }, /* (303) literal ::= NK_FLOAT */ + { 320, -1 }, /* (304) literal ::= NK_STRING */ + { 320, -1 }, /* (305) literal ::= NK_BOOL */ + { 320, -2 }, /* (306) literal ::= TIMESTAMP NK_STRING */ + { 320, -1 }, /* (307) literal ::= duration_literal */ + { 320, -1 }, /* (308) literal ::= NULL */ + { 320, -1 }, /* (309) literal ::= NK_QUESTION */ + { 362, -1 }, /* (310) duration_literal ::= NK_VARIABLE */ + { 388, -1 }, /* (311) signed ::= NK_INTEGER */ + { 388, -2 }, /* (312) signed ::= NK_PLUS NK_INTEGER */ + { 388, -2 }, /* (313) signed ::= NK_MINUS NK_INTEGER */ + { 388, -1 }, /* (314) signed ::= NK_FLOAT */ + { 388, -2 }, /* (315) signed ::= NK_PLUS NK_FLOAT */ + { 388, -2 }, /* (316) signed ::= NK_MINUS NK_FLOAT */ + { 351, -1 }, /* (317) signed_literal ::= signed */ + { 351, -1 }, /* (318) signed_literal ::= NK_STRING */ + { 351, -1 }, /* (319) signed_literal ::= NK_BOOL */ + { 351, -2 }, /* (320) signed_literal ::= TIMESTAMP NK_STRING */ + { 351, -1 }, /* (321) signed_literal ::= duration_literal */ + { 351, -1 }, /* (322) signed_literal ::= NULL */ + { 351, -1 }, /* (323) signed_literal ::= literal_func */ + { 351, -1 }, /* (324) signed_literal ::= NK_QUESTION */ + { 390, -1 }, /* (325) literal_list ::= signed_literal */ + { 390, -3 }, /* (326) literal_list ::= literal_list NK_COMMA signed_literal */ + { 328, -1 }, /* (327) db_name ::= NK_ID */ + { 357, -1 }, /* (328) table_name ::= NK_ID */ + { 349, -1 }, /* (329) column_name ::= NK_ID */ + { 364, -1 }, /* (330) function_name ::= NK_ID */ + { 391, -1 }, /* (331) table_alias ::= NK_ID */ + { 392, -1 }, /* (332) column_alias ::= NK_ID */ + { 322, -1 }, /* (333) user_name ::= NK_ID */ + { 376, -1 }, /* (334) topic_name ::= NK_ID */ + { 383, -1 }, /* (335) stream_name ::= NK_ID */ + { 378, -1 }, /* (336) cgroup_name ::= NK_ID */ + { 393, -1 }, /* (337) expr_or_subquery ::= expression */ + { 393, -1 }, /* (338) expr_or_subquery ::= subquery */ + { 385, -1 }, /* (339) expression ::= literal */ + { 385, -1 }, /* (340) expression ::= pseudo_column */ + { 385, -1 }, /* (341) expression ::= column_reference */ + { 385, -1 }, /* (342) expression ::= function_expression */ + { 385, -1 }, /* (343) expression ::= case_when_expression */ + { 385, -3 }, /* (344) expression ::= NK_LP expression NK_RP */ + { 385, -2 }, /* (345) expression ::= NK_PLUS expr_or_subquery */ + { 385, -2 }, /* (346) expression ::= NK_MINUS expr_or_subquery */ + { 385, -3 }, /* (347) expression ::= expr_or_subquery NK_PLUS expr_or_subquery */ + { 385, -3 }, /* (348) expression ::= expr_or_subquery NK_MINUS expr_or_subquery */ + { 385, -3 }, /* (349) expression ::= expr_or_subquery NK_STAR expr_or_subquery */ + { 385, -3 }, /* (350) expression ::= expr_or_subquery NK_SLASH expr_or_subquery */ + { 385, -3 }, /* (351) expression ::= expr_or_subquery NK_REM expr_or_subquery */ + { 385, -3 }, /* (352) expression ::= column_reference NK_ARROW NK_STRING */ + { 385, -3 }, /* (353) expression ::= expr_or_subquery NK_BITAND expr_or_subquery */ + { 385, -3 }, /* (354) expression ::= expr_or_subquery NK_BITOR expr_or_subquery */ + { 354, -1 }, /* (355) expression_list ::= expr_or_subquery */ + { 354, -3 }, /* (356) expression_list ::= expression_list NK_COMMA expr_or_subquery */ + { 396, -1 }, /* (357) column_reference ::= column_name */ + { 396, -3 }, /* (358) column_reference ::= table_name NK_DOT column_name */ + { 395, -1 }, /* (359) pseudo_column ::= ROWTS */ + { 395, -1 }, /* (360) pseudo_column ::= TBNAME */ + { 395, -3 }, /* (361) pseudo_column ::= table_name NK_DOT TBNAME */ + { 395, -1 }, /* (362) pseudo_column ::= QSTART */ + { 395, -1 }, /* (363) pseudo_column ::= QEND */ + { 395, -1 }, /* (364) pseudo_column ::= QDURATION */ + { 395, -1 }, /* (365) pseudo_column ::= WSTART */ + { 395, -1 }, /* (366) pseudo_column ::= WEND */ + { 395, -1 }, /* (367) pseudo_column ::= WDURATION */ + { 395, -1 }, /* (368) pseudo_column ::= IROWTS */ + { 395, -1 }, /* (369) pseudo_column ::= QTAGS */ + { 397, -4 }, /* (370) function_expression ::= function_name NK_LP expression_list NK_RP */ + { 397, -4 }, /* (371) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ + { 397, -6 }, /* (372) function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP */ + { 397, -1 }, /* (373) function_expression ::= literal_func */ + { 389, -3 }, /* (374) literal_func ::= noarg_func NK_LP NK_RP */ + { 389, -1 }, /* (375) literal_func ::= NOW */ + { 401, -1 }, /* (376) noarg_func ::= NOW */ + { 401, -1 }, /* (377) noarg_func ::= TODAY */ + { 401, -1 }, /* (378) noarg_func ::= TIMEZONE */ + { 401, -1 }, /* (379) noarg_func ::= DATABASE */ + { 401, -1 }, /* (380) noarg_func ::= CLIENT_VERSION */ + { 401, -1 }, /* (381) noarg_func ::= SERVER_VERSION */ + { 401, -1 }, /* (382) noarg_func ::= SERVER_STATUS */ + { 401, -1 }, /* (383) noarg_func ::= CURRENT_USER */ + { 401, -1 }, /* (384) noarg_func ::= USER */ + { 399, -1 }, /* (385) star_func ::= COUNT */ + { 399, -1 }, /* (386) star_func ::= FIRST */ + { 399, -1 }, /* (387) star_func ::= LAST */ + { 399, -1 }, /* (388) star_func ::= LAST_ROW */ + { 400, -1 }, /* (389) star_func_para_list ::= NK_STAR */ + { 400, -1 }, /* (390) star_func_para_list ::= other_para_list */ + { 402, -1 }, /* (391) other_para_list ::= star_func_para */ + { 402, -3 }, /* (392) other_para_list ::= other_para_list NK_COMMA star_func_para */ + { 403, -1 }, /* (393) star_func_para ::= expr_or_subquery */ + { 403, -3 }, /* (394) star_func_para ::= table_name NK_DOT NK_STAR */ + { 398, -4 }, /* (395) case_when_expression ::= CASE when_then_list case_when_else_opt END */ + { 398, -5 }, /* (396) case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END */ + { 404, -1 }, /* (397) when_then_list ::= when_then_expr */ + { 404, -2 }, /* (398) when_then_list ::= when_then_list when_then_expr */ + { 407, -4 }, /* (399) when_then_expr ::= WHEN common_expression THEN common_expression */ + { 405, 0 }, /* (400) case_when_else_opt ::= */ + { 405, -2 }, /* (401) case_when_else_opt ::= ELSE common_expression */ + { 408, -3 }, /* (402) predicate ::= expr_or_subquery compare_op expr_or_subquery */ + { 408, -5 }, /* (403) predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery */ + { 408, -6 }, /* (404) predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery */ + { 408, -3 }, /* (405) predicate ::= expr_or_subquery IS NULL */ + { 408, -4 }, /* (406) predicate ::= expr_or_subquery IS NOT NULL */ + { 408, -3 }, /* (407) predicate ::= expr_or_subquery in_op in_predicate_value */ + { 409, -1 }, /* (408) compare_op ::= NK_LT */ + { 409, -1 }, /* (409) compare_op ::= NK_GT */ + { 409, -1 }, /* (410) compare_op ::= NK_LE */ + { 409, -1 }, /* (411) compare_op ::= NK_GE */ + { 409, -1 }, /* (412) compare_op ::= NK_NE */ + { 409, -1 }, /* (413) compare_op ::= NK_EQ */ + { 409, -1 }, /* (414) compare_op ::= LIKE */ + { 409, -2 }, /* (415) compare_op ::= NOT LIKE */ + { 409, -1 }, /* (416) compare_op ::= MATCH */ + { 409, -1 }, /* (417) compare_op ::= NMATCH */ + { 409, -1 }, /* (418) compare_op ::= CONTAINS */ + { 410, -1 }, /* (419) in_op ::= IN */ + { 410, -2 }, /* (420) in_op ::= NOT IN */ + { 411, -3 }, /* (421) in_predicate_value ::= NK_LP literal_list NK_RP */ + { 412, -1 }, /* (422) boolean_value_expression ::= boolean_primary */ + { 412, -2 }, /* (423) boolean_value_expression ::= NOT boolean_primary */ + { 412, -3 }, /* (424) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 412, -3 }, /* (425) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 413, -1 }, /* (426) boolean_primary ::= predicate */ + { 413, -3 }, /* (427) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 406, -1 }, /* (428) common_expression ::= expr_or_subquery */ + { 406, -1 }, /* (429) common_expression ::= boolean_value_expression */ + { 414, 0 }, /* (430) from_clause_opt ::= */ + { 414, -2 }, /* (431) from_clause_opt ::= FROM table_reference_list */ + { 415, -1 }, /* (432) table_reference_list ::= table_reference */ + { 415, -3 }, /* (433) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 416, -1 }, /* (434) table_reference ::= table_primary */ + { 416, -1 }, /* (435) table_reference ::= joined_table */ + { 417, -2 }, /* (436) table_primary ::= table_name alias_opt */ + { 417, -4 }, /* (437) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 417, -2 }, /* (438) table_primary ::= subquery alias_opt */ + { 417, -1 }, /* (439) table_primary ::= parenthesized_joined_table */ + { 419, 0 }, /* (440) alias_opt ::= */ + { 419, -1 }, /* (441) alias_opt ::= table_alias */ + { 419, -2 }, /* (442) alias_opt ::= AS table_alias */ + { 420, -3 }, /* (443) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 420, -3 }, /* (444) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 418, -6 }, /* (445) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 421, 0 }, /* (446) join_type ::= */ + { 421, -1 }, /* (447) join_type ::= INNER */ + { 423, -12 }, /* (448) query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 424, 0 }, /* (449) set_quantifier_opt ::= */ + { 424, -1 }, /* (450) set_quantifier_opt ::= DISTINCT */ + { 424, -1 }, /* (451) set_quantifier_opt ::= ALL */ + { 425, -1 }, /* (452) select_list ::= select_item */ + { 425, -3 }, /* (453) select_list ::= select_list NK_COMMA select_item */ + { 433, -1 }, /* (454) select_item ::= NK_STAR */ + { 433, -1 }, /* (455) select_item ::= common_expression */ + { 433, -2 }, /* (456) select_item ::= common_expression column_alias */ + { 433, -3 }, /* (457) select_item ::= common_expression AS column_alias */ + { 433, -3 }, /* (458) select_item ::= table_name NK_DOT NK_STAR */ + { 387, 0 }, /* (459) where_clause_opt ::= */ + { 387, -2 }, /* (460) where_clause_opt ::= WHERE search_condition */ + { 426, 0 }, /* (461) partition_by_clause_opt ::= */ + { 426, -3 }, /* (462) partition_by_clause_opt ::= PARTITION BY partition_list */ + { 434, -1 }, /* (463) partition_list ::= partition_item */ + { 434, -3 }, /* (464) partition_list ::= partition_list NK_COMMA partition_item */ + { 435, -1 }, /* (465) partition_item ::= expr_or_subquery */ + { 435, -2 }, /* (466) partition_item ::= expr_or_subquery column_alias */ + { 435, -3 }, /* (467) partition_item ::= expr_or_subquery AS column_alias */ + { 430, 0 }, /* (468) twindow_clause_opt ::= */ + { 430, -6 }, /* (469) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 430, -4 }, /* (470) twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP */ + { 430, -6 }, /* (471) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 430, -8 }, /* (472) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 372, 0 }, /* (473) sliding_opt ::= */ + { 372, -4 }, /* (474) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 429, 0 }, /* (475) fill_opt ::= */ + { 429, -4 }, /* (476) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 429, -6 }, /* (477) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 436, -1 }, /* (478) fill_mode ::= NONE */ + { 436, -1 }, /* (479) fill_mode ::= PREV */ + { 436, -1 }, /* (480) fill_mode ::= NULL */ + { 436, -1 }, /* (481) fill_mode ::= LINEAR */ + { 436, -1 }, /* (482) fill_mode ::= NEXT */ + { 431, 0 }, /* (483) group_by_clause_opt ::= */ + { 431, -3 }, /* (484) group_by_clause_opt ::= GROUP BY group_by_list */ + { 437, -1 }, /* (485) group_by_list ::= expr_or_subquery */ + { 437, -3 }, /* (486) group_by_list ::= group_by_list NK_COMMA expr_or_subquery */ + { 432, 0 }, /* (487) having_clause_opt ::= */ + { 432, -2 }, /* (488) having_clause_opt ::= HAVING search_condition */ + { 427, 0 }, /* (489) range_opt ::= */ + { 427, -6 }, /* (490) range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP */ + { 428, 0 }, /* (491) every_opt ::= */ + { 428, -4 }, /* (492) every_opt ::= EVERY NK_LP duration_literal NK_RP */ + { 438, -4 }, /* (493) query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 439, -1 }, /* (494) query_simple ::= query_specification */ + { 439, -1 }, /* (495) query_simple ::= union_query_expression */ + { 443, -4 }, /* (496) union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery */ + { 443, -3 }, /* (497) union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery */ + { 444, -1 }, /* (498) query_simple_or_subquery ::= query_simple */ + { 444, -1 }, /* (499) query_simple_or_subquery ::= subquery */ + { 377, -1 }, /* (500) query_or_subquery ::= query_expression */ + { 377, -1 }, /* (501) query_or_subquery ::= subquery */ + { 440, 0 }, /* (502) order_by_clause_opt ::= */ + { 440, -3 }, /* (503) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 441, 0 }, /* (504) slimit_clause_opt ::= */ + { 441, -2 }, /* (505) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 441, -4 }, /* (506) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 441, -4 }, /* (507) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 442, 0 }, /* (508) limit_clause_opt ::= */ + { 442, -2 }, /* (509) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 442, -4 }, /* (510) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 442, -4 }, /* (511) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 394, -3 }, /* (512) subquery ::= NK_LP query_expression NK_RP */ + { 394, -3 }, /* (513) subquery ::= NK_LP subquery NK_RP */ + { 422, -1 }, /* (514) search_condition ::= common_expression */ + { 445, -1 }, /* (515) sort_specification_list ::= sort_specification */ + { 445, -3 }, /* (516) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 446, -3 }, /* (517) sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt */ + { 447, 0 }, /* (518) ordering_specification_opt ::= */ + { 447, -1 }, /* (519) ordering_specification_opt ::= ASC */ + { 447, -1 }, /* (520) ordering_specification_opt ::= DESC */ + { 448, 0 }, /* (521) null_ordering_opt ::= */ + { 448, -2 }, /* (522) null_ordering_opt ::= NULLS FIRST */ + { 448, -2 }, /* (523) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -3711,29 +3715,29 @@ static YYACTIONTYPE yy_reduce( case 49: /* dnode_endpoint ::= NK_STRING */ case 50: /* dnode_endpoint ::= NK_ID */ yytestcase(yyruleno==50); case 51: /* dnode_endpoint ::= NK_IPTOKEN */ yytestcase(yyruleno==51); - case 325: /* db_name ::= NK_ID */ yytestcase(yyruleno==325); - case 326: /* table_name ::= NK_ID */ yytestcase(yyruleno==326); - case 327: /* column_name ::= NK_ID */ yytestcase(yyruleno==327); - case 328: /* function_name ::= NK_ID */ yytestcase(yyruleno==328); - case 329: /* table_alias ::= NK_ID */ yytestcase(yyruleno==329); - case 330: /* column_alias ::= NK_ID */ yytestcase(yyruleno==330); - case 331: /* user_name ::= NK_ID */ yytestcase(yyruleno==331); - case 332: /* topic_name ::= NK_ID */ yytestcase(yyruleno==332); - case 333: /* stream_name ::= NK_ID */ yytestcase(yyruleno==333); - case 334: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==334); - case 374: /* noarg_func ::= NOW */ yytestcase(yyruleno==374); - case 375: /* noarg_func ::= TODAY */ yytestcase(yyruleno==375); - case 376: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==376); - case 377: /* noarg_func ::= DATABASE */ yytestcase(yyruleno==377); - case 378: /* noarg_func ::= CLIENT_VERSION */ yytestcase(yyruleno==378); - case 379: /* noarg_func ::= SERVER_VERSION */ yytestcase(yyruleno==379); - case 380: /* noarg_func ::= SERVER_STATUS */ yytestcase(yyruleno==380); - case 381: /* noarg_func ::= CURRENT_USER */ yytestcase(yyruleno==381); - case 382: /* noarg_func ::= USER */ yytestcase(yyruleno==382); - case 383: /* star_func ::= COUNT */ yytestcase(yyruleno==383); - case 384: /* star_func ::= FIRST */ yytestcase(yyruleno==384); - case 385: /* star_func ::= LAST */ yytestcase(yyruleno==385); - case 386: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==386); + case 327: /* db_name ::= NK_ID */ yytestcase(yyruleno==327); + case 328: /* table_name ::= NK_ID */ yytestcase(yyruleno==328); + case 329: /* column_name ::= NK_ID */ yytestcase(yyruleno==329); + case 330: /* function_name ::= NK_ID */ yytestcase(yyruleno==330); + case 331: /* table_alias ::= NK_ID */ yytestcase(yyruleno==331); + case 332: /* column_alias ::= NK_ID */ yytestcase(yyruleno==332); + case 333: /* user_name ::= NK_ID */ yytestcase(yyruleno==333); + case 334: /* topic_name ::= NK_ID */ yytestcase(yyruleno==334); + case 335: /* stream_name ::= NK_ID */ yytestcase(yyruleno==335); + case 336: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==336); + case 376: /* noarg_func ::= NOW */ yytestcase(yyruleno==376); + case 377: /* noarg_func ::= TODAY */ yytestcase(yyruleno==377); + case 378: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==378); + case 379: /* noarg_func ::= DATABASE */ yytestcase(yyruleno==379); + case 380: /* noarg_func ::= CLIENT_VERSION */ yytestcase(yyruleno==380); + case 381: /* noarg_func ::= SERVER_VERSION */ yytestcase(yyruleno==381); + case 382: /* noarg_func ::= SERVER_STATUS */ yytestcase(yyruleno==382); + case 383: /* noarg_func ::= CURRENT_USER */ yytestcase(yyruleno==383); + case 384: /* noarg_func ::= USER */ yytestcase(yyruleno==384); + case 385: /* star_func ::= COUNT */ yytestcase(yyruleno==385); + case 386: /* star_func ::= FIRST */ yytestcase(yyruleno==386); + case 387: /* star_func ::= LAST */ yytestcase(yyruleno==387); + case 388: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==388); { yylhsminor.yy181 = yymsp[0].minor.yy0; } yymsp[0].minor.yy181 = yylhsminor.yy181; break; @@ -3790,9 +3794,9 @@ static YYACTIONTYPE yy_reduce( break; case 69: /* not_exists_opt ::= */ case 71: /* exists_opt ::= */ yytestcase(yyruleno==71); - case 266: /* analyze_opt ::= */ yytestcase(yyruleno==266); - case 273: /* agg_func_opt ::= */ yytestcase(yyruleno==273); - case 447: /* set_quantifier_opt ::= */ yytestcase(yyruleno==447); + case 268: /* analyze_opt ::= */ yytestcase(yyruleno==268); + case 275: /* agg_func_opt ::= */ yytestcase(yyruleno==275); + case 449: /* set_quantifier_opt ::= */ yytestcase(yyruleno==449); { yymsp[1].minor.yy39 = false; } break; case 70: /* exists_opt ::= IF EXISTS */ @@ -3954,655 +3958,661 @@ static YYACTIONTYPE yy_reduce( case 112: /* alter_db_option ::= PAGES NK_INTEGER */ { yymsp[-1].minor.yy645.type = DB_OPTION_PAGES; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } break; - case 113: /* alter_db_option ::= WAL_LEVEL NK_INTEGER */ + case 113: /* alter_db_option ::= REPLICA NK_INTEGER */ +{ yymsp[-1].minor.yy645.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } + break; + case 114: /* alter_db_option ::= STRICT NK_STRING */ +{ yymsp[-1].minor.yy645.type = DB_OPTION_STRICT; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } + break; + case 115: /* alter_db_option ::= WAL_LEVEL NK_INTEGER */ { yymsp[-1].minor.yy645.type = DB_OPTION_WAL; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } break; - case 114: /* alter_db_option ::= STT_TRIGGER NK_INTEGER */ + case 116: /* alter_db_option ::= STT_TRIGGER NK_INTEGER */ { yymsp[-1].minor.yy645.type = DB_OPTION_STT_TRIGGER; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } break; - case 115: /* integer_list ::= NK_INTEGER */ + case 117: /* integer_list ::= NK_INTEGER */ { yylhsminor.yy282 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy282 = yylhsminor.yy282; break; - case 116: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ - case 295: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==295); + case 118: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ + case 297: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==297); { yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-2].minor.yy282, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } yymsp[-2].minor.yy282 = yylhsminor.yy282; break; - case 117: /* variable_list ::= NK_VARIABLE */ + case 119: /* variable_list ::= NK_VARIABLE */ { yylhsminor.yy282 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy282 = yylhsminor.yy282; break; - case 118: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ + case 120: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ { yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-2].minor.yy282, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } yymsp[-2].minor.yy282 = yylhsminor.yy282; break; - case 119: /* retention_list ::= retention */ - case 141: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==141); - case 144: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==144); - case 151: /* column_def_list ::= column_def */ yytestcase(yyruleno==151); - case 194: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==194); - case 199: /* col_name_list ::= col_name */ yytestcase(yyruleno==199); - case 249: /* func_list ::= func */ yytestcase(yyruleno==249); - case 323: /* literal_list ::= signed_literal */ yytestcase(yyruleno==323); - case 389: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==389); - case 395: /* when_then_list ::= when_then_expr */ yytestcase(yyruleno==395); - case 450: /* select_list ::= select_item */ yytestcase(yyruleno==450); - case 461: /* partition_list ::= partition_item */ yytestcase(yyruleno==461); - case 513: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==513); + case 121: /* retention_list ::= retention */ + case 143: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==143); + case 146: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==146); + case 153: /* column_def_list ::= column_def */ yytestcase(yyruleno==153); + case 196: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==196); + case 201: /* col_name_list ::= col_name */ yytestcase(yyruleno==201); + case 251: /* func_list ::= func */ yytestcase(yyruleno==251); + case 325: /* literal_list ::= signed_literal */ yytestcase(yyruleno==325); + case 391: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==391); + case 397: /* when_then_list ::= when_then_expr */ yytestcase(yyruleno==397); + case 452: /* select_list ::= select_item */ yytestcase(yyruleno==452); + case 463: /* partition_list ::= partition_item */ yytestcase(yyruleno==463); + case 515: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==515); { yylhsminor.yy282 = createNodeList(pCxt, yymsp[0].minor.yy778); } yymsp[0].minor.yy282 = yylhsminor.yy282; break; - case 120: /* retention_list ::= retention_list NK_COMMA retention */ - case 152: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==152); - case 195: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==195); - case 200: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==200); - case 250: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==250); - case 324: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==324); - case 390: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==390); - case 451: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==451); - case 462: /* partition_list ::= partition_list NK_COMMA partition_item */ yytestcase(yyruleno==462); - case 514: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==514); + case 122: /* retention_list ::= retention_list NK_COMMA retention */ + case 154: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==154); + case 197: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==197); + case 202: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==202); + case 252: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==252); + case 326: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==326); + case 392: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==392); + case 453: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==453); + case 464: /* partition_list ::= partition_list NK_COMMA partition_item */ yytestcase(yyruleno==464); + case 516: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==516); { yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-2].minor.yy282, yymsp[0].minor.yy778); } yymsp[-2].minor.yy282 = yylhsminor.yy282; break; - case 121: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ + case 123: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ { yylhsminor.yy778 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 122: /* speed_opt ::= */ - case 275: /* bufsize_opt ::= */ yytestcase(yyruleno==275); + case 124: /* speed_opt ::= */ + case 277: /* bufsize_opt ::= */ yytestcase(yyruleno==277); { yymsp[1].minor.yy276 = 0; } break; - case 123: /* speed_opt ::= MAX_SPEED NK_INTEGER */ - case 276: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ yytestcase(yyruleno==276); + case 125: /* speed_opt ::= MAX_SPEED NK_INTEGER */ + case 278: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ yytestcase(yyruleno==278); { yymsp[-1].minor.yy276 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 124: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - case 126: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==126); + case 126: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + case 128: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==128); { pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy39, yymsp[-5].minor.yy778, yymsp[-3].minor.yy282, yymsp[-1].minor.yy282, yymsp[0].minor.yy778); } break; - case 125: /* cmd ::= CREATE TABLE multi_create_clause */ + case 127: /* cmd ::= CREATE TABLE multi_create_clause */ { pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy282); } break; - case 127: /* cmd ::= DROP TABLE multi_drop_clause */ + case 129: /* cmd ::= DROP TABLE multi_drop_clause */ { pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy282); } break; - case 128: /* cmd ::= DROP STABLE exists_opt full_table_name */ + case 130: /* cmd ::= DROP STABLE exists_opt full_table_name */ { pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy39, yymsp[0].minor.yy778); } break; - case 129: /* cmd ::= ALTER TABLE alter_table_clause */ - case 297: /* cmd ::= query_or_subquery */ yytestcase(yyruleno==297); + case 131: /* cmd ::= ALTER TABLE alter_table_clause */ + case 299: /* cmd ::= query_or_subquery */ yytestcase(yyruleno==299); { pCxt->pRootNode = yymsp[0].minor.yy778; } break; - case 130: /* cmd ::= ALTER STABLE alter_table_clause */ + case 132: /* cmd ::= ALTER STABLE alter_table_clause */ { pCxt->pRootNode = setAlterSuperTableType(yymsp[0].minor.yy778); } break; - case 131: /* alter_table_clause ::= full_table_name alter_table_options */ + case 133: /* alter_table_clause ::= full_table_name alter_table_options */ { yylhsminor.yy778 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 132: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + case 134: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ { yylhsminor.yy778 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy181, yymsp[0].minor.yy380); } yymsp[-4].minor.yy778 = yylhsminor.yy778; break; - case 133: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ + case 135: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ { yylhsminor.yy778 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy778, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy181); } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 134: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + case 136: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ { yylhsminor.yy778 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy181, yymsp[0].minor.yy380); } yymsp[-4].minor.yy778 = yylhsminor.yy778; break; - case 135: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + case 137: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ { yylhsminor.yy778 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy181, &yymsp[0].minor.yy181); } yymsp[-4].minor.yy778 = yylhsminor.yy778; break; - case 136: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + case 138: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ { yylhsminor.yy778 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy181, yymsp[0].minor.yy380); } yymsp[-4].minor.yy778 = yylhsminor.yy778; break; - case 137: /* alter_table_clause ::= full_table_name DROP TAG column_name */ + case 139: /* alter_table_clause ::= full_table_name DROP TAG column_name */ { yylhsminor.yy778 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy778, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy181); } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 138: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + case 140: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ { yylhsminor.yy778 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy181, yymsp[0].minor.yy380); } yymsp[-4].minor.yy778 = yylhsminor.yy778; break; - case 139: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + case 141: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ { yylhsminor.yy778 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy181, &yymsp[0].minor.yy181); } yymsp[-4].minor.yy778 = yylhsminor.yy778; break; - case 140: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ + case 142: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ { yylhsminor.yy778 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy778, &yymsp[-2].minor.yy181, yymsp[0].minor.yy778); } yymsp[-5].minor.yy778 = yylhsminor.yy778; break; - case 142: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ - case 145: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==145); - case 396: /* when_then_list ::= when_then_list when_then_expr */ yytestcase(yyruleno==396); + case 144: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ + case 147: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==147); + case 398: /* when_then_list ::= when_then_list when_then_expr */ yytestcase(yyruleno==398); { yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-1].minor.yy282, yymsp[0].minor.yy778); } yymsp[-1].minor.yy282 = yylhsminor.yy282; break; - case 143: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ + case 145: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ { yylhsminor.yy778 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy39, yymsp[-8].minor.yy778, yymsp[-6].minor.yy778, yymsp[-5].minor.yy282, yymsp[-2].minor.yy282, yymsp[0].minor.yy778); } yymsp[-9].minor.yy778 = yylhsminor.yy778; break; - case 146: /* drop_table_clause ::= exists_opt full_table_name */ + case 148: /* drop_table_clause ::= exists_opt full_table_name */ { yylhsminor.yy778 = createDropTableClause(pCxt, yymsp[-1].minor.yy39, yymsp[0].minor.yy778); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 147: /* specific_cols_opt ::= */ - case 178: /* tags_def_opt ::= */ yytestcase(yyruleno==178); - case 459: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==459); - case 481: /* group_by_clause_opt ::= */ yytestcase(yyruleno==481); - case 500: /* order_by_clause_opt ::= */ yytestcase(yyruleno==500); + case 149: /* specific_cols_opt ::= */ + case 180: /* tags_def_opt ::= */ yytestcase(yyruleno==180); + case 461: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==461); + case 483: /* group_by_clause_opt ::= */ yytestcase(yyruleno==483); + case 502: /* order_by_clause_opt ::= */ yytestcase(yyruleno==502); { yymsp[1].minor.yy282 = NULL; } break; - case 148: /* specific_cols_opt ::= NK_LP col_name_list NK_RP */ + case 150: /* specific_cols_opt ::= NK_LP col_name_list NK_RP */ { yymsp[-2].minor.yy282 = yymsp[-1].minor.yy282; } break; - case 149: /* full_table_name ::= table_name */ + case 151: /* full_table_name ::= table_name */ { yylhsminor.yy778 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy181, NULL); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 150: /* full_table_name ::= db_name NK_DOT table_name */ + case 152: /* full_table_name ::= db_name NK_DOT table_name */ { yylhsminor.yy778 = createRealTableNode(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy181, NULL); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 153: /* column_def ::= column_name type_name */ + case 155: /* column_def ::= column_name type_name */ { yylhsminor.yy778 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy181, yymsp[0].minor.yy380, NULL); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 154: /* column_def ::= column_name type_name COMMENT NK_STRING */ + case 156: /* column_def ::= column_name type_name COMMENT NK_STRING */ { yylhsminor.yy778 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy181, yymsp[-2].minor.yy380, &yymsp[0].minor.yy0); } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 155: /* type_name ::= BOOL */ + case 157: /* type_name ::= BOOL */ { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_BOOL); } break; - case 156: /* type_name ::= TINYINT */ + case 158: /* type_name ::= TINYINT */ { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; - case 157: /* type_name ::= SMALLINT */ + case 159: /* type_name ::= SMALLINT */ { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; - case 158: /* type_name ::= INT */ - case 159: /* type_name ::= INTEGER */ yytestcase(yyruleno==159); + case 160: /* type_name ::= INT */ + case 161: /* type_name ::= INTEGER */ yytestcase(yyruleno==161); { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_INT); } break; - case 160: /* type_name ::= BIGINT */ + case 162: /* type_name ::= BIGINT */ { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; - case 161: /* type_name ::= FLOAT */ + case 163: /* type_name ::= FLOAT */ { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; - case 162: /* type_name ::= DOUBLE */ + case 164: /* type_name ::= DOUBLE */ { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; - case 163: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + case 165: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ { yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; - case 164: /* type_name ::= TIMESTAMP */ + case 166: /* type_name ::= TIMESTAMP */ { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; - case 165: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + case 167: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ { yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; - case 166: /* type_name ::= TINYINT UNSIGNED */ + case 168: /* type_name ::= TINYINT UNSIGNED */ { yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; - case 167: /* type_name ::= SMALLINT UNSIGNED */ + case 169: /* type_name ::= SMALLINT UNSIGNED */ { yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; - case 168: /* type_name ::= INT UNSIGNED */ + case 170: /* type_name ::= INT UNSIGNED */ { yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_UINT); } break; - case 169: /* type_name ::= BIGINT UNSIGNED */ + case 171: /* type_name ::= BIGINT UNSIGNED */ { yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; - case 170: /* type_name ::= JSON */ + case 172: /* type_name ::= JSON */ { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_JSON); } break; - case 171: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + case 173: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ { yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; - case 172: /* type_name ::= MEDIUMBLOB */ + case 174: /* type_name ::= MEDIUMBLOB */ { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; - case 173: /* type_name ::= BLOB */ + case 175: /* type_name ::= BLOB */ { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_BLOB); } break; - case 174: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + case 176: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ { yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; - case 175: /* type_name ::= DECIMAL */ + case 177: /* type_name ::= DECIMAL */ { yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 176: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + case 178: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ { yymsp[-3].minor.yy380 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 177: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + case 179: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ { yymsp[-5].minor.yy380 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 179: /* tags_def_opt ::= tags_def */ - case 388: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==388); + case 181: /* tags_def_opt ::= tags_def */ + case 390: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==390); { yylhsminor.yy282 = yymsp[0].minor.yy282; } yymsp[0].minor.yy282 = yylhsminor.yy282; break; - case 180: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ + case 182: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ { yymsp[-3].minor.yy282 = yymsp[-1].minor.yy282; } break; - case 181: /* table_options ::= */ + case 183: /* table_options ::= */ { yymsp[1].minor.yy778 = createDefaultTableOptions(pCxt); } break; - case 182: /* table_options ::= table_options COMMENT NK_STRING */ + case 184: /* table_options ::= table_options COMMENT NK_STRING */ { yylhsminor.yy778 = setTableOption(pCxt, yymsp[-2].minor.yy778, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 183: /* table_options ::= table_options MAX_DELAY duration_list */ + case 185: /* table_options ::= table_options MAX_DELAY duration_list */ { yylhsminor.yy778 = setTableOption(pCxt, yymsp[-2].minor.yy778, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy282); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 184: /* table_options ::= table_options WATERMARK duration_list */ + case 186: /* table_options ::= table_options WATERMARK duration_list */ { yylhsminor.yy778 = setTableOption(pCxt, yymsp[-2].minor.yy778, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy282); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 185: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ + case 187: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ { yylhsminor.yy778 = setTableOption(pCxt, yymsp[-4].minor.yy778, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy282); } yymsp[-4].minor.yy778 = yylhsminor.yy778; break; - case 186: /* table_options ::= table_options TTL NK_INTEGER */ + case 188: /* table_options ::= table_options TTL NK_INTEGER */ { yylhsminor.yy778 = setTableOption(pCxt, yymsp[-2].minor.yy778, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 187: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + case 189: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ { yylhsminor.yy778 = setTableOption(pCxt, yymsp[-4].minor.yy778, TABLE_OPTION_SMA, yymsp[-1].minor.yy282); } yymsp[-4].minor.yy778 = yylhsminor.yy778; break; - case 188: /* alter_table_options ::= alter_table_option */ + case 190: /* alter_table_options ::= alter_table_option */ { yylhsminor.yy778 = createAlterTableOptions(pCxt); yylhsminor.yy778 = setTableOption(pCxt, yylhsminor.yy778, yymsp[0].minor.yy645.type, &yymsp[0].minor.yy645.val); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 189: /* alter_table_options ::= alter_table_options alter_table_option */ + case 191: /* alter_table_options ::= alter_table_options alter_table_option */ { yylhsminor.yy778 = setTableOption(pCxt, yymsp[-1].minor.yy778, yymsp[0].minor.yy645.type, &yymsp[0].minor.yy645.val); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 190: /* alter_table_option ::= COMMENT NK_STRING */ + case 192: /* alter_table_option ::= COMMENT NK_STRING */ { yymsp[-1].minor.yy645.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } break; - case 191: /* alter_table_option ::= TTL NK_INTEGER */ + case 193: /* alter_table_option ::= TTL NK_INTEGER */ { yymsp[-1].minor.yy645.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } break; - case 192: /* duration_list ::= duration_literal */ - case 353: /* expression_list ::= expr_or_subquery */ yytestcase(yyruleno==353); + case 194: /* duration_list ::= duration_literal */ + case 355: /* expression_list ::= expr_or_subquery */ yytestcase(yyruleno==355); { yylhsminor.yy282 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy778)); } yymsp[0].minor.yy282 = yylhsminor.yy282; break; - case 193: /* duration_list ::= duration_list NK_COMMA duration_literal */ - case 354: /* expression_list ::= expression_list NK_COMMA expr_or_subquery */ yytestcase(yyruleno==354); + case 195: /* duration_list ::= duration_list NK_COMMA duration_literal */ + case 356: /* expression_list ::= expression_list NK_COMMA expr_or_subquery */ yytestcase(yyruleno==356); { yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-2].minor.yy282, releaseRawExprNode(pCxt, yymsp[0].minor.yy778)); } yymsp[-2].minor.yy282 = yylhsminor.yy282; break; - case 196: /* rollup_func_name ::= function_name */ + case 198: /* rollup_func_name ::= function_name */ { yylhsminor.yy778 = createFunctionNode(pCxt, &yymsp[0].minor.yy181, NULL); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 197: /* rollup_func_name ::= FIRST */ - case 198: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==198); + case 199: /* rollup_func_name ::= FIRST */ + case 200: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==200); { yylhsminor.yy778 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 201: /* col_name ::= column_name */ + case 203: /* col_name ::= column_name */ { yylhsminor.yy778 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy181); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 202: /* cmd ::= SHOW DNODES */ + case 204: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); } break; - case 203: /* cmd ::= SHOW USERS */ + case 205: /* cmd ::= SHOW USERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); } break; - case 204: /* cmd ::= SHOW DATABASES */ + case 206: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); } break; - case 205: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + case 207: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy778, yymsp[0].minor.yy778, OP_TYPE_LIKE); } break; - case 206: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + case 208: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy778, yymsp[0].minor.yy778, OP_TYPE_LIKE); } break; - case 207: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ + case 209: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy778, NULL, OP_TYPE_LIKE); } break; - case 208: /* cmd ::= SHOW MNODES */ + case 210: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT); } break; - case 209: /* cmd ::= SHOW QNODES */ + case 211: /* cmd ::= SHOW QNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT); } break; - case 210: /* cmd ::= SHOW FUNCTIONS */ + case 212: /* cmd ::= SHOW FUNCTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT); } break; - case 211: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + case 213: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy778, yymsp[-1].minor.yy778, OP_TYPE_EQUAL); } break; - case 212: /* cmd ::= SHOW STREAMS */ + case 214: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT); } break; - case 213: /* cmd ::= SHOW ACCOUNTS */ + case 215: /* cmd ::= SHOW ACCOUNTS */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } break; - case 214: /* cmd ::= SHOW APPS */ + case 216: /* cmd ::= SHOW APPS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT); } break; - case 215: /* cmd ::= SHOW CONNECTIONS */ + case 217: /* cmd ::= SHOW CONNECTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT); } break; - case 216: /* cmd ::= SHOW LICENCES */ - case 217: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==217); + case 218: /* cmd ::= SHOW LICENCES */ + case 219: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==219); { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCES_STMT); } break; - case 218: /* cmd ::= SHOW CREATE DATABASE db_name */ + case 220: /* cmd ::= SHOW CREATE DATABASE db_name */ { pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy181); } break; - case 219: /* cmd ::= SHOW CREATE TABLE full_table_name */ + case 221: /* cmd ::= SHOW CREATE TABLE full_table_name */ { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy778); } break; - case 220: /* cmd ::= SHOW CREATE STABLE full_table_name */ + case 222: /* cmd ::= SHOW CREATE STABLE full_table_name */ { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy778); } break; - case 221: /* cmd ::= SHOW QUERIES */ + case 223: /* cmd ::= SHOW QUERIES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); } break; - case 222: /* cmd ::= SHOW SCORES */ + case 224: /* cmd ::= SHOW SCORES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); } break; - case 223: /* cmd ::= SHOW TOPICS */ + case 225: /* cmd ::= SHOW TOPICS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); } break; - case 224: /* cmd ::= SHOW VARIABLES */ + case 226: /* cmd ::= SHOW VARIABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } break; - case 225: /* cmd ::= SHOW LOCAL VARIABLES */ + case 227: /* cmd ::= SHOW LOCAL VARIABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); } break; - case 226: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ + case 228: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[-1].minor.yy0)); } break; - case 227: /* cmd ::= SHOW BNODES */ + case 229: /* cmd ::= SHOW BNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); } break; - case 228: /* cmd ::= SHOW SNODES */ + case 230: /* cmd ::= SHOW SNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); } break; - case 229: /* cmd ::= SHOW CLUSTER */ + case 231: /* cmd ::= SHOW CLUSTER */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); } break; - case 230: /* cmd ::= SHOW TRANSACTIONS */ + case 232: /* cmd ::= SHOW TRANSACTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); } break; - case 231: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ + case 233: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ { pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy778); } break; - case 232: /* cmd ::= SHOW CONSUMERS */ + case 234: /* cmd ::= SHOW CONSUMERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); } break; - case 233: /* cmd ::= SHOW SUBSCRIPTIONS */ + case 235: /* cmd ::= SHOW SUBSCRIPTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); } break; - case 234: /* cmd ::= SHOW TAGS FROM table_name_cond from_db_opt */ + case 236: /* cmd ::= SHOW TAGS FROM table_name_cond from_db_opt */ { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TAGS_STMT, yymsp[0].minor.yy778, yymsp[-1].minor.yy778, OP_TYPE_EQUAL); } break; - case 235: /* cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt */ + case 237: /* cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt */ { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLE_TAGS_STMT, yymsp[0].minor.yy778, yymsp[-1].minor.yy778, OP_TYPE_EQUAL); } break; - case 236: /* cmd ::= SHOW VNODES NK_INTEGER */ + case 238: /* cmd ::= SHOW VNODES NK_INTEGER */ { pCxt->pRootNode = createShowVnodesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0), NULL); } break; - case 237: /* cmd ::= SHOW VNODES NK_STRING */ + case 239: /* cmd ::= SHOW VNODES NK_STRING */ { pCxt->pRootNode = createShowVnodesStmt(pCxt, NULL, createValueNode(pCxt, TSDB_DATA_TYPE_VARCHAR, &yymsp[0].minor.yy0)); } break; - case 238: /* db_name_cond_opt ::= */ - case 243: /* from_db_opt ::= */ yytestcase(yyruleno==243); + case 240: /* db_name_cond_opt ::= */ + case 245: /* from_db_opt ::= */ yytestcase(yyruleno==245); { yymsp[1].minor.yy778 = createDefaultDatabaseCondValue(pCxt); } break; - case 239: /* db_name_cond_opt ::= db_name NK_DOT */ + case 241: /* db_name_cond_opt ::= db_name NK_DOT */ { yylhsminor.yy778 = createIdentifierValueNode(pCxt, &yymsp[-1].minor.yy181); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 240: /* like_pattern_opt ::= */ - case 285: /* subtable_opt ::= */ yytestcase(yyruleno==285); - case 398: /* case_when_else_opt ::= */ yytestcase(yyruleno==398); - case 428: /* from_clause_opt ::= */ yytestcase(yyruleno==428); - case 457: /* where_clause_opt ::= */ yytestcase(yyruleno==457); - case 466: /* twindow_clause_opt ::= */ yytestcase(yyruleno==466); - case 471: /* sliding_opt ::= */ yytestcase(yyruleno==471); - case 473: /* fill_opt ::= */ yytestcase(yyruleno==473); - case 485: /* having_clause_opt ::= */ yytestcase(yyruleno==485); - case 487: /* range_opt ::= */ yytestcase(yyruleno==487); - case 489: /* every_opt ::= */ yytestcase(yyruleno==489); - case 502: /* slimit_clause_opt ::= */ yytestcase(yyruleno==502); - case 506: /* limit_clause_opt ::= */ yytestcase(yyruleno==506); + case 242: /* like_pattern_opt ::= */ + case 287: /* subtable_opt ::= */ yytestcase(yyruleno==287); + case 400: /* case_when_else_opt ::= */ yytestcase(yyruleno==400); + case 430: /* from_clause_opt ::= */ yytestcase(yyruleno==430); + case 459: /* where_clause_opt ::= */ yytestcase(yyruleno==459); + case 468: /* twindow_clause_opt ::= */ yytestcase(yyruleno==468); + case 473: /* sliding_opt ::= */ yytestcase(yyruleno==473); + case 475: /* fill_opt ::= */ yytestcase(yyruleno==475); + case 487: /* having_clause_opt ::= */ yytestcase(yyruleno==487); + case 489: /* range_opt ::= */ yytestcase(yyruleno==489); + case 491: /* every_opt ::= */ yytestcase(yyruleno==491); + case 504: /* slimit_clause_opt ::= */ yytestcase(yyruleno==504); + case 508: /* limit_clause_opt ::= */ yytestcase(yyruleno==508); { yymsp[1].minor.yy778 = NULL; } break; - case 241: /* like_pattern_opt ::= LIKE NK_STRING */ + case 243: /* like_pattern_opt ::= LIKE NK_STRING */ { yymsp[-1].minor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 242: /* table_name_cond ::= table_name */ + case 244: /* table_name_cond ::= table_name */ { yylhsminor.yy778 = createIdentifierValueNode(pCxt, &yymsp[0].minor.yy181); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 244: /* from_db_opt ::= FROM db_name */ + case 246: /* from_db_opt ::= FROM db_name */ { yymsp[-1].minor.yy778 = createIdentifierValueNode(pCxt, &yymsp[0].minor.yy181); } break; - case 245: /* cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options */ + case 247: /* cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options */ { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy39, yymsp[-3].minor.yy778, yymsp[-1].minor.yy778, NULL, yymsp[0].minor.yy778); } break; - case 246: /* cmd ::= DROP INDEX exists_opt full_table_name */ + case 248: /* cmd ::= DROP INDEX exists_opt full_table_name */ { pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-1].minor.yy39, yymsp[0].minor.yy778); } break; - case 247: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ + case 249: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ { yymsp[-9].minor.yy778 = createIndexOption(pCxt, yymsp[-7].minor.yy282, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), NULL, yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } break; - case 248: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ + case 250: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ { yymsp[-11].minor.yy778 = createIndexOption(pCxt, yymsp[-9].minor.yy282, releaseRawExprNode(pCxt, yymsp[-5].minor.yy778), releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } break; - case 251: /* func ::= function_name NK_LP expression_list NK_RP */ + case 253: /* func ::= function_name NK_LP expression_list NK_RP */ { yylhsminor.yy778 = createFunctionNode(pCxt, &yymsp[-3].minor.yy181, yymsp[-1].minor.yy282); } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 252: /* sma_stream_opt ::= */ - case 279: /* stream_options ::= */ yytestcase(yyruleno==279); + case 254: /* sma_stream_opt ::= */ + case 281: /* stream_options ::= */ yytestcase(yyruleno==281); { yymsp[1].minor.yy778 = createStreamOptions(pCxt); } break; - case 253: /* sma_stream_opt ::= stream_options WATERMARK duration_literal */ - case 283: /* stream_options ::= stream_options WATERMARK duration_literal */ yytestcase(yyruleno==283); + case 255: /* sma_stream_opt ::= stream_options WATERMARK duration_literal */ + case 285: /* stream_options ::= stream_options WATERMARK duration_literal */ yytestcase(yyruleno==285); { ((SStreamOptions*)yymsp[-2].minor.yy778)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy778); yylhsminor.yy778 = yymsp[-2].minor.yy778; } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 254: /* sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ + case 256: /* sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ { ((SStreamOptions*)yymsp[-2].minor.yy778)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy778); yylhsminor.yy778 = yymsp[-2].minor.yy778; } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 255: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery */ + case 257: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery */ { pCxt->pRootNode = createCreateTopicStmtUseQuery(pCxt, yymsp[-3].minor.yy39, &yymsp[-2].minor.yy181, yymsp[0].minor.yy778); } break; - case 256: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ + case 258: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ { pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-4].minor.yy39, &yymsp[-3].minor.yy181, &yymsp[0].minor.yy181, false); } break; - case 257: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ + case 259: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ { pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-6].minor.yy39, &yymsp[-5].minor.yy181, &yymsp[0].minor.yy181, true); } break; - case 258: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ + case 260: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ { pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-4].minor.yy39, &yymsp[-3].minor.yy181, yymsp[0].minor.yy778, false); } break; - case 259: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ + case 261: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ { pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-6].minor.yy39, &yymsp[-5].minor.yy181, yymsp[0].minor.yy778, true); } break; - case 260: /* cmd ::= DROP TOPIC exists_opt topic_name */ + case 262: /* cmd ::= DROP TOPIC exists_opt topic_name */ { pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy39, &yymsp[0].minor.yy181); } break; - case 261: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ + case 263: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ { pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy39, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy181); } break; - case 262: /* cmd ::= DESC full_table_name */ - case 263: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==263); + case 264: /* cmd ::= DESC full_table_name */ + case 265: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==265); { pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy778); } break; - case 264: /* cmd ::= RESET QUERY CACHE */ + case 266: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; - case 265: /* cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery */ + case 267: /* cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery */ { pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy39, yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } break; - case 267: /* analyze_opt ::= ANALYZE */ - case 274: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==274); - case 448: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==448); + case 269: /* analyze_opt ::= ANALYZE */ + case 276: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==276); + case 450: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==450); { yymsp[0].minor.yy39 = true; } break; - case 268: /* explain_options ::= */ + case 270: /* explain_options ::= */ { yymsp[1].minor.yy778 = createDefaultExplainOptions(pCxt); } break; - case 269: /* explain_options ::= explain_options VERBOSE NK_BOOL */ + case 271: /* explain_options ::= explain_options VERBOSE NK_BOOL */ { yylhsminor.yy778 = setExplainVerbose(pCxt, yymsp[-2].minor.yy778, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 270: /* explain_options ::= explain_options RATIO NK_FLOAT */ + case 272: /* explain_options ::= explain_options RATIO NK_FLOAT */ { yylhsminor.yy778 = setExplainRatio(pCxt, yymsp[-2].minor.yy778, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 271: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ + case 273: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ { pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy39, yymsp[-8].minor.yy39, &yymsp[-5].minor.yy181, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy380, yymsp[0].minor.yy276); } break; - case 272: /* cmd ::= DROP FUNCTION exists_opt function_name */ + case 274: /* cmd ::= DROP FUNCTION exists_opt function_name */ { pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy39, &yymsp[0].minor.yy181); } break; - case 277: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery */ + case 279: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery */ { pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-8].minor.yy39, &yymsp[-7].minor.yy181, yymsp[-4].minor.yy778, yymsp[-6].minor.yy778, yymsp[-3].minor.yy282, yymsp[-2].minor.yy778, yymsp[0].minor.yy778); } break; - case 278: /* cmd ::= DROP STREAM exists_opt stream_name */ + case 280: /* cmd ::= DROP STREAM exists_opt stream_name */ { pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy39, &yymsp[0].minor.yy181); } break; - case 280: /* stream_options ::= stream_options TRIGGER AT_ONCE */ + case 282: /* stream_options ::= stream_options TRIGGER AT_ONCE */ { ((SStreamOptions*)yymsp[-2].minor.yy778)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy778 = yymsp[-2].minor.yy778; } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 281: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ + case 283: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ { ((SStreamOptions*)yymsp[-2].minor.yy778)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy778 = yymsp[-2].minor.yy778; } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 282: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ + case 284: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ { ((SStreamOptions*)yymsp[-3].minor.yy778)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)yymsp[-3].minor.yy778)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy778); yylhsminor.yy778 = yymsp[-3].minor.yy778; } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 284: /* stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */ + case 286: /* stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */ { ((SStreamOptions*)yymsp[-3].minor.yy778)->ignoreExpired = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); yylhsminor.yy778 = yymsp[-3].minor.yy778; } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 286: /* subtable_opt ::= SUBTABLE NK_LP expression NK_RP */ - case 472: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ yytestcase(yyruleno==472); - case 490: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==490); + case 288: /* subtable_opt ::= SUBTABLE NK_LP expression NK_RP */ + case 474: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ yytestcase(yyruleno==474); + case 492: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==492); { yymsp[-3].minor.yy778 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy778); } break; - case 287: /* cmd ::= KILL CONNECTION NK_INTEGER */ + case 289: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } break; - case 288: /* cmd ::= KILL QUERY NK_STRING */ + case 290: /* cmd ::= KILL QUERY NK_STRING */ { pCxt->pRootNode = createKillQueryStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 289: /* cmd ::= KILL TRANSACTION NK_INTEGER */ + case 291: /* cmd ::= KILL TRANSACTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_TRANSACTION_STMT, &yymsp[0].minor.yy0); } break; - case 290: /* cmd ::= BALANCE VGROUP */ + case 292: /* cmd ::= BALANCE VGROUP */ { pCxt->pRootNode = createBalanceVgroupStmt(pCxt); } break; - case 291: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + case 293: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 292: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + case 294: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ { pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy282); } break; - case 293: /* cmd ::= SPLIT VGROUP NK_INTEGER */ + case 295: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 294: /* dnode_list ::= DNODE NK_INTEGER */ + case 296: /* dnode_list ::= DNODE NK_INTEGER */ { yymsp[-1].minor.yy282 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } break; - case 296: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ + case 298: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ { pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } break; - case 298: /* cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */ + case 300: /* cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */ { pCxt->pRootNode = createInsertStmt(pCxt, yymsp[-4].minor.yy778, yymsp[-2].minor.yy282, yymsp[0].minor.yy778); } break; - case 299: /* cmd ::= INSERT INTO full_table_name query_or_subquery */ + case 301: /* cmd ::= INSERT INTO full_table_name query_or_subquery */ { pCxt->pRootNode = createInsertStmt(pCxt, yymsp[-1].minor.yy778, NULL, yymsp[0].minor.yy778); } break; - case 300: /* literal ::= NK_INTEGER */ + case 302: /* literal ::= NK_INTEGER */ { yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 301: /* literal ::= NK_FLOAT */ + case 303: /* literal ::= NK_FLOAT */ { yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 302: /* literal ::= NK_STRING */ + case 304: /* literal ::= NK_STRING */ { yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 303: /* literal ::= NK_BOOL */ + case 305: /* literal ::= NK_BOOL */ { yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 304: /* literal ::= TIMESTAMP NK_STRING */ + case 306: /* literal ::= TIMESTAMP NK_STRING */ { yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 305: /* literal ::= duration_literal */ - case 315: /* signed_literal ::= signed */ yytestcase(yyruleno==315); - case 335: /* expr_or_subquery ::= expression */ yytestcase(yyruleno==335); - case 336: /* expr_or_subquery ::= subquery */ yytestcase(yyruleno==336); - case 337: /* expression ::= literal */ yytestcase(yyruleno==337); - case 338: /* expression ::= pseudo_column */ yytestcase(yyruleno==338); - case 339: /* expression ::= column_reference */ yytestcase(yyruleno==339); - case 340: /* expression ::= function_expression */ yytestcase(yyruleno==340); - case 341: /* expression ::= case_when_expression */ yytestcase(yyruleno==341); - case 371: /* function_expression ::= literal_func */ yytestcase(yyruleno==371); - case 420: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==420); - case 424: /* boolean_primary ::= predicate */ yytestcase(yyruleno==424); - case 426: /* common_expression ::= expr_or_subquery */ yytestcase(yyruleno==426); - case 427: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==427); - case 430: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==430); - case 432: /* table_reference ::= table_primary */ yytestcase(yyruleno==432); - case 433: /* table_reference ::= joined_table */ yytestcase(yyruleno==433); - case 437: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==437); - case 492: /* query_simple ::= query_specification */ yytestcase(yyruleno==492); - case 493: /* query_simple ::= union_query_expression */ yytestcase(yyruleno==493); - case 496: /* query_simple_or_subquery ::= query_simple */ yytestcase(yyruleno==496); - case 498: /* query_or_subquery ::= query_expression */ yytestcase(yyruleno==498); + case 307: /* literal ::= duration_literal */ + case 317: /* signed_literal ::= signed */ yytestcase(yyruleno==317); + case 337: /* expr_or_subquery ::= expression */ yytestcase(yyruleno==337); + case 338: /* expr_or_subquery ::= subquery */ yytestcase(yyruleno==338); + case 339: /* expression ::= literal */ yytestcase(yyruleno==339); + case 340: /* expression ::= pseudo_column */ yytestcase(yyruleno==340); + case 341: /* expression ::= column_reference */ yytestcase(yyruleno==341); + case 342: /* expression ::= function_expression */ yytestcase(yyruleno==342); + case 343: /* expression ::= case_when_expression */ yytestcase(yyruleno==343); + case 373: /* function_expression ::= literal_func */ yytestcase(yyruleno==373); + case 422: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==422); + case 426: /* boolean_primary ::= predicate */ yytestcase(yyruleno==426); + case 428: /* common_expression ::= expr_or_subquery */ yytestcase(yyruleno==428); + case 429: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==429); + case 432: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==432); + case 434: /* table_reference ::= table_primary */ yytestcase(yyruleno==434); + case 435: /* table_reference ::= joined_table */ yytestcase(yyruleno==435); + case 439: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==439); + case 494: /* query_simple ::= query_specification */ yytestcase(yyruleno==494); + case 495: /* query_simple ::= union_query_expression */ yytestcase(yyruleno==495); + case 498: /* query_simple_or_subquery ::= query_simple */ yytestcase(yyruleno==498); + case 500: /* query_or_subquery ::= query_expression */ yytestcase(yyruleno==500); { yylhsminor.yy778 = yymsp[0].minor.yy778; } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 306: /* literal ::= NULL */ + case 308: /* literal ::= NULL */ { yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 307: /* literal ::= NK_QUESTION */ + case 309: /* literal ::= NK_QUESTION */ { yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 308: /* duration_literal ::= NK_VARIABLE */ + case 310: /* duration_literal ::= NK_VARIABLE */ { yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 309: /* signed ::= NK_INTEGER */ + case 311: /* signed ::= NK_INTEGER */ { yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 310: /* signed ::= NK_PLUS NK_INTEGER */ + case 312: /* signed ::= NK_PLUS NK_INTEGER */ { yymsp[-1].minor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0); } break; - case 311: /* signed ::= NK_MINUS NK_INTEGER */ + case 313: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; @@ -4610,14 +4620,14 @@ static YYACTIONTYPE yy_reduce( } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 312: /* signed ::= NK_FLOAT */ + case 314: /* signed ::= NK_FLOAT */ { yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 313: /* signed ::= NK_PLUS NK_FLOAT */ + case 315: /* signed ::= NK_PLUS NK_FLOAT */ { yymsp[-1].minor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 314: /* signed ::= NK_MINUS NK_FLOAT */ + case 316: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; @@ -4625,57 +4635,57 @@ static YYACTIONTYPE yy_reduce( } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 316: /* signed_literal ::= NK_STRING */ + case 318: /* signed_literal ::= NK_STRING */ { yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 317: /* signed_literal ::= NK_BOOL */ + case 319: /* signed_literal ::= NK_BOOL */ { yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 318: /* signed_literal ::= TIMESTAMP NK_STRING */ + case 320: /* signed_literal ::= TIMESTAMP NK_STRING */ { yymsp[-1].minor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 319: /* signed_literal ::= duration_literal */ - case 321: /* signed_literal ::= literal_func */ yytestcase(yyruleno==321); - case 391: /* star_func_para ::= expr_or_subquery */ yytestcase(yyruleno==391); - case 453: /* select_item ::= common_expression */ yytestcase(yyruleno==453); - case 463: /* partition_item ::= expr_or_subquery */ yytestcase(yyruleno==463); - case 497: /* query_simple_or_subquery ::= subquery */ yytestcase(yyruleno==497); - case 499: /* query_or_subquery ::= subquery */ yytestcase(yyruleno==499); - case 512: /* search_condition ::= common_expression */ yytestcase(yyruleno==512); + case 321: /* signed_literal ::= duration_literal */ + case 323: /* signed_literal ::= literal_func */ yytestcase(yyruleno==323); + case 393: /* star_func_para ::= expr_or_subquery */ yytestcase(yyruleno==393); + case 455: /* select_item ::= common_expression */ yytestcase(yyruleno==455); + case 465: /* partition_item ::= expr_or_subquery */ yytestcase(yyruleno==465); + case 499: /* query_simple_or_subquery ::= subquery */ yytestcase(yyruleno==499); + case 501: /* query_or_subquery ::= subquery */ yytestcase(yyruleno==501); + case 514: /* search_condition ::= common_expression */ yytestcase(yyruleno==514); { yylhsminor.yy778 = releaseRawExprNode(pCxt, yymsp[0].minor.yy778); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 320: /* signed_literal ::= NULL */ + case 322: /* signed_literal ::= NULL */ { yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 322: /* signed_literal ::= NK_QUESTION */ + case 324: /* signed_literal ::= NK_QUESTION */ { yylhsminor.yy778 = createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 342: /* expression ::= NK_LP expression NK_RP */ - case 425: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==425); - case 511: /* subquery ::= NK_LP subquery NK_RP */ yytestcase(yyruleno==511); + case 344: /* expression ::= NK_LP expression NK_RP */ + case 427: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==427); + case 513: /* subquery ::= NK_LP subquery NK_RP */ yytestcase(yyruleno==513); { yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy778)); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 343: /* expression ::= NK_PLUS expr_or_subquery */ + case 345: /* expression ::= NK_PLUS expr_or_subquery */ { SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy778)); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 344: /* expression ::= NK_MINUS expr_or_subquery */ + case 346: /* expression ::= NK_MINUS expr_or_subquery */ { SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy778), NULL)); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 345: /* expression ::= expr_or_subquery NK_PLUS expr_or_subquery */ + case 347: /* expression ::= expr_or_subquery NK_PLUS expr_or_subquery */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4683,7 +4693,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 346: /* expression ::= expr_or_subquery NK_MINUS expr_or_subquery */ + case 348: /* expression ::= expr_or_subquery NK_MINUS expr_or_subquery */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4691,7 +4701,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 347: /* expression ::= expr_or_subquery NK_STAR expr_or_subquery */ + case 349: /* expression ::= expr_or_subquery NK_STAR expr_or_subquery */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4699,7 +4709,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 348: /* expression ::= expr_or_subquery NK_SLASH expr_or_subquery */ + case 350: /* expression ::= expr_or_subquery NK_SLASH expr_or_subquery */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4707,7 +4717,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 349: /* expression ::= expr_or_subquery NK_REM expr_or_subquery */ + case 351: /* expression ::= expr_or_subquery NK_REM expr_or_subquery */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4715,14 +4725,14 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 350: /* expression ::= column_reference NK_ARROW NK_STRING */ + case 352: /* expression ::= column_reference NK_ARROW NK_STRING */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 351: /* expression ::= expr_or_subquery NK_BITAND expr_or_subquery */ + case 353: /* expression ::= expr_or_subquery NK_BITAND expr_or_subquery */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4730,7 +4740,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 352: /* expression ::= expr_or_subquery NK_BITOR expr_or_subquery */ + case 354: /* expression ::= expr_or_subquery NK_BITOR expr_or_subquery */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4738,70 +4748,70 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 355: /* column_reference ::= column_name */ + case 357: /* column_reference ::= column_name */ { yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy181, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy181)); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 356: /* column_reference ::= table_name NK_DOT column_name */ + case 358: /* column_reference ::= table_name NK_DOT column_name */ { yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy181, createColumnNode(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy181)); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 357: /* pseudo_column ::= ROWTS */ - case 358: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==358); - case 360: /* pseudo_column ::= QSTART */ yytestcase(yyruleno==360); - case 361: /* pseudo_column ::= QEND */ yytestcase(yyruleno==361); - case 362: /* pseudo_column ::= QDURATION */ yytestcase(yyruleno==362); - case 363: /* pseudo_column ::= WSTART */ yytestcase(yyruleno==363); - case 364: /* pseudo_column ::= WEND */ yytestcase(yyruleno==364); - case 365: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==365); - case 366: /* pseudo_column ::= IROWTS */ yytestcase(yyruleno==366); - case 367: /* pseudo_column ::= QTAGS */ yytestcase(yyruleno==367); - case 373: /* literal_func ::= NOW */ yytestcase(yyruleno==373); + case 359: /* pseudo_column ::= ROWTS */ + case 360: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==360); + case 362: /* pseudo_column ::= QSTART */ yytestcase(yyruleno==362); + case 363: /* pseudo_column ::= QEND */ yytestcase(yyruleno==363); + case 364: /* pseudo_column ::= QDURATION */ yytestcase(yyruleno==364); + case 365: /* pseudo_column ::= WSTART */ yytestcase(yyruleno==365); + case 366: /* pseudo_column ::= WEND */ yytestcase(yyruleno==366); + case 367: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==367); + case 368: /* pseudo_column ::= IROWTS */ yytestcase(yyruleno==368); + case 369: /* pseudo_column ::= QTAGS */ yytestcase(yyruleno==369); + case 375: /* literal_func ::= NOW */ yytestcase(yyruleno==375); { yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 359: /* pseudo_column ::= table_name NK_DOT TBNAME */ + case 361: /* pseudo_column ::= table_name NK_DOT TBNAME */ { yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy181)))); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 368: /* function_expression ::= function_name NK_LP expression_list NK_RP */ - case 369: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==369); + case 370: /* function_expression ::= function_name NK_LP expression_list NK_RP */ + case 371: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==371); { yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy181, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy181, yymsp[-1].minor.yy282)); } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 370: /* function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP */ + case 372: /* function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP */ { yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), yymsp[-1].minor.yy380)); } yymsp[-5].minor.yy778 = yylhsminor.yy778; break; - case 372: /* literal_func ::= noarg_func NK_LP NK_RP */ + case 374: /* literal_func ::= noarg_func NK_LP NK_RP */ { yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy181, NULL)); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 387: /* star_func_para_list ::= NK_STAR */ + case 389: /* star_func_para_list ::= NK_STAR */ { yylhsminor.yy282 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy282 = yylhsminor.yy282; break; - case 392: /* star_func_para ::= table_name NK_DOT NK_STAR */ - case 456: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==456); + case 394: /* star_func_para ::= table_name NK_DOT NK_STAR */ + case 458: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==458); { yylhsminor.yy778 = createColumnNode(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 393: /* case_when_expression ::= CASE when_then_list case_when_else_opt END */ + case 395: /* case_when_expression ::= CASE when_then_list case_when_else_opt END */ { yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, createCaseWhenNode(pCxt, NULL, yymsp[-2].minor.yy282, yymsp[-1].minor.yy778)); } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 394: /* case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END */ + case 396: /* case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END */ { yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0, createCaseWhenNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), yymsp[-2].minor.yy282, yymsp[-1].minor.yy778)); } yymsp[-4].minor.yy778 = yylhsminor.yy778; break; - case 397: /* when_then_expr ::= WHEN common_expression THEN common_expression */ + case 399: /* when_then_expr ::= WHEN common_expression THEN common_expression */ { yymsp[-3].minor.yy778 = createWhenThenNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778)); } break; - case 399: /* case_when_else_opt ::= ELSE common_expression */ + case 401: /* case_when_else_opt ::= ELSE common_expression */ { yymsp[-1].minor.yy778 = releaseRawExprNode(pCxt, yymsp[0].minor.yy778); } break; - case 400: /* predicate ::= expr_or_subquery compare_op expr_or_subquery */ - case 405: /* predicate ::= expr_or_subquery in_op in_predicate_value */ yytestcase(yyruleno==405); + case 402: /* predicate ::= expr_or_subquery compare_op expr_or_subquery */ + case 407: /* predicate ::= expr_or_subquery in_op in_predicate_value */ yytestcase(yyruleno==407); { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4809,7 +4819,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 401: /* predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery */ + case 403: /* predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4817,7 +4827,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-4].minor.yy778 = yylhsminor.yy778; break; - case 402: /* predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery */ + case 404: /* predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4825,71 +4835,71 @@ static YYACTIONTYPE yy_reduce( } yymsp[-5].minor.yy778 = yylhsminor.yy778; break; - case 403: /* predicate ::= expr_or_subquery IS NULL */ + case 405: /* predicate ::= expr_or_subquery IS NULL */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), NULL)); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 404: /* predicate ::= expr_or_subquery IS NOT NULL */ + case 406: /* predicate ::= expr_or_subquery IS NOT NULL */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy778); yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), NULL)); } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 406: /* compare_op ::= NK_LT */ + case 408: /* compare_op ::= NK_LT */ { yymsp[0].minor.yy682 = OP_TYPE_LOWER_THAN; } break; - case 407: /* compare_op ::= NK_GT */ + case 409: /* compare_op ::= NK_GT */ { yymsp[0].minor.yy682 = OP_TYPE_GREATER_THAN; } break; - case 408: /* compare_op ::= NK_LE */ + case 410: /* compare_op ::= NK_LE */ { yymsp[0].minor.yy682 = OP_TYPE_LOWER_EQUAL; } break; - case 409: /* compare_op ::= NK_GE */ + case 411: /* compare_op ::= NK_GE */ { yymsp[0].minor.yy682 = OP_TYPE_GREATER_EQUAL; } break; - case 410: /* compare_op ::= NK_NE */ + case 412: /* compare_op ::= NK_NE */ { yymsp[0].minor.yy682 = OP_TYPE_NOT_EQUAL; } break; - case 411: /* compare_op ::= NK_EQ */ + case 413: /* compare_op ::= NK_EQ */ { yymsp[0].minor.yy682 = OP_TYPE_EQUAL; } break; - case 412: /* compare_op ::= LIKE */ + case 414: /* compare_op ::= LIKE */ { yymsp[0].minor.yy682 = OP_TYPE_LIKE; } break; - case 413: /* compare_op ::= NOT LIKE */ + case 415: /* compare_op ::= NOT LIKE */ { yymsp[-1].minor.yy682 = OP_TYPE_NOT_LIKE; } break; - case 414: /* compare_op ::= MATCH */ + case 416: /* compare_op ::= MATCH */ { yymsp[0].minor.yy682 = OP_TYPE_MATCH; } break; - case 415: /* compare_op ::= NMATCH */ + case 417: /* compare_op ::= NMATCH */ { yymsp[0].minor.yy682 = OP_TYPE_NMATCH; } break; - case 416: /* compare_op ::= CONTAINS */ + case 418: /* compare_op ::= CONTAINS */ { yymsp[0].minor.yy682 = OP_TYPE_JSON_CONTAINS; } break; - case 417: /* in_op ::= IN */ + case 419: /* in_op ::= IN */ { yymsp[0].minor.yy682 = OP_TYPE_IN; } break; - case 418: /* in_op ::= NOT IN */ + case 420: /* in_op ::= NOT IN */ { yymsp[-1].minor.yy682 = OP_TYPE_NOT_IN; } break; - case 419: /* in_predicate_value ::= NK_LP literal_list NK_RP */ + case 421: /* in_predicate_value ::= NK_LP literal_list NK_RP */ { yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy282)); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 421: /* boolean_value_expression ::= NOT boolean_primary */ + case 423: /* boolean_value_expression ::= NOT boolean_primary */ { SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy778), NULL)); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 422: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 424: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4897,7 +4907,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 423: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 425: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); @@ -4905,52 +4915,52 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 429: /* from_clause_opt ::= FROM table_reference_list */ - case 458: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==458); - case 486: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==486); + case 431: /* from_clause_opt ::= FROM table_reference_list */ + case 460: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==460); + case 488: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==488); { yymsp[-1].minor.yy778 = yymsp[0].minor.yy778; } break; - case 431: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ + case 433: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ { yylhsminor.yy778 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy778, yymsp[0].minor.yy778, NULL); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 434: /* table_primary ::= table_name alias_opt */ + case 436: /* table_primary ::= table_name alias_opt */ { yylhsminor.yy778 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy181, &yymsp[0].minor.yy181); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 435: /* table_primary ::= db_name NK_DOT table_name alias_opt */ + case 437: /* table_primary ::= db_name NK_DOT table_name alias_opt */ { yylhsminor.yy778 = createRealTableNode(pCxt, &yymsp[-3].minor.yy181, &yymsp[-1].minor.yy181, &yymsp[0].minor.yy181); } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 436: /* table_primary ::= subquery alias_opt */ + case 438: /* table_primary ::= subquery alias_opt */ { yylhsminor.yy778 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy778), &yymsp[0].minor.yy181); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 438: /* alias_opt ::= */ + case 440: /* alias_opt ::= */ { yymsp[1].minor.yy181 = nil_token; } break; - case 439: /* alias_opt ::= table_alias */ + case 441: /* alias_opt ::= table_alias */ { yylhsminor.yy181 = yymsp[0].minor.yy181; } yymsp[0].minor.yy181 = yylhsminor.yy181; break; - case 440: /* alias_opt ::= AS table_alias */ + case 442: /* alias_opt ::= AS table_alias */ { yymsp[-1].minor.yy181 = yymsp[0].minor.yy181; } break; - case 441: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 442: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==442); + case 443: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 444: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==444); { yymsp[-2].minor.yy778 = yymsp[-1].minor.yy778; } break; - case 443: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + case 445: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ { yylhsminor.yy778 = createJoinTableNode(pCxt, yymsp[-4].minor.yy202, yymsp[-5].minor.yy778, yymsp[-2].minor.yy778, yymsp[0].minor.yy778); } yymsp[-5].minor.yy778 = yylhsminor.yy778; break; - case 444: /* join_type ::= */ + case 446: /* join_type ::= */ { yymsp[1].minor.yy202 = JOIN_TYPE_INNER; } break; - case 445: /* join_type ::= INNER */ + case 447: /* join_type ::= INNER */ { yymsp[0].minor.yy202 = JOIN_TYPE_INNER; } break; - case 446: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 448: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { yymsp[-11].minor.yy778 = createSelectStmt(pCxt, yymsp[-10].minor.yy39, yymsp[-9].minor.yy282, yymsp[-8].minor.yy778); yymsp[-11].minor.yy778 = addWhereClause(pCxt, yymsp[-11].minor.yy778, yymsp[-7].minor.yy778); @@ -4963,73 +4973,73 @@ static YYACTIONTYPE yy_reduce( yymsp[-11].minor.yy778 = addFillClause(pCxt, yymsp[-11].minor.yy778, yymsp[-3].minor.yy778); } break; - case 449: /* set_quantifier_opt ::= ALL */ + case 451: /* set_quantifier_opt ::= ALL */ { yymsp[0].minor.yy39 = false; } break; - case 452: /* select_item ::= NK_STAR */ + case 454: /* select_item ::= NK_STAR */ { yylhsminor.yy778 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0); } yymsp[0].minor.yy778 = yylhsminor.yy778; break; - case 454: /* select_item ::= common_expression column_alias */ - case 464: /* partition_item ::= expr_or_subquery column_alias */ yytestcase(yyruleno==464); + case 456: /* select_item ::= common_expression column_alias */ + case 466: /* partition_item ::= expr_or_subquery column_alias */ yytestcase(yyruleno==466); { yylhsminor.yy778 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy778), &yymsp[0].minor.yy181); } yymsp[-1].minor.yy778 = yylhsminor.yy778; break; - case 455: /* select_item ::= common_expression AS column_alias */ - case 465: /* partition_item ::= expr_or_subquery AS column_alias */ yytestcase(yyruleno==465); + case 457: /* select_item ::= common_expression AS column_alias */ + case 467: /* partition_item ::= expr_or_subquery AS column_alias */ yytestcase(yyruleno==467); { yylhsminor.yy778 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), &yymsp[0].minor.yy181); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 460: /* partition_by_clause_opt ::= PARTITION BY partition_list */ - case 482: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==482); - case 501: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==501); + case 462: /* partition_by_clause_opt ::= PARTITION BY partition_list */ + case 484: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==484); + case 503: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==503); { yymsp[-2].minor.yy282 = yymsp[0].minor.yy282; } break; - case 467: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + case 469: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ { yymsp[-5].minor.yy778 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), releaseRawExprNode(pCxt, yymsp[-1].minor.yy778)); } break; - case 468: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP */ + case 470: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP */ { yymsp[-3].minor.yy778 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy778)); } break; - case 469: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + case 471: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ { yymsp[-5].minor.yy778 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), NULL, yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } break; - case 470: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + case 472: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ { yymsp[-7].minor.yy778 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy778), releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } break; - case 474: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ + case 476: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ { yymsp[-3].minor.yy778 = createFillNode(pCxt, yymsp[-1].minor.yy381, NULL); } break; - case 475: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + case 477: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ { yymsp[-5].minor.yy778 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy282)); } break; - case 476: /* fill_mode ::= NONE */ + case 478: /* fill_mode ::= NONE */ { yymsp[0].minor.yy381 = FILL_MODE_NONE; } break; - case 477: /* fill_mode ::= PREV */ + case 479: /* fill_mode ::= PREV */ { yymsp[0].minor.yy381 = FILL_MODE_PREV; } break; - case 478: /* fill_mode ::= NULL */ + case 480: /* fill_mode ::= NULL */ { yymsp[0].minor.yy381 = FILL_MODE_NULL; } break; - case 479: /* fill_mode ::= LINEAR */ + case 481: /* fill_mode ::= LINEAR */ { yymsp[0].minor.yy381 = FILL_MODE_LINEAR; } break; - case 480: /* fill_mode ::= NEXT */ + case 482: /* fill_mode ::= NEXT */ { yymsp[0].minor.yy381 = FILL_MODE_NEXT; } break; - case 483: /* group_by_list ::= expr_or_subquery */ + case 485: /* group_by_list ::= expr_or_subquery */ { yylhsminor.yy282 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); } yymsp[0].minor.yy282 = yylhsminor.yy282; break; - case 484: /* group_by_list ::= group_by_list NK_COMMA expr_or_subquery */ + case 486: /* group_by_list ::= group_by_list NK_COMMA expr_or_subquery */ { yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-2].minor.yy282, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); } yymsp[-2].minor.yy282 = yylhsminor.yy282; break; - case 488: /* range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP */ + case 490: /* range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP */ { yymsp[-5].minor.yy778 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), releaseRawExprNode(pCxt, yymsp[-1].minor.yy778)); } break; - case 491: /* query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 493: /* query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt */ { yylhsminor.yy778 = addOrderByClause(pCxt, yymsp[-3].minor.yy778, yymsp[-2].minor.yy282); yylhsminor.yy778 = addSlimitClause(pCxt, yylhsminor.yy778, yymsp[-1].minor.yy778); @@ -5037,50 +5047,50 @@ static YYACTIONTYPE yy_reduce( } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 494: /* union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery */ + case 496: /* union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery */ { yylhsminor.yy778 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy778, yymsp[0].minor.yy778); } yymsp[-3].minor.yy778 = yylhsminor.yy778; break; - case 495: /* union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery */ + case 497: /* union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery */ { yylhsminor.yy778 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy778, yymsp[0].minor.yy778); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 503: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 507: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==507); + case 505: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 509: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==509); { yymsp[-1].minor.yy778 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 504: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 508: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==508); + case 506: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 510: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==510); { yymsp[-3].minor.yy778 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 505: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 509: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==509); + case 507: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 511: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==511); { yymsp[-3].minor.yy778 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 510: /* subquery ::= NK_LP query_expression NK_RP */ + case 512: /* subquery ::= NK_LP query_expression NK_RP */ { yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy778); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 515: /* sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt */ + case 517: /* sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt */ { yylhsminor.yy778 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), yymsp[-1].minor.yy14, yymsp[0].minor.yy305); } yymsp[-2].minor.yy778 = yylhsminor.yy778; break; - case 516: /* ordering_specification_opt ::= */ + case 518: /* ordering_specification_opt ::= */ { yymsp[1].minor.yy14 = ORDER_ASC; } break; - case 517: /* ordering_specification_opt ::= ASC */ + case 519: /* ordering_specification_opt ::= ASC */ { yymsp[0].minor.yy14 = ORDER_ASC; } break; - case 518: /* ordering_specification_opt ::= DESC */ + case 520: /* ordering_specification_opt ::= DESC */ { yymsp[0].minor.yy14 = ORDER_DESC; } break; - case 519: /* null_ordering_opt ::= */ + case 521: /* null_ordering_opt ::= */ { yymsp[1].minor.yy305 = NULL_ORDER_DEFAULT; } break; - case 520: /* null_ordering_opt ::= NULLS FIRST */ + case 522: /* null_ordering_opt ::= NULLS FIRST */ { yymsp[-1].minor.yy305 = NULL_ORDER_FIRST; } break; - case 521: /* null_ordering_opt ::= NULLS LAST */ + case 523: /* null_ordering_opt ::= NULLS LAST */ { yymsp[-1].minor.yy305 = NULL_ORDER_LAST; } break; default: diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index a9360f796c9eee31c45007ebdc365aa2455365fd..7f18a7b28215192dc9f073018e795a205fbac929 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -32,23 +32,29 @@ namespace { void generateInformationSchema(MockCatalogService* mcs) { - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODES, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODES, TSDB_SYSTEM_TABLE, 2) + .addColumn("id", TSDB_DATA_TYPE_INT) .addColumn("endpoint", TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN) .done(); - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MNODES, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MNODES, TSDB_SYSTEM_TABLE, 2) + .addColumn("id", TSDB_DATA_TYPE_INT) .addColumn("endpoint", TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN) .done(); - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MODULES, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MODULES, TSDB_SYSTEM_TABLE, 2) + .addColumn("id", TSDB_DATA_TYPE_INT) .addColumn("endpoint", TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN) .done(); - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_QNODES, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_QNODES, TSDB_SYSTEM_TABLE, 2) + .addColumn("id", TSDB_DATA_TYPE_INT) .addColumn("endpoint", TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN) .done(); - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DATABASES, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DATABASES, TSDB_SYSTEM_TABLE, 2) .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) + .addColumn("create_time", TSDB_DATA_TYPE_TIMESTAMP) .done(); - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_FUNCTIONS, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_FUNCTIONS, TSDB_SYSTEM_TABLE, 2) .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN) + .addColumn("aggregate", TSDB_DATA_TYPE_INT) .done(); mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_INDEXES, TSDB_SYSTEM_TABLE, 3) .addColumn("index_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN) @@ -63,22 +69,28 @@ void generateInformationSchema(MockCatalogService* mcs) { .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) .addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN) .done(); - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TABLE_DISTRIBUTED, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TABLE_DISTRIBUTED, TSDB_SYSTEM_TABLE, 2) .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) + .addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN) .done(); - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USERS, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USERS, TSDB_SYSTEM_TABLE, 2) .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN) + .addColumn("super", TSDB_DATA_TYPE_TINYINT) .done(); - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS, TSDB_SYSTEM_TABLE, 2) + .addColumn("vgroup_id", TSDB_DATA_TYPE_INT) .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) .done(); - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CONFIGS, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CONFIGS, TSDB_SYSTEM_TABLE, 2) .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_CONFIG_OPTION_LEN) + .addColumn("value", TSDB_DATA_TYPE_BINARY, TSDB_CONFIG_VALUE_LEN) .done(); - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODE_VARIABLES, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODE_VARIABLES, TSDB_SYSTEM_TABLE, 2) .addColumn("dnode_id", TSDB_DATA_TYPE_INT) + .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_CONFIG_OPTION_LEN) .done(); - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CLUSTER, TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CLUSTER, TSDB_SYSTEM_TABLE, 2) + .addColumn("id", TSDB_DATA_TYPE_BIGINT) .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN) .done(); mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VNODES, TSDB_SYSTEM_TABLE, 2) @@ -92,30 +104,22 @@ void generateInformationSchema(MockCatalogService* mcs) { } void generatePerformanceSchema(MockCatalogService* mcs) { - { - ITableBuilder& builder = - mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_TRANS, TSDB_SYSTEM_TABLE, 1) - .addColumn("id", TSDB_DATA_TYPE_INT); - builder.done(); - } - { - ITableBuilder& builder = - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STREAMS, TSDB_SYSTEM_TABLE, 1) - .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); - builder.done(); - } - { - ITableBuilder& builder = - mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_CONSUMERS, TSDB_SYSTEM_TABLE, 1) - .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); - builder.done(); - } - { - ITableBuilder& builder = - mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_SUBSCRIPTIONS, TSDB_SYSTEM_TABLE, 1) - .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); - builder.done(); - } + mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_TRANS, TSDB_SYSTEM_TABLE, 2) + .addColumn("id", TSDB_DATA_TYPE_INT) + .addColumn("create_time", TSDB_DATA_TYPE_TIMESTAMP) + .done(); + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STREAMS, TSDB_SYSTEM_TABLE, 2) + .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN) + .addColumn("create_time", TSDB_DATA_TYPE_TIMESTAMP) + .done(); + mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_CONSUMERS, TSDB_SYSTEM_TABLE, 2) + .addColumn("consumer_id", TSDB_DATA_TYPE_BIGINT) + .addColumn("consumer_group", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN) + .done(); + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_SUBSCRIPTIONS, TSDB_SYSTEM_TABLE, 2) + .addColumn("vgroup_id", TSDB_DATA_TYPE_INT) + .addColumn("consumer_id", TSDB_DATA_TYPE_BIGINT) + .done(); } /* @@ -239,8 +243,8 @@ int32_t __catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* ve return 0; } -int32_t __catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SArray** pVgList) { - return g_mockCatalogService->catalogGetDBVgInfo(dbFName, pVgList); +int32_t __catalogGetDBVgList(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SArray** pVgList) { + return g_mockCatalogService->catalogGetDBVgList(dbFName, pVgList); } int32_t __catalogGetDBCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SDbCfgInfo* pDbCfg) { @@ -289,7 +293,7 @@ void initMetaDataEnv() { stub.set(catalogGetTableHashVgroup, __catalogGetTableHashVgroup); stub.set(catalogGetTableDistVgInfo, __catalogGetTableDistVgInfo); stub.set(catalogGetDBVgVersion, __catalogGetDBVgVersion); - stub.set(catalogGetDBVgInfo, __catalogGetDBVgInfo); + stub.set(catalogGetDBVgList, __catalogGetDBVgList); stub.set(catalogGetDBCfg, __catalogGetDBCfg); stub.set(catalogChkAuth, __catalogChkAuth); stub.set(catalogGetUdfInfo, __catalogGetUdfInfo); diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index 6717a1fdf15719c4cc6ff59e891a4bbd5713d323..f2cebcb08d157a724e45bb4c5eebc7ba2873c4a9 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -132,7 +132,7 @@ class MockCatalogServiceImpl { return copyTableVgroup(db, tNameGetTableName(pTableName), vgList); } - int32_t catalogGetDBVgInfo(const char* pDbFName, SArray** pVgList) const { + int32_t catalogGetDBVgList(const char* pDbFName, SArray** pVgList) const { std::string dbFName(pDbFName); DbMetaCache::const_iterator it = meta_.find(dbFName.substr(std::string(pDbFName).find_last_of('.') + 1)); if (meta_.end() == it) { @@ -663,8 +663,8 @@ int32_t MockCatalogService::catalogGetTableDistVgInfo(const SName* pTableName, S return impl_->catalogGetTableDistVgInfo(pTableName, pVgList); } -int32_t MockCatalogService::catalogGetDBVgInfo(const char* pDbFName, SArray** pVgList) const { - return impl_->catalogGetDBVgInfo(pDbFName, pVgList); +int32_t MockCatalogService::catalogGetDBVgList(const char* pDbFName, SArray** pVgList) const { + return impl_->catalogGetDBVgList(pDbFName, pVgList); } int32_t MockCatalogService::catalogGetDBCfg(const char* pDbFName, SDbCfgInfo* pDbCfg) const { diff --git a/source/libs/parser/test/mockCatalogService.h b/source/libs/parser/test/mockCatalogService.h index c0330692ee4bbcf32cdcbeb6cd48822708976965..d9d2185728305ce4c4205f3c55ac10cda5231cb4 100644 --- a/source/libs/parser/test/mockCatalogService.h +++ b/source/libs/parser/test/mockCatalogService.h @@ -70,7 +70,7 @@ class MockCatalogService { int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const; int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const; int32_t catalogGetTableDistVgInfo(const SName* pTableName, SArray** pVgList) const; - int32_t catalogGetDBVgInfo(const char* pDbFName, SArray** pVgList) const; + int32_t catalogGetDBVgList(const char* pDbFName, SArray** pVgList) const; int32_t catalogGetDBCfg(const char* pDbFName, SDbCfgInfo* pDbCfg) const; int32_t catalogGetUdfInfo(const std::string& funcName, SFuncInfo* pInfo) const; int32_t catalogGetTableIndex(const SName* pTableName, SArray** pIndexes) const; diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index ccae1f54be3938f45c36ebee24ef4d4a305cb3ce..3171bb531b1be4a0bff5363555e94c3f6576587b 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -2139,6 +2139,46 @@ static int32_t rewriteUniqueOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLog return rewriteUniqueOptimizeImpl(pCxt, pLogicSubplan, pIndef); } +typedef struct SLastRowScanOptLastParaCkCxt { + bool hasTag; + bool hasCol; +} SLastRowScanOptLastParaCkCxt; + +static EDealRes lastRowScanOptLastParaCheckImpl(SNode* pNode, void* pContext) { + if (QUERY_NODE_COLUMN == nodeType(pNode)) { + SLastRowScanOptLastParaCkCxt* pCxt = pContext; + if (COLUMN_TYPE_TAG == ((SColumnNode*)pNode)->colType || COLUMN_TYPE_TBNAME == ((SColumnNode*)pNode)->colType) { + pCxt->hasTag = true; + } else { + pCxt->hasCol = true; + } + return DEAL_RES_END; + } + return DEAL_RES_CONTINUE; +} + +static bool lastRowScanOptLastParaCheck(SNode* pExpr) { + SLastRowScanOptLastParaCkCxt cxt = {.hasTag = false, .hasCol = false}; + nodesWalkExpr(pExpr, lastRowScanOptLastParaCheckImpl, &cxt); + return !cxt.hasTag && cxt.hasCol; +} + +static bool hasSuitableCache(int8_t cacheLastMode, bool hasLastRow, bool hasLast) { + switch (cacheLastMode) { + case TSDB_CACHE_MODEL_NONE: + return false; + case TSDB_CACHE_MODEL_LAST_ROW: + return hasLastRow; + case TSDB_CACHE_MODEL_LAST_VALUE: + return hasLast; + case TSDB_CACHE_MODEL_BOTH: + return true; + default: + break; + } + return false; +} + static bool lastRowScanOptMayBeOptimized(SLogicNode* pNode) { if (QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode) || 1 != LIST_LENGTH(pNode->pChildren) || QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(nodesListGetNode(pNode->pChildren, 0))) { @@ -2149,16 +2189,27 @@ static bool lastRowScanOptMayBeOptimized(SLogicNode* pNode) { SScanLogicNode* pScan = (SScanLogicNode*)nodesListGetNode(pNode->pChildren, 0); // Only one of LAST and LASTROW can appear if (pAgg->hasLastRow == pAgg->hasLast || NULL != pAgg->pGroupKeys || NULL != pScan->node.pConditions || - 0 == pScan->cacheLastMode || IS_TSWINDOW_SPECIFIED(pScan->scanRange)) { + !hasSuitableCache(pScan->cacheLastMode, pAgg->hasLastRow, pAgg->hasLast) || + IS_TSWINDOW_SPECIFIED(pScan->scanRange)) { return false; } + bool hasLastFunc = false; + bool hasSelectFunc = false; SNode* pFunc = NULL; FOREACH(pFunc, ((SAggLogicNode*)pNode)->pAggFuncs) { - if (FUNCTION_TYPE_LAST_ROW != ((SFunctionNode*)pFunc)->funcType && - // FUNCTION_TYPE_LAST != ((SFunctionNode*)pFunc)->funcType && - FUNCTION_TYPE_SELECT_VALUE != ((SFunctionNode*)pFunc)->funcType && - FUNCTION_TYPE_GROUP_KEY != ((SFunctionNode*)pFunc)->funcType) { + SFunctionNode* pAggFunc = (SFunctionNode*)pFunc; + if (FUNCTION_TYPE_LAST == pAggFunc->funcType) { + if (hasSelectFunc || !lastRowScanOptLastParaCheck(nodesListGetNode(pAggFunc->pParameterList, 0))) { + return false; + } + hasLastFunc = true; + } else if (FUNCTION_TYPE_SELECT_VALUE == pAggFunc->funcType || FUNCTION_TYPE_GROUP_KEY == pAggFunc->funcType) { + if (hasLastFunc) { + return false; + } + hasSelectFunc = true; + } else if (FUNCTION_TYPE_LAST_ROW != pAggFunc->funcType) { return false; } } @@ -2166,6 +2217,31 @@ static bool lastRowScanOptMayBeOptimized(SLogicNode* pNode) { return true; } +typedef struct SLastRowScanOptSetColDataTypeCxt { + bool doAgg; + SNodeList* pLastCols; +} SLastRowScanOptSetColDataTypeCxt; + +static EDealRes lastRowScanOptSetColDataType(SNode* pNode, void* pContext) { + if (QUERY_NODE_COLUMN == nodeType(pNode)) { + SLastRowScanOptSetColDataTypeCxt* pCxt = pContext; + if (pCxt->doAgg) { + nodesListMakeAppend(&pCxt->pLastCols, pNode); + getLastCacheDataType(&(((SColumnNode*)pNode)->node.resType)); + } else { + SNode* pCol = NULL; + FOREACH(pCol, pCxt->pLastCols) { + if (nodesEqualNode(pCol, pNode)) { + getLastCacheDataType(&(((SColumnNode*)pNode)->node.resType)); + break; + } + } + } + return DEAL_RES_IGNORE_CHILD; + } + return DEAL_RES_CONTINUE; +} + static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) { SAggLogicNode* pAgg = (SAggLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, lastRowScanOptMayBeOptimized); @@ -2173,22 +2249,36 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic return TSDB_CODE_SUCCESS; } - SNode* pNode = NULL; + SLastRowScanOptSetColDataTypeCxt cxt = {.doAgg = true, .pLastCols = NULL}; + SNode* pNode = NULL; FOREACH(pNode, pAgg->pAggFuncs) { SFunctionNode* pFunc = (SFunctionNode*)pNode; - if (FUNCTION_TYPE_LAST_ROW == pFunc->funcType || FUNCTION_TYPE_LAST == pFunc->funcType) { - int32_t len = snprintf(pFunc->functionName, sizeof(pFunc->functionName), "_cache_last_row"); + int32_t funcType = pFunc->funcType; + if (FUNCTION_TYPE_LAST_ROW == funcType || FUNCTION_TYPE_LAST == funcType) { + int32_t len = snprintf(pFunc->functionName, sizeof(pFunc->functionName), + FUNCTION_TYPE_LAST_ROW == funcType ? "_cache_last_row" : "_cache_last"); pFunc->functionName[len] = '\0'; int32_t code = fmGetFuncInfo(pFunc, NULL, 0); if (TSDB_CODE_SUCCESS != code) { + nodesClearList(cxt.pLastCols); return code; } + if (FUNCTION_TYPE_LAST == funcType) { + nodesWalkExpr(nodesListGetNode(pFunc->pParameterList, 0), lastRowScanOptSetColDataType, &cxt); + } } } SScanLogicNode* pScan = (SScanLogicNode*)nodesListGetNode(pAgg->node.pChildren, 0); pScan->scanType = SCAN_TYPE_LAST_ROW; pScan->igLastNull = pAgg->hasLast ? true : false; + if (NULL != cxt.pLastCols) { + cxt.doAgg = false; + nodesWalkExprs(pScan->pScanCols, lastRowScanOptSetColDataType, &cxt); + nodesWalkExprs(pScan->pScanPseudoCols, lastRowScanOptSetColDataType, &cxt); + nodesWalkExprs(pScan->node.pTargets, lastRowScanOptSetColDataType, &cxt); + nodesClearList(cxt.pLastCols); + } pAgg->hasLastRow = false; pAgg->hasLast = false; diff --git a/source/libs/planner/test/planBasicTest.cpp b/source/libs/planner/test/planBasicTest.cpp index 0baec147a2461c9dfe62dd602a40af55dd9be81b..c5a9a447c73fff32ad16d6a76126ed8bf9f86994 100644 --- a/source/libs/planner/test/planBasicTest.cpp +++ b/source/libs/planner/test/planBasicTest.cpp @@ -105,24 +105,6 @@ TEST_F(PlanBasicTest, interpFunc) { run("SELECT _IROWTS, INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR)"); } -TEST_F(PlanBasicTest, lastRowFunc) { - useDb("root", "cache_db"); - - run("SELECT LAST_ROW(c1) FROM t1"); - - run("SELECT LAST_ROW(*) FROM t1"); - - run("SELECT LAST_ROW(c1, c2) FROM t1"); - - run("SELECT LAST_ROW(c1), c2 FROM t1"); - - run("SELECT LAST_ROW(c1) FROM st1"); - - run("SELECT LAST_ROW(c1) FROM st1 PARTITION BY TBNAME"); - - run("SELECT LAST_ROW(c1), SUM(c3) FROM t1"); -} - TEST_F(PlanBasicTest, lastRowFuncWithoutCache) { useDb("root", "test"); diff --git a/source/libs/planner/test/planOptimizeTest.cpp b/source/libs/planner/test/planOptimizeTest.cpp index c2a0aee847f8ad1f6a03cf675c01fabdab3c4eff..fb4f32a9bf9571fe964f88fb664e704005c1be69 100644 --- a/source/libs/planner/test/planOptimizeTest.cpp +++ b/source/libs/planner/test/planOptimizeTest.cpp @@ -109,9 +109,28 @@ TEST_F(PlanOptimizeTest, mergeProjects) { TEST_F(PlanOptimizeTest, pushDownProjectCond) { useDb("root", "test"); + run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) where 1-c1>5 order by 1 nulls first"); } +TEST_F(PlanOptimizeTest, LastRowScan) { + useDb("root", "cache_db"); + + run("SELECT LAST_ROW(c1), c2 FROM t1"); + + run("SELECT LAST_ROW(c1), c2, tag1, tbname FROM st1"); + + run("SELECT LAST_ROW(c1) FROM st1 PARTITION BY TBNAME"); + + run("SELECT LAST_ROW(c1), SUM(c3) FROM t1"); + + run("SELECT LAST_ROW(tag1) FROM st1"); + + run("SELECT LAST(c1) FROM st1"); + + run("SELECT LAST(c1), c2 FROM st1"); +} + TEST_F(PlanOptimizeTest, tagScan) { useDb("root", "test"); run("select tag1 from st1 group by tag1"); diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index 618f597d72f37919fce27eb8259dcacf784a513b..23f177ffe273a0e7db6f44bc17cecfff1a1ca67c 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -423,13 +423,14 @@ int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) { return TSDB_CODE_SUCCESS; } - if ((pSrc->tableInfo.numOfColumns + pSrc->tableInfo.numOfTags) > TSDB_MAX_COL_TAG_NUM) { + int32_t numOfField = pSrc->tableInfo.numOfColumns + pSrc->tableInfo.numOfTags; + if (numOfField > TSDB_MAX_COL_TAG_NUM || numOfField < TSDB_MIN_COLUMNS) { *pDst = NULL; qError("too many column and tag num:%d,%d", pSrc->tableInfo.numOfColumns, pSrc->tableInfo.numOfTags); return TSDB_CODE_INVALID_PARA; } - int32_t metaSize = sizeof(STableMeta) + (pSrc->tableInfo.numOfColumns + pSrc->tableInfo.numOfTags) * sizeof(SSchema); + int32_t metaSize = sizeof(STableMeta) + numOfField * sizeof(SSchema); *pDst = taosMemoryMalloc(metaSize); if (NULL == *pDst) { return TSDB_CODE_TSC_OUT_OF_MEMORY; diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index fadd07a9f3221d5dce2e62f96967106b10fa1d7c..953abd595695a3616e3cf89fa89994f3306283d0 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -529,7 +529,7 @@ int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) { } if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) { - qError("tDeserializeSDbCfgRsp failed, msgSize:%d", msgSize); + qError("tDeserializeSDbCfgRsp failed, msgSize:%d,dbCfgRsp:%lu", msgSize, sizeof(out)); return TSDB_CODE_INVALID_MSG; } diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 3df16563e26a95fc5b40fae9c81fe026a25d70b0..001a1972a02b33cf1a076bca7c1ca31bf57a75c1 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -258,7 +258,7 @@ int32_t qwGetQueryResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, dsGetDataLength(ctx->sinkHandle, &len, &queryEnd); if (len < 0) { - QW_TASK_ELOG("invalid length from dsGetDataLength, length:%" PRId64, len); + QW_TASK_ELOG("invalid length from dsGetDataLength, length:%" PRId64 "", len); QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } @@ -292,7 +292,7 @@ int32_t qwGetQueryResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, } // Got data from sink - QW_TASK_DLOG("there are data in sink, dataLength:%" PRId64, len); + QW_TASK_DLOG("there are data in sink, dataLength:%" PRId64 "", len); *dataLen += len; diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index c20ff06c160f6620c6d3bf0cc6c1bd205fd55e12..7e93c9173c0d21edca583c40caab11a30f5c146f 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1178,9 +1178,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData); GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData); - int64_t factor = - (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); - + int64_t factor = TSDB_TICK_PER_SECOND(timePrec); int64_t unit = timeUnit * 1000 / factor; for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { @@ -1372,9 +1370,7 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData); } - int64_t factor = - (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); - + int64_t factor = TSDB_TICK_PER_SECOND(timePrec); int32_t numOfRows = 0; for (int32_t i = 0; i < inputNum; ++i) { if (pInput[i].numOfRows > numOfRows) { diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index e2c26c32e0388699349f005497887e3965e661be..415ceeb2bda1c32439566a676bd99c5d702dd686 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1429,57 +1429,6 @@ void vectorAssign(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, pOut->numOfQualified = pRight->numOfQualified * pOut->numOfRows; } -void vectorConcat(SScalarParam *pLeft, SScalarParam *pRight, void *out, int32_t _ord) { -#if 0 - int32_t len = pLeft->bytes + pRight->bytes; - - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - - char *output = (char *)out; - if (pLeft->numOfRows == pRight->numOfRows) { - for (; i < pRight->numOfRows && i >= 0; i += step, output += len) { - char* left = POINTER_SHIFT(pLeft->data, pLeft->bytes * i); - char* right = POINTER_SHIFT(pRight->data, pRight->bytes * i); - - if (isNull(left, pLeftCol->info.type) || isNull(right, pRight->info.type)) { - setVardataNull(output, TSDB_DATA_TYPE_BINARY); - continue; - } - - // todo define a macro - memcpy(varDataVal(output), varDataVal(left), varDataLen(left)); - memcpy(varDataVal(output) + varDataLen(left), varDataVal(right), varDataLen(right)); - varDataSetLen(output, varDataLen(left) + varDataLen(right)); - } - } else if (pLeft->numOfRows == 1) { - for (; i >= 0 && i < pRight->numOfRows; i += step, output += len) { - char *right = POINTER_SHIFT(pRight->data, pRight->bytes * i); - if (isNull(pLeft->data, pLeftCol->info.type) || isNull(right, pRight->info.type)) { - setVardataNull(output, TSDB_DATA_TYPE_BINARY); - continue; - } - - memcpy(varDataVal(output), varDataVal(pLeft->data), varDataLen(pLeft->data)); - memcpy(varDataVal(output) + varDataLen(pLeft->data), varDataVal(right), varDataLen(right)); - varDataSetLen(output, varDataLen(pLeft->data) + varDataLen(right)); - } - } else if (pRight->numOfRows == 1) { - for (; i >= 0 && i < pLeft->numOfRows; i += step, output += len) { - char* left = POINTER_SHIFT(pLeft->data, pLeft->bytes * i); - if (isNull(left, pLeftCol->info.type) || isNull(pRight->data, pRight->info.type)) { - SET_DOUBLE_NULL(output); - continue; - } - - memcpy(varDataVal(output), varDataVal(left), varDataLen(pRight->data)); - memcpy(varDataVal(output) + varDataLen(left), varDataVal(pRight->data), varDataLen(pRight->data)); - varDataSetLen(output, varDataLen(left) + varDataLen(pRight->data)); - } - } -#endif -} - static void vectorBitAndHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c index 5ad5aa549d28a6b8c4835177dcb11df5418fe57c..149b1a84478bf73e96f4d2f504da60731e800891 100644 --- a/source/libs/stream/src/streamExec.c +++ b/source/libs/stream/src/streamExec.c @@ -137,6 +137,8 @@ int32_t streamPipelineExec(SStreamTask* pTask, int32_t batchNum, bool dispatch) if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH || pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) { streamDispatch(pTask); } + } else { + taosArrayDestroyEx(pRes, (FDelete)blockDataFreeRes); } } diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index 53e49a6ba5e0be669329c5ff6414c3648ee14fb3..df28e4a62dc5a48041c7baf7fa6c4daec3ef738c 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -27,7 +27,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF char* streamPath = taosMemoryCalloc(1, len); sprintf(streamPath, "%s/%s", path, "stream"); pMeta->path = strdup(streamPath); - if (tdbOpen(pMeta->path, 16 * 1024, 1, &pMeta->db) < 0) { + if (tdbOpen(pMeta->path, 16 * 1024, 1, &pMeta->db, 0) < 0) { taosMemoryFree(streamPath); goto _err; } @@ -36,11 +36,11 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF taosMulModeMkDir(streamPath, 0755); taosMemoryFree(streamPath); - if (tdbTbOpen("task.db", sizeof(int32_t), -1, NULL, pMeta->db, &pMeta->pTaskDb) < 0) { + if (tdbTbOpen("task.db", sizeof(int32_t), -1, NULL, pMeta->db, &pMeta->pTaskDb, 0) < 0) { goto _err; } - if (tdbTbOpen("checkpoint.db", sizeof(int32_t), -1, NULL, pMeta->db, &pMeta->pCheckpointDb) < 0) { + if (tdbTbOpen("checkpoint.db", sizeof(int32_t), -1, NULL, pMeta->db, &pMeta->pCheckpointDb, 0) < 0) { goto _err; } @@ -94,7 +94,7 @@ int32_t streamMetaAddSerializedTask(SStreamMeta* pMeta, int64_t startVer, char* SDecoder decoder; tDecoderInit(&decoder, (uint8_t*)msg, msgLen); if (tDecodeSStreamTask(&decoder, pTask) < 0) { - ASSERT(0); + tDecoderClear(&decoder); goto FAIL; } tDecoderClear(&decoder); @@ -113,6 +113,13 @@ int32_t streamMetaAddSerializedTask(SStreamMeta* pMeta, int64_t startVer, char* ASSERT(0); goto FAIL; } + + if (pTask->fillHistory) { + // pipeline exec + // if finished, dispatch a stream-prepare-finished msg to downstream task + // set status normal + } + return 0; FAIL: @@ -120,6 +127,7 @@ FAIL: return -1; } +#if 0 int32_t streamMetaAddTask(SStreamMeta* pMeta, SStreamTask* pTask) { void* buf = NULL; if (pMeta->expandFunc(pMeta->ahandle, pTask) < 0) { @@ -149,6 +157,7 @@ int32_t streamMetaAddTask(SStreamMeta* pMeta, SStreamTask* pTask) { return 0; } +#endif SStreamTask* streamMetaGetTask(SStreamMeta* pMeta, int32_t taskId) { SStreamTask** ppTask = (SStreamTask**)taosHashGet(pMeta->pTasks, &taskId, sizeof(int32_t)); @@ -253,6 +262,7 @@ int32_t streamLoadTasks(SStreamMeta* pMeta) { if (pTask == NULL) { tdbFree(pKey); tdbFree(pVal); + tdbTbcClose(pCur); return -1; } tDecoderInit(&decoder, (uint8_t*)pVal, vLen); @@ -262,12 +272,14 @@ int32_t streamLoadTasks(SStreamMeta* pMeta) { if (pMeta->expandFunc(pMeta->ahandle, pTask) < 0) { tdbFree(pKey); tdbFree(pVal); + tdbTbcClose(pCur); return -1; } if (taosHashPut(pMeta->pTasks, &pTask->taskId, sizeof(int32_t), &pTask, sizeof(void*)) < 0) { tdbFree(pKey); tdbFree(pVal); + tdbTbcClose(pCur); return -1; } } diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c index 6991f00bb7427154c845e64d8ceb1f3c7e8b7e29..ea429a76b0357d85b295fb1fbcc24c685290464f 100644 --- a/source/libs/stream/src/streamState.c +++ b/source/libs/stream/src/streamState.c @@ -99,26 +99,26 @@ SStreamState* streamStateOpen(char* path, SStreamTask* pTask, bool specPath, int memset(statePath, 0, 300); tstrncpy(statePath, path, 300); } - if (tdbOpen(statePath, szPage, pages, &pState->db) < 0) { + if (tdbOpen(statePath, szPage, pages, &pState->db, 0) < 0) { goto _err; } // open state storage backend - if (tdbTbOpen("state.db", sizeof(SStateKey), -1, stateKeyCmpr, pState->db, &pState->pStateDb) < 0) { + if (tdbTbOpen("state.db", sizeof(SStateKey), -1, stateKeyCmpr, pState->db, &pState->pStateDb, 0) < 0) { goto _err; } // todo refactor - if (tdbTbOpen("fill.state.db", sizeof(SWinKey), -1, winKeyCmpr, pState->db, &pState->pFillStateDb) < 0) { + if (tdbTbOpen("fill.state.db", sizeof(SWinKey), -1, winKeyCmpr, pState->db, &pState->pFillStateDb, 0) < 0) { goto _err; } if (tdbTbOpen("session.state.db", sizeof(SStateSessionKey), -1, stateSessionKeyCmpr, pState->db, - &pState->pSessionStateDb) < 0) { + &pState->pSessionStateDb, 0) < 0) { goto _err; } - if (tdbTbOpen("func.state.db", sizeof(STupleKey), -1, STupleKeyCmpr, pState->db, &pState->pFuncStateDb) < 0) { + if (tdbTbOpen("func.state.db", sizeof(STupleKey), -1, STupleKeyCmpr, pState->db, &pState->pFuncStateDb, 0) < 0) { goto _err; } @@ -526,7 +526,7 @@ int32_t streamStateSessionDel(SStreamState* pState, const SSessionKey* key) { return tdbTbDelete(pState->pSessionStateDb, &sKey, sizeof(SStateSessionKey), &pState->txn); } -SStreamStateCur* streamStateSessionSeekKeyPrev(SStreamState* pState, const SSessionKey* key) { +SStreamStateCur* streamStateSessionSeekKeyCurrentPrev(SStreamState* pState, const SSessionKey* key) { SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur)); if (pCur == NULL) { return NULL; @@ -544,7 +544,7 @@ SStreamStateCur* streamStateSessionSeekKeyPrev(SStreamState* pState, const SSess streamStateFreeCur(pCur); return NULL; } - if (c > 0) return pCur; + if (c >= 0) return pCur; if (tdbTbcMoveToPrev(pCur->pCur) < 0) { streamStateFreeCur(pCur); @@ -572,7 +572,7 @@ SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSess streamStateFreeCur(pCur); return NULL; } - if (c > 0) return pCur; + if (c < 0) return pCur; if (tdbTbcMoveToNext(pCur->pCur) < 0) { streamStateFreeCur(pCur); @@ -630,7 +630,7 @@ SStreamStateCur* streamStateSessionGetCur(SStreamState* pState, const SSessionKe streamStateCurPrev(pState, pCur); SSessionKey tmpKey = *key; int32_t code = streamStateSessionGetKVByCur(pCur, &tmpKey, NULL, 0); - if (code == TSDB_CODE_SUCCESS && sessionKeyCmpr(key, &tmpKey) == 0) { + if (code == 0 && sessionKeyCmpr(key, &tmpKey) == 0) { resKey = tmpKey; } else { break; @@ -640,9 +640,29 @@ SStreamStateCur* streamStateSessionGetCur(SStreamState* pState, const SSessionKe return streamStateSessionGetRanomCur(pState, &resKey); } +int32_t streamStateSessionGetKey(SStreamState* pState, const SSessionKey* key, SSessionKey* curKey) { + SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key); + SSessionKey resKey = *key; + int32_t res = -1; + while (1) { + SSessionKey tmpKey = *key; + int32_t code = streamStateSessionGetKVByCur(pCur, &tmpKey, NULL, 0); + if (code == 0 && sessionKeyCmpr(key, &tmpKey) == 0) { + res = 0; + resKey = tmpKey; + streamStateCurPrev(pState, pCur); + } else { + break; + } + } + *curKey = resKey; + streamStateFreeCur(pCur); + return res; +} + int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen) { // todo refactor - SStreamStateCur* pCur = streamStateSessionGetCur(pState, key); + SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key); int32_t size = *pVLen; void* tmp = NULL; *pVal = tdbRealloc(NULL, size); @@ -659,7 +679,7 @@ int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen, state_key_cmpr_fn fn, void** pVal, int32_t* pVLen) { // todo refactor - int32_t res = TSDB_CODE_SUCCESS; + int32_t res = 0; SSessionKey tmpKey = *key; int32_t valSize = *pVLen; void* tmp = tdbRealloc(NULL, valSize); @@ -667,33 +687,29 @@ int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, ch return -1; } - SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key); + SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentPrev(pState, key); int32_t code = streamStateSessionGetKVByCur(pCur, key, (const void**)pVal, pVLen); - if (code == TSDB_CODE_SUCCESS) { - memcpy(tmp, *pVal, valSize); - *pVal = tmp; - streamStateFreeCur(pCur); - return res; - } - streamStateFreeCur(pCur); + if (code == 0) { + if (key->win.skey <= tmpKey.win.skey && tmpKey.win.ekey <= key->win.ekey) { + memcpy(tmp, *pVal, valSize); + goto _end; + } - streamStateSessionPut(pState, key, NULL, 0); - pCur = streamStateSessionGetRanomCur(pState, key); - streamStateCurPrev(pState, pCur); - code = streamStateSessionGetKVByCur(pCur, key, (const void**)pVal, pVLen); - if (code == TSDB_CODE_SUCCESS) { void* stateKey = (char*)(*pVal) + (valSize - keyDataLen); if (fn(pKeyData, stateKey) == true) { memcpy(tmp, *pVal, valSize); goto _end; } + + streamStateCurNext(pState, pCur); + } else { + *key = tmpKey; + streamStateFreeCur(pCur); + pCur = streamStateSessionSeekKeyNext(pState, key); } - streamStateFreeCur(pCur); - *key = tmpKey; - pCur = streamStateSessionSeekKeyNext(pState, key); code = streamStateSessionGetKVByCur(pCur, key, (const void**)pVal, pVLen); - if (code == TSDB_CODE_SUCCESS) { + if (code == 0) { void* stateKey = (char*)(*pVal) + (valSize - keyDataLen); if (fn(pKeyData, stateKey) == true) { memcpy(tmp, *pVal, valSize); @@ -708,7 +724,6 @@ int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, ch _end: *pVal = tmp; - streamStateSessionDel(pState, &tmpKey); streamStateFreeCur(pCur); return res; } diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c index ce5917de296c317f739e79cb78cda21660769aa8..f7252ed8a036152b2ae9fb46861fdb8ac6754d2d 100644 --- a/source/libs/stream/src/streamTask.c +++ b/source/libs/stream/src/streamTask.c @@ -49,7 +49,7 @@ int32_t tDecodeStreamEpInfo(SDecoder* pDecoder, SStreamChildEpInfo* pInfo) { } int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) { - /*if (tStartEncode(pEncoder) < 0) return -1;*/ + if (tStartEncode(pEncoder) < 0) return -1; if (tEncodeI64(pEncoder, pTask->streamId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->taskId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->totalLevel) < 0) return -1; @@ -64,6 +64,10 @@ int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) { if (tEncodeI32(pEncoder, pTask->nodeId) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pTask->epSet) < 0) return -1; + if (tEncodeI64(pEncoder, pTask->recoverSnapVer) < 0) return -1; + if (tEncodeI64(pEncoder, pTask->startVer) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->fillHistory) < 0) return -1; + int32_t epSz = taosArrayGetSize(pTask->childEpInfo); if (tEncodeI32(pEncoder, epSz) < 0) return -1; for (int32_t i = 0; i < epSz; i++) { @@ -93,12 +97,12 @@ int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) { } if (tEncodeI64(pEncoder, pTask->triggerParam) < 0) return -1; - /*tEndEncode(pEncoder);*/ + tEndEncode(pEncoder); return pEncoder->pos; } int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) { - /*if (tStartDecode(pDecoder) < 0) return -1;*/ + if (tStartDecode(pDecoder) < 0) return -1; if (tDecodeI64(pDecoder, &pTask->streamId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->totalLevel) < 0) return -1; @@ -113,13 +117,20 @@ int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) { if (tDecodeI32(pDecoder, &pTask->nodeId) < 0) return -1; if (tDecodeSEpSet(pDecoder, &pTask->epSet) < 0) return -1; + if (tDecodeI64(pDecoder, &pTask->recoverSnapVer) < 0) return -1; + if (tDecodeI64(pDecoder, &pTask->startVer) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->fillHistory) < 0) return -1; + int32_t epSz; if (tDecodeI32(pDecoder, &epSz) < 0) return -1; pTask->childEpInfo = taosArrayInit(epSz, sizeof(void*)); for (int32_t i = 0; i < epSz; i++) { SStreamChildEpInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamChildEpInfo)); if (pInfo == NULL) return -1; - if (tDecodeStreamEpInfo(pDecoder, pInfo) < 0) return -1; + if (tDecodeStreamEpInfo(pDecoder, pInfo) < 0) { + taosMemoryFreeClear(pInfo); + return -1; + } taosArrayPush(pTask->childEpInfo, &pInfo); } @@ -147,7 +158,7 @@ int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) { } if (tDecodeI64(pDecoder, &pTask->triggerParam) < 0) return -1; - /*tEndDecode(pDecoder);*/ + tEndDecode(pDecoder); return 0; } diff --git a/source/libs/stream/src/streamUpdate.c b/source/libs/stream/src/streamUpdate.c index 5aadb599a30b0df5cc2b89608ea0afcfb79298c1..199892c24196b5178981a5b400cf62a4d5d02e88 100644 --- a/source/libs/stream/src/streamUpdate.c +++ b/source/libs/stream/src/streamUpdate.c @@ -14,6 +14,7 @@ */ #include "query.h" +#include "tdatablock.h" #include "tencode.h" #include "tstreamUpdate.h" #include "ttime.h" @@ -162,15 +163,46 @@ bool updateInfoIsTableInserted(SUpdateInfo *pInfo, int64_t tbUid) { return false; } +void updateInfoFillBlockData(SUpdateInfo *pInfo, SSDataBlock *pBlock, int32_t primaryTsCol) { + if (pBlock == NULL || pBlock->info.rows == 0) return; + TSKEY maxTs = -1; + int64_t tbUid = pBlock->info.uid; + + SColumnInfoData *pColDataInfo = taosArrayGet(pBlock->pDataBlock, primaryTsCol); + + for (int32_t i = 0; i < pBlock->info.rows; i++) { + TSKEY ts = ((TSKEY *)pColDataInfo->pData)[i]; + maxTs = TMAX(maxTs, ts); + SScalableBf *pSBf = getSBf(pInfo, ts); + if (pSBf) { + SUpdateKey updateKey = { + .tbUid = tbUid, + .ts = ts, + }; + tScalableBfPut(pSBf, &updateKey, sizeof(SUpdateKey)); + } + } + TSKEY *pMaxTs = taosHashGet(pInfo->pMap, &tbUid, sizeof(int64_t)); + if (pMaxTs == NULL || *pMaxTs > maxTs) { + taosHashPut(pInfo->pMap, &tbUid, sizeof(int64_t), &maxTs, sizeof(TSKEY)); + } +} + bool updateInfoIsUpdated(SUpdateInfo *pInfo, uint64_t tableId, TSKEY ts) { - int32_t res = TSDB_CODE_FAILED; + int32_t res = TSDB_CODE_FAILED; + + SUpdateKey updateKey = { + .tbUid = tableId, + .ts = ts, + }; + TSKEY *pMapMaxTs = taosHashGet(pInfo->pMap, &tableId, sizeof(uint64_t)); uint64_t index = ((uint64_t)tableId) % pInfo->numBuckets; TSKEY maxTs = *(TSKEY *)taosArrayGet(pInfo->pTsBuckets, index); if (ts < maxTs - pInfo->watermark) { // this window has been closed. if (pInfo->pCloseWinSBF) { - res = tScalableBfPut(pInfo->pCloseWinSBF, &ts, sizeof(TSKEY)); + res = tScalableBfPut(pInfo->pCloseWinSBF, &updateKey, sizeof(SUpdateKey)); if (res == TSDB_CODE_SUCCESS) { return false; } else { @@ -183,7 +215,7 @@ bool updateInfoIsUpdated(SUpdateInfo *pInfo, uint64_t tableId, TSKEY ts) { SScalableBf *pSBf = getSBf(pInfo, ts); // pSBf may be a null pointer if (pSBf) { - res = tScalableBfPut(pSBf, &ts, sizeof(TSKEY)); + res = tScalableBfPut(pSBf, &updateKey, sizeof(SUpdateKey)); } int32_t size = taosHashGetSize(pInfo->pMap); diff --git a/source/libs/stream/test/CMakeLists.txt b/source/libs/stream/test/CMakeLists.txt index 96209f681259da0ac8369a30327dcb868729b177..5a97ba45f684dc444f3e7b5cb0cfdeade8728fd1 100644 --- a/source/libs/stream/test/CMakeLists.txt +++ b/source/libs/stream/test/CMakeLists.txt @@ -9,12 +9,17 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(streamUpdateTest "tstreamUpdateTest.cpp") TARGET_LINK_LIBRARIES( - streamUpdateTest - PUBLIC os util common gtest stream + streamUpdateTest + PUBLIC os util common gtest stream ) TARGET_INCLUDE_DIRECTORIES( - streamUpdateTest - PUBLIC "${TD_SOURCE_DIR}/include/libs/stream/" - PRIVATE "${TD_SOURCE_DIR}/source/libs/stream/inc" + streamUpdateTest + PUBLIC "${TD_SOURCE_DIR}/include/libs/stream/" + PRIVATE "${TD_SOURCE_DIR}/source/libs/stream/inc" +) + +add_test( + NAME streamUpdateTest + COMMAND streamUpdateTest ) \ No newline at end of file diff --git a/source/libs/sync/inc/syncAppendEntries.h b/source/libs/sync/inc/syncAppendEntries.h index e15c85d73bfda288bfb249c366a020997f1202c1..dc40e2fc7230b6bc235798945008718d7b347a88 100644 --- a/source/libs/sync/inc/syncAppendEntries.h +++ b/source/libs/sync/inc/syncAppendEntries.h @@ -92,9 +92,8 @@ extern "C" { // /\ UNCHANGED <> // /\ UNCHANGED <> // -int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg); -int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMsg); -int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatch* pMsg); + +int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncAppendEntriesReply.h b/source/libs/sync/inc/syncAppendEntriesReply.h index 03148252fba36d8264123a5e169cb18a065d5de4..0227d832fcf8c24affff174ecb1613f691d4c19f 100644 --- a/source/libs/sync/inc/syncAppendEntriesReply.h +++ b/source/libs/sync/inc/syncAppendEntriesReply.h @@ -40,9 +40,7 @@ extern "C" { // /\ Discard(m) // /\ UNCHANGED <> // -int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg); -int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg); -int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntriesReply* pMsg); +int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncElection.h b/source/libs/sync/inc/syncElection.h index 128dbf40502c809a4141840dc0a73639607639c1..9ccd9dd28f4ecff100aaa3875b811b5fce6ec096 100644 --- a/source/libs/sync/inc/syncElection.h +++ b/source/libs/sync/inc/syncElection.h @@ -37,12 +37,10 @@ extern "C" { // msource |-> i, // mdest |-> j]) // /\ UNCHANGED <> -// -int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode); -int32_t syncNodeRequestVotePeersSnapshot(SSyncNode* pSyncNode); int32_t syncNodeElect(SSyncNode* pSyncNode); -int32_t syncNodeRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncRequestVote* pMsg); +int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode); +int32_t syncNodeSendRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncRequestVote* pMsg); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncEnv.h b/source/libs/sync/inc/syncEnv.h index e6d2bd49202fe4d5caba72183dcc6b99673cd066..2a37e000e259c85f5a7de333b35e5a8822422647 100644 --- a/source/libs/sync/inc/syncEnv.h +++ b/source/libs/sync/inc/syncEnv.h @@ -28,13 +28,13 @@ extern "C" { #include "trpc.h" #include "ttimer.h" -#define TIMER_MAX_MS 0x7FFFFFFF -#define ENV_TICK_TIMER_MS 1000 -#define PING_TIMER_MS 5000 -#define ELECT_TIMER_MS_MIN 5000 -#define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2) +#define TIMER_MAX_MS 0x7FFFFFFF +#define ENV_TICK_TIMER_MS 1000 +#define PING_TIMER_MS 5000 +#define ELECT_TIMER_MS_MIN 5000 +#define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2) #define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN) -#define HEARTBEAT_TIMER_MS 900 +#define HEARTBEAT_TIMER_MS 900 #define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0}) diff --git a/source/libs/sync/inc/syncIO.h b/source/libs/sync/inc/syncIO.h index 68d2334101b3e9bff70b7e77c2fcbfaf84fa8d57..cfc4dd247263a3c3eb877a814d6da00ed956589a 100644 --- a/source/libs/sync/inc/syncIO.h +++ b/source/libs/sync/inc/syncIO.h @@ -56,9 +56,8 @@ typedef struct SSyncIO { int32_t (*FpOnSyncAppendEntries)(SSyncNode *pSyncNode, SyncAppendEntries *pMsg); int32_t (*FpOnSyncAppendEntriesReply)(SSyncNode *pSyncNode, SyncAppendEntriesReply *pMsg); int32_t (*FpOnSyncTimeout)(SSyncNode *pSyncNode, SyncTimeout *pMsg); - - int32_t (*FpOnSyncSnapshotSend)(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg); - int32_t (*FpOnSyncSnapshotRsp)(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg); + int32_t (*FpOnSyncSnapshot)(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg); + int32_t (*FpOnSyncSnapshotReply)(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg); int8_t isStart; diff --git a/source/libs/sync/inc/syncIndexMgr.h b/source/libs/sync/inc/syncIndexMgr.h index fb85b89419a8b09a4e60d174d51791acf5a5b6ae..e8f17537b4ad6a3e8bb79769ca5cbe8af346306b 100644 --- a/source/libs/sync/inc/syncIndexMgr.h +++ b/source/libs/sync/inc/syncIndexMgr.h @@ -45,8 +45,8 @@ void syncIndexMgrDestroy(SSyncIndexMgr *pSyncIndexMgr); void syncIndexMgrClear(SSyncIndexMgr *pSyncIndexMgr); void syncIndexMgrSetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, SyncIndex index); SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId); -cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr); -char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr); +cJSON * syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr); +char * syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr); void syncIndexMgrSetStartTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, int64_t startTime); int64_t syncIndexMgrGetStartTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId); diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index 101e99afea8db60011fa535a53320a32c2dd376c..a158430a0ff6d361c072fb02d4bdf6317732ae5d 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -57,9 +57,37 @@ typedef struct SRaftCfg SRaftCfg; typedef struct SSyncRespMgr SSyncRespMgr; typedef struct SSyncSnapshotSender SSyncSnapshotSender; typedef struct SSyncSnapshotReceiver SSyncSnapshotReceiver; +typedef struct SSyncTimer SSyncTimer; +typedef struct SSyncHbTimerData SSyncHbTimerData; extern bool gRaftDetailLog; +typedef struct SSyncHbTimerData { + SSyncNode* pSyncNode; + SSyncTimer* pTimer; + SRaftId destId; + uint64_t logicClock; +} SSyncHbTimerData; + +typedef struct SSyncTimer { + void* pTimer; + TAOS_TMR_CALLBACK timerCb; + uint64_t logicClock; + uint64_t counter; + int32_t timerMS; + SRaftId destId; + void* pData; +} SSyncTimer; + +int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId destId); +int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer); +int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer); + +typedef struct SPeerState { + SyncIndex lastSendIndex; + int64_t lastSendTime; +} SPeerState; + typedef struct SSyncNode { // init by SSyncInfo SyncGroupId vgId; @@ -73,6 +101,7 @@ typedef struct SSyncNode { const SMsgCb* msgcb; int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg); int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); + int32_t (*FpEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); // init internal SNodeInfo myNodeInfo; @@ -138,6 +167,9 @@ typedef struct SSyncNode { TAOS_TMR_CALLBACK FpHeartbeatTimerCB; // Timer Fp uint64_t heartbeatTimerCounter; + // peer heartbeat timer + SSyncTimer peerHeartbeatTimerArr[TSDB_MAX_REPLICA]; + // callback FpOnPingCb FpOnPing; FpOnPingReplyCb FpOnPingReply; @@ -147,8 +179,8 @@ typedef struct SSyncNode { FpOnRequestVoteReplyCb FpOnRequestVoteReply; FpOnAppendEntriesCb FpOnAppendEntries; FpOnAppendEntriesReplyCb FpOnAppendEntriesReply; - FpOnSnapshotSendCb FpOnSnapshotSend; - FpOnSnapshotRspCb FpOnSnapshotRsp; + FpOnSnapshotCb FpOnSnapshot; + FpOnSnapshotReplyCb FpOnSnapshotReply; // tools SSyncRespMgr* pSyncRespMgr; @@ -159,9 +191,15 @@ typedef struct SSyncNode { SSyncSnapshotSender* senders[TSDB_MAX_REPLICA]; SSyncSnapshotReceiver* pNewNodeReceiver; + SPeerState peerStates[TSDB_MAX_REPLICA]; + // is config changing bool changing; + int64_t snapshottingIndex; + int64_t snapshottingTime; + int64_t minMatchIndex; + int64_t startTime; int64_t leaderTime; int64_t lastReplicateTime; @@ -174,7 +212,6 @@ void syncNodeStart(SSyncNode* pSyncNode); void syncNodeStartStandBy(SSyncNode* pSyncNode); void syncNodeClose(SSyncNode* pSyncNode); int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak); -int32_t syncNodeProposeBatch(SSyncNode* pSyncNode, SRpcMsg** pMsgPArr, bool* pIsWeakArr, int32_t arrSize); // option bool syncNodeSnapshotEnable(SSyncNode* pSyncNode); @@ -197,23 +234,21 @@ int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms); int32_t syncNodeResetElectTimer(SSyncNode* pSyncNode); int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode); -int32_t syncNodeStartHeartbeatTimerNow(SSyncNode* pSyncNode); -int32_t syncNodeStartHeartbeatTimerMS(SSyncNode* pSyncNode, int32_t ms); int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode); int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode); -int32_t syncNodeRestartHeartbeatTimerNow(SSyncNode* pSyncNode); -int32_t syncNodeRestartNowHeartbeatTimerMS(SSyncNode* pSyncNode, int32_t ms); // utils -------------- -int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg); -int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg); -cJSON* syncNode2Json(const SSyncNode* pSyncNode); -char* syncNode2Str(const SSyncNode* pSyncNode); -void syncNodeEventLog(const SSyncNode* pSyncNode, char* str); -void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str); -char* syncNode2SimpleStr(const SSyncNode* pSyncNode); -bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config); -void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* newConfig, SyncIndex lastConfigChangeIndex); +int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg); +int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg); +cJSON* syncNode2Json(const SSyncNode* pSyncNode); +char* syncNode2Str(const SSyncNode* pSyncNode); +void syncNodeEventLog(const SSyncNode* pSyncNode, char* str); +void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str); +char* syncNode2SimpleStr(const SSyncNode* pSyncNode); +bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config); +void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* newConfig, SyncIndex lastConfigChangeIndex); +SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode); +char* syncNodePeerState2Str(const SSyncNode* pSyncNode); SSyncNode* syncNodeAcquire(int64_t rid); void syncNodeRelease(SSyncNode* pNode); @@ -221,6 +256,7 @@ void syncNodeRelease(SSyncNode* pNode); // raft state change -------------- void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term); void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term); +void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm); void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr); void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr); @@ -240,21 +276,23 @@ void syncNodeMaybeUpdateCommitBySnapshot(SSyncNode* pSyncNode); SyncIndex syncNodeGetLastIndex(const SSyncNode* pSyncNode); SyncTerm syncNodeGetLastTerm(SSyncNode* pSyncNode); int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, SyncTerm* pLastTerm); - SyncIndex syncNodeSyncStartIndex(SSyncNode* pSyncNode); - SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index); SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index); int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex* pPreIndex, SyncTerm* pPreTerm); bool syncNodeIsOptimizedOneReplica(SSyncNode* ths, SRpcMsg* pMsg); -int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, uint64_t flag); +int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, uint64_t flag); +int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex); int32_t syncNodePreCommit(SSyncNode* ths, SSyncRaftEntry* pEntry, int32_t code); int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg); bool syncNodeInRaftGroup(SSyncNode* ths, SRaftId* pRaftId); SSyncSnapshotSender* syncNodeGetSnapshotSender(SSyncNode* ths, SRaftId* pDestId); +SSyncTimer* syncNodeGetHbTimer(SSyncNode* ths, SRaftId* pDestId); +SPeerState* syncNodeGetPeerState(SSyncNode* ths, const SRaftId* pDestId); +bool syncNodeNeedSendAppendEntries(SSyncNode* ths, const SRaftId* pDestId, const SyncAppendEntries* pMsg); int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta); int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta); @@ -271,7 +309,12 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode); +bool syncNodeIsMnode(SSyncNode* pSyncNode); +int32_t syncNodePeerStateInit(SSyncNode* pSyncNode); + // trace log +void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s); + void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s); void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s); @@ -287,6 +330,12 @@ void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntries void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s); void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s); +void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s); +void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s); + +void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s); +void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s); + // for debug -------------- void syncNodePrint(SSyncNode* pObj); void syncNodePrint2(char* s, SSyncNode* pObj); diff --git a/source/libs/sync/inc/syncRaftCfg.h b/source/libs/sync/inc/syncRaftCfg.h index ba0f9738154475395dd17411b4eb616b5d919b4a..e193e16c02d3b811216bed03b1ad17899ebe04da 100644 --- a/source/libs/sync/inc/syncRaftCfg.h +++ b/source/libs/sync/inc/syncRaftCfg.h @@ -45,8 +45,8 @@ int32_t raftCfgIndexClose(SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexPersist(SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexAddConfigIndex(SRaftCfgIndex *pRaftCfgIndex, SyncIndex configIndex); -cJSON *raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex); -char *raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex); +cJSON * raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex); +char * raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexFromJson(const cJSON *pRoot, SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexFromStr(const char *s, SRaftCfgIndex *pRaftCfgIndex); @@ -73,14 +73,14 @@ int32_t raftCfgClose(SRaftCfg *pRaftCfg); int32_t raftCfgPersist(SRaftCfg *pRaftCfg); int32_t raftCfgAddConfigIndex(SRaftCfg *pRaftCfg, SyncIndex configIndex); -cJSON *syncCfg2Json(SSyncCfg *pSyncCfg); -char *syncCfg2Str(SSyncCfg *pSyncCfg); -char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg); +cJSON * syncCfg2Json(SSyncCfg *pSyncCfg); +char * syncCfg2Str(SSyncCfg *pSyncCfg); +char * syncCfg2SimpleStr(SSyncCfg *pSyncCfg); int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg); int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg); -cJSON *raftCfg2Json(SRaftCfg *pRaftCfg); -char *raftCfg2Str(SRaftCfg *pRaftCfg); +cJSON * raftCfg2Json(SRaftCfg *pRaftCfg); +char * raftCfg2Str(SRaftCfg *pRaftCfg); int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg); int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg); diff --git a/source/libs/sync/inc/syncReplication.h b/source/libs/sync/inc/syncReplication.h index edce124ee52fefb07d52ae7fc27038c0b14f9b35..4f15a45cec7dbd3dfa03189980629bc6f9804660 100644 --- a/source/libs/sync/inc/syncReplication.h +++ b/source/libs/sync/inc/syncReplication.h @@ -50,16 +50,15 @@ extern "C" { // msource |-> i, // mdest |-> j]) // /\ UNCHANGED <> -// -int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode); -int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode); -int32_t syncNodeAppendEntriesPeersSnapshot2(SSyncNode* pSyncNode); -int32_t syncNodeAppendEntriesOnePeer(SSyncNode* pSyncNode, SRaftId* pDestId, SyncIndex nextIndex); +int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode); +int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* pDestId, const SyncHeartbeat* pMsg); -int32_t syncNodeReplicate(SSyncNode* pSyncNode, bool isTimer); -int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg); -int32_t syncNodeAppendEntriesBatch(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntriesBatch* pMsg); +int32_t syncNodeReplicate(SSyncNode* pSyncNode); +int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId); + +int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* pDestId, const SyncAppendEntries* pMsg); +int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* pDestId, const SyncAppendEntries* pMsg); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncRequestVote.h b/source/libs/sync/inc/syncRequestVote.h index 3fe8dc0237ee42106d75ccbade515f91546189f0..73b4a0efaeab6b72153ff1193d4951ee9cb2e2ea 100644 --- a/source/libs/sync/inc/syncRequestVote.h +++ b/source/libs/sync/inc/syncRequestVote.h @@ -49,8 +49,7 @@ extern "C" { // m) // /\ UNCHANGED <> // -int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg); -int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg); +int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncRequestVoteReply.h b/source/libs/sync/inc/syncRequestVoteReply.h index ac47a8d0261c56a10ce8ff825f47d24d804269bc..6bef18405cc7780db60b04c1cf32161f20c2a42c 100644 --- a/source/libs/sync/inc/syncRequestVoteReply.h +++ b/source/libs/sync/inc/syncRequestVoteReply.h @@ -44,8 +44,7 @@ extern "C" { // /\ Discard(m) // /\ UNCHANGED <> // -int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg); -int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteReply* pMsg); +int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncRespMgr.h b/source/libs/sync/inc/syncRespMgr.h index 28978af77e674231138a33e6f59574c217e659fe..22e1005e5c495c6f4f17c452418d8b028d0cfffa 100644 --- a/source/libs/sync/inc/syncRespMgr.h +++ b/source/libs/sync/inc/syncRespMgr.h @@ -32,9 +32,9 @@ typedef struct SRespStub { } SRespStub; typedef struct SSyncRespMgr { - SHashObj *pRespHash; + SHashObj * pRespHash; int64_t ttl; - void *data; + void * data; TdThreadMutex mutex; uint64_t seqNum; } SSyncRespMgr; diff --git a/source/libs/sync/inc/syncSnapshot.h b/source/libs/sync/inc/syncSnapshot.h index 6fb558e45c66e13646c26b20e20bf60a7ded1d26..b8b7af2dda614b9f7e53cdb64e26fc941e295472 100644 --- a/source/libs/sync/inc/syncSnapshot.h +++ b/source/libs/sync/inc/syncSnapshot.h @@ -28,10 +28,10 @@ extern "C" { #include "syncMessage.h" #include "taosdef.h" -#define SYNC_SNAPSHOT_SEQ_INVALID -1 +#define SYNC_SNAPSHOT_SEQ_INVALID -1 #define SYNC_SNAPSHOT_SEQ_FORCE_CLOSE -2 -#define SYNC_SNAPSHOT_SEQ_BEGIN 0 -#define SYNC_SNAPSHOT_SEQ_END 0x7FFFFFFF +#define SYNC_SNAPSHOT_SEQ_BEGIN 0 +#define SYNC_SNAPSHOT_SEQ_END 0x7FFFFFFF #define SYNC_SNAPSHOT_RETRY_MS 5000 @@ -51,6 +51,7 @@ typedef struct SSyncSnapshotSender { int32_t replicaIndex; SyncTerm term; SyncTerm privateTerm; + int64_t startTime; bool finish; } SSyncSnapshotSender; @@ -67,6 +68,8 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender); char *snapshotSender2Str(SSyncSnapshotSender *pSender); char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event); +int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId); + //--------------------------------------------------- typedef struct SSyncSnapshotReceiver { bool start; @@ -94,8 +97,8 @@ char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event) //--------------------------------------------------- // on message -int32_t syncNodeOnSnapshotSendCb(SSyncNode *ths, SyncSnapshotSend *pMsg); -int32_t syncNodeOnSnapshotRspCb(SSyncNode *ths, SyncSnapshotRsp *pMsg); +int32_t syncNodeOnSnapshot(SSyncNode *ths, SyncSnapshotSend *pMsg); +int32_t syncNodeOnSnapshotReply(SSyncNode *ths, SyncSnapshotRsp *pMsg); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncTimeout.h b/source/libs/sync/inc/syncTimeout.h index 25c26c909da2c5616d2a56a6dd0689530f8e49a7..112a3d861024f70ce811f8f77487ce7550534db1 100644 --- a/source/libs/sync/inc/syncTimeout.h +++ b/source/libs/sync/inc/syncTimeout.h @@ -39,7 +39,7 @@ extern "C" { // /\ voterLog' = [voterLog EXCEPT ![i] = [j \in {} |-> <<>>]] // /\ UNCHANGED <> // -int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg); +int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg); #ifdef __cplusplus } diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 4a35a15d3e35189daa291094c575e35d05ed8e02..170a57a7a9835e1a1adee90983dd5f86517377df 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -89,240 +89,6 @@ // /\ UNCHANGED <> // -int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { - int32_t ret = 0; - - // if already drop replica, do not process - if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncLogRecvAppendEntries(ths, pMsg, "maybe replica already dropped"); - return -1; - } - - // maybe update term - if (pMsg->term > ths->pRaftStore->currentTerm) { - syncNodeUpdateTerm(ths, pMsg->term); - } - ASSERT(pMsg->term <= ths->pRaftStore->currentTerm); - - // reset elect timer - if (pMsg->term == ths->pRaftStore->currentTerm) { - ths->leaderCache = pMsg->srcId; - syncNodeResetElectTimer(ths); - } - ASSERT(pMsg->dataLen >= 0); - - // return to follower state - if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE) { - syncLogRecvAppendEntries(ths, pMsg, "candidate to follower"); - syncNodeBecomeFollower(ths, "from candidate by append entries"); - return -1; // ret or reply? - } - - SyncTerm localPreLogTerm = 0; - if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) { - SSyncRaftEntry* pEntry = ths->pLogStore->getEntry(ths->pLogStore, pMsg->prevLogIndex); - if (pEntry == NULL) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "getEntry error, index:%" PRId64 ", since %s", pMsg->prevLogIndex, terrstr()); - syncNodeErrorLog(ths, logBuf); - return -1; - } - - localPreLogTerm = pEntry->term; - syncEntryDestory(pEntry); - } - - bool logOK = - (pMsg->prevLogIndex == SYNC_INDEX_INVALID) || - ((pMsg->prevLogIndex >= SYNC_INDEX_BEGIN) && - (pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) && (pMsg->prevLogTerm == localPreLogTerm)); - - // reject request - if ((pMsg->term < ths->pRaftStore->currentTerm) || - ((pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK)) { - syncLogRecvAppendEntries(ths, pMsg, "reject"); - - SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->success = false; - pReply->matchIndex = SYNC_INDEX_INVALID; - pReply->startTime = ths->startTime; - - // msg event log - syncLogSendAppendEntriesReply(ths, pReply, ""); - - SRpcMsg rpcMsg; - syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); - syncAppendEntriesReplyDestroy(pReply); - - return ret; - } - - // accept request - if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_FOLLOWER && logOK) { - // preIndex = -1, or has preIndex entry in local log - ASSERT(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)); - - // has extra entries (> preIndex) in local log - bool hasExtraEntries = pMsg->prevLogIndex < ths->pLogStore->getLastIndex(ths->pLogStore); - - // has entries in SyncAppendEntries msg - bool hasAppendEntries = pMsg->dataLen > 0; - - syncLogRecvAppendEntries(ths, pMsg, "accept"); - - if (hasExtraEntries && hasAppendEntries) { - // not conflict by default - bool conflict = false; - - SyncIndex extraIndex = pMsg->prevLogIndex + 1; - SSyncRaftEntry* pExtraEntry = ths->pLogStore->getEntry(ths->pLogStore, extraIndex); - if (pExtraEntry == NULL) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "getEntry error2, index:%" PRId64 ", since %s", extraIndex, terrstr()); - syncNodeErrorLog(ths, logBuf); - return -1; - } - - SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen); - if (pAppendEntry == NULL) { - syncNodeErrorLog(ths, "syncEntryDeserialize pAppendEntry error"); - return -1; - } - - // log not match, conflict - ASSERT(extraIndex == pAppendEntry->index); - if (pExtraEntry->term != pAppendEntry->term) { - conflict = true; - } - - if (conflict) { - // roll back - SyncIndex delBegin = ths->pLogStore->getLastIndex(ths->pLogStore); - SyncIndex delEnd = extraIndex; - - sTrace("syncNodeOnAppendEntriesCb --> conflict:%d, delBegin:%" PRId64 ", delEnd:%" PRId64, conflict, delBegin, - delEnd); - - // notice! reverse roll back! - for (SyncIndex index = delEnd; index >= delBegin; --index) { - if (ths->pFsm->FpRollBackCb != NULL) { - SSyncRaftEntry* pRollBackEntry = ths->pLogStore->getEntry(ths->pLogStore, index); - if (pRollBackEntry == NULL) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "getEntry error3, index:%" PRId64 ", since %s", index, terrstr()); - syncNodeErrorLog(ths, logBuf); - return -1; - } - - // if (pRollBackEntry->msgType != TDMT_SYNC_NOOP) { - if (syncUtilUserRollback(pRollBackEntry->msgType)) { - SRpcMsg rpcMsg; - syncEntry2OriginalRpc(pRollBackEntry, &rpcMsg); - - SFsmCbMeta cbMeta = {0}; - cbMeta.index = pRollBackEntry->index; - cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index); - cbMeta.isWeak = pRollBackEntry->isWeak; - cbMeta.code = 0; - cbMeta.state = ths->state; - cbMeta.seqNum = pRollBackEntry->seqNum; - ths->pFsm->FpRollBackCb(ths->pFsm, &rpcMsg, cbMeta); - rpcFreeCont(rpcMsg.pCont); - } - - syncEntryDestory(pRollBackEntry); - } - } - - // delete confict entries - ths->pLogStore->truncate(ths->pLogStore, extraIndex); - - // append new entries - ths->pLogStore->appendEntry(ths->pLogStore, pAppendEntry); - - // pre commit - syncNodePreCommit(ths, pAppendEntry, 0); - } - - // free memory - syncEntryDestory(pExtraEntry); - syncEntryDestory(pAppendEntry); - - } else if (hasExtraEntries && !hasAppendEntries) { - // do nothing - - } else if (!hasExtraEntries && hasAppendEntries) { - SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen); - if (pAppendEntry == NULL) { - syncNodeErrorLog(ths, "syncEntryDeserialize pAppendEntry2 error"); - return -1; - } - - // append new entries - ths->pLogStore->appendEntry(ths->pLogStore, pAppendEntry); - - // pre commit - syncNodePreCommit(ths, pAppendEntry, 0); - - // free memory - syncEntryDestory(pAppendEntry); - - } else if (!hasExtraEntries && !hasAppendEntries) { - // do nothing - - } else { - syncNodeLog3("", ths); - ASSERT(0); - } - - SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->success = true; - - if (hasAppendEntries) { - pReply->matchIndex = pMsg->prevLogIndex + 1; - } else { - pReply->matchIndex = pMsg->prevLogIndex; - } - - pReply->startTime = ths->startTime; - - // msg event log - syncLogSendAppendEntriesReply(ths, pReply, ""); - - SRpcMsg rpcMsg; - syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); - syncAppendEntriesReplyDestroy(pReply); - - // maybe update commit index from leader - if (pMsg->commitIndex > ths->commitIndex) { - // has commit entry in local - if (pMsg->commitIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) { - SyncIndex beginIndex = ths->commitIndex + 1; - SyncIndex endIndex = pMsg->commitIndex; - - // update commit index - ths->commitIndex = pMsg->commitIndex; - - // call back Wal - ths->pLogStore->updateCommitIndex(ths->pLogStore, ths->commitIndex); - - int32_t code = syncNodeCommit(ths, beginIndex, endIndex, ths->state); - ASSERT(code == 0); - } - } - } - - return ret; -} - static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) { int32_t code; @@ -408,7 +174,7 @@ static int32_t syncNodeDoMakeLogSame(SSyncNode* ths, SyncIndex FromIndex) { do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "update delete begin to %ld", delBegin); + snprintf(logBuf, sizeof(logBuf), "update delete begin to %" PRId64, delBegin); syncNodeEventLog(ths, logBuf); } while (0); } @@ -419,7 +185,8 @@ static int32_t syncNodeDoMakeLogSame(SSyncNode* ths, SyncIndex FromIndex) { do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "make log same from:%ld, delbegin:%ld, pass:%d", FromIndex, delBegin, pass); + snprintf(logBuf, sizeof(logBuf), "make log same from:%" PRId64 ", delbegin:%" PRId64 ", pass:%d", FromIndex, + delBegin, pass); syncNodeEventLog(ths, logBuf); } while (0); @@ -504,544 +271,222 @@ static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries return false; } -int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatch* pMsg) { - int32_t ret = 0; - int32_t code = 0; +int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) { + // maybe update commit index, leader notice me + if (newCommitIndex > ths->commitIndex) { + // has commit entry in local + if (newCommitIndex <= ths->pLogStore->syncLogLastIndex(ths->pLogStore)) { + // advance commit index to sanpshot first + SSnapshot snapshot; + ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot); + if (snapshot.lastApplyIndex >= 0 && snapshot.lastApplyIndex > ths->commitIndex) { + SyncIndex commitBegin = ths->commitIndex; + SyncIndex commitEnd = snapshot.lastApplyIndex; + ths->commitIndex = snapshot.lastApplyIndex; + + char eventLog[128]; + snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin, + commitEnd); + syncNodeEventLog(ths, eventLog); + } - // if already drop replica, do not process - if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncLogRecvAppendEntriesBatch(ths, pMsg, "maybe replica already dropped"); - return -1; - } + SyncIndex beginIndex = ths->commitIndex + 1; + SyncIndex endIndex = newCommitIndex; - // maybe update term - if (pMsg->term > ths->pRaftStore->currentTerm) { - syncNodeUpdateTerm(ths, pMsg->term); - } - ASSERT(pMsg->term <= ths->pRaftStore->currentTerm); + // update commit index + ths->commitIndex = newCommitIndex; - // reset elect timer - if (pMsg->term == ths->pRaftStore->currentTerm) { - ths->leaderCache = pMsg->srcId; - syncNodeResetElectTimer(ths); - } - ASSERT(pMsg->dataLen >= 0); + // call back Wal + int32_t code = ths->pLogStore->syncLogUpdateCommitIndex(ths->pLogStore, ths->commitIndex); + ASSERT(code == 0); - // candidate to follower - // - // operation: - // to follower - do { - bool condition = pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE; - if (condition) { - syncLogRecvAppendEntriesBatch(ths, pMsg, "candidate to follower"); - syncNodeBecomeFollower(ths, "from candidate by append entries"); - return 0; // do not reply? + code = syncNodeDoCommit(ths, beginIndex, endIndex, ths->state); + ASSERT(code == 0); } - } while (0); + } - // fake match - // - // condition1: - // preIndex <= my commit index - // - // operation: - // if hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex, append entry - // match my-commit-index or my-commit-index + batchSize - do { - bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && - (pMsg->prevLogIndex <= ths->commitIndex); - if (condition) { - syncLogRecvAppendEntriesBatch(ths, pMsg, "fake match"); - - SyncIndex matchIndex = ths->commitIndex; - bool hasAppendEntries = pMsg->dataLen > 0; - SOffsetAndContLen* metaTableArr = syncAppendEntriesBatchMetaTableArray(pMsg); - - if (hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex) { - int32_t pass = 0; - SyncIndex logLastIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore); - bool hasExtraEntries = logLastIndex > pMsg->prevLogIndex; - - // make log same - if (hasExtraEntries) { - // make log same, rollback deleted entries - pass = syncNodeDoMakeLogSame(ths, pMsg->prevLogIndex + 1); - ASSERT(pass >= 0); - } + return 0; +} - // append entry batch - if (pass == 0) { - // assert! no batch - ASSERT(pMsg->dataCount <= 1); +int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { + // if already drop replica, do not process + if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) { + syncLogRecvAppendEntries(ths, pMsg, "not in my config"); + goto _IGNORE; + } - for (int32_t i = 0; i < pMsg->dataCount; ++i) { - SSyncRaftEntry* pAppendEntry = (SSyncRaftEntry*)(pMsg->data + metaTableArr[i].offset); - code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); - if (code != 0) { - sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); - return -1; - } + // prepare response msg + SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); + pReply->srcId = ths->myRaftId; + pReply->destId = pMsg->srcId; + pReply->term = ths->pRaftStore->currentTerm; + pReply->success = false; + // pReply->matchIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore); + pReply->matchIndex = SYNC_INDEX_INVALID; + pReply->lastSendIndex = pMsg->prevLogIndex + 1; + pReply->privateTerm = ths->pNewNodeReceiver->privateTerm; + pReply->startTime = ths->startTime; + + if (pMsg->term < ths->pRaftStore->currentTerm) { + syncLogRecvAppendEntries(ths, pMsg, "reject, small term"); + goto _SEND_RESPONSE; + } - code = syncNodePreCommit(ths, pAppendEntry, 0); - ASSERT(code == 0); + if (pMsg->term > ths->pRaftStore->currentTerm) { + pReply->term = pMsg->term; + } - // syncEntryDestory(pAppendEntry); - } - } + syncNodeStepDown(ths, pMsg->term); + syncNodeResetElectTimer(ths); - // fsync once - SSyncLogStoreData* pData = ths->pLogStore->data; - SWal* pWal = pData->pWal; - walFsync(pWal, false); + SyncIndex startIndex = ths->pLogStore->syncLogBeginIndex(ths->pLogStore); + SyncIndex lastIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore); - // update match index - matchIndex = pMsg->prevLogIndex + pMsg->dataCount; - } + if (pMsg->prevLogIndex > lastIndex) { + syncLogRecvAppendEntries(ths, pMsg, "reject, index not match"); + goto _SEND_RESPONSE; + } - // prepare response msg - SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->privateTerm = ths->pNewNodeReceiver->privateTerm; - pReply->success = true; - pReply->matchIndex = matchIndex; - pReply->startTime = ths->startTime; - - // msg event log - syncLogSendAppendEntriesReply(ths, pReply, ""); - - // send response - SRpcMsg rpcMsg; - syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); - syncAppendEntriesReplyDestroy(pReply); - - return 0; - } - } while (0); + if (pMsg->prevLogIndex >= startIndex) { + SyncTerm myPreLogTerm = syncNodeGetPreTerm(ths, pMsg->prevLogIndex + 1); + ASSERT(myPreLogTerm != SYNC_TERM_INVALID); - // calculate logOK here, before will coredump, due to fake match - bool logOK = syncNodeOnAppendEntriesBatchLogOK(ths, pMsg); - - // not match - // - // condition1: - // term < myTerm - // - // condition2: - // !logOK - // - // operation: - // not match - // no operation on log - do { - bool condition1 = pMsg->term < ths->pRaftStore->currentTerm; - bool condition2 = - (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK; - bool condition = condition1 || condition2; - - if (condition) { - syncLogRecvAppendEntriesBatch(ths, pMsg, "not match"); - - // maybe update commit index by snapshot - syncNodeMaybeUpdateCommitBySnapshot(ths); - - // prepare response msg - SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->privateTerm = ths->pNewNodeReceiver->privateTerm; - pReply->success = false; - pReply->matchIndex = ths->commitIndex; - pReply->startTime = ths->startTime; - - // msg event log - syncLogSendAppendEntriesReply(ths, pReply, ""); - - // send response - SRpcMsg rpcMsg; - syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); - syncAppendEntriesReplyDestroy(pReply); - - return 0; + if (myPreLogTerm != pMsg->prevLogTerm) { + syncLogRecvAppendEntries(ths, pMsg, "reject, pre-term not match"); + goto _SEND_RESPONSE; } - } while (0); - - // really match - // - // condition: - // logOK - // - // operation: - // match - // make log same - do { - bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && logOK; - if (condition) { - // has extra entries (> preIndex) in local log - SyncIndex myLastIndex = syncNodeGetLastIndex(ths); - bool hasExtraEntries = myLastIndex > pMsg->prevLogIndex; + } - // has entries in SyncAppendEntries msg - bool hasAppendEntries = pMsg->dataLen > 0; - SOffsetAndContLen* metaTableArr = syncAppendEntriesBatchMetaTableArray(pMsg); + // accept + pReply->success = true; + bool hasAppendEntries = pMsg->dataLen > 0; + if (hasAppendEntries) { + SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen); + ASSERT(pAppendEntry != NULL); - syncLogRecvAppendEntriesBatch(ths, pMsg, "really match"); + SyncIndex appendIndex = pMsg->prevLogIndex + 1; + SSyncRaftEntry* pLocalEntry = NULL; + int32_t code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, appendIndex, &pLocalEntry); + if (code == 0) { + if (pLocalEntry->term == pAppendEntry->term) { + // do nothing - int32_t pass = 0; + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "log match, do nothing, index:%" PRId64, appendIndex); + syncNodeEventLog(ths, logBuf); - if (hasExtraEntries) { - // make log same, rollback deleted entries - pass = syncNodeDoMakeLogSame(ths, pMsg->prevLogIndex + 1); - ASSERT(pass >= 0); - } + } else { + // truncate + code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex); + if (code != 0) { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "ignore, truncate error, append-index:%" PRId64, appendIndex); + syncLogRecvAppendEntries(ths, pMsg, logBuf); - if (hasAppendEntries) { - // append entry batch - if (pass == 0) { - // assert! no batch - ASSERT(pMsg->dataCount <= 1); - - // append entry batch - for (int32_t i = 0; i < pMsg->dataCount; ++i) { - SSyncRaftEntry* pAppendEntry = (SSyncRaftEntry*)(pMsg->data + metaTableArr[i].offset); - code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); - if (code != 0) { - sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); - return -1; - } - - code = syncNodePreCommit(ths, pAppendEntry, 0); - ASSERT(code == 0); - - // syncEntryDestory(pAppendEntry); - } + goto _IGNORE; } - // fsync once - SSyncLogStoreData* pData = ths->pLogStore->data; - SWal* pWal = pData->pWal; - walFsync(pWal, false); - } + // append + code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); + if (code != 0) { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "ignore, append error, append-index:%" PRId64, appendIndex); + syncLogRecvAppendEntries(ths, pMsg, logBuf); - // prepare response msg - SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->privateTerm = ths->pNewNodeReceiver->privateTerm; - pReply->success = true; - pReply->matchIndex = hasAppendEntries ? pMsg->prevLogIndex + pMsg->dataCount : pMsg->prevLogIndex; - pReply->startTime = ths->startTime; - - // msg event log - syncLogSendAppendEntriesReply(ths, pReply, ""); - - // send response - SRpcMsg rpcMsg; - syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); - syncAppendEntriesReplyDestroy(pReply); - - // maybe update commit index, leader notice me - if (pMsg->commitIndex > ths->commitIndex) { - SyncIndex lastIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore); - - SyncIndex beginIndex = 0; - SyncIndex endIndex = -1; - - // has commit entry in local - if (pMsg->commitIndex <= lastIndex) { - beginIndex = ths->commitIndex + 1; - endIndex = pMsg->commitIndex; - - // update commit index - ths->commitIndex = pMsg->commitIndex; - - // call back Wal - code = ths->pLogStore->updateCommitIndex(ths->pLogStore, ths->commitIndex); - ASSERT(code == 0); - - } else if (pMsg->commitIndex > lastIndex && ths->commitIndex < lastIndex) { - beginIndex = ths->commitIndex + 1; - endIndex = lastIndex; - - // update commit index, speed up - ths->commitIndex = lastIndex; - - // call back Wal - code = ths->pLogStore->updateCommitIndex(ths->pLogStore, ths->commitIndex); - ASSERT(code == 0); + goto _IGNORE; } - - code = syncNodeCommit(ths, beginIndex, endIndex, ths->state); - ASSERT(code == 0); } - return 0; - } - } while (0); - - return 0; -} - -int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMsg) { - int32_t ret = 0; - int32_t code = 0; - - // if already drop replica, do not process - if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncLogRecvAppendEntries(ths, pMsg, "maybe replica already dropped"); - return -1; - } - - // maybe update term - if (pMsg->term > ths->pRaftStore->currentTerm) { - syncNodeUpdateTerm(ths, pMsg->term); - } - ASSERT(pMsg->term <= ths->pRaftStore->currentTerm); - - // reset elect timer - if (pMsg->term == ths->pRaftStore->currentTerm) { - ths->leaderCache = pMsg->srcId; - syncNodeResetElectTimer(ths); - } - ASSERT(pMsg->dataLen >= 0); + } else { + if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { + // log not exist - // candidate to follower - // - // operation: - // to follower - do { - bool condition = pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE; - if (condition) { - syncLogRecvAppendEntries(ths, pMsg, "candidate to follower"); - syncNodeBecomeFollower(ths, "from candidate by append entries"); - return 0; // do not reply? - } - } while (0); + // truncate + code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex); + if (code != 0) { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, truncate error, append-index:%" PRId64, appendIndex); + syncLogRecvAppendEntries(ths, pMsg, logBuf); - // fake match - // - // condition1: - // preIndex <= my commit index - // - // operation: - // if hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex, append entry - // match my-commit-index or my-commit-index + 1 - // no operation on log - do { - bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && - (pMsg->prevLogIndex <= ths->commitIndex); - if (condition) { - syncLogRecvAppendEntries(ths, pMsg, "fake match"); - - SyncIndex matchIndex = ths->commitIndex; - bool hasAppendEntries = pMsg->dataLen > 0; - if (hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex) { - // append entry - SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen); - ASSERT(pAppendEntry != NULL); - - { - // has extra entries (> preIndex) in local log - SyncIndex logLastIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore); - bool hasExtraEntries = logLastIndex > pMsg->prevLogIndex; - - if (hasExtraEntries) { - // make log same, rollback deleted entries - code = syncNodeMakeLogSame(ths, pMsg); - ASSERT(code == 0); - } + goto _IGNORE; } + // append code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); if (code != 0) { - sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); - return -1; - } + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, append error, append-index:%" PRId64, appendIndex); + syncLogRecvAppendEntries(ths, pMsg, logBuf); - // pre commit - code = syncNodePreCommit(ths, pAppendEntry, 0); - ASSERT(code == 0); + goto _IGNORE; + } - // update match index - matchIndex = pMsg->prevLogIndex + 1; + } else { + // error + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "ignore, get local entry error, append-index:%" PRId64, appendIndex); + syncLogRecvAppendEntries(ths, pMsg, logBuf); - syncEntryDestory(pAppendEntry); + goto _IGNORE; } - - // prepare response msg - SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->privateTerm = ths->pNewNodeReceiver->privateTerm; - pReply->success = true; - pReply->matchIndex = matchIndex; - pReply->startTime = ths->startTime; - - // msg event log - syncLogSendAppendEntriesReply(ths, pReply, ""); - - // send response - SRpcMsg rpcMsg; - syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); - syncAppendEntriesReplyDestroy(pReply); - - return ret; } - } while (0); - // calculate logOK here, before will coredump, due to fake match - bool logOK = syncNodeOnAppendEntriesLogOK(ths, pMsg); - - // not match - // - // condition1: - // term < myTerm - // - // condition2: - // !logOK - // - // operation: - // not match - // no operation on log - do { - bool condition1 = pMsg->term < ths->pRaftStore->currentTerm; - bool condition2 = - (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK; - bool condition = condition1 || condition2; - - if (condition) { - syncLogRecvAppendEntries(ths, pMsg, "not match"); - - // prepare response msg - SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->privateTerm = ths->pNewNodeReceiver->privateTerm; - pReply->success = false; - pReply->matchIndex = SYNC_INDEX_INVALID; - pReply->startTime = ths->startTime; - - // msg event log - syncLogSendAppendEntriesReply(ths, pReply, ""); - - // send response - SRpcMsg rpcMsg; - syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); - syncAppendEntriesReplyDestroy(pReply); - - return ret; - } - } while (0); +#if 0 + if (code != 0 && terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { + code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex); + ASSERT(code == 0); - // really match - // - // condition: - // logOK - // - // operation: - // match - // make log same - do { - bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && logOK; - if (condition) { - // has extra entries (> preIndex) in local log - SyncIndex myLastIndex = syncNodeGetLastIndex(ths); - bool hasExtraEntries = myLastIndex > pMsg->prevLogIndex; + code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); + ASSERT(code == 0); - // has entries in SyncAppendEntries msg - bool hasAppendEntries = pMsg->dataLen > 0; + } else { + ASSERT(code == 0); - syncLogRecvAppendEntries(ths, pMsg, "really match"); + if (pLocalEntry->term == pAppendEntry->term) { + // do nothing + } else { + code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex); + ASSERT(code == 0); - if (hasExtraEntries) { - // make log same, rollback deleted entries - code = syncNodeMakeLogSame(ths, pMsg); + code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); ASSERT(code == 0); } + } +#endif - if (hasAppendEntries) { - // append entry - SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen); - ASSERT(pAppendEntry != NULL); + // update match index + pReply->matchIndex = pAppendEntry->index; - code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); - if (code != 0) { - sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); - return -1; - } + syncEntryDestory(pLocalEntry); + syncEntryDestory(pAppendEntry); - // pre commit - code = syncNodePreCommit(ths, pAppendEntry, 0); - ASSERT(code == 0); + } else { + // no append entries, do nothing + // maybe has extra entries, no harm - syncEntryDestory(pAppendEntry); - } + // update match index + pReply->matchIndex = pMsg->prevLogIndex; + } - // prepare response msg - SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->privateTerm = ths->pNewNodeReceiver->privateTerm; - pReply->success = true; - pReply->matchIndex = hasAppendEntries ? pMsg->prevLogIndex + 1 : pMsg->prevLogIndex; - pReply->startTime = ths->startTime; - - // msg event log - syncLogSendAppendEntriesReply(ths, pReply, ""); - - // send response - SRpcMsg rpcMsg; - syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); - syncAppendEntriesReplyDestroy(pReply); - - // maybe update commit index, leader notice me - if (pMsg->commitIndex > ths->commitIndex) { - // has commit entry in local - if (pMsg->commitIndex <= ths->pLogStore->syncLogLastIndex(ths->pLogStore)) { - // advance commit index to sanpshot first - SSnapshot snapshot; - ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot); - if (snapshot.lastApplyIndex >= 0 && snapshot.lastApplyIndex > ths->commitIndex) { - SyncIndex commitBegin = ths->commitIndex; - SyncIndex commitEnd = snapshot.lastApplyIndex; - ths->commitIndex = snapshot.lastApplyIndex; - - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, - commitBegin, commitEnd); - syncNodeEventLog(ths, eventLog); - } - - SyncIndex beginIndex = ths->commitIndex + 1; - SyncIndex endIndex = pMsg->commitIndex; - - // update commit index - ths->commitIndex = pMsg->commitIndex; - - // call back Wal - code = ths->pLogStore->updateCommitIndex(ths->pLogStore, ths->commitIndex); - ASSERT(code == 0); - - code = syncNodeCommit(ths, beginIndex, endIndex, ths->state); - ASSERT(code == 0); - } - } - return ret; - } - } while (0); + // maybe update commit index, leader notice me + syncNodeFollowerCommit(ths, pMsg->commitIndex); - return ret; -} + syncLogRecvAppendEntries(ths, pMsg, "accept"); + goto _SEND_RESPONSE; + +_IGNORE: + syncAppendEntriesReplyDestroy(pReply); + return 0; + +_SEND_RESPONSE: + // msg event log + syncLogSendAppendEntriesReply(ths, pReply, ""); + + // send response + SRpcMsg rpcMsg; + syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); + syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); + syncAppendEntriesReplyDestroy(pReply); + + return 0; +} \ No newline at end of file diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index 9253ed0129751c2e0d0538602dc124b38a72447d..5e6c9f153422cf9e6f3baeaec8cf93ca8f0339ab 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -20,6 +20,7 @@ #include "syncRaftCfg.h" #include "syncRaftLog.h" #include "syncRaftStore.h" +#include "syncReplication.h" #include "syncSnapshot.h" #include "syncUtil.h" #include "syncVoteMgr.h" @@ -37,74 +38,6 @@ // /\ Discard(m) // /\ UNCHANGED <> // -int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) { - int32_t ret = 0; - - // if already drop replica, do not process - if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncLogRecvAppendEntriesReply(ths, pMsg, "maybe replica already dropped"); - return -1; - } - - // drop stale response - if (pMsg->term < ths->pRaftStore->currentTerm) { - syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response"); - return 0; - } - - // no need this code, because if I receive reply.term, then I must have sent for that term. - // if (pMsg->term > ths->pRaftStore->currentTerm) { - // syncNodeUpdateTerm(ths, pMsg->term); - // } - - if (pMsg->term > ths->pRaftStore->currentTerm) { - syncLogRecvAppendEntriesReply(ths, pMsg, "error term"); - return -1; - } - - ASSERT(pMsg->term == ths->pRaftStore->currentTerm); - - // update time - syncIndexMgrSetStartTime(ths->pNextIndex, &(pMsg->srcId), pMsg->startTime); - syncIndexMgrSetRecvTime(ths->pNextIndex, &(pMsg->srcId), taosGetTimestampMs()); - - SyncIndex beforeNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - SyncIndex beforeMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); - - if (pMsg->success) { - // nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1] - syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1); - - // matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex] - syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex); - - // maybe commit - syncMaybeAdvanceCommitIndex(ths); - - } else { - SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - - // notice! int64, uint64 - if (nextIndex > SYNC_INDEX_BEGIN) { - --nextIndex; - } else { - nextIndex = SYNC_INDEX_BEGIN; - } - syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex); - } - - SyncIndex afterNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - SyncIndex afterMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); - do { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "before next:%" PRId64 ", match:%" PRId64 ", after next:%" PRId64 ", match:%" PRId64, beforeNextIndex, - beforeMatchIndex, afterNextIndex, afterMatchIndex); - syncLogRecvAppendEntriesReply(ths, pMsg, logBuf); - } while (0); - - return 0; -} // only start once static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, SyncTerm lastApplyTerm, @@ -151,13 +84,13 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync } } -int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) { +int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg) { int32_t ret = 0; // if already drop replica, do not process - if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncLogRecvAppendEntriesReply(ths, pMsg, "maybe replica already dropped"); - return -1; + if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) { + syncLogRecvAppendEntriesReply(ths, pMsg, "not in my config"); + return 0; } // drop stale response @@ -166,251 +99,40 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie return 0; } - // error term - if (pMsg->term > ths->pRaftStore->currentTerm) { - syncLogRecvAppendEntriesReply(ths, pMsg, "error term"); - return -1; - } - - ASSERT(pMsg->term == ths->pRaftStore->currentTerm); - - // update time - syncIndexMgrSetStartTime(ths->pNextIndex, &(pMsg->srcId), pMsg->startTime); - syncIndexMgrSetRecvTime(ths->pNextIndex, &(pMsg->srcId), taosGetTimestampMs()); - - SyncIndex beforeNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - SyncIndex beforeMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); - - if (pMsg->success) { - SyncIndex newNextIndex = pMsg->matchIndex + 1; - SyncIndex newMatchIndex = pMsg->matchIndex; - - bool needStartSnapshot = false; - if (newMatchIndex >= SYNC_INDEX_BEGIN && !ths->pLogStore->syncLogExist(ths->pLogStore, newMatchIndex)) { - needStartSnapshot = true; + if (ths->state == TAOS_SYNC_STATE_LEADER) { + if (pMsg->term > ths->pRaftStore->currentTerm) { + syncLogRecvAppendEntriesReply(ths, pMsg, "error term"); + syncNodeStepDown(ths, pMsg->term); + return -1; } - if (!needStartSnapshot) { - // update next-index, match-index - syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), newNextIndex); - syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), newMatchIndex); + ASSERT(pMsg->term == ths->pRaftStore->currentTerm); - // maybe commit - if (ths->state == TAOS_SYNC_STATE_LEADER) { + if (pMsg->success) { + SyncIndex oldMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); + if (pMsg->matchIndex > oldMatchIndex) { + syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex); syncMaybeAdvanceCommitIndex(ths); } + syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1); } else { - // start snapshot - SSnapshot oldSnapshot; - ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &oldSnapshot); - if (oldSnapshot.lastApplyIndex > newMatchIndex) { - syncNodeStartSnapshotOnce(ths, newMatchIndex + 1, oldSnapshot.lastApplyIndex, oldSnapshot.lastApplyTerm, - pMsg); // term maybe not ok? - } - - syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), oldSnapshot.lastApplyIndex + 1); - syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), newMatchIndex); - } - - // event log, update next-index - do { - char host[64]; - int16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "reset next-index:%" PRId64 ", match-index:%" PRId64 " for %s:%d", newNextIndex, - newMatchIndex, host, port); - syncNodeEventLog(ths, logBuf); - - } while (0); - - } else { - SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - - if (nextIndex > SYNC_INDEX_BEGIN) { - --nextIndex; - - // speed up - if (nextIndex > pMsg->matchIndex + 1) { - nextIndex = pMsg->matchIndex + 1; - } - - bool needStartSnapshot = false; - if (nextIndex >= SYNC_INDEX_BEGIN && !ths->pLogStore->syncLogExist(ths->pLogStore, nextIndex)) { - needStartSnapshot = true; - } - if (nextIndex - 1 >= SYNC_INDEX_BEGIN && !ths->pLogStore->syncLogExist(ths->pLogStore, nextIndex - 1)) { - needStartSnapshot = true; - } - - if (!needStartSnapshot) { - // do nothing - - } else { - SSnapshot oldSnapshot; - ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &oldSnapshot); - SyncTerm newSnapshotTerm = oldSnapshot.lastApplyTerm; - - SyncIndex endIndex; - if (ths->pLogStore->syncLogExist(ths->pLogStore, nextIndex + 1)) { - endIndex = nextIndex; - } else { - endIndex = oldSnapshot.lastApplyIndex; - } - syncNodeStartSnapshotOnce(ths, pMsg->matchIndex + 1, endIndex, newSnapshotTerm, pMsg); - - // get sender - SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(pMsg->srcId)); - ASSERT(pSender != NULL); - SyncIndex sentryIndex = pSender->snapshot.lastApplyIndex + 1; - - // update nextIndex to sentryIndex - if (nextIndex <= sentryIndex) { - nextIndex = sentryIndex; - } + SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); + if (nextIndex > SYNC_INDEX_BEGIN) { + --nextIndex; } - - } else { - nextIndex = SYNC_INDEX_BEGIN; - } - syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex); - - SyncIndex oldMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); - if (pMsg->matchIndex > oldMatchIndex) { - syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex); - } - - // event log, update next-index - do { - char host[64]; - int16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - - SyncIndex newNextIndex = nextIndex; - SyncIndex newMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "reset2 next-index:%" PRId64 ", match-index:%" PRId64 " for %s:%d", newNextIndex, - newMatchIndex, host, port); - syncNodeEventLog(ths, logBuf); - - } while (0); - } - - SyncIndex afterNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - SyncIndex afterMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); - do { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "before next:%" PRId64 ", match:%" PRId64 ", after next:%" PRId64 ", match:%" PRId64, beforeNextIndex, - beforeMatchIndex, afterNextIndex, afterMatchIndex); - syncLogRecvAppendEntriesReply(ths, pMsg, logBuf); - } while (0); - - return 0; -} - -int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) { - int32_t ret = 0; - - // if already drop replica, do not process - if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncLogRecvAppendEntriesReply(ths, pMsg, "maybe replica already dropped"); - return -1; - } - - // drop stale response - if (pMsg->term < ths->pRaftStore->currentTerm) { - syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response"); - return 0; - } - - // no need this code, because if I receive reply.term, then I must have sent for that term. - // if (pMsg->term > ths->pRaftStore->currentTerm) { - // syncNodeUpdateTerm(ths, pMsg->term); - // } - - if (pMsg->term > ths->pRaftStore->currentTerm) { - syncLogRecvAppendEntriesReply(ths, pMsg, "error term"); - return -1; - } - - ASSERT(pMsg->term == ths->pRaftStore->currentTerm); - - // update time - syncIndexMgrSetStartTime(ths->pNextIndex, &(pMsg->srcId), pMsg->startTime); - syncIndexMgrSetRecvTime(ths->pNextIndex, &(pMsg->srcId), taosGetTimestampMs()); - - SyncIndex beforeNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - SyncIndex beforeMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); - - if (pMsg->success) { - // nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1] - syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1); - - // matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex] - syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex); - - // maybe commit - if (ths->state == TAOS_SYNC_STATE_LEADER) { - syncMaybeAdvanceCommitIndex(ths); + syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex); } - } else { - SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - - // notice! int64, uint64 - if (nextIndex > SYNC_INDEX_BEGIN) { - --nextIndex; - - // get sender - SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(pMsg->srcId)); - ASSERT(pSender != NULL); - - SSnapshot snapshot = {.data = NULL, - .lastApplyIndex = SYNC_INDEX_INVALID, - .lastApplyTerm = 0, - .lastConfigIndex = SYNC_INDEX_INVALID}; - void* pReader = NULL; - ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot, NULL, &pReader); - if (snapshot.lastApplyIndex >= SYNC_INDEX_BEGIN && nextIndex <= snapshot.lastApplyIndex + 1 && - !snapshotSenderIsStart(pSender) && pMsg->privateTerm < pSender->privateTerm) { - // has snapshot - ASSERT(pReader != NULL); - SSnapshotParam readerParam = {.start = 0, .end = snapshot.lastApplyIndex}; - snapshotSenderStart(pSender, readerParam, snapshot, pReader); - - } else { - // no snapshot - if (pReader != NULL) { - ths->pFsm->FpSnapshotStopRead(ths->pFsm, pReader); - } - } + // send next append entries + SPeerState* pState = syncNodeGetPeerState(ths, &(pMsg->srcId)); + ASSERT(pState != NULL); - SyncIndex sentryIndex = pSender->snapshot.lastApplyIndex + 1; - - // update nextIndex to sentryIndex - if (nextIndex <= sentryIndex) { - nextIndex = sentryIndex; - } - - } else { - nextIndex = SYNC_INDEX_BEGIN; + if (pMsg->lastSendIndex == pState->lastSendIndex) { + syncNodeReplicateOne(ths, &(pMsg->srcId)); } - - syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex); } - SyncIndex afterNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - SyncIndex afterMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); - do { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "before next:%" PRId64 ", match:%" PRId64 ", after next:%" PRId64 ", match:%" PRId64, beforeNextIndex, - beforeMatchIndex, afterNextIndex, afterMatchIndex); - syncLogRecvAppendEntriesReply(ths, pMsg, logBuf); - } while (0); - + syncLogRecvAppendEntriesReply(ths, pMsg, "process"); return 0; } \ No newline at end of file diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index 511113352ea07625b3cbf223add13d2c807ddbac..811a7b8e999b3c287c210c70fb7a71ed9ec3b419 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -45,8 +45,10 @@ // /\ UNCHANGED <> // void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { - syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pNextIndex", pSyncNode->pNextIndex); - syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pMatchIndex", pSyncNode->pMatchIndex); + if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { + syncNodeErrorLog(pSyncNode, "not leader, can not advance commit index"); + return; + } // advance commit index to sanpshot first SSnapshot snapshot; @@ -75,10 +77,12 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { if (h) { pEntry = (SSyncRaftEntry*)taosLRUCacheValue(pCache, h); } else { - pEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, index); - if (pEntry == NULL) { - sError("failed to get entry since %s. index:%lld", tstrerror(terrno), index); - return; + int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, index, &pEntry); + if (code != 0) { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "advance commit index error, read wal index:%" PRId64, index); + syncNodeErrorLog(pSyncNode, logBuf); + return; } } // cannot commit, even if quorum agree. need check term! @@ -125,13 +129,17 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { pSyncNode->commitIndex = newCommitIndex; // call back Wal - pSyncNode->pLogStore->updateCommitIndex(pSyncNode->pLogStore, pSyncNode->commitIndex); + pSyncNode->pLogStore->syncLogUpdateCommitIndex(pSyncNode->pLogStore, pSyncNode->commitIndex); // execute fsm if (pSyncNode->pFsm != NULL) { - int32_t code = syncNodeCommit(pSyncNode, beginIndex, endIndex, pSyncNode->state); + int32_t code = syncNodeDoCommit(pSyncNode, beginIndex, endIndex, pSyncNode->state); if (code != 0) { - wError("failed to commit sync node since %s", tstrerror(terrno)); + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "advance commit index error, do commit begin:%" PRId64 ", end:%" PRId64, + beginIndex, endIndex); + syncNodeErrorLog(pSyncNode, logBuf); + return; } } } @@ -162,6 +170,8 @@ static inline int64_t syncNodeAbs64(int64_t a, int64_t b) { } int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode) { + return pSyncNode->quorum; + int32_t quorum = 1; // self int64_t timeNow = taosGetTimestampMs(); @@ -220,6 +230,7 @@ int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode) { return quorum; } +/* bool syncAgree(SSyncNode* pSyncNode, SyncIndex index) { int agreeCount = 0; for (int i = 0; i < pSyncNode->replicaNum; ++i) { @@ -232,8 +243,8 @@ bool syncAgree(SSyncNode* pSyncNode, SyncIndex index) { } return false; } +*/ -/* bool syncAgree(SSyncNode* pSyncNode, SyncIndex index) { int agreeCount = 0; for (int i = 0; i < pSyncNode->replicaNum; ++i) { @@ -246,4 +257,3 @@ bool syncAgree(SSyncNode* pSyncNode, SyncIndex index) { } return false; } -*/ diff --git a/source/libs/sync/src/syncElection.c b/source/libs/sync/src/syncElection.c index 3f13249ce6b47c748685ca59421e1f9a42231e94..b428f4d2f2b3844f446f0ad9a0dde4fd3175f0f1 100644 --- a/source/libs/sync/src/syncElection.c +++ b/source/libs/sync/src/syncElection.c @@ -30,45 +30,6 @@ // msource |-> i, // mdest |-> j]) // /\ UNCHANGED <> -// -int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) { - ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE); - - int32_t ret = 0; - for (int i = 0; i < pSyncNode->peersNum; ++i) { - SyncRequestVote* pMsg = syncRequestVoteBuild(pSyncNode->vgId); - pMsg->srcId = pSyncNode->myRaftId; - pMsg->destId = pSyncNode->peersId[i]; - pMsg->term = pSyncNode->pRaftStore->currentTerm; - pMsg->lastLogIndex = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore); - pMsg->lastLogTerm = pSyncNode->pLogStore->getLastTerm(pSyncNode->pLogStore); - - ret = syncNodeRequestVote(pSyncNode, &pSyncNode->peersId[i], pMsg); - ASSERT(ret == 0); - syncRequestVoteDestroy(pMsg); - } - return ret; -} - -int32_t syncNodeRequestVotePeersSnapshot(SSyncNode* pSyncNode) { - ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE); - - int32_t ret = 0; - for (int i = 0; i < pSyncNode->peersNum; ++i) { - SyncRequestVote* pMsg = syncRequestVoteBuild(pSyncNode->vgId); - pMsg->srcId = pSyncNode->myRaftId; - pMsg->destId = pSyncNode->peersId[i]; - pMsg->term = pSyncNode->pRaftStore->currentTerm; - - ret = syncNodeGetLastIndexTerm(pSyncNode, &(pMsg->lastLogIndex), &(pMsg->lastLogTerm)); - ASSERT(ret == 0); - - ret = syncNodeRequestVote(pSyncNode, &pSyncNode->peersId[i], pMsg); - ASSERT(ret == 0); - syncRequestVoteDestroy(pMsg); - } - return ret; -} int32_t syncNodeElect(SSyncNode* pSyncNode) { syncNodeEventLog(pSyncNode, "begin election"); @@ -111,27 +72,38 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) { } - switch (pSyncNode->pRaftCfg->snapshotStrategy) { - case SYNC_STRATEGY_NO_SNAPSHOT: - ret = syncNodeRequestVotePeers(pSyncNode); - break; + ret = syncNodeRequestVotePeers(pSyncNode); + ASSERT(ret == 0); - case SYNC_STRATEGY_STANDARD_SNAPSHOT: - case SYNC_STRATEGY_WAL_FIRST: - ret = syncNodeRequestVotePeersSnapshot(pSyncNode); - break; + syncNodeResetElectTimer(pSyncNode); - default: - ret = syncNodeRequestVotePeers(pSyncNode); - break; + return ret; +} + +int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) { + if (pSyncNode->state != TAOS_SYNC_STATE_CANDIDATE) { + syncNodeEventLog(pSyncNode, "not candidate, stop elect"); + return 0; } - ASSERT(ret == 0); - syncNodeResetElectTimer(pSyncNode); + int32_t ret = 0; + for (int i = 0; i < pSyncNode->peersNum; ++i) { + SyncRequestVote* pMsg = syncRequestVoteBuild(pSyncNode->vgId); + pMsg->srcId = pSyncNode->myRaftId; + pMsg->destId = pSyncNode->peersId[i]; + pMsg->term = pSyncNode->pRaftStore->currentTerm; + + ret = syncNodeGetLastIndexTerm(pSyncNode, &(pMsg->lastLogIndex), &(pMsg->lastLogTerm)); + ASSERT(ret == 0); + + ret = syncNodeSendRequestVote(pSyncNode, &pSyncNode->peersId[i], pMsg); + ASSERT(ret == 0); + syncRequestVoteDestroy(pMsg); + } return ret; } -int32_t syncNodeRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncRequestVote* pMsg) { +int32_t syncNodeSendRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncRequestVote* pMsg) { int32_t ret = 0; syncLogSendRequestVote(pSyncNode, pMsg, ""); diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c index e9899a3e33701d425b85878cfa1253e111e3964c..afa2d43e13a90000da15093b658ca480b285791f 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/src/syncIO.c @@ -326,18 +326,18 @@ static void *syncIOConsumerFunc(void *param) { } } else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) { - if (io->FpOnSyncSnapshotSend != NULL) { + if (io->FpOnSyncSnapshot != NULL) { SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pRpcMsg); ASSERT(pSyncMsg != NULL); - io->FpOnSyncSnapshotSend(io->pSyncNode, pSyncMsg); + io->FpOnSyncSnapshot(io->pSyncNode, pSyncMsg); syncSnapshotSendDestroy(pSyncMsg); } } else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) { - if (io->FpOnSyncSnapshotRsp != NULL) { + if (io->FpOnSyncSnapshotReply != NULL) { SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pRpcMsg); ASSERT(pSyncMsg != NULL); - io->FpOnSyncSnapshotRsp(io->pSyncNode, pSyncMsg); + io->FpOnSyncSnapshotReply(io->pSyncNode, pSyncMsg); syncSnapshotRspDestroy(pSyncMsg); } diff --git a/source/libs/sync/src/syncIndexMgr.c b/source/libs/sync/src/syncIndexMgr.c index 28b5313ac514ef98f4295cd547b947447d9c09bc..8e78aeedc335c1368dc62435cf21dbb205316e11 100644 --- a/source/libs/sync/src/syncIndexMgr.c +++ b/source/libs/sync/src/syncIndexMgr.c @@ -83,6 +83,10 @@ void syncIndexMgrSetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, } SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId) { + if (pSyncIndexMgr == NULL) { + return SYNC_INDEX_INVALID; + } + for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) { if (syncUtilSameId(&((*(pSyncIndexMgr->replicas))[i]), pRaftId)) { SyncIndex idx = (pSyncIndexMgr->index)[i]; @@ -200,28 +204,28 @@ int64_t syncIndexMgrGetRecvTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRa // for debug ------------------- void syncIndexMgrPrint(SSyncIndexMgr *pObj) { char *serialized = syncIndexMgr2Str(pObj); - printf("syncIndexMgrPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncIndexMgrPrint | len:%" PRIu64 " | %s \n", (uint64_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncIndexMgrPrint2(char *s, SSyncIndexMgr *pObj) { char *serialized = syncIndexMgr2Str(pObj); - printf("syncIndexMgrPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncIndexMgrPrint2 | len:%" PRIu64 " | %s | %s \n", (uint64_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncIndexMgrLog(SSyncIndexMgr *pObj) { char *serialized = syncIndexMgr2Str(pObj); - sTrace("syncIndexMgrLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncIndexMgrLog | len:%" PRIu64 " | %s", (uint64_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncIndexMgrLog2(char *s, SSyncIndexMgr *pObj) { if (gRaftDetailLog) { char *serialized = syncIndexMgr2Str(pObj); - sTrace("syncIndexMgrLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncIndexMgrLog2 | len:%" PRIu64 " | %s | %s", (uint64_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 6e4eaa0aaf71908eea798a6916dda5a5e4642ec2..fd2a1b22b439a382a8467dfeed6cf529e1a12f7a 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -46,6 +46,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId); static void syncNodeEqHeartbeatTimer(void* param, void* tmrId); static int32_t syncNodeEqNoop(SSyncNode* ths); static int32_t syncNodeAppendNoop(SSyncNode* ths); +static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId); // process message ---- int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg); @@ -67,7 +68,7 @@ int32_t syncInit() { syncCleanUp(); ret = -1; } else { - sDebug("sync rsetId:%" PRId64 " is open", tsNodeRefId); + sDebug("sync rsetId:%d is open", tsNodeRefId); ret = syncEnvStart(); } } @@ -80,7 +81,7 @@ void syncCleanUp() { ASSERT(ret == 0); if (tsNodeRefId != -1) { - sDebug("sync rsetId:%" PRId64 " is closed", tsNodeRefId); + sDebug("sync rsetId:%d is closed", tsNodeRefId); taosCloseRef(tsNodeRefId); tsNodeRefId = -1; } @@ -89,7 +90,7 @@ void syncCleanUp() { int64_t syncOpen(SSyncInfo* pSyncInfo) { SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo); if (pSyncNode == NULL) { - sError("vgId:%d, failed to open sync node since %s", pSyncInfo->vgId, terrstr()); + sError("vgId:%d, failed to open sync node", pSyncInfo->vgId); return -1; } @@ -100,12 +101,12 @@ int64_t syncOpen(SSyncInfo* pSyncInfo) { return -1; } - sDebug("vgId:%d, sync rid:%" PRId64 " is added to rsetId:%" PRId64, pSyncInfo->vgId, pSyncNode->rid, tsNodeRefId); + sDebug("vgId:%d, sync rid:%" PRId64 " is added to rsetId:%d", pSyncInfo->vgId, pSyncNode->rid, tsNodeRefId); return pSyncNode->rid; } void syncStart(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { return; } @@ -120,7 +121,7 @@ void syncStart(int64_t rid) { } void syncStartNormal(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { return; } @@ -130,7 +131,7 @@ void syncStartNormal(int64_t rid) { } void syncStartStandBy(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { return; } @@ -140,17 +141,17 @@ void syncStartStandBy(int64_t rid) { } void syncStop(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) return; int32_t vgId = pSyncNode->vgId; taosReleaseRef(tsNodeRefId, pSyncNode->rid); taosRemoveRef(tsNodeRefId, rid); - sDebug("vgId:%d, sync rid:%" PRId64 " is removed from rsetId:%" PRId64, vgId, rid, tsNodeRefId); + sDebug("vgId:%d, sync rid:%" PRId64 " is removed from rsetId:%d", vgId, rid, tsNodeRefId); } int32_t syncSetStandby(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { terrno = TSDB_CODE_SYN_INTERNAL_ERROR; sError("failed to set standby since accquire ref error, rid:%" PRId64, rid); @@ -238,7 +239,6 @@ int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) { } ASSERT(rid == pSyncNode->rid); -#if 0 if (!syncNodeCheckNewConfig(pSyncNode, pNewCfg)) { taosReleaseRef(tsNodeRefId, pSyncNode->rid); terrno = TSDB_CODE_SYN_NEW_CONFIG_ERROR; @@ -246,6 +246,7 @@ int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) { return -1; } +#if 0 char* newconfig = syncCfg2Str((SSyncCfg*)pNewCfg); int32_t ret = 0; @@ -263,6 +264,17 @@ int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) { #else syncNodeUpdateNewConfigIndex(pSyncNode, pNewCfg); syncNodeDoConfigChange(pSyncNode, pNewCfg, SYNC_INDEX_INVALID); + if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { + syncNodeStopHeartbeatTimer(pSyncNode); + + for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { + syncHbTimerInit(pSyncNode, &(pSyncNode->peerHeartbeatTimerArr[i]), (pSyncNode->replicasId)[i]); + } + + syncNodeStartHeartbeatTimer(pSyncNode); + + syncNodeReplicate(pSyncNode); + } taosReleaseRef(tsNodeRefId, pSyncNode->rid); return 0; #endif @@ -294,6 +306,225 @@ int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader) { return ret; } +SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode) { + SyncIndex minMatchIndex = SYNC_INDEX_INVALID; + + if (pSyncNode->peersNum > 0) { + minMatchIndex = syncIndexMgrGetIndex(pSyncNode->pMatchIndex, &(pSyncNode->peersId[0])); + } + + for (int32_t i = 1; i < pSyncNode->peersNum; ++i) { + SyncIndex matchIndex = syncIndexMgrGetIndex(pSyncNode->pMatchIndex, &(pSyncNode->peersId[i])); + if (matchIndex < minMatchIndex) { + minMatchIndex = matchIndex; + } + } + return minMatchIndex; +} + +char* syncNodePeerState2Str(const SSyncNode* pSyncNode) { + int32_t len = 128; + int32_t useLen = 0; + int32_t leftLen = len - useLen; + char* pStr = taosMemoryMalloc(len); + memset(pStr, 0, len); + + char* p = pStr; + int32_t use = snprintf(p, leftLen, "{"); + useLen += use; + leftLen -= use; + + for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) { + SPeerState* pState = syncNodeGetPeerState((SSyncNode*)pSyncNode, &(pSyncNode->replicasId[i])); + ASSERT(pState != NULL); + + p = pStr + useLen; + use = snprintf(p, leftLen, "%d:%" PRId64 " ,%" PRId64, i, pState->lastSendIndex, pState->lastSendTime); + useLen += use; + leftLen -= use; + } + + p = pStr + useLen; + use = snprintf(p, leftLen, "}"); + useLen += use; + leftLen -= use; + + // sTrace("vgId:%d, ------------------ syncNodePeerState2Str:%s", pSyncNode->vgId, pStr); + + return pStr; +} + +int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { + SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + if (pSyncNode == NULL) { + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + return -1; + } + ASSERT(rid == pSyncNode->rid); + int32_t code = 0; + + if (syncNodeIsMnode(pSyncNode)) { + // mnode + int64_t logRetention = SYNC_MNODE_LOG_RETENTION; + + SyncIndex beginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); + SyncIndex endIndex = pSyncNode->pLogStore->syncLogEndIndex(pSyncNode->pLogStore); + int64_t logNum = endIndex - beginIndex; + bool isEmpty = pSyncNode->pLogStore->syncLogIsEmpty(pSyncNode->pLogStore); + + if (isEmpty || (!isEmpty && logNum < logRetention)) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "new-snapshot-index:%" PRId64 ", log-num:%" PRId64 ", empty:%d, do not delete wal", lastApplyIndex, + logNum, isEmpty); + syncNodeEventLog(pSyncNode, logBuf); + + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return 0; + } + + goto _DEL_WAL; + + } else { + // vnode + if (pSyncNode->replicaNum > 1) { + // multi replicas + + if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { + pSyncNode->minMatchIndex = syncMinMatchIndex(pSyncNode); + + for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { + int64_t matchIndex = syncIndexMgrGetIndex(pSyncNode->pMatchIndex, &(pSyncNode->peersId[i])); + if (lastApplyIndex > matchIndex) { + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pSyncNode->peersId[i].addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "new-snapshot-index:%" PRId64 " is greater than match-index:%" PRId64 + " of %s:%d, do not delete wal", + lastApplyIndex, matchIndex, host, port); + syncNodeEventLog(pSyncNode, logBuf); + } while (0); + + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return 0; + } + } + + } else if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) { + if (lastApplyIndex > pSyncNode->minMatchIndex) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "new-snapshot-index:%" PRId64 " is greater than min-match-index:%" PRId64 ", do not delete wal", + lastApplyIndex, pSyncNode->minMatchIndex); + syncNodeEventLog(pSyncNode, logBuf); + + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return 0; + } + + } else if (pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%" PRId64 " candidate, do not delete wal", lastApplyIndex); + syncNodeEventLog(pSyncNode, logBuf); + + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return 0; + + } else { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%" PRId64 " unknown state, do not delete wal", + lastApplyIndex); + syncNodeEventLog(pSyncNode, logBuf); + + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return 0; + } + + goto _DEL_WAL; + + } else { + // one replica + + goto _DEL_WAL; + } + } + +_DEL_WAL: + + do { + SyncIndex snapshottingIndex = atomic_load_64(&pSyncNode->snapshottingIndex); + + if (snapshottingIndex == SYNC_INDEX_INVALID) { + atomic_store_64(&pSyncNode->snapshottingIndex, lastApplyIndex); + pSyncNode->snapshottingTime = taosGetTimestampMs(); + + SSyncLogStoreData* pData = pSyncNode->pLogStore->data; + code = walBeginSnapshot(pData->pWal, lastApplyIndex); + if (code == 0) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "wal snapshot begin, index:%" PRId64 ", last apply index:%" PRId64, + pSyncNode->snapshottingIndex, lastApplyIndex); + syncNodeEventLog(pSyncNode, logBuf); + + } else { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "wal snapshot begin error since:%s, index:%" PRId64 ", last apply index:%" PRId64, terrstr(terrno), + pSyncNode->snapshottingIndex, lastApplyIndex); + syncNodeErrorLog(pSyncNode, logBuf); + + atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID); + } + + } else { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "snapshotting for %" PRId64 ", do not delete wal for new-snapshot-index:%" PRId64, snapshottingIndex, + lastApplyIndex); + syncNodeEventLog(pSyncNode, logBuf); + } + } while (0); + + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return code; +} + +int32_t syncEndSnapshot(int64_t rid) { + SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + if (pSyncNode == NULL) { + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + return -1; + } + ASSERT(rid == pSyncNode->rid); + + int32_t code = 0; + if (atomic_load_64(&pSyncNode->snapshottingIndex) != SYNC_INDEX_INVALID) { + SSyncLogStoreData* pData = pSyncNode->pLogStore->data; + code = walEndSnapshot(pData->pWal); + if (code != 0) { + sError("vgId:%d, wal snapshot end error since:%s", pSyncNode->vgId, terrstr(terrno)); + + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return -1; + } else { + do { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "wal snapshot end, index:%" PRId64, + atomic_load_64(&pSyncNode->snapshottingIndex)); + syncNodeEventLog(pSyncNode, logBuf); + } while (0); + + atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID); + } + } + + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return code; +} + int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode) { if (pSyncNode->peersNum == 0) { sDebug("only one replica, cannot leader transfer"); @@ -716,24 +947,6 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) { return ret; } -int32_t syncProposeBatch(int64_t rid, SRpcMsg** pMsgPArr, bool* pIsWeakArr, int32_t arrSize) { - if (arrSize < 0) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - - SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - ASSERT(rid == pSyncNode->rid); - - int32_t ret = syncNodeProposeBatch(pSyncNode, pMsgPArr, pIsWeakArr, arrSize); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return ret; -} - static bool syncNodeBatchOK(SRpcMsg** pMsgPArr, int32_t arrSize) { for (int32_t i = 0; i < arrSize; ++i) { if (pMsgPArr[i]->msgType == TDMT_SYNC_CONFIG_CHANGE) { @@ -748,91 +961,6 @@ static bool syncNodeBatchOK(SRpcMsg** pMsgPArr, int32_t arrSize) { return true; } -int32_t syncNodeProposeBatch(SSyncNode* pSyncNode, SRpcMsg** pMsgPArr, bool* pIsWeakArr, int32_t arrSize) { - if (!syncNodeBatchOK(pMsgPArr, arrSize)) { - syncNodeErrorLog(pSyncNode, "sync propose batch error"); - terrno = TSDB_CODE_SYN_BATCH_ERROR; - return -1; - } - - if (arrSize > SYNC_MAX_BATCH_SIZE) { - syncNodeErrorLog(pSyncNode, "sync propose batch error"); - terrno = TSDB_CODE_SYN_BATCH_ERROR; - return -1; - } - - if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { - syncNodeErrorLog(pSyncNode, "sync propose not leader"); - terrno = TSDB_CODE_SYN_NOT_LEADER; - return -1; - } - - if (pSyncNode->changing) { - syncNodeErrorLog(pSyncNode, "sync propose not ready"); - terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY; - return -1; - } - - SRaftMeta raftArr[SYNC_MAX_BATCH_SIZE]; - for (int i = 0; i < arrSize; ++i) { - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "propose message, type:%s batch:%d", TMSG_INFO(pMsgPArr[i]->msgType), - arrSize); - syncNodeEventLog(pSyncNode, eventLog); - } while (0); - - SRespStub stub; - stub.createTime = taosGetTimestampMs(); - stub.rpcMsg = *(pMsgPArr[i]); - uint64_t seqNum = syncRespMgrAdd(pSyncNode->pSyncRespMgr, &stub); - - raftArr[i].isWeak = pIsWeakArr[i]; - raftArr[i].seqNum = seqNum; - } - - SyncClientRequestBatch* pSyncMsg = syncClientRequestBatchBuild(pMsgPArr, raftArr, arrSize, pSyncNode->vgId); - ASSERT(pSyncMsg != NULL); - - SRpcMsg rpcMsg; - syncClientRequestBatch2RpcMsg(pSyncMsg, &rpcMsg); - taosMemoryFree(pSyncMsg); // only free msg body, do not free rpc msg content - - if (pSyncNode->replicaNum == 1 && pSyncNode->vgId != 1) { - int32_t code = syncNodeOnClientRequestBatchCb(pSyncNode, pSyncMsg); - if (code == 0) { - // update rpc msg applyIndex - SRpcMsg* msgArr = syncClientRequestBatchRpcMsgArr(pSyncMsg); - ASSERT(arrSize == pSyncMsg->dataCount); - for (int i = 0; i < arrSize; ++i) { - pMsgPArr[i]->info.conn.applyIndex = msgArr[i].info.conn.applyIndex; - syncRespMgrDel(pSyncNode->pSyncRespMgr, raftArr[i].seqNum); - } - - rpcFreeCont(rpcMsg.pCont); - terrno = 0; - return 1; - - } else { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - - } else { - if (pSyncNode->FpEqMsg != NULL && (*pSyncNode->FpEqMsg)(pSyncNode->msgcb, &rpcMsg) == 0) { - // enqueue msg ok - return 0; - - } else { - sError("vgId:%d, enqueue msg error, FpEqMsg is NULL", pSyncNode->vgId); - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - } - - return 0; -} - int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { int32_t ret = 0; @@ -867,8 +995,8 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { if (!pSyncNode->restoreFinish && pSyncNode->vgId != 1) { ret = -1; terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY; - sError("vgId:%d, failed to sync propose since not ready, type:%s, last:%ld, cmt:%ld", pSyncNode->vgId, - TMSG_INFO(pMsg->msgType), syncNodeGetLastIndex(pSyncNode), pSyncNode->commitIndex); + sError("vgId:%d, failed to sync propose since not ready, type:%s, last:%" PRId64 ", cmt:%" PRId64, + pSyncNode->vgId, TMSG_INFO(pMsg->msgType), syncNodeGetLastIndex(pSyncNode), pSyncNode->commitIndex); goto _END; } @@ -884,7 +1012,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { // optimized one replica if (syncNodeIsOptimizedOneReplica(pSyncNode, pMsg)) { SyncIndex retIndex; - int32_t code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, &retIndex); + int32_t code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, &retIndex); if (code == 0) { pMsg->info.conn.applyIndex = retIndex; pMsg->info.conn.applyTerm = pSyncNode->pRaftStore->currentTerm; @@ -925,15 +1053,49 @@ _END: return ret; } -// open/close -------------- +int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId destId) { + pSyncTimer->pTimer = NULL; + pSyncTimer->counter = 0; + pSyncTimer->timerMS = pSyncNode->hbBaseLine; + pSyncTimer->timerCb = syncNodeEqPeerHeartbeatTimer; + pSyncTimer->destId = destId; + atomic_store_64(&pSyncTimer->logicClock, 0); + return 0; +} + +int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { + int32_t ret = 0; + if (syncEnvIsStart()) { + SSyncHbTimerData* pData = taosMemoryMalloc(sizeof(SSyncHbTimerData)); + pData->pSyncNode = pSyncNode; + pData->pTimer = pSyncTimer; + pData->destId = pSyncTimer->destId; + pData->logicClock = pSyncTimer->logicClock; + + pSyncTimer->pData = pData; + taosTmrReset(pSyncTimer->timerCb, pSyncTimer->timerMS, pData, gSyncEnv->pTimerManager, &pSyncTimer->pTimer); + } else { + sError("vgId:%d, start ctrl hb timer error, sync env is stop", pSyncNode->vgId); + } + return ret; +} + +int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { + int32_t ret = 0; + atomic_add_fetch_64(&pSyncTimer->logicClock, 1); + taosTmrStop(pSyncTimer->pTimer); + pSyncTimer->pTimer = NULL; + // taosMemoryFree(pSyncTimer->pData); + return ret; +} + SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { - SSyncNode* pSyncNode = (SSyncNode*)taosMemoryCalloc(1, sizeof(SSyncNode)); + SSyncNode* pSyncNode = taosMemoryCalloc(1, sizeof(SSyncNode)); if (pSyncNode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto _error; } - int32_t ret = 0; if (!taosDirExist((char*)(pSyncInfo->path))) { if (taosMkDir(pSyncInfo->path) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -945,24 +1107,35 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { snprintf(pSyncNode->configPath, sizeof(pSyncNode->configPath), "%s%sraft_config.json", pSyncInfo->path, TD_DIRSEP); if (!taosCheckExistFile(pSyncNode->configPath)) { // create a new raft config file - SRaftCfgMeta meta; + SRaftCfgMeta meta = {0}; meta.isStandBy = pSyncInfo->isStandBy; meta.snapshotStrategy = pSyncInfo->snapshotStrategy; meta.lastConfigIndex = SYNC_INDEX_INVALID; meta.batchSize = pSyncInfo->batchSize; - ret = raftCfgCreateFile((SSyncCfg*)&(pSyncInfo->syncCfg), meta, pSyncNode->configPath); - if (ret != 0) { - sError("failed to create raft cfg file. configPath: %s", pSyncNode->configPath); + if (raftCfgCreateFile(&pSyncInfo->syncCfg, meta, pSyncNode->configPath) != 0) { + sError("vgId:%d, failed to create raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath); goto _error; } + if (pSyncInfo->syncCfg.replicaNum == 0) { + sInfo("vgId:%d, sync config not input", pSyncNode->vgId); + pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg; + } } else { // update syncCfg by raft_config.json pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath); if (pSyncNode->pRaftCfg == NULL) { - sError("failed to open raft cfg file. path:%s", pSyncNode->configPath); + sError("vgId:%d, failed to open raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath); goto _error; } - if (pSyncInfo->syncCfg.replicaNum == 0) { + if (pSyncInfo->syncCfg.replicaNum > 0 && pSyncInfo->syncCfg.replicaNum != pSyncNode->pRaftCfg->cfg.replicaNum) { + sInfo("vgId:%d, use sync config from input options and write to cfg file", pSyncNode->vgId); + pSyncNode->pRaftCfg->cfg = pSyncInfo->syncCfg; + if (raftCfgPersist(pSyncNode->pRaftCfg) != 0) { + sError("vgId:%d, failed to persist raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath); + goto _error; + } + } else { + sInfo("vgId:%d, use sync config from raft cfg file", pSyncNode->vgId); pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg; } @@ -970,6 +1143,13 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { pSyncNode->pRaftCfg = NULL; } + SSyncCfg* pCfg = &pSyncInfo->syncCfg; + sDebug("vgId:%d, replica:%d selfIndex:%d", pSyncNode->vgId, pCfg->replicaNum, pCfg->myIndex); + for (int32_t i = 0; i < pCfg->replicaNum; ++i) { + SNodeInfo* pNode = &pCfg->nodeInfo[i]; + sDebug("vgId:%d, index:%d ep:%s:%u", pSyncNode->vgId, i, pNode->nodeFqdn, pNode->nodePort); + } + // init by SSyncInfo pSyncNode->vgId = pSyncInfo->vgId; memcpy(pSyncNode->path, pSyncInfo->path, sizeof(pSyncNode->path)); @@ -981,18 +1161,19 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { pSyncNode->msgcb = pSyncInfo->msgcb; pSyncNode->FpSendMsg = pSyncInfo->FpSendMsg; pSyncNode->FpEqMsg = pSyncInfo->FpEqMsg; + pSyncNode->FpEqCtrlMsg = pSyncInfo->FpEqCtrlMsg; // init raft config pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath); if (pSyncNode->pRaftCfg == NULL) { - sError("failed to open raft cfg file. path:%s", pSyncNode->configPath); + sError("vgId:%d, failed to open raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath); goto _error; } // init internal pSyncNode->myNodeInfo = pSyncNode->pRaftCfg->cfg.nodeInfo[pSyncNode->pRaftCfg->cfg.myIndex]; if (!syncUtilnodeInfo2raftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId)) { - sError("failed to determine my raft member id. vgId:%d", pSyncNode->vgId); + sError("vgId:%d, failed to determine my raft member id", pSyncNode->vgId); goto _error; } @@ -1007,7 +1188,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { } for (int i = 0; i < pSyncNode->peersNum; ++i) { if (!syncUtilnodeInfo2raftId(&pSyncNode->peersNodeInfo[i], pSyncNode->vgId, &pSyncNode->peersId[i])) { - sError("failed to determine raft member id. vgId:%d, peer:%d", pSyncNode->vgId, i); + sError("vgId:%d, failed to determine raft member id, peer:%d", pSyncNode->vgId, i); goto _error; } } @@ -1016,7 +1197,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { pSyncNode->replicaNum = pSyncNode->pRaftCfg->cfg.replicaNum; for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { if (!syncUtilnodeInfo2raftId(&pSyncNode->pRaftCfg->cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i])) { - sError("failed to determine raft member id. vgId:%d, replica:%d", pSyncNode->vgId, i); + sError("vgId:%d, failed to determine raft member id, replica:%d", pSyncNode->vgId, i); goto _error; } } @@ -1057,38 +1238,38 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER; pSyncNode->pRaftStore = raftStoreOpen(pSyncNode->raftStorePath); if (pSyncNode->pRaftStore == NULL) { - sError("failed to open raft store. path: %s", pSyncNode->raftStorePath); + sError("vgId:%d, failed to open raft store at path %s", pSyncNode->vgId, pSyncNode->raftStorePath); goto _error; } // init TLA+ candidate vars pSyncNode->pVotesGranted = voteGrantedCreate(pSyncNode); if (pSyncNode->pVotesGranted == NULL) { - sError("failed to create VotesGranted. vgId:%d", pSyncNode->vgId); + sError("vgId:%d, failed to create VotesGranted", pSyncNode->vgId); goto _error; } pSyncNode->pVotesRespond = votesRespondCreate(pSyncNode); if (pSyncNode->pVotesRespond == NULL) { - sError("failed to create VotesRespond. vgId:%d", pSyncNode->vgId); + sError("vgId:%d, failed to create VotesRespond", pSyncNode->vgId); goto _error; } // init TLA+ leader vars pSyncNode->pNextIndex = syncIndexMgrCreate(pSyncNode); if (pSyncNode->pNextIndex == NULL) { - sError("failed to create SyncIndexMgr. vgId:%d", pSyncNode->vgId); + sError("vgId:%d, failed to create SyncIndexMgr", pSyncNode->vgId); goto _error; } pSyncNode->pMatchIndex = syncIndexMgrCreate(pSyncNode); if (pSyncNode->pMatchIndex == NULL) { - sError("failed to create SyncIndexMgr. vgId:%d", pSyncNode->vgId); + sError("vgId:%d, failed to create SyncIndexMgr", pSyncNode->vgId); goto _error; } // init TLA+ log vars pSyncNode->pLogStore = logStoreCreate(pSyncNode); if (pSyncNode->pLogStore == NULL) { - sError("failed to create SyncLogStore. vgId:%d", pSyncNode->vgId); + sError("vgId:%d, failed to create SyncLogStore", pSyncNode->vgId); goto _error; } @@ -1097,7 +1278,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { SSnapshot snapshot = {0}; int32_t code = pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); if (code != 0) { - sError("failed to get snapshot info. vgId:%d, code:%d", pSyncNode->vgId, code); + sError("vgId:%d, failed to get snapshot info, code:%d", pSyncNode->vgId, code); goto _error; } if (snapshot.lastApplyIndex > commitIndex) { @@ -1136,34 +1317,27 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { pSyncNode->FpHeartbeatTimerCB = syncNodeEqHeartbeatTimer; pSyncNode->heartbeatTimerCounter = 0; + // init peer heartbeat timer + for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { + syncHbTimerInit(pSyncNode, &(pSyncNode->peerHeartbeatTimerArr[i]), (pSyncNode->replicasId)[i]); + } + // init callback pSyncNode->FpOnPing = syncNodeOnPingCb; pSyncNode->FpOnPingReply = syncNodeOnPingReplyCb; - pSyncNode->FpOnClientRequest = syncNodeOnClientRequestCb; - pSyncNode->FpOnTimeout = syncNodeOnTimeoutCb; - - pSyncNode->FpOnSnapshotSend = syncNodeOnSnapshotSendCb; - pSyncNode->FpOnSnapshotRsp = syncNodeOnSnapshotRspCb; - - if (pSyncNode->pRaftCfg->snapshotStrategy) { - sInfo("vgId:%d, sync node use snapshot", pSyncNode->vgId); - pSyncNode->FpOnRequestVote = syncNodeOnRequestVoteSnapshotCb; - pSyncNode->FpOnRequestVoteReply = syncNodeOnRequestVoteReplySnapshotCb; - pSyncNode->FpOnAppendEntries = syncNodeOnAppendEntriesSnapshotCb; - pSyncNode->FpOnAppendEntriesReply = syncNodeOnAppendEntriesReplySnapshotCb; - - } else { - sInfo("vgId:%d, sync node do not use snapshot", pSyncNode->vgId); - pSyncNode->FpOnRequestVote = syncNodeOnRequestVoteCb; - pSyncNode->FpOnRequestVoteReply = syncNodeOnRequestVoteReplyCb; - pSyncNode->FpOnAppendEntries = syncNodeOnAppendEntriesCb; - pSyncNode->FpOnAppendEntriesReply = syncNodeOnAppendEntriesReplyCb; - } + pSyncNode->FpOnClientRequest = syncNodeOnClientRequest; + pSyncNode->FpOnTimeout = syncNodeOnTimer; + pSyncNode->FpOnSnapshot = syncNodeOnSnapshot; + pSyncNode->FpOnSnapshotReply = syncNodeOnSnapshotReply; + pSyncNode->FpOnRequestVote = syncNodeOnRequestVote; + pSyncNode->FpOnRequestVoteReply = syncNodeOnRequestVoteReply; + pSyncNode->FpOnAppendEntries = syncNodeOnAppendEntries; + pSyncNode->FpOnAppendEntriesReply = syncNodeOnAppendEntriesReply; // tools pSyncNode->pSyncRespMgr = syncRespMgrCreate(pSyncNode, SYNC_RESP_TTL_MS); if (pSyncNode->pSyncRespMgr == NULL) { - sError("failed to create SyncRespMgr. vgId:%d", pSyncNode->vgId); + sError("vgId:%d, failed to create SyncRespMgr", pSyncNode->vgId); goto _error; } @@ -1183,6 +1357,12 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { // is config changing pSyncNode->changing = false; + // peer state + syncNodePeerStateInit(pSyncNode); + + // min match index + pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; + // start in syncNodeStart // start raft // syncNodeBecomeFollower(pSyncNode); @@ -1192,6 +1372,9 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { pSyncNode->leaderTime = timeNow; pSyncNode->lastReplicateTime = timeNow; + // snapshotting + atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID); + syncNodeEventLog(pSyncNode, "sync open"); return pSyncNode; @@ -1226,15 +1409,14 @@ void syncNodeStart(SSyncNode* pSyncNode) { // Raft 3.6.2 Committing entries from previous terms syncNodeAppendNoop(pSyncNode); syncMaybeAdvanceCommitIndex(pSyncNode); + } else { syncNodeBecomeFollower(pSyncNode, "first start"); } - if (pSyncNode->vgId == 1) { - int32_t ret = 0; - ret = syncNodeStartPingTimer(pSyncNode); - ASSERT(ret == 0); - } + int32_t ret = 0; + ret = syncNodeStartPingTimer(pSyncNode); + ASSERT(ret == 0); } void syncNodeStartStandBy(SSyncNode* pSyncNode) { @@ -1247,11 +1429,9 @@ void syncNodeStartStandBy(SSyncNode* pSyncNode) { int32_t ret = syncNodeRestartElectTimer(pSyncNode, electMS); ASSERT(ret == 0); - if (pSyncNode->vgId == 1) { - int32_t ret = 0; - ret = syncNodeStartPingTimer(pSyncNode); - ASSERT(ret == 0); - } + ret = 0; + ret = syncNodeStartPingTimer(pSyncNode); + ASSERT(ret == 0); } void syncNodeClose(SSyncNode* pSyncNode) { @@ -1383,11 +1563,13 @@ int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms) { &pSyncNode->pElectTimer); atomic_store_64(&pSyncNode->electTimerLogicClock, pSyncNode->electTimerLogicClockUser); - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "elect timer reset, ms:%d", ms); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); + /* + do { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "elect timer reset, ms:%d", ms); + syncNodeEventLog(pSyncNode, logBuf); + } while (0); + */ } else { sError("vgId:%d, start elect timer error, sync env is stop", pSyncNode->vgId); @@ -1401,7 +1583,7 @@ int32_t syncNodeStopElectTimer(SSyncNode* pSyncNode) { taosTmrStop(pSyncNode->pElectTimer); pSyncNode->pElectTimer = NULL; - sTrace("vgId:%d, sync %s stop elect timer", pSyncNode->vgId, syncUtilState2String(pSyncNode->state)); + // sTrace("vgId:%d, sync %s stop elect timer", pSyncNode->vgId, syncUtilState2String(pSyncNode->state)); return ret; } @@ -1453,30 +1635,34 @@ static int32_t syncNodeDoStartHeartbeatTimer(SSyncNode* pSyncNode) { } int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode) { + int32_t ret = 0; + +#if 0 pSyncNode->heartbeatTimerMS = pSyncNode->hbBaseLine; - int32_t ret = syncNodeDoStartHeartbeatTimer(pSyncNode); - return ret; -} + ret = syncNodeDoStartHeartbeatTimer(pSyncNode); +#endif -int32_t syncNodeStartHeartbeatTimerMS(SSyncNode* pSyncNode, int32_t ms) { - pSyncNode->heartbeatTimerMS = ms; - int32_t ret = syncNodeDoStartHeartbeatTimer(pSyncNode); - return ret; -} + for (int i = 0; i < pSyncNode->peersNum; ++i) { + SSyncTimer* pSyncTimer = syncNodeGetHbTimer(pSyncNode, &(pSyncNode->peersId[i])); + syncHbTimerStart(pSyncNode, pSyncTimer); + } -int32_t syncNodeStartHeartbeatTimerNow(SSyncNode* pSyncNode) { - pSyncNode->heartbeatTimerMS = 1; - int32_t ret = syncNodeDoStartHeartbeatTimer(pSyncNode); return ret; } int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode) { int32_t ret = 0; + +#if 0 atomic_add_fetch_64(&pSyncNode->heartbeatTimerLogicClockUser, 1); taosTmrStop(pSyncNode->pHeartbeatTimer); pSyncNode->pHeartbeatTimer = NULL; +#endif - sTrace("vgId:%d, sync %s stop heartbeat timer", pSyncNode->vgId, syncUtilState2String(pSyncNode->state)); + for (int i = 0; i < pSyncNode->peersNum; ++i) { + SSyncTimer* pSyncTimer = syncNodeGetHbTimer(pSyncNode, &(pSyncNode->peersId[i])); + syncHbTimerStop(pSyncNode, pSyncTimer); + } return ret; } @@ -1487,18 +1673,6 @@ int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode) { return 0; } -int32_t syncNodeRestartHeartbeatTimerNow(SSyncNode* pSyncNode) { - syncNodeStopHeartbeatTimer(pSyncNode); - syncNodeStartHeartbeatTimerNow(pSyncNode); - return 0; -} - -int32_t syncNodeRestartNowHeartbeatTimerMS(SSyncNode* pSyncNode, int32_t ms) { - syncNodeStopHeartbeatTimer(pSyncNode); - syncNodeStartHeartbeatTimerMS(pSyncNode, ms); - return 0; -} - // utils -------------- int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg) { SEpSet epSet; @@ -1702,8 +1876,6 @@ char* syncNode2Str(const SSyncNode* pSyncNode) { } inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { - int32_t userStrLen = strlen(str); - SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); @@ -1722,22 +1894,25 @@ inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { printStr = pCfgStr; } + char* peerStateStr = syncNodePeerState2Str(pSyncNode); + int32_t userStrLen = strlen(str) + strlen(peerStateStr); + if (userStrLen < 256) { char logBuf[256 + 256]; if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(logBuf, sizeof(logBuf), - "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64 - ", snap-tm:%" PRIu64 + "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 + ", snap:%" PRId64 ", snap-tm:%" PRIu64 ", sby:%d, " "stgy:%d, bch:%d, " "r-num:%d, " - "lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s", + "lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, - pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, - pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, pSyncNode->pRaftCfg->batchSize, - pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, - pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode), pSyncNode->electTimerLogicClockUser, - pSyncNode->heartbeatTimerLogicClockUser, printStr); + pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex, + snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, + pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, + pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode), + pSyncNode->electTimerLogicClockUser, pSyncNode->heartbeatTimerLogicClockUser, peerStateStr, printStr); } else { snprintf(logBuf, sizeof(logBuf), "%s", str); } @@ -1750,18 +1925,18 @@ inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { char* s = (char*)taosMemoryMalloc(len); if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(s, len, - "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64 - ", snap-tm:%" PRIu64 + "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 + ", snap:%" PRId64 ", snap-tm:%" PRIu64 ", sby:%d, " "stgy:%d, bch:%d, " "r-num:%d, " - "lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s", + "lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, - pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, - pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, pSyncNode->pRaftCfg->batchSize, - pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, - pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode), pSyncNode->electTimerLogicClockUser, - pSyncNode->heartbeatTimerLogicClockUser, printStr); + pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex, + snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, + pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, + pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode), + pSyncNode->electTimerLogicClockUser, pSyncNode->heartbeatTimerLogicClockUser, peerStateStr, printStr); } else { snprintf(s, len, "%s", str); } @@ -1771,6 +1946,7 @@ inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { taosMemoryFree(s); } + taosMemoryFree(peerStateStr); taosMemoryFree(pCfgStr); } @@ -1799,17 +1975,18 @@ inline void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) { char logBuf[256 + 256]; if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(logBuf, sizeof(logBuf), - "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64 - ", snap-tm:%" PRIu64 + "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 + ", snap:%" PRId64 ", snap-tm:%" PRIu64 ", sby:%d, " "stgy:%d, bch:%d, " "r-num:%d, " - "lcfg:%" PRId64 ", chging:%d, rsto:%d, %s", + "lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, - pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, - pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, pSyncNode->pRaftCfg->batchSize, - pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, - pSyncNode->restoreFinish, printStr); + pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex, + snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, + pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, + pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode), + pSyncNode->electTimerLogicClockUser, pSyncNode->heartbeatTimerLogicClockUser, printStr); } else { snprintf(logBuf, sizeof(logBuf), "%s", str); } @@ -1820,17 +1997,18 @@ inline void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) { char* s = (char*)taosMemoryMalloc(len); if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(s, len, - "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64 - ", snap-tm:%" PRIu64 + "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 + ", snap:%" PRId64 ", snap-tm:%" PRIu64 ", sby:%d, " "stgy:%d, bch:%d, " "r-num:%d, " - "lcfg:%" PRId64 ", chging:%d, rsto:%d, %s", + "lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, - pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, - pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, pSyncNode->pRaftCfg->batchSize, - pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, - pSyncNode->restoreFinish, printStr); + pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex, + snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, + pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, + pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode), + pSyncNode->electTimerLogicClockUser, pSyncNode->heartbeatTimerLogicClockUser, printStr); } else { snprintf(s, len, "%s", str); } @@ -1906,11 +2084,12 @@ static bool syncIsConfigChanged(const SSyncCfg* pOldCfg, const SSyncCfg* pNewCfg void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncIndex lastConfigChangeIndex) { SSyncCfg oldConfig = pSyncNode->pRaftCfg->cfg; +#if 1 if (!syncIsConfigChanged(&oldConfig, pNewConfig)) { sInfo("vgId:1, sync not reconfig since not changed"); return; } - +#endif pSyncNode->pRaftCfg->cfg = *pNewConfig; pSyncNode->pRaftCfg->lastConfigIndex = lastConfigChangeIndex; @@ -1993,13 +2172,14 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde syncUtilnodeInfo2raftId(&pSyncNode->pRaftCfg->cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i]); } + // update quorum first + pSyncNode->quorum = syncUtilQuorum(pSyncNode->pRaftCfg->cfg.replicaNum); + syncIndexMgrUpdate(pSyncNode->pNextIndex, pSyncNode); syncIndexMgrUpdate(pSyncNode->pMatchIndex, pSyncNode); voteGrantedUpdate(pSyncNode->pVotesGranted, pSyncNode); votesRespondUpdate(pSyncNode->pVotesRespond, pSyncNode); - pSyncNode->quorum = syncUtilQuorum(pSyncNode->pRaftCfg->cfg.replicaNum); - // reset snapshot senders // clear new @@ -2148,6 +2328,30 @@ void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term) { } } +void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) { + ASSERT(pSyncNode->pRaftStore->currentTerm <= newTerm); + + do { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "step down, new-term:%" PRIu64 ", current-term:%" PRIu64, newTerm, + pSyncNode->pRaftStore->currentTerm); + syncNodeEventLog(pSyncNode, logBuf); + } while (0); + + if (pSyncNode->pRaftStore->currentTerm < newTerm) { + raftStoreSetTerm(pSyncNode->pRaftStore, newTerm); + char tmpBuf[64]; + snprintf(tmpBuf, sizeof(tmpBuf), "step down, update term to %" PRIu64, newTerm); + syncNodeBecomeFollower(pSyncNode, tmpBuf); + raftStoreClearVote(pSyncNode->pRaftStore); + + } else { + if (pSyncNode->state != TAOS_SYNC_STATE_FOLLOWER) { + syncNodeBecomeFollower(pSyncNode, "step down"); + } + } +} + void syncNodeLeaderChangeRsp(SSyncNode* pSyncNode) { syncRespCleanRsp(pSyncNode->pSyncRespMgr); } void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) { @@ -2171,6 +2375,9 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) { pSyncNode->pFsm->FpBecomeFollowerCb(pSyncNode->pFsm); } + // min match index + pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; + // trace log do { int32_t debugStrLen = strlen(debugStr); @@ -2237,6 +2444,9 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { pSyncNode->pMatchIndex->index[i] = SYNC_INDEX_INVALID; } + // init peer mgr + syncNodePeerStateInit(pSyncNode); + // update sender private term SSyncSnapshotSender* pMySender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->myRaftId)); if (pMySender != NULL) { @@ -2259,11 +2469,17 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { // start heartbeat timer syncNodeStartHeartbeatTimer(pSyncNode); + // send heartbeat right now + syncNodeHeartbeatPeers(pSyncNode); + // call back if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpBecomeLeaderCb != NULL) { pSyncNode->pFsm->FpBecomeLeaderCb(pSyncNode->pFsm); } + // min match index + pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; + // trace log do { int32_t debugStrLen = strlen(debugStr); @@ -2282,7 +2498,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { void syncNodeCandidate2Leader(SSyncNode* pSyncNode) { ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE); - //ASSERT(voteGrantedMajority(pSyncNode->pVotesGranted)); + ASSERT(voteGrantedMajority(pSyncNode->pVotesGranted)); syncNodeBecomeLeader(pSyncNode, "candidate to leader"); syncNodeLog2("==state change syncNodeCandidate2Leader==", pSyncNode); @@ -2290,6 +2506,21 @@ void syncNodeCandidate2Leader(SSyncNode* pSyncNode) { // Raft 3.6.2 Committing entries from previous terms syncNodeAppendNoop(pSyncNode); syncMaybeAdvanceCommitIndex(pSyncNode); + + if (pSyncNode->replicaNum > 1) { + syncNodeReplicate(pSyncNode); + } +} + +bool syncNodeIsMnode(SSyncNode* pSyncNode) { return (pSyncNode->vgId == 1); } + +int32_t syncNodePeerStateInit(SSyncNode* pSyncNode) { + for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + pSyncNode->peerStates[i].lastSendIndex = SYNC_INDEX_INVALID; + pSyncNode->peerStates[i].lastSendTime = 0; + } + + return 0; } void syncNodeFollower2Candidate(SSyncNode* pSyncNode) { @@ -2475,35 +2706,35 @@ int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex // for debug -------------- void syncNodePrint(SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); - printf("syncNodePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncNodePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncNodePrint2(char* s, SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); - printf("syncNodePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncNodePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncNodeLog(SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); - sTraceLong("syncNodeLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTraceLong("syncNodeLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncNodeLog2(char* s, SSyncNode* pObj) { if (gRaftDetailLog) { char* serialized = syncNode2Str(pObj); - sTraceLong("syncNodeLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTraceLong("syncNodeLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } void syncNodeLog3(char* s, SSyncNode* pObj) { char* serialized = syncNode2Str(pObj); - sTraceLong("syncNodeLog3 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTraceLong("syncNodeLog3 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } @@ -2565,7 +2796,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) { syncTimeoutDestroy(pSyncMsg); // reset timer ms - if (syncEnvIsStart()) { + if (syncEnvIsStart() && pSyncNode->electBaseLine > 0) { pSyncNode->electTimerMS = syncUtilElectRandomMS(pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine); taosTmrReset(syncNodeEqElectTimer, pSyncNode->electTimerMS, pSyncNode, gSyncEnv->pTimerManager, &pSyncNode->pElectTimer); @@ -2619,6 +2850,67 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) { } } +static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) { + SSyncHbTimerData* pData = (SSyncHbTimerData*)param; + SSyncNode* pSyncNode = pData->pSyncNode; + SSyncTimer* pSyncTimer = pData->pTimer; + + if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { + return; + } + + // syncNodeEventLog(pSyncNode, "eq peer hb timer"); + + int64_t timerLogicClock = atomic_load_64(&pSyncTimer->logicClock); + int64_t msgLogicClock = atomic_load_64(&pData->logicClock); + + if (pSyncNode->replicaNum > 1) { + if (timerLogicClock == msgLogicClock) { + SyncHeartbeat* pSyncMsg = syncHeartbeatBuild(pSyncNode->vgId); + pSyncMsg->srcId = pSyncNode->myRaftId; + pSyncMsg->destId = pData->destId; + pSyncMsg->term = pSyncNode->pRaftStore->currentTerm; + pSyncMsg->commitIndex = pSyncNode->commitIndex; + pSyncMsg->minMatchIndex = syncMinMatchIndex(pSyncNode); + pSyncMsg->privateTerm = 0; + + SRpcMsg rpcMsg; + syncHeartbeat2RpcMsg(pSyncMsg, &rpcMsg); + +// eq msg +#if 0 + if (pSyncNode->FpEqCtrlMsg != NULL) { + int32_t code = pSyncNode->FpEqCtrlMsg(pSyncNode->msgcb, &rpcMsg); + if (code != 0) { + sError("vgId:%d, sync ctrl enqueue timer msg error, code:%d", pSyncNode->vgId, code); + rpcFreeCont(rpcMsg.pCont); + syncHeartbeatDestroy(pSyncMsg); + return; + } + } else { + sError("vgId:%d, enqueue ctrl msg cb ptr (i.e. FpEqMsg) not set.", pSyncNode->vgId); + } +#endif + + // send msg + syncNodeSendHeartbeat(pSyncNode, &(pSyncMsg->destId), pSyncMsg); + + syncHeartbeatDestroy(pSyncMsg); + + if (syncEnvIsStart()) { + taosTmrReset(syncNodeEqPeerHeartbeatTimer, pSyncTimer->timerMS, pData, gSyncEnv->pTimerManager, + &pSyncTimer->pTimer); + } else { + sError("sync env is stop, syncNodeEqHeartbeatTimer"); + } + + } else { + sTrace("==syncNodeEqPeerHeartbeatTimer== timerLogicClock:%" PRIu64 ", msgLogicClock:%" PRIu64 "", timerLogicClock, + msgLogicClock); + } + } +} + static int32_t syncNodeEqNoop(SSyncNode* ths) { int32_t ret = 0; ASSERT(ths->state == TAOS_SYNC_STATE_LEADER); @@ -2676,10 +2968,9 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) { if (ths->state == TAOS_SYNC_STATE_LEADER) { int32_t code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry); if (code != 0) { - sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); + syncNodeErrorLog(ths, "append noop error"); return -1; } - syncNodeReplicate(ths, false); } if (h) { @@ -2726,6 +3017,57 @@ int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) { return ret; } +int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) { + syncLogRecvHeartbeat(ths, pMsg, ""); + + SyncHeartbeatReply* pMsgReply = syncHeartbeatReplyBuild(ths->vgId); + pMsgReply->destId = pMsg->srcId; + pMsgReply->srcId = ths->myRaftId; + pMsgReply->term = ths->pRaftStore->currentTerm; + pMsgReply->privateTerm = 8864; // magic number + + SRpcMsg rpcMsg; + syncHeartbeatReply2RpcMsg(pMsgReply, &rpcMsg); + +#if 1 + if (pMsg->term >= ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_FOLLOWER) { + syncNodeStepDown(ths, pMsg->term); + } +#endif + + if (pMsg->term == ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_LEADER) { + syncNodeResetElectTimer(ths); + ths->minMatchIndex = pMsg->minMatchIndex; + +#if 0 + if (ths->state == TAOS_SYNC_STATE_FOLLOWER) { + syncNodeFollowerCommit(ths, pMsg->commitIndex); + } +#endif + } + + /* + // htonl + SMsgHead* pHead = rpcMsg.pCont; + pHead->contLen = htonl(pHead->contLen); + pHead->vgId = htonl(pHead->vgId); + */ + + // reply + syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg); + + return 0; +} + +int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg) { + syncLogRecvHeartbeatReply(ths, pMsg, ""); + + // update last reply time, make decision whether the other node is alive or not + syncIndexMgrSetRecvTime(ths->pMatchIndex, &(pMsg->destId), pMsg->startTime); + + return 0; +} + // TLA+ Spec // ClientRequest(i, v) == // /\ state[i] = Leader @@ -2736,10 +3078,12 @@ int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) { // /\ UNCHANGED <> // -int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex) { + +int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex) { + syncNodeEventLog(ths, "on client request"); + int32_t ret = 0; int32_t code = 0; - syncClientRequestLog2("==syncNodeOnClientRequestCb==", pMsg); SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore); SyncTerm term = ths->pRaftStore->currentTerm; @@ -2754,16 +3098,13 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry); if (code != 0) { // del resp mgr, call FpCommitCb - sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); + ASSERT(0); return -1; } // if mulit replica, start replicate right now if (ths->replicaNum > 1) { - syncNodeReplicate(ths, false); - - // pre commit - syncNodePreCommit(ths, pEntry, 0); + syncNodeReplicate(ths); } // if only myself, maybe commit right now @@ -2789,61 +3130,6 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI return ret; } -int32_t syncNodeOnClientRequestBatchCb(SSyncNode* ths, SyncClientRequestBatch* pMsg) { - int32_t code = 0; - - if (ths->state != TAOS_SYNC_STATE_LEADER) { - // call FpCommitCb, delete resp mgr - return -1; - } - - SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore); - SyncTerm term = ths->pRaftStore->currentTerm; - - int32_t raftMetaArrayLen = sizeof(SRaftMeta) * pMsg->dataCount; - int32_t rpcArrayLen = sizeof(SRpcMsg) * pMsg->dataCount; - SRaftMeta* raftMetaArr = (SRaftMeta*)(pMsg->data); - SRpcMsg* msgArr = (SRpcMsg*)((char*)(pMsg->data) + raftMetaArrayLen); - for (int32_t i = 0; i < pMsg->dataCount; ++i) { - SSyncRaftEntry* pEntry = syncEntryBuild(msgArr[i].contLen); - ASSERT(pEntry != NULL); - - pEntry->originalRpcType = msgArr[i].msgType; - pEntry->seqNum = raftMetaArr[i].seqNum; - pEntry->isWeak = raftMetaArr[i].isWeak; - pEntry->term = term; - pEntry->index = index; - memcpy(pEntry->data, msgArr[i].pCont, msgArr[i].contLen); - ASSERT(msgArr[i].contLen == pEntry->dataLen); - - code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry); - if (code != 0) { - sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); - // del resp mgr, call FpCommitCb - return -1; - } - - // update rpc msg conn apply.index - msgArr[i].info.conn.applyIndex = pEntry->index; - } - - // fsync once - SSyncLogStoreData* pData = ths->pLogStore->data; - SWal* pWal = pData->pWal; - walFsync(pWal, false); - - if (ths->replicaNum > 1) { - // if multi replica, start replicate right now - syncNodeReplicate(ths, false); - - } else if (ths->replicaNum == 1) { - // one replica - syncMaybeAdvanceCommitIndex(ths); - } - - return 0; -} - const char* syncStr(ESyncState state) { switch (state) { case TAOS_SYNC_STATE_FOLLOWER: @@ -2870,14 +3156,14 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p if (pEntry->term < ths->pRaftStore->currentTerm) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "little term:%lu, can not do leader transfer", pEntry->term); + snprintf(logBuf, sizeof(logBuf), "little term:%" PRIu64 ", can not do leader transfer", pEntry->term); syncNodeEventLog(ths, logBuf); return 0; } if (pEntry->index < syncNodeGetLastIndex(ths)) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "little index:%ld, can not do leader transfer", pEntry->index); + snprintf(logBuf, sizeof(logBuf), "little index:%" PRId64 ", can not do leader transfer", pEntry->index); syncNodeEventLog(ths, logBuf); return 0; } @@ -2893,7 +3179,7 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "do leader transfer, index:%ld", pEntry->index); + snprintf(logBuf, sizeof(logBuf), "do leader transfer, index:%" PRId64, pEntry->index); syncNodeEventLog(ths, logBuf); } while (0); @@ -3032,11 +3318,10 @@ static int32_t syncNodeProposeConfigChangeFinish(SSyncNode* ths, SyncReconfigFin } bool syncNodeIsOptimizedOneReplica(SSyncNode* ths, SRpcMsg* pMsg) { - return (ths->replicaNum == 1 && syncUtilUserCommit(pMsg->msgType)); - // return (ths->replicaNum == 1 && syncUtilUserCommit(pMsg->msgType) && ths->vgId != 1); + return (ths->replicaNum == 1 && syncUtilUserCommit(pMsg->msgType) && ths->vgId != 1); } -int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, uint64_t flag) { +int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, uint64_t flag) { if (beginIndex > endIndex) { return 0; } @@ -3072,10 +3357,7 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, pEntry = (SSyncRaftEntry*)taosLRUCacheValue(pCache, h); } else { code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, i, &pEntry); - if (code != 0) { - sError("vgId:%d, failed to get log entry since %s. index:%lld", ths->vgId, tstrerror(terrno), i); - return -1; - } + ASSERT(code == 0); ASSERT(pEntry != NULL); } @@ -3085,8 +3367,7 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, // user commit if ((ths->pFsm->FpCommitCb != NULL) && syncUtilUserCommit(pEntry->originalRpcType)) { bool internalExecute = true; - if ((ths->replicaNum == 1) && ths->restoreFinish) { - // if ((ths->replicaNum == 1) && ths->restoreFinish && ths->vgId != 1) { + if ((ths->replicaNum == 1) && ths->restoreFinish && ths->vgId != 1) { internalExecute = false; } @@ -3154,8 +3435,8 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, int64_t restoreDelay = taosGetTimestampMs() - ths->leaderTime; char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "restore finish, index:%ld, elapsed:%ld ms, ", pEntry->index, - restoreDelay); + snprintf(eventLog, sizeof(eventLog), "restore finish, index:%" PRId64 ", elapsed:%" PRId64 " ms, ", + pEntry->index, restoreDelay); syncNodeEventLog(ths, eventLog); } } @@ -3191,6 +3472,42 @@ SSyncSnapshotSender* syncNodeGetSnapshotSender(SSyncNode* ths, SRaftId* pDestId) return pSender; } +SSyncTimer* syncNodeGetHbTimer(SSyncNode* ths, SRaftId* pDestId) { + SSyncTimer* pTimer = NULL; + for (int i = 0; i < ths->replicaNum; ++i) { + if (syncUtilSameId(pDestId, &((ths->replicasId)[i]))) { + pTimer = &((ths->peerHeartbeatTimerArr)[i]); + } + } + return pTimer; +} + +SPeerState* syncNodeGetPeerState(SSyncNode* ths, const SRaftId* pDestId) { + SPeerState* pState = NULL; + for (int i = 0; i < ths->replicaNum; ++i) { + if (syncUtilSameId(pDestId, &((ths->replicasId)[i]))) { + pState = &((ths->peerStates)[i]); + } + } + return pState; +} + +bool syncNodeNeedSendAppendEntries(SSyncNode* ths, const SRaftId* pDestId, const SyncAppendEntries* pMsg) { + SPeerState* pState = syncNodeGetPeerState(ths, pDestId); + if (pState == NULL) { + return false; + } + + SyncIndex sendIndex = pMsg->prevLogIndex + 1; + int64_t tsNow = taosGetTimestampMs(); + + if (pState->lastSendIndex == sendIndex && tsNow - pState->lastSendTime < SYNC_APPEND_ENTRIES_TIMEOUT_MS) { + return false; + } + + return true; +} + bool syncNodeCanChange(SSyncNode* pSyncNode) { if (pSyncNode->changing) { sError("sync cannot change"); @@ -3216,6 +3533,25 @@ bool syncNodeCanChange(SSyncNode* pSyncNode) { return true; } +const char* syncTimerTypeStr(enum ESyncTimeoutType timerType) { + if (timerType == SYNC_TIMEOUT_PING) { + return "ping"; + } else if (timerType == SYNC_TIMEOUT_ELECTION) { + return "elect"; + } else if (timerType == SYNC_TIMEOUT_HEARTBEAT) { + return "heartbeat"; + } else { + return "unknown"; + } +} + +void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s) { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "recv sync-timer {type:%s, lc:%" PRIu64 ", ms:%d, data:%p}, %s", + syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->data, s); + syncNodeEventLog(pSyncNode, logBuf); +} + void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) { char host[64]; uint16_t port; @@ -3337,3 +3673,47 @@ void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntries host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s); syncNodeEventLog(pSyncNode, logBuf); } + +void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-heartbeat to %s:%d {term:%" PRIu64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRIu64 + "}, %s", + host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s); + syncNodeEventLog(pSyncNode, logBuf); +} + +void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-heartbeat from %s:%d {term:%" PRIu64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRIu64 + "}, %s", + host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s); + syncNodeEventLog(pSyncNode, logBuf); +} + +void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "send sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s", + host, port, pMsg->term, pMsg->privateTerm, s); + syncNodeEventLog(pSyncNode, logBuf); +} + +void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "recv sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s", + host, port, pMsg->term, pMsg->privateTerm, s); + syncNodeEventLog(pSyncNode, logBuf); +} \ No newline at end of file diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index faebe5bbecb16012831ed103de520c14accc81d5..9de3fde3894f069afbe8152b646643a2b2a1fd25 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -133,28 +133,28 @@ char* syncRpcMsg2Str(SRpcMsg* pRpcMsg) { // for debug ---------------------- void syncRpcMsgPrint(SRpcMsg* pMsg) { char* serialized = syncRpcMsg2Str(pMsg); - printf("syncRpcMsgPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncRpcMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg) { char* serialized = syncRpcMsg2Str(pMsg); - printf("syncRpcMsgPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncRpcMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRpcMsgLog(SRpcMsg* pMsg) { char* serialized = syncRpcMsg2Str(pMsg); - sTrace("syncRpcMsgLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncRpcMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) { if (gRaftDetailLog) { char* serialized = syncRpcMsg2Str(pMsg); - sTrace("syncRpcMsgLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncRpcMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -271,21 +271,21 @@ void syncTimeoutPrint(const SyncTimeout* pMsg) { void syncTimeoutPrint2(char* s, const SyncTimeout* pMsg) { char* serialized = syncTimeout2Str(pMsg); - printf("syncTimeoutPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncTimeoutPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncTimeoutLog(const SyncTimeout* pMsg) { char* serialized = syncTimeout2Str(pMsg); - sTrace("syncTimeoutLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncTimeoutLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncTimeoutLog2(char* s, const SyncTimeout* pMsg) { if (gRaftDetailLog) { char* serialized = syncTimeout2Str(pMsg); - sTrace("syncTimeoutLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncTimeoutLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -526,28 +526,28 @@ char* syncPing2Str(const SyncPing* pMsg) { // for debug ---------------------- void syncPingPrint(const SyncPing* pMsg) { char* serialized = syncPing2Str(pMsg); - printf("syncPingPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncPingPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncPingPrint2(char* s, const SyncPing* pMsg) { char* serialized = syncPing2Str(pMsg); - printf("syncPingPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncPingPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncPingLog(const SyncPing* pMsg) { char* serialized = syncPing2Str(pMsg); - sTrace("syncPingLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncPingLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncPingLog2(char* s, const SyncPing* pMsg) { if (gRaftDetailLog) { char* serialized = syncPing2Str(pMsg); - sTrace("syncPingLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncPingLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -931,28 +931,28 @@ char* syncClientRequest2Str(const SyncClientRequest* pMsg) { // for debug ---------------------- void syncClientRequestPrint(const SyncClientRequest* pMsg) { char* serialized = syncClientRequest2Str(pMsg); - printf("syncClientRequestPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncClientRequestPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg) { char* serialized = syncClientRequest2Str(pMsg); - printf("syncClientRequestPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncClientRequestPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncClientRequestLog(const SyncClientRequest* pMsg) { char* serialized = syncClientRequest2Str(pMsg); - sTrace("syncClientRequestLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncClientRequestLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) { if (gRaftDetailLog) { char* serialized = syncClientRequest2Str(pMsg); - sTrace("syncClientRequestLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncClientRequestLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1101,28 +1101,28 @@ char* syncClientRequestBatch2Str(const SyncClientRequestBatch* pMsg) { // for debug ---------------------- void syncClientRequestBatchPrint(const SyncClientRequestBatch* pMsg) { char* serialized = syncClientRequestBatch2Str(pMsg); - printf("syncClientRequestBatchPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncClientRequestBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncClientRequestBatchPrint2(char* s, const SyncClientRequestBatch* pMsg) { char* serialized = syncClientRequestBatch2Str(pMsg); - printf("syncClientRequestBatchPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncClientRequestBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncClientRequestBatchLog(const SyncClientRequestBatch* pMsg) { char* serialized = syncClientRequestBatch2Str(pMsg); - sTrace("syncClientRequestBatchLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncClientRequestBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncClientRequestBatchLog2(char* s, const SyncClientRequestBatch* pMsg) { if (gRaftDetailLog) { char* serialized = syncClientRequestBatch2Str(pMsg); - sTraceLong("syncClientRequestBatchLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTraceLong("syncClientRequestBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1252,28 +1252,28 @@ char* syncRequestVote2Str(const SyncRequestVote* pMsg) { // for debug ---------------------- void syncRequestVotePrint(const SyncRequestVote* pMsg) { char* serialized = syncRequestVote2Str(pMsg); - printf("syncRequestVotePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncRequestVotePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRequestVotePrint2(char* s, const SyncRequestVote* pMsg) { char* serialized = syncRequestVote2Str(pMsg); - printf("syncRequestVotePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncRequestVotePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRequestVoteLog(const SyncRequestVote* pMsg) { char* serialized = syncRequestVote2Str(pMsg); - sTrace("syncRequestVoteLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncRequestVoteLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncRequestVoteLog2(char* s, const SyncRequestVote* pMsg) { if (gRaftDetailLog) { char* serialized = syncRequestVote2Str(pMsg); - sTrace("syncRequestVoteLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncRequestVoteLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1400,28 +1400,28 @@ char* syncRequestVoteReply2Str(const SyncRequestVoteReply* pMsg) { // for debug ---------------------- void syncRequestVoteReplyPrint(const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); - printf("syncRequestVoteReplyPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncRequestVoteReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRequestVoteReplyPrint2(char* s, const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); - printf("syncRequestVoteReplyPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncRequestVoteReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg) { char* serialized = syncRequestVoteReply2Str(pMsg); - sTrace("syncRequestVoteReplyLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncRequestVoteReplyLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg) { if (gRaftDetailLog) { char* serialized = syncRequestVoteReply2Str(pMsg); - sTrace("syncRequestVoteReplyLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncRequestVoteReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1571,28 +1571,28 @@ char* syncAppendEntries2Str(const SyncAppendEntries* pMsg) { // for debug ---------------------- void syncAppendEntriesPrint(const SyncAppendEntries* pMsg) { char* serialized = syncAppendEntries2Str(pMsg); - printf("syncAppendEntriesPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncAppendEntriesPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg) { char* serialized = syncAppendEntries2Str(pMsg); - printf("syncAppendEntriesPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncAppendEntriesPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesLog(const SyncAppendEntries* pMsg) { char* serialized = syncAppendEntries2Str(pMsg); - sTrace("syncAppendEntriesLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncAppendEntriesLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) { if (gRaftDetailLog) { char* serialized = syncAppendEntries2Str(pMsg); - sTrace("syncAppendEntriesLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncAppendEntriesLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1810,28 +1810,28 @@ char* syncAppendEntriesBatch2Str(const SyncAppendEntriesBatch* pMsg) { // for debug ---------------------- void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg) { char* serialized = syncAppendEntriesBatch2Str(pMsg); - printf("syncAppendEntriesBatchPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncAppendEntriesBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg) { char* serialized = syncAppendEntriesBatch2Str(pMsg); - printf("syncAppendEntriesBatchPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncAppendEntriesBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg) { char* serialized = syncAppendEntriesBatch2Str(pMsg); - sTrace("syncAppendEntriesBatchLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncAppendEntriesBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg) { if (gRaftDetailLog) { char* serialized = syncAppendEntriesBatch2Str(pMsg); - sTraceLong("syncAppendEntriesBatchLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTraceLong("syncAppendEntriesBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -1966,28 +1966,28 @@ char* syncAppendEntriesReply2Str(const SyncAppendEntriesReply* pMsg) { // for debug ---------------------- void syncAppendEntriesReplyPrint(const SyncAppendEntriesReply* pMsg) { char* serialized = syncAppendEntriesReply2Str(pMsg); - printf("syncAppendEntriesReplyPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncAppendEntriesReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesReplyPrint2(char* s, const SyncAppendEntriesReply* pMsg) { char* serialized = syncAppendEntriesReply2Str(pMsg); - printf("syncAppendEntriesReplyPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncAppendEntriesReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncAppendEntriesReplyLog(const SyncAppendEntriesReply* pMsg) { char* serialized = syncAppendEntriesReply2Str(pMsg); - sTrace("syncAppendEntriesReplyLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncAppendEntriesReplyLog | len:%d| %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg) { if (gRaftDetailLog) { char* serialized = syncAppendEntriesReply2Str(pMsg); - sTrace("syncAppendEntriesReplyLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncAppendEntriesReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -2119,28 +2119,28 @@ char* syncHeartbeat2Str(const SyncHeartbeat* pMsg) { void syncHeartbeatPrint(const SyncHeartbeat* pMsg) { char* serialized = syncHeartbeat2Str(pMsg); - printf("syncHeartbeatPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncHeartbeatPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncHeartbeatPrint2(char* s, const SyncHeartbeat* pMsg) { char* serialized = syncHeartbeat2Str(pMsg); - printf("syncHeartbeatPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncHeartbeatPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncHeartbeatLog(const SyncHeartbeat* pMsg) { char* serialized = syncHeartbeat2Str(pMsg); - sTrace("syncHeartbeatLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncHeartbeatLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncHeartbeatLog2(char* s, const SyncHeartbeat* pMsg) { if (gRaftDetailLog) { char* serialized = syncHeartbeat2Str(pMsg); - sTrace("syncHeartbeatLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncHeartbeatLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -2273,28 +2273,28 @@ char* syncHeartbeatReply2Str(const SyncHeartbeatReply* pMsg) { void syncHeartbeatReplyPrint(const SyncHeartbeatReply* pMsg) { char* serialized = syncHeartbeatReply2Str(pMsg); - printf("syncHeartbeatReplyPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncHeartbeatReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncHeartbeatReplyPrint2(char* s, const SyncHeartbeatReply* pMsg) { char* serialized = syncHeartbeatReply2Str(pMsg); - printf("syncHeartbeatReplyPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncHeartbeatReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncHeartbeatReplyLog(const SyncHeartbeatReply* pMsg) { char* serialized = syncHeartbeatReply2Str(pMsg); - sTrace("syncHeartbeatReplyLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncHeartbeatReplyLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncHeartbeatReplyLog2(char* s, const SyncHeartbeatReply* pMsg) { if (gRaftDetailLog) { char* serialized = syncHeartbeatReply2Str(pMsg); - sTrace("syncHeartbeatReplyLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncHeartbeatReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -2426,28 +2426,28 @@ char* syncApplyMsg2Str(const SyncApplyMsg* pMsg) { // for debug ---------------------- void syncApplyMsgPrint(const SyncApplyMsg* pMsg) { char* serialized = syncApplyMsg2Str(pMsg); - printf("syncApplyMsgPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncApplyMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncApplyMsgPrint2(char* s, const SyncApplyMsg* pMsg) { char* serialized = syncApplyMsg2Str(pMsg); - printf("syncApplyMsgPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncApplyMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncApplyMsgLog(const SyncApplyMsg* pMsg) { char* serialized = syncApplyMsg2Str(pMsg); - sTrace("ssyncApplyMsgLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("ssyncApplyMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg) { if (gRaftDetailLog) { char* serialized = syncApplyMsg2Str(pMsg); - sTrace("syncApplyMsgLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncApplyMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -2603,28 +2603,28 @@ char* syncSnapshotSend2Str(const SyncSnapshotSend* pMsg) { // for debug ---------------------- void syncSnapshotSendPrint(const SyncSnapshotSend* pMsg) { char* serialized = syncSnapshotSend2Str(pMsg); - printf("syncSnapshotSendPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncSnapshotSendPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncSnapshotSendPrint2(char* s, const SyncSnapshotSend* pMsg) { char* serialized = syncSnapshotSend2Str(pMsg); - printf("syncSnapshotSendPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncSnapshotSendPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncSnapshotSendLog(const SyncSnapshotSend* pMsg) { char* serialized = syncSnapshotSend2Str(pMsg); - sTrace("syncSnapshotSendLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncSnapshotSendLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg) { if (gRaftDetailLog) { char* serialized = syncSnapshotSend2Str(pMsg); - sTrace("syncSnapshotSendLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncSnapshotSendLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -2763,28 +2763,28 @@ char* syncSnapshotRsp2Str(const SyncSnapshotRsp* pMsg) { // for debug ---------------------- void syncSnapshotRspPrint(const SyncSnapshotRsp* pMsg) { char* serialized = syncSnapshotRsp2Str(pMsg); - printf("syncSnapshotRspPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncSnapshotRspPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncSnapshotRspPrint2(char* s, const SyncSnapshotRsp* pMsg) { char* serialized = syncSnapshotRsp2Str(pMsg); - printf("syncSnapshotRspPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncSnapshotRspPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncSnapshotRspLog(const SyncSnapshotRsp* pMsg) { char* serialized = syncSnapshotRsp2Str(pMsg); - sTrace("syncSnapshotRspLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncSnapshotRspLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg) { if (gRaftDetailLog) { char* serialized = syncSnapshotRsp2Str(pMsg); - sTrace("syncSnapshotRspLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncSnapshotRspLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -2925,28 +2925,28 @@ char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg) { // for debug ---------------------- void syncLeaderTransferPrint(const SyncLeaderTransfer* pMsg) { char* serialized = syncLeaderTransfer2Str(pMsg); - printf("syncLeaderTransferPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncLeaderTransferPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg) { char* serialized = syncLeaderTransfer2Str(pMsg); - printf("syncLeaderTransferPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncLeaderTransferPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg) { char* serialized = syncLeaderTransfer2Str(pMsg); - sTrace("syncLeaderTransferLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncLeaderTransferLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg) { if (gRaftDetailLog) { char* serialized = syncLeaderTransfer2Str(pMsg); - sTrace("syncLeaderTransferLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncLeaderTransferLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -3054,28 +3054,28 @@ char* syncReconfigFinish2Str(const SyncReconfigFinish* pMsg) { // for debug ---------------------- void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg) { char* serialized = syncReconfigFinish2Str(pMsg); - printf("syncReconfigFinishPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncReconfigFinishPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg) { char* serialized = syncReconfigFinish2Str(pMsg); - printf("syncReconfigFinishPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncReconfigFinishPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncReconfigFinishLog(const SyncReconfigFinish* pMsg) { char* serialized = syncReconfigFinish2Str(pMsg); - sTrace("syncReconfigFinishLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncReconfigFinishLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) { if (gRaftDetailLog) { char* serialized = syncReconfigFinish2Str(pMsg); - sTrace("syncReconfigFinishLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncReconfigFinishLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } -} \ No newline at end of file +} diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index 57126d0871da0ab80cf718260377fa8754581d65..7c8f503de6b3ffec9cb118cf9972bbf17ff412ee 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -355,8 +355,6 @@ char *raftCfg2Str(SRaftCfg *pRaftCfg) { } int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path) { - ASSERT(pCfg != NULL); - TdFilePtr pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE); if (pFile == NULL) { int32_t err = terrno; @@ -447,85 +445,85 @@ int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg) { // for debug ---------------------- void syncCfgPrint(SSyncCfg *pCfg) { char *serialized = syncCfg2Str(pCfg); - printf("syncCfgPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("syncCfgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void syncCfgPrint2(char *s, SSyncCfg *pCfg) { char *serialized = syncCfg2Str(pCfg); - printf("syncCfgPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("syncCfgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void syncCfgLog(SSyncCfg *pCfg) { char *serialized = syncCfg2Str(pCfg); - sTrace("syncCfgLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("syncCfgLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void syncCfgLog2(char *s, SSyncCfg *pCfg) { char *serialized = syncCfg2Str(pCfg); - sTrace("syncCfgLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncCfgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } void syncCfgLog3(char *s, SSyncCfg *pCfg) { char *serialized = syncCfg2SimpleStr(pCfg); - sTrace("syncCfgLog3 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("syncCfgLog3 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } void raftCfgPrint(SRaftCfg *pCfg) { char *serialized = raftCfg2Str(pCfg); - printf("raftCfgPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("raftCfgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void raftCfgPrint2(char *s, SRaftCfg *pCfg) { char *serialized = raftCfg2Str(pCfg); - printf("raftCfgPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("raftCfgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void raftCfgLog(SRaftCfg *pCfg) { char *serialized = raftCfg2Str(pCfg); - sTrace("raftCfgLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("raftCfgLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void raftCfgLog2(char *s, SRaftCfg *pCfg) { char *serialized = raftCfg2Str(pCfg); - sTrace("raftCfgLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("raftCfgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } // --------- void raftCfgIndexPrint(SRaftCfgIndex *pCfg) { char *serialized = raftCfgIndex2Str(pCfg); - printf("raftCfgIndexPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("raftCfgIndexPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void raftCfgIndexPrint2(char *s, SRaftCfgIndex *pCfg) { char *serialized = raftCfgIndex2Str(pCfg); - printf("raftCfgIndexPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("raftCfgIndexPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void raftCfgIndexLog(SRaftCfgIndex *pCfg) { char *serialized = raftCfgIndex2Str(pCfg); - sTrace("raftCfgIndexLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("raftCfgIndexLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void raftCfgIndexLog2(char *s, SRaftCfgIndex *pCfg) { char *serialized = raftCfgIndex2Str(pCfg); - sTrace("raftCfgIndexLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("raftCfgIndexLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index c481c55e1c2ce1f64e1fcd3a97b44bd701a237d7..940aaca055eab991087c7ab7591abc0f46e78ede 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -418,28 +418,28 @@ char* raftCache2Str(SRaftEntryHashCache* pCache) { void raftCachePrint(SRaftEntryHashCache* pCache) { char* serialized = raftCache2Str(pCache); - printf("raftCachePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("raftCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void raftCachePrint2(char* s, SRaftEntryHashCache* pCache) { char* serialized = raftCache2Str(pCache); - printf("raftCachePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("raftCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void raftCacheLog(SRaftEntryHashCache* pCache) { char* serialized = raftCache2Str(pCache); - sTrace("raftCacheLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("raftCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void raftCacheLog2(char* s, SRaftEntryHashCache* pCache) { if (gRaftDetailLog) { char* serialized = raftCache2Str(pCache); - sTraceLong("raftCacheLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTraceLong("raftCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -677,28 +677,28 @@ char* raftEntryCache2Str(SRaftEntryCache* pObj) { void raftEntryCachePrint(SRaftEntryCache* pObj) { char* serialized = raftEntryCache2Str(pObj); - printf("raftEntryCachePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("raftEntryCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj) { char* serialized = raftEntryCache2Str(pObj); - printf("raftEntryCachePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("raftEntryCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void raftEntryCacheLog(SRaftEntryCache* pObj) { char* serialized = raftEntryCache2Str(pObj); - sTrace("raftEntryCacheLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("raftEntryCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj) { if (gRaftDetailLog) { char* serialized = raftEntryCache2Str(pObj); - sTraceLong("raftEntryCacheLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTraceLong("raftEntryCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } -} \ No newline at end of file +} diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index c3dad104d1629cf127a1eae5034fdf0844930e74..23d076cfbc1affd3f52f1f6e1902bf27d2618519 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -33,21 +33,11 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEn static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry); static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIndex); static bool raftLogExist(struct SSyncLogStore* pLogStore, SyncIndex index); +static int32_t raftLogUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index); +static SyncIndex raftlogCommitIndex(SSyncLogStore* pLogStore); -// private function static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** ppLastEntry); -//------------------------------- -// log[0 .. n] -static SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore); -static SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore); -static SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore); -static SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index); -static int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry); -static int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex); -static int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index); -static SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore); - //------------------------------- SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) { SSyncLogStore* pLogStore = taosMemoryMalloc(sizeof(SSyncLogStore)); @@ -74,14 +64,8 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) { pData->pWalHandle = walOpenReader(pData->pWal, NULL); ASSERT(pData->pWalHandle != NULL); - pLogStore->appendEntry = logStoreAppendEntry; - pLogStore->getEntry = logStoreGetEntry; - pLogStore->truncate = logStoreTruncate; - pLogStore->getLastIndex = logStoreLastIndex; - pLogStore->getLastTerm = logStoreLastTerm; - pLogStore->updateCommitIndex = logStoreUpdateCommitIndex; - pLogStore->getCommitIndex = logStoreGetCommitIndex; - + pLogStore->syncLogUpdateCommitIndex = raftLogUpdateCommitIndex; + pLogStore->syncLogCommitIndex = raftlogCommitIndex; pLogStore->syncLogRestoreFromSnapshot = raftLogRestoreFromSnapshot; pLogStore->syncLogBeginIndex = raftLogBeginIndex; pLogStore->syncLogEndIndex = raftLogEndIndex; @@ -234,6 +218,8 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", pEntry->index, err, err, errStr, sysErr, sysErrStr); syncNodeErrorLog(pData->pSyncNode, logBuf); + + ASSERT(0); return -1; } pEntry->index = index; @@ -277,11 +263,15 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", - index, err, err, errStr, sysErr, sysErrStr); if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { - // syncNodeEventLog(pData->pSyncNode, logBuf); + snprintf(logBuf, sizeof(logBuf), + "wal read not exist, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, err, err, + errStr, sysErr, sysErrStr); + syncNodeEventLog(pData->pSyncNode, logBuf); + } else { + snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + index, err, err, errStr, sysErr, sysErrStr); syncNodeErrorLog(pData->pSyncNode, logBuf); } } while (0); @@ -372,157 +362,7 @@ static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** pp return -1; } -//------------------------------- -// log[0 .. n] - -int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { - SSyncLogStoreData* pData = pLogStore->data; - SWal* pWal = pData->pWal; - - SyncIndex index = 0; - SWalSyncInfo syncMeta = {0}; - syncMeta.isWeek = pEntry->isWeak; - syncMeta.seqNum = pEntry->seqNum; - syncMeta.term = pEntry->term; - - index = walAppendLog(pWal, pEntry->originalRpcType, syncMeta, pEntry->data, pEntry->dataLen); - if (index < 0) { - int32_t err = terrno; - const char* errStr = tstrerror(err); - int32_t sysErr = errno; - const char* sysErrStr = strerror(errno); - - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", - pEntry->index, err, err, errStr, sysErr, sysErrStr); - syncNodeErrorLog(pData->pSyncNode, logBuf); - - ASSERT(0); - return -1; - } - pEntry->index = index; - - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "write2 index:%" PRId64 ", type:%s, origin type:%s", pEntry->index, - TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType)); - syncNodeEventLog(pData->pSyncNode, eventLog); - } while (0); - - return 0; -} - -SSyncRaftEntry* logStoreGetEntryWithoutLock(SSyncLogStore* pLogStore, SyncIndex index) { - SSyncLogStoreData* pData = pLogStore->data; - SWal* pWal = pData->pWal; - - if (index >= SYNC_INDEX_BEGIN && index <= logStoreLastIndex(pLogStore)) { - // SWalReadHandle* pWalHandle = walOpenReadHandle(pWal); - SWalReader* pWalHandle = pData->pWalHandle; - ASSERT(pWalHandle != NULL); - - int32_t code = walReadVer(pWalHandle, index); - // int32_t code = walReadVerCached(pWalHandle, index); - if (code != 0) { - int32_t err = terrno; - const char* errStr = tstrerror(err); - int32_t sysErr = errno; - const char* sysErrStr = strerror(errno); - - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", - index, err, err, errStr, sysErr, sysErrStr); - if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { - // syncNodeEventLog(pData->pSyncNode, logBuf); - } else { - syncNodeErrorLog(pData->pSyncNode, logBuf); - } - } while (0); - - sError("failed to read ver since %s. index:%lld", tstrerror(terrno), index); - return NULL; - } - - SSyncRaftEntry* pEntry = syncEntryBuild(pWalHandle->pHead->head.bodyLen); - ASSERT(pEntry != NULL); - - pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST; - pEntry->originalRpcType = pWalHandle->pHead->head.msgType; - pEntry->seqNum = pWalHandle->pHead->head.syncMeta.seqNum; - pEntry->isWeak = pWalHandle->pHead->head.syncMeta.isWeek; - pEntry->term = pWalHandle->pHead->head.syncMeta.term; - pEntry->index = index; - ASSERT(pEntry->dataLen == pWalHandle->pHead->head.bodyLen); - memcpy(pEntry->data, pWalHandle->pHead->head.body, pWalHandle->pHead->head.bodyLen); - - /* - int32_t saveErr = terrno; - walCloseReadHandle(pWalHandle); - terrno = saveErr; - */ - - return pEntry; - - } else { - return NULL; - } -} - -SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { - SSyncLogStoreData* pData = pLogStore->data; - SSyncRaftEntry *pEntry = NULL; - - taosThreadMutexLock(&pData->mutex); - pEntry = logStoreGetEntryWithoutLock(pLogStore, index); - taosThreadMutexUnlock(&pData->mutex); - return pEntry; -} - -int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) { - SSyncLogStoreData* pData = pLogStore->data; - SWal* pWal = pData->pWal; - // ASSERT(walRollback(pWal, fromIndex) == 0); - int32_t code = walRollback(pWal, fromIndex); - if (code != 0) { - int32_t err = terrno; - const char* errStr = tstrerror(err); - int32_t sysErr = errno; - const char* sysErrStr = strerror(errno); - sError("vgId:%d, wal truncate error, from-index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", - pData->pSyncNode->vgId, fromIndex, err, err, errStr, sysErr, sysErrStr); - - ASSERT(0); - } - - // event log - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal truncate, from-index:%" PRId64, fromIndex); - syncNodeEventLog(pData->pSyncNode, logBuf); - } while (0); - - return 0; -} - -SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) { - SSyncLogStoreData* pData = pLogStore->data; - SWal* pWal = pData->pWal; - SyncIndex lastIndex = walGetLastVer(pWal); - return lastIndex; -} - -SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore) { - SyncTerm lastTerm = 0; - SSyncRaftEntry* pLastEntry = logStoreGetLastEntry(pLogStore); - if (pLastEntry != NULL) { - lastTerm = pLastEntry->term; - taosMemoryFree(pLastEntry); - } - return lastTerm; -} - -int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) { +int32_t raftLogUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; // ASSERT(walCommit(pWal, index) == 0); @@ -540,23 +380,11 @@ int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) { return 0; } -SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore) { +SyncIndex raftlogCommitIndex(SSyncLogStore* pLogStore) { SSyncLogStoreData* pData = pLogStore->data; return pData->pSyncNode->commitIndex; } -SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore) { - SSyncLogStoreData* pData = pLogStore->data; - SWal* pWal = pData->pWal; - SyncIndex lastIndex = walGetLastVer(pWal); - - SSyncRaftEntry* pEntry = NULL; - if (lastIndex > 0) { - pEntry = logStoreGetEntry(pLogStore, lastIndex); - } - return pEntry; -} - cJSON* logStore2Json(SSyncLogStore* pLogStore) { char u64buf[128] = {0}; SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data; @@ -595,7 +423,9 @@ cJSON* logStore2Json(SSyncLogStore* pLogStore) { if (!raftLogIsEmpty(pLogStore)) { for (SyncIndex i = beginIndex; i <= endIndex; ++i) { - SSyncRaftEntry* pEntry = logStoreGetEntry(pLogStore, i); + SSyncRaftEntry* pEntry = NULL; + raftLogGetEntry(pLogStore, i, &pEntry); + cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); syncEntryDestory(pEntry); } @@ -675,14 +505,14 @@ SyncIndex logStoreWalCommitVer(SSyncLogStore* pLogStore) { // for debug ----------------- void logStorePrint(SSyncLogStore* pLogStore) { char* serialized = logStore2Str(pLogStore); - printf("logStorePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("logStorePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void logStorePrint2(char* s, SSyncLogStore* pLogStore) { char* serialized = logStore2Str(pLogStore); - printf("logStorePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("logStorePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } @@ -690,7 +520,7 @@ void logStorePrint2(char* s, SSyncLogStore* pLogStore) { void logStoreLog(SSyncLogStore* pLogStore) { if (gRaftDetailLog) { char* serialized = logStore2Str(pLogStore); - sTraceLong("logStoreLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTraceLong("logStoreLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } } @@ -698,7 +528,7 @@ void logStoreLog(SSyncLogStore* pLogStore) { void logStoreLog2(char* s, SSyncLogStore* pLogStore) { if (gRaftDetailLog) { char* serialized = logStore2Str(pLogStore); - sTraceLong("logStoreLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTraceLong("logStoreLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } @@ -706,28 +536,28 @@ void logStoreLog2(char* s, SSyncLogStore* pLogStore) { // for debug ----------------- void logStoreSimplePrint(SSyncLogStore* pLogStore) { char* serialized = logStoreSimple2Str(pLogStore); - printf("logStoreSimplePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("logStoreSimplePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore) { char* serialized = logStoreSimple2Str(pLogStore); - printf("logStoreSimplePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("logStoreSimplePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void logStoreSimpleLog(SSyncLogStore* pLogStore) { char* serialized = logStoreSimple2Str(pLogStore); - sTrace("logStoreSimpleLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("logStoreSimpleLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) { if (gRaftDetailLog) { char* serialized = logStoreSimple2Str(pLogStore); - sTrace("logStoreSimpleLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("logStoreSimpleLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index 6d4d54a9b1708fb5db6eac81df1addc2536b8cfb..dcc4e1f1330a9b8163b338f5d3f0bc0b879fdbf7 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -226,25 +226,25 @@ char *raftStore2Str(SRaftStore *pRaftStore) { // for debug ------------------- void raftStorePrint(SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - printf("raftStorePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("raftStorePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void raftStorePrint2(char *s, SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - printf("raftStorePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("raftStorePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void raftStoreLog(SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - sTrace("raftStoreLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("raftStoreLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void raftStoreLog2(char *s, SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - sTrace("raftStoreLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("raftStoreLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index 886f7ad199818dd81b42e07f14f4679f3a77ac1e..e040310e15a4f01fa9d1c6848bf27157c7a57213 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -47,138 +47,75 @@ // msource |-> i, // mdest |-> j]) // /\ UNCHANGED <> -// -int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode) { - ASSERT(pSyncNode->state == TAOS_SYNC_STATE_LEADER); - syncIndexMgrLog2("==syncNodeAppendEntriesPeers== pNextIndex", pSyncNode->pNextIndex); - syncIndexMgrLog2("==syncNodeAppendEntriesPeers== pMatchIndex", pSyncNode->pMatchIndex); - logStoreSimpleLog2("==syncNodeAppendEntriesPeers==", pSyncNode->pLogStore); +int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) { + // next index + SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId); + + // maybe start snapshot + SyncIndex logStartIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); + SyncIndex logEndIndex = pSyncNode->pLogStore->syncLogEndIndex(pSyncNode->pLogStore); + if (nextIndex < logStartIndex || nextIndex - 1 > logEndIndex) { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "start snapshot for next-index:%" PRId64 ", start:%" PRId64 ", end:%" PRId64, + nextIndex, logStartIndex, logEndIndex); + syncNodeEventLog(pSyncNode, logBuf); - int32_t ret = 0; - for (int i = 0; i < pSyncNode->peersNum; ++i) { - SRaftId* pDestId = &(pSyncNode->peersId[i]); + // start snapshot + int32_t code = syncNodeStartSnapshot(pSyncNode, pDestId); + ASSERT(code == 0); + return 0; + } - // set prevLogIndex - SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId); + // pre index, pre term + SyncIndex preLogIndex = syncNodeGetPreIndex(pSyncNode, nextIndex); + SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex); - SyncIndex preLogIndex = nextIndex - 1; + // prepare entry + SyncAppendEntries* pMsg = NULL; - // set preLogTerm - SyncTerm preLogTerm = 0; - if (preLogIndex >= SYNC_INDEX_BEGIN) { - SSyncRaftEntry* pPreEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, preLogIndex); - ASSERT(pPreEntry != NULL); + SSyncRaftEntry* pEntry; + int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, nextIndex, &pEntry); - preLogTerm = pPreEntry->term; - syncEntryDestory(pPreEntry); - } + if (code == 0) { + ASSERT(pEntry != NULL); - // batch optimized - // SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex); - - SyncAppendEntries* pMsg = NULL; - SSyncRaftEntry* pEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, nextIndex); - if (pEntry != NULL) { - pMsg = syncAppendEntriesBuild(pEntry->bytes, pSyncNode->vgId); - ASSERT(pMsg != NULL); + pMsg = syncAppendEntriesBuild(pEntry->bytes, pSyncNode->vgId); + ASSERT(pMsg != NULL); - // add pEntry into msg - uint32_t len; - char* serialized = syncEntrySerialize(pEntry, &len); - ASSERT(len == pEntry->bytes); - memcpy(pMsg->data, serialized, len); + // add pEntry into msg + uint32_t len; + char* serialized = syncEntrySerialize(pEntry, &len); + ASSERT(len == pEntry->bytes); + memcpy(pMsg->data, serialized, len); - taosMemoryFree(serialized); - syncEntryDestory(pEntry); + taosMemoryFree(serialized); + syncEntryDestory(pEntry); - } else { - // maybe overflow, send empty record + } else { + if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { + // no entry in log pMsg = syncAppendEntriesBuild(0, pSyncNode->vgId); ASSERT(pMsg != NULL); - } - - ASSERT(pMsg != NULL); - pMsg->srcId = pSyncNode->myRaftId; - pMsg->destId = *pDestId; - pMsg->term = pSyncNode->pRaftStore->currentTerm; - pMsg->prevLogIndex = preLogIndex; - pMsg->prevLogTerm = preLogTerm; - pMsg->commitIndex = pSyncNode->commitIndex; - - syncAppendEntriesLog2("==syncNodeAppendEntriesPeers==", pMsg); - - // send AppendEntries - syncNodeAppendEntries(pSyncNode, pDestId, pMsg); - syncAppendEntriesDestroy(pMsg); - } - - return ret; -} - -int32_t syncNodeAppendEntriesOnePeer(SSyncNode* pSyncNode, SRaftId* pDestId, SyncIndex nextIndex) { - int32_t ret = 0; - - // pre index, pre term - SyncIndex preLogIndex = syncNodeGetPreIndex(pSyncNode, nextIndex); - SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex); - if (preLogTerm == SYNC_TERM_INVALID) { - SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1; - // SyncIndex newNextIndex = nextIndex + 1; - - syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex); - syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID); - sError("vgId:%d, sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64 - ", match-index:%d, raftid:%" PRId64, - pSyncNode->vgId, nextIndex, newNextIndex, SYNC_INDEX_INVALID, pDestId->addr); - return -1; - } - - // entry pointer array - SSyncRaftEntry* entryPArr[SYNC_MAX_BATCH_SIZE]; - memset(entryPArr, 0, sizeof(entryPArr)); - - // get entry batch - int32_t getCount = 0; - SyncIndex getEntryIndex = nextIndex; - for (int32_t i = 0; i < pSyncNode->pRaftCfg->batchSize; ++i) { - SSyncRaftEntry* pEntry = NULL; - int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, getEntryIndex, &pEntry); - if (code == 0) { - ASSERT(pEntry != NULL); - entryPArr[i] = pEntry; - getCount++; - getEntryIndex++; } else { - break; - } - } - - // event log - do { - char logBuf[128]; - char host[64]; - uint16_t port; - syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port); - snprintf(logBuf, sizeof(logBuf), "build batch:%d for %s:%d", getCount, host, port); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port); - // build msg - SyncAppendEntriesBatch* pMsg = syncAppendEntriesBatchBuild(entryPArr, getCount, pSyncNode->vgId); - ASSERT(pMsg != NULL); + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "replicate to %s:%d error, next-index:%" PRId64, host, port, nextIndex); + syncNodeErrorLog(pSyncNode, logBuf); + } while (0); - // free entries - for (int32_t i = 0; i < pSyncNode->pRaftCfg->batchSize; ++i) { - SSyncRaftEntry* pEntry = entryPArr[i]; - if (pEntry != NULL) { - syncEntryDestory(pEntry); - entryPArr[i] = NULL; + syncAppendEntriesDestroy(pMsg); + return -1; } } // prepare msg + ASSERT(pMsg != NULL); pMsg->srcId = pSyncNode->myRaftId; pMsg->destId = *pDestId; pMsg->term = pSyncNode->pRaftStore->currentTerm; @@ -186,293 +123,69 @@ int32_t syncNodeAppendEntriesOnePeer(SSyncNode* pSyncNode, SRaftId* pDestId, Syn pMsg->prevLogTerm = preLogTerm; pMsg->commitIndex = pSyncNode->commitIndex; pMsg->privateTerm = 0; - pMsg->dataCount = getCount; + // pMsg->privateTerm = syncIndexMgrGetTerm(pSyncNode->pNextIndex, pDestId); // send msg - syncNodeAppendEntriesBatch(pSyncNode, pDestId, pMsg); - - // speed up - if (pMsg->dataCount > 0 && pSyncNode->commitIndex - pMsg->prevLogIndex > SYNC_SLOW_DOWN_RANGE) { - ret = 1; - -#if 0 - do { - char logBuf[128]; - char host[64]; - uint16_t port; - syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port); - snprintf(logBuf, sizeof(logBuf), "maybe speed up for %s:%d, pre-index:%ld", host, port, pMsg->prevLogIndex); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); -#endif - } - - syncAppendEntriesBatchDestroy(pMsg); + syncNodeMaybeSendAppendEntries(pSyncNode, pDestId, pMsg); + syncAppendEntriesDestroy(pMsg); - return ret; + return 0; } -int32_t syncNodeAppendEntriesPeersSnapshot2(SSyncNode* pSyncNode) { +int32_t syncNodeReplicate(SSyncNode* pSyncNode) { if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { return -1; } - int32_t ret = 0; - for (int i = 0; i < pSyncNode->peersNum; ++i) { - SRaftId* pDestId = &(pSyncNode->peersId[i]); - - // next index - SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId); - ret = syncNodeAppendEntriesOnePeer(pSyncNode, pDestId, nextIndex); - } - - return ret; -} - -#if 0 -int32_t syncNodeAppendEntriesPeersSnapshot2(SSyncNode* pSyncNode) { - if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { - return -1; - } + syncNodeEventLog(pSyncNode, "do replicate"); int32_t ret = 0; for (int i = 0; i < pSyncNode->peersNum; ++i) { SRaftId* pDestId = &(pSyncNode->peersId[i]); - - // next index - SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId); - - // pre index, pre term - SyncIndex preLogIndex = syncNodeGetPreIndex(pSyncNode, nextIndex); - SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex); - if (preLogTerm == SYNC_TERM_INVALID) { - SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1; - // SyncIndex newNextIndex = nextIndex + 1; - - syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex); - syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID); - sError("vgId:%d, sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64 - ", match-index:%d, raftid:%" PRId64, - pSyncNode->vgId, nextIndex, newNextIndex, SYNC_INDEX_INVALID, pDestId->addr); - return -1; - } - - // entry pointer array - SSyncRaftEntry* entryPArr[SYNC_MAX_BATCH_SIZE]; - memset(entryPArr, 0, sizeof(entryPArr)); - - // get entry batch - int32_t getCount = 0; - SyncIndex getEntryIndex = nextIndex; - for (int32_t i = 0; i < pSyncNode->pRaftCfg->batchSize; ++i) { - SSyncRaftEntry* pEntry = NULL; - int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, getEntryIndex, &pEntry); - if (code == 0) { - ASSERT(pEntry != NULL); - entryPArr[i] = pEntry; - getCount++; - getEntryIndex++; - - } else { - break; - } - } - - // event log - do { - char logBuf[128]; - char host[64]; - uint16_t port; + ret = syncNodeReplicateOne(pSyncNode, pDestId); + if (ret != 0) { + char host[64]; + int16_t port; syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port); - snprintf(logBuf, sizeof(logBuf), "build batch:%d for %s:%d", getCount, host, port); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); - - // build msg - SyncAppendEntriesBatch* pMsg = syncAppendEntriesBatchBuild(entryPArr, getCount, pSyncNode->vgId); - ASSERT(pMsg != NULL); - - // free entries - for (int32_t i = 0; i < pSyncNode->pRaftCfg->batchSize; ++i) { - SSyncRaftEntry* pEntry = entryPArr[i]; - if (pEntry != NULL) { - syncEntryDestory(pEntry); - entryPArr[i] = NULL; - } - } - - // prepare msg - pMsg->srcId = pSyncNode->myRaftId; - pMsg->destId = *pDestId; - pMsg->term = pSyncNode->pRaftStore->currentTerm; - pMsg->prevLogIndex = preLogIndex; - pMsg->prevLogTerm = preLogTerm; - pMsg->commitIndex = pSyncNode->commitIndex; - pMsg->privateTerm = 0; - pMsg->dataCount = getCount; - - // send msg - syncNodeAppendEntriesBatch(pSyncNode, pDestId, pMsg); - - // speed up - if (pMsg->dataCount > 0 && pSyncNode->commitIndex - pMsg->prevLogIndex > SYNC_SLOW_DOWN_RANGE) { - ret = 1; - -#if 0 - do { - char logBuf[128]; - char host[64]; - uint16_t port; - syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port); - snprintf(logBuf, sizeof(logBuf), "maybe speed up for %s:%d, pre-index:%ld", host, port, pMsg->prevLogIndex); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); -#endif + sError("vgId:%d, do append entries error for %s:%d", pSyncNode->vgId, host, port); } - - syncAppendEntriesBatchDestroy(pMsg); } - return ret; + return 0; } -#endif - -int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) { - ASSERT(pSyncNode->state == TAOS_SYNC_STATE_LEADER); - - syncIndexMgrLog2("begin append entries peers pNextIndex:", pSyncNode->pNextIndex); - syncIndexMgrLog2("begin append entries peers pMatchIndex:", pSyncNode->pMatchIndex); - logStoreSimpleLog2("begin append entries peers LogStore:", pSyncNode->pLogStore); +int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg) { int32_t ret = 0; - for (int i = 0; i < pSyncNode->peersNum; ++i) { - SRaftId* pDestId = &(pSyncNode->peersId[i]); - - // next index - SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId); - - // pre index, pre term - SyncIndex preLogIndex = syncNodeGetPreIndex(pSyncNode, nextIndex); - SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex); - if (preLogTerm == SYNC_TERM_INVALID) { - SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1; - // SyncIndex newNextIndex = nextIndex + 1; - - syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex); - syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID); - sError("vgId:%d, sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64 - ", match-index:%d, raftid:%" PRId64, - pSyncNode->vgId, nextIndex, newNextIndex, SYNC_INDEX_INVALID, pDestId->addr); - - return -1; - } - - // prepare entry - SyncAppendEntries* pMsg = NULL; - - SSyncRaftEntry* pEntry; - int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, nextIndex, &pEntry); - - if (code == 0) { - ASSERT(pEntry != NULL); - - pMsg = syncAppendEntriesBuild(pEntry->bytes, pSyncNode->vgId); - ASSERT(pMsg != NULL); - - // add pEntry into msg - uint32_t len; - char* serialized = syncEntrySerialize(pEntry, &len); - ASSERT(len == pEntry->bytes); - memcpy(pMsg->data, serialized, len); + syncLogSendAppendEntries(pSyncNode, pMsg, ""); - taosMemoryFree(serialized); - syncEntryDestory(pEntry); + SRpcMsg rpcMsg; + syncAppendEntries2RpcMsg(pMsg, &rpcMsg); + syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg); - } else { - if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { - // no entry in log - pMsg = syncAppendEntriesBuild(0, pSyncNode->vgId); - ASSERT(pMsg != NULL); - - } else { - syncNodeLog3("", pSyncNode); - ASSERT(0); - } - } + SPeerState* pState = syncNodeGetPeerState(pSyncNode, destRaftId); + ASSERT(pState != NULL); - // prepare msg - ASSERT(pMsg != NULL); - pMsg->srcId = pSyncNode->myRaftId; - pMsg->destId = *pDestId; - pMsg->term = pSyncNode->pRaftStore->currentTerm; - pMsg->prevLogIndex = preLogIndex; - pMsg->prevLogTerm = preLogTerm; - pMsg->commitIndex = pSyncNode->commitIndex; - pMsg->privateTerm = 0; - // pMsg->privateTerm = syncIndexMgrGetTerm(pSyncNode->pNextIndex, pDestId); - - // send msg - syncNodeAppendEntries(pSyncNode, pDestId, pMsg); - syncAppendEntriesDestroy(pMsg); + if (pMsg->dataLen > 0) { + pState->lastSendIndex = pMsg->prevLogIndex + 1; + pState->lastSendTime = taosGetTimestampMs(); } return ret; } -int32_t syncNodeReplicate(SSyncNode* pSyncNode, bool isTimer) { - // start replicate +int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg) { int32_t ret = 0; - - switch (pSyncNode->pRaftCfg->snapshotStrategy) { - case SYNC_STRATEGY_NO_SNAPSHOT: - ret = syncNodeAppendEntriesPeers(pSyncNode); - break; - - case SYNC_STRATEGY_STANDARD_SNAPSHOT: - ret = syncNodeAppendEntriesPeersSnapshot(pSyncNode); - break; - - case SYNC_STRATEGY_WAL_FIRST: - ret = syncNodeAppendEntriesPeersSnapshot2(pSyncNode); - break; - - default: - ret = syncNodeAppendEntriesPeers(pSyncNode); - break; - } - - // start delay - int64_t timeNow = taosGetTimestampMs(); - int64_t startDelay = timeNow - pSyncNode->startTime; - - // replicate delay - int64_t replicateDelay = timeNow - pSyncNode->lastReplicateTime; - pSyncNode->lastReplicateTime = timeNow; - - if (ret > 0 && isTimer && startDelay > SYNC_SPEED_UP_AFTER_MS) { - // speed up replicate - int32_t ms = - pSyncNode->heartbeatTimerMS < SYNC_SPEED_UP_HB_TIMER ? pSyncNode->heartbeatTimerMS : SYNC_SPEED_UP_HB_TIMER; - syncNodeRestartNowHeartbeatTimerMS(pSyncNode, ms); - -#if 0 - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "replicate speed up"); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); -#endif + if (syncNodeNeedSendAppendEntries(pSyncNode, destRaftId, pMsg)) { + ret = syncNodeSendAppendEntries(pSyncNode, destRaftId, pMsg); } else { - syncNodeRestartHeartbeatTimer(pSyncNode); - -#if 0 - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "replicate slow down"); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); -#endif + char logBuf[128]; + char host[64]; + int16_t port; + syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); + + snprintf(logBuf, sizeof(logBuf), "do not repcate to %s:%d for index:%" PRId64, host, port, pMsg->prevLogIndex + 1); + syncNodeEventLog(pSyncNode, logBuf); } return ret; @@ -488,12 +201,34 @@ int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, c return ret; } -int32_t syncNodeAppendEntriesBatch(SSyncNode* pSyncNode, const SRaftId* destRaftId, - const SyncAppendEntriesBatch* pMsg) { - syncLogSendAppendEntriesBatch(pSyncNode, pMsg, ""); +int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncHeartbeat* pMsg) { + int32_t ret = 0; + syncLogSendHeartbeat(pSyncNode, pMsg, ""); SRpcMsg rpcMsg; - syncAppendEntriesBatch2RpcMsg(pMsg, &rpcMsg); - syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg); + syncHeartbeat2RpcMsg(pMsg, &rpcMsg); + syncNodeSendMsgById(&(pMsg->destId), pSyncNode, &rpcMsg); + return ret; +} + +int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode) { + for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { + SyncHeartbeat* pSyncMsg = syncHeartbeatBuild(pSyncNode->vgId); + pSyncMsg->srcId = pSyncNode->myRaftId; + pSyncMsg->destId = pSyncNode->peersId[i]; + pSyncMsg->term = pSyncNode->pRaftStore->currentTerm; + pSyncMsg->commitIndex = pSyncNode->commitIndex; + pSyncMsg->minMatchIndex = syncMinMatchIndex(pSyncNode); + pSyncMsg->privateTerm = 0; + + SRpcMsg rpcMsg; + syncHeartbeat2RpcMsg(pSyncMsg, &rpcMsg); + + // send msg + syncNodeSendHeartbeat(pSyncNode, &(pSyncMsg->destId), pSyncMsg); + + syncHeartbeatDestroy(pSyncMsg); + } + return 0; } \ No newline at end of file diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c index 122a81930bec953f167030873ae2ed48bdafc555..074e4fca647e223d85905b46dbf65a26c2914455 100644 --- a/source/libs/sync/src/syncRequestVote.c +++ b/source/libs/sync/src/syncRequestVote.c @@ -42,65 +42,6 @@ // m) // /\ UNCHANGED <> // -int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) { - int32_t ret = 0; - - // if already drop replica, do not process - if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncLogRecvRequestVote(ths, pMsg, "maybe replica already dropped"); - return -1; - } - - bool logOK = (pMsg->lastLogTerm > ths->pLogStore->getLastTerm(ths->pLogStore)) || - ((pMsg->lastLogTerm == ths->pLogStore->getLastTerm(ths->pLogStore)) && - (pMsg->lastLogIndex >= ths->pLogStore->getLastIndex(ths->pLogStore))); - - // maybe update term - if (pMsg->term > ths->pRaftStore->currentTerm) { - syncNodeUpdateTerm(ths, pMsg->term); -#if 0 - if (logOK) { - syncNodeUpdateTerm(ths, pMsg->term); - } else { - syncNodeUpdateTermWithoutStepDown(ths, pMsg->term); - } -#endif - } - ASSERT(pMsg->term <= ths->pRaftStore->currentTerm); - - bool grant = (pMsg->term == ths->pRaftStore->currentTerm) && logOK && - ((!raftStoreHasVoted(ths->pRaftStore)) || (syncUtilSameId(&(ths->pRaftStore->voteFor), &(pMsg->srcId)))); - if (grant) { - // maybe has already voted for pMsg->srcId - // vote again, no harm - raftStoreVote(ths->pRaftStore, &(pMsg->srcId)); - - // forbid elect for this round - syncNodeResetElectTimer(ths); - } - - // send msg - SyncRequestVoteReply* pReply = syncRequestVoteReplyBuild(ths->vgId); - pReply->srcId = ths->myRaftId; - pReply->destId = pMsg->srcId; - pReply->term = ths->pRaftStore->currentTerm; - pReply->voteGranted = grant; - - // trace log - do { - char logBuf[32]; - snprintf(logBuf, sizeof(logBuf), "grant:%d", pReply->voteGranted); - syncLogRecvRequestVote(ths, pMsg, logBuf); - syncLogSendRequestVoteReply(ths, pReply, ""); - } while (0); - - SRpcMsg rpcMsg; - syncRequestVoteReply2RpcMsg(pReply, &rpcMsg); - syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); - syncRequestVoteReplyDestroy(pReply); - - return ret; -} static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pMsg) { SyncTerm myLastTerm = syncNodeGetLastTerm(pSyncNode); @@ -157,12 +98,12 @@ static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pM return false; } -int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) { +int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg) { int32_t ret = 0; // if already drop replica, do not process - if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncLogRecvRequestVote(ths, pMsg, "maybe replica already dropped"); + if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) { + syncLogRecvRequestVote(ths, pMsg, "not in my config"); return -1; } @@ -170,14 +111,8 @@ int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) { // maybe update term if (pMsg->term > ths->pRaftStore->currentTerm) { - syncNodeUpdateTerm(ths, pMsg->term); -#if 0 - if (logOK) { - syncNodeUpdateTerm(ths, pMsg->term); - } else { - syncNodeUpdateTermWithoutStepDown(ths, pMsg->term); - } -#endif + syncNodeStepDown(ths, pMsg->term); + // syncNodeUpdateTerm(ths, pMsg->term); } ASSERT(pMsg->term <= ths->pRaftStore->currentTerm); @@ -188,6 +123,9 @@ int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) { // vote again, no harm raftStoreVote(ths->pRaftStore, &(pMsg->srcId)); + // candidate ? + syncNodeStepDown(ths, ths->pRaftStore->currentTerm); + // forbid elect for this round syncNodeResetElectTimer(ths); } diff --git a/source/libs/sync/src/syncRequestVoteReply.c b/source/libs/sync/src/syncRequestVoteReply.c index 55553d50485358a79adfadc625dd73ca0c05c251..a9c325625813ff9285673579945d6ac16780b6da 100644 --- a/source/libs/sync/src/syncRequestVoteReply.c +++ b/source/libs/sync/src/syncRequestVoteReply.c @@ -37,68 +37,12 @@ // /\ Discard(m) // /\ UNCHANGED <> // -int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) { +int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg) { int32_t ret = 0; // if already drop replica, do not process - if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncLogRecvRequestVoteReply(ths, pMsg, "maybe replica already dropped"); - return -1; - } - - // drop stale response - if (pMsg->term < ths->pRaftStore->currentTerm) { - syncLogRecvRequestVoteReply(ths, pMsg, "drop stale response"); - return -1; - } - - // ASSERT(!(pMsg->term > ths->pRaftStore->currentTerm)); - // no need this code, because if I receive reply.term, then I must have sent for that term. - // if (pMsg->term > ths->pRaftStore->currentTerm) { - // syncNodeUpdateTerm(ths, pMsg->term); - // } - - if (pMsg->term > ths->pRaftStore->currentTerm) { - syncLogRecvRequestVoteReply(ths, pMsg, "error term"); - return -1; - } - - syncLogRecvRequestVoteReply(ths, pMsg, ""); - ASSERT(pMsg->term == ths->pRaftStore->currentTerm); - - // This tallies votes even when the current state is not Candidate, - // but they won't be looked at, so it doesn't matter. - if (ths->state == TAOS_SYNC_STATE_CANDIDATE) { - votesRespondAdd(ths->pVotesRespond, pMsg); - if (pMsg->voteGranted) { - // add vote - voteGrantedVote(ths->pVotesGranted, pMsg); - - // maybe to leader - if (voteGrantedMajority(ths->pVotesGranted)) { - if (!ths->pVotesGranted->toLeader) { - syncNodeCandidate2Leader(ths); - - // prevent to leader again! - ths->pVotesGranted->toLeader = true; - } - } - } else { - ; - // do nothing - // UNCHANGED <> - } - } - - return 0; -} - -int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) { - int32_t ret = 0; - - // if already drop replica, do not process - if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncLogRecvRequestVoteReply(ths, pMsg, "maybe replica already dropped"); + if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) { + syncLogRecvRequestVoteReply(ths, pMsg, "not in my config"); return -1; } @@ -116,6 +60,7 @@ int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteRepl if (pMsg->term > ths->pRaftStore->currentTerm) { syncLogRecvRequestVoteReply(ths, pMsg, "error term"); + syncNodeStepDown(ths, pMsg->term); return -1; } @@ -127,7 +72,7 @@ int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteRepl if (ths->state == TAOS_SYNC_STATE_CANDIDATE) { if (ths->pVotesRespond->term != pMsg->term) { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "vote respond error vote-respond-mgr term:%lu, msg term:lu", + snprintf(logBuf, sizeof(logBuf), "vote respond error vote-respond-mgr term:%" PRIu64 ", msg term:%" PRIu64 "", ths->pVotesRespond->term, pMsg->term); syncNodeErrorLog(ths, logBuf); return -1; @@ -155,4 +100,4 @@ int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteRepl } return 0; -} \ No newline at end of file +} diff --git a/source/libs/sync/src/syncRespMgr.c b/source/libs/sync/src/syncRespMgr.c index 103c2254768a3b5bfc6d5c8090828f999b2e8c9e..88af5746d403e62db38fe49a0886854e53a82f4d 100644 --- a/source/libs/sync/src/syncRespMgr.c +++ b/source/libs/sync/src/syncRespMgr.c @@ -136,7 +136,7 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) { while (pStub) { size_t len; - void *key = taosHashGetKey(pStub, &len); + void * key = taosHashGetKey(pStub, &len); uint64_t *pSeqNum = (uint64_t *)key; sum++; @@ -177,7 +177,7 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) { for (int32_t i = 0; i < arraySize; ++i) { uint64_t *pSeqNum = taosArrayGet(delIndexArray, i); taosHashRemove(pObj->pRespHash, pSeqNum, sizeof(uint64_t)); - sDebug("vgId:%d, resp mgr clean by ttl, seq:%d", pSyncNode->vgId, *pSeqNum); + sDebug("vgId:%d, resp mgr clean by ttl, seq:%" PRId64 "", pSyncNode->vgId, *pSeqNum); } taosArrayDestroy(delIndexArray); } diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index 6167d41141735e1800848a989e1d3a0b75454e41..a7bafa9f28f2b6bdeeb568477cc524648d67cd05 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -41,6 +41,8 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI } memset(pSender, 0, sizeof(*pSender)); + int64_t timeNow = taosGetTimestampMs(); + pSender->start = false; pSender->seq = SYNC_SNAPSHOT_SEQ_INVALID; pSender->ack = SYNC_SNAPSHOT_SEQ_INVALID; @@ -51,7 +53,8 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI pSender->pSyncNode = pSyncNode; pSender->replicaIndex = replicaIndex; pSender->term = pSyncNode->pRaftStore->currentTerm; - pSender->privateTerm = taosGetTimestampMs() + 100; + pSender->privateTerm = timeNow + 100; + pSender->startTime = timeNow; pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &(pSender->snapshot)); pSender->finish = false; } else { @@ -402,6 +405,24 @@ char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event) { return s; } +int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId) { + // calculate index + + syncNodeEventLog(pSyncNode, "start snapshot ..."); + + SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, pDestId); + if (pSender == NULL) { + // create sender + } else { + // if is same + // return 0; + } + + // send begin msg + + return 0; +} + // ------------------------------------- SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId) { bool condition = (pSyncNode->pFsm->FpSnapshotStartWrite != NULL) && (pSyncNode->pFsm->FpSnapshotStopWrite != NULL) && @@ -721,7 +742,7 @@ char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event) // condition 3, recv SYNC_SNAPSHOT_SEQ_FORCE_CLOSE, force close // condition 4, got data, update ack // -int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { +int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { // get receiver SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver; bool needRsp = false; @@ -834,7 +855,7 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { // condition 2 sender receives ack, set seq = ack + 1, send msg from seq // condition 3 sender receives error msg, just print error log // -int32_t syncNodeOnSnapshotRspCb(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) { +int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) { // if already drop replica, do not process if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId)) && pSyncNode->state == TAOS_SYNC_STATE_LEADER) { sError("vgId:%d, recv sync-snapshot-rsp, maybe replica already dropped", pSyncNode->vgId); diff --git a/source/libs/sync/src/syncTimeout.c b/source/libs/sync/src/syncTimeout.c index c3c8131cbb31c3d4ac0b9fb59afc7bc751096329..17c8c14136d858c2a2ea5cba351aa48051f5b60c 100644 --- a/source/libs/sync/src/syncTimeout.c +++ b/source/libs/sync/src/syncTimeout.c @@ -16,6 +16,7 @@ #include "syncTimeout.h" #include "syncElection.h" #include "syncRaftCfg.h" +#include "syncRaftLog.h" #include "syncReplication.h" #include "syncRespMgr.h" @@ -60,12 +61,36 @@ static void syncNodeCleanConfigIndex(SSyncNode* ths) { int32_t syncNodeTimerRoutine(SSyncNode* ths) { syncNodeEventLog(ths, "timer routines"); - if (ths->vgId == 1) { + // timer replicate + syncNodeReplicate(ths); + + // clean mnode index + if (syncNodeIsMnode(ths)) { syncNodeCleanConfigIndex(ths); } + // end timeout wal snapshot + int64_t timeNow = taosGetTimestampMs(); + if (timeNow - ths->snapshottingIndex > SYNC_DEL_WAL_MS && + atomic_load_64(&ths->snapshottingIndex) != SYNC_INDEX_INVALID) { + SSyncLogStoreData* pData = ths->pLogStore->data; + int32_t code = walEndSnapshot(pData->pWal); + if (code != 0) { + sError("vgId:%d, wal snapshot end error since:%s", ths->vgId, terrstr(terrno)); + return -1; + } else { + do { + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "wal snapshot end, index:%" PRId64, atomic_load_64(&ths->snapshottingIndex)); + syncNodeEventLog(ths, logBuf); + } while (0); + + atomic_store_64(&ths->snapshottingIndex, SYNC_INDEX_INVALID); + } + } + #if 0 - if (ths->vgId != 1) { + if (!syncNodeIsMnode(ths)) { syncRespClean(ths->pSyncRespMgr); } #endif @@ -73,9 +98,9 @@ int32_t syncNodeTimerRoutine(SSyncNode* ths) { return 0; } -int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) { +int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg) { int32_t ret = 0; - syncTimeoutLog2("==syncNodeOnTimeoutCb==", pMsg); + syncLogRecvTimer(ths, pMsg, ""); if (pMsg->timeoutType == SYNC_TIMEOUT_PING) { if (atomic_load_64(&ths->pingTimerLogicClockUser) <= pMsg->logicClock) { @@ -84,27 +109,29 @@ int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) { // syncNodePingAll(ths); // syncNodePingPeers(ths); - // sTrace("vgId:%d, sync timeout, type:ping count:%d", ths->vgId, ths->pingTimerCounter); syncNodeTimerRoutine(ths); } } else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) { if (atomic_load_64(&ths->electTimerLogicClockUser) <= pMsg->logicClock) { ++(ths->electTimerCounter); - sTrace("vgId:%d, sync timer, type:election count:%d, electTimerLogicClockUser:%ld", ths->vgId, + sTrace("vgId:%d, sync timer, type:election count:%" PRIu64 ", lc-user:%" PRIu64, ths->vgId, ths->electTimerCounter, ths->electTimerLogicClockUser); + syncNodeElect(ths); } } else if (pMsg->timeoutType == SYNC_TIMEOUT_HEARTBEAT) { if (atomic_load_64(&ths->heartbeatTimerLogicClockUser) <= pMsg->logicClock) { ++(ths->heartbeatTimerCounter); - sTrace("vgId:%d, sync timer, type:replicate count:%d, heartbeatTimerLogicClockUser:%ld", ths->vgId, + sTrace("vgId:%d, sync timer, type:replicate count:%" PRIu64 ", lc-user:%" PRIu64, ths->vgId, ths->heartbeatTimerCounter, ths->heartbeatTimerLogicClockUser); - syncNodeReplicate(ths, true); + + // syncNodeReplicate(ths, true); } + } else { - sError("vgId:%d, unknown timeout-type:%d", ths->vgId, pMsg->timeoutType); + sError("vgId:%d, recv unknown timer-type:%d", ths->vgId, pMsg->timeoutType); } return ret; diff --git a/source/libs/sync/src/syncVoteMgr.c b/source/libs/sync/src/syncVoteMgr.c index 09b79825d04f83ebe8e729b362fd05f95d3b24a4..39d62b957ad90e5f7b9f428e31a24d10cc24bd8f 100644 --- a/source/libs/sync/src/syncVoteMgr.c +++ b/source/libs/sync/src/syncVoteMgr.c @@ -138,27 +138,27 @@ char *voteGranted2Str(SVotesGranted *pVotesGranted) { // for debug ------------------- void voteGrantedPrint(SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); - printf("voteGrantedPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("voteGrantedPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void voteGrantedPrint2(char *s, SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); - printf("voteGrantedPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("voteGrantedPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void voteGrantedLog(SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); - sTrace("voteGrantedLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("voteGrantedLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void voteGrantedLog2(char *s, SVotesGranted *pObj) { char *serialized = voteGranted2Str(pObj); - sTrace("voteGrantedLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("voteGrantedLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } @@ -267,26 +267,26 @@ char *votesRespond2Str(SVotesRespond *pVotesRespond) { // for debug ------------------- void votesRespondPrint(SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); - printf("votesRespondPrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("votesRespondPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void votesRespondPrint2(char *s, SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); - printf("votesRespondPrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("votesRespondPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void votesRespondLog(SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); - sTrace("votesRespondLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("votesRespondLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } void votesRespondLog2(char *s, SVotesRespond *pObj) { char *serialized = votesRespond2Str(pObj); - sTrace("votesRespondLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("votesRespondLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } diff --git a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp index c523fbc1c3115b2c27c0dd48b2f08cffc234c18c..95677e592bb7a4d16f9e7670c5bc4d77ab5a6538 100644 --- a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp +++ b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp @@ -237,8 +237,8 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal* gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply; - gSyncIO->FpOnSyncSnapshotSend = pSyncNode->FpOnSnapshotSend; - gSyncIO->FpOnSyncSnapshotRsp = pSyncNode->FpOnSnapshotRsp; + gSyncIO->FpOnSyncSnapshot = pSyncNode->FpOnSnapshot; + gSyncIO->FpOnSyncSnapshotReply = pSyncNode->FpOnSnapshotReply; gSyncIO->pSyncNode = pSyncNode; syncNodeRelease(pSyncNode); diff --git a/source/libs/sync/test/syncEncodeTest.cpp b/source/libs/sync/test/syncEncodeTest.cpp index 4016f0744201e69aaab2531ab4e64932327b4df0..8b209c4c9ef6e9f2951c5ca28abedd434459bd89 100644 --- a/source/libs/sync/test/syncEncodeTest.cpp +++ b/source/libs/sync/test/syncEncodeTest.cpp @@ -181,8 +181,11 @@ int main(int argc, char **argv) { SSyncNode *pSyncNode = syncNodeInit(); assert(pSyncNode != NULL); SSyncRaftEntry *pEntry = pMsg4; - pSyncNode->pLogStore->appendEntry(pSyncNode->pLogStore, pEntry); - SSyncRaftEntry *pEntry2 = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, pEntry->index); + pSyncNode->pLogStore->syncLogAppendEntry(pSyncNode->pLogStore, pEntry); + + int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, pEntry->index, &pEntry); + ASSERT(code == 0); + syncEntryLog2((char *)"==pEntry2==", pEntry2); // step5 diff --git a/source/libs/sync/test/syncHeartbeatReplyTest.cpp b/source/libs/sync/test/syncHeartbeatReplyTest.cpp index f5519fe6d4bd4870813937eaaddab088ec3889ca..1fac03652b9f0835074ef738f5d38fce720f8aad 100644 --- a/source/libs/sync/test/syncHeartbeatReplyTest.cpp +++ b/source/libs/sync/test/syncHeartbeatReplyTest.cpp @@ -36,7 +36,7 @@ void test1() { void test2() { SyncHeartbeatReply *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char *serialized = (char *)taosMemoryMalloc(len); + char * serialized = (char *)taosMemoryMalloc(len); syncHeartbeatReplySerialize(pMsg, serialized, len); SyncHeartbeatReply *pMsg2 = syncHeartbeatReplyBuild(1000); syncHeartbeatReplyDeserialize(serialized, len, pMsg2); @@ -50,7 +50,7 @@ void test2() { void test3() { SyncHeartbeatReply *pMsg = createMsg(); uint32_t len; - char *serialized = syncHeartbeatReplySerialize2(pMsg, &len); + char * serialized = syncHeartbeatReplySerialize2(pMsg, &len); SyncHeartbeatReply *pMsg2 = syncHeartbeatReplyDeserialize2(serialized, len); syncHeartbeatReplyLog2((char *)"test3: syncHeartbeatReplySerialize3 -> syncHeartbeatReplyDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncHeartbeatTest.cpp b/source/libs/sync/test/syncHeartbeatTest.cpp index 577af33b9c2587ceff1412e499fbc9670d7e98a1..b0c055435599279b08b9aeec6b26f28ca279d0be 100644 --- a/source/libs/sync/test/syncHeartbeatTest.cpp +++ b/source/libs/sync/test/syncHeartbeatTest.cpp @@ -35,7 +35,7 @@ void test1() { void test2() { SyncHeartbeat *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char *serialized = (char *)taosMemoryMalloc(len); + char * serialized = (char *)taosMemoryMalloc(len); syncHeartbeatSerialize(pMsg, serialized, len); SyncHeartbeat *pMsg2 = syncHeartbeatBuild(789); syncHeartbeatDeserialize(serialized, len, pMsg2); @@ -49,7 +49,7 @@ void test2() { void test3() { SyncHeartbeat *pMsg = createMsg(); uint32_t len; - char *serialized = syncHeartbeatSerialize2(pMsg, &len); + char * serialized = syncHeartbeatSerialize2(pMsg, &len); SyncHeartbeat *pMsg2 = syncHeartbeatDeserialize2(serialized, len); syncHeartbeatLog2((char *)"test3: syncHeartbeatSerialize2 -> syncHeartbeatDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncLogStoreTest.cpp b/source/libs/sync/test/syncLogStoreTest.cpp index 9cb8194aa732101cae417bf6402513aec86791ab..9ff0ed208957efc55ad66733d5a1543f44ef795e 100644 --- a/source/libs/sync/test/syncLogStoreTest.cpp +++ b/source/libs/sync/test/syncLogStoreTest.cpp @@ -52,7 +52,7 @@ void cleanup() { void logStoreTest() { pLogStore = logStoreCreate(pSyncNode); assert(pLogStore); - assert(pLogStore->getLastIndex(pLogStore) == SYNC_INDEX_INVALID); + assert(pLogStore->syncLogLastIndex(pLogStore) == SYNC_INDEX_INVALID); logStoreLog2((char*)"logStoreTest", pLogStore); @@ -65,22 +65,20 @@ void logStoreTest() { pEntry->seqNum = 3; pEntry->isWeak = true; pEntry->term = 100 + i; - pEntry->index = pLogStore->getLastIndex(pLogStore) + 1; + pEntry->index = pLogStore->syncLogLastIndex(pLogStore) + 1; snprintf(pEntry->data, dataLen, "value%d", i); syncEntryLog2((char*)"==write entry== :", pEntry); - pLogStore->appendEntry(pLogStore, pEntry); + pLogStore->syncLogAppendEntry(pLogStore, pEntry); syncEntryDestory(pEntry); if (i == 0) { - assert(pLogStore->getLastIndex(pLogStore) == SYNC_INDEX_BEGIN); + assert(pLogStore->syncLogLastIndex(pLogStore) == SYNC_INDEX_BEGIN); } } logStoreLog2((char*)"after appendEntry", pLogStore); - - pLogStore->truncate(pLogStore, 3); + pLogStore->syncLogTruncate(pLogStore, 3); logStoreLog2((char*)"after truncate 3", pLogStore); - logStoreDestory(pLogStore); } diff --git a/source/libs/sync/test/syncTestTool.cpp b/source/libs/sync/test/syncTestTool.cpp index e718d37376c7aa15a131156b638fb12ea11319ca..1cdecfe5b37663671799ede7bcf17556a15fc096 100644 --- a/source/libs/sync/test/syncTestTool.cpp +++ b/source/libs/sync/test/syncTestTool.cpp @@ -266,14 +266,12 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal* gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply; gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout; gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest; - gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote; gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply; gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries; gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply; - - gSyncIO->FpOnSyncSnapshotSend = pSyncNode->FpOnSnapshotSend; - gSyncIO->FpOnSyncSnapshotRsp = pSyncNode->FpOnSnapshotRsp; + gSyncIO->FpOnSyncSnapshot = pSyncNode->FpOnSnapshot; + gSyncIO->FpOnSyncSnapshotReply = pSyncNode->FpOnSnapshotReply; gSyncIO->pSyncNode = pSyncNode; syncNodeRelease(pSyncNode); diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index c90d4e3c03dbaf07ccd9cd790937a99e59caf51e..3d92d164b49c1a2804fd3eab3452ff5d386b080c 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -31,15 +31,17 @@ typedef struct STBC TBC; typedef struct STxn TXN; // TDB -int32_t tdbOpen(const char *dbname, int szPage, int pages, TDB **ppDb); +int32_t tdbOpen(const char *dbname, int szPage, int pages, TDB **ppDb, int8_t rollback); int32_t tdbClose(TDB *pDb); int32_t tdbBegin(TDB *pDb, TXN *pTxn); int32_t tdbCommit(TDB *pDb, TXN *pTxn); +int32_t tdbPostCommit(TDB *pDb, TXN *pTxn); int32_t tdbAbort(TDB *pDb, TXN *pTxn); int32_t tdbAlter(TDB *pDb, int pages); // TTB -int32_t tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TDB *pEnv, TTB **ppTb); +int32_t tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TDB *pEnv, TTB **ppTb, + int8_t rollback); int32_t tdbTbClose(TTB *pTb); int32_t tdbTbDrop(TTB *pTb); int32_t tdbTbInsert(TTB *pTb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn); diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 8f11fb88a2399f84af8b32e41fb9477c2d61485c..3f36a058e5098265ab9467bc4d66d81ba05e2f3e 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -371,7 +371,7 @@ static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2 } return cret; } - +/* static int tdbBtreeOpenImpl(SBTree *pBt) { // Try to get the root page of the an existing btree SPgno pgno; @@ -400,7 +400,7 @@ static int tdbBtreeOpenImpl(SBTree *pBt) { pBt->root = pgno; return 0; } - +*/ int tdbBtreeInitPage(SPage *pPage, void *arg, int init) { SBTree *pBt; u8 flags; @@ -1094,6 +1094,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const // fetch next ofp, a new ofp and make it dirty ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt); if (ret < 0) { + tdbFree(pBuf); return -1; } } @@ -1135,6 +1136,11 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const memcpy(pBuf, ((SCell *)pVal) + vLen - nLeft, bytes); memcpy(pBuf + bytes, &pgno, sizeof(pgno)); + if (ofp == NULL) { + tdbFree(pBuf); + return -1; + } + ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0); if (ret < 0) { tdbFree(pBuf); diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index a2803d3ecf7eabd5a317d7755200cb19f9e9d72a..855e3510f2355729ab66a9e17dc32b91cd78e913 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -15,7 +15,7 @@ #include "tdbInt.h" -int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb) { +int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, int8_t rollback) { TDB *pDb; int dsize; int zsize; @@ -66,7 +66,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb) { #ifdef USE_MAINDB // open main db - ret = tdbTbOpen(TDB_MAINDB_NAME, -1, sizeof(SBtInfo), NULL, pDb, &pDb->pMainDb); + ret = tdbTbOpen(TDB_MAINDB_NAME, -1, sizeof(SBtInfo), NULL, pDb, &pDb->pMainDb, rollback); if (ret < 0) { return -1; } @@ -106,7 +106,8 @@ int32_t tdbBegin(TDB *pDb, TXN *pTxn) { for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) { ret = tdbPagerBegin(pPager, pTxn); if (ret < 0) { - tdbError("failed to begin pager since %s. dbName:%s, txnId:%ld", tstrerror(terrno), pDb->dbName, pTxn->txnId); + tdbError("failed to begin pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName, + pTxn->txnId); return -1; } } @@ -121,7 +122,23 @@ int32_t tdbCommit(TDB *pDb, TXN *pTxn) { for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) { ret = tdbPagerCommit(pPager, pTxn); if (ret < 0) { - tdbError("failed to commit pager since %s. dbName:%s, txnId:%ld", tstrerror(terrno), pDb->dbName, pTxn->txnId); + tdbError("failed to commit pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName, + pTxn->txnId); + return -1; + } + } + + return 0; +} + +int32_t tdbPostCommit(TDB *pDb, TXN *pTxn) { + SPager *pPager; + int ret; + + for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) { + ret = tdbPagerPostCommit(pPager, pTxn); + if (ret < 0) { + tdbError("failed to commit pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName, pTxn->txnId); return -1; } } @@ -136,7 +153,8 @@ int32_t tdbAbort(TDB *pDb, TXN *pTxn) { for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) { ret = tdbPagerAbort(pPager, pTxn); if (ret < 0) { - tdbError("failed to abort pager since %s. dbName:%s, txnId:%ld", tstrerror(terrno), pDb->dbName, pTxn->txnId); + tdbError("failed to abort pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName, + pTxn->txnId); return -1; } } diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 732a57639f2cc1a931a81058461034911a6729ee..bdbd6c2f3dbb904eae7b91c6cb935caa9b20aa2c 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -105,7 +105,7 @@ static int tdbPCacheAlterImpl(SPCache *pCache, int32_t nPage) { for (int32_t iPage = pCache->nPages; iPage < nPage; iPage++) { if (tdbPageCreate(pCache->szPage, &aPage[iPage], tdbDefaultMalloc, NULL) < 0) { // TODO: handle error - tdbOsFree(pCache->aPage); + tdbOsFree(aPage); return -1; } @@ -301,8 +301,8 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) pPage->pPager = pPageH->pPager; memcpy(pPage->pData, pPageH->pData, pPage->pageSize); - // tdbDebug("pcache/pPageH: %p %d %p %p %d", pPageH, pPageH->pPageHdr - pPageH->pData, pPageH->xCellSize, pPage, - // TDB_PAGE_PGNO(pPageH)); + // tdbDebug("pcache/pPageH: %p %ld %p %p %u", pPageH, pPageH->pPageHdr - pPageH->pData, pPageH->xCellSize, pPage, + // TDB_PAGE_PGNO(pPageH)); tdbPageInit(pPage, pPageH->pPageHdr - pPageH->pData, pPageH->xCellSize); pPage->kLen = pPageH->kLen; pPage->vLen = pPageH->vLen; diff --git a/source/libs/tdb/src/db/tdbPage.c b/source/libs/tdb/src/db/tdbPage.c index f4878ea861b342724896e844d4796d4bdd598c01..016ad65cf3849ec7a1af762853932df4e5943d83 100644 --- a/source/libs/tdb/src/db/tdbPage.c +++ b/source/libs/tdb/src/db/tdbPage.c @@ -586,7 +586,7 @@ static inline void setLPageNFree(SPage *pPage, int nFree) { // cell offset static inline int getLPageCellOffset(SPage *pPage, int idx) { - ASSERT(idx >= 0 && idx < getPageCellNum(pPage)); + ASSERT(idx >= 0 && idx < getLPageCellNum(pPage)); return TDB_GET_U24(pPage->pCellIdx + 3 * idx); } diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 90332617cdc01e95931d2450c0f1723a91f75ffc..cee54c1a73f43fb12865a06a94f5c888e134280f 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -116,7 +116,7 @@ int tdbPagerClose(SPager *pPager) { } return 0; } - +/* int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate, SBTree *pBt) { SPgno pgno; SPage *pPage; @@ -167,7 +167,7 @@ int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate, SBTree *pBt) { *ppgno = pgno; return 0; } - +*/ int tdbPagerWrite(SPager *pPager, SPage *pPage) { int ret; SPage **ppPage; @@ -305,6 +305,18 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) { return 0; } +int tdbPagerPostCommit(SPager *pPager, TXN *pTxn) { + if (tdbOsRemove(pPager->jFileName) < 0 && errno != ENOENT) { + tdbError("failed to remove file due to %s. file:%s", strerror(errno), pPager->jFileName); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + pPager->inTran = 0; + + return 0; +} + // recovery dirty pages int tdbPagerAbort(SPager *pPager, TXN *pTxn) { SPage *pPage; @@ -541,8 +553,8 @@ static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage) { ret = tdbOsWrite(pPager->jfd, pPage->pData, pPage->pageSize); if (ret < 0) { - tdbError("failed to write page data due to %s. file:%s, pageSize:%d", strerror(errno), pPager->jFileName, - pPage->pageSize); + tdbError("failed to write page data due to %s. file:%s, pageSize:%ld", strerror(errno), pPager->jFileName, + (long)pPage->pageSize); terrno = TAOS_SYSTEM_ERROR(errno); return -1; } @@ -563,7 +575,7 @@ static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage) { offset = (i64)pPage->pageSize * (TDB_PAGE_PGNO(pPage) - 1); if (tdbOsLSeek(pPager->fd, offset, SEEK_SET) < 0) { - tdbError("failed to lseek due to %s. file:%s, offset:%ld", strerror(errno), pPager->dbFileName, offset); + tdbError("failed to lseek due to %s. file:%s, offset:%" PRId64, strerror(errno), pPager->dbFileName, offset); terrno = TAOS_SYSTEM_ERROR(errno); return -1; } @@ -618,7 +630,7 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) { i64 offset = pPager->pageSize * (pgno - 1); if (tdbOsLSeek(pPager->fd, offset, SEEK_SET) < 0) { - tdbError("failed to lseek fd due to %s. file:%s, offset:%ld", strerror(errno), pPager->dbFileName, offset); + tdbError("failed to lseek fd due to %s. file:%s, offset:%" PRId64, strerror(errno), pPager->dbFileName, offset); terrno = TAOS_SYSTEM_ERROR(errno); tdbOsFree(pageBuf); return -1; @@ -657,3 +669,13 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) { return 0; } + +int tdbPagerRollback(SPager *pPager) { + if (tdbOsRemove(pPager->jFileName) < 0 && errno != ENOENT) { + tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), pPager->jFileName); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return 0; +} diff --git a/source/libs/tdb/src/db/tdbTable.c b/source/libs/tdb/src/db/tdbTable.c index 008907ca777b9216c3675b2a341f8883be7225b2..8b029b06d6d6b0c0332b48bb36075fc9e3fbf28d 100644 --- a/source/libs/tdb/src/db/tdbTable.c +++ b/source/libs/tdb/src/db/tdbTable.c @@ -24,7 +24,8 @@ struct STBC { SBTC btc; }; -int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TDB *pEnv, TTB **ppTb) { +int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TDB *pEnv, TTB **ppTb, + int8_t rollback) { TTB *pTb; SPager *pPager; int ret; @@ -52,6 +53,7 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF if (strcmp(TDB_MAINDB_NAME, tbname)) { pPager = tdbEnvGetPager(pEnv, fFullName); if (!pPager) { + tdbOsFree(pTb); return -1; } @@ -71,6 +73,7 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF if (pPager == NULL) { ret = tdbPagerOpen(pEnv->pCache, fFullName, &pPager); if (ret < 0) { + tdbOsFree(pTb); return -1; } @@ -93,6 +96,7 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF snprintf(fFullName, TDB_FILENAME_LEN, "%s/%s", pEnv->dbName, tbname); ret = tdbPagerOpen(pEnv->pCache, fFullName, &pPager); if (ret < 0) { + tdbOsFree(pTb); return -1; } @@ -110,10 +114,14 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF return -1; } - ret = tdbPagerRestore(pPager, pTb->pBt); - if (ret < 0) { - tdbOsFree(pTb); - return -1; + if (rollback) { + tdbPagerRollback(pPager); + } else { + ret = tdbPagerRestore(pPager, pTb->pBt); + if (ret < 0) { + tdbOsFree(pTb); + return -1; + } } *ppTb = pTb; diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 68434a4319090c2e54fd161e78d30848c36cad4d..b45747c9726aa49857843f859b2c66f20374c214 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -190,12 +190,14 @@ int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate, SBTree *pBt); int tdbPagerWrite(SPager *pPager, SPage *pPage); int tdbPagerBegin(SPager *pPager, TXN *pTxn); int tdbPagerCommit(SPager *pPager, TXN *pTxn); +int tdbPagerPostCommit(SPager *pPager, TXN *pTxn); int tdbPagerAbort(SPager *pPager, TXN *pTxn); int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *, int), void *arg, TXN *pTxn); void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn); int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno); int tdbPagerRestore(SPager *pPager, SBTree *pBt); +int tdbPagerRollback(SPager *pPager); // tdbPCache.c ==================================== #define TDB_PCACHE_PAGE \ diff --git a/source/libs/tdb/test/tdbExOVFLTest.cpp b/source/libs/tdb/test/tdbExOVFLTest.cpp index d98c271edb128d3ba4c8b465dcd0aeba287bd0d4..305e91f62c19f1d067c92fd2ed298dfdd1ee0f70 100644 --- a/source/libs/tdb/test/tdbExOVFLTest.cpp +++ b/source/libs/tdb/test/tdbExOVFLTest.cpp @@ -119,13 +119,13 @@ static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, in return cret; } -TEST(TdbOVFLPagesTest, DISABLED_TbUpsertTest) { - // TEST(TdbOVFLPagesTest, TbUpsertTest) { -} +// TEST(TdbOVFLPagesTest, DISABLED_TbUpsertTest) { +// TEST(TdbOVFLPagesTest, TbUpsertTest) { +//} -TEST(TdbOVFLPagesTest, DISABLED_TbPGetTest) { - // TEST(TdbOVFLPagesTest, TbPGetTest) { -} +// TEST(TdbOVFLPagesTest, DISABLED_TbPGetTest) { +// TEST(TdbOVFLPagesTest, TbPGetTest) { +//} static void generateBigVal(char *val, int valLen) { for (int i = 0; i < valLen; ++i) { @@ -140,7 +140,7 @@ static void generateBigVal(char *val, int valLen) { static TDB *openEnv(char const *envName, int const pageSize, int const pageNum) { TDB *pEnv = NULL; - int ret = tdbOpen(envName, pageSize, pageNum, &pEnv); + int ret = tdbOpen(envName, pageSize, pageNum, &pEnv, 0); if (ret) { pEnv = NULL; } @@ -162,8 +162,8 @@ static void insertOfp(void) { // open db TTB *pDb = NULL; tdb_cmpr_fn_t compFunc = tKeyCmpr; - // ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb); - ret = tdbTbOpen("ofp_insert.db", 12, -1, compFunc, pEnv, &pDb); + // ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0); + ret = tdbTbOpen("ofp_insert.db", 12, -1, compFunc, pEnv, &pDb, 0); GTEST_ASSERT_EQ(ret, 0); // open the pool @@ -193,10 +193,8 @@ static void insertOfp(void) { tdbTxnClose(&txn); } -TEST(TdbOVFLPagesTest, DISABLED_TbInsertTest) { - // TEST(TdbOVFLPagesTest, TbInsertTest) { - insertOfp(); -} +// TEST(TdbOVFLPagesTest, DISABLED_TbInsertTest) { +TEST(TdbOVFLPagesTest, TbInsertTest) { insertOfp(); } // TEST(TdbOVFLPagesTest, DISABLED_TbGetTest) { TEST(TdbOVFLPagesTest, TbGetTest) { @@ -211,8 +209,8 @@ TEST(TdbOVFLPagesTest, TbGetTest) { // open db TTB *pDb = NULL; tdb_cmpr_fn_t compFunc = tKeyCmpr; - // int ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb); - int ret = tdbTbOpen("ofp_insert.db", 12, -1, compFunc, pEnv, &pDb); + // int ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0); + int ret = tdbTbOpen("ofp_insert.db", 12, -1, compFunc, pEnv, &pDb, 0); GTEST_ASSERT_EQ(ret, 0); // generate value payload @@ -253,7 +251,7 @@ TEST(TdbOVFLPagesTest, TbDeleteTest) { // open db TTB *pDb = NULL; tdb_cmpr_fn_t compFunc = tKeyCmpr; - ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb); + ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb, 0); GTEST_ASSERT_EQ(ret, 0); // open the pool @@ -354,12 +352,12 @@ TEST(tdb_test, simple_insert1) { taosRemoveDir("tdb"); // Open Env - ret = tdbOpen("tdb", pageSize, 64, &pEnv); + ret = tdbOpen("tdb", pageSize, 64, &pEnv, 0); GTEST_ASSERT_EQ(ret, 0); // Create a database compFunc = tKeyCmpr; - ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb); + ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb, 0); GTEST_ASSERT_EQ(ret, 0); { @@ -422,13 +420,13 @@ TEST(tdb_test, simple_insert1) { for (int i = 1; i <= nData; i++) { sprintf(key, "key%d", i); - sprintf(val, "value%d", i); + // sprintf(val, "value%d", i); ret = tdbTbGet(pDb, key, strlen(key), &pVal, &vLen); ASSERT(ret == 0); GTEST_ASSERT_EQ(ret, 0); - GTEST_ASSERT_EQ(vLen, strlen(val)); + GTEST_ASSERT_EQ(vLen, sizeof(val) / sizeof(val[0])); GTEST_ASSERT_EQ(memcmp(val, pVal, vLen), 0); } diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 6070052127f8d2efde0fb42a6697935d257675e1..f3a301cf5bed77918f1c4d208f146769688b5206 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -130,12 +130,12 @@ TEST(tdb_test, DISABLED_simple_insert1) { taosRemoveDir("tdb"); // Open Env - ret = tdbOpen("tdb", 4096, 64, &pEnv); + ret = tdbOpen("tdb", 4096, 64, &pEnv, 0); GTEST_ASSERT_EQ(ret, 0); // Create a database compFunc = tKeyCmpr; - ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb); + ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb, 0); GTEST_ASSERT_EQ(ret, 0); { @@ -250,12 +250,12 @@ TEST(tdb_test, DISABLED_simple_insert2) { taosRemoveDir("tdb"); // Open Env - ret = tdbOpen("tdb", 1024, 10, &pEnv); + ret = tdbOpen("tdb", 1024, 10, &pEnv, 0); GTEST_ASSERT_EQ(ret, 0); // Create a database compFunc = tDefaultKeyCmpr; - ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb); + ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb, 0); GTEST_ASSERT_EQ(ret, 0); { @@ -346,11 +346,11 @@ TEST(tdb_test, DISABLED_simple_delete1) { pPool = openPool(); // open env - ret = tdbOpen("tdb", 1024, 256, &pEnv); + ret = tdbOpen("tdb", 1024, 256, &pEnv, 0); GTEST_ASSERT_EQ(ret, 0); // open database - ret = tdbTbOpen("db.db", -1, -1, tKeyCmpr, pEnv, &pDb); + ret = tdbTbOpen("db.db", -1, -1, tKeyCmpr, pEnv, &pDb, 0); GTEST_ASSERT_EQ(ret, 0); tdbTxnOpen(&txn, 0, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED); @@ -435,11 +435,11 @@ TEST(tdb_test, DISABLED_simple_upsert1) { taosRemoveDir("tdb"); // open env - ret = tdbOpen("tdb", 4096, 64, &pEnv); + ret = tdbOpen("tdb", 4096, 64, &pEnv, 0); GTEST_ASSERT_EQ(ret, 0); // open database - ret = tdbTbOpen("db.db", -1, -1, NULL, pEnv, &pDb); + ret = tdbTbOpen("db.db", -1, -1, NULL, pEnv, &pDb, 0); GTEST_ASSERT_EQ(ret, 0); pPool = openPool(); @@ -497,12 +497,12 @@ TEST(tdb_test, multi_thread_query) { taosRemoveDir("tdb"); // Open Env - ret = tdbOpen("tdb", 4096, 10, &pEnv); + ret = tdbOpen("tdb", 4096, 10, &pEnv, 0); GTEST_ASSERT_EQ(ret, 0); // Create a database compFunc = tKeyCmpr; - ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb); + ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb, 0); GTEST_ASSERT_EQ(ret, 0); char key[64]; @@ -614,10 +614,10 @@ TEST(tdb_test, DISABLED_multi_thread1) { taosRemoveDir("tdb"); // Open Env - ret = tdbOpen("tdb", 512, 1, &pDb); + ret = tdbOpen("tdb", 512, 1, &pDb, 0); GTEST_ASSERT_EQ(ret, 0); - ret = tdbTbOpen("db.db", -1, -1, NULL, pDb, &pTb); + ret = tdbTbOpen("db.db", -1, -1, NULL, pDb, &pTb, 0); GTEST_ASSERT_EQ(ret, 0); auto insert = [](TDB *pDb, TTB *pTb, int nData, int *stop, std::shared_timed_mutex *mu) { @@ -726,4 +726,4 @@ TEST(tdb_test, DISABLED_multi_thread1) { ret = tdbClose(pDb); GTEST_ASSERT_EQ(ret, 0); #endif -} \ No newline at end of file +} diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 2399891f6d99ad50e50f3a2b7add37f9f71e2ead..a58363276526dccd612346dc3f1b0063fc91d967 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -234,7 +234,15 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32 cli->addr = tstrdup(server); cli->port = port; - uv_loop_t* loop = uv_default_loop(); + uv_loop_t* loop = taosMemoryMalloc(sizeof(uv_loop_t)); + int err = uv_loop_init(loop); + if (err != 0) { + uError("http-report failed to init uv_loop, reason: %s", uv_strerror(err)); + taosMemoryFree(loop); + terrno = TAOS_SYSTEM_ERROR(err); + destroyHttpClient(cli); + return terrno; + } uv_tcp_init(loop, &cli->tcp); // set up timeout to avoid stuck; int32_t fd = taosCreateSocketWithTimeout(5); @@ -258,5 +266,6 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32 uv_run(loop, UV_RUN_DEFAULT); uv_loop_close(loop); + taosMemoryFree(loop); return terrno; } diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 237a4b6059227bfe435cc36601580f06f8e86f62..756a8ff2cf7202e7a94eb4bd6ce4186f1d68c27f 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -43,7 +43,7 @@ void* rpcOpen(const SRpcInit* pInit) { return NULL; } if (pInit->label) { - tstrncpy(pRpc->label, pInit->label, TSDB_LABEL_LEN); + tstrncpy(pRpc->label, pInit->label, sizeof(pRpc->label)); } pRpc->compressSize = pInit->compressSize; @@ -69,13 +69,14 @@ void* rpcOpen(const SRpcInit* pInit) { pRpc->idleTime = pInit->idleTime; pRpc->tcphandle = (*taosInitHandle[pRpc->connType])(ip, pInit->localPort, pRpc->label, pRpc->numOfThreads, NULL, pRpc); + if (pRpc->tcphandle == NULL) { taosMemoryFree(pRpc); return NULL; } pRpc->parent = pInit->parent; if (pInit->user) { - memcpy(pRpc->user, pInit->user, TSDB_UNI_LEN); + tstrncpy(pRpc->user, pInit->user, sizeof(pRpc->user)); } int64_t refId = transAddExHandle(transGetInstMgt(), pRpc); @@ -87,7 +88,7 @@ void rpcClose(void* arg) { tInfo("start to close rpc"); transRemoveExHandle(transGetInstMgt(), (int64_t)arg); transReleaseExHandle(transGetInstMgt(), (int64_t)arg); - tInfo("rpc is closed"); + tInfo("end to close rpc"); return; } void rpcCloseImpl(void* arg) { @@ -100,11 +101,11 @@ void* rpcMallocCont(int64_t contLen) { int64_t size = contLen + TRANS_MSG_OVERHEAD; char* start = taosMemoryCalloc(1, size); if (start == NULL) { - tError("failed to malloc msg, size:%d", size); + tError("failed to malloc msg, size:%" PRId64, size); terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } else { - tTrace("malloc mem:%p size:%d", start, size); + tTrace("malloc mem:%p size:%" PRId64, start, size); } return start + sizeof(STransMsgHead); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 48b3097449695af53f74147b32bb77238e44235b..126b0b638e4c7611d9e48de0d367aead086b3d17 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -439,12 +439,14 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { tDebug("%s conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.info.ahandle, TMSG_INFO(transMsg.msgType)); if (transMsg.info.ahandle == NULL) { - transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, (int32_t*)&(transMsg.msgType)); + int32_t msgType = 0; + transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, &msgType); + transMsg.msgType = msgType; tDebug("%s conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, transMsg.info.ahandle); } } else { - transMsg.info.ahandle = (pMsg->type != Release && pCtx) ? pCtx->ahandle : NULL; + transMsg.info.ahandle = (pMsg != NULL && pMsg->type != Release && pCtx) ? pCtx->ahandle : NULL; } if (pCtx == NULL || pCtx->pSem == NULL) { @@ -1078,9 +1080,6 @@ static void cliPrepareCb(uv_prepare_t* handle) { QUEUE_REMOVE(h); SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q); - if (pMsg == NULL) { - continue; - } (*cliAsyncHandle[pMsg->type])(pMsg, thrd); count++; } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 3616b4808f8869633bce34f1840644318489bdda..cc381d06a7373a57847a71f83302512a17b9e08d 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -811,7 +811,7 @@ static bool addHandleToAcceptloop(void* arg) { tError("failed to bind:%s", uv_err_name(err)); return false; } - if ((err = uv_listen((uv_stream_t*)&srv->server, 512, uvOnAcceptCb)) != 0) { + if ((err = uv_listen((uv_stream_t*)&srv->server, 4096 * 2, uvOnAcceptCb)) != 0) { tError("failed to listen:%s", uv_err_name(err)); terrno = TSDB_CODE_RPC_PORT_EADDRINUSE; return false; diff --git a/source/libs/transport/test/svrBench.c b/source/libs/transport/test/svrBench.c index 6eb80c8504d68b066d527393a7ba36175f737a23..ce465d989a82078532bd230477b6565cbd098fb2 100644 --- a/source/libs/transport/test/svrBench.c +++ b/source/libs/transport/test/svrBench.c @@ -134,7 +134,7 @@ int main(int argc, char *argv[]) { dDebugFlag = rpcDebugFlag; uDebugFlag = rpcDebugFlag; } else { - printf("\nusage:% [options] \n", argv[0]); + printf("\nusage:%s [options] \n", argv[0]); printf(" [-p port]: server port number, default is:%d\n", rpcInit.localPort); printf(" [-t threads]: number of rpc threads, default is:%d\n", rpcInit.numOfThreads); printf(" [-s sessions]: number of sessions, default is:%d\n", rpcInit.sessions); diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index fa22805df2490508346e3d8821a7956992d019e8..a4c2be4661e5668b99f999ecba3e7ad6b0cc966d 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -69,8 +69,8 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) { int64_t walCkHeadSz = sizeof(SWalCkHead); int64_t end = fileSize; int64_t offset = 0; - int32_t capacity = 0; - int32_t readSize = 0; + int64_t capacity = 0; + int64_t readSize = 0; char* buf = NULL; char* found = NULL; bool firstTrial = pFileInfo->fileSize < fileSize; @@ -200,8 +200,8 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) { // truncate file if (lastEntryEndOffset != fileSize) { - wWarn("vgId:%d, repair meta truncate file %s to %ld, orig size %ld", pWal->cfg.vgId, fnameStr, lastEntryEndOffset, - fileSize); + wWarn("vgId:%d, repair meta truncate file %s to %" PRId64 ", orig size %" PRId64, pWal->cfg.vgId, fnameStr, + lastEntryEndOffset, fileSize); if (taosFtruncateFile(pFile, lastEntryEndOffset) < 0) { wError("failed to truncate file due to %s. file:%s", strerror(errno), fnameStr); terrno = TAOS_SYSTEM_ERROR(errno); @@ -464,7 +464,7 @@ int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { // determine the last valid entry end, i.e. offset while ((offset -= sizeof(SWalIdxEntry)) >= 0) { if (taosLSeekFile(pIdxFile, offset, SEEK_SET) < 0) { - wError("vgId:%d, failed to seek file due to %s. offset:" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), + wError("vgId:%d, failed to seek file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), offset, fnameStr); terrno = TAOS_SYSTEM_ERROR(errno); goto _err; @@ -511,7 +511,7 @@ int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { // rebuild idx file if (taosLSeekFile(pIdxFile, 0, SEEK_END) < 0) { - wError("vgId:%d, failed to seek file due to %s. offset:" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), + wError("vgId:%d, failed to seek file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), offset, fnameStr); terrno = TAOS_SYSTEM_ERROR(errno); goto _err; @@ -528,7 +528,7 @@ int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { idxEntry.offset, fLogNameStr); goto _err; } - wWarn("vgId:%d wal idx append new entry %ld %ld", pWal->cfg.vgId, idxEntry.ver, idxEntry.offset); + wWarn("vgId:%d, wal idx append new entry %" PRId64 " %" PRId64, pWal->cfg.vgId, idxEntry.ver, idxEntry.offset); if (taosWriteFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) < 0) { wError("vgId:%d, failed to append file since %s. file:%s", pWal->cfg.vgId, terrstr(), fnameStr); goto _err; @@ -812,7 +812,7 @@ int walLoadMeta(SWal* pWal) { // find existing meta file int metaVer = walFindCurMetaVer(pWal); if (metaVer == -1) { - wDebug("vgId:%d wal find meta ver %d", pWal->cfg.vgId, metaVer); + wDebug("vgId:%d, wal find meta ver %d", pWal->cfg.vgId, metaVer); return -1; } char fnameStr[WAL_FILE_LEN]; @@ -822,7 +822,7 @@ int walLoadMeta(SWal* pWal) { taosStatFile(fnameStr, &fileSize, NULL); if (fileSize == 0) { taosRemoveFile(fnameStr); - wDebug("vgId:%d wal find empty meta ver %d", pWal->cfg.vgId, metaVer); + wDebug("vgId:%d, wal find empty meta ver %d", pWal->cfg.vgId, metaVer); return -1; } int size = (int)fileSize; diff --git a/source/libs/wal/src/walMgmt.c b/source/libs/wal/src/walMgmt.c index 29058cada1ce665882606ee186074a44452d6533..0df1a6b3878863d16a6ff4b831081e71759f324d 100644 --- a/source/libs/wal/src/walMgmt.c +++ b/source/libs/wal/src/walMgmt.c @@ -138,12 +138,12 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { (void)walLoadMeta(pWal); if (walCheckAndRepairMeta(pWal) < 0) { - wError("vgId:%d cannot open wal since repair meta file failed", pWal->cfg.vgId); + wError("vgId:%d, cannot open wal since repair meta file failed", pWal->cfg.vgId); goto _err; } if (walCheckAndRepairIdx(pWal) < 0) { - wError("vgId:%d cannot open wal since repair idx file failed", pWal->cfg.vgId); + wError("vgId:%d, cannot open wal since repair idx file failed", pWal->cfg.vgId); goto _err; } diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index 179d809c84c5773c138ae7dc35284d5b3fb461eb..8f493ddd85a23a67e1bc2f11412cfc991a4cdeca 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -126,7 +126,7 @@ static int64_t walReadSeekFilePos(SWalReader *pReader, int64_t fileFirstVer, int wError("vgId:%d, failed to read idx file, since %s", pReader->pWal->cfg.vgId, terrstr()); } else { terrno = TSDB_CODE_WAL_FILE_CORRUPTED; - wError("vgId:%d, read idx file incompletely, read bytes %" PRId64 ", bytes should be %" PRIu64, + wError("vgId:%d, read idx file incompletely, read bytes %" PRId64 ", bytes should be %ld", pReader->pWal->cfg.vgId, ret, sizeof(SWalIdxEntry)); } return -1; @@ -182,7 +182,7 @@ int32_t walReadSeekVerImpl(SWalReader *pReader, int64_t ver) { tmpInfo.firstVer = ver; SWalFileInfo *pRet = taosArraySearch(pWal->fileInfoSet, &tmpInfo, compareWalFileInfo, TD_LE); if (pRet == NULL) { - wError("failed to find WAL log file with ver:%lld", ver); + wError("failed to find WAL log file with ver:%" PRId64, ver); terrno = TSDB_CODE_WAL_INVALID_VER; return -1; } @@ -278,12 +278,12 @@ static int32_t walFetchBodyNew(SWalReader *pRead) { wDebug("vgId:%d, wal starts to fetch body, index:%" PRId64, pRead->pWal->cfg.vgId, ver); if (pRead->capacity < pReadHead->bodyLen) { - void *ptr = taosMemoryRealloc(pRead->pHead, sizeof(SWalCkHead) + pReadHead->bodyLen); + SWalCkHead *ptr = (SWalCkHead *)taosMemoryRealloc(pRead->pHead, sizeof(SWalCkHead) + pReadHead->bodyLen); if (ptr == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; return -1; } - pRead->pHead = (SWalCkHead *)ptr; + pRead->pHead = ptr; pReadHead = &pRead->pHead->head; pRead->capacity = pReadHead->bodyLen; } @@ -398,12 +398,12 @@ int32_t walFetchBody(SWalReader *pRead, SWalCkHead **ppHead) { int64_t ver = pReadHead->version; if (pRead->capacity < pReadHead->bodyLen) { - void *ptr = taosMemoryRealloc(*ppHead, sizeof(SWalCkHead) + pReadHead->bodyLen); + SWalCkHead *ptr = (SWalCkHead *)taosMemoryRealloc(*ppHead, sizeof(SWalCkHead) + pReadHead->bodyLen); if (ptr == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; return -1; } - *ppHead = (SWalCkHead *)ptr; + *ppHead = ptr; pReadHead = &((*ppHead)->head); pRead->capacity = pReadHead->bodyLen; } @@ -493,13 +493,14 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) { } if (pReader->capacity < pReader->pHead->head.bodyLen) { - void *ptr = taosMemoryRealloc(pReader->pHead, sizeof(SWalCkHead) + pReader->pHead->head.bodyLen); + SWalCkHead *ptr = + (SWalCkHead *)taosMemoryRealloc(pReader->pHead, sizeof(SWalCkHead) + pReader->pHead->head.bodyLen); if (ptr == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; taosThreadMutexUnlock(&pReader->mutex); return -1; } - pReader->pHead = (SWalCkHead *)ptr; + pReader->pHead = ptr; pReader->capacity = pReader->pHead->head.bodyLen; } diff --git a/source/libs/wal/src/walRef.c b/source/libs/wal/src/walRef.c index 2c45fbbdaf3148ea194a09c31c97b13d7b6d31ec..119d0575d8959e8657deef7f6109c5d6d6623a81 100644 --- a/source/libs/wal/src/walRef.c +++ b/source/libs/wal/src/walRef.c @@ -42,6 +42,7 @@ void walCloseRef(SWal *pWal, int64_t refId) { int32_t walRefVer(SWalRef *pRef, int64_t ver) { SWal *pWal = pRef->pWal; + wDebug("vgId:%d, wal ref version %" PRId64 ", refId %" PRId64, pWal->cfg.vgId, ver, pRef->refId); if (pRef->refVer != ver) { taosThreadMutexLock(&pWal->mutex); if (ver < pWal->vers.firstVer || ver > pWal->vers.lastVer) { diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 0562bbad274a795048c2b91566a3040e43800541..527ffa005623af34d76e6b68644b01b0a66b3163 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -44,20 +44,20 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) { walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); if (taosRemoveFile(fnameStr) < 0) { terrno = TAOS_SYSTEM_ERROR(errno); - wError("vgId:%d restore from snapshot, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); + wError("vgId:%d, restore from snapshot, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); taosThreadMutexUnlock(&pWal->mutex); return -1; } - wInfo("vgId:%d restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr); + wInfo("vgId:%d, restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr); walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); if (taosRemoveFile(fnameStr) < 0) { terrno = TAOS_SYSTEM_ERROR(errno); - wError("vgId:%d cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); + wError("vgId:%d, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); taosThreadMutexUnlock(&pWal->mutex); return -1; } - wInfo("vgId:%d restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr); + wInfo("vgId:%d, restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr); } } walRemoveMeta(pWal); @@ -257,6 +257,8 @@ static FORCE_INLINE int32_t walCheckAndRoll(SWal *pWal) { int32_t walBeginSnapshot(SWal *pWal, int64_t ver) { pWal->vers.verInSnapshotting = ver; + wDebug("vgId:%d, wal begin snapshot for version %" PRId64 ", first ver %" PRId64 ", last ver %" PRId64, + pWal->cfg.vgId, ver, pWal->vers.firstVer, pWal->vers.lastVer); // check file rolling if (pWal->cfg.retentionPeriod == 0) { taosThreadMutexLock(&pWal->mutex); @@ -273,6 +275,10 @@ int32_t walEndSnapshot(SWal *pWal) { int32_t code = 0; taosThreadMutexLock(&pWal->mutex); int64_t ver = pWal->vers.verInSnapshotting; + + wDebug("vgId:%d, wal end snapshot for version %" PRId64 ", first ver %" PRId64 ", last ver %" PRId64, pWal->cfg.vgId, + ver, pWal->vers.firstVer, pWal->vers.lastVer); + if (ver == -1) { code = -1; goto END; @@ -287,7 +293,8 @@ int32_t walEndSnapshot(SWal *pWal) { if (pIter == NULL) break; SWalRef *pRef = *(SWalRef **)pIter; if (pRef->refVer == -1) continue; - ver = TMIN(ver, pRef->refVer); + ver = TMIN(ver, pRef->refVer - 1); + wDebug("vgId:%d, wal found ref %" PRId64 ", refId %" PRId64, pWal->cfg.vgId, pRef->refVer, pRef->refId); } int deleteCnt = 0; @@ -298,7 +305,12 @@ int32_t walEndSnapshot(SWal *pWal) { SWalFileInfo *pInfo = taosArraySearch(pWal->fileInfoSet, &tmp, compareWalFileInfo, TD_LE); if (pInfo) { if (ver >= pInfo->lastVer) { - pInfo++; + pInfo--; + } + if (POINTER_DISTANCE(pInfo, pWal->fileInfoSet->pData) > 0) { + wDebug("vgId:%d, begin remove from %" PRId64, pWal->cfg.vgId, pInfo->firstVer); + } else { + wDebug("vgId:%d, no remove", pWal->cfg.vgId); } // iterate files, until the searched result for (SWalFileInfo *iter = pWal->fileInfoSet->pData; iter < pInfo; iter++) { @@ -315,10 +327,12 @@ int32_t walEndSnapshot(SWal *pWal) { for (int i = 0; i < deleteCnt; i++) { pInfo = taosArrayGet(pWal->fileInfoSet, i); walBuildLogName(pWal, pInfo->firstVer, fnameStr); + wDebug("vgId:%d, remove file %s", pWal->cfg.vgId, fnameStr); if (taosRemoveFile(fnameStr) < 0) { goto UPDATE_META; } walBuildIdxName(pWal, pInfo->firstVer, fnameStr); + wDebug("vgId:%d, remove file %s", pWal->cfg.vgId, fnameStr); if (taosRemoveFile(fnameStr) < 0) { ASSERT(0); } @@ -409,7 +423,7 @@ END: } static int32_t walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { - SWalIdxEntry entry = {.ver = ver, .offset = offset}; + SWalIdxEntry entry = {.ver = ver, .offset = offset}; SWalFileInfo *pFileInfo = walGetCurFileInfo(pWal); ASSERT(pFileInfo != NULL); ASSERT(pFileInfo->firstVer >= 0); @@ -419,12 +433,17 @@ static int32_t walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { int64_t size = taosWriteFile(pWal->pIdxFile, &entry, sizeof(SWalIdxEntry)); if (size != sizeof(SWalIdxEntry)) { - wError("vgId:%d, failed to write idx entry due to %s. ver:%lld", pWal->cfg.vgId, strerror(errno), ver); + wError("vgId:%d, failed to write idx entry due to %s. ver:%" PRId64, pWal->cfg.vgId, strerror(errno), ver); terrno = TAOS_SYSTEM_ERROR(errno); return -1; } - ASSERT(taosLSeekFile(pWal->pIdxFile, 0, SEEK_END) == idxOffset + sizeof(SWalIdxEntry) && "Offset of idx entries misaligned"); + // check alignment of idx entries + int64_t endOffset = taosLSeekFile(pWal->pIdxFile, 0, SEEK_END); + if (endOffset < 0) { + wFatal("vgId:%d, failed to seek end of idxfile due to %s. ver:%" PRId64 "", pWal->cfg.vgId, strerror(errno), ver); + } + ASSERT(endOffset == idxOffset + sizeof(SWalIdxEntry) && "Offset of idx entries misaligned"); return 0; } @@ -432,7 +451,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy const void *body, int32_t bodyLen) { int64_t code = 0; - int64_t offset = walGetCurFileOffset(pWal); + int64_t offset = walGetCurFileOffset(pWal); SWalFileInfo *pFileInfo = walGetCurFileInfo(pWal); ASSERT(pFileInfo != NULL); @@ -449,7 +468,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy pWal->writeHead.cksumHead = walCalcHeadCksum(&pWal->writeHead); pWal->writeHead.cksumBody = walCalcBodyCksum(body, bodyLen); - wDebug("vgId:%d, wal write log %ld, msgType: %s", pWal->cfg.vgId, index, TMSG_INFO(msgType)); + wDebug("vgId:%d, wal write log %" PRId64 ", msgType: %s", pWal->cfg.vgId, index, TMSG_INFO(msgType)); code = walWriteIndex(pWal, index, offset); if (code < 0) { @@ -484,16 +503,16 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy END: // recover in a reverse order if (taosFtruncateFile(pWal->pLogFile, offset) < 0) { - wFatal("vgId:%d, failed to ftruncate logfile to offset:%lld during recovery due to %s", pWal->cfg.vgId, offset, - strerror(errno)); + wFatal("vgId:%d, failed to ftruncate logfile to offset:%" PRId64 " during recovery due to %s", pWal->cfg.vgId, + offset, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); ASSERT(0 && "failed to recover from error"); } int64_t idxOffset = (index - pFileInfo->firstVer) * sizeof(SWalIdxEntry); if (taosFtruncateFile(pWal->pIdxFile, idxOffset) < 0) { - wFatal("vgId:%d, failed to ftruncate idxfile to offset:%lld during recovery due to %s", pWal->cfg.vgId, idxOffset, - strerror(errno)); + wFatal("vgId:%d, failed to ftruncate idxfile to offset:%" PRId64 "during recovery due to %s", pWal->cfg.vgId, + idxOffset, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); ASSERT(0 && "failed to recover from error"); } diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 2902f90f7bca791d08c99c86d4c12d19170229ab..ca997427734ff7a5c817a8e439909cabd68dff64 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -388,8 +388,15 @@ char *taosDirEntryBaseName(char *name) { _splitpath(name, NULL, NULL, Filename1, Ext1); return name + (strlen(name) - strlen(Filename1) - strlen(Ext1)); #else - char *pPoint = strchr(name, '.'); - if (pPoint != NULL) pPoint = 0; + if (name == NULL || (name[0] == '/' && name[1] == '\0')) return name; + char *pPoint = strrchr(name, '/'); + if (pPoint != NULL) { + if (*(pPoint + 1) == '\0') { + *pPoint = '\0'; + return taosDirEntryBaseName(name); + } + return pPoint + 1; + } return name; #endif } diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c index 616ab7875dd9634b4ad4258c51320b589dd744ae..ac1881fc6d843b3ad215ceb809d44e5811c53328 100644 --- a/source/os/src/osEnv.c +++ b/source/os/src/osEnv.c @@ -105,3 +105,5 @@ void osSetSystemLocale(const char *inLocale, const char *inCharSet) { memcpy(tsLocale, inLocale, strlen(inLocale) + 1); memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1); } + +void osSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; } diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index d332d913ca89ff0a80cefd9fececdb2c6279114e..be862308f116da45c53f53a25f89192dd25432c2 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -343,6 +343,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { TdFilePtr pFile = (TdFilePtr)taosMemoryMalloc(sizeof(TdFile)); if (pFile == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; if (fd >= 0) close(fd); if (fp != NULL) fclose(fp); return NULL; diff --git a/source/os/src/osProc.c b/source/os/src/osProc.c deleted file mode 100644 index f060ab48c9bb9fd45b385c36a77db1e0adba0e6f..0000000000000000000000000000000000000000 --- a/source/os/src/osProc.c +++ /dev/null @@ -1,80 +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 . - */ - -#define ALLOW_FORBID_FUNC -#define _DEFAULT_SOURCE -#include "os.h" - -int32_t taosNewProc(char **args) { -#ifdef WINDOWS - assert(0); - return 0; -#else - int32_t pid = fork(); - if (pid == 0) { - args[0] = tsProcPath; - // close(STDIN_FILENO); - // close(STDOUT_FILENO); - // close(STDERR_FILENO); - return execvp(tsProcPath, args); - } else { - return pid; - } -#endif -} - -void taosWaitProc(int32_t pid) { -#ifdef WINDOWS - assert(0); -#else - int32_t status = -1; - waitpid(pid, &status, 0); -#endif -} - -void taosKillProc(int32_t pid) { -#ifdef WINDOWS - assert(0); -#else - kill(pid, SIGINT); -#endif -} - -bool taosProcExist(int32_t pid) { -#ifdef WINDOWS - assert(0); - return false; -#else - int32_t p = getpgid(pid); - return p >= 0; -#endif -} - -// the length of the new name must be less than the original name to take effect -void taosSetProcName(int32_t argc, char **argv, const char *name) { - setThreadName(name); - - for (int32_t i = 0; i < argc; ++i) { - int32_t len = strlen(argv[i]); - for (int32_t j = 0; j < len; ++j) { - argv[i][j] = 0; - } - if (i == 0) { - tstrncpy(argv[0], name, len + 1); - } - } -} - -void taosSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; } diff --git a/source/os/src/osShm.c b/source/os/src/osShm.c deleted file mode 100644 index cb09e2fb38c5edcc00ae753245d98b9ca498e825..0000000000000000000000000000000000000000 --- a/source/os/src/osShm.c +++ /dev/null @@ -1,106 +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 . - */ - -#define ALLOW_FORBID_FUNC -#define _DEFAULT_SOURCE -#include "os.h" - -#define MAX_SHMIDS 6 - -static int32_t shmids[MAX_SHMIDS] = {0}; - -static void taosDeleteCreatedShms() { -#if defined(WINDOWS) - assert(0); -#else - for (int32_t i = 0; i < MAX_SHMIDS; ++i) { - int32_t shmid = shmids[i] - 1; - if (shmid >= 0) { - shmctl(shmid, IPC_RMID, NULL); - } - } -#endif -} - -int32_t taosCreateShm(SShm* pShm, int32_t key, int32_t shmsize) { -#if defined(WINDOWS) - assert(0); -#else - pShm->id = -1; - -#if 1 - key_t __shkey = IPC_PRIVATE; - int32_t __shmflag = IPC_CREAT | IPC_EXCL | 0600; -#else - key_t __shkey = 0X95270000 + key; - int32_t __shmflag = IPC_CREAT | 0600; -#endif - - int32_t shmid = shmget(__shkey, shmsize, __shmflag); - if (shmid < 0) { - return -1; - } - - void* shmptr = shmat(shmid, NULL, 0); - if (shmptr == NULL) { - return -1; - } - - pShm->id = shmid; - pShm->size = shmsize; - pShm->ptr = shmptr; - -#if 0 - if (key >= 0 && key < MAX_SHMIDS) { - shmids[key] = pShm->id + 1; - } - atexit(taosDeleteCreatedShms); -#else - shmctl(pShm->id, IPC_RMID, NULL); -#endif - -#endif - return 0; -} - -void taosDropShm(SShm* pShm) { -#if defined(WINDOWS) - assert(0); -#else - if (pShm->id >= 0) { - if (pShm->ptr != NULL) { - shmdt(pShm->ptr); - } - shmctl(pShm->id, IPC_RMID, NULL); - } - pShm->id = -1; - pShm->size = 0; - pShm->ptr = NULL; -#endif -} - -int32_t taosAttachShm(SShm* pShm) { -#if defined(WINDOWS) - assert(0); -#else - errno = 0; - - void* ptr = shmat(pShm->id, NULL, 0); - if (errno == 0) { - pShm->ptr = ptr; - } -#endif - return errno; -} diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index fc943d4d76f983aed8c36efd72f851e9b8f3baa4..fd5bde90ba21b13f2bb3d2cbbeb7b9778b8929f4 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -73,6 +73,7 @@ typedef struct TdEpoll { EpollFd fd; } * TdEpollPtr, TdEpoll; +#if 0 int32_t taosSendto(TdSocketPtr pSocket, void *buf, int len, unsigned int flags, const struct sockaddr *dest_addr, int addrlen) { if (pSocket == NULL || pSocket->fd < 0) { @@ -84,6 +85,7 @@ int32_t taosSendto(TdSocketPtr pSocket, void *buf, int len, unsigned int flags, return sendto(pSocket->fd, buf, len, flags, dest_addr, addrlen); #endif } + int32_t taosWriteSocket(TdSocketPtr pSocket, void *buf, int len) { if (pSocket == NULL || pSocket->fd < 0) { return -1; @@ -114,6 +116,8 @@ int32_t taosReadFromSocket(TdSocketPtr pSocket, void *buf, int32_t len, int32_t } return recvfrom(pSocket->fd, buf, len, flags, destAddr, addrLen); } +#endif // endif 0 + int32_t taosCloseSocketNoCheck1(SocketFd fd) { #ifdef WINDOWS return closesocket(fd); @@ -121,6 +125,7 @@ int32_t taosCloseSocketNoCheck1(SocketFd fd) { return close(fd); #endif } + int32_t taosCloseSocket(TdSocketPtr *ppSocket) { int32_t code; if (ppSocket == NULL || *ppSocket == NULL || (*ppSocket)->fd < 0) { @@ -131,6 +136,8 @@ int32_t taosCloseSocket(TdSocketPtr *ppSocket) { taosMemoryFree(*ppSocket); return code; } + +#if 0 int32_t taosCloseSocketServer(TdSocketServerPtr *ppSocketServer) { int32_t code; if (ppSocketServer == NULL || *ppSocketServer == NULL || (*ppSocketServer)->fd < 0) { @@ -216,20 +223,6 @@ int32_t taosShutDownSocketServerRDWR(TdSocketServerPtr pSocketServer) { #endif } -void taosWinSocketInit() { -#ifdef WINDOWS - static char flag = 0; - if (flag == 0) { - WORD wVersionRequested; - WSADATA wsaData; - wVersionRequested = MAKEWORD(1, 1); - if (WSAStartup(wVersionRequested, &wsaData) == 0) { - flag = 1; - } - } -#else -#endif -} int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on) { if (pSocket == NULL || pSocket->fd < 0) { return -1; @@ -262,6 +255,8 @@ int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on) { #endif return 0; } +#endif // endif 0 + int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t optlen) { if (pSocket == NULL || pSocket->fd < 0) { return -1; @@ -296,6 +291,8 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void return setsockopt(pSocket->fd, level, optname, optval, (int)optlen); #endif } + +#if 0 int32_t taosGetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t *optlen) { if (pSocket == NULL || pSocket->fd < 0) { return -1; @@ -307,6 +304,9 @@ int32_t taosGetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void return getsockopt(pSocket->fd, level, optname, optval, (int *)optlen); #endif } + +#endif + uint32_t taosInetAddr(const char *ipAddr) { #ifdef WINDOWS uint32_t value; @@ -330,6 +330,7 @@ const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len) { #define TCP_CONN_TIMEOUT 3000 // conn timeout +#if 0 int32_t taosWriteMsg(TdSocketPtr pSocket, void *buf, int32_t nbytes) { if (pSocket == NULL || pSocket->fd < 0) { return -1; @@ -726,6 +727,7 @@ int taosValidIp(uint32_t ip) { #endif return 0; } +#endif // endif 0 bool taosValidIpAndPort(uint32_t ip, uint16_t port) { struct sockaddr_in serverAdd; @@ -774,6 +776,8 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) { return true; // return 0 == taosValidIp(ip) ? true : false; } + +#if 0 TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) { struct sockaddr_in serverAdd; SocketFd fd; @@ -888,6 +892,36 @@ int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len return len; } +// Function converting an IP address string to an uint32_t. +uint32_t ip2uint(const char *const ip_addr) { + char ip_addr_cpy[20]; + char ip[5]; + + tstrncpy(ip_addr_cpy, ip_addr, sizeof(ip_addr_cpy)); + + char *s_start, *s_end; + s_start = ip_addr_cpy; + s_end = ip_addr_cpy; + + int32_t k; + + for (k = 0; *s_start != '\0'; s_start = s_end) { + for (s_end = s_start; *s_end != '.' && *s_end != '\0'; s_end++) { + } + if (*s_end == '.') { + *s_end = '\0'; + s_end++; + } + ip[k++] = (char)atoi(s_start); + } + + ip[k] = '\0'; + + return *((uint32_t *)ip); +} + +#endif // endif 0 + void taosBlockSIGPIPE() { #ifdef WINDOWS // assert(0); @@ -991,34 +1025,6 @@ int32_t taosGetFqdn(char *fqdn) { return 0; } -// Function converting an IP address string to an uint32_t. -uint32_t ip2uint(const char *const ip_addr) { - char ip_addr_cpy[20]; - char ip[5]; - - tstrncpy(ip_addr_cpy, ip_addr, sizeof(ip_addr_cpy)); - - char *s_start, *s_end; - s_start = ip_addr_cpy; - s_end = ip_addr_cpy; - - int32_t k; - - for (k = 0; *s_start != '\0'; s_start = s_end) { - for (s_end = s_start; *s_end != '.' && *s_end != '\0'; s_end++) { - } - if (*s_end == '.') { - *s_end = '\0'; - s_end++; - } - ip[k++] = (char)atoi(s_start); - } - - ip[k] = '\0'; - - return *((uint32_t *)ip); -} - void tinet_ntoa(char *ipstr, uint32_t ip) { sprintf(ipstr, "%d.%d.%d.%d", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24); } @@ -1039,12 +1045,14 @@ void taosSetMaskSIGPIPE() { #endif } +#if 0 int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *addrLen) { if (pSocket == NULL || pSocket->fd < 0) { return -1; } return getsockname(pSocket->fd, destAddr, addrLen); } +#endif // endif 0 /* * Set TCP connection timeout per-socket level. @@ -1080,3 +1088,18 @@ int32_t taosCreateSocketWithTimeout(uint32_t timeout) { return (int)fd; } + +void taosWinSocketInit() { +#ifdef WINDOWS + static char flag = 0; + if (flag == 0) { + WORD wVersionRequested; + WSADATA wsaData; + wVersionRequested = MAKEWORD(1, 1); + if (WSAStartup(wVersionRequested, &wsaData) == 0) { + flag = 1; + } + } +#else +#endif +} diff --git a/source/util/src/tbloomfilter.c b/source/util/src/tbloomfilter.c index f3ccbb0aac5e06673681181795cf5ae1e30a43a8..84a78f34774a606e08bf76b6b40e6a303fc19299 100644 --- a/source/util/src/tbloomfilter.c +++ b/source/util/src/tbloomfilter.c @@ -57,8 +57,10 @@ SBloomFilter *tBloomFilterInit(uint64_t expectedEntries, double errorRate) { // ln(2) = 0.693147180559945 pBF->hashFunctions = (uint32_t)ceil(lnRate / 0.693147180559945); - pBF->hashFn1 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_TIMESTAMP); - pBF->hashFn2 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_NCHAR); + /*pBF->hashFn1 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_TIMESTAMP);*/ + /*pBF->hashFn2 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_NCHAR);*/ + pBF->hashFn1 = taosFastHash; + pBF->hashFn2 = taosDJB2Hash; pBF->buffer = taosMemoryCalloc(pBF->numUnits, sizeof(uint64_t)); if (pBF->buffer == NULL) { tBloomFilterDestroy(pBF); @@ -135,8 +137,10 @@ SBloomFilter *tBloomFilterDecode(SDecoder *pDecoder) { if (tDecodeU64(pDecoder, pUnits + i) < 0) goto _error; } if (tDecodeDouble(pDecoder, &pBF->errorRate) < 0) goto _error; - pBF->hashFn1 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_TIMESTAMP); - pBF->hashFn2 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_NCHAR); + /*pBF->hashFn1 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_TIMESTAMP);*/ + /*pBF->hashFn2 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_NCHAR);*/ + pBF->hashFn1 = taosFastHash; + pBF->hashFn2 = taosDJB2Hash; return pBF; _error: @@ -144,4 +148,4 @@ _error: return NULL; } -bool tBloomFilterIsFull(const SBloomFilter *pBF) { return pBF->size >= pBF->expectedEntries; } \ No newline at end of file +bool tBloomFilterIsFull(const SBloomFilter *pBF) { return pBF->size >= pBF->expectedEntries; } diff --git a/source/util/src/tcache.c b/source/util/src/tcache.c index a559a9c000f4a4d336a8440d17db0629b0caf3a4..7d1686ef80c0e157bd897e1a8f3bdab1411cf97f 100644 --- a/source/util/src/tcache.c +++ b/source/util/src/tcache.c @@ -227,7 +227,7 @@ static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheNode * static FORCE_INLINE STrashElem *doRemoveElemInTrashcan(SCacheObj *pCacheObj, STrashElem *pElem) { if (pElem->pData->signature != pElem->pData) { - uWarn("key:sig:0x%" PRIx64 " %p data has been released, ignore", pElem->pData->signature, pElem->pData); + uWarn("key:sig:0x%" PRIx64 " %p data has been released, ignore", (int64_t)pElem->pData->signature, pElem->pData); return NULL; } diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index edb2f0380efbbfa384e8c611ade240e25a22664f..0bf9e7cc3365240f34fe2b8697559cf60f5fdfe9 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -944,6 +944,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { if (taosReadFile(pFile, buf, fileSize) <= 0) { taosCloseFile(&pFile); uError("load json file error: %s", filepath); + taosMemoryFreeClear(buf); return -1; } taosCloseFile(&pFile); @@ -953,6 +954,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { if (jsonParseError != NULL) { uError("load json file parse error: %s", jsonParseError); } + taosMemoryFreeClear(buf); return -1; } taosMemoryFreeClear(buf); diff --git a/source/util/src/thashutil.c b/source/util/src/thashutil.c index e646e9aa36ec3026d687c09beb084738db503e31..59f7d389c263a72aa11c2521bc546e268cf74f2b 100644 --- a/source/util/src/thashutil.c +++ b/source/util/src/thashutil.c @@ -32,6 +32,23 @@ (h) ^= (h) >> 16; \ } while (0) +uint32_t taosFastHash(const char *key, uint32_t len) { + uint32_t result = 0x55555555; + for (uint32_t i = 0; i < len; i++) { + result ^= (uint8_t)key[i]; + result = ROTL32(result, 5); + } + return result; +} + +uint32_t taosDJB2Hash(const char *key, uint32_t len) { + uint32_t hash = 5381; + for (uint32_t i = 0; i < len; i++) { + hash = ((hash << 5) + hash) + (uint8_t)key[i]; /* hash * 33 + c */ + } + return hash; +} + uint32_t MurmurHash3_32(const char *key, uint32_t len) { const uint8_t *data = (const uint8_t *)key; const int32_t nblocks = len >> 2u; diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index eb62e12a19ed44da50ade5bcb9ba5423530b08dd..f1f926c0b78a991710654f2536211f8d1ec4a76a 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -141,8 +141,6 @@ int32_t taosQueueItemSize(STaosQueue *queue) { } int64_t taosQueueMemorySize(STaosQueue *queue) { - if (queue == NULL) return 0; - taosThreadMutexLock(&queue->mutex); int64_t memOfItems = queue->memOfItems; taosThreadMutexUnlock(&queue->mutex); @@ -298,9 +296,6 @@ int32_t taosGetQitem(STaosQall *qall, void **ppItem) { return num; } -void taosResetQitems(STaosQall *qall) { qall->current = qall->start; } -int32_t taosQallItemSize(STaosQall *qall) { return qall->numOfItems; } - STaosQset *taosOpenQset() { STaosQset *qset = taosMemoryCalloc(sizeof(STaosQset), 1); if (qset == NULL) { @@ -405,8 +400,6 @@ void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) { uDebug("queue:%p is removed from qset:%p", queue, qset); } -int32_t taosGetQueueNumber(STaosQset *qset) { return qset->numOfQueues; } - int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo) { STaosQnode *pNode = NULL; int32_t code = 0; @@ -497,6 +490,12 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo * return code; } +int32_t taosQallItemSize(STaosQall *qall) { return qall->numOfItems; } +void taosResetQitems(STaosQall *qall) { qall->current = qall->start; } +int32_t taosGetQueueNumber(STaosQset *qset) { return qset->numOfQueues; } + +#if 0 + void taosResetQsetThread(STaosQset *qset, void *pItem) { if (pItem == NULL) return; STaosQnode *pNode = (STaosQnode *)((char *)pItem - sizeof(STaosQnode)); @@ -507,3 +506,5 @@ void taosResetQsetThread(STaosQset *qset, void *pItem) { } taosThreadMutexUnlock(&qset->mutex); } + +#endif diff --git a/source/util/src/tsched.c b/source/util/src/tsched.c index f524680331dcfdc61005c3e3b60b679463c5a1b9..467f26b36275a84d64d89e1e00b5e901f9867307 100644 --- a/source/util/src/tsched.c +++ b/source/util/src/tsched.c @@ -26,19 +26,25 @@ static void *taosProcessSchedQueue(void *param); static void taosDumpSchedulerStatus(void *qhandle, void *tmrId); void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *label, SSchedQueue *pSched) { + bool schedMalloced = false; + if (NULL == pSched) { pSched = (SSchedQueue *)taosMemoryCalloc(sizeof(SSchedQueue), 1); if (pSched == NULL) { uError("%s: no enough memory for pSched", label); return NULL; } + + schedMalloced = true; } pSched->queue = (SSchedMsg *)taosMemoryCalloc(sizeof(SSchedMsg), queueSize); if (pSched->queue == NULL) { uError("%s: no enough memory for queue", label); taosCleanUpScheduler(pSched); - taosMemoryFree(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } @@ -46,6 +52,9 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab if (pSched->qthread == NULL) { uError("%s: no enough memory for qthread", label); taosCleanUpScheduler(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } @@ -58,18 +67,27 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab if (taosThreadMutexInit(&pSched->queueMutex, NULL) < 0) { uError("init %s:queueMutex failed(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } if (tsem_init(&pSched->emptySem, 0, (uint32_t)pSched->queueSize) != 0) { uError("init %s:empty semaphore failed(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } if (tsem_init(&pSched->fullSem, 0, 0) != 0) { uError("init %s:full semaphore failed(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } @@ -83,6 +101,9 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab if (code != 0) { uError("%s: failed to create rpc thread(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); + if (schedMalloced) { + taosMemoryFree(pSched); + } return NULL; } ++pSched->numOfThreads; diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index e353546ca7a359a970accd6071ef6018e45eaa64..f7d4173d3fcb4e30c927543436acb83596bf7339 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -28,10 +28,7 @@ int32_t tQWorkerInit(SQWorkerPool *pool) { return -1; } - if (taosThreadMutexInit(&pool->mutex, NULL)) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + (void)taosThreadMutexInit(&pool->mutex, NULL); for (int32_t i = 0; i < pool->max; ++i) { SQWorker *worker = pool->workers + i; @@ -97,14 +94,10 @@ static void *tQWorkerThreadFp(SQWorker *worker) { } STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) { - taosThreadMutexLock(&pool->mutex); STaosQueue *queue = taosOpenQueue(); - if (queue == NULL) { - taosThreadMutexUnlock(&pool->mutex); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } + if (queue == NULL) return NULL; + taosThreadMutexLock(&pool->mutex); taosSetQueueFp(queue, fp, NULL); taosAddIntoQset(pool->qset, queue, ahandle); @@ -118,7 +111,6 @@ STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) { taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tQWorkerThreadFp, worker) != 0) { - uError("worker:%s:%d failed to create thread to process since %s", pool->name, worker->id, strerror(errno)); taosCloseQueue(queue); terrno = TSDB_CODE_OUT_OF_MEMORY; queue = NULL; @@ -150,10 +142,7 @@ int32_t tWWorkerInit(SWWorkerPool *pool) { return -1; } - if (taosThreadMutexInit(&pool->mutex, NULL) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + (void)taosThreadMutexInit(&pool->mutex, NULL); for (int32_t i = 0; i < pool->max; ++i) { SWWorker *worker = pool->workers + i; @@ -225,48 +214,27 @@ static void *tWWorkerThreadFp(SWWorker *worker) { STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) { taosThreadMutexLock(&pool->mutex); SWWorker *worker = pool->workers + pool->nextId; + int32_t code = -1; STaosQueue *queue = taosOpenQueue(); - if (queue == NULL) { - taosThreadMutexUnlock(&pool->mutex); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } + if (queue == NULL) goto _OVER; taosSetQueueFp(queue, NULL, fp); - if (worker->qset == NULL) { worker->qset = taosOpenQset(); - if (worker->qset == NULL) { - taosCloseQueue(queue); - taosThreadMutexUnlock(&pool->mutex); - return NULL; - } + if (worker->qset == NULL) goto _OVER; taosAddIntoQset(worker->qset, queue, ahandle); worker->qall = taosAllocateQall(); - if (worker->qall == NULL) { - taosCloseQset(worker->qset); - taosCloseQueue(queue); - taosThreadMutexUnlock(&pool->mutex); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } + if (worker->qall == NULL) goto _OVER; + TdThreadAttr thAttr; taosThreadAttrInit(&thAttr); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); + if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker) != 0) goto _OVER; - if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker) != 0) { - uError("worker:%s:%d failed to create thread to process since %s", pool->name, worker->id, strerror(errno)); - taosFreeQall(worker->qall); - taosCloseQset(worker->qset); - taosCloseQueue(queue); - terrno = TSDB_CODE_OUT_OF_MEMORY; - queue = NULL; - } else { - uDebug("worker:%s:%d is launched, max:%d", pool->name, worker->id, pool->max); - pool->nextId = (pool->nextId + 1) % pool->max; - } + uDebug("worker:%s:%d is launched, max:%d", pool->name, worker->id, pool->max); + pool->nextId = (pool->nextId + 1) % pool->max; taosThreadAttrDestroy(&thAttr); pool->num++; @@ -276,10 +244,20 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) { pool->nextId = (pool->nextId + 1) % pool->max; } - taosThreadMutexUnlock(&pool->mutex); uDebug("worker:%s, queue:%p is allocated, ahandle:%p", pool->name, queue, ahandle); + code = 0; - return queue; +_OVER: + taosThreadMutexUnlock(&pool->mutex); + + if (code == -1) { + if (queue != NULL) taosCloseQueue(queue); + if (worker->qset != NULL) taosCloseQset(worker->qset); + if (worker->qall != NULL) taosFreeQall(worker->qall); + return NULL; + } else { + return queue; + } } void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue) { @@ -292,15 +270,11 @@ int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg) pPool->name = pCfg->name; pPool->min = pCfg->min; pPool->max = pCfg->max; - if (tQWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + if (tQWorkerInit(pPool) != 0) return -1; + pWorker->queue = tQWorkerAllocQueue(pPool, pCfg->param, pCfg->fp); - if (pWorker->queue == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + if (pWorker->queue == NULL) return -1; + pWorker->name = pCfg->name; return 0; } @@ -320,15 +294,11 @@ int32_t tMultiWorkerInit(SMultiWorker *pWorker, const SMultiWorkerCfg *pCfg) { SWWorkerPool *pPool = &pWorker->pool; pPool->name = pCfg->name; pPool->max = pCfg->max; - if (tWWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + if (tWWorkerInit(pPool) != 0) return -1; + pWorker->queue = tWWorkerAllocQueue(pPool, pCfg->param, pCfg->fp); - if (pWorker->queue == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } + if (pWorker->queue == NULL) return -1; + pWorker->name = pCfg->name; return 0; } diff --git a/source/util/test/CMakeLists.txt b/source/util/test/CMakeLists.txt index 6e42ef7e75eac38a5a072bfef8521152fd74ae06..2e307771b7ed6c5473c4edc0b1947de199f82f10 100644 --- a/source/util/test/CMakeLists.txt +++ b/source/util/test/CMakeLists.txt @@ -45,14 +45,6 @@ INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc) # add_executable(encodeTest "encodeTest.cpp") # target_link_libraries(encodeTest os util gtest gtest_main) -# queueTest -# add_executable(procTest "procTest.cpp") -# target_link_libraries(procTest os util transport sut gtest_main) -# add_test( -# NAME procTest -# COMMAND procTest -# ) - # cfgTest add_executable(cfgTest "cfgTest.cpp") target_link_libraries(cfgTest os util gtest_main) diff --git a/source/util/test/hashTest.cpp b/source/util/test/hashTest.cpp index 7c9283464eec311b1cfa48b7eee75b5c89fa3018..76fb9c70679c30e537a9ece9b1202b2c9b5da08e 100644 --- a/source/util/test/hashTest.cpp +++ b/source/util/test/hashTest.cpp @@ -216,7 +216,7 @@ void perfTest() { char* name = (char*)taosMemoryCalloc(50000000, 9); for (int64_t i = 0; i < 50000000; ++i) { - sprintf(name + i * 9, "t%08d", i); + sprintf(name + i * 9, "t%08" PRId64, i); } for (int64_t i = 0; i < 50; ++i) { diff --git a/source/util/test/procTest.cpp b/source/util/test/procTest.cpp deleted file mode 100644 index 53d3fa2c4bc118d57d9a8d08ecc4810f83aa5eda..0000000000000000000000000000000000000000 --- a/source/util/test/procTest.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/** - * @file queue.cpp - * @author slguan (slguan@taosdata.com) - * @brief UTIL module queue tests - * @version 1.0 - * @date 2022-01-27 - * - * @copyright Copyright (c) 2022 - * - */ -#if 0 -#include -#include "tlog.h" -#include "tprocess.h" -#include "tqueue.h" - -typedef struct STestMsg { - uint16_t msgType; - void *pCont; - int contLen; - int32_t code; - void *handle; // rpc handle returned to app - void *ahandle; // app handle set by client - int noResp; // has response or not(default 0, 0: resp, 1: no resp); - int persistHandle; // persist handle or not -} STestMsg; - -class UtilTesProc : public ::testing::Test { - public: - void SetUp() override { - shm.id = -1; - for (int32_t i = 0; i < 4000; ++i) { - body[i] = i % 26 + 'a'; - } - head.pCont = body; - head.code = 1; - head.msgType = 2; - head.noResp = 3; - head.persistHandle = 4; - - taosRemoveDir(TD_TMP_DIR_PATH "td"); - taosMkDir(TD_TMP_DIR_PATH "td"); - tstrncpy(tsLogDir, TD_TMP_DIR_PATH "td", PATH_MAX); - if (taosInitLog("taosdlog", 1) != 0) { - printf("failed to init log file\n"); - } - } - void TearDown() override { taosDropShm(&shm); } - - public: - static STestMsg head; - static char body[4000]; - static SShm shm; - static void SetUpTestSuite() {} - static void TearDownTestSuite() {} -}; - -SShm UtilTesProc::shm; -char UtilTesProc::body[4000]; -STestMsg UtilTesProc::head; - -TEST_F(UtilTesProc, 00_Init_Cleanup) { - ASSERT_EQ(taosCreateShm(&shm, 1234, 1024 * 1024 * 2), 0); - - shm.size = 1023; - SProcCfg cfg = {(ProcConsumeFp)NULL, - (ProcMallocFp)taosAllocateQitem, - (ProcFreeFp)taosFreeQitem, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryMalloc, - (ProcConsumeFp)NULL, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryFree, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryMalloc, - shm, - &shm, - "1234"}; - SProc *proc = dmInitProc(&cfg); - ASSERT_EQ(proc, nullptr); - - shm.size = 2468; - cfg.shm = shm; - proc = dmInitProc(&cfg); - ASSERT_NE(proc, nullptr); - - ASSERT_EQ(dmRunProc(proc), 0); - dmCleanupProc(proc); - taosDropShm(&shm); -} - -void ConsumeChild1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { - STestMsg msg; - memcpy(&msg, pHead, headLen); - char body[2000] = {0}; - memcpy(body, pBody, bodyLen); - - uDebug("====> parent:%" PRId64 " ftype:%d, headLen:%d bodyLen:%d head:%d:%d:%d:%d body:%s <====", (int64_t)parent, - ftype, headLen, bodyLen, msg.code, msg.msgType, msg.noResp, msg.persistHandle, body); - taosMemoryFree(pBody); - taosFreeQitem(pHead); -} - -TEST_F(UtilTesProc, 01_Push_Pop_Child) { - shm.size = 3000; - ASSERT_EQ(taosCreateShm(&shm, 1235, shm.size), 0); - SProcCfg cfg = {(ProcConsumeFp)ConsumeChild1, - (ProcMallocFp)taosAllocateQitem, - (ProcFreeFp)taosFreeQitem, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryFree, - (ProcConsumeFp)NULL, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryFree, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryFree, - shm, - (void *)((int64_t)1235), - "1235_c"}; - SProc *cproc = dmInitProc(&cfg); - ASSERT_NE(cproc, nullptr); - - ASSERT_NE(dmPutToProcCQueue(cproc, &head, 0, body, 0, 0, 0, DND_FUNC_RSP), 0); - ASSERT_NE(dmPutToProcCQueue(cproc, &head, 0, body, 0, 0, 0, DND_FUNC_REGIST), 0); - ASSERT_NE(dmPutToProcCQueue(cproc, &head, 0, body, 0, 0, 0, DND_FUNC_RELEASE), 0); - ASSERT_NE(dmPutToProcCQueue(cproc, NULL, 12, body, 0, 0, 0, DND_FUNC_REQ), 0); - ASSERT_NE(dmPutToProcCQueue(cproc, &head, 0, body, 0, 0, 0, DND_FUNC_REQ), 0); - ASSERT_NE(dmPutToProcCQueue(cproc, &head, shm.size, body, 0, 0, 0, DND_FUNC_REQ), 0); - ASSERT_NE(dmPutToProcCQueue(cproc, &head, sizeof(STestMsg), body, shm.size, 0, 0, DND_FUNC_REQ), 0); - - for (int32_t j = 0; j < 1000; j++) { - int32_t i = 0; - for (i = 0; i < 20; ++i) { - ASSERT_EQ(dmPutToProcCQueue(cproc, &head, sizeof(STestMsg), body, i, 0, 0, DND_FUNC_REQ), 0); - } - ASSERT_NE(dmPutToProcCQueue(cproc, &head, sizeof(STestMsg), body, i, 0, 0, DND_FUNC_REQ), 0); - - cfg.isChild = true; - cfg.name = "1235_p"; - SProc *pproc = dmInitProc(&cfg); - ASSERT_NE(pproc, nullptr); - dmRunProc(pproc); - dmCleanupProc(pproc); - } - - dmCleanupProc(cproc); - taosDropShm(&shm); -} - -void ConsumeParent1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { - STestMsg msg; - memcpy(&msg, pHead, headLen); - char body[2000] = {0}; - memcpy(body, pBody, bodyLen); - - uDebug("----> parent:%" PRId64 " ftype:%d, headLen:%d bodyLen:%d head:%d:%d:%d:%d body:%s <----", (int64_t)parent, - ftype, headLen, bodyLen, msg.code, msg.msgType, msg.noResp, msg.persistHandle, body); - taosMemoryFree(pBody); - taosMemoryFree(pHead); -} - -TEST_F(UtilTesProc, 02_Push_Pop_Parent) { - shm.size = 3000; - ASSERT_EQ(taosCreateShm(&shm, 1236, shm.size), 0); - SProcCfg cfg = {(ProcConsumeFp)NULL, - (ProcMallocFp)taosAllocateQitem, - (ProcFreeFp)taosFreeQitem, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryFree, - (ProcConsumeFp)ConsumeParent1, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryFree, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryFree, - shm, - (void *)((int64_t)1236), - "1236_c"}; - SProc *cproc = dmInitProc(&cfg); - ASSERT_NE(cproc, nullptr); - - cfg.name = "1236_p"; - cfg.isChild = true; - SProc *pproc = dmInitProc(&cfg); - ASSERT_NE(pproc, nullptr); - - for (int32_t j = 0; j < 1000; j++) { - int32_t i = 0; - for (i = 0; i < 20; ++i) { - dmPutToProcPQueue(pproc, &head, sizeof(STestMsg), body, i, DND_FUNC_REQ); - } - - dmRunProc(cproc); - dmStopProc(cproc); - } - - dmCleanupProc(pproc); - dmCleanupProc(cproc); - taosDropShm(&shm); -} - -void ConsumeChild3(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { - STestMsg msg; - memcpy(&msg, pHead, headLen); - char body[2000] = {0}; - memcpy(body, pBody, bodyLen); - - uDebug("====> parent:%" PRId64 " ftype:%d, headLen:%d bodyLen:%d handle:%" PRId64 " body:%s <====", (int64_t)parent, - ftype, headLen, bodyLen, (int64_t)msg.handle, body); - taosMemoryFree(pBody); - taosFreeQitem(pHead); -} - -void processHandle(void *handle) { uDebug("----> remove handle:%" PRId64 " <----", (int64_t)handle); } - -TEST_F(UtilTesProc, 03_Handle) { - // uDebugFlag = 207; - shm.size = 3000; - ASSERT_EQ(taosCreateShm(&shm, 1237, shm.size), 0); - SProcCfg cfg = {(ProcConsumeFp)ConsumeChild3, - (ProcMallocFp)taosAllocateQitem, - (ProcFreeFp)taosFreeQitem, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryFree, - (ProcConsumeFp)NULL, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryFree, - (ProcMallocFp)taosMemoryMalloc, - (ProcFreeFp)taosMemoryFree, - shm, - (void *)((int64_t)1235), - "1237_p"}; - SProc *cproc = dmInitProc(&cfg); - ASSERT_NE(cproc, nullptr); - - for (int32_t j = 0; j < 1; j++) { - int32_t i = 0; - for (i = 0; i < 20; ++i) { - head.handle = (void *)((int64_t)i); - ASSERT_EQ(dmPutToProcCQueue(cproc, &head, sizeof(STestMsg), body, i, (void *)((int64_t)i), i, DND_FUNC_REQ), 0); - } - - cfg.isChild = true; - cfg.name = "child_queue"; - SProc *pproc = dmInitProc(&cfg); - ASSERT_NE(pproc, nullptr); - dmRunProc(pproc); - dmCleanupProc(pproc); - - int64_t ref = 0; - - ref = dmRemoveProcRpcHandle(cproc, (void *)((int64_t)3)); - EXPECT_EQ(ref, 3); - ref = dmRemoveProcRpcHandle(cproc, (void *)((int64_t)5)); - EXPECT_EQ(ref, 5); - ref = dmRemoveProcRpcHandle(cproc, (void *)((int64_t)6)); - EXPECT_EQ(ref, 6); - dmCloseProcRpcHandles(cproc, processHandle); - } - - dmCleanupProc(cproc); - taosDropShm(&shm); -} - -#endif \ No newline at end of file diff --git a/tests/docs-examples-test/taosx.sh b/tests/docs-examples-test/taosx.sh new file mode 100644 index 0000000000000000000000000000000000000000..5db2605bfd83a694118e28a68282f97aa90933b5 --- /dev/null +++ b/tests/docs-examples-test/taosx.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +taosd >>/dev/null 2>&1 & +taosadapter >>/dev/null 2>&1 & +sleep 5 + +taosBenchmark -y -n 10000 -t 1000 + +taosx run -f 'tmq:///test' -t 'taos:///test1' -y + +taos -s 'select count(*) from test1.meters' |grep 10000000 || (echo database sync failed!; exit 1) + +taosx run -f 'tmq:///test' -t 'local:./test-backup' -y +taosx run -f 'local:./test-backup' -t 'taos:///test2' -y + +rm -rf ./test-backup diff --git a/tests/parallel_test/container_build.sh b/tests/parallel_test/container_build.sh index deaea4fa4078b5ec480b711d1ac5865bb2e67dac..e88982aa8000abb5f97eb1a8005cbbefbac8eab5 100755 --- a/tests/parallel_test/container_build.sh +++ b/tests/parallel_test/container_build.sh @@ -52,7 +52,7 @@ fi docker run \ -v $REP_MOUNT_PARAM \ - --rm --ulimit core=-1 taos_test:v1.0 sh -c "cd $REP_DIR;rm -rf debug;mkdir -p debug;cd debug;cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true -DWEBSOCKET=true;make -j $THREAD_COUNT" + --rm --ulimit core=-1 taos_test:v1.0 sh -c "cd $REP_DIR;rm -rf debug;mkdir -p debug;cd debug;cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true -DWEBSOCKET=true -DBUILD_TAOSX=true;make -j $THREAD_COUNT" ret=$? exit $ret diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 4bcbe190d564a3d734d8c720af88eb1493867019..b9504875e55dfc36487f23d951fc2da26f48719f 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -131,7 +131,7 @@ class TDDnode: "qDebugFlag": "143", "rpcDebugFlag": "143", "tmrDebugFlag": "131", - "uDebugFlag": "131", + "uDebugFlag": "143", "sDebugFlag": "143", "wDebugFlag": "143", "numOfLogLines": "100000000", diff --git a/tests/script/api/dbTableRoute.c b/tests/script/api/dbTableRoute.c new file mode 100644 index 0000000000000000000000000000000000000000..2cf721875a23c121d8dfd3131b3758f8dadd2192 --- /dev/null +++ b/tests/script/api/dbTableRoute.c @@ -0,0 +1,195 @@ +/* + * 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 . + */ + +// TAOS asynchronous API example +// this example opens multiple tables, insert/retrieve multiple tables +// it is used by TAOS internally for one performance testing +// to compiple: gcc -o asyncdemo asyncdemo.c -ltaos + +#include +#include +#include +#include +#include +#include +#include "taos.h" + +int rtTables = 20; +char hostName[128]; + +static void rtExecSQL(TAOS *taos, char *command) { + int i; + int32_t code = -1; + + TAOS_RES *pSql = taos_query(taos, command); + code = taos_errno(pSql); + if (code != 0) { + fprintf(stderr, "Failed to run %s, reason: %s\n", command, taos_errstr(pSql)); + taos_free_result(pSql); + taos_close(taos); + taos_cleanup(); + exit(EXIT_FAILURE); + } + + taos_free_result(pSql); +} + +static void rtFetchVgId(TAOS *taos, char *sql, int *vgId) { + int i; + int32_t code = -1; + + TAOS_RES *pSql = taos_query(taos, sql); + code = taos_errno(pSql); + if (code != 0) { + fprintf(stderr, "Failed to run %s, reason: %s\n", sql, taos_errstr(pSql)); + taos_free_result(pSql); + taos_close(taos); + taos_cleanup(); + exit(EXIT_FAILURE); + } + + TAOS_ROW row = taos_fetch_row(pSql); + + *vgId = *(int*)row[0]; + + taos_free_result(pSql); +} + +void rtError(char* prefix, const char* errMsg) { + fprintf(stderr, "%s error: %s\n", prefix, errMsg); +} + +void rtExit(char* prefix, const char* errMsg) { + rtError(prefix, errMsg); + exit(1); +} + +int rtPrepare(TAOS ** p, int prefix, int suffix) { + char sql[1024] = {0}; + int32_t code = 0; + TAOS *taos = taos_connect(hostName, "root", "taosdata", NULL, 0); + if (taos == NULL) rtExit("taos_connect", taos_errstr(NULL)); + + strcpy(sql, "drop database if exists db1"); + rtExecSQL(taos, sql); + + sprintf(sql, "create database db1 vgroups 10 table_prefix %d table_suffix %d", prefix, suffix); + rtExecSQL(taos, sql); + + strcpy(sql, "use db1"); + rtExecSQL(taos, sql); + + for (int32_t i = 0; i < rtTables; ++i) { + sprintf(sql, "create table tb%d (ts timestamp, f1 int)", i); + rtExecSQL(taos, sql); + } + + *p = taos; + + return 0; +} + +int rtGetDbRouteInfo(TAOS * taos) { + TAOS_DB_ROUTE_INFO dbInfo; + int code = taos_get_db_route_info(taos, "db1", &dbInfo); + if (code) { + rtExit("taos_get_db_route_info", taos_errstr(NULL)); + } + + printf("db db1 routeVersion:%d hashPrefix:%d hashSuffix:%d hashMethod:%d vgNum %d\n", + dbInfo.routeVersion, dbInfo.hashPrefix, dbInfo.hashSuffix, dbInfo.hashMethod, dbInfo.vgNum); + + for (int32_t i = 0; i < dbInfo.vgNum; ++i) { + printf("%dth vg, id:%d hashBegin:%u hashEnd:%u\n", + i, dbInfo.vgHash[i].vgId, dbInfo.vgHash[i].hashBegin, dbInfo.vgHash[i].hashEnd); + } + + return 0; +} + +int rtGetTableRouteInfo(TAOS * taos) { + char table[64] = {0}; + int vgId1 = 0; + int vgId2 = 0; + char sql[1024] = {0}; + for (int32_t i = 0; i < rtTables; ++i) { + sprintf(table, "tb%d", i); + int code = taos_get_table_vgId(taos, "db1", table, &vgId1); + if (code) { + rtExit("taos_get_table_vgId", taos_errstr(NULL)); + } + + sprintf(sql, "select vgroup_id from information_schema.ins_tables where table_name=\"tb%d\"", i); + + rtFetchVgId(taos, sql, &vgId2); + if (vgId1 != vgId2) { + fprintf(stderr, "!!!! table tb%d vgId mis-match, vgId(api):%d, vgId(sys):%d\n", i, vgId1, vgId2); + exit(1); + } else { + printf("table tb%d vgId %d\n", i, vgId1); + } + } + + return 0; +} + +void rtClose(TAOS * taos) { + taos_close(taos); +} + + +int rtRunCase1(void) { + TAOS *taos = NULL; + rtPrepare(&taos, 0, 0); + rtGetDbRouteInfo(taos); + rtGetTableRouteInfo(taos); + rtClose(taos); + + return 0; +} + +int rtRunCase2(void) { + TAOS *taos = NULL; + rtPrepare(&taos, 2, 0); + rtGetTableRouteInfo(taos); + rtGetDbRouteInfo(taos); + rtClose(taos); + + return 0; +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + printf("usage: %s server-ip\n", argv[0]); + exit(0); + } + + srand((unsigned int)time(NULL)); + + strcpy(hostName, argv[1]); + + rtRunCase1(); + rtRunCase2(); + + int32_t l = 5; + while (l) { + printf("%d\n", l--); + sleep(1); + } + + return 0; +} + + diff --git a/tests/script/api/makefile b/tests/script/api/makefile index 1f725f17c95217fabbd2d40166a8af19e3df1a52..52c9fcbdf8f43010c6801be5d7bbb9661cb08f00 100644 --- a/tests/script/api/makefile +++ b/tests/script/api/makefile @@ -13,6 +13,7 @@ all: $(TARGET) exe: gcc $(CFLAGS) ./batchprepare.c -o $(ROOT)batchprepare $(LFLAGS) gcc $(CFLAGS) ./stopquery.c -o $(ROOT)stopquery $(LFLAGS) + gcc $(CFLAGS) ./dbTableRoute.c -o $(ROOT)dbTableRoute $(LFLAGS) clean: rm $(ROOT)batchprepare diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 81625d55e5680c7688dd47305271714fd5c8524f..d5f19cc62f4f3dd6c0e38c97e4025264f69b0c4a 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -9,8 +9,8 @@ # ---- db ---- ./test.sh -f tsim/db/alter_option.sim -# unsupport ./test.sh -f tsim/db/alter_replica_13.sim -# unsupport ./test.sh -f tsim/db/alter_replica_31.sim +./test.sh -f tsim/db/alter_replica_13.sim +./test.sh -f tsim/db/alter_replica_31.sim ./test.sh -f tsim/db/basic1.sim ./test.sh -f tsim/db/basic2.sim ./test.sh -f tsim/db/basic3.sim @@ -228,7 +228,7 @@ ./test.sh -f tsim/table/vgroup.sim # ---- stream -./test.sh -f tsim/stream/basic0.sim +./test.sh -f tsim/stream/basic0.sim -v ./test.sh -f tsim/stream/basic1.sim ./test.sh -f tsim/stream/basic2.sim ./test.sh -f tsim/stream/drop_stream.sim @@ -298,18 +298,7 @@ ./test.sh -f tsim/stable/tag_rename.sim ./test.sh -f tsim/stable/values.sim ./test.sh -f tsim/stable/vnode3.sim - -# --- for multi process mode -./test.sh -f tsim/user/basic.sim -m -./test.sh -f tsim/db/basic3.sim -m -./test.sh -f tsim/db/error1.sim -m -./test.sh -f tsim/insert/backquote.sim -m -# unsupport ./test.sh -f tsim/parser/fourArithmetic-basic.sim -m -./test.sh -f tsim/query/interval-offset.sim -m -# unsupport ./test.sh -f tsim/tmq/basic3.sim -m -./test.sh -f tsim/stable/vnode3.sim -m -./test.sh -f tsim/qnode/basic1.sim -m -# unsupport ./test.sh -f tsim/mnode/basic1.sim -m +./test.sh -f tsim/stable/metrics_idx.sim # --- sma ./test.sh -f tsim/sma/drop_sma.sim @@ -457,5 +446,7 @@ ./test.sh -f tsim/tag/set.sim ./test.sh -f tsim/tag/smallint.sim ./test.sh -f tsim/tag/tinyint.sim +./test.sh -f tsim/tag/drop_tag.sim + #======================b1-end=============== diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 5f497a248f7aadd1e060cd44ee9073d792bf14ba..606afe164b9657e63ae68c2edb1231073031d96d 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -9,7 +9,6 @@ UNAME_BIN=`which uname` OS_TYPE=`$UNAME_BIN` NODE_NAME= NODE= -MULTIPROCESS=0 while getopts "n:i:m" arg do case $arg in @@ -19,9 +18,6 @@ do i) NODE=$OPTARG ;; - m) - MULTIPROCESS=1 - ;; ?) echo "unkonw argument" ;; @@ -148,5 +144,4 @@ echo "numOfLogLines 20000000" >> $TAOS_CFG echo "asyncLog 0" >> $TAOS_CFG echo "locale en_US.UTF-8" >> $TAOS_CFG echo "telemetryReporting 0" >> $TAOS_CFG -echo "multiProcess ${MULTIPROCESS}" >> $TAOS_CFG echo " " >> $TAOS_CFG diff --git a/tests/script/test.sh b/tests/script/test.sh index 0ffe8cf8f16e9cf6114e3dd4348de56a4f8a497c..15305679876625b150aa4d53038f025e0acb7ff6 100755 --- a/tests/script/test.sh +++ b/tests/script/test.sh @@ -15,7 +15,6 @@ VALGRIND=0 UNIQUE=0 UNAME_BIN=`which uname` OS_TYPE=`$UNAME_BIN` -MULTIPROCESS=0 while getopts "f:avum" arg do case $arg in @@ -28,9 +27,6 @@ do u) UNIQUE=1 ;; - m) - MULTIPROCESS=1 - ;; ?) echo "unknow argument" ;; @@ -126,22 +122,12 @@ ulimit -c unlimited if [ -n "$FILE_NAME" ]; then echo "------------------------------------------------------------------------" if [ $VALGRIND -eq 1 ]; then - if [[ $MULTIPROCESS -eq 1 ]];then - FLAG="-m -v" - else - FLAG="-v" - fi - + FLAG="-v" echo valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --child-silent-after-fork=yes --show-leak-kinds=all --num-callers=20 -v --workaround-gcc296-bugs=yes --log-file=${LOG_DIR}/valgrind-tsim.log $PROGRAM -c $CFG_DIR -f $FILE_NAME $FLAG valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --child-silent-after-fork=yes --show-leak-kinds=all --num-callers=20 -v --workaround-gcc296-bugs=yes --log-file=${LOG_DIR}/valgrind-tsim.log $PROGRAM -c $CFG_DIR -f $FILE_NAME $FLAG else - if [[ $MULTIPROCESS -eq 1 ]];then - echo "ExcuteCmd(multiprocess):" $PROGRAM -m -c $CFG_DIR -f $FILE_NAME - $PROGRAM -m -c $CFG_DIR -f $FILE_NAME - else - echo "ExcuteCmd(singleprocess):" $PROGRAM -c $CFG_DIR -f $FILE_NAME - $PROGRAM -c $CFG_DIR -f $FILE_NAME - fi + echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME + $PROGRAM -c $CFG_DIR -f $FILE_NAME fi else echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f basicSuite.sim diff --git a/tests/script/tsim/alter/dnode.sim b/tests/script/tsim/alter/dnode.sim index be3c385d45a58a538d786a34fe59f74e5dc38678..8cfa86a88a50c55b6ba85a199ba09237c8e06795 100644 --- a/tests/script/tsim/alter/dnode.sim +++ b/tests/script/tsim/alter/dnode.sim @@ -32,6 +32,26 @@ sql alter dnode 1 'rpcDebugFlag 131' sql alter dnode 1 'qDebugFlag 131' sql alter dnode 1 'metaDebugFlag 131' +sql alter dnode 1 'debugFlag' '135' +sql alter dnode 1 'dDebugFlag' '131' +sql alter dnode 1 'vDebugFlag' '131' +sql alter dnode 1 'mDebugFlag' '131' +sql alter dnode 1 'wDebugFlag' '131' +sql alter dnode 1 'sDebugFlag' '131' +sql alter dnode 1 'tsdbDebugFlag' '131' +sql alter dnode 1 'tqDebugFlag' '131' +sql alter dnode 1 'fsDebugFlag' '131' +sql alter dnode 1 'udfDebugFlag' '131' +sql alter dnode 1 'smaDebugFlag' '131' +sql alter dnode 1 'idxDebugFlag' '131' +sql alter dnode 1 'tdbDebugFlag' '131' +sql alter dnode 1 'tmrDebugFlag' '131' +sql alter dnode 1 'uDebugFlag' '131' +sql alter dnode 1 'smaDebugFlag' '131' +sql alter dnode 1 'rpcDebugFlag' '131' +sql alter dnode 1 'qDebugFlag' '131' +sql alter dnode 1 'metaDebugFlag' '131' + sql_error alter dnode 2 'wDebugFlag 135' sql_error alter dnode 2 'tmrDebugFlag 135' sql_error alter dnode 1 'monDebugFlag 131' @@ -39,6 +59,13 @@ sql_error alter dnode 1 'cqDebugFlag 131' sql_error alter dnode 1 'httpDebugFlag 131' sql_error alter dnode 1 'mqttDebugFlag 131' +sql_error alter dnode 2 'wDebugFlag' '135' +sql_error alter dnode 2 'tmrDebugFlag' '135' +sql_error alter dnode 1 'monDebugFlag' '131' +sql_error alter dnode 1 'cqDebugFlag' '131' +sql_error alter dnode 1 'httpDebugFlag' '131' +sql_error alter dnode 1 'mqttDebugFlag' '131' + print ======== step3 sql_error alter $hostname1 debugFlag 135 sql_error alter $hostname1 monDebugFlag 135 diff --git a/tests/script/tsim/db/alter_replica_13.sim b/tests/script/tsim/db/alter_replica_13.sim index 1d06d3abb96b101d6fdaede7a321515a9999d8c5..007bb00f075323b9ee20179ec0f5b827b0adb80f 100644 --- a/tests/script/tsim/db/alter_replica_13.sim +++ b/tests/script/tsim/db/alter_replica_13.sim @@ -127,13 +127,33 @@ if $data[0][8] != follower then goto step4 endi -print ============= step5: stop dnode 2 +print ============= step5: result +$i = 0 +while $i < 10 + $i = $i + 1 + + sleep 1000 + sql show db.vgroups + print ===> loop: $i | v0: $data03 $data04 | v1: $data05 $data06 | v2: $data07 $data08 + if $data[0][4] != leader then + return -1 + endi + if $data[0][6] != follower then + return -1 + endi + if $data[0][8] != follower then + return -1 + endi +endw + +print ============= step5: stop dnode 2 sql select * from db.stb if $rows != 1 then return -1 endi +return system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec.sh -n dnode3 -s stop -x SIGINT diff --git a/tests/script/tsim/insert/basic.sim b/tests/script/tsim/insert/basic.sim index c926cbc8b0cf2f7250d8b7ba9850ecc13cee19d4..ec8a61bb04561da2ffdf06cfdb55f483f5f13de8 100644 --- a/tests/script/tsim/insert/basic.sim +++ b/tests/script/tsim/insert/basic.sim @@ -12,14 +12,14 @@ $tb = $tbPrefix . $i print =============== step1 sql drop database -x step1 step1: -sql create database $db vgroups 2 +sql create database $db vgroups 2 precision 'ns' sql use $db sql create table $tb (ts timestamp, speed int) $x = 0 -while $x < 10 +while $x < 110 $cc = $x * 60000 - $ms = 1601481600000 + $cc + $ms = 1601481600000000000 + $cc sql insert into $tb values ($ms , $x ) $x = $x + 1 @@ -27,9 +27,9 @@ endw print =============== step 2 $x = 0 -while $x < 5 +while $x < 110 $cc = $x * 60000 - $ms = 1551481600000 + $cc + $ms = 1551481600000000000 + $cc sql insert into $tb values ($ms , $x ) $x = $x + 1 @@ -38,8 +38,29 @@ endw sql select * from $tb print $rows points data are retrieved -if $rows != 15 then +if $rows != 220 then return -1 endi +# error +print $data1 +print $data[1000][1] +print $data[1][1000] +print $data[1000][1000] +$a1 = 0 +$a2 = 0 +$a3 = $a1 % $a2 +print $a3 + +$val = \\\1 +print ====> $val + +sql_slow select * from $tb + +sql close +sql connect +sql close +sql connect root + + system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/mnode/basic5.sim b/tests/script/tsim/mnode/basic5.sim index 16e8fa3dfaf9d3b8254de7e013e2383ee17a9e01..e96b193b83732116b53c60d9b3b16e87386e8e9a 100644 --- a/tests/script/tsim/mnode/basic5.sim +++ b/tests/script/tsim/mnode/basic5.sim @@ -183,7 +183,7 @@ $x = 0 step71: $x = $x + 1 sleep 1000 - if $x == 10 then + if $x == 50 then return -1 endi sql select * from information_schema.ins_dnodes diff --git a/tests/script/tsim/parser/last_cache_query.sim b/tests/script/tsim/parser/last_cache_query.sim index f32435960cbdae77462a342d6d87f9e9a28bec65..6cd53095907584b4023816da54c198031a29491b 100644 --- a/tests/script/tsim/parser/last_cache_query.sim +++ b/tests/script/tsim/parser/last_cache_query.sim @@ -39,6 +39,7 @@ if $data02 != 5.000000000 then return -1 endi if $data03 != 3 then + print expect 3, actual: $data03 return -1 endi if $data04 != @70-01-01 07:59:57.000@ then @@ -210,7 +211,7 @@ if $data01 != 6 then return -1 endi if $data02 != 37.000000000 then - print $data02 + print expect 37.000000000 actual: $data02 return -1 endi if $data03 != 27 then @@ -233,7 +234,7 @@ if $data01 != 6 then return -1 endi if $data02 != 37.000000000 then - print $data02 + print expect 37.000000000, acutal: $data02 return -1 endi if $data03 != 27 then diff --git a/tests/script/tsim/parser/where.sim b/tests/script/tsim/parser/where.sim index e242dea8ec74e252abba30f46cc53dc18eb98872..c1660883b6189a74c38b59b95c4c4fc1fcad8a90 100644 --- a/tests/script/tsim/parser/where.sim +++ b/tests/script/tsim/parser/where.sim @@ -87,17 +87,17 @@ if $rows != 2 then return -1 endi -print $tbPrefix -$tb = $tbPrefix . 0 -if $data00 != wh_tb1 then - print expect wh_tb1, actual:$data00 - return -1 -endi -$tb = $tbPrefix . 1 -if $data10 != wh_tb0 then - print expect wh_tb0, actual:$data00 - return -1 -endi +#print $tbPrefix +#$tb = $tbPrefix . 0 +#if $data00 != wh_tb1 then +# print expect wh_tb1, actual:$data00 +# return -1 +#endi +#$tb = $tbPrefix . 1 +#if $data10 != wh_tb0 then +# print expect wh_tb0, actual:$data00 +# return -1 +#endi ## select specified columns diff --git a/tests/script/tsim/sma/tsmaCreateInsertQuery.sim b/tests/script/tsim/sma/tsmaCreateInsertQuery.sim index 2ff01263a45d7c6eeac3cf1bc553f567725fc2b5..7aef9e0f8634725c6befd3a9d8c9c2ddcbee9b30 100644 --- a/tests/script/tsim/sma/tsmaCreateInsertQuery.sim +++ b/tests/script/tsim/sma/tsmaCreateInsertQuery.sim @@ -5,7 +5,7 @@ sleep 50 sql connect print =============== create database -sql create database d1 vgroups 1 +sql create database d1 keep 36500d vgroups 1 sql use d1 print =============== create super table, include column type for count/sum/min/max/first @@ -25,8 +25,8 @@ if $rows != 1 then endi print =============== insert data, mode1: one row one table in sql -sql insert into ct1 values(now+0s, 10, 2.0, 3.0) -sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) +sql insert into ct1 values('2022-10-19 09:55:45.682', 10, 2.0, 3.0) +sql insert into ct1 values('2022-10-19 09:55:46.682', 11, 2.1, 3.1)('2022-10-19 09:55:47.682', -12, -2.2, -3.2)('2022-10-19 09:55:48.682', -13, -2.3, -3.3) print =============== create sma index from super table @@ -34,7 +34,7 @@ sql create sma index sma_index_name1 on stb function(max(c1),max(c2),min(c1)) in print $data00 $data01 $data02 $data03 print =============== trigger stream to execute sma aggr task and insert sma data into sma store -sql insert into ct1 values(now+5s, 20, 20.0, 30.0) +sql insert into ct1 values('2022-10-19 09:55:50.682', 20, 20.0, 30.0) #=================================================================== print =============== show streams ================================ diff --git a/tests/script/tsim/stable/metrics_idx.sim b/tests/script/tsim/stable/metrics_idx.sim new file mode 100644 index 0000000000000000000000000000000000000000..844d41f3a83fe729fe0b9241e2b914efeabff7b7 --- /dev/null +++ b/tests/script/tsim/stable/metrics_idx.sim @@ -0,0 +1,65 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +$dbPrefix = m_me_db_idx +$tbPrefix = m_me_tb_idx +$mtPrefix = m_me_mt_idx + +print =============== step1 +$i = 0 +$db = $dbPrefix +$mt = $mtPrefix + +sql drop database if exists $db +sql create database $db + +sql use $db + +sql create table $mt (ts timestamp, speed int) TAGS(sp int) + +$tbNum = 10000 + +while $i < $tbNum + $tb = $tbPrefix . $i + sql insert into $tb using $mt tags( $i ) values(now, $i ) + $i = $i + 1 +endw + +sql use information_schema +sql select count(*) from ins_tables where db_name = "m_me_db_idx" and create_time > now() - 10m +if $data[0][0] != $tbNum then + return -1 +endi + +sql select count(*) from ins_tables where db_name = "m_me_db_idx" and create_time < now(); +if $data[0][0] != $tbNum then + return -1 +endi + +sleep 1000 + + +sql use $db +$doubletbNum = 20000 + +while $i < $doubletbNum + $tb = $tbPrefix . $i + sql insert into $tb using $mt tags( $i ) values(now, $i ) + $i = $i + 1 +endw + + +sql use information_schema + +sql select count(*) from ins_tables where db_name = "m_me_db_idx" and create_time < now(); +if $data[0][0] != $doubletbNum then + print ==== $data[0][0] + return -1 +endi + + + + + diff --git a/tests/script/tsim/stream/basic0.sim b/tests/script/tsim/stream/basic0.sim index 6d05f69dcfc542de9b4ebb195479263db4d76881..8e3e99978b5a877bd6f2f9bb51daf9a05e50140a 100644 --- a/tests/script/tsim/stream/basic0.sim +++ b/tests/script/tsim/stream/basic0.sim @@ -1,7 +1,7 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c debugflag -v 131 -system sh/exec.sh -n dnode1 -s start -v +system sh/exec.sh -n dnode1 -s start sql connect print =============== create database diff --git a/tests/script/tsim/stream/state0.sim b/tests/script/tsim/stream/state0.sim index 60a50f95607129efcdcb406c01ca1eadf196c869..dc7d9bc40746b76ad3b34430981c86c2b75c9010 100644 --- a/tests/script/tsim/stream/state0.sim +++ b/tests/script/tsim/stream/state0.sim @@ -449,12 +449,12 @@ if $data26 != 14 then return -1 endi -sql create database test1 vgroups 1 -sql select * from information_schema.ins_databases +sql create database test1 vgroups 1; +sql select * from information_schema.ins_databases; print $data00 $data01 $data02 -sql use test1 +sql use test1; sql create table t1(ts timestamp, a int, b int , c int, d double, id int); sql create stream streams2 trigger at_once into streamt1 as select _wstart, count(*) c1, count(d) c2 , sum(a) c3 , max(a) c4, min(c) c5, max(id) c from t1 state_window(a); @@ -498,7 +498,50 @@ if $data15 != 3 then goto loop5 endi -sql drop database test; -sql drop database test1; +sql create database test3 vgroups 1; +sql use test3; + +sql create table t1(ts timestamp, a int, b int , c int, d double, id int); +sql create stream streams3 trigger at_once into streamt3 as select _wstart, count(*) c1, sum(b) c3 from t1 state_window(a); +sql insert into t1 values(1648791212000,1,2,3,1.0,1); +sql insert into t1 values(1648791213000,2,2,3,1.0,1); +sql insert into t1 values(1648791214000,3,2,4,1.0,2); +sql insert into t1 values(1648791215000,4,2,3,1.0,1); +sql insert into t1 values(1648791211000,5,2,3,1.0,1); +sql insert into t1 values(1648791210000,6,2,4,1.0,2); +sql insert into t1 values(1648791217000,7,2,3,1.0,1); +sql insert into t1 values(1648791219000,8,2,3,1.0,1); +sql insert into t1 values(1648791209000,9,2,4,1.0,2); +sql insert into t1 values(1648791220000,10,2,4,1.0,2); + +sql insert into t1 values(1648791212000,1,2,3,1.0,1); +sql insert into t1 values(1648791213000,2,2,3,1.0,1); +sql insert into t1 values(1648791214000,3,2,4,1.0,2); +sql insert into t1 values(1648791215000,4,2,3,1.0,1); +sql insert into t1 values(1648791211000,5,2,3,1.0,1); +sql insert into t1 values(1648791210000,6,2,4,1.0,2); +sql insert into t1 values(1648791217000,7,2,3,1.0,1); +sql insert into t1 values(1648791219000,8,2,3,1.0,1); +sql insert into t1 values(1648791209000,9,2,4,1.0,2); +sql insert into t1 values(1648791220000,10,2,4,1.0,2); + + +$loop_count = 0 +loop6: + +sleep 300 + +sql select * from streamt3; + +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + +if $rows != 10 then + print =====rows=$rows + goto loop6 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/stream/triggerSession0.sim b/tests/script/tsim/stream/triggerSession0.sim index 1bef4398845178be526723cdaf75863e46e3da02..4c664cf7c7b9ad8d29b0439066cefc3c130fc25e 100644 --- a/tests/script/tsim/stream/triggerSession0.sim +++ b/tests/script/tsim/stream/triggerSession0.sim @@ -5,7 +5,7 @@ sleep 50 sql connect print =============== create database -sql create database test vgroups 1 +sql create database test vgroups 1; sql select * from information_schema.ins_databases if $rows != 3 then return -1 diff --git a/tests/script/tsim/stream/windowClose.sim b/tests/script/tsim/stream/windowClose.sim index 0d435a9fbd700c2cfb0f4696a3886ca20b281299..9fcdcfb9599db5bbd2d4e93a069647a2518abaac 100644 --- a/tests/script/tsim/stream/windowClose.sim +++ b/tests/script/tsim/stream/windowClose.sim @@ -5,7 +5,7 @@ sleep 50 sql connect print =============== create database -sql create database test vgroups 1 +sql create database test vgroups 1; sql select * from information_schema.ins_databases if $rows != 3 then return -1 @@ -29,4 +29,100 @@ if $rows != 0 then return -1 endi + +sql create database test1 vgroups 4; +sql use test1; +sql create stable st(ts timestamp, a int, b int) tags(t int); +sql create table t1 using st tags(1); +sql create table t2 using st tags(2); + +sql create stream stream2 trigger window_close into streamt2 as select _wstart, sum(a) from st interval(10s); +sql create stream stream3 trigger max_delay 1s into streamt3 as select _wstart, sum(a) from st interval(10s); +sql create stream stream4 trigger window_close into streamt4 as select _wstart, sum(a) from t1 interval(10s); +sql create stream stream5 trigger max_delay 1s into streamt5 as select _wstart, sum(a) from t1 interval(10s); +sql create stream stream6 trigger window_close into streamt6 as select _wstart, sum(a) from st session(ts, 10s); +sql create stream stream7 trigger max_delay 1s into streamt7 as select _wstart, sum(a) from st session(ts, 10s); +sql create stream stream8 trigger window_close into streamt8 as select _wstart, sum(a) from t1 session(ts, 10s); +sql create stream stream9 trigger max_delay 1s into streamt9 as select _wstart, sum(a) from t1 session(ts, 10s); +sql create stream stream10 trigger window_close into streamt10 as select _wstart, sum(a) from t1 state_window(b); +sql create stream stream11 trigger max_delay 1s into streamt11 as select _wstart, sum(a) from t1 state_window(b); + +sql insert into t1 values(1648791213000,1,1); +sql insert into t1 values(1648791213001,2,1); +sql insert into t1 values(1648791213002,3,1); + +sql insert into t1 values(1648791233000,4,2); + +$loop_count = 0 + +loop1: + +sleep 200 + +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + +sql select * from streamt2; + +if $rows != 1 then + print ======streamt2=$rows + return -1 +endi + +sql select * from streamt3; +if $rows != 2 then + print ======streamt3=$rows + goto loop1 +endi + +sql select * from streamt4; +if $rows != 1 then + print ======streamt4=$rows + return -1 +endi + +sql select * from streamt5; +if $rows != 2 then + print ======streamt5=$rows + goto loop1 +endi + +sql select * from streamt6; +if $rows != 1 then + print ======streamt6=$rows + return -1 +endi + +sql select * from streamt7; +if $rows != 2 then + print ======streamt7=$rows + goto loop1 +endi + +sql select * from streamt8; +if $rows != 1 then + print ======streamt8=$rows + return -1 +endi + +sql select * from streamt9; +if $rows != 2 then + print ======streamt9=$rows + goto loop1 +endi + +sql select * from streamt10; +if $rows != 1 then + print ======streamt10=$rows + return -1 +endi + +sql select * from streamt11; +if $rows != 2 then + print ======streamt11=$rows + goto loop1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/sync/sync2-test.sim b/tests/script/tsim/sync/sync2-test.sim new file mode 100644 index 0000000000000000000000000000000000000000..4f6bf3f9f1d7e4ff0f2daf73292245e5d2603bb4 --- /dev/null +++ b/tests/script/tsim/sync/sync2-test.sim @@ -0,0 +1,175 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 + +system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 + +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start + +sql connect +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 +sql create dnode $hostname port 7400 + +$x = 0 +step1: + $x = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not ready! + return -1 + endi +sql select * from information_schema.ins_dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +print ===> $data20 $data21 $data22 $data23 $data24 $data25 +print ===> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 4 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi +if $data(3)[4] != ready then + goto step1 +endi +if $data(4)[4] != ready then + goto step1 +endi + +$replica = 3 +$vgroups = 1 + +print ============= create database +sql create database db replica $replica vgroups $vgroups + +$loop_cnt = 0 +check_db_ready: +$loop_cnt = $loop_cnt + 1 +sleep 200 +if $loop_cnt == 100 then + print ====> db not ready! + return -1 +endi +sql select * from information_schema.ins_databases +print ===> rows: $rows +print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][6] $data[2][11] $data[2][12] $data[2][13] $data[2][14] $data[2][15] $data[2][16] $data[2][17] $data[2][18] $data[2][19] +if $rows != 3 then + return -1 +endi +if $data[2][15] != ready then + goto check_db_ready +endi + +sql use db + +$loop_cnt = 0 +check_vg_ready: +$loop_cnt = $loop_cnt + 1 +sleep 200 +if $loop_cnt == 300 then + print ====> vgroups not ready! + return -1 +endi + +sql show vgroups +print ===> rows: $rows +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][10] $data[0][11] + +if $rows != $vgroups then + return -1 +endi + +if $data[0][4] == leader then + if $data[0][6] == follower then + if $data[0][8] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][3] + endi + endi +elif $data[0][6] == leader then + if $data[0][4] == follower then + if $data[0][8] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][5] + endi + endi +elif $data[0][8] == leader then + if $data[0][4] == follower then + if $data[0][6] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][7] + endi + endi +else + goto check_vg_ready +endi + + + + + +#return 0 + + + + + +vg_ready: +print ====> create stable/child table +sql create table stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int) + + + + +#return 0 + + + +sql show stables +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb tags(1000) + + + + + + + + +print ====> step1 insert 1000 records +$N = 1000 +$count = 0 +while $count < $N + $ms = 1591200000000 + $count + sql insert into ct1 values( $ms , $count , 2.1, 3.1) + $count = $count + 1 +endw + +print ====> step2 sleep 20s, checking data +sleep 20000 + + +print ====> step3 sleep 30s, kill leader +sleep 30000 + +print ====> step4 insert 1000 records +$N = 1000 +$count = 0 +while $count < $N + $ms = 1591201000000 + $count + sql insert into ct1 values( $ms , $count , 2.1, 3.1) + $count = $count + 1 +endw + +print ====> step5 sleep 20s, checking data +sleep 20000 + diff --git a/tests/script/tsim/tag/drop_tag.sim b/tests/script/tsim/tag/drop_tag.sim new file mode 100644 index 0000000000000000000000000000000000000000..03892039f92dfdd74fda175ea942dfa752ba6c2a --- /dev/null +++ b/tests/script/tsim/tag/drop_tag.sim @@ -0,0 +1,84 @@ + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + + +$dbPrefix = ta_bib_db +$tbPrefix = ta_bib_tb +$mtPrefix = ta_bib_mt +$tbNum = 10 +$rowNum = 20 +$totalNum = 200 + +print =============== step1 +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +sql drop database if exists $db + +sql create database $db vgroups 1 +sql use $db + +print ======== test bigint +sql create table if not exists st( ts timestamp, order_id bigint) tags (account_id bigint) + +sql create table t1 using st tags(111) +sql create table t2 using st tags(222) + +sql insert into t1(ts, order_id) values(1648791213001, 1) +sql insert into t2(ts, order_id) values(1648791213002, 2) +sql select account_id,count(*) from st where account_id = 111 group by account_id + +sql drop table t1 + +sql create table t1 using st tags(111) + +sql insert into t1(ts, order_id) values(1648791213001, 1) +sql insert into t2(ts, order_id) values(1648791213002, 2) + +sql select account_id,count(*) from st where account_id = 111 group by account_id + +if $rows != 1 then + return -1 +endi + +print ======== test varchar + +sql drop stable st + +sql create table if not exists st( ts timestamp, order_id bigint) tags (account_id binary(16)) + +sql create table t1 using st tags("aac") +sql create table t2 using st tags("abc") + +sql insert into t1(ts, order_id) values(1648791213001, 1) +sql insert into t2(ts, order_id) values(1648791213002, 2) +sql select account_id,count(*) from st where account_id = "aac" group by account_id + +sql drop table t1 + +sql create table t1 using st tags("aac") + +sql insert into t1(ts, order_id) values(1648791213001, 1) +sql insert into t2(ts, order_id) values(1648791213002, 2) + +sql select account_id,count(*) from st where account_id = "aac" group by account_id + +if $rows != 1 then + return -1 +endi + +print ====== test empty table +sql drop table t1 + +sql select account_id,count(*) from st where account_id = "aac" group by account_id +if $rows != 0 then + return -1 +endi + + +sql drop database $db + diff --git a/tests/system-test/0-others/compatibility.py b/tests/system-test/0-others/compatibility.py index 25b023bb76e9e9f34f288624a5f33daeca78d717..e81579a9e4ca3f2f72b9aff3892f1ed2878855a1 100644 --- a/tests/system-test/0-others/compatibility.py +++ b/tests/system-test/0-others/compatibility.py @@ -81,6 +81,7 @@ class TDTestCase: dbname = "test" stb = f"{dbname}.meters" self.installTaosd(bPath,cPath) + os.system("echo 'debugFlag 143' > /etc/taos/taos.cfg ") tableNumbers=100 recordNumbers1=100 recordNumbers2=1000 @@ -96,8 +97,8 @@ class TDTestCase: tdLog.info(f"Base client version is {oldClientVersion}") tdLog.printNoPrefix(f"==========step1:prepare and check data in old version-{oldServerVersion}") - tdLog.info(f"taosBenchmark -t {tableNumbers} -n {recordNumbers1} -y ") - os.system(f"taosBenchmark -t {tableNumbers} -n {recordNumbers1} -y ") + tdLog.info(f" LD_LIBRARY_PATH=/usr/lib taosBenchmark -t {tableNumbers} -n {recordNumbers1} -y ") + os.system(f"LD_LIBRARY_PATH=/usr/lib taosBenchmark -t {tableNumbers} -n {recordNumbers1} -y ") sleep(3) # tdsqlF.query(f"select count(*) from {stb}") diff --git a/tests/system-test/0-others/taosdMonitor.py b/tests/system-test/0-others/taosdMonitor.py index 1d733191b72249f426f836a8115e28a7283bbb32..96e057c9f815b19a20ef98b87d58c3ec7fdfe51d 100644 --- a/tests/system-test/0-others/taosdMonitor.py +++ b/tests/system-test/0-others/taosdMonitor.py @@ -94,7 +94,7 @@ class RequestHandlerImpl(http.server.BaseHTTPRequestHandler): tdLog.exit("vgroup_id is null!") if "database_name" not in infoDict["vgroup_infos"][index] or len(infoDict["vgroup_infos"][index]["database_name"]) < 0: tdLog.exit("database_name is null!") - if "tables_num" not in infoDict["vgroup_infos"][index] or infoDict["vgroup_infos"][index]["tables_num"]!= 0: + if "tables_num" not in infoDict["vgroup_infos"][index]: tdLog.exit("tables_num is null!") if "status" not in infoDict["vgroup_infos"][index] or len(infoDict["vgroup_infos"][index]["status"]) < 0 : tdLog.exit("status is null!") @@ -294,6 +294,10 @@ class TDTestCase: vgroups = "30" sql = "create database db3 vgroups " + vgroups tdSql.query(sql) + sql = "create table db3.stb (ts timestamp, f int) tags (t int)" + tdSql.query(sql) + sql = "create table db3.tb using db3.stb tags (1)" + tdSql.query(sql) # create http server: bing ip/port , and request processor if (platform.system().lower() == 'windows' and not tdDnodes.dnodes[0].remoteIP == ""): diff --git a/tests/system-test/0-others/taosdShell.py b/tests/system-test/0-others/taosdShell.py new file mode 100644 index 0000000000000000000000000000000000000000..6d62420efec4bebd89e8656b2e966dac861318e3 --- /dev/null +++ b/tests/system-test/0-others/taosdShell.py @@ -0,0 +1,185 @@ + +import taos +import sys +import time +import socket +import os +import platform +if platform.system().lower() == 'windows': + import wexpect as taosExpect +else: + import pexpect as taosExpect + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + +class TDTestCase: + #updatecfgDict = {'clientCfg': {'serverPort': 7080, 'firstEp': 'trd02:7080', 'secondEp':'trd02:7080'},\ + # 'serverPort': 7080, 'firstEp': 'trd02:7080'} + # hostname = socket.gethostname() + # if (platform.system().lower() == 'windows' and not tdDnodes.dnodes[0].remoteIP == ""): + # try: + # config = eval(tdDnodes.dnodes[0].remoteIP) + # hostname = config["host"] + # except Exception: + # hostname = tdDnodes.dnodes[0].remoteIP + # serverPort = '7080' + # rpcDebugFlagVal = '143' + # clientCfgDict = {'serverPort': '', 'firstEp': '', 'secondEp':'', 'rpcDebugFlag':'135', 'fqdn':''} + # clientCfgDict["serverPort"] = serverPort + # clientCfgDict["firstEp"] = hostname + ':' + serverPort + # clientCfgDict["secondEp"] = hostname + ':' + serverPort + # clientCfgDict["rpcDebugFlag"] = rpcDebugFlagVal + # clientCfgDict["fqdn"] = hostname + + # updatecfgDict = {'clientCfg': {}, 'serverPort': '', 'firstEp': '', 'secondEp':'', 'rpcDebugFlag':'135', 'fqdn':''} + # updatecfgDict["clientCfg"] = clientCfgDict + # updatecfgDict["serverPort"] = serverPort + # updatecfgDict["firstEp"] = hostname + ':' + serverPort + # updatecfgDict["secondEp"] = hostname + ':' + serverPort + # updatecfgDict["fqdn"] = hostname + + # print ("===================: ", updatecfgDict) + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + 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 or "taosd.exe" 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 get_process_pid(self,processname): + #origin artical link:https://blog.csdn.net/weixin_45623536/article/details/122099062 + process_info_list = [] + process = os.popen('ps -A | grep %s'% processname) + process_info = process.read() + for i in process_info.split(' '): + if i != "": + process_info_list.append(i) + print(process_info_list) + if len(process_info_list) != 0 : + pid = int(process_info_list[0]) + else : + pid = 0 + return pid + + def checkAndstopPro(self,processName,startAction): + i = 1 + count = 10 + for i in range(count): + taosdPid=self.get_process_pid(processName) + if taosdPid != 0 and taosdPid != "" : + tdLog.info("stop taosd %s ,kill pid :%s "%(startAction,taosdPid)) + os.system("kill -9 %d"%taosdPid) + break + else: + tdLog.info( "wait start taosd ,times: %d "%i) + sleep + i+= 1 + else : + tdLog.exit("taosd %s is not running "%startAction) + + def taosdCommandStop(self,startAction,taosdCmdRun): + processName="taosd" + taosdCmd = taosdCmdRun + startAction + tdLog.printNoPrefix("%s"%taosdCmd) + os.system(f"nohup {taosdCmd} & ") + self.checkAndstopPro(processName,startAction) + + def taosdCommandExe(self,startAction,taosdCmdRun): + taosdCmd = taosdCmdRun + startAction + tdLog.printNoPrefix("%s"%taosdCmd) + os.system(f"{taosdCmd}") + + def run(self): + tdSql.prepare() + # time.sleep(2) + tdSql.query("create user testpy pass 'testpy'") + + #hostname = socket.gethostname() + #tdLog.info ("hostname: %s" % hostname) + + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + cfgPath = buildPath + "/../sim/psim/cfg" + taosdCfgPath = buildPath + "/../sim/dnode1/cfg" + + + taosdCmdRun= buildPath + '/build/bin/taosd' + tdLog.info("cfgPath: %s" % cfgPath) + # keyDict['h'] = self.hostname + # keyDict['c'] = cfgPath + # keyDict['P'] = self.serverPort + tdDnodes.stop(1) + + startAction = " --help" + tdLog.printNoPrefix("================================ parameter: %s"%startAction) + self.taosdCommandExe(startAction,taosdCmdRun) + + startAction = " -h" + tdLog.printNoPrefix("================================ parameter: %s"%startAction) + self.taosdCommandExe(startAction,taosdCmdRun) + + startAction=" -a jsonFile:./taosdCaseTmp.json" + tdLog.printNoPrefix("================================ parameter: %s"%startAction) + os.system("echo \'{\"queryPolicy\":\"3\"}\' > taosdCaseTmp.json") + self.taosdCommandStop(startAction,taosdCmdRun) + + startAction = " -a jsonFile:./taosdCaseTmp.json -C " + tdLog.printNoPrefix("================================ parameter: %s"%startAction) + self.taosdCommandExe(startAction,taosdCmdRun) + + os.system("rm -rf taosdCaseTmp.json") + + startAction = " -c " + taosdCfgPath + tdLog.printNoPrefix("================================ parameter: %s"%startAction) + self.taosdCommandStop(startAction,taosdCmdRun) + + startAction = " -s" + tdLog.printNoPrefix("================================ parameter: %s"%startAction) + self.taosdCommandExe(startAction,taosdCmdRun) + + startAction = " -e TAOS_QUERY_POLICY=2 " + tdLog.printNoPrefix("================================ parameter: %s"%startAction) + self.taosdCommandStop(startAction,taosdCmdRun) + + + startAction=" -E taosdCaseTmp/.env" + tdLog.printNoPrefix("================================ parameter: %s"%startAction) + os.system(" mkdir -p taosdCaseTmp/.env ") + os.system("echo \'TAOS_QUERY_POLICY=3\' > taosdCaseTmp/.env ") + self.taosdCommandStop(startAction,taosdCmdRun) + os.system(" rm -rf taosdCaseTmp/.env ") + + startAction = " -V" + tdLog.printNoPrefix("================================ parameter: %s"%startAction) + self.taosdCommandExe(startAction,taosdCmdRun) + + startAction = " -k" + tdLog.printNoPrefix("================================ parameter: %s"%startAction) + self.taosdCommandExe(startAction,taosdCmdRun) + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/Today.py b/tests/system-test/2-query/Today.py index 6887e7397034b2f99ad581a1fde412bca87c8007..0124c5bbac937f46e78096cc3a55f873a80ad15b 100644 --- a/tests/system-test/2-query/Today.py +++ b/tests/system-test/2-query/Today.py @@ -43,7 +43,13 @@ class TDTestCase: f'today(),3,3.333,333.333333,now()', f'today()-1d,10,11.11,99.999999,now()', f'today()+1d,1,1.55,100.555555,today()'] - self.db_percision = ['ms','us','ns'] + + self.rest_tag = str(conn).lower().split('.')[0].replace("0: - # print(("=====matrix===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - tdLog.info(("===matrix===sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) - elif (set(list2)).issubset(set(list1)): - # 解决不同子表排列结果乱序 - # print(("=====list_issubset==matrix2in1-true===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - tdLog.info(("===matrix_issubset===sql1:'%s' matrix_set_result = sql2:'%s' matrix_set_result") %(sql1,sql2)) - #elif abs(float(str(list1).replace("]","").replace("[","").replace("e+","")) - float(str(list2).replace("]","").replace("[","").replace("e+",""))) <= 0.0001: - elif abs(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-","")) - float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-",""))) <= 0.0001: - print(("=====matrix_abs+e+===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - print(("=====matrix_abs+e+replace_after===sql1.list1:'%s',sql2.list2:'%s'") %(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-","")),float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-","")))) - tdLog.info(("===matrix_abs+e+===sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) - elif abs(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")) - float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-",""))) <= 0.1: - #{datetime.datetime(2021, 8, 27, 1, 46, 40), -441.46841430664057}replace - print(("=====matrix_abs+replace===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - print(("=====matrix_abs+replace_after===sql1.list1:'%s',sql2.list2:'%s'") %(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")),float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")))) - tdLog.info(("===matrix_abs+replace===sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) - elif abs(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")) - float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-",""))) <= 0.5: - print(("=====matrix_abs===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - print(("=====matrix_abs===sql1.list1:'%s',sql2.list2:'%s'") %(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")),float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")))) - tdLog.info(("===matrix_abs======sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) - else: - print(("=====matrix_error===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - tdLog.info(("sql1:'%s' matrix_result != sql2:'%s' matrix_result") %(sql1,sql2)) - return tdSql.checkEqual(list1,list2) - - def restartDnodes(self): - pass - # tdDnodes.stop(1) - # tdDnodes.start(1) - - def dropandcreateDB_random(self,database,n): - ts = 1630000000000 - num_random = 100 - fake = Faker('zh_CN') - tdSql.execute('''drop database if exists %s ;''' %database) - tdSql.execute('''create database %s keep 36500;'''%database) - tdSql.execute('''use %s;'''%database) - - tdSql.execute('''create stable stable_1 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ - tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') - tdSql.execute('''create stable stable_2 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ - tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') - - tdSql.execute('''create stable stable_null_data (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ - tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') - - tdSql.execute('''create stable stable_null_childtable (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ - tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') - - #tdSql.execute('''create table stable_1_1 using stable_1 tags('stable_1_1', '0' , '0' , '0' , '0' , 0 , 'binary1' , 'nchar1' , '0' , '0' ,'0') ;''') - tdSql.execute('''create table stable_1_1 using stable_1 tags('stable_1_1', '%d' , '%d', '%d' , '%d' , 0 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' - %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) - tdSql.execute('''create table stable_1_2 using stable_1 tags('stable_1_2', '2147483647' , '9223372036854775807' , '32767' , '127' , 1 , 'binary2' , 'nchar2' , '2' , '22' , \'1999-09-09 09:09:09.090\') ;''') - tdSql.execute('''create table stable_1_3 using stable_1 tags('stable_1_3', '-2147483647' , '-9223372036854775807' , '-32767' , '-127' , false , 'binary3' , 'nchar3nchar3' , '-3.3' , '-33.33' , \'2099-09-09 09:09:09.090\') ;''') - #tdSql.execute('''create table stable_1_4 using stable_1 tags('stable_1_4', '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') - tdSql.execute('''create table stable_1_4 using stable_1 tags('stable_1_4', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' - %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) - - # tdSql.execute('''create table stable_2_1 using stable_2 tags('stable_2_1' , '0' , '0' , '0' , '0' , 0 , 'binary21' , 'nchar21' , '0' , '0' ,'0') ;''') - # tdSql.execute('''create table stable_2_2 using stable_2 tags('stable_2_2' , '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') - - # tdSql.execute('''create table stable_null_data_1 using stable_null_data tags('stable_null_data_1', '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') - - tdSql.execute('''create table stable_2_1 using stable_2 tags('stable_2_1' , '0' , '0' , '0' , '0' , 0 , 'binary21' , 'nchar21' , '0' , '0' ,\'2099-09-09 09:09:09.090\') ;''') - tdSql.execute('''create table stable_2_2 using stable_2 tags('stable_2_2' , '%d' , '%d', '%d' , '%d' , 0 , 'binary2.%s' , 'nchar2.%s' , '%f', '%f' ,'%d') ;''' - %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) - - tdSql.execute('''create table stable_null_data_1 using stable_null_data tags('stable_null_data_1', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' - %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) - - #regular table - tdSql.execute('''create table regular_table_1 \ - (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') - tdSql.execute('''create table regular_table_2 \ - (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') - tdSql.execute('''create table regular_table_3 \ - (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') - - tdSql.execute('''create table regular_table_null \ - (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') - - - for i in range(num_random*n): - tdSql.execute('''insert into stable_1_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d) ;''' - % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1), - fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i)) - tdSql.execute('''insert into regular_table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d) ;''' - % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1) , - fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1) , - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i)) - - tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' - % (ts + i*1000, fake.random_int(min=0, max=2147483647, step=1), - fake.random_int(min=0, max=9223372036854775807, step=1), - fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i)) - tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' - % (ts + i*1000, fake.random_int(min=0, max=2147483647, step=1), - fake.random_int(min=0, max=9223372036854775807, step=1), - fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i)) - - tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' - % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), - fake.random_int(min=-9223372036854775807, max=0, step=1), - fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i +1)) - tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' - % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), - fake.random_int(min=-9223372036854775807, max=0, step=1), - fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i +1)) - - tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d) ;''' - % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1), - fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i)) - - # tdSql.execute('''insert into regular_table_3 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d)''' - # % (ts + i*1000, fake.random_int(min=-2147483647, max=0, step=1), - # fake.random_int(min=-9223372036854775807, max=0, step=1), - # fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , - # fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i)) - - tdSql.query("select count(*) from stable_1;") - tdSql.checkData(0,0,3*num_random*n) - tdSql.query("select count(*) from regular_table_1;") - tdSql.checkData(0,0,num_random*n) - - - def run(self): - tdSql.prepare() - os.system("rm -rf nestedQuery3.py.sql") - - startTime = time.time() - - db = "nest" - self.dropandcreateDB_random("%s" %db, 1) - + self.fornum = 15 + + self.db_nest = "nest" + self.dropandcreateDB_random("%s" %self.db_nest, 1) + # regular column select - q_select= ['ts' , '*' , 'q_int', 'q_bigint' , 'q_bigint' , 'q_smallint' , 'q_tinyint' , 'q_bool' , 'q_binary' , 'q_nchar' ,'q_float' , 'q_double' ,'q_ts '] - q_select= ['ts' , 'q_int', 'q_bigint' , 'q_bigint' , 'q_smallint' , 'q_tinyint' , 'q_bool' , 'q_binary' , 'q_nchar' ,'q_float' , 'q_double' ,'q_ts ', 'q_int_null ', 'q_bigint_null ' , 'q_bigint_null ' , 'q_smallint_null ' , 'q_tinyint_null ' , 'q_bool_null ' , 'q_binary_null ' , 'q_nchar_null ' ,'q_float_null ' , 'q_double_null ' ,'q_ts_null '] + #q_select= ['ts' , '*' , 'q_int', 'q_bigint' , 'q_bigint' , 'q_smallint' , 'q_tinyint' , 'q_bool' , 'q_binary' , 'q_nchar' ,'q_float' , 'q_double' ,'q_ts '] + self.q_select= ['q_int', 'q_bigint' , 'q_bigint' , 'q_smallint' , 'q_tinyint' , 'q_bool' , 'q_binary' , 'q_nchar' ,'q_float' , 'q_double' ,'q_ts ', 'q_int_null ', 'q_bigint_null ' , 'q_bigint_null ' , 'q_smallint_null ' , 'q_tinyint_null ' , 'q_bool_null ' , 'q_binary_null ' , 'q_nchar_null ' ,'q_float_null ' , 'q_double_null ' ,'q_ts_null '] # tag column select - t_select= ['*' , 'loc' ,'t_int', 't_bigint' , 't_bigint' , 't_smallint' , 't_tinyint' , 't_bool' , 't_binary' , 't_nchar' ,'t_float' , 't_double' ,'t_ts '] - t_select= ['loc' ,'tbname','t_int', 't_bigint' , 't_bigint' , 't_smallint' , 't_tinyint' , 't_bool' , 't_binary' , 't_nchar' ,'t_float' , 't_double' ,'t_ts '] + #t_select= ['*' , 'loc' ,'t_int', 't_bigint' , 't_bigint' , 't_smallint' , 't_tinyint' , 't_bool' , 't_binary' , 't_nchar' ,'t_float' , 't_double' ,'t_ts '] + self.t_select= ['loc','t_int', 't_bigint' , 't_bigint' , 't_smallint' , 't_tinyint' , 't_bool' , 't_binary' , 't_nchar' ,'t_float' , 't_double' ,'t_ts '] # regular and tag column select - qt_select= q_select + t_select + self.qt_select= self.q_select + self.t_select # distinct regular column select - dq_select= ['distinct q_int', 'distinct q_bigint' , 'distinct q_smallint' , 'distinct q_tinyint' , + self.dq_select= ['distinct q_int', 'distinct q_bigint' , 'distinct q_smallint' , 'distinct q_tinyint' , 'distinct q_bool' , 'distinct q_binary' , 'distinct q_nchar' ,'distinct q_float' , 'distinct q_double' ,'distinct q_ts '] # distinct tag column select - dt_select= ['distinct loc', 'distinct t_int', 'distinct t_bigint' , 'distinct t_smallint' , 'distinct t_tinyint' , + self.dt_select= ['distinct loc', 'distinct t_int', 'distinct t_bigint' , 'distinct t_smallint' , 'distinct t_tinyint' , 'distinct t_bool' , 'distinct t_binary' , 'distinct t_nchar' ,'distinct t_float' , 'distinct t_double' ,'distinct t_ts '] # distinct regular and tag column select - dqt_select= dq_select + dt_select + self.dqt_select= self.dq_select + self.dt_select # special column select - s_r_select= ['_c0', '_rowts' , '_C0' ] - s_s_select= ['tbname' , '_rowts' , '_c0', '_C0' ] - unionall_or_union= [ ' union ' , ' union all ' ] - - # regular column where - q_where = ['ts < now +1s','q_bigint >= -9223372036854775807 and q_bigint <= 9223372036854775807', 'q_int <= 2147483647 and q_int >= -2147483647', - 'q_smallint >= -32767 and q_smallint <= 32767','q_tinyint >= -127 and q_tinyint <= 127','q_float >= -1.7E308 and q_float <= 1.7E308', - 'q_double >= -1.7E308 and q_double <= 1.7E308', 'q_binary like \'binary%\' or q_binary = \'0\' ' , 'q_nchar like \'nchar%\' or q_nchar = \'0\' ' , + self.s_r_select= ['_c0', '_rowts' , '_C0' ] + self.s_s_select= ['tbname' , '_rowts' , '_c0', '_C0' ] + self.unionall_or_union= [ ' union ' , ' union all ' ] + + # regular column where + self.q_where = ['ts < now +1s','q_bigint >= -9223372036854775807 and q_bigint <= 9223372036854775807', 'q_int <= 2147483647 and q_int >= -2147483647', + 'q_smallint >= -32767 and q_smallint <= 32767','q_tinyint >= -127 and q_tinyint <= 127','q_float >= -1.7E308 and q_float <= 1.7E308', + 'q_double >= -1.7E308 and q_double <= 1.7E308', 'q_binary like \'binary%\' or q_binary = \'0\' ' , 'q_nchar like \'nchar%\' or q_nchar = \'0\' ' , 'q_bool = true or q_bool = false' , 'q_bool in (0 , 1)' , 'q_bool in ( true , false)' , 'q_bool = 0 or q_bool = 1', - 'q_bigint between -9223372036854775807 and 9223372036854775807',' q_int between -2147483647 and 2147483647','q_smallint between -32767 and 32767', + 'q_bigint between -9223372036854775807 and 9223372036854775807',' q_int between -2147483647 and 2147483647','q_smallint between -32767 and 32767', + 'q_bigint not between 9223372036854775807 and -9223372036854775807','q_int not between 2147483647 and -2147483647','q_smallint not between 32767 and -32767', 'q_tinyint between -127 and 127 ','q_float >= -3.4E38 ','q_float <= 3.4E38 ','q_double >= -1.7E308 ', - 'q_double <= 1.7E308 ','q_float between -3.4E38 and 3.4E38 ','q_double between -1.7E308 and 1.7E308 ' , - 'q_float is not null ' ,'q_double is not null ' ,] + 'q_double <= 1.7E308 ','q_float between -3.4E38 and 3.4E38 ','q_double between -1.7E308 and 1.7E308 ' ,'q_float not between 3.4E38 and -3.4E38 ','q_double not between 1.7E308 and -1.7E308 ', + 'q_float is not null ' ,'q_double is not null ' ,'q_binary match \'binary\' ','q_binary nmatch \'binarynchar\' ','q_nchar match \'nchar\' ','q_nchar nmatch \'binarynchar\' ', + 'q_binary like \'binary%\' ','(q_binary like \'binary%\' or q_nchar = \'0\' or q_binary = \'binary_\' ) ','q_nchar like \'nchar%\' ','(q_nchar like \'nchar%\' or q_binary = \'0\' or q_nchar = \'nchar_\' ) ',] #TD-6201 ,'q_bool between 0 and 1' # regular column where for test union,join - q_u_where = ['t1.ts < now +1s' , 't2.ts < now +1s','t1.q_bigint >= -9223372036854775807 and t1.q_bigint <= 9223372036854775807 and t2.q_bigint >= -9223372036854775807 and t2.q_bigint <= 9223372036854775807', + self.q_u_where = ['t1.ts < now +1s' , 't2.ts < now +1s','t1.q_bigint >= -9223372036854775807 and t1.q_bigint <= 9223372036854775807 and t2.q_bigint >= -9223372036854775807 and t2.q_bigint <= 9223372036854775807', 't1.q_int <= 2147483647 and t1.q_int >= -2147483647 and t2.q_int <= 2147483647 and t2.q_int >= -2147483647', 't1.q_smallint >= -32767 and t1.q_smallint <= 32767 and t2.q_smallint >= -32767 and t2.q_smallint <= 32767', 't1.q_tinyint >= -127 and t1.q_tinyint <= 127 and t2.q_tinyint >= -127 and t2.q_tinyint <= 127', 't1.q_float >= - 1.7E308 and t1.q_float <= 1.7E308 and t2.q_float >= - 1.7E308 and t2.q_float <= 1.7E308', - 't1.q_double >= - 1.7E308 and t1.q_double <= 1.7E308 and t2.q_double >= - 1.7E308 and t2.q_double <= 1.7E308', - 't1.q_binary like \'binary%\' and t2.q_binary like \'binary%\' ' , - 't1.q_nchar like \'nchar%\' and t2.q_nchar like \'nchar%\' ' , - 't1.q_bool in (0 , 1) and t2.q_bool in (0 , 1)' , 't1.q_bool in ( true , false) and t2.q_bool in ( true , false)' , + 't1.q_double >= - 1.7E308 and t1.q_double <= 1.7E308 and t2.q_double >= - 1.7E308 and t2.q_double <= 1.7E308', + 't1.q_binary like \'binary%\' and t2.q_binary like \'binary%\' ' , + 't1.q_nchar like \'nchar%\' and t2.q_nchar like \'nchar%\' ' , + 't1.q_bool in (0 , 1) and t2.q_bool in (0 , 1)' , 't1.q_bool in ( true , false) and t2.q_bool in ( true , false)' , 't1.q_bigint between -9223372036854775807 and 9223372036854775807 and t2.q_bigint between -9223372036854775807 and 9223372036854775807', 't1.q_int between -2147483647 and 2147483647 and t2.q_int between -2147483647 and 2147483647', - 't1.q_smallint between -32767 and 32767 and t2.q_smallint between -32767 and 32767', + 't1.q_smallint between -32767 and 32767 and t2.q_smallint between -32767 and 32767', 't1.q_tinyint between -127 and 127 and t2.q_tinyint between -127 and 127 ','t1.q_float between -1.7E308 and 1.7E308 and t2.q_float between -1.7E308 and 1.7E308', - 't1.q_double between -1.7E308 and 1.7E308 and t2.q_double between -1.7E308 and 1.7E308'] + 't1.q_double between -1.7E308 and 1.7E308 and t2.q_double between -1.7E308 and 1.7E308', + 't1.q_bigint not between 9223372036854775807 and -9223372036854775807 and t2.q_bigint not between 9223372036854775807 and -9223372036854775807', + 't1.q_int not between 2147483647 and -2147483647 and t2.q_int not between 2147483647 and -2147483647', + 't1.q_smallint not between 32767 and -32767 and t2.q_smallint not between 32767 and -32767', + 't1.q_tinyint not between 127 and -127 and t2.q_tinyint not between 127 and -127 ','t1.q_float not between -1.7E308 and -1.7E308 and t2.q_float not between 1.7E308 and -1.7E308', + 't1.q_double not between 1.7E308 and -1.7E308 and t2.q_double not between 1.7E308 and -1.7E308'] #TD-6201 ,'t1.q_bool between 0 and 1 or t2.q_bool between 0 and 1'] #'t1.q_bool = true and t1.q_bool = false and t2.q_bool = true and t2.q_bool = false' , 't1.q_bool = 0 and t1.q_bool = 1 and t2.q_bool = 0 and t2.q_bool = 1' , - q_u_or_where = ['(t1.q_binary like \'binary%\' or t1.q_binary = \'0\' or t2.q_binary like \'binary%\' or t2.q_binary = \'0\' )' , - '(t1.q_nchar like \'nchar%\' or t1.q_nchar = \'0\' or t2.q_nchar like \'nchar%\' or t2.q_nchar = \'0\' )' , '(t1.q_bool = true or t1.q_bool = false or t2.q_bool = true or t2.q_bool = false)' , + self.q_u_or_where = ['(t1.q_binary like \'binary%\' or t1.q_binary = \'0\' or t2.q_binary like \'binary%\' or t2.q_binary = \'0\' )' , + '(t1.q_nchar like \'nchar%\' or t1.q_nchar = \'0\' or t2.q_nchar like \'nchar%\' or t2.q_nchar = \'0\' )' , '(t1.q_bool = true or t1.q_bool = false or t2.q_bool = true or t2.q_bool = false)' , '(t1.q_bool in (0 , 1) or t2.q_bool in (0 , 1))' , '(t1.q_bool in ( true , false) or t2.q_bool in ( true , false))' , '(t1.q_bool = 0 or t1.q_bool = 1 or t2.q_bool = 0 or t2.q_bool = 1)' , '(t1.q_bigint between -9223372036854775807 and 9223372036854775807 or t2.q_bigint between -9223372036854775807 and 9223372036854775807)', '(t1.q_int between -2147483647 and 2147483647 or t2.q_int between -2147483647 and 2147483647)', - '(t1.q_smallint between -32767 and 32767 or t2.q_smallint between -32767 and 32767)', + '(t1.q_smallint between -32767 and 32767 or t2.q_smallint between -32767 and 32767)', '(t1.q_tinyint between -127 and 127 or t2.q_tinyint between -127 and 127 )','(t1.q_float between -1.7E308 and 1.7E308 or t2.q_float between -1.7E308 and 1.7E308)', '(t1.q_double between -1.7E308 and 1.7E308 or t2.q_double between -1.7E308 and 1.7E308)'] # tag column where - t_where = ['ts < now +1s','t_bigint >= -9223372036854775807 and t_bigint <= 9223372036854775807','t_int <= 2147483647 and t_int >= -2147483647', + self.t_where = ['ts < now +1s','t_bigint >= -9223372036854775807 and t_bigint <= 9223372036854775807','t_int <= 2147483647 and t_int >= -2147483647', 't_smallint >= -32767 and t_smallint <= 32767','q_tinyint >= -127 and t_tinyint <= 127','t_float >= -1.7E308 and t_float <= 1.7E308', - 't_double >= -1.7E308 and t_double <= 1.7E308', 't_binary like \'binary%\' or t_binary = \'0\' ' , 't_nchar like \'nchar%\' or t_nchar = \'0\'' , + 't_double >= -1.7E308 and t_double <= 1.7E308', 't_binary like \'binary%\' or t_binary = \'0\' ' , 't_nchar like \'nchar%\' or t_nchar = \'0\'' , 't_bool = true or t_bool = false' , 't_bool in (0 , 1)' , 't_bool in ( true , false)' , 't_bool = 0 or t_bool = 1', - 't_bigint between -9223372036854775807 and 9223372036854775807',' t_int between -2147483647 and 2147483647','t_smallint between -32767 and 32767', - 't_tinyint between -127 and 127 ','t_float between -1.7E308 and 1.7E308','t_double between -1.7E308 and 1.7E308'] + 't_bigint between -9223372036854775807 and 9223372036854775807',' t_int between -2147483647 and 2147483647','t_smallint between -32767 and 32767', + 't_tinyint between -127 and 127 ','t_float between -1.7E308 and 1.7E308','t_double between -1.7E308 and 1.7E308', + 't_binary match \'binary\' ','t_binary nmatch \'binarynchar\' ','t_nchar match \'nchar\' ','t_nchar nmatch \'binarynchar\' ', + 't_binary like \'binary%\' ','t_nchar like \'nchar%\' ','(t_binary like \'binary%\' or t_nchar = \'0\' ) ','(t_nchar like \'nchar%\' or t_binary = \'0\' ) ',] #TD-6201,'t_bool between 0 and 1' # tag column where for test union,join | this is not support - t_u_where = ['t1.ts < now +1s' , 't2.ts < now +1s','t1.t_bigint >= -9223372036854775807 and t1.t_bigint <= 9223372036854775807 and t2.t_bigint >= -9223372036854775807 and t2.t_bigint <= 9223372036854775807', + self.t_u_where = ['t1.ts < now +1s' , 't2.ts < now +1s','t1.t_bigint >= -9223372036854775807 and t1.t_bigint <= 9223372036854775807 and t2.t_bigint >= -9223372036854775807 and t2.t_bigint <= 9223372036854775807', 't1.t_int <= 2147483647 and t1.t_int >= -2147483647 and t2.t_int <= 2147483647 and t2.t_int >= -2147483647', 't1.t_smallint >= -32767 and t1.t_smallint <= 32767 and t2.t_smallint >= -32767 and t2.t_smallint <= 32767', 't1.t_tinyint >= -127 and t1.t_tinyint <= 127 and t2.t_tinyint >= -127 and t2.t_tinyint <= 127', 't1.t_float >= -1.7E308 and t1.t_float <= 1.7E308 and t2.t_float >= -1.7E308 and t2.t_float <= 1.7E308', - 't1.t_double >= -1.7E308 and t1.t_double <= 1.7E308 and t2.t_double >= -1.7E308 and t2.t_double <= 1.7E308', - '(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\') ' , - '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , + 't1.t_double >= -1.7E308 and t1.t_double <= 1.7E308 and t2.t_double >= -1.7E308 and t2.t_double <= 1.7E308', + '(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\') ' , + '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , 't1.t_bool in (0 , 1) and t2.t_bool in (0 , 1)' , 't1.t_bool in ( true , false) and t2.t_bool in ( true , false)' , '(t1.t_bool = 0 or t1.t_bool = 1 or t2.t_bool = 0 or t2.t_bool = 1)', 't1.t_bigint between -9223372036854775807 and 9223372036854775807 and t2.t_bigint between -9223372036854775807 and 9223372036854775807', 't1.t_int between -2147483647 and 2147483647 and t2.t_int between -2147483647 and 2147483647', - 't1.t_smallint between -32767 and 32767 and t2.t_smallint between -32767 and 32767', + 't1.t_smallint between -32767 and 32767 and t2.t_smallint between -32767 and 32767', '(t1.t_tinyint between -127 and 127 and t2.t_tinyint between -127 and 127) ','t1.t_float between -1.7E308 and 1.7E308 and t2.t_float between -1.7E308 and 1.7E308', '(t1.t_double between -1.7E308 and 1.7E308 and t2.t_double between -1.7E308 and 1.7E308)'] #TD-6201,'t1.t_bool between 0 and 1 or t2.q_bool between 0 and 1'] - t_u_or_where = ['(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\' )' , - '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , + self.t_u_or_where = ['(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\' )' , + '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , '(t1.t_bool in (0 , 1) or t2.t_bool in (0 , 1))' , '(t1.t_bool in ( true , false) or t2.t_bool in ( true , false))' , '(t1.t_bool = 0 or t1.t_bool = 1 or t2.t_bool = 0 or t2.t_bool = 1)', '(t1.t_bigint between -9223372036854775807 and 9223372036854775807 or t2.t_bigint between -9223372036854775807 and 9223372036854775807)', '(t1.t_int between -2147483647 and 2147483647 or t2.t_int between -2147483647 and 2147483647)', - '(t1.t_smallint between -32767 and 32767 or t2.t_smallint between -32767 and 32767)', + '(t1.t_smallint between -32767 and 32767 or t2.t_smallint between -32767 and 32767)', '(t1.t_tinyint between -127 and 127 or t2.t_tinyint between -127 and 127 )','(t1.t_float between -1.7E308 and 1.7E308 or t2.t_float between -1.7E308 and 1.7E308)', '(t1.t_double between -1.7E308 and 1.7E308 or t2.t_double between -1.7E308 and 1.7E308)'] - - # regular and tag column where - qt_where = q_where + t_where - qt_u_where = q_u_where + t_u_where + + # self.t_u_where = ['t1.ts < now +1s'] # 超级表tag不支持,暂时注掉 + # self.t_u_or_where = ['(t1.q_bool in (0 , 1))'] #超级表tag不支持,暂时注掉 + + # regular and tag column where + self.qt_where = self.q_where + self.t_where + #self.qt_where = self.q_where #超级表tag不支持,暂时注掉 + self.qt_u_where = self.q_u_where + self.t_u_where # now,qt_u_or_where is not support - qt_u_or_where = q_u_or_where + t_u_or_where + self.qt_u_or_where = self.q_u_or_where + self.t_u_or_where # tag column where for test super join | this is support , 't1.t_bool = t2.t_bool ' ??? - t_join_where = ['t1.t_bigint = t2.t_bigint ', 't1.t_int = t2.t_int ', 't1.t_smallint = t2.t_smallint ', 't1.t_tinyint = t2.t_tinyint ', + self.t_join_where = ['t1.t_bigint = t2.t_bigint ', 't1.t_int = t2.t_int ', 't1.t_smallint = t2.t_smallint ', 't1.t_tinyint = t2.t_tinyint ', 't1.t_float = t2.t_float ', 't1.t_double = t2.t_double ', 't1.t_binary = t2.t_binary ' , 't1.t_nchar = t2.t_nchar ' ] + #self.t_join_where = ['t1.ts = t2.ts'] # 超级表tag不支持,暂时注掉 # session && fill - session_where = ['session(ts,10a)' , 'session(ts,10s)', 'session(ts,10m)' , 'session(ts,10h)','session(ts,10d)' , 'session(ts,10w)'] - session_u_where = ['session(t1.ts,10a)' , 'session(t1.ts,10s)', 'session(t1.ts,10m)' , 'session(t1.ts,10h)','session(t1.ts,10d)' , 'session(t1.ts,10w)', + self.session_where = ['session(ts,10a)' , 'session(ts,10s)', 'session(ts,10m)' , 'session(ts,10h)','session(ts,10d)' , 'session(ts,10w)'] + self.session_u_where = ['session(t1.ts,10a)' , 'session(t1.ts,10s)', 'session(t1.ts,10m)' , 'session(t1.ts,10h)','session(t1.ts,10d)' , 'session(t1.ts,10w)', 'session(t2.ts,10a)' , 'session(t2.ts,10s)', 'session(t2.ts,10m)' , 'session(t2.ts,10h)','session(t2.ts,10d)' , 'session(t2.ts,10w)'] - - fill_where = ['FILL(NONE)','FILL(PREV)','FILL(NULL)','FILL(LINEAR)','FILL(NEXT)','FILL(VALUE, 1.23)'] - - state_window = ['STATE_WINDOW(q_tinyint)','STATE_WINDOW(q_bigint)','STATE_WINDOW(q_int)','STATE_WINDOW(q_bool)','STATE_WINDOW(q_smallint)'] - state_u_window = ['STATE_WINDOW(t1.q_tinyint)','STATE_WINDOW(t1.q_bigint)','STATE_WINDOW(t1.q_int)','STATE_WINDOW(t1.q_bool)','STATE_WINDOW(t1.q_smallint)', + + self.fill_where = ['FILL(NONE)','FILL(PREV)','FILL(NULL)','FILL(LINEAR)','FILL(NEXT)','FILL(VALUE, 1.23)'] + + self.state_window = ['STATE_WINDOW(q_tinyint)','STATE_WINDOW(q_bigint)','STATE_WINDOW(q_int)','STATE_WINDOW(q_bool)','STATE_WINDOW(q_smallint)'] + self.state_u_window = ['STATE_WINDOW(t1.q_tinyint)','STATE_WINDOW(t1.q_bigint)','STATE_WINDOW(t1.q_int)','STATE_WINDOW(t1.q_bool)','STATE_WINDOW(t1.q_smallint)', 'STATE_WINDOW(t2.q_tinyint)','STATE_WINDOW(t2.q_bigint)','STATE_WINDOW(t2.q_int)','STATE_WINDOW(t2.q_bool)','STATE_WINDOW(t2.q_smallint)'] - # order by where - order_where = ['order by ts' , 'order by ts asc'] - order_u_where = ['order by t1.ts' , 'order by t1.ts asc' , 'order by t2.ts' , 'order by t2.ts asc'] - order_desc_where = ['order by ts' , 'order by ts asc' , 'order by ts desc' ] - orders_desc_where = ['order by ts' , 'order by ts asc' , 'order by ts desc' , 'order by loc' , 'order by loc asc' , 'order by loc desc'] - - group_where = ['group by tbname , loc' , 'group by tbname', 'group by tbname, t_bigint', 'group by tbname,t_int', 'group by tbname, t_smallint', 'group by tbname,t_tinyint', + # order by where + self.order_where = ['order by ts' , 'order by ts asc'] + self.order_u_where = ['order by t1.ts' , 'order by t1.ts asc' , 'order by t2.ts' , 'order by t2.ts asc'] + self.order_desc_where = ['order by ts' , 'order by ts asc' , 'order by ts desc' ] + self.orders_desc_where = ['order by ts' , 'order by ts asc' , 'order by ts desc' , 'order by ts,loc' , 'order by ts,loc asc' , 'order by ts,loc desc'] + + self.group_where = ['group by tbname , loc' , 'group by tbname', 'group by tbname, t_bigint', 'group by tbname,t_int', 'group by tbname, t_smallint', 'group by tbname,t_tinyint', 'group by tbname,t_float', 'group by tbname,t_double' , 'group by tbname,t_binary', 'group by tbname,t_nchar', 'group by tbname,t_bool' ,'group by tbname ,loc ,t_bigint', 'group by tbname,t_binary ,t_nchar ,t_bool' , 'group by tbname,t_int ,t_smallint ,t_tinyint' , 'group by tbname,t_float ,t_double ' , - 'PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', + 'PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', 'PARTITION BY tbname,t_float', 'PARTITION BY tbname,t_double' , 'PARTITION BY tbname,t_binary', 'PARTITION BY tbname,t_nchar', 'PARTITION BY tbname,t_bool' ,'PARTITION BY tbname ,loc ,t_bigint', 'PARTITION BY tbname,t_binary ,t_nchar ,t_bool' , 'PARTITION BY tbname,t_int ,t_smallint ,t_tinyint' , 'PARTITION BY tbname,t_float ,t_double '] - group_where_j = ['group by t1.loc' , 'group by t1.t_bigint', 'group by t1.t_int', 'group by t1.t_smallint', 'group by t1.t_tinyint', + self.group_where_j = ['group by t1.loc' , 'group by t1.t_bigint', 'group by t1.t_int', 'group by t1.t_smallint', 'group by t1.t_tinyint', 'group by t1.t_float', 'group by t1.t_double' , 'group by t1.t_binary', 'group by t1.t_nchar', 'group by t1.t_bool' ,'group by t1.loc ,t1.t_bigint', 'group by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'group by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'group by t1.t_float ,t1.t_double ' , - 'PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', + 'PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', 'PARTITION by t1.t_float', 'PARTITION by t1.t_double' , 'PARTITION by t1.t_binary', 'PARTITION by t1.t_nchar', 'PARTITION by t1.t_bool' ,'PARTITION BY t1.loc ,t1.t_bigint', 'PARTITION by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'PARTITION by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'PARTITION by t1.t_float ,t1.t_double ', - 'group by t2.loc' , 'group by t2.t_bigint', 'group by t2.t_int', 'group by t2.t_smallint', 'group by t2.t_tinyint', + 'group by t2.loc' , 'group by t2.t_bigint', 'group by t2.t_int', 'group by t2.t_smallint', 'group by t2.t_tinyint', 'group by t2.t_float', 'group by t2.t_double' , 'group by t2.t_binary', 'group by t2.t_nchar', 'group by t2.t_bool' ,'group by t2.loc ,t2.t_bigint', 'group by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'group by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'group by t2.t_float ,t2.t_double ' , - 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', + 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', 'PARTITION by t2.t_float', 'PARTITION by t2.t_double' , 'PARTITION by t2.t_binary', 'PARTITION by t2.t_nchar', 'PARTITION by t2.t_bool' ,'PARTITION BY t2.loc ,t2.t_bigint', - 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] - - partiton_where = ['PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', + 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] + + self.group_only_where = ['group by tbname , loc' , 'group by tbname', 'group by tbname, t_bigint', 'group by tbname,t_int', 'group by tbname, t_smallint', 'group by tbname,t_tinyint', + 'group by tbname,t_float', 'group by tbname,t_double' , 'group by tbname,t_binary', 'group by tbname,t_nchar', 'group by tbname,t_bool' ,'group by tbname ,loc ,t_bigint', + 'group by tbname,t_binary ,t_nchar ,t_bool' , 'group by tbname,t_int ,t_smallint ,t_tinyint' , 'group by tbname,t_float ,t_double ' ] + self.group_only_where_j = ['group by t1.loc' , 'group by t1.t_bigint', 'group by t1.t_int', 'group by t1.t_smallint', 'group by t1.t_tinyint', + 'group by t1.t_float', 'group by t1.t_double' , 'group by t1.t_binary', 'group by t1.t_nchar', 'group by t1.t_bool' ,'group by t1.loc ,t1.t_bigint', + 'group by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'group by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'group by t1.t_float ,t1.t_double ' , + 'group by t2.loc' , 'group by t2.t_bigint', 'group by t2.t_int', 'group by t2.t_smallint', 'group by t2.t_tinyint', + 'group by t2.t_float', 'group by t2.t_double' , 'group by t2.t_binary', 'group by t2.t_nchar', 'group by t2.t_bool' ,'group by t2.loc ,t2.t_bigint', + 'group by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'group by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'group by t2.t_float ,t2.t_double ' ] + + self.partiton_where = ['PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', 'PARTITION BY tbname,t_float', 'PARTITION BY tbname,t_double' , 'PARTITION BY tbname,t_binary', 'PARTITION BY tbname,t_nchar', 'PARTITION BY tbname,t_bool' ,'PARTITION BY tbname ,loc ,t_bigint', 'PARTITION BY tbname,t_binary ,t_nchar ,t_bool' , 'PARTITION BY tbname,t_int ,t_smallint ,t_tinyint' , 'PARTITION BY tbname,t_float ,t_double '] - partiton_where_j = ['PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', + self.partiton_where_j = ['PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', 'PARTITION by t1.t_float', 'PARTITION by t1.t_double' , 'PARTITION by t1.t_binary', 'PARTITION by t1.t_nchar', 'PARTITION by t1.t_bool' ,'PARTITION BY t1.loc ,t1.t_bigint', 'PARTITION by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'PARTITION by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'PARTITION by t1.t_float ,t1.t_double ', - 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', + 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', 'PARTITION by t2.t_float', 'PARTITION by t2.t_double' , 'PARTITION by t2.t_binary', 'PARTITION by t2.t_nchar', 'PARTITION by t2.t_bool' ,'PARTITION BY t2.loc ,t2.t_bigint', - 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] - + 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] - group_where_regular = ['group by tbname ' , 'group by tbname', 'group by tbname, q_bigint', 'group by tbname,q_int', 'group by tbname, q_smallint', 'group by tbname,q_tinyint', + + self.group_where_regular = ['group by tbname ' , 'group by tbname', 'group by tbname, q_bigint', 'group by tbname,q_int', 'group by tbname, q_smallint', 'group by tbname,q_tinyint', 'group by tbname,q_float', 'group by tbname,q_double' , 'group by tbname,q_binary', 'group by tbname,q_nchar', 'group by tbname,q_bool' ,'group by tbname ,q_bigint', 'group by tbname,q_binary ,q_nchar ,q_bool' , 'group by tbname,q_int ,q_smallint ,q_tinyint' , 'group by tbname,q_float ,q_double ' , - 'PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', + 'PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', 'PARTITION BY tbname,q_float', 'PARTITION BY tbname,q_double' , 'PARTITION BY tbname,q_binary', 'PARTITION BY tbname,q_nchar', 'PARTITION BY tbname,q_bool' ,'PARTITION BY tbname ,q_bigint', 'PARTITION BY tbname,q_binary ,q_nchar ,q_bool' , 'PARTITION BY tbname,q_int ,q_smallint ,q_tinyint' , 'PARTITION BY tbname,q_float ,q_double '] - group_where_regular_j = ['group by t1.q_bigint', 'group by t1.q_int', 'group by t1.q_smallint', 'group by t1.q_tinyint', + self.group_where_regular_j = ['group by t1.q_bigint', 'group by t1.q_int', 'group by t1.q_smallint', 'group by t1.q_tinyint', 'group by t1.q_float', 'group by t1.q_double' , 'group by t1.q_binary', 'group by t1.q_nchar', 'group by t1.q_bool' ,'group by t1.q_bigint', 'group by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'group by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'group by t1.q_float ,t1.q_double ' , - 'PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', + 'PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', 'PARTITION by t1.q_float', 'PARTITION by t1.q_double' , 'PARTITION by t1.q_binary', 'PARTITION by t1.q_nchar', 'PARTITION by t1.q_bool' ,'PARTITION BY t1.q_bigint', 'PARTITION by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'PARTITION by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'PARTITION by t1.q_float ,t1.q_double ', - 'group by t2.q_bigint', 'group by t2.q_int', 'group by t2.q_smallint', 'group by t2.q_tinyint', + 'group by t2.q_bigint', 'group by t2.q_int', 'group by t2.q_smallint', 'group by t2.q_tinyint', 'group by t2.q_float', 'group by t2.q_double' , 'group by t2.q_binary', 'group by t2.q_nchar', 'group by t2.q_bool' ,'group by t2.q_bigint', 'group by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'group by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'group by t2.q_float ,t2.q_double ' , - 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', + 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', 'PARTITION by t2.q_float', 'PARTITION by t2.q_double' , 'PARTITION by t2.q_binary', 'PARTITION by t2.q_nchar', 'PARTITION by t2.q_bool' ,'PARTITION BY t2.q_bigint', - 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] - - partiton_where_regular = ['PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', + 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] + + self.partiton_where_regular = ['PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', 'PARTITION BY tbname,q_float', 'PARTITION BY tbname,q_double' , 'PARTITION BY tbname,q_binary', 'PARTITION BY tbname,q_nchar', 'PARTITION BY tbname,q_bool' ,'PARTITION BY tbname ,q_bigint', 'PARTITION BY tbname,q_binary ,q_nchar ,q_bool' , 'PARTITION BY tbname,q_int ,q_smallint ,q_tinyint' , 'PARTITION BY tbname,q_float ,q_double '] - partiton_where_regular_j = ['PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', + self.partiton_where_regular_j = ['PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', 'PARTITION by t1.q_float', 'PARTITION by t1.q_double' , 'PARTITION by t1.q_binary', 'PARTITION by t1.q_nchar', 'PARTITION by t1.q_bool' ,'PARTITION BY t1.q_bigint', 'PARTITION by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'PARTITION by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'PARTITION by t1.q_float ,t1.q_double ', - 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', + 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', 'PARTITION by t2.q_float', 'PARTITION by t2.q_double' , 'PARTITION by t2.q_binary', 'PARTITION by t2.q_nchar', 'PARTITION by t2.q_bool' ,'PARTITION BY t2.q_bigint', - 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] - - having_support = ['having count(q_int) > 0','having count(q_bigint) > 0','having count(q_smallint) > 0','having count(q_tinyint) > 0','having count(q_float) > 0','having count(q_double) > 0','having count(q_bool) > 0', + 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] + + self.having_support = ['having count(q_int) > 0','having count(q_bigint) > 0','having count(q_smallint) > 0','having count(q_tinyint) > 0','having count(q_float) > 0','having count(q_double) > 0','having count(q_bool) > 0', 'having avg(q_int) > 0','having avg(q_bigint) > 0','having avg(q_smallint) > 0','having avg(q_tinyint) > 0','having avg(q_float) > 0','having avg(q_double) > 0', 'having sum(q_int) > 0','having sum(q_bigint) > 0','having sum(q_smallint) > 0','having sum(q_tinyint) > 0','having sum(q_float) > 0','having sum(q_double) > 0', 'having STDDEV(q_int) > 0','having STDDEV(q_bigint) > 0','having STDDEV(q_smallint) > 0','having STDDEV(q_tinyint) > 0','having STDDEV(q_float) > 0','having STDDEV(q_double) > 0', @@ -436,15 +262,32 @@ class TDTestCase: 'having MAX(q_int) > 0','having MAX(q_bigint) > 0','having MAX(q_smallint) > 0','having MAX(q_tinyint) > 0','having MAX(q_float) > 0','having MAX(q_double) > 0', 'having FIRST(q_int) > 0','having FIRST(q_bigint) > 0','having FIRST(q_smallint) > 0','having FIRST(q_tinyint) > 0','having FIRST(q_float) > 0','having FIRST(q_double) > 0', 'having LAST(q_int) > 0','having LAST(q_bigint) > 0','having LAST(q_smallint) > 0','having LAST(q_tinyint) > 0','having LAST(q_float) > 0','having LAST(q_double) > 0', - 'having APERCENTILE(q_int,10) > 0','having APERCENTILE(q_bigint,10) > 0','having APERCENTILE(q_smallint,10) > 0','having APERCENTILE(q_tinyint,10) > 0','having APERCENTILE(q_float,10) > 0','having APERCENTILE(q_double,10) > 0'] - having_not_support = ['having TOP(q_int,10) > 0','having TOP(q_bigint,10) > 0','having TOP(q_smallint,10) > 0','having TOP(q_tinyint,10) > 0','having TOP(q_float,10) > 0','having TOP(q_double,10) > 0','having TOP(q_bool,10) > 0', + 'having APERCENTILE(q_int,10) > 0','having APERCENTILE(q_bigint,10) > 0','having APERCENTILE(q_smallint,10) > 0','having APERCENTILE(q_tinyint,10) > 0','having APERCENTILE(q_float,10) > 0','having APERCENTILE(q_double,10) > 0', + 'having count(q_int_null) > 0','having count(q_bigint_null) > 0','having count(q_smallint_null) > 0','having count(q_tinyint_null) > 0','having count(q_float_null) > 0','having count(q_double_null) > 0','having count(q_bool_null) > 0', + 'having avg(q_int_null) > 0','having avg(q_bigint_null) > 0','having avg(q_smallint_null) > 0','having avg(q_tinyint_null) > 0','having avg(q_float_null) > 0','having avg(q_double_null) > 0', + 'having sum(q_int_null) > 0','having sum(q_bigint_null) > 0','having sum(q_smallint_null) > 0','having sum(q_tinyint_null) > 0','having sum(q_float_null) > 0','having sum(q_double_null) > 0', + 'having STDDEV(q_int_null) > 0','having STDDEV(q_bigint_null) > 0','having STDDEV(q_smallint_null) > 0','having STDDEV(q_tinyint_null) > 0','having STDDEV(q_float_null) > 0','having STDDEV(q_double_null) > 0', + 'having TWA(q_int_null) > 0','having TWA(q_bigint_null) > 0','having TWA(q_smallint_null) > 0','having TWA(q_tinyint_null) > 0','having TWA(q_float_null) > 0','having TWA(q_double_null) > 0', + 'having IRATE(q_int_null) > 0','having IRATE(q_bigint_null) > 0','having IRATE(q_smallint_null) > 0','having IRATE(q_tinyint_null) > 0','having IRATE(q_float_null) > 0','having IRATE(q_double_null) > 0', + 'having MIN(q_int_null) > 0','having MIN(q_bigint_null) > 0','having MIN(q_smallint_null) > 0','having MIN(q_tinyint_null) > 0','having MIN(q_float_null) > 0','having MIN(q_double_null) > 0', + 'having MAX(q_int_null) > 0','having MAX(q_bigint_null) > 0','having MAX(q_smallint_null) > 0','having MAX(q_tinyint_null) > 0','having MAX(q_float_null) > 0','having MAX(q_double_null) > 0', + 'having FIRST(q_int_null) > 0','having FIRST(q_bigint_null) > 0','having FIRST(q_smallint_null) > 0','having FIRST(q_tinyint_null) > 0','having FIRST(q_float_null) > 0','having FIRST(q_double_null) > 0', + 'having LAST(q_int_null) > 0','having LAST(q_bigint_null) > 0','having LAST(q_smallint_null) > 0','having LAST(q_tinyint_null) > 0','having LAST(q_float_null) > 0','having LAST(q_double_null) > 0', + 'having APERCENTILE(q_int_null,10) > 0','having APERCENTILE(q_bigint_null,10) > 0','having APERCENTILE(q_smallint_null,10) > 0','having APERCENTILE(q_tinyint_null,10) > 0','having APERCENTILE(q_float_null,10) > 0','having APERCENTILE(q_double_null,10) > 0'] + self.having_not_support = ['having TOP(q_int,10) > 0','having TOP(q_bigint,10) > 0','having TOP(q_smallint,10) > 0','having TOP(q_tinyint,10) > 0','having TOP(q_float,10) > 0','having TOP(q_double,10) > 0','having TOP(q_bool,10) > 0', 'having BOTTOM(q_int,10) > 0','having BOTTOM(q_bigint,10) > 0','having BOTTOM(q_smallint,10) > 0','having BOTTOM(q_tinyint,10) > 0','having BOTTOM(q_float,10) > 0','having BOTTOM(q_double,10) > 0','having BOTTOM(q_bool,10) > 0', 'having LEASTSQUARES(q_int) > 0','having LEASTSQUARES(q_bigint) > 0','having LEASTSQUARES(q_smallint) > 0','having LEASTSQUARES(q_tinyint) > 0','having LEASTSQUARES(q_float) > 0','having LEASTSQUARES(q_double) > 0','having LEASTSQUARES(q_bool) > 0', - 'having FIRST(q_bool) > 0','having IRATE(q_bool) > 0','having PERCENTILE(q_bool,10) > 0','having avg(q_bool) > 0','having LAST_ROW(q_bool) > 0','having sum(q_bool) > 0','having STDDEV(q_bool) > 0','having APERCENTILE(q_bool,10) > 0','having TWA(q_bool) > 0','having LAST(q_bool) > 0', - 'having PERCENTILE(q_int,10) > 0','having PERCENTILE(q_bigint,10) > 0','having PERCENTILE(q_smallint,10) > 0','having PERCENTILE(q_tinyint,10) > 0','having PERCENTILE(q_float,10) > 0','having PERCENTILE(q_double,10) > 0'] - having_tagnot_support = ['having LAST_ROW(q_int) > 0','having LAST_ROW(q_bigint) > 0','having LAST_ROW(q_smallint) > 0','having LAST_ROW(q_tinyint) > 0','having LAST_ROW(q_float) > 0','having LAST_ROW(q_double) > 0'] - - having_support_j = ['having count(t1.q_int) > 0','having count(t1.q_bigint) > 0','having count(t1.q_smallint) > 0','having count(t1.q_tinyint) > 0','having count(t1.q_float) > 0','having count(t1.q_double) > 0','having count(t1.q_bool) > 0', + 'having FIRST(q_bool) > 0','having IRATE(q_bool) > 0','having PERCENTILE(q_bool,10) > 0','having avg(q_bool) > 0','having LAST_ROW(q_bool) > 0','having sum(q_bool) > 0','having STDDEV(q_bool) > 0','having APERCENTILE(q_bool,10) > 0','having TWA(q_bool) > 0','having LAST(q_bool) > 0', + 'having PERCENTILE(q_int,10) > 0','having PERCENTILE(q_bigint,10) > 0','having PERCENTILE(q_smallint,10) > 0','having PERCENTILE(q_tinyint,10) > 0','having PERCENTILE(q_float,10) > 0','having PERCENTILE(q_double,10) > 0', + 'having TOP(q_int_null,10) > 0','having TOP(q_bigint_null,10) > 0','having TOP(q_smallint_null,10) > 0','having TOP(q_tinyint_null,10) > 0','having TOP(q_float_null,10) > 0','having TOP(q_double_null,10) > 0','having TOP(q_bool_null,10) > 0', + 'having BOTTOM(q_int_null,10) > 0','having BOTTOM(q_bigint_null,10) > 0','having BOTTOM(q_smallint_null,10) > 0','having BOTTOM(q_tinyint_null,10) > 0','having BOTTOM(q_float_null,10) > 0','having BOTTOM(q_double_null,10) > 0','having BOTTOM(q_bool_null,10) > 0', + 'having LEASTSQUARES(q_int_null) > 0','having LEASTSQUARES(q_bigint_null) > 0','having LEASTSQUARES(q_smallint_null) > 0','having LEASTSQUARES(q_tinyint_null) > 0','having LEASTSQUARES(q_float_null) > 0','having LEASTSQUARES(q_double_null) > 0','having LEASTSQUARES(q_bool_null) > 0', + 'having FIRST(q_bool_null) > 0','having IRATE(q_bool_null) > 0','having PERCENTILE(q_bool_null,10) > 0','having avg(q_bool_null) > 0','having LAST_ROW(q_bool_null) > 0','having sum(q_bool_null) > 0','having STDDEV(q_bool_null) > 0','having APERCENTILE(q_bool_null,10) > 0','having TWA(q_bool_null) > 0','having LAST(q_bool_null) > 0', + 'having PERCENTILE(q_int_null,10) > 0','having PERCENTILE(q_bigint_null,10) > 0','having PERCENTILE(q_smallint_null,10) > 0','having PERCENTILE(q_tinyint_null,10) > 0','having PERCENTILE(q_float_null,10) > 0','having PERCENTILE(q_double_null,10) > 0'] + self.having_tagnot_support = ['having LAST_ROW(q_int) > 0','having LAST_ROW(q_bigint) > 0','having LAST_ROW(q_smallint) > 0','having LAST_ROW(q_tinyint) > 0','having LAST_ROW(q_float) > 0','having LAST_ROW(q_double) > 0', + 'having LAST_ROW(q_int_null) > 0','having LAST_ROW(q_bigint_null) > 0','having LAST_ROW(q_smallint_null) > 0','having LAST_ROW(q_tinyint_null) > 0','having LAST_ROW(q_float_null) > 0','having LAST_ROW(q_double_null) > 0'] + + self.having_support_j = ['having count(t1.q_int) > 0','having count(t1.q_bigint) > 0','having count(t1.q_smallint) > 0','having count(t1.q_tinyint) > 0','having count(t1.q_float) > 0','having count(t1.q_double) > 0','having count(t1.q_bool) > 0', 'having avg(t1.q_int) > 0','having avg(t1.q_bigint) > 0','having avg(t1.q_smallint) > 0','having avg(t1.q_tinyint) > 0','having avg(t1.q_float) > 0','having avg(t1.q_double) > 0', 'having sum(t1.q_int) > 0','having sum(t1.q_bigint) > 0','having sum(t1.q_smallint) > 0','having sum(t1.q_tinyint) > 0','having sum(t1.q_float) > 0','having sum(t1.q_double) > 0', 'having STDDEV(t1.q_int) > 0','having STDDEV(t1.q_bigint) > 0','having STDDEV(t1.q_smallint) > 0','having STDDEV(t1.q_tinyint) > 0','having STDDEV(t1.q_float) > 0','having STDDEV(t1.q_double) > 0', @@ -455,17 +298,17 @@ class TDTestCase: 'having FIRST(t1.q_int) > 0','having FIRST(t1.q_bigint) > 0','having FIRST(t1.q_smallint) > 0','having FIRST(t1.q_tinyint) > 0','having FIRST(t1.q_float) > 0','having FIRST(t1.q_double) > 0', 'having LAST(t1.q_int) > 0','having LAST(t1.q_bigint) > 0','having LAST(t1.q_smallint) > 0','having LAST(t1.q_tinyint) > 0','having LAST(t1.q_float) > 0','having LAST(t1.q_double) > 0', 'having APERCENTILE(t1.q_int,10) > 0','having APERCENTILE(t1.q_bigint,10) > 0','having APERCENTILE(t1.q_smallint,10) > 0','having APERCENTILE(t1.q_tinyint,10) > 0','having APERCENTILE(t1.q_float,10) > 0','having APERCENTILE(t1.q_double,10) > 0'] - + # limit offset where - limit_where = ['limit 1 offset 1' , 'limit 1' , 'limit 2 offset 1' , 'limit 2', 'limit 12 offset 1' , 'limit 20', 'limit 20 offset 10' , 'limit 200'] - limit1_where = ['limit 1 offset 1' , 'limit 1' ] - limit_u_where = ['limit 100 offset 10' , 'limit 50' , 'limit 100' , 'limit 10' ] + self.limit_where = ['limit 1 offset 1' , 'limit 1' , 'limit 2 offset 1' , 'limit 2', 'limit 12 offset 1' , 'limit 20', 'limit 20 offset 10' , 'limit 200'] + self.limit1_where = ['limit 1 offset 1' , 'limit 1' ] + self.limit_u_where = ['limit 100 offset 10' , 'limit 50' , 'limit 100' , 'limit 10' ] # slimit soffset where - slimit_where = ['slimit 1 soffset 1' , 'slimit 1' , 'slimit 2 soffset 1' , 'slimit 2'] - slimit1_where = ['slimit 2 soffset 1' , 'slimit 1' ] - - # aggregate function include [all:count(*)\avg\sum\stddev ||regualr:twa\irate\leastsquares ||group by tbname:twa\irate\] + self.slimit_where = ['slimit 1 soffset 1' , 'slimit 1' , 'slimit 2 soffset 1' , 'slimit 2'] + self.slimit1_where = ['slimit 2 soffset 1' , 'slimit 1' ] + + # aggregate function include [all:count(*)\avg\sum\stddev ||regualr:twa\irate\leastsquares ||group by tbname:twa\irate\] # select function include [all: min\max\first(*)\last(*)\top\bottom\apercentile\last_row(*)(not with interval)\interp(*)(FILL) ||regualr: percentile] # calculation function include [all:spread\+-*/ ||regualr:diff\derivative ||group by tbname:diff\derivative\] # **_ns_** express is not support stable, therefore, separated from regular tables @@ -475,56 +318,92 @@ class TDTestCase: # calc_select_all calc_select_regular calc_select_in_ts calc_select_fill calc_select_not_interval # select function include [all: min\max\first(*)\last(*)\top\bottom\apercentile\last_row(*)(not with interval)\interp(*)(FILL) ||regualr: percentile] - - calc_select_all = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , + + self.calc_select_all = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , 'top(q_int,20)' , 'top(q_bigint,20)' , 'top(q_smallint,20)' ,'top(q_tinyint,20)' ,'top(q_float,20)' ,'top(q_double,20)' , 'first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , 'last(q_int)' , 'last(q_bigint)' , 'last(q_smallint)' , 'last(q_tinyint)' , 'last(q_float)' ,'last(q_double)' , 'last(q_binary)' ,'last(q_nchar)' ,'last(q_bool)' ,'last(q_ts)' , 'min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' , 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)' , - 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , - 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)'] - - calc_select_in_ts = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , + 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , + 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)', + 'bottom(q_int_null,20)' , 'bottom(q_bigint_null,20)' , 'bottom(q_smallint_null,20)' , 'bottom(q_tinyint_null,20)' ,'bottom(q_float_null,20)' , 'bottom(q_double_null,20)' , + 'top(q_int_null,20)' , 'top(q_bigint_null,20)' , 'top(q_smallint_null,20)' ,'top(q_tinyint_null,20)' ,'top(q_float_null,20)' ,'top(q_double_null,20)' , + 'first(q_int_null)' , 'first(q_bigint_null)' , 'first(q_smallint_null)' , 'first(q_tinyint_null)' , 'first(q_float_null)' ,'first(q_double_null)' ,'first(q_binary_null)' ,'first(q_nchar_null)' ,'first(q_bool_null)' ,'first(q_ts_null)' , + 'last(q_int_null)' , 'last(q_bigint_null)' , 'last(q_smallint_null)' , 'last(q_tinyint_null)' , 'last(q_float_null)' ,'last(q_double_null)' , 'last(q_binary_null)' ,'last(q_nchar_null)' ,'last(q_bool_null)' ,'last(q_ts_null)' , + 'min(q_int_null)' , 'min(q_bigint_null)' , 'min(q_smallint_null)' , 'min(q_tinyint_null)' , 'min(q_float_null)' ,'min(q_double_null)' , + 'max(q_int_null)' , 'max(q_bigint_null)' , 'max(q_smallint_null)' , 'max(q_tinyint_null)' ,'max(q_float_null)' ,'max(q_double_null)' , + 'last_row(q_int_null)' , 'last_row(q_bigint_null)' , 'last_row(q_smallint_null)' , 'last_row(q_tinyint_null)' , 'last_row(q_float_null)' , + 'last_row(q_double_null)' , 'last_row(q_bool_null)' ,'last_row(q_binary_null)' ,'last_row(q_nchar_null)' ,'last_row(q_ts_null)', + 'apercentile(q_int_null,20)' , 'apercentile(q_bigint_null,20)' ,'apercentile(q_smallint_null,20)' ,'apercentile(q_tinyint_null,20)' ,'apercentile(q_float_null,20)' ,'apercentile(q_double_null,20)' ,] + + self.calc_select_in_ts = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , 'top(q_int,20)' , 'top(q_bigint,20)' , 'top(q_smallint,20)' ,'top(q_tinyint,20)' ,'top(q_float,20)' ,'top(q_double,20)' , + 'bottom(q_int_null,20)' , 'bottom(q_bigint_null,20)' , 'bottom(q_smallint_null,20)' , 'bottom(q_tinyint_null,20)' ,'bottom(q_float_null,20)' , 'bottom(q_double_null,20)' , + 'top(q_int_null,20)' , 'top(q_bigint_null,20)' , 'top(q_smallint_null,20)' ,'top(q_tinyint_null,20)' ,'top(q_float_null,20)' ,'top(q_double_null,20)' , 'first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , - 'last(q_int)' , 'last(q_bigint)' , 'last(q_smallint)' , 'last(q_tinyint)' , 'last(q_float)' ,'last(q_double)' , 'last(q_binary)' ,'last(q_nchar)' ,'last(q_bool)' ,'last(q_ts)' ] + 'last(q_int)' , 'last(q_bigint)' , 'last(q_smallint)' , 'last(q_tinyint)' , 'last(q_float)' ,'last(q_double)' , 'last(q_binary)' ,'last(q_nchar)' ,'last(q_bool)' ,'last(q_ts)' , + 'first(q_int_null)' , 'first(q_bigint_null)' , 'first(q_smallint_null)' , 'first(q_tinyint_null)' , 'first(q_float_null)' ,'first(q_double_null)' ,'first(q_binary_null)' ,'first(q_nchar_null)' ,'first(q_bool_null)' ,'first(q_ts_null)' , + 'last(q_int_null)' , 'last(q_bigint_null)' , 'last(q_smallint_null)' , 'last(q_tinyint_null)' , 'last(q_float_null)' ,'last(q_double_null)' , 'last(q_binary_null)' ,'last(q_nchar_null)' ,'last(q_bool_null)' ,'last(q_ts_null)' ] - calc_select_in = ['min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , + self.calc_select_in = ['min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' , 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)' , - 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , - 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)'] - - calc_select_not_support_ts = ['first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , + 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , + 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)', + 'min(q_int_null)' , 'min(q_bigint_null)' , 'min(q_smallint_null)' , 'min(q_tinyint_null)' , 'min(q_float_null)' ,'min(q_double_null)' , + 'max(q_int_null)' , 'max(q_bigint_null)' , 'max(q_smallint_null)' , 'max(q_tinyint_null)' ,'max(q_float_null)' ,'max(q_double_null)' , + 'apercentile(q_int_null,20)' , 'apercentile(q_bigint_null,20)' ,'apercentile(q_smallint_null,20)' ,'apercentile(q_tinyint_null,20)' ,'apercentile(q_float_null,20)' ,'apercentile(q_double_null,20)' , + 'last_row(q_int_null)' , 'last_row(q_bigint_null)' , 'last_row(q_smallint_null)' , 'last_row(q_tinyint_null)' , 'last_row(q_float_null)' , + 'last_row(q_double_null)' , 'last_row(q_bool_null)' ,'last_row(q_binary_null)' ,'last_row(q_nchar_null)' ,'last_row(q_ts_null)'] + + self.calc_select_not_support_ts = ['first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , 'last(q_int)' , 'last(q_bigint)' , 'last(q_smallint)' , 'last(q_tinyint)' , 'last(q_float)' ,'last(q_double)' , 'last(q_binary)' ,'last(q_nchar)' ,'last(q_bool)' ,'last(q_ts)' , - 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , + 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)', - 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)'] - - calc_select_support_ts = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , + 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)', + 'first(q_int_null)' , 'first(q_bigint_null)' , 'first(q_smallint_null)' , 'first(q_tinyint_null)' , 'first(q_float_null)' ,'first(q_double_null)' ,'first(q_binary_null)' ,'first(q_nchar_null)' ,'first(q_bool_null)' ,'first(q_ts_null)' , + 'last(q_int_null)' , 'last(q_bigint_null)' , 'last(q_smallint_null)' , 'last(q_tinyint_null)' , 'last(q_float_null)' ,'last(q_double_null)' , 'last(q_binary_null)' ,'last(q_nchar_null)' ,'last(q_bool_null)' ,'last(q_ts_null)' , + 'last_row(q_int_null)' , 'last_row(q_bigint_null)' , 'last_row(q_smallint_null)' , 'last_row(q_tinyint_null)' , 'last_row(q_float_null)' , + 'last_row(q_double_null)' , 'last_row(q_bool_null)' ,'last_row(q_binary_null)' ,'last_row(q_nchar_null)' ,'last_row(q_ts_null)', + 'apercentile(q_int_null,20)' , 'apercentile(q_bigint_null,20)' ,'apercentile(q_smallint_null,20)' ,'apercentile(q_tinyint_null,20)' ,'apercentile(q_float_null,20)' ,'apercentile(q_double_null,20)'] + + self.calc_select_support_ts = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , 'top(q_int,20)' , 'top(q_bigint,20)' , 'top(q_smallint,20)' ,'top(q_tinyint,20)' ,'top(q_float,20)' ,'top(q_double,20)' , + 'bottom(q_int_null,20)' , 'bottom(q_bigint_null,20)' , 'bottom(q_smallint_null,20)' , 'bottom(q_tinyint_null,20)' ,'bottom(q_float_null,20)' , 'bottom(q_double_null,20)' , + 'top(q_int_null,20)' , 'top(q_bigint_null,20)' , 'top(q_smallint_null,20)' ,'top(q_tinyint_null,20)' ,'top(q_float_null,20)' ,'top(q_double_null,20)' , 'min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , - 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' ] - - calc_select_regular = [ 'PERCENTILE(q_int,10)' ,'PERCENTILE(q_bigint,20)' , 'PERCENTILE(q_smallint,30)' ,'PERCENTILE(q_tinyint,40)' ,'PERCENTILE(q_float,50)' ,'PERCENTILE(q_double,60)'] + 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' , + 'min(q_int_null)' , 'min(q_bigint_null)' , 'min(q_smallint_null)' , 'min(q_tinyint_null)' , 'min(q_float_null)' ,'min(q_double_null)' , + 'max(q_int_null)' , 'max(q_bigint_null)' , 'max(q_smallint_null)' , 'max(q_tinyint_null)' ,'max(q_float_null)' ,'max(q_double_null)'] + + self.calc_select_regular = [ 'PERCENTILE(q_int,10)' ,'PERCENTILE(q_bigint,20)' , 'PERCENTILE(q_smallint,30)' ,'PERCENTILE(q_tinyint,40)' ,'PERCENTILE(q_float,50)' ,'PERCENTILE(q_double,60)', + 'PERCENTILE(q_int_null,10)' ,'PERCENTILE(q_bigint_null,20)' , 'PERCENTILE(q_smallint_null,30)' ,'PERCENTILE(q_tinyint_null,40)' ,'PERCENTILE(q_float_null,50)' ,'PERCENTILE(q_double_null,60)'] - - calc_select_fill = ['INTERP(q_int)' ,'INTERP(q_bigint)' ,'INTERP(q_smallint)' ,'INTERP(q_tinyint)', 'INTERP(q_float)' ,'INTERP(q_double)'] - interp_where = ['ts = now' , 'ts = \'2020-09-13 20:26:40.000\'' , 'ts = \'2020-09-13 20:26:40.009\'' ,'tbname in (\'table_1\') and ts = now' ,'tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and ts = \'2020-09-13 20:26:40.000\'','tbname like \'table%\' and ts = \'2020-09-13 20:26:40.002\''] + + self.calc_select_fill = ['INTERP(q_int)' ,'INTERP(q_bigint)' ,'INTERP(q_smallint)' ,'INTERP(q_tinyint)', 'INTERP(q_float)' ,'INTERP(q_double)'] + self.interp_where = ['ts = now' , 'ts = \'2020-09-13 20:26:40.000\'' , 'ts = \'2020-09-13 20:26:40.009\'' ,'tbname in (\'table_1\') and ts = now' ,'tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and ts = \'2020-09-13 20:26:40.000\'','tbname like \'table%\' and ts = \'2020-09-13 20:26:40.002\''] #two table join - calc_select_in_ts_j = ['bottom(t1.q_int,20)' , 'bottom(t1.q_bigint,20)' , 'bottom(t1.q_smallint,20)' , 'bottom(t1.q_tinyint,20)' ,'bottom(t1.q_float,20)' , 'bottom(t1.q_double,20)' , + self.calc_select_in_ts_j = ['bottom(t1.q_int,20)' , 'bottom(t1.q_bigint,20)' , 'bottom(t1.q_smallint,20)' , 'bottom(t1.q_tinyint,20)' ,'bottom(t1.q_float,20)' , 'bottom(t1.q_double,20)' , 'top(t1.q_int,20)' , 'top(t1.q_bigint,20)' , 'top(t1.q_smallint,20)' ,'top(t1.q_tinyint,20)' ,'top(t1.q_float,20)' ,'top(t1.q_double,20)' , 'first(t1.q_int)' , 'first(t1.q_bigint)' , 'first(t1.q_smallint)' , 'first(t1.q_tinyint)' , 'first(t1.q_float)' ,'first(t1.q_double)' ,'first(t1.q_binary)' ,'first(t1.q_nchar)' ,'first(t1.q_bool)' ,'first(t1.q_ts)' , 'last(t1.q_int)' , 'last(t1.q_bigint)' , 'last(t1.q_smallint)' , 'last(t1.q_tinyint)' , 'last(t1.q_float)' ,'last(t1.q_double)' , 'last(t1.q_binary)' ,'last(t1.q_nchar)' ,'last(t1.q_bool)' ,'last(t1.q_ts)' , 'bottom(t2.q_int,20)' , 'bottom(t2.q_bigint,20)' , 'bottom(t2.q_smallint,20)' , 'bottom(t2.q_tinyint,20)' ,'bottom(t2.q_float,20)' , 'bottom(t2.q_double,20)' , 'top(t2.q_int,20)' , 'top(t2.q_bigint,20)' , 'top(t2.q_smallint,20)' ,'top(t2.q_tinyint,20)' ,'top(t2.q_float,20)' ,'top(t2.q_double,20)' , 'first(t2.q_int)' , 'first(t2.q_bigint)' , 'first(t2.q_smallint)' , 'first(t2.q_tinyint)' , 'first(t2.q_float)' ,'first(t2.q_double)' ,'first(t2.q_binary)' ,'first(t2.q_nchar)' ,'first(t2.q_bool)' ,'first(t2.q_ts)' , - 'last(t2.q_int)' , 'last(t2.q_bigint)' , 'last(t2.q_smallint)' , 'last(t2.q_tinyint)' , 'last(t2.q_float)' ,'last(t2.q_double)' , 'last(t2.q_binary)' ,'last(t2.q_nchar)' ,'last(t2.q_bool)' ,'last(t2.q_ts)'] - - calc_select_in_support_ts_j = ['bottom(t1.q_int,20)' , 'bottom(t1.q_bigint,20)' , 'bottom(t1.q_smallint,20)' , 'bottom(t1.q_tinyint,20)' ,'bottom(t1.q_float,20)' , 'bottom(t1.q_double,20)' , + 'last(t2.q_int)' , 'last(t2.q_bigint)' , 'last(t2.q_smallint)' , 'last(t2.q_tinyint)' , 'last(t2.q_float)' ,'last(t2.q_double)' , 'last(t2.q_binary)' ,'last(t2.q_nchar)' ,'last(t2.q_bool)' ,'last(t2.q_ts)', + 'bottom(t1.q_int_null,20)' , 'bottom(t1.q_bigint_null,20)' , 'bottom(t1.q_smallint_null,20)' , 'bottom(t1.q_tinyint_null,20)' ,'bottom(t1.q_float_null,20)' , 'bottom(t1.q_double_null,20)' , + 'top(t1.q_int_null,20)' , 'top(t1.q_bigint_null,20)' , 'top(t1.q_smallint_null,20)' ,'top(t1.q_tinyint_null,20)' ,'top(t1.q_float_null,20)' ,'top(t1.q_double_null,20)' , + 'first(t1.q_int_null)' , 'first(t1.q_bigint_null)' , 'first(t1.q_smallint_null)' , 'first(t1.q_tinyint_null)' , 'first(t1.q_float_null)' ,'first(t1.q_double_null)' ,'first(t1.q_binary_null)' ,'first(t1.q_nchar_null))' ,'first(t1.q_bool_null)' ,'first(t1.q_ts_null)' , + 'last(t1.q_int_null)' , 'last(t1.q_bigint_null)' , 'last(t1.q_smallint_null)' , 'last(t1.q_tinyint_null)' , 'last(t1.q_float_null)' ,'last(t1.q_double_null)' , 'last(t1.q_binary_null)' ,'last(t1.q_nchar_null))' ,'last(t1.q_bool_null)' ,'last(t1.q_ts_null)' , + 'bottom(t2.q_int_null,20)' , 'bottom(t2.q_bigint_null,20)' , 'bottom(t2.q_smallint_null,20)' , 'bottom(t2.q_tinyint_null,20)' ,'bottom(t2.q_float_null,20)' , 'bottom(t2.q_double_null,20)' , + 'top(t2.q_int_null,20)' , 'top(t2.q_bigint_null,20)' , 'top(t2.q_smallint_null,20)' ,'top(t2.q_tinyint_null,20)' ,'top(t2.q_float_null,20)' ,'top(t2.q_double_null,20)' , + 'first(t2.q_int_null)' , 'first(t2.q_bigint_null)' , 'first(t2.q_smallint_null)' , 'first(t2.q_tinyint_null)' , 'first(t2.q_float_null)' ,'first(t2.q_double_null)' ,'first(t2.q_binary_null)' ,'first(t2.q_nchar_null))' ,'first(t2.q_bool_null)' ,'first(t2.q_ts_null)' , + 'last(t2.q_int_null)' , 'last(t2.q_bigint_null)' , 'last(t2.q_smallint_null)' , 'last(t2.q_tinyint_null)' , 'last(t2.q_float_null)' ,'last(t2.q_double_null)' , 'last(t2.q_binary_null)' ,'last(t2.q_nchar_null))' ,'last(t2.q_bool_null)' ,'last(t2.q_ts_null)'] + + self.calc_select_in_support_ts_j = ['bottom(t1.q_int,20)' , 'bottom(t1.q_bigint,20)' , 'bottom(t1.q_smallint,20)' , 'bottom(t1.q_tinyint,20)' ,'bottom(t1.q_float,20)' , 'bottom(t1.q_double,20)' , 'top(t1.q_int,20)' , 'top(t1.q_bigint,20)' , 'top(t1.q_smallint,20)' ,'top(t1.q_tinyint,20)' ,'top(t1.q_float,20)' ,'top(t1.q_double,20)' , 'min(t1.q_int)' , 'min(t1.q_bigint)' , 'min(t1.q_smallint)' , 'min(t1.q_tinyint)' , 'min(t1.q_float)' ,'min(t1.q_double)' , 'max(t1.q_int)' , 'max(t1.q_bigint)' , 'max(t1.q_smallint)' , 'max(t1.q_tinyint)' ,'max(t1.q_float)' ,'max(t1.q_double)' , @@ -532,2045 +411,5790 @@ class TDTestCase: 'top(t2.q_int,20)' , 'top(t2.q_bigint,20)' , 'top(t2.q_smallint,20)' ,'top(t2.q_tinyint,20)' ,'top(t2.q_float,20)' ,'top(t2.q_double,20)' , 'min(t2.q_int)' , 'min(t2.q_bigint)' , 'min(t2.q_smallint)' , 'min(t2.q_tinyint)' , 'min(t2.q_float)' ,'min(t2.q_double)' , 'max(t2.q_int)' , 'max(t2.q_bigint)' , 'max(t2.q_smallint)' , 'max(t2.q_tinyint)' ,'max(t2.q_float)' ,'max(t2.q_double)' , - ] - - calc_select_in_not_support_ts_j = ['apercentile(t1.q_int,20)' , 'apercentile(t1.q_bigint,20)' ,'apercentile(t1.q_smallint,20)' ,'apercentile(t1.q_tinyint,20)' ,'apercentile(t1.q_float,20)' ,'apercentile(t1.q_double,20)' , - 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , + 'bottom(t1.q_int_null,20)' , 'bottom(t1.q_bigint_null,20)' , 'bottom(t1.q_smallint_null,20)' , 'bottom(t1.q_tinyint_null,20)' ,'bottom(t1.q_float_null,20)' , 'bottom(t1.q_double_null,20)' , + 'top(t1.q_int_null,20)' , 'top(t1.q_bigint_null,20)' , 'top(t1.q_smallint_null,20)' ,'top(t1.q_tinyint_null,20)' ,'top(t1.q_float_null,20)' ,'top(t1.q_double_null,20)' , + 'bottom(t2.q_int_null,20)' , 'bottom(t2.q_bigint_null,20)' , 'bottom(t2.q_smallint_null,20)' , 'bottom(t2.q_tinyint_null,20)' ,'bottom(t2.q_float_null,20)' , 'bottom(t2.q_double_null,20)' , + 'top(t2.q_int_null,20)' , 'top(t2.q_bigint_null,20)' , 'top(t2.q_smallint_null,20)' ,'top(t2.q_tinyint_null,20)' ,'top(t2.q_float_null,20)' ,'top(t2.q_double_null,20)' , + 'min(t1.q_int_null)' , 'min(t1.q_bigint_null)' , 'min(t1.q_smallint_null)' , 'min(t1.q_tinyint_null)' , 'min(t1.q_float_null)' ,'min(t1.q_double_null)' , + 'max(t1.q_int_null)' , 'max(t1.q_bigint_null)' , 'max(t1.q_smallint_null)' , 'max(t1.q_tinyint_null)' ,'max(t1.q_float_null)' ,'max(t1.q_double_null)' , + 'min(t2.q_int_null)' , 'min(t2.q_bigint_null)' , 'min(t2.q_smallint_null)' , 'min(t2.q_tinyint_null)' , 'min(t2.q_float_null)' ,'min(t2.q_double_null)' , + 'max(t2.q_int_null)' , 'max(t2.q_bigint_null)' , 'max(t2.q_smallint_null)' , 'max(t2.q_tinyint_null)' ,'max(t2.q_float_null)' ,'max(t2.q_double_null)' ] + + self.calc_select_in_not_support_ts_j = ['apercentile(t1.q_int,20)' , 'apercentile(t1.q_bigint,20)' ,'apercentile(t1.q_smallint,20)' ,'apercentile(t1.q_tinyint,20)' ,'apercentile(t1.q_float,20)' ,'apercentile(t1.q_double,20)' , + 'apercentile(t1.q_int_null,20)' , 'apercentile(t1.q_bigint_null,20)' ,'apercentile(t1.q_smallint_null,20)' ,'apercentile(t1.q_tinyint_null,20)' ,'apercentile(t1.q_float_null,20)' ,'apercentile(t1.q_double_null,20)' , + 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , 'last_row(t1.q_double)' , 'last_row(t1.q_bool)' ,'last_row(t1.q_binary)' ,'last_row(t1.q_nchar)' ,'last_row(t1.q_ts)' , + 'last_row(t1.q_int_null)' , 'last_row(t1.q_bigint_null)' , 'last_row(t1.q_smallint_null)' , 'last_row(t1.q_tinyint_null)' , 'last_row(t1.q_float_null)' , + 'last_row(t1.q_double_null)' , 'last_row(t1.q_bool_null)' ,'last_row(t1.q_binary_null)' ,'last_row(t1.q_nchar_null)' ,'last_row(t1.q_ts_null)' , 'apercentile(t2.q_int,20)' , 'apercentile(t2.q_bigint,20)' ,'apercentile(t2.q_smallint,20)' ,'apercentile(t2.q_tinyint,20)' ,'apercentile(t2.q_float,20)' ,'apercentile(t2.q_double,20)' , - 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , - 'last_row(t2.q_double)' , 'last_row(t2.q_bool)' ,'last_row(t2.q_binary)' ,'last_row(t2.q_nchar)' ,'last_row(t2.q_ts)'] + 'apercentile(t2.q_int_null,20)' , 'apercentile(t2.q_bigint_null,20)' ,'apercentile(t2.q_smallint_null,20)' ,'apercentile(t2.q_tinyint_null,20)' ,'apercentile(t2.q_float_null,20)' ,'apercentile(t2.q_double_null,20)' , + 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , + 'last_row(t2.q_double)' , 'last_row(t2.q_bool)' ,'last_row(t2.q_binary)' ,'last_row(t2.q_nchar)' ,'last_row(t2.q_ts)', + 'last_row(t2.q_int_null)' , 'last_row(t2.q_bigint_null)' , 'last_row(t2.q_smallint_null)' , 'last_row(t2.q_tinyint_null)' , 'last_row(t2.q_float_null)' , + 'last_row(t2.q_double_null)' , 'last_row(t2.q_bool_null)' ,'last_row(t2.q_binary_null)' ,'last_row(t2.q_nchar_null)' ,'last_row(t2.q_ts_null)'] - calc_select_in_j = ['min(t1.q_int)' , 'min(t1.q_bigint)' , 'min(t1.q_smallint)' , 'min(t1.q_tinyint)' , 'min(t1.q_float)' ,'min(t1.q_double)' , + self.calc_select_in_j = ['min(t1.q_int)' , 'min(t1.q_bigint)' , 'min(t1.q_smallint)' , 'min(t1.q_tinyint)' , 'min(t1.q_float)' ,'min(t1.q_double)' , 'max(t1.q_int)' , 'max(t1.q_bigint)' , 'max(t1.q_smallint)' , 'max(t1.q_tinyint)' ,'max(t1.q_float)' ,'max(t1.q_double)' , 'apercentile(t1.q_int,20)' , 'apercentile(t1.q_bigint,20)' ,'apercentile(t1.q_smallint,20)' ,'apercentile(t1.q_tinyint,20)' ,'apercentile(t1.q_float,20)' ,'apercentile(t1.q_double,20)' , - 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , + 'min(t1.q_int_null)' , 'min(t1.q_bigint_null)' , 'min(t1.q_smallint_null)' , 'min(t1.q_tinyint_null)' , 'min(t1.q_float_null)' ,'min(t1.q_double_null)' , + 'max(t1.q_int_null)' , 'max(t1.q_bigint_null)' , 'max(t1.q_smallint_null)' , 'max(t1.q_tinyint_null)' ,'max(t1.q_float_null)' ,'max(t1.q_double_null)' , + 'apercentile(t1.q_int_null,20)' , 'apercentile(t1.q_bigint_null,20)' ,'apercentile(t1.q_smallint_null,20)' ,'apercentile(t1.q_tinyint_null,20)' ,'apercentile(t1.q_float_null,20)' ,'apercentile(t1.q_double_null,20)' , + 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , 'last_row(t1.q_double)' , 'last_row(t1.q_bool)' ,'last_row(t1.q_binary)' ,'last_row(t1.q_nchar)' ,'last_row(t1.q_ts)' , 'min(t2.q_int)' , 'min(t2.q_bigint)' , 'min(t2.q_smallint)' , 'min(t2.q_tinyint)' , 'min(t2.q_float)' ,'min(t2.q_double)' , 'max(t2.q_int)' , 'max(t2.q_bigint)' , 'max(t2.q_smallint)' , 'max(t2.q_tinyint)' ,'max(t2.q_float)' ,'max(t2.q_double)' , + 'last_row(t1.q_int_null)' , 'last_row(t1.q_bigint_null)' , 'last_row(t1.q_smallint_null)' , 'last_row(t1.q_tinyint_null)' , 'last_row(t1.q_float_null)' , + 'last_row(t1.q_double_null)' , 'last_row(t1.q_bool_null)' ,'last_row(t1.q_binary_null)' ,'last_row(t1.q_nchar_null)' ,'last_row(t1.q_ts_null)' , + 'min(t2.q_int_null)' , 'min(t2.q_bigint_null)' , 'min(t2.q_smallint_null)' , 'min(t2.q_tinyint_null)' , 'min(t2.q_float_null)' ,'min(t2.q_double_null)' , + 'max(t2.q_int_null)' , 'max(t2.q_bigint_null)' , 'max(t2.q_smallint_null)' , 'max(t2.q_tinyint_null)' ,'max(t2.q_float_null)' ,'max(t2.q_double_null)' , 'apercentile(t2.q_int,20)' , 'apercentile(t2.q_bigint,20)' ,'apercentile(t2.q_smallint,20)' ,'apercentile(t2.q_tinyint,20)' ,'apercentile(t2.q_float,20)' ,'apercentile(t2.q_double,20)' , - 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , - 'last_row(t2.q_double)' , 'last_row(t2.q_bool)' ,'last_row(t2.q_binary)' ,'last_row(t2.q_nchar)' ,'last_row(t2.q_ts)'] - calc_select_all_j = calc_select_in_ts_j + calc_select_in_j - - calc_select_regular_j = [ 'PERCENTILE(t1.q_int,10)' ,'PERCENTILE(t1.q_bigint,20)' , 'PERCENTILE(t1.q_smallint,30)' ,'PERCENTILE(t1.q_tinyint,40)' ,'PERCENTILE(t1.q_float,50)' ,'PERCENTILE(t1.q_double,60)' , - 'PERCENTILE(t2.q_int,10)' ,'PERCENTILE(t2.q_bigint,20)' , 'PERCENTILE(t2.q_smallint,30)' ,'PERCENTILE(t2.q_tinyint,40)' ,'PERCENTILE(t2.q_float,50)' ,'PERCENTILE(t2.q_double,60)'] - - - calc_select_fill_j = ['INTERP(t1.q_int)' ,'INTERP(t1.q_bigint)' ,'INTERP(t1.q_smallint)' ,'INTERP(t1.q_tinyint)', 'INTERP(t1.q_float)' ,'INTERP(t1.q_double)' , + 'apercentile(t2.q_int_null,20)' , 'apercentile(t2.q_bigint_null,20)' ,'apercentile(t2.q_smallint_null,20)' ,'apercentile(t2.q_tinyint_null,20)' ,'apercentile(t2.q_float_null,20)' ,'apercentile(t2.q_double_null,20)' , + 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , + 'last_row(t2.q_double)' , 'last_row(t2.q_bool)' ,'last_row(t2.q_binary)' ,'last_row(t2.q_nchar)' ,'last_row(t2.q_ts)', + 'last_row(t2.q_int_null)' , 'last_row(t2.q_bigint_null)' , 'last_row(t2.q_smallint_null)' , 'last_row(t2.q_tinyint_null)' , 'last_row(t2.q_float_null)' , + 'last_row(t2.q_double_null)' , 'last_row(t2.q_bool_null)' ,'last_row(t2.q_binary_null)' ,'last_row(t2.q_nchar_null)' ,'last_row(t2.q_ts_null)'] + self.calc_select_all_j = self.calc_select_in_ts_j + self.calc_select_in_j + + self.calc_select_regular_j = [ 'PERCENTILE(t1.q_int,10)' ,'PERCENTILE(t1.q_bigint,20)' , 'PERCENTILE(t1.q_smallint,30)' ,'PERCENTILE(t1.q_tinyint,40)' ,'PERCENTILE(t1.q_float,50)' ,'PERCENTILE(t1.q_double,60)' , + 'PERCENTILE(t2.q_int,10)' ,'PERCENTILE(t2.q_bigint,20)' , 'PERCENTILE(t2.q_smallint,30)' ,'PERCENTILE(t2.q_tinyint,40)' ,'PERCENTILE(t2.q_float,50)' ,'PERCENTILE(t2.q_double,60)', + 'PERCENTILE(t1.q_int_null,10)' ,'PERCENTILE(t1.q_bigint_null,20)' , 'PERCENTILE(t1.q_smallint_null,30)' ,'PERCENTILE(t1.q_tinyint_null,40)' ,'PERCENTILE(t1.q_float_null,50)' ,'PERCENTILE(t1.q_double_null,60)' , + 'PERCENTILE(t2.q_int_null,10)' ,'PERCENTILE(t2.q_bigint_null,20)' , 'PERCENTILE(t2.q_smallint_null,30)' ,'PERCENTILE(t2.q_tinyint_null,40)' ,'PERCENTILE(t2.q_float_null,50)' ,'PERCENTILE(t2.q_double_null,60)'] + + + self.calc_select_fill_j = ['INTERP(t1.q_int)' ,'INTERP(t1.q_bigint)' ,'INTERP(t1.q_smallint)' ,'INTERP(t1.q_tinyint)', 'INTERP(t1.q_float)' ,'INTERP(t1.q_double)' , 'INTERP(t2.q_int)' ,'INTERP(t2.q_bigint)' ,'INTERP(t2.q_smallint)' ,'INTERP(t2.q_tinyint)', 'INTERP(t2.q_float)' ,'INTERP(t2.q_double)'] - interp_where_j = ['t1.ts = now' , 't1.ts = \'2020-09-13 20:26:40.000\'' , 't1.ts = \'2020-09-13 20:26:40.009\'' ,'t2.ts = now' , 't2.ts = \'2020-09-13 20:26:40.000\'' , 't2.ts = \'2020-09-13 20:26:40.009\'' , + self.interp_where_j = ['t1.ts = now' , 't1.ts = \'2020-09-13 20:26:40.000\'' , 't1.ts = \'2020-09-13 20:26:40.009\'' ,'t2.ts = now' , 't2.ts = \'2020-09-13 20:26:40.000\'' , 't2.ts = \'2020-09-13 20:26:40.009\'' , 't1.tbname in (\'table_1\') and t1.ts = now' ,'t1.tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and t1.ts = \'2020-09-13 20:26:40.000\'','t1.tbname like \'table%\' and t1.ts = \'2020-09-13 20:26:40.002\'', 't2.tbname in (\'table_1\') and t2.ts = now' ,'t2.tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and t2.ts = \'2020-09-13 20:26:40.000\'','t2.tbname like \'table%\' and t2.ts = \'2020-09-13 20:26:40.002\''] # calc_aggregate_all calc_aggregate_regular calc_aggregate_groupbytbname APERCENTILE\PERCENTILE # aggregate function include [all:count(*)\avg\sum\stddev ||regualr:twa\irate\leastsquares ||group by tbname:twa\irate\] - calc_aggregate_all = ['count(*)' , 'count(q_int)' ,'count(q_bigint)' , 'count(q_smallint)' ,'count(q_tinyint)' ,'count(q_float)' , + self.calc_aggregate_all = ['count(*)' , 'count(q_int)' ,'count(q_bigint)' , 'count(q_smallint)' ,'count(q_tinyint)' ,'count(q_float)' , 'count(q_double)' ,'count(q_binary)' ,'count(q_nchar)' ,'count(q_bool)' ,'count(q_ts)' , 'avg(q_int)' ,'avg(q_bigint)' , 'avg(q_smallint)' ,'avg(q_tinyint)' ,'avg(q_float)' ,'avg(q_double)' , 'sum(q_int)' ,'sum(q_bigint)' , 'sum(q_smallint)' ,'sum(q_tinyint)' ,'sum(q_float)' ,'sum(q_double)' , 'STDDEV(q_int)' ,'STDDEV(q_bigint)' , 'STDDEV(q_smallint)' ,'STDDEV(q_tinyint)' ,'STDDEV(q_float)' ,'STDDEV(q_double)', - 'APERCENTILE(q_int,10)' ,'APERCENTILE(q_bigint,20)' , 'APERCENTILE(q_smallint,30)' ,'APERCENTILE(q_tinyint,40)' ,'APERCENTILE(q_float,50)' ,'APERCENTILE(q_double,60)'] - - calc_aggregate_regular = ['twa(q_int)' ,'twa(q_bigint)' , 'twa(q_smallint)' ,'twa(q_tinyint)' ,'twa (q_float)' ,'twa(q_double)' , + 'APERCENTILE(q_int,10)' ,'APERCENTILE(q_bigint,20)' , 'APERCENTILE(q_smallint,30)' ,'APERCENTILE(q_tinyint,40)' ,'APERCENTILE(q_float,50)' ,'APERCENTILE(q_double,60)', + 'count(q_int_null)' ,'count(q_bigint_null)' , 'count(q_smallint_null)' ,'count(q_tinyint_null)' ,'count(q_float_null)' , + 'count(q_double_null)' ,'count(q_binary_null)' ,'count(q_nchar_null)' ,'count(q_bool_null)' ,'count(q_ts_null)' , + 'avg(q_int_null)' ,'avg(q_bigint_null)' , 'avg(q_smallint_null)' ,'avg(q_tinyint_null)' ,'avg(q_float_null)' ,'avg(q_double_null)' , + 'sum(q_int_null)' ,'sum(q_bigint_null)' , 'sum(q_smallint_null)' ,'sum(q_tinyint_null)' ,'sum(q_float_null)' ,'sum(q_double_null)' , + 'STDDEV(q_int_null)' ,'STDDEV(q_bigint_null)' , 'STDDEV(q_smallint_null)' ,'STDDEV(q_tinyint_null)' ,'STDDEV(q_float_null)' ,'STDDEV(q_double_null)', + 'APERCENTILE(q_int_null,10)' ,'APERCENTILE(q_bigint_null,20)' , 'APERCENTILE(q_smallint_null,30)' ,'APERCENTILE(q_tinyint_null,40)' ,'APERCENTILE(q_float_null,50)' ,'APERCENTILE(q_double_null,60)'] + + self.calc_aggregate_regular = ['twa(q_int)' ,'twa(q_bigint)' , 'twa(q_smallint)' ,'twa(q_tinyint)' ,'twa (q_float)' ,'twa(q_double)' , 'IRATE(q_int)' ,'IRATE(q_bigint)' , 'IRATE(q_smallint)' ,'IRATE(q_tinyint)' ,'IRATE (q_float)' ,'IRATE(q_double)' , + 'twa(q_int_null)' ,'twa(q_bigint_null)' , 'twa(q_smallint_null)' ,'twa(q_tinyint_null)' ,'twa (q_float_null)' ,'twa(q_double_null)' , + 'IRATE(q_int_null)' ,'IRATE(q_bigint_null)' , 'IRATE(q_smallint_null)' ,'IRATE(q_tinyint_null)' ,'IRATE (q_float_null)' ,'IRATE(q_double_null)' , 'LEASTSQUARES(q_int,15,3)' , 'LEASTSQUARES(q_bigint,10,1)' , 'LEASTSQUARES(q_smallint,20,3)' ,'LEASTSQUARES(q_tinyint,10,4)' ,'LEASTSQUARES(q_float,6,4)' ,'LEASTSQUARES(q_double,3,1)' , - 'PERCENTILE(q_int,10)' ,'PERCENTILE(q_bigint,20)' , 'PERCENTILE(q_smallint,30)' ,'PERCENTILE(q_tinyint,40)' ,'PERCENTILE(q_float,50)' ,'PERCENTILE(q_double,60)'] + 'PERCENTILE(q_int,10)' ,'PERCENTILE(q_bigint,20)' , 'PERCENTILE(q_smallint,30)' ,'PERCENTILE(q_tinyint,40)' ,'PERCENTILE(q_float,50)' ,'PERCENTILE(q_double,60)', + 'LEASTSQUARES(q_int_null,15,3)' , 'LEASTSQUARES(q_bigint_null,10,1)' , 'LEASTSQUARES(q_smallint_null,20,3)' ,'LEASTSQUARES(q_tinyint_null,10,4)' ,'LEASTSQUARES(q_float_null,6,4)' ,'LEASTSQUARES(q_double_null,3,1)' , + 'PERCENTILE(q_int_null,10)' ,'PERCENTILE(q_bigint_null,20)' , 'PERCENTILE(q_smallint_null,30)' ,'PERCENTILE(q_tinyint_null,40)' ,'PERCENTILE(q_float_null,50)' ,'PERCENTILE(q_double_null,60)'] - calc_aggregate_groupbytbname = ['twa(q_int)' ,'twa(q_bigint)' , 'twa(q_smallint)' ,'twa(q_tinyint)' ,'twa (q_float)' ,'twa(q_double)' , - 'IRATE(q_int)' ,'IRATE(q_bigint)' , 'IRATE(q_smallint)' ,'IRATE(q_tinyint)' ,'IRATE (q_float)' ,'IRATE(q_double)' ] + self.calc_aggregate_groupbytbname = ['twa(q_int)' ,'twa(q_bigint)' , 'twa(q_smallint)' ,'twa(q_tinyint)' ,'twa (q_float)' ,'twa(q_double)' , + 'IRATE(q_int)' ,'IRATE(q_bigint)' , 'IRATE(q_smallint)' ,'IRATE(q_tinyint)' ,'IRATE (q_float)' ,'IRATE(q_double)', + 'twa(q_int_null)' ,'twa(q_bigint_null)' , 'twa(q_smallint_null)' ,'twa(q_tinyint_null)' ,'twa (q_float_null)' ,'twa(q_double_null)' , + 'IRATE(q_int_null)' ,'IRATE(q_bigint_null)' , 'IRATE(q_smallint_null)' ,'IRATE(q_tinyint_null)' ,'IRATE (q_float_null)' ,'IRATE(q_double_null)'] #two table join - calc_aggregate_all_j = ['count(t1.*)' , 'count(t1.q_int)' ,'count(t1.q_bigint)' , 'count(t1.q_smallint)' ,'count(t1.q_tinyint)' ,'count(t1.q_float)' , + self.calc_aggregate_all_j = ['count(t1.*)' , 'count(t1.q_int)' ,'count(t1.q_bigint)' , 'count(t1.q_smallint)' ,'count(t1.q_tinyint)' ,'count(t1.q_float)' , 'count(t1.q_double)' ,'count(t1.q_binary)' ,'count(t1.q_nchar)' ,'count(t1.q_bool)' ,'count(t1.q_ts)' , 'avg(t1.q_int)' ,'avg(t1.q_bigint)' , 'avg(t1.q_smallint)' ,'avg(t1.q_tinyint)' ,'avg(t1.q_float)' ,'avg(t1.q_double)' , 'sum(t1.q_int)' ,'sum(t1.q_bigint)' , 'sum(t1.q_smallint)' ,'sum(t1.q_tinyint)' ,'sum(t1.q_float)' ,'sum(t1.q_double)' , 'STDDEV(t1.q_int)' ,'STDDEV(t1.q_bigint)' , 'STDDEV(t1.q_smallint)' ,'STDDEV(t1.q_tinyint)' ,'STDDEV(t1.q_float)' ,'STDDEV(t1.q_double)', 'APERCENTILE(t1.q_int,10)' ,'APERCENTILE(t1.q_bigint,20)' , 'APERCENTILE(t1.q_smallint,30)' ,'APERCENTILE(t1.q_tinyint,40)' ,'APERCENTILE(t1.q_float,50)' ,'APERCENTILE(t1.q_double,60)' , + 'count(t1.q_int_null)' ,'count(t1.q_bigint_null)' , 'count(t1.q_smallint_null)' ,'count(t1.q_tinyint_null)' ,'count(t1.q_float_null)' , + 'count(t1.q_double_null)' ,'count(t1.q_binary_null)' ,'count(t1.q_nchar_null)' ,'count(t1.q_bool_null)' ,'count(t1.q_ts_null)' , + 'avg(t1.q_int_null)' ,'avg(t1.q_bigint_null)' , 'avg(t1.q_smallint_null)' ,'avg(t1.q_tinyint_null)' ,'avg(t1.q_float_null)' ,'avg(t1.q_double_null)' , + 'sum(t1.q_int_null)' ,'sum(t1.q_bigint_null)' , 'sum(t1.q_smallint_null)' ,'sum(t1.q_tinyint_null)' ,'sum(t1.q_float_null)' ,'sum(t1.q_double_null)' , + 'STDDEV(t1.q_int_null)' ,'STDDEV(t1.q_bigint_null)' , 'STDDEV(t1.q_smallint_null)' ,'STDDEV(t1.q_tinyint_null)' ,'STDDEV(t1.q_float_null)' ,'STDDEV(t1.q_double_null)', + 'APERCENTILE(t1.q_int_null,10)' ,'APERCENTILE(t1.q_bigint_null,20)' , 'APERCENTILE(t1.q_smallint_null,30)' ,'APERCENTILE(t1.q_tinyint_null,40)' ,'APERCENTILE(t1.q_float_null,50)' ,'APERCENTILE(t1.q_double,60)' , 'count(t2.*)' , 'count(t2.q_int)' ,'count(t2.q_bigint)' , 'count(t2.q_smallint)' ,'count(t2.q_tinyint)' ,'count(t2.q_float)' , 'count(t2.q_double)' ,'count(t2.q_binary)' ,'count(t2.q_nchar)' ,'count(t2.q_bool)' ,'count(t2.q_ts)' , 'avg(t2.q_int)' ,'avg(t2.q_bigint)' , 'avg(t2.q_smallint)' ,'avg(t2.q_tinyint)' ,'avg(t2.q_float)' ,'avg(t2.q_double)' , 'sum(t2.q_int)' ,'sum(t2.q_bigint)' , 'sum(t2.q_smallint)' ,'sum(t2.q_tinyint)' ,'sum(t2.q_float)' ,'sum(t2.q_double)' , 'STDDEV(t2.q_int)' ,'STDDEV(t2.q_bigint)' , 'STDDEV(t2.q_smallint)' ,'STDDEV(t2.q_tinyint)' ,'STDDEV(t2.q_float)' ,'STDDEV(t2.q_double)', - 'APERCENTILE(t2.q_int,10)' ,'APERCENTILE(t2.q_bigint,20)' , 'APERCENTILE(t2.q_smallint,30)' ,'APERCENTILE(t2.q_tinyint,40)' ,'APERCENTILE(t2.q_float,50)' ,'APERCENTILE(t2.q_double,60)'] - - calc_aggregate_regular_j = ['twa(t1.q_int)' ,'twa(t1.q_bigint)' , 'twa(t1.q_smallint)' ,'twa(t1.q_tinyint)' ,'twa (t1.q_float)' ,'twa(t1.q_double)' , + 'APERCENTILE(t2.q_int,10)' ,'APERCENTILE(t2.q_bigint,20)' , 'APERCENTILE(t2.q_smallint,30)' ,'APERCENTILE(t2.q_tinyint,40)' ,'APERCENTILE(t2.q_float,50)' ,'APERCENTILE(t2.q_double,60)', + 'count(t2.q_int_null)' ,'count(t2.q_bigint_null)' , 'count(t2.q_smallint_null)' ,'count(t2.q_tinyint_null)' ,'count(t2.q_float_null)' , + 'count(t2.q_double_null)' ,'count(t2.q_binary_null)' ,'count(t2.q_nchar_null)' ,'count(t2.q_bool_null)' ,'count(t2.q_ts_null)' , + 'avg(t2.q_int_null)' ,'avg(t2.q_bigint_null)' , 'avg(t2.q_smallint_null)' ,'avg(t2.q_tinyint_null)' ,'avg(t2.q_float_null)' ,'avg(t2.q_double_null)' , + 'sum(t2.q_int_null)' ,'sum(t2.q_bigint_null)' , 'sum(t2.q_smallint_null)' ,'sum(t2.q_tinyint_null)' ,'sum(t2.q_float_null)' ,'sum(t2.q_double_null)' , + 'STDDEV(t2.q_int_null)' ,'STDDEV(t2.q_bigint_null)' , 'STDDEV(t2.q_smallint_null)' ,'STDDEV(t2.q_tinyint_null)' ,'STDDEV(t2.q_float_null)' ,'STDDEV(t2.q_double_null)', + 'APERCENTILE(t2.q_int_null,10)' ,'APERCENTILE(t2.q_bigint_null,20)' , 'APERCENTILE(t2.q_smallint_null,30)' ,'APERCENTILE(t2.q_tinyint_null,40)' ,'APERCENTILE(t2.q_float_null,50)' ,'APERCENTILE(t2.q_double,60)'] + + self.calc_aggregate_regular_j = ['twa(t1.q_int)' ,'twa(t1.q_bigint)' , 'twa(t1.q_smallint)' ,'twa(t1.q_tinyint)' ,'twa (t1.q_float)' ,'twa(t1.q_double)' , 'IRATE(t1.q_int)' ,'IRATE(t1.q_bigint)' , 'IRATE(t1.q_smallint)' ,'IRATE(t1.q_tinyint)' ,'IRATE (t1.q_float)' ,'IRATE(t1.q_double)' , 'LEASTSQUARES(t1.q_int,15,3)' , 'LEASTSQUARES(t1.q_bigint,10,1)' , 'LEASTSQUARES(t1.q_smallint,20,3)' ,'LEASTSQUARES(t1.q_tinyint,10,4)' ,'LEASTSQUARES(t1.q_float,6,4)' ,'LEASTSQUARES(t1.q_double,3,1)' , - 'PERCENTILE(t1.q_int,10)' ,'PERCENTILE(t1.q_bigint,20)' , 'PERCENTILE(t1.q_smallint,30)' ,'PERCENTILE(t1.q_tinyint,40)' ,'PERCENTILE(t1.q_float,50)' ,'PERCENTILE(t1.q_double,60)' , 'twa(t2.q_int)' ,'twa(t2.q_bigint)' , 'twa(t2.q_smallint)' ,'twa(t2.q_tinyint)' ,'twa (t2.q_float)' ,'twa(t2.q_double)' , 'IRATE(t2.q_int)' ,'IRATE(t2.q_bigint)' , 'IRATE(t2.q_smallint)' ,'IRATE(t2.q_tinyint)' ,'IRATE (t2.q_float)' ,'IRATE(t2.q_double)', 'LEASTSQUARES(t2.q_int,15,3)' , 'LEASTSQUARES(t2.q_bigint,10,1)' , 'LEASTSQUARES(t2.q_smallint,20,3)' ,'LEASTSQUARES(t2.q_tinyint,10,4)' ,'LEASTSQUARES(t2.q_float,6,4)' ,'LEASTSQUARES(t2.q_double,3,1)' , - 'PERCENTILE(t2.q_int,10)' ,'PERCENTILE(t2.q_bigint,20)' , 'PERCENTILE(t2.q_smallint,30)' ,'PERCENTILE(t2.q_tinyint,40)' ,'PERCENTILE(t2.q_float,50)' ,'PERCENTILE(t2.q_double,60)'] - - calc_aggregate_groupbytbname_j = ['twa(t1.q_int)' ,'twa(t1.q_bigint)' , 'twa(t1.q_smallint)' ,'twa(t1.q_tinyint)' ,'twa (t1.q_float)' ,'twa(t1.q_double)' , + 'twa(t1.q_int_null)' ,'twa(t1.q_bigint_null)' , 'twa(t1.q_smallint_null)' ,'twa(t1.q_tinyint_null)' ,'twa (t1.q_float_null)' ,'twa(t1.q_double_null)' , + 'IRATE(t1.q_int_null)' ,'IRATE(t1.q_bigint_null)' , 'IRATE(t1.q_smallint_null)' ,'IRATE(t1.q_tinyint_null)' ,'IRATE (t1.q_float_null)' ,'IRATE(t1.q_double_null)' , + 'LEASTSQUARES(t1.q_int_null,15,3)' , 'LEASTSQUARES(t1.q_bigint_null,10,1)' , 'LEASTSQUARES(t1.q_smallint_null,20,3)' ,'LEASTSQUARES(t1.q_tinyint_null,10,4)' ,'LEASTSQUARES(t1.q_float_null,6,4)' ,'LEASTSQUARES(t1.q_double_null,3,1)' , + 'twa(t2.q_int_null)' ,'twa(t2.q_bigint_null)' , 'twa(t2.q_smallint_null)' ,'twa(t2.q_tinyint_null)' ,'twa (t2.q_float_null)' ,'twa(t2.q_double_null)' , + 'IRATE(t2.q_int_null)' ,'IRATE(t2.q_bigint_null)' , 'IRATE(t2.q_smallint_null)' ,'IRATE(t2.q_tinyint_null)' ,'IRATE (t2.q_float_null)' ,'IRATE(t2.q_double_null)', + 'LEASTSQUARES(t2.q_int_null,15,3)' , 'LEASTSQUARES(t2.q_bigint_null,10,1)' , 'LEASTSQUARES(t2.q_smallint_null,20,3)' ,'LEASTSQUARES(t2.q_tinyint_null,10,4)' ,'LEASTSQUARES(t2.q_float_null,6,4)' ,'LEASTSQUARES(t2.q_double_null,3,1)' ] + + self.calc_aggregate_groupbytbname_j = ['twa(t1.q_int)' ,'twa(t1.q_bigint)' , 'twa(t1.q_smallint)' ,'twa(t1.q_tinyint)' ,'twa (t1.q_float)' ,'twa(t1.q_double)' , 'IRATE(t1.q_int)' ,'IRATE(t1.q_bigint)' , 'IRATE(t1.q_smallint)' ,'IRATE(t1.q_tinyint)' ,'IRATE (t1.q_float)' ,'IRATE(t1.q_double)' , 'twa(t2.q_int)' ,'twa(t2.q_bigint)' , 'twa(t2.q_smallint)' ,'twa(t2.q_tinyint)' ,'twa (t2.q_float)' ,'twa(t2.q_double)' , - 'IRATE(t2.q_int)' ,'IRATE(t2.q_bigint)' , 'IRATE(t2.q_smallint)' ,'IRATE(t2.q_tinyint)' ,'IRATE (t2.q_float)' ,'IRATE(t2.q_double)' ] - + 'IRATE(t2.q_int)' ,'IRATE(t2.q_bigint)' , 'IRATE(t2.q_smallint)' ,'IRATE(t2.q_tinyint)' ,'IRATE (t2.q_float)' ,'IRATE(t2.q_double)' , + 'twa(t1.q_int_null)' ,'twa(t1.q_bigint_null)' , 'twa(t1.q_smallint_null)' ,'twa(t1.q_tinyint_null)' ,'twa (t1.q_float_null)' ,'twa(t1.q_double_null)' , + 'IRATE(t1.q_int_null)' ,'IRATE(t1.q_bigint_null)' , 'IRATE(t1.q_smallint_null)' ,'IRATE(t1.q_tinyint_null)' ,'IRATE (t1.q_float_null)' ,'IRATE(t1.q_double_null)' , + 'twa(t2.q_int_null)' ,'twa(t2.q_bigint_null)' , 'twa(t2.q_smallint_null)' ,'twa(t2.q_tinyint_null)' ,'twa (t2.q_float_null)' ,'twa(t2.q_double_null)' , + 'IRATE(t2.q_int_null)' ,'IRATE(t2.q_bigint_null)' , 'IRATE(t2.q_smallint_null)' ,'IRATE(t2.q_tinyint_null)' ,'IRATE (t2.q_float_null)' ,'IRATE(t2.q_double_null)' ] + # calc_calculate_all calc_calculate_regular calc_calculate_groupbytbname # calculation function include [all:spread\+-*/ ||regualr:diff\derivative ||group by tbname:diff\derivative\] - calc_calculate_all = ['SPREAD(ts)' , 'SPREAD(q_ts)' , 'SPREAD(q_int)' ,'SPREAD(q_bigint)' , 'SPREAD(q_smallint)' ,'SPREAD(q_tinyint)' ,'SPREAD(q_float)' ,'SPREAD(q_double)' , - '(SPREAD(q_int) + SPREAD(q_bigint))' , '(SPREAD(q_smallint) - SPREAD(q_float))', '(SPREAD(q_double) * SPREAD(q_tinyint))' , '(SPREAD(q_double) / SPREAD(q_float))'] - calc_calculate_regular = ['DIFF(q_int)' ,'DIFF(q_bigint)' , 'DIFF(q_smallint)' ,'DIFF(q_tinyint)' ,'DIFF(q_float)' ,'DIFF(q_double)' , - 'DIFF(q_int,0)' ,'DIFF(q_bigint,0)' , 'DIFF(q_smallint,0)' ,'DIFF(q_tinyint,0)' ,'DIFF(q_float,0)' ,'DIFF(q_double,0)' , - 'DIFF(q_int,1)' ,'DIFF(q_bigint,1)' , 'DIFF(q_smallint,1)' ,'DIFF(q_tinyint,1)' ,'DIFF(q_float,1)' ,'DIFF(q_double,1)' , - 'DERIVATIVE(q_int,15s,0)' , 'DERIVATIVE(q_bigint,10s,1)' , 'DERIVATIVE(q_smallint,20s,0)' ,'DERIVATIVE(q_tinyint,10s,1)' ,'DERIVATIVE(q_float,6s,0)' ,'DERIVATIVE(q_double,3s,1)' ] - calc_calculate_groupbytbname = calc_calculate_regular - + self.calc_calculate_all = ['SPREAD(ts)' , 'SPREAD(q_ts)' , 'SPREAD(q_int)' ,'SPREAD(q_bigint)' , 'SPREAD(q_smallint)' ,'SPREAD(q_tinyint)' ,'SPREAD(q_float)' ,'SPREAD(q_double)' , + '(SPREAD(q_int) + SPREAD(q_bigint))' , '(SPREAD(q_smallint) - SPREAD(q_float))', '(SPREAD(q_double) * SPREAD(q_tinyint))' , '(SPREAD(q_double) / SPREAD(q_float))', + 'SPREAD(q_ts_null)' , 'SPREAD(q_int_null)' ,'SPREAD(q_bigint_null)' , 'SPREAD(q_smallint_null)' ,'SPREAD(q_tinyint_null)' ,'SPREAD(q_float_null)' ,'SPREAD(q_double_null)' , + '(SPREAD(q_int_null) + SPREAD(q_bigint_null))' , '(SPREAD(q_smallint_null) - SPREAD(q_float_null))', '(SPREAD(q_double_null) * SPREAD(q_tinyint_null))' , '(SPREAD(q_double_null) / SPREAD(q_float_null))'] + self.calc_calculate_regular = ['DIFF(q_int)' ,'DIFF(q_bigint)' , 'DIFF(q_smallint)' ,'DIFF(q_tinyint)' ,'DIFF(q_float)' ,'DIFF(q_double)' , + 'DIFF(q_int,0)' ,'DIFF(q_bigint,0)' , 'DIFF(q_smallint,0)' ,'DIFF(q_tinyint,0)' ,'DIFF(q_float,0)' ,'DIFF(q_double,0)' , + 'DIFF(q_int,1)' ,'DIFF(q_bigint,1)' , 'DIFF(q_smallint,1)' ,'DIFF(q_tinyint,1)' ,'DIFF(q_float,1)' ,'DIFF(q_double,1)' , + 'DERIVATIVE(q_int,15s,0)' , 'DERIVATIVE(q_bigint,10s,1)' , 'DERIVATIVE(q_smallint,20s,0)' ,'DERIVATIVE(q_tinyint,10s,1)' ,'DERIVATIVE(q_float,6s,0)' ,'DERIVATIVE(q_double,3s,1)', + 'DIFF(q_int_null)' ,'DIFF(q_bigint_null)' , 'DIFF(q_smallint_null)' ,'DIFF(q_tinyint_null)' ,'DIFF(q_float_null)' ,'DIFF(q_double_null)' , + 'DIFF(q_int_null,0)' ,'DIFF(q_bigint_null,0)' , 'DIFF(q_smallint_null,0)' ,'DIFF(q_tinyint_null,0)' ,'DIFF(q_float_null,0)' ,'DIFF(q_double_null,0)' , + 'DIFF(q_int_null,1)' ,'DIFF(q_bigint_null,1)' , 'DIFF(q_smallint_null,1)' ,'DIFF(q_tinyint_null,1)' ,'DIFF(q_float_null,1)' ,'DIFF(q_double_null,1)' , + 'DERIVATIVE(q_int_null,15s,0)' , 'DERIVATIVE(q_bigint_null,10s,1)' , 'DERIVATIVE(q_smallint_null,20s,0)' ,'DERIVATIVE(q_tinyint_null,10s,1)' ,'DERIVATIVE(q_float_null,6s,0)' ,'DERIVATIVE(q_double_null,3s,1)'] + self.calc_calculate_groupbytbname = self.calc_calculate_regular + #two table join - calc_calculate_all_j = ['SPREAD(t1.ts)' , 'SPREAD(t1.q_ts)' , 'SPREAD(t1.q_int)' ,'SPREAD(t1.q_bigint)' , 'SPREAD(t1.q_smallint)' ,'SPREAD(t1.q_tinyint)' ,'SPREAD(t1.q_float)' ,'SPREAD(t1.q_double)' , + self.calc_calculate_all_j = ['SPREAD(t1.ts)' , 'SPREAD(t1.q_ts)' , 'SPREAD(t1.q_int)' ,'SPREAD(t1.q_bigint)' , 'SPREAD(t1.q_smallint)' ,'SPREAD(t1.q_tinyint)' ,'SPREAD(t1.q_float)' ,'SPREAD(t1.q_double)' , 'SPREAD(t2.ts)' , 'SPREAD(t2.q_ts)' , 'SPREAD(t2.q_int)' ,'SPREAD(t2.q_bigint)' , 'SPREAD(t2.q_smallint)' ,'SPREAD(t2.q_tinyint)' ,'SPREAD(t2.q_float)' ,'SPREAD(t2.q_double)' , '(SPREAD(t1.q_int) + SPREAD(t1.q_bigint))' , '(SPREAD(t1.q_tinyint) - SPREAD(t1.q_float))', '(SPREAD(t1.q_double) * SPREAD(t1.q_tinyint))' , '(SPREAD(t1.q_double) / SPREAD(t1.q_tinyint))', '(SPREAD(t2.q_int) + SPREAD(t2.q_bigint))' , '(SPREAD(t2.q_smallint) - SPREAD(t2.q_float))', '(SPREAD(t2.q_double) * SPREAD(t2.q_tinyint))' , '(SPREAD(t2.q_double) / SPREAD(t2.q_tinyint))', - '(SPREAD(t1.q_int) + SPREAD(t1.q_smallint))' , '(SPREAD(t2.q_smallint) - SPREAD(t2.q_float))', '(SPREAD(t1.q_double) * SPREAD(t1.q_tinyint))' , '(SPREAD(t1.q_double) / SPREAD(t1.q_float))'] - calc_calculate_regular_j = ['DIFF(t1.q_int)' ,'DIFF(t1.q_bigint)' , 'DIFF(t1.q_smallint)' ,'DIFF(t1.q_tinyint)' ,'DIFF(t1.q_float)' ,'DIFF(t1.q_double)' , + '(SPREAD(t1.q_int) + SPREAD(t1.q_smallint))' , '(SPREAD(t2.q_smallint) - SPREAD(t2.q_float))', '(SPREAD(t1.q_double) * SPREAD(t1.q_tinyint))' , '(SPREAD(t1.q_double) / SPREAD(t1.q_float))', + 'SPREAD(t1.q_ts_null)' , 'SPREAD(t1.q_int_null)' ,'SPREAD(t1.q_bigint_null)' , 'SPREAD(t1.q_smallint_null)' ,'SPREAD(t1.q_tinyint_null)' ,'SPREAD(t1.q_float_null)' ,'SPREAD(t1.q_double_null)' , + 'SPREAD(t2.q_ts_null)' , 'SPREAD(t2.q_int_null)' ,'SPREAD(t2.q_bigint_null)' , 'SPREAD(t2.q_smallint_null)' ,'SPREAD(t2.q_tinyint_null)' ,'SPREAD(t2.q_float_null)' ,'SPREAD(t2.q_double_null)' , + '(SPREAD(t1.q_int_null) + SPREAD(t1.q_bigint_null))' , '(SPREAD(t1.q_tinyint_null) - SPREAD(t1.q_float_null))', '(SPREAD(t1.q_double_null) * SPREAD(t1.q_tinyint_null))' , '(SPREAD(t1.q_double_null) / SPREAD(t1.q_tinyint_null))', + '(SPREAD(t2.q_int_null) + SPREAD(t2.q_bigint_null))' , '(SPREAD(t2.q_smallint_null) - SPREAD(t2.q_float_null))', '(SPREAD(t2.q_double_null) * SPREAD(t2.q_tinyint_null))' , '(SPREAD(t2.q_double_null) / SPREAD(t2.q_tinyint_null))', + '(SPREAD(t1.q_int_null) + SPREAD(t1.q_smallint_null))' , '(SPREAD(t2.q_smallint_null) - SPREAD(t2.q_float_null))', '(SPREAD(t1.q_double_null) * SPREAD(t1.q_tinyint_null))' , '(SPREAD(t1.q_double_null) / SPREAD(t1.q_float_null))'] + self.calc_calculate_regular_j = ['DIFF(t1.q_int)' ,'DIFF(t1.q_bigint)' , 'DIFF(t1.q_smallint)' ,'DIFF(t1.q_tinyint)' ,'DIFF(t1.q_float)' ,'DIFF(t1.q_double)' , 'DIFF(t1.q_int,0)' ,'DIFF(t1.q_bigint,0)' , 'DIFF(t1.q_smallint,0)' ,'DIFF(t1.q_tinyint,0)' ,'DIFF(t1.q_float,0)' ,'DIFF(t1.q_double,0)' , 'DIFF(t1.q_int,1)' ,'DIFF(t1.q_bigint,1)' , 'DIFF(t1.q_smallint,1)' ,'DIFF(t1.q_tinyint,1)' ,'DIFF(t1.q_float,1)' ,'DIFF(t1.q_double,1)' , 'DERIVATIVE(t1.q_int,15s,0)' , 'DERIVATIVE(t1.q_bigint,10s,1)' , 'DERIVATIVE(t1.q_smallint,20s,0)' ,'DERIVATIVE(t1.q_tinyint,10s,1)' ,'DERIVATIVE(t1.q_float,6s,0)' ,'DERIVATIVE(t1.q_double,3s,1)' , 'DIFF(t2.q_int)' ,'DIFF(t2.q_bigint)' , 'DIFF(t2.q_smallint)' ,'DIFF(t2.q_tinyint)' ,'DIFF(t2.q_float)' ,'DIFF(t2.q_double)' , 'DIFF(t2.q_int,0)' ,'DIFF(t2.q_bigint,0)' , 'DIFF(t2.q_smallint,0)' ,'DIFF(t2.q_tinyint,0)' ,'DIFF(t2.q_float,0)' ,'DIFF(t2.q_double,0)' , 'DIFF(t2.q_int,1)' ,'DIFF(t2.q_bigint,1)' , 'DIFF(t2.q_smallint,1)' ,'DIFF(t2.q_tinyint,1)' ,'DIFF(t2.q_float,1)' ,'DIFF(t2.q_double,1)' , - 'DERIVATIVE(t2.q_int,15s,0)' , 'DERIVATIVE(t2.q_bigint,10s,1)' , 'DERIVATIVE(t2.q_smallint,20s,0)' ,'DERIVATIVE(t2.q_tinyint,10s,1)' ,'DERIVATIVE(t2.q_float,6s,0)' ,'DERIVATIVE(t2.q_double,3s,1)' ] - calc_calculate_groupbytbname_j = calc_calculate_regular_j + 'DERIVATIVE(t2.q_int,15s,0)' , 'DERIVATIVE(t2.q_bigint,10s,1)' , 'DERIVATIVE(t2.q_smallint,20s,0)' ,'DERIVATIVE(t2.q_tinyint,10s,1)' ,'DERIVATIVE(t2.q_float,6s,0)' ,'DERIVATIVE(t2.q_double,3s,1)' , + 'DIFF(t1.q_int_null)' ,'DIFF(t1.q_bigint_null)' , 'DIFF(t1.q_smallint_null)' ,'DIFF(t1.q_tinyint_null)' ,'DIFF(t1.q_float_null)' ,'DIFF(t1.q_double_null)' , + 'DIFF(t1.q_int_null,0)' ,'DIFF(t1.q_bigint_null,0)' , 'DIFF(t1.q_smallint_null,0)' ,'DIFF(t1.q_tinyint_null,0)' ,'DIFF(t1.q_float_null,0)' ,'DIFF(t1.q_double_null,0)' , + 'DIFF(t1.q_int_null,1)' ,'DIFF(t1.q_bigint_null,1)' , 'DIFF(t1.q_smallint_null,1)' ,'DIFF(t1.q_tinyint_null,1)' ,'DIFF(t1.q_float_null,1)' ,'DIFF(t1.q_double_null,1)' , + 'DERIVATIVE(t1.q_int_null,15s,0)' , 'DERIVATIVE(t1.q_bigint_null,10s,1)' , 'DERIVATIVE(t1.q_smallint_null,20s,0)' ,'DERIVATIVE(t1.q_tinyint_null,10s,1)' ,'DERIVATIVE(t1.q_float_null,6s,0)' ,'DERIVATIVE(t1.q_double_null,3s,1)' , + 'DIFF(t2.q_int_null)' ,'DIFF(t2.q_bigint_null)' , 'DIFF(t2.q_smallint_null)' ,'DIFF(t2.q_tinyint_null)' ,'DIFF(t2.q_float_null)' ,'DIFF(t2.q_double_null)' , + 'DIFF(t2.q_int_null,0)' ,'DIFF(t2.q_bigint_null,0)' , 'DIFF(t2.q_smallint_null,0)' ,'DIFF(t2.q_tinyint_null,0)' ,'DIFF(t2.q_float_null,0)' ,'DIFF(t2.q_double_null,0)' , + 'DIFF(t2.q_int_null,1)' ,'DIFF(t2.q_bigint_null,1)' , 'DIFF(t2.q_smallint_null,1)' ,'DIFF(t2.q_tinyint_null,1)' ,'DIFF(t2.q_float_null,1)' ,'DIFF(t2.q_double_null,1)' , + 'DERIVATIVE(t2.q_int_null,15s,0)' , 'DERIVATIVE(t2.q_bigint_null,10s,1)' , 'DERIVATIVE(t2.q_smallint_null,20s,0)' ,'DERIVATIVE(t2.q_tinyint_null,10s,1)' ,'DERIVATIVE(t2.q_float_null,6s,0)' ,'DERIVATIVE(t2.q_double_null,3s,1)'] + self.calc_calculate_groupbytbname_j = self.calc_calculate_regular_j #inter && calc_aggregate_all\calc_aggregate_regular\calc_select_all - interval_sliding = ['interval(4w) sliding(1w) ','interval(1w) sliding(1d) ','interval(1d) sliding(1h) ' , + self.interval_sliding = ['interval(4w) sliding(1w) ','interval(1w) sliding(1d) ','interval(1d) sliding(1h) ' , 'interval(1h) sliding(1m) ','interval(1m) sliding(1s) ','interval(1s) sliding(10a) ', 'interval(1y) ','interval(1n) ','interval(1w) ','interval(1d) ','interval(1h) ','interval(1m) ','interval(1s) ' ,'interval(10a)', 'interval(1y,1n) ','interval(1n,1w) ','interval(1w,1d) ','interval(1d,1h) ','interval(1h,1m) ','interval(1m,1s) ','interval(1s,10a) ' ,'interval(100a,30a)'] - #1 select * from (select column form regular_table where <\>\in\and\or order by) - tdSql.query("select 1-1 from stable_1;") + self.conn1 = taos.connect(host="127.0.0.1", user="root", password="taosdata", config="/etc/taos/") + self.cur1 = self.conn1.cursor() + print(self.cur1) + self.cur1.execute("use %s ;" %self.db_nest) + sql = 'select * from stable_1 limit 5;' + self.cur1.execute(sql) + + + def data_matrix_equal(self, sql1,row1_s,row1_e,col1_s,col1_e, sql2,row2_s,row2_e,col2_s,col2_e): + # ----row1_start----col1_start---- + # - - - - 是一个矩阵内的数据相等- - - + # - - - - - - - - - - - - - - - - + # ----row1_end------col1_end------ + self.sql1 = sql1 + list1 =[] + tdSql.query(sql1) + for i1 in range(row1_s-1,row1_e): + #print("iiii=%d"%i1) + for j1 in range(col1_s-1,col1_e): + #print("jjjj=%d"%j1) + #print("data=%s" %(tdSql.getData(i1,j1))) + list1.append(tdSql.getData(i1,j1)) + print("=====list1-------list1---=%s" %set(list1)) + + tdSql.execute("reset query cache;") + self.sql2 = sql2 + list2 =[] + tdSql.query(sql2) + for i2 in range(row2_s-1,row2_e): + #print("iiii222=%d"%i2) + for j2 in range(col2_s-1,col2_e): + #print("jjjj222=%d"%j2) + #print("data=%s" %(tdSql.getData(i2,j2))) + list2.append(tdSql.getData(i2,j2)) + print("=====list2-------list2---=%s" %set(list2)) + + if (list1 == list2) and len(list2)>0: + # print(("=====matrix===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) + tdLog.info(("===matrix===sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) + elif (set(list2)).issubset(set(list1)): + # 解决不同子表排列结果乱序 + # print(("=====list_issubset==matrix2in1-true===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) + tdLog.info(("===matrix_issubset===sql1:'%s' matrix_set_result = sql2:'%s' matrix_set_result") %(sql1,sql2)) + #elif abs(float(str(list1).replace("]","").replace("[","").replace("e+","")) - float(str(list2).replace("]","").replace("[","").replace("e+",""))) <= 0.0001: + elif abs(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-","")) - float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-",""))) <= 0.0001: + print(("=====matrix_abs+e+===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) + print(("=====matrix_abs+e+replace_after===sql1.list1:'%s',sql2.list2:'%s'") %(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-","")),float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-","")))) + tdLog.info(("===matrix_abs+e+===sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) + elif abs(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")) - float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-",""))) <= 0.1: + #{datetime.datetime(2021, 8, 27, 1, 46, 40), -441.46841430664057}replace + print(("=====matrix_abs+replace===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) + print(("=====matrix_abs+replace_after===sql1.list1:'%s',sql2.list2:'%s'") %(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")),float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")))) + tdLog.info(("===matrix_abs+replace===sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) + elif abs(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")) - float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-",""))) <= 0.5: + print(("=====matrix_abs===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) + print(("=====matrix_abs===sql1.list1:'%s',sql2.list2:'%s'") %(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")),float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")))) + tdLog.info(("===matrix_abs======sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) + else: + print(("=====matrix_error===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) + tdLog.info(("sql1:'%s' matrix_result != sql2:'%s' matrix_result") %(sql1,sql2)) + return tdSql.checkEqual(list1,list2) + + def restartDnodes(self): + pass + # tdDnodes.stop(1) + # tdDnodes.start(1) + + def dropandcreateDB_random(self,database,n): + ts = 1630000000000 + num_random = 100 + fake = Faker('zh_CN') + tdSql.execute('''drop database if exists %s ;''' %database) + tdSql.execute('''create database %s keep 36500;'''%database) + tdSql.execute('''use %s;'''%database) + + tdSql.execute('''create stable stable_1 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ + tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') + tdSql.execute('''create stable stable_2 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ + tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') + + tdSql.execute('''create stable stable_null_data (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ + tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') + + tdSql.execute('''create stable stable_null_childtable (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ + tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') + + #tdSql.execute('''create table stable_1_1 using stable_1 tags('stable_1_1', '0' , '0' , '0' , '0' , 0 , 'binary1' , 'nchar1' , '0' , '0' ,'0') ;''') + tdSql.execute('''create table stable_1_1 using stable_1 tags('stable_1_1', '%d' , '%d', '%d' , '%d' , 0 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + tdSql.execute('''create table stable_1_2 using stable_1 tags('stable_1_2', '2147483647' , '9223372036854775807' , '32767' , '127' , 1 , 'binary2' , 'nchar2' , '2' , '22' , \'1999-09-09 09:09:09.090\') ;''') + tdSql.execute('''create table stable_1_3 using stable_1 tags('stable_1_3', '-2147483647' , '-9223372036854775807' , '-32767' , '-127' , false , 'binary3' , 'nchar3nchar3' , '-3.3' , '-33.33' , \'2099-09-09 09:09:09.090\') ;''') + #tdSql.execute('''create table stable_1_4 using stable_1 tags('stable_1_4', '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') + tdSql.execute('''create table stable_1_4 using stable_1 tags('stable_1_4', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + + # tdSql.execute('''create table stable_2_1 using stable_2 tags('stable_2_1' , '0' , '0' , '0' , '0' , 0 , 'binary21' , 'nchar21' , '0' , '0' ,'0') ;''') + # tdSql.execute('''create table stable_2_2 using stable_2 tags('stable_2_2' , '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') + + # tdSql.execute('''create table stable_null_data_1 using stable_null_data tags('stable_null_data_1', '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') + + tdSql.execute('''create table stable_2_1 using stable_2 tags('stable_2_1' , '0' , '0' , '0' , '0' , 0 , 'binary21' , 'nchar21' , '0' , '0' ,\'2099-09-09 09:09:09.090\') ;''') + tdSql.execute('''create table stable_2_2 using stable_2 tags('stable_2_2' , '%d' , '%d', '%d' , '%d' , 0 , 'binary2.%s' , 'nchar2.%s' , '%f', '%f' ,'%d') ;''' + %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + + tdSql.execute('''create table stable_null_data_1 using stable_null_data tags('stable_null_data_1', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + + #regular table + tdSql.execute('''create table regular_table_1 \ + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') + tdSql.execute('''create table regular_table_2 \ + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') + tdSql.execute('''create table regular_table_3 \ + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') + + tdSql.execute('''create table regular_table_null \ + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') + + + for i in range(num_random*n): + tdSql.execute('''insert into stable_1_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double , q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1), + fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + tdSql.execute('''insert into regular_table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1) , + fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1) , + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8)\ + values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000, fake.random_int(min=0, max=2147483647, step=1), + fake.random_int(min=0, max=9223372036854775807, step=1), + fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000, fake.random_int(min=0, max=2147483647, step=1), + fake.random_int(min=0, max=9223372036854775807, step=1), + fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), + fake.random_int(min=-9223372036854775807, max=0, step=1), + fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i +1, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), + fake.random_int(min=-9223372036854775807, max=0, step=1), + fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i +1, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000, fake.random_int(min=-0, max=2147483647, step=1), + fake.random_int(min=-0, max=9223372036854775807, step=1), + fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000 +1, fake.random_int(min=-0, max=2147483647, step=1), + fake.random_int(min=-0, max=9223372036854775807, step=1), + fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000 +10, fake.random_int(min=-0, max=2147483647, step=1), + fake.random_int(min=-0, max=9223372036854775807, step=1), + fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.query("select count(*) from stable_1;") + tdSql.checkData(0,0,3*num_random*n) + tdSql.query("select count(*) from regular_table_1;") + tdSql.checkData(0,0,num_random*n) + + def explain_sql(self,sql): + # #执行sql解析 + sql = "explain " + sql + tdLog.info(sql) + tdSql.query(sql) + #pass + + def data_check(self,sql,mark='mark') : + tdLog.info("========mark==%s==="% mark); + try: + tdSql.query(sql,queryTimes=1) + except: + tdLog.info("sql is not support :=====%s; " %sql) + tdSql.error(sql) + + + def math_nest(self,mathlist): + + print("==========%s===start=============" %mathlist) + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + self.dropandcreateDB_random("%s" %self.db_nest, 1) + + if (mathlist == ['ABS','SQRT']) or (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['FLOOR','CEIL','ROUND']) \ + or (mathlist == ['CSUM']) : + math_functions = mathlist + fun_fix_column = ['(q_bigint)','(q_smallint)','(q_tinyint)','(q_int)','(q_float)','(q_double)','(q_bigint_null)','(q_smallint_null)','(q_tinyint_null)','(q_int_null)','(q_float_null)','(q_double_null)'] + fun_column_1 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_2 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_j = ['(t1.q_bigint)','(t1.q_smallint)','(t1.q_tinyint)','(t1.q_int)','(t1.q_float)','(t1.q_double)','(t1.q_bigint_null)','(t1.q_smallint_null)','(t1.q_tinyint_null)','(t1.q_int_null)','(t1.q_float_null)','(t1.q_double_null)', + '(t2.q_bigint)','(t2.q_smallint)','(t2.q_tinyint)','(t2.q_int)','(t2.q_float)','(t2.q_double)','(t2.q_bigint_null)','(t2.q_smallint_null)','(t2.q_tinyint_null)','(t2.q_int_null)','(t2.q_float_null)','(t2.q_double_null)'] + fun_column_join_1 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_join_2 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + elif (mathlist == ['UNIQUE']) or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['MODE']) : + math_functions = mathlist + fun_fix_column = ['(q_bigint)','(q_smallint)','(q_tinyint)','(q_int)','(q_float)','(q_double)','(q_binary)','(q_nchar)','(q_bool)','(q_ts)', + '(q_bigint_null)','(q_smallint_null)','(q_tinyint_null)','(q_int_null)','(q_float_null)','(q_double_null)','(q_binary_null)','(q_nchar_null)','(q_bool_null)','(q_ts_null)'] + fun_column_1 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_2 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_j = ['(t1.q_bigint)','(t1.q_smallint)','(t1.q_tinyint)','(t1.q_int)','(t1.q_float)','(t1.q_double)','(t1.q_bigint_null)','(t1.q_smallint_null)','(t1.q_tinyint_null)','(t1.q_int_null)','(t1.q_float_null)','(t1.q_double_null)','(t1.q_ts)','(t1.q_ts_null)', + '(t2.q_bigint)','(t2.q_smallint)','(t2.q_tinyint)','(t2.q_int)','(t2.q_float)','(t2.q_double)','(t2.q_bigint_null)','(t2.q_smallint_null)','(t2.q_tinyint_null)','(t2.q_int_null)','(t2.q_float_null)','(t2.q_double_null)','(t2.q_ts)','(t2.q_ts_null)'] + fun_column_join_1 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_join_2 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + elif (mathlist == ['TAIL']): + math_functions = mathlist + num = random.randint(1, 100) + offset_rows = random.randint(0, 100) + fun_fix_column = ['(q_bigint,num)','(q_smallint,num)','(q_tinyint,num)','(q_int,num)','(q_float,num)','(q_double,num)','(q_binary,num)','(q_nchar,num)','(q_bool,num)','(q_ts,num)', + '(q_bigint_null,num)','(q_smallint_null,num)','(q_tinyint_null,num)','(q_int_null,num)','(q_float_null,num)','(q_double_null,num)','(q_binary_null,num)','(q_nchar_null,num)','(q_bool_null,num)','(q_ts_null,num)', + '(q_bigint,num,offset_rows)','(q_smallint,num,offset_rows)','(q_tinyint,num,offset_rows)','(q_int,num,offset_rows)','(q_float,num,offset_rows)','(q_double,num,offset_rows)','(q_binary,num,offset_rows)','(q_nchar,num,offset_rows)','(q_bool,num,offset_rows)','(q_ts,num,offset_rows)', + '(q_bigint_null,num,offset_rows)','(q_smallint_null,num,offset_rows)','(q_tinyint_null,num,offset_rows)','(q_int_null,num,offset_rows)','(q_float_null,num,offset_rows)','(q_double_null,num,offset_rows)','(q_binary_null,num,offset_rows)','(q_nchar_null,num,offset_rows)','(q_bool_null,num,offset_rows)','(q_ts_null,num,offset_rows)'] + fun_column_1 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)).replace("offset_rows",str(offset_rows)) + fun_column_2 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)).replace("offset_rows",str(offset_rows)) + + fun_fix_column_j = ['(t1.q_bigint,num)','(t1.q_smallint,num)','(t1.q_tinyint,num)','(t1.q_int,num)','(t1.q_float,num)','(t1.q_double,num)','(t1.q_binary,num)','(t1.q_nchar,num)','(t1.q_bool,num)','(t1.q_ts,num)', + '(t1.q_bigint_null,num)','(t1.q_smallint_null,num)','(t1.q_tinyint_null,num)','(t1.q_int_null,num)','(t1.q_float_null,num)','(t1.q_double_null,num)','(t1.q_binary_null,num)','(t1.q_nchar_null,num)','(t1.q_bool_null,num)','(t1.q_ts_null,num)', + '(t2.q_bigint,num)','(t2.q_smallint,num)','(t2.q_tinyint,num)','(t2.q_int,num)','(t2.q_float,num)','(t2.q_double,num)','(t2.q_binary,num)','(t2.q_nchar,num)','(t2.q_bool,num)','(t2.q_ts,num)', + '(t2.q_bigint_null,num)','(t2.q_smallint_null,num)','(t2.q_tinyint_null,num)','(t2.q_int_null,num)','(t2.q_float_null,num)','(t2.q_double_null,num)','(t2.q_binary_null,num)','(t2.q_nchar_null,num)','(t2.q_bool_null,num)','(t2.q_ts_null,num)', + '(t1.q_bigint,num,offset_rows)','(t1.q_smallint,num,offset_rows)','(t1.q_tinyint,num,offset_rows)','(t1.q_int,num,offset_rows)','(t1.q_float,num,offset_rows)','(t1.q_double,num,offset_rows)','(t1.q_binary,num,offset_rows)','(t1.q_nchar,num,offset_rows)','(t1.q_bool,num,offset_rows)','(t1.q_ts,num,offset_rows)', + '(t1.q_bigint_null,num,offset_rows)','(t1.q_smallint_null,num,offset_rows)','(t1.q_tinyint_null,num,offset_rows)','(t1.q_int_null,num,offset_rows)','(t1.q_float_null,num,offset_rows)','(t1.q_double_null,num,offset_rows)','(t1.q_binary_null,num,offset_rows)','(t1.q_nchar_null,num,offset_rows)','(t1.q_bool_null,num,offset_rows)','(t1.q_ts_null,num,offset_rows)', + '(t2.q_bigint,num,offset_rows)','(t2.q_smallint,num,offset_rows)','(t2.q_tinyint,num,offset_rows)','(t2.q_int,num,offset_rows)','(t2.q_float,num,offset_rows)','(t2.q_double,num,offset_rows)','(t2.q_binary,num,offset_rows)','(t2.q_nchar,num,offset_rows)','(t2.q_bool,num,offset_rows)','(t2.q_ts,num,offset_rows)', + '(t2.q_bigint_null,num,offset_rows)','(t2.q_smallint_null,num,offset_rows)','(t2.q_tinyint_null,num,offset_rows)','(t2.q_int_null,num,offset_rows)','(t2.q_float_null,num,offset_rows)','(t2.q_double_null,num,offset_rows)','(t2.q_binary_null,num,offset_rows)','(t2.q_nchar_null,num,offset_rows)','(t2.q_bool_null,num,offset_rows)','(t2.q_ts_null,num,offset_rows)'] + fun_column_join_1 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)).replace("offset_rows",str(offset_rows)) + fun_column_join_2 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)).replace("offset_rows",str(offset_rows)) + + elif (mathlist == ['POW','LOG']) or (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) : + math_functions = mathlist + num = random.randint(1, 1000) + fun_fix_column = ['(q_bigint,num)','(q_smallint,num)','(q_tinyint,num)','(q_int,num)','(q_float,num)','(q_double,num)', + '(q_bigint_null,num)','(q_smallint_null,num)','(q_tinyint_null,num)','(q_int_null,num)','(q_float_null,num)','(q_double_null,num)'] + fun_column_1 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) + fun_column_2 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) + + fun_fix_column_j = ['(t1.q_bigint,num)','(t1.q_smallint,num)','(t1.q_tinyint,num)','(t1.q_int,num)','(t1.q_float,num)','(t1.q_double,num)', + '(t1.q_bigint_null,num)','(t1.q_smallint_null,num)','(t1.q_tinyint_null,num)','(t1.q_int_null,num)','(t1.q_float_null,num)','(t1.q_double_null,num)', + '(t2.q_bigint,num)','(t2.q_smallint,num)','(t2.q_tinyint,num)','(t2.q_int,num)','(t2.q_float,num)','(t2.q_double,num)', + '(t2.q_bigint_null,num)','(t2.q_smallint_null,num)','(t2.q_tinyint_null,num)','(t2.q_int_null,num)','(t2.q_float_null,num)','(t2.q_double_null,num)'] + fun_column_join_1 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) + fun_column_join_2 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) + + elif (mathlist == ['statecount','stateduration']): + math_functions = mathlist + num = random.randint(-1000, 1000) + + operator = ['LT' , 'GT' ,'GE','NE','EQ'] + oper = str(random.sample(operator,1)).replace("[","").replace("]","")#.replace("'","") + + fun_fix_column = ['(q_bigint,oper,num,time)','(q_smallint,oper,num,time)','(q_tinyint,oper,num,time)','(q_int,oper,num,time)','(q_float,oper,num,time)','(q_double,oper,num,time)', + '(q_bigint_null,oper,num,time)','(q_smallint_null,oper,num,time)','(q_tinyint_null,oper,num,time)','(q_int_null,oper,num,time)','(q_float_null,oper,num,time)','(q_double_null,oper,num,time)'] + + hanshu_select1 = random.sample(math_functions,1) + fun_column_1 = random.sample(hanshu_select1,1)+random.sample(fun_fix_column,1) + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + + if str(hanshu_select1).replace("[","").replace("]","").replace("'","") == 'statecount': + math_fun_1 = math_fun_1.replace("oper","%s" %oper).replace(",time","").replace("num",str(num)) + elif str(hanshu_select1).replace("[","").replace("]","").replace("'","") == 'stateduration': + timeunit = ['1s' , '1m' ,'1h'] + time = str(random.sample(timeunit,1)).replace("[","").replace("]","").replace("'","") + math_fun_1 = math_fun_1.replace("oper","%s" %oper).replace("time","%s" %time).replace("num",str(num)) + + hanshu_select2 = random.sample(math_functions,1) + fun_column_2 = random.sample(hanshu_select2,1)+random.sample(fun_fix_column,1) + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + if str(hanshu_select2).replace("[","").replace("]","").replace("'","") == 'statecount': + math_fun_2 = math_fun_2.replace("oper","%s" %oper).replace(",time","").replace("num",str(num)) + elif str(hanshu_select2).replace("[","").replace("]","").replace("'","") == 'stateduration': + timeunit = ['1s' , '1m' ,'1h'] + time = str(random.sample(timeunit,1)).replace("[","").replace("]","").replace("'","") + math_fun_2 = math_fun_2.replace("oper","%s" %oper).replace("time","%s" %time).replace("num",str(num)) + + fun_fix_column_j = ['(t1.q_bigint,oper,num,time)','(t1.q_smallint,oper,num,time)','(t1.q_tinyint,oper,num,time)','(t1.q_int,oper,num,time)','(t1.q_float,oper,num,time)','(t1.q_double,oper,num,time)', + '(t1.q_bigint_null,oper,num,time)','(t1.q_smallint_null,oper,num,time)','(t1.q_tinyint_null,oper,num,time)','(t1.q_int_null,oper,num,time)','(t1.q_float_null,oper,num,time)','(t1.q_double_null,oper,num,time)', + '(t2.q_bigint,oper,num,time)','(t2.q_smallint,oper,num,time)','(t2.q_tinyint,oper,num,time)','(t2.q_int,oper,num,time)','(t2.q_float,oper,num,time)','(t2.q_double,oper,num,time)', + '(t2.q_bigint_null,oper,num,time)','(t2.q_smallint_null,oper,num,time)','(t2.q_tinyint_null,oper,num,time)','(t2.q_int_null,oper,num,time)','(t2.q_float_null,oper,num,time)','(t2.q_double_null,oper,num,time)'] + + hanshu_select_join_1 = random.sample(math_functions,1) + fun_column_join_1 = random.sample(hanshu_select_join_1,1)+random.sample(fun_fix_column_j,1) + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + + if str(hanshu_select_join_1).replace("[","").replace("]","").replace("'","") == 'statecount': + math_fun_join_1 = math_fun_join_1.replace("oper","%s" %oper).replace(",time","").replace("num",str(num)) + elif str(hanshu_select_join_1).replace("[","").replace("]","").replace("'","") == 'stateduration': + timeunit = ['1s' , '1m' ,'1h'] + time = str(random.sample(timeunit,1)).replace("[","").replace("]","").replace("'","") + math_fun_join_1 = math_fun_join_1.replace("oper","%s" %oper).replace("time","%s" %time).replace("num",str(num)) + + hanshu_select_join_2 = random.sample(math_functions,1) + fun_column_join_2 = random.sample(hanshu_select_join_2,1)+random.sample(fun_fix_column_j,1) + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + if str(hanshu_select_join_2).replace("[","").replace("]","").replace("'","") == 'statecount': + math_fun_join_2 = math_fun_join_2.replace("oper","%s" %oper).replace(",time","").replace("num",str(num)) + elif str(hanshu_select_join_2).replace("[","").replace("]","").replace("'","") == 'stateduration': + timeunit = ['1s' , '1m' ,'1h'] + time = str(random.sample(timeunit,1)).replace("[","").replace("]","").replace("'","") + math_fun_join_2 = math_fun_join_2.replace("oper","%s" %oper).replace("time","%s" %time).replace("num",str(num)) + + elif(mathlist == ['HISTOGRAM']) : + math_functions = mathlist + fun_fix_column = ['(q_bigint','(q_smallint','(q_tinyint','(q_int','(q_float','(q_double','(q_bigint_null','(q_smallint_null','(q_tinyint_null','(q_int_null','(q_float_null','(q_double_null'] + + fun_fix_column_j = ['(t1.q_bigint','(t1.q_smallint','(t1.q_tinyint','(t1.q_int','(t1.q_float','(t1.q_double','(t1.q_bigint_null','(t1.q_smallint_null','(t1.q_tinyint_null','(t1.q_int_null','(t1.q_float_null','(t1.q_double_null', + '(t2.q_bigint','(t2.q_smallint','(t2.q_tinyint','(t2.q_int','(t2.q_float','(t2.q_double','(t2.q_bigint_null','(t2.q_smallint_null','(t2.q_tinyint_null','(t2.q_int_null','(t2.q_float_null','(t2.q_double_null'] + + normalized = random.randint(0, 1) + + i = random.randint(1,3) + if i == 1: + bin_type = 'user_input' + bin_description = {-11111119395555977777} #9一会转译成, + fun_column_1 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',',"'%s'" % bin_description, ',', "%d" %normalized,')'] + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("{","[").replace("}","]").replace("9",",") + + fun_column_2 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',',"'%s'" % bin_description, ',', "%d" %normalized,')'] + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("{","[").replace("}","]").replace("9",",") + + fun_column_join_1 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',',"'%s'" % bin_description, ',', "%d" %normalized,')'] + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("{","[").replace("}","]").replace("9",",") + + fun_column_join_2 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',',"'%s'" % bin_description, ',', "%d" %normalized,')'] + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("{","[").replace("}","]").replace("9",",") + + elif i == 2: + bin_type = 'linear_bin' + true_false = random.randint(10, 11) + bin_description = {"ZstartZ": -333339, "ZwidthZ":559, "ZcountZ":59, "ZinfinityZ":'%d' %true_false} #Z一会转译成" ,9一会转译成 , + fun_column_1 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_2 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_join_1 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_join_2 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + elif i == 3: + bin_type = 'log_bin' + true_false = random.randint(10, 11) + bin_description = {"ZstartZ": -333339, "ZfactorZ":559, "ZcountZ":59, "ZinfinityZ":'%d' %true_false} #Z一会转译成" ,9一会转译成 , + fun_column_1 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_2 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_join_1 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_join_2 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + tdSql.query("select 1-1 as math_nest from stable_1 limit 1;") for i in range(self.fornum): - #sql = "select ts , * from ( select " ===暂时不支持select * ,用下面这一行 - sql = "select ts from ( select " - sql += "%s, " % random.choice(s_s_select) - sql += "%s, " % random.choice(q_select) + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']): + sql = "select ts1 , floor(asct1) from ( select " + sql += "%s as asct1, " % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts1 from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_1 + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-2 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts , abs(asct1) from ( select " + sql += "%s as asct1, " % math_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s )" % random.choice(self.order_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select ts , asct2 from ( select " + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']): + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_1 + sql += "from regular_table_1 where " + sql += "%s )" % random.choice(self.q_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select count(asct2) from ( select " + sql += "%s as asct2 " % math_fun_2 + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-3 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts , min(asct1) from ( select " + sql += "%s as asct1, ts ," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2, ts ," % math_fun_2 + sql += "%s as asct1, " % math_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += " from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MODE']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1," % math_fun_1 + sql += "%s as asct2 " % math_fun_2 + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2 ," % math_fun_2 + sql += "%s as asct1 " % math_fun_1 + sql += " from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['statecount','stateduration']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['TAIL']) or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['SAMPLE']): + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_1 + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2 " % math_fun_2 + sql += " from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += " order by asct1 asc " + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-4 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1,ts2 ,timediff(ts1,ts2), asct1 from ( select t1.ts as ts1," + sql += "%s as asct0, " % math_fun_join_1 + sql += "%s as asct1, " % math_fun_join_2 + sql += "%s as asct2, " % math_fun_join_1 + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct22, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_join_2 + sql += "from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-5 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts ," + sql += "%s, " % math_fun_1 + sql += "%s as asct1, " % random.choice(self.q_select) + sql += "%s as asct2, " % random.choice(self.q_select) + sql += "%s " % math_fun_2 + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += " ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select " + sql += "%s " % math_fun_2 + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += " ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-6 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1 ,timediff(ts1,ts2), max(asct1) from ( select t1.ts,t1.ts as ts1," + sql += "%s as asct0, " % math_fun_join_1 + sql += "%s as asct1, " % math_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t2.%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % math_fun_join_1 + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_join_2 + sql += "from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-7 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1,ts2 , abs(asct1) from ( select " + sql += "%s as asct1, ts as ts1," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as ts2 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_1 + sql += "from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-8 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1,floor(asct1),ts2 " + sql += "from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s as asct1, ts as ts1," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as ts2 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) " + sql += "from ( select " + sql += "%s as asct1 " % math_fun_1 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-9 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1,ts2 ,timediff(ts1,ts2) , max(asct1) from ( select t1.ts as ts1," + sql += "%s, " % math_fun_join_1 + sql += "%s as asct1, " % math_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct21, " % random.choice(self.q_select) + sql += "t2.%s as asct22, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_join_2 + sql += "from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + self.restartDnodes() + tdSql.query("select 1-10 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts , min(asct1) from ( select " + sql += "%s as asct1 ," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select ts , max(asct2) from ( select " + sql += "%s as asct1 ," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_1 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select count(asct2) from ( select " + sql += "%s as asct2 " % math_fun_2 + sql += "from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + #3 inter union not support + tdSql.query("select 1-11 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select min(asct1), max(asct2) from ( select " + sql += "%s as asct1, ts ," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as t2ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1, ts as t1ts," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as t2ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_1 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct2 " % math_fun_2 + sql += " from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-12 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1,ts2 ,timediff(ts1,ts2), max(asct1) from ( select t1.ts as ts1," + sql += "%s, " % math_fun_join_1 + sql += "%s as asct1, " % math_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct21, " % random.choice(self.q_select) + sql += "t2.%s as asct111, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_join_2 + sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-13 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts ," + sql += "%s as asct11, " % math_fun_1 + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % random.choice(self.q_select) + sql += "%s as asct14, " % math_fun_2 + sql += "%s as asct15 " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select " + sql += "%s " % math_fun_2 + sql += "%s " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-14 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select avg(asct1),count(asct2) from ( select " + sql += "%s as asct1, " % math_fun_1 + sql += "%s as asct2" % math_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_1 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-15 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1,ts ,timediff(ts1,ts), max(asct1) from ( select t1.ts as ts1," + sql += "%s, " % math_fun_join_1 + sql += "%s as asct1, " % math_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_join_2 + sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + #taos -f sql + # startTime_taosf = time.time() + print("taos -f %s sql start!" %mathlist) + taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) + #_ = subprocess.check_output(taos_cmd1, shell=True).decode("utf-8") + _ = subprocess.check_output(taos_cmd1, shell=True) + print("taos -f %s sql over!" %mathlist) + # endTime_taosf = time.time() + # print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) + + print("=========%s====over=============" %mathlist) + + + def str_nest(self,strlist): + + print("==========%s===start=============" %strlist) + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + self.dropandcreateDB_random("%s" %self.db_nest, 1) + + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['LENGTH','CHAR_LENGTH']) \ + or (strlist == ['']): + str_functions = strlist + fun_fix_column = ['(q_nchar)','(q_binary)','(q_nchar_null)','(q_binary_null)'] + fun_column_1 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) + str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_2 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) + str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_j = ['(t1.q_nchar)','(t1.q_binary)','(t1.q_nchar_null)','(t1.q_binary_null)', + '(t2.q_nchar)','(t2.q_binary)','(t2.q_nchar_null)','(t2.q_binary_null)'] + fun_column_join_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_join_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_s = ['(q_nchar)','(q_binary)','(q_nchar_null)','(q_binary_null)','(loc)','(tbname)'] + fun_column_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) + str_fun_s_1 = str(fun_column_s_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) + str_fun_s_2 = str(fun_column_s_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_s_j = ['(t1.q_nchar)','(t1.q_binary)','(t1.q_nchar_null)','(t1.q_binary_null)','(t1.loc)','(t1.tbname)', + '(t2.q_nchar)','(t2.q_binary)','(t2.q_nchar_null)','(t2.q_binary_null)','(t2.loc)','(t2.tbname)'] + fun_column_join_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_s_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_join_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_s_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + elif (strlist == ['SUBSTR']) : + str_functions = strlist + pos = random.randint(1, 20) + sub_len = random.randint(1, 10) + fun_fix_column = ['(q_nchar,pos)','(q_binary,pos)','(q_nchar_null,pos)','(q_binary_null,pos)', + '(q_nchar,pos,sub_len)','(q_binary,pos,sub_len)','(q_nchar_null,pos,sub_len)','(q_binary_null,pos,sub_len)',] + fun_column_1 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) + str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + fun_column_2 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) + str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + + fun_fix_column_j = ['(t1.q_nchar,pos)','(t1.q_binary,pos)','(t1.q_nchar_null,pos)','(t1.q_binary_null,pos)', + '(t1.q_nchar,pos,sub_len)','(t1.q_binary,pos,sub_len)','(t1.q_nchar_null,pos,sub_len)','(t1.q_binary_null,pos,sub_len)', + '(t2.q_nchar,pos)','(t2.q_binary,pos)','(t2.q_nchar_null,pos)','(t2.q_binary_null,pos)', + '(t2.q_nchar,pos,sub_len)','(t2.q_binary,pos,sub_len)','(t2.q_nchar_null,pos,sub_len)','(t2.q_binary_null,pos,sub_len)'] + fun_column_join_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + fun_column_join_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + + fun_fix_column_s = ['(q_nchar,pos)','(q_binary,pos)','(q_nchar_null,pos)','(q_binary_null,pos)','(loc,pos)', + '(q_nchar,pos,sub_len)','(q_binary,pos,sub_len)','(q_nchar_null,pos,sub_len)','(q_binary_null,pos,sub_len)','(loc,pos,sub_len)',] + fun_column_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) + str_fun_s_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + fun_column_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) + str_fun_s_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + + fun_fix_column_s_j = ['(t1.q_nchar,pos)','(t1.q_binary,pos)','(t1.q_nchar_null,pos)','(t1.q_binary_null,pos)','(t1.loc,pos)', + '(t1.q_nchar,pos,sub_len)','(t1.q_binary,pos,sub_len)','(t1.q_nchar_null,pos,sub_len)','(t1.q_binary_null,pos,sub_len)','(t1.loc,pos,sub_len)', + '(t2.q_nchar,pos)','(t2.q_binary,pos)','(t2.q_nchar_null,pos)','(t2.q_binary_null,pos)','(t2.loc,pos)', + '(t2.q_nchar,pos,sub_len)','(t2.q_binary,pos,sub_len)','(t2.q_nchar_null,pos,sub_len)','(t2.q_binary_null,pos,sub_len)','(t2.loc,pos,sub_len)'] + fun_column_join_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_s_j,1) + str_fun_join_s_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + fun_column_join_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_s_j,1) + str_fun_join_s_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + + elif (strlist == ['CONCAT']) : + str_functions = strlist + i = random.randint(2,4) + fun_fix_column = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','q_nchar_null', + 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] + + column1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+column1+')' + str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + column2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+column2+')' + str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)', + '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)', + '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', + '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] + + column_j1 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+column_j1+')' + str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + column_j2 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+column_j2+')' + str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_s = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','loc','q_nchar_null', + 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] + + column_s1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_s_1 = str(random.sample(str_functions,1))+'('+column_s1+')' + str_fun_s_1 = str(fun_column_s_1).replace("[","").replace("]","").replace("'","") + + column_s2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_s_2 = str(random.sample(str_functions,1))+'('+column_s2+')' + str_fun_s_2 = str(fun_column_s_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_s_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)','(t1.loc)', + '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)','(t2.loc)', + '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', + '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] + + column_j_s1 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_s_1 = str(random.sample(str_functions,1))+'('+column_j_s1+')' + str_fun_join_s_1 = str(fun_column_join_s_1).replace("[","").replace("]","").replace("'","") + + column_j_s2 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_s_2 = str(random.sample(str_functions,1))+'('+column_j_s2+')' + str_fun_join_s_2 = str(fun_column_join_s_2).replace("[","").replace("]","").replace("'","") + + elif (strlist == ['CONCAT_WS']): + str_functions = strlist + i = random.randint(2,4) + fun_fix_column = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','q_nchar_null', + 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] + + separators = ['',' ','abc','123','!','@','#','$','%','^','&','*','(',')','-','_','+','=','{', + '[','}',']','|',';',':',',','.','<','>','?','/','~','`','taos','涛思'] + separator = str(random.sample(separators,i)).replace("[","").replace("]","") + + column1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column1+')' + str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + column2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column2+')' + str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)', + '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)', + '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', + '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] + + column_j1 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j1+')' + str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + column_j2 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j2+')' + str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_s = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','loc','q_nchar_null', + 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] + + column_s1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_s_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_s1+')' + str_fun_s_1 = str(fun_column_s_1).replace("[","").replace("]","").replace("'","") + + column_s2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_s_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_s2+')' + str_fun_s_2 = str(fun_column_s_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_s_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)','(t1.loc)', + '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)','(t2.loc)', + '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', + '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] + + column_j_s1 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_s_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j_s1+')' + str_fun_join_s_1 = str(fun_column_join_s_1).replace("[","").replace("]","").replace("'","") + + column_j_s2 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_s_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j_s2+')' + str_fun_join_s_2 = str(fun_column_join_s_2).replace("[","").replace("]","").replace("'","") + + + tdSql.query("select 1-1 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']) : + sql = "select t1s , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1, " % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as t1s from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1, " % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-2 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']) : + sql = "select ts , asct1 from ( select " + sql += "%s as asct1, " % str_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s )" % random.choice(self.order_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select ts , asct2 from ( select " + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + #sql += "%s " % random.choice(having_support) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1) from ( select " + sql += "%s as asct1, " % str_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s )" % random.choice(self.order_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select sum(asct2), min(asct2) from ( select " + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-3 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2 ," % str_fun_2 + sql += "%s as asct1, " % str_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + #tdSql.query(sql) #'unexpected end of data' + # self.cur1.execute(sql) + # self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2 ," % str_fun_2 + sql += "%s as asct1, " % str_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-4 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_1 + sql += "%s as asct1, " % str_fun_join_2 + sql += "%s, " % str_fun_join_1 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t2.%s as asct12, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_1 + sql += "%s as asct1, " % str_fun_join_2 + sql += "%s, " % str_fun_join_1 + sql += "t1.%s as asct21, " % random.choice(self.q_select) + sql += "t2.%s as asct22, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-5 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts ," + sql += "%s, " % str_fun_1 + sql += "%s as asct21, " % random.choice(self.q_select) + sql += "%s as asct22, " % random.choice(self.q_select) + sql += "%s " % str_fun_2 + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += " ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select ts ," + sql += "%s, " % str_fun_1 + sql += "%s as asct22, " % random.choice(self.q_select) + sql += "%s as asct21, " % random.choice(self.q_select) + sql += "%s " % str_fun_2 + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += " ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-6 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts1,ts ,timediff(ts1,ts), LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_1 + sql += "%s as asct1, " % str_fun_join_2 + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct21, " % random.choice(self.q_select) + sql += "%s, " % str_fun_join_1 + sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_1 + sql += "%s as asct1, " % str_fun_join_2 + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct21, " % random.choice(self.q_select) + sql += "%s, " % str_fun_join_1 + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-7 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select t1s ,ts1, LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1, ts as t1s," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as ts1 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1, ts as ts1," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as t1s from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-8 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts1,st1, LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) " + sql += "from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s as asct1, ts as st1," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as ts1 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) " + sql += "from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s as asct1, ts as ts1," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as st1 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-9 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct21, " % random.choice(self.q_select) + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct23, " % random.choice(self.q_select) + sql += "t2.%s as asct24, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct21, " % random.choice(self.q_select) + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct23, " % random.choice(self.q_select) + sql += "t2.%s as asct24, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + self.restartDnodes() + tdSql.query("select 1-10 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + #3 inter union not support + tdSql.query("select 1-11 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1, ts ," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s " % random.choice(self.q_select) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1, ts ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s " % random.choice(self.q_select) + sql += " from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1 ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-12 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct21, " % random.choice(self.q_select) + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct23, " % random.choice(self.q_select) + sql += "t2.%s as asct24, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct21, " % random.choice(self.q_select) + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct23, " % random.choice(self.q_select) + sql += "t2.%s as asct24, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-13 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts ," + sql += "%s as asct10, " % str_fun_1 + sql += "%s as asct1, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % str_fun_2 + sql += "%s as asct14 " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select ts ," + sql += "%s as asct1, " % str_fun_1 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % str_fun_2 + sql += "%s as asct14 " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-14 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1, " % str_fun_s_1 + sql += "%s as asct2" % str_fun_s_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1, " % str_fun_s_1 + sql += "%s as asct2" % str_fun_s_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-15 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts,ts2 ,timediff(ts,ts2), LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts ," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14 " % random.choice(self.q_select) + sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + #taos -f sql + startTime_taos_f = time.time() + print("taos -f %s sql start!" %strlist) + taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) + #_ = subprocess.check_output(taos_cmd1, shell=True).decode("utf-8") + _ = subprocess.check_output(taos_cmd1, shell=True) + print("taos -f %s sql over!" %strlist) + endTime_taos_f = time.time() + print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) + + print("=========%s====over=============" %strlist) + + def time_nest(self,timelist): + + print("==========%s===start=============" %timelist) + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + self.dropandcreateDB_random("%s" %self.db_nest, 1) + + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMEZONE']): + time_functions = timelist + fun_fix_column = ['()'] + fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_j = ['()'] + fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + elif (timelist == ['TIMETRUNCATE']): + time_functions = timelist + + t = time.time() + t_to_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)) + fun_fix_column = ['q_ts','ts','_c0','_C0','_rowts','1600000000000','1600000000000000','1600000000000000000', + '%d' %t, '%d000' %t, '%d000000' %t,'t_to_s'] + + timeunits = ['1a' ,'1s', '1m' ,'1h', '1d'] + timeunit = str(random.sample(timeunits,1)).replace("[","").replace("]","").replace("'","") + + column_1 = ['(%s,timeutil)'%(random.sample(fun_fix_column,1))] + fun_column_1 = random.sample(time_functions,1)+random.sample(column_1,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_1 = str(time_fun_1).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) + + column_2 = ['(%s,timeutil)'%(random.sample(fun_fix_column,1))] + fun_column_2 = random.sample(time_functions,1)+random.sample(column_2,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_2 = str(time_fun_2).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) + + + fun_fix_column_j = ['(t1.q_ts)','(t1.ts)', '(t2.q_ts)','(t2.ts)','(1600000000000)','(1600000000000000)','(1600000000000000000)', + '(%d)' %t, '(%d000)' %t, '(%d000000)' %t,'t_to_s'] + + column_j1 = ['(%s,timeutil)'%(random.sample(fun_fix_column_j,1))] + fun_column_join_1 = random.sample(time_functions,1)+random.sample(column_j1,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_1 = str(time_fun_join_1).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) + + column_j2 = ['(%s,timeutil)'%(random.sample(fun_fix_column_j,1))] + fun_column_join_2 = random.sample(time_functions,1)+random.sample(column_j2,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_2 = str(time_fun_join_2).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) + + elif (timelist == ['TO_ISO8601']): + time_functions = timelist + + t = time.time() + fun_fix_column = ['(now())','(ts)','(q_ts)','(_rowts)','(_c0)','(_C0)', + '(1600000000000)','(1600000000000000)','(1600000000000000000)', + '(%d)' %t, '(%d000)' %t, '(%d000000)' %t] + + fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_j = ['(t1.q_ts)','(t1.ts)', '(t2.q_ts)','(t2.ts)','(1600000000000)','(1600000000000000)','(1600000000000000000)','(now())', + '(%d)' %t, '(%d000)' %t, '(%d000000)' %t] + + fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + elif (timelist == ['TO_UNIXTIMESTAMP']): + time_functions = timelist + + t = time.time() + t_to_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)) + fun_fix_column = ['(q_nchar)','(q_nchar1)','(q_nchar2)','(q_nchar3)','(q_nchar4)','(q_nchar_null)','(q_binary)','(q_binary5)','(q_binary6)','(q_binary7)','(q_binary8)','(q_binary_null)','(t_to_s)'] + + fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") + time_fun_1 = str(time_fun_1).replace("t_to_s","%s" %t_to_s) + + fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") + time_fun_2 = str(time_fun_2).replace("t_to_s","%s" %t_to_s) + + fun_fix_column_j = ['(t1.q_nchar)','(t1.q_binary)', '(t2.q_nchar)','(t2.q_binary)','(t_to_s)'] + + fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") + time_fun_join_1 = str(time_fun_join_1).replace("t_to_s","%s" %t_to_s) + + fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") + time_fun_join_2 = str(time_fun_join_2).replace("t_to_s","%s" %t_to_s) + + elif (timelist == ['TIMEDIFF_1']): + time_functions = timelist + + t = time.time() + t_to_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)) + timeunits = [ '1a' ,'1s', '1m' ,'1h', '1d'] + timeunit = str(random.sample(timeunits,1)).replace("[","").replace("]","").replace("'","") + + fun_fix_column = ['q_ts','ts','_c0','_C0','_rowts','1600000000000','1600000000000000','1600000000000000000', + '%d' %t, '%d000' %t, '%d000000' %t,'t_to_s'] + + column_1,column_2 = random.sample(fun_fix_column,1),random.sample(fun_fix_column,1) + column_12 = ['(%s,%s,timeutil)'%(column_1,column_2)] + fun_column_1 = random.sample(time_functions,1)+random.sample(column_12,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_1 = str(time_fun_1).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s).replace("_1","") + + column_3,column_4 = random.sample(fun_fix_column,1),random.sample(fun_fix_column,1) + column_34 = ['(%s,%s,timeutil)'%(column_3,column_4)] + fun_column_2 = random.sample(time_functions,1)+random.sample(column_34,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_2 = str(time_fun_2).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s).replace("_1","") + + fun_fix_column_j = ['(t1.q_ts)','(t1.ts)', '(t2.q_ts)','(t2.ts)','1600000000000','1600000000000000','1600000000000000000', + '%d' %t, '%d000' %t, '%d000000' %t,'t_to_s'] + + column_j1,column_j2 = random.sample(fun_fix_column_j,1),random.sample(fun_fix_column_j,1) + column_j12 = ['(%s,%s,timeutil)'%(column_j1,column_j2)] + fun_column_join_1 = random.sample(time_functions,1)+random.sample(column_j12,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_1 = str(time_fun_join_1).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s).replace("_1","") + + column_j3,column_j4 = random.sample(fun_fix_column_j,1),random.sample(fun_fix_column_j,1) + column_j34 = ['(%s,%s,timeutil)'%(column_j3,column_j4)] + fun_column_join_2 = random.sample(time_functions,1)+random.sample(column_j34,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_2 = str(time_fun_join_2).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s).replace("_1","") + + elif (timelist == ['TIMEDIFF_2']): + time_functions = timelist + + t = time.time() + t_to_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)) + + fun_fix_column = ['q_ts','ts','_c0','_C0','_rowts','1600000000000','1600000000000000','1600000000000000000', + '%d' %t, '%d000' %t, '%d000000' %t,'t_to_s'] + + column_1,column_2 = random.sample(fun_fix_column,1),random.sample(fun_fix_column,1) + column_12 = ['(%s,%s)'%(column_1,column_2)] + fun_column_1 = random.sample(time_functions,1)+random.sample(column_12,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_1 = str(time_fun_1).replace("t_to_s","%s" %t_to_s).replace("_2","") + + column_3,column_4 = random.sample(fun_fix_column,1),random.sample(fun_fix_column,1) + column_34 = ['(%s,%s)'%(column_3,column_4)] + fun_column_2 = random.sample(time_functions,1)+random.sample(column_34,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_2 = str(time_fun_2).replace("t_to_s","%s" %t_to_s).replace("_2","") + + fun_fix_column_j = ['(t1.q_ts)','(t1.ts)', '(t2.q_ts)','(t2.ts)','1600000000000','1600000000000000','1600000000000000000', + '%d' %t, '%d000' %t, '%d000000' %t,'t_to_s'] + + column_j1,column_j2 = random.sample(fun_fix_column_j,1),random.sample(fun_fix_column_j,1) + column_j12 = ['(%s,%s)'%(column_j1,column_j2)] + fun_column_join_1 = random.sample(time_functions,1)+random.sample(column_j12,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_1 = str(time_fun_join_1).replace("t_to_s","%s" %t_to_s).replace("_2","") + + column_j3,column_j4 = random.sample(fun_fix_column_j,1),random.sample(fun_fix_column_j,1) + column_j34 = ['(%s,%s)'%(column_j3,column_j4)] + fun_column_join_2 = random.sample(time_functions,1)+random.sample(column_j34,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_2 = str(time_fun_join_2).replace("t_to_s","%s" %t_to_s).replace("_2","") + + elif (timelist == ['ELAPSED']): + time_functions = timelist + + fun_fix_column = ['(ts)','(_c0)','(_C0)','(_rowts)','(ts,time_unit)','(_c0,time_unit)','(_C0,time_unit)','(_rowts,time_unit)'] + + time_units = ['1s','1m','1h','1d','1a'] + time_unit1 = str(random.sample(time_units,1)).replace("[","").replace("]","").replace("'","") + time_unit2 = str(random.sample(time_units,1)).replace("[","").replace("]","").replace("'","") + + fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit1) + + fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit2) + + + fun_fix_column_j = ['(t1.ts)', '(t2.ts)','(t1.ts,time_unit)','(t1.ts,time_unit)','(t2.ts,time_unit)','(t2.ts,time_unit)'] + + fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit1) + + fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit2) + + + elif (timelist == ['CAST']) : + str_functions = timelist + #下面的4个是全的,这个只是1个 + i = random.randint(1,4) + if i ==1: + print('===========cast_1===========') + fun_fix_column = ['q_bool','q_bool_null','q_bigint','q_bigint_null','q_smallint','q_smallint_null', + 'q_tinyint','q_tinyint_null','q_int','q_int_null','q_float','q_float_null','q_double','q_double_null'] + type_names = ['BIGINT','BINARY(100)','TIMESTAMP','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['t1.q_bool','t1.q_bool_null','t1.q_bigint','t1.q_bigint_null','t1.q_smallint','t1.q_smallint_null', + 't1.q_tinyint','t1.q_tinyint_null','t1.q_int','t1.q_int_null','t1.q_float','t1.q_float_null','t1.q_double','t1.q_double_null', + 't2.q_bool','t2.q_bool_null','t2.q_bigint','t2.q_bigint_null','t2.q_smallint','t2.q_smallint_null', + 't2.q_tinyint','t2.q_tinyint_null','t2.q_int','t2.q_int_null','t2.q_float','t2.q_float_null','t2.q_double','t2.q_double_null'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + elif i==2: + print('===========cast_2===========') + fun_fix_column = ['q_binary','q_binary_null','q_binary1','q_binary2','q_binary3','q_binary4'] + type_names = ['BIGINT','BINARY(100)','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['t1.q_binary','t1.q_binary_null','t1.q_binary1','t1.q_binary2','t1.q_binary3','t1.q_binary4', + 't2.q_binary','t2.q_binary_null','t2.q_binary1','t2.q_binary2','t2.q_binary3','t2.q_binary4'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + elif i==3: + print('===========cast_3===========') + fun_fix_column = ['q_nchar','q_nchar_null','q_nchar5','q_nchar6','q_nchar7','q_nchar8'] + type_names = ['BIGINT','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['t1.q_nchar','t1.q_nchar_null','t1.q_nchar5','t1.q_nchar6','t1.q_nchar7','t1.q_nchar8', + 't2.q_nchar','t2.q_nchar_null','t2.q_nchar5','t2.q_nchar6','t2.q_nchar7','t2.q_nchar8'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + elif i==4: + print('===========cast_4===========') + fun_fix_column = ['q_ts','q_ts_null','_C0','_c0','ts','_rowts'] + type_names = ['BIGINT','TIMESTAMP','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['t1.q_ts','t1.q_ts_null','t1.ts','t2.q_ts','t2.q_ts_null','t2.ts'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + elif (timelist == ['CAST_1']) : + str_functions = timelist + + print('===========cast_1===========') + fun_fix_column = ['q_bool','q_bool_null','q_bigint','q_bigint_null','q_smallint','q_smallint_null', + 'q_tinyint','q_tinyint_null','q_int','q_int_null','q_float','q_float_null','q_double','q_double_null'] + type_names = ['BIGINT','BINARY(100)','TIMESTAMP','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_1","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_1","") + + fun_fix_column_j = ['t1.q_bool','t1.q_bool_null','t1.q_bigint','t1.q_bigint_null','t1.q_smallint','t1.q_smallint_null', + 't1.q_tinyint','t1.q_tinyint_null','t1.q_int','t1.q_int_null','t1.q_float','t1.q_float_null','t1.q_double','t1.q_double_null', + 't2.q_bool','t2.q_bool_null','t2.q_bigint','t2.q_bigint_null','t2.q_smallint','t2.q_smallint_null', + 't2.q_tinyint','t2.q_tinyint_null','t2.q_int','t2.q_int_null','t2.q_float','t2.q_float_null','t2.q_double','t2.q_double_null'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_1","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_1","") + + elif (timelist == ['CAST_2']) : + str_functions = timelist + print('===========cast_2===========') + fun_fix_column = ['q_binary','q_binary_null','q_binary1','q_binary2','q_binary3','q_binary4'] + type_names = ['BIGINT','BINARY(100)','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_2","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_2","") + + fun_fix_column_j = ['t1.q_binary','t1.q_binary_null','t1.q_binary1','t1.q_binary2','t1.q_binary3','t1.q_binary4', + 't2.q_binary','t2.q_binary_null','t2.q_binary1','t2.q_binary2','t2.q_binary3','t2.q_binary4'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_2","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_2","") + + elif (timelist == ['CAST_3']) : + str_functions = timelist + print('===========cast_3===========') + fun_fix_column = ['q_nchar','q_nchar_null','q_nchar5','q_nchar6','q_nchar7','q_nchar8'] + type_names = ['BIGINT','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_3","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_3","") + + fun_fix_column_j = ['t1.q_nchar','t1.q_nchar_null','t1.q_nchar5','t1.q_nchar6','t1.q_nchar7','t1.q_nchar8', + 't2.q_nchar','t2.q_nchar_null','t2.q_nchar5','t2.q_nchar6','t2.q_nchar7','t2.q_nchar8'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_3","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_3","") + + elif (timelist == ['CAST_4']) : + str_functions = timelist + print('===========cast_4===========') + fun_fix_column = ['q_ts','q_ts_null','_C0','_c0','ts','_rowts'] + type_names = ['BIGINT','TIMESTAMP','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_4","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_4","") + + fun_fix_column_j = ['t1.q_ts','t1.q_ts_null','t1.ts','t2.q_ts','t2.q_ts_null','t2.ts'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_4","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_4","") + + tdSql.query("select 1-1 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1 , timediff(asct1,now) from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts1 from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) \ + or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts2 , asct1,now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts2 from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select max(asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += "from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-2 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(asct1,now),now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s )" % random.choice(self.order_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select ts , timediff(asct2,now),now(),today(),timezone() from ( select " + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + #sql += "%s " % random.choice(having_support) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts , (asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s )" % random.choice(self.order_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select ts , asct2,now(),today(),timezone() from ( select " + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select min(asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1 " % time_fun_1 + sql += " from regular_table_1 where " + sql += "%s )" % random.choice(self.q_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select avg(asct2),now(),today(),timezone() from ( select " + sql += "%s as asct2 " % time_fun_2 + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-3 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(asct1,now) from ( select " + sql += "%s as asct1, ts ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += "from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2, ts ," % time_fun_2 + sql += "%s as asct1, " % time_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += "from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += " order by asct1 desc " + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts , (asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1, ts ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2, ts ," % time_fun_2 + sql += "%s as asct1, " % time_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += "from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += " order by asct1 desc " + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select abs(asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1," % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += "from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2," % time_fun_2 + sql += "%s as asct1 " % time_fun_1 + sql += "from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += " order by asct1 asc " + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-4 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), timediff(asct1,now) from ( select t1.ts as ts1," + sql += "%s as asct11, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "%s as asct12, " % time_fun_join_1 + sql += "t1.%s as asct111, " % random.choice(self.q_select) + sql += "t2.%s as asct121, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), (asct1) from ( select t1.ts as ts1," + sql += "%s as asct10, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "%s as asct11, " % time_fun_join_1 + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select floor(asct1) from ( select " + sql += "%s as asct10, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "%s as asct11" % time_fun_join_1 + sql += " from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-5 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['ELAPSED']) : + sql = "select now(),today(),timezone(), " + sql += "%s, " % time_fun_1 + sql += "%s " % time_fun_2 + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += " ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + else: + sql = "select ts ,now(),today(),timezone(), " + sql += "%s as asct11, " % time_fun_1 + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % random.choice(self.q_select) + sql += "%s as asct14 " % time_fun_2 + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += " ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-6 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,ts ,timediff(ts1,ts), timediff(asct1,now) from ( select t1.ts as ts1," + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t2.%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % time_fun_join_1 + sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts ,timediff(ts1,ts), (asct1) from ( select t1.ts as ts1," + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t2.%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % time_fun_join_1 + sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select (asct1)*111 from ( select " + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "%s as asct122 " % time_fun_join_1 + sql += " from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-7 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,m1 , timediff(asct1,now) from ( select " + sql += "%s as asct1, ts as m1," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.t_select) + sql += "ts as ts1 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select tm1,tm2 , (asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1, ts as tm1," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.t_select) + sql += "ts as tm2 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select (asct1)/asct2 ,now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += "from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-8 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select tm1,tm2 , timediff(asct1,now) " + sql += "from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s as asct1, ts as tm1," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.t_select) + sql += "ts as tm2 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts2 , (asct1),now(),today(),timezone() " + sql += "from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s as asct1, ts as ts1," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.t_select) + sql += "ts as ts2 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select floor(abs(asct1)),now(),today(),timezone() " + sql += "from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += "from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-9 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), timediff(asct1,now) from ( select t1.ts as ts1," + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), asct1 from ( select t1.ts as ts1," + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select min(asct1*110) from ( select " + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1 " % time_fun_join_2 + sql += "from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + self.restartDnodes() + tdSql.query("select 1-10 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(asct1,now) from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select ts , timediff(asct1,now) from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts , (asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select ts , (asct2),now(),today(),timezone() from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select abs(asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select max(asct2),now(),today(),timezone() from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += "from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + #3 inter union not support + tdSql.query("select 1-11 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(asct1,now), timediff(now,asct2) from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts , asct1,now(),now(),asct2 from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select asct1+asct2,now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += " from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "order by asct1 " + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-12 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), timediff(asct1,now) from ( select t1.ts as ts1," + sql += "%s, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), asct1,now() from ( select t1.ts as ts1," + sql += "%s, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select min(floor(asct1)),now() from ( select " + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1 " % time_fun_join_2 + sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-13 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(%s,now)," % time_fun_2 + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % time_fun_2 + sql += "%s as asct122 " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts ,now(),today(),timezone(), " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % time_fun_2 + sql += "%s as asct122 " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select now(),today(),timezone(), " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct12 " % time_fun_2 + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-14 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(asct1,now),timediff(now,asct2) from ( select ts ts ," + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2" % time_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts , (asct1),now(),(now()),asct2 from ( select ts ts ," + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2" % time_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select (asct1)*asct2,now(),(now()) from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2" % time_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + tdSql.query("select 1-15 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,ts ,timediff(ts1,ts), timediff(asct1,now),timediff(now,asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts ,timediff(ts1,ts), asct1,(now()),(now()),asct2 ,now(),today(),timezone() from ( select t1.ts as ts1," + sql += "%s as asct2, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select asct1,(now()),(now()),asct2 ,now(),today(),timezone() from ( select " + sql += "%s as asct2, " % time_fun_join_1 + sql += "%s as asct1 " % time_fun_join_2 + sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + #taos -f sql + startTime_taos_f = time.time() + print("taos -f %s sql start!" %timelist) + taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) + #_ = subprocess.check_output(taos_cmd1, shell=True).decode("utf-8") + _ = subprocess.check_output(taos_cmd1, shell=True) + print("taos -f %s sql over!" %timelist) + endTime_taos_f = time.time() + print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) + + print("=========%s====over=============" %timelist) + + def base_nest(self,baselist): + + print("==========%s===start=============" %baselist) + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + self.dropandcreateDB_random("%s" %self.db_nest, 1) + + if (baselist == ['A']) or (baselist == ['S']) or (baselist == ['F']) \ + or (baselist == ['C']): + base_functions = baselist + fun_fix_column = ['(q_bigint)','(q_smallint)','(q_tinyint)','(q_int)','(q_float)','(q_double)','(q_bigint_null)','(q_smallint_null)','(q_tinyint_null)','(q_int_null)','(q_float_null)','(q_double_null)'] + fun_column_1 = random.sample(base_functions,1)+random.sample(fun_fix_column,1) + base_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_2 = random.sample(base_functions,1)+random.sample(fun_fix_column,1) + base_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_j = ['(t1.q_bigint)','(t1.q_smallint)','(t1.q_tinyint)','(t1.q_int)','(t1.q_float)','(t1.q_double)','(t1.q_bigint_null)','(t1.q_smallint_null)','(t1.q_tinyint_null)','(t1.q_int_null)','(t1.q_float_null)','(t1.q_double_null)', + '(t2.q_bigint)','(t2.q_smallint)','(t2.q_tinyint)','(t2.q_int)','(t2.q_float)','(t2.q_double)','(t2.q_bigint_null)','(t2.q_smallint_null)','(t2.q_tinyint_null)','(t2.q_int_null)','(t2.q_float_null)','(t2.q_double_null)'] + fun_column_join_1 = random.sample(base_functions,1)+random.sample(fun_fix_column_j,1) + base_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_join_2 = random.sample(base_functions,1)+random.sample(fun_fix_column_j,1) + base_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + elif (baselist == ['P']) or (baselist == ['M']) or (baselist == ['S'])or (baselist == ['T']): + base_functions = baselist + num = random.randint(0, 1000) + fun_fix_column = ['(q_bigint,num)','(q_smallint,num)','(q_tinyint,num)','(q_int,num)','(q_float,num)','(q_double,num)', + '(q_bigint_null,num)','(q_smallint_null,num)','(q_tinyint_null,num)','(q_int_null,num)','(q_float_null,num)','(q_double_null,num)'] + fun_column_1 = random.sample(base_functions,1)+random.sample(fun_fix_column,1) + base_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",base(num)) + fun_column_2 = random.sample(base_functions,1)+random.sample(fun_fix_column,1) + base_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",base(num)) + + fun_fix_column_j = ['(t1.q_bigint,num)','(t1.q_smallint,num)','(t1.q_tinyint,num)','(t1.q_int,num)','(t1.q_float,num)','(t1.q_double,num)', + '(t1.q_bigint_null,num)','(t1.q_smallint_null,num)','(t1.q_tinyint_null,num)','(t1.q_int_null,num)','(t1.q_float_null,num)','(t1.q_double_null,num)', + '(t2.q_bigint,num)','(t2.q_smallint,num)','(t2.q_tinyint,num)','(t2.q_int,num)','(t2.q_float,num)','(t2.q_double,num)', + '(t2.q_bigint_null,num)','(t2.q_smallint_null,num)','(t2.q_tinyint_null,num)','(t2.q_int_null,num)','(t2.q_float_null,num)','(t2.q_double_null,num)'] + fun_column_join_1 = random.sample(base_functions,1)+random.sample(fun_fix_column_j,1) + base_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",base(num)) + fun_column_join_2 = random.sample(base_functions,1)+random.sample(fun_fix_column_j,1) + base_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",base(num)) + + tdSql.query("select 1-1 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts , floor(asct1) from ( select " + sql += "%s as asct1, " % base_fun_1 + sql += "%s as asct2, " % base_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(100) + self.cur1.execute(sql) + + tdSql.query("select 1-2 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts , abs(asct1) from ( select " + sql += "%s as asct1, " % base_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s )" % random.choice(self.order_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select ts , asct2 from ( select " + sql += "%s as asct2, " % base_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + #sql += "%s " % random.choice(having_support) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + #tdSql.query(sql) + #self.cur1.execute(sql) + + tdSql.query("select 1-3 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts , min(asct1) from ( select " + sql += "%s as asct1, ts ," % base_fun_1 + sql += "%s as asct2, " % base_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2, ts ," % base_fun_2 + sql += "%s as asct1, " % base_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + #tdSql.query(sql) + #self.cur1.execute(sql) + + tdSql.query("select 1-4 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts1,ts2 ,timediff(ts1,ts2), asct1 from ( select t1.ts as ts1," + sql += "%s, " % base_fun_join_1 + sql += "%s as asct1, " % base_fun_join_2 + sql += "%s, " % base_fun_join_1 + sql += "t1.%s, " % random.choice(self.q_select) + sql += "t2.%s, " % random.choice(self.q_select) + sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + + tdSql.query("select 1-5 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts ," + sql += "%s, " % base_fun_1 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.q_select) + sql += "%s " % base_fun_2 + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += " ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(100) + self.cur1.execute(sql) + + tdSql.query("select 1-6 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts , max(asct1) from ( select t1.ts as ts1," + sql += "%s, " % base_fun_join_1 + sql += "%s as asct1, " % base_fun_join_2 + sql += "t1.%s, " % random.choice(self.q_select) + sql += "t2.%s, " % random.choice(self.q_select) + sql += "%s, " % base_fun_join_1 + sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + + tdSql.query("select 1-7 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts , abs(asct1) from ( select " + sql += "%s as asct1, ts ," % base_fun_1 + sql += "%s as asct2, " % base_fun_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + + tdSql.query("select 1-8 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts,floor(asct1) " + sql += "from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s as asct1, ts ," % base_fun_1 + sql += "%s as asct2, " % base_fun_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) - #1 outer union not support + tdSql.query("select 1-9 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts , max(asct1) from ( select t1.ts as ts1," + sql += "%s, " % base_fun_join_1 + sql += "%s as asct1, " % base_fun_join_2 + sql += "t1.%s, " % random.choice(self.q_select) + sql += "t1.%s, " % random.choice(self.q_select) + sql += "t2.%s, " % random.choice(self.q_select) + sql += "t2.%s, " % random.choice(self.q_select) + sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + + self.restartDnodes() + tdSql.query("select 1-10 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts , min(asct1) from ( select " + sql += "%s as asct1, ts ," % base_fun_1 + sql += "%s as asct2, " % base_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select ts , max(asct2) from ( select " + sql += "%s as asct1, ts ," % base_fun_1 + sql += "%s as asct2, " % base_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + #tdSql.query(sql) + #self.cur1.execute(sql) + + #3 inter union not support + tdSql.query("select 1-11 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts , min(asct1), max(asct2) from ( select " + sql += "%s as asct1, ts ," % base_fun_1 + sql += "%s as asct2, " % base_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + #sql += "%s " % random.choice(limit1_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1, ts ," % base_fun_1 + sql += "%s as asct2, " % base_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdLog.info(len(sql)) + #TD-15837 tdSql.query(sql) + # self.cur1.execute(sql) + + tdSql.query("select 1-12 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts , max(asct1) from ( select t1.ts as ts1," + sql += "%s, " % base_fun_join_1 + sql += "%s as asct1, " % base_fun_join_2 + sql += "t1.%s, " % random.choice(self.q_select) + sql += "t1.%s, " % random.choice(self.q_select) + sql += "t2.%s, " % random.choice(self.q_select) + sql += "t2.%s, " % random.choice(self.q_select) + sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + + tdSql.query("select 1-13 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts ," + sql += "%s, " % base_fun_1 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.q_select) + sql += "%s " % base_fun_2 + sql += "%s " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + + tdSql.query("select 1-14 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select avg(asct1),count(asct2) from ( select " + sql += "%s as asct1, " % base_fun_1 + sql += "%s as asct2" % base_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + + tdSql.query("select 1-15 as base_nest from stable_1 limit 1;") + for i in range(self.fornum): + sql = "select ts , max(asct1) from ( select t1.ts as ts1," + sql += "%s, " % base_fun_join_1 + sql += "%s as asct1, " % base_fun_join_2 + sql += "t1.%s, " % random.choice(self.q_select) + sql += "t1.%s, " % random.choice(self.q_select) + sql += "t2.%s, " % random.choice(self.q_select) + sql += "t2.%s " % random.choice(self.q_select) + sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + + #taos -f sql + startTime_taos_f = time.time() + print("taos -f %s sql start!" %baselist) + taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) + _ = subprocess.check_output(taos_cmd1, shell=True).decode("utf-8") + print("taos -f %s sql over!" %baselist) + endTime_taos_f = time.time() + print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) + + print("=========%s====over=============" %baselist) + + def function_before_26(self): + + print('=====================2.6 old function start ===========') + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + self.dropandcreateDB_random("%s" %self.db_nest, 1) + + #1 select * from (select column form regular_table where <\>\in\and\or order by) + tdSql.query("select 1-1 from stable_1;") + for i in range(self.fornum): + sql = "select tas from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as tas from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ");" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql,queryTimes=1) + tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) + + #1 outer union not support #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 1-2 from stable_1;") for i in range(self.fornum): #sql = "select ts , * from ( select " - sql = "select ts from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) - #sql += "%s, " % q_select[len(q_select) -i-1] - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql = "select t1s from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as t1s from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ") union " - #sql += "select ts , * from ( select " - sql += "select ts from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql += "select t2s from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as t2s from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(100) - + self.cur1.execute(sql) + self.explain_sql(sql) + #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 1-2 from stable_1;") for i in range(self.fornum): - #sql = "select ts , * from ( select " sql = "select ts from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) - #sql += "%s, " % q_select[len(q_select) -i-1] + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ") union all " - #sql += "select ts , * from ( select " sql += "select ts from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(200) - + self.cur1.execute(sql) + self.explain_sql(sql) + #1 inter union not support tdSql.query("select 1-3 from stable_1;") for i in range(self.fornum): #sql = "select ts , * from ( select " sql = "select ts from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "" - sql += " union select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) + sql += "%s " % random.choice(self.q_where) + sql += "" + sql += " union all select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) sql += "ts from regular_table_2 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15606 tdSql.query(sql) - # tdSql.checkRows(200) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + tdSql.query("select 1-3 from stable_1;") for i in range(self.fornum): - #sql = "select ts , * from ( select " sql = "select ts from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(q_where) + sql += "%s " % random.choice(self.q_where) sql += " union all select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) sql += "ts from regular_table_2 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15607 tdSql.query(sql) - # tdSql.checkRows(300) - - #join:TD-6020\TD-6149 select * from (select column form regular_table1,regular_table2 where t1.ts=t2.ts and <\>\in\and\or order by) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) + + #join:select * from (select column form regular_table1,regular_table2 where t1.ts=t2.ts and <\>\in\and\or order by) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 1-4 from stable_1;") for i in range(self.fornum): - #sql = "select ts , * from ( select t1.ts ," - sql = "select * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(q_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(order_u_where) + sql = "select * from ( select t1.ts as t1ts," + sql += "t1.%s as t11, " % random.choice(self.q_select) + sql += "t1.%s as t12, " % random.choice(self.q_select) + sql += "t2.%s as t21, " % random.choice(self.q_select) + sql += "t2.%s as t22, " % random.choice(self.q_select) + sql += "t2.ts as t2ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) - tdSql.query("select 1-5 from stable_1;") - for i in range(self.fornum): - sql = "select ts , * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(q_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) - sql += "%s " % random.choice(order_u_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) - # TD-15587 tdSql.query(sql) - # tdSql.checkRows(100) - #2 select column from (select * form regular_table ) where <\>\in\and\or order by + #2 select column from (select * form regular_table ) where <\>\in\and\or order by #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 2-1 from stable_1;") for i in range(self.fornum): sql = "select ts ," - sql += "%s, " % random.choice(s_r_select) - sql += "%s " % random.choice(q_select) + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s " % random.choice(self.q_select) sql += " from ( select * from regular_table_1 ) where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(100) + self.cur1.execute(sql) + self.explain_sql(sql) #join: select column from (select column form regular_table1,regular_table2 )where t1.ts=t2.ts and <\>\in\and\or order by #cross join not supported yet tdSql.query("select 2-2 from stable_1;") for i in range(self.fornum): sql = "select ts , * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(q_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(self.q_select) + sql += "t1.%s, " % random.choice(self.q_select) + sql += "t2.%s, " % random.choice(self.q_select) + sql += "t2.%s, " % random.choice(self.q_select) sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 ) where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(order_u_where) + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.order_u_where) #sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.error(sql) - #3 select * from (select column\tag form stable where <\>\in\and\or order by ) + #3 select * from (select column\tag form stable where <\>\in\and\or order by ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 3-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s, " % random.choice(s_s_select) - sql += "%s, " % random.choice(q_select) - sql += "%s, " % random.choice(t_select) + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) sql += "ts from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) sql += ") ;" - tdLog.info(sql) + tdLog.info(sql) tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 3-1 from stable_1;") for i in range(self.fornum): sql = "select ts, " - sql += "%s " % random.choice(s_r_select) + sql += "%s " % random.choice(self.s_r_select) sql += "from ( select " - sql += "%s, " % random.choice(s_s_select) - sql += "%s, " % random.choice(q_select) - sql += "%s, " % random.choice(t_select) + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) sql += "ts from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) sql += ") ;" - tdLog.info(sql) + tdLog.info(sql) tdLog.info(len(sql)) - tdSql.query(sql) + tdSql.query(sql) tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) - # select ts,* from (select column\tag form stable1,stable2 where t1.ts = t2.ts and <\>\in\and\or order by ) + # select ts,* from (select column\tag form stable1,stable2 where t1.ts = t2.ts and <\>\in\and\or order by ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 3-2 from stable_1;") for i in range(self.fornum): - sql = "select ts , * from ( select t1.ts , " - sql += "t1.%s, " % random.choice(s_s_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(s_s_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) - sql += "%s " % random.choice(order_u_where) + #sql = "select ts , * from ( select t1.ts as t1ts , " + sql = "select t1ts , t2ts from ( select t1.ts as t1ts , " + sql += "t1.%s as t11, " % random.choice(self.t_select) + sql += "t1.%s as t12, " % random.choice(self.q_select) + sql += "t2.%s as t13, " % random.choice(self.t_select) + sql += "t2.%s as t14, " % random.choice(self.q_select) + sql += "t2.ts as t2ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.order_u_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # TD-15609 tdSql.query(sql) - # tdSql.checkRows(100) - + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + #3 outer union not support - rsDn = self.restartDnodes() + self.restartDnodes() tdSql.query("select 3-3 from stable_1;") for i in range(self.fornum): #sql = "select ts , * from ( select " - sql = "select ts from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql = "select ts1 from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts1 from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ") union " - sql += "select ts from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql += "select ts2 from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts2 from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - tdSql.checkRows(200) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) for i in range(self.fornum): - #sql = "select ts , * from ( select " - sql = "select ts from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql = "select ts1 from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts1 from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ") union all " - sql += "select ts from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql += "select ts2 from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts2 from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - tdSql.checkRows(400) - + tdSql.checkRows(600) + self.cur1.execute(sql) + self.explain_sql(sql) + #3 inter union not support tdSql.query("select 3-4 from stable_1;") for i in range(self.fornum): - sql = "select ts , * from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) + sql = "select * from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) sql += "ts from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) - sql += " %s " % random.choice(unionall_or_union) + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) sql += " select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) sql += "ts from stable_2 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) #join:select * from (select column form stable1,stable2 where t1.ts=t2.ts and <\>\in\and\or order by) tdSql.query("select 3-5 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(q_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_u_where) - sql += "%s " % random.choice(order_u_where) + sql = "select * from ( select t1.ts as t1ts," + sql += "t1.%s as t11, " % random.choice(self.q_select) + sql += "t1.%s as t12, " % random.choice(self.q_select) + sql += "t2.%s as t21, " % random.choice(self.q_select) + sql += "t2.%s as t22, " % random.choice(self.q_select) + sql += "t2.ts as t2ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "%s " % random.choice(self.order_u_where) sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - # TD-15609 tdSql.query(sql) - # tdSql.checkRows(100) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 3-6 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(q_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_u_or_where) - sql += "%s " % random.choice(order_u_where) + sql = "select * from ( select t1.ts as t1ts ," + sql += "t1.%s as t11, " % random.choice(self.q_select) + sql += "t1.%s as t12, " % random.choice(self.q_select) + sql += "t2.%s as t21, " % random.choice(self.q_select) + sql += "t2.%s as t22, " % random.choice(self.q_select) + sql += "t2.ts as t2ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - # TD-15609 同上 tdSql.query(sql) - # tdSql.checkRows(100) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) - #4 select column from (select * form stable where <\>\in\and\or order by ) + #4 select column from (select * form stable where <\>\in\and\or order by ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 4-1 from stable_1;") for i in range(self.fornum): sql = "select ts , " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) - sql += "%s " % random.choice(t_select) + sql += "%s as t11, " % random.choice(self.q_select) + sql += "%s as t12, " % random.choice(self.q_select) + sql += "%s " % random.choice(self.t_select) sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15616 tdSql.query(sql) - # tdSql.checkRows(300) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + tdSql.checkRows(300) + self.cur1.execute(sql) + self.explain_sql(sql) #5 select distinct column\tag from (select * form stable where <\>\in\and\or order by limit offset ) tdSql.query("select 5-1 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(dqt_select) + sql += "%s " % random.choice(self.dqt_select) sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15500 tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) #5-1 select distinct column\tag from (select calc form stable where <\>\in\and\or order by limit offset ) tdSql.query("select 5-2 from stable_1;") for i in range(self.fornum): sql = "select distinct c5_1 " sql += " from ( select " - sql += "%s " % random.choice(calc_select_in_ts) + sql += "%s " % random.choice(self.calc_select_in_ts) sql += " as c5_1 from stable_1 where " - sql += "%s " % random.choice(qt_where) - #sql += "%s " % random.choice(order_where) + sql += "%s " % random.choice(self.qt_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - #tdSql.checkRows(1)有的函数还没有提交,会不返回结果,先忽略 + self.cur1.execute(sql) + self.explain_sql(sql) #6-error select * from (select distinct(tag) form stable where <\>\in\and\or order by limit ) tdSql.query("select 6-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(dt_select) + sql += "%s " % random.choice(self.dt_select) sql += " from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(order_desc_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_desc_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.error(sql) tdSql.query("select 6-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(dt_select) + sql += "%s " % random.choice(self.dt_select) sql += " from stable_1 where " - sql += "%s ) ;" % random.choice(qt_where) - tdLog.info(sql) - tdLog.info(len(sql)) + sql += "%s ) ;" % random.choice(self.qt_where) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - #tdSql.checkRows(1)#数量不一致,不在校验 + self.cur1.execute(sql) + self.explain_sql(sql) #7-error select * from (select distinct(tag) form stable where <\>\in\and\or order by limit ) tdSql.query("select 7-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(dq_select) + sql += "%s " % random.choice(self.dq_select) sql += " from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice([limit_where[0] , limit_where[1]] ) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[0] , self.limit_where[1]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) #distinct 和 order by 不能混合使用 + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.error(sql) tdSql.query("select 7-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(dq_select) + sql += "%s " % random.choice(self.dq_select) sql += " from stable_1 where " - sql += "%s " % random.choice(qt_where) - #sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice([limit_where[0] , limit_where[1]] ) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice([self.limit_where[0] , self.limit_where[1]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(1) + self.cur1.execute(sql) + self.explain_sql(sql) #calc_select,TWA/Diff/Derivative/Irate are not allowed to apply to super table directly #8 select * from (select ts,calc form ragular_table where <\>\in\and\or order by ) - + # dcDB = self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 8-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select ts ," - sql += "%s " % random.choice(calc_select_support_ts) + sql += "%s " % random.choice(self.calc_select_support_ts) sql += "from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) # 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 8-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_not_support_ts) + sql += "%s " % random.choice(self.calc_select_not_support_ts) sql += "from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) # 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function - + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_in_ts) + sql += "%s " % random.choice(self.calc_select_in_ts) sql += "from regular_table_1 where " - sql += "%s " % random.choice(q_where) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - ##top返回结果有问题nest.sql tdSql.checkRows(1) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 8-2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select t1.ts, " - sql += "%s " % random.choice(calc_select_in_support_ts_j) + sql += "%s " % random.choice(self.calc_select_in_support_ts_j) sql += "from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql)# 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_in_not_support_ts_j) + sql += "%s " % random.choice(self.calc_select_in_not_support_ts_j) sql += "from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - ##top返回结果有问题 tdSql.checkRows(1) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) - #9 select * from (select ts,calc form stable where <\>\in\and\or order by ) + #9 select * from (select ts,calc form stable where <\>\in\and\or order by ) # self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 9-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_not_support_ts) + sql += "%s " % random.choice(self.calc_select_not_support_ts) sql += "from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 9-2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select ts ," - sql += "%s " % random.choice(calc_select_support_ts) + sql += "%s " % random.choice(self.calc_select_support_ts) sql += "from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - + self.cur1.execute(sql) + self.explain_sql(sql) + tdSql.query("select 9-3 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_in_not_support_ts_j) + sql += "%s " % random.choice(self.calc_select_in_not_support_ts_j) sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) - sql += " and %s " % random.choice(qt_u_or_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 9-4 from stable_1;") for i in range(self.fornum): sql = "select * from ( select t1.ts," - sql += "%s " % random.choice(calc_select_in_support_ts_j) + sql += "%s " % random.choice(self.calc_select_in_support_ts_j) sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) - sql += " and %s " % random.choice(qt_u_or_where) - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - - #10 select calc from (select * form regualr_table where <\>\in\and\or order by ) + self.cur1.execute(sql) + self.explain_sql(sql) + + #10 select calc from (select * form regualr_table where <\>\in\and\or order by ) tdSql.query("select 10-1 from stable_1;") for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(calc_select_in_ts) + sql = "select " + sql += "%s " % random.choice(self.calc_select_in_ts) sql += "as calc10_1 from ( select * from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - tdSql.checkRows(1) - + self.cur1.execute(sql) + self.explain_sql(sql) + #10-1 select calc from (select * form regualr_table where <\>\in\and\or order by ) - # rsDn = self.restartDnodes() + # rsDn = self.restartDnodes() # self.dropandcreateDB_random("%s" %db, 1) # rsDn = self.restartDnodes() tdSql.query("select 10-2 from stable_1;") for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(calc_select_all) + sql = "select " + sql += "%s " % random.choice(self.calc_select_all) sql += "as calc10_2 from ( select * from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - # tdSql.checkRows(1) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) - #10-2 select calc from (select * form regualr_tables where <\>\in\and\or order by ) + #10-2 select calc from (select * form regualr_tables where <\>\in\and\or order by ) tdSql.query("select 10-3 from stable_1;") for i in range(self.fornum): - sql = "select " - sql += "%s as calc10_3 " % random.choice(calc_select_all) - sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += " and %s " % random.choice(q_u_or_where) - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql = "select " + sql += "count(*) as calc10_3 " + sql += " from ( select t1.ts as t11, t2.ts as t22 from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += " and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - sql += "%s ;" % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) + sql += "%s ;" % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 10-4 from stable_1;") for i in range(self.fornum): - sql = "select " - sql += "%s as calc10_4 " % random.choice(calc_select_all) + sql = "select " + sql += "%s as calc10_4 " % random.choice(self.calc_select_all) sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) - sql += " and %s " % random.choice(q_u_or_where) - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_or_where) + sql += " and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - # tdSql.checkRows(1) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.error(sql) - #11 select calc from (select * form stable where <\>\in\and\or order by limit ) + #11 select calc from (select * form stable where <\>\in\and\or order by limit ) tdSql.query("select 11-1 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_select_in_ts) + sql += "%s " % random.choice(self.calc_select_in_ts) sql += "as calc11_1 from ( select * from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - tdSql.checkRows(1) + self.cur1.execute(sql) + self.explain_sql(sql) - #11-1 select calc from (select * form stable where <\>\in\and\or order by limit ) + #11-1 select calc from (select * form stable where <\>\in\and\or order by limit ) tdSql.query("select 11-2 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_select_all) + sql += "%s " % random.choice(self.calc_select_all) sql += "as calc11_1 from ( select * from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - #不好计算结果 tdSql.checkRows(1) - + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + #11-2 select calc from (select * form stables where <\>\in\and\or order by limit ) tdSql.query("select 11-3 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_select_all) + sql += "%s " % random.choice(self.calc_select_all) sql += "as calc11_1 from ( select * from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.error(sql) tdSql.query("select 11-4 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_select_all) + sql += "%s " % random.choice(self.calc_select_all) sql += "as calc11_1 from ( select * from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(qt_u_or_where) - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.error(sql) - #12 select calc-diff from (select * form regualr_table where <\>\in\and\or order by limit ) + #12 select calc-diff from (select * form regualr_table where <\>\in\and\or order by limit ) ##self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 12-1 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(self.calc_calculate_regular) sql += " from ( select * from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - ##目前derivative不支持 tdSql.query(sql) - # tdSql.checkRows(1) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 12-2 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(self.calc_calculate_regular) sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #目前derivative不支持 tdSql.query(sql) - # tdSql.checkRows(1) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.error(sql) tdSql.query("select 12-2.2 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(self.calc_calculate_regular) sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #目前derivative不支持 tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.error(sql) #12-1 select calc-diff from (select * form stable where <\>\in\and\or order by limit ) tdSql.query("select 12-3 from stable_1;") - rsDn = self.restartDnodes() + self.restartDnodes() for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(self.calc_calculate_regular) sql += " from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(group_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) sql += ") " - sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #目前derivative不支持 tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 12-4 from stable_1;") #join query does not support group by for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_calculate_regular_j) + sql += "%s " % random.choice(self.calc_calculate_regular_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) - sql += "%s " % random.choice(group_where_j) + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.partiton_where_j) sql += ") " - #sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) 目前de函数不支持,另外看看需要不需要将group by和pari by分开 + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 12-5 from stable_1;") #join query does not support group by for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_calculate_regular_j) + sql += "%s " % random.choice(self.calc_calculate_regular_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(qt_u_or_where) - sql += "%s " % random.choice(group_where_j) + sql += "%s " % random.choice(self.qt_u_or_where) sql += ") " - sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #derivative not support tdSql.query(sql) - + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + #13 select calc-diff as diffns from (select * form stable where <\>\in\and\or order by limit ) tdSql.query("select 13-1 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(self.calc_calculate_regular) sql += " as calc13_1 from ( select * from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(orders_desc_where) - sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.orders_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #derivative not support tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) #14 select * from (select calc_aggregate_alls as agg from stable where <\>\in\and\or group by order by slimit soffset ) - # TD-5955 select * from ( select count (q_double) from stable_1 where t_bool = true or t_bool = false group by loc order by ts asc slimit 1 ) ; tdSql.query("select 14-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(calc_aggregate_all) - sql += "%s as calc14_2, " % random.choice(calc_aggregate_all) - sql += "%s " % random.choice(calc_aggregate_all) + sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all) + sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all) + sql += "%s " % random.choice(self.calc_aggregate_all) sql += " as calc14_3 from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(group_where) - sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice(slimit1_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.group_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15678 tdSql.query(sql) - # tdSql.checkRows(1) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) # error group by in out query tdSql.query("select 14-2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(calc_aggregate_all) - sql += "%s as calc14_2, " % random.choice(calc_aggregate_all) - sql += "%s " % random.choice(calc_aggregate_all) + sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all) + sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all) + sql += "%s " % random.choice(self.calc_aggregate_all) sql += " as calc14_3 from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(group_where) - sql += "%s " % random.choice(having_support) - sql += "%s " % random.choice(orders_desc_where) - sql += "%s " % random.choice(slimit1_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.partiton_where_regular) + sql += "%s " % random.choice(self.slimit1_where) sql += ") " - sql += "%s " % random.choice(group_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15678 tdSql.query(sql) - # tdSql.checkRows(1) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) #14-2 select * from (select calc_aggregate_all_js as agg from stables where <\>\in\and\or group by order by slimit soffset ) tdSql.query("select 14-3 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(calc_aggregate_all_j) - sql += "%s as calc14_2, " % random.choice(calc_aggregate_all_j) - sql += "%s " % random.choice(calc_aggregate_all_j) + sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all_j) + sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all_j) + sql += "%s " % random.choice(self.calc_aggregate_all_j) sql += " as calc14_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) - sql += "%s " % random.choice(partiton_where_j) - sql += "%s " % random.choice(slimit1_where) + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) sql += ") " - sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 14-4 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(calc_aggregate_all_j) - sql += "%s as calc14_2, " % random.choice(calc_aggregate_all_j) - sql += "%s " % random.choice(calc_aggregate_all_j) + sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all_j) + sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all_j) + sql += "%s " % random.choice(self.calc_aggregate_all_j) sql += " as calc14_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(qt_u_or_where) - sql += "%s " % random.choice(partiton_where_j) - sql += "%s " % random.choice(slimit1_where) + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) sql += ") " - sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) - #15 TD-6320 select * from (select calc_aggregate_regulars as agg from regular_table where <\>\in\and\or order by slimit soffset ) + #15 select * from (select calc_aggregate_regulars as agg from regular_table where <\>\in\and\or order by slimit soffset ) tdSql.query("select 15-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_regular) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_regular) - sql += "%s " % random.choice(calc_aggregate_regular) + sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_regular) + sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_regular) + sql += "%s " % random.choice(self.calc_aggregate_regular) sql += " as calc15_3 from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(group_where_regular) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.group_where_regular) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #Invalid function name: twa' - # tdSql.checkRows(1) - + tdLog.info(sql) + tdLog.info(len(sql)) + self.data_check(sql,mark='15-1') + tdSql.query("select 15-2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_regular_j) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_regular_j) - sql += "%s " % random.choice(calc_aggregate_regular_j) - sql += " as calc15_3 from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(group_where_regular_j) - sql += "%s " % random.choice(limit_u_where) + sql += "%s as calc15_2 " % random.choice(self.calc_aggregate_regular_j) + sql += "from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.group_where_regular_j) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #Invalid function name: twa' + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 15-2.2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_regular_j) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_regular_j) - sql += "%s " % random.choice(calc_aggregate_regular_j) + sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_regular_j) + sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_regular_j) + sql += "%s " % random.choice(self.calc_aggregate_regular_j) sql += " as calc15_3 from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) - sql += "%s " % random.choice(group_where_regular_j) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.group_where_regular_j) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #Invalid function name: twa' + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) - rsDn = self.restartDnodes() + self.restartDnodes() tdSql.query("select 15-3 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname) - sql += "%s " % random.choice(calc_aggregate_groupbytbname) + sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_groupbytbname) + sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_groupbytbname) + sql += "%s " % random.choice(self.calc_aggregate_groupbytbname) sql += " as calc15_3 from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(group_where) - sql += "%s " % random.choice(having_support) - sql += "%s " % random.choice(order_desc_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.group_only_where) + sql += "%s " % random.choice(self.having_support) sql += ") " - sql += "order by calc15_1 " - sql += "%s " % random.choice(limit_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #Invalid function name: twa',可能还的去掉order by + sql += "order by calc15_1 " + sql += "%s " % random.choice(self.limit_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 15-4 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname_j) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname_j) - sql += "%s " % random.choice(calc_aggregate_groupbytbname_j) + sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_groupbytbname_j) + sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_groupbytbname_j) + sql += "%s " % random.choice(self.calc_aggregate_groupbytbname_j) sql += " as calc15_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) - sql += "%s " % random.choice(group_where_j) - sql += "%s " % random.choice(having_support_j) - #sql += "%s " % random.choice(orders_desc_where) + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.group_only_where_j) + sql += "%s " % random.choice(self.having_support_j) sql += ") " - sql += "order by calc15_1 " - sql += "%s " % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #'Invalid function name: irate' + sql += "order by calc15_1 " + sql += "%s " % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 15-4.2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname_j) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname_j) - sql += "%s " % random.choice(calc_aggregate_groupbytbname_j) + sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_groupbytbname_j) + sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_groupbytbname_j) + sql += "%s " % random.choice(self.calc_aggregate_groupbytbname_j) sql += " as calc15_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(qt_u_or_where) - sql += "%s " % random.choice(group_where_j) - sql += "%s " % random.choice(having_support_j) - sql += "%s " % random.choice(orders_desc_where) + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.group_where_j) sql += ") " - sql += "order by calc15_1 " - sql += "%s " % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15678 #tdSql.query(sql) + sql += "order by calc15_1 " + sql += "%s " % random.choice(self.limit_u_where) + tdLog.info(sql) + tdLog.info(len(sql)) + self.data_check(sql,mark='15-4.2') tdSql.query("select 15-5 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname) - sql += "%s " % random.choice(calc_aggregate_groupbytbname) + sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_groupbytbname) + sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_groupbytbname) + sql += "%s " % random.choice(self.calc_aggregate_groupbytbname) sql += " as calc15_3 from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(group_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.group_where) sql += ") " - sql += "order by calc15_1 " - sql += "%s " % random.choice(limit_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #'Invalid function name: irate' - - #16 select * from (select calc_aggregate_regulars as agg from regular_table where <\>\in\and\or order by limit offset ) + sql += "order by calc15_1 " + sql += "%s " % random.choice(self.limit_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + #16 select * from (select calc_aggregate_regulars as agg from regular_table where <\>\in\and\or order by limit offset ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 16-1 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_0 , " % random.choice(calc_calculate_all) - sql += "%s as calc16_1 , " % random.choice(calc_aggregate_all) - sql += "%s as calc16_2 " % random.choice(calc_select_in) + sql = "select * from ( select " + sql += "%s as calc16_0 , " % random.choice(self.calc_calculate_all) + sql += "%s as calc16_1 , " % random.choice(self.calc_aggregate_all) + sql += "%s as calc16_2 " % random.choice(self.calc_select_in) sql += " from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(group_where) - #sql += "%s " % random.choice(having_support)having和 partition不能混合使用 + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.group_where) sql += ") " - sql += "order by calc16_0 " - sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) + sql += "order by calc16_0 " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 16-2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_0 " % random.choice(calc_calculate_all_j) - sql += ", %s as calc16_1 " % random.choice(calc_aggregate_all_j) - #sql += ", %s as calc16_2 " % random.choice(calc_select_in_j) + sql = "select * from ( select " + sql += "%s as calc16_0 " % random.choice(self.calc_calculate_all_j) + sql += ", %s as calc16_1 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) + sql += "%s " % random.choice(self.t_join_where) sql += ") " - sql += "order by calc16_0 " - sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + sql += "order by calc16_0 " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 16-2.2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_0 " % random.choice(calc_calculate_all_j) - sql += ", %s as calc16_1 " % random.choice(calc_aggregate_all_j) + sql = "select * from ( select " + sql += "%s as calc16_0 " % random.choice(self.calc_calculate_all_j) + sql += ", %s as calc16_1 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(qt_u_or_where) + sql += "%s " % random.choice(self.qt_u_or_where) sql += ") " - sql += "order by calc16_0 " - sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + sql += "order by calc16_0 " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - + self.cur1.execute(sql) + self.explain_sql(sql) + tdSql.query("select 16-3 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_regular) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_regular) sql += " from regular_table_1 where " - sql += "%s " % random.choice(q_where) + sql += "%s " % random.choice(self.q_where) sql += "limit 2 ) " - sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql)#Invalid function name: derivative' + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 16-4 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_regular_j) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_regular_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) + sql += "%s " % random.choice(self.q_u_where) sql += "limit 2 ) " - sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql)#Invalid function name: derivative' + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 16-4.2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_regular_j) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_regular_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) + sql += "%s " % random.choice(self.q_u_or_where) sql += "limit 2 ) " - sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql)#Invalid function name: derivative' - + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + tdSql.query("select 16-5 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 , " % random.choice(calc_calculate_all) - sql += "%s as calc16_1 , " % random.choice(calc_calculate_regular) - sql += "%s as calc16_2 " % random.choice(calc_select_all) + sql = "select * from ( select " + sql += "%s as calc16_1 , " % random.choice(self.calc_calculate_all) + sql += "%s as calc16_2 , " % random.choice(self.calc_calculate_all) + sql += "%s as calc16_3 " % random.choice(self.calc_calculate_all) sql += " from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(group_where) - #sql += "%s " % random.choice(having_support) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.group_where) sql += ") " - sql += "order by calc16_1 " - sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - + sql += "order by calc16_1 " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + tdSql.query("select 16-6 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_groupbytbname) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_groupbytbname) sql += " from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(group_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) sql += "limit 2 ) " - sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #Invalid function name: derivative' tdSql.query(sql) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 16-7 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_groupbytbname_j) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_groupbytbname_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) + sql += "%s " % random.choice(self.t_join_where) sql += "limit 2 ) " - sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #Invalid function name: derivative' tdSql.query(sql) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 16-8 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_groupbytbname_j) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_groupbytbname_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(qt_u_or_where) + sql += "%s " % random.choice(self.qt_u_or_where) sql += "limit 2 ) " - sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #Invalid function name: derivative' tdSql.query(sql) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) #17 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or interval_sliding group by having order by limit offset )interval_sliding #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 17-1 from stable_1;") for i in range(self.fornum): - #this is having_support , but tag-select cannot mix with last_row,other select can + #this is having_support , but tag-select cannot mix with last_row,other select can sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_0 , " % random.choice(calc_calculate_all) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal17_0 , " % random.choice(self.calc_calculate_all) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) sql += " from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(partiton_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(having_support) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15719 tdSql.query(sql) - + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + tdSql.query("select 17-2 from stable_1;") for i in range(self.fornum): - #this is having_support , but tag-select cannot mix with last_row,other select can + #this is having_support , but tag-select cannot mix with last_row,other select can sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_0 , " % random.choice(calc_calculate_all_j) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_0 , " % random.choice(self.calc_calculate_all_j) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 17-2.2 from stable_1;") for i in range(self.fornum): - #this is having_support , but tag-select cannot mix with last_row,other select can + #this is having_support , but tag-select cannot mix with last_row,other select can sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_0 , " % random.choice(calc_calculate_all_j) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_0 , " % random.choice(self.calc_calculate_all_j) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(qt_u_or_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) self.restartDnodes() tdSql.query("select 17-3 from stable_1;") for i in range(self.fornum): #this is having_tagnot_support , because tag-select cannot mix with last_row... sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) sql += " from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(partiton_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(having_tagnot_support) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15770 tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 17-4 from stable_1;") for i in range(self.fornum): #this is having_tagnot_support , because tag-select cannot mix with last_row... sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 17-4.2 from stable_1;") for i in range(self.fornum): #this is having_tagnot_support , because tag-select cannot mix with last_row... sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(qt_u_or_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 17-5 from stable_1;") for i in range(self.fornum): - #having_not_support + #having_not_support sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) sql += " from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(partiton_where) - sql += "%s " % random.choice(interval_sliding) - # sql += "%s " % random.choice(having_not_support) - # sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15719 tdSql.query(sql) - + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + tdSql.query("select 17-6 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) sql += " from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15770 tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 17-7 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 17-7.2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) self.restartDnodes() tdSql.query("select 17-8 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) sql += " from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + tdSql.query("select 17-9 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 17-10 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) - sql += "%s " % random.choice(interval_sliding) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) #18 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or session order by limit )interval_sliding tdSql.query("select 18-1 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all) sql += " from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(session_where) - #sql += "%s " % random.choice(fill_where) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.session_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + tdSql.query("select 18-2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(session_u_where) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 18-2.2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) - sql += "%s " % random.choice(session_u_where) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) self.restartDnodes() tdSql.query("select 18-3 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all) sql += " from stable_1_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(session_where) - #sql += "%s " % random.choice(fill_where) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.session_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 18-4 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(session_u_where) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 18-4.2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) - sql += "%s " % random.choice(session_u_where) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 18-5 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all) sql += " from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(session_where) - #sql += "%s " % random.choice(fill_where) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.session_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15770 tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 18-6 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(t_join_where) - sql += "%s " % random.choice(session_u_where) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + tdSql.query("select 18-7 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(qt_u_or_where) - sql += "%s " % random.choice(session_u_where) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) - #19 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or session order by limit )interval_sliding + #19 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or session order by limit )interval_sliding #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 19-1 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all) sql += " from regular_table_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(state_window) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.state_window) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 19-2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(state_u_window) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.state_u_window) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 19-2.2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) - sql += "%s " % random.choice(state_u_window) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.state_u_window) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + tdSql.query("select 19-3 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all) sql += " from stable_1_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(state_window) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.state_window) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 19-4 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - #sql += "%s " % random.choice(state_window) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 19-4.2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 19-5 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all) sql += " from stable_1 where " - sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(state_window) - sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit1_where) + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.state_window) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) sql += ") " - sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) #'STATE_WINDOW not support for super table query' - + sql += "%s " % random.choice(self.interval_sliding) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.error(sql) + tdSql.query("select 19-6 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) - #sql += "%s " % random.choice(state_window) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) tdSql.query("select 19-7 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(qt_u_or_where) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) - #20 select * from (select calc_select_fills form regualr_table or stable where <\>\in\and\or fill_where group by order by limit offset ) + #20 select * from (select calc_select_fills form regualr_table or stable where <\>\in\and\or fill_where group by order by limit offset ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 20-1 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(calc_select_fill) - sql += "%s ," % random.choice(calc_select_fill) - sql += "%s " % random.choice(calc_select_fill) + sql = "select * from ( select " + sql += "%s , " % random.choice(self.calc_select_fill) + sql += "%s ," % random.choice(self.calc_select_fill) + sql += "%s " % random.choice(self.calc_select_fill) sql += " from stable_1 where " - sql += "%s " % random.choice(interp_where) - sql += "%s " % random.choice(fill_where) - sql += "%s " % random.choice(group_where) - sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit_where) + sql += "%s " % random.choice(self.interp_where) + sql += "%s " % random.choice(self.fill_where) + sql += "%s " % random.choice(self.group_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #interp不支持 tdSql.query(sql) + #self.cur1.execute(sql) + #self.explain_sql(sql) rsDn = self.restartDnodes() tdSql.query("select 20-2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(calc_select_fill_j) - sql += "%s ," % random.choice(calc_select_fill_j) - sql += "%s " % random.choice(calc_select_fill_j) + sql = "select * from ( select " + sql += "%s , " % random.choice(self.calc_select_fill_j) + sql += "%s ," % random.choice(self.calc_select_fill_j) + sql += "%s " % random.choice(self.calc_select_fill_j) sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s and " % random.choice(t_join_where) - sql += "%s " % random.choice(interp_where_j) - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s and " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.interp_where_j) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #interp不支持 tdSql.query(sql) + #self.cur1.execute(sql) + #self.explain_sql(sql) tdSql.query("select 20-2.2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(calc_select_fill_j) - sql += "%s ," % random.choice(calc_select_fill_j) - sql += "%s " % random.choice(calc_select_fill_j) + sql = "select * from ( select " + sql += "%s , " % random.choice(self.calc_select_fill_j) + sql += "%s ," % random.choice(self.calc_select_fill_j) + sql += "%s " % random.choice(self.calc_select_fill_j) sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s and " % random.choice(qt_u_or_where) - sql += "%s " % random.choice(interp_where_j) - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql += "%s and " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.interp_where_j) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #interp不支持 tdSql.query(sql) + #self.cur1.execute(sql) + #self.explain_sql(sql) tdSql.query("select 20-3 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(calc_select_fill) - sql += "%s ," % random.choice(calc_select_fill) - sql += "%s " % random.choice(calc_select_fill) + sql = "select * from ( select " + sql += "%s , " % random.choice(self.calc_select_fill) + sql += "%s ," % random.choice(self.calc_select_fill) + sql += "%s " % random.choice(self.calc_select_fill) sql += " from stable_1 where " - sql += "%s " % interp_where[2] - sql += "%s " % random.choice(fill_where) - sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit_where) + sql += "%s " % self.interp_where[2] + sql += "%s " % random.choice(self.fill_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #interp不支持 tdSql.query(sql) - + #self.cur1.execute(sql) + #self.explain_sql(sql) + tdSql.query("select 20-4 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(calc_select_fill_j) - sql += "%s ," % random.choice(calc_select_fill_j) - sql += "%s " % random.choice(calc_select_fill_j) - sql += " from stable_1 t1, table_1 t2 where t1.ts = t2.ts and " - #sql += "%s and " % random.choice(t_join_where) - sql += "%s " % interp_where_j[random.randint(0,5)] - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql = "select * from ( select " + sql += "%s , " % random.choice(self.calc_select_fill_j) + sql += "%s ," % random.choice(self.calc_select_fill_j) + sql += "%s " % random.choice(self.calc_select_fill_j) + sql += " from stable_1 t1, table_1 t2 where t1.ts = t2.ts and " + #sql += "%s and " % random.choice(self.t_join_where) + sql += "%s " % self.interp_where_j[random.randint(0,5)] + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #interp不支持 tdSql.query(sql) + #self.cur1.execute(sql) + #self.explain_sql(sql) tdSql.query("select 20-4.2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(calc_select_fill_j) - sql += "%s ," % random.choice(calc_select_fill_j) - sql += "%s " % random.choice(calc_select_fill_j) - sql += " from stable_1 t1, stable_1_1 t2 where t1.ts = t2.ts and " - sql += "%s and " % random.choice(qt_u_or_where) - sql += "%s " % interp_where_j[random.randint(0,5)] - sql += "%s " % random.choice(fill_where) - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + sql = "select * from ( select " + sql += "%s , " % random.choice(self.calc_select_fill_j) + sql += "%s ," % random.choice(self.calc_select_fill_j) + sql += "%s " % random.choice(self.calc_select_fill_j) + sql += " from stable_1 t1, stable_1_1 t2 where t1.ts = t2.ts and " + sql += "%s and " % random.choice(self.qt_u_or_where) + sql += "%s " % self.interp_where_j[random.randint(0,5)] + sql += "%s " % random.choice(self.fill_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) ##interp不支持 tdSql.error(sql) - + #self.cur1.execute(sql) + #self.explain_sql(sql) + tdSql.query("select 20-5 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(calc_select_fill) - sql += "%s ," % random.choice(calc_select_fill) - sql += "%s " % random.choice(calc_select_fill) + sql = "select * from ( select " + sql += "%s , " % random.choice(self.calc_select_fill) + sql += "%s ," % random.choice(self.calc_select_fill) + sql += "%s " % random.choice(self.calc_select_fill) sql += " from regular_table_1 where " - sql += "%s " % interp_where[1] - sql += "%s " % random.choice(fill_where) - sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(limit_where) + sql += "%s " % self.interp_where[1] + sql += "%s " % random.choice(self.fill_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) ##interp不支持 tdSql.query(sql) + #self.cur1.execute(sql) + #self.explain_sql(sql) tdSql.query("select 20-6 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(calc_select_fill_j) - sql += "%s ," % random.choice(calc_select_fill_j) - sql += "%s " % random.choice(calc_select_fill_j) + sql = "select * from ( select " + sql += "%s , " % random.choice(self.calc_select_fill_j) + sql += "%s ," % random.choice(self.calc_select_fill_j) + sql += "%s " % random.choice(self.calc_select_fill_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - #sql += "%s " % random.choice(interp_where_j) - sql += "%s " % interp_where_j[random.randint(0,5)] - sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(limit_u_where) + #sql += "%s " % random.choice(self.interp_where_j) + sql += "%s " % self.interp_where_j[random.randint(0,5)] + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) ##interp不支持 tdSql.query(sql) + #self.cur1.execute(sql) + #self.explain_sql(sql) #1 select * from (select * from (select * form regular_table where <\>\in\and\or order by limit )) tdSql.query("select 1-1 from stable_1;") - for i in range(self.fornum): + for i in range(self.fornum): # sql_start = "select * from ( " # sql_end = ")" for_num = random.randint(1, 15); - sql = "select * from (" * for_num + sql = "select * from (" * for_num sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(q_where) + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ttt from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql += ")" * for_num + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + sql2 = "select * from ( select * from ( select " - sql2 += "%s, " % random.choice(s_r_select) - sql2 += "%s, " % random.choice(q_select) - sql2 += "ts from regular_table_1 where " - sql2 += "%s " % random.choice(q_where) - sql2 += ")) " - tdLog.info(sql2) - tdLog.info(len(sql2)) - + sql2 += "%s, " % random.choice(self.s_r_select) + sql2 += "%s, " % random.choice(self.q_select) + sql2 += "ts as tin from regular_table_1 where " + sql2 += "%s " % random.choice(self.q_where) + sql2 += ")) " + tdLog.info(sql2) + tdLog.info(len(sql2)) + tdSql.query(sql2) + self.cur1.execute(sql2) + self.explain_sql(sql2) + self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql2 ,1,10,1,1) self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql ,1,10,3,3) self.data_matrix_equal('%s' %sql ,1,10,3,3,'%s' %sql2 ,1,10,3,3) - + + tdLog.info("=====1-1==over=========") + for i in range(self.fornum): for_num = random.randint(1, 15); - sql = "select ts from (" * for_num + sql = "select ts2 from (" * for_num sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(q_where) + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts2 from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql += ")" * for_num + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + sql2 = "select * from ( select * from ( select " - sql2 += "%s, " % random.choice(s_r_select) - sql2 += "%s, " % random.choice(q_select) - sql2 += "ts from regular_table_1 where " - sql2 += "%s " % random.choice(q_where) - sql2 += ")) " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql2 += "%s, " % random.choice(self.s_r_select) + sql2 += "%s, " % random.choice(self.q_select) + sql2 += "ts as tt from regular_table_1 where " + sql2 += "%s " % random.choice(self.q_where) + sql2 += ")) " + tdLog.info(sql2) + tdLog.info(len(sql2)) + tdSql.query(sql2) + self.cur1.execute(sql2) + self.explain_sql(sql2) + self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql2 ,1,10,1,1) - + tdLog.info("=====1-2==over=========") + #2 select * from (select * from (select * form stable where <\>\in\and\or order by limit )) tdSql.query("select 2-1 from stable_1;") for i in range(self.fornum): for_num = random.randint(1, 15); - sql = "select * from (" * for_num + sql = "select * from (" * for_num sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(s_s_select) - sql += "%s, " % random.choice(qt_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(q_where) + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.qt_select) + sql += "ts as tss from stable_1 where " + sql += "%s " % random.choice(self.q_where) sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql += ")" * for_num + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + sql2 = "select * from ( select * from ( select " - sql2 += "%s, " % random.choice(s_s_select) - sql2 += "%s, " % random.choice(qt_select) - sql2 += "ts from stable_1 where " - sql2 += "%s " % random.choice(q_where) - sql2 += ")) " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql2 += "%s, " % random.choice(self.s_s_select) + sql2 += "%s, " % random.choice(self.qt_select) + sql2 += "ts as tst from stable_1 where " + sql2 += "%s " % random.choice(self.q_where) + sql2 += ")) " + tdLog.info(sql2) + tdLog.info(len(sql2)) + tdSql.query(sql2) + self.cur1.execute(sql2) + self.explain_sql(sql2) + self.data_matrix_equal('%s' %sql ,1,10,3,3,'%s' %sql2 ,1,10,3,3) - + + tdLog.info("=====2-1==over=========") + for i in range(self.fornum): for_num = random.randint(1, 15); - sql = "select ts from (" * for_num + sql = "select tsn from (" * for_num sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(s_s_select) - sql += "%s, " % random.choice(qt_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(q_where) + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.qt_select) + sql += "ts as tsn from stable_1 where " + sql += "%s " % random.choice(self.q_where) sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - - sql2 = "select ts from ( select * from ( select " - sql2 += "%s, " % random.choice(s_s_select) - sql2 += "%s, " % random.choice(qt_select) - sql2 += "ts from stable_1 where " - sql2 += "%s " % random.choice(q_where) - sql2 += ")) " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql += ")" * for_num + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + sql2 = "select ts1 from ( select * from ( select " + sql2 += "%s, " % random.choice(self.s_s_select) + sql2 += "%s, " % random.choice(self.qt_select) + sql2 += "ts as ts1 from stable_1 where " + sql2 += "%s " % random.choice(self.q_where) + sql2 += ")) " + tdLog.info(sql2) + tdLog.info(len(sql2)) + tdSql.query(sql2) + self.cur1.execute(sql2) + self.explain_sql(sql2) + self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql2 ,1,10,1,1) - - #3 select ts ,calc from (select * form stable where <\>\in\and\or order by limit ) + tdLog.info("=====2-2==over=========") + + #3 select ts ,calc from (select * form stable where <\>\in\and\or order by limit ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 3-1 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(self.calc_calculate_regular) sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(orders_desc_where) - sql += "%s " % random.choice(limit_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.orders_desc_where) + sql += "%s " % random.choice(self.limit_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #'Invalid function name: derivative' tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) #4 select * from (select calc form stable where <\>\in\and\or order by limit ) tdSql.query("select 4-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_in_ts) + sql += "%s " % random.choice(self.calc_select_in_ts) sql += "from stable_1 where " - sql += "%s " % random.choice(qt_where) - #sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice(limit_where) + sql += "%s " % random.choice(self.qt_where) + #sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice(self.limit_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - + self.cur1.execute(sql) + self.explain_sql(sql) + #5 select ts ,tbname from (select * form stable where <\>\in\and\or order by limit ) tdSql.query("select 5-1 from stable_1;") for i in range(self.fornum): sql = "select ts , tbname , " - sql += "%s ," % random.choice(calc_calculate_regular) - sql += "%s ," % random.choice(dqt_select) - sql += "%s " % random.choice(qt_select) + sql += "%s ," % random.choice(self.calc_calculate_regular) + sql += "%s ," % random.choice(self.dqt_select) + sql += "%s " % random.choice(self.qt_select) sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(qt_where) - sql += "%s " % random.choice(orders_desc_where) - sql += "%s " % random.choice(limit_where) + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.orders_desc_where) + sql += "%s " % random.choice(self.limit_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.error(sql) #special sql tdSql.query("select 6-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select _block_dist() from stable_1);" - # tdSql.query(sql) - # tdSql.checkRows(1) + tdSql.error(sql) sql = "select _block_dist() from (select * from stable_1);" tdSql.error(sql) sql = "select * from (select database());" - tdSql.error(sql) + tdLog.info(sql) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) sql = "select * from (select client_version());" - tdSql.error(sql) + tdLog.info(sql) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) sql = "select * from (select client_version() as version);" - tdSql.error(sql) + tdLog.info(sql) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) sql = "select * from (select server_version());" - tdSql.error(sql) + tdLog.info(sql) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) sql = "select * from (select server_version() as version);" - tdSql.error(sql) + tdLog.info(sql) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) sql = "select * from (select server_status());" - tdSql.error(sql) + tdLog.info(sql) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) sql = "select * from (select server_status() as status);" - tdSql.error(sql) - + tdLog.info(sql) + tdSql.query(sql) + self.cur1.execute(sql) + self.explain_sql(sql) + + #taos -f sql + startTime_taos_f = time.time() + print("taos -f sql start!") + taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) + #_ = subprocess.check_output(taos_cmd1, shell=True).decode("utf-8") + _ = subprocess.check_output(taos_cmd1, shell=True) + print("taos -f sql over!") + endTime_taos_f = time.time() + print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) + + print('=====================2.6 old function end ===========') + + + + def run(self): + tdSql.prepare() + + startTime = time.time() + + self.function_before_26() + + self.math_nest(['UNIQUE']) + self.math_nest(['MODE']) + self.math_nest(['SAMPLE']) + + # self.math_nest(['ABS','SQRT']) + # self.math_nest(['SIN','COS','TAN','ASIN','ACOS','ATAN']) + # self.math_nest(['POW','LOG']) + # self.math_nest(['FLOOR','CEIL','ROUND']) + # self.math_nest(['MAVG']) + # self.math_nest(['HYPERLOGLOG']) + # self.math_nest(['TAIL']) + # self.math_nest(['CSUM']) + # self.math_nest(['statecount','stateduration']) + # self.math_nest(['HISTOGRAM']) + + # self.str_nest(['LTRIM','RTRIM','LOWER','UPPER']) + # self.str_nest(['LENGTH','CHAR_LENGTH']) + # self.str_nest(['SUBSTR']) + # self.str_nest(['CONCAT']) + # self.str_nest(['CONCAT_WS']) + # self.time_nest(['CAST']) #放到time里起来弄 + # self.time_nest(['CAST_1']) + # self.time_nest(['CAST_2']) + # self.time_nest(['CAST_3']) + # self.time_nest(['CAST_4']) + + + + # self.time_nest(['NOW','TODAY']) + # self.time_nest(['TIMEZONE']) + # self.time_nest(['TIMETRUNCATE']) + # self.time_nest(['TO_ISO8601']) + # self.time_nest(['TO_UNIXTIMESTAMP']) + # self.time_nest(['ELAPSED']) + self.time_nest(['TIMEDIFF_1']) + self.time_nest(['TIMEDIFF_2']) + endTime = time.time() print("total time %ds" % (endTime - startTime)) - + def stop(self): diff --git a/tests/system-test/2-query/nestedQuery_math.py b/tests/system-test/2-query/nestedQuery_math.py new file mode 100755 index 0000000000000000000000000000000000000000..2d0bbcb352a4cfc732a2ccd4ec83604733146d32 --- /dev/null +++ b/tests/system-test/2-query/nestedQuery_math.py @@ -0,0 +1,76 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- +from util.cases import tdCases +from .nestedQuery import * + +class TDTestCase(TDTestCase): + + + def run(self): + tdSql.prepare() + + startTime = time.time() + + #self.function_before_26() + + # self.math_nest(['UNIQUE']) + # self.math_nest(['MODE']) + # self.math_nest(['SAMPLE']) + + self.math_nest(['ABS','SQRT']) + self.math_nest(['SIN','COS','TAN','ASIN','ACOS','ATAN']) + self.math_nest(['POW','LOG']) + self.math_nest(['FLOOR','CEIL','ROUND']) + self.math_nest(['MAVG']) + self.math_nest(['HYPERLOGLOG']) + self.math_nest(['TAIL']) + self.math_nest(['CSUM']) + self.math_nest(['statecount','stateduration']) + self.math_nest(['HISTOGRAM']) + + # self.str_nest(['LTRIM','RTRIM','LOWER','UPPER']) + # self.str_nest(['LENGTH','CHAR_LENGTH']) + # self.str_nest(['SUBSTR']) + # self.str_nest(['CONCAT']) + # self.str_nest(['CONCAT_WS']) + # self.time_nest(['CAST']) #放到time里起来弄 + # self.time_nest(['CAST_1']) + # self.time_nest(['CAST_2']) + # self.time_nest(['CAST_3']) + # self.time_nest(['CAST_4']) + + + + # self.time_nest(['NOW','TODAY']) + # self.time_nest(['TIMEZONE']) + # self.time_nest(['TIMETRUNCATE']) + # self.time_nest(['TO_ISO8601']) + # self.time_nest(['TO_UNIXTIMESTAMP']) + # self.time_nest(['ELAPSED']) + # self.time_nest(['TIMEDIFF_1']) + # self.time_nest(['TIMEDIFF_2']) + + + endTime = time.time() + print("total time %ds" % (endTime - startTime)) + + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/nestedQuery_str.py b/tests/system-test/2-query/nestedQuery_str.py index 931ff873dcce279d8ddff018549beb648c5cfbc4..6492b3df3a8d67be1e3c3d47d78eafe908a59fe5 100755 --- a/tests/system-test/2-query/nestedQuery_str.py +++ b/tests/system-test/2-query/nestedQuery_str.py @@ -10,5735 +10,61 @@ ################################################################### # -*- coding: utf-8 -*- - -import random -import os -import time -import taos -import subprocess -from faker import Faker -from util.log import tdLog from util.cases import tdCases -from util.sql import tdSql -from util.dnodes import tdDnodes -from util.dnodes import * - -class TDTestCase: - - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - self.testcasePath = os.path.split(__file__)[0] - self.testcaseFilename = os.path.split(__file__)[-1] - os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) - - self.num = 10 - self.fornum = 5 - - self.db_nest = "nest" - self.dropandcreateDB_random("%s" %self.db_nest, 1) - - # regular column select - #q_select= ['ts' , '*' , 'q_int', 'q_bigint' , 'q_bigint' , 'q_smallint' , 'q_tinyint' , 'q_bool' , 'q_binary' , 'q_nchar' ,'q_float' , 'q_double' ,'q_ts '] - self.q_select= ['ts' , 'q_int', 'q_bigint' , 'q_bigint' , 'q_smallint' , 'q_tinyint' , 'q_bool' , 'q_binary' , 'q_nchar' ,'q_float' , 'q_double' ,'q_ts ', 'q_int_null ', 'q_bigint_null ' , 'q_bigint_null ' , 'q_smallint_null ' , 'q_tinyint_null ' , 'q_bool_null ' , 'q_binary_null ' , 'q_nchar_null ' ,'q_float_null ' , 'q_double_null ' ,'q_ts_null '] - - # tag column select - #t_select= ['*' , 'loc' ,'t_int', 't_bigint' , 't_bigint' , 't_smallint' , 't_tinyint' , 't_bool' , 't_binary' , 't_nchar' ,'t_float' , 't_double' ,'t_ts '] - self.t_select= ['loc','t_int', 't_bigint' , 't_bigint' , 't_smallint' , 't_tinyint' , 't_bool' , 't_binary' , 't_nchar' ,'t_float' , 't_double' ,'t_ts '] - - # regular and tag column select - self.qt_select= self.q_select + self.t_select - - # distinct regular column select - self.dq_select= ['distinct q_int', 'distinct q_bigint' , 'distinct q_smallint' , 'distinct q_tinyint' , - 'distinct q_bool' , 'distinct q_binary' , 'distinct q_nchar' ,'distinct q_float' , 'distinct q_double' ,'distinct q_ts '] - - # distinct tag column select - self.dt_select= ['distinct loc', 'distinct t_int', 'distinct t_bigint' , 'distinct t_smallint' , 'distinct t_tinyint' , - 'distinct t_bool' , 'distinct t_binary' , 'distinct t_nchar' ,'distinct t_float' , 'distinct t_double' ,'distinct t_ts '] - - # distinct regular and tag column select - self.dqt_select= self.dq_select + self.dt_select - - # special column select - self.s_r_select= ['_c0', '_rowts' , '_C0' ] - self.s_s_select= ['tbname' , '_rowts' , '_c0', '_C0' ] - self.unionall_or_union= [ ' union ' , ' union all ' ] - - # regular column where - self.q_where = ['ts < now +1s','q_bigint >= -9223372036854775807 and q_bigint <= 9223372036854775807', 'q_int <= 2147483647 and q_int >= -2147483647', - 'q_smallint >= -32767 and q_smallint <= 32767','q_tinyint >= -127 and q_tinyint <= 127','q_float >= -1.7E308 and q_float <= 1.7E308', - 'q_double >= -1.7E308 and q_double <= 1.7E308', 'q_binary like \'binary%\' or q_binary = \'0\' ' , 'q_nchar like \'nchar%\' or q_nchar = \'0\' ' , - 'q_bool = true or q_bool = false' , 'q_bool in (0 , 1)' , 'q_bool in ( true , false)' , 'q_bool = 0 or q_bool = 1', - 'q_bigint between -9223372036854775807 and 9223372036854775807',' q_int between -2147483647 and 2147483647','q_smallint between -32767 and 32767', - 'q_bigint not between 9223372036854775807 and -9223372036854775807','q_int not between 2147483647 and -2147483647','q_smallint not between 32767 and -32767', - 'q_tinyint between -127 and 127 ','q_float >= -3.4E38 ','q_float <= 3.4E38 ','q_double >= -1.7E308 ', - 'q_double <= 1.7E308 ','q_float between -3.4E38 and 3.4E38 ','q_double between -1.7E308 and 1.7E308 ' ,'q_float not between 3.4E38 and -3.4E38 ','q_double not between 1.7E308 and -1.7E308 ', - 'q_float is not null ' ,'q_double is not null ' ,'q_binary match \'binary\' ','q_binary nmatch \'binarynchar\' ','q_nchar match \'nchar\' ','q_nchar nmatch \'binarynchar\' ', - 'q_binary like \'binary%\' ','(q_binary like \'binary%\' or q_nchar = \'0\' or q_binary = \'binary_\' ) ','q_nchar like \'nchar%\' ','(q_nchar like \'nchar%\' or q_binary = \'0\' or q_nchar = \'nchar_\' ) ',] - #TD-6201 ,'q_bool between 0 and 1' - - # regular column where for test union,join - self.q_u_where = ['t1.ts < now +1s' , 't2.ts < now +1s','t1.q_bigint >= -9223372036854775807 and t1.q_bigint <= 9223372036854775807 and t2.q_bigint >= -9223372036854775807 and t2.q_bigint <= 9223372036854775807', - 't1.q_int <= 2147483647 and t1.q_int >= -2147483647 and t2.q_int <= 2147483647 and t2.q_int >= -2147483647', - 't1.q_smallint >= -32767 and t1.q_smallint <= 32767 and t2.q_smallint >= -32767 and t2.q_smallint <= 32767', - 't1.q_tinyint >= -127 and t1.q_tinyint <= 127 and t2.q_tinyint >= -127 and t2.q_tinyint <= 127', - 't1.q_float >= - 1.7E308 and t1.q_float <= 1.7E308 and t2.q_float >= - 1.7E308 and t2.q_float <= 1.7E308', - 't1.q_double >= - 1.7E308 and t1.q_double <= 1.7E308 and t2.q_double >= - 1.7E308 and t2.q_double <= 1.7E308', - 't1.q_binary like \'binary%\' and t2.q_binary like \'binary%\' ' , - 't1.q_nchar like \'nchar%\' and t2.q_nchar like \'nchar%\' ' , - 't1.q_bool in (0 , 1) and t2.q_bool in (0 , 1)' , 't1.q_bool in ( true , false) and t2.q_bool in ( true , false)' , - 't1.q_bigint between -9223372036854775807 and 9223372036854775807 and t2.q_bigint between -9223372036854775807 and 9223372036854775807', - 't1.q_int between -2147483647 and 2147483647 and t2.q_int between -2147483647 and 2147483647', - 't1.q_smallint between -32767 and 32767 and t2.q_smallint between -32767 and 32767', - 't1.q_tinyint between -127 and 127 and t2.q_tinyint between -127 and 127 ','t1.q_float between -1.7E308 and 1.7E308 and t2.q_float between -1.7E308 and 1.7E308', - 't1.q_double between -1.7E308 and 1.7E308 and t2.q_double between -1.7E308 and 1.7E308', - 't1.q_bigint not between 9223372036854775807 and -9223372036854775807 and t2.q_bigint not between 9223372036854775807 and -9223372036854775807', - 't1.q_int not between 2147483647 and -2147483647 and t2.q_int not between 2147483647 and -2147483647', - 't1.q_smallint not between 32767 and -32767 and t2.q_smallint not between 32767 and -32767', - 't1.q_tinyint not between 127 and -127 and t2.q_tinyint not between 127 and -127 ','t1.q_float not between -1.7E308 and -1.7E308 and t2.q_float not between 1.7E308 and -1.7E308', - 't1.q_double not between 1.7E308 and -1.7E308 and t2.q_double not between 1.7E308 and -1.7E308'] - #TD-6201 ,'t1.q_bool between 0 and 1 or t2.q_bool between 0 and 1'] - #'t1.q_bool = true and t1.q_bool = false and t2.q_bool = true and t2.q_bool = false' , 't1.q_bool = 0 and t1.q_bool = 1 and t2.q_bool = 0 and t2.q_bool = 1' , - - self.q_u_or_where = ['(t1.q_binary like \'binary%\' or t1.q_binary = \'0\' or t2.q_binary like \'binary%\' or t2.q_binary = \'0\' )' , - '(t1.q_nchar like \'nchar%\' or t1.q_nchar = \'0\' or t2.q_nchar like \'nchar%\' or t2.q_nchar = \'0\' )' , '(t1.q_bool = true or t1.q_bool = false or t2.q_bool = true or t2.q_bool = false)' , - '(t1.q_bool in (0 , 1) or t2.q_bool in (0 , 1))' , '(t1.q_bool in ( true , false) or t2.q_bool in ( true , false))' , '(t1.q_bool = 0 or t1.q_bool = 1 or t2.q_bool = 0 or t2.q_bool = 1)' , - '(t1.q_bigint between -9223372036854775807 and 9223372036854775807 or t2.q_bigint between -9223372036854775807 and 9223372036854775807)', - '(t1.q_int between -2147483647 and 2147483647 or t2.q_int between -2147483647 and 2147483647)', - '(t1.q_smallint between -32767 and 32767 or t2.q_smallint between -32767 and 32767)', - '(t1.q_tinyint between -127 and 127 or t2.q_tinyint between -127 and 127 )','(t1.q_float between -1.7E308 and 1.7E308 or t2.q_float between -1.7E308 and 1.7E308)', - '(t1.q_double between -1.7E308 and 1.7E308 or t2.q_double between -1.7E308 and 1.7E308)'] - - # tag column where - self.t_where = ['ts < now +1s','t_bigint >= -9223372036854775807 and t_bigint <= 9223372036854775807','t_int <= 2147483647 and t_int >= -2147483647', - 't_smallint >= -32767 and t_smallint <= 32767','q_tinyint >= -127 and t_tinyint <= 127','t_float >= -1.7E308 and t_float <= 1.7E308', - 't_double >= -1.7E308 and t_double <= 1.7E308', 't_binary like \'binary%\' or t_binary = \'0\' ' , 't_nchar like \'nchar%\' or t_nchar = \'0\'' , - 't_bool = true or t_bool = false' , 't_bool in (0 , 1)' , 't_bool in ( true , false)' , 't_bool = 0 or t_bool = 1', - 't_bigint between -9223372036854775807 and 9223372036854775807',' t_int between -2147483647 and 2147483647','t_smallint between -32767 and 32767', - 't_tinyint between -127 and 127 ','t_float between -1.7E308 and 1.7E308','t_double between -1.7E308 and 1.7E308', - 't_binary match \'binary\' ','t_binary nmatch \'binarynchar\' ','t_nchar match \'nchar\' ','t_nchar nmatch \'binarynchar\' ', - 't_binary like \'binary%\' ','t_nchar like \'nchar%\' ','(t_binary like \'binary%\' or t_nchar = \'0\' ) ','(t_nchar like \'nchar%\' or t_binary = \'0\' ) ',] - #TD-6201,'t_bool between 0 and 1' - - # tag column where for test union,join | this is not support - self.t_u_where = ['t1.ts < now +1s' , 't2.ts < now +1s','t1.t_bigint >= -9223372036854775807 and t1.t_bigint <= 9223372036854775807 and t2.t_bigint >= -9223372036854775807 and t2.t_bigint <= 9223372036854775807', - 't1.t_int <= 2147483647 and t1.t_int >= -2147483647 and t2.t_int <= 2147483647 and t2.t_int >= -2147483647', - 't1.t_smallint >= -32767 and t1.t_smallint <= 32767 and t2.t_smallint >= -32767 and t2.t_smallint <= 32767', - 't1.t_tinyint >= -127 and t1.t_tinyint <= 127 and t2.t_tinyint >= -127 and t2.t_tinyint <= 127', - 't1.t_float >= -1.7E308 and t1.t_float <= 1.7E308 and t2.t_float >= -1.7E308 and t2.t_float <= 1.7E308', - 't1.t_double >= -1.7E308 and t1.t_double <= 1.7E308 and t2.t_double >= -1.7E308 and t2.t_double <= 1.7E308', - '(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\') ' , - '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , - 't1.t_bool in (0 , 1) and t2.t_bool in (0 , 1)' , 't1.t_bool in ( true , false) and t2.t_bool in ( true , false)' , '(t1.t_bool = 0 or t1.t_bool = 1 or t2.t_bool = 0 or t2.t_bool = 1)', - 't1.t_bigint between -9223372036854775807 and 9223372036854775807 and t2.t_bigint between -9223372036854775807 and 9223372036854775807', - 't1.t_int between -2147483647 and 2147483647 and t2.t_int between -2147483647 and 2147483647', - 't1.t_smallint between -32767 and 32767 and t2.t_smallint between -32767 and 32767', - '(t1.t_tinyint between -127 and 127 and t2.t_tinyint between -127 and 127) ','t1.t_float between -1.7E308 and 1.7E308 and t2.t_float between -1.7E308 and 1.7E308', - '(t1.t_double between -1.7E308 and 1.7E308 and t2.t_double between -1.7E308 and 1.7E308)'] - #TD-6201,'t1.t_bool between 0 and 1 or t2.q_bool between 0 and 1'] - - self.t_u_or_where = ['(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\' )' , - '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , - '(t1.t_bool in (0 , 1) or t2.t_bool in (0 , 1))' , '(t1.t_bool in ( true , false) or t2.t_bool in ( true , false))' , '(t1.t_bool = 0 or t1.t_bool = 1 or t2.t_bool = 0 or t2.t_bool = 1)', - '(t1.t_bigint between -9223372036854775807 and 9223372036854775807 or t2.t_bigint between -9223372036854775807 and 9223372036854775807)', - '(t1.t_int between -2147483647 and 2147483647 or t2.t_int between -2147483647 and 2147483647)', - '(t1.t_smallint between -32767 and 32767 or t2.t_smallint between -32767 and 32767)', - '(t1.t_tinyint between -127 and 127 or t2.t_tinyint between -127 and 127 )','(t1.t_float between -1.7E308 and 1.7E308 or t2.t_float between -1.7E308 and 1.7E308)', - '(t1.t_double between -1.7E308 and 1.7E308 or t2.t_double between -1.7E308 and 1.7E308)'] - - # regular and tag column where - self.qt_where = self.q_where + self.t_where - self.qt_u_where = self.q_u_where + self.t_u_where - # now,qt_u_or_where is not support - self.qt_u_or_where = self.q_u_or_where + self.t_u_or_where - - # tag column where for test super join | this is support , 't1.t_bool = t2.t_bool ' ??? - self.t_join_where = ['t1.t_bigint = t2.t_bigint ', 't1.t_int = t2.t_int ', 't1.t_smallint = t2.t_smallint ', 't1.t_tinyint = t2.t_tinyint ', - 't1.t_float = t2.t_float ', 't1.t_double = t2.t_double ', 't1.t_binary = t2.t_binary ' , 't1.t_nchar = t2.t_nchar ' ] - - # session && fill - self.session_where = ['session(ts,10a)' , 'session(ts,10s)', 'session(ts,10m)' , 'session(ts,10h)','session(ts,10d)' , 'session(ts,10w)'] - self.session_u_where = ['session(t1.ts,10a)' , 'session(t1.ts,10s)', 'session(t1.ts,10m)' , 'session(t1.ts,10h)','session(t1.ts,10d)' , 'session(t1.ts,10w)', - 'session(t2.ts,10a)' , 'session(t2.ts,10s)', 'session(t2.ts,10m)' , 'session(t2.ts,10h)','session(t2.ts,10d)' , 'session(t2.ts,10w)'] - - self.fill_where = ['FILL(NONE)','FILL(PREV)','FILL(NULL)','FILL(LINEAR)','FILL(NEXT)','FILL(VALUE, 1.23)'] - - self.state_window = ['STATE_WINDOW(q_tinyint)','STATE_WINDOW(q_bigint)','STATE_WINDOW(q_int)','STATE_WINDOW(q_bool)','STATE_WINDOW(q_smallint)'] - self.state_u_window = ['STATE_WINDOW(t1.q_tinyint)','STATE_WINDOW(t1.q_bigint)','STATE_WINDOW(t1.q_int)','STATE_WINDOW(t1.q_bool)','STATE_WINDOW(t1.q_smallint)', - 'STATE_WINDOW(t2.q_tinyint)','STATE_WINDOW(t2.q_bigint)','STATE_WINDOW(t2.q_int)','STATE_WINDOW(t2.q_bool)','STATE_WINDOW(t2.q_smallint)'] - - # order by where - self.order_where = ['order by ts' , 'order by ts asc'] - self.order_u_where = ['order by t1.ts' , 'order by t1.ts asc' , 'order by t2.ts' , 'order by t2.ts asc'] - self.order_desc_where = ['order by ts' , 'order by ts asc' , 'order by ts desc' ] - self.orders_desc_where = ['order by ts' , 'order by ts asc' , 'order by ts desc' , 'order by loc' , 'order by loc asc' , 'order by loc desc'] - - self.group_where = ['group by tbname , loc' , 'group by tbname', 'group by tbname, t_bigint', 'group by tbname,t_int', 'group by tbname, t_smallint', 'group by tbname,t_tinyint', - 'group by tbname,t_float', 'group by tbname,t_double' , 'group by tbname,t_binary', 'group by tbname,t_nchar', 'group by tbname,t_bool' ,'group by tbname ,loc ,t_bigint', - 'group by tbname,t_binary ,t_nchar ,t_bool' , 'group by tbname,t_int ,t_smallint ,t_tinyint' , 'group by tbname,t_float ,t_double ' , - 'PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', - 'PARTITION BY tbname,t_float', 'PARTITION BY tbname,t_double' , 'PARTITION BY tbname,t_binary', 'PARTITION BY tbname,t_nchar', 'PARTITION BY tbname,t_bool' ,'PARTITION BY tbname ,loc ,t_bigint', - 'PARTITION BY tbname,t_binary ,t_nchar ,t_bool' , 'PARTITION BY tbname,t_int ,t_smallint ,t_tinyint' , 'PARTITION BY tbname,t_float ,t_double '] - self.group_where_j = ['group by t1.loc' , 'group by t1.t_bigint', 'group by t1.t_int', 'group by t1.t_smallint', 'group by t1.t_tinyint', - 'group by t1.t_float', 'group by t1.t_double' , 'group by t1.t_binary', 'group by t1.t_nchar', 'group by t1.t_bool' ,'group by t1.loc ,t1.t_bigint', - 'group by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'group by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'group by t1.t_float ,t1.t_double ' , - 'PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', - 'PARTITION by t1.t_float', 'PARTITION by t1.t_double' , 'PARTITION by t1.t_binary', 'PARTITION by t1.t_nchar', 'PARTITION by t1.t_bool' ,'PARTITION BY t1.loc ,t1.t_bigint', - 'PARTITION by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'PARTITION by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'PARTITION by t1.t_float ,t1.t_double ', - 'group by t2.loc' , 'group by t2.t_bigint', 'group by t2.t_int', 'group by t2.t_smallint', 'group by t2.t_tinyint', - 'group by t2.t_float', 'group by t2.t_double' , 'group by t2.t_binary', 'group by t2.t_nchar', 'group by t2.t_bool' ,'group by t2.loc ,t2.t_bigint', - 'group by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'group by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'group by t2.t_float ,t2.t_double ' , - 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', - 'PARTITION by t2.t_float', 'PARTITION by t2.t_double' , 'PARTITION by t2.t_binary', 'PARTITION by t2.t_nchar', 'PARTITION by t2.t_bool' ,'PARTITION BY t2.loc ,t2.t_bigint', - 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] - - self.partiton_where = ['PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', - 'PARTITION BY tbname,t_float', 'PARTITION BY tbname,t_double' , 'PARTITION BY tbname,t_binary', 'PARTITION BY tbname,t_nchar', 'PARTITION BY tbname,t_bool' ,'PARTITION BY tbname ,loc ,t_bigint', - 'PARTITION BY tbname,t_binary ,t_nchar ,t_bool' , 'PARTITION BY tbname,t_int ,t_smallint ,t_tinyint' , 'PARTITION BY tbname,t_float ,t_double '] - self.partiton_where_j = ['PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', - 'PARTITION by t1.t_float', 'PARTITION by t1.t_double' , 'PARTITION by t1.t_binary', 'PARTITION by t1.t_nchar', 'PARTITION by t1.t_bool' ,'PARTITION BY t1.loc ,t1.t_bigint', - 'PARTITION by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'PARTITION by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'PARTITION by t1.t_float ,t1.t_double ', - 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', - 'PARTITION by t2.t_float', 'PARTITION by t2.t_double' , 'PARTITION by t2.t_binary', 'PARTITION by t2.t_nchar', 'PARTITION by t2.t_bool' ,'PARTITION BY t2.loc ,t2.t_bigint', - 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] - - - self.group_where_regular = ['group by tbname ' , 'group by tbname', 'group by tbname, q_bigint', 'group by tbname,q_int', 'group by tbname, q_smallint', 'group by tbname,q_tinyint', - 'group by tbname,q_float', 'group by tbname,q_double' , 'group by tbname,q_binary', 'group by tbname,q_nchar', 'group by tbname,q_bool' ,'group by tbname ,q_bigint', - 'group by tbname,q_binary ,q_nchar ,q_bool' , 'group by tbname,q_int ,q_smallint ,q_tinyint' , 'group by tbname,q_float ,q_double ' , - 'PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', - 'PARTITION BY tbname,q_float', 'PARTITION BY tbname,q_double' , 'PARTITION BY tbname,q_binary', 'PARTITION BY tbname,q_nchar', 'PARTITION BY tbname,q_bool' ,'PARTITION BY tbname ,q_bigint', - 'PARTITION BY tbname,q_binary ,q_nchar ,q_bool' , 'PARTITION BY tbname,q_int ,q_smallint ,q_tinyint' , 'PARTITION BY tbname,q_float ,q_double '] - self.group_where_regular_j = ['group by t1.q_bigint', 'group by t1.q_int', 'group by t1.q_smallint', 'group by t1.q_tinyint', - 'group by t1.q_float', 'group by t1.q_double' , 'group by t1.q_binary', 'group by t1.q_nchar', 'group by t1.q_bool' ,'group by t1.q_bigint', - 'group by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'group by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'group by t1.q_float ,t1.q_double ' , - 'PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', - 'PARTITION by t1.q_float', 'PARTITION by t1.q_double' , 'PARTITION by t1.q_binary', 'PARTITION by t1.q_nchar', 'PARTITION by t1.q_bool' ,'PARTITION BY t1.q_bigint', - 'PARTITION by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'PARTITION by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'PARTITION by t1.q_float ,t1.q_double ', - 'group by t2.q_bigint', 'group by t2.q_int', 'group by t2.q_smallint', 'group by t2.q_tinyint', - 'group by t2.q_float', 'group by t2.q_double' , 'group by t2.q_binary', 'group by t2.q_nchar', 'group by t2.q_bool' ,'group by t2.q_bigint', - 'group by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'group by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'group by t2.q_float ,t2.q_double ' , - 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', - 'PARTITION by t2.q_float', 'PARTITION by t2.q_double' , 'PARTITION by t2.q_binary', 'PARTITION by t2.q_nchar', 'PARTITION by t2.q_bool' ,'PARTITION BY t2.q_bigint', - 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] - - self.partiton_where_regular = ['PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', - 'PARTITION BY tbname,q_float', 'PARTITION BY tbname,q_double' , 'PARTITION BY tbname,q_binary', 'PARTITION BY tbname,q_nchar', 'PARTITION BY tbname,q_bool' ,'PARTITION BY tbname ,q_bigint', - 'PARTITION BY tbname,q_binary ,q_nchar ,q_bool' , 'PARTITION BY tbname,q_int ,q_smallint ,q_tinyint' , 'PARTITION BY tbname,q_float ,q_double '] - self.partiton_where_regular_j = ['PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', - 'PARTITION by t1.q_float', 'PARTITION by t1.q_double' , 'PARTITION by t1.q_binary', 'PARTITION by t1.q_nchar', 'PARTITION by t1.q_bool' ,'PARTITION BY t1.q_bigint', - 'PARTITION by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'PARTITION by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'PARTITION by t1.q_float ,t1.q_double ', - 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', - 'PARTITION by t2.q_float', 'PARTITION by t2.q_double' , 'PARTITION by t2.q_binary', 'PARTITION by t2.q_nchar', 'PARTITION by t2.q_bool' ,'PARTITION BY t2.q_bigint', - 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] - - self.having_support = ['having count(q_int) > 0','having count(q_bigint) > 0','having count(q_smallint) > 0','having count(q_tinyint) > 0','having count(q_float) > 0','having count(q_double) > 0','having count(q_bool) > 0', - 'having avg(q_int) > 0','having avg(q_bigint) > 0','having avg(q_smallint) > 0','having avg(q_tinyint) > 0','having avg(q_float) > 0','having avg(q_double) > 0', - 'having sum(q_int) > 0','having sum(q_bigint) > 0','having sum(q_smallint) > 0','having sum(q_tinyint) > 0','having sum(q_float) > 0','having sum(q_double) > 0', - 'having STDDEV(q_int) > 0','having STDDEV(q_bigint) > 0','having STDDEV(q_smallint) > 0','having STDDEV(q_tinyint) > 0','having STDDEV(q_float) > 0','having STDDEV(q_double) > 0', - 'having TWA(q_int) > 0','having TWA(q_bigint) > 0','having TWA(q_smallint) > 0','having TWA(q_tinyint) > 0','having TWA(q_float) > 0','having TWA(q_double) > 0', - 'having IRATE(q_int) > 0','having IRATE(q_bigint) > 0','having IRATE(q_smallint) > 0','having IRATE(q_tinyint) > 0','having IRATE(q_float) > 0','having IRATE(q_double) > 0', - 'having MIN(q_int) > 0','having MIN(q_bigint) > 0','having MIN(q_smallint) > 0','having MIN(q_tinyint) > 0','having MIN(q_float) > 0','having MIN(q_double) > 0', - 'having MAX(q_int) > 0','having MAX(q_bigint) > 0','having MAX(q_smallint) > 0','having MAX(q_tinyint) > 0','having MAX(q_float) > 0','having MAX(q_double) > 0', - 'having FIRST(q_int) > 0','having FIRST(q_bigint) > 0','having FIRST(q_smallint) > 0','having FIRST(q_tinyint) > 0','having FIRST(q_float) > 0','having FIRST(q_double) > 0', - 'having LAST(q_int) > 0','having LAST(q_bigint) > 0','having LAST(q_smallint) > 0','having LAST(q_tinyint) > 0','having LAST(q_float) > 0','having LAST(q_double) > 0', - 'having APERCENTILE(q_int,10) > 0','having APERCENTILE(q_bigint,10) > 0','having APERCENTILE(q_smallint,10) > 0','having APERCENTILE(q_tinyint,10) > 0','having APERCENTILE(q_float,10) > 0','having APERCENTILE(q_double,10) > 0'] - self.having_not_support = ['having TOP(q_int,10) > 0','having TOP(q_bigint,10) > 0','having TOP(q_smallint,10) > 0','having TOP(q_tinyint,10) > 0','having TOP(q_float,10) > 0','having TOP(q_double,10) > 0','having TOP(q_bool,10) > 0', - 'having BOTTOM(q_int,10) > 0','having BOTTOM(q_bigint,10) > 0','having BOTTOM(q_smallint,10) > 0','having BOTTOM(q_tinyint,10) > 0','having BOTTOM(q_float,10) > 0','having BOTTOM(q_double,10) > 0','having BOTTOM(q_bool,10) > 0', - 'having LEASTSQUARES(q_int) > 0','having LEASTSQUARES(q_bigint) > 0','having LEASTSQUARES(q_smallint) > 0','having LEASTSQUARES(q_tinyint) > 0','having LEASTSQUARES(q_float) > 0','having LEASTSQUARES(q_double) > 0','having LEASTSQUARES(q_bool) > 0', - 'having FIRST(q_bool) > 0','having IRATE(q_bool) > 0','having PERCENTILE(q_bool,10) > 0','having avg(q_bool) > 0','having LAST_ROW(q_bool) > 0','having sum(q_bool) > 0','having STDDEV(q_bool) > 0','having APERCENTILE(q_bool,10) > 0','having TWA(q_bool) > 0','having LAST(q_bool) > 0', - 'having PERCENTILE(q_int,10) > 0','having PERCENTILE(q_bigint,10) > 0','having PERCENTILE(q_smallint,10) > 0','having PERCENTILE(q_tinyint,10) > 0','having PERCENTILE(q_float,10) > 0','having PERCENTILE(q_double,10) > 0'] - self.having_tagnot_support = ['having LAST_ROW(q_int) > 0','having LAST_ROW(q_bigint) > 0','having LAST_ROW(q_smallint) > 0','having LAST_ROW(q_tinyint) > 0','having LAST_ROW(q_float) > 0','having LAST_ROW(q_double) > 0'] - - self.having_support_j = ['having count(t1.q_int) > 0','having count(t1.q_bigint) > 0','having count(t1.q_smallint) > 0','having count(t1.q_tinyint) > 0','having count(t1.q_float) > 0','having count(t1.q_double) > 0','having count(t1.q_bool) > 0', - 'having avg(t1.q_int) > 0','having avg(t1.q_bigint) > 0','having avg(t1.q_smallint) > 0','having avg(t1.q_tinyint) > 0','having avg(t1.q_float) > 0','having avg(t1.q_double) > 0', - 'having sum(t1.q_int) > 0','having sum(t1.q_bigint) > 0','having sum(t1.q_smallint) > 0','having sum(t1.q_tinyint) > 0','having sum(t1.q_float) > 0','having sum(t1.q_double) > 0', - 'having STDDEV(t1.q_int) > 0','having STDDEV(t1.q_bigint) > 0','having STDDEV(t1.q_smallint) > 0','having STDDEV(t1.q_tinyint) > 0','having STDDEV(t1.q_float) > 0','having STDDEV(t1.q_double) > 0', - 'having TWA(t1.q_int) > 0','having TWA(t1.q_bigint) > 0','having TWA(t1.q_smallint) > 0','having TWA(t1.q_tinyint) > 0','having TWA(t1.q_float) > 0','having TWA(t1.q_double) > 0', - 'having IRATE(t1.q_int) > 0','having IRATE(t1.q_bigint) > 0','having IRATE(t1.q_smallint) > 0','having IRATE(t1.q_tinyint) > 0','having IRATE(t1.q_float) > 0','having IRATE(t1.q_double) > 0', - 'having MIN(t1.q_int) > 0','having MIN(t1.q_bigint) > 0','having MIN(t1.q_smallint) > 0','having MIN(t1.q_tinyint) > 0','having MIN(t1.q_float) > 0','having MIN(t1.q_double) > 0', - 'having MAX(t1.q_int) > 0','having MAX(t1.q_bigint) > 0','having MAX(t1.q_smallint) > 0','having MAX(t1.q_tinyint) > 0','having MAX(t1.q_float) > 0','having MAX(t1.q_double) > 0', - 'having FIRST(t1.q_int) > 0','having FIRST(t1.q_bigint) > 0','having FIRST(t1.q_smallint) > 0','having FIRST(t1.q_tinyint) > 0','having FIRST(t1.q_float) > 0','having FIRST(t1.q_double) > 0', - 'having LAST(t1.q_int) > 0','having LAST(t1.q_bigint) > 0','having LAST(t1.q_smallint) > 0','having LAST(t1.q_tinyint) > 0','having LAST(t1.q_float) > 0','having LAST(t1.q_double) > 0', - 'having APERCENTILE(t1.q_int,10) > 0','having APERCENTILE(t1.q_bigint,10) > 0','having APERCENTILE(t1.q_smallint,10) > 0','having APERCENTILE(t1.q_tinyint,10) > 0','having APERCENTILE(t1.q_float,10) > 0','having APERCENTILE(t1.q_double,10) > 0'] - - # limit offset where - self.limit_where = ['limit 1 offset 1' , 'limit 1' , 'limit 2 offset 1' , 'limit 2', 'limit 12 offset 1' , 'limit 20', 'limit 20 offset 10' , 'limit 200'] - self.limit1_where = ['limit 1 offset 1' , 'limit 1' ] - self.limit_u_where = ['limit 100 offset 10' , 'limit 50' , 'limit 100' , 'limit 10' ] - - # slimit soffset where - self.slimit_where = ['slimit 1 soffset 1' , 'slimit 1' , 'slimit 2 soffset 1' , 'slimit 2'] - self.slimit1_where = ['slimit 2 soffset 1' , 'slimit 1' ] - - # aggregate function include [all:count(*)\avg\sum\stddev ||regualr:twa\irate\leastsquares ||group by tbname:twa\irate\] - # select function include [all: min\max\first(*)\last(*)\top\bottom\apercentile\last_row(*)(not with interval)\interp(*)(FILL) ||regualr: percentile] - # calculation function include [all:spread\+-*/ ||regualr:diff\derivative ||group by tbname:diff\derivative\] - # **_ns_** express is not support stable, therefore, separated from regular tables - # calc_select_all calc_select_regular calc_select_in_ts calc_select_fill calc_select_not_interval - # calc_aggregate_all calc_aggregate_regular calc_aggregate_groupbytbname - # calc_calculate_all calc_calculate_regular calc_calculate_groupbytbname - - # calc_select_all calc_select_regular calc_select_in_ts calc_select_fill calc_select_not_interval - # select function include [all: min\max\first(*)\last(*)\top\bottom\apercentile\last_row(*)(not with interval)\interp(*)(FILL) ||regualr: percentile] - - self.calc_select_all = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , - 'top(q_int,20)' , 'top(q_bigint,20)' , 'top(q_smallint,20)' ,'top(q_tinyint,20)' ,'top(q_float,20)' ,'top(q_double,20)' , - 'first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , - 'last(q_int)' , 'last(q_bigint)' , 'last(q_smallint)' , 'last(q_tinyint)' , 'last(q_float)' ,'last(q_double)' , 'last(q_binary)' ,'last(q_nchar)' ,'last(q_bool)' ,'last(q_ts)' , - 'min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , - 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' , - 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)' , - 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , - 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)'] - - self.calc_select_in_ts = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , - 'top(q_int,20)' , 'top(q_bigint,20)' , 'top(q_smallint,20)' ,'top(q_tinyint,20)' ,'top(q_float,20)' ,'top(q_double,20)' , - 'first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , - 'last(q_int)' , 'last(q_bigint)' , 'last(q_smallint)' , 'last(q_tinyint)' , 'last(q_float)' ,'last(q_double)' , 'last(q_binary)' ,'last(q_nchar)' ,'last(q_bool)' ,'last(q_ts)' ] - - self.calc_select_in = ['min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , - 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' , - 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)' , - 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , - 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)'] - - self.calc_select_not_support_ts = ['first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , - 'last(q_int)' , 'last(q_bigint)' , 'last(q_smallint)' , 'last(q_tinyint)' , 'last(q_float)' ,'last(q_double)' , 'last(q_binary)' ,'last(q_nchar)' ,'last(q_bool)' ,'last(q_ts)' , - 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , - 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)', - 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)'] - - self.calc_select_support_ts = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , - 'top(q_int,20)' , 'top(q_bigint,20)' , 'top(q_smallint,20)' ,'top(q_tinyint,20)' ,'top(q_float,20)' ,'top(q_double,20)' , - 'min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , - 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' ] - - self.calc_select_regular = [ 'PERCENTILE(q_int,10)' ,'PERCENTILE(q_bigint,20)' , 'PERCENTILE(q_smallint,30)' ,'PERCENTILE(q_tinyint,40)' ,'PERCENTILE(q_float,50)' ,'PERCENTILE(q_double,60)'] - - - self.calc_select_fill = ['INTERP(q_int)' ,'INTERP(q_bigint)' ,'INTERP(q_smallint)' ,'INTERP(q_tinyint)', 'INTERP(q_float)' ,'INTERP(q_double)'] - self.interp_where = ['ts = now' , 'ts = \'2020-09-13 20:26:40.000\'' , 'ts = \'2020-09-13 20:26:40.009\'' ,'tbname in (\'table_1\') and ts = now' ,'tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and ts = \'2020-09-13 20:26:40.000\'','tbname like \'table%\' and ts = \'2020-09-13 20:26:40.002\''] - - #two table join - self.calc_select_in_ts_j = ['bottom(t1.q_int,20)' , 'bottom(t1.q_bigint,20)' , 'bottom(t1.q_smallint,20)' , 'bottom(t1.q_tinyint,20)' ,'bottom(t1.q_float,20)' , 'bottom(t1.q_double,20)' , - 'top(t1.q_int,20)' , 'top(t1.q_bigint,20)' , 'top(t1.q_smallint,20)' ,'top(t1.q_tinyint,20)' ,'top(t1.q_float,20)' ,'top(t1.q_double,20)' , - 'first(t1.q_int)' , 'first(t1.q_bigint)' , 'first(t1.q_smallint)' , 'first(t1.q_tinyint)' , 'first(t1.q_float)' ,'first(t1.q_double)' ,'first(t1.q_binary)' ,'first(t1.q_nchar)' ,'first(t1.q_bool)' ,'first(t1.q_ts)' , - 'last(t1.q_int)' , 'last(t1.q_bigint)' , 'last(t1.q_smallint)' , 'last(t1.q_tinyint)' , 'last(t1.q_float)' ,'last(t1.q_double)' , 'last(t1.q_binary)' ,'last(t1.q_nchar)' ,'last(t1.q_bool)' ,'last(t1.q_ts)' , - 'bottom(t2.q_int,20)' , 'bottom(t2.q_bigint,20)' , 'bottom(t2.q_smallint,20)' , 'bottom(t2.q_tinyint,20)' ,'bottom(t2.q_float,20)' , 'bottom(t2.q_double,20)' , - 'top(t2.q_int,20)' , 'top(t2.q_bigint,20)' , 'top(t2.q_smallint,20)' ,'top(t2.q_tinyint,20)' ,'top(t2.q_float,20)' ,'top(t2.q_double,20)' , - 'first(t2.q_int)' , 'first(t2.q_bigint)' , 'first(t2.q_smallint)' , 'first(t2.q_tinyint)' , 'first(t2.q_float)' ,'first(t2.q_double)' ,'first(t2.q_binary)' ,'first(t2.q_nchar)' ,'first(t2.q_bool)' ,'first(t2.q_ts)' , - 'last(t2.q_int)' , 'last(t2.q_bigint)' , 'last(t2.q_smallint)' , 'last(t2.q_tinyint)' , 'last(t2.q_float)' ,'last(t2.q_double)' , 'last(t2.q_binary)' ,'last(t2.q_nchar)' ,'last(t2.q_bool)' ,'last(t2.q_ts)'] - - self.calc_select_in_support_ts_j = ['bottom(t1.q_int,20)' , 'bottom(t1.q_bigint,20)' , 'bottom(t1.q_smallint,20)' , 'bottom(t1.q_tinyint,20)' ,'bottom(t1.q_float,20)' , 'bottom(t1.q_double,20)' , - 'top(t1.q_int,20)' , 'top(t1.q_bigint,20)' , 'top(t1.q_smallint,20)' ,'top(t1.q_tinyint,20)' ,'top(t1.q_float,20)' ,'top(t1.q_double,20)' , - 'min(t1.q_int)' , 'min(t1.q_bigint)' , 'min(t1.q_smallint)' , 'min(t1.q_tinyint)' , 'min(t1.q_float)' ,'min(t1.q_double)' , - 'max(t1.q_int)' , 'max(t1.q_bigint)' , 'max(t1.q_smallint)' , 'max(t1.q_tinyint)' ,'max(t1.q_float)' ,'max(t1.q_double)' , - 'bottom(t2.q_int,20)' , 'bottom(t2.q_bigint,20)' , 'bottom(t2.q_smallint,20)' , 'bottom(t2.q_tinyint,20)' ,'bottom(t2.q_float,20)' , 'bottom(t2.q_double,20)' , - 'top(t2.q_int,20)' , 'top(t2.q_bigint,20)' , 'top(t2.q_smallint,20)' ,'top(t2.q_tinyint,20)' ,'top(t2.q_float,20)' ,'top(t2.q_double,20)' , - 'min(t2.q_int)' , 'min(t2.q_bigint)' , 'min(t2.q_smallint)' , 'min(t2.q_tinyint)' , 'min(t2.q_float)' ,'min(t2.q_double)' , - 'max(t2.q_int)' , 'max(t2.q_bigint)' , 'max(t2.q_smallint)' , 'max(t2.q_tinyint)' ,'max(t2.q_float)' ,'max(t2.q_double)' , - ] - - self.calc_select_in_not_support_ts_j = ['apercentile(t1.q_int,20)' , 'apercentile(t1.q_bigint,20)' ,'apercentile(t1.q_smallint,20)' ,'apercentile(t1.q_tinyint,20)' ,'apercentile(t1.q_float,20)' ,'apercentile(t1.q_double,20)' , - 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , - 'last_row(t1.q_double)' , 'last_row(t1.q_bool)' ,'last_row(t1.q_binary)' ,'last_row(t1.q_nchar)' ,'last_row(t1.q_ts)' , - 'apercentile(t2.q_int,20)' , 'apercentile(t2.q_bigint,20)' ,'apercentile(t2.q_smallint,20)' ,'apercentile(t2.q_tinyint,20)' ,'apercentile(t2.q_float,20)' ,'apercentile(t2.q_double,20)' , - 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , - 'last_row(t2.q_double)' , 'last_row(t2.q_bool)' ,'last_row(t2.q_binary)' ,'last_row(t2.q_nchar)' ,'last_row(t2.q_ts)'] - - self.calc_select_in_j = ['min(t1.q_int)' , 'min(t1.q_bigint)' , 'min(t1.q_smallint)' , 'min(t1.q_tinyint)' , 'min(t1.q_float)' ,'min(t1.q_double)' , - 'max(t1.q_int)' , 'max(t1.q_bigint)' , 'max(t1.q_smallint)' , 'max(t1.q_tinyint)' ,'max(t1.q_float)' ,'max(t1.q_double)' , - 'apercentile(t1.q_int,20)' , 'apercentile(t1.q_bigint,20)' ,'apercentile(t1.q_smallint,20)' ,'apercentile(t1.q_tinyint,20)' ,'apercentile(t1.q_float,20)' ,'apercentile(t1.q_double,20)' , - 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , - 'last_row(t1.q_double)' , 'last_row(t1.q_bool)' ,'last_row(t1.q_binary)' ,'last_row(t1.q_nchar)' ,'last_row(t1.q_ts)' , - 'min(t2.q_int)' , 'min(t2.q_bigint)' , 'min(t2.q_smallint)' , 'min(t2.q_tinyint)' , 'min(t2.q_float)' ,'min(t2.q_double)' , - 'max(t2.q_int)' , 'max(t2.q_bigint)' , 'max(t2.q_smallint)' , 'max(t2.q_tinyint)' ,'max(t2.q_float)' ,'max(t2.q_double)' , - 'apercentile(t2.q_int,20)' , 'apercentile(t2.q_bigint,20)' ,'apercentile(t2.q_smallint,20)' ,'apercentile(t2.q_tinyint,20)' ,'apercentile(t2.q_float,20)' ,'apercentile(t2.q_double,20)' , - 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , - 'last_row(t2.q_double)' , 'last_row(t2.q_bool)' ,'last_row(t2.q_binary)' ,'last_row(t2.q_nchar)' ,'last_row(t2.q_ts)'] - self.calc_select_all_j = self.calc_select_in_ts_j + self.calc_select_in_j - - self.calc_select_regular_j = [ 'PERCENTILE(t1.q_int,10)' ,'PERCENTILE(t1.q_bigint,20)' , 'PERCENTILE(t1.q_smallint,30)' ,'PERCENTILE(t1.q_tinyint,40)' ,'PERCENTILE(t1.q_float,50)' ,'PERCENTILE(t1.q_double,60)' , - 'PERCENTILE(t2.q_int,10)' ,'PERCENTILE(t2.q_bigint,20)' , 'PERCENTILE(t2.q_smallint,30)' ,'PERCENTILE(t2.q_tinyint,40)' ,'PERCENTILE(t2.q_float,50)' ,'PERCENTILE(t2.q_double,60)'] - - - self.calc_select_fill_j = ['INTERP(t1.q_int)' ,'INTERP(t1.q_bigint)' ,'INTERP(t1.q_smallint)' ,'INTERP(t1.q_tinyint)', 'INTERP(t1.q_float)' ,'INTERP(t1.q_double)' , - 'INTERP(t2.q_int)' ,'INTERP(t2.q_bigint)' ,'INTERP(t2.q_smallint)' ,'INTERP(t2.q_tinyint)', 'INTERP(t2.q_float)' ,'INTERP(t2.q_double)'] - self.interp_where_j = ['t1.ts = now' , 't1.ts = \'2020-09-13 20:26:40.000\'' , 't1.ts = \'2020-09-13 20:26:40.009\'' ,'t2.ts = now' , 't2.ts = \'2020-09-13 20:26:40.000\'' , 't2.ts = \'2020-09-13 20:26:40.009\'' , - 't1.tbname in (\'table_1\') and t1.ts = now' ,'t1.tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and t1.ts = \'2020-09-13 20:26:40.000\'','t1.tbname like \'table%\' and t1.ts = \'2020-09-13 20:26:40.002\'', - 't2.tbname in (\'table_1\') and t2.ts = now' ,'t2.tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and t2.ts = \'2020-09-13 20:26:40.000\'','t2.tbname like \'table%\' and t2.ts = \'2020-09-13 20:26:40.002\''] - - # calc_aggregate_all calc_aggregate_regular calc_aggregate_groupbytbname APERCENTILE\PERCENTILE - # aggregate function include [all:count(*)\avg\sum\stddev ||regualr:twa\irate\leastsquares ||group by tbname:twa\irate\] - self.calc_aggregate_all = ['count(*)' , 'count(q_int)' ,'count(q_bigint)' , 'count(q_smallint)' ,'count(q_tinyint)' ,'count(q_float)' , - 'count(q_double)' ,'count(q_binary)' ,'count(q_nchar)' ,'count(q_bool)' ,'count(q_ts)' , - 'avg(q_int)' ,'avg(q_bigint)' , 'avg(q_smallint)' ,'avg(q_tinyint)' ,'avg(q_float)' ,'avg(q_double)' , - 'sum(q_int)' ,'sum(q_bigint)' , 'sum(q_smallint)' ,'sum(q_tinyint)' ,'sum(q_float)' ,'sum(q_double)' , - 'STDDEV(q_int)' ,'STDDEV(q_bigint)' , 'STDDEV(q_smallint)' ,'STDDEV(q_tinyint)' ,'STDDEV(q_float)' ,'STDDEV(q_double)', - 'APERCENTILE(q_int,10)' ,'APERCENTILE(q_bigint,20)' , 'APERCENTILE(q_smallint,30)' ,'APERCENTILE(q_tinyint,40)' ,'APERCENTILE(q_float,50)' ,'APERCENTILE(q_double,60)'] - - self.calc_aggregate_regular = ['twa(q_int)' ,'twa(q_bigint)' , 'twa(q_smallint)' ,'twa(q_tinyint)' ,'twa (q_float)' ,'twa(q_double)' , - 'IRATE(q_int)' ,'IRATE(q_bigint)' , 'IRATE(q_smallint)' ,'IRATE(q_tinyint)' ,'IRATE (q_float)' ,'IRATE(q_double)' , - 'LEASTSQUARES(q_int,15,3)' , 'LEASTSQUARES(q_bigint,10,1)' , 'LEASTSQUARES(q_smallint,20,3)' ,'LEASTSQUARES(q_tinyint,10,4)' ,'LEASTSQUARES(q_float,6,4)' ,'LEASTSQUARES(q_double,3,1)' , - 'PERCENTILE(q_int,10)' ,'PERCENTILE(q_bigint,20)' , 'PERCENTILE(q_smallint,30)' ,'PERCENTILE(q_tinyint,40)' ,'PERCENTILE(q_float,50)' ,'PERCENTILE(q_double,60)'] - - self.calc_aggregate_groupbytbname = ['twa(q_int)' ,'twa(q_bigint)' , 'twa(q_smallint)' ,'twa(q_tinyint)' ,'twa (q_float)' ,'twa(q_double)' , - 'IRATE(q_int)' ,'IRATE(q_bigint)' , 'IRATE(q_smallint)' ,'IRATE(q_tinyint)' ,'IRATE (q_float)' ,'IRATE(q_double)' ] - - #two table join - self.calc_aggregate_all_j = ['count(t1.*)' , 'count(t1.q_int)' ,'count(t1.q_bigint)' , 'count(t1.q_smallint)' ,'count(t1.q_tinyint)' ,'count(t1.q_float)' , - 'count(t1.q_double)' ,'count(t1.q_binary)' ,'count(t1.q_nchar)' ,'count(t1.q_bool)' ,'count(t1.q_ts)' , - 'avg(t1.q_int)' ,'avg(t1.q_bigint)' , 'avg(t1.q_smallint)' ,'avg(t1.q_tinyint)' ,'avg(t1.q_float)' ,'avg(t1.q_double)' , - 'sum(t1.q_int)' ,'sum(t1.q_bigint)' , 'sum(t1.q_smallint)' ,'sum(t1.q_tinyint)' ,'sum(t1.q_float)' ,'sum(t1.q_double)' , - 'STDDEV(t1.q_int)' ,'STDDEV(t1.q_bigint)' , 'STDDEV(t1.q_smallint)' ,'STDDEV(t1.q_tinyint)' ,'STDDEV(t1.q_float)' ,'STDDEV(t1.q_double)', - 'APERCENTILE(t1.q_int,10)' ,'APERCENTILE(t1.q_bigint,20)' , 'APERCENTILE(t1.q_smallint,30)' ,'APERCENTILE(t1.q_tinyint,40)' ,'APERCENTILE(t1.q_float,50)' ,'APERCENTILE(t1.q_double,60)' , - 'count(t2.*)' , 'count(t2.q_int)' ,'count(t2.q_bigint)' , 'count(t2.q_smallint)' ,'count(t2.q_tinyint)' ,'count(t2.q_float)' , - 'count(t2.q_double)' ,'count(t2.q_binary)' ,'count(t2.q_nchar)' ,'count(t2.q_bool)' ,'count(t2.q_ts)' , - 'avg(t2.q_int)' ,'avg(t2.q_bigint)' , 'avg(t2.q_smallint)' ,'avg(t2.q_tinyint)' ,'avg(t2.q_float)' ,'avg(t2.q_double)' , - 'sum(t2.q_int)' ,'sum(t2.q_bigint)' , 'sum(t2.q_smallint)' ,'sum(t2.q_tinyint)' ,'sum(t2.q_float)' ,'sum(t2.q_double)' , - 'STDDEV(t2.q_int)' ,'STDDEV(t2.q_bigint)' , 'STDDEV(t2.q_smallint)' ,'STDDEV(t2.q_tinyint)' ,'STDDEV(t2.q_float)' ,'STDDEV(t2.q_double)', - 'APERCENTILE(t2.q_int,10)' ,'APERCENTILE(t2.q_bigint,20)' , 'APERCENTILE(t2.q_smallint,30)' ,'APERCENTILE(t2.q_tinyint,40)' ,'APERCENTILE(t2.q_float,50)' ,'APERCENTILE(t2.q_double,60)'] - - self.calc_aggregate_regular_j = ['twa(t1.q_int)' ,'twa(t1.q_bigint)' , 'twa(t1.q_smallint)' ,'twa(t1.q_tinyint)' ,'twa (t1.q_float)' ,'twa(t1.q_double)' , - 'IRATE(t1.q_int)' ,'IRATE(t1.q_bigint)' , 'IRATE(t1.q_smallint)' ,'IRATE(t1.q_tinyint)' ,'IRATE (t1.q_float)' ,'IRATE(t1.q_double)' , - 'LEASTSQUARES(t1.q_int,15,3)' , 'LEASTSQUARES(t1.q_bigint,10,1)' , 'LEASTSQUARES(t1.q_smallint,20,3)' ,'LEASTSQUARES(t1.q_tinyint,10,4)' ,'LEASTSQUARES(t1.q_float,6,4)' ,'LEASTSQUARES(t1.q_double,3,1)' , - 'PERCENTILE(t1.q_int,10)' ,'PERCENTILE(t1.q_bigint,20)' , 'PERCENTILE(t1.q_smallint,30)' ,'PERCENTILE(t1.q_tinyint,40)' ,'PERCENTILE(t1.q_float,50)' ,'PERCENTILE(t1.q_double,60)' , - 'twa(t2.q_int)' ,'twa(t2.q_bigint)' , 'twa(t2.q_smallint)' ,'twa(t2.q_tinyint)' ,'twa (t2.q_float)' ,'twa(t2.q_double)' , - 'IRATE(t2.q_int)' ,'IRATE(t2.q_bigint)' , 'IRATE(t2.q_smallint)' ,'IRATE(t2.q_tinyint)' ,'IRATE (t2.q_float)' ,'IRATE(t2.q_double)', - 'LEASTSQUARES(t2.q_int,15,3)' , 'LEASTSQUARES(t2.q_bigint,10,1)' , 'LEASTSQUARES(t2.q_smallint,20,3)' ,'LEASTSQUARES(t2.q_tinyint,10,4)' ,'LEASTSQUARES(t2.q_float,6,4)' ,'LEASTSQUARES(t2.q_double,3,1)' , - 'PERCENTILE(t2.q_int,10)' ,'PERCENTILE(t2.q_bigint,20)' , 'PERCENTILE(t2.q_smallint,30)' ,'PERCENTILE(t2.q_tinyint,40)' ,'PERCENTILE(t2.q_float,50)' ,'PERCENTILE(t2.q_double,60)'] - - self.calc_aggregate_groupbytbname_j = ['twa(t1.q_int)' ,'twa(t1.q_bigint)' , 'twa(t1.q_smallint)' ,'twa(t1.q_tinyint)' ,'twa (t1.q_float)' ,'twa(t1.q_double)' , - 'IRATE(t1.q_int)' ,'IRATE(t1.q_bigint)' , 'IRATE(t1.q_smallint)' ,'IRATE(t1.q_tinyint)' ,'IRATE (t1.q_float)' ,'IRATE(t1.q_double)' , - 'twa(t2.q_int)' ,'twa(t2.q_bigint)' , 'twa(t2.q_smallint)' ,'twa(t2.q_tinyint)' ,'twa (t2.q_float)' ,'twa(t2.q_double)' , - 'IRATE(t2.q_int)' ,'IRATE(t2.q_bigint)' , 'IRATE(t2.q_smallint)' ,'IRATE(t2.q_tinyint)' ,'IRATE (t2.q_float)' ,'IRATE(t2.q_double)' ] - - # calc_calculate_all calc_calculate_regular calc_calculate_groupbytbname - # calculation function include [all:spread\+-*/ ||regualr:diff\derivative ||group by tbname:diff\derivative\] - self.calc_calculate_all = ['SPREAD(ts)' , 'SPREAD(q_ts)' , 'SPREAD(q_int)' ,'SPREAD(q_bigint)' , 'SPREAD(q_smallint)' ,'SPREAD(q_tinyint)' ,'SPREAD(q_float)' ,'SPREAD(q_double)' , - '(SPREAD(q_int) + SPREAD(q_bigint))' , '(SPREAD(q_smallint) - SPREAD(q_float))', '(SPREAD(q_double) * SPREAD(q_tinyint))' , '(SPREAD(q_double) / SPREAD(q_float))'] - self.calc_calculate_regular = ['DIFF(q_int)' ,'DIFF(q_bigint)' , 'DIFF(q_smallint)' ,'DIFF(q_tinyint)' ,'DIFF(q_float)' ,'DIFF(q_double)' , - 'DIFF(q_int,0)' ,'DIFF(q_bigint,0)' , 'DIFF(q_smallint,0)' ,'DIFF(q_tinyint,0)' ,'DIFF(q_float,0)' ,'DIFF(q_double,0)' , - 'DIFF(q_int,1)' ,'DIFF(q_bigint,1)' , 'DIFF(q_smallint,1)' ,'DIFF(q_tinyint,1)' ,'DIFF(q_float,1)' ,'DIFF(q_double,1)' , - 'DERIVATIVE(q_int,15s,0)' , 'DERIVATIVE(q_bigint,10s,1)' , 'DERIVATIVE(q_smallint,20s,0)' ,'DERIVATIVE(q_tinyint,10s,1)' ,'DERIVATIVE(q_float,6s,0)' ,'DERIVATIVE(q_double,3s,1)' ] - self.calc_calculate_groupbytbname = self.calc_calculate_regular - - #two table join - self.calc_calculate_all_j = ['SPREAD(t1.ts)' , 'SPREAD(t1.q_ts)' , 'SPREAD(t1.q_int)' ,'SPREAD(t1.q_bigint)' , 'SPREAD(t1.q_smallint)' ,'SPREAD(t1.q_tinyint)' ,'SPREAD(t1.q_float)' ,'SPREAD(t1.q_double)' , - 'SPREAD(t2.ts)' , 'SPREAD(t2.q_ts)' , 'SPREAD(t2.q_int)' ,'SPREAD(t2.q_bigint)' , 'SPREAD(t2.q_smallint)' ,'SPREAD(t2.q_tinyint)' ,'SPREAD(t2.q_float)' ,'SPREAD(t2.q_double)' , - '(SPREAD(t1.q_int) + SPREAD(t1.q_bigint))' , '(SPREAD(t1.q_tinyint) - SPREAD(t1.q_float))', '(SPREAD(t1.q_double) * SPREAD(t1.q_tinyint))' , '(SPREAD(t1.q_double) / SPREAD(t1.q_tinyint))', - '(SPREAD(t2.q_int) + SPREAD(t2.q_bigint))' , '(SPREAD(t2.q_smallint) - SPREAD(t2.q_float))', '(SPREAD(t2.q_double) * SPREAD(t2.q_tinyint))' , '(SPREAD(t2.q_double) / SPREAD(t2.q_tinyint))', - '(SPREAD(t1.q_int) + SPREAD(t1.q_smallint))' , '(SPREAD(t2.q_smallint) - SPREAD(t2.q_float))', '(SPREAD(t1.q_double) * SPREAD(t1.q_tinyint))' , '(SPREAD(t1.q_double) / SPREAD(t1.q_float))'] - self.calc_calculate_regular_j = ['DIFF(t1.q_int)' ,'DIFF(t1.q_bigint)' , 'DIFF(t1.q_smallint)' ,'DIFF(t1.q_tinyint)' ,'DIFF(t1.q_float)' ,'DIFF(t1.q_double)' , - 'DIFF(t1.q_int,0)' ,'DIFF(t1.q_bigint,0)' , 'DIFF(t1.q_smallint,0)' ,'DIFF(t1.q_tinyint,0)' ,'DIFF(t1.q_float,0)' ,'DIFF(t1.q_double,0)' , - 'DIFF(t1.q_int,1)' ,'DIFF(t1.q_bigint,1)' , 'DIFF(t1.q_smallint,1)' ,'DIFF(t1.q_tinyint,1)' ,'DIFF(t1.q_float,1)' ,'DIFF(t1.q_double,1)' , - 'DERIVATIVE(t1.q_int,15s,0)' , 'DERIVATIVE(t1.q_bigint,10s,1)' , 'DERIVATIVE(t1.q_smallint,20s,0)' ,'DERIVATIVE(t1.q_tinyint,10s,1)' ,'DERIVATIVE(t1.q_float,6s,0)' ,'DERIVATIVE(t1.q_double,3s,1)' , - 'DIFF(t2.q_int)' ,'DIFF(t2.q_bigint)' , 'DIFF(t2.q_smallint)' ,'DIFF(t2.q_tinyint)' ,'DIFF(t2.q_float)' ,'DIFF(t2.q_double)' , - 'DIFF(t2.q_int,0)' ,'DIFF(t2.q_bigint,0)' , 'DIFF(t2.q_smallint,0)' ,'DIFF(t2.q_tinyint,0)' ,'DIFF(t2.q_float,0)' ,'DIFF(t2.q_double,0)' , - 'DIFF(t2.q_int,1)' ,'DIFF(t2.q_bigint,1)' , 'DIFF(t2.q_smallint,1)' ,'DIFF(t2.q_tinyint,1)' ,'DIFF(t2.q_float,1)' ,'DIFF(t2.q_double,1)' , - 'DERIVATIVE(t2.q_int,15s,0)' , 'DERIVATIVE(t2.q_bigint,10s,1)' , 'DERIVATIVE(t2.q_smallint,20s,0)' ,'DERIVATIVE(t2.q_tinyint,10s,1)' ,'DERIVATIVE(t2.q_float,6s,0)' ,'DERIVATIVE(t2.q_double,3s,1)' ] - self.calc_calculate_groupbytbname_j = self.calc_calculate_regular_j - - #inter && calc_aggregate_all\calc_aggregate_regular\calc_select_all - self.interval_sliding = ['interval(4w) sliding(1w) ','interval(1w) sliding(1d) ','interval(1d) sliding(1h) ' , - 'interval(1h) sliding(1m) ','interval(1m) sliding(1s) ','interval(1s) sliding(10a) ', - 'interval(1y) ','interval(1n) ','interval(1w) ','interval(1d) ','interval(1h) ','interval(1m) ','interval(1s) ' ,'interval(10a)', - 'interval(1y,1n) ','interval(1n,1w) ','interval(1w,1d) ','interval(1d,1h) ','interval(1h,1m) ','interval(1m,1s) ','interval(1s,10a) ' ,'interval(100a,30a)'] - - self.conn1 = taos.connect(host="127.0.0.1", user="root", password="taosdata", config="/etc/taos/") - self.cur1 = self.conn1.cursor() - print(self.cur1) - self.cur1.execute("use %s ;" %self.db_nest) - sql = 'select * from stable_1 limit 5;' - self.cur1.execute(sql) - - - def data_matrix_equal(self, sql1,row1_s,row1_e,col1_s,col1_e, sql2,row2_s,row2_e,col2_s,col2_e): - # ----row1_start----col1_start---- - # - - - - 是一个矩阵内的数据相等- - - - # - - - - - - - - - - - - - - - - - # ----row1_end------col1_end------ - self.sql1 = sql1 - list1 =[] - tdSql.query(sql1) - for i1 in range(row1_s-1,row1_e): - #print("iiii=%d"%i1) - for j1 in range(col1_s-1,col1_e): - #print("jjjj=%d"%j1) - #print("data=%s" %(tdSql.getData(i1,j1))) - list1.append(tdSql.getData(i1,j1)) - print("=====list1-------list1---=%s" %set(list1)) - - tdSql.execute("reset query cache;") - self.sql2 = sql2 - list2 =[] - tdSql.query(sql2) - for i2 in range(row2_s-1,row2_e): - #print("iiii222=%d"%i2) - for j2 in range(col2_s-1,col2_e): - #print("jjjj222=%d"%j2) - #print("data=%s" %(tdSql.getData(i2,j2))) - list2.append(tdSql.getData(i2,j2)) - print("=====list2-------list2---=%s" %set(list2)) - - if (list1 == list2) and len(list2)>0: - # print(("=====matrix===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - tdLog.info(("===matrix===sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) - elif (set(list2)).issubset(set(list1)): - # 解决不同子表排列结果乱序 - # print(("=====list_issubset==matrix2in1-true===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - tdLog.info(("===matrix_issubset===sql1:'%s' matrix_set_result = sql2:'%s' matrix_set_result") %(sql1,sql2)) - #elif abs(float(str(list1).replace("]","").replace("[","").replace("e+","")) - float(str(list2).replace("]","").replace("[","").replace("e+",""))) <= 0.0001: - elif abs(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-","")) - float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-",""))) <= 0.0001: - print(("=====matrix_abs+e+===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - print(("=====matrix_abs+e+replace_after===sql1.list1:'%s',sql2.list2:'%s'") %(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-","")),float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace("e+","").replace(", ","").replace("(","").replace(")","").replace("-","")))) - tdLog.info(("===matrix_abs+e+===sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) - elif abs(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")) - float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-",""))) <= 0.1: - #{datetime.datetime(2021, 8, 27, 1, 46, 40), -441.46841430664057}replace - print(("=====matrix_abs+replace===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - print(("=====matrix_abs+replace_after===sql1.list1:'%s',sql2.list2:'%s'") %(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")),float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")))) - tdLog.info(("===matrix_abs+replace===sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) - elif abs(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")) - float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-",""))) <= 0.5: - print(("=====matrix_abs===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - print(("=====matrix_abs===sql1.list1:'%s',sql2.list2:'%s'") %(float(str(list1).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")),float(str(list2).replace("datetime.datetime","").replace("]","").replace("[","").replace(", ","").replace("(","").replace(")","").replace("-","")))) - tdLog.info(("===matrix_abs======sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) - else: - print(("=====matrix_error===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) - tdLog.info(("sql1:'%s' matrix_result != sql2:'%s' matrix_result") %(sql1,sql2)) - return tdSql.checkEqual(list1,list2) - - def restartDnodes(self): - pass - # tdDnodes.stop(1) - # tdDnodes.start(1) - - def dropandcreateDB_random(self,database,n): - ts = 1630000000000 - num_random = 100 - fake = Faker('zh_CN') - tdSql.execute('''drop database if exists %s ;''' %database) - tdSql.execute('''create database %s keep 36500;'''%database) - tdSql.execute('''use %s;'''%database) - - tdSql.execute('''create stable stable_1 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ - q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ - tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') - tdSql.execute('''create stable stable_2 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ - q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ - tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') - - tdSql.execute('''create stable stable_null_data (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ - q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ - tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') - - tdSql.execute('''create stable stable_null_childtable (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ - q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ - tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') - - #tdSql.execute('''create table stable_1_1 using stable_1 tags('stable_1_1', '0' , '0' , '0' , '0' , 0 , 'binary1' , 'nchar1' , '0' , '0' ,'0') ;''') - tdSql.execute('''create table stable_1_1 using stable_1 tags('stable_1_1', '%d' , '%d', '%d' , '%d' , 0 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' - %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) - tdSql.execute('''create table stable_1_2 using stable_1 tags('stable_1_2', '2147483647' , '9223372036854775807' , '32767' , '127' , 1 , 'binary2' , 'nchar2' , '2' , '22' , \'1999-09-09 09:09:09.090\') ;''') - tdSql.execute('''create table stable_1_3 using stable_1 tags('stable_1_3', '-2147483647' , '-9223372036854775807' , '-32767' , '-127' , false , 'binary3' , 'nchar3nchar3' , '-3.3' , '-33.33' , \'2099-09-09 09:09:09.090\') ;''') - #tdSql.execute('''create table stable_1_4 using stable_1 tags('stable_1_4', '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') - tdSql.execute('''create table stable_1_4 using stable_1 tags('stable_1_4', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' - %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) - - # tdSql.execute('''create table stable_2_1 using stable_2 tags('stable_2_1' , '0' , '0' , '0' , '0' , 0 , 'binary21' , 'nchar21' , '0' , '0' ,'0') ;''') - # tdSql.execute('''create table stable_2_2 using stable_2 tags('stable_2_2' , '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') - - # tdSql.execute('''create table stable_null_data_1 using stable_null_data tags('stable_null_data_1', '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') - - tdSql.execute('''create table stable_2_1 using stable_2 tags('stable_2_1' , '0' , '0' , '0' , '0' , 0 , 'binary21' , 'nchar21' , '0' , '0' ,\'2099-09-09 09:09:09.090\') ;''') - tdSql.execute('''create table stable_2_2 using stable_2 tags('stable_2_2' , '%d' , '%d', '%d' , '%d' , 0 , 'binary2.%s' , 'nchar2.%s' , '%f', '%f' ,'%d') ;''' - %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) - - tdSql.execute('''create table stable_null_data_1 using stable_null_data tags('stable_null_data_1', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' - %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) - - #regular table - tdSql.execute('''create table regular_table_1 \ - (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ - q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') - tdSql.execute('''create table regular_table_2 \ - (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ - q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') - tdSql.execute('''create table regular_table_3 \ - (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ - q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') - - tdSql.execute('''create table regular_table_null \ - (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ - q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ - q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ - q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') - - - for i in range(num_random*n): - tdSql.execute('''insert into stable_1_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double , q_bool , q_binary , q_nchar, q_ts,\ - q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ - values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ - 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' - % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1), - fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , - fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address())) - tdSql.execute('''insert into regular_table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ - q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ - values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ - 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' - % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1) , - fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1) , - fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i, fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , - fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address())) - - tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ - q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8)\ - values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ - 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' - % (ts + i*1000, fake.random_int(min=0, max=2147483647, step=1), - fake.random_int(min=0, max=9223372036854775807, step=1), - fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i, fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , - fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address())) - tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ - q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ - values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ - 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' - % (ts + i*1000, fake.random_int(min=0, max=2147483647, step=1), - fake.random_int(min=0, max=9223372036854775807, step=1), - fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i, fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , - fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address())) - - tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ - q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ - values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ - 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' - % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), - fake.random_int(min=-9223372036854775807, max=0, step=1), - fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i +1, fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , - fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address())) - tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ - q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ - values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ - 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' - % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), - fake.random_int(min=-9223372036854775807, max=0, step=1), - fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i +1, fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , - fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address())) - - tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ - q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ - values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ - 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' - % (ts + i*1000, fake.random_int(min=-0, max=2147483647, step=1), - fake.random_int(min=-0, max=9223372036854775807, step=1), - fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i, fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , - fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address())) - - tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ - q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ - values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ - 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' - % (ts + i*1000 +1, fake.random_int(min=-0, max=2147483647, step=1), - fake.random_int(min=-0, max=9223372036854775807, step=1), - fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i, fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , - fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address())) - - tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ - q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ - values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ - 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' - % (ts + i*1000 +10, fake.random_int(min=-0, max=2147483647, step=1), - fake.random_int(min=-0, max=9223372036854775807, step=1), - fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , - fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i, fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , - fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address() , fake.pystr() , fake.address())) - - tdSql.query("select count(*) from stable_1;") - tdSql.checkData(0,0,3*num_random*n) - tdSql.query("select count(*) from regular_table_1;") - tdSql.checkData(0,0,num_random*n) - - def math_nest(self,mathlist): - - print("==========%s===start=============" %mathlist) - os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) - - self.dropandcreateDB_random("%s" %self.db_nest, 1) - - if (mathlist == ['ABS','SQRT']) or (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['FLOOR','CEIL','ROUND']) \ - or (mathlist == ['CSUM']) or (mathlist == ['']): - math_functions = mathlist - fun_fix_column = ['(q_bigint)','(q_smallint)','(q_tinyint)','(q_int)','(q_float)','(q_double)','(q_bigint_null)','(q_smallint_null)','(q_tinyint_null)','(q_int_null)','(q_float_null)','(q_double_null)'] - fun_column_1 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) - math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_2 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) - math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - fun_fix_column_j = ['(t1.q_bigint)','(t1.q_smallint)','(t1.q_tinyint)','(t1.q_int)','(t1.q_float)','(t1.q_double)','(t1.q_bigint_null)','(t1.q_smallint_null)','(t1.q_tinyint_null)','(t1.q_int_null)','(t1.q_float_null)','(t1.q_double_null)', - '(t2.q_bigint)','(t2.q_smallint)','(t2.q_tinyint)','(t2.q_int)','(t2.q_float)','(t2.q_double)','(t2.q_bigint_null)','(t2.q_smallint_null)','(t2.q_tinyint_null)','(t2.q_int_null)','(t2.q_float_null)','(t2.q_double_null)'] - fun_column_join_1 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) - math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_join_2 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) - math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - elif (mathlist == ['UNIQUE']) or (mathlist == ['HYPERLOGLOG']): - math_functions = mathlist - fun_fix_column = ['(q_bigint)','(q_smallint)','(q_tinyint)','(q_int)','(q_float)','(q_double)','(q_binary)','(q_nchar)','(q_bool)','(q_ts)', - '(q_bigint_null)','(q_smallint_null)','(q_tinyint_null)','(q_int_null)','(q_float_null)','(q_double_null)','(q_binary_null)','(q_nchar_null)','(q_bool_null)','(q_ts_null)'] - fun_column_1 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) - math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_2 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) - math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - fun_fix_column_j = ['(t1.q_bigint)','(t1.q_smallint)','(t1.q_tinyint)','(t1.q_int)','(t1.q_float)','(t1.q_double)','(t1.q_bigint_null)','(t1.q_smallint_null)','(t1.q_tinyint_null)','(t1.q_int_null)','(t1.q_float_null)','(t1.q_double_null)', - '(t2.q_bigint)','(t2.q_smallint)','(t2.q_tinyint)','(t2.q_int)','(t2.q_float)','(t2.q_double)','(t2.q_bigint_null)','(t2.q_smallint_null)','(t2.q_tinyint_null)','(t2.q_int_null)','(t2.q_float_null)','(t2.q_double_null)'] - fun_column_join_1 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) - math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_join_2 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) - math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - elif (mathlist == ['POW','LOG']) or (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) or (mathlist == ['TAIL']): - math_functions = mathlist - num = random.randint(0, 1000) - fun_fix_column = ['(q_bigint,num)','(q_smallint,num)','(q_tinyint,num)','(q_int,num)','(q_float,num)','(q_double,num)', - '(q_bigint_null,num)','(q_smallint_null,num)','(q_tinyint_null,num)','(q_int_null,num)','(q_float_null,num)','(q_double_null,num)'] - fun_column_1 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) - math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) - fun_column_2 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) - math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) - - fun_fix_column_j = ['(t1.q_bigint,num)','(t1.q_smallint,num)','(t1.q_tinyint,num)','(t1.q_int,num)','(t1.q_float,num)','(t1.q_double,num)', - '(t1.q_bigint_null,num)','(t1.q_smallint_null,num)','(t1.q_tinyint_null,num)','(t1.q_int_null,num)','(t1.q_float_null,num)','(t1.q_double_null,num)', - '(t2.q_bigint,num)','(t2.q_smallint,num)','(t2.q_tinyint,num)','(t2.q_int,num)','(t2.q_float,num)','(t2.q_double,num)', - '(t2.q_bigint_null,num)','(t2.q_smallint_null,num)','(t2.q_tinyint_null,num)','(t2.q_int_null,num)','(t2.q_float_null,num)','(t2.q_double_null,num)'] - fun_column_join_1 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) - math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) - fun_column_join_2 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) - math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) - - tdSql.query("select 1-1 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts , floor(asct1) from ( select " - sql += "%s as asct1, " % math_fun_1 - sql += "%s as asct2, " % math_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) \ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select floor(asct1) from ( select " - sql += "%s as asct1 " % math_fun_1 - # sql += "%s as asct2, " % math_fun_2 - # sql += "%s, " % random.choice(self.s_s_select) - # sql += "%s, " % random.choice(self.q_select) - sql += " from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - #sql += "%s " % random.choice(self.order_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - #tdSql.checkRows(100) - self.cur1.execute(sql) - - tdSql.query("select 1-2 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts , abs(asct1) from ( select " - sql += "%s as asct1, " % math_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s )" % random.choice(self.order_where) - sql += "%s " % random.choice(self.unionall_or_union) - sql += "select ts , asct2 from ( select " - sql += "%s as asct2, " % math_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - #sql += "%s " % random.choice(having_support) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) \ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select abs(asct1) from ( select " - sql += "%s as asct1 " % math_fun_1 - # sql += "%s, " % random.choice(self.s_s_select) - # sql += "%s, " % random.choice(self.q_select) - sql += "from regular_table_1 where " - sql += "%s )" % random.choice(self.q_where) - #sql += "%s )" % random.choice(self.order_where) - sql += "%s " % random.choice(self.unionall_or_union) - sql += "select floor(asct2) from ( select " - sql += "%s as asct2 " % math_fun_2 - # sql += "%s, " % random.choice(self.s_s_select) - # sql += "%s, " % random.choice(self.q_select) - sql += " from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - #sql += "%s " % random.choice(having_support) - #sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15473 tdSql.query(sql) - #TD-15473 self.cur1.execute(sql) - - tdSql.query("select 1-3 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts , min(asct1) from ( select " - sql += "%s as asct1, ts ," % math_fun_1 - sql += "%s as asct2, " % math_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s select " % random.choice(self.unionall_or_union) - sql += "%s as asct2, ts ," % math_fun_2 - sql += "%s as asct1, " % math_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15473 tdSql.query(sql) - #self.cur1.execute(sql) - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) \ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select ts , min(asct1) from ( select " - sql += "%s as asct1, ts ," % math_fun_1 - sql += "%s as asct2, " % math_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s select " % random.choice(self.unionall_or_union) - sql += "%s as asct2, ts ," % math_fun_2 - sql += "%s as asct1, " % math_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15473 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 1-4 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts , asct1 from ( select t1.ts as ts," - sql += "%s, " % math_fun_join_1 - sql += "%s as asct1, " % math_fun_join_2 - sql += "%s, " % math_fun_join_1 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM'])\ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select count(asct1) from ( select " - sql += "%s as asct1 " % math_fun_join_2 - sql += "from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s " % random.choice(self.q_u_or_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-5 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts ," - sql += "%s, " % math_fun_1 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s " % math_fun_2 - sql += " from ( select * from regular_table_1 ) where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM'])\ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select " - # sql += "%s, " % math_fun_1 - # sql += "%s, " % random.choice(self.q_select) - # sql += "%s, " % random.choice(self.q_select) - sql += "%s " % math_fun_2 - sql += " from ( select * from regular_table_1 ) where " - sql += "%s " % random.choice(self.q_where) - sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15973 tdSql.query(sql) - #TD-15973 self.cur1.execute(sql) - - tdSql.query("select 1-6 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts , max(asct1) from ( select t1.ts as ts," - sql += "%s, " % math_fun_join_1 - sql += "%s as asct1, " % math_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "%s, " % math_fun_join_1 - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s )" % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) \ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select max(asct1) from ( select " - #sql += "%s, " % math_fun_join_1 - sql += "%s as asct1 " % math_fun_join_2 - # sql += "t1.%s, " % random.choice(self.q_select) - # sql += "t2.%s, " % random.choice(self.q_select) - # sql += "%s, " % math_fun_join_1 - sql += "from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s )" % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-7 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts , abs(asct1) from ( select " - sql += "%s as asct1, ts ," % math_fun_1 - sql += "%s as asct2, " % math_fun_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # tdSql.checkRows(300) - # self.cur1.execute(sql)# TD-16039 - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) or (mathlist == ['TAIL']) or (mathlist == ['CSUM'])\ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select abs(asct1) from ( select " - sql += "%s as asct1 " % math_fun_1 - sql += "from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - - tdSql.query("select 1-8 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts,floor(asct1) " - sql += "from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s as asct1, ts ," % math_fun_1 - sql += "%s as asct2, " % math_fun_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) - # tdSql.checkRows(300) - # self.cur1.execute(sql)# TD-16039 - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM'])\ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select floor(asct1) " - sql += "from ( select " - sql += "%s as asct1 " % math_fun_1 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - - tdSql.query("select 1-9 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts , max(asct1) from ( select t1.ts as ts," - sql += "%s, " % math_fun_join_1 - sql += "%s as asct1, " % math_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "and %s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM'])\ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select max(asct1) from ( select " - sql += "%s as asct1 " % math_fun_join_2 - # sql += "t1.%s, " % random.choice(self.q_select) - # sql += "t1.%s, " % random.choice(self.q_select) - # sql += "t2.%s, " % random.choice(self.q_select) - # sql += "t2.%s, " % random.choice(self.q_select) - sql += "from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "and %s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql)# TD-16039 - # self.cur1.execute(sql) - - self.restartDnodes() - tdSql.query("select 1-10 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts , min(asct1) from ( select " - sql += "%s as asct1, ts ," % math_fun_1 - sql += "%s as asct2, " % math_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ") %s " % random.choice(self.unionall_or_union) - sql += "select ts , max(asct2) from ( select " - sql += "%s as asct1, ts ," % math_fun_1 - sql += "%s as asct2, " % math_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) \ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select min(asct1) from ( select " - sql += "%s as asct1 " % math_fun_1 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += ") %s " % random.choice(self.unionall_or_union) - sql += "select max(asct2) from ( select " - sql += "%s as asct2 " % math_fun_2 - sql += "from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - - #3 inter union not support - tdSql.query("select 1-11 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts , min(asct1), max(asct2) from ( select " - sql += "%s as asct1, ts ," % math_fun_1 - sql += "%s as asct2, " % math_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - #sql += "%s " % random.choice(limit1_where) - sql += " %s " % random.choice(self.unionall_or_union) - sql += " select " - sql += "%s as asct1, ts ," % math_fun_1 - sql += "%s as asct2, " % math_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15837 tdSql.query(sql) - # self.cur1.execute(sql) - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) \ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select min(asct1) from ( select " - sql += "%s as asct1 " % math_fun_1 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += " %s " % random.choice(self.unionall_or_union) - sql += " select " - sql += "%s as asct2 " % math_fun_2 - sql += " from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15837 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 1-12 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts , max(asct1) from ( select t1.ts as ts," - sql += "%s, " % math_fun_join_1 - sql += "%s as asct1, " % math_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM'])\ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select max(asct1) from ( select " - sql += "%s as asct1 " % math_fun_join_2 - sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - - tdSql.query("select 1-13 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts ," - sql += "%s, " % math_fun_1 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s " % math_fun_2 - sql += "%s " % random.choice(self.t_select) - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # tdSql.checkRows(300) - # self.cur1.execute(sql) # TD-16039 - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) \ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select " - sql += "%s " % math_fun_2 - sql += "%s " % random.choice(self.t_select) - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD15973 tdSql.query(sql) - #TD15973 self.cur1.execute(sql) - - tdSql.query("select 1-14 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select avg(asct1),count(asct2) from ( select " - sql += "%s as asct1, " % math_fun_1 - sql += "%s as asct2" % math_fun_2 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.partiton_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += " ) ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM'])\ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select avg(asct1) from ( select " - sql += "%s as asct1 " % math_fun_1 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.partiton_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += " ) ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - - tdSql.query("select 1-15 as math_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ - or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : - sql = "select ts , max(asct1) from ( select t1.ts as ts," - sql += "%s, " % math_fun_join_1 - sql += "%s as asct1, " % math_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s " % random.choice(self.q_select) - sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += " and %s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.partiton_where_j) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") " - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) or (mathlist == ['TAIL']) or (mathlist == ['CSUM'])\ - or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']): - sql = "select max(asct1) from ( select " - sql += "%s as asct1 " % math_fun_join_2 - sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += " and %s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.partiton_where_j) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") " - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - - #taos -f sql - startTime_taos_f = time.time() - print("taos -f %s sql start!" %mathlist) - taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) - _ = subprocess.check_output(taos_cmd1, shell=True).decode("utf-8") - print("taos -f %s sql over!" %mathlist) - endTime_taos_f = time.time() - print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) - - print("=========%s====over=============" %mathlist) - - - def str_nest(self,strlist): - - print("==========%s===start=============" %strlist) - os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) - - self.dropandcreateDB_random("%s" %self.db_nest, 1) - - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['LENGTH','CHAR_LENGTH']) \ - or (strlist == ['']): - str_functions = strlist - fun_fix_column = ['(q_nchar)','(q_binary)','(q_nchar_null)','(q_binary_null)'] - fun_column_1 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) - str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_2 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) - str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - fun_fix_column_j = ['(t1.q_nchar)','(t1.q_binary)','(t1.q_nchar_null)','(t1.q_binary_null)', - '(t2.q_nchar)','(t2.q_binary)','(t2.q_nchar_null)','(t2.q_binary_null)'] - fun_column_join_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) - str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_join_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) - str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - fun_fix_column_s = ['(q_nchar)','(q_binary)','(q_nchar_null)','(q_binary_null)','(loc)','(tbname)'] - fun_column_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) - str_fun_s_1 = str(fun_column_s_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) - str_fun_s_2 = str(fun_column_s_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - fun_fix_column_s_j = ['(t1.q_nchar)','(t1.q_binary)','(t1.q_nchar_null)','(t1.q_binary_null)','(t1.loc)','(t1.tbname)', - '(t2.q_nchar)','(t2.q_binary)','(t2.q_nchar_null)','(t2.q_binary_null)','(t2.loc)','(t2.tbname)'] - fun_column_join_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) - str_fun_join_s_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_join_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) - str_fun_join_s_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - elif (strlist == ['SUBSTR']) : - str_functions = strlist - pos = random.randint(1, 20) - sub_len = random.randint(1, 10) - fun_fix_column = ['(q_nchar,pos)','(q_binary,pos)','(q_nchar_null,pos)','(q_binary_null,pos)', - '(q_nchar,pos,sub_len)','(q_binary,pos,sub_len)','(q_nchar_null,pos,sub_len)','(q_binary_null,pos,sub_len)',] - fun_column_1 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) - str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) - fun_column_2 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) - str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) - - fun_fix_column_j = ['(t1.q_nchar,pos)','(t1.q_binary,pos)','(t1.q_nchar_null,pos)','(t1.q_binary_null,pos)', - '(t1.q_nchar,pos,sub_len)','(t1.q_binary,pos,sub_len)','(t1.q_nchar_null,pos,sub_len)','(t1.q_binary_null,pos,sub_len)', - '(t2.q_nchar,pos)','(t2.q_binary,pos)','(t2.q_nchar_null,pos)','(t2.q_binary_null,pos)', - '(t2.q_nchar,pos,sub_len)','(t2.q_binary,pos,sub_len)','(t2.q_nchar_null,pos,sub_len)','(t2.q_binary_null,pos,sub_len)'] - fun_column_join_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) - str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) - fun_column_join_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) - str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) - - fun_fix_column_s = ['(q_nchar,pos)','(q_binary,pos)','(q_nchar_null,pos)','(q_binary_null,pos)','(loc,pos)', - '(q_nchar,pos,sub_len)','(q_binary,pos,sub_len)','(q_nchar_null,pos,sub_len)','(q_binary_null,pos,sub_len)','(loc,pos,sub_len)',] - fun_column_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) - str_fun_s_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) - fun_column_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) - str_fun_s_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) - - fun_fix_column_s_j = ['(t1.q_nchar,pos)','(t1.q_binary,pos)','(t1.q_nchar_null,pos)','(t1.q_binary_null,pos)','(t1.loc,pos)', - '(t1.q_nchar,pos,sub_len)','(t1.q_binary,pos,sub_len)','(t1.q_nchar_null,pos,sub_len)','(t1.q_binary_null,pos,sub_len)','(t1.loc,pos,sub_len)', - '(t2.q_nchar,pos)','(t2.q_binary,pos)','(t2.q_nchar_null,pos)','(t2.q_binary_null,pos)','(t2.loc,pos)', - '(t2.q_nchar,pos,sub_len)','(t2.q_binary,pos,sub_len)','(t2.q_nchar_null,pos,sub_len)','(t2.q_binary_null,pos,sub_len)','(t2.loc,pos,sub_len)'] - fun_column_join_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_s_j,1) - str_fun_join_s_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) - fun_column_join_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_s_j,1) - str_fun_join_s_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) - - elif (strlist == ['CONCAT']) : - str_functions = strlist - i = random.randint(2,8) - fun_fix_column = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','q_nchar_null', - 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] - - column1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") - fun_column_1 = str(random.sample(str_functions,1))+'('+column1+')' - str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") - - column2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") - fun_column_2 = str(random.sample(str_functions,1))+'('+column2+')' - str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") - - fun_fix_column_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)', - '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)', - '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', - '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] - - column_j1 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") - fun_column_join_1 = str(random.sample(str_functions,1))+'('+column_j1+')' - str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") - - column_j2 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") - fun_column_join_2 = str(random.sample(str_functions,1))+'('+column_j2+')' - str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") - - fun_fix_column_s = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','loc','q_nchar_null', - 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] - - column_s1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") - fun_column_s_1 = str(random.sample(str_functions,1))+'('+column_s1+')' - str_fun_s_1 = str(fun_column_s_1).replace("[","").replace("]","").replace("'","") - - column_s2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") - fun_column_s_2 = str(random.sample(str_functions,1))+'('+column_s2+')' - str_fun_s_2 = str(fun_column_s_2).replace("[","").replace("]","").replace("'","") - - fun_fix_column_s_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)','(t1.loc)', - '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)','(t2.loc)', - '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', - '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] - - column_j_s1 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") - fun_column_join_s_1 = str(random.sample(str_functions,1))+'('+column_j_s1+')' - str_fun_join_s_1 = str(fun_column_join_s_1).replace("[","").replace("]","").replace("'","") - - column_j_s2 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") - fun_column_join_s_2 = str(random.sample(str_functions,1))+'('+column_j_s2+')' - str_fun_join_s_2 = str(fun_column_join_s_2).replace("[","").replace("]","").replace("'","") - - elif (strlist == ['CONCAT_WS']): - str_functions = strlist - i = random.randint(2,8) - fun_fix_column = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','q_nchar_null', - 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] - - separators = ['',' ','abc','123','!','@','#','$','%','^','&','*','(',')','-','_','+','=','{', - '[','}',']','|',';',':',',','.','<','>','?','/','~','`','taos','涛思'] - separator = str(random.sample(separators,i)).replace("[","").replace("]","") - - column1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") - fun_column_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column1+')' - str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") - - column2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") - fun_column_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column2+')' - str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") - - fun_fix_column_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)', - '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)', - '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', - '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] - - column_j1 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") - fun_column_join_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j1+')' - str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") - - column_j2 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") - fun_column_join_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j2+')' - str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") - - fun_fix_column_s = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','loc','q_nchar_null', - 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] - - column_s1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") - fun_column_s_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_s1+')' - str_fun_s_1 = str(fun_column_s_1).replace("[","").replace("]","").replace("'","") - - column_s2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") - fun_column_s_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_s2+')' - str_fun_s_2 = str(fun_column_s_2).replace("[","").replace("]","").replace("'","") - - fun_fix_column_s_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)','(t1.loc)', - '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)','(t2.loc)', - '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', - '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] - - column_j_s1 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") - fun_column_join_s_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j_s1+')' - str_fun_join_s_1 = str(fun_column_join_s_1).replace("[","").replace("]","").replace("'","") - - column_j_s2 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") - fun_column_join_s_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j_s2+')' - str_fun_join_s_2 = str(fun_column_join_s_2).replace("[","").replace("]","").replace("'","") - - - tdSql.query("select 1-1 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']) : - sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " - sql += "%s as asct1, " % str_fun_1 - sql += "%s as asct2, " % str_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " - sql += "%s as asct1, " % str_fun_1 - sql += "%s as asct2, " % str_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-2 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']) : - sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " - sql += "%s as asct1, " % str_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s )" % random.choice(self.order_where) - sql += "%s " % random.choice(self.unionall_or_union) - sql += "select ts , asct2 from ( select " - sql += "%s as asct2, " % str_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - #sql += "%s " % random.choice(having_support) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " - sql += "%s as asct1, " % str_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s )" % random.choice(self.order_where) - sql += "%s " % random.choice(self.unionall_or_union) - sql += "select ts , asct2 from ( select " - sql += "%s as asct2, " % str_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - #sql += "%s " % random.choice(having_support) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - - tdSql.query("select 1-3 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " - sql += "%s as asct1, ts ," % str_fun_1 - sql += "%s as asct2, " % str_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s select " % random.choice(self.unionall_or_union) - sql += "%s as asct2, ts ," % str_fun_2 - sql += "%s as asct1, " % str_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15473 tdSql.query(sql) - #self.cur1.execute(sql) - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " - sql += "%s as asct1, ts ," % str_fun_1 - sql += "%s as asct2, " % str_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s select " % random.choice(self.unionall_or_union) - sql += "%s as asct2, ts ," % str_fun_2 - sql += "%s as asct1, " % str_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15473 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 1-4 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts," - sql += "%s as asct2, " % str_fun_join_1 - sql += "%s as asct1, " % str_fun_join_2 - sql += "%s, " % str_fun_join_1 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts," - sql += "%s as asct2, " % str_fun_join_1 - sql += "%s as asct1, " % str_fun_join_2 - sql += "%s, " % str_fun_join_1 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-5 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts ," - sql += "%s, " % str_fun_1 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s " % str_fun_2 - sql += " from ( select * from regular_table_1 ) where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select ts ," - sql += "%s, " % str_fun_1 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s " % str_fun_2 - sql += " from ( select * from regular_table_1 ) where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - - tdSql.query("select 1-6 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts," - sql += "%s as asct2, " % str_fun_join_1 - sql += "%s as asct1, " % str_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "%s, " % str_fun_join_1 - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s )" % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts," - sql += "%s as asct2, " % str_fun_join_1 - sql += "%s as asct1, " % str_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "%s, " % str_fun_join_1 - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s )" % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-7 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " - sql += "%s as asct1, ts ," % str_fun_s_1 - sql += "%s as asct2, " % str_fun_s_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # tdSql.checkRows(300) - # self.cur1.execute(sql)# TD-16039 - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " - sql += "%s as asct1, ts ," % str_fun_s_1 - sql += "%s as asct2, " % str_fun_s_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - - tdSql.query("select 1-8 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts, LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) " - sql += "from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s as asct1, ts ," % str_fun_s_1 - sql += "%s as asct2, " % str_fun_s_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # tdSql.checkRows(300) - # self.cur1.execute(sql)# TD-16039 - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) " - sql += "from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s as asct1, ts ," % str_fun_s_1 - sql += "%s as asct2, " % str_fun_s_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - - tdSql.query("select 1-9 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts," - sql += "%s as asct2, " % str_fun_join_s_1 - sql += "%s as asct1, " % str_fun_join_s_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "and %s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts," - sql += "%s as asct2, " % str_fun_join_s_1 - sql += "%s as asct1, " % str_fun_join_s_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "and %s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - - self.restartDnodes() - tdSql.query("select 1-10 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " - sql += "%s as asct1, ts ," % str_fun_s_1 - sql += "%s as asct2, " % str_fun_s_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ") %s " % random.choice(self.unionall_or_union) - sql += "select ts , max(asct2) from ( select " - sql += "%s as asct1, ts ," % str_fun_1 - sql += "%s as asct2, " % str_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " - sql += "%s as asct1, ts ," % str_fun_s_1 - sql += "%s as asct2, " % str_fun_s_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ") %s " % random.choice(self.unionall_or_union) - sql += "select ts , max(asct2) from ( select " - sql += "%s as asct1, ts ," % str_fun_1 - sql += "%s as asct2, " % str_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - - #3 inter union not support - tdSql.query("select 1-11 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " - sql += "%s as asct1, ts ," % str_fun_s_1 - sql += "%s as asct2, " % str_fun_s_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - #sql += "%s " % random.choice(limit1_where) - sql += " %s " % random.choice(self.unionall_or_union) - sql += " select " - sql += "%s as asct1, ts ," % str_fun_1 - sql += "%s as asct2, " % str_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15837 tdSql.query(sql) - # self.cur1.execute(sql) - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " - sql += "%s as asct1, ts ," % str_fun_s_1 - sql += "%s as asct2, " % str_fun_s_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - #sql += "%s " % random.choice(limit1_where) - sql += " %s " % random.choice(self.unionall_or_union) - sql += " select " - sql += "%s as asct1, ts ," % str_fun_1 - sql += "%s as asct2, " % str_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15837 tdSql.query(sql) - # self.cur1.execute(sql) - - tdSql.query("select 1-12 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts," - sql += "%s as asct2, " % str_fun_join_s_1 - sql += "%s as asct1, " % str_fun_join_s_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts," - sql += "%s as asct2, " % str_fun_join_s_1 - sql += "%s as asct1, " % str_fun_join_s_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - - tdSql.query("select 1-13 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts ," - sql += "%s, " % str_fun_1 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % str_fun_2 - sql += "%s " % random.choice(self.t_select) - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # tdSql.checkRows(300) - # self.cur1.execute(sql) # TD-16039 - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select ts ," - sql += "%s, " % str_fun_1 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % str_fun_2 - sql += "%s " % random.choice(self.t_select) - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # tdSql.checkRows(300) - # self.cur1.execute(sql)# TD-16039 - - tdSql.query("select 1-14 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " - sql += "%s as asct1, " % str_fun_s_1 - sql += "%s as asct2" % str_fun_s_2 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.partiton_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += " ) ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " - sql += "%s as asct1, " % str_fun_s_1 - sql += "%s as asct2" % str_fun_s_2 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.partiton_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += " ) ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - - tdSql.query("select 1-15 as str_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): - sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts," - sql += "%s as asct2, " % str_fun_join_s_1 - sql += "%s as asct1, " % str_fun_join_s_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s " % random.choice(self.q_select) - sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += " and %s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.partiton_where_j) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") " - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15955 tdSql.query(sql) - #TD-15955 self.cur1.execute(sql) - elif (strlist == ['LENGTH','CHAR_LENGTH']): - sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts," - sql += "%s as asct2, " % str_fun_join_s_1 - sql += "%s as asct1, " % str_fun_join_s_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s " % random.choice(self.q_select) - sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += " and %s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.partiton_where_j) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") " - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15955 tdSql.query(sql) - #TD-15955 self.cur1.execute(sql) - - #taos -f sql - startTime_taos_f = time.time() - print("taos -f %s sql start!" %strlist) - taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) - _ = subprocess.check_output(taos_cmd1, shell=True).decode("utf-8") - print("taos -f %s sql over!" %strlist) - endTime_taos_f = time.time() - print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) - - print("=========%s====over=============" %strlist) - - def time_nest(self,timelist): - - print("==========%s===start=============" %timelist) - os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) - - self.dropandcreateDB_random("%s" %self.db_nest, 1) - - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMEZONE']): - time_functions = timelist - fun_fix_column = ['()'] - fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - fun_fix_column_j = ['()'] - fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - elif (timelist == ['TIMETRUNCATE']): - time_functions = timelist - - t = time.time() - t_to_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)) - fun_fix_column = ['q_ts','ts','_c0','_C0','_rowts','1600000000000','1600000000000000','1600000000000000000', - '%d' %t, '%d000' %t, '%d000000' %t,'t_to_s'] - - timeunits = ['1u' , '1a' ,'1s', '1m' ,'1h', '1d'] - timeunit = str(random.sample(timeunits,1)).replace("[","").replace("]","").replace("'","") - - column_1 = ['(%s,timeutil)'%(random.sample(fun_fix_column,1))] - fun_column_1 = random.sample(time_functions,1)+random.sample(column_1,1) - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") - time_fun_1 = str(time_fun_1).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) - - column_2 = ['(%s,timeutil)'%(random.sample(fun_fix_column,1))] - fun_column_2 = random.sample(time_functions,1)+random.sample(column_2,1) - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") - time_fun_2 = str(time_fun_2).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) - - - fun_fix_column_j = ['(t1.q_ts)','(t1.ts)', '(t2.q_ts)','(t2.ts)','(1600000000000)','(1600000000000000)','(1600000000000000000)', - '(%d)' %t, '(%d000)' %t, '(%d000000)' %t,'t_to_s'] - - column_j1 = ['(%s,timeutil)'%(random.sample(fun_fix_column_j,1))] - fun_column_join_1 = random.sample(time_functions,1)+random.sample(column_j1,1) - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") - time_fun_join_1 = str(time_fun_join_1).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) - - column_j2 = ['(%s,timeutil)'%(random.sample(fun_fix_column_j,1))] - fun_column_join_2 = random.sample(time_functions,1)+random.sample(column_j2,1) - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") - time_fun_join_2 = str(time_fun_join_2).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) - - elif (timelist == ['TO_ISO8601']): - time_functions = timelist - - t = time.time() - fun_fix_column = ['(now())','(ts)','(q_ts)','(_rowts)','(_c0)','(_C0)', - '(1600000000000)','(1600000000000000)','(1600000000000000000)', - '(%d)' %t, '(%d000)' %t, '(%d000000)' %t] - - fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") - - fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - fun_fix_column_j = ['(t1.q_ts)','(t1.ts)', '(t2.q_ts)','(t2.ts)','(1600000000000)','(1600000000000000)','(1600000000000000000)','(now())', - '(%d)' %t, '(%d000)' %t, '(%d000000)' %t] - - fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") - - fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - elif (timelist == ['TO_UNIXTIMESTAMP']): - time_functions = timelist - - t = time.time() - t_to_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)) - fun_fix_column = ['(q_nchar)','(q_nchar1)','(q_nchar2)','(q_nchar3)','(q_nchar4)','(q_nchar_null)','(q_binary)','(q_binary5)','(q_binary6)','(q_binary7)','(q_binary8)','(q_binary_null)','(t_to_s)'] - - fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") - time_fun_1 = str(time_fun_1).replace("t_to_s","%s" %t_to_s) - - fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") - time_fun_2 = str(time_fun_2).replace("t_to_s","%s" %t_to_s) - - fun_fix_column_j = ['(t1.q_nchar)','(t1.q_binary)', '(t2.q_nchar)','(t2.q_binary)','(t_to_s)'] - - fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") - time_fun_join_1 = str(time_fun_join_1).replace("t_to_s","%s" %t_to_s) - - fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") - time_fun_join_2 = str(time_fun_join_2).replace("t_to_s","%s" %t_to_s) - - elif (timelist == ['TIMEDIFF']): - time_functions = timelist - - t = time.time() - t_to_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)) - fun_fix_column = ['(q_nchar)','(q_nchar1)','(q_nchar2)','(q_nchar3)','(q_nchar4)','(q_nchar_null)','(q_binary)','(q_binary5)','(q_binary6)','(q_binary7)','(q_binary8)','(q_binary_null)','(t_to_s)'] - - fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") - time_fun_1 = str(time_fun_1).replace("t_to_s","%s" %t_to_s) - - fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") - time_fun_2 = str(time_fun_2).replace("t_to_s","%s" %t_to_s) - - fun_fix_column_j = ['(t1.q_nchar)','(t1.q_binary)', '(t2.q_nchar)','(t2.q_binary)','(t_to_s)'] - - fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") - time_fun_join_1 = str(time_fun_join_1).replace("t_to_s","%s" %t_to_s) - - fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") - time_fun_join_2 = str(time_fun_join_2).replace("t_to_s","%s" %t_to_s) - - elif (timelist == ['ELAPSED']): - time_functions = timelist - - fun_fix_column = ['(ts)','(q_ts)','(_c0)','(_C0)','(_rowts)','(ts,time_unit)','(_c0,time_unit)','(_C0,time_unit)','(_rowts,time_unit)'] - - time_units = ['nums','numm','numh','numd','numa'] - time_unit = str(random.sample(time_units,1)).replace("[","").replace("]","").replace("'","") - time_num1 = random.randint(0, 1000) - time_unit1 = time_unit.replace("num","%d" %time_num1) - time_num2 = random.randint(0, 1000) - time_unit2 = time_unit.replace("num","%d" %time_num2) - - fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit1) - - fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit2) - - - fun_fix_column_j = ['(t1.ts)','(t1.q_ts)', '(t2.ts)','(t2.q_ts)','(t1.ts,time_unit)','(t1.q_ts,time_unit)','(t2.ts,time_unit)','(t2.q_ts,time_unit)'] - - fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit1) - - fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit2) - - - elif (timelist == ['CAST']) : - str_functions = timelist - #下面的4个是全的,这个只是1个 - i = random.randint(1,4) - if i ==1: - print('===========cast_1===========') - fun_fix_column = ['q_bool','q_bool_null','q_bigint','q_bigint_null','q_smallint','q_smallint_null', - 'q_tinyint','q_tinyint_null','q_int','q_int_null','q_float','q_float_null','q_double','q_double_null'] - type_names = ['BIGINT','BINARY(100)','TIMESTAMP','NCHAR(100)','BIGINT UNSIGNED'] - - type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") - - type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") - - fun_fix_column_j = ['t1.q_bool','t1.q_bool_null','t1.q_bigint','t1.q_bigint_null','t1.q_smallint','t1.q_smallint_null', - 't1.q_tinyint','t1.q_tinyint_null','t1.q_int','t1.q_int_null','t1.q_float','t1.q_float_null','t1.q_double','t1.q_double_null', - 't2.q_bool','t2.q_bool_null','t2.q_bigint','t2.q_bigint_null','t2.q_smallint','t2.q_smallint_null', - 't2.q_tinyint','t2.q_tinyint_null','t2.q_int','t2.q_int_null','t2.q_float','t2.q_float_null','t2.q_double','t2.q_double_null'] - - type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") - - type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") - - elif i==2: - print('===========cast_2===========') - fun_fix_column = ['q_binary','q_binary_null','q_binary1','q_binary2','q_binary3','q_binary4'] - type_names = ['BIGINT','BINARY(100)','NCHAR(100)','BIGINT UNSIGNED'] - - type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") - - type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") - - fun_fix_column_j = ['t1.q_binary','t1.q_binary_null','t1.q_binary1','t1.q_binary2','t1.q_binary3','t1.q_smallint_null','t1.q_binary4', - 't2.q_binary','t2.q_binary_null','t2.q_bigint','t2.q_binary1','t2.q_binary2','t2.q_binary3','t2.q_binary4'] - - type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") - - type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") - - elif i==3: - print('===========cast_3===========') - fun_fix_column = ['q_nchar','q_nchar_null','q_nchar5','q_nchar6','q_nchar7','q_nchar8'] - type_names = ['BIGINT','NCHAR(100)','BIGINT UNSIGNED'] - - type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") - - type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") - - fun_fix_column_j = ['t1.q_nchar','t1.q_nchar_null','t1.q_nchar5','t1.q_nchar6','t1.q_nchar7','t1.q_nchar8', - 't2.q_nchar','t2.q_nchar_null','t2.q_nchar5','t2.q_nchar6','t2.q_nchar7','t2.q_nchar8'] - - type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") - - type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") - - elif i==4: - print('===========cast_4===========') - fun_fix_column = ['q_ts','q_ts_null','_C0','_c0','ts','_rowts'] - type_names = ['BIGINT','TIMESTAMP','BIGINT UNSIGNED'] - - type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") - - type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") - - fun_fix_column_j = ['t1.q_ts','t1.q_ts_null','t1.ts','t2.q_ts','t2.q_ts_null','t2.ts'] - - type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") - - type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") - - elif (timelist == ['CAST_1']) : - str_functions = timelist - - print('===========cast_1===========') - fun_fix_column = ['q_bool','q_bool_null','q_bigint','q_bigint_null','q_smallint','q_smallint_null', - 'q_tinyint','q_tinyint_null','q_int','q_int_null','q_float','q_float_null','q_double','q_double_null'] - type_names = ['BIGINT','BINARY(100)','TIMESTAMP','NCHAR(100)','BIGINT UNSIGNED'] - - type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_1","") - - type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_1","") - - fun_fix_column_j = ['t1.q_bool','t1.q_bool_null','t1.q_bigint','t1.q_bigint_null','t1.q_smallint','t1.q_smallint_null', - 't1.q_tinyint','t1.q_tinyint_null','t1.q_int','t1.q_int_null','t1.q_float','t1.q_float_null','t1.q_double','t1.q_double_null', - 't2.q_bool','t2.q_bool_null','t2.q_bigint','t2.q_bigint_null','t2.q_smallint','t2.q_smallint_null', - 't2.q_tinyint','t2.q_tinyint_null','t2.q_int','t2.q_int_null','t2.q_float','t2.q_float_null','t2.q_double','t2.q_double_null'] - - type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_1","") - - type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_1","") - - elif (timelist == ['CAST_2']) : - str_functions = timelist - print('===========cast_2===========') - fun_fix_column = ['q_binary','q_binary_null','q_binary1','q_binary2','q_binary3','q_binary4'] - type_names = ['BIGINT','BINARY(100)','NCHAR(100)','BIGINT UNSIGNED'] - - type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_2","") - - type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_2","") - - fun_fix_column_j = ['t1.q_binary','t1.q_binary_null','t1.q_binary1','t1.q_binary2','t1.q_binary3','t1.q_smallint_null','t1.q_binary4', - 't2.q_binary','t2.q_binary_null','t2.q_bigint','t2.q_binary1','t2.q_binary2','t2.q_binary3','t2.q_binary4'] - - type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_2","") - - type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_2","") - - elif (timelist == ['CAST_3']) : - str_functions = timelist - print('===========cast_3===========') - fun_fix_column = ['q_nchar','q_nchar_null','q_nchar5','q_nchar6','q_nchar7','q_nchar8'] - type_names = ['BIGINT','NCHAR(100)','BIGINT UNSIGNED'] - - type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_3","") - - type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_3","") - - fun_fix_column_j = ['t1.q_nchar','t1.q_nchar_null','t1.q_nchar5','t1.q_nchar6','t1.q_nchar7','t1.q_nchar8', - 't2.q_nchar','t2.q_nchar_null','t2.q_nchar5','t2.q_nchar6','t2.q_nchar7','t2.q_nchar8'] - - type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_3","") - - type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_3","") - - elif (timelist == ['CAST_4']) : - str_functions = timelist - print('===========cast_4===========') - fun_fix_column = ['q_ts','q_ts_null','_C0','_c0','ts','_rowts'] - type_names = ['BIGINT','TIMESTAMP','BIGINT UNSIGNED'] - - type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' - time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_4","") - - type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' - time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_4","") - - fun_fix_column_j = ['t1.q_ts','t1.q_ts_null','t1.ts','t2.q_ts','t2.q_ts_null','t2.ts'] - - type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' - time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_4","") - - type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") - fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' - time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_4","") - - tdSql.query("select 1-1 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now) from ( select " - sql += "%s as asct1, " % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - elif (timelist == ['TIMEZONE']) \ - or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , asct1,now(),today(),timezone() from ( select " - sql += "%s as asct1, " % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - elif (timelist == ['ELAPSED']) : - sql = "select max(asct1),now(),today(),timezone() from ( select " - sql += "%s as asct1, " % time_fun_1 - sql += "%s as asct2 " % time_fun_2 - sql += "from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-2 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now),now(),today(),timezone() from ( select " - sql += "%s as asct1, " % time_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s )" % random.choice(self.order_where) - sql += "%s " % random.choice(self.unionall_or_union) - sql += "select ts , timediff(asct2,now),now(),today(),timezone() from ( select " - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - #sql += "%s " % random.choice(having_support) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , (asct1),now(),today(),timezone() from ( select " - sql += "%s as asct1, " % time_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s )" % random.choice(self.order_where) - sql += "%s " % random.choice(self.unionall_or_union) - sql += "select ts , asct2,now(),today(),timezone() from ( select " - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - elif (timelist == ['ELAPSED']) : - sql = "select min(asct1),now(),today(),timezone() from ( select " - sql += "%s as asct1 " % time_fun_1 - sql += " from regular_table_1 where " - sql += "%s )" % random.choice(self.q_where) - sql += "%s " % random.choice(self.unionall_or_union) - sql += "select avg(asct2),now(),today(),timezone() from ( select " - sql += "%s as asct2 " % time_fun_2 - sql += " from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-3 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now) from ( select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s select " % random.choice(self.unionall_or_union) - sql += "%s as asct2, ts ," % time_fun_2 - sql += "%s as asct1, " % time_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15473 tdSql.query(sql) - #self.cur1.execute(sql) - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , (asct1),now(),today(),timezone() from ( select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s select " % random.choice(self.unionall_or_union) - sql += "%s as asct2, ts ," % time_fun_2 - sql += "%s as asct1, " % time_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15473 tdSql.query(sql) - #self.cur1.execute(sql) - elif (timelist == ['ELAPSED']) : - sql = "select abs(asct1),now(),today(),timezone() from ( select " - sql += "%s as asct1," % time_fun_1 - sql += "%s as asct2 " % time_fun_2 - sql += "from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s select " % random.choice(self.unionall_or_union) - sql += "%s as asct2," % time_fun_2 - sql += "%s as asct1 " % time_fun_1 - sql += "from regular_table_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-4 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now) from ( select t1.ts as ts," - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "%s, " % time_fun_join_1 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , (asct1) from ( select t1.ts as ts," - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "%s, " % time_fun_join_1 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - elif (timelist == ['ELAPSED']) : - sql = "select floor(asct1) from ( select " - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "%s " % time_fun_join_1 - sql += " from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s " % random.choice(self.q_u_or_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-5 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['ELAPSED']) : - sql = "select now(),today(),timezone(), " - sql += "%s, " % time_fun_1 - sql += "%s " % time_fun_2 - sql += " from ( select * from regular_table_1 ) where " - sql += "%s " % random.choice(self.q_where) - sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - else: - sql = "select ts ,now(),today(),timezone(), " - sql += "%s, " % time_fun_1 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s " % time_fun_2 - sql += " from ( select * from regular_table_1 ) where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - - tdSql.query("select 1-6 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now) from ( select t1.ts as ts," - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "%s, " % time_fun_join_1 - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s )" % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , (asct1) from ( select t1.ts as ts," - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "%s, " % time_fun_join_1 - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s )" % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - elif (timelist == ['ELAPSED']) : - sql = "select (asct1)*111 from ( select " - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "%s " % time_fun_join_1 - sql += " from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s )" % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-7 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now) from ( select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) # TD-16039 - # tdSql.checkRows(300) - # self.cur1.execute(sql) - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , (asct1),now(),today(),timezone() from ( select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) # TD-16039 - # tdSql.checkRows(300) - # self.cur1.execute(sql) - elif (timelist == ['ELAPSED']) : - sql = "select (asct1)/asct2 ,now(),today(),timezone() from ( select " - sql += "%s as asct1, " % time_fun_1 - sql += "%s as asct2 " % time_fun_2 - sql += "from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) #同时出现core:TD-16095和TD-16042 - # self.cur1.execute(sql) - - tdSql.query("select 1-8 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now) " - sql += "from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) # TD-16039 - # tdSql.checkRows(300) - # self.cur1.execute(sql) - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , (asct1),now(),today(),timezone() " - sql += "from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) # TD-16039 - # tdSql.checkRows(300) - # self.cur1.execute(sql) - elif (timelist == ['ELAPSED']) : - sql = "select floor(abs(asct1)),now(),today(),timezone() " - sql += "from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s as asct1, " % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) # TD-16039 - # self.cur1.execute(sql) - - tdSql.query("select 1-9 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now) from ( select t1.ts as ts," - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "and %s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) TD-16039 - # self.cur1.execute(sql) TD-16039 - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , asct1 from ( select t1.ts as ts," - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "and %s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - elif (timelist == ['ELAPSED']) : - sql = "select min(asct1*110) from ( select " - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1 " % time_fun_join_2 - sql += "from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "and %s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - - self.restartDnodes() - tdSql.query("select 1-10 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now) from ( select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ") %s " % random.choice(self.unionall_or_union) - sql += "select ts , max(asct2) from ( select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , (asct1),now(),today(),timezone() from ( select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ") %s " % random.choice(self.unionall_or_union) - sql += "select ts , max(asct2),now(),today(),timezone() from ( select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - elif (timelist == ['ELAPSED']) : - sql = "select abs(asct1),now(),today(),timezone() from ( select " - sql += "%s as asct1 ," % time_fun_1 - sql += "%s as asct2 " % time_fun_2 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += ") %s " % random.choice(self.unionall_or_union) - sql += "select max(asct2),now(),today(),timezone() from ( select " - sql += "%s as asct1 ," % time_fun_1 - sql += "%s as asct2 " % time_fun_2 - sql += "from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - - #3 inter union not support - tdSql.query("select 1-11 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now), timediff(now,asct2) from ( select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += " %s " % random.choice(self.unionall_or_union) - sql += " select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql)#TD-15473 - # self.cur1.execute(sql)#TD-15473 - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , (asct1,now()),(now(),asct2) from ( select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += " %s " % random.choice(self.unionall_or_union) - sql += " select " - sql += "%s as asct1, ts ," % time_fun_1 - sql += "%s as asct2, " % time_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql)#TD-15473 - # self.cur1.execute(sql)#TD-15473 - elif (timelist == ['ELAPSED']) : - sql = "select asct1+asct2,now(),today(),timezone() from ( select " - sql += "%s as asct1, " % time_fun_1 - sql += "%s as asct2 " % time_fun_2 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += " %s " % random.choice(self.unionall_or_union) - sql += " select " - sql += "%s as asct1 ," % time_fun_1 - sql += "%s as asct2 " % time_fun_2 - sql += " from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql)#TD-15473 - self.cur1.execute(sql)#TD-15473 - - tdSql.query("select 1-12 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now) from ( select t1.ts as ts," - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , asct1,now() from ( select t1.ts as ts," - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - elif (timelist == ['ELAPSED']) : - sql = "select min(floor(asct1)),now() from ( select " - sql += "%s, " % time_fun_join_1 - sql += "%s as asct1 " % time_fun_join_2 - sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql)# TD-16039 - - tdSql.query("select 1-13 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(%s,now)," % time_fun_2 - sql += "%s as asct1, " % time_fun_1 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s " % time_fun_2 - sql += "%s " % random.choice(self.t_select) - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # tdSql.checkRows(300) - # self.cur1.execute(sql) # TD-16039 - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts ,now(),today(),timezone(), " - sql += "%s as asct1, " % time_fun_1 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s " % time_fun_2 - sql += "%s " % random.choice(self.t_select) - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # tdSql.checkRows(300) - # self.cur1.execute(sql) # TD-16039 - elif (timelist == ['ELAPSED']) : - sql = "select now(),today(),timezone(), " - sql += "%s as asct1, " % time_fun_1 - sql += "%s " % time_fun_2 - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - - tdSql.query("select 1-14 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now),timediff(now,asct2) from ( select ts ts ," - sql += "%s as asct1, " % time_fun_1 - sql += "%s as asct2" % time_fun_2 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.partiton_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += " ) ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , (asct1),now(),(now()),asct2 from ( select ts ts ," - sql += "%s as asct1, " % time_fun_1 - sql += "%s as asct2" % time_fun_2 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.partiton_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += " ) ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - elif (timelist == ['ELAPSED']) : - sql = "select ts , (asct1)*asct2,now(),(now()) from ( select " - sql += "%s as asct1, " % time_fun_1 - sql += "%s as asct2" % time_fun_2 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.partiton_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += " ) ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - - tdSql.query("select 1-15 as time_nest from stable_1 limit 1;") - for i in range(self.fornum): - if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ - or (timelist == ['TO_UNIXTIMESTAMP']): - sql = "select ts , timediff(asct1,now),timediff(now,asct2) from ( select t1.ts as ts," - sql += "%s as asct2, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s " % random.choice(self.q_select) - sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += " and %s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.partiton_where_j) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") " - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): - sql = "select ts , asct1,(now()),(now()),asct2 ,now(),today(),timezone() from ( select t1.ts as ts," - sql += "%s as asct2, " % time_fun_join_1 - sql += "%s as asct1, " % time_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s " % random.choice(self.q_select) - sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += " and %s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.partiton_where_j) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") " - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - # self.cur1.execute(sql) # TD-16039 - elif (timelist == ['ELAPSED']) : - sql = "select asct1,(now()),(now()),asct2 ,now(),today(),timezone() from ( select " - sql += "%s as asct2, " % time_fun_join_1 - sql += "%s as asct1 " % time_fun_join_2 - sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += " and %s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.partiton_where_j) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") " - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) # TD-16039 - - #taos -f sql - startTime_taos_f = time.time() - print("taos -f %s sql start!" %timelist) - taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) - _ = subprocess.check_output(taos_cmd1, shell=True).decode("utf-8") - print("taos -f %s sql over!" %timelist) - endTime_taos_f = time.time() - print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) - - print("=========%s====over=============" %timelist) - - def base_nest(self,baselist): - - print("==========%s===start=============" %baselist) - os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) - - self.dropandcreateDB_random("%s" %self.db_nest, 1) - - if (baselist == ['A']) or (baselist == ['S']) or (baselist == ['F']) \ - or (baselist == ['C']): - base_functions = baselist - fun_fix_column = ['(q_bigint)','(q_smallint)','(q_tinyint)','(q_int)','(q_float)','(q_double)','(q_bigint_null)','(q_smallint_null)','(q_tinyint_null)','(q_int_null)','(q_float_null)','(q_double_null)'] - fun_column_1 = random.sample(base_functions,1)+random.sample(fun_fix_column,1) - base_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_2 = random.sample(base_functions,1)+random.sample(fun_fix_column,1) - base_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - fun_fix_column_j = ['(t1.q_bigint)','(t1.q_smallint)','(t1.q_tinyint)','(t1.q_int)','(t1.q_float)','(t1.q_double)','(t1.q_bigint_null)','(t1.q_smallint_null)','(t1.q_tinyint_null)','(t1.q_int_null)','(t1.q_float_null)','(t1.q_double_null)', - '(t2.q_bigint)','(t2.q_smallint)','(t2.q_tinyint)','(t2.q_int)','(t2.q_float)','(t2.q_double)','(t2.q_bigint_null)','(t2.q_smallint_null)','(t2.q_tinyint_null)','(t2.q_int_null)','(t2.q_float_null)','(t2.q_double_null)'] - fun_column_join_1 = random.sample(base_functions,1)+random.sample(fun_fix_column_j,1) - base_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") - fun_column_join_2 = random.sample(base_functions,1)+random.sample(fun_fix_column_j,1) - base_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") - - elif (baselist == ['P']) or (baselist == ['M']) or (baselist == ['S'])or (baselist == ['T']): - base_functions = baselist - num = random.randint(0, 1000) - fun_fix_column = ['(q_bigint,num)','(q_smallint,num)','(q_tinyint,num)','(q_int,num)','(q_float,num)','(q_double,num)', - '(q_bigint_null,num)','(q_smallint_null,num)','(q_tinyint_null,num)','(q_int_null,num)','(q_float_null,num)','(q_double_null,num)'] - fun_column_1 = random.sample(base_functions,1)+random.sample(fun_fix_column,1) - base_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",base(num)) - fun_column_2 = random.sample(base_functions,1)+random.sample(fun_fix_column,1) - base_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",base(num)) - - fun_fix_column_j = ['(t1.q_bigint,num)','(t1.q_smallint,num)','(t1.q_tinyint,num)','(t1.q_int,num)','(t1.q_float,num)','(t1.q_double,num)', - '(t1.q_bigint_null,num)','(t1.q_smallint_null,num)','(t1.q_tinyint_null,num)','(t1.q_int_null,num)','(t1.q_float_null,num)','(t1.q_double_null,num)', - '(t2.q_bigint,num)','(t2.q_smallint,num)','(t2.q_tinyint,num)','(t2.q_int,num)','(t2.q_float,num)','(t2.q_double,num)', - '(t2.q_bigint_null,num)','(t2.q_smallint_null,num)','(t2.q_tinyint_null,num)','(t2.q_int_null,num)','(t2.q_float_null,num)','(t2.q_double_null,num)'] - fun_column_join_1 = random.sample(base_functions,1)+random.sample(fun_fix_column_j,1) - base_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",base(num)) - fun_column_join_2 = random.sample(base_functions,1)+random.sample(fun_fix_column_j,1) - base_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",base(num)) - - tdSql.query("select 1-1 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts , floor(asct1) from ( select " - sql += "%s as asct1, " % base_fun_1 - sql += "%s as asct2, " % base_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - - tdSql.query("select 1-2 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts , abs(asct1) from ( select " - sql += "%s as asct1, " % base_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s )" % random.choice(self.order_where) - sql += "%s " % random.choice(self.unionall_or_union) - sql += "select ts , asct2 from ( select " - sql += "%s as asct2, " % base_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - #sql += "%s " % random.choice(having_support) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - - tdSql.query("select 1-3 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts , min(asct1) from ( select " - sql += "%s as asct1, ts ," % base_fun_1 - sql += "%s as asct2, " % base_fun_2 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s select " % random.choice(self.unionall_or_union) - sql += "%s as asct2, ts ," % base_fun_2 - sql += "%s as asct1, " % base_fun_1 - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15473 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 1-4 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts , asct1 from ( select t1.ts as ts," - sql += "%s, " % base_fun_join_1 - sql += "%s as asct1, " % base_fun_join_2 - sql += "%s, " % base_fun_join_1 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - - tdSql.query("select 1-5 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts ," - sql += "%s, " % base_fun_1 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s " % base_fun_2 - sql += " from ( select * from regular_table_1 ) where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - - tdSql.query("select 1-6 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts , max(asct1) from ( select t1.ts as ts," - sql += "%s, " % base_fun_join_1 - sql += "%s as asct1, " % base_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "%s, " % base_fun_join_1 - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s )" % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-7 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts , abs(asct1) from ( select " - sql += "%s as asct1, ts ," % base_fun_1 - sql += "%s as asct2, " % base_fun_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(300) - self.cur1.execute(sql) - - tdSql.query("select 1-8 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts,floor(asct1) " - sql += "from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s as asct1, ts ," % base_fun_1 - sql += "%s as asct2, " % base_fun_2 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(300) - self.cur1.execute(sql) - - tdSql.query("select 1-9 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts , max(asct1) from ( select t1.ts as ts," - sql += "%s, " % base_fun_join_1 - sql += "%s as asct1, " % base_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "and %s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - self.restartDnodes() - tdSql.query("select 1-10 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts , min(asct1) from ( select " - sql += "%s as asct1, ts ," % base_fun_1 - sql += "%s as asct2, " % base_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ") %s " % random.choice(self.unionall_or_union) - sql += "select ts , max(asct2) from ( select " - sql += "%s as asct1, ts ," % base_fun_1 - sql += "%s as asct2, " % base_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15437 tdSql.query(sql) - #TD-15437 self.cur1.execute(sql) - - #3 inter union not support - tdSql.query("select 1-11 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts , min(asct1), max(asct2) from ( select " - sql += "%s as asct1, ts ," % base_fun_1 - sql += "%s as asct2, " % base_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - #sql += "%s " % random.choice(limit1_where) - sql += " %s " % random.choice(self.unionall_or_union) - sql += " select " - sql += "%s as asct1, ts ," % base_fun_1 - sql += "%s as asct2, " % base_fun_2 - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15837 tdSql.query(sql) - # self.cur1.execute(sql) - - tdSql.query("select 1-12 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts , max(asct1) from ( select t1.ts as ts," - sql += "%s, " % base_fun_join_1 - sql += "%s as asct1, " % base_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_u_where) - sql += "and %s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-13 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts ," - sql += "%s, " % base_fun_1 - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s " % base_fun_2 - sql += "%s " % random.choice(self.t_select) - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(300) - self.cur1.execute(sql) - - tdSql.query("select 1-14 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select avg(asct1),count(asct2) from ( select " - sql += "%s as asct1, " % base_fun_1 - sql += "%s as asct2" % base_fun_2 - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.partiton_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += " ) ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 1-15 as base_nest from stable_1 limit 1;") - for i in range(self.fornum): - sql = "select ts , max(asct1) from ( select t1.ts as ts," - sql += "%s, " % base_fun_join_1 - sql += "%s as asct1, " % base_fun_join_2 - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s " % random.choice(self.q_select) - sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += " and %s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.partiton_where_j) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") " - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - #taos -f sql - startTime_taos_f = time.time() - print("taos -f %s sql start!" %baselist) - taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) - _ = subprocess.check_output(taos_cmd1, shell=True).decode("utf-8") - print("taos -f %s sql over!" %baselist) - endTime_taos_f = time.time() - print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) - - print("=========%s====over=============" %baselist) - - def function_before_26(self): - - print('=====================2.6 old function start ===========') - os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) - - self.dropandcreateDB_random("%s" %self.db_nest, 1) - - #1 select * from (select column form regular_table where <\>\in\and\or order by) - tdSql.query("select 1-1 from stable_1;") - for i in range(self.fornum): - #sql = "select ts , * from ( select " ===暂时不支持select * ,用下面这一行 - sql = "select ts from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - - #1 outer union not support - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 1-2 from stable_1;") - for i in range(self.fornum): - #sql = "select ts , * from ( select " - sql = "select ts from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ") union " - #sql += "select ts , * from ( select " - sql += "select ts from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 1-2 from stable_1;") - for i in range(self.fornum): - #sql = "select ts , * from ( select " - sql = "select ts from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ") union all " - #sql += "select ts , * from ( select " - sql += "select ts from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(200) - self.cur1.execute(sql) - - #1 inter union not support - tdSql.query("select 1-3 from stable_1;") - for i in range(self.fornum): - #sql = "select ts , * from ( select " - sql = "select ts from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "" - sql += " union select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15607 tdSql.query(sql) - #tdSql.checkRows(200) - #self.cur1.execute(sql) - - tdSql.query("select 1-3 from stable_1;") - for i in range(self.fornum): - #sql = "select ts , * from ( select " - sql = "select ts from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += " union all select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15607 tdSql.query(sql) - # tdSql.checkRows(300) - #self.cur1.execute(sql) - - #join:select * from (select column form regular_table1,regular_table2 where t1.ts=t2.ts and <\>\in\and\or order by) - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 1-4 from stable_1;") - for i in range(self.fornum): - #sql = "select ts , * from ( select t1.ts ," - sql = "select * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "and %s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - - - #2 select column from (select * form regular_table ) where <\>\in\and\or order by - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 2-1 from stable_1;") - for i in range(self.fornum): - sql = "select ts ," - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s " % random.choice(self.q_select) - sql += " from ( select * from regular_table_1 ) where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(100) - self.cur1.execute(sql) - - #join: select column from (select column form regular_table1,regular_table2 )where t1.ts=t2.ts and <\>\in\and\or order by - #cross join not supported yet - tdSql.query("select 2-2 from stable_1;") - for i in range(self.fornum): - sql = "select ts , * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 ) where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "%s " % random.choice(self.order_u_where) - #sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) - - #3 select * from (select column\tag form stable where <\>\in\and\or order by ) - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 3-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(300) - self.cur1.execute(sql) - tdSql.query("select 3-1 from stable_1;") - for i in range(self.fornum): - sql = "select ts, " - sql += "%s " % random.choice(self.s_r_select) - sql += "from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.t_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(300) - self.cur1.execute(sql) - - # select ts,* from (select column\tag form stable1,stable2 where t1.ts = t2.ts and <\>\in\and\or order by ) - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 3-2 from stable_1;") - for i in range(self.fornum): - sql = "select ts , * from ( select t1.ts , " - sql += "t1.%s, " % random.choice(self.s_s_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.s_s_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "%s " % random.choice(self.order_u_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - # TD-15609 tdSql.query(sql) - # tdSql.checkRows(100) - #self.cur1.execute(sql) - - #3 outer union not support - self.restartDnodes() - tdSql.query("select 3-3 from stable_1;") - for i in range(self.fornum): - #sql = "select ts , * from ( select " - sql = "select ts from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ") union " - sql += "select ts from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(300) - self.cur1.execute(sql) - for i in range(self.fornum): - #sql = "select ts , * from ( select " - sql = "select ts from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ") union all " - sql += "select ts from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(600) - self.cur1.execute(sql) - - #3 inter union not support - tdSql.query("select 3-4 from stable_1;") - for i in range(self.fornum): - sql = "select ts , * from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += " %s " % random.choice(self.unionall_or_union) - sql += " select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from stable_2 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15837 tdSql.query(sql) - # self.cur1.execute(sql) - - #join:select * from (select column form stable1,stable2 where t1.ts=t2.ts and <\>\in\and\or order by) - tdSql.query("select 3-5 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_u_where) - sql += "%s " % random.choice(self.order_u_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - # TD-15609 tdSql.query(sql) - # tdSql.checkRows(100) - #self.cur1.execute(sql) - - tdSql.query("select 3-6 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t1.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.%s, " % random.choice(self.q_select) - sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - # TD-15609 同上 tdSql.query(sql) - # tdSql.checkRows(100) - #self.cur1.execute(sql) - - #4 select column from (select * form stable where <\>\in\and\or order by ) - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 4-1 from stable_1;") - for i in range(self.fornum): - sql = "select ts , " - sql += "%s, " % random.choice(self.q_select) - sql += "%s, " % random.choice(self.q_select) - sql += "%s " % random.choice(self.t_select) - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(300) - self.cur1.execute(sql) - - #5 select distinct column\tag from (select * form stable where <\>\in\and\or order by limit offset ) - tdSql.query("select 5-1 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.dqt_select) - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15500 tdSql.query(sql) - #self.cur1.execute(sql) - - #5-1 select distinct column\tag from (select calc form stable where <\>\in\and\or order by limit offset ) - tdSql.query("select 5-2 from stable_1;") - for i in range(self.fornum): - sql = "select distinct c5_1 " - sql += " from ( select " - sql += "%s " % random.choice(self.calc_select_in_ts) - sql += " as c5_1 from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - #sql += "%s " % random.choice(order_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - #tdSql.checkRows(1)有的函数还没有提交,会不返回结果,先忽略 - self.cur1.execute(sql) - - #6-error select * from (select distinct(tag) form stable where <\>\in\and\or order by limit ) - tdSql.query("select 6-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.dt_select) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) - tdSql.query("select 6-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.dt_select) - sql += " from stable_1 where " - sql += "%s ) ;" % random.choice(self.qt_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - #7-error select * from (select distinct(tag) form stable where <\>\in\and\or order by limit ) - tdSql.query("select 7-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.dq_select) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice([self.limit_where[0] , self.limit_where[1]] ) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) #distinct 和 order by 不能混合使用 - tdSql.query("select 7-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.dq_select) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - #sql += "%s " % random.choice(order_desc_where) - sql += "%s " % random.choice([self.limit_where[0] , self.limit_where[1]] ) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(1) - self.cur1.execute(sql) - - #calc_select,TWA/Diff/Derivative/Irate are not allowed to apply to super table directly - #8 select * from (select ts,calc form ragular_table where <\>\in\and\or order by ) - - # dcDB = self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 8-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select ts ," - sql += "%s " % random.choice(self.calc_select_support_ts) - sql += "from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) # 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function - self.cur1.execute(sql) - tdSql.query("select 8-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.calc_select_not_support_ts) - sql += "from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) # 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function - #self.cur1.execute(sql) - - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.calc_select_in_ts) - sql += "from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 8-2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select t1.ts, " - sql += "%s " % random.choice(self.calc_select_in_support_ts_j) - sql += "from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql)# 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function - self.cur1.execute(sql) - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.calc_select_in_not_support_ts_j) - sql += "from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - ##top返回结果有问题 tdSql.checkRows(1) - #self.cur1.execute(sql) - - #9 select * from (select ts,calc form stable where <\>\in\and\or order by ) - # self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 9-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.calc_select_not_support_ts) - sql += "from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - # self.cur1.execute(sql) - tdSql.query("select 9-2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select ts ," - sql += "%s " % random.choice(self.calc_select_support_ts) - sql += "from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 9-3 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.calc_select_in_not_support_ts_j) - sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += " and %s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - #self.cur1.execute(sql) - tdSql.query("select 9-4 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select t1.ts," - sql += "%s " % random.choice(self.calc_select_in_support_ts_j) - sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += " and %s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - #10 select calc from (select * form regualr_table where <\>\in\and\or order by ) - tdSql.query("select 10-1 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.calc_select_in_ts) - sql += "as calc10_1 from ( select * from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(1) - self.cur1.execute(sql) - - #10-1 select calc from (select * form regualr_table where <\>\in\and\or order by ) - # rsDn = self.restartDnodes() - # self.dropandcreateDB_random("%s" %db, 1) - # rsDn = self.restartDnodes() - tdSql.query("select 10-2 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.calc_select_all) - sql += "as calc10_2 from ( select * from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - # tdSql.checkRows(1) - #self.cur1.execute(sql) - - #10-2 select calc from (select * form regualr_tables where <\>\in\and\or order by ) - tdSql.query("select 10-3 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s as calc10_3 " % random.choice(self.calc_select_all) - sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += " and %s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - sql += "%s ;" % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 10-4 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s as calc10_4 " % random.choice(self.calc_select_all) - sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_or_where) - sql += " and %s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - # tdSql.checkRows(1) - #self.cur1.execute(sql) - - #11 select calc from (select * form stable where <\>\in\and\or order by limit ) - tdSql.query("select 11-1 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.calc_select_in_ts) - sql += "as calc11_1 from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - tdSql.checkRows(1) - self.cur1.execute(sql) - - #11-1 select calc from (select * form stable where <\>\in\and\or order by limit ) - tdSql.query("select 11-2 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.calc_select_all) - sql += "as calc11_1 from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - #self.cur1.execute(sql) - #不好计算结果 tdSql.checkRows(1) - - #11-2 select calc from (select * form stables where <\>\in\and\or order by limit ) - tdSql.query("select 11-3 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.calc_select_all) - sql += "as calc11_1 from ( select * from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 11-4 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.calc_select_all) - sql += "as calc11_1 from ( select * from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - #self.cur1.execute(sql) - - #12 select calc-diff from (select * form regualr_table where <\>\in\and\or order by limit ) - ##self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 12-1 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.calc_calculate_regular) - sql += " from ( select * from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - ##目前derivative不支持 tdSql.query(sql) - # tdSql.checkRows(1) - #self.cur1.execute(sql) - - tdSql.query("select 12-2 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.calc_calculate_regular) - sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #目前derivative不支持 tdSql.query(sql) - # tdSql.checkRows(1) - #self.cur1.execute(sql) - - tdSql.query("select 12-2.2 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.calc_calculate_regular) - sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #目前derivative不支持 tdSql.query(sql) - #self.cur1.execute(sql) - - #12-1 select calc-diff from (select * form stable where <\>\in\and\or order by limit ) - tdSql.query("select 12-3 from stable_1;") - self.restartDnodes() - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.calc_calculate_regular) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.group_where) - sql += ") " - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #目前derivative不支持 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 12-4 from stable_1;") - #join query does not support group by - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.calc_calculate_regular_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "%s " % random.choice(self.group_where_j) - sql += ") " - #sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) 目前de函数不支持,另外看看需要不需要将group by和pari by分开 - #self.cur1.execute(sql) - - tdSql.query("select 12-5 from stable_1;") - #join query does not support group by - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.calc_calculate_regular_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.group_where_j) - sql += ") " - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #derivative not support tdSql.query(sql) - #self.cur1.execute(sql) - - - #13 select calc-diff as diffns from (select * form stable where <\>\in\and\or order by limit ) - tdSql.query("select 13-1 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.calc_calculate_regular) - sql += " as calc13_1 from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.orders_desc_where) - sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #derivative not support tdSql.query(sql) - #self.cur1.execute(sql) - - #14 select * from (select calc_aggregate_alls as agg from stable where <\>\in\and\or group by order by slimit soffset ) - # TD-5955 select * from ( select count (q_double) from stable_1 where t_bool = true or t_bool = false group by loc order by ts asc slimit 1 ) ; - tdSql.query("select 14-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all) - sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all) - sql += "%s " % random.choice(self.calc_aggregate_all) - sql += " as calc14_3 from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.group_where) - sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15678 tdSql.query(sql) - # tdSql.checkRows(1) - #self.cur1.execute(sql) - - # error group by in out query - tdSql.query("select 14-2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all) - sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all) - sql += "%s " % random.choice(self.calc_aggregate_all) - sql += " as calc14_3 from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.group_where) - sql += "%s " % random.choice(self.having_support) - sql += "%s " % random.choice(self.orders_desc_where) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") " - sql += "%s " % random.choice(self.group_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15678 tdSql.query(sql) - # tdSql.checkRows(1) - #self.cur1.execute(sql) - - #14-2 select * from (select calc_aggregate_all_js as agg from stables where <\>\in\and\or group by order by slimit soffset ) - tdSql.query("select 14-3 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all_j) - sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all_j) - sql += "%s " % random.choice(self.calc_aggregate_all_j) - sql += " as calc14_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "%s " % random.choice(self.partiton_where_j) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") " - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 14-4 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all_j) - sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all_j) - sql += "%s " % random.choice(self.calc_aggregate_all_j) - sql += " as calc14_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.partiton_where_j) - sql += "%s " % random.choice(self.slimit1_where) - sql += ") " - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - #15 select * from (select calc_aggregate_regulars as agg from regular_table where <\>\in\and\or order by slimit soffset ) - tdSql.query("select 15-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_regular) - sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_regular) - sql += "%s " % random.choice(self.calc_aggregate_regular) - sql += " as calc15_3 from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.group_where_regular) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #Invalid function name: twa' - # tdSql.checkRows(1) - #self.cur1.execute(sql) - - tdSql.query("select 15-2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_regular_j) - sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_regular_j) - sql += "%s " % random.choice(self.calc_aggregate_regular_j) - sql += " as calc15_3 from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "%s " % random.choice(self.group_where_regular_j) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #Invalid function name: twa' - #self.cur1.execute(sql) - - tdSql.query("select 15-2.2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_regular_j) - sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_regular_j) - sql += "%s " % random.choice(self.calc_aggregate_regular_j) - sql += " as calc15_3 from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.group_where_regular_j) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - sql += "%s ;" % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #Invalid function name: twa' - #self.cur1.execute(sql) - - self.restartDnodes() - tdSql.query("select 15-3 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_groupbytbname) - sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_groupbytbname) - sql += "%s " % random.choice(self.calc_aggregate_groupbytbname) - sql += " as calc15_3 from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.group_where) - sql += "%s " % random.choice(self.having_support) - sql += "%s " % random.choice(self.order_desc_where) - sql += ") " - sql += "order by calc15_1 " - sql += "%s " % random.choice(self.limit_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #Invalid function name: twa',可能还的去掉order by - #self.cur1.execute(sql) - - tdSql.query("select 15-4 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_groupbytbname_j) - sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_groupbytbname_j) - sql += "%s " % random.choice(self.calc_aggregate_groupbytbname_j) - sql += " as calc15_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "%s " % random.choice(self.group_where_j) - sql += "%s " % random.choice(self.having_support_j) - #sql += "%s " % random.choice(orders_desc_where) - sql += ") " - sql += "order by calc15_1 " - sql += "%s " % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #'Invalid function name: irate' - #self.cur1.execute(sql) - - tdSql.query("select 15-4.2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_groupbytbname_j) - sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_groupbytbname_j) - sql += "%s " % random.choice(self.calc_aggregate_groupbytbname_j) - sql += " as calc15_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.group_where_j) - sql += "%s " % random.choice(self.having_support_j) - sql += "%s " % random.choice(self.orders_desc_where) - sql += ") " - sql += "order by calc15_1 " - sql += "%s " % random.choice(self.limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15678 #tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 15-5 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_groupbytbname) - sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_groupbytbname) - sql += "%s " % random.choice(self.calc_aggregate_groupbytbname) - sql += " as calc15_3 from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.group_where) - sql += ") " - sql += "order by calc15_1 " - sql += "%s " % random.choice(self.limit_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql) #'Invalid function name: irate' - #self.cur1.execute(sql) - - #16 select * from (select calc_aggregate_regulars as agg from regular_table where <\>\in\and\or order by limit offset ) - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 16-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_0 , " % random.choice(self.calc_calculate_all) - sql += "%s as calc16_1 , " % random.choice(self.calc_aggregate_all) - sql += "%s as calc16_2 " % random.choice(self.calc_select_in) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.group_where) - #sql += "%s " % random.choice(having_support)having和 partition不能混合使用 - sql += ") " - sql += "order by calc16_0 " - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 16-2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_0 " % random.choice(self.calc_calculate_all_j) - sql += ", %s as calc16_1 " % random.choice(self.calc_aggregate_all_j) - #sql += ", %s as calc16_2 " % random.choice(self.calc_select_in_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += ") " - sql += "order by calc16_0 " - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 16-2.2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_0 " % random.choice(self.calc_calculate_all_j) - sql += ", %s as calc16_1 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.qt_u_or_where) - sql += ") " - sql += "order by calc16_0 " - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 16-3 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(self.calc_calculate_regular) - sql += " from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "limit 2 ) " - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql)#Invalid function name: derivative' - #self.cur1.execute(sql) - - tdSql.query("select 16-4 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(self.calc_calculate_regular_j) - sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "limit 2 ) " - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql)#Invalid function name: derivative' - #self.cur1.execute(sql) - - tdSql.query("select 16-4.2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(self.calc_calculate_regular_j) - sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_or_where) - sql += "limit 2 ) " - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #tdSql.query(sql)#Invalid function name: derivative' - #self.cur1.execute(sql) - - tdSql.query("select 16-5 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 , " % random.choice(self.calc_calculate_all) - sql += "%s as calc16_1 , " % random.choice(self.calc_calculate_regular) - sql += "%s as calc16_2 " % random.choice(self.calc_select_all) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.group_where) - #sql += "%s " % random.choice(having_support) - sql += ") " - sql += "order by calc16_1 " - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - # tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 16-6 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(self.calc_calculate_groupbytbname) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.group_where) - sql += "limit 2 ) " - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #Invalid function name: derivative' tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 16-7 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(self.calc_calculate_groupbytbname_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "limit 2 ) " - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #Invalid function name: derivative' tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 16-8 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(self.calc_calculate_groupbytbname_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.qt_u_or_where) - sql += "limit 2 ) " - sql += "%s " % random.choice(self.limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) - #Invalid function name: derivative' tdSql.query(sql) - #self.cur1.execute(sql) - - #17 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or interval_sliding group by having order by limit offset )interval_sliding - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 17-1 from stable_1;") - for i in range(self.fornum): - #this is having_support , but tag-select cannot mix with last_row,other select can - sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_0 , " % random.choice(self.calc_calculate_all) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.partiton_where) - sql += "%s " % random.choice(self.interval_sliding) - #sql += "%s " % random.choice(having_support) - #sql += "%s " % random.choice(order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 17-2 from stable_1;") - for i in range(self.fornum): - #this is having_support , but tag-select cannot mix with last_row,other select can - sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_0 , " % random.choice(self.calc_calculate_all_j) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "%s " % random.choice(self.interval_sliding) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 17-2.2 from stable_1;") - for i in range(self.fornum): - #this is having_support , but tag-select cannot mix with last_row,other select can - sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_0 , " % random.choice(self.calc_calculate_all_j) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.interval_sliding) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - self.restartDnodes() - tdSql.query("select 17-3 from stable_1;") - for i in range(self.fornum): - #this is having_tagnot_support , because tag-select cannot mix with last_row... - sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.partiton_where) - sql += "%s " % random.choice(self.interval_sliding) - #sql += "%s " % random.choice(self.having_tagnot_support) - #sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 17-4 from stable_1;") - for i in range(self.fornum): - #this is having_tagnot_support , because tag-select cannot mix with last_row... - sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "%s " % random.choice(self.interval_sliding) - #sql += "%s " % random.choice(order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 17-4.2 from stable_1;") - for i in range(self.fornum): - #this is having_tagnot_support , because tag-select cannot mix with last_row... - sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.interval_sliding) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 17-5 from stable_1;") - for i in range(self.fornum): - #having_not_support - sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.partiton_where) - sql += "%s " % random.choice(self.interval_sliding) - # sql += "%s " % random.choice(self.having_not_support) - # sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 17-6 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.interval_sliding) - #sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 17-7 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "%s " % random.choice(self.interval_sliding) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 17-7.2 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.interval_sliding) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - self.restartDnodes() - tdSql.query("select 17-8 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) - sql += " from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.interval_sliding) - #sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 17-9 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "%s " % random.choice(self.interval_sliding) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 17-10 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.interval_sliding) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - #18 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or session order by limit )interval_sliding - tdSql.query("select 18-1 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all) - sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all) - sql += " from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.session_where) - #sql += "%s " % random.choice(self.fill_where) - #sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 18-2 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "%s " % random.choice(self.session_u_where) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 18-2.2 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.session_u_where) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - self.restartDnodes() - tdSql.query("select 18-3 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all) - sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all) - sql += " from stable_1_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.session_where) - #sql += "%s " % random.choice(self.fill_where) - #sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 18-4 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "%s " % random.choice(self.session_u_where) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 18-4.2 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.session_u_where) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 18-5 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all) - sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.session_where) - #sql += "%s " % random.choice(self.fill_where) - #sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 18-6 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.t_join_where) - sql += "%s " % random.choice(self.session_u_where) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 18-7 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.session_u_where) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - #19 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or session order by limit )interval_sliding - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 19-1 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all) - sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all) - sql += " from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.state_window) - #sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 19-2 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - sql += "%s " % random.choice(self.state_u_window) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 19-2.2 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_or_where) - sql += "%s " % random.choice(self.state_u_window) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 19-3 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all) - sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all) - sql += " from stable_1_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.state_window) - #sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 19-4 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - #sql += "%s " % random.choice(self.state_window) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 19-4.2 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_or_where) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 19-5 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all) - sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += "%s " % random.choice(self.state_window) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit1_where) - sql += ") " - sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) #'STATE_WINDOW not support for super table query' - - tdSql.query("select 19-6 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.q_u_where) - #sql += "%s " % random.choice(self.state_window) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - tdSql.query("select 19-7 from stable_1;") - for i in range(self.fornum): - sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) - sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(self.qt_u_or_where) - #sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - #sql += "%s " % random.choice(self.interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - #20 select * from (select calc_select_fills form regualr_table or stable where <\>\in\and\or fill_where group by order by limit offset ) - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 20-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(self.calc_select_fill) - sql += "%s ," % random.choice(self.calc_select_fill) - sql += "%s " % random.choice(self.calc_select_fill) - sql += " from stable_1 where " - sql += "%s " % random.choice(self.interp_where) - sql += "%s " % random.choice(self.fill_where) - sql += "%s " % random.choice(self.group_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - #interp不支持 tdSql.query(sql) - #self.cur1.execute(sql) - - rsDn = self.restartDnodes() - tdSql.query("select 20-2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(self.calc_select_fill_j) - sql += "%s ," % random.choice(self.calc_select_fill_j) - sql += "%s " % random.choice(self.calc_select_fill_j) - sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s and " % random.choice(self.t_join_where) - sql += "%s " % random.choice(self.interp_where_j) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - #interp不支持 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 20-2.2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(self.calc_select_fill_j) - sql += "%s ," % random.choice(self.calc_select_fill_j) - sql += "%s " % random.choice(self.calc_select_fill_j) - sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s and " % random.choice(self.qt_u_or_where) - sql += "%s " % random.choice(self.interp_where_j) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - #interp不支持 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 20-3 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(self.calc_select_fill) - sql += "%s ," % random.choice(self.calc_select_fill) - sql += "%s " % random.choice(self.calc_select_fill) - sql += " from stable_1 where " - sql += "%s " % self.interp_where[2] - sql += "%s " % random.choice(self.fill_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - #interp不支持 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 20-4 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(self.calc_select_fill_j) - sql += "%s ," % random.choice(self.calc_select_fill_j) - sql += "%s " % random.choice(self.calc_select_fill_j) - sql += " from stable_1 t1, table_1 t2 where t1.ts = t2.ts and " - #sql += "%s and " % random.choice(self.t_join_where) - sql += "%s " % self.interp_where_j[random.randint(0,5)] - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - #interp不支持 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 20-4.2 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(self.calc_select_fill_j) - sql += "%s ," % random.choice(self.calc_select_fill_j) - sql += "%s " % random.choice(self.calc_select_fill_j) - sql += " from stable_1 t1, stable_1_1 t2 where t1.ts = t2.ts and " - sql += "%s and " % random.choice(self.qt_u_or_where) - sql += "%s " % self.interp_where_j[random.randint(0,5)] - sql += "%s " % random.choice(self.fill_where) - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - ##interp不支持 tdSql.error(sql) - #self.cur1.execute(sql) - - tdSql.query("select 20-5 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(self.calc_select_fill) - sql += "%s ," % random.choice(self.calc_select_fill) - sql += "%s " % random.choice(self.calc_select_fill) - sql += " from regular_table_1 where " - sql += "%s " % self.interp_where[1] - sql += "%s " % random.choice(self.fill_where) - sql += "%s " % random.choice(self.order_where) - sql += "%s " % random.choice(self.limit_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - ##interp不支持 tdSql.query(sql) - #self.cur1.execute(sql) - - tdSql.query("select 20-6 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s , " % random.choice(self.calc_select_fill_j) - sql += "%s ," % random.choice(self.calc_select_fill_j) - sql += "%s " % random.choice(self.calc_select_fill_j) - sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - #sql += "%s " % random.choice(self.interp_where_j) - sql += "%s " % self.interp_where_j[random.randint(0,5)] - sql += "%s " % random.choice(self.order_u_where) - sql += "%s " % random.choice(self.limit_u_where) - sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) - ##interp不支持 tdSql.query(sql) - #self.cur1.execute(sql) - - #1 select * from (select * from (select * form regular_table where <\>\in\and\or order by limit )) - tdSql.query("select 1-1 from stable_1;") - for i in range(self.fornum): - # sql_start = "select * from ( " - # sql_end = ")" - for_num = random.randint(1, 15); - sql = "select * from (" * for_num - sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - sql2 = "select * from ( select * from ( select " - sql2 += "%s, " % random.choice(self.s_r_select) - sql2 += "%s, " % random.choice(self.q_select) - sql2 += "ts from regular_table_1 where " - sql2 += "%s " % random.choice(self.q_where) - sql2 += ")) " - tdLog.info(sql2) - tdLog.info(len(sql2)) - tdSql.query(sql2) - self.cur1.execute(sql2) - - self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql2 ,1,10,1,1) - self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql ,1,10,3,3) - self.data_matrix_equal('%s' %sql ,1,10,3,3,'%s' %sql2 ,1,10,3,3) - - for i in range(self.fornum): - for_num = random.randint(1, 15); - sql = "select ts from (" * for_num - sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(self.s_r_select) - sql += "%s, " % random.choice(self.q_select) - sql += "ts from regular_table_1 where " - sql += "%s " % random.choice(self.q_where) - sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - sql2 = "select * from ( select * from ( select " - sql2 += "%s, " % random.choice(self.s_r_select) - sql2 += "%s, " % random.choice(self.q_select) - sql2 += "ts from regular_table_1 where " - sql2 += "%s " % random.choice(self.q_where) - sql2 += ")) " - tdLog.info(sql2) - tdLog.info(len(sql2)) - tdSql.query(sql2) - self.cur1.execute(sql2) - - self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql2 ,1,10,1,1) - - #2 select * from (select * from (select * form stable where <\>\in\and\or order by limit )) - tdSql.query("select 2-1 from stable_1;") - for i in range(self.fornum): - for_num = random.randint(1, 15); - sql = "select * from (" * for_num - sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.qt_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - sql2 = "select * from ( select * from ( select " - sql2 += "%s, " % random.choice(self.s_s_select) - sql2 += "%s, " % random.choice(self.qt_select) - sql2 += "ts from stable_1 where " - sql2 += "%s " % random.choice(self.q_where) - sql2 += ")) " - tdLog.info(sql2) - tdLog.info(len(sql2)) - tdSql.query(sql2) - self.cur1.execute(sql2) - - self.data_matrix_equal('%s' %sql ,1,10,3,3,'%s' %sql2 ,1,10,3,3) - - for i in range(self.fornum): - for_num = random.randint(1, 15); - sql = "select ts from (" * for_num - sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(self.s_s_select) - sql += "%s, " % random.choice(self.qt_select) - sql += "ts from stable_1 where " - sql += "%s " % random.choice(self.q_where) - sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - sql2 = "select ts from ( select * from ( select " - sql2 += "%s, " % random.choice(self.s_s_select) - sql2 += "%s, " % random.choice(self.qt_select) - sql2 += "ts from stable_1 where " - sql2 += "%s " % random.choice(self.q_where) - sql2 += ")) " - tdLog.info(sql2) - tdLog.info(len(sql2)) - tdSql.query(sql2) - self.cur1.execute(sql2) - - self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql2 ,1,10,1,1) - - #3 select ts ,calc from (select * form stable where <\>\in\and\or order by limit ) - #self.dropandcreateDB_random("%s" %db, 1) - tdSql.query("select 3-1 from stable_1;") - for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(self.calc_calculate_regular) - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.orders_desc_where) - sql += "%s " % random.choice(self.limit_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #'Invalid function name: derivative' tdSql.query(sql) - #self.cur1.execute(sql) - - #4 select * from (select calc form stable where <\>\in\and\or order by limit ) - tdSql.query("select 4-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s " % random.choice(self.calc_select_in_ts) - sql += "from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - #sql += "%s " % random.choice(self.order_desc_where) - sql += "%s " % random.choice(self.limit_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - self.cur1.execute(sql) - - #5 select ts ,tbname from (select * form stable where <\>\in\and\or order by limit ) - tdSql.query("select 5-1 from stable_1;") - for i in range(self.fornum): - sql = "select ts , tbname , " - sql += "%s ," % random.choice(self.calc_calculate_regular) - sql += "%s ," % random.choice(self.dqt_select) - sql += "%s " % random.choice(self.qt_select) - sql += " from ( select * from stable_1 where " - sql += "%s " % random.choice(self.qt_where) - sql += "%s " % random.choice(self.orders_desc_where) - sql += "%s " % random.choice(self.limit_where) - sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) - - #special sql - tdSql.query("select 6-1 from stable_1;") - for i in range(self.fornum): - sql = "select * from ( select _block_dist() from stable_1);" - # tdSql.query(sql) - # tdSql.checkRows(1) - sql = "select _block_dist() from (select * from stable_1);" - tdSql.error(sql) - sql = "select * from (select database());" - tdSql.error(sql) - sql = "select * from (select client_version());" - tdSql.error(sql) - sql = "select * from (select client_version() as version);" - tdSql.error(sql) - sql = "select * from (select server_version());" - tdSql.error(sql) - sql = "select * from (select server_version() as version);" - tdSql.error(sql) - sql = "select * from (select server_status());" - tdSql.error(sql) - sql = "select * from (select server_status() as status);" - tdSql.error(sql) - - #taos -f sql - startTime_taos_f = time.time() - print("taos -f sql start!") - taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) - _ = subprocess.check_output(taos_cmd1, shell=True).decode("utf-8") - print("taos -f sql over!") - endTime_taos_f = time.time() - print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) - - print('=====================2.6 old function end ===========') - +from .nestedQuery import * +class TDTestCase(TDTestCase): + def run(self): tdSql.prepare() + + startTime = time.time() - startTime = time.time() - - # - - - #self.math_nest(['TAIL']) #TD-16009 - # self.math_nest(['HYPERLOGLOG']) #TD-16038 + # self.function_before_26() + # self.math_nest(['UNIQUE']) - - - - # # - #self.function_before_26() #TD-16031 - - # self.math_nest(['ABS','SQRT']) #TD-16042 - # self.math_nest(['SIN','COS','TAN','ASIN','ACOS','ATAN']) - # self.math_nest(['POW','LOG']) #TD-16039 - # self.math_nest(['FLOOR','CEIL','ROUND']) - # #self.math_nest(['SAMPLE']) #TD-16017 - # #self.math_nest(['CSUM']) #TD-15936 crash - # self.math_nest(['MAVG']) - - self.str_nest(['LTRIM','RTRIM','LOWER','UPPER']) - self.str_nest(['LENGTH','CHAR_LENGTH']) - self.str_nest(['SUBSTR']) #TD-16042 - self.str_nest(['CONCAT']) #TD-16002 偶尔 - self.str_nest(['CONCAT_WS']) #TD-16002 偶尔 - # self.time_nest(['CAST']) #TD-16017偶尔,放到time里起来弄 - self.time_nest(['CAST_1']) - self.time_nest(['CAST_2']) - self.time_nest(['CAST_3']) - self.time_nest(['CAST_4']) - - - - # self.time_nest(['NOW','TODAY']) # - # self.time_nest(['TIMEZONE']) # - # self.time_nest(['TIMETRUNCATE']) #TD-16039 + # self.math_nest(['MODE']) + # self.math_nest(['SAMPLE']) + + # self.math_nest(['ABS','SQRT']) + # self.math_nest(['SIN','COS','TAN','ASIN','ACOS','ATAN']) + # self.math_nest(['POW','LOG']) + # self.math_nest(['FLOOR','CEIL','ROUND']) + # self.math_nest(['MAVG']) + # self.math_nest(['HYPERLOGLOG']) + # self.math_nest(['TAIL']) + # self.math_nest(['CSUM']) + # self.math_nest(['statecount','stateduration']) + # self.math_nest(['HISTOGRAM']) + + self.str_nest(['LTRIM','RTRIM','LOWER','UPPER']) + self.str_nest(['LENGTH','CHAR_LENGTH']) + self.str_nest(['SUBSTR']) + self.str_nest(['CONCAT']) + self.str_nest(['CONCAT_WS']) + # self.time_nest(['CAST']) #放到time里起来弄 + # self.time_nest(['CAST_1']) + # self.time_nest(['CAST_2']) + # self.time_nest(['CAST_3']) + # self.time_nest(['CAST_4']) + + + + # self.time_nest(['NOW','TODAY']) + # self.time_nest(['TIMEZONE']) + # self.time_nest(['TIMETRUNCATE']) # self.time_nest(['TO_ISO8601']) - # self.time_nest(['TO_UNIXTIMESTAMP'])#core多 + # self.time_nest(['TO_UNIXTIMESTAMP']) # self.time_nest(['ELAPSED']) - + # self.time_nest(['TIMEDIFF_1']) + # self.time_nest(['TIMEDIFF_2']) + endTime = time.time() print("total time %ds" % (endTime - startTime)) - + def stop(self): diff --git a/tests/system-test/2-query/nestedQuery_time.py b/tests/system-test/2-query/nestedQuery_time.py new file mode 100755 index 0000000000000000000000000000000000000000..65eab3436e8dc7b97496a29f9353f60fbdabe525 --- /dev/null +++ b/tests/system-test/2-query/nestedQuery_time.py @@ -0,0 +1,76 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- +from util.cases import tdCases +from .nestedQuery import * + +class TDTestCase(TDTestCase): + + + def run(self): + tdSql.prepare() + + startTime = time.time() + + # self.function_before_26() + + # self.math_nest(['UNIQUE']) + # self.math_nest(['MODE']) + # self.math_nest(['SAMPLE']) + + # self.math_nest(['ABS','SQRT']) + # self.math_nest(['SIN','COS','TAN','ASIN','ACOS','ATAN']) + # self.math_nest(['POW','LOG']) + # self.math_nest(['FLOOR','CEIL','ROUND']) + # self.math_nest(['MAVG']) + # self.math_nest(['HYPERLOGLOG']) + # self.math_nest(['TAIL']) + # self.math_nest(['CSUM']) + # self.math_nest(['statecount','stateduration']) + # self.math_nest(['HISTOGRAM']) + + # self.str_nest(['LTRIM','RTRIM','LOWER','UPPER']) + # self.str_nest(['LENGTH','CHAR_LENGTH']) + # self.str_nest(['SUBSTR']) + # self.str_nest(['CONCAT']) + # self.str_nest(['CONCAT_WS']) + # self.time_nest(['CAST']) #放到time里起来弄 + # self.time_nest(['CAST_1']) + # self.time_nest(['CAST_2']) + # self.time_nest(['CAST_3']) + # self.time_nest(['CAST_4']) + + + + self.time_nest(['NOW','TODAY']) + self.time_nest(['TIMEZONE']) + self.time_nest(['TIMETRUNCATE']) + self.time_nest(['TO_ISO8601']) + self.time_nest(['TO_UNIXTIMESTAMP']) + self.time_nest(['ELAPSED']) + #self.time_nest(['TIMEDIFF_1']) + #self.time_nest(['TIMEDIFF_2']) + + + endTime = time.time() + print("total time %ds" % (endTime - startTime)) + + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/stablity.py b/tests/system-test/2-query/stablity.py new file mode 100755 index 0000000000000000000000000000000000000000..b4343359702e0af4e5a9e2b9f29cba1700f8be35 --- /dev/null +++ b/tests/system-test/2-query/stablity.py @@ -0,0 +1,4935 @@ +################################################################### +# 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 random +import os +import time +import taos +import subprocess +from faker import Faker +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +from util.dnodes import tdDnodes +from util.dnodes import * + +class TDTestCase: + updatecfgDict = {'maxSQLLength':1048576,'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, + "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"fnDebugFlag":143} + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + self.testcasePath = os.path.split(__file__)[0] + self.testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + self.num = 10 + self.fornum = 5 + + self.db_nest = "stab" + self.dropandcreateDB_random("%s" %self.db_nest, 1) + + # regular column select + self.q_select= ['q_int', 'q_bigint' , 'q_bigint' , 'q_smallint' , 'q_tinyint' , 'q_bool' , 'q_binary' , 'q_nchar' ,'q_float' , 'q_double' ,'q_ts ', 'q_int_null ', 'q_bigint_null ' , 'q_bigint_null ' , 'q_smallint_null ' , 'q_tinyint_null ' , 'q_bool_null ' , 'q_binary_null ' , 'q_nchar_null ' ,'q_float_null ' , 'q_double_null ' ,'q_ts_null '] + + # tag column select + self.t_select= ['loc','t_int', 't_bigint' , 't_bigint' , 't_smallint' , 't_tinyint' , 't_bool' , 't_binary' , 't_nchar' ,'t_float' , 't_double' ,'t_ts '] + + # regular and tag column select + self.qt_select= self.q_select + self.t_select + + # distinct regular column select + self.dq_select= ['distinct q_int', 'distinct q_bigint' , 'distinct q_smallint' , 'distinct q_tinyint' , + 'distinct q_bool' , 'distinct q_binary' , 'distinct q_nchar' ,'distinct q_float' , 'distinct q_double' ,'distinct q_ts '] + + # distinct tag column select + self.dt_select= ['distinct loc', 'distinct t_int', 'distinct t_bigint' , 'distinct t_smallint' , 'distinct t_tinyint' , + 'distinct t_bool' , 'distinct t_binary' , 'distinct t_nchar' ,'distinct t_float' , 'distinct t_double' ,'distinct t_ts '] + + # distinct regular and tag column select + self.dqt_select= self.dq_select + self.dt_select + + # special column select + self.s_r_select= ['_c0', '_rowts' , '_C0' ] + self.s_s_select= ['tbname' , '_rowts' , '_c0', '_C0' ] + self.unionall_or_union= [ ' union ' , ' union all ' ] + + # regular column where + self.q_where = ['ts < now +1s','q_bigint >= -9223372036854775807 and q_bigint <= 9223372036854775807', 'q_int <= 2147483647 and q_int >= -2147483647', + 'q_smallint >= -32767 and q_smallint <= 32767','q_tinyint >= -127 and q_tinyint <= 127','q_float >= -1.7E308 and q_float <= 1.7E308', + 'q_double >= -1.7E308 and q_double <= 1.7E308', 'q_binary like \'binary%\' or q_binary = \'0\' ' , 'q_nchar like \'nchar%\' or q_nchar = \'0\' ' , + 'q_bool = true or q_bool = false' , 'q_bool in (0 , 1)' , 'q_bool in ( true , false)' , 'q_bool = 0 or q_bool = 1', + 'q_bigint between -9223372036854775807 and 9223372036854775807',' q_int between -2147483647 and 2147483647','q_smallint between -32767 and 32767', + 'q_bigint not between 9223372036854775807 and -9223372036854775807','q_int not between 2147483647 and -2147483647','q_smallint not between 32767 and -32767', + 'q_tinyint between -127 and 127 ','q_float >= -3.4E38 ','q_float <= 3.4E38 ','q_double >= -1.7E308 ', + 'q_double <= 1.7E308 ','q_float between -3.4E38 and 3.4E38 ','q_double between -1.7E308 and 1.7E308 ' ,'q_float not between 3.4E38 and -3.4E38 ','q_double not between 1.7E308 and -1.7E308 ', + 'q_float is not null ' ,'q_double is not null ' ,'q_binary match \'binary\' ','q_binary nmatch \'binarynchar\' ','q_nchar match \'nchar\' ','q_nchar nmatch \'binarynchar\' ', + 'q_binary like \'binary%\' ','(q_binary like \'binary%\' or q_nchar = \'0\' or q_binary = \'binary_\' ) ','q_nchar like \'nchar%\' ','(q_nchar like \'nchar%\' or q_binary = \'0\' or q_nchar = \'nchar_\' ) ', + 'q_binary match \'[binary]\'','q_binary nmatch \'[binarynchar]\' ',] + #TD-6201 ,'q_bool between 0 and 1' + + # regular column where for test union,join + self.q_u_where = ['t1.ts < now +1s' , 't2.ts < now +1s','t1.q_bigint >= -9223372036854775807 and t1.q_bigint <= 9223372036854775807 and t2.q_bigint >= -9223372036854775807 and t2.q_bigint <= 9223372036854775807', + 't1.q_int <= 2147483647 and t1.q_int >= -2147483647 and t2.q_int <= 2147483647 and t2.q_int >= -2147483647', + 't1.q_smallint >= -32767 and t1.q_smallint <= 32767 and t2.q_smallint >= -32767 and t2.q_smallint <= 32767', + 't1.q_tinyint >= -127 and t1.q_tinyint <= 127 and t2.q_tinyint >= -127 and t2.q_tinyint <= 127', + 't1.q_float >= - 1.7E308 and t1.q_float <= 1.7E308 and t2.q_float >= - 1.7E308 and t2.q_float <= 1.7E308', + 't1.q_double >= - 1.7E308 and t1.q_double <= 1.7E308 and t2.q_double >= - 1.7E308 and t2.q_double <= 1.7E308', + 't1.q_binary like \'binary%\' and t2.q_binary like \'binary%\' ' , + 't1.q_nchar like \'nchar%\' and t2.q_nchar like \'nchar%\' ' , + 't1.q_bool in (0 , 1) and t2.q_bool in (0 , 1)' , 't1.q_bool in ( true , false) and t2.q_bool in ( true , false)' , + 't1.q_bigint between -9223372036854775807 and 9223372036854775807 and t2.q_bigint between -9223372036854775807 and 9223372036854775807', + 't1.q_int between -2147483647 and 2147483647 and t2.q_int between -2147483647 and 2147483647', + 't1.q_smallint between -32767 and 32767 and t2.q_smallint between -32767 and 32767', + 't1.q_tinyint between -127 and 127 and t2.q_tinyint between -127 and 127 ','t1.q_float between -1.7E308 and 1.7E308 and t2.q_float between -1.7E308 and 1.7E308', + 't1.q_double between -1.7E308 and 1.7E308 and t2.q_double between -1.7E308 and 1.7E308', + 't1.q_bigint not between 9223372036854775807 and -9223372036854775807 and t2.q_bigint not between 9223372036854775807 and -9223372036854775807', + 't1.q_int not between 2147483647 and -2147483647 and t2.q_int not between 2147483647 and -2147483647', + 't1.q_smallint not between 32767 and -32767 and t2.q_smallint not between 32767 and -32767', + 't1.q_tinyint not between 127 and -127 and t2.q_tinyint not between 127 and -127 ','t1.q_float not between -1.7E308 and -1.7E308 and t2.q_float not between 1.7E308 and -1.7E308', + 't1.q_double not between 1.7E308 and -1.7E308 and t2.q_double not between 1.7E308 and -1.7E308'] + #TD-6201 ,'t1.q_bool between 0 and 1 or t2.q_bool between 0 and 1'] + #'t1.q_bool = true and t1.q_bool = false and t2.q_bool = true and t2.q_bool = false' , 't1.q_bool = 0 and t1.q_bool = 1 and t2.q_bool = 0 and t2.q_bool = 1' , + + self.q_u_or_where = ['(t1.q_binary like \'binary%\' or t1.q_binary = \'0\' or t2.q_binary like \'binary%\' or t2.q_binary = \'0\' )' , + '(t1.q_nchar like \'nchar%\' or t1.q_nchar = \'0\' or t2.q_nchar like \'nchar%\' or t2.q_nchar = \'0\' )' , '(t1.q_bool = true or t1.q_bool = false or t2.q_bool = true or t2.q_bool = false)' , + '(t1.q_bool in (0 , 1) or t2.q_bool in (0 , 1))' , '(t1.q_bool in ( true , false) or t2.q_bool in ( true , false))' , '(t1.q_bool = 0 or t1.q_bool = 1 or t2.q_bool = 0 or t2.q_bool = 1)' , + '(t1.q_bigint between -9223372036854775807 and 9223372036854775807 or t2.q_bigint between -9223372036854775807 and 9223372036854775807)', + '(t1.q_int between -2147483647 and 2147483647 or t2.q_int between -2147483647 and 2147483647)', + '(t1.q_smallint between -32767 and 32767 or t2.q_smallint between -32767 and 32767)', + '(t1.q_tinyint between -127 and 127 or t2.q_tinyint between -127 and 127 )','(t1.q_float between -1.7E308 and 1.7E308 or t2.q_float between -1.7E308 and 1.7E308)', + '(t1.q_double between -1.7E308 and 1.7E308 or t2.q_double between -1.7E308 and 1.7E308)'] + + # tag column where + self.t_where = ['ts < now +1s','t_bigint >= -9223372036854775807 and t_bigint <= 9223372036854775807','t_int <= 2147483647 and t_int >= -2147483647', + 't_smallint >= -32767 and t_smallint <= 32767','q_tinyint >= -127 and t_tinyint <= 127','t_float >= -1.7E308 and t_float <= 1.7E308', + 't_double >= -1.7E308 and t_double <= 1.7E308', 't_binary like \'binary%\' or t_binary = \'0\' ' , 't_nchar like \'nchar%\' or t_nchar = \'0\'' , + 't_bool = true or t_bool = false' , 't_bool in (0 , 1)' , 't_bool in ( true , false)' , 't_bool = 0 or t_bool = 1', + 't_bigint between -9223372036854775807 and 9223372036854775807',' t_int between -2147483647 and 2147483647','t_smallint between -32767 and 32767', + 't_tinyint between -127 and 127 ','t_float between -1.7E308 and 1.7E308','t_double between -1.7E308 and 1.7E308', + 't_binary match \'binary\' ','t_binary nmatch \'binarynchar\' ','t_nchar match \'nchar\' ','t_nchar nmatch \'binarynchar\' ', + 't_binary like \'binary%\' ','t_nchar like \'nchar%\' ','(t_binary like \'binary%\' or t_nchar = \'0\' ) ','(t_nchar like \'nchar%\' or t_binary = \'0\' ) ', + 'tbname match \'[stable]\' ','tbname nmatch \'[qwwerrwee]\' ','loc match \'[stable]\' ','loc nmatch \'[qwwerrwee]\' ', + 'tbname match \'[^stable]\' ','tbname nmatch \'[^qwwerrwee]\' ','loc match \'[^stable]\' ','loc nmatch \'[^qwwerrwee]\' ',] + + # tag column where for test union,join | this is not support + self.t_u_where = ['t1.ts < now +1s' , 't2.ts < now +1s','t1.t_bigint >= -9223372036854775807 and t1.t_bigint <= 9223372036854775807 and t2.t_bigint >= -9223372036854775807 and t2.t_bigint <= 9223372036854775807', + 't1.t_int <= 2147483647 and t1.t_int >= -2147483647 and t2.t_int <= 2147483647 and t2.t_int >= -2147483647', + 't1.t_smallint >= -32767 and t1.t_smallint <= 32767 and t2.t_smallint >= -32767 and t2.t_smallint <= 32767', + 't1.t_tinyint >= -127 and t1.t_tinyint <= 127 and t2.t_tinyint >= -127 and t2.t_tinyint <= 127', + 't1.t_float >= -1.7E308 and t1.t_float <= 1.7E308 and t2.t_float >= -1.7E308 and t2.t_float <= 1.7E308', + 't1.t_double >= -1.7E308 and t1.t_double <= 1.7E308 and t2.t_double >= -1.7E308 and t2.t_double <= 1.7E308', + '(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\') ' , + '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , + 't1.t_bool in (0 , 1) and t2.t_bool in (0 , 1)' , 't1.t_bool in ( true , false) and t2.t_bool in ( true , false)' , '(t1.t_bool = 0 or t1.t_bool = 1 or t2.t_bool = 0 or t2.t_bool = 1)', + 't1.t_bigint between -9223372036854775807 and 9223372036854775807 and t2.t_bigint between -9223372036854775807 and 9223372036854775807', + 't1.t_int between -2147483647 and 2147483647 and t2.t_int between -2147483647 and 2147483647', + 't1.t_smallint between -32767 and 32767 and t2.t_smallint between -32767 and 32767', + '(t1.t_tinyint between -127 and 127 and t2.t_tinyint between -127 and 127) ','t1.t_float between -1.7E308 and 1.7E308 and t2.t_float between -1.7E308 and 1.7E308', + '(t1.t_double between -1.7E308 and 1.7E308 and t2.t_double between -1.7E308 and 1.7E308)', + '(t1.loc match \'[stable]\' and t2.loc match \'[stable]\')','(t1.loc nmatch \'[qqeqweq]\' and t2.loc nmatch \'[eqeqweq]\')', + '(t1.loc match \'[^stable]\' and t2.loc match \'[^stable]\')','(t1.loc nmatch \'[^qqeqweq]\' and t2.loc nmatch \'[^eqeqweq]\')', + '(t1.t_binary match \'[stable]\' and t2.t_binary match \'[stable]\')','(t1.t_binary nmatch \'[qqeqweq]\' and t2.t_binary nmatch \'[eqeqweq]\')', + '(t1.t_binary match \'[^stable]\' and t2.t_binary match \'[^stable]\')','(t1.t_binary nmatch \'[^qqeqweq]\' and t2.t_binary nmatch \'[^eqeqweq]\')', + '(t1.t_nchar match \'[stable]\' and t2.t_nchar match \'[stable]\')','(t1.t_nchar nmatch \'[qqeqweq]\' and t2.t_nchar nmatch \'[eqeqweq]\')', + '(t1.t_nchar match \'[^stable]\' and t2.t_nchar match \'[^stable]\')','(t1.t_nchar nmatch \'[^qqeqweq]\' and t2.t_nchar nmatch \'[^eqeqweq]\')'] + + self.t_u_or_where = ['(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\' )' , + '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , + '(t1.t_bool in (0 , 1) or t2.t_bool in (0 , 1))' , '(t1.t_bool in ( true , false) or t2.t_bool in ( true , false))' , '(t1.t_bool = 0 or t1.t_bool = 1 or t2.t_bool = 0 or t2.t_bool = 1)', + '(t1.t_bigint between -9223372036854775807 and 9223372036854775807 or t2.t_bigint between -9223372036854775807 and 9223372036854775807)', + '(t1.t_int between -2147483647 and 2147483647 or t2.t_int between -2147483647 and 2147483647)', + '(t1.t_smallint between -32767 and 32767 or t2.t_smallint between -32767 and 32767)', + '(t1.t_tinyint between -127 and 127 or t2.t_tinyint between -127 and 127 )','(t1.t_float between -1.7E308 and 1.7E308 or t2.t_float between -1.7E308 and 1.7E308)', + '(t1.t_double between -1.7E308 and 1.7E308 or t2.t_double between -1.7E308 and 1.7E308)', + '(t1.loc match \'[stable]\' or t2.loc match \'[stable]\')','(t1.loc nmatch \'[qqeqweq]\' or t2.loc nmatch \'[eqeqweq]\')', + '(t1.loc match \'[^stable]\' or t2.loc match \'[^stable]\')','(t1.loc nmatch \'[^qqeqweq]\' or t2.loc nmatch \'[^eqeqweq]\')' , + '(t1.t_binary match \'[stable]\' or t2.t_binary match \'[stable]\')','(t1.t_binary nmatch \'[qqeqweq]\' or t2.t_binary nmatch \'[eqeqweq]\')', + '(t1.t_binary match \'[^stable]\' or t2.t_binary match \'[^stable]\')','(t1.t_binary nmatch \'[^qqeqweq]\' or t2.t_binary nmatch \'[^eqeqweq]\')', + '(t1.t_nchar match \'[stable]\' or t2.t_nchar match \'[stable]\')','(t1.t_nchar nmatch \'[qqeqweq]\' or t2.t_nchar nmatch \'[eqeqweq]\')', + '(t1.t_nchar match \'[^stable]\' or t2.t_nchar match \'[^stable]\')','(t1.t_nchar nmatch \'[^qqeqweq]\' or t2.t_nchar nmatch \'[^eqeqweq]\')'] + + # regular and tag column where + self.qt_where = self.q_where + self.t_where + self.qt_u_where = self.q_u_where + self.t_u_where + self.qt_u_or_where = self.q_u_or_where + self.t_u_or_where + + # tag column where for test super join | this is support , 't1.t_bool = t2.t_bool ' ??? + self.t_join_where = ['t1.t_bigint = t2.t_bigint ', 't1.t_int = t2.t_int ', 't1.t_smallint = t2.t_smallint ', 't1.t_tinyint = t2.t_tinyint ', + 't1.t_float = t2.t_float ', 't1.t_double = t2.t_double ', 't1.t_binary = t2.t_binary ' , 't1.t_nchar = t2.t_nchar ' ] + + # session && fill + self.session_where = ['session(ts,10a)' , 'session(ts,10s)', 'session(ts,10m)' , 'session(ts,10h)','session(ts,10d)' , 'session(ts,10w)'] + self.session_u_where = ['session(t1.ts,10a)' , 'session(t1.ts,10s)', 'session(t1.ts,10m)' , 'session(t1.ts,10h)','session(t1.ts,10d)' , 'session(t1.ts,10w)', + 'session(t2.ts,10a)' , 'session(t2.ts,10s)', 'session(t2.ts,10m)' , 'session(t2.ts,10h)','session(t2.ts,10d)' , 'session(t2.ts,10w)'] + + self.fill_where = ['FILL(NONE)','FILL(PREV)','FILL(NULL)','FILL(LINEAR)','FILL(NEXT)','FILL(VALUE, 1.23)'] + + self.state_window = ['STATE_WINDOW(q_tinyint)','STATE_WINDOW(q_bigint)','STATE_WINDOW(q_int)','STATE_WINDOW(q_bool)','STATE_WINDOW(q_smallint)'] + self.state_u_window = ['STATE_WINDOW(t1.q_tinyint)','STATE_WINDOW(t1.q_bigint)','STATE_WINDOW(t1.q_int)','STATE_WINDOW(t1.q_bool)','STATE_WINDOW(t1.q_smallint)', + 'STATE_WINDOW(t2.q_tinyint)','STATE_WINDOW(t2.q_bigint)','STATE_WINDOW(t2.q_int)','STATE_WINDOW(t2.q_bool)','STATE_WINDOW(t2.q_smallint)'] + + # order by where + self.order_where = ['order by ts' , 'order by ts asc'] + self.order_u_where = ['order by t1.ts' , 'order by t1.ts asc' , 'order by t2.ts' , 'order by t2.ts asc'] + self.order_desc_where = ['order by ts' , 'order by ts asc' , 'order by ts desc' ] + self.orders_desc_where = ['order by ts' , 'order by ts asc' , 'order by ts desc' , 'order by ts,loc' , 'order by ts,loc asc' , 'order by ts,loc desc'] + + self.group_where = ['group by tbname , loc' , 'group by tbname', 'group by tbname, t_bigint', 'group by tbname,t_int', 'group by tbname, t_smallint', 'group by tbname,t_tinyint', + 'group by tbname,t_float', 'group by tbname,t_double' , 'group by tbname,t_binary', 'group by tbname,t_nchar', 'group by tbname,t_bool' ,'group by tbname ,loc ,t_bigint', + 'group by tbname,t_binary ,t_nchar ,t_bool' , 'group by tbname,t_int ,t_smallint ,t_tinyint' , 'group by tbname,t_float ,t_double ' , + 'PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', + 'PARTITION BY tbname,t_float', 'PARTITION BY tbname,t_double' , 'PARTITION BY tbname,t_binary', 'PARTITION BY tbname,t_nchar', 'PARTITION BY tbname,t_bool' ,'PARTITION BY tbname ,loc ,t_bigint', + 'PARTITION BY tbname,t_binary ,t_nchar ,t_bool' , 'PARTITION BY tbname,t_int ,t_smallint ,t_tinyint' , 'PARTITION BY tbname,t_float ,t_double '] + self.group_where_j = ['group by t1.loc' , 'group by t1.t_bigint', 'group by t1.t_int', 'group by t1.t_smallint', 'group by t1.t_tinyint', + 'group by t1.t_float', 'group by t1.t_double' , 'group by t1.t_binary', 'group by t1.t_nchar', 'group by t1.t_bool' ,'group by t1.loc ,t1.t_bigint', + 'group by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'group by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'group by t1.t_float ,t1.t_double ' , + 'PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', + 'PARTITION by t1.t_float', 'PARTITION by t1.t_double' , 'PARTITION by t1.t_binary', 'PARTITION by t1.t_nchar', 'PARTITION by t1.t_bool' ,'PARTITION BY t1.loc ,t1.t_bigint', + 'PARTITION by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'PARTITION by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'PARTITION by t1.t_float ,t1.t_double ', + 'group by t2.loc' , 'group by t2.t_bigint', 'group by t2.t_int', 'group by t2.t_smallint', 'group by t2.t_tinyint', + 'group by t2.t_float', 'group by t2.t_double' , 'group by t2.t_binary', 'group by t2.t_nchar', 'group by t2.t_bool' ,'group by t2.loc ,t2.t_bigint', + 'group by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'group by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'group by t2.t_float ,t2.t_double ' , + 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', + 'PARTITION by t2.t_float', 'PARTITION by t2.t_double' , 'PARTITION by t2.t_binary', 'PARTITION by t2.t_nchar', 'PARTITION by t2.t_bool' ,'PARTITION BY t2.loc ,t2.t_bigint', + 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] + + self.group_only_where = ['group by tbname , loc' , 'group by tbname', 'group by tbname, t_bigint', 'group by tbname,t_int', 'group by tbname, t_smallint', 'group by tbname,t_tinyint', + 'group by tbname,t_float', 'group by tbname,t_double' , 'group by tbname,t_binary', 'group by tbname,t_nchar', 'group by tbname,t_bool' ,'group by tbname ,loc ,t_bigint', + 'group by tbname,t_binary ,t_nchar ,t_bool' , 'group by tbname,t_int ,t_smallint ,t_tinyint' , 'group by tbname,t_float ,t_double ' ] + self.group_only_where_j = ['group by t1.loc' , 'group by t1.t_bigint', 'group by t1.t_int', 'group by t1.t_smallint', 'group by t1.t_tinyint', + 'group by t1.t_float', 'group by t1.t_double' , 'group by t1.t_binary', 'group by t1.t_nchar', 'group by t1.t_bool' ,'group by t1.loc ,t1.t_bigint', + 'group by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'group by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'group by t1.t_float ,t1.t_double ' , + 'group by t2.loc' , 'group by t2.t_bigint', 'group by t2.t_int', 'group by t2.t_smallint', 'group by t2.t_tinyint', + 'group by t2.t_float', 'group by t2.t_double' , 'group by t2.t_binary', 'group by t2.t_nchar', 'group by t2.t_bool' ,'group by t2.loc ,t2.t_bigint', + 'group by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'group by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'group by t2.t_float ,t2.t_double ' ] + + self.partiton_where = ['PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', + 'PARTITION BY tbname,t_float', 'PARTITION BY tbname,t_double' , 'PARTITION BY tbname,t_binary', 'PARTITION BY tbname,t_nchar', 'PARTITION BY tbname,t_bool' ,'PARTITION BY tbname ,loc ,t_bigint', + 'PARTITION BY tbname,t_binary ,t_nchar ,t_bool' , 'PARTITION BY tbname,t_int ,t_smallint ,t_tinyint' , 'PARTITION BY tbname,t_float ,t_double '] + self.partiton_where_j = ['PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', + 'PARTITION by t1.t_float', 'PARTITION by t1.t_double' , 'PARTITION by t1.t_binary', 'PARTITION by t1.t_nchar', 'PARTITION by t1.t_bool' ,'PARTITION BY t1.loc ,t1.t_bigint', + 'PARTITION by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'PARTITION by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'PARTITION by t1.t_float ,t1.t_double ', + 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', + 'PARTITION by t2.t_float', 'PARTITION by t2.t_double' , 'PARTITION by t2.t_binary', 'PARTITION by t2.t_nchar', 'PARTITION by t2.t_bool' ,'PARTITION BY t2.loc ,t2.t_bigint', + 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] + + self.group_where_regular = ['group by tbname ' , 'group by tbname', 'group by tbname, q_bigint', 'group by tbname,q_int', 'group by tbname, q_smallint', 'group by tbname,q_tinyint', + 'group by tbname,q_float', 'group by tbname,q_double' , 'group by tbname,q_binary', 'group by tbname,q_nchar', 'group by tbname,q_bool' ,'group by tbname ,q_bigint', + 'group by tbname,q_binary ,q_nchar ,q_bool' , 'group by tbname,q_int ,q_smallint ,q_tinyint' , 'group by tbname,q_float ,q_double ' , + 'PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', + 'PARTITION BY tbname,q_float', 'PARTITION BY tbname,q_double' , 'PARTITION BY tbname,q_binary', 'PARTITION BY tbname,q_nchar', 'PARTITION BY tbname,q_bool' ,'PARTITION BY tbname ,q_bigint', + 'PARTITION BY tbname,q_binary ,q_nchar ,q_bool' , 'PARTITION BY tbname,q_int ,q_smallint ,q_tinyint' , 'PARTITION BY tbname,q_float ,q_double '] + self.group_where_regular_j = ['group by t1.q_bigint', 'group by t1.q_int', 'group by t1.q_smallint', 'group by t1.q_tinyint', + 'group by t1.q_float', 'group by t1.q_double' , 'group by t1.q_binary', 'group by t1.q_nchar', 'group by t1.q_bool' ,'group by t1.q_bigint', + 'group by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'group by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'group by t1.q_float ,t1.q_double ' , + 'PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', + 'PARTITION by t1.q_float', 'PARTITION by t1.q_double' , 'PARTITION by t1.q_binary', 'PARTITION by t1.q_nchar', 'PARTITION by t1.q_bool' ,'PARTITION BY t1.q_bigint', + 'PARTITION by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'PARTITION by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'PARTITION by t1.q_float ,t1.q_double ', + 'group by t2.q_bigint', 'group by t2.q_int', 'group by t2.q_smallint', 'group by t2.q_tinyint', + 'group by t2.q_float', 'group by t2.q_double' , 'group by t2.q_binary', 'group by t2.q_nchar', 'group by t2.q_bool' ,'group by t2.q_bigint', + 'group by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'group by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'group by t2.q_float ,t2.q_double ' , + 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', + 'PARTITION by t2.q_float', 'PARTITION by t2.q_double' , 'PARTITION by t2.q_binary', 'PARTITION by t2.q_nchar', 'PARTITION by t2.q_bool' ,'PARTITION BY t2.q_bigint', + 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] + + self.partiton_where_regular = ['PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', + 'PARTITION BY tbname,q_float', 'PARTITION BY tbname,q_double' , 'PARTITION BY tbname,q_binary', 'PARTITION BY tbname,q_nchar', 'PARTITION BY tbname,q_bool' ,'PARTITION BY tbname ,q_bigint', + 'PARTITION BY tbname,q_binary ,q_nchar ,q_bool' , 'PARTITION BY tbname,q_int ,q_smallint ,q_tinyint' , 'PARTITION BY tbname,q_float ,q_double '] + self.partiton_where_regular_j = ['PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', + 'PARTITION by t1.q_float', 'PARTITION by t1.q_double' , 'PARTITION by t1.q_binary', 'PARTITION by t1.q_nchar', 'PARTITION by t1.q_bool' ,'PARTITION BY t1.q_bigint', + 'PARTITION by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'PARTITION by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'PARTITION by t1.q_float ,t1.q_double ', + 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', + 'PARTITION by t2.q_float', 'PARTITION by t2.q_double' , 'PARTITION by t2.q_binary', 'PARTITION by t2.q_nchar', 'PARTITION by t2.q_bool' ,'PARTITION BY t2.q_bigint', + 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] + + self.having_support = ['having count(q_int) > 0','having count(q_bigint) > 0','having count(q_smallint) > 0','having count(q_tinyint) > 0','having count(q_float) > 0','having count(q_double) > 0','having count(q_bool) > 0', + 'having avg(q_int) > 0','having avg(q_bigint) > 0','having avg(q_smallint) > 0','having avg(q_tinyint) > 0','having avg(q_float) > 0','having avg(q_double) > 0', + 'having sum(q_int) > 0','having sum(q_bigint) > 0','having sum(q_smallint) > 0','having sum(q_tinyint) > 0','having sum(q_float) > 0','having sum(q_double) > 0', + 'having STDDEV(q_int) > 0','having STDDEV(q_bigint) > 0','having STDDEV(q_smallint) > 0','having STDDEV(q_tinyint) > 0','having STDDEV(q_float) > 0','having STDDEV(q_double) > 0', + 'having TWA(q_int) > 0','having TWA(q_bigint) > 0','having TWA(q_smallint) > 0','having TWA(q_tinyint) > 0','having TWA(q_float) > 0','having TWA(q_double) > 0', + 'having IRATE(q_int) > 0','having IRATE(q_bigint) > 0','having IRATE(q_smallint) > 0','having IRATE(q_tinyint) > 0','having IRATE(q_float) > 0','having IRATE(q_double) > 0', + 'having MIN(q_int) > 0','having MIN(q_bigint) > 0','having MIN(q_smallint) > 0','having MIN(q_tinyint) > 0','having MIN(q_float) > 0','having MIN(q_double) > 0', + 'having MAX(q_int) > 0','having MAX(q_bigint) > 0','having MAX(q_smallint) > 0','having MAX(q_tinyint) > 0','having MAX(q_float) > 0','having MAX(q_double) > 0', + 'having FIRST(q_int) > 0','having FIRST(q_bigint) > 0','having FIRST(q_smallint) > 0','having FIRST(q_tinyint) > 0','having FIRST(q_float) > 0','having FIRST(q_double) > 0', + 'having LAST(q_int) > 0','having LAST(q_bigint) > 0','having LAST(q_smallint) > 0','having LAST(q_tinyint) > 0','having LAST(q_float) > 0','having LAST(q_double) > 0', + 'having APERCENTILE(q_int,10) > 0','having APERCENTILE(q_bigint,10) > 0','having APERCENTILE(q_smallint,10) > 0','having APERCENTILE(q_tinyint,10) > 0','having APERCENTILE(q_float,10) > 0','having APERCENTILE(q_double,10) > 0', + 'having count(q_int_null) > 0','having count(q_bigint_null) > 0','having count(q_smallint_null) > 0','having count(q_tinyint_null) > 0','having count(q_float_null) > 0','having count(q_double_null) > 0','having count(q_bool_null) > 0', + 'having avg(q_int_null) > 0','having avg(q_bigint_null) > 0','having avg(q_smallint_null) > 0','having avg(q_tinyint_null) > 0','having avg(q_float_null) > 0','having avg(q_double_null) > 0', + 'having sum(q_int_null) > 0','having sum(q_bigint_null) > 0','having sum(q_smallint_null) > 0','having sum(q_tinyint_null) > 0','having sum(q_float_null) > 0','having sum(q_double_null) > 0', + 'having STDDEV(q_int_null) > 0','having STDDEV(q_bigint_null) > 0','having STDDEV(q_smallint_null) > 0','having STDDEV(q_tinyint_null) > 0','having STDDEV(q_float_null) > 0','having STDDEV(q_double_null) > 0', + 'having TWA(q_int_null) > 0','having TWA(q_bigint_null) > 0','having TWA(q_smallint_null) > 0','having TWA(q_tinyint_null) > 0','having TWA(q_float_null) > 0','having TWA(q_double_null) > 0', + 'having IRATE(q_int_null) > 0','having IRATE(q_bigint_null) > 0','having IRATE(q_smallint_null) > 0','having IRATE(q_tinyint_null) > 0','having IRATE(q_float_null) > 0','having IRATE(q_double_null) > 0', + 'having MIN(q_int_null) > 0','having MIN(q_bigint_null) > 0','having MIN(q_smallint_null) > 0','having MIN(q_tinyint_null) > 0','having MIN(q_float_null) > 0','having MIN(q_double_null) > 0', + 'having MAX(q_int_null) > 0','having MAX(q_bigint_null) > 0','having MAX(q_smallint_null) > 0','having MAX(q_tinyint_null) > 0','having MAX(q_float_null) > 0','having MAX(q_double_null) > 0', + 'having FIRST(q_int_null) > 0','having FIRST(q_bigint_null) > 0','having FIRST(q_smallint_null) > 0','having FIRST(q_tinyint_null) > 0','having FIRST(q_float_null) > 0','having FIRST(q_double_null) > 0', + 'having LAST(q_int_null) > 0','having LAST(q_bigint_null) > 0','having LAST(q_smallint_null) > 0','having LAST(q_tinyint_null) > 0','having LAST(q_float_null) > 0','having LAST(q_double_null) > 0', + 'having APERCENTILE(q_int_null,10) > 0','having APERCENTILE(q_bigint_null,10) > 0','having APERCENTILE(q_smallint_null,10) > 0','having APERCENTILE(q_tinyint_null,10) > 0','having APERCENTILE(q_float_null,10) > 0','having APERCENTILE(q_double_null,10) > 0'] + self.having_not_support = ['having TOP(q_int,10) > 0','having TOP(q_bigint,10) > 0','having TOP(q_smallint,10) > 0','having TOP(q_tinyint,10) > 0','having TOP(q_float,10) > 0','having TOP(q_double,10) > 0','having TOP(q_bool,10) > 0', + 'having BOTTOM(q_int,10) > 0','having BOTTOM(q_bigint,10) > 0','having BOTTOM(q_smallint,10) > 0','having BOTTOM(q_tinyint,10) > 0','having BOTTOM(q_float,10) > 0','having BOTTOM(q_double,10) > 0','having BOTTOM(q_bool,10) > 0', + 'having LEASTSQUARES(q_int) > 0','having LEASTSQUARES(q_bigint) > 0','having LEASTSQUARES(q_smallint) > 0','having LEASTSQUARES(q_tinyint) > 0','having LEASTSQUARES(q_float) > 0','having LEASTSQUARES(q_double) > 0','having LEASTSQUARES(q_bool) > 0', + 'having FIRST(q_bool) > 0','having IRATE(q_bool) > 0','having PERCENTILE(q_bool,10) > 0','having avg(q_bool) > 0','having LAST_ROW(q_bool) > 0','having sum(q_bool) > 0','having STDDEV(q_bool) > 0','having APERCENTILE(q_bool,10) > 0','having TWA(q_bool) > 0','having LAST(q_bool) > 0', + 'having PERCENTILE(q_int,10) > 0','having PERCENTILE(q_bigint,10) > 0','having PERCENTILE(q_smallint,10) > 0','having PERCENTILE(q_tinyint,10) > 0','having PERCENTILE(q_float,10) > 0','having PERCENTILE(q_double,10) > 0', + 'having TOP(q_int_null,10) > 0','having TOP(q_bigint_null,10) > 0','having TOP(q_smallint_null,10) > 0','having TOP(q_tinyint_null,10) > 0','having TOP(q_float_null,10) > 0','having TOP(q_double_null,10) > 0','having TOP(q_bool_null,10) > 0', + 'having BOTTOM(q_int_null,10) > 0','having BOTTOM(q_bigint_null,10) > 0','having BOTTOM(q_smallint_null,10) > 0','having BOTTOM(q_tinyint_null,10) > 0','having BOTTOM(q_float_null,10) > 0','having BOTTOM(q_double_null,10) > 0','having BOTTOM(q_bool_null,10) > 0', + 'having LEASTSQUARES(q_int_null) > 0','having LEASTSQUARES(q_bigint_null) > 0','having LEASTSQUARES(q_smallint_null) > 0','having LEASTSQUARES(q_tinyint_null) > 0','having LEASTSQUARES(q_float_null) > 0','having LEASTSQUARES(q_double_null) > 0','having LEASTSQUARES(q_bool_null) > 0', + 'having FIRST(q_bool_null) > 0','having IRATE(q_bool_null) > 0','having PERCENTILE(q_bool_null,10) > 0','having avg(q_bool_null) > 0','having LAST_ROW(q_bool_null) > 0','having sum(q_bool_null) > 0','having STDDEV(q_bool_null) > 0','having APERCENTILE(q_bool_null,10) > 0','having TWA(q_bool_null) > 0','having LAST(q_bool_null) > 0', + 'having PERCENTILE(q_int_null,10) > 0','having PERCENTILE(q_bigint_null,10) > 0','having PERCENTILE(q_smallint_null,10) > 0','having PERCENTILE(q_tinyint_null,10) > 0','having PERCENTILE(q_float_null,10) > 0','having PERCENTILE(q_double_null,10) > 0'] + self.having_tagnot_support = ['having LAST_ROW(q_int) > 0','having LAST_ROW(q_bigint) > 0','having LAST_ROW(q_smallint) > 0','having LAST_ROW(q_tinyint) > 0','having LAST_ROW(q_float) > 0','having LAST_ROW(q_double) > 0', + 'having LAST_ROW(q_int_null) > 0','having LAST_ROW(q_bigint_null) > 0','having LAST_ROW(q_smallint_null) > 0','having LAST_ROW(q_tinyint_null) > 0','having LAST_ROW(q_float_null) > 0','having LAST_ROW(q_double_null) > 0'] + + self.having_support_j = ['having count(t1.q_int) > 0','having count(t1.q_bigint) > 0','having count(t1.q_smallint) > 0','having count(t1.q_tinyint) > 0','having count(t1.q_float) > 0','having count(t1.q_double) > 0','having count(t1.q_bool) > 0', + 'having avg(t1.q_int) > 0','having avg(t1.q_bigint) > 0','having avg(t1.q_smallint) > 0','having avg(t1.q_tinyint) > 0','having avg(t1.q_float) > 0','having avg(t1.q_double) > 0', + 'having sum(t1.q_int) > 0','having sum(t1.q_bigint) > 0','having sum(t1.q_smallint) > 0','having sum(t1.q_tinyint) > 0','having sum(t1.q_float) > 0','having sum(t1.q_double) > 0', + 'having STDDEV(t1.q_int) > 0','having STDDEV(t1.q_bigint) > 0','having STDDEV(t1.q_smallint) > 0','having STDDEV(t1.q_tinyint) > 0','having STDDEV(t1.q_float) > 0','having STDDEV(t1.q_double) > 0', + 'having TWA(t1.q_int) > 0','having TWA(t1.q_bigint) > 0','having TWA(t1.q_smallint) > 0','having TWA(t1.q_tinyint) > 0','having TWA(t1.q_float) > 0','having TWA(t1.q_double) > 0', + 'having IRATE(t1.q_int) > 0','having IRATE(t1.q_bigint) > 0','having IRATE(t1.q_smallint) > 0','having IRATE(t1.q_tinyint) > 0','having IRATE(t1.q_float) > 0','having IRATE(t1.q_double) > 0', + 'having MIN(t1.q_int) > 0','having MIN(t1.q_bigint) > 0','having MIN(t1.q_smallint) > 0','having MIN(t1.q_tinyint) > 0','having MIN(t1.q_float) > 0','having MIN(t1.q_double) > 0', + 'having MAX(t1.q_int) > 0','having MAX(t1.q_bigint) > 0','having MAX(t1.q_smallint) > 0','having MAX(t1.q_tinyint) > 0','having MAX(t1.q_float) > 0','having MAX(t1.q_double) > 0', + 'having FIRST(t1.q_int) > 0','having FIRST(t1.q_bigint) > 0','having FIRST(t1.q_smallint) > 0','having FIRST(t1.q_tinyint) > 0','having FIRST(t1.q_float) > 0','having FIRST(t1.q_double) > 0', + 'having LAST(t1.q_int) > 0','having LAST(t1.q_bigint) > 0','having LAST(t1.q_smallint) > 0','having LAST(t1.q_tinyint) > 0','having LAST(t1.q_float) > 0','having LAST(t1.q_double) > 0', + 'having APERCENTILE(t1.q_int,10) > 0','having APERCENTILE(t1.q_bigint,10) > 0','having APERCENTILE(t1.q_smallint,10) > 0','having APERCENTILE(t1.q_tinyint,10) > 0','having APERCENTILE(t1.q_float,10) > 0','having APERCENTILE(t1.q_double,10) > 0'] + + # limit offset where + self.limit_where = ['limit 1 offset 1' , 'limit 1' , 'limit 2 offset 1' , 'limit 2', 'limit 12 offset 1' , 'limit 20', 'limit 20 offset 10' , 'limit 200'] + self.limit1_where = ['limit 1 offset 1' , 'limit 1' ] + self.limit_u_where = ['limit 100 offset 10' , 'limit 50' , 'limit 100' , 'limit 10' ] + + # slimit soffset where + self.slimit_where = ['slimit 1 soffset 1' , 'slimit 1' , 'slimit 2 soffset 1' , 'slimit 2'] + self.slimit1_where = ['slimit 2 soffset 1' , 'slimit 1' ] + + self.calc_select_all = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , + 'top(q_int,20)' , 'top(q_bigint,20)' , 'top(q_smallint,20)' ,'top(q_tinyint,20)' ,'top(q_float,20)' ,'top(q_double,20)' , + 'first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , + 'last(q_int)' , 'last(q_bigint)' , 'last(q_smallint)' , 'last(q_tinyint)' , 'last(q_float)' ,'last(q_double)' , 'last(q_binary)' ,'last(q_nchar)' ,'last(q_bool)' ,'last(q_ts)' , + 'min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , + 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' , + 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)' , + 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , + 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)', + 'bottom(q_int_null,20)' , 'bottom(q_bigint_null,20)' , 'bottom(q_smallint_null,20)' , 'bottom(q_tinyint_null,20)' ,'bottom(q_float_null,20)' , 'bottom(q_double_null,20)' , + 'top(q_int_null,20)' , 'top(q_bigint_null,20)' , 'top(q_smallint_null,20)' ,'top(q_tinyint_null,20)' ,'top(q_float_null,20)' ,'top(q_double_null,20)' , + 'first(q_int_null)' , 'first(q_bigint_null)' , 'first(q_smallint_null)' , 'first(q_tinyint_null)' , 'first(q_float_null)' ,'first(q_double_null)' ,'first(q_binary_null)' ,'first(q_nchar_null)' ,'first(q_bool_null)' ,'first(q_ts_null)' , + 'last(q_int_null)' , 'last(q_bigint_null)' , 'last(q_smallint_null)' , 'last(q_tinyint_null)' , 'last(q_float_null)' ,'last(q_double_null)' , 'last(q_binary_null)' ,'last(q_nchar_null)' ,'last(q_bool_null)' ,'last(q_ts_null)' , + 'min(q_int_null)' , 'min(q_bigint_null)' , 'min(q_smallint_null)' , 'min(q_tinyint_null)' , 'min(q_float_null)' ,'min(q_double_null)' , + 'max(q_int_null)' , 'max(q_bigint_null)' , 'max(q_smallint_null)' , 'max(q_tinyint_null)' ,'max(q_float_null)' ,'max(q_double_null)' , + 'last_row(q_int_null)' , 'last_row(q_bigint_null)' , 'last_row(q_smallint_null)' , 'last_row(q_tinyint_null)' , 'last_row(q_float_null)' , + 'last_row(q_double_null)' , 'last_row(q_bool_null)' ,'last_row(q_binary_null)' ,'last_row(q_nchar_null)' ,'last_row(q_ts_null)', + 'apercentile(q_int_null,20)' , 'apercentile(q_bigint_null,20)' ,'apercentile(q_smallint_null,20)' ,'apercentile(q_tinyint_null,20)' ,'apercentile(q_float_null,20)' ,'apercentile(q_double_null,20)' ,] + + self.calc_select_in_ts = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , + 'top(q_int,20)' , 'top(q_bigint,20)' , 'top(q_smallint,20)' ,'top(q_tinyint,20)' ,'top(q_float,20)' ,'top(q_double,20)' , + 'bottom(q_int_null,20)' , 'bottom(q_bigint_null,20)' , 'bottom(q_smallint_null,20)' , 'bottom(q_tinyint_null,20)' ,'bottom(q_float_null,20)' , 'bottom(q_double_null,20)' , + 'top(q_int_null,20)' , 'top(q_bigint_null,20)' , 'top(q_smallint_null,20)' ,'top(q_tinyint_null,20)' ,'top(q_float_null,20)' ,'top(q_double_null,20)' , + 'first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , + 'last(q_int)' , 'last(q_bigint)' , 'last(q_smallint)' , 'last(q_tinyint)' , 'last(q_float)' ,'last(q_double)' , 'last(q_binary)' ,'last(q_nchar)' ,'last(q_bool)' ,'last(q_ts)' , + 'first(q_int_null)' , 'first(q_bigint_null)' , 'first(q_smallint_null)' , 'first(q_tinyint_null)' , 'first(q_float_null)' ,'first(q_double_null)' ,'first(q_binary_null)' ,'first(q_nchar_null)' ,'first(q_bool_null)' ,'first(q_ts_null)' , + 'last(q_int_null)' , 'last(q_bigint_null)' , 'last(q_smallint_null)' , 'last(q_tinyint_null)' , 'last(q_float_null)' ,'last(q_double_null)' , 'last(q_binary_null)' ,'last(q_nchar_null)' ,'last(q_bool_null)' ,'last(q_ts_null)' ] + + self.calc_select_in = ['min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , + 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' , + 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)' , + 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , + 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)', + 'min(q_int_null)' , 'min(q_bigint_null)' , 'min(q_smallint_null)' , 'min(q_tinyint_null)' , 'min(q_float_null)' ,'min(q_double_null)' , + 'max(q_int_null)' , 'max(q_bigint_null)' , 'max(q_smallint_null)' , 'max(q_tinyint_null)' ,'max(q_float_null)' ,'max(q_double_null)' , + 'apercentile(q_int_null,20)' , 'apercentile(q_bigint_null,20)' ,'apercentile(q_smallint_null,20)' ,'apercentile(q_tinyint_null,20)' ,'apercentile(q_float_null,20)' ,'apercentile(q_double_null,20)' , + 'last_row(q_int_null)' , 'last_row(q_bigint_null)' , 'last_row(q_smallint_null)' , 'last_row(q_tinyint_null)' , 'last_row(q_float_null)' , + 'last_row(q_double_null)' , 'last_row(q_bool_null)' ,'last_row(q_binary_null)' ,'last_row(q_nchar_null)' ,'last_row(q_ts_null)'] + + self.calc_select_not_support_ts = ['first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , + 'last(q_int)' , 'last(q_bigint)' , 'last(q_smallint)' , 'last(q_tinyint)' , 'last(q_float)' ,'last(q_double)' , 'last(q_binary)' ,'last(q_nchar)' ,'last(q_bool)' ,'last(q_ts)' , + 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , + 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)', + 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)', + 'first(q_int_null)' , 'first(q_bigint_null)' , 'first(q_smallint_null)' , 'first(q_tinyint_null)' , 'first(q_float_null)' ,'first(q_double_null)' ,'first(q_binary_null)' ,'first(q_nchar_null)' ,'first(q_bool_null)' ,'first(q_ts_null)' , + 'last(q_int_null)' , 'last(q_bigint_null)' , 'last(q_smallint_null)' , 'last(q_tinyint_null)' , 'last(q_float_null)' ,'last(q_double_null)' , 'last(q_binary_null)' ,'last(q_nchar_null)' ,'last(q_bool_null)' ,'last(q_ts_null)' , + 'last_row(q_int_null)' , 'last_row(q_bigint_null)' , 'last_row(q_smallint_null)' , 'last_row(q_tinyint_null)' , 'last_row(q_float_null)' , + 'last_row(q_double_null)' , 'last_row(q_bool_null)' ,'last_row(q_binary_null)' ,'last_row(q_nchar_null)' ,'last_row(q_ts_null)', + 'apercentile(q_int_null,20)' , 'apercentile(q_bigint_null,20)' ,'apercentile(q_smallint_null,20)' ,'apercentile(q_tinyint_null,20)' ,'apercentile(q_float_null,20)' ,'apercentile(q_double_null,20)'] + + self.calc_select_support_ts = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , + 'top(q_int,20)' , 'top(q_bigint,20)' , 'top(q_smallint,20)' ,'top(q_tinyint,20)' ,'top(q_float,20)' ,'top(q_double,20)' , + 'bottom(q_int_null,20)' , 'bottom(q_bigint_null,20)' , 'bottom(q_smallint_null,20)' , 'bottom(q_tinyint_null,20)' ,'bottom(q_float_null,20)' , 'bottom(q_double_null,20)' , + 'top(q_int_null,20)' , 'top(q_bigint_null,20)' , 'top(q_smallint_null,20)' ,'top(q_tinyint_null,20)' ,'top(q_float_null,20)' ,'top(q_double_null,20)' , + 'min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , + 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' , + 'min(q_int_null)' , 'min(q_bigint_null)' , 'min(q_smallint_null)' , 'min(q_tinyint_null)' , 'min(q_float_null)' ,'min(q_double_null)' , + 'max(q_int_null)' , 'max(q_bigint_null)' , 'max(q_smallint_null)' , 'max(q_tinyint_null)' ,'max(q_float_null)' ,'max(q_double_null)'] + + self.calc_select_regular = [ 'PERCENTILE(q_int,10)' ,'PERCENTILE(q_bigint,20)' , 'PERCENTILE(q_smallint,30)' ,'PERCENTILE(q_tinyint,40)' ,'PERCENTILE(q_float,50)' ,'PERCENTILE(q_double,60)', + 'PERCENTILE(q_int_null,10)' ,'PERCENTILE(q_bigint_null,20)' , 'PERCENTILE(q_smallint_null,30)' ,'PERCENTILE(q_tinyint_null,40)' ,'PERCENTILE(q_float_null,50)' ,'PERCENTILE(q_double_null,60)'] + + + self.calc_select_fill = ['INTERP(q_int)' ,'INTERP(q_bigint)' ,'INTERP(q_smallint)' ,'INTERP(q_tinyint)', 'INTERP(q_float)' ,'INTERP(q_double)'] + self.interp_where = ['ts = now' , 'ts = \'2020-09-13 20:26:40.000\'' , 'ts = \'2020-09-13 20:26:40.009\'' ,'tbname in (\'table_1\') and ts = now' ,'tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and ts = \'2020-09-13 20:26:40.000\'','tbname like \'table%\' and ts = \'2020-09-13 20:26:40.002\''] + + #two table join + self.calc_select_in_ts_j = ['bottom(t1.q_int,20)' , 'bottom(t1.q_bigint,20)' , 'bottom(t1.q_smallint,20)' , 'bottom(t1.q_tinyint,20)' ,'bottom(t1.q_float,20)' , 'bottom(t1.q_double,20)' , + 'top(t1.q_int,20)' , 'top(t1.q_bigint,20)' , 'top(t1.q_smallint,20)' ,'top(t1.q_tinyint,20)' ,'top(t1.q_float,20)' ,'top(t1.q_double,20)' , + 'first(t1.q_int)' , 'first(t1.q_bigint)' , 'first(t1.q_smallint)' , 'first(t1.q_tinyint)' , 'first(t1.q_float)' ,'first(t1.q_double)' ,'first(t1.q_binary)' ,'first(t1.q_nchar)' ,'first(t1.q_bool)' ,'first(t1.q_ts)' , + 'last(t1.q_int)' , 'last(t1.q_bigint)' , 'last(t1.q_smallint)' , 'last(t1.q_tinyint)' , 'last(t1.q_float)' ,'last(t1.q_double)' , 'last(t1.q_binary)' ,'last(t1.q_nchar)' ,'last(t1.q_bool)' ,'last(t1.q_ts)' , + 'bottom(t2.q_int,20)' , 'bottom(t2.q_bigint,20)' , 'bottom(t2.q_smallint,20)' , 'bottom(t2.q_tinyint,20)' ,'bottom(t2.q_float,20)' , 'bottom(t2.q_double,20)' , + 'top(t2.q_int,20)' , 'top(t2.q_bigint,20)' , 'top(t2.q_smallint,20)' ,'top(t2.q_tinyint,20)' ,'top(t2.q_float,20)' ,'top(t2.q_double,20)' , + 'first(t2.q_int)' , 'first(t2.q_bigint)' , 'first(t2.q_smallint)' , 'first(t2.q_tinyint)' , 'first(t2.q_float)' ,'first(t2.q_double)' ,'first(t2.q_binary)' ,'first(t2.q_nchar)' ,'first(t2.q_bool)' ,'first(t2.q_ts)' , + 'last(t2.q_int)' , 'last(t2.q_bigint)' , 'last(t2.q_smallint)' , 'last(t2.q_tinyint)' , 'last(t2.q_float)' ,'last(t2.q_double)' , 'last(t2.q_binary)' ,'last(t2.q_nchar)' ,'last(t2.q_bool)' ,'last(t2.q_ts)', + 'bottom(t1.q_int_null,20)' , 'bottom(t1.q_bigint_null,20)' , 'bottom(t1.q_smallint_null,20)' , 'bottom(t1.q_tinyint_null,20)' ,'bottom(t1.q_float_null,20)' , 'bottom(t1.q_double_null,20)' , + 'top(t1.q_int_null,20)' , 'top(t1.q_bigint_null,20)' , 'top(t1.q_smallint_null,20)' ,'top(t1.q_tinyint_null,20)' ,'top(t1.q_float_null,20)' ,'top(t1.q_double_null,20)' , + 'first(t1.q_int_null)' , 'first(t1.q_bigint_null)' , 'first(t1.q_smallint_null)' , 'first(t1.q_tinyint_null)' , 'first(t1.q_float_null)' ,'first(t1.q_double_null)' ,'first(t1.q_binary_null)' ,'first(t1.q_nchar_null))' ,'first(t1.q_bool_null)' ,'first(t1.q_ts_null)' , + 'last(t1.q_int_null)' , 'last(t1.q_bigint_null)' , 'last(t1.q_smallint_null)' , 'last(t1.q_tinyint_null)' , 'last(t1.q_float_null)' ,'last(t1.q_double_null)' , 'last(t1.q_binary_null)' ,'last(t1.q_nchar_null))' ,'last(t1.q_bool_null)' ,'last(t1.q_ts_null)' , + 'bottom(t2.q_int_null,20)' , 'bottom(t2.q_bigint_null,20)' , 'bottom(t2.q_smallint_null,20)' , 'bottom(t2.q_tinyint_null,20)' ,'bottom(t2.q_float_null,20)' , 'bottom(t2.q_double_null,20)' , + 'top(t2.q_int_null,20)' , 'top(t2.q_bigint_null,20)' , 'top(t2.q_smallint_null,20)' ,'top(t2.q_tinyint_null,20)' ,'top(t2.q_float_null,20)' ,'top(t2.q_double_null,20)' , + 'first(t2.q_int_null)' , 'first(t2.q_bigint_null)' , 'first(t2.q_smallint_null)' , 'first(t2.q_tinyint_null)' , 'first(t2.q_float_null)' ,'first(t2.q_double_null)' ,'first(t2.q_binary_null)' ,'first(t2.q_nchar_null))' ,'first(t2.q_bool_null)' ,'first(t2.q_ts_null)' , + 'last(t2.q_int_null)' , 'last(t2.q_bigint_null)' , 'last(t2.q_smallint_null)' , 'last(t2.q_tinyint_null)' , 'last(t2.q_float_null)' ,'last(t2.q_double_null)' , 'last(t2.q_binary_null)' ,'last(t2.q_nchar_null))' ,'last(t2.q_bool_null)' ,'last(t2.q_ts_null)'] + + self.calc_select_in_support_ts_j = ['bottom(t1.q_int,20)' , 'bottom(t1.q_bigint,20)' , 'bottom(t1.q_smallint,20)' , 'bottom(t1.q_tinyint,20)' ,'bottom(t1.q_float,20)' , 'bottom(t1.q_double,20)' , + 'top(t1.q_int,20)' , 'top(t1.q_bigint,20)' , 'top(t1.q_smallint,20)' ,'top(t1.q_tinyint,20)' ,'top(t1.q_float,20)' ,'top(t1.q_double,20)' , + 'min(t1.q_int)' , 'min(t1.q_bigint)' , 'min(t1.q_smallint)' , 'min(t1.q_tinyint)' , 'min(t1.q_float)' ,'min(t1.q_double)' , + 'max(t1.q_int)' , 'max(t1.q_bigint)' , 'max(t1.q_smallint)' , 'max(t1.q_tinyint)' ,'max(t1.q_float)' ,'max(t1.q_double)' , + 'bottom(t2.q_int,20)' , 'bottom(t2.q_bigint,20)' , 'bottom(t2.q_smallint,20)' , 'bottom(t2.q_tinyint,20)' ,'bottom(t2.q_float,20)' , 'bottom(t2.q_double,20)' , + 'top(t2.q_int,20)' , 'top(t2.q_bigint,20)' , 'top(t2.q_smallint,20)' ,'top(t2.q_tinyint,20)' ,'top(t2.q_float,20)' ,'top(t2.q_double,20)' , + 'min(t2.q_int)' , 'min(t2.q_bigint)' , 'min(t2.q_smallint)' , 'min(t2.q_tinyint)' , 'min(t2.q_float)' ,'min(t2.q_double)' , + 'max(t2.q_int)' , 'max(t2.q_bigint)' , 'max(t2.q_smallint)' , 'max(t2.q_tinyint)' ,'max(t2.q_float)' ,'max(t2.q_double)' , + 'bottom(t1.q_int_null,20)' , 'bottom(t1.q_bigint_null,20)' , 'bottom(t1.q_smallint_null,20)' , 'bottom(t1.q_tinyint_null,20)' ,'bottom(t1.q_float_null,20)' , 'bottom(t1.q_double_null,20)' , + 'top(t1.q_int_null,20)' , 'top(t1.q_bigint_null,20)' , 'top(t1.q_smallint_null,20)' ,'top(t1.q_tinyint_null,20)' ,'top(t1.q_float_null,20)' ,'top(t1.q_double_null,20)' , + 'bottom(t2.q_int_null,20)' , 'bottom(t2.q_bigint_null,20)' , 'bottom(t2.q_smallint_null,20)' , 'bottom(t2.q_tinyint_null,20)' ,'bottom(t2.q_float_null,20)' , 'bottom(t2.q_double_null,20)' , + 'top(t2.q_int_null,20)' , 'top(t2.q_bigint_null,20)' , 'top(t2.q_smallint_null,20)' ,'top(t2.q_tinyint_null,20)' ,'top(t2.q_float_null,20)' ,'top(t2.q_double_null,20)' , + 'min(t1.q_int_null)' , 'min(t1.q_bigint_null)' , 'min(t1.q_smallint_null)' , 'min(t1.q_tinyint_null)' , 'min(t1.q_float_null)' ,'min(t1.q_double_null)' , + 'max(t1.q_int_null)' , 'max(t1.q_bigint_null)' , 'max(t1.q_smallint_null)' , 'max(t1.q_tinyint_null)' ,'max(t1.q_float_null)' ,'max(t1.q_double_null)' , + 'min(t2.q_int_null)' , 'min(t2.q_bigint_null)' , 'min(t2.q_smallint_null)' , 'min(t2.q_tinyint_null)' , 'min(t2.q_float_null)' ,'min(t2.q_double_null)' , + 'max(t2.q_int_null)' , 'max(t2.q_bigint_null)' , 'max(t2.q_smallint_null)' , 'max(t2.q_tinyint_null)' ,'max(t2.q_float_null)' ,'max(t2.q_double_null)' ] + + self.calc_select_in_not_support_ts_j = ['apercentile(t1.q_int,20)' , 'apercentile(t1.q_bigint,20)' ,'apercentile(t1.q_smallint,20)' ,'apercentile(t1.q_tinyint,20)' ,'apercentile(t1.q_float,20)' ,'apercentile(t1.q_double,20)' , + 'apercentile(t1.q_int_null,20)' , 'apercentile(t1.q_bigint_null,20)' ,'apercentile(t1.q_smallint_null,20)' ,'apercentile(t1.q_tinyint_null,20)' ,'apercentile(t1.q_float_null,20)' ,'apercentile(t1.q_double_null,20)' , + 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , + 'last_row(t1.q_double)' , 'last_row(t1.q_bool)' ,'last_row(t1.q_binary)' ,'last_row(t1.q_nchar)' ,'last_row(t1.q_ts)' , + 'last_row(t1.q_int_null)' , 'last_row(t1.q_bigint_null)' , 'last_row(t1.q_smallint_null)' , 'last_row(t1.q_tinyint_null)' , 'last_row(t1.q_float_null)' , + 'last_row(t1.q_double_null)' , 'last_row(t1.q_bool_null)' ,'last_row(t1.q_binary_null)' ,'last_row(t1.q_nchar_null)' ,'last_row(t1.q_ts_null)' , + 'apercentile(t2.q_int,20)' , 'apercentile(t2.q_bigint,20)' ,'apercentile(t2.q_smallint,20)' ,'apercentile(t2.q_tinyint,20)' ,'apercentile(t2.q_float,20)' ,'apercentile(t2.q_double,20)' , + 'apercentile(t2.q_int_null,20)' , 'apercentile(t2.q_bigint_null,20)' ,'apercentile(t2.q_smallint_null,20)' ,'apercentile(t2.q_tinyint_null,20)' ,'apercentile(t2.q_float_null,20)' ,'apercentile(t2.q_double_null,20)' , + 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , + 'last_row(t2.q_double)' , 'last_row(t2.q_bool)' ,'last_row(t2.q_binary)' ,'last_row(t2.q_nchar)' ,'last_row(t2.q_ts)', + 'last_row(t2.q_int_null)' , 'last_row(t2.q_bigint_null)' , 'last_row(t2.q_smallint_null)' , 'last_row(t2.q_tinyint_null)' , 'last_row(t2.q_float_null)' , + 'last_row(t2.q_double_null)' , 'last_row(t2.q_bool_null)' ,'last_row(t2.q_binary_null)' ,'last_row(t2.q_nchar_null)' ,'last_row(t2.q_ts_null)'] + + self.calc_select_in_j = ['min(t1.q_int)' , 'min(t1.q_bigint)' , 'min(t1.q_smallint)' , 'min(t1.q_tinyint)' , 'min(t1.q_float)' ,'min(t1.q_double)' , + 'max(t1.q_int)' , 'max(t1.q_bigint)' , 'max(t1.q_smallint)' , 'max(t1.q_tinyint)' ,'max(t1.q_float)' ,'max(t1.q_double)' , + 'apercentile(t1.q_int,20)' , 'apercentile(t1.q_bigint,20)' ,'apercentile(t1.q_smallint,20)' ,'apercentile(t1.q_tinyint,20)' ,'apercentile(t1.q_float,20)' ,'apercentile(t1.q_double,20)' , + 'min(t1.q_int_null)' , 'min(t1.q_bigint_null)' , 'min(t1.q_smallint_null)' , 'min(t1.q_tinyint_null)' , 'min(t1.q_float_null)' ,'min(t1.q_double_null)' , + 'max(t1.q_int_null)' , 'max(t1.q_bigint_null)' , 'max(t1.q_smallint_null)' , 'max(t1.q_tinyint_null)' ,'max(t1.q_float_null)' ,'max(t1.q_double_null)' , + 'apercentile(t1.q_int_null,20)' , 'apercentile(t1.q_bigint_null,20)' ,'apercentile(t1.q_smallint_null,20)' ,'apercentile(t1.q_tinyint_null,20)' ,'apercentile(t1.q_float_null,20)' ,'apercentile(t1.q_double_null,20)' , + 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , + 'last_row(t1.q_double)' , 'last_row(t1.q_bool)' ,'last_row(t1.q_binary)' ,'last_row(t1.q_nchar)' ,'last_row(t1.q_ts)' , + 'min(t2.q_int)' , 'min(t2.q_bigint)' , 'min(t2.q_smallint)' , 'min(t2.q_tinyint)' , 'min(t2.q_float)' ,'min(t2.q_double)' , + 'max(t2.q_int)' , 'max(t2.q_bigint)' , 'max(t2.q_smallint)' , 'max(t2.q_tinyint)' ,'max(t2.q_float)' ,'max(t2.q_double)' , + 'last_row(t1.q_int_null)' , 'last_row(t1.q_bigint_null)' , 'last_row(t1.q_smallint_null)' , 'last_row(t1.q_tinyint_null)' , 'last_row(t1.q_float_null)' , + 'last_row(t1.q_double_null)' , 'last_row(t1.q_bool_null)' ,'last_row(t1.q_binary_null)' ,'last_row(t1.q_nchar_null)' ,'last_row(t1.q_ts_null)' , + 'min(t2.q_int_null)' , 'min(t2.q_bigint_null)' , 'min(t2.q_smallint_null)' , 'min(t2.q_tinyint_null)' , 'min(t2.q_float_null)' ,'min(t2.q_double_null)' , + 'max(t2.q_int_null)' , 'max(t2.q_bigint_null)' , 'max(t2.q_smallint_null)' , 'max(t2.q_tinyint_null)' ,'max(t2.q_float_null)' ,'max(t2.q_double_null)' , + 'apercentile(t2.q_int,20)' , 'apercentile(t2.q_bigint,20)' ,'apercentile(t2.q_smallint,20)' ,'apercentile(t2.q_tinyint,20)' ,'apercentile(t2.q_float,20)' ,'apercentile(t2.q_double,20)' , + 'apercentile(t2.q_int_null,20)' , 'apercentile(t2.q_bigint_null,20)' ,'apercentile(t2.q_smallint_null,20)' ,'apercentile(t2.q_tinyint_null,20)' ,'apercentile(t2.q_float_null,20)' ,'apercentile(t2.q_double_null,20)' , + 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , + 'last_row(t2.q_double)' , 'last_row(t2.q_bool)' ,'last_row(t2.q_binary)' ,'last_row(t2.q_nchar)' ,'last_row(t2.q_ts)', + 'last_row(t2.q_int_null)' , 'last_row(t2.q_bigint_null)' , 'last_row(t2.q_smallint_null)' , 'last_row(t2.q_tinyint_null)' , 'last_row(t2.q_float_null)' , + 'last_row(t2.q_double_null)' , 'last_row(t2.q_bool_null)' ,'last_row(t2.q_binary_null)' ,'last_row(t2.q_nchar_null)' ,'last_row(t2.q_ts_null)'] + self.calc_select_all_j = self.calc_select_in_ts_j + self.calc_select_in_j + + self.calc_select_regular_j = [ 'PERCENTILE(t1.q_int,10)' ,'PERCENTILE(t1.q_bigint,20)' , 'PERCENTILE(t1.q_smallint,30)' ,'PERCENTILE(t1.q_tinyint,40)' ,'PERCENTILE(t1.q_float,50)' ,'PERCENTILE(t1.q_double,60)' , + 'PERCENTILE(t2.q_int,10)' ,'PERCENTILE(t2.q_bigint,20)' , 'PERCENTILE(t2.q_smallint,30)' ,'PERCENTILE(t2.q_tinyint,40)' ,'PERCENTILE(t2.q_float,50)' ,'PERCENTILE(t2.q_double,60)', + 'PERCENTILE(t1.q_int_null,10)' ,'PERCENTILE(t1.q_bigint_null,20)' , 'PERCENTILE(t1.q_smallint_null,30)' ,'PERCENTILE(t1.q_tinyint_null,40)' ,'PERCENTILE(t1.q_float_null,50)' ,'PERCENTILE(t1.q_double_null,60)' , + 'PERCENTILE(t2.q_int_null,10)' ,'PERCENTILE(t2.q_bigint_null,20)' , 'PERCENTILE(t2.q_smallint_null,30)' ,'PERCENTILE(t2.q_tinyint_null,40)' ,'PERCENTILE(t2.q_float_null,50)' ,'PERCENTILE(t2.q_double_null,60)'] + + + self.calc_select_fill_j = ['INTERP(t1.q_int)' ,'INTERP(t1.q_bigint)' ,'INTERP(t1.q_smallint)' ,'INTERP(t1.q_tinyint)', 'INTERP(t1.q_float)' ,'INTERP(t1.q_double)' , + 'INTERP(t2.q_int)' ,'INTERP(t2.q_bigint)' ,'INTERP(t2.q_smallint)' ,'INTERP(t2.q_tinyint)', 'INTERP(t2.q_float)' ,'INTERP(t2.q_double)'] + self.interp_where_j = ['t1.ts = now' , 't1.ts = \'2020-09-13 20:26:40.000\'' , 't1.ts = \'2020-09-13 20:26:40.009\'' ,'t2.ts = now' , 't2.ts = \'2020-09-13 20:26:40.000\'' , 't2.ts = \'2020-09-13 20:26:40.009\'' , + 't1.tbname in (\'table_1\') and t1.ts = now' ,'t1.tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and t1.ts = \'2020-09-13 20:26:40.000\'','t1.tbname like \'table%\' and t1.ts = \'2020-09-13 20:26:40.002\'', + 't2.tbname in (\'table_1\') and t2.ts = now' ,'t2.tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and t2.ts = \'2020-09-13 20:26:40.000\'','t2.tbname like \'table%\' and t2.ts = \'2020-09-13 20:26:40.002\''] + + self.calc_aggregate_all = ['count(*)' , 'count(q_int)' ,'count(q_bigint)' , 'count(q_smallint)' ,'count(q_tinyint)' ,'count(q_float)' , + 'count(q_double)' ,'count(q_binary)' ,'count(q_nchar)' ,'count(q_bool)' ,'count(q_ts)' , + 'avg(q_int)' ,'avg(q_bigint)' , 'avg(q_smallint)' ,'avg(q_tinyint)' ,'avg(q_float)' ,'avg(q_double)' , + 'sum(q_int)' ,'sum(q_bigint)' , 'sum(q_smallint)' ,'sum(q_tinyint)' ,'sum(q_float)' ,'sum(q_double)' , + 'STDDEV(q_int)' ,'STDDEV(q_bigint)' , 'STDDEV(q_smallint)' ,'STDDEV(q_tinyint)' ,'STDDEV(q_float)' ,'STDDEV(q_double)', + 'APERCENTILE(q_int,10)' ,'APERCENTILE(q_bigint,20)' , 'APERCENTILE(q_smallint,30)' ,'APERCENTILE(q_tinyint,40)' ,'APERCENTILE(q_float,50)' ,'APERCENTILE(q_double,60)', + 'count(q_int_null)' ,'count(q_bigint_null)' , 'count(q_smallint_null)' ,'count(q_tinyint_null)' ,'count(q_float_null)' , + 'count(q_double_null)' ,'count(q_binary_null)' ,'count(q_nchar_null)' ,'count(q_bool_null)' ,'count(q_ts_null)' , + 'avg(q_int_null)' ,'avg(q_bigint_null)' , 'avg(q_smallint_null)' ,'avg(q_tinyint_null)' ,'avg(q_float_null)' ,'avg(q_double_null)' , + 'sum(q_int_null)' ,'sum(q_bigint_null)' , 'sum(q_smallint_null)' ,'sum(q_tinyint_null)' ,'sum(q_float_null)' ,'sum(q_double_null)' , + 'STDDEV(q_int_null)' ,'STDDEV(q_bigint_null)' , 'STDDEV(q_smallint_null)' ,'STDDEV(q_tinyint_null)' ,'STDDEV(q_float_null)' ,'STDDEV(q_double_null)', + 'APERCENTILE(q_int_null,10)' ,'APERCENTILE(q_bigint_null,20)' , 'APERCENTILE(q_smallint_null,30)' ,'APERCENTILE(q_tinyint_null,40)' ,'APERCENTILE(q_float_null,50)' ,'APERCENTILE(q_double_null,60)'] + + self.calc_aggregate_regular = ['twa(q_int)' ,'twa(q_bigint)' , 'twa(q_smallint)' ,'twa(q_tinyint)' ,'twa (q_float)' ,'twa(q_double)' , + 'IRATE(q_int)' ,'IRATE(q_bigint)' , 'IRATE(q_smallint)' ,'IRATE(q_tinyint)' ,'IRATE (q_float)' ,'IRATE(q_double)' , + 'twa(q_int_null)' ,'twa(q_bigint_null)' , 'twa(q_smallint_null)' ,'twa(q_tinyint_null)' ,'twa (q_float_null)' ,'twa(q_double_null)' , + 'IRATE(q_int_null)' ,'IRATE(q_bigint_null)' , 'IRATE(q_smallint_null)' ,'IRATE(q_tinyint_null)' ,'IRATE (q_float_null)' ,'IRATE(q_double_null)' , + 'LEASTSQUARES(q_int,15,3)' , 'LEASTSQUARES(q_bigint,10,1)' , 'LEASTSQUARES(q_smallint,20,3)' ,'LEASTSQUARES(q_tinyint,10,4)' ,'LEASTSQUARES(q_float,6,4)' ,'LEASTSQUARES(q_double,3,1)' , + 'PERCENTILE(q_int,10)' ,'PERCENTILE(q_bigint,20)' , 'PERCENTILE(q_smallint,30)' ,'PERCENTILE(q_tinyint,40)' ,'PERCENTILE(q_float,50)' ,'PERCENTILE(q_double,60)', + 'LEASTSQUARES(q_int_null,15,3)' , 'LEASTSQUARES(q_bigint_null,10,1)' , 'LEASTSQUARES(q_smallint_null,20,3)' ,'LEASTSQUARES(q_tinyint_null,10,4)' ,'LEASTSQUARES(q_float_null,6,4)' ,'LEASTSQUARES(q_double_null,3,1)' , + 'PERCENTILE(q_int_null,10)' ,'PERCENTILE(q_bigint_null,20)' , 'PERCENTILE(q_smallint_null,30)' ,'PERCENTILE(q_tinyint_null,40)' ,'PERCENTILE(q_float_null,50)' ,'PERCENTILE(q_double_null,60)'] + + self.calc_aggregate_groupbytbname = ['twa(q_int)' ,'twa(q_bigint)' , 'twa(q_smallint)' ,'twa(q_tinyint)' ,'twa (q_float)' ,'twa(q_double)' , + 'IRATE(q_int)' ,'IRATE(q_bigint)' , 'IRATE(q_smallint)' ,'IRATE(q_tinyint)' ,'IRATE (q_float)' ,'IRATE(q_double)', + 'twa(q_int_null)' ,'twa(q_bigint_null)' , 'twa(q_smallint_null)' ,'twa(q_tinyint_null)' ,'twa (q_float_null)' ,'twa(q_double_null)' , + 'IRATE(q_int_null)' ,'IRATE(q_bigint_null)' , 'IRATE(q_smallint_null)' ,'IRATE(q_tinyint_null)' ,'IRATE (q_float_null)' ,'IRATE(q_double_null)'] + + #two table join + self.calc_aggregate_all_j = ['count(t1.*)' , 'count(t1.q_int)' ,'count(t1.q_bigint)' , 'count(t1.q_smallint)' ,'count(t1.q_tinyint)' ,'count(t1.q_float)' , + 'count(t1.q_double)' ,'count(t1.q_binary)' ,'count(t1.q_nchar)' ,'count(t1.q_bool)' ,'count(t1.q_ts)' , + 'avg(t1.q_int)' ,'avg(t1.q_bigint)' , 'avg(t1.q_smallint)' ,'avg(t1.q_tinyint)' ,'avg(t1.q_float)' ,'avg(t1.q_double)' , + 'sum(t1.q_int)' ,'sum(t1.q_bigint)' , 'sum(t1.q_smallint)' ,'sum(t1.q_tinyint)' ,'sum(t1.q_float)' ,'sum(t1.q_double)' , + 'STDDEV(t1.q_int)' ,'STDDEV(t1.q_bigint)' , 'STDDEV(t1.q_smallint)' ,'STDDEV(t1.q_tinyint)' ,'STDDEV(t1.q_float)' ,'STDDEV(t1.q_double)', + 'APERCENTILE(t1.q_int,10)' ,'APERCENTILE(t1.q_bigint,20)' , 'APERCENTILE(t1.q_smallint,30)' ,'APERCENTILE(t1.q_tinyint,40)' ,'APERCENTILE(t1.q_float,50)' ,'APERCENTILE(t1.q_double,60)' , + 'count(t1.q_int_null)' ,'count(t1.q_bigint_null)' , 'count(t1.q_smallint_null)' ,'count(t1.q_tinyint_null)' ,'count(t1.q_float_null)' , + 'count(t1.q_double_null)' ,'count(t1.q_binary_null)' ,'count(t1.q_nchar_null)' ,'count(t1.q_bool_null)' ,'count(t1.q_ts_null)' , + 'avg(t1.q_int_null)' ,'avg(t1.q_bigint_null)' , 'avg(t1.q_smallint_null)' ,'avg(t1.q_tinyint_null)' ,'avg(t1.q_float_null)' ,'avg(t1.q_double_null)' , + 'sum(t1.q_int_null)' ,'sum(t1.q_bigint_null)' , 'sum(t1.q_smallint_null)' ,'sum(t1.q_tinyint_null)' ,'sum(t1.q_float_null)' ,'sum(t1.q_double_null)' , + 'STDDEV(t1.q_int_null)' ,'STDDEV(t1.q_bigint_null)' , 'STDDEV(t1.q_smallint_null)' ,'STDDEV(t1.q_tinyint_null)' ,'STDDEV(t1.q_float_null)' ,'STDDEV(t1.q_double_null)', + 'APERCENTILE(t1.q_int_null,10)' ,'APERCENTILE(t1.q_bigint_null,20)' , 'APERCENTILE(t1.q_smallint_null,30)' ,'APERCENTILE(t1.q_tinyint_null,40)' ,'APERCENTILE(t1.q_float_null,50)' ,'APERCENTILE(t1.q_double,60)' , + 'count(t2.*)' , 'count(t2.q_int)' ,'count(t2.q_bigint)' , 'count(t2.q_smallint)' ,'count(t2.q_tinyint)' ,'count(t2.q_float)' , + 'count(t2.q_double)' ,'count(t2.q_binary)' ,'count(t2.q_nchar)' ,'count(t2.q_bool)' ,'count(t2.q_ts)' , + 'avg(t2.q_int)' ,'avg(t2.q_bigint)' , 'avg(t2.q_smallint)' ,'avg(t2.q_tinyint)' ,'avg(t2.q_float)' ,'avg(t2.q_double)' , + 'sum(t2.q_int)' ,'sum(t2.q_bigint)' , 'sum(t2.q_smallint)' ,'sum(t2.q_tinyint)' ,'sum(t2.q_float)' ,'sum(t2.q_double)' , + 'STDDEV(t2.q_int)' ,'STDDEV(t2.q_bigint)' , 'STDDEV(t2.q_smallint)' ,'STDDEV(t2.q_tinyint)' ,'STDDEV(t2.q_float)' ,'STDDEV(t2.q_double)', + 'APERCENTILE(t2.q_int,10)' ,'APERCENTILE(t2.q_bigint,20)' , 'APERCENTILE(t2.q_smallint,30)' ,'APERCENTILE(t2.q_tinyint,40)' ,'APERCENTILE(t2.q_float,50)' ,'APERCENTILE(t2.q_double,60)', + 'count(t2.q_int_null)' ,'count(t2.q_bigint_null)' , 'count(t2.q_smallint_null)' ,'count(t2.q_tinyint_null)' ,'count(t2.q_float_null)' , + 'count(t2.q_double_null)' ,'count(t2.q_binary_null)' ,'count(t2.q_nchar_null)' ,'count(t2.q_bool_null)' ,'count(t2.q_ts_null)' , + 'avg(t2.q_int_null)' ,'avg(t2.q_bigint_null)' , 'avg(t2.q_smallint_null)' ,'avg(t2.q_tinyint_null)' ,'avg(t2.q_float_null)' ,'avg(t2.q_double_null)' , + 'sum(t2.q_int_null)' ,'sum(t2.q_bigint_null)' , 'sum(t2.q_smallint_null)' ,'sum(t2.q_tinyint_null)' ,'sum(t2.q_float_null)' ,'sum(t2.q_double_null)' , + 'STDDEV(t2.q_int_null)' ,'STDDEV(t2.q_bigint_null)' , 'STDDEV(t2.q_smallint_null)' ,'STDDEV(t2.q_tinyint_null)' ,'STDDEV(t2.q_float_null)' ,'STDDEV(t2.q_double_null)', + 'APERCENTILE(t2.q_int_null,10)' ,'APERCENTILE(t2.q_bigint_null,20)' , 'APERCENTILE(t2.q_smallint_null,30)' ,'APERCENTILE(t2.q_tinyint_null,40)' ,'APERCENTILE(t2.q_float_null,50)' ,'APERCENTILE(t2.q_double,60)'] + + self.calc_aggregate_regular_j = ['twa(t1.q_int)' ,'twa(t1.q_bigint)' , 'twa(t1.q_smallint)' ,'twa(t1.q_tinyint)' ,'twa (t1.q_float)' ,'twa(t1.q_double)' , + 'IRATE(t1.q_int)' ,'IRATE(t1.q_bigint)' , 'IRATE(t1.q_smallint)' ,'IRATE(t1.q_tinyint)' ,'IRATE (t1.q_float)' ,'IRATE(t1.q_double)' , + 'LEASTSQUARES(t1.q_int,15,3)' , 'LEASTSQUARES(t1.q_bigint,10,1)' , 'LEASTSQUARES(t1.q_smallint,20,3)' ,'LEASTSQUARES(t1.q_tinyint,10,4)' ,'LEASTSQUARES(t1.q_float,6,4)' ,'LEASTSQUARES(t1.q_double,3,1)' , + 'twa(t2.q_int)' ,'twa(t2.q_bigint)' , 'twa(t2.q_smallint)' ,'twa(t2.q_tinyint)' ,'twa (t2.q_float)' ,'twa(t2.q_double)' , + 'IRATE(t2.q_int)' ,'IRATE(t2.q_bigint)' , 'IRATE(t2.q_smallint)' ,'IRATE(t2.q_tinyint)' ,'IRATE (t2.q_float)' ,'IRATE(t2.q_double)', + 'LEASTSQUARES(t2.q_int,15,3)' , 'LEASTSQUARES(t2.q_bigint,10,1)' , 'LEASTSQUARES(t2.q_smallint,20,3)' ,'LEASTSQUARES(t2.q_tinyint,10,4)' ,'LEASTSQUARES(t2.q_float,6,4)' ,'LEASTSQUARES(t2.q_double,3,1)' , + 'twa(t1.q_int_null)' ,'twa(t1.q_bigint_null)' , 'twa(t1.q_smallint_null)' ,'twa(t1.q_tinyint_null)' ,'twa (t1.q_float_null)' ,'twa(t1.q_double_null)' , + 'IRATE(t1.q_int_null)' ,'IRATE(t1.q_bigint_null)' , 'IRATE(t1.q_smallint_null)' ,'IRATE(t1.q_tinyint_null)' ,'IRATE (t1.q_float_null)' ,'IRATE(t1.q_double_null)' , + 'LEASTSQUARES(t1.q_int_null,15,3)' , 'LEASTSQUARES(t1.q_bigint_null,10,1)' , 'LEASTSQUARES(t1.q_smallint_null,20,3)' ,'LEASTSQUARES(t1.q_tinyint_null,10,4)' ,'LEASTSQUARES(t1.q_float_null,6,4)' ,'LEASTSQUARES(t1.q_double_null,3,1)' , + 'twa(t2.q_int_null)' ,'twa(t2.q_bigint_null)' , 'twa(t2.q_smallint_null)' ,'twa(t2.q_tinyint_null)' ,'twa (t2.q_float_null)' ,'twa(t2.q_double_null)' , + 'IRATE(t2.q_int_null)' ,'IRATE(t2.q_bigint_null)' , 'IRATE(t2.q_smallint_null)' ,'IRATE(t2.q_tinyint_null)' ,'IRATE (t2.q_float_null)' ,'IRATE(t2.q_double_null)', + 'LEASTSQUARES(t2.q_int_null,15,3)' , 'LEASTSQUARES(t2.q_bigint_null,10,1)' , 'LEASTSQUARES(t2.q_smallint_null,20,3)' ,'LEASTSQUARES(t2.q_tinyint_null,10,4)' ,'LEASTSQUARES(t2.q_float_null,6,4)' ,'LEASTSQUARES(t2.q_double_null,3,1)' ] + + self.calc_aggregate_groupbytbname_j = ['twa(t1.q_int)' ,'twa(t1.q_bigint)' , 'twa(t1.q_smallint)' ,'twa(t1.q_tinyint)' ,'twa (t1.q_float)' ,'twa(t1.q_double)' , + 'IRATE(t1.q_int)' ,'IRATE(t1.q_bigint)' , 'IRATE(t1.q_smallint)' ,'IRATE(t1.q_tinyint)' ,'IRATE (t1.q_float)' ,'IRATE(t1.q_double)' , + 'twa(t2.q_int)' ,'twa(t2.q_bigint)' , 'twa(t2.q_smallint)' ,'twa(t2.q_tinyint)' ,'twa (t2.q_float)' ,'twa(t2.q_double)' , + 'IRATE(t2.q_int)' ,'IRATE(t2.q_bigint)' , 'IRATE(t2.q_smallint)' ,'IRATE(t2.q_tinyint)' ,'IRATE (t2.q_float)' ,'IRATE(t2.q_double)' , + 'twa(t1.q_int_null)' ,'twa(t1.q_bigint_null)' , 'twa(t1.q_smallint_null)' ,'twa(t1.q_tinyint_null)' ,'twa (t1.q_float_null)' ,'twa(t1.q_double_null)' , + 'IRATE(t1.q_int_null)' ,'IRATE(t1.q_bigint_null)' , 'IRATE(t1.q_smallint_null)' ,'IRATE(t1.q_tinyint_null)' ,'IRATE (t1.q_float_null)' ,'IRATE(t1.q_double_null)' , + 'twa(t2.q_int_null)' ,'twa(t2.q_bigint_null)' , 'twa(t2.q_smallint_null)' ,'twa(t2.q_tinyint_null)' ,'twa (t2.q_float_null)' ,'twa(t2.q_double_null)' , + 'IRATE(t2.q_int_null)' ,'IRATE(t2.q_bigint_null)' , 'IRATE(t2.q_smallint_null)' ,'IRATE(t2.q_tinyint_null)' ,'IRATE (t2.q_float_null)' ,'IRATE(t2.q_double_null)' ] + + self.calc_calculate_all = ['SPREAD(ts)' , 'SPREAD(q_ts)' , 'SPREAD(q_int)' ,'SPREAD(q_bigint)' , 'SPREAD(q_smallint)' ,'SPREAD(q_tinyint)' ,'SPREAD(q_float)' ,'SPREAD(q_double)' , + '(SPREAD(q_int) + SPREAD(q_bigint))' , '(SPREAD(q_smallint) - SPREAD(q_float))', '(SPREAD(q_double) * SPREAD(q_tinyint))' , '(SPREAD(q_double) / SPREAD(q_float))', + 'SPREAD(q_ts_null)' , 'SPREAD(q_int_null)' ,'SPREAD(q_bigint_null)' , 'SPREAD(q_smallint_null)' ,'SPREAD(q_tinyint_null)' ,'SPREAD(q_float_null)' ,'SPREAD(q_double_null)' , + '(SPREAD(q_int_null) + SPREAD(q_bigint_null))' , '(SPREAD(q_smallint_null) - SPREAD(q_float_null))', '(SPREAD(q_double_null) * SPREAD(q_tinyint_null))' , '(SPREAD(q_double_null) / SPREAD(q_float_null))'] + self.calc_calculate_regular = ['DIFF(q_int)' ,'DIFF(q_bigint)' , 'DIFF(q_smallint)' ,'DIFF(q_tinyint)' ,'DIFF(q_float)' ,'DIFF(q_double)' , + 'DIFF(q_int,0)' ,'DIFF(q_bigint,0)' , 'DIFF(q_smallint,0)' ,'DIFF(q_tinyint,0)' ,'DIFF(q_float,0)' ,'DIFF(q_double,0)' , + 'DIFF(q_int,1)' ,'DIFF(q_bigint,1)' , 'DIFF(q_smallint,1)' ,'DIFF(q_tinyint,1)' ,'DIFF(q_float,1)' ,'DIFF(q_double,1)' , + 'DERIVATIVE(q_int,15s,0)' , 'DERIVATIVE(q_bigint,10s,1)' , 'DERIVATIVE(q_smallint,20s,0)' ,'DERIVATIVE(q_tinyint,10s,1)' ,'DERIVATIVE(q_float,6s,0)' ,'DERIVATIVE(q_double,3s,1)', + 'DIFF(q_int_null)' ,'DIFF(q_bigint_null)' , 'DIFF(q_smallint_null)' ,'DIFF(q_tinyint_null)' ,'DIFF(q_float_null)' ,'DIFF(q_double_null)' , + 'DIFF(q_int_null,0)' ,'DIFF(q_bigint_null,0)' , 'DIFF(q_smallint_null,0)' ,'DIFF(q_tinyint_null,0)' ,'DIFF(q_float_null,0)' ,'DIFF(q_double_null,0)' , + 'DIFF(q_int_null,1)' ,'DIFF(q_bigint_null,1)' , 'DIFF(q_smallint_null,1)' ,'DIFF(q_tinyint_null,1)' ,'DIFF(q_float_null,1)' ,'DIFF(q_double_null,1)' , + 'DERIVATIVE(q_int_null,15s,0)' , 'DERIVATIVE(q_bigint_null,10s,1)' , 'DERIVATIVE(q_smallint_null,20s,0)' ,'DERIVATIVE(q_tinyint_null,10s,1)' ,'DERIVATIVE(q_float_null,6s,0)' ,'DERIVATIVE(q_double_null,3s,1)'] + self.calc_calculate_groupbytbname = self.calc_calculate_regular + + #two table join + self.calc_calculate_all_j = ['SPREAD(t1.ts)' , 'SPREAD(t1.q_ts)' , 'SPREAD(t1.q_int)' ,'SPREAD(t1.q_bigint)' , 'SPREAD(t1.q_smallint)' ,'SPREAD(t1.q_tinyint)' ,'SPREAD(t1.q_float)' ,'SPREAD(t1.q_double)' , + 'SPREAD(t2.ts)' , 'SPREAD(t2.q_ts)' , 'SPREAD(t2.q_int)' ,'SPREAD(t2.q_bigint)' , 'SPREAD(t2.q_smallint)' ,'SPREAD(t2.q_tinyint)' ,'SPREAD(t2.q_float)' ,'SPREAD(t2.q_double)' , + '(SPREAD(t1.q_int) + SPREAD(t1.q_bigint))' , '(SPREAD(t1.q_tinyint) - SPREAD(t1.q_float))', '(SPREAD(t1.q_double) * SPREAD(t1.q_tinyint))' , '(SPREAD(t1.q_double) / SPREAD(t1.q_tinyint))', + '(SPREAD(t2.q_int) + SPREAD(t2.q_bigint))' , '(SPREAD(t2.q_smallint) - SPREAD(t2.q_float))', '(SPREAD(t2.q_double) * SPREAD(t2.q_tinyint))' , '(SPREAD(t2.q_double) / SPREAD(t2.q_tinyint))', + '(SPREAD(t1.q_int) + SPREAD(t1.q_smallint))' , '(SPREAD(t2.q_smallint) - SPREAD(t2.q_float))', '(SPREAD(t1.q_double) * SPREAD(t1.q_tinyint))' , '(SPREAD(t1.q_double) / SPREAD(t1.q_float))', + 'SPREAD(t1.q_ts_null)' , 'SPREAD(t1.q_int_null)' ,'SPREAD(t1.q_bigint_null)' , 'SPREAD(t1.q_smallint_null)' ,'SPREAD(t1.q_tinyint_null)' ,'SPREAD(t1.q_float_null)' ,'SPREAD(t1.q_double_null)' , + 'SPREAD(t2.q_ts_null)' , 'SPREAD(t2.q_int_null)' ,'SPREAD(t2.q_bigint_null)' , 'SPREAD(t2.q_smallint_null)' ,'SPREAD(t2.q_tinyint_null)' ,'SPREAD(t2.q_float_null)' ,'SPREAD(t2.q_double_null)' , + '(SPREAD(t1.q_int_null) + SPREAD(t1.q_bigint_null))' , '(SPREAD(t1.q_tinyint_null) - SPREAD(t1.q_float_null))', '(SPREAD(t1.q_double_null) * SPREAD(t1.q_tinyint_null))' , '(SPREAD(t1.q_double_null) / SPREAD(t1.q_tinyint_null))', + '(SPREAD(t2.q_int_null) + SPREAD(t2.q_bigint_null))' , '(SPREAD(t2.q_smallint_null) - SPREAD(t2.q_float_null))', '(SPREAD(t2.q_double_null) * SPREAD(t2.q_tinyint_null))' , '(SPREAD(t2.q_double_null) / SPREAD(t2.q_tinyint_null))', + '(SPREAD(t1.q_int_null) + SPREAD(t1.q_smallint_null))' , '(SPREAD(t2.q_smallint_null) - SPREAD(t2.q_float_null))', '(SPREAD(t1.q_double_null) * SPREAD(t1.q_tinyint_null))' , '(SPREAD(t1.q_double_null) / SPREAD(t1.q_float_null))'] + self.calc_calculate_regular_j = ['DIFF(t1.q_int)' ,'DIFF(t1.q_bigint)' , 'DIFF(t1.q_smallint)' ,'DIFF(t1.q_tinyint)' ,'DIFF(t1.q_float)' ,'DIFF(t1.q_double)' , + 'DIFF(t1.q_int,0)' ,'DIFF(t1.q_bigint,0)' , 'DIFF(t1.q_smallint,0)' ,'DIFF(t1.q_tinyint,0)' ,'DIFF(t1.q_float,0)' ,'DIFF(t1.q_double,0)' , + 'DIFF(t1.q_int,1)' ,'DIFF(t1.q_bigint,1)' , 'DIFF(t1.q_smallint,1)' ,'DIFF(t1.q_tinyint,1)' ,'DIFF(t1.q_float,1)' ,'DIFF(t1.q_double,1)' , + 'DERIVATIVE(t1.q_int,15s,0)' , 'DERIVATIVE(t1.q_bigint,10s,1)' , 'DERIVATIVE(t1.q_smallint,20s,0)' ,'DERIVATIVE(t1.q_tinyint,10s,1)' ,'DERIVATIVE(t1.q_float,6s,0)' ,'DERIVATIVE(t1.q_double,3s,1)' , + 'DIFF(t2.q_int)' ,'DIFF(t2.q_bigint)' , 'DIFF(t2.q_smallint)' ,'DIFF(t2.q_tinyint)' ,'DIFF(t2.q_float)' ,'DIFF(t2.q_double)' , + 'DIFF(t2.q_int,0)' ,'DIFF(t2.q_bigint,0)' , 'DIFF(t2.q_smallint,0)' ,'DIFF(t2.q_tinyint,0)' ,'DIFF(t2.q_float,0)' ,'DIFF(t2.q_double,0)' , + 'DIFF(t2.q_int,1)' ,'DIFF(t2.q_bigint,1)' , 'DIFF(t2.q_smallint,1)' ,'DIFF(t2.q_tinyint,1)' ,'DIFF(t2.q_float,1)' ,'DIFF(t2.q_double,1)' , + 'DERIVATIVE(t2.q_int,15s,0)' , 'DERIVATIVE(t2.q_bigint,10s,1)' , 'DERIVATIVE(t2.q_smallint,20s,0)' ,'DERIVATIVE(t2.q_tinyint,10s,1)' ,'DERIVATIVE(t2.q_float,6s,0)' ,'DERIVATIVE(t2.q_double,3s,1)' , + 'DIFF(t1.q_int_null)' ,'DIFF(t1.q_bigint_null)' , 'DIFF(t1.q_smallint_null)' ,'DIFF(t1.q_tinyint_null)' ,'DIFF(t1.q_float_null)' ,'DIFF(t1.q_double_null)' , + 'DIFF(t1.q_int_null,0)' ,'DIFF(t1.q_bigint_null,0)' , 'DIFF(t1.q_smallint_null,0)' ,'DIFF(t1.q_tinyint_null,0)' ,'DIFF(t1.q_float_null,0)' ,'DIFF(t1.q_double_null,0)' , + 'DIFF(t1.q_int_null,1)' ,'DIFF(t1.q_bigint_null,1)' , 'DIFF(t1.q_smallint_null,1)' ,'DIFF(t1.q_tinyint_null,1)' ,'DIFF(t1.q_float_null,1)' ,'DIFF(t1.q_double_null,1)' , + 'DERIVATIVE(t1.q_int_null,15s,0)' , 'DERIVATIVE(t1.q_bigint_null,10s,1)' , 'DERIVATIVE(t1.q_smallint_null,20s,0)' ,'DERIVATIVE(t1.q_tinyint_null,10s,1)' ,'DERIVATIVE(t1.q_float_null,6s,0)' ,'DERIVATIVE(t1.q_double_null,3s,1)' , + 'DIFF(t2.q_int_null)' ,'DIFF(t2.q_bigint_null)' , 'DIFF(t2.q_smallint_null)' ,'DIFF(t2.q_tinyint_null)' ,'DIFF(t2.q_float_null)' ,'DIFF(t2.q_double_null)' , + 'DIFF(t2.q_int_null,0)' ,'DIFF(t2.q_bigint_null,0)' , 'DIFF(t2.q_smallint_null,0)' ,'DIFF(t2.q_tinyint_null,0)' ,'DIFF(t2.q_float_null,0)' ,'DIFF(t2.q_double_null,0)' , + 'DIFF(t2.q_int_null,1)' ,'DIFF(t2.q_bigint_null,1)' , 'DIFF(t2.q_smallint_null,1)' ,'DIFF(t2.q_tinyint_null,1)' ,'DIFF(t2.q_float_null,1)' ,'DIFF(t2.q_double_null,1)' , + 'DERIVATIVE(t2.q_int_null,15s,0)' , 'DERIVATIVE(t2.q_bigint_null,10s,1)' , 'DERIVATIVE(t2.q_smallint_null,20s,0)' ,'DERIVATIVE(t2.q_tinyint_null,10s,1)' ,'DERIVATIVE(t2.q_float_null,6s,0)' ,'DERIVATIVE(t2.q_double_null,3s,1)'] + self.calc_calculate_groupbytbname_j = self.calc_calculate_regular_j + + self.interval_sliding = ['interval(4w) sliding(1w) ','interval(1w) sliding(1d) ','interval(1d) sliding(1h) ' , + 'interval(1h) sliding(1m) ','interval(1m) sliding(1s) ','interval(1s) sliding(10a) ', + 'interval(1y) ','interval(1n) ','interval(1w) ','interval(1d) ','interval(1h) ','interval(1m) ','interval(1s) ' ,'interval(10a)', + 'interval(1y,1n) ','interval(1n,1w) ','interval(1w,1d) ','interval(1d,1h) ','interval(1h,1m) ','interval(1m,1s) ','interval(1s,10a) ' ,'interval(100a,30a)'] + + self.conn1 = taos.connect(host="127.0.0.1", user="root", password="taosdata", config="/etc/taos/") + self.cur1 = self.conn1.cursor() + self.cur1.execute("use %s ;" %self.db_nest) + sql = 'select * from stable_1 limit 5;' + self.cur1.execute(sql) + + + def dropandcreateDB_random(self,database,n): + ts = 1630000000000 + num_random = 100 + fake = Faker('zh_CN') + tdSql.execute('''drop database if exists %s ;''' %database) + tdSql.execute('''create database %s keep 36500;'''%database) + tdSql.execute('''use %s;'''%database) + + tdSql.execute('''create stable stable_1 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ + tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') + tdSql.execute('''create stable stable_2 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ + tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') + + tdSql.execute('''create stable stable_null_data (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ + tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') + + tdSql.execute('''create stable stable_null_childtable (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ + tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''') + + tdSql.execute('''create table stable_1_1 using stable_1 tags('stable_1_1', '%d' , '%d', '%d' , '%d' , 0 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + tdSql.execute('''create table stable_1_2 using stable_1 tags('stable_1_2', '2147483647' , '9223372036854775807' , '32767' , '127' , 1 , 'binary2' , 'nchar2' , '2' , '22' , \'1999-09-09 09:09:09.090\') ;''') + tdSql.execute('''create table stable_1_3 using stable_1 tags('stable_1_3', '-2147483647' , '-9223372036854775807' , '-32767' , '-127' , false , 'binary3' , 'nchar3nchar3' , '-3.3' , '-33.33' , \'2099-09-09 09:09:09.090\') ;''') + tdSql.execute('''create table stable_1_4 using stable_1 tags('stable_1_4', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + + tdSql.execute('''create table stable_2_1 using stable_2 tags('stable_2_1' , '0' , '0' , '0' , '0' , 0 , 'binary21' , 'nchar21' , '0' , '0' ,\'2099-09-09 09:09:09.090\') ;''') + tdSql.execute('''create table stable_2_2 using stable_2 tags('stable_2_2' , '%d' , '%d', '%d' , '%d' , 0 , 'binary2.%s' , 'nchar2.%s' , '%f', '%f' ,'%d') ;''' + %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + + tdSql.execute('''create table stable_null_data_1 using stable_null_data tags('stable_null_data_1', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + + #regular table + tdSql.execute('''create table regular_table_1 \ + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') + tdSql.execute('''create table regular_table_2 \ + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') + tdSql.execute('''create table regular_table_3 \ + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') + + tdSql.execute('''create table regular_table_null \ + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;''') + + + for i in range(num_random*n): + tdSql.execute('''insert into stable_1_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double , q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1), + fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + tdSql.execute('''insert into regular_table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1) , + fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1) , + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8)\ + values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000, fake.random_int(min=0, max=2147483647, step=1), + fake.random_int(min=0, max=9223372036854775807, step=1), + fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000, fake.random_int(min=0, max=2147483647, step=1), + fake.random_int(min=0, max=9223372036854775807, step=1), + fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), + fake.random_int(min=-9223372036854775807, max=0, step=1), + fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i +1, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), + fake.random_int(min=-9223372036854775807, max=0, step=1), + fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i +1, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000, fake.random_int(min=-0, max=2147483647, step=1), + fake.random_int(min=-0, max=9223372036854775807, step=1), + fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000 +1, fake.random_int(min=-0, max=2147483647, step=1), + fake.random_int(min=-0, max=9223372036854775807, step=1), + fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (ts + i*1000 +10, fake.random_int(min=-0, max=2147483647, step=1), + fake.random_int(min=-0, max=9223372036854775807, step=1), + fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.query("select count(*) from stable_1;") + tdSql.checkData(0,0,3*num_random*n) + tdSql.query("select count(*) from regular_table_1;") + tdSql.checkData(0,0,num_random*n) + + def explain_sql(self,sql): + # #执行sql解析 + sql = "explain " + sql + tdLog.info(sql) + tdSql.query(sql) + + def data_check(self,sql,mark='mark') : + tdLog.info("========mark==%s==="% mark); + try: + tdSql.query(sql,queryTimes=1) + except: + tdLog.info("sql is not support :=====%s; " %sql) + tdSql.error(sql) + + + def math_nest(self,mathlist): + + print("==========%s===start=============" %mathlist) + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + #self.dropandcreateDB_random("%s" %self.db_nest, 1) + + if (mathlist == ['ABS','SQRT']) or (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['FLOOR','CEIL','ROUND']) \ + or (mathlist == ['CSUM']) : + math_functions = mathlist + fun_fix_column = ['(q_bigint)','(q_smallint)','(q_tinyint)','(q_int)','(q_float)','(q_double)','(q_bigint_null)','(q_smallint_null)','(q_tinyint_null)','(q_int_null)','(q_float_null)','(q_double_null)'] + fun_column_1 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_2 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_j = ['(t1.q_bigint)','(t1.q_smallint)','(t1.q_tinyint)','(t1.q_int)','(t1.q_float)','(t1.q_double)','(t1.q_bigint_null)','(t1.q_smallint_null)','(t1.q_tinyint_null)','(t1.q_int_null)','(t1.q_float_null)','(t1.q_double_null)', + '(t2.q_bigint)','(t2.q_smallint)','(t2.q_tinyint)','(t2.q_int)','(t2.q_float)','(t2.q_double)','(t2.q_bigint_null)','(t2.q_smallint_null)','(t2.q_tinyint_null)','(t2.q_int_null)','(t2.q_float_null)','(t2.q_double_null)'] + fun_column_join_1 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_join_2 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + elif (mathlist == ['UNIQUE']) or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['MODE']) : + math_functions = mathlist + fun_fix_column = ['(q_bigint)','(q_smallint)','(q_tinyint)','(q_int)','(q_float)','(q_double)','(q_binary)','(q_nchar)','(q_bool)','(q_ts)', + '(q_bigint_null)','(q_smallint_null)','(q_tinyint_null)','(q_int_null)','(q_float_null)','(q_double_null)','(q_binary_null)','(q_nchar_null)','(q_bool_null)','(q_ts_null)'] + fun_column_1 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_2 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_j = ['(t1.q_bigint)','(t1.q_smallint)','(t1.q_tinyint)','(t1.q_int)','(t1.q_float)','(t1.q_double)','(t1.q_bigint_null)','(t1.q_smallint_null)','(t1.q_tinyint_null)','(t1.q_int_null)','(t1.q_float_null)','(t1.q_double_null)','(t1.q_ts)','(t1.q_ts_null)', + '(t2.q_bigint)','(t2.q_smallint)','(t2.q_tinyint)','(t2.q_int)','(t2.q_float)','(t2.q_double)','(t2.q_bigint_null)','(t2.q_smallint_null)','(t2.q_tinyint_null)','(t2.q_int_null)','(t2.q_float_null)','(t2.q_double_null)','(t2.q_ts)','(t2.q_ts_null)'] + fun_column_join_1 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_join_2 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + elif (mathlist == ['TAIL']): + math_functions = mathlist + num = random.randint(1, 100) + offset_rows = random.randint(0, 100) + fun_fix_column = ['(q_bigint,num)','(q_smallint,num)','(q_tinyint,num)','(q_int,num)','(q_float,num)','(q_double,num)','(q_binary,num)','(q_nchar,num)','(q_bool,num)','(q_ts,num)', + '(q_bigint_null,num)','(q_smallint_null,num)','(q_tinyint_null,num)','(q_int_null,num)','(q_float_null,num)','(q_double_null,num)','(q_binary_null,num)','(q_nchar_null,num)','(q_bool_null,num)','(q_ts_null,num)', + '(q_bigint,num,offset_rows)','(q_smallint,num,offset_rows)','(q_tinyint,num,offset_rows)','(q_int,num,offset_rows)','(q_float,num,offset_rows)','(q_double,num,offset_rows)','(q_binary,num,offset_rows)','(q_nchar,num,offset_rows)','(q_bool,num,offset_rows)','(q_ts,num,offset_rows)', + '(q_bigint_null,num,offset_rows)','(q_smallint_null,num,offset_rows)','(q_tinyint_null,num,offset_rows)','(q_int_null,num,offset_rows)','(q_float_null,num,offset_rows)','(q_double_null,num,offset_rows)','(q_binary_null,num,offset_rows)','(q_nchar_null,num,offset_rows)','(q_bool_null,num,offset_rows)','(q_ts_null,num,offset_rows)'] + fun_column_1 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)).replace("offset_rows",str(offset_rows)) + fun_column_2 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)).replace("offset_rows",str(offset_rows)) + + fun_fix_column_j = ['(t1.q_bigint,num)','(t1.q_smallint,num)','(t1.q_tinyint,num)','(t1.q_int,num)','(t1.q_float,num)','(t1.q_double,num)','(t1.q_binary,num)','(t1.q_nchar,num)','(t1.q_bool,num)','(t1.q_ts,num)', + '(t1.q_bigint_null,num)','(t1.q_smallint_null,num)','(t1.q_tinyint_null,num)','(t1.q_int_null,num)','(t1.q_float_null,num)','(t1.q_double_null,num)','(t1.q_binary_null,num)','(t1.q_nchar_null,num)','(t1.q_bool_null,num)','(t1.q_ts_null,num)', + '(t2.q_bigint,num)','(t2.q_smallint,num)','(t2.q_tinyint,num)','(t2.q_int,num)','(t2.q_float,num)','(t2.q_double,num)','(t2.q_binary,num)','(t2.q_nchar,num)','(t2.q_bool,num)','(t2.q_ts,num)', + '(t2.q_bigint_null,num)','(t2.q_smallint_null,num)','(t2.q_tinyint_null,num)','(t2.q_int_null,num)','(t2.q_float_null,num)','(t2.q_double_null,num)','(t2.q_binary_null,num)','(t2.q_nchar_null,num)','(t2.q_bool_null,num)','(t2.q_ts_null,num)', + '(t1.q_bigint,num,offset_rows)','(t1.q_smallint,num,offset_rows)','(t1.q_tinyint,num,offset_rows)','(t1.q_int,num,offset_rows)','(t1.q_float,num,offset_rows)','(t1.q_double,num,offset_rows)','(t1.q_binary,num,offset_rows)','(t1.q_nchar,num,offset_rows)','(t1.q_bool,num,offset_rows)','(t1.q_ts,num,offset_rows)', + '(t1.q_bigint_null,num,offset_rows)','(t1.q_smallint_null,num,offset_rows)','(t1.q_tinyint_null,num,offset_rows)','(t1.q_int_null,num,offset_rows)','(t1.q_float_null,num,offset_rows)','(t1.q_double_null,num,offset_rows)','(t1.q_binary_null,num,offset_rows)','(t1.q_nchar_null,num,offset_rows)','(t1.q_bool_null,num,offset_rows)','(t1.q_ts_null,num,offset_rows)', + '(t2.q_bigint,num,offset_rows)','(t2.q_smallint,num,offset_rows)','(t2.q_tinyint,num,offset_rows)','(t2.q_int,num,offset_rows)','(t2.q_float,num,offset_rows)','(t2.q_double,num,offset_rows)','(t2.q_binary,num,offset_rows)','(t2.q_nchar,num,offset_rows)','(t2.q_bool,num,offset_rows)','(t2.q_ts,num,offset_rows)', + '(t2.q_bigint_null,num,offset_rows)','(t2.q_smallint_null,num,offset_rows)','(t2.q_tinyint_null,num,offset_rows)','(t2.q_int_null,num,offset_rows)','(t2.q_float_null,num,offset_rows)','(t2.q_double_null,num,offset_rows)','(t2.q_binary_null,num,offset_rows)','(t2.q_nchar_null,num,offset_rows)','(t2.q_bool_null,num,offset_rows)','(t2.q_ts_null,num,offset_rows)'] + fun_column_join_1 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)).replace("offset_rows",str(offset_rows)) + fun_column_join_2 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)).replace("offset_rows",str(offset_rows)) + + elif (mathlist == ['POW','LOG']) or (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) : + math_functions = mathlist + num = random.randint(1, 1000) + fun_fix_column = ['(q_bigint,num)','(q_smallint,num)','(q_tinyint,num)','(q_int,num)','(q_float,num)','(q_double,num)', + '(q_bigint_null,num)','(q_smallint_null,num)','(q_tinyint_null,num)','(q_int_null,num)','(q_float_null,num)','(q_double_null,num)'] + fun_column_1 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) + fun_column_2 = random.sample(math_functions,1)+random.sample(fun_fix_column,1) + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) + + fun_fix_column_j = ['(t1.q_bigint,num)','(t1.q_smallint,num)','(t1.q_tinyint,num)','(t1.q_int,num)','(t1.q_float,num)','(t1.q_double,num)', + '(t1.q_bigint_null,num)','(t1.q_smallint_null,num)','(t1.q_tinyint_null,num)','(t1.q_int_null,num)','(t1.q_float_null,num)','(t1.q_double_null,num)', + '(t2.q_bigint,num)','(t2.q_smallint,num)','(t2.q_tinyint,num)','(t2.q_int,num)','(t2.q_float,num)','(t2.q_double,num)', + '(t2.q_bigint_null,num)','(t2.q_smallint_null,num)','(t2.q_tinyint_null,num)','(t2.q_int_null,num)','(t2.q_float_null,num)','(t2.q_double_null,num)'] + fun_column_join_1 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) + fun_column_join_2 = random.sample(math_functions,1)+random.sample(fun_fix_column_j,1) + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("num",str(num)) + + elif (mathlist == ['statecount','stateduration']): + math_functions = mathlist + num = random.randint(-1000, 1000) + + operator = ['LT' , 'GT' ,'GE','NE','EQ'] + oper = str(random.sample(operator,1)).replace("[","").replace("]","")#.replace("'","") + + fun_fix_column = ['(q_bigint,oper,num,time)','(q_smallint,oper,num,time)','(q_tinyint,oper,num,time)','(q_int,oper,num,time)','(q_float,oper,num,time)','(q_double,oper,num,time)', + '(q_bigint_null,oper,num,time)','(q_smallint_null,oper,num,time)','(q_tinyint_null,oper,num,time)','(q_int_null,oper,num,time)','(q_float_null,oper,num,time)','(q_double_null,oper,num,time)'] + + hanshu_select1 = random.sample(math_functions,1) + fun_column_1 = random.sample(hanshu_select1,1)+random.sample(fun_fix_column,1) + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + + if str(hanshu_select1).replace("[","").replace("]","").replace("'","") == 'statecount': + math_fun_1 = math_fun_1.replace("oper","%s" %oper).replace(",time","").replace("num",str(num)) + elif str(hanshu_select1).replace("[","").replace("]","").replace("'","") == 'stateduration': + timeunit = ['1s' , '1m' ,'1h'] + time = str(random.sample(timeunit,1)).replace("[","").replace("]","").replace("'","") + math_fun_1 = math_fun_1.replace("oper","%s" %oper).replace("time","%s" %time).replace("num",str(num)) + + hanshu_select2 = random.sample(math_functions,1) + fun_column_2 = random.sample(hanshu_select2,1)+random.sample(fun_fix_column,1) + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + if str(hanshu_select2).replace("[","").replace("]","").replace("'","") == 'statecount': + math_fun_2 = math_fun_2.replace("oper","%s" %oper).replace(",time","").replace("num",str(num)) + elif str(hanshu_select2).replace("[","").replace("]","").replace("'","") == 'stateduration': + timeunit = ['1s' , '1m' ,'1h'] + time = str(random.sample(timeunit,1)).replace("[","").replace("]","").replace("'","") + math_fun_2 = math_fun_2.replace("oper","%s" %oper).replace("time","%s" %time).replace("num",str(num)) + + fun_fix_column_j = ['(t1.q_bigint,oper,num,time)','(t1.q_smallint,oper,num,time)','(t1.q_tinyint,oper,num,time)','(t1.q_int,oper,num,time)','(t1.q_float,oper,num,time)','(t1.q_double,oper,num,time)', + '(t1.q_bigint_null,oper,num,time)','(t1.q_smallint_null,oper,num,time)','(t1.q_tinyint_null,oper,num,time)','(t1.q_int_null,oper,num,time)','(t1.q_float_null,oper,num,time)','(t1.q_double_null,oper,num,time)', + '(t2.q_bigint,oper,num,time)','(t2.q_smallint,oper,num,time)','(t2.q_tinyint,oper,num,time)','(t2.q_int,oper,num,time)','(t2.q_float,oper,num,time)','(t2.q_double,oper,num,time)', + '(t2.q_bigint_null,oper,num,time)','(t2.q_smallint_null,oper,num,time)','(t2.q_tinyint_null,oper,num,time)','(t2.q_int_null,oper,num,time)','(t2.q_float_null,oper,num,time)','(t2.q_double_null,oper,num,time)'] + + hanshu_select_join_1 = random.sample(math_functions,1) + fun_column_join_1 = random.sample(hanshu_select_join_1,1)+random.sample(fun_fix_column_j,1) + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + + if str(hanshu_select_join_1).replace("[","").replace("]","").replace("'","") == 'statecount': + math_fun_join_1 = math_fun_join_1.replace("oper","%s" %oper).replace(",time","").replace("num",str(num)) + elif str(hanshu_select_join_1).replace("[","").replace("]","").replace("'","") == 'stateduration': + timeunit = ['1s' , '1m' ,'1h'] + time = str(random.sample(timeunit,1)).replace("[","").replace("]","").replace("'","") + math_fun_join_1 = math_fun_join_1.replace("oper","%s" %oper).replace("time","%s" %time).replace("num",str(num)) + + hanshu_select_join_2 = random.sample(math_functions,1) + fun_column_join_2 = random.sample(hanshu_select_join_2,1)+random.sample(fun_fix_column_j,1) + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + if str(hanshu_select_join_2).replace("[","").replace("]","").replace("'","") == 'statecount': + math_fun_join_2 = math_fun_join_2.replace("oper","%s" %oper).replace(",time","").replace("num",str(num)) + elif str(hanshu_select_join_2).replace("[","").replace("]","").replace("'","") == 'stateduration': + timeunit = ['1s' , '1m' ,'1h'] + time = str(random.sample(timeunit,1)).replace("[","").replace("]","").replace("'","") + math_fun_join_2 = math_fun_join_2.replace("oper","%s" %oper).replace("time","%s" %time).replace("num",str(num)) + + elif(mathlist == ['HISTOGRAM']) : + math_functions = mathlist + fun_fix_column = ['(q_bigint','(q_smallint','(q_tinyint','(q_int','(q_float','(q_double','(q_bigint_null','(q_smallint_null','(q_tinyint_null','(q_int_null','(q_float_null','(q_double_null'] + + fun_fix_column_j = ['(t1.q_bigint','(t1.q_smallint','(t1.q_tinyint','(t1.q_int','(t1.q_float','(t1.q_double','(t1.q_bigint_null','(t1.q_smallint_null','(t1.q_tinyint_null','(t1.q_int_null','(t1.q_float_null','(t1.q_double_null', + '(t2.q_bigint','(t2.q_smallint','(t2.q_tinyint','(t2.q_int','(t2.q_float','(t2.q_double','(t2.q_bigint_null','(t2.q_smallint_null','(t2.q_tinyint_null','(t2.q_int_null','(t2.q_float_null','(t2.q_double_null'] + + normalized = random.randint(0, 1) + + i = random.randint(1,3) + if i == 1: + bin_type = 'user_input' + bin_description = {-11111119395555977777} #9一会转译成, + fun_column_1 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',',"'%s'" % bin_description, ',', "%d" %normalized,')'] + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("{","[").replace("}","]").replace("9",",") + + fun_column_2 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',',"'%s'" % bin_description, ',', "%d" %normalized,')'] + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("{","[").replace("}","]").replace("9",",") + + fun_column_join_1 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',',"'%s'" % bin_description, ',', "%d" %normalized,')'] + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("{","[").replace("}","]").replace("9",",") + + fun_column_join_2 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',',"'%s'" % bin_description, ',', "%d" %normalized,')'] + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("{","[").replace("}","]").replace("9",",") + + elif i == 2: + bin_type = 'linear_bin' + true_false = random.randint(10, 11) + bin_description = {"ZstartZ": -333339, "ZwidthZ":559, "ZcountZ":59, "ZinfinityZ":'%d' %true_false} #Z一会转译成" ,9一会转译成 , + fun_column_1 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_2 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_join_1 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_join_2 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + elif i == 3: + bin_type = 'log_bin' + true_false = random.randint(10, 11) + bin_description = {"ZstartZ": -333339, "ZfactorZ":559, "ZcountZ":59, "ZinfinityZ":'%d' %true_false} #Z一会转译成" ,9一会转译成 , + fun_column_1 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_2 = [math_functions , random.sample(fun_fix_column,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_join_1 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + fun_column_join_2 = [math_functions , random.sample(fun_fix_column_j,1), ',',"'%s'" %bin_type, ',','%s' % bin_description, ',', "%d" %normalized,')'] + math_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("9",",").replace("Z","\"").replace("10","false").replace("11","true").replace("\"{","'{").replace("}\"","}'") + + tdSql.query("select 1-1 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']): + sql = "select %s as asct1, " % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts1 from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select %s as asct1 " % math_fun_1 + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-2 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "(select %s as asct1, " % math_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s )" % random.choice(self.order_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "(select %s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']): + sql = "(select %s as asct1 " % math_fun_1 + sql += "from regular_table_1 where " + sql += "%s )" % random.choice(self.q_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "(select %s as asct2 " % math_fun_2 + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-3 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "(select %s as asct1, ts ," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ") %s (select " % random.choice(self.unionall_or_union) + sql += "%s as asct2, ts ," % math_fun_2 + sql += "%s as asct1, " % math_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += " from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MODE']) : + sql = "(select %s as asct1," % math_fun_1 + sql += "%s as asct2 " % math_fun_2 + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ") %s (select " % random.choice(self.unionall_or_union) + sql += "%s as asct2 ," % math_fun_2 + sql += "%s as asct1 " % math_fun_1 + sql += " from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['statecount','stateduration']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['TAIL']) or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['SAMPLE']): + sql = "(select %s as asct1 " % math_fun_1 + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ") %s (select " % random.choice(self.unionall_or_union) + sql += "%s as asct1 " % math_fun_2 + sql += " from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += " order by asct1 asc " + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-4 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1,ts2 ,timediff(ts1,ts2), asct1 from ( select t1.ts as ts1," + sql += "%s as asct0, " % math_fun_join_1 + sql += "%s as asct1, " % math_fun_join_2 + sql += "%s as asct2, " % math_fun_join_1 + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct22, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_join_2 + sql += "from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-5 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts ," + sql += "%s, " % math_fun_1 + sql += "%s as asct1, " % random.choice(self.q_select) + sql += "%s as asct2, " % random.choice(self.q_select) + sql += "%s " % math_fun_2 + sql += " from regular_table_1" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select " + sql += "%s " % math_fun_2 + sql += " from regular_table_1" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-6 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1 ,timediff(ts1,ts2), max(asct1) from ( select t1.ts,t1.ts as ts1," + sql += "%s as asct0, " % math_fun_join_1 + sql += "%s as asct1, " % math_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t2.%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % math_fun_join_1 + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_join_2 + sql += "from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-7 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1,ts2 , abs(asct1) from ( select " + sql += "%s as asct1, ts as ts1," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as ts2 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_1 + sql += "from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-8 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select %s, " % random.choice(self.s_s_select) + sql += "%s as asct1, ts as ts1," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as ts2 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select %s as asct1 " % math_fun_1 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-9 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select %s, " % math_fun_join_1 + sql += "%s as asct1, " % math_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct21, " % random.choice(self.q_select) + sql += "t2.%s as asct22, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select %s as asct1 " % math_fun_join_2 + sql += "from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-10 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "(select %s as asct1 ," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "(select " + sql += "%s as asct1 ," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "(select %s as asct1 " % math_fun_1 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "(select " + sql += "%s as asct2 " % math_fun_2 + sql += "from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #3 inter union not support + tdSql.query("select 1-11 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "(select %s as asct1, ts ," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as t2ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " ) %s (" % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1, ts as t1ts," % math_fun_1 + sql += "%s as asct2, " % math_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as t2ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select %s as asct1 " % math_fun_1 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct2 " % math_fun_2 + sql += " from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-12 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1,ts2 ,timediff(ts1,ts2), max(asct1) from ( select t1.ts as ts1," + sql += "%s, " % math_fun_join_1 + sql += "%s as asct1, " % math_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct21, " % random.choice(self.q_select) + sql += "t2.%s as asct111, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_join_2 + sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-13 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts ," + sql += "%s as asct11, " % math_fun_1 + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % random.choice(self.q_select) + sql += "%s as asct14, " % math_fun_2 + sql += "%s as asct15 " % random.choice(self.t_select) + sql += " from stable_1 " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select " + sql += "%s " % math_fun_2 + sql += "%s " % random.choice(self.t_select) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-14 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select avg(asct1),count(asct2) from ( select " + sql += "%s as asct1, " % math_fun_1 + sql += "%s as asct2" % math_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE'])or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_1 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-15 as math_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (mathlist == ['SIN','COS','TAN','ASIN','ACOS','ATAN']) or (mathlist == ['ABS','SQRT']) \ + or (mathlist == ['POW','LOG']) or (mathlist == ['FLOOR','CEIL','ROUND']) : + sql = "select ts1,ts ,timediff(ts1,ts), max(asct1) from ( select t1.ts as ts1," + sql += "%s, " % math_fun_join_1 + sql += "%s as asct1, " % math_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (mathlist == ['MAVG']) or (mathlist == ['SAMPLE']) or (mathlist == ['TAIL']) or (mathlist == ['CSUM']) or (mathlist == ['HISTOGRAM']) \ + or (mathlist == ['HYPERLOGLOG']) or (mathlist == ['UNIQUE']) or (mathlist == ['MODE']) or (mathlist == ['statecount','stateduration']) : + sql = "select count(asct1) from ( select " + sql += "%s as asct1 " % math_fun_join_2 + sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #taos -f sql + # startTime_taosf = time.time() + print("taos -f %s sql start!" %mathlist) + # taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) + # _ = subprocess.check_output(taos_cmd1, shell=True) + print("taos -f %s sql over!" %mathlist) + + print("=========%s====over=============" %mathlist) + + + def str_nest(self,strlist): + + print("==========%s===start=============" %strlist) + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + #self.dropandcreateDB_random("%s" %self.db_nest, 1) + + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['LENGTH','CHAR_LENGTH']) \ + or (strlist == ['']): + str_functions = strlist + fun_fix_column = ['(q_nchar)','(q_binary)','(q_nchar_null)','(q_binary_null)'] + fun_column_1 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) + str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_2 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) + str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_j = ['(t1.q_nchar)','(t1.q_binary)','(t1.q_nchar_null)','(t1.q_binary_null)', + '(t2.q_nchar)','(t2.q_binary)','(t2.q_nchar_null)','(t2.q_binary_null)'] + fun_column_join_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_join_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_s = ['(q_nchar)','(q_binary)','(q_nchar_null)','(q_binary_null)','(loc)','(tbname)'] + fun_column_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) + str_fun_s_1 = str(fun_column_s_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) + str_fun_s_2 = str(fun_column_s_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_s_j = ['(t1.q_nchar)','(t1.q_binary)','(t1.q_nchar_null)','(t1.q_binary_null)','(t1.loc)','(t1.tbname)', + '(t2.q_nchar)','(t2.q_binary)','(t2.q_nchar_null)','(t2.q_binary_null)','(t2.loc)','(t2.tbname)'] + fun_column_join_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_s_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_join_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_s_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + elif (strlist == ['SUBSTR']) : + str_functions = strlist + pos = random.randint(1, 20) + sub_len = random.randint(1, 10) + fun_fix_column = ['(q_nchar,pos)','(q_binary,pos)','(q_nchar_null,pos)','(q_binary_null,pos)', + '(q_nchar,pos,sub_len)','(q_binary,pos,sub_len)','(q_nchar_null,pos,sub_len)','(q_binary_null,pos,sub_len)',] + fun_column_1 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) + str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + fun_column_2 = random.sample(str_functions,1)+random.sample(fun_fix_column,1) + str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + + fun_fix_column_j = ['(t1.q_nchar,pos)','(t1.q_binary,pos)','(t1.q_nchar_null,pos)','(t1.q_binary_null,pos)', + '(t1.q_nchar,pos,sub_len)','(t1.q_binary,pos,sub_len)','(t1.q_nchar_null,pos,sub_len)','(t1.q_binary_null,pos,sub_len)', + '(t2.q_nchar,pos)','(t2.q_binary,pos)','(t2.q_nchar_null,pos)','(t2.q_binary_null,pos)', + '(t2.q_nchar,pos,sub_len)','(t2.q_binary,pos,sub_len)','(t2.q_nchar_null,pos,sub_len)','(t2.q_binary_null,pos,sub_len)'] + fun_column_join_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + fun_column_join_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_j,1) + str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + + fun_fix_column_s = ['(q_nchar,pos)','(q_binary,pos)','(q_nchar_null,pos)','(q_binary_null,pos)','(loc,pos)', + '(q_nchar,pos,sub_len)','(q_binary,pos,sub_len)','(q_nchar_null,pos,sub_len)','(q_binary_null,pos,sub_len)','(loc,pos,sub_len)',] + fun_column_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) + str_fun_s_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + fun_column_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_s,1) + str_fun_s_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + + fun_fix_column_s_j = ['(t1.q_nchar,pos)','(t1.q_binary,pos)','(t1.q_nchar_null,pos)','(t1.q_binary_null,pos)','(t1.loc,pos)', + '(t1.q_nchar,pos,sub_len)','(t1.q_binary,pos,sub_len)','(t1.q_nchar_null,pos,sub_len)','(t1.q_binary_null,pos,sub_len)','(t1.loc,pos,sub_len)', + '(t2.q_nchar,pos)','(t2.q_binary,pos)','(t2.q_nchar_null,pos)','(t2.q_binary_null,pos)','(t2.loc,pos)', + '(t2.q_nchar,pos,sub_len)','(t2.q_binary,pos,sub_len)','(t2.q_nchar_null,pos,sub_len)','(t2.q_binary_null,pos,sub_len)','(t2.loc,pos,sub_len)'] + fun_column_join_s_1 = random.sample(str_functions,1)+random.sample(fun_fix_column_s_j,1) + str_fun_join_s_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + fun_column_join_s_2 = random.sample(str_functions,1)+random.sample(fun_fix_column_s_j,1) + str_fun_join_s_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("pos",str(pos)).replace("sub_len",str(sub_len)) + + elif (strlist == ['CONCAT']) : + str_functions = strlist + i = random.randint(2,4) + fun_fix_column = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','q_nchar_null', + 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] + + column1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+column1+')' + str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + column2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+column2+')' + str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)', + '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)', + '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', + '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] + + column_j1 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+column_j1+')' + str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + column_j2 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+column_j2+')' + str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_s = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','loc','q_nchar_null', + 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] + + column_s1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_s_1 = str(random.sample(str_functions,1))+'('+column_s1+')' + str_fun_s_1 = str(fun_column_s_1).replace("[","").replace("]","").replace("'","") + + column_s2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_s_2 = str(random.sample(str_functions,1))+'('+column_s2+')' + str_fun_s_2 = str(fun_column_s_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_s_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)','(t1.loc)', + '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)','(t2.loc)', + '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', + '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] + + column_j_s1 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_s_1 = str(random.sample(str_functions,1))+'('+column_j_s1+')' + str_fun_join_s_1 = str(fun_column_join_s_1).replace("[","").replace("]","").replace("'","") + + column_j_s2 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_s_2 = str(random.sample(str_functions,1))+'('+column_j_s2+')' + str_fun_join_s_2 = str(fun_column_join_s_2).replace("[","").replace("]","").replace("'","") + + elif (strlist == ['CONCAT_WS']): + str_functions = strlist + i = random.randint(2,4) + fun_fix_column = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','q_nchar_null', + 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] + + separators = ['',' ','abc','123','!','@','#','$','%','^','&','*','(',')','-','_','+','=','{', + '[','}',']','|',';',':',',','.','<','>','?','/','~','`','taos','涛思'] + separator = str(random.sample(separators,i)).replace("[","").replace("]","") + + column1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column1+')' + str_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + column2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column2+')' + str_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)', + '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)', + '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', + '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] + + column_j1 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j1+')' + str_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + column_j2 = str(random.sample(fun_fix_column_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j2+')' + str_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_s = ['q_nchar','q_nchar1','q_nchar2','q_nchar3','q_nchar4','q_nchar5','q_nchar6','q_nchar7','q_nchar8','loc','q_nchar_null', + 'q_binary','q_binary1','q_binary2','q_binary3','q_binary4','q_binary5','q_binary6','q_binary7','q_binary8','q_binary_null'] + + column_s1 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_s_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_s1+')' + str_fun_s_1 = str(fun_column_s_1).replace("[","").replace("]","").replace("'","") + + column_s2 = str(random.sample(fun_fix_column,i)).replace("[","").replace("]","").replace("'","") + fun_column_s_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_s2+')' + str_fun_s_2 = str(fun_column_s_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_s_j = ['(t1.q_nchar)','(t1.q_nchar1)','(t1.q_nchar2)','(t1.q_nchar3)','(t1.q_nchar4)','(t1.q_nchar5)','(t1.q_nchar6)','(t1.q_nchar7)','(t1.q_nchar8)','(t1.q_nchar_null)','(t1.loc)', + '(t2.q_nchar)','(t2.q_nchar1)','(t2.q_nchar2)','(t2.q_nchar3)','(t2.q_nchar4)','(t2.q_nchar5)','(t2.q_nchar6)','(t2.q_nchar7)','(t2.q_nchar8)','(t2.q_nchar_null)','(t2.loc)', + '(t1.q_binary)','(t1.q_binary1)','(t1.q_binary2)','(t1.q_binary3)','(t1.q_binary4)','(t1.q_binary5)','(t1.q_binary6)','(t1.q_binary7)','(t1.q_binary8)','(t1.q_binary_null)', + '(t2.q_binary)','(t2.q_binary1)','(t2.q_binary2)','(t2.q_binary3)','(t2.q_binary4)','(t2.q_binary5)','(t2.q_binary6)','(t2.q_binary7)','(t2.q_binary8)','(t2.q_binary_null)'] + + column_j_s1 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_s_1 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j_s1+')' + str_fun_join_s_1 = str(fun_column_join_s_1).replace("[","").replace("]","").replace("'","") + + column_j_s2 = str(random.sample(fun_fix_column_s_j,i)).replace("[","").replace("]","").replace("'","") + fun_column_join_s_2 = str(random.sample(str_functions,1))+'('+'\"'+separator+'\",'+column_j_s2+')' + str_fun_join_s_2 = str(fun_column_join_s_2).replace("[","").replace("]","").replace("'","") + + + tdSql.query("select 1-1 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']) : + sql = "select t1s , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1, " % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as t1s from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1, " % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-2 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']) : + sql = "select ts , asct1 from ( select " + sql += "%s as asct1, " % str_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s )" % random.choice(self.order_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select ts , asct2 from ( select " + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1) from ( select " + sql += "%s as asct1, " % str_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s )" % random.choice(self.order_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select sum(asct2), min(asct2) from ( select " + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-3 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2 ," % str_fun_2 + sql += "%s as asct1, " % str_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2 ," % str_fun_2 + sql += "%s as asct1, " % str_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-4 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_1 + sql += "%s as asct1, " % str_fun_join_2 + sql += "%s, " % str_fun_join_1 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t2.%s as asct12, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_1 + sql += "%s as asct1, " % str_fun_join_2 + sql += "%s, " % str_fun_join_1 + sql += "t1.%s as asct21, " % random.choice(self.q_select) + sql += "t2.%s as asct22, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-5 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts ," + sql += "%s, " % str_fun_1 + sql += "%s as asct21, " % random.choice(self.q_select) + sql += "%s as asct22, " % random.choice(self.q_select) + sql += "%s " % str_fun_2 + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += " ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select ts ," + sql += "%s, " % str_fun_1 + sql += "%s as asct22, " % random.choice(self.q_select) + sql += "%s as asct21, " % random.choice(self.q_select) + sql += "%s " % str_fun_2 + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += " ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-6 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts1,ts ,timediff(ts1,ts), LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_1 + sql += "%s as asct1, " % str_fun_join_2 + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct21, " % random.choice(self.q_select) + sql += "%s, " % str_fun_join_1 + sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_1 + sql += "%s as asct1, " % str_fun_join_2 + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct21, " % random.choice(self.q_select) + sql += "%s, " % str_fun_join_1 + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-7 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select t1s ,ts1, LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1, ts as t1s," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as ts1 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1, ts as ts1," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as t1s from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-8 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts1,st1, LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) " + sql += "from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s as asct1, ts as st1," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as ts1 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) " + sql += "from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s as asct1, ts as ts1," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts as st1 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-9 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct21, " % random.choice(self.q_select) + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct23, " % random.choice(self.q_select) + sql += "t2.%s as asct24, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct21, " % random.choice(self.q_select) + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct23, " % random.choice(self.q_select) + sql += "t2.%s as asct24, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + + tdSql.query("select 1-10 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #3 inter union not support + tdSql.query("select 1-11 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts , LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1, ts ," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s " % random.choice(self.q_select) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1, ts ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s " % random.choice(self.q_select) + sql += " from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1 ," % str_fun_s_1 + sql += "%s as asct2, " % str_fun_s_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1 ," % str_fun_1 + sql += "%s as asct2, " % str_fun_2 + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-12 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct21, " % random.choice(self.q_select) + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct23, " % random.choice(self.q_select) + sql += "t2.%s as asct24, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct21, " % random.choice(self.q_select) + sql += "t1.%s as asct22, " % random.choice(self.q_select) + sql += "t2.%s as asct23, " % random.choice(self.q_select) + sql += "t2.%s as asct24, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-13 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts ," + sql += "%s as asct10, " % str_fun_1 + sql += "%s as asct1, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % str_fun_2 + sql += "%s as asct14 " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select ts ," + sql += "%s as asct1, " % str_fun_1 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % str_fun_2 + sql += "%s as asct14 " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-14 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select " + sql += "%s as asct1, " % str_fun_s_1 + sql += "%s as asct2" % str_fun_s_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select " + sql += "%s as asct1, " % str_fun_s_1 + sql += "%s as asct2" % str_fun_s_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-15 as str_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (strlist == ['LTRIM','RTRIM','LOWER','UPPER']) or (strlist == ['SUBSTR']) or (strlist == ['CONCAT']) or (strlist == ['CONCAT_WS']): + sql = "select ts,ts2 ,timediff(ts,ts2), LTRIM(asct1), LOWER(asct1), RTRIM(asct2), UPPER(asct2) from ( select t1.ts ," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (strlist == ['LENGTH','CHAR_LENGTH']): + sql = "select sum(asct1), min(asct1), max(asct2), avg(asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % str_fun_join_s_1 + sql += "%s as asct1, " % str_fun_join_s_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14 " % random.choice(self.q_select) + sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #taos -f sql + startTime_taos_f = time.time() + print("taos -f %s sql start!" %strlist) + # taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) + # _ = subprocess.check_output(taos_cmd1, shell=True) + print("taos -f %s sql over!" %strlist) + endTime_taos_f = time.time() + print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) + + print("=========%s====over=============" %strlist) + + def time_nest(self,timelist): + + print("==========%s===start=============" %timelist) + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + #self.dropandcreateDB_random("%s" %self.db_nest, 1) + + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMEZONE']): + time_functions = timelist + fun_fix_column = ['()'] + fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_j = ['()'] + fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + elif (timelist == ['TIMETRUNCATE']): + time_functions = timelist + + t = time.time() + t_to_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)) + fun_fix_column = ['q_ts','ts','_c0','_C0','_rowts','1600000000000','1600000000000000','1600000000000000000', + '%d' %t, '%d000' %t, '%d000000' %t,'t_to_s'] + + timeunits = ['1a' ,'1s', '1m' ,'1h', '1d'] + timeunit = str(random.sample(timeunits,1)).replace("[","").replace("]","").replace("'","") + + column_1 = ['(%s,timeutil)'%(random.sample(fun_fix_column,1))] + fun_column_1 = random.sample(time_functions,1)+random.sample(column_1,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_1 = str(time_fun_1).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) + + column_2 = ['(%s,timeutil)'%(random.sample(fun_fix_column,1))] + fun_column_2 = random.sample(time_functions,1)+random.sample(column_2,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_2 = str(time_fun_2).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) + + + fun_fix_column_j = ['(t1.q_ts)','(t1.ts)', '(t2.q_ts)','(t2.ts)','(1600000000000)','(1600000000000000)','(1600000000000000000)', + '(%d)' %t, '(%d000)' %t, '(%d000000)' %t,'t_to_s'] + + column_j1 = ['(%s,timeutil)'%(random.sample(fun_fix_column_j,1))] + fun_column_join_1 = random.sample(time_functions,1)+random.sample(column_j1,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_1 = str(time_fun_join_1).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) + + column_j2 = ['(%s,timeutil)'%(random.sample(fun_fix_column_j,1))] + fun_column_join_2 = random.sample(time_functions,1)+random.sample(column_j2,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_2 = str(time_fun_join_2).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s) + + elif (timelist == ['TO_ISO8601']): + time_functions = timelist + + t = time.time() + fun_fix_column = ['(now())','(ts)','(q_ts)','(_rowts)','(_c0)','(_C0)', + '(1600000000000)','(1600000000000000)','(1600000000000000000)', + '(%d)' %t, '(%d000)' %t, '(%d000000)' %t] + + fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_fix_column_j = ['(t1.q_ts)','(t1.ts)', '(t2.q_ts)','(t2.ts)','(1600000000000)','(1600000000000000)','(1600000000000000000)','(now())', + '(%d)' %t, '(%d000)' %t, '(%d000000)' %t] + + fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","") + + fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","") + + elif (timelist == ['TO_UNIXTIMESTAMP']): + time_functions = timelist + + t = time.time() + t_to_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)) + fun_fix_column = ['(q_nchar)','(q_nchar1)','(q_nchar2)','(q_nchar3)','(q_nchar4)','(q_nchar_null)','(q_binary)','(q_binary5)','(q_binary6)','(q_binary7)','(q_binary8)','(q_binary_null)','(t_to_s)'] + + fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") + time_fun_1 = str(time_fun_1).replace("t_to_s","%s" %t_to_s) + + fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") + time_fun_2 = str(time_fun_2).replace("t_to_s","%s" %t_to_s) + + fun_fix_column_j = ['(t1.q_nchar)','(t1.q_binary)', '(t2.q_nchar)','(t2.q_binary)','(t_to_s)'] + + fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") + time_fun_join_1 = str(time_fun_join_1).replace("t_to_s","%s" %t_to_s) + + fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("t_to_s","'t_to_s'") + time_fun_join_2 = str(time_fun_join_2).replace("t_to_s","%s" %t_to_s) + + elif (timelist == ['TIMEDIFF_1']): + time_functions = timelist + + t = time.time() + t_to_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)) + timeunits = [ '1a' ,'1s', '1m' ,'1h', '1d'] + timeunit = str(random.sample(timeunits,1)).replace("[","").replace("]","").replace("'","") + + fun_fix_column = ['q_ts','ts','_c0','_C0','_rowts','1600000000000','1600000000000000','1600000000000000000', + '%d' %t, '%d000' %t, '%d000000' %t,'t_to_s'] + + column_1,column_2 = random.sample(fun_fix_column,1),random.sample(fun_fix_column,1) + column_12 = ['(%s,%s,timeutil)'%(column_1,column_2)] + fun_column_1 = random.sample(time_functions,1)+random.sample(column_12,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_1 = str(time_fun_1).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s).replace("_1","") + + column_3,column_4 = random.sample(fun_fix_column,1),random.sample(fun_fix_column,1) + column_34 = ['(%s,%s,timeutil)'%(column_3,column_4)] + fun_column_2 = random.sample(time_functions,1)+random.sample(column_34,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_2 = str(time_fun_2).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s).replace("_1","") + + fun_fix_column_j = ['(t1.q_ts)','(t1.ts)', '(t2.q_ts)','(t2.ts)','1600000000000','1600000000000000','1600000000000000000', + '%d' %t, '%d000' %t, '%d000000' %t,'t_to_s'] + + column_j1,column_j2 = random.sample(fun_fix_column_j,1),random.sample(fun_fix_column_j,1) + column_j12 = ['(%s,%s,timeutil)'%(column_j1,column_j2)] + fun_column_join_1 = random.sample(time_functions,1)+random.sample(column_j12,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_1 = str(time_fun_join_1).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s).replace("_1","") + + column_j3,column_j4 = random.sample(fun_fix_column_j,1),random.sample(fun_fix_column_j,1) + column_j34 = ['(%s,%s,timeutil)'%(column_j3,column_j4)] + fun_column_join_2 = random.sample(time_functions,1)+random.sample(column_j34,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_2 = str(time_fun_join_2).replace("timeutil","%s" %timeunit).replace("t_to_s","%s" %t_to_s).replace("_1","") + + elif (timelist == ['TIMEDIFF_2']): + time_functions = timelist + + t = time.time() + t_to_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t)) + + fun_fix_column = ['q_ts','ts','_c0','_C0','_rowts','1600000000000','1600000000000000','1600000000000000000', + '%d' %t, '%d000' %t, '%d000000' %t,'t_to_s'] + + column_1,column_2 = random.sample(fun_fix_column,1),random.sample(fun_fix_column,1) + column_12 = ['(%s,%s)'%(column_1,column_2)] + fun_column_1 = random.sample(time_functions,1)+random.sample(column_12,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_1 = str(time_fun_1).replace("t_to_s","%s" %t_to_s).replace("_2","") + + column_3,column_4 = random.sample(fun_fix_column,1),random.sample(fun_fix_column,1) + column_34 = ['(%s,%s)'%(column_3,column_4)] + fun_column_2 = random.sample(time_functions,1)+random.sample(column_34,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_2 = str(time_fun_2).replace("t_to_s","%s" %t_to_s).replace("_2","") + + fun_fix_column_j = ['(t1.q_ts)','(t1.ts)', '(t2.q_ts)','(t2.ts)','1600000000000','1600000000000000','1600000000000000000', + '%d' %t, '%d000' %t, '%d000000' %t,'t_to_s'] + + column_j1,column_j2 = random.sample(fun_fix_column_j,1),random.sample(fun_fix_column_j,1) + column_j12 = ['(%s,%s)'%(column_j1,column_j2)] + fun_column_join_1 = random.sample(time_functions,1)+random.sample(column_j12,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_1 = str(time_fun_join_1).replace("t_to_s","%s" %t_to_s).replace("_2","") + + column_j3,column_j4 = random.sample(fun_fix_column_j,1),random.sample(fun_fix_column_j,1) + column_j34 = ['(%s,%s)'%(column_j3,column_j4)] + fun_column_join_2 = random.sample(time_functions,1)+random.sample(column_j34,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("\"","").replace("t_to_s","'t_to_s'") + time_fun_join_2 = str(time_fun_join_2).replace("t_to_s","%s" %t_to_s).replace("_2","") + + elif (timelist == ['ELAPSED']): + time_functions = timelist + + fun_fix_column = ['(ts)','(_c0)','(_C0)','(_rowts)','(ts,time_unit)','(_c0,time_unit)','(_C0,time_unit)','(_rowts,time_unit)'] + + time_units = ['1s','1m','1h','1d','1a'] + time_unit1 = str(random.sample(time_units,1)).replace("[","").replace("]","").replace("'","") + time_unit2 = str(random.sample(time_units,1)).replace("[","").replace("]","").replace("'","") + + fun_column_1 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit1) + + fun_column_2 = random.sample(time_functions,1)+random.sample(fun_fix_column,1) + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit2) + + + fun_fix_column_j = ['(t1.ts)', '(t2.ts)','(t1.ts,time_unit)','(t1.ts,time_unit)','(t2.ts,time_unit)','(t2.ts,time_unit)'] + + fun_column_join_1 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit1) + + fun_column_join_2 = random.sample(time_functions,1)+random.sample(fun_fix_column_j,1) + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace(", ","").replace("time_unit","%s" %time_unit2) + + + elif (timelist == ['CAST']) : + str_functions = timelist + #下面的4个是全的,这个只是1个 + i = random.randint(1,4) + if i ==1: + print('===========cast_1===========') + fun_fix_column = ['q_bool','q_bool_null','q_bigint','q_bigint_null','q_smallint','q_smallint_null', + 'q_tinyint','q_tinyint_null','q_int','q_int_null','q_float','q_float_null','q_double','q_double_null'] + type_names = ['BIGINT','BINARY(100)','TIMESTAMP','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['t1.q_bool','t1.q_bool_null','t1.q_bigint','t1.q_bigint_null','t1.q_smallint','t1.q_smallint_null', + 't1.q_tinyint','t1.q_tinyint_null','t1.q_int','t1.q_int_null','t1.q_float','t1.q_float_null','t1.q_double','t1.q_double_null', + 't2.q_bool','t2.q_bool_null','t2.q_bigint','t2.q_bigint_null','t2.q_smallint','t2.q_smallint_null', + 't2.q_tinyint','t2.q_tinyint_null','t2.q_int','t2.q_int_null','t2.q_float','t2.q_float_null','t2.q_double','t2.q_double_null'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + elif i==2: + print('===========cast_2===========') + fun_fix_column = ['q_binary','q_binary_null','q_binary1','q_binary2','q_binary3','q_binary4'] + type_names = ['BIGINT','BINARY(100)','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['t1.q_binary','t1.q_binary_null','t1.q_binary1','t1.q_binary2','t1.q_binary3','t1.q_binary4', + 't2.q_binary','t2.q_binary_null','t2.q_binary1','t2.q_binary2','t2.q_binary3','t2.q_binary4'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + elif i==3: + print('===========cast_3===========') + fun_fix_column = ['q_nchar','q_nchar_null','q_nchar5','q_nchar6','q_nchar7','q_nchar8'] + type_names = ['BIGINT','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['t1.q_nchar','t1.q_nchar_null','t1.q_nchar5','t1.q_nchar6','t1.q_nchar7','t1.q_nchar8', + 't2.q_nchar','t2.q_nchar_null','t2.q_nchar5','t2.q_nchar6','t2.q_nchar7','t2.q_nchar8'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + elif i==4: + print('===========cast_4===========') + fun_fix_column = ['q_ts','q_ts_null','_C0','_c0','ts','_rowts'] + type_names = ['BIGINT','TIMESTAMP','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","") + + fun_fix_column_j = ['t1.q_ts','t1.q_ts_null','t1.ts','t2.q_ts','t2.q_ts_null','t2.ts'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","") + + elif (timelist == ['CAST_1']) : + str_functions = timelist + + print('===========cast_1===========') + fun_fix_column = ['q_bool','q_bool_null','q_bigint','q_bigint_null','q_smallint','q_smallint_null', + 'q_tinyint','q_tinyint_null','q_int','q_int_null','q_float','q_float_null','q_double','q_double_null'] + type_names = ['BIGINT','BINARY(100)','TIMESTAMP','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_1","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_1","") + + fun_fix_column_j = ['t1.q_bool','t1.q_bool_null','t1.q_bigint','t1.q_bigint_null','t1.q_smallint','t1.q_smallint_null', + 't1.q_tinyint','t1.q_tinyint_null','t1.q_int','t1.q_int_null','t1.q_float','t1.q_float_null','t1.q_double','t1.q_double_null', + 't2.q_bool','t2.q_bool_null','t2.q_bigint','t2.q_bigint_null','t2.q_smallint','t2.q_smallint_null', + 't2.q_tinyint','t2.q_tinyint_null','t2.q_int','t2.q_int_null','t2.q_float','t2.q_float_null','t2.q_double','t2.q_double_null'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_1","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_1","") + + elif (timelist == ['CAST_2']) : + str_functions = timelist + print('===========cast_2===========') + fun_fix_column = ['q_binary','q_binary_null','q_binary1','q_binary2','q_binary3','q_binary4'] + type_names = ['BIGINT','BINARY(100)','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_2","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_2","") + + fun_fix_column_j = ['t1.q_binary','t1.q_binary_null','t1.q_binary1','t1.q_binary2','t1.q_binary3','t1.q_binary4', + 't2.q_binary','t2.q_binary_null','t2.q_binary1','t2.q_binary2','t2.q_binary3','t2.q_binary4'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_2","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_2","") + + elif (timelist == ['CAST_3']) : + str_functions = timelist + print('===========cast_3===========') + fun_fix_column = ['q_nchar','q_nchar_null','q_nchar5','q_nchar6','q_nchar7','q_nchar8'] + type_names = ['BIGINT','NCHAR(100)','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_3","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_3","") + + fun_fix_column_j = ['t1.q_nchar','t1.q_nchar_null','t1.q_nchar5','t1.q_nchar6','t1.q_nchar7','t1.q_nchar8', + 't2.q_nchar','t2.q_nchar_null','t2.q_nchar5','t2.q_nchar6','t2.q_nchar7','t2.q_nchar8'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_3","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_3","") + + elif (timelist == ['CAST_4']) : + str_functions = timelist + print('===========cast_4===========') + fun_fix_column = ['q_ts','q_ts_null','_C0','_c0','ts','_rowts'] + type_names = ['BIGINT','TIMESTAMP','BIGINT UNSIGNED'] + + type_name1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name1+')' + time_fun_1 = str(fun_column_1).replace("[","").replace("]","").replace("'","").replace("_4","") + + type_name2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column,1))+' AS '+type_name2+')' + time_fun_2 = str(fun_column_2).replace("[","").replace("]","").replace("'","").replace("_4","") + + fun_fix_column_j = ['t1.q_ts','t1.q_ts_null','t1.ts','t2.q_ts','t2.q_ts_null','t2.ts'] + + type_name_j1 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_1 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j1+')' + time_fun_join_1 = str(fun_column_join_1).replace("[","").replace("]","").replace("'","").replace("_4","") + + type_name_j2 = str(random.sample(type_names,1)).replace("[","").replace("]","").replace("'","") + fun_column_join_2 = str(random.sample(str_functions,1))+'('+str(random.sample(fun_fix_column_j,1))+' AS '+type_name_j2+')' + time_fun_join_2 = str(fun_column_join_2).replace("[","").replace("]","").replace("'","").replace("_4","") + + tdSql.query("select 1-1 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1 , timediff(asct1,now) from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts1 from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) \ + or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts2 , asct1,now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts2 from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select max(asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += "from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-2 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(asct1,now),now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s )" % random.choice(self.order_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select ts , timediff(asct2,now),now(),today(),timezone() from ( select " + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts , (asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s )" % random.choice(self.order_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select ts , asct2,now(),today(),timezone() from ( select " + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select min(asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1 " % time_fun_1 + sql += " from regular_table_1 where " + sql += "%s )" % random.choice(self.q_where) + sql += "%s " % random.choice(self.unionall_or_union) + sql += "select avg(asct2),now(),today(),timezone() from ( select " + sql += "%s as asct2 " % time_fun_2 + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-3 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(asct1,now) from ( select " + sql += "%s as asct1, ts ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += "from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2, ts ," % time_fun_2 + sql += "%s as asct1, " % time_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += "from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += " order by asct1 desc " + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts , (asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1, ts ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2, ts ," % time_fun_2 + sql += "%s as asct1, " % time_fun_1 + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s " % random.choice(self.q_select) + sql += "from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += " order by asct1 desc " + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select abs(asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1," % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += "from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s select " % random.choice(self.unionall_or_union) + sql += "%s as asct2," % time_fun_2 + sql += "%s as asct1 " % time_fun_1 + sql += "from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += " order by asct1 asc " + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-4 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), timediff(asct1,now) from ( select t1.ts as ts1," + sql += "%s as asct11, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "%s as asct12, " % time_fun_join_1 + sql += "t1.%s as asct111, " % random.choice(self.q_select) + sql += "t2.%s as asct121, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), (asct1) from ( select t1.ts as ts1," + sql += "%s as asct10, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "%s as asct11, " % time_fun_join_1 + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select floor(asct1) from ( select " + sql += "%s as asct10, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "%s as asct11" % time_fun_join_1 + sql += " from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-5 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['ELAPSED']) : + sql = "select now(),today(),timezone(), " + sql += "%s, " % time_fun_1 + sql += "%s " % time_fun_2 + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += " ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + else: + sql = "select ts ,now(),today(),timezone(), " + sql += "%s as asct11, " % time_fun_1 + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % random.choice(self.q_select) + sql += "%s as asct14 " % time_fun_2 + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += " ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-6 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,ts ,timediff(ts1,ts), timediff(asct1,now) from ( select t1.ts as ts1," + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t2.%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % time_fun_join_1 + sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts ,timediff(ts1,ts), (asct1) from ( select t1.ts as ts1," + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t2.%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % time_fun_join_1 + sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select (asct1)*111 from ( select " + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "%s as asct122 " % time_fun_join_1 + sql += " from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s )" % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-7 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,m1 , timediff(asct1,now) from ( select " + sql += "%s as asct1, ts as m1," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.t_select) + sql += "ts as ts1 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select tm1,tm2 , (asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1, ts as tm1," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.t_select) + sql += "ts as tm2 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select (asct1)/asct2 ,now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += "from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-8 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select tm1,tm2 , timediff(asct1,now) " + sql += "from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s as asct1, ts as tm1," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.t_select) + sql += "ts as tm2 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts2 , (asct1),now(),today(),timezone() " + sql += "from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s as asct1, ts as ts1," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.t_select) + sql += "ts as ts2 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select floor(abs(asct1)),now(),today(),timezone() " + sql += "from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += "from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-9 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), timediff(asct1,now) from ( select t1.ts as ts1," + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), asct1 from ( select t1.ts as ts1," + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select min(asct1*110) from ( select " + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1 " % time_fun_join_2 + sql += "from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "and %s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + + tdSql.query("select 1-10 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(asct1,now) from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select ts , timediff(asct1,now) from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts , (asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select ts , (asct2),now(),today(),timezone() from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select abs(asct1),now(),today(),timezone() from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ") %s " % random.choice(self.unionall_or_union) + sql += "select max(asct2),now(),today(),timezone() from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += "from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #3 inter union not support + tdSql.query("select 1-11 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(asct1,now), timediff(now,asct2) from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts , asct1,now(),now(),asct2 from ( select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2, " % time_fun_2 + sql += "%s as asct121, " % random.choice(self.s_r_select) + sql += "%s as asct122, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select asct1+asct2,now(),today(),timezone() from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s as asct1 ," % time_fun_1 + sql += "%s as asct2 " % time_fun_2 + sql += " from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "order by asct1 " + sql += "%s " % random.choice(self.limit1_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-12 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), timediff(asct1,now) from ( select t1.ts as ts1," + sql += "%s, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts2 ,timediff(ts1,ts2), asct1,now() from ( select t1.ts as ts1," + sql += "%s, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts as ts2 from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select min(floor(asct1)),now() from ( select " + sql += "%s as asct121, " % time_fun_join_1 + sql += "%s as asct1 " % time_fun_join_2 + sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "and %s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-13 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(%s,now)," % time_fun_2 + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % time_fun_2 + sql += "%s as asct122 " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts ,now(),today(),timezone(), " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct11, " % random.choice(self.q_select) + sql += "%s as asct12, " % random.choice(self.q_select) + sql += "%s as asct13, " % time_fun_2 + sql += "%s as asct122 " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select now(),today(),timezone(), " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct12 " % time_fun_2 + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-14 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts , timediff(asct1,now),timediff(now,asct2) from ( select ts ts ," + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2" % time_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts , (asct1),now(),(now()),asct2 from ( select ts ts ," + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2" % time_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select (asct1)*asct2,now(),(now()) from ( select " + sql += "%s as asct1, " % time_fun_1 + sql += "%s as asct2" % time_fun_2 + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ) ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-15 as time_nest from stable_1 limit 1;") + for i in range(self.fornum): + if (timelist == ['NOW','TODAY']) or (timelist == ['TIMETRUNCATE']) or (timelist == ['TO_ISO8601'])\ + or (timelist == ['TO_UNIXTIMESTAMP']) or (timelist == ['TIMEDIFF_1']) or (timelist == ['TIMEDIFF_2']): + sql = "select ts1,ts ,timediff(ts1,ts), timediff(asct1,now),timediff(now,asct2) from ( select t1.ts as ts1," + sql += "%s as asct2, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['TIMEZONE']) or (timelist == ['CAST']) or (timelist == ['CAST_1']) or (timelist == ['CAST_2']) or (timelist == ['CAST_3']) or (timelist == ['CAST_4']): + sql = "select ts1,ts ,timediff(ts1,ts), asct1,(now()),(now()),asct2 ,now(),today(),timezone() from ( select t1.ts as ts1," + sql += "%s as asct2, " % time_fun_join_1 + sql += "%s as asct1, " % time_fun_join_2 + sql += "t1.%s as asct11, " % random.choice(self.q_select) + sql += "t1.%s as asct12, " % random.choice(self.q_select) + sql += "t2.%s as asct13, " % random.choice(self.q_select) + sql += "t2.%s as asct14, " % random.choice(self.q_select) + sql += "t2.ts from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + elif (timelist == ['ELAPSED']) : + sql = "select asct1,(now()),(now()),asct2 ,now(),today(),timezone() from ( select " + sql += "%s as asct2, " % time_fun_join_1 + sql += "%s as asct1 " % time_fun_join_2 + sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #taos -f sql + startTime_taos_f = time.time() + print("taos -f %s sql start!" %timelist) + # taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) + # _ = subprocess.check_output(taos_cmd1, shell=True) + print("taos -f %s sql over!" %timelist) + endTime_taos_f = time.time() + print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) + + print("=========%s====over=============" %timelist) + + def function_before_26(self): + + print('=====================2.6 old function start ===========') + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + self.dropandcreateDB_random("%s" %self.db_nest, 1) + + #1 select * from (select column form regular_table where <\>\in\and\or order by) + tdSql.query("select 1-1 from stable_1;") + for i in range(self.fornum): + sql = "select tas from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as tas from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql,queryTimes=1) + self.explain_sql(sql) + + #1 outer union not support + tdSql.query("select 1-2 from stable_1;") + for i in range(self.fornum): + sql = "select t1s from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as t1s from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") union " + sql += "select t2s from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as t2s from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #self.dropandcreateDB_random("%s" %db, 1) + tdSql.query("select 1-2 from stable_1;") + for i in range(self.fornum): + sql = "select ts from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") union all " + sql += "select ts from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #1 inter union not support + tdSql.query("select 1-3 from stable_1;") + for i in range(self.fornum): + #sql = "select ts , * from ( select " + sql = "select ts from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "" + sql += " union all select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 1-3 from stable_1;") + for i in range(self.fornum): + sql = "select ts from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " union all select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from regular_table_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #join:select * from (select column form regular_table1,regular_table2 where t1.ts=t2.ts and <\>\in\and\or order by) + tdSql.query("select 1-4 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select t1.ts as t1ts," + sql += "t1.%s as t11, " % random.choice(self.q_select) + sql += "t1.%s as t12, " % random.choice(self.q_select) + sql += "t2.%s as t21, " % random.choice(self.q_select) + sql += "t2.%s as t22, " % random.choice(self.q_select) + sql += "t2.ts as t2ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #2 select column from (select * form regular_table ) where <\>\in\and\or order by + tdSql.query("select 2-1 from stable_1;") + for i in range(self.fornum): + sql = "select ts ," + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s " % random.choice(self.q_select) + sql += " from ( select * from regular_table_1 ) where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += " ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #3 select * from (select column\tag form stable where <\>\in\and\or order by ) + #self.dropandcreateDB_random("%s" %db, 1) + tdSql.query("select 3-1 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.explain_sql(sql) + tdSql.query("select 3-1 from stable_1;") + for i in range(self.fornum): + sql = "select ts, " + sql += "%s " % random.choice(self.s_r_select) + sql += "from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.q_select) + sql += "%s, " % random.choice(self.t_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.explain_sql(sql) + + # select ts,* from (select column\tag form stable1,stable2 where t1.ts = t2.ts and <\>\in\and\or order by ) + #self.dropandcreateDB_random("%s" %db, 1) + tdSql.query("select 3-2 from stable_1;") + for i in range(self.fornum): + #sql = "select ts , * from ( select t1.ts as t1ts , " + sql = "select t1ts , t2ts from ( select t1.ts as t1ts , " + sql += "t1.%s as t11, " % random.choice(self.t_select) + sql += "t1.%s as t12, " % random.choice(self.q_select) + sql += "t2.%s as t13, " % random.choice(self.t_select) + sql += "t2.%s as t14, " % random.choice(self.q_select) + sql += "t2.ts as t2ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #3 outer union not support + + tdSql.query("select 3-3 from stable_1;") + for i in range(self.fornum): + #sql = "select ts , * from ( select " + sql = "select ts1 from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts1 from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") union " + sql += "select ts2 from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts2 from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + for i in range(self.fornum): + sql = "select ts1 from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts1 from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ") union all " + sql += "select ts2 from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts2 from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #3 inter union not support + tdSql.query("select 3-4 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += " %s " % random.choice(self.unionall_or_union) + sql += " select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts from stable_2 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += ")" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #join:select * from (select column form stable1,stable2 where t1.ts=t2.ts and <\>\in\and\or order by) + tdSql.query("select 3-5 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select t1.ts as t1ts," + sql += "t1.%s as t11, " % random.choice(self.q_select) + sql += "t1.%s as t12, " % random.choice(self.q_select) + sql += "t2.%s as t21, " % random.choice(self.q_select) + sql += "t2.%s as t22, " % random.choice(self.q_select) + sql += "t2.ts as t2ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 3-6 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select t1.ts as t1ts ," + sql += "t1.%s as t11, " % random.choice(self.q_select) + sql += "t1.%s as t12, " % random.choice(self.q_select) + sql += "t2.%s as t21, " % random.choice(self.q_select) + sql += "t2.%s as t22, " % random.choice(self.q_select) + sql += "t2.ts as t2ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += ");" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #4 select column from (select * form stable where <\>\in\and\or order by ) + tdSql.query("select 4-1 from stable_1;") + for i in range(self.fornum): + sql = "select ts , " + sql += "%s as t11, " % random.choice(self.q_select) + sql += "%s as t12, " % random.choice(self.q_select) + sql += "%s " % random.choice(self.t_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #5 select distinct column\tag from (select * form stable where <\>\in\and\or order by limit offset ) + tdSql.query("select 5-1 from stable_1;") + for i in range(self.fornum): + sql = "select " + sql += "%s " % random.choice(self.dqt_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #5-1 select distinct column\tag from (select calc form stable where <\>\in\and\or order by limit offset ) + tdSql.query("select 5-2 from stable_1;") + for i in range(self.fornum): + sql = "select distinct c5_1 " + sql += " from ( select " + sql += "%s " % random.choice(self.calc_select_in_ts) + sql += " as c5_1 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #6 select * from (select distinct(tag) form stable where <\>\in\and\or order by limit ) + tdSql.query("select 6-1 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s " % random.choice(self.dt_select) + sql += " from stable_1 where " + sql += "%s ) ;" % random.choice(self.qt_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #7 select * from (select distinct(tag) form stable where <\>\in\and\or order by limit ) + tdSql.query("select 7-1 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s " % random.choice(self.dq_select) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice([self.limit_where[0] , self.limit_where[1]] ) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #calc_select,TWA/Diff/Derivative/Irate are not allowed to apply to super table directly + #8 select * from (select ts,calc form ragular_table where <\>\in\and\or order by ) + tdSql.query("select 8-1 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select ts ," + sql += "%s " % random.choice(self.calc_select_support_ts) + sql += "from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + tdSql.query("select 8-1 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s " % random.choice(self.calc_select_not_support_ts) + sql += "from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s " % random.choice(self.calc_select_in_ts) + sql += "from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 8-2 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select t1.ts, " + sql += "%s " % random.choice(self.calc_select_in_support_ts_j) + sql += "from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s " % random.choice(self.calc_select_in_not_support_ts_j) + sql += "from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #9 select * from (select ts,calc form stable where <\>\in\and\or order by ) + # self.dropandcreateDB_random("%s" %db, 1) + tdSql.query("select 9-1 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s " % random.choice(self.calc_select_not_support_ts) + sql += "from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + tdSql.query("select 9-2 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select ts ," + sql += "%s " % random.choice(self.calc_select_support_ts) + sql += "from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 9-3 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s " % random.choice(self.calc_select_in_not_support_ts_j) + sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + tdSql.query("select 9-4 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select t1.ts," + sql += "%s " % random.choice(self.calc_select_in_support_ts_j) + sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += " and %s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #10 select calc from (select * form regualr_table where <\>\in\and\or order by ) + tdSql.query("select 10-1 from stable_1;") + for i in range(self.fornum): + sql = "select " + sql += "%s " % random.choice(self.calc_select_in_ts) + sql += "as calc10_1 from ( select * from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #10-1 select calc from (select * form regualr_table where <\>\in\and\or order by ) + tdSql.query("select 10-2 from stable_1;") + for i in range(self.fornum): + sql = "select " + sql += "%s " % random.choice(self.calc_select_all) + sql += "as calc10_2 from ( select * from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #10-2 select calc from (select * form regualr_tables where <\>\in\and\or order by ) + tdSql.query("select 10-3 from stable_1;") + for i in range(self.fornum): + sql = "select " + sql += "count(*) as calc10_3 " + sql += " from ( select t1.ts as t11, t2.ts as t22 from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += " and %s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.order_u_where) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + sql += "%s ;" % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #11 select calc from (select * form stable where <\>\in\and\or order by limit ) + tdSql.query("select 11-1 from stable_1;") + for i in range(self.fornum): + sql = "select " + sql += "%s " % random.choice(self.calc_select_in_ts) + sql += "as calc11_1 from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #11-1 select calc from (select * form stable where <\>\in\and\or order by limit ) + tdSql.query("select 11-2 from stable_1;") + for i in range(self.fornum): + sql = "select " + sql += "%s " % random.choice(self.calc_select_all) + sql += "as calc11_1 from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #12 select calc-diff from (select * form regualr_table where <\>\in\and\or order by limit ) + tdSql.query("select 12-1 from stable_1;") + for i in range(self.fornum): + sql = "select " + sql += "%s " % random.choice(self.calc_calculate_regular) + sql += " from ( select * from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.order_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #12-1 select calc-diff from (select * form stable where <\>\in\and\or order by limit ) + tdSql.query("select 12-3 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s " % random.choice(self.calc_calculate_regular) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += ") " + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 12-4 from stable_1;") + #join query does not support group by + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s " % random.choice(self.calc_calculate_regular_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += ") " + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 12-5 from stable_1;") + #join query does not support group by + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s " % random.choice(self.calc_calculate_regular_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.qt_u_or_where) + sql += ") " + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += " ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #13 select calc-diff as diffns from (select * form stable where <\>\in\and\or order by limit ) + tdSql.query("select 13-1 from stable_1;") + for i in range(self.fornum): + sql = "select " + sql += "%s " % random.choice(self.calc_calculate_regular) + sql += " as calc13_1 from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.orders_desc_where) + sql += "%s " % random.choice([self.limit_where[2] , self.limit_where[3]] ) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #14 select * from (select calc_aggregate_alls as agg from stable where <\>\in\and\or group by order by slimit soffset ) + tdSql.query("select 14-1 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all) + sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all) + sql += "%s " % random.choice(self.calc_aggregate_all) + sql += " as calc14_3 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.group_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + # error group by in out query + tdSql.query("select 14-2 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all) + sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all) + sql += "%s " % random.choice(self.calc_aggregate_all) + sql += " as calc14_3 from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.partiton_where_regular) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #14-2 select * from (select calc_aggregate_all_js as agg from stables where <\>\in\and\or group by order by slimit soffset ) + tdSql.query("select 14-3 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all_j) + sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all_j) + sql += "%s " % random.choice(self.calc_aggregate_all_j) + sql += " as calc14_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 14-4 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc14_1, " % random.choice(self.calc_aggregate_all_j) + sql += "%s as calc14_2, " % random.choice(self.calc_aggregate_all_j) + sql += "%s " % random.choice(self.calc_aggregate_all_j) + sql += " as calc14_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.partiton_where_j) + sql += "%s " % random.choice(self.slimit1_where) + sql += ") " + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #15 select * from (select calc_aggregate_regulars as agg from regular_table where <\>\in\and\or order by slimit soffset ) + tdSql.query("select 15-1 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_regular) + sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_regular) + sql += "%s " % random.choice(self.calc_aggregate_regular) + sql += " as calc15_3 from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.group_where_regular) + sql += ") ;" + tdLog.info(sql) + self.data_check(sql,mark='15-1') + + tdSql.query("select 15-2 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc15_2 " % random.choice(self.calc_aggregate_regular_j) + sql += "from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.group_where_regular_j) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 15-2.2 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_regular_j) + sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_regular_j) + sql += "%s " % random.choice(self.calc_aggregate_regular_j) + sql += " as calc15_3 from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.group_where_regular_j) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + sql += "%s ;" % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 15-3 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_groupbytbname) + sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_groupbytbname) + sql += "%s " % random.choice(self.calc_aggregate_groupbytbname) + sql += " as calc15_3 from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.group_only_where) + sql += "%s " % random.choice(self.having_support) + sql += ") " + sql += "order by calc15_1 " + sql += "%s " % random.choice(self.limit_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 15-4 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_groupbytbname_j) + sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_groupbytbname_j) + sql += "%s " % random.choice(self.calc_aggregate_groupbytbname_j) + sql += " as calc15_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.group_only_where_j) + sql += "%s " % random.choice(self.having_support_j) + sql += ") " + sql += "order by calc15_1 " + sql += "%s " % random.choice(self.limit_u_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 15-5 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc15_1, " % random.choice(self.calc_aggregate_groupbytbname) + sql += "%s as calc15_2, " % random.choice(self.calc_aggregate_groupbytbname) + sql += "%s " % random.choice(self.calc_aggregate_groupbytbname) + sql += " as calc15_3 from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.group_where) + sql += ") " + sql += "order by calc15_1 " + sql += "%s " % random.choice(self.limit_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #16 select * from (select calc_aggregate_regulars as agg from regular_table where <\>\in\and\or order by limit offset ) + tdSql.query("select 16-1 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc16_0 , " % random.choice(self.calc_calculate_all) + sql += "%s as calc16_1 , " % random.choice(self.calc_aggregate_all) + sql += "%s as calc16_2 " % random.choice(self.calc_select_in) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.group_where) + sql += ") " + sql += "order by calc16_0 " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 16-2 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc16_0 " % random.choice(self.calc_calculate_all_j) + sql += ", %s as calc16_1 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += ") " + sql += "order by calc16_0 " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 16-2.2 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc16_0 " % random.choice(self.calc_calculate_all_j) + sql += ", %s as calc16_1 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.qt_u_or_where) + sql += ") " + sql += "order by calc16_0 " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 16-3 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_regular) + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "limit 2 ) " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 16-4 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_regular_j) + sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "limit 2 ) " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 16-4.2 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_regular_j) + sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_or_where) + sql += "limit 2 ) " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 16-5 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc16_1 , " % random.choice(self.calc_calculate_all) + sql += "%s as calc16_2 , " % random.choice(self.calc_calculate_all) + sql += "%s as calc16_3 " % random.choice(self.calc_calculate_all) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.group_where) + sql += ") " + sql += "order by calc16_1 " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 16-6 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_groupbytbname) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "limit 2 ) " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 16-7 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_groupbytbname_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "limit 2 ) " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 16-8 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(self.calc_calculate_groupbytbname_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "limit 2 ) " + sql += "%s " % random.choice(self.limit1_where) + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #17 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or interval_sliding group by having order by limit offset )interval_sliding + tdSql.query("select 17-1 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_0 , " % random.choice(self.calc_calculate_all) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-2 from stable_1;") + for i in range(self.fornum): + #this is having_support , but tag-select cannot mix with last_row,other select can + sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_0 , " % random.choice(self.calc_calculate_all_j) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-2.2 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_0 , " % random.choice(self.calc_calculate_all_j) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-3 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-4 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-4.2 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-5 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.partiton_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-6 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-7 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-7.2 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-8 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all) + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-9 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 17-10 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal17_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.interval_sliding) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 18-1 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all) + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.session_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 18-2 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 18-2.2 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 18-3 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all) + sql += " from stable_1_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.session_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 18-4 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 18-4.2 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 18-5 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all) + sql += " from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.session_where) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 18-6 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.t_join_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 18-7 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal18_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.session_u_where) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #19 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or session order by limit )interval_sliding + tdSql.query("select 19-1 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all) + sql += " from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.state_window) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 19-2 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.state_u_window) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 19-2.2 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.state_u_window) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 19-3 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all) + sql += " from stable_1_1 where " + sql += "%s " % random.choice(self.q_where) + sql += "%s " % random.choice(self.state_window) + sql += "%s " % random.choice(self.limit1_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 19-4 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 19-4.2 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_or_where) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 19-6 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.q_u_where) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + tdSql.query("select 19-7 from stable_1;") + for i in range(self.fornum): + sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) + sql += "%s as cal19_1 ," % random.choice(self.calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(self.calc_aggregate_all_j) + sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " + sql += "%s " % random.choice(self.qt_u_or_where) + sql += "%s " % random.choice(self.limit_u_where) + sql += ") " + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #1 select * from (select * from (select * form regular_table where <\>\in\and\or order by limit )) + tdSql.query("select 1-1 from stable_1;") + for i in range(self.fornum): + for_num = random.randint(1, 15); + sql = "select * from (" * for_num + sql += "select * from ( select * from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ttt from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ")) " + sql += ")" * for_num + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + sql2 = "select * from ( select * from ( select " + sql2 += "%s, " % random.choice(self.s_r_select) + sql2 += "%s, " % random.choice(self.q_select) + sql2 += "ts as tin from regular_table_1 where " + sql2 += "%s " % random.choice(self.q_where) + sql2 += ")) " + tdLog.info(sql2) + tdSql.query(sql2) + self.cur1.execute(sql2) + self.explain_sql(sql2) + + tdLog.info("=====1-1==over=========") + + for i in range(self.fornum): + for_num = random.randint(1, 15); + sql = "select ts2 from (" * for_num + sql += "select * from ( select * from ( select " + sql += "%s, " % random.choice(self.s_r_select) + sql += "%s, " % random.choice(self.q_select) + sql += "ts as ts2 from regular_table_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ")) " + sql += ")" * for_num + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + sql2 = "select * from ( select * from ( select " + sql2 += "%s, " % random.choice(self.s_r_select) + sql2 += "%s, " % random.choice(self.q_select) + sql2 += "ts as tt from regular_table_1 where " + sql2 += "%s " % random.choice(self.q_where) + sql2 += ")) " + tdLog.info(sql2) + tdSql.query(sql2) + self.explain_sql(sql2) + tdLog.info("=====1-2==over=========") + + #2 select * from (select * from (select * form stable where <\>\in\and\or order by limit )) + tdSql.query("select 2-1 from stable_1;") + for i in range(self.fornum): + for_num = random.randint(1, 15); + sql = "select * from (" * for_num + sql += "select * from ( select * from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.qt_select) + sql += "ts as tss from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ")) " + sql += ")" * for_num + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + sql2 = "select * from ( select * from ( select " + sql2 += "%s, " % random.choice(self.s_s_select) + sql2 += "%s, " % random.choice(self.qt_select) + sql2 += "ts as tst from stable_1 where " + sql2 += "%s " % random.choice(self.q_where) + sql2 += ")) " + tdLog.info(sql2) + tdSql.query(sql2) + self.explain_sql(sql2) + + tdLog.info("=====2-1==over=========") + + for i in range(self.fornum): + for_num = random.randint(1, 15); + sql = "select tsn from (" * for_num + sql += "select * from ( select * from ( select " + sql += "%s, " % random.choice(self.s_s_select) + sql += "%s, " % random.choice(self.qt_select) + sql += "ts as tsn from stable_1 where " + sql += "%s " % random.choice(self.q_where) + sql += ")) " + sql += ")" * for_num + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + sql2 = "select ts1 from ( select * from ( select " + sql2 += "%s, " % random.choice(self.s_s_select) + sql2 += "%s, " % random.choice(self.qt_select) + sql2 += "ts as ts1 from stable_1 where " + sql2 += "%s " % random.choice(self.q_where) + sql2 += ")) " + tdLog.info(sql2) + tdSql.query(sql2) + self.cur1.execute(sql2) + self.explain_sql(sql2) + tdLog.info("=====2-2==over=========") + + #3 select ts ,calc from (select * form stable where <\>\in\and\or order by limit ) + tdSql.query("select 3-1 from stable_1;") + for i in range(self.fornum): + sql = "select " + sql += "%s " % random.choice(self.calc_calculate_regular) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.orders_desc_where) + sql += "%s " % random.choice(self.limit_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #4 select * from (select calc form stable where <\>\in\and\or order by limit ) + tdSql.query("select 4-1 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select " + sql += "%s " % random.choice(self.calc_select_in_ts) + sql += "from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.limit_where) + sql += ") ;" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #5 select ts ,tbname from (select * form stable where <\>\in\and\or order by limit ) + tdSql.query("select 5-1 from stable_1;") + for i in range(self.fornum): + sql = "select ts , tbname , " + sql += "%s ," % random.choice(self.calc_calculate_regular) + sql += "%s ," % random.choice(self.dqt_select) + sql += "%s " % random.choice(self.qt_select) + sql += " from ( select * from stable_1 where " + sql += "%s " % random.choice(self.qt_where) + sql += "%s " % random.choice(self.orders_desc_where) + sql += "%s " % random.choice(self.limit_where) + sql += ") ;" + tdLog.info(sql) + tdSql.error(sql) + + #special sql + tdSql.query("select 6-1 from stable_1;") + for i in range(self.fornum): + sql = "select * from ( select _block_dist() from stable_1);" + tdSql.error(sql) + sql = "select _block_dist() from (select * from stable_1);" + tdSql.error(sql) + sql = "select * from (select database());" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + sql = "select * from (select client_version());" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + sql = "select * from (select client_version() as version);" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + sql = "select * from (select server_version());" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + sql = "select * from (select server_version() as version);" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + sql = "select * from (select server_status());" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + sql = "select * from (select server_status() as status);" + tdLog.info(sql) + tdSql.query(sql) + self.explain_sql(sql) + + #taos -f sql + startTime_taos_f = time.time() + print("taos -f sql start!") + taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) + _ = subprocess.check_output(taos_cmd1, shell=True) + print("taos -f sql over!") + endTime_taos_f = time.time() + print("taos_f total time %ds" % (endTime_taos_f - startTime_taos_f)) + + print('=====================2.6 old function end ===========') + + + def run(self): + tdSql.prepare() + + startTime = time.time() + + #self.function_before_26() + + self.dropandcreateDB_random("%s" %self.db_nest, 1) + + self.math_nest(['UNIQUE']) + self.math_nest(['MODE']) + self.math_nest(['SAMPLE']) + + self.math_nest(['ABS','SQRT']) + self.math_nest(['SIN','COS','TAN','ASIN','ACOS','ATAN']) + self.math_nest(['POW','LOG']) + self.math_nest(['FLOOR','CEIL','ROUND']) + self.math_nest(['MAVG']) + self.math_nest(['HYPERLOGLOG']) + self.math_nest(['TAIL']) + self.math_nest(['CSUM']) + self.math_nest(['statecount','stateduration']) + self.math_nest(['HISTOGRAM']) + + self.str_nest(['LTRIM','RTRIM','LOWER','UPPER']) + self.str_nest(['LENGTH','CHAR_LENGTH']) + self.str_nest(['SUBSTR']) + self.str_nest(['CONCAT']) + self.str_nest(['CONCAT_WS']) + self.time_nest(['CAST']) + self.time_nest(['CAST_1']) + self.time_nest(['CAST_2']) + self.time_nest(['CAST_3']) + self.time_nest(['CAST_4']) + + self.time_nest(['NOW','TODAY']) + self.time_nest(['TIMEZONE']) + self.time_nest(['TIMETRUNCATE']) + self.time_nest(['TO_ISO8601']) + self.time_nest(['TO_UNIXTIMESTAMP']) + self.time_nest(['ELAPSED']) + self.time_nest(['TIMEDIFF_1']) + self.time_nest(['TIMEDIFF_2']) + + endTime = time.time() + print("total time %ds" % (endTime - startTime)) + + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/stablity_1.py b/tests/system-test/2-query/stablity_1.py new file mode 100755 index 0000000000000000000000000000000000000000..c1a5eea3500832ba6d9fb535fcc7dc1fc4607904 --- /dev/null +++ b/tests/system-test/2-query/stablity_1.py @@ -0,0 +1,73 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- +from util.cases import tdCases +from .stablity import * + +class TDTestCase(TDTestCase): + + def run(self): + tdSql.prepare() + + startTime = time.time() + + self.function_before_26() + + self.dropandcreateDB_random("%s" %self.db_nest, 1) + + # self.math_nest(['UNIQUE']) + # self.math_nest(['MODE']) + # self.math_nest(['SAMPLE']) + + # self.math_nest(['ABS','SQRT']) + # self.math_nest(['SIN','COS','TAN','ASIN','ACOS','ATAN']) + # self.math_nest(['POW','LOG']) + # self.math_nest(['FLOOR','CEIL','ROUND']) + # self.math_nest(['MAVG']) + # self.math_nest(['HYPERLOGLOG']) + # self.math_nest(['TAIL']) + # self.math_nest(['CSUM']) + # self.math_nest(['statecount','stateduration']) + # self.math_nest(['HISTOGRAM']) + + self.str_nest(['LTRIM','RTRIM','LOWER','UPPER']) + self.str_nest(['LENGTH','CHAR_LENGTH']) + self.str_nest(['SUBSTR']) + self.str_nest(['CONCAT']) + self.str_nest(['CONCAT_WS']) + self.time_nest(['CAST']) + self.time_nest(['CAST_1']) + self.time_nest(['CAST_2']) + self.time_nest(['CAST_3']) + self.time_nest(['CAST_4']) + + self.time_nest(['NOW','TODAY']) + self.time_nest(['TIMEZONE']) + self.time_nest(['TIMETRUNCATE']) + self.time_nest(['TO_ISO8601']) + self.time_nest(['TO_UNIXTIMESTAMP']) + self.time_nest(['ELAPSED']) + self.time_nest(['TIMEDIFF_1']) + self.time_nest(['TIMEDIFF_2']) + + endTime = time.time() + print("total time %ds" % (endTime - startTime)) + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/timetruncate.py b/tests/system-test/2-query/timetruncate.py index d773114c3c3d84bb6b102852d84223d68e0c0a2f..8d1c9214e91e4b965a26681f848a5be05dd5dd6f 100644 --- a/tests/system-test/2-query/timetruncate.py +++ b/tests/system-test/2-query/timetruncate.py @@ -10,6 +10,9 @@ class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) + print(conn) + self.rest_tag = str(conn).lower().split('.')[0].replace(" 0 and actConsumeTotalRows < totalRowsInserted): tdLog.info("act consume rows: %d"%(actConsumeTotalRows)) tdLog.info("and second consume rows should be between 0 and %d"%(totalRowsInserted)) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh old mode 100755 new mode 100644 index 4c0ef5a52731975a39b576cce5918ab7a97bf9e4..2c7848d50530901c222c84435423786c6ebc240c --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -127,7 +127,7 @@ python3 ./test.py -f 2-query/leastsquares.py -R python3 ./test.py -f 2-query/length.py python3 ./test.py -f 2-query/length.py -R python3 ./test.py -f 2-query/log.py -# python3 ./test.py -f 2-query/log.py -R +python3 ./test.py -f 2-query/log.py -R python3 ./test.py -f 2-query/lower.py python3 ./test.py -f 2-query/lower.py -R python3 ./test.py -f 2-query/ltrim.py @@ -175,11 +175,11 @@ python3 ./test.py -f 2-query/sum.py -R python3 ./test.py -f 2-query/tail.py python3 ./test.py -f 2-query/tail.py -R python3 ./test.py -f 2-query/tan.py -# python3 ./test.py -f 2-query/tan.py -R +python3 ./test.py -f 2-query/tan.py -R python3 ./test.py -f 2-query/Timediff.py python3 ./test.py -f 2-query/Timediff.py -R python3 ./test.py -f 2-query/timetruncate.py -# python3 ./test.py -f 2-query/timetruncate.py -R +python3 ./test.py -f 2-query/timetruncate.py -R python3 ./test.py -f 2-query/timezone.py python3 ./test.py -f 2-query/timezone.py -R python3 ./test.py -f 2-query/To_iso8601.py @@ -187,7 +187,7 @@ python3 ./test.py -f 2-query/To_iso8601.py -R python3 ./test.py -f 2-query/To_unixtimestamp.py python3 ./test.py -f 2-query/To_unixtimestamp.py -R python3 ./test.py -f 2-query/Today.py -# python3 ./test.py -f 2-query/Today.py -R +python3 ./test.py -f 2-query/Today.py -R python3 ./test.py -f 2-query/top.py python3 ./test.py -f 2-query/top.py -R python3 ./test.py -f 2-query/tsbsQuery.py @@ -217,10 +217,12 @@ python3 ./test.py -f 2-query/concat2.py python3 ./test.py -f 2-query/json_tag.py -# python3 ./test.py -f 2-query/nestedQuery.py -# TD-15983 subquery output duplicate name column. -# Please Xiangyang Guo modify the following script -# python3 ./test.py -f 2-query/nestedQuery_str.py +python3 ./test.py -f 2-query/nestedQuery.py +python3 ./test.py -f 2-query/nestedQuery_str.py +python3 ./test.py -f 2-query/nestedQuery_math.py +python3 ./test.py -f 2-query/nestedQuery_time.py +python3 ./test.py -f 2-query/stablity.py +python3 ./test.py -f 2-query/stablity_1.py python3 ./test.py -f 2-query/elapsed.py python3 ./test.py -f 2-query/csum.py @@ -248,8 +250,8 @@ python3 ./test.py -f 6-cluster/5dnode3mnodeRestartDnodeInsertDataAsync.py -N 5 - python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 6 -M 3 -C 5 # BUG python3 ./test.py -f 6-cluster/5dnode3mnodeStopInsert.py -# python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -N 5 -python3 test.py -f 6-cluster/5dnode3mnodeStopConnect.py -N 5 -M 3 +# TD-19646 python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -N 5 +# TD-19646 python3 test.py -f 6-cluster/5dnode3mnodeStopConnect.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeRecreateMnode.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeStopFollowerLeader.py -N 5 -M 3 @@ -287,7 +289,7 @@ python3 ./test.py -f 7-tmq/subscribeDb0.py python3 ./test.py -f 7-tmq/subscribeDb1.py python3 ./test.py -f 7-tmq/subscribeDb2.py python3 ./test.py -f 7-tmq/subscribeDb3.py -#python3 ./test.py -f 7-tmq/subscribeDb4.py +python3 ./test.py -f 7-tmq/subscribeDb4.py python3 ./test.py -f 7-tmq/subscribeStb.py python3 ./test.py -f 7-tmq/subscribeStb0.py python3 ./test.py -f 7-tmq/subscribeStb1.py @@ -302,14 +304,14 @@ python3 ./test.py -f 7-tmq/tmqCheckData.py python3 ./test.py -f 7-tmq/tmqCheckData1.py #python3 ./test.py -f 7-tmq/tmq3mnodeSwitch.py -N 5 python3 ./test.py -f 7-tmq/tmqConsumerGroup.py -#python3 ./test.py -f 7-tmq/tmqShow.py +python3 ./test.py -f 7-tmq/tmqShow.py python3 ./test.py -f 7-tmq/tmqAlterSchema.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb1.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb-mutilVg.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-mutilVg.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb-1ctb.py -# python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-1ctb.py +python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-1ctb.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb-1ctb-funcNFilter.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb-funcNFilter.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb.py @@ -609,4 +611,3 @@ python3 ./test.py -f 2-query/last_row.py -Q 4 python3 ./test.py -f 2-query/tsbsQuery.py -Q 4 #python3 ./test.py -f 2-query/sml.py -Q 4 python3 ./test.py -f 2-query/interp.py -Q 4 - diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 98d21a4f2cc327e429646b2e045ae44d468c9523..c6a5e337355e8ba0cd0c6260c5ef6bc3a2741e3e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -17,7 +17,8 @@ IF (TD_WEBSOCKET) PATCH_COMMAND COMMAND git clean -f -d BUILD_COMMAND - COMMAND cargo build --release -p taos-ws-sys + COMMAND cargo update + COMMAND cargo build --release -p taos-ws-sys --features native-tls-vendored COMMAND ./taos-ws-sys/ci/package.sh INSTALL_COMMAND COMMAND cmake -E copy target/libtaosws/${websocket_lib_file} ${CMAKE_BINARY_DIR}/build/lib @@ -36,7 +37,8 @@ IF (TD_WEBSOCKET) PATCH_COMMAND COMMAND git clean -f -d BUILD_COMMAND - COMMAND cargo build --release -p taos-ws-sys + COMMAND cargo update + COMMAND cargo build --release -p taos-ws-sys --features native-tls-vendored COMMAND ./taos-ws-sys/ci/package.sh INSTALL_COMMAND COMMAND cmake -E copy target/libtaosws/${websocket_lib_file} ${CMAKE_BINARY_DIR}/build/lib diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 46eaf6cff1a7d070a88ae4fa1dc67cb0512de75a..e7dfd45c602b5020446a5ca8d6249d9ff0f40093 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -30,6 +30,7 @@ void shellClearScreen(int32_t ecmd_pos, int32_t cursor_pos); void shellGetPrevCharSize(const char* str, int32_t pos, int32_t* size, int32_t* width); void shellShowOnScreen(SShellCmd* cmd); void shellInsertChar(SShellCmd* cmd, char* c, int size); +void shellInsertStr(SShellCmd* cmd, char* str, int size); bool appendAfterSelect(TAOS* con, SShellCmd* cmd, char* p, int32_t len); typedef struct SAutoPtr { @@ -562,23 +563,15 @@ void parseCommand(SWords* command, bool pattern) { // free SShellCmd void freeCommand(SWords* command) { - SWord* word = command->head; - if (word == NULL) { - return; - } - + SWord* item = command->head; // loop - while (word->next) { - SWord* tmp = word; - word = word->next; + while (item) { + SWord* tmp = item; + item = item->next; // if malloc need free if (tmp->free && tmp->word) taosMemoryFree(tmp->word); taosMemoryFree(tmp); } - - // if malloc need free - if (word->free && word->word) taosMemoryFree(word->word); - taosMemoryFree(word); } void GenerateVarType(int type, char** p, int count) { @@ -1107,7 +1100,7 @@ void printScreen(TAOS* con, SShellCmd* cmd, SWords* match) { } // insert new - shellInsertChar(cmd, (char*)str, strLen); + shellInsertStr(cmd, (char*)str, strLen); } // main key press tab , matched return true else false @@ -1204,11 +1197,11 @@ bool nextMatchCommand(TAOS* con, SShellCmd* cmd, SWords* firstMatch) { #endif // free + freeCommand(input); if (input->source) { taosMemoryFree(input->source); input->source = NULL; } - freeCommand(input); taosMemoryFree(input); return true; @@ -1228,7 +1221,7 @@ bool fillWithType(TAOS* con, SShellCmd* cmd, char* pre, int type) { // show int count = strlen(part); - shellInsertChar(cmd, part, count); + shellInsertStr(cmd, part, count); cntDel = count; // next press tab delete current append count taosMemoryFree(str); @@ -1255,7 +1248,7 @@ bool fillTableName(TAOS* con, SShellCmd* cmd, char* pre) { // show int count = strlen(part); - shellInsertChar(cmd, part, count); + shellInsertStr(cmd, part, count); cntDel = count; // next press tab delete current append count taosMemoryFree(str); @@ -1377,9 +1370,9 @@ bool appendAfterSelect(TAOS* con, SShellCmd* cmd, char* sql, int32_t len) { bool ret = false; if (from == NULL) { bool fieldEnd = fieldsInputEnd(p); - // cheeck fields input end then insert from keyword + // check fields input end then insert from keyword if (fieldEnd && p[len - 1] == ' ') { - shellInsertChar(cmd, "from", 4); + shellInsertStr(cmd, "from", 4); taosMemoryFree(p); return true; } @@ -1577,7 +1570,7 @@ bool matchOther(TAOS* con, SShellCmd* cmd) { if (p[len - 1] == '\\') { // append '\G' char a[] = "G;"; - shellInsertChar(cmd, a, 2); + shellInsertStr(cmd, a, 2); return true; } diff --git a/tools/shell/src/shellCommand.c b/tools/shell/src/shellCommand.c index c34b22b691c077b7e08ca7afb4e929f6851d95e2..5235030cf91cac5d41b782544da9d8a7be4e1349 100644 --- a/tools/shell/src/shellCommand.c +++ b/tools/shell/src/shellCommand.c @@ -47,6 +47,7 @@ void shellClearScreen(int32_t ecmd_pos, int32_t cursor_pos); void shellShowOnScreen(SShellCmd *cmd); void shellGetPrevCharSize(const char *str, int32_t pos, int32_t *size, int32_t *width); void shellInsertChar(SShellCmd *cmd, char *c, int size); +void shellInsertString(SShellCmd *cmd, char *str, int size); int32_t shellCountPrefixOnes(uint8_t c) { uint8_t mask = 127; @@ -102,7 +103,31 @@ void shellInsertChar(SShellCmd *cmd, char *c, int32_t size) { cmd->commandSize += size; cmd->cursorOffset += size; cmd->screenOffset += taosWcharWidth(wc); - cmd->endOffset += taosWcharWidth(wc); + cmd->endOffset += taosWcharWidth(wc); + + // set string end + cmd->command[cmd->commandSize] = 0; +#ifdef WINDOWS +#else + shellShowOnScreen(cmd); +#endif +} + +// insert string . count is str char count +void shellInsertStr(SShellCmd *cmd, char *str, int32_t size) { + shellClearScreen(cmd->endOffset + PSIZE, cmd->screenOffset + PSIZE); + /* update the buffer */ + memmove(cmd->command + cmd->cursorOffset + size, cmd->command + cmd->cursorOffset, + cmd->commandSize - cmd->cursorOffset); + memcpy(cmd->command + cmd->cursorOffset, str, size); + /* update the values */ + cmd->commandSize += size; + cmd->cursorOffset += size; + cmd->screenOffset += size; + cmd->endOffset += size; + + // set string end + cmd->command[cmd->commandSize] = 0; #ifdef WINDOWS #else shellShowOnScreen(cmd); @@ -123,6 +148,8 @@ void shellBackspaceChar(SShellCmd *cmd) { cmd->cursorOffset -= size; cmd->screenOffset -= width; cmd->endOffset -= width; + // set string end + cmd->command[cmd->commandSize] = 0; shellShowOnScreen(cmd); } } @@ -136,6 +163,8 @@ void shellClearLineBefore(SShellCmd *cmd) { cmd->cursorOffset = 0; cmd->screenOffset = 0; cmd->endOffset = cmd->commandSize; + // set string end + cmd->command[cmd->commandSize] = 0; shellShowOnScreen(cmd); } @@ -160,6 +189,8 @@ void shellDeleteChar(SShellCmd *cmd) { cmd->commandSize - cmd->cursorOffset - size); cmd->commandSize -= size; cmd->endOffset -= width; + // set string end + cmd->command[cmd->commandSize] = 0; shellShowOnScreen(cmd); } } @@ -469,9 +500,11 @@ int32_t shellReadCommand(char *command) { } shellInsertChar(&cmd, utf8_array, count); pressOtherKey(c); +#ifndef WINDOWS } else if (c == TAB_KEY) { // press TAB key pressTabKey(&cmd); +#endif } else if (c < '\033') { pressOtherKey(c); // Ctrl keys. TODO: Implement ctrl combinations diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 37d00c0a7ce9d5a2d91ae7a2f9747097361e2c1f..d5c765e8c5b0fcf38080a58e605a52e29a859bb2 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -282,9 +282,14 @@ char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision) { void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, int32_t length, int32_t precision) { if (val == NULL) { + taosFprintfFile(pFile, "NULL"); return; } + char quotationStr[2]; + quotationStr[0] = '\"'; + quotationStr[1] = 0; + int n; char buf[TSDB_MAX_BYTES_PER_ROW]; switch (field->type) { @@ -330,33 +335,23 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_JSON: { - char quotationStr[2]; int32_t bufIndex = 0; - quotationStr[0] = 0; - quotationStr[1] = 0; for (int32_t i = 0; i < length; i++) { buf[bufIndex] = val[i]; bufIndex++; if (val[i] == '\"') { buf[bufIndex] = val[i]; bufIndex++; - quotationStr[0] = '\"'; - } - if (val[i] == ',') { - quotationStr[0] = '\"'; } } buf[bufIndex] = 0; - if (length == 0) { - quotationStr[0] = '\"'; - } taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr); } break; case TSDB_DATA_TYPE_TIMESTAMP: shellFormatTimestamp(buf, *(int64_t *)val, precision); - taosFprintfFile(pFile, "%s", buf); + taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr); break; default: break; diff --git a/tools/shell/src/shellTire.c b/tools/shell/src/shellTire.c index 346757b76fea28b1cf918572606a29b6a3ef65b1..06285709045fb9f7e60f4f8bde927a1f86b0d81a 100644 --- a/tools/shell/src/shellTire.c +++ b/tools/shell/src/shellTire.c @@ -309,27 +309,24 @@ void matchPrefixFromTree(STire* tire, char* prefix, SMatch* match) { } SMatch* matchPrefix(STire* tire, char* prefix, SMatch* match) { - if (match == NULL) { - match = (SMatch*)taosMemoryMalloc(sizeof(SMatch)); - memset(match, 0, sizeof(SMatch)); + SMatch* rMatch = match; // define return match + if (rMatch == NULL) { + rMatch = (SMatch*)taosMemoryMalloc(sizeof(SMatch)); + memset(rMatch, 0, sizeof(SMatch)); } switch (tire->type) { case TIRE_TREE: - matchPrefixFromTree(tire, prefix, match); + matchPrefixFromTree(tire, prefix, rMatch); + break; case TIRE_LIST: - matchPrefixFromList(tire, prefix, match); + matchPrefixFromList(tire, prefix, rMatch); + break; default: break; } - // return if need - if (match->count == 0) { - freeMatch(match); - match = NULL; - } - - return match; + return rMatch; } // get all items from tires tree @@ -378,8 +375,10 @@ SMatch* enumAll(STire* tire) { switch (tire->type) { case TIRE_TREE: enumFromTree(tire, match); + break; case TIRE_LIST: enumFromList(tire, match); + break; default: break; } diff --git a/tools/taosws-rs b/tools/taosws-rs deleted file mode 160000 index 1bdfca396cd6730cdc334e06fc7b2156dd1239a0..0000000000000000000000000000000000000000 --- a/tools/taosws-rs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1bdfca396cd6730cdc334e06fc7b2156dd1239a0 diff --git a/utils/test/c/createTable.c b/utils/test/c/createTable.c index 783ed85adce6dbc282b25987b2864d3903a326e2..9a39fdd9752dd9343040bb9b3e7bb6ae9dc3ab79 100644 --- a/utils/test/c/createTable.c +++ b/utils/test/c/createTable.c @@ -330,11 +330,11 @@ void parseArgument(int32_t argc, char *argv[]) { printHelp(); exit(0); } else if (strcmp(argv[i], "-d") == 0) { - strcpy(dbName, argv[++i]); + tstrncpy(dbName, argv[++i], sizeof(dbName)); } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); + tstrncpy(configDir, argv[++i], PATH_MAX); } else if (strcmp(argv[i], "-s") == 0) { - strcpy(stbName, argv[++i]); + tstrncpy(stbName, argv[++i], sizeof(stbName)); } else if (strcmp(argv[i], "-t") == 0) { numOfThreads = atoi(argv[++i]); } else if (strcmp(argv[i], "-n") == 0) { diff --git a/utils/test/c/tmqSim.c b/utils/test/c/tmqSim.c index 25e83363ee03052a4fa15b16a12af4593f0aad04..f77a910f3571fd94b8c47d03b27f17e05223e599 100644 --- a/utils/test/c/tmqSim.c +++ b/utils/test/c/tmqSim.c @@ -497,9 +497,14 @@ static char* shellFormatTimestamp(char* buf, int64_t val, int32_t precision) { static void shellDumpFieldToFile(TdFilePtr pFile, const char* val, TAOS_FIELD* field, int32_t length, int32_t precision) { if (val == NULL) { + taosFprintfFile(pFile, "NULL"); return; } + char quotationStr[2]; + quotationStr[0] = '\"'; + quotationStr[1] = 0; + int n; char buf[TSDB_MAX_BYTES_PER_ROW]; switch (field->type) { @@ -545,33 +550,23 @@ static void shellDumpFieldToFile(TdFilePtr pFile, const char* val, TAOS_FIELD* f case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_JSON: { - char quotationStr[2]; int32_t bufIndex = 0; - quotationStr[0] = 0; - quotationStr[1] = 0; for (int32_t i = 0; i < length; i++) { buf[bufIndex] = val[i]; bufIndex++; if (val[i] == '\"') { buf[bufIndex] = val[i]; bufIndex++; - quotationStr[0] = '\"'; - } - if (val[i] == ',') { - quotationStr[0] = '\"'; } } buf[bufIndex] = 0; - if (length == 0) { - quotationStr[0] = '\"'; - } taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr); } break; case TSDB_DATA_TYPE_TIMESTAMP: shellFormatTimestamp(buf, *(int64_t*)val, precision); - taosFprintfFile(pFile, "%s", buf); + taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr); break; default: break; @@ -1262,7 +1257,7 @@ void* ombProduceThreadFunc(void* param) { printf("Produce Info: totalSendLoopTimes: %d, batchPerTblTimes: %d, producerRate: %d\n", totalSendLoopTimes, batchPerTblTimes, pInfo->producerRate); - char ctbName[64] = {0}; + char ctbName[128] = {0}; sprintf(ctbName, "%s.ctb%d", g_stConfInfo.dbName, pInfo->consumerId); int64_t lastPrintTime = taosGetTimestampUs(); diff --git a/utils/tsim/inc/simInt.h b/utils/tsim/inc/simInt.h index f9e96fc67b20eee8b05619475c3d577cfa5b659c..f512b119b4299c9146a3a9a915a2359ca52fc4c4 100644 --- a/utils/tsim/inc/simInt.h +++ b/utils/tsim/inc/simInt.h @@ -19,20 +19,20 @@ #include "os.h" #include "cJSON.h" -#include "tconfig.h" #include "taos.h" #include "taoserror.h" +#include "tconfig.h" +#include "tglobal.h" #include "tidpool.h" #include "tlog.h" #include "ttimer.h" #include "ttypes.h" #include "tutil.h" -#include "tglobal.h" #define MAX_MAIN_SCRIPT_NUM 10 #define MAX_BACKGROUND_SCRIPT_NUM 10 #define MAX_FILE_NAME_LEN 256 -#define MAX_ERROR_LEN 1024 +#define MAX_ERROR_LEN 4096 #define MAX_QUERY_VALUE_LEN 1024 #define MAX_QUERY_COL_NUM 100 #define MAX_QUERY_ROW_NUM 100 @@ -55,12 +55,42 @@ #define FAILED_POSTFIX "" #endif -#define simFatal(...) { if (simDebugFlag & DEBUG_FATAL) { taosPrintLog("SIM FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} -#define simError(...) { if (simDebugFlag & DEBUG_ERROR) { taosPrintLog("SIM ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} -#define simWarn(...) { if (simDebugFlag & DEBUG_WARN) { taosPrintLog("SIM WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} -#define simInfo(...) { if (simDebugFlag & DEBUG_INFO) { taosPrintLog("SIM ", DEBUG_INFO, 255, __VA_ARGS__); }} -#define simDebug(...) { if (simDebugFlag & DEBUG_DEBUG) { taosPrintLog("SIM ", DEBUG_DEBUG, simDebugFlag, __VA_ARGS__); }} -#define simTrace(...) { if (simDebugFlag & DEBUG_TRACE) { taosPrintLog("SIM ", DEBUG_TRACE, simDebugFlag, __VA_ARGS__); }} +#define simFatal(...) \ + { \ + if (simDebugFlag & DEBUG_FATAL) { \ + taosPrintLog("SIM FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ + } \ + } +#define simError(...) \ + { \ + if (simDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("SIM ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ + } \ + } +#define simWarn(...) \ + { \ + if (simDebugFlag & DEBUG_WARN) { \ + taosPrintLog("SIM WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ + } \ + } +#define simInfo(...) \ + { \ + if (simDebugFlag & DEBUG_INFO) { \ + taosPrintLog("SIM ", DEBUG_INFO, 255, __VA_ARGS__); \ + } \ + } +#define simDebug(...) \ + { \ + if (simDebugFlag & DEBUG_DEBUG) { \ + taosPrintLog("SIM ", DEBUG_DEBUG, simDebugFlag, __VA_ARGS__); \ + } \ + } +#define simTrace(...) \ + { \ + if (simDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("SIM ", DEBUG_TRACE, simDebugFlag, __VA_ARGS__); \ + } \ + } enum { SIM_SCRIPT_TYPE_MAIN, SIM_SCRIPT_TYPE_BACKGROUND }; @@ -143,7 +173,7 @@ typedef struct _script_t { char *optionBuffer; SCmdLine *lines; // command list SVariable variables[MAX_VAR_LEN]; - TdThread bgPid; + TdThread bgPid; char auth[128]; struct _script_t *bgScripts[MAX_BACKGROUND_SCRIPT_NUM]; } SScript; @@ -155,7 +185,6 @@ extern int32_t simScriptSucced; extern int32_t simDebugFlag; extern char simScriptDir[]; extern bool abortExecution; -extern bool useMultiProcess; extern bool useValgrind; SScript *simParseScript(char *fileName); @@ -183,4 +212,4 @@ bool simExecuteLineInsertCmd(SScript *script, char *option); bool simExecuteLineInsertErrorCmd(SScript *script, char *option); void simVisuallizeOption(SScript *script, char *src, char *dst); -#endif /*_TD_SIM_INT_H_*/ \ No newline at end of file +#endif /*_TD_SIM_INT_H_*/ diff --git a/utils/tsim/src/simExe.c b/utils/tsim/src/simExe.c index 6f693cf015e9690a05f90429803250a6ce8b237c..258c61155769be2d3aef314ee1602a4ba1b8af3d 100644 --- a/utils/tsim/src/simExe.c +++ b/utils/tsim/src/simExe.c @@ -21,34 +21,19 @@ void simLogSql(char *sql, bool useSharp) { char filename[256]; sprintf(filename, "%s/sim.sql", simScriptDir); if (pFile == NULL) { - // fp = fopen(filename, "w"); pFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); - if (pFile == NULL) { - fprintf(stderr, "ERROR: failed to open file: %s\n", filename); - return; - } - } - if (useSharp) { - taosFprintfFile(pFile, "# %s;\n", sql); - } else { - taosFprintfFile(pFile, "%s;\n", sql); } - taosFsyncFile(pFile); -} + if (pFile != NULL) { + if (useSharp) { + taosFprintfFile(pFile, "# %s;\n", sql); + } else { + taosFprintfFile(pFile, "%s;\n", sql); + } -#if 0 -char *simParseArbitratorName(char *varName) { - static char hostName[140]; -#ifdef WINDOWS - taosGetFqdn(hostName); - sprintf(&hostName[strlen(hostName)], ":%d", 8000); -#else - sprintf(hostName, "%s:%d", "localhost", 8000); -#endif - return hostName; + taosFsyncFile(pFile); + } } -#endif char *simParseHostName(char *varName) { static char hostName[140]; @@ -65,18 +50,18 @@ char *simParseHostName(char *varName) { } static void simFindFirstNum(const char *begin, int32_t beginLen, int32_t *num) { - if (beginLen <= 5) { - *num = 0; - } else { + *num = 0; + + if (beginLen > 5) { *num = atoi(begin + 5); } } static void simFindSecondNum(const char *begin, int32_t beginLen, int32_t *num) { + *num = 0; + const char *number = strstr(begin, "]["); - if (number == NULL) { - *num = 0; - } else { + if (number != NULL) { *num = atoi(number + 2); } } @@ -91,10 +76,10 @@ static void simFindFirstKeyVal(const char *begin, int32_t beginLen, char *key, i } static void simFindSecondKeyNum(const char *begin, int32_t beginLen, int32_t *num) { + *num = 0; + const char *number = strstr(begin, ")["); - if (number == NULL) { - *num = 0; - } else { + if (number != NULL) { *num = atoi(number + 2); } } @@ -104,12 +89,6 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { return simParseHostName(varName); } -#if 0 - if (strncmp(varName, "arbitrator", 10) == 0) { - return simParseArbitratorName(varName); - } -#endif - if (strncmp(varName, "error", varLen) == 0) return script->error; if (strncmp(varName, "rows", varLen) == 0) return script->rows; @@ -153,9 +132,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { } else if (varName[5] == '_') { // data2_db int32_t col = varName[4] - '0'; - if (col < 0 || col >= MAX_QUERY_COL_NUM) { - return "null"; - } + col = col % MAX_QUERY_COL_NUM; char *keyName; int32_t keyLen; @@ -171,9 +148,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { } else if (varName[6] == '_') { // data21_db int32_t col = (varName[4] - '0') * 10 + (varName[5] - '0'); - if (col < 0 || col >= MAX_QUERY_COL_NUM) { - return "null"; - } + col = col % MAX_QUERY_COL_NUM; char *keyName; int32_t keyLen; @@ -185,17 +160,12 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { return script->data[i][col]; } } - return "null"; } else { // $data00 int32_t row = varName[4] - '0'; int32_t col = varName[5] - '0'; - if (row < 0 || row >= MAX_QUERY_ROW_NUM) { - return "null"; - } - if (col < 0 || col >= MAX_QUERY_COL_NUM) { - return "null"; - } + row = row % MAX_QUERY_ROW_NUM; + col = col % MAX_QUERY_COL_NUM; simDebug("script:%s, data[%d][%d]=%s", script->fileName, row, col, script->data[row][col]); return script->data[row][col]; @@ -253,9 +223,9 @@ int32_t simExecuteExpression(SScript *script, char *exp) { rest = paGetToken(rest, &op2, &op2Len); if (var1[0] == '$') - strcpy(t0, simGetVariable(script, var1 + 1, var1Len - 1)); + tstrncpy(t0, simGetVariable(script, var1 + 1, var1Len - 1), sizeof(t0)); else { - memcpy(t0, var1, var1Len); + tstrncpy(t0, var1, var1Len); t0[var1Len] = 0; } @@ -292,7 +262,7 @@ int32_t simExecuteExpression(SScript *script, char *exp) { sprintf(t3, "%" PRId64, t1l / t2l); } } else if (op2[0] == '.') { - sprintf(t3, "%s%s", t1, t2); + snprintf(t3, sizeof(t3), "%s%s", t1, t2); } } else { tstrncpy(t3, t1, sizeof(t3)); @@ -442,10 +412,6 @@ bool simExecuteSystemCmd(SScript *script, char *option) { simReplaceStr(buf, ".sh", ".bat"); #endif - if (useMultiProcess) { - simReplaceStr(buf, "deploy.sh", "deploy.sh -m"); - } - if (useValgrind) { replaced = simReplaceStr(buf, "exec.sh", "exec.sh -v"); } @@ -582,6 +548,8 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) { while (1) { var = strchr(src, '$'); if (var == NULL) break; + +#if 0 if (var && ((var - src - 1) > 0) && *(var - 1) == '\\') { srcLen = (int32_t)(var - src - 1); memcpy(dst + dstLen, src, srcLen); @@ -589,6 +557,7 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) { src = var; break; } +#endif srcLen = (int32_t)(var - src); memcpy(dst + dstLen, src, srcLen); @@ -661,11 +630,11 @@ bool simCreateTaosdConnect(SScript *script, char *rest) { } bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { - char timeStr[80] = {0}; - time_t tt; - struct tm tp; - SCmdLine *line = &script->lines[script->linePos]; - int32_t ret = -1; + char timeStr[80] = {0}; + time_t tt; + struct tm tp; + SCmdLine *line = &script->lines[script->linePos]; + int32_t ret = -1; TAOS_RES *pSql = NULL; @@ -709,17 +678,6 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { int32_t numOfRows = 0; int32_t num_fields = taos_field_count(pSql); if (num_fields != 0) { - if (pSql == NULL) { - simDebug("script:%s, taos:%p, %s failed, result is null", script->fileName, script->taos, rest); - if (line->errorJump == SQL_JUMP_TRUE) { - script->linePos = line->jump; - return true; - } - - sprintf(script->error, "lineNum:%d. result set null, sql:%s", line->lineNum, rest); - return false; - } - TAOS_ROW row; while ((row = taos_fetch_row(pSql))) { @@ -946,30 +904,6 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) { } } - if (strncmp(rest, "connect", 7) == 0) { - if (!simCreateTaosdConnect(script, rest)) { - return false; - } - script->linePos++; - return true; - } - - if (script->taos == NULL) { - if (!simCreateTaosdConnect(script, "connect root")) { - if (line->errorJump == SQL_JUMP_TRUE) { - script->linePos = line->jump; - return true; - } - return false; - } - } - - if (strncmp(rest, "close", 5) == 0) { - simCloseTaosdConnect(script); - script->linePos++; - return true; - } - TAOS_RES *pSql = taos_query(script->taos, rest); int32_t ret = taos_errno(pSql); taos_free_result(pSql); @@ -1044,4 +978,4 @@ bool simExecuteLineInsertErrorCmd(SScript *script, char *rest) { return true; } } -#endif \ No newline at end of file +#endif diff --git a/utils/tsim/src/simMain.c b/utils/tsim/src/simMain.c index e58a22cf682d1cbc5be9a32057caee25ef00c254..cd4a5117b2a5904b934775d4a24a23059714a1a7 100644 --- a/utils/tsim/src/simMain.c +++ b/utils/tsim/src/simMain.c @@ -18,7 +18,6 @@ bool simExecSuccess = false; bool abortExecution = false; -bool useMultiProcess = false; bool useValgrind = false; void simHandleSignal(int32_t signo, void *sigInfo, void *context) { @@ -34,8 +33,6 @@ int32_t main(int32_t argc, char *argv[]) { tstrncpy(configDir, argv[++i], 128); } else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) { tstrncpy(scriptFile, argv[++i], MAX_FILE_NAME_LEN); - } else if (strcmp(argv[i], "-m") == 0) { - useMultiProcess = true; } else if (strcmp(argv[i], "-v") == 0) { useValgrind = true; } else { diff --git a/utils/tsim/src/simParse.c b/utils/tsim/src/simParse.c index ae523edfc4b2f6e0ebc6f62155f79cb4540d3945..cdd918ac00745aa027f5d2d26adcdb605f703573 100644 --- a/utils/tsim/src/simParse.c +++ b/utils/tsim/src/simParse.c @@ -717,20 +717,12 @@ bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) { return true; } -#if 0 bool simParseSqlSlowCmd(char *rest, SCommand *pCmd, int32_t lineNum) { simParseSqlCmd(rest, pCmd, lineNum); cmdLine[numOfLines - 1].cmdno = SIM_CMD_SQL_SLOW; return true; } -bool simParseRestfulCmd(char *rest, SCommand *pCmd, int32_t lineNum) { - simParseSqlCmd(rest, pCmd, lineNum); - cmdLine[numOfLines - 1].cmdno = SIM_CMD_RESTFUL; - return true; -} -#endif - bool simParseSystemCmd(char *rest, SCommand *pCmd, int32_t lineNum) { int32_t expLen; @@ -1058,7 +1050,6 @@ void simInitsimCmdList() { simCmdList[cmdno].executeCmd = simExecuteSqlErrorCmd; simAddCmdIntoHash(&(simCmdList[cmdno])); -#if 0 cmdno = SIM_CMD_SQL_SLOW; simCmdList[cmdno].cmdno = cmdno; strcpy(simCmdList[cmdno].name, "sql_slow"); @@ -1067,15 +1058,6 @@ void simInitsimCmdList() { simCmdList[cmdno].executeCmd = simExecuteSqlSlowCmd; simAddCmdIntoHash(&(simCmdList[cmdno])); - cmdno = SIM_CMD_RESTFUL; - simCmdList[cmdno].cmdno = cmdno; - strcpy(simCmdList[cmdno].name, "restful"); - simCmdList[cmdno].nlen = (int16_t)strlen(simCmdList[cmdno].name); - simCmdList[cmdno].parseCmd = simParseRestfulCmd; - simCmdList[cmdno].executeCmd = simExecuteRestfulCmd; - simAddCmdIntoHash(&(simCmdList[cmdno])); -#endif - /* test is only an internal command */ cmdno = SIM_CMD_TEST; simCmdList[cmdno].cmdno = cmdno;