diff --git a/docs/en/12-taos-sql/06-select.md b/docs/en/12-taos-sql/06-select.md index 687349e31d..7ef47f2131 100755 --- a/docs/en/12-taos-sql/06-select.md +++ b/docs/en/12-taos-sql/06-select.md @@ -7,7 +7,7 @@ description: This document describes how to query data in TDengine. ## Syntax ```sql -SELECT {DATABASE() | CLIENT_VERSION() | SERVER_VERSION() | SERVER_STATUS() | NOW() | TODAY() | TIMEZONE()} +SELECT {DATABASE() | CLIENT_VERSION() | SERVER_VERSION() | SERVER_STATUS() | NOW() | TODAY() | TIMEZONE() | CURRENT_USER() | USER() } SELECT [hints] [DISTINCT] [TAGS] select_list from_clause @@ -195,7 +195,7 @@ The following SQL statement returns the number of subtables within the meters su SELECT COUNT(*) FROM (SELECT DISTINCT TBNAME FROM meters); ``` -In the preceding two statements, only tags can be used as filtering conditions in the WHERE clause. For example: +In the preceding two statements, only tags can be used as filtering conditions in the WHERE clause. **\_QSTART and \_QEND** @@ -245,8 +245,7 @@ You can perform INNER JOIN statements based on the primary key. The following co 3. For supertables, the ON condition must be equivalent to the primary key. In addition, the tag columns of the tables on which the INNER JOIN is performed must have a one-to-one relationship. You cannot specify an OR condition. 4. The tables that are included in a JOIN clause must be of the same type (supertable, standard table, or subtable). 5. You can include subqueries before and after the JOIN keyword. -6. You cannot include more than ten tables in a JOIN clause. -7. You cannot include a FILL clause and a JOIN clause in the same statement. +6. You cannot include a FILL clause and a JOIN clause in the same statement. ## GROUP BY @@ -337,6 +336,12 @@ SELECT TODAY(); SELECT TIMEZONE(); ``` +### Obtain Current User + +```sql +SELECT CURRENT_USER(); +``` + ## Regular Expression ### Syntax @@ -391,7 +396,7 @@ SELECT AVG(CASE WHEN voltage < 200 or voltage > 250 THEN 220 ELSE voltage END) F ## JOIN -TDengine supports the `INTER JOIN` based on the timestamp primary key, that is, the `JOIN` condition must contain the timestamp primary key. As long as the requirement of timestamp-based primary key is met, `INTER JOIN` can be made between normal tables, sub-tables, super tables and sub-queries at will, and there is no limit on the number of tables. +TDengine supports the `INTER JOIN` based on the timestamp primary key, that is, the `JOIN` condition must contain the timestamp primary key. As long as the requirement of timestamp-based primary key is met, `INTER JOIN` can be made between normal tables, sub-tables, super tables and sub-queries at will, and there is no limit on the number of tables, primary key and other conditions must be combined with `AND` operator. For standard tables: diff --git a/docs/en/12-taos-sql/10-function.md b/docs/en/12-taos-sql/10-function.md index 234625bfb4..b0c5f82985 100644 --- a/docs/en/12-taos-sql/10-function.md +++ b/docs/en/12-taos-sql/10-function.md @@ -1275,6 +1275,14 @@ SELECT SERVER_STATUS(); **Description**: The server status. +### CURRENT_USER + +```sql +SELECT CURRENT_USER(); +``` + +**Description**: get current user. + ## Geometry Functions diff --git a/docs/en/12-taos-sql/20-keywords.md b/docs/en/12-taos-sql/20-keywords.md index d563181b87..983d4f63c9 100644 --- a/docs/en/12-taos-sql/20-keywords.md +++ b/docs/en/12-taos-sql/20-keywords.md @@ -178,7 +178,7 @@ The following list shows all reserved keywords: - MATCH - MAX_DELAY -- MAX_SPEED +- BWLIMIT - MAXROWS - MERGE - META diff --git a/docs/en/12-taos-sql/24-show.md b/docs/en/12-taos-sql/24-show.md index b663fbd435..7a58343f24 100644 --- a/docs/en/12-taos-sql/24-show.md +++ b/docs/en/12-taos-sql/24-show.md @@ -22,6 +22,14 @@ SHOW CLUSTER; Shows information about the current cluster. +## SHOW CLUSTER ALIVE + +```sql +SHOW CLUSTER ALIVE; +``` + +It is used to check whether the cluster is available or not. Return value: 0 means unavailable, 1 means available, 2 means partially available (some dnodes are offline, the other dnodes are available) + ## SHOW CONNECTIONS ```sql diff --git a/docs/en/12-taos-sql/27-indexing.md b/docs/en/12-taos-sql/27-indexing.md index a89c8929c1..1badd38d17 100644 --- a/docs/en/12-taos-sql/27-indexing.md +++ b/docs/en/12-taos-sql/27-indexing.md @@ -19,6 +19,9 @@ index_option: functions: function [, function] ... ``` +### tag Indexing + + [tag index](../tag-index) ### SMA Indexing diff --git a/docs/en/12-taos-sql/28-recovery.md b/docs/en/12-taos-sql/28-recovery.md index b4da25ea0c..1c1838f616 100644 --- a/docs/en/12-taos-sql/28-recovery.md +++ b/docs/en/12-taos-sql/28-recovery.md @@ -17,7 +17,7 @@ You can use the SHOW CONNECTIONS statement to find the conn_id. ## Terminate a Query ```sql -KILL QUERY kill_id; +KILL QUERY 'kill_id'; ``` You can use the SHOW QUERIES statement to find the kill_id. diff --git a/docs/en/14-reference/03-connector/03-cpp.mdx b/docs/en/14-reference/03-connector/03-cpp.mdx index 3e1a0f9545..f6ebf0fe47 100644 --- a/docs/en/14-reference/03-connector/03-cpp.mdx +++ b/docs/en/14-reference/03-connector/03-cpp.mdx @@ -168,6 +168,12 @@ The base API is used to do things like create database connections and provide a ::: +- `TAOS *taos_connect_auth(const char *host, const char *user, const char *auth, const char *db, uint16_t port)` + + The function is the same as taos_connect. Except that the pass parameter is replaced by auth, other parameters are the same as taos_connect. + + - auth: the 32-bit lowercase md5 of the raw password + - `char *taos_get_server_info(TAOS *taos)` Get server-side version information. @@ -184,6 +190,14 @@ The base API is used to do things like create database connections and provide a - If len is less than the space required to store the db (including the last '\0'), an error is returned. The truncated data assigned in the database ends with '\0'. - If len is greater than or equal to the space required to store the db (including the last '\0'), return normal 0, and assign the db name ending with '\0' in the database. +- `int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type)` + + Set the event callback function. + + - fp: event callback function pointer. Declaration:typedef void (*__taos_notify_fn_t)(void *param, void *ext, int type);Param is a user-defined parameter, ext is an extended parameter (depending on the event type, and returns the user password version for TAOS_NOTIFY_PASSVER), and type is the event type + - param: user-defined parameter + - type: event type. Value range: 1) TAOS_NOTIFY_PASSVER: User password changed + - `void taos_close(TAOS *taos)` Closes the connection, where `taos` is the handle returned by `taos_connect()`. @@ -307,21 +321,20 @@ The specific functions related to the interface are as follows (see also the [pr Parse a SQL command, and bind the parsed result and parameter information to `stmt`. If the parameter length is greater than 0, use this parameter as the length of the SQL command. If it is equal to 0, the length of the SQL command will be determined automatically. -- `int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind)` +- `int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind)` Not as efficient as `taos_stmt_bind_param_batch()`, but can support non-INSERT type SQL statements. To bind parameters, bind points to an array (representing the row of data to be bound), making sure that the number and order of the elements in this array are the same as the parameters in the SQL statement. taos_bind is used similarly to MYSQL_BIND in MySQL, as defined below. ```c - typedef struct TAOS_BIND { + typedef struct TAOS_MULTI_BIND { int buffer_type; - void * buffer; - uintptr_t buffer_length; // not in use - uintptr_t * length; - int * is_null; - int is_unsigned; // not in use - int * error; // not in use - } TAOS_BIND; + void *buffer; + uintptr_t buffer_length; + uint32_t *length; + char *is_null; + int num; + } TAOS_MULTI_BIND; ``` - `int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name)` @@ -329,7 +342,7 @@ The specific functions related to the interface are as follows (see also the [pr (Available in 2.1.1.0 and later versions, only supported for replacing parameter values in INSERT statements) When the table name in the SQL command uses `? ` placeholder, you can use this function to bind a specific table name. -- `int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags)` +- `int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_MULTI_BIND* tags)` (Available in 2.1.2.0 and later versions, only supported for replacing parameter values in INSERT statements) When the table name and TAGS in the SQL command both use `? `, you can use this function to bind the specific table name and the specific TAGS value. The most typical usage scenario is an INSERT statement that uses the automatic table building function (the current version does not support specifying specific TAGS columns.) The number of columns in the TAGS parameter needs to be the same as the number of TAGS requested in the SQL command. @@ -358,6 +371,14 @@ The specific functions related to the interface are as follows (see also the [pr Execute the prepared statement. Currently, a statement can only be executed once. +- `int taos_stmt_affected_rows(TAOS_STMT *stmt)` + + Gets the number of rows affected by executing bind statements multiple times. + +- `int taos_stmt_affected_rows_once(TAOS_STMT *stmt)` + + Gets the number of rows affected by executing a bind statement once. + - `TAOS_RES* taos_stmt_use_result(TAOS_STMT *stmt)` Gets the result set of a statement. Use the result set in the same way as in the non-parametric call. When finished, `taos_free_result()` should be called on this result set to free resources. diff --git a/docs/en/14-reference/03-connector/09-csharp.mdx b/docs/en/14-reference/03-connector/09-csharp.mdx index 718462295a..203d44fe02 100644 --- a/docs/en/14-reference/03-connector/09-csharp.mdx +++ b/docs/en/14-reference/03-connector/09-csharp.mdx @@ -30,6 +30,10 @@ The source code of `TDengine.Connector` is hosted on [GitHub](https://github.com The supported platforms are the same as those supported by the TDengine client driver. +:::note +Please note TDengine does not support 32bit Windows any more. +::: + ## Version support Please refer to [version support list](/reference/connector#version-support) diff --git a/docs/en/14-reference/06-taosdump.md b/docs/en/14-reference/06-taosdump.md index 6d5547e7a9..baf07d6b9e 100644 --- a/docs/en/14-reference/06-taosdump.md +++ b/docs/en/14-reference/06-taosdump.md @@ -102,6 +102,8 @@ Usage: taosdump [OPTION...] dbname [tbname ...] -L, --loose-mode Use loose mode if the table name and column name use letter and number only. Default is NOT. -n, --no-escape No escape char '`'. Default is using it. + -Q, --dot-replace Repalce dot character with underline character in + the table name. -T, --thread-num=THREAD_NUM Number of thread for dump in file. Default is 8. -C, --cloud=CLOUD_DSN specify a DSN to access TDengine cloud service diff --git a/docs/en/20-third-party/01-grafana.mdx b/docs/en/20-third-party/01-grafana.mdx index 64acefe6b8..0ccdfe7254 100644 --- a/docs/en/20-third-party/01-grafana.mdx +++ b/docs/en/20-third-party/01-grafana.mdx @@ -74,7 +74,7 @@ grafana-cli plugins install tdengine-datasource sudo -u grafana grafana-cli plugins install tdengine-datasource ``` -You can also download zip files from [GitHub](https://github.com/taosdata/grafanaplugin/releases/tag/latest) or [Grafana](https://grafana.com/grafana/plugins/tdengine-datasource/?tab=installation) and install manually. The commands are as follows: +You can also download zip files from [GitHub](https://github.com/taosdata/grafanaplugin/releases/latest) or [Grafana](https://grafana.com/grafana/plugins/tdengine-datasource/?tab=installation) and install manually. The commands are as follows: ```bash GF_VERSION=3.3.1 diff --git a/docs/examples/c/multi_bind_example.c b/docs/examples/c/multi_bind_example.c index 02e6568e9e..3d0bd3ccef 100644 --- a/docs/examples/c/multi_bind_example.c +++ b/docs/examples/c/multi_bind_example.c @@ -51,7 +51,7 @@ void insertData(TAOS *taos) { int code = taos_stmt_prepare(stmt, sql, 0); checkErrorCode(stmt, code, "failed to execute taos_stmt_prepare"); // bind table name and tags - TAOS_BIND tags[2]; + TAOS_MULTI_BIND tags[2]; char *location = "California.SanFrancisco"; int groupId = 2; tags[0].buffer_type = TSDB_DATA_TYPE_BINARY; @@ -144,4 +144,4 @@ int main() { } // output: -// successfully inserted 2 rows \ No newline at end of file +// successfully inserted 2 rows diff --git a/docs/examples/c/stmt_example.c b/docs/examples/c/stmt_example.c index 28dae5f9d5..290a6bee66 100644 --- a/docs/examples/c/stmt_example.c +++ b/docs/examples/c/stmt_example.c @@ -58,7 +58,7 @@ void insertData(TAOS *taos) { int code = taos_stmt_prepare(stmt, sql, 0); checkErrorCode(stmt, code, "failed to execute taos_stmt_prepare"); // bind table name and tags - TAOS_BIND tags[2]; + TAOS_MULTI_BIND tags[2]; char* location = "California.SanFrancisco"; int groupId = 2; tags[0].buffer_type = TSDB_DATA_TYPE_BINARY; @@ -82,7 +82,7 @@ void insertData(TAOS *taos) { {1648432611749, 12.6, 218, 0.33}, }; - TAOS_BIND values[4]; + TAOS_MULTI_BIND values[4]; values[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; values[0].buffer_length = sizeof(int64_t); values[0].length = &values[0].buffer_length; @@ -138,4 +138,4 @@ int main() { // output: -// successfully inserted 2 rows \ No newline at end of file +// successfully inserted 2 rows diff --git a/docs/zh/02-intro.md b/docs/zh/02-intro.md index 888f779966..68a2541717 100644 --- a/docs/zh/02-intro.md +++ b/docs/zh/02-intro.md @@ -6,7 +6,14 @@ toc_max_heading_level: 2 TDengine 是一款开源、高性能、云原生的[时序数据库](https://tdengine.com/tsdb/),且针对物联网、车联网、工业互联网、金融、IT 运维等场景进行了优化。TDengine 的代码,包括集群功能,都在 GNU AGPL v3.0 下开源。除核心的时序数据库功能外,TDengine 还提供[缓存](../develop/cache/)、[数据订阅](../develop/tmq)、[流式计算](../develop/stream)等其它功能以降低系统复杂度及研发和运维成本。 -本章节介绍 TDengine 的主要功能、竞争优势、适用场景、与其他数据库的对比测试等等,让大家对 TDengine 有个整体的了解。 +本章节介绍 TDengine 的主要产品和功能、竞争优势、适用场景、与其他数据库的对比测试等等,让大家对 TDengine 有个整体的了解。 + +## 主要产品 + +TDengine 有三个主要产品:TDengine Pro (即 TDengine 企业版),TDengine Cloud,和 TDengine OSS,关于它们的具体定义请参考 +- [TDengine 企业版](https://www.taosdata.com/tdengine-pro) +- [TDengine 云服务](https://cloud.taosdata.com/?utm_source=menu&utm_medium=webcn) +- [TDengine 开源版](https://www.taosdata.com/tdengine-oss) ## 主要功能 diff --git a/docs/zh/08-connector/10-cpp.mdx b/docs/zh/08-connector/10-cpp.mdx index 12bbffa4f9..e5dc2ec8c8 100644 --- a/docs/zh/08-connector/10-cpp.mdx +++ b/docs/zh/08-connector/10-cpp.mdx @@ -256,6 +256,12 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) ::: +- `TAOS *taos_connect_auth(const char *host, const char *user, const char *auth, const char *db, uint16_t port)` + + 功能同 taos_connect。除 pass 参数替换为 auth 外,其他参数同 taos_connect。 + + - auth: 原始密码取 32 位小写 md5 + - `char *taos_get_server_info(TAOS *taos)` 获取服务端版本信息。 @@ -272,6 +278,14 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) - 如果,len 小于 存储db需要的空间(包含最后的'\0'),返回错误,database里赋值截断的数据,以'\0'结尾。 - 如果,len 大于等于 存储db需要的空间(包含最后的'\0'),返回正常0,database里赋值以'\0‘结尾的db名。 +- `int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type)` + + 设置事件回调函数。 + + - fp 事件回调函数指针。函数声明:typedef void (*__taos_notify_fn_t)(void *param, void *ext, int type);其中, param 为用户自定义参数,ext 为扩展参数(依赖事件类型,针对 TAOS_NOTIFY_PASSVER 返回用户密码版本),type 为事件类型 + - param 用户自定义参数 + - type 事件类型。取值范围:1)TAOS_NOTIFY_PASSVER: 用户密码改变 + - `void taos_close(TAOS *taos)` 关闭连接,其中`taos`是 `taos_connect()` 返回的句柄。 @@ -396,21 +410,20 @@ TDengine 的异步 API 均采用非阻塞调用模式。应用程序可以用多 解析一条 SQL 语句,将解析结果和参数信息绑定到 stmt 上,如果参数 length 大于 0,将使用此参数作为 SQL 语句的长度,如等于 0,将自动判断 SQL 语句的长度。 -- `int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind)` +- `int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind)` 不如 `taos_stmt_bind_param_batch()` 效率高,但可以支持非 INSERT 类型的 SQL 语句。 - 进行参数绑定,bind 指向一个数组(代表所要绑定的一行数据),需保证此数组中的元素数量和顺序与 SQL 语句中的参数完全一致。TAOS_BIND 的使用方法与 MySQL 中的 MYSQL_BIND 类似,具体定义如下: + 进行参数绑定,bind 指向一个数组(代表所要绑定的一行数据),需保证此数组中的元素数量和顺序与 SQL 语句中的参数完全一致。TAOS_MULTI_BIND 的使用方法与 MySQL 中的 MYSQL_BIND 类似,具体定义如下: ```c - typedef struct TAOS_BIND { + typedef struct TAOS_MULTI_BIND { int buffer_type; - void * buffer; - uintptr_t buffer_length; // not in use - uintptr_t * length; - int * is_null; - int is_unsigned; // not in use - int * error; // not in use - } TAOS_BIND; + void *buffer; + uintptr_t buffer_length; + uint32_t *length; + char *is_null; + int num; // the number of columns + } TAOS_MULTI_BIND; ``` - `int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name)` @@ -418,7 +431,7 @@ TDengine 的异步 API 均采用非阻塞调用模式。应用程序可以用多 (2.1.1.0 版本新增,仅支持用于替换 INSERT 语句中的参数值) 当 SQL 语句中的表名使用了 `?` 占位时,可以使用此函数绑定一个具体的表名。 -- `int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags)` +- `int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_MULTI_BIND* tags)` (2.1.2.0 版本新增,仅支持用于替换 INSERT 语句中的参数值) 当 SQL 语句中的表名和 TAGS 都使用了 `?` 占位时,可以使用此函数绑定具体的表名和具体的 TAGS 取值。最典型的使用场景是使用了自动建表功能的 INSERT 语句(目前版本不支持指定具体的 TAGS 列)。TAGS 参数中的列数量需要与 SQL 语句中要求的 TAGS 数量完全一致。 @@ -428,17 +441,6 @@ TDengine 的异步 API 均采用非阻塞调用模式。应用程序可以用多 (2.1.1.0 版本新增,仅支持用于替换 INSERT 语句中的参数值) 以多列的方式传递待绑定的数据,需要保证这里传递的数据列的顺序、列的数量与 SQL 语句中的 VALUES 参数完全一致。TAOS_MULTI_BIND 的具体定义如下: - ```c - typedef struct TAOS_MULTI_BIND { - int buffer_type; - void * buffer; - uintptr_t buffer_length; - uintptr_t * length; - char * is_null; - int num; // the number of columns - } TAOS_MULTI_BIND; - ``` - - `int taos_stmt_add_batch(TAOS_STMT *stmt)` 将当前绑定的参数加入批处理中,调用此函数后,可以再次调用 `taos_stmt_bind_param()` 或 `taos_stmt_bind_param_batch()` 绑定新的参数。需要注意,此函数仅支持 INSERT/IMPORT 语句,如果是 SELECT 等其他 SQL 语句,将返回错误。 @@ -447,6 +449,14 @@ TDengine 的异步 API 均采用非阻塞调用模式。应用程序可以用多 执行准备好的语句。目前,一条语句只能执行一次。 +- `int taos_stmt_affected_rows(TAOS_STMT *stmt)` + + 获取执行多次绑定语句影响的行数。 + +- `int taos_stmt_affected_rows_once(TAOS_STMT *stmt)` + + 获取执行一次绑定语句影响的行数。 + - `TAOS_RES* taos_stmt_use_result(TAOS_STMT *stmt)` 获取语句的结果集。结果集的使用方式与非参数化调用时一致,使用完成后,应对此结果集调用 `taos_free_result()` 以释放资源。 diff --git a/docs/zh/08-connector/40-csharp.mdx b/docs/zh/08-connector/40-csharp.mdx index 3a945e77fd..325c71da88 100644 --- a/docs/zh/08-connector/40-csharp.mdx +++ b/docs/zh/08-connector/40-csharp.mdx @@ -29,6 +29,10 @@ import CSAsyncQuery from "../07-develop/04-query-data/_cs_async.mdx" 支持的平台和 TDengine 客户端驱动支持的平台一致。 +:::note +注意 TDengine 不再支持 32 位 Windows 平台。 +::: + ## 版本支持 请参考[版本支持列表](../#版本支持) diff --git a/docs/zh/12-taos-sql/06-select.md b/docs/zh/12-taos-sql/06-select.md index 49a5cf8f19..222e166019 100755 --- a/docs/zh/12-taos-sql/06-select.md +++ b/docs/zh/12-taos-sql/06-select.md @@ -7,7 +7,7 @@ description: 查询数据的详细语法 ## 查询语法 ```sql -SELECT {DATABASE() | CLIENT_VERSION() | SERVER_VERSION() | SERVER_STATUS() | NOW() | TODAY() | TIMEZONE()} +SELECT {DATABASE() | CLIENT_VERSION() | SERVER_VERSION() | SERVER_STATUS() | NOW() | TODAY() | TIMEZONE() | CURRENT_USER() | USER() } SELECT [hints] [DISTINCT] [TAGS] select_list from_clause @@ -205,7 +205,7 @@ SELECT table_name, tag_name, tag_type, tag_value FROM information_schema.ins_tag SELECT COUNT(*) FROM (SELECT DISTINCT TBNAME FROM meters); ``` -以上两个查询均只支持在 WHERE 条件子句中添加针对标签(TAGS)的过滤条件。例如: +以上两个查询均只支持在 WHERE 条件子句中添加针对标签(TAGS)的过滤条件。 **\_QSTART/\_QEND** @@ -247,8 +247,7 @@ TDengine 支持基于时间戳主键的 INNER JOIN,规则如下: 3. 对于超级表,ON 条件在时间戳主键的等值条件之外,还要求有可以一一对应的标签列等值条件,不支持 OR 条件。 4. 参与 JOIN 计算的表只能是同一种类型,即只能都是超级表,或都是子表,或都是普通表。 5. JOIN 两侧均支持子查询。 -6. 参与 JOIN 的表个数上限为 10 个。 -7. 不支持与 FILL 子句混合使用。 +6. 不支持与 FILL 子句混合使用。 ## GROUP BY @@ -339,6 +338,12 @@ SELECT TODAY(); SELECT TIMEZONE(); ``` +### 获取当前用户 + +```sql +SELECT CURRENT_USER(); +``` + ## 正则表达式过滤 ### 语法 @@ -392,7 +397,7 @@ SELECT AVG(CASE WHEN voltage < 200 or voltage > 250 THEN 220 ELSE voltage END) F ## JOIN 子句 -TDengine 支持基于时间戳主键的内连接,即 JOIN 条件必须包含时间戳主键。只要满足基于时间戳主键这个要求,普通表、子表、超级表和子查询之间可以随意的进行内连接,且对表个数没有限制。 +TDengine 支持基于时间戳主键的内连接,即 JOIN 条件必须包含时间戳主键。只要满足基于时间戳主键这个要求,普通表、子表、超级表和子查询之间可以随意的进行内连接,且对表个数没有限制,其它连接条件与主键间必须是 AND 操作。 普通表与普通表之间的 JOIN 操作: diff --git a/docs/zh/12-taos-sql/10-function.md b/docs/zh/12-taos-sql/10-function.md index 3c0ee06caf..f7e2a64ea7 100644 --- a/docs/zh/12-taos-sql/10-function.md +++ b/docs/zh/12-taos-sql/10-function.md @@ -1266,6 +1266,14 @@ SELECT SERVER_STATUS(); **说明**:检测服务端是否所有 dnode 都在线,如果是则返回成功,否则返回无法建立连接的错误。 +### CURRENT_USER + +```sql +SELECT CURRENT_USER(); +``` + +**说明**:获取当前用户。 + ## Geometry 函数 diff --git a/docs/zh/12-taos-sql/12-distinguished.md b/docs/zh/12-taos-sql/12-distinguished.md old mode 100644 new mode 100755 index f750124049..62888cc5f7 --- a/docs/zh/12-taos-sql/12-distinguished.md +++ b/docs/zh/12-taos-sql/12-distinguished.md @@ -31,7 +31,7 @@ select max(current) from meters partition by location interval(10m) ## 窗口切分查询 -TDengine 支持按时间窗口切分方式进行聚合结果查询,比如温度传感器每秒采集一次数据,但需查询每隔 10 分钟的温度平均值。这种场景下可以使用窗口子句来获得需要的查询结果。窗口子句用于针对查询的数据集合按照窗口切分成为查询子集并进行聚合,窗口包含时间窗口(time window)、状态窗口(status window)、会话窗口(session window)、条件窗口(event window)四种窗口。其中时间窗口又可划分为滑动时间窗口和翻转时间窗口。 +TDengine 支持按时间窗口切分方式进行聚合结果查询,比如温度传感器每秒采集一次数据,但需查询每隔 10 分钟的温度平均值。这种场景下可以使用窗口子句来获得需要的查询结果。窗口子句用于针对查询的数据集合按照窗口切分成为查询子集并进行聚合,窗口包含时间窗口(time window)、状态窗口(status window)、会话窗口(session window)、事件窗口(event window)四种窗口。其中时间窗口又可划分为滑动时间窗口和翻转时间窗口。 窗口子句语法如下: diff --git a/docs/zh/12-taos-sql/20-keywords.md b/docs/zh/12-taos-sql/20-keywords.md index f52af2f282..e7e926d0b7 100644 --- a/docs/zh/12-taos-sql/20-keywords.md +++ b/docs/zh/12-taos-sql/20-keywords.md @@ -178,7 +178,7 @@ description: TDengine 保留关键字的详细列表 - MATCH - MAX_DELAY -- MAX_SPEED +- BWLIMIT - MAXROWS - MERGE - META diff --git a/docs/zh/12-taos-sql/24-show.md b/docs/zh/12-taos-sql/24-show.md index 6e102e2356..b7ca9493d4 100644 --- a/docs/zh/12-taos-sql/24-show.md +++ b/docs/zh/12-taos-sql/24-show.md @@ -22,6 +22,14 @@ SHOW CLUSTER; 显示当前集群的信息 +## SHOW CLUSTER ALIVE + +```sql +SHOW CLUSTER ALIVE; +``` + +查询当前集群的状态是否可用,返回值: 0:不可用 1:完全可用 2:部分可用(集群中部分节点下线,但其它节点仍可以正常使用) + ## SHOW CONNECTIONS ```sql diff --git a/docs/zh/12-taos-sql/25-grant.md b/docs/zh/12-taos-sql/25-grant.md deleted file mode 100644 index d53f951e67..0000000000 --- a/docs/zh/12-taos-sql/25-grant.md +++ /dev/null @@ -1,138 +0,0 @@ ---- -sidebar_label: 权限管理 -title: 权限管理 -description: 企业版中才具有的权限管理功能 ---- - -本节讲述如何在 TDengine 中进行权限管理的相关操作。权限管理是 TDengine 企业版的特有功能,本节只列举了一些基本的权限管理功能作为示例,更丰富的权限管理请联系 TDengine 销售或市场团队。 - -## 创建用户 - -```sql -CREATE USER use_name PASS 'password' [SYSINFO {1|0}]; -``` - -创建用户。 - -use_name 最长为 23 字节。 - -password 最长为 31 字节,合法字符包括"a-zA-Z0-9!?$%^&*()_–+={[}]:;@~#|<,>.?/",不可以出现单双引号、撇号、反斜杠和空格,且不可以为空。 - -SYSINFO 表示用户是否可以查看系统信息。1 表示可以查看,0 表示不可以查看。系统信息包括服务端配置信息、服务端各种节点信息(如 DNODE、QNODE等)、存储相关的信息等。默认为可以查看系统信息。 - -例如,创建密码为123456且可以查看系统信息的用户test如下: - -```sql -taos> create user test pass '123456' sysinfo 1; -Query OK, 0 of 0 rows affected (0.001254s) -``` - -## 查看用户 - -```sql -SHOW USERS; -``` - -查看用户信息。 - -```sql -taos> show users; - name | super | enable | sysinfo | create_time | -================================================================================ - test | 0 | 1 | 1 | 2022-08-29 15:10:27.315 | - root | 1 | 1 | 1 | 2022-08-29 15:03:34.710 | -Query OK, 2 rows in database (0.001657s) -``` - -也可以通过查询INFORMATION_SCHEMA.INS_USERS系统表来查看用户信息,例如: - -```sql -taos> select * from information_schema.ins_users; - name | super | enable | sysinfo | create_time | -================================================================================ - test | 0 | 1 | 1 | 2022-08-29 15:10:27.315 | - root | 1 | 1 | 1 | 2022-08-29 15:03:34.710 | -Query OK, 2 rows in database (0.001953s) -``` - -## 删除用户 - -```sql -DROP USER user_name; -``` - -## 修改用户信息 - -```sql -ALTER USER user_name alter_user_clause - -alter_user_clause: { - PASS 'literal' - | ENABLE value - | SYSINFO value -} -``` - -- PASS:修改用户密码。 -- ENABLE:修改用户是否启用。1 表示启用此用户,0 表示禁用此用户。 -- SYSINFO:修改用户是否可查看系统信息。1 表示可以查看系统信息,0 表示不可以查看系统信息。 - -例如,禁用 test 用户: - -```sql -taos> alter user test enable 0; -Query OK, 0 of 0 rows affected (0.001160s) -``` - -## 授权 - -```sql -GRANT privileges ON priv_level TO user_name - -privileges : { - ALL - | priv_type [, priv_type] ... -} - -priv_type : { - READ - | WRITE -} - -priv_level : { - dbname.* - | *.* -} -``` - -对用户授权。授权功能只包含在企业版中。 - -授权级别支持到DATABASE,权限有READ和WRITE两种。 - -TDengine 有超级用户和普通用户两类用户。超级用户缺省创建为root,拥有所有权限。使用超级用户创建出来的用户为普通用户。在未授权的情况下,普通用户可以创建DATABASE,并拥有自己创建的DATABASE的所有权限,包括删除数据库、修改数据库、查询时序数据和写入时序数据。超级用户可以给普通用户授予其他DATABASE的读写权限,使其可以在此DATABASE上读写数据,但不能对其进行删除和修改数据库的操作。 - -对于非DATABASE的对象,如USER、DNODE、UDF、QNODE等,普通用户只有读权限(一般为SHOW命令),不能创建和修改。 - -## 撤销授权 - -```sql -REVOKE privileges ON priv_level FROM user_name - -privileges : { - ALL - | priv_type [, priv_type] ... -} - -priv_type : { - READ - | WRITE -} - -priv_level : { - dbname.* - | *.* -} - -``` - -收回对用户的授权。授权功能只包含在企业版中。 diff --git a/docs/zh/12-taos-sql/27-index.md b/docs/zh/12-taos-sql/27-indexing.md similarity index 98% rename from docs/zh/12-taos-sql/27-index.md rename to docs/zh/12-taos-sql/27-indexing.md index da8f38eb22..cf8cac1bed 100644 --- a/docs/zh/12-taos-sql/27-index.md +++ b/docs/zh/12-taos-sql/27-indexing.md @@ -20,6 +20,9 @@ index_option: functions: function [, function] ... ``` +### tag 索引 + + [tag 索引](../tag-index) ### SMA 索引 diff --git a/docs/zh/12-taos-sql/28-recovery.md b/docs/zh/12-taos-sql/28-recovery.md index b5088e7982..8e327afe0b 100644 --- a/docs/zh/12-taos-sql/28-recovery.md +++ b/docs/zh/12-taos-sql/28-recovery.md @@ -17,7 +17,7 @@ conn_id 可以通过 `SHOW CONNECTIONS` 获取。 ## 终止查询 ```sql -KILL QUERY kill_id; +KILL QUERY 'kill_id'; ``` kill_id 可以通过 `SHOW QUERIES` 获取。 diff --git a/docs/zh/14-reference/05-taosbenchmark.md b/docs/zh/14-reference/05-taosbenchmark.md index e4c3efba17..d5ae95b20b 100644 --- a/docs/zh/14-reference/05-taosbenchmark.md +++ b/docs/zh/14-reference/05-taosbenchmark.md @@ -13,7 +13,7 @@ taosBenchmark (曾用名 taosdemo ) 是一个用于测试 TDengine 产品性能 taosBenchmark 有两种安装方式: -- 安装 TDengine 官方安装包的同时会自动安装 taosBenchmark, 详情请参考[ TDengine 安装](/operation/pkg-install)。 +- 安装 TDengine 官方安装包的同时会自动安装 taosBenchmark, 详情请参考[ TDengine 安装](../../operation/pkg-install)。 - 单独编译 taos-tools 并安装, 详情请参考 [taos-tools](https://github.com/taosdata/taos-tools) 仓库。 diff --git a/docs/zh/14-reference/06-taosdump.md b/docs/zh/14-reference/06-taosdump.md index 12122edd32..9fe3c5af7a 100644 --- a/docs/zh/14-reference/06-taosdump.md +++ b/docs/zh/14-reference/06-taosdump.md @@ -105,6 +105,8 @@ Usage: taosdump [OPTION...] dbname [tbname ...] -L, --loose-mode Using loose mode if the table name and column name use letter and number only. Default is NOT. -n, --no-escape No escape char '`'. Default is using it. + -Q, --dot-replace Repalce dot character with underline character in + the table name. -T, --thread-num=THREAD_NUM Number of thread for dump in file. Default is 8. -C, --cloud=CLOUD_DSN specify a DSN to access TDengine cloud service diff --git a/docs/zh/14-reference/14-taosKeeper.md b/docs/zh/14-reference/14-taosKeeper.md index b4d35fb240..738d351d45 100644 --- a/docs/zh/14-reference/14-taosKeeper.md +++ b/docs/zh/14-reference/14-taosKeeper.md @@ -16,7 +16,7 @@ taosKeeper 是 TDengine 3.0 版本监控指标的导出工具,通过简单的 taosKeeper 有两种安装方式: taosKeeper 安装方式: -- 安装 TDengine 官方安装包的同时会自动安装 taosKeeper, 详情请参考[ TDengine 安装](/operation/pkg-install)。 +- 安装 TDengine 官方安装包的同时会自动安装 taosKeeper, 详情请参考[ TDengine 安装](../../operation/pkg-install)。 - 单独编译 taosKeeper 并安装,详情请参考 [taosKeeper](https://github.com/taosdata/taoskeeper) 仓库。 diff --git a/docs/zh/17-operation/07-import.md b/docs/zh/17-operation/04-import.md similarity index 100% rename from docs/zh/17-operation/07-import.md rename to docs/zh/17-operation/04-import.md diff --git a/docs/zh/17-operation/08-export.md b/docs/zh/17-operation/05-export.md similarity index 100% rename from docs/zh/17-operation/08-export.md rename to docs/zh/17-operation/05-export.md diff --git a/docs/zh/17-operation/10-monitor.md b/docs/zh/17-operation/06-monitor.md similarity index 100% rename from docs/zh/17-operation/10-monitor.md rename to docs/zh/17-operation/06-monitor.md diff --git a/docs/zh/17-operation/07-cluster.md b/docs/zh/17-operation/07-cluster.md new file mode 100644 index 0000000000..cf4bfafd53 --- /dev/null +++ b/docs/zh/17-operation/07-cluster.md @@ -0,0 +1,80 @@ +--- +title: 集群运维 +description: TDengine 提供了多种集群运维手段以使集群运行更健康更高效 +--- + +为了使集群运行更健康更高效,TDengine 企业版提供了一些运维手段来帮助系统管理员更好地运维集群。 + +## 数据重整 + +TDengine 面向多种写入场景,在有些写入场景下,TDengine 的存储会导致数据存储的放大或数据文件的空洞等。这一方面影响数据的存储效率,另一方面也会影响查询效率。为了解决上述问题,TDengine 企业版提供了对数据的重整功能,即 DATA COMPACT 功能,将存储的数据文件重新整理,删除文件空洞和无效数据,提高数据的组织度,从而提高存储和查询的效率。 + +**语法** + +```sql +COMPACT DATABASE db_name [start with 'XXXX'] [end with 'YYYY']; +``` + +**效果** + +- 扫描并压缩指定的 DB 中所有 VGROUP 中 VNODE 的所有数据文件 +- COMPCAT 会删除被删除数据以及被删除的表的数据 +- COMPACT 会合并多个 STT 文件 +- 可通过 start with 关键字指定 COMPACT 数据的起始时间 +- 可通过 end with 关键字指定 COMPACT 数据的终止时间 + +**补充说明** + +- COMPACT 为异步,执行 COMPACT 命令后不会等 COMPACT 结束就会返回。如果上一个 COMPACT 没有完成则再发起一个 COMPACT 任务,则会等上一个任务完成后再返回。 +- COMPACT 可能阻塞写入,但不阻塞查询 +- COMPACT 的进度不可观测 + +## 集群负载再平衡 + +当多副本集群中的一个或多个节点因为升级或其它原因而重启后,有可能出现集群中各个 dnode 负载不均衡的现象,极端情况下会出现所有 vgroup 的 leader 都位于同一个 dnode 的情况。为了解决这个问题,可以使用下面的命令 + +```sql +balance vgroup leader; +``` + +**功能** + +让所有的 vgroup 的 leade r在各自的replica节点上均匀分布。这个命令会让 vgroup 强制重新选举,通过重新选举,在选举的过程中,变换 vgroup 的leader,通过这个方式,最终让leader均匀分布。 + +**注意** + +Raft选举本身带有随机性,所以通过选举的重新分布产生的均匀分布也是带有一定的概率,不会完全的均匀。**该命令的副作用是影响查询和写入**,在vgroup重新选举时,从开始选举到选举出新的 leader 这段时间,这 个vgroup 无法写入和查询。选举过程一般在秒级完成。所有的vgroup会依次逐个重新选举。 + +## 恢复数据节点 + +在多节点三副本的集群环境中,如果某个 dnode 的磁盘损坏,该 dnode 会自动退出,但集群中其它的 dnode 仍然能够继续提供写入和查询服务。 + +在更换了损坏的磁盘后,如果想要让曾经主动退出的 dnode 重新加入集群提供服务,可以通过 `restore dnode` 命令来恢复该数据节点上的部分或全部逻辑节点,该功能依赖多副本中的其它副本进行数据复制,所以只在集群中 dnode 数量大于等于 3 且副本数为 3 的情况下能够工作。 + + +```sql +restore dnode ;# 恢复dnode上的mnode,所有vnode和qnode +restore mnode on dnode ;# 恢复dnode上的mnode +restore vnode on dnode ;# 恢复dnode上的所有vnode +restore qnode on dnode ;# 恢复dnode上的qnode +``` + +**限制** +- 该功能是基于已有的复制功能的恢复,不是灾难恢复或者备份恢复,所以对于要恢复的 mnode 和 vnode来说,使用该命令的前提是还存在该 mnode 或 vnode 的其它两个副本仍然能够正常工作。 +- 该命令不能修复数据目录中的个别文件的损坏或者丢失。例如,如果某个 mnode 或者 vnode 中的个别文件或数据损坏,无法单独恢复损坏的某个文件或者某块数据。此时,可以选择将该 mnode/vnode 的数据全部清空再进行恢复。 + + +## 虚拟组分裂 (Scale Out) + +当一个 vgroup 因为子表数过多而导致 CPU 或 Disk 资源使用量负载过高时,增加 dnode 节点后,可通过 `split vgroup` 命令把该 vgroup 分裂为两个虚拟组。分裂完成后,新产生的两个 vgroup 承担原来由一个 vgroup 提供的读写服务。这也是 TDengine 为企业版用户提供的 scale out 集群的能力。 + +```sql +split vgroup +``` + +**注意** +- 单副本库虚拟组,在分裂完成后,历史时序数据总磁盘空间使用量,可能会翻倍。所以,在执行该操作之前,通过增加 dnode 节点方式,确保集群中有足够的 CPU 和磁盘资源,避免资源不足现象发生。 +- 该命令为 DB 级事务;执行过程,当前DB的其它管理事务将会被拒绝。集群中,其它DB不受影响。 +- 分裂任务执行过程中,可持续提供读写服务;期间,可能存在可感知的短暂的读写业务中断。 +- 在分裂过程中,不支持流和订阅。分裂结束后,历史 WAL 会清空。 +- 分裂过程中,可支持节点宕机重启容错;但不支持节点磁盘故障容错。 \ No newline at end of file diff --git a/docs/zh/17-operation/09-storage.md b/docs/zh/17-operation/09-storage.md new file mode 100644 index 0000000000..185b2c40ec --- /dev/null +++ b/docs/zh/17-operation/09-storage.md @@ -0,0 +1,56 @@ +--- +title: 多级存储 +--- + +## 多级存储 + +说明:多级存储功能仅企业版支持。 + +在默认配置下,TDengine 会将所有数据保存在 /var/lib/taos 目录下,而且每个 vnode 的数据文件保存在该目录下的不同目录。为扩大存储空间,尽量减少文件读取的瓶颈,提高数据吞吐率 TDengine 可通过配置系统参数 dataDir 让多个挂载的硬盘被系统同时使用。 + +除此之外,TDengine 也提供了数据分级存储的功能,将不同时间段的数据存储在挂载的不同介质上的目录里,从而实现不同“热度”的数据存储在不同的存储介质上,充分利用存储,节约成本。比如,最新采集的数据需要经常访问,对硬盘的读取性能要求高,那么用户可以配置将这些数据存储在 SSD 盘上。超过一定期限的数据,查询需求量没有那么高,那么可以存储在相对便宜的 HDD 盘上。 + +多级存储支持 3 级,每级最多可配置 16 个挂载点。 + +TDengine 多级存储配置方式如下(在配置文件/etc/taos/taos.cfg 中): + +``` +dataDir [path] +``` + +- path: 挂载点的文件夹路径 +- level: 介质存储等级,取值为 0,1,2。 + 0 级存储最新的数据,1 级存储次新的数据,2 级存储最老的数据,省略默认为 0。 + 各级存储之间的数据流向:0 级存储 -> 1 级存储 -> 2 级存储。 + 同一存储等级可挂载多个硬盘,同一存储等级上的数据文件分布在该存储等级的所有硬盘上。 + 需要说明的是,数据在不同级别的存储介质上的移动,是由系统自动完成的,用户无需干预。 +- primary: 是否为主挂载点,0(否)或 1(是),省略默认为 1。 + +在配置中,只允许一个主挂载点的存在(level=0,primary=1),例如采用如下的配置方式: + +``` +dataDir /mnt/data1 0 1 +dataDir /mnt/data2 0 0 +dataDir /mnt/data3 1 0 +dataDir /mnt/data4 1 0 +dataDir /mnt/data5 2 0 +dataDir /mnt/data6 2 0 +``` + +:::note + +1. 多级存储不允许跨级配置,合法的配置方案有:仅 0 级,仅 0 级+ 1 级,以及 0 级+ 1 级+ 2 级。而不允许只配置 level=0 和 level=2,而不配置 level=1。 +2. 禁止手动移除使用中的挂载盘,挂载盘目前不支持非本地的网络盘。 +3. 多级存储目前不支持删除已经挂载的硬盘的功能。 + +::: + +## 0 级负载均衡 + +在多级存储中,有且只有一个主挂载点,主挂载点承担了系统中最重要的元数据在座,同时各个 vnode 的主目录均存在于当前 dnode 主挂载点上,从而导致该 dnode 的写入性能受限于单个磁盘的 IO 吞吐能力。 + +从 TDengine 3.1.0.0 开始,如果一个 dnode 配置了多个 0 级挂载点,我们将该 dnode 上所有 vnode 的主目录均衡分布在所有的 0 级挂载点上,由这些 0 级挂载点共同承担写入负荷。在网络 I/O 及其它处理资源不成为瓶颈的情况下,通过优化集群配置,测试结果证明整个系统的写入能力和 0 级挂载点的数量呈现线性关系,即随着 0 级挂载点数量的增加,整个系统的写入能力也成倍增加。 + +## 同级挂载点选择策略 + +一般情况下,当 TDengine 要从同级挂载点中选择一个用于生成新的数据文件时,采用 round robin 策略进行选择。但现实中有可能每个磁盘的容量不相同,或者容量相同但写入的数据量不相同,这就导致会出现每个磁盘上的可用空间不均衡,在实际进行选择时有可能会选择到一个剩余空间已经很小的磁盘。为了解决这个问题,从 3.1.1.0 开始引入了一个新的配置 `minDiskFreeSize`,当某块磁盘上的可用空间小于等于这个阈值时,该磁盘将不再被选择用于生成新的数据文件。该配置项的单位为字节,其值应该大于 2GB,即会跳过可用空间小于 2GB 的挂载点。 diff --git a/docs/zh/20-third-party/11-kafka.md b/docs/zh/20-third-party/11-kafka.md index dc4f25cbe8..2f09e50f0b 100644 --- a/docs/zh/20-third-party/11-kafka.md +++ b/docs/zh/20-third-party/11-kafka.md @@ -23,7 +23,7 @@ TDengine Source Connector 用于把数据实时地从 TDengine 读出来发送 1. Linux 操作系统 2. 已安装 Java 8 和 Maven 3. 已安装 Git、curl、vi -4. 已安装并启动 TDengine。如果还没有可参考[安装和卸载](/operation/pkg-install) +4. 已安装并启动 TDengine。如果还没有可参考[安装和卸载](../../operation/pkg-install) ## 安装 Kafka diff --git a/docs/zh/20-third-party/70-seeq.md b/docs/zh/20-third-party/70-seeq.md new file mode 100644 index 0000000000..0bdf58955d --- /dev/null +++ b/docs/zh/20-third-party/70-seeq.md @@ -0,0 +1,437 @@ +--- +sidebar_label: Seeq +title: Seeq +description: 如何使用 Seeq 和 TDengine 进行时序数据分析 +--- + +# 如何使用 Seeq 和 TDengine 进行时序数据分析 + +## 方案介绍 + +Seeq 是制造业和工业互联网(IIOT)高级分析软件。Seeq 支持在工艺制造组织中使用机器学习创新的新功能。这些功能使组织能够将自己或第三方机器学习算法部署到前线流程工程师和主题专家使用的高级分析应用程序,从而使单个数据科学家的努力扩展到许多前线员工。 + +通过 TDengine Java connector, Seeq 可以轻松支持查询 TDengine 提供的时序数据,并提供数据展现、分析、预测等功能。 + +### Seeq 安装方法 + +从 (Seeq 官网)[https://www.seeq.com/customer-download]下载相关软件,例如 Seeq Server 和 Seeq Data Lab 等。 + +### Seeq Server 安装和启动 + +``` +tar xvzf seeq-server-xxx.tar.gz +cd seeq-server-installer +sudo ./install + +sudo seeq service enable +sudo seeq start +``` + +### Seeq Data Lab Server 安装和启动 + +Seeq Data Lab 需要安装在和 Seeq Server 不同的服务器上,并通过配置和 Seeq Server 互联。详细安装配置指令参见(Seeq 官方文档)[https://support.seeq.com/space/KB/1034059842]。 + +``` +tar xvf seeq-data-lab--64bit-linux.tar.gz +sudo seeq-data-lab-installer/install -f /opt/seeq/seeq-data-lab -g /var/opt/seeq -u seeq +sudo seeq config set Network/DataLab/Hostname localhost +sudo seeq config set Network/DataLab/Port 34231 # the port of the Data Lab server (usually 34231) +sudo seeq config set Network/Hostname # the host IP or URL of the main Seeq Server + +# If the main Seeq server is configured to listen over HTTPS +sudo seeq config set Network/Webserver/SecurePort 443 # the secure port of the main Seeq Server (usually 443) + +# If the main Seeq server is NOT configured to listen over HTTPS +sudo seeq config set Network/Webserver/Port + +#On the main Seeq server, open a Seeq Command Prompt and set the hostname of the Data Lab server: +sudo seeq config set Network/DataLab/Hostname # the host IP (not URL) of the Data Lab server +sudo seeq config set Network/DataLab/Port 34231 # the port of the Data Lab server (usually 34231 +``` + +## TDengine 本地实例安装方法 + +请参考(官网文档)[https://docs.taosdata.com/get-started/package/]。 + +## TDengine Cloud 访问方法 +如果使用 Seeq 连接 TDengine Cloud,请在 https://cloud.taosdata.com 申请帐号并登录查看如何访问 TDengine Cloud。 + +## 如何配置 Seeq 访问 TDengine + +1. 查看 data 存储位置 + +``` +sudo seeq config get Folders/Data +``` + +2. 从 maven.org 下载 TDengine Java connector 包,目前最新版本为(3.2.4)[https://repo1.maven.org/maven2/com/taosdata/jdbc/taos-jdbcdriver/3.2.4/taos-jdbcdriver-3.2.4-dist.jar],并拷贝至 data 存储位置的 plugins\lib 中。 + +3. 重新启动 seeq server + +``` +sudo seeq restart +``` + +4. 输入 License + +使用浏览器访问 ip:34216 并按照说明输入 license。 + +## 使用 Seeq 分析 TDengine 时序数据 + +本章节演示如何使用 Seeq 软件配合 TDengine 进行时序数据分析。 + +### 场景介绍 + +示例场景为一个电力系统,用户每天从电站仪表收集用电量数据,并将其存储在 TDengine 集群中。现在用户想要预测电力消耗将会如何发展,并购买更多设备来支持它。用户电力消耗随着每月订单变化而不同,另外考虑到季节变化,电力消耗量会有所不同。这个城市位于北半球,所以在夏天会使用更多的电力。我们模拟数据来反映这些假定。 + +### 数据 Schema + +``` +CREATE STABLE meters (ts TIMESTAMP, num INT, temperature FLOAT, goods INT) TAGS (device NCHAR(20)); +CREATE TABLE goods (ts1 TIMESTAMP, ts2 TIMESTAMP, goods FLOAT); +``` + +!(Seeq demo schema)[./seeq/seeq-demo-schema.webp] + +### 构造数据方法 + +``` +python mockdata.py +taos -s "insert into power.goods select _wstart, _wstart + 10d, avg(goods) from power.meters interval(10d);" +``` +源代码托管在(github 仓库)[https://github.com/sangshuduo/td-forecasting]。 + +### 使用 Seeq 进行数据分析 + +#### 配置数据源(Data Source) + +使用 Seeq 管理员角色的帐号登录,并新建数据源。 + +- Power + +``` +{ + "QueryDefinitions": [ + { + "Name": "PowerNum", + "Type": "SIGNAL", + "Sql": "SELECT ts, num FROM meters", + "Enabled": true, + "TestMode": false, + "TestQueriesDuringSync": true, + "InProgressCapsulesEnabled": false, + "Variables": null, + "Properties": [ + { + "Name": "Name", + "Value": "Num", + "Sql": null, + "Uom": "string" + }, + { + "Name": "Interpolation Method", + "Value": "linear", + "Sql": null, + "Uom": "string" + }, + { + "Name": "Maximum Interpolation", + "Value": "2day", + "Sql": null, + "Uom": "string" + } + ], + "CapsuleProperties": null + } + ], + "Type": "GENERIC", + "Hostname": null, + "Port": 0, + "DatabaseName": null, + "Username": "root", + "Password": "taosdata", + "InitialSql": null, + "TimeZone": null, + "PrintRows": false, + "UseWindowsAuth": false, + "SqlFetchBatchSize": 100000, + "UseSSL": false, + "JdbcProperties": null, + "GenericDatabaseConfig": { + "DatabaseJdbcUrl": "jdbc:TAOS-RS://127.0.0.1:6041/power?user=root&password=taosdata", + "SqlDriverClassName": "com.taosdata.jdbc.rs.RestfulDriver", + "ResolutionInNanoseconds": 1000, + "ZonedColumnTypes": [] + } +} +``` + +- Goods + +``` +{ + "QueryDefinitions": [ + { + "Name": "PowerGoods", + "Type": "CONDITION", + "Sql": "SELECT ts1, ts2, goods FROM power.goods", + "Enabled": true, + "TestMode": false, + "TestQueriesDuringSync": true, + "InProgressCapsulesEnabled": false, + "Variables": null, + "Properties": [ + { + "Name": "Name", + "Value": "Goods", + "Sql": null, + "Uom": "string" + }, + { + "Name": "Maximum Duration", + "Value": "10days", + "Sql": null, + "Uom": "string" + } + ], + "CapsuleProperties": [ + { + "Name": "goods", + "Value": "${columnResult}", + "Column": "goods", + "Uom": "string" + } + ] + } + ], + "Type": "GENERIC", + "Hostname": null, + "Port": 0, + "DatabaseName": null, + "Username": "root", + "Password": "taosdata", + "InitialSql": null, + "TimeZone": null, + "PrintRows": false, + "UseWindowsAuth": false, + "SqlFetchBatchSize": 100000, + "UseSSL": false, + "JdbcProperties": null, + "GenericDatabaseConfig": { + "DatabaseJdbcUrl": "jdbc:TAOS-RS://127.0.0.1:6041/power?user=root&password=taosdata", + "SqlDriverClassName": "com.taosdata.jdbc.rs.RestfulDriver", + "ResolutionInNanoseconds": 1000, + "ZonedColumnTypes": [] + } +} +``` + +- Temperature + +``` +{ + "QueryDefinitions": [ + { + "Name": "PowerNum", + "Type": "SIGNAL", + "Sql": "SELECT ts, temperature FROM meters", + "Enabled": true, + "TestMode": false, + "TestQueriesDuringSync": true, + "InProgressCapsulesEnabled": false, + "Variables": null, + "Properties": [ + { + "Name": "Name", + "Value": "Temperature", + "Sql": null, + "Uom": "string" + }, + { + "Name": "Interpolation Method", + "Value": "linear", + "Sql": null, + "Uom": "string" + }, + { + "Name": "Maximum Interpolation", + "Value": "2day", + "Sql": null, + "Uom": "string" + } + ], + "CapsuleProperties": null + } + ], + "Type": "GENERIC", + "Hostname": null, + "Port": 0, + "DatabaseName": null, + "Username": "root", + "Password": "taosdata", + "InitialSql": null, + "TimeZone": null, + "PrintRows": false, + "UseWindowsAuth": false, + "SqlFetchBatchSize": 100000, + "UseSSL": false, + "JdbcProperties": null, + "GenericDatabaseConfig": { + "DatabaseJdbcUrl": "jdbc:TAOS-RS://127.0.0.1:6041/power?user=root&password=taosdata", + "SqlDriverClassName": "com.taosdata.jdbc.rs.RestfulDriver", + "ResolutionInNanoseconds": 1000, + "ZonedColumnTypes": [] + } +} +``` + +#### 使用 Seeq Workbench + +登录 Seeq 服务页面并新建 Seeq Workbench,通过选择数据源搜索结果和根据需要选择不同的工具,可以进行数据展现或预测,详细使用方法参见(官方知识库)[https://support.seeq.com/space/KB/146440193/Seeq+Workbench]。 + +!(Seeq Workbench)[./seeq/seeq-demo-workbench.webp] + +#### 用 Seeq Data Lab Server 进行进一步的数据分析 + +登录 Seeq 服务页面并新建 Seeq Data Lab,可以进一步使用 Python 编程或其他机器学习工具进行更复杂的数据挖掘功能。 + +```Python +from seeq import spy +spy.options.compatibility = 189 +import pandas as pd +import matplotlib +import matplotlib.pyplot as plt +import mlforecast +import lightgbm as lgb +from mlforecast.target_transforms import Differences +from sklearn.linear_model import LinearRegression + +ds = spy.search({'ID': "8C91A9C7-B6C2-4E18-AAAF-XXXXXXXXX"}) +print(ds) + +sig = ds.loc[ds['Name'].isin(['Num'])] +print(sig) + +data = spy.pull(sig, start='2015-01-01', end='2022-12-31', grid=None) +print("data.info()") +data.info() +print(data) +#data.plot() + +print("data[Num].info()") +data['Num'].info() +da = data['Num'].index.tolist() +#print(da) + +li = data['Num'].tolist() +#print(li) + +data2 = pd.DataFrame() +data2['ds'] = da +print('1st data2 ds info()') +data2['ds'].info() + +#data2['ds'] = pd.to_datetime(data2['ds']).to_timestamp() +data2['ds'] = pd.to_datetime(data2['ds']).astype('int64') +data2['y'] = li +print('2nd data2 ds info()') +data2['ds'].info() +print(data2) + +data2.insert(0, column = "unique_id", value="unique_id") + +print("Forecasting ...") + +forecast = mlforecast.MLForecast( + models = lgb.LGBMRegressor(), + freq = 1, + lags=[365], + target_transforms=[Differences([365])], +) + +forecast.fit(data2) +predicts = forecast.predict(365) + +pd.concat([data2, predicts]).set_index("ds").plot(title = "current data with forecast") +plt.show() +``` + +运行程序输出结果: + +!(Seeq forecast result)[./seeq/seeq-forecast-result.webp] + +### 配置 Seeq 数据源连接 TDengine Cloud + +配置 Seeq 数据源连接 TDengine Cloud 和连接 TDengine 本地安装实例没有本质的不同,只要登录 TDengine Cloud 后选择“编程 - Java”并拷贝带 token 字符串的 JDBC 填写为 Seeq Data Source 的 DatabaseJdbcUrl 值。 +注意使用 TDengine Cloud 时 SQL 命令中需要指定数据库名称。 + +#### 用 TDengine Cloud 作为数据源的配置内容示例: + +``` +{ + "QueryDefinitions": [ + { + "Name": "CloudVoltage", + "Type": "SIGNAL", + "Sql": "SELECT ts, voltage FROM test.meters", + "Enabled": true, + "TestMode": false, + "TestQueriesDuringSync": true, + "InProgressCapsulesEnabled": false, + "Variables": null, + "Properties": [ + { + "Name": "Name", + "Value": "Voltage", + "Sql": null, + "Uom": "string" + }, + { + "Name": "Interpolation Method", + "Value": "linear", + "Sql": null, + "Uom": "string" + }, + { + "Name": "Maximum Interpolation", + "Value": "2day", + "Sql": null, + "Uom": "string" + } + ], + "CapsuleProperties": null + } + ], + "Type": "GENERIC", + "Hostname": null, + "Port": 0, + "DatabaseName": null, + "Username": "root", + "Password": "taosdata", + "InitialSql": null, + "TimeZone": null, + "PrintRows": false, + "UseWindowsAuth": false, + "SqlFetchBatchSize": 100000, + "UseSSL": false, + "JdbcProperties": null, + "GenericDatabaseConfig": { + "DatabaseJdbcUrl": "jdbc:TAOS-RS://gw.cloud.taosdata.com?useSSL=true&token=41ac9d61d641b6b334e8b76f45f5a8XXXXXXXXXX", + "SqlDriverClassName": "com.taosdata.jdbc.rs.RestfulDriver", + "ResolutionInNanoseconds": 1000, + "ZonedColumnTypes": [] + } +} +``` + +#### TDengine Cloud 作为数据源的 Seeq Workbench 界面示例 + +!(Seeq workbench with TDengine cloud)[./seeq/seeq-workbench-with-tdengine-cloud.webp] + +## 方案总结 + +通过集成Seeq和TDengine,可以充分利用TDengine高效的存储和查询性能,同时也可以受益于Seeq提供给用户的强大数据可视化和分析功能。 + +这种集成使用户能够充分利用TDengine的高性能时序数据存储和检索,确保高效处理大量数据。同时,Seeq提供高级分析功能,如数据可视化、异常检测、相关性分析和预测建模,使用户能够获得有价值的洞察并基于数据进行决策。 + +综合来看,Seeq和TDengine共同为制造业、工业物联网和电力系统等各行各业的时序数据分析提供了综合解决方案。高效数据存储和先进的分析相结合,赋予用户充分发挥时序数据潜力的能力,推动运营改进,并支持预测和规划分析应用。 diff --git a/docs/zh/20-third-party/seeq/seeq-demo-schema.webp b/docs/zh/20-third-party/seeq/seeq-demo-schema.webp new file mode 100644 index 0000000000..3f603749ad Binary files /dev/null and b/docs/zh/20-third-party/seeq/seeq-demo-schema.webp differ diff --git a/docs/zh/20-third-party/seeq/seeq-demo-workbench.webp b/docs/zh/20-third-party/seeq/seeq-demo-workbench.webp new file mode 100644 index 0000000000..5c3d7a4158 Binary files /dev/null and b/docs/zh/20-third-party/seeq/seeq-demo-workbench.webp differ diff --git a/docs/zh/20-third-party/seeq/seeq-forecast-result.webp b/docs/zh/20-third-party/seeq/seeq-forecast-result.webp new file mode 100644 index 0000000000..13144207eb Binary files /dev/null and b/docs/zh/20-third-party/seeq/seeq-forecast-result.webp differ diff --git a/docs/zh/20-third-party/seeq/seeq-workbench-with-tdengine-cloud.webp b/docs/zh/20-third-party/seeq/seeq-workbench-with-tdengine-cloud.webp new file mode 100644 index 0000000000..f486c3ea29 Binary files /dev/null and b/docs/zh/20-third-party/seeq/seeq-workbench-with-tdengine-cloud.webp differ diff --git a/examples/JDBC/taosdemo/pom.xml b/examples/JDBC/taosdemo/pom.xml index 0d47663bba..ff64d3e1df 100644 --- a/examples/JDBC/taosdemo/pom.xml +++ b/examples/JDBC/taosdemo/pom.xml @@ -133,6 +133,7 @@ 8 8 + UTF-8 diff --git a/examples/JDBC/taosdemo/readme.md b/examples/JDBC/taosdemo/readme.md index edac970399..986eef8a05 100644 --- a/examples/JDBC/taosdemo/readme.md +++ b/examples/JDBC/taosdemo/readme.md @@ -8,4 +8,4 @@ java -jar target/taosdemo-2.0.1-jar-with-dependencies.jar -host -data ``` 如果发生错误 Exception in thread "main" java.lang.UnsatisfiedLinkError: no taos in java.library.path -请检查是否安装 TDengine 客户端安装包或编译 TDengine 安装。如果确定已经安装过还出现这个错误,可以在命令行 java 后加 -Djava.library.path=/usr/local/lib 来指定寻找共享库的路径。 +请检查是否安装 TDengine 客户端安装包或编译 TDengine 安装。如果确定已经安装过还出现这个错误,可以在命令行 java 后加 -Djava.library.path=/usr/lib 来指定寻找共享库的路径。 diff --git a/examples/c/prepare.c b/examples/c/prepare.c index 4f05b6fb4c..aee8400663 100644 --- a/examples/c/prepare.c +++ b/examples/c/prepare.c @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) taos_free_result(result); // create table - const char* sql = "create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), blob nchar(10))"; + const char* sql = "create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), blob nchar(10), varbin varbinary(16))"; result = taos_query(taos, sql); code = taos_errno(result); if (code != 0) { @@ -68,6 +68,7 @@ int main(int argc, char *argv[]) double f8; char bin[40]; char blob[80]; + int8_t varbin[16]; } v = {0}; int32_t boolLen = sizeof(int8_t); @@ -80,7 +81,7 @@ int main(int argc, char *argv[]) int32_t ncharLen = 30; stmt = taos_stmt_init(taos); - TAOS_MULTI_BIND params[10]; + TAOS_MULTI_BIND params[11]; params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; params[0].buffer_length = sizeof(v.ts); params[0].buffer = &v.ts; @@ -152,9 +153,19 @@ int main(int argc, char *argv[]) params[9].is_null = NULL; params[9].num = 1; + int8_t tmp[16] = {'a', 0, 1, 13, '1'}; + int32_t vbinLen = 5; + memcpy(v.varbin, tmp, sizeof(v.varbin)); + params[10].buffer_type = TSDB_DATA_TYPE_VARBINARY; + params[10].buffer_length = sizeof(v.varbin); + params[10].buffer = v.varbin; + params[10].length = &vbinLen; + params[10].is_null = NULL; + params[10].num = 1; + char is_null = 1; - sql = "insert into m1 values(?,?,?,?,?,?,?,?,?,?)"; + sql = "insert into m1 values(?,?,?,?,?,?,?,?,?,?,?)"; code = taos_stmt_prepare(stmt, sql, 0); if (code != 0){ printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); @@ -162,7 +173,7 @@ int main(int argc, char *argv[]) v.ts = 1591060628000; for (int i = 0; i < 10; ++i) { v.ts += 1; - for (int j = 1; j < 10; ++j) { + for (int j = 1; j < 11; ++j) { params[j].is_null = ((i == j) ? &is_null : 0); } v.b = (int8_t)i % 2; @@ -216,7 +227,7 @@ int main(int argc, char *argv[]) printf("expect two rows, but %d rows are fetched\n", rows); } - taos_free_result(result); +// taos_free_result(result); taos_stmt_close(stmt); return 0; diff --git a/examples/c/tmq.c b/examples/c/tmq.c index 136c54b874..15ab4fcfc9 100644 --- a/examples/c/tmq.c +++ b/examples/c/tmq.c @@ -280,7 +280,7 @@ void consume_repeatly(tmq_t* tmq) { code = tmq_offset_seek(tmq, topic_name, p->vgId, p->begin); if (code != 0) { - fprintf(stderr, "failed to seek to %ld, reason:%s", p->begin, tmq_err2str(code)); + fprintf(stderr, "failed to seek to %d, reason:%s", (int)p->begin, tmq_err2str(code)); } } diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 2db9c475dd..d7a3d84424 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -102,6 +102,11 @@ extern uint16_t tsMonitorPort; extern int32_t tsMonitorMaxLogs; extern bool tsMonitorComp; +// audit +extern bool tsEnableAudit; +extern char tsAuditFqdn[]; +extern uint16_t tsAuditPort; + // telem extern bool tsEnableTelem; extern int32_t tsTelemInterval; diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 63a370355a..748854c51b 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -113,7 +113,7 @@ #define TK_TABLE_PREFIX 95 #define TK_TABLE_SUFFIX 96 #define TK_NK_COLON 97 -#define TK_MAX_SPEED 98 +#define TK_BWLIMIT 98 #define TK_START 99 #define TK_TIMESTAMP 100 #define TK_END 101 @@ -356,6 +356,7 @@ #define TK_WAL 338 + #define TK_NK_SPACE 600 #define TK_NK_COMMENT 601 #define TK_NK_ILLEGAL 602 diff --git a/include/libs/audit/audit.h b/include/libs/audit/audit.h new file mode 100644 index 0000000000..1381b6e4a2 --- /dev/null +++ b/include/libs/audit/audit.h @@ -0,0 +1,46 @@ +/* + * 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_AUDIT_H_ +#define _TD_AUDIT_H_ + +#include "tarray.h" +#include "tdef.h" +#include "tlog.h" +#include "tmsg.h" +#include "tjson.h" +#include "tmsgcb.h" +#include "trpc.h" +#include "mnode.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + const char *server; + uint16_t port; + bool comp; +} SAuditCfg; + +int32_t auditInit(const SAuditCfg *pCfg); +void auditSend(SJson *pJson); +void auditRecord(SRpcMsg *pReq, int64_t clusterId, char *operation, char *target1, char *target2, char *detail); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_MONITOR_H_*/ diff --git a/include/libs/executor/dataSinkMgt.h b/include/libs/executor/dataSinkMgt.h index 617ca7c23a..2e2882e35e 100644 --- a/include/libs/executor/dataSinkMgt.h +++ b/include/libs/executor/dataSinkMgt.h @@ -59,7 +59,7 @@ typedef struct SDataSinkMgtCfg { uint32_t maxDataBlockNumPerQuery; } SDataSinkMgtCfg; -int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg, SStorageAPI* pAPI); +int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg, SStorageAPI* pAPI, void** ppSinkManager); typedef struct SInputData { const struct SSDataBlock* pData; @@ -83,7 +83,7 @@ typedef struct SOutputData { * @param pHandle output * @return error code */ -int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam, const char* id); +int32_t dsCreateDataSinker(void* pSinkManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam, const char* id); int32_t dsDataSinkGetCacheSize(SDataSinkStat* pStat); diff --git a/include/os/osDir.h b/include/os/osDir.h index 55c7a15764..533ac8e4a4 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -83,7 +83,7 @@ void taosRemoveDir(const char *dirname); bool taosDirExist(const char *dirname); int32_t taosMkDir(const char *dirname); int32_t taosMulMkDir(const char *dirname); -int32_t taosMulModeMkDir(const char *dirname, int mode); +int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess); void taosRemoveOldFiles(const char *dirname, int32_t keepDays); int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen); int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen); diff --git a/packaging/MPtestJenkinsfile b/packaging/MPtestJenkinsfile index 0570bae191..1b2e555b88 100644 --- a/packaging/MPtestJenkinsfile +++ b/packaging/MPtestJenkinsfile @@ -114,7 +114,7 @@ pipeline { sync_source("${BRANCH_NAME}") sh ''' if [ "${verMode}" = "all" ];then - verMode="community enterprise" + verMode="enterprise" fi verModeList=${verMode} for verModeSin in ${verModeList} @@ -123,18 +123,6 @@ pipeline { bash testpackage.sh -m ${verModeSin} -f server -l false -c x64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t tar python3 checkPackageRuning.py done - ''' - - sh ''' - cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh -m community -f server -l true -c x64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t tar - python3 checkPackageRuning.py - ''' - - sh ''' - cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh -m community -f server -l false -c x64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t deb - python3 checkPackageRuning.py ''' } } diff --git a/packaging/deb/DEBIAN/prerm b/packaging/deb/DEBIAN/prerm index 0d63115a04..a474dc4c80 100644 --- a/packaging/deb/DEBIAN/prerm +++ b/packaging/deb/DEBIAN/prerm @@ -37,6 +37,7 @@ else ${csudo}rm -f ${inc_link_dir}/taos.h || : ${csudo}rm -f ${inc_link_dir}/taosdef.h || : ${csudo}rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${inc_link_dir}/tdef.h || : ${csudo}rm -f ${inc_link_dir}/taosudf.h || : [ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h || : ${csudo}rm -f ${lib_link_dir}/libtaos.* || : diff --git a/packaging/deb/makedeb.sh b/packaging/deb/makedeb.sh index 07819159c4..eca75ce71a 100755 --- a/packaging/deb/makedeb.sh +++ b/packaging/deb/makedeb.sh @@ -98,6 +98,7 @@ cp ${compile_dir}/build/lib/${libfile} ${pkg_dir}${install_home_pat cp ${compile_dir}/../include/client/taos.h ${pkg_dir}${install_home_path}/include cp ${compile_dir}/../include/common/taosdef.h ${pkg_dir}${install_home_path}/include cp ${compile_dir}/../include/util/taoserror.h ${pkg_dir}${install_home_path}/include +cp ${compile_dir}/../include/util/tdef.h ${pkg_dir}${install_home_path}/include cp ${compile_dir}/../include/libs/function/taosudf.h ${pkg_dir}${install_home_path}/include [ -f ${compile_dir}/build/include/taosws.h ] && cp ${compile_dir}/build/include/taosws.h ${pkg_dir}${install_home_path}/include ||: cp -r ${top_dir}/examples/* ${pkg_dir}${install_home_path}/examples diff --git a/packaging/rpm/tdengine.spec b/packaging/rpm/tdengine.spec index 846d17e7f6..e93af2470a 100644 --- a/packaging/rpm/tdengine.spec +++ b/packaging/rpm/tdengine.spec @@ -95,6 +95,7 @@ cp %{_compiledir}/build/lib/${libfile} %{buildroot}%{homepath}/driv cp %{_compiledir}/../include/client/taos.h %{buildroot}%{homepath}/include cp %{_compiledir}/../include/common/taosdef.h %{buildroot}%{homepath}/include cp %{_compiledir}/../include/util/taoserror.h %{buildroot}%{homepath}/include +cp %{_compiledir}/../include/util/tdef.h %{buildroot}%{homepath}/include cp %{_compiledir}/../include/libs/function/taosudf.h %{buildroot}%{homepath}/include [ -f %{_compiledir}/build/include/taosws.h ] && cp %{_compiledir}/build/include/taosws.h %{buildroot}%{homepath}/include ||: #cp -r %{_compiledir}/../src/connector/python %{buildroot}%{homepath}/connector @@ -217,6 +218,7 @@ if [ $1 -eq 0 ];then ${csudo}rm -f ${inc_link_dir}/taos.h || : ${csudo}rm -f ${inc_link_dir}/taosdef.h || : ${csudo}rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${inc_link_dir}/tdef.h || : ${csudo}rm -f ${inc_link_dir}/taosudf.h || : ${csudo}rm -f ${lib_link_dir}/libtaos.* || : diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index f9a11f5540..408a5664a8 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -345,7 +345,7 @@ function install_jemalloc() { } function install_header() { - ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/taosudf.h || : + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/tdef.h ${inc_link_dir}/taosudf.h || : [ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h || : @@ -353,6 +353,7 @@ function install_header() { ${csudo}ln -sf ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h ${csudo}ln -sf ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h ${csudo}ln -sf ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}ln -sf ${install_main_dir}/include/tdef.h ${inc_link_dir}/tdef.h ${csudo}ln -sf ${install_main_dir}/include/taosudf.h ${inc_link_dir}/taosudf.h [ -f ${install_main_dir}/include/taosws.h ] && ${csudo}ln -sf ${install_main_dir}/include/taosws.h ${inc_link_dir}/taosws.h || : @@ -935,7 +936,7 @@ function updateProduct() { fi echo echo -e "\033[44;32;1m${productName2} is updated successfully!${NC}" - echo -e "\033[44;32;1mTo manage ${productName2} instance, view documentation and explorer features, you need to install ${clientName2}Explorer ${NC}" + echo -e "\033[44;32;1mTo manage ${productName2} instance, view documentation or explorer features, please install ${clientName2}Explorer ${NC}" else install_bin install_config @@ -1028,7 +1029,7 @@ function installProduct() { fi echo -e "\033[44;32;1m${productName2} is installed successfully!${NC}" - echo -e "\033[44;32;1mTo manage ${productName2} instance, view documentation and explorer features, you need to install ${clientName2}Explorer ${NC}" + echo -e "\033[44;32;1mTo manage ${productName2} instance, view documentation or explorer features, please install ${clientName2}Explorer ${NC}" echo else # Only install client install_bin diff --git a/packaging/tools/install_client.sh b/packaging/tools/install_client.sh index 18ebf9dc8f..c8baab8269 100755 --- a/packaging/tools/install_client.sh +++ b/packaging/tools/install_client.sh @@ -180,10 +180,11 @@ function install_lib() { } function install_header() { - ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/taosudf.h || : + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/tdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/taosudf.h || : ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/tdef.h ${inc_link_dir}/tdef.h ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h ${csudo}ln -s ${install_main_dir}/include/taosudf.h ${inc_link_dir}/taosudf.h diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index 0a5f9d2668..ea19125bf5 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -158,7 +158,6 @@ function install_bin() { ${csudo}rm -f ${bin_link_dir}/udfd || : ${csudo}rm -f ${bin_link_dir}/taosdemo || : ${csudo}rm -f ${bin_link_dir}/taosdump || : - ${csudo}rm -f ${bin_link_dir}/taosx || : ${csudo}rm -f ${bin_link_dir}/${uninstallScript} || : if [ "$osType" != "Darwin" ]; then @@ -348,9 +347,9 @@ function install_lib() { function install_header() { ${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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/tdef.h ${inc_link_dir}/taosudf.h || : [ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h ||: - ${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h ${source_dir}/include/libs/function/taosudf.h \ + ${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h ${source_dir}/include/util/tdef.h ${source_dir}/include/libs/function/taosudf.h \ ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* if [ -f ${binary_dir}/build/include/taosws.h ]; then @@ -361,6 +360,7 @@ function install_header() { ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h > /dev/null 2>&1 ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h > /dev/null 2>&1 ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h > /dev/null 2>&1 + ${csudo}ln -s ${install_main_dir}/include/tdef.h ${inc_link_dir}/tdef.h > /dev/null 2>&1 ${csudo}ln -s ${install_main_dir}/include/taosudf.h ${inc_link_dir}/taosudf.h > /dev/null 2>&1 ${csudo}chmod 644 ${install_main_dir}/include/* diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh index cd59294fe7..243efd693e 100755 --- a/packaging/tools/makeclient.sh +++ b/packaging/tools/makeclient.sh @@ -83,7 +83,7 @@ else wslib_files="${build_dir}/lib/libtaosws.dylib" fi -header_files="${code_dir}/include/client/taos.h ${code_dir}/include/common/taosdef.h ${code_dir}/include/util/taoserror.h ${code_dir}/include/libs/function/taosudf.h" +header_files="${code_dir}/include/client/taos.h ${code_dir}/include/common/taosdef.h ${code_dir}/include/util/taoserror.h ${code_dir}/include/util/tdef.h ${code_dir}/include/libs/function/taosudf.h" wsheader_files="${build_dir}/include/taosws.h" if [ "$dbName" != "taos" ]; then diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index ad64ca431e..655629b92c 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -115,7 +115,7 @@ else lib_files="${build_dir}/lib/libtaos.so.${version}" wslib_files="${build_dir}/lib/libtaosws.so" fi -header_files="${code_dir}/include/client/taos.h ${code_dir}/include/common/taosdef.h ${code_dir}/include/util/taoserror.h ${code_dir}/include/libs/function/taosudf.h" +header_files="${code_dir}/include/client/taos.h ${code_dir}/include/common/taosdef.h ${code_dir}/include/util/taoserror.h ${code_dir}/include/util/tdef.h ${code_dir}/include/libs/function/taosudf.h" wsheader_files="${build_dir}/include/taosws.h" diff --git a/packaging/tools/post.sh b/packaging/tools/post.sh index e79a10c9e9..ceaebfdc7c 100755 --- a/packaging/tools/post.sh +++ b/packaging/tools/post.sh @@ -133,12 +133,13 @@ function kill_taosd() { function install_include() { log_print "start install include from ${inc_dir} to ${inc_link_dir}" ${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 || : + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/tdef.h ${inc_link_dir}/taosudf.h || : [ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h ||: ${csudo}ln -s ${inc_dir}/taos.h ${inc_link_dir}/taos.h ${csudo}ln -s ${inc_dir}/taosdef.h ${inc_link_dir}/taosdef.h ${csudo}ln -s ${inc_dir}/taoserror.h ${inc_link_dir}/taoserror.h + ${csudo}ln -s ${inc_dir}/tdef.h ${inc_link_dir}/tdef.h ${csudo}ln -s ${inc_dir}/taosudf.h ${inc_link_dir}/taosudf.h [ -f ${inc_dir}/taosws.h ] && ${csudo}ln -sf ${inc_dir}/taosws.h ${inc_link_dir}/taosws.h ||: diff --git a/packaging/tools/preun.sh b/packaging/tools/preun.sh index 68f6b53c45..25f3d8ce4a 100755 --- a/packaging/tools/preun.sh +++ b/packaging/tools/preun.sh @@ -143,6 +143,7 @@ ${csudo}rm -f ${cfg_link_dir}/*.new || : ${csudo}rm -f ${inc_link_dir}/taos.h || : ${csudo}rm -f ${inc_link_dir}/taosdef.h || : ${csudo}rm -f ${inc_link_dir}/taoserror.h || : +${csudo}rm -f ${inc_link_dir}/tdef.h || : ${csudo}rm -f ${inc_link_dir}/taosudf.h || : ${csudo}rm -f ${lib_link_dir}/libtaos.* || : ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : diff --git a/packaging/tools/remove.sh b/packaging/tools/remove.sh index eca0c5e973..0e8b036f28 100755 --- a/packaging/tools/remove.sh +++ b/packaging/tools/remove.sh @@ -155,6 +155,7 @@ function clean_header() { ${csudo}rm -f ${inc_link_dir}/taos.h || : ${csudo}rm -f ${inc_link_dir}/taosdef.h || : ${csudo}rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${inc_link_dir}/tdef.h || : ${csudo}rm -f ${inc_link_dir}/taosudf.h || : [ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h || : diff --git a/packaging/tools/remove_client.sh b/packaging/tools/remove_client.sh index 2bdb56fac2..695307254d 100755 --- a/packaging/tools/remove_client.sh +++ b/packaging/tools/remove_client.sh @@ -73,6 +73,7 @@ function clean_header() { ${csudo}rm -f ${inc_link_dir}/taos.h || : ${csudo}rm -f ${inc_link_dir}/taosdef.h || : ${csudo}rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${inc_link_dir}/tdef.h || : ${csudo}rm -f ${inc_link_dir}/taosudf.h || : } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 64bcd6d898..73b4ec2a74 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -387,8 +387,18 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) len += sprintf(str + len, "%lf", dv); } break; + case TSDB_DATA_TYPE_VARBINARY:{ + void* data = NULL; + uint32_t size = 0; + int32_t charLen = varDataLen((char *)row[i] - VARSTR_HEADER_SIZE); + if(taosAscii2Hex(row[i], charLen, &data, &size) < 0){ + break; + } + memcpy(str + len, data, size); + len += size; + taosMemoryFree(data); + }break; case TSDB_DATA_TYPE_BINARY: - case TSDB_DATA_TYPE_VARBINARY: case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_GEOMETRY: { int32_t charLen = varDataLen((char *)row[i] - VARSTR_HEADER_SIZE); diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index af6b3bcc8c..f5cdfeadad 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -522,9 +522,9 @@ static char* processAlterTable(SMqMetaRsp* metaRsp) { buf = parseTagDatatoJson(vAlterTbReq.pTagVal); } else { if(vAlterTbReq.tagType == TSDB_DATA_TYPE_VARBINARY){ - buf = taosMemoryCalloc(vAlterTbReq.nTagVal + 1, 1); + buf = taosMemoryCalloc(vAlterTbReq.nTagVal*2 + 2 + 3, 1); }else{ - buf = taosMemoryCalloc(vAlterTbReq.nTagVal + 1, 1); + buf = taosMemoryCalloc(vAlterTbReq.nTagVal + 3, 1); } dataConverToStr(buf, vAlterTbReq.tagType, vAlterTbReq.pTagVal, vAlterTbReq.nTagVal, NULL); } @@ -697,14 +697,14 @@ static int32_t taosCreateStb(TAOS* taos, void* meta, int32_t metaLen) { pReq.pColumns = taosArrayInit(req.schemaRow.nCols, sizeof(SField)); for (int32_t i = 0; i < req.schemaRow.nCols; i++) { SSchema* pSchema = req.schemaRow.pSchema + i; - SField field = {.type = pSchema->type, .bytes = pSchema->bytes}; + SField field = {.type = pSchema->type, .flags = pSchema->flags, .bytes = pSchema->bytes}; strcpy(field.name, pSchema->name); taosArrayPush(pReq.pColumns, &field); } pReq.pTags = taosArrayInit(req.schemaTag.nCols, sizeof(SField)); for (int32_t i = 0; i < req.schemaTag.nCols; i++) { SSchema* pSchema = req.schemaTag.pSchema + i; - SField field = {.type = pSchema->type, .bytes = pSchema->bytes}; + SField field = {.type = pSchema->type, .flags = pSchema->flags, .bytes = pSchema->bytes}; strcpy(field.name, pSchema->name); taosArrayPush(pReq.pTags, &field); } diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 9b2f805675..10f8b89f4d 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -218,7 +218,16 @@ int32_t smlSetCTableName(SSmlTableInfo *oneTable) { if (strlen(oneTable->childTableName) == 0) { SArray *dst = taosArrayDup(oneTable->tags, NULL); - RandTableName rName = {dst, oneTable->sTableName, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName}; + ASSERT(oneTable->sTableNameLen < TSDB_TABLE_NAME_LEN); + char superName[TSDB_TABLE_NAME_LEN] = {0}; + RandTableName rName = {dst, NULL, (uint8_t)oneTable->sTableNameLen, oneTable->childTableName}; + if(tsSmlDot2Underline){ + memcpy(superName, oneTable->sTableName, oneTable->sTableNameLen); + smlStrReplace(superName, oneTable->sTableNameLen); + rName.stbFullName = superName; + }else{ + rName.stbFullName = oneTable->sTableName; + } buildChildTableName(&rName); taosArrayDestroy(dst); @@ -230,6 +239,9 @@ void getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tin char key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0}; size_t nLen = strlen(tinfo->childTableName); memcpy(key, currElement->measure, currElement->measureLen); + if(tsSmlDot2Underline){ + smlStrReplace(key, currElement->measureLen); + } memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen); void *uid = taosHashGet(info->tableUids, key, diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index 619f144bf9..e861bd4b92 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -986,7 +986,7 @@ int32_t tmq_subscription(tmq_t* tmq, tmq_list_t** topics) { int32_t tmq_unsubscribe(tmq_t* tmq) { if(tmq == NULL) return TSDB_CODE_INVALID_PARA; if (tmq->status != TMQ_CONSUMER_STATUS__READY) { - tscInfo("consumer:0x%" PRIx64 " not in ready state, close it directly", tmq->consumerId); + tscInfo("consumer:0x%" PRIx64 " not in ready state, unsubscribe it directly", tmq->consumerId); return 0; } if (tmq->autoCommit) { diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 06d38dee70..02c56cc40f 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -95,6 +95,11 @@ uint16_t tsMonitorPort = 6043; int32_t tsMonitorMaxLogs = 100; bool tsMonitorComp = false; +// audit +bool tsEnableAudit = false; +char tsAuditFqdn[TSDB_FQDN_LEN] = {0}; +uint16_t tsAuditPort = 6043; + // telem bool tsEnableTelem = true; int32_t tsTelemInterval = 43200; @@ -602,6 +607,10 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "monitorMaxLogs", tsMonitorMaxLogs, 1, 1000000, CFG_SCOPE_SERVER) != 0) return -1; if (cfgAddBool(pCfg, "monitorComp", tsMonitorComp, CFG_SCOPE_SERVER) != 0) return -1; + if (cfgAddBool(pCfg, "audit", tsEnableAudit, CFG_SCOPE_SERVER) != 0) return -1; + if (cfgAddString(pCfg, "auditFqdn", tsAuditFqdn, CFG_SCOPE_SERVER) != 0) return -1; + if (cfgAddInt32(pCfg, "auditPort", tsAuditPort, 1, 65056, CFG_SCOPE_SERVER) != 0) return -1; + if (cfgAddBool(pCfg, "crashReporting", tsEnableCrashReport, CFG_SCOPE_BOTH) != 0) return -1; if (cfgAddBool(pCfg, "telemetryReporting", tsEnableTelem, CFG_SCOPE_BOTH) != 0) return -1; if (cfgAddInt32(pCfg, "telemetryInterval", tsTelemInterval, 1, 200000, CFG_SCOPE_BOTH) != 0) return -1; @@ -1003,6 +1012,10 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsMonitorComp = cfgGetItem(pCfg, "monitorComp")->bval; tsQueryRspPolicy = cfgGetItem(pCfg, "queryRspPolicy")->i32; + tsEnableAudit = cfgGetItem(pCfg, "audit")->bval; + tstrncpy(tsAuditFqdn, cfgGetItem(pCfg, "auditFqdn")->str, TSDB_FQDN_LEN); + tsAuditPort = (uint16_t)cfgGetItem(pCfg, "auditPort")->i32; + tsEnableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval; tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval; tsTtlChangeOnWrite = cfgGetItem(pCfg, "ttlChangeOnWrite")->bval; @@ -1511,7 +1524,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32, false); - if (taosMulModeMkDir(tsLogDir, 0777) != 0) { + if (taosMulModeMkDir(tsLogDir, 0777, true) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); printf("failed to create dir:%s since %s", tsLogDir, terrstr()); cfgCleanup(pCfg); diff --git a/source/dnode/mgmt/node_mgmt/src/dmEnv.c b/source/dnode/mgmt/node_mgmt/src/dmEnv.c index a34002161d..320c9db37d 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmEnv.c +++ b/source/dnode/mgmt/node_mgmt/src/dmEnv.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "dmMgmt.h" +#include "audit.h" #define STR_CASE_CMP(s, d) (0 == strcasecmp((s), (d))) #define STR_STR_CMP(s, d) (strstr((s), (d))) @@ -34,6 +35,16 @@ } \ } while (0) +#define DM_INIT_AUDIT() \ + do { \ + auditCfg.port = tsMonitorPort; \ + auditCfg.server = tsMonitorFqdn; \ + auditCfg.comp = tsMonitorComp; \ + if (auditInit(&auditCfg) != 0) { \ + return -1; \ + } \ + } while (0) + #define DM_ERR_RTN(c) \ do { \ code = (c); \ @@ -96,6 +107,14 @@ _exit: return code; } +static int32_t dmInitAudit() { + SAuditCfg auditCfg = {0}; + + DM_INIT_AUDIT(); + + return 0; +} + static bool dmDataSpaceAvailable() { SDnode *pDnode = dmInstance(); if (pDnode->pTfs) { @@ -176,6 +195,7 @@ int32_t dmInit() { if (dmCheckRepeatInit(dmInstance()) != 0) return -1; if (dmInitSystem() != 0) return -1; if (dmInitMonitor() != 0) return -1; + if (dmInitAudit() != 0) return -1; if (dmInitDnode(dmInstance()) != 0) return -1; dInfo("dnode env is initialized"); diff --git a/source/dnode/mnode/impl/CMakeLists.txt b/source/dnode/mnode/impl/CMakeLists.txt index 010067e99f..48dc71a12b 100644 --- a/source/dnode/mnode/impl/CMakeLists.txt +++ b/source/dnode/mnode/impl/CMakeLists.txt @@ -16,7 +16,7 @@ target_include_directories( PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( - mnode scheduler sdb wal transport cjson sync monitor executor qworker stream parser + mnode scheduler sdb wal transport cjson sync monitor executor qworker stream parser audit ) IF (TD_GRANT) diff --git a/source/dnode/mnode/impl/inc/mndConsumer.h b/source/dnode/mnode/impl/inc/mndConsumer.h index a3a31cfc5a..94c937e8f4 100644 --- a/source/dnode/mnode/impl/inc/mndConsumer.h +++ b/source/dnode/mnode/impl/inc/mndConsumer.h @@ -33,7 +33,7 @@ enum { int32_t mndInitConsumer(SMnode *pMnode); void mndCleanupConsumer(SMnode *pMnode); -void mndDropConsumerFromSdb(SMnode *pMnode, int64_t consumerId); +void mndDropConsumerFromSdb(SMnode *pMnode, int64_t consumerId, SRpcHandleInfo* info); SMqConsumerObj *mndAcquireConsumer(SMnode *pMnode, int64_t consumerId); void mndReleaseConsumer(SMnode *pMnode, SMqConsumerObj *pConsumer); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 81c401775b..c4c0ea238d 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -99,6 +99,8 @@ typedef enum { TRN_CONFLICT_GLOBAL = 1, TRN_CONFLICT_DB = 2, TRN_CONFLICT_DB_INSIDE = 3, + TRN_CONFLICT_TOPIC = 4, + TRN_CONFLICT_TOPIC_INSIDE = 5, } ETrnConflct; typedef enum { diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 82492f930e..f25bd2cffb 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -37,7 +37,6 @@ static const char *mndConsumerStatusName(int status); static int32_t mndConsumerActionInsert(SSdb *pSdb, SMqConsumerObj *pConsumer); static int32_t mndConsumerActionDelete(SSdb *pSdb, SMqConsumerObj *pConsumer); static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer, SMqConsumerObj *pNewConsumer); -static int32_t mndProcessConsumerMetaMsg(SRpcMsg *pMsg); static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextConsumer(SMnode *pMnode, void *pIter); @@ -45,7 +44,6 @@ static int32_t mndProcessSubscribeReq(SRpcMsg *pMsg); static int32_t mndProcessAskEpReq(SRpcMsg *pMsg); static int32_t mndProcessMqHbReq(SRpcMsg *pMsg); static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg); -static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg); static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg); static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg); @@ -64,7 +62,6 @@ int32_t mndInitConsumer(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_TMQ_HB, mndProcessMqHbReq); mndSetMsgHandle(pMnode, TDMT_MND_TMQ_ASK_EP, mndProcessAskEpReq); mndSetMsgHandle(pMnode, TDMT_MND_TMQ_TIMER, mndProcessMqTimerMsg); -// mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CONSUMER_LOST, mndProcessConsumerLostMsg); mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CONSUMER_RECOVER, mndProcessConsumerRecoverMsg); mndSetMsgHandle(pMnode, TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, mndProcessConsumerClearMsg); @@ -76,7 +73,7 @@ int32_t mndInitConsumer(SMnode *pMnode) { void mndCleanupConsumer(SMnode *pMnode) {} -void mndDropConsumerFromSdb(SMnode *pMnode, int64_t consumerId){ +void mndDropConsumerFromSdb(SMnode *pMnode, int64_t consumerId, SRpcHandleInfo* info){ SMqConsumerClearMsg *pClearMsg = rpcMallocCont(sizeof(SMqConsumerClearMsg)); if (pClearMsg == NULL) { mError("consumer:0x%"PRIx64" failed to clear consumer due to out of memory. alloc size:%d", consumerId, (int32_t)sizeof(SMqConsumerClearMsg)); @@ -85,7 +82,11 @@ void mndDropConsumerFromSdb(SMnode *pMnode, int64_t consumerId){ pClearMsg->consumerId = consumerId; SRpcMsg rpcMsg = { - .msgType = TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, .pCont = pClearMsg, .contLen = sizeof(SMqConsumerClearMsg)}; + .msgType = TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, + .pCont = pClearMsg, + .contLen = sizeof(SMqConsumerClearMsg), + .info = *info, + }; mInfo("consumer:0x%" PRIx64 " drop from sdb", consumerId); tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); @@ -122,48 +123,31 @@ void mndRebCntDec() { } } -//static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg) { -// SMnode *pMnode = pMsg->info.node; -// SMqConsumerLostMsg *pLostMsg = pMsg->pCont; -// SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pLostMsg->consumerId); -// if (pConsumer == NULL) { -// return 0; -// } -// -// mInfo("process consumer lost msg, consumer:0x%" PRIx64 " status:%d(%s)", pLostMsg->consumerId, pConsumer->status, -// mndConsumerStatusName(pConsumer->status)); -// -// if (pConsumer->status != MQ_CONSUMER_STATUS_READY) { -// mndReleaseConsumer(pMnode, pConsumer); -// return -1; -// } -// -// SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup); -// pConsumerNew->updateType = CONSUMER_UPDATE_TIMER_LOST; -// -// mndReleaseConsumer(pMnode, pConsumer); -// -// STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "lost-csm"); -// if (pTrans == NULL) { -// goto FAIL; -// } -// -// if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) { -// goto FAIL; -// } -// -// if (mndTransPrepare(pMnode, pTrans) != 0) { -// goto FAIL; -// } -// -// tDeleteSMqConsumerObj(pConsumerNew, true); -// mndTransDrop(pTrans); -// return 0; -//FAIL: -// tDeleteSMqConsumerObj(pConsumerNew, true); -// mndTransDrop(pTrans); -// return -1; -//} +static int32_t validateTopics(STrans *pTrans, const SArray *pTopicList, SMnode *pMnode, const char *pUser) { + int32_t numOfTopics = taosArrayGetSize(pTopicList); + + for (int32_t i = 0; i < numOfTopics; i++) { + char *pOneTopic = taosArrayGetP(pTopicList, i); + SMqTopicObj *pTopic = mndAcquireTopic(pMnode, pOneTopic); + if (pTopic == NULL) { // terrno has been set by callee function + return -1; + } + + if (mndCheckTopicPrivilege(pMnode, pUser, MND_OPER_SUBSCRIBE, pTopic) != 0) { + mndReleaseTopic(pMnode, pTopic); + return -1; + } + + mndTransSetDbName(pTrans, pOneTopic, NULL); + if(mndTransCheckConflict(pMnode, pTrans) != 0){ + mndReleaseTopic(pMnode, pTopic); + return -1; + } + mndReleaseTopic(pMnode, pTopic); + } + + return 0; +} static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg) { SMnode *pMnode = pMsg->info.node; @@ -188,10 +172,13 @@ static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg) { mndReleaseConsumer(pMnode, pConsumer); - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pMsg, "recover-csm"); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_TOPIC, pMsg, "recover-csm"); if (pTrans == NULL) { goto FAIL; } + if(validateTopics(pTrans, pConsumer->assignedTopics, pMnode, pMsg->info.conn.user) != 0){ + goto FAIL; + } if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL; if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL; @@ -221,19 +208,12 @@ static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg) { mInfo("consumer:0x%" PRIx64 " needs to be cleared, status %s", pClearMsg->consumerId, mndConsumerStatusName(pConsumer->status)); -// if (pConsumer->status != MQ_CONSUMER_STATUS_LOST) { -// mndReleaseConsumer(pMnode, pConsumer); -// return -1; -// } - SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup); -// pConsumerNew->updateType = CONSUMER_UPDATE_TIMER_LOST; mndReleaseConsumer(pMnode, pConsumer); STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "clear-csm"); if (pTrans == NULL) goto FAIL; - // this is the drop action, not the update action if (mndSetConsumerDropLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL; if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL; @@ -318,7 +298,7 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) { if (status == MQ_CONSUMER_STATUS_READY) { if (taosArrayGetSize(pConsumer->assignedTopics) == 0) { // unsubscribe or close - mndDropConsumerFromSdb(pMnode, pConsumer->consumerId); + mndDropConsumerFromSdb(pMnode, pConsumer->consumerId, &pMsg->info); } else if (hbStatus > MND_CONSUMER_LOST_HB_CNT) { taosRLockLatch(&pConsumer->lock); int32_t topicNum = taosArrayGetSize(pConsumer->currentTopics); @@ -333,7 +313,7 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) { } } else if (status == MQ_CONSUMER_STATUS_LOST) { if (hbStatus > MND_CONSUMER_LOST_CLEAR_THRESHOLD) { // clear consumer if lost a day - mndDropConsumerFromSdb(pMnode, pConsumer->consumerId); + mndDropConsumerFromSdb(pMnode, pConsumer->consumerId, &pMsg->info); } } else { // MQ_CONSUMER_STATUS_REBALANCE taosRLockLatch(&pConsumer->lock); @@ -410,6 +390,7 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) { .msgType = TDMT_MND_TMQ_CONSUMER_RECOVER, .pCont = pRecoverMsg, .contLen = sizeof(SMqConsumerRecoverMsg), + .info = pMsg->info, }; tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &pRpcMsg); } @@ -484,6 +465,7 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) { .msgType = TDMT_MND_TMQ_CONSUMER_RECOVER, .pCont = pRecoverMsg, .contLen = sizeof(SMqConsumerRecoverMsg), + .info = pMsg->info, }; tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &pRpcMsg); @@ -629,27 +611,6 @@ int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj return 0; } -static int32_t validateTopics(const SArray *pTopicList, SMnode *pMnode, const char *pUser) { - int32_t numOfTopics = taosArrayGetSize(pTopicList); - - for (int32_t i = 0; i < numOfTopics; i++) { - char *pOneTopic = taosArrayGetP(pTopicList, i); - SMqTopicObj *pTopic = mndAcquireTopic(pMnode, pOneTopic); - if (pTopic == NULL) { // terrno has been set by callee function - return -1; - } - - if (mndCheckTopicPrivilege(pMnode, pUser, MND_OPER_SUBSCRIBE, pTopic) != 0) { - mndReleaseTopic(pMnode, pTopic); - return -1; - } - - mndReleaseTopic(pMnode, pTopic); - } - - return 0; -} - static void *topicNameDup(void *p) { return taosStrdup((char *)p); } static void freeItem(void *param) { @@ -688,12 +649,12 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) { } // check topic existence - pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pMsg, "subscribe"); + pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_TOPIC, pMsg, "subscribe"); if (pTrans == NULL) { goto _over; } - code = validateTopics(pTopicList, pMnode, pMsg->info.conn.user); + code = validateTopics(pTrans, pTopicList, pMnode, pMsg->info.conn.user); if (code != TSDB_CODE_SUCCESS) { goto _over; } @@ -722,7 +683,6 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) { if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto _over; if (mndTransPrepare(pMnode, pTrans) != 0) goto _over; - } else { int32_t status = atomic_load_32(&pExistedConsumer->status); @@ -802,7 +762,6 @@ _over: tDeleteSMqConsumerObj(pConsumerNew, true); - // TODO: replace with destroy subscribe msg taosArrayDestroyP(subscribe.topicNames, (FDelete)taosMemoryFree); return code; } diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index b0e3dc4331..cbb7a27ef5 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -29,6 +29,9 @@ #include "mndUser.h" #include "mndVgroup.h" #include "systable.h" +#include "tjson.h" +#include "thttp.h" +#include "audit.h" #define DB_VER_NUMBER 1 #define DB_RESERVE_SIZE 46 @@ -675,6 +678,22 @@ _OVER: return code; } +static void mndBuildAuditDetailInt32(char* detail, char* tmp, char* format, int32_t para){ + if(para > 0){ + if(strlen(detail) > 0) strcat(detail, ", "); + sprintf(tmp, format, para); + strcat(detail, tmp); + } +} + +static void mndBuildAuditDetailInt64(char* detail, char* tmp, char* format, int64_t para){ + if(para > 0){ + if(strlen(detail) > 0) strcat(detail, ", "); + sprintf(tmp, format, para); + strcat(detail, tmp); + } +} + static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; int32_t code = -1; @@ -733,6 +752,45 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) { code = mndCreateDb(pMnode, pReq, &createReq, pUser); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char detail[3000] = {0}; + char tmp[100] = {0}; + + mndBuildAuditDetailInt32(detail, tmp, "buffer:%d", createReq.buffer); + mndBuildAuditDetailInt32(detail, tmp, "cacheLast:%d", createReq.cacheLast); + mndBuildAuditDetailInt32(detail, tmp, "cacheLastSize:%d", createReq.cacheLastSize); + mndBuildAuditDetailInt32(detail, tmp, "compression:%d", createReq.compression); + mndBuildAuditDetailInt32(detail, tmp, "daysPerFile:%d", createReq.daysPerFile); + mndBuildAuditDetailInt32(detail, tmp, "daysToKeep0:%d", createReq.daysToKeep0); + mndBuildAuditDetailInt32(detail, tmp, "daysToKeep1:%d", createReq.daysToKeep1); + mndBuildAuditDetailInt32(detail, tmp, "daysToKeep2:%d", createReq.daysToKeep2); + mndBuildAuditDetailInt32(detail, tmp, "hashPrefix:%d", createReq.hashPrefix); + mndBuildAuditDetailInt32(detail, tmp, "hashSuffix:%d", createReq.hashSuffix); + mndBuildAuditDetailInt32(detail, tmp, "ignoreExist:%d", createReq.ignoreExist); + mndBuildAuditDetailInt32(detail, tmp, "maxRows:%d", createReq.maxRows); + mndBuildAuditDetailInt32(detail, tmp, "minRows:%d", createReq.minRows); + mndBuildAuditDetailInt32(detail, tmp, "numOfRetensions:%d", createReq.numOfRetensions); + mndBuildAuditDetailInt32(detail, tmp, "numOfStables:%d", createReq.numOfStables); + mndBuildAuditDetailInt32(detail, tmp, "numOfVgroups:%d", createReq.numOfVgroups); + mndBuildAuditDetailInt32(detail, tmp, "pages:%d", createReq.pages); + mndBuildAuditDetailInt32(detail, tmp, "pageSize:%d", createReq.pageSize); + mndBuildAuditDetailInt32(detail, tmp, "precision:%d", createReq.precision); + mndBuildAuditDetailInt32(detail, tmp, "replications:%d", createReq.replications); + mndBuildAuditDetailInt32(detail, tmp, "schemaless:%d", createReq.schemaless); + mndBuildAuditDetailInt32(detail, tmp, "sstTrigger:%d", createReq.sstTrigger); + mndBuildAuditDetailInt32(detail, tmp, "strict:%d", createReq.strict); + mndBuildAuditDetailInt32(detail, tmp, "tsdbPageSize:%d", createReq.tsdbPageSize); + mndBuildAuditDetailInt32(detail, tmp, "walFsyncPeriod:%d", createReq.walFsyncPeriod); + mndBuildAuditDetailInt32(detail, tmp, "walLevel:%d", createReq.walLevel); + mndBuildAuditDetailInt32(detail, tmp, "walRetentionPeriod:%d", createReq.walRetentionPeriod); + mndBuildAuditDetailInt32(detail, tmp, "walRetentionSize:%" PRId64, createReq.walRetentionSize); + mndBuildAuditDetailInt32(detail, tmp, "walRollPeriod:%d", createReq.walRollPeriod); + mndBuildAuditDetailInt32(detail, tmp, "walSegmentSize:%" PRId64, createReq.walSegmentSize); + + SName name = {0}; + tNameFromString(&name, createReq.db, T_NAME_ACCT | T_NAME_DB); + + auditRecord(pReq, pMnode->clusterId, "createDB", name.dbname, "", detail); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("db:%s, failed to create since %s", createReq.db, terrstr()); @@ -975,6 +1033,30 @@ static int32_t mndProcessAlterDbReq(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; } + char detail[3000] = {0}; + char tmp[100] = {0}; + + mndBuildAuditDetailInt32(detail, tmp, "buffer:%d", alterReq.buffer); + mndBuildAuditDetailInt32(detail, tmp, "cacheLast:%d", alterReq.cacheLast); + mndBuildAuditDetailInt32(detail, tmp, "cacheLastSize:%d", alterReq.cacheLastSize); + mndBuildAuditDetailInt32(detail, tmp, "daysPerFile:%d", alterReq.daysPerFile); + mndBuildAuditDetailInt32(detail, tmp, "daysToKeep0:%d", alterReq.daysToKeep0); + mndBuildAuditDetailInt32(detail, tmp, "daysToKeep1:%d", alterReq.daysToKeep1); + mndBuildAuditDetailInt32(detail, tmp, "daysToKeep2:%d", alterReq.daysToKeep2); + mndBuildAuditDetailInt32(detail, tmp, "minRows:%d", alterReq.minRows); + mndBuildAuditDetailInt32(detail, tmp, "pages:%d", alterReq.pages); + mndBuildAuditDetailInt32(detail, tmp, "pageSize:%d", alterReq.pageSize); + mndBuildAuditDetailInt32(detail, tmp, "replications:%d", alterReq.replications); + mndBuildAuditDetailInt32(detail, tmp, "sstTrigger:%d", alterReq.sstTrigger); + mndBuildAuditDetailInt32(detail, tmp, "strict:%d", alterReq.strict); + mndBuildAuditDetailInt32(detail, tmp, "walFsyncPeriod:%d", alterReq.walFsyncPeriod); + mndBuildAuditDetailInt32(detail, tmp, "walRetentionSize:%d", alterReq.walRetentionSize); + + SName name = {0}; + tNameFromString(&name, alterReq.db, T_NAME_ACCT | T_NAME_DB); + + auditRecord(pReq, pMnode->clusterId, "alterDB", name.dbname, "", detail); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (terrno != 0) code = terrno; @@ -1264,6 +1346,14 @@ static int32_t mndProcessDropDbReq(SRpcMsg *pReq) { code = TSDB_CODE_ACTION_IN_PROGRESS; } + char detail[1000] = {0}; + sprintf(detail, "ignoreNotExists:%d", dropReq.ignoreNotExists); + + SName name = {0}; + tNameFromString(&name, dropReq.db, T_NAME_ACCT | T_NAME_DB); + + auditRecord(pReq, pMnode->clusterId, "dropDB", name.dbname, "", detail); + _OVER: if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("db:%s, failed to drop since %s", dropReq.db, terrstr()); diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 291c2a793b..949d41ef07 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -26,6 +26,7 @@ #include "mndVgroup.h" #include "tmisce.h" #include "mndCluster.h" +#include "audit.h" #define TSDB_DNODE_VER_NUMBER 2 #define TSDB_DNODE_RESERVE_SIZE 64 @@ -908,6 +909,12 @@ static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) { code = mndCreateDnode(pMnode, pReq, &createReq); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; tsGrantHBInterval = 5; + + char obj[200] = {0}; + sprintf(obj, "%s:%d", createReq.fqdn, createReq.port); + + auditRecord(pReq, pMnode->clusterId, "createDnode", obj, "", ""); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("dnode:%s:%d, failed to create since %s", createReq.fqdn, createReq.port, terrstr()); @@ -1055,6 +1062,17 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) { code = mndDropDnode(pMnode, pReq, pDnode, pMObj, pQObj, pSObj, numOfVnodes, force, dropReq.unsafe); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char obj1[150] = {0}; + sprintf(obj1, "%s:%d", dropReq.fqdn, dropReq.port); + + char obj2[30] = {0}; + sprintf(obj2, "%d", dropReq.dnodeId); + + char detail[100] = {0}; + sprintf(detail, "force:%d, unsafe:%d", dropReq.force, dropReq.unsafe); + + auditRecord(pReq, pMnode->clusterId, "dropDnode", obj1, obj2, detail); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("dnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr()); @@ -1236,6 +1254,14 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { } } + char obj[50] = {0}; + sprintf(obj, "%d", cfgReq.dnodeId); + + char detail[500] = {0}; + sprintf(detail, "config:%s, value:%s", cfgReq.config, cfgReq.value); + + auditRecord(pReq, pMnode->clusterId, "alterDnode", obj, "", detail); + int32_t code = -1; SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 2757578d35..5827a30b43 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -22,6 +22,7 @@ #include "mndSync.h" #include "mndTrans.h" #include "tmisce.h" +#include "audit.h" #define MNODE_VER_NUMBER 2 #define MNODE_RESERVE_SIZE 64 @@ -652,6 +653,11 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) { code = mndCreateMnode(pMnode, pReq, pDnode, &createReq); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char obj[40] = {0}; + sprintf(obj, "%d", createReq.dnodeId); + + auditRecord(pReq, pMnode->clusterId, "createMnode", obj, "", ""); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("mnode:%d, failed to create since %s", createReq.dnodeId, terrstr()); @@ -788,6 +794,11 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) { code = mndDropMnode(pMnode, pReq, pObj); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char obj[40] = {0}; + sprintf(obj, "%d", dropReq.dnodeId); + + auditRecord(pReq, pMnode->clusterId, "dropMnode", obj, "", ""); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("mnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr()); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 524ea1a06b..9847024bee 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -25,6 +25,7 @@ #include "mndUser.h" #include "tglobal.h" #include "tversion.h" +#include "audit.h" typedef struct { uint32_t id; @@ -308,6 +309,15 @@ _CONNECT: code = 0; + char obj[100] = {0}; + sprintf(obj, "%s:%d", ip, pConn->port); + + char detail[1000] = {0}; + sprintf(detail, "connType:%d, db:%s, pid:%d, startTime:%" PRId64 ", sVer:%s, app:%s", + connReq.connType, connReq.db, connReq.pid, connReq.startTime, connReq.sVer, connReq.app); + + auditRecord(pReq, pMnode->clusterId, "login", connReq.user, obj, detail); + _OVER: mndReleaseUser(pMnode, pUser); diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 5ec81440bb..767e06a8d4 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -20,6 +20,7 @@ #include "mndShow.h" #include "mndTrans.h" #include "mndUser.h" +#include "audit.h" #define QNODE_VER_NUMBER 1 #define QNODE_RESERVE_SIZE 64 @@ -306,6 +307,10 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) { code = mndCreateQnode(pMnode, pReq, pDnode, &createReq); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char obj[33] = {0}; + sprintf(obj, "%d", createReq.dnodeId); + + auditRecord(pReq, pMnode->clusterId, "createQnode", obj, "", ""); _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("qnode:%d, failed to create since %s", createReq.dnodeId, terrstr()); @@ -415,6 +420,11 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) { code = mndDropQnode(pMnode, pReq, pObj); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char obj[33] = {0}; + sprintf(obj, "%d", dropReq.dnodeId); + + auditRecord(pReq, pMnode->clusterId, "dropQnode", obj, "", ""); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("qnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr()); diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 7d842be7de..2286186ebb 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -329,7 +329,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { pReq->info.rsp = pRsp; pReq->info.rspLen = size; - if (rowsRead == 0 || ((rowsRead < rowsToRead) && !pShow->restore)) { + if (rowsRead == 0 || mndCheckRetrieveFinished(pShow)) { pRsp->completed = 1; mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); mndReleaseShowObj(pShow, true); diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index d666f80fd3..44842084c5 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -1324,7 +1324,14 @@ static int32_t mndRetrieveIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc pShow->pIter = taosMemoryCalloc(1, sizeof(SSmaAndTagIter)); } int32_t read = mndRetrieveSma(pReq, pShow, pBlock, rows); - if (read < rows) read += mndRetrieveTagIdx(pReq, pShow, pBlock, rows - read); + if (read < rows) { + read += mndRetrieveTagIdx(pReq, pShow, pBlock, rows - read); + } + // no more to read + if (read < rows) { + taosMemoryFree(pShow->pIter); + pShow->pIter = NULL; + } return read; } static void mndCancelRetrieveIdx(SMnode *pMnode, void *pIter) { diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index cf624596dd..9a5429ba87 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -31,6 +31,7 @@ #include "mndUser.h" #include "mndVgroup.h" #include "tname.h" +#include "audit.h" #define STB_VER_NUMBER 1 #define STB_RESERVE_SIZE 64 @@ -1173,6 +1174,21 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { } if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char detail[2000] = {0}; + sprintf(detail, "colVer:%d, delay1:%" PRId64 ", delay2:%" PRId64 ", deleteMark1:%" PRId64 ", " + "deleteMark2:%" PRId64 ", igExists:%d, numOfColumns:%d, numOfFuncs:%d, numOfTags:%d, " + "source:%d, suid:%" PRId64 ", tagVer:%d, ttl:%d, " + "watermark1:%" PRId64 ", watermark2:%" PRId64, + createReq.colVer, createReq.delay1, createReq.delay2, createReq.deleteMark1, + createReq.deleteMark2, createReq.igExists, createReq.numOfColumns, createReq.numOfFuncs, createReq.numOfTags, + createReq.source, createReq.suid, createReq.tagVer, createReq.ttl, + createReq.watermark1, createReq.watermark2); + + SName name = {0}; + tNameFromString(&name, pDb->name, T_NAME_ACCT | T_NAME_DB); + + auditRecord(pReq, pMnode->clusterId, "createStb", name.dbname, createReq.name, detail); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("stb:%s, failed to create since %s", createReq.name, terrstr()); @@ -2241,6 +2257,15 @@ static int32_t mndProcessAlterStbReq(SRpcMsg *pReq) { code = mndAlterStb(pMnode, pReq, &alterReq, pDb, pStb); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char detail[2000] = {0}; + sprintf(detail, "alterType:%d, numOfFields:%d, ttl:%d" , + alterReq.alterType, alterReq.numOfFields, alterReq.ttl); + + SName name = {0}; + tNameFromString(&name, pDb->name, T_NAME_ACCT | T_NAME_DB); + + auditRecord(pReq, pMnode->clusterId, "alterStb", name.dbname, alterReq.name, detail); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("stb:%s, failed to alter since %s", alterReq.name, terrstr()); @@ -2502,6 +2527,15 @@ static int32_t mndProcessDropStbReq(SRpcMsg *pReq) { code = mndDropStb(pMnode, pReq, pDb, pStb); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char detail[2000] = {0}; + sprintf(detail, "igNotExists:%d, source:%d" , + dropReq.igNotExists, dropReq.source); + + SName name = {0}; + tNameFromString(&name, pDb->name, T_NAME_ACCT | T_NAME_DB); + + auditRecord(pReq, pMnode->clusterId, "dropStb", name.dbname, dropReq.name, detail); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("stb:%s, failed to drop since %s", dropReq.name, terrstr()); @@ -3233,136 +3267,161 @@ static int32_t buildDbColsInfoBlock(const SSDataBlock *p, const SSysTableMeta *p return numOfRows; } +#define BUILD_COL_FOR_INFO_DB 1 +#define BUILD_COL_FOR_PERF_DB 1 << 1 +#define BUILD_COL_FOR_USER_DB 1 << 2 +#define BUILD_COL_FOR_ALL_DB (BUILD_COL_FOR_INFO_DB | BUILD_COL_FOR_PERF_DB | BUILD_COL_FOR_USER_DB) -static int32_t buildSysDbColsInfo(SSDataBlock *p, char *db, char *tb) { +static int32_t buildSysDbColsInfo(SSDataBlock *p, int8_t buildWhichDBs, char *tb) { size_t size = 0; const SSysTableMeta *pSysDbTableMeta = NULL; - if (db[0] && strncmp(db, TSDB_INFORMATION_SCHEMA_DB, TSDB_DB_FNAME_LEN) != 0 && - strncmp(db, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_DB_FNAME_LEN) != 0) { - return p->info.rows; + if (buildWhichDBs & BUILD_COL_FOR_INFO_DB) { + getInfosDbMeta(&pSysDbTableMeta, &size); + p->info.rows = buildDbColsInfoBlock(p, pSysDbTableMeta, size, TSDB_INFORMATION_SCHEMA_DB, tb); } - getInfosDbMeta(&pSysDbTableMeta, &size); - p->info.rows = buildDbColsInfoBlock(p, pSysDbTableMeta, size, TSDB_INFORMATION_SCHEMA_DB, tb); - - getPerfDbMeta(&pSysDbTableMeta, &size); - p->info.rows = buildDbColsInfoBlock(p, pSysDbTableMeta, size, TSDB_PERFORMANCE_SCHEMA_DB, tb); + if (buildWhichDBs & BUILD_COL_FOR_PERF_DB) { + getPerfDbMeta(&pSysDbTableMeta, &size); + p->info.rows = buildDbColsInfoBlock(p, pSysDbTableMeta, size, TSDB_PERFORMANCE_SCHEMA_DB, tb); + } return p->info.rows; } +static int8_t determineBuildColForWhichDBs(const char* db) { + int8_t buildWhichDBs; + if (!db[0]) + buildWhichDBs = BUILD_COL_FOR_ALL_DB; + else { + char *p = strchr(db, '.'); + if (p && strcmp(p + 1, TSDB_INFORMATION_SCHEMA_DB) == 0) { + buildWhichDBs = BUILD_COL_FOR_INFO_DB; + } else if (p && strcmp(p + 1, TSDB_PERFORMANCE_SCHEMA_DB) == 0) { + buildWhichDBs = BUILD_COL_FOR_PERF_DB; + } else { + buildWhichDBs = BUILD_COL_FOR_USER_DB; + } + } + return buildWhichDBs; +} + static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { + uint8_t buildWhichDBs; SMnode *pMnode = pReq->info.node; SSdb *pSdb = pMnode->pSdb; SStbObj *pStb = NULL; - int32_t numOfRows = 0; + + buildWhichDBs = determineBuildColForWhichDBs(pShow->db); + if (!pShow->sysDbRsp) { - numOfRows = buildSysDbColsInfo(pBlock, pShow->db, pShow->filterTb); + numOfRows = buildSysDbColsInfo(pBlock, buildWhichDBs, pShow->filterTb); mDebug("mndRetrieveStbCol get system table cols, rows:%d, db:%s", numOfRows, pShow->db); pShow->sysDbRsp = true; } - SDbObj *pDb = NULL; - if (strlen(pShow->db) > 0) { - pDb = mndAcquireDb(pMnode, pShow->db); - if (pDb == NULL) return terrno; - } - - char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_TO_VARSTR(typeName, "SUPER_TABLE"); - bool fetch = pShow->restore ? false : true; - pShow->restore = false; - while (numOfRows < rows) { - if (fetch) { - pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb); - if (pShow->pIter == NULL) break; - } else { - fetch = true; - void *pKey = taosHashGetKey(pShow->pIter, NULL); - pStb = sdbAcquire(pSdb, SDB_STB, pKey); - if (!pStb) continue; + if (buildWhichDBs & BUILD_COL_FOR_USER_DB) { + SDbObj *pDb = NULL; + if (strlen(pShow->db) > 0) { + pDb = mndAcquireDb(pMnode, pShow->db); + if (pDb == NULL && TSDB_CODE_MND_DB_NOT_EXIST != terrno && pBlock->info.rows == 0) return terrno; } - if (pDb != NULL && pStb->dbUid != pDb->uid) { - sdbRelease(pSdb, pStb); - continue; - } - - SName name = {0}; - char stbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - mndExtractTbNameFromStbFullName(pStb->name, &stbName[VARSTR_HEADER_SIZE], TSDB_TABLE_NAME_LEN); - if (pShow->filterTb[0] && strncmp(pShow->filterTb, &stbName[VARSTR_HEADER_SIZE], TSDB_TABLE_NAME_LEN) != 0) { - sdbRelease(pSdb, pStb); - continue; - } - - if ((numOfRows + pStb->numOfColumns) > rows) { - pShow->restore = true; - if (numOfRows == 0) { - mError("mndRetrieveStbCol failed to get stable cols since buf:%d less than result:%d, stable name:%s, db:%s", - rows, pStb->numOfColumns, pStb->name, pStb->db); + char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(typeName, "SUPER_TABLE"); + bool fetch = pShow->restore ? false : true; + pShow->restore = false; + while (numOfRows < rows) { + if (fetch) { + pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb); + if (pShow->pIter == NULL) break; + } else { + fetch = true; + void *pKey = taosHashGetKey(pShow->pIter, NULL); + pStb = sdbAcquire(pSdb, SDB_STB, pKey); + if (!pStb) continue; } - sdbRelease(pSdb, pStb); - break; - } - varDataSetLen(stbName, strlen(&stbName[VARSTR_HEADER_SIZE])); - - mDebug("mndRetrieveStbCol get stable cols, stable name:%s, db:%s", pStb->name, pStb->db); - - char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - tNameFromString(&name, pStb->db, T_NAME_ACCT | T_NAME_DB); - tNameGetDbName(&name, varDataVal(db)); - varDataSetLen(db, strlen(varDataVal(db))); - - for (int i = 0; i < pStb->numOfColumns; i++) { - int32_t cols = 0; - SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)stbName, false); - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)db, false); - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, typeName, false); - - // col name - char colName[TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_TO_VARSTR(colName, pStb->pColumns[i].name); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, colName, false); - - // col type - int8_t colType = pStb->pColumns[i].type; - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - char colTypeStr[VARSTR_HEADER_SIZE + 32]; - int colTypeLen = sprintf(varDataVal(colTypeStr), "%s", tDataTypes[colType].name); - if (colType == TSDB_DATA_TYPE_VARCHAR) { - colTypeLen += sprintf(varDataVal(colTypeStr) + colTypeLen, "(%d)", - (int32_t)(pStb->pColumns[i].bytes - VARSTR_HEADER_SIZE)); - } else if (colType == TSDB_DATA_TYPE_NCHAR) { - colTypeLen += sprintf(varDataVal(colTypeStr) + colTypeLen, "(%d)", - (int32_t)((pStb->pColumns[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)); + if (pDb != NULL && pStb->dbUid != pDb->uid) { + sdbRelease(pSdb, pStb); + continue; } - varDataSetLen(colTypeStr, colTypeLen); - colDataSetVal(pColInfo, numOfRows, (char *)colTypeStr, false); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->pColumns[i].bytes, false); - while (cols < pShow->numOfColumns) { + SName name = {0}; + char stbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + mndExtractTbNameFromStbFullName(pStb->name, &stbName[VARSTR_HEADER_SIZE], TSDB_TABLE_NAME_LEN); + if (pShow->filterTb[0] && strncmp(pShow->filterTb, &stbName[VARSTR_HEADER_SIZE], TSDB_TABLE_NAME_LEN) != 0) { + sdbRelease(pSdb, pStb); + continue; + } + + if ((numOfRows + pStb->numOfColumns) > rows) { + pShow->restore = true; + if (numOfRows == 0) { + mError("mndRetrieveStbCol failed to get stable cols since buf:%d less than result:%d, stable name:%s, db:%s", + rows, pStb->numOfColumns, pStb->name, pStb->db); + } + sdbRelease(pSdb, pStb); + break; + } + + varDataSetLen(stbName, strlen(&stbName[VARSTR_HEADER_SIZE])); + + mDebug("mndRetrieveStbCol get stable cols, stable name:%s, db:%s", pStb->name, pStb->db); + + char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + tNameFromString(&name, pStb->db, T_NAME_ACCT | T_NAME_DB); + tNameGetDbName(&name, varDataVal(db)); + varDataSetLen(db, strlen(varDataVal(db))); + + for (int i = 0; i < pStb->numOfColumns; i++) { + int32_t cols = 0; + SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataSetVal(pColInfo, numOfRows, (const char *)stbName, false); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataSetNULL(pColInfo, numOfRows); + colDataSetVal(pColInfo, numOfRows, (const char *)db, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataSetVal(pColInfo, numOfRows, typeName, false); + + // col name + char colName[TSDB_COL_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(colName, pStb->pColumns[i].name); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataSetVal(pColInfo, numOfRows, colName, false); + + // col type + int8_t colType = pStb->pColumns[i].type; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + char colTypeStr[VARSTR_HEADER_SIZE + 32]; + int colTypeLen = sprintf(varDataVal(colTypeStr), "%s", tDataTypes[colType].name); + if (colType == TSDB_DATA_TYPE_VARCHAR) { + colTypeLen += sprintf(varDataVal(colTypeStr) + colTypeLen, "(%d)", + (int32_t)(pStb->pColumns[i].bytes - VARSTR_HEADER_SIZE)); + } else if (colType == TSDB_DATA_TYPE_NCHAR) { + colTypeLen += sprintf(varDataVal(colTypeStr) + colTypeLen, "(%d)", + (int32_t)((pStb->pColumns[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)); + } + varDataSetLen(colTypeStr, colTypeLen); + colDataSetVal(pColInfo, numOfRows, (char *)colTypeStr, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataSetVal(pColInfo, numOfRows, (const char *)&pStb->pColumns[i].bytes, false); + while (cols < pShow->numOfColumns) { + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataSetNULL(pColInfo, numOfRows); + } + numOfRows++; } - numOfRows++; + + sdbRelease(pSdb, pStb); } - sdbRelease(pSdb, pStb); - } - - if (pDb != NULL) { - mndReleaseDb(pMnode, pDb); + if (pDb != NULL) { + mndReleaseDb(pMnode, pDb); + } } pShow->numOfRows += numOfRows; diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 306a6cbdd9..cce57c4510 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -28,6 +28,7 @@ #include "parser.h" #include "tmisce.h" #include "tname.h" +#include "audit.h" #define MND_STREAM_VER_NUMBER 3 #define MND_STREAM_RESERVE_SIZE 64 @@ -872,6 +873,20 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) { code = TSDB_CODE_ACTION_IN_PROGRESS; + char detail[2000] = {0}; + sprintf(detail, "checkpointFreq:%" PRId64 ", createStb:%d, deleteMark:%" PRId64 ", " + "fillHistory:%d, igExists:%d, " + "igExpired:%d, igUpdate:%d, lastTs:%" PRId64 ", " + "maxDelay:%" PRId64 ", numOfTags:%d, sourceDB:%s, " + "targetStbFullName:%s, triggerType:%d, watermark:%" PRId64, + createStreamReq.checkpointFreq, createStreamReq.createStb, createStreamReq.deleteMark, + createStreamReq.fillHistory, createStreamReq.igExists, + createStreamReq.igExpired, createStreamReq.igUpdate, createStreamReq.lastTs, + createStreamReq.maxDelay, createStreamReq.numOfTags, createStreamReq.sourceDB, + createStreamReq.targetStbFullName, createStreamReq.triggerType, createStreamReq.watermark); + + auditRecord(pReq, pMnode->clusterId, "createStream", createStreamReq.name, "", detail); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("stream:%s, failed to create since %s", createStreamReq.name, terrstr()); @@ -1301,6 +1316,11 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { return -1; } + char detail[100] = {0}; + sprintf(detail, "igNotExists:%d", dropReq.igNotExists); + + auditRecord(pReq, pMnode->clusterId, "dropStream", dropReq.name, "", detail); + sdbRelease(pMnode->pSdb, pStream); mndTransDrop(pTrans); diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index d62b9e4174..c756341164 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -553,13 +553,17 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu } } - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pMsg, "tmq-reb"); + char topic[TSDB_TOPIC_FNAME_LEN] = {0}; + char cgroup[TSDB_CGROUP_LEN] = {0}; + mndSplitSubscribeKey(pOutput->pSub->key, topic, cgroup, true); + + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_TOPIC_INSIDE, pMsg, "tmq-reb"); if (pTrans == NULL) { nodesDestroyNode((SNode*)pPlan); return -1; } - mndTransSetDbName(pTrans, pOutput->pSub->dbName, NULL); + mndTransSetDbName(pTrans, topic, cgroup); if (mndTransCheckConflict(pMnode, pTrans) != 0) { mndTransDrop(pTrans); nodesDestroyNode((SNode*)pPlan); @@ -587,10 +591,6 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu return -1; } - char topic[TSDB_TOPIC_FNAME_LEN] = {0}; - char cgroup[TSDB_CGROUP_LEN] = {0}; - mndSplitSubscribeKey(pOutput->pSub->key, topic, cgroup, true); - // 3. commit log: consumer to update status and epoch // 3.1 set touched consumer int32_t consumerNum = taosArrayGetSize(pOutput->modifyConsumers); @@ -802,6 +802,19 @@ static int32_t mndProcessDropCgroupReq(SRpcMsg *pMsg) { goto end; } + pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_TOPIC_INSIDE, pMsg, "drop-cgroup"); + if (pTrans == NULL) { + mError("cgroup: %s on topic:%s, failed to drop since %s", dropReq.cgroup, dropReq.topic, terrstr()); + code = -1; + goto end; + } + + mndTransSetDbName(pTrans, dropReq.topic, dropReq.cgroup); + code = mndTransCheckConflict(pMnode, pTrans); + if (code != 0) { + goto end; + } + void *pIter = NULL; SMqConsumerObj *pConsumer; while (1) { @@ -811,18 +824,11 @@ static int32_t mndProcessDropCgroupReq(SRpcMsg *pMsg) { } if (strcmp(dropReq.cgroup, pConsumer->cgroup) == 0) { - mndDropConsumerFromSdb(pMnode, pConsumer->consumerId); + mndDropConsumerFromSdb(pMnode, pConsumer->consumerId, &pMsg->info); } sdbRelease(pMnode->pSdb, pConsumer); } - pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "drop-cgroup"); - if (pTrans == NULL) { - mError("cgroup: %s on topic:%s, failed to drop since %s", dropReq.cgroup, dropReq.topic, terrstr()); - code = -1; - goto end; - } - mInfo("trans:%d, used to drop cgroup:%s on topic %s", pTrans->id, dropReq.cgroup, dropReq.topic); if (mndSetDropSubCommitLogs(pMnode, pTrans, pSub) < 0) { @@ -1019,8 +1025,8 @@ int32_t mndGetGroupNumByTopic(SMnode *pMnode, const char *topicName) { if (pIter == NULL) break; - char topic[TSDB_TOPIC_FNAME_LEN]; - char cgroup[TSDB_CGROUP_LEN]; + char topic[TSDB_TOPIC_FNAME_LEN] = {0}; + char cgroup[TSDB_CGROUP_LEN] = {0}; mndSplitSubscribeKey(pSub->key, topic, cgroup, true); if (strcmp(topic, topicName) != 0) { sdbRelease(pSdb, pSub); @@ -1084,7 +1090,6 @@ int32_t mndDropSubByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { } int32_t mndDropSubByTopic(SMnode *pMnode, STrans *pTrans, const char *topicName) { - int32_t code = -1; SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; @@ -1093,8 +1098,8 @@ int32_t mndDropSubByTopic(SMnode *pMnode, STrans *pTrans, const char *topicName) pIter = sdbFetch(pSdb, SDB_SUBSCRIBE, pIter, (void **)&pSub); if (pIter == NULL) break; - char topic[TSDB_TOPIC_FNAME_LEN]; - char cgroup[TSDB_CGROUP_LEN]; + char topic[TSDB_TOPIC_FNAME_LEN] = {0}; + char cgroup[TSDB_CGROUP_LEN] = {0}; mndSplitSubscribeKey(pSub->key, topic, cgroup, true); if (strcmp(topic, topicName) != 0) { sdbRelease(pSdb, pSub); @@ -1132,15 +1137,13 @@ int32_t mndDropSubByTopic(SMnode *pMnode, STrans *pTrans, const char *topicName) if (mndSetDropSubRedoLogs(pMnode, pTrans, pSub) < 0) { sdbRelease(pSdb, pSub); sdbCancelFetch(pSdb, pIter); - goto END; + return -1; } sdbRelease(pSdb, pSub); } - code = 0; -END: - return code; + return 0; } static int32_t buildResult(SSDataBlock *pBlock, int32_t* numOfRows, int64_t consumerId, const char* topic, const char* cgroup, SArray* vgs, SArray *offsetRows){ diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 6250a3dd71..1e3a8bddb7 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -27,6 +27,7 @@ #include "mndVgroup.h" #include "parser.h" #include "tname.h" +#include "audit.h" #define MND_TOPIC_VER_NUMBER 3 #define MND_TOPIC_RESERVE_SIZE 64 @@ -381,14 +382,29 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * int32_t code = -1; SNode *pAst = NULL; SQueryPlan *pPlan = NULL; - SMqTopicObj topicObj = {0}; + + pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_TOPIC, pReq, "create-topic"); + if (pTrans == NULL) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + code = -1; + goto _OUT; + } + + mndTransSetDbName(pTrans, pCreate->name, NULL); + code = mndTransCheckConflict(pMnode, pTrans); + if (code != 0) { + goto _OUT; + } + mInfo("trans:%d to create topic:%s", pTrans->id, pCreate->name); + tstrncpy(topicObj.name, pCreate->name, TSDB_TOPIC_FNAME_LEN); tstrncpy(topicObj.db, pDb->name, TSDB_DB_FNAME_LEN); tstrncpy(topicObj.createUser, userName, TSDB_USER_LEN); - if (mndCheckTopicPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_TOPIC, &topicObj) != 0) { - return -1; + code = mndCheckTopicPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_TOPIC, &topicObj); + if (code != 0) { + goto _OUT; } topicObj.createTime = taosGetTimestampMs(); @@ -405,6 +421,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * if (pCreate->withMeta) { terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION; mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + code = terrno; goto _OUT; } @@ -413,13 +430,15 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * qDebugL("topic:%s ast %s", topicObj.name, topicObj.ast); - if (nodesStringToNode(pCreate->ast, &pAst) != 0) { + code = nodesStringToNode(pCreate->ast, &pAst); + if (code != 0) { mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); goto _OUT; } SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true}; - if (qCreateQueryPlan(&cxt, &pPlan, NULL) != 0) { + code = qCreateQueryPlan(&cxt, &pPlan, NULL); + if (code != 0) { mError("failed to create topic:%s since %s", pCreate->name, terrstr()); goto _OUT; } @@ -427,6 +446,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * topicObj.ntbColIds = taosArrayInit(0, sizeof(int16_t)); if (topicObj.ntbColIds == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OUT; } @@ -437,12 +457,14 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * topicObj.ntbColIds = NULL; } - if (qExtractResultSchema(pAst, &topicObj.schema.nCols, &topicObj.schema.pSchema) != 0) { + code = qExtractResultSchema(pAst, &topicObj.schema.nCols, &topicObj.schema.pSchema); + if (code != 0) { mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); goto _OUT; } - if (nodesNodeToString((SNode *)pPlan, false, &topicObj.physicalPlan, NULL) != 0) { + code = nodesNodeToString((SNode *)pPlan, false, &topicObj.physicalPlan, NULL); + if (code != 0) { mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); goto _OUT; } @@ -450,6 +472,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * SStbObj *pStb = mndAcquireStb(pMnode, pCreate->subStbName); if (pStb == NULL) { terrno = TSDB_CODE_MND_STB_NOT_EXIST; + code = terrno; goto _OUT; } @@ -469,21 +492,10 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * /*topicObj.withTbName = 1;*/ /*topicObj.withSchema = 1;*/ - pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq, "create-topic"); - if (pTrans == NULL) { - mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); - goto _OUT; - } - - mndTransSetDbName(pTrans, pDb->name, NULL); - if (mndTransCheckConflict(pMnode, pTrans) != 0) { - goto _OUT; - } - mInfo("trans:%d to create topic:%s", pTrans->id, pCreate->name); - SSdbRaw *pCommitRaw = mndTopicActionEncode(&topicObj); if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); + code = -1; goto _OUT; } @@ -509,7 +521,6 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * // encoder check alter info int32_t len; - int32_t code; tEncodeSize(tEncodeSTqCheckInfo, &info, len, code); if (code < 0) { sdbRelease(pSdb, pVgroup); @@ -524,6 +535,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * taosMemoryFree(buf); sdbRelease(pSdb, pVgroup); sdbCancelFetch(pSdb, pIter); + code = -1; goto _OUT; } tEncoderClear(&encoder); @@ -538,6 +550,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * taosMemoryFree(buf); sdbRelease(pSdb, pVgroup); sdbCancelFetch(pSdb, pIter); + code = -1; goto _OUT; } buf = NULL; @@ -547,6 +560,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + code = -1; goto _OUT; } @@ -621,6 +635,15 @@ static int32_t mndProcessCreateTopicReq(SRpcMsg *pReq) { code = TSDB_CODE_ACTION_IN_PROGRESS; } + char detail[1000] = {0}; + sprintf(detail, "igExists:%d, subStbName:%s, subType:%d, withMeta:%d", + createTopicReq.igExists, createTopicReq.subStbName, createTopicReq.subType, createTopicReq.withMeta); + + SName name = {0}; + tNameFromString(&name, createTopicReq.subDbName, T_NAME_ACCT | T_NAME_DB); + + auditRecord(pReq, pMnode->clusterId, "crateTopic", createTopicReq.name, name.dbname, detail); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("failed to create topic:%s since %s", createTopicReq.name, terrstr()); @@ -654,16 +677,19 @@ _OVER: } static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) { - SMnode *pMnode = pReq->info.node; - SSdb *pSdb = pMnode->pSdb; + SMnode *pMnode = pReq->info.node; + SSdb *pSdb = pMnode->pSdb; SMDropTopicReq dropReq = {0}; + int32_t code = 0; + SMqTopicObj *pTopic = NULL; + STrans *pTrans = NULL; if (tDeserializeSMDropTopicReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { terrno = TSDB_CODE_INVALID_MSG; return -1; } - SMqTopicObj *pTopic = mndAcquireTopic(pMnode, dropReq.name); + pTopic = mndAcquireTopic(pMnode, dropReq.name); if (pTopic == NULL) { if (dropReq.igNotExists) { mInfo("topic:%s, not exist, ignore not exist is set", dropReq.name); @@ -675,9 +701,29 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) { } } - if (mndCheckTopicPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_TOPIC, pTopic) != 0) { - mndReleaseTopic(pMnode, pTopic); - return -1; + pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_TOPIC, pReq, "drop-topic"); + if (pTrans == NULL) { + mError("topic:%s, failed to drop since %s", pTopic->name, terrstr()); + code = -1; + goto end; + } + + mndTransSetDbName(pTrans, pTopic->name, NULL); + code = mndTransCheckConflict(pMnode, pTrans); + if (code != 0) { + goto end; + } + + mInfo("trans:%d, used to drop topic:%s", pTrans->id, pTopic->name); + + code = mndCheckTopicPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_TOPIC, pTopic); + if (code != 0) { + goto end; + } + + code = mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_READ_DB, pTopic->db); + if (code != 0) { + goto end; } void *pIter = NULL; @@ -688,37 +734,42 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) { break; } - if (pConsumer->status == MQ_CONSUMER_STATUS_LOST){ - mndDropConsumerFromSdb(pMnode, pConsumer->consumerId); - mndReleaseConsumer(pMnode, pConsumer); - continue; - } - + bool found = false; int32_t sz = taosArrayGetSize(pConsumer->assignedTopics); for (int32_t i = 0; i < sz; i++) { char *name = taosArrayGetP(pConsumer->assignedTopics, i); if (strcmp(name, pTopic->name) == 0) { - mndReleaseConsumer(pMnode, pConsumer); - mndReleaseTopic(pMnode, pTopic); - sdbCancelFetch(pSdb, pIter); - terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED; - mError("topic:%s, failed to drop since subscribed by consumer:0x%" PRIx64 ", in consumer group %s", - dropReq.name, pConsumer->consumerId, pConsumer->cgroup); - return -1; + found = true; + break; } } + if (found){ + if (pConsumer->status == MQ_CONSUMER_STATUS_LOST) { + mndDropConsumerFromSdb(pMnode, pConsumer->consumerId, &pReq->info); + mndReleaseConsumer(pMnode, pConsumer); + continue; + } + + mndReleaseConsumer(pMnode, pConsumer); + sdbCancelFetch(pSdb, pIter); + terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED; + mError("topic:%s, failed to drop since subscribed by consumer:0x%" PRIx64 ", in consumer group %s", + dropReq.name, pConsumer->consumerId, pConsumer->cgroup); + code = -1; + goto end; + } sz = taosArrayGetSize(pConsumer->rebNewTopics); for (int32_t i = 0; i < sz; i++) { char *name = taosArrayGetP(pConsumer->rebNewTopics, i); if (strcmp(name, pTopic->name) == 0) { mndReleaseConsumer(pMnode, pConsumer); - mndReleaseTopic(pMnode, pTopic); sdbCancelFetch(pSdb, pIter); terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED; mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb new)", dropReq.name, pConsumer->consumerId, pConsumer->cgroup); - return -1; + code = -1; + goto end; } } @@ -727,45 +778,22 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) { char *name = taosArrayGetP(pConsumer->rebRemovedTopics, i); if (strcmp(name, pTopic->name) == 0) { mndReleaseConsumer(pMnode, pConsumer); - mndReleaseTopic(pMnode, pTopic); sdbCancelFetch(pSdb, pIter); terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED; mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb remove)", dropReq.name, pConsumer->consumerId, pConsumer->cgroup); - return -1; + code = -1; + goto end; } } sdbRelease(pSdb, pConsumer); } - if (mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_READ_DB, pTopic->db) != 0) { - mndReleaseTopic(pMnode, pTopic); - return -1; - } - - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq, "drop-topic"); - if (pTrans == NULL) { + code = mndDropSubByTopic(pMnode, pTrans, dropReq.name); + if (code < 0) { mError("topic:%s, failed to drop since %s", pTopic->name, terrstr()); - mndReleaseTopic(pMnode, pTopic); - return -1; - } - - mndTransSetDbName(pTrans, pTopic->db, NULL); - if (mndTransCheckConflict(pMnode, pTrans) != 0) { - mndReleaseTopic(pMnode, pTopic); - mndTransDrop(pTrans); - return -1; - } - - mInfo("trans:%d, used to drop topic:%s", pTrans->id, pTopic->name); - - // TODO check if rebalancing - if (mndDropSubByTopic(pMnode, pTrans, dropReq.name) < 0) { - mError("topic:%s, failed to drop since %s", pTopic->name, terrstr()); - mndTransDrop(pTrans); - mndReleaseTopic(pMnode, pTopic); - return -1; + goto end; } if (pTopic->ntbUid != 0) { @@ -791,27 +819,32 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) { action.pCont = buf; action.contLen = sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN; action.msgType = TDMT_VND_TMQ_DEL_CHECKINFO; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { + code = mndTransAppendRedoAction(pTrans, &action); + if (code != 0) { taosMemoryFree(buf); sdbRelease(pSdb, pVgroup); - mndReleaseTopic(pMnode, pTopic); sdbCancelFetch(pSdb, pIter); - mndTransDrop(pTrans); - return -1; + goto end; } sdbRelease(pSdb, pVgroup); } } - int32_t code = mndDropTopic(pMnode, pTrans, pReq, pTopic); + code = mndDropTopic(pMnode, pTrans, pReq, pTopic); + +end: mndReleaseTopic(pMnode, pTopic); mndTransDrop(pTrans); - if (code != 0) { mError("topic:%s, failed to drop since %s", dropReq.name, terrstr()); - return -1; + return code; } + char detail[100] = {0}; + sprintf(detail, "igNotExists:%d", dropReq.igNotExists); + + auditRecord(pReq, pMnode->clusterId, "dropTopic", dropReq.name, "", detail); + return TSDB_CODE_ACTION_IN_PROGRESS; } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 3fc249cead..5d150b731c 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -790,6 +790,22 @@ static bool mndCheckTransConflict(SMnode *pMnode, STrans *pNew) { } } + if (pNew->conflict == TRN_CONFLICT_TOPIC) { + if (pTrans->conflict == TRN_CONFLICT_GLOBAL) conflict = true; + if (pTrans->conflict == TRN_CONFLICT_TOPIC || pTrans->conflict == TRN_CONFLICT_TOPIC_INSIDE) { + if (strcasecmp(pNew->dbname, pTrans->dbname) == 0 ) conflict = true; + } + } + if (pNew->conflict == TRN_CONFLICT_TOPIC_INSIDE) { + if (pTrans->conflict == TRN_CONFLICT_GLOBAL) conflict = true; + if (pTrans->conflict == TRN_CONFLICT_TOPIC ) { + if (strcasecmp(pNew->dbname, pTrans->dbname) == 0 ) conflict = true; + } + if (pTrans->conflict == TRN_CONFLICT_TOPIC_INSIDE) { + if (strcasecmp(pNew->dbname, pTrans->dbname) == 0 && strcasecmp(pNew->stbname, pTrans->stbname) == 0) conflict = true; + } + } + if (conflict) { mError("trans:%d, db:%s stb:%s type:%d, can't execute since conflict with trans:%d db:%s stb:%s type:%d", pNew->id, pNew->dbname, pNew->stbname, pNew->conflict, pTrans->id, pTrans->dbname, pTrans->stbname, diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index c59d23d252..42a3ba8904 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -22,6 +22,7 @@ #include "mndTopic.h" #include "mndTrans.h" #include "tbase64.h" +#include "audit.h" #define USER_VER_NUMBER 4 #define USER_RESERVE_SIZE 64 @@ -655,6 +656,12 @@ static int32_t mndProcessCreateUserReq(SRpcMsg *pReq) { code = mndCreateUser(pMnode, pOperUser->acct, &createReq, pReq); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char detail[1000] = {0}; + sprintf(detail, "createType:%d, enable:%d, superUser:%d, sysInfo:%d", + createReq.createType, createReq.enable, createReq.superUser, createReq.sysInfo); + + auditRecord(pReq, pMnode->clusterId, "createUser", createReq.user, "", detail); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("user:%s, failed to create since %s", createReq.user, terrstr()); @@ -970,6 +977,48 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) { code = mndAlterUser(pMnode, pUser, &newUser, pReq); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char detail[1000] = {0}; + sprintf(detail, "alterType:%d, enable:%d, superUser:%d, sysInfo:%d, tabName:%s", + alterReq.alterType, alterReq.enable, alterReq.superUser, alterReq.sysInfo, alterReq.tabName); + + if(alterReq.alterType == TSDB_ALTER_USER_PASSWD){ + auditRecord(pReq, pMnode->clusterId, "changePassword", alterReq.user, "", detail); + } + else if(alterReq.alterType == TSDB_ALTER_USER_SUPERUSER || + alterReq.alterType == TSDB_ALTER_USER_ENABLE || + alterReq.alterType == TSDB_ALTER_USER_SYSINFO){ + auditRecord(pReq, pMnode->clusterId, "alterUser", alterReq.user, "", detail); + } + else if(alterReq.alterType == TSDB_ALTER_USER_ADD_READ_DB|| + alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_DB|| + alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_DB|| + alterReq.alterType == TSDB_ALTER_USER_ADD_READ_TABLE|| + alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_TABLE|| + alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_TABLE){ + if (strcmp(alterReq.objname, "1.*") != 0){ + SName name = {0}; + tNameFromString(&name, alterReq.objname, T_NAME_ACCT | T_NAME_DB); + auditRecord(pReq, pMnode->clusterId, "GrantPrivileges", alterReq.user, name.dbname, detail); + }else{ + auditRecord(pReq, pMnode->clusterId, "GrantPrivileges", alterReq.user, "*", detail); + } + } + else if(alterReq.alterType == TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC){ + auditRecord(pReq, pMnode->clusterId, "GrantPrivileges", alterReq.user, alterReq.objname, detail); + } + else if(alterReq.alterType == TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC){ + auditRecord(pReq, pMnode->clusterId, "RevokePrivileges", alterReq.user, alterReq.objname, detail); + } + else{ + if (strcmp(alterReq.objname, "1.*") != 0){ + SName name = {0}; + tNameFromString(&name, alterReq.objname, T_NAME_ACCT | T_NAME_DB); + auditRecord(pReq, pMnode->clusterId, "RevokePrivileges", alterReq.user, name.dbname, detail); + }else{ + auditRecord(pReq, pMnode->clusterId, "RevokePrivileges", alterReq.user, "*", detail); + } + } + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("user:%s, failed to alter since %s", alterReq.user, terrstr()); @@ -1039,6 +1088,8 @@ static int32_t mndProcessDropUserReq(SRpcMsg *pReq) { code = mndDropUser(pMnode, pReq, pUser); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + auditRecord(pReq, pMnode->clusterId, "dropUser", dropReq.user, "", ""); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("user:%s, failed to drop since %s", dropReq.user, terrstr()); diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 26dc2a3f87..d819b71f18 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -26,6 +26,7 @@ #include "mndTrans.h" #include "mndUser.h" #include "tmisce.h" +#include "audit.h" #define VGROUP_VER_NUMBER 1 #define VGROUP_RESERVE_SIZE 64 @@ -1090,7 +1091,7 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB int32_t cols = 0; int64_t curMs = taosGetTimestampMs(); - while (numOfRows < rows) { + while (numOfRows < rows - TSDB_MAX_REPLICA) { pShow->pIter = sdbFetch(pSdb, SDB_VGROUP, pShow->pIter, (void **)&pVgroup); if (pShow->pIter == NULL) break; @@ -2171,6 +2172,15 @@ static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq) { if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + char obj[33] = {0}; + sprintf(obj, "%d", req.vgId); + + char detail[1000] = {0}; + sprintf(detail, "dnodeId1:%d, dnodeId2:%d, dnodeId3:%d", + req.dnodeId1, req.dnodeId2, req.dnodeId3); + + auditRecord(pReq, pMnode->clusterId, "RedistributeVgroup", obj, "", detail); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("vgId:%d, failed to redistribute to dnode %d:%d:%d since %s", req.vgId, req.dnodeId1, req.dnodeId2, @@ -2981,6 +2991,8 @@ static int32_t mndProcessBalanceVgroupMsg(SRpcMsg *pReq) { code = mndBalanceVgroup(pMnode, pReq, pArray); } + auditRecord(pReq, pMnode->clusterId, "balanceVgroup", "", "", ""); + _OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("failed to balance vgroup since %s", terrstr()); diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 6b460feb2c..6c5eeb3424 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -150,6 +150,7 @@ target_link_libraries( PUBLIC executor PUBLIC scheduler PUBLIC tdb + PUBLIC audit # PUBLIC bdb # PUBLIC scalar diff --git a/source/dnode/vnode/src/inc/metaTtl.h b/source/dnode/vnode/src/inc/metaTtl.h index c2cd389dab..ead2d89b28 100644 --- a/source/dnode/vnode/src/inc/metaTtl.h +++ b/source/dnode/vnode/src/inc/metaTtl.h @@ -26,7 +26,7 @@ extern "C" { #endif typedef enum DirtyEntryType { - ENTRY_TYPE_DEL = 1, + ENTRY_TYPE_DELETE = 1, ENTRY_TYPE_UPSERT = 2, } DirtyEntryType; @@ -44,6 +44,8 @@ typedef struct STtlManger { typedef struct { int64_t ttlDays; int64_t changeTimeMs; + int64_t ttlDaysDirty; + int64_t changeTimeMsDirty; } STtlCacheEntry; typedef struct { diff --git a/source/dnode/vnode/src/meta/metaTtl.c b/source/dnode/vnode/src/meta/metaTtl.c index 3c45982311..f920296b4a 100644 --- a/source/dnode/vnode/src/meta/metaTtl.c +++ b/source/dnode/vnode/src/meta/metaTtl.c @@ -209,7 +209,8 @@ static int32_t ttlMgrFillCacheOneEntry(const void *pKey, int keyLen, const void int64_t ttlDays = *(int64_t *)pVal; int64_t changeTimeMs = ttlKey->deleteTimeMs - ttlDays * tsTtlUnit * 1000; - STtlCacheEntry data = {.ttlDays = ttlDays, .changeTimeMs = changeTimeMs}; + STtlCacheEntry data = { + .ttlDays = ttlDays, .changeTimeMs = changeTimeMs, .ttlDaysDirty = ttlDays, .changeTimeMsDirty = changeTimeMs}; return taosHashPut(pCache, &uid, sizeof(uid), &data, sizeof(data)); } @@ -257,34 +258,37 @@ static int32_t ttlMgrFindExpiredOneEntry(const void *pKey, int keyLen, const voi static int ttlMgrConvert(TTB *pOldTtlIdx, TTB *pNewTtlIdx, void *pMeta) { SMeta *meta = pMeta; - metaInfo("ttlMgr convert ttl start."); + metaInfo("ttlMgr convert start."); SConvertData cvData = {.pNewTtlIdx = pNewTtlIdx, .pMeta = meta}; int ret = tdbTbTraversal(pOldTtlIdx, &cvData, ttlMgrConvertOneEntry); if (ret < 0) { - metaError("failed to convert ttl since %s", tstrerror(terrno)); + metaError("failed to convert since %s", tstrerror(terrno)); } - metaInfo("ttlMgr convert ttl end."); + metaInfo("ttlMgr convert end."); return ret; } int ttlMgrInsertTtl(STtlManger *pTtlMgr, const STtlUpdTtlCtx *updCtx) { if (updCtx->ttlDays == 0) return 0; - STtlCacheEntry cacheEntry = {.ttlDays = updCtx->ttlDays, .changeTimeMs = updCtx->changeTimeMs}; + STtlCacheEntry cacheEntry = {.ttlDays = updCtx->ttlDays, + .changeTimeMs = updCtx->changeTimeMs, + .ttlDaysDirty = updCtx->ttlDays, + .changeTimeMsDirty = updCtx->changeTimeMs}; STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_UPSERT}; int ret = taosHashPut(pTtlMgr->pTtlCache, &updCtx->uid, sizeof(updCtx->uid), &cacheEntry, sizeof(cacheEntry)); if (ret < 0) { - metaError("%s, ttlMgr insert failed to update ttl cache since %s", pTtlMgr->logPrefix, tstrerror(terrno)); + metaError("%s, ttlMgr insert failed to update cache since %s", pTtlMgr->logPrefix, tstrerror(terrno)); goto _out; } ret = taosHashPut(pTtlMgr->pDirtyUids, &updCtx->uid, sizeof(updCtx->uid), &dirtryEntry, sizeof(dirtryEntry)); if (ret < 0) { - metaError("%s, ttlMgr insert failed to update ttl dirty uids since %s", pTtlMgr->logPrefix, tstrerror(terrno)); + metaError("%s, ttlMgr insert failed to update dirty uids since %s", pTtlMgr->logPrefix, tstrerror(terrno)); goto _out; } @@ -304,11 +308,11 @@ _out: int ttlMgrDeleteTtl(STtlManger *pTtlMgr, const STtlDelTtlCtx *delCtx) { if (delCtx->ttlDays == 0) return 0; - STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_DEL}; + STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_DELETE}; int ret = taosHashPut(pTtlMgr->pDirtyUids, &delCtx->uid, sizeof(delCtx->uid), &dirtryEntry, sizeof(dirtryEntry)); if (ret < 0) { - metaError("%s, ttlMgr del failed to update ttl dirty uids since %s", pTtlMgr->logPrefix, tstrerror(terrno)); + metaError("%s, ttlMgr del failed to update dirty uids since %s", pTtlMgr->logPrefix, tstrerror(terrno)); goto _out; } @@ -332,19 +336,22 @@ int ttlMgrUpdateChangeTime(STtlManger *pTtlMgr, const STtlUpdCtimeCtx *pUpdCtime goto _out; } - STtlCacheEntry cacheEntry = {.ttlDays = oldData->ttlDays, .changeTimeMs = pUpdCtimeCtx->changeTimeMs}; + STtlCacheEntry cacheEntry = {.ttlDays = oldData->ttlDays, + .changeTimeMs = oldData->changeTimeMs, + .ttlDaysDirty = oldData->ttlDays, + .changeTimeMsDirty = pUpdCtimeCtx->changeTimeMs}; STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_UPSERT}; ret = taosHashPut(pTtlMgr->pTtlCache, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid), &cacheEntry, sizeof(cacheEntry)); if (ret < 0) { - metaError("%s, ttlMgr update ctime failed to update ttl cache since %s", pTtlMgr->logPrefix, tstrerror(terrno)); + metaError("%s, ttlMgr update ctime failed to update cache since %s", pTtlMgr->logPrefix, tstrerror(terrno)); goto _out; } ret = taosHashPut(pTtlMgr->pDirtyUids, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid), &dirtryEntry, sizeof(dirtryEntry)); if (ret < 0) { - metaError("%s, ttlMgr update ctime failed to update ttl dirty uids since %s", pTtlMgr->logPrefix, + metaError("%s, ttlMgr update ctime failed to update dirty uids since %s", pTtlMgr->logPrefix, tstrerror(terrno)); goto _out; } @@ -396,27 +403,35 @@ int ttlMgrFlush(STtlManger *pTtlMgr, TXN *pTxn) { STtlIdxKeyV1 ttlKey; ttlMgrBuildKey(&ttlKey, cacheEntry->ttlDays, cacheEntry->changeTimeMs, *pUid); + STtlIdxKeyV1 ttlKeyDirty; + ttlMgrBuildKey(&ttlKeyDirty, cacheEntry->ttlDaysDirty, cacheEntry->changeTimeMsDirty, *pUid); + if (pEntry->type == ENTRY_TYPE_UPSERT) { - ret = tdbTbUpsert(pTtlMgr->pTtlIdx, &ttlKey, sizeof(ttlKey), &cacheEntry->ttlDays, sizeof(cacheEntry->ttlDays), - pTxn); + // delete old key & upsert new key + tdbTbDelete(pTtlMgr->pTtlIdx, &ttlKey, sizeof(ttlKey), pTxn); // maybe first insert, ignore error + ret = tdbTbUpsert(pTtlMgr->pTtlIdx, &ttlKeyDirty, sizeof(ttlKeyDirty), &cacheEntry->ttlDaysDirty, + sizeof(cacheEntry->ttlDaysDirty), pTxn); if (ret < 0) { - metaError("%s, ttlMgr flush failed to flush ttl cache upsert since %s", pTtlMgr->logPrefix, tstrerror(terrno)); + metaError("%s, ttlMgr flush failed to upsert since %s", pTtlMgr->logPrefix, tstrerror(terrno)); goto _out; } - } else if (pEntry->type == ENTRY_TYPE_DEL) { + + cacheEntry->ttlDays = cacheEntry->ttlDaysDirty; + cacheEntry->changeTimeMs = cacheEntry->changeTimeMsDirty; + } else if (pEntry->type == ENTRY_TYPE_DELETE) { ret = tdbTbDelete(pTtlMgr->pTtlIdx, &ttlKey, sizeof(ttlKey), pTxn); if (ret < 0) { - metaError("%s, ttlMgr flush failed to flush ttl cache del since %s", pTtlMgr->logPrefix, tstrerror(terrno)); + metaError("%s, ttlMgr flush failed to delete since %s", pTtlMgr->logPrefix, tstrerror(terrno)); goto _out; } ret = taosHashRemove(pTtlMgr->pTtlCache, pUid, sizeof(*pUid)); if (ret < 0) { - metaError("%s, ttlMgr flush failed to delete ttl cache since %s", pTtlMgr->logPrefix, tstrerror(terrno)); + metaError("%s, ttlMgr flush failed to remove cache since %s", pTtlMgr->logPrefix, tstrerror(terrno)); goto _out; } } else { - metaError("%s, ttlMgr flush failed to flush ttl cache, unknown type: %d", pTtlMgr->logPrefix, pEntry->type); + metaError("%s, ttlMgr flush failed, unknown type: %d", pTtlMgr->logPrefix, pEntry->type); goto _out; } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 000d6e9d5d..9f4a95c8ff 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -666,6 +666,8 @@ int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg walCloseRef(pTq->pVnode->pWal, pHandle->pRef->refId); } + tqUnregisterPushHandle(pTq, pHandle); + code = taosHashRemove(pTq->pHandle, pReq->subKey, strlen(pReq->subKey)); if (code != 0) { tqError("cannot process tq delete req %s, since no such handle", pReq->subKey); @@ -767,20 +769,7 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg tqInfo("vgId:%d switch consumer from Id:0x%" PRIx64 " to Id:0x%" PRIx64, req.vgId, pHandle->consumerId, req.newConsumerId); atomic_store_64(&pHandle->consumerId, req.newConsumerId); - // atomic_add_fetch_32(&pHandle->epoch, 1); - - // kill executing task - // if(tqIsHandleExec(pHandle)) { - // qTaskInfo_t pTaskInfo = pHandle->execHandle.task; - // if (pTaskInfo != NULL) { - // qKillTask(pTaskInfo, TSDB_CODE_SUCCESS); - // } - - // if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { - // qStreamCloseTsdbReader(pTaskInfo); - // } - // } - // remove if it has been register in the push manager, and return one empty block to consumer + atomic_store_32(&pHandle->epoch, 0); tqUnregisterPushHandle(pTq, pHandle); ret = tqMetaSaveHandle(pTq, req.subKey, pHandle); } diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index c15a92cc2e..ec8f2ae35d 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -305,7 +305,7 @@ int32_t extractMsgFromWal(SWalReader* pReader, void** pItem, int64_t maxVer, con } SWalCont* pCont = &pReader->pHead->head; - int64_t ver = pCont->version; + int64_t ver = pCont->version; if (ver > maxVer) { tqDebug("maxVer in WAL:%" PRId64 " reached current:%" PRId64 ", do not scan wal anymore, %s", maxVer, ver, id); return TSDB_CODE_SUCCESS; diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index 8ca2ccad1b..caf88f55fc 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -25,7 +25,7 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* pReader, const int32_t* slotIds, const int32_t* dstSlotIds, void** pRes, const char* idStr) { int32_t numOfRows = pBlock->info.rows; - bool allNullRow = true; + // bool allNullRow = true; if (HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST)) { for (int32_t i = 0; i < pReader->numOfCols; ++i) { @@ -36,7 +36,7 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p p->ts = pColVal->ts; p->isNull = !COL_VAL_IS_VALUE(&pColVal->colVal); - allNullRow = p->isNull & allNullRow; + // allNullRow = p->isNull & allNullRow; if (!p->isNull) { if (IS_VAR_DATA_TYPE(pColVal->colVal.type)) { @@ -56,7 +56,8 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p colDataSetVal(pColInfoData, numOfRows, (const char*)pRes[i], false); } - pBlock->info.rows += allNullRow ? 0 : 1; + // pBlock->info.rows += allNullRow ? 0 : 1; + ++pBlock->info.rows; } else if (HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST_ROW)) { for (int32_t i = 0; i < pReader->numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotIds[i]); @@ -65,7 +66,7 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, i); SColVal* pVal = &pColVal->colVal; - allNullRow = false; + // allNullRow = false; if (IS_VAR_DATA_TYPE(pColVal->colVal.type)) { if (!COL_VAL_IS_VALUE(&pColVal->colVal)) { colDataSetNULL(pColInfoData, numOfRows); @@ -80,7 +81,8 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p } } - pBlock->info.rows += allNullRow ? 0 : 1; + // pBlock->info.rows += allNullRow ? 0 : 1; + ++pBlock->info.rows; } else { tsdbError("invalid retrieve type:%d, %s", pReader->type, idStr); return TSDB_CODE_INVALID_PARA; diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c index afbe895721..d4cb63fb7b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit2.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit2.c @@ -235,36 +235,33 @@ static int32_t tsdbCommitOpenReader(SCommitter2 *committer) { return 0; } - ASSERT(TARRAY2_SIZE(committer->ctx->fset->lvlArr) == 1); + SSttLvl *lvl; + TARRAY2_FOREACH(committer->ctx->fset->lvlArr, lvl) { + STFileObj *fobj = NULL; + TARRAY2_FOREACH(lvl->fobjArr, fobj) { + SSttFileReader *sttReader; - SSttLvl *lvl = TARRAY2_FIRST(committer->ctx->fset->lvlArr); + SSttFileReaderConfig config = { + .tsdb = committer->tsdb, + .szPage = committer->szPage, + .file = fobj->f[0], + }; - ASSERT(lvl->level == 0); + code = tsdbSttFileReaderOpen(fobj->fname, &config, &sttReader); + TSDB_CHECK_CODE(code, lino, _exit); - STFileObj *fobj = NULL; - TARRAY2_FOREACH(lvl->fobjArr, fobj) { - SSttFileReader *sttReader; + code = TARRAY2_APPEND(committer->sttReaderArray, sttReader); + TSDB_CHECK_CODE(code, lino, _exit); - SSttFileReaderConfig config = { - .tsdb = committer->tsdb, - .szPage = committer->szPage, - .file = fobj->f[0], - }; + STFileOp op = { + .optype = TSDB_FOP_REMOVE, + .fid = fobj->f->fid, + .of = fobj->f[0], + }; - code = tsdbSttFileReaderOpen(fobj->fname, &config, &sttReader); - TSDB_CHECK_CODE(code, lino, _exit); - - code = TARRAY2_APPEND(committer->sttReaderArray, sttReader); - TSDB_CHECK_CODE(code, lino, _exit); - - STFileOp op = { - .optype = TSDB_FOP_REMOVE, - .fid = fobj->f->fid, - .of = fobj->f[0], - }; - - code = TARRAY2_APPEND(committer->fopArray, op); - TSDB_CHECK_CODE(code, lino, _exit); + code = TARRAY2_APPEND(committer->fopArray, op); + TSDB_CHECK_CODE(code, lino, _exit); + } } _exit: diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index 7f843070d6..a997c3eea5 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -16,6 +16,7 @@ #include "tsdbFS2.h" #include "tsdbUpgrade.h" #include "vnd.h" +#include "vndCos.h" extern int vnodeScheduleTask(int (*execute)(void *), void *arg); extern int vnodeScheduleTaskEx(int tpid, int (*execute)(void *), void *arg); @@ -365,6 +366,14 @@ static int32_t tsdbFSDoScanAndFixFile(STFileSystem *fs, const STFileObj *fobj) { // check file existence if (!taosCheckExistFile(fobj->fname)) { + if (tsS3Enabled) { + const char *object_name = taosDirEntryBaseName((char *)fobj->fname); + long s3_size = s3Size(object_name); + if (s3_size > 0) { + return 0; + } + } + code = TSDB_CODE_FILE_CORRUPTED; tsdbError("vgId:%d %s failed since file:%s does not exist", TD_VID(fs->tsdb->pVnode), __func__, fobj->fname); return code; @@ -628,7 +637,7 @@ _exit: } else { tsdbInfo("vgId:%d %s success", TD_VID(pTsdb->pVnode), __func__); } - return 0; + return code; } static int32_t close_file_system(STFileSystem *fs) { @@ -721,7 +730,7 @@ _exit: } else { tsdbInfo("vgId:%d %s success", TD_VID(pTsdb->pVnode), __func__); } - return 0; + return code; } static void tsdbDoWaitBgTask(STFileSystem *fs, STFSBgTask *task) { diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 52e6fe6312..c02cff3aa9 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -5608,4 +5608,4 @@ void tsdbReaderSetId(STsdbReader* pReader, const char* idstr) { pReader->idStr = taosStrdup(idstr); } -void tsdbReaderSetCloseFlag(STsdbReader* pReader) { pReader->code = TSDB_CODE_TSC_QUERY_CANCELLED; } +void tsdbReaderSetCloseFlag(STsdbReader* pReader) { /*pReader->code = TSDB_CODE_TSC_QUERY_CANCELLED;*/ } diff --git a/source/dnode/vnode/src/tsdb/tsdbRead2.c b/source/dnode/vnode/src/tsdb/tsdbRead2.c index e635862200..c10d8c628d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead2.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead2.c @@ -1268,7 +1268,7 @@ static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo* } // has duplicated ts of different version in this block - pInfo->hasDupTs = (pBlockInfo->record.numRow > pBlockInfo->record.count); + pInfo->hasDupTs = (pBlockInfo->record.numRow > pBlockInfo->record.count) || (pBlockInfo->record.count <= 0); pInfo->overlapWithDelInfo = overlapWithDelSkyline(pScanInfo, &pBlockInfo->record, pReader->info.order); if (hasDataInLastBlock(pLastBlockReader)) { diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index dcf3770cbd..974b7f1b76 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -26,8 +26,8 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) { if (pFD->pFD == NULL) { int errsv = errno; const char *object_name = taosDirEntryBaseName((char *)path); - long s3_size = s3Size(object_name); - if (!strncmp(path + strlen(path) - 5, ".data", 5) && s3_size > 0) { + long s3_size = tsS3Enabled ? s3Size(object_name) : 0; + if (tsS3Enabled && !strncmp(path + strlen(path) - 5, ".data", 5) && s3_size > 0) { s3EvictCache(path, s3_size); s3Get(object_name, path); diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c index 267e8b4117..61be14f9bc 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRetention.c +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -338,6 +338,17 @@ static int32_t tsdbDoRetention2(void *arg) { code = tsdbMigrateDataFileS3(rtner, fobj, &did); TSDB_CHECK_CODE(code, lino, _exit); } else { + if (tsS3Enabled) { + int64_t fsize = 0; + if (taosStatFile(fobj->fname, &fsize, NULL, NULL) < 0) { + code = TAOS_SYSTEM_ERROR(terrno); + tsdbError("vgId:%d %s failed since file:%s stat failed, reason:%s", TD_VID(rtner->tsdb->pVnode), __func__, + fobj->fname, tstrerror(code)); + TSDB_CHECK_CODE(code, lino, _exit); + } + s3EvictCache(fobj->fname, fsize * 2); + } + code = tsdbDoMigrateFileObj(rtner, fobj, &did); TSDB_CHECK_CODE(code, lino, _exit); } diff --git a/source/dnode/vnode/src/tsdb/tsdbUpgrade.c b/source/dnode/vnode/src/tsdb/tsdbUpgrade.c index 59ba51c371..3f1fcb7248 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUpgrade.c +++ b/source/dnode/vnode/src/tsdb/tsdbUpgrade.c @@ -120,7 +120,15 @@ static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader * }; if (dataBlk->hasDup) { - code = tsdbReadDataBlockEx(reader, dataBlk, ctx->blockData); + tBlockDataReset(ctx->blockData); + + int16_t aCid = 0; + STSchema tSchema = {0}; + TABLEID tbid = {.suid = pBlockIdx->suid, .uid = pBlockIdx->uid}; + code = tBlockDataInit(ctx->blockData, &tbid, &tSchema, &aCid, 0); + TSDB_CHECK_CODE(code, lino, _exit); + + code = tsdbReadDataBlock(reader, dataBlk, ctx->blockData); TSDB_CHECK_CODE(code, lino, _exit); record.count = 1; @@ -334,6 +342,8 @@ static int32_t tsdbUpgradeFileSet(STsdb *tsdb, SDFileSet *pDFileSet, TFileSetArr int32_t code = 0; int32_t lino = 0; + tsdbInfo("vgId:%d upgrade file set start, fid:%d", TD_VID(tsdb->pVnode), pDFileSet->fid); + SDataFReader *reader; STFileSet *fset; @@ -366,6 +376,8 @@ static int32_t tsdbUpgradeFileSet(STsdb *tsdb, SDFileSet *pDFileSet, TFileSetArr code = TARRAY2_APPEND(fileSetArray, fset); TSDB_CHECK_CODE(code, lino, _exit); + tsdbInfo("vgId:%d upgrade file set end, fid:%d", TD_VID(tsdb->pVnode), pDFileSet->fid); + _exit: if (code) { TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 543edecec2..1ec301f7de 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -19,6 +19,7 @@ #include "vndCos.h" #include "vnode.h" #include "vnodeInt.h" +#include "audit.h" static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessAlterStbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp); @@ -940,6 +941,14 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, } taosArrayPush(rsp.pArray, &cRsp); + + int32_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId; + + char detail[1000] = {0}; + sprintf(detail, "btime:%" PRId64 ", flags:%d, ttl:%d, type:%d", + pCreateReq->btime, pCreateReq->flags, pCreateReq->ttl, pCreateReq->type); + + auditRecord(pReq, clusterId, "createTable", pVnode->config.dbname, pCreateReq->name, detail); } vDebug("vgId:%d, add %d new created tables into query table list", TD_VID(pVnode), (int32_t)taosArrayGetSize(tbUids)); diff --git a/source/libs/CMakeLists.txt b/source/libs/CMakeLists.txt index 4a95629d59..9f812517c1 100644 --- a/source/libs/CMakeLists.txt +++ b/source/libs/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory(sync) add_subdirectory(qcom) add_subdirectory(nodes) add_subdirectory(catalog) +add_subdirectory(audit) add_subdirectory(scalar) add_subdirectory(function) diff --git a/source/libs/audit/CMakeLists.txt b/source/libs/audit/CMakeLists.txt new file mode 100644 index 0000000000..2a04f084f1 --- /dev/null +++ b/source/libs/audit/CMakeLists.txt @@ -0,0 +1,13 @@ +aux_source_directory(src AUDIT_SRC) +IF (TD_ENTERPRISE) + LIST(APPEND AUDIT_SRC ${TD_ENTERPRISE_DIR}/src/plugins/audit/src/audit.c) +ENDIF () + +add_library(audit STATIC ${AUDIT_SRC}) +target_include_directories( + audit + PUBLIC "${TD_SOURCE_DIR}/include/libs/audit" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + +target_link_libraries(audit os util common transport mnode) diff --git a/source/libs/audit/inc/auditInt.h b/source/libs/audit/inc/auditInt.h new file mode 100644 index 0000000000..b6c6ec87e8 --- /dev/null +++ b/source/libs/audit/inc/auditInt.h @@ -0,0 +1,25 @@ +/* + * 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_AUDIT_INT_H_ +#define _TD_AUDIT_INT_H_ + +#include "audit.h" + +typedef struct { + SAuditCfg cfg; +} SAudit; + +#endif /*_TD_AUDIT_INT_H_*/ diff --git a/source/libs/audit/src/auditMain.c b/source/libs/audit/src/auditMain.c new file mode 100644 index 0000000000..d4b6465ac7 --- /dev/null +++ b/source/libs/audit/src/auditMain.c @@ -0,0 +1,43 @@ +/* + * 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 "auditInt.h" +#include "taoserror.h" +#include "thttp.h" +#include "ttime.h" +#include "tjson.h" +#include "tglobal.h" +#include "mnode.h" + +SAudit tsAudit = {0}; +char* tsAuditUri = "/audit"; + +int32_t auditInit(const SAuditCfg *pCfg) { + tsAudit.cfg = *pCfg; + return 0; +} + +extern void auditRecordImp(SRpcMsg *pReq, int64_t clusterId, char *operation, char *target1, char *target2, char *detail); + +void auditRecord(SRpcMsg *pReq, int64_t clusterId, char *operation, char *target1, char *target2, char *detail) { + auditRecordImp(pReq, clusterId, operation, target1, target2, detail); +} + +#ifndef TD_ENTERPRISE +void auditRecordImp(SRpcMsg *pReq, int64_t clusterId, char *operation, char *target1, char *target2, char *detail) { +} +#endif + diff --git a/source/libs/executor/src/dataDeleter.c b/source/libs/executor/src/dataDeleter.c index 11074b0e94..960ae14fcf 100644 --- a/source/libs/executor/src/dataDeleter.c +++ b/source/libs/executor/src/dataDeleter.c @@ -224,6 +224,8 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { } taosCloseQueue(pDeleter->pDataBlocks); taosThreadMutexDestroy(&pDeleter->mutex); + + taosMemoryFree(pDeleter->pManager); return TSDB_CODE_SUCCESS; } @@ -279,6 +281,8 @@ _end: if (deleter != NULL) { destroyDataSinker((SDataSinkHandle*)deleter); taosMemoryFree(deleter); + } else { + taosMemoryFree(pManager); } return code; } diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index f31658b5c1..abe566473f 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -234,6 +234,7 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { } taosCloseQueue(pDispatcher->pDataBlocks); taosThreadMutexDestroy(&pDispatcher->mutex); + taosMemoryFree(pDispatcher->pManager); return TSDB_CODE_SUCCESS; } @@ -248,7 +249,7 @@ int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pD SDataDispatchHandle* dispatcher = taosMemoryCalloc(1, sizeof(SDataDispatchHandle)); if (NULL == dispatcher) { terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_OUT_OF_MEMORY; + goto _return; } dispatcher->sink.fPut = putDataBlock; dispatcher->sink.fEndPut = endPut; @@ -266,8 +267,13 @@ int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pD if (NULL == dispatcher->pDataBlocks) { taosMemoryFree(dispatcher); terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_OUT_OF_MEMORY; + goto _return; } *pHandle = dispatcher; return TSDB_CODE_SUCCESS; + +_return: + + taosMemoryFree(pManager); + return terrno; } diff --git a/source/libs/executor/src/dataInserter.c b/source/libs/executor/src/dataInserter.c index c65dfd97d1..38d82f05fb 100644 --- a/source/libs/executor/src/dataInserter.c +++ b/source/libs/executor/src/dataInserter.c @@ -395,6 +395,8 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { taosMemoryFree(pInserter->pParam); taosHashCleanup(pInserter->pCols); taosThreadMutexDestroy(&pInserter->mutex); + + taosMemoryFree(pInserter->pManager); return TSDB_CODE_SUCCESS; } @@ -411,7 +413,7 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat if (NULL == inserter) { taosMemoryFree(pParam); terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_OUT_OF_MEMORY; + goto _return; } SQueryInserterNode* pInserterNode = (SQueryInserterNode*)pDataSink; @@ -431,23 +433,18 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat int64_t suid = 0; int32_t code = pManager->pAPI->metaFn.getTableSchema(inserter->pParam->readHandle->vnode, pInserterNode->tableId, &inserter->pSchema, &suid); if (code) { - destroyDataSinker((SDataSinkHandle*)inserter); - taosMemoryFree(inserter); - return code; + terrno = code; + goto _return; } if (pInserterNode->stableId != suid) { - destroyDataSinker((SDataSinkHandle*)inserter); - taosMemoryFree(inserter); terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; - return terrno; + goto _return; } inserter->pDataBlocks = taosArrayInit(1, POINTER_BYTES); taosThreadMutexInit(&inserter->mutex, NULL); if (NULL == inserter->pDataBlocks) { - destroyDataSinker((SDataSinkHandle*)inserter); - taosMemoryFree(inserter); terrno = TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY; } @@ -471,4 +468,15 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat *pHandle = inserter; return TSDB_CODE_SUCCESS; + +_return: + + if (inserter) { + destroyDataSinker((SDataSinkHandle*)inserter); + taosMemoryFree(inserter); + } else { + taosMemoryFree(pManager); + } + + return terrno; } diff --git a/source/libs/executor/src/dataSinkMgt.c b/source/libs/executor/src/dataSinkMgt.c index 38ec3ad393..2a59bbf1dc 100644 --- a/source/libs/executor/src/dataSinkMgt.c +++ b/source/libs/executor/src/dataSinkMgt.c @@ -18,12 +18,17 @@ #include "planner.h" #include "tarray.h" -static SDataSinkManager gDataSinkManager = {0}; SDataSinkStat gDataSinkStat = {0}; -int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg, SStorageAPI* pAPI) { - gDataSinkManager.cfg = *cfg; - gDataSinkManager.pAPI = pAPI; +int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg, SStorageAPI* pAPI, void** ppSinkManager) { + SDataSinkManager* pSinkManager = taosMemoryMalloc(sizeof(SDataSinkManager)); + if (NULL == pSinkManager) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pSinkManager->cfg = *cfg; + pSinkManager->pAPI = pAPI; + + *ppSinkManager = pSinkManager; return 0; // to avoid compiler eror } @@ -33,18 +38,22 @@ int32_t dsDataSinkGetCacheSize(SDataSinkStat* pStat) { return 0; } -int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam, const char* id) { +int32_t dsCreateDataSinker(void* pSinkManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam, const char* id) { + SDataSinkManager* pManager = pSinkManager; switch ((int)nodeType(pDataSink)) { case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: - return createDataDispatcher(&gDataSinkManager, pDataSink, pHandle); + return createDataDispatcher(pManager, pDataSink, pHandle); case QUERY_NODE_PHYSICAL_PLAN_DELETE: { - return createDataDeleter(&gDataSinkManager, pDataSink, pHandle, pParam); + return createDataDeleter(pManager, pDataSink, pHandle, pParam); } case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: { - return createDataInserter(&gDataSinkManager, pDataSink, pHandle, pParam); + return createDataInserter(pManager, pDataSink, pHandle, pParam); } + default: + break; } + taosMemoryFree(pSinkManager); qError("invalid input node type:%d, %s", nodeType(pDataSink), id); return TSDB_CODE_QRY_INVALID_INPUT; } diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 4d8b69a1d8..60dc6f0185 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -528,23 +528,25 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, goto _error; } - SDataSinkMgtCfg cfg = {.maxDataBlockNum = 500, .maxDataBlockNumPerQuery = 50}; - code = dsDataSinkMgtInit(&cfg, &(*pTask)->storageAPI); - if (code != TSDB_CODE_SUCCESS) { - qError("failed to dsDataSinkMgtInit, code:%s, %s", tstrerror(code), (*pTask)->id.str); - goto _error; - } - if (handle) { + SDataSinkMgtCfg cfg = {.maxDataBlockNum = 500, .maxDataBlockNumPerQuery = 50}; + void* pSinkManager = NULL; + code = dsDataSinkMgtInit(&cfg, &(*pTask)->storageAPI, &pSinkManager); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to dsDataSinkMgtInit, code:%s, %s", tstrerror(code), (*pTask)->id.str); + goto _error; + } + void* pSinkParam = NULL; code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, (*pTask), readHandle); if (code != TSDB_CODE_SUCCESS) { qError("failed to createDataSinkParam, vgId:%d, code:%s, %s", vgId, tstrerror(code), (*pTask)->id.str); + taosMemoryFree(pSinkManager); goto _error; } // pSinkParam has been freed during create sinker. - code = dsCreateDataSinker(pSubplan->pDataSink, handle, pSinkParam, (*pTask)->id.str); + code = dsCreateDataSinker(pSinkManager, pSubplan->pDataSink, handle, pSinkParam, (*pTask)->id.str); } qDebug("subplan task create completed, TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, pSubplan->id.queryId); diff --git a/source/libs/executor/src/filloperator.c b/source/libs/executor/src/filloperator.c index 0c8ae41e6e..9fce058c4c 100644 --- a/source/libs/executor/src/filloperator.c +++ b/source/libs/executor/src/filloperator.c @@ -64,6 +64,7 @@ typedef struct SFillOperatorInfo { static void revisedFillStartKey(SFillOperatorInfo* pInfo, SSDataBlock* pBlock, int32_t order); static void destroyFillOperatorInfo(void* param); static void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag); +static void fillResetPrevForNewGroup(SFillInfo* pFillInfo); static void doHandleRemainBlockForNewGroupImpl(SOperatorInfo* pOperator, SFillOperatorInfo* pInfo, SResultInfo* pResultInfo, int32_t order) { @@ -84,6 +85,9 @@ static void doHandleRemainBlockForNewGroupImpl(SOperatorInfo* pOperator, SFillOp taosFillSetStartInfo(pInfo->pFillInfo, pInfo->pRes->info.rows, ts); taosFillSetInputDataBlock(pInfo->pFillInfo, pInfo->pRes); + if (pInfo->pFillInfo->type == TSDB_FILL_PREV || pInfo->pFillInfo->type == TSDB_FILL_LINEAR) { + fillResetPrevForNewGroup(pInfo->pFillInfo); + } int32_t numOfResultRows = pResultInfo->capacity - pResBlock->info.rows; taosFillResultDataBlock(pInfo->pFillInfo, pResBlock, numOfResultRows); @@ -122,6 +126,15 @@ void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int pInfo->pRes->info.id.groupId = pBlock->info.id.groupId; } +static void fillResetPrevForNewGroup(SFillInfo* pFillInfo) { + for (int32_t colIdx = 0; colIdx < pFillInfo->numOfCols; ++colIdx) { + if (!pFillInfo->pFillCol[colIdx].notFillCol) { + SGroupKeys* key = taosArrayGet(pFillInfo->prev.pRowVal, colIdx); + key->isNull = true; + } + } +} + // todo refactor: decide the start key according to the query time range. static void revisedFillStartKey(SFillOperatorInfo* pInfo, SSDataBlock* pBlock, int32_t order) { if (order == TSDB_ORDER_ASC) { @@ -153,17 +166,20 @@ static void revisedFillStartKey(SFillOperatorInfo* pInfo, SSDataBlock* pBlock, i } else if (ekey < pInfo->pFillInfo->start) { int64_t t = ekey; SInterval* pInterval = &pInfo->pFillInfo->interval; - + int64_t prev = t; while(1) { - int64_t prev = taosTimeAdd(t, pInterval->sliding, pInterval->slidingUnit, pInterval->precision); - if (prev >= pInfo->pFillInfo->start) { - t = prev; + int64_t next = taosTimeAdd(t, pInterval->sliding, pInterval->slidingUnit, pInterval->precision); + if (next >= pInfo->pFillInfo->start) { + prev = t; + t = next; break; } - t = prev; + prev = t; + t = next; } - // todo time window chosen problem: t or prev value? + // todo time window chosen problem: t or next value? + if (t > pInfo->pFillInfo->start) t = prev; taosFillUpdateStartTimestampInfo(pInfo->pFillInfo, t); } } diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 188a1fcd4d..96bb32dd98 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -314,7 +314,7 @@ static int32_t translateInOutStr(SFunctionNode* pFunc, char* pErrBuf, int32_t le } SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); - if (!IS_STR_DATA_TYPE(pPara1->resType.type)) { + if (TSDB_DATA_TYPE_VARBINARY == pPara1->resType.type || !IS_STR_DATA_TYPE(pPara1->resType.type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -328,7 +328,7 @@ static int32_t translateTrimStr(SFunctionNode* pFunc, char* pErrBuf, int32_t len } SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); - if (!IS_STR_DATA_TYPE(pPara1->resType.type)) { + if (TSDB_DATA_TYPE_VARBINARY == pPara1->resType.type || !IS_STR_DATA_TYPE(pPara1->resType.type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -1839,6 +1839,10 @@ static int32_t translateLength(SFunctionNode* pFunc, char* pErrBuf, int32_t len) return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } + if (TSDB_DATA_TYPE_VARBINARY == ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; return TSDB_CODE_SUCCESS; } @@ -1867,6 +1871,10 @@ static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t for (int32_t i = 0; i < numOfParams; ++i) { SNode* pPara = nodesListGetNode(pFunc->pParameterList, i); uint8_t paraType = ((SExprNode*)pPara)->resType.type; + if (TSDB_DATA_TYPE_VARBINARY == paraType) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + if (!IS_STR_DATA_TYPE(paraType) && !IS_NULL_TYPE(paraType)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -1923,7 +1931,7 @@ static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) uint8_t para0Type = pPara0->resType.type; uint8_t para1Type = pPara1->resType.type; - if (!IS_STR_DATA_TYPE(para0Type) || !IS_INTEGER_TYPE(para1Type)) { + if (TSDB_DATA_TYPE_VARBINARY == para0Type || !IS_STR_DATA_TYPE(para0Type) || !IS_INTEGER_TYPE(para1Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -1951,6 +1959,12 @@ static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { // The number of parameters has been limited by the syntax definition + SExprNode* pPara0 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); + uint8_t para0Type = pPara0->resType.type; + if (TSDB_DATA_TYPE_VARBINARY == para0Type) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + // The function return type has been set during syntax parsing uint8_t para2Type = pFunc->node.resType.type; @@ -2022,7 +2036,7 @@ static int32_t translateToUnixtimestamp(SFunctionNode* pFunc, char* pErrBuf, int } uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; - if (!IS_STR_DATA_TYPE(para1Type)) { + if (para1Type == TSDB_DATA_TYPE_VARBINARY || !IS_STR_DATA_TYPE(para1Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -2156,7 +2170,7 @@ static int32_t translateToJson(SFunctionNode* pFunc, char* pErrBuf, int32_t len) } SExprNode* pPara = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); - if (QUERY_NODE_VALUE != nodeType(pPara) || (!IS_VAR_DATA_TYPE(pPara->resType.type))) { + if (QUERY_NODE_VALUE != nodeType(pPara) || TSDB_DATA_TYPE_VARBINARY == pPara->resType.type || (!IS_VAR_DATA_TYPE(pPara->resType.type))) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index a742f5c954..3b0b4ed171 100755 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -286,7 +286,7 @@ retention(A) ::= NK_VARIABLE(B) NK_COLON NK_VARIABLE(C). %type speed_opt { int32_t } %destructor speed_opt { } speed_opt(A) ::= . { A = 0; } -speed_opt(A) ::= MAX_SPEED NK_INTEGER(B). { A = taosStr2Int32(B.z, NULL, 10); } +speed_opt(A) ::= BWLIMIT NK_INTEGER(B). { A = taosStr2Int32(B.z, NULL, 10); } start_opt(A) ::= . { A = NULL; } start_opt(A) ::= START WITH NK_INTEGER(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 342c0f390e..410365b05e 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -635,7 +635,7 @@ SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType d CHECK_OUT_OF_MEM(func); strcpy(func->functionName, "cast"); func->node.resType = dt; - if (TSDB_DATA_TYPE_VARCHAR == dt.type || TSDB_DATA_TYPE_GEOMETRY == dt.type) { + if (TSDB_DATA_TYPE_VARCHAR == dt.type || TSDB_DATA_TYPE_GEOMETRY == dt.type || TSDB_DATA_TYPE_VARBINARY == dt.type) { func->node.resType.bytes = func->node.resType.bytes + VARSTR_HEADER_SIZE; } else if (TSDB_DATA_TYPE_NCHAR == dt.type) { func->node.resType.bytes = func->node.resType.bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 6fd2dd4785..d74a77b134 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -138,7 +138,7 @@ static SKeyword keywordTable[] = { {"MATCH", TK_MATCH}, {"MAXROWS", TK_MAXROWS}, {"MAX_DELAY", TK_MAX_DELAY}, - {"MAX_SPEED", TK_MAX_SPEED}, + {"BWLIMIT", TK_BWLIMIT}, {"MERGE", TK_MERGE}, {"META", TK_META}, {"ONLY", TK_ONLY}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index e973694a04..2509272b33 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -1258,7 +1258,7 @@ static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal, if(isHexChar) taosMemoryFree(data); return generateDealNodeErrMsg(pCxt, TSDB_CODE_OUT_OF_MEMORY); } - varDataSetLen(pVal->datum.p, size + VARSTR_HEADER_SIZE); + varDataSetLen(pVal->datum.p, size); memcpy(varDataVal(pVal->datum.p), data, size); if(isHexChar) taosMemoryFree(data); break; diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 10fda8741b..4034597eed 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -97,8 +97,16 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { pVal->node.resType.bytes = inputSize; switch (pParam->buffer_type) { - case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: + pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); + if (NULL == pVal->datum.p) { + return TSDB_CODE_OUT_OF_MEMORY; + } + varDataSetLen(pVal->datum.p, pVal->node.resType.bytes); + memcpy(varDataVal(pVal->datum.p), pParam->buffer, pVal->node.resType.bytes); + pVal->node.resType.bytes += VARSTR_HEADER_SIZE; + break; + case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_GEOMETRY: pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index fb1355d3db..0caf0c566c 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -1,5 +1,3 @@ -/* This file is automatically generated by Lemon from input grammar -** source file "sql.y". */ /* ** 2000-05-29 ** @@ -24,8 +22,9 @@ ** The following is the concatenation of all %include directives from the ** input grammar file: */ +#include +#include /************ Begin %include sections from the grammar ************************/ -#line 11 "sql.y" #include #include @@ -42,351 +41,12 @@ #include "parAst.h" #define YYSTACKDEPTH 0 -#line 46 "sql.c" /**************** End of %include directives **********************************/ -/* These constants specify the various numeric values for terminal symbols. -***************** Begin token definitions *************************************/ -#ifndef TK_OR -#define TK_OR 1 -#define TK_AND 2 -#define TK_UNION 3 -#define TK_ALL 4 -#define TK_MINUS 5 -#define TK_EXCEPT 6 -#define TK_INTERSECT 7 -#define TK_NK_BITAND 8 -#define TK_NK_BITOR 9 -#define TK_NK_LSHIFT 10 -#define TK_NK_RSHIFT 11 -#define TK_NK_PLUS 12 -#define TK_NK_MINUS 13 -#define TK_NK_STAR 14 -#define TK_NK_SLASH 15 -#define TK_NK_REM 16 -#define TK_NK_CONCAT 17 -#define TK_CREATE 18 -#define TK_ACCOUNT 19 -#define TK_NK_ID 20 -#define TK_PASS 21 -#define TK_NK_STRING 22 -#define TK_ALTER 23 -#define TK_PPS 24 -#define TK_TSERIES 25 -#define TK_STORAGE 26 -#define TK_STREAMS 27 -#define TK_QTIME 28 -#define TK_DBS 29 -#define TK_USERS 30 -#define TK_CONNS 31 -#define TK_STATE 32 -#define TK_USER 33 -#define TK_ENABLE 34 -#define TK_NK_INTEGER 35 -#define TK_SYSINFO 36 -#define TK_DROP 37 -#define TK_GRANT 38 -#define TK_ON 39 -#define TK_TO 40 -#define TK_REVOKE 41 -#define TK_FROM 42 -#define TK_SUBSCRIBE 43 -#define TK_NK_COMMA 44 -#define TK_READ 45 -#define TK_WRITE 46 -#define TK_NK_DOT 47 -#define TK_WITH 48 -#define TK_DNODE 49 -#define TK_PORT 50 -#define TK_DNODES 51 -#define TK_RESTORE 52 -#define TK_NK_IPTOKEN 53 -#define TK_FORCE 54 -#define TK_UNSAFE 55 -#define TK_LOCAL 56 -#define TK_QNODE 57 -#define TK_BNODE 58 -#define TK_SNODE 59 -#define TK_MNODE 60 -#define TK_VNODE 61 -#define TK_DATABASE 62 -#define TK_USE 63 -#define TK_FLUSH 64 -#define TK_TRIM 65 -#define TK_COMPACT 66 -#define TK_IF 67 -#define TK_NOT 68 -#define TK_EXISTS 69 -#define TK_BUFFER 70 -#define TK_CACHEMODEL 71 -#define TK_CACHESIZE 72 -#define TK_COMP 73 -#define TK_DURATION 74 -#define TK_NK_VARIABLE 75 -#define TK_MAXROWS 76 -#define TK_MINROWS 77 -#define TK_KEEP 78 -#define TK_PAGES 79 -#define TK_PAGESIZE 80 -#define TK_TSDB_PAGESIZE 81 -#define TK_PRECISION 82 -#define TK_REPLICA 83 -#define TK_VGROUPS 84 -#define TK_SINGLE_STABLE 85 -#define TK_RETENTIONS 86 -#define TK_SCHEMALESS 87 -#define TK_WAL_LEVEL 88 -#define TK_WAL_FSYNC_PERIOD 89 -#define TK_WAL_RETENTION_PERIOD 90 -#define TK_WAL_RETENTION_SIZE 91 -#define TK_WAL_ROLL_PERIOD 92 -#define TK_WAL_SEGMENT_SIZE 93 -#define TK_STT_TRIGGER 94 -#define TK_TABLE_PREFIX 95 -#define TK_TABLE_SUFFIX 96 -#define TK_NK_COLON 97 -#define TK_MAX_SPEED 98 -#define TK_START 99 -#define TK_TIMESTAMP 100 -#define TK_END 101 -#define TK_TABLE 102 -#define TK_NK_LP 103 -#define TK_NK_RP 104 -#define TK_STABLE 105 -#define TK_ADD 106 -#define TK_COLUMN 107 -#define TK_MODIFY 108 -#define TK_RENAME 109 -#define TK_TAG 110 -#define TK_SET 111 -#define TK_NK_EQ 112 -#define TK_USING 113 -#define TK_TAGS 114 -#define TK_BOOL 115 -#define TK_TINYINT 116 -#define TK_SMALLINT 117 -#define TK_INT 118 -#define TK_INTEGER 119 -#define TK_BIGINT 120 -#define TK_FLOAT 121 -#define TK_DOUBLE 122 -#define TK_BINARY 123 -#define TK_NCHAR 124 -#define TK_UNSIGNED 125 -#define TK_JSON 126 -#define TK_VARCHAR 127 -#define TK_MEDIUMBLOB 128 -#define TK_BLOB 129 -#define TK_VARBINARY 130 -#define TK_GEOMETRY 131 -#define TK_DECIMAL 132 -#define TK_COMMENT 133 -#define TK_MAX_DELAY 134 -#define TK_WATERMARK 135 -#define TK_ROLLUP 136 -#define TK_TTL 137 -#define TK_SMA 138 -#define TK_DELETE_MARK 139 -#define TK_FIRST 140 -#define TK_LAST 141 -#define TK_SHOW 142 -#define TK_PRIVILEGES 143 -#define TK_DATABASES 144 -#define TK_TABLES 145 -#define TK_STABLES 146 -#define TK_MNODES 147 -#define TK_QNODES 148 -#define TK_FUNCTIONS 149 -#define TK_INDEXES 150 -#define TK_ACCOUNTS 151 -#define TK_APPS 152 -#define TK_CONNECTIONS 153 -#define TK_LICENCES 154 -#define TK_GRANTS 155 -#define TK_QUERIES 156 -#define TK_SCORES 157 -#define TK_TOPICS 158 -#define TK_VARIABLES 159 -#define TK_CLUSTER 160 -#define TK_BNODES 161 -#define TK_SNODES 162 -#define TK_TRANSACTIONS 163 -#define TK_DISTRIBUTED 164 -#define TK_CONSUMERS 165 -#define TK_SUBSCRIPTIONS 166 -#define TK_VNODES 167 -#define TK_ALIVE 168 -#define TK_LIKE 169 -#define TK_TBNAME 170 -#define TK_QTAGS 171 -#define TK_AS 172 -#define TK_INDEX 173 -#define TK_FUNCTION 174 -#define TK_INTERVAL 175 -#define TK_COUNT 176 -#define TK_LAST_ROW 177 -#define TK_META 178 -#define TK_ONLY 179 -#define TK_TOPIC 180 -#define TK_CONSUMER 181 -#define TK_GROUP 182 -#define TK_DESC 183 -#define TK_DESCRIBE 184 -#define TK_RESET 185 -#define TK_QUERY 186 -#define TK_CACHE 187 -#define TK_EXPLAIN 188 -#define TK_ANALYZE 189 -#define TK_VERBOSE 190 -#define TK_NK_BOOL 191 -#define TK_RATIO 192 -#define TK_NK_FLOAT 193 -#define TK_OUTPUTTYPE 194 -#define TK_AGGREGATE 195 -#define TK_BUFSIZE 196 -#define TK_LANGUAGE 197 -#define TK_REPLACE 198 -#define TK_STREAM 199 -#define TK_INTO 200 -#define TK_PAUSE 201 -#define TK_RESUME 202 -#define TK_TRIGGER 203 -#define TK_AT_ONCE 204 -#define TK_WINDOW_CLOSE 205 -#define TK_IGNORE 206 -#define TK_EXPIRED 207 -#define TK_FILL_HISTORY 208 -#define TK_UPDATE 209 -#define TK_SUBTABLE 210 -#define TK_UNTREATED 211 -#define TK_KILL 212 -#define TK_CONNECTION 213 -#define TK_TRANSACTION 214 -#define TK_BALANCE 215 -#define TK_VGROUP 216 -#define TK_LEADER 217 -#define TK_MERGE 218 -#define TK_REDISTRIBUTE 219 -#define TK_SPLIT 220 -#define TK_DELETE 221 -#define TK_INSERT 222 -#define TK_NULL 223 -#define TK_NK_QUESTION 224 -#define TK_NK_ARROW 225 -#define TK_ROWTS 226 -#define TK_QSTART 227 -#define TK_QEND 228 -#define TK_QDURATION 229 -#define TK_WSTART 230 -#define TK_WEND 231 -#define TK_WDURATION 232 -#define TK_IROWTS 233 -#define TK_ISFILLED 234 -#define TK_CAST 235 -#define TK_NOW 236 -#define TK_TODAY 237 -#define TK_TIMEZONE 238 -#define TK_CLIENT_VERSION 239 -#define TK_SERVER_VERSION 240 -#define TK_SERVER_STATUS 241 -#define TK_CURRENT_USER 242 -#define TK_CASE 243 -#define TK_WHEN 244 -#define TK_THEN 245 -#define TK_ELSE 246 -#define TK_BETWEEN 247 -#define TK_IS 248 -#define TK_NK_LT 249 -#define TK_NK_GT 250 -#define TK_NK_LE 251 -#define TK_NK_GE 252 -#define TK_NK_NE 253 -#define TK_MATCH 254 -#define TK_NMATCH 255 -#define TK_CONTAINS 256 -#define TK_IN 257 -#define TK_JOIN 258 -#define TK_INNER 259 -#define TK_SELECT 260 -#define TK_NK_HINT 261 -#define TK_DISTINCT 262 -#define TK_WHERE 263 -#define TK_PARTITION 264 -#define TK_BY 265 -#define TK_SESSION 266 -#define TK_STATE_WINDOW 267 -#define TK_EVENT_WINDOW 268 -#define TK_SLIDING 269 -#define TK_FILL 270 -#define TK_VALUE 271 -#define TK_VALUE_F 272 -#define TK_NONE 273 -#define TK_PREV 274 -#define TK_NULL_F 275 -#define TK_LINEAR 276 -#define TK_NEXT 277 -#define TK_HAVING 278 -#define TK_RANGE 279 -#define TK_EVERY 280 -#define TK_ORDER 281 -#define TK_SLIMIT 282 -#define TK_SOFFSET 283 -#define TK_LIMIT 284 -#define TK_OFFSET 285 -#define TK_ASC 286 -#define TK_NULLS 287 -#define TK_ABORT 288 -#define TK_AFTER 289 -#define TK_ATTACH 290 -#define TK_BEFORE 291 -#define TK_BEGIN 292 -#define TK_BITAND 293 -#define TK_BITNOT 294 -#define TK_BITOR 295 -#define TK_BLOCKS 296 -#define TK_CHANGE 297 -#define TK_COMMA 298 -#define TK_CONCAT 299 -#define TK_CONFLICT 300 -#define TK_COPY 301 -#define TK_DEFERRED 302 -#define TK_DELIMITERS 303 -#define TK_DETACH 304 -#define TK_DIVIDE 305 -#define TK_DOT 306 -#define TK_EACH 307 -#define TK_FAIL 308 -#define TK_FILE 309 -#define TK_FOR 310 -#define TK_GLOB 311 -#define TK_ID 312 -#define TK_IMMEDIATE 313 -#define TK_IMPORT 314 -#define TK_INITIALLY 315 -#define TK_INSTEAD 316 -#define TK_ISNULL 317 -#define TK_KEY 318 -#define TK_MODULES 319 -#define TK_NK_BITNOT 320 -#define TK_NK_SEMI 321 -#define TK_NOTNULL 322 -#define TK_OF 323 -#define TK_PLUS 324 -#define TK_PRIVILEGE 325 -#define TK_RAISE 326 -#define TK_RESTRICT 327 -#define TK_ROW 328 -#define TK_SEMI 329 -#define TK_STAR 330 -#define TK_STATEMENT 331 -#define TK_STRICT 332 -#define TK_STRING 333 -#define TK_TIMES 334 -#define TK_VALUES 335 -#define TK_VARIABLE 336 -#define TK_VIEW 337 -#define TK_WAL 338 -#endif -/**************** End token definitions ***************************************/ +/* These constants specify the various numeric values for terminal symbols +** in a format understandable to "makeheaders". This section is blank unless +** "lemon" is run with the "-m" command-line option. +***************** Begin makeheaders token definitions *************************/ +/**************** End makeheaders token definitions ***************************/ /* The next sections is a series of control #defines. ** various aspects of the generated parser. @@ -1480,7 +1140,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* TABLE_PREFIX => nothing */ 0, /* TABLE_SUFFIX => nothing */ 0, /* NK_COLON => nothing */ - 0, /* MAX_SPEED => nothing */ + 0, /* BWLIMIT => nothing */ 0, /* START => nothing */ 0, /* TIMESTAMP => nothing */ 288, /* END => ABORT */ @@ -1772,7 +1432,6 @@ struct yyParser { }; typedef struct yyParser yyParser; -#include #ifndef NDEBUG #include static FILE *yyTraceFILE = 0; @@ -1907,7 +1566,7 @@ static const char *const yyTokenName[] = { /* 95 */ "TABLE_PREFIX", /* 96 */ "TABLE_SUFFIX", /* 97 */ "NK_COLON", - /* 98 */ "MAX_SPEED", + /* 98 */ "BWLIMIT", /* 99 */ "START", /* 100 */ "TIMESTAMP", /* 101 */ "END", @@ -2449,7 +2108,7 @@ static const char *const yyRuleName[] = { /* 140 */ "retention_list ::= retention_list NK_COMMA retention", /* 141 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", /* 142 */ "speed_opt ::=", - /* 143 */ "speed_opt ::= MAX_SPEED NK_INTEGER", + /* 143 */ "speed_opt ::= BWLIMIT NK_INTEGER", /* 144 */ "start_opt ::=", /* 145 */ "start_opt ::= START WITH NK_INTEGER", /* 146 */ "start_opt ::= START WITH NK_STRING", @@ -3111,9 +2770,7 @@ static void yy_destructor( case 485: /* query_simple_or_subquery */ case 487: /* sort_specification */ { -#line 7 "sql.y" nodesDestroyNode((yypminor->yy952)); -#line 3116 "sql.c" } break; case 340: /* account_options */ @@ -3123,9 +2780,7 @@ static void yy_destructor( case 411: /* with_meta */ case 420: /* bufsize_opt */ { -#line 54 "sql.y" -#line 3128 "sql.c" } break; case 344: /* user_name */ @@ -3146,32 +2801,24 @@ static void yy_destructor( case 440: /* noarg_func */ case 458: /* alias_opt */ { -#line 742 "sql.y" -#line 3151 "sql.c" } break; case 345: /* sysinfo_opt */ { -#line 92 "sql.y" -#line 3158 "sql.c" } break; case 346: /* privileges */ case 349: /* priv_type_list */ case 350: /* priv_type */ { -#line 101 "sql.y" -#line 3167 "sql.c" } break; case 347: /* priv_level */ { -#line 117 "sql.y" -#line 3174 "sql.c" } break; case 356: /* force_opt */ @@ -3185,9 +2832,7 @@ static void yy_destructor( case 464: /* set_quantifier_opt */ case 465: /* tag_mode_opt */ { -#line 146 "sql.y" -#line 3190 "sql.c" } break; case 365: /* integer_list */ @@ -3221,60 +2866,44 @@ static void yy_destructor( case 481: /* order_by_clause_opt */ case 486: /* sort_specification_list */ { -#line 270 "sql.y" nodesDestroyList((yypminor->yy824)); -#line 3226 "sql.c" } break; case 369: /* alter_db_option */ case 391: /* alter_table_option */ { -#line 243 "sql.y" -#line 3234 "sql.c" } break; case 381: /* type_name */ { -#line 364 "sql.y" -#line 3241 "sql.c" } break; case 448: /* compare_op */ case 449: /* in_op */ { -#line 930 "sql.y" -#line 3249 "sql.c" } break; case 461: /* join_type */ { -#line 1006 "sql.y" -#line 3256 "sql.c" } break; case 477: /* fill_mode */ { -#line 1092 "sql.y" -#line 3263 "sql.c" } break; case 488: /* ordering_specification_opt */ { -#line 1177 "sql.y" -#line 3270 "sql.c" } break; case 489: /* null_ordering_opt */ { -#line 1183 "sql.y" -#line 3277 "sql.c" } break; /********* End destructor definitions *****************************************/ @@ -3441,7 +3070,7 @@ static YYACTIONTYPE yy_find_shift_action( #endif /* YYWILDCARD */ return yy_default[stateno]; }else{ - assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) ); + assert( i>=0 && iyytos; +#ifndef NDEBUG + if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ + yysize = yyRuleInfoNRhs[yyruleno]; + if( yysize ){ + fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", + yyTracePrompt, + yyruleno, yyRuleName[yyruleno], + yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ + yypParser->yyhwm++; + assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack)); + } +#endif +#if YYSTACKDEPTH>0 + if( yypParser->yytos>=yypParser->yystackEnd ){ + yyStackOverflow(yypParser); + /* The call to yyStackOverflow() above pops the stack until it is + ** empty, causing the main parser loop to exit. So the return value + ** is never used and does not matter. */ + return 0; + } +#else + if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ + if( yyGrowStack(yypParser) ){ + yyStackOverflow(yypParser); + /* The call to yyStackOverflow() above pops the stack until it is + ** empty, causing the main parser loop to exit. So the return value + ** is never used and does not matter. */ + return 0; + } + yymsp = yypParser->yytos; + } +#endif + } switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example @@ -4818,21 +4495,15 @@ static YYACTIONTYPE yy_reduce( /********** Begin reduce actions **********************************************/ YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ -#line 50 "sql.y" { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } -#line 4823 "sql.c" yy_destructor(yypParser,340,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ -#line 51 "sql.y" { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } -#line 4829 "sql.c" yy_destructor(yypParser,341,&yymsp[0].minor); break; case 2: /* account_options ::= */ -#line 55 "sql.y" { } -#line 4835 "sql.c" break; case 3: /* account_options ::= account_options PPS literal */ case 4: /* account_options ::= account_options TSERIES literal */ yytestcase(yyruleno==4); @@ -4844,24 +4515,18 @@ static YYACTIONTYPE yy_reduce( case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); { yy_destructor(yypParser,340,&yymsp[-2].minor); -#line 56 "sql.y" { } -#line 4849 "sql.c" yy_destructor(yypParser,342,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ { yy_destructor(yypParser,343,&yymsp[0].minor); -#line 68 "sql.y" { } -#line 4857 "sql.c" } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ { yy_destructor(yypParser,341,&yymsp[-1].minor); -#line 69 "sql.y" { } -#line 4864 "sql.c" yy_destructor(yypParser,343,&yymsp[0].minor); } break; @@ -4875,111 +4540,71 @@ static YYACTIONTYPE yy_reduce( case 21: /* alter_account_option ::= USERS literal */ yytestcase(yyruleno==21); case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); -#line 73 "sql.y" { } -#line 4880 "sql.c" yy_destructor(yypParser,342,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ -#line 85 "sql.y" { pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-3].minor.yy169, &yymsp[-1].minor.yy0, yymsp[0].minor.yy243); } -#line 4886 "sql.c" break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -#line 86 "sql.y" { pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy169, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } -#line 4891 "sql.c" break; case 26: /* cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ -#line 87 "sql.y" { pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy169, TSDB_ALTER_USER_ENABLE, &yymsp[0].minor.yy0); } -#line 4896 "sql.c" break; case 27: /* cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ -#line 88 "sql.y" { pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy169, TSDB_ALTER_USER_SYSINFO, &yymsp[0].minor.yy0); } -#line 4901 "sql.c" break; case 28: /* cmd ::= DROP USER user_name */ -#line 89 "sql.y" { pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy169); } -#line 4906 "sql.c" break; case 29: /* sysinfo_opt ::= */ -#line 93 "sql.y" { yymsp[1].minor.yy243 = 1; } -#line 4911 "sql.c" break; case 30: /* sysinfo_opt ::= SYSINFO NK_INTEGER */ -#line 94 "sql.y" { yymsp[-1].minor.yy243 = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); } -#line 4916 "sql.c" break; case 31: /* cmd ::= GRANT privileges ON priv_level with_opt TO user_name */ -#line 97 "sql.y" { pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-5].minor.yy949, &yymsp[-3].minor.yy637, &yymsp[0].minor.yy169, yymsp[-2].minor.yy952); } -#line 4921 "sql.c" break; case 32: /* cmd ::= REVOKE privileges ON priv_level with_opt FROM user_name */ -#line 98 "sql.y" { pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-5].minor.yy949, &yymsp[-3].minor.yy637, &yymsp[0].minor.yy169, yymsp[-2].minor.yy952); } -#line 4926 "sql.c" break; case 33: /* privileges ::= ALL */ -#line 102 "sql.y" { yymsp[0].minor.yy949 = PRIVILEGE_TYPE_ALL; } -#line 4931 "sql.c" break; case 34: /* privileges ::= priv_type_list */ case 36: /* priv_type_list ::= priv_type */ yytestcase(yyruleno==36); -#line 103 "sql.y" { yylhsminor.yy949 = yymsp[0].minor.yy949; } -#line 4937 "sql.c" yymsp[0].minor.yy949 = yylhsminor.yy949; break; case 35: /* privileges ::= SUBSCRIBE */ -#line 104 "sql.y" { yymsp[0].minor.yy949 = PRIVILEGE_TYPE_SUBSCRIBE; } -#line 4943 "sql.c" break; case 37: /* priv_type_list ::= priv_type_list NK_COMMA priv_type */ -#line 109 "sql.y" { yylhsminor.yy949 = yymsp[-2].minor.yy949 | yymsp[0].minor.yy949; } -#line 4948 "sql.c" yymsp[-2].minor.yy949 = yylhsminor.yy949; break; case 38: /* priv_type ::= READ */ -#line 113 "sql.y" { yymsp[0].minor.yy949 = PRIVILEGE_TYPE_READ; } -#line 4954 "sql.c" break; case 39: /* priv_type ::= WRITE */ -#line 114 "sql.y" { yymsp[0].minor.yy949 = PRIVILEGE_TYPE_WRITE; } -#line 4959 "sql.c" break; case 40: /* priv_level ::= NK_STAR NK_DOT NK_STAR */ -#line 118 "sql.y" { yylhsminor.yy637.first = yymsp[-2].minor.yy0; yylhsminor.yy637.second = yymsp[0].minor.yy0; } -#line 4964 "sql.c" yymsp[-2].minor.yy637 = yylhsminor.yy637; break; case 41: /* priv_level ::= db_name NK_DOT NK_STAR */ -#line 119 "sql.y" { yylhsminor.yy637.first = yymsp[-2].minor.yy169; yylhsminor.yy637.second = yymsp[0].minor.yy0; } -#line 4970 "sql.c" yymsp[-2].minor.yy637 = yylhsminor.yy637; break; case 42: /* priv_level ::= db_name NK_DOT table_name */ -#line 120 "sql.y" { yylhsminor.yy637.first = yymsp[-2].minor.yy169; yylhsminor.yy637.second = yymsp[0].minor.yy169; } -#line 4976 "sql.c" yymsp[-2].minor.yy637 = yylhsminor.yy637; break; case 43: /* priv_level ::= topic_name */ -#line 121 "sql.y" { yylhsminor.yy637.first = yymsp[0].minor.yy169; yylhsminor.yy637.second = nil_token; } -#line 4982 "sql.c" yymsp[0].minor.yy637 = yylhsminor.yy637; break; case 44: /* with_opt ::= */ @@ -4998,72 +4623,46 @@ static YYACTIONTYPE yy_reduce( case 571: /* every_opt ::= */ yytestcase(yyruleno==571); case 584: /* slimit_clause_opt ::= */ yytestcase(yyruleno==584); case 588: /* limit_clause_opt ::= */ yytestcase(yyruleno==588); -#line 123 "sql.y" { yymsp[1].minor.yy952 = NULL; } -#line 5003 "sql.c" break; case 45: /* with_opt ::= WITH search_condition */ case 503: /* from_clause_opt ::= FROM table_reference_list */ yytestcase(yyruleno==503); case 536: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==536); case 567: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==567); -#line 124 "sql.y" { yymsp[-1].minor.yy952 = yymsp[0].minor.yy952; } -#line 5011 "sql.c" break; case 46: /* cmd ::= CREATE DNODE dnode_endpoint */ -#line 127 "sql.y" { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy169, NULL); } -#line 5016 "sql.c" break; case 47: /* cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ -#line 128 "sql.y" { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy169, &yymsp[0].minor.yy0); } -#line 5021 "sql.c" break; case 48: /* cmd ::= DROP DNODE NK_INTEGER force_opt */ -#line 129 "sql.y" { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy957, false); } -#line 5026 "sql.c" break; case 49: /* cmd ::= DROP DNODE dnode_endpoint force_opt */ -#line 130 "sql.y" { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[-1].minor.yy169, yymsp[0].minor.yy957, false); } -#line 5031 "sql.c" break; case 50: /* cmd ::= DROP DNODE NK_INTEGER unsafe_opt */ -#line 131 "sql.y" { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[-1].minor.yy0, false, yymsp[0].minor.yy957); } -#line 5036 "sql.c" break; case 51: /* cmd ::= DROP DNODE dnode_endpoint unsafe_opt */ -#line 132 "sql.y" { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[-1].minor.yy169, false, yymsp[0].minor.yy957); } -#line 5041 "sql.c" break; case 52: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ -#line 133 "sql.y" { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } -#line 5046 "sql.c" break; case 53: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ -#line 134 "sql.y" { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-2].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } -#line 5051 "sql.c" break; case 54: /* cmd ::= ALTER ALL DNODES NK_STRING */ -#line 135 "sql.y" { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &yymsp[0].minor.yy0, NULL); } -#line 5056 "sql.c" break; case 55: /* cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ -#line 136 "sql.y" { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } -#line 5061 "sql.c" break; case 56: /* cmd ::= RESTORE DNODE NK_INTEGER */ -#line 137 "sql.y" { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_DNODE_STMT, &yymsp[0].minor.yy0); } -#line 5066 "sql.c" break; case 57: /* dnode_endpoint ::= NK_STRING */ case 58: /* dnode_endpoint ::= NK_ID */ yytestcase(yyruleno==58); @@ -5096,9 +4695,7 @@ static YYACTIONTYPE yy_reduce( case 458: /* star_func ::= FIRST */ yytestcase(yyruleno==458); case 459: /* star_func ::= LAST */ yytestcase(yyruleno==459); case 460: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==460); -#line 141 "sql.y" { yylhsminor.yy169 = yymsp[0].minor.yy0; } -#line 5101 "sql.c" yymsp[0].minor.yy169 = yylhsminor.yy169; break; case 60: /* force_opt ::= */ @@ -5110,9 +4707,7 @@ static YYACTIONTYPE yy_reduce( case 356: /* ignore_opt ::= */ yytestcase(yyruleno==356); case 523: /* tag_mode_opt ::= */ yytestcase(yyruleno==523); case 525: /* set_quantifier_opt ::= */ yytestcase(yyruleno==525); -#line 147 "sql.y" { yymsp[1].minor.yy957 = false; } -#line 5115 "sql.c" break; case 61: /* force_opt ::= FORCE */ case 62: /* unsafe_opt ::= UNSAFE */ yytestcase(yyruleno==62); @@ -5120,419 +4715,275 @@ static YYACTIONTYPE yy_reduce( case 329: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==329); case 524: /* tag_mode_opt ::= TAGS */ yytestcase(yyruleno==524); case 526: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==526); -#line 148 "sql.y" { yymsp[0].minor.yy957 = true; } -#line 5125 "sql.c" break; case 63: /* cmd ::= ALTER LOCAL NK_STRING */ -#line 155 "sql.y" { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } -#line 5130 "sql.c" break; case 64: /* cmd ::= ALTER LOCAL NK_STRING NK_STRING */ -#line 156 "sql.y" { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } -#line 5135 "sql.c" break; case 65: /* cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ -#line 159 "sql.y" { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_QNODE_STMT, &yymsp[0].minor.yy0); } -#line 5140 "sql.c" break; case 66: /* cmd ::= DROP QNODE ON DNODE NK_INTEGER */ -#line 160 "sql.y" { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_QNODE_STMT, &yymsp[0].minor.yy0); } -#line 5145 "sql.c" break; case 67: /* cmd ::= RESTORE QNODE ON DNODE NK_INTEGER */ -#line 161 "sql.y" { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_QNODE_STMT, &yymsp[0].minor.yy0); } -#line 5150 "sql.c" break; case 68: /* cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ -#line 164 "sql.y" { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_BNODE_STMT, &yymsp[0].minor.yy0); } -#line 5155 "sql.c" break; case 69: /* cmd ::= DROP BNODE ON DNODE NK_INTEGER */ -#line 165 "sql.y" { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_BNODE_STMT, &yymsp[0].minor.yy0); } -#line 5160 "sql.c" break; case 70: /* cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ -#line 168 "sql.y" { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_SNODE_STMT, &yymsp[0].minor.yy0); } -#line 5165 "sql.c" break; case 71: /* cmd ::= DROP SNODE ON DNODE NK_INTEGER */ -#line 169 "sql.y" { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_SNODE_STMT, &yymsp[0].minor.yy0); } -#line 5170 "sql.c" break; case 72: /* cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ -#line 172 "sql.y" { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_MNODE_STMT, &yymsp[0].minor.yy0); } -#line 5175 "sql.c" break; case 73: /* cmd ::= DROP MNODE ON DNODE NK_INTEGER */ -#line 173 "sql.y" { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &yymsp[0].minor.yy0); } -#line 5180 "sql.c" break; case 74: /* cmd ::= RESTORE MNODE ON DNODE NK_INTEGER */ -#line 174 "sql.y" { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_MNODE_STMT, &yymsp[0].minor.yy0); } -#line 5185 "sql.c" break; case 75: /* cmd ::= RESTORE VNODE ON DNODE NK_INTEGER */ -#line 177 "sql.y" { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_VNODE_STMT, &yymsp[0].minor.yy0); } -#line 5190 "sql.c" break; case 76: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -#line 180 "sql.y" { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy957, &yymsp[-1].minor.yy169, yymsp[0].minor.yy952); } -#line 5195 "sql.c" break; case 77: /* cmd ::= DROP DATABASE exists_opt db_name */ -#line 181 "sql.y" { pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy957, &yymsp[0].minor.yy169); } -#line 5200 "sql.c" break; case 78: /* cmd ::= USE db_name */ -#line 182 "sql.y" { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy169); } -#line 5205 "sql.c" break; case 79: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -#line 183 "sql.y" { pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy169, yymsp[0].minor.yy952); } -#line 5210 "sql.c" break; case 80: /* cmd ::= FLUSH DATABASE db_name */ -#line 184 "sql.y" { pCxt->pRootNode = createFlushDatabaseStmt(pCxt, &yymsp[0].minor.yy169); } -#line 5215 "sql.c" break; case 81: /* cmd ::= TRIM DATABASE db_name speed_opt */ -#line 185 "sql.y" { pCxt->pRootNode = createTrimDatabaseStmt(pCxt, &yymsp[-1].minor.yy169, yymsp[0].minor.yy480); } -#line 5220 "sql.c" break; case 82: /* cmd ::= COMPACT DATABASE db_name start_opt end_opt */ -#line 186 "sql.y" { pCxt->pRootNode = createCompactStmt(pCxt, &yymsp[-2].minor.yy169, yymsp[-1].minor.yy952, yymsp[0].minor.yy952); } -#line 5225 "sql.c" break; case 83: /* not_exists_opt ::= IF NOT EXISTS */ -#line 190 "sql.y" { yymsp[-2].minor.yy957 = true; } -#line 5230 "sql.c" break; case 85: /* exists_opt ::= IF EXISTS */ case 335: /* or_replace_opt ::= OR REPLACE */ yytestcase(yyruleno==335); case 357: /* ignore_opt ::= IGNORE UNTREATED */ yytestcase(yyruleno==357); -#line 195 "sql.y" { yymsp[-1].minor.yy957 = true; } -#line 5237 "sql.c" break; case 87: /* db_options ::= */ -#line 198 "sql.y" { yymsp[1].minor.yy952 = createDefaultDatabaseOptions(pCxt); } -#line 5242 "sql.c" break; case 88: /* db_options ::= db_options BUFFER NK_INTEGER */ -#line 199 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } -#line 5247 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 89: /* db_options ::= db_options CACHEMODEL NK_STRING */ -#line 200 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_CACHEMODEL, &yymsp[0].minor.yy0); } -#line 5253 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 90: /* db_options ::= db_options CACHESIZE NK_INTEGER */ -#line 201 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_CACHESIZE, &yymsp[0].minor.yy0); } -#line 5259 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 91: /* db_options ::= db_options COMP NK_INTEGER */ -#line 202 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_COMP, &yymsp[0].minor.yy0); } -#line 5265 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 92: /* db_options ::= db_options DURATION NK_INTEGER */ case 93: /* db_options ::= db_options DURATION NK_VARIABLE */ yytestcase(yyruleno==93); -#line 203 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } -#line 5272 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 94: /* db_options ::= db_options MAXROWS NK_INTEGER */ -#line 205 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } -#line 5278 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 95: /* db_options ::= db_options MINROWS NK_INTEGER */ -#line 206 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } -#line 5284 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 96: /* db_options ::= db_options KEEP integer_list */ case 97: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==97); -#line 207 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_KEEP, yymsp[0].minor.yy824); } -#line 5291 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 98: /* db_options ::= db_options PAGES NK_INTEGER */ -#line 209 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } -#line 5297 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 99: /* db_options ::= db_options PAGESIZE NK_INTEGER */ -#line 210 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } -#line 5303 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 100: /* db_options ::= db_options TSDB_PAGESIZE NK_INTEGER */ -#line 211 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_TSDB_PAGESIZE, &yymsp[0].minor.yy0); } -#line 5309 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 101: /* db_options ::= db_options PRECISION NK_STRING */ -#line 212 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } -#line 5315 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 102: /* db_options ::= db_options REPLICA NK_INTEGER */ -#line 213 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } -#line 5321 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 103: /* db_options ::= db_options VGROUPS NK_INTEGER */ -#line 215 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } -#line 5327 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 104: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -#line 216 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } -#line 5333 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 105: /* db_options ::= db_options RETENTIONS retention_list */ -#line 217 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_RETENTIONS, yymsp[0].minor.yy824); } -#line 5339 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 106: /* db_options ::= db_options SCHEMALESS NK_INTEGER */ -#line 218 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); } -#line 5345 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 107: /* db_options ::= db_options WAL_LEVEL NK_INTEGER */ -#line 219 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_WAL, &yymsp[0].minor.yy0); } -#line 5351 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 108: /* db_options ::= db_options WAL_FSYNC_PERIOD NK_INTEGER */ -#line 220 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } -#line 5357 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 109: /* db_options ::= db_options WAL_RETENTION_PERIOD NK_INTEGER */ -#line 221 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_WAL_RETENTION_PERIOD, &yymsp[0].minor.yy0); } -#line 5363 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 110: /* db_options ::= db_options WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER */ -#line 222 "sql.y" { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-3].minor.yy952, DB_OPTION_WAL_RETENTION_PERIOD, &t); } -#line 5373 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 111: /* db_options ::= db_options WAL_RETENTION_SIZE NK_INTEGER */ -#line 227 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_WAL_RETENTION_SIZE, &yymsp[0].minor.yy0); } -#line 5379 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 112: /* db_options ::= db_options WAL_RETENTION_SIZE NK_MINUS NK_INTEGER */ -#line 228 "sql.y" { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-3].minor.yy952, DB_OPTION_WAL_RETENTION_SIZE, &t); } -#line 5389 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 113: /* db_options ::= db_options WAL_ROLL_PERIOD NK_INTEGER */ -#line 233 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_WAL_ROLL_PERIOD, &yymsp[0].minor.yy0); } -#line 5395 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 114: /* db_options ::= db_options WAL_SEGMENT_SIZE NK_INTEGER */ -#line 234 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_WAL_SEGMENT_SIZE, &yymsp[0].minor.yy0); } -#line 5401 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 115: /* db_options ::= db_options STT_TRIGGER NK_INTEGER */ -#line 235 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_STT_TRIGGER, &yymsp[0].minor.yy0); } -#line 5407 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 116: /* db_options ::= db_options TABLE_PREFIX signed */ -#line 236 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_TABLE_PREFIX, yymsp[0].minor.yy952); } -#line 5413 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 117: /* db_options ::= db_options TABLE_SUFFIX signed */ -#line 237 "sql.y" { yylhsminor.yy952 = setDatabaseOption(pCxt, yymsp[-2].minor.yy952, DB_OPTION_TABLE_SUFFIX, yymsp[0].minor.yy952); } -#line 5419 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 118: /* alter_db_options ::= alter_db_option */ -#line 239 "sql.y" { yylhsminor.yy952 = createAlterDatabaseOptions(pCxt); yylhsminor.yy952 = setAlterDatabaseOption(pCxt, yylhsminor.yy952, &yymsp[0].minor.yy25); } -#line 5425 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 119: /* alter_db_options ::= alter_db_options alter_db_option */ -#line 240 "sql.y" { yylhsminor.yy952 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy952, &yymsp[0].minor.yy25); } -#line 5431 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 120: /* alter_db_option ::= BUFFER NK_INTEGER */ -#line 244 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5437 "sql.c" break; case 121: /* alter_db_option ::= CACHEMODEL NK_STRING */ -#line 245 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_CACHEMODEL; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5442 "sql.c" break; case 122: /* alter_db_option ::= CACHESIZE NK_INTEGER */ -#line 246 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_CACHESIZE; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5447 "sql.c" break; case 123: /* alter_db_option ::= WAL_FSYNC_PERIOD NK_INTEGER */ -#line 247 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5452 "sql.c" break; case 124: /* alter_db_option ::= KEEP integer_list */ case 125: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==125); -#line 248 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_KEEP; yymsp[-1].minor.yy25.pList = yymsp[0].minor.yy824; } -#line 5458 "sql.c" break; case 126: /* alter_db_option ::= PAGES NK_INTEGER */ -#line 250 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_PAGES; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5463 "sql.c" break; case 127: /* alter_db_option ::= REPLICA NK_INTEGER */ -#line 251 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5468 "sql.c" break; case 128: /* alter_db_option ::= WAL_LEVEL NK_INTEGER */ -#line 253 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_WAL; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5473 "sql.c" break; case 129: /* alter_db_option ::= STT_TRIGGER NK_INTEGER */ -#line 254 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_STT_TRIGGER; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5478 "sql.c" break; case 130: /* alter_db_option ::= MINROWS NK_INTEGER */ -#line 255 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_MINROWS; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5483 "sql.c" break; case 131: /* alter_db_option ::= WAL_RETENTION_PERIOD NK_INTEGER */ -#line 256 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_WAL_RETENTION_PERIOD; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5488 "sql.c" break; case 132: /* alter_db_option ::= WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER */ -#line 257 "sql.y" { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; yymsp[-2].minor.yy25.type = DB_OPTION_WAL_RETENTION_PERIOD; yymsp[-2].minor.yy25.val = t; } -#line 5497 "sql.c" break; case 133: /* alter_db_option ::= WAL_RETENTION_SIZE NK_INTEGER */ -#line 262 "sql.y" { yymsp[-1].minor.yy25.type = DB_OPTION_WAL_RETENTION_SIZE; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5502 "sql.c" break; case 134: /* alter_db_option ::= WAL_RETENTION_SIZE NK_MINUS NK_INTEGER */ -#line 263 "sql.y" { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; yymsp[-2].minor.yy25.type = DB_OPTION_WAL_RETENTION_SIZE; yymsp[-2].minor.yy25.val = t; } -#line 5511 "sql.c" break; case 135: /* integer_list ::= NK_INTEGER */ -#line 271 "sql.y" { yylhsminor.yy824 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } -#line 5516 "sql.c" yymsp[0].minor.yy824 = yylhsminor.yy824; break; case 136: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ case 367: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==367); -#line 272 "sql.y" { yylhsminor.yy824 = addNodeToList(pCxt, yymsp[-2].minor.yy824, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } -#line 5523 "sql.c" yymsp[-2].minor.yy824 = yylhsminor.yy824; break; case 137: /* variable_list ::= NK_VARIABLE */ -#line 276 "sql.y" { yylhsminor.yy824 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } -#line 5529 "sql.c" yymsp[0].minor.yy824 = yylhsminor.yy824; break; case 138: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ -#line 277 "sql.y" { yylhsminor.yy824 = addNodeToList(pCxt, yymsp[-2].minor.yy824, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } -#line 5535 "sql.c" yymsp[-2].minor.yy824 = yylhsminor.yy824; break; case 139: /* retention_list ::= retention */ @@ -5549,9 +5000,7 @@ static YYACTIONTYPE yy_reduce( case 528: /* select_list ::= select_item */ yytestcase(yyruleno==528); case 539: /* partition_list ::= partition_item */ yytestcase(yyruleno==539); case 595: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==595); -#line 281 "sql.y" { yylhsminor.yy824 = createNodeList(pCxt, yymsp[0].minor.yy952); } -#line 5554 "sql.c" yymsp[0].minor.yy824 = yylhsminor.yy824; break; case 140: /* retention_list ::= retention_list NK_COMMA retention */ @@ -5566,157 +5015,105 @@ static YYACTIONTYPE yy_reduce( case 529: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==529); case 540: /* partition_list ::= partition_list NK_COMMA partition_item */ yytestcase(yyruleno==540); case 596: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==596); -#line 282 "sql.y" { yylhsminor.yy824 = addNodeToList(pCxt, yymsp[-2].minor.yy824, yymsp[0].minor.yy952); } -#line 5571 "sql.c" yymsp[-2].minor.yy824 = yylhsminor.yy824; break; case 141: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ -#line 284 "sql.y" { yylhsminor.yy952 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } -#line 5577 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 142: /* speed_opt ::= */ case 330: /* bufsize_opt ::= */ yytestcase(yyruleno==330); -#line 288 "sql.y" { yymsp[1].minor.yy480 = 0; } -#line 5584 "sql.c" break; - case 143: /* speed_opt ::= MAX_SPEED NK_INTEGER */ + case 143: /* speed_opt ::= BWLIMIT NK_INTEGER */ case 331: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ yytestcase(yyruleno==331); -#line 289 "sql.y" { yymsp[-1].minor.yy480 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } -#line 5590 "sql.c" break; case 145: /* start_opt ::= START WITH NK_INTEGER */ case 149: /* end_opt ::= END WITH NK_INTEGER */ yytestcase(yyruleno==149); -#line 292 "sql.y" { yymsp[-2].minor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } -#line 5596 "sql.c" break; case 146: /* start_opt ::= START WITH NK_STRING */ case 150: /* end_opt ::= END WITH NK_STRING */ yytestcase(yyruleno==150); -#line 293 "sql.y" { yymsp[-2].minor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } -#line 5602 "sql.c" break; case 147: /* start_opt ::= START WITH TIMESTAMP NK_STRING */ case 151: /* end_opt ::= END WITH TIMESTAMP NK_STRING */ yytestcase(yyruleno==151); -#line 294 "sql.y" { yymsp[-3].minor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } -#line 5608 "sql.c" break; case 152: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ case 154: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==154); -#line 303 "sql.y" { pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy957, yymsp[-5].minor.yy952, yymsp[-3].minor.yy824, yymsp[-1].minor.yy824, yymsp[0].minor.yy952); } -#line 5614 "sql.c" break; case 153: /* cmd ::= CREATE TABLE multi_create_clause */ -#line 304 "sql.y" { pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy824); } -#line 5619 "sql.c" break; case 155: /* cmd ::= DROP TABLE multi_drop_clause */ -#line 307 "sql.y" { pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy824); } -#line 5624 "sql.c" break; case 156: /* cmd ::= DROP STABLE exists_opt full_table_name */ -#line 308 "sql.y" { pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy957, yymsp[0].minor.yy952); } -#line 5629 "sql.c" break; case 157: /* cmd ::= ALTER TABLE alter_table_clause */ case 369: /* cmd ::= query_or_subquery */ yytestcase(yyruleno==369); case 370: /* cmd ::= insert_query */ yytestcase(yyruleno==370); -#line 310 "sql.y" { pCxt->pRootNode = yymsp[0].minor.yy952; } -#line 5636 "sql.c" break; case 158: /* cmd ::= ALTER STABLE alter_table_clause */ -#line 311 "sql.y" { pCxt->pRootNode = setAlterSuperTableType(yymsp[0].minor.yy952); } -#line 5641 "sql.c" break; case 159: /* alter_table_clause ::= full_table_name alter_table_options */ -#line 313 "sql.y" { yylhsminor.yy952 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy952, yymsp[0].minor.yy952); } -#line 5646 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 160: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -#line 315 "sql.y" { yylhsminor.yy952 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy952, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy169, yymsp[0].minor.yy84); } -#line 5652 "sql.c" yymsp[-4].minor.yy952 = yylhsminor.yy952; break; case 161: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -#line 316 "sql.y" { yylhsminor.yy952 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy952, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy169); } -#line 5658 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 162: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -#line 318 "sql.y" { yylhsminor.yy952 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy952, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy169, yymsp[0].minor.yy84); } -#line 5664 "sql.c" yymsp[-4].minor.yy952 = yylhsminor.yy952; break; case 163: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -#line 320 "sql.y" { yylhsminor.yy952 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy952, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy169, &yymsp[0].minor.yy169); } -#line 5670 "sql.c" yymsp[-4].minor.yy952 = yylhsminor.yy952; break; case 164: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -#line 322 "sql.y" { yylhsminor.yy952 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy952, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy169, yymsp[0].minor.yy84); } -#line 5676 "sql.c" yymsp[-4].minor.yy952 = yylhsminor.yy952; break; case 165: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -#line 323 "sql.y" { yylhsminor.yy952 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy952, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy169); } -#line 5682 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 166: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -#line 325 "sql.y" { yylhsminor.yy952 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy952, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy169, yymsp[0].minor.yy84); } -#line 5688 "sql.c" yymsp[-4].minor.yy952 = yylhsminor.yy952; break; case 167: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -#line 327 "sql.y" { yylhsminor.yy952 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy952, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy169, &yymsp[0].minor.yy169); } -#line 5694 "sql.c" yymsp[-4].minor.yy952 = yylhsminor.yy952; break; case 168: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ -#line 329 "sql.y" { yylhsminor.yy952 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy952, &yymsp[-2].minor.yy169, yymsp[0].minor.yy952); } -#line 5700 "sql.c" yymsp[-5].minor.yy952 = yylhsminor.yy952; break; case 170: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ case 470: /* when_then_list ::= when_then_list when_then_expr */ yytestcase(yyruleno==470); -#line 334 "sql.y" { yylhsminor.yy824 = addNodeToList(pCxt, yymsp[-1].minor.yy824, yymsp[0].minor.yy952); } -#line 5707 "sql.c" yymsp[-1].minor.yy824 = yylhsminor.yy824; break; case 171: /* 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 */ -#line 338 "sql.y" { yylhsminor.yy952 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy957, yymsp[-8].minor.yy952, yymsp[-6].minor.yy952, yymsp[-5].minor.yy824, yymsp[-2].minor.yy824, yymsp[0].minor.yy952); } -#line 5713 "sql.c" yymsp[-9].minor.yy952 = yylhsminor.yy952; break; case 174: /* drop_table_clause ::= exists_opt full_table_name */ -#line 345 "sql.y" { yylhsminor.yy952 = createDropTableClause(pCxt, yymsp[-1].minor.yy957, yymsp[0].minor.yy952); } -#line 5719 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 175: /* specific_cols_opt ::= */ @@ -5727,847 +5124,535 @@ static YYACTIONTYPE yy_reduce( case 537: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==537); case 562: /* group_by_clause_opt ::= */ yytestcase(yyruleno==562); case 582: /* order_by_clause_opt ::= */ yytestcase(yyruleno==582); -#line 349 "sql.y" { yymsp[1].minor.yy824 = NULL; } -#line 5732 "sql.c" break; case 176: /* specific_cols_opt ::= NK_LP col_name_list NK_RP */ case 341: /* col_list_opt ::= NK_LP col_name_list NK_RP */ yytestcase(yyruleno==341); -#line 350 "sql.y" { yymsp[-2].minor.yy824 = yymsp[-1].minor.yy824; } -#line 5738 "sql.c" break; case 177: /* full_table_name ::= table_name */ -#line 352 "sql.y" { yylhsminor.yy952 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy169, NULL); } -#line 5743 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 178: /* full_table_name ::= db_name NK_DOT table_name */ -#line 353 "sql.y" { yylhsminor.yy952 = createRealTableNode(pCxt, &yymsp[-2].minor.yy169, &yymsp[0].minor.yy169, NULL); } -#line 5749 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 181: /* column_def ::= column_name type_name */ -#line 360 "sql.y" { yylhsminor.yy952 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy169, yymsp[0].minor.yy84, NULL); } -#line 5755 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 182: /* type_name ::= BOOL */ -#line 365 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_BOOL); } -#line 5761 "sql.c" break; case 183: /* type_name ::= TINYINT */ -#line 366 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_TINYINT); } -#line 5766 "sql.c" break; case 184: /* type_name ::= SMALLINT */ -#line 367 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_SMALLINT); } -#line 5771 "sql.c" break; case 185: /* type_name ::= INT */ case 186: /* type_name ::= INTEGER */ yytestcase(yyruleno==186); -#line 368 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_INT); } -#line 5777 "sql.c" break; case 187: /* type_name ::= BIGINT */ -#line 370 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_BIGINT); } -#line 5782 "sql.c" break; case 188: /* type_name ::= FLOAT */ -#line 371 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_FLOAT); } -#line 5787 "sql.c" break; case 189: /* type_name ::= DOUBLE */ -#line 372 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_DOUBLE); } -#line 5792 "sql.c" break; case 190: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -#line 373 "sql.y" { yymsp[-3].minor.yy84 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } -#line 5797 "sql.c" break; case 191: /* type_name ::= TIMESTAMP */ -#line 374 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } -#line 5802 "sql.c" break; case 192: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -#line 375 "sql.y" { yymsp[-3].minor.yy84 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } -#line 5807 "sql.c" break; case 193: /* type_name ::= TINYINT UNSIGNED */ -#line 376 "sql.y" { yymsp[-1].minor.yy84 = createDataType(TSDB_DATA_TYPE_UTINYINT); } -#line 5812 "sql.c" break; case 194: /* type_name ::= SMALLINT UNSIGNED */ -#line 377 "sql.y" { yymsp[-1].minor.yy84 = createDataType(TSDB_DATA_TYPE_USMALLINT); } -#line 5817 "sql.c" break; case 195: /* type_name ::= INT UNSIGNED */ -#line 378 "sql.y" { yymsp[-1].minor.yy84 = createDataType(TSDB_DATA_TYPE_UINT); } -#line 5822 "sql.c" break; case 196: /* type_name ::= BIGINT UNSIGNED */ -#line 379 "sql.y" { yymsp[-1].minor.yy84 = createDataType(TSDB_DATA_TYPE_UBIGINT); } -#line 5827 "sql.c" break; case 197: /* type_name ::= JSON */ -#line 380 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_JSON); } -#line 5832 "sql.c" break; case 198: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -#line 381 "sql.y" { yymsp[-3].minor.yy84 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } -#line 5837 "sql.c" break; case 199: /* type_name ::= MEDIUMBLOB */ -#line 382 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } -#line 5842 "sql.c" break; case 200: /* type_name ::= BLOB */ -#line 383 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_BLOB); } -#line 5847 "sql.c" break; case 201: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -#line 384 "sql.y" { yymsp[-3].minor.yy84 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } -#line 5852 "sql.c" break; case 202: /* type_name ::= GEOMETRY NK_LP NK_INTEGER NK_RP */ -#line 385 "sql.y" { yymsp[-3].minor.yy84 = createVarLenDataType(TSDB_DATA_TYPE_GEOMETRY, &yymsp[-1].minor.yy0); } -#line 5857 "sql.c" break; case 203: /* type_name ::= DECIMAL */ -#line 386 "sql.y" { yymsp[0].minor.yy84 = createDataType(TSDB_DATA_TYPE_DECIMAL); } -#line 5862 "sql.c" break; case 204: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -#line 387 "sql.y" { yymsp[-3].minor.yy84 = createDataType(TSDB_DATA_TYPE_DECIMAL); } -#line 5867 "sql.c" break; case 205: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -#line 388 "sql.y" { yymsp[-5].minor.yy84 = createDataType(TSDB_DATA_TYPE_DECIMAL); } -#line 5872 "sql.c" break; case 207: /* tags_def_opt ::= tags_def */ case 343: /* tag_def_or_ref_opt ::= tags_def */ yytestcase(yyruleno==343); case 462: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==462); -#line 393 "sql.y" { yylhsminor.yy824 = yymsp[0].minor.yy824; } -#line 5879 "sql.c" yymsp[0].minor.yy824 = yylhsminor.yy824; break; case 208: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ case 344: /* tag_def_or_ref_opt ::= TAGS NK_LP col_name_list NK_RP */ yytestcase(yyruleno==344); -#line 397 "sql.y" { yymsp[-3].minor.yy824 = yymsp[-1].minor.yy824; } -#line 5886 "sql.c" break; case 209: /* table_options ::= */ -#line 399 "sql.y" { yymsp[1].minor.yy952 = createDefaultTableOptions(pCxt); } -#line 5891 "sql.c" break; case 210: /* table_options ::= table_options COMMENT NK_STRING */ -#line 400 "sql.y" { yylhsminor.yy952 = setTableOption(pCxt, yymsp[-2].minor.yy952, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } -#line 5896 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 211: /* table_options ::= table_options MAX_DELAY duration_list */ -#line 401 "sql.y" { yylhsminor.yy952 = setTableOption(pCxt, yymsp[-2].minor.yy952, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy824); } -#line 5902 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 212: /* table_options ::= table_options WATERMARK duration_list */ -#line 402 "sql.y" { yylhsminor.yy952 = setTableOption(pCxt, yymsp[-2].minor.yy952, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy824); } -#line 5908 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 213: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ -#line 403 "sql.y" { yylhsminor.yy952 = setTableOption(pCxt, yymsp[-4].minor.yy952, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy824); } -#line 5914 "sql.c" yymsp[-4].minor.yy952 = yylhsminor.yy952; break; case 214: /* table_options ::= table_options TTL NK_INTEGER */ -#line 404 "sql.y" { yylhsminor.yy952 = setTableOption(pCxt, yymsp[-2].minor.yy952, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } -#line 5920 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 215: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -#line 405 "sql.y" { yylhsminor.yy952 = setTableOption(pCxt, yymsp[-4].minor.yy952, TABLE_OPTION_SMA, yymsp[-1].minor.yy824); } -#line 5926 "sql.c" yymsp[-4].minor.yy952 = yylhsminor.yy952; break; case 216: /* table_options ::= table_options DELETE_MARK duration_list */ -#line 406 "sql.y" { yylhsminor.yy952 = setTableOption(pCxt, yymsp[-2].minor.yy952, TABLE_OPTION_DELETE_MARK, yymsp[0].minor.yy824); } -#line 5932 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 217: /* alter_table_options ::= alter_table_option */ -#line 408 "sql.y" { yylhsminor.yy952 = createAlterTableOptions(pCxt); yylhsminor.yy952 = setTableOption(pCxt, yylhsminor.yy952, yymsp[0].minor.yy25.type, &yymsp[0].minor.yy25.val); } -#line 5938 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 218: /* alter_table_options ::= alter_table_options alter_table_option */ -#line 409 "sql.y" { yylhsminor.yy952 = setTableOption(pCxt, yymsp[-1].minor.yy952, yymsp[0].minor.yy25.type, &yymsp[0].minor.yy25.val); } -#line 5944 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 219: /* alter_table_option ::= COMMENT NK_STRING */ -#line 413 "sql.y" { yymsp[-1].minor.yy25.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5950 "sql.c" break; case 220: /* alter_table_option ::= TTL NK_INTEGER */ -#line 414 "sql.y" { yymsp[-1].minor.yy25.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy25.val = yymsp[0].minor.yy0; } -#line 5955 "sql.c" break; case 221: /* duration_list ::= duration_literal */ case 426: /* expression_list ::= expr_or_subquery */ yytestcase(yyruleno==426); -#line 418 "sql.y" { yylhsminor.yy824 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy952)); } -#line 5961 "sql.c" yymsp[0].minor.yy824 = yylhsminor.yy824; break; case 222: /* duration_list ::= duration_list NK_COMMA duration_literal */ case 427: /* expression_list ::= expression_list NK_COMMA expr_or_subquery */ yytestcase(yyruleno==427); -#line 419 "sql.y" { yylhsminor.yy824 = addNodeToList(pCxt, yymsp[-2].minor.yy824, releaseRawExprNode(pCxt, yymsp[0].minor.yy952)); } -#line 5968 "sql.c" yymsp[-2].minor.yy824 = yylhsminor.yy824; break; case 225: /* rollup_func_name ::= function_name */ -#line 426 "sql.y" { yylhsminor.yy952 = createFunctionNode(pCxt, &yymsp[0].minor.yy169, NULL); } -#line 5974 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 226: /* rollup_func_name ::= FIRST */ case 227: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==227); case 285: /* tag_item ::= QTAGS */ yytestcase(yyruleno==285); -#line 427 "sql.y" { yylhsminor.yy952 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } -#line 5982 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 230: /* col_name ::= column_name */ case 286: /* tag_item ::= column_name */ yytestcase(yyruleno==286); -#line 435 "sql.y" { yylhsminor.yy952 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy169); } -#line 5989 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 231: /* cmd ::= SHOW DNODES */ -#line 438 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); } -#line 5995 "sql.c" break; case 232: /* cmd ::= SHOW USERS */ -#line 439 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); } -#line 6000 "sql.c" break; case 233: /* cmd ::= SHOW USER PRIVILEGES */ -#line 440 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USER_PRIVILEGES_STMT); } -#line 6005 "sql.c" break; case 234: /* cmd ::= SHOW DATABASES */ -#line 441 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); } -#line 6010 "sql.c" break; case 235: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -#line 442 "sql.y" { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy952, yymsp[0].minor.yy952, OP_TYPE_LIKE); } -#line 6015 "sql.c" break; case 236: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -#line 443 "sql.y" { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy952, yymsp[0].minor.yy952, OP_TYPE_LIKE); } -#line 6020 "sql.c" break; case 237: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -#line 444 "sql.y" { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy952, NULL, OP_TYPE_LIKE); } -#line 6025 "sql.c" break; case 238: /* cmd ::= SHOW MNODES */ -#line 445 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT); } -#line 6030 "sql.c" break; case 239: /* cmd ::= SHOW QNODES */ -#line 447 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT); } -#line 6035 "sql.c" break; case 240: /* cmd ::= SHOW FUNCTIONS */ -#line 448 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT); } -#line 6040 "sql.c" break; case 241: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -#line 449 "sql.y" { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy952, yymsp[-1].minor.yy952, OP_TYPE_EQUAL); } -#line 6045 "sql.c" break; case 242: /* cmd ::= SHOW INDEXES FROM db_name NK_DOT table_name */ -#line 450 "sql.y" { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, createIdentifierValueNode(pCxt, &yymsp[-2].minor.yy169), createIdentifierValueNode(pCxt, &yymsp[0].minor.yy169), OP_TYPE_EQUAL); } -#line 6050 "sql.c" break; case 243: /* cmd ::= SHOW STREAMS */ -#line 451 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT); } -#line 6055 "sql.c" break; case 244: /* cmd ::= SHOW ACCOUNTS */ -#line 452 "sql.y" { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } -#line 6060 "sql.c" break; case 245: /* cmd ::= SHOW APPS */ -#line 453 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT); } -#line 6065 "sql.c" break; case 246: /* cmd ::= SHOW CONNECTIONS */ -#line 454 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT); } -#line 6070 "sql.c" break; case 247: /* cmd ::= SHOW LICENCES */ case 248: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==248); -#line 455 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCES_STMT); } -#line 6076 "sql.c" break; case 249: /* cmd ::= SHOW CREATE DATABASE db_name */ -#line 457 "sql.y" { pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy169); } -#line 6081 "sql.c" break; case 250: /* cmd ::= SHOW CREATE TABLE full_table_name */ -#line 458 "sql.y" { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy952); } -#line 6086 "sql.c" break; case 251: /* cmd ::= SHOW CREATE STABLE full_table_name */ -#line 459 "sql.y" { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy952); } -#line 6091 "sql.c" break; case 252: /* cmd ::= SHOW QUERIES */ -#line 460 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); } -#line 6096 "sql.c" break; case 253: /* cmd ::= SHOW SCORES */ -#line 461 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); } -#line 6101 "sql.c" break; case 254: /* cmd ::= SHOW TOPICS */ -#line 462 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); } -#line 6106 "sql.c" break; case 255: /* cmd ::= SHOW VARIABLES */ case 256: /* cmd ::= SHOW CLUSTER VARIABLES */ yytestcase(yyruleno==256); -#line 463 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } -#line 6112 "sql.c" break; case 257: /* cmd ::= SHOW LOCAL VARIABLES */ -#line 465 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); } -#line 6117 "sql.c" break; case 258: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES like_pattern_opt */ -#line 466 "sql.y" { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[-2].minor.yy0), yymsp[0].minor.yy952); } -#line 6122 "sql.c" break; case 259: /* cmd ::= SHOW BNODES */ -#line 467 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); } -#line 6127 "sql.c" break; case 260: /* cmd ::= SHOW SNODES */ -#line 468 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); } -#line 6132 "sql.c" break; case 261: /* cmd ::= SHOW CLUSTER */ -#line 469 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); } -#line 6137 "sql.c" break; case 262: /* cmd ::= SHOW TRANSACTIONS */ -#line 470 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); } -#line 6142 "sql.c" break; case 263: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ -#line 471 "sql.y" { pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy952); } -#line 6147 "sql.c" break; case 264: /* cmd ::= SHOW CONSUMERS */ -#line 472 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); } -#line 6152 "sql.c" break; case 265: /* cmd ::= SHOW SUBSCRIPTIONS */ -#line 473 "sql.y" { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); } -#line 6157 "sql.c" break; case 266: /* cmd ::= SHOW TAGS FROM table_name_cond from_db_opt */ -#line 474 "sql.y" { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TAGS_STMT, yymsp[0].minor.yy952, yymsp[-1].minor.yy952, OP_TYPE_EQUAL); } -#line 6162 "sql.c" break; case 267: /* cmd ::= SHOW TAGS FROM db_name NK_DOT table_name */ -#line 475 "sql.y" { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TAGS_STMT, createIdentifierValueNode(pCxt, &yymsp[-2].minor.yy169), createIdentifierValueNode(pCxt, &yymsp[0].minor.yy169), OP_TYPE_EQUAL); } -#line 6167 "sql.c" break; case 268: /* cmd ::= SHOW TABLE TAGS tag_list_opt FROM table_name_cond from_db_opt */ -#line 476 "sql.y" { pCxt->pRootNode = createShowTableTagsStmt(pCxt, yymsp[-1].minor.yy952, yymsp[0].minor.yy952, yymsp[-3].minor.yy824); } -#line 6172 "sql.c" break; case 269: /* cmd ::= SHOW TABLE TAGS tag_list_opt FROM db_name NK_DOT table_name */ -#line 477 "sql.y" { pCxt->pRootNode = createShowTableTagsStmt(pCxt, createIdentifierValueNode(pCxt, &yymsp[0].minor.yy169), createIdentifierValueNode(pCxt, &yymsp[-2].minor.yy169), yymsp[-4].minor.yy824); } -#line 6177 "sql.c" break; case 270: /* cmd ::= SHOW VNODES ON DNODE NK_INTEGER */ -#line 478 "sql.y" { pCxt->pRootNode = createShowVnodesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0), NULL); } -#line 6182 "sql.c" break; case 271: /* cmd ::= SHOW VNODES */ -#line 479 "sql.y" { pCxt->pRootNode = createShowVnodesStmt(pCxt, NULL, NULL); } -#line 6187 "sql.c" break; case 272: /* cmd ::= SHOW db_name_cond_opt ALIVE */ -#line 481 "sql.y" { pCxt->pRootNode = createShowAliveStmt(pCxt, yymsp[-1].minor.yy952, QUERY_NODE_SHOW_DB_ALIVE_STMT); } -#line 6192 "sql.c" break; case 273: /* cmd ::= SHOW CLUSTER ALIVE */ -#line 482 "sql.y" { pCxt->pRootNode = createShowAliveStmt(pCxt, NULL, QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT); } -#line 6197 "sql.c" break; case 274: /* db_name_cond_opt ::= */ case 279: /* from_db_opt ::= */ yytestcase(yyruleno==279); -#line 484 "sql.y" { yymsp[1].minor.yy952 = createDefaultDatabaseCondValue(pCxt); } -#line 6203 "sql.c" break; case 275: /* db_name_cond_opt ::= db_name NK_DOT */ -#line 485 "sql.y" { yylhsminor.yy952 = createIdentifierValueNode(pCxt, &yymsp[-1].minor.yy169); } -#line 6208 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 277: /* like_pattern_opt ::= LIKE NK_STRING */ -#line 488 "sql.y" { yymsp[-1].minor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } -#line 6214 "sql.c" break; case 278: /* table_name_cond ::= table_name */ -#line 490 "sql.y" { yylhsminor.yy952 = createIdentifierValueNode(pCxt, &yymsp[0].minor.yy169); } -#line 6219 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 280: /* from_db_opt ::= FROM db_name */ -#line 493 "sql.y" { yymsp[-1].minor.yy952 = createIdentifierValueNode(pCxt, &yymsp[0].minor.yy169); } -#line 6225 "sql.c" break; case 284: /* tag_item ::= TBNAME */ -#line 501 "sql.y" { yylhsminor.yy952 = setProjectionAlias(pCxt, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL), &yymsp[0].minor.yy0); } -#line 6230 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 287: /* tag_item ::= column_name column_alias */ -#line 504 "sql.y" { yylhsminor.yy952 = setProjectionAlias(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy169), &yymsp[0].minor.yy169); } -#line 6236 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 288: /* tag_item ::= column_name AS column_alias */ -#line 505 "sql.y" { yylhsminor.yy952 = setProjectionAlias(pCxt, createColumnNode(pCxt, NULL, &yymsp[-2].minor.yy169), &yymsp[0].minor.yy169); } -#line 6242 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 289: /* cmd ::= CREATE SMA INDEX not_exists_opt full_index_name ON full_table_name index_options */ -#line 509 "sql.y" { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy957, yymsp[-3].minor.yy952, yymsp[-1].minor.yy952, NULL, yymsp[0].minor.yy952); } -#line 6248 "sql.c" break; case 290: /* cmd ::= CREATE INDEX not_exists_opt full_index_name ON full_table_name NK_LP col_name_list NK_RP */ -#line 511 "sql.y" { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_NORMAL, yymsp[-6].minor.yy957, yymsp[-5].minor.yy952, yymsp[-3].minor.yy952, yymsp[-1].minor.yy824, NULL); } -#line 6253 "sql.c" break; case 291: /* cmd ::= DROP INDEX exists_opt full_index_name */ -#line 512 "sql.y" { pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-1].minor.yy957, yymsp[0].minor.yy952); } -#line 6258 "sql.c" break; case 292: /* full_index_name ::= index_name */ -#line 514 "sql.y" { yylhsminor.yy952 = createRealTableNodeForIndexName(pCxt, NULL, &yymsp[0].minor.yy169); } -#line 6263 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 293: /* full_index_name ::= db_name NK_DOT index_name */ -#line 515 "sql.y" { yylhsminor.yy952 = createRealTableNodeForIndexName(pCxt, &yymsp[-2].minor.yy169, &yymsp[0].minor.yy169); } -#line 6269 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 294: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ -#line 518 "sql.y" { yymsp[-9].minor.yy952 = createIndexOption(pCxt, yymsp[-7].minor.yy824, releaseRawExprNode(pCxt, yymsp[-3].minor.yy952), NULL, yymsp[-1].minor.yy952, yymsp[0].minor.yy952); } -#line 6275 "sql.c" break; case 295: /* 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 */ -#line 521 "sql.y" { yymsp[-11].minor.yy952 = createIndexOption(pCxt, yymsp[-9].minor.yy824, releaseRawExprNode(pCxt, yymsp[-5].minor.yy952), releaseRawExprNode(pCxt, yymsp[-3].minor.yy952), yymsp[-1].minor.yy952, yymsp[0].minor.yy952); } -#line 6280 "sql.c" break; case 298: /* func ::= sma_func_name NK_LP expression_list NK_RP */ -#line 528 "sql.y" { yylhsminor.yy952 = createFunctionNode(pCxt, &yymsp[-3].minor.yy169, yymsp[-1].minor.yy824); } -#line 6285 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 299: /* sma_func_name ::= function_name */ case 513: /* alias_opt ::= table_alias */ yytestcase(yyruleno==513); -#line 532 "sql.y" { yylhsminor.yy169 = yymsp[0].minor.yy169; } -#line 6292 "sql.c" yymsp[0].minor.yy169 = yylhsminor.yy169; break; case 304: /* sma_stream_opt ::= */ case 345: /* stream_options ::= */ yytestcase(yyruleno==345); -#line 538 "sql.y" { yymsp[1].minor.yy952 = createStreamOptions(pCxt); } -#line 6299 "sql.c" break; case 305: /* sma_stream_opt ::= sma_stream_opt WATERMARK duration_literal */ -#line 539 "sql.y" { ((SStreamOptions*)yymsp[-2].minor.yy952)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = yymsp[-2].minor.yy952; } -#line 6304 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 306: /* sma_stream_opt ::= sma_stream_opt MAX_DELAY duration_literal */ -#line 540 "sql.y" { ((SStreamOptions*)yymsp[-2].minor.yy952)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = yymsp[-2].minor.yy952; } -#line 6310 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 307: /* sma_stream_opt ::= sma_stream_opt DELETE_MARK duration_literal */ -#line 541 "sql.y" { ((SStreamOptions*)yymsp[-2].minor.yy952)->pDeleteMark = releaseRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = yymsp[-2].minor.yy952; } -#line 6316 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 308: /* with_meta ::= AS */ -#line 546 "sql.y" { yymsp[0].minor.yy480 = 0; } -#line 6322 "sql.c" break; case 309: /* with_meta ::= WITH META AS */ -#line 547 "sql.y" { yymsp[-2].minor.yy480 = 1; } -#line 6327 "sql.c" break; case 310: /* with_meta ::= ONLY META AS */ -#line 548 "sql.y" { yymsp[-2].minor.yy480 = 2; } -#line 6332 "sql.c" break; case 311: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery */ -#line 550 "sql.y" { pCxt->pRootNode = createCreateTopicStmtUseQuery(pCxt, yymsp[-3].minor.yy957, &yymsp[-2].minor.yy169, yymsp[0].minor.yy952); } -#line 6337 "sql.c" break; case 312: /* cmd ::= CREATE TOPIC not_exists_opt topic_name with_meta DATABASE db_name */ -#line 552 "sql.y" { pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-4].minor.yy957, &yymsp[-3].minor.yy169, &yymsp[0].minor.yy169, yymsp[-2].minor.yy480); } -#line 6342 "sql.c" break; case 313: /* cmd ::= CREATE TOPIC not_exists_opt topic_name with_meta STABLE full_table_name where_clause_opt */ -#line 554 "sql.y" { pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-5].minor.yy957, &yymsp[-4].minor.yy169, yymsp[-1].minor.yy952, yymsp[-3].minor.yy480, yymsp[0].minor.yy952); } -#line 6347 "sql.c" break; case 314: /* cmd ::= DROP TOPIC exists_opt topic_name */ -#line 556 "sql.y" { pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy957, &yymsp[0].minor.yy169); } -#line 6352 "sql.c" break; case 315: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ -#line 557 "sql.y" { pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy957, &yymsp[-2].minor.yy169, &yymsp[0].minor.yy169); } -#line 6357 "sql.c" break; case 316: /* cmd ::= DESC full_table_name */ case 317: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==317); -#line 560 "sql.y" { pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy952); } -#line 6363 "sql.c" break; case 318: /* cmd ::= RESET QUERY CACHE */ -#line 564 "sql.y" { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } -#line 6368 "sql.c" break; case 319: /* cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery */ case 320: /* cmd ::= EXPLAIN analyze_opt explain_options insert_query */ yytestcase(yyruleno==320); -#line 567 "sql.y" { pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy957, yymsp[-1].minor.yy952, yymsp[0].minor.yy952); } -#line 6374 "sql.c" break; case 323: /* explain_options ::= */ -#line 575 "sql.y" { yymsp[1].minor.yy952 = createDefaultExplainOptions(pCxt); } -#line 6379 "sql.c" break; case 324: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -#line 576 "sql.y" { yylhsminor.yy952 = setExplainVerbose(pCxt, yymsp[-2].minor.yy952, &yymsp[0].minor.yy0); } -#line 6384 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 325: /* explain_options ::= explain_options RATIO NK_FLOAT */ -#line 577 "sql.y" { yylhsminor.yy952 = setExplainRatio(pCxt, yymsp[-2].minor.yy952, &yymsp[0].minor.yy0); } -#line 6390 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 326: /* cmd ::= CREATE or_replace_opt agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt language_opt */ -#line 582 "sql.y" { pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-7].minor.yy957, yymsp[-9].minor.yy957, &yymsp[-6].minor.yy169, &yymsp[-4].minor.yy0, yymsp[-2].minor.yy84, yymsp[-1].minor.yy480, &yymsp[0].minor.yy169, yymsp[-10].minor.yy957); } -#line 6396 "sql.c" break; case 327: /* cmd ::= DROP FUNCTION exists_opt function_name */ -#line 583 "sql.y" { pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy957, &yymsp[0].minor.yy169); } -#line 6401 "sql.c" break; case 332: /* language_opt ::= */ -#line 597 "sql.y" { yymsp[1].minor.yy169 = nil_token; } -#line 6406 "sql.c" break; case 333: /* language_opt ::= LANGUAGE NK_STRING */ -#line 598 "sql.y" { yymsp[-1].minor.yy169 = yymsp[0].minor.yy0; } -#line 6411 "sql.c" break; case 336: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name col_list_opt tag_def_or_ref_opt subtable_opt AS query_or_subquery */ -#line 608 "sql.y" { pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-9].minor.yy957, &yymsp[-8].minor.yy169, yymsp[-5].minor.yy952, yymsp[-7].minor.yy952, yymsp[-3].minor.yy824, yymsp[-2].minor.yy952, yymsp[0].minor.yy952, yymsp[-4].minor.yy824); } -#line 6416 "sql.c" break; case 337: /* cmd ::= DROP STREAM exists_opt stream_name */ -#line 609 "sql.y" { pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy957, &yymsp[0].minor.yy169); } -#line 6421 "sql.c" break; case 338: /* cmd ::= PAUSE STREAM exists_opt stream_name */ -#line 610 "sql.y" { pCxt->pRootNode = createPauseStreamStmt(pCxt, yymsp[-1].minor.yy957, &yymsp[0].minor.yy169); } -#line 6426 "sql.c" break; case 339: /* cmd ::= RESUME STREAM exists_opt ignore_opt stream_name */ -#line 611 "sql.y" { pCxt->pRootNode = createResumeStreamStmt(pCxt, yymsp[-2].minor.yy957, yymsp[-1].minor.yy957, &yymsp[0].minor.yy169); } -#line 6431 "sql.c" break; case 346: /* stream_options ::= stream_options TRIGGER AT_ONCE */ case 347: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ yytestcase(yyruleno==347); -#line 625 "sql.y" { yylhsminor.yy952 = setStreamOptions(pCxt, yymsp[-2].minor.yy952, SOPT_TRIGGER_TYPE_SET, &yymsp[0].minor.yy0, NULL); } -#line 6437 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 348: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ -#line 627 "sql.y" { yylhsminor.yy952 = setStreamOptions(pCxt, yymsp[-3].minor.yy952, SOPT_TRIGGER_TYPE_SET, &yymsp[-1].minor.yy0, releaseRawExprNode(pCxt, yymsp[0].minor.yy952)); } -#line 6443 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 349: /* stream_options ::= stream_options WATERMARK duration_literal */ -#line 628 "sql.y" { yylhsminor.yy952 = setStreamOptions(pCxt, yymsp[-2].minor.yy952, SOPT_WATERMARK_SET, NULL, releaseRawExprNode(pCxt, yymsp[0].minor.yy952)); } -#line 6449 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 350: /* stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */ -#line 629 "sql.y" { yylhsminor.yy952 = setStreamOptions(pCxt, yymsp[-3].minor.yy952, SOPT_IGNORE_EXPIRED_SET, &yymsp[0].minor.yy0, NULL); } -#line 6455 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 351: /* stream_options ::= stream_options FILL_HISTORY NK_INTEGER */ -#line 630 "sql.y" { yylhsminor.yy952 = setStreamOptions(pCxt, yymsp[-2].minor.yy952, SOPT_FILL_HISTORY_SET, &yymsp[0].minor.yy0, NULL); } -#line 6461 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 352: /* stream_options ::= stream_options DELETE_MARK duration_literal */ -#line 631 "sql.y" { yylhsminor.yy952 = setStreamOptions(pCxt, yymsp[-2].minor.yy952, SOPT_DELETE_MARK_SET, NULL, releaseRawExprNode(pCxt, yymsp[0].minor.yy952)); } -#line 6467 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 353: /* stream_options ::= stream_options IGNORE UPDATE NK_INTEGER */ -#line 632 "sql.y" { yylhsminor.yy952 = setStreamOptions(pCxt, yymsp[-3].minor.yy952, SOPT_IGNORE_UPDATE_SET, &yymsp[0].minor.yy0, NULL); } -#line 6473 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 355: /* subtable_opt ::= SUBTABLE NK_LP expression NK_RP */ case 551: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ yytestcase(yyruleno==551); case 572: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==572); -#line 635 "sql.y" { yymsp[-3].minor.yy952 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy952); } -#line 6481 "sql.c" break; case 358: /* cmd ::= KILL CONNECTION NK_INTEGER */ -#line 643 "sql.y" { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } -#line 6486 "sql.c" break; case 359: /* cmd ::= KILL QUERY NK_STRING */ -#line 644 "sql.y" { pCxt->pRootNode = createKillQueryStmt(pCxt, &yymsp[0].minor.yy0); } -#line 6491 "sql.c" break; case 360: /* cmd ::= KILL TRANSACTION NK_INTEGER */ -#line 645 "sql.y" { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_TRANSACTION_STMT, &yymsp[0].minor.yy0); } -#line 6496 "sql.c" break; case 361: /* cmd ::= BALANCE VGROUP */ -#line 648 "sql.y" { pCxt->pRootNode = createBalanceVgroupStmt(pCxt); } -#line 6501 "sql.c" break; case 362: /* cmd ::= BALANCE VGROUP LEADER */ -#line 649 "sql.y" { pCxt->pRootNode = createBalanceVgroupLeaderStmt(pCxt); } -#line 6506 "sql.c" break; case 363: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ -#line 650 "sql.y" { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } -#line 6511 "sql.c" break; case 364: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ -#line 651 "sql.y" { pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy824); } -#line 6516 "sql.c" break; case 365: /* cmd ::= SPLIT VGROUP NK_INTEGER */ -#line 652 "sql.y" { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } -#line 6521 "sql.c" break; case 366: /* dnode_list ::= DNODE NK_INTEGER */ -#line 656 "sql.y" { yymsp[-1].minor.yy824 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } -#line 6526 "sql.c" break; case 368: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ -#line 663 "sql.y" { pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy952, yymsp[0].minor.yy952); } -#line 6531 "sql.c" break; case 371: /* insert_query ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */ -#line 672 "sql.y" { yymsp[-6].minor.yy952 = createInsertStmt(pCxt, yymsp[-4].minor.yy952, yymsp[-2].minor.yy824, yymsp[0].minor.yy952); } -#line 6536 "sql.c" break; case 372: /* insert_query ::= INSERT INTO full_table_name query_or_subquery */ -#line 673 "sql.y" { yymsp[-3].minor.yy952 = createInsertStmt(pCxt, yymsp[-1].minor.yy952, NULL, yymsp[0].minor.yy952); } -#line 6541 "sql.c" break; case 373: /* literal ::= NK_INTEGER */ -#line 676 "sql.y" { yylhsminor.yy952 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0)); } -#line 6546 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 374: /* literal ::= NK_FLOAT */ -#line 677 "sql.y" { yylhsminor.yy952 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } -#line 6552 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 375: /* literal ::= NK_STRING */ -#line 678 "sql.y" { yylhsminor.yy952 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } -#line 6558 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 376: /* literal ::= NK_BOOL */ -#line 679 "sql.y" { yylhsminor.yy952 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } -#line 6564 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 377: /* literal ::= TIMESTAMP NK_STRING */ -#line 680 "sql.y" { yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } -#line 6570 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 378: /* literal ::= duration_literal */ @@ -6591,87 +5676,61 @@ static YYACTIONTYPE yy_reduce( case 575: /* query_simple ::= union_query_expression */ yytestcase(yyruleno==575); case 578: /* query_simple_or_subquery ::= query_simple */ yytestcase(yyruleno==578); case 580: /* query_or_subquery ::= query_expression */ yytestcase(yyruleno==580); -#line 681 "sql.y" { yylhsminor.yy952 = yymsp[0].minor.yy952; } -#line 6596 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 379: /* literal ::= NULL */ -#line 682 "sql.y" { yylhsminor.yy952 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } -#line 6602 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 380: /* literal ::= NK_QUESTION */ -#line 683 "sql.y" { yylhsminor.yy952 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } -#line 6608 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 381: /* duration_literal ::= NK_VARIABLE */ -#line 685 "sql.y" { yylhsminor.yy952 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } -#line 6614 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 382: /* signed ::= NK_INTEGER */ -#line 687 "sql.y" { yylhsminor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0); } -#line 6620 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 383: /* signed ::= NK_PLUS NK_INTEGER */ -#line 688 "sql.y" { yymsp[-1].minor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0); } -#line 6626 "sql.c" break; case 384: /* signed ::= NK_MINUS NK_INTEGER */ -#line 689 "sql.y" { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; yylhsminor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } -#line 6635 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 385: /* signed ::= NK_FLOAT */ -#line 694 "sql.y" { yylhsminor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } -#line 6641 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 386: /* signed ::= NK_PLUS NK_FLOAT */ -#line 695 "sql.y" { yymsp[-1].minor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } -#line 6647 "sql.c" break; case 387: /* signed ::= NK_MINUS NK_FLOAT */ -#line 696 "sql.y" { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; yylhsminor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } -#line 6656 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 389: /* signed_literal ::= NK_STRING */ -#line 703 "sql.y" { yylhsminor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } -#line 6662 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 390: /* signed_literal ::= NK_BOOL */ -#line 704 "sql.y" { yylhsminor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } -#line 6668 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 391: /* signed_literal ::= TIMESTAMP NK_STRING */ -#line 705 "sql.y" { yymsp[-1].minor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } -#line 6674 "sql.c" break; case 392: /* signed_literal ::= duration_literal */ case 394: /* signed_literal ::= literal_func */ yytestcase(yyruleno==394); @@ -6681,138 +5740,106 @@ static YYACTIONTYPE yy_reduce( case 579: /* query_simple_or_subquery ::= subquery */ yytestcase(yyruleno==579); case 581: /* query_or_subquery ::= subquery */ yytestcase(yyruleno==581); case 594: /* search_condition ::= common_expression */ yytestcase(yyruleno==594); -#line 706 "sql.y" { yylhsminor.yy952 = releaseRawExprNode(pCxt, yymsp[0].minor.yy952); } -#line 6686 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 393: /* signed_literal ::= NULL */ -#line 707 "sql.y" { yylhsminor.yy952 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } -#line 6692 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 395: /* signed_literal ::= NK_QUESTION */ -#line 709 "sql.y" { yylhsminor.yy952 = createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0); } -#line 6698 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 415: /* expression ::= NK_LP expression NK_RP */ case 499: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==499); case 593: /* subquery ::= NK_LP subquery NK_RP */ yytestcase(yyruleno==593); -#line 770 "sql.y" { yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy952)); } -#line 6706 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 416: /* expression ::= NK_PLUS expr_or_subquery */ -#line 771 "sql.y" { SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy952)); } -#line 6715 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 417: /* expression ::= NK_MINUS expr_or_subquery */ -#line 775 "sql.y" { SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy952), NULL)); } -#line 6724 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 418: /* expression ::= expr_or_subquery NK_PLUS expr_or_subquery */ -#line 779 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 6734 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 419: /* expression ::= expr_or_subquery NK_MINUS expr_or_subquery */ -#line 784 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 6744 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 420: /* expression ::= expr_or_subquery NK_STAR expr_or_subquery */ -#line 789 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 6754 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 421: /* expression ::= expr_or_subquery NK_SLASH expr_or_subquery */ -#line 794 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 6764 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 422: /* expression ::= expr_or_subquery NK_REM expr_or_subquery */ -#line 799 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 6774 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 423: /* expression ::= column_reference NK_ARROW NK_STRING */ -#line 804 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); } -#line 6783 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 424: /* expression ::= expr_or_subquery NK_BITAND expr_or_subquery */ -#line 808 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 6793 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 425: /* expression ::= expr_or_subquery NK_BITOR expr_or_subquery */ -#line 813 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 6803 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 428: /* column_reference ::= column_name */ -#line 824 "sql.y" { yylhsminor.yy952 = createRawExprNode(pCxt, &yymsp[0].minor.yy169, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy169)); } -#line 6809 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 429: /* column_reference ::= table_name NK_DOT column_name */ -#line 825 "sql.y" { yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy169, &yymsp[0].minor.yy169, createColumnNode(pCxt, &yymsp[-2].minor.yy169, &yymsp[0].minor.yy169)); } -#line 6815 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 430: /* pseudo_column ::= ROWTS */ @@ -6827,278 +5854,191 @@ static YYACTIONTYPE yy_reduce( case 440: /* pseudo_column ::= ISFILLED */ yytestcase(yyruleno==440); case 441: /* pseudo_column ::= QTAGS */ yytestcase(yyruleno==441); case 447: /* literal_func ::= NOW */ yytestcase(yyruleno==447); -#line 827 "sql.y" { yylhsminor.yy952 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } -#line 6832 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 432: /* pseudo_column ::= table_name NK_DOT TBNAME */ -#line 829 "sql.y" { yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy169, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy169)))); } -#line 6838 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 442: /* function_expression ::= function_name NK_LP expression_list NK_RP */ case 443: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==443); -#line 840 "sql.y" { yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy169, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy169, yymsp[-1].minor.yy824)); } -#line 6845 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 444: /* function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP */ -#line 843 "sql.y" { yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy952), yymsp[-1].minor.yy84)); } -#line 6851 "sql.c" yymsp[-5].minor.yy952 = yylhsminor.yy952; break; case 446: /* literal_func ::= noarg_func NK_LP NK_RP */ -#line 846 "sql.y" { yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy169, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy169, NULL)); } -#line 6857 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 461: /* star_func_para_list ::= NK_STAR */ -#line 870 "sql.y" { yylhsminor.yy824 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } -#line 6863 "sql.c" yymsp[0].minor.yy824 = yylhsminor.yy824; break; case 466: /* star_func_para ::= table_name NK_DOT NK_STAR */ case 534: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==534); -#line 879 "sql.y" { yylhsminor.yy952 = createColumnNode(pCxt, &yymsp[-2].minor.yy169, &yymsp[0].minor.yy0); } -#line 6870 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 467: /* case_when_expression ::= CASE when_then_list case_when_else_opt END */ -#line 882 "sql.y" { yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, createCaseWhenNode(pCxt, NULL, yymsp[-2].minor.yy824, yymsp[-1].minor.yy952)); } -#line 6876 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 468: /* case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END */ -#line 884 "sql.y" { yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0, createCaseWhenNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy952), yymsp[-2].minor.yy824, yymsp[-1].minor.yy952)); } -#line 6882 "sql.c" yymsp[-4].minor.yy952 = yylhsminor.yy952; break; case 471: /* when_then_expr ::= WHEN common_expression THEN common_expression */ -#line 891 "sql.y" { yymsp[-3].minor.yy952 = createWhenThenNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952)); } -#line 6888 "sql.c" break; case 473: /* case_when_else_opt ::= ELSE common_expression */ -#line 894 "sql.y" { yymsp[-1].minor.yy952 = releaseRawExprNode(pCxt, yymsp[0].minor.yy952); } -#line 6893 "sql.c" break; case 474: /* predicate ::= expr_or_subquery compare_op expr_or_subquery */ case 479: /* predicate ::= expr_or_subquery in_op in_predicate_value */ yytestcase(yyruleno==479); -#line 897 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy520, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 6903 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 475: /* predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery */ -#line 904 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy952), releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 6913 "sql.c" yymsp[-4].minor.yy952 = yylhsminor.yy952; break; case 476: /* predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery */ -#line 910 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy952), releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 6923 "sql.c" yymsp[-5].minor.yy952 = yylhsminor.yy952; break; case 477: /* predicate ::= expr_or_subquery IS NULL */ -#line 915 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), NULL)); } -#line 6932 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 478: /* predicate ::= expr_or_subquery IS NOT NULL */ -#line 919 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy952), NULL)); } -#line 6941 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 480: /* compare_op ::= NK_LT */ -#line 931 "sql.y" { yymsp[0].minor.yy520 = OP_TYPE_LOWER_THAN; } -#line 6947 "sql.c" break; case 481: /* compare_op ::= NK_GT */ -#line 932 "sql.y" { yymsp[0].minor.yy520 = OP_TYPE_GREATER_THAN; } -#line 6952 "sql.c" break; case 482: /* compare_op ::= NK_LE */ -#line 933 "sql.y" { yymsp[0].minor.yy520 = OP_TYPE_LOWER_EQUAL; } -#line 6957 "sql.c" break; case 483: /* compare_op ::= NK_GE */ -#line 934 "sql.y" { yymsp[0].minor.yy520 = OP_TYPE_GREATER_EQUAL; } -#line 6962 "sql.c" break; case 484: /* compare_op ::= NK_NE */ -#line 935 "sql.y" { yymsp[0].minor.yy520 = OP_TYPE_NOT_EQUAL; } -#line 6967 "sql.c" break; case 485: /* compare_op ::= NK_EQ */ -#line 936 "sql.y" { yymsp[0].minor.yy520 = OP_TYPE_EQUAL; } -#line 6972 "sql.c" break; case 486: /* compare_op ::= LIKE */ -#line 937 "sql.y" { yymsp[0].minor.yy520 = OP_TYPE_LIKE; } -#line 6977 "sql.c" break; case 487: /* compare_op ::= NOT LIKE */ -#line 938 "sql.y" { yymsp[-1].minor.yy520 = OP_TYPE_NOT_LIKE; } -#line 6982 "sql.c" break; case 488: /* compare_op ::= MATCH */ -#line 939 "sql.y" { yymsp[0].minor.yy520 = OP_TYPE_MATCH; } -#line 6987 "sql.c" break; case 489: /* compare_op ::= NMATCH */ -#line 940 "sql.y" { yymsp[0].minor.yy520 = OP_TYPE_NMATCH; } -#line 6992 "sql.c" break; case 490: /* compare_op ::= CONTAINS */ -#line 941 "sql.y" { yymsp[0].minor.yy520 = OP_TYPE_JSON_CONTAINS; } -#line 6997 "sql.c" break; case 491: /* in_op ::= IN */ -#line 945 "sql.y" { yymsp[0].minor.yy520 = OP_TYPE_IN; } -#line 7002 "sql.c" break; case 492: /* in_op ::= NOT IN */ -#line 946 "sql.y" { yymsp[-1].minor.yy520 = OP_TYPE_NOT_IN; } -#line 7007 "sql.c" break; case 493: /* in_predicate_value ::= NK_LP literal_list NK_RP */ -#line 948 "sql.y" { yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy824)); } -#line 7012 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 495: /* boolean_value_expression ::= NOT boolean_primary */ -#line 952 "sql.y" { SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy952), NULL)); } -#line 7021 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 496: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ -#line 957 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 7031 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 497: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ -#line 963 "sql.y" { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy952); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy952); yylhsminor.yy952 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 7041 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 505: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -#line 981 "sql.y" { yylhsminor.yy952 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy952, yymsp[0].minor.yy952, NULL); } -#line 7047 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 508: /* table_primary ::= table_name alias_opt */ -#line 987 "sql.y" { yylhsminor.yy952 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy169, &yymsp[0].minor.yy169); } -#line 7053 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 509: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -#line 988 "sql.y" { yylhsminor.yy952 = createRealTableNode(pCxt, &yymsp[-3].minor.yy169, &yymsp[-1].minor.yy169, &yymsp[0].minor.yy169); } -#line 7059 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 510: /* table_primary ::= subquery alias_opt */ -#line 989 "sql.y" { yylhsminor.yy952 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy952), &yymsp[0].minor.yy169); } -#line 7065 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 512: /* alias_opt ::= */ -#line 994 "sql.y" { yymsp[1].minor.yy169 = nil_token; } -#line 7071 "sql.c" break; case 514: /* alias_opt ::= AS table_alias */ -#line 996 "sql.y" { yymsp[-1].minor.yy169 = yymsp[0].minor.yy169; } -#line 7076 "sql.c" break; case 515: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ case 516: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==516); -#line 998 "sql.y" { yymsp[-2].minor.yy952 = yymsp[-1].minor.yy952; } -#line 7082 "sql.c" break; case 517: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -#line 1003 "sql.y" { yylhsminor.yy952 = createJoinTableNode(pCxt, yymsp[-4].minor.yy932, yymsp[-5].minor.yy952, yymsp[-2].minor.yy952, yymsp[0].minor.yy952); } -#line 7087 "sql.c" yymsp[-5].minor.yy952 = yylhsminor.yy952; break; case 518: /* join_type ::= */ -#line 1007 "sql.y" { yymsp[1].minor.yy932 = JOIN_TYPE_INNER; } -#line 7093 "sql.c" break; case 519: /* join_type ::= INNER */ -#line 1008 "sql.y" { yymsp[0].minor.yy932 = JOIN_TYPE_INNER; } -#line 7098 "sql.c" break; case 520: /* query_specification ::= SELECT hint_list set_quantifier_opt tag_mode_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 */ -#line 1014 "sql.y" { yymsp[-13].minor.yy952 = createSelectStmt(pCxt, yymsp[-11].minor.yy957, yymsp[-9].minor.yy824, yymsp[-8].minor.yy952, yymsp[-12].minor.yy824); yymsp[-13].minor.yy952 = setSelectStmtTagMode(pCxt, yymsp[-13].minor.yy952, yymsp[-10].minor.yy957); @@ -7111,224 +6051,145 @@ static YYACTIONTYPE yy_reduce( yymsp[-13].minor.yy952 = addEveryClause(pCxt, yymsp[-13].minor.yy952, yymsp[-4].minor.yy952); yymsp[-13].minor.yy952 = addFillClause(pCxt, yymsp[-13].minor.yy952, yymsp[-3].minor.yy952); } -#line 7114 "sql.c" break; case 521: /* hint_list ::= */ -#line 1029 "sql.y" { yymsp[1].minor.yy824 = createHintNodeList(pCxt, NULL); } -#line 7119 "sql.c" break; case 522: /* hint_list ::= NK_HINT */ -#line 1030 "sql.y" { yylhsminor.yy824 = createHintNodeList(pCxt, &yymsp[0].minor.yy0); } -#line 7124 "sql.c" yymsp[0].minor.yy824 = yylhsminor.yy824; break; case 527: /* set_quantifier_opt ::= ALL */ -#line 1041 "sql.y" { yymsp[0].minor.yy957 = false; } -#line 7130 "sql.c" break; case 530: /* select_item ::= NK_STAR */ -#line 1048 "sql.y" { yylhsminor.yy952 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0); } -#line 7135 "sql.c" yymsp[0].minor.yy952 = yylhsminor.yy952; break; case 532: /* select_item ::= common_expression column_alias */ case 542: /* partition_item ::= expr_or_subquery column_alias */ yytestcase(yyruleno==542); -#line 1050 "sql.y" { yylhsminor.yy952 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy952), &yymsp[0].minor.yy169); } -#line 7142 "sql.c" yymsp[-1].minor.yy952 = yylhsminor.yy952; break; case 533: /* select_item ::= common_expression AS column_alias */ case 543: /* partition_item ::= expr_or_subquery AS column_alias */ yytestcase(yyruleno==543); -#line 1051 "sql.y" { yylhsminor.yy952 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), &yymsp[0].minor.yy169); } -#line 7149 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 538: /* partition_by_clause_opt ::= PARTITION BY partition_list */ case 563: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==563); case 583: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==583); -#line 1060 "sql.y" { yymsp[-2].minor.yy824 = yymsp[0].minor.yy824; } -#line 7157 "sql.c" break; case 545: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -#line 1073 "sql.y" { yymsp[-5].minor.yy952 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy952), releaseRawExprNode(pCxt, yymsp[-1].minor.yy952)); } -#line 7162 "sql.c" break; case 546: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP */ -#line 1074 "sql.y" { yymsp[-3].minor.yy952 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy952)); } -#line 7167 "sql.c" break; case 547: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -#line 1076 "sql.y" { yymsp[-5].minor.yy952 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy952), NULL, yymsp[-1].minor.yy952, yymsp[0].minor.yy952); } -#line 7172 "sql.c" break; case 548: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -#line 1079 "sql.y" { yymsp[-7].minor.yy952 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy952), releaseRawExprNode(pCxt, yymsp[-3].minor.yy952), yymsp[-1].minor.yy952, yymsp[0].minor.yy952); } -#line 7177 "sql.c" break; case 549: /* twindow_clause_opt ::= EVENT_WINDOW START WITH search_condition END WITH search_condition */ -#line 1081 "sql.y" { yymsp[-6].minor.yy952 = createEventWindowNode(pCxt, yymsp[-3].minor.yy952, yymsp[0].minor.yy952); } -#line 7182 "sql.c" break; case 553: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -#line 1087 "sql.y" { yymsp[-3].minor.yy952 = createFillNode(pCxt, yymsp[-1].minor.yy214, NULL); } -#line 7187 "sql.c" break; case 554: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA expression_list NK_RP */ -#line 1088 "sql.y" { yymsp[-5].minor.yy952 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy824)); } -#line 7192 "sql.c" break; case 555: /* fill_opt ::= FILL NK_LP VALUE_F NK_COMMA expression_list NK_RP */ -#line 1089 "sql.y" { yymsp[-5].minor.yy952 = createFillNode(pCxt, FILL_MODE_VALUE_F, createNodeListNode(pCxt, yymsp[-1].minor.yy824)); } -#line 7197 "sql.c" break; case 556: /* fill_mode ::= NONE */ -#line 1093 "sql.y" { yymsp[0].minor.yy214 = FILL_MODE_NONE; } -#line 7202 "sql.c" break; case 557: /* fill_mode ::= PREV */ -#line 1094 "sql.y" { yymsp[0].minor.yy214 = FILL_MODE_PREV; } -#line 7207 "sql.c" break; case 558: /* fill_mode ::= NULL */ -#line 1095 "sql.y" { yymsp[0].minor.yy214 = FILL_MODE_NULL; } -#line 7212 "sql.c" break; case 559: /* fill_mode ::= NULL_F */ -#line 1096 "sql.y" { yymsp[0].minor.yy214 = FILL_MODE_NULL_F; } -#line 7217 "sql.c" break; case 560: /* fill_mode ::= LINEAR */ -#line 1097 "sql.y" { yymsp[0].minor.yy214 = FILL_MODE_LINEAR; } -#line 7222 "sql.c" break; case 561: /* fill_mode ::= NEXT */ -#line 1098 "sql.y" { yymsp[0].minor.yy214 = FILL_MODE_NEXT; } -#line 7227 "sql.c" break; case 564: /* group_by_list ::= expr_or_subquery */ -#line 1107 "sql.y" { yylhsminor.yy824 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 7232 "sql.c" yymsp[0].minor.yy824 = yylhsminor.yy824; break; case 565: /* group_by_list ::= group_by_list NK_COMMA expr_or_subquery */ -#line 1108 "sql.y" { yylhsminor.yy824 = addNodeToList(pCxt, yymsp[-2].minor.yy824, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy952))); } -#line 7238 "sql.c" yymsp[-2].minor.yy824 = yylhsminor.yy824; break; case 569: /* range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP */ -#line 1115 "sql.y" { yymsp[-5].minor.yy952 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy952), releaseRawExprNode(pCxt, yymsp[-1].minor.yy952)); } -#line 7244 "sql.c" break; case 570: /* range_opt ::= RANGE NK_LP expr_or_subquery NK_RP */ -#line 1117 "sql.y" { yymsp[-3].minor.yy952 = createInterpTimePoint(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy952)); } -#line 7249 "sql.c" break; case 573: /* query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt */ -#line 1124 "sql.y" { yylhsminor.yy952 = addOrderByClause(pCxt, yymsp[-3].minor.yy952, yymsp[-2].minor.yy824); yylhsminor.yy952 = addSlimitClause(pCxt, yylhsminor.yy952, yymsp[-1].minor.yy952); yylhsminor.yy952 = addLimitClause(pCxt, yylhsminor.yy952, yymsp[0].minor.yy952); } -#line 7258 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 576: /* union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery */ -#line 1134 "sql.y" { yylhsminor.yy952 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy952, yymsp[0].minor.yy952); } -#line 7264 "sql.c" yymsp[-3].minor.yy952 = yylhsminor.yy952; break; case 577: /* union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery */ -#line 1136 "sql.y" { yylhsminor.yy952 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy952, yymsp[0].minor.yy952); } -#line 7270 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 585: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ case 589: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==589); -#line 1150 "sql.y" { yymsp[-1].minor.yy952 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } -#line 7277 "sql.c" break; case 586: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ case 590: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==590); -#line 1151 "sql.y" { yymsp[-3].minor.yy952 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } -#line 7283 "sql.c" break; case 587: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ case 591: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==591); -#line 1152 "sql.y" { yymsp[-3].minor.yy952 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } -#line 7289 "sql.c" break; case 592: /* subquery ::= NK_LP query_expression NK_RP */ -#line 1160 "sql.y" { yylhsminor.yy952 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy952); } -#line 7294 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 597: /* sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt */ -#line 1174 "sql.y" { yylhsminor.yy952 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy952), yymsp[-1].minor.yy498, yymsp[0].minor.yy977); } -#line 7300 "sql.c" yymsp[-2].minor.yy952 = yylhsminor.yy952; break; case 598: /* ordering_specification_opt ::= */ -#line 1178 "sql.y" { yymsp[1].minor.yy498 = ORDER_ASC; } -#line 7306 "sql.c" break; case 599: /* ordering_specification_opt ::= ASC */ -#line 1179 "sql.y" { yymsp[0].minor.yy498 = ORDER_ASC; } -#line 7311 "sql.c" break; case 600: /* ordering_specification_opt ::= DESC */ -#line 1180 "sql.y" { yymsp[0].minor.yy498 = ORDER_DESC; } -#line 7316 "sql.c" break; case 601: /* null_ordering_opt ::= */ -#line 1184 "sql.y" { yymsp[1].minor.yy977 = NULL_ORDER_DEFAULT; } -#line 7321 "sql.c" break; case 602: /* null_ordering_opt ::= NULLS FIRST */ -#line 1185 "sql.y" { yymsp[-1].minor.yy977 = NULL_ORDER_FIRST; } -#line 7326 "sql.c" break; case 603: /* null_ordering_opt ::= NULLS LAST */ -#line 1186 "sql.y" { yymsp[-1].minor.yy977 = NULL_ORDER_LAST; } -#line 7331 "sql.c" break; default: break; @@ -7390,7 +6251,6 @@ static void yy_syntax_error( ParseCTX_FETCH #define TOKEN yyminor /************ Begin %syntax_error code ****************************************/ -#line 29 "sql.y" if (TSDB_CODE_SUCCESS == pCxt->errCode) { if(TOKEN.z) { @@ -7401,7 +6261,6 @@ static void yy_syntax_error( } else if (TSDB_CODE_PAR_DB_NOT_SPECIFIED == pCxt->errCode && TK_NK_FLOAT == TOKEN.type) { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z); } -#line 7404 "sql.c" /************ End %syntax_error code ******************************************/ ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ ParseCTX_STORE @@ -7487,56 +6346,12 @@ void Parse( } #endif - while(1){ /* Exit by "break" */ - assert( yypParser->yytos>=yypParser->yystack ); + do{ assert( yyact==yypParser->yytos->stateno ); yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact); if( yyact >= YY_MIN_REDUCE ){ - unsigned int yyruleno = yyact - YY_MIN_REDUCE; /* Reduce by this rule */ -#ifndef NDEBUG - assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ); - if( yyTraceFILE ){ - int yysize = yyRuleInfoNRhs[yyruleno]; - if( yysize ){ - fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", - yyTracePrompt, - yyruleno, yyRuleName[yyruleno], - yyrulenoyytos[yysize].stateno); - }else{ - fprintf(yyTraceFILE, "%sReduce %d [%s]%s.\n", - yyTracePrompt, yyruleno, yyRuleName[yyruleno], - yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ - yypParser->yyhwm++; - assert( yypParser->yyhwm == - (int)(yypParser->yytos - yypParser->yystack)); - } -#endif -#if YYSTACKDEPTH>0 - if( yypParser->yytos>=yypParser->yystackEnd ){ - yyStackOverflow(yypParser); - break; - } -#else - if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ - if( yyGrowStack(yypParser) ){ - yyStackOverflow(yypParser); - break; - } - } -#endif - } - yyact = yy_reduce(yypParser,yyruleno,yymajor,yyminor ParseCTX_PARAM); + yyact = yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor, + yyminor ParseCTX_PARAM); }else if( yyact <= YY_MAX_SHIFTREDUCE ){ yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor); #ifndef YYNOERRORRECOVERY @@ -7592,13 +6407,14 @@ void Parse( yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion); yymajor = YYNOCODE; }else{ - while( yypParser->yytos > yypParser->yystack ){ - yyact = yy_find_reduce_action(yypParser->yytos->stateno, - YYERRORSYMBOL); - if( yyact<=YY_MAX_SHIFTREDUCE ) break; + while( yypParser->yytos >= yypParser->yystack + && (yyact = yy_find_reduce_action( + yypParser->yytos->stateno, + YYERRORSYMBOL)) > YY_MAX_SHIFTREDUCE + ){ yy_pop_parser_stack(yypParser); } - if( yypParser->yytos <= yypParser->yystack || yymajor==0 ){ + if( yypParser->yytos < yypParser->yystack || yymajor==0 ){ yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yy_parse_failed(yypParser); #ifndef YYNOERRORRECOVERY @@ -7648,7 +6464,7 @@ void Parse( break; #endif } - } + }while( yypParser->yytos>yypParser->yystack ); #ifndef NDEBUG if( yyTraceFILE ){ yyStackEntry *i; diff --git a/source/libs/parser/test/parShowToUse.cpp b/source/libs/parser/test/parShowToUse.cpp index 3e1482d420..ee71950621 100644 --- a/source/libs/parser/test/parShowToUse.cpp +++ b/source/libs/parser/test/parShowToUse.cpp @@ -286,7 +286,7 @@ TEST_F(ParserShowToUseTest, trimDatabase) { run("TRIM DATABASE wxy_db"); setTrimDbReq("wxy_db", 100); - run("TRIM DATABASE wxy_db MAX_SPEED 100"); + run("TRIM DATABASE wxy_db BWLIMIT 100"); } TEST_F(ParserShowToUseTest, useDatabase) { diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 7ce6994ce6..51d5c96c86 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -969,6 +969,9 @@ static int32_t pushDownCondOptDealJoin(SOptimizeContext* pCxt, SJoinLogicNode* p if (NULL == pJoin->node.pConditions) { int32_t code = pushDownCondOptJoinExtractCond(pCxt, pJoin); + if (TSDB_CODE_SUCCESS == code) { + code = pushDownCondOptJoinExtractEqualOnCond(pCxt, pJoin); + } if (TSDB_CODE_SUCCESS == code) { OPTIMIZE_FLAG_SET_MASK(pJoin->node.optimizedFlag, OPTIMIZE_FLAG_PUSH_DOWN_CONDE); pCxt->optimized = true; diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 6cc235bd06..12729c3262 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -1990,6 +1990,8 @@ int32_t fltInitValFieldData(SFilterInfo *info) { // todo refactor the convert int32_t code = sclConvertValueToSclParam(var, &out, NULL); if (code != TSDB_CODE_SUCCESS) { + colDataDestroy(out.columnData); + taosMemoryFree(out.columnData); qError("convert value to type[%d] failed", type); return code; } @@ -4678,10 +4680,10 @@ int32_t filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData **p, code = scalarCalculate(info->sclCtx.node, pList, &output); taosArrayDestroy(pList); - FLT_ERR_RET(code); - *p = output.columnData; + FLT_ERR_RET(code); + if (output.numOfQualified == output.numOfRows) { *pResultStatus = FILTER_RESULT_ALL_QUALIFIED; } else if (output.numOfQualified == 0) { diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index b3f67f2c9d..cc6be68c85 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -1193,6 +1193,7 @@ EDealRes sclRewriteFunction(SNode **pNode, SScalarCtx *ctx) { ctx->code = sclExecFunction(node, ctx, &output); if (ctx->code) { + sclFreeParam(&output); return DEAL_RES_ERROR; } @@ -1241,10 +1242,12 @@ EDealRes sclRewriteLogic(SNode **pNode, SScalarCtx *ctx) { SScalarParam output = {0}; ctx->code = sclExecLogic(node, ctx, &output); if (ctx->code) { + sclFreeParam(&output); return DEAL_RES_ERROR; } if (0 == output.numOfRows) { + sclFreeParam(&output); return DEAL_RES_CONTINUE; } @@ -1341,6 +1344,7 @@ EDealRes sclRewriteCaseWhen(SNode **pNode, SScalarCtx *ctx) { SScalarParam output = {0}; ctx->code = sclExecCaseWhen(node, ctx, &output); if (ctx->code) { + sclFreeParam(&output); return DEAL_RES_ERROR; } @@ -1403,11 +1407,13 @@ EDealRes sclWalkFunction(SNode *pNode, SScalarCtx *ctx) { ctx->code = sclExecFunction(node, ctx, &output); if (ctx->code) { + sclFreeParam(&output); return DEAL_RES_ERROR; } if (taosHashPut(ctx->pRes, &pNode, POINTER_BYTES, &output, sizeof(output))) { ctx->code = TSDB_CODE_OUT_OF_MEMORY; + sclFreeParam(&output); return DEAL_RES_ERROR; } @@ -1420,11 +1426,13 @@ EDealRes sclWalkLogic(SNode *pNode, SScalarCtx *ctx) { ctx->code = sclExecLogic(node, ctx, &output); if (ctx->code) { + sclFreeParam(&output); return DEAL_RES_ERROR; } if (taosHashPut(ctx->pRes, &pNode, POINTER_BYTES, &output, sizeof(output))) { ctx->code = TSDB_CODE_OUT_OF_MEMORY; + sclFreeParam(&output); return DEAL_RES_ERROR; } @@ -1443,6 +1451,7 @@ EDealRes sclWalkOperator(SNode *pNode, SScalarCtx *ctx) { if (taosHashPut(ctx->pRes, &pNode, POINTER_BYTES, &output, sizeof(output))) { ctx->code = TSDB_CODE_OUT_OF_MEMORY; + sclFreeParam(&output); return DEAL_RES_ERROR; } diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 821967dfa4..4df7454df8 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -654,9 +654,12 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; - int32_t outputLen = pInputData->varmeta.length * pInput->numOfRows; - char *outputBuf = taosMemoryCalloc(outputLen, 1); - char *output = outputBuf; + int32_t outputLen = pInputData->info.bytes; + char *outputBuf = taosMemoryMalloc(outputLen); + if (outputBuf == NULL) { + qError("substr function memory allocation failure. size: %d", outputLen); + return TSDB_CODE_OUT_OF_MEMORY; + } for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { @@ -676,14 +679,16 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu startPosBytes = TMAX(startPosBytes, 0); } + char *output = outputBuf; int32_t resLen = TMIN(subLen, len - startPosBytes); if (resLen > 0) { memcpy(varDataVal(output), varDataVal(input) + startPosBytes, resLen); + varDataSetLen(output, resLen); + } else { + varDataSetLen(output, 0); } - varDataSetLen(output, resLen); colDataSetVal(pOutputData, i, output, false); - output += varDataTLen(output); } pOutput->numOfRows = pInput->numOfRows; @@ -964,6 +969,17 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp } break; } + case TSDB_DATA_TYPE_VARBINARY:{ + if (inputType == TSDB_DATA_TYPE_BINARY) { + int32_t len = TMIN(varDataLen(input), outputLen - VARSTR_HEADER_SIZE); + memcpy(varDataVal(output), varDataVal(input), len); + varDataSetLen(output, len); + }else{ + code = TSDB_CODE_FUNC_FUNTION_PARA_TYPE; + goto _end; + } + break; + } case TSDB_DATA_TYPE_NCHAR: { int32_t outputCharLen = (outputLen - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; int32_t len; diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index d4dd878250..4246263ddf 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -112,7 +112,9 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF return NULL; } - char* tpath = taosMemoryCalloc(1, strlen(path) + 64); + int32_t len = strlen(path) + 64; + char* tpath = taosMemoryCalloc(1, len); + sprintf(tpath, "%s%s%s", path, TD_DIRSEP, "stream"); pMeta->path = tpath; @@ -120,6 +122,13 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF goto _err; } + sprintf(tpath, "%s/%s", pMeta->path, "checkpoints"); + code = taosMulModeMkDir(tpath, 0755, false); + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(code); + goto _err; + } + if (tdbTbOpen("task.db", STREAM_TASK_KEY_LEN, -1, NULL, pMeta->db, &pMeta->pTaskDb, 0) < 0) { goto _err; } @@ -156,6 +165,14 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF int64_t* pRid = taosMemoryMalloc(sizeof(int64_t)); *pRid = pMeta->rid; + memset(tpath, 0, len); + sprintf(tpath, "%s/%s", pMeta->path, "state"); + code = taosMulModeMkDir(tpath, 0755, false); + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(code); + goto _err; + } + metaRefMgtAdd(pMeta->vgId, pRid); pMeta->hbInfo.hbTmr = taosTmrStart(metaHbToMnode, META_HB_CHECK_INTERVAL, pRid, streamEnv.timer); diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c index 5b4141bc7f..83aed42fe2 100644 --- a/source/libs/stream/src/streamState.c +++ b/source/libs/stream/src/streamState.c @@ -171,7 +171,7 @@ SStreamState* streamStateOpen(char* path, void* pTask, bool specPath, int32_t sz sscanf(cfg, "%d\n%d\n", &szPage, &pages); } } else { - int32_t code = taosMulModeMkDir(statePath, 0755); + int32_t code = taosMulModeMkDir(statePath, 0755, false); if (code == 0) { pCfgFile = taosOpenFile(cfgPath, TD_FILE_WRITE | TD_FILE_CREATE); sprintf(cfg, "%d\n%d\n", szPage, pages); diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 4f595d8d4a..81b306e65d 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -62,7 +62,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, i } memset(pDb->pgrHash, 0, tsize); - ret = taosMulModeMkDir(dbname, 0755); + ret = taosMulModeMkDir(dbname, 0755, false); if (ret < 0) { return -1; } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 607c33ed9f..a53830723c 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -287,8 +287,15 @@ static bool uvHandleReq(SSvrConn* pConn) { } void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { - SSvrConn* conn = cli->data; - STrans* pTransInst = conn->pTransInst; + SSvrConn* conn = cli->data; + SWorkThrd* pThrd = conn->hostThrd; + + if (true == pThrd->quit) { + tInfo("work thread received quit msg, destroy conn"); + destroyConn(conn, true); + return; + } + STrans* pTransInst = conn->pTransInst; SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 3d63da7ba3..6e52c4ed27 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -193,7 +193,7 @@ int32_t taosMulMkDir(const char *dirname) { return code; } -int32_t taosMulModeMkDir(const char *dirname, int mode) { +int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) { if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return -1; char temp[TDDIRMAXLEN]; char *pos = temp; @@ -206,6 +206,9 @@ int32_t taosMulModeMkDir(const char *dirname, int mode) { #endif if (taosDirExist(temp)) { + if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { + return 0; + } return chmod(temp, mode); } @@ -248,6 +251,9 @@ int32_t taosMulModeMkDir(const char *dirname, int mode) { } if (code < 0 && errno == EEXIST) { + if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) { + return 0; + } return chmod(temp, mode); } diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index a32417b24a..1177ff562e 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -889,13 +889,16 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) { char *data = taosMemoryMalloc(compressSize); gzFile dstFp = NULL; - TdFilePtr pSrcFile = taosOpenFile(srcFileName, TD_FILE_READ | TD_FILE_STREAM); + TdFilePtr pFile = NULL; + TdFilePtr pSrcFile = NULL; + + pSrcFile = taosOpenFile(srcFileName, TD_FILE_READ | TD_FILE_STREAM); if (pSrcFile == NULL) { ret = -1; goto cmp_end; } - TdFilePtr pFile = taosOpenFile(destFileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); + pFile = taosOpenFile(destFileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { ret = -2; goto cmp_end; @@ -914,6 +917,9 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) { } cmp_end: + if (pFile) { + taosCloseFile(&pFile); + } if (pSrcFile) { taosCloseFile(&pSrcFile); } diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index b7130fb02e..9bdabf030b 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -360,7 +360,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/smaTest.py -R ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/sma_index.py ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/sml_TS-3724.py -#,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/varbinary.py +,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/varbinary.py ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/sml.py ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/sml.py -R ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/spread.py @@ -773,6 +773,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/blockSMA.py -Q 4 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/projectionDesc.py -Q 4 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/odbc.py +,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/fill_with_group.py ,,y,system-test,./pytest.sh python3 ./test.py -f 99-TDcase/TD-21561.py -Q 4 ,,y,system-test,./pytest.sh python3 ./test.py -f 99-TDcase/TD-20582.py ,,n,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/insertMix.py -N 3 diff --git a/tests/script/tsim/query/interval.sim b/tests/script/tsim/query/interval.sim index e2b0d219cb..135fcc8591 100644 --- a/tests/script/tsim/query/interval.sim +++ b/tests/script/tsim/query/interval.sim @@ -206,6 +206,19 @@ if $desc_rows != $asc_rows then return -1 endi +print ================= step11 + +sql create database if not exists test0828 +sql use test0828 +sql create stable st (ts timestamp, c2 int) tags(tg int) +sql insert into ct1 using st tags(1) values('2021-08-01', 0) +sql insert into ct2 using st tags(2) values('2022-08-01', 1) +sql select _wstart, _wend, count(*) from st where ts>='2021-01-01' and ts < '2023-08-28' interval(1n) fill(value, 0) order by _wstart desc +print $rows +if $rows != 32 then + return -1 +endi +sql drop database test0828 print =============== clear #sql drop database $db #sql select * from information_schema.ins_databases diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index f7788d1d50..baf0682fbb 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -215,7 +215,13 @@ class TDTestCase: for t in range (2): tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"') tdSql.checkEqual(20470,len(tdSql.queryResult)) - + + tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'") + tdSql.checkEqual(193, len(tdSql.queryResult)) + + tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'") + tdSql.checkEqual(54, len(tdSql.queryResult)) + def ins_dnodes_check(self): tdSql.execute('drop database if exists db2') tdSql.execute('create database if not exists db2 vgroups 1 replica 1') diff --git a/tests/system-test/0-others/walRetention.py b/tests/system-test/0-others/walRetention.py index 5257b7644a..0fdeb84a5b 100644 --- a/tests/system-test/0-others/walRetention.py +++ b/tests/system-test/0-others/walRetention.py @@ -147,13 +147,13 @@ class VNode : if self.lastVer != -1 and ret: # first wal file ignore if walFile.startVer == self.firstVer: - tdLog.info(f" {walFile.pathFile} can del, but is first. snapVer={self.snapVer} firstVer={self.firstVer}") + tdLog.info(f" can del {walFile.pathFile}, but is first. snapVer={self.snapVer} firstVer={self.firstVer}") return False # ver in stay range smallVer = self.snapVer - self.walStayRange -1 if walFile.startVer >= smallVer: - tdLog.info(f" {walFile.pathFile} can del, but range not arrived. snapVer={self.snapVer} smallVer={smallVer}") + tdLog.info(f" can del {walFile.pathFile}, but range not arrived. snapVer={self.snapVer} smallVer={smallVer}") return False return ret @@ -161,9 +161,20 @@ class VNode : # get log size def getWalsSize(self): size = 0 + lastSize = 0 + max = -1 for walFile in self.walFiles: - size += walFile.fsize + if self.canDelete(walFile) == False: + tdLog.info(f" calc vnode size {walFile.pathFile} size={walFile.fsize} startVer={walFile.startVer}") + size += walFile.fsize + if max < walFile.startVer: + max = walFile.startVer + lastSize = walFile.fsize + + if lastSize > 0: + tdLog.info(f" last file size need reduct . lastSize={lastSize}") + size -= lastSize return size # vnode @@ -183,7 +194,7 @@ class VNode : delTs = delTsLine.timestamp() for walFile in self.walFiles: mt = datetime.fromtimestamp(walFile.mtime) - info = f" {walFile.pathFile} mt={mt} line={delTsLine} start={walFile.startVer} snap={self.snapVer} end= {walFile.endVer}" + info = f" {walFile.pathFile} size={walFile.fsize} mt={mt} line={delTsLine} start={walFile.startVer} snap={self.snapVer} end= {walFile.endVer}" tdLog.info(info) if walFile.mtime < delTs and self.canDelete(walFile): # wait a moment then check file exist @@ -199,25 +210,16 @@ class VNode : if self.walSize == 0: return True + time.sleep(2) vnodeSize = self.getWalsSize() - if vnodeSize < self.walSize: - tdLog.info(f" wal size valid. {self.path} real = {vnodeSize} set = {self.walSize} ") + # need over 20% + if vnodeSize < self.walSize * 1.2: + tdLog.info(f" wal size valid. {self.path} real = {vnodeSize} set = {self.walSize}. allow over 20%.") return True - # check valid - tdLog.info(f" wal size over set. {self.path} real = {vnodeSize} set = {self.walSize} ") - for walFile in self.walFiles: - if self.canDelete(walFile): - # wait a moment then check file exist - time.sleep(1) - if os.path.exists(walFile.pathFile): - tdLog.exit(f" wal file size over .\ - \n wal file = {walFile.pathFile}\ - \n snapVer = {self.snapVer}\ - \n real = {vnodeSize} bytes\ - \n set = {self.walSize} bytes") - return False - return True + # check over + tdLog.exit(f" wal size over set. {self.path} real = {vnodeSize} set = {self.walSize} ") + return False # insert by async diff --git a/tests/system-test/1-insert/alter_stable.py b/tests/system-test/1-insert/alter_stable.py index 3e82b573b1..52f185a868 100644 --- a/tests/system-test/1-insert/alter_stable.py +++ b/tests/system-test/1-insert/alter_stable.py @@ -155,9 +155,37 @@ class TDTestCase: tdSql.error(f'alter stable {self.ntbname} modify column {key} {v}') for i in range(self.tbnum): tdSql.error(f'alter stable {self.stbname}_{i} modify column {key} {v}') - def run(self): + + def alter_stable_column_varchar_39001(self): + """Check alter stable column varchar 39001 from 39000(TS-3841) + """ + stbname = "st1" + column_dict = { + 'ts' : 'timestamp', + 'col1': 'varchar(39000)', + 'col2': 'tinyint', + 'col3': 'timestamp', + 'col4': 'tinyint', + 'col5': 'timestamp', + 'col6': 'varchar(18)', + 'col7': 'varchar(17)' + } + tag_dict = { + 'id': 'int' + } + tdSql.execute(self.setsql.set_create_stable_sql(stbname, column_dict, tag_dict)) + res = tdSql.getResult(f'desc {stbname}') + tdLog.info(res) + assert(res[1][2] == 39000) + tdSql.execute(f'alter stable {stbname} modify column col1 varchar(39001)') + res = tdSql.getResult(f'desc {stbname}') + tdLog.info(res) + assert(res[1][2] == 39001) + + def run(self): self.alter_stable_check() + self.alter_stable_column_varchar_39001() def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/2-query/fill_with_group.py b/tests/system-test/2-query/fill_with_group.py new file mode 100644 index 0000000000..393102c8ed --- /dev/null +++ b/tests/system-test/2-query/fill_with_group.py @@ -0,0 +1,153 @@ +import taos +import sys +import time +import socket +import os +import threading +import math + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * +# from tmqCommon import * + +class TDTestCase: + def __init__(self): + self.vgroups = 4 + self.ctbNum = 10 + self.rowsPerTbl = 10000 + self.duraion = '1h' + + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + + def create_database(self,tsql, dbName,dropFlag=1,vgroups=2,replica=1, duration:str='1d'): + if dropFlag == 1: + tsql.execute("drop database if exists %s"%(dbName)) + + tsql.execute("create database if not exists %s vgroups %d replica %d duration %s"%(dbName, vgroups, replica, duration)) + tdLog.debug("complete to create database %s"%(dbName)) + return + + def create_stable(self,tsql, paraDict): + colString = tdCom.gen_column_type_str(colname_prefix=paraDict["colPrefix"], column_elm_list=paraDict["colSchema"]) + tagString = tdCom.gen_tag_type_str(tagname_prefix=paraDict["tagPrefix"], tag_elm_list=paraDict["tagSchema"]) + sqlString = f"create table if not exists %s.%s (%s) tags (%s)"%(paraDict["dbName"], paraDict["stbName"], colString, tagString) + tdLog.debug("%s"%(sqlString)) + tsql.execute(sqlString) + return + + def create_ctable(self,tsql=None, dbName='dbx',stbName='stb',ctbPrefix='ctb',ctbNum=1,ctbStartIdx=0): + for i in range(ctbNum): + sqlString = "create table %s.%s%d using %s.%s tags(%d, 'tb%d', 'tb%d', %d, %d, %d)" % \ + (dbName,ctbPrefix,i+ctbStartIdx,dbName,stbName,(i+ctbStartIdx) % 5,i+ctbStartIdx,i+ctbStartIdx,i+ctbStartIdx,i+ctbStartIdx,i+ctbStartIdx) + tsql.execute(sqlString) + + tdLog.debug("complete to create %d child tables by %s.%s" %(ctbNum, dbName, stbName)) + return + + def insert_data(self,tsql,dbName,ctbPrefix,ctbNum,rowsPerTbl,batchNum,startTs,tsStep): + tdLog.debug("start to insert data ............") + tsql.execute("use %s" %dbName) + pre_insert = "insert into " + sql = pre_insert + + for i in range(ctbNum): + rowsBatched = 0 + sql += " %s%d values "%(ctbPrefix,i) + for j in range(rowsPerTbl): + if (i < ctbNum/2): + sql += "(%d, %d, %d, %d,%d,%d,%d,true,'binary%d', 'nchar%d') "%(startTs + j*tsStep, j%10, j%10, j%10, j%10, j%10, j%10, j%10, j%10) + else: + sql += "(%d, %d, NULL, %d,NULL,%d,%d,true,'binary%d', 'nchar%d') "%(startTs + j*tsStep, j%10, j%10, j%10, j%10, j%10, j%10) + rowsBatched += 1 + if ((rowsBatched == batchNum) or (j == rowsPerTbl - 1)): + tsql.execute(sql) + rowsBatched = 0 + if j < rowsPerTbl - 1: + sql = "insert into %s%d values " %(ctbPrefix,i) + else: + sql = "insert into " + if sql != pre_insert: + tsql.execute(sql) + tdLog.debug("insert data ............ [OK]") + return + + def prepareTestEnv(self): + tdLog.printNoPrefix("======== prepare test env include database, stable, ctables, and insert data: ") + paraDict = {'dbName': 'test', + 'dropFlag': 1, + 'vgroups': 2, + 'stbName': 'meters', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'FLOAT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'smallint', 'count':1},{'type': 'tinyint', 'count':1},{'type': 'bool', 'count':1},{'type': 'binary', 'len':10, 'count':1},{'type': 'nchar', 'len':10, 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'nchar', 'len':20, 'count':1},{'type': 'binary', 'len':20, 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'smallint', 'count':1},{'type': 'DOUBLE', 'count':1}], + 'ctbPrefix': 't', + 'ctbStartIdx': 0, + 'ctbNum': 100, + 'rowsPerTbl': 10000, + 'batchNum': 3000, + 'startTs': 1537146000000, + 'tsStep': 600000} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tdLog.info("create database") + self.create_database(tsql=tdSql, dbName=paraDict["dbName"], dropFlag=paraDict["dropFlag"], vgroups=paraDict["vgroups"], replica=self.replicaVar, duration=self.duraion) + + tdLog.info("create stb") + self.create_stable(tsql=tdSql, paraDict=paraDict) + + tdLog.info("create child tables") + self.create_ctable(tsql=tdSql, dbName=paraDict["dbName"], \ + stbName=paraDict["stbName"],ctbPrefix=paraDict["ctbPrefix"],\ + ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict["ctbStartIdx"]) + self.insert_data(tsql=tdSql, dbName=paraDict["dbName"],\ + ctbPrefix=paraDict["ctbPrefix"],ctbNum=paraDict["ctbNum"],\ + rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"],\ + startTs=paraDict["startTs"],tsStep=paraDict["tsStep"]) + return + + def test_partition_by_with_interval_fill_prev_new_group_fill_error(self): + ## every table has 1500 rows after fill, 10 tables, total 15000 rows. + ## there is no data from 9-17 08:00:00 ~ 9-17 09:00:00, so first 60 rows of every group will be NULL, cause no prev value. + sql = "select _wstart, count(*),tbname from meters where ts > '2018-09-17 08:00:00.000' and ts < '2018-09-18 09:00:00.000' partition by tbname interval(1m) fill(PREV) order by tbname, _wstart" + tdSql.query(sql) + for i in range(0,10): + for j in range(0,60): + tdSql.checkData(i*1500+j, 1, None) + + sql = "select _wstart, count(*),tbname from meters where ts > '2018-09-17 08:00:00.000' and ts < '2018-09-18 09:00:00.000' partition by tbname interval(1m) fill(LINEAR) order by tbname, _wstart" + tdSql.query(sql) + for i in range(0,10): + for j in range(0,60): + tdSql.checkData(i*1500+j, 1, None) + + def test_fill_with_order_by(self): + sql = "select _wstart, _wend, count(ts), sum(c1) from meters where ts > '2018-11-25 00:00:00.000' and ts < '2018-11-26 00:00:00.00' interval(1d) fill(NULL) order by _wstart" + tdSql.query(sql) + tdSql.checkRows(1) + sql = "select _wstart, _wend, count(ts), sum(c1) from meters where ts > '2018-11-25 00:00:00.000' and ts < '2018-11-26 00:00:00.00' interval(1d) fill(NULL) order by _wstart desc" + tdSql.query(sql) + tdSql.checkRows(1) + + def run(self): + self.prepareTestEnv() + self.test_partition_by_with_interval_fill_prev_new_group_fill_error() + self.test_fill_with_order_by() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/sml_TS-3724.py b/tests/system-test/2-query/sml_TS-3724.py index a8b16c4662..410e266f10 100644 --- a/tests/system-test/2-query/sml_TS-3724.py +++ b/tests/system-test/2-query/sml_TS-3724.py @@ -67,7 +67,7 @@ class TDTestCase: tdSql.query(f"select distinct tbname from {dbname}.`sys_if_bytes_out`") tdSql.checkRows(2) - tdSql.query(f"select * from {dbname}.t_fc70dec6677d4277c5d9799c4da806da order by times") + tdSql.query(f"select * from {dbname}.t_f67972b49aa8adf8bca5d0d54f0d850d order by times") tdSql.checkRows(2) tdSql.checkData(0, 1, 1.300000000) tdSql.checkData(1, 1, 13.000000000) diff --git a/tests/system-test/2-query/stbJoin.py b/tests/system-test/2-query/stbJoin.py index b4d6301424..e21a875cf2 100644 --- a/tests/system-test/2-query/stbJoin.py +++ b/tests/system-test/2-query/stbJoin.py @@ -106,6 +106,9 @@ class TDTestCase: tdSql.query(f"select a.ts, b.ts from sta a, stb b where a.ts=b.ts and (a.tg1=b.tg1 and a.tg1 > b.tg1);") tdSql.checkRows(0) + tdSql.query(f"select a.* from sta a join stb b on a.tg1=b.tg1 and a.ts=b.ts and a.tg2=b.tg2;") + tdSql.checkRows(12) + # tdSql.checkData(0,1,10) tdSql.error(f"select a.* from sta a join stb b on a.tg1=b.tg1 where a.ts=b.ts or a.tg2=b.tg2;") diff --git a/tests/system-test/2-query/varbinary.py b/tests/system-test/2-query/varbinary.py index 8f7032cdc3..8f8021c8ad 100644 --- a/tests/system-test/2-query/varbinary.py +++ b/tests/system-test/2-query/varbinary.py @@ -23,16 +23,16 @@ class TDTestCase: if ret != 0: tdLog.exit("varbinary_test ret != 0") - tdSql.execute(f" create database test") - tdSql.execute(f" use test ") - tdSql.execute(f" create stable stb (ts timestamp, c1 nchar(32), c2 varbinary(16), c3 float) tags (t1 int, t2 binary(8), t3 varbinary(8))") - - tdSql.query(f"desc stb") - tdSql.checkRows(7) - tdSql.checkData(2, 1, 'VARBINARY') - tdSql.checkData(2, 2, 16) - tdSql.checkData(6, 1, 'VARBINARY') - tdSql.checkData(6, 2, 8) + # tdSql.execute(f" create database test") + # tdSql.execute(f" use test ") + # tdSql.execute(f" create stable stb (ts timestamp, c1 nchar(32), c2 varbinary(16), c3 float) tags (t1 int, t2 binary(8), t3 varbinary(8))") + # + # tdSql.query(f"desc stb") + # tdSql.checkRows(7) + # tdSql.checkData(2, 1, 'VARBINARY') + # tdSql.checkData(2, 2, 16) + # tdSql.checkData(6, 1, 'VARBINARY') + # tdSql.checkData(6, 2, 8) # tdSql.execute(f" insert into tb1 using stb tags (1, 'tb1_bin1', 'vart1') values (now, 'nchar1', 'varc1', 0.3)") # tdSql.execute(f" insert into tb1 values (now + 1s, 'nchar2', null, 0.4)") diff --git a/tests/system-test/7-tmq/subscribeDb0.py b/tests/system-test/7-tmq/subscribeDb0.py index ed13fcbe06..d4dfe425dc 100644 --- a/tests/system-test/7-tmq/subscribeDb0.py +++ b/tests/system-test/7-tmq/subscribeDb0.py @@ -237,7 +237,7 @@ class TDTestCase: for i in range(expectRows): totalConsumeRows += resultList[i] - if totalConsumeRows != expectrowcnt: + if totalConsumeRows < expectrowcnt: tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, expectrowcnt)) tdLog.exit("tmq consume rows error!") diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 35ab86269d..72cf3cd1cc 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -409,7 +409,7 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i if(taosAscii2Hex(val, length, &tmp, &size) < 0){ break; } - taosFprintfFile(pFile, "%s", tmp); + taosFprintfFile(pFile, "%s%s%s", quotationStr, tmp, quotationStr); taosMemoryFree(tmp); break; } diff --git a/tools/shell/src/shellWebsocket.c b/tools/shell/src/shellWebsocket.c index af7f13c69c..ff2e5efdd4 100644 --- a/tools/shell/src/shellWebsocket.c +++ b/tools/shell/src/shellWebsocket.c @@ -278,7 +278,7 @@ void shellRunSingleCommandWebsocketImp(char *command) { } if (code == TSDB_CODE_WS_SEND_TIMEOUT || code == TSDB_CODE_WS_RECV_TIMEOUT) { - fprintf(stderr, "Hint: use -t to increase the timeout in seconds\n"); + fprintf(stderr, "Hint: use -T to increase the timeout in seconds\n"); } else if (code == TSDB_CODE_WS_INTERNAL_ERRO || code == TSDB_CODE_WS_CLOSED) { shell.ws_conn = NULL; @@ -373,8 +373,6 @@ void shellRunSingleCommandWebsocketImp(char *command) { } else { printf("Query interrupted, %d row(s) in set (%.6fs)\n", numOfRows, (et - st)/1E6); - printf("Execute: %.2f ms Network: %.2f ms Total: %.2f ms\n", - execute_time, net_time, total_time); } } printf("\n"); diff --git a/utils/test/c/sml_test.c b/utils/test/c/sml_test.c index 105fdd2ca4..9153706d23 100644 --- a/utils/test/c/sml_test.c +++ b/utils/test/c/sml_test.c @@ -1534,6 +1534,7 @@ int sml_ts3724_Test() { const char *sql[] = { "stb.2,t1=1 f1=283i32 1632299372000", + "stb_2,t1=1 f1=283i32 1632299372000", ".stb2,t1=1 f1=106i32 1632299378000", "stb2.,t1=1 f1=106i32 1632299378000", }; @@ -1548,6 +1549,12 @@ int sml_ts3724_Test() { printf("%s result0:%s\n", __FUNCTION__, taos_errstr(pRes)); taos_free_result(pRes); + pRes = taos_query(taos, "select * from stb_2"); + TAOS_ROW row = taos_fetch_row(pRes); + int numRows = taos_affected_rows(pRes); + ASSERT(numRows == 1); + taos_free_result(pRes); + taos_close(taos); return code; diff --git a/utils/test/c/varbinary_test.c b/utils/test/c/varbinary_test.c index b2fccee63b..e29b94ad1f 100644 --- a/utils/test/c/varbinary_test.c +++ b/utils/test/c/varbinary_test.c @@ -32,7 +32,7 @@ break;\ }\ } -int varbinary_test() { +void varbinary_sql_test() { TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0); TAOS_RES *pRes = taos_query(taos, "drop database if exists varbinary_db"); @@ -68,6 +68,7 @@ int varbinary_test() { } rowIndex++; } + taos_free_result(pRes); pRes = taos_query(taos, "insert into tb1 using stb tags (1, 'tb1_bin1', 'vart1') values (now, 'nchar1', 'varc1', 0.3)"); taos_free_result(pRes); @@ -96,7 +97,6 @@ int varbinary_test() { ASSERT(taos_errno(pRes) != 0); taos_free_result(pRes); - // test error pRes = taos_query(taos, "select * from tb1 where c2 >= 0x8de6"); ASSERT(taos_errno(pRes) != 0); @@ -146,13 +146,81 @@ int varbinary_test() { ASSERT(taos_errno(pRes) != 0); taos_free_result(pRes); -// pRes = taos_query(taos, "select * from stb where c2 contains 'ssd'"); -// ASSERT(taos_errno(pRes) != 0); -// taos_free_result(pRes); -// -// pRes = taos_query(taos, "select * from stb where c2 contains 'ssd'"); -// ASSERT(taos_errno(pRes) != 0); -// taos_free_result(pRes); + + // math function test, not support + pRes = taos_query(taos, "select abs(c2) from stb"); + ASSERT(taos_errno(pRes) != 0); + taos_free_result(pRes); + + pRes = taos_query(taos, "select floor(c2) from stb"); + ASSERT(taos_errno(pRes) != 0); + taos_free_result(pRes); + + // string function test, not support + pRes = taos_query(taos, "select length(c2) from stb"); + ASSERT(taos_errno(pRes) != 0); + taos_free_result(pRes); + + pRes = taos_query(taos, "select ltrim(c2) from stb"); + ASSERT(taos_errno(pRes) != 0); + taos_free_result(pRes); + + pRes = taos_query(taos, "select upper(c2) from stb"); + ASSERT(taos_errno(pRes) != 0); + taos_free_result(pRes); + + + pRes = taos_query(taos, "select to_json(c2) from stb"); + ASSERT(taos_errno(pRes) != 0); + taos_free_result(pRes); + + pRes = taos_query(taos, "select TO_UNIXTIMESTAMP(c2) from stb"); + ASSERT(taos_errno(pRes) != 0); + taos_free_result(pRes); + + pRes = taos_query(taos, "select cast(c2 as varchar(16)) from stb"); + ASSERT(taos_errno(pRes) != 0); + taos_free_result(pRes); + + pRes = taos_query(taos, "select cast(c3 as varbinary(16)) from stb"); + ASSERT(taos_errno(pRes) != 0); + taos_free_result(pRes); + + pRes = taos_query(taos, "select cast(c1 as varbinary(16)) from stb"); + ASSERT(taos_errno(pRes) != 0); + taos_free_result(pRes); + + // support first/last/last_row/count/hyperloglog/sample/tail/mode + pRes = taos_query(taos, "select first(c2) from stb"); + ASSERT(taos_errno(pRes) == 0); + taos_free_result(pRes); + + pRes = taos_query(taos, "select count(c2) from stb"); + ASSERT(taos_errno(pRes) == 0); + taos_free_result(pRes); + + pRes = taos_query(taos, "select sample(c2,2) from stb"); + ASSERT(taos_errno(pRes) == 0); + taos_free_result(pRes); + + pRes = taos_query(taos, "select mode(c2) from stb"); + ASSERT(taos_errno(pRes) == 0); + taos_free_result(pRes); + + pRes = taos_query(taos, "select cast(t2 as varbinary(16)) from stb order by ts"); + while ((row = taos_fetch_row(pRes)) != NULL) { + int32_t* length = taos_fetch_lengths(pRes); + void* data = NULL; + uint32_t size = 0; + if(taosAscii2Hex(row[0], length[0], &data, &size) < 0){ + ASSERT(0); + } + + ASSERT(memcmp(data, "\\x7462315F62696E31", size) == 0); + taosMemoryFree(data); + break; + } + taos_free_result(pRes); int numRows = 0; @@ -191,12 +259,25 @@ int varbinary_test() { ASSERT(numRows == 2); taos_free_result(pRes); - pRes = taos_query(taos, "select * from stb where c2 not between '\\x3e' and '\\x7F8290'"); GET_ROW_NUM ASSERT(numRows == 3); taos_free_result(pRes); + pRes = taos_query(taos, "select cast('1' as varbinary(8))"); + while ((row = taos_fetch_row(pRes)) != NULL) { + int32_t* length = taos_fetch_lengths(pRes); + void* data = NULL; + uint32_t size = 0; + if(taosAscii2Hex(row[0], length[0], &data, &size) < 0){ + ASSERT(0); + } + + ASSERT(memcmp(data, "\\x31", size) == 0); + taosMemoryFree(data); + } + taos_free_result(pRes); + pRes = taos_query(taos, "select ts,c2 from stb order by c2"); rowIndex = 0; while ((row = taos_fetch_row(pRes)) != NULL) { @@ -237,17 +318,355 @@ int varbinary_test() { rowIndex++; } - printf("%s result1:%s\n", __FUNCTION__, taos_errstr(pRes)); + printf("%s result %s\n", __FUNCTION__, taos_errstr(pRes)); taos_free_result(pRes); taos_close(taos); +} - return code; +void varbinary_stmt_test(){ + TAOS *taos; + TAOS_RES *result; + int code; + TAOS_STMT *stmt; + + taos = taos_connect("localhost", "root", "taosdata", NULL, 0); + if (taos == NULL) { + printf("failed to connect to db, reason:%s\n", taos_errstr(taos)); + ASSERT(0); + } + + result = taos_query(taos, "drop database demo"); + taos_free_result(result); + + result = taos_query(taos, "create database demo"); + code = taos_errno(result); + if (code != 0) { + printf("failed to create database, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + ASSERT(0); + } + taos_free_result(result); + + result = taos_query(taos, "use demo"); + taos_free_result(result); + + // create table + const char* sql = "create table m1 (ts timestamp, b bool, varbin varbinary(16))"; + result = taos_query(taos, sql); + code = taos_errno(result); + if (code != 0) { + printf("failed to create table, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + ASSERT(0); + } + taos_free_result(result); + struct { + int64_t ts; + int8_t b; + int8_t varbin[16]; + } v = {0}; + + int32_t boolLen = sizeof(int8_t); + int32_t bintLen = sizeof(int64_t); + int32_t vbinLen = 5; + + stmt = taos_stmt_init(taos); + TAOS_MULTI_BIND params[3]; + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[0].buffer_length = sizeof(v.ts); + params[0].buffer = &v.ts; + params[0].length = &bintLen; + params[0].is_null = NULL; + params[0].num = 1; + + params[1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[1].buffer_length = sizeof(v.b); + params[1].buffer = &v.b; + params[1].length = &boolLen; + params[1].is_null = NULL; + params[1].num = 1; + + params[2].buffer_type = TSDB_DATA_TYPE_VARBINARY; + params[2].buffer_length = sizeof(v.varbin); + params[2].buffer = v.varbin; + params[2].length = &vbinLen; + params[2].is_null = NULL; + params[2].num = 1; + + char is_null = 1; + + sql = "insert into m1 values(?,?,?)"; + code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); + } + v.ts = 1591060628000; + for (int i = 0; i < 10; ++i) { + v.ts += 1; + for (int j = 1; j < 3; ++j) { + params[j].is_null = ((i == j) ? &is_null : 0); + } + v.b = (int8_t)i % 2; + + for (int j = 0; j < vbinLen; ++j) { + v.varbin[j] = i + j; + } + + taos_stmt_bind_param(stmt, params); + taos_stmt_add_batch(stmt); + } + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute insert statement.\n"); + ASSERT(0); + } + taos_stmt_close(stmt); + + // query the records + stmt = taos_stmt_init(taos); + taos_stmt_prepare(stmt, "SELECT varbin FROM m1 WHERE varbin = ?", 0); + for (int j = 0; j < vbinLen; ++j) { + v.varbin[j] = j; + } + taos_stmt_bind_param(stmt, params + 2); + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute select statement.\n"); + ASSERT(0); + } + + result = taos_stmt_use_result(stmt); + + TAOS_ROW row; + int rows = 0; + int num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + + // fetch the records row by row + while ((row = taos_fetch_row(result))) { + char temp[256] = {0}; + rows++; + taos_print_row(temp, row, fields, num_fields); + ASSERT(strcmp(temp, "\\x0001020304") == 0); + } + ASSERT (rows == 1); + +// taos_free_result(result); + taos_stmt_close(stmt); + + // query the records + stmt = taos_stmt_init(taos); + taos_stmt_prepare(stmt, "SELECT varbin FROM m1 WHERE varbin = ?", 0); + + char tmp[16] = "\\x090a0b0c0d"; + vbinLen = strlen(tmp); + params[2].buffer_type = TSDB_DATA_TYPE_VARCHAR; + params[2].buffer_length = sizeof(v.varbin); + params[2].buffer = tmp; + params[2].length = &vbinLen; + taos_stmt_bind_param(stmt, params + 2); + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute select statement.\n"); + ASSERT(0); + } + + result = taos_stmt_use_result(stmt); + + rows = 0; + num_fields = taos_num_fields(result); + fields = taos_fetch_fields(result); + + // fetch the records row by row + while ((row = taos_fetch_row(result))) { + char temp[256] = {0}; + rows++; + taos_print_row(temp, row, fields, num_fields); + ASSERT(strcmp(temp, "\\x090A0B0C0D") == 0); + } + ASSERT (rows == 1); +// taos_free_result(result); + taos_stmt_close(stmt); + taos_close(taos); + printf("%s result success\n", __FUNCTION__); +} + +tmq_t* build_consumer() { + tmq_conf_t* conf = tmq_conf_new(); + tmq_conf_set(conf, "group.id", "tg2"); + tmq_conf_set(conf, "client.id", "my app 1"); + tmq_conf_set(conf, "td.connect.user", "root"); + tmq_conf_set(conf, "td.connect.pass", "taosdata"); + tmq_conf_set(conf, "msg.with.table.name", "true"); + tmq_conf_set(conf, "enable.auto.commit", "true"); + + tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); + assert(tmq); + tmq_conf_destroy(conf); + return tmq; +} + +void varbinary_tmq_test(){ + + // build database + + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT(pConn != NULL); + + TAOS_RES *pRes = taos_query(pConn, "drop database if exists abc"); + if (taos_errno(pRes) != 0) { + printf("error in drop db, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create database if not exists abc vgroups 1 wal_retention_period 3600"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "use abc"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create stable if not exists st1 (ts timestamp, c2 varbinary(16)) tags(t1 int, t2 varbinary(8))"); + if (taos_errno(pRes) != 0) { + printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists ct0 using st1 tags(1000, '\\x3f89')"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table tu1, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct0 values(1626006833400, 'hello')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct0, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table st1 modify column c2 varbinary(64)"); + if (taos_errno(pRes) != 0) { + printf("failed to alter super table st1, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table st1 add tag t3 varbinary(64)"); + if (taos_errno(pRes) != 0) { + printf("failed to alter super table st1, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table ct0 set tag t2='894'"); + if (taos_errno(pRes) != 0) { + printf("failed to slter child table ct3, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table tb1 (ts timestamp, c1 varbinary(8))"); + if (taos_errno(pRes) != 0) { + printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table tb1 add column c2 varbinary(8)"); + if (taos_errno(pRes) != 0) { + printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + // create topic + pRes = taos_query(pConn, "create topic topic_db with meta as database abc"); + if (taos_errno(pRes) != 0) { + printf("failed to create topic topic_db, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + + // build consumer + tmq_t* tmq = build_consumer(); + tmq_list_t* topic_list = tmq_list_new(); + tmq_list_append(topic_list, "topic_db"); + + int32_t code = tmq_subscribe(tmq, topic_list); + ASSERT(code == 0); + + int32_t cnt = 0; + while (1) { + TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 1000); + if (tmqmessage) { + if (tmq_get_res_type(tmqmessage) == TMQ_RES_TABLE_META || tmq_get_res_type(tmqmessage) == TMQ_RES_METADATA) { + char* result = tmq_get_json_meta(tmqmessage); +// if (result) { +// printf("meta result: %s\n", result); +// } + switch (cnt) { + case 0: + ASSERT(strcmp(result, "{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"st1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c2\",\"type\":16,\"length\":16}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t2\",\"type\":16,\"length\":8}]}") == 0); + break; + case 1: + ASSERT(strcmp(result, "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct0\",\"using\":\"st1\",\"tagNum\":2,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t2\",\"type\":16,\"value\":\"\\\"\\\\x3F89\\\"\"}],\"createList\":[]}") == 0); + break; + case 2: + ASSERT(strcmp(result, "{\"type\":\"alter\",\"tableType\":\"super\",\"tableName\":\"st1\",\"alterType\":7,\"colName\":\"c2\",\"colType\":16,\"colLength\":64}") == 0); + break; + case 3: + ASSERT(strcmp(result, "{\"type\":\"alter\",\"tableType\":\"super\",\"tableName\":\"st1\",\"alterType\":1,\"colName\":\"t3\",\"colType\":16,\"colLength\":64}") == 0); + break; + case 4: + ASSERT(strcmp(result, "{\"type\":\"alter\",\"tableType\":\"child\",\"tableName\":\"ct0\",\"alterType\":4,\"colName\":\"t2\",\"colValue\":\"\\\"\\\\x383934\\\"\",\"colValueNull\":false}") == 0); + break; + case 5: + ASSERT(strcmp(result, "{\"type\":\"create\",\"tableType\":\"normal\",\"tableName\":\"tb1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":16,\"length\":8}],\"tags\":[]}") == 0); + break; + case 6: + ASSERT(strcmp(result, "{\"type\":\"alter\",\"tableType\":\"normal\",\"tableName\":\"tb1\",\"alterType\":5,\"colName\":\"c2\",\"colType\":16,\"colLength\":8}") == 0); + break; + default: + break; + } + cnt++; + tmq_free_json_meta(result); + } + taos_free_result(tmqmessage); + } else { + break; + } + } + + code = tmq_consumer_close(tmq); + ASSERT(code == 0); + + tmq_list_destroy(topic_list); + + pRes = taos_query(pConn, "drop topic if exists topic_db"); + if (taos_errno(pRes) != 0) { + printf("error in drop topic, reason:%s\n", taos_errstr(pRes)); + ASSERT(0); + } + taos_free_result(pRes); + taos_close(pConn); + printf("%s result success\n", __FUNCTION__); } int main(int argc, char *argv[]) { int ret = 0; - ret = varbinary_test(); - ASSERT(!ret); + + varbinary_tmq_test(); + varbinary_stmt_test(); + varbinary_sql_test(); return ret; }