diff --git a/cmake/cmake.platform b/cmake/cmake.platform index acf17e9427..849d31f93e 100644 --- a/cmake/cmake.platform +++ b/cmake/cmake.platform @@ -70,5 +70,46 @@ ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows") ENDIF() +IF ("${CPUTYPE}" STREQUAL "") + MESSAGE(STATUS "The current platform " ${CMAKE_SYSTEM_PROCESSOR} " is detected") + + IF (CMAKE_SYSTEM_PROCESSOR MATCHES "(amd64)|(AMD64)") + MESSAGE(STATUS "The current platform is amd64") + SET(PLATFORM_ARCH_STR "amd64") + ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)") + MESSAGE(STATUS "The current platform is x86") + SET(PLATFORM_ARCH_STR "i386") + ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "armv7l") + MESSAGE(STATUS "The current platform is aarch32") + SET(PLATFORM_ARCH_STR "arm") + ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + MESSAGE(STATUS "The current platform is aarch64") + SET(PLATFORM_ARCH_STR "arm64") + ENDIF () +ELSE () + # if generate ARM version: + # cmake -DCPUTYPE=aarch32 .. or cmake -DCPUTYPE=aarch64 + IF (${CPUTYPE} MATCHES "aarch32") + SET(PLATFORM_ARCH_STR "arm") + MESSAGE(STATUS "input cpuType: aarch32") + ELSEIF (${CPUTYPE} MATCHES "aarch64") + SET(PLATFORM_ARCH_STR "arm64") + MESSAGE(STATUS "input cpuType: aarch64") + ELSEIF (${CPUTYPE} MATCHES "mips64") + SET(PLATFORM_ARCH_STR "mips") + MESSAGE(STATUS "input cpuType: mips64") + ELSEIF (${CPUTYPE} MATCHES "x64") + SET(PLATFORM_ARCH_STR "amd64") + MESSAGE(STATUS "input cpuType: x64") + ELSEIF (${CPUTYPE} MATCHES "x86") + SET(PLATFORM_ARCH_STR "i386") + MESSAGE(STATUS "input cpuType: x86") + ELSE () + MESSAGE(STATUS "input cpuType unknown " ${CPUTYPE}) + ENDIF () +ENDIF () + +MESSAGE(STATUS "platform arch:" ${PLATFORM_ARCH_STR}) + MESSAGE("C Compiler ID: ${CMAKE_C_COMPILER_ID}") MESSAGE("CXX Compiler ID: ${CMAKE_CXX_COMPILER_ID}") diff --git a/docs/en/14-reference/02-rest-api/02-rest-api.mdx b/docs/en/14-reference/02-rest-api/02-rest-api.mdx index 990af86196..fe18349a6d 100644 --- a/docs/en/14-reference/02-rest-api/02-rest-api.mdx +++ b/docs/en/14-reference/02-rest-api/02-rest-api.mdx @@ -21,7 +21,7 @@ The following example is in an Ubuntu environment and uses the `curl` tool to ve The following example lists all databases on the host h1.taosdata.com. To use it in your environment, replace `h1.taosdata.com` and `6041` (the default port) with the actual running TDengine service FQDN and port number. ```html -curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'show databases;' h1.taosdata.com:6041/rest/sql +curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "show databases;" h1.taosdata.com:6041/rest/sql ``` The following return value results indicate that the verification passed. @@ -106,13 +106,13 @@ The HTTP request's BODY is a complete SQL command, and the data table in the SQL Use `curl` to initiate an HTTP request with a custom authentication method, with the following syntax. ```bash -curl -H 'Authorization: Basic ' -d '' :/rest/sql/[db_name] +curl -L -H "Authorization: Basic " -d "" :/rest/sql/[db_name] ``` Or ```bash -curl -u username:password -d '' :/rest/sql/[db_name] +curl -L -u username:password -d "" :/rest/sql/[db_name] ``` where `TOKEN` is the string after Base64 encoding of `{username}:{password}`, e.g. `root:taosdata` is encoded as `cm9vdDp0YW9zZGF0YQ==`. @@ -192,7 +192,7 @@ Response body: - query all records from table d1001 of database demo ```bash - curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001' 192.168.0.1:6041/rest/sql + curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "select * from demo.d1001" 192.168.0.1:6041/rest/sql ``` Response body: @@ -218,7 +218,7 @@ Response body: - Create database demo: ```bash - curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'create database demo' 192.168.0.1:6041/rest/sql + curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "create database demo" 192.168.0.1:6041/rest/sql ``` Response body: @@ -240,7 +240,7 @@ Response body: When the HTTP request URL uses `/rest/sqlt`, the returned result set's timestamp value will be in Unix timestamp format, for example: ```bash -curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001' 192.168.0.1:6041/rest/sqlt +curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "select * from demo.d1001" 192.168.0.1:6041/rest/sqlt ``` Response body: @@ -268,7 +268,7 @@ Response body: When the HTTP request URL uses `/rest/sqlutc`, the timestamp of the returned result set will be expressed as a UTC format, for example: ```bash - curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.t1' 192.168.0.1:6041/rest/sqlutc + curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "select * from demo.t1" 192.168.0.1:6041/rest/sqlutc ``` Response body: diff --git a/docs/en/14-reference/06-taosdump.md b/docs/en/14-reference/06-taosdump.md index 5403e40925..96e68d0edb 100644 --- a/docs/en/14-reference/06-taosdump.md +++ b/docs/en/14-reference/06-taosdump.md @@ -36,6 +36,8 @@ There are two ways to install taosdump: :::tip - taosdump versions after 1.4.1 provide the `-I` argument for parsing Avro file schema and data. If users specify `-s` then only taosdump will parse schema. - Backups after taosdump 1.4.2 use the batch count specified by the `-B` parameter. The default value is 16384. If, in some environments, low network speed or disk performance causes "Error actual dump ... batch ...", then try changing the `-B` parameter to a smaller value. +- The export of taosdump does not support resuming from an interruption. Therefore, if the taosdump process terminates unexpectedly, delete all related files that have been exported or generated. +- The import of taosdump supports resuming from an interruption, but when the process resumes, you will receive some "table already exists" messages, which could be ignored. ::: diff --git a/docs/en/14-reference/12-directory.md b/docs/en/14-reference/12-directory.md index 304e3bcb43..d6cffd22e0 100644 --- a/docs/en/14-reference/12-directory.md +++ b/docs/en/14-reference/12-directory.md @@ -26,7 +26,6 @@ All executable files of TDengine are in the _/usr/local/taos/bin_ directory by d - _remove.sh_: script to uninstall TDengine, please execute it carefully, link to the **rmtaos** command in the /usr/bin directory. Will remove the TDengine installation directory `/usr/local/taos`, but will keep `/etc/taos`, `/var/lib/taos`, `/var/log/taos` - _taosadapter_: server-side executable that provides RESTful services and accepts writing requests from a variety of other softwares - _tarbitrator_: provides arbitration for two-node cluster deployments -- _run_taosd_and_taosadapter.sh_: script to start both taosd and taosAdapter - _TDinsight.sh_: script to download TDinsight and install it - _set_core.sh_: script for setting up the system to generate core dump files for easy debugging - _taosd-dump-cfg.gdb_: script to facilitate debugging of taosd's gdb execution. diff --git a/docs/en/27-train-faq/03-docker.md b/docs/en/27-train-faq/03-docker.md index afee13c137..0378fffb8b 100644 --- a/docs/en/27-train-faq/03-docker.md +++ b/docs/en/27-train-faq/03-docker.md @@ -109,7 +109,7 @@ taos> It's also able to access the REST interface provided by TDengine in container from the host. ``` -curl -u root:taosdata -d 'show databases' 127.0.0.1:6041/rest/sql +curl -L -u root:taosdata -d "show databases" 127.0.0.1:6041/rest/sql ``` Output is like below: @@ -147,7 +147,7 @@ docker run -d --name tdengine-taosd -p 6030-6042:6030-6042 -p 6030-6042:6030-604 - Verify the REST interface: ```bash -curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'show databases;' 127.0.0.1:6041/rest/sql +curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "show databases;" 127.0.0.1:6041/rest/sql ``` Below is an example output: diff --git a/docs/zh/14-reference/02-rest-api/02-rest-api.mdx b/docs/zh/14-reference/02-rest-api/02-rest-api.mdx index 43099319b9..a8a92606e4 100644 --- a/docs/zh/14-reference/02-rest-api/02-rest-api.mdx +++ b/docs/zh/14-reference/02-rest-api/02-rest-api.mdx @@ -21,7 +21,7 @@ RESTful 接口不依赖于任何 TDengine 的库,因此客户端不需要安 下面示例是列出所有的数据库,请把 h1.taosdata.com 和 6041(缺省值)替换为实际运行的 TDengine 服务 FQDN 和端口号: ```html -curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'show databases;' h1.taosdata.com:6041/rest/sql +curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "show databases;" h1.taosdata.com:6041/rest/sql ``` 返回值结果如下表示验证通过: @@ -106,13 +106,13 @@ HTTP 请求的 BODY 里就是一个完整的 SQL 语句,SQL 语句中的数据 使用 `curl` 通过自定义身份认证方式来发起一个 HTTP Request,语法如下: ```bash -curl -H 'Authorization: Basic ' -d '' :/rest/sql/[db_name] +curl -L -H "Authorization: Basic " -d "" :/rest/sql/[db_name] ``` 或者 ```bash -curl -u username:password -d '' :/rest/sql/[db_name] +curl -L -u username:password -d "" :/rest/sql/[db_name] ``` 其中,`TOKEN` 为 `{username}:{password}` 经过 Base64 编码之后的字符串,例如 `root:taosdata` 编码后为 `cm9vdDp0YW9zZGF0YQ==` @@ -192,7 +192,7 @@ curl http://192.168.0.1:6041/rest/login/root/taosdata - 在 demo 库里查询表 d1001 的所有记录: ```bash - curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001' 192.168.0.1:6041/rest/sql + curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "select * from demo.d1001" 192.168.0.1:6041/rest/sql ``` 返回值: @@ -218,7 +218,7 @@ curl http://192.168.0.1:6041/rest/login/root/taosdata - 创建库 demo: ```bash - curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'create database demo' 192.168.0.1:6041/rest/sql + curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "create database demo" 192.168.0.1:6041/rest/sql ``` 返回值: @@ -240,7 +240,7 @@ curl http://192.168.0.1:6041/rest/login/root/taosdata HTTP 请求 URL 采用 `/rest/sqlt` 时,返回结果集的时间戳将采用 Unix 时间戳格式表示,例如 ```bash -curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001' 192.168.0.1:6041/rest/sqlt +curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "select * from demo.d1001" 192.168.0.1:6041/rest/sqlt ``` 返回结果: @@ -268,7 +268,7 @@ curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001 HTTP 请求 URL 采用 `/rest/sqlutc` 时,返回结果集的时间戳将采用 UTC 时间字符串表示,例如 ```bash - curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.t1' 192.168.0.1:6041/rest/sqlutc + curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "select * from demo.t1" 192.168.0.1:6041/rest/sqlutc ``` 返回值: diff --git a/docs/zh/14-reference/06-taosdump.md b/docs/zh/14-reference/06-taosdump.md index 3a9f2e9acd..95ee20bfba 100644 --- a/docs/zh/14-reference/06-taosdump.md +++ b/docs/zh/14-reference/06-taosdump.md @@ -39,6 +39,8 @@ taosdump 有两种安装方式: :::tip - taosdump 1.4.1 之后的版本提供 `-I` 参数,用于解析 avro 文件 schema 和数据,如果指定 `-s` 参数将只解析 schema。 - taosdump 1.4.2 之后的备份使用 `-B` 参数指定的批次数,默认值为 16384,如果在某些环境下由于网络速度或磁盘性能不足导致 "Error actual dump .. batch .." 可以通过 `-B` 参数调整为更小的值进行尝试。 +- taosdump 的导出不支持中断恢复,所以当进程意外终止后,正确的处理方式是删除当前已导出或生成的所有相关文件。 +- taosdump 的导入支持中断恢复,但是当进程重新启动时,会收到一些“表已经存在”的提示,可以忽视。 ::: diff --git a/docs/zh/14-reference/12-directory.md b/docs/zh/14-reference/12-directory.md index f8c8cb4a08..0caf7e03c3 100644 --- a/docs/zh/14-reference/12-directory.md +++ b/docs/zh/14-reference/12-directory.md @@ -26,7 +26,6 @@ TDengine 的所有可执行文件默认存放在 _/usr/local/taos/bin_ 目录下 - _remove.sh_:卸载 TDengine 的脚本,请谨慎执行,链接到/usr/bin 目录下的**rmtaos**命令。会删除 TDengine 的安装目录/usr/local/taos,但会保留/etc/taos、/var/lib/taos、/var/log/taos - _taosadapter_: 提供 RESTful 服务和接受其他多种软件写入请求的服务端可执行文件 - _tarbitrator_: 提供双节点集群部署的仲裁功能 -- _run_taosd_and_taosadapter.sh_:同时启动 taosd 和 taosAdapter 的脚本 - _TDinsight.sh_:用于下载 TDinsight 并安装的脚本 - _set_core.sh_:用于方便调试设置系统生成 core dump 文件的脚本 - _taosd-dump-cfg.gdb_:用于方便调试 taosd 的 gdb 执行脚本。 diff --git a/docs/zh/27-train-faq/03-docker.md b/docs/zh/27-train-faq/03-docker.md index 7791569b25..72b4603dda 100644 --- a/docs/zh/27-train-faq/03-docker.md +++ b/docs/zh/27-train-faq/03-docker.md @@ -108,7 +108,7 @@ taos> 也可以在宿主机使用 curl 通过 RESTful 端口访问 Docker 容器内的 TDengine server。 ``` -curl -u root:taosdata -d 'show databases' 127.0.0.1:6041/rest/sql +curl -L -u root:taosdata -d "show databases" 127.0.0.1:6041/rest/sql ``` 输出示例如下: @@ -148,7 +148,7 @@ docker run -d --name tdengine-taosd -p 6030-6042:6030-6042 -p 6030-6042:6030-604 使用 curl 命令验证 RESTful 接口可以正常工作: ```bash -curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'show databases;' 127.0.0.1:6041/rest/sql +curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d "show databases;" 127.0.0.1:6041/rest/sql ``` 输出示例如下: diff --git a/examples/c/stream_demo.c b/examples/c/stream_demo.c index 5a141867e7..5f6e3b2aeb 100644 --- a/examples/c/stream_demo.c +++ b/examples/c/stream_demo.c @@ -25,19 +25,21 @@ int32_t init_env() { return -1; } - TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2"); + TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1"); if (taos_errno(pRes) != 0) { printf("error in create db, reason:%s\n", taos_errstr(pRes)); return -1; } taos_free_result(pRes); +#if 0 pRes = taos_query(pConn, "create database if not exists abc2 vgroups 20"); if (taos_errno(pRes) != 0) { printf("error in create db, reason:%s\n", taos_errstr(pRes)); return -1; } taos_free_result(pRes); +#endif pRes = taos_query(pConn, "use abc1"); if (taos_errno(pRes) != 0) { @@ -89,8 +91,8 @@ int32_t create_stream() { /*const char* sql = "select sum(k) from tu1 interval(10m)";*/ /*pRes = tmq_create_stream(pConn, "stream1", "out1", sql);*/ pRes = taos_query(pConn, - "create stream stream1 trigger at_once into abc2.outstb as select _wstartts, sum(k) from st1 " - "partition by tbname interval(10m) "); + "create stream stream1 trigger window_close into outstb as select _wstartts, sum(k) from st1 " + "interval(10s) "); if (taos_errno(pRes) != 0) { printf("failed to create stream stream1, reason:%s\n", taos_errstr(pRes)); return -1; @@ -107,11 +109,4 @@ int main(int argc, char* argv[]) { code = init_env(); } create_stream(); -#if 0 - tmq_t* tmq = build_consumer(); - tmq_list_t* topic_list = build_topic_list(); - /*perf_loop(tmq, topic_list);*/ - /*basic_consume_loop(tmq, topic_list);*/ - sync_consume_loop(tmq, topic_list); -#endif } diff --git a/include/client/taos.h b/include/client/taos.h index 61538e392a..9d4da221f4 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -187,8 +187,8 @@ DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res); DLL_EXPORT const char *taos_get_server_info(TAOS *taos); DLL_EXPORT const char *taos_get_client_info(); -DLL_EXPORT const char *taos_errstr(TAOS_RES *tres); -DLL_EXPORT int taos_errno(TAOS_RES *tres); +DLL_EXPORT const char *taos_errstr(TAOS_RES *res); +DLL_EXPORT int taos_errno(TAOS_RES *res); DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param); DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param); @@ -252,6 +252,16 @@ DLL_EXPORT void tmq_conf_set_auto_commit_cb(tmq_conf_t *conf, tmq_comm /* -------------------------TMQ MSG HANDLE INTERFACE---------------------- */ +enum tmq_res_t { + TMQ_RES_INVALID = -1, + TMQ_RES_DATA = 1, + TMQ_RES_TABLE_META = 2, +}; + +typedef enum tmq_res_t tmq_res_t; + +DLL_EXPORT tmq_res_t tmq_get_res_type(TAOS_RES *res); +DLL_EXPORT int32_t tmq_get_raw_meta(TAOS_RES *res, const void **raw_meta, int32_t *raw_meta_len); DLL_EXPORT const char *tmq_get_topic_name(TAOS_RES *res); DLL_EXPORT const char *tmq_get_db_name(TAOS_RES *res); DLL_EXPORT int32_t tmq_get_vgroup_id(TAOS_RES *res); diff --git a/include/common/systable.h b/include/common/systable.h index d2c28941c7..faea4dd3f8 100644 --- a/include/common/systable.h +++ b/include/common/systable.h @@ -41,6 +41,7 @@ extern "C" { #define TSDB_INS_TABLE_VGROUPS "vgroups" #define TSDB_INS_TABLE_VNODES "vnodes" #define TSDB_INS_TABLE_CONFIGS "configs" +#define TSDB_INS_TABLE_DNODE_VARIABLES "dnode_variables" #define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema" #define TSDB_PERFS_TABLE_SMAS "smas" diff --git a/include/common/tcommon.h b/include/common/tcommon.h index a05287761e..1eb73b503c 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -34,6 +34,7 @@ enum { enum { TMQ_MSG_TYPE__DUMMY = 0, TMQ_MSG_TYPE__POLL_RSP, + TMQ_MSG_TYPE__POLL_META_RSP, TMQ_MSG_TYPE__EP_RSP, TMQ_MSG_TYPE__END_RSP, }; @@ -49,6 +50,8 @@ typedef enum EStreamType { typedef struct { SArray* pTableList; SHashObj* map; // speedup acquire the tableQueryInfo by table uid + void* pTagCond; + void* pTagIndexCond; } STableListInfo; typedef struct SColumnDataAgg { diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 857a554f62..340cb9893f 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1317,7 +1317,7 @@ int32_t tSerializeSSetStandbyReq(void* buf, int32_t bufLen, SSetStandbyReq* pReq int32_t tDeserializeSSetStandbyReq(void* buf, int32_t bufLen, SSetStandbyReq* pReq); typedef struct { - char queryStrId[TSDB_QUERY_ID_LEN]; + char queryStrId[TSDB_QUERY_ID_LEN]; } SKillQueryReq; int32_t tSerializeSKillQueryReq(void* buf, int32_t bufLen, SKillQueryReq* pReq); @@ -1560,6 +1560,7 @@ typedef struct { char name[TSDB_TOPIC_FNAME_LEN]; // accout.topic int8_t igExists; int8_t subType; + int8_t withMeta; char* sql; char subDbName[TSDB_DB_FNAME_LEN]; union { @@ -1776,12 +1777,10 @@ typedef struct { } SDDropTopicReq; typedef struct { - float xFilesFactor; - int32_t delay; - int32_t qmsg1Len; - int32_t qmsg2Len; - char* qmsg1; // pAst1:qmsg1:SRetention1 => trigger aggr task1 - char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2 + int64_t maxdelay[2]; + int64_t watermark[2]; + int32_t qmsgLen[2]; + char* qmsg[2]; // pAst:qmsg:SRetention => trigger aggr task1/2 } SRSmaParam; int32_t tEncodeSRSmaParam(SEncoder* pCoder, const SRSmaParam* pRSmaParam); @@ -1817,6 +1816,8 @@ typedef struct SVCreateTbReq { tb_uid_t uid; int64_t ctime; int32_t ttl; + int32_t commentLen; + char* comment; int8_t type; union { struct { @@ -1834,6 +1835,7 @@ int tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq); static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) { taosMemoryFreeClear(req->name); + taosMemoryFreeClear(req->comment); if (req->type == TSDB_CHILD_TABLE) { taosMemoryFreeClear(req->ctb.pTag); } else if (req->type == TSDB_NORMAL_TABLE) { @@ -1930,7 +1932,7 @@ typedef struct { // TSDB_ALTER_TABLE_UPDATE_OPTIONS int8_t updateTTL; int32_t newTTL; - int8_t updateComment; + int32_t newCommentLen; char* newComment; } SVAlterTbReq; @@ -2281,6 +2283,9 @@ typedef struct { int8_t igNotExists; } SMDropStreamReq; +int32_t tSerializeSMDropStreamReq(void* buf, int32_t bufLen, const SMDropStreamReq* pReq); +int32_t tDeserializeSMDropStreamReq(void* buf, int32_t bufLen, SMDropStreamReq* pReq); + typedef struct { int8_t reserved; } SMDropStreamRsp; @@ -2302,6 +2307,7 @@ typedef struct { int64_t newConsumerId; char subKey[TSDB_SUBSCRIBE_KEY_LEN]; int8_t subType; + int8_t withMeta; char* qmsg; int64_t suid; } SMqRebVgReq; @@ -2314,6 +2320,7 @@ static FORCE_INLINE int32_t tEncodeSMqRebVgReq(void** buf, const SMqRebVgReq* pR tlen += taosEncodeFixedI64(buf, pReq->newConsumerId); tlen += taosEncodeString(buf, pReq->subKey); tlen += taosEncodeFixedI8(buf, pReq->subType); + tlen += taosEncodeFixedI8(buf, pReq->withMeta); if (pReq->subType == TOPIC_SUB_TYPE__COLUMN) { tlen += taosEncodeString(buf, pReq->qmsg); } else if (pReq->subType == TOPIC_SUB_TYPE__TABLE) { @@ -2329,6 +2336,7 @@ static FORCE_INLINE void* tDecodeSMqRebVgReq(const void* buf, SMqRebVgReq* pReq) buf = taosDecodeFixedI64(buf, &pReq->newConsumerId); buf = taosDecodeStringTo(buf, pReq->subKey); buf = taosDecodeFixedI8(buf, &pReq->subType); + buf = taosDecodeFixedI8(buf, &pReq->withMeta); if (pReq->subType == TOPIC_SUB_TYPE__COLUMN) { buf = taosDecodeString(buf, &pReq->qmsg); } else if (pReq->subType == TOPIC_SUB_TYPE__TABLE) { @@ -2673,6 +2681,34 @@ static FORCE_INLINE void tDeleteSMqSubTopicEp(SMqSubTopicEp* pSubTopicEp) { taosArrayDestroy(pSubTopicEp->vgs); } +typedef struct { + SMqRspHead head; + int64_t reqOffset; + int64_t rspOffset; + int16_t resMsgType; + int32_t metaRspLen; + void* metaRsp; +} SMqMetaRsp; + +static FORCE_INLINE int32_t tEncodeSMqMetaRsp(void** buf, const SMqMetaRsp* pRsp) { + int32_t tlen = 0; + tlen += taosEncodeFixedI64(buf, pRsp->reqOffset); + tlen += taosEncodeFixedI64(buf, pRsp->rspOffset); + tlen += taosEncodeFixedI16(buf, pRsp->resMsgType); + tlen += taosEncodeFixedI32(buf, pRsp->metaRspLen); + tlen += taosEncodeBinary(buf, pRsp->metaRsp, pRsp->metaRspLen); + return tlen; +} + +static FORCE_INLINE void* tDecodeSMqMetaRsp(const void* buf, SMqMetaRsp* pRsp) { + buf = taosDecodeFixedI64(buf, &pRsp->reqOffset); + buf = taosDecodeFixedI64(buf, &pRsp->rspOffset); + buf = taosDecodeFixedI16(buf, &pRsp->resMsgType); + buf = taosDecodeFixedI32(buf, &pRsp->metaRspLen); + buf = taosDecodeBinary(buf, &pRsp->metaRsp, pRsp->metaRspLen); + return (void*)buf; +} + typedef struct { SMqRspHead head; int64_t reqOffset; diff --git a/include/common/tmsgcb.h b/include/common/tmsgcb.h index e99377f9b4..b56f755266 100644 --- a/include/common/tmsgcb.h +++ b/include/common/tmsgcb.h @@ -34,7 +34,6 @@ typedef enum { WRITE_QUEUE, APPLY_QUEUE, SYNC_QUEUE, - MERGE_QUEUE, QUEUE_MAX, } EQueueType; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index f89f548fc5..907798d19d 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -187,7 +187,6 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_CONSUME, "vnode-consume", SMqPollReq, SMqDataBlkRsp) TD_DEF_MSG_TYPE(TDMT_VND_STREAM_TRIGGER, "vnode-stream-trigger", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_STREAM_DISPATCH_WRITE, "vnode-stream-task-dispatch-write", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_STREAM_TASK_DROP, "vnode-stream-task-drop", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_CREATE_SMA, "vnode-create-sma", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_SMA, "vnode-cancel-sma", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_SMA, "vnode-drop-sma", NULL, NULL) @@ -198,12 +197,13 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_ALTER_CONFIRM, "alter-confirm", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_ALTER_HASHRANGE, "alter-hashrange", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_COMPACT, "compact", NULL, NULL) - + TD_DEF_MSG_TYPE(TDMT_VND_DROP_TTL_TABLE, "drop-ttl-stb", NULL, NULL) TD_NEW_MSG_SEG(TDMT_QND_MSG) //shared by snode and vnode TD_NEW_MSG_SEG(TDMT_STREAM_MSG) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DEPLOY, "stream-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp) + TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DROP, "stream-task-drop", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RUN, "stream-task-run", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DISPATCH, "stream-task-dispatch", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RECOVER, "stream-task-recover", NULL, NULL) @@ -236,6 +236,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_SYNC_COMMON_RESPONSE, "sync-common-response", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_APPLY_MSG, "sync-apply-msg", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_CONFIG_CHANGE, "sync-config-change", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_SYNC_CONFIG_CHANGE_FINISH, "sync-config-change-finish", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_SEND, "sync-snapshot-send", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_RSP, "sync-snapshot-rsp", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_LEADER_TRANSFER, "sync-leader-transfer", NULL, NULL) diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 1edfcbabad..35b4a5ce7d 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -156,104 +156,107 @@ #define TK_SNODES 138 #define TK_CLUSTER 139 #define TK_TRANSACTIONS 140 -#define TK_LIKE 141 -#define TK_INDEX 142 -#define TK_FULLTEXT 143 -#define TK_FUNCTION 144 -#define TK_INTERVAL 145 -#define TK_TOPIC 146 -#define TK_AS 147 -#define TK_CONSUMER 148 -#define TK_GROUP 149 -#define TK_DESC 150 -#define TK_DESCRIBE 151 -#define TK_RESET 152 -#define TK_QUERY 153 -#define TK_CACHE 154 -#define TK_EXPLAIN 155 -#define TK_ANALYZE 156 -#define TK_VERBOSE 157 -#define TK_NK_BOOL 158 -#define TK_RATIO 159 -#define TK_NK_FLOAT 160 -#define TK_COMPACT 161 -#define TK_VNODES 162 -#define TK_IN 163 -#define TK_OUTPUTTYPE 164 -#define TK_AGGREGATE 165 -#define TK_BUFSIZE 166 -#define TK_STREAM 167 -#define TK_INTO 168 -#define TK_TRIGGER 169 -#define TK_AT_ONCE 170 -#define TK_WINDOW_CLOSE 171 -#define TK_KILL 172 -#define TK_CONNECTION 173 -#define TK_TRANSACTION 174 -#define TK_BALANCE 175 -#define TK_VGROUP 176 -#define TK_MERGE 177 -#define TK_REDISTRIBUTE 178 -#define TK_SPLIT 179 -#define TK_SYNCDB 180 -#define TK_DELETE 181 -#define TK_NULL 182 -#define TK_NK_QUESTION 183 -#define TK_NK_ARROW 184 -#define TK_ROWTS 185 -#define TK_TBNAME 186 -#define TK_QSTARTTS 187 -#define TK_QENDTS 188 -#define TK_WSTARTTS 189 -#define TK_WENDTS 190 -#define TK_WDURATION 191 -#define TK_CAST 192 -#define TK_NOW 193 -#define TK_TODAY 194 -#define TK_TIMEZONE 195 -#define TK_COUNT 196 -#define TK_LAST_ROW 197 -#define TK_BETWEEN 198 -#define TK_IS 199 -#define TK_NK_LT 200 -#define TK_NK_GT 201 -#define TK_NK_LE 202 -#define TK_NK_GE 203 -#define TK_NK_NE 204 -#define TK_MATCH 205 -#define TK_NMATCH 206 -#define TK_CONTAINS 207 -#define TK_JOIN 208 -#define TK_INNER 209 -#define TK_SELECT 210 -#define TK_DISTINCT 211 -#define TK_WHERE 212 -#define TK_PARTITION 213 -#define TK_BY 214 -#define TK_SESSION 215 -#define TK_STATE_WINDOW 216 -#define TK_SLIDING 217 -#define TK_FILL 218 -#define TK_VALUE 219 -#define TK_NONE 220 -#define TK_PREV 221 -#define TK_LINEAR 222 -#define TK_NEXT 223 -#define TK_HAVING 224 -#define TK_ORDER 225 -#define TK_SLIMIT 226 -#define TK_SOFFSET 227 -#define TK_LIMIT 228 -#define TK_OFFSET 229 -#define TK_ASC 230 -#define TK_NULLS 231 -#define TK_ID 232 -#define TK_NK_BITNOT 233 -#define TK_INSERT 234 -#define TK_VALUES 235 -#define TK_IMPORT 236 -#define TK_NK_SEMI 237 -#define TK_FILE 238 +#define TK_DISTRIBUTED 141 +#define TK_LIKE 142 +#define TK_INDEX 143 +#define TK_FULLTEXT 144 +#define TK_FUNCTION 145 +#define TK_INTERVAL 146 +#define TK_TOPIC 147 +#define TK_AS 148 +#define TK_CONSUMER 149 +#define TK_GROUP 150 +#define TK_DESC 151 +#define TK_DESCRIBE 152 +#define TK_RESET 153 +#define TK_QUERY 154 +#define TK_CACHE 155 +#define TK_EXPLAIN 156 +#define TK_ANALYZE 157 +#define TK_VERBOSE 158 +#define TK_NK_BOOL 159 +#define TK_RATIO 160 +#define TK_NK_FLOAT 161 +#define TK_COMPACT 162 +#define TK_VNODES 163 +#define TK_IN 164 +#define TK_OUTPUTTYPE 165 +#define TK_AGGREGATE 166 +#define TK_BUFSIZE 167 +#define TK_STREAM 168 +#define TK_INTO 169 +#define TK_TRIGGER 170 +#define TK_AT_ONCE 171 +#define TK_WINDOW_CLOSE 172 +#define TK_KILL 173 +#define TK_CONNECTION 174 +#define TK_TRANSACTION 175 +#define TK_BALANCE 176 +#define TK_VGROUP 177 +#define TK_MERGE 178 +#define TK_REDISTRIBUTE 179 +#define TK_SPLIT 180 +#define TK_SYNCDB 181 +#define TK_DELETE 182 +#define TK_NULL 183 +#define TK_NK_QUESTION 184 +#define TK_NK_ARROW 185 +#define TK_ROWTS 186 +#define TK_TBNAME 187 +#define TK_QSTARTTS 188 +#define TK_QENDTS 189 +#define TK_WSTARTTS 190 +#define TK_WENDTS 191 +#define TK_WDURATION 192 +#define TK_CAST 193 +#define TK_NOW 194 +#define TK_TODAY 195 +#define TK_TIMEZONE 196 +#define TK_COUNT 197 +#define TK_LAST_ROW 198 +#define TK_BETWEEN 199 +#define TK_IS 200 +#define TK_NK_LT 201 +#define TK_NK_GT 202 +#define TK_NK_LE 203 +#define TK_NK_GE 204 +#define TK_NK_NE 205 +#define TK_MATCH 206 +#define TK_NMATCH 207 +#define TK_CONTAINS 208 +#define TK_JOIN 209 +#define TK_INNER 210 +#define TK_SELECT 211 +#define TK_DISTINCT 212 +#define TK_WHERE 213 +#define TK_PARTITION 214 +#define TK_BY 215 +#define TK_SESSION 216 +#define TK_STATE_WINDOW 217 +#define TK_SLIDING 218 +#define TK_FILL 219 +#define TK_VALUE 220 +#define TK_NONE 221 +#define TK_PREV 222 +#define TK_LINEAR 223 +#define TK_NEXT 224 +#define TK_HAVING 225 +#define TK_RANGE 226 +#define TK_EVERY 227 +#define TK_ORDER 228 +#define TK_SLIMIT 229 +#define TK_SOFFSET 230 +#define TK_LIMIT 231 +#define TK_OFFSET 232 +#define TK_ASC 233 +#define TK_NULLS 234 +#define TK_ID 235 +#define TK_NK_BITNOT 236 +#define TK_INSERT 237 +#define TK_VALUES 238 +#define TK_IMPORT 239 +#define TK_NK_SEMI 240 +#define TK_FILE 241 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 21d8405f58..2509c10601 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -95,7 +95,8 @@ int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad); */ int32_t mndProcessRpcMsg(SRpcMsg *pMsg); int32_t mndProcessSyncMsg(SRpcMsg *pMsg); -int32_t mndPreProcessMsg(SRpcMsg *pMsg); +int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg); +void mndPostProcessQueryMsg(SRpcMsg *pMsg); /** * @brief Generate machine code diff --git a/include/dnode/snode/snode.h b/include/dnode/snode/snode.h index 611bff49f1..3d0ef2e052 100644 --- a/include/dnode/snode/snode.h +++ b/include/dnode/snode/snode.h @@ -16,8 +16,8 @@ #ifndef _TD_SNODE_H_ #define _TD_SNODE_H_ -#include "tmsgcb.h" #include "tmsg.h" +#include "tmsgcb.h" #include "trpc.h" #ifdef __cplusplus @@ -68,8 +68,8 @@ int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad); * @param pMsg The request message * @param pRsp The response message */ -void sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg); -void sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg); +int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg); +int32_t sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg); #ifdef __cplusplus } diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index c0116051af..0c720138bd 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -69,6 +69,7 @@ typedef struct SCatalogReq { SArray* pUser; // element is SUserAuthInfo SArray* pTableIndex; // element is SNAME bool qNodeRequired; // valid qnode + bool dNodeRequired; // valid dnode bool forceUpdate; } SCatalogReq; @@ -87,7 +88,8 @@ typedef struct SMetaData { SArray* pUdfList; // pRes = SFuncInfo* SArray* pIndex; // pRes = SIndexInfo* SArray* pUser; // pRes = bool* - SArray* pQnodeList; // pRes = SQueryNodeAddr* + SArray* pQnodeList; // pRes = SArray* + SArray* pDnodeList; // pRes = SArray* } SMetaData; typedef struct SCatalogCfg { @@ -268,6 +270,8 @@ int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, uint64_t int32_t catalogGetQnodeList(SCatalog* pCatalog, SRequestConnInfo* pConn, SArray* pQnodeList); +int32_t catalogGetDnodeList(SCatalog* pCatalog, SRequestConnInfo* pConn, SArray** pDnodeList); + int32_t catalogGetExpiredSTables(SCatalog* pCatalog, SSTableVersion **stables, uint32_t *num); int32_t catalogGetExpiredDBs(SCatalog* pCatalog, SDbVgVersion** dbs, uint32_t* num); diff --git a/include/libs/function/function.h b/include/libs/function/function.h index 0d8ae289cc..e543f0f653 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -67,7 +67,7 @@ typedef struct SResultRowEntryInfo { bool initialized:1; // output buffer has been initialized bool complete:1; // query has completed uint8_t isNullRes:6; // the result is null - uint8_t numOfRes; // num of output result in current buffer + uint16_t numOfRes; // num of output result in current buffer } SResultRowEntryInfo; // determine the real data need to calculated the result diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 8e003eea7f..cbaff29cb2 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -121,7 +121,8 @@ typedef enum EFunctionType { // internal function FUNCTION_TYPE_SELECT_VALUE, - FUNCTION_TYPE_BLOCK_DIST, // block distribution aggregate function + FUNCTION_TYPE_BLOCK_DIST, // block distribution aggregate function + FUNCTION_TYPE_BLOCK_DIST_INFO, // block distribution pseudo column function // distributed splitting functions FUNCTION_TYPE_APERCENTILE_PARTIAL = 4000, @@ -188,6 +189,7 @@ bool fmIsForbidStreamFunc(int32_t funcId); bool fmIsForbidWindowFunc(int32_t funcId); bool fmIsForbidGroupByFunc(int32_t funcId); bool fmIsIntervalInterpoFunc(int32_t funcId); +bool fmIsInterpFunc(int32_t funcId); int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc); diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 087d252ed7..4578087164 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -87,6 +87,7 @@ typedef struct SAlterDatabaseStmt { typedef struct STableOptions { ENodeType type; + bool commentNull; char comment[TSDB_TB_COMMENT_LEN]; SNodeList* pMaxDelay; int64_t maxDelay1; @@ -118,14 +119,15 @@ typedef struct SCreateTableStmt { } SCreateTableStmt; typedef struct SCreateSubTableClause { - ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - char useDbName[TSDB_DB_NAME_LEN]; - char useTableName[TSDB_TABLE_NAME_LEN]; - bool ignoreExists; - SNodeList* pSpecificTags; - SNodeList* pValsOfTags; + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + char useDbName[TSDB_DB_NAME_LEN]; + char useTableName[TSDB_TABLE_NAME_LEN]; + bool ignoreExists; + SNodeList* pSpecificTags; + SNodeList* pValsOfTags; + STableOptions* pOptions; } SCreateSubTableClause; typedef struct SCreateMultiTableStmt { @@ -203,9 +205,10 @@ typedef struct SAlterDnodeStmt { } SAlterDnodeStmt; typedef struct SShowStmt { - ENodeType type; - SNode* pDbName; // SValueNode - SNode* pTbNamePattern; // SValueNode + ENodeType type; + SNode* pDbName; // SValueNode + SNode* pTbName; // SValueNode + EOperatorType tableCondType; } SShowStmt; typedef struct SShowCreateDatabaseStmt { @@ -221,6 +224,17 @@ typedef struct SShowCreateTableStmt { STableMeta* pMeta; } SShowCreateTableStmt; +typedef struct SShowTableDistributedStmt { + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; +} SShowTableDistributedStmt; + +typedef struct SShowDnodeVariablesStmt { + ENodeType type; + SNode* pDnodeId; +} SShowDnodeVariablesStmt; + typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT } EIndexType; typedef struct SIndexOptions { diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 08190d978e..58e2393970 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -180,11 +180,14 @@ typedef enum ENodeType { QUERY_NODE_SHOW_VNODES_STMT, QUERY_NODE_SHOW_APPS_STMT, QUERY_NODE_SHOW_SCORES_STMT, - QUERY_NODE_SHOW_VARIABLE_STMT, + QUERY_NODE_SHOW_VARIABLES_STMT, + QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT, + QUERY_NODE_SHOW_DNODE_VARIABLES_STMT, QUERY_NODE_SHOW_CREATE_DATABASE_STMT, QUERY_NODE_SHOW_CREATE_TABLE_STMT, QUERY_NODE_SHOW_CREATE_STABLE_STMT, QUERY_NODE_SHOW_TRANSACTIONS_STMT, + QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT, QUERY_NODE_KILL_CONNECTION_STMT, QUERY_NODE_KILL_QUERY_STMT, QUERY_NODE_KILL_TRANSACTION_STMT, @@ -204,6 +207,7 @@ typedef enum ENodeType { QUERY_NODE_LOGIC_PLAN_SORT, QUERY_NODE_LOGIC_PLAN_PARTITION, QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC, + QUERY_NODE_LOGIC_PLAN_INTERP_FUNC, QUERY_NODE_LOGIC_SUBPLAN, QUERY_NODE_LOGIC_PLAN, @@ -214,6 +218,7 @@ typedef enum ENodeType { QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN, + QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN, QUERY_NODE_PHYSICAL_PLAN_PROJECT, QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN, QUERY_NODE_PHYSICAL_PLAN_HASH_AGG, @@ -234,6 +239,7 @@ typedef enum ENodeType { QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE, QUERY_NODE_PHYSICAL_PLAN_PARTITION, QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC, + QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC, QUERY_NODE_PHYSICAL_PLAN_DISPATCH, QUERY_NODE_PHYSICAL_PLAN_INSERT, QUERY_NODE_PHYSICAL_PLAN_DELETE, diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index ac37b0c44f..aeaeb12bc3 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -39,7 +39,8 @@ typedef enum EScanType { SCAN_TYPE_TABLE, SCAN_TYPE_SYSTEM_TABLE, SCAN_TYPE_STREAM, - SCAN_TYPE_TABLE_MERGE + SCAN_TYPE_TABLE_MERGE, + SCAN_TYPE_BLOCK_INFO } EScanType; typedef struct SScanLogicNode { @@ -98,9 +99,19 @@ typedef struct SProjectLogicNode { typedef struct SIndefRowsFuncLogicNode { SLogicNode node; - SNodeList* pVectorFuncs; + SNodeList* pFuncs; } SIndefRowsFuncLogicNode; +typedef struct SInterpFuncLogicNode { + SLogicNode node; + SNodeList* pFuncs; + STimeWindow timeRange; + int64_t interval; + EFillMode fillMode; + SNode* pFillValues; // SNodeListNode + SNode* pTimeSeries; // SColumnNode +} SInterpFuncLogicNode; + typedef enum EModifyTableType { MODIFY_TABLE_TYPE_INSERT = 1, MODIFY_TABLE_TYPE_DELETE } EModifyTableType; typedef struct SVnodeModifyLogicNode { @@ -154,6 +165,7 @@ typedef struct SWindowLogicNode { int8_t slidingUnit; int64_t sessionGap; SNode* pTspk; + SNode* pTsEnd; SNode* pStateExpr; int8_t triggerType; int64_t watermark; @@ -248,6 +260,7 @@ typedef struct SScanPhysiNode { } SScanPhysiNode; typedef SScanPhysiNode STagScanPhysiNode; +typedef SScanPhysiNode SBlockDistScanPhysiNode; typedef struct SSystemTableScanPhysiNode { SScanPhysiNode scan; @@ -291,9 +304,20 @@ typedef struct SProjectPhysiNode { typedef struct SIndefRowsFuncPhysiNode { SPhysiNode node; SNodeList* pExprs; - SNodeList* pVectorFuncs; + SNodeList* pFuncs; } SIndefRowsFuncPhysiNode; +typedef struct SInterpFuncPhysiNode { + SPhysiNode node; + SNodeList* pExprs; + SNodeList* pFuncs; + STimeWindow timeRange; + int64_t interval; + EFillMode fillMode; + SNode* pFillValues; // SNodeListNode + SNode* pTimeSeries; // SColumnNode +} SInterpFuncPhysiNode; + typedef struct SJoinPhysiNode { SPhysiNode node; EJoinType joinType; @@ -336,7 +360,8 @@ typedef struct SWinodwPhysiNode { SPhysiNode node; SNodeList* pExprs; // these are expression list of parameter expression of function SNodeList* pFuncs; - SNode* pTspk; // timestamp primary key + SNode* pTspk; // timestamp primary key + SNode* pTsEnd; // window end timestamp int8_t triggerType; int64_t watermark; double filesFactor; diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 78c6f3467e..3191d0c8eb 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -240,6 +240,9 @@ typedef struct SSelectStmt { SNode* pWindow; SNodeList* pGroupByList; // SGroupingSetNode SNode* pHaving; + SNode* pRange; + SNode* pEvery; + SNode* pFill; SNodeList* pOrderByList; // SOrderByExprNode SLimitNode* pLimit; SLimitNode* pSlimit; @@ -254,6 +257,7 @@ typedef struct SSelectStmt { bool hasSelectValFunc; bool hasUniqueFunc; bool hasTailFunc; + bool hasInterpFunc; } SSelectStmt; typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType; diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index 8ed95b6010..c4f71e57a8 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -36,7 +36,6 @@ typedef struct SPlanContext { int64_t watermark; char* pMsg; int32_t msgLen; - // double filesFactor; } SPlanContext; // Create the physical plan for the query, according to the AST. diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index b6a3a08f7e..d562d07d77 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -47,6 +47,10 @@ typedef enum { TARGET_TYPE_OTHER, } ETargetType; +#define QUERY_POLICY_VNODE 1 +#define QUERY_POLICY_HYBRID 2 +#define QUERY_POLICY_QNODE 3 + typedef struct STableComInfo { uint8_t numOfTags; // the number of tags in schema uint8_t precision; // the number of precision diff --git a/include/libs/qworker/qworker.h b/include/libs/qworker/qworker.h index f3f147955a..3b8a37f420 100644 --- a/include/libs/qworker/qworker.h +++ b/include/libs/qworker/qworker.h @@ -64,6 +64,8 @@ typedef struct { int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, SQWorkerCfg *cfg, void **qWorkerMgmt, const SMsgCb *pMsgCb); +int32_t qWorkerAbortPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg); + int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg); int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_t ts); diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index 2c9d66a828..ee599e8498 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -30,9 +30,14 @@ extern "C" { typedef struct SStreamTask SStreamTask; enum { - TASK_STATUS__IDLE = 1, - TASK_STATUS__EXECUTING, - TASK_STATUS__CLOSING, + TASK_STATUS__NORMAL = 0, + TASK_STATUS__DROPPING, +}; + +enum { + TASK_EXEC_STATUS__IDLE = 1, + TASK_EXEC_STATUS__EXECUTING, + TASK_EXEC_STATUS__CLOSING, }; enum { @@ -50,16 +55,12 @@ enum { TASK_OUTPUT_STATUS__BLOCKED, }; -enum { - STREAM_CREATED_BY__USER = 1, - STREAM_CREATED_BY__SMA, -}; - enum { STREAM_INPUT__DATA_SUBMIT = 1, STREAM_INPUT__DATA_BLOCK, STREAM_INPUT__TRIGGER, STREAM_INPUT__CHECKPOINT, + STREAM_INPUT__DROP, }; typedef struct { @@ -152,7 +153,6 @@ void* streamDataBlockDecode(const void* buf, SStreamDataBlock* pInput); typedef struct { char* qmsg; // followings are not applicable to encoder and decoder - void* inputHandle; void* executor; } STaskExec; @@ -238,14 +238,17 @@ struct SStreamTask { int64_t streamId; int32_t taskId; int8_t inputType; - int8_t status; + int8_t taskStatus; + + int8_t execStatus; - int8_t sourceType; int8_t execType; int8_t sinkType; int8_t dispatchType; int16_t dispatchMsgType; + int8_t dataScan; + // node info int32_t childId; int32_t nodeId; @@ -399,15 +402,13 @@ typedef struct { int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq); -int32_t streamLaunchByWrite(SStreamTask* pTask, int32_t vgId, SMsgCb* pMsgCb); +int32_t streamLaunchByWrite(SStreamTask* pTask, int32_t vgId); int32_t streamSetupTrigger(SStreamTask* pTask); -int32_t streamTaskRun(SStreamTask* pTask); - -int32_t streamTaskProcessRunReq(SStreamTask* pTask, SMsgCb* pMsgCb); -int32_t streamProcessDispatchReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchReq* pReq, SRpcMsg* pMsg); -int32_t streamProcessDispatchRsp(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchRsp* pRsp); -int32_t streamProcessRecoverReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamTaskRecoverReq* pReq, SRpcMsg* pMsg); +int32_t streamProcessRunReq(SStreamTask* pTask); +int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pMsg); +int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp); +int32_t streamProcessRecoverReq(SStreamTask* pTask, SStreamTaskRecoverReq* pReq, SRpcMsg* pMsg); int32_t streamProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp); #ifdef __cplusplus diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index e8c4faa240..e963f25616 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -24,6 +24,8 @@ extern "C" { #include "tdef.h" #include "tmsgcb.h" +extern bool gRaftDetailLog; + #define SYNC_INDEX_BEGIN 0 #define SYNC_INDEX_INVALID -1 @@ -61,28 +63,35 @@ typedef struct SSyncCfg { } SSyncCfg; typedef struct SFsmCbMeta { - SyncIndex index; - SyncIndex lastConfigIndex; - bool isWeak; int32_t code; - ESyncState state; - uint64_t seqNum; + SyncIndex index; SyncTerm term; + uint64_t seqNum; + SyncIndex lastConfigIndex; + ESyncState state; SyncTerm currentTerm; + bool isWeak; uint64_t flag; } SFsmCbMeta; typedef struct SReConfigCbMeta { - int32_t code; - SyncIndex index; - SyncTerm term; - SyncIndex lastConfigIndex; - SyncTerm currentTerm; + int32_t code; + SyncIndex index; + SyncTerm term; + uint64_t seqNum; + SyncIndex lastConfigIndex; + ESyncState state; + SyncTerm currentTerm; + bool isWeak; + uint64_t flag; + + // config info SSyncCfg oldCfg; SSyncCfg newCfg; - bool isDrop; - uint64_t flag; - uint64_t seqNum; + SyncIndex newCfgIndex; + SyncTerm newCfgTerm; + uint64_t newCfgSeqNum; + } SReConfigCbMeta; typedef struct SSnapshot { @@ -107,7 +116,8 @@ typedef struct SSyncFSM { void (*FpReConfigCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta); void (*FpLeaderTransferCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta); - int32_t (*FpGetSnapshot)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot); + int32_t (*FpGetSnapshot)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot, void* pReaderParam, void** ppReader); + int32_t (*FpGetSnapshotInfo)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot); int32_t (*FpSnapshotStartRead)(struct SSyncFSM* pFsm, void** ppReader); int32_t (*FpSnapshotStopRead)(struct SSyncFSM* pFsm, void* pReader); @@ -187,14 +197,12 @@ ESyncState syncGetMyRole(int64_t rid); bool syncIsReady(int64_t rid); const char* syncGetMyRoleStr(int64_t rid); SyncTerm syncGetMyTerm(int64_t rid); +SyncGroupId syncGetVgId(int64_t rid); void syncGetEpSet(int64_t rid, SEpSet* pEpSet); -int32_t syncGetVgId(int64_t rid); int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); bool syncEnvIsStart(); const char* syncStr(ESyncState state); bool syncIsRestoreFinish(int64_t rid); -int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta); -int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta); int32_t syncReconfig(int64_t rid, const SSyncCfg* pNewCfg); diff --git a/include/libs/sync/syncTools.h b/include/libs/sync/syncTools.h index fbf124bf47..37b465e56e 100644 --- a/include/libs/sync/syncTools.h +++ b/include/libs/sync/syncTools.h @@ -489,6 +489,40 @@ void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg); void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg); void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg); + +// --------------------------------------------- +typedef struct SyncReconfigFinish { + uint32_t bytes; + int32_t vgId; + uint32_t msgType; + SSyncCfg oldCfg; + SSyncCfg newCfg; + SyncIndex newCfgIndex; + SyncTerm newCfgTerm; + uint64_t newCfgSeqNum; + +} SyncReconfigFinish; + +SyncReconfigFinish* syncReconfigFinishBuild(int32_t vgId); +void syncReconfigFinishDestroy(SyncReconfigFinish* pMsg); +void syncReconfigFinishSerialize(const SyncReconfigFinish* pMsg, char* buf, uint32_t bufLen); +void syncReconfigFinishDeserialize(const char* buf, uint32_t len, SyncReconfigFinish* pMsg); +char* syncReconfigFinishSerialize2(const SyncReconfigFinish* pMsg, uint32_t* len); +SyncReconfigFinish* syncReconfigFinishDeserialize2(const char* buf, uint32_t len); +void syncReconfigFinish2RpcMsg(const SyncReconfigFinish* pMsg, SRpcMsg* pRpcMsg); +void syncReconfigFinishFromRpcMsg(const SRpcMsg* pRpcMsg, SyncReconfigFinish* pMsg); +SyncReconfigFinish* syncReconfigFinishFromRpcMsg2(const SRpcMsg* pRpcMsg); +cJSON* syncReconfigFinish2Json(const SyncReconfigFinish* pMsg); +char* syncReconfigFinish2Str(const SyncReconfigFinish* pMsg); + +// for debug ---------------------- +void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg); +void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg); +void syncReconfigFinishLog(const SyncReconfigFinish* pMsg); +void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg); + + + // on message ---------------------- int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg); int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg); diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 280af6adb5..e695a9e282 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -128,6 +128,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TSC_STMT_TBNAME_ERROR TAOS_DEF_ERROR_CODE(0, 0X0226) #define TSDB_CODE_TSC_STMT_CLAUSE_ERROR TAOS_DEF_ERROR_CODE(0, 0X0227) #define TSDB_CODE_TSC_QUERY_KILLED TAOS_DEF_ERROR_CODE(0, 0X0228) +#define TSDB_CODE_TSC_NO_EXEC_NODE TAOS_DEF_ERROR_CODE(0, 0X0229) // mnode-common #define TSDB_CODE_MND_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0300) @@ -415,6 +416,10 @@ int32_t* taosGetErrno(); #define TSDB_CODE_SYN_NOT_LEADER TAOS_DEF_ERROR_CODE(0, 0x090C) #define TSDB_CODE_SYN_ONE_REPLICA TAOS_DEF_ERROR_CODE(0, 0x090D) #define TSDB_CODE_SYN_NOT_IN_NEW_CONFIG TAOS_DEF_ERROR_CODE(0, 0x090E) +#define TSDB_CODE_SYN_NEW_CONFIG_ERROR TAOS_DEF_ERROR_CODE(0, 0x090F) +#define TSDB_CODE_SYN_RECONFIG_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0910) +#define TSDB_CODE_SYN_PROPOSE_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0911) +#define TSDB_CODE_SYN_STANDBY_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0912) #define TSDB_CODE_SYN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x09FF) // tq @@ -563,6 +568,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_STREAM_NOT_ALLOWED_FUNC TAOS_DEF_ERROR_CODE(0, 0x265A) #define TSDB_CODE_PAR_GROUP_BY_NOT_ALLOWED_FUNC TAOS_DEF_ERROR_CODE(0, 0x265B) #define TSDB_CODE_PAR_INVALID_TABLE_OPTION TAOS_DEF_ERROR_CODE(0, 0x265C) +#define TSDB_CODE_PAR_INVALID_INTERP_CLAUSE TAOS_DEF_ERROR_CODE(0, 0x265D) //planner #define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index ea8ebba450..d0fbf0c4d7 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -88,7 +88,6 @@ else ${build_dir}/bin/tarbitrator\ ${script_dir}/remove.sh \ ${script_dir}/set_core.sh \ - ${script_dir}/run_taosd_and_taosadapter.sh \ ${script_dir}/startPre.sh \ ${script_dir}/taosd-dump-cfg.gdb" fi @@ -152,7 +151,6 @@ if [ $adapterName != "taosadapter" ]; then sed -i "s/taosadapter/${adapterName}/g" ${install_dir}/cfg/$adapterName.service mv ${install_dir}/bin/taosadapter ${install_dir}/bin/${adapterName} - mv ${install_dir}/bin/run_taosd_and_taosadapter.sh ${install_dir}/bin/run_${serverName}_and_${adapterName}.sh mv ${install_dir}/bin/taosd-dump-cfg.gdb ${install_dir}/bin/${serverName}-dump-cfg.gdb fi diff --git a/packaging/tools/run_taosd_and_taosadapter.sh b/packaging/tools/run_taosd_and_taosadapter.sh deleted file mode 100755 index 9ab9eb484a..0000000000 --- a/packaging/tools/run_taosd_and_taosadapter.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -[[ -x /usr/bin/taosadapter ]] && /usr/bin/taosadapter & -taosd diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 51a5b84a1c..cfe507e505 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -20,6 +20,7 @@ extern "C" { #endif +#include "catalog.h" #include "parser.h" #include "planner.h" #include "query.h" @@ -50,10 +51,12 @@ extern "C" { enum { RES_TYPE__QUERY = 1, RES_TYPE__TMQ, + RES_TYPE__TMQ_META, }; -#define TD_RES_QUERY(res) (*(int8_t*)res == RES_TYPE__QUERY) -#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ) +#define TD_RES_QUERY(res) (*(int8_t*)res == RES_TYPE__QUERY) +#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ) +#define TD_RES_TMQ_META(res) (*(int8_t*)res == RES_TYPE__TMQ_META) typedef struct SAppInstInfo SAppInstInfo; @@ -65,9 +68,9 @@ typedef struct { int64_t reportBytes; // not implemented int64_t startTime; // ctl - SRWLatch lock; // lock is used in serialization + SRWLatch lock; // lock is used in serialization SAppInstInfo* pAppInstInfo; - SHashObj* activeInfo; // hash + SHashObj* activeInfo; // hash } SAppHbMgr; typedef int32_t (*FHbRspHandle)(SAppHbMgr* pAppHbMgr, SClientHbRsp* pRsp); @@ -75,13 +78,13 @@ typedef int32_t (*FHbRspHandle)(SAppHbMgr* pAppHbMgr, SClientHbRsp* pRsp); typedef int32_t (*FHbReqHandle)(SClientHbKey* connKey, void* param, SClientHbReq* req); typedef struct { - int8_t inited; - int64_t appId; + int8_t inited; + int64_t appId; // ctl int8_t threadStop; TdThread thread; - TdThreadMutex lock; // used when app init and cleanup - SHashObj *appSummary; + TdThreadMutex lock; // used when app init and cleanup + SHashObj* appSummary; SArray* appHbMgrs; // SArray one for each cluster FHbReqHandle reqHandle[CONN_TYPE__MAX]; FHbRspHandle rspHandle[CONN_TYPE__MAX]; @@ -128,7 +131,7 @@ typedef struct STscObj { int8_t connType; int32_t acctId; uint32_t connId; - TAOS *id; // ref ID returned by taosAddRef + TAOS* id; // ref ID returned by taosAddRef TdThreadMutex mutex; // used to protect the operation on db int32_t numOfReqs; // number of sqlObj bound to this connection SAppInstInfo* pAppInfo; @@ -162,6 +165,7 @@ typedef struct SReqResultInfo { int32_t precision; bool convertUcs4; int32_t payloadLen; + char* convertJson; } SReqResultInfo; typedef struct SRequestSendRecvBody { @@ -186,6 +190,14 @@ typedef struct { SReqResultInfo resInfo; } SMqRspObj; +typedef struct { + int8_t resType; + char topic[TSDB_TOPIC_FNAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; + int32_t vgId; + SMqMetaRsp metaRsp; +} SMqMetaRspObj; + typedef struct SRequestObj { int8_t resType; // query or tmq uint64_t requestId; @@ -204,9 +216,9 @@ typedef struct SRequestObj { SRequestSendRecvBody body; bool stableQuery; - bool killed; - uint32_t prevCode; //previous error code: todo refactor, add update flag for catalog - uint32_t retry; + bool killed; + uint32_t prevCode; // previous error code: todo refactor, add update flag for catalog + uint32_t retry; } SRequestObj; typedef struct SSyncQueryParam { @@ -214,15 +226,15 @@ typedef struct SSyncQueryParam { SRequestObj* pRequest; } SSyncQueryParam; -void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); -void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); +void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); +void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); -void doSetOneRowPtr(SReqResultInfo* pResultInfo); -void setResPrecision(SReqResultInfo* pResInfo, int32_t precision); -int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4, - bool freeAfterUse); -void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols); -void doFreeReqResultInfo(SReqResultInfo* pResInfo); +void doSetOneRowPtr(SReqResultInfo* pResultInfo); +void setResPrecision(SReqResultInfo* pResInfo, int32_t precision); +int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4, + bool freeAfterUse); +void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols); +void doFreeReqResultInfo(SReqResultInfo* pResInfo); SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen); static FORCE_INLINE SReqResultInfo* tmqGetCurResInfo(TAOS_RES* res) { @@ -242,6 +254,7 @@ static FORCE_INLINE SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res, bool conver taosMemoryFreeClear(msg->resInfo.pCol); taosMemoryFreeClear(msg->resInfo.length); taosMemoryFreeClear(msg->resInfo.convertBuf); + taosMemoryFreeClear(msg->resInfo.convertJson); } setQueryResultFromRsp(&msg->resInfo, pRetrieve, convertUcs4, false); return &msg->resInfo; @@ -286,17 +299,17 @@ bool persistConnForSpecificMsg(void* parenct, tmsg_t msgType); void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet); STscObj* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, - uint16_t port, int connType); + uint16_t port, int connType); SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen); int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb); -int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray** pNodeList); +int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList); int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest); -void taos_close_internal(void *taos); +void taos_close_internal(void* taos); // --- heartbeat // global, called by mgmt @@ -317,12 +330,13 @@ void hbMgrInitMqHbRspHandle(); SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQuery, void** res); int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList); -void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery); +void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultMeta); int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest); int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList); void doAsyncQuery(SRequestObj* pRequest, bool forceUpdateMeta); -int32_t removeMeta(STscObj* pTscObj, SArray* tbList);// todo move to clientImpl.c and become a static function -int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog);// todo move to xxx +int32_t removeMeta(STscObj* pTscObj, SArray* tbList); // todo move to clientImpl.c and become a static function +int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog); // todo move to xxx +bool qnodeRequired(SRequestObj* pRequest); #ifdef __cplusplus } diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 78454268b7..9f04e89694 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -212,6 +212,7 @@ void doFreeReqResultInfo(SReqResultInfo *pResInfo) { taosMemoryFreeClear(pResInfo->pCol); taosMemoryFreeClear(pResInfo->fields); taosMemoryFreeClear(pResInfo->userFields); + taosMemoryFreeClear(pResInfo->convertJson); if (pResInfo->convertBuf != NULL) { for (int32_t i = 0; i < pResInfo->numOfCols; ++i) { diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 9668d2b72c..8920922006 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -307,6 +307,21 @@ int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList) { return TSDB_CODE_SUCCESS; } +bool qnodeRequired(SRequestObj* pRequest) { + if (QUERY_POLICY_VNODE == tsQueryPolicy) { + return false; + } + + SAppInstInfo* pInfo = pRequest->pTscObj->pAppInfo; + bool required = false; + + taosThreadMutexLock(&pInfo->qnodeMutex); + required = (NULL == pInfo->pQnodeList); + taosThreadMutexUnlock(&pInfo->qnodeMutex); + + return required; +} + int32_t getQnodeList(SRequestObj* pRequest, SArray** pNodeList) { SAppInstInfo* pInfo = pRequest->pTscObj->pAppInfo; int32_t code = 0; @@ -337,7 +352,7 @@ int32_t getQnodeList(SRequestObj* pRequest, SArray** pNodeList) { return code; } -int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray** pNodeList) { +int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) { pRequest->type = pQuery->msgType; SAppInstInfo* pAppInfo = getAppInfo(pRequest); @@ -349,12 +364,7 @@ int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArra .pMsg = pRequest->msgBuf, .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE}; - int32_t code = getQnodeList(pRequest, pNodeList); - if (TSDB_CODE_SUCCESS == code) { - code = qCreateQueryPlan(&cxt, pPlan, *pNodeList); - } - - return code; + return qCreateQueryPlan(&cxt, pPlan, pNodeList); } void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols) { @@ -397,6 +407,195 @@ void setResPrecision(SReqResultInfo* pResInfo, int32_t precision) { pResInfo->precision = precision; } +int32_t buildVnodePolicyNodeList(SRequestObj* pRequest, SArray** pNodeList, SArray* pMnodeList, SArray* pDbVgList) { + SArray* nodeList = taosArrayInit(4, sizeof(SQueryNodeLoad)); + + int32_t dbNum = taosArrayGetSize(pDbVgList); + for (int32_t i = 0; i < dbNum; ++i) { + SArray* pVg = taosArrayGetP(pDbVgList, i); + int32_t vgNum = taosArrayGetSize(pVg); + if (vgNum <= 0) { + continue; + } + + for (int32_t j = 0; j < vgNum; ++j) { + SVgroupInfo* pInfo = taosArrayGet(pVg, j); + SQueryNodeLoad load = {0}; + load.addr.nodeId = pInfo->vgId; + load.addr.epSet = pInfo->epSet; + + taosArrayPush(nodeList, &load); + } + } + + int32_t vnodeNum = taosArrayGetSize(nodeList); + if (vnodeNum > 0) { + tscDebug("0x%" PRIx64 " vnode policy, use vnode list, num:%d", pRequest->requestId, vnodeNum); + goto _return; + } + + int32_t mnodeNum = taosArrayGetSize(pMnodeList); + if (mnodeNum <= 0) { + tscDebug("0x%" PRIx64 " vnode policy, empty node list", pRequest->requestId); + goto _return; + } + + void* pData = taosArrayGet(pMnodeList, 0); + taosArrayAddBatch(nodeList, pData, mnodeNum); + + tscDebug("0x%" PRIx64 " vnode policy, use mnode list, num:%d", pRequest->requestId, mnodeNum); + +_return: + + *pNodeList = nodeList; + + return TSDB_CODE_SUCCESS; +} + +int32_t buildQnodePolicyNodeList(SRequestObj* pRequest, SArray** pNodeList, SArray* pMnodeList, SArray* pQnodeList) { + SArray* nodeList = taosArrayInit(4, sizeof(SQueryNodeLoad)); + + int32_t qNodeNum = taosArrayGetSize(pQnodeList); + if (qNodeNum > 0) { + void* pData = taosArrayGet(pQnodeList, 0); + taosArrayAddBatch(nodeList, pData, qNodeNum); + tscDebug("0x%" PRIx64 " qnode policy, use qnode list, num:%d", pRequest->requestId, qNodeNum); + goto _return; + } + + int32_t mnodeNum = taosArrayGetSize(pMnodeList); + if (mnodeNum <= 0) { + tscDebug("0x%" PRIx64 " qnode policy, empty node list", pRequest->requestId); + goto _return; + } + + void* pData = taosArrayGet(pMnodeList, 0); + taosArrayAddBatch(nodeList, pData, mnodeNum); + + tscDebug("0x%" PRIx64 " qnode policy, use mnode list, num:%d", pRequest->requestId, mnodeNum); + +_return: + + *pNodeList = nodeList; + + return TSDB_CODE_SUCCESS; +} + + +int32_t buildAsyncExecNodeList(SRequestObj* pRequest, SArray** pNodeList, SArray* pMnodeList, SMetaData *pResultMeta) { + SArray* pDbVgList = NULL; + SArray* pQnodeList = NULL; + int32_t code = 0; + + switch (tsQueryPolicy) { + case QUERY_POLICY_VNODE: { + if (pResultMeta) { + pDbVgList = taosArrayInit(4, POINTER_BYTES); + + int32_t dbNum = taosArrayGetSize(pResultMeta->pDbVgroup); + for (int32_t i = 0; i < dbNum; ++i) { + SMetaRes* pRes = taosArrayGet(pResultMeta->pDbVgroup, i); + if (pRes->code || NULL == pRes->pRes) { + continue; + } + + taosArrayPush(pDbVgList, &pRes->pRes); + } + } + + code = buildVnodePolicyNodeList(pRequest, pNodeList, pMnodeList, pDbVgList); + break; + } + case QUERY_POLICY_HYBRID: + case QUERY_POLICY_QNODE: { + if (pResultMeta && taosArrayGetSize(pResultMeta->pQnodeList) > 0) { + SMetaRes* pRes = taosArrayGet(pResultMeta->pQnodeList, 0); + if (pRes->code) { + pQnodeList = NULL; + } else { + pQnodeList = taosArrayDup((SArray*)pRes->pRes); + } + } else { + SAppInstInfo* pInst = pRequest->pTscObj->pAppInfo; + taosThreadMutexLock(&pInst->qnodeMutex); + if (pInst->pQnodeList) { + pQnodeList = taosArrayDup(pInst->pQnodeList); + } + taosThreadMutexUnlock(&pInst->qnodeMutex); + } + + code = buildQnodePolicyNodeList(pRequest, pNodeList, pMnodeList, pQnodeList); + break; + } + default: + tscError("unknown query policy: %d", tsQueryPolicy); + return TSDB_CODE_TSC_APP_ERROR; + } + + taosArrayDestroy(pDbVgList); + taosArrayDestroy(pQnodeList); + + return code; +} + +int32_t buildSyncExecNodeList(SRequestObj* pRequest, SArray** pNodeList, SArray* pMnodeList) { + SArray* pDbVgList = NULL; + SArray* pQnodeList = NULL; + int32_t code = 0; + + switch (tsQueryPolicy) { + case QUERY_POLICY_VNODE: { + int32_t dbNum = taosArrayGetSize(pRequest->dbList); + if (dbNum > 0) { + SCatalog* pCtg = NULL; + SAppInstInfo* pInst = pRequest->pTscObj->pAppInfo; + code = catalogGetHandle(pInst->clusterId, &pCtg); + if (code != TSDB_CODE_SUCCESS) { + goto _return; + } + + pDbVgList = taosArrayInit(dbNum, POINTER_BYTES); + SArray* pVgList = NULL; + for (int32_t i = 0; i < dbNum; ++i) { + char* dbFName = taosArrayGet(pRequest->dbList, i); + SRequestConnInfo conn = {.pTrans = pInst->pTransporter, + .requestId = pRequest->requestId, + .requestObjRefId = pRequest->self, + .mgmtEps = getEpSet_s(&pInst->mgmtEp)}; + + code = catalogGetDBVgInfo(pCtg, &conn, dbFName, &pVgList); + if (code) { + goto _return; + } + + taosArrayPush(pDbVgList, &pVgList); + } + } + + code = buildVnodePolicyNodeList(pRequest, pNodeList, pMnodeList, pDbVgList); + break; + } + case QUERY_POLICY_HYBRID: + case QUERY_POLICY_QNODE: { + getQnodeList(pRequest, &pQnodeList); + + code = buildQnodePolicyNodeList(pRequest, pNodeList, pMnodeList, pQnodeList); + break; + } + default: + tscError("unknown query policy: %d", tsQueryPolicy); + return TSDB_CODE_TSC_APP_ERROR; + } + +_return: + + taosArrayDestroy(pDbVgList); + taosArrayDestroy(pQnodeList); + + return code; +} + + int32_t scheduleAsyncQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) { tsem_init(&schdRspSem, 0, 0); @@ -658,12 +857,16 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue code = execDdlQuery(pRequest, pQuery); break; case QUERY_EXEC_MODE_SCHEDULE: { - SArray* pNodeList = NULL; - code = getPlan(pRequest, pQuery, &pRequest->body.pDag, &pNodeList); + SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad)); + code = getPlan(pRequest, pQuery, &pRequest->body.pDag, pMnodeList); if (TSDB_CODE_SUCCESS == code) { + SArray* pNodeList = NULL; + buildSyncExecNodeList(pRequest, &pNodeList, pMnodeList); + code = scheduleQuery(pRequest, pRequest->body.pDag, pNodeList); + taosArrayDestroy(pNodeList); } - taosArrayDestroy(pNodeList); + taosArrayDestroy(pMnodeList); break; } case QUERY_EXEC_MODE_EMPTY_RESULT: @@ -712,7 +915,7 @@ SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen) { return launchQueryImpl(pRequest, pQuery, false, NULL); } -void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) { +void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData *pResultMeta) { int32_t code = 0; switch (pQuery->execMode) { @@ -723,7 +926,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) { code = asyncExecDdlQuery(pRequest, pQuery); break; case QUERY_EXEC_MODE_SCHEDULE: { - SArray* pNodeList = taosArrayInit(4, sizeof(SQueryNodeLoad)); + SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad)); pRequest->type = pQuery->msgType; @@ -736,13 +939,16 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) { .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE}; SAppInstInfo* pAppInfo = getAppInfo(pRequest); - code = qCreateQueryPlan(&cxt, &pRequest->body.pDag, pNodeList); + code = qCreateQueryPlan(&cxt, &pRequest->body.pDag, pMnodeList); if (code) { tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code), pRequest->requestId); } if (TSDB_CODE_SUCCESS == code) { + SArray* pNodeList = NULL; + buildAsyncExecNodeList(pRequest, &pNodeList, pMnodeList, pResultMeta); + SRequestConnInfo conn = { .pTrans = pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self}; SSchedulerReq req = {.pConn = &conn, @@ -754,6 +960,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) { .cbParam = pRequest, .reqKilled = &pRequest->killed}; code = schedulerAsyncExecJob(&req, &pRequest->body.queryJob); + taosArrayDestroy(pNodeList); } else { tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code), pRequest->requestId); @@ -761,7 +968,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) { } // todo not to be released here - taosArrayDestroy(pNodeList); + taosArrayDestroy(pMnodeList); break; } case QUERY_EXEC_MODE_EMPTY_RESULT: @@ -1339,67 +1546,6 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int } } - pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i]; - pResultInfo->row[i] = pResultInfo->pCol[i].pData; - } else if (type == TSDB_DATA_TYPE_JSON && colLength[i] > 0) { - char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]); - if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - pResultInfo->convertBuf[i] = p; - int32_t len = 0; - SResultColumn* pCol = &pResultInfo->pCol[i]; - for (int32_t j = 0; j < numOfRows; ++j) { - if (pCol->offset[j] != -1) { - char* pStart = pCol->offset[j] + pCol->pData; - - int32_t jsonInnerType = *pStart; - char* jsonInnerData = pStart + CHAR_BYTES; - char dst[TSDB_MAX_JSON_TAG_LEN] = {0}; - if (jsonInnerType == TSDB_DATA_TYPE_NULL) { - sprintf(varDataVal(dst), "%s", TSDB_DATA_NULL_STR_L); - varDataSetLen(dst, strlen(varDataVal(dst))); - } else if (jsonInnerType == TD_TAG_JSON) { - char* jsonString = parseTagDatatoJson(pStart); - STR_TO_VARSTR(dst, jsonString); - taosMemoryFree(jsonString); - } else if (jsonInnerType == TSDB_DATA_TYPE_NCHAR) { // value -> "value" - *(char*)varDataVal(dst) = '\"'; - int32_t length = taosUcs4ToMbs((TdUcs4*)varDataVal(jsonInnerData), varDataLen(jsonInnerData), - varDataVal(dst) + CHAR_BYTES); - if (length <= 0) { - tscError("charset:%s to %s. convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset); - length = 0; - } - varDataSetLen(dst, length + CHAR_BYTES * 2); - *(char*)POINTER_SHIFT(varDataVal(dst), length + CHAR_BYTES) = '\"'; - } else if (jsonInnerType == TSDB_DATA_TYPE_DOUBLE) { - double jsonVd = *(double*)(jsonInnerData); - sprintf(varDataVal(dst), "%.9lf", jsonVd); - varDataSetLen(dst, strlen(varDataVal(dst))); - } else if (jsonInnerType == TSDB_DATA_TYPE_BOOL) { - sprintf(varDataVal(dst), "%s", (*((char*)jsonInnerData) == 1) ? "true" : "false"); - varDataSetLen(dst, strlen(varDataVal(dst))); - } else { - ASSERT(0); - } - - if (len + varDataTLen(dst) > colLength[i]) { - p = taosMemoryRealloc(pResultInfo->convertBuf[i], len + varDataTLen(dst)); - if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - pResultInfo->convertBuf[i] = p; - } - p = pResultInfo->convertBuf[i] + len; - memcpy(p, dst, varDataTLen(dst)); - pCol->offset[j] = len; - len += varDataTLen(dst); - } - } - pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i]; pResultInfo->row[i] = pResultInfo->pCol[i].pData; } @@ -1408,6 +1554,171 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int return TSDB_CODE_SUCCESS; } +static int32_t estimateJsonLen(SReqResultInfo* pResultInfo, int32_t numOfCols, int32_t numOfRows){ + char* p = (char*)pResultInfo->pData; + + int32_t len = sizeof(int32_t) + sizeof(uint64_t) + numOfCols * (sizeof(int16_t) + sizeof(int32_t)); + int32_t* colLength = (int32_t*)(p + len); + len += sizeof(int32_t) * numOfCols; + + char* pStart = p + len; + for (int32_t i = 0; i < numOfCols; ++i) { + int32_t colLen = htonl(colLength[i]); + + if (pResultInfo->fields[i].type == TSDB_DATA_TYPE_JSON) { + int32_t* offset = (int32_t*)pStart; + int32_t lenTmp = numOfRows * sizeof(int32_t); + len += lenTmp; + pStart += lenTmp; + + for (int32_t j = 0; j < numOfRows; ++j) { + if (offset[j] == -1) { + continue; + } + char* data = offset[j] + pStart; + + int32_t jsonInnerType = *data; + char* jsonInnerData = data + CHAR_BYTES; + if (jsonInnerType == TSDB_DATA_TYPE_NULL) { + len += (VARSTR_HEADER_SIZE + strlen(TSDB_DATA_NULL_STR_L)); + } else if (jsonInnerType & TD_TAG_JSON) { + len += (VARSTR_HEADER_SIZE + ((const STag*)(data))->len); + } else if (jsonInnerType == TSDB_DATA_TYPE_NCHAR) { // value -> "value" + len += varDataTLen(jsonInnerData) + CHAR_BYTES * 2; + } else if (jsonInnerType == TSDB_DATA_TYPE_DOUBLE) { + len += (VARSTR_HEADER_SIZE + 32); + } else if (jsonInnerType == TSDB_DATA_TYPE_BOOL) { + len += (VARSTR_HEADER_SIZE + 5); + } else { + ASSERT(0); + } + + } + } else if (IS_VAR_DATA_TYPE(pResultInfo->fields[i].type)) { + int32_t lenTmp = numOfRows * sizeof(int32_t); + len += (lenTmp + colLen); + pStart += lenTmp; + } else { + int32_t lenTmp = BitmapLen(pResultInfo->numOfRows); + len += (lenTmp + colLen); + pStart += lenTmp; + } + pStart += colLen; + } + return len; +} + +static int32_t doConvertJson(SReqResultInfo* pResultInfo, int32_t numOfCols, int32_t numOfRows) { + bool needConvert = false; + for (int32_t i = 0; i < numOfCols; ++i) { + if (pResultInfo->fields[i].type == TSDB_DATA_TYPE_JSON) { + needConvert = true; + break; + } + } + if(!needConvert) return TSDB_CODE_SUCCESS; + + char* p = (char*)pResultInfo->pData; + int32_t dataLen = estimateJsonLen(pResultInfo, numOfCols, numOfRows); + + pResultInfo->convertJson = taosMemoryCalloc(1, dataLen); + if(pResultInfo->convertJson == NULL) return TSDB_CODE_OUT_OF_MEMORY; + char* p1 = pResultInfo->convertJson; + + int32_t len = sizeof(int32_t) + sizeof(uint64_t) + numOfCols * (sizeof(int16_t) + sizeof(int32_t)); + memcpy(p1, p, len); + + p += len; + p1 += len; + + len = sizeof(int32_t) * numOfCols; + int32_t* colLength = (int32_t*)p; + int32_t* colLength1 = (int32_t*)p1; + memcpy(p1, p, len); + p += len; + p1 += len; + + char* pStart = p; + char* pStart1 = p1; + for (int32_t i = 0; i < numOfCols; ++i) { + int32_t colLen = htonl(colLength[i]); + int32_t colLen1 = htonl(colLength1[i]); + ASSERT(colLen < dataLen); + + if (pResultInfo->fields[i].type == TSDB_DATA_TYPE_JSON) { + int32_t* offset = (int32_t*)pStart; + int32_t* offset1 = (int32_t*)pStart1; + len = numOfRows * sizeof(int32_t); + memcpy(pStart1, pStart, len); + pStart += len; + pStart1 += len; + + len = 0; + for (int32_t j = 0; j < numOfRows; ++j) { + if (offset[j] == -1) { + continue; + } + char* data = offset[j] + pStart; + + int32_t jsonInnerType = *data; + char* jsonInnerData = data + CHAR_BYTES; + char dst[TSDB_MAX_JSON_TAG_LEN] = {0}; + if (jsonInnerType == TSDB_DATA_TYPE_NULL) { + sprintf(varDataVal(dst), "%s", TSDB_DATA_NULL_STR_L); + varDataSetLen(dst, strlen(varDataVal(dst))); + } else if (jsonInnerType & TD_TAG_JSON) { + char* jsonString = parseTagDatatoJson(data); + STR_TO_VARSTR(dst, jsonString); + taosMemoryFree(jsonString); + } else if (jsonInnerType == TSDB_DATA_TYPE_NCHAR) { // value -> "value" + *(char*)varDataVal(dst) = '\"'; + int32_t length = taosUcs4ToMbs((TdUcs4*)varDataVal(jsonInnerData), varDataLen(jsonInnerData), + varDataVal(dst) + CHAR_BYTES); + if (length <= 0) { + tscError("charset:%s to %s. convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset); + length = 0; + } + varDataSetLen(dst, length + CHAR_BYTES * 2); + *(char*)POINTER_SHIFT(varDataVal(dst), length + CHAR_BYTES) = '\"'; + } else if (jsonInnerType == TSDB_DATA_TYPE_DOUBLE) { + double jsonVd = *(double*)(jsonInnerData); + sprintf(varDataVal(dst), "%.9lf", jsonVd); + varDataSetLen(dst, strlen(varDataVal(dst))); + } else if (jsonInnerType == TSDB_DATA_TYPE_BOOL) { + sprintf(varDataVal(dst), "%s", (*((char*)jsonInnerData) == 1) ? "true" : "false"); + varDataSetLen(dst, strlen(varDataVal(dst))); + } else { + ASSERT(0); + } + + offset1[j]= len; + memcpy(pStart1 + len, dst, varDataTLen(dst)); + len += varDataTLen(dst); + } + colLen1 = len; + colLength1[i] = htonl(len); + } else if (IS_VAR_DATA_TYPE(pResultInfo->fields[i].type)) { + len = numOfRows * sizeof(int32_t); + memcpy(pStart1, pStart, len); + pStart += len; + pStart1 += len; + memcpy(pStart1, pStart, colLen); + } else { + len = BitmapLen(pResultInfo->numOfRows); + memcpy(pStart1, pStart, len); + pStart += len; + pStart1 += len; + memcpy(pStart1, pStart, colLen); + + } + pStart += colLen; + pStart1 += colLen1; + } + + pResultInfo->pData = pResultInfo->convertJson; + return TSDB_CODE_SUCCESS; +} + int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows, bool convertUcs4) { assert(numOfCols > 0 && pFields != NULL && pResultInfo != NULL); @@ -1419,6 +1730,10 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 if (code != TSDB_CODE_SUCCESS) { return code; } + code = doConvertJson(pResultInfo, numOfCols, numOfRows); + if (code != TSDB_CODE_SUCCESS) { + return code; + } char* p = (char*)pResultInfo->pData; @@ -1462,8 +1777,7 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 pStart += colLength[i]; } - // convert UCS4-LE encoded character to native multi-bytes character in current data block. - if (convertUcs4) { + if(convertUcs4){ code = doConvertUCS4(pResultInfo, numOfRows, numOfCols, colLength); } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 51e05537d4..ab4d14b1cc 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -17,6 +17,7 @@ #include "clientInt.h" #include "clientLog.h" #include "clientStmt.h" +#include "functionMgt.h" #include "os.h" #include "query.h" #include "scheduler.h" @@ -25,7 +26,6 @@ #include "tref.h" #include "trpc.h" #include "version.h" -#include "functionMgt.h" #define TSC_VAR_NOT_RELEASE 1 #define TSC_VAR_RELEASED 0 @@ -97,11 +97,11 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha pass = TSDB_DEFAULT_PASS; } - STscObj* pObj = taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY); + STscObj *pObj = taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY); if (pObj) { return pObj->id; } - + return NULL; } @@ -111,41 +111,40 @@ void taos_close_internal(void *taos) { } STscObj *pTscObj = (STscObj *)taos; - tscDebug("0x%" PRIx64 " try to close connection, numOfReq:%d", *(int64_t*)pTscObj->id, pTscObj->numOfReqs); + tscDebug("0x%" PRIx64 " try to close connection, numOfReq:%d", *(int64_t *)pTscObj->id, pTscObj->numOfReqs); - taosRemoveRef(clientConnRefPool, *(int64_t*)pTscObj->id); + taosRemoveRef(clientConnRefPool, *(int64_t *)pTscObj->id); } void taos_close(TAOS *taos) { if (taos == NULL) { return; } - - STscObj* pObj = acquireTscObj(*(int64_t*)taos); + + STscObj *pObj = acquireTscObj(*(int64_t *)taos); if (NULL == pObj) { return; } - + taos_close_internal(pObj); - releaseTscObj(*(int64_t*)taos); + releaseTscObj(*(int64_t *)taos); taosMemoryFree(taos); } - -int taos_errno(TAOS_RES *tres) { - if (tres == NULL) { +int taos_errno(TAOS_RES *res) { + if (res == NULL || TD_RES_TMQ_META(res)) { return terrno; } - if (TD_RES_TMQ(tres)) { + if (TD_RES_TMQ(res)) { return 0; } - return ((SRequestObj *)tres)->code; + return ((SRequestObj *)res)->code; } const char *taos_errstr(TAOS_RES *res) { - if (res == NULL) { + if (res == NULL || TD_RES_TMQ_META(res)) { return (const char *)tstrerror(terrno); } @@ -179,11 +178,15 @@ void taos_free_result(TAOS_RES *res) { if (pRsp->rsp.withSchema) taosArrayDestroyP(pRsp->rsp.blockSchema, (FDelete)tDeleteSSchemaWrapper); pRsp->resInfo.pRspMsg = NULL; doFreeReqResultInfo(&pRsp->resInfo); + } else if (TD_RES_TMQ_META(res)) { + SMqMetaRspObj *pRspObj = (SMqMetaRspObj *)res; + taosMemoryFree(pRspObj->metaRsp.metaRsp); + taosMemoryFree(pRspObj); } } int taos_field_count(TAOS_RES *res) { - if (res == NULL) { + if (res == NULL || TD_RES_TMQ_META(res)) { return 0; } @@ -194,7 +197,7 @@ int taos_field_count(TAOS_RES *res) { int taos_num_fields(TAOS_RES *res) { return taos_field_count(res); } TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { - if (taos_num_fields(res) == 0) { + if (taos_num_fields(res) == 0 || TD_RES_TMQ_META(res)) { return NULL; } @@ -215,8 +218,8 @@ TAOS_RES *taos_query(TAOS *taos, const char *sql) { terrno = TSDB_CODE_TSC_DISCONNECTED; return NULL; } - - STscObj* pTscObj = acquireTscObj(*(int64_t*)taos); + + STscObj *pTscObj = acquireTscObj(*(int64_t *)taos); if (pTscObj == NULL || sql == NULL) { terrno = TSDB_CODE_TSC_DISCONNECTED; return NULL; @@ -229,21 +232,21 @@ TAOS_RES *taos_query(TAOS *taos, const char *sql) { taos_query_a(taos, sql, syncQueryFn, param); tsem_wait(¶m->sem); - releaseTscObj(*(int64_t*)taos); + releaseTscObj(*(int64_t *)taos); return param->pRequest; #else size_t sqlLen = strlen(sql); if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) { - releaseTscObj(*(int64_t*)taos); + releaseTscObj(*(int64_t *)taos); tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN); terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; return NULL; } - TAOS_RES* pRes = execQuery(pTscObj, sql, sqlLen); + TAOS_RES *pRes = execQuery(pTscObj, sql, sqlLen); - releaseTscObj(*(int64_t*)taos); + releaseTscObj(*(int64_t *)taos); return pRes; #endif @@ -380,7 +383,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) } int *taos_fetch_lengths(TAOS_RES *res) { - if (res == NULL) { + if (res == NULL || TD_RES_TMQ_META(res)) { return NULL; } @@ -389,7 +392,7 @@ int *taos_fetch_lengths(TAOS_RES *res) { } TAOS_ROW *taos_result_block(TAOS_RES *res) { - if (res == NULL) { + if (res == NULL || TD_RES_TMQ_META(res)) { terrno = TSDB_CODE_INVALID_PARA; return NULL; } @@ -438,7 +441,7 @@ const char *taos_data_type(int type) { const char *taos_get_client_info() { return version; } int taos_affected_rows(TAOS_RES *res) { - if (res == NULL || TD_RES_TMQ(res)) { + if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res)) { return 0; } @@ -448,7 +451,7 @@ int taos_affected_rows(TAOS_RES *res) { } int taos_result_precision(TAOS_RES *res) { - if (res == NULL) { + if (res == NULL || TD_RES_TMQ_META(res)) { return TSDB_TIME_PRECISION_MILLI; } @@ -463,15 +466,15 @@ int taos_result_precision(TAOS_RES *res) { } int taos_select_db(TAOS *taos, const char *db) { - STscObj* pObj = acquireTscObj(*(int64_t*)taos); + STscObj *pObj = acquireTscObj(*(int64_t *)taos); if (pObj == NULL) { - releaseTscObj(*(int64_t*)taos); + releaseTscObj(*(int64_t *)taos); terrno = TSDB_CODE_TSC_DISCONNECTED; return TSDB_CODE_TSC_DISCONNECTED; } if (db == NULL || strlen(db) == 0) { - releaseTscObj(*(int64_t*)taos); + releaseTscObj(*(int64_t *)taos); terrno = TSDB_CODE_TSC_INVALID_INPUT; return terrno; } @@ -483,19 +486,19 @@ int taos_select_db(TAOS *taos, const char *db) { int32_t code = taos_errno(pRequest); taos_free_result(pRequest); - releaseTscObj(*(int64_t*)taos); + releaseTscObj(*(int64_t *)taos); return code; } void taos_stop_query(TAOS_RES *res) { - if (res == NULL) { + if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res)) { return; } SRequestObj *pRequest = (SRequestObj *)res; pRequest->killed = true; - - int32_t numOfFields = taos_num_fields(pRequest); + + int32_t numOfFields = taos_num_fields(pRequest); // It is not a query, no need to stop. if (numOfFields == 0) { tscDebug("request %" PRIx64 " no need to be killed since not query", pRequest->requestId); @@ -510,6 +513,9 @@ void taos_stop_query(TAOS_RES *res) { } bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) { + if (res == NULL || TD_RES_TMQ_META(res)) { + return true; + } SReqResultInfo *pResultInfo = tscGetCurResInfo(res); if (col >= pResultInfo->numOfCols || col < 0 || row >= pResultInfo->numOfRows || row < 0) { return true; @@ -532,7 +538,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { } int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) { - if (res == NULL) { + if (res == NULL || TD_RES_TMQ_META(res)) { return 0; } @@ -575,7 +581,7 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) { } int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) { - if (res == NULL) { + if (res == NULL || TD_RES_TMQ_META(res)) { return 0; } @@ -615,7 +621,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) { } int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) { - if (res == NULL) { + if (res == NULL || TD_RES_TMQ_META(res)) { return 0; } @@ -636,7 +642,7 @@ int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) { int taos_validate_sql(TAOS *taos, const char *sql) { return true; } void taos_reset_current_db(TAOS *taos) { - STscObj* pTscObj = acquireTscObj(*(int64_t*)taos); + STscObj *pTscObj = acquireTscObj(*(int64_t *)taos); if (pTscObj == NULL) { terrno = TSDB_CODE_TSC_DISCONNECTED; return; @@ -644,17 +650,17 @@ void taos_reset_current_db(TAOS *taos) { resetConnectDB(pTscObj); - releaseTscObj(*(int64_t*)taos); + releaseTscObj(*(int64_t *)taos); } const char *taos_get_server_info(TAOS *taos) { - STscObj* pTscObj = acquireTscObj(*(int64_t*)taos); + STscObj *pTscObj = acquireTscObj(*(int64_t *)taos); if (pTscObj == NULL) { terrno = TSDB_CODE_TSC_DISCONNECTED; return NULL; } - releaseTscObj(*(int64_t*)taos); + releaseTscObj(*(int64_t *)taos); return pTscObj->ver; } @@ -682,7 +688,7 @@ static void destorySqlParseWrapper(SqlParseWrapper *pWrapper) { void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { tscDebug("enter meta callback, code %s", tstrerror(code)); - + SqlParseWrapper *pWrapper = (SqlParseWrapper *)param; SQuery *pQuery = pWrapper->pQuery; SRequestObj *pRequest = pWrapper->pRequest; @@ -702,7 +708,7 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { TSWAP(pRequest->tableList, (pQuery)->pTableList); destorySqlParseWrapper(pWrapper); - launchAsyncQuery(pRequest, pQuery); + launchAsyncQuery(pRequest, pQuery, pResultMeta); } else { destorySqlParseWrapper(pWrapper); tscDebug("error happens, code:%d", code); @@ -723,11 +729,11 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { } void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) { - STscObj* pTscObj = acquireTscObj(*(int64_t*)taos); + STscObj *pTscObj = acquireTscObj(*(int64_t *)taos); if (pTscObj == NULL || sql == NULL || NULL == fp) { terrno = TSDB_CODE_INVALID_PARA; if (pTscObj) { - releaseTscObj(*(int64_t*)taos); + releaseTscObj(*(int64_t *)taos); } else { terrno = TSDB_CODE_TSC_DISCONNECTED; } @@ -745,7 +751,7 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param } SRequestObj *pRequest = NULL; - int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest); + int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest); if (code != TSDB_CODE_SUCCESS) { terrno = code; fp(param, NULL, terrno); @@ -808,7 +814,7 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) { SQuery *pQuery = NULL; - SCatalogReq catalogReq = {.forceUpdate = updateMetaForce}; + SCatalogReq catalogReq = {.forceUpdate = updateMetaForce, .qNodeRequired = qnodeRequired(pRequest)}; code = qParseSqlSyntax(pCxt, &pQuery, &catalogReq); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -849,8 +855,8 @@ static void fetchCallback(void *pResult, void *param, int32_t code) { SReqResultInfo *pResultInfo = &pRequest->body.resInfo; - tscDebug("0x%" PRIx64 " enter scheduler fetch cb, code:%d - %s, reqId:0x%" PRIx64, - pRequest->self, code, tstrerror(code), pRequest->requestId); + tscDebug("0x%" PRIx64 " enter scheduler fetch cb, code:%d - %s, reqId:0x%" PRIx64, pRequest->self, code, + tstrerror(code), pRequest->requestId); pResultInfo->pData = pResult; pResultInfo->numOfRows = 0; @@ -884,9 +890,11 @@ static void fetchCallback(void *pResult, void *param, int32_t code) { void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { ASSERT(res != NULL && fp != NULL); + ASSERT(TD_RES_QUERY(res)); SRequestObj *pRequest = res; pRequest->body.fetchFp = fp; + pRequest->body.param = param; SReqResultInfo *pResultInfo = &pRequest->body.resInfo; if (taos_num_fields(pRequest) == 0) { @@ -909,6 +917,7 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { ASSERT(res != NULL && fp != NULL); + ASSERT(TD_RES_QUERY(res)); SRequestObj *pRequest = res; pRequest->body.resInfo.convertUcs4 = false; @@ -922,6 +931,7 @@ void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { const void *taos_get_raw_block(TAOS_RES *res) { ASSERT(res != NULL); + ASSERT(TD_RES_QUERY(res)); SRequestObj *pRequest = res; return pRequest->body.resInfo.pData; @@ -948,16 +958,16 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { } TAOS_STMT *taos_stmt_init(TAOS *taos) { - STscObj* pObj = acquireTscObj(*(int64_t*)taos); + STscObj *pObj = acquireTscObj(*(int64_t *)taos); if (NULL == pObj) { tscError("invalid parameter for %s", __FUNCTION__); terrno = TSDB_CODE_TSC_DISCONNECTED; return NULL; } - TAOS_STMT* pStmt = stmtInit(pObj); - - releaseTscObj(*(int64_t*)taos); + TAOS_STMT *pStmt = stmtInit(pObj); + + releaseTscObj(*(int64_t *)taos); return pStmt; } diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 580aafa010..6fa4e6bffb 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -2274,7 +2274,7 @@ static int32_t smlInsertData(SSmlHandle *info) { // info->affectedRows = taos_affected_rows(info->pRequest); // return info->pRequest->code; - launchAsyncQuery(info->pRequest, info->pQuery); + launchAsyncQuery(info->pRequest, info->pQuery, NULL); return TSDB_CODE_SUCCESS; } diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 638b4f1ea5..3c349f61a1 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -149,7 +149,10 @@ typedef struct { int32_t epoch; SMqClientVg* vgHandle; SMqClientTopic* topicHandle; - SMqDataBlkRsp msg; + union { + SMqDataBlkRsp dataRsp; + SMqMetaRsp metaRsp; + }; } SMqPollRspWrapper; typedef struct { @@ -401,8 +404,17 @@ int32_t tmqCommitInner2(tmq_t* tmq, const TAOS_RES* msg, int8_t automatic, int8_ int32_t code = -1; if (msg != NULL) { - SMqRspObj* pRspObj = (SMqRspObj*)msg; - if (!TD_RES_TMQ(pRspObj)) { + char* topic; + int32_t vgId; + if (TD_RES_TMQ(msg)) { + SMqRspObj* pRspObj = (SMqRspObj*)msg; + topic = pRspObj->topic; + vgId = pRspObj->vgId; + } else if (TD_RES_TMQ_META(msg)) { + SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)msg; + topic = pMetaRspObj->topic; + vgId = pMetaRspObj->vgId; + } else { return TSDB_CODE_TMQ_INVALID_MSG; } @@ -421,10 +433,10 @@ int32_t tmqCommitInner2(tmq_t* tmq, const TAOS_RES* msg, int8_t automatic, int8_ for (int32_t i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) { SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i); - if (strcmp(pTopic->topicName, pRspObj->topic) == 0) { + if (strcmp(pTopic->topicName, topic) == 0) { for (int32_t j = 0; j < taosArrayGetSize(pTopic->vgs); j++) { SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j); - if (pVg->vgId == pRspObj->vgId) { + if (pVg->vgId == vgId) { if (pVg->currentOffset < 0 || pVg->committedOffset == pVg->currentOffset) { tscDebug("consumer %ld skip commit for topic %s vg %d, current offset is %ld, committed offset is %ld", tmq->consumerId, pTopic->topicName, pVg->vgId, pVg->currentOffset, pVg->committedOffset); @@ -1131,6 +1143,11 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { tscWarn("mismatch rsp from vg %d, epoch %d, current epoch %d", vgId, msgEpoch, tmqEpoch); } + // handle meta rsp + int8_t rspType = ((SMqRspHead*)pMsg->pData)->mqMsgType; + if (rspType == TMQ_MSG_TYPE__POLL_META_RSP) { + } + SMqPollRspWrapper* pRspWrapper = taosAllocateQitem(sizeof(SMqPollRspWrapper), DEF_QITEM); if (pRspWrapper == NULL) { taosMemoryFree(pMsg->pData); @@ -1138,17 +1155,23 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { goto CREATE_MSG_FAIL; } - pRspWrapper->tmqRspType = TMQ_MSG_TYPE__POLL_RSP; + pRspWrapper->tmqRspType = rspType; pRspWrapper->vgHandle = pVg; pRspWrapper->topicHandle = pTopic; - memcpy(&pRspWrapper->msg, pMsg->pData, sizeof(SMqRspHead)); + memcpy(&pRspWrapper->dataRsp, pMsg->pData, sizeof(SMqRspHead)); + + if (rspType == TMQ_MSG_TYPE__POLL_RSP) { + tDecodeSMqDataBlkRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->dataRsp); + } else { + ASSERT(rspType == TMQ_MSG_TYPE__POLL_META_RSP); + tDecodeSMqMetaRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->metaRsp); + } - tDecodeSMqDataBlkRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->msg); taosMemoryFree(pMsg->pData); tscDebug("consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld", tmq->consumerId, pVg->vgId, - pRspWrapper->msg.reqOffset, pRspWrapper->msg.rspOffset); + pRspWrapper->dataRsp.reqOffset, pRspWrapper->dataRsp.rspOffset); taosWriteQitem(tmq->mqueue, pRspWrapper); tsem_post(&tmq->rspSem); @@ -1516,6 +1539,17 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t timeout, SMqClientTopic* return pReq; } +SMqMetaRspObj* tmqBuildMetaRspFromWrapper(SMqPollRspWrapper* pWrapper) { + SMqMetaRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqMetaRspObj)); + pRspObj->resType = RES_TYPE__TMQ; + tstrncpy(pRspObj->topic, pWrapper->topicHandle->topicName, TSDB_TOPIC_FNAME_LEN); + tstrncpy(pRspObj->db, pWrapper->topicHandle->db, TSDB_DB_FNAME_LEN); + pRspObj->vgId = pWrapper->vgHandle->vgId; + + memcpy(&pRspObj->metaRsp, &pWrapper->metaRsp, sizeof(SMqMetaRsp)); + return pRspObj; +} + SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper) { SMqRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqRspObj)); pRspObj->resType = RES_TYPE__TMQ; @@ -1523,11 +1557,11 @@ SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper) { tstrncpy(pRspObj->db, pWrapper->topicHandle->db, TSDB_DB_FNAME_LEN); pRspObj->vgId = pWrapper->vgHandle->vgId; pRspObj->resIter = -1; - memcpy(&pRspObj->rsp, &pWrapper->msg, sizeof(SMqDataBlkRsp)); + memcpy(&pRspObj->rsp, &pWrapper->dataRsp, sizeof(SMqDataBlkRsp)); pRspObj->resInfo.totalRows = 0; pRspObj->resInfo.precision = TSDB_TIME_PRECISION_MILLI; - if (!pWrapper->msg.withSchema) { + if (!pWrapper->dataRsp.withSchema) { setResSchemaInfo(&pRspObj->resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols); } @@ -1643,12 +1677,12 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { SMqPollRspWrapper* pollRspWrapper = (SMqPollRspWrapper*)rspWrapper; /*atomic_sub_fetch_32(&tmq->readyRequest, 1);*/ int32_t consumerEpoch = atomic_load_32(&tmq->epoch); - if (pollRspWrapper->msg.head.epoch == consumerEpoch) { + if (pollRspWrapper->dataRsp.head.epoch == consumerEpoch) { SMqClientVg* pVg = pollRspWrapper->vgHandle; /*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/ - pVg->currentOffset = pollRspWrapper->msg.rspOffset; + pVg->currentOffset = pollRspWrapper->dataRsp.rspOffset; atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); - if (pollRspWrapper->msg.blockNum == 0) { + if (pollRspWrapper->dataRsp.blockNum == 0) { taosFreeQitem(pollRspWrapper); rspWrapper = NULL; continue; @@ -1658,8 +1692,25 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { taosFreeQitem(pollRspWrapper); return pRsp; } else { - tscDebug("msg discard since epoch mismatch: msg epoch %d, consumer epoch %d\n", pollRspWrapper->msg.head.epoch, - consumerEpoch); + tscDebug("msg discard since epoch mismatch: msg epoch %d, consumer epoch %d\n", + pollRspWrapper->dataRsp.head.epoch, consumerEpoch); + taosFreeQitem(pollRspWrapper); + } + } else if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__POLL_META_RSP) { + SMqPollRspWrapper* pollRspWrapper = (SMqPollRspWrapper*)rspWrapper; + int32_t consumerEpoch = atomic_load_32(&tmq->epoch); + if (pollRspWrapper->dataRsp.head.epoch == consumerEpoch) { + SMqClientVg* pVg = pollRspWrapper->vgHandle; + /*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/ + pVg->currentOffset = pollRspWrapper->dataRsp.rspOffset; + atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); + // build rsp + SMqRspObj* pRsp = tmqBuildRspFromWrapper(pollRspWrapper); + taosFreeQitem(pollRspWrapper); + return pRsp; + } else { + tscDebug("msg discard since epoch mismatch: msg epoch %d, consumer epoch %d\n", + pollRspWrapper->dataRsp.head.epoch, consumerEpoch); taosFreeQitem(pollRspWrapper); } } else { @@ -1747,10 +1798,23 @@ const char* tmq_err2str(int32_t err) { } } +tmq_res_t tmq_get_res_type(TAOS_RES* res) { + if (TD_RES_TMQ(res)) { + return TMQ_RES_DATA; + } else if (TD_RES_TMQ_META(res)) { + return TMQ_RES_TABLE_META; + } else { + return TMQ_RES_INVALID; + } +} + const char* tmq_get_topic_name(TAOS_RES* res) { if (TD_RES_TMQ(res)) { SMqRspObj* pRspObj = (SMqRspObj*)res; return strchr(pRspObj->topic, '.') + 1; + } else if (TD_RES_TMQ_META(res)) { + SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res; + return strchr(pMetaRspObj->topic, '.') + 1; } else { return NULL; } @@ -1760,6 +1824,9 @@ const char* tmq_get_db_name(TAOS_RES* res) { if (TD_RES_TMQ(res)) { SMqRspObj* pRspObj = (SMqRspObj*)res; return strchr(pRspObj->db, '.') + 1; + } else if (TD_RES_TMQ_META(res)) { + SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res; + return strchr(pMetaRspObj->db, '.') + 1; } else { return NULL; } @@ -1769,6 +1836,9 @@ int32_t tmq_get_vgroup_id(TAOS_RES* res) { if (TD_RES_TMQ(res)) { SMqRspObj* pRspObj = (SMqRspObj*)res; return pRspObj->vgId; + } else if (TD_RES_TMQ_META(res)) { + SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res; + return pMetaRspObj->vgId; } else { return -1; } @@ -1786,6 +1856,16 @@ const char* tmq_get_table_name(TAOS_RES* res) { return NULL; } +int32_t tmq_get_raw_meta(TAOS_RES* res, const void** raw_meta, int32_t* raw_meta_len) { + if (TD_RES_TMQ_META(res)) { + SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res; + *raw_meta = pMetaRspObj->metaRsp.metaRsp; + *raw_meta_len = pMetaRspObj->metaRsp.metaRspLen; + return 0; + } + return -1; +} + void tmq_commit_async(tmq_t* tmq, const TAOS_RES* msg, tmq_commit_cb* cb, void* param) { tmqCommitInner2(tmq, msg, 0, 1, cb, param); } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index b6ec75f8eb..36dcab5c19 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -43,6 +43,26 @@ void showDB(TAOS* pConn) { } } +void printResult(TAOS_RES* pRes) { + TAOS_ROW pRow = NULL; + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + int32_t n = 0; + char str[512] = {0}; + while ((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t* length = taos_fetch_lengths(pRes); + for(int32_t i = 0; i < numOfFields; ++i) { + printf("(%d):%d " , i, length[i]); + } + printf("\n"); + + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + memset(str, 0, sizeof(str)); + } +} + void fetchCallback(void* param, void* res, int32_t numOfRow) { #if 0 printf("numOfRow = %d \n", numOfRow); @@ -729,48 +749,31 @@ TEST(testCase, projection_query_tables) { // taos_close(pConn); //} -//TEST(testCase, agg_query_tables) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// ASSERT_NE(pConn, nullptr); -// -// TAOS_RES* pRes = taos_query(pConn, "use abc1"); -// if (taos_errno(pRes) != 0) { -// printf("failed to use db, reason:%s\n", taos_errstr(pRes)); -// taos_free_result(pRes); -// ASSERT_TRUE(false); -// } -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "show stables"); -// if (taos_errno(pRes) != 0) { -// printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); -// taos_free_result(pRes); -// ASSERT_TRUE(false); -// } -// -// TAOS_ROW pRow = NULL; -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// int32_t numOfFields = taos_num_fields(pRes); -// -// int32_t n = 0; -// char str[512] = {0}; -// while ((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t* length = taos_fetch_lengths(pRes); -// for(int32_t i = 0; i < numOfFields; ++i) { -// printf("(%d):%d " , i, length[i]); -// } -// printf("\n"); -// -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); -// memset(str, 0, sizeof(str)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -#endif +TEST(testCase, agg_query_tables) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT_NE(pConn, nullptr); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("failed to use db, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "show table distributed st1"); + if (taos_errno(pRes) != 0) { + printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + + printResult(pRes); + taos_free_result(pRes); + taos_close(pConn); +} +#endif /* --- copy the following script in the shell to setup the environment --- @@ -786,7 +789,7 @@ TEST(testCase, async_api_test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); - taos_query(pConn, "use table_alltype_hyperloglog"); + taos_query(pConn, "use abc1"); #if 0 TAOS_RES* pRes = taos_query(pConn, "insert into tu(ts) values('2022-02-27 12:12:61')"); if (taos_errno(pRes) != 0) { @@ -812,7 +815,7 @@ TEST(testCase, async_api_test) { } #endif - taos_query_a(pConn, "select HYPERLOGLOG(q_ts) from stable_1_2 where ts between 1630000001000 and 1630100001000 interval(19d) Fill(NONE);", queryCallback, pConn); + taos_query_a(pConn, "select count(*) from tu", queryCallback, pConn); getchar(); taos_close(pConn); } diff --git a/source/common/src/systable.c b/source/common/src/systable.c index a1b64b363c..e7b6342150 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -124,7 +124,7 @@ static const SSysDbTableSchema userStbsSchema[] = { {.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "tags", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "table_comment", .bytes = 1024 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "table_comment", .bytes = TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; static const SSysDbTableSchema streamSchema[] = { @@ -148,7 +148,7 @@ static const SSysDbTableSchema userTblsSchema[] = { {.name = "uid", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "table_comment", .bytes = 512 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "table_comment", .bytes = TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "type", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 7457fe7eb6..269c92a670 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -161,7 +161,7 @@ int32_t tsDiskCfgNum = 0; SDiskCfg tsDiskCfg[TFS_MAX_DISKS] = {0}; // stream scheduler -bool tsStreamSchedV = true; +bool tsSchedStreamToSnode = true; /* * minimum scale for whole system, millisecond by default @@ -185,7 +185,7 @@ char tsCompressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPR bool tsStartUdfd = true; // internal -int32_t tsTransPullupInterval = 6; +int32_t tsTransPullupInterval = 2; int32_t tsMqRebalanceInterval = 2; void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary) { diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 2443ffbb7f..7e9ce34f9f 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -524,7 +524,7 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq } if (pReq->commentLen > 0) { - if (tEncodeBinary(&encoder, pReq->comment, pReq->commentLen) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->comment) < 0) return -1; } if (pReq->ast1Len > 0) { if (tEncodeBinary(&encoder, pReq->pAst1, pReq->ast1Len) < 0) return -1; @@ -589,7 +589,7 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR } if (pReq->commentLen > 0) { - pReq->comment = taosMemoryMalloc(pReq->commentLen); + pReq->comment = taosMemoryMalloc(pReq->commentLen + 1); if (pReq->comment == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1; } @@ -707,7 +707,7 @@ int32_t tDeserializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1; if (tDecodeI32(&decoder, &pReq->commentLen) < 0) return -1; if (pReq->commentLen > 0) { - pReq->comment = taosMemoryMalloc(pReq->commentLen); + pReq->comment = taosMemoryMalloc(pReq->commentLen + 1); if (pReq->comment == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1; } @@ -2956,6 +2956,7 @@ int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTo if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; if (tEncodeI8(&encoder, pReq->subType) < 0) return -1; + if (tEncodeI8(&encoder, pReq->withMeta) < 0) return -1; if (tEncodeCStr(&encoder, pReq->subDbName) < 0) return -1; if (TOPIC_SUB_TYPE__DB == pReq->subType) { } else if (TOPIC_SUB_TYPE__TABLE == pReq->subType) { @@ -2985,6 +2986,7 @@ int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicR if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; if (tDecodeI8(&decoder, &pReq->subType) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->withMeta) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->subDbName) < 0) return -1; if (TOPIC_SUB_TYPE__DB == pReq->subType) { } else if (TOPIC_SUB_TYPE__TABLE == pReq->subType) { @@ -4267,45 +4269,69 @@ int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStrea return 0; } +int32_t tSerializeSMDropStreamReq(void *buf, int32_t bufLen, const SMDropStreamReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; + if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1; + + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMDropStreamReq(void *buf, int32_t bufLen, SMDropStreamReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1; + + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) { taosMemoryFreeClear(pReq->sql); taosMemoryFreeClear(pReq->ast); } int32_t tEncodeSRSmaParam(SEncoder *pCoder, const SRSmaParam *pRSmaParam) { - if (tEncodeFloat(pCoder, pRSmaParam->xFilesFactor) < 0) return -1; - if (tEncodeI32v(pCoder, pRSmaParam->delay) < 0) return -1; - if (tEncodeI32v(pCoder, pRSmaParam->qmsg1Len) < 0) return -1; - if (tEncodeI32v(pCoder, pRSmaParam->qmsg2Len) < 0) return -1; - if (pRSmaParam->qmsg1Len > 0) { - if (tEncodeBinary(pCoder, pRSmaParam->qmsg1, (uint64_t)pRSmaParam->qmsg1Len) < 0) // qmsg1Len contains len of '\0' - return -1; - } - if (pRSmaParam->qmsg2Len > 0) { - if (tEncodeBinary(pCoder, pRSmaParam->qmsg2, (uint64_t)pRSmaParam->qmsg2Len) < 0) // qmsg2Len contains len of '\0' - return -1; + for (int32_t i = 0; i < 2; ++i) { + if (tEncodeI64v(pCoder, pRSmaParam->maxdelay[i]) < 0) return -1; + if (tEncodeI64v(pCoder, pRSmaParam->watermark[i]) < 0) return -1; + if (tEncodeI32v(pCoder, pRSmaParam->qmsgLen[i]) < 0) return -1; + if (pRSmaParam->qmsgLen[i] > 0) { + if (tEncodeBinary(pCoder, pRSmaParam->qmsg[i], (uint64_t)pRSmaParam->qmsgLen[i]) < + 0) // qmsgLen contains len of '\0' + return -1; + } } return 0; } int32_t tDecodeSRSmaParam(SDecoder *pCoder, SRSmaParam *pRSmaParam) { - if (tDecodeFloat(pCoder, &pRSmaParam->xFilesFactor) < 0) return -1; - if (tDecodeI32v(pCoder, &pRSmaParam->delay) < 0) return -1; - if (tDecodeI32v(pCoder, &pRSmaParam->qmsg1Len) < 0) return -1; - if (tDecodeI32v(pCoder, &pRSmaParam->qmsg2Len) < 0) return -1; - if (pRSmaParam->qmsg1Len > 0) { - uint64_t len; - if (tDecodeBinaryAlloc(pCoder, (void **)&pRSmaParam->qmsg1, &len) < 0) return -1; // qmsg1Len contains len of '\0' - } else { - pRSmaParam->qmsg1 = NULL; - } - if (pRSmaParam->qmsg2Len > 0) { - uint64_t len; - if (tDecodeBinaryAlloc(pCoder, (void **)&pRSmaParam->qmsg2, &len) < 0) return -1; // qmsg2Len contains len of '\0' - } else { - pRSmaParam->qmsg2 = NULL; + for (int32_t i = 0; i < 2; ++i) { + if (tDecodeI64v(pCoder, &pRSmaParam->maxdelay[i]) < 0) return -1; + if (tDecodeI64v(pCoder, &pRSmaParam->watermark[i]) < 0) return -1; + if (tDecodeI32v(pCoder, &pRSmaParam->qmsgLen[i]) < 0) return -1; + if (pRSmaParam->qmsgLen[i] > 0) { + uint64_t len; + if (tDecodeBinaryAlloc(pCoder, (void **)&pRSmaParam->qmsg[i], &len) < 0) + return -1; // qmsgLen contains len of '\0' + } else { + pRSmaParam->qmsg[i] = NULL; + } } + return 0; } @@ -4374,6 +4400,10 @@ int tEncodeSVCreateTbReq(SEncoder *pCoder, const SVCreateTbReq *pReq) { if (tEncodeI64(pCoder, pReq->ctime) < 0) return -1; if (tEncodeI32(pCoder, pReq->ttl) < 0) return -1; if (tEncodeI8(pCoder, pReq->type) < 0) return -1; + if (tEncodeI32(pCoder, pReq->commentLen) < 0) return -1; + if (pReq->commentLen > 0) { + if (tEncodeCStr(pCoder, pReq->comment) < 0) return -1; + } if (pReq->type == TSDB_CHILD_TABLE) { if (tEncodeI64(pCoder, pReq->ctb.suid) < 0) return -1; @@ -4397,6 +4427,12 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) { if (tDecodeI64(pCoder, &pReq->ctime) < 0) return -1; if (tDecodeI32(pCoder, &pReq->ttl) < 0) return -1; if (tDecodeI8(pCoder, &pReq->type) < 0) return -1; + if (tDecodeI32(pCoder, &pReq->commentLen) < 0) return -1; + if (pReq->commentLen > 0) { + pReq->comment = taosMemoryMalloc(pReq->commentLen + 1); + if (pReq->comment == NULL) return -1; + if (tDecodeCStrTo(pCoder, pReq->comment) < 0) return -1; + } if (pReq->type == TSDB_CHILD_TABLE) { if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1; @@ -4750,8 +4786,8 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) { if (pReq->updateTTL) { if (tEncodeI32v(pEncoder, pReq->newTTL) < 0) return -1; } - if (tEncodeI8(pEncoder, pReq->updateComment) < 0) return -1; - if (pReq->updateComment) { + if (tEncodeI32v(pEncoder, pReq->newCommentLen) < 0) return -1; + if (pReq->newCommentLen > 0) { if (tEncodeCStr(pEncoder, pReq->newComment) < 0) return -1; } break; @@ -4798,8 +4834,8 @@ int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) { if (pReq->updateTTL) { if (tDecodeI32v(pDecoder, &pReq->newTTL) < 0) return -1; } - if (tDecodeI8(pDecoder, &pReq->updateComment) < 0) return -1; - if (pReq->updateComment) { + if (tDecodeI32v(pDecoder, &pReq->newCommentLen) < 0) return -1; + if (pReq->newCommentLen > 0) { if (tDecodeCStr(pDecoder, &pReq->newComment) < 0) return -1; } break; diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index a845ae7b39..89349d2de9 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -183,6 +183,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_SMA, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_SMA, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_STREAM, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_STREAM, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_GET_INDEX, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_GET_TABLE_INDEX, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; @@ -215,7 +216,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TASK, mmPutMsgToFetchQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TASK_DROP_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIRM_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c index 60c42d31f5..32477febeb 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c @@ -68,6 +68,10 @@ static void mmProcessRpcMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) { mmSendRsp(pMsg, code); } + if (code == TSDB_CODE_RPC_REDIRECT) { + mndPostProcessQueryMsg(pMsg); + } + dTrace("msg:%p, is freed, code:0x%x", pMsg, code); rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); @@ -116,7 +120,7 @@ int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { int32_t mmPutMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { pMsg->info.node = pMgmt->pMnode; - if (mndPreProcessMsg(pMsg) != 0) { + if (mndPreProcessQueryMsg(pMsg) != 0) { dError("msg:%p, failed to pre-process in mnode since %s, type:%s", pMsg, terrstr(), TMSG_INFO(pMsg->msgType)); return -1; } diff --git a/source/dnode/mgmt/mgmt_snode/src/smHandle.c b/source/dnode/mgmt/mgmt_snode/src/smHandle.c index 66ab627e32..e1ffc3bdb7 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smHandle.c +++ b/source/dnode/mgmt/mgmt_snode/src/smHandle.c @@ -95,9 +95,12 @@ SArray *smGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MON_SM_INFO, smPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER_RSP, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; code = 0; _OVER: diff --git a/source/dnode/mgmt/mgmt_snode/src/smWorker.c b/source/dnode/mgmt/mgmt_snode/src/smWorker.c index 34a205232e..19c1b9b5c7 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smWorker.c +++ b/source/dnode/mgmt/mgmt_snode/src/smWorker.c @@ -55,7 +55,10 @@ static void smProcessUniqueQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t num taosGetQitem(qall, (void **)&pMsg); dTrace("msg:%p, get from snode-unique queue", pMsg); - sndProcessUMsg(pMgmt->pSnode, pMsg); + if (sndProcessUMsg(pMgmt->pSnode, pMsg) < 0) { + ASSERT(0); + } + smSendRsp(pMsg, 0); dTrace("msg:%p, is freed", pMsg); rpcFreeCont(pMsg->pCont); @@ -67,7 +70,10 @@ static void smProcessSharedQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { SSnodeMgmt *pMgmt = pInfo->ahandle; dTrace("msg:%p, get from snode-shared queue", pMsg); - sndProcessSMsg(pMgmt->pSnode, pMsg); + if (sndProcessSMsg(pMgmt->pSnode, pMsg) < 0) { + smSendRsp(pMsg, terrno); + ASSERT(0); + } dTrace("msg:%p, is freed", pMsg); rpcFreeCont(pMsg->pCont); diff --git a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h index 7e5379b0f8..6f00767eb0 100644 --- a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h +++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h @@ -35,7 +35,6 @@ typedef struct SVnodeMgmt { SWWorkerPool syncPool; SWWorkerPool writePool; SWWorkerPool applyPool; - SWWorkerPool mergePool; SSingleWorker mgmtWorker; SSingleWorker monitorWorker; SHashObj *hash; @@ -63,7 +62,6 @@ typedef struct { STaosQueue *pApplyQ; STaosQueue *pQueryQ; STaosQueue *pFetchQ; - STaosQueue *pMergeQ; } SVnodeObj; typedef struct { diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index f112727c08..c2821669f0 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -334,6 +334,7 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TTL_TABLE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_TABLE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; @@ -350,7 +351,7 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_HEARTBEAT, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TASK_DROP, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index 9e4e7713f2..3f053639aa 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -86,7 +86,6 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { while (!taosQueueEmpty(pVnode->pApplyQ)) taosMsleep(10); while (!taosQueueEmpty(pVnode->pQueryQ)) taosMsleep(10); while (!taosQueueEmpty(pVnode->pFetchQ)) taosMsleep(10); - while (!taosQueueEmpty(pVnode->pMergeQ)) taosMsleep(10); vmFreeQueue(pMgmt, pVnode); vnodeClose(pVnode->pImpl); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index 09fdd4b087..71bbc8ddd4 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -98,7 +98,7 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { SVnodeObj *pVnode = pInfo->ahandle; - SRpcMsg * pMsg = NULL; + SRpcMsg *pMsg = NULL; for (int32_t i = 0; i < numOfMsgs; ++i) { if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; @@ -119,7 +119,7 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { SVnodeObj *pVnode = pInfo->ahandle; - SRpcMsg * pMsg = NULL; + SRpcMsg *pMsg = NULL; for (int32_t i = 0; i < numOfMsgs; ++i) { if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; @@ -170,10 +170,6 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp dTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg); taosWriteQitem(pVnode->pSyncQ, pMsg); break; - case MERGE_QUEUE: - dTrace("vgId:%d, msg:%p put into vnode-merge queue", pVnode->vgId, pMsg); - taosWriteQitem(pVnode->pMergeQ, pMsg); - break; case APPLY_QUEUE: dTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg); taosWriteQitem(pVnode->pApplyQ, pMsg); @@ -196,8 +192,6 @@ int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsg int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); } -int32_t vmPutMsgToMergeQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, MERGE_QUEUE); } - int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { dTrace("msg:%p, put into vnode-mgmt queue", pMsg); taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg); @@ -243,9 +237,6 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) { case FETCH_QUEUE: size = taosQueueItemSize(pVnode->pFetchQ); break; - case MERGE_QUEUE: - size = taosQueueItemSize(pVnode->pMergeQ); - break; default: break; } @@ -260,10 +251,9 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->applyPool, pVnode->pImpl, (FItems)vnodeApplyMsg); pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue); pVnode->pFetchQ = tQWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItem)vmProcessFetchQueue); - pVnode->pMergeQ = tWWorkerAllocQueue(&pMgmt->mergePool, pVnode, (FItems)vmProcessMergeQueue); if (pVnode->pWriteQ == NULL || pVnode->pSyncQ == NULL || pVnode->pApplyQ == NULL || pVnode->pQueryQ == NULL || - pVnode->pFetchQ == NULL || pVnode->pMergeQ == NULL) { + pVnode->pFetchQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -278,13 +268,11 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { tWWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ); tQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ); tQWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ); - tWWorkerFreeQueue(&pMgmt->mergePool, pVnode->pMergeQ); pVnode->pWriteQ = NULL; pVnode->pSyncQ = NULL; pVnode->pApplyQ = NULL; pVnode->pQueryQ = NULL; pVnode->pFetchQ = NULL; - pVnode->pMergeQ = NULL; dDebug("vgId:%d, queue is freed", pVnode->vgId); } @@ -316,11 +304,6 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) { pSPool->max = tsNumOfVnodeSyncThreads; if (tWWorkerInit(pSPool) != 0) return -1; - SWWorkerPool *pMPool = &pMgmt->mergePool; - pMPool->name = "vnode-merge"; - pMPool->max = tsNumOfVnodeMergeThreads; - if (tWWorkerInit(pMPool) != 0) return -1; - SSingleWorkerCfg mgmtCfg = { .min = 1, .max = 1, @@ -351,6 +334,5 @@ void vmStopWorker(SVnodeMgmt *pMgmt) { tWWorkerCleanup(&pMgmt->syncPool); tQWorkerCleanup(&pMgmt->queryPool); tQWorkerCleanup(&pMgmt->fetchPool); - tWWorkerCleanup(&pMgmt->mergePool); dDebug("vnode workers are closed"); } diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 8963f6be39..3e4cb6a64d 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -341,8 +341,8 @@ typedef struct { int32_t colVer; int32_t smaVer; int32_t nextColId; - float xFilesFactor; - int32_t delay; + int64_t watermark[2]; + int64_t maxdelay[2]; int32_t ttl; int32_t numOfColumns; int32_t numOfTags; @@ -420,7 +420,8 @@ typedef struct { int64_t uid; int64_t dbUid; int32_t version; - int8_t subType; // column, db or stable + int8_t subType; // column, db or stable + int8_t withMeta; // TODO SRWLatch lock; int32_t sqlLen; int32_t astLen; @@ -487,6 +488,7 @@ typedef struct { int64_t dbUid; int32_t vgNum; int8_t subType; + int8_t withMeta; int64_t stbUid; SHashObj* consumerHash; // consumerId -> SMqConsumerEp SArray* unassignedVgs; // SArray diff --git a/source/dnode/mnode/impl/inc/mndScheduler.h b/source/dnode/mnode/impl/inc/mndScheduler.h index 8e816d2dd6..15d2c6cd5e 100644 --- a/source/dnode/mnode/impl/inc/mndScheduler.h +++ b/source/dnode/mnode/impl/inc/mndScheduler.h @@ -30,7 +30,7 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream); int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64_t uid, int8_t triggerType, - int64_t watermark, double filesFactor); + int64_t watermark); int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream); diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index 20ba71992e..dc7f08ebc2 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -381,6 +381,7 @@ SMqSubscribeObj *tCloneSubscribeObj(const SMqSubscribeObj *pSub) { pSubNew->dbUid = pSub->dbUid; pSubNew->stbUid = pSub->stbUid; pSubNew->subType = pSub->subType; + pSubNew->withMeta = pSub->withMeta; pSubNew->vgNum = pSub->vgNum; pSubNew->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); @@ -414,6 +415,7 @@ int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) { tlen += taosEncodeFixedI64(buf, pSub->dbUid); tlen += taosEncodeFixedI32(buf, pSub->vgNum); tlen += taosEncodeFixedI8(buf, pSub->subType); + tlen += taosEncodeFixedI8(buf, pSub->withMeta); tlen += taosEncodeFixedI64(buf, pSub->stbUid); void *pIter = NULL; @@ -440,6 +442,7 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub) { buf = taosDecodeFixedI64(buf, &pSub->dbUid); buf = taosDecodeFixedI32(buf, &pSub->vgNum); buf = taosDecodeFixedI8(buf, &pSub->subType); + buf = taosDecodeFixedI8(buf, &pSub->withMeta); buf = taosDecodeFixedI64(buf, &pSub->stbUid); int32_t sz; diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index fa6f45bdad..ef82d1131c 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -58,31 +58,69 @@ static void *mndBuildTimerMsg(int32_t *pContLen) { static void mndPullupTrans(SMnode *pMnode) { int32_t contLen = 0; - void * pReq = mndBuildTimerMsg(&contLen); + void *pReq = mndBuildTimerMsg(&contLen); SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS_TIMER, .pCont = pReq, .contLen = contLen}; tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } static void mndCalMqRebalance(SMnode *pMnode) { int32_t contLen = 0; - void * pReq = mndBuildTimerMsg(&contLen); + void *pReq = mndBuildTimerMsg(&contLen); SRpcMsg rpcMsg = {.msgType = TDMT_MND_MQ_TIMER, .pCont = pReq, .contLen = contLen}; tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg); } static void mndPullupTelem(SMnode *pMnode) { int32_t contLen = 0; - void * pReq = mndBuildTimerMsg(&contLen); + void *pReq = mndBuildTimerMsg(&contLen); SRpcMsg rpcMsg = {.msgType = TDMT_MND_TELEM_TIMER, .pCont = pReq, .contLen = contLen}; tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg); } +static void mndPushTtlTime(SMnode *pMnode) { + SSdb *pSdb = pMnode->pSdb; + SVgObj *pVgroup = NULL; + void *pIter = NULL; + + while (1) { + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + int32_t contLen = sizeof(SMsgHead) + sizeof(int32_t); + SMsgHead *pHead = rpcMallocCont(contLen); + if (pHead == NULL) { + mError("ttl time malloc err. contLen:%d", contLen); + sdbRelease(pSdb, pVgroup); + continue; + } + pHead->contLen = htonl(contLen); + pHead->vgId = htonl(pVgroup->vgId); + + int32_t t = taosGetTimestampSec(); + *(int32_t *)(POINTER_SHIFT(pHead, sizeof(SMsgHead))) = htonl(t); + + SRpcMsg rpcMsg = {.msgType = TDMT_VND_DROP_TTL_TABLE, .pCont = pHead, .contLen = contLen}; + + SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup); + int32_t code = tmsgSendReq(&epSet, &rpcMsg); + if (code != 0) { + mError("ttl time seed err. code:%d", code); + } + mError("ttl time seed succ. time:%d", t); + sdbRelease(pSdb, pVgroup); + } +} + static void *mndThreadFp(void *param) { SMnode *pMnode = param; int64_t lastTime = 0; setThreadName("mnode-timer"); while (1) { + if (lastTime % (864000) == 0) { // sleep 1 day for ttl + mndPushTtlTime(pMnode); + } + lastTime++; taosMsleep(100); if (mndGetStop(pMnode)) break; @@ -378,7 +416,7 @@ void mndStop(SMnode *pMnode) { } int32_t mndProcessSyncMsg(SRpcMsg *pMsg) { - SMnode * pMnode = pMsg->info.node; + SMnode *pMnode = pMsg->info.node; SSyncMgmt *pMgmt = &pMnode->syncMgmt; int32_t code = 0; @@ -395,15 +433,19 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) { return -1; } - char logBuf[512] = {0}; - char *syncNodeStr = sync2SimpleStr(pMgmt->sync); - snprintf(logBuf, sizeof(logBuf), "==mndProcessSyncMsg== msgType:%d, syncNode: %s", pMsg->msgType, syncNodeStr); - static int64_t mndTick = 0; - if (++mndTick % 10 == 1) { - mTrace("sync trace msg:%s, %s", TMSG_INFO(pMsg->msgType), syncNodeStr); - } - syncRpcMsgLog2(logBuf, pMsg); - taosMemoryFree(syncNodeStr); + do { + char *syncNodeStr = sync2SimpleStr(pMgmt->sync); + static int64_t mndTick = 0; + if (++mndTick % 10 == 1) { + mTrace("vgId:%d, sync heartbeat msg:%s, %s", syncGetVgId(pMgmt->sync), TMSG_INFO(pMsg->msgType), syncNodeStr); + } + if (gRaftDetailLog) { + char logBuf[512] = {0}; + snprintf(logBuf, sizeof(logBuf), "==mndProcessSyncMsg== msgType:%d, syncNode: %s", pMsg->msgType, syncNodeStr); + syncRpcMsgLog2(logBuf, pMsg); + } + taosMemoryFree(syncNodeStr); + } while (0); // ToDo: ugly! use function pointer if (syncNodeSnapshotEnable(pSyncNode)) { @@ -508,7 +550,7 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) { if (!IsReq(pMsg)) return 0; if (mndAcquireRpcRef(pMsg->info.node) == 0) return 0; - if (IsReq(pMsg) && pMsg->msgType != TDMT_MND_MQ_TIMER && pMsg->msgType != TDMT_MND_TELEM_TIMER && + if (pMsg->msgType != TDMT_MND_MQ_TIMER && pMsg->msgType != TDMT_MND_TELEM_TIMER && pMsg->msgType != TDMT_MND_TRANS_TIMER) { mError("msg:%p, failed to check mnode state since %s, type:%s", pMsg, terrstr(), TMSG_INFO(pMsg->msgType)); @@ -540,7 +582,7 @@ static int32_t mndCheckMsgContent(SRpcMsg *pMsg) { } int32_t mndProcessRpcMsg(SRpcMsg *pMsg) { - SMnode * pMnode = pMsg->info.node; + SMnode *pMnode = pMsg->info.node; MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(pMsg->msgType)]; if (fp == NULL) { mError("msg:%p, failed to get msg handle, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType)); @@ -593,7 +635,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr SMonGrantInfo *pGrantInfo) { if (mndAcquireRpcRef(pMnode) != 0) return -1; - SSdb * pSdb = pMnode->pSdb; + SSdb *pSdb = pMnode->pSdb; int64_t ms = taosGetTimestampMs(); pClusterInfo->dnodes = taosArrayInit(sdbGetSize(pSdb, SDB_DNODE), sizeof(SMonDnodeDesc)); @@ -669,7 +711,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr pGrantInfo->timeseries_used += pVgroup->numOfTimeSeries; tstrncpy(desc.status, "unsynced", sizeof(desc.status)); for (int32_t i = 0; i < pVgroup->replica; ++i) { - SVnodeGid * pVgid = &pVgroup->vnodeGid[i]; + SVnodeGid *pVgid = &pVgroup->vnodeGid[i]; SMonVnodeDesc *pVnDesc = &desc.vnodes[i]; pVnDesc->dnode_id = pVgid->dnodeId; tstrncpy(pVnDesc->vnode_role, syncStr(pVgid->role), sizeof(pVnDesc->vnode_role)); diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c index 5374f48e47..671152f9c6 100644 --- a/source/dnode/mnode/impl/src/mndQuery.c +++ b/source/dnode/mnode/impl/src/mndQuery.c @@ -18,13 +18,18 @@ #include "mndMnode.h" #include "qworker.h" -int32_t mndPreProcessMsg(SRpcMsg *pMsg) { +int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg) { if (TDMT_VND_QUERY != pMsg->msgType) return 0; - SMnode *pMnode = pMsg->info.node; return qWorkerPreprocessQueryMsg(pMnode->pQuery, pMsg); } +void mndPostProcessQueryMsg(SRpcMsg *pMsg) { + if (TDMT_VND_QUERY != pMsg->msgType) return; + SMnode *pMnode = pMsg->info.node; + qWorkerAbortPreprocessQueryMsg(pMnode->pQuery, pMsg); +} + int32_t mndProcessQueryMsg(SRpcMsg *pMsg) { int32_t code = -1; SMnode *pMnode = pMsg->info.node; diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 39bb6798aa..2b6258b10a 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -33,7 +33,7 @@ #include "tname.h" #include "tuuid.h" -extern bool tsStreamSchedV; +extern bool tsSchedStreamToSnode; static int32_t mndAddTaskToTaskSet(SArray* pArray, SStreamTask* pTask) { int32_t childId = taosArrayGetSize(pArray); @@ -43,7 +43,7 @@ static int32_t mndAddTaskToTaskSet(SArray* pArray, SStreamTask* pTask) { } int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64_t uid, int8_t triggerType, - int64_t watermark, double filesFactor) { + int64_t watermark) { SNode* pAst = NULL; SQueryPlan* pPlan = NULL; terrno = TSDB_CODE_SUCCESS; @@ -63,9 +63,8 @@ int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64 .topicQuery = false, .streamQuery = true, .rSmaQuery = true, - .triggerType = STREAM_TRIGGER_AT_ONCE, + .triggerType = triggerType, .watermark = watermark, - /*.filesFactor = filesFactor,*/ }; if (qCreateQueryPlan(&cxt, &pPlan, NULL) < 0) { @@ -205,9 +204,11 @@ int32_t mndAssignTaskToVg(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SS return 0; } -SSnodeObj* mndSchedFetchSnode(SMnode* pMnode) { +SSnodeObj* mndSchedFetchOneSnode(SMnode* pMnode) { SSnodeObj* pObj = NULL; - pObj = sdbFetch(pMnode->pSdb, SDB_SNODE, NULL, (void**)&pObj); + void* pIter = NULL; + // TODO random fetch + pIter = sdbFetch(pMnode->pSdb, SDB_SNODE, pIter, (void**)&pObj); return pObj; } @@ -215,7 +216,7 @@ int32_t mndAssignTaskToSnode(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, const SSnodeObj* pSnode) { int32_t msgLen; - pTask->nodeId = 0; + pTask->nodeId = SNODE_HANDLE; pTask->epSet = mndAcquireEpFromSnode(pMnode, pSnode); plan->execNode.nodeId = 0; @@ -225,7 +226,7 @@ int32_t mndAssignTaskToSnode(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, terrno = TSDB_CODE_QRY_INVALID_INPUT; return -1; } - mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_STREAM_TASK_DEPLOY, 0); + mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_STREAM_TASK_DEPLOY, SNODE_HANDLE); return 0; } @@ -270,7 +271,6 @@ int32_t mndAddShuffleSinkTasksToStream(SMnode* pMnode, STrans* pTrans, SStreamOb pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup); // source - pTask->sourceType = TASK_SOURCE__MERGE; pTask->inputType = TASK_INPUT_TYPE__DATA_BLOCK; // exec @@ -316,7 +316,6 @@ int32_t mndAddFixedSinkTaskToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* #endif pTask->epSet = mndGetVgroupEpset(pMnode, &pStream->fixedSinkVg); // source - pTask->sourceType = TASK_SOURCE__MERGE; pTask->inputType = TASK_INPUT_TYPE__DATA_BLOCK; // exec @@ -373,8 +372,8 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { } if (totLevel > 1) { - SStreamTask* pFinalTask; - // inner plan + SStreamTask* pInnerTask; + // inner level { SArray* taskInnerLevel = taosArrayInit(0, sizeof(void*)); taosArrayPush(pStream->tasks, &taskInnerLevel); @@ -383,31 +382,51 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { SSubplan* plan = (SSubplan*)nodesListGetNode(inner->pNodeList, 0); ASSERT(plan->subplanType == SUBPLAN_TYPE_MERGE); - pFinalTask = tNewSStreamTask(pStream->uid); - mndAddTaskToTaskSet(taskInnerLevel, pFinalTask); + pInnerTask = tNewSStreamTask(pStream->uid); + mndAddTaskToTaskSet(taskInnerLevel, pInnerTask); // input - pFinalTask->inputType = TASK_INPUT_TYPE__DATA_BLOCK; + pInnerTask->inputType = TASK_INPUT_TYPE__DATA_BLOCK; // trigger - pFinalTask->triggerParam = pStream->triggerParam; + pInnerTask->triggerParam = pStream->triggerParam; // dispatch - if (mndAddDispatcherToInnerTask(pMnode, pTrans, pStream, pFinalTask) < 0) { + if (mndAddDispatcherToInnerTask(pMnode, pTrans, pStream, pInnerTask) < 0) { qDestroyQueryPlan(pPlan); return -1; } // exec - pFinalTask->execType = TASK_EXEC__PIPE; - SVgObj* pVgroup = mndSchedFetchOneVg(pMnode, pStream->sourceDbUid); - if (mndAssignTaskToVg(pMnode, pTrans, pFinalTask, plan, pVgroup) < 0) { - sdbRelease(pSdb, pVgroup); - qDestroyQueryPlan(pPlan); - return -1; + pInnerTask->execType = TASK_EXEC__PIPE; + + if (tsSchedStreamToSnode) { + SSnodeObj* pSnode = mndSchedFetchOneSnode(pMnode); + if (pSnode == NULL) { + SVgObj* pVgroup = mndSchedFetchOneVg(pMnode, pStream->sourceDbUid); + if (mndAssignTaskToVg(pMnode, pTrans, pInnerTask, plan, pVgroup) < 0) { + sdbRelease(pSdb, pVgroup); + qDestroyQueryPlan(pPlan); + return -1; + } + } else { + if (mndAssignTaskToSnode(pMnode, pTrans, pInnerTask, plan, pSnode) < 0) { + ASSERT(0); + sdbRelease(pSdb, pSnode); + qDestroyQueryPlan(pPlan); + return -1; + } + } + } else { + SVgObj* pVgroup = mndSchedFetchOneVg(pMnode, pStream->sourceDbUid); + if (mndAssignTaskToVg(pMnode, pTrans, pInnerTask, plan, pVgroup) < 0) { + sdbRelease(pSdb, pVgroup); + qDestroyQueryPlan(pPlan); + return -1; + } } } - // source plan + // source level SArray* taskSourceLevel = taosArrayInit(0, sizeof(void*)); taosArrayPush(pStream->tasks, &taskSourceLevel); @@ -427,6 +446,8 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { SStreamTask* pTask = tNewSStreamTask(pStream->uid); mndAddTaskToTaskSet(taskSourceLevel, pTask); + pTask->dataScan = 1; + // input pTask->inputType = TASK_INPUT_TYPE__SUMBIT_BLOCK; @@ -435,9 +456,9 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { pTask->dispatchMsgType = TDMT_STREAM_TASK_DISPATCH; pTask->dispatchType = TASK_DISPATCH__FIXED; - pTask->fixedEpDispatcher.taskId = pFinalTask->taskId; - pTask->fixedEpDispatcher.nodeId = pFinalTask->nodeId; - pTask->fixedEpDispatcher.epSet = pFinalTask->epSet; + pTask->fixedEpDispatcher.taskId = pInnerTask->taskId; + pTask->fixedEpDispatcher.nodeId = pInnerTask->nodeId; + pTask->fixedEpDispatcher.epSet = pInnerTask->epSet; // exec pTask->execType = TASK_EXEC__PIPE; @@ -470,9 +491,14 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { SStreamTask* pTask = tNewSStreamTask(pStream->uid); mndAddTaskToTaskSet(taskOneLevel, pTask); + pTask->dataScan = 1; + // input pTask->inputType = TASK_INPUT_TYPE__SUMBIT_BLOCK; + // trigger + pTask->triggerParam = pStream->triggerParam; + // sink or dispatch if (hasExtraSink) { mndAddDispatcherToInnerTask(pMnode, pTrans, pStream, pTask); diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 0a99f356b1..12188a3b3a 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -408,6 +408,7 @@ static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) { goto _OVER; } + // check deletable code = mndDropSnode(pMnode, pReq, pObj); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index c37cdd1888..3e50ea8262 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -89,8 +89,10 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) { SDB_SET_INT32(pRaw, dataPos, pStb->tagVer, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->colVer, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, _OVER) - SDB_SET_INT32(pRaw, dataPos, (int32_t)(pStb->xFilesFactor * 10000), _OVER) - SDB_SET_INT32(pRaw, dataPos, pStb->delay, _OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->maxdelay[0], _OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->maxdelay[1], _OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->watermark[0], _OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->watermark[1], _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->ttl, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags, _OVER) @@ -117,7 +119,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) { } if (pStb->commentLen > 0) { - SDB_SET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen, _OVER) + SDB_SET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen + 1, _OVER) } if (pStb->ast1Len > 0) { SDB_SET_BINARY(pRaw, dataPos, pStb->pAst1, pStb->ast1Len, _OVER) @@ -168,10 +170,10 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pStb->tagVer, _OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->colVer, _OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->nextColId, _OVER) - int32_t xFilesFactor = 0; - SDB_GET_INT32(pRaw, dataPos, &xFilesFactor, _OVER) - pStb->xFilesFactor = xFilesFactor / 10000.0f; - SDB_GET_INT32(pRaw, dataPos, &pStb->delay, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->maxdelay[0], _OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->maxdelay[1], _OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->watermark[0], _OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->watermark[1], _OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->ttl, _OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, _OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTags, _OVER) @@ -204,9 +206,9 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { } if (pStb->commentLen > 0) { - pStb->comment = taosMemoryCalloc(pStb->commentLen, 1); + pStb->comment = taosMemoryCalloc(pStb->commentLen + 1, 1); if (pStb->comment == NULL) goto _OVER; - SDB_GET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen, _OVER) + SDB_GET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen + 1, _OVER) } if (pStb->ast1Len > 0) { pStb->pAst1 = taosMemoryCalloc(pStb->ast1Len, 1); @@ -280,8 +282,8 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { } } - if (pOld->commentLen < pNew->commentLen) { - void *comment = taosMemoryMalloc(pNew->commentLen); + if (pOld->commentLen < pNew->commentLen && pNew->commentLen > 0) { + void *comment = taosMemoryMalloc(pNew->commentLen + 1); if (comment != NULL) { taosMemoryFree(pOld->comment); pOld->comment = comment; @@ -291,6 +293,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { taosWUnLockLatch(&pOld->lock); } } + pOld->commentLen = pNew->commentLen; if (pOld->ast1Len < pNew->ast1Len) { void *pAst1 = taosMemoryMalloc(pNew->ast1Len); @@ -330,8 +333,8 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { pOld->numOfTags = pNew->numOfTags; memcpy(pOld->pTags, pNew->pTags, pOld->numOfTags * sizeof(SSchema)); } - if (pNew->commentLen != 0) { - memcpy(pOld->comment, pNew->comment, pNew->commentLen); + if (pNew->commentLen > 0) { + memcpy(pOld->comment, pNew->comment, pNew->commentLen + 1); } if (pNew->ast1Len != 0) { memcpy(pOld->pAst1, pNew->pAst1, pNew->ast1Len); @@ -398,18 +401,18 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt req.schemaTag.pSchema = pStb->pTags; if (req.rollup) { - req.pRSmaParam.xFilesFactor = pStb->xFilesFactor; - req.pRSmaParam.delay = pStb->delay; + req.pRSmaParam.maxdelay[0] = pStb->maxdelay[0]; + req.pRSmaParam.maxdelay[1] = pStb->maxdelay[1]; if (pStb->ast1Len > 0) { - if (mndConvertRsmaTask(&req.pRSmaParam.qmsg1, &req.pRSmaParam.qmsg1Len, pStb->pAst1, pStb->uid, - STREAM_TRIGGER_AT_ONCE, 0, req.pRSmaParam.xFilesFactor) != TSDB_CODE_SUCCESS) { - return NULL; + if (mndConvertRsmaTask(&req.pRSmaParam.qmsg[0], &req.pRSmaParam.qmsgLen[0], pStb->pAst1, pStb->uid, + STREAM_TRIGGER_WINDOW_CLOSE, req.pRSmaParam.watermark[0]) < 0) { + goto _err; } } if (pStb->ast2Len > 0) { - if (mndConvertRsmaTask(&req.pRSmaParam.qmsg2, &req.pRSmaParam.qmsg2Len, pStb->pAst2, pStb->uid, - STREAM_TRIGGER_AT_ONCE, 0, req.pRSmaParam.xFilesFactor) != TSDB_CODE_SUCCESS) { - return NULL; + if (mndConvertRsmaTask(&req.pRSmaParam.qmsg[1], &req.pRSmaParam.qmsgLen[1], pStb->pAst2, pStb->uid, + STREAM_TRIGGER_WINDOW_CLOSE, req.pRSmaParam.watermark[1]) < 0) { + goto _err; } } } @@ -417,17 +420,15 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt int32_t ret = 0; tEncodeSize(tEncodeSVCreateStbReq, &req, contLen, ret); if (ret < 0) { - return NULL; + goto _err; } contLen += sizeof(SMsgHead); SMsgHead *pHead = taosMemoryMalloc(contLen); if (pHead == NULL) { - taosMemoryFreeClear(req.pRSmaParam.qmsg1); - taosMemoryFreeClear(req.pRSmaParam.qmsg2); terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; + goto _err; } pHead->contLen = htonl(contLen); @@ -437,17 +438,19 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt tEncoderInit(&encoder, pBuf, contLen - sizeof(SMsgHead)); if (tEncodeSVCreateStbReq(&encoder, &req) < 0) { taosMemoryFreeClear(pHead); - taosMemoryFreeClear(req.pRSmaParam.qmsg1); - taosMemoryFreeClear(req.pRSmaParam.qmsg2); tEncoderClear(&encoder); - return NULL; + goto _err; } tEncoderClear(&encoder); *pContLen = contLen; - taosMemoryFreeClear(req.pRSmaParam.qmsg1); - taosMemoryFreeClear(req.pRSmaParam.qmsg2); + taosMemoryFreeClear(req.pRSmaParam.qmsg[0]); + taosMemoryFreeClear(req.pRSmaParam.qmsg[1]); return pHead; +_err: + taosMemoryFreeClear(req.pRSmaParam.qmsg[0]); + taosMemoryFreeClear(req.pRSmaParam.qmsg[1]); + return NULL; } static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int32_t *pContLen) { @@ -669,19 +672,21 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat pDst->tagVer = 1; pDst->colVer = 1; pDst->nextColId = 1; - // pDst->xFilesFactor = pCreate->xFilesFactor; - // pDst->delay = pCreate->delay; + pDst->maxdelay[0] = pCreate->delay1; + pDst->maxdelay[1] = pCreate->delay2; + pDst->watermark[0] = pCreate->watermark1; + pDst->watermark[1] = pCreate->watermark2; pDst->ttl = pCreate->ttl; pDst->numOfColumns = pCreate->numOfColumns; pDst->numOfTags = pCreate->numOfTags; pDst->commentLen = pCreate->commentLen; if (pDst->commentLen > 0) { - pDst->comment = taosMemoryCalloc(pDst->commentLen, 1); + pDst->comment = taosMemoryCalloc(pDst->commentLen + 1, 1); if (pDst->comment == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - memcpy(pDst->comment, pCreate->comment, pDst->commentLen); + memcpy(pDst->comment, pCreate->comment, pDst->commentLen + 1); } pDst->ast1Len = pCreate->ast1Len; @@ -835,7 +840,7 @@ _OVER: } static int32_t mndCheckAlterStbReq(SMAlterStbReq *pAlter) { - if (pAlter->commentLen != 0 || pAlter->ttl != 0) return 0; + if (pAlter->commentLen >= 0 || pAlter->ttl != 0) return 0; if (pAlter->numOfFields < 1 || pAlter->numOfFields != (int32_t)taosArrayGetSize(pAlter->pFields)) { terrno = TSDB_CODE_MND_INVALID_STB_OPTION; @@ -890,13 +895,16 @@ static int32_t mndUpdateStbCommentAndTTL(const SStbObj *pOld, SStbObj *pNew, cha int32_t ttl) { if (commentLen > 0) { pNew->commentLen = commentLen; - pNew->comment = taosMemoryCalloc(1, commentLen); + pNew->comment = taosMemoryCalloc(1, commentLen + 1); if (pNew->comment == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - memcpy(pNew->comment, pComment, commentLen); + memcpy(pNew->comment, pComment, commentLen + 1); + } else if (commentLen == 0) { + pNew->commentLen = 0; } + if (ttl >= 0) { pNew->ttl = ttl; } @@ -1206,7 +1214,6 @@ static int32_t mndSetAlterStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj sdbRelease(pSdb, pVgroup); return -1; } - STransAction action = {0}; action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pReq; @@ -1841,17 +1848,17 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)&pStb->updateTime, false); // number of tables - char *p = taosMemoryCalloc(1, pStb->commentLen + 1 + VARSTR_HEADER_SIZE); // check malloc failures - if (p != NULL) { - if (pStb->commentLen != 0) { - STR_TO_VARSTR(p, pStb->comment); - } else { - STR_TO_VARSTR(p, ""); - } - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols); - colDataAppend(pColInfo, numOfRows, (const char *)p, false); - taosMemoryFree(p); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols); + if (pStb->commentLen > 0) { + char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, pStb->comment); + colDataAppend(pColInfo, numOfRows, comment, false); + } else if (pStb->commentLen == 0) { + char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, ""); + colDataAppend(pColInfo, numOfRows, comment, false); + } else { + colDataAppendNULL(pColInfo, numOfRows); } numOfRows++; diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index d432256f15..7e9069d5fc 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -54,9 +54,10 @@ int32_t mndInitStream(SMnode *pMnode) { }; mndSetMsgHandle(pMnode, TDMT_MND_CREATE_STREAM, mndProcessCreateStreamReq); - mndSetMsgHandle(pMnode, TDMT_STREAM_TASK_DEPLOY_RSP, mndTransProcessRsp); mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM, mndProcessDropStreamReq); - mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM_RSP, mndTransProcessRsp); + + mndSetMsgHandle(pMnode, TDMT_STREAM_TASK_DEPLOY_RSP, mndTransProcessRsp); + mndSetMsgHandle(pMnode, TDMT_STREAM_TASK_DROP_RSP, mndTransProcessRsp); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndRetrieveStream); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndCancelGetNextStream); @@ -477,7 +478,7 @@ static int32_t mndPersistTaskDropReq(STrans *pTrans, SStreamTask *pTask) { memcpy(&action.epSet, &pTask->epSet, sizeof(SEpSet)); action.pCont = pReq; action.contLen = sizeof(SVDropStreamTaskReq); - action.msgType = TDMT_VND_STREAM_TASK_DROP; + action.msgType = TDMT_STREAM_TASK_DROP; if (mndTransAppendRedoAction(pTrans, &action) != 0) { taosMemoryFree(pReq); return -1; @@ -518,7 +519,6 @@ static int32_t mndCreateStream(SMnode *pMnode, SRpcMsg *pReq, SCMCreateStreamReq // TODO streamObj.fixedSinkVgId = 0; streamObj.smaId = 0; - /*streamObj.physicalPlan = "";*/ streamObj.trigger = pCreate->triggerType; streamObj.watermark = pCreate->watermark; streamObj.triggerParam = pCreate->maxDelay; @@ -607,17 +607,6 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) { } #endif - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq); - if (pTrans == NULL) { - mError("stream:%s, failed to create since %s", createStreamReq.name, terrstr()); - goto _OVER; - } - - mndTransSetDbName(pTrans, createStreamReq.sourceDB, NULL); - // TODO - /*mndTransSetDbName(pTrans, streamObj.targetDb, NULL);*/ - mDebug("trans:%d, used to create stream:%s", pTrans->id, createStreamReq.name); - // build stream obj from request SStreamObj streamObj = {0}; if (mndBuildStreamObjFromCreateReq(pMnode, &streamObj, &createStreamReq) < 0) { @@ -626,6 +615,14 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) { goto _OVER; } + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq); + if (pTrans == NULL) { + mError("stream:%s, failed to create since %s", createStreamReq.name, terrstr()); + goto _OVER; + } + mndTransSetDbName(pTrans, createStreamReq.sourceDB, streamObj.targetDb); + mDebug("trans:%d, used to create stream:%s", pTrans->id, createStreamReq.name); + // create stb for stream if (mndCreateStbForStream(pMnode, pTrans, &streamObj, pReq->info.conn.user) < 0) { mError("trans:%d, failed to create stb for stream %s since %s", pTrans->id, createStreamReq.name, terrstr()); @@ -674,20 +671,24 @@ _OVER: static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; - int32_t code = -1; SStreamObj *pStream = NULL; /*SDbObj *pDb = NULL;*/ /*SUserObj *pUser = NULL;*/ - SMDropStreamReq dropReq = *(SMDropStreamReq *)pReq->pCont; + SMDropStreamReq dropReq = {0}; + if (tDeserializeSMDropStreamReq(pReq->pCont, pReq->contLen, &dropReq) < 0) { + ASSERT(0); + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } pStream = mndAcquireStream(pMnode, dropReq.name); if (pStream == NULL) { if (dropReq.igNotExists) { mDebug("stream:%s, not exist, ignore not exist is set", dropReq.name); - code = 0; - goto DROP_STREAM_OVER; + sdbRelease(pMnode->pSdb, pStream); + return -1; } else { terrno = TSDB_CODE_MND_STREAM_NOT_EXIST; return -1; @@ -705,14 +706,16 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq); if (pTrans == NULL) { mError("stream:%s, failed to drop since %s", dropReq.name, terrstr()); - return code; + sdbRelease(pMnode->pSdb, pStream); + return -1; } mDebug("trans:%d, used to drop stream:%s", pTrans->id, dropReq.name); // drop all tasks if (mndDropStreamTasks(pMnode, pTrans, pStream) < 0) { mError("stream:%s, failed to drop task since %s", dropReq.name, terrstr()); - return code; + sdbRelease(pMnode->pSdb, pStream); + return -1; } // drop stream @@ -721,8 +724,16 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { return -1; } -DROP_STREAM_OVER: - return code; + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare drop stream trans since %s", pTrans->id, terrstr()); + sdbRelease(pMnode->pSdb, pStream); + mndTransDrop(pTrans); + return -1; + } + + sdbRelease(pMnode->pSdb, pStream); + + return TSDB_CODE_ACTION_IN_PROGRESS; } int32_t mndDropStreamByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index d2b7a61e83..8dde3e92d8 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -96,6 +96,7 @@ static SMqSubscribeObj *mndCreateSub(SMnode *pMnode, const SMqTopicObj *pTopic, pSub->dbUid = pTopic->dbUid; pSub->stbUid = pTopic->stbUid; pSub->subType = pTopic->subType; + pSub->withMeta = pTopic->withMeta; ASSERT(pSub->unassignedVgs->size == 0); ASSERT(taosHashGetSize(pSub->consumerHash) == 0); @@ -120,6 +121,7 @@ static int32_t mndBuildSubChangeReq(void **pBuf, int32_t *pLen, const SMqSubscri req.vgId = pRebVg->pVgEp->vgId; req.qmsg = pRebVg->pVgEp->qmsg; req.subType = pSub->subType; + req.withMeta = pSub->withMeta; req.suid = pSub->stbUid; strncpy(req.subKey, pSub->key, TSDB_SUBSCRIBE_KEY_LEN); diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 3e3850de1a..8666739dab 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -68,12 +68,21 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM mndTransExecute(pMnode, pTrans); mndReleaseTrans(pMnode, pTrans); } - +#if 0 sdbWriteFile(pMnode->pSdb, SDB_WRITE_DELTA); +#endif } } -int32_t mndSyncGetSnapshot(struct SSyncFSM *pFsm, SSnapshot *pSnapshot) { +int32_t mndSyncGetSnapshot(struct SSyncFSM *pFsm, SSnapshot *pSnapshot, void *pReaderParam, void **ppReader) { + mInfo("start to read snapshot from sdb in atomic way"); + SMnode *pMnode = pFsm->data; + return sdbStartRead(pMnode->pSdb, (SSdbIter **)ppReader, &pSnapshot->lastApplyIndex, &pSnapshot->lastApplyTerm, + &pSnapshot->lastConfigIndex); + return 0; +} + +int32_t mndSyncGetSnapshotInfo(struct SSyncFSM *pFsm, SSnapshot *pSnapshot) { SMnode *pMnode = pFsm->data; sdbGetCommitInfo(pMnode->pSdb, &pSnapshot->lastApplyIndex, &pSnapshot->lastApplyTerm, &pSnapshot->lastConfigIndex); return 0; @@ -95,14 +104,6 @@ void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta cbM SMnode *pMnode = pFsm->data; SSyncMgmt *pMgmt = &pMnode->syncMgmt; -#if 0 -// send response - SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen, .conn.applyIndex = cbMeta.index}; - rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); - memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen); - syncGetAndDelRespRpc(pMnode->syncMgmt.sync, cbMeta.seqNum, &rpcMsg.info); -#endif - pMgmt->errCode = cbMeta.code; mInfo("trans:-1, sync reconfig is proposed, saved:%d code:0x%x, index:%" PRId64 " term:%" PRId64, pMgmt->transId, cbMeta.code, cbMeta.index, cbMeta.term); @@ -119,7 +120,7 @@ void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta cbM int32_t mndSnapshotStartRead(struct SSyncFSM *pFsm, void **ppReader) { mInfo("start to read snapshot from sdb"); SMnode *pMnode = pFsm->data; - return sdbStartRead(pMnode->pSdb, (SSdbIter **)ppReader); + return sdbStartRead(pMnode->pSdb, (SSdbIter **)ppReader, NULL, NULL, NULL); } int32_t mndSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) { @@ -159,6 +160,7 @@ SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) { pFsm->FpRestoreFinishCb = mndRestoreFinish; pFsm->FpReConfigCb = mndReConfig; pFsm->FpGetSnapshot = mndSyncGetSnapshot; + pFsm->FpGetSnapshotInfo = mndSyncGetSnapshotInfo; pFsm->FpSnapshotStartRead = mndSnapshotStartRead; pFsm->FpSnapshotStopRead = mndSnapshotStopRead; pFsm->FpSnapshotDoRead = mndSnapshotDoRead; diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 9632c04f4c..a650ed29f1 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -141,6 +141,7 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { SDB_SET_INT64(pRaw, dataPos, pTopic->dbUid, TOPIC_ENCODE_OVER); SDB_SET_INT32(pRaw, dataPos, pTopic->version, TOPIC_ENCODE_OVER); SDB_SET_INT8(pRaw, dataPos, pTopic->subType, TOPIC_ENCODE_OVER); + SDB_SET_INT8(pRaw, dataPos, pTopic->withMeta, TOPIC_ENCODE_OVER); SDB_SET_INT64(pRaw, dataPos, pTopic->stbUid, TOPIC_ENCODE_OVER); SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen, TOPIC_ENCODE_OVER); @@ -208,6 +209,7 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { SDB_GET_INT64(pRaw, dataPos, &pTopic->dbUid, TOPIC_DECODE_OVER); SDB_GET_INT32(pRaw, dataPos, &pTopic->version, TOPIC_DECODE_OVER); SDB_GET_INT8(pRaw, dataPos, &pTopic->subType, TOPIC_DECODE_OVER); + SDB_GET_INT8(pRaw, dataPos, &pTopic->withMeta, TOPIC_DECODE_OVER); SDB_GET_INT64(pRaw, dataPos, &pTopic->stbUid, TOPIC_DECODE_OVER); SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER); @@ -357,6 +359,10 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * topicObj.sql = strdup(pCreate->sql); topicObj.sqlLen = strlen(pCreate->sql) + 1; topicObj.subType = pCreate->subType; + topicObj.withMeta = pCreate->withMeta; + if (topicObj.withMeta) { + ASSERT(topicObj.subType != TOPIC_SUB_TYPE__COLUMN); + } if (pCreate->subType == TOPIC_SUB_TYPE__COLUMN) { topicObj.ast = strdup(pCreate->ast); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 31a955b030..de6a44d456 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -22,8 +22,8 @@ #include "mndSync.h" #include "mndUser.h" -#define TRANS_VER_NUMBER 1 -#define TRANS_ARRAY_SIZE 8 +#define TRANS_VER_NUMBER 1 +#define TRANS_ARRAY_SIZE 8 #define TRANS_RESERVE_SIZE 64 static SSdbRaw *mndTransActionEncode(STrans *pTrans); @@ -804,7 +804,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) { sendRsp = true; } } else { - if (pTrans->stage == TRN_STAGE_REDO_ACTION && pTrans->failedTimes > 2) { + if (pTrans->stage == TRN_STAGE_REDO_ACTION && pTrans->failedTimes > 3) { if (code == 0) code = TSDB_CODE_MND_TRANS_UNKNOW_ERROR; sendRsp = true; } @@ -896,7 +896,7 @@ static void mndTransResetActions(SMnode *pMnode, STrans *pTrans, SArray *pArray) pAction->rawWritten = 0; pAction->msgSent = 0; pAction->msgReceived = 0; - if (pAction->errCode == TSDB_CODE_RPC_REDIRECT || pAction->errCode == TSDB_CODE_SYN_NOT_IN_NEW_CONFIG || + if (pAction->errCode == TSDB_CODE_RPC_REDIRECT || pAction->errCode == TSDB_CODE_SYN_NEW_CONFIG_ERROR || pAction->errCode == TSDB_CODE_SYN_INTERNAL_ERROR || pAction->errCode == TSDB_CODE_SYN_NOT_LEADER) { pAction->epSet.inUse = (pAction->epSet.inUse + 1) % pAction->epSet.numOfEps; mDebug("trans:%d, %s:%d execute status is reset and set epset inuse:%d", pTrans->id, mndTransStr(pAction->stage), @@ -1127,6 +1127,7 @@ static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans) } if (code == 0) { + pTrans->failedTimes = 0; pTrans->lastAction = action; pTrans->lastMsgType = 0; pTrans->lastErrorNo = 0; @@ -1430,8 +1431,7 @@ void mndTransPullup(SMnode *pMnode) { mndReleaseTrans(pMnode, pTrans); } - // todo, set to SDB_WRITE_DELTA - sdbWriteFile(pMnode->pSdb, 0); + sdbWriteFile(pMnode->pSdb, SDB_WRITE_DELTA); taosArrayDestroy(pArray); } diff --git a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp index bc118ee26e..87895d3b49 100644 --- a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp +++ b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp @@ -910,7 +910,7 @@ TEST_F(MndTestSdb, 01_Read_Str) { int32_t len = 0; int32_t code = 0; - code = sdbStartRead(pSdb, &pReader); + code = sdbStartRead(pSdb, &pReader, NULL, NULL, NULL); ASSERT_EQ(code, 0); code = sdbStartWrite(pSdb, &pWritter); ASSERT_EQ(code, 0); diff --git a/source/dnode/mnode/sdb/inc/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h index 1bd09aef63..1294f0cff3 100644 --- a/source/dnode/mnode/sdb/inc/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -37,7 +37,7 @@ extern "C" { #define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", DEBUG_TRACE, mDebugFlag, __VA_ARGS__); }} // clang-format on -#define SDB_WRITE_DELTA 100 +#define SDB_WRITE_DELTA 20 #define SDB_GET_VAL(pData, dataPos, val, pos, func, type) \ { \ @@ -388,7 +388,7 @@ SSdbRow *sdbAllocRow(int32_t objSize); void *sdbGetRowObj(SSdbRow *pRow); void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow, bool callFunc); -int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter); +int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *term, int64_t *config); int32_t sdbStopRead(SSdb *pSdb, SSdbIter *pIter); int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len); diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index c44f1670c3..fbf66da632 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -161,9 +161,11 @@ static int32_t sdbCreateDir(SSdb *pSdb) { } void sdbSetApplyInfo(SSdb *pSdb, int64_t index, int64_t term, int64_t config) { - mTrace("mnode apply info changed, from index:%" PRId64 " term:%" PRId64 " config:%" PRId64 ", to index:%" PRId64 +#if 1 + mTrace("mnode apply info changed from index:%" PRId64 " term:%" PRId64 " config:%" PRId64 " to index:%" PRId64 " term:%" PRId64 " config:%" PRId64, pSdb->applyIndex, pSdb->applyTerm, pSdb->applyConfig, index, term, config); +#endif pSdb->applyIndex = index; pSdb->applyTerm = term; pSdb->applyConfig = config; @@ -173,7 +175,9 @@ void sdbGetCommitInfo(SSdb *pSdb, int64_t *index, int64_t *term, int64_t *config *index = pSdb->commitIndex; *term = pSdb->commitTerm; *config = pSdb->commitConfig; +#if 0 mTrace("mnode current info, apply index:%" PRId64 " term:%" PRId64 " config:%" PRId64 ", commit index:%" PRId64 " term:%" PRId64 " config:%" PRId64, pSdb->applyIndex, pSdb->applyTerm, pSdb->applyConfig, *index, *term, *config); +#endif } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 0f4e1276c1..47c4a4ed0f 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -523,7 +523,7 @@ static void sdbCloseIter(SSdbIter *pIter) { taosMemoryFree(pIter); } -int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter) { +int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *term, int64_t *config) { SSdbIter *pIter = sdbCreateIter(pSdb); if (pIter == NULL) return -1; @@ -552,6 +552,10 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter) { } *ppIter = pIter; + if (index != NULL) *index = commitIndex; + if (term != NULL) *term = commitTerm; + if (config != NULL) *config = commitConfig; + mInfo("sdbiter:%p, is created to read snapshot, commit index:%" PRId64 " term:%" PRId64 " config:%" PRId64 " file:%s", pIter, commitIndex, commitTerm, commitConfig, pIter->name); return 0; diff --git a/source/dnode/snode/inc/sndInt.h b/source/dnode/snode/inc/sndInt.h index 2802537dcd..8916e2a31c 100644 --- a/source/dnode/snode/inc/sndInt.h +++ b/source/dnode/snode/inc/sndInt.h @@ -56,7 +56,6 @@ SStreamTask* sndMetaGetTask(SStreamMeta* pMeta, int32_t taskId); int32_t sndMetaRemoveTask(SStreamMeta* pMeta, int32_t taskId); int32_t sndDropTaskOfStream(SStreamMeta* pMeta, int64_t streamId); - int32_t sndStopTaskOfStream(SStreamMeta* pMeta, int64_t streamId); int32_t sndResumeTaskOfStream(SStreamMeta* pMeta, int64_t streamId); diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c index cbbe071c5f..c2c4ea3a88 100644 --- a/source/dnode/snode/src/snode.c +++ b/source/dnode/snode/src/snode.c @@ -76,45 +76,157 @@ int32_t sndMetaRemoveTask(SStreamMeta *pMeta, int32_t taskId) { return taosHashRemove(pMeta->pHash, &taskId, sizeof(int32_t)); } -static int32_t sndProcessTaskExecReq(SSnode *pSnode, SRpcMsg *pMsg) { - /*SStreamExecMsgHead *pHead = pMsg->pCont;*/ - /*int32_t taskId = pHead->streamTaskId;*/ - /*SStreamTask *pTask = sndMetaGetTask(pSnode->pMeta, taskId);*/ - /*if (pTask == NULL) {*/ - /*return -1;*/ - /*}*/ +static int32_t sndProcessTaskDeployReq(SSnode *pNode, SRpcMsg *pMsg) { + SStreamMeta *pMeta = pNode->pMeta; + char *msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + + SStreamTask *pTask = taosMemoryCalloc(1, sizeof(SStreamTask)); + if (pTask == NULL) { + return -1; + } + SDecoder decoder; + tDecoderInit(&decoder, (uint8_t *)msg, msgLen); + if (tDecodeSStreamTask(&decoder, pTask) < 0) { + ASSERT(0); + } + tDecoderClear(&decoder); + + pTask->execStatus = TASK_EXEC_STATUS__IDLE; + + pTask->inputQueue = streamQueueOpen(); + pTask->outputQueue = streamQueueOpen(); + pTask->inputStatus = TASK_INPUT_STATUS__NORMAL; + pTask->outputStatus = TASK_INPUT_STATUS__NORMAL; + + if (pTask->inputQueue == NULL || pTask->outputQueue == NULL) goto FAIL; + + pTask->pMsgCb = &pNode->msgCb; + + ASSERT(pTask->execType != TASK_EXEC__NONE); + + ASSERT(pTask->dataScan == 0); + pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, NULL); + ASSERT(pTask->exec.executor); + + streamSetupTrigger(pTask); + + qInfo("deploy stream: stream id %ld task id %d child id %d on snode", pTask->streamId, pTask->taskId, pTask->childId); + + taosHashPut(pMeta->pHash, &pTask->taskId, sizeof(int32_t), &pTask, sizeof(void *)); + + return 0; + +FAIL: + if (pTask->inputQueue) streamQueueClose(pTask->inputQueue); + if (pTask->outputQueue) streamQueueClose(pTask->outputQueue); + if (pTask) taosMemoryFree(pTask); + return -1; +} + +static int32_t sndProcessTaskRunReq(SSnode *pNode, SRpcMsg *pMsg) { + SStreamMeta *pMeta = pNode->pMeta; + SStreamTaskRunReq *pReq = pMsg->pCont; + int32_t taskId = pReq->taskId; + SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); + streamProcessRunReq(pTask); return 0; } -void sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) { +static int32_t sndProcessTaskDispatchReq(SSnode *pNode, SRpcMsg *pMsg) { + SStreamMeta *pMeta = pNode->pMeta; + + char *msgStr = pMsg->pCont; + char *msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + + SStreamDispatchReq req; + SDecoder decoder; + tDecoderInit(&decoder, msgBody, msgLen); + tDecodeStreamDispatchReq(&decoder, &req); + int32_t taskId = req.taskId; + SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); + SRpcMsg rsp = { + .info = pMsg->info, + .code = 0, + }; + streamProcessDispatchReq(pTask, &req, &rsp); + return 0; +} + +static int32_t sndProcessTaskRecoverReq(SSnode *pNode, SRpcMsg *pMsg) { + SStreamMeta *pMeta = pNode->pMeta; + + SStreamTaskRecoverReq *pReq = pMsg->pCont; + int32_t taskId = pReq->taskId; + SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); + streamProcessRecoverReq(pTask, pReq, pMsg); + return 0; +} + +static int32_t sndProcessTaskDispatchRsp(SSnode *pNode, SRpcMsg *pMsg) { + SStreamMeta *pMeta = pNode->pMeta; + + SStreamDispatchRsp *pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); + int32_t taskId = pRsp->taskId; + SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); + streamProcessDispatchRsp(pTask, pRsp); + return 0; +} + +static int32_t sndProcessTaskRecoverRsp(SSnode *pNode, SRpcMsg *pMsg) { + SStreamMeta *pMeta = pNode->pMeta; + + SStreamTaskRecoverRsp *pRsp = pMsg->pCont; + int32_t taskId = pRsp->taskId; + SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); + streamProcessRecoverRsp(pTask, pRsp); + return 0; +} + +static int32_t sndProcessTaskDropReq(SSnode *pNode, SRpcMsg *pMsg) { + SStreamMeta *pMeta = pNode->pMeta; + + char *msg = pMsg->pCont; + int32_t msgLen = pMsg->contLen; + SVDropStreamTaskReq *pReq = (SVDropStreamTaskReq *)msg; + int32_t code = taosHashRemove(pMeta->pHash, &pReq->taskId, sizeof(int32_t)); + ASSERT(code == 0); + if (code == 0) { + // sendrsp + } + return code; +} + +int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) { // stream deploy // stream stop/resume // operator exec - if (pMsg->msgType == TDMT_STREAM_TASK_DEPLOY) { - void *msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); - SStreamTask *pTask = taosMemoryMalloc(sizeof(SStreamTask)); - if (pTask == NULL) { + switch (pMsg->msgType) { + case TDMT_STREAM_TASK_DEPLOY: + return sndProcessTaskDeployReq(pSnode, pMsg); + case TDMT_STREAM_TASK_DROP: + return sndProcessTaskDropReq(pSnode, pMsg); + default: ASSERT(0); - return; - } - SDecoder decoder; - tDecoderInit(&decoder, msg, pMsg->contLen - sizeof(SMsgHead)); - tDecodeSStreamTask(&decoder, pTask); - tDecoderClear(&decoder); - - sndMetaDeployTask(pSnode->pMeta, pTask); - /*} else if (pMsg->msgType == TDMT_SND_TASK_EXEC) {*/ - /*sndProcessTaskExecReq(pSnode, pMsg);*/ - } else { - ASSERT(0); } + return 0; } -void sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg) { - // operator exec - /*if (pMsg->msgType == TDMT_SND_TASK_EXEC) {*/ - /*sndProcessTaskExecReq(pSnode, pMsg);*/ - /*} else {*/ - ASSERT(0); - /*}*/ +int32_t sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg) { + switch (pMsg->msgType) { + case TDMT_STREAM_TASK_RUN: + return sndProcessTaskRunReq(pSnode, pMsg); + case TDMT_STREAM_TASK_DISPATCH: + return sndProcessTaskDispatchReq(pSnode, pMsg); + case TDMT_STREAM_TASK_RECOVER: + return sndProcessTaskRecoverReq(pSnode, pMsg); + case TDMT_STREAM_TASK_DISPATCH_RSP: + return sndProcessTaskDispatchRsp(pSnode, pMsg); + case TDMT_STREAM_TASK_RECOVER_RSP: + return sndProcessTaskRecoverRsp(pSnode, pMsg); + default: + ASSERT(0); + } + return 0; } diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 3cfca66a39..70d89102e6 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -116,7 +116,7 @@ typedef void *tsdbReaderT; #define BLOCK_LOAD_TABLE_SEQ_ORDER 2 #define BLOCK_LOAD_TABLE_RR_ORDER 3 -tsdbReaderT *tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *tableInfoGroup, uint64_t qId, +tsdbReaderT tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *tableInfoGroup, uint64_t qId, uint64_t taskId); tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *groupList, uint64_t qId, void *pMemRef); @@ -210,12 +210,16 @@ struct SMetaEntry { struct { int64_t ctime; int32_t ttlDays; + int32_t commentLen; + char *comment; tb_uid_t suid; uint8_t *pTags; } ctbEntry; struct { int64_t ctime; int32_t ttlDays; + int32_t commentLen; + char *comment; int32_t ncid; // next column id SSchemaWrapper schemaRow; } ntbEntry; diff --git a/source/dnode/vnode/src/inc/sma.h b/source/dnode/vnode/src/inc/sma.h index 1e77022d04..902e5e1bcc 100644 --- a/source/dnode/vnode/src/inc/sma.h +++ b/source/dnode/vnode/src/inc/sma.h @@ -32,11 +32,12 @@ extern "C" { #define smaTrace(...) do { if (smaDebugFlag & DEBUG_TRACE) { taosPrintLog("SMA ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) // clang-format on -typedef struct SSmaEnv SSmaEnv; -typedef struct SSmaStat SSmaStat; -typedef struct SSmaStatItem SSmaStatItem; -typedef struct SSmaKey SSmaKey; -typedef struct SRSmaInfo SRSmaInfo; +typedef struct SSmaEnv SSmaEnv; +typedef struct SSmaStat SSmaStat; +typedef struct SSmaStatItem SSmaStatItem; +typedef struct SSmaKey SSmaKey; +typedef struct SRSmaInfo SRSmaInfo; +typedef struct SRSmaInfoItem SRSmaInfoItem; struct SSmaEnv { TdThreadRwlock lock; diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h index 2ee0673ce5..8f6077e996 100644 --- a/source/dnode/vnode/src/inc/tq.h +++ b/source/dnode/vnode/src/inc/tq.h @@ -114,6 +114,7 @@ typedef struct { char subKey[TSDB_SUBSCRIBE_KEY_LEN]; int64_t consumerId; int32_t epoch; + int8_t fetchMeta; // reader SWalReadHandle* pWalReader; diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 553c6a40ab..c0dfebb08f 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -87,6 +87,7 @@ int metaAlterSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* p int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq); int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq); int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq, SArray* tbUids); +int metaTtlDropTable(SMeta* pMeta, int64_t ttl, SArray* tbUids); int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp); SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline); STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver); @@ -105,27 +106,28 @@ int32_t metaSnapshotReaderClose(SMetaSnapshotReader* pReader); int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nData); void* metaGetIdx(SMeta* pMeta); void* metaGetIvtIdx(SMeta* pMeta); +int metaTtlSmaller(SMeta* pMeta, uint64_t time, SArray* uidList); int32_t metaCreateTSma(SMeta* pMeta, int64_t version, SSmaCfg* pCfg); int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid); // tsdb -int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg); -int tsdbClose(STsdb** pTsdb); -int32_t tsdbBegin(STsdb* pTsdb); -int32_t tsdbCommit(STsdb* pTsdb); -int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq* pMsg); -int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp); -int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, - SSubmitBlkRsp* pRsp); -int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey); -tsdbReaderT* tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, - uint64_t taskId); -tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, - void* pMemRef); -int32_t tsdbSnapshotReaderOpen(STsdb* pTsdb, STsdbSnapshotReader** ppReader, int64_t sver, int64_t ever); -int32_t tsdbSnapshotReaderClose(STsdbSnapshotReader* pReader); -int32_t tsdbSnapshotRead(STsdbSnapshotReader* pReader, void** ppData, uint32_t* nData); +int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg); +int tsdbClose(STsdb** pTsdb); +int32_t tsdbBegin(STsdb* pTsdb); +int32_t tsdbCommit(STsdb* pTsdb); +int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq* pMsg); +int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp); +int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, + SSubmitBlkRsp* pRsp); +int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey); +tsdbReaderT tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, + uint64_t taskId); +tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, + void* pMemRef); +int32_t tsdbSnapshotReaderOpen(STsdb* pTsdb, STsdbSnapshotReader** ppReader, int64_t sver, int64_t ever); +int32_t tsdbSnapshotReaderClose(STsdbSnapshotReader* pReader); +int32_t tsdbSnapshotRead(STsdbSnapshotReader* pReader, void** ppData, uint32_t* nData); // tq int tqInit(); @@ -139,7 +141,7 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessVgDeleteReq(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessOffsetCommitReq(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId); -int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); +int32_t tqProcessTaskDeployReq(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessTaskDropReq(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessStreamTrigger(STQ* pTq, SSubmitReq* data); int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg); @@ -260,7 +262,7 @@ struct SSma { #define SMA_CFG(s) (&(s)->pVnode->config) #define SMA_TSDB_CFG(s) (&(s)->pVnode->config.tsdbCfg) -#define SMA_RETENTION(s) ((SRetention *)&(s)->pVnode->config.tsdbCfg.retentions) +#define SMA_RETENTION(s) ((SRetention*)&(s)->pVnode->config.tsdbCfg.retentions) #define SMA_LOCKED(s) ((s)->locked) #define SMA_META(s) ((s)->pVnode->pMeta) #define SMA_VID(s) TD_VID((s)->pVnode) diff --git a/source/dnode/vnode/src/meta/metaEntry.c b/source/dnode/vnode/src/meta/metaEntry.c index 15ef38719f..acf5b0b613 100644 --- a/source/dnode/vnode/src/meta/metaEntry.c +++ b/source/dnode/vnode/src/meta/metaEntry.c @@ -29,12 +29,20 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) { } else if (pME->type == TSDB_CHILD_TABLE) { if (tEncodeI64(pCoder, pME->ctbEntry.ctime) < 0) return -1; if (tEncodeI32(pCoder, pME->ctbEntry.ttlDays) < 0) return -1; + if (tEncodeI32(pCoder, pME->ctbEntry.commentLen) < 0) return -1; + if (pME->ctbEntry.commentLen > 0){ + if (tEncodeCStr(pCoder, pME->ctbEntry.comment) < 0) return -1; + } if (tEncodeI64(pCoder, pME->ctbEntry.suid) < 0) return -1; debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug if (tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags) < 0) return -1; } else if (pME->type == TSDB_NORMAL_TABLE) { if (tEncodeI64(pCoder, pME->ntbEntry.ctime) < 0) return -1; if (tEncodeI32(pCoder, pME->ntbEntry.ttlDays) < 0) return -1; + if (tEncodeI32(pCoder, pME->ntbEntry.commentLen) < 0) return -1; + if (pME->ntbEntry.commentLen > 0){ + if (tEncodeCStr(pCoder, pME->ntbEntry.comment) < 0) return -1; + } if (tEncodeI32v(pCoder, pME->ntbEntry.ncid) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1; } else if (pME->type == TSDB_TSMA_TABLE) { @@ -61,12 +69,21 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { } else if (pME->type == TSDB_CHILD_TABLE) { if (tDecodeI64(pCoder, &pME->ctbEntry.ctime) < 0) return -1; if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1; + if (tDecodeI32(pCoder, &pME->ctbEntry.commentLen) < 0) return -1; + if (pME->ctbEntry.commentLen > 0){ + if (tDecodeCStr(pCoder, &pME->ctbEntry.comment) < 0) + return -1; + } if (tDecodeI64(pCoder, &pME->ctbEntry.suid) < 0) return -1; if (tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags) < 0) return -1; // (TODO) debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug } else if (pME->type == TSDB_NORMAL_TABLE) { if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1; if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1; + if (tDecodeI32(pCoder, &pME->ntbEntry.commentLen) < 0) return -1; + if (pME->ntbEntry.commentLen > 0){ + if (tDecodeCStr(pCoder, &pME->ntbEntry.comment) < 0) return -1; + } if (tDecodeI32v(pCoder, &pME->ntbEntry.ncid) < 0) return -1; if (tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1; } else if (pME->type == TSDB_TSMA_TABLE) { diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 8cfebe1b98..a5ca90e55f 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -95,7 +95,7 @@ tb_uid_t metaGetTableEntryUidByName(SMeta *pMeta, const char *name) { metaULock(pMeta); - return 0; + return uid; } int metaReadNext(SMetaReader *pReader) { @@ -218,6 +218,40 @@ _err: return NULL; } +int metaTtlSmaller(SMeta *pMeta, uint64_t ttl, SArray *uidList){ + metaRLock(pMeta); + TBC * pCur; + int ret = tdbTbcOpen(pMeta->pTtlIdx, &pCur, NULL); + if (ret < 0) { + metaULock(pMeta); + return ret; + } + + STtlIdxKey ttlKey = {0}; + ttlKey.dtime = ttl; + ttlKey.uid = INT64_MAX; + int c = 0; + tdbTbcMoveTo(pCur, &ttlKey, sizeof(ttlKey), &c); + if (c < 0) { + tdbTbcMoveToPrev(pCur); + } + + void *pKey = NULL; + int kLen = 0; + while(1){ + ret = tdbTbcPrev(pCur, &pKey, &kLen, NULL, NULL); + if (ret < 0) { + break; + } + ttlKey = *(STtlIdxKey*)pKey; + taosArrayPush(uidList, &ttlKey.uid); + } + tdbTbcClose(pCur); + + tdbFree(pKey); + return 0; +} + struct SMCtbCursor { SMeta * pMeta; TBC * pCur; diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 9a05f9e5a0..bf5d5912f9 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -320,11 +320,15 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) { if (me.type == TSDB_CHILD_TABLE) { me.ctbEntry.ctime = pReq->ctime; me.ctbEntry.ttlDays = pReq->ttl; + me.ctbEntry.commentLen = pReq->commentLen; + me.ctbEntry.comment = pReq->comment; me.ctbEntry.suid = pReq->ctb.suid; me.ctbEntry.pTags = pReq->ctb.pTag; } else { me.ntbEntry.ctime = pReq->ctime; me.ntbEntry.ttlDays = pReq->ttl; + me.ntbEntry.commentLen = pReq->commentLen; + me.ntbEntry.comment = pReq->comment; me.ntbEntry.schemaRow = pReq->ntb.schemaRow; me.ntbEntry.ncid = me.ntbEntry.schemaRow.pSchema[me.ntbEntry.schemaRow.nCols - 1].colId + 1; } @@ -359,7 +363,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi metaDropTableByUid(pMeta, uid, &type); metaULock(pMeta); - if (type == TSDB_CHILD_TABLE && tbUids) { + if ((type == TSDB_CHILD_TABLE || type == TSDB_NORMAL_TABLE) && tbUids) { taosArrayPush(tbUids, &uid); } @@ -367,16 +371,57 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi return 0; } +int metaTtlDropTable(SMeta *pMeta, int64_t ttl, SArray *tbUids) { + metaWLock(pMeta); + int ret = metaTtlSmaller(pMeta, ttl, tbUids); + if(ret != 0){ + return ret; + } + for (int i = 0; i < taosArrayGetSize(tbUids); ++i) { + tb_uid_t *uid = (tb_uid_t *)taosArrayGet(tbUids, i); + metaDropTableByUid(pMeta, *uid, NULL); + } + metaULock(pMeta); + return 0; +} + +static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME){ + int32_t ttlDays; + int64_t ctime; + if (pME->type == TSDB_CHILD_TABLE) { + ctime = pME->ctbEntry.ctime; + ttlDays = pME->ctbEntry.ttlDays; + } else if (pME->type == TSDB_NORMAL_TABLE) { + ctime = pME->ntbEntry.ctime; + ttlDays = pME->ntbEntry.ttlDays; + } else { + ASSERT(0); + } + + if (ttlDays <= 0) return; + + ttlKey->dtime = ctime / 1000 + ttlDays * 24 * 60 * 60; +// ttlKey->dtime = ctime / 1000 + ttlDays; + ttlKey->uid = pME->uid; +} + +static int metaDeleteTtlIdx(SMeta *pMeta, const SMetaEntry *pME) { + STtlIdxKey ttlKey = {0}; + metaBuildTtlIdxKey(&ttlKey, pME); + if(ttlKey.dtime == 0) return 0; + return tdbTbDelete(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), &pMeta->txn); +} + + static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { void * pData = NULL; int nData = 0; int rc = 0; - int64_t version; SMetaEntry e = {0}; SDecoder dc = {0}; rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData); - version = *(int64_t *)pData; + int64_t version = *(int64_t *)pData; tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData); @@ -388,15 +433,17 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pMeta->txn); tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn); tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn); + if(e.type != TSDB_SUPER_TABLE) metaDeleteTtlIdx(pMeta, &e); + if (e.type == TSDB_CHILD_TABLE) { tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), &pMeta->txn); } else if (e.type == TSDB_NORMAL_TABLE) { // drop schema.db (todo) - // drop ttl.idx (todo) } else if (e.type == TSDB_SUPER_TABLE) { // drop schema.db (todo) } + metaError("ttl drop table:%s", e.name); tDecoderClear(&dc); tdbFree(pData); @@ -545,16 +592,20 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl metaUpdateMetaRsp(uid, pAlterTbReq->tbName, pSchema, pMetaRsp); + if (entry.pBuf) taosMemoryFree(entry.pBuf); if (pNewSchema) taosMemoryFree(pNewSchema); - tDecoderClear(&dc); tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); + tDecoderClear(&dc); + return 0; _err: - tDecoderClear(&dc); + if (entry.pBuf) taosMemoryFree(entry.pBuf); tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); + tDecoderClear(&dc); + return -1; } @@ -706,8 +757,87 @@ _err: } static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { - // TODO - ASSERT(0); + void * pVal = NULL; + int nVal = 0; + const void * pData = NULL; + int nData = 0; + int ret = 0; + tb_uid_t uid; + int64_t oversion; + SMetaEntry entry = {0}; + int c = 0; + + // search name index + ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal); + if (ret < 0) { + terrno = TSDB_CODE_VND_TABLE_NOT_EXIST; + return -1; + } + + uid = *(tb_uid_t *)pVal; + tdbFree(pVal); + pVal = NULL; + + // search uid index + TBC *pUidIdxc = NULL; + + tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn); + tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); + ASSERT(c == 0); + + tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); + oversion = *(int64_t *)pData; + + // search table.db + TBC *pTbDbc = NULL; + + tdbTbcOpen(pMeta->pTbDb, &pTbDbc, &pMeta->txn); + tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); + ASSERT(c == 0); + tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); + + // get table entry + SDecoder dc = {0}; + entry.pBuf = taosMemoryMalloc(nData); + memcpy(entry.pBuf, pData, nData); + tDecoderInit(&dc, entry.pBuf, nData); + ret = metaDecodeEntry(&dc, &entry); + ASSERT(ret == 0); + + entry.version = version; + metaWLock(pMeta); + // build SMetaEntry + if (entry.type == TSDB_CHILD_TABLE) { + if(pAlterTbReq->updateTTL) { + metaDeleteTtlIdx(pMeta, &entry); + entry.ctbEntry.ttlDays = pAlterTbReq->newTTL; + metaUpdateTtlIdx(pMeta, &entry); + } + if(pAlterTbReq->newCommentLen >= 0) { + entry.ctbEntry.commentLen = pAlterTbReq->newCommentLen; + entry.ctbEntry.comment = pAlterTbReq->newComment; + } + } else { + if(pAlterTbReq->updateTTL) { + metaDeleteTtlIdx(pMeta, &entry); + entry.ntbEntry.ttlDays = pAlterTbReq->newTTL; + metaUpdateTtlIdx(pMeta, &entry); + } + if(pAlterTbReq->newCommentLen >= 0) { + entry.ntbEntry.commentLen = pAlterTbReq->newCommentLen; + entry.ntbEntry.comment = pAlterTbReq->newComment; + } + } + + // save to table db + metaSaveToTbDb(pMeta, &entry); + tdbTbcUpsert(pUidIdxc, &entry.uid, sizeof(tb_uid_t), &version, sizeof(version), 0); + metaULock(pMeta); + + tdbTbcClose(pTbDbc); + tdbTbcClose(pUidIdxc); + tDecoderClear(&dc); + if (entry.pBuf) taosMemoryFree(entry.pBuf); return 0; } @@ -786,25 +916,9 @@ static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) { } static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) { - int32_t ttlDays; - int64_t ctime; - STtlIdxKey ttlKey; - - if (pME->type == TSDB_CHILD_TABLE) { - ctime = pME->ctbEntry.ctime; - ttlDays = pME->ctbEntry.ttlDays; - } else if (pME->type == TSDB_NORMAL_TABLE) { - ctime = pME->ntbEntry.ctime; - ttlDays = pME->ntbEntry.ttlDays; - } else { - ASSERT(0); - } - - if (ttlDays <= 0) return 0; - - ttlKey.dtime = ctime + ttlDays * 24 * 60 * 60; - ttlKey.uid = pME->uid; - + STtlIdxKey ttlKey = {0}; + metaBuildTtlIdxKey(&ttlKey, pME); + if(ttlKey.dtime == 0) return 0; return tdbTbInsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn); } diff --git a/source/dnode/vnode/src/sma/sma.c b/source/dnode/vnode/src/sma/sma.c index b5c55a2f83..12f93f9400 100644 --- a/source/dnode/vnode/src/sma/sma.c +++ b/source/dnode/vnode/src/sma/sma.c @@ -15,6 +15,8 @@ #include "sma.h" +// functions for external invocation + // TODO: Who is responsible for resource allocate and release? int32_t tdProcessTSmaInsert(SSma* pSma, int64_t indexUid, const char* msg) { int32_t code = TSDB_CODE_SUCCESS; @@ -45,6 +47,9 @@ int32_t smaGetTSmaDays(SVnodeCfg* pCfg, void* pCont, uint32_t contLen, int32_t* return code; } + +// functions for internal invocation + #if 0 /** diff --git a/source/dnode/vnode/src/sma/smaEnv.c b/source/dnode/vnode/src/sma/smaEnv.c index f71c222772..a80af2b202 100644 --- a/source/dnode/vnode/src/sma/smaEnv.c +++ b/source/dnode/vnode/src/sma/smaEnv.c @@ -208,7 +208,6 @@ int32_t tdUnLockSma(SSma *pSma) { int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType) { SSmaEnv *pEnv = NULL; - // return if already init switch (smaType) { case TSDB_SMA_TYPE_TIME_RANGE: if ((pEnv = (SSmaEnv *)atomic_load_ptr(&SMA_TSMA_ENV(pSma)))) { @@ -244,3 +243,34 @@ int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType) { return TSDB_CODE_SUCCESS; }; + +int32_t smaTimerInit(void **timer, int8_t *initFlag, const char *label) { + int8_t old; + while (1) { + old = atomic_val_compare_exchange_8(initFlag, 0, 2); + if (old != 2) break; + } + + if (old == 0) { + *timer = taosTmrInit(10000, 100, 10000, label); + if (!(*timer)) { + atomic_store_8(initFlag, 0); + return -1; + } + atomic_store_8(initFlag, 1); + } + return 0; +} + +void smaTimerCleanUp(void *timer, int8_t *initFlag) { + int8_t old; + while (1) { + old = atomic_val_compare_exchange_8(initFlag, 1, 2); + if (old != 2) break; + } + + if (old == 1) { + taosTmrCleanUp(timer); + atomic_store_8(initFlag, 0); + } +} diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index 0c372dfa70..1f18f6cb87 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -14,14 +14,61 @@ */ #include "sma.h" +#include "tstream.h" static FORCE_INLINE int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid); static FORCE_INLINE int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids); -static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType, qTaskInfo_t *taskInfo, - STSchema *pTSchema, tb_uid_t suid, int8_t level); +static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType, SRSmaInfoItem *rsmaItem, + tb_uid_t suid, int8_t level); + +#define SET_RSMA_INFO_ITEM_PARAMS(__idx, __level) \ + if (param->qmsg[__idx]) { \ + pRSmaInfo->items[__idx].pRsmaInfo = pRSmaInfo; \ + pRSmaInfo->items[__idx].taskInfo = qCreateStreamExecTaskInfo(param->qmsg[0], &handle); \ + if (!pRSmaInfo->items[__idx].taskInfo) { \ + goto _err; \ + } \ + pRSmaInfo->items[__idx].triggerStatus = TASK_TRIGGER_STATUS__IN_ACTIVE; \ + if (param->maxdelay[__idx] < 1) { \ + int64_t msInterval = \ + convertTimeFromPrecisionToUnit(pRetention[__level].freq, pTsdbCfg->precision, TIME_UNIT_MILLISECOND); \ + pRSmaInfo->items[__idx].maxDelay = msInterval; \ + } else { \ + pRSmaInfo->items[__idx].maxDelay = param->maxdelay[__idx]; \ + } \ + if (pRSmaInfo->items[__idx].maxDelay > TSDB_MAX_ROLLUP_MAX_DELAY) { \ + pRSmaInfo->items[__idx].maxDelay = TSDB_MAX_ROLLUP_MAX_DELAY; \ + } \ + pRSmaInfo->items[__idx].level = TSDB_RETENTION_L##__level; \ + pRSmaInfo->items[__idx].tmrHandle = taosTmrInit(10000, 100, 10000, "RSMA"); \ + if (!pRSmaInfo->items[__idx].tmrHandle) { \ + goto _err; \ + } \ + } + +struct SRSmaInfoItem { + SRSmaInfo *pRsmaInfo; + void *taskInfo; // qTaskInfo_t + void *tmrHandle; + tmr_h tmrId; + int8_t level; + int8_t tmrInitFlag; + int8_t triggerStatus; // TASK_TRIGGER_STATUS__IN_ACTIVE/TASK_TRIGGER_STATUS__ACTIVE + int32_t maxDelay; +}; + +typedef struct { + int64_t suid; + SRSmaInfoItem *pItem; + SSma *pSma; + STSchema *pTSchema; +} SRSmaTriggerParam; struct SRSmaInfo { - void *taskInfo[TSDB_RETENTION_L2]; // qTaskInfo_t + STSchema *pTSchema; + SSma *pSma; + int64_t suid; + SRSmaInfoItem items[TSDB_RETENTION_L2]; }; static FORCE_INLINE void tdFreeTaskHandle(qTaskInfo_t *taskHandle) { @@ -33,11 +80,20 @@ static FORCE_INLINE void tdFreeTaskHandle(qTaskInfo_t *taskHandle) { } void *tdFreeRSmaInfo(SRSmaInfo *pInfo) { - for (int32_t i = 0; i < TSDB_RETENTION_MAX; ++i) { - if (pInfo->taskInfo[i]) { - tdFreeTaskHandle(pInfo->taskInfo[i]); + if (pInfo) { + for (int32_t i = 0; i < TSDB_RETENTION_MAX; ++i) { + SRSmaInfoItem *pItem = &pInfo->items[i]; + if (pItem->taskInfo) { + tdFreeTaskHandle(pItem->taskInfo); + } + if (pItem->tmrHandle) { + taosTmrCleanUp(pItem->tmrHandle); + } } + taosMemoryFree(pInfo->pTSchema); + taosMemoryFree(pInfo); } + return NULL; } @@ -69,20 +125,20 @@ static FORCE_INLINE int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SA return TSDB_CODE_FAILED; } - if (pRSmaInfo->taskInfo[0] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[0], tbUids, true) != 0)) { + if (pRSmaInfo->items[0].taskInfo && (qUpdateQualifiedTableId(pRSmaInfo->items[0].taskInfo, tbUids, true) < 0)) { smaError("vgId:%d, update tbUidList failed for uid:%" PRIi64 " since %s", SMA_VID(pSma), *suid, terrstr(terrno)); return TSDB_CODE_FAILED; } else { smaDebug("vgId:%d, update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, SMA_VID(pSma), - pRSmaInfo->taskInfo[0], *suid, *(int64_t *)taosArrayGet(tbUids, 0)); + pRSmaInfo->items[0].taskInfo, *suid, *(int64_t *)taosArrayGet(tbUids, 0)); } - if (pRSmaInfo->taskInfo[1] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[1], tbUids, true) != 0)) { + if (pRSmaInfo->items[1].taskInfo && (qUpdateQualifiedTableId(pRSmaInfo->items[1].taskInfo, tbUids, true) < 0)) { smaError("vgId:%d, update tbUidList failed for uid:%" PRIi64 " since %s", SMA_VID(pSma), *suid, terrstr(terrno)); return TSDB_CODE_FAILED; } else { smaDebug("vgId:%d, update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, SMA_VID(pSma), - pRSmaInfo->taskInfo[1], *suid, *(int64_t *)taosArrayGet(tbUids, 0)); + pRSmaInfo->items[1].taskInfo, *suid, *(int64_t *)taosArrayGet(tbUids, 0)); } return TSDB_CODE_SUCCESS; @@ -144,12 +200,12 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui ASSERT(ppStore != NULL); if (!(*ppStore)) { - if (tdUidStoreInit(ppStore) != 0) { + if (tdUidStoreInit(ppStore) < 0) { return TSDB_CODE_FAILED; } } - if (tdUidStorePut(*ppStore, suid, &uid) != 0) { + if (tdUidStorePut(*ppStore, suid, &uid) < 0) { *ppStore = tdUidStoreFree(*ppStore); return TSDB_CODE_FAILED; } @@ -172,11 +228,11 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) { return TSDB_CODE_SUCCESS; } - SMeta *pMeta = pVnode->pMeta; - SMsgCb *pMsgCb = &pVnode->msgCb; + SMeta *pMeta = pVnode->pMeta; + SMsgCb *pMsgCb = &pVnode->msgCb; SRSmaParam *param = &pReq->pRSmaParam; - if ((param->qmsg1Len == 0) && (param->qmsg2Len == 0)) { + if ((param->qmsgLen[0] == 0) && (param->qmsgLen[1] == 0)) { smaWarn("vgId:%d, no qmsg1/qmsg2 for rollup stable %s %" PRIi64, SMA_VID(pSma), pReq->name, pReq->suid); return TSDB_CODE_SUCCESS; } @@ -192,10 +248,12 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) { pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &pReq->suid, sizeof(tb_uid_t)); if (pRSmaInfo) { + ASSERT(0); // TODO: free original pRSmaInfo is exists abnormally smaWarn("vgId:%d, rsma info already exists for stb: %s, %" PRIi64, SMA_VID(pSma), pReq->name, pReq->suid); return TSDB_CODE_SUCCESS; } + // from write queue: single thead pRSmaInfo = (SRSmaInfo *)taosMemoryCalloc(1, sizeof(SRSmaInfo)); if (!pRSmaInfo) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -204,9 +262,8 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) { STqReadHandle *pReadHandle = tqInitSubmitMsgScanner(pMeta); if (!pReadHandle) { - taosMemoryFree(pRSmaInfo); terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_FAILED; + goto _err; } SReadHandle handle = { @@ -216,32 +273,33 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) { .vnode = pVnode, }; - if (param->qmsg1) { - pRSmaInfo->taskInfo[0] = qCreateStreamExecTaskInfo(param->qmsg1, &handle); - if (!pRSmaInfo->taskInfo[0]) { - taosMemoryFree(pRSmaInfo); - taosMemoryFree(pReadHandle); - return TSDB_CODE_FAILED; - } + STSchema *pTSchema = metaGetTbTSchema(SMA_META(pSma), pReq->suid, -1); + if (!pTSchema) { + terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION; + goto _err; } + pRSmaInfo->pTSchema = pTSchema; + pRSmaInfo->pSma = pSma; + pRSmaInfo->suid = pReq->suid; - if (param->qmsg2) { - pRSmaInfo->taskInfo[1] = qCreateStreamExecTaskInfo(param->qmsg2, &handle); - if (!pRSmaInfo->taskInfo[1]) { - taosMemoryFree(pRSmaInfo); - taosMemoryFree(pReadHandle); - return TSDB_CODE_FAILED; - } - } + SRetention *pRetention = SMA_RETENTION(pSma); + STsdbCfg *pTsdbCfg = SMA_TSDB_CFG(pSma); + + SET_RSMA_INFO_ITEM_PARAMS(0, 1); + SET_RSMA_INFO_ITEM_PARAMS(1, 2); if (taosHashPut(SMA_STAT_INFO_HASH(pStat), &pReq->suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_FAILED; + goto _err; } else { smaDebug("vgId:%d, register rsma info succeed for suid:%" PRIi64, SMA_VID(pSma), pReq->suid); } return TSDB_CODE_SUCCESS; +_err: + tdFreeRSmaInfo(pRSmaInfo); + taosMemoryFree(pReadHandle); + return TSDB_CODE_FAILED; } /** @@ -291,12 +349,12 @@ static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid) terrno = TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_FAILED; } - if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), &pUidArray, sizeof(pUidArray)) != 0) { + if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), &pUidArray, sizeof(pUidArray)) < 0) { return TSDB_CODE_FAILED; } } } else { - if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), NULL, 0) != 0) { + if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), NULL, 0) < 0) { return TSDB_CODE_FAILED; } } @@ -367,22 +425,15 @@ static int32_t tdFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) { return 0; } -static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType, qTaskInfo_t *taskInfo, - STSchema *pTSchema, tb_uid_t suid, int8_t level) { - SArray *pResult = NULL; +static int32_t tdFetchAndSubmitRSmaResult(SRSmaInfoItem *pItem, int8_t blkType) { + SArray *pResult = NULL; + SRSmaInfo *pRSmaInfo = pItem->pRsmaInfo; + SSma *pSma = pRSmaInfo->pSma; - if (!taskInfo) { - smaDebug("vgId:%d, no qTaskInfo to execute rsma %" PRIi8 " task for suid:%" PRIu64, SMA_VID(pSma), level, suid); - return TSDB_CODE_SUCCESS; - } - - smaDebug("vgId:%d, execute rsma %" PRIi8 " task for qTaskInfo:%p suid:%" PRIu64, SMA_VID(pSma), level, taskInfo, suid); - - qSetStreamInput(taskInfo, pMsg, inputType, true); while (1) { SSDataBlock *output = NULL; uint64_t ts; - if (qExecTask(taskInfo, &output, &ts) < 0) { + if (qExecTask(pItem->taskInfo, &output, &ts) < 0) { ASSERT(false); } if (!output) { @@ -402,16 +453,16 @@ static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int3 if (taosArrayGetSize(pResult) > 0) { #if 0 char flag[10] = {0}; - snprintf(flag, 10, "level %" PRIi8, level); + snprintf(flag, 10, "level %" PRIi8, pItem->level); blockDebugShowData(pResult, flag); #endif - STsdb *sinkTsdb = (level == TSDB_RETENTION_L1 ? pSma->pRSmaTsdb1 : pSma->pRSmaTsdb2); + STsdb *sinkTsdb = (pItem->level == TSDB_RETENTION_L1 ? pSma->pRSmaTsdb1 : pSma->pRSmaTsdb2); SSubmitReq *pReq = NULL; - if (buildSubmitReqFromDataBlock(&pReq, pResult, pTSchema, SMA_VID(pSma), suid) < 0) { + if (buildSubmitReqFromDataBlock(&pReq, pResult, pRSmaInfo->pTSchema, SMA_VID(pSma), pRSmaInfo->suid) < 0) { taosArrayDestroy(pResult); return TSDB_CODE_FAILED; } - + if (pReq && tdProcessSubmitReq(sinkTsdb, INT64_MAX, pReq) < 0) { taosArrayDestroy(pResult); taosMemoryFreeClear(pReq); @@ -420,10 +471,63 @@ static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int3 taosMemoryFreeClear(pReq); } else { - smaDebug("vgId:%d, no rsma % " PRIi8 " data generated since %s", SMA_VID(pSma), level, tstrerror(terrno)); + smaDebug("vgId:%d, no rsma % " PRIi8 " data generated since %s", SMA_VID(pSma), pItem->level, tstrerror(terrno)); + } + + if (blkType == STREAM_DATA_TYPE_SUBMIT_BLOCK) { + atomic_store_8(&pItem->triggerStatus, TASK_TRIGGER_STATUS__ACTIVE); } taosArrayDestroy(pResult); + return 0; +} + +/** + * @brief trigger to get rsma result + * + * @param param + * @param tmrId + */ +static void rsmaTriggerByTimer(void *param, void *tmrId) { + // SRSmaTriggerParam *pParam = (SRSmaTriggerParam *)param; + // SRSmaInfoItem *pItem = pParam->pItem; + SRSmaInfoItem *pItem = param; + + if (atomic_load_8(&pItem->triggerStatus) == TASK_TRIGGER_STATUS__ACTIVE) { + smaTrace("level %" PRIi8 " status is active for tb suid:%" PRIi64, pItem->level, pItem->pRsmaInfo->suid); + SSDataBlock dataBlock = {.info.type = STREAM_GET_ALL}; + + atomic_store_8(&pItem->triggerStatus, TASK_TRIGGER_STATUS__IN_ACTIVE); + qSetStreamInput(pItem->taskInfo, &dataBlock, STREAM_DATA_TYPE_SSDATA_BLOCK, false); + + tdFetchAndSubmitRSmaResult(pItem, STREAM_DATA_TYPE_SSDATA_BLOCK); + } else { + smaTrace("level %" PRIi8 " status is inactive for tb suid:%" PRIi64, pItem->level, pItem->pRsmaInfo->suid); + } + + // taosTmrReset(rsmaTriggerByTimer, pItem->maxDelay, pItem, pItem->tmrHandle, &pItem->tmrId); +} + +static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType, SRSmaInfoItem *pItem, + tb_uid_t suid, int8_t level) { + if (!pItem || !pItem->taskInfo) { + smaDebug("vgId:%d, no qTaskInfo to execute rsma %" PRIi8 " task for suid:%" PRIu64, SMA_VID(pSma), level, suid); + return TSDB_CODE_SUCCESS; + } + + smaDebug("vgId:%d, execute rsma %" PRIi8 " task for qTaskInfo:%p suid:%" PRIu64, SMA_VID(pSma), level, + pItem->taskInfo, suid); + + // inputType = STREAM_DATA_TYPE_SUBMIT_BLOCK(1) + if (qSetStreamInput(pItem->taskInfo, pMsg, inputType, true) < 0) { + smaError("vgId:%d, rsma % " PRIi8 " qSetStreamInput failed since %s", SMA_VID(pSma), level, tstrerror(terrno)); + return TSDB_CODE_FAILED; + } + + // SRSmaTriggerParam triggerParam = {.suid = suid, .pItem = pItem, .pSma = pSma, .pTSchema = pTSchema}; + tdFetchAndSubmitRSmaResult(pItem, STREAM_DATA_TYPE_SUBMIT_BLOCK); + atomic_store_8(&pItem->triggerStatus, TASK_TRIGGER_STATUS__ACTIVE); + taosTmrReset(rsmaTriggerByTimer, pItem->maxDelay, pItem, pItem->tmrHandle, &pItem->tmrId); return TSDB_CODE_SUCCESS; } @@ -441,24 +545,18 @@ static int32_t tdExecuteRSma(SSma *pSma, const void *pMsg, int32_t inputType, tb pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &suid, sizeof(tb_uid_t)); if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) { - smaDebug("vgId:%d, no rsma info for suid:%" PRIu64, SMA_VID(pSma), suid); + smaDebug("vgId:%d, return as no rsma info for suid:%" PRIu64, SMA_VID(pSma), suid); return TSDB_CODE_SUCCESS; } - if (!pRSmaInfo->taskInfo[0]) { - smaDebug("vgId:%d, no rsma qTaskInfo for suid:%" PRIu64, SMA_VID(pSma), suid); + + if (!pRSmaInfo->items[0].taskInfo) { + smaDebug("vgId:%d, return as no rsma qTaskInfo for suid:%" PRIu64, SMA_VID(pSma), suid); return TSDB_CODE_SUCCESS; } if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) { - // TODO: cache STSchema - STSchema *pTSchema = metaGetTbTSchema(SMA_META(pSma), suid, -1); - if (!pTSchema) { - terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION; - return TSDB_CODE_FAILED; - } - tdExecuteRSmaImpl(pSma, pMsg, inputType, pRSmaInfo->taskInfo[0], pTSchema, suid, TSDB_RETENTION_L1); - tdExecuteRSmaImpl(pSma, pMsg, inputType, pRSmaInfo->taskInfo[1], pTSchema, suid, TSDB_RETENTION_L2); - taosMemoryFree(pTSchema); + tdExecuteRSmaImpl(pSma, pMsg, inputType, &pRSmaInfo->items[0], suid, TSDB_RETENTION_L1); + tdExecuteRSmaImpl(pSma, pMsg, inputType, &pRSmaInfo->items[1], suid, TSDB_RETENTION_L2); } return TSDB_CODE_SUCCESS; diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 70b09ec701..3ce02dc50a 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -85,6 +85,34 @@ void tqClose(STQ* pTq) { } } +int32_t tqSendMetaPollRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqMetaRsp* pRsp) { + int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqMetaRsp(NULL, pRsp); + void* buf = rpcMallocCont(tlen); + if (buf == NULL) { + return -1; + } + + ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_META_RSP; + ((SMqRspHead*)buf)->epoch = pReq->epoch; + ((SMqRspHead*)buf)->consumerId = pReq->consumerId; + + void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); + tEncodeSMqMetaRsp(&abuf, pRsp); + + SRpcMsg resp = { + .info = pMsg->info, + .pCont = buf, + .contLen = tlen, + .code = 0, + }; + tmsgSendRsp(&resp); + + tqDebug("vg %d from consumer %ld (epoch %d) send rsp, res msg type %d, reqOffset: %ld, rspOffset: %ld", + TD_VID(pTq->pVnode), pReq->consumerId, pReq->epoch, pRsp->resMsgType, pRsp->reqOffset, pRsp->rspOffset); + + return 0; +} + int32_t tqSendPollRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataBlkRsp* pRsp) { int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqDataBlkRsp(NULL, pRsp); void* buf = rpcMallocCont(tlen); @@ -125,10 +153,10 @@ int32_t tqProcessOffsetCommitReq(STQ* pTq, char* msg, int32_t msgLen) { if (offset.type == TMQ_OFFSET__SNAPSHOT) { tqDebug("receive offset commit msg to %s on vg %d, offset(type:snapshot) uid: %ld, ts: %ld", offset.subKey, - pTq->pVnode->config.vgId, offset.uid, offset.ts); + TD_VID(pTq->pVnode), offset.uid, offset.ts); } else if (offset.type == TMQ_OFFSET__LOG) { tqDebug("receive offset commit msg to %s on vg %d, offset(type:log) version: %ld", offset.subKey, - pTq->pVnode->config.vgId, offset.version); + TD_VID(pTq->pVnode), offset.version); } else { ASSERT(0); } @@ -159,7 +187,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { if (pOffset != NULL) { ASSERT(pOffset->type == TMQ_OFFSET__LOG); tqDebug("consumer %ld, restore offset of %s on vg %d, offset(type:log) version: %ld", consumerId, pReq->subKey, - pTq->pVnode->config.vgId, pOffset->version); + TD_VID(pTq->pVnode), pOffset->version); fetchOffset = pOffset->version + 1; } else { if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__EARLIEAST) { @@ -167,13 +195,13 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { } else if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__LATEST) { fetchOffset = walGetCommittedVer(pTq->pWal); } else if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__NONE) { - tqError("tmq poll: no offset committed for consumer %ld in vg %d, subkey %s", consumerId, - pTq->pVnode->config.vgId, pReq->subKey); + tqError("tmq poll: no offset committed for consumer %ld in vg %d, subkey %s", consumerId, TD_VID(pTq->pVnode), + pReq->subKey); terrno = TSDB_CODE_TQ_NO_COMMITTED_OFFSET; return -1; } tqDebug("consumer %ld, restore offset of %s on vg %d failed, config is %ld, set to %ld", consumerId, pReq->subKey, - pTq->pVnode->config.vgId, pReq->currentOffset, fetchOffset); + TD_VID(pTq->pVnode), pReq->currentOffset, fetchOffset); } } @@ -183,14 +211,14 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { STqHandle* pHandle = taosHashGet(pTq->handles, pReq->subKey, strlen(pReq->subKey)); /*ASSERT(pHandle);*/ if (pHandle == NULL) { - tqError("tmq poll: no consumer handle for consumer %ld in vg %d, subkey %s", consumerId, pTq->pVnode->config.vgId, + tqError("tmq poll: no consumer handle for consumer %ld in vg %d, subkey %s", consumerId, TD_VID(pTq->pVnode), pReq->subKey); return -1; } if (pHandle->consumerId != consumerId) { tqError("tmq poll: consumer handle mismatch for consumer %ld in vg %d, subkey %s, handle consumer id %ld", - consumerId, pTq->pVnode->config.vgId, pReq->subKey, pHandle->consumerId); + consumerId, TD_VID(pTq->pVnode), pReq->subKey, pHandle->consumerId); return -1; } @@ -250,8 +278,23 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { /*ASSERT(0);*/ } } else { - // TODO - ASSERT(0); + ASSERT(pHandle->fetchMeta); + ASSERT(pHead->msgType == TDMT_VND_CREATE_STB || pHead->msgType == TDMT_VND_ALTER_STB || + pHead->msgType == TDMT_VND_DROP_STB || pHead->msgType == TDMT_VND_CREATE_TABLE || + pHead->msgType == TDMT_VND_ALTER_TABLE || pHead->msgType == TDMT_VND_DROP_TABLE || + pHead->msgType == TDMT_VND_DROP_TTL_TABLE); + // return + SMqMetaRsp metaRsp = {0}; + metaRsp.reqOffset = pReq->currentOffset; + metaRsp.rspOffset = fetchOffset; + metaRsp.resMsgType = pHead->msgType; + metaRsp.metaRspLen = pHead->bodyLen; + metaRsp.metaRsp = pHead->body; + if (tqSendMetaPollRsp(pTq, pMsg, pReq, &metaRsp) < 0) { + code = -1; + } + code = 0; + goto OVER; } // TODO batch optimization: @@ -276,7 +319,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { if (tqSendPollRsp(pTq, pMsg, pReq, &rsp) < 0) { code = -1; } - +OVER: // TODO wrap in destroy func taosArrayDestroy(rsp.blockDataLen); taosArrayDestroyP(rsp.blockData, (FDelete)taosMemoryFree); @@ -304,7 +347,6 @@ int32_t tqProcessVgDeleteReq(STQ* pTq, char* msg, int32_t msgLen) { return 0; } -// TODO: persist meta into tdb int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { SMqRebVgReq req = {0}; tDecodeSMqRebVgReq(msg, &req); @@ -334,7 +376,6 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { SReadHandle handle = { .reader = pHandle->execHandle.pExecReader[i], .meta = pTq->pVnode->pMeta, - .pMsgCb = &pTq->pVnode->msgCb, }; pHandle->execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle); ASSERT(pHandle->execHandle.execCol.task[i]); @@ -346,10 +387,10 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { pHandle->execHandle.execTb.suid = req.suid; SArray* tbUidList = taosArrayInit(0, sizeof(int64_t)); tsdbGetCtbIdList(pTq->pVnode->pMeta, req.suid, tbUidList); - tqDebug("vg %d, tq try get suid: %ld", pTq->pVnode->config.vgId, req.suid); + tqDebug("vg %d, tq try get suid: %ld", TD_VID(pTq->pVnode), req.suid); for (int32_t i = 0; i < taosArrayGetSize(tbUidList); i++) { int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i); - tqDebug("vg %d, idx %d, uid: %ld", pTq->pVnode->config.vgId, i, tbUid); + tqDebug("vg %d, idx %d, uid: %ld", TD_VID(pTq->pVnode), i, tbUid); } for (int32_t i = 0; i < 5; i++) { tqReadHandleSetTbUidList(pHandle->execHandle.pExecReader[i], tbUidList); @@ -374,7 +415,7 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { return 0; } -int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { +int32_t tqProcessTaskDeployReq(STQ* pTq, char* msg, int32_t msgLen) { SStreamTask* pTask = taosMemoryCalloc(1, sizeof(SStreamTask)); if (pTask == NULL) { return -1; @@ -386,7 +427,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { } tDecoderClear(&decoder); - pTask->status = TASK_STATUS__IDLE; + pTask->execStatus = TASK_EXEC_STATUS__IDLE; pTask->inputQueue = streamQueueOpen(); pTask->outputQueue = streamQueueOpen(); @@ -400,16 +441,20 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { // exec if (pTask->execType != TASK_EXEC__NONE) { // expand runners - STqReadHandle* pStreamReader = tqInitSubmitMsgScanner(pTq->pVnode->pMeta); - SReadHandle handle = { - .reader = pStreamReader, - .meta = pTq->pVnode->pMeta, - .pMsgCb = &pTq->pVnode->msgCb, - .vnode = pTq->pVnode, - }; - pTask->exec.inputHandle = pStreamReader; - pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle); - ASSERT(pTask->exec.executor); + if (pTask->dataScan) { + STqReadHandle* pStreamReader = tqInitSubmitMsgScanner(pTq->pVnode->pMeta); + SReadHandle handle = { + .reader = pStreamReader, + .meta = pTq->pVnode->pMeta, + .vnode = pTq->pVnode, + }; + /*pTask->exec.inputHandle = pStreamReader;*/ + pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle); + ASSERT(pTask->exec.executor); + } else { + pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, NULL); + ASSERT(pTask->exec.executor); + } } // sink @@ -431,7 +476,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { streamSetupTrigger(pTask); - tqInfo("deploy stream task id %d child id %d on vg %d", pTask->taskId, pTask->childId, pTq->pVnode->config.vgId); + tqInfo("deploy stream task id %d child id %d on vg %d", pTask->taskId, pTask->childId, TD_VID(pTq->pVnode)); taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), &pTask, sizeof(void*)); @@ -457,6 +502,9 @@ int32_t tqProcessStreamTrigger(STQ* pTq, SSubmitReq* pReq) { pIter = taosHashIterate(pTq->pStreamTasks, pIter); if (pIter == NULL) break; SStreamTask* pTask = *(SStreamTask**)pIter; + if (atomic_load_8(&pTask->taskStatus) == TASK_STATUS__DROPPING) { + continue; + } if (pTask->inputType != STREAM_INPUT__DATA_SUBMIT) continue; if (!failed) { @@ -464,7 +512,7 @@ int32_t tqProcessStreamTrigger(STQ* pTq, SSubmitReq* pReq) { continue; } - if (streamLaunchByWrite(pTask, pTq->pVnode->config.vgId, &pTq->pVnode->msgCb) < 0) { + if (streamLaunchByWrite(pTask, TD_VID(pTq->pVnode)) < 0) { continue; } } else { @@ -485,7 +533,10 @@ int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) { SStreamTaskRunReq* pReq = pMsg->pCont; int32_t taskId = pReq->taskId; SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - streamTaskProcessRunReq(pTask, &pTq->pVnode->msgCb); + if (atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) { + return 0; + } + streamProcessRunReq(pTask); return 0; } @@ -499,11 +550,14 @@ int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg) { tDecodeStreamDispatchReq(&decoder, &req); int32_t taskId = req.taskId; SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - SRpcMsg rsp = { - .info = pMsg->info, - .code = 0, + if (atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) { + return 0; + } + SRpcMsg rsp = { + .info = pMsg->info, + .code = 0, }; - streamProcessDispatchReq(pTask, &pTq->pVnode->msgCb, &req, &rsp); + streamProcessDispatchReq(pTask, &req, &rsp); return 0; } @@ -511,7 +565,10 @@ int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg) { SStreamTaskRecoverReq* pReq = pMsg->pCont; int32_t taskId = pReq->taskId; SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - streamProcessRecoverReq(pTask, &pTq->pVnode->msgCb, pReq, pMsg); + if (atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) { + return 0; + } + streamProcessRecoverReq(pTask, pReq, pMsg); return 0; } @@ -519,7 +576,10 @@ int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) { SStreamDispatchRsp* pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); int32_t taskId = pRsp->taskId; SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - streamProcessDispatchRsp(pTask, &pTq->pVnode->msgCb, pRsp); + if (atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) { + return 0; + } + streamProcessDispatchRsp(pTask, pRsp); return 0; } @@ -527,16 +587,32 @@ int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg) { SStreamTaskRecoverRsp* pRsp = pMsg->pCont; int32_t taskId = pRsp->taskId; SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) { + return 0; + } streamProcessRecoverRsp(pTask, pRsp); return 0; } int32_t tqProcessTaskDropReq(STQ* pTq, char* msg, int32_t msgLen) { SVDropStreamTaskReq* pReq = (SVDropStreamTaskReq*)msg; + + SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &pReq->taskId, sizeof(int32_t)); + atomic_store_8(&pTask->taskStatus, TASK_STATUS__DROPPING); + // todo + // clear queue + // push drop req into queue + // launch exec to free memory + // remove from hash + return 0; + +#if 0 int32_t code = taosHashRemove(pTq->pStreamTasks, &pReq->taskId, sizeof(int32_t)); + // set status dropping + ASSERT(code == 0); if (code == 0) { // sendrsp } - ASSERT(code == 0); return code; +#endif } diff --git a/source/dnode/vnode/src/tq/tqPush.c b/source/dnode/vnode/src/tq/tqPush.c index 3af8901b2b..2ec627bd5c 100644 --- a/source/dnode/vnode/src/tq/tqPush.c +++ b/source/dnode/vnode/src/tq/tqPush.c @@ -45,9 +45,9 @@ static int32_t tqLoopExecFromQueue(STQ* pTq, STqHandle* pHandle, SStreamDataSubm int32_t tqExecFromInputQ(STQ* pTq, STqHandle* pHandle) { SMqDataBlkRsp rsp = {0}; // 1. guard and set status executing - int8_t execStatus = - atomic_val_compare_exchange_8(&pHandle->pushHandle.execStatus, TASK_STATUS__IDLE, TASK_STATUS__EXECUTING); - if (execStatus == TASK_STATUS__IDLE) { + int8_t execStatus = atomic_val_compare_exchange_8(&pHandle->pushHandle.execStatus, TASK_EXEC_STATUS__IDLE, + TASK_EXEC_STATUS__EXECUTING); + if (execStatus == TASK_EXEC_STATUS__IDLE) { SStreamDataSubmit* pSubmit = NULL; // 2. check processedVer // 2.1. if not missed, get msg from queue @@ -68,18 +68,18 @@ int32_t tqExecFromInputQ(STQ* pTq, STqHandle* pHandle) { goto SEND_RSP; } // set exec status closing - atomic_store_8(&pHandle->pushHandle.execStatus, TASK_STATUS__CLOSING); + atomic_store_8(&pHandle->pushHandle.execStatus, TASK_EXEC_STATUS__CLOSING); // second run if (tqLoopExecFromQueue(pTq, pHandle, &pSubmit, &rsp) == 0) { goto SEND_RSP; } // set exec status idle - atomic_store_8(&pHandle->pushHandle.execStatus, TASK_STATUS__IDLE); + atomic_store_8(&pHandle->pushHandle.execStatus, TASK_EXEC_STATUS__IDLE); } SEND_RSP: // 4. if get result // 4.1 set exec input status blocked and exec status idle - atomic_store_8(&pHandle->pushHandle.execStatus, TASK_STATUS__IDLE); + atomic_store_8(&pHandle->pushHandle.execStatus, TASK_EXEC_STATUS__IDLE); // 4.2 rpc send rsp.rspOffset = pHandle->pushHandle.processedVer; /*if (tqSendPollRsp(pTq, pMsg, pReq, &rsp) < 0) {*/ @@ -150,7 +150,7 @@ int32_t tqEnqueueAll(STQ* pTq, SSubmitReq* pReq) { continue; } int8_t execStatus = atomic_load_8(&pHandle->pushHandle.execStatus); - if (execStatus == TASK_STATUS__IDLE || execStatus == TASK_STATUS__CLOSING) { + if (execStatus == TASK_EXEC_STATUS__IDLE || execStatus == TASK_EXEC_STATUS__CLOSING) { tqSendExecReq(pTq, pHandle); } } diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index 0c38d6442b..6f44eb4569 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -42,6 +42,25 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalHead* code = 0; goto END; } else { + if (pHandle->fetchMeta) { + SWalReadHead* pHead = &((*ppHeadWithCkSum)->head); + if (pHead->msgType == TDMT_VND_CREATE_STB || pHead->msgType == TDMT_VND_ALTER_STB || + pHead->msgType == TDMT_VND_DROP_STB || pHead->msgType == TDMT_VND_CREATE_TABLE || + pHead->msgType == TDMT_VND_ALTER_TABLE || pHead->msgType == TDMT_VND_DROP_TABLE || + pHead->msgType == TDMT_VND_DROP_TTL_TABLE) { + code = walFetchBody(pHandle->pWalReader, ppHeadWithCkSum); + + if (code < 0) { + ASSERT(0); + *fetchOffset = offset; + code = -1; + goto END; + } + *fetchOffset = offset; + code = 0; + goto END; + } + } code = walSkipFetchBody(pHandle->pWalReader, *ppHeadWithCkSum); if (code < 0) { ASSERT(0); diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index e7a40eeeb9..ce73246e51 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -500,7 +500,7 @@ static int32_t setCurrentSchema(SVnode* pVnode, STsdbReadHandle* pTsdbReadHandle return TSDB_CODE_SUCCESS; } -tsdbReaderT* tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, +tsdbReaderT tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, uint64_t taskId) { STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(pVnode, pCond, qId, taskId); if (pTsdbReadHandle == NULL) { @@ -508,7 +508,7 @@ tsdbReaderT* tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, STableLi } if (emptyQueryTimewindow(pTsdbReadHandle)) { - return (tsdbReaderT*)pTsdbReadHandle; + return (tsdbReaderT)pTsdbReadHandle; } // todo apply the lastkey of table check to avoid to load header file diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index feb8419bdf..b5a2da091f 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -26,6 +26,7 @@ static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void * static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRpcMsg *pRsp); +static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) { int32_t code = 0; @@ -134,6 +135,9 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp case TDMT_VND_DROP_TABLE: if (vnodeProcessDropTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; break; + case TDMT_VND_DROP_TTL_TABLE: + if (vnodeProcessDropTtlTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; + break; case TDMT_VND_CREATE_SMA: { if (vnodeProcessCreateTSmaReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; } break; @@ -163,12 +167,12 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp } break; case TDMT_STREAM_TASK_DEPLOY: { - if (tqProcessTaskDeploy(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), - pMsg->contLen - sizeof(SMsgHead)) < 0) { + if (tqProcessTaskDeployReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), + pMsg->contLen - sizeof(SMsgHead)) < 0) { goto _err; } } break; - case TDMT_VND_STREAM_TASK_DROP: { + case TDMT_STREAM_TASK_DROP: { if (tqProcessTaskDropReq(pVnode->pTq, pMsg->pCont, pMsg->contLen) < 0) { goto _err; } @@ -300,6 +304,25 @@ void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) { pMetaRsp->precision = pVnode->config.tsdbCfg.precision; } +static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { + SArray *tbUids = taosArrayInit(8, sizeof(int64_t)); + if (tbUids == NULL) return TSDB_CODE_OUT_OF_MEMORY; + + int32_t t = ntohl(*(int32_t *)pReq); + vError("rec ttl time:%d", t); + int32_t ret = metaTtlDropTable(pVnode->pMeta, t, tbUids); + if (ret != 0) { + goto end; + } + if (taosArrayGetSize(tbUids) > 0) { + tqUpdateTbUidList(pVnode->pTq, tbUids, false); + } + +end: + taosArrayDestroy(tbUids); + return ret; +} + static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { SVCreateStbReq req = {0}; SDecoder coder; @@ -322,7 +345,10 @@ static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *p goto _err; } - tdProcessRSmaCreate(pVnode, &req); + if (tdProcessRSmaCreate(pVnode, &req) < 0) { + pRsp->code = terrno; + goto _err; + } tDecoderClear(&coder); return 0; diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c index ae61aa454e..32090b774e 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -119,7 +119,7 @@ static int32_t vnodeProcessAlterReplicaReq(SVnode *pVnode, SRpcMsg *pMsg) { } void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { - SVnode * pVnode = pInfo->ahandle; + SVnode *pVnode = pInfo->ahandle; int32_t vgId = pVnode->config.vgId; int32_t code = 0; SRpcMsg *pMsg = NULL; @@ -174,7 +174,7 @@ void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { } void vnodeApplyMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { - SVnode * pVnode = pInfo->ahandle; + SVnode *pVnode = pInfo->ahandle; int32_t vgId = pVnode->config.vgId; int32_t code = 0; SRpcMsg *pMsg = NULL; @@ -211,21 +211,23 @@ int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync); assert(pSyncNode != NULL); - ESyncState state = syncGetMyRole(pVnode->sync); - SyncTerm currentTerm = syncGetMyTerm(pVnode->sync); - SMsgHead *pHead = pMsg->pCont; + STraceId *trace = &pMsg->info.traceId; - char logBuf[512] = {0}; - char *syncNodeStr = sync2SimpleStr(pVnode->sync); - snprintf(logBuf, sizeof(logBuf), "==vnodeProcessSyncReq== msgType:%d, syncNode: %s", pMsg->msgType, syncNodeStr); - static int64_t vndTick = 0; - STraceId * trace = &pMsg->info.traceId; - if (++vndTick % 10 == 1) { - vGTrace("sync trace msg:%s, %s", TMSG_INFO(pMsg->msgType), syncNodeStr); - } - syncRpcMsgLog2(logBuf, pMsg); - taosMemoryFree(syncNodeStr); + do { + char *syncNodeStr = sync2SimpleStr(pVnode->sync); + static int64_t vndTick = 0; + if (++vndTick % 10 == 1) { + vGTrace("vgId:%d, sync heartbeat msg:%s, %s", syncGetVgId(pVnode->sync), TMSG_INFO(pMsg->msgType), syncNodeStr); + } + if (gRaftDetailLog) { + char logBuf[512] = {0}; + snprintf(logBuf, sizeof(logBuf), "==vnodeProcessSyncReq== msgType:%d, syncNode: %s", pMsg->msgType, + syncNodeStr); + syncRpcMsgLog2(logBuf, pMsg); + } + taosMemoryFree(syncNodeStr); + } while (0); SRpcMsg *pRpcMsg = pMsg; @@ -334,7 +336,7 @@ static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReCon SVnode *pVnode = pFsm->data; SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen}; - syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info); + syncGetAndDelRespRpc(pVnode->sync, cbMeta.newCfgSeqNum, &rpcMsg.info); rpcMsg.info.conn.applyIndex = cbMeta.index; STraceId *trace = (STraceId *)&pMsg->info.traceId; @@ -348,13 +350,13 @@ static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReCon } static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { - SVnode * pVnode = pFsm->data; + SVnode *pVnode = pFsm->data; SSnapshot snapshot = {0}; SyncIndex beginIndex = SYNC_INDEX_INVALID; char logBuf[256] = {0}; - if (pFsm->FpGetSnapshot != NULL) { - (*pFsm->FpGetSnapshot)(pFsm, &snapshot); + if (pFsm->FpGetSnapshotInfo != NULL) { + (*pFsm->FpGetSnapshotInfo)(pFsm, &snapshot); beginIndex = snapshot.lastApplyIndex; } @@ -416,7 +418,7 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) { pFsm->FpCommitCb = vnodeSyncCommitMsg; pFsm->FpPreCommitCb = vnodeSyncPreCommitMsg; pFsm->FpRollBackCb = vnodeSyncRollBackMsg; - pFsm->FpGetSnapshot = vnodeSyncGetSnapshot; + pFsm->FpGetSnapshotInfo = vnodeSyncGetSnapshot; pFsm->FpRestoreFinishCb = NULL; pFsm->FpReConfigCb = vnodeSyncReconfig; pFsm->FpSnapshotStartRead = vnodeSnapshotStartRead; diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index bb02895569..ce2456d8c3 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -1121,6 +1121,10 @@ _return: CTG_API_LEAVE(TSDB_CODE_SUCCESS); } +int32_t catalogGetDnodeList(SCatalog* pCatalog, SRequestConnInfo* pConn, SArray** pDnodeList) { + return TSDB_CODE_CTG_INVALID_INPUT; +} + int32_t catalogGetExpiredSTables(SCatalog* pCtg, SSTableVersion **stables, uint32_t *num) { CTG_API_ENTER(); diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index c6a0e52a42..6a3852abbc 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -131,6 +131,8 @@ static int32_t execShowCreateSTable(SShowCreateTableStmt* pStmt) { return TSDB_C static int32_t execAlterLocal(SAlterLocalStmt* pStmt) { return TSDB_CODE_FAILED; } +static int32_t execShowLocalVariables() { return TSDB_CODE_FAILED; } + int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp) { switch (nodeType(pStmt)) { case QUERY_NODE_DESCRIBE_STMT: @@ -145,6 +147,8 @@ int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp) { return execShowCreateSTable((SShowCreateTableStmt*)pStmt); case QUERY_NODE_ALTER_LOCAL_STMT: return execAlterLocal((SAlterLocalStmt*)pStmt); + case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: + return execShowLocalVariables(); default: break; } diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 8f91282480..ae0f669d65 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -412,6 +412,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); } + EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pTblScanNode->scan.pScanCols->length); EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pTblScanNode->scan.node.pOutputDataBlockDesc->totalRowSize); @@ -426,27 +427,57 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i EXPLAIN_ROW_NEW(level + 1, "I/O: "); int32_t nodeNum = taosArrayGetSize(pResNode->pExecInfo); - for (int32_t i = 0; i < nodeNum; ++i) { + struct STableScanAnalyzeInfo info = {0}; + + int32_t maxIndex = 0; + int32_t totalRows = 0; + for(int32_t i = 0; i < nodeNum; ++i) { SExplainExecInfo *execInfo = taosArrayGet(pResNode->pExecInfo, i); STableScanAnalyzeInfo *pScanInfo = (STableScanAnalyzeInfo *)execInfo->verboseInfo; - EXPLAIN_ROW_APPEND("total_blocks=%d", pScanInfo->totalBlocks); - EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + info.totalBlocks += pScanInfo->totalBlocks; + info.loadBlocks += pScanInfo->loadBlocks; + info.totalRows += pScanInfo->totalRows; + info.skipBlocks += pScanInfo->skipBlocks; + info.filterTime += pScanInfo->filterTime; + info.loadBlockStatis += pScanInfo->loadBlockStatis; + info.totalCheckedRows += pScanInfo->totalCheckedRows; + info.filterOutBlocks += pScanInfo->filterOutBlocks; - EXPLAIN_ROW_APPEND("load_blocks=%d", pScanInfo->loadBlocks); - EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); - - EXPLAIN_ROW_APPEND("load_block_SMAs=%d", pScanInfo->loadBlockStatis); - EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); - - EXPLAIN_ROW_APPEND("total_rows=%" PRIu64, pScanInfo->totalRows); - EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); - - EXPLAIN_ROW_APPEND("check_rows=%" PRIu64, pScanInfo->totalCheckedRows); - EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + if (pScanInfo->totalRows > totalRows) { + totalRows = pScanInfo->totalRows; + maxIndex = i; + } } + EXPLAIN_ROW_APPEND("total_blocks=%.1f", ((double)info.totalBlocks) / nodeNum); + EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + + EXPLAIN_ROW_APPEND("load_blocks=%.1f", ((double)info.loadBlocks) / nodeNum); + EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + + EXPLAIN_ROW_APPEND("load_block_SMAs=%.1f", ((double)info.loadBlockStatis) / nodeNum); + EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + + EXPLAIN_ROW_APPEND("total_rows=%.1f", ((double)info.totalRows) / nodeNum); + EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + + EXPLAIN_ROW_APPEND("check_rows=%.1f", ((double)info.totalCheckedRows) / nodeNum); + EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); EXPLAIN_ROW_END(); + + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + + //Rows out: Avg 4166.7 rows x 24 workers. Max 4187 rows (seg7) with 0.220 ms to first row, 1.738 ms to end, start offset by 1.470 ms. + SExplainExecInfo *execInfo = taosArrayGet(pResNode->pExecInfo, maxIndex); + STableScanAnalyzeInfo *p1 = (STableScanAnalyzeInfo *)execInfo->verboseInfo; + + EXPLAIN_ROW_NEW(level + 1, " "); + EXPLAIN_ROW_APPEND("max_row_task=%d, total_rows:%" PRId64 ", ep:%s (cost=%.3f..%.3f)", maxIndex, p1->totalRows, "tbd", + execInfo->startupCost, execInfo->totalCost); + EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); } @@ -631,8 +662,8 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); } - if (pIndefNode->pVectorFuncs) { - EXPLAIN_ROW_APPEND(EXPLAIN_FUNCTIONS_FORMAT, pIndefNode->pVectorFuncs->length); + if (pIndefNode->pFuncs) { + EXPLAIN_ROW_APPEND(EXPLAIN_FUNCTIONS_FORMAT, pIndefNode->pFuncs->length); EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); } EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pIndefNode->node.pOutputDataBlockDesc->totalRowSize); diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h index 07686893db..f3e1eb47e8 100644 --- a/source/libs/executor/inc/executil.h +++ b/source/libs/executor/inc/executil.h @@ -106,7 +106,8 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo); SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode); -int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo, SNode* pTagCond); +EDealRes doTranslateTagExpr(SNode** pNode, void* pContext); +int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo); SArray* createSortInfo(SNodeList* pNodeList); SArray* extractPartitionColInfo(SNodeList* pNodeList); SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols, int32_t type); @@ -114,7 +115,7 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* numOfExprs); SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowEntryInfoOffset); -void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols); +void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols, bool outputEveryColumn); void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow); SInterval extractIntervalInfo(const STableScanPhysiNode* pTableScanNode); @@ -123,4 +124,6 @@ SColumn extractColumnFromColumnNode(SColumnNode* pColNode); int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysiNode* pTableScanNode); void cleanupQueryTableDataCond(SQueryTableDataCond* pCond); +int32_t convertFillType(int32_t mode); + #endif // TDENGINE_QUERYUTIL_H diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 28241d778c..0ceb2e8aa1 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -282,7 +282,6 @@ typedef struct STagScanInfo { int32_t curPos; SReadHandle readHandle; STableListInfo *pTableList; - SNode* pFilterNode; // filter info, } STagScanInfo; typedef enum EStreamScanMode { @@ -369,6 +368,8 @@ typedef struct SSysTableScanInfo { typedef struct SBlockDistInfo { SSDataBlock* pResBlock; void* pHandle; + SReadHandle readHandle; + uint64_t uid; // table uid } SBlockDistInfo; // todo remove this @@ -423,6 +424,7 @@ typedef struct SStreamFinalIntervalOperatorInfo { SArray* pChildren; SSDataBlock* pUpdateRes; SPhysiNode* pPhyNode; // create new child + bool isFinal; } SStreamFinalIntervalOperatorInfo; typedef struct SAggOperatorInfo { @@ -503,7 +505,8 @@ typedef struct SPartitionOperatorInfo { SDiskbasedBuf* pBuf; // query result buffer based on blocked-wised disk file int32_t rowCapacity; // maximum number of rows for each buffer page int32_t* columnOffset; // start position for each column data - void* pGroupIter; // group iterator + SArray* sortedGroupArray; // SDataGroupInfo sorted by group id + int32_t groupIndex; // group index int32_t pageIndex; // page index of current group SSDataBlock* pUpdateRes; SExprSupp scalarSup; @@ -547,24 +550,29 @@ typedef struct SStreamSessionAggOperatorInfo { SGroupResInfo groupResInfo; int64_t gap; // session window gap int32_t primaryTsIndex; // primary timestamp slot id + int32_t endTsIndex; // window end timestamp slot id int32_t order; // current SSDataBlock scan order STimeWindowAggSupp twAggSup; SSDataBlock* pWinBlock; // window result SqlFunctionCtx* pDummyCtx; // for combine - SSDataBlock* pDelRes; + SSDataBlock* pDelRes; // delete result + SSDataBlock* pUpdateRes; // update window SHashObj* pStDeleted; void* pDelIterator; SArray* pChildren; // cache for children's result; final stream operator + SPhysiNode* pPhyNode; // create new child + bool isFinal; } SStreamSessionAggOperatorInfo; typedef struct STimeSliceOperatorInfo { - SOptrBasicInfo binfo; + SSDataBlock* pRes; STimeWindow win; SInterval interval; int64_t current; SArray* pPrevRow; // SArray - SArray* pCols; // SArray int32_t fillType; // fill type + SColumn tsCol; // primary timestamp column + SExprSupp scalarSup; // scalar calculation struct SFillColInfo* pFillColInfo; // fill column info } STimeSliceOperatorInfo; @@ -662,7 +670,7 @@ int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock); void cleanupBasicInfo(SOptrBasicInfo* pInfo); -void initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr); +int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr); void cleanupExprSup(SExprSupp* pSup); int32_t initAggInfo(SExprSupp *pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize, const char* pkey); @@ -735,7 +743,8 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SNode* pCondition, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* readHandle, uint64_t uid, SBlockDistScanPhysiNode* pBlockScanNode, + SExecTaskInfo* pTaskInfo); SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHandle, STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo, STimeWindowAggSupp* pTwSup); @@ -748,8 +757,8 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartitionPhysiNode* pPartNode, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResultBlock, const SNodeListNode* pValNode, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pNode, /*SExprInfo* pExprInfo, int32_t numOfCols, + SSDataBlock* pResultBlock, const SNodeListNode* pValNode, */SExecTaskInfo* pTaskInfo); SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SJoinPhysiNode* pJoinNode, SExecTaskInfo* pTaskInfo); @@ -813,10 +822,10 @@ int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order); int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t size); SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, int32_t interBufSize); -SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY ts, uint64_t groupId, int64_t gap, int32_t* pIndex); -int32_t updateSessionWindowInfo(SResultWindowInfo* pWinInfo, TSKEY* pTs, int32_t rows, int32_t start, int64_t gap, - SHashObj* pStDeleted); - +SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, + TSKEY endTs, uint64_t groupId, int64_t gap, int32_t* pIndex); +int32_t updateSessionWindowInfo(SResultWindowInfo* pWinInfo, TSKEY* pStartTs, + TSKEY* pEndTs, int32_t rows, int32_t start, int64_t gap, SHashObj* pStDeleted); bool functionNeedToExecute(SqlFunctionCtx* pCtx); int32_t compareTimeWindow(const void* p1, const void* p2, const void* param); @@ -826,7 +835,7 @@ int32_t finalizeResultRowIntoResultDataBlock(SDiskbasedBuf* pBuf, SResultRowPosi int32_t createMultipleDataReaders(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, STableListInfo* pTableListInfo, SArray* arrayReader, uint64_t queryId, - uint64_t taskId, SNode* pTagCond); + uint64_t taskId); SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SArray* dataReaders, SReadHandle* readHandle, SExecTaskInfo* pTaskInfo); diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index b7c7102143..802f9ea5b5 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -75,12 +75,18 @@ static bool needCompress(const SSDataBlock* pData, int32_t numOfCols) { // The length of bitmap is decided by number of rows of this data block, and the length of each column data is // recorded in the first segment, next to the struct header static void toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pInput, SDataDispatchBuf* pBuf) { - int32_t numOfCols = LIST_LENGTH(pHandle->pSchema->pSlots); - + int32_t numOfCols = 0; + SNode* pNode; + FOREACH(pNode, pHandle->pSchema->pSlots) { + SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode; + if (pSlotDesc->output) { + ++numOfCols; + } + } SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData; pEntry->compressed = (int8_t)needCompress(pInput->pData, numOfCols); pEntry->numOfRows = pInput->pData->info.rows; - pEntry->numOfCols = pInput->pData->info.numOfCols; + pEntry->numOfCols = numOfCols; pEntry->dataLen = 0; pBuf->useSize = sizeof(SDataCacheEntry); diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 99139be409..40e85613b2 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -193,9 +193,9 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) { for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData idata = {{0}}; SSlotDescNode* pDescNode = (SSlotDescNode*)nodesListGetNode(pNode->pSlots, i); - // if (!pDescNode->output) { // todo disable it temporarily - // continue; - // } +// if (!pDescNode->output) { // todo disable it temporarily +// continue; +// } idata.info.type = pDescNode->dataType.type; idata.info.bytes = pDescNode->dataType.bytes; @@ -214,21 +214,104 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) { return pBlock; } -int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo, SNode* pTagCond) { +EDealRes doTranslateTagExpr(SNode** pNode, void* pContext) { + SMetaReader* mr = (SMetaReader*)pContext; + if(nodeType(*pNode) == QUERY_NODE_COLUMN){ + SColumnNode* pSColumnNode = *(SColumnNode**)pNode; + + SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); + if (NULL == res) { + return DEAL_RES_ERROR; + } + + res->translate = true; + res->node.resType = pSColumnNode->node.resType; + + STagVal tagVal = {0}; + tagVal.cid = pSColumnNode->colId; + const char* p = metaGetTableTagVal(&mr->me, pSColumnNode->node.resType.type, &tagVal); + if (p == NULL) { + res->node.resType.type = TSDB_DATA_TYPE_NULL; + }else if (pSColumnNode->node.resType.type == TSDB_DATA_TYPE_JSON) { + int32_t len = ((const STag*)p) -> len; + res->datum.p = taosMemoryCalloc(len + 1, 1); + memcpy(res->datum.p, p, len); + } else if (IS_VAR_DATA_TYPE(pSColumnNode->node.resType.type)) { + res->datum.p = taosMemoryCalloc(tagVal.nData + VARSTR_HEADER_SIZE + 1, 1); + memcpy(varDataVal(res->datum.p), tagVal.pData, tagVal.nData); + varDataSetLen(res->datum.p, tagVal.nData); + } else { + nodesSetValueNodeValue(res, &(tagVal.i64)); + } + nodesDestroyNode(*pNode); + *pNode = (SNode*)res; + }else if (nodeType(*pNode) == QUERY_NODE_FUNCTION){ + SFunctionNode * pFuncNode = *(SFunctionNode**)pNode; + if(pFuncNode->funcType == FUNCTION_TYPE_TBNAME){ + SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); + if (NULL == res) { + return DEAL_RES_ERROR; + } + + res->translate = true; + res->node.resType = pFuncNode->node.resType; + + int32_t len = strlen(mr->me.name); + res->datum.p = taosMemoryCalloc(len + VARSTR_HEADER_SIZE + 1, 1); + memcpy(varDataVal(res->datum.p), mr->me.name, len); + varDataSetLen(res->datum.p, len); + nodesDestroyNode(*pNode); + *pNode = (SNode*)res; + } + } + + return DEAL_RES_CONTINUE; +} + +static bool isTableOk(STableKeyInfo* info, SNode *pTagCond, SMeta *metaHandle){ + SMetaReader mr = {0}; + metaReaderInit(&mr, metaHandle, 0); + metaGetTableEntryByUid(&mr, info->uid); + + SNode *pTagCondTmp = nodesCloneNode(pTagCond); + + nodesRewriteExprPostOrder(&pTagCondTmp, doTranslateTagExpr, &mr); + metaReaderClear(&mr); + + SNode* pNew = NULL; + int32_t code = scalarCalculateConstants(pTagCondTmp, &pNew); + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyNode(pTagCondTmp); + return false; + } + + ASSERT(nodeType(pNew) == QUERY_NODE_VALUE); + SValueNode *pValue = (SValueNode *)pNew; + + ASSERT(pValue->node.resType.type == TSDB_DATA_TYPE_BOOL); + bool result = pValue->datum.b; + nodesDestroyNode(pNew); + return result; +} + +int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo) { int32_t code = TSDB_CODE_SUCCESS; pListInfo->pTableList = taosArrayInit(8, sizeof(STableKeyInfo)); uint64_t tableUid = pScanNode->uid; + SNode* pTagCond = (SNode*)pListInfo->pTagCond; + SNode* pTagIndexCond = (SNode*)pListInfo->pTagIndexCond; if (pScanNode->tableType == TSDB_SUPER_TABLE) { - if (pTagCond) { + if (pTagIndexCond) { SIndexMetaArg metaArg = { .metaEx = metaHandle, .idx = tsdbGetIdx(metaHandle), .ivtIdx = tsdbGetIvtIdx(metaHandle), .suid = tableUid}; SArray* res = taosArrayInit(8, sizeof(uint64_t)); - code = doFilterTag(pTagCond, &metaArg, res); - if (code == TSDB_CODE_INDEX_REBUILDING) { // todo - // doFilter(); + //code = doFilterTag(pTagIndexCond, &metaArg, res); + code = TSDB_CODE_INDEX_REBUILDING; + if (code == TSDB_CODE_INDEX_REBUILDING) { + code = tsdbGetAllTableList(metaHandle, tableUid, pListInfo->pTableList); } else if (code != TSDB_CODE_SUCCESS) { qError("failed to get tableIds, reason: %s, suid: %" PRIu64 "", tstrerror(code), tableUid); taosArrayDestroy(res); @@ -246,7 +329,20 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo } else { code = tsdbGetAllTableList(metaHandle, tableUid, pListInfo->pTableList); } - } else { // Create one table group. + + if(pTagCond){ + int32_t i = 0; + while(i < taosArrayGetSize(pListInfo->pTableList)) { + STableKeyInfo* info = taosArrayGet(pListInfo->pTableList, i); + bool isOk = isTableOk(info, pTagCond, metaHandle); + if(!isOk){ + taosArrayRemove(pListInfo->pTableList, i); + continue; + } + i++; + } + } + }else { // Create one table group. STableKeyInfo info = {.lastKey = 0, .uid = tableUid}; taosArrayPush(pListInfo->pTableList, &info); } @@ -319,7 +415,14 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod continue; } - SColMatchInfo* info = taosArrayGet(pList, pNode->slotId); + SColMatchInfo* info = NULL; + for (int32_t j = 0; j < taosArrayGetSize(pList); ++j) { + info = taosArrayGet(pList, j); + if (info->targetSlotId == pNode->slotId) { + break; + } + } + if (pNode->output) { (*numOfOutputCols) += 1; } else { @@ -578,14 +681,15 @@ SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, } // NOTE: sources columns are more than the destination SSDatablock columns. -void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols) { +// doFilter in table scan needs every column even its output is false +void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols, bool outputEveryColumn) { size_t numOfSrcCols = taosArrayGetSize(pCols); int32_t i = 0, j = 0; while (i < numOfSrcCols && j < taosArrayGetSize(pColMatchInfo)) { SColumnInfoData* p = taosArrayGet(pCols, i); SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, j); - if (!pmInfo->output) { + if (!outputEveryColumn && !pmInfo->output) { j++; continue; } @@ -686,4 +790,32 @@ int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysi void cleanupQueryTableDataCond(SQueryTableDataCond* pCond) { taosMemoryFree(pCond->twindows); taosMemoryFree(pCond->colList); -} \ No newline at end of file +} + +int32_t convertFillType(int32_t mode) { + int32_t type = TSDB_FILL_NONE; + switch (mode) { + case FILL_MODE_PREV: + type = TSDB_FILL_PREV; + break; + case FILL_MODE_NONE: + type = TSDB_FILL_NONE; + break; + case FILL_MODE_NULL: + type = TSDB_FILL_NULL; + break; + case FILL_MODE_NEXT: + type = TSDB_FILL_NEXT; + break; + case FILL_MODE_VALUE: + type = TSDB_FILL_SET_VALUE; + break; + case FILL_MODE_LINEAR: + type = TSDB_FILL_LINEAR; + break; + default: + type = TSDB_FILL_NONE; + } + + return type; +} diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index b1d076e8f5..cf72dfd796 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -41,12 +41,18 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu pInfo->assignBlockUid = assignUid; // the block type can not be changed in the streamscan operators +#if 0 if (pInfo->blockType == 0) { pInfo->blockType = type; } else if (pInfo->blockType != type) { ASSERT(0); return TSDB_CODE_QRY_APP_ERROR; } +#endif + // rollup sma, the same qTaskInfo is used to insert data by SubmitReq and fetch result by SSDataBlock + if (pInfo->blockType != type) { + pInfo->blockType = type; + } if (type == STREAM_DATA_TYPE_SUBMIT_BLOCK) { if (tqReadHandleSetMsg(pInfo->streamBlockReader, input, 0) < 0) { @@ -99,7 +105,7 @@ int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numO } qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle) { - if (msg == NULL || streamReadHandle == NULL) { + if (msg == NULL) { return NULL; } diff --git a/source/libs/executor/src/executorMain.c b/source/libs/executor/src/executorMain.c index ff281dacbd..a9e1e03178 100644 --- a/source/libs/executor/src/executorMain.c +++ b/source/libs/executor/src/executorMain.c @@ -13,10 +13,10 @@ * along with this program. If not, see . */ -#include "os.h" -#include "tref.h" #include "dataSinkMgt.h" +#include "os.h" #include "tmsg.h" +#include "tref.h" #include "tudf.h" #include "executor.h" @@ -24,15 +24,13 @@ #include "query.h" static TdThreadOnce initPoolOnce = PTHREAD_ONCE_INIT; -int32_t exchangeObjRefPool = -1; +int32_t exchangeObjRefPool = -1; -static void initRefPool() { - exchangeObjRefPool = taosOpenRef(1024, doDestroyExchangeOperatorInfo); -} +static void initRefPool() { exchangeObjRefPool = taosOpenRef(1024, doDestroyExchangeOperatorInfo); } int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SSubplan* pSubplan, qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, const char* sql, EOPTR_EXEC_MODEL model) { - assert(readHandle != NULL && pSubplan != NULL); + assert(pSubplan != NULL); SExecTaskInfo** pTask = (SExecTaskInfo**)pTaskInfo; taosThreadOnce(&initPoolOnce, initRefPool); @@ -47,57 +45,57 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, if (code != TSDB_CODE_SUCCESS) { goto _error; } - + if (handle) { void* pSinkParam = NULL; code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, pTaskInfo); if (code != TSDB_CODE_SUCCESS) { goto _error; } - + code = dsCreateDataSinker(pSubplan->pDataSink, handle, pSinkParam); } - _error: +_error: // if failed to add ref for all tables in this query, abort current query return code; } #ifdef TEST_IMPL // wait moment -int waitMoment(SQInfo* pQInfo){ - if(pQInfo->sql) { - int ms = 0; +int waitMoment(SQInfo* pQInfo) { + if (pQInfo->sql) { + int ms = 0; char* pcnt = strstr(pQInfo->sql, " count(*)"); - if(pcnt) return 0; - + if (pcnt) return 0; + char* pos = strstr(pQInfo->sql, " t_"); - if(pos){ + if (pos) { pos += 3; ms = atoi(pos); - while(*pos >= '0' && *pos <= '9'){ - pos ++; + while (*pos >= '0' && *pos <= '9') { + pos++; } char unit_char = *pos; - if(unit_char == 'h'){ - ms *= 3600*1000; - } else if(unit_char == 'm'){ - ms *= 60*1000; - } else if(unit_char == 's'){ + if (unit_char == 'h') { + ms *= 3600 * 1000; + } else if (unit_char == 'm') { + ms *= 60 * 1000; + } else if (unit_char == 's') { ms *= 1000; } } - if(ms == 0) return 0; + if (ms == 0) return 0; printf("test wait sleep %dms. sql=%s ...\n", ms, pQInfo->sql); - - if(ms < 1000) { + + if (ms < 1000) { taosMsleep(ms); } else { int used_ms = 0; - while(used_ms < ms) { + while (used_ms < ms) { taosMsleep(1000); used_ms += 1000; - if(isTaskKilled(pQInfo)){ + if (isTaskKilled(pQInfo)) { printf("test check query is canceled, sleep break.%s\n", pQInfo->sql); break; } @@ -108,15 +106,14 @@ int waitMoment(SQInfo* pQInfo){ } #endif -int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) { +int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds) { SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; int64_t threadId = taosGetSelfPthreadId(); *pRes = NULL; int64_t curOwner = 0; if ((curOwner = atomic_val_compare_exchange_64(&pTaskInfo->owner, 0, threadId)) != 0) { - qError("%s-%p execTask is now executed by thread:%p", GET_TASKID(pTaskInfo), pTaskInfo, - (void*)curOwner); + qError("%s-%p execTask is now executed by thread:%p", GET_TASKID(pTaskInfo), pTaskInfo, (void*)curOwner); pTaskInfo->code = TSDB_CODE_QRY_IN_EXEC; return pTaskInfo->code; } @@ -152,18 +149,18 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) { cleanUpUdfs(); - int32_t current = (*pRes != NULL)? (*pRes)->info.rows:0; + int32_t current = (*pRes != NULL) ? (*pRes)->info.rows : 0; uint64_t total = pTaskInfo->pRoot->resultInfo.totalRows; qDebug("%s task suspended, %d rows returned, total:%" PRId64 " rows, in sinkNode:%d, elapsed:%.2f ms", - GET_TASKID(pTaskInfo), current, total, 0, el/1000.0); + GET_TASKID(pTaskInfo), current, total, 0, el / 1000.0); atomic_store_64(&pTaskInfo->owner, 0); return pTaskInfo->code; } int32_t qKillTask(qTaskInfo_t qinfo) { - SExecTaskInfo *pTaskInfo = (SExecTaskInfo *)qinfo; + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qinfo; if (pTaskInfo == NULL) { return TSDB_CODE_QRY_INVALID_QHANDLE; @@ -182,7 +179,7 @@ int32_t qKillTask(qTaskInfo_t qinfo) { } int32_t qAsyncKillTask(qTaskInfo_t qinfo) { - SExecTaskInfo *pTaskInfo = (SExecTaskInfo *)qinfo; + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qinfo; if (pTaskInfo == NULL) { return TSDB_CODE_QRY_INVALID_QHANDLE; @@ -195,7 +192,7 @@ int32_t qAsyncKillTask(qTaskInfo_t qinfo) { } int32_t qIsTaskCompleted(qTaskInfo_t qinfo) { - SExecTaskInfo *pTaskInfo = (SExecTaskInfo *)qinfo; + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qinfo; if (pTaskInfo == NULL) { return TSDB_CODE_QRY_INVALID_QHANDLE; @@ -205,18 +202,18 @@ int32_t qIsTaskCompleted(qTaskInfo_t qinfo) { } void qDestroyTask(qTaskInfo_t qTaskHandle) { - SExecTaskInfo* pTaskInfo = (SExecTaskInfo*) qTaskHandle; - qDebug("%s execTask completed, numOfRows:%"PRId64, GET_TASKID(pTaskInfo), pTaskInfo->pRoot->resultInfo.totalRows); + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qTaskHandle; + qDebug("%s execTask completed, numOfRows:%" PRId64, GET_TASKID(pTaskInfo), pTaskInfo->pRoot->resultInfo.totalRows); - queryCostStatis(pTaskInfo); // print the query cost summary + queryCostStatis(pTaskInfo); // print the query cost summary doDestroyTask(pTaskInfo); } -int32_t qGetExplainExecInfo(qTaskInfo_t tinfo, int32_t *resNum, SExplainExecInfo **pRes) { - SExecTaskInfo *pTaskInfo = (SExecTaskInfo *)tinfo; - int32_t capacity = 0; +int32_t qGetExplainExecInfo(qTaskInfo_t tinfo, int32_t* resNum, SExplainExecInfo** pRes) { + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; + int32_t capacity = 0; - return getOperatorExplainExecInfo(pTaskInfo->pRoot, pRes, &capacity, resNum); + return getOperatorExplainExecInfo(pTaskInfo->pRoot, pRes, &capacity, resNum); } int32_t qSerializeTaskStatus(qTaskInfo_t tinfo, char** pOutput, int32_t* len) { diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 421fd56e1f..8d5c48f6cd 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -141,8 +141,8 @@ static int32_t doCopyToSDataBlock(SExecTaskInfo* taskInfo, SSDataBlock* pBlock, SqlFunctionCtx* pCtx, int32_t numOfExprs); static void initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size); -static void doSetTableGroupOutputBuf(SOperatorInfo* pOperator, SAggOperatorInfo* pAggInfo, int32_t numOfOutput, uint64_t groupId); - +static void doSetTableGroupOutputBuf(SOperatorInfo* pOperator, SAggOperatorInfo* pAggInfo, int32_t numOfOutput, + uint64_t groupId); // setup the output buffer for each operator static bool hasNull(SColumn* pColumn, SColumnDataAgg* pStatis) { @@ -1230,8 +1230,9 @@ void initResultRow(SResultRow* pResultRow) { * offset[0] offset[1] offset[2] */ // TODO refactor: some function move away -void setFunctionResultOutput(SOperatorInfo *pOperator, SOptrBasicInfo *pInfo, SAggSupporter* pSup, int32_t stage, int32_t numOfExprs) { - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; +void setFunctionResultOutput(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t stage, + int32_t numOfExprs) { + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx; int32_t* rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset; @@ -1380,9 +1381,10 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const int8_t* rowR } } -void doSetTableGroupOutputBuf(SOperatorInfo* pOperator, SAggOperatorInfo* pAggInfo, int32_t numOfOutput, uint64_t groupId) { +void doSetTableGroupOutputBuf(SOperatorInfo* pOperator, SAggOperatorInfo* pAggInfo, int32_t numOfOutput, + uint64_t groupId) { // for simple group by query without interval, all the tables belong to one group result. - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo; SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx; int32_t* rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset; @@ -2040,8 +2042,8 @@ static int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInf } int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows, char* pData, - int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, - SArray* pColList) { + int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, + SArray* pColList) { if (pColList == NULL) { // data from other sources blockCompressDecode(pRes, numOfOutput, numOfRows, pData); pRes->info.rows = numOfRows; @@ -2084,7 +2086,7 @@ int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLo // data from mnode pRes->info.rows = numOfRows; - relocateColumnData(pRes, pColList, pBlock->pDataBlock); + relocateColumnData(pRes, pColList, pBlock->pDataBlock, false); taosArrayDestroy(pBlock->pDataBlock); taosMemoryFree(pBlock); // blockDataDestroy(pBlock); @@ -2165,8 +2167,9 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SEx } SRetrieveTableRsp* pTableRsp = pDataInfo->pRsp; - code = extractDataBlockFromFetchRsp(pExchangeInfo->pResult, pLoadInfo, pTableRsp->numOfRows, pTableRsp->data, - pTableRsp->compLen, pTableRsp->numOfCols, startTs, &pDataInfo->totalRows, NULL); + code = + extractDataBlockFromFetchRsp(pExchangeInfo->pResult, pLoadInfo, pTableRsp->numOfRows, pTableRsp->data, + pTableRsp->compLen, pTableRsp->numOfCols, startTs, &pDataInfo->totalRows, NULL); if (code != 0) { taosMemoryFreeClear(pDataInfo->pRsp); goto _error; @@ -2281,7 +2284,7 @@ static SSDataBlock* seqLoadRemoteData(SOperatorInfo* pOperator) { SRetrieveTableRsp* pTableRsp = pDataInfo->pRsp; int32_t code = extractDataBlockFromFetchRsp(pExchangeInfo->pResult, pLoadInfo, pTableRsp->numOfRows, pTableRsp->data, - pTableRsp->compLen, pTableRsp->numOfCols, startTs, &pDataInfo->totalRows, NULL); + pTableRsp->compLen, pTableRsp->numOfCols, startTs, &pDataInfo->totalRows, NULL); if (pRsp->completed == 1) { qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, rowsOfSource:%" PRIu64 @@ -2673,8 +2676,8 @@ static SSDataBlock* doSortedMerge(SOperatorInfo* pOperator) { } int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; - pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, - numOfBufPage, pInfo->binfo.pRes, "GET_TASKID(pTaskInfo)"); + pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, numOfBufPage, + pInfo->binfo.pRes, "GET_TASKID(pTaskInfo)"); tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, NULL, NULL); @@ -2751,7 +2754,11 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t goto _error; } - pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, num, &pOperator->exprSupp.rowEntryInfoOffset); + int32_t code = initExprSupp(&pOperator->exprSupp, pExprInfo, num); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + initResultRowInfo(&pInfo->binfo.resultRowInfo); if (pOperator->exprSupp.pCtx == NULL || pInfo->binfo.pRes == NULL) { @@ -2759,7 +2766,7 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t } size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - int32_t code = doInitAggInfoSup(&pInfo->aggSup, pOperator->exprSupp.pCtx, num, keyBufSize, pTaskInfo->id.str); + code = doInitAggInfoSup(&pInfo->aggSup, pOperator->exprSupp.pCtx, num, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -2780,12 +2787,9 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t pOperator->name = "SortedMerge"; // pOperator->operatorType = OP_SortedMerge; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->exprSupp.numOfExprs = num; - pOperator->exprSupp.pExprInfo = pExprInfo; - + pOperator->blocking = true; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSortedMerge, NULL, NULL, destroySortedMergeOperatorInfo, @@ -2812,7 +2816,8 @@ int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scan // todo add more information about exchange operation int32_t type = pOperator->operatorType; if (type == QUERY_NODE_PHYSICAL_PLAN_EXCHANGE || type == QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN || - type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN) { + type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN || + type == QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN) { *order = TSDB_ORDER_ASC; *scanFlag = MAIN_SCAN; return TSDB_CODE_SUCCESS; @@ -2840,7 +2845,6 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) { SAggOperatorInfo* pAggInfo = pOperator->info; SExprSupp* pSup = &pOperator->exprSupp; - SOptrBasicInfo* pInfo = &pAggInfo->binfo; SOperatorInfo* downstream = pOperator->pDownstream[0]; int64_t st = taosGetTimestampUs(); @@ -3130,7 +3134,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { SProjectOperatorInfo* pProjectInfo = pOperator->info; SOptrBasicInfo* pInfo = &pProjectInfo->binfo; - SExprSupp* pSup = &pOperator->exprSupp; + SExprSupp* pSup = &pOperator->exprSupp; SSDataBlock* pRes = pInfo->pRes; blockDataCleanup(pRes); @@ -3403,9 +3407,13 @@ void cleanupAggSup(SAggSupporter* pAggSup) { destroyDiskbasedBuf(pAggSup->pResultBuf); } -int32_t initAggInfo(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, - size_t keyBufSize, const char* pkey) { - initExprSupp(pSup, pExprInfo, numOfCols); +int32_t initAggInfo(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize, + const char* pkey) { + int32_t code = initExprSupp(pSup, pExprInfo, numOfCols); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey); for (int32_t i = 0; i < numOfCols; ++i) { pSup->pCtx[i].pBuf = pAggSup->pResultBuf; @@ -3428,12 +3436,17 @@ void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) { initResultRowInfo(&pInfo->resultRowInfo); } -void initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr) { +int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr) { pSup->pExprInfo = pExprInfo; pSup->numOfExprs = numOfExpr; if (pSup->pExprInfo != NULL) { pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset); + if (pSup->pCtx == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } } + + return TSDB_CODE_SUCCESS; } SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, @@ -3455,14 +3468,17 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* } initBasicInfo(&pInfo->binfo, pResultBlock); - initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr); + code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } - pInfo->groupId = INT32_MIN; - pOperator->name = "TableAggregate"; + pInfo->groupId = INT32_MIN; + pOperator->name = "TableAggregate"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_HASH_AGG; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + pOperator->blocking = true; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(doOpenAggregateOptr, getAggregateResult, NULL, NULL, destroyAggOperatorInfo, @@ -3578,25 +3594,26 @@ static SArray* setRowTsColumnOutputInfo(SqlFunctionCtx* pCtx, int32_t numOfCols) return pList; } -SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhysiNode* pProjPhyNode, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhysiNode* pProjPhyNode, + SExecTaskInfo* pTaskInfo) { SProjectOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SProjectOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - int32_t numOfCols = 0; + int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pProjPhyNode->pProjections, NULL, &numOfCols); SSDataBlock* pResBlock = createResDataBlock(pProjPhyNode->node.pOutputDataBlockDesc); SLimit limit = {.limit = pProjPhyNode->limit, .offset = pProjPhyNode->offset}; SLimit slimit = {.limit = pProjPhyNode->slimit, .offset = pProjPhyNode->soffset}; - pInfo->limit = limit; - pInfo->slimit = slimit; - pInfo->curOffset = limit.offset; - pInfo->curSOffset = slimit.offset; - pInfo->binfo.pRes = pResBlock; + pInfo->limit = limit; + pInfo->slimit = slimit; + pInfo->curOffset = limit.offset; + pInfo->curSOffset = slimit.offset; + pInfo->binfo.pRes = pResBlock; pInfo->pFilterNode = pProjPhyNode->node.pConditions; int32_t numOfRows = 4096; @@ -3614,12 +3631,12 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys setFunctionResultOutput(pOperator, &pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, numOfCols); pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pOperator->exprSupp.pCtx, numOfCols); - pOperator->name = "ProjectOperator"; + pOperator->name = "ProjectOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PROJECT; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doProjectOperation, NULL, NULL, destroyProjectOperatorInfo, NULL, NULL, NULL); @@ -3639,7 +3656,7 @@ _error: static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { SIndefOperatorInfo* pIndefInfo = pOperator->info; SOptrBasicInfo* pInfo = &pIndefInfo->binfo; - SExprSupp* pSup = &pOperator->exprSupp; + SExprSupp* pSup = &pOperator->exprSupp; SSDataBlock* pRes = pInfo->pRes; blockDataCleanup(pRes); @@ -3677,7 +3694,7 @@ static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { SExprSupp* pScalarSup = &pIndefInfo->scalarSup; if (pScalarSup->pExprInfo != NULL) { code = projectApplyFunctions(pScalarSup->pExprInfo, pBlock, pBlock, pScalarSup->pCtx, pScalarSup->numOfExprs, - pIndefInfo->pPseudoColInfo); + pIndefInfo->pPseudoColInfo); if (code != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, code); } @@ -3686,8 +3703,8 @@ static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, scanFlag, false); blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); - code = projectApplyFunctions(pOperator->exprSupp.pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, pOperator->exprSupp.numOfExprs, - pIndefInfo->pPseudoColInfo); + code = projectApplyFunctions(pOperator->exprSupp.pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, + pOperator->exprSupp.numOfExprs, pIndefInfo->pPseudoColInfo); if (code != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, code); } @@ -3716,16 +3733,18 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy SIndefRowsFuncPhysiNode* pPhyNode = (SIndefRowsFuncPhysiNode*)pNode; int32_t numOfExpr = 0; - SExprInfo* pExprInfo = createExprInfo(pPhyNode->pVectorFuncs, NULL, &numOfExpr); + SExprInfo* pExprInfo = createExprInfo(pPhyNode->pFuncs, NULL, &numOfExpr); if (pPhyNode->pExprs != NULL) { - SExprSupp* pSup1 = &pInfo->scalarSup; - pSup1->pExprInfo = createExprInfo(pPhyNode->pExprs, NULL, &pSup1->numOfExprs); - pSup1->pCtx = createSqlFunctionCtx(pSup1->pExprInfo, pSup1->numOfExprs, &pSup1->rowEntryInfoOffset); + int32_t num = 0; + SExprInfo* pSExpr = createExprInfo(pPhyNode->pExprs, NULL, &num); + int32_t code = initExprSupp(&pInfo->scalarSup, pSExpr, num); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } } SSDataBlock* pResBlock = createResDataBlock(pPhyNode->node.pOutputDataBlockDesc); - ; int32_t numOfRows = 4096; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; @@ -3742,17 +3761,16 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy setFunctionResultOutput(pOperator, &pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, numOfExpr); - pInfo->binfo.pRes = pResBlock; - pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pSup->pCtx, numOfExpr); + pInfo->binfo.pRes = pResBlock; + pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pSup->pCtx, numOfExpr); - pOperator->name = "IndefinitOperator"; + pOperator->name = "IndefinitOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PROJECT; pOperator->blocking = false; pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; - pOperator->exprSupp.pExprInfo = pExprInfo; pOperator->exprSupp.numOfExprs = numOfExpr; - pOperator->pTaskInfo = pTaskInfo; + pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doApplyIndefinitFunction, NULL, NULL, destroyIndefinitOperatorInfo, NULL, NULL, NULL); @@ -3791,34 +3809,6 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t } } -static int32_t convertFillType(int32_t mode) { - int32_t type = TSDB_FILL_NONE; - switch (mode) { - case FILL_MODE_PREV: - type = TSDB_FILL_PREV; - break; - case FILL_MODE_NONE: - type = TSDB_FILL_NONE; - break; - case FILL_MODE_NULL: - type = TSDB_FILL_NULL; - break; - case FILL_MODE_NEXT: - type = TSDB_FILL_NEXT; - break; - case FILL_MODE_VALUE: - type = TSDB_FILL_SET_VALUE; - break; - case FILL_MODE_LINEAR: - type = TSDB_FILL_LINEAR; - break; - default: - type = TSDB_FILL_NONE; - } - - return type; -} - SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFillNode, bool multigroupResult, SExecTaskInfo* pTaskInfo) { SFillOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SFillOperatorInfo)); @@ -3827,11 +3817,11 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* goto _error; } - int32_t num = 0; - SSDataBlock* pResBlock = createResDataBlock(pPhyFillNode->node.pOutputDataBlockDesc); - SExprInfo* pExprInfo = createExprInfo(pPhyFillNode->pTargets, NULL, &num); - SInterval* pInterval = &((SIntervalAggOperatorInfo*)downstream->info)->interval; - int32_t type = convertFillType(pPhyFillNode->mode); + int32_t num = 0; + SSDataBlock* pResBlock = createResDataBlock(pPhyFillNode->node.pOutputDataBlockDesc); + SExprInfo* pExprInfo = createExprInfo(pPhyFillNode->pTargets, NULL, &num); + SInterval* pInterval = &((SIntervalAggOperatorInfo*)downstream->info)->interval; + int32_t type = convertFillType(pPhyFillNode->mode); SResultInfo* pResultInfo = &pOperator->resultInfo; initResultSizeInfo(pOperator, 4096); @@ -3842,14 +3832,14 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* goto _error; } - pInfo->pRes = pResBlock; + pInfo->pRes = pResBlock; pInfo->multigroupResult = multigroupResult; - pOperator->name = "FillOperator"; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; + pOperator->name = "FillOperator"; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_FILL; - pOperator->exprSupp.pExprInfo = pExprInfo; - pOperator->exprSupp.numOfExprs = num; + pOperator->exprSupp.pExprInfo = pExprInfo; + pOperator->exprSupp.numOfExprs = num; pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; @@ -3882,8 +3872,7 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPT } static tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, - STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId, - SNode* pTagCond); + STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId); static SArray* extractColumnInfo(SNodeList* pNodeList); @@ -3995,7 +3984,7 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, } SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, - uint64_t queryId, uint64_t taskId, STableListInfo* pTableListInfo, SNode* pTagCond) { + uint64_t queryId, uint64_t taskId, STableListInfo* pTableListInfo) { int32_t type = nodeType(pPhyNode); if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) { @@ -4003,7 +3992,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode; tsdbReaderT pDataReader = - doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId, pTagCond); + doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId); if (pDataReader == NULL && terrno != 0) { pTaskInfo->code = terrno; return NULL; @@ -4033,7 +4022,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode; SArray* dataReaders = taosArrayInit(8, POINTER_BYTES); - createMultipleDataReaders(pTableScanNode, pHandle, pTableListInfo, dataReaders, queryId, taskId, pTagCond); + createMultipleDataReaders(pTableScanNode, pHandle, pTableListInfo, dataReaders, queryId, taskId); extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo); SArray* groupKeys = extractPartitionColInfo(pTableScanNode->pPartitionTags); generateGroupIdMap(pTableListInfo, pHandle, groupKeys); // todo for json @@ -4048,12 +4037,21 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SScanPhysiNode* pScanPhyNode = (SScanPhysiNode*)pPhyNode; // simple child table. STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode; STimeWindowAggSupp twSup = { - .waterMark = pTableScanNode->watermark, .calTrigger = pTableScanNode->triggerType, .maxTs = INT64_MIN}; + .waterMark = pTableScanNode->watermark, + .calTrigger = pTableScanNode->triggerType, + .maxTs = INT64_MIN, + }; tsdbReaderT pDataReader = NULL; - if (pHandle->vnode) { - pDataReader = doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId, pTagCond); - } else { - getTableList(pHandle->meta, pScanPhyNode, pTableListInfo, pTagCond); + + if (pHandle) { + if (pHandle->vnode) { + // for stram + pDataReader = + doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId); + } else { + // for tq + getTableList(pHandle->meta, pScanPhyNode, pTableListInfo); + } } if (pDataReader == NULL && terrno != 0) { @@ -4080,13 +4078,53 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo } else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) { STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode; - int32_t code = getTableList(pHandle->meta, pScanPhyNode, pTableListInfo, pScanPhyNode->node.pConditions); + int32_t code = getTableList(pHandle->meta, pScanPhyNode, pTableListInfo); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = terrno; return NULL; } return createTagScanOperatorInfo(pHandle, pScanPhyNode, pTableListInfo, pTaskInfo); + } else if (QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN == type) { + SBlockDistScanPhysiNode* pBlockNode = (SBlockDistScanPhysiNode*) pPhyNode; + pTableListInfo->pTableList = taosArrayInit(4, sizeof(STableKeyInfo)); + + if (pBlockNode->tableType == TSDB_SUPER_TABLE) { + int32_t code = tsdbGetAllTableList(pHandle->meta, pBlockNode->uid, pTableListInfo->pTableList); + if (code != TSDB_CODE_SUCCESS) { + pTaskInfo->code = terrno; + return NULL; + } + } else { // Create one table group. + STableKeyInfo info = {.lastKey = 0, .uid = pBlockNode->uid}; + taosArrayPush(pTableListInfo->pTableList, &info); + } + + SQueryTableDataCond cond = {0}; + + { + cond.order = TSDB_ORDER_ASC; + cond.numOfCols = 1; + cond.colList = taosMemoryCalloc(1, sizeof(SColumnInfo)); + if (cond.colList == NULL) { + terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; + return NULL; + } + + cond.colList->colId = 1; + cond.colList->type = TSDB_DATA_TYPE_TIMESTAMP; + cond.colList->bytes = sizeof(TSKEY); + + cond.numOfTWindows = 1; + cond.twindows = taosMemoryCalloc(1, sizeof(STimeWindow)); + cond.twindows[0] = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX}; + cond.suid = pBlockNode->suid; + cond.type = BLOCK_LOAD_OFFSET_SEQ_ORDER; + } + tsdbReaderT* pReader = tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo, queryId, taskId); + cleanupQueryTableDataCond(&cond); + + return createDataBlockInfoScanOperator(pReader, pHandle, cond.suid, pBlockNode, pTaskInfo); } else { ASSERT(0); } @@ -4098,7 +4136,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SOperatorInfo** ops = taosMemoryCalloc(size, POINTER_BYTES); for (int32_t i = 0; i < size; ++i) { SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i); - ops[i] = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableListInfo, pTagCond); + ops[i] = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableListInfo); if (ops[i] == NULL) { return NULL; } @@ -4229,6 +4267,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo pOptr = createFillOperatorInfo(ops[0], (SFillPhysiNode*)pPhyNode, false, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC == type) { pOptr = createIndefinitOutputOperatorInfo(ops[0], pPhyNode, pTaskInfo); + } else if (QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC == type) { + pOptr = createTimeSliceOperatorInfo(ops[0], pPhyNode, pTaskInfo); } else { ASSERT(0); } @@ -4270,7 +4310,7 @@ SArray* extractColumnInfo(SNodeList* pNodeList) { SColumn c = {0}; c.slotId = pNode->slotId; c.colId = pNode->slotId; - c.type = pValNode->node.type; + c.type = pValNode->node.type; c.bytes = pValNode->node.resType.bytes; c.scale = pValNode->node.resType.scale; c.precision = pValNode->node.resType.precision; @@ -4283,9 +4323,8 @@ SArray* extractColumnInfo(SNodeList* pNodeList) { } tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, - STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId, SNode* pTagCond) { - int32_t code = - getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo, pTagCond); + STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId) { + int32_t code = getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -4374,7 +4413,7 @@ int32_t decodeOperator(SOperatorInfo* ops, const char* result, int32_t length) { ASSERT(length == *(int32_t*)result); const char* data = result + sizeof(int32_t); - code = ops->fpSet.decodeResultRow(ops, (char*) data); + code = ops->fpSet.decodeResultRow(ops, (char*)data); if (code != TDB_CODE_SUCCESS) { return code; } @@ -4443,8 +4482,10 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead } (*pTaskInfo)->sql = sql; + (*pTaskInfo)->tableqinfoList.pTagCond = pPlan->pTagCond; + (*pTaskInfo)->tableqinfoList.pTagIndexCond = pPlan->pTagIndexCond; (*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, queryId, taskId, - &(*pTaskInfo)->tableqinfoList, pPlan->pTagCond); + &(*pTaskInfo)->tableqinfoList); if (NULL == (*pTaskInfo)->pRoot) { code = (*pTaskInfo)->code; goto _complete; diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 527f4520bf..064a36df1c 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -387,11 +387,12 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx pInfo->pGroupCols = pGroupColList; pInfo->pCondition = pCondition; - pInfo->scalarSup.pExprInfo = pScalarExprInfo; - pInfo->scalarSup.numOfExprs = numOfScalarExpr; - pInfo->scalarSup.pCtx = createSqlFunctionCtx(pScalarExprInfo, numOfScalarExpr, &pInfo->scalarSup.rowEntryInfoOffset); + int32_t code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } - int32_t code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pGroupColList); + code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pGroupColList); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -586,24 +587,30 @@ static void clearPartitionOperator(SPartitionOperatorInfo* pInfo) { while( (ite = taosHashIterate(pInfo->pGroupSet, ite)) != NULL ) { taosArrayDestroy( ((SDataGroupInfo *)ite)->pPageList); } - taosHashClear(pInfo->pGroupSet); + taosArrayClear(pInfo->sortedGroupArray); clearDiskbasedBuf(pInfo->pBuf); } +static int compareDataGroupInfo(const void* group1, const void* group2) { + const SDataGroupInfo* pGroupInfo1 = group1; + const SDataGroupInfo* pGroupInfo2 = group2; + return pGroupInfo1->groupId - pGroupInfo2->groupId; +} + static SSDataBlock* buildPartitionResult(SOperatorInfo* pOperator) { SPartitionOperatorInfo* pInfo = pOperator->info; - SDataGroupInfo* pGroupInfo = pInfo->pGroupIter; - if (pInfo->pGroupIter == NULL || pInfo->pageIndex >= taosArrayGetSize(pGroupInfo->pPageList)) { + SDataGroupInfo* pGroupInfo = (pInfo->groupIndex != -1) ? taosArrayGet(pInfo->sortedGroupArray, pInfo->groupIndex) : NULL; + if (pInfo->groupIndex == -1 || pInfo->pageIndex >= taosArrayGetSize(pGroupInfo->pPageList)) { // try next group data - pInfo->pGroupIter = taosHashIterate(pInfo->pGroupSet, pInfo->pGroupIter); - if (pInfo->pGroupIter == NULL) { + ++pInfo->groupIndex; + if (pInfo->groupIndex >= taosArrayGetSize(pInfo->sortedGroupArray)) { doSetOperatorCompleted(pOperator); clearPartitionOperator(pInfo); return NULL; } - pGroupInfo = pInfo->pGroupIter; + pGroupInfo = taosArrayGet(pInfo->sortedGroupArray, pInfo->groupIndex); pInfo->pageIndex = 0; } @@ -657,6 +664,20 @@ static SSDataBlock* hashPartition(SOperatorInfo* pOperator) { doHashPartition(pOperator, pBlock); } + SArray* groupArray = taosArrayInit(taosHashGetSize(pInfo->pGroupSet), sizeof(SDataGroupInfo)); + void* pGroupIter = NULL; + pGroupIter = taosHashIterate(pInfo->pGroupSet, NULL); + while (pGroupIter != NULL) { + SDataGroupInfo* pGroupInfo = pGroupIter; + taosArrayPush(groupArray, pGroupInfo); + pGroupIter = taosHashIterate(pInfo->pGroupSet, pGroupIter); + } + + taosArraySort(groupArray, compareDataGroupInfo); + pInfo->sortedGroupArray = groupArray; + pInfo->groupIndex = -1; + taosHashClear(pInfo->pGroupSet); + pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0; pOperator->status = OP_RES_TO_RETURN; @@ -676,6 +697,7 @@ static void destroyPartitionOperatorInfo(void* param, int32_t numOfOutput) { taosArrayDestroy(pInfo->pGroupColVals); taosMemoryFree(pInfo->keyBuf); + taosArrayDestroy(pInfo->sortedGroupArray); taosHashCleanup(pInfo->pGroupSet); taosMemoryFree(pInfo->columnOffset); @@ -697,10 +719,12 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition pInfo->pGroupCols = extractPartitionColInfo(pPartNode->pPartitionKeys); if (pPartNode->pExprs != NULL) { - pInfo->scalarSup.numOfExprs = 0; - pInfo->scalarSup.pExprInfo = createExprInfo(pPartNode->pExprs, NULL, &pInfo->scalarSup.numOfExprs); - pInfo->scalarSup.pCtx = createSqlFunctionCtx( - pInfo->scalarSup.pExprInfo, pInfo->scalarSup.numOfExprs, &pInfo->scalarSup.rowEntryInfoOffset); + int32_t num = 0; + SExprInfo* pExprInfo1 = createExprInfo(pPartNode->pExprs, NULL, &num); + int32_t code = initExprSupp(&pInfo->scalarSup, pExprInfo1, num); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } } _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 812272c559..8a3f6128fe 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include #include "filter.h" #include "function.h" #include "functionMgt.h" @@ -258,7 +259,7 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca return terrno; } - relocateColumnData(pBlock, pTableScanInfo->pColMatchInfo, pCols); + relocateColumnData(pBlock, pTableScanInfo->pColMatchInfo, pCols, true); // currently only the tbname pseudo column if (pTableScanInfo->pseudoSup.numOfExprs > 0) { @@ -367,13 +368,14 @@ void setTbNameColData(void* pMeta, const SSDataBlock* pBlock, SColumnInfoData* p static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) { STableScanInfo* pTableScanInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SSDataBlock* pBlock = pTableScanInfo->pResBlock; int64_t st = taosGetTimestampUs(); while (tsdbNextDataBlock(pTableScanInfo->dataReader)) { - if (isTaskKilled(pOperator->pTaskInfo)) { - longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_QUERY_CANCELLED); + if (isTaskKilled(pTaskInfo)) { + longjmp(pTaskInfo->env, TSDB_CODE_TSC_QUERY_CANCELLED); } // process this data block based on the probabilities @@ -396,7 +398,7 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) { continue; } - uint64_t* groupId = taosHashGet(pOperator->pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t)); + uint64_t* groupId = taosHashGet(pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t)); if (groupId) { pBlock->info.groupId = *groupId; } @@ -525,7 +527,7 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, goto _error; } - //taosSsleep(20); + // taosSsleep(20); SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc; @@ -589,44 +591,76 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo* pInfo->dataReader = pReadHandle; // pInfo->prevGroupId = -1; - pOperator->name = "TableSeqScanOperator"; + pOperator->name = "TableSeqScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScanImpl, NULL, NULL, NULL, NULL, NULL, NULL); return pOperator; } +static int32_t doGetTableRowSize(void* pMeta, uint64_t uid) { + int32_t rowLen = 0; + + SMetaReader mr = {0}; + metaReaderInit(&mr, pMeta, 0); + metaGetTableEntryByUid(&mr, uid); + if (mr.me.type == TSDB_SUPER_TABLE) { + int32_t numOfCols = mr.me.stbEntry.schemaRow.nCols; + for(int32_t i = 0; i < numOfCols; ++i) { + rowLen += mr.me.stbEntry.schemaRow.pSchema[i].bytes; + } + } else if (mr.me.type == TSDB_CHILD_TABLE) { + uint64_t suid = mr.me.ctbEntry.suid; + metaGetTableEntryByUid(&mr, suid); + int32_t numOfCols = mr.me.stbEntry.schemaRow.nCols; + + for(int32_t i = 0; i < numOfCols; ++i) { + rowLen += mr.me.stbEntry.schemaRow.pSchema[i].bytes; + } + } else if (mr.me.type == TSDB_NORMAL_TABLE) { + int32_t numOfCols = mr.me.ntbEntry.schemaRow.nCols; + for(int32_t i = 0; i < numOfCols; ++i) { + rowLen += mr.me.ntbEntry.schemaRow.pSchema[i].bytes; + } + } + + metaReaderClear(&mr); + return rowLen; +} + static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) { if (pOperator->status == OP_EXEC_DONE) { return NULL; } - STableScanInfo* pTableScanInfo = pOperator->info; + SBlockDistInfo* pBlockScanInfo = pOperator->info; - STableBlockDistInfo blockDistInfo = {0}; - blockDistInfo.maxRows = INT_MIN; - blockDistInfo.minRows = INT_MAX; + STableBlockDistInfo blockDistInfo = {.minRows = INT_MAX, .maxRows = INT_MIN}; + blockDistInfo.rowSize = doGetTableRowSize(pBlockScanInfo->readHandle.meta, pBlockScanInfo->uid); - tsdbGetFileBlocksDistInfo(pTableScanInfo->dataReader, &blockDistInfo); - blockDistInfo.numOfInmemRows = (int32_t)tsdbGetNumOfRowsInMemTable(pTableScanInfo->dataReader); + tsdbGetFileBlocksDistInfo(pBlockScanInfo->pHandle, &blockDistInfo); + blockDistInfo.numOfInmemRows = (int32_t)tsdbGetNumOfRowsInMemTable(pBlockScanInfo->pHandle); - SSDataBlock* pBlock = pTableScanInfo->pResBlock; - pBlock->info.rows = 1; + SSDataBlock* pBlock = pBlockScanInfo->pResBlock; - SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 0); + int32_t slotId = pOperator->exprSupp.pExprInfo->base.resSchema.slotId; + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, slotId); int32_t len = tSerializeBlockDistInfo(NULL, 0, &blockDistInfo); char* p = taosMemoryCalloc(1, len + VARSTR_HEADER_SIZE); tSerializeBlockDistInfo(varDataVal(p), len, &blockDistInfo); varDataSetLen(p, len); + blockDataEnsureCapacity(pBlock, 1); colDataAppend(pColInfo, 0, p, false); taosMemoryFree(p); + pBlock->info.rows = 1; + pOperator->status = OP_EXEC_DONE; return pBlock; } @@ -636,7 +670,8 @@ static void destroyBlockDistScanOperatorInfo(void* param, int32_t numOfOutput) { blockDataDestroy(pDistInfo->pResBlock); } -SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* readHandle, uint64_t uid, + SBlockDistScanPhysiNode* pBlockScanNode, SExecTaskInfo* pTaskInfo) { SBlockDistInfo* pInfo = taosMemoryCalloc(1, sizeof(SBlockDistInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -644,21 +679,23 @@ SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* goto _error; } - pInfo->pHandle = dataReader; + pInfo->pHandle = dataReader; + pInfo->readHandle = *readHandle; + pInfo->uid = uid; + pInfo->pResBlock = createResDataBlock(pBlockScanNode->node.pOutputDataBlockDesc); - pInfo->pResBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); + int32_t numOfCols = 0; + SExprInfo* pExprInfo = createExprInfo(pBlockScanNode->pScanPseudoCols, NULL, &numOfCols); + int32_t code = initExprSupp(&pOperator->exprSupp, pExprInfo, numOfCols); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } - SColumnInfoData infoData = {0}; - infoData.info.type = TSDB_DATA_TYPE_VARCHAR; - infoData.info.bytes = 1024; - - taosArrayPush(pInfo->pResBlock->pDataBlock, &infoData); - - pOperator->name = "DataBlockInfoScanOperator"; - // pOperator->operatorType = OP_TableBlockInfoScan; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + pOperator->name = "DataBlockDistScanOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doBlockInfoScan, NULL, NULL, @@ -707,10 +744,10 @@ static bool prepareDataScan(SStreamBlockScanInfo* pInfo) { int64_t gap = pInfo->sessionSup.gap; int32_t winIndex = 0; SResultWindowInfo* pCurWin = - getSessionTimeWindow(pAggSup, tsCols[pInfo->updateResIndex], pSDB->info.groupId, gap, &winIndex); + getSessionTimeWindow(pAggSup, tsCols[pInfo->updateResIndex], INT64_MIN, pSDB->info.groupId, gap, &winIndex); win = pCurWin->win; pInfo->updateResIndex += - updateSessionWindowInfo(pCurWin, tsCols, pSDB->info.rows, pInfo->updateResIndex, gap, NULL); + updateSessionWindowInfo(pCurWin, tsCols, NULL, pSDB->info.rows, pInfo->updateResIndex, gap, NULL); } else { win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[pInfo->updateResIndex], &pInfo->interval, pInfo->interval.precision, NULL); @@ -788,23 +825,23 @@ static SSDataBlock* doDataScan(SStreamBlockScanInfo* pInfo) { if (!pResult) { return NULL; } - + if (pResult->info.groupId == pInfo->groupId) { return pResult; } } -/* Todo(liuyao) for partition by column - SSDataBlock* pBlock = createOneDataBlock(pResult, true); - blockDataCleanup(pResult); - for (int32_t i = 0; i < pBlock->info.rows; i++) { - uint64_t id = getGroupId(pInfo->pOperatorDumy, pBlock, i); - if (id == pInfo->groupId) { - copyOneRow(pResult, pBlock, i); + /* Todo(liuyao) for partition by column + SSDataBlock* pBlock = createOneDataBlock(pResult, true); + blockDataCleanup(pResult); + for (int32_t i = 0; i < pBlock->info.rows; i++) { + uint64_t id = getGroupId(pInfo->pOperatorDumy, pBlock, i); + if (id == pInfo->groupId) { + copyOneRow(pResult, pBlock, i); + } } - } - return pResult; -*/ + return pResult; + */ } static void setUpdateData(SStreamBlockScanInfo* pInfo, SSDataBlock* pBlock, SSDataBlock* pUpdateBlock) { @@ -819,7 +856,7 @@ static void setUpdateData(SStreamBlockScanInfo* pInfo, SSDataBlock* pBlock, SSDa int32_t rowId = *(int32_t*)taosArrayGet(pInfo->tsArray, pInfo->tsArrayIndex); pInfo->groupId = getGroupId(pInfo->pOperatorDumy, pBlock, rowId); int32_t i = 0; - for ( ; i < size; i++) { + for (; i < size; i++) { rowId = *(int32_t*)taosArrayGet(pInfo->tsArray, i + pInfo->tsArrayIndex); uint64_t id = getGroupId(pInfo->pOperatorDumy, pBlock, rowId); if (pInfo->groupId != id) { @@ -1049,9 +1086,6 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan SScanPhysiNode* pScanPhyNode = &pTableScanNode->scan; SDataBlockDescNode* pDescNode = pScanPhyNode->node.pOutputDataBlockDesc; - SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, pTaskInfo); - - STableScanInfo* pSTInfo = (STableScanInfo*)pTableScanDummy->info; int32_t numOfCols = 0; pInfo->pColMatchInfo = extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID); @@ -1068,16 +1102,6 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan } } - // set the extract column id to streamHandle - tqReadHandleSetColIdList((STqReadHandle*)pHandle->reader, pColIds); - SArray* tableIdList = extractTableIdList(&pTaskInfo->tableqinfoList); - int32_t code = tqReadHandleSetTbUidList(pHandle->reader, tableIdList); - if (code != 0) { - taosArrayDestroy(tableIdList); - goto _error; - } - taosArrayDestroy(tableIdList); - pInfo->pBlockLists = taosArrayInit(4, POINTER_BYTES); if (pInfo->pBlockLists == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -1089,10 +1113,31 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan goto _error; } - if (pSTInfo->interval.interval > 0 && pDataReader) { - pInfo->pUpdateInfo = updateInfoInitP(&pSTInfo->interval, pTwSup->waterMark); - } else { - pInfo->pUpdateInfo = NULL; + if (pHandle) { + SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, pTaskInfo); + STableScanInfo* pSTInfo = (STableScanInfo*)pTableScanDummy->info; + if (pSTInfo->interval.interval > 0) { + pInfo->pUpdateInfo = updateInfoInitP(&pSTInfo->interval, pTwSup->waterMark); + } else { + pInfo->pUpdateInfo = NULL; + } + pInfo->pOperatorDumy = pTableScanDummy; + pInfo->interval = pSTInfo->interval; + + pInfo->readHandle = *pHandle; + ASSERT(pHandle->reader); + pInfo->streamBlockReader = pHandle->reader; + pInfo->tableUid = pScanPhyNode->uid; + + // set the extract column id to streamHandle + tqReadHandleSetColIdList((STqReadHandle*)pHandle->reader, pColIds); + SArray* tableIdList = extractTableIdList(&pTaskInfo->tableqinfoList); + int32_t code = tqReadHandleSetTbUidList(pHandle->reader, tableIdList); + if (code != 0) { + taosArrayDestroy(tableIdList); + goto _error; + } + taosArrayDestroy(tableIdList); } // create the pseduo columns info @@ -1100,19 +1145,14 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan pInfo->pPseudoExpr = createExprInfo(pTableScanNode->scan.pScanPseudoCols, NULL, &pInfo->numOfPseudoExpr); } - pInfo->readHandle = *pHandle; - pInfo->tableUid = pScanPhyNode->uid; - pInfo->streamBlockReader = pHandle->reader; pInfo->pRes = createResDataBlock(pDescNode); pInfo->pUpdateRes = createResDataBlock(pDescNode); pInfo->pCondition = pScanPhyNode->node.pConditions; pInfo->pDataReader = pDataReader; pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE; - pInfo->pOperatorDumy = pTableScanDummy; - pInfo->interval = pSTInfo->interval; pInfo->sessionSup = (SessionWindowSupporter){.pStreamAggSup = NULL, .gap = -1}; pInfo->groupId = 0; - + pOperator->name = "StreamBlockScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; pOperator->blocking = false; @@ -1368,12 +1408,6 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { pColInfoData = taosArrayGet(p->pDataBlock, 6); colDataAppend(pColInfoData, numOfRows, (char*)&vgId, false); - // table comment - // todo: set the correct comment - pColInfoData = taosArrayGet(p->pDataBlock, 8); - colDataAppendNULL(pColInfoData, numOfRows); - - char str[256] = {0}; int32_t tableType = pInfo->pCur->mr.me.type; if (tableType == TSDB_CHILD_TABLE) { // create time @@ -1390,11 +1424,25 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.stbEntry.schemaRow.nCols, false); // super table name - STR_TO_VARSTR(str, mr.me.name); + STR_TO_VARSTR(n, mr.me.name); pColInfoData = taosArrayGet(p->pDataBlock, 4); - colDataAppend(pColInfoData, numOfRows, str, false); + colDataAppend(pColInfoData, numOfRows, n, false); metaReaderClear(&mr); + // table comment + pColInfoData = taosArrayGet(p->pDataBlock, 8); + if (pInfo->pCur->mr.me.ctbEntry.commentLen > 0) { + char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ctbEntry.comment); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else if (pInfo->pCur->mr.me.ctbEntry.commentLen == 0) { + char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, ""); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else { + colDataAppendNULL(pColInfoData, numOfRows); + } + // uid pColInfoData = taosArrayGet(p->pDataBlock, 5); colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false); @@ -1403,7 +1451,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { pColInfoData = taosArrayGet(p->pDataBlock, 7); colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ctbEntry.ttlDays, false); - STR_TO_VARSTR(str, "CHILD_TABLE"); + STR_TO_VARSTR(n, "CHILD_TABLE"); } else if (tableType == TSDB_NORMAL_TABLE) { // create time pColInfoData = taosArrayGet(p->pDataBlock, 2); @@ -1417,6 +1465,20 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { pColInfoData = taosArrayGet(p->pDataBlock, 4); colDataAppendNULL(pColInfoData, numOfRows); + // table comment + pColInfoData = taosArrayGet(p->pDataBlock, 8); + if (pInfo->pCur->mr.me.ntbEntry.commentLen > 0) { + char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ntbEntry.comment); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else if (pInfo->pCur->mr.me.ntbEntry.commentLen == 0) { + char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, ""); + colDataAppend(pColInfoData, numOfRows, comment, false); + } else { + colDataAppendNULL(pColInfoData, numOfRows); + } + // uid pColInfoData = taosArrayGet(p->pDataBlock, 5); colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false); @@ -1425,11 +1487,11 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { pColInfoData = taosArrayGet(p->pDataBlock, 7); colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ttlDays, false); - STR_TO_VARSTR(str, "NORMAL_TABLE"); + STR_TO_VARSTR(n, "NORMAL_TABLE"); } pColInfoData = taosArrayGet(p->pDataBlock, 9); - colDataAppend(pColInfoData, numOfRows, str, false); + colDataAppend(pColInfoData, numOfRows, n, false); if (++numOfRows >= pOperator->resultInfo.capacity) { break; @@ -1446,7 +1508,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { p->info.rows = numOfRows; pInfo->pRes->info.rows = numOfRows; - relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock); + relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock, false); doFilterResult(pInfo); blockDataDestroy(p); @@ -1513,7 +1575,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { } extractDataBlockFromFetchRsp(pInfo->pRes, &pInfo->loadInfo, pRsp->numOfRows, pRsp->data, pRsp->compLen, - pOperator->exprSupp.numOfExprs, startTs, NULL, pInfo->scanCols); + pOperator->exprSupp.numOfExprs, startTs, NULL, pInfo->scanCols); // todo log the filter info doFilterResult(pInfo); @@ -1538,7 +1600,7 @@ int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capacity) { getPerfDbMeta(&pSysDbTableMeta, &size); p->info.rows = buildDbTableInfoBlock(p, pSysDbTableMeta, size, TSDB_PERFORMANCE_SCHEMA_DB); - relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock); + relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock, false); pInfo->pRes->info.rows = p->info.rows; blockDataDestroy(p); @@ -1785,9 +1847,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) { } pRes->info.rows = count; - doFilter(pInfo->pFilterNode, pRes); - - pOperator->resultInfo.totalRows += pRes->info.rows; + pOperator->resultInfo.totalRows += count; return (pRes->info.rows == 0) ? NULL : pInfo->pRes; } @@ -1810,22 +1870,26 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi int32_t num = 0; int32_t numOfExprs = 0; SExprInfo* pExprInfo = createExprInfo(pPhyNode->pScanPseudoCols, NULL, &numOfExprs); - SArray* colList = extractColMatchInfo(pPhyNode->pScanPseudoCols, pDescNode, &num, COL_MATCH_FROM_COL_ID); + SArray* colList = extractColMatchInfo(pPhyNode->pScanPseudoCols, pDescNode, &num, COL_MATCH_FROM_COL_ID); + + + int32_t code = initExprSupp(&pOperator->exprSupp, pExprInfo, numOfExprs); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } pInfo->pTableList = pTableListInfo; pInfo->pColMatchInfo = colList; pInfo->pRes = createResDataBlock(pDescNode); pInfo->readHandle = *pReadHandle; pInfo->curPos = 0; - pInfo->pFilterNode = pPhyNode->node.pConditions; - pOperator->name = "TagScanOperator"; + pOperator->name = "TagScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN; + pOperator->blocking = false; pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; - pOperator->exprSupp.pExprInfo = pExprInfo; - pOperator->exprSupp.numOfExprs = numOfExprs; pOperator->pTaskInfo = pTaskInfo; initResultSizeInfo(pOperator, 4096); @@ -1894,9 +1958,8 @@ typedef struct STableMergeScanInfo { int32_t createMultipleDataReaders(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, STableListInfo* pTableListInfo, SArray* arrayReader, uint64_t queryId, - uint64_t taskId, SNode* pTagCond) { - int32_t code = - getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo, pTagCond); + uint64_t taskId) { + int32_t code = getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -1933,7 +1996,7 @@ _error: static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeScanInfo* pTableScanInfo, int32_t readerIdx, SSDataBlock* pBlock, uint32_t* status) { - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; STableMergeScanInfo* pInfo = pOperator->info; SFileBlockLoadRecorder* pCost = &pTableScanInfo->readRecorder; @@ -2019,7 +2082,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc return terrno; } - relocateColumnData(pBlock, pTableScanInfo->pColMatchInfo, pCols); + relocateColumnData(pBlock, pTableScanInfo->pColMatchInfo, pCols, true); // currently only the tbname pseudo column if (pTableScanInfo->numOfPseudoExpr > 0) { @@ -2120,9 +2183,8 @@ int32_t doOpenTableMergeScanOperator(SOperatorInfo* pOperator) { int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; - pInfo->pSortHandle = - tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, - numOfBufPage, pInfo->pSortInputBlock, pTaskInfo->id.str); + pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, numOfBufPage, + pInfo->pSortInputBlock, pTaskInfo->id.str); tsortSetFetchRawDataFp(pInfo->pSortHandle, getTableDataBlock, NULL, NULL); @@ -2186,8 +2248,7 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) { longjmp(pTaskInfo->env, code); } - SSDataBlock* pBlock = - getSortedTableMergeScanBlockData(pInfo->pSortHandle, pOperator->resultInfo.capacity, pOperator); + SSDataBlock* pBlock = getSortedTableMergeScanBlockData(pInfo->pSortHandle, pOperator->resultInfo.capacity, pOperator); if (pBlock != NULL) { pOperator->resultInfo.totalRows += pBlock->info.rows; @@ -2220,20 +2281,20 @@ void destroyTableMergeScanOperatorInfo(void* param, int32_t numOfOutput) { typedef struct STableMergeScanExecInfo { SFileBlockLoadRecorder blockRecorder; - SSortExecInfo sortExecInfo; + SSortExecInfo sortExecInfo; } STableMergeScanExecInfo; int32_t getTableMergeScanExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) { ASSERT(pOptr != NULL); // TODO: merge these two info into one struct STableMergeScanExecInfo* execInfo = taosMemoryCalloc(1, sizeof(STableMergeScanExecInfo)); - STableMergeScanInfo* pInfo = pOptr->info; + STableMergeScanInfo* pInfo = pOptr->info; execInfo->blockRecorder = pInfo->readRecorder; execInfo->sortExecInfo = tsortGetSortExecInfo(pInfo->pSortHandle); *pOptrExplain = execInfo; *len = sizeof(STableMergeScanExecInfo); - + return TSDB_CODE_SUCCESS; } @@ -2248,8 +2309,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc; int32_t numOfCols = 0; - SArray* pColList = - extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID); + SArray* pColList = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID); int32_t code = initQueryTableDataCond(&pInfo->cond, pTableScanNode); if (code != TSDB_CODE_SUCCESS) { @@ -2263,16 +2323,16 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN pInfo->scanInfo = (SScanInfo){.numOfAsc = pTableScanNode->scanSeq[0], .numOfDesc = pTableScanNode->scanSeq[1]}; - pInfo->readHandle = *readHandle; - pInfo->interval = extractIntervalInfo(pTableScanNode); + pInfo->readHandle = *readHandle; + pInfo->interval = extractIntervalInfo(pTableScanNode); pInfo->sample.sampleRatio = pTableScanNode->ratio; - pInfo->sample.seed = taosGetTimestampSec(); - pInfo->dataBlockLoadFlag = pTableScanNode->dataRequired; - pInfo->pFilterNode = pTableScanNode->scan.node.pConditions; - pInfo->dataReaders = dataReaders; - pInfo->scanFlag = MAIN_SCAN; - pInfo->pColMatchInfo = pColList; - pInfo->curTWinIdx = 0; + pInfo->sample.seed = taosGetTimestampSec(); + pInfo->dataBlockLoadFlag = pTableScanNode->dataRequired; + pInfo->pFilterNode = pTableScanNode->scan.node.pConditions; + pInfo->dataReaders = dataReaders; + pInfo->scanFlag = MAIN_SCAN; + pInfo->pColMatchInfo = pColList; + pInfo->curTWinIdx = 0; pInfo->pResBlock = createResDataBlock(pDescNode); @@ -2290,22 +2350,22 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN pInfo->pSortInputBlock = createOneDataBlock(pInfo->pResBlock, false); int32_t rowSize = pInfo->pResBlock->info.rowSize; - pInfo->bufPageSize = getProperSortPageSize(rowSize); + pInfo->bufPageSize = getProperSortPageSize(rowSize); // todo the total available buffer should be determined by total capacity of buffer of this task. // the additional one is reserved for merge result - pInfo->sortBufSize = pInfo->bufPageSize * (taosArrayGetSize(dataReaders) + 1); - pInfo->hasGroupId = false; + pInfo->sortBufSize = pInfo->bufPageSize * (taosArrayGetSize(dataReaders) + 1); + pInfo->hasGroupId = false; pInfo->prefetchedTuple = NULL; - pOperator->name = "TableMergeScanOperator"; + pOperator->name = "TableMergeScanOperator"; // TODO : change it pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->exprSupp.numOfExprs = numOfCols; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->exprSupp.numOfExprs = numOfCols; + pOperator->pTaskInfo = pTaskInfo; initResultSizeInfo(pOperator, 1024); pOperator->fpSet = diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index a31bfab62d..63285daa3a 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -24,6 +24,8 @@ typedef enum SResultTsInterpType { RESULT_ROW_END_INTERP = 2, } SResultTsInterpType; +#define IS_FINAL_OP(op) ((op)->isFinal) + static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator); static int64_t* extractTsCol(SSDataBlock* pBlock, const SIntervalAggOperatorInfo* pInfo); @@ -682,6 +684,13 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num } } +void printDataBlock(SSDataBlock* pBlock, const char* flag) { + SArray* blocks = taosArrayInit(1, sizeof(SSDataBlock)); + taosArrayPush(blocks, pBlock); + blockDebugShowData(blocks, flag); + taosArrayDestroy(blocks); +} + typedef int64_t (*__get_value_fn_t)(void* data, int32_t index); int32_t binarySearch(void* keyList, int num, TSKEY key, int order, __get_value_fn_t getValuefn) { @@ -1696,7 +1705,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) { return (rows == 0) ? NULL : pBInfo->pRes; } -static void doKeepPrevRows(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock* pBlock) { +static void doKeepPrevRows(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock* pBlock, int32_t rowIndex) { int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); for(int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); @@ -1706,108 +1715,53 @@ static void doKeepPrevRows(STimeSliceOperatorInfo* pSliceInfo, const SSDataBlock SGroupKeys* pkey = taosArrayGet(pSliceInfo->pPrevRow, i); pkey->isNull = false; - char* val = colDataGetData(pColInfoData, i); + char* val = colDataGetData(pColInfoData, rowIndex); memcpy(pkey->pData, val, pkey->bytes); } } } -static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { - if (pOperator->status == OP_EXEC_DONE) { - return NULL; - } +static void genInterpolationResult(STimeSliceOperatorInfo* pSliceInfo, SExprSupp* pExprSup, SSDataBlock* pBlock, + int32_t rowIndex, SSDataBlock* pResBlock) { + int32_t rows = pResBlock->info.rows; - STimeSliceOperatorInfo* pSliceInfo = pOperator->info; - SSDataBlock* pResBlock = pSliceInfo->binfo.pRes; - SExprSupp* pSup = &pOperator->exprSupp; + // todo set the correct primary timestamp column -// if (pOperator->status == OP_RES_TO_RETURN) { -// // doBuildResultDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); -// if (pResBlock->info.rows == 0 || !hasDataInGroupInfo(&pSliceInfo->groupResInfo)) { -// doSetOperatorCompleted(pOperator); -// } -// -// return pResBlock; -// } + // output the result + for (int32_t j = 0; j < pExprSup->numOfExprs; ++j) { + SExprInfo* pExprInfo = &pExprSup->pExprInfo[j]; + int32_t dstSlot = pExprInfo->base.resSchema.slotId; + int32_t srcSlot = pExprInfo->base.pParam[0].pCol->slotId; - int32_t order = TSDB_ORDER_ASC; - SInterval* pInterval = &pSliceInfo->interval; - SOperatorInfo* downstream = pOperator->pDownstream[0]; + SColumnInfoData* pSrc = taosArrayGet(pBlock->pDataBlock, srcSlot); + SColumnInfoData* pDst = taosArrayGet(pResBlock->pDataBlock, dstSlot); - int32_t numOfRows = 0; - while (1) { - SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); - if (pBlock == NULL) { - break; - } + switch (pSliceInfo->fillType) { + case TSDB_FILL_NULL: + colDataAppendNULL(pDst, rows); + break; - // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, MAIN_SCAN, true); + case TSDB_FILL_SET_VALUE: { + SVariant* pVar = &pSliceInfo->pFillColInfo[j].fillVal; - SColumnInfoData* pTsCol = taosArrayGet(pBlock->pDataBlock, 0); - for(int32_t i = 0; i < pBlock->info.rows; ++i) { - int64_t ts = *(int64_t*) colDataGetData(pTsCol, i); - - if (ts == pSliceInfo->current) { - for(int32_t j = 0; j < pOperator->exprSupp.numOfExprs; ++j) { - SExprInfo* pExprInfo = &pOperator->exprSupp.pExprInfo[j]; - int32_t dstSlot = pExprInfo->base.resSchema.slotId; - int32_t srcSlot = pExprInfo->base.pParam[0].pCol->slotId; - - SColumnInfoData* pSrc = taosArrayGet(pBlock->pDataBlock, srcSlot); - SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, dstSlot); - - char* v = colDataGetData(pSrc, i); - colDataAppend(pDst, numOfRows, v, false); + if (pDst->info.type == TSDB_DATA_TYPE_FLOAT) { + float v = 0; + GET_TYPED_DATA(v, float, pVar->nType, &pVar->i); + colDataAppend(pDst, rows, (char*)&v, false); + } else if (pDst->info.type == TSDB_DATA_TYPE_DOUBLE) { + double v = 0; + GET_TYPED_DATA(v, double, pVar->nType, &pVar->i); + colDataAppend(pDst, rows, (char*)&v, false); + } else if (IS_SIGNED_NUMERIC_TYPE(pDst->info.type)) { + int64_t v = 0; + GET_TYPED_DATA(v, int64_t, pVar->nType, &pVar->i); + colDataAppend(pDst, rows, (char*)&v, false); } + } break; - numOfRows += 1; - - pSliceInfo->current += taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision); - if (pSliceInfo->current > pSliceInfo->win.ekey) { - doSetOperatorCompleted(pOperator); - break; - } - } else if (ts < pSliceInfo->current) { - if (i != pBlock->info.window.ekey) { - int64_t nextTs = *(int64_t*) colDataGetData(pTsCol, i + 1); - if (nextTs > pSliceInfo->current) { - // output the result - for (int32_t j = 0; j < pOperator->exprSupp.numOfExprs; ++j) { - SExprInfo* pExprInfo = &pOperator->exprSupp.pExprInfo[j]; - int32_t dstSlot = pExprInfo->base.resSchema.slotId; - int32_t srcSlot = pExprInfo->base.pParam[0].pCol->slotId; - - SColumnInfoData* pSrc = taosArrayGet(pBlock->pDataBlock, srcSlot); - SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, dstSlot); - - switch (pSliceInfo->fillType) { - case TSDB_FILL_NULL: - colDataAppendNULL(pDst, numOfRows); - break; - - case TSDB_FILL_SET_VALUE: { - SVariant* pVar = &pSliceInfo->pFillColInfo[i].fillVal; - - if (pDst->info.type == TSDB_DATA_TYPE_FLOAT) { - float v = 0; - GET_TYPED_DATA(v, float, pVar->nType, &pVar->i); - colDataAppend(pDst, numOfRows, (char*)&v, false); - } else if (pDst->info.type == TSDB_DATA_TYPE_DOUBLE) { - double v = 0; - GET_TYPED_DATA(v, double, pVar->nType, &pVar->i); - colDataAppend(pDst, numOfRows, (char*)&v, false); - } else if (IS_SIGNED_NUMERIC_TYPE(pDst->info.type)) { - int64_t v = 0; - GET_TYPED_DATA(v, int64_t, pVar->nType, &pVar->i); - colDataAppend(pDst, numOfRows, (char*)&v, false); - } - } - break; - - case TSDB_FILL_LINEAR: + case TSDB_FILL_LINEAR: #if 0 - if (pCtx->start.key == INT64_MIN || pCtx->start.key > pCtx->startTs + if (pCtx->start.key == INT64_MIN || pCtx->start.key > pCtx->startTs || pCtx->end.key == INT64_MIN || pCtx->end.key < pCtx->startTs) { // goto interp_exit; } @@ -1836,33 +1790,158 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { } } #endif - break; + break; - case TSDB_FILL_PREV: { - SGroupKeys* pkey = taosArrayGet(pSliceInfo->pPrevRow, srcSlot); - colDataAppend(pDst, numOfRows, pkey->pData, false); - } break; + case TSDB_FILL_PREV: { + SGroupKeys* pkey = taosArrayGet(pSliceInfo->pPrevRow, srcSlot); + colDataAppend(pDst, rows, pkey->pData, false); + } break; - case TSDB_FILL_NEXT: { - } break; + case TSDB_FILL_NEXT: { + char* p = colDataGetData(pSrc, rowIndex); + colDataAppend(pDst, rows, p, colDataIsNull_s(pSrc, rowIndex)); + } break; - case TSDB_FILL_NONE: - default: - break; - } + case TSDB_FILL_NONE: + default: + break; + } + } - pSliceInfo->current += + pResBlock->info.rows += 1; +} + +static int32_t initPrevRowsKeeper(STimeSliceOperatorInfo* pInfo, SSDataBlock* pBlock) { + if (pInfo->pPrevRow != NULL) { + return TSDB_CODE_SUCCESS; + } + + pInfo->pPrevRow = taosArrayInit(4, sizeof(SGroupKeys)); + if (pInfo->pPrevRow == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + int32_t numOfCols = pBlock->info.numOfCols; + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); + + SGroupKeys key = {0}; + key.bytes = pColInfo->info.bytes; + key.type = pColInfo->info.type; + key.isNull = false; + key.pData = taosMemoryCalloc(1, pColInfo->info.bytes); + taosArrayPush(pInfo->pPrevRow, &key); + } + + return TSDB_CODE_SUCCESS; +} + +static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + STimeSliceOperatorInfo* pSliceInfo = pOperator->info; + SSDataBlock* pResBlock = pSliceInfo->pRes; + SExprSupp* pSup = &pOperator->exprSupp; + + blockDataEnsureCapacity(pResBlock, pOperator->resultInfo.capacity); + +// if (pOperator->status == OP_RES_TO_RETURN) { +// // doBuildResultDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); +// if (pResBlock->info.rows == 0 || !hasDataInGroupInfo(&pSliceInfo->groupResInfo)) { +// doSetOperatorCompleted(pOperator); +// } +// +// return pResBlock; +// } + + int32_t order = TSDB_ORDER_ASC; + SInterval* pInterval = &pSliceInfo->interval; + SOperatorInfo* downstream = pOperator->pDownstream[0]; + + int32_t numOfRows = 0; + while (1) { + SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); + if (pBlock == NULL) { + break; + } + + int32_t code = initPrevRowsKeeper(pSliceInfo, pBlock); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + + // the pDataBlock are always the same one, no need to call this again + setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, MAIN_SCAN, true); + + SColumnInfoData* pTsCol = taosArrayGet(pBlock->pDataBlock, pSliceInfo->tsCol.slotId); + for(int32_t i = 0; i < pBlock->info.rows; ++i) { + int64_t ts = *(int64_t*) colDataGetData(pTsCol, i); + + if (ts == pSliceInfo->current) { + for(int32_t j = 0; j < pOperator->exprSupp.numOfExprs; ++j) { + SExprInfo* pExprInfo = &pOperator->exprSupp.pExprInfo[j]; + int32_t dstSlot = pExprInfo->base.resSchema.slotId; + int32_t srcSlot = pExprInfo->base.pParam[0].pCol->slotId; + + SColumnInfoData* pSrc = taosArrayGet(pBlock->pDataBlock, srcSlot); + SColumnInfoData* pDst = taosArrayGet(pResBlock->pDataBlock, dstSlot); + + char* v = colDataGetData(pSrc, i); + colDataAppend(pDst, numOfRows, v, false); + } + + pResBlock->info.rows += 1; + doKeepPrevRows(pSliceInfo, pBlock, i); + + pSliceInfo->current = taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision); + if (pSliceInfo->current > pSliceInfo->win.ekey) { + doSetOperatorCompleted(pOperator); + break; + } + + if (pResBlock->info.rows >= pResBlock->info.capacity) { + break; + } + } else if (ts < pSliceInfo->current) { + if (i < pBlock->info.rows - 1) { + int64_t nextTs = *(int64_t*) colDataGetData(pTsCol, i + 1); + if (nextTs > pSliceInfo->current) { + while (pSliceInfo->current < nextTs && pSliceInfo->current <= pSliceInfo->win.ekey) { + genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pBlock, i, pResBlock); + pSliceInfo->current = taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision); - if (pSliceInfo->current > pSliceInfo->win.ekey) { - doSetOperatorCompleted(pOperator); + if (pResBlock->info.rows >= pResBlock->info.capacity) { break; } } + + if (pSliceInfo->current > pSliceInfo->win.ekey) { + doSetOperatorCompleted(pOperator); + break; + } } else { // ignore current row, and do nothing } } else { // it is the last row of current block - doKeepPrevRows(pSliceInfo, pBlock); + doKeepPrevRows(pSliceInfo, pBlock, i); + } + } else { // ts > pSliceInfo->current + while (pSliceInfo->current < ts && pSliceInfo->current <= pSliceInfo->win.ekey) { + genInterpolationResult(pSliceInfo, &pOperator->exprSupp, pBlock, i, pResBlock); + pSliceInfo->current = + taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision); + if (pResBlock->info.rows >= pResBlock->info.capacity) { + break; + } + } + + if (pSliceInfo->current > pSliceInfo->win.ekey) { + doSetOperatorCompleted(pOperator); + break; } } } @@ -1877,59 +1956,46 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { return pResBlock->info.rows == 0 ? NULL : pResBlock; } -static int32_t initTimesliceInfo(STimeSliceOperatorInfo* pInfo, SqlFunctionCtx* pCtx, int32_t numOfCols) { - pInfo->pPrevRow = taosArrayInit(4, sizeof(SGroupKeys)); - pInfo->pCols = taosArrayInit(4, sizeof(SColumn)); - - if (pInfo->pPrevRow == NULL || pInfo->pCols == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - for (int32_t i = 0; i < numOfCols; ++i) { - SExprInfo* pExpr = pCtx[i].pExpr; - - SFunctParam* pParam = &pExpr->base.pParam[0]; - - SColumn c = *pParam->pCol; - taosArrayPush(pInfo->pCols, &c); - - SGroupKeys key = {0}; - key.bytes = c.bytes; - key.type = c.type; - key.isNull = false; - key.pData = taosMemoryCalloc(1, c.bytes); - taosArrayPush(pInfo->pPrevRow, &key); - } - - return TSDB_CODE_SUCCESS; -} - -SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResultBlock, const SNodeListNode* pValNode, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SPhysiNode *pPhyNode, SExecTaskInfo* pTaskInfo) { STimeSliceOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STimeSliceOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pOperator == NULL || pInfo == NULL) { goto _error; } + SInterpFuncPhysiNode* pInterpPhyNode = (SInterpFuncPhysiNode*)pPhyNode; SExprSupp* pSup = &pOperator->exprSupp; - int32_t code = initTimesliceInfo(pInfo, pSup->pCtx, numOfCols); + int32_t numOfExprs = 0; + SExprInfo* pExprInfo = createExprInfo(pInterpPhyNode->pFuncs, NULL, &numOfExprs); + int32_t code = initExprSupp(pSup, pExprInfo, numOfExprs); if (code != TSDB_CODE_SUCCESS) { goto _error; } - initResultRowInfo(&pInfo->binfo.resultRowInfo); - pInfo->pFillColInfo = createFillColInfo(pExprInfo, numOfCols, pValNode); + if (pInterpPhyNode->pExprs != NULL) { + int32_t num = 0; + SExprInfo* pScalarExprInfo = createExprInfo(pInterpPhyNode->pExprs, NULL, &num); + code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, num); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + } - pInfo->binfo.pRes = pResultBlock; + pInfo->tsCol = extractColumnFromColumnNode((SColumnNode*)pInterpPhyNode->pTimeSeries); + pInfo->fillType = convertFillType(pInterpPhyNode->fillMode); + initResultSizeInfo(pOperator, 4096); + + pInfo->pFillColInfo = createFillColInfo(pExprInfo, numOfExprs, (SNodeListNode*)pInterpPhyNode->pFillValues); + pInfo->pRes = createResDataBlock(pPhyNode->pOutputDataBlockDesc); + pInfo->win = pInterpPhyNode->timeRange; + pInfo->interval.interval = pInterpPhyNode->interval; + pInfo->current = pInfo->win.skey; pOperator->name = "TimeSliceOperator"; - // pOperator->operatorType = OP_AllTimeWindow; - pOperator->blocking = true; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC; + pOperator->blocking = false; pOperator->status = OP_NOT_OPENED; - pOperator->exprSupp.pExprInfo = pExprInfo; - pOperator->exprSupp.numOfExprs = numOfCols; pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; @@ -2054,8 +2120,6 @@ _error: return NULL; } -bool isFinalInterval(SStreamFinalIntervalOperatorInfo* pInfo) { return pInfo->pChildren != NULL; } - void compactFunctions(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx, int32_t numOfOutput, SExecTaskInfo* pTaskInfo) { for (int32_t k = 0; k < numOfOutput; ++k) { @@ -2129,7 +2193,7 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc STimeWindow nextWin = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, pInfo->interval.precision, NULL); while (1) { - if (isFinalInterval(pInfo) && isCloseWindow(&nextWin, &pInfo->twAggSup) && + if (IS_FINAL_OP(pInfo) && isCloseWindow(&nextWin, &pInfo->twAggSup) && isDeletedWindow(&nextWin, tableGroupId, &pInfo->aggSup)) { SArray* pUpWins = taosArrayInit(8, sizeof(STimeWindow)); taosArrayPush(pUpWins, &nextWin); @@ -2150,9 +2214,6 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pUpdated) { saveResultRow(pResult, tableGroupId, pUpdated); } - // window start(end) key interpolation - // doWindowBorderInterpolation(pInfo, pSDataBlock, numOfOutput, pSup->pCtx, pResult, &nextWin, startPos, - // forwardRows); updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, true); doApplyFunctions(pTaskInfo, pSup->pCtx, &nextWin, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); @@ -2214,8 +2275,8 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); if (pInfo->binfo.pRes->info.rows == 0) { pOperator->status = OP_EXEC_DONE; - if (isFinalInterval(pInfo) || pInfo->pUpdateRes->info.rows == 0) { - if (!isFinalInterval(pInfo)) { + if (IS_FINAL_OP(pInfo) || pInfo->pUpdateRes->info.rows == 0) { + if (!IS_FINAL_OP(pInfo)) { // semi interval operator clear disk buffer clearStreamIntervalOperator(pInfo); } @@ -2239,7 +2300,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { SArray* pUpWins = taosArrayInit(8, sizeof(STimeWindow)); doClearWindows(&pInfo->aggSup, pSup, &pInfo->interval, pInfo->primaryTsIndex, pOperator->exprSupp.numOfExprs, pBlock, pUpWins); - if (isFinalInterval(pInfo)) { + if (IS_FINAL_OP(pInfo)) { int32_t childIndex = getChildIndex(pBlock); SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex); SIntervalAggOperatorInfo* pChildInfo = pChildOp->info; @@ -2256,14 +2317,14 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { copyUpdateDataBlock(pInfo->pUpdateRes, pBlock, pInfo->primaryTsIndex); taosArrayDestroy(pUpWins); break; - } else if (pBlock->info.type == STREAM_GET_ALL && isFinalInterval(pInfo)) { + } else if (pBlock->info.type == STREAM_GET_ALL && IS_FINAL_OP(pInfo)) { getAllIntervalWindow(pInfo->aggSup.pResultRowHashTable, pUpdated); continue; } setInputDataBlock(pOperator, pSup->pCtx, pBlock, pInfo->order, MAIN_SCAN, true); doHashInterval(pOperator, pBlock, pBlock->info.groupId, pUpdated); - if (isFinalInterval(pInfo)) { + if (IS_FINAL_OP(pInfo)) { int32_t chIndex = getChildIndex(pBlock); int32_t size = taosArrayGetSize(pInfo->pChildren); // if chIndex + 1 - size > 0, add new child @@ -2283,7 +2344,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { } pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs); - if (isFinalInterval(pInfo)) { + if (IS_FINAL_OP(pInfo)) { closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, &pInfo->interval, pUpdated); } @@ -2356,16 +2417,24 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, } } // semi interval operator does not catch result - if (!isFinalInterval(pInfo)) { - pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE; - } pInfo->pUpdateRes = createResDataBlock(pPhyNode->pOutputDataBlockDesc); pInfo->pUpdateRes->info.type = STREAM_REPROCESS; blockDataEnsureCapacity(pInfo->pUpdateRes, 128); pInfo->pPhyNode = (SPhysiNode*)nodesCloneNode((SNode*)pPhyNode); - pOperator->name = "StreamFinalIntervalOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL; + if (pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL) { + pInfo->isFinal = true; + pOperator->name = "StreamFinalIntervalOperator"; + } else { + pInfo->isFinal = false; + pOperator->name = "StreamSemiIntervalOperator"; + } + + if (!IS_FINAL_OP(pInfo)) { + pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE; + } + + pOperator->operatorType = pPhyNode->type; pOperator->blocking = true; pOperator->status = OP_NOT_OPENED; pOperator->exprSupp.pExprInfo = pExprInfo; @@ -2421,7 +2490,11 @@ void destroyStreamSessionAggOperatorInfo(void* param, int32_t numOfOutput) { } int32_t initBasicInfoEx(SOptrBasicInfo* pBasicInfo, SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock) { - initExprSupp(pSup, pExprInfo, numOfCols); + int32_t code = initExprSupp(pSup, pExprInfo, numOfCols); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + initBasicInfo(pBasicInfo, pResultBlock); for (int32_t i = 0; i < numOfCols; ++i) { @@ -2455,7 +2528,6 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pSessionNode->window.pFuncs, NULL, &numOfCols); SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc); - int32_t tsSlotId = ((SColumnNode*)pSessionNode->window.pTspk)->slotId; int32_t code = TSDB_CODE_OUT_OF_MEMORY; SStreamSessionAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamSessionAggOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); @@ -2491,7 +2563,10 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh initResultRowInfo(&pInfo->binfo.resultRowInfo); initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window); - pInfo->primaryTsIndex = tsSlotId; + pInfo->primaryTsIndex = ((SColumnNode*)pSessionNode->window.pTspk)->slotId; + if (pSessionNode->window.pTsEnd) { + pInfo->endTsIndex = ((SColumnNode*)pSessionNode->window.pTsEnd)->slotId; + } pInfo->gap = pSessionNode->gap; pInfo->binfo.pRes = pResBlock; pInfo->order = TSDB_ORDER_ASC; @@ -2501,6 +2576,8 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh pInfo->pDelRes = createOneDataBlock(pResBlock, false); blockDataEnsureCapacity(pInfo->pDelRes, 64); pInfo->pChildren = NULL; + pInfo->isFinal = false; + pInfo->pPhyNode = pPhyNode; pOperator->name = "StreamSessionWindowAggOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION; @@ -2513,8 +2590,10 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh createOperatorFpSet(operatorDummyOpenFn, doStreamSessionAgg, NULL, NULL, destroyStreamSessionAggOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); pOperator->pTaskInfo = pTaskInfo; - initDownStream(downstream, &pInfo->streamAggSup, pInfo->gap, pInfo->twAggSup.waterMark, pOperator->operatorType); - code = appendDownstream(pOperator, &downstream, 1); + if (downstream) { + initDownStream(downstream, &pInfo->streamAggSup, pInfo->gap, pInfo->twAggSup.waterMark, pOperator->operatorType); + code = appendDownstream(pOperator, &downstream, 1); + } return pOperator; _error: @@ -2564,21 +2643,22 @@ SArray* getWinInfos(SStreamAggSupporter* pAggSup, uint64_t groupId) { return pWinInfos; } -SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY ts, uint64_t groupId, int64_t gap, int32_t* pIndex) { +SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, + TSKEY endTs, uint64_t groupId, int64_t gap, int32_t* pIndex) { SArray* pWinInfos = getWinInfos(pAggSup, groupId); pAggSup->pCurWins = pWinInfos; int32_t size = taosArrayGetSize(pWinInfos); if (size == 0) { *pIndex = 0; - return addNewSessionWindow(pWinInfos, ts); + return addNewSessionWindow(pWinInfos, startTs); } // find the first position which is smaller than the key - int32_t index = binarySearch(pWinInfos, size, ts, TSDB_ORDER_DESC, getSessionWindowEndkey); + int32_t index = binarySearch(pWinInfos, size, startTs, TSDB_ORDER_DESC, getSessionWindowEndkey); SResultWindowInfo* pWin = NULL; if (index >= 0) { pWin = taosArrayGet(pWinInfos, index); - if (isInWindow(pWin, ts, gap)) { + if (isInWindow(pWin, startTs, gap)) { *pIndex = index; return pWin; } @@ -2586,34 +2666,40 @@ SResultWindowInfo* getSessionTimeWindow(SStreamAggSupporter* pAggSup, TSKEY ts, if (index + 1 < size) { pWin = taosArrayGet(pWinInfos, index + 1); - if (isInWindow(pWin, ts, gap)) { + if (isInWindow(pWin, startTs, gap)) { *pIndex = index + 1; return pWin; + } else if (endTs != INT64_MIN && isInWindow(pWin, endTs, gap)) { + *pIndex = index; + return pWin; } } if (index == size - 1) { *pIndex = taosArrayGetSize(pWinInfos); - return addNewSessionWindow(pWinInfos, ts); + return addNewSessionWindow(pWinInfos, startTs); } *pIndex = index + 1; - return insertNewSessionWindow(pWinInfos, ts, index + 1); + return insertNewSessionWindow(pWinInfos, startTs, index + 1); } -int32_t updateSessionWindowInfo(SResultWindowInfo* pWinInfo, TSKEY* pTs, int32_t rows, int32_t start, int64_t gap, - SHashObj* pStDeleted) { +int32_t updateSessionWindowInfo(SResultWindowInfo* pWinInfo, TSKEY* pStartTs, + TSKEY* pEndTs, int32_t rows, int32_t start, int64_t gap, SHashObj* pStDeleted) { for (int32_t i = start; i < rows; ++i) { - if (!isInWindow(pWinInfo, pTs[i], gap)) { + if (!isInWindow(pWinInfo, pStartTs[i], gap) && (!pEndTs || !isInWindow(pWinInfo, pEndTs[i], gap)) ) { return i - start; } - if (pWinInfo->win.skey > pTs[i]) { + if (pWinInfo->win.skey > pStartTs[i]) { if (pStDeleted && pWinInfo->isOutput) { taosHashPut(pStDeleted, &pWinInfo->pos, sizeof(SResultRowPosition), &pWinInfo->win.skey, sizeof(TSKEY)); pWinInfo->isOutput = false; } - pWinInfo->win.skey = pTs[i]; + pWinInfo->win.skey = pStartTs[i]; + } + pWinInfo->win.ekey = TMAX(pWinInfo->win.ekey, pStartTs[i]); + if (pEndTs) { + pWinInfo->win.ekey = TMAX(pWinInfo->win.ekey, pEndTs[i]); } - pWinInfo->win.ekey = TMAX(pWinInfo->win.ekey, pTs[i]); } return rows - start; } @@ -2666,7 +2752,7 @@ static int32_t doOneWindowAggImpl(int32_t tsColId, SOptrBasicInfo* pBinfo, SStre if (code != TSDB_CODE_SUCCESS || (*pResult) == NULL) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } - updateTimeWindowInfo(pTimeWindowData, &pCurWin->win, true); + updateTimeWindowInfo(pTimeWindowData, &pCurWin->win, false); doApplyFunctions(pTaskInfo, pSup->pCtx, &pCurWin->win, pTimeWindowData, startIndex, winRows, tsCols, pSDataBlock->info.rows, numOutput, TSDB_ORDER_ASC); return TSDB_CODE_SUCCESS; @@ -2733,8 +2819,8 @@ typedef struct SWinRes { uint64_t groupId; } SWinRes; -static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBlock, SHashObj* pStUpdated, - SHashObj* pStDeleted) { +static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBlock, + SHashObj* pStUpdated, SHashObj* pStDeleted, bool hasEndTs) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SStreamSessionAggOperatorInfo* pInfo = pOperator->info; bool masterScan = true; @@ -2745,13 +2831,21 @@ static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSData int32_t step = 1; bool ascScan = true; - TSKEY* tsCols = NULL; + TSKEY* startTsCols = NULL; + TSKEY* endTsCols = NULL; SResultRow* pResult = NULL; int32_t winRows = 0; if (pSDataBlock->pDataBlock != NULL) { - SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex); - tsCols = (int64_t*)pColDataInfo->pData; + SColumnInfoData* pStartTsCol = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex); + startTsCols = (int64_t*) pStartTsCol->pData; + SColumnInfoData* pEndTsCol = NULL; + if (hasEndTs) { + pEndTsCol = taosArrayGet(pSDataBlock->pDataBlock, pInfo->endTsIndex); + } else { + pEndTsCol = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex); + } + endTsCols = (int64_t*) pEndTsCol->pData; } else { return; } @@ -2759,22 +2853,21 @@ static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSData SStreamAggSupporter* pAggSup = &pInfo->streamAggSup; for (int32_t i = 0; i < pSDataBlock->info.rows;) { int32_t winIndex = 0; - SResultWindowInfo* pCurWin = getSessionTimeWindow(pAggSup, tsCols[i], groupId, gap, &winIndex); - winRows = updateSessionWindowInfo(pCurWin, tsCols, pSDataBlock->info.rows, i, pInfo->gap, pStDeleted); + SResultWindowInfo* pCurWin = getSessionTimeWindow(pAggSup, startTsCols[i], + endTsCols[i], groupId, gap, &winIndex); + winRows = updateSessionWindowInfo(pCurWin, startTsCols, endTsCols, + pSDataBlock->info.rows, i, pInfo->gap, pStDeleted); code = doOneWindowAgg(pInfo, pSDataBlock, pCurWin, &pResult, i, winRows, numOfOutput, pOperator); if (code != TSDB_CODE_SUCCESS || pResult == NULL) { longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } - // window start(end) key interpolation - // doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pSup->pCtx, pResult, &nextWin, startPos, - // forwardRows, - // pInfo->order, false); + int32_t winNum = getNumCompactWindow(pAggSup->pCurWins, winIndex, gap); if (winNum > 0) { compactTimeWindow(pInfo, winIndex, winNum, groupId, numOfOutput, pStUpdated, pStDeleted, pOperator); } pCurWin->isClosed = false; - if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE) { + if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pStUpdated) { SWinRes value = {.ts = pCurWin->win.skey, .groupId = groupId}; code = taosHashPut(pStUpdated, &pCurWin->pos, sizeof(SResultRowPosition), &value, sizeof(SWinRes)); if (code != TSDB_CODE_SUCCESS) { @@ -2793,8 +2886,8 @@ static void doClearSessionWindows(SStreamAggSupporter* pAggSup, SExprSupp* pSup, int32_t step = 0; for (int32_t i = 0; i < pBlock->info.rows; i += step) { int32_t winIndex = 0; - SResultWindowInfo* pCurWin = getSessionTimeWindow(pAggSup, tsCols[i], pBlock->info.groupId, gap, &winIndex); - step = updateSessionWindowInfo(pCurWin, tsCols, pBlock->info.rows, i, gap, NULL); + SResultWindowInfo* pCurWin = getSessionTimeWindow(pAggSup, tsCols[i], INT64_MIN, pBlock->info.groupId, gap, &winIndex); + step = updateSessionWindowInfo(pCurWin, tsCols, NULL, pBlock->info.rows, i, gap, NULL); ASSERT(isInWindow(pCurWin, tsCols[i], gap)); doClearWindowImpl(&pCurWin->pos, pAggSup->pResultBuf, pSup, numOfOutput); if (result) { @@ -2861,7 +2954,10 @@ static void rebuildTimeWindow(SStreamSessionAggOperatorInfo* pInfo, SArray* pWin SArray* pChWins = getWinInfos(&pChInfo->streamAggSup, groupId); int32_t chWinSize = taosArrayGetSize(pChWins); int32_t index = binarySearch(pChWins, chWinSize, pParentWin->win.skey, TSDB_ORDER_DESC, getSessionWindowEndkey); - for (int32_t k = index; k > 0 && k < chWinSize; k++) { + if (index < 0) { + index = 0; + } + for (int32_t k = index; k < chWinSize; k++) { SResultWindowInfo* pcw = taosArrayGet(pChWins, k); if (pParentWin->win.skey <= pcw->win.skey && pcw->win.ekey <= pParentWin->win.ekey) { SResultRow* pChResult = NULL; @@ -2876,11 +2972,9 @@ static void rebuildTimeWindow(SStreamSessionAggOperatorInfo* pInfo, SArray* pWin } } -bool isFinalSession(SStreamSessionAggOperatorInfo* pInfo) { return pInfo->pChildren != NULL; } - typedef SResultWindowInfo* (*__get_win_info_)(void*); -SResultWindowInfo* getSessionWinInfo(void* pData) { return (SResultWindowInfo*)pData; } -SResultWindowInfo* getStateWinInfo(void* pData) { return &((SStateWindowInfo*)pData)->winInfo; } +SResultWindowInfo* getResWinForSession(void* pData) { return (SResultWindowInfo*)pData; } +SResultWindowInfo* getResWinForState(void* pData) { return &((SStateWindowInfo*)pData)->winInfo; } int32_t closeSessionWindow(SHashObj* pHashMap, STimeWindowAggSupp* pTwSup, SArray* pClosed, __get_win_info_ fn) { @@ -2928,14 +3022,13 @@ int32_t getAllSessionWindow(SHashObj* pHashMap, SArray* pClosed, __get_win_info_ } static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { - if (pOperator->status == OP_EXEC_DONE) { - return NULL; - } - - SExprSupp* pSup = &pOperator->exprSupp; + SExprSupp* pSup = &pOperator->exprSupp; SStreamSessionAggOperatorInfo* pInfo = pOperator->info; SOptrBasicInfo* pBInfo = &pInfo->binfo; - if (pOperator->status == OP_RES_TO_RETURN) { + TSKEY maxTs = INT64_MIN; + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } else if (pOperator->status == OP_RES_TO_RETURN) { doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator); if (pInfo->pDelRes->info.rows > 0) { return pInfo->pDelRes; @@ -2960,8 +3053,8 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { if (pBlock->info.type == STREAM_REPROCESS) { SArray* pWins = taosArrayInit(16, sizeof(SResultWindowInfo)); doClearSessionWindows(&pInfo->streamAggSup, &pOperator->exprSupp, pBlock, 0, pOperator->exprSupp.numOfExprs, pInfo->gap, pWins); - if (isFinalSession(pInfo)) { - int32_t childIndex = 0; // Todo(liuyao) get child id from SSDataBlock + if (IS_FINAL_OP(pInfo)) { + int32_t childIndex = getChildIndex(pBlock); SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex); SStreamSessionAggOperatorInfo* pChildInfo = pChildOp->info; doClearSessionWindows(&pChildInfo->streamAggSup, &pChildOp->exprSupp, pBlock, 0, pChildOp->exprSupp.numOfExprs, @@ -2971,25 +3064,139 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { taosArrayDestroy(pWins); continue; } else if (pBlock->info.type == STREAM_GET_ALL) { - getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getSessionWinInfo); + getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getResWinForSession); continue; } // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); - if (isFinalSession(pInfo)) { - int32_t childIndex = 0; // Todo(liuyao) get child id from SSDataBlock - SOptrBasicInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex); - doStreamSessionAggImpl(pOperator, pBlock, NULL, NULL); + doStreamSessionAggImpl(pOperator, pBlock, pStUpdated, pInfo->pStDeleted, IS_FINAL_OP(pInfo)); + if (IS_FINAL_OP(pInfo)) { + int32_t chIndex = getChildIndex(pBlock); + int32_t size = taosArrayGetSize(pInfo->pChildren); + // if chIndex + 1 - size > 0, add new child + for (int32_t i = 0; i < chIndex + 1 - size; i++) { + SOperatorInfo* pChildOp = createStreamFinalSessionAggOperatorInfo(NULL, pInfo->pPhyNode, pOperator->pTaskInfo, 0); + if (!pChildOp) { + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); + } + taosArrayPush(pInfo->pChildren, &pChildOp); + } + SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, chIndex); + setInputDataBlock(pChildOp, pChildOp->exprSupp.pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); + doStreamSessionAggImpl(pChildOp, pBlock, NULL, NULL, true); } - doStreamSessionAggImpl(pOperator, pBlock, pStUpdated, pInfo->pStDeleted); - pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, pBlock->info.window.ekey); + maxTs = TMAX(maxTs, pBlock->info.window.ekey); } + + pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs); // restore the value pOperator->status = OP_RES_TO_RETURN; closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pUpdated, - getSessionWinInfo); + getResWinForSession); + copyUpdateResult(pStUpdated, pUpdated); + taosHashCleanup(pStUpdated); + + finalizeUpdatedResult(pSup->numOfExprs, pInfo->streamAggSup.pResultBuf, pUpdated, + pSup->rowEntryInfoOffset); + initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated); + blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity); + doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator); + if (pInfo->pDelRes->info.rows > 0) { + return pInfo->pDelRes; + } + doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf); + return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes; +} + +static void clearStreamSessionOperator(SStreamSessionAggOperatorInfo* pInfo) { + void **pIte = NULL; + while ((pIte = taosHashIterate(pInfo->streamAggSup.pResultRows, pIte)) != NULL) { + SArray *pWins = (SArray *) (*pIte); + int32_t size = taosArrayGetSize(pWins); + for (int32_t i = 0; i < size; i++) { + SResultWindowInfo* pWin = (SResultWindowInfo*)taosArrayGet(pWins, i); + pWin->pos.pageId = -1; + pWin->pos.offset = -1; + } + } + clearDiskbasedBuf(pInfo->streamAggSup.pResultBuf); + cleanupResultRowInfo(&pInfo->binfo.resultRowInfo); + initResultRowInfo(&pInfo->binfo.resultRowInfo); +} + +static void removeSessionResults(SHashObj* pHashMap, SArray* pWins) { + int32_t size = taosArrayGetSize(pWins); + for (int32_t i = 0; i < size; i++) { + SResultWindowInfo* pWin = taosArrayGet(pWins, i); + taosHashRemove(pHashMap, &pWin->pos, sizeof(SResultRowPosition)); + } +} + +static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) { + SStreamSessionAggOperatorInfo* pInfo = pOperator->info; + SOptrBasicInfo* pBInfo = &pInfo->binfo; + TSKEY maxTs = INT64_MIN; + SExprSupp* pSup = &pOperator->exprSupp; + + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } else if (pOperator->status == OP_RES_TO_RETURN) { + doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator); + if (pInfo->pDelRes->info.rows > 0) { + return pInfo->pDelRes; + } + doBuildResultDatablock(pOperator, pBInfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf); + if (pInfo->binfo.pRes->info.rows == 0) { + pOperator->status = OP_EXEC_DONE; + if (pInfo->pUpdateRes->info.rows == 0) { + // semi interval operator clear disk buffer + clearStreamSessionOperator(pInfo); + return NULL; + } + // process the rest of the data + pOperator->status = OP_OPENED; + return pInfo->pUpdateRes; + } + return pInfo->binfo.pRes; + } + + _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); + SHashObj* pStUpdated = taosHashInit(64, hashFn, true, HASH_NO_LOCK); + SOperatorInfo* downstream = pOperator->pDownstream[0]; + SArray* pUpdated = taosArrayInit(16, POINTER_BYTES); + while (1) { + SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); + if (pBlock == NULL) { + clearUpdateDataBlock(pInfo->pUpdateRes); + break; + } + + if (pBlock->info.type == STREAM_REPROCESS) { + SArray* pWins = taosArrayInit(16, sizeof(SResultWindowInfo)); + doClearSessionWindows(&pInfo->streamAggSup, pSup, pBlock, 0, pSup->numOfExprs, pInfo->gap, pWins); + removeSessionResults(pStUpdated, pWins); + taosArrayDestroy(pWins); + copyUpdateDataBlock(pInfo->pUpdateRes, pBlock, pInfo->primaryTsIndex); + break; + } else if (pBlock->info.type == STREAM_GET_ALL) { + getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getResWinForSession); + continue; + } + + // the pDataBlock are always the same one, no need to call this again + setInputDataBlock(pOperator, pSup->pCtx, pBlock, TSDB_ORDER_ASC, MAIN_SCAN, true); + doStreamSessionAggImpl(pOperator, pBlock, pStUpdated, pInfo->pStDeleted, false); + maxTs = TMAX(pInfo->twAggSup.maxTs, pBlock->info.window.ekey); + } + + pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs); + // restore the value + pOperator->status = OP_RES_TO_RETURN; + // semi operator + // closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pUpdated, + // getResWinForSession); copyUpdateResult(pStUpdated, pUpdated); taosHashCleanup(pStUpdated); @@ -3002,6 +3209,15 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { return pInfo->pDelRes; } doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf); + if (pInfo->binfo.pRes->info.rows == 0) { + pOperator->status = OP_EXEC_DONE; + if (pInfo->pUpdateRes->info.rows == 0) { + return NULL; + } + // process the rest of the data + pOperator->status = OP_OPENED; + return pInfo->pUpdateRes; + } return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes; } @@ -3012,17 +3228,32 @@ SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream if (pOperator == NULL) { goto _error; } - pOperator->name = "StreamFinalSessionWindowAggOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION; SStreamSessionAggOperatorInfo* pInfo = pOperator->info; - pInfo->pChildren = taosArrayInit(8, sizeof(void*)); - for (int32_t i = 0; i < numOfChild; i++) { - SOperatorInfo* pChild = - createStreamSessionAggOperatorInfo(NULL, pPhyNode, pTaskInfo); - if (pChild == NULL) { - goto _error; + + if (pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) { + pInfo->isFinal = true; + pOperator->name = "StreamSessionFinalAggOperator"; + } else { + pInfo->isFinal = false; + pInfo->pUpdateRes = createResDataBlock(pPhyNode->pOutputDataBlockDesc); + pInfo->pUpdateRes->info.type = STREAM_REPROCESS; + blockDataEnsureCapacity(pInfo->pUpdateRes, 128); + pOperator->name = "StreamSessionSemiAggOperator"; + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, doStreamSessionSemiAgg, NULL, NULL, destroyStreamSessionAggOperatorInfo, + aggEncodeResultRow, aggDecodeResultRow, NULL); + } + pOperator->operatorType = pPhyNode->type; + if (numOfChild > 0) { + pInfo->pChildren = taosArrayInit(numOfChild, sizeof(void*)); + for (int32_t i = 0; i < numOfChild; i++) { + SOperatorInfo* pChild = + createStreamFinalSessionAggOperatorInfo(NULL, pPhyNode, pTaskInfo, 0); + if (pChild == NULL) { + goto _error; + } + taosArrayPush(pInfo->pChildren, &pChild); } - taosArrayPush(pInfo->pChildren, &pChild); } return pOperator; @@ -3331,7 +3562,7 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) { pSeUpdated, pInfo->pSeDeleted); continue; } else if (pBlock->info.type == STREAM_GET_ALL) { - getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getStateWinInfo); + getAllSessionWindow(pInfo->streamAggSup.pResultRows, pUpdated, getResWinForState); continue; } @@ -3344,7 +3575,7 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) { pOperator->status = OP_RES_TO_RETURN; closeSessionWindow(pInfo->streamAggSup.pResultRows, &pInfo->twAggSup, pUpdated, - getStateWinInfo); + getResWinForState); copyUpdateResult(pSeUpdated, pUpdated); taosHashCleanup(pSeUpdated); diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index f21cad2dd6..581935514e 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -374,11 +374,6 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { SSDataBlock* pLeftBlock = pLeftSource->src.pBlock; SSDataBlock* pRightBlock = pRightSource->src.pBlock; - // first sort by block groupId - if (pLeftBlock->info.groupId != pRightBlock->info.groupId) { - return pLeftBlock->info.groupId < pRightBlock->info.groupId ? -1 : 1; - } - for(int32_t i = 0; i < pInfo->size; ++i) { SBlockOrderInfo* pOrder = TARRAY_GET_ELEM(pInfo, i); SColumnInfoData* pLeftColInfoData = TARRAY_GET_ELEM(pLeftBlock->pDataBlock, pOrder->slotId); diff --git a/source/libs/function/inc/builtins.h b/source/libs/function/inc/builtins.h index bc91875006..256500ff8c 100644 --- a/source/libs/function/inc/builtins.h +++ b/source/libs/function/inc/builtins.h @@ -24,22 +24,24 @@ extern "C" { typedef int32_t (*FTranslateFunc)(SFunctionNode* pFunc, char* pErrBuf, int32_t len); typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow); +typedef int32_t (*FCreateMergeFuncParameters)(SNodeList* pRawParameters, SNode* pPartialRes, SNodeList** pParameters); typedef struct SBuiltinFuncDefinition { - const char* name; - EFunctionType type; - uint64_t classification; - FTranslateFunc translateFunc; - FFuncDataRequired dataRequiredFunc; - FExecGetEnv getEnvFunc; - FExecInit initFunc; - FExecProcess processFunc; - FScalarExecProcess sprocessFunc; - FExecFinalize finalizeFunc; - FExecProcess invertFunc; - FExecCombine combineFunc; - const char* pPartialFunc; - const char* pMergeFunc; + const char* name; + EFunctionType type; + uint64_t classification; + FTranslateFunc translateFunc; + FFuncDataRequired dataRequiredFunc; + FExecGetEnv getEnvFunc; + FExecInit initFunc; + FExecProcess processFunc; + FScalarExecProcess sprocessFunc; + FExecFinalize finalizeFunc; + FExecProcess invertFunc; + FExecCombine combineFunc; + const char* pPartialFunc; + const char* pMergeFunc; + FCreateMergeFuncParameters createMergeParaFuc; } SBuiltinFuncDefinition; extern const SBuiltinFuncDefinition funcMgtBuiltins[]; diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index c243c1c175..e691d562c6 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -192,6 +192,8 @@ int32_t twaFunction(SqlFunctionCtx *pCtx); int32_t twaFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock); bool getSelectivityFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); + +bool blockDistSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); int32_t blockDistFunction(SqlFunctionCtx *pCtx); int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); diff --git a/source/libs/function/inc/functionMgtInt.h b/source/libs/function/inc/functionMgtInt.h index c02c09e18a..44e1e6f7b1 100644 --- a/source/libs/function/inc/functionMgtInt.h +++ b/source/libs/function/inc/functionMgtInt.h @@ -51,8 +51,6 @@ extern "C" { #define FUNC_UDF_ID_START 5000 -extern const int funcMgtUdfNum; - #ifdef __cplusplus } #endif diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index e1375e8a6f..cfad00f458 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -419,65 +419,14 @@ static int32_t translateTopBot(SFunctionNode* pFunc, char* pErrBuf, int32_t len) return TSDB_CODE_SUCCESS; } -static int32_t translateTopBotImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isPartial) { - int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList); - - if (isPartial) { - if (2 != numOfParams) { - return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); - } - - uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; - uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; - if (!IS_NUMERIC_TYPE(para1Type) || !IS_INTEGER_TYPE(para2Type)) { - return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); - } - - // param1 - SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1); - if (nodeType(pParamNode1) != QUERY_NODE_VALUE) { - return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); - } - - SValueNode* pValue = (SValueNode*)pParamNode1; - if (pValue->node.resType.type != TSDB_DATA_TYPE_BIGINT) { - return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); - } - - if (pValue->datum.i < 1 || pValue->datum.i > 100) { - return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); - } - - pValue->notReserved = true; - - // set result type - pFunc->node.resType = - (SDataType){.bytes = getTopBotInfoSize(pValue->datum.i) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}; - } else { - if (1 != numOfParams) { - return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); - } - - uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; - if (TSDB_DATA_TYPE_BINARY != para1Type) { - return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); - } - - // Do nothing. We can only access output of partial functions as input, - // so original input type cannot be obtained, resType will be set same - // as original function input type after merge function created. +int32_t topBotCreateMergePara(SNodeList* pRawParameters, SNode* pPartialRes, SNodeList** pParameters) { + int32_t code = nodesListMakeAppend(pParameters, pPartialRes); + if (TSDB_CODE_SUCCESS == code) { + code = nodesListStrictAppend(*pParameters, nodesCloneNode(nodesListGetNode(pRawParameters, 1))); } return TSDB_CODE_SUCCESS; } -static int32_t translateTopBotPartial(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { - return translateTopBotImpl(pFunc, pErrBuf, len, true); -} - -static int32_t translateTopBotMerge(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { - return translateTopBotImpl(pFunc, pErrBuf, len, false); -} - static int32_t translateSpread(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { if (1 != LIST_LENGTH(pFunc->pParameterList)) { return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); @@ -1508,6 +1457,11 @@ static int32_t translateBlockDistFunc(SFunctionNode* pFunc, char* pErrBuf, int32 return TSDB_CODE_SUCCESS; } +static int32_t translateBlockDistInfoFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + pFunc->node.resType = (SDataType){.bytes = 128, .type = TSDB_DATA_TYPE_VARCHAR}; + return TSDB_CODE_SUCCESS; +} + static bool getBlockDistFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { pEnv->calcMemSize = sizeof(STableBlockDistInfo); return true; @@ -1722,30 +1676,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .processFunc = topFunction, .finalizeFunc = topBotFinalize, .combineFunc = topCombine, - .pPartialFunc = "_top_partial", - .pMergeFunc = "_top_merge" - }, - { - .name = "_top_partial", - .type = FUNCTION_TYPE_TOP_PARTIAL, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC, - .translateFunc = translateTopBotPartial, - .getEnvFunc = getTopBotFuncEnv, - .initFunc = topBotFunctionSetup, - .processFunc = topFunction, - .finalizeFunc = topBotPartialFinalize, - .combineFunc = topCombine, - }, - { - .name = "_top_merge", - .type = FUNCTION_TYPE_TOP_MERGE, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC, - .translateFunc = translateTopBotMerge, - .getEnvFunc = getTopBotMergeFuncEnv, - .initFunc = functionSetup, - .processFunc = topFunctionMerge, - .finalizeFunc = topBotMergeFinalize, - .combineFunc = topCombine, + .pPartialFunc = "top", + .pMergeFunc = "top", + .createMergeParaFuc = topBotCreateMergePara }, { .name = "bottom", @@ -1757,30 +1690,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .processFunc = bottomFunction, .finalizeFunc = topBotFinalize, .combineFunc = bottomCombine, - .pPartialFunc = "_bottom_partial", - .pMergeFunc = "_bottom_merge" - }, - { - .name = "_bottom_partial", - .type = FUNCTION_TYPE_BOTTOM_PARTIAL, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC, - .translateFunc = translateTopBotPartial, - .getEnvFunc = getTopBotFuncEnv, - .initFunc = topBotFunctionSetup, - .processFunc = bottomFunction, - .finalizeFunc = topBotPartialFinalize, - .combineFunc = bottomCombine, - }, - { - .name = "_bottom_merge", - .type = FUNCTION_TYPE_BOTTOM_MERGE, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC, - .translateFunc = translateTopBotMerge, - .getEnvFunc = getTopBotMergeFuncEnv, - .initFunc = functionSetup, - .processFunc = bottomFunctionMerge, - .finalizeFunc = topBotMergeFinalize, - .combineFunc = bottomCombine, + .pPartialFunc = "bottom", + .pMergeFunc = "bottom", + .createMergeParaFuc = topBotCreateMergePara }, { .name = "spread", @@ -1867,7 +1779,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "interp", .type = FUNCTION_TYPE_INTERP, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_INTERVAL_INTERPO_FUNC, + .classification = FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_INTERVAL_INTERPO_FUNC, .translateFunc = translateFirstLast, .getEnvFunc = getSelectivityFuncEnv, .initFunc = functionSetup, @@ -2510,7 +2422,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getSelectivityFuncEnv, // todo remove this function later. .initFunc = functionSetup, .processFunc = NULL, - .finalizeFunc = NULL + .finalizeFunc = NULL, + .pPartialFunc = "_select_value", + .pMergeFunc = "_select_value" }, { .name = "_block_dist", @@ -2518,8 +2432,15 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .classification = FUNC_MGT_AGG_FUNC, .translateFunc = translateBlockDistFunc, .getEnvFunc = getBlockDistFuncEnv, + .initFunc = blockDistSetup, .processFunc = blockDistFunction, .finalizeFunc = blockDistFinalize + }, + { + .name = "_block_dist_info", + .type = FUNCTION_TYPE_BLOCK_DIST_INFO, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_SCAN_PC_FUNC, + .translateFunc = translateBlockDistInfoFunc, } }; // clang-format on diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 55900c7c7e..076ae61460 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -67,8 +67,7 @@ typedef struct STopBotResItem { typedef struct STopBotRes { int32_t maxSize; - int16_t type; // store the original input type, used in merge function - int32_t numOfItems; + int16_t type; STopBotResItem* pItems; } STopBotRes; @@ -794,8 +793,8 @@ int32_t avgFunctionMerge(SqlFunctionCtx* pCtx) { SAvgRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); + int32_t start = pInput->startRowIndex; + char* data = colDataGetData(pCol, start); SAvgRes* pInputInfo = (SAvgRes*)varDataVal(data); avgTransferInfo(pInputInfo, pInfo); @@ -908,9 +907,9 @@ int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t avgPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - SAvgRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t resultBytes = getAvgInfoSize(); - char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); + SAvgRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + int32_t resultBytes = getAvgInfoSize(); + char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); memcpy(varDataVal(res), pInfo, resultBytes); varDataSetLen(res, resultBytes); @@ -1418,7 +1417,7 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { void setNullSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t rowIndex) { for (int32_t j = 0; j < pCtx->subsidiaries.num; ++j) { SqlFunctionCtx* pc = pCtx->subsidiaries.pCtx[j]; - int32_t dstSlotId = pc->pExpr->base.resSchema.slotId; + int32_t dstSlotId = pc->pExpr->base.resSchema.slotId; SColumnInfoData* pDstCol = taosArrayGet(pBlock->pDataBlock, dstSlotId); colDataAppendNULL(pDstCol, rowIndex); @@ -1481,11 +1480,13 @@ int32_t minMaxCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx, int3 if (pSBuf->assign && ((((*(double*)&pDBuf->v) < (*(double*)&pSBuf->v)) ^ isMinFunc) || !pDBuf->assign)) { *(double*)&pDBuf->v = *(double*)&pSBuf->v; replaceTupleData(&pDBuf->tuplePos, &pSBuf->tuplePos); + pDBuf->assign = true; } } else { if (pSBuf->assign && (((pDBuf->v < pSBuf->v) ^ isMinFunc) || !pDBuf->assign)) { pDBuf->v = pSBuf->v; replaceTupleData(&pDBuf->tuplePos, &pSBuf->tuplePos); + pDBuf->assign = true; } } pDResInfo->numOfRes = TMAX(pDResInfo->numOfRes, pSResInfo->numOfRes); @@ -1663,8 +1664,8 @@ int32_t stddevFunctionMerge(SqlFunctionCtx* pCtx) { SStddevRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); + int32_t start = pInput->startRowIndex; + char* data = colDataGetData(pCol, start); SStddevRes* pInputInfo = (SStddevRes*)varDataVal(data); stddevTransferInfo(pInputInfo, pInfo); @@ -1745,10 +1746,10 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { if (IS_INTEGER_TYPE(type)) { avg = pStddevRes->isum / ((double)pStddevRes->count); - pStddevRes->result = sqrt(pStddevRes->quadraticISum / ((double)pStddevRes->count) - avg * avg); + pStddevRes->result = sqrt(fabs(pStddevRes->quadraticISum / ((double)pStddevRes->count) - avg * avg)); } else { avg = pStddevRes->dsum / ((double)pStddevRes->count); - pStddevRes->result = sqrt(pStddevRes->quadraticDSum / ((double)pStddevRes->count) - avg * avg); + pStddevRes->result = sqrt(fabs(pStddevRes->quadraticDSum / ((double)pStddevRes->count) - avg * avg)); } return functionFinalize(pCtx, pBlock); @@ -1756,9 +1757,9 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t stddevPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - SStddevRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t resultBytes = getStddevInfoSize(); - char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); + SStddevRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + int32_t resultBytes = getStddevInfoSize(); + char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); memcpy(varDataVal(res), pInfo, resultBytes); varDataSetLen(res, resultBytes); @@ -2360,12 +2361,10 @@ int32_t apercentileCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) return TSDB_CODE_SUCCESS; } -int32_t getFirstLastInfoSize(int32_t resBytes) { - return sizeof(SFirstLastRes) + resBytes + sizeof(int64_t); -} +int32_t getFirstLastInfoSize(int32_t resBytes) { return sizeof(SFirstLastRes) + resBytes + sizeof(int64_t); } bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { - SColumnNode* pNode = (SColumnNode *)nodesListGetNode(pFunc->pParameterList, 0); + SColumnNode* pNode = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0); pEnv->calcMemSize = sizeof(SFirstLastRes) + pNode->node.resType.bytes + sizeof(int64_t); return true; } @@ -2390,14 +2389,14 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) { int32_t numOfElems = 0; SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - SFirstLastRes *pInfo = GET_ROWCELL_INTERBUF(pResInfo); + SFirstLastRes* pInfo = GET_ROWCELL_INTERBUF(pResInfo); SInputColumnInfoData* pInput = &pCtx->input; SColumnInfoData* pInputCol = pInput->pData[0]; - int32_t type = pInputCol->info.type; + int32_t type = pInputCol->info.type; int32_t bytes = pInputCol->info.bytes; - pInfo->bytes = bytes; + pInfo->bytes = bytes; // All null data column, return directly. if (pInput->colDataAggIsSet && (pInput->pColumnDataAgg[0]->numOfNull == pInput->totalRows)) { @@ -2488,14 +2487,14 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) { int32_t numOfElems = 0; SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - SFirstLastRes *pInfo = GET_ROWCELL_INTERBUF(pResInfo); + SFirstLastRes* pInfo = GET_ROWCELL_INTERBUF(pResInfo); SInputColumnInfoData* pInput = &pCtx->input; SColumnInfoData* pInputCol = pInput->pData[0]; - int32_t type = pInputCol->info.type; + int32_t type = pInputCol->info.type; int32_t bytes = pInputCol->info.bytes; - pInfo->bytes = bytes; + pInfo->bytes = bytes; // All null data column, return directly. if (pInput->colDataAggIsSet && (pInput->pColumnDataAgg[0]->numOfNull == pInput->totalRows)) { @@ -2563,12 +2562,9 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) { } static void firstLastTransferInfo(SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst) { - if (!pInput->hasResult) { - return; - } pOutput->bytes = pInput->bytes; - TSKEY *tsIn = (TSKEY*)(pInput->buf + pInput->bytes); - TSKEY *tsOut = (TSKEY*)(pOutput->buf + pInput->bytes); + TSKEY* tsIn = (TSKEY*)(pInput->buf + pInput->bytes); + TSKEY* tsOut = (TSKEY*)(pOutput->buf + pInput->bytes); if (pOutput->hasResult) { if (isFirst) { if (*tsIn > *tsOut) { @@ -2586,31 +2582,29 @@ static void firstLastTransferInfo(SFirstLastRes* pInput, SFirstLastRes* pOutput, return; } -static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx *pCtx, bool isFirstQuery) { +static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx* pCtx, bool isFirstQuery) { SInputColumnInfoData* pInput = &pCtx->input; - SColumnInfoData* pCol = pInput->pData[0]; + SColumnInfoData* pCol = pInput->pData[0]; ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY); SFirstLastRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); - SFirstLastRes* pInputInfo = (SFirstLastRes *)varDataVal(data); + int32_t start = pInput->startRowIndex; + char* data = colDataGetData(pCol, start); + SFirstLastRes* pInputInfo = (SFirstLastRes*)varDataVal(data); firstLastTransferInfo(pInputInfo, pInfo, isFirstQuery); - SET_VAL(GET_RES_INFO(pCtx), 1, 1); + int32_t numOfElems = pInputInfo->hasResult ? 1 : 0; + + SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); return TSDB_CODE_SUCCESS; } -int32_t firstFunctionMerge(SqlFunctionCtx *pCtx) { - return firstLastFunctionMergeImpl(pCtx, true); -} +int32_t firstFunctionMerge(SqlFunctionCtx* pCtx) { return firstLastFunctionMergeImpl(pCtx, true); } -int32_t lastFunctionMerge(SqlFunctionCtx *pCtx) { - return firstLastFunctionMergeImpl(pCtx, false); -} +int32_t lastFunctionMerge(SqlFunctionCtx* pCtx) { return firstLastFunctionMergeImpl(pCtx, false); } int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t slotId = pCtx->pExpr->base.resSchema.slotId; @@ -2627,9 +2621,10 @@ int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(pCtx); - SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t resultBytes = getFirstLastInfoSize(pRes->bytes); - char *res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); + SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + + int32_t resultBytes = getFirstLastInfoSize(pRes->bytes); + char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); memcpy(varDataVal(res), pRes, resultBytes); varDataSetLen(res, resultBytes); @@ -2876,12 +2871,6 @@ bool getTopBotFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { return true; } -bool getTopBotMergeFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { - // intermediate result is binary and length contains VAR header size - pEnv->calcMemSize = pFunc->node.resType.bytes; - return true; -} - bool topBotFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) { if (!functionSetup(pCtx, pResInfo)) { return false; @@ -2956,50 +2945,6 @@ int32_t bottomFunction(SqlFunctionCtx* pCtx) { return TSDB_CODE_SUCCESS; } -static void topBotTransferInfo(SqlFunctionCtx* pCtx, STopBotRes* pInput, bool isTopQuery) { - for (int32_t i = 0; i < pInput->numOfItems; i++) { - addResult(pCtx, &pInput->pItems[i], pInput->type, isTopQuery); - } -} - -int32_t topFunctionMerge(SqlFunctionCtx* pCtx) { - SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(pCtx); - SInputColumnInfoData* pInput = &pCtx->input; - SColumnInfoData* pCol = pInput->pData[0]; - ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY); - - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); - STopBotRes* pInputInfo = (STopBotRes*)varDataVal(data); - STopBotRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - - pInfo->maxSize = pInputInfo->maxSize; - pInfo->type = pInputInfo->type; - topBotTransferInfo(pCtx, pInputInfo, true); - SET_VAL(GET_RES_INFO(pCtx), pEntryInfo->numOfRes, pEntryInfo->numOfRes); - - return TSDB_CODE_SUCCESS; -} - -int32_t bottomFunctionMerge(SqlFunctionCtx* pCtx) { - SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(pCtx); - SInputColumnInfoData* pInput = &pCtx->input; - SColumnInfoData* pCol = pInput->pData[0]; - ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY); - - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); - STopBotRes* pInputInfo = (STopBotRes*)varDataVal(data); - STopBotRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - - pInfo->maxSize = pInputInfo->maxSize; - pInfo->type = pInputInfo->type; - topBotTransferInfo(pCtx, pInputInfo, false); - SET_VAL(GET_RES_INFO(pCtx), pEntryInfo->numOfRes, pEntryInfo->numOfRes); - - return TSDB_CODE_SUCCESS; -} - static int32_t topBotResComparFn(const void* p1, const void* p2, const void* param) { uint16_t type = *(uint16_t*)param; @@ -3048,8 +2993,6 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData // allocate the buffer and keep the data of this row into the new allocated buffer pEntryInfo->numOfRes++; - // accumulate number of items for each vgroup, this info is needed for merge - pRes->numOfItems++; taosheapsort((void*)pItems, sizeof(STopBotResItem), pEntryInfo->numOfRes, (const void*)&type, topBotResComparFn, !isTopQuery); } else { // replace the minimum value in the result @@ -3148,7 +3091,7 @@ void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS releaseBufPage(pCtx->pBuf, pPage); } -int32_t topBotFinalizeImpl(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, bool isMerge) { +int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(pCtx); STopBotRes* pRes = GET_ROWCELL_INTERBUF(pEntryInfo); @@ -3168,39 +3111,13 @@ int32_t topBotFinalizeImpl(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, bool isMer colDataAppend(pCol, currentRow, (const char*)&pItem->v.i, false); } - if (!isMerge) { - setSelectivityValue(pCtx, pBlock, &pRes->pItems[i].tuplePos, currentRow); - } + setSelectivityValue(pCtx, pBlock, &pRes->pItems[i].tuplePos, currentRow); currentRow += 1; } return pEntryInfo->numOfRes; } -int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return topBotFinalizeImpl(pCtx, pBlock, false); } - -int32_t topBotMergeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { - return topBotFinalizeImpl(pCtx, pBlock, true); -} - -int32_t topBotPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { - SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(pCtx); - STopBotRes* pRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t resultBytes = getTopBotInfoSize(pRes->maxSize); - char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); - - memcpy(varDataVal(res), pRes, resultBytes); - varDataSetLen(res, resultBytes); - - int32_t slotId = pCtx->pExpr->base.resSchema.slotId; - SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); - - colDataAppend(pCol, pBlock->info.rows, res, false); - - taosMemoryFree(res); - return 1; -} - void addResult(SqlFunctionCtx* pCtx, STopBotResItem* pSourceItem, int16_t type, bool isTopQuery) { SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(pCtx); STopBotRes* pRes = getTopBotOutputInfo(pCtx); @@ -3215,8 +3132,6 @@ void addResult(SqlFunctionCtx* pCtx, STopBotResItem* pSourceItem, int16_t type, pItem->tuplePos.pageId = -1; replaceTupleData(&pItem->tuplePos, &pSourceItem->tuplePos); pEntryInfo->numOfRes++; - // accumulate number of items for each vgroup, this info is needed for merge - pRes->numOfItems++; taosheapsort((void*)pItems, sizeof(STopBotResItem), pEntryInfo->numOfRes, (const void*)&type, topBotResComparFn, !isTopQuery); } else { // replace the minimum value in the result @@ -3369,8 +3284,8 @@ int32_t spreadFunctionMerge(SqlFunctionCtx* pCtx) { SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); + int32_t start = pInput->startRowIndex; + char* data = colDataGetData(pCol, start); SSpreadInfo* pInputInfo = (SSpreadInfo*)varDataVal(data); spreadTransferInfo(pInputInfo, pInfo); @@ -3390,9 +3305,9 @@ int32_t spreadFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t spreadPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t resultBytes = getSpreadInfoSize(); - char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); + SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + int32_t resultBytes = getSpreadInfoSize(); + char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); memcpy(varDataVal(res), pInfo, resultBytes); varDataSetLen(res, resultBytes); @@ -3484,8 +3399,8 @@ int32_t elapsedFunction(SqlFunctionCtx* pCtx) { SColumnInfoData* pCol = pInput->pData[0]; - int32_t start = pInput->startRowIndex; - TSKEY* ptsList = (int64_t*)colDataGetData(pCol, 0); + int32_t start = pInput->startRowIndex; + TSKEY* ptsList = (int64_t*)colDataGetData(pCol, 0); if (pCtx->order == TSDB_ORDER_DESC) { if (pCtx->start.key == INT64_MIN) { pInfo->max = @@ -5008,7 +4923,19 @@ int32_t twaFinalize(struct SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return functionFinalize(pCtx, pBlock); } +bool blockDistSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { + if (!functionSetup(pCtx, pResultInfo)) { + return false; + } + + STableBlockDistInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + pInfo->minRows = INT32_MAX; + return true; +} + int32_t blockDistFunction(SqlFunctionCtx* pCtx) { + const int32_t BLOCK_DIST_RESULT_ROWS = 24; + SInputColumnInfoData* pInput = &pCtx->input; SColumnInfoData* pInputCol = pInput->pData[0]; @@ -5026,6 +4953,11 @@ int32_t blockDistFunction(SqlFunctionCtx* pCtx) { pDistInfo->totalRows += p1.totalRows; pDistInfo->numOfFiles += p1.numOfFiles; + pDistInfo->defMinRows = p1.defMinRows; + pDistInfo->defMaxRows = p1.defMaxRows; + pDistInfo->rowSize = p1.rowSize; + pDistInfo->numOfSmallBlocks = p1.numOfSmallBlocks; + if (pDistInfo->minRows > p1.minRows) { pDistInfo->minRows = p1.minRows; } @@ -5037,7 +4969,7 @@ int32_t blockDistFunction(SqlFunctionCtx* pCtx) { pDistInfo->blockRowsHisto[i] += p1.blockRowsHisto[i]; } - pResInfo->numOfRes = 1; + pResInfo->numOfRes = BLOCK_DIST_RESULT_ROWS; // default output rows return TSDB_CODE_SUCCESS; } @@ -5049,7 +4981,7 @@ int32_t tSerializeBlockDistInfo(void* buf, int32_t bufLen, const STableBlockDist if (tEncodeU32(&encoder, pInfo->rowSize) < 0) return -1; if (tEncodeU16(&encoder, pInfo->numOfFiles) < 0) return -1; - if (tEncodeU32(&encoder, pInfo->rowSize) < 0) return -1; + if (tEncodeU32(&encoder, pInfo->numOfBlocks) < 0) return -1; if (tEncodeU32(&encoder, pInfo->numOfTables) < 0) return -1; if (tEncodeU64(&encoder, pInfo->totalSize) < 0) return -1; @@ -5080,7 +5012,7 @@ int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo if (tDecodeU32(&decoder, &pInfo->rowSize) < 0) return -1; if (tDecodeU16(&decoder, &pInfo->numOfFiles) < 0) return -1; - if (tDecodeU32(&decoder, &pInfo->rowSize) < 0) return -1; + if (tDecodeU32(&decoder, &pInfo->numOfBlocks) < 0) return -1; if (tDecodeU32(&decoder, &pInfo->numOfTables) < 0) return -1; if (tDecodeU64(&decoder, &pInfo->totalSize) < 0) return -1; @@ -5102,32 +5034,29 @@ int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - char* pData = GET_ROWCELL_INTERBUF(pResInfo); + STableBlockDistInfo* pData = GET_ROWCELL_INTERBUF(pResInfo); SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 0); int32_t row = 0; - - STableBlockDistInfo info = {0}; - tDeserializeBlockDistInfo(varDataVal(pData), varDataLen(pData), &info); - char st[256] = {0}; + double totalRawSize = pData->totalRows * pData->rowSize; int32_t len = - sprintf(st + VARSTR_HEADER_SIZE, "Blocks=[%d] Size=[%.3fKb] Average_Block_size=[%.3fKb] Compression_Ratio=[%.3f]", - info.numOfBlocks, info.totalSize / 1024.0, info.totalSize / (info.numOfBlocks * 1024.0), - info.totalSize / (info.totalRows * info.rowSize * 1.0)); + sprintf(st + VARSTR_HEADER_SIZE, "Total_Blocks=[%d] Total_Size=[%.2f Kb] Average_size=[%.2f Kb] Compression_Ratio=[%.2f %c]", + pData->numOfBlocks, pData->totalSize / 1024.0, ((double)pData->totalSize) / pData->numOfBlocks, + pData->totalSize * 100 / totalRawSize, '%'); varDataSetLen(st, len); colDataAppend(pColInfo, row++, st, false); - len = sprintf(st + VARSTR_HEADER_SIZE, "Total_Rows=[%ld] MinRows=[%d] MaxRows=[%d] Averge_Rows=[%ld] Inmem_Rows=[%d]", - info.totalRows, info.minRows, info.maxRows, info.totalRows / info.numOfBlocks, info.numOfInmemRows); + len = sprintf(st + VARSTR_HEADER_SIZE, "Total_Rows=[%"PRId64"] Inmem_Rows=[%d] MinRows=[%d] MaxRows=[%d] Average_Rows=[%"PRId64"]", + pData->totalRows, pData->numOfInmemRows, pData->minRows, pData->maxRows, pData->totalRows / pData->numOfBlocks); varDataSetLen(st, len); colDataAppend(pColInfo, row++, st, false); - len = sprintf(st + VARSTR_HEADER_SIZE, "Total_Tables=[%d] Total_Files=[%d] Total_Vgroups=[%d]", info.numOfTables, - info.numOfFiles, 0); + len = sprintf(st + VARSTR_HEADER_SIZE, "Total_Tables=[%d] Total_Files=[%d] Total_Vgroups=[%d]", pData->numOfTables, + pData->numOfFiles, 0); varDataSetLen(st, len); colDataAppend(pColInfo, row++, st, false); @@ -5139,48 +5068,64 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t maxVal = 0; int32_t minVal = INT32_MAX; - for (int32_t i = 0; i < sizeof(info.blockRowsHisto) / sizeof(info.blockRowsHisto[0]); ++i) { - if (maxVal < info.blockRowsHisto[i]) { - maxVal = info.blockRowsHisto[i]; + for (int32_t i = 0; i < tListLen(pData->blockRowsHisto); ++i) { + if (maxVal < pData->blockRowsHisto[i]) { + maxVal = pData->blockRowsHisto[i]; } - if (minVal > info.blockRowsHisto[i]) { - minVal = info.blockRowsHisto[i]; + if (minVal > pData->blockRowsHisto[i]) { + minVal = pData->blockRowsHisto[i]; } } int32_t delta = maxVal - minVal; int32_t step = delta / 50; + if (step == 0) { + step = 1; + } - int32_t numOfBuckets = sizeof(info.blockRowsHisto) / sizeof(info.blockRowsHisto[0]); - int32_t bucketRange = (info.maxRows - info.minRows) / numOfBuckets; + int32_t numOfBuckets = sizeof(pData->blockRowsHisto) / sizeof(pData->blockRowsHisto[0]); + int32_t bucketRange = (pData->maxRows - pData->minRows) / numOfBuckets; - for (int32_t i = 0; i < 20; ++i) { - len += sprintf(st + VARSTR_HEADER_SIZE, "%04d |", info.defMinRows + bucketRange * (i + 1)); + bool singleModel = false; + if (bucketRange == 0) { + singleModel = true; + step = 20; + bucketRange = (pData->defMaxRows - pData->defMinRows) / numOfBuckets; + } + + for (int32_t i = 0; i < tListLen(pData->blockRowsHisto); ++i) { + len = sprintf(st + VARSTR_HEADER_SIZE, "%04d |", pData->defMinRows + bucketRange * (i + 1)); + + int32_t num = 0; + if (singleModel && pData->blockRowsHisto[i] > 0) { + num = 20; + } else { + num = (pData->blockRowsHisto[i] + step - 1) / step; + } - int32_t num = (info.blockRowsHisto[i] + step - 1) / step; for (int32_t j = 0; j < num; ++j) { int32_t x = sprintf(st + VARSTR_HEADER_SIZE + len, "%c", '|'); len += x; } - double v = info.blockRowsHisto[i] * 100.0 / info.numOfBlocks; - len += sprintf(st + VARSTR_HEADER_SIZE + len, " %d (%.3f%c)", info.blockRowsHisto[i], v, '%'); + double v = pData->blockRowsHisto[i] * 100.0 / pData->numOfBlocks; + len += sprintf(st + VARSTR_HEADER_SIZE + len, " %d (%.2f%c)", pData->blockRowsHisto[i], v, '%'); printf("%s\n", st); varDataSetLen(st, len); colDataAppend(pColInfo, row++, st, false); } - return row; + return TSDB_CODE_SUCCESS; } typedef struct SDerivInfo { - double prevValue; // previous value - TSKEY prevTs; // previous timestamp - bool ignoreNegative;// ignore the negative value - int64_t tsWindow; // time window for derivative - bool valueSet; // the value has been set already + double prevValue; // previous value + TSKEY prevTs; // previous timestamp + bool ignoreNegative; // ignore the negative value + int64_t tsWindow; // time window for derivative + bool valueSet; // the value has been set already } SDerivInfo; bool getDerivativeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) { @@ -5188,7 +5133,7 @@ bool getDerivativeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) { return true; } -bool derivativeFuncSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo) { +bool derivativeFuncSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) { if (!functionSetup(pCtx, pResInfo)) { return false; // not initialized since it has been initialized } @@ -5196,25 +5141,25 @@ bool derivativeFuncSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo) { SDerivInfo* pDerivInfo = GET_ROWCELL_INTERBUF(pResInfo); pDerivInfo->ignoreNegative = pCtx->param[2].param.i; - pDerivInfo->prevTs = -1; + pDerivInfo->prevTs = -1; pDerivInfo->tsWindow = pCtx->param[1].param.i; pDerivInfo->valueSet = false; return true; } -int32_t derivativeFunction(SqlFunctionCtx *pCtx) { - SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); - SDerivInfo* pDerivInfo = GET_ROWCELL_INTERBUF(pResInfo); +int32_t derivativeFunction(SqlFunctionCtx* pCtx) { + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + SDerivInfo* pDerivInfo = GET_ROWCELL_INTERBUF(pResInfo); SInputColumnInfoData* pInput = &pCtx->input; - SColumnInfoData* pInputCol = pInput->pData[0]; + SColumnInfoData* pInputCol = pInput->pData[0]; - int32_t numOfElems = 0; + int32_t numOfElems = 0; SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput; SColumnInfoData* pTsOutput = pCtx->pTsOutput; int32_t i = pInput->startRowIndex; - TSKEY* tsList = (int64_t*)pInput->pPTS->pData; + TSKEY* tsList = (int64_t*)pInput->pPTS->pData; double v = 0; @@ -5224,7 +5169,7 @@ int32_t derivativeFunction(SqlFunctionCtx *pCtx) { continue; } - char* d = (char*)pInputCol->pData + pInputCol->info.bytes * i; + char* d = (char*)pInputCol->pData + pInputCol->info.bytes * i; GET_TYPED_DATA(v, double, pInputCol->info.type, d); int32_t pos = pCtx->offset + numOfElems; @@ -5251,7 +5196,7 @@ int32_t derivativeFunction(SqlFunctionCtx *pCtx) { continue; } - char* d = (char*)pInputCol->pData + pInputCol->info.bytes * i; + char* d = (char*)pInputCol->pData + pInputCol->info.bytes * i; GET_TYPED_DATA(v, double, pInputCol->info.type, d); int32_t pos = pCtx->offset + numOfElems; @@ -5277,7 +5222,7 @@ int32_t derivativeFunction(SqlFunctionCtx *pCtx) { return numOfElems; } -int32_t interpFunction(SqlFunctionCtx *pCtx) { +int32_t interpFunction(SqlFunctionCtx* pCtx) { #if 0 int32_t fillType = (int32_t) pCtx->param[2].i64; //bool ascQuery = (pCtx->order == TSDB_ORDER_ASC); @@ -5368,4 +5313,4 @@ int32_t interpFunction(SqlFunctionCtx *pCtx) { #endif return TSDB_CODE_SUCCESS; -} \ No newline at end of file +} diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index 7dbe456d4a..710b01ce59 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -70,11 +70,21 @@ int32_t fmFuncMgtInit() { } int32_t fmGetFuncInfo(SFunctionNode* pFunc, char* pMsg, int32_t msgLen) { - void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName)); - if (NULL != pVal) { - pFunc->funcId = *(int32_t*)pVal; - pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type; - return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pMsg, msgLen); + if (NULL != gFunMgtService.pFuncNameHashTable) { + void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName)); + if (NULL != pVal) { + pFunc->funcId = *(int32_t*)pVal; + pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type; + return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pMsg, msgLen); + } + return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION; + } + for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) { + if (0 == strcmp(funcMgtBuiltins[i].name, pFunc->functionName)) { + pFunc->funcId = i; + pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type; + return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pMsg, msgLen); + } } return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION; } @@ -169,6 +179,13 @@ bool fmIsForbidWindowFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId bool fmIsForbidGroupByFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORBID_GROUP_BY_FUNC); } +bool fmIsInterpFunc(int32_t funcId) { + if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { + return false; + } + return FUNCTION_TYPE_INTERP == funcMgtBuiltins[funcId].type; +} + void fmFuncMgtDestroy() { void* m = gFunMgtService.pFuncNameHashTable; if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) { @@ -233,17 +250,7 @@ bool fmIsSameInOutType(int32_t funcId) { static int32_t getFuncInfo(SFunctionNode* pFunc) { char msg[64] = {0}; - if (NULL != gFunMgtService.pFuncNameHashTable) { - return fmGetFuncInfo(pFunc, msg, sizeof(msg)); - } - for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) { - if (0 == strcmp(funcMgtBuiltins[i].name, pFunc->functionName)) { - pFunc->funcId = i; - pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type; - return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, msg, sizeof(msg)); - } - } - return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION; + return fmGetFuncInfo(pFunc, msg, sizeof(msg)); } static SFunctionNode* createFunction(const char* pName, SNodeList* pParameterList) { @@ -261,14 +268,14 @@ static SFunctionNode* createFunction(const char* pName, SNodeList* pParameterLis return pFunc; } -static SColumnNode* createColumnByFunc(const SFunctionNode* pFunc) { +static SNode* createColumnByFunc(const SFunctionNode* pFunc) { SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); if (NULL == pCol) { return NULL; } strcpy(pCol->colName, pFunc->node.aliasName); pCol->node.resType = pFunc->node.resType; - return pCol; + return (SNode*)pCol; } bool fmIsDistExecFunc(int32_t funcId) { @@ -296,21 +303,47 @@ static int32_t createPartialFunction(const SFunctionNode* pSrcFunc, SFunctionNod return TSDB_CODE_SUCCESS; } +static int32_t createMergeFuncPara(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc, + SNodeList** pParameterList) { + SNode* pRes = createColumnByFunc(pPartialFunc); + if (NULL != funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc) { + return funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc(pSrcFunc->pParameterList, pRes, pParameterList); + } else { + return nodesListMakeStrictAppend(pParameterList, pRes); + } +} + static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc, SFunctionNode** pMergeFunc) { - SNodeList* pParameterList = NULL; - nodesListMakeStrictAppend(&pParameterList, (SNode*)createColumnByFunc(pPartialFunc)); - *pMergeFunc = createFunction(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pParameterList); - if (NULL == *pMergeFunc) { + SNodeList* pParameterList = NULL; + SFunctionNode* pFunc = NULL; + + int32_t code = createMergeFuncPara(pSrcFunc, pPartialFunc, &pParameterList); + if (TSDB_CODE_SUCCESS == code) { + pFunc = createFunction(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pParameterList); + if (NULL == pFunc) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + } + if (TSDB_CODE_SUCCESS == code) { + // overwrite function restype set by translate function + if (fmIsSameInOutType(pSrcFunc->funcId)) { + pFunc->node.resType = pSrcFunc->node.resType; + } + strcpy(pFunc->node.aliasName, pSrcFunc->node.aliasName); + } + + if (TSDB_CODE_SUCCESS == code) { + *pMergeFunc = pFunc; + } else { + if (NULL != pFunc) { + pFunc->pParameterList = NULL; + nodesDestroyNode((SNode*)pFunc); + } nodesDestroyList(pParameterList); - return TSDB_CODE_OUT_OF_MEMORY; } - // overwrite function restype set by translate function - if (fmIsSameInOutType(pSrcFunc->funcId)) { - (*pMergeFunc)->node.resType = pSrcFunc->node.resType; - } - strcpy((*pMergeFunc)->node.aliasName, pSrcFunc->node.aliasName); - return TSDB_CODE_SUCCESS; + + return code; } int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc) { diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index 472d672607..f6ae027e48 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -972,6 +972,11 @@ void releaseUdfFuncHandle(char* udfName) { } int32_t cleanUpUdfs() { + int8_t initialized = atomic_load_8(&gUdfdProxy.initialized); + if (!initialized) { + return TSDB_CODE_SUCCESS; + } + uv_mutex_lock(&gUdfdProxy.udfStubsMutex); int32_t i = 0; SArray* udfStubs = taosArrayInit(16, sizeof(SUdfcFuncStub)); diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 02c6c582e3..101edbd38d 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -424,6 +424,7 @@ static SNode* logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pD COPY_SCALAR_FIELD(slidingUnit); COPY_SCALAR_FIELD(sessionGap); CLONE_NODE_FIELD(pTspk); + CLONE_NODE_FIELD(pTsEnd); CLONE_NODE_FIELD(pStateExpr); COPY_SCALAR_FIELD(triggerType); COPY_SCALAR_FIELD(watermark); @@ -455,7 +456,18 @@ static SNode* logicPartitionCopy(const SPartitionLogicNode* pSrc, SPartitionLogi static SNode* logicIndefRowsFuncCopy(const SIndefRowsFuncLogicNode* pSrc, SIndefRowsFuncLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); - CLONE_NODE_LIST_FIELD(pVectorFuncs); + CLONE_NODE_LIST_FIELD(pFuncs); + return (SNode*)pDst; +} + +static SNode* logicInterpFuncCopy(const SInterpFuncLogicNode* pSrc, SInterpFuncLogicNode* pDst) { + COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); + CLONE_NODE_LIST_FIELD(pFuncs); + COPY_OBJECT_FIELD(timeRange, sizeof(STimeWindow)); + COPY_SCALAR_FIELD(interval); + COPY_SCALAR_FIELD(fillMode); + CLONE_NODE_FIELD(pFillValues); + CLONE_NODE_FIELD(pTimeSeries); return (SNode*)pDst; } @@ -523,6 +535,7 @@ static SNode* physiWindowCopy(const SWinodwPhysiNode* pSrc, SWinodwPhysiNode* pD CLONE_NODE_LIST_FIELD(pExprs); CLONE_NODE_LIST_FIELD(pFuncs); CLONE_NODE_FIELD(pTspk); + CLONE_NODE_FIELD(pTsEnd); COPY_SCALAR_FIELD(triggerType); COPY_SCALAR_FIELD(watermark); COPY_SCALAR_FIELD(filesFactor); @@ -669,6 +682,8 @@ SNode* nodesCloneNode(const SNode* pNode) { return logicPartitionCopy((const SPartitionLogicNode*)pNode, (SPartitionLogicNode*)pDst); case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: return logicIndefRowsFuncCopy((const SIndefRowsFuncLogicNode*)pNode, (SIndefRowsFuncLogicNode*)pDst); + case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC: + return logicInterpFuncCopy((const SInterpFuncLogicNode*)pNode, (SInterpFuncLogicNode*)pDst); case QUERY_NODE_LOGIC_SUBPLAN: return logicSubplanCopy((const SLogicSubplan*)pNode, (SLogicSubplan*)pDst); case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 3d5e018dfa..9b634d68d5 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -202,6 +202,8 @@ const char* nodesNodeName(ENodeType type) { return "LogicPartition"; case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: return "LogicIndefRowsFunc"; + case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC: + return "LogicInterpFunc"; case QUERY_NODE_LOGIC_SUBPLAN: return "LogicSubplan"; case QUERY_NODE_LOGIC_PLAN: @@ -216,6 +218,8 @@ const char* nodesNodeName(ENodeType type) { return "PhysiSreamScan"; case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: return "PhysiSystemTableScan"; + case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: + return "PhysiBlockDistScan"; case QUERY_NODE_PHYSICAL_PLAN_PROJECT: return "PhysiProject"; case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: @@ -256,6 +260,8 @@ const char* nodesNodeName(ENodeType type) { return "PhysiPartition"; case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC: return "PhysiIndefRowsFunc"; + case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC: + return "PhysiInterpFunc"; case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return "PhysiDispatch"; case QUERY_NODE_PHYSICAL_PLAN_INSERT: @@ -933,14 +939,14 @@ static int32_t jsonToLogicPartitionNode(const SJson* pJson, void* pObj) { return code; } -static const char* jkIndefRowsFuncLogicPlanVectorFuncs = "VectorFuncs"; +static const char* jkIndefRowsFuncLogicPlanFuncs = "Funcs"; static int32_t logicIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) { const SIndefRowsFuncLogicNode* pNode = (const SIndefRowsFuncLogicNode*)pObj; int32_t code = logicPlanNodeToJson(pObj, pJson); if (TSDB_CODE_SUCCESS == code) { - code = nodeListToJson(pJson, jkIndefRowsFuncLogicPlanVectorFuncs, pNode->pVectorFuncs); + code = nodeListToJson(pJson, jkIndefRowsFuncLogicPlanFuncs, pNode->pFuncs); } return code; @@ -951,7 +957,52 @@ static int32_t jsonToLogicIndefRowsFuncNode(const SJson* pJson, void* pObj) { int32_t code = jsonToLogicPlanNode(pJson, pObj); if (TSDB_CODE_SUCCESS == code) { - code = jsonToNodeList(pJson, jkIndefRowsFuncLogicPlanVectorFuncs, &pNode->pVectorFuncs); + code = jsonToNodeList(pJson, jkIndefRowsFuncLogicPlanFuncs, &pNode->pFuncs); + } + + return code; +} + +static const char* jkInterpFuncLogicPlanFuncs = "Funcs"; +static const char* jkInterpFuncLogicPlanStartTime = "StartTime"; +static const char* jkInterpFuncLogicPlanEndTime = "EndTime"; +static const char* jkInterpFuncLogicPlanInterval = "Interval"; + +static int32_t logicInterpFuncNodeToJson(const void* pObj, SJson* pJson) { + const SInterpFuncLogicNode* pNode = (const SInterpFuncLogicNode*)pObj; + + int32_t code = logicPlanNodeToJson(pObj, pJson); + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkInterpFuncLogicPlanFuncs, pNode->pFuncs); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkInterpFuncLogicPlanStartTime, pNode->timeRange.skey); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkInterpFuncLogicPlanEndTime, pNode->timeRange.ekey); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkInterpFuncLogicPlanInterval, pNode->interval); + } + + return code; +} + +static int32_t jsonToLogicInterpFuncNode(const SJson* pJson, void* pObj) { + SInterpFuncLogicNode* pNode = (SInterpFuncLogicNode*)pObj; + + int32_t code = jsonToLogicPlanNode(pJson, pObj); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkInterpFuncLogicPlanFuncs, &pNode->pFuncs); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkInterpFuncLogicPlanStartTime, &pNode->timeRange.skey); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkInterpFuncLogicPlanEndTime, &pNode->timeRange.ekey); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkInterpFuncLogicPlanInterval, &pNode->interval); } return code; @@ -1782,6 +1833,7 @@ static int32_t jsonToPhysiSortNode(const SJson* pJson, void* pObj) { static const char* jkWindowPhysiPlanExprs = "Exprs"; static const char* jkWindowPhysiPlanFuncs = "Funcs"; static const char* jkWindowPhysiPlanTsPk = "TsPk"; +static const char* jkWindowPhysiPlanTsEnd = "TsEnd"; static const char* jkWindowPhysiPlanTriggerType = "TriggerType"; static const char* jkWindowPhysiPlanWatermark = "Watermark"; static const char* jkWindowPhysiPlanFilesFactor = "FilesFactor"; @@ -1799,6 +1851,9 @@ static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddObject(pJson, jkWindowPhysiPlanTsPk, nodeToJson, pNode->pTspk); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkWindowPhysiPlanTsEnd, nodeToJson, pNode->pTsEnd); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType); } @@ -1825,6 +1880,9 @@ static int32_t jsonToPhysiWindowNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsPk, (SNode**)&pNode->pTspk); } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsEnd, (SNode**)&pNode->pTsEnd); + } if (TSDB_CODE_SUCCESS == code) { tjsonGetNumberValue(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType, code); ; @@ -2040,7 +2098,7 @@ static int32_t jsonToPhysiPartitionNode(const SJson* pJson, void* pObj) { } static const char* jkIndefRowsFuncPhysiPlanExprs = "Exprs"; -static const char* jkIndefRowsFuncPhysiPlanVectorFuncs = "VectorFuncs"; +static const char* jkIndefRowsFuncPhysiPlanFuncs = "Funcs"; static int32_t physiIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) { const SIndefRowsFuncPhysiNode* pNode = (const SIndefRowsFuncPhysiNode*)pObj; @@ -2050,7 +2108,7 @@ static int32_t physiIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) { code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanExprs, pNode->pExprs); } if (TSDB_CODE_SUCCESS == code) { - code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanVectorFuncs, pNode->pVectorFuncs); + code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanFuncs, pNode->pFuncs); } return code; @@ -2064,7 +2122,80 @@ static int32_t jsonToPhysiIndefRowsFuncNode(const SJson* pJson, void* pObj) { code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanExprs, &pNode->pExprs); } if (TSDB_CODE_SUCCESS == code) { - code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanVectorFuncs, &pNode->pVectorFuncs); + code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanFuncs, &pNode->pFuncs); + } + + return code; +} + +static const char* jkInterpFuncPhysiPlanExprs = "Exprs"; +static const char* jkInterpFuncPhysiPlanFuncs = "Funcs"; +static const char* jkInterpFuncPhysiPlanStartTime = "StartTime"; +static const char* jkInterpFuncPhysiPlanEndTime = "EndTime"; +static const char* jkInterpFuncPhysiPlanInterval = "Interval"; +static const char* jkInterpFuncPhysiPlanFillMode = "FillMode"; +static const char* jkInterpFuncPhysiPlanFillValues = "FillValues"; +static const char* jkInterpFuncPhysiPlanTimeSeries = "TimeSeries"; + +static int32_t physiInterpFuncNodeToJson(const void* pObj, SJson* pJson) { + const SInterpFuncPhysiNode* pNode = (const SInterpFuncPhysiNode*)pObj; + + int32_t code = physicPlanNodeToJson(pObj, pJson); + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkInterpFuncPhysiPlanExprs, pNode->pExprs); + } + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkInterpFuncPhysiPlanFuncs, pNode->pFuncs); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkInterpFuncPhysiPlanStartTime, pNode->timeRange.skey); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkInterpFuncPhysiPlanEndTime, pNode->timeRange.ekey); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkInterpFuncPhysiPlanInterval, pNode->interval); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkInterpFuncPhysiPlanFillMode, pNode->fillMode); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkInterpFuncPhysiPlanFillValues, nodeToJson, pNode->pFillValues); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkInterpFuncPhysiPlanTimeSeries, nodeToJson, pNode->pTimeSeries); + } + + return code; +} + +static int32_t jsonToPhysiInterpFuncNode(const SJson* pJson, void* pObj) { + SInterpFuncPhysiNode* pNode = (SInterpFuncPhysiNode*)pObj; + + int32_t code = jsonToPhysicPlanNode(pJson, pObj); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkInterpFuncPhysiPlanExprs, &pNode->pExprs); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkInterpFuncPhysiPlanFuncs, &pNode->pFuncs); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkInterpFuncPhysiPlanStartTime, &pNode->timeRange.skey); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkInterpFuncPhysiPlanEndTime, &pNode->timeRange.ekey); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkInterpFuncPhysiPlanInterval, &pNode->interval); + } + if (TSDB_CODE_SUCCESS == code) { + tjsonGetNumberValue(pJson, jkInterpFuncPhysiPlanFillMode, pNode->fillMode, code); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkInterpFuncPhysiPlanFillValues, &pNode->pFillValues); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkInterpFuncPhysiPlanTimeSeries, &pNode->pTimeSeries); } return code; @@ -3973,11 +4104,14 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { return logicPartitionNodeToJson(pObj, pJson); case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: return logicIndefRowsFuncNodeToJson(pObj, pJson); + case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC: + return logicInterpFuncNodeToJson(pObj, pJson); case QUERY_NODE_LOGIC_SUBPLAN: return logicSubplanToJson(pObj, pJson); case QUERY_NODE_LOGIC_PLAN: return logicPlanToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: return physiTagScanNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN: @@ -4017,6 +4151,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { return physiPartitionNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC: return physiIndefRowsFuncNodeToJson(pObj, pJson); + case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC: + return physiInterpFuncNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return physiDispatchNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_INSERT: @@ -4108,11 +4244,14 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToLogicPartitionNode(pJson, pObj); case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: return jsonToLogicIndefRowsFuncNode(pJson, pObj); + case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC: + return jsonToLogicInterpFuncNode(pJson, pObj); case QUERY_NODE_LOGIC_SUBPLAN: return jsonToLogicSubplan(pJson, pObj); case QUERY_NODE_LOGIC_PLAN: return jsonToLogicPlan(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: return jsonToPhysiTagScanNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN: @@ -4152,6 +4291,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToPhysiPartitionNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC: return jsonToPhysiIndefRowsFuncNode(pJson, pObj); + case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC: + return jsonToPhysiInterpFuncNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return jsonToPhysiDispatchNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_DELETE: diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 3561a7f8ea..e49e4952d3 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -207,14 +207,19 @@ SNode* nodesMakeNode(ENodeType type) { case QUERY_NODE_SHOW_VNODES_STMT: case QUERY_NODE_SHOW_APPS_STMT: case QUERY_NODE_SHOW_SCORES_STMT: - case QUERY_NODE_SHOW_VARIABLE_STMT: + case QUERY_NODE_SHOW_VARIABLES_STMT: + case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: case QUERY_NODE_SHOW_TRANSACTIONS_STMT: return makeNode(type, sizeof(SShowStmt)); + case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT: + return makeNode(type, sizeof(SShowDnodeVariablesStmt)); case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: return makeNode(type, sizeof(SShowCreateDatabaseStmt)); case QUERY_NODE_SHOW_CREATE_TABLE_STMT: case QUERY_NODE_SHOW_CREATE_STABLE_STMT: return makeNode(type, sizeof(SShowCreateTableStmt)); + case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT: + return makeNode(type, sizeof(SShowTableDistributedStmt)); case QUERY_NODE_KILL_QUERY_STMT: return makeNode(type, sizeof(SKillQueryStmt)); case QUERY_NODE_KILL_TRANSACTION_STMT: @@ -248,6 +253,8 @@ SNode* nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SPartitionLogicNode)); case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: return makeNode(type, sizeof(SIndefRowsFuncLogicNode)); + case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC: + return makeNode(type, sizeof(SInterpFuncLogicNode)); case QUERY_NODE_LOGIC_SUBPLAN: return makeNode(type, sizeof(SLogicSubplan)); case QUERY_NODE_LOGIC_PLAN: @@ -264,6 +271,8 @@ SNode* nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SStreamScanPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: return makeNode(type, sizeof(SSystemTableScanPhysiNode)); + case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: + return makeNode(type, sizeof(SBlockDistScanPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_PROJECT: return makeNode(type, sizeof(SProjectPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: @@ -304,6 +313,8 @@ SNode* nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SPartitionPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC: return makeNode(type, sizeof(SIndefRowsFuncPhysiNode)); + case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC: + return makeNode(type, sizeof(SInterpFuncLogicNode)); case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return makeNode(type, sizeof(SDataDispatcherNode)); case QUERY_NODE_PHYSICAL_PLAN_INSERT: @@ -348,6 +359,7 @@ static void destroyWinodwPhysiNode(SWinodwPhysiNode* pNode) { nodesDestroyList(pNode->pExprs); nodesDestroyList(pNode->pFuncs); nodesDestroyNode(pNode->pTspk); + nodesDestroyNode(pNode->pTsEnd); } static void destroyScanPhysiNode(SScanPhysiNode* pNode) { @@ -521,6 +533,7 @@ void nodesDestroyNode(SNode* pNode) { SCreateSubTableClause* pStmt = (SCreateSubTableClause*)pNode; nodesDestroyList(pStmt->pSpecificTags); nodesDestroyList(pStmt->pValsOfTags); + nodesDestroyNode((SNode*)pStmt->pOptions); break; } case QUERY_NODE_CREATE_MULTI_TABLE_STMT: @@ -627,19 +640,27 @@ void nodesDestroyNode(SNode* pNode) { case QUERY_NODE_SHOW_VNODES_STMT: case QUERY_NODE_SHOW_APPS_STMT: case QUERY_NODE_SHOW_SCORES_STMT: - case QUERY_NODE_SHOW_VARIABLE_STMT: - case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: - case QUERY_NODE_SHOW_CREATE_TABLE_STMT: - case QUERY_NODE_SHOW_CREATE_STABLE_STMT: + case QUERY_NODE_SHOW_VARIABLES_STMT: + case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: case QUERY_NODE_SHOW_TRANSACTIONS_STMT: { SShowStmt* pStmt = (SShowStmt*)pNode; nodesDestroyNode(pStmt->pDbName); - nodesDestroyNode(pStmt->pTbNamePattern); + nodesDestroyNode(pStmt->pTbName); break; } - case QUERY_NODE_KILL_CONNECTION_STMT: // no pointer field - case QUERY_NODE_KILL_QUERY_STMT: // no pointer field - case QUERY_NODE_KILL_TRANSACTION_STMT: // no pointer field + case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT: // no pointer field + break; + case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: + taosMemoryFreeClear(((SShowCreateDatabaseStmt*)pNode)->pCfg); + break; + case QUERY_NODE_SHOW_CREATE_TABLE_STMT: + case QUERY_NODE_SHOW_CREATE_STABLE_STMT: + taosMemoryFreeClear(((SShowCreateTableStmt*)pNode)->pMeta); + break; + case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT: // no pointer field + case QUERY_NODE_KILL_CONNECTION_STMT: // no pointer field + case QUERY_NODE_KILL_QUERY_STMT: // no pointer field + case QUERY_NODE_KILL_TRANSACTION_STMT: // no pointer field break; case QUERY_NODE_DELETE_STMT: { SDeleteStmt* pStmt = (SDeleteStmt*)pNode; @@ -715,6 +736,7 @@ void nodesDestroyNode(SNode* pNode) { destroyLogicNode((SLogicNode*)pLogicNode); nodesDestroyList(pLogicNode->pFuncs); nodesDestroyNode(pLogicNode->pTspk); + nodesDestroyNode(pLogicNode->pTsEnd); break; } case QUERY_NODE_LOGIC_PLAN_FILL: { @@ -739,7 +761,13 @@ void nodesDestroyNode(SNode* pNode) { case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: { SIndefRowsFuncLogicNode* pLogicNode = (SIndefRowsFuncLogicNode*)pNode; destroyLogicNode((SLogicNode*)pLogicNode); - nodesDestroyList(pLogicNode->pVectorFuncs); + nodesDestroyList(pLogicNode->pFuncs); + break; + } + case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC: { + SInterpFuncLogicNode* pLogicNode = (SInterpFuncLogicNode*)pNode; + destroyLogicNode((SLogicNode*)pLogicNode); + nodesDestroyList(pLogicNode->pFuncs); break; } case QUERY_NODE_LOGIC_SUBPLAN: { @@ -758,6 +786,7 @@ void nodesDestroyNode(SNode* pNode) { case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN: case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: destroyScanPhysiNode((SScanPhysiNode*)pNode); break; case QUERY_NODE_PHYSICAL_PLAN_PROJECT: { @@ -841,7 +870,14 @@ void nodesDestroyNode(SNode* pNode) { SIndefRowsFuncPhysiNode* pPhyNode = (SIndefRowsFuncPhysiNode*)pNode; destroyPhysiNode((SPhysiNode*)pPhyNode); nodesDestroyList(pPhyNode->pExprs); - nodesDestroyList(pPhyNode->pVectorFuncs); + nodesDestroyList(pPhyNode->pFuncs); + break; + } + case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC: { + SInterpFuncPhysiNode* pPhyNode = (SInterpFuncPhysiNode*)pNode; + destroyPhysiNode((SPhysiNode*)pPhyNode); + nodesDestroyList(pPhyNode->pExprs); + nodesDestroyList(pPhyNode->pFuncs); break; } case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index b4f49b3e88..2d9bb49762 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -109,6 +109,7 @@ SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode SNode* pFill); SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues); SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode); +SNode* createInterpTimeRange(SAstCreateContext* pCxt, SNode* pStart, SNode* pEnd); SNode* addWhereClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWhere); SNode* addPartitionByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pPartitionByList); @@ -118,6 +119,9 @@ SNode* addHavingClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pHaving); SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrderByList); SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit); SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit); +SNode* addRangeClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pRange); +SNode* addEveryClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pEvery); +SNode* addFillClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pFill); SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable); SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight); @@ -151,9 +155,13 @@ SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int SToken* pNewColName); SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken* pTagName, SNode* pVal); SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); -SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern); +SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type); +SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName, + EOperatorType tableCondType); SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable); +SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable); +SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId); SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword); SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal); SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName); diff --git a/source/libs/parser/inc/parUtil.h b/source/libs/parser/inc/parUtil.h index 862e3e2cc0..e08f813c19 100644 --- a/source/libs/parser/inc/parUtil.h +++ b/source/libs/parser/inc/parUtil.h @@ -47,6 +47,8 @@ typedef struct SParseMetaCache { SHashObj* pUserAuth; // key is SUserAuthInfo serialized string, element is bool indicating whether or not to pass SHashObj* pUdf; // key is funcName, element is SFuncInfo* SHashObj* pTableIndex; // key is tbFName, element is SArray* + SArray* pDnodes; // element is SEpSet + bool dnodeRequired; } SParseMetaCache; int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...); @@ -77,6 +79,7 @@ int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pD int32_t reserveUserAuthInCacheExt(const char* pUser, const SName* pName, AUTH_TYPE type, SParseMetaCache* pMetaCache); int32_t reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache); int32_t reserveTableIndexInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache); +int32_t reserveDnodeRequiredInCache(SParseMetaCache* pMetaCache); int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta); int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SArray** pVgInfo); int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup); @@ -87,6 +90,7 @@ int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, const char* pUser, con bool* pPass); int32_t getUdfInfoFromCache(SParseMetaCache* pMetaCache, const char* pFunc, SFuncInfo* pInfo); int32_t getTableIndexFromCache(SParseMetaCache* pMetaCache, const SName* pName, SArray** pIndexes); +int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes); void destoryParseMetaCache(SParseMetaCache* pMetaCache); #ifdef __cplusplus diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 476485904c..54c46ecb5d 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -350,34 +350,37 @@ col_name_list(A) ::= col_name_list(B) NK_COMMA col_name(C). col_name(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &B); } /************************************************ show ****************************************************************/ -cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } -cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL, NULL); } -cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); } -cmd ::= SHOW db_name_cond_opt(A) TABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, A, B); } -cmd ::= SHOW db_name_cond_opt(A) STABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, A, B); } -cmd ::= SHOW db_name_cond_opt(A) VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, A, NULL); } -cmd ::= SHOW MNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } -cmd ::= SHOW MODULES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT, NULL, NULL); } -cmd ::= SHOW QNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL, NULL); } -cmd ::= SHOW FUNCTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } -cmd ::= SHOW INDEXES FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, A, B); } -cmd ::= SHOW STREAMS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } +cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); } +cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); } +cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); } +cmd ::= SHOW db_name_cond_opt(A) TABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, A, B, OP_TYPE_LIKE); } +cmd ::= SHOW db_name_cond_opt(A) STABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, A, B, OP_TYPE_LIKE); } +cmd ::= SHOW db_name_cond_opt(A) VGROUPS. { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, A, NULL, OP_TYPE_LIKE); } +cmd ::= SHOW MNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT); } +cmd ::= SHOW MODULES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT); } +cmd ::= SHOW QNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT); } +cmd ::= SHOW FUNCTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT); } +cmd ::= SHOW INDEXES FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, B, A, OP_TYPE_EQUAL); } +cmd ::= SHOW STREAMS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT); } cmd ::= SHOW ACCOUNTS. { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } -cmd ::= SHOW APPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } -cmd ::= SHOW CONNECTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } -cmd ::= SHOW LICENCE. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } -cmd ::= SHOW GRANTS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } +cmd ::= SHOW APPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT); } +cmd ::= SHOW CONNECTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT); } +cmd ::= SHOW LICENCE. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT); } +cmd ::= SHOW GRANTS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT); } cmd ::= SHOW CREATE DATABASE db_name(A). { pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &A); } cmd ::= SHOW CREATE TABLE full_table_name(A). { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, A); } cmd ::= SHOW CREATE STABLE full_table_name(A). { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, A); } -cmd ::= SHOW QUERIES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT, NULL, NULL); } -cmd ::= SHOW SCORES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT, NULL, NULL); } -cmd ::= SHOW TOPICS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT, NULL, NULL); } -cmd ::= SHOW VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } -cmd ::= SHOW BNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT, NULL, NULL); } -cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT, NULL, NULL); } -cmd ::= SHOW CLUSTER. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT, NULL, NULL); } -cmd ::= SHOW TRANSACTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT, NULL, NULL); } +cmd ::= SHOW QUERIES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); } +cmd ::= SHOW SCORES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); } +cmd ::= SHOW TOPICS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); } +cmd ::= SHOW VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } +cmd ::= SHOW LOCAL VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); } +cmd ::= SHOW DNODE NK_INTEGER(A) VARIABLES. { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A)); } +cmd ::= SHOW BNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); } +cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); } +cmd ::= SHOW CLUSTER. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); } +cmd ::= SHOW TRANSACTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); } +cmd ::= SHOW TABLE DISTRIBUTED full_table_name(A). { pCxt->pRootNode = createShowTableDistributedStmt(pCxt, A); } db_name_cond_opt(A) ::= . { A = createDefaultDatabaseCondValue(pCxt); } db_name_cond_opt(A) ::= db_name(B) NK_DOT. { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); } @@ -790,7 +793,7 @@ join_type(A) ::= INNER. /************************************************ query_specification *************************************************/ query_specification(A) ::= SELECT set_quantifier_opt(B) select_list(C) from_clause(D) where_clause_opt(E) - partition_by_clause_opt(F) twindow_clause_opt(G) + partition_by_clause_opt(F) range_opt(J) every_opt(K) fill_opt(L) twindow_clause_opt(G) group_by_clause_opt(H) having_clause_opt(I). { A = createSelectStmt(pCxt, B, C, D); A = addWhereClause(pCxt, A, E); @@ -798,6 +801,9 @@ query_specification(A) ::= A = addWindowClauseClause(pCxt, A, G); A = addGroupByClause(pCxt, A, H); A = addHavingClause(pCxt, A, I); + A = addRangeClause(pCxt, A, J); + A = addEveryClause(pCxt, A, K); + A = addFillClause(pCxt, A, L); } %type set_quantifier_opt { bool } @@ -859,14 +865,20 @@ fill_mode(A) ::= NEXT. group_by_clause_opt(A) ::= . { A = NULL; } group_by_clause_opt(A) ::= GROUP BY group_by_list(B). { A = B; } -%type group_by_list { SNodeList* } -%destructor group_by_list { nodesDestroyList($$); } -group_by_list(A) ::= expression(B). { A = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, B))); } -group_by_list(A) ::= group_by_list(B) NK_COMMA expression(C). { A = addNodeToList(pCxt, B, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, C))); } +%type group_by_list { SNodeList* } +%destructor group_by_list { nodesDestroyList($$); } +group_by_list(A) ::= expression(B). { A = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, B))); } +group_by_list(A) ::= group_by_list(B) NK_COMMA expression(C). { A = addNodeToList(pCxt, B, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, C))); } having_clause_opt(A) ::= . { A = NULL; } having_clause_opt(A) ::= HAVING search_condition(B). { A = B; } +range_opt(A) ::= . { A = NULL; } +range_opt(A) ::= RANGE NK_LP expression(B) NK_COMMA expression(C) NK_RP. { A = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)); } + +every_opt(A) ::= . { A = NULL; } +every_opt(A) ::= EVERY NK_LP duration_literal(B) NK_RP. { A = releaseRawExprNode(pCxt, B); } + /************************************************ query_expression ****************************************************/ query_expression(A) ::= query_expression_body(B) diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 6ea1b090ad..4fc5cf96e5 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -599,6 +599,11 @@ SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode) { return (SNode*)groupingSet; } +SNode* createInterpTimeRange(SAstCreateContext* pCxt, SNode* pStart, SNode* pEnd) { + CHECK_PARSER_STATUS(pCxt); + return createBetweenAnd(pCxt, createPrimaryKeyCol(pCxt), pStart, pEnd); +} + SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* pAlias) { CHECK_PARSER_STATUS(pCxt); int32_t len = TMIN(sizeof(((SExprNode*)pNode)->aliasName) - 1, pAlias->n); @@ -671,6 +676,35 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit) { CHECK_PARSER_STATUS(pCxt); if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) { ((SSelectStmt*)pStmt)->pLimit = (SLimitNode*)pLimit; + } else { + ((SSetOperator*)pStmt)->pLimit = pLimit; + } + return pStmt; +} + +SNode* addRangeClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pRange) { + CHECK_PARSER_STATUS(pCxt); + if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) { + ((SSelectStmt*)pStmt)->pRange = pRange; + } + return pStmt; +} + +SNode* addEveryClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pEvery) { + CHECK_PARSER_STATUS(pCxt); + if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) { + ((SSelectStmt*)pStmt)->pEvery = pEvery; + } + return pStmt; +} + +SNode* addFillClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pFill) { + CHECK_PARSER_STATUS(pCxt); + if (QUERY_NODE_SELECT_STMT == nodeType(pStmt) && NULL != pFill) { + SFillNode* pFillClause = (SFillNode*)pFill; + nodesDestroyNode(pFillClause->pWStartTs); + pFillClause->pWStartTs = createPrimaryKeyCol(pCxt); + ((SSelectStmt*)pStmt)->pFill = (SNode*)pFillClause; } return pStmt; } @@ -878,6 +912,7 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) { pOptions->watermark1 = TSDB_DEFAULT_ROLLUP_WATERMARK; pOptions->watermark2 = TSDB_DEFAULT_ROLLUP_WATERMARK; pOptions->ttl = TSDB_DEFAULT_TABLE_TTL; + pOptions->commentNull = true; // mark null return (SNode*)pOptions; } @@ -886,6 +921,7 @@ SNode* createAlterTableOptions(SAstCreateContext* pCxt) { STableOptions* pOptions = (STableOptions*)nodesMakeNode(QUERY_NODE_TABLE_OPTIONS); CHECK_OUT_OF_MEM(pOptions); pOptions->ttl = -1; + pOptions->commentNull = true; // mark null return (SNode*)pOptions; } @@ -894,6 +930,7 @@ SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType switch (type) { case TABLE_OPTION_COMMENT: if (checkComment(pCxt, (SToken*)pVal, true)) { + ((STableOptions*)pOptions)->commentNull = false; COPY_STRING_FORM_STR_TOKEN(((STableOptions*)pOptions)->comment, (SToken*)pVal); } break; @@ -906,9 +943,15 @@ SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType case TABLE_OPTION_ROLLUP: ((STableOptions*)pOptions)->pRollupFuncs = pVal; break; - case TABLE_OPTION_TTL: - ((STableOptions*)pOptions)->ttl = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); + case TABLE_OPTION_TTL: { + int64_t ttl = taosStr2Int64(((SToken*)pVal)->z, NULL, 10); + if (ttl > INT32_MAX) { + ttl = INT32_MAX; + } + // ttl can not be smaller than 0, because there is a limitation in sql.y (TTL NK_INTEGER) + ((STableOptions*)pOptions)->ttl = ttl; break; + } case TABLE_OPTION_SMA: ((STableOptions*)pOptions)->pSma = pVal; break; @@ -971,9 +1014,9 @@ SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SN pStmt->ignoreExists = ignoreExists; pStmt->pSpecificTags = pSpecificTags; pStmt->pValsOfTags = pValsOfTags; + pStmt->pOptions = (STableOptions*)pOptions; nodesDestroyNode(pRealTable); nodesDestroyNode(pUseRealTable); - nodesDestroyNode(pOptions); return (SNode*)pStmt; } @@ -1100,7 +1143,15 @@ static bool needDbShowStmt(ENodeType type) { QUERY_NODE_SHOW_VGROUPS_STMT == type; } -SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern) { +SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type) { + CHECK_PARSER_STATUS(pCxt); + SShowStmt* pStmt = (SShowStmt*)nodesMakeNode(type); + CHECK_OUT_OF_MEM(pStmt); + return (SNode*)pStmt; +} + +SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName, + EOperatorType tableCondType) { CHECK_PARSER_STATUS(pCxt); if (needDbShowStmt(type) && NULL == pDbName && NULL == pCxt->pQueryCxt->db) { snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "db not specified"); @@ -1110,7 +1161,8 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S SShowStmt* pStmt = (SShowStmt*)nodesMakeNode(type); CHECK_OUT_OF_MEM(pStmt); pStmt->pDbName = pDbName; - pStmt->pTbNamePattern = pTbNamePattern; + pStmt->pTbName = pTbName; + pStmt->tableCondType = tableCondType; return (SNode*)pStmt; } @@ -1131,6 +1183,25 @@ SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* CHECK_OUT_OF_MEM(pStmt); strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); + nodesDestroyNode(pRealTable); + return (SNode*)pStmt; +} + +SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable) { + CHECK_PARSER_STATUS(pCxt); + SShowTableDistributedStmt* pStmt = (SShowTableDistributedStmt*)nodesMakeNode(QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT); + CHECK_OUT_OF_MEM(pStmt); + strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); + strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); + nodesDestroyNode(pRealTable); + return (SNode*)pStmt; +} + +SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId) { + CHECK_PARSER_STATUS(pCxt); + SShowDnodeVariablesStmt* pStmt = (SShowDnodeVariablesStmt*)nodesMakeNode(QUERY_NODE_SHOW_DNODE_VARIABLES_STMT); + CHECK_OUT_OF_MEM(pStmt); + pStmt->pDnodeId = pDnodeId; return (SNode*)pStmt; } diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index e3218f972b..131eccae24 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -397,6 +397,15 @@ static int32_t collectMetaKeyFromShowVariables(SCollectMetaKeyCxt* pCxt, SShowSt pCxt->pMetaCache); } +static int32_t collectMetaKeyFromShowDnodeVariables(SCollectMetaKeyCxt* pCxt, SShowDnodeVariablesStmt* pStmt) { + int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, + TSDB_INS_TABLE_DNODE_VARIABLES, pCxt->pMetaCache); + if (TSDB_CODE_SUCCESS == code) { + code = reserveDnodeRequiredInCache(pCxt->pMetaCache); + } + return code; +} + static int32_t collectMetaKeyFromShowCreateDatabase(SCollectMetaKeyCxt* pCxt, SShowCreateDatabaseStmt* pStmt) { return reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache); } @@ -419,6 +428,24 @@ static int32_t collectMetaKeyFromDelete(SCollectMetaKeyCxt* pCxt, SDeleteStmt* p return collectMetaKeyFromRealTableImpl(pCxt, (SRealTableNode*)pStmt->pFromTable, AUTH_TYPE_WRITE); } +static int32_t collectMetaKeyFromShowBlockDist(SCollectMetaKeyCxt* pCxt, SShowTableDistributedStmt* pStmt) { + SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId}; + strcpy(name.dbname, pStmt->dbName); + strcpy(name.tname, pStmt->tableName); + int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name); + if (TSDB_CODE_SUCCESS == code) { + code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache); + } + + if (TSDB_CODE_SUCCESS == code) { + code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache); + } + if (TSDB_CODE_SUCCESS == code) { + code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache); + } + return code; +} + static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { pCxt->pStmt = pStmt; switch (nodeType(pStmt)) { @@ -484,8 +511,10 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { return collectMetaKeyFromShowConnections(pCxt, (SShowStmt*)pStmt); case QUERY_NODE_SHOW_QUERIES_STMT: return collectMetaKeyFromShowQueries(pCxt, (SShowStmt*)pStmt); - case QUERY_NODE_SHOW_VARIABLE_STMT: + case QUERY_NODE_SHOW_VARIABLES_STMT: return collectMetaKeyFromShowVariables(pCxt, (SShowStmt*)pStmt); + case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT: + return collectMetaKeyFromShowDnodeVariables(pCxt, (SShowDnodeVariablesStmt*)pStmt); case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: return collectMetaKeyFromShowCreateDatabase(pCxt, (SShowCreateDatabaseStmt*)pStmt); case QUERY_NODE_SHOW_CREATE_TABLE_STMT: @@ -497,6 +526,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { return collectMetaKeyFromShowTransactions(pCxt, (SShowStmt*)pStmt); case QUERY_NODE_DELETE_STMT: return collectMetaKeyFromDelete(pCxt, (SDeleteStmt*)pStmt); + case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT: + return collectMetaKeyFromShowBlockDist(pCxt, (SShowTableDistributedStmt*)pStmt); default: break; } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 626960bf10..c8b78fcc8b 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -803,6 +803,7 @@ static void buildCreateTbReq(SVCreateTbReq* pTbReq, const char* tname, STag* pTa pTbReq->name = strdup(tname); pTbReq->ctb.suid = suid; pTbReq->ctb.pTag = (uint8_t*)pTag; + pTbReq->commentLen = -1; return; } diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 41d32204da..21f227b7ea 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -68,12 +68,12 @@ static SKeyword keywordTable[] = { {"CONTAINS", TK_CONTAINS}, {"DATABASE", TK_DATABASE}, {"DATABASES", TK_DATABASES}, - // {"DAYS", TK_DAYS}, {"DBS", TK_DBS}, {"DELETE", TK_DELETE}, {"DESC", TK_DESC}, {"DESCRIBE", TK_DESCRIBE}, {"DISTINCT", TK_DISTINCT}, + {"DISTRIBUTED", TK_DISTRIBUTED}, {"DNODE", TK_DNODE}, {"DNODES", TK_DNODES}, {"DOUBLE", TK_DOUBLE}, @@ -81,7 +81,7 @@ static SKeyword keywordTable[] = { {"DURATION", TK_DURATION}, {"EXISTS", TK_EXISTS}, {"EXPLAIN", TK_EXPLAIN}, - // {"FILE_FACTOR", TK_FILE_FACTOR}, + {"EVERY", TK_EVERY}, {"FILL", TK_FILL}, {"FIRST", TK_FIRST}, {"FLOAT", TK_FLOAT}, @@ -153,6 +153,7 @@ static SKeyword keywordTable[] = { {"QTIME", TK_QTIME}, {"QUERIES", TK_QUERIES}, {"QUERY", TK_QUERY}, + {"RANGE", TK_RANGE}, {"RATIO", TK_RATIO}, {"READ", TK_READ}, {"REDISTRIBUTE", TK_REDISTRIBUTE}, @@ -259,7 +260,6 @@ static SKeyword keywordTable[] = { // {"LP", TK_LP}, // {"RP", TK_RP}, // {"COMMA", TK_COMMA}, - // {"EVERY", TK_EVERY}, // {"VARIABLE", TK_VARIABLE}, // {"UPDATE", TK_UPDATE}, // {"CHANGE", TK_CHANGE}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 66990a8e41..1689fbd5dd 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -305,6 +305,24 @@ static int32_t getTableIndex(STranslateContext* pCxt, const SName* pName, SArray return code; } +static int32_t getDnodeList(STranslateContext* pCxt, SArray** pDnodes) { + SParseContext* pParCxt = pCxt->pParseCxt; + int32_t code = TSDB_CODE_SUCCESS; + if (pParCxt->async) { + code = getDnodeListFromCache(pCxt->pMetaCache, pDnodes); + } else { + SRequestConnInfo conn = {.pTrans = pParCxt->pTransporter, + .requestId = pParCxt->requestId, + .requestObjRefId = pParCxt->requestRid, + .mgmtEps = pParCxt->mgmtEpSet}; + code = catalogGetDnodeList(pParCxt->pCatalog, &conn, pDnodes); + } + if (TSDB_CODE_SUCCESS != code) { + parserError("getDnodeList error, code:%s", tstrerror(code)); + } + return code; +} + static int32_t initTranslateContext(SParseContext* pParseCxt, SParseMetaCache* pMetaCache, STranslateContext* pCxt) { pCxt->pParseCxt = pParseCxt; pCxt->errCode = TSDB_CODE_SUCCESS; @@ -1157,6 +1175,7 @@ static void setFuncClassification(SSelectStmt* pSelect, SFunctionNode* pFunc) { pSelect->hasIndefiniteRowsFunc = pSelect->hasIndefiniteRowsFunc ? true : fmIsIndefiniteRowsFunc(pFunc->funcId); pSelect->hasUniqueFunc = pSelect->hasUniqueFunc ? true : (FUNCTION_TYPE_UNIQUE == pFunc->funcType); pSelect->hasTailFunc = pSelect->hasTailFunc ? true : (FUNCTION_TYPE_TAIL == pFunc->funcType); + pSelect->hasInterpFunc = pSelect->hasInterpFunc ? true : (FUNCTION_TYPE_INTERP == pFunc->funcType); } } @@ -1449,12 +1468,27 @@ static int32_t addMnodeToVgroupList(const SEpSet* pEpSet, SArray** pVgroupList) return TSDB_CODE_SUCCESS; } -static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) { - if (0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES) && - 0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED)) { - return TSDB_CODE_SUCCESS; +static int32_t dnodeToVgroupsInfo(SArray* pDnodes, SVgroupsInfo** pVgsInfo) { + size_t ndnode = taosArrayGetSize(pDnodes); + *pVgsInfo = taosMemoryCalloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * ndnode); + if (NULL == *pVgsInfo) { + return TSDB_CODE_OUT_OF_MEMORY; } + (*pVgsInfo)->numOfVgroups = ndnode; + for (int32_t i = 0; i < ndnode; ++i) { + memcpy(&((*pVgsInfo)->vgroups[i].epSet), taosArrayGet(pDnodes, i), sizeof(SEpSet)); + } + return TSDB_CODE_SUCCESS; +} +static bool sysTableFromVnode(const char* pTable) { + return (0 == strcmp(pTable, TSDB_INS_TABLE_USER_TABLES)) || + (0 == strcmp(pTable, TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED)); +} + +static bool sysTableFromDnode(const char* pTable) { return 0 == strcmp(pTable, TSDB_INS_TABLE_DNODE_VARIABLES); } + +static int32_t setVnodeSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) { int32_t code = TSDB_CODE_SUCCESS; SArray* vgroupList = NULL; if ('\0' != pRealTable->qualDbName[0]) { @@ -1477,6 +1511,26 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea return code; } +static int32_t setDnodeSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) { + SArray* pDnodes = NULL; + int32_t code = getDnodeList(pCxt, &pDnodes); + if (TSDB_CODE_SUCCESS == code) { + code = dnodeToVgroupsInfo(pDnodes, &pRealTable->pVgroupList); + } + taosArrayDestroy(pDnodes); + return code; +} + +static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) { + if (sysTableFromVnode(pRealTable->table.tableName)) { + return setVnodeSysTableVgroupList(pCxt, pName, pRealTable); + } else if (sysTableFromDnode(pRealTable->table.tableName)) { + return setDnodeSysTableVgroupList(pCxt, pName, pRealTable); + } else { + return TSDB_CODE_SUCCESS; + } +} + static int32_t setTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) { if (pCxt->pParseCxt->topicQuery) { return TSDB_CODE_SUCCESS; @@ -1931,26 +1985,33 @@ static int32_t getFillTimeRange(STranslateContext* pCxt, SNode* pWhere, STimeWin return code; } -static int32_t checkFill(STranslateContext* pCxt, SIntervalWindowNode* pInterval) { - SFillNode* pFill = (SFillNode*)pInterval->pFill; +static int32_t checkFill(STranslateContext* pCxt, SFillNode* pFill, SValueNode* pInterval) { + if (FILL_MODE_NONE == pFill->mode) { + return TSDB_CODE_SUCCESS; + } + if (TSWINDOW_IS_EQUAL(pFill->timeRange, TSWINDOW_INITIALIZER) || TSWINDOW_IS_EQUAL(pFill->timeRange, TSWINDOW_DESC_INITIALIZER)) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE); } - int64_t timeRange = TABS(pFill->timeRange.skey - pFill->timeRange.ekey); - int64_t intervalRange = 0; - SValueNode* pInter = (SValueNode*)pInterval->pInterval; - if (TIME_IS_VAR_DURATION(pInter->unit)) { + // interp FILL clause + if (NULL == pInterval) { + return TSDB_CODE_SUCCESS; + } + + int64_t timeRange = TABS(pFill->timeRange.skey - pFill->timeRange.ekey); + int64_t intervalRange = 0; + if (TIME_IS_VAR_DURATION(pInterval->unit)) { int64_t f = 1; - if (pInter->unit == 'n') { + if (pInterval->unit == 'n') { f = 30L * MILLISECOND_PER_DAY; - } else if (pInter->unit == 'y') { + } else if (pInterval->unit == 'y') { f = 365L * MILLISECOND_PER_DAY; } - intervalRange = pInter->datum.i * f; + intervalRange = pInterval->datum.i * f; } else { - intervalRange = pInter->datum.i; + intervalRange = pInterval->datum.i; } if ((timeRange == 0) || (timeRange / intervalRange) >= MAX_INTERVAL_TIME_WINDOW) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE); @@ -1966,7 +2027,7 @@ static int32_t translateFill(STranslateContext* pCxt, SNode* pWhere, SIntervalWi int32_t code = getFillTimeRange(pCxt, pWhere, &(((SFillNode*)pInterval->pFill)->timeRange)); if (TSDB_CODE_SUCCESS == code) { - code = checkFill(pCxt, pInterval); + code = checkFill(pCxt, (SFillNode*)pInterval->pFill, (SValueNode*)pInterval->pInterval); } return code; } @@ -2108,6 +2169,64 @@ static int32_t translateWindow(STranslateContext* pCxt, SSelectStmt* pSelect) { return code; } +static int32_t createDefaultFillNode(STranslateContext* pCxt, SNode** pOutput) { + SFillNode* pFill = (SFillNode*)nodesMakeNode(QUERY_NODE_FILL); + if (NULL == pFill) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + pFill->mode = FILL_MODE_NONE; + + SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); + if (NULL == pCol) { + nodesDestroyNode((SNode*)pFill); + return TSDB_CODE_OUT_OF_MEMORY; + } + pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID; + strcpy(pCol->colName, PK_TS_COL_INTERNAL_NAME); + pFill->pWStartTs = (SNode*)pCol; + + *pOutput = (SNode*)pFill; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateInterpFill(STranslateContext* pCxt, SSelectStmt* pSelect) { + int32_t code = TSDB_CODE_SUCCESS; + + if (NULL == pSelect->pFill) { + code = createDefaultFillNode(pCxt, &pSelect->pFill); + } + if (TSDB_CODE_SUCCESS == code) { + code = translateExpr(pCxt, &pSelect->pFill); + } + if (TSDB_CODE_SUCCESS == code) { + code = getFillTimeRange(pCxt, pSelect->pRange, &(((SFillNode*)pSelect->pFill)->timeRange)); + } + if (TSDB_CODE_SUCCESS == code) { + code = checkFill(pCxt, (SFillNode*)pSelect->pFill, (SValueNode*)pSelect->pEvery); + } + + return code; +} + +static int32_t translateInterp(STranslateContext* pCxt, SSelectStmt* pSelect) { + if (!pSelect->hasInterpFunc) { + if (NULL != pSelect->pRange || NULL != pSelect->pEvery || NULL != pSelect->pFill) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_INTERP_CLAUSE); + } + return TSDB_CODE_SUCCESS; + } + + int32_t code = translateExpr(pCxt, &pSelect->pRange); + if (TSDB_CODE_SUCCESS == code) { + code = translateExpr(pCxt, &pSelect->pEvery); + } + if (TSDB_CODE_SUCCESS == code) { + code = translateInterpFill(pCxt, pSelect); + } + return code; +} + static int32_t translatePartitionBy(STranslateContext* pCxt, SNodeList* pPartitionByList) { pCxt->currClause = SQL_CLAUSE_PARTITION_BY; return translateExprList(pCxt, pPartitionByList); @@ -2377,6 +2496,9 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { if (TSDB_CODE_SUCCESS == code) { code = checkLimit(pCxt, pSelect); } + if (TSDB_CODE_SUCCESS == code) { + code = translateInterp(pCxt, pSelect); + } if (TSDB_CODE_SUCCESS == code) { code = rewriteUniqueStmt(pCxt, pSelect); } @@ -3147,9 +3269,6 @@ static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt if (TSDB_CODE_SUCCESS == code) { code = checkTableRollupOption(pCxt, pStmt->pOptions->pRollupFuncs); } - if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "ttl", pStmt->pOptions->ttl, TSDB_MIN_TABLE_TTL, INT32_MAX); - } if (TSDB_CODE_SUCCESS == code) { code = checkTableSmaOption(pCxt, pStmt); } @@ -3390,17 +3509,19 @@ static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStm pReq->delay2 = pStmt->pOptions->maxDelay2; pReq->watermark1 = pStmt->pOptions->watermark1; pReq->watermark2 = pStmt->pOptions->watermark2; - pReq->ttl = pStmt->pOptions->ttl; + // pReq->ttl = pStmt->pOptions->ttl; columnDefNodeToField(pStmt->pCols, &pReq->pColumns); columnDefNodeToField(pStmt->pTags, &pReq->pTags); pReq->numOfColumns = LIST_LENGTH(pStmt->pCols); pReq->numOfTags = LIST_LENGTH(pStmt->pTags); - if ('\0' != pStmt->pOptions->comment[0]) { + if (pStmt->pOptions->commentNull == false) { pReq->comment = strdup(pStmt->pOptions->comment); if (NULL == pReq->comment) { return TSDB_CODE_OUT_OF_MEMORY; } - pReq->commentLen = strlen(pStmt->pOptions->comment) + 1; + pReq->commentLen = strlen(pStmt->pOptions->comment); + } else { + pReq->commentLen = -1; } SName tableName; @@ -3452,14 +3573,17 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* pAlterReq->alterType = pStmt->alterType; if (TSDB_ALTER_TABLE_UPDATE_OPTIONS == pStmt->alterType) { - pAlterReq->ttl = pStmt->pOptions->ttl; - if ('\0' != pStmt->pOptions->comment[0]) { + // pAlterReq->ttl = pStmt->pOptions->ttl; + if (pStmt->pOptions->commentNull == false) { pAlterReq->comment = strdup(pStmt->pOptions->comment); if (NULL == pAlterReq->comment) { return TSDB_CODE_OUT_OF_MEMORY; } - pAlterReq->commentLen = strlen(pStmt->pOptions->comment) + 1; + pAlterReq->commentLen = strlen(pStmt->pOptions->comment); + } else { + pAlterReq->commentLen = -1; } + return TSDB_CODE_SUCCESS; } @@ -4010,8 +4134,12 @@ static int32_t translateCreateStream(STranslateContext* pCxt, SCreateStreamStmt* } static int32_t translateDropStream(STranslateContext* pCxt, SDropStreamStmt* pStmt) { - // todo - return TSDB_CODE_SUCCESS; + SMDropStreamReq dropReq = {0}; + SName name; + tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->streamName, strlen(pStmt->streamName)); + tNameGetFullDbName(&name, dropReq.name); + dropReq.igNotExists = pStmt->ignoreNotExists; + return buildCmdMsg(pCxt, TDMT_MND_DROP_STREAM, (FSerializeFunc)tSerializeSMDropStreamReq, &dropReq); } static int32_t readFromFile(char* pName, int32_t* len, char** buf) { @@ -4467,7 +4595,8 @@ static const char* getSysDbName(ENodeType type) { case QUERY_NODE_SHOW_SNODES_STMT: case QUERY_NODE_SHOW_LICENCE_STMT: case QUERY_NODE_SHOW_CLUSTER_STMT: - case QUERY_NODE_SHOW_VARIABLE_STMT: + case QUERY_NODE_SHOW_VARIABLES_STMT: + case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT: return TSDB_INFORMATION_SCHEMA_DB; case QUERY_NODE_SHOW_CONNECTIONS_STMT: case QUERY_NODE_SHOW_QUERIES_STMT: @@ -4524,38 +4653,48 @@ static const char* getSysTableName(ENodeType type) { return TSDB_PERFS_TABLE_TOPICS; case QUERY_NODE_SHOW_TRANSACTIONS_STMT: return TSDB_PERFS_TABLE_TRANS; - case QUERY_NODE_SHOW_VARIABLE_STMT: + case QUERY_NODE_SHOW_VARIABLES_STMT: return TSDB_INS_TABLE_CONFIGS; case QUERY_NODE_SHOW_APPS_STMT: return TSDB_PERFS_TABLE_APPS; + case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT: + return TSDB_INS_TABLE_DNODE_VARIABLES; default: break; } return NULL; } -static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt) { +static int32_t createSimpleSelectStmt(const char* pDb, const char* pTable, SSelectStmt** pStmt) { SSelectStmt* pSelect = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT); if (NULL == pSelect) { return TSDB_CODE_OUT_OF_MEMORY; } sprintf(pSelect->stmtName, "%p", pSelect); - SRealTableNode* pTable = (SRealTableNode*)nodesMakeNode(QUERY_NODE_REAL_TABLE); - if (NULL == pTable) { + SRealTableNode* pRealTable = (SRealTableNode*)nodesMakeNode(QUERY_NODE_REAL_TABLE); + if (NULL == pRealTable) { nodesDestroyNode((SNode*)pSelect); return TSDB_CODE_OUT_OF_MEMORY; } - strcpy(pTable->table.dbName, getSysDbName(showType)); - strcpy(pTable->table.tableName, getSysTableName(showType)); - strcpy(pTable->table.tableAlias, pTable->table.tableName); - pSelect->pFromTable = (SNode*)pTable; + strcpy(pRealTable->table.dbName, pDb); + strcpy(pRealTable->table.tableName, pTable); + strcpy(pRealTable->table.tableAlias, pTable); + pSelect->pFromTable = (SNode*)pRealTable; *pStmt = pSelect; return TSDB_CODE_SUCCESS; } +static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt) { + return createSimpleSelectStmt(getSysDbName(showType), getSysTableName(showType), pStmt); +} + +static int32_t createSelectStmtForShowTableDist(SShowTableDistributedStmt* pStmt, SSelectStmt** pOutput) { + return createSimpleSelectStmt(pStmt->dbName, pStmt->tableName, pOutput); +} + static int32_t createOperatorNode(EOperatorType opType, const char* pColName, SNode* pRight, SNode** pOp) { if (NULL == pRight) { return TSDB_CODE_SUCCESS; @@ -4609,7 +4748,7 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect) SNode* pTbCond = NULL; if (TSDB_CODE_SUCCESS != createOperatorNode(OP_TYPE_EQUAL, "db_name", pShow->pDbName, &pDbCond) || TSDB_CODE_SUCCESS != - createOperatorNode(OP_TYPE_LIKE, getTbNameColName(nodeType(pShow)), pShow->pTbNamePattern, &pTbCond)) { + createOperatorNode(pShow->tableCondType, getTbNameColName(nodeType(pShow)), pShow->pTbName, &pTbCond)) { nodesDestroyNode(pDbCond); nodesDestroyNode(pTbCond); return TSDB_CODE_OUT_OF_MEMORY; @@ -4646,6 +4785,61 @@ static int32_t rewriteShow(STranslateContext* pCxt, SQuery* pQuery) { return code; } +static int32_t rewriteShowDnodeVariables(STranslateContext* pCxt, SQuery* pQuery) { + SSelectStmt* pStmt = NULL; + int32_t code = createSelectStmtForShow(nodeType(pQuery->pRoot), &pStmt); + if (TSDB_CODE_SUCCESS == code) { + code = createOperatorNode(OP_TYPE_EQUAL, "dnode_id", ((SShowDnodeVariablesStmt*)pQuery->pRoot)->pDnodeId, + &pStmt->pWhere); + } + if (TSDB_CODE_SUCCESS == code) { + pQuery->showRewrite = true; + nodesDestroyNode(pQuery->pRoot); + pQuery->pRoot = (SNode*)pStmt; + } + return code; +} + +static SNode* createBlockDistInfoFunc() { + SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); + if (NULL == pFunc) { + return NULL; + } + + strcpy(pFunc->functionName, "_block_dist_info"); + strcpy(pFunc->node.aliasName, "_block_dist_info"); + return (SNode*)pFunc; +} + +static SNode* createBlockDistFunc() { + SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); + if (NULL == pFunc) { + return NULL; + } + + strcpy(pFunc->functionName, "_block_dist"); + strcpy(pFunc->node.aliasName, "_block_dist"); + if (TSDB_CODE_SUCCESS != nodesListMakeStrictAppend(&pFunc->pParameterList, createBlockDistInfoFunc())) { + nodesDestroyNode((SNode*)pFunc); + return NULL; + } + return (SNode*)pFunc; +} + +static int32_t rewriteShowTableDist(STranslateContext* pCxt, SQuery* pQuery) { + SSelectStmt* pStmt = NULL; + int32_t code = createSelectStmtForShowTableDist((SShowTableDistributedStmt*)pQuery->pRoot, &pStmt); + if (TSDB_CODE_SUCCESS == code) { + code = nodesListMakeStrictAppend(&pStmt->pProjectionList, createBlockDistFunc()); + } + if (TSDB_CODE_SUCCESS == code) { + pQuery->showRewrite = true; + nodesDestroyNode(pQuery->pRoot); + pQuery->pRoot = (SNode*)pStmt; + } + return code; +} + typedef struct SVgroupCreateTableBatch { SVCreateTbBatchReq req; SVgroupInfo info; @@ -4667,6 +4861,16 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* SVCreateTbReq req = {0}; req.type = TD_NORMAL_TABLE; req.name = strdup(pStmt->tableName); + req.ttl = pStmt->pOptions->ttl; + if (pStmt->pOptions->commentNull == false) { + req.comment = strdup(pStmt->pOptions->comment); + if (NULL == req.comment) { + return TSDB_CODE_OUT_OF_MEMORY; + } + req.commentLen = strlen(pStmt->pOptions->comment); + } else { + req.commentLen = -1; + } req.ntb.schemaRow.nCols = LIST_LENGTH(pStmt->pCols); req.ntb.schemaRow.version = 1; req.ntb.schemaRow.pSchema = taosMemoryCalloc(req.ntb.schemaRow.nCols, sizeof(SSchema)); @@ -4817,6 +5021,13 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, S struct SVCreateTbReq req = {0}; req.type = TD_CHILD_TABLE; req.name = strdup(pStmt->tableName); + req.ttl = pStmt->pOptions->ttl; + if (pStmt->pOptions->commentNull == false) { + req.comment = strdup(pStmt->pOptions->comment); + req.commentLen = strlen(pStmt->pOptions->comment); + } else { + req.commentLen = -1; + } req.ctb.suid = suid; req.ctb.pTag = (uint8_t*)pTag; if (pStmt->ignoreExists) { @@ -5388,18 +5599,19 @@ static int32_t buildUpdateOptionsReq(STranslateContext* pCxt, SAlterTableStmt* p int32_t code = TSDB_CODE_SUCCESS; if (-1 != pStmt->pOptions->ttl) { - code = checkRangeOption(pCxt, "ttl", pStmt->pOptions->ttl, TSDB_MIN_TABLE_TTL, INT32_MAX); - if (TSDB_CODE_SUCCESS == code) { - pReq->updateTTL = true; - pReq->newTTL = pStmt->pOptions->ttl; - } + pReq->updateTTL = true; + pReq->newTTL = pStmt->pOptions->ttl; } - if (TSDB_CODE_SUCCESS == code && '\0' != pStmt->pOptions->comment[0]) { - pReq->updateComment = true; - pReq->newComment = strdup(pStmt->pOptions->comment); - if (NULL == pReq->newComment) { - code = TSDB_CODE_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS == code) { + if (pStmt->pOptions->commentNull == false) { + pReq->newComment = strdup(pStmt->pOptions->comment); + if (NULL == pReq->newComment) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + pReq->newCommentLen = strlen(pReq->newComment); + } else { + pReq->newCommentLen = -1; } } @@ -5518,6 +5730,9 @@ static int32_t rewriteAlterTableImpl(STranslateContext* pCxt, SAlterTableStmt* p pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_TAG_BYTES)) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_ONLY_ONE_JSON_TAG); } + if (pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_OPTIONS && -1 != pStmt->pOptions->ttl) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE); + } return TSDB_CODE_SUCCESS; } else if (TSDB_CHILD_TABLE != pTableMeta->tableType && TSDB_NORMAL_TABLE != pTableMeta->tableType) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE); @@ -5580,10 +5795,16 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_CLUSTER_STMT: case QUERY_NODE_SHOW_TOPICS_STMT: case QUERY_NODE_SHOW_TRANSACTIONS_STMT: - case QUERY_NODE_SHOW_VARIABLE_STMT: + case QUERY_NODE_SHOW_VARIABLES_STMT: case QUERY_NODE_SHOW_APPS_STMT: code = rewriteShow(pCxt, pQuery); break; + case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT: + code = rewriteShowDnodeVariables(pCxt, pQuery); + break; + case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT: + code = rewriteShowTableDist(pCxt, pQuery); + break; case QUERY_NODE_CREATE_TABLE_STMT: if (NULL == ((SCreateTableStmt*)pQuery->pRoot)->pTags) { code = rewriteCreateTable(pCxt, pQuery); @@ -5671,6 +5892,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { break; case QUERY_NODE_RESET_QUERY_CACHE_STMT: case QUERY_NODE_ALTER_LOCAL_STMT: + case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: pQuery->execMode = QUERY_EXEC_MODE_LOCAL; break; default: diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 95cdf58d5a..51e0dd58d8 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -196,6 +196,8 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "%s function does not supportted in group query"; case TSDB_CODE_PAR_INVALID_TABLE_OPTION: return "Invalid option %s"; + case TSDB_CODE_PAR_INVALID_INTERP_CLAUSE: + return "Invalid usage of RANGE clause, EVERY clause or FILL clause"; case TSDB_CODE_OUT_OF_MEMORY: return "Out of memory"; default: @@ -559,6 +561,7 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog if (TSDB_CODE_SUCCESS == code) { code = buildTableReq(pMetaCache->pTableIndex, &pCatalogReq->pTableIndex); } + pCatalogReq->dNodeRequired = pMetaCache->dnodeRequired; return code; } @@ -654,6 +657,7 @@ int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMet if (TSDB_CODE_SUCCESS == code) { code = putTableDataToCache(pCatalogReq->pTableIndex, pMetaData->pTableIndex, &pMetaCache->pTableIndex); } + pMetaCache->pDnodes = pMetaData->pDnodeList; return code; } @@ -873,6 +877,19 @@ int32_t getTableIndexFromCache(SParseMetaCache* pMetaCache, const SName* pName, return code; } +int32_t reserveDnodeRequiredInCache(SParseMetaCache* pMetaCache) { + pMetaCache->dnodeRequired = true; + return TSDB_CODE_SUCCESS; +} + +int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes) { + *pDnodes = taosArrayDup(pMetaCache->pDnodes); + if (NULL == *pDnodes) { + return TSDB_CODE_OUT_OF_MEMORY; + } + return TSDB_CODE_SUCCESS; +} + void destoryParseMetaCache(SParseMetaCache* pMetaCache) { taosHashCleanup(pMetaCache->pTableMeta); taosHashCleanup(pMetaCache->pDbVgroup); diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index a950b4efb0..c7651137b1 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -104,25 +104,25 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 359 +#define YYNOCODE 364 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - EOperatorType yy28; - int32_t yy42; - ENullOrder yy107; - EFillMode yy320; - SToken yy421; - SNodeList* yy530; - SAlterOption yy557; - EOrder yy610; - bool yy621; - EJoinType yy636; - int64_t yy669; - SNode* yy674; - SDataType yy690; + SToken yy57; + EOrder yy162; + EJoinType yy204; + SAlterOption yy221; + int32_t yy228; + EFillMode yy270; + EOperatorType yy324; + int64_t yy389; + SNode* yy392; + SDataType yy448; + bool yy481; + ENullOrder yy529; + SNodeList* yy600; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -138,17 +138,17 @@ typedef union { #define ParseCTX_FETCH #define ParseCTX_STORE #define YYFALLBACK 1 -#define YYNSTATE 622 -#define YYNRULE 459 -#define YYNTOKEN 239 -#define YY_MAX_SHIFT 621 -#define YY_MIN_SHIFTREDUCE 912 -#define YY_MAX_SHIFTREDUCE 1370 -#define YY_ERROR_ACTION 1371 -#define YY_ACCEPT_ACTION 1372 -#define YY_NO_ACTION 1373 -#define YY_MIN_REDUCE 1374 -#define YY_MAX_REDUCE 1832 +#define YYNSTATE 641 +#define YYNRULE 466 +#define YYNTOKEN 242 +#define YY_MAX_SHIFT 640 +#define YY_MIN_SHIFTREDUCE 933 +#define YY_MAX_SHIFTREDUCE 1398 +#define YY_ERROR_ACTION 1399 +#define YY_ACCEPT_ACTION 1400 +#define YY_NO_ACTION 1401 +#define YY_MIN_REDUCE 1402 +#define YY_MAX_REDUCE 1867 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -215,594 +215,619 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (2098) +#define YY_ACTTAB_COUNT (2192) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 1557, 321, 1679, 1666, 1550, 1552, 300, 396, 1666, 397, - /* 10 */ 1406, 317, 35, 33, 1663, 404, 1556, 397, 1406, 1663, - /* 20 */ 309, 1483, 1184, 1557, 36, 34, 32, 31, 30, 1695, - /* 30 */ 299, 536, 36, 34, 32, 31, 30, 521, 1810, 1555, - /* 40 */ 1659, 1665, 1649, 1810, 520, 1659, 1665, 1182, 28, 233, - /* 50 */ 1809, 540, 362, 1372, 1807, 150, 540, 501, 14, 1807, - /* 60 */ 35, 33, 1311, 395, 1190, 1679, 399, 536, 309, 1708, - /* 70 */ 1184, 159, 82, 1680, 523, 1682, 1683, 519, 414, 540, - /* 80 */ 57, 1, 1748, 536, 401, 1810, 283, 1744, 497, 281, - /* 90 */ 1206, 537, 1695, 537, 1325, 1182, 62, 1808, 1810, 61, - /* 100 */ 521, 1807, 106, 618, 154, 1649, 14, 520, 942, 435, - /* 110 */ 151, 326, 1190, 24, 1807, 414, 114, 1253, 1254, 1505, - /* 120 */ 501, 1505, 356, 36, 34, 32, 31, 30, 39, 2, - /* 130 */ 134, 497, 1708, 1695, 1462, 82, 1680, 523, 1682, 1683, - /* 140 */ 519, 490, 540, 524, 38, 1748, 946, 947, 1318, 283, - /* 150 */ 1744, 618, 1810, 1600, 1208, 112, 196, 56, 1185, 114, - /* 160 */ 1183, 1810, 1208, 1810, 149, 1253, 1254, 130, 1807, 499, - /* 170 */ 146, 1755, 1756, 149, 1760, 149, 574, 1807, 489, 1807, - /* 180 */ 508, 486, 1188, 1189, 347, 1235, 1236, 1238, 1239, 1240, - /* 190 */ 1241, 1242, 516, 538, 1250, 1251, 1252, 1255, 112, 36, - /* 200 */ 34, 32, 31, 30, 349, 345, 1185, 133, 1183, 1386, - /* 210 */ 152, 66, 282, 147, 1755, 1756, 1209, 1760, 524, 35, - /* 220 */ 33, 36, 34, 32, 31, 30, 312, 309, 1599, 1184, - /* 230 */ 1188, 1189, 1375, 1235, 1236, 1238, 1239, 1240, 1241, 1242, - /* 240 */ 516, 538, 1250, 1251, 1252, 1255, 36, 34, 32, 31, - /* 250 */ 30, 492, 487, 96, 1182, 73, 95, 94, 93, 92, - /* 260 */ 91, 90, 89, 88, 87, 14, 491, 35, 33, 1222, - /* 270 */ 26, 1190, 1433, 152, 1496, 309, 1498, 1184, 1193, 56, - /* 280 */ 36, 34, 32, 31, 30, 1663, 152, 403, 2, 1335, - /* 290 */ 399, 1049, 563, 562, 561, 1053, 560, 1055, 1056, 559, - /* 300 */ 1058, 556, 1182, 1064, 553, 1066, 1067, 550, 547, 1261, - /* 310 */ 618, 1659, 1665, 1091, 1092, 1208, 32, 31, 30, 1190, - /* 320 */ 1237, 589, 540, 1397, 1253, 1254, 483, 1333, 1334, 1336, - /* 330 */ 1337, 1209, 596, 595, 594, 324, 8, 593, 592, 591, - /* 340 */ 116, 586, 585, 584, 583, 582, 581, 580, 579, 124, - /* 350 */ 575, 1436, 578, 313, 1477, 355, 56, 354, 618, 1367, - /* 360 */ 1207, 131, 350, 1649, 572, 1185, 1396, 1183, 509, 1395, - /* 370 */ 1507, 96, 1253, 1254, 95, 94, 93, 92, 91, 90, - /* 380 */ 89, 88, 87, 122, 121, 569, 568, 567, 64, 1188, - /* 390 */ 1189, 1196, 1235, 1236, 1238, 1239, 1240, 1241, 1242, 516, - /* 400 */ 538, 1250, 1251, 1252, 1255, 497, 1649, 537, 152, 1649, - /* 410 */ 1501, 449, 448, 1185, 1557, 1183, 447, 1394, 360, 111, - /* 420 */ 444, 314, 1393, 443, 442, 441, 35, 33, 1256, 570, - /* 430 */ 1555, 1679, 1548, 114, 309, 1505, 1184, 1188, 1189, 1366, - /* 440 */ 1235, 1236, 1238, 1239, 1240, 1241, 1242, 516, 538, 1250, - /* 450 */ 1251, 1252, 1255, 1392, 1184, 449, 448, 1649, 1695, 1391, - /* 460 */ 447, 1182, 1649, 111, 444, 152, 521, 443, 442, 441, - /* 470 */ 197, 1649, 112, 520, 35, 33, 1551, 1552, 1190, 1182, - /* 480 */ 1190, 1237, 309, 1679, 1184, 152, 537, 148, 1755, 1756, - /* 490 */ 293, 1760, 959, 1649, 958, 9, 1190, 361, 1708, 1649, - /* 500 */ 64, 84, 1680, 523, 1682, 1683, 519, 1390, 540, 1182, - /* 510 */ 1695, 1748, 203, 110, 1505, 1747, 1744, 618, 500, 433, - /* 520 */ 473, 960, 1500, 1649, 571, 520, 1190, 1548, 1166, 1167, - /* 530 */ 187, 1253, 1254, 185, 537, 618, 316, 315, 56, 294, - /* 540 */ 67, 292, 291, 9, 437, 106, 1198, 1649, 439, 1482, - /* 550 */ 1708, 1310, 440, 83, 1680, 523, 1682, 1683, 519, 1011, - /* 560 */ 540, 1810, 1505, 1748, 959, 618, 958, 302, 1744, 145, - /* 570 */ 438, 1191, 1185, 149, 1183, 463, 1013, 1807, 1557, 1253, - /* 580 */ 1254, 225, 446, 445, 537, 320, 479, 1775, 1190, 386, - /* 590 */ 1185, 7, 1183, 960, 1555, 371, 1188, 1189, 1208, 1235, - /* 600 */ 1236, 1238, 1239, 1240, 1241, 1242, 516, 538, 1250, 1251, - /* 610 */ 1252, 1255, 1505, 319, 1188, 1189, 1810, 1275, 946, 947, - /* 620 */ 1185, 131, 1183, 322, 144, 79, 1389, 541, 149, 1388, - /* 630 */ 1507, 131, 1807, 35, 33, 163, 162, 1544, 115, 1280, - /* 640 */ 1507, 309, 572, 1184, 1188, 1189, 1497, 1235, 1236, 1238, - /* 650 */ 1239, 1240, 1241, 1242, 516, 538, 1250, 1251, 1252, 1255, - /* 660 */ 1385, 122, 121, 569, 568, 567, 1649, 152, 1182, 1649, - /* 670 */ 537, 1384, 11, 10, 25, 1667, 1383, 537, 280, 54, - /* 680 */ 1206, 372, 1199, 1762, 1194, 1190, 1663, 379, 413, 1382, - /* 690 */ 391, 36, 34, 32, 31, 30, 590, 588, 1505, 537, - /* 700 */ 1649, 1679, 2, 1210, 132, 1505, 1202, 1759, 392, 262, - /* 710 */ 1502, 1649, 1659, 1665, 1192, 1381, 1649, 538, 1250, 1251, - /* 720 */ 1374, 260, 53, 540, 618, 52, 1380, 1505, 1695, 1649, - /* 730 */ 1379, 256, 1762, 1762, 1535, 505, 521, 284, 1253, 1254, - /* 740 */ 1480, 1649, 164, 520, 105, 104, 103, 102, 101, 100, - /* 750 */ 99, 98, 97, 1287, 480, 1649, 1758, 1757, 1309, 1767, - /* 760 */ 1306, 1222, 1378, 1306, 1237, 566, 1649, 56, 1708, 1273, - /* 770 */ 1649, 278, 1680, 523, 1682, 1683, 519, 577, 540, 1185, - /* 780 */ 390, 1183, 1481, 385, 384, 383, 382, 381, 378, 377, - /* 790 */ 376, 375, 374, 370, 369, 368, 367, 366, 365, 364, - /* 800 */ 363, 1211, 1649, 1188, 1189, 81, 1235, 1236, 1238, 1239, - /* 810 */ 1240, 1241, 1242, 516, 538, 1250, 1251, 1252, 1255, 131, - /* 820 */ 1274, 537, 36, 34, 32, 31, 30, 1195, 1508, 537, - /* 830 */ 224, 1637, 1626, 572, 537, 1377, 60, 59, 359, 574, - /* 840 */ 471, 158, 1279, 189, 513, 534, 188, 353, 191, 1505, - /* 850 */ 439, 190, 122, 121, 569, 568, 567, 1505, 279, 537, - /* 860 */ 537, 343, 1505, 341, 337, 333, 155, 328, 284, 1494, - /* 870 */ 535, 246, 438, 1423, 1490, 1649, 335, 27, 307, 1268, - /* 880 */ 1269, 1270, 1271, 1272, 1276, 1277, 1278, 1505, 1505, 1418, - /* 890 */ 1679, 1590, 537, 1416, 193, 450, 152, 192, 1669, 461, - /* 900 */ 1273, 503, 161, 323, 120, 621, 46, 983, 212, 1369, - /* 910 */ 1370, 452, 459, 11, 10, 455, 78, 1695, 37, 251, - /* 920 */ 1505, 506, 1492, 1488, 984, 500, 75, 200, 209, 515, - /* 930 */ 1649, 142, 520, 565, 182, 1671, 37, 612, 608, 604, - /* 940 */ 600, 250, 470, 1387, 37, 475, 137, 1332, 235, 214, - /* 950 */ 118, 1274, 431, 427, 423, 419, 181, 1708, 228, 1281, - /* 960 */ 83, 1680, 523, 1682, 1683, 519, 80, 540, 1265, 244, - /* 970 */ 1748, 484, 1463, 1279, 302, 1744, 145, 1243, 119, 120, - /* 980 */ 46, 65, 545, 119, 179, 1139, 120, 107, 1412, 237, - /* 990 */ 464, 529, 119, 432, 1776, 1696, 219, 325, 1407, 1545, - /* 1000 */ 1778, 498, 533, 3, 1679, 5, 227, 230, 27, 307, - /* 1010 */ 1268, 1269, 1270, 1271, 1272, 1276, 1277, 1278, 327, 243, - /* 1020 */ 1042, 255, 1206, 1070, 1074, 232, 330, 1081, 1079, 478, - /* 1030 */ 1679, 1695, 205, 123, 614, 334, 289, 1150, 1011, 521, - /* 1040 */ 290, 252, 380, 178, 1649, 170, 520, 175, 373, 409, - /* 1050 */ 1592, 1158, 160, 199, 388, 387, 1679, 1695, 389, 1212, - /* 1060 */ 393, 394, 402, 1215, 405, 521, 167, 406, 168, 169, - /* 1070 */ 1649, 1708, 520, 1214, 83, 1680, 523, 1682, 1683, 519, - /* 1080 */ 407, 540, 1216, 1695, 1748, 408, 172, 410, 302, 1744, - /* 1090 */ 1823, 521, 174, 1213, 412, 177, 1649, 1708, 520, 1782, - /* 1100 */ 83, 1680, 523, 1682, 1683, 519, 411, 540, 1679, 63, - /* 1110 */ 1748, 415, 180, 434, 302, 1744, 1823, 436, 1495, 184, - /* 1120 */ 1491, 186, 1679, 1708, 125, 1805, 83, 1680, 523, 1682, - /* 1130 */ 1683, 519, 298, 540, 86, 1695, 1748, 126, 198, 1493, - /* 1140 */ 302, 1744, 1823, 521, 1489, 127, 1631, 253, 1649, 1695, - /* 1150 */ 520, 1766, 128, 1630, 472, 465, 469, 521, 1211, 466, - /* 1160 */ 527, 201, 1649, 501, 520, 204, 207, 476, 485, 477, - /* 1170 */ 474, 1789, 1779, 1679, 482, 1708, 301, 501, 269, 1680, - /* 1180 */ 523, 1682, 1683, 519, 210, 540, 488, 1788, 6, 1708, - /* 1190 */ 454, 213, 269, 1680, 523, 1682, 1683, 519, 494, 540, - /* 1200 */ 1695, 1306, 1769, 220, 1810, 462, 481, 113, 521, 1210, - /* 1210 */ 1763, 40, 510, 1649, 303, 520, 151, 18, 1810, 195, - /* 1220 */ 1807, 1598, 507, 530, 531, 218, 525, 1597, 221, 526, - /* 1230 */ 149, 457, 239, 241, 1807, 311, 451, 1679, 139, 532, - /* 1240 */ 1708, 194, 1826, 84, 1680, 523, 1682, 1683, 519, 1729, - /* 1250 */ 540, 1679, 254, 1748, 72, 1806, 1506, 512, 1744, 504, - /* 1260 */ 1679, 511, 74, 226, 1695, 1478, 51, 543, 229, 50, - /* 1270 */ 231, 257, 518, 617, 249, 47, 138, 1649, 1695, 520, - /* 1280 */ 1549, 261, 263, 270, 264, 259, 521, 1695, 1643, 1642, - /* 1290 */ 58, 1649, 1641, 520, 329, 521, 1638, 332, 331, 1177, - /* 1300 */ 1649, 1178, 520, 156, 1708, 336, 1636, 277, 1680, 523, - /* 1310 */ 1682, 1683, 519, 517, 540, 514, 1720, 1679, 1708, 338, - /* 1320 */ 339, 135, 1680, 523, 1682, 1683, 519, 1708, 540, 340, - /* 1330 */ 84, 1680, 523, 1682, 1683, 519, 1635, 540, 342, 1679, - /* 1340 */ 1748, 1634, 344, 1633, 1695, 1745, 346, 1632, 348, 1616, - /* 1350 */ 157, 351, 521, 352, 1153, 1152, 1610, 1649, 1609, 520, - /* 1360 */ 357, 358, 1608, 1607, 502, 1824, 1695, 1125, 1585, 1584, - /* 1370 */ 1583, 1582, 1581, 1580, 521, 1579, 1578, 1577, 1576, 1649, - /* 1380 */ 1575, 520, 1574, 1573, 1708, 1572, 1571, 273, 1680, 523, - /* 1390 */ 1682, 1683, 519, 1679, 540, 1570, 1569, 1568, 1567, 117, - /* 1400 */ 1566, 1565, 1564, 1563, 1562, 1679, 1708, 1561, 1560, 135, - /* 1410 */ 1680, 523, 1682, 1683, 519, 1127, 540, 1559, 1558, 1435, - /* 1420 */ 1695, 1403, 143, 949, 493, 108, 948, 165, 521, 1402, - /* 1430 */ 1624, 1618, 1695, 1649, 398, 520, 400, 166, 1606, 173, - /* 1440 */ 518, 1605, 109, 1595, 1484, 1649, 306, 520, 171, 1434, - /* 1450 */ 176, 1432, 418, 1825, 1430, 1428, 1679, 422, 1426, 426, - /* 1460 */ 1708, 416, 430, 278, 1680, 523, 1682, 1683, 519, 977, - /* 1470 */ 540, 417, 1708, 421, 420, 277, 1680, 523, 1682, 1683, - /* 1480 */ 519, 424, 540, 1695, 1721, 425, 428, 429, 1415, 1414, - /* 1490 */ 1401, 521, 1486, 1085, 1084, 1485, 1649, 1010, 520, 1009, - /* 1500 */ 1008, 587, 589, 1007, 1004, 1424, 45, 1679, 295, 308, - /* 1510 */ 1003, 183, 1002, 1419, 453, 296, 1417, 456, 297, 1400, - /* 1520 */ 458, 1679, 1399, 1708, 460, 1623, 278, 1680, 523, 1682, - /* 1530 */ 1683, 519, 85, 540, 1695, 1617, 49, 467, 1160, 1604, - /* 1540 */ 1603, 1602, 521, 129, 1594, 68, 206, 1649, 1695, 520, - /* 1550 */ 211, 4, 37, 15, 136, 43, 521, 1331, 215, 22, - /* 1560 */ 310, 1649, 1324, 520, 216, 217, 69, 23, 1669, 16, - /* 1570 */ 1679, 468, 223, 41, 1708, 208, 202, 278, 1680, 523, - /* 1580 */ 1682, 1683, 519, 48, 540, 1303, 1302, 1679, 1708, 42, - /* 1590 */ 140, 265, 1680, 523, 1682, 1683, 519, 1695, 540, 1360, - /* 1600 */ 17, 1355, 1349, 1354, 10, 521, 19, 304, 1359, 1358, - /* 1610 */ 1649, 305, 520, 1245, 1695, 29, 141, 153, 1244, 1266, - /* 1620 */ 234, 1230, 521, 12, 20, 1593, 21, 1649, 236, 520, - /* 1630 */ 240, 1329, 522, 238, 70, 1668, 1679, 1708, 245, 528, - /* 1640 */ 272, 1680, 523, 1682, 1683, 519, 75, 540, 1679, 13, - /* 1650 */ 71, 1711, 1200, 1247, 1708, 539, 44, 274, 1680, 523, - /* 1660 */ 1682, 1683, 519, 1695, 540, 1071, 544, 318, 542, 242, - /* 1670 */ 546, 521, 1068, 548, 1065, 1695, 1649, 549, 520, 551, - /* 1680 */ 554, 552, 555, 521, 557, 1059, 1057, 558, 1649, 1679, - /* 1690 */ 520, 1063, 1062, 1048, 76, 77, 1080, 55, 564, 247, - /* 1700 */ 1061, 1076, 1060, 1708, 975, 573, 266, 1680, 523, 1682, - /* 1710 */ 1683, 519, 999, 540, 1017, 1708, 1695, 576, 275, 1680, - /* 1720 */ 523, 1682, 1683, 519, 521, 540, 248, 997, 996, 1649, - /* 1730 */ 995, 520, 992, 994, 993, 991, 990, 1014, 1012, 987, - /* 1740 */ 986, 1679, 985, 982, 981, 980, 1431, 597, 598, 599, - /* 1750 */ 1679, 1429, 601, 602, 1427, 603, 1708, 1425, 605, 267, - /* 1760 */ 1680, 523, 1682, 1683, 519, 606, 540, 607, 1695, 609, - /* 1770 */ 610, 611, 1413, 613, 1398, 615, 521, 1695, 1186, 616, - /* 1780 */ 619, 1649, 258, 520, 620, 521, 1373, 1373, 1373, 1373, - /* 1790 */ 1649, 1373, 520, 1373, 1373, 1373, 1373, 1373, 1373, 1679, - /* 1800 */ 1373, 1373, 1373, 1373, 1373, 1373, 1373, 1373, 1708, 1373, - /* 1810 */ 1373, 276, 1680, 523, 1682, 1683, 519, 1708, 540, 1373, - /* 1820 */ 268, 1680, 523, 1682, 1683, 519, 1695, 540, 1373, 1373, - /* 1830 */ 1373, 1373, 1373, 1373, 521, 1373, 1373, 497, 1373, 1649, - /* 1840 */ 1679, 520, 1373, 1373, 1373, 1373, 1373, 1373, 1373, 1373, - /* 1850 */ 1373, 1373, 1373, 1373, 1373, 1373, 1373, 1679, 1373, 1373, - /* 1860 */ 1373, 1373, 1373, 1373, 1373, 114, 1708, 1695, 1373, 1691, - /* 1870 */ 1680, 523, 1682, 1683, 519, 521, 540, 1373, 1373, 1373, - /* 1880 */ 1649, 1373, 520, 1373, 1695, 501, 1373, 1373, 1373, 1373, - /* 1890 */ 1373, 1373, 521, 1373, 1373, 1373, 1373, 1649, 1373, 520, - /* 1900 */ 1373, 1373, 1373, 1373, 112, 1373, 1679, 1708, 1373, 1373, - /* 1910 */ 1690, 1680, 523, 1682, 1683, 519, 1373, 540, 1679, 222, - /* 1920 */ 1755, 496, 1373, 495, 1708, 1373, 1810, 1689, 1680, 523, - /* 1930 */ 1682, 1683, 519, 1695, 540, 1373, 1373, 1373, 151, 497, - /* 1940 */ 1373, 521, 1807, 1373, 1373, 1695, 1649, 1373, 520, 1373, - /* 1950 */ 1373, 1373, 1373, 521, 1373, 1373, 1373, 1373, 1649, 1679, - /* 1960 */ 520, 1373, 1373, 1373, 1373, 1373, 1373, 114, 1373, 1373, - /* 1970 */ 1373, 1373, 1373, 1708, 1373, 1373, 287, 1680, 523, 1682, - /* 1980 */ 1683, 519, 1373, 540, 1373, 1708, 1695, 501, 286, 1680, - /* 1990 */ 523, 1682, 1683, 519, 521, 540, 1373, 1373, 1373, 1649, - /* 2000 */ 1373, 520, 1373, 1373, 1373, 1373, 112, 1373, 1373, 1373, - /* 2010 */ 1373, 1679, 1373, 1373, 1373, 1373, 1373, 1373, 1373, 1373, - /* 2020 */ 1679, 222, 1755, 496, 1373, 495, 1708, 1373, 1810, 288, - /* 2030 */ 1680, 523, 1682, 1683, 519, 1373, 540, 1373, 1695, 1373, - /* 2040 */ 149, 1373, 1373, 1373, 1807, 1373, 521, 1695, 1373, 1373, - /* 2050 */ 1373, 1649, 1373, 520, 1373, 521, 1373, 1373, 1373, 1373, - /* 2060 */ 1649, 1373, 520, 1373, 1373, 1373, 1373, 1373, 1373, 1373, - /* 2070 */ 1373, 1373, 1373, 1373, 1373, 1373, 1373, 1373, 1708, 1373, - /* 2080 */ 1373, 285, 1680, 523, 1682, 1683, 519, 1708, 540, 1373, - /* 2090 */ 271, 1680, 523, 1682, 1683, 519, 1373, 540, + /* 0 */ 1697, 1845, 1522, 309, 412, 1697, 413, 1434, 326, 1400, + /* 10 */ 137, 1694, 37, 35, 1490, 1844, 1694, 1710, 417, 1842, + /* 20 */ 318, 556, 1208, 556, 1230, 38, 36, 34, 33, 32, + /* 30 */ 325, 324, 109, 420, 109, 413, 1434, 1690, 1696, 451, + /* 40 */ 1222, 456, 1690, 1696, 1726, 30, 240, 1206, 559, 1533, + /* 50 */ 1793, 1533, 540, 559, 22, 556, 555, 1680, 14, 539, + /* 60 */ 37, 35, 1335, 322, 1214, 1215, 157, 335, 318, 1710, + /* 70 */ 1208, 134, 520, 365, 1790, 38, 36, 34, 33, 32, + /* 80 */ 1535, 1, 1214, 1533, 1739, 67, 555, 85, 1711, 542, + /* 90 */ 1713, 1714, 538, 58, 559, 1206, 1726, 1779, 113, 76, + /* 100 */ 371, 292, 1775, 637, 519, 556, 14, 1528, 1845, 1680, + /* 110 */ 1425, 539, 1214, 1845, 1845, 543, 369, 1277, 1278, 963, + /* 120 */ 1526, 560, 152, 470, 555, 1631, 1842, 154, 152, 2, + /* 130 */ 430, 1842, 1842, 1533, 206, 82, 1739, 290, 478, 86, + /* 140 */ 1711, 542, 1713, 1714, 538, 1369, 559, 40, 118, 1779, + /* 150 */ 1680, 637, 198, 311, 1775, 148, 1525, 967, 968, 1209, + /* 160 */ 58, 1207, 70, 328, 473, 1277, 1278, 232, 56, 467, + /* 170 */ 364, 134, 363, 1233, 197, 495, 1806, 1223, 330, 1218, + /* 180 */ 1535, 1578, 1580, 1212, 1213, 41, 1259, 1260, 1262, 1263, + /* 190 */ 1264, 1265, 1266, 535, 557, 1274, 1275, 1276, 1279, 53, + /* 200 */ 1232, 1226, 52, 1579, 1580, 26, 59, 1209, 1845, 1207, + /* 210 */ 510, 155, 557, 1274, 1275, 38, 36, 34, 33, 32, + /* 220 */ 37, 35, 153, 155, 1424, 1710, 1842, 402, 318, 67, + /* 230 */ 1208, 1212, 1213, 302, 1259, 1260, 1262, 1263, 1264, 1265, + /* 240 */ 1266, 535, 557, 1274, 1275, 1276, 1279, 516, 1726, 465, + /* 250 */ 464, 1529, 1726, 489, 463, 1206, 509, 114, 460, 1668, + /* 260 */ 540, 459, 458, 457, 1680, 1680, 14, 539, 37, 35, + /* 270 */ 1112, 1113, 1214, 166, 165, 117, 318, 155, 1208, 1299, + /* 280 */ 520, 1511, 303, 58, 301, 300, 356, 453, 58, 2, + /* 290 */ 155, 455, 1739, 508, 1845, 85, 1711, 542, 1713, 1714, + /* 300 */ 538, 1304, 559, 1206, 344, 1779, 358, 354, 152, 292, + /* 310 */ 1775, 637, 1842, 454, 115, 38, 36, 34, 33, 32, + /* 320 */ 1214, 1845, 136, 1524, 1414, 1277, 1278, 1509, 518, 149, + /* 330 */ 1786, 1787, 1233, 1791, 1694, 152, 27, 8, 430, 1842, + /* 340 */ 1070, 582, 581, 580, 1074, 579, 1076, 1077, 578, 1079, + /* 350 */ 575, 1403, 1085, 572, 1087, 1088, 569, 566, 81, 637, + /* 360 */ 1690, 1696, 38, 36, 34, 33, 32, 1209, 78, 1207, + /* 370 */ 1359, 559, 99, 1277, 1278, 98, 97, 96, 95, 94, + /* 380 */ 93, 92, 91, 90, 593, 1349, 38, 36, 34, 33, + /* 390 */ 32, 1212, 1213, 522, 1259, 1260, 1262, 1263, 1264, 1265, + /* 400 */ 1266, 535, 557, 1274, 1275, 1276, 1279, 502, 1357, 1358, + /* 410 */ 1360, 1361, 980, 155, 979, 1209, 99, 1207, 155, 98, + /* 420 */ 97, 96, 95, 94, 93, 92, 91, 90, 37, 35, + /* 430 */ 1280, 11, 10, 1710, 462, 461, 318, 162, 1208, 1212, + /* 440 */ 1213, 981, 1259, 1260, 1262, 1263, 1264, 1265, 1266, 535, + /* 450 */ 557, 1274, 1275, 1276, 1279, 38, 36, 34, 33, 32, + /* 460 */ 1726, 479, 65, 1206, 1845, 64, 593, 155, 540, 980, + /* 470 */ 147, 979, 1585, 1680, 1231, 539, 37, 35, 1843, 308, + /* 480 */ 1214, 1461, 1842, 1572, 318, 1793, 1208, 1423, 1583, 1214, + /* 490 */ 38, 36, 34, 33, 32, 1422, 449, 9, 981, 1234, + /* 500 */ 1739, 1395, 1845, 87, 1711, 542, 1713, 1714, 538, 1789, + /* 510 */ 559, 1206, 1311, 1779, 199, 134, 152, 1778, 1775, 637, + /* 520 */ 1842, 543, 133, 1585, 1536, 1246, 1342, 1680, 1214, 321, + /* 530 */ 323, 1630, 1232, 1277, 1278, 1680, 293, 609, 607, 1583, + /* 540 */ 1421, 615, 614, 613, 333, 9, 612, 611, 610, 119, + /* 550 */ 605, 604, 603, 602, 601, 600, 599, 598, 127, 594, + /* 560 */ 1246, 1402, 38, 36, 34, 33, 32, 637, 1297, 505, + /* 570 */ 69, 291, 1285, 967, 968, 1209, 1420, 1207, 1232, 1419, + /* 580 */ 1680, 1277, 1278, 1394, 28, 108, 107, 106, 105, 104, + /* 590 */ 103, 102, 101, 100, 38, 36, 34, 33, 32, 1212, + /* 600 */ 1213, 1510, 1259, 1260, 1262, 1263, 1264, 1265, 1266, 535, + /* 610 */ 557, 1274, 1275, 1276, 1279, 556, 1680, 1585, 1585, 1680, + /* 620 */ 1298, 331, 585, 1209, 329, 1207, 370, 231, 1518, 134, + /* 630 */ 34, 33, 32, 1583, 1584, 1418, 37, 35, 1535, 511, + /* 640 */ 506, 200, 1303, 1533, 318, 591, 1208, 1212, 1213, 1417, + /* 650 */ 1259, 1260, 1262, 1263, 1264, 1265, 1266, 535, 557, 1274, + /* 660 */ 1275, 1276, 1279, 556, 125, 124, 588, 587, 586, 411, + /* 670 */ 419, 1206, 415, 415, 372, 1680, 556, 29, 316, 1292, + /* 680 */ 1293, 1294, 1295, 1296, 1300, 1301, 1302, 387, 1214, 1680, + /* 690 */ 185, 1533, 556, 263, 591, 597, 1563, 1505, 1416, 1261, + /* 700 */ 1190, 1191, 140, 388, 1533, 2, 1413, 556, 447, 443, + /* 710 */ 439, 435, 184, 125, 124, 588, 587, 586, 429, 1793, + /* 720 */ 1533, 1698, 1710, 1334, 289, 1232, 1230, 637, 1412, 1700, + /* 730 */ 1411, 455, 1694, 395, 7, 1533, 407, 68, 1680, 556, + /* 740 */ 182, 1277, 1278, 1788, 556, 1261, 1680, 1410, 1409, 1726, + /* 750 */ 1530, 380, 1235, 454, 408, 1657, 382, 540, 1690, 1696, + /* 760 */ 135, 524, 1680, 556, 539, 269, 1702, 1533, 1680, 559, + /* 770 */ 1680, 1621, 1533, 556, 487, 496, 589, 267, 55, 1576, + /* 780 */ 527, 54, 164, 1209, 553, 1207, 373, 1680, 1680, 1739, + /* 790 */ 596, 1533, 287, 1711, 542, 1713, 1714, 538, 167, 559, + /* 800 */ 181, 1533, 173, 1464, 178, 1520, 425, 1212, 1213, 1408, + /* 810 */ 1259, 1260, 1262, 1263, 1264, 1265, 1266, 535, 557, 1274, + /* 820 */ 1275, 1276, 1279, 58, 590, 171, 406, 1576, 1516, 401, + /* 830 */ 400, 399, 398, 397, 394, 393, 392, 391, 390, 386, + /* 840 */ 385, 384, 383, 377, 376, 375, 374, 203, 1032, 1680, + /* 850 */ 38, 36, 34, 33, 32, 556, 556, 1208, 556, 516, + /* 860 */ 1407, 84, 1406, 465, 464, 1034, 554, 253, 463, 332, + /* 870 */ 1405, 114, 460, 1798, 1330, 459, 458, 457, 608, 1451, + /* 880 */ 212, 534, 1206, 1533, 1533, 190, 1533, 117, 188, 486, + /* 890 */ 1710, 1508, 1261, 62, 61, 368, 293, 1217, 161, 1214, + /* 900 */ 1680, 466, 1680, 192, 362, 516, 191, 1330, 194, 196, + /* 910 */ 1680, 193, 195, 1446, 1444, 288, 584, 1726, 352, 359, + /* 920 */ 350, 346, 342, 158, 337, 519, 115, 477, 1297, 1415, + /* 930 */ 1680, 1333, 539, 117, 1216, 468, 471, 123, 637, 1004, + /* 940 */ 475, 150, 1786, 1787, 532, 1791, 235, 11, 10, 48, + /* 950 */ 525, 216, 1491, 155, 448, 503, 1005, 1739, 1710, 480, + /* 960 */ 86, 1711, 542, 1713, 1714, 538, 1440, 559, 1397, 1398, + /* 970 */ 1779, 528, 115, 39, 311, 1775, 148, 223, 491, 39, + /* 980 */ 1298, 1727, 1710, 334, 591, 1726, 39, 151, 1786, 1787, + /* 990 */ 1356, 1791, 218, 540, 1209, 242, 1207, 1807, 1680, 1435, + /* 1000 */ 539, 1573, 1303, 125, 124, 588, 587, 586, 1809, 1726, + /* 1010 */ 121, 1220, 633, 517, 1305, 234, 237, 540, 1212, 1213, + /* 1020 */ 1267, 239, 1680, 1710, 539, 1739, 3, 1163, 272, 1711, + /* 1030 */ 542, 1713, 1714, 538, 122, 559, 244, 29, 316, 1292, + /* 1040 */ 1293, 1294, 1295, 1296, 1300, 1301, 1302, 123, 1219, 1739, + /* 1050 */ 1726, 548, 86, 1711, 542, 1713, 1714, 538, 540, 559, + /* 1060 */ 48, 564, 1779, 1680, 1710, 539, 311, 1775, 1858, 1289, + /* 1070 */ 122, 123, 110, 122, 5, 250, 336, 1813, 1230, 339, + /* 1080 */ 343, 298, 1174, 1032, 299, 259, 389, 163, 1063, 396, + /* 1090 */ 1739, 1726, 1623, 86, 1711, 542, 1713, 1714, 538, 540, + /* 1100 */ 559, 262, 1091, 1779, 1680, 404, 539, 311, 1775, 1858, + /* 1110 */ 403, 1095, 1102, 1100, 126, 405, 409, 1236, 1836, 410, + /* 1120 */ 418, 1239, 421, 170, 172, 1238, 422, 423, 1240, 426, + /* 1130 */ 424, 1739, 175, 177, 86, 1711, 542, 1713, 1714, 538, + /* 1140 */ 1710, 559, 427, 1237, 1779, 428, 180, 450, 311, 1775, + /* 1150 */ 1858, 431, 452, 66, 183, 1523, 187, 1519, 481, 1797, + /* 1160 */ 189, 128, 307, 89, 260, 129, 1521, 1726, 482, 485, + /* 1170 */ 201, 204, 488, 1517, 130, 540, 131, 490, 207, 1235, + /* 1180 */ 1680, 210, 539, 1810, 504, 546, 6, 492, 1662, 1820, + /* 1190 */ 1661, 1819, 513, 1800, 222, 520, 142, 499, 500, 224, + /* 1200 */ 498, 225, 493, 1710, 501, 1330, 310, 1739, 497, 226, + /* 1210 */ 278, 1711, 542, 1713, 1714, 538, 507, 559, 214, 217, + /* 1220 */ 1710, 116, 1234, 42, 1841, 18, 526, 529, 227, 523, + /* 1230 */ 1726, 233, 312, 1861, 544, 545, 1845, 320, 540, 1794, + /* 1240 */ 1629, 549, 246, 1680, 1628, 539, 551, 1726, 261, 550, + /* 1250 */ 154, 77, 1534, 248, 1842, 540, 75, 562, 520, 264, + /* 1260 */ 1680, 228, 539, 1760, 1577, 1506, 256, 49, 636, 266, + /* 1270 */ 1739, 270, 1674, 278, 1711, 542, 1713, 1714, 538, 279, + /* 1280 */ 559, 271, 268, 1710, 141, 236, 1673, 1739, 530, 60, + /* 1290 */ 87, 1711, 542, 1713, 1714, 538, 238, 559, 1672, 1845, + /* 1300 */ 1779, 1710, 338, 1669, 531, 1775, 340, 341, 1201, 1202, + /* 1310 */ 1726, 159, 345, 152, 1667, 347, 348, 1842, 537, 349, + /* 1320 */ 1666, 1665, 351, 1680, 353, 539, 1664, 355, 1726, 1663, + /* 1330 */ 357, 1647, 160, 360, 361, 1177, 540, 1176, 1641, 1640, + /* 1340 */ 366, 1680, 367, 539, 1639, 1638, 1149, 1616, 63, 1615, + /* 1350 */ 1739, 378, 1710, 286, 1711, 542, 1713, 1714, 538, 536, + /* 1360 */ 559, 533, 1751, 1614, 1613, 1612, 1611, 1610, 1739, 379, + /* 1370 */ 640, 138, 1711, 542, 1713, 1714, 538, 381, 559, 1726, + /* 1380 */ 1609, 1608, 1607, 1606, 258, 1605, 1604, 540, 1603, 1602, + /* 1390 */ 1601, 1600, 1680, 516, 539, 1599, 145, 1598, 1597, 1596, + /* 1400 */ 120, 1595, 631, 627, 623, 619, 257, 1594, 1593, 1592, + /* 1410 */ 1591, 1590, 1589, 1710, 1151, 1588, 521, 1859, 1587, 1739, + /* 1420 */ 1586, 117, 87, 1711, 542, 1713, 1714, 538, 1463, 559, + /* 1430 */ 1431, 83, 1779, 168, 251, 146, 970, 1776, 969, 111, + /* 1440 */ 1726, 520, 1430, 169, 414, 1655, 1649, 416, 540, 1637, + /* 1450 */ 112, 174, 1636, 1680, 176, 539, 1626, 1512, 179, 1462, + /* 1460 */ 115, 1460, 434, 998, 433, 1458, 1710, 552, 438, 1456, + /* 1470 */ 432, 1454, 437, 436, 441, 229, 1786, 515, 442, 514, + /* 1480 */ 1739, 440, 1845, 282, 1711, 542, 1713, 1714, 538, 1710, + /* 1490 */ 559, 444, 445, 1726, 1443, 494, 154, 446, 208, 1442, + /* 1500 */ 1842, 540, 1429, 1514, 186, 1106, 1680, 516, 539, 1105, + /* 1510 */ 1513, 1031, 1452, 1030, 1029, 1028, 1726, 1182, 606, 202, + /* 1520 */ 608, 1025, 512, 47, 540, 1024, 304, 1023, 1447, 1680, + /* 1530 */ 305, 539, 469, 1739, 1445, 117, 138, 1711, 542, 1713, + /* 1540 */ 1714, 538, 315, 559, 306, 1710, 1428, 472, 474, 1427, + /* 1550 */ 88, 476, 1654, 1184, 51, 520, 1739, 1648, 483, 287, + /* 1560 */ 1711, 542, 1713, 1714, 538, 1635, 559, 1634, 1633, 1625, + /* 1570 */ 71, 15, 1726, 4, 115, 209, 39, 1371, 23, 213, + /* 1580 */ 537, 205, 1860, 484, 45, 1680, 211, 539, 50, 229, + /* 1590 */ 1786, 515, 139, 514, 220, 215, 1845, 132, 1710, 1355, + /* 1600 */ 219, 24, 221, 1348, 1700, 72, 230, 1710, 143, 1327, + /* 1610 */ 152, 25, 1739, 1326, 1842, 286, 1711, 542, 1713, 1714, + /* 1620 */ 538, 1710, 559, 44, 1752, 1726, 1388, 17, 1383, 1377, + /* 1630 */ 10, 1382, 313, 540, 1726, 1387, 1386, 314, 1680, 19, + /* 1640 */ 539, 1269, 540, 1268, 31, 1290, 144, 1680, 1726, 539, + /* 1650 */ 156, 317, 16, 12, 13, 20, 540, 43, 1254, 21, + /* 1660 */ 319, 1680, 1710, 539, 1624, 1739, 541, 247, 287, 1711, + /* 1670 */ 542, 1713, 1714, 538, 1739, 559, 241, 287, 1711, 542, + /* 1680 */ 1713, 1714, 538, 1710, 559, 1353, 243, 547, 1739, 1726, + /* 1690 */ 245, 273, 1711, 542, 1713, 1714, 538, 540, 559, 73, + /* 1700 */ 74, 78, 1680, 1699, 539, 252, 1742, 1224, 1271, 249, + /* 1710 */ 1726, 1092, 558, 46, 561, 563, 327, 1089, 540, 565, + /* 1720 */ 567, 568, 570, 1680, 1086, 539, 571, 573, 1080, 1739, + /* 1730 */ 574, 576, 274, 1711, 542, 1713, 1714, 538, 1078, 559, + /* 1740 */ 1069, 1710, 1084, 583, 577, 1101, 1083, 79, 1082, 1081, + /* 1750 */ 1739, 80, 1710, 281, 1711, 542, 1713, 1714, 538, 57, + /* 1760 */ 559, 254, 1097, 1710, 996, 592, 1020, 595, 1726, 255, + /* 1770 */ 1038, 1013, 1018, 1017, 1016, 1035, 540, 1015, 1014, 1726, + /* 1780 */ 1012, 1680, 1011, 539, 1033, 1008, 1007, 540, 1006, 1003, + /* 1790 */ 1726, 1002, 1680, 1001, 539, 1459, 617, 616, 540, 618, + /* 1800 */ 1457, 620, 621, 1680, 622, 539, 1455, 624, 1739, 625, + /* 1810 */ 626, 283, 1711, 542, 1713, 1714, 538, 1453, 559, 1739, + /* 1820 */ 629, 628, 275, 1711, 542, 1713, 1714, 538, 1710, 559, + /* 1830 */ 1739, 630, 1441, 284, 1711, 542, 1713, 1714, 538, 632, + /* 1840 */ 559, 1426, 634, 635, 1710, 1210, 265, 638, 639, 1401, + /* 1850 */ 1401, 1401, 1401, 1401, 1401, 1726, 1401, 1401, 1401, 1401, + /* 1860 */ 1401, 1401, 1401, 540, 1401, 1401, 1401, 1401, 1680, 1401, + /* 1870 */ 539, 1726, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 540, + /* 1880 */ 1401, 1401, 1401, 1401, 1680, 1401, 539, 1401, 1401, 1401, + /* 1890 */ 1401, 1401, 1401, 1710, 1401, 1739, 1401, 1401, 276, 1711, + /* 1900 */ 542, 1713, 1714, 538, 1401, 559, 1401, 1710, 1401, 1401, + /* 1910 */ 1401, 1739, 1401, 1401, 285, 1711, 542, 1713, 1714, 538, + /* 1920 */ 1726, 559, 1401, 1401, 1401, 1401, 1401, 1401, 540, 1401, + /* 1930 */ 1401, 1401, 1401, 1680, 1726, 539, 1401, 1401, 1401, 1401, + /* 1940 */ 1401, 1401, 540, 1401, 1401, 1401, 1401, 1680, 1710, 539, + /* 1950 */ 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, + /* 1960 */ 1739, 1401, 1401, 277, 1711, 542, 1713, 1714, 538, 1710, + /* 1970 */ 559, 1401, 1401, 1401, 1739, 1726, 1401, 1722, 1711, 542, + /* 1980 */ 1713, 1714, 538, 540, 559, 1401, 1401, 1401, 1680, 1401, + /* 1990 */ 539, 1401, 1401, 1401, 1401, 1401, 1726, 1401, 1401, 1401, + /* 2000 */ 1401, 1401, 1401, 1401, 540, 1401, 1401, 1401, 1401, 1680, + /* 2010 */ 1401, 539, 1401, 1401, 1401, 1739, 1401, 1401, 1721, 1711, + /* 2020 */ 542, 1713, 1714, 538, 1401, 559, 1401, 1710, 1401, 1401, + /* 2030 */ 1401, 1401, 1401, 1401, 1401, 1401, 1739, 1401, 1710, 1720, + /* 2040 */ 1711, 542, 1713, 1714, 538, 1401, 559, 1401, 1401, 1710, + /* 2050 */ 1401, 1401, 1401, 1401, 1726, 1401, 1401, 1401, 1401, 1401, + /* 2060 */ 1401, 1401, 540, 1401, 1401, 1726, 1401, 1680, 1401, 539, + /* 2070 */ 1401, 1401, 1401, 540, 1401, 1401, 1726, 1401, 1680, 1401, + /* 2080 */ 539, 1401, 1401, 1401, 540, 1401, 1401, 1401, 1401, 1680, + /* 2090 */ 1710, 539, 1401, 1401, 1739, 1401, 1401, 296, 1711, 542, + /* 2100 */ 1713, 1714, 538, 1401, 559, 1739, 1401, 1401, 295, 1711, + /* 2110 */ 542, 1713, 1714, 538, 1710, 559, 1739, 1726, 1401, 297, + /* 2120 */ 1711, 542, 1713, 1714, 538, 540, 559, 1401, 1401, 1401, + /* 2130 */ 1680, 1401, 539, 1401, 1401, 1401, 1401, 1401, 1401, 1401, + /* 2140 */ 1401, 1726, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 540, + /* 2150 */ 1401, 1401, 1401, 1401, 1680, 1401, 539, 1739, 1401, 1401, + /* 2160 */ 294, 1711, 542, 1713, 1714, 538, 1401, 559, 1401, 1401, + /* 2170 */ 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, + /* 2180 */ 1401, 1739, 1401, 1401, 280, 1711, 542, 1713, 1714, 538, + /* 2190 */ 1401, 559, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 269, 280, 242, 271, 283, 284, 274, 245, 271, 247, - /* 10 */ 248, 274, 12, 13, 282, 245, 285, 247, 248, 282, - /* 20 */ 20, 0, 22, 269, 12, 13, 14, 15, 16, 269, - /* 30 */ 276, 20, 12, 13, 14, 15, 16, 277, 338, 285, - /* 40 */ 308, 309, 282, 338, 284, 308, 309, 47, 323, 324, - /* 50 */ 350, 319, 249, 239, 354, 350, 319, 297, 58, 354, - /* 60 */ 12, 13, 14, 246, 64, 242, 249, 20, 20, 309, - /* 70 */ 22, 55, 312, 313, 314, 315, 316, 317, 57, 319, - /* 80 */ 4, 81, 322, 20, 14, 338, 326, 327, 249, 286, - /* 90 */ 20, 249, 269, 249, 82, 47, 80, 350, 338, 83, - /* 100 */ 277, 354, 260, 103, 260, 282, 58, 284, 4, 267, - /* 110 */ 350, 297, 64, 2, 354, 57, 277, 117, 118, 277, - /* 120 */ 297, 277, 297, 12, 13, 14, 15, 16, 81, 81, - /* 130 */ 254, 249, 309, 269, 258, 312, 313, 314, 315, 316, - /* 140 */ 317, 277, 319, 284, 81, 322, 42, 43, 14, 326, - /* 150 */ 327, 103, 338, 294, 20, 316, 113, 81, 158, 277, - /* 160 */ 160, 338, 20, 338, 350, 117, 118, 147, 354, 330, - /* 170 */ 331, 332, 333, 350, 335, 350, 57, 354, 314, 354, - /* 180 */ 41, 145, 182, 183, 153, 185, 186, 187, 188, 189, - /* 190 */ 190, 191, 192, 193, 194, 195, 196, 197, 316, 12, - /* 200 */ 13, 14, 15, 16, 173, 174, 158, 241, 160, 243, - /* 210 */ 210, 168, 169, 331, 332, 333, 20, 335, 284, 12, - /* 220 */ 13, 12, 13, 14, 15, 16, 292, 20, 294, 22, - /* 230 */ 182, 183, 0, 185, 186, 187, 188, 189, 190, 191, - /* 240 */ 192, 193, 194, 195, 196, 197, 12, 13, 14, 15, - /* 250 */ 16, 215, 216, 21, 47, 251, 24, 25, 26, 27, - /* 260 */ 28, 29, 30, 31, 32, 58, 20, 12, 13, 82, - /* 270 */ 2, 64, 0, 210, 271, 20, 272, 22, 47, 81, - /* 280 */ 12, 13, 14, 15, 16, 282, 210, 246, 81, 182, - /* 290 */ 249, 94, 95, 96, 97, 98, 99, 100, 101, 102, - /* 300 */ 103, 104, 47, 106, 107, 108, 109, 110, 111, 14, - /* 310 */ 103, 308, 309, 117, 118, 20, 14, 15, 16, 64, - /* 320 */ 186, 41, 319, 242, 117, 118, 219, 220, 221, 222, - /* 330 */ 223, 20, 60, 61, 62, 63, 81, 65, 66, 67, - /* 340 */ 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, - /* 350 */ 78, 0, 257, 261, 259, 157, 81, 159, 103, 150, - /* 360 */ 20, 269, 82, 282, 93, 158, 242, 160, 229, 242, - /* 370 */ 278, 21, 117, 118, 24, 25, 26, 27, 28, 29, - /* 380 */ 30, 31, 32, 112, 113, 114, 115, 116, 253, 182, - /* 390 */ 183, 160, 185, 186, 187, 188, 189, 190, 191, 192, - /* 400 */ 193, 194, 195, 196, 197, 249, 282, 249, 210, 282, - /* 410 */ 275, 60, 61, 158, 269, 160, 65, 242, 260, 68, - /* 420 */ 69, 276, 242, 72, 73, 74, 12, 13, 14, 279, - /* 430 */ 285, 242, 282, 277, 20, 277, 22, 182, 183, 230, - /* 440 */ 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, - /* 450 */ 195, 196, 197, 242, 22, 60, 61, 282, 269, 242, - /* 460 */ 65, 47, 282, 68, 69, 210, 277, 72, 73, 74, - /* 470 */ 112, 282, 316, 284, 12, 13, 283, 284, 64, 47, - /* 480 */ 64, 186, 20, 242, 22, 210, 249, 331, 332, 333, - /* 490 */ 35, 335, 20, 282, 22, 81, 64, 260, 309, 282, - /* 500 */ 253, 312, 313, 314, 315, 316, 317, 242, 319, 47, - /* 510 */ 269, 322, 55, 266, 277, 326, 327, 103, 277, 47, - /* 520 */ 297, 49, 275, 282, 279, 284, 64, 282, 170, 171, - /* 530 */ 85, 117, 118, 88, 249, 103, 12, 13, 81, 84, - /* 540 */ 83, 86, 87, 81, 89, 260, 22, 282, 93, 0, - /* 550 */ 309, 4, 267, 312, 313, 314, 315, 316, 317, 47, - /* 560 */ 319, 338, 277, 322, 20, 103, 22, 326, 327, 328, - /* 570 */ 115, 47, 158, 350, 160, 297, 64, 354, 269, 117, - /* 580 */ 118, 340, 255, 256, 249, 276, 345, 346, 64, 75, - /* 590 */ 158, 37, 160, 49, 285, 260, 182, 183, 20, 185, - /* 600 */ 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - /* 610 */ 196, 197, 277, 261, 182, 183, 338, 141, 42, 43, - /* 620 */ 158, 269, 160, 261, 268, 251, 242, 103, 350, 242, - /* 630 */ 278, 269, 354, 12, 13, 121, 122, 281, 264, 163, - /* 640 */ 278, 20, 93, 22, 182, 183, 272, 185, 186, 187, - /* 650 */ 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, - /* 660 */ 242, 112, 113, 114, 115, 116, 282, 210, 47, 282, - /* 670 */ 249, 242, 1, 2, 198, 271, 242, 249, 18, 3, - /* 680 */ 20, 260, 158, 310, 160, 64, 282, 27, 260, 242, - /* 690 */ 30, 12, 13, 14, 15, 16, 255, 256, 277, 249, - /* 700 */ 282, 242, 81, 20, 18, 277, 182, 334, 48, 23, - /* 710 */ 260, 282, 308, 309, 47, 242, 282, 193, 194, 195, - /* 720 */ 0, 35, 36, 319, 103, 39, 242, 277, 269, 282, - /* 730 */ 242, 262, 310, 310, 265, 41, 277, 58, 117, 118, - /* 740 */ 0, 282, 56, 284, 24, 25, 26, 27, 28, 29, - /* 750 */ 30, 31, 32, 82, 295, 282, 334, 334, 211, 208, - /* 760 */ 209, 82, 242, 209, 186, 92, 282, 81, 309, 90, - /* 770 */ 282, 312, 313, 314, 315, 316, 317, 64, 319, 158, - /* 780 */ 120, 160, 0, 123, 124, 125, 126, 127, 128, 129, - /* 790 */ 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, - /* 800 */ 140, 20, 282, 182, 183, 119, 185, 186, 187, 188, - /* 810 */ 189, 190, 191, 192, 193, 194, 195, 196, 197, 269, - /* 820 */ 141, 249, 12, 13, 14, 15, 16, 160, 278, 249, - /* 830 */ 147, 0, 260, 93, 249, 242, 150, 151, 152, 57, - /* 840 */ 260, 155, 163, 85, 58, 260, 88, 161, 85, 277, - /* 850 */ 93, 88, 112, 113, 114, 115, 116, 277, 172, 249, - /* 860 */ 249, 175, 277, 177, 178, 179, 180, 181, 58, 270, - /* 870 */ 260, 260, 115, 0, 270, 282, 45, 198, 199, 200, - /* 880 */ 201, 202, 203, 204, 205, 206, 207, 277, 277, 0, - /* 890 */ 242, 277, 249, 0, 85, 22, 210, 88, 44, 21, - /* 900 */ 90, 225, 288, 260, 41, 19, 41, 47, 41, 117, - /* 910 */ 118, 22, 34, 1, 2, 22, 81, 269, 41, 33, - /* 920 */ 277, 227, 270, 270, 64, 277, 91, 270, 147, 270, - /* 930 */ 282, 45, 284, 270, 33, 81, 41, 51, 52, 53, - /* 940 */ 54, 55, 301, 243, 41, 82, 45, 82, 41, 82, - /* 950 */ 41, 141, 51, 52, 53, 54, 55, 309, 357, 82, - /* 960 */ 312, 313, 314, 315, 316, 317, 80, 319, 182, 83, - /* 970 */ 322, 348, 258, 163, 326, 327, 328, 82, 41, 41, - /* 980 */ 41, 80, 41, 41, 83, 82, 41, 41, 0, 82, - /* 990 */ 305, 82, 41, 250, 346, 269, 342, 250, 248, 281, - /* 1000 */ 311, 336, 116, 339, 242, 212, 351, 351, 198, 199, - /* 1010 */ 200, 201, 202, 203, 204, 205, 206, 207, 307, 82, - /* 1020 */ 82, 82, 20, 82, 82, 351, 249, 82, 82, 143, - /* 1030 */ 242, 269, 146, 82, 46, 45, 306, 156, 47, 277, - /* 1040 */ 255, 299, 289, 142, 282, 144, 284, 146, 249, 148, - /* 1050 */ 249, 165, 40, 167, 141, 287, 242, 269, 287, 20, - /* 1060 */ 249, 244, 244, 20, 303, 277, 253, 284, 167, 253, - /* 1070 */ 282, 309, 284, 20, 312, 313, 314, 315, 316, 317, - /* 1080 */ 296, 319, 20, 269, 322, 298, 253, 296, 326, 327, - /* 1090 */ 328, 277, 253, 20, 290, 253, 282, 309, 284, 337, - /* 1100 */ 312, 313, 314, 315, 316, 317, 277, 319, 242, 253, - /* 1110 */ 322, 249, 253, 244, 326, 327, 328, 269, 269, 269, - /* 1120 */ 269, 269, 242, 309, 269, 337, 312, 313, 314, 315, - /* 1130 */ 316, 317, 244, 319, 249, 269, 322, 269, 251, 269, - /* 1140 */ 326, 327, 328, 277, 269, 269, 282, 303, 282, 269, - /* 1150 */ 284, 337, 269, 282, 249, 166, 284, 277, 20, 302, - /* 1160 */ 217, 251, 282, 297, 284, 251, 251, 277, 218, 290, - /* 1170 */ 296, 347, 311, 242, 282, 309, 282, 297, 312, 313, - /* 1180 */ 314, 315, 316, 317, 293, 319, 282, 347, 224, 309, - /* 1190 */ 4, 293, 312, 313, 314, 315, 316, 317, 149, 319, - /* 1200 */ 269, 209, 344, 307, 338, 19, 213, 277, 277, 20, - /* 1210 */ 310, 40, 228, 282, 231, 284, 350, 81, 338, 33, - /* 1220 */ 354, 293, 226, 144, 291, 343, 282, 293, 329, 282, - /* 1230 */ 350, 45, 277, 251, 354, 282, 50, 242, 341, 290, - /* 1240 */ 309, 55, 358, 312, 313, 314, 315, 316, 317, 325, - /* 1250 */ 319, 242, 265, 322, 251, 353, 277, 326, 327, 353, - /* 1260 */ 242, 353, 81, 352, 269, 259, 80, 273, 352, 83, - /* 1270 */ 352, 249, 277, 244, 251, 300, 304, 282, 269, 284, - /* 1280 */ 282, 240, 263, 263, 263, 252, 277, 269, 0, 0, - /* 1290 */ 40, 282, 0, 284, 72, 277, 0, 176, 47, 47, - /* 1300 */ 282, 47, 284, 47, 309, 176, 0, 312, 313, 314, - /* 1310 */ 315, 316, 317, 318, 319, 320, 321, 242, 309, 47, - /* 1320 */ 47, 312, 313, 314, 315, 316, 317, 309, 319, 176, - /* 1330 */ 312, 313, 314, 315, 316, 317, 0, 319, 176, 242, - /* 1340 */ 322, 0, 47, 0, 269, 327, 22, 0, 47, 0, - /* 1350 */ 81, 163, 277, 162, 160, 158, 0, 282, 0, 284, - /* 1360 */ 154, 153, 0, 0, 355, 356, 269, 44, 0, 0, - /* 1370 */ 0, 0, 0, 0, 277, 0, 0, 0, 0, 282, - /* 1380 */ 0, 284, 0, 0, 309, 0, 0, 312, 313, 314, - /* 1390 */ 315, 316, 317, 242, 319, 0, 0, 0, 0, 40, - /* 1400 */ 0, 0, 0, 0, 0, 242, 309, 0, 0, 312, - /* 1410 */ 313, 314, 315, 316, 317, 22, 319, 0, 0, 0, - /* 1420 */ 269, 0, 41, 14, 349, 37, 14, 40, 277, 0, - /* 1430 */ 0, 0, 269, 282, 44, 284, 44, 38, 0, 149, - /* 1440 */ 277, 0, 37, 0, 0, 282, 295, 284, 37, 0, - /* 1450 */ 37, 0, 37, 356, 0, 0, 242, 37, 0, 37, - /* 1460 */ 309, 47, 37, 312, 313, 314, 315, 316, 317, 59, - /* 1470 */ 319, 45, 309, 45, 47, 312, 313, 314, 315, 316, - /* 1480 */ 317, 47, 319, 269, 321, 45, 47, 45, 0, 0, - /* 1490 */ 0, 277, 0, 47, 22, 0, 282, 47, 284, 47, - /* 1500 */ 47, 41, 41, 47, 47, 0, 90, 242, 22, 295, - /* 1510 */ 47, 88, 47, 0, 48, 22, 0, 47, 22, 0, - /* 1520 */ 22, 242, 0, 309, 22, 0, 312, 313, 314, 315, - /* 1530 */ 316, 317, 20, 319, 269, 0, 147, 22, 47, 0, - /* 1540 */ 0, 0, 277, 164, 0, 81, 37, 282, 269, 284, - /* 1550 */ 82, 41, 41, 214, 81, 41, 277, 82, 81, 81, - /* 1560 */ 295, 282, 82, 284, 41, 44, 81, 41, 44, 214, - /* 1570 */ 242, 147, 44, 208, 309, 142, 144, 312, 313, 314, - /* 1580 */ 315, 316, 317, 147, 319, 82, 82, 242, 309, 41, - /* 1590 */ 44, 312, 313, 314, 315, 316, 317, 269, 319, 82, - /* 1600 */ 41, 47, 82, 47, 2, 277, 41, 47, 47, 47, - /* 1610 */ 282, 47, 284, 82, 269, 81, 44, 44, 82, 182, - /* 1620 */ 82, 22, 277, 81, 81, 0, 81, 282, 81, 284, - /* 1630 */ 37, 82, 184, 81, 81, 44, 242, 309, 44, 145, - /* 1640 */ 312, 313, 314, 315, 316, 317, 91, 319, 242, 214, - /* 1650 */ 81, 81, 22, 82, 309, 81, 81, 312, 313, 314, - /* 1660 */ 315, 316, 317, 269, 319, 82, 47, 47, 92, 142, - /* 1670 */ 81, 277, 82, 47, 82, 269, 282, 81, 284, 47, - /* 1680 */ 47, 81, 81, 277, 47, 82, 82, 81, 282, 242, - /* 1690 */ 284, 105, 105, 22, 81, 81, 47, 81, 93, 41, - /* 1700 */ 105, 22, 105, 309, 59, 58, 312, 313, 314, 315, - /* 1710 */ 316, 317, 47, 319, 64, 309, 269, 79, 312, 313, - /* 1720 */ 314, 315, 316, 317, 277, 319, 41, 47, 47, 282, - /* 1730 */ 47, 284, 22, 47, 47, 47, 47, 64, 47, 47, - /* 1740 */ 47, 242, 47, 47, 47, 47, 0, 47, 45, 37, - /* 1750 */ 242, 0, 47, 45, 0, 37, 309, 0, 47, 312, - /* 1760 */ 313, 314, 315, 316, 317, 45, 319, 37, 269, 47, - /* 1770 */ 45, 37, 0, 47, 0, 22, 277, 269, 22, 21, - /* 1780 */ 21, 282, 22, 284, 20, 277, 359, 359, 359, 359, - /* 1790 */ 282, 359, 284, 359, 359, 359, 359, 359, 359, 242, - /* 1800 */ 359, 359, 359, 359, 359, 359, 359, 359, 309, 359, - /* 1810 */ 359, 312, 313, 314, 315, 316, 317, 309, 319, 359, - /* 1820 */ 312, 313, 314, 315, 316, 317, 269, 319, 359, 359, - /* 1830 */ 359, 359, 359, 359, 277, 359, 359, 249, 359, 282, - /* 1840 */ 242, 284, 359, 359, 359, 359, 359, 359, 359, 359, - /* 1850 */ 359, 359, 359, 359, 359, 359, 359, 242, 359, 359, - /* 1860 */ 359, 359, 359, 359, 359, 277, 309, 269, 359, 312, - /* 1870 */ 313, 314, 315, 316, 317, 277, 319, 359, 359, 359, - /* 1880 */ 282, 359, 284, 359, 269, 297, 359, 359, 359, 359, - /* 1890 */ 359, 359, 277, 359, 359, 359, 359, 282, 359, 284, - /* 1900 */ 359, 359, 359, 359, 316, 359, 242, 309, 359, 359, - /* 1910 */ 312, 313, 314, 315, 316, 317, 359, 319, 242, 331, - /* 1920 */ 332, 333, 359, 335, 309, 359, 338, 312, 313, 314, - /* 1930 */ 315, 316, 317, 269, 319, 359, 359, 359, 350, 249, - /* 1940 */ 359, 277, 354, 359, 359, 269, 282, 359, 284, 359, - /* 1950 */ 359, 359, 359, 277, 359, 359, 359, 359, 282, 242, - /* 1960 */ 284, 359, 359, 359, 359, 359, 359, 277, 359, 359, - /* 1970 */ 359, 359, 359, 309, 359, 359, 312, 313, 314, 315, - /* 1980 */ 316, 317, 359, 319, 359, 309, 269, 297, 312, 313, - /* 1990 */ 314, 315, 316, 317, 277, 319, 359, 359, 359, 282, - /* 2000 */ 359, 284, 359, 359, 359, 359, 316, 359, 359, 359, - /* 2010 */ 359, 242, 359, 359, 359, 359, 359, 359, 359, 359, - /* 2020 */ 242, 331, 332, 333, 359, 335, 309, 359, 338, 312, - /* 2030 */ 313, 314, 315, 316, 317, 359, 319, 359, 269, 359, - /* 2040 */ 350, 359, 359, 359, 354, 359, 277, 269, 359, 359, - /* 2050 */ 359, 282, 359, 284, 359, 277, 359, 359, 359, 359, - /* 2060 */ 282, 359, 284, 359, 359, 359, 359, 359, 359, 359, - /* 2070 */ 359, 359, 359, 359, 359, 359, 359, 359, 309, 359, - /* 2080 */ 359, 312, 313, 314, 315, 316, 317, 309, 319, 359, - /* 2090 */ 312, 313, 314, 315, 316, 317, 359, 319, + /* 0 */ 274, 341, 273, 277, 248, 274, 250, 251, 277, 242, + /* 10 */ 257, 285, 12, 13, 261, 355, 285, 245, 14, 359, + /* 20 */ 20, 252, 22, 252, 20, 12, 13, 14, 15, 16, + /* 30 */ 12, 13, 263, 248, 263, 250, 251, 311, 312, 270, + /* 40 */ 22, 270, 311, 312, 272, 326, 327, 47, 322, 280, + /* 50 */ 313, 280, 280, 322, 41, 252, 20, 285, 58, 287, + /* 60 */ 12, 13, 14, 264, 64, 47, 263, 300, 20, 245, + /* 70 */ 22, 272, 300, 300, 337, 12, 13, 14, 15, 16, + /* 80 */ 281, 81, 64, 280, 312, 256, 20, 315, 316, 317, + /* 90 */ 318, 319, 320, 81, 322, 47, 272, 325, 269, 254, + /* 100 */ 252, 329, 330, 103, 280, 252, 58, 278, 341, 285, + /* 110 */ 245, 287, 64, 341, 341, 287, 263, 117, 118, 4, + /* 120 */ 275, 103, 355, 4, 20, 297, 359, 355, 355, 81, + /* 130 */ 57, 359, 359, 280, 55, 254, 312, 289, 19, 315, + /* 140 */ 316, 317, 318, 319, 320, 82, 322, 81, 267, 325, + /* 150 */ 285, 103, 33, 329, 330, 331, 275, 42, 43, 159, + /* 160 */ 81, 161, 83, 264, 45, 117, 118, 343, 3, 50, + /* 170 */ 158, 272, 160, 20, 55, 351, 352, 159, 283, 161, + /* 180 */ 281, 286, 287, 183, 184, 81, 186, 187, 188, 189, + /* 190 */ 190, 191, 192, 193, 194, 195, 196, 197, 198, 80, + /* 200 */ 20, 183, 83, 286, 287, 2, 4, 159, 341, 161, + /* 210 */ 20, 211, 194, 195, 196, 12, 13, 14, 15, 16, + /* 220 */ 12, 13, 355, 211, 245, 245, 359, 75, 20, 256, + /* 230 */ 22, 183, 184, 35, 186, 187, 188, 189, 190, 191, + /* 240 */ 192, 193, 194, 195, 196, 197, 198, 252, 272, 60, + /* 250 */ 61, 278, 272, 300, 65, 47, 280, 68, 69, 0, + /* 260 */ 280, 72, 73, 74, 285, 285, 58, 287, 12, 13, + /* 270 */ 117, 118, 64, 121, 122, 280, 20, 211, 22, 142, + /* 280 */ 300, 0, 84, 81, 86, 87, 154, 89, 81, 81, + /* 290 */ 211, 93, 312, 317, 341, 315, 316, 317, 318, 319, + /* 300 */ 320, 164, 322, 47, 45, 325, 174, 175, 355, 329, + /* 310 */ 330, 103, 359, 115, 319, 12, 13, 14, 15, 16, + /* 320 */ 64, 341, 244, 274, 246, 117, 118, 0, 333, 334, + /* 330 */ 335, 336, 20, 338, 285, 355, 199, 81, 57, 359, + /* 340 */ 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, + /* 350 */ 104, 0, 106, 107, 108, 109, 110, 111, 81, 103, + /* 360 */ 311, 312, 12, 13, 14, 15, 16, 159, 91, 161, + /* 370 */ 183, 322, 21, 117, 118, 24, 25, 26, 27, 28, + /* 380 */ 29, 30, 31, 32, 57, 82, 12, 13, 14, 15, + /* 390 */ 16, 183, 184, 228, 186, 187, 188, 189, 190, 191, + /* 400 */ 192, 193, 194, 195, 196, 197, 198, 220, 221, 222, + /* 410 */ 223, 224, 20, 211, 22, 159, 21, 161, 211, 24, + /* 420 */ 25, 26, 27, 28, 29, 30, 31, 32, 12, 13, + /* 430 */ 14, 1, 2, 245, 258, 259, 20, 55, 22, 183, + /* 440 */ 184, 49, 186, 187, 188, 189, 190, 191, 192, 193, + /* 450 */ 194, 195, 196, 197, 198, 12, 13, 14, 15, 16, + /* 460 */ 272, 300, 80, 47, 341, 83, 57, 211, 280, 20, + /* 470 */ 271, 22, 272, 285, 20, 287, 12, 13, 355, 279, + /* 480 */ 64, 0, 359, 284, 20, 313, 22, 245, 288, 64, + /* 490 */ 12, 13, 14, 15, 16, 245, 47, 81, 49, 20, + /* 500 */ 312, 151, 341, 315, 316, 317, 318, 319, 320, 337, + /* 510 */ 322, 47, 82, 325, 113, 272, 355, 329, 330, 103, + /* 520 */ 359, 287, 148, 272, 281, 82, 14, 285, 64, 295, + /* 530 */ 279, 297, 20, 117, 118, 285, 58, 258, 259, 288, + /* 540 */ 245, 60, 61, 62, 63, 81, 65, 66, 67, 68, + /* 550 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, + /* 560 */ 82, 0, 12, 13, 14, 15, 16, 103, 90, 146, + /* 570 */ 169, 170, 14, 42, 43, 159, 245, 161, 20, 245, + /* 580 */ 285, 117, 118, 233, 2, 24, 25, 26, 27, 28, + /* 590 */ 29, 30, 31, 32, 12, 13, 14, 15, 16, 183, + /* 600 */ 184, 0, 186, 187, 188, 189, 190, 191, 192, 193, + /* 610 */ 194, 195, 196, 197, 198, 252, 285, 272, 272, 285, + /* 620 */ 142, 264, 92, 159, 279, 161, 263, 148, 273, 272, + /* 630 */ 14, 15, 16, 288, 288, 245, 12, 13, 281, 216, + /* 640 */ 217, 112, 164, 280, 20, 93, 22, 183, 184, 245, + /* 650 */ 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, + /* 660 */ 196, 197, 198, 252, 112, 113, 114, 115, 116, 249, + /* 670 */ 249, 47, 252, 252, 263, 285, 252, 199, 200, 201, + /* 680 */ 202, 203, 204, 205, 206, 207, 208, 263, 64, 285, + /* 690 */ 33, 280, 252, 265, 93, 260, 268, 262, 245, 187, + /* 700 */ 171, 172, 45, 263, 280, 81, 245, 252, 51, 52, + /* 710 */ 53, 54, 55, 112, 113, 114, 115, 116, 263, 313, + /* 720 */ 280, 274, 245, 4, 18, 20, 20, 103, 245, 44, + /* 730 */ 245, 93, 285, 27, 37, 280, 30, 80, 285, 252, + /* 740 */ 83, 117, 118, 337, 252, 187, 285, 245, 245, 272, + /* 750 */ 263, 45, 20, 115, 48, 263, 50, 280, 311, 312, + /* 760 */ 18, 41, 285, 252, 287, 23, 81, 280, 285, 322, + /* 770 */ 285, 280, 280, 252, 263, 298, 282, 35, 36, 285, + /* 780 */ 41, 39, 291, 159, 263, 161, 80, 285, 285, 312, + /* 790 */ 64, 280, 315, 316, 317, 318, 319, 320, 56, 322, + /* 800 */ 143, 280, 145, 0, 147, 273, 149, 183, 184, 245, + /* 810 */ 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, + /* 820 */ 196, 197, 198, 81, 282, 168, 120, 285, 273, 123, + /* 830 */ 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, + /* 840 */ 134, 135, 136, 137, 138, 139, 140, 273, 47, 285, + /* 850 */ 12, 13, 14, 15, 16, 252, 252, 22, 252, 252, + /* 860 */ 245, 119, 245, 60, 61, 64, 263, 263, 65, 263, + /* 870 */ 245, 68, 69, 209, 210, 72, 73, 74, 41, 0, + /* 880 */ 148, 273, 47, 280, 280, 85, 280, 280, 88, 304, + /* 890 */ 245, 0, 187, 151, 152, 153, 58, 47, 156, 64, + /* 900 */ 285, 22, 285, 85, 162, 252, 88, 210, 85, 85, + /* 910 */ 285, 88, 88, 0, 0, 173, 273, 272, 176, 82, + /* 920 */ 178, 179, 180, 181, 182, 280, 319, 21, 90, 246, + /* 930 */ 285, 212, 287, 280, 47, 22, 22, 41, 103, 47, + /* 940 */ 34, 334, 335, 336, 58, 338, 362, 1, 2, 41, + /* 950 */ 230, 41, 261, 211, 253, 353, 64, 312, 245, 308, + /* 960 */ 315, 316, 317, 318, 319, 320, 0, 322, 117, 118, + /* 970 */ 325, 232, 319, 41, 329, 330, 331, 348, 82, 41, + /* 980 */ 142, 272, 245, 253, 93, 272, 41, 334, 335, 336, + /* 990 */ 82, 338, 82, 280, 159, 41, 161, 352, 285, 251, + /* 1000 */ 287, 284, 164, 112, 113, 114, 115, 116, 314, 272, + /* 1010 */ 41, 161, 46, 339, 82, 356, 356, 280, 183, 184, + /* 1020 */ 82, 356, 285, 245, 287, 312, 342, 82, 315, 316, + /* 1030 */ 317, 318, 319, 320, 41, 322, 82, 199, 200, 201, + /* 1040 */ 202, 203, 204, 205, 206, 207, 208, 41, 161, 312, + /* 1050 */ 272, 82, 315, 316, 317, 318, 319, 320, 280, 322, + /* 1060 */ 41, 41, 325, 285, 245, 287, 329, 330, 331, 183, + /* 1070 */ 41, 41, 41, 41, 213, 82, 310, 340, 20, 252, + /* 1080 */ 45, 309, 157, 47, 258, 302, 252, 40, 82, 292, + /* 1090 */ 312, 272, 252, 315, 316, 317, 318, 319, 320, 280, + /* 1100 */ 322, 82, 82, 325, 285, 142, 287, 329, 330, 331, + /* 1110 */ 290, 82, 82, 82, 82, 290, 252, 20, 340, 247, + /* 1120 */ 247, 20, 306, 256, 256, 20, 287, 299, 20, 299, + /* 1130 */ 301, 312, 256, 256, 315, 316, 317, 318, 319, 320, + /* 1140 */ 245, 322, 280, 20, 325, 293, 256, 247, 329, 330, + /* 1150 */ 331, 252, 272, 256, 256, 272, 272, 272, 167, 340, + /* 1160 */ 272, 272, 247, 252, 306, 272, 272, 272, 305, 287, + /* 1170 */ 254, 254, 252, 272, 272, 280, 272, 299, 254, 20, + /* 1180 */ 285, 254, 287, 314, 219, 218, 225, 280, 285, 347, + /* 1190 */ 285, 347, 150, 350, 349, 300, 347, 285, 227, 346, + /* 1200 */ 226, 345, 293, 245, 285, 210, 285, 312, 214, 344, + /* 1210 */ 315, 316, 317, 318, 319, 320, 285, 322, 296, 296, + /* 1220 */ 245, 280, 20, 40, 358, 81, 229, 231, 310, 358, + /* 1230 */ 272, 357, 234, 363, 285, 285, 341, 285, 280, 313, + /* 1240 */ 296, 145, 280, 285, 296, 287, 293, 272, 268, 294, + /* 1250 */ 355, 81, 280, 254, 359, 280, 254, 276, 300, 252, + /* 1260 */ 285, 332, 287, 328, 285, 262, 254, 303, 247, 255, + /* 1270 */ 312, 266, 0, 315, 316, 317, 318, 319, 320, 266, + /* 1280 */ 322, 266, 243, 245, 307, 357, 0, 312, 358, 40, + /* 1290 */ 315, 316, 317, 318, 319, 320, 357, 322, 0, 341, + /* 1300 */ 325, 245, 72, 0, 329, 330, 47, 177, 47, 47, + /* 1310 */ 272, 47, 177, 355, 0, 47, 47, 359, 280, 177, + /* 1320 */ 0, 0, 177, 285, 47, 287, 0, 22, 272, 0, + /* 1330 */ 47, 0, 81, 164, 163, 161, 280, 159, 0, 0, + /* 1340 */ 155, 285, 154, 287, 0, 0, 44, 0, 141, 0, + /* 1350 */ 312, 136, 245, 315, 316, 317, 318, 319, 320, 321, + /* 1360 */ 322, 323, 324, 0, 0, 0, 0, 0, 312, 47, + /* 1370 */ 19, 315, 316, 317, 318, 319, 320, 136, 322, 272, + /* 1380 */ 0, 0, 0, 0, 33, 0, 0, 280, 0, 0, + /* 1390 */ 0, 0, 285, 252, 287, 0, 45, 0, 0, 0, + /* 1400 */ 40, 0, 51, 52, 53, 54, 55, 0, 0, 0, + /* 1410 */ 0, 0, 0, 245, 22, 0, 360, 361, 0, 312, + /* 1420 */ 0, 280, 315, 316, 317, 318, 319, 320, 0, 322, + /* 1430 */ 0, 80, 325, 40, 83, 41, 14, 330, 14, 37, + /* 1440 */ 272, 300, 0, 38, 44, 0, 0, 44, 280, 0, + /* 1450 */ 37, 37, 0, 285, 150, 287, 0, 0, 37, 0, + /* 1460 */ 319, 0, 37, 59, 45, 0, 245, 116, 37, 0, + /* 1470 */ 47, 0, 45, 47, 45, 334, 335, 336, 37, 338, + /* 1480 */ 312, 47, 341, 315, 316, 317, 318, 319, 320, 245, + /* 1490 */ 322, 47, 45, 272, 0, 144, 355, 37, 147, 0, + /* 1500 */ 359, 280, 0, 0, 88, 47, 285, 252, 287, 22, + /* 1510 */ 0, 47, 0, 47, 47, 47, 272, 166, 41, 168, + /* 1520 */ 41, 47, 354, 90, 280, 47, 22, 47, 0, 285, + /* 1530 */ 22, 287, 48, 312, 0, 280, 315, 316, 317, 318, + /* 1540 */ 319, 320, 298, 322, 22, 245, 0, 47, 22, 0, + /* 1550 */ 20, 22, 0, 47, 148, 300, 312, 0, 22, 315, + /* 1560 */ 316, 317, 318, 319, 320, 0, 322, 0, 0, 0, + /* 1570 */ 81, 215, 272, 41, 319, 37, 41, 82, 81, 81, + /* 1580 */ 280, 145, 361, 148, 41, 285, 143, 287, 148, 334, + /* 1590 */ 335, 336, 81, 338, 41, 82, 341, 165, 245, 82, + /* 1600 */ 81, 81, 44, 82, 44, 81, 44, 245, 44, 82, + /* 1610 */ 355, 41, 312, 82, 359, 315, 316, 317, 318, 319, + /* 1620 */ 320, 245, 322, 41, 324, 272, 82, 41, 47, 82, + /* 1630 */ 2, 47, 47, 280, 272, 47, 47, 47, 285, 41, + /* 1640 */ 287, 82, 280, 82, 81, 183, 44, 285, 272, 287, + /* 1650 */ 44, 298, 215, 81, 215, 81, 280, 209, 22, 81, + /* 1660 */ 298, 285, 245, 287, 0, 312, 185, 37, 315, 316, + /* 1670 */ 317, 318, 319, 320, 312, 322, 82, 315, 316, 317, + /* 1680 */ 318, 319, 320, 245, 322, 82, 81, 146, 312, 272, + /* 1690 */ 81, 315, 316, 317, 318, 319, 320, 280, 322, 81, + /* 1700 */ 81, 91, 285, 44, 287, 44, 81, 22, 82, 143, + /* 1710 */ 272, 82, 81, 81, 92, 47, 47, 82, 280, 81, + /* 1720 */ 47, 81, 47, 285, 82, 287, 81, 47, 82, 312, + /* 1730 */ 81, 47, 315, 316, 317, 318, 319, 320, 82, 322, + /* 1740 */ 22, 245, 105, 93, 81, 47, 105, 81, 105, 105, + /* 1750 */ 312, 81, 245, 315, 316, 317, 318, 319, 320, 81, + /* 1760 */ 322, 41, 22, 245, 59, 58, 47, 79, 272, 41, + /* 1770 */ 64, 22, 47, 47, 47, 64, 280, 47, 47, 272, + /* 1780 */ 47, 285, 47, 287, 47, 47, 47, 280, 47, 47, + /* 1790 */ 272, 47, 285, 47, 287, 0, 45, 47, 280, 37, + /* 1800 */ 0, 47, 45, 285, 37, 287, 0, 47, 312, 45, + /* 1810 */ 37, 315, 316, 317, 318, 319, 320, 0, 322, 312, + /* 1820 */ 45, 47, 315, 316, 317, 318, 319, 320, 245, 322, + /* 1830 */ 312, 37, 0, 315, 316, 317, 318, 319, 320, 47, + /* 1840 */ 322, 0, 22, 21, 245, 22, 22, 21, 20, 364, + /* 1850 */ 364, 364, 364, 364, 364, 272, 364, 364, 364, 364, + /* 1860 */ 364, 364, 364, 280, 364, 364, 364, 364, 285, 364, + /* 1870 */ 287, 272, 364, 364, 364, 364, 364, 364, 364, 280, + /* 1880 */ 364, 364, 364, 364, 285, 364, 287, 364, 364, 364, + /* 1890 */ 364, 364, 364, 245, 364, 312, 364, 364, 315, 316, + /* 1900 */ 317, 318, 319, 320, 364, 322, 364, 245, 364, 364, + /* 1910 */ 364, 312, 364, 364, 315, 316, 317, 318, 319, 320, + /* 1920 */ 272, 322, 364, 364, 364, 364, 364, 364, 280, 364, + /* 1930 */ 364, 364, 364, 285, 272, 287, 364, 364, 364, 364, + /* 1940 */ 364, 364, 280, 364, 364, 364, 364, 285, 245, 287, + /* 1950 */ 364, 364, 364, 364, 364, 364, 364, 364, 364, 364, + /* 1960 */ 312, 364, 364, 315, 316, 317, 318, 319, 320, 245, + /* 1970 */ 322, 364, 364, 364, 312, 272, 364, 315, 316, 317, + /* 1980 */ 318, 319, 320, 280, 322, 364, 364, 364, 285, 364, + /* 1990 */ 287, 364, 364, 364, 364, 364, 272, 364, 364, 364, + /* 2000 */ 364, 364, 364, 364, 280, 364, 364, 364, 364, 285, + /* 2010 */ 364, 287, 364, 364, 364, 312, 364, 364, 315, 316, + /* 2020 */ 317, 318, 319, 320, 364, 322, 364, 245, 364, 364, + /* 2030 */ 364, 364, 364, 364, 364, 364, 312, 364, 245, 315, + /* 2040 */ 316, 317, 318, 319, 320, 364, 322, 364, 364, 245, + /* 2050 */ 364, 364, 364, 364, 272, 364, 364, 364, 364, 364, + /* 2060 */ 364, 364, 280, 364, 364, 272, 364, 285, 364, 287, + /* 2070 */ 364, 364, 364, 280, 364, 364, 272, 364, 285, 364, + /* 2080 */ 287, 364, 364, 364, 280, 364, 364, 364, 364, 285, + /* 2090 */ 245, 287, 364, 364, 312, 364, 364, 315, 316, 317, + /* 2100 */ 318, 319, 320, 364, 322, 312, 364, 364, 315, 316, + /* 2110 */ 317, 318, 319, 320, 245, 322, 312, 272, 364, 315, + /* 2120 */ 316, 317, 318, 319, 320, 280, 322, 364, 364, 364, + /* 2130 */ 285, 364, 287, 364, 364, 364, 364, 364, 364, 364, + /* 2140 */ 364, 272, 364, 364, 364, 364, 364, 364, 364, 280, + /* 2150 */ 364, 364, 364, 364, 285, 364, 287, 312, 364, 364, + /* 2160 */ 315, 316, 317, 318, 319, 320, 364, 322, 364, 364, + /* 2170 */ 364, 364, 364, 364, 364, 364, 364, 364, 364, 364, + /* 2180 */ 364, 312, 364, 364, 315, 316, 317, 318, 319, 320, + /* 2190 */ 364, 322, }; -#define YY_SHIFT_COUNT (621) +#define YY_SHIFT_COUNT (640) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1774) +#define YY_SHIFT_MAX (1841) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 686, 0, 0, 48, 207, 207, 207, 207, 255, 255, - /* 10 */ 207, 207, 414, 462, 621, 462, 462, 462, 462, 462, - /* 20 */ 462, 462, 462, 462, 462, 462, 462, 462, 462, 462, - /* 30 */ 462, 462, 462, 462, 462, 462, 462, 462, 63, 63, - /* 40 */ 47, 47, 47, 524, 524, 524, 524, 198, 457, 275, - /* 50 */ 11, 11, 104, 104, 76, 196, 275, 275, 11, 11, - /* 60 */ 11, 11, 11, 11, 11, 58, 11, 11, 142, 246, - /* 70 */ 311, 142, 11, 11, 142, 11, 142, 142, 142, 11, - /* 80 */ 119, 660, 679, 810, 810, 350, 395, 432, 432, 432, - /* 90 */ 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, - /* 100 */ 432, 432, 432, 432, 432, 432, 455, 196, 70, 70, - /* 110 */ 21, 512, 683, 683, 683, 782, 512, 340, 311, 142, - /* 120 */ 142, 416, 416, 673, 713, 197, 197, 197, 197, 197, - /* 130 */ 197, 197, 886, 232, 351, 209, 107, 472, 43, 36, - /* 140 */ 134, 295, 544, 576, 757, 781, 551, 554, 551, 676, - /* 150 */ 676, 676, 547, 578, 793, 1002, 990, 991, 881, 1002, - /* 160 */ 1002, 1012, 913, 913, 1002, 1039, 1039, 1043, 58, 311, - /* 170 */ 58, 1053, 1062, 58, 1053, 58, 340, 1073, 58, 58, - /* 180 */ 1002, 58, 1039, 142, 142, 142, 142, 142, 142, 142, - /* 190 */ 142, 142, 142, 142, 1002, 1039, 416, 416, 1043, 119, - /* 200 */ 989, 311, 119, 1002, 1053, 119, 340, 1073, 119, 1138, - /* 210 */ 950, 943, 416, 950, 943, 416, 416, 142, 964, 1049, - /* 220 */ 993, 793, 992, 340, 1189, 1171, 984, 996, 983, 984, - /* 230 */ 996, 984, 996, 1136, 943, 416, 416, 943, 416, 1079, - /* 240 */ 340, 1073, 119, 673, 119, 340, 1181, 416, 713, 1002, - /* 250 */ 119, 1039, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 272, - /* 260 */ 901, 720, 1186, 549, 740, 12, 111, 268, 20, 187, - /* 270 */ 271, 234, 234, 234, 234, 234, 234, 234, 234, 31, - /* 280 */ 16, 514, 358, 671, 476, 302, 302, 302, 302, 831, - /* 290 */ 280, 445, 758, 763, 809, 873, 889, 893, 878, 863, - /* 300 */ 865, 867, 912, 792, 694, 139, 877, 786, 895, 854, - /* 310 */ 903, 907, 909, 937, 938, 231, 667, 939, 941, 942, - /* 320 */ 945, 946, 951, 835, 860, 988, 1288, 1289, 1250, 1292, - /* 330 */ 1222, 1296, 1251, 1121, 1252, 1254, 1256, 1129, 1306, 1272, - /* 340 */ 1273, 1153, 1336, 1162, 1341, 1295, 1343, 1324, 1347, 1301, - /* 350 */ 1349, 1269, 1188, 1191, 1194, 1197, 1356, 1358, 1206, 1208, - /* 360 */ 1362, 1363, 1323, 1368, 1369, 1370, 1371, 1372, 1373, 1375, - /* 370 */ 1376, 1377, 1378, 1380, 1382, 1383, 1385, 1386, 1395, 1396, - /* 380 */ 1397, 1359, 1398, 1400, 1401, 1402, 1403, 1404, 1393, 1407, - /* 390 */ 1408, 1417, 1418, 1419, 1421, 1387, 1388, 1381, 1409, 1390, - /* 400 */ 1412, 1392, 1429, 1399, 1405, 1430, 1431, 1438, 1411, 1290, - /* 410 */ 1441, 1443, 1413, 1444, 1410, 1449, 1451, 1414, 1426, 1415, - /* 420 */ 1454, 1427, 1428, 1420, 1455, 1434, 1440, 1422, 1458, 1439, - /* 430 */ 1442, 1425, 1488, 1489, 1490, 1492, 1416, 1423, 1446, 1472, - /* 440 */ 1495, 1450, 1452, 1453, 1456, 1460, 1461, 1457, 1463, 1465, - /* 450 */ 1505, 1486, 1513, 1493, 1466, 1516, 1496, 1470, 1519, 1498, - /* 460 */ 1522, 1502, 1512, 1525, 1389, 1491, 1535, 1379, 1515, 1424, - /* 470 */ 1432, 1539, 1540, 1541, 1436, 1544, 1464, 1509, 1433, 1510, - /* 480 */ 1511, 1339, 1468, 1514, 1475, 1473, 1477, 1478, 1480, 1523, - /* 490 */ 1521, 1524, 1485, 1526, 1355, 1503, 1504, 1528, 1365, 1548, - /* 500 */ 1546, 1517, 1559, 1435, 1520, 1554, 1556, 1560, 1561, 1562, - /* 510 */ 1564, 1520, 1602, 1437, 1565, 1531, 1534, 1536, 1572, 1542, - /* 520 */ 1543, 1573, 1599, 1448, 1545, 1538, 1549, 1547, 1552, 1494, - /* 530 */ 1553, 1625, 1593, 1527, 1569, 1555, 1591, 1594, 1570, 1571, - /* 540 */ 1574, 1630, 1575, 1576, 1583, 1619, 1620, 1589, 1590, 1626, - /* 550 */ 1596, 1592, 1632, 1600, 1603, 1633, 1601, 1604, 1637, 1606, - /* 560 */ 1586, 1587, 1595, 1597, 1671, 1605, 1613, 1614, 1649, 1616, - /* 570 */ 1658, 1658, 1679, 1645, 1647, 1665, 1650, 1638, 1685, 1680, - /* 580 */ 1681, 1683, 1686, 1687, 1710, 1688, 1689, 1673, 1460, 1691, - /* 590 */ 1461, 1692, 1693, 1695, 1696, 1697, 1698, 1746, 1700, 1703, - /* 600 */ 1712, 1751, 1705, 1708, 1718, 1754, 1711, 1720, 1730, 1757, - /* 610 */ 1722, 1725, 1734, 1772, 1726, 1774, 1753, 1758, 1756, 1760, - /* 620 */ 1759, 1764, + /* 0 */ 742, 0, 0, 48, 208, 208, 208, 208, 256, 256, + /* 10 */ 208, 208, 416, 464, 624, 464, 464, 464, 464, 464, + /* 20 */ 464, 464, 464, 464, 464, 464, 464, 464, 464, 464, + /* 30 */ 464, 464, 464, 464, 464, 464, 464, 464, 464, 464, + /* 40 */ 66, 66, 104, 104, 104, 18, 18, 18, 18, 12, + /* 50 */ 79, 207, 36, 36, 115, 115, 202, 153, 207, 207, + /* 60 */ 36, 36, 36, 36, 36, 36, 36, 36, 73, 36, + /* 70 */ 36, 180, 190, 312, 180, 36, 36, 180, 36, 180, + /* 80 */ 180, 180, 36, 409, 706, 478, 838, 838, 395, 189, + /* 90 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, + /* 100 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 198, + /* 110 */ 153, 4, 4, 281, 801, 479, 479, 479, 327, 801, + /* 120 */ 454, 312, 180, 180, 425, 425, 530, 726, 246, 246, + /* 130 */ 246, 246, 246, 246, 246, 1351, 351, 803, 350, 187, + /* 140 */ 449, 401, 423, 512, 558, 392, 531, 638, 732, 664, + /* 150 */ 697, 664, 165, 165, 165, 719, 705, 861, 1058, 1035, + /* 160 */ 1036, 925, 1058, 1058, 1047, 963, 963, 1058, 1097, 1097, + /* 170 */ 1101, 73, 312, 73, 1105, 1108, 73, 1105, 73, 454, + /* 180 */ 1123, 73, 73, 1058, 73, 1097, 180, 180, 180, 180, + /* 190 */ 180, 180, 180, 180, 180, 180, 180, 1058, 1097, 425, + /* 200 */ 425, 1101, 409, 991, 312, 409, 1058, 1105, 409, 454, + /* 210 */ 1123, 409, 1159, 425, 965, 967, 425, 965, 967, 425, + /* 220 */ 425, 180, 961, 1042, 965, 971, 974, 994, 861, 995, + /* 230 */ 454, 1202, 1183, 996, 997, 998, 996, 997, 996, 997, + /* 240 */ 1144, 967, 425, 425, 967, 425, 1096, 454, 1123, 409, + /* 250 */ 530, 409, 454, 1170, 425, 726, 1058, 409, 1097, 2192, + /* 260 */ 2192, 2192, 2192, 2192, 2192, 2192, 481, 657, 561, 119, + /* 270 */ 601, 891, 63, 13, 303, 203, 582, 374, 443, 552, + /* 280 */ 550, 550, 550, 550, 550, 550, 550, 550, 132, 382, + /* 290 */ 152, 529, 430, 137, 616, 616, 616, 616, 259, 837, + /* 300 */ 800, 818, 823, 824, 879, 913, 914, 906, 896, 908, + /* 310 */ 910, 946, 851, 720, 739, 932, 886, 938, 685, 945, + /* 320 */ 954, 969, 993, 1006, 850, 887, 1019, 1020, 1029, 1030, + /* 330 */ 1031, 1032, 277, 892, 966, 1272, 1286, 1249, 1298, 1230, + /* 340 */ 1303, 1259, 1130, 1261, 1262, 1264, 1135, 1314, 1268, 1269, + /* 350 */ 1142, 1320, 1145, 1321, 1277, 1326, 1305, 1329, 1283, 1331, + /* 360 */ 1251, 1169, 1171, 1174, 1178, 1338, 1339, 1185, 1188, 1344, + /* 370 */ 1345, 1302, 1347, 1207, 1349, 1363, 1364, 1365, 1366, 1215, + /* 380 */ 1322, 1367, 1241, 1380, 1381, 1382, 1383, 1385, 1386, 1388, + /* 390 */ 1389, 1390, 1391, 1395, 1397, 1398, 1399, 1360, 1401, 1407, + /* 400 */ 1408, 1409, 1410, 1411, 1392, 1412, 1415, 1418, 1420, 1428, + /* 410 */ 1430, 1393, 1402, 1394, 1422, 1400, 1424, 1403, 1442, 1405, + /* 420 */ 1413, 1445, 1446, 1449, 1414, 1304, 1452, 1456, 1421, 1457, + /* 430 */ 1404, 1459, 1461, 1423, 1419, 1425, 1465, 1426, 1427, 1431, + /* 440 */ 1469, 1434, 1429, 1441, 1471, 1444, 1447, 1460, 1494, 1499, + /* 450 */ 1502, 1503, 1433, 1416, 1458, 1487, 1510, 1464, 1466, 1467, + /* 460 */ 1468, 1477, 1479, 1474, 1478, 1480, 1512, 1504, 1528, 1508, + /* 470 */ 1484, 1534, 1522, 1500, 1546, 1526, 1549, 1529, 1530, 1552, + /* 480 */ 1406, 1506, 1557, 1432, 1536, 1435, 1436, 1565, 1567, 1568, + /* 490 */ 1440, 1569, 1489, 1538, 1443, 1532, 1535, 1356, 1497, 1495, + /* 500 */ 1498, 1513, 1543, 1517, 1511, 1519, 1520, 1521, 1553, 1558, + /* 510 */ 1560, 1524, 1570, 1437, 1527, 1531, 1562, 1448, 1582, 1564, + /* 520 */ 1544, 1586, 1439, 1547, 1581, 1584, 1585, 1588, 1589, 1590, + /* 530 */ 1547, 1628, 1462, 1598, 1559, 1563, 1561, 1602, 1572, 1574, + /* 540 */ 1606, 1636, 1481, 1578, 1594, 1603, 1605, 1609, 1541, 1618, + /* 550 */ 1664, 1630, 1566, 1619, 1610, 1659, 1661, 1625, 1626, 1631, + /* 560 */ 1685, 1632, 1622, 1629, 1668, 1669, 1638, 1635, 1673, 1640, + /* 570 */ 1642, 1675, 1645, 1646, 1680, 1649, 1656, 1684, 1663, 1637, + /* 580 */ 1641, 1643, 1644, 1718, 1650, 1666, 1670, 1698, 1678, 1720, + /* 590 */ 1720, 1740, 1705, 1707, 1719, 1706, 1688, 1728, 1725, 1726, + /* 600 */ 1727, 1730, 1731, 1749, 1733, 1735, 1711, 1477, 1737, 1479, + /* 610 */ 1738, 1739, 1741, 1742, 1744, 1746, 1795, 1750, 1751, 1762, + /* 620 */ 1800, 1754, 1757, 1767, 1806, 1760, 1764, 1773, 1817, 1774, + /* 630 */ 1775, 1794, 1832, 1792, 1841, 1820, 1822, 1823, 1824, 1826, + /* 640 */ 1828, }; -#define YY_REDUCE_COUNT (258) -#define YY_REDUCE_MIN (-300) -#define YY_REDUCE_MAX (1778) +#define YY_REDUCE_COUNT (265) +#define YY_REDUCE_MIN (-340) +#define YY_REDUCE_MAX (1869) static const short yy_reduce_ofst[] = { - /* 0 */ -186, -240, -177, 241, 648, 762, 788, 814, 866, 880, - /* 10 */ 189, 931, 995, 1009, 1018, 459, 1075, 1097, 1151, 1163, - /* 20 */ 1214, 1265, 1279, 1328, 1345, 1394, 1406, 1447, 1499, 1508, - /* 30 */ 1557, 1598, 1615, 1664, 1676, 1717, 1769, 1778, 1588, 1690, - /* 40 */ -161, -118, 156, -268, -263, 3, 404, -175, 223, 278, - /* 50 */ -158, 285, -238, -230, -300, -279, -295, -253, -156, 158, - /* 60 */ 237, 335, 421, 428, 450, 247, 572, 580, -246, -136, - /* 70 */ -66, 92, 585, 610, 145, 611, 352, 309, 362, 643, - /* 80 */ 374, -197, -275, -275, -275, -34, -124, 81, 124, 127, - /* 90 */ 175, 180, 211, 217, 265, 384, 387, 418, 429, 434, - /* 100 */ 447, 473, 484, 488, 520, 593, 356, 193, -183, 41, - /* 110 */ 135, 327, 373, 422, 423, 4, 441, 614, -141, 550, - /* 120 */ -269, 150, 245, 469, 95, 599, 604, 652, 653, 657, - /* 130 */ 659, 663, 641, 700, 714, 601, 623, 743, 685, 654, - /* 140 */ 726, 726, 747, 750, 718, 689, 665, 665, 665, 655, - /* 150 */ 656, 674, 664, 726, 711, 777, 730, 785, 742, 799, - /* 160 */ 801, 753, 768, 771, 811, 817, 818, 761, 813, 783, - /* 170 */ 816, 784, 787, 833, 791, 839, 829, 804, 842, 856, - /* 180 */ 862, 859, 869, 848, 849, 850, 851, 852, 855, 868, - /* 190 */ 870, 875, 876, 883, 885, 888, 864, 871, 844, 887, - /* 200 */ 857, 872, 910, 905, 874, 914, 890, 879, 915, 861, - /* 210 */ 824, 891, 892, 840, 898, 894, 904, 726, 858, 882, - /* 220 */ 897, 896, 665, 930, 900, 899, 902, 911, 884, 906, - /* 230 */ 916, 908, 918, 924, 928, 944, 947, 934, 953, 933, - /* 240 */ 955, 949, 982, 987, 1003, 979, 994, 998, 1006, 1022, - /* 250 */ 1023, 1029, 975, 972, 1019, 1020, 1021, 1033, 1041, + /* 0 */ -233, -228, -20, -176, 645, 737, 778, 819, 895, 958, + /* 10 */ 188, 975, 1038, 1056, 1107, 477, 1168, 1221, 1244, 1300, + /* 20 */ 1353, 1362, 713, 1376, 1417, 1438, 1496, 1507, 1518, 1583, + /* 30 */ 1599, 1648, 1662, 1703, 1724, 1782, 1793, 1804, 1845, 1869, + /* 40 */ 1141, 1255, -5, 607, 653, -274, -269, 49, 447, -227, + /* 50 */ -47, 161, -231, -229, -244, -215, -340, -105, -133, 123, + /* 60 */ -197, -147, 363, 411, 424, 440, 455, 487, -171, 492, + /* 70 */ 511, 200, -24, 234, -201, 521, 603, 251, 604, -101, + /* 80 */ 345, 357, 606, -119, -152, -281, -281, -281, 78, -247, + /* 90 */ -135, -21, 242, 250, 295, 331, 334, 390, 404, 453, + /* 100 */ 461, 483, 485, 502, 503, 564, 615, 617, 625, 199, + /* 110 */ -83, 420, 421, -27, 176, -263, 172, 406, -155, 279, + /* 120 */ 491, -172, 243, 346, 494, 542, 428, 435, -271, 355, + /* 130 */ 532, 555, 574, 608, 643, 585, 683, 691, 584, 602, + /* 140 */ 701, 651, 629, 709, 709, 730, 748, 717, 694, 674, + /* 150 */ 674, 674, 659, 660, 665, 684, 709, 766, 827, 772, + /* 160 */ 826, 783, 834, 840, 797, 820, 825, 864, 872, 873, + /* 170 */ 816, 867, 839, 868, 828, 829, 876, 830, 877, 862, + /* 180 */ 852, 890, 897, 899, 898, 900, 880, 883, 884, 885, + /* 190 */ 888, 889, 893, 894, 901, 902, 904, 911, 915, 903, + /* 200 */ 905, 858, 916, 863, 882, 917, 920, 878, 924, 907, + /* 210 */ 909, 927, 869, 912, 842, 922, 919, 844, 923, 921, + /* 220 */ 931, 709, 843, 845, 849, 853, 856, 865, 918, 674, + /* 230 */ 941, 926, 929, 866, 874, 870, 871, 928, 930, 939, + /* 240 */ 935, 944, 949, 950, 948, 952, 955, 962, 953, 999, + /* 250 */ 980, 1002, 972, 981, 979, 1003, 1007, 1012, 1021, 964, + /* 260 */ 977, 1005, 1013, 1015, 1014, 1039, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 10 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 20 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 30 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 40 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 50 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 60 */ 1371, 1371, 1371, 1371, 1371, 1440, 1371, 1371, 1371, 1371, - /* 70 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 80 */ 1438, 1586, 1371, 1750, 1371, 1371, 1371, 1371, 1371, 1371, - /* 90 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 100 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 110 */ 1440, 1371, 1761, 1761, 1761, 1438, 1371, 1371, 1371, 1371, - /* 120 */ 1371, 1371, 1371, 1534, 1371, 1371, 1371, 1371, 1371, 1371, - /* 130 */ 1371, 1371, 1619, 1371, 1371, 1827, 1371, 1371, 1625, 1785, - /* 140 */ 1371, 1371, 1371, 1371, 1487, 1777, 1753, 1767, 1754, 1812, - /* 150 */ 1812, 1812, 1770, 1371, 1781, 1371, 1371, 1371, 1611, 1371, - /* 160 */ 1371, 1591, 1588, 1588, 1371, 1371, 1371, 1371, 1440, 1371, - /* 170 */ 1440, 1371, 1371, 1440, 1371, 1440, 1371, 1371, 1440, 1440, - /* 180 */ 1371, 1440, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 190 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1438, - /* 200 */ 1621, 1371, 1438, 1371, 1371, 1438, 1371, 1371, 1438, 1371, - /* 210 */ 1792, 1790, 1371, 1792, 1790, 1371, 1371, 1371, 1804, 1800, - /* 220 */ 1783, 1781, 1767, 1371, 1371, 1371, 1818, 1814, 1830, 1818, - /* 230 */ 1814, 1818, 1814, 1371, 1790, 1371, 1371, 1790, 1371, 1596, - /* 240 */ 1371, 1371, 1438, 1371, 1438, 1371, 1503, 1371, 1371, 1371, - /* 250 */ 1438, 1371, 1613, 1627, 1537, 1537, 1537, 1441, 1376, 1371, - /* 260 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 270 */ 1499, 1694, 1803, 1802, 1726, 1725, 1724, 1722, 1693, 1371, - /* 280 */ 1371, 1371, 1371, 1371, 1371, 1687, 1688, 1686, 1685, 1371, - /* 290 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 300 */ 1371, 1371, 1751, 1371, 1815, 1819, 1371, 1371, 1371, 1670, - /* 310 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 320 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 330 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 340 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 350 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 360 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 370 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 380 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 390 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1405, 1371, 1371, - /* 400 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 410 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 420 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 430 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 440 */ 1371, 1371, 1371, 1371, 1371, 1468, 1467, 1371, 1371, 1371, - /* 450 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 460 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 470 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1774, - /* 480 */ 1784, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 490 */ 1371, 1670, 1371, 1801, 1371, 1760, 1756, 1371, 1371, 1752, - /* 500 */ 1371, 1371, 1813, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 510 */ 1371, 1371, 1746, 1371, 1719, 1371, 1371, 1371, 1371, 1371, - /* 520 */ 1371, 1371, 1371, 1681, 1371, 1371, 1371, 1371, 1371, 1371, - /* 530 */ 1371, 1371, 1371, 1371, 1371, 1371, 1669, 1371, 1710, 1371, - /* 540 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1531, 1371, 1371, - /* 550 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 560 */ 1516, 1514, 1513, 1512, 1371, 1509, 1371, 1371, 1371, 1371, - /* 570 */ 1540, 1539, 1371, 1371, 1371, 1371, 1371, 1371, 1460, 1371, - /* 580 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1451, 1371, - /* 590 */ 1450, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 600 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 610 */ 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, 1371, - /* 620 */ 1371, 1371, + /* 0 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 10 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 20 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 30 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 40 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 50 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 60 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1468, 1399, + /* 70 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 80 */ 1399, 1399, 1399, 1466, 1617, 1399, 1781, 1399, 1399, 1399, + /* 90 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 100 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 110 */ 1399, 1399, 1399, 1468, 1399, 1792, 1792, 1792, 1466, 1399, + /* 120 */ 1399, 1399, 1399, 1399, 1399, 1399, 1562, 1399, 1399, 1399, + /* 130 */ 1399, 1399, 1399, 1399, 1399, 1650, 1399, 1399, 1862, 1399, + /* 140 */ 1399, 1656, 1816, 1399, 1399, 1399, 1399, 1515, 1808, 1784, + /* 150 */ 1798, 1785, 1847, 1847, 1847, 1801, 1399, 1812, 1399, 1399, + /* 160 */ 1399, 1642, 1399, 1399, 1622, 1619, 1619, 1399, 1399, 1399, + /* 170 */ 1399, 1468, 1399, 1468, 1399, 1399, 1468, 1399, 1468, 1399, + /* 180 */ 1399, 1468, 1468, 1399, 1468, 1399, 1399, 1399, 1399, 1399, + /* 190 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 200 */ 1399, 1399, 1466, 1652, 1399, 1466, 1399, 1399, 1466, 1399, + /* 210 */ 1399, 1466, 1399, 1399, 1823, 1821, 1399, 1823, 1821, 1399, + /* 220 */ 1399, 1399, 1835, 1831, 1823, 1839, 1837, 1814, 1812, 1798, + /* 230 */ 1399, 1399, 1399, 1853, 1849, 1865, 1853, 1849, 1853, 1849, + /* 240 */ 1399, 1821, 1399, 1399, 1821, 1399, 1627, 1399, 1399, 1466, + /* 250 */ 1399, 1466, 1399, 1531, 1399, 1399, 1399, 1466, 1399, 1644, + /* 260 */ 1658, 1565, 1565, 1565, 1469, 1404, 1399, 1399, 1399, 1399, + /* 270 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1527, + /* 280 */ 1725, 1834, 1833, 1757, 1756, 1755, 1753, 1724, 1399, 1399, + /* 290 */ 1399, 1399, 1399, 1399, 1718, 1719, 1717, 1716, 1399, 1399, + /* 300 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 310 */ 1399, 1782, 1399, 1850, 1854, 1399, 1399, 1399, 1701, 1399, + /* 320 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 330 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 340 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 350 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 360 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 370 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 380 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 390 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 400 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 410 */ 1399, 1399, 1399, 1433, 1399, 1399, 1399, 1399, 1399, 1399, + /* 420 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 430 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 440 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 450 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 460 */ 1399, 1496, 1495, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 470 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 480 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 490 */ 1399, 1399, 1399, 1399, 1399, 1805, 1815, 1399, 1399, 1399, + /* 500 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 510 */ 1701, 1399, 1832, 1399, 1791, 1787, 1399, 1399, 1783, 1399, + /* 520 */ 1399, 1848, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 530 */ 1399, 1777, 1399, 1750, 1399, 1399, 1399, 1399, 1399, 1399, + /* 540 */ 1399, 1399, 1712, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 550 */ 1399, 1399, 1399, 1399, 1399, 1700, 1399, 1741, 1399, 1399, + /* 560 */ 1399, 1399, 1399, 1399, 1399, 1399, 1559, 1399, 1399, 1399, + /* 570 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1544, + /* 580 */ 1542, 1541, 1540, 1399, 1537, 1399, 1399, 1399, 1399, 1568, + /* 590 */ 1567, 1399, 1399, 1399, 1399, 1399, 1399, 1488, 1399, 1399, + /* 600 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1479, 1399, 1478, + /* 610 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 620 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 630 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, + /* 640 */ 1399, }; /********** End of lemon-generated parsing tables *****************************/ @@ -963,6 +988,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* SNODES => nothing */ 0, /* CLUSTER => nothing */ 0, /* TRANSACTIONS => nothing */ + 0, /* DISTRIBUTED => nothing */ 0, /* LIKE => nothing */ 0, /* INDEX => nothing */ 0, /* FULLTEXT => nothing */ @@ -1047,6 +1073,8 @@ static const YYCODETYPE yyFallback[] = { 0, /* LINEAR => nothing */ 0, /* NEXT => nothing */ 0, /* HAVING => nothing */ + 0, /* RANGE => nothing */ + 0, /* EVERY => nothing */ 0, /* ORDER => nothing */ 0, /* SLIMIT => nothing */ 0, /* SOFFSET => nothing */ @@ -1055,12 +1083,12 @@ static const YYCODETYPE yyFallback[] = { 0, /* ASC => nothing */ 0, /* NULLS => nothing */ 0, /* ID => nothing */ - 232, /* NK_BITNOT => ID */ - 232, /* INSERT => ID */ - 232, /* VALUES => ID */ - 232, /* IMPORT => ID */ - 232, /* NK_SEMI => ID */ - 232, /* FILE => ID */ + 235, /* NK_BITNOT => ID */ + 235, /* INSERT => ID */ + 235, /* VALUES => ID */ + 235, /* IMPORT => ID */ + 235, /* NK_SEMI => ID */ + 235, /* FILE => ID */ }; #endif /* YYFALLBACK */ @@ -1289,224 +1317,229 @@ static const char *const yyTokenName[] = { /* 138 */ "SNODES", /* 139 */ "CLUSTER", /* 140 */ "TRANSACTIONS", - /* 141 */ "LIKE", - /* 142 */ "INDEX", - /* 143 */ "FULLTEXT", - /* 144 */ "FUNCTION", - /* 145 */ "INTERVAL", - /* 146 */ "TOPIC", - /* 147 */ "AS", - /* 148 */ "CONSUMER", - /* 149 */ "GROUP", - /* 150 */ "DESC", - /* 151 */ "DESCRIBE", - /* 152 */ "RESET", - /* 153 */ "QUERY", - /* 154 */ "CACHE", - /* 155 */ "EXPLAIN", - /* 156 */ "ANALYZE", - /* 157 */ "VERBOSE", - /* 158 */ "NK_BOOL", - /* 159 */ "RATIO", - /* 160 */ "NK_FLOAT", - /* 161 */ "COMPACT", - /* 162 */ "VNODES", - /* 163 */ "IN", - /* 164 */ "OUTPUTTYPE", - /* 165 */ "AGGREGATE", - /* 166 */ "BUFSIZE", - /* 167 */ "STREAM", - /* 168 */ "INTO", - /* 169 */ "TRIGGER", - /* 170 */ "AT_ONCE", - /* 171 */ "WINDOW_CLOSE", - /* 172 */ "KILL", - /* 173 */ "CONNECTION", - /* 174 */ "TRANSACTION", - /* 175 */ "BALANCE", - /* 176 */ "VGROUP", - /* 177 */ "MERGE", - /* 178 */ "REDISTRIBUTE", - /* 179 */ "SPLIT", - /* 180 */ "SYNCDB", - /* 181 */ "DELETE", - /* 182 */ "NULL", - /* 183 */ "NK_QUESTION", - /* 184 */ "NK_ARROW", - /* 185 */ "ROWTS", - /* 186 */ "TBNAME", - /* 187 */ "QSTARTTS", - /* 188 */ "QENDTS", - /* 189 */ "WSTARTTS", - /* 190 */ "WENDTS", - /* 191 */ "WDURATION", - /* 192 */ "CAST", - /* 193 */ "NOW", - /* 194 */ "TODAY", - /* 195 */ "TIMEZONE", - /* 196 */ "COUNT", - /* 197 */ "LAST_ROW", - /* 198 */ "BETWEEN", - /* 199 */ "IS", - /* 200 */ "NK_LT", - /* 201 */ "NK_GT", - /* 202 */ "NK_LE", - /* 203 */ "NK_GE", - /* 204 */ "NK_NE", - /* 205 */ "MATCH", - /* 206 */ "NMATCH", - /* 207 */ "CONTAINS", - /* 208 */ "JOIN", - /* 209 */ "INNER", - /* 210 */ "SELECT", - /* 211 */ "DISTINCT", - /* 212 */ "WHERE", - /* 213 */ "PARTITION", - /* 214 */ "BY", - /* 215 */ "SESSION", - /* 216 */ "STATE_WINDOW", - /* 217 */ "SLIDING", - /* 218 */ "FILL", - /* 219 */ "VALUE", - /* 220 */ "NONE", - /* 221 */ "PREV", - /* 222 */ "LINEAR", - /* 223 */ "NEXT", - /* 224 */ "HAVING", - /* 225 */ "ORDER", - /* 226 */ "SLIMIT", - /* 227 */ "SOFFSET", - /* 228 */ "LIMIT", - /* 229 */ "OFFSET", - /* 230 */ "ASC", - /* 231 */ "NULLS", - /* 232 */ "ID", - /* 233 */ "NK_BITNOT", - /* 234 */ "INSERT", - /* 235 */ "VALUES", - /* 236 */ "IMPORT", - /* 237 */ "NK_SEMI", - /* 238 */ "FILE", - /* 239 */ "cmd", - /* 240 */ "account_options", - /* 241 */ "alter_account_options", - /* 242 */ "literal", - /* 243 */ "alter_account_option", - /* 244 */ "user_name", - /* 245 */ "privileges", - /* 246 */ "priv_level", - /* 247 */ "priv_type_list", - /* 248 */ "priv_type", - /* 249 */ "db_name", - /* 250 */ "dnode_endpoint", - /* 251 */ "not_exists_opt", - /* 252 */ "db_options", - /* 253 */ "exists_opt", - /* 254 */ "alter_db_options", - /* 255 */ "integer_list", - /* 256 */ "variable_list", - /* 257 */ "retention_list", - /* 258 */ "alter_db_option", - /* 259 */ "retention", - /* 260 */ "full_table_name", - /* 261 */ "column_def_list", - /* 262 */ "tags_def_opt", - /* 263 */ "table_options", - /* 264 */ "multi_create_clause", - /* 265 */ "tags_def", - /* 266 */ "multi_drop_clause", - /* 267 */ "alter_table_clause", - /* 268 */ "alter_table_options", - /* 269 */ "column_name", - /* 270 */ "type_name", - /* 271 */ "signed_literal", - /* 272 */ "create_subtable_clause", - /* 273 */ "specific_tags_opt", - /* 274 */ "literal_list", - /* 275 */ "drop_table_clause", - /* 276 */ "col_name_list", - /* 277 */ "table_name", - /* 278 */ "column_def", - /* 279 */ "duration_list", - /* 280 */ "rollup_func_list", - /* 281 */ "alter_table_option", - /* 282 */ "duration_literal", - /* 283 */ "rollup_func_name", - /* 284 */ "function_name", - /* 285 */ "col_name", - /* 286 */ "db_name_cond_opt", - /* 287 */ "like_pattern_opt", - /* 288 */ "table_name_cond", - /* 289 */ "from_db_opt", - /* 290 */ "index_name", - /* 291 */ "index_options", - /* 292 */ "func_list", - /* 293 */ "sliding_opt", - /* 294 */ "func", - /* 295 */ "expression_list", - /* 296 */ "topic_name", - /* 297 */ "query_expression", - /* 298 */ "cgroup_name", - /* 299 */ "analyze_opt", - /* 300 */ "explain_options", - /* 301 */ "agg_func_opt", - /* 302 */ "bufsize_opt", - /* 303 */ "stream_name", - /* 304 */ "stream_options", - /* 305 */ "into_opt", - /* 306 */ "dnode_list", - /* 307 */ "where_clause_opt", - /* 308 */ "signed", - /* 309 */ "literal_func", - /* 310 */ "table_alias", - /* 311 */ "column_alias", - /* 312 */ "expression", - /* 313 */ "pseudo_column", - /* 314 */ "column_reference", - /* 315 */ "function_expression", - /* 316 */ "subquery", - /* 317 */ "star_func", - /* 318 */ "star_func_para_list", - /* 319 */ "noarg_func", - /* 320 */ "other_para_list", - /* 321 */ "star_func_para", - /* 322 */ "predicate", - /* 323 */ "compare_op", - /* 324 */ "in_op", - /* 325 */ "in_predicate_value", - /* 326 */ "boolean_value_expression", - /* 327 */ "boolean_primary", - /* 328 */ "common_expression", - /* 329 */ "from_clause", - /* 330 */ "table_reference_list", - /* 331 */ "table_reference", - /* 332 */ "table_primary", - /* 333 */ "joined_table", - /* 334 */ "alias_opt", - /* 335 */ "parenthesized_joined_table", - /* 336 */ "join_type", - /* 337 */ "search_condition", - /* 338 */ "query_specification", - /* 339 */ "set_quantifier_opt", - /* 340 */ "select_list", - /* 341 */ "partition_by_clause_opt", - /* 342 */ "twindow_clause_opt", - /* 343 */ "group_by_clause_opt", - /* 344 */ "having_clause_opt", - /* 345 */ "select_sublist", - /* 346 */ "select_item", + /* 141 */ "DISTRIBUTED", + /* 142 */ "LIKE", + /* 143 */ "INDEX", + /* 144 */ "FULLTEXT", + /* 145 */ "FUNCTION", + /* 146 */ "INTERVAL", + /* 147 */ "TOPIC", + /* 148 */ "AS", + /* 149 */ "CONSUMER", + /* 150 */ "GROUP", + /* 151 */ "DESC", + /* 152 */ "DESCRIBE", + /* 153 */ "RESET", + /* 154 */ "QUERY", + /* 155 */ "CACHE", + /* 156 */ "EXPLAIN", + /* 157 */ "ANALYZE", + /* 158 */ "VERBOSE", + /* 159 */ "NK_BOOL", + /* 160 */ "RATIO", + /* 161 */ "NK_FLOAT", + /* 162 */ "COMPACT", + /* 163 */ "VNODES", + /* 164 */ "IN", + /* 165 */ "OUTPUTTYPE", + /* 166 */ "AGGREGATE", + /* 167 */ "BUFSIZE", + /* 168 */ "STREAM", + /* 169 */ "INTO", + /* 170 */ "TRIGGER", + /* 171 */ "AT_ONCE", + /* 172 */ "WINDOW_CLOSE", + /* 173 */ "KILL", + /* 174 */ "CONNECTION", + /* 175 */ "TRANSACTION", + /* 176 */ "BALANCE", + /* 177 */ "VGROUP", + /* 178 */ "MERGE", + /* 179 */ "REDISTRIBUTE", + /* 180 */ "SPLIT", + /* 181 */ "SYNCDB", + /* 182 */ "DELETE", + /* 183 */ "NULL", + /* 184 */ "NK_QUESTION", + /* 185 */ "NK_ARROW", + /* 186 */ "ROWTS", + /* 187 */ "TBNAME", + /* 188 */ "QSTARTTS", + /* 189 */ "QENDTS", + /* 190 */ "WSTARTTS", + /* 191 */ "WENDTS", + /* 192 */ "WDURATION", + /* 193 */ "CAST", + /* 194 */ "NOW", + /* 195 */ "TODAY", + /* 196 */ "TIMEZONE", + /* 197 */ "COUNT", + /* 198 */ "LAST_ROW", + /* 199 */ "BETWEEN", + /* 200 */ "IS", + /* 201 */ "NK_LT", + /* 202 */ "NK_GT", + /* 203 */ "NK_LE", + /* 204 */ "NK_GE", + /* 205 */ "NK_NE", + /* 206 */ "MATCH", + /* 207 */ "NMATCH", + /* 208 */ "CONTAINS", + /* 209 */ "JOIN", + /* 210 */ "INNER", + /* 211 */ "SELECT", + /* 212 */ "DISTINCT", + /* 213 */ "WHERE", + /* 214 */ "PARTITION", + /* 215 */ "BY", + /* 216 */ "SESSION", + /* 217 */ "STATE_WINDOW", + /* 218 */ "SLIDING", + /* 219 */ "FILL", + /* 220 */ "VALUE", + /* 221 */ "NONE", + /* 222 */ "PREV", + /* 223 */ "LINEAR", + /* 224 */ "NEXT", + /* 225 */ "HAVING", + /* 226 */ "RANGE", + /* 227 */ "EVERY", + /* 228 */ "ORDER", + /* 229 */ "SLIMIT", + /* 230 */ "SOFFSET", + /* 231 */ "LIMIT", + /* 232 */ "OFFSET", + /* 233 */ "ASC", + /* 234 */ "NULLS", + /* 235 */ "ID", + /* 236 */ "NK_BITNOT", + /* 237 */ "INSERT", + /* 238 */ "VALUES", + /* 239 */ "IMPORT", + /* 240 */ "NK_SEMI", + /* 241 */ "FILE", + /* 242 */ "cmd", + /* 243 */ "account_options", + /* 244 */ "alter_account_options", + /* 245 */ "literal", + /* 246 */ "alter_account_option", + /* 247 */ "user_name", + /* 248 */ "privileges", + /* 249 */ "priv_level", + /* 250 */ "priv_type_list", + /* 251 */ "priv_type", + /* 252 */ "db_name", + /* 253 */ "dnode_endpoint", + /* 254 */ "not_exists_opt", + /* 255 */ "db_options", + /* 256 */ "exists_opt", + /* 257 */ "alter_db_options", + /* 258 */ "integer_list", + /* 259 */ "variable_list", + /* 260 */ "retention_list", + /* 261 */ "alter_db_option", + /* 262 */ "retention", + /* 263 */ "full_table_name", + /* 264 */ "column_def_list", + /* 265 */ "tags_def_opt", + /* 266 */ "table_options", + /* 267 */ "multi_create_clause", + /* 268 */ "tags_def", + /* 269 */ "multi_drop_clause", + /* 270 */ "alter_table_clause", + /* 271 */ "alter_table_options", + /* 272 */ "column_name", + /* 273 */ "type_name", + /* 274 */ "signed_literal", + /* 275 */ "create_subtable_clause", + /* 276 */ "specific_tags_opt", + /* 277 */ "literal_list", + /* 278 */ "drop_table_clause", + /* 279 */ "col_name_list", + /* 280 */ "table_name", + /* 281 */ "column_def", + /* 282 */ "duration_list", + /* 283 */ "rollup_func_list", + /* 284 */ "alter_table_option", + /* 285 */ "duration_literal", + /* 286 */ "rollup_func_name", + /* 287 */ "function_name", + /* 288 */ "col_name", + /* 289 */ "db_name_cond_opt", + /* 290 */ "like_pattern_opt", + /* 291 */ "table_name_cond", + /* 292 */ "from_db_opt", + /* 293 */ "index_name", + /* 294 */ "index_options", + /* 295 */ "func_list", + /* 296 */ "sliding_opt", + /* 297 */ "func", + /* 298 */ "expression_list", + /* 299 */ "topic_name", + /* 300 */ "query_expression", + /* 301 */ "cgroup_name", + /* 302 */ "analyze_opt", + /* 303 */ "explain_options", + /* 304 */ "agg_func_opt", + /* 305 */ "bufsize_opt", + /* 306 */ "stream_name", + /* 307 */ "stream_options", + /* 308 */ "into_opt", + /* 309 */ "dnode_list", + /* 310 */ "where_clause_opt", + /* 311 */ "signed", + /* 312 */ "literal_func", + /* 313 */ "table_alias", + /* 314 */ "column_alias", + /* 315 */ "expression", + /* 316 */ "pseudo_column", + /* 317 */ "column_reference", + /* 318 */ "function_expression", + /* 319 */ "subquery", + /* 320 */ "star_func", + /* 321 */ "star_func_para_list", + /* 322 */ "noarg_func", + /* 323 */ "other_para_list", + /* 324 */ "star_func_para", + /* 325 */ "predicate", + /* 326 */ "compare_op", + /* 327 */ "in_op", + /* 328 */ "in_predicate_value", + /* 329 */ "boolean_value_expression", + /* 330 */ "boolean_primary", + /* 331 */ "common_expression", + /* 332 */ "from_clause", + /* 333 */ "table_reference_list", + /* 334 */ "table_reference", + /* 335 */ "table_primary", + /* 336 */ "joined_table", + /* 337 */ "alias_opt", + /* 338 */ "parenthesized_joined_table", + /* 339 */ "join_type", + /* 340 */ "search_condition", + /* 341 */ "query_specification", + /* 342 */ "set_quantifier_opt", + /* 343 */ "select_list", + /* 344 */ "partition_by_clause_opt", + /* 345 */ "range_opt", + /* 346 */ "every_opt", /* 347 */ "fill_opt", - /* 348 */ "fill_mode", - /* 349 */ "group_by_list", - /* 350 */ "query_expression_body", - /* 351 */ "order_by_clause_opt", - /* 352 */ "slimit_clause_opt", - /* 353 */ "limit_clause_opt", - /* 354 */ "query_primary", - /* 355 */ "sort_specification_list", - /* 356 */ "sort_specification", - /* 357 */ "ordering_specification_opt", - /* 358 */ "null_ordering_opt", + /* 348 */ "twindow_clause_opt", + /* 349 */ "group_by_clause_opt", + /* 350 */ "having_clause_opt", + /* 351 */ "select_sublist", + /* 352 */ "select_item", + /* 353 */ "fill_mode", + /* 354 */ "group_by_list", + /* 355 */ "query_expression_body", + /* 356 */ "order_by_clause_opt", + /* 357 */ "slimit_clause_opt", + /* 358 */ "limit_clause_opt", + /* 359 */ "query_primary", + /* 360 */ "sort_specification_list", + /* 361 */ "sort_specification", + /* 362 */ "ordering_specification_opt", + /* 363 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1722,257 +1755,264 @@ static const char *const yyRuleName[] = { /* 205 */ "cmd ::= SHOW SCORES", /* 206 */ "cmd ::= SHOW TOPICS", /* 207 */ "cmd ::= SHOW VARIABLES", - /* 208 */ "cmd ::= SHOW BNODES", - /* 209 */ "cmd ::= SHOW SNODES", - /* 210 */ "cmd ::= SHOW CLUSTER", - /* 211 */ "cmd ::= SHOW TRANSACTIONS", - /* 212 */ "db_name_cond_opt ::=", - /* 213 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 214 */ "like_pattern_opt ::=", - /* 215 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 216 */ "table_name_cond ::= table_name", - /* 217 */ "from_db_opt ::=", - /* 218 */ "from_db_opt ::= FROM db_name", - /* 219 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", - /* 220 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", - /* 221 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", - /* 222 */ "index_options ::=", - /* 223 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", - /* 224 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", - /* 225 */ "func_list ::= func", - /* 226 */ "func_list ::= func_list NK_COMMA func", - /* 227 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 228 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", - /* 229 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", - /* 230 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", - /* 231 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 232 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", - /* 233 */ "cmd ::= DESC full_table_name", - /* 234 */ "cmd ::= DESCRIBE full_table_name", - /* 235 */ "cmd ::= RESET QUERY CACHE", - /* 236 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", - /* 237 */ "analyze_opt ::=", - /* 238 */ "analyze_opt ::= ANALYZE", - /* 239 */ "explain_options ::=", - /* 240 */ "explain_options ::= explain_options VERBOSE NK_BOOL", - /* 241 */ "explain_options ::= explain_options RATIO NK_FLOAT", - /* 242 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", - /* 243 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", - /* 244 */ "cmd ::= DROP FUNCTION exists_opt function_name", - /* 245 */ "agg_func_opt ::=", - /* 246 */ "agg_func_opt ::= AGGREGATE", - /* 247 */ "bufsize_opt ::=", - /* 248 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", - /* 249 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", - /* 250 */ "cmd ::= DROP STREAM exists_opt stream_name", - /* 251 */ "into_opt ::=", - /* 252 */ "into_opt ::= INTO full_table_name", - /* 253 */ "stream_options ::=", - /* 254 */ "stream_options ::= stream_options TRIGGER AT_ONCE", - /* 255 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", - /* 256 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", - /* 257 */ "stream_options ::= stream_options WATERMARK duration_literal", - /* 258 */ "cmd ::= KILL CONNECTION NK_INTEGER", - /* 259 */ "cmd ::= KILL QUERY NK_STRING", - /* 260 */ "cmd ::= KILL TRANSACTION NK_INTEGER", - /* 261 */ "cmd ::= BALANCE VGROUP", - /* 262 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", - /* 263 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", - /* 264 */ "cmd ::= SPLIT VGROUP NK_INTEGER", - /* 265 */ "dnode_list ::= DNODE NK_INTEGER", - /* 266 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", - /* 267 */ "cmd ::= SYNCDB db_name REPLICA", - /* 268 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", - /* 269 */ "cmd ::= query_expression", - /* 270 */ "literal ::= NK_INTEGER", - /* 271 */ "literal ::= NK_FLOAT", - /* 272 */ "literal ::= NK_STRING", - /* 273 */ "literal ::= NK_BOOL", - /* 274 */ "literal ::= TIMESTAMP NK_STRING", - /* 275 */ "literal ::= duration_literal", - /* 276 */ "literal ::= NULL", - /* 277 */ "literal ::= NK_QUESTION", - /* 278 */ "duration_literal ::= NK_VARIABLE", - /* 279 */ "signed ::= NK_INTEGER", - /* 280 */ "signed ::= NK_PLUS NK_INTEGER", - /* 281 */ "signed ::= NK_MINUS NK_INTEGER", - /* 282 */ "signed ::= NK_FLOAT", - /* 283 */ "signed ::= NK_PLUS NK_FLOAT", - /* 284 */ "signed ::= NK_MINUS NK_FLOAT", - /* 285 */ "signed_literal ::= signed", - /* 286 */ "signed_literal ::= NK_STRING", - /* 287 */ "signed_literal ::= NK_BOOL", - /* 288 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 289 */ "signed_literal ::= duration_literal", - /* 290 */ "signed_literal ::= NULL", - /* 291 */ "signed_literal ::= literal_func", - /* 292 */ "literal_list ::= signed_literal", - /* 293 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 294 */ "db_name ::= NK_ID", - /* 295 */ "table_name ::= NK_ID", - /* 296 */ "column_name ::= NK_ID", - /* 297 */ "function_name ::= NK_ID", - /* 298 */ "table_alias ::= NK_ID", - /* 299 */ "column_alias ::= NK_ID", - /* 300 */ "user_name ::= NK_ID", - /* 301 */ "index_name ::= NK_ID", - /* 302 */ "topic_name ::= NK_ID", - /* 303 */ "stream_name ::= NK_ID", - /* 304 */ "cgroup_name ::= NK_ID", - /* 305 */ "expression ::= literal", - /* 306 */ "expression ::= pseudo_column", - /* 307 */ "expression ::= column_reference", - /* 308 */ "expression ::= function_expression", - /* 309 */ "expression ::= subquery", - /* 310 */ "expression ::= NK_LP expression NK_RP", - /* 311 */ "expression ::= NK_PLUS expression", - /* 312 */ "expression ::= NK_MINUS expression", - /* 313 */ "expression ::= expression NK_PLUS expression", - /* 314 */ "expression ::= expression NK_MINUS expression", - /* 315 */ "expression ::= expression NK_STAR expression", - /* 316 */ "expression ::= expression NK_SLASH expression", - /* 317 */ "expression ::= expression NK_REM expression", - /* 318 */ "expression ::= column_reference NK_ARROW NK_STRING", - /* 319 */ "expression_list ::= expression", - /* 320 */ "expression_list ::= expression_list NK_COMMA expression", - /* 321 */ "column_reference ::= column_name", - /* 322 */ "column_reference ::= table_name NK_DOT column_name", - /* 323 */ "pseudo_column ::= ROWTS", - /* 324 */ "pseudo_column ::= TBNAME", - /* 325 */ "pseudo_column ::= table_name NK_DOT TBNAME", - /* 326 */ "pseudo_column ::= QSTARTTS", - /* 327 */ "pseudo_column ::= QENDTS", - /* 328 */ "pseudo_column ::= WSTARTTS", - /* 329 */ "pseudo_column ::= WENDTS", - /* 330 */ "pseudo_column ::= WDURATION", - /* 331 */ "function_expression ::= function_name NK_LP expression_list NK_RP", - /* 332 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", - /* 333 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", - /* 334 */ "function_expression ::= literal_func", - /* 335 */ "literal_func ::= noarg_func NK_LP NK_RP", - /* 336 */ "literal_func ::= NOW", - /* 337 */ "noarg_func ::= NOW", - /* 338 */ "noarg_func ::= TODAY", - /* 339 */ "noarg_func ::= TIMEZONE", - /* 340 */ "star_func ::= COUNT", - /* 341 */ "star_func ::= FIRST", - /* 342 */ "star_func ::= LAST", - /* 343 */ "star_func ::= LAST_ROW", - /* 344 */ "star_func_para_list ::= NK_STAR", - /* 345 */ "star_func_para_list ::= other_para_list", - /* 346 */ "other_para_list ::= star_func_para", - /* 347 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", - /* 348 */ "star_func_para ::= expression", - /* 349 */ "star_func_para ::= table_name NK_DOT NK_STAR", - /* 350 */ "predicate ::= expression compare_op expression", - /* 351 */ "predicate ::= expression BETWEEN expression AND expression", - /* 352 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 353 */ "predicate ::= expression IS NULL", - /* 354 */ "predicate ::= expression IS NOT NULL", - /* 355 */ "predicate ::= expression in_op in_predicate_value", - /* 356 */ "compare_op ::= NK_LT", - /* 357 */ "compare_op ::= NK_GT", - /* 358 */ "compare_op ::= NK_LE", - /* 359 */ "compare_op ::= NK_GE", - /* 360 */ "compare_op ::= NK_NE", - /* 361 */ "compare_op ::= NK_EQ", - /* 362 */ "compare_op ::= LIKE", - /* 363 */ "compare_op ::= NOT LIKE", - /* 364 */ "compare_op ::= MATCH", - /* 365 */ "compare_op ::= NMATCH", - /* 366 */ "compare_op ::= CONTAINS", - /* 367 */ "in_op ::= IN", - /* 368 */ "in_op ::= NOT IN", - /* 369 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 370 */ "boolean_value_expression ::= boolean_primary", - /* 371 */ "boolean_value_expression ::= NOT boolean_primary", - /* 372 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 373 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 374 */ "boolean_primary ::= predicate", - /* 375 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 376 */ "common_expression ::= expression", - /* 377 */ "common_expression ::= boolean_value_expression", - /* 378 */ "from_clause ::= FROM table_reference_list", - /* 379 */ "table_reference_list ::= table_reference", - /* 380 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 381 */ "table_reference ::= table_primary", - /* 382 */ "table_reference ::= joined_table", - /* 383 */ "table_primary ::= table_name alias_opt", - /* 384 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 385 */ "table_primary ::= subquery alias_opt", - /* 386 */ "table_primary ::= parenthesized_joined_table", - /* 387 */ "alias_opt ::=", - /* 388 */ "alias_opt ::= table_alias", - /* 389 */ "alias_opt ::= AS table_alias", - /* 390 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 391 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 392 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 393 */ "join_type ::=", - /* 394 */ "join_type ::= INNER", - /* 395 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 396 */ "set_quantifier_opt ::=", - /* 397 */ "set_quantifier_opt ::= DISTINCT", - /* 398 */ "set_quantifier_opt ::= ALL", - /* 399 */ "select_list ::= NK_STAR", - /* 400 */ "select_list ::= select_sublist", - /* 401 */ "select_sublist ::= select_item", - /* 402 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 403 */ "select_item ::= common_expression", - /* 404 */ "select_item ::= common_expression column_alias", - /* 405 */ "select_item ::= common_expression AS column_alias", - /* 406 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 407 */ "where_clause_opt ::=", - /* 408 */ "where_clause_opt ::= WHERE search_condition", - /* 409 */ "partition_by_clause_opt ::=", - /* 410 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 411 */ "twindow_clause_opt ::=", - /* 412 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 413 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 414 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 415 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 416 */ "sliding_opt ::=", - /* 417 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 418 */ "fill_opt ::=", - /* 419 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 420 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 421 */ "fill_mode ::= NONE", - /* 422 */ "fill_mode ::= PREV", - /* 423 */ "fill_mode ::= NULL", - /* 424 */ "fill_mode ::= LINEAR", - /* 425 */ "fill_mode ::= NEXT", - /* 426 */ "group_by_clause_opt ::=", - /* 427 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 428 */ "group_by_list ::= expression", - /* 429 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 430 */ "having_clause_opt ::=", - /* 431 */ "having_clause_opt ::= HAVING search_condition", - /* 432 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 433 */ "query_expression_body ::= query_primary", - /* 434 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 435 */ "query_expression_body ::= query_expression_body UNION query_expression_body", - /* 436 */ "query_primary ::= query_specification", - /* 437 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP", - /* 438 */ "order_by_clause_opt ::=", - /* 439 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 440 */ "slimit_clause_opt ::=", - /* 441 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 442 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 443 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 444 */ "limit_clause_opt ::=", - /* 445 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 446 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 447 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 448 */ "subquery ::= NK_LP query_expression NK_RP", - /* 449 */ "search_condition ::= common_expression", - /* 450 */ "sort_specification_list ::= sort_specification", - /* 451 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 452 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 453 */ "ordering_specification_opt ::=", - /* 454 */ "ordering_specification_opt ::= ASC", - /* 455 */ "ordering_specification_opt ::= DESC", - /* 456 */ "null_ordering_opt ::=", - /* 457 */ "null_ordering_opt ::= NULLS FIRST", - /* 458 */ "null_ordering_opt ::= NULLS LAST", + /* 208 */ "cmd ::= SHOW LOCAL VARIABLES", + /* 209 */ "cmd ::= SHOW DNODE NK_INTEGER VARIABLES", + /* 210 */ "cmd ::= SHOW BNODES", + /* 211 */ "cmd ::= SHOW SNODES", + /* 212 */ "cmd ::= SHOW CLUSTER", + /* 213 */ "cmd ::= SHOW TRANSACTIONS", + /* 214 */ "cmd ::= SHOW TABLE DISTRIBUTED full_table_name", + /* 215 */ "db_name_cond_opt ::=", + /* 216 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 217 */ "like_pattern_opt ::=", + /* 218 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 219 */ "table_name_cond ::= table_name", + /* 220 */ "from_db_opt ::=", + /* 221 */ "from_db_opt ::= FROM db_name", + /* 222 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", + /* 223 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", + /* 224 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", + /* 225 */ "index_options ::=", + /* 226 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", + /* 227 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", + /* 228 */ "func_list ::= func", + /* 229 */ "func_list ::= func_list NK_COMMA func", + /* 230 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 231 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", + /* 232 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", + /* 233 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", + /* 234 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 235 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", + /* 236 */ "cmd ::= DESC full_table_name", + /* 237 */ "cmd ::= DESCRIBE full_table_name", + /* 238 */ "cmd ::= RESET QUERY CACHE", + /* 239 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", + /* 240 */ "analyze_opt ::=", + /* 241 */ "analyze_opt ::= ANALYZE", + /* 242 */ "explain_options ::=", + /* 243 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 244 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 245 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", + /* 246 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", + /* 247 */ "cmd ::= DROP FUNCTION exists_opt function_name", + /* 248 */ "agg_func_opt ::=", + /* 249 */ "agg_func_opt ::= AGGREGATE", + /* 250 */ "bufsize_opt ::=", + /* 251 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", + /* 252 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", + /* 253 */ "cmd ::= DROP STREAM exists_opt stream_name", + /* 254 */ "into_opt ::=", + /* 255 */ "into_opt ::= INTO full_table_name", + /* 256 */ "stream_options ::=", + /* 257 */ "stream_options ::= stream_options TRIGGER AT_ONCE", + /* 258 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", + /* 259 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", + /* 260 */ "stream_options ::= stream_options WATERMARK duration_literal", + /* 261 */ "cmd ::= KILL CONNECTION NK_INTEGER", + /* 262 */ "cmd ::= KILL QUERY NK_STRING", + /* 263 */ "cmd ::= KILL TRANSACTION NK_INTEGER", + /* 264 */ "cmd ::= BALANCE VGROUP", + /* 265 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 266 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", + /* 267 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 268 */ "dnode_list ::= DNODE NK_INTEGER", + /* 269 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", + /* 270 */ "cmd ::= SYNCDB db_name REPLICA", + /* 271 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", + /* 272 */ "cmd ::= query_expression", + /* 273 */ "literal ::= NK_INTEGER", + /* 274 */ "literal ::= NK_FLOAT", + /* 275 */ "literal ::= NK_STRING", + /* 276 */ "literal ::= NK_BOOL", + /* 277 */ "literal ::= TIMESTAMP NK_STRING", + /* 278 */ "literal ::= duration_literal", + /* 279 */ "literal ::= NULL", + /* 280 */ "literal ::= NK_QUESTION", + /* 281 */ "duration_literal ::= NK_VARIABLE", + /* 282 */ "signed ::= NK_INTEGER", + /* 283 */ "signed ::= NK_PLUS NK_INTEGER", + /* 284 */ "signed ::= NK_MINUS NK_INTEGER", + /* 285 */ "signed ::= NK_FLOAT", + /* 286 */ "signed ::= NK_PLUS NK_FLOAT", + /* 287 */ "signed ::= NK_MINUS NK_FLOAT", + /* 288 */ "signed_literal ::= signed", + /* 289 */ "signed_literal ::= NK_STRING", + /* 290 */ "signed_literal ::= NK_BOOL", + /* 291 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 292 */ "signed_literal ::= duration_literal", + /* 293 */ "signed_literal ::= NULL", + /* 294 */ "signed_literal ::= literal_func", + /* 295 */ "literal_list ::= signed_literal", + /* 296 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 297 */ "db_name ::= NK_ID", + /* 298 */ "table_name ::= NK_ID", + /* 299 */ "column_name ::= NK_ID", + /* 300 */ "function_name ::= NK_ID", + /* 301 */ "table_alias ::= NK_ID", + /* 302 */ "column_alias ::= NK_ID", + /* 303 */ "user_name ::= NK_ID", + /* 304 */ "index_name ::= NK_ID", + /* 305 */ "topic_name ::= NK_ID", + /* 306 */ "stream_name ::= NK_ID", + /* 307 */ "cgroup_name ::= NK_ID", + /* 308 */ "expression ::= literal", + /* 309 */ "expression ::= pseudo_column", + /* 310 */ "expression ::= column_reference", + /* 311 */ "expression ::= function_expression", + /* 312 */ "expression ::= subquery", + /* 313 */ "expression ::= NK_LP expression NK_RP", + /* 314 */ "expression ::= NK_PLUS expression", + /* 315 */ "expression ::= NK_MINUS expression", + /* 316 */ "expression ::= expression NK_PLUS expression", + /* 317 */ "expression ::= expression NK_MINUS expression", + /* 318 */ "expression ::= expression NK_STAR expression", + /* 319 */ "expression ::= expression NK_SLASH expression", + /* 320 */ "expression ::= expression NK_REM expression", + /* 321 */ "expression ::= column_reference NK_ARROW NK_STRING", + /* 322 */ "expression_list ::= expression", + /* 323 */ "expression_list ::= expression_list NK_COMMA expression", + /* 324 */ "column_reference ::= column_name", + /* 325 */ "column_reference ::= table_name NK_DOT column_name", + /* 326 */ "pseudo_column ::= ROWTS", + /* 327 */ "pseudo_column ::= TBNAME", + /* 328 */ "pseudo_column ::= table_name NK_DOT TBNAME", + /* 329 */ "pseudo_column ::= QSTARTTS", + /* 330 */ "pseudo_column ::= QENDTS", + /* 331 */ "pseudo_column ::= WSTARTTS", + /* 332 */ "pseudo_column ::= WENDTS", + /* 333 */ "pseudo_column ::= WDURATION", + /* 334 */ "function_expression ::= function_name NK_LP expression_list NK_RP", + /* 335 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", + /* 336 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", + /* 337 */ "function_expression ::= literal_func", + /* 338 */ "literal_func ::= noarg_func NK_LP NK_RP", + /* 339 */ "literal_func ::= NOW", + /* 340 */ "noarg_func ::= NOW", + /* 341 */ "noarg_func ::= TODAY", + /* 342 */ "noarg_func ::= TIMEZONE", + /* 343 */ "star_func ::= COUNT", + /* 344 */ "star_func ::= FIRST", + /* 345 */ "star_func ::= LAST", + /* 346 */ "star_func ::= LAST_ROW", + /* 347 */ "star_func_para_list ::= NK_STAR", + /* 348 */ "star_func_para_list ::= other_para_list", + /* 349 */ "other_para_list ::= star_func_para", + /* 350 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", + /* 351 */ "star_func_para ::= expression", + /* 352 */ "star_func_para ::= table_name NK_DOT NK_STAR", + /* 353 */ "predicate ::= expression compare_op expression", + /* 354 */ "predicate ::= expression BETWEEN expression AND expression", + /* 355 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 356 */ "predicate ::= expression IS NULL", + /* 357 */ "predicate ::= expression IS NOT NULL", + /* 358 */ "predicate ::= expression in_op in_predicate_value", + /* 359 */ "compare_op ::= NK_LT", + /* 360 */ "compare_op ::= NK_GT", + /* 361 */ "compare_op ::= NK_LE", + /* 362 */ "compare_op ::= NK_GE", + /* 363 */ "compare_op ::= NK_NE", + /* 364 */ "compare_op ::= NK_EQ", + /* 365 */ "compare_op ::= LIKE", + /* 366 */ "compare_op ::= NOT LIKE", + /* 367 */ "compare_op ::= MATCH", + /* 368 */ "compare_op ::= NMATCH", + /* 369 */ "compare_op ::= CONTAINS", + /* 370 */ "in_op ::= IN", + /* 371 */ "in_op ::= NOT IN", + /* 372 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 373 */ "boolean_value_expression ::= boolean_primary", + /* 374 */ "boolean_value_expression ::= NOT boolean_primary", + /* 375 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 376 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 377 */ "boolean_primary ::= predicate", + /* 378 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 379 */ "common_expression ::= expression", + /* 380 */ "common_expression ::= boolean_value_expression", + /* 381 */ "from_clause ::= FROM table_reference_list", + /* 382 */ "table_reference_list ::= table_reference", + /* 383 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 384 */ "table_reference ::= table_primary", + /* 385 */ "table_reference ::= joined_table", + /* 386 */ "table_primary ::= table_name alias_opt", + /* 387 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 388 */ "table_primary ::= subquery alias_opt", + /* 389 */ "table_primary ::= parenthesized_joined_table", + /* 390 */ "alias_opt ::=", + /* 391 */ "alias_opt ::= table_alias", + /* 392 */ "alias_opt ::= AS table_alias", + /* 393 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 394 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 395 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 396 */ "join_type ::=", + /* 397 */ "join_type ::= INNER", + /* 398 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 399 */ "set_quantifier_opt ::=", + /* 400 */ "set_quantifier_opt ::= DISTINCT", + /* 401 */ "set_quantifier_opt ::= ALL", + /* 402 */ "select_list ::= NK_STAR", + /* 403 */ "select_list ::= select_sublist", + /* 404 */ "select_sublist ::= select_item", + /* 405 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 406 */ "select_item ::= common_expression", + /* 407 */ "select_item ::= common_expression column_alias", + /* 408 */ "select_item ::= common_expression AS column_alias", + /* 409 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 410 */ "where_clause_opt ::=", + /* 411 */ "where_clause_opt ::= WHERE search_condition", + /* 412 */ "partition_by_clause_opt ::=", + /* 413 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 414 */ "twindow_clause_opt ::=", + /* 415 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 416 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", + /* 417 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 418 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 419 */ "sliding_opt ::=", + /* 420 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 421 */ "fill_opt ::=", + /* 422 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 423 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 424 */ "fill_mode ::= NONE", + /* 425 */ "fill_mode ::= PREV", + /* 426 */ "fill_mode ::= NULL", + /* 427 */ "fill_mode ::= LINEAR", + /* 428 */ "fill_mode ::= NEXT", + /* 429 */ "group_by_clause_opt ::=", + /* 430 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 431 */ "group_by_list ::= expression", + /* 432 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 433 */ "having_clause_opt ::=", + /* 434 */ "having_clause_opt ::= HAVING search_condition", + /* 435 */ "range_opt ::=", + /* 436 */ "range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP", + /* 437 */ "every_opt ::=", + /* 438 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", + /* 439 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 440 */ "query_expression_body ::= query_primary", + /* 441 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 442 */ "query_expression_body ::= query_expression_body UNION query_expression_body", + /* 443 */ "query_primary ::= query_specification", + /* 444 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP", + /* 445 */ "order_by_clause_opt ::=", + /* 446 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 447 */ "slimit_clause_opt ::=", + /* 448 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 449 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 450 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 451 */ "limit_clause_opt ::=", + /* 452 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 453 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 454 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 455 */ "subquery ::= NK_LP query_expression NK_RP", + /* 456 */ "search_condition ::= common_expression", + /* 457 */ "sort_specification_list ::= sort_specification", + /* 458 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 459 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 460 */ "ordering_specification_opt ::=", + /* 461 */ "ordering_specification_opt ::= ASC", + /* 462 */ "ordering_specification_opt ::= DESC", + /* 463 */ "null_ordering_opt ::=", + /* 464 */ "null_ordering_opt ::= NULLS FIRST", + /* 465 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -2099,174 +2139,176 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 239: /* cmd */ - case 242: /* literal */ - case 252: /* db_options */ - case 254: /* alter_db_options */ - case 259: /* retention */ - case 260: /* full_table_name */ - case 263: /* table_options */ - case 267: /* alter_table_clause */ - case 268: /* alter_table_options */ - case 271: /* signed_literal */ - case 272: /* create_subtable_clause */ - case 275: /* drop_table_clause */ - case 278: /* column_def */ - case 282: /* duration_literal */ - case 283: /* rollup_func_name */ - case 285: /* col_name */ - case 286: /* db_name_cond_opt */ - case 287: /* like_pattern_opt */ - case 288: /* table_name_cond */ - case 289: /* from_db_opt */ - case 291: /* index_options */ - case 293: /* sliding_opt */ - case 294: /* func */ - case 297: /* query_expression */ - case 300: /* explain_options */ - case 304: /* stream_options */ - case 305: /* into_opt */ - case 307: /* where_clause_opt */ - case 308: /* signed */ - case 309: /* literal_func */ - case 312: /* expression */ - case 313: /* pseudo_column */ - case 314: /* column_reference */ - case 315: /* function_expression */ - case 316: /* subquery */ - case 321: /* star_func_para */ - case 322: /* predicate */ - case 325: /* in_predicate_value */ - case 326: /* boolean_value_expression */ - case 327: /* boolean_primary */ - case 328: /* common_expression */ - case 329: /* from_clause */ - case 330: /* table_reference_list */ - case 331: /* table_reference */ - case 332: /* table_primary */ - case 333: /* joined_table */ - case 335: /* parenthesized_joined_table */ - case 337: /* search_condition */ - case 338: /* query_specification */ - case 342: /* twindow_clause_opt */ - case 344: /* having_clause_opt */ - case 346: /* select_item */ + case 242: /* cmd */ + case 245: /* literal */ + case 255: /* db_options */ + case 257: /* alter_db_options */ + case 262: /* retention */ + case 263: /* full_table_name */ + case 266: /* table_options */ + case 270: /* alter_table_clause */ + case 271: /* alter_table_options */ + case 274: /* signed_literal */ + case 275: /* create_subtable_clause */ + case 278: /* drop_table_clause */ + case 281: /* column_def */ + case 285: /* duration_literal */ + case 286: /* rollup_func_name */ + case 288: /* col_name */ + case 289: /* db_name_cond_opt */ + case 290: /* like_pattern_opt */ + case 291: /* table_name_cond */ + case 292: /* from_db_opt */ + case 294: /* index_options */ + case 296: /* sliding_opt */ + case 297: /* func */ + case 300: /* query_expression */ + case 303: /* explain_options */ + case 307: /* stream_options */ + case 308: /* into_opt */ + case 310: /* where_clause_opt */ + case 311: /* signed */ + case 312: /* literal_func */ + case 315: /* expression */ + case 316: /* pseudo_column */ + case 317: /* column_reference */ + case 318: /* function_expression */ + case 319: /* subquery */ + case 324: /* star_func_para */ + case 325: /* predicate */ + case 328: /* in_predicate_value */ + case 329: /* boolean_value_expression */ + case 330: /* boolean_primary */ + case 331: /* common_expression */ + case 332: /* from_clause */ + case 333: /* table_reference_list */ + case 334: /* table_reference */ + case 335: /* table_primary */ + case 336: /* joined_table */ + case 338: /* parenthesized_joined_table */ + case 340: /* search_condition */ + case 341: /* query_specification */ + case 345: /* range_opt */ + case 346: /* every_opt */ case 347: /* fill_opt */ - case 350: /* query_expression_body */ - case 352: /* slimit_clause_opt */ - case 353: /* limit_clause_opt */ - case 354: /* query_primary */ - case 356: /* sort_specification */ + case 348: /* twindow_clause_opt */ + case 350: /* having_clause_opt */ + case 352: /* select_item */ + case 355: /* query_expression_body */ + case 357: /* slimit_clause_opt */ + case 358: /* limit_clause_opt */ + case 359: /* query_primary */ + case 361: /* sort_specification */ { - nodesDestroyNode((yypminor->yy674)); + nodesDestroyNode((yypminor->yy392)); } break; - case 240: /* account_options */ - case 241: /* alter_account_options */ - case 243: /* alter_account_option */ - case 302: /* bufsize_opt */ + case 243: /* account_options */ + case 244: /* alter_account_options */ + case 246: /* alter_account_option */ + case 305: /* bufsize_opt */ { } break; - case 244: /* user_name */ - case 246: /* priv_level */ - case 249: /* db_name */ - case 250: /* dnode_endpoint */ - case 269: /* column_name */ - case 277: /* table_name */ - case 284: /* function_name */ - case 290: /* index_name */ - case 296: /* topic_name */ - case 298: /* cgroup_name */ - case 303: /* stream_name */ - case 310: /* table_alias */ - case 311: /* column_alias */ - case 317: /* star_func */ - case 319: /* noarg_func */ - case 334: /* alias_opt */ + case 247: /* user_name */ + case 249: /* priv_level */ + case 252: /* db_name */ + case 253: /* dnode_endpoint */ + case 272: /* column_name */ + case 280: /* table_name */ + case 287: /* function_name */ + case 293: /* index_name */ + case 299: /* topic_name */ + case 301: /* cgroup_name */ + case 306: /* stream_name */ + case 313: /* table_alias */ + case 314: /* column_alias */ + case 320: /* star_func */ + case 322: /* noarg_func */ + case 337: /* alias_opt */ { } break; - case 245: /* privileges */ - case 247: /* priv_type_list */ - case 248: /* priv_type */ + case 248: /* privileges */ + case 250: /* priv_type_list */ + case 251: /* priv_type */ { } break; - case 251: /* not_exists_opt */ - case 253: /* exists_opt */ - case 299: /* analyze_opt */ - case 301: /* agg_func_opt */ - case 339: /* set_quantifier_opt */ + case 254: /* not_exists_opt */ + case 256: /* exists_opt */ + case 302: /* analyze_opt */ + case 304: /* agg_func_opt */ + case 342: /* set_quantifier_opt */ { } break; - case 255: /* integer_list */ - case 256: /* variable_list */ - case 257: /* retention_list */ - case 261: /* column_def_list */ - case 262: /* tags_def_opt */ - case 264: /* multi_create_clause */ - case 265: /* tags_def */ - case 266: /* multi_drop_clause */ - case 273: /* specific_tags_opt */ - case 274: /* literal_list */ - case 276: /* col_name_list */ - case 279: /* duration_list */ - case 280: /* rollup_func_list */ - case 292: /* func_list */ - case 295: /* expression_list */ - case 306: /* dnode_list */ - case 318: /* star_func_para_list */ - case 320: /* other_para_list */ - case 340: /* select_list */ - case 341: /* partition_by_clause_opt */ - case 343: /* group_by_clause_opt */ - case 345: /* select_sublist */ - case 349: /* group_by_list */ - case 351: /* order_by_clause_opt */ - case 355: /* sort_specification_list */ + case 258: /* integer_list */ + case 259: /* variable_list */ + case 260: /* retention_list */ + case 264: /* column_def_list */ + case 265: /* tags_def_opt */ + case 267: /* multi_create_clause */ + case 268: /* tags_def */ + case 269: /* multi_drop_clause */ + case 276: /* specific_tags_opt */ + case 277: /* literal_list */ + case 279: /* col_name_list */ + case 282: /* duration_list */ + case 283: /* rollup_func_list */ + case 295: /* func_list */ + case 298: /* expression_list */ + case 309: /* dnode_list */ + case 321: /* star_func_para_list */ + case 323: /* other_para_list */ + case 343: /* select_list */ + case 344: /* partition_by_clause_opt */ + case 349: /* group_by_clause_opt */ + case 351: /* select_sublist */ + case 354: /* group_by_list */ + case 356: /* order_by_clause_opt */ + case 360: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy530)); + nodesDestroyList((yypminor->yy600)); } break; - case 258: /* alter_db_option */ - case 281: /* alter_table_option */ + case 261: /* alter_db_option */ + case 284: /* alter_table_option */ { } break; - case 270: /* type_name */ + case 273: /* type_name */ { } break; - case 323: /* compare_op */ - case 324: /* in_op */ + case 326: /* compare_op */ + case 327: /* in_op */ { } break; - case 336: /* join_type */ + case 339: /* join_type */ { } break; - case 348: /* fill_mode */ + case 353: /* fill_mode */ { } break; - case 357: /* ordering_specification_opt */ + case 362: /* ordering_specification_opt */ { } break; - case 358: /* null_ordering_opt */ + case 363: /* null_ordering_opt */ { } @@ -2565,465 +2607,472 @@ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 239, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 239, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 240, 0 }, /* (2) account_options ::= */ - { 240, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 240, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 240, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 240, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 240, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 240, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 240, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 240, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 240, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 241, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 241, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 243, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 243, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 243, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 243, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 243, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 243, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 243, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 243, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 243, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 243, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 239, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ - { 239, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 239, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ - { 239, -3 }, /* (27) cmd ::= DROP USER user_name */ - { 239, -6 }, /* (28) cmd ::= GRANT privileges ON priv_level TO user_name */ - { 239, -6 }, /* (29) cmd ::= REVOKE privileges ON priv_level FROM user_name */ - { 245, -1 }, /* (30) privileges ::= ALL */ - { 245, -1 }, /* (31) privileges ::= priv_type_list */ - { 247, -1 }, /* (32) priv_type_list ::= priv_type */ - { 247, -3 }, /* (33) priv_type_list ::= priv_type_list NK_COMMA priv_type */ - { 248, -1 }, /* (34) priv_type ::= READ */ - { 248, -1 }, /* (35) priv_type ::= WRITE */ - { 246, -3 }, /* (36) priv_level ::= NK_STAR NK_DOT NK_STAR */ - { 246, -3 }, /* (37) priv_level ::= db_name NK_DOT NK_STAR */ - { 239, -3 }, /* (38) cmd ::= CREATE DNODE dnode_endpoint */ - { 239, -5 }, /* (39) cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ - { 239, -3 }, /* (40) cmd ::= DROP DNODE NK_INTEGER */ - { 239, -3 }, /* (41) cmd ::= DROP DNODE dnode_endpoint */ - { 239, -4 }, /* (42) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 239, -5 }, /* (43) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 239, -4 }, /* (44) cmd ::= ALTER ALL DNODES NK_STRING */ - { 239, -5 }, /* (45) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 250, -1 }, /* (46) dnode_endpoint ::= NK_STRING */ - { 250, -1 }, /* (47) dnode_endpoint ::= NK_ID */ - { 250, -1 }, /* (48) dnode_endpoint ::= NK_IPTOKEN */ - { 239, -3 }, /* (49) cmd ::= ALTER LOCAL NK_STRING */ - { 239, -4 }, /* (50) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 239, -5 }, /* (51) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 239, -5 }, /* (52) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 239, -5 }, /* (53) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ - { 239, -5 }, /* (54) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ - { 239, -5 }, /* (55) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ - { 239, -5 }, /* (56) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ - { 239, -5 }, /* (57) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ - { 239, -5 }, /* (58) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ - { 239, -5 }, /* (59) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 239, -4 }, /* (60) cmd ::= DROP DATABASE exists_opt db_name */ - { 239, -2 }, /* (61) cmd ::= USE db_name */ - { 239, -4 }, /* (62) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 251, -3 }, /* (63) not_exists_opt ::= IF NOT EXISTS */ - { 251, 0 }, /* (64) not_exists_opt ::= */ - { 253, -2 }, /* (65) exists_opt ::= IF EXISTS */ - { 253, 0 }, /* (66) exists_opt ::= */ - { 252, 0 }, /* (67) db_options ::= */ - { 252, -3 }, /* (68) db_options ::= db_options BUFFER NK_INTEGER */ - { 252, -3 }, /* (69) db_options ::= db_options CACHELAST NK_INTEGER */ - { 252, -3 }, /* (70) db_options ::= db_options COMP NK_INTEGER */ - { 252, -3 }, /* (71) db_options ::= db_options DURATION NK_INTEGER */ - { 252, -3 }, /* (72) db_options ::= db_options DURATION NK_VARIABLE */ - { 252, -3 }, /* (73) db_options ::= db_options FSYNC NK_INTEGER */ - { 252, -3 }, /* (74) db_options ::= db_options MAXROWS NK_INTEGER */ - { 252, -3 }, /* (75) db_options ::= db_options MINROWS NK_INTEGER */ - { 252, -3 }, /* (76) db_options ::= db_options KEEP integer_list */ - { 252, -3 }, /* (77) db_options ::= db_options KEEP variable_list */ - { 252, -3 }, /* (78) db_options ::= db_options PAGES NK_INTEGER */ - { 252, -3 }, /* (79) db_options ::= db_options PAGESIZE NK_INTEGER */ - { 252, -3 }, /* (80) db_options ::= db_options PRECISION NK_STRING */ - { 252, -3 }, /* (81) db_options ::= db_options REPLICA NK_INTEGER */ - { 252, -3 }, /* (82) db_options ::= db_options STRICT NK_INTEGER */ - { 252, -3 }, /* (83) db_options ::= db_options WAL NK_INTEGER */ - { 252, -3 }, /* (84) db_options ::= db_options VGROUPS NK_INTEGER */ - { 252, -3 }, /* (85) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 252, -3 }, /* (86) db_options ::= db_options RETENTIONS retention_list */ - { 252, -3 }, /* (87) db_options ::= db_options SCHEMALESS NK_INTEGER */ - { 254, -1 }, /* (88) alter_db_options ::= alter_db_option */ - { 254, -2 }, /* (89) alter_db_options ::= alter_db_options alter_db_option */ - { 258, -2 }, /* (90) alter_db_option ::= BUFFER NK_INTEGER */ - { 258, -2 }, /* (91) alter_db_option ::= CACHELAST NK_INTEGER */ - { 258, -2 }, /* (92) alter_db_option ::= FSYNC NK_INTEGER */ - { 258, -2 }, /* (93) alter_db_option ::= KEEP integer_list */ - { 258, -2 }, /* (94) alter_db_option ::= KEEP variable_list */ - { 258, -2 }, /* (95) alter_db_option ::= PAGES NK_INTEGER */ - { 258, -2 }, /* (96) alter_db_option ::= REPLICA NK_INTEGER */ - { 258, -2 }, /* (97) alter_db_option ::= STRICT NK_INTEGER */ - { 258, -2 }, /* (98) alter_db_option ::= WAL NK_INTEGER */ - { 255, -1 }, /* (99) integer_list ::= NK_INTEGER */ - { 255, -3 }, /* (100) integer_list ::= integer_list NK_COMMA NK_INTEGER */ - { 256, -1 }, /* (101) variable_list ::= NK_VARIABLE */ - { 256, -3 }, /* (102) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ - { 257, -1 }, /* (103) retention_list ::= retention */ - { 257, -3 }, /* (104) retention_list ::= retention_list NK_COMMA retention */ - { 259, -3 }, /* (105) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ - { 239, -9 }, /* (106) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 239, -3 }, /* (107) cmd ::= CREATE TABLE multi_create_clause */ - { 239, -9 }, /* (108) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 239, -3 }, /* (109) cmd ::= DROP TABLE multi_drop_clause */ - { 239, -4 }, /* (110) cmd ::= DROP STABLE exists_opt full_table_name */ - { 239, -3 }, /* (111) cmd ::= ALTER TABLE alter_table_clause */ - { 239, -3 }, /* (112) cmd ::= ALTER STABLE alter_table_clause */ - { 267, -2 }, /* (113) alter_table_clause ::= full_table_name alter_table_options */ - { 267, -5 }, /* (114) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 267, -4 }, /* (115) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 267, -5 }, /* (116) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 267, -5 }, /* (117) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 267, -5 }, /* (118) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 267, -4 }, /* (119) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 267, -5 }, /* (120) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 267, -5 }, /* (121) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 267, -6 }, /* (122) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ - { 264, -1 }, /* (123) multi_create_clause ::= create_subtable_clause */ - { 264, -2 }, /* (124) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 272, -10 }, /* (125) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options */ - { 266, -1 }, /* (126) multi_drop_clause ::= drop_table_clause */ - { 266, -2 }, /* (127) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 275, -2 }, /* (128) drop_table_clause ::= exists_opt full_table_name */ - { 273, 0 }, /* (129) specific_tags_opt ::= */ - { 273, -3 }, /* (130) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 260, -1 }, /* (131) full_table_name ::= table_name */ - { 260, -3 }, /* (132) full_table_name ::= db_name NK_DOT table_name */ - { 261, -1 }, /* (133) column_def_list ::= column_def */ - { 261, -3 }, /* (134) column_def_list ::= column_def_list NK_COMMA column_def */ - { 278, -2 }, /* (135) column_def ::= column_name type_name */ - { 278, -4 }, /* (136) column_def ::= column_name type_name COMMENT NK_STRING */ - { 270, -1 }, /* (137) type_name ::= BOOL */ - { 270, -1 }, /* (138) type_name ::= TINYINT */ - { 270, -1 }, /* (139) type_name ::= SMALLINT */ - { 270, -1 }, /* (140) type_name ::= INT */ - { 270, -1 }, /* (141) type_name ::= INTEGER */ - { 270, -1 }, /* (142) type_name ::= BIGINT */ - { 270, -1 }, /* (143) type_name ::= FLOAT */ - { 270, -1 }, /* (144) type_name ::= DOUBLE */ - { 270, -4 }, /* (145) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 270, -1 }, /* (146) type_name ::= TIMESTAMP */ - { 270, -4 }, /* (147) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 270, -2 }, /* (148) type_name ::= TINYINT UNSIGNED */ - { 270, -2 }, /* (149) type_name ::= SMALLINT UNSIGNED */ - { 270, -2 }, /* (150) type_name ::= INT UNSIGNED */ - { 270, -2 }, /* (151) type_name ::= BIGINT UNSIGNED */ - { 270, -1 }, /* (152) type_name ::= JSON */ - { 270, -4 }, /* (153) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 270, -1 }, /* (154) type_name ::= MEDIUMBLOB */ - { 270, -1 }, /* (155) type_name ::= BLOB */ - { 270, -4 }, /* (156) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 270, -1 }, /* (157) type_name ::= DECIMAL */ - { 270, -4 }, /* (158) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 270, -6 }, /* (159) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 262, 0 }, /* (160) tags_def_opt ::= */ - { 262, -1 }, /* (161) tags_def_opt ::= tags_def */ - { 265, -4 }, /* (162) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 263, 0 }, /* (163) table_options ::= */ - { 263, -3 }, /* (164) table_options ::= table_options COMMENT NK_STRING */ - { 263, -3 }, /* (165) table_options ::= table_options MAX_DELAY duration_list */ - { 263, -3 }, /* (166) table_options ::= table_options WATERMARK duration_list */ - { 263, -5 }, /* (167) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ - { 263, -3 }, /* (168) table_options ::= table_options TTL NK_INTEGER */ - { 263, -5 }, /* (169) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 268, -1 }, /* (170) alter_table_options ::= alter_table_option */ - { 268, -2 }, /* (171) alter_table_options ::= alter_table_options alter_table_option */ - { 281, -2 }, /* (172) alter_table_option ::= COMMENT NK_STRING */ - { 281, -2 }, /* (173) alter_table_option ::= TTL NK_INTEGER */ - { 279, -1 }, /* (174) duration_list ::= duration_literal */ - { 279, -3 }, /* (175) duration_list ::= duration_list NK_COMMA duration_literal */ - { 280, -1 }, /* (176) rollup_func_list ::= rollup_func_name */ - { 280, -3 }, /* (177) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ - { 283, -1 }, /* (178) rollup_func_name ::= function_name */ - { 283, -1 }, /* (179) rollup_func_name ::= FIRST */ - { 283, -1 }, /* (180) rollup_func_name ::= LAST */ - { 276, -1 }, /* (181) col_name_list ::= col_name */ - { 276, -3 }, /* (182) col_name_list ::= col_name_list NK_COMMA col_name */ - { 285, -1 }, /* (183) col_name ::= column_name */ - { 239, -2 }, /* (184) cmd ::= SHOW DNODES */ - { 239, -2 }, /* (185) cmd ::= SHOW USERS */ - { 239, -2 }, /* (186) cmd ::= SHOW DATABASES */ - { 239, -4 }, /* (187) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 239, -4 }, /* (188) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 239, -3 }, /* (189) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 239, -2 }, /* (190) cmd ::= SHOW MNODES */ - { 239, -2 }, /* (191) cmd ::= SHOW MODULES */ - { 239, -2 }, /* (192) cmd ::= SHOW QNODES */ - { 239, -2 }, /* (193) cmd ::= SHOW FUNCTIONS */ - { 239, -5 }, /* (194) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 239, -2 }, /* (195) cmd ::= SHOW STREAMS */ - { 239, -2 }, /* (196) cmd ::= SHOW ACCOUNTS */ - { 239, -2 }, /* (197) cmd ::= SHOW APPS */ - { 239, -2 }, /* (198) cmd ::= SHOW CONNECTIONS */ - { 239, -2 }, /* (199) cmd ::= SHOW LICENCE */ - { 239, -2 }, /* (200) cmd ::= SHOW GRANTS */ - { 239, -4 }, /* (201) cmd ::= SHOW CREATE DATABASE db_name */ - { 239, -4 }, /* (202) cmd ::= SHOW CREATE TABLE full_table_name */ - { 239, -4 }, /* (203) cmd ::= SHOW CREATE STABLE full_table_name */ - { 239, -2 }, /* (204) cmd ::= SHOW QUERIES */ - { 239, -2 }, /* (205) cmd ::= SHOW SCORES */ - { 239, -2 }, /* (206) cmd ::= SHOW TOPICS */ - { 239, -2 }, /* (207) cmd ::= SHOW VARIABLES */ - { 239, -2 }, /* (208) cmd ::= SHOW BNODES */ - { 239, -2 }, /* (209) cmd ::= SHOW SNODES */ - { 239, -2 }, /* (210) cmd ::= SHOW CLUSTER */ - { 239, -2 }, /* (211) cmd ::= SHOW TRANSACTIONS */ - { 286, 0 }, /* (212) db_name_cond_opt ::= */ - { 286, -2 }, /* (213) db_name_cond_opt ::= db_name NK_DOT */ - { 287, 0 }, /* (214) like_pattern_opt ::= */ - { 287, -2 }, /* (215) like_pattern_opt ::= LIKE NK_STRING */ - { 288, -1 }, /* (216) table_name_cond ::= table_name */ - { 289, 0 }, /* (217) from_db_opt ::= */ - { 289, -2 }, /* (218) from_db_opt ::= FROM db_name */ - { 239, -8 }, /* (219) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 239, -10 }, /* (220) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ - { 239, -6 }, /* (221) cmd ::= DROP INDEX exists_opt index_name ON table_name */ - { 291, 0 }, /* (222) index_options ::= */ - { 291, -9 }, /* (223) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ - { 291, -11 }, /* (224) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ - { 292, -1 }, /* (225) func_list ::= func */ - { 292, -3 }, /* (226) func_list ::= func_list NK_COMMA func */ - { 294, -4 }, /* (227) func ::= function_name NK_LP expression_list NK_RP */ - { 239, -6 }, /* (228) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ - { 239, -7 }, /* (229) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ - { 239, -7 }, /* (230) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ - { 239, -4 }, /* (231) cmd ::= DROP TOPIC exists_opt topic_name */ - { 239, -7 }, /* (232) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ - { 239, -2 }, /* (233) cmd ::= DESC full_table_name */ - { 239, -2 }, /* (234) cmd ::= DESCRIBE full_table_name */ - { 239, -3 }, /* (235) cmd ::= RESET QUERY CACHE */ - { 239, -4 }, /* (236) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ - { 299, 0 }, /* (237) analyze_opt ::= */ - { 299, -1 }, /* (238) analyze_opt ::= ANALYZE */ - { 300, 0 }, /* (239) explain_options ::= */ - { 300, -3 }, /* (240) explain_options ::= explain_options VERBOSE NK_BOOL */ - { 300, -3 }, /* (241) explain_options ::= explain_options RATIO NK_FLOAT */ - { 239, -6 }, /* (242) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ - { 239, -10 }, /* (243) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ - { 239, -4 }, /* (244) cmd ::= DROP FUNCTION exists_opt function_name */ - { 301, 0 }, /* (245) agg_func_opt ::= */ - { 301, -1 }, /* (246) agg_func_opt ::= AGGREGATE */ - { 302, 0 }, /* (247) bufsize_opt ::= */ - { 302, -2 }, /* (248) bufsize_opt ::= BUFSIZE NK_INTEGER */ - { 239, -8 }, /* (249) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ - { 239, -4 }, /* (250) cmd ::= DROP STREAM exists_opt stream_name */ - { 305, 0 }, /* (251) into_opt ::= */ - { 305, -2 }, /* (252) into_opt ::= INTO full_table_name */ - { 304, 0 }, /* (253) stream_options ::= */ - { 304, -3 }, /* (254) stream_options ::= stream_options TRIGGER AT_ONCE */ - { 304, -3 }, /* (255) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ - { 304, -4 }, /* (256) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ - { 304, -3 }, /* (257) stream_options ::= stream_options WATERMARK duration_literal */ - { 239, -3 }, /* (258) cmd ::= KILL CONNECTION NK_INTEGER */ - { 239, -3 }, /* (259) cmd ::= KILL QUERY NK_STRING */ - { 239, -3 }, /* (260) cmd ::= KILL TRANSACTION NK_INTEGER */ - { 239, -2 }, /* (261) cmd ::= BALANCE VGROUP */ - { 239, -4 }, /* (262) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ - { 239, -4 }, /* (263) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ - { 239, -3 }, /* (264) cmd ::= SPLIT VGROUP NK_INTEGER */ - { 306, -2 }, /* (265) dnode_list ::= DNODE NK_INTEGER */ - { 306, -3 }, /* (266) dnode_list ::= dnode_list DNODE NK_INTEGER */ - { 239, -3 }, /* (267) cmd ::= SYNCDB db_name REPLICA */ - { 239, -4 }, /* (268) cmd ::= DELETE FROM full_table_name where_clause_opt */ - { 239, -1 }, /* (269) cmd ::= query_expression */ - { 242, -1 }, /* (270) literal ::= NK_INTEGER */ - { 242, -1 }, /* (271) literal ::= NK_FLOAT */ - { 242, -1 }, /* (272) literal ::= NK_STRING */ - { 242, -1 }, /* (273) literal ::= NK_BOOL */ - { 242, -2 }, /* (274) literal ::= TIMESTAMP NK_STRING */ - { 242, -1 }, /* (275) literal ::= duration_literal */ - { 242, -1 }, /* (276) literal ::= NULL */ - { 242, -1 }, /* (277) literal ::= NK_QUESTION */ - { 282, -1 }, /* (278) duration_literal ::= NK_VARIABLE */ - { 308, -1 }, /* (279) signed ::= NK_INTEGER */ - { 308, -2 }, /* (280) signed ::= NK_PLUS NK_INTEGER */ - { 308, -2 }, /* (281) signed ::= NK_MINUS NK_INTEGER */ - { 308, -1 }, /* (282) signed ::= NK_FLOAT */ - { 308, -2 }, /* (283) signed ::= NK_PLUS NK_FLOAT */ - { 308, -2 }, /* (284) signed ::= NK_MINUS NK_FLOAT */ - { 271, -1 }, /* (285) signed_literal ::= signed */ - { 271, -1 }, /* (286) signed_literal ::= NK_STRING */ - { 271, -1 }, /* (287) signed_literal ::= NK_BOOL */ - { 271, -2 }, /* (288) signed_literal ::= TIMESTAMP NK_STRING */ - { 271, -1 }, /* (289) signed_literal ::= duration_literal */ - { 271, -1 }, /* (290) signed_literal ::= NULL */ - { 271, -1 }, /* (291) signed_literal ::= literal_func */ - { 274, -1 }, /* (292) literal_list ::= signed_literal */ - { 274, -3 }, /* (293) literal_list ::= literal_list NK_COMMA signed_literal */ - { 249, -1 }, /* (294) db_name ::= NK_ID */ - { 277, -1 }, /* (295) table_name ::= NK_ID */ - { 269, -1 }, /* (296) column_name ::= NK_ID */ - { 284, -1 }, /* (297) function_name ::= NK_ID */ - { 310, -1 }, /* (298) table_alias ::= NK_ID */ - { 311, -1 }, /* (299) column_alias ::= NK_ID */ - { 244, -1 }, /* (300) user_name ::= NK_ID */ - { 290, -1 }, /* (301) index_name ::= NK_ID */ - { 296, -1 }, /* (302) topic_name ::= NK_ID */ - { 303, -1 }, /* (303) stream_name ::= NK_ID */ - { 298, -1 }, /* (304) cgroup_name ::= NK_ID */ - { 312, -1 }, /* (305) expression ::= literal */ - { 312, -1 }, /* (306) expression ::= pseudo_column */ - { 312, -1 }, /* (307) expression ::= column_reference */ - { 312, -1 }, /* (308) expression ::= function_expression */ - { 312, -1 }, /* (309) expression ::= subquery */ - { 312, -3 }, /* (310) expression ::= NK_LP expression NK_RP */ - { 312, -2 }, /* (311) expression ::= NK_PLUS expression */ - { 312, -2 }, /* (312) expression ::= NK_MINUS expression */ - { 312, -3 }, /* (313) expression ::= expression NK_PLUS expression */ - { 312, -3 }, /* (314) expression ::= expression NK_MINUS expression */ - { 312, -3 }, /* (315) expression ::= expression NK_STAR expression */ - { 312, -3 }, /* (316) expression ::= expression NK_SLASH expression */ - { 312, -3 }, /* (317) expression ::= expression NK_REM expression */ - { 312, -3 }, /* (318) expression ::= column_reference NK_ARROW NK_STRING */ - { 295, -1 }, /* (319) expression_list ::= expression */ - { 295, -3 }, /* (320) expression_list ::= expression_list NK_COMMA expression */ - { 314, -1 }, /* (321) column_reference ::= column_name */ - { 314, -3 }, /* (322) column_reference ::= table_name NK_DOT column_name */ - { 313, -1 }, /* (323) pseudo_column ::= ROWTS */ - { 313, -1 }, /* (324) pseudo_column ::= TBNAME */ - { 313, -3 }, /* (325) pseudo_column ::= table_name NK_DOT TBNAME */ - { 313, -1 }, /* (326) pseudo_column ::= QSTARTTS */ - { 313, -1 }, /* (327) pseudo_column ::= QENDTS */ - { 313, -1 }, /* (328) pseudo_column ::= WSTARTTS */ - { 313, -1 }, /* (329) pseudo_column ::= WENDTS */ - { 313, -1 }, /* (330) pseudo_column ::= WDURATION */ - { 315, -4 }, /* (331) function_expression ::= function_name NK_LP expression_list NK_RP */ - { 315, -4 }, /* (332) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ - { 315, -6 }, /* (333) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ - { 315, -1 }, /* (334) function_expression ::= literal_func */ - { 309, -3 }, /* (335) literal_func ::= noarg_func NK_LP NK_RP */ - { 309, -1 }, /* (336) literal_func ::= NOW */ - { 319, -1 }, /* (337) noarg_func ::= NOW */ - { 319, -1 }, /* (338) noarg_func ::= TODAY */ - { 319, -1 }, /* (339) noarg_func ::= TIMEZONE */ - { 317, -1 }, /* (340) star_func ::= COUNT */ - { 317, -1 }, /* (341) star_func ::= FIRST */ - { 317, -1 }, /* (342) star_func ::= LAST */ - { 317, -1 }, /* (343) star_func ::= LAST_ROW */ - { 318, -1 }, /* (344) star_func_para_list ::= NK_STAR */ - { 318, -1 }, /* (345) star_func_para_list ::= other_para_list */ - { 320, -1 }, /* (346) other_para_list ::= star_func_para */ - { 320, -3 }, /* (347) other_para_list ::= other_para_list NK_COMMA star_func_para */ - { 321, -1 }, /* (348) star_func_para ::= expression */ - { 321, -3 }, /* (349) star_func_para ::= table_name NK_DOT NK_STAR */ - { 322, -3 }, /* (350) predicate ::= expression compare_op expression */ - { 322, -5 }, /* (351) predicate ::= expression BETWEEN expression AND expression */ - { 322, -6 }, /* (352) predicate ::= expression NOT BETWEEN expression AND expression */ - { 322, -3 }, /* (353) predicate ::= expression IS NULL */ - { 322, -4 }, /* (354) predicate ::= expression IS NOT NULL */ - { 322, -3 }, /* (355) predicate ::= expression in_op in_predicate_value */ - { 323, -1 }, /* (356) compare_op ::= NK_LT */ - { 323, -1 }, /* (357) compare_op ::= NK_GT */ - { 323, -1 }, /* (358) compare_op ::= NK_LE */ - { 323, -1 }, /* (359) compare_op ::= NK_GE */ - { 323, -1 }, /* (360) compare_op ::= NK_NE */ - { 323, -1 }, /* (361) compare_op ::= NK_EQ */ - { 323, -1 }, /* (362) compare_op ::= LIKE */ - { 323, -2 }, /* (363) compare_op ::= NOT LIKE */ - { 323, -1 }, /* (364) compare_op ::= MATCH */ - { 323, -1 }, /* (365) compare_op ::= NMATCH */ - { 323, -1 }, /* (366) compare_op ::= CONTAINS */ - { 324, -1 }, /* (367) in_op ::= IN */ - { 324, -2 }, /* (368) in_op ::= NOT IN */ - { 325, -3 }, /* (369) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 326, -1 }, /* (370) boolean_value_expression ::= boolean_primary */ - { 326, -2 }, /* (371) boolean_value_expression ::= NOT boolean_primary */ - { 326, -3 }, /* (372) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 326, -3 }, /* (373) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 327, -1 }, /* (374) boolean_primary ::= predicate */ - { 327, -3 }, /* (375) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 328, -1 }, /* (376) common_expression ::= expression */ - { 328, -1 }, /* (377) common_expression ::= boolean_value_expression */ - { 329, -2 }, /* (378) from_clause ::= FROM table_reference_list */ - { 330, -1 }, /* (379) table_reference_list ::= table_reference */ - { 330, -3 }, /* (380) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 331, -1 }, /* (381) table_reference ::= table_primary */ - { 331, -1 }, /* (382) table_reference ::= joined_table */ - { 332, -2 }, /* (383) table_primary ::= table_name alias_opt */ - { 332, -4 }, /* (384) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 332, -2 }, /* (385) table_primary ::= subquery alias_opt */ - { 332, -1 }, /* (386) table_primary ::= parenthesized_joined_table */ - { 334, 0 }, /* (387) alias_opt ::= */ - { 334, -1 }, /* (388) alias_opt ::= table_alias */ - { 334, -2 }, /* (389) alias_opt ::= AS table_alias */ - { 335, -3 }, /* (390) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 335, -3 }, /* (391) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 333, -6 }, /* (392) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 336, 0 }, /* (393) join_type ::= */ - { 336, -1 }, /* (394) join_type ::= INNER */ - { 338, -9 }, /* (395) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 339, 0 }, /* (396) set_quantifier_opt ::= */ - { 339, -1 }, /* (397) set_quantifier_opt ::= DISTINCT */ - { 339, -1 }, /* (398) set_quantifier_opt ::= ALL */ - { 340, -1 }, /* (399) select_list ::= NK_STAR */ - { 340, -1 }, /* (400) select_list ::= select_sublist */ - { 345, -1 }, /* (401) select_sublist ::= select_item */ - { 345, -3 }, /* (402) select_sublist ::= select_sublist NK_COMMA select_item */ - { 346, -1 }, /* (403) select_item ::= common_expression */ - { 346, -2 }, /* (404) select_item ::= common_expression column_alias */ - { 346, -3 }, /* (405) select_item ::= common_expression AS column_alias */ - { 346, -3 }, /* (406) select_item ::= table_name NK_DOT NK_STAR */ - { 307, 0 }, /* (407) where_clause_opt ::= */ - { 307, -2 }, /* (408) where_clause_opt ::= WHERE search_condition */ - { 341, 0 }, /* (409) partition_by_clause_opt ::= */ - { 341, -3 }, /* (410) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 342, 0 }, /* (411) twindow_clause_opt ::= */ - { 342, -6 }, /* (412) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 342, -4 }, /* (413) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ - { 342, -6 }, /* (414) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 342, -8 }, /* (415) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 293, 0 }, /* (416) sliding_opt ::= */ - { 293, -4 }, /* (417) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 347, 0 }, /* (418) fill_opt ::= */ - { 347, -4 }, /* (419) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 347, -6 }, /* (420) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 348, -1 }, /* (421) fill_mode ::= NONE */ - { 348, -1 }, /* (422) fill_mode ::= PREV */ - { 348, -1 }, /* (423) fill_mode ::= NULL */ - { 348, -1 }, /* (424) fill_mode ::= LINEAR */ - { 348, -1 }, /* (425) fill_mode ::= NEXT */ - { 343, 0 }, /* (426) group_by_clause_opt ::= */ - { 343, -3 }, /* (427) group_by_clause_opt ::= GROUP BY group_by_list */ - { 349, -1 }, /* (428) group_by_list ::= expression */ - { 349, -3 }, /* (429) group_by_list ::= group_by_list NK_COMMA expression */ - { 344, 0 }, /* (430) having_clause_opt ::= */ - { 344, -2 }, /* (431) having_clause_opt ::= HAVING search_condition */ - { 297, -4 }, /* (432) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 350, -1 }, /* (433) query_expression_body ::= query_primary */ - { 350, -4 }, /* (434) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 350, -3 }, /* (435) query_expression_body ::= query_expression_body UNION query_expression_body */ - { 354, -1 }, /* (436) query_primary ::= query_specification */ - { 354, -6 }, /* (437) query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ - { 351, 0 }, /* (438) order_by_clause_opt ::= */ - { 351, -3 }, /* (439) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 352, 0 }, /* (440) slimit_clause_opt ::= */ - { 352, -2 }, /* (441) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 352, -4 }, /* (442) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 352, -4 }, /* (443) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 353, 0 }, /* (444) limit_clause_opt ::= */ - { 353, -2 }, /* (445) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 353, -4 }, /* (446) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 353, -4 }, /* (447) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 316, -3 }, /* (448) subquery ::= NK_LP query_expression NK_RP */ - { 337, -1 }, /* (449) search_condition ::= common_expression */ - { 355, -1 }, /* (450) sort_specification_list ::= sort_specification */ - { 355, -3 }, /* (451) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 356, -3 }, /* (452) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 357, 0 }, /* (453) ordering_specification_opt ::= */ - { 357, -1 }, /* (454) ordering_specification_opt ::= ASC */ - { 357, -1 }, /* (455) ordering_specification_opt ::= DESC */ - { 358, 0 }, /* (456) null_ordering_opt ::= */ - { 358, -2 }, /* (457) null_ordering_opt ::= NULLS FIRST */ - { 358, -2 }, /* (458) null_ordering_opt ::= NULLS LAST */ + { 242, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ + { 242, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ + { 243, 0 }, /* (2) account_options ::= */ + { 243, -3 }, /* (3) account_options ::= account_options PPS literal */ + { 243, -3 }, /* (4) account_options ::= account_options TSERIES literal */ + { 243, -3 }, /* (5) account_options ::= account_options STORAGE literal */ + { 243, -3 }, /* (6) account_options ::= account_options STREAMS literal */ + { 243, -3 }, /* (7) account_options ::= account_options QTIME literal */ + { 243, -3 }, /* (8) account_options ::= account_options DBS literal */ + { 243, -3 }, /* (9) account_options ::= account_options USERS literal */ + { 243, -3 }, /* (10) account_options ::= account_options CONNS literal */ + { 243, -3 }, /* (11) account_options ::= account_options STATE literal */ + { 244, -1 }, /* (12) alter_account_options ::= alter_account_option */ + { 244, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ + { 246, -2 }, /* (14) alter_account_option ::= PASS literal */ + { 246, -2 }, /* (15) alter_account_option ::= PPS literal */ + { 246, -2 }, /* (16) alter_account_option ::= TSERIES literal */ + { 246, -2 }, /* (17) alter_account_option ::= STORAGE literal */ + { 246, -2 }, /* (18) alter_account_option ::= STREAMS literal */ + { 246, -2 }, /* (19) alter_account_option ::= QTIME literal */ + { 246, -2 }, /* (20) alter_account_option ::= DBS literal */ + { 246, -2 }, /* (21) alter_account_option ::= USERS literal */ + { 246, -2 }, /* (22) alter_account_option ::= CONNS literal */ + { 246, -2 }, /* (23) alter_account_option ::= STATE literal */ + { 242, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ + { 242, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 242, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ + { 242, -3 }, /* (27) cmd ::= DROP USER user_name */ + { 242, -6 }, /* (28) cmd ::= GRANT privileges ON priv_level TO user_name */ + { 242, -6 }, /* (29) cmd ::= REVOKE privileges ON priv_level FROM user_name */ + { 248, -1 }, /* (30) privileges ::= ALL */ + { 248, -1 }, /* (31) privileges ::= priv_type_list */ + { 250, -1 }, /* (32) priv_type_list ::= priv_type */ + { 250, -3 }, /* (33) priv_type_list ::= priv_type_list NK_COMMA priv_type */ + { 251, -1 }, /* (34) priv_type ::= READ */ + { 251, -1 }, /* (35) priv_type ::= WRITE */ + { 249, -3 }, /* (36) priv_level ::= NK_STAR NK_DOT NK_STAR */ + { 249, -3 }, /* (37) priv_level ::= db_name NK_DOT NK_STAR */ + { 242, -3 }, /* (38) cmd ::= CREATE DNODE dnode_endpoint */ + { 242, -5 }, /* (39) cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ + { 242, -3 }, /* (40) cmd ::= DROP DNODE NK_INTEGER */ + { 242, -3 }, /* (41) cmd ::= DROP DNODE dnode_endpoint */ + { 242, -4 }, /* (42) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + { 242, -5 }, /* (43) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + { 242, -4 }, /* (44) cmd ::= ALTER ALL DNODES NK_STRING */ + { 242, -5 }, /* (45) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + { 253, -1 }, /* (46) dnode_endpoint ::= NK_STRING */ + { 253, -1 }, /* (47) dnode_endpoint ::= NK_ID */ + { 253, -1 }, /* (48) dnode_endpoint ::= NK_IPTOKEN */ + { 242, -3 }, /* (49) cmd ::= ALTER LOCAL NK_STRING */ + { 242, -4 }, /* (50) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + { 242, -5 }, /* (51) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 242, -5 }, /* (52) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 242, -5 }, /* (53) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ + { 242, -5 }, /* (54) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ + { 242, -5 }, /* (55) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ + { 242, -5 }, /* (56) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ + { 242, -5 }, /* (57) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ + { 242, -5 }, /* (58) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ + { 242, -5 }, /* (59) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 242, -4 }, /* (60) cmd ::= DROP DATABASE exists_opt db_name */ + { 242, -2 }, /* (61) cmd ::= USE db_name */ + { 242, -4 }, /* (62) cmd ::= ALTER DATABASE db_name alter_db_options */ + { 254, -3 }, /* (63) not_exists_opt ::= IF NOT EXISTS */ + { 254, 0 }, /* (64) not_exists_opt ::= */ + { 256, -2 }, /* (65) exists_opt ::= IF EXISTS */ + { 256, 0 }, /* (66) exists_opt ::= */ + { 255, 0 }, /* (67) db_options ::= */ + { 255, -3 }, /* (68) db_options ::= db_options BUFFER NK_INTEGER */ + { 255, -3 }, /* (69) db_options ::= db_options CACHELAST NK_INTEGER */ + { 255, -3 }, /* (70) db_options ::= db_options COMP NK_INTEGER */ + { 255, -3 }, /* (71) db_options ::= db_options DURATION NK_INTEGER */ + { 255, -3 }, /* (72) db_options ::= db_options DURATION NK_VARIABLE */ + { 255, -3 }, /* (73) db_options ::= db_options FSYNC NK_INTEGER */ + { 255, -3 }, /* (74) db_options ::= db_options MAXROWS NK_INTEGER */ + { 255, -3 }, /* (75) db_options ::= db_options MINROWS NK_INTEGER */ + { 255, -3 }, /* (76) db_options ::= db_options KEEP integer_list */ + { 255, -3 }, /* (77) db_options ::= db_options KEEP variable_list */ + { 255, -3 }, /* (78) db_options ::= db_options PAGES NK_INTEGER */ + { 255, -3 }, /* (79) db_options ::= db_options PAGESIZE NK_INTEGER */ + { 255, -3 }, /* (80) db_options ::= db_options PRECISION NK_STRING */ + { 255, -3 }, /* (81) db_options ::= db_options REPLICA NK_INTEGER */ + { 255, -3 }, /* (82) db_options ::= db_options STRICT NK_INTEGER */ + { 255, -3 }, /* (83) db_options ::= db_options WAL NK_INTEGER */ + { 255, -3 }, /* (84) db_options ::= db_options VGROUPS NK_INTEGER */ + { 255, -3 }, /* (85) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 255, -3 }, /* (86) db_options ::= db_options RETENTIONS retention_list */ + { 255, -3 }, /* (87) db_options ::= db_options SCHEMALESS NK_INTEGER */ + { 257, -1 }, /* (88) alter_db_options ::= alter_db_option */ + { 257, -2 }, /* (89) alter_db_options ::= alter_db_options alter_db_option */ + { 261, -2 }, /* (90) alter_db_option ::= BUFFER NK_INTEGER */ + { 261, -2 }, /* (91) alter_db_option ::= CACHELAST NK_INTEGER */ + { 261, -2 }, /* (92) alter_db_option ::= FSYNC NK_INTEGER */ + { 261, -2 }, /* (93) alter_db_option ::= KEEP integer_list */ + { 261, -2 }, /* (94) alter_db_option ::= KEEP variable_list */ + { 261, -2 }, /* (95) alter_db_option ::= PAGES NK_INTEGER */ + { 261, -2 }, /* (96) alter_db_option ::= REPLICA NK_INTEGER */ + { 261, -2 }, /* (97) alter_db_option ::= STRICT NK_INTEGER */ + { 261, -2 }, /* (98) alter_db_option ::= WAL NK_INTEGER */ + { 258, -1 }, /* (99) integer_list ::= NK_INTEGER */ + { 258, -3 }, /* (100) integer_list ::= integer_list NK_COMMA NK_INTEGER */ + { 259, -1 }, /* (101) variable_list ::= NK_VARIABLE */ + { 259, -3 }, /* (102) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ + { 260, -1 }, /* (103) retention_list ::= retention */ + { 260, -3 }, /* (104) retention_list ::= retention_list NK_COMMA retention */ + { 262, -3 }, /* (105) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ + { 242, -9 }, /* (106) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 242, -3 }, /* (107) cmd ::= CREATE TABLE multi_create_clause */ + { 242, -9 }, /* (108) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 242, -3 }, /* (109) cmd ::= DROP TABLE multi_drop_clause */ + { 242, -4 }, /* (110) cmd ::= DROP STABLE exists_opt full_table_name */ + { 242, -3 }, /* (111) cmd ::= ALTER TABLE alter_table_clause */ + { 242, -3 }, /* (112) cmd ::= ALTER STABLE alter_table_clause */ + { 270, -2 }, /* (113) alter_table_clause ::= full_table_name alter_table_options */ + { 270, -5 }, /* (114) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 270, -4 }, /* (115) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 270, -5 }, /* (116) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 270, -5 }, /* (117) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 270, -5 }, /* (118) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 270, -4 }, /* (119) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 270, -5 }, /* (120) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 270, -5 }, /* (121) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 270, -6 }, /* (122) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ + { 267, -1 }, /* (123) multi_create_clause ::= create_subtable_clause */ + { 267, -2 }, /* (124) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 275, -10 }, /* (125) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options */ + { 269, -1 }, /* (126) multi_drop_clause ::= drop_table_clause */ + { 269, -2 }, /* (127) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 278, -2 }, /* (128) drop_table_clause ::= exists_opt full_table_name */ + { 276, 0 }, /* (129) specific_tags_opt ::= */ + { 276, -3 }, /* (130) specific_tags_opt ::= NK_LP col_name_list NK_RP */ + { 263, -1 }, /* (131) full_table_name ::= table_name */ + { 263, -3 }, /* (132) full_table_name ::= db_name NK_DOT table_name */ + { 264, -1 }, /* (133) column_def_list ::= column_def */ + { 264, -3 }, /* (134) column_def_list ::= column_def_list NK_COMMA column_def */ + { 281, -2 }, /* (135) column_def ::= column_name type_name */ + { 281, -4 }, /* (136) column_def ::= column_name type_name COMMENT NK_STRING */ + { 273, -1 }, /* (137) type_name ::= BOOL */ + { 273, -1 }, /* (138) type_name ::= TINYINT */ + { 273, -1 }, /* (139) type_name ::= SMALLINT */ + { 273, -1 }, /* (140) type_name ::= INT */ + { 273, -1 }, /* (141) type_name ::= INTEGER */ + { 273, -1 }, /* (142) type_name ::= BIGINT */ + { 273, -1 }, /* (143) type_name ::= FLOAT */ + { 273, -1 }, /* (144) type_name ::= DOUBLE */ + { 273, -4 }, /* (145) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 273, -1 }, /* (146) type_name ::= TIMESTAMP */ + { 273, -4 }, /* (147) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 273, -2 }, /* (148) type_name ::= TINYINT UNSIGNED */ + { 273, -2 }, /* (149) type_name ::= SMALLINT UNSIGNED */ + { 273, -2 }, /* (150) type_name ::= INT UNSIGNED */ + { 273, -2 }, /* (151) type_name ::= BIGINT UNSIGNED */ + { 273, -1 }, /* (152) type_name ::= JSON */ + { 273, -4 }, /* (153) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 273, -1 }, /* (154) type_name ::= MEDIUMBLOB */ + { 273, -1 }, /* (155) type_name ::= BLOB */ + { 273, -4 }, /* (156) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 273, -1 }, /* (157) type_name ::= DECIMAL */ + { 273, -4 }, /* (158) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 273, -6 }, /* (159) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 265, 0 }, /* (160) tags_def_opt ::= */ + { 265, -1 }, /* (161) tags_def_opt ::= tags_def */ + { 268, -4 }, /* (162) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 266, 0 }, /* (163) table_options ::= */ + { 266, -3 }, /* (164) table_options ::= table_options COMMENT NK_STRING */ + { 266, -3 }, /* (165) table_options ::= table_options MAX_DELAY duration_list */ + { 266, -3 }, /* (166) table_options ::= table_options WATERMARK duration_list */ + { 266, -5 }, /* (167) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ + { 266, -3 }, /* (168) table_options ::= table_options TTL NK_INTEGER */ + { 266, -5 }, /* (169) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 271, -1 }, /* (170) alter_table_options ::= alter_table_option */ + { 271, -2 }, /* (171) alter_table_options ::= alter_table_options alter_table_option */ + { 284, -2 }, /* (172) alter_table_option ::= COMMENT NK_STRING */ + { 284, -2 }, /* (173) alter_table_option ::= TTL NK_INTEGER */ + { 282, -1 }, /* (174) duration_list ::= duration_literal */ + { 282, -3 }, /* (175) duration_list ::= duration_list NK_COMMA duration_literal */ + { 283, -1 }, /* (176) rollup_func_list ::= rollup_func_name */ + { 283, -3 }, /* (177) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ + { 286, -1 }, /* (178) rollup_func_name ::= function_name */ + { 286, -1 }, /* (179) rollup_func_name ::= FIRST */ + { 286, -1 }, /* (180) rollup_func_name ::= LAST */ + { 279, -1 }, /* (181) col_name_list ::= col_name */ + { 279, -3 }, /* (182) col_name_list ::= col_name_list NK_COMMA col_name */ + { 288, -1 }, /* (183) col_name ::= column_name */ + { 242, -2 }, /* (184) cmd ::= SHOW DNODES */ + { 242, -2 }, /* (185) cmd ::= SHOW USERS */ + { 242, -2 }, /* (186) cmd ::= SHOW DATABASES */ + { 242, -4 }, /* (187) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 242, -4 }, /* (188) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 242, -3 }, /* (189) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 242, -2 }, /* (190) cmd ::= SHOW MNODES */ + { 242, -2 }, /* (191) cmd ::= SHOW MODULES */ + { 242, -2 }, /* (192) cmd ::= SHOW QNODES */ + { 242, -2 }, /* (193) cmd ::= SHOW FUNCTIONS */ + { 242, -5 }, /* (194) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 242, -2 }, /* (195) cmd ::= SHOW STREAMS */ + { 242, -2 }, /* (196) cmd ::= SHOW ACCOUNTS */ + { 242, -2 }, /* (197) cmd ::= SHOW APPS */ + { 242, -2 }, /* (198) cmd ::= SHOW CONNECTIONS */ + { 242, -2 }, /* (199) cmd ::= SHOW LICENCE */ + { 242, -2 }, /* (200) cmd ::= SHOW GRANTS */ + { 242, -4 }, /* (201) cmd ::= SHOW CREATE DATABASE db_name */ + { 242, -4 }, /* (202) cmd ::= SHOW CREATE TABLE full_table_name */ + { 242, -4 }, /* (203) cmd ::= SHOW CREATE STABLE full_table_name */ + { 242, -2 }, /* (204) cmd ::= SHOW QUERIES */ + { 242, -2 }, /* (205) cmd ::= SHOW SCORES */ + { 242, -2 }, /* (206) cmd ::= SHOW TOPICS */ + { 242, -2 }, /* (207) cmd ::= SHOW VARIABLES */ + { 242, -3 }, /* (208) cmd ::= SHOW LOCAL VARIABLES */ + { 242, -4 }, /* (209) cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ + { 242, -2 }, /* (210) cmd ::= SHOW BNODES */ + { 242, -2 }, /* (211) cmd ::= SHOW SNODES */ + { 242, -2 }, /* (212) cmd ::= SHOW CLUSTER */ + { 242, -2 }, /* (213) cmd ::= SHOW TRANSACTIONS */ + { 242, -4 }, /* (214) cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ + { 289, 0 }, /* (215) db_name_cond_opt ::= */ + { 289, -2 }, /* (216) db_name_cond_opt ::= db_name NK_DOT */ + { 290, 0 }, /* (217) like_pattern_opt ::= */ + { 290, -2 }, /* (218) like_pattern_opt ::= LIKE NK_STRING */ + { 291, -1 }, /* (219) table_name_cond ::= table_name */ + { 292, 0 }, /* (220) from_db_opt ::= */ + { 292, -2 }, /* (221) from_db_opt ::= FROM db_name */ + { 242, -8 }, /* (222) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + { 242, -10 }, /* (223) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ + { 242, -6 }, /* (224) cmd ::= DROP INDEX exists_opt index_name ON table_name */ + { 294, 0 }, /* (225) index_options ::= */ + { 294, -9 }, /* (226) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ + { 294, -11 }, /* (227) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ + { 295, -1 }, /* (228) func_list ::= func */ + { 295, -3 }, /* (229) func_list ::= func_list NK_COMMA func */ + { 297, -4 }, /* (230) func ::= function_name NK_LP expression_list NK_RP */ + { 242, -6 }, /* (231) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ + { 242, -7 }, /* (232) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ + { 242, -7 }, /* (233) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ + { 242, -4 }, /* (234) cmd ::= DROP TOPIC exists_opt topic_name */ + { 242, -7 }, /* (235) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ + { 242, -2 }, /* (236) cmd ::= DESC full_table_name */ + { 242, -2 }, /* (237) cmd ::= DESCRIBE full_table_name */ + { 242, -3 }, /* (238) cmd ::= RESET QUERY CACHE */ + { 242, -4 }, /* (239) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ + { 302, 0 }, /* (240) analyze_opt ::= */ + { 302, -1 }, /* (241) analyze_opt ::= ANALYZE */ + { 303, 0 }, /* (242) explain_options ::= */ + { 303, -3 }, /* (243) explain_options ::= explain_options VERBOSE NK_BOOL */ + { 303, -3 }, /* (244) explain_options ::= explain_options RATIO NK_FLOAT */ + { 242, -6 }, /* (245) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ + { 242, -10 }, /* (246) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ + { 242, -4 }, /* (247) cmd ::= DROP FUNCTION exists_opt function_name */ + { 304, 0 }, /* (248) agg_func_opt ::= */ + { 304, -1 }, /* (249) agg_func_opt ::= AGGREGATE */ + { 305, 0 }, /* (250) bufsize_opt ::= */ + { 305, -2 }, /* (251) bufsize_opt ::= BUFSIZE NK_INTEGER */ + { 242, -8 }, /* (252) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ + { 242, -4 }, /* (253) cmd ::= DROP STREAM exists_opt stream_name */ + { 308, 0 }, /* (254) into_opt ::= */ + { 308, -2 }, /* (255) into_opt ::= INTO full_table_name */ + { 307, 0 }, /* (256) stream_options ::= */ + { 307, -3 }, /* (257) stream_options ::= stream_options TRIGGER AT_ONCE */ + { 307, -3 }, /* (258) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ + { 307, -4 }, /* (259) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ + { 307, -3 }, /* (260) stream_options ::= stream_options WATERMARK duration_literal */ + { 242, -3 }, /* (261) cmd ::= KILL CONNECTION NK_INTEGER */ + { 242, -3 }, /* (262) cmd ::= KILL QUERY NK_STRING */ + { 242, -3 }, /* (263) cmd ::= KILL TRANSACTION NK_INTEGER */ + { 242, -2 }, /* (264) cmd ::= BALANCE VGROUP */ + { 242, -4 }, /* (265) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + { 242, -4 }, /* (266) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + { 242, -3 }, /* (267) cmd ::= SPLIT VGROUP NK_INTEGER */ + { 309, -2 }, /* (268) dnode_list ::= DNODE NK_INTEGER */ + { 309, -3 }, /* (269) dnode_list ::= dnode_list DNODE NK_INTEGER */ + { 242, -3 }, /* (270) cmd ::= SYNCDB db_name REPLICA */ + { 242, -4 }, /* (271) cmd ::= DELETE FROM full_table_name where_clause_opt */ + { 242, -1 }, /* (272) cmd ::= query_expression */ + { 245, -1 }, /* (273) literal ::= NK_INTEGER */ + { 245, -1 }, /* (274) literal ::= NK_FLOAT */ + { 245, -1 }, /* (275) literal ::= NK_STRING */ + { 245, -1 }, /* (276) literal ::= NK_BOOL */ + { 245, -2 }, /* (277) literal ::= TIMESTAMP NK_STRING */ + { 245, -1 }, /* (278) literal ::= duration_literal */ + { 245, -1 }, /* (279) literal ::= NULL */ + { 245, -1 }, /* (280) literal ::= NK_QUESTION */ + { 285, -1 }, /* (281) duration_literal ::= NK_VARIABLE */ + { 311, -1 }, /* (282) signed ::= NK_INTEGER */ + { 311, -2 }, /* (283) signed ::= NK_PLUS NK_INTEGER */ + { 311, -2 }, /* (284) signed ::= NK_MINUS NK_INTEGER */ + { 311, -1 }, /* (285) signed ::= NK_FLOAT */ + { 311, -2 }, /* (286) signed ::= NK_PLUS NK_FLOAT */ + { 311, -2 }, /* (287) signed ::= NK_MINUS NK_FLOAT */ + { 274, -1 }, /* (288) signed_literal ::= signed */ + { 274, -1 }, /* (289) signed_literal ::= NK_STRING */ + { 274, -1 }, /* (290) signed_literal ::= NK_BOOL */ + { 274, -2 }, /* (291) signed_literal ::= TIMESTAMP NK_STRING */ + { 274, -1 }, /* (292) signed_literal ::= duration_literal */ + { 274, -1 }, /* (293) signed_literal ::= NULL */ + { 274, -1 }, /* (294) signed_literal ::= literal_func */ + { 277, -1 }, /* (295) literal_list ::= signed_literal */ + { 277, -3 }, /* (296) literal_list ::= literal_list NK_COMMA signed_literal */ + { 252, -1 }, /* (297) db_name ::= NK_ID */ + { 280, -1 }, /* (298) table_name ::= NK_ID */ + { 272, -1 }, /* (299) column_name ::= NK_ID */ + { 287, -1 }, /* (300) function_name ::= NK_ID */ + { 313, -1 }, /* (301) table_alias ::= NK_ID */ + { 314, -1 }, /* (302) column_alias ::= NK_ID */ + { 247, -1 }, /* (303) user_name ::= NK_ID */ + { 293, -1 }, /* (304) index_name ::= NK_ID */ + { 299, -1 }, /* (305) topic_name ::= NK_ID */ + { 306, -1 }, /* (306) stream_name ::= NK_ID */ + { 301, -1 }, /* (307) cgroup_name ::= NK_ID */ + { 315, -1 }, /* (308) expression ::= literal */ + { 315, -1 }, /* (309) expression ::= pseudo_column */ + { 315, -1 }, /* (310) expression ::= column_reference */ + { 315, -1 }, /* (311) expression ::= function_expression */ + { 315, -1 }, /* (312) expression ::= subquery */ + { 315, -3 }, /* (313) expression ::= NK_LP expression NK_RP */ + { 315, -2 }, /* (314) expression ::= NK_PLUS expression */ + { 315, -2 }, /* (315) expression ::= NK_MINUS expression */ + { 315, -3 }, /* (316) expression ::= expression NK_PLUS expression */ + { 315, -3 }, /* (317) expression ::= expression NK_MINUS expression */ + { 315, -3 }, /* (318) expression ::= expression NK_STAR expression */ + { 315, -3 }, /* (319) expression ::= expression NK_SLASH expression */ + { 315, -3 }, /* (320) expression ::= expression NK_REM expression */ + { 315, -3 }, /* (321) expression ::= column_reference NK_ARROW NK_STRING */ + { 298, -1 }, /* (322) expression_list ::= expression */ + { 298, -3 }, /* (323) expression_list ::= expression_list NK_COMMA expression */ + { 317, -1 }, /* (324) column_reference ::= column_name */ + { 317, -3 }, /* (325) column_reference ::= table_name NK_DOT column_name */ + { 316, -1 }, /* (326) pseudo_column ::= ROWTS */ + { 316, -1 }, /* (327) pseudo_column ::= TBNAME */ + { 316, -3 }, /* (328) pseudo_column ::= table_name NK_DOT TBNAME */ + { 316, -1 }, /* (329) pseudo_column ::= QSTARTTS */ + { 316, -1 }, /* (330) pseudo_column ::= QENDTS */ + { 316, -1 }, /* (331) pseudo_column ::= WSTARTTS */ + { 316, -1 }, /* (332) pseudo_column ::= WENDTS */ + { 316, -1 }, /* (333) pseudo_column ::= WDURATION */ + { 318, -4 }, /* (334) function_expression ::= function_name NK_LP expression_list NK_RP */ + { 318, -4 }, /* (335) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ + { 318, -6 }, /* (336) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ + { 318, -1 }, /* (337) function_expression ::= literal_func */ + { 312, -3 }, /* (338) literal_func ::= noarg_func NK_LP NK_RP */ + { 312, -1 }, /* (339) literal_func ::= NOW */ + { 322, -1 }, /* (340) noarg_func ::= NOW */ + { 322, -1 }, /* (341) noarg_func ::= TODAY */ + { 322, -1 }, /* (342) noarg_func ::= TIMEZONE */ + { 320, -1 }, /* (343) star_func ::= COUNT */ + { 320, -1 }, /* (344) star_func ::= FIRST */ + { 320, -1 }, /* (345) star_func ::= LAST */ + { 320, -1 }, /* (346) star_func ::= LAST_ROW */ + { 321, -1 }, /* (347) star_func_para_list ::= NK_STAR */ + { 321, -1 }, /* (348) star_func_para_list ::= other_para_list */ + { 323, -1 }, /* (349) other_para_list ::= star_func_para */ + { 323, -3 }, /* (350) other_para_list ::= other_para_list NK_COMMA star_func_para */ + { 324, -1 }, /* (351) star_func_para ::= expression */ + { 324, -3 }, /* (352) star_func_para ::= table_name NK_DOT NK_STAR */ + { 325, -3 }, /* (353) predicate ::= expression compare_op expression */ + { 325, -5 }, /* (354) predicate ::= expression BETWEEN expression AND expression */ + { 325, -6 }, /* (355) predicate ::= expression NOT BETWEEN expression AND expression */ + { 325, -3 }, /* (356) predicate ::= expression IS NULL */ + { 325, -4 }, /* (357) predicate ::= expression IS NOT NULL */ + { 325, -3 }, /* (358) predicate ::= expression in_op in_predicate_value */ + { 326, -1 }, /* (359) compare_op ::= NK_LT */ + { 326, -1 }, /* (360) compare_op ::= NK_GT */ + { 326, -1 }, /* (361) compare_op ::= NK_LE */ + { 326, -1 }, /* (362) compare_op ::= NK_GE */ + { 326, -1 }, /* (363) compare_op ::= NK_NE */ + { 326, -1 }, /* (364) compare_op ::= NK_EQ */ + { 326, -1 }, /* (365) compare_op ::= LIKE */ + { 326, -2 }, /* (366) compare_op ::= NOT LIKE */ + { 326, -1 }, /* (367) compare_op ::= MATCH */ + { 326, -1 }, /* (368) compare_op ::= NMATCH */ + { 326, -1 }, /* (369) compare_op ::= CONTAINS */ + { 327, -1 }, /* (370) in_op ::= IN */ + { 327, -2 }, /* (371) in_op ::= NOT IN */ + { 328, -3 }, /* (372) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 329, -1 }, /* (373) boolean_value_expression ::= boolean_primary */ + { 329, -2 }, /* (374) boolean_value_expression ::= NOT boolean_primary */ + { 329, -3 }, /* (375) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 329, -3 }, /* (376) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 330, -1 }, /* (377) boolean_primary ::= predicate */ + { 330, -3 }, /* (378) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 331, -1 }, /* (379) common_expression ::= expression */ + { 331, -1 }, /* (380) common_expression ::= boolean_value_expression */ + { 332, -2 }, /* (381) from_clause ::= FROM table_reference_list */ + { 333, -1 }, /* (382) table_reference_list ::= table_reference */ + { 333, -3 }, /* (383) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 334, -1 }, /* (384) table_reference ::= table_primary */ + { 334, -1 }, /* (385) table_reference ::= joined_table */ + { 335, -2 }, /* (386) table_primary ::= table_name alias_opt */ + { 335, -4 }, /* (387) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 335, -2 }, /* (388) table_primary ::= subquery alias_opt */ + { 335, -1 }, /* (389) table_primary ::= parenthesized_joined_table */ + { 337, 0 }, /* (390) alias_opt ::= */ + { 337, -1 }, /* (391) alias_opt ::= table_alias */ + { 337, -2 }, /* (392) alias_opt ::= AS table_alias */ + { 338, -3 }, /* (393) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 338, -3 }, /* (394) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 336, -6 }, /* (395) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 339, 0 }, /* (396) join_type ::= */ + { 339, -1 }, /* (397) join_type ::= INNER */ + { 341, -12 }, /* (398) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 342, 0 }, /* (399) set_quantifier_opt ::= */ + { 342, -1 }, /* (400) set_quantifier_opt ::= DISTINCT */ + { 342, -1 }, /* (401) set_quantifier_opt ::= ALL */ + { 343, -1 }, /* (402) select_list ::= NK_STAR */ + { 343, -1 }, /* (403) select_list ::= select_sublist */ + { 351, -1 }, /* (404) select_sublist ::= select_item */ + { 351, -3 }, /* (405) select_sublist ::= select_sublist NK_COMMA select_item */ + { 352, -1 }, /* (406) select_item ::= common_expression */ + { 352, -2 }, /* (407) select_item ::= common_expression column_alias */ + { 352, -3 }, /* (408) select_item ::= common_expression AS column_alias */ + { 352, -3 }, /* (409) select_item ::= table_name NK_DOT NK_STAR */ + { 310, 0 }, /* (410) where_clause_opt ::= */ + { 310, -2 }, /* (411) where_clause_opt ::= WHERE search_condition */ + { 344, 0 }, /* (412) partition_by_clause_opt ::= */ + { 344, -3 }, /* (413) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 348, 0 }, /* (414) twindow_clause_opt ::= */ + { 348, -6 }, /* (415) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 348, -4 }, /* (416) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ + { 348, -6 }, /* (417) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 348, -8 }, /* (418) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 296, 0 }, /* (419) sliding_opt ::= */ + { 296, -4 }, /* (420) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 347, 0 }, /* (421) fill_opt ::= */ + { 347, -4 }, /* (422) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 347, -6 }, /* (423) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 353, -1 }, /* (424) fill_mode ::= NONE */ + { 353, -1 }, /* (425) fill_mode ::= PREV */ + { 353, -1 }, /* (426) fill_mode ::= NULL */ + { 353, -1 }, /* (427) fill_mode ::= LINEAR */ + { 353, -1 }, /* (428) fill_mode ::= NEXT */ + { 349, 0 }, /* (429) group_by_clause_opt ::= */ + { 349, -3 }, /* (430) group_by_clause_opt ::= GROUP BY group_by_list */ + { 354, -1 }, /* (431) group_by_list ::= expression */ + { 354, -3 }, /* (432) group_by_list ::= group_by_list NK_COMMA expression */ + { 350, 0 }, /* (433) having_clause_opt ::= */ + { 350, -2 }, /* (434) having_clause_opt ::= HAVING search_condition */ + { 345, 0 }, /* (435) range_opt ::= */ + { 345, -6 }, /* (436) range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ + { 346, 0 }, /* (437) every_opt ::= */ + { 346, -4 }, /* (438) every_opt ::= EVERY NK_LP duration_literal NK_RP */ + { 300, -4 }, /* (439) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 355, -1 }, /* (440) query_expression_body ::= query_primary */ + { 355, -4 }, /* (441) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 355, -3 }, /* (442) query_expression_body ::= query_expression_body UNION query_expression_body */ + { 359, -1 }, /* (443) query_primary ::= query_specification */ + { 359, -6 }, /* (444) query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ + { 356, 0 }, /* (445) order_by_clause_opt ::= */ + { 356, -3 }, /* (446) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 357, 0 }, /* (447) slimit_clause_opt ::= */ + { 357, -2 }, /* (448) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 357, -4 }, /* (449) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 357, -4 }, /* (450) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 358, 0 }, /* (451) limit_clause_opt ::= */ + { 358, -2 }, /* (452) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 358, -4 }, /* (453) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 358, -4 }, /* (454) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 319, -3 }, /* (455) subquery ::= NK_LP query_expression NK_RP */ + { 340, -1 }, /* (456) search_condition ::= common_expression */ + { 360, -1 }, /* (457) sort_specification_list ::= sort_specification */ + { 360, -3 }, /* (458) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 361, -3 }, /* (459) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 362, 0 }, /* (460) ordering_specification_opt ::= */ + { 362, -1 }, /* (461) ordering_specification_opt ::= ASC */ + { 362, -1 }, /* (462) ordering_specification_opt ::= DESC */ + { 363, 0 }, /* (463) null_ordering_opt ::= */ + { 363, -2 }, /* (464) null_ordering_opt ::= NULLS FIRST */ + { 363, -2 }, /* (465) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -3112,11 +3161,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,240,&yymsp[0].minor); + yy_destructor(yypParser,243,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,241,&yymsp[0].minor); + yy_destructor(yypParser,244,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -3130,20 +3179,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); 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,240,&yymsp[-2].minor); +{ yy_destructor(yypParser,243,&yymsp[-2].minor); { } - yy_destructor(yypParser,242,&yymsp[0].minor); + yy_destructor(yypParser,245,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,243,&yymsp[0].minor); +{ yy_destructor(yypParser,246,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,241,&yymsp[-1].minor); +{ yy_destructor(yypParser,244,&yymsp[-1].minor); { } - yy_destructor(yypParser,243,&yymsp[0].minor); + yy_destructor(yypParser,246,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -3157,63 +3206,63 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,242,&yymsp[0].minor); + yy_destructor(yypParser,245,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy421, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy57, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy421, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy57, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy421); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy57); } break; case 28: /* cmd ::= GRANT privileges ON priv_level TO user_name */ -{ pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-4].minor.yy669, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy421); } +{ pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-4].minor.yy389, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57); } break; case 29: /* cmd ::= REVOKE privileges ON priv_level FROM user_name */ -{ pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-4].minor.yy669, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy421); } +{ pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-4].minor.yy389, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57); } break; case 30: /* privileges ::= ALL */ -{ yymsp[0].minor.yy669 = PRIVILEGE_TYPE_ALL; } +{ yymsp[0].minor.yy389 = PRIVILEGE_TYPE_ALL; } break; case 31: /* privileges ::= priv_type_list */ case 32: /* priv_type_list ::= priv_type */ yytestcase(yyruleno==32); -{ yylhsminor.yy669 = yymsp[0].minor.yy669; } - yymsp[0].minor.yy669 = yylhsminor.yy669; +{ yylhsminor.yy389 = yymsp[0].minor.yy389; } + yymsp[0].minor.yy389 = yylhsminor.yy389; break; case 33: /* priv_type_list ::= priv_type_list NK_COMMA priv_type */ -{ yylhsminor.yy669 = yymsp[-2].minor.yy669 | yymsp[0].minor.yy669; } - yymsp[-2].minor.yy669 = yylhsminor.yy669; +{ yylhsminor.yy389 = yymsp[-2].minor.yy389 | yymsp[0].minor.yy389; } + yymsp[-2].minor.yy389 = yylhsminor.yy389; break; case 34: /* priv_type ::= READ */ -{ yymsp[0].minor.yy669 = PRIVILEGE_TYPE_READ; } +{ yymsp[0].minor.yy389 = PRIVILEGE_TYPE_READ; } break; case 35: /* priv_type ::= WRITE */ -{ yymsp[0].minor.yy669 = PRIVILEGE_TYPE_WRITE; } +{ yymsp[0].minor.yy389 = PRIVILEGE_TYPE_WRITE; } break; case 36: /* priv_level ::= NK_STAR NK_DOT NK_STAR */ -{ yylhsminor.yy421 = yymsp[-2].minor.yy0; } - yymsp[-2].minor.yy421 = yylhsminor.yy421; +{ yylhsminor.yy57 = yymsp[-2].minor.yy0; } + yymsp[-2].minor.yy57 = yylhsminor.yy57; break; case 37: /* priv_level ::= db_name NK_DOT NK_STAR */ -{ yylhsminor.yy421 = yymsp[-2].minor.yy421; } - yymsp[-2].minor.yy421 = yylhsminor.yy421; +{ yylhsminor.yy57 = yymsp[-2].minor.yy57; } + yymsp[-2].minor.yy57 = yylhsminor.yy57; break; case 38: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy421, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy57, NULL); } break; case 39: /* cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy0); } break; case 40: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 41: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy421); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy57); } break; case 42: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -3230,26 +3279,26 @@ static YYACTIONTYPE yy_reduce( case 46: /* dnode_endpoint ::= NK_STRING */ case 47: /* dnode_endpoint ::= NK_ID */ yytestcase(yyruleno==47); case 48: /* dnode_endpoint ::= NK_IPTOKEN */ yytestcase(yyruleno==48); - case 294: /* db_name ::= NK_ID */ yytestcase(yyruleno==294); - case 295: /* table_name ::= NK_ID */ yytestcase(yyruleno==295); - case 296: /* column_name ::= NK_ID */ yytestcase(yyruleno==296); - case 297: /* function_name ::= NK_ID */ yytestcase(yyruleno==297); - case 298: /* table_alias ::= NK_ID */ yytestcase(yyruleno==298); - case 299: /* column_alias ::= NK_ID */ yytestcase(yyruleno==299); - case 300: /* user_name ::= NK_ID */ yytestcase(yyruleno==300); - case 301: /* index_name ::= NK_ID */ yytestcase(yyruleno==301); - case 302: /* topic_name ::= NK_ID */ yytestcase(yyruleno==302); - case 303: /* stream_name ::= NK_ID */ yytestcase(yyruleno==303); - case 304: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==304); - case 337: /* noarg_func ::= NOW */ yytestcase(yyruleno==337); - case 338: /* noarg_func ::= TODAY */ yytestcase(yyruleno==338); - case 339: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==339); - case 340: /* star_func ::= COUNT */ yytestcase(yyruleno==340); - case 341: /* star_func ::= FIRST */ yytestcase(yyruleno==341); - case 342: /* star_func ::= LAST */ yytestcase(yyruleno==342); - case 343: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==343); -{ yylhsminor.yy421 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy421 = yylhsminor.yy421; + case 297: /* db_name ::= NK_ID */ yytestcase(yyruleno==297); + case 298: /* table_name ::= NK_ID */ yytestcase(yyruleno==298); + case 299: /* column_name ::= NK_ID */ yytestcase(yyruleno==299); + case 300: /* function_name ::= NK_ID */ yytestcase(yyruleno==300); + case 301: /* table_alias ::= NK_ID */ yytestcase(yyruleno==301); + case 302: /* column_alias ::= NK_ID */ yytestcase(yyruleno==302); + case 303: /* user_name ::= NK_ID */ yytestcase(yyruleno==303); + case 304: /* index_name ::= NK_ID */ yytestcase(yyruleno==304); + case 305: /* topic_name ::= NK_ID */ yytestcase(yyruleno==305); + case 306: /* stream_name ::= NK_ID */ yytestcase(yyruleno==306); + case 307: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==307); + case 340: /* noarg_func ::= NOW */ yytestcase(yyruleno==340); + case 341: /* noarg_func ::= TODAY */ yytestcase(yyruleno==341); + case 342: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==342); + case 343: /* star_func ::= COUNT */ yytestcase(yyruleno==343); + case 344: /* star_func ::= FIRST */ yytestcase(yyruleno==344); + case 345: /* star_func ::= LAST */ yytestcase(yyruleno==345); + case 346: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==346); +{ yylhsminor.yy57 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy57 = yylhsminor.yy57; break; case 49: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -3282,156 +3331,156 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &yymsp[0].minor.yy0); } break; case 59: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy621, &yymsp[-1].minor.yy421, yymsp[0].minor.yy674); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy481, &yymsp[-1].minor.yy57, yymsp[0].minor.yy392); } break; case 60: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy621, &yymsp[0].minor.yy421); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy481, &yymsp[0].minor.yy57); } break; case 61: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy421); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy57); } break; case 62: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy421, yymsp[0].minor.yy674); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy57, yymsp[0].minor.yy392); } break; case 63: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy621 = true; } +{ yymsp[-2].minor.yy481 = true; } break; case 64: /* not_exists_opt ::= */ case 66: /* exists_opt ::= */ yytestcase(yyruleno==66); - case 237: /* analyze_opt ::= */ yytestcase(yyruleno==237); - case 245: /* agg_func_opt ::= */ yytestcase(yyruleno==245); - case 396: /* set_quantifier_opt ::= */ yytestcase(yyruleno==396); -{ yymsp[1].minor.yy621 = false; } + case 240: /* analyze_opt ::= */ yytestcase(yyruleno==240); + case 248: /* agg_func_opt ::= */ yytestcase(yyruleno==248); + case 399: /* set_quantifier_opt ::= */ yytestcase(yyruleno==399); +{ yymsp[1].minor.yy481 = false; } break; case 65: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy621 = true; } +{ yymsp[-1].minor.yy481 = true; } break; case 67: /* db_options ::= */ -{ yymsp[1].minor.yy674 = createDefaultDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy392 = createDefaultDatabaseOptions(pCxt); } break; case 68: /* db_options ::= db_options BUFFER NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 69: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 70: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 71: /* db_options ::= db_options DURATION NK_INTEGER */ case 72: /* db_options ::= db_options DURATION NK_VARIABLE */ yytestcase(yyruleno==72); -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 73: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 74: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 75: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 76: /* db_options ::= db_options KEEP integer_list */ case 77: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==77); -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_KEEP, yymsp[0].minor.yy530); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_KEEP, yymsp[0].minor.yy600); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 78: /* db_options ::= db_options PAGES NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 79: /* db_options ::= db_options PAGESIZE NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 80: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 81: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 82: /* db_options ::= db_options STRICT NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_STRICT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_STRICT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 83: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 84: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 85: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 86: /* db_options ::= db_options RETENTIONS retention_list */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_RETENTIONS, yymsp[0].minor.yy530); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_RETENTIONS, yymsp[0].minor.yy600); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 87: /* db_options ::= db_options SCHEMALESS NK_INTEGER */ -{ yylhsminor.yy674 = setDatabaseOption(pCxt, yymsp[-2].minor.yy674, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 88: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy674 = createAlterDatabaseOptions(pCxt); yylhsminor.yy674 = setAlterDatabaseOption(pCxt, yylhsminor.yy674, &yymsp[0].minor.yy557); } - yymsp[0].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterDatabaseOptions(pCxt); yylhsminor.yy392 = setAlterDatabaseOption(pCxt, yylhsminor.yy392, &yymsp[0].minor.yy221); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; case 89: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy674 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy674, &yymsp[0].minor.yy557); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy392, &yymsp[0].minor.yy221); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; case 90: /* alter_db_option ::= BUFFER NK_INTEGER */ -{ yymsp[-1].minor.yy557.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy557.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy221.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } break; case 91: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy557.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy557.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy221.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } break; case 92: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy557.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy557.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy221.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } break; case 93: /* alter_db_option ::= KEEP integer_list */ case 94: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==94); -{ yymsp[-1].minor.yy557.type = DB_OPTION_KEEP; yymsp[-1].minor.yy557.pList = yymsp[0].minor.yy530; } +{ yymsp[-1].minor.yy221.type = DB_OPTION_KEEP; yymsp[-1].minor.yy221.pList = yymsp[0].minor.yy600; } break; case 95: /* alter_db_option ::= PAGES NK_INTEGER */ -{ yymsp[-1].minor.yy557.type = DB_OPTION_PAGES; yymsp[-1].minor.yy557.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy221.type = DB_OPTION_PAGES; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } break; case 96: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy557.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy557.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy221.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } break; case 97: /* alter_db_option ::= STRICT NK_INTEGER */ -{ yymsp[-1].minor.yy557.type = DB_OPTION_STRICT; yymsp[-1].minor.yy557.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy221.type = DB_OPTION_STRICT; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } break; case 98: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy557.type = DB_OPTION_WAL; yymsp[-1].minor.yy557.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy221.type = DB_OPTION_WAL; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } break; case 99: /* integer_list ::= NK_INTEGER */ -{ yylhsminor.yy530 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy530 = yylhsminor.yy530; +{ yylhsminor.yy600 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy600 = yylhsminor.yy600; break; case 100: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ - case 266: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==266); -{ yylhsminor.yy530 = addNodeToList(pCxt, yymsp[-2].minor.yy530, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy530 = yylhsminor.yy530; + case 269: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==269); +{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-2].minor.yy600, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy600 = yylhsminor.yy600; break; case 101: /* variable_list ::= NK_VARIABLE */ -{ yylhsminor.yy530 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy530 = yylhsminor.yy530; +{ yylhsminor.yy600 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy600 = yylhsminor.yy600; break; case 102: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ -{ yylhsminor.yy530 = addNodeToList(pCxt, yymsp[-2].minor.yy530, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy530 = yylhsminor.yy530; +{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-2].minor.yy600, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy600 = yylhsminor.yy600; break; case 103: /* retention_list ::= retention */ case 123: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==123); @@ -3439,1009 +3488,1027 @@ static YYACTIONTYPE yy_reduce( case 133: /* column_def_list ::= column_def */ yytestcase(yyruleno==133); case 176: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==176); case 181: /* col_name_list ::= col_name */ yytestcase(yyruleno==181); - case 225: /* func_list ::= func */ yytestcase(yyruleno==225); - case 292: /* literal_list ::= signed_literal */ yytestcase(yyruleno==292); - case 346: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==346); - case 401: /* select_sublist ::= select_item */ yytestcase(yyruleno==401); - case 450: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==450); -{ yylhsminor.yy530 = createNodeList(pCxt, yymsp[0].minor.yy674); } - yymsp[0].minor.yy530 = yylhsminor.yy530; + case 228: /* func_list ::= func */ yytestcase(yyruleno==228); + case 295: /* literal_list ::= signed_literal */ yytestcase(yyruleno==295); + case 349: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==349); + case 404: /* select_sublist ::= select_item */ yytestcase(yyruleno==404); + case 457: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==457); +{ yylhsminor.yy600 = createNodeList(pCxt, yymsp[0].minor.yy392); } + yymsp[0].minor.yy600 = yylhsminor.yy600; break; case 104: /* retention_list ::= retention_list NK_COMMA retention */ case 134: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==134); case 177: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==177); case 182: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==182); - case 226: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==226); - case 293: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==293); - case 347: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==347); - case 402: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==402); - case 451: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==451); -{ yylhsminor.yy530 = addNodeToList(pCxt, yymsp[-2].minor.yy530, yymsp[0].minor.yy674); } - yymsp[-2].minor.yy530 = yylhsminor.yy530; + case 229: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==229); + case 296: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==296); + case 350: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==350); + case 405: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==405); + case 458: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==458); +{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-2].minor.yy600, yymsp[0].minor.yy392); } + yymsp[-2].minor.yy600 = yylhsminor.yy600; break; case 105: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ -{ yylhsminor.yy674 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 106: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ case 108: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==108); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy621, yymsp[-5].minor.yy674, yymsp[-3].minor.yy530, yymsp[-1].minor.yy530, yymsp[0].minor.yy674); } +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy481, yymsp[-5].minor.yy392, yymsp[-3].minor.yy600, yymsp[-1].minor.yy600, yymsp[0].minor.yy392); } break; case 107: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy530); } +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy600); } break; case 109: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy530); } +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy600); } break; case 110: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy621, yymsp[0].minor.yy674); } +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy481, yymsp[0].minor.yy392); } break; case 111: /* cmd ::= ALTER TABLE alter_table_clause */ case 112: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==112); - case 269: /* cmd ::= query_expression */ yytestcase(yyruleno==269); -{ pCxt->pRootNode = yymsp[0].minor.yy674; } + case 272: /* cmd ::= query_expression */ yytestcase(yyruleno==272); +{ pCxt->pRootNode = yymsp[0].minor.yy392; } break; case 113: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy674 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy674, yymsp[0].minor.yy674); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; case 114: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy674 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy674, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy421, yymsp[0].minor.yy690); } - yymsp[-4].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy57, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 115: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy674 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy674, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy421); } - yymsp[-3].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy392, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy57); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; case 116: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy674 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy674, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy421, yymsp[0].minor.yy690); } - yymsp[-4].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy57, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 117: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy674 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy674, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy421, &yymsp[0].minor.yy421); } - yymsp[-4].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy57, &yymsp[0].minor.yy57); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 118: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy674 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy674, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy421, yymsp[0].minor.yy690); } - yymsp[-4].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy57, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 119: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy674 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy674, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy421); } - yymsp[-3].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy392, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy57); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; case 120: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy674 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy674, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy421, yymsp[0].minor.yy690); } - yymsp[-4].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy57, yymsp[0].minor.yy448); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 121: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy674 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy674, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy421, &yymsp[0].minor.yy421); } - yymsp[-4].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy57, &yymsp[0].minor.yy57); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 122: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ -{ yylhsminor.yy674 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy674, &yymsp[-2].minor.yy421, yymsp[0].minor.yy674); } - yymsp[-5].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy392, &yymsp[-2].minor.yy57, yymsp[0].minor.yy392); } + yymsp[-5].minor.yy392 = yylhsminor.yy392; break; case 124: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ case 127: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==127); -{ yylhsminor.yy530 = addNodeToList(pCxt, yymsp[-1].minor.yy530, yymsp[0].minor.yy674); } - yymsp[-1].minor.yy530 = yylhsminor.yy530; +{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-1].minor.yy600, yymsp[0].minor.yy392); } + yymsp[-1].minor.yy600 = yylhsminor.yy600; break; case 125: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options */ -{ yylhsminor.yy674 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy621, yymsp[-8].minor.yy674, yymsp[-6].minor.yy674, yymsp[-5].minor.yy530, yymsp[-2].minor.yy530, yymsp[0].minor.yy674); } - yymsp[-9].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy481, yymsp[-8].minor.yy392, yymsp[-6].minor.yy392, yymsp[-5].minor.yy600, yymsp[-2].minor.yy600, yymsp[0].minor.yy392); } + yymsp[-9].minor.yy392 = yylhsminor.yy392; break; case 128: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy674 = createDropTableClause(pCxt, yymsp[-1].minor.yy621, yymsp[0].minor.yy674); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createDropTableClause(pCxt, yymsp[-1].minor.yy481, yymsp[0].minor.yy392); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; case 129: /* specific_tags_opt ::= */ case 160: /* tags_def_opt ::= */ yytestcase(yyruleno==160); - case 409: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==409); - case 426: /* group_by_clause_opt ::= */ yytestcase(yyruleno==426); - case 438: /* order_by_clause_opt ::= */ yytestcase(yyruleno==438); -{ yymsp[1].minor.yy530 = NULL; } + case 412: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==412); + case 429: /* group_by_clause_opt ::= */ yytestcase(yyruleno==429); + case 445: /* order_by_clause_opt ::= */ yytestcase(yyruleno==445); +{ yymsp[1].minor.yy600 = NULL; } break; case 130: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy530 = yymsp[-1].minor.yy530; } +{ yymsp[-2].minor.yy600 = yymsp[-1].minor.yy600; } break; case 131: /* full_table_name ::= table_name */ -{ yylhsminor.yy674 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy421, NULL); } - yymsp[0].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy57, NULL); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; case 132: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy674 = createRealTableNode(pCxt, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy421, NULL); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createRealTableNode(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57, NULL); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 135: /* column_def ::= column_name type_name */ -{ yylhsminor.yy674 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy421, yymsp[0].minor.yy690, NULL); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy57, yymsp[0].minor.yy448, NULL); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; case 136: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy674 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy421, yymsp[-2].minor.yy690, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy57, yymsp[-2].minor.yy448, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; case 137: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_BOOL); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BOOL); } break; case 138: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_TINYINT); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; case 139: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_SMALLINT); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; case 140: /* type_name ::= INT */ case 141: /* type_name ::= INTEGER */ yytestcase(yyruleno==141); -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_INT); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_INT); } break; case 142: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_BIGINT); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; case 143: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_FLOAT); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; case 144: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_DOUBLE); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; case 145: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy690 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; case 146: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; case 147: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy690 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; case 148: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy690 = createDataType(TSDB_DATA_TYPE_UTINYINT); } +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; case 149: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy690 = createDataType(TSDB_DATA_TYPE_USMALLINT); } +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; case 150: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy690 = createDataType(TSDB_DATA_TYPE_UINT); } +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UINT); } break; case 151: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy690 = createDataType(TSDB_DATA_TYPE_UBIGINT); } +{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; case 152: /* type_name ::= JSON */ -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_JSON); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_JSON); } break; case 153: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy690 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; case 154: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; case 155: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_BLOB); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BLOB); } break; case 156: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy690 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; case 157: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy690 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 158: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy690 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-3].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 159: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy690 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-5].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 161: /* tags_def_opt ::= tags_def */ - case 345: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==345); - case 400: /* select_list ::= select_sublist */ yytestcase(yyruleno==400); -{ yylhsminor.yy530 = yymsp[0].minor.yy530; } - yymsp[0].minor.yy530 = yylhsminor.yy530; + case 348: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==348); + case 403: /* select_list ::= select_sublist */ yytestcase(yyruleno==403); +{ yylhsminor.yy600 = yymsp[0].minor.yy600; } + yymsp[0].minor.yy600 = yylhsminor.yy600; break; case 162: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy530 = yymsp[-1].minor.yy530; } +{ yymsp[-3].minor.yy600 = yymsp[-1].minor.yy600; } break; case 163: /* table_options ::= */ -{ yymsp[1].minor.yy674 = createDefaultTableOptions(pCxt); } +{ yymsp[1].minor.yy392 = createDefaultTableOptions(pCxt); } break; case 164: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy674 = setTableOption(pCxt, yymsp[-2].minor.yy674, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-2].minor.yy392, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 165: /* table_options ::= table_options MAX_DELAY duration_list */ -{ yylhsminor.yy674 = setTableOption(pCxt, yymsp[-2].minor.yy674, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy530); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-2].minor.yy392, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy600); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 166: /* table_options ::= table_options WATERMARK duration_list */ -{ yylhsminor.yy674 = setTableOption(pCxt, yymsp[-2].minor.yy674, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy530); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-2].minor.yy392, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy600); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 167: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ -{ yylhsminor.yy674 = setTableOption(pCxt, yymsp[-4].minor.yy674, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy530); } - yymsp[-4].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-4].minor.yy392, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy600); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 168: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy674 = setTableOption(pCxt, yymsp[-2].minor.yy674, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-2].minor.yy392, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 169: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy674 = setTableOption(pCxt, yymsp[-4].minor.yy674, TABLE_OPTION_SMA, yymsp[-1].minor.yy530); } - yymsp[-4].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-4].minor.yy392, TABLE_OPTION_SMA, yymsp[-1].minor.yy600); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 170: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy674 = createAlterTableOptions(pCxt); yylhsminor.yy674 = setTableOption(pCxt, yylhsminor.yy674, yymsp[0].minor.yy557.type, &yymsp[0].minor.yy557.val); } - yymsp[0].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createAlterTableOptions(pCxt); yylhsminor.yy392 = setTableOption(pCxt, yylhsminor.yy392, yymsp[0].minor.yy221.type, &yymsp[0].minor.yy221.val); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; case 171: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy674 = setTableOption(pCxt, yymsp[-1].minor.yy674, yymsp[0].minor.yy557.type, &yymsp[0].minor.yy557.val); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-1].minor.yy392, yymsp[0].minor.yy221.type, &yymsp[0].minor.yy221.val); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; case 172: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy557.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy557.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy221.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } break; case 173: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy557.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy557.val = yymsp[0].minor.yy0; } +{ yymsp[-1].minor.yy221.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } break; case 174: /* duration_list ::= duration_literal */ - case 319: /* expression_list ::= expression */ yytestcase(yyruleno==319); -{ yylhsminor.yy530 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy674)); } - yymsp[0].minor.yy530 = yylhsminor.yy530; + case 322: /* expression_list ::= expression */ yytestcase(yyruleno==322); +{ yylhsminor.yy600 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); } + yymsp[0].minor.yy600 = yylhsminor.yy600; break; case 175: /* duration_list ::= duration_list NK_COMMA duration_literal */ - case 320: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==320); -{ yylhsminor.yy530 = addNodeToList(pCxt, yymsp[-2].minor.yy530, releaseRawExprNode(pCxt, yymsp[0].minor.yy674)); } - yymsp[-2].minor.yy530 = yylhsminor.yy530; + case 323: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==323); +{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-2].minor.yy600, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); } + yymsp[-2].minor.yy600 = yylhsminor.yy600; break; case 178: /* rollup_func_name ::= function_name */ -{ yylhsminor.yy674 = createFunctionNode(pCxt, &yymsp[0].minor.yy421, NULL); } - yymsp[0].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createFunctionNode(pCxt, &yymsp[0].minor.yy57, NULL); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; case 179: /* rollup_func_name ::= FIRST */ case 180: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==180); -{ yylhsminor.yy674 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } - yymsp[0].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; case 183: /* col_name ::= column_name */ -{ yylhsminor.yy674 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy421); } - yymsp[0].minor.yy674 = yylhsminor.yy674; +{ yylhsminor.yy392 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy57); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; case 184: /* cmd ::= SHOW DNODES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); } break; case 185: /* cmd ::= SHOW USERS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); } break; case 186: /* cmd ::= SHOW DATABASES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); } break; case 187: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy674, yymsp[0].minor.yy674); } +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy392, yymsp[0].minor.yy392, OP_TYPE_LIKE); } break; case 188: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy674, yymsp[0].minor.yy674); } +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy392, yymsp[0].minor.yy392, OP_TYPE_LIKE); } break; case 189: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy674, NULL); } +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy392, NULL, OP_TYPE_LIKE); } break; case 190: /* cmd ::= SHOW MNODES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT); } break; case 191: /* cmd ::= SHOW MODULES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT); } break; case 192: /* cmd ::= SHOW QNODES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT); } break; case 193: /* cmd ::= SHOW FUNCTIONS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT); } break; case 194: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy674, yymsp[0].minor.yy674); } +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy392, yymsp[-1].minor.yy392, OP_TYPE_EQUAL); } break; case 195: /* cmd ::= SHOW STREAMS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT); } break; case 196: /* cmd ::= SHOW ACCOUNTS */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } break; case 197: /* cmd ::= SHOW APPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT); } break; case 198: /* cmd ::= SHOW CONNECTIONS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT); } break; case 199: /* cmd ::= SHOW LICENCE */ case 200: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==200); -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT); } break; case 201: /* cmd ::= SHOW CREATE DATABASE db_name */ -{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy421); } +{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy57); } break; case 202: /* cmd ::= SHOW CREATE TABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy674); } +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy392); } break; case 203: /* cmd ::= SHOW CREATE STABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy674); } +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy392); } break; case 204: /* cmd ::= SHOW QUERIES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); } break; case 205: /* cmd ::= SHOW SCORES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); } break; case 206: /* cmd ::= SHOW TOPICS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); } break; case 207: /* cmd ::= SHOW VARIABLES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } break; - case 208: /* cmd ::= SHOW BNODES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT, NULL, NULL); } + case 208: /* cmd ::= SHOW LOCAL VARIABLES */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); } break; - case 209: /* cmd ::= SHOW SNODES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT, NULL, NULL); } + case 209: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ +{ pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[-1].minor.yy0)); } break; - case 210: /* cmd ::= SHOW CLUSTER */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT, NULL, NULL); } + case 210: /* cmd ::= SHOW BNODES */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); } break; - case 211: /* cmd ::= SHOW TRANSACTIONS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT, NULL, NULL); } + case 211: /* cmd ::= SHOW SNODES */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); } break; - case 212: /* db_name_cond_opt ::= */ - case 217: /* from_db_opt ::= */ yytestcase(yyruleno==217); -{ yymsp[1].minor.yy674 = createDefaultDatabaseCondValue(pCxt); } + case 212: /* cmd ::= SHOW CLUSTER */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); } break; - case 213: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy421); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; + case 213: /* cmd ::= SHOW TRANSACTIONS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); } break; - case 214: /* like_pattern_opt ::= */ - case 222: /* index_options ::= */ yytestcase(yyruleno==222); - case 251: /* into_opt ::= */ yytestcase(yyruleno==251); - case 407: /* where_clause_opt ::= */ yytestcase(yyruleno==407); - case 411: /* twindow_clause_opt ::= */ yytestcase(yyruleno==411); - case 416: /* sliding_opt ::= */ yytestcase(yyruleno==416); - case 418: /* fill_opt ::= */ yytestcase(yyruleno==418); - case 430: /* having_clause_opt ::= */ yytestcase(yyruleno==430); - case 440: /* slimit_clause_opt ::= */ yytestcase(yyruleno==440); - case 444: /* limit_clause_opt ::= */ yytestcase(yyruleno==444); -{ yymsp[1].minor.yy674 = NULL; } + case 214: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ +{ pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy392); } break; - case 215: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + case 215: /* db_name_cond_opt ::= */ + case 220: /* from_db_opt ::= */ yytestcase(yyruleno==220); +{ yymsp[1].minor.yy392 = createDefaultDatabaseCondValue(pCxt); } break; - case 216: /* table_name_cond ::= table_name */ -{ yylhsminor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy421); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 216: /* db_name_cond_opt ::= db_name NK_DOT */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy57); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 218: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy421); } + case 217: /* like_pattern_opt ::= */ + case 225: /* index_options ::= */ yytestcase(yyruleno==225); + case 254: /* into_opt ::= */ yytestcase(yyruleno==254); + case 410: /* where_clause_opt ::= */ yytestcase(yyruleno==410); + case 414: /* twindow_clause_opt ::= */ yytestcase(yyruleno==414); + case 419: /* sliding_opt ::= */ yytestcase(yyruleno==419); + case 421: /* fill_opt ::= */ yytestcase(yyruleno==421); + case 433: /* having_clause_opt ::= */ yytestcase(yyruleno==433); + case 435: /* range_opt ::= */ yytestcase(yyruleno==435); + case 437: /* every_opt ::= */ yytestcase(yyruleno==437); + case 447: /* slimit_clause_opt ::= */ yytestcase(yyruleno==447); + case 451: /* limit_clause_opt ::= */ yytestcase(yyruleno==451); +{ yymsp[1].minor.yy392 = NULL; } break; - case 219: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy621, &yymsp[-3].minor.yy421, &yymsp[-1].minor.yy421, NULL, yymsp[0].minor.yy674); } + case 218: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 220: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy621, &yymsp[-5].minor.yy421, &yymsp[-3].minor.yy421, yymsp[-1].minor.yy530, NULL); } + case 219: /* table_name_cond ::= table_name */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy57); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 221: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy621, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy421); } + case 221: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy57); } break; - case 223: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy674 = createIndexOption(pCxt, yymsp[-6].minor.yy530, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), NULL, yymsp[0].minor.yy674); } + case 222: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy481, &yymsp[-3].minor.yy57, &yymsp[-1].minor.yy57, NULL, yymsp[0].minor.yy392); } break; - case 224: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ -{ yymsp[-10].minor.yy674 = createIndexOption(pCxt, yymsp[-8].minor.yy530, releaseRawExprNode(pCxt, yymsp[-4].minor.yy674), releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), yymsp[0].minor.yy674); } + case 223: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy481, &yymsp[-5].minor.yy57, &yymsp[-3].minor.yy57, yymsp[-1].minor.yy600, NULL); } break; - case 227: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy674 = createFunctionNode(pCxt, &yymsp[-3].minor.yy421, yymsp[-1].minor.yy530); } - yymsp[-3].minor.yy674 = yylhsminor.yy674; + case 224: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy481, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57); } break; - case 228: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy621, &yymsp[-2].minor.yy421, yymsp[0].minor.yy674, NULL, NULL); } + case 226: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ +{ yymsp[-8].minor.yy392 = createIndexOption(pCxt, yymsp[-6].minor.yy600, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), NULL, yymsp[0].minor.yy392); } break; - case 229: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-4].minor.yy621, &yymsp[-3].minor.yy421, NULL, &yymsp[0].minor.yy421, NULL); } + case 227: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ +{ yymsp[-10].minor.yy392 = createIndexOption(pCxt, yymsp[-8].minor.yy600, releaseRawExprNode(pCxt, yymsp[-4].minor.yy392), releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), yymsp[0].minor.yy392); } break; - case 230: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-4].minor.yy621, &yymsp[-3].minor.yy421, NULL, NULL, yymsp[0].minor.yy674); } + case 230: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy392 = createFunctionNode(pCxt, &yymsp[-3].minor.yy57, yymsp[-1].minor.yy600); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 231: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy621, &yymsp[0].minor.yy421); } + case 231: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy481, &yymsp[-2].minor.yy57, yymsp[0].minor.yy392, NULL, NULL); } break; - case 232: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ -{ pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy621, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy421); } + case 232: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-4].minor.yy481, &yymsp[-3].minor.yy57, NULL, &yymsp[0].minor.yy57, NULL); } break; - case 233: /* cmd ::= DESC full_table_name */ - case 234: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==234); -{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy674); } + case 233: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-4].minor.yy481, &yymsp[-3].minor.yy57, NULL, NULL, yymsp[0].minor.yy392); } break; - case 235: /* cmd ::= RESET QUERY CACHE */ + case 234: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy481, &yymsp[0].minor.yy57); } + break; + case 235: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ +{ pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy481, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57); } + break; + case 236: /* cmd ::= DESC full_table_name */ + case 237: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==237); +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy392); } + break; + case 238: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; - case 236: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ -{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy621, yymsp[-1].minor.yy674, yymsp[0].minor.yy674); } + case 239: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy481, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } break; - case 238: /* analyze_opt ::= ANALYZE */ - case 246: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==246); - case 397: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==397); -{ yymsp[0].minor.yy621 = true; } + case 241: /* analyze_opt ::= ANALYZE */ + case 249: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==249); + case 400: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==400); +{ yymsp[0].minor.yy481 = true; } break; - case 239: /* explain_options ::= */ -{ yymsp[1].minor.yy674 = createDefaultExplainOptions(pCxt); } + case 242: /* explain_options ::= */ +{ yymsp[1].minor.yy392 = createDefaultExplainOptions(pCxt); } break; - case 240: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy674 = setExplainVerbose(pCxt, yymsp[-2].minor.yy674, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 243: /* explain_options ::= explain_options VERBOSE NK_BOOL */ +{ yylhsminor.yy392 = setExplainVerbose(pCxt, yymsp[-2].minor.yy392, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 241: /* explain_options ::= explain_options RATIO NK_FLOAT */ -{ yylhsminor.yy674 = setExplainRatio(pCxt, yymsp[-2].minor.yy674, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 244: /* explain_options ::= explain_options RATIO NK_FLOAT */ +{ yylhsminor.yy392 = setExplainRatio(pCxt, yymsp[-2].minor.yy392, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 242: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ -{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy530); } + case 245: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ +{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy600); } break; - case 243: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ -{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy621, yymsp[-8].minor.yy621, &yymsp[-5].minor.yy421, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy690, yymsp[0].minor.yy42); } + case 246: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ +{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy481, yymsp[-8].minor.yy481, &yymsp[-5].minor.yy57, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy448, yymsp[0].minor.yy228); } break; - case 244: /* cmd ::= DROP FUNCTION exists_opt function_name */ -{ pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy621, &yymsp[0].minor.yy421); } + case 247: /* cmd ::= DROP FUNCTION exists_opt function_name */ +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy481, &yymsp[0].minor.yy57); } break; - case 247: /* bufsize_opt ::= */ -{ yymsp[1].minor.yy42 = 0; } + case 250: /* bufsize_opt ::= */ +{ yymsp[1].minor.yy228 = 0; } break; - case 248: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy42 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } + case 251: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ +{ yymsp[-1].minor.yy228 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 249: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ -{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy621, &yymsp[-4].minor.yy421, yymsp[-2].minor.yy674, yymsp[-3].minor.yy674, yymsp[0].minor.yy674); } + case 252: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ +{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy481, &yymsp[-4].minor.yy57, yymsp[-2].minor.yy392, yymsp[-3].minor.yy392, yymsp[0].minor.yy392); } break; - case 250: /* cmd ::= DROP STREAM exists_opt stream_name */ -{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy621, &yymsp[0].minor.yy421); } + case 253: /* cmd ::= DROP STREAM exists_opt stream_name */ +{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy481, &yymsp[0].minor.yy57); } break; - case 252: /* into_opt ::= INTO full_table_name */ - case 378: /* from_clause ::= FROM table_reference_list */ yytestcase(yyruleno==378); - case 408: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==408); - case 431: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==431); -{ yymsp[-1].minor.yy674 = yymsp[0].minor.yy674; } + case 255: /* into_opt ::= INTO full_table_name */ + case 381: /* from_clause ::= FROM table_reference_list */ yytestcase(yyruleno==381); + case 411: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==411); + case 434: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==434); +{ yymsp[-1].minor.yy392 = yymsp[0].minor.yy392; } break; - case 253: /* stream_options ::= */ -{ yymsp[1].minor.yy674 = createStreamOptions(pCxt); } + case 256: /* stream_options ::= */ +{ yymsp[1].minor.yy392 = createStreamOptions(pCxt); } break; - case 254: /* stream_options ::= stream_options TRIGGER AT_ONCE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy674)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy674 = yymsp[-2].minor.yy674; } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 257: /* stream_options ::= stream_options TRIGGER AT_ONCE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy392)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 255: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy674)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy674 = yymsp[-2].minor.yy674; } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 258: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy392)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 256: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ -{ ((SStreamOptions*)yymsp[-3].minor.yy674)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)yymsp[-3].minor.yy674)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy674); yylhsminor.yy674 = yymsp[-3].minor.yy674; } - yymsp[-3].minor.yy674 = yylhsminor.yy674; + case 259: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ +{ ((SStreamOptions*)yymsp[-3].minor.yy392)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)yymsp[-3].minor.yy392)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy392); yylhsminor.yy392 = yymsp[-3].minor.yy392; } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 257: /* stream_options ::= stream_options WATERMARK duration_literal */ -{ ((SStreamOptions*)yymsp[-2].minor.yy674)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy674); yylhsminor.yy674 = yymsp[-2].minor.yy674; } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 260: /* stream_options ::= stream_options WATERMARK duration_literal */ +{ ((SStreamOptions*)yymsp[-2].minor.yy392)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy392); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 258: /* cmd ::= KILL CONNECTION NK_INTEGER */ + case 261: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } break; - case 259: /* cmd ::= KILL QUERY NK_STRING */ + case 262: /* cmd ::= KILL QUERY NK_STRING */ { pCxt->pRootNode = createKillQueryStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 260: /* cmd ::= KILL TRANSACTION NK_INTEGER */ + case 263: /* cmd ::= KILL TRANSACTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_TRANSACTION_STMT, &yymsp[0].minor.yy0); } break; - case 261: /* cmd ::= BALANCE VGROUP */ + case 264: /* cmd ::= BALANCE VGROUP */ { pCxt->pRootNode = createBalanceVgroupStmt(pCxt); } break; - case 262: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + case 265: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 263: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ -{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy530); } + case 266: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy600); } break; - case 264: /* cmd ::= SPLIT VGROUP NK_INTEGER */ + case 267: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 265: /* dnode_list ::= DNODE NK_INTEGER */ -{ yymsp[-1].minor.yy530 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + case 268: /* dnode_list ::= DNODE NK_INTEGER */ +{ yymsp[-1].minor.yy600 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } break; - case 267: /* cmd ::= SYNCDB db_name REPLICA */ -{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy421); } + case 270: /* cmd ::= SYNCDB db_name REPLICA */ +{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy57); } break; - case 268: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ -{ pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy674, yymsp[0].minor.yy674); } + case 271: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ +{ pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } break; - case 270: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy674 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 273: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 271: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy674 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 274: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 272: /* literal ::= NK_STRING */ -{ yylhsminor.yy674 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 275: /* literal ::= NK_STRING */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 273: /* literal ::= NK_BOOL */ -{ yylhsminor.yy674 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 276: /* literal ::= NK_BOOL */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 274: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; + case 277: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 275: /* literal ::= duration_literal */ - case 285: /* signed_literal ::= signed */ yytestcase(yyruleno==285); - case 305: /* expression ::= literal */ yytestcase(yyruleno==305); - case 306: /* expression ::= pseudo_column */ yytestcase(yyruleno==306); - case 307: /* expression ::= column_reference */ yytestcase(yyruleno==307); - case 308: /* expression ::= function_expression */ yytestcase(yyruleno==308); - case 309: /* expression ::= subquery */ yytestcase(yyruleno==309); - case 334: /* function_expression ::= literal_func */ yytestcase(yyruleno==334); - case 370: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==370); - case 374: /* boolean_primary ::= predicate */ yytestcase(yyruleno==374); - case 376: /* common_expression ::= expression */ yytestcase(yyruleno==376); - case 377: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==377); - case 379: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==379); - case 381: /* table_reference ::= table_primary */ yytestcase(yyruleno==381); - case 382: /* table_reference ::= joined_table */ yytestcase(yyruleno==382); - case 386: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==386); - case 433: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==433); - case 436: /* query_primary ::= query_specification */ yytestcase(yyruleno==436); -{ yylhsminor.yy674 = yymsp[0].minor.yy674; } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 278: /* literal ::= duration_literal */ + case 288: /* signed_literal ::= signed */ yytestcase(yyruleno==288); + case 308: /* expression ::= literal */ yytestcase(yyruleno==308); + case 309: /* expression ::= pseudo_column */ yytestcase(yyruleno==309); + case 310: /* expression ::= column_reference */ yytestcase(yyruleno==310); + case 311: /* expression ::= function_expression */ yytestcase(yyruleno==311); + case 312: /* expression ::= subquery */ yytestcase(yyruleno==312); + case 337: /* function_expression ::= literal_func */ yytestcase(yyruleno==337); + case 373: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==373); + case 377: /* boolean_primary ::= predicate */ yytestcase(yyruleno==377); + case 379: /* common_expression ::= expression */ yytestcase(yyruleno==379); + case 380: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==380); + case 382: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==382); + case 384: /* table_reference ::= table_primary */ yytestcase(yyruleno==384); + case 385: /* table_reference ::= joined_table */ yytestcase(yyruleno==385); + case 389: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==389); + case 440: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==440); + case 443: /* query_primary ::= query_specification */ yytestcase(yyruleno==443); +{ yylhsminor.yy392 = yymsp[0].minor.yy392; } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 276: /* literal ::= NULL */ -{ yylhsminor.yy674 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 279: /* literal ::= NULL */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 277: /* literal ::= NK_QUESTION */ -{ yylhsminor.yy674 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 280: /* literal ::= NK_QUESTION */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 278: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy674 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 281: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 279: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 282: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 280: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 283: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; - case 281: /* signed ::= NK_MINUS NK_INTEGER */ + case 284: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 282: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 285: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 283: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 286: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 284: /* signed ::= NK_MINUS NK_FLOAT */ + case 287: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 286: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 289: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 287: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 290: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 288: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + case 291: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 289: /* signed_literal ::= duration_literal */ - case 291: /* signed_literal ::= literal_func */ yytestcase(yyruleno==291); - case 348: /* star_func_para ::= expression */ yytestcase(yyruleno==348); - case 403: /* select_item ::= common_expression */ yytestcase(yyruleno==403); - case 449: /* search_condition ::= common_expression */ yytestcase(yyruleno==449); -{ yylhsminor.yy674 = releaseRawExprNode(pCxt, yymsp[0].minor.yy674); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 292: /* signed_literal ::= duration_literal */ + case 294: /* signed_literal ::= literal_func */ yytestcase(yyruleno==294); + case 351: /* star_func_para ::= expression */ yytestcase(yyruleno==351); + case 406: /* select_item ::= common_expression */ yytestcase(yyruleno==406); + case 456: /* search_condition ::= common_expression */ yytestcase(yyruleno==456); +{ yylhsminor.yy392 = releaseRawExprNode(pCxt, yymsp[0].minor.yy392); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 290: /* signed_literal ::= NULL */ -{ yylhsminor.yy674 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 293: /* signed_literal ::= NULL */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 310: /* expression ::= NK_LP expression NK_RP */ - case 375: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==375); -{ yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy674)); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 313: /* expression ::= NK_LP expression NK_RP */ + case 378: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==378); +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 311: /* expression ::= NK_PLUS expression */ + case 314: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy674)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 312: /* expression ::= NK_MINUS expression */ + case 315: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy674), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy392), NULL)); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 313: /* expression ::= expression NK_PLUS expression */ + case 316: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy674); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 314: /* expression ::= expression NK_MINUS expression */ + case 317: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy674); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 315: /* expression ::= expression NK_STAR expression */ + case 318: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy674); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 316: /* expression ::= expression NK_SLASH expression */ + case 319: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy674); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 317: /* expression ::= expression NK_REM expression */ + case 320: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy674); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 318: /* expression ::= column_reference NK_ARROW NK_STRING */ + case 321: /* expression ::= column_reference NK_ARROW NK_STRING */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 321: /* column_reference ::= column_name */ -{ yylhsminor.yy674 = createRawExprNode(pCxt, &yymsp[0].minor.yy421, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy421)); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 324: /* column_reference ::= column_name */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy57, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy57)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 322: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy421, createColumnNode(pCxt, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy421)); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 325: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57, createColumnNode(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57)); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 323: /* pseudo_column ::= ROWTS */ - case 324: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==324); - case 326: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==326); - case 327: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==327); - case 328: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==328); - case 329: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==329); - case 330: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==330); - case 336: /* literal_func ::= NOW */ yytestcase(yyruleno==336); -{ yylhsminor.yy674 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy674 = yylhsminor.yy674; + case 326: /* pseudo_column ::= ROWTS */ + case 327: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==327); + case 329: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==329); + case 330: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==330); + case 331: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==331); + case 332: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==332); + case 333: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==333); + case 339: /* literal_func ::= NOW */ yytestcase(yyruleno==339); +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 325: /* pseudo_column ::= table_name NK_DOT TBNAME */ -{ yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy421)))); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 328: /* pseudo_column ::= table_name NK_DOT TBNAME */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy57)))); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 331: /* function_expression ::= function_name NK_LP expression_list NK_RP */ - case 332: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==332); -{ yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy421, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy421, yymsp[-1].minor.yy530)); } - yymsp[-3].minor.yy674 = yylhsminor.yy674; + case 334: /* function_expression ::= function_name NK_LP expression_list NK_RP */ + case 335: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==335); +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy57, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy57, yymsp[-1].minor.yy600)); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 333: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ -{ yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy674), yymsp[-1].minor.yy690)); } - yymsp[-5].minor.yy674 = yylhsminor.yy674; + case 336: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), yymsp[-1].minor.yy448)); } + yymsp[-5].minor.yy392 = yylhsminor.yy392; break; - case 335: /* literal_func ::= noarg_func NK_LP NK_RP */ -{ yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy421, NULL)); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 338: /* literal_func ::= noarg_func NK_LP NK_RP */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy57, NULL)); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 344: /* star_func_para_list ::= NK_STAR */ -{ yylhsminor.yy530 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy530 = yylhsminor.yy530; + case 347: /* star_func_para_list ::= NK_STAR */ +{ yylhsminor.yy600 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy600 = yylhsminor.yy600; break; - case 349: /* star_func_para ::= table_name NK_DOT NK_STAR */ - case 406: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==406); -{ yylhsminor.yy674 = createColumnNode(pCxt, &yymsp[-2].minor.yy421, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 352: /* star_func_para ::= table_name NK_DOT NK_STAR */ + case 409: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==409); +{ yylhsminor.yy392 = createColumnNode(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 350: /* predicate ::= expression compare_op expression */ - case 355: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==355); + case 353: /* predicate ::= expression compare_op expression */ + case 358: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==358); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy674); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy28, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy324, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 351: /* predicate ::= expression BETWEEN expression AND expression */ + case 354: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy674); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy674), releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy392), releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-4].minor.yy674 = yylhsminor.yy674; + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; - case 352: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 355: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy674); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy674), releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy392), releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-5].minor.yy674 = yylhsminor.yy674; + yymsp[-5].minor.yy392 = yylhsminor.yy392; break; - case 353: /* predicate ::= expression IS NULL */ + case 356: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), NULL)); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 354: /* predicate ::= expression IS NOT NULL */ + case 357: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy674), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), NULL)); } - yymsp[-3].minor.yy674 = yylhsminor.yy674; + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 356: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy28 = OP_TYPE_LOWER_THAN; } + case 359: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy324 = OP_TYPE_LOWER_THAN; } break; - case 357: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy28 = OP_TYPE_GREATER_THAN; } + case 360: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy324 = OP_TYPE_GREATER_THAN; } break; - case 358: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy28 = OP_TYPE_LOWER_EQUAL; } + case 361: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy324 = OP_TYPE_LOWER_EQUAL; } break; - case 359: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy28 = OP_TYPE_GREATER_EQUAL; } + case 362: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy324 = OP_TYPE_GREATER_EQUAL; } break; - case 360: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy28 = OP_TYPE_NOT_EQUAL; } + case 363: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy324 = OP_TYPE_NOT_EQUAL; } break; - case 361: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy28 = OP_TYPE_EQUAL; } + case 364: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy324 = OP_TYPE_EQUAL; } break; - case 362: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy28 = OP_TYPE_LIKE; } + case 365: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy324 = OP_TYPE_LIKE; } break; - case 363: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy28 = OP_TYPE_NOT_LIKE; } + case 366: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy324 = OP_TYPE_NOT_LIKE; } break; - case 364: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy28 = OP_TYPE_MATCH; } + case 367: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy324 = OP_TYPE_MATCH; } break; - case 365: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy28 = OP_TYPE_NMATCH; } + case 368: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy324 = OP_TYPE_NMATCH; } break; - case 366: /* compare_op ::= CONTAINS */ -{ yymsp[0].minor.yy28 = OP_TYPE_JSON_CONTAINS; } + case 369: /* compare_op ::= CONTAINS */ +{ yymsp[0].minor.yy324 = OP_TYPE_JSON_CONTAINS; } break; - case 367: /* in_op ::= IN */ -{ yymsp[0].minor.yy28 = OP_TYPE_IN; } + case 370: /* in_op ::= IN */ +{ yymsp[0].minor.yy324 = OP_TYPE_IN; } break; - case 368: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy28 = OP_TYPE_NOT_IN; } + case 371: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy324 = OP_TYPE_NOT_IN; } break; - case 369: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy530)); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 372: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy600)); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 371: /* boolean_value_expression ::= NOT boolean_primary */ + case 374: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy674), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy392), NULL)); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 372: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 375: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy674); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 373: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 376: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy674); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy674); - yylhsminor.yy674 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 380: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy674 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy674, yymsp[0].minor.yy674, NULL); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 383: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy392 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy392, yymsp[0].minor.yy392, NULL); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 383: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy674 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy421, &yymsp[0].minor.yy421); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; + case 386: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy392 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy57, &yymsp[0].minor.yy57); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 384: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy674 = createRealTableNode(pCxt, &yymsp[-3].minor.yy421, &yymsp[-1].minor.yy421, &yymsp[0].minor.yy421); } - yymsp[-3].minor.yy674 = yylhsminor.yy674; + case 387: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy392 = createRealTableNode(pCxt, &yymsp[-3].minor.yy57, &yymsp[-1].minor.yy57, &yymsp[0].minor.yy57); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 385: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy674 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy674), &yymsp[0].minor.yy421); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; + case 388: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy392 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392), &yymsp[0].minor.yy57); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 387: /* alias_opt ::= */ -{ yymsp[1].minor.yy421 = nil_token; } + case 390: /* alias_opt ::= */ +{ yymsp[1].minor.yy57 = nil_token; } break; - case 388: /* alias_opt ::= table_alias */ -{ yylhsminor.yy421 = yymsp[0].minor.yy421; } - yymsp[0].minor.yy421 = yylhsminor.yy421; + case 391: /* alias_opt ::= table_alias */ +{ yylhsminor.yy57 = yymsp[0].minor.yy57; } + yymsp[0].minor.yy57 = yylhsminor.yy57; break; - case 389: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy421 = yymsp[0].minor.yy421; } + case 392: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy57 = yymsp[0].minor.yy57; } break; - case 390: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 391: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==391); -{ yymsp[-2].minor.yy674 = yymsp[-1].minor.yy674; } + case 393: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 394: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==394); +{ yymsp[-2].minor.yy392 = yymsp[-1].minor.yy392; } break; - case 392: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy674 = createJoinTableNode(pCxt, yymsp[-4].minor.yy636, yymsp[-5].minor.yy674, yymsp[-2].minor.yy674, yymsp[0].minor.yy674); } - yymsp[-5].minor.yy674 = yylhsminor.yy674; + case 395: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy392 = createJoinTableNode(pCxt, yymsp[-4].minor.yy204, yymsp[-5].minor.yy392, yymsp[-2].minor.yy392, yymsp[0].minor.yy392); } + yymsp[-5].minor.yy392 = yylhsminor.yy392; break; - case 393: /* join_type ::= */ -{ yymsp[1].minor.yy636 = JOIN_TYPE_INNER; } + case 396: /* join_type ::= */ +{ yymsp[1].minor.yy204 = JOIN_TYPE_INNER; } break; - case 394: /* join_type ::= INNER */ -{ yymsp[0].minor.yy636 = JOIN_TYPE_INNER; } + case 397: /* join_type ::= INNER */ +{ yymsp[0].minor.yy204 = JOIN_TYPE_INNER; } break; - case 395: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 398: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-8].minor.yy674 = createSelectStmt(pCxt, yymsp[-7].minor.yy621, yymsp[-6].minor.yy530, yymsp[-5].minor.yy674); - yymsp[-8].minor.yy674 = addWhereClause(pCxt, yymsp[-8].minor.yy674, yymsp[-4].minor.yy674); - yymsp[-8].minor.yy674 = addPartitionByClause(pCxt, yymsp[-8].minor.yy674, yymsp[-3].minor.yy530); - yymsp[-8].minor.yy674 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy674, yymsp[-2].minor.yy674); - yymsp[-8].minor.yy674 = addGroupByClause(pCxt, yymsp[-8].minor.yy674, yymsp[-1].minor.yy530); - yymsp[-8].minor.yy674 = addHavingClause(pCxt, yymsp[-8].minor.yy674, yymsp[0].minor.yy674); + yymsp[-11].minor.yy392 = createSelectStmt(pCxt, yymsp[-10].minor.yy481, yymsp[-9].minor.yy600, yymsp[-8].minor.yy392); + yymsp[-11].minor.yy392 = addWhereClause(pCxt, yymsp[-11].minor.yy392, yymsp[-7].minor.yy392); + yymsp[-11].minor.yy392 = addPartitionByClause(pCxt, yymsp[-11].minor.yy392, yymsp[-6].minor.yy600); + yymsp[-11].minor.yy392 = addWindowClauseClause(pCxt, yymsp[-11].minor.yy392, yymsp[-2].minor.yy392); + yymsp[-11].minor.yy392 = addGroupByClause(pCxt, yymsp[-11].minor.yy392, yymsp[-1].minor.yy600); + yymsp[-11].minor.yy392 = addHavingClause(pCxt, yymsp[-11].minor.yy392, yymsp[0].minor.yy392); + yymsp[-11].minor.yy392 = addRangeClause(pCxt, yymsp[-11].minor.yy392, yymsp[-5].minor.yy392); + yymsp[-11].minor.yy392 = addEveryClause(pCxt, yymsp[-11].minor.yy392, yymsp[-4].minor.yy392); + yymsp[-11].minor.yy392 = addFillClause(pCxt, yymsp[-11].minor.yy392, yymsp[-3].minor.yy392); } break; - case 398: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy621 = false; } + case 401: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy481 = false; } break; - case 399: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy530 = NULL; } + case 402: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy600 = NULL; } break; - case 404: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy674 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy674), &yymsp[0].minor.yy421); } - yymsp[-1].minor.yy674 = yylhsminor.yy674; + case 407: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy392 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392), &yymsp[0].minor.yy57); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 405: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy674 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), &yymsp[0].minor.yy421); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 408: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy392 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), &yymsp[0].minor.yy57); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 410: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 427: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==427); - case 439: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==439); -{ yymsp[-2].minor.yy530 = yymsp[0].minor.yy530; } + case 413: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 430: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==430); + case 446: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==446); +{ yymsp[-2].minor.yy600 = yymsp[0].minor.yy600; } break; - case 412: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy674 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy674), releaseRawExprNode(pCxt, yymsp[-1].minor.yy674)); } + case 415: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy392 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } break; - case 413: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ -{ yymsp[-3].minor.yy674 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy674)); } + case 416: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ +{ yymsp[-3].minor.yy392 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } break; - case 414: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy674 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy674), NULL, yymsp[-1].minor.yy674, yymsp[0].minor.yy674); } + case 417: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy392 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), NULL, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } break; - case 415: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy674 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy674), releaseRawExprNode(pCxt, yymsp[-3].minor.yy674), yymsp[-1].minor.yy674, yymsp[0].minor.yy674); } + case 418: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy392 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy392), releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } break; - case 417: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy674 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy674); } + case 420: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + case 438: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==438); +{ yymsp[-3].minor.yy392 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy392); } break; - case 419: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy674 = createFillNode(pCxt, yymsp[-1].minor.yy320, NULL); } + case 422: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy392 = createFillNode(pCxt, yymsp[-1].minor.yy270, NULL); } break; - case 420: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy674 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy530)); } + case 423: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy392 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy600)); } break; - case 421: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy320 = FILL_MODE_NONE; } + case 424: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy270 = FILL_MODE_NONE; } break; - case 422: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy320 = FILL_MODE_PREV; } + case 425: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy270 = FILL_MODE_PREV; } break; - case 423: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy320 = FILL_MODE_NULL; } + case 426: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy270 = FILL_MODE_NULL; } break; - case 424: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy320 = FILL_MODE_LINEAR; } + case 427: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy270 = FILL_MODE_LINEAR; } break; - case 425: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy320 = FILL_MODE_NEXT; } + case 428: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy270 = FILL_MODE_NEXT; } break; - case 428: /* group_by_list ::= expression */ -{ yylhsminor.yy530 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); } - yymsp[0].minor.yy530 = yylhsminor.yy530; + case 431: /* group_by_list ::= expression */ +{ yylhsminor.yy600 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } + yymsp[0].minor.yy600 = yylhsminor.yy600; break; - case 429: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy530 = addNodeToList(pCxt, yymsp[-2].minor.yy530, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy674))); } - yymsp[-2].minor.yy530 = yylhsminor.yy530; + case 432: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-2].minor.yy600, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } + yymsp[-2].minor.yy600 = yylhsminor.yy600; break; - case 432: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 436: /* range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ +{ yymsp[-5].minor.yy392 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } + break; + case 439: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy674 = addOrderByClause(pCxt, yymsp[-3].minor.yy674, yymsp[-2].minor.yy530); - yylhsminor.yy674 = addSlimitClause(pCxt, yylhsminor.yy674, yymsp[-1].minor.yy674); - yylhsminor.yy674 = addLimitClause(pCxt, yylhsminor.yy674, yymsp[0].minor.yy674); + yylhsminor.yy392 = addOrderByClause(pCxt, yymsp[-3].minor.yy392, yymsp[-2].minor.yy600); + yylhsminor.yy392 = addSlimitClause(pCxt, yylhsminor.yy392, yymsp[-1].minor.yy392); + yylhsminor.yy392 = addLimitClause(pCxt, yylhsminor.yy392, yymsp[0].minor.yy392); } - yymsp[-3].minor.yy674 = yylhsminor.yy674; + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 434: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy674 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy674, yymsp[0].minor.yy674); } - yymsp[-3].minor.yy674 = yylhsminor.yy674; + case 441: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy392 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy392, yymsp[0].minor.yy392); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 435: /* query_expression_body ::= query_expression_body UNION query_expression_body */ -{ yylhsminor.yy674 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy674, yymsp[0].minor.yy674); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 442: /* query_expression_body ::= query_expression_body UNION query_expression_body */ +{ yylhsminor.yy392 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy392, yymsp[0].minor.yy392); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 437: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ -{ yymsp[-5].minor.yy674 = yymsp[-4].minor.yy674; } - yy_destructor(yypParser,351,&yymsp[-3].minor); - yy_destructor(yypParser,352,&yymsp[-2].minor); - yy_destructor(yypParser,353,&yymsp[-1].minor); + case 444: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ +{ yymsp[-5].minor.yy392 = yymsp[-4].minor.yy392; } + yy_destructor(yypParser,356,&yymsp[-3].minor); + yy_destructor(yypParser,357,&yymsp[-2].minor); + yy_destructor(yypParser,358,&yymsp[-1].minor); break; - case 441: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 445: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==445); -{ yymsp[-1].minor.yy674 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 448: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 452: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==452); +{ yymsp[-1].minor.yy392 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 442: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 446: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==446); -{ yymsp[-3].minor.yy674 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 449: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 453: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==453); +{ yymsp[-3].minor.yy392 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 443: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 447: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==447); -{ yymsp[-3].minor.yy674 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 450: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 454: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==454); +{ yymsp[-3].minor.yy392 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 448: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy674 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy674); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 455: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy392); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 452: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy674 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy674), yymsp[-1].minor.yy610, yymsp[0].minor.yy107); } - yymsp[-2].minor.yy674 = yylhsminor.yy674; + case 459: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy392 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), yymsp[-1].minor.yy162, yymsp[0].minor.yy529); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 453: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy610 = ORDER_ASC; } + case 460: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy162 = ORDER_ASC; } break; - case 454: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy610 = ORDER_ASC; } + case 461: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy162 = ORDER_ASC; } break; - case 455: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy610 = ORDER_DESC; } + case 462: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy162 = ORDER_DESC; } break; - case 456: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy107 = NULL_ORDER_DEFAULT; } + case 463: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy529 = NULL_ORDER_DEFAULT; } break; - case 457: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy107 = NULL_ORDER_FIRST; } + case 464: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy529 = NULL_ORDER_FIRST; } break; - case 458: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy107 = NULL_ORDER_LAST; } + case 465: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy529 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index b0c6181264..0213a3a854 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -93,6 +93,16 @@ void generateInformationSchema(MockCatalogService* mcs) { .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); builder.done(); } + { + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "configs", TSDB_SYSTEM_TABLE, 1) + .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_CONFIG_OPTION_LEN); + builder.done(); + } + { + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnode_variables", TSDB_SYSTEM_TABLE, 1) + .addColumn("dnode_id", TSDB_DATA_TYPE_INT); + builder.done(); + } } void generatePerformanceSchema(MockCatalogService* mcs) { @@ -187,6 +197,12 @@ void generateFunctions(MockCatalogService* mcs) { 8); } +void generateDnodes(MockCatalogService* mcs) { + mcs->createDnode(1, "host1", 7030); + mcs->createDnode(2, "host2", 7030); + mcs->createDnode(3, "host3", 7030); +} + } // namespace int32_t __catalogGetHandle(const char* clusterId, struct SCatalog** catalogHandle) { return 0; } @@ -241,6 +257,10 @@ int32_t __catalogGetTableIndex(SCatalog* pCtg, void* pTrans, const SEpSet* pMgmt return g_mockCatalogService->catalogGetTableIndex(pName, pRes); } +int32_t __catalogGetDnodeList(SCatalog* pCatalog, SRequestConnInfo* pConn, SArray** pDnodeList) { + return g_mockCatalogService->catalogGetDnodeList(pDnodeList); +} + void initMetaDataEnv() { g_mockCatalogService.reset(new MockCatalogService()); @@ -258,6 +278,7 @@ void initMetaDataEnv() { stub.set(catalogRefreshGetTableMeta, __catalogRefreshGetTableMeta); stub.set(catalogRemoveTableMeta, __catalogRemoveTableMeta); stub.set(catalogGetTableIndex, __catalogGetTableIndex); + stub.set(catalogGetDnodeList, __catalogGetDnodeList); // { // AddrAny any("libcatalog.so"); // std::map result; @@ -307,6 +328,7 @@ void generateMetaData() { generateTestST1(g_mockCatalogService.get()); generateTestST2(g_mockCatalogService.get()); generateFunctions(g_mockCatalogService.get()); + generateDnodes(g_mockCatalogService.get()); g_mockCatalogService->showTables(); } diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index 9758da7899..7915c32437 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -165,6 +165,14 @@ class MockCatalogServiceImpl { return TSDB_CODE_SUCCESS; } + int32_t catalogGetDnodeList(SArray** pDnodes) const { + *pDnodes = taosArrayInit(dnode_.size(), sizeof(SEpSet)); + for (const auto& dnode : dnode_) { + taosArrayPush(*pDnodes, &dnode.second); + } + return TSDB_CODE_SUCCESS; + } + int32_t catalogGetAllMeta(const SCatalogReq* pCatalogReq, SMetaData* pMetaData) const { int32_t code = getAllTableMeta(pCatalogReq->pTableMeta, &pMetaData->pTableMeta); if (TSDB_CODE_SUCCESS == code) { @@ -188,6 +196,9 @@ class MockCatalogServiceImpl { if (TSDB_CODE_SUCCESS == code) { code = getAllTableIndex(pCatalogReq->pTableIndex, &pMetaData->pTableIndex); } + if (TSDB_CODE_SUCCESS == code && pCatalogReq->dNodeRequired) { + code = catalogGetDnodeList(&pMetaData->pDnodeList); + } return code; } @@ -303,11 +314,18 @@ class MockCatalogServiceImpl { } } + void createDnode(int32_t dnodeId, const std::string& host, int16_t port) { + SEpSet epSet = {0}; + addEpIntoEpSet(&epSet, host.c_str(), port); + dnode_.insert(std::make_pair(dnodeId, epSet)); + } + private: typedef std::map> TableMetaCache; typedef std::map DbMetaCache; typedef std::map> UdfMetaCache; typedef std::map> IndexMetaCache; + typedef std::map DnodeCache; uint64_t getNextId() { return id_++; } @@ -532,6 +550,7 @@ class MockCatalogServiceImpl { DbMetaCache meta_; UdfMetaCache udf_; IndexMetaCache index_; + DnodeCache dnode_; }; MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) {} @@ -557,6 +576,10 @@ void MockCatalogService::createFunction(const std::string& func, int8_t funcType void MockCatalogService::createSmaIndex(const SMCreateSmaReq* pReq) { impl_->createSmaIndex(pReq); } +void MockCatalogService::createDnode(int32_t dnodeId, const std::string& host, int16_t port) { + impl_->createDnode(dnodeId, host, port); +} + int32_t MockCatalogService::catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const { return impl_->catalogGetTableMeta(pTableName, pTableMeta); } @@ -581,6 +604,8 @@ int32_t MockCatalogService::catalogGetTableIndex(const SName* pTableName, SArray return impl_->catalogGetTableIndex(pTableName, pIndexes); } +int32_t MockCatalogService::catalogGetDnodeList(SArray** pDnodes) const { return impl_->catalogGetDnodeList(pDnodes); } + int32_t MockCatalogService::catalogGetAllMeta(const SCatalogReq* pCatalogReq, SMetaData* pMetaData) const { return impl_->catalogGetAllMeta(pCatalogReq, pMetaData); } diff --git a/source/libs/parser/test/mockCatalogService.h b/source/libs/parser/test/mockCatalogService.h index 1c98a7d9d5..932424823c 100644 --- a/source/libs/parser/test/mockCatalogService.h +++ b/source/libs/parser/test/mockCatalogService.h @@ -62,6 +62,7 @@ class MockCatalogService { void showTables() const; void createFunction(const std::string& func, int8_t funcType, int8_t outputType, int32_t outputLen, int32_t bufSize); void createSmaIndex(const SMCreateSmaReq* pReq); + void createDnode(int32_t dnodeId, const std::string& host, int16_t port); int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const; int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const; @@ -69,6 +70,7 @@ class MockCatalogService { int32_t catalogGetDBVgInfo(const char* pDbFName, SArray** pVgList) const; int32_t catalogGetUdfInfo(const std::string& funcName, SFuncInfo* pInfo) const; int32_t catalogGetTableIndex(const SName* pTableName, SArray** pIndexes) const; + int32_t catalogGetDnodeList(SArray** pDnodes) const; int32_t catalogGetAllMeta(const SCatalogReq* pCatalogReq, SMetaData* pMetaData) const; private: diff --git a/source/libs/parser/test/parInitialATest.cpp b/source/libs/parser/test/parInitialATest.cpp index 3247ff352e..021348dcc7 100644 --- a/source/libs/parser/test/parInitialATest.cpp +++ b/source/libs/parser/test/parInitialATest.cpp @@ -121,10 +121,10 @@ TEST_F(ParserInitialATest, alterSTable) { int32_t len = snprintf(expect.name, sizeof(expect.name), "0.test.%s", pTbname); expect.name[len] = '\0'; expect.alterType = alterType; - expect.ttl = ttl; +// expect.ttl = ttl; if (nullptr != pComment) { expect.comment = strdup(pComment); - expect.commentLen = strlen(pComment) + 1; + expect.commentLen = strlen(pComment); } expect.numOfFields = numOfFields; @@ -180,9 +180,9 @@ TEST_F(ParserInitialATest, alterSTable) { tFreeSMAltertbReq(&req); }); - setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10); - run("ALTER TABLE st1 TTL 10"); - clearAlterStbReq(); +// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10); +// run("ALTER TABLE st1 TTL 10"); +// clearAlterStbReq(); setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, "test"); run("ALTER TABLE st1 COMMENT 'test'"); @@ -289,7 +289,7 @@ TEST_F(ParserInitialATest, alterTable) { expect.newTTL = ttl; } if (nullptr != pComment) { - expect.updateComment = true; + expect.newCommentLen = strlen(pComment); expect.newComment = pComment; } }; @@ -328,9 +328,10 @@ TEST_F(ParserInitialATest, alterTable) { ASSERT_EQ(memcmp(req.pTagVal, expect.pTagVal, expect.nTagVal), 0); ASSERT_EQ(req.updateTTL, expect.updateTTL); ASSERT_EQ(req.newTTL, expect.newTTL); - ASSERT_EQ(req.updateComment, expect.updateComment); if (nullptr != expect.newComment) { ASSERT_EQ(std::string(req.newComment), std::string(expect.newComment)); + ASSERT_EQ(req.newCommentLen, strlen(req.newComment)); + ASSERT_EQ(expect.newCommentLen, strlen(expect.newComment)); } tDecoderClear(&coder); diff --git a/source/libs/parser/test/parInitialCTest.cpp b/source/libs/parser/test/parInitialCTest.cpp index 1ab251fa48..d188744adf 100644 --- a/source/libs/parser/test/parInitialCTest.cpp +++ b/source/libs/parser/test/parInitialCTest.cpp @@ -370,10 +370,10 @@ TEST_F(ParserInitialCTest, createStable) { expect.delay2 = delay2; expect.watermark1 = watermark1; expect.watermark2 = watermark2; - expect.ttl = ttl; +// expect.ttl = ttl; if (nullptr != pComment) { expect.comment = strdup(pComment); - expect.commentLen = strlen(pComment) + 1; + expect.commentLen = strlen(pComment); } }; @@ -414,7 +414,7 @@ TEST_F(ParserInitialCTest, createStable) { ASSERT_EQ(req.ttl, expect.ttl); ASSERT_EQ(req.numOfColumns, expect.numOfColumns); ASSERT_EQ(req.numOfTags, expect.numOfTags); - ASSERT_EQ(req.commentLen, expect.commentLen); +// ASSERT_EQ(req.commentLen, expect.commentLen); ASSERT_EQ(req.ast1Len, expect.ast1Len); ASSERT_EQ(req.ast2Len, expect.ast2Len); diff --git a/source/libs/parser/test/parInitialDTest.cpp b/source/libs/parser/test/parInitialDTest.cpp index 4ecbb7b6d8..c2039718d0 100644 --- a/source/libs/parser/test/parInitialDTest.cpp +++ b/source/libs/parser/test/parInitialDTest.cpp @@ -159,7 +159,35 @@ TEST_F(ParserInitialDTest, dropSTable) { run("DROP STABLE st1"); } -// todo DROP stream +TEST_F(ParserInitialDTest, dropStream) { + useDb("root", "test"); + + SMDropStreamReq expect = {0}; + + auto clearDropStreamReq = [&]() { memset(&expect, 0, sizeof(SMDropStreamReq)); }; + + auto setDropStreamReq = [&](const char* pStream, int8_t igNotExists = 0) { + sprintf(expect.name, "0.%s", pStream); + expect.igNotExists = igNotExists; + }; + + setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) { + ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_DROP_STREAM_STMT); + SMDropStreamReq req = {0}; + ASSERT_TRUE(TSDB_CODE_SUCCESS == tDeserializeSMDropStreamReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req)); + + ASSERT_EQ(std::string(req.name), std::string(expect.name)); + ASSERT_EQ(req.igNotExists, expect.igNotExists); + }); + + setDropStreamReq("s1"); + run("DROP STREAM s1"); + clearDropStreamReq(); + + setDropStreamReq("s2", 1); + run("DROP STREAM IF EXISTS s2"); + clearDropStreamReq(); +} TEST_F(ParserInitialDTest, dropTable) { useDb("root", "test"); diff --git a/source/libs/parser/test/parSelectTest.cpp b/source/libs/parser/test/parSelectTest.cpp index a69b012574..11e09cd83d 100644 --- a/source/libs/parser/test/parSelectTest.cpp +++ b/source/libs/parser/test/parSelectTest.cpp @@ -256,6 +256,22 @@ TEST_F(ParserSelectTest, intervalSemanticCheck) { run("SELECT _WSTARTTS, _WENDTS, _WDURATION, sum(c1) FROM t1", TSDB_CODE_PAR_INVALID_WINDOW_PC); } +TEST_F(ParserSelectTest, interp) { + useDb("root", "test"); + + run("SELECT INTERP(c1) FROM t1"); + + run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00')"); + + run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') FILL(LINEAR)"); + + run("SELECT INTERP(c1) FROM t1 EVERY(5s)"); + + run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') EVERY(5s)"); + + run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR)"); +} + TEST_F(ParserSelectTest, subquery) { useDb("root", "test"); diff --git a/source/libs/parser/test/parShowToUse.cpp b/source/libs/parser/test/parShowToUse.cpp index 940b6ea8ac..1a68e80872 100644 --- a/source/libs/parser/test/parShowToUse.cpp +++ b/source/libs/parser/test/parShowToUse.cpp @@ -76,6 +76,12 @@ TEST_F(ParserShowToUseTest, showDnodes) { run("SHOW dnodes"); } +TEST_F(ParserShowToUseTest, showDnodeVariables) { + useDb("root", "test"); + + run("SHOW DNODE 1 VARIABLES"); +} + TEST_F(ParserShowToUseTest, showFunctions) { useDb("root", "test"); @@ -84,6 +90,12 @@ TEST_F(ParserShowToUseTest, showFunctions) { // todo SHOW licence +TEST_F(ParserShowToUseTest, showLocalVariables) { + useDb("root", "test"); + + run("SHOW LOCAL VARIABLES"); +} + TEST_F(ParserShowToUseTest, showIndexes) { useDb("root", "test"); @@ -157,7 +169,11 @@ TEST_F(ParserShowToUseTest, showUsers) { run("SHOW users"); } -// todo SHOW variables +TEST_F(ParserShowToUseTest, showVariables) { + useDb("root", "test"); + + run("SHOW VARIABLES"); +} TEST_F(ParserShowToUseTest, showVgroups) { useDb("root", "test"); diff --git a/source/libs/planner/inc/planInt.h b/source/libs/planner/inc/planInt.h index e0728c8654..b7fba83235 100644 --- a/source/libs/planner/inc/planInt.h +++ b/source/libs/planner/inc/planInt.h @@ -23,10 +23,6 @@ extern "C" { #include "planner.h" #include "taoserror.h" -#define QUERY_POLICY_VNODE 1 -#define QUERY_POLICY_HYBRID 2 -#define QUERY_POLICY_QNODE 3 - #define planFatal(param, ...) qFatal("PLAN: " param, __VA_ARGS__) #define planError(param, ...) qError("PLAN: " param, __VA_ARGS__) #define planWarn(param, ...) qWarn("PLAN: " param, __VA_ARGS__) diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 7fad7416cd..46ba9aca74 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -91,7 +91,7 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) { return DEAL_RES_CONTINUE; } -static int32_t rewriteExprForSelect(SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) { +static int32_t rewriteExprsForSelect(SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) { nodesWalkExprs(pExprs, doNameExpr, NULL); SRewriteExprCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs}; nodesRewriteSelectStmt(pSelect, clause, doRewriteExpr, &cxt); @@ -156,7 +156,11 @@ static EScanType getScanType(SLogicPlanContext* pCxt, SNodeList* pScanPseudoCols if (NULL == pScanCols) { // select count(*) from t - return NULL == pScanPseudoCols ? SCAN_TYPE_TABLE : SCAN_TYPE_TAG; + return NULL == pScanPseudoCols + ? SCAN_TYPE_TABLE + : ((FUNCTION_TYPE_BLOCK_DIST_INFO == ((SFunctionNode*)nodesListGetNode(pScanPseudoCols, 0))->funcType) + ? SCAN_TYPE_BLOCK_INFO + : SCAN_TYPE_TAG); } if (TSDB_SYSTEM_TABLE == tableType) { @@ -262,7 +266,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect // rewrite the expression in subsequent clauses if (TSDB_CODE_SUCCESS == code) { - code = rewriteExprForSelect(pScan->pScanPseudoCols, pSelect, SQL_CLAUSE_FROM); + code = rewriteExprsForSelect(pScan->pScanPseudoCols, pSelect, SQL_CLAUSE_FROM); } pScan->scanType = getScanType(pCxt, pScan->pScanPseudoCols, pScan->pScanCols, pScan->tableType); @@ -421,7 +425,7 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, // rewrite the expression in subsequent clauses if (TSDB_CODE_SUCCESS == code) { - code = rewriteExprForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY); + code = rewriteExprsForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY); } if (TSDB_CODE_SUCCESS == code && pSelect->hasAggFuncs) { @@ -430,7 +434,7 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, // rewrite the expression in subsequent clauses if (TSDB_CODE_SUCCESS == code) { - code = rewriteExprForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY); + code = rewriteExprsForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY); } if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pHaving) { @@ -469,14 +473,15 @@ static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt return TSDB_CODE_OUT_OF_MEMORY; } - int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, fmIsVectorFunc, &pIdfRowsFunc->pVectorFuncs); + // indefinite rows functions and _select_values functions + int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, fmIsVectorFunc, &pIdfRowsFunc->pFuncs); if (TSDB_CODE_SUCCESS == code) { - code = rewriteExprForSelect(pIdfRowsFunc->pVectorFuncs, pSelect, SQL_CLAUSE_SELECT); + code = rewriteExprsForSelect(pIdfRowsFunc->pFuncs, pSelect, SQL_CLAUSE_SELECT); } // set the output if (TSDB_CODE_SUCCESS == code) { - code = createColumnByRewriteExprs(pIdfRowsFunc->pVectorFuncs, &pIdfRowsFunc->node.pTargets); + code = createColumnByRewriteExprs(pIdfRowsFunc->pFuncs, &pIdfRowsFunc->node.pTargets); } if (TSDB_CODE_SUCCESS == code) { @@ -488,6 +493,50 @@ static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt return code; } +static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { + if (!pSelect->hasInterpFunc) { + return TSDB_CODE_SUCCESS; + } + + SInterpFuncLogicNode* pInterpFunc = (SInterpFuncLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_INTERP_FUNC); + if (NULL == pInterpFunc) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, fmIsInterpFunc, &pInterpFunc->pFuncs); + if (TSDB_CODE_SUCCESS == code) { + code = rewriteExprsForSelect(pInterpFunc->pFuncs, pSelect, SQL_CLAUSE_SELECT); + } + + if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pFill) { + SFillNode* pFill = (SFillNode*)pSelect->pFill; + pInterpFunc->timeRange = pFill->timeRange; + pInterpFunc->fillMode = pFill->mode; + pInterpFunc->pTimeSeries = nodesCloneNode(pFill->pWStartTs); + pInterpFunc->pFillValues = nodesCloneNode(pFill->pValues); + if (NULL == pInterpFunc->pTimeSeries || (NULL != pFill->pValues && NULL == pInterpFunc->pFillValues)) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + } + + if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pEvery) { + pInterpFunc->interval = ((SValueNode*)pSelect->pEvery)->datum.i; + } + + // set the output + if (TSDB_CODE_SUCCESS == code) { + code = createColumnByRewriteExprs(pInterpFunc->pFuncs, &pInterpFunc->node.pTargets); + } + + if (TSDB_CODE_SUCCESS == code) { + *pLogicNode = (SLogicNode*)pInterpFunc; + } else { + nodesDestroyNode((SNode*)pInterpFunc); + } + + return code; +} + static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow, SLogicNode** pLogicNode) { int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_WINDOW, fmIsWindowClauseFunc, &pWindow->pFuncs); @@ -502,7 +551,7 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm } if (TSDB_CODE_SUCCESS == code) { - code = rewriteExprForSelect(pWindow->pFuncs, pSelect, SQL_CLAUSE_WINDOW); + code = rewriteExprsForSelect(pWindow->pFuncs, pSelect, SQL_CLAUSE_WINDOW); } if (TSDB_CODE_SUCCESS == code) { @@ -555,6 +604,7 @@ static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionW nodesDestroyNode((SNode*)pWindow); return TSDB_CODE_OUT_OF_MEMORY; } + pWindow->pTsEnd = nodesCloneNode((SNode*)pSession->pCol); return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode); } @@ -773,7 +823,7 @@ static int32_t createDistinctLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe // rewrite the expression in subsequent clauses if (TSDB_CODE_SUCCESS == code) { - code = rewriteExprForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_DISTINCT); + code = rewriteExprsForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_DISTINCT); } // set the output @@ -808,6 +858,9 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele if (TSDB_CODE_SUCCESS == code) { code = createSelectRootLogicNode(pCxt, pSelect, createIndefRowsFuncLogicNode, &pRoot); } + if (TSDB_CODE_SUCCESS == code) { + code = createSelectRootLogicNode(pCxt, pSelect, createInterpFuncLogicNode, &pRoot); + } if (TSDB_CODE_SUCCESS == code) { code = createSelectRootLogicNode(pCxt, pSelect, createDistinctLogicNode, &pRoot); } diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 3a2cbd090c..de6edea222 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -1026,39 +1026,136 @@ static bool partTagsOptHasCol(SNodeList* pPartKeys) { return hasCol; } +static bool partTagsIsOptimizableNode(SLogicNode* pNode) { + return ((QUERY_NODE_LOGIC_PLAN_PARTITION == nodeType(pNode) /*|| + (QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pNode) && NULL != ((SAggLogicNode*)pNode)->pGroupKeys && + NULL != ((SAggLogicNode*)pNode)->pAggFuncs)*/) && + 1 == LIST_LENGTH(pNode->pChildren) && + QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(nodesListGetNode(pNode->pChildren, 0))); +} + +static SNodeList* partTagsGetPartKeys(SLogicNode* pNode) { + if (QUERY_NODE_LOGIC_PLAN_PARTITION == nodeType(pNode)) { + return ((SPartitionLogicNode*)pNode)->pPartitionKeys; + } else { + return ((SAggLogicNode*)pNode)->pGroupKeys; + } +} + static bool partTagsOptMayBeOptimized(SLogicNode* pNode) { - if (QUERY_NODE_LOGIC_PLAN_PARTITION != nodeType(pNode) || 1 != LIST_LENGTH(pNode->pChildren) || - QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(nodesListGetNode(pNode->pChildren, 0))) { + if (!partTagsIsOptimizableNode(pNode)) { return false; } - return !partTagsOptHasCol(((SPartitionLogicNode*)pNode)->pPartitionKeys); + return !partTagsOptHasCol(partTagsGetPartKeys(pNode)); } static int32_t partTagsOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) { - SPartitionLogicNode* pPart = - (SPartitionLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, partTagsOptMayBeOptimized); - if (NULL == pPart) { + SLogicNode* pNode = optFindPossibleNode(pLogicSubplan->pNode, partTagsOptMayBeOptimized); + if (NULL == pNode) { return TSDB_CODE_SUCCESS; } - SScanLogicNode* pScan = (SScanLogicNode*)nodesListGetNode(pPart->node.pChildren, 0); - TSWAP(pPart->pPartitionKeys, pScan->pPartTags); - int32_t code = replaceLogicNode(pLogicSubplan, (SLogicNode*)pPart, (SLogicNode*)pScan); - if (TSDB_CODE_SUCCESS == code) { - NODES_CLEAR_LIST(pPart->node.pChildren); - nodesDestroyNode((SNode*)pPart); + int32_t code = TSDB_CODE_SUCCESS; + SScanLogicNode* pScan = (SScanLogicNode*)nodesListGetNode(pNode->pChildren, 0); + if (QUERY_NODE_LOGIC_PLAN_PARTITION == nodeType(pNode)) { + TSWAP(((SPartitionLogicNode*)pNode)->pPartitionKeys, pScan->pPartTags); + int32_t code = replaceLogicNode(pLogicSubplan, pNode, (SLogicNode*)pScan); + if (TSDB_CODE_SUCCESS == code) { + NODES_CLEAR_LIST(pNode->pChildren); + nodesDestroyNode((SNode*)pNode); + } + } else { + TSWAP(((SAggLogicNode*)pNode)->pGroupKeys, pScan->pPartTags); } return code; } +static bool eliminateProjOptMayBeOptimized(SLogicNode* pNode) { + // TODO: enable this optimization after new mechanising that map projection and targets of project node + if (NULL != pNode->pParent) { + return false; + } + + if (QUERY_NODE_LOGIC_PLAN_PROJECT != nodeType(pNode) || 1 != LIST_LENGTH(pNode->pChildren)) { + return false; + } + + SProjectLogicNode* pProjectNode = (SProjectLogicNode*)pNode; + if (-1 != pProjectNode->limit || -1 != pProjectNode->slimit || -1 != pProjectNode->offset || + -1 != pProjectNode->soffset) { + return false; + } + + SHashObj* pProjColNameHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + SNode* pProjection; + FOREACH(pProjection, pProjectNode->pProjections) { + SExprNode* pExprNode = (SExprNode*)pProjection; + if (QUERY_NODE_COLUMN != nodeType(pExprNode)) { + taosHashCleanup(pProjColNameHash); + return false; + } + + char* projColumnName = ((SColumnNode*)pProjection)->colName; + int32_t* pExist = taosHashGet(pProjColNameHash, projColumnName, strlen(projColumnName)); + if (NULL != pExist) { + taosHashCleanup(pProjColNameHash); + return false; + } else { + int32_t exist = 1; + taosHashPut(pProjColNameHash, projColumnName, strlen(projColumnName), &exist, sizeof(exist)); + } + } + taosHashCleanup(pProjColNameHash); + + return true; +} + +static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan, + SProjectLogicNode* pProjectNode) { + SLogicNode* pChild = (SLogicNode*)nodesListGetNode(pProjectNode->node.pChildren, 0); + SNodeList* pNewChildTargets = nodesMakeList(); + + SNode* pProjection = NULL; + FOREACH(pProjection, pProjectNode->pProjections) { + SNode* pChildTarget = NULL; + FOREACH(pChildTarget, pChild->pTargets) { + if (strcmp(((SColumnNode*)pProjection)->colName, ((SColumnNode*)pChildTarget)->colName) == 0) { + nodesListAppend(pNewChildTargets, nodesCloneNode(pChildTarget)); + break; + } + } + } + nodesDestroyList(pChild->pTargets); + pChild->pTargets = pNewChildTargets; + + int32_t code = replaceLogicNode(pLogicSubplan, (SLogicNode*)pProjectNode, pChild); + if (TSDB_CODE_SUCCESS == code) { + NODES_CLEAR_LIST(pProjectNode->node.pChildren); + nodesDestroyNode((SNode*)pProjectNode); + } + return code; +} + +static int32_t eliminateProjOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) { + SProjectLogicNode* pProjectNode = + (SProjectLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, eliminateProjOptMayBeOptimized); + + if (NULL == pProjectNode) { + return TSDB_CODE_SUCCESS; + } + + return eliminateProjOptimizeImpl(pCxt, pLogicSubplan, pProjectNode); +} + // clang-format off static const SOptimizeRule optimizeRuleSet[] = { {.pName = "OptimizeScanData", .optimizeFunc = osdOptimize}, {.pName = "ConditionPushDown", .optimizeFunc = cpdOptimize}, {.pName = "OrderByPrimaryKey", .optimizeFunc = opkOptimize}, {.pName = "SmaIndex", .optimizeFunc = smaOptimize}, - {.pName = "PartitionByTags", .optimizeFunc = partTagsOptimize} + {.pName = "PartitionByTags", .optimizeFunc = partTagsOptimize}, + {.pName = "EliminateProject", .optimizeFunc = eliminateProjOptimize} }; // clang-format on diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 567df6c4d1..b5a4e4b81f 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -459,34 +459,37 @@ static void vgroupInfoToNodeAddr(const SVgroupInfo* vg, SQueryNodeAddr* pNodeAdd pNodeAddr->epSet = vg->epSet; } -static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, - SPhysiNode** pPhyNode) { - STagScanPhysiNode* pTagScan = - (STagScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN); - if (NULL == pTagScan) { - return TSDB_CODE_OUT_OF_MEMORY; - } - vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode); - SQueryNodeLoad node = {.addr = pSubplan->execNode, .load = 0}; - taosArrayPush(pCxt->pExecNodeList, &node); - return createScanPhysiNodeFinalize(pCxt, pSubplan, pScanLogicNode, (SScanPhysiNode*)pTagScan, pPhyNode); -} - static ENodeType getScanOperatorType(EScanType scanType) { switch (scanType) { + case SCAN_TYPE_TAG: + return QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN; case SCAN_TYPE_TABLE: return QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN; case SCAN_TYPE_STREAM: return QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; case SCAN_TYPE_TABLE_MERGE: - // return QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN; return QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN; + case SCAN_TYPE_BLOCK_INFO: + return QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN; default: break; } return QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN; } +static int32_t createSimpleScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, + SPhysiNode** pPhyNode) { + SScanPhysiNode* pScan = + (SScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, getScanOperatorType(pScanLogicNode->scanType)); + if (NULL == pScan) { + return TSDB_CODE_OUT_OF_MEMORY; + } + vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode); + SQueryNodeLoad node = {.addr = pSubplan->execNode, .load = 0}; + taosArrayPush(pCxt->pExecNodeList, &node); + return createScanPhysiNodeFinalize(pCxt, pSubplan, pScanLogicNode, pScan, pPhyNode); +} + static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, @@ -502,10 +505,6 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode); pSubplan->execNodeStat.tableNum = pScanLogicNode->pVgroupList->vgroups[0].numOfTable; } - if (pCxt->pExecNodeList) { - SQueryNodeLoad node = {.addr = pSubplan->execNode, .load = 0}; - taosArrayPush(pCxt->pExecNodeList, &node); - } tNameGetFullDbName(&pScanLogicNode->tableName, pSubplan->dbFName); pTableScan->dataRequired = pScanLogicNode->dataRequired; pTableScan->pDynamicScanFuncs = nodesCloneList(pScanLogicNode->pDynamicScanFuncs); @@ -541,13 +540,14 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* if (0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_USER_TABLES) || 0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED)) { vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode); - SQueryNodeLoad node = {.addr = pSubplan->execNode, .load = 0}; - taosArrayPush(pCxt->pExecNodeList, &node); - } else { - SQueryNodeLoad node = {.addr = {.nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet}, .load = 0}; - taosArrayPush(pCxt->pExecNodeList, &node); } - pScan->mgmtEpSet = pCxt->pPlanCxt->mgmtEpSet; + SQueryNodeLoad node = {.addr = {.nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet}, .load = 0}; + taosArrayPush(pCxt->pExecNodeList, &node); + if (0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_DNODE_VARIABLES)) { + pScan->mgmtEpSet = pScanLogicNode->pVgroupList->vgroups->epSet; + } else { + pScan->mgmtEpSet = pCxt->pPlanCxt->mgmtEpSet; + } tNameGetFullDbName(&pScanLogicNode->tableName, pSubplan->dbFName); return createScanPhysiNodeFinalize(pCxt, pSubplan, pScanLogicNode, (SScanPhysiNode*)pScan, pPhyNode); @@ -567,7 +567,8 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SPhysiNode** pPhyNode) { switch (pScanLogicNode->scanType) { case SCAN_TYPE_TAG: - return createTagScanPhysiNode(pCxt, pSubplan, pScanLogicNode, pPhyNode); + case SCAN_TYPE_BLOCK_INFO: + return createSimpleScanPhysiNode(pCxt, pSubplan, pScanLogicNode, pPhyNode); case SCAN_TYPE_TABLE: return createTableScanPhysiNode(pCxt, pSubplan, pScanLogicNode, pPhyNode); case SCAN_TYPE_SYSTEM_TABLE: @@ -830,8 +831,8 @@ static int32_t createIndefRowsFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList* } SNodeList* pPrecalcExprs = NULL; - SNodeList* pVectorFuncs = NULL; - int32_t code = rewritePrecalcExprs(pCxt, pFuncLogicNode->pVectorFuncs, &pPrecalcExprs, &pVectorFuncs); + SNodeList* pFuncs = NULL; + int32_t code = rewritePrecalcExprs(pCxt, pFuncLogicNode->pFuncs, &pPrecalcExprs, &pFuncs); SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); // push down expression to pOutputDataBlockDesc of child node @@ -842,10 +843,10 @@ static int32_t createIndefRowsFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList* } } - if (TSDB_CODE_SUCCESS == code && NULL != pVectorFuncs) { - code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pVectorFuncs, &pIdfRowsFunc->pVectorFuncs); + if (TSDB_CODE_SUCCESS == code) { + code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pIdfRowsFunc->pFuncs); if (TSDB_CODE_SUCCESS == code) { - code = addDataBlockSlots(pCxt, pIdfRowsFunc->pVectorFuncs, pIdfRowsFunc->node.pOutputDataBlockDesc); + code = addDataBlockSlots(pCxt, pIdfRowsFunc->pFuncs, pIdfRowsFunc->node.pOutputDataBlockDesc); } } @@ -858,6 +859,57 @@ static int32_t createIndefRowsFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList* return code; } +static int32_t createInterpFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SInterpFuncLogicNode* pFuncLogicNode, SPhysiNode** pPhyNode) { + SInterpFuncPhysiNode* pInterpFunc = + (SInterpFuncPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pFuncLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC); + if (NULL == pInterpFunc) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + SNodeList* pPrecalcExprs = NULL; + SNodeList* pFuncs = NULL; + int32_t code = rewritePrecalcExprs(pCxt, pFuncLogicNode->pFuncs, &pPrecalcExprs, &pFuncs); + + SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); + // push down expression to pOutputDataBlockDesc of child node + if (TSDB_CODE_SUCCESS == code && NULL != pPrecalcExprs) { + code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs, &pInterpFunc->pExprs); + if (TSDB_CODE_SUCCESS == code) { + code = pushdownDataBlockSlots(pCxt, pInterpFunc->pExprs, pChildTupe); + } + } + + if (TSDB_CODE_SUCCESS == code) { + code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pInterpFunc->pFuncs); + if (TSDB_CODE_SUCCESS == code) { + code = addDataBlockSlots(pCxt, pInterpFunc->pFuncs, pInterpFunc->node.pOutputDataBlockDesc); + } + } + + if (TSDB_CODE_SUCCESS == code) { + pInterpFunc->timeRange = pFuncLogicNode->timeRange; + pInterpFunc->interval = pFuncLogicNode->interval; + pInterpFunc->fillMode = pFuncLogicNode->fillMode; + pInterpFunc->pFillValues = nodesCloneNode(pFuncLogicNode->pFillValues); + if (NULL != pFuncLogicNode->pFillValues && NULL == pInterpFunc->pFillValues) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + } + + if (TSDB_CODE_SUCCESS == code) { + code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncLogicNode->pTimeSeries, &pInterpFunc->pTimeSeries); + } + + if (TSDB_CODE_SUCCESS == code) { + *pPhyNode = (SPhysiNode*)pInterpFunc; + } else { + nodesDestroyNode((SNode*)pInterpFunc); + } + + return code; +} + static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) { SProjectPhysiNode* pProject = @@ -966,6 +1018,9 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* if (TSDB_CODE_SUCCESS == code) { code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTspk, &pWindow->pTspk); } + if (TSDB_CODE_SUCCESS == code && pWindowLogicNode->pTsEnd) { + code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTsEnd, &pWindow->pTsEnd); + } if (TSDB_CODE_SUCCESS == code && NULL != pFuncs) { code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pWindow->pFuncs); @@ -1300,6 +1355,8 @@ static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode return createFillPhysiNode(pCxt, pChildren, (SFillLogicNode*)pLogicNode, pPhyNode); case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: return createIndefRowsFuncPhysiNode(pCxt, pChildren, (SIndefRowsFuncLogicNode*)pLogicNode, pPhyNode); + case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC: + return createInterpFuncPhysiNode(pCxt, pChildren, (SInterpFuncLogicNode*)pLogicNode, pPhyNode); case QUERY_NODE_LOGIC_PLAN_MERGE: return createMergePhysiNode(pCxt, (SMergeLogicNode*)pLogicNode, pPhyNode); default: @@ -1390,8 +1447,6 @@ static SSubplan* makeSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubpl static int32_t buildInsertSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, SSubplan* pSubplan) { pSubplan->msgType = pModify->msgType; pSubplan->execNode.epSet = pModify->pVgDataBlocks->vg.epSet; - SQueryNodeLoad node = {.addr = pSubplan->execNode, .load = 0}; - taosArrayPush(pCxt->pExecNodeList, &node); return createDataInserter(pCxt, pModify->pVgDataBlocks, &pSubplan->pDataSink); } diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index fe02dd6425..390d665760 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -176,7 +176,7 @@ static bool stbSplNeedSplit(bool streamQuery, SLogicNode* pNode) { return !stbSplHasGatherExecFunc(((SAggLogicNode*)pNode)->pAggFuncs) && stbSplHasMultiTbScan(streamQuery, pNode); case QUERY_NODE_LOGIC_PLAN_WINDOW: { SWindowLogicNode* pWindow = (SWindowLogicNode*)pNode; - if (WINDOW_TYPE_INTERVAL != pWindow->winType) { + if (WINDOW_TYPE_STATE == pWindow->winType || (!streamQuery && WINDOW_TYPE_SESSION == pWindow->winType) ) { return false; } return !stbSplHasGatherExecFunc(pWindow->pFuncs) && stbSplHasMultiTbScan(streamQuery, pNode); @@ -257,6 +257,34 @@ static int32_t stbSplAppendWStart(SNodeList* pFuncs, int32_t* pIndex) { return code; } +static int32_t stbSplAppendWEnd(SWindowLogicNode* pWin, int32_t* pIndex) { + int32_t index = 0; + SNode* pFunc = NULL; + FOREACH(pFunc, pWin->pFuncs) { + if (FUNCTION_TYPE_WENDTS == ((SFunctionNode*)pFunc)->funcType) { + *pIndex = index; + return TSDB_CODE_SUCCESS; + } + ++index; + } + + SFunctionNode* pWEnd = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); + if (NULL == pWEnd) { + return TSDB_CODE_OUT_OF_MEMORY; + } + strcpy(pWEnd->functionName, "_wendts"); + snprintf(pWEnd->node.aliasName, sizeof(pWEnd->node.aliasName), "%s.%p", pWEnd->functionName, pWEnd); + int32_t code = fmGetFuncInfo(pWEnd, NULL, 0); + if (TSDB_CODE_SUCCESS == code) { + code = nodesListStrictAppend(pWin->pFuncs, (SNode*)pWEnd); + } + *pIndex = index; + if (TSDB_CODE_SUCCESS == code) { + code = createColumnByRewriteExpr(nodesListGetNode(pWin->pFuncs, index), &pWin->node.pTargets); + } + return code; +} + static int32_t stbSplCreatePartWindowNode(SWindowLogicNode* pMergeWindow, SLogicNode** pPartWindow) { SNodeList* pFunc = pMergeWindow->pFuncs; pMergeWindow->pFuncs = NULL; @@ -425,8 +453,18 @@ static int32_t stbSplSplitSessionForStream(SSplitContext* pCxt, SStableSplitInfo SLogicNode* pPartWindow = NULL; int32_t code = stbSplCreatePartWindowNode((SWindowLogicNode*)pInfo->pSplitNode, &pPartWindow); if (TSDB_CODE_SUCCESS == code) { - ((SWindowLogicNode*)pPartWindow)->windowAlgo = SESSION_ALGO_STREAM_SEMI; - ((SWindowLogicNode*)pInfo->pSplitNode)->windowAlgo = SESSION_ALGO_STREAM_FINAL; + SWindowLogicNode* pPartWin = (SWindowLogicNode*)pPartWindow; + SWindowLogicNode* pMergeWin = (SWindowLogicNode*)pInfo->pSplitNode; + pPartWin->windowAlgo = SESSION_ALGO_STREAM_SEMI; + pMergeWin->windowAlgo = SESSION_ALGO_STREAM_FINAL; + int32_t index = 0; + int32_t code = stbSplAppendWEnd(pPartWin, &index); + if (TSDB_CODE_SUCCESS == code) { + pMergeWin->pTsEnd = nodesCloneNode(nodesListGetNode(pPartWin->node.pTargets, index)); + if (NULL == pMergeWin->pTsEnd) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + } code = stbSplCreateExchangeNode(pCxt, pInfo->pSplitNode, pPartWindow); } if (TSDB_CODE_SUCCESS == code) { diff --git a/source/libs/planner/src/planUtil.c b/source/libs/planner/src/planUtil.c index 7f650c7c9a..77e4e05530 100644 --- a/source/libs/planner/src/planUtil.c +++ b/source/libs/planner/src/planUtil.c @@ -107,6 +107,7 @@ int32_t createColumnByRewriteExpr(SNode* pExpr, SNodeList** pList) { int32_t replaceLogicNode(SLogicSubplan* pSubplan, SLogicNode* pOld, SLogicNode* pNew) { if (NULL == pOld->pParent) { pSubplan->pNode = (SLogicNode*)pNew; + pNew->pParent = NULL; return TSDB_CODE_SUCCESS; } diff --git a/source/libs/planner/test/planBasicTest.cpp b/source/libs/planner/test/planBasicTest.cpp index c075bfeee8..f74c7df355 100644 --- a/source/libs/planner/test/planBasicTest.cpp +++ b/source/libs/planner/test/planBasicTest.cpp @@ -52,6 +52,8 @@ TEST_F(PlanBasicTest, func) { run("SELECT PERCENTILE(c1, 60) FROM t1"); run("SELECT TOP(c1, 60) FROM t1"); + + run("SELECT TOP(c1, 60) FROM st1"); } TEST_F(PlanBasicTest, uniqueFunc) { @@ -73,3 +75,11 @@ TEST_F(PlanBasicTest, tailFunc) { run("SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10"); } + +TEST_F(PlanBasicTest, interpFunc) { + useDb("root", "test"); + + run("SELECT INTERP(c1) FROM t1"); + + run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR)"); +} diff --git a/source/libs/planner/test/planOptimizeTest.cpp b/source/libs/planner/test/planOptimizeTest.cpp index ead3956450..8b3d263d66 100644 --- a/source/libs/planner/test/planOptimizeTest.cpp +++ b/source/libs/planner/test/planOptimizeTest.cpp @@ -47,10 +47,27 @@ TEST_F(PlanOptimizeTest, ConditionPushDown) { TEST_F(PlanOptimizeTest, orderByPrimaryKey) { useDb("root", "test"); - run("SELECT * FROM t1 ORDER BY ts"); - run("SELECT * FROM t1 ORDER BY ts DESC"); run("SELECT c1 FROM t1 ORDER BY ts"); + run("SELECT c1 FROM t1 ORDER BY ts DESC"); run("SELECT COUNT(*) FROM t1 INTERVAL(10S) ORDER BY _WSTARTTS DESC"); } + +TEST_F(PlanOptimizeTest, PartitionTags) { + useDb("root", "test"); + + run("SELECT c1 FROM st1 PARTITION BY tag1"); + + run("SELECT SUM(c1) FROM st1 GROUP BY tag1"); +} + +TEST_F(PlanOptimizeTest, eliminateProjection) { + useDb("root", "test"); + + run("SELECT c1, sum(c3) FROM t1 GROUP BY c1"); + run("SELECT c1 FROM t1"); + run("SELECT * FROM st1"); + run("SELECT c1 FROM st1s3"); + // run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) order by 1 nulls first"); +} diff --git a/source/libs/planner/test/planOtherTest.cpp b/source/libs/planner/test/planOtherTest.cpp index f9feb8d1fe..12d14369de 100644 --- a/source/libs/planner/test/planOtherTest.cpp +++ b/source/libs/planner/test/planOtherTest.cpp @@ -70,6 +70,12 @@ TEST_F(PlanOtherTest, show) { useDb("root", "test"); run("SHOW DATABASES"); + + run("SHOW TABLE DISTRIBUTED t1"); + + run("SHOW TABLE DISTRIBUTED st1"); + + run("SHOW DNODE 1 VARIABLES"); } TEST_F(PlanOtherTest, delete) { diff --git a/source/libs/qworker/inc/qwMsg.h b/source/libs/qworker/inc/qwMsg.h index ecff861f50..8c7c030dce 100644 --- a/source/libs/qworker/inc/qwMsg.h +++ b/source/libs/qworker/inc/qwMsg.h @@ -23,6 +23,7 @@ extern "C" { #include "qwInt.h" #include "dataSinkMgt.h" +int32_t qwAbortPrerocessQuery(QW_FPARAMS_DEF); int32_t qwPrerocessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, int8_t taskType, int8_t explain, const char* sql); int32_t qwProcessCQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg); diff --git a/source/libs/qworker/src/qwMsg.c b/source/libs/qworker/src/qwMsg.c index 5635ec8fc6..82a62b5c5a 100644 --- a/source/libs/qworker/src/qwMsg.c +++ b/source/libs/qworker/src/qwMsg.c @@ -283,6 +283,26 @@ int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg) { return TSDB_CODE_SUCCESS; } +int32_t qWorkerAbortPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg) { + if (NULL == qWorkerMgmt || NULL == pMsg) { + QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + SSubQueryMsg *msg = pMsg->pCont; + SQWorker * mgmt = (SQWorker *)qWorkerMgmt; + + uint64_t sId = msg->sId; + uint64_t qId = msg->queryId; + uint64_t tId = msg->taskId; + int64_t rId = msg->refId; + + QW_SCH_TASK_DLOG("Abort prerocessQuery start, handle:%p", pMsg->info.handle); + qwAbortPrerocessQuery(QW_FPARAMS()); + QW_SCH_TASK_DLOG("Abort prerocessQuery end, handle:%p", pMsg->info.handle); + + return TSDB_CODE_SUCCESS; +} + int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_t ts) { if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 800cc4c6e5..28181d7e11 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -482,6 +482,13 @@ _return: QW_RET(code); } +int32_t qwAbortPrerocessQuery(QW_FPARAMS_DEF) { + QW_ERR_RET(qwDropTask(QW_FPARAMS())); + + QW_RET(TSDB_CODE_SUCCESS); +} + + int32_t qwPrerocessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) { int32_t code = 0; bool queryRsped = false; @@ -526,7 +533,7 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, int8_t taskType, int8_t ex atomic_store_8(&ctx->taskType, taskType); atomic_store_8(&ctx->explain, explain); - /*QW_TASK_DLOGL("subplan json string, len:%d, %s", qwMsg->msgLen, qwMsg->msg);*/ + QW_TASK_DLOGL("subplan json string, len:%d, %s", qwMsg->msgLen, qwMsg->msg); code = qStringToSubplan(qwMsg->msg, &plan); if (TSDB_CODE_SUCCESS != code) { diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index 679a244f31..72809e1f93 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -652,7 +652,7 @@ int32_t schSetAddrsFromNodeList(SSchJob *pJob, SSchTask *pTask) { if (addNum <= 0) { SCH_TASK_ELOG("no available execNode as candidates, nodeNum:%d", nodeNum); - SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + SCH_ERR_RET(TSDB_CODE_TSC_NO_EXEC_NODE); } return TSDB_CODE_SUCCESS; @@ -677,7 +677,7 @@ int32_t schSetTaskCandidateAddrs(SSchJob *pJob, SSchTask *pTask) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SCH_TASK_DLOG("use execNode from plan as candidate addr, numOfEps:%d", pTask->plan->execNode.epSet.numOfEps); + SCH_TASK_DLOG("use execNode in plan as candidate addr, numOfEps:%d", pTask->plan->execNode.epSet.numOfEps); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/stream/src/stream.c b/source/libs/stream/src/stream.c index 6dcbfad957..18a6e5bf77 100644 --- a/source/libs/stream/src/stream.c +++ b/source/libs/stream/src/stream.c @@ -50,6 +50,10 @@ void streamCleanUp() { void streamTriggerByTimer(void* param, void* tmrId) { SStreamTask* pTask = (void*)param; + if (atomic_load_8(&pTask->taskStatus) == TASK_STATUS__DROPPING) { + return; + } + if (atomic_load_8(&pTask->triggerStatus) == TASK_TRIGGER_STATUS__ACTIVE) { SStreamTrigger* trigger = taosAllocateQitem(sizeof(SStreamTrigger), DEF_QITEM); if (trigger == NULL) return; @@ -64,7 +68,7 @@ void streamTriggerByTimer(void* param, void* tmrId) { atomic_store_8(&pTask->triggerStatus, TASK_TRIGGER_STATUS__IN_ACTIVE); streamTaskInput(pTask, (SStreamQueueItem*)trigger); - streamLaunchByWrite(pTask, pTask->nodeId, pTask->pMsgCb); + streamLaunchByWrite(pTask, pTask->nodeId); } taosTmrReset(streamTriggerByTimer, (int32_t)pTask->triggerParam, pTask, streamEnv.timer, &pTask->timer); @@ -81,9 +85,9 @@ int32_t streamSetupTrigger(SStreamTask* pTask) { return 0; } -int32_t streamLaunchByWrite(SStreamTask* pTask, int32_t vgId, SMsgCb* pMsgCb) { - int8_t execStatus = atomic_load_8(&pTask->status); - if (execStatus == TASK_STATUS__IDLE || execStatus == TASK_STATUS__CLOSING) { +int32_t streamLaunchByWrite(SStreamTask* pTask, int32_t vgId) { + int8_t execStatus = atomic_load_8(&pTask->execStatus); + if (execStatus == TASK_EXEC_STATUS__IDLE || execStatus == TASK_EXEC_STATUS__CLOSING) { SStreamTaskRunReq* pRunReq = rpcMallocCont(sizeof(SStreamTaskRunReq)); if (pRunReq == NULL) return -1; @@ -96,7 +100,7 @@ int32_t streamLaunchByWrite(SStreamTask* pTask, int32_t vgId, SMsgCb* pMsgCb) { .pCont = pRunReq, .contLen = sizeof(SStreamTaskRunReq), }; - tmsgPutToQueue(pMsgCb, FETCH_QUEUE, &msg); + tmsgPutToQueue(pTask->pMsgCb, FETCH_QUEUE, &msg); } return 0; } @@ -136,7 +140,9 @@ int32_t streamTaskEnqueue(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* return status == TASK_INPUT_STATUS__NORMAL ? 0 : -1; } -int32_t streamProcessDispatchReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchReq* pReq, SRpcMsg* pRsp) { +int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pRsp) { + qInfo("task %d receive dispatch req from node %d task %d", pTask->taskId, pReq->upstreamNodeId, pReq->sourceTaskId); + // 1. handle input streamTaskEnqueue(pTask, pReq, pRsp); @@ -145,7 +151,7 @@ int32_t streamProcessDispatchReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDisp // 2.2. executing: return // 2.3. closing: keep trying if (pTask->execType != TASK_EXEC__NONE) { - streamExec(pTask, pMsgCb); + streamExec(pTask, pTask->pMsgCb); } else { ASSERT(pTask->sinkType != TASK_SINK__NONE); while (1) { @@ -161,34 +167,39 @@ int32_t streamProcessDispatchReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDisp // 3.1 check and set status // 3.2 dispatch / sink if (pTask->dispatchType != TASK_DISPATCH__NONE) { - streamDispatch(pTask, pMsgCb); + streamDispatch(pTask, pTask->pMsgCb); } return 0; } -int32_t streamProcessDispatchRsp(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchRsp* pRsp) { +int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp) { ASSERT(pRsp->inputStatus == TASK_OUTPUT_STATUS__NORMAL || pRsp->inputStatus == TASK_OUTPUT_STATUS__BLOCKED); + + qInfo("task %d receive dispatch rsp", pTask->taskId); + int8_t old = atomic_exchange_8(&pTask->outputStatus, pRsp->inputStatus); ASSERT(old == TASK_OUTPUT_STATUS__WAIT); if (pRsp->inputStatus == TASK_INPUT_STATUS__BLOCKED) { // TODO: init recover timer + ASSERT(0); return 0; } // continue dispatch - streamDispatch(pTask, pMsgCb); + streamDispatch(pTask, pTask->pMsgCb); return 0; } -int32_t streamTaskProcessRunReq(SStreamTask* pTask, SMsgCb* pMsgCb) { - streamExec(pTask, pMsgCb); +int32_t streamProcessRunReq(SStreamTask* pTask) { + streamExec(pTask, pTask->pMsgCb); + if (pTask->dispatchType != TASK_DISPATCH__NONE) { - streamDispatch(pTask, pMsgCb); + streamDispatch(pTask, pTask->pMsgCb); } return 0; } -int32_t streamProcessRecoverReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamTaskRecoverReq* pReq, SRpcMsg* pMsg) { +int32_t streamProcessRecoverReq(SStreamTask* pTask, SStreamTaskRecoverReq* pReq, SRpcMsg* pMsg) { // return 0; } diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index ca10e7d956..1894f697c0 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -144,7 +144,7 @@ int32_t streamBuildDispatchMsg(SStreamTask* pTask, SStreamDataBlock* data, SRpcM } } - ASSERT(vgId != 0); + ASSERT(vgId > 0 || vgId == SNODE_HANDLE); req.taskId = downstreamTaskId; qInfo("dispatch from task %d (child id %d) to down stream task %d in vnode %d", pTask->taskId, pTask->childId, @@ -199,6 +199,8 @@ int32_t streamDispatch(SStreamTask* pTask, SMsgCb* pMsgCb) { } ASSERT(pBlock->type == STREAM_DATA_TYPE_SSDATA_BLOCK); + qInfo("stream continue dispatching: task %d", pTask->taskId); + SRpcMsg dispatchMsg = {0}; SEpSet* pEpSet = NULL; if (streamBuildDispatchMsg(pTask, pBlock, &dispatchMsg, &pEpSet) < 0) { diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c index 04428136ae..bab86223bf 100644 --- a/source/libs/stream/src/streamExec.c +++ b/source/libs/stream/src/streamExec.c @@ -33,6 +33,9 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) ASSERT(pTask->inputType == STREAM_INPUT__DATA_BLOCK); SArray* blocks = pBlock->blocks; qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_DATA_TYPE_SSDATA_BLOCK, false); + } else if (pItem->type == STREAM_INPUT__DROP) { + // TODO exec drop + return 0; } // exec @@ -58,6 +61,10 @@ static SArray* streamExecForQall(SStreamTask* pTask, SArray* pRes) { streamTaskExecImpl(pTask, data, pRes); + if (pTask->taskStatus == TASK_STATUS__DROPPING) { + return NULL; + } + if (taosArrayGetSize(pRes) != 0) { SStreamDataBlock* qRes = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM); if (qRes == NULL) { @@ -75,12 +82,17 @@ static SArray* streamExecForQall(SStreamTask* pTask, SArray* pRes) { return NULL; } - if (pTask->inputType == STREAM_INPUT__DATA_SUBMIT) { - streamDataSubmitRefDec((SStreamDataSubmit*)data); + if (((SStreamQueueItem*)data)->type == STREAM_INPUT__TRIGGER) { + blockDataDestroy(((SStreamTrigger*)data)->pBlock); taosFreeQitem(data); } else { - taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)tDeleteSSDataBlock); - taosFreeQitem(data); + if (pTask->inputType == STREAM_INPUT__DATA_SUBMIT) { + streamDataSubmitRefDec((SStreamDataSubmit*)data); + taosFreeQitem(data); + } else { + taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)tDeleteSSDataBlock); + taosFreeQitem(data); + } } streamQueueProcessSuccess(pTask->inputQueue); return taosArrayInit(0, sizeof(SSDataBlock)); @@ -94,34 +106,36 @@ int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) { SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); if (pRes == NULL) return -1; while (1) { - int8_t execStatus = atomic_val_compare_exchange_8(&pTask->status, TASK_STATUS__IDLE, TASK_STATUS__EXECUTING); - if (execStatus == TASK_STATUS__IDLE) { + int8_t execStatus = + atomic_val_compare_exchange_8(&pTask->execStatus, TASK_EXEC_STATUS__IDLE, TASK_EXEC_STATUS__EXECUTING); + if (execStatus == TASK_EXEC_STATUS__IDLE) { // first run pRes = streamExecForQall(pTask, pRes); if (pRes == NULL) goto FAIL; // set status closing - atomic_store_8(&pTask->status, TASK_STATUS__CLOSING); + atomic_store_8(&pTask->execStatus, TASK_EXEC_STATUS__CLOSING); // second run, make sure inputQ and qall are cleared pRes = streamExecForQall(pTask, pRes); if (pRes == NULL) goto FAIL; - break; - } else if (execStatus == TASK_STATUS__CLOSING) { + taosArrayDestroy(pRes); + atomic_store_8(&pTask->execStatus, TASK_EXEC_STATUS__IDLE); + return 0; + } else if (execStatus == TASK_EXEC_STATUS__CLOSING) { continue; - } else if (execStatus == TASK_STATUS__EXECUTING) { - break; + } else if (execStatus == TASK_EXEC_STATUS__EXECUTING) { + ASSERT(taosArrayGetSize(pRes) == 0); + taosArrayDestroy(pRes); + return 0; } else { ASSERT(0); } } - if (pRes) taosArrayDestroy(pRes); - atomic_store_8(&pTask->status, TASK_STATUS__IDLE); - return 0; FAIL: if (pRes) taosArrayDestroy(pRes); - atomic_store_8(&pTask->status, TASK_STATUS__IDLE); + atomic_store_8(&pTask->execStatus, TASK_EXEC_STATUS__IDLE); return -1; } diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c index a35e7679a1..6dfaa4cb74 100644 --- a/source/libs/stream/src/streamTask.c +++ b/source/libs/stream/src/streamTask.c @@ -23,7 +23,7 @@ SStreamTask* tNewSStreamTask(int64_t streamId) { } pTask->taskId = tGenIdPI32(); pTask->streamId = streamId; - pTask->status = TASK_STATUS__IDLE; + pTask->execStatus = TASK_EXEC_STATUS__IDLE; pTask->inputStatus = TASK_INPUT_STATUS__NORMAL; pTask->outputStatus = TASK_OUTPUT_STATUS__NORMAL; @@ -35,12 +35,13 @@ int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) { if (tEncodeI64(pEncoder, pTask->streamId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->taskId) < 0) return -1; if (tEncodeI8(pEncoder, pTask->inputType) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->status) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->sourceType) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->taskStatus) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->execStatus) < 0) return -1; if (tEncodeI8(pEncoder, pTask->execType) < 0) return -1; if (tEncodeI8(pEncoder, pTask->sinkType) < 0) return -1; if (tEncodeI8(pEncoder, pTask->dispatchType) < 0) return -1; if (tEncodeI16(pEncoder, pTask->dispatchMsgType) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->dataScan) < 0) return -1; if (tEncodeI32(pEncoder, pTask->childId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->nodeId) < 0) return -1; @@ -83,12 +84,13 @@ int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) { if (tDecodeI64(pDecoder, &pTask->streamId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->inputType) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->status) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->sourceType) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->taskStatus) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->execStatus) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->execType) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->sinkType) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->dispatchType) < 0) return -1; if (tDecodeI16(pDecoder, &pTask->dispatchMsgType) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->dataScan) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->childId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->nodeId) < 0) return -1; diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index b910b59f83..999147eda4 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -159,7 +159,8 @@ typedef struct SSyncNode { SSyncSnapshotSender* senders[TSDB_MAX_REPLICA]; SSyncSnapshotReceiver* pNewNodeReceiver; - // SSnapshotMeta sMeta; + // is config changing + bool changing; } SSyncNode; @@ -198,7 +199,7 @@ char* syncNode2Str(const SSyncNode* pSyncNode); void syncNodeEventLog(const SSyncNode* pSyncNode, char* str); char* syncNode2SimpleStr(const SSyncNode* pSyncNode); bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config); -void syncNodeUpdateConfig(SSyncNode* pSyncNode, SSyncCfg* newConfig, SyncIndex lastConfigChangeIndex, bool* isDrop); +void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* newConfig, SyncIndex lastConfigChangeIndex); SSyncNode* syncNodeAcquire(int64_t rid); void syncNodeRelease(SSyncNode* pNode); @@ -238,14 +239,21 @@ int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg); bool syncNodeInRaftGroup(SSyncNode* ths, SRaftId* pRaftId); SSyncSnapshotSender* syncNodeGetSnapshotSender(SSyncNode* ths, SRaftId* pDestId); +int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta); +int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta); + void syncStartNormal(int64_t rid); void syncStartStandBy(int64_t rid); +bool syncNodeCanChange(SSyncNode* pSyncNode); +bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pNewCfg); + // for debug -------------- void syncNodePrint(SSyncNode* pObj); void syncNodePrint2(char* s, SSyncNode* pObj); void syncNodeLog(SSyncNode* pObj); void syncNodeLog2(char* s, SSyncNode* pObj); +void syncNodeLog3(char* s, SSyncNode* pObj); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncRaftCfg.h b/source/libs/sync/inc/syncRaftCfg.h index 435ad98fb3..efe8a65b77 100644 --- a/source/libs/sync/inc/syncRaftCfg.h +++ b/source/libs/sync/inc/syncRaftCfg.h @@ -27,7 +27,7 @@ extern "C" { #include "syncInt.h" #include "taosdef.h" -#define CONFIG_FILE_LEN 1024 +#define CONFIG_FILE_LEN 2048 #define MAX_CONFIG_INDEX_COUNT 512 diff --git a/source/libs/sync/inc/syncSnapshot.h b/source/libs/sync/inc/syncSnapshot.h index f6544dd79d..f00dfe6f50 100644 --- a/source/libs/sync/inc/syncSnapshot.h +++ b/source/libs/sync/inc/syncSnapshot.h @@ -39,8 +39,8 @@ typedef struct SSyncSnapshotSender { bool start; int32_t seq; int32_t ack; - void *pReader; - void *pCurrentBlock; + void * pReader; + void * pCurrentBlock; int32_t blockLen; SSnapshot snapshot; SSyncCfg lastConfig; @@ -55,21 +55,22 @@ typedef struct SSyncSnapshotSender { SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex); void snapshotSenderDestroy(SSyncSnapshotSender *pSender); bool snapshotSenderIsStart(SSyncSnapshotSender *pSender); -void snapshotSenderStart(SSyncSnapshotSender *pSender); +void snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshot snapshot, void *pReader); void snapshotSenderStop(SSyncSnapshotSender *pSender); int32_t snapshotSend(SSyncSnapshotSender *pSender); int32_t snapshotReSend(SSyncSnapshotSender *pSender); -cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender); -char *snapshotSender2Str(SSyncSnapshotSender *pSender); -char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event); +cJSON * snapshotSender2Json(SSyncSnapshotSender *pSender); +char * snapshotSender2Str(SSyncSnapshotSender *pSender); +char * snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event); typedef struct SSyncSnapshotReceiver { bool start; - int32_t ack; - void *pWriter; - SyncTerm term; - SyncTerm privateTerm; + int32_t ack; + void * pWriter; + SyncTerm term; + SyncTerm privateTerm; + SSnapshot snapshot; SSyncNode *pSyncNode; SRaftId fromId; @@ -78,12 +79,12 @@ typedef struct SSyncSnapshotReceiver { SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId); void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver); -void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, SRaftId fromId); -bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver); -void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver, bool apply); -cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver); -char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver); -char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event); +void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, SyncSnapshotSend *pBeginMsg); +bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver); +void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver, bool apply); +cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver); +char * snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver); +char * snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event); int32_t syncNodeOnSnapshotSendCb(SSyncNode *ths, SyncSnapshotSend *pMsg); int32_t syncNodeOnSnapshotRspCb(SSyncNode *ths, SyncSnapshotRsp *pMsg); diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 58e40668a2..d2726201cc 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -497,7 +497,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs do { SyncIndex myLastIndex = syncNodeGetLastIndex(ths); SSnapshot snapshot; - ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot); + ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot); bool condition0 = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && syncNodeHasSnapshot(ths); @@ -710,7 +710,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs if (pMsg->commitIndex <= ths->pLogStore->syncLogLastIndex(ths->pLogStore)) { // advance commit index to sanpshot first SSnapshot snapshot; - ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot); + ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot); if (snapshot.lastApplyIndex >= 0 && snapshot.lastApplyIndex > ths->commitIndex) { SyncIndex commitBegin = ths->commitIndex; SyncIndex commitEnd = snapshot.lastApplyIndex; diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index 5e5e23b312..7b342cdcff 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -123,7 +123,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries syncIndexMgrLog2("recv SyncAppendEntriesReply, before pMatchIndex:", ths->pMatchIndex); if (gRaftDetailLog) { SSnapshot snapshot; - ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot); + ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot); sTrace("recv SyncAppendEntriesReply, before snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu", snapshot.lastApplyIndex, snapshot.lastApplyTerm); } @@ -173,21 +173,44 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries // get sender SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(pMsg->srcId)); ASSERT(pSender != NULL); - bool hasSnapshot = syncNodeHasSnapshot(ths); - SSnapshot snapshot; - ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot); - // start sending snapshot first time - // start here, stop by receiver - if (hasSnapshot && nextIndex <= snapshot.lastApplyIndex + 1 && !snapshotSenderIsStart(pSender) && - pMsg->privateTerm < pSender->privateTerm) { - snapshotSenderStart(pSender); + SSnapshot snapshot; + void* pReader = NULL; + ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot, NULL, &pReader); + if (snapshot.lastApplyIndex >= SYNC_INDEX_BEGIN && nextIndex <= snapshot.lastApplyIndex + 1 && + !snapshotSenderIsStart(pSender) && pMsg->privateTerm < pSender->privateTerm) { + // has snapshot + ASSERT(pReader != NULL); + snapshotSenderStart(pSender, snapshot, pReader); char* eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender start"); syncNodeEventLog(ths, eventLog); taosMemoryFree(eventLog); + + } else { + // no snapshot + if (pReader != NULL) { + ths->pFsm->FpSnapshotStopRead(ths->pFsm, pReader); + } } + /* + bool hasSnapshot = syncNodeHasSnapshot(ths); + SSnapshot snapshot; + ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot); + + // start sending snapshot first time + // start here, stop by receiver + if (hasSnapshot && nextIndex <= snapshot.lastApplyIndex + 1 && !snapshotSenderIsStart(pSender) && + pMsg->privateTerm < pSender->privateTerm) { + snapshotSenderStart(pSender); + + char* eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender start"); + syncNodeEventLog(ths, eventLog); + taosMemoryFree(eventLog); + } + */ + SyncIndex sentryIndex = pSender->snapshot.lastApplyIndex + 1; // update nextIndex to sentryIndex @@ -207,12 +230,6 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries syncIndexMgrLog2("recv SyncAppendEntriesReply, after pNextIndex:", ths->pNextIndex); syncIndexMgrLog2("recv SyncAppendEntriesReply, after pMatchIndex:", ths->pMatchIndex); - if (gRaftDetailLog) { - SSnapshot snapshot; - ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot); - sTrace("recv SyncAppendEntriesReply, after snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu", - snapshot.lastApplyIndex, snapshot.lastApplyTerm); - } return ret; } \ No newline at end of file diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index 738cbd3c2b..ec3e1ab2ba 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -50,7 +50,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { // advance commit index to sanpshot first SSnapshot snapshot; - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); if (snapshot.lastApplyIndex > 0 && snapshot.lastApplyIndex > pSyncNode->commitIndex) { SyncIndex commitBegin = pSyncNode->commitIndex; SyncIndex commitEnd = snapshot.lastApplyIndex; diff --git a/source/libs/sync/src/syncEnv.c b/source/libs/sync/src/syncEnv.c index e67439f8fe..c92af0dd42 100644 --- a/source/libs/sync/src/syncEnv.c +++ b/source/libs/sync/src/syncEnv.c @@ -35,8 +35,9 @@ bool syncEnvIsStart() { } int32_t syncEnvStart() { - int32_t ret = 0; - taosSeedRand(taosGetTimestampSec()); + int32_t ret = 0; + uint32_t seed = (uint32_t)(taosGetTimestampNs() & 0x00000000FFFFFFFF); + taosSeedRand(seed); // gSyncEnv = doSyncEnvStart(gSyncEnv); gSyncEnv = doSyncEnvStart(); assert(gSyncEnv != NULL); diff --git a/source/libs/sync/src/syncIndexMgr.c b/source/libs/sync/src/syncIndexMgr.c index 18cb55b417..2827fcc12f 100644 --- a/source/libs/sync/src/syncIndexMgr.c +++ b/source/libs/sync/src/syncIndexMgr.c @@ -63,7 +63,12 @@ void syncIndexMgrSetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, } // maybe config change - assert(0); + // assert(0); + + char host[128]; + uint16_t port; + syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port); + sError("vgId:%d index mgr set for %s:%d, index:%" PRId64 " error", pSyncIndexMgr->pSyncNode->vgId, host, port, index); } SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId) { @@ -73,7 +78,9 @@ SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaf return idx; } } - assert(0); + + syncNodeLog3("syncIndexMgrGetIndex", pSyncIndexMgr->pSyncNode); + ASSERT(0); } cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) { @@ -119,7 +126,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) { char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr) { cJSON *pJson = syncIndexMgr2Json(pSyncIndexMgr); - char * serialized = cJSON_Print(pJson); + char *serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -162,7 +169,11 @@ void syncIndexMgrSetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, S } // maybe config change - assert(0); + // assert(0); + char host[128]; + uint16_t port; + syncUtilU642Addr(pRaftId->addr, host, sizeof(host), &port); + sError("vgId:%d index mgr set for %s:%d, term:%lu error", pSyncIndexMgr->pSyncNode->vgId, host, port, term); } SyncTerm syncIndexMgrGetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId) { diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 15a67adf77..b520629e15 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -154,10 +154,14 @@ int32_t syncSetStandby(int64_t rid) { return -1; } - if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { + if (pSyncNode->state != TAOS_SYNC_STATE_FOLLOWER) { taosReleaseRef(tsNodeRefId, pSyncNode->rid); - terrno = TSDB_CODE_SYN_IS_LEADER; - sError("failed to set standby since it is leader, rid:%" PRId64, rid); + if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { + terrno = TSDB_CODE_SYN_IS_LEADER; + } else { + terrno = TSDB_CODE_SYN_STANDBY_NOT_READY; + } + sError("failed to set standby since it is not follower, state:%s rid:%" PRId64, syncStr(pSyncNode->state), rid); return -1; } @@ -178,6 +182,23 @@ int32_t syncSetStandby(int64_t rid) { return 0; } +bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pNewCfg) { + bool IamInNew = syncNodeInConfig(pSyncNode, pNewCfg); + if (!IamInNew) { + return false; + } + + if (pNewCfg->replicaNum > pSyncNode->replicaNum + 1) { + return false; + } + + if (pNewCfg->replicaNum < pSyncNode->replicaNum - 1) { + return false; + } + + return true; +} + int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg) { SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { @@ -185,13 +206,12 @@ int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg return -1; } ASSERT(rid == pSyncNode->rid); - int32_t ret = 0; - bool IamInNew = syncNodeInConfig(pSyncNode, pNewCfg); - if (!IamInNew) { + if (!syncNodeCheckNewConfig(pSyncNode, pNewCfg)) { taosReleaseRef(tsNodeRefId, pSyncNode->rid); - terrno = TSDB_CODE_SYN_NOT_IN_NEW_CONFIG; + terrno = TSDB_CODE_SYN_NEW_CONFIG_ERROR; + sError("syncNodeCheckNewConfig error"); return -1; } @@ -215,12 +235,10 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg* pNewCfg) { } ASSERT(rid == pSyncNode->rid); - bool IamInNew = syncNodeInConfig(pSyncNode, pNewCfg); - - if (!IamInNew) { - sError("sync reconfig error, not in new config"); + if (!syncNodeCheckNewConfig(pSyncNode, pNewCfg)) { taosReleaseRef(tsNodeRefId, pSyncNode->rid); - terrno = TSDB_CODE_SYN_NOT_IN_NEW_CONFIG; + terrno = TSDB_CODE_SYN_NEW_CONFIG_ERROR; + sError("syncNodeCheckNewConfig error"); return -1; } @@ -425,18 +443,6 @@ const char* syncGetMyRoleStr(int64_t rid) { return s; } -int32_t syncGetVgId(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return TAOS_SYNC_STATE_ERROR; - } - assert(rid == pSyncNode->rid); - int32_t vgId = pSyncNode->vgId; - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return vgId; -} - SyncTerm syncGetMyTerm(int64_t rid) { SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { @@ -449,6 +455,18 @@ SyncTerm syncGetMyTerm(int64_t rid) { return term; } +SyncGroupId syncGetVgId(int64_t rid) { + SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + if (pSyncNode == NULL) { + return TAOS_SYNC_STATE_ERROR; + } + assert(rid == pSyncNode->rid); + SyncGroupId vgId = pSyncNode->vgId; + + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return vgId; +} + void syncGetEpSet(int64_t rid, SEpSet* pEpSet) { SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { @@ -589,6 +607,26 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, const SRpcMsg* pMsg, bool isWeak) syncNodeEventLog(pSyncNode, eventLog); if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { + if (pSyncNode->changing && pMsg->msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH) { + ret = -1; + terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY; + sError("sync propose not ready, type:%s,%d", TMSG_INFO(pMsg->msgType), pMsg->msgType); + goto _END; + } + + // config change + if (pMsg->msgType == TDMT_SYNC_CONFIG_CHANGE) { + if (!syncNodeCanChange(pSyncNode)) { + ret = -1; + terrno = TSDB_CODE_SYN_RECONFIG_NOT_READY; + sError("sync reconfig not ready, type:%s,%d", TMSG_INFO(pMsg->msgType), pMsg->msgType); + goto _END; + } + + ASSERT(!pSyncNode->changing); + pSyncNode->changing = true; + } + SRespStub stub; stub.createTime = taosGetTimestampMs(); stub.rpcMsg = *pMsg; @@ -606,12 +644,16 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, const SRpcMsg* pMsg, bool isWeak) sError("syncPropose pSyncNode->FpEqMsg is NULL"); } syncClientRequestDestroy(pSyncMsg); + goto _END; + } else { ret = -1; terrno = TSDB_CODE_SYN_NOT_LEADER; sError("syncPropose not leader, %s", syncUtilState2String(pSyncNode->state)); + goto _END; } +_END: return ret; } @@ -809,9 +851,9 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { pSyncNode->restoreFinish = false; // pSyncNode->pSnapshot = NULL; - // if (pSyncNode->pFsm->FpGetSnapshot != NULL) { + // if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { // pSyncNode->pSnapshot = taosMemoryMalloc(sizeof(SSnapshot)); - // pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, pSyncNode->pSnapshot); + // pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, pSyncNode->pSnapshot); // } // tsem_init(&(pSyncNode->restoreSem), 0, 0); @@ -825,6 +867,9 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { // snapshot receivers pSyncNode->pNewNodeReceiver = snapshotReceiverCreate(pSyncNode, EMPTY_RAFT_ID); + // is config changing + pSyncNode->changing = false; + // start in syncNodeStart // start raft // syncNodeBecomeFollower(pSyncNode); @@ -841,15 +886,6 @@ void syncNodeStart(SSyncNode* pSyncNode) { syncNodeBecomeLeader(pSyncNode, "one replica start"); // Raft 3.6.2 Committing entries from previous terms - - // use this now - syncNodeAppendNoop(pSyncNode); - syncMaybeAdvanceCommitIndex(pSyncNode); // maybe only one replica - - if (gRaftDetailLog) { - syncNodeLog2("==state change become leader immediately==", pSyncNode); - } - return; } @@ -1246,6 +1282,9 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) { // snapshot receivers cJSON* pReceivers = cJSON_CreateArray(); cJSON_AddItemToObject(pRoot, "receiver", snapshotReceiver2Json(pSyncNode->pNewNodeReceiver)); + + // changing + cJSON_AddNumberToObject(pRoot, "changing", pSyncNode->changing); } cJSON* pJson = cJSON_CreateObject(); @@ -1262,20 +1301,37 @@ char* syncNode2Str(const SSyncNode* pSyncNode) { void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { int32_t userStrLen = strlen(str); + + SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; + if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + } + SyncIndex logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); + SyncIndex logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); + if (userStrLen < 256) { char logBuf[128 + 256]; snprintf(logBuf, sizeof(logBuf), - "vgId:%d %s term:%lu commit:%ld standby:%d replica-num:%d lconfig:%ld sync event %s", pSyncNode->vgId, - syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, - pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, str); + "vgId:%d, sync %s %s, term:%lu, commit:%ld, beginlog:%ld, lastlog:%ld, lastsnapshot:%ld, standby:%d, " + "replica-num:%d, " + "lconfig:%ld, changing:%d", + pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, + pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, + pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, + pSyncNode->changing); sDebug("%s", logBuf); + } else { int len = 128 + userStrLen; char* s = (char*)taosMemoryMalloc(len); - snprintf(s, len, "vgId:%d %s term:%lu commit:%ld standby:%d replica-num:%d lconfig:%ld sync event %s", - pSyncNode->vgId, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, - pSyncNode->commitIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum, - pSyncNode->pRaftCfg->lastConfigIndex, str); + snprintf(s, len, + "vgId:%d, sync %s %s, term:%lu, commit:%ld, beginlog:%ld, lastlog:%ld, lastsnapshot:%ld, standby:%d, " + "replica-num:%d, " + "lconfig:%ld, changing:%d", + pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, + pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, + pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, + pSyncNode->changing); sDebug("%s", s); taosMemoryFree(s); } @@ -1322,146 +1378,188 @@ bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config) { return b1; } -void syncNodeUpdateConfig(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncIndex lastConfigChangeIndex, bool* isDrop) { +void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncIndex lastConfigChangeIndex) { SSyncCfg oldConfig = pSyncNode->pRaftCfg->cfg; pSyncNode->pRaftCfg->cfg = *pNewConfig; pSyncNode->pRaftCfg->lastConfigIndex = lastConfigChangeIndex; - int32_t ret = 0; - - // save snapshot senders - int32_t oldReplicaNum = pSyncNode->replicaNum; - SRaftId oldReplicasId[TSDB_MAX_REPLICA]; - memcpy(oldReplicasId, pSyncNode->replicasId, sizeof(oldReplicasId)); - SSyncSnapshotSender* oldSenders[TSDB_MAX_REPLICA]; - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { - oldSenders[i] = (pSyncNode->senders)[i]; - - char* eventLog = snapshotSender2SimpleStr(oldSenders[i], "snapshot sender save old"); - syncNodeEventLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); - } - - // init internal - pSyncNode->myNodeInfo = pSyncNode->pRaftCfg->cfg.nodeInfo[pSyncNode->pRaftCfg->cfg.myIndex]; - syncUtilnodeInfo2raftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId); - - // init peersNum, peers, peersId - pSyncNode->peersNum = pSyncNode->pRaftCfg->cfg.replicaNum - 1; - int j = 0; - for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { - if (i != pSyncNode->pRaftCfg->cfg.myIndex) { - pSyncNode->peersNodeInfo[j] = pSyncNode->pRaftCfg->cfg.nodeInfo[i]; - j++; - } - } - for (int i = 0; i < pSyncNode->peersNum; ++i) { - syncUtilnodeInfo2raftId(&pSyncNode->peersNodeInfo[i], pSyncNode->vgId, &pSyncNode->peersId[i]); - } - - // init replicaNum, replicasId - pSyncNode->replicaNum = pSyncNode->pRaftCfg->cfg.replicaNum; - for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { - syncUtilnodeInfo2raftId(&pSyncNode->pRaftCfg->cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i]); - } - - syncIndexMgrUpdate(pSyncNode->pNextIndex, pSyncNode); - syncIndexMgrUpdate(pSyncNode->pMatchIndex, pSyncNode); - voteGrantedUpdate(pSyncNode->pVotesGranted, pSyncNode); - votesRespondUpdate(pSyncNode->pVotesRespond, pSyncNode); - - pSyncNode->quorum = syncUtilQuorum(pSyncNode->pRaftCfg->cfg.replicaNum); - - // reset snapshot senders - - // clear new - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { - (pSyncNode->senders)[i] = NULL; - } - - // reset new - for (int i = 0; i < pSyncNode->replicaNum; ++i) { - // reset sender - bool reset = false; - for (int j = 0; j < TSDB_MAX_REPLICA; ++j) { - if (syncUtilSameId(&(pSyncNode->replicasId)[i], &oldReplicasId[j])) { - char host[128]; - uint16_t port; - syncUtilU642Addr((pSyncNode->replicasId)[i].addr, host, sizeof(host), &port); - - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "snapshot sender reset for %lu, newIndex:%d, %s:%d, %p", - (pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]); - syncNodeEventLog(pSyncNode, eventLog); - } while (0); - - (pSyncNode->senders)[i] = oldSenders[j]; - oldSenders[j] = NULL; - reset = true; - - // reset replicaIndex - int32_t oldreplicaIndex = (pSyncNode->senders)[i]->replicaIndex; - (pSyncNode->senders)[i]->replicaIndex = i; - - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "snapshot sender udpate replicaIndex from %d to %d, %s:%d, %p, reset:%d", - oldreplicaIndex, i, host, port, (pSyncNode->senders)[i], reset); - syncNodeEventLog(pSyncNode, eventLog); - } while (0); - } - } - } - - // create new - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { - if ((pSyncNode->senders)[i] == NULL) { - (pSyncNode->senders)[i] = snapshotSenderCreate(pSyncNode, i); - - char* eventLog = snapshotSender2SimpleStr((pSyncNode->senders)[i], "snapshot sender create new"); - syncNodeEventLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); - } - } - - // free old - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { - if (oldSenders[i] != NULL) { - snapshotSenderDestroy(oldSenders[i]); - - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "snapshot sender delete old %p replica-index:%d", oldSenders[i], i); - syncNodeEventLog(pSyncNode, eventLog); - } while (0); - - oldSenders[i] = NULL; - } - } - bool IamInOld = syncNodeInConfig(pSyncNode, &oldConfig); bool IamInNew = syncNodeInConfig(pSyncNode, pNewConfig); - *isDrop = true; + bool isDrop = false; + bool isAdd = false; + if (IamInOld && !IamInNew) { - *isDrop = true; + isDrop = true; } else { - *isDrop = false; + isDrop = false; } - // may be add me to a new raft group - if (IamInOld && IamInNew && oldConfig.replicaNum == 1) { + if (!IamInOld && IamInNew) { + isAdd = true; + } else { + isAdd = false; } if (IamInNew) { pSyncNode->pRaftCfg->isStandBy = 0; // change isStandBy to normal } - raftCfgPersist(pSyncNode->pRaftCfg); - - if (gRaftDetailLog) { - syncNodeLog2("==syncNodeUpdateConfig==", pSyncNode); + if (isDrop) { + pSyncNode->pRaftCfg->isStandBy = 1; // set standby } + + // add last config index + raftCfgAddConfigIndex(pSyncNode->pRaftCfg, lastConfigChangeIndex); + + if (IamInNew) { + //----------------------------------------- + int32_t ret = 0; + + // save snapshot senders + int32_t oldReplicaNum = pSyncNode->replicaNum; + SRaftId oldReplicasId[TSDB_MAX_REPLICA]; + memcpy(oldReplicasId, pSyncNode->replicasId, sizeof(oldReplicasId)); + SSyncSnapshotSender* oldSenders[TSDB_MAX_REPLICA]; + for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + oldSenders[i] = (pSyncNode->senders)[i]; + + char* eventLog = snapshotSender2SimpleStr(oldSenders[i], "snapshot sender save old"); + syncNodeEventLog(pSyncNode, eventLog); + taosMemoryFree(eventLog); + } + + // init internal + pSyncNode->myNodeInfo = pSyncNode->pRaftCfg->cfg.nodeInfo[pSyncNode->pRaftCfg->cfg.myIndex]; + syncUtilnodeInfo2raftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId); + + // init peersNum, peers, peersId + pSyncNode->peersNum = pSyncNode->pRaftCfg->cfg.replicaNum - 1; + int j = 0; + for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { + if (i != pSyncNode->pRaftCfg->cfg.myIndex) { + pSyncNode->peersNodeInfo[j] = pSyncNode->pRaftCfg->cfg.nodeInfo[i]; + j++; + } + } + for (int i = 0; i < pSyncNode->peersNum; ++i) { + syncUtilnodeInfo2raftId(&pSyncNode->peersNodeInfo[i], pSyncNode->vgId, &pSyncNode->peersId[i]); + } + + // init replicaNum, replicasId + pSyncNode->replicaNum = pSyncNode->pRaftCfg->cfg.replicaNum; + for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { + syncUtilnodeInfo2raftId(&pSyncNode->pRaftCfg->cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i]); + } + + syncIndexMgrUpdate(pSyncNode->pNextIndex, pSyncNode); + syncIndexMgrUpdate(pSyncNode->pMatchIndex, pSyncNode); + voteGrantedUpdate(pSyncNode->pVotesGranted, pSyncNode); + votesRespondUpdate(pSyncNode->pVotesRespond, pSyncNode); + + pSyncNode->quorum = syncUtilQuorum(pSyncNode->pRaftCfg->cfg.replicaNum); + + // reset snapshot senders + + // clear new + for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + (pSyncNode->senders)[i] = NULL; + } + + // reset new + for (int i = 0; i < pSyncNode->replicaNum; ++i) { + // reset sender + bool reset = false; + for (int j = 0; j < TSDB_MAX_REPLICA; ++j) { + if (syncUtilSameId(&(pSyncNode->replicasId)[i], &oldReplicasId[j])) { + char host[128]; + uint16_t port; + syncUtilU642Addr((pSyncNode->replicasId)[i].addr, host, sizeof(host), &port); + + do { + char eventLog[256]; + snprintf(eventLog, sizeof(eventLog), "snapshot sender reset for %lu, newIndex:%d, %s:%d, %p", + (pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]); + syncNodeEventLog(pSyncNode, eventLog); + } while (0); + + (pSyncNode->senders)[i] = oldSenders[j]; + oldSenders[j] = NULL; + reset = true; + + // reset replicaIndex + int32_t oldreplicaIndex = (pSyncNode->senders)[i]->replicaIndex; + (pSyncNode->senders)[i]->replicaIndex = i; + + do { + char eventLog[256]; + snprintf(eventLog, sizeof(eventLog), + "snapshot sender udpate replicaIndex from %d to %d, %s:%d, %p, reset:%d", oldreplicaIndex, i, host, + port, (pSyncNode->senders)[i], reset); + syncNodeEventLog(pSyncNode, eventLog); + } while (0); + } + } + } + + // create new + for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + if ((pSyncNode->senders)[i] == NULL) { + (pSyncNode->senders)[i] = snapshotSenderCreate(pSyncNode, i); + + char* eventLog = snapshotSender2SimpleStr((pSyncNode->senders)[i], "snapshot sender create new"); + syncNodeEventLog(pSyncNode, eventLog); + taosMemoryFree(eventLog); + } + } + + // free old + for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + if (oldSenders[i] != NULL) { + snapshotSenderDestroy(oldSenders[i]); + + do { + char eventLog[128]; + snprintf(eventLog, sizeof(eventLog), "snapshot sender delete old %p replica-index:%d", oldSenders[i], i); + syncNodeEventLog(pSyncNode, eventLog); + } while (0); + + oldSenders[i] = NULL; + } + } + + // persist cfg + raftCfgPersist(pSyncNode->pRaftCfg); + + char tmpbuf[512]; + char* oldStr = syncCfg2SimpleStr(&oldConfig); + char* newStr = syncCfg2SimpleStr(pNewConfig); + snprintf(tmpbuf, sizeof(tmpbuf), "config change from %d to %d, index:%ld, %s --> %s", oldConfig.replicaNum, + pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); + taosMemoryFree(oldStr); + taosMemoryFree(newStr); + + // change isStandBy to normal (election timeout) + if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { + syncNodeBecomeLeader(pSyncNode, tmpbuf); + } else { + syncNodeBecomeFollower(pSyncNode, tmpbuf); + } + } else { + // persist cfg + raftCfgPersist(pSyncNode->pRaftCfg); + + char tmpbuf[512]; + char* oldStr = syncCfg2SimpleStr(&oldConfig); + char* newStr = syncCfg2SimpleStr(pNewConfig); + snprintf(tmpbuf, sizeof(tmpbuf), "do not config change from %d to %d, index:%ld, %s --> %s", oldConfig.replicaNum, + pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); + taosMemoryFree(oldStr); + taosMemoryFree(newStr); + syncNodeEventLog(pSyncNode, tmpbuf); + } + +_END: + return; } SSyncNode* syncNodeAcquire(int64_t rid) { @@ -1583,6 +1681,10 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { // start heartbeat timer syncNodeStartHeartbeatTimer(pSyncNode); + // append noop + syncNodeAppendNoop(pSyncNode); + syncMaybeAdvanceCommitIndex(pSyncNode); // maybe only one replica + // trace log do { int32_t debugStrLen = strlen(debugStr); @@ -1608,10 +1710,6 @@ void syncNodeCandidate2Leader(SSyncNode* pSyncNode) { // Raft 3.6.2 Committing entries from previous terms - // use this now - syncNodeAppendNoop(pSyncNode); - syncMaybeAdvanceCommitIndex(pSyncNode); // maybe only one replica - // do not use this // syncNodeEqNoop(pSyncNode); } @@ -1667,8 +1765,8 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode) { bool syncNodeHasSnapshot(SSyncNode* pSyncNode) { bool ret = false; SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; - if (pSyncNode->pFsm->FpGetSnapshot != NULL) { - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); if (snapshot.lastApplyIndex >= SYNC_INDEX_BEGIN) { ret = true; } @@ -1678,19 +1776,19 @@ bool syncNodeHasSnapshot(SSyncNode* pSyncNode) { bool syncNodeIsIndexInSnapshot(SSyncNode* pSyncNode, SyncIndex index) { ASSERT(syncNodeHasSnapshot(pSyncNode)); - ASSERT(pSyncNode->pFsm->FpGetSnapshot != NULL); + ASSERT(pSyncNode->pFsm->FpGetSnapshotInfo != NULL); ASSERT(index >= SYNC_INDEX_BEGIN); SSnapshot snapshot; - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); bool b = (index <= snapshot.lastApplyIndex); return b; } SyncIndex syncNodeGetLastIndex(SSyncNode* pSyncNode) { SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; - if (pSyncNode->pFsm->FpGetSnapshot != NULL) { - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); } SyncIndex logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); @@ -1703,8 +1801,8 @@ SyncTerm syncNodeGetLastTerm(SSyncNode* pSyncNode) { if (syncNodeHasSnapshot(pSyncNode)) { // has snapshot SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; - if (pSyncNode->pFsm->FpGetSnapshot != NULL) { - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); } SyncIndex logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); @@ -1737,7 +1835,11 @@ SyncIndex syncNodeSyncStartIndex(SSyncNode* pSyncNode) { SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index) { ASSERT(index >= SYNC_INDEX_BEGIN); SyncIndex syncStartIndex = syncNodeSyncStartIndex(pSyncNode); - ASSERT(index <= syncStartIndex); + + if (index > syncStartIndex) { + syncNodeLog3("syncNodeGetPreIndex", pSyncNode); + ASSERT(0); + } SyncIndex preIndex = index - 1; return preIndex; @@ -1746,7 +1848,11 @@ SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index) { SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { ASSERT(index >= SYNC_INDEX_BEGIN); SyncIndex syncStartIndex = syncNodeSyncStartIndex(pSyncNode); - ASSERT(index <= syncStartIndex); + + if (index > syncStartIndex) { + syncNodeLog3("syncNodeGetPreTerm", pSyncNode); + ASSERT(0); + } if (index == SYNC_INDEX_BEGIN) { return 0; @@ -1756,8 +1862,8 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { if (syncNodeHasSnapshot(pSyncNode)) { // has snapshot SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; - if (pSyncNode->pFsm->FpGetSnapshot != NULL) { - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); } if (index > snapshot.lastApplyIndex + 1) { @@ -1839,6 +1945,12 @@ void syncNodeLog2(char* s, SSyncNode* pObj) { } } +void syncNodeLog3(char* s, SSyncNode* pObj) { + char* serialized = syncNode2Str(pObj); + sTraceLong("syncNodeLog3 | len:%lu | %s | %s", strlen(serialized), s, serialized); + taosMemoryFree(serialized); +} + // ------ local funciton --------- // enqueue message ---- static void syncNodeEqPingTimer(void* param, void* tmrId) { @@ -2179,9 +2291,57 @@ int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg) { return -1; } -static int32_t syncNodeConfigChange(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry) { +static int32_t syncNodeConfigChangeFinish(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry) { + SyncReconfigFinish* pFinish = syncReconfigFinishFromRpcMsg2(pRpcMsg); + ASSERT(pFinish); + + if (ths->pFsm->FpReConfigCb != NULL) { + SReConfigCbMeta cbMeta = {0}; + cbMeta.code = 0; + cbMeta.index = pEntry->index; + cbMeta.term = pEntry->term; + cbMeta.seqNum = pEntry->seqNum; + cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, pEntry->index); + cbMeta.state = ths->state; + cbMeta.currentTerm = ths->pRaftStore->currentTerm; + cbMeta.isWeak = pEntry->isWeak; + cbMeta.flag = 0; + + cbMeta.oldCfg = pFinish->oldCfg; + cbMeta.newCfg = pFinish->newCfg; + cbMeta.newCfgIndex = pFinish->newCfgIndex; + cbMeta.newCfgTerm = pFinish->newCfgTerm; + cbMeta.newCfgSeqNum = pFinish->newCfgSeqNum; + + ths->pFsm->FpReConfigCb(ths->pFsm, pRpcMsg, cbMeta); + } + + // clear changing + ths->changing = false; + + char tmpbuf[512]; + char* oldStr = syncCfg2SimpleStr(&(pFinish->oldCfg)); + char* newStr = syncCfg2SimpleStr(&(pFinish->newCfg)); + snprintf(tmpbuf, sizeof(tmpbuf), "config change finish from %d to %d, index:%ld, %s --> %s", + pFinish->oldCfg.replicaNum, pFinish->newCfg.replicaNum, pFinish->newCfgIndex, oldStr, newStr); + taosMemoryFree(oldStr); + taosMemoryFree(newStr); + syncNodeEventLog(ths, tmpbuf); + + syncReconfigFinishDestroy(pFinish); + + return 0; +} + +static int32_t syncNodeConfigChange(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry, + SyncReconfigFinish* pFinish) { + // set changing + ths->changing = true; + + // old config SSyncCfg oldSyncCfg = ths->pRaftCfg->cfg; + // new config SSyncCfg newSyncCfg; int32_t ret = syncCfgFromStr(pRpcMsg->pCont, &newSyncCfg); ASSERT(ret == 0); @@ -2189,77 +2349,28 @@ static int32_t syncNodeConfigChange(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftE // update new config myIndex syncNodeUpdateNewConfigIndex(ths, &newSyncCfg); - bool IamInNew = syncNodeInConfig(ths, &newSyncCfg); + // do config change + syncNodeDoConfigChange(ths, &newSyncCfg, pEntry->index); - /* - for (int i = 0; i < newSyncCfg.replicaNum; ++i) { - if (strcmp(ths->myNodeInfo.nodeFqdn, (newSyncCfg.nodeInfo)[i].nodeFqdn) == 0 && - ths->myNodeInfo.nodePort == (newSyncCfg.nodeInfo)[i].nodePort) { - newSyncCfg.myIndex = i; - IamInNew = true; - break; - } - } - */ + // set pFinish + pFinish->oldCfg = oldSyncCfg; + pFinish->newCfg = newSyncCfg; + pFinish->newCfgIndex = pEntry->index; + pFinish->newCfgTerm = pEntry->term; + pFinish->newCfgSeqNum = pEntry->seqNum; - bool isDrop; + return 0; +} - if (IamInNew) { - syncNodeUpdateConfig(ths, &newSyncCfg, pEntry->index, &isDrop); +static int32_t syncNodeProposeConfigChangeFinish(SSyncNode* ths, SyncReconfigFinish* pFinish) { + SRpcMsg rpcMsg; + syncReconfigFinish2RpcMsg(pFinish, &rpcMsg); - // change isStandBy to normal - if (!isDrop) { - char tmpbuf[512]; - char* oldStr = syncCfg2SimpleStr(&oldSyncCfg); - char* newStr = syncCfg2SimpleStr(&newSyncCfg); - snprintf(tmpbuf, sizeof(tmpbuf), "config change from %d to %d, index:%ld, %s --> %s", oldSyncCfg.replicaNum, - newSyncCfg.replicaNum, pEntry->index, oldStr, newStr); - taosMemoryFree(oldStr); - taosMemoryFree(newStr); - - if (ths->state == TAOS_SYNC_STATE_LEADER) { - syncNodeBecomeLeader(ths, tmpbuf); - } else { - syncNodeBecomeFollower(ths, tmpbuf); - } - } - } else { - char tmpbuf[512]; - char* oldStr = syncCfg2SimpleStr(&oldSyncCfg); - char* newStr = syncCfg2SimpleStr(&newSyncCfg); - snprintf(tmpbuf, sizeof(tmpbuf), "config change2 from %d to %d, index:%ld, %s --> %s", oldSyncCfg.replicaNum, - newSyncCfg.replicaNum, pEntry->index, oldStr, newStr); - taosMemoryFree(oldStr); - taosMemoryFree(newStr); - - syncNodeBecomeFollower(ths, tmpbuf); + int32_t code = syncNodePropose(ths, &rpcMsg, false); + if (code != 0) { + sError("syncNodeProposeConfigChangeFinish error"); + ths->changing = false; } - - if (gRaftDetailLog) { - char* sOld = syncCfg2Str(&oldSyncCfg); - char* sNew = syncCfg2Str(&newSyncCfg); - sInfo("==config change== 0x11 old:%s new:%s isDrop:%d index:%ld IamInNew:%d \n", sOld, sNew, isDrop, pEntry->index, - IamInNew); - taosMemoryFree(sOld); - taosMemoryFree(sNew); - } - - // always call FpReConfigCb - if (ths->pFsm->FpReConfigCb != NULL) { - SReConfigCbMeta cbMeta = {0}; - cbMeta.code = 0; - cbMeta.currentTerm = ths->pRaftStore->currentTerm; - cbMeta.index = pEntry->index; - cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, pEntry->index); - cbMeta.term = pEntry->term; - cbMeta.newCfg = newSyncCfg; - cbMeta.oldCfg = oldSyncCfg; - cbMeta.seqNum = pEntry->seqNum; - cbMeta.flag = 0x11; - cbMeta.isDrop = isDrop; - ths->pFsm->FpReConfigCb(ths->pFsm, pRpcMsg, cbMeta); - } - return 0; } @@ -2301,9 +2412,21 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, // config change if (pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE) { - raftCfgAddConfigIndex(ths->pRaftCfg, pEntry->index); - raftCfgPersist(ths->pRaftCfg); - code = syncNodeConfigChange(ths, &rpcMsg, pEntry); + SyncReconfigFinish* pFinish = syncReconfigFinishBuild(ths->vgId); + ASSERT(pFinish != NULL); + + code = syncNodeConfigChange(ths, &rpcMsg, pEntry, pFinish); + ASSERT(code == 0); + + if (ths->state == TAOS_SYNC_STATE_LEADER) { + syncNodeProposeConfigChangeFinish(ths, pFinish); + } + syncReconfigFinishDestroy(pFinish); + } + + // config change finish + if (pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE_FINISH) { + code = syncNodeConfigChangeFinish(ths, &rpcMsg, pEntry); ASSERT(code == 0); } @@ -2354,3 +2477,28 @@ SSyncSnapshotSender* syncNodeGetSnapshotSender(SSyncNode* ths, SRaftId* pDestId) } return pSender; } + +bool syncNodeCanChange(SSyncNode* pSyncNode) { + if (pSyncNode->changing) { + sError("sync cannot change"); + return false; + } + + if ((pSyncNode->commitIndex >= SYNC_INDEX_BEGIN)) { + SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode); + if (pSyncNode->commitIndex != lastIndex) { + sError("sync cannot change2"); + return false; + } + } + + for (int i = 0; i < pSyncNode->peersNum; ++i) { + SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->peersId)[i]); + if (pSender->start) { + sError("sync cannot change3"); + return false; + } + } + + return true; +} \ No newline at end of file diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 23165f6790..454609009c 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -2227,4 +2227,133 @@ void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg) { sTrace("syncLeaderTransferLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } +} + +// --------------------------------------------- +SyncReconfigFinish* syncReconfigFinishBuild(int32_t vgId) { + uint32_t bytes = sizeof(SyncReconfigFinish); + SyncReconfigFinish* pMsg = taosMemoryMalloc(bytes); + memset(pMsg, 0, bytes); + pMsg->bytes = bytes; + pMsg->vgId = vgId; + pMsg->msgType = TDMT_SYNC_CONFIG_CHANGE_FINISH; + return pMsg; +} + +void syncReconfigFinishDestroy(SyncReconfigFinish* pMsg) { + if (pMsg != NULL) { + taosMemoryFree(pMsg); + } +} + +void syncReconfigFinishSerialize(const SyncReconfigFinish* pMsg, char* buf, uint32_t bufLen) { + assert(pMsg->bytes <= bufLen); + memcpy(buf, pMsg, pMsg->bytes); +} + +void syncReconfigFinishDeserialize(const char* buf, uint32_t len, SyncReconfigFinish* pMsg) { + memcpy(pMsg, buf, len); + assert(len == pMsg->bytes); +} + +char* syncReconfigFinishSerialize2(const SyncReconfigFinish* pMsg, uint32_t* len) { + char* buf = taosMemoryMalloc(pMsg->bytes); + assert(buf != NULL); + syncReconfigFinishSerialize(pMsg, buf, pMsg->bytes); + if (len != NULL) { + *len = pMsg->bytes; + } + return buf; +} + +SyncReconfigFinish* syncReconfigFinishDeserialize2(const char* buf, uint32_t len) { + uint32_t bytes = *((uint32_t*)buf); + SyncReconfigFinish* pMsg = taosMemoryMalloc(bytes); + assert(pMsg != NULL); + syncReconfigFinishDeserialize(buf, len, pMsg); + assert(len == pMsg->bytes); + return pMsg; +} + +void syncReconfigFinish2RpcMsg(const SyncReconfigFinish* pMsg, SRpcMsg* pRpcMsg) { + memset(pRpcMsg, 0, sizeof(*pRpcMsg)); + pRpcMsg->msgType = pMsg->msgType; + pRpcMsg->contLen = pMsg->bytes; + pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); + syncReconfigFinishSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); +} + +void syncReconfigFinishFromRpcMsg(const SRpcMsg* pRpcMsg, SyncReconfigFinish* pMsg) { + syncReconfigFinishDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); +} + +SyncReconfigFinish* syncReconfigFinishFromRpcMsg2(const SRpcMsg* pRpcMsg) { + SyncReconfigFinish* pMsg = syncReconfigFinishDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + assert(pMsg != NULL); + return pMsg; +} + +cJSON* syncReconfigFinish2Json(const SyncReconfigFinish* pMsg) { + char u64buf[128]; + cJSON* pRoot = cJSON_CreateObject(); + + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + + cJSON* pOldCfg = syncCfg2Json((SSyncCfg*)(&(pMsg->oldCfg))); + cJSON* pNewCfg = syncCfg2Json((SSyncCfg*)(&(pMsg->newCfg))); + cJSON_AddItemToObject(pRoot, "oldCfg", pOldCfg); + cJSON_AddItemToObject(pRoot, "newCfg", pNewCfg); + + snprintf(u64buf, sizeof(u64buf), "%ld", pMsg->newCfgIndex); + cJSON_AddStringToObject(pRoot, "newCfgIndex", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->newCfgTerm); + cJSON_AddStringToObject(pRoot, "newCfgTerm", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->newCfgSeqNum); + cJSON_AddStringToObject(pRoot, "newCfgSeqNum", u64buf); + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SyncReconfigFinish", pRoot); + return pJson; +} + +char* syncReconfigFinish2Str(const SyncReconfigFinish* pMsg) { + cJSON* pJson = syncReconfigFinish2Json(pMsg); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + +// for debug ---------------------- +void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg) { + char* serialized = syncReconfigFinish2Str(pMsg); + printf("syncReconfigFinishPrint | len:%lu | %s \n", strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg) { + char* serialized = syncReconfigFinish2Str(pMsg); + printf("syncReconfigFinishPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncReconfigFinishLog(const SyncReconfigFinish* pMsg) { + char* serialized = syncReconfigFinish2Str(pMsg); + sTrace("syncReconfigFinishLog | len:%lu | %s", strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) { + if (gRaftDetailLog) { + char* serialized = syncReconfigFinish2Str(pMsg); + sTrace("syncReconfigFinishLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } } \ No newline at end of file diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index a8242d06e3..7d020f6892 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -53,7 +53,12 @@ int32_t raftCfgPersist(SRaftCfg *pRaftCfg) { char buf[CONFIG_FILE_LEN] = {0}; memset(buf, 0, sizeof(buf)); - ASSERT(strlen(s) + 1 <= CONFIG_FILE_LEN); + + if (strlen(s) + 1 > CONFIG_FILE_LEN) { + sError("too long config str:%s", s); + ASSERT(0); + } + snprintf(buf, sizeof(buf), "%s", s); int64_t ret = taosWriteFile(pRaftCfg->pFile, buf, sizeof(buf)); assert(ret == sizeof(buf)); diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index 08564f8293..f044ae5733 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -124,7 +124,7 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) { logStoreSimpleLog2("begin append entries peers LogStore:", pSyncNode->pLogStore); if (gRaftDetailLog) { SSnapshot snapshot; - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); sTrace("begin append entries peers, snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu", snapshot.lastApplyIndex, snapshot.lastApplyTerm); } diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index d1bfc39d1e..68185131d1 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -21,7 +21,8 @@ #include "syncUtil.h" #include "wal.h" -static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, SRaftId fromId); +static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, + SyncSnapshotSend *pBeginMsg); //---------------------------------- SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex) { @@ -45,7 +46,7 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI pSender->replicaIndex = replicaIndex; pSender->term = pSyncNode->pRaftStore->currentTerm; pSender->privateTerm = taosGetTimestampMs() + 100; - pSender->pSyncNode->pFsm->FpGetSnapshot(pSender->pSyncNode->pFsm, &(pSender->snapshot)); + pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &(pSender->snapshot)); pSender->finish = false; } else { sError("snapshotSenderCreate cannot create sender"); @@ -66,7 +67,7 @@ void snapshotSenderDestroy(SSyncSnapshotSender *pSender) { bool snapshotSenderIsStart(SSyncSnapshotSender *pSender) { return pSender->start; } // begin send snapshot (current term, seq begin) -void snapshotSenderStart(SSyncSnapshotSender *pSender) { +void snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshot snapshot, void *pReader) { ASSERT(!snapshotSenderIsStart(pSender)); pSender->seq = SYNC_SNAPSHOT_SEQ_BEGIN; @@ -74,8 +75,18 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) { // open snapshot reader ASSERT(pSender->pReader == NULL); - int32_t ret = pSender->pSyncNode->pFsm->FpSnapshotStartRead(pSender->pSyncNode->pFsm, &(pSender->pReader)); - ASSERT(ret == 0); + pSender->pReader = pReader; + pSender->snapshot = snapshot; + + /* + // open snapshot reader + ASSERT(pSender->pReader == NULL); + int32_t ret = pSender->pSyncNode->pFsm->FpSnapshotStartRead(pSender->pSyncNode->pFsm, &(pSender->pReader)); + ASSERT(ret == 0); + + // get current snapshot info + pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &(pSender->snapshot)); + */ if (pSender->pCurrentBlock != NULL) { taosMemoryFree(pSender->pCurrentBlock); @@ -83,21 +94,7 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) { pSender->blockLen = 0; - // get current snapshot info - pSender->pSyncNode->pFsm->FpGetSnapshot(pSender->pSyncNode->pFsm, &(pSender->snapshot)); - - sTrace("snapshotSenderStart lastApplyIndex:%ld, lastApplyTerm:%lu, lastConfigIndex:%ld", - pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm, pSender->snapshot.lastConfigIndex); - if (pSender->snapshot.lastConfigIndex != SYNC_INDEX_INVALID) { - /* - SSyncRaftEntry *pEntry = NULL; - int32_t code = pSender->pSyncNode->pLogStore->syncLogGetEntry(pSender->pSyncNode->pLogStore, - pSender->snapshot.lastConfigIndex, &pEntry); - ASSERT(code == 0); - ASSERT(pEntry != NULL); - */ - SSyncRaftEntry *pEntry = pSender->pSyncNode->pLogStore->getEntry(pSender->pSyncNode->pLogStore, pSender->snapshot.lastConfigIndex); ASSERT(pEntry != NULL); @@ -341,6 +338,10 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId from pReceiver->fromId = fromId; pReceiver->term = pSyncNode->pRaftStore->currentTerm; pReceiver->privateTerm = 0; + pReceiver->snapshot.data = NULL; + pReceiver->snapshot.lastApplyIndex = -1; + pReceiver->snapshot.lastApplyTerm = 0; + pReceiver->snapshot.lastConfigIndex = -1; } else { sInfo("snapshotReceiverCreate cannot create receiver"); @@ -358,11 +359,16 @@ void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver) { bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver) { return pReceiver->start; } // begin receive snapshot msg (current term, seq begin) -static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, SRaftId fromId) { +static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, + SyncSnapshotSend *pBeginMsg) { pReceiver->term = pReceiver->pSyncNode->pRaftStore->currentTerm; pReceiver->privateTerm = privateTerm; pReceiver->ack = SYNC_SNAPSHOT_SEQ_BEGIN; - pReceiver->fromId = fromId; + pReceiver->fromId = pBeginMsg->srcId; + + pReceiver->snapshot.lastApplyIndex = pBeginMsg->lastIndex; + pReceiver->snapshot.lastApplyTerm = pBeginMsg->lastTerm; + pReceiver->snapshot.lastConfigIndex = pBeginMsg->lastConfigIndex; ASSERT(pReceiver->pWriter == NULL); int32_t ret = pReceiver->pSyncNode->pFsm->FpSnapshotStartWrite(pReceiver->pSyncNode->pFsm, &(pReceiver->pWriter)); @@ -371,10 +377,10 @@ static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm p // if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver // if already start, force close, start again -void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, SRaftId fromId) { +void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, SyncSnapshotSend *pBeginMsg) { if (!snapshotReceiverIsStart(pReceiver)) { // start - snapshotReceiverDoStart(pReceiver, privateTerm, fromId); + snapshotReceiverDoStart(pReceiver, privateTerm, pBeginMsg); pReceiver->start = true; } else { @@ -388,7 +394,7 @@ void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTer pReceiver->pWriter = NULL; // start again - snapshotReceiverDoStart(pReceiver, privateTerm, fromId); + snapshotReceiverDoStart(pReceiver, privateTerm, pBeginMsg); pReceiver->start = true; } @@ -449,6 +455,15 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) { cJSON_AddNumberToObject(pFromId, "vgId", pReceiver->fromId.vgId); cJSON_AddItemToObject(pRoot, "fromId", pFromId); + snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->snapshot.lastApplyIndex); + cJSON_AddStringToObject(pRoot, "snapshot.lastApplyIndex", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->snapshot.lastApplyTerm); + cJSON_AddStringToObject(pRoot, "snapshot.lastApplyTerm", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->snapshot.lastConfigIndex); + cJSON_AddStringToObject(pRoot, "snapshot.lastConfigIndex", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->term); cJSON_AddStringToObject(pRoot, "term", u64buf); @@ -477,8 +492,9 @@ char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event) uint16_t port; syncUtilU642Addr(fromId.addr, host, sizeof(host), &port); - snprintf(s, len, "%s %p start:%d ack:%d term:%lu pterm:%lu %s:%d ", event, pReceiver, pReceiver->start, - pReceiver->ack, pReceiver->term, pReceiver->privateTerm, host, port); + snprintf(s, len, "%s %p start:%d ack:%d term:%lu pterm:%lu from:%s:%d laindex:%ld laterm:%lu lcindex:%ld", event, + pReceiver, pReceiver->start, pReceiver->ack, pReceiver->term, pReceiver->privateTerm, host, port, + pReceiver->snapshot.lastApplyIndex, pReceiver->snapshot.lastApplyTerm, pReceiver->snapshot.lastConfigIndex); return s; } @@ -495,7 +511,7 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { if (pMsg->term == pSyncNode->pRaftStore->currentTerm) { if (pMsg->seq == SYNC_SNAPSHOT_SEQ_BEGIN) { // begin - snapshotReceiverStart(pReceiver, pMsg->privateTerm, pMsg->srcId); + snapshotReceiverStart(pReceiver, pMsg->privateTerm, pMsg); pReceiver->ack = pMsg->seq; needRsp = true; @@ -519,46 +535,13 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { // update new config myIndex SSyncCfg newSyncCfg = pMsg->lastConfig; syncNodeUpdateNewConfigIndex(pSyncNode, &newSyncCfg); - bool IamInNew = syncNodeInConfig(pSyncNode, &newSyncCfg); - bool isDrop = false; - if (IamInNew) { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), - "update config by snapshot, lastIndex:%ld, lastTerm:%lu, lastConfigIndex:%ld", pMsg->lastIndex, - pMsg->lastTerm, pMsg->lastConfigIndex); - syncNodeEventLog(pSyncNode, eventLog); - - syncNodeUpdateConfig(pSyncNode, &newSyncCfg, pMsg->lastConfigIndex, &isDrop); - - } else { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), - "do not update config by snapshot, not in new, lastIndex:%ld, lastTerm:%lu, lastConfigIndex:%ld", - pMsg->lastIndex, pMsg->lastTerm, pMsg->lastConfigIndex); - syncNodeEventLog(pSyncNode, eventLog); - } - - // change isStandBy to normal - if (!isDrop) { - char tmpbuf[512]; - char *oldStr = syncCfg2SimpleStr(&oldSyncCfg); - char *newStr = syncCfg2SimpleStr(&newSyncCfg); - snprintf(tmpbuf, sizeof(tmpbuf), "config change3 from %d to %d, index:%ld, %s --> %s", - oldSyncCfg.replicaNum, newSyncCfg.replicaNum, pMsg->lastConfigIndex, oldStr, newStr); - taosMemoryFree(oldStr); - taosMemoryFree(newStr); - - if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { - syncNodeBecomeLeader(pSyncNode, tmpbuf); - } else { - syncNodeBecomeFollower(pSyncNode, tmpbuf); - } - } + // do config change + syncNodeDoConfigChange(pSyncNode, &newSyncCfg, pMsg->lastConfigIndex); } SSnapshot snapshot; - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); do { char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver finish"); diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index cbc1298113..1d1ff7ae53 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -261,23 +261,29 @@ bool syncUtilIsData(tmsg_t msgType) { #endif bool syncUtilUserPreCommit(tmsg_t msgType) { - if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_LEADER_TRANSFER) { + if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH && + msgType != TDMT_SYNC_LEADER_TRANSFER) { return true; } + return false; } bool syncUtilUserCommit(tmsg_t msgType) { - if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_LEADER_TRANSFER) { + if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH && + msgType != TDMT_SYNC_LEADER_TRANSFER) { return true; } + return false; } bool syncUtilUserRollback(tmsg_t msgType) { - if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_LEADER_TRANSFER) { + if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH && + msgType != TDMT_SYNC_LEADER_TRANSFER) { return true; } + return false; } diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index 725343e373..2057aa23a4 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -49,6 +49,7 @@ add_executable(syncRaftLogTest "") add_executable(syncRaftLogTest2 "") add_executable(syncRaftLogTest3 "") add_executable(syncLeaderTransferTest "") +add_executable(syncReconfigFinishTest "") target_sources(syncTest @@ -255,6 +256,10 @@ target_sources(syncLeaderTransferTest PRIVATE "syncLeaderTransferTest.cpp" ) +target_sources(syncReconfigFinishTest + PRIVATE + "syncReconfigFinishTest.cpp" +) target_include_directories(syncTest @@ -512,6 +517,11 @@ target_include_directories(syncLeaderTransferTest "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) +target_include_directories(syncReconfigFinishTest + PUBLIC + "${TD_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) target_link_libraries(syncTest @@ -718,6 +728,10 @@ target_link_libraries(syncLeaderTransferTest sync gtest_main ) +target_link_libraries(syncReconfigFinishTest + sync + gtest_main +) enable_testing() diff --git a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp index 3ee2b458d6..b4f173ff02 100644 --- a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp +++ b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp @@ -36,9 +36,9 @@ void cleanup() { walCleanUp(); } void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { SyncIndex beginIndex = SYNC_INDEX_INVALID; - if (pFsm->FpGetSnapshot != NULL) { + if (pFsm->FpGetSnapshotInfo != NULL) { SSnapshot snapshot; - pFsm->FpGetSnapshot(pFsm, &snapshot); + pFsm->FpGetSnapshotInfo(pFsm, &snapshot); beginIndex = snapshot.lastApplyIndex; } @@ -147,8 +147,8 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_ void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); } void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) { - sTrace("==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu", - cbMeta.flag, cbMeta.isDrop, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); + sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%ld, code:%d, currentTerm:%lu, term:%lu", cbMeta.flag, + cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); } SSyncFSM* createFsm() { @@ -159,7 +159,7 @@ SSyncFSM* createFsm() { pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; - pFsm->FpGetSnapshot = GetSnapshotCb; + pFsm->FpGetSnapshotInfo = GetSnapshotCb; pFsm->FpRestoreFinishCb = RestoreFinishCb; pFsm->FpSnapshotStartRead = SnapshotStartRead; pFsm->FpSnapshotStopRead = SnapshotStopRead; diff --git a/source/libs/sync/test/syncConfigChangeTest.cpp b/source/libs/sync/test/syncConfigChangeTest.cpp index b1dc53d804..c96e337378 100644 --- a/source/libs/sync/test/syncConfigChangeTest.cpp +++ b/source/libs/sync/test/syncConfigChangeTest.cpp @@ -35,9 +35,9 @@ void cleanup() { walCleanUp(); } void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { SyncIndex beginIndex = SYNC_INDEX_INVALID; - if (pFsm->FpGetSnapshot != NULL) { + if (pFsm->FpGetSnapshotInfo != NULL) { SSnapshot snapshot; - pFsm->FpGetSnapshot(pFsm, &snapshot); + pFsm->FpGetSnapshotInfo(pFsm, &snapshot); beginIndex = snapshot.lastApplyIndex; } @@ -78,8 +78,8 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); } void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) { - sTrace("==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu", - cbMeta.flag, cbMeta.isDrop, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); + sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%ld, code:%d, currentTerm:%lu, term:%lu", cbMeta.flag, + cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); } SSyncFSM* createFsm() { @@ -90,7 +90,7 @@ SSyncFSM* createFsm() { pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; - pFsm->FpGetSnapshot = GetSnapshotCb; + pFsm->FpGetSnapshotInfo = GetSnapshotCb; pFsm->FpRestoreFinishCb = RestoreFinishCb; pFsm->FpReConfigCb = ReConfigCb; diff --git a/source/libs/sync/test/syncRaftCfgTest.cpp b/source/libs/sync/test/syncRaftCfgTest.cpp index 8171d266d4..0f111ef22c 100644 --- a/source/libs/sync/test/syncRaftCfgTest.cpp +++ b/source/libs/sync/test/syncRaftCfgTest.cpp @@ -137,6 +137,6 @@ int main() { test3(); test4(); test5(); - + return 0; } diff --git a/source/libs/sync/test/syncRaftLogTest2.cpp b/source/libs/sync/test/syncRaftLogTest2.cpp index 64e1da51a1..32ff441a6f 100644 --- a/source/libs/sync/test/syncRaftLogTest2.cpp +++ b/source/libs/sync/test/syncRaftLogTest2.cpp @@ -54,7 +54,7 @@ void init() { pSyncNode->pWal = pWal; pSyncNode->pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(SSyncFSM)); - pSyncNode->pFsm->FpGetSnapshot = GetSnapshotCb; + pSyncNode->pFsm->FpGetSnapshotInfo = GetSnapshotCb; } void cleanup() { diff --git a/source/libs/sync/test/syncRaftLogTest3.cpp b/source/libs/sync/test/syncRaftLogTest3.cpp index b47f8c96c5..c81a6d3ca9 100644 --- a/source/libs/sync/test/syncRaftLogTest3.cpp +++ b/source/libs/sync/test/syncRaftLogTest3.cpp @@ -54,7 +54,7 @@ void init() { pSyncNode->pWal = pWal; pSyncNode->pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(SSyncFSM)); - pSyncNode->pFsm->FpGetSnapshot = GetSnapshotCb; + pSyncNode->pFsm->FpGetSnapshotInfo = GetSnapshotCb; } void cleanup() { @@ -80,7 +80,7 @@ void test1() { bool hasSnapshot = syncNodeHasSnapshot(pSyncNode); SSnapshot snapshot; - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode); SyncTerm lastTerm = syncNodeGetLastTerm(pSyncNode); @@ -146,7 +146,7 @@ void test2() { bool hasSnapshot = syncNodeHasSnapshot(pSyncNode); SSnapshot snapshot; - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode); SyncTerm lastTerm = syncNodeGetLastTerm(pSyncNode); @@ -203,7 +203,7 @@ void test3() { bool hasSnapshot = syncNodeHasSnapshot(pSyncNode); SSnapshot snapshot; - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode); SyncTerm lastTerm = syncNodeGetLastTerm(pSyncNode); @@ -268,7 +268,7 @@ void test4() { bool hasSnapshot = syncNodeHasSnapshot(pSyncNode); SSnapshot snapshot; - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode); SyncTerm lastTerm = syncNodeGetLastTerm(pSyncNode); @@ -335,7 +335,7 @@ void test5() { bool hasSnapshot = syncNodeHasSnapshot(pSyncNode); SSnapshot snapshot; - pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot); + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode); SyncTerm lastTerm = syncNodeGetLastTerm(pSyncNode); diff --git a/source/libs/sync/test/syncReconfigFinishTest.cpp b/source/libs/sync/test/syncReconfigFinishTest.cpp new file mode 100644 index 0000000000..2aac38bbd1 --- /dev/null +++ b/source/libs/sync/test/syncReconfigFinishTest.cpp @@ -0,0 +1,133 @@ +#include +#include +#include "syncIO.h" +#include "syncInt.h" +#include "syncMessage.h" +#include "syncUtil.h" + +void logTest() { + sTrace("--- sync log test: trace"); + sDebug("--- sync log test: debug"); + sInfo("--- sync log test: info"); + sWarn("--- sync log test: warn"); + sError("--- sync log test: error"); + sFatal("--- sync log test: fatal"); +} + +SSyncCfg *createSyncOldCfg() { + SSyncCfg *pCfg = (SSyncCfg *)taosMemoryMalloc(sizeof(SSyncCfg)); + memset(pCfg, 0, sizeof(SSyncCfg)); + + pCfg->replicaNum = 3; + pCfg->myIndex = 1; + for (int i = 0; i < pCfg->replicaNum; ++i) { + ((pCfg->nodeInfo)[i]).nodePort = i * 100; + snprintf(((pCfg->nodeInfo)[i]).nodeFqdn, sizeof(((pCfg->nodeInfo)[i]).nodeFqdn), "100.200.300.%d", i); + } + + return pCfg; +} + +SSyncCfg *createSyncNewCfg() { + SSyncCfg *pCfg = (SSyncCfg *)taosMemoryMalloc(sizeof(SSyncCfg)); + memset(pCfg, 0, sizeof(SSyncCfg)); + + pCfg->replicaNum = 3; + pCfg->myIndex = 1; + for (int i = 0; i < pCfg->replicaNum; ++i) { + ((pCfg->nodeInfo)[i]).nodePort = i * 100; + snprintf(((pCfg->nodeInfo)[i]).nodeFqdn, sizeof(((pCfg->nodeInfo)[i]).nodeFqdn), "500.600.700.%d", i); + } + + return pCfg; +} + +SyncReconfigFinish *createMsg() { + SyncReconfigFinish *pMsg = syncReconfigFinishBuild(1234); + + SSyncCfg *pOld = createSyncOldCfg(); + SSyncCfg *pNew = createSyncNewCfg(); + pMsg->oldCfg = *pOld; + pMsg->newCfg = *pNew; + + pMsg->newCfgIndex = 11; + pMsg->newCfgTerm = 22; + pMsg->newCfgSeqNum = 33; + + taosMemoryFree(pOld); + taosMemoryFree(pNew); + + return pMsg; +} + +void test1() { + SyncReconfigFinish *pMsg = createMsg(); + syncReconfigFinishLog2((char *)"test1:", pMsg); + syncReconfigFinishDestroy(pMsg); +} + +void test2() { + SyncReconfigFinish *pMsg = createMsg(); + uint32_t len = pMsg->bytes; + char * serialized = (char *)taosMemoryMalloc(len); + syncReconfigFinishSerialize(pMsg, serialized, len); + SyncReconfigFinish *pMsg2 = syncReconfigFinishBuild(1000); + syncReconfigFinishDeserialize(serialized, len, pMsg2); + syncReconfigFinishLog2((char *)"test2: syncReconfigFinishSerialize -> syncReconfigFinishDeserialize ", pMsg2); + + taosMemoryFree(serialized); + syncReconfigFinishDestroy(pMsg); + syncReconfigFinishDestroy(pMsg2); +} + +void test3() { + SyncReconfigFinish *pMsg = createMsg(); + uint32_t len; + char * serialized = syncReconfigFinishSerialize2(pMsg, &len); + SyncReconfigFinish *pMsg2 = syncReconfigFinishDeserialize2(serialized, len); + syncReconfigFinishLog2((char *)"test3: SyncReconfigFinishSerialize2 -> syncReconfigFinishDeserialize2 ", pMsg2); + + taosMemoryFree(serialized); + syncReconfigFinishDestroy(pMsg); + syncReconfigFinishDestroy(pMsg2); +} + +void test4() { + SyncReconfigFinish *pMsg = createMsg(); + SRpcMsg rpcMsg; + syncReconfigFinish2RpcMsg(pMsg, &rpcMsg); + SyncReconfigFinish *pMsg2 = (SyncReconfigFinish *)taosMemoryMalloc(rpcMsg.contLen); + syncReconfigFinishFromRpcMsg(&rpcMsg, pMsg2); + syncReconfigFinishLog2((char *)"test4: syncReconfigFinish2RpcMsg -> syncReconfigFinishFromRpcMsg ", pMsg2); + + rpcFreeCont(rpcMsg.pCont); + syncReconfigFinishDestroy(pMsg); + syncReconfigFinishDestroy(pMsg2); +} + +void test5() { + SyncReconfigFinish *pMsg = createMsg(); + SRpcMsg rpcMsg; + syncReconfigFinish2RpcMsg(pMsg, &rpcMsg); + SyncReconfigFinish *pMsg2 = syncReconfigFinishFromRpcMsg2(&rpcMsg); + syncReconfigFinishLog2((char *)"test5: syncReconfigFinish2RpcMsg -> syncReconfigFinishFromRpcMsg2 ", pMsg2); + + rpcFreeCont(rpcMsg.pCont); + syncReconfigFinishDestroy(pMsg); + syncReconfigFinishDestroy(pMsg2); +} + +int main() { + gRaftDetailLog = true; + tsAsyncLog = 0; + sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE; + logTest(); + + test1(); + test2(); + test3(); + test4(); + test5(); + + return 0; +} diff --git a/source/libs/sync/test/syncReplicateTest.cpp b/source/libs/sync/test/syncReplicateTest.cpp index d955e64f81..66f347b620 100644 --- a/source/libs/sync/test/syncReplicateTest.cpp +++ b/source/libs/sync/test/syncReplicateTest.cpp @@ -32,9 +32,9 @@ void cleanup() { walCleanUp(); } void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { SyncIndex beginIndex = SYNC_INDEX_INVALID; - if (pFsm->FpGetSnapshot != NULL) { + if (pFsm->FpGetSnapshotInfo != NULL) { SSnapshot snapshot; - pFsm->FpGetSnapshot(pFsm, &snapshot); + pFsm->FpGetSnapshotInfo(pFsm, &snapshot); beginIndex = snapshot.lastApplyIndex; } @@ -75,7 +75,7 @@ SSyncFSM* createFsm() { pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; - pFsm->FpGetSnapshot = GetSnapshotCb; + pFsm->FpGetSnapshotInfo = GetSnapshotCb; return pFsm; } diff --git a/source/libs/sync/test/syncSnapshotSenderTest.cpp b/source/libs/sync/test/syncSnapshotSenderTest.cpp index 404ba2acae..04a02460af 100644 --- a/source/libs/sync/test/syncSnapshotSenderTest.cpp +++ b/source/libs/sync/test/syncSnapshotSenderTest.cpp @@ -40,7 +40,7 @@ SSyncSnapshotSender* createSender() { pSyncNode->pFsm->FpSnapshotStartRead = SnapshotStartRead; pSyncNode->pFsm->FpSnapshotStopRead = SnapshotStopRead; pSyncNode->pFsm->FpSnapshotDoRead = SnapshotDoRead; - pSyncNode->pFsm->FpGetSnapshot = GetSnapshot; + pSyncNode->pFsm->FpGetSnapshotInfo = GetSnapshot; SSyncSnapshotSender* pSender = snapshotSenderCreate(pSyncNode, 2); pSender->start = true; diff --git a/source/libs/sync/test/syncSnapshotTest.cpp b/source/libs/sync/test/syncSnapshotTest.cpp index 820500e2d8..954bdd8ea5 100644 --- a/source/libs/sync/test/syncSnapshotTest.cpp +++ b/source/libs/sync/test/syncSnapshotTest.cpp @@ -35,9 +35,9 @@ const char *pWalDir = "./syncSnapshotTest_wal"; void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { SyncIndex beginIndex = SYNC_INDEX_INVALID; - if (pFsm->FpGetSnapshot != NULL) { + if (pFsm->FpGetSnapshotInfo != NULL) { SSnapshot snapshot; - pFsm->FpGetSnapshot(pFsm, &snapshot); + pFsm->FpGetSnapshotInfo(pFsm, &snapshot); beginIndex = snapshot.lastApplyIndex; } @@ -79,7 +79,7 @@ void initFsm() { pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; - pFsm->FpGetSnapshot = GetSnapshotCb; + pFsm->FpGetSnapshotInfo = GetSnapshotCb; } SSyncNode *syncNodeInit() { diff --git a/source/libs/sync/test/syncTestTool.cpp b/source/libs/sync/test/syncTestTool.cpp index 1eac372bd4..91a16cc033 100644 --- a/source/libs/sync/test/syncTestTool.cpp +++ b/source/libs/sync/test/syncTestTool.cpp @@ -148,8 +148,8 @@ void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFini void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) { char* s = syncCfg2Str(&(cbMeta.newCfg)); - sTrace("==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu, newCfg:%s", - cbMeta.flag, cbMeta.isDrop, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term, s); + sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%ld, code:%d, currentTerm:%lu, term:%lu, newCfg:%s", + cbMeta.flag, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term, s); taosMemoryFree(s); } @@ -172,7 +172,7 @@ SSyncFSM* createFsm() { pFsm->FpRollBackCb = RollBackCb; pFsm->FpReConfigCb = ReConfigCb; - pFsm->FpGetSnapshot = GetSnapshotCb; + pFsm->FpGetSnapshotInfo = GetSnapshotCb; pFsm->FpRestoreFinishCb = RestoreFinishCb; pFsm->FpSnapshotStartRead = SnapshotStartRead; diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 5912fd800c..628bf6d7aa 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -58,6 +58,7 @@ int32_t tdbTbcMoveToPrev(TBC *pTbc); int32_t tdbTbcGet(TBC *pTbc, const void **ppKey, int *pkLen, const void **ppVal, int *pvLen); int32_t tdbTbcDelete(TBC *pTbc); int32_t tdbTbcNext(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen); +int32_t tdbTbcPrev(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen); int32_t tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, int nData, int insert); // TXN diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index fffda68731..45e71f6c0d 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -17,6 +17,7 @@ #define TDB_BTREE_ROOT 0x1 #define TDB_BTREE_LEAF 0x2 +#define TDB_BTREE_OVFL 0x4 struct SBTree { SPgno root; @@ -38,9 +39,11 @@ struct SBTree { #define TDB_BTREE_PAGE_SET_FLAGS(PAGE, flags) ((PAGE)->pData[0] = (flags)) #define TDB_BTREE_PAGE_IS_ROOT(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_ROOT) #define TDB_BTREE_PAGE_IS_LEAF(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_LEAF) +#define TDB_BTREE_PAGE_IS_OVFL(PAGE) (TDB_BTREE_PAGE_GET_FLAGS(PAGE) & TDB_BTREE_OVFL) #define TDB_BTREE_ASSERT_FLAG(flags) \ ASSERT(TDB_FLAG_IS(flags, TDB_BTREE_ROOT) || TDB_FLAG_IS(flags, TDB_BTREE_LEAF) || \ - TDB_FLAG_IS(flags, TDB_BTREE_ROOT | TDB_BTREE_LEAF) || TDB_FLAG_IS(flags, 0)) + TDB_FLAG_IS(flags, TDB_BTREE_ROOT | TDB_BTREE_LEAF) || TDB_FLAG_IS(flags, 0) || \ + TDB_FLAG_IS(flags, TDB_BTREE_OVFL)) #pragma pack(push, 1) typedef struct { @@ -62,10 +65,10 @@ static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2 static int tdbBtreeOpenImpl(SBTree *pBt); static int tdbBtreeInitPage(SPage *pPage, void *arg, int init); static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell, - int *szCell); -static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder); + int *szCell, TXN *pTxn, SBTree *pBt); +static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder, TXN *pTxn, SBTree *pBt); static int tdbBtreeBalance(SBTC *pBtc); -static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell); +static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *pTxn, SBTree *pBt); static int tdbBtcMoveDownward(SBTC *pBtc); static int tdbBtcMoveUpward(SBTC *pBtc); @@ -255,7 +258,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL } pCell = tdbPageGetCell(btc.pPage, btc.idx); - tdbBtreeDecodeCell(btc.pPage, pCell, &cd); + tdbBtreeDecodeCell(btc.pPage, pCell, &cd, btc.pTxn, pBt); if (ppKey) { pTKey = tdbRealloc(*ppKey, cd.kLen); @@ -281,6 +284,14 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL memcpy(*ppVal, cd.pVal, cd.vLen); } + if (TDB_CELLDECODER_FREE_KEY(&cd)) { + tdbFree(cd.pKey); + } + + if (TDB_CELLDECODER_FREE_VAL(&cd)) { + tdbFree(cd.pVal); + } + tdbBtcClose(&btc); return 0; @@ -375,6 +386,11 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg, int init) { pPage->vLen = pBt->valLen; pPage->maxLocal = pBt->maxLeaf; pPage->minLocal = pBt->minLeaf; + } else if (TDB_BTREE_PAGE_IS_OVFL(pPage)) { + pPage->kLen = pBt->keyLen; + pPage->vLen = pBt->valLen; + pPage->maxLocal = tdbPageCapacity(pBt->pageSize, sizeof(SIntHdr)); + pPage->minLocal = pBt->minLocal; } else { pPage->kLen = pBt->keyLen; pPage->vLen = sizeof(SPgno); @@ -499,7 +515,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx for (int i = 0; i < nOlds; i++) { if (sIdx + i < TDB_PAGE_TOTAL_CELLS(pParent)) { pCell = tdbPageGetCell(pParent, sIdx + i); - szDivCell[i] = tdbBtreeCellSize(pParent, pCell); + szDivCell[i] = tdbBtreeCellSize(pParent, pCell, 0, NULL, NULL); pDivCell[i] = tdbOsMalloc(szDivCell[i]); memcpy(pDivCell[i], pCell, szDivCell[i]); } @@ -524,7 +540,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx for (int i = 0; i < nOlds; i++) { nCells = TDB_PAGE_TOTAL_CELLS(pParent); if (sIdx < nCells) { - tdbPageDropCell(pParent, sIdx); + tdbPageDropCell(pParent, sIdx, pTxn, pBt); } else { ((SIntHdr *)pParent->pData)->pgno = 0; } @@ -582,7 +598,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx for (;;) { pCell = tdbPageGetCell(pOlds[infoNews[iNew - 1].iPage], infoNews[iNew - 1].oIdx); - szLCell = tdbBtreeCellSize(pOlds[infoNews[iNew - 1].iPage], pCell); + szLCell = tdbBtreeCellSize(pOlds[infoNews[iNew - 1].iPage], pCell, 0, NULL, NULL); if (!childNotLeaf) { szRCell = szLCell; } else { @@ -600,7 +616,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx } pCell = tdbPageGetCell(pPage, oIdx); - szRCell = tdbBtreeCellSize(pPage, pCell); + szRCell = tdbBtreeCellSize(pPage, pCell, 0, NULL, NULL); } ASSERT(infoNews[iNew - 1].cnt > 0); @@ -687,7 +703,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx for (int oIdx = 0; oIdx < TDB_PAGE_TOTAL_CELLS(pPage); oIdx++) { pCell = tdbPageGetCell(pPage, oIdx); - szCell = tdbBtreeCellSize(pPage, pCell); + szCell = tdbBtreeCellSize(pPage, pCell, 0, NULL, NULL); ASSERT(nNewCells <= infoNews[iNew].cnt); ASSERT(iNew < nNews); @@ -703,14 +719,14 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx if (iNew == nNews - 1 && pIntHdr->pgno == 0) { pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]); } else { - tdbBtreeDecodeCell(pPage, pCell, &cd); + tdbBtreeDecodeCell(pPage, pCell, &cd, pTxn, pBt); // TODO: pCell here may be inserted as an overflow cell, handle it SCell *pNewCell = tdbOsMalloc(cd.kLen + 9); int szNewCell; SPgno pgno; pgno = TDB_PAGE_PGNO(pNews[iNew]); - tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell); + tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell, pTxn, pBt); tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0); tdbOsFree(pNewCell); } @@ -846,13 +862,50 @@ static int tdbBtreeBalance(SBTC *pBtc) { } // TDB_BTREE_BALANCE +static int tdbFetchOvflPage(SPager *pPager, SPgno *pPgno, SPage **ppOfp, TXN *pTxn, SBTree *pBt) { + int ret = 0; + + *pPgno = 0; + SBtreeInitPageArg iArg; + iArg.pBt = pBt; + iArg.flags = TDB_FLAG_ADD(0, TDB_BTREE_OVFL); + ret = tdbPagerFetchPage(pPager, pPgno, ppOfp, tdbBtreeInitPage, &iArg, pTxn); + if (ret < 0) { + return -1; + } + + // mark dirty + ret = tdbPagerWrite(pPager, *ppOfp); + if (ret < 0) { + ASSERT(0); + return -1; + } + + return ret; +} + +static int tdbLoadOvflPage(SPager *pPager, SPgno *pPgno, SPage **ppOfp, TXN *pTxn, SBTree *pBt) { + int ret = 0; + + SBtreeInitPageArg iArg; + iArg.pBt = pBt; + iArg.flags = TDB_FLAG_ADD(0, TDB_BTREE_OVFL); + ret = tdbPagerFetchPage(pPager, pPgno, ppOfp, tdbBtreeInitPage, &iArg, pTxn); + if (ret < 0) { + return -1; + } + + return ret; +} + // TDB_BTREE_CELL ===================== static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const void *pKey, int kLen, const void *pVal, - int vLen, int *szPayload) { - int nPayload; + int vLen, int *szPayload, TXN *pTxn, SBTree *pBt) { + int ret = 0; + int nPayload = kLen + vLen; + int maxLocal = pPage->maxLocal; - nPayload = kLen + vLen; - if (nPayload + nHeader <= pPage->maxLocal) { + if (nPayload + nHeader <= maxLocal) { // no overflow page is needed memcpy(pCell + nHeader, pKey, kLen); if (pVal) { @@ -861,18 +914,190 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const *szPayload = nPayload; return 0; - } + } else { + // handle overflow case + // calc local storage size + int minLocal = pPage->minLocal; + int surplus = minLocal + (nPayload + nHeader - minLocal) % (maxLocal - sizeof(SPgno)); + int nLocal = surplus <= maxLocal ? surplus : minLocal; - { - // TODO: handle overflow case - ASSERT(0); + //int ofpCap = tdbPageCapacity(pBt->pageSize, sizeof(SIntHdr)); + + // fetch a new ofp and make it dirty + SPgno pgno = 0; + SPage *ofp, *nextOfp; + + ret = tdbFetchOvflPage(pPage->pPager, &pgno, &ofp, pTxn, pBt); + if (ret < 0) { + return -1; + } + + // local buffer for cell + SCell *pBuf = tdbRealloc(NULL, pBt->pageSize); + if (pBuf == NULL) { + return -1; + } + + int nLeft = nPayload; + int bytes; + int lastPage = 0; + if (nLocal >= kLen + 4) { + // pack key to local + memcpy(pCell + nHeader, pKey, kLen); + nLeft -= kLen; + // pack partial val to local if any space left + if (nLocal > kLen + 4) { + memcpy(pCell + nHeader + kLen, pVal, nLocal - kLen - sizeof(SPgno)); + nLeft -= nLocal - kLen - sizeof(SPgno); + } + + // pack nextPgno + memcpy(pCell + nHeader + nPayload - nLeft, &pgno, sizeof(pgno)); + + // pack left val data to ovpages + do { + lastPage = 0; + if (nLeft <= ofp->maxLocal - sizeof(SPgno)) { + bytes = nLeft; + lastPage = 1; + } else { + bytes = ofp->maxLocal - sizeof(SPgno); + } + + // fetch next ofp if not last page + if (!lastPage) { + // fetch a new ofp and make it dirty + ret = tdbFetchOvflPage(pPage->pPager, &pgno, &nextOfp, pTxn, pBt); + if (ret < 0) { + tdbFree(pBuf); + return -1; + } + } else { + pgno = 0; + } + + memcpy(pBuf, ((SCell *)pVal) + vLen - nLeft, bytes); + memcpy(pBuf + bytes, &pgno, sizeof(pgno)); + + ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0); + if (ret < 0) { + tdbFree(pBuf); + return -1; + } + + ofp = nextOfp; + nLeft -= bytes; + } while (nLeft > 0); + } else { + int nLeftKey = kLen; + // pack partial key and nextPgno + memcpy(pCell + nHeader, pKey, nLocal - 4); + nLeft -= nLocal - 4; + nLeftKey -= nLocal -4; + + memcpy(pCell + nHeader + nLocal - 4, &pgno, sizeof(pgno)); + + int lastKeyPageSpace = 0; + // pack left key & val to ovpages + do { + // cal key to cpy + int lastKeyPage = 0; + if (nLeftKey <= ofp->maxLocal - sizeof(SPgno)) { + bytes = nLeftKey; + lastKeyPage = 1; + lastKeyPageSpace = ofp->maxLocal - sizeof(SPgno) - nLeftKey; + } else { + bytes = ofp->maxLocal - sizeof(SPgno); + } + + // cpy key + memcpy(pBuf, ((SCell *)pKey) + kLen - nLeftKey, bytes); + + if (lastKeyPage) { + if (lastKeyPageSpace >= vLen) { + memcpy(pBuf + kLen -nLeftKey, pVal, vLen); + + nLeft -= vLen; + pgno = 0; + } else { + memcpy(pBuf + kLen -nLeftKey, pVal, lastKeyPageSpace); + nLeft -= lastKeyPageSpace; + + // fetch next ofp, a new ofp and make it dirty + ret = tdbFetchOvflPage(pPage->pPager, &pgno, &nextOfp, pTxn, pBt); + if (ret < 0) { + return -1; + } + } + } else { + // fetch next ofp, a new ofp and make it dirty + ret = tdbFetchOvflPage(pPage->pPager, &pgno, &nextOfp, pTxn, pBt); + if (ret < 0) { + return -1; + } + } + + memcpy(pBuf + kLen - nLeft, &pgno, sizeof(pgno)); + + ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0); + if (ret < 0) { + return -1; + } + + ofp = nextOfp; + nLeftKey -= bytes; + nLeft -= bytes; + } while (nLeftKey > 0); + + while (nLeft > 0) { + // pack left val data to ovpages + lastPage = 0; + if (nLeft <= maxLocal - sizeof(SPgno)) { + bytes = nLeft; + lastPage = 1; + } else { + bytes = maxLocal - sizeof(SPgno); + } + + // fetch next ofp if not last page + if (!lastPage) { + // fetch a new ofp and make it dirty + ret = tdbFetchOvflPage(pPage->pPager, &pgno, &nextOfp, pTxn, pBt); + if (ret < 0) { + tdbFree(pBuf); + return -1; + } + } else { + pgno = 0; + } + + memcpy(pBuf, ((SCell *)pVal) + vLen - nLeft, bytes); + memcpy(pBuf + bytes, &pgno, sizeof(pgno)); + + ret = tdbPageInsertCell(ofp, 0, pBuf, bytes + sizeof(pgno), 0); + if (ret < 0) { + tdbFree(pBuf); + return -1; + } + + ofp = nextOfp; + nLeft -= bytes; + } + } + + // free local buffer + tdbFree(pBuf); + + *szPayload = nLocal; + + // ASSERT(0); } return 0; } static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell, - int *szCell) { + int *szCell, TXN *pTxn, SBTree *pBt) { u8 leaf; int nHeader; int nPayload; @@ -911,7 +1136,7 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo vLen = 0; } - ret = tdbBtreeEncodePayload(pPage, pCell, nHeader, pKey, kLen, pVal, vLen, &nPayload); + ret = tdbBtreeEncodePayload(pPage, pCell, nHeader, pKey, kLen, pVal, vLen, &nPayload, pTxn, pBt); if (ret < 0) { // TODO ASSERT(0); @@ -922,8 +1147,13 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo return 0; } -static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, SCellDecoder *pDecoder) { +static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, SCellDecoder *pDecoder, TXN *pTxn, SBTree *pBt) { + int ret = 0; int nPayload; + int maxLocal = pPage->maxLocal; + + int kLen = pDecoder->kLen; + int vLen = pDecoder->vLen; if (pDecoder->pVal) { ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pPage)); @@ -932,24 +1162,171 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, nPayload = pDecoder->kLen + pDecoder->vLen; } - if (nHeader + nPayload <= pPage->maxLocal) { + if (nHeader + nPayload <= maxLocal) { // no over flow case - pDecoder->pKey = pCell + nHeader; + pDecoder->pKey = (SCell *)pCell + nHeader; if (pDecoder->pVal == NULL && pDecoder->vLen > 0) { - pDecoder->pVal = pCell + nHeader + pDecoder->kLen; + pDecoder->pVal = (SCell *)pCell + nHeader + pDecoder->kLen; } return 0; - } + } else { + // handle overflow case + // calc local storage size + int minLocal = pPage->minLocal; + int surplus = minLocal + (nPayload + nHeader - minLocal) % (maxLocal - sizeof(SPgno)); + int nLocal = surplus <= maxLocal ? surplus : minLocal; - { - // TODO: handle overflow case - ASSERT(0); + int nLeft = nPayload; + SPgno pgno = 0; + SPage *ofp; + SCell *ofpCell; + int bytes; + int lastPage = 0; + + if (nLocal >= pDecoder->kLen + 4) { + pDecoder->pKey = (SCell *)pCell + nHeader; + nLeft -= kLen; + if (nLocal > kLen + 4) { + // read partial val to local + pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen); + if (pDecoder->pVal == NULL) { + return -1; + } + TDB_CELLDECODER_SET_FREE_VAL(pDecoder); + + memcpy(pDecoder->pVal, pCell + nHeader + kLen, nLocal - kLen - sizeof(SPgno)); + + nLeft -= nLocal - kLen - sizeof(SPgno); + } + + memcpy(&pgno, pCell + nHeader + nPayload - nLeft, sizeof(pgno)); + + // unpack left val data from ovpages + while (pgno != 0) { + ret = tdbLoadOvflPage(pPage->pPager, &pgno, &ofp, pTxn, pBt); + if (ret < 0) { + return -1; + } + + ofpCell = tdbPageGetCell(ofp, 0); + + if (nLeft <= ofp->maxLocal - sizeof(SPgno)) { + bytes = nLeft; + lastPage = 1; + } else { + bytes = ofp->maxLocal - sizeof(SPgno); + } + + memcpy(pDecoder->pVal + vLen - nLeft, ofpCell, bytes); + nLeft -= bytes; + + memcpy(&pgno, ofpCell + bytes, sizeof(pgno)); + } + } else { + int nLeftKey = kLen; + // load partial key and nextPgno + pDecoder->pKey = tdbRealloc(pDecoder->pKey, kLen); + if (pDecoder->pKey == NULL) { + return -1; + } + TDB_CELLDECODER_SET_FREE_KEY(pDecoder); + + memcpy(pDecoder->pKey, pCell + nHeader, nLocal - 4); + nLeft -= nLocal - 4; + nLeftKey -= nLocal -4; + + memcpy(&pgno, pCell + nHeader + nLocal - 4, sizeof(pgno)); + + int lastKeyPageSpace = 0; + // load left key & val to ovpages + while (pgno != 0) { + ret = tdbLoadOvflPage(pPage->pPager, &pgno, &ofp, pTxn, pBt); + if (ret < 0) { + return -1; + } + + ofpCell = tdbPageGetCell(ofp, 0); + + int lastKeyPage = 0; + if (nLeftKey <= maxLocal - sizeof(SPgno)) { + bytes = nLeftKey; + lastKeyPage = 1; + lastKeyPageSpace = ofp->maxLocal - sizeof(SPgno) - nLeftKey; + } else { + bytes = ofp->maxLocal - sizeof(SPgno); + } + + // cpy key + memcpy(pDecoder->pKey + kLen - nLeftKey, ofpCell, bytes); + + if (lastKeyPage) { + if (lastKeyPageSpace >= vLen) { + pDecoder->pVal = ofpCell + kLen -nLeftKey; + + nLeft -= vLen; + pgno = 0; + } else { + // read partial val to local + pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen); + if (pDecoder->pVal == NULL) { + return -1; + } + TDB_CELLDECODER_SET_FREE_VAL(pDecoder); + + memcpy(pDecoder->pVal, ofpCell + kLen -nLeftKey, lastKeyPageSpace); + nLeft -= lastKeyPageSpace; + } + } + + memcpy(&pgno, ofpCell + bytes, sizeof(pgno)); + + nLeftKey -= bytes; + nLeft -= bytes; + } + + while (nLeft > 0) { + ret = tdbLoadOvflPage(pPage->pPager, &pgno, &ofp, pTxn, pBt); + if (ret < 0) { + return -1; + } + + ofpCell = tdbPageGetCell(ofp, 0); + + // load left val data to ovpages + lastPage = 0; + if (nLeft <= ofp->maxLocal - sizeof(SPgno)) { + bytes = nLeft; + lastPage = 1; + } else { + bytes = ofp->maxLocal - sizeof(SPgno); + } + + if (lastPage) { + pgno = 0; + } + + if (!pDecoder->pVal) { + pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen); + if (pDecoder->pVal == NULL) { + return -1; + } + TDB_CELLDECODER_SET_FREE_VAL(pDecoder); + } + + memcpy(pDecoder->pVal, ofpCell + vLen - nLeft, bytes); + nLeft -= bytes; + + memcpy(&pgno, ofpCell + vLen - nLeft + bytes, sizeof(pgno)); + + nLeft -= bytes; + } + } } return 0; } -static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder) { +static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder, TXN *pTxn, SBTree *pBt) { u8 leaf; int nHeader; int ret; @@ -963,6 +1340,7 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD pDecoder->vLen = -1; pDecoder->pVal = NULL; pDecoder->pgno = 0; + TDB_CELLDECODER_SET_FREE_NIL(pDecoder); // 1. Decode header part if (!leaf) { @@ -987,7 +1365,7 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD } // 2. Decode payload part - ret = tdbBtreeDecodePayload(pPage, pCell, nHeader, pDecoder); + ret = tdbBtreeDecodePayload(pPage, pCell, nHeader, pDecoder, pTxn, pBt); if (ret < 0) { return -1; } @@ -995,41 +1373,71 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD return 0; } -static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) { +static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *pTxn, SBTree *pBt) { u8 leaf; - int szCell; - int kLen = 0, vLen = 0; + int kLen = 0, vLen = 0, nHeader = 0; leaf = TDB_BTREE_PAGE_IS_LEAF(pPage); - szCell = 0; if (!leaf) { - szCell += sizeof(SPgno); + nHeader += sizeof(SPgno); } if (pPage->kLen == TDB_VARIANT_LEN) { - szCell += tdbGetVarInt(pCell + szCell, &kLen); + nHeader += tdbGetVarInt(pCell + nHeader, &kLen); } else { kLen = pPage->kLen; } if (pPage->vLen == TDB_VARIANT_LEN) { ASSERT(leaf); - szCell += tdbGetVarInt(pCell + szCell, &vLen); + nHeader += tdbGetVarInt(pCell + nHeader, &vLen); } else if (leaf) { vLen = pPage->vLen; } - szCell = szCell + kLen + vLen; + int nPayload = kLen + vLen; + if (nHeader + nPayload <= pPage->maxLocal) { + return nHeader + kLen + vLen; + } else { + int maxLocal = pPage->maxLocal; - if (szCell <= pPage->maxLocal) { - return szCell; - } + // calc local storage size + int minLocal = pPage->minLocal; + int surplus = minLocal + (nPayload + nHeader - minLocal) % (maxLocal - sizeof(SPgno)); + int nLocal = surplus <= maxLocal ? surplus : minLocal; - { - // TODO - ASSERT(0); - return 0; + // free ofp pages' cells + if (dropOfp) { + int ret = 0; + SPgno pgno = *(SPgno *) (pCell + nHeader + nLocal - sizeof(SPgno)); + int nLeft = nPayload - nLocal + sizeof(SPgno); + SPage *ofp; + int bytes; + + while (pgno != 0) { + ret = tdbLoadOvflPage(pPage->pPager, &pgno, &ofp, pTxn, pBt); + if (ret < 0) { + return -1; + } + + SCell *ofpCell = tdbPageGetCell(ofp, 0); + + if (nLeft <= ofp->maxLocal - sizeof(SPgno)) { + bytes = nLeft; + } else { + bytes = ofp->maxLocal - sizeof(SPgno); + } + + memcpy(&pgno, ofpCell + bytes, sizeof(pgno)); + + tdbPagerReturnPage(pPage->pPager, ofp, pTxn); + + nLeft -= bytes; + } + } + + return nHeader + nLocal; } } // TDB_BTREE_CELL @@ -1212,7 +1620,7 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx); - tdbBtreeDecodeCell(pBtc->pPage, pCell, &cd); + tdbBtreeDecodeCell(pBtc->pPage, pCell, &cd, pBtc->pTxn, pBtc->pBt); pKey = tdbRealloc(*ppKey, cd.kLen); if (pKey == NULL) { @@ -1245,6 +1653,52 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { return 0; } +int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { + SCell *pCell; + SCellDecoder cd; + void *pKey, *pVal; + int ret; + + // current cursor points to an invalid position + if (pBtc->idx < 0) { + return -1; + } + + pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx); + + tdbBtreeDecodeCell(pBtc->pPage, pCell, &cd, pBtc->pTxn, pBtc->pBt); + + pKey = tdbRealloc(*ppKey, cd.kLen); + if (pKey == NULL) { + return -1; + } + + *ppKey = pKey; + *kLen = cd.kLen; + memcpy(pKey, cd.pKey, cd.kLen); + + if (ppVal) { + // TODO: vLen may be zero + pVal = tdbRealloc(*ppVal, cd.vLen); + if (pVal == NULL) { + tdbFree(pKey); + return -1; + } + + *ppVal = pVal; + *vLen = cd.vLen; + memcpy(pVal, cd.pVal, cd.vLen); + } + + ret = tdbBtcMoveToPrev(pBtc); + if (ret < 0) { + ASSERT(0); + return -1; + } + + return 0; +} + int tdbBtcMoveToNext(SBTC *pBtc) { int nCells; int ret; @@ -1381,7 +1835,7 @@ int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int } pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx); - tdbBtreeDecodeCell(pBtc->pPage, pCell, &pBtc->coder); + tdbBtreeDecodeCell(pBtc->pPage, pCell, &pBtc->coder, pBtc->pTxn, pBtc->pBt); if (ppKey) { *ppKey = (void *)pBtc->coder.pKey; @@ -1418,7 +1872,7 @@ int tdbBtcDelete(SBTC *pBtc) { return -1; } - tdbPageDropCell(pBtc->pPage, idx); + tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt); // update interior page or do balance if (idx == nCells - 1) { @@ -1442,9 +1896,9 @@ int tdbBtcDelete(SBTC *pBtc) { // update the cell with new key pCell = tdbOsMalloc(nKey + 9); - tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell); + tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell, pBtc->pTxn, pBtc->pBt); - ret = tdbPageUpdateCell(pPage, idx, pCell, szCell); + ret = tdbPageUpdateCell(pPage, idx, pCell, szCell, pBtc->pTxn, pBtc->pBt); if (ret < 0) { tdbOsFree(pCell); ASSERT(0); @@ -1483,7 +1937,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int // alloc space szBuf = kLen + nData + 14; - pBuf = tdbRealloc(pBtc->pBt->pBuf, pBtc->pBt->pageSize > szBuf ? szBuf : pBtc->pBt->pageSize); + pBuf = tdbRealloc(pBtc->pBt->pBuf, pBtc->pBt->pageSize > szBuf ? szBuf : pBtc->pBt->pageSize); if (pBuf == NULL) { ASSERT(0); return -1; @@ -1492,7 +1946,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int pCell = (SCell *)pBtc->pBt->pBuf; // encode cell - ret = tdbBtreeEncodeCell(pBtc->pPage, pKey, kLen, pData, nData, pCell, &szCell); + ret = tdbBtreeEncodeCell(pBtc->pPage, pKey, kLen, pData, nData, pCell, &szCell, pBtc->pTxn, pBtc->pBt); if (ret < 0) { ASSERT(0); return -1; @@ -1513,7 +1967,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int } else { ASSERT(pBtc->idx < nCells); - ret = tdbPageUpdateCell(pBtc->pPage, pBtc->idx, pCell, szCell); + ret = tdbPageUpdateCell(pBtc->pPage, pBtc->idx, pCell, szCell, pBtc->pTxn, pBtc->pBt); } if (ret < 0) { ASSERT(0); @@ -1574,7 +2028,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { // check if key <= current position if (idx < nCells) { pCell = tdbPageGetCell(pPage, idx); - tdbBtreeDecodeCell(pPage, pCell, &cd); + tdbBtreeDecodeCell(pPage, pCell, &cd, pBtc->pTxn, pBtc->pBt); c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); if (c > 0) break; } @@ -1583,7 +2037,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { if (idx > 0) { pCell = tdbPageGetCell(pPage, idx - 1); tdbBtreeDecodeCell(pPage, pCell, &cd); - c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); + c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen, pBtc->pTxn, pBtc->pBt); if (c <= 0) break; } } @@ -1723,4 +2177,4 @@ void tdbBtPageInfo(SPage *pPage, int idx) { pBtPageInfo->nOvfl = pPage->nOverflow; } #endif -// TDB_BTREE_DEBUG \ No newline at end of file +// TDB_BTREE_DEBUG diff --git a/source/libs/tdb/src/db/tdbPage.c b/source/libs/tdb/src/db/tdbPage.c index 78470b6256..7a70b621c6 100644 --- a/source/libs/tdb/src/db/tdbPage.c +++ b/source/libs/tdb/src/db/tdbPage.c @@ -82,7 +82,8 @@ int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) return 0; } -void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)) { +void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, + TXN *, SBTree *pBt)) { pPage->pPageHdr = pPage->pData + szAmHdr; TDB_PAGE_NCELLS_SET(pPage, 0); TDB_PAGE_CCELLS_SET(pPage, pPage->pageSize - sizeof(SPageFtr)); @@ -98,7 +99,8 @@ void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell ASSERT((u8 *)pPage->pPageFtr == pPage->pFreeEnd); } -void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)) { +void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, + TXN *, SBTree *pBt)) { pPage->pPageHdr = pPage->pData + szAmHdr; pPage->pCellIdx = pPage->pPageHdr + TDB_PAGE_HDR_SIZE(pPage); pPage->pFreeStart = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * TDB_PAGE_NCELLS(pPage); @@ -171,12 +173,12 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl return 0; } -int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell) { - tdbPageDropCell(pPage, idx); +int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell, TXN *pTxn, SBTree *pBt) { + tdbPageDropCell(pPage, idx, pTxn, pBt); return tdbPageInsertCell(pPage, idx, pCell, szCell, 0); } -int tdbPageDropCell(SPage *pPage, int idx) { +int tdbPageDropCell(SPage *pPage, int idx, TXN *pTxn, SBTree *pBt) { int lidx; SCell *pCell; int szCell; @@ -205,7 +207,7 @@ int tdbPageDropCell(SPage *pPage, int idx) { lidx = idx - iOvfl; pCell = TDB_PAGE_CELL_AT(pPage, lidx); - szCell = (*pPage->xCellSize)(pPage, pCell); + szCell = (*pPage->xCellSize)(pPage, pCell, 1, pTxn, pBt); tdbPageFree(pPage, lidx, pCell, szCell); TDB_PAGE_NCELLS_SET(pPage, nCells - 1); @@ -420,7 +422,7 @@ static int tdbPageDefragment(SPage *pPage) { ASSERT(pCell != NULL); - szCell = (*pPage->xCellSize)(pPage, pCell); + szCell = (*pPage->xCellSize)(pPage, pCell, 0, NULL, NULL); ASSERT(pCell + szCell <= pNextCell); if (pCell + szCell < pNextCell) { diff --git a/source/libs/tdb/src/db/tdbTable.c b/source/libs/tdb/src/db/tdbTable.c index 239aa5d7ef..1575f9f206 100644 --- a/source/libs/tdb/src/db/tdbTable.c +++ b/source/libs/tdb/src/db/tdbTable.c @@ -132,6 +132,10 @@ int tdbTbcNext(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { return tdbBtreeNext(&pTbc->btc, ppKey, kLen, ppVal, vLen); } +int tdbTbcPrev(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { + return tdbBtreePrev(&pTbc->btc, ppKey, kLen, ppVal, vLen); +} + int tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, int nData, int insert) { return tdbBtcUpsert(&pTbc->btc, pKey, nKey, pData, nData, insert); } diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 6524e3c9bc..39b5584fab 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -116,13 +116,25 @@ typedef struct SBtInfo { int nData; } SBtInfo; +#define TDB_CELLD_F_NIL 0x0 +#define TDB_CELLD_F_KEY 0x1 +#define TDB_CELLD_F_VAL 0x2 + +#define TDB_CELLDECODER_SET_FREE_NIL(pCellDecoder) ((pCellDecoder)->freeKV = TDB_CELLD_F_NIL) +#define TDB_CELLDECODER_SET_FREE_KEY(pCellDecoder) ((pCellDecoder)->freeKV |= TDB_CELLD_F_KEY) +#define TDB_CELLDECODER_SET_FREE_VAL(pCellDecoder) ((pCellDecoder)->freeKV |= TDB_CELLD_F_VAL) + +#define TDB_CELLDECODER_FREE_KEY(pCellDecoder) ((pCellDecoder)->freeKV & TDB_CELLD_F_KEY) +#define TDB_CELLDECODER_FREE_VAL(pCellDecoder) ((pCellDecoder)->freeKV & TDB_CELLD_F_VAL) + typedef struct { int kLen; - const u8 *pKey; + u8 *pKey; int vLen; - const u8 *pVal; + u8 *pVal; SPgno pgno; u8 *pBuf; + u8 freeKV; } SCellDecoder; struct SBTC { @@ -156,6 +168,7 @@ int tdbBtcMoveToLast(SBTC *pBtc); int tdbBtcMoveToNext(SBTC *pBtc); int tdbBtcMoveToPrev(SBTC *pBtc); int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen); +int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen); int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int *vLen); int tdbBtcDelete(SBTC *pBtc); int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int nData, int insert); @@ -250,7 +263,7 @@ struct SPage { int vLen; // value length of the page, -1 for unknown int maxLocal; int minLocal; - int (*xCellSize)(const SPage *, SCell *); + int (*xCellSize)(const SPage *, SCell *, int, TXN *pTxn, SBTree *pBt); // Fields used by SPCache TDB_PCACHE_PAGE }; @@ -297,16 +310,18 @@ static inline int tdbTryLockPage(tdb_spinlock_t *pLock) { #define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx) #define TDB_PAGE_FREE_SIZE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage) #define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno) -#define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset) +#define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell, 0, NULL, NULL) + (pPage)->pPageMethods->szOffset) #define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset) int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg); -void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)); -void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)); +void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, + TXN *, SBTree *pBt)); +void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, + TXN *, SBTree *pBt)); int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl); -int tdbPageDropCell(SPage *pPage, int idx); -int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell); +int tdbPageDropCell(SPage *pPage, int idx, TXN *pTxn, SBTree *pBt); +int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell, TXN *pTxn, SBTree *pBt); void tdbPageCopy(SPage *pFromPage, SPage *pToPage); int tdbPageCapacity(int pageSize, int amHdrSize); diff --git a/source/libs/tdb/test/CMakeLists.txt b/source/libs/tdb/test/CMakeLists.txt index b2c8aaf9bc..2621e02b02 100644 --- a/source/libs/tdb/test/CMakeLists.txt +++ b/source/libs/tdb/test/CMakeLists.txt @@ -4,4 +4,9 @@ target_link_libraries(tdbTest tdb gtest gtest_main) # tdbUtilTest add_executable(tdbUtilTest "tdbUtilTest.cpp") -target_link_libraries(tdbUtilTest tdb gtest gtest_main) \ No newline at end of file +target_link_libraries(tdbUtilTest tdb gtest gtest_main) + +# tdbUtilTest +add_executable(tdbExOVFLTest "tdbExOVFLTest.cpp") +target_link_libraries(tdbExOVFLTest tdb gtest gtest_main) + diff --git a/source/libs/tdb/test/tdbExOVFLTest.cpp b/source/libs/tdb/test/tdbExOVFLTest.cpp new file mode 100644 index 0000000000..2d8d012a6a --- /dev/null +++ b/source/libs/tdb/test/tdbExOVFLTest.cpp @@ -0,0 +1,469 @@ +#include + +#define ALLOW_FORBID_FUNC +#include "os.h" +#include "tdb.h" + +#include +#include +#include +#include + +typedef struct SPoolMem { + int64_t size; + struct SPoolMem *prev; + struct SPoolMem *next; +} SPoolMem; + +static SPoolMem *openPool() { + SPoolMem *pPool = (SPoolMem *)taosMemoryMalloc(sizeof(*pPool)); + + pPool->prev = pPool->next = pPool; + pPool->size = 0; + + return pPool; +} + +static void clearPool(SPoolMem *pPool) { + SPoolMem *pMem; + + do { + pMem = pPool->next; + + if (pMem == pPool) break; + + pMem->next->prev = pMem->prev; + pMem->prev->next = pMem->next; + pPool->size -= pMem->size; + + taosMemoryFree(pMem); + } while (1); + + assert(pPool->size == 0); +} + +static void closePool(SPoolMem *pPool) { + clearPool(pPool); + taosMemoryFree(pPool); +} + +static void *poolMalloc(void *arg, size_t size) { + void *ptr = NULL; + SPoolMem *pPool = (SPoolMem *)arg; + SPoolMem *pMem; + + pMem = (SPoolMem *)taosMemoryMalloc(sizeof(*pMem) + size); + if (pMem == NULL) { + assert(0); + } + + pMem->size = sizeof(*pMem) + size; + pMem->next = pPool->next; + pMem->prev = pPool; + + pPool->next->prev = pMem; + pPool->next = pMem; + pPool->size += pMem->size; + + ptr = (void *)(&pMem[1]); + return ptr; +} + +static void poolFree(void *arg, void *ptr) { + SPoolMem *pPool = (SPoolMem *)arg; + SPoolMem *pMem; + + pMem = &(((SPoolMem *)ptr)[-1]); + + pMem->next->prev = pMem->prev; + pMem->prev->next = pMem->next; + pPool->size -= pMem->size; + + taosMemoryFree(pMem); +} + +static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { + int k1, k2; + + std::string s1((char *)pKey1 + 3, kLen1 - 3); + std::string s2((char *)pKey2 + 3, kLen2 - 3); + k1 = stoi(s1); + k2 = stoi(s2); + + if (k1 < k2) { + return -1; + } else if (k1 > k2) { + return 1; + } else { + return 0; + } +} + +static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2) { + int mlen; + int cret; + + ASSERT(keyLen1 > 0 && keyLen2 > 0 && pKey1 != NULL && pKey2 != NULL); + + mlen = keyLen1 < keyLen2 ? keyLen1 : keyLen2; + cret = memcmp(pKey1, pKey2, mlen); + if (cret == 0) { + if (keyLen1 < keyLen2) { + cret = -1; + } else if (keyLen1 > keyLen2) { + cret = 1; + } else { + cret = 0; + } + } + return cret; +} + +TEST(TdbOVFLPagesTest, TbUpsertTest) { + +} + +TEST(TdbOVFLPagesTest, TbPGetTest) { + +} + +static void generateBigVal(char *val, int valLen) { + for (int i = 0; i < valLen; ++i) { + char c = char(i & 0xff); + if (c == 0) { + c = 1; + } + val[i] = c; + } +} + +static TDB *openEnv(char const *envName, int const pageSize, int const pageNum) { + TDB *pEnv = NULL; + + int ret = tdbOpen(envName, pageSize, pageNum, &pEnv); + if (ret) { + pEnv = NULL; + } + + return pEnv; +} + +static void insertOfp(void) { + int ret = 0; + + taosRemoveDir("tdb"); + + // open Env + int const pageSize = 4096; + int const pageNum = 64; + TDB *pEnv = openEnv("tdb", pageSize, pageNum); + GTEST_ASSERT_NE(pEnv, nullptr); + + // open db + TTB *pDb = NULL; + tdb_cmpr_fn_t compFunc = tKeyCmpr; + ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb); + GTEST_ASSERT_EQ(ret, 0); + + // open the pool + SPoolMem *pPool = openPool(); + + // start a transaction + TXN txn; + int64_t txnid = 0; + ++txnid; + tdbTxnOpen(&txn, txnid, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED); + tdbBegin(pEnv, &txn); + + // generate value payload + char val[((4083 - 4 - 3 - 2)+1)*100]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4) + int valLen = sizeof(val) / sizeof(val[0]); + generateBigVal(val, valLen); + + // insert the generated big data + ret = tdbTbInsert(pDb, "key1", strlen("key1"), val, valLen, &txn); + GTEST_ASSERT_EQ(ret, 0); + + // commit current transaction + tdbCommit(pEnv, &txn); + tdbTxnClose(&txn); +} + +//TEST(TdbOVFLPagesTest, DISABLED_TbInsertTest) { +TEST(TdbOVFLPagesTest, TbInsertTest) { + insertOfp(); +} + +//TEST(TdbOVFLPagesTest, DISABLED_TbGetTest) { +TEST(TdbOVFLPagesTest, TbGetTest) { + insertOfp(); + + // open Env + int const pageSize = 4096; + int const pageNum = 64; + TDB *pEnv = openEnv("tdb", pageSize, pageNum); + GTEST_ASSERT_NE(pEnv, nullptr); + + // open db + TTB *pDb = NULL; + tdb_cmpr_fn_t compFunc = tKeyCmpr; + int ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb); + GTEST_ASSERT_EQ(ret, 0); + + // generate value payload + char val[((4083 - 4 - 3 - 2)+1)*100]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4) + int valLen = sizeof(val) / sizeof(val[0]); + generateBigVal(val, valLen); + + { // Query the data + void *pVal = NULL; + int vLen; + + ret = tdbTbGet(pDb, "key1", strlen("key1"), &pVal, &vLen); + ASSERT(ret == 0); + GTEST_ASSERT_EQ(ret, 0); + + GTEST_ASSERT_EQ(vLen, valLen); + GTEST_ASSERT_EQ(memcmp(val, pVal, vLen), 0); + + tdbFree(pVal); + } +} + +TEST(TdbOVFLPagesTest, TbDeleteTest) { + int ret = 0; + + taosRemoveDir("tdb"); + + // open Env + int const pageSize = 4096; + int const pageNum = 64; + TDB *pEnv = openEnv("tdb", pageSize, pageNum); + GTEST_ASSERT_NE(pEnv, nullptr); + + // open db + TTB *pDb = NULL; + tdb_cmpr_fn_t compFunc = tKeyCmpr; + ret = tdbTbOpen("ofp_insert.db", -1, -1, compFunc, pEnv, &pDb); + GTEST_ASSERT_EQ(ret, 0); + + // open the pool + SPoolMem *pPool = openPool(); + + // start a transaction + TXN txn; + int64_t txnid = 0; + ++txnid; + tdbTxnOpen(&txn, txnid, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED); + tdbBegin(pEnv, &txn); + + // generate value payload + char val[((4083 - 4 - 3 - 2)+1)*100]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4) + int valLen = sizeof(val) / sizeof(val[0]); + generateBigVal(val, valLen); + + { // insert the generated big data + ret = tdbTbInsert(pDb, "key1", strlen("key1"), val, valLen, &txn); + GTEST_ASSERT_EQ(ret, 0); + } + + { // query the data + void *pVal = NULL; + int vLen; + + ret = tdbTbGet(pDb, "key1", strlen("key1"), &pVal, &vLen); + ASSERT(ret == 0); + GTEST_ASSERT_EQ(ret, 0); + + GTEST_ASSERT_EQ(vLen, valLen); + GTEST_ASSERT_EQ(memcmp(val, pVal, vLen), 0); + + tdbFree(pVal); + } + /* open to debug committed file + tdbCommit(pEnv, &txn); + tdbTxnClose(&txn); + + ++txnid; + tdbTxnOpen(&txn, txnid, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED); + tdbBegin(pEnv, &txn); + */ + { // upsert the data + ret = tdbTbUpsert(pDb, "key1", strlen("key1"), "value1", strlen("value1"), &txn); + GTEST_ASSERT_EQ(ret, 0); + } + + { // query the upserted data + void *pVal = NULL; + int vLen; + + ret = tdbTbGet(pDb, "key1", strlen("key1"), &pVal, &vLen); + ASSERT(ret == 0); + GTEST_ASSERT_EQ(ret, 0); + + GTEST_ASSERT_EQ(vLen, strlen("value1")); + GTEST_ASSERT_EQ(memcmp("value1", pVal, vLen), 0); + + tdbFree(pVal); + } + + { // delete the data + ret = tdbTbDelete(pDb, "key1", strlen("key1"), &txn); + GTEST_ASSERT_EQ(ret, 0); + } + + { // query the deleted data + void *pVal = NULL; + int vLen = -1; + + ret = tdbTbGet(pDb, "key1", strlen("key1"), &pVal, &vLen); + ASSERT(ret == -1); + GTEST_ASSERT_EQ(ret, -1); + + GTEST_ASSERT_EQ(vLen, -1); + GTEST_ASSERT_EQ(pVal, nullptr); + + tdbFree(pVal); + } + + // commit current transaction + tdbCommit(pEnv, &txn); + tdbTxnClose(&txn); +} + +TEST(tdb_test, DISABLED_simple_insert1) { +//TEST(tdb_test, simple_insert1) { + int ret; + TDB *pEnv; + TTB *pDb; + tdb_cmpr_fn_t compFunc; + int nData = 1; + TXN txn; + int const pageSize = 4096; + + taosRemoveDir("tdb"); + + // Open Env + ret = tdbOpen("tdb", pageSize, 64, &pEnv); + GTEST_ASSERT_EQ(ret, 0); + + // Create a database + compFunc = tKeyCmpr; + ret = tdbTbOpen("db.db", -1, -1, compFunc, pEnv, &pDb); + GTEST_ASSERT_EQ(ret, 0); + + { + char key[64]; + //char val[(4083 - 4 - 3 - 2)]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4) + char val[(4083 - 4 - 3 - 2)+1]; // pSize(4096) - amSize(1) - pageHdr(8) - footerSize(4) + int64_t poolLimit = 4096; // 1M pool limit + int64_t txnid = 0; + SPoolMem *pPool; + + // open the pool + pPool = openPool(); + + // start a transaction + txnid++; + tdbTxnOpen(&txn, txnid, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED); + tdbBegin(pEnv, &txn); + + for (int iData = 1; iData <= nData; iData++) { + sprintf(key, "key0"); + sprintf(val, "value%d", iData); + + //ret = tdbTbInsert(pDb, key, strlen(key), val, strlen(val), &txn); + //GTEST_ASSERT_EQ(ret, 0); + + // generate value payload + int valLen = sizeof(val) / sizeof(val[0]); + for (int i = 6; i < valLen; ++i) { + char c = char(i & 0xff); + if (c == 0) { + c = 1; + } + val[i] = c; + } + + ret = tdbTbInsert(pDb, "key1", strlen("key1"), val, valLen, &txn); + GTEST_ASSERT_EQ(ret, 0); + + // if pool is full, commit the transaction and start a new one + if (pPool->size >= poolLimit) { + // commit current transaction + tdbCommit(pEnv, &txn); + tdbTxnClose(&txn); + + // start a new transaction + clearPool(pPool); + txnid++; + tdbTxnOpen(&txn, txnid, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED); + tdbBegin(pEnv, &txn); + } + } + + // commit the transaction + tdbCommit(pEnv, &txn); + tdbTxnClose(&txn); + + { // Query the data + void *pVal = NULL; + int vLen; + + for (int i = 1; i <= nData; i++) { + sprintf(key, "key%d", i); + sprintf(val, "value%d", i); + + ret = tdbTbGet(pDb, key, strlen(key), &pVal, &vLen); + ASSERT(ret == 0); + GTEST_ASSERT_EQ(ret, 0); + + GTEST_ASSERT_EQ(vLen, strlen(val)); + GTEST_ASSERT_EQ(memcmp(val, pVal, vLen), 0); + } + + tdbFree(pVal); + } + + { // Iterate to query the DB data + TBC *pDBC; + void *pKey = NULL; + void *pVal = NULL; + int vLen, kLen; + int count = 0; + + ret = tdbTbcOpen(pDb, &pDBC, NULL); + GTEST_ASSERT_EQ(ret, 0); + + tdbTbcMoveToFirst(pDBC); + + for (;;) { + ret = tdbTbcNext(pDBC, &pKey, &kLen, &pVal, &vLen); + if (ret < 0) break; + + // std::cout.write((char *)pKey, kLen) /* << " " << kLen */ << " "; + // std::cout.write((char *)pVal, vLen) /* << " " << vLen */; + // std::cout << std::endl; + + count++; + } + + GTEST_ASSERT_EQ(count, nData); + + tdbTbcClose(pDBC); + + tdbFree(pKey); + tdbFree(pVal); + } + } + + ret = tdbTbDrop(pDb); + GTEST_ASSERT_EQ(ret, 0); + + // Close a database + tdbTbClose(pDb); + + // Close Env + ret = tdbClose(pEnv); + GTEST_ASSERT_EQ(ret, 0); +} diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 7976cb09af..66a73ac92b 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -133,6 +133,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_STMT_API_ERROR, "Stmt API usage error" TAOS_DEFINE_ERROR(TSDB_CODE_TSC_STMT_TBNAME_ERROR, "Stmt table name not set") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_STMT_CLAUSE_ERROR, "not supported stmt clause") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_QUERY_KILLED, "Query killed") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_EXEC_NODE, "No available execution node") // mnode-common TAOS_DEFINE_ERROR(TSDB_CODE_MND_APP_ERROR, "Mnode internal error") @@ -422,6 +423,10 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_IS_LEADER, "Sync is leader") TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_LEADER, "Sync not leader") TAOS_DEFINE_ERROR(TSDB_CODE_SYN_ONE_REPLICA, "Sync one replica") TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_IN_NEW_CONFIG, "Sync not in new config") +TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NEW_CONFIG_ERROR, "Sync new config error") +TAOS_DEFINE_ERROR(TSDB_CODE_SYN_RECONFIG_NOT_READY, "Sync not ready for reconfig") +TAOS_DEFINE_ERROR(TSDB_CODE_SYN_PROPOSE_NOT_READY, "Sync not ready for propose") +TAOS_DEFINE_ERROR(TSDB_CODE_SYN_STANDBY_NOT_READY, "Sync not ready for standby") TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INTERNAL_ERROR, "Sync internal error") // wal diff --git a/tests/pytest/util/common.py b/tests/pytest/util/common.py index 7b00e6f331..e158f8edd2 100644 --- a/tests/pytest/util/common.py +++ b/tests/pytest/util/common.py @@ -11,13 +11,20 @@ # -*- coding: utf-8 -*- +from collections import defaultdict import random import string -from util.sql import tdSql -from util.dnodes import tdDnodes import requests import time import socket + +import taos +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * + class TDCom: def init(self, conn, logSql): tdSql.init(conn.cursor(), logSql) @@ -170,4 +177,122 @@ class TDCom: def close(self): self.cursor.close() + def create_database(self,tsql, dbName='test',dropFlag=1,precision="ms", **kwargs): + if dropFlag == 1: + tsql.execute("drop database if exists %s"%(dbName)) + ''' + vgroups replica precision strict wal fsync comp cachelast single_stable buffer pagesize pages minrows maxrows duration keep retentions + ''' + sqlString = f'create database if not exists {dbName} precision "{precision}" vgroups 4' + if len(kwargs) > 0: + dbParams = "" + for param, value in kwargs.items(): + dbParams += f'{param} {value} ' + sqlString += f'{dbParams}' + + tsql.execute(sqlString) + tdLog.debug("complete to create database %s"%(dbName)) + return + + def create_stable(self,tsql, dbName,stbName,columnDict,tagDict): + colSchema = '' + for i in range(columnDict['int']): + colSchema += ', c%d int'%i + tagSchema = '' + for i in range(tagDict['int']): + if i > 0: + tagSchema += ',' + tagSchema += 't%d int'%i + + tsql.execute("create table if not exists %s.%s (ts timestamp %s) tags(%s)"%(dbName, stbName, colSchema, tagSchema)) + tdLog.debug("complete to create %s.%s" %(dbName, stbName)) + return + + def create_ctables(self,tsql, dbName,stbName,ctbNum,tagDict): + tsql.execute("use %s" %dbName) + tagsValues = '' + for i in range(tagDict['int']): + if i > 0: + tagsValues += ',' + tagsValues += '%d'%i + + pre_create = "create table" + sql = pre_create + #tdLog.debug("doing create one stable %s and %d child table in %s ..." %(stbname, count ,dbname)) + for i in range(ctbNum): + sql += " %s_%d using %s tags(%s)"%(stbName,i,stbName,tagsValues) + if (i > 0) and (i%100 == 0): + tsql.execute(sql) + sql = pre_create + if sql != pre_create: + tsql.execute(sql) + + tdLog.debug("complete to create %d child tables in %s.%s" %(ctbNum, dbName, stbName)) + return + + def insert_data(self,tsql,dbName,stbName,ctbNum,rowsPerTbl,batchNum,startTs=0): + tdLog.debug("start to insert data ............") + tsql.execute("use %s" %dbName) + pre_insert = "insert into " + sql = pre_insert + if startTs == 0: + t = time.time() + startTs = int(round(t * 1000)) + #tdLog.debug("doing insert data into stable:%s rows:%d ..."%(stbName, allRows)) + for i in range(ctbNum): + sql += " %s_%d values "%(stbName,i) + for j in range(rowsPerTbl): + sql += "(%d, %d, %d)"%(startTs + j, j, j) + if (j > 0) and ((j%batchNum == 0) or (j == rowsPerTbl - 1)): + tsql.execute(sql) + if j < rowsPerTbl - 1: + sql = "insert into %s_%d values " %(stbName,i) + else: + sql = "insert into " + #end sql + if sql != pre_insert: + #print("insert sql:%s"%sql) + tsql.execute(sql) + tdLog.debug("insert data ............ [OK]") + return + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files or "taosd.exe" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def getClientCfgPath(self): + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + cfgPath = buildPath + "/../sim/psim/cfg" + tdLog.info("cfgPath: %s" % cfgPath) + return cfgPath + + def newcur(self,host='localhost',port=6030,user='root',password='taosdata'): + cfgPath = self.getClientCfgPath() + con=taos.connect(host=host, user=user, password=password, config=cfgPath, port=port) + cur=con.cursor() + print(cur) + return cur + + def newTdSql(self, host='localhost',port=6030,user='root',password='taosdata'): + newTdSql = TDSql() + cur = self.newcur(host=host,port=port,user=user,password=password) + newTdSql.init(cur, False) + return newTdSql + tdCom = TDCom() diff --git a/tests/pytest/util/constant.py b/tests/pytest/util/constant.py new file mode 100644 index 0000000000..e5095c74dc --- /dev/null +++ b/tests/pytest/util/constant.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +# basic data type boundary +TINYINT_MAX = 127 +TINYINT_MIN = -128 + +TINYINT_UN_MAX = 255 +TINYINT_UN_MIN = 0 + +SMALLINT_MAX = 32767 +SMALLINT_MIN = -32768 + +SMALLINT_UN_MAX = 65535 +MALLINT_UN_MIN = 0 + +INT_MAX = 2147483647 +INT_MIN = -2147483648 + +INT_UN_MAX = 4294967295 +INT_UN_MIN = 0 + +BIGINT_MAX = 9223372036854775807 +BIGINT_MIN = -9223372036854775808 + +BIGINT_UN_MAX = 18446744073709551615 +BIGINT_UN_MIN = 0 + +FLOAT_MAX = 3.40E+38 +FLOAT_MIN = -3.40E+38 + +DOUBLE_MAX = 1.7E+308 +DOUBLE_MIN = -1.7E+308 + +# schema boundary +BINARY_LENGTH_MAX = 16374 +NCAHR_LENGTH_MAX_ = 4093 +DBNAME_LENGTH_MAX_ = 64 + +STBNAME_LENGTH_MAX = 192 +STBNAME_LENGTH_MIN = 1 + +TBNAME_LENGTH_MAX = 192 +TBNAME_LENGTH_MIN = 1 + +CHILD_TBNAME_LENGTH_MAX = 192 +CHILD_TBNAME_LENGTH_MIN = 1 + +TAG_NAME_LENGTH_MAX = 64 +TAG_NAME_LENGTH_MIN = 1 + +COL_NAME_LENGTH_MAX = 64 +COL_NAME_LENGTH_MIN = 1 + +TAG_COUNT_MAX = 128 +TAG_COUNT_MIN = 1 + +COL_COUNT_MAX = 4096 +COL_COUNT_MIN = 2 + +TAG_COL_COUNT_MAX = 4096 +TAG_COL_COUNT_MIN = 3 + +MNODE_SHM_SIZE_MAX = 2147483647 +MNODE_SHM_SIZE_MIN = 6292480 +MNODE_SHM_SIZE_DEFAULT = 6292480 + +VNODE_SHM_SIZE_MAX = 2147483647 +VNODE_SHM_SIZE_MIN = 6292480 +VNODE_SHM_SIZE_DEFAULT = 31458304 \ No newline at end of file diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index b7c6dce018..580fc8ee47 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -61,7 +61,7 @@ class TDSql: self.cursor.execute(s) s = 'use db' self.cursor.execute(s) - time.sleep(2) + time.sleep(2) def error(self, sql): expectErrNotOccured = True @@ -249,7 +249,7 @@ class TDSql: raise Exception(repr(e)) return self.queryResult - + def executeTimes(self, sql, times): for i in range(times): try: diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index a8ec0f5151..276b5e6e34 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -72,13 +72,16 @@ ./test.sh -f tsim/stream/basic0.sim ./test.sh -f tsim/stream/basic1.sim ./test.sh -f tsim/stream/basic2.sim -# ./test.sh -f tsim/stream/distributeInterval0.sim +./test.sh -f tsim/stream/distributeInterval0.sim +# ./test.sh -f tsim/stream/distributesession0.sim # ./test.sh -f tsim/stream/session0.sim # ./test.sh -f tsim/stream/session1.sim # ./test.sh -f tsim/stream/state0.sim -# ./test.sh -f tsim/stream/triggerInterval0.sim +./test.sh -f tsim/stream/triggerInterval0.sim # ./test.sh -f tsim/stream/triggerSession0.sim -# ./test.sh -f tsim/stream/partitionby.sim +./test.sh -f tsim/stream/partitionby.sim +./test.sh -f tsim/stream/schedSnode.sim +./test.sh -f tsim/stream/windowClose.sim # ---- transaction diff --git a/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim b/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim index 7b52b51306..e9dd82cad9 100644 --- a/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim +++ b/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim @@ -53,31 +53,10 @@ endi if $data(4)[4] != ready then goto step1 endi -#if $data(5)[4] != ready then -# goto step1 -#endi print =============== step2: create db sql create database d1 vgroups 1 replica 3 -# dnode not exist -sql_error redistribute vgroup 3 dnode 6 dnode 3 dnode 4 -# vgroup not exist -sql_error redistribute vgroup 3 dnode 5 dnode 3 dnode 4 -# un changed -sql_error redistribute vgroup 2 dnode 2 dnode 3 dnode 4 -# no enought vnodes -sql_error redistribute vgroup 2 dnode 1 dnode 3 dnode 4 -# offline vnodes -sql_error redistribute vgroup 2 dnode 5 dnode 3 dnode 4 -# Invalid replica -sql_error redistribute vgroup 2 dnode 5 -sql_error redistribute vgroup 2 dnode 5 dnode 3 -sql_error redistribute vgroup 2 dnode 2 dnode 3 -sql_error redistribute vgroup 2 dnode 2 dnode 2 -sql_error redistribute vgroup 3 dnode 2 dnode 2 -sql_error redistribute vgroup 2 dnode 2 dnode 2 dnode 3 - system sh/exec.sh -n dnode5 -s start $x = 0 step2: diff --git a/tests/script/tsim/mnode/basic5.sim b/tests/script/tsim/mnode/basic5.sim index fc591aa25d..23f5f6d782 100644 --- a/tests/script/tsim/mnode/basic5.sim +++ b/tests/script/tsim/mnode/basic5.sim @@ -148,7 +148,7 @@ endi print =============== step6: stop mnode1 system sh/exec.sh -n dnode1 -s stop -x SIGKILL -sql_error drop mnode on dnode 1 +# sql_error drop mnode on dnode 1 $x = 0 step61: diff --git a/tests/script/tsim/sma/rsmaCreateInsertQuery.sim b/tests/script/tsim/sma/rsmaCreateInsertQuery.sim index 645b28f771..fb3503c841 100644 --- a/tests/script/tsim/sma/rsmaCreateInsertQuery.sim +++ b/tests/script/tsim/sma/rsmaCreateInsertQuery.sim @@ -5,7 +5,7 @@ sleep 50 sql connect print =============== create database with retentions -sql create database d0 retentions 15s:7d,1m:21d,15m:365d; +sql create database d0 retentions 5s:7d,10s:21d,15s:365d; sql use d0 print =============== create super table and register rsma @@ -29,6 +29,8 @@ sql insert into ct1 values(now, 10); sql insert into ct1 values(now+1s, 1); sql insert into ct1 values(now+2s, 100); +print =============== wait maxdelay 15+1 seconds for results +sleep 16000 print =============== select * from retention level 2 from memory sql select * from ct1; diff --git a/tests/script/tsim/stable/alter_comment.sim b/tests/script/tsim/stable/alter_comment.sim index cfcbb9a1da..19f4858585 100644 --- a/tests/script/tsim/stable/alter_comment.sim +++ b/tests/script/tsim/stable/alter_comment.sim @@ -159,7 +159,7 @@ sql alter table db.stb rename tag t1 tx print ========== alter common sql alter table db.stb comment 'abcde' ; -sql alter table db.stb ttl 10 ; +sql_error alter table db.stb ttl 10 ; sql show db.stables; if $data[0][6] != abcde then diff --git a/tests/script/tsim/stream/distributeInterval0.sim b/tests/script/tsim/stream/distributeInterval0.sim index b720272116..91ce49bc8c 100644 --- a/tests/script/tsim/stream/distributeInterval0.sim +++ b/tests/script/tsim/stream/distributeInterval0.sim @@ -208,4 +208,4 @@ if $data11 != 2 then goto loop2 endi -system sh/stop_dnodes.sh \ No newline at end of file +system sh/stop_dnodes.sh diff --git a/tests/script/tsim/stream/distributesession0.sim b/tests/script/tsim/stream/distributesession0.sim new file mode 100644 index 0000000000..a165b86edd --- /dev/null +++ b/tests/script/tsim/stream/distributesession0.sim @@ -0,0 +1,58 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 + +system sh/exec.sh -n dnode1 -s start +sleep 50 +sql connect + +sql create dnode $hostname2 port 7200 + +system sh/exec.sh -n dnode2 -s start + +sql create database test vgroups 4; +sql use test; +sql create stable st(ts timestamp,a int,b int,c int) tags(ta int,tb int,tc int); +sql create table ts1 using st tags(1,1,1); +sql create table ts2 using st tags(2,2,2); +sql create stream stream_t1 trigger at_once into streamtST as select _wstartts, count(*) c1, sum(a) c2 , max(b) c3 from st session(ts, 10s) ; + +sleep 1000 + +sql insert into ts1 values(1648791211000,1,1,1) (1648791211005,1,1,1); +sql insert into ts2 values(1648791221004,1,2,3) (1648791221008,2,2,3); +sql insert into ts1 values(1648791211005,1,1,1); +sql insert into ts2 values(1648791221006,5,5,5) (1648791221007,5,5,5); +sql insert into ts2 values(1648791221008,5,5,5) (1648791221008,5,5,5)(1648791221006,5,5,5); +sql insert into ts1 values(1648791231000,1,1,1) (1648791231002,1,1,1) (1648791231006,1,1,1); +sql insert into ts1 values(1648791211000,6,6,6) (1648791231002,2,2,2); +sql insert into ts1 values(1648791211002,7,7,7); +sql insert into ts1 values(1648791211002,7,7,7) ts2 values(1648791221008,5,5,5) ; + +$loop_count = 0 +loop1: +sql select * from streamtST; + +sleep 300 +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + +# row 0 +if $data01 != 10 then + print =====data01=$data01 + goto loop1 +endi + +if $data02 != 34 then + print =====data02=$data02 + goto loop1 +endi + +if $data03 != 7 then + print ======$data03 + return -1 +endi + +system sh/stop_dnodes.sh diff --git a/tests/script/tsim/stream/schedSnode.sim b/tests/script/tsim/stream/schedSnode.sim new file mode 100644 index 0000000000..dbf714a96f --- /dev/null +++ b/tests/script/tsim/stream/schedSnode.sim @@ -0,0 +1,173 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 + +system sh/exec.sh -n dnode1 -s start +sleep 50 +sql connect + +sql create snode on dnode 1 + +sql create database test vgroups 1; +sql create database target vgroups 1; +sql use test; +sql create stable st(ts timestamp, a int, b int , c int, d double) tags(ta int,tb int,tc int); +sql create table ts1 using st tags(1,1,1); +sql create table ts2 using st tags(2,2,2); +sql create table ts3 using st tags(3,2,2); +sql create table ts4 using st tags(4,2,2); +sql create stream stream_t1 trigger at_once into target.streamtST1 as select _wstartts, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5 from st interval(10s); + +sleep 1000 + +sql insert into ts1 values(1648791213001,1,12,3,1.0); +sql insert into ts2 values(1648791213001,1,12,3,1.0); + +sql insert into ts3 values(1648791213001,1,12,3,1.0); +sql insert into ts4 values(1648791213001,1,12,3,1.0); + +sql insert into ts1 values(1648791213002,NULL,NULL,NULL,NULL); +sql insert into ts2 values(1648791213002,NULL,NULL,NULL,NULL); + +sql insert into ts3 values(1648791213002,NULL,NULL,NULL,NULL); +sql insert into ts4 values(1648791213002,NULL,NULL,NULL,NULL); + +sql insert into ts1 values(1648791223002,2,2,3,1.1); +sql insert into ts1 values(1648791233003,3,2,3,2.1); +sql insert into ts2 values(1648791243004,4,2,43,73.1); +sql insert into ts1 values(1648791213002,24,22,23,4.1); +sql insert into ts1 values(1648791243005,4,20,3,3.1); +sql insert into ts2 values(1648791243006,4,2,3,3.1) (1648791243007,4,2,3,3.1) ; +sql insert into ts1 values(1648791243008,4,2,30,3.1) (1648791243009,4,2,3,3.1) (1648791243010,4,2,3,3.1) ; +sql insert into ts2 values(1648791243011,4,2,3,3.1) (1648791243012,34,32,33,3.1) (1648791243013,4,2,3,3.1) (1648791243014,4,2,13,3.1); +sql insert into ts1 values(1648791243005,4,42,3,3.1) (1648791243003,4,2,33,3.1) (1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) ; +sql insert into ts2 values(1648791243005,4,42,3,3.1) (1648791243003,4,2,33,3.1) (1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) (1648791233004,13,12,13,2.1) ; +sql insert into ts1 values(1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) ; + +sql insert into ts3 values(1648791223002,2,2,3,1.1); +sql insert into ts4 values(1648791233003,3,2,3,2.1); +sql insert into ts3 values(1648791243004,4,2,43,73.1); +sql insert into ts4 values(1648791213002,24,22,23,4.1); +sql insert into ts3 values(1648791243005,4,20,3,3.1); +sql insert into ts4 values(1648791243006,4,2,3,3.1) (1648791243007,4,2,3,3.1) ; +sql insert into ts3 values(1648791243008,4,2,30,3.1) (1648791243009,4,2,3,3.1) (1648791243010,4,2,3,3.1) ; +sql insert into ts4 values(1648791243011,4,2,3,3.1) (1648791243012,34,32,33,3.1) (1648791243013,4,2,3,3.1) (1648791243014,4,2,13,3.1); +sql insert into ts3 values(1648791243005,4,42,3,3.1) (1648791243003,4,2,33,3.1) (1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) ; +sql insert into ts4 values(1648791243005,4,42,3,3.1) (1648791243003,4,2,33,3.1) (1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) (1648791233004,13,12,13,2.1) ; +sql insert into ts3 values(1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) ; + +$loop_count = 0 +loop1: +sql select * from target.streamtST1; + +sleep 300 +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + +# row 0 +if $data01 != 8 then + print =====data01=$data01 + goto loop1 +endi + +if $data02 != 4 then + print =====data02=$data02 + goto loop1 +endi + +if $data03 != 4 then + print ======$data03 + return -1 +endi + +if $data04 != 52 then + print ======$data04 + return -1 +endi + +if $data05 != 13 then + print ======$data05 + return -1 +endi + +# row 1 +if $data11 != 6 then + print =====data11=$data11 + goto loop1 +endi + +if $data12 != 6 then + print =====data12=$data12 + goto loop1 +endi + +if $data13 != 92 then + print ======$data13 + return -1 +endi + +if $data14 != 22 then + print ======$data14 + return -1 +endi + +if $data15 != 3 then + print ======$data15 + return -1 +endi + +# row 2 +if $data21 != 4 then + print =====data21=$data21 + goto loop1 +endi + +if $data22 != 4 then + print =====data22=$data22 + goto loop1 +endi + +if $data23 != 32 then + print ======$data23 + return -1 +endi + +if $data24 != 12 then + print ======$data24 + return -1 +endi + +if $data25 != 3 then + print ======$data25 + return -1 +endi + +# row 3 +if $data31 != 30 then + print =====data31=$data31 + goto loop1 +endi + +if $data32 != 30 then + print =====data32=$data32 + goto loop1 +endi + +if $data33 != 180 then + print ======$data33 + return -1 +endi + +if $data34 != 42 then + print ======$data34 + return -1 +endi + +if $data35 != 3 then + print ======$data35 + return -1 +endi + +sql select _wstartts, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5, avg(d) from st interval(10s); diff --git a/tests/script/tsim/stream/session0.sim b/tests/script/tsim/stream/session0.sim index 2a737578bc..24ffe76d2b 100644 --- a/tests/script/tsim/stream/session0.sim +++ b/tests/script/tsim/stream/session0.sim @@ -231,9 +231,10 @@ sql use test3; sql create table t1(ts timestamp, a int, b int , c int, d double); sql create stream streams3 trigger at_once watermark 1d into streamt3 as select _wstartts, min(b), a,c from t1 session(ts,10s); sql create stream streams4 trigger at_once watermark 1d into streamt4 as select _wstartts, max(b), a,c from t1 session(ts,10s); -sql create stream streams5 trigger at_once watermark 1d into streamt5 as select _wstartts, top(b,3), a,c from t1 session(ts,10s); -sql create stream streams6 trigger at_once watermark 1d into streamt6 as select _wstartts, bottom(b,3), a,c from t1 session(ts,10s); -sql create stream streams7 trigger at_once watermark 1d into streamt7 as select _wstartts, spread(a), elapsed(ts), hyperloglog(a) from t1 session(ts,10s); +# sql create stream streams5 trigger at_once watermark 1d into streamt5 as select _wstartts, top(b,3), a,c from t1 session(ts,10s); +# sql create stream streams6 trigger at_once watermark 1d into streamt6 as select _wstartts, bottom(b,3), a,c from t1 session(ts,10s); +# sql create stream streams7 trigger at_once watermark 1d into streamt7 as select _wstartts, spread(a), elapsed(ts), hyperloglog(a) from t1 session(ts,10s); +sql create stream streams7 trigger at_once watermark 1d into streamt7 as select _wstartts, spread(a), hyperloglog(a) from t1 session(ts,10s); sql create stream streams8 trigger at_once watermark 1d into streamt8 as select _wstartts, histogram(a,"user_input", "[1,3,5,7]", 1), histogram(a,"user_input", "[1,3,5,7]", 0) from t1 session(ts,10s); sql insert into t1 values(1648791213001,1,1,1,1.0); sql insert into t1 values(1648791213002,2,3,2,3.4); @@ -269,13 +270,13 @@ if $rows == 0 then goto loop3 endi -sql select * from streamt5; +#sql select * from streamt5; if $rows == 0 then print ======$rows - goto loop3 + # goto loop3 endi -sql select * from streamt6; +# sql select * from streamt6; if $rows == 0 then print ======$rows goto loop3 diff --git a/tests/script/tsim/stream/triggerSession0.sim b/tests/script/tsim/stream/triggerSession0.sim index 69b3dc1704..48827a64a2 100644 --- a/tests/script/tsim/stream/triggerSession0.sim +++ b/tests/script/tsim/stream/triggerSession0.sim @@ -85,7 +85,7 @@ sql insert into t2 values(1648791243003,1,2,3,1.0) (1648791243002,1,2,3,1.0) (16 sleep 500 sql select * from streamt2; if $rows != 3 then - print ======$rows + print =====rows=$rows return -1 endi diff --git a/tests/script/tsim/stream/windowClose.sim b/tests/script/tsim/stream/windowClose.sim new file mode 100644 index 0000000000..695d5749fa --- /dev/null +++ b/tests/script/tsim/stream/windowClose.sim @@ -0,0 +1,32 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sleep 50 +sql connect + +print =============== create database +sql create database test vgroups 1 +sql show databases +if $rows != 3 then + return -1 +endi + +print $data00 $data01 $data02 + +sql use test +sql create stable st(ts timestamp, a int) tags(t int); +sql create table tu1 using st tags(1); +sql create table tu2 using st tags(2); + +sql create stream stream1 trigger window_close into streamt as select _wstartts, sum(a) from st interval(10s); + +sql insert into tu1 values(now, 1); + +sleep 500 +sql select * from streamt; +if $rows != 0 then + print ======$rows + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/system-test/1-insert/create_retentions.py b/tests/system-test/1-insert/create_retentions.py index 313c643822..5a0684e2ee 100644 --- a/tests/system-test/1-insert/create_retentions.py +++ b/tests/system-test/1-insert/create_retentions.py @@ -1,5 +1,7 @@ import datetime +from dataclasses import dataclass +from typing import List from util.log import * from util.sql import * from util.cases import * @@ -28,6 +30,28 @@ CHAR_COL = [ BINARY_COL, NCHAR_COL, ] BOOLEAN_COL = [ BOOL_COL, ] TS_TYPE_COL = [ TS_COL, ] +## insert data args: +TIME_STEP = 10000 +NOW = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + +@dataclass +class DataSet: + ts_data : List[int] = None + int_data : List[int] = None + bint_data : List[int] = None + sint_data : List[int] = None + tint_data : List[int] = None + int_un_data : List[int] = None + bint_un_data : List[int] = None + sint_un_data : List[int] = None + tint_un_data : List[int] = None + float_data : List[float] = None + double_data : List[float] = None + bool_data : List[int] = None + binary_data : List[str] = None + nchar_data : List[str] = None + + class TDTestCase: def init(self, conn, logSql): @@ -37,10 +61,13 @@ class TDTestCase: @property def create_databases_sql_err(self): return [ - "create database if not exists db1 retentions 0s:1d", - "create database if not exists db1 retentions 1s:1y", - "create database if not exists db1 retentions 1s:1n", - "create database if not exists db1 retentions 1s:1n,2s:2d,3s:3d,4s:4d", + "create database db1 retentions 0s:1d", + "create database db3 retentions 1s:0d", + "create database db1 retentions 1s:1y", + "create database db1 retentions 1s:1n", + "create database db2 retentions 1w:1d ;", + "create database db5 retentions 1s:1d,3s:3d,2s:2d", + "create database db1 retentions 1s:1n,2s:2d,3s:3d,4s:4d", ] @property @@ -60,16 +87,41 @@ class TDTestCase: @property def create_stable_sql_err(self): return [ - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(ceil) delay 1", - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(count) delay 1", - f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} binary(16)) tags (tag1 int) rollup(avg) delay 1", - f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) tags (tag1 int) rollup(avg) delay 1", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(ceil) watermark 1s maxdelay 1m", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(count) watermark 1min", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay -1s", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark -1m", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 1m ", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) maxdelay 1m ", + f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} binary(16)) tags (tag1 int) rollup(avg) watermark 1s", + f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) tags (tag1 int) rollup(avg) maxdelay 1m", + # f"create table ntb_1 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) rollup(avg) watermark 1s maxdelay 1s", + # f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) tags (tag1 int) " , + # f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) " , + # f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) " , + # f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) " , + + # watermark, maxdelay: [0, 900000], [ms, s, m, ?] + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay 1u", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 1b", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 900001ms", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay 16m", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay 901s", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay 1h", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay 0.2h", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 0.002d", + ] @property def create_stable_sql_current(self): return [ - f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(avg) delay 5", + f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(avg)", + f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 5s maxdelay 1m", + f"create stable stb3 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(max) watermark 5s maxdelay 1m", + f"create stable stb4 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(sum) watermark 5s maxdelay 1m", + # f"create stable stb5 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(last) watermark 5s maxdelay 1m", + # f"create stable stb6 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s maxdelay 1m", ] def test_create_stb(self): @@ -79,14 +131,19 @@ class TDTestCase: for cur_sql in self.create_stable_sql_current: tdSql.execute(cur_sql) tdSql.query("show stables") + # assert "rollup" in tdSql.description tdSql.checkRows(len(self.create_stable_sql_current)) + # tdSql.execute("use db") # because db is a noraml database, not a rollup database, should not be able to create a rollup database + # tdSql.error(f"create stable nor_db_rollup_stb ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) file_factor 5.0") + + def test_create_databases(self): for err_sql in self.create_databases_sql_err: tdSql.error(err_sql) for cur_sql in self.create_databases_sql_current: tdSql.execute(cur_sql) - tdSql.query("show databases") + # tdSql.query("show databases") for alter_sql in self.alter_database_sql: tdSql.error(alter_sql) @@ -95,9 +152,7 @@ class TDTestCase: self.test_create_stb() def __create_tb(self): - tdSql.prepare() - - tdLog.printNoPrefix("==========step1:create table") + tdLog.printNoPrefix("==========step: create table") create_stb_sql = f'''create table stb1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, @@ -120,129 +175,118 @@ class TDTestCase: for i in range(4): tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') - def __create_data_set(self, rows): - now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) - pos_data = [] - neg_data = [] - spec_data = [] - for i in range(rows): - pos_data.append( - ( - now_time - i * 1000, i, 11111 * i, 111 * i % 32767 , 11 * i % 127, 1.11 * i, 1100.0011 * i, - i % 2, f'binary{i}', f'nchar_测试_{i}', now_time + 1 * i, 11 * i % 127, 111 * i % 32767, i, 11111 * i - ) - ) - neg_data.append( - ( - now_time - i * 7776000000, -i, -11111 * i, -111 * i % 32767, -11 * i % 127, -1.11 * i, -1100.0011 * i, - i % 2, f'binary{i}', f'nchar_测试_{i}', now_time + 1 * i, 11 * i % 127, 111 * i % 32767, i, 11111 * i - ) - ) - - def __insert_data(self, rows): - now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) - for i in range(rows): - tdSql.execute( - f'''insert into ct1 values ( - { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, - {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i }, {11 * i % 127}, {111 * i % 32767}, {i}, {11111 * i} )''' - ) - tdSql.execute( - f'''insert into ct4 values ( - { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, - {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i }, {11 * i % 127}, {111 * i % 32767}, {i}, {11111 * i} )''' - ) - tdSql.execute( - f'''insert into ct2 values ( - { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, - {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i }, {11 * i % 127}, {111 * i % 32767}, {i}, {11111 * i} )''' - ) - tdSql.execute( - f'''insert into ct1 values - ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 }, 0, 0, 0, 0) - ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 }, 0, 0, 0, 0 ) - ''' - ) - - tdSql.execute( - f'''insert into ct4 values - ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( - { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, - { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000}, - 254, 65534, {pow(2,32)-pow(2,16)}, {pow(2,64)-pow(2,31)} - ) - ( - { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, - { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000}, - 255, 65535, {pow(2,32)-pow(2,15)}, {pow(2,64)-pow(2,30)} - ) - ''' - ) - - tdSql.execute( - f'''insert into ct2 values - ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( - { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, { -1 * 3.2 * pow(10,38) }, - { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 }, 1, 1, 1, 1 - ) - ( - { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, { - 3.3 * pow(10,38) }, - { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 }, 1, 1, 1, 1 - ) - ''' - ) + def __data_set(self, rows): + data_set = DataSet() + # neg_data_set = DataSet() + data_set.ts_data = [] + data_set.int_data = [] + data_set.bint_data = [] + data_set.sint_data = [] + data_set.tint_data = [] + data_set.int_un_data = [] + data_set.bint_un_data = [] + data_set.sint_un_data = [] + data_set.tint_un_data = [] + data_set.float_data = [] + data_set.double_data = [] + data_set.bool_data = [] + data_set.binary_data = [] + data_set.nchar_data = [] for i in range(rows): - insert_data = f'''insert into t1 values - ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, - "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i }, {i % 127}, {i % 32767}, {i}, {i * 11111}) - ''' - tdSql.execute(insert_data) - tdSql.execute( - f'''insert into t1 values - ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) - ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( - { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, { 3.3 * pow(10,38) }, - { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 }, - 254, 65534, {pow(2,32)-pow(2,16)}, {pow(2,64)-pow(2,31)} - ) - ( - { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, { 3.2 * pow(10,38) }, - { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 }, - 255, 65535, {pow(2,32)-pow(2,15)}, {pow(2,64)-pow(2,30)} - ) + data_set.ts_data.append(NOW + 1 * (rows - i)) + data_set.int_data.append(rows - i) + data_set.bint_data.append(11111 * (rows - i)) + data_set.sint_data.append(111 * (rows - i) % 32767) + data_set.tint_data.append(11 * (rows - i) % 127) + data_set.int_un_data.append(rows - i) + data_set.bint_un_data.append(11111 * (rows - i)) + data_set.sint_un_data.append(111 * (rows - i) % 32767) + data_set.tint_un_data.append(11 * (rows - i) % 127) + data_set.float_data.append(1.11 * (rows - i)) + data_set.double_data.append(1100.0011 * (rows - i)) + data_set.bool_data.append((rows - i) % 2) + data_set.binary_data.append(f'binary{(rows - i)}') + data_set.nchar_data.append(f'nchar_测试_{(rows - i)}') + + # neg_data_set.ts_data.append(-1 * i) + # neg_data_set.int_data.append(-i) + # neg_data_set.bint_data.append(-11111 * i) + # neg_data_set.sint_data.append(-111 * i % 32767) + # neg_data_set.tint_data.append(-11 * i % 127) + # neg_data_set.int_un_data.append(-i) + # neg_data_set.bint_un_data.append(-11111 * i) + # neg_data_set.sint_un_data.append(-111 * i % 32767) + # neg_data_set.tint_un_data.append(-11 * i % 127) + # neg_data_set.float_data.append(-1.11 * i) + # neg_data_set.double_data.append(-1100.0011 * i) + # neg_data_set.binary_data.append(f'binary{i}') + # neg_data_set.nchar_data.append(f'nchar_测试_{i}') + + return data_set + + def __insert_data(self): + data = self.__data_set(rows=self.rows) + + # now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + null_data = '''null, null, null, null, null, null, null, null, null, null, null, null, null, null''' + zero_data = "0, 0, 0, 0, 0, 0, 0, 'binary_0', 'nchar_0', 0, 0, 0, 0, 0" + + for i in range(self.rows): + row_data = f''' + {data.int_data[i]}, {data.bint_data[i]}, {data.sint_data[i]}, {data.tint_data[i]}, {data.float_data[i]}, {data.double_data[i]}, + {data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {data.tint_un_data[i]}, + {data.sint_un_data[i]}, {data.int_un_data[i]}, {data.bint_un_data[i]} ''' - ) + neg_row_data = f''' + {-1 * data.int_data[i]}, {-1 * data.bint_data[i]}, {-1 * data.sint_data[i]}, {-1 * data.tint_data[i]}, {-1 * data.float_data[i]}, {-1 * data.double_data[i]}, + {data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {1 * data.tint_un_data[i]}, + {1 * data.sint_un_data[i]}, {1 * data.int_un_data[i]}, {1 * data.bint_un_data[i]} + ''' + + tdSql.execute( f"insert into ct1 values ( {NOW - i * TIME_STEP}, {row_data} )" ) + tdSql.execute( f"insert into ct2 values ( {NOW - i * int(TIME_STEP * 0.6)}, {neg_row_data} )" ) + tdSql.execute( f"insert into ct4 values ( {NOW - i * int(TIME_STEP * 0.8) }, {row_data} )" ) + tdSql.execute( f"insert into t1 values ( {NOW - i * int(TIME_STEP * 1.2)}, {row_data} )" ) + + tdSql.execute( f"insert into ct2 values ( {NOW + int(TIME_STEP * 0.6)}, {null_data} )" ) + tdSql.execute( f"insert into ct2 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.6)}, {null_data} )" ) + tdSql.execute( f"insert into ct2 values ( {NOW - self.rows * int(TIME_STEP * 0.29) }, {null_data} )" ) + + tdSql.execute( f"insert into ct4 values ( {NOW + int(TIME_STEP * 0.8)}, {null_data} )" ) + tdSql.execute( f"insert into ct4 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.8)}, {null_data} )" ) + tdSql.execute( f"insert into ct4 values ( {NOW - self.rows * int(TIME_STEP * 0.39)}, {null_data} )" ) + + tdSql.execute( f"insert into t1 values ( {NOW + int(TIME_STEP * 1.2)}, {null_data} )" ) + tdSql.execute( f"insert into t1 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 1.2)}, {null_data} )" ) + tdSql.execute( f"insert into t1 values ( {NOW - self.rows * int(TIME_STEP * 0.59)}, {null_data} )" ) def run(self): - tdSql.prepare() - - tdLog.printNoPrefix("==========step1:create table") - self.__create_tb() - - tdLog.printNoPrefix("==========step2:insert data") self.rows = 10 - self.__insert_data(self.rows) - tdLog.printNoPrefix("==========step3:all check") - self.all_test() + + tdLog.printNoPrefix("==========step0:all check") + # self.all_test() + + tdLog.printNoPrefix("==========step1:create table in normal database") + tdSql.prepare() + self.__create_tb() + self.__insert_data() + # return + + tdLog.printNoPrefix("==========step2:create table in rollup database") + tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m") + tdSql.execute("use db3") + self.__create_tb() + self.__insert_data() + tdSql.execute("drop database if exists db1 ") tdSql.execute("drop database if exists db2 ") tdDnodes.stop(1) tdDnodes.start(1) - tdSql.execute("use db") - tdLog.printNoPrefix("==========step4:after wal, all check again ") self.all_test() diff --git a/tests/system-test/1-insert/create_table_comment.py b/tests/system-test/1-insert/create_table_comment.py deleted file mode 100644 index 92ea083c5a..0000000000 --- a/tests/system-test/1-insert/create_table_comment.py +++ /dev/null @@ -1,113 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import random -import string -from util.log import * -from util.cases import * -from util.sql import * - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) - - def get_long_name(self, length, mode="mixed"): - """ - generate long name - mode could be numbers/letters/letters_mixed/mixed - """ - if mode == "numbers": - population = string.digits - elif mode == "letters": - population = string.ascii_letters.lower() - elif mode == "letters_mixed": - population = string.ascii_letters.upper() + string.ascii_letters.lower() - else: - population = string.ascii_letters.lower() + string.digits - return "".join(random.choices(population, k=length)) - - def __create_tb(self,dbname,stbname,tbname,comment): - tdSql.execute(f'create database if not exists {dbname}') - tdSql.execute(f'use {dbname}') - tdSql.execute( - f'create table {stbname} (ts timestamp,c0 int) tags(t0 int) ') - tdSql.execute( - f'create table {tbname} using {stbname} tags(1) comment "{comment}"') - def __create_normaltb(self,dbname,tbname,comment): - tdSql.execute(f'create database if not exists {dbname}') - tdSql.execute(f'use {dbname}') - tdSql.execute( - f'create table {tbname} (ts timestamp,c0 int) comment "{comment}"') - - def check_comment(self): - dbname = self.get_long_name(length=10, mode="letters") - ntbname = self.get_long_name(length=5, mode="letters") - - # create normal table with comment - comment = self.get_long_name(length=10, mode="letters") - self.__create_normaltb(dbname,ntbname,comment) - ntb_kv_list = tdSql.getResult("show tables") - print(ntb_kv_list) - tdSql.checkEqual(ntb_kv_list[0][8], comment) - tdSql.error('alter table {ntbname} comment "test1"') - tdSql.execute(f'drop database {dbname}') - - # max length(1024) - comment = self.get_long_name(length=1024, mode="letters") - self.__create_normaltb(dbname,ntbname,comment) - ntb_kv_list = tdSql.getResult("show tables") - tdSql.checkEqual(ntb_kv_list[0][8], comment) - tdSql.execute(f'drop database {dbname}') - - # error overlength - comment = self.get_long_name(length=1025, mode="letters") - tdSql.execute(f'create database if not exists {dbname}') - tdSql.execute(f'use {dbname}') - tdSql.error(f"create table ntb (ts timestamp,c0 int) comment '{comment}'") - tdSql.execute(f'drop database {dbname}') - - # create child table with comment - comment = self.get_long_name(length=10, mode="letters") - stbname = self.get_long_name(length=5, mode="letters") - tbname = self.get_long_name(length=3, mode="letters") - self.__create_tb(dbname,stbname,tbname,comment) - ntb_kv_list = tdSql.getResult("show tables") - tdSql.checkEqual(ntb_kv_list[0][8], comment) - tdSql.error(f'alter table {tbname} comment "test1"') - tdSql.execute(f'drop database {dbname}') - - # max length 1024 - comment = self.get_long_name(length=1024, mode="letters") - self.__create_tb(dbname,ntbname,comment) - ntb_kv_list = tdSql.getResult("show tables") - tdSql.checkEqual(ntb_kv_list[0][8], comment) - tdSql.execute(f'drop database {dbname}') - - # error overlength - comment = self.get_long_name(length=1025, mode="letters") - tdSql.execute(f'create database if not exists {dbname}') - tdSql.execute(f'use {dbname}') - tdSql.execute(f"create table stb (ts timestamp,c0 int) tags(t0 int)") - tdSql.error(f'create table stb_1 us stb tags(1) comment "{comment}"') - tdSql.execute(f'drop database {dbname}') - - def run(self): - self.check_comment() - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/1-insert/table_comment.py b/tests/system-test/1-insert/table_comment.py new file mode 100644 index 0000000000..5b85a3964f --- /dev/null +++ b/tests/system-test/1-insert/table_comment.py @@ -0,0 +1,134 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import random +import string + +from util.log import * +from util.cases import * +from util.sql import * +from util.common import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + # prepare data + self.ntbname = 'ntb' + self.stbname = 'stb' + self.column_dict = { + 'ts':'timestamp', + 'c1':'int', + 'c2':'float', + 'c3':'double', + 'c4':'timestamp' + } + self.tag_dict = { + 't0':'int' + } + self.comment_length = [0,1024] + self.error_comment_length = [1025] + self.table_type_list = ['normal_table','stable','child_table'] + self.comment_flag_list = [True,False] + + def __set_and_alter_comment(self,tb_type='',comment_flag= False): + + column_sql = '' + tag_sql = '' + for k,v in self.column_dict.items(): + column_sql += f"{k} {v}," + for k,v in self.tag_dict.items(): + tag_sql += f"{k} {v}," + if tb_type == 'normal_table' or tb_type == '': + if comment_flag == False: + tdSql.execute(f'create table {self.ntbname} ({column_sql[:-1]})') + self.check_comment_info() + self.alter_comment(self.ntbname) + tdSql.execute(f'drop table {self.ntbname}') + elif comment_flag == True: + for i in self.comment_length: + comment_info = tdCom.getLongName(i) + tdSql.execute(f'create table {self.ntbname} ({column_sql[:-1]}) comment "{comment_info}"') + self.check_comment_info(comment_info) + self.alter_comment(self.ntbname) + tdSql.execute(f'drop table {self.ntbname}') + for i in self.error_comment_length: + comment_info = tdCom.getLongName(i) + tdSql.error(f'create table {self.ntbname} ({column_sql[:-1]}) comment "{comment_info}"') + elif tb_type == 'stable': + for operation in ['table','stable']: + if comment_flag == False: + tdSql.execute(f'create {operation} {self.stbname} ({column_sql[:-1]}) tags({tag_sql[:-1]})') + self.check_comment_info(None,'stable') + self.alter_comment(self.stbname,'stable') + tdSql.execute(f'drop table {self.stbname}') + elif comment_flag == True: + for i in self.comment_length: + comment_info = tdCom.getLongName(i) + tdSql.execute(f'create {operation} {self.stbname} ({column_sql[:-1]}) tags({tag_sql[:-1]}) comment "{comment_info}"') + self.check_comment_info(comment_info,'stable') + self.alter_comment(self.stbname,'stable') + tdSql.execute(f'drop table {self.stbname}') + elif tb_type == 'child_table': + tdSql.execute(f'create table if not exists {self.stbname} ({column_sql[:-1]}) tags({tag_sql[:-1]})') + if comment_flag == False: + tdSql.execute(f'create table if not exists {self.stbname}_ctb using {self.stbname} tags(1)') + self.check_comment_info() + self.alter_comment(f'{self.stbname}_ctb') + tdSql.execute(f'drop table {self.stbname}_ctb') + elif comment_flag == True: + for j in self.comment_length: + comment_info = tdCom.getLongName(j) + tdSql.execute(f'create table if not exists {self.stbname}_ctb using {self.stbname} tags(1) comment "{comment_info}"') + self.check_comment_info(comment_info) + self.alter_comment(f'{self.stbname}_ctb') + tdSql.execute(f'drop table {self.stbname}_ctb') + tdSql.execute(f'drop table {self.stbname}') + def alter_comment(self,tbname,tb_type=''): + for i in self.comment_length: + comment_info = tdCom.getLongName(i) + print(comment_info) + tdSql.execute(f'alter table {tbname} comment "{comment_info}"') + self.check_comment_info(comment_info,tb_type) + for i in self.error_comment_length: + comment_info = tdCom.getLongName(i) + tdSql.error(f'alter table {tbname} comment "{comment_info}"') + def check_comment_info(self,comment_info=None,tb_type=''): + if tb_type == '' or tb_type == 'normal_table' or tb_type == 'child_table': + tdSql.query('show tables') + if comment_info == None: + tdSql.checkEqual(tdSql.queryResult[0][8],None) + else : + tdSql.checkEqual(tdSql.queryResult[0][8],comment_info) + elif tb_type == 'stable': + tdSql.query('show stables') + if comment_info == None: + tdSql.checkEqual(tdSql.queryResult[0][6],None) + else : + tdSql.checkEqual(tdSql.queryResult[0][6],comment_info) + def comment_check_case(self,table_type,comment_flag): + tdSql.prepare() + for tb in table_type: + for flag in comment_flag: + self.__set_and_alter_comment(tb,flag) + tdSql.execute('drop database db') + + def run(self): + self.comment_check_case(self.table_type_list,self.comment_flag_list) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/1-insert/time_range_wise.py b/tests/system-test/1-insert/time_range_wise.py new file mode 100644 index 0000000000..5387970d56 --- /dev/null +++ b/tests/system-test/1-insert/time_range_wise.py @@ -0,0 +1,343 @@ +import datetime + +from dataclasses import dataclass +from typing import List, Any, Tuple +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.constant import * + +PRIMARY_COL = "ts" + +INT_COL = "c_int" +BINT_COL = "c_bint" +SINT_COL = "c_sint" +TINT_COL = "c_tint" +FLOAT_COL = "c_float" +DOUBLE_COL = "c_double" +BOOL_COL = "c_bool" +TINT_UN_COL = "c_tint_un" +SINT_UN_COL = "c_sint_un" +BINT_UN_COL = "c_bint_un" +INT_UN_COL = "c_int_un" +BINARY_COL = "c_binary" +NCHAR_COL = "c_nchar" +TS_COL = "c_ts" + + + +NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, ] +CHAR_COL = [BINARY_COL, NCHAR_COL, ] +BOOLEAN_COL = [BOOL_COL, ] +TS_TYPE_COL = [TS_COL, ] + +# insert data args: +TIME_STEP = 10000 +NOW = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + + +@dataclass +class DataSet: + ts_data : List[int] = None + int_data : List[int] = None + bint_data : List[int] = None + sint_data : List[int] = None + tint_data : List[int] = None + int_un_data : List[int] = None + bint_un_data: List[int] = None + sint_un_data: List[int] = None + tint_un_data: List[int] = None + float_data : List[float] = None + double_data : List[float] = None + bool_data : List[int] = None + binary_data : List[str] = None + nchar_data : List[str] = None + + def __post_init__(self): + self.ts_data = [] + self.int_data = [] + self.bint_data = [] + self.sint_data = [] + self.tint_data = [] + self.int_un_data = [] + self.bint_un_data = [] + self.sint_un_data = [] + self.tint_un_data = [] + self.float_data = [] + self.double_data = [] + self.bool_data = [] + self.binary_data = [] + self.nchar_data = [] + + +@dataclass +class SMAschema: + creation : str = "CREATE" + index_name : str = "sma_index_1" + index_flag : str = "SMA INDEX" + operator : str = "ON" + tbname : str = None + watermark : str = None + maxdelay : str = None + func : Tuple[str] = None + interval : Tuple[str] = None + sliding : str = None + other : Any = None + drop : str = "DROP" + drop_flag : str = "INDEX" + + def __post_init__(self): + if isinstance(self.other, dict): + for k,v in self.other.items(): + + if k.lower() == "index_name" and isinstance(v, str) and not self.index_name: + self.index_name = v + del self.other[k] + + if k.lower() == "index_flag" and isinstance(v, str) and not self.index_flag: + self.index_flag = v + del self.other[k] + + if k.lower() == "operator" and isinstance(v, str) and not self.operator: + self.operator = v + del self.other[k] + + if k.lower() == "tbname" and isinstance(v, str) and not self.tbname: + self.tbname = v + del self.other[k] + + if k.lower() == "watermark" and isinstance(v, str) and not self.watermark: + self.watermark = v + del self.other[k] + + if k.lower() == "maxdelay" and isinstance(v, str) and not self.maxdelay: + self.maxdelay = v + del self.other[k] + + if k.lower() == "functions" and isinstance(v, tuple) and not self.func: + self.func = v + del self.other[k] + + if k.lower() == "interval" and isinstance(v, tuple) and not self.interval: + self.interval = v + del self.other[k] + + if k.lower() == "sliding" and isinstance(v, str) and not self.sliding: + self.sliding = v + del self.other[k] + + if k.lower() == "drop_flag" and isinstance(v, str) and not self.drop_flag: + self.drop_flag = v + del self.other[k] + + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + + """ + create sma index : + 1. only create on stable, err_type: [child-table, normal-table] + 2. one taosd, one sma index , err_type: [ + one stb --> multi sma index, + multi stb in one db--> multi sma index, + multi stb in multi db --> multi sma index + ] + 3. arg of (interval/sliding) in query sql is equal to this arg in sma index + 4. client timezone is equal to timezone of sma index + 5. does not take effect unless querySmaOptimize flag is turned on, + """ + def __create_sma_index(self, sma:SMAschema): + sql = f"{sma.creation} {sma.index_flag} {sma.index_name} {sma.operator} {sma.tbname}" + if sma.func: + sql += f" function({', '.join(sma.func)})" + if sma.interval: + sql += f" interval({', '.join(sma.interval)})" + if sma.sliding: + sql += f" sliding({sma.sliding})" + if sma.watermark: + sql += f" watermark {sma.watermark}" + if sma.maxdelay: + sql += f" maxdelay {sma.maxdelay}" + if isinstance(sma.other, dict): + for k,v in sma.other.items(): + if isinstance(v,tuple) or isinstance(v, list): + sql += f" {k} ({' '.join(v)})" + else: + sql += f" {k} {v}" + if isinstance(sma.other, tuple) or isinstance(sma.other, list): + sql += " ".join(sma.other) + if isinstance(sma.other, int) or isinstance(sma.other, float) or isinstance(sma.other, str): + sql += sma.other + + return sql + + def sma_create_check(self, sma:SMAschema): + tdSql.query("show stables") + stb_in_list = False + for row in tdSql.queryResult: + if sma.tbname == row[0]: + stb_in_list = True + break + if not stb_in_list: + tdSql.error(self.__create_sma_index(sma)) + if not sma.creation: + tdSql.error(self.__create_sma_index(sma)) + if not sma.index_flag: + tdSql.error(self.__create_sma_index(sma)) + if not sma.index_name: + tdSql.error(self.__create_sma_index(sma)) + if not sma.operator: + tdSql.error(self.__create_sma_index(sma)) + if not sma.tbname: + tdSql.error(self.__create_sma_index(sma)) + if not sma.func: + tdSql.error(self.__create_sma_index(sma)) + if not sma.interval: + tdSql.error(self.__create_sma_index(sma)) + if not sma.sliding: + tdSql.error(self.__create_sma_index(sma)) + if sma.other: + tdSql.error(self.__create_sma_index(sma)) + + + def all_test(self): + pass + + def __create_tb(self): + tdLog.printNoPrefix("==========step: create table") + create_stb_sql = f'''create table stb1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, + {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, + {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned + ) tags (tag1 int) + ''' + create_ntb_sql = f'''create table t1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, + {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, + {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned + ) + ''' + tdSql.execute(create_stb_sql) + tdSql.execute(create_ntb_sql) + + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + def __data_set(self, rows): + data_set = DataSet() + + for i in range(rows): + data_set.ts_data.append(NOW + 1 * (rows - i)) + data_set.int_data.append(rows - i) + data_set.bint_data.append(11111 * (rows - i)) + data_set.sint_data.append(111 * (rows - i) % 32767) + data_set.tint_data.append(11 * (rows - i) % 127) + data_set.int_un_data.append(rows - i) + data_set.bint_un_data.append(11111 * (rows - i)) + data_set.sint_un_data.append(111 * (rows - i) % 32767) + data_set.tint_un_data.append(11 * (rows - i) % 127) + data_set.float_data.append(1.11 * (rows - i)) + data_set.double_data.append(1100.0011 * (rows - i)) + data_set.bool_data.append((rows - i) % 2) + data_set.binary_data.append(f'binary{(rows - i)}') + data_set.nchar_data.append(f'nchar_测试_{(rows - i)}') + + return data_set + + def __insert_data(self): + data = self.__data_set(rows=self.rows) + + # now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + null_data = '''null, null, null, null, null, null, null, null, null, null, null, null, null, null''' + zero_data = "0, 0, 0, 0, 0, 0, 0, 'binary_0', 'nchar_0', 0, 0, 0, 0, 0" + + for i in range(self.rows): + row_data = f''' + {data.int_data[i]}, {data.bint_data[i]}, {data.sint_data[i]}, {data.tint_data[i]}, {data.float_data[i]}, {data.double_data[i]}, + {data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {data.tint_un_data[i]}, + {data.sint_un_data[i]}, {data.int_un_data[i]}, {data.bint_un_data[i]} + ''' + neg_row_data = f''' + {-1 * data.int_data[i]}, {-1 * data.bint_data[i]}, {-1 * data.sint_data[i]}, {-1 * data.tint_data[i]}, {-1 * data.float_data[i]}, {-1 * data.double_data[i]}, + {data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {1 * data.tint_un_data[i]}, + {1 * data.sint_un_data[i]}, {1 * data.int_un_data[i]}, {1 * data.bint_un_data[i]} + ''' + + tdSql.execute( + f"insert into ct1 values ( {NOW - i * TIME_STEP}, {row_data} )") + tdSql.execute( + f"insert into ct2 values ( {NOW - i * int(TIME_STEP * 0.6)}, {neg_row_data} )") + tdSql.execute( + f"insert into ct4 values ( {NOW - i * int(TIME_STEP * 0.8) }, {row_data} )") + tdSql.execute( + f"insert into t1 values ( {NOW - i * int(TIME_STEP * 1.2)}, {row_data} )") + + tdSql.execute( + f"insert into ct2 values ( {NOW + int(TIME_STEP * 0.6)}, {null_data} )") + tdSql.execute( + f"insert into ct2 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.6)}, {null_data} )") + tdSql.execute( + f"insert into ct2 values ( {NOW - self.rows * int(TIME_STEP * 0.29) }, {null_data} )") + + tdSql.execute( + f"insert into ct4 values ( {NOW + int(TIME_STEP * 0.8)}, {null_data} )") + tdSql.execute( + f"insert into ct4 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.8)}, {null_data} )") + tdSql.execute( + f"insert into ct4 values ( {NOW - self.rows * int(TIME_STEP * 0.39)}, {null_data} )") + + tdSql.execute( + f"insert into t1 values ( {NOW + int(TIME_STEP * 1.2)}, {null_data} )") + tdSql.execute( + f"insert into t1 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 1.2)}, {null_data} )") + tdSql.execute( + f"insert into t1 values ( {NOW - self.rows * int(TIME_STEP * 0.59)}, {null_data} )") + + def run(self): + sma1 = SMAschema(func=("min(c1)","max(c2)")) + sql1 = self.__create_sma_index(sma1) + print("================") + print(sql1) + # a = DataSet() + # return + self.rows = 10 + + tdLog.printNoPrefix("==========step0:all check") + # self.all_test() + + tdLog.printNoPrefix("==========step1:create table in normal database") + tdSql.prepare() + self.__create_tb() + self.__insert_data() + return + + tdLog.printNoPrefix("==========step2:create table in rollup database") + tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m") + tdSql.execute("use db3") + self.__create_tb() + self.__insert_data() + + tdSql.execute("drop database if exists db1 ") + tdSql.execute("drop database if exists db2 ") + + tdDnodes.stop(1) + tdDnodes.start(1) + + tdLog.printNoPrefix("==========step4:after wal, all check again ") + self.all_test() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/Today.py b/tests/system-test/2-query/Today.py index 9eb06de9fb..a9c3215a12 100644 --- a/tests/system-test/2-query/Today.py +++ b/tests/system-test/2-query/Today.py @@ -4,394 +4,163 @@ from util.dnodes import * from util.log import * from util.sql import * from util.cases import * +import datetime class TDTestCase: - updatecfgDict = {'rpcDebugFlag': '143'} def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) + self.today_date = datetime.datetime.strptime( + datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d") + self.time_unit = ['b','u','a','s','m','h','d','w'] + self.error_param = ['1.5','abc','!@#','"abc"','today()'] + self.arithmetic_operators = ['+','-','*','/'] + self.relational_operator = ['<','<=','=','>=','>'] + # prepare data + self.ntbname = 'ntb' + self.stbname = 'stb' + self.column_dict = { + 'ts':'timestamp', + 'c1':'int', + 'c2':'float', + 'c3':'double', + 'c4':'timestamp' + } + self.tag_dict = { + 't0':'int' + } + self.tbnum = 2 + self.tag_values = [ + f'10', + f'100' + ] + self.values_list = [f'now,1,1.55,100.555555,today()', + f'now+1d,10,11.11,99.999999,now()', + f'today(),3,3.333,333.333333,now()', + f'today()-1d,10,11.11,99.999999,now()', + f'today()+1d,1,1.55,100.555555,today()'] + + def set_create_normaltable_sql(self, ntbname, column_dict): + column_sql = '' + for k, v in column_dict.items(): + column_sql += f"{k} {v}," + create_ntb_sql = f'create table {ntbname} ({column_sql[:-1]})' + return create_ntb_sql + def set_create_stable_sql(self,stbname,column_dict,tag_dict): + column_sql = '' + tag_sql = '' + for k,v in column_dict.items(): + column_sql += f"{k} {v}," + for k,v in tag_dict.items(): + tag_sql += f"{k} {v}," + create_stb_sql = f'create table {stbname} ({column_sql[:-1]}) tags({tag_sql[:-1]})' + return create_stb_sql + def data_check(self,column_dict={},tbname = '',values_list = [],tb_num = 1,tb = 'tb'): + for k,v in column_dict.items(): + num_up = 0 + num_down = 0 + num_same = 0 + if v.lower() == 'timestamp': + tdSql.query(f'select {k} from {tbname}') + for i in tdSql.queryResult: + if i[0] > self.today_date: + num_up += 1 + elif i[0] == self.today_date: + num_same += 1 + elif i[0] < self.today_date: + num_down += 1 + tdSql.query(f"select today() from {tbname}") + tdSql.checkRows(len(values_list)*tb_num) + tdSql.checkData(0, 0, str(self.today_date)) + tdSql.query(f"select * from {tbname} where {k}=today()") + if tb == 'tb': + tdSql.checkRows(num_same*tb_num) + elif tb == 'stb': + tdSql.checkRows(num_same) + for i in [f'{tbname}',f'db.{tbname}']: + for unit in self.time_unit: + for symbol in ['+','-']: + tdSql.query(f"select today() {symbol}1{unit} from {i}") + tdSql.checkRows(len(values_list)*tb_num) + for unit in self.error_param: + for symbol in self.arithmetic_operators: + tdSql.error(f'select today() {symbol}{unit} from {i}') + for symbol in self.arithmetic_operators: + tdSql.query(f'select now(){symbol}null from {i}') + tdSql.checkData(0,0,None) + for symbol in self.relational_operator: + tdSql.query(f'select * from {i} where {k} {symbol} today()') + if symbol == '<' : + if tb == 'tb': + tdSql.checkRows(num_down*tb_num) + elif tb == 'stb': + tdSql.checkRows(num_down) + elif symbol == '<=': + if tb == 'tb': + tdSql.checkRows((num_same+num_down)*tb_num) + elif tb == 'stb': + tdSql.checkRows(num_same+num_down) + elif symbol == '=': + if tb == 'tb': + tdSql.checkRows(num_same*tb_num) + elif tb == 'stb': + tdSql.checkRows(num_same) + elif symbol == '>=': + if tb == 'tb': + tdSql.checkRows((num_up + num_same)*tb_num) + elif tb == 'stb': + tdSql.checkRows(num_up + num_same) + elif symbol == '>': + if tb == 'tb': + tdSql.checkRows(num_up*tb_num) + elif tb == 'stb': + tdSql.checkRows(num_up) + tdSql.query(f"select today()/0 from {tbname}") + tdSql.checkRows(len(values_list)*tb_num) + tdSql.checkData(0,0,None) + tdSql.query(f"select {k} from {tbname} where {k}=today()") + if tb == 'tb': + tdSql.checkRows(num_same*tb_num) + for i in range(num_same*tb_num): + tdSql.checkData(i, 0, str(self.today_date)) + elif tb == 'stb': + tdSql.checkRows(num_same) + for i in range(num_same): + tdSql.checkData(i, 0, str(self.today_date)) + def today_check_ntb(self): + tdSql.prepare() + tdSql.execute(self.set_create_normaltable_sql(self.ntbname,self.column_dict)) + for i in self.values_list: + tdSql.execute( + f'insert into {self.ntbname} values({i})') + self.data_check(self.column_dict,self.ntbname,self.values_list) + tdSql.execute('drop database db') + def today_check_stb_tb(self): + tdSql.prepare() + tdSql.execute(self.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict)) + for i in range(self.tbnum): + tdSql.execute(f'create table if not exists {self.stbname}_{i} using {self.stbname} tags({self.tag_values[i]})') + for j in self.values_list: + tdSql.execute(f'insert into {self.stbname}_{i} values ({j})') + # check child table + for i in range(self.tbnum): + self.data_check(self.column_dict,f'{self.stbname}_{i}',self.values_list) + # check stable + self.data_check(self.column_dict,self.stbname,self.values_list,self.tbnum,'stb') + tdSql.execute('drop database db') def run(self): # sourcery skip: extract-duplicate-method - # for func now() , today(), timezone() - tdSql.prepare() - today_date = datetime.datetime.strptime( - datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d") + + tdLog.printNoPrefix("==========check today() for normal table ==========") + self.today_check_ntb() + tdLog.printNoPrefix("==========check today() for stable and child table==========") + self.today_check_stb_tb() - tdLog.printNoPrefix("==========step1:create tables==========") - tdSql.execute( - '''create table if not exists ntb - (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) - ''' - ) - tdSql.execute( - '''create table if not exists stb - (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int) - ''' - ) - tdSql.execute( - '''create table if not exists stb_1 using stb tags(100) - ''' - ) - tdLog.printNoPrefix("==========step2:insert data into ntb==========") - tdSql.execute( - 'insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') - tdSql.execute( - 'insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') - tdLog.printNoPrefix("==========step2:query test of ntb ==========") - - # test function today() - # normal table - tdSql.query("select today() from ntb") - tdSql.checkRows(3) - tdSql.checkData(0, 0, str(today_date)) - tdSql.query("select today() from db.ntb") - tdSql.checkRows(3) - tdSql.checkData(0, 0, str(today_date)) - tdSql.query("select today() +1w from ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1w from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1d from ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1d from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1h from ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1h from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1m from ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1m from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1s from ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1s from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1a from ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1a from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1u from ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1u from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1b from ntb") - tdSql.checkRows(3) - tdSql.query("select today() +1b from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1w from ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1w from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1d from ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1d from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1h from ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1h from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1m from ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1m from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1s from ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1s from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1a from ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1a from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1u from ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1u from db.ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1b from ntb") - tdSql.checkRows(3) - tdSql.query("select today() -1b from db.ntb") - tdSql.checkRows(3) - tdSql.query("select * from ntb where ts=today()") - tdSql.checkRows(1) - tdSql.checkData(0, 1, 3) - tdSql.query("select * from ntb where ts<=today()") - tdSql.checkRows(2) - tdSql.checkData(0, 1, 10) - # for bug - # tdSql.query("select * from ntb where ts=today()") - tdSql.checkRows(2) - tdSql.checkData(0, 1, 3) - # tdSql.query("select * from ntb where ts>today()") - # tdSql.checkRows(1) - tdSql.query("select c4 from ntb where c4=today()") - tdSql.checkRows(1) - tdSql.checkData(0, 0, str(today_date)) - tdSql.query("select today() from ntb where ts=today()") - # tdSql.checkRows(2) - # tdSql.query("select * from ntb where ts>today()") - # tdSql.checkRows(1) - tdSql.query("select c4 from stb where c4=today()") - tdSql.checkRows(1) - tdSql.checkData(0, 0, str(today_date)) - tdSql.query("select today() from stb where ts=today()") - tdSql.checkRows(2) - tdSql.query("select * from ntb where ts>today()") - tdSql.checkRows(1) - tdSql.query("select c4 from stb_1 where c4=today()") - tdSql.checkRows(1) - tdSql.query("select today() from stb_1 where ts=2: + count+=1 + if count < 2: + tdLog.exit(" the datas of all not satisfy sub_table has been distributed ") + + def check_avg_distribute_diff_vnode(self,col_name): + + vgroup_ids = [] + for k ,v in self.vnode_disbutes.items(): + if len(v)>=2: + vgroup_ids.append(k) + + distribute_tbnames = [] + + for vgroup_id in vgroup_ids: + vnode_tables = self.vnode_disbutes[vgroup_id] + distribute_tbnames.append(random.sample(vnode_tables,1)[0]) + tbname_ins = "" + for tbname in distribute_tbnames: + tbname_ins += "'%s' ,"%tbname + + tbname_filters = tbname_ins[:-1] + + avg_sql = f"select avg({col_name}) from stb1 where tbname in ({tbname_filters});" + + same_sql = f"select {col_name} from stb1 where tbname in ({tbname_filters}) and {col_name} is not null " + + tdSql.query(same_sql) + pre_data = np.array(tdSql.queryResult)[np.array(tdSql.queryResult) != None] + if (platform.system().lower() == 'windows' and pre_data.dtype == 'int32'): + pre_data = np.array(pre_data, dtype = 'int64') + pre_avg = np.sum(pre_data)/len(pre_data) + + tdSql.query(avg_sql) + tdSql.checkData(0,0,pre_avg) + + def check_avg_status(self): + # check max function work status + + tdSql.query("show tables like 'ct%'") + table_names = tdSql.queryResult + tablenames = [] + for table_name in table_names: + tablenames.append(table_name[0]) + + tdSql.query("desc stb1") + col_names = tdSql.queryResult + + colnames = [] + for col_name in col_names: + if col_name[1] in ["INT" ,"BIGINT" ,"SMALLINT" ,"TINYINT" , "FLOAT" ,"DOUBLE"]: + colnames.append(col_name[0]) + + for tablename in tablenames: + for colname in colnames: + self.check_avg_functions(tablename,colname) + + # check max function for different vnode + + for colname in colnames: + if colname.startswith("c"): + self.check_avg_distribute_diff_vnode(colname) + else: + # self.check_avg_distribute_diff_vnode(colname) # bug for tag + pass + + + def distribute_agg_query(self): + # basic filter + tdSql.query(" select avg(c1) from stb1 ") + tdSql.checkData(0,0,14.086956522) + + tdSql.query(" select avg(a) from (select avg(c1) a from stb1 partition by tbname) ") + tdSql.checkData(0,0,14.292307692) + + tdSql.query(" select avg(c1) from stb1 where t1=1") + tdSql.checkData(0,0,6.000000000) + + tdSql.query("select avg(c1+c2) from stb1 where c1 =1 ") + tdSql.checkData(0,0,11112.000000000) + + tdSql.query("select avg(c1) from stb1 where tbname=\"ct2\"") + tdSql.checkData(0,0,6.000000000) + + tdSql.query("select avg(c1) from stb1 partition by tbname") + tdSql.checkRows(20) + + tdSql.query("select avg(c1) from stb1 where t1> 4 partition by tbname") + tdSql.checkRows(15) + + # union all + tdSql.query("select avg(c1) from stb1 union all select avg(c1) from stb1 ") + tdSql.checkRows(2) + tdSql.checkData(0,0,14.086956522) + + tdSql.query("select avg(a) from (select avg(c1) a from stb1 union all select avg(c1) a from stb1)") + tdSql.checkRows(1) + tdSql.checkData(0,0,14.086956522) + + # join + + tdSql.execute(" create database if not exists db ") + tdSql.execute(" use db ") + tdSql.execute(" create stable st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") + tdSql.execute(" create table tb1 using st tags(1) ") + tdSql.execute(" create table tb2 using st tags(2) ") + + + for i in range(10): + ts = i*10 + self.ts + tdSql.execute(f" insert into tb1 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into tb2 values({ts},{i},{i}.0)") + + tdSql.query("select avg(tb1.c1), avg(tb2.c2) from tb1, tb2 where tb1.ts=tb2.ts") + tdSql.checkRows(1) + tdSql.checkData(0,0,4.500000000) + tdSql.checkData(0,1,4.500000000) + + # group by + tdSql.execute(" use testdb ") + + # partition by tbname or partition by tag + tdSql.query("select avg(c1) from stb1 partition by tbname") + tdSql.checkRows(20) + + # nest query for support max + tdSql.query("select avg(c2+2)+1 from (select avg(c1) c2 from stb1)") + tdSql.checkData(0,0,17.086956522) + tdSql.query("select avg(c1+2) as c2 from (select ts ,c1 ,c2 from stb1)") + tdSql.checkData(0,0,16.086956522) + tdSql.query("select avg(a+2) as c2 from (select ts ,abs(c1) a ,c2 from stb1)") + tdSql.checkData(0,0,16.086956522) + + # mixup with other functions + tdSql.query("select max(c1),count(c1),last(c2,c3),sum(c1+c2),avg(c1) from stb1") + tdSql.checkData(0,0,28) + tdSql.checkData(0,1,184) + tdSql.checkData(0,2,-99999) + tdSql.checkData(0,3,-999) + tdSql.checkData(0,4,28202310.000000000) + tdSql.checkData(0,5,14.086956522) + + def run(self): + + self.prepare_datas_of_distribute() + self.check_distribute_datas() + self.check_avg_status() + self.distribute_agg_query() + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/distribute_agg_max.py b/tests/system-test/2-query/distribute_agg_max.py index ae0ab5aafa..5c9760cbcf 100644 --- a/tests/system-test/2-query/distribute_agg_max.py +++ b/tests/system-test/2-query/distribute_agg_max.py @@ -245,6 +245,27 @@ class TDTestCase: tdSql.query(" select max(c1),c2 from stb1 group by c2 ") tdSql.checkRows(31) + # selective common cols of datas + tdSql.query("select max(c1),c2,c3,c5 from stb1") + tdSql.checkRows(1) + tdSql.checkData(0,0,28) + tdSql.checkData(0,1,311108) + tdSql.checkData(0,2,3108) + tdSql.checkData(0,3,31.08000) + + tdSql.query("select max(c1),t1,c2,t3 from stb1") + tdSql.checkRows(1) + tdSql.checkData(0,0,28) + tdSql.checkData(0,1,19) + tdSql.checkData(0,2,311108) + + tdSql.query("select max(c1),ceil(t1),pow(c2,1)+2,abs(t3) from stb1") + tdSql.checkRows(1) + tdSql.checkData(0,0,28) + tdSql.checkData(0,1,19) + tdSql.checkData(0,2,311110.000000000) + tdSql.checkData(0,3,2109) + # partition by tbname or partition by tag tdSql.query("select max(c1),tbname from stb1 partition by tbname") query_data = tdSql.queryResult diff --git a/tests/system-test/2-query/distribute_agg_min.py b/tests/system-test/2-query/distribute_agg_min.py index 8a458c74df..dd20d88229 100644 --- a/tests/system-test/2-query/distribute_agg_min.py +++ b/tests/system-test/2-query/distribute_agg_min.py @@ -245,6 +245,24 @@ class TDTestCase: tdSql.query(" select min(c1),c2 from stb1 group by c2 ") tdSql.checkRows(31) + # selective common cols of datas + tdSql.query("select min(c1),c2,c3,c5 from stb1") + tdSql.checkRows(1) + tdSql.checkData(0,0,0) + tdSql.checkData(0,1,0) + tdSql.checkData(0,2,0) + tdSql.checkData(0,3,0) + + tdSql.query("select min(c1),t1,c2,t3 from stb1 where c1 >5") + tdSql.checkRows(1) + tdSql.checkData(0,0,6) + tdSql.checkData(0,2,66666) + + tdSql.query("select min(c1),ceil(t1),pow(c2,1)+2,abs(t3) from stb1 where c1>12") + tdSql.checkRows(1) + tdSql.checkData(0,0,13) + tdSql.checkData(0,2,144445.000000000) + # partition by tbname or partition by tag tdSql.query("select min(c1),tbname from stb1 partition by tbname") query_data = tdSql.queryResult diff --git a/tests/system-test/2-query/distribute_agg_stddev.py b/tests/system-test/2-query/distribute_agg_stddev.py new file mode 100644 index 0000000000..5050e6e940 --- /dev/null +++ b/tests/system-test/2-query/distribute_agg_stddev.py @@ -0,0 +1,304 @@ +from util.log import * +from util.cases import * +from util.sql import * +import numpy as np +import random ,os ,sys +import platform +import math + +class TDTestCase: + updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, + "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"fnDebugFlag":143, + "maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + self.vnode_disbutes = None + self.ts = 1537146000000 + + + def check_stddev_functions(self, tbname , col_name): + + stddev_sql = f"select stddev({col_name}) from {tbname};" + + same_sql = f"select {col_name} from {tbname} where {col_name} is not null " + + tdSql.query(same_sql) + pre_data = np.array(tdSql.queryResult)[np.array(tdSql.queryResult) != None] + if (platform.system().lower() == 'windows' and pre_data.dtype == 'int32'): + pre_data = np.array(pre_data, dtype = 'int64') + pre_avg = np.sum(pre_data)/len(pre_data) + + # Calculate variance + stddev_result = 0 + for num in tdSql.queryResult: + stddev_result += (num-pre_avg)*(num-pre_avg)/len(tdSql.queryResult) + + stddev_result = math.sqrt(stddev_result) + + tdSql.query(stddev_sql) + + if -0.0001 < tdSql.queryResult[0][0]-stddev_result < 0.0001: + tdLog.info(" sql:%s; row:0 col:0 data:%d , expect:%d"%(stddev_sql,tdSql.queryResult[0][0],stddev_result)) + else: + tdLog.exit(" sql:%s; row:0 col:0 data:%d , expect:%d"%(stddev_sql,tdSql.queryResult[0][0],stddev_result)) + + def prepare_datas_of_distribute(self): + + # prepate datas for 20 tables distributed at different vgroups + tdSql.execute("create database if not exists testdb keep 3650 duration 1000 vgroups 5") + tdSql.execute(" use testdb ") + tdSql.execute( + '''create table stb1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) + ''' + ) + + tdSql.execute( + ''' + create table t1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + ''' + ) + for i in range(20): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') + + for i in range(9): + tdSql.execute( + f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute( + f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + + for i in range(1,21): + if i ==1 or i == 4: + continue + else: + tbname = "ct"+f'{i}' + for j in range(9): + tdSql.execute( + f"insert into {tbname} values ( now()-{(i+j)*10}s, {1*(j+i)}, {11111*(j+i)}, {111*(j+i)}, {11*(j)}, {1.11*(j+i)}, {11.11*(j+i)}, {(j+i)%2}, 'binary{j}', 'nchar{j}', now()+{1*j}a )" + ) + tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + + tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + + tdSql.execute( + f'''insert into t1 values + ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) + ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) + ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) + ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) + ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) + ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) + ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) + ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ''' + ) + + tdLog.info(" prepare data for distributed_aggregate done! ") + + def check_distribute_datas(self): + # get vgroup_ids of all + tdSql.query("show vgroups ") + vgroups = tdSql.queryResult + + vnode_tables={} + + for vgroup_id in vgroups: + vnode_tables[vgroup_id[0]]=[] + + + # check sub_table of per vnode ,make sure sub_table has been distributed + tdSql.query("show tables like 'ct%'") + table_names = tdSql.queryResult + tablenames = [] + for table_name in table_names: + vnode_tables[table_name[6]].append(table_name[0]) + self.vnode_disbutes = vnode_tables + + count = 0 + for k ,v in vnode_tables.items(): + if len(v)>=2: + count+=1 + if count < 2: + tdLog.exit(" the datas of all not satisfy sub_table has been distributed ") + + def check_stddev_distribute_diff_vnode(self,col_name): + + vgroup_ids = [] + for k ,v in self.vnode_disbutes.items(): + if len(v)>=2: + vgroup_ids.append(k) + + distribute_tbnames = [] + + for vgroup_id in vgroup_ids: + vnode_tables = self.vnode_disbutes[vgroup_id] + distribute_tbnames.append(random.sample(vnode_tables,1)[0]) + tbname_ins = "" + for tbname in distribute_tbnames: + tbname_ins += "'%s' ,"%tbname + + tbname_filters = tbname_ins[:-1] + + stddev_sql = f"select stddev({col_name}) from stb1 where tbname in ({tbname_filters});" + + same_sql = f"select {col_name} from stb1 where tbname in ({tbname_filters}) and {col_name} is not null " + + tdSql.query(same_sql) + pre_data = np.array(tdSql.queryResult)[np.array(tdSql.queryResult) != None] + if (platform.system().lower() == 'windows' and pre_data.dtype == 'int32'): + pre_data = np.array(pre_data, dtype = 'int64') + pre_avg = np.sum(pre_data)/len(pre_data) + + # Calculate variance + stddev_result = 0 + for num in tdSql.queryResult: + stddev_result += (num-pre_avg)*(num-pre_avg)/len(tdSql.queryResult) + + stddev_result = math.sqrt(stddev_result) + + tdSql.query(stddev_sql) + tdSql.checkData(0,0,stddev_result) + + + def check_stddev_status(self): + # check max function work status + + tdSql.query("show tables like 'ct%'") + table_names = tdSql.queryResult + tablenames = [] + for table_name in table_names: + tablenames.append(table_name[0]) + + tdSql.query("desc stb1") + col_names = tdSql.queryResult + + colnames = [] + for col_name in col_names: + if col_name[1] in ["INT" ,"BIGINT" ,"SMALLINT" ,"TINYINT" , "FLOAT" ,"DOUBLE"]: + colnames.append(col_name[0]) + + for tablename in tablenames: + for colname in colnames: + if colname.startswith("c"): + self.check_stddev_functions(tablename,colname) + else: + # self.check_stddev_functions(tablename,colname) + pass + + + # check max function for different vnode + + for colname in colnames: + if colname.startswith("c"): + self.check_stddev_distribute_diff_vnode(colname) + else: + # self.check_stddev_distribute_diff_vnode(colname) # bug for tag + pass + + + def distribute_agg_query(self): + # basic filter + tdSql.query(" select stddev(c1) from stb1 ") + tdSql.checkData(0,0,6.694663959) + + tdSql.query(" select stddev(a) from (select stddev(c1) a from stb1 partition by tbname) ") + tdSql.checkData(0,0,0.156797505) + + tdSql.query(" select stddev(c1) from stb1 where t1=1") + tdSql.checkData(0,0,2.581988897) + + tdSql.query("select stddev(c1+c2) from stb1 where c1 =1 ") + tdSql.checkData(0,0,0.000000000) + + tdSql.query("select stddev(c1) from stb1 where tbname=\"ct2\"") + tdSql.checkData(0,0,2.581988897) + + tdSql.query("select stddev(c1) from stb1 partition by tbname") + tdSql.checkRows(20) + + tdSql.query("select stddev(c1) from stb1 where t1> 4 partition by tbname") + tdSql.checkRows(15) + + # union all + tdSql.query("select stddev(c1) from stb1 union all select stddev(c1) from stb1 ") + tdSql.checkRows(2) + tdSql.checkData(0,0,6.694663959) + + tdSql.query("select stddev(a) from (select stddev(c1) a from stb1 union all select stddev(c1) a from stb1)") + tdSql.checkRows(1) + tdSql.checkData(0,0,0.000000000) + + # join + + tdSql.execute(" create database if not exists db ") + tdSql.execute(" use db ") + tdSql.execute(" create stable st (ts timestamp , c1 int ,c2 float) tags(t1 int) ") + tdSql.execute(" create table tb1 using st tags(1) ") + tdSql.execute(" create table tb2 using st tags(2) ") + + + for i in range(10): + ts = i*10 + self.ts + tdSql.execute(f" insert into tb1 values({ts},{i},{i}.0)") + tdSql.execute(f" insert into tb2 values({ts},{i},{i}.0)") + + tdSql.query("select stddev(tb1.c1), stddev(tb2.c2) from tb1, tb2 where tb1.ts=tb2.ts") + tdSql.checkRows(1) + tdSql.checkData(0,0,2.872281323) + tdSql.checkData(0,1,2.872281323) + + # group by + tdSql.execute(" use testdb ") + + # partition by tbname or partition by tag + tdSql.query("select stddev(c1) from stb1 partition by tbname") + tdSql.checkRows(20) + + # nest query for support max + tdSql.query("select stddev(c2+2)+1 from (select stddev(c1) c2 from stb1)") + tdSql.checkData(0,0,1.000000000) + tdSql.query("select stddev(c1+2) as c2 from (select ts ,c1 ,c2 from stb1)") + tdSql.checkData(0,0,6.694663959) + tdSql.query("select stddev(a+2) as c2 from (select ts ,abs(c1) a ,c2 from stb1)") + tdSql.checkData(0,0,6.694663959) + + # mixup with other functions + tdSql.query("select max(c1),count(c1),last(c2,c3),sum(c1+c2),avg(c1),stddev(c1) from stb1") + tdSql.checkData(0,0,28) + tdSql.checkData(0,1,184) + tdSql.checkData(0,2,-99999) + tdSql.checkData(0,3,-999) + tdSql.checkData(0,4,28202310.000000000) + tdSql.checkData(0,5,14.086956522) + tdSql.checkData(0,6,6.694663959) + + def run(self): + + self.prepare_datas_of_distribute() + self.check_distribute_datas() + self.check_stddev_status() + self.distribute_agg_query() + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/join.py b/tests/system-test/2-query/join.py index 140808d387..5ff11c84dd 100644 --- a/tests/system-test/2-query/join.py +++ b/tests/system-test/2-query/join.py @@ -238,7 +238,7 @@ class TDTestCase: ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp - ) tags (t1 int) + ) tags (tag1 int) ''' create_ntb_sql = f'''create table t1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, diff --git a/tests/system-test/2-query/substr.py b/tests/system-test/2-query/substr.py index e78606826b..79b5ac515b 100644 --- a/tests/system-test/2-query/substr.py +++ b/tests/system-test/2-query/substr.py @@ -23,6 +23,9 @@ CHAR_COL = [ BINARY_COL, NCHAR_COL, ] BOOLEAN_COL = [ BOOL_COL, ] TS_TYPE_COL = [ TS_COL, ] +ERR_POS = 0 +CURRENT_POS = 1 +LENS = 6 class TDTestCase: @@ -76,6 +79,7 @@ class TDTestCase: if pos < 1: tdSql.error(f"select substr( {condition}, {pos}, {lens}) , {condition} from {tbname} ") + break tdSql.query(f"select substr( {condition}, {pos}, {lens}) , {condition} from {tbname} ") for j in range(tdSql.queryRows): @@ -127,7 +131,7 @@ class TDTestCase: tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] for tb in tbname: - self.__substr_check(tb, 1, 6) + self.__substr_check(tb, CURRENT_POS, LENS) tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") def __test_error(self): @@ -137,7 +141,7 @@ class TDTestCase: for tb in tbname: for errsql in self.__substr_err_check(tb): tdSql.error(sql=errsql) - self.__substr_check(tb, 0, 6) + self.__substr_check(tb, ERR_POS, LENS) tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") @@ -154,7 +158,7 @@ class TDTestCase: ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp - ) tags (t1 int) + ) tags (tag1 int) ''' create_ntb_sql = f'''create table t1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index ea0e1f7fae..f6ff4989e7 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -73,7 +73,7 @@ class TDTestCase: f"select sum(ceil( {un_num_col} )) from {tbanme} ", ) ) - sqls.extend( f"select sum( {un_num_col} + {un_num_col_2} ) from {tbanme} " for un_num_col_2 in UN_NUM_COL ) + # sqls.extend( f"select sum( {un_num_col} + {un_num_col_2} ) from {tbanme} " for un_num_col_2 in UN_NUM_COL ) sqls.extend( f"select sum( {num_col} + {ts_col} ) from {tbanme} " for num_col in NUM_COL for ts_col in TS_TYPE_COL) sqls.extend( diff --git a/tests/system-test/2-query/ttl_comment.py b/tests/system-test/2-query/ttl_comment.py new file mode 100644 index 0000000000..8fc582c587 --- /dev/null +++ b/tests/system-test/2-query/ttl_comment.py @@ -0,0 +1,206 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, db_test.stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql + +class TDTestCase: + def caseDescription(self): + ''' + ttl/comment test + ''' + return + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + + tdSql.error("create table ttl_table1(ts timestamp, i int) ttl 1.1") + tdSql.error("create table ttl_table2(ts timestamp, i int) ttl 1e1") + tdSql.error("create table ttl_table3(ts timestamp, i int) ttl -1") + + print("============== STEP 1 ===== test normal table") + + tdSql.execute("create table normal_table1(ts timestamp, i int)") + tdSql.execute("create table normal_table2(ts timestamp, i int) comment '' ttl 3") + tdSql.execute("create table normal_table3(ts timestamp, i int) ttl 2100000000020 comment 'hello'") + + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 7, 0) + tdSql.checkData(0, 8, None) + + + tdSql.query("show tables like 'normal_table2'") + tdSql.checkData(0, 0, 'normal_table2') + tdSql.checkData(0, 7, 3) + tdSql.checkData(0, 8, '') + + + tdSql.query("show tables like 'normal_table3'") + tdSql.checkData(0, 0, 'normal_table3') + tdSql.checkData(0, 7, 2147483647) + tdSql.checkData(0, 8, 'hello') + + tdSql.execute("alter table normal_table1 comment 'nihao'") + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 8, 'nihao') + + tdSql.execute("alter table normal_table1 comment ''") + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 8, '') + + tdSql.execute("alter table normal_table2 comment 'fly'") + tdSql.query("show tables like 'normal_table2'") + tdSql.checkData(0, 0, 'normal_table2') + tdSql.checkData(0, 8, 'fly') + + tdSql.execute("alter table normal_table3 comment 'fly'") + tdSql.query("show tables like 'normal_table3'") + tdSql.checkData(0, 0, 'normal_table3') + tdSql.checkData(0, 8, 'fly') + + tdSql.execute("alter table normal_table1 ttl 1") + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 7, 1) + + tdSql.execute("alter table normal_table3 ttl 0") + tdSql.query("show tables like 'normal_table3'") + tdSql.checkData(0, 0, 'normal_table3') + tdSql.checkData(0, 7, 0) + + + print("============== STEP 2 ===== test super table") + + tdSql.execute("create table super_table1(ts timestamp, i int) tags(t int)") + tdSql.execute("create table super_table2(ts timestamp, i int) tags(t int) comment ''") + tdSql.execute("create table super_table3(ts timestamp, i int) tags(t int) comment 'super'") + + tdSql.query("show stables like 'super_table1'") + tdSql.checkData(0, 0, 'super_table1') + tdSql.checkData(0, 6, None) + + + tdSql.query("show stables like 'super_table2'") + tdSql.checkData(0, 0, 'super_table2') + tdSql.checkData(0, 6, '') + + + tdSql.query("show stables like 'super_table3'") + tdSql.checkData(0, 0, 'super_table3') + tdSql.checkData(0, 6, 'super') + + + tdSql.execute("alter table super_table1 comment 'nihao'") + tdSql.query("show stables like 'super_table1'") + tdSql.checkData(0, 0, 'super_table1') + tdSql.checkData(0, 6, 'nihao') + + tdSql.execute("alter table super_table1 comment ''") + tdSql.query("show stables like 'super_table1'") + tdSql.checkData(0, 0, 'super_table1') + tdSql.checkData(0, 6, '') + + tdSql.execute("alter table super_table2 comment 'fly'") + tdSql.query("show stables like 'super_table2'") + tdSql.checkData(0, 0, 'super_table2') + tdSql.checkData(0, 6, 'fly') + + tdSql.execute("alter table super_table3 comment 'tdengine'") + tdSql.query("show stables like 'super_table3'") + tdSql.checkData(0, 0, 'super_table3') + tdSql.checkData(0, 6, 'tdengine') + + print("============== STEP 3 ===== test child table") + + tdSql.execute("create table child_table1 using super_table1 tags(1) ttl 10") + tdSql.execute("create table child_table2 using super_table1 tags(1) comment ''") + tdSql.execute("create table child_table3 using super_table1 tags(1) comment 'child'") + tdSql.execute("insert into child_table4 using super_table1 tags(1) values(now, 1)") + + + tdSql.query("show tables like 'child_table1'") + tdSql.checkData(0, 0, 'child_table1') + tdSql.checkData(0, 7, 10) + tdSql.checkData(0, 8, None) + + + tdSql.query("show tables like 'child_table2'") + tdSql.checkData(0, 0, 'child_table2') + tdSql.checkData(0, 7, 0) + tdSql.checkData(0, 8, '') + + + tdSql.query("show tables like 'child_table3'") + tdSql.checkData(0, 0, 'child_table3') + tdSql.checkData(0, 8, 'child') + + tdSql.query("show tables like 'child_table4'") + tdSql.checkData(0, 0, 'child_table4') + tdSql.checkData(0, 7, 0) + tdSql.checkData(0, 8, None) + + + tdSql.execute("alter table child_table1 comment 'nihao'") + tdSql.query("show tables like 'child_table1'") + tdSql.checkData(0, 0, 'child_table1') + tdSql.checkData(0, 8, 'nihao') + + tdSql.execute("alter table child_table1 comment ''") + tdSql.query("show tables like 'child_table1'") + tdSql.checkData(0, 0, 'child_table1') + tdSql.checkData(0, 8, '') + + tdSql.execute("alter table child_table2 comment 'fly'") + tdSql.query("show tables like 'child_table2'") + tdSql.checkData(0, 0, 'child_table2') + tdSql.checkData(0, 8, 'fly') + + tdSql.execute("alter table child_table3 comment 'tdengine'") + tdSql.query("show tables like 'child_table3'") + tdSql.checkData(0, 0, 'child_table3') + tdSql.checkData(0, 8, 'tdengine') + + + tdSql.execute("alter table child_table4 comment 'tdengine'") + tdSql.query("show tables like 'child_table4'") + tdSql.checkData(0, 0, 'child_table4') + tdSql.checkData(0, 8, 'tdengine') + + tdSql.execute("alter table child_table4 ttl 9") + tdSql.query("show tables like 'child_table4'") + tdSql.checkData(0, 0, 'child_table4') + tdSql.checkData(0, 7, 9) + + tdSql.execute("alter table child_table3 ttl 9") + tdSql.query("show tables like 'child_table3'") + tdSql.checkData(0, 0, 'child_table3') + tdSql.checkData(0, 7, 9) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) + diff --git a/tests/system-test/6-cluster/5dnode3mnodeDrop.py b/tests/system-test/6-cluster/5dnode3mnodeDrop.py index b98134f5e0..e81d5295f2 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeDrop.py +++ b/tests/system-test/6-cluster/5dnode3mnodeDrop.py @@ -75,7 +75,7 @@ class TDTestCase: testCluster = False valgrind = 0 hostname = socket.gethostname() - print(hostname) + tdLog.debug(hostname) dnodes = [] start_port = 6030 start_port_sec = 6130 @@ -102,12 +102,12 @@ class TDTestCase: # create cluster for dnode in self.TDDnodes.dnodes[1:]: - # print(dnode.cfgDict) + # tdLog.debug(dnode.cfgDict) dnode_id = dnode.cfgDict["fqdn"] + ":" +dnode.cfgDict["serverPort"] dnode_first_host = dnode.cfgDict["firstEp"].split(":")[0] dnode_first_port = dnode.cfgDict["firstEp"].split(":")[-1] cmd = f" taos -h {dnode_first_host} -P {dnode_first_port} -s ' create dnode \"{dnode_id} \" ' ;" - print(cmd) + tdLog.debug(cmd) os.system(cmd) time.sleep(2) @@ -119,26 +119,26 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[1][2]=='follower': if tdSql.queryResult[2][2]=='follower': - print("three mnodes is ready in 10s") + tdLog.debug("three mnodes is ready in 10s") break elif tdSql.queryResult[0][2]=='follower' : if tdSql.queryResult[1][2]=='leader': if tdSql.queryResult[2][2]=='follower': - print("three mnodes is ready in 10s") + tdLog.debug("three mnodes is ready in 10s") break elif tdSql.queryResult[0][2]=='follower' : if tdSql.queryResult[1][2]=='follower': if tdSql.queryResult[2][2]=='leader': - print("three mnodes is ready in 10s") + tdLog.debug("three mnodes is ready in 10s") break count+=1 else: - print(tdSql.queryResult) - print("three mnodes is not ready in 10s ") + tdLog.debug(tdSql.queryResult) + tdLog.debug("three mnodes is not ready in 10s ") return -1 tdSql.query("show mnodes;") @@ -156,19 +156,19 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='offline' : if tdSql.queryResult[1][2]=='leader': if tdSql.queryResult[2][2]=='follower': - print("stop mnodes on dnode 2 successfully in 10s") + tdLog.debug("stop mnodes on dnode 2 successfully in 10s") break elif tdSql.queryResult[1][2]=='follower': if tdSql.queryResult[2][2]=='leader': - print("stop mnodes on dnode 2 successfully in 10s") + tdLog.debug("stop mnodes on dnode 2 successfully in 10s") break count+=1 else: - print("stop mnodes on dnode 2 failed in 10s ") + tdLog.debug("stop mnodes on dnode 2 failed in 10s ") return -1 tdSql.error("drop mnode on dnode 1;") @@ -188,15 +188,15 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[1][2]=='offline': if tdSql.queryResult[2][2]=='follower': - print("stop mnodes on dnode 2 successfully in 10s") + tdLog.debug("stop mnodes on dnode 2 successfully in 10s") break count+=1 else: - print("stop mnodes on dnode 2 failed in 10s ") + tdLog.debug("stop mnodes on dnode 2 failed in 10s ") return -1 tdSql.error("drop mnode on dnode 2;") @@ -218,15 +218,15 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[2][2]=='offline': if tdSql.queryResult[1][2]=='follower': - print("stop mnodes on dnode 3 successfully in 10s") + tdLog.debug("stop mnodes on dnode 3 successfully in 10s") break count+=1 else: - print("stop mnodes on dnode 3 failed in 10s") + tdLog.debug("stop mnodes on dnode 3 failed in 10s") return -1 tdSql.error("drop mnode on dnode 3;") tdSql.query("show mnodes;") @@ -268,7 +268,7 @@ class TDTestCase: tdSql.error("drop mnode on dnode 1") tdSql.query("show dnodes;") - print(tdSql.queryResult) + tdLog.debug(tdSql.queryResult) # drop follower of mnode dropcount =0 @@ -282,7 +282,7 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(2): - print("drop mnode %d successfully"%(i+1)) + tdLog.debug("drop mnode %d successfully"%(i+1)) break count+=1 tdLog.debug("create mnode on dnode %d"%(i+1)) @@ -292,7 +292,7 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3): - print("drop mnode %d successfully"%(i+1)) + tdLog.debug("drop mnode %d successfully"%(i+1)) break count+=1 dropcount+=1 @@ -307,7 +307,7 @@ class TDTestCase: def run(self): - # print(self.master_dnode.cfgDict) + # tdLog.debug(self.master_dnode.cfgDict) self.buildcluster(5) self.five_dnode_three_mnode() diff --git a/tests/system-test/6-cluster/5dnode3mnodeStop.py b/tests/system-test/6-cluster/5dnode3mnodeStop.py index e11f819263..654b27bfc0 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeStop.py +++ b/tests/system-test/6-cluster/5dnode3mnodeStop.py @@ -99,12 +99,12 @@ class TDTestCase: # create cluster for dnode in self.TDDnodes.dnodes[1:]: - # print(dnode.cfgDict) + # tdLog.debug(dnode.cfgDict) dnode_id = dnode.cfgDict["fqdn"] + ":" +dnode.cfgDict["serverPort"] dnode_first_host = dnode.cfgDict["firstEp"].split(":")[0] dnode_first_port = dnode.cfgDict["firstEp"].split(":")[-1] cmd = f" taos -h {dnode_first_host} -P {dnode_first_port} -s ' create dnode \"{dnode_id} \" ' ;" - print(cmd) + tdLog.debug(cmd) os.system(cmd) time.sleep(2) @@ -116,25 +116,25 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[1][2]=='follower': if tdSql.queryResult[2][2]=='follower': - print("three mnodes is ready in 10s") + tdLog.debug("three mnodes is ready in 10s") break elif tdSql.queryResult[0][2]=='follower' : if tdSql.queryResult[1][2]=='leader': if tdSql.queryResult[2][2]=='follower': - print("three mnodes is ready in 10s") + tdLog.debug("three mnodes is ready in 10s") break elif tdSql.queryResult[0][2]=='follower' : if tdSql.queryResult[1][2]=='follower': if tdSql.queryResult[2][2]=='leader': - print("three mnodes is ready in 10s") + tdLog.debug("three mnodes is ready in 10s") break count+=1 else: - print("three mnodes is not ready in 10s ") + tdLog.debug("three mnodes is not ready in 10s ") return -1 tdSql.query("show mnodes;") @@ -152,19 +152,19 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='offline' : if tdSql.queryResult[1][2]=='leader': if tdSql.queryResult[2][2]=='follower': - print("stop mnodes on dnode 2 successfully in 10s") + tdLog.debug("stop mnodes on dnode 2 successfully in 10s") break elif tdSql.queryResult[1][2]=='follower': if tdSql.queryResult[2][2]=='leader': - print("stop mnodes on dnode 2 successfully in 10s") + tdLog.debug("stop mnodes on dnode 2 successfully in 10s") break count+=1 else: - print("stop mnodes on dnode 2 failed in 10s ") + tdLog.debug("stop mnodes on dnode 2 failed in 10s ") return -1 tdSql.error("drop mnode on dnode 1;") @@ -184,15 +184,15 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[1][2]=='offline': if tdSql.queryResult[2][2]=='follower': - print("stop mnodes on dnode 2 successfully in 10s") + tdLog.debug("stop mnodes on dnode 2 successfully in 10s") break count+=1 else: - print("stop mnodes on dnode 2 failed in 10s ") + tdLog.debug("stop mnodes on dnode 2 failed in 10s ") return -1 tdSql.error("drop mnode on dnode 2;") @@ -214,15 +214,15 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[2][2]=='offline': if tdSql.queryResult[1][2]=='follower': - print("stop mnodes on dnode 3 successfully in 10s") + tdLog.debug("stop mnodes on dnode 3 successfully in 10s") break count+=1 else: - print("stop mnodes on dnode 3 failed in 10s") + tdLog.debug("stop mnodes on dnode 3 failed in 10s") return -1 tdSql.error("drop mnode on dnode 3;") tdSql.query("show mnodes;") @@ -262,7 +262,7 @@ class TDTestCase: tdSql.error("create mnode on dnode 2") tdSql.query("show dnodes;") - print(tdSql.queryResult) + tdLog.debug(tdSql.queryResult) tdLog.debug("stop and follower of mnode") self.TDDnodes.stoptaosd(2) @@ -303,7 +303,7 @@ class TDTestCase: def run(self): - # print(self.master_dnode.cfgDict) + # tdLog.debug(self.master_dnode.cfgDict) self.buildcluster(5) self.five_dnode_three_mnode(5) diff --git a/tests/system-test/6-cluster/5dnode3mnodeStopInsert.py b/tests/system-test/6-cluster/5dnode3mnodeStopInsert.py index ce3f2c4093..a53930faac 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeStopInsert.py +++ b/tests/system-test/6-cluster/5dnode3mnodeStopInsert.py @@ -77,7 +77,7 @@ class TDTestCase: for couti in range(countstart,countstop): tdLog.debug("drop database if exists db%d" %couti) tdSql.execute("drop database if exists db%d" %couti) - print("create database if not exists db%d replica 1 duration 300" %couti) + tdLog.debug("create database if not exists db%d replica 1 duration 300" %couti) tdSql.execute("create database if not exists db%d replica 1 duration 300" %couti) tdSql.execute("use db%d" %couti) tdSql.execute( @@ -126,12 +126,12 @@ class TDTestCase: # create cluster for dnode in self.TDDnodes.dnodes[1:]: - # print(dnode.cfgDict) + # tdLog.debug(dnode.cfgDict) dnode_id = dnode.cfgDict["fqdn"] + ":" +dnode.cfgDict["serverPort"] dnode_first_host = dnode.cfgDict["firstEp"].split(":")[0] dnode_first_port = dnode.cfgDict["firstEp"].split(":")[-1] cmd = f" taos -h {dnode_first_host} -P {dnode_first_port} -s ' create dnode \"{dnode_id} \" ' ;" - print(cmd) + tdLog.debug(cmd) os.system(cmd) time.sleep(2) @@ -144,22 +144,22 @@ class TDTestCase: statusReadyBumber=0 tdSql.query("show dnodes;") if tdSql.checkRows(dnodenumber) : - print("dnode is %d nodes"%dnodenumber) + tdLog.debug("dnode is %d nodes"%dnodenumber) for i in range(dnodenumber): if tdSql.queryResult[i][4] !='ready' : status=tdSql.queryResult[i][4] - print("dnode:%d status is %s "%(i,status)) + tdLog.debug("dnode:%d status is %s "%(i,status)) break else: statusReadyBumber+=1 - print(statusReadyBumber) + tdLog.debug(statusReadyBumber) if statusReadyBumber == dnodenumber : - print("all of %d mnodes is ready in 10s "%dnodenumber) + tdLog.debug("all of %d mnodes is ready in 10s "%dnodenumber) return True break count+=1 else: - print("%d mnodes is not ready in 10s "%dnodenumber) + tdLog.debug("%d mnodes is not ready in 10s "%dnodenumber) return False @@ -169,25 +169,25 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[1][2]=='follower': if tdSql.queryResult[2][2]=='follower': - print("three mnodes is ready in 10s") + tdLog.debug("three mnodes is ready in 10s") break elif tdSql.queryResult[0][2]=='follower' : if tdSql.queryResult[1][2]=='leader': if tdSql.queryResult[2][2]=='follower': - print("three mnodes is ready in 10s") + tdLog.debug("three mnodes is ready in 10s") break elif tdSql.queryResult[0][2]=='follower' : if tdSql.queryResult[1][2]=='follower': if tdSql.queryResult[2][2]=='leader': - print("three mnodes is ready in 10s") + tdLog.debug("three mnodes is ready in 10s") break count+=1 else: - print("three mnodes is not ready in 10s ") + tdLog.debug("three mnodes is not ready in 10s ") return -1 tdSql.query("show mnodes;") @@ -205,19 +205,19 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='offline' : if tdSql.queryResult[1][2]=='leader': if tdSql.queryResult[2][2]=='follower': - print("stop mnodes on dnode 2 successfully in 10s") + tdLog.debug("stop mnodes on dnode 2 successfully in 10s") break elif tdSql.queryResult[1][2]=='follower': if tdSql.queryResult[2][2]=='leader': - print("stop mnodes on dnode 2 successfully in 10s") + tdLog.debug("stop mnodes on dnode 2 successfully in 10s") break count+=1 else: - print("stop mnodes on dnode 2 failed in 10s ") + tdLog.debug("stop mnodes on dnode 2 failed in 10s ") return -1 tdSql.error("drop mnode on dnode 1;") @@ -237,15 +237,15 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[1][2]=='offline': if tdSql.queryResult[2][2]=='follower': - print("stop mnodes on dnode 2 successfully in 10s") + tdLog.debug("stop mnodes on dnode 2 successfully in 10s") break count+=1 else: - print("stop mnodes on dnode 2 failed in 10s ") + tdLog.debug("stop mnodes on dnode 2 failed in 10s ") return -1 tdSql.error("drop mnode on dnode 2;") @@ -267,15 +267,15 @@ class TDTestCase: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - print("mnode is three nodes") + tdLog.debug("mnode is three nodes") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[2][2]=='offline': if tdSql.queryResult[1][2]=='follower': - print("stop mnodes on dnode 3 successfully in 10s") + tdLog.debug("stop mnodes on dnode 3 successfully in 10s") break count+=1 else: - print("stop mnodes on dnode 3 failed in 10s") + tdLog.debug("stop mnodes on dnode 3 failed in 10s") return -1 tdSql.error("drop mnode on dnode 3;") tdSql.query("show mnodes;") @@ -311,7 +311,7 @@ class TDTestCase: tdSql.error("create mnode on dnode 2") tdSql.query("show dnodes;") - print(tdSql.queryResult) + tdLog.debug(tdSql.queryResult) tdLog.debug("stop all of mnode ") stopcount =0 @@ -325,10 +325,10 @@ class TDTestCase: self.TDDnodes.starttaosd(i+1) if self.checkdnodes(5): - print("123") + tdLog.debug("123") threads.join() else: - print("456") + tdLog.debug("456") self.stop_thread(threads) assert 1 == 2 ,"some dnode started failed" return False @@ -345,7 +345,7 @@ class TDTestCase: def run(self): - # print(self.master_dnode.cfgDict) + # tdLog.debug(self.master_dnode.cfgDict) self.buildcluster(5) self.five_dnode_three_mnode(5) diff --git a/tests/system-test/7-tmq/subscribeDb3.py b/tests/system-test/7-tmq/subscribeDb3.py index 6973f4c51f..b576a0ea70 100644 --- a/tests/system-test/7-tmq/subscribeDb3.py +++ b/tests/system-test/7-tmq/subscribeDb3.py @@ -54,9 +54,11 @@ class TDTestCase: tdSql.query("create database if not exists %s vgroups 1"%(cdbName)) tdSql.query("drop table if exists %s.consumeinfo "%(cdbName)) tdSql.query("drop table if exists %s.consumeresult "%(cdbName)) + tdSql.query("drop table if exists %s.notifyinfo "%(cdbName)) tdSql.query("create table %s.consumeinfo (ts timestamp, consumerid int, topiclist binary(1024), keylist binary(1024), expectmsgcnt bigint, ifcheckdata int, ifmanualcommit int)"%cdbName) tdSql.query("create table %s.consumeresult (ts timestamp, consumerid int, consummsgcnt bigint, consumrowcnt bigint, checkresult int)"%cdbName) + tdSql.query("create table %s.notifyinfo (ts timestamp, cmdid int, consumerid int)"%cdbName) def insertConsumerInfo(self,consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifmanualcommit,cdbName='cdb'): sql = "insert into %s.consumeinfo values "%cdbName @@ -64,6 +66,27 @@ class TDTestCase: tdLog.info("consume info sql: %s"%sql) tdSql.query(sql) + def getStartConsumeNotifyFromTmqsim(self,cdbName='cdb'): + while 1: + tdSql.query("select * from %s.notifyinfo"%cdbName) + #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3)) + if (tdSql.getRows() == 1) and (tdSql.getData(0, 1) == 0): + break + else: + time.sleep(0.1) + return + + def getStartCommitNotifyFromTmqsim(self,cdbName='cdb'): + while 1: + tdSql.query("select * from %s.notifyinfo"%cdbName) + #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3)) + if tdSql.getRows() == 2 : + print(tdSql.getData(0, 1), tdSql.getData(1, 1)) + if tdSql.getData(1, 1) == 1: + break + time.sleep(0.1) + return + def selectConsumeResult(self,expectRows,cdbName='cdb'): resultList=[] while 1: @@ -72,7 +95,7 @@ class TDTestCase: if tdSql.getRows() == expectRows: break else: - time.sleep(5) + time.sleep(1) for i in range(expectRows): tdLog.info ("ts: %s, consume id: %d, consume msgs: %d, consume rows: %d"%(tdSql.getData(i , 0), tdSql.getData(i , 1), tdSql.getData(i , 2), tdSql.getData(i , 3))) @@ -207,7 +230,9 @@ class TDTestCase: showRow = 1 self.startTmqSimProcess(buildPath,cfgPath,pollDelay,parameterDict["dbName"],showMsg, showRow) - time.sleep(2) + tdLog.info("wait the notify info of start consume") + self.getStartConsumeNotifyFromTmqsim() + tdLog.info("pkill consume processor") if (platform.system().lower() == 'windows'): os.system("TASKKILL /F /IM tmq_sim.exe") @@ -282,14 +307,17 @@ class TDTestCase: showRow = 1 self.startTmqSimProcess(buildPath,cfgPath,pollDelay,parameterDict["dbName"],showMsg, showRow) - time.sleep(6) + # time.sleep(6) + tdLog.info("start to wait commit notify") + self.getStartCommitNotifyFromTmqsim() + tdLog.info("pkill consume processor") if (platform.system().lower() == 'windows'): os.system("TASKKILL /F /IM tmq_sim.exe") else: os.system('pkill tmq_sim') - expectRows = 0 - resultList = self.selectConsumeResult(expectRows) + # expectRows = 0 + # resultList = self.selectConsumeResult(expectRows) # wait for data ready prepareEnvThread.join() diff --git a/tests/system-test/7-tmq/subscribeDb4.py b/tests/system-test/7-tmq/subscribeDb4.py new file mode 100644 index 0000000000..de475803fe --- /dev/null +++ b/tests/system-test/7-tmq/subscribeDb4.py @@ -0,0 +1,116 @@ +import sys +import time +import socket +import os +import threading + +import taos +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + paraDict = {'dbName': 'db12', + 'dropFlag':1, + 'vgroups': 4, + 'precision': 'ms', + 'stbName': 'stb0', + 'ctbNum': 10, + 'rowsPerTbl': 10000, + 'batchNum': 10, + 'startTs': 0, # 1640966400000 ----> 2022-01-01 00:00:00.000 + 'event':'', + 'columnDict': {'int':2}, + 'tagDict': {'int':1} + } + + cdbName = 'cdb' + # some parameter to consumer processor + consumerId = 0 + expectrowcnt = 0 + topicList = '' + ifcheckdata = 0 + ifManualCommit = 1 + groupId = 'group.id:cgrp1' + autoCommit = 'enable.auto.commit:false' + autoCommitInterval = 'auto.commit.interval.ms:1000' + autoOffset = 'auto.offset.reset:earliest' + + pollDelay = 20 + showMsg = 1 + showRow = 1 + + hostname = socket.gethostname() + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + logSql = False + tdSql.init(conn.cursor(), logSql) + + def tmqCase12(self): + tdLog.printNoPrefix("======== test case 12: ") + tdLog.info("step 1: create database, stb, ctb and insert data") + + tmqCom.initConsumerTable(self.cdbName) + + tdCom.create_database(tdSql,self.paraDict["dbName"],self.paraDict["dropFlag"], self.paraDict['precision']) + + self.paraDict["stbName"] = 'stb1' + tdCom.create_stable(tdSql,self.paraDict["dbName"],self.paraDict["stbName"],self.paraDict["columnDict"],self.paraDict["tagDict"]) + tdCom.create_ctables(tdSql,self.paraDict["dbName"],self.paraDict["stbName"],self.paraDict["ctbNum"],self.paraDict["tagDict"]) + tdCom.insert_data(tdSql,self.paraDict["dbName"],self.paraDict["stbName"],self.paraDict["ctbNum"],self.paraDict["rowsPerTbl"],self.paraDict["batchNum"]) + + self.paraDict["stbName"] = 'stb2' + tdCom.create_stable(tdSql,self.paraDict["dbName"],self.paraDict["stbName"],self.paraDict["columnDict"],self.paraDict["tagDict"]) + tdCom.create_ctables(tdSql,self.paraDict["dbName"],self.paraDict["stbName"],self.paraDict["ctbNum"],self.paraDict["tagDict"]) + tdCom.insert_data(tdSql,self.paraDict["dbName"],self.paraDict["stbName"],self.paraDict["ctbNum"],self.paraDict["rowsPerTbl"],self.paraDict["batchNum"]) + + tdLog.info("create topics from db") + topicName1 = 'topic_%s'%(self.paraDict['dbName']) + tdSql.execute("create topic %s as database %s" %(topicName1, self.paraDict['dbName'])) + + topicList = topicName1 + keyList = '%s,%s,%s,%s'%(self.groupId,self.autoCommit,self.autoCommitInterval,self.autoOffset) + self.expectrowcnt = self.paraDict["rowsPerTbl"] * self.paraDict["ctbNum"] * 2 + tmqCom.insertConsumerInfo(self.consumerId, self.expectrowcnt,topicList,keyList,self.ifcheckdata,self.ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(self.pollDelay,self.paraDict["dbName"],self.showMsg, self.showRow,self.cdbName) + + tdLog.info("After waiting for a period of time, drop one stable") + time.sleep(10) + tdSql.execute("drop table %s.%s" %(self.paraDict['dbName'], self.paraDict['stbName'])) + + tdLog.info("wait result from consumer, then check it") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + if not (totalConsumeRows >= self.expectrowcnt/2 and totalConsumeRows <= self.expectrowcnt): + tdLog.info("act consume rows: %d, expect consume rows: between %d and %d"%(totalConsumeRows, self.expectrowcnt/2, self.expectrowcnt)) + tdLog.exit("tmq consume rows error!") + + time.sleep(15) + tdSql.query("drop topic %s"%topicName1) + + tdLog.printNoPrefix("======== test case 12 end ...... ") + + def run(self): + tdSql.prepare() + self.tmqCase12() + + 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/7-tmq/subscribeStb4.py b/tests/system-test/7-tmq/subscribeStb4.py index d8a9ca95b0..f3982c8f1f 100644 --- a/tests/system-test/7-tmq/subscribeStb4.py +++ b/tests/system-test/7-tmq/subscribeStb4.py @@ -196,16 +196,16 @@ class TDTestCase: auotCtbPrefix = 'autoCtb' # create and start thread - parameterDict = {'cfg': '', \ - 'actionType': 0, \ - 'dbName': 'db1', \ - 'dropFlag': 1, \ - 'vgroups': 4, \ - 'replica': 1, \ - 'stbName': 'stb1', \ - 'ctbNum': 10, \ - 'rowsPerTbl': 10000, \ - 'batchNum': 100, \ + parameterDict = {'cfg': '', + 'actionType': 0, + 'dbName': 'db1', + 'dropFlag': 1, + 'vgroups': 4, + 'replica': 1, + 'stbName': 'stb1', + 'ctbNum': 10, + 'rowsPerTbl': 10000, + 'batchNum': 100, 'startTs': 1640966400000} # 2022-01-01 00:00:00.000 parameterDict['cfg'] = cfgPath @@ -349,7 +349,5 @@ class TDTestCase: 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/7-tmq/tmqCommon.py b/tests/system-test/7-tmq/tmqCommon.py new file mode 100644 index 0000000000..68adaa4126 --- /dev/null +++ b/tests/system-test/7-tmq/tmqCommon.py @@ -0,0 +1,118 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +from collections import defaultdict +import random +import string +import threading +import requests +import time +# import socketfrom + +import taos +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * + +# class actionType(Enum): +# CREATE_DATABASE = 0 +# CREATE_STABLE = 1 +# CREATE_CTABLE = 2 +# INSERT_DATA = 3 + +class TMQCom: + def init(self, conn, logSql): + tdSql.init(conn.cursor()) + # tdSql.init(conn.cursor(), logSql) # output sql.txt file + + def initConsumerTable(self,cdbName='cdb'): + tdLog.info("create consume database, and consume info table, and consume result table") + tdSql.query("create database if not exists %s vgroups 1"%(cdbName)) + tdSql.query("drop table if exists %s.consumeinfo "%(cdbName)) + tdSql.query("drop table if exists %s.consumeresult "%(cdbName)) + + tdSql.query("create table %s.consumeinfo (ts timestamp, consumerid int, topiclist binary(1024), keylist binary(1024), expectmsgcnt bigint, ifcheckdata int, ifmanualcommit int)"%cdbName) + tdSql.query("create table %s.consumeresult (ts timestamp, consumerid int, consummsgcnt bigint, consumrowcnt bigint, checkresult int)"%cdbName) + + def initConsumerInfoTable(self,cdbName='cdb'): + tdLog.info("drop consumeinfo table") + tdSql.query("drop table if exists %s.consumeinfo "%(cdbName)) + tdSql.query("create table %s.consumeinfo (ts timestamp, consumerid int, topiclist binary(1024), keylist binary(1024), expectmsgcnt bigint, ifcheckdata int, ifmanualcommit int)"%cdbName) + + def insertConsumerInfo(self,consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifmanualcommit,cdbName='cdb'): + sql = "insert into %s.consumeinfo values "%cdbName + sql += "(now, %d, '%s', '%s', %d, %d, %d)"%(consumerId, topicList, keyList, expectrowcnt, ifcheckdata, ifmanualcommit) + tdLog.info("consume info sql: %s"%sql) + tdSql.query(sql) + + def selectConsumeResult(self,expectRows,cdbName='cdb'): + resultList=[] + while 1: + tdSql.query("select * from %s.consumeresult"%cdbName) + #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3)) + if tdSql.getRows() == expectRows: + break + else: + time.sleep(5) + + for i in range(expectRows): + tdLog.info ("consume id: %d, consume msgs: %d, consume rows: %d"%(tdSql.getData(i , 1), tdSql.getData(i , 2), tdSql.getData(i , 3))) + resultList.append(tdSql.getData(i , 3)) + + return resultList + + def startTmqSimProcess(self,pollDelay,dbName,showMsg=1,showRow=1,cdbName='cdb',valgrind=0): + buildPath = tdCom.getBuildPath() + cfgPath = tdCom.getClientCfgPath() + if valgrind == 1: + logFile = cfgPath + '/../log/valgrind-tmq.log' + shellCmd = 'nohup valgrind --log-file=' + logFile + shellCmd += '--tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all --num-callers=20 -v --workaround-gcc296-bugs=yes ' + + if (platform.system().lower() == 'windows'): + shellCmd = 'mintty -h never -w hide ' + buildPath + '\\build\\bin\\tmq_sim.exe -c ' + cfgPath + shellCmd += " -y %d -d %s -g %d -r %d -w %s "%(pollDelay, dbName, showMsg, showRow, cdbName) + shellCmd += "> nul 2>&1 &" + else: + shellCmd = 'nohup ' + buildPath + '/build/bin/tmq_sim -c ' + cfgPath + shellCmd += " -y %d -d %s -g %d -r %d -w %s "%(pollDelay, dbName, showMsg, showRow, cdbName) + shellCmd += "> /dev/null 2>&1 &" + tdLog.info(shellCmd) + os.system(shellCmd) + + def syncCreateDbStbCtbInsertData(self, tsql, paraDict): + tdCom.create_database(tsql, paraDict["dbName"],paraDict["dropFlag"], paraDict['precision']) + tdCom.create_stable(tsql, paraDict["dbName"],paraDict["stbName"], paraDict["columnDict"], paraDict["tagDict"]) + tdCom.create_ctables(tsql, paraDict["dbName"],paraDict["stbName"],paraDict["ctbNum"],paraDict["tagDict"]) + if "event" in paraDict and type(paraDict['event']) == type(threading.Event()): + paraDict["event"].set() + tdCom.insert_data(tsql,paraDict["dbName"],paraDict["stbName"],paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"]) + return + + def threadFunction(self, **paraDict): + # create new connector for new tdSql instance in my thread + newTdSql = tdCom.newTdSql() + self.syncCreateDbStbCtbInsertData(self, newTdSql, paraDict) + return + + def asyncCreateDbStbCtbInsertData(self, paraDict): + pThread = threading.Thread(target=self.threadFunction, kwargs=paraDict) + pThread.start() + return pThread + + def close(self): + self.cursor.close() + +tmqCom = TMQCom() diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index b5004d41ce..ee946caf53 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -22,7 +22,7 @@ python3 ./test.py -f 1-insert/opentsdb_json_taosc_insert.py python3 ./test.py -f 1-insert/alter_stable.py python3 ./test.py -f 1-insert/alter_table.py python3 ./test.py -f 1-insert/insertWithMoreVgroup.py -# python3 ./test.py -f 1-inerst/create_table_comment.py +python3 ./test.py -f 1-insert/table_comment.py python3 ./test.py -f 2-query/between.py python3 ./test.py -f 2-query/distinct.py python3 ./test.py -f 2-query/varchar.py @@ -35,6 +35,7 @@ python3 ./test.py -f 2-query/lower.py python3 ./test.py -f 2-query/join.py python3 ./test.py -f 2-query/join2.py python3 ./test.py -f 2-query/cast.py +python3 ./test.py -f 2-query/substr.py python3 ./test.py -f 2-query/union.py python3 ./test.py -f 2-query/union1.py python3 ./test.py -f 2-query/concat.py @@ -98,18 +99,21 @@ python3 ./test.py -f 2-query/stateduration.py python3 ./test.py -f 2-query/function_stateduration.py python3 ./test.py -f 2-query/statecount.py python3 ./test.py -f 2-query/tail.py +python3 ./test.py -f 2-query/ttl_comment.py python3 ./test.py -f 2-query/distribute_agg_count.py python3 ./test.py -f 2-query/distribute_agg_max.py python3 ./test.py -f 2-query/distribute_agg_min.py python3 ./test.py -f 2-query/distribute_agg_sum.py python3 ./test.py -f 2-query/distribute_agg_spread.py python3 ./test.py -f 2-query/distribute_agg_apercentile.py +python3 ./test.py -f 2-query/distribute_agg_avg.py +python3 ./test.py -f 2-query/distribute_agg_stddev.py -python3 ./test.py -f 6-cluster/5dnode1mnode.py -python3 ./test.py -f 6-cluster/5dnode2mnode.py +python3 ./test.py -f 6-cluster/5dnode1mnode.py +python3 ./test.py -f 6-cluster/5dnode2mnode.py #python3 ./test.py -f 6-cluster/5dnode3mnodeStop.py #python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -# BUG python3 ./test.py -f 6-cluster/5dnode3mnodeStopInsert.py +# BUG python3 ./test.py -f 6-cluster/5dnode3mnodeStopInsert.py python3 ./test.py -f 7-tmq/basic5.py python3 ./test.py -f 7-tmq/subscribeDb.py diff --git a/tests/test/c/sdbDump.c b/tests/test/c/sdbDump.c index 612b870b7e..a62c30660d 100644 --- a/tests/test/c/sdbDump.c +++ b/tests/test/c/sdbDump.c @@ -114,8 +114,10 @@ void dumpStb(SSdb *pSdb, SJson *json) { tjsonAddIntegerToObject(item, "tagVer", pObj->tagVer); tjsonAddIntegerToObject(item, "colVer", pObj->colVer); tjsonAddIntegerToObject(item, "nextColId", pObj->nextColId); - tjsonAddIntegerToObject(item, "xFilesFactor", pObj->xFilesFactor * 10000); - tjsonAddIntegerToObject(item, "delay", pObj->delay); + tjsonAddIntegerToObject(item, "watermark1", pObj->watermark[0]); + tjsonAddIntegerToObject(item, "watermark2", pObj->watermark[1]); + tjsonAddIntegerToObject(item, "maxdelay1", pObj->maxdelay[0]); + tjsonAddIntegerToObject(item, "maxdelay2", pObj->maxdelay[1]); tjsonAddIntegerToObject(item, "ttl", pObj->ttl); tjsonAddIntegerToObject(item, "numOfColumns", pObj->numOfColumns); tjsonAddIntegerToObject(item, "numOfTags", pObj->numOfTags); diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index 0f78a003d6..948df3a40a 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -34,6 +34,12 @@ #define MAX_CONSUMER_THREAD_CNT (16) #define MAX_VGROUP_CNT (32) +typedef enum { + NOTIFY_CMD_START_CONSUM, + NOTIFY_CMD_START_COMMIT, + NOTIFY_CMD_ID_BUTT +}NOTIFY_CMD_ID; + typedef struct { TdThread thread; int32_t consumerId; @@ -67,6 +73,8 @@ typedef struct { int32_t rowsOfPerVgroups[MAX_VGROUP_CNT][2]; // [i][0]: vgroup id, [i][1]: rows of consume int64_t ts; + TAOS* taos; + } SThreadInfo; typedef struct { @@ -339,8 +347,37 @@ int queryDB(TAOS* taos, char* command) { return 0; } +static void appNothing(void* param, TAOS_RES* res, int32_t numOfRows) { +} + +int32_t notifyMainScript(SThreadInfo* pInfo, int32_t cmdId) { + char sqlStr[1024] = {0}; + + int64_t now = taosGetTimestampMs(); + + // schema: ts timestamp, consumerid int, consummsgcnt bigint, checkresult int + sprintf(sqlStr, "insert into %s.notifyinfo values (%"PRId64", %d, %d)", + g_stConfInfo.cdbName, + now, + cmdId, + pInfo->consumerId); + + taos_query_a(pInfo->taos, sqlStr, appNothing, NULL); + + taosFprintfFile(g_fp, "notifyMainScript success, sql: %s\n", sqlStr); + + return 0; +} + +static int32_t g_once_commit_flag = 0; static void tmq_commit_cb_print(tmq_t* tmq, int32_t code, void* param) { - pError("tmq_commit_cb_print() commit %d\n", code); + pError("tmq_commit_cb_print() commit %d\n", code); + + if (0 == g_once_commit_flag) { + g_once_commit_flag = 1; + notifyMainScript((SThreadInfo*)param, (int32_t)NOTIFY_CMD_START_COMMIT); + } + taosFprintfFile(g_fp, "tmq_commit_cb_print() be called\n"); } void build_consumer(SThreadInfo* pInfo) { @@ -353,7 +390,7 @@ void build_consumer(SThreadInfo* pInfo) { // tmq_conf_set(conf, "td.connect.db", g_stConfInfo.dbName); - tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL); + tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, pInfo); // tmq_conf_set(conf, "group.id", "cgrp1"); for (int32_t i = 0; i < pInfo->numOfKey; i++) { @@ -392,9 +429,6 @@ void build_topic_list(SThreadInfo* pInfo) { int32_t saveConsumeResult(SThreadInfo* pInfo) { char sqlStr[1024] = {0}; - TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); - assert(pConn != NULL); - int64_t now = taosGetTimestampMs(); // schema: ts timestamp, consumerid int, consummsgcnt bigint, checkresult int @@ -404,7 +438,7 @@ int32_t saveConsumeResult(SThreadInfo* pInfo) { char tmpString[128]; taosFprintfFile(g_fp, "%s, consume id %d result: %s\n", getCurrentTimeString(tmpString), pInfo->consumerId, sqlStr); - TAOS_RES* pRes = taos_query(pConn, sqlStr); + TAOS_RES* pRes = taos_query(pInfo->taos, sqlStr); if (taos_errno(pRes) != 0) { pError("error in save consumeinfo, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); @@ -413,38 +447,14 @@ int32_t saveConsumeResult(SThreadInfo* pInfo) { taos_free_result(pRes); -#if 0 - // vgroups - for (i = 0; i < pInfo->numOfVgroups; i++) { - // schema: ts timestamp, consumerid int, consummsgcnt bigint, checkresult int - sprintf(sqlStr, "insert into %s.vgroup_%d values (%"PRId64", %d, %" PRId64 ", %" PRId64 ", %d)", - g_stConfInfo.cdbName, - now, - pInfo->consumerId, - pInfo->consumeMsgCnt, - pInfo->consumeRowCnt, - pInfo->checkresult); - - char tmpString[128]; - taosFprintfFile(g_fp, "%s, consume id %d result: %s\n", getCurrentTimeString(tmpString), pInfo->consumerId ,sqlStr); - - TAOS_RES* pRes = taos_query(pConn, sqlStr); - if (taos_errno(pRes) != 0) { - pError("error in save consumeinfo, reason:%s\n", taos_errstr(pRes)); - taos_free_result(pRes); - exit(-1); - } - - taos_free_result(pRes); - } -#endif - return 0; } void loop_consume(SThreadInfo* pInfo) { int32_t code; + int32_t once_flag = 0; + int64_t totalMsgs = 0; int64_t totalRows = 0; @@ -465,6 +475,11 @@ void loop_consume(SThreadInfo* pInfo) { totalMsgs++; + if (0 == once_flag) { + once_flag = 1; + notifyMainScript(pInfo, NOTIFY_CMD_START_CONSUM); + } + if (totalRows >= pInfo->expectMsgCnt) { char tmpString[128]; taosFprintfFile(g_fp, "%s over than expect rows, so break consume\n", getCurrentTimeString(tmpString)); @@ -489,6 +504,12 @@ void* consumeThreadFunc(void* param) { SThreadInfo* pInfo = (SThreadInfo*)param; + pInfo->taos = taos_connect(NULL, "root", "taosdata", NULL, 0); + if (pInfo->taos == NULL) { + taosFprintfFile(g_fp, "taos_connect() fail, can not notify and save consume result to main scripte\n"); + exit(-1); + } + build_consumer(pInfo); build_topic_list(pInfo); if ((NULL == pInfo->tmq) || (NULL == pInfo->topicList)) { @@ -508,7 +529,6 @@ void* consumeThreadFunc(void* param) { loop_consume(pInfo); if (pInfo->ifManualCommit) { - taosFprintfFile(g_fp, "tmq_commit() manual commit when consume end.\n"); pPrint("tmq_commit() manual commit when consume end.\n"); /*tmq_commit(pInfo->tmq, NULL, 0);*/ tmq_commit_sync(pInfo->tmq, NULL); @@ -539,6 +559,9 @@ void* consumeThreadFunc(void* param) { taosFprintfFile(g_fp, "vgroups: %04d, rows: %d\n", pInfo->rowsOfPerVgroups[i][0], pInfo->rowsOfPerVgroups[i][1]); } + taos_close(pInfo->taos); + pInfo->taos = NULL; + return NULL; } diff --git a/tools/taosadapter b/tools/taosadapter index 29926478ed..c1dc11f3ca 160000 --- a/tools/taosadapter +++ b/tools/taosadapter @@ -1 +1 @@ -Subproject commit 29926478edd87533a043f91c1a9ed0e27671e626 +Subproject commit c1dc11f3cae64adf31dbd9a954ef8372d1e8f671