diff --git a/README-CN.md b/README-CN.md index 627b35698c21cf234b011c17c85c7faee53671b3..437d671bb97a1009f5d48d2423a3d17f75bf1494 100644 --- a/README-CN.md +++ b/README-CN.md @@ -107,7 +107,7 @@ sudo yum config-manager --set-enabled Powertools ### macOS ``` -sudo brew install argp-standalone pkgconfig +brew install argp-standalone pkgconfig ``` ### 设置 golang 开发环境 @@ -276,7 +276,7 @@ sudo make install 安装成功后,可以在应用程序中双击 TDengine 图标启动服务,或者在终端中启动 TDengine 服务: ```bash -launchctl start taosd +launchctl start com.tdengine.taosd ``` 用户可以使用 TDengine CLI 来连接 TDengine 服务,在终端中,输入: diff --git a/README.md b/README.md index 00d36efb5a630a44eeeaa9b3b47df5c649a0a305..8d2567a816f9048cd689afa06426e9c88979a354 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ sudo yum config-manager --set-enabled powertools ### macOS ``` -sudo brew install argp-standalone pkgconfig +brew install argp-standalone pkgconfig ``` ### Setup golang environment @@ -280,7 +280,7 @@ Installing from source code will also configure service management for TDengine. To start the service after installation, double-click the /applications/TDengine to start the program, or in a terminal, use: ```bash -launchctl start taosd +launchctl start com.tdengine.taosd ``` Then users can use the TDengine CLI to connect the TDengine server. In a terminal, use: diff --git a/cmake/cmake.platform b/cmake/cmake.platform index e4d440d76edbfcf0d1d6f932cfa598fe0a0f43d2..3e239d2e0c9f1fb53a4c156cab52801f6206df75 100644 --- a/cmake/cmake.platform +++ b/cmake/cmake.platform @@ -45,10 +45,19 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin ADD_DEFINITIONS("-DDARWIN -Wno-tautological-pointer-compare") MESSAGE("Current system processor is ${CMAKE_SYSTEM_PROCESSOR}.") - IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") - MESSAGE("Current system arch is 64") + IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64") + MESSAGE("Current system arch is arm64") SET(TD_DARWIN_64 TRUE) + SET(TD_DARWIN_ARM64 TRUE) ADD_DEFINITIONS("-D_TD_DARWIN_64") + ADD_DEFINITIONS("-D_TD_DARWIN_ARM64") + ENDIF () + IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") + MESSAGE("Current system arch is x86_64") + SET(TD_DARWIN_64 TRUE) + SET(TD_DARWIN_X64 TRUE) + ADD_DEFINITIONS("-D_TD_DARWIN_64") + ADD_DEFINITIONS("-D_TD_DARWIN_X64") ENDIF () ADD_DEFINITIONS("-DHAVE_UNISTD_H") diff --git a/cmake/taostools_CMakeLists.txt.in b/cmake/taostools_CMakeLists.txt.in index 7bde332c8c0f068017aa15e5a1172716b78698bb..f0a1ad83adfdadc5f2385f7d1d83ec751dae58ae 100644 --- a/cmake/taostools_CMakeLists.txt.in +++ b/cmake/taostools_CMakeLists.txt.in @@ -2,7 +2,7 @@ # taos-tools ExternalProject_Add(taos-tools GIT_REPOSITORY https://github.com/taosdata/taos-tools.git - GIT_TAG d58230c + GIT_TAG 2849aa4 SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools" BINARY_DIR "" #BUILD_IN_SOURCE TRUE diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index a1a6cd4519294fa99a5bee41ae21aad4c1731373..969724cc8d0ebd68f3a3cbdf5716bdcb4efb5ff9 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -270,7 +270,7 @@ if(${JEMALLOC_ENABLED}) PREFIX "jemalloc" SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/jemalloc BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND ./autogen.sh COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/build/ --disable-initial-exec-tls + CONFIGURE_COMMAND ./autogen.sh COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/build/ --disable-initial-exec-tls --with-malloc-conf='background_thread:true,metadata_thp:auto' BUILD_COMMAND ${MAKE} ) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/build/include) diff --git a/docs/en/05-get-started/03-package.md b/docs/en/05-get-started/03-package.md index f734e354fb16c8ca7342f04fc46f869009bbd8c8..7800fb1c88a59c28945a196e1e5dac95427bf1f6 100644 --- a/docs/en/05-get-started/03-package.md +++ b/docs/en/05-get-started/03-package.md @@ -189,13 +189,13 @@ After the installation is complete, run `C:\TDengine\taosd.exe` to start TDengin -After the installation is complete, double-click the /applications/TDengine to start the program, or run `launchctl start taosd` to start TDengine Server. +After the installation is complete, double-click the /applications/TDengine to start the program, or run `launchctl start com.tdengine.taosd` to start TDengine Server. The following `launchctl` commands can help you manage TDengine service: -- Start TDengine Server: `launchctl start taosd` +- Start TDengine Server: `launchctl start com.tdengine.taosd` -- Stop TDengine Server: `launchctl stop taosd` +- Stop TDengine Server: `launchctl stop com.tdengine.taosd` - Check TDengine Server status: `launchctl list | grep taosd` diff --git a/docs/en/12-taos-sql/28-recovery.md b/docs/en/12-taos-sql/28-recovery.md index 14ac14f8673fba05fee09317de927df00effed0f..e869ffc45ff7420836d91a2536d32ce6b08a0d82 100644 --- a/docs/en/12-taos-sql/28-recovery.md +++ b/docs/en/12-taos-sql/28-recovery.md @@ -16,10 +16,10 @@ You can use the SHOW CONNECTIONS statement to find the conn_id. ## Terminate a Query ```sql -SHOW QUERY query_id; +KILL QUERY kill_id; ``` -You can use the SHOW QUERIES statement to find the query_id. +You can use the SHOW QUERIES statement to find the kill_id. ## Terminate a Transaction diff --git a/docs/en/14-reference/05-taosbenchmark.md b/docs/en/14-reference/05-taosbenchmark.md index d95086d4c498bf61564eb953ea54da93a8bac404..6295d8553d54033ee08413696d45503416394f27 100644 --- a/docs/en/14-reference/05-taosbenchmark.md +++ b/docs/en/14-reference/05-taosbenchmark.md @@ -231,7 +231,7 @@ The parameters related to database creation are configured in `dbinfo` in the js - **name**: specify the name of the database. -- **drop**: indicate whether to delete the database before inserting. The default is true. +- **drop**: indicate whether to delete the database before inserting. The value can be 'yes' or 'no'. No means do not drop. The default is to drop. #### Stream processing related configuration parameters diff --git a/docs/en/14-reference/12-config/index.md b/docs/en/14-reference/12-config/index.md index d91675a0ab7209bdae9b4aa5a80e984c7605f2f9..8053c4d25d527adf3e2c22fd107c7c28114e2eb6 100644 --- a/docs/en/14-reference/12-config/index.md +++ b/docs/en/14-reference/12-config/index.md @@ -675,7 +675,7 @@ To prevent system resource from being exhausted by multiple concurrent streams, | Meaning | Whether to generate core file when server crashes | | Value Range | 0: false, 1: true | | Default Value | 1 | -| Note | The core file is generated under root directory `systemctl/launchctl start taosd` is used to start, or under the working directory if `taosd` is started directly on Linux/macOS Shell. | +| Note | The core file is generated under root directory `systemctl start taosd`/`launchctl start com.tdengine.taosd` is used to start, or under the working directory if `taosd` is started directly on Linux/macOS Shell. | ### udf diff --git a/docs/en/21-tdinternal/01-arch.md b/docs/en/21-tdinternal/01-arch.md index 6622ee525af1e696f21dcbef424269dd3c29e1a4..a938084eb1ee76e85c076b13335e0ce813bf7a7c 100644 --- a/docs/en/21-tdinternal/01-arch.md +++ b/docs/en/21-tdinternal/01-arch.md @@ -181,7 +181,7 @@ To make full use of the characteristics of time-series data, TDengine splits the For time-series data, there is generally a retention policy, which is determined by the system configuration parameter `keep`. Data files exceeding this set number of days will be automatically deleted by the system to free up storage space. -Given `duration` and `keep` parameters, the total number of data files in a vnode is: keep/duration. The total number of data files should not be too large or too small. 10 to 100 is appropriate. Based on this principle, reasonable `duration` can be set. In the current version, parameter `keep` can be modified, but parameter `duration` cannot be modified once it is set. +Given `duration` and `keep` parameters, the total number of data files in a vnode is: round up of (keep/duration+1). The total number of data files should not be too large or too small. 10 to 100 is appropriate. Based on this principle, reasonable `duration` can be set. In the current version, parameter `keep` can be modified, but parameter `duration` cannot be modified once it is set. In each data file, the data of a table is stored in blocks. A table can have one or more data file blocks. In a file block, data is stored in columns, occupying a continuous storage space, thus greatly improving the reading speed. The size of file block is determined by the system parameter `maxRows` (the maximum number of records per block), and the default value is 4096. This value should not be too large or too small. If it is too large, data location for queries will take a longer time. If it is too small, the index of data block is too large, and the compression efficiency will be low with slower reading speed. diff --git a/docs/examples/python/tmq_example.py b/docs/examples/python/tmq_example.py index cee036454ec4d3f4809576a1eee8ac054fcba056..836beb2417c310337d73e678f97810e447824b63 100644 --- a/docs/examples/python/tmq_example.py +++ b/docs/examples/python/tmq_example.py @@ -1,6 +1,58 @@ import taos -from taos.tmq import TaosConsumer -consumer = TaosConsumer('topic_ctb_column', group_id='vg2') -for msg in consumer: - for row in msg: - print(row) +from taos.tmq import * + +conn = taos.connect() + +print("init") +conn.execute("drop database if exists py_tmq") +conn.execute("create database if not exists py_tmq vgroups 2") +conn.select_db("py_tmq") +conn.execute( + "create stable if not exists stb1 (ts timestamp, c1 int, c2 float, c3 binary(10)) tags(t1 int)" +) +conn.execute("create table if not exists tb1 using stb1 tags(1)") +conn.execute("create table if not exists tb2 using stb1 tags(2)") +conn.execute("create table if not exists tb3 using stb1 tags(3)") + +print("create topic") +conn.execute("drop topic if exists topic_ctb_column") +conn.execute( + "create topic if not exists topic_ctb_column as select ts, c1, c2, c3 from stb1" +) + +print("build consumer") +conf = TaosTmqConf() +conf.set("group.id", "tg2") +conf.set("td.connect.user", "root") +conf.set("td.connect.pass", "taosdata") +conf.set("enable.auto.commit", "true") + + +def tmq_commit_cb_print(tmq, resp, offset, param=None): + print(f"commit: {resp}, tmq: {tmq}, offset: {offset}, param: {param}") + + +conf.set_auto_commit_cb(tmq_commit_cb_print, None) +tmq = conf.new_consumer() + +print("build topic list") + +topic_list = TaosTmqList() +topic_list.append("topic_ctb_column") + +print("basic consume loop") +tmq.subscribe(topic_list) + +sub_list = tmq.subscription() + +print("subscribed topics: ", sub_list) + +while 1: + res = tmq.poll(1000) + if res: + topic = res.get_topic_name() + vg = res.get_vgroup_id() + db = res.get_db_name() + print(f"topic: {topic}\nvgroup id: {vg}\ndb: {db}") + for row in res: + print(row) diff --git a/docs/zh/05-get-started/03-package.md b/docs/zh/05-get-started/03-package.md index 50ee721386a591bbafece210cd963e50eef3ea7e..167a68d3c84a7da25f8ae0bfa9592fbd933299e0 100644 --- a/docs/zh/05-get-started/03-package.md +++ b/docs/zh/05-get-started/03-package.md @@ -188,13 +188,13 @@ Active: inactive (dead) -安装后,在应用程序目录下,双击 TDengine 图标来启动程序,也可以运行 `launchctl start taosd` 来启动 TDengine 服务进程。 +安装后,在应用程序目录下,双击 TDengine 图标来启动程序,也可以运行 `launchctl start com.tdengine.taosd` 来启动 TDengine 服务进程。 如下 `launchctl` 命令可以帮助你管理 TDengine 服务: -- 启动服务进程:`launchctl start taosd` +- 启动服务进程:`launchctl start com.tdengine.taosd` -- 停止服务进程:`launchctl stop taosd` +- 停止服务进程:`launchctl stop com.tdengine.taosd` - 查看服务状态:`launchctl list | grep taosd` diff --git a/docs/zh/12-taos-sql/10-function.md b/docs/zh/12-taos-sql/10-function.md index 4c33b5232ac7d7511d1ff4bd121c389ce84d9a41..9346c3f76393cb4c6a36b129078c1c65e6869c28 100644 --- a/docs/zh/12-taos-sql/10-function.md +++ b/docs/zh/12-taos-sql/10-function.md @@ -340,7 +340,7 @@ LTRIM(expr) #### RTRIM ```sql -LTRIM(expr) +RTRIM(expr) ``` **功能说明**:返回清除右边空格后的字符串。 diff --git a/docs/zh/12-taos-sql/28-recovery.md b/docs/zh/12-taos-sql/28-recovery.md index 582c3739073513df4ceb212080805136947e62d4..b5088e7982620e43aaead01ad6493d1ef5ed72ab 100644 --- a/docs/zh/12-taos-sql/28-recovery.md +++ b/docs/zh/12-taos-sql/28-recovery.md @@ -17,10 +17,10 @@ conn_id 可以通过 `SHOW CONNECTIONS` 获取。 ## 终止查询 ```sql -SHOW QUERY query_id; +KILL QUERY kill_id; ``` -query_id 可以通过 `SHOW QUERIES` 获取。 +kill_id 可以通过 `SHOW QUERIES` 获取。 ## 终止事务 diff --git a/docs/zh/12-taos-sql/29-changes.md b/docs/zh/12-taos-sql/29-changes.md index 7da8e9f331bd1d9c81e9bde441e35b03900422b0..1ab7f4f0169932576edf9087a825367573713b03 100644 --- a/docs/zh/12-taos-sql/29-changes.md +++ b/docs/zh/12-taos-sql/29-changes.md @@ -94,3 +94,10 @@ description: "TDengine 3.0 版本的语法变更说明" | 9 | SAMPLE | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。 | 10 | STATECOUNT | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。 | 11 | STATEDURATION | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。 + + +## SCHEMALESS 变更 + +| # | **元素** | **
差异性
** | **说明** | +| - | :------- | :-------- | :------- | +| 1 | 主键ts 变更为 _ts | 变更 | schemaless自动建的列名用 _ 开头,不同于2.x。 diff --git a/docs/zh/14-reference/05-taosbenchmark.md b/docs/zh/14-reference/05-taosbenchmark.md index 9f4f728f78438bab299360717ba467a7fcea47ca..e067c646b23db8080251ab7b51e693337436cfcc 100644 --- a/docs/zh/14-reference/05-taosbenchmark.md +++ b/docs/zh/14-reference/05-taosbenchmark.md @@ -231,7 +231,7 @@ taosBenchmark -A INT,DOUBLE,NCHAR,BINARY\(16\) - **name** : 数据库名。 -- **drop** : 插入前是否删除数据库,默认为 true。 +- **drop** : 插入前是否删除数据库,可选项为 "yes" 或者 "no", 为 "no" 时不创建。默认删除。 #### 流式计算相关配置参数 diff --git a/docs/zh/14-reference/13-schemaless/13-schemaless.md b/docs/zh/14-reference/13-schemaless/13-schemaless.md index 07d5b0692bc9ac53d8c46cc0542c9512c2aa536e..b89f625376404677af21f0d48b77c3df5ebd748a 100644 --- a/docs/zh/14-reference/13-schemaless/13-schemaless.md +++ b/docs/zh/14-reference/13-schemaless/13-schemaless.md @@ -115,7 +115,7 @@ st,t1=3,t2=4,t3=t3 c1=3i64,c3="passit",c2=false,c4=4f64 1626006833639000000 ## 数据模式映射规则 -本节将说明行协议的数据如何映射成为具有模式的数据。每个行协议中数据 measurement 映射为 +本节将说明 InfluxDB 行协议(Line Protocol)的数据如何映射成为具有模式的数据。每个行协议中数据 measurement 映射为 超级表名称。tag_set 中的 标签名称为 数据模式中的标签名,field_set 中的名称为列名称。以如下数据为例,说明映射规则: ```json diff --git a/examples/c/demoapi.c b/examples/c/demoapi.c index c3a6d267766dcb5621c126fb1dc3d411f9f3929a..18f1b5a0592a27b1f40c5c7f7c64e6e7341d1a6e 100644 --- a/examples/c/demoapi.c +++ b/examples/c/demoapi.c @@ -1,5 +1,17 @@ -// C api call sequence demo -// to compile: gcc -o apidemo apidemo.c -ltaos +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ #include #include @@ -13,23 +25,23 @@ #include "taos.h" #define debugPrint(fmt, ...) \ - do { if (g_args.debug_print || g_args.verbose_print) \ - fprintf(stdout, "DEBG: "fmt, __VA_ARGS__); } while(0) + do { if (g_args.debug_print || g_args.verbose_print) {\ + fprintf(stdout, "DEBG: "fmt, __VA_ARGS__); }} while (0) #define warnPrint(fmt, ...) \ do { fprintf(stderr, "\033[33m"); \ fprintf(stderr, "WARN: "fmt, __VA_ARGS__); \ - fprintf(stderr, "\033[0m"); } while(0) + fprintf(stderr, "\033[0m"); } while (0) #define errorPrint(fmt, ...) \ do { fprintf(stderr, "\033[31m"); \ fprintf(stderr, "ERROR: "fmt, __VA_ARGS__); \ - fprintf(stderr, "\033[0m"); } while(0) + fprintf(stderr, "\033[0m"); } while (0) #define okPrint(fmt, ...) \ do { fprintf(stderr, "\033[32m"); \ fprintf(stderr, "OK: "fmt, __VA_ARGS__); \ - fprintf(stderr, "\033[0m"); } while(0) + fprintf(stderr, "\033[0m"); } while (0) int64_t g_num_of_tb = 2; int64_t g_num_of_rec = 3; @@ -74,10 +86,16 @@ static void prepare_data(TAOS* taos) { res = taos_query(taos, "create database test;"); taos_free_result(res); taosMsleep(100); - taos_select_db(taos, "test"); + if (taos_select_db(taos, "test")) { + errorPrint("%s() LN%d: taos_select_db() failed\n", + __func__, __LINE__); + return; + } char command[1024] = {0}; - sprintf(command, "%s", "create table meters(ts timestamp, f float, n int, bin1 binary(20), c nchar(20), bin2 binary(20)) tags(area int, city binary(20), dist nchar(20), street binary(20));"); + sprintf(command, "%s", "create table meters(ts timestamp, f float, n int, " + "bin1 binary(20), c nchar(20), bin2 binary(20)) tags(area int, " + "city binary(20), dist nchar(20), street binary(20));"); res = taos_query(taos, command); if ((res) && (0 == taos_errno(res))) { okPrint("%s created\n", "meters"); @@ -117,12 +135,11 @@ static void prepare_data(TAOS* taos) { sprintf(command, "insert into t%"PRId64" " "values(%" PRId64 ", %f, %"PRId64", " "'%c%d', '%s%c%d', '%c%d')", - i, 1650000000000+j, (float)j, j, + i, 1650000000000+j, j * 1.0, j, 'a'+(int)j%25, rand(), // "涛思", 'z' - (int)j%25, rand(), "TAOS", 'z' - (int)j%25, rand(), - 'b' - (int)j%25, rand() - ); + 'b' - (int)j%25, rand()); res = taos_query(taos, command); if ((res) && (0 == taos_errno(res))) { affected = taos_affected_rows(res); @@ -150,8 +167,7 @@ static void prepare_data(TAOS* taos) { i, 1650000000000+j+1, (float)j, j, 'a'+(int)j%25, rand(), "数据", 'z' - (int)j%25, rand(), - 'b' - (int)j%25, rand() - ); + 'b' - (int)j%25, rand()); res = taos_query(taos, command); if ((res) && (0 == taos_errno(res))) { affected = taos_affected_rows(res); @@ -179,7 +195,8 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { } if (block) { - warnPrint("%s", "call taos_fetch_block(), don't call taos_fetch_lengths()\n"); + warnPrint("%s", "call taos_fetch_block(), " + "don't call taos_fetch_lengths()\n"); int rows = 0; while ((rows = taos_fetch_block(res, &row))) { int *lengths = taos_fetch_lengths(res); @@ -190,7 +207,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { printf("col%d type is %d, no need get offset\n", f, fields[f].type); for (int64_t c = 0; c < rows; c++) { - switch(fields[f].type) { + switch (fields[f].type) { case TSDB_DATA_TYPE_TIMESTAMP: if (taos_is_null(res, c, f)) { printf("col%d, row: %"PRId64" " @@ -199,7 +216,8 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { printf("col%d, row: %"PRId64", " "value: %"PRId64"\n", f, c, - *(int64_t*)((char*)(row[f])+c*sizeof(int64_t))); + *(int64_t*)((char*)(row[f]) + +c*sizeof(int64_t))); } break; @@ -211,7 +229,8 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { printf("col%d, row: %"PRId64", " "value: %d\n", f, c, - *(int32_t*)((char*)(row[f])+c*sizeof(int32_t))); + *(int32_t*)((char*)(row[f]) + +c*sizeof(int32_t))); } break; @@ -223,7 +242,8 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { printf("col%d, row: %"PRId64", " "value: %f\n", f, c, - *(float*)((char*)(row[f])+c*sizeof(float))); + *(float*)((char*)(row[f]) + +c*sizeof(float))); } break; @@ -238,14 +258,18 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { if (offsets) { for (int c = 0; c < rows; c++) { if (offsets[c] != -1) { - int length = *(int16_t*)((char*)(row[f]) + offsets[c]); + int length = *(int16_t*)((char*)(row[f]) + + offsets[c]); char *buf = calloc(1, length + 1); - strncpy(buf, (char *)((char*)(row[f]) + offsets[c] + 2), length); - printf("row: %d, col: %d, offset: %d, length: %d, content: %s\n", + strncpy(buf, (char *)((char*)(row[f]) + + offsets[c] + 2), length); + printf("row: %d, col: %d, offset: %d, " + "length: %d, content: %s\n", c, f, offsets[c], length, buf); free(buf); } else { - printf("row: %d, col: %d, offset: -1, means content is NULL\n", + printf("row: %d, col: %d, offset: -1, " + "means content is NULL\n", c, f); } } @@ -267,7 +291,8 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { int* lengths = taos_fetch_lengths(res); if (lengths) { for (int c = 0; c < num_fields; c++) { - printf("row: %"PRId64", col: %d, is_null: %s, length of column %d is %d\n", + printf("row: %"PRId64", col: %d, is_null: %s, " + "length of column %d is %d\n", num_rows, c, taos_is_null(res, num_rows, c)?"True":"False", c, lengths[c]); @@ -277,7 +302,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { __func__, __LINE__, tbname); } - num_rows ++; + num_rows++; } } @@ -322,7 +347,8 @@ int main(int argc, char *argv[]) { #endif TAOS* taos = taos_connect(host, user, passwd, "", 0); if (taos == NULL) { - printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos)); + printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", + taos_errstr(taos)); exit(1); } diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 0e22985059907956c207d7c40103480d0913e65e..fd0521af3b96933dec7064483578e06d00731ce8 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -93,6 +93,7 @@ extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in // query client extern int32_t tsQueryPolicy; +extern int32_t tsQueryRspPolicy; extern int32_t tsQuerySmaOptimize; extern int32_t tsQueryRsmaTolerance; extern bool tsQueryPlannerTrace; diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 0d43539629c170a2dcf22bee395cbc7caa93edc5..cdb1642a5c313767fe6a6d5ad53d6202f8c677a6 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -30,9 +30,10 @@ typedef struct SMnode SMnode; typedef struct { int32_t dnodeId; - bool standby; bool deploy; - SReplica replica; + int8_t selfIndex; + int8_t numOfReplicas; + SReplica replicas[TSDB_MAX_REPLICA]; SMsgCb msgCb; } SMnodeOpt; diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index c179d69960ac80eef69a04e721fb6c582560ef59..7d95e840e9c539aa7d75fa32a325de2be766aec2 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -54,6 +54,9 @@ typedef enum { #define QUERY_POLICY_QNODE 3 #define QUERY_POLICY_CLIENT 4 +#define QUERY_RSP_POLICY_DELAY 0 +#define QUERY_RSP_POLICY_QUICK 1 + typedef struct STableComInfo { uint8_t numOfTags; // the number of tags in schema uint8_t precision; // the number of precision @@ -230,7 +233,7 @@ int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst); int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst); extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char** msg, int32_t msgSize, int32_t* msgLen, - void* (*mallocFp)(int32_t)); + void* (*mallocFp)(int64_t)); extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t msgSize); #define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE diff --git a/include/libs/scalar/scalar.h b/include/libs/scalar/scalar.h index 6322c6a1e969371c20efbb0e2f4b96800242ecee..ef8e80b57fbc7fdb6255bcd38b88652e20cc5a9d 100644 --- a/include/libs/scalar/scalar.h +++ b/include/libs/scalar/scalar.h @@ -43,7 +43,7 @@ int32_t scalarGetOperatorParamNum(EOperatorType type); int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type); int32_t vectorGetConvertType(int32_t type1, int32_t type2); -int32_t vectorConvertImpl(const SScalarParam *pIn, SScalarParam *pOut, int32_t *overflow); +int32_t vectorConvertSingleColImpl(const SScalarParam *pIn, SScalarParam *pOut, int32_t *overflow, int32_t startIndex, int32_t numOfRows); /* Math functions */ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); diff --git a/include/libs/stream/streamState.h b/include/libs/stream/streamState.h index c2b3a7977c850d07feeed5af9fe71f7006fdc893..9445a0baa5302a7529e8d2d75ca89db6b96d6374 100644 --- a/include/libs/stream/streamState.h +++ b/include/libs/stream/streamState.h @@ -36,7 +36,7 @@ typedef struct { int32_t number; } SStreamState; -SStreamState* streamStateOpen(char* path, SStreamTask* pTask, bool specPath); +SStreamState* streamStateOpen(char* path, SStreamTask* pTask, bool specPath, int32_t szPage, int32_t pages); void streamStateClose(SStreamState* pState); int32_t streamStateBegin(SStreamState* pState); int32_t streamStateCommit(SStreamState* pState); diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 411a63a37966fc7104b86202fe97f22c78c92ad1..0f8220f19ccc1bc01a69c37a054f1621aef0e0c2 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -211,7 +211,7 @@ typedef struct SSyncInfo { int32_t syncInit(); void syncCleanUp(); -int64_t syncOpen(const SSyncInfo* pSyncInfo); +int64_t syncOpen(SSyncInfo* pSyncInfo); void syncStart(int64_t rid); void syncStop(int64_t rid); int32_t syncSetStandby(int64_t rid); @@ -233,7 +233,7 @@ const char* syncStr(ESyncState state); bool syncIsRestoreFinish(int64_t rid); int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapshot); -int32_t syncReconfig(int64_t rid, const SSyncCfg* pNewCfg); +int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg); // build SRpcMsg, need to call syncPropose with SRpcMsg int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg); diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 56c5750475e32b6c2606cfdbc0e4c5e75faabf46..53edcd4fee9bb9af6ab0d44235159b90990cf5c1 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -123,9 +123,9 @@ void rpcCleanup(); void *rpcOpen(const SRpcInit *pRpc); void rpcClose(void *); void rpcCloseImpl(void *); -void *rpcMallocCont(int32_t contLen); +void *rpcMallocCont(int64_t contLen); void rpcFreeCont(void *pCont); -void *rpcReallocCont(void *ptr, int32_t contLen); +void *rpcReallocCont(void *ptr, int64_t contLen); // Because taosd supports multi-process mode // These functions should not be used on the server side diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index de31a970dffc146dcc3b36e3933740200811af47..adf244e32a82a67386e4ef699b8689165c9519eb 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -43,6 +43,7 @@ extern "C" { #define WAL_FILE_LEN (WAL_PATH_LEN + 32) #define WAL_MAGIC 0xFAFBFCFDF4F3F2F1ULL #define WAL_SCAN_BUF_SIZE (1024 * 1024 * 3) +#define WAL_RECOV_SIZE_LIMIT (100 * WAL_SCAN_BUF_SIZE) typedef enum { TAOS_WAL_WRITE = 1, diff --git a/include/os/osEnv.h b/include/os/osEnv.h index 293d9d17f85b9fe890570ec7045a5b4c59b7adc5..d4e94d6173a813e44e68355bb6a0ead964823ba1 100644 --- a/include/os/osEnv.h +++ b/include/os/osEnv.h @@ -49,9 +49,15 @@ extern SDiskSpace tsTempSpace; void osDefaultInit(); void osUpdate(); void osCleanup(); + bool osLogSpaceAvailable(); bool osDataSpaceAvailable(); bool osTempSpaceAvailable(); + +bool osLogSpaceSufficient(); +bool osDataSpaceSufficient(); +bool osTempSpaceSufficient(); + void osSetTimezone(const char *timezone); void osSetSystemLocale(const char *inLocale, const char *inCharSet); @@ -59,4 +65,4 @@ void osSetSystemLocale(const char *inLocale, const char *inCharSet); } #endif -#endif /*_TD_OS_ENV_H_*/ \ No newline at end of file +#endif /*_TD_OS_ENV_H_*/ diff --git a/include/os/osMemory.h b/include/os/osMemory.h index 3146590d6c9e81a415c7efce52ff16167f886b75..7ec8366ee4cb584dc41aa0ce94d5c54f6405964e 100644 --- a/include/os/osMemory.h +++ b/include/os/osMemory.h @@ -29,12 +29,12 @@ extern "C" { #define free FREE_FUNC_TAOS_FORBID #endif -void *taosMemoryMalloc(int32_t size); -void *taosMemoryCalloc(int32_t num, int32_t size); -void *taosMemoryRealloc(void *ptr, int32_t size); +void *taosMemoryMalloc(int64_t size); +void *taosMemoryCalloc(int64_t num, int64_t size); +void *taosMemoryRealloc(void *ptr, int64_t size); void *taosMemoryStrDup(const char *ptr); void taosMemoryFree(void *ptr); -int32_t taosMemorySize(void *ptr); +int64_t taosMemorySize(void *ptr); void taosPrintBackTrace(); #define taosMemoryFreeClear(ptr) \ diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 6bc0e0e7dd509075834b5fb650b28206f5c502f9..bbddb539c60dd53d73ee6e7528caa5a4c48ce9c1 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -450,6 +450,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_WAL_INVALID_VER TAOS_DEF_ERROR_CODE(0, 0x1003) #define TSDB_CODE_WAL_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x1004) #define TSDB_CODE_WAL_LOG_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x1005) +#define TSDB_CODE_WAL_CHKSUM_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x1006) // tfs #define TSDB_CODE_FS_INVLD_CFG TAOS_DEF_ERROR_CODE(0, 0x2201) diff --git a/include/util/trbtree.h b/include/util/trbtree.h index f6d37e3d753de71fdf312b795935cb9014149f23..7c93c8dd8d65f2c4947019f370c0933e6ad81ee0 100644 --- a/include/util/trbtree.h +++ b/include/util/trbtree.h @@ -26,7 +26,7 @@ typedef struct SRBTree SRBTree; typedef struct SRBTreeNode SRBTreeNode; typedef struct SRBTreeIter SRBTreeIter; -typedef int32_t (*tRBTreeCmprFn)(const void *, const void *); +typedef int32_t (*tRBTreeCmprFn)(const SRBTreeNode *, const SRBTreeNode *); // SRBTree ============================================= #define tRBTreeMin(T) ((T)->min == ((T)->NIL) ? NULL : (T)->min) @@ -36,7 +36,7 @@ void tRBTreeCreate(SRBTree *pTree, tRBTreeCmprFn cmprFn); SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *z); void tRBTreeDrop(SRBTree *pTree, SRBTreeNode *z); SRBTreeNode *tRBTreeDropByKey(SRBTree *pTree, void *pKey); -SRBTreeNode *tRBTreeGet(SRBTree *pTree, void *pKey); +SRBTreeNode *tRBTreeGet(SRBTree *pTree, const SRBTreeNode *pKeyNode); // SRBTreeIter ============================================= #define tRBTreeIterCreate(tree, ascend) \ @@ -53,8 +53,6 @@ struct SRBTreeNode { SRBTreeNode *right; }; -#define RBTREE_NODE_PAYLOAD(N) ((const void *)&(N)[1]) - struct SRBTree { tRBTreeCmprFn cmprFn; int64_t n; diff --git a/packaging/release.sh b/packaging/release.sh index 9ebbc50a84ffb762a2440b840fce8064bb4b7f2b..ce424918926dc7b9f62d70fe8da03d9688f33189 100755 --- a/packaging/release.sh +++ b/packaging/release.sh @@ -260,7 +260,7 @@ if [ "$osType" != "Darwin" ]; then if [[ "$pagMode" == "full" ]]; then if [ -d ${top_dir}/tools/taos-tools/packaging/deb ]; then cd ${top_dir}/tools/taos-tools/packaging/deb - taos_tools_ver=$(git describe --tags | sed -e 's/ver-//g' | awk -F '-' '{print $1}') + taos_tools_ver=$(git tag |grep -v taos | sort | tail -1) [ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0" ${csudo}./make-taos-tools-deb.sh ${top_dir} \ @@ -285,7 +285,7 @@ if [ "$osType" != "Darwin" ]; then if [[ "$pagMode" == "full" ]]; then if [ -d ${top_dir}/tools/taos-tools/packaging/rpm ]; then cd ${top_dir}/tools/taos-tools/packaging/rpm - taos_tools_ver=$(git describe --tags | sed -e 's/ver-//g' | awk -F '-' '{print $1}' | sed -e 's/-/_/g') + taos_tools_ver=$(git tag |grep -v taos | sort | tail -1) [ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0" ${csudo}./make-taos-tools-rpm.sh ${top_dir} \ diff --git a/packaging/tools/TDengine b/packaging/tools/TDengine index 3025a5639f3dda2c9b06ef5ffaf0a7f0995c2532..c0b80564c49c5dde631bc96f68e4d37fc1f12b33 100755 --- a/packaging/tools/TDengine +++ b/packaging/tools/TDengine @@ -17,12 +17,12 @@ EOF taosd_status=`Launchctl list | grep taosd | head -n 1 | awk '{print $1}'` if [ "$taosd_status"x = "-"x ]; then - launchctl start taosd + launchctl start com.tdengine.taosd showAlertMessage "Taosd is running!" "TDengine" "ok" "note" else choose_result=`showAlertMessage "Taosd is running!\nDo you want to close it?" "TDengine" "yes,cancel" "stop"` if [ "$choose_result"x = "button returned:yes"x ]; then - launchctl stop taosd + launchctl stop com.tdengine.taosd fi fi diff --git a/packaging/tools/TDengine.pkgproj b/packaging/tools/TDengine.pkgproj new file mode 100644 index 0000000000000000000000000000000000000000..7aaac627352e60385af5fd6e4fd2b2694952a580 --- /dev/null +++ b/packaging/tools/TDengine.pkgproj @@ -0,0 +1,882 @@ + + + + + PACKAGES + + + MUST-CLOSE-APPLICATION-ITEMS + + MUST-CLOSE-APPLICATIONS + + PACKAGE_FILES + + DEFAULT_INSTALL_LOCATION + / + HIERARCHY + + CHILDREN + + + CHILDREN + + GID + 80 + PATH + Applications + PATH_TYPE + 0 + PERMISSIONS + 509 + TYPE + 1 + UID + 0 + + + CHILDREN + + + CHILDREN + + GID + 80 + PATH + Application Support + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Automator + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Documentation + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Extensions + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Filesystems + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Frameworks + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Input Methods + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Internet Plug-Ins + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Keyboard Layouts + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + LaunchAgents + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + LaunchDaemons + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + PreferencePanes + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Preferences + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 80 + PATH + Printers + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + PrivilegedHelperTools + PATH_TYPE + 0 + PERMISSIONS + 1005 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + QuickLook + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + QuickTime + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Screen Savers + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Scripts + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Services + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + GID + 0 + PATH + Widgets + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + GID + 0 + PATH + Library + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + CHILDREN + + + CHILDREN + + GID + 0 + PATH + Shared + PATH_TYPE + 0 + PERMISSIONS + 1023 + TYPE + 1 + UID + 0 + + + GID + 80 + PATH + Users + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + + GID + 0 + PATH + / + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 1 + UID + 0 + + PAYLOAD_TYPE + 0 + PRESERVE_EXTENDED_ATTRIBUTES + + SHOW_INVISIBLE + + SPLIT_FORKS + + TREAT_MISSING_FILES_AS_WARNING + + VERSION + 5 + + PACKAGE_SCRIPTS + + POSTINSTALL_PATH + + PATH + /opt/taos/TDengine/packaging/tools/post.sh + PATH_TYPE + 0 + + PREINSTALL_PATH + + PATH_TYPE + 0 + + RESOURCES + + + CHILDREN + + GID + 0 + PATH + /opt/tdengine + PATH_TYPE + 0 + PERMISSIONS + 493 + TYPE + 3 + UID + 0 + + + + PACKAGE_SETTINGS + + AUTHENTICATION + 1 + CONCLUSION_ACTION + 0 + FOLLOW_SYMBOLIC_LINKS + + IDENTIFIER + com.taosdata.pkg.pkgtaos + LOCATION + 0 + NAME + TDengine + OVERWRITE_PERMISSIONS + + PAYLOAD_SIZE + -1 + REFERENCE_PATH + + RELOCATABLE + + USE_HFS+_COMPRESSION + + VERSION + 3.0.1.4 + + TYPE + 0 + UUID + 48F6B249-AF56-46E3-B75A-AEED5858A764 + + + PROJECT + + PROJECT_COMMENTS + + NOTES + + + + PROJECT_PRESENTATION + + BACKGROUND + + APPAREANCES + + DARK_AQUA + + LIGHT_AQUA + + + SHARED_SETTINGS_FOR_ALL_APPAREANCES + + + INSTALLATION TYPE + + HIERARCHIES + + INSTALLER + + LIST + + + CHILDREN + + DESCRIPTION + + OPTIONS + + HIDDEN + + STATE + 1 + + PACKAGE_UUID + 48F6B249-AF56-46E3-B75A-AEED5858A764 + TITLE + + TYPE + 0 + UUID + 7ED88D2C-D55C-46FF-99CB-73313ACAD73D + + + REMOVED + + + + MODE + 0 + + INSTALLATION_STEPS + + + ICPRESENTATION_CHAPTER_VIEW_CONTROLLER_CLASS + ICPresentationViewIntroductionController + INSTALLER_PLUGIN + Introduction + LIST_TITLE_KEY + InstallerSectionTitle + + + ICPRESENTATION_CHAPTER_VIEW_CONTROLLER_CLASS + ICPresentationViewReadMeController + INSTALLER_PLUGIN + ReadMe + LIST_TITLE_KEY + InstallerSectionTitle + + + ICPRESENTATION_CHAPTER_VIEW_CONTROLLER_CLASS + ICPresentationViewLicenseController + INSTALLER_PLUGIN + License + LIST_TITLE_KEY + InstallerSectionTitle + + + ICPRESENTATION_CHAPTER_VIEW_CONTROLLER_CLASS + ICPresentationViewDestinationSelectController + INSTALLER_PLUGIN + TargetSelect + LIST_TITLE_KEY + InstallerSectionTitle + + + ICPRESENTATION_CHAPTER_VIEW_CONTROLLER_CLASS + ICPresentationViewInstallationTypeController + INSTALLER_PLUGIN + PackageSelection + LIST_TITLE_KEY + InstallerSectionTitle + + + ICPRESENTATION_CHAPTER_VIEW_CONTROLLER_CLASS + ICPresentationViewInstallationController + INSTALLER_PLUGIN + Install + LIST_TITLE_KEY + InstallerSectionTitle + + + ICPRESENTATION_CHAPTER_VIEW_CONTROLLER_CLASS + ICPresentationViewSummaryController + INSTALLER_PLUGIN + Summary + LIST_TITLE_KEY + InstallerSectionTitle + + + INTRODUCTION + + LOCALIZATIONS + + + LANGUAGE + English + VALUE + + PATH + /opt/taos/TDengine/packaging/tools/mac_before_install.txt + PATH_TYPE + 0 + + + + + LICENSE + + LOCALIZATIONS + + MODE + 0 + + README + + LOCALIZATIONS + + + SUMMARY + + LOCALIZATIONS + + + TITLE + + LOCALIZATIONS + + + LANGUAGE + English + VALUE + TDengine + + + + + PROJECT_REQUIREMENTS + + LIST + + RESOURCES + + ROOT_VOLUME_ONLY + + + PROJECT_SETTINGS + + BUILD_FORMAT + 0 + BUILD_PATH + + PATH + /opt/taos/TDengine/release + PATH_TYPE + 0 + + EXCLUDED_FILES + + + PATTERNS_ARRAY + + + REGULAR_EXPRESSION + + STRING + .DS_Store + TYPE + 0 + + + PROTECTED + + PROXY_NAME + Remove .DS_Store files + PROXY_TOOLTIP + Remove ".DS_Store" files created by the Finder. + STATE + + + + PATTERNS_ARRAY + + + REGULAR_EXPRESSION + + STRING + .pbdevelopment + TYPE + 0 + + + PROTECTED + + PROXY_NAME + Remove .pbdevelopment files + PROXY_TOOLTIP + Remove ".pbdevelopment" files created by ProjectBuilder or Xcode. + STATE + + + + PATTERNS_ARRAY + + + REGULAR_EXPRESSION + + STRING + CVS + TYPE + 1 + + + REGULAR_EXPRESSION + + STRING + .cvsignore + TYPE + 0 + + + REGULAR_EXPRESSION + + STRING + .cvspass + TYPE + 0 + + + REGULAR_EXPRESSION + + STRING + .svn + TYPE + 1 + + + REGULAR_EXPRESSION + + STRING + .git + TYPE + 1 + + + REGULAR_EXPRESSION + + STRING + .gitignore + TYPE + 0 + + + PROTECTED + + PROXY_NAME + Remove SCM metadata + PROXY_TOOLTIP + Remove helper files and folders used by the CVS, SVN or Git Source Code Management systems. + STATE + + + + PATTERNS_ARRAY + + + REGULAR_EXPRESSION + + STRING + classes.nib + TYPE + 0 + + + REGULAR_EXPRESSION + + STRING + designable.db + TYPE + 0 + + + REGULAR_EXPRESSION + + STRING + info.nib + TYPE + 0 + + + PROTECTED + + PROXY_NAME + Optimize nib files + PROXY_TOOLTIP + Remove "classes.nib", "info.nib" and "designable.nib" files within .nib bundles. + STATE + + + + PATTERNS_ARRAY + + + REGULAR_EXPRESSION + + STRING + Resources Disabled + TYPE + 1 + + + PROTECTED + + PROXY_NAME + Remove Resources Disabled folders + PROXY_TOOLTIP + Remove "Resources Disabled" folders. + STATE + + + + SEPARATOR + + + + NAME + TDengine-client-3.0.1.4-macOS-arm64 + PAYLOAD_ONLY + + TREAT_MISSING_PRESENTATION_DOCUMENTS_AS_WARNING + + + + TYPE + 0 + VERSION + 2 + + diff --git a/packaging/tools/com.taosdata.taosd.plist b/packaging/tools/com.taosdata.taosd.plist index ca9b8c5ef1a103afc125417f99b60ccf4b51f610..0bf3135ac30239fefe081d1b45928540ecbebdbf 100644 --- a/packaging/tools/com.taosdata.taosd.plist +++ b/packaging/tools/com.taosdata.taosd.plist @@ -3,7 +3,7 @@ Label - taosd + com.tdengine.taosd ProgramArguments /usr/local/bin/taosd diff --git a/packaging/tools/mac_before_install.txt b/packaging/tools/mac_before_install.txt index f70ea7161f4df28594639f8f2a1f0a335b8ad03f..b33cd478b8982a5c6c8263ea3d2ea6d607f3f706 100644 --- a/packaging/tools/mac_before_install.txt +++ b/packaging/tools/mac_before_install.txt @@ -1,5 +1,5 @@ TDengine is a high-efficient, scalable, high-available distributed time-series database, which makes a lot of optimizations on inserting and querying data, which is far more efficient than normal regular databases. So TDengine can meet the high requirements of IOT and other areas on storing and querying a large amount of data. To configure TDengine : edit /etc/taos/taos.cfg -To start service : launchctl start taosd +To start service : launchctl start com.tdengine.taosd To access TDengine : use taos in shell \ No newline at end of file diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index b8796ddf09b2f0d899aad793ebe757b649ad9814..b56a5a203d7e42827512c8930345e45022a719b1 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -615,7 +615,7 @@ function update_TDengine() { if [ "$osType" != "Darwin" ]; then echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${serverName}${NC}" else - echo -e "${GREEN_DARK}To start service ${NC}: launchctl start ${serverName}${NC}" + echo -e "${GREEN_DARK}To start service ${NC}: launchctl start com.tdengine.taosd${NC}" fi [ -f ${installDir}/bin/taosadapter ] && \ echo -e "${GREEN_DARK}To start Taos Adapter ${NC}: taosadapter &${NC}" @@ -666,7 +666,7 @@ function install_TDengine() { if [ "$osType" != "Darwin" ]; then echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${serverName}${NC}" else - echo -e "${GREEN_DARK}To start service ${NC}: launchctl start ${serverName}${NC}" + echo -e "${GREEN_DARK}To start service ${NC}: launchctl start com.tdengine.taosd${NC}" fi [ -f ${installDir}/bin/taosadapter ] && \ echo -e "${GREEN_DARK}To start Taos Adapter ${NC}: taosadapter &${NC}" diff --git a/packaging/tools/post.sh b/packaging/tools/post.sh index 29d4ac017ca9d8813e1f7c69f4f5e6056602b16c..b729513b97206673c2ed6d2d9be20a28b5b8e258 100755 --- a/packaging/tools/post.sh +++ b/packaging/tools/post.sh @@ -18,6 +18,7 @@ if [ "$osType" != "Darwin" ]; then script_dir=$(dirname $(readlink -f "$0")) verNumber="" lib_file_ext="so" + lib_file_ext_1="so.1" bin_link_dir="/usr/bin" lib_link_dir="/usr/lib" @@ -29,6 +30,7 @@ else script_dir=${source_dir}/packaging/tools verNumber=`ls tdengine/driver | grep -E "libtaos\.[0-9]\.[0-9]" | sed "s/libtaos.//g" | sed "s/.dylib//g" | head -n 1` lib_file_ext="dylib" + lib_file_ext_1="1.dylib" bin_link_dir="/usr/local/bin" lib_link_dir="/usr/local/lib" @@ -134,14 +136,14 @@ function install_lib() { [ -f ${lib_link_dir}/libtaosws.${lib_file_ext} ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.${lib_file_ext} || : [ -f ${lib64_link_dir}/libtaosws.${lib_file_ext} ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.${lib_file_ext} || : - ${csudo}ln -s ${lib_dir}/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${lib_dir}/libtaos.* ${lib_link_dir}/libtaos.${lib_file_ext_1} + ${csudo}ln -s ${lib_link_dir}/libtaos.${lib_file_ext_1} ${lib_link_dir}/libtaos.${lib_file_ext} [ -f ${lib_dir}/libtaosws.${lib_file_ext} ] && ${csudo}ln -sf ${lib_dir}/libtaosws.${lib_file_ext} ${lib_link_dir}/libtaosws.${lib_file_ext} ||: - if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then - ${csudo}ln -s ${lib_dir}/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : - ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.${lib_file_ext} ]]; then + ${csudo}ln -s ${lib_dir}/libtaos.* ${lib64_link_dir}/libtaos.${lib_file_ext_1} || : + ${csudo}ln -s ${lib64_link_dir}/libtaos.${lib_file_ext_1} ${lib64_link_dir}/libtaos.${lib_file_ext} || : [ -f ${lib_dir}/libtaosws.${lib_file_ext} ] && ${csudo}ln -sf ${lib_dir}/libtaosws.${lib_file_ext} ${lib64_link_dir}/libtaosws.${lib_file_ext} || : fi diff --git a/packaging/tools/remove.sh b/packaging/tools/remove.sh index 6172fc9bc8bcce6a311b82cff52b797c3731b296..bace0bc869e599aaf376356094b85e8f5e0d4556 100755 --- a/packaging/tools/remove.sh +++ b/packaging/tools/remove.sh @@ -117,7 +117,7 @@ function clean_local_bin() { function clean_lib() { # Remove link ${csudo}rm -f ${lib_link_dir}/libtaos.* || : - [ -f ${lib_link_dir}/libtaosws.so ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.so || : + [ -f ${lib_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.* || : ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : [ -f ${lib64_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.* || : diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index e8e3c878496c58631131922cc6de47491d548f06..0c445c7fbfa01b6432259bd20e7e481966aee7a7 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -19,6 +19,13 @@ target_link_libraries( PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom ) +if(TD_DARWIN_ARM64) + target_link_libraries( + taos + PRIVATE "-arch x86_64" + ) +endif() + if(TD_WINDOWS) INCLUDE_DIRECTORIES(jni/windows) INCLUDE_DIRECTORIES(jni/windows/win32) diff --git a/source/client/inc/clientLog.h b/source/client/inc/clientLog.h index ec0a41a68f9515bc7ea2c54e96b0235c0a9683eb..541717c7eb4bf9719e49ce0482b0df95625199c6 100644 --- a/source/client/inc/clientLog.h +++ b/source/client/inc/clientLog.h @@ -22,6 +22,7 @@ extern "C" { #include "tlog.h" +// clang-format off #define tscFatal(...) do { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", DEBUG_FATAL, cDebugFlag, __VA_ARGS__); }} while(0) #define tscError(...) do { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", DEBUG_ERROR, cDebugFlag, __VA_ARGS__); }} while(0) #define tscWarn(...) do { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", DEBUG_WARN, cDebugFlag, __VA_ARGS__); }} while(0) @@ -30,6 +31,7 @@ extern "C" { #define tscTrace(...) do { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", DEBUG_TRACE, cDebugFlag, __VA_ARGS__); }} while(0) #define tscDebugL(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", DEBUG_DEBUG, cDebugFlag, __VA_ARGS__); }} while(0) #define tscPerf(...) do { taosPrintLog("TSC ", 0, cDebugFlag, __VA_ARGS__); } while(0) +// clang-format on #ifdef __cplusplus } diff --git a/source/client/inc/clientStmt.h b/source/client/inc/clientStmt.h index a7adaef96613cbaa52a212528b36eaa5a1ea0cb7..2261a6becb30c01e5d8edb096169721d84a4a88c 100644 --- a/source/client/inc/clientStmt.h +++ b/source/client/inc/clientStmt.h @@ -42,37 +42,37 @@ typedef enum { } STMT_STATUS; typedef struct SStmtTableCache { - STableDataBlocks* pDataBlock; - void* boundTags; + STableDataBlocks *pDataBlock; + void *boundTags; } SStmtTableCache; typedef struct SStmtQueryResInfo { - TAOS_FIELD* fields; - TAOS_FIELD* userFields; - uint32_t numOfCols; - int32_t precision; + TAOS_FIELD *fields; + TAOS_FIELD *userFields; + uint32_t numOfCols; + int32_t precision; } SStmtQueryResInfo; typedef struct SStmtBindInfo { - bool needParse; - bool inExecCache; - uint64_t tbUid; - uint64_t tbSuid; - int32_t sBindRowNum; - int32_t sBindLastIdx; - int8_t tbType; - bool tagsCached; - void* boundTags; - char tbName[TSDB_TABLE_FNAME_LEN]; - char tbFName[TSDB_TABLE_FNAME_LEN]; - char stbFName[TSDB_TABLE_FNAME_LEN]; - SName sname; + bool needParse; + bool inExecCache; + uint64_t tbUid; + uint64_t tbSuid; + int32_t sBindRowNum; + int32_t sBindLastIdx; + int8_t tbType; + bool tagsCached; + void *boundTags; + char tbName[TSDB_TABLE_FNAME_LEN]; + char tbFName[TSDB_TABLE_FNAME_LEN]; + char stbFName[TSDB_TABLE_FNAME_LEN]; + SName sname; } SStmtBindInfo; typedef struct SStmtExecInfo { int32_t affectedRows; - SRequestObj* pRequest; - SHashObj* pBlockHash; + SRequestObj *pRequest; + SHashObj *pBlockHash; bool autoCreateTbl; } SStmtExecInfo; @@ -80,20 +80,20 @@ typedef struct SStmtSQLInfo { STMT_TYPE type; STMT_STATUS status; uint64_t runTimes; - SHashObj* pTableCache; //SHash - SQuery* pQuery; - char* sqlStr; + SHashObj *pTableCache; // SHash + SQuery *pQuery; + char *sqlStr; int32_t sqlLen; - SArray* nodeList; + SArray *nodeList; SStmtQueryResInfo queryRes; bool autoCreateTbl; - SHashObj* pVgHash; + SHashObj *pVgHash; } SStmtSQLInfo; typedef struct STscStmt { - STscObj* taos; - SCatalog* pCatalog; - int32_t affectedRows; + STscObj *taos; + SCatalog *pCatalog; + int32_t affectedRows; SStmtSQLInfo sql; SStmtExecInfo exec; @@ -103,28 +103,48 @@ typedef struct STscStmt { #define STMT_STATUS_NE(S) (pStmt->sql.status != STMT_##S) #define STMT_STATUS_EQ(S) (pStmt->sql.status == STMT_##S) -#define STMT_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) -#define STMT_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) -#define STMT_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) - -TAOS_STMT *stmtInit(STscObj* taos); -int stmtClose(TAOS_STMT *stmt); -int stmtExec(TAOS_STMT *stmt); +#define STMT_ERR_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + return _code; \ + } \ + } while (0) +#define STMT_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + } \ + return _code; \ + } while (0) +#define STMT_ERR_JRET(c) \ + do { \ + code = c; \ + if (code != TSDB_CODE_SUCCESS) { \ + terrno = code; \ + goto _return; \ + } \ + } while (0) + +TAOS_STMT *stmtInit(STscObj *taos); +int stmtClose(TAOS_STMT *stmt); +int stmtExec(TAOS_STMT *stmt); const char *stmtErrstr(TAOS_STMT *stmt); -int stmtAffectedRows(TAOS_STMT *stmt); -int stmtAffectedRowsOnce(TAOS_STMT *stmt); -int stmtPrepare(TAOS_STMT *stmt, const char *sql, unsigned long length); -int stmtSetTbName(TAOS_STMT *stmt, const char *tbName); -int stmtSetTbTags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags); -int stmtGetTagFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields); -int stmtGetColFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields); -int stmtIsInsert(TAOS_STMT *stmt, int *insert); -int stmtGetParamNum(TAOS_STMT *stmt, int *nums); -int stmtGetParam(TAOS_STMT *stmt, int idx, int *type, int *bytes); -int stmtAddBatch(TAOS_STMT *stmt); -TAOS_RES *stmtUseResult(TAOS_STMT *stmt); -int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int32_t colIdx); - +int stmtAffectedRows(TAOS_STMT *stmt); +int stmtAffectedRowsOnce(TAOS_STMT *stmt); +int stmtPrepare(TAOS_STMT *stmt, const char *sql, unsigned long length); +int stmtSetTbName(TAOS_STMT *stmt, const char *tbName); +int stmtSetTbTags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags); +int stmtGetTagFields(TAOS_STMT *stmt, int *nums, TAOS_FIELD_E **fields); +int stmtGetColFields(TAOS_STMT *stmt, int *nums, TAOS_FIELD_E **fields); +int stmtIsInsert(TAOS_STMT *stmt, int *insert); +int stmtGetParamNum(TAOS_STMT *stmt, int *nums); +int stmtGetParam(TAOS_STMT *stmt, int idx, int *type, int *bytes); +int stmtAddBatch(TAOS_STMT *stmt); +TAOS_RES *stmtUseResult(TAOS_STMT *stmt); +int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int32_t colIdx); #ifdef __cplusplus } diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 7b437e47699ca623da62ceb496ab2a7337df7412..940dd745c855f2f380faded0933434430886d3c6 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -1036,30 +1036,38 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat pRequest->type = pQuery->msgType; SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad)); - SPlanContext cxt = {.queryId = pRequest->requestId, - .acctId = pRequest->pTscObj->acctId, - .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp), - .pAstRoot = pQuery->pRoot, - .showRewrite = pQuery->showRewrite, - .pMsg = pRequest->msgBuf, - .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE, - .pUser = pRequest->pTscObj->user, - .sysInfo = pRequest->pTscObj->sysInfo, - .allocatorId = pRequest->allocatorRefId}; - SQueryPlan* pDag = NULL; - int32_t code = qCreateQueryPlan(&cxt, &pDag, pMnodeList); - if (code) { - tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code), - pRequest->requestId); - } else { - pRequest->body.subplanNum = pDag->numOfSubplans; - } - pRequest->metric.planEnd = taosGetTimestampUs(); + SPlanContext cxt = {.queryId = pRequest->requestId, + .acctId = pRequest->pTscObj->acctId, + .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp), + .pAstRoot = pQuery->pRoot, + .showRewrite = pQuery->showRewrite, + .pMsg = pRequest->msgBuf, + .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE, + .pUser = pRequest->pTscObj->user, + .sysInfo = pRequest->pTscObj->sysInfo, + .allocatorId = pRequest->allocatorRefId}; + + SAppInstInfo* pAppInfo = getAppInfo(pRequest); + SQueryPlan* pDag = NULL; + + int64_t st = taosGetTimestampUs(); + int32_t code = qCreateQueryPlan(&cxt, &pDag, pMnodeList); + if (code) { + tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code), + pRequest->requestId); + } else { + pRequest->body.subplanNum = pDag->numOfSubplans; + } - if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) { - SArray* pNodeList = NULL; - buildAsyncExecNodeList(pRequest, &pNodeList, pMnodeList, pResultMeta); + pRequest->metric.planEnd = taosGetTimestampUs(); + if (code == TSDB_CODE_SUCCESS) { + tscDebug("0x%" PRIx64 " create query plan success, elapsed time:%.2f ms, 0x%" PRIx64, pRequest->self, + (pRequest->metric.planEnd - st)/1000.0, pRequest->requestId); + } + if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) { + SArray* pNodeList = NULL; + buildAsyncExecNodeList(pRequest, &pNodeList, pMnodeList, pResultMeta); SRequestConnInfo conn = {.pTrans = getAppInfo(pRequest)->pTransporter, .requestId = pRequest->requestId, diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 6f8cef7c0d50aff6dd76903691a0fc3521230d85..6126817ececa647dacd220031163464ae57d854e 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -146,7 +146,7 @@ void taos_close(TAOS *taos) { int taos_errno(TAOS_RES *res) { if (res == NULL || TD_RES_TMQ_META(res)) { - if (terrno == TSDB_CODE_RPC_REDIRECT) terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; + if (terrno == TSDB_CODE_RPC_REDIRECT) terrno = TSDB_CODE_QRY_NOT_READY; return terrno; } @@ -154,13 +154,12 @@ int taos_errno(TAOS_RES *res) { return 0; } - return ((SRequestObj *)res)->code == TSDB_CODE_RPC_REDIRECT ? TSDB_CODE_RPC_NETWORK_UNAVAIL - : ((SRequestObj *)res)->code; + return ((SRequestObj *)res)->code == TSDB_CODE_RPC_REDIRECT ? TSDB_CODE_QRY_NOT_READY : ((SRequestObj *)res)->code; } const char *taos_errstr(TAOS_RES *res) { if (res == NULL || TD_RES_TMQ_META(res)) { - if (terrno == TSDB_CODE_RPC_REDIRECT) terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; + if (terrno == TSDB_CODE_RPC_REDIRECT) terrno = TSDB_CODE_QRY_NOT_READY; return (const char *)tstrerror(terrno); } @@ -172,7 +171,7 @@ const char *taos_errstr(TAOS_RES *res) { if (NULL != pRequest->msgBuf && (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR)) { return pRequest->msgBuf; } else { - return pRequest->code == TSDB_CODE_RPC_REDIRECT ? (const char *)tstrerror(TSDB_CODE_RPC_NETWORK_UNAVAIL) + return pRequest->code == TSDB_CODE_RPC_REDIRECT ? (const char *)tstrerror(TSDB_CODE_QRY_NOT_READY) : (const char *)tstrerror(pRequest->code); } } @@ -222,7 +221,9 @@ void taos_kill_query(TAOS *taos) { int64_t rid = *(int64_t *)taos; STscObj *pTscObj = acquireTscObj(rid); - stopAllRequests(pTscObj->pRequests); + if (pTscObj) { + stopAllRequests(pTscObj->pRequests); + } releaseTscObj(rid); } diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index c5633e73d0521c9304f1f23c778506cd9a0ad005..24da5f7b7005fad2e2be60f5391d541abe915887 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -2477,11 +2477,12 @@ static void smlInsertCallback(void *param, void *res, int32_t code) { } else { pParam->request->body.resInfo.numOfRows += info->affectedRows; } + // unlock + taosThreadSpinUnlock(&pParam->lock); + if (pParam->cnt == pParam->total) { tsem_post(&pParam->sem); } - taosThreadSpinUnlock(&pParam->lock); - // unlock uDebug("SML:0x%" PRIx64 " insert finished, code: %d, rows: %d, total: %d", info->id, code, rows, info->affectedRows); info->cost.endTime = taosGetTimestampUs(); info->cost.code = code; diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index fa21f82d190569e1c6eb3b2642aeb7b63d4b66f9..7a800bd3349308d87ef4897e034b23330dabce0e 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -7,8 +7,8 @@ static int32_t stmtCreateRequest(STscStmt* pStmt) { int32_t code = 0; - - if (pStmt->exec.pRequest == NULL) { + + if (pStmt->exec.pRequest == NULL) { code = buildRequest(pStmt->taos->id, pStmt->sql.sqlStr, pStmt->sql.sqlLen, NULL, false, &pStmt->exec.pRequest); if (TSDB_CODE_SUCCESS == code) { pStmt->exec.pRequest->syncQuery = true; @@ -232,7 +232,7 @@ int32_t stmtParseSql(STscStmt* pStmt) { }; STMT_ERR_RET(stmtCreateRequest(pStmt)); - + STMT_ERR_RET(parseSql(pStmt->exec.pRequest, false, &pStmt->sql.pQuery, &stmtCb)); pStmt->bInfo.needParse = false; @@ -402,7 +402,7 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - tscDebug("reuse stmt block for tb %s in sqlBlock, suid:0x%" PRIx64 , pStmt->bInfo.tbFName, pStmt->bInfo.tbSuid); + tscDebug("reuse stmt block for tb %s in sqlBlock, suid:0x%" PRIx64, pStmt->bInfo.tbFName, pStmt->bInfo.tbSuid); return TSDB_CODE_SUCCESS; } @@ -600,8 +600,9 @@ int stmtSetTbTags(TAOS_STMT* stmt, TAOS_MULTI_BIND* tags) { } tscDebug("start to bind stmt tag values"); - STMT_ERR_RET(qBindStmtTagsValue(*pDataBlock, pStmt->bInfo.boundTags, pStmt->bInfo.tbSuid, pStmt->bInfo.stbFName, pStmt->bInfo.sname.tname, - tags, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen)); + STMT_ERR_RET(qBindStmtTagsValue(*pDataBlock, pStmt->bInfo.boundTags, pStmt->bInfo.tbSuid, pStmt->bInfo.stbFName, + pStmt->bInfo.sname.tname, tags, pStmt->exec.pRequest->msgBuf, + pStmt->exec.pRequest->msgBufLen)); return TSDB_CODE_SUCCESS; } diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index 66f992f05f94f1e583118044cea2271ec8fcd7ee..922cab23c89f1f0fce7b1e24eec6fdaf58255215 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -972,6 +972,8 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { req.topicNames = taosArrayInit(sz, sizeof(void*)); if (req.topicNames == NULL) goto FAIL; + tscDebug("call tmq subscribe, consumer: %ld, topic num %d", tmq->consumerId, sz); + for (int32_t i = 0; i < sz; i++) { char* topic = taosArrayGetP(container, i); @@ -1297,7 +1299,8 @@ int32_t tmqAskEpCb(void* param, SDataBuf* pMsg, int32_t code) { pParam->code = code; if (code != 0) { - tscError("consumer:%" PRId64 ", get topic endpoint error, not ready, wait:%d", tmq->consumerId, pParam->async); + tscError("consumer:%" PRId64 ", get topic endpoint error, not ready, wait:%d, code %x", tmq->consumerId, + pParam->async, code); goto END; } diff --git a/source/client/src/clientTmqConnector.c b/source/client/src/clientTmqConnector.c index 26bf55055f76eeade6a192e759560f21c0c2253d..6edf76124e5940b9120d9e8ccdd4c1c4ec537fcb 100644 --- a/source/client/src/clientTmqConnector.c +++ b/source/client/src/clientTmqConnector.c @@ -212,7 +212,8 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitAsync(JN tmq_commit_async(tmq, res, commit_cb, consumer); } -JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqUnsubscribeImp(JNIEnv *env, jobject jobj, jlong jtmq) { +JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqUnsubscribeImp(JNIEnv *env, jobject jobj, + jlong jtmq) { tmq_t *tmq = (tmq_t *)jtmq; if (tmq == NULL) { jniError("jobj:%p, tmq is closed", jobj); @@ -223,7 +224,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqUnsubscribeImp } JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqConsumerCloseImp(JNIEnv *env, jobject jobj, - jlong jtmq) { + jlong jtmq) { tmq_t *tmq = (tmq_t *)jtmq; if (tmq == NULL) { jniDebug("jobj:%p, tmq is closed", jobj); diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 4ea5443678d8b927f8df831874f32b20655cb7d0..21a52a4b57f9e7ba9cda24e8f9a08fdb53545b1c 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -13,12 +13,12 @@ * along with this program. If not, see . */ -#include #include +#include +#include "clientInt.h" #include "taoserror.h" #include "tglobal.h" #include "thash.h" -#include "clientInt.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wwrite-strings" @@ -26,8 +26,8 @@ #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wsign-compare" -#include "taos.h" #include "executor.h" +#include "taos.h" namespace { void showDB(TAOS* pConn) { @@ -50,17 +50,17 @@ void printResult(TAOS_RES* pRes) { int32_t numOfFields = taos_num_fields(pRes); int32_t n = 0; - char str[512] = {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)); +// 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)); } } @@ -102,17 +102,6 @@ void queryCallback(void* param, void* res, int32_t code) { taos_fetch_raw_block_a(res, fetchCallback, param); } -void queryCallback1(void* param, void* res, int32_t code) { - if (code != TSDB_CODE_SUCCESS) { - printf("failed to execute, reason:%s\n", taos_errstr(res)); - } - - taos_free_result(res); - - printf("exec query:\n"); - taos_query_a(param, "select * from tm1", queryCallback, param); -} - void createNewTable(TAOS* pConn, int32_t index) { char str[1024] = {0}; sprintf(str, "create table tu%d using st2 tags(%d)", index, index); @@ -123,16 +112,16 @@ void createNewTable(TAOS* pConn, int32_t index) { } taos_free_result(pRes); - for(int32_t i = 0; i < 3280; i += 20) { + for(int32_t i = 0; i < 10000; i += 20) { char sql[1024] = {0}; sprintf(sql, "insert into tu%d values(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)" "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)" "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)" - "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)", index, - i, i, i + 1, i + 1, i + 2, i + 2, i + 3, i + 3, i + 4, i + 4, i + 5, i + 5, i + 6, i + 6, i + 7, i + 7, - i + 8, i + 8, i + 9, i + 9, i + 10, i + 10, i + 11, i + 11, i + 12, i + 12, i + 13, i + 13, i + 14, i + 14, - i + 15, i + 15, i + 16, i + 16, i + 17, i + 17, i + 18, i + 18, i + 19, i + 19); + "(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)", + index, i, i, i + 1, i + 1, i + 2, i + 2, i + 3, i + 3, i + 4, i + 4, i + 5, i + 5, i + 6, i + 6, i + 7, + i + 7, i + 8, i + 8, i + 9, i + 9, i + 10, i + 10, i + 11, i + 11, i + 12, i + 12, i + 13, i + 13, i + 14, + i + 14, i + 15, i + 15, i + 16, i + 16, i + 17, i + 17, i + 18, i + 18, i + 19, i + 19); TAOS_RES* p = taos_query(pConn, sql); if (taos_errno(p) != 0) { printf("failed to insert data, reason:%s\n", taos_errstr(p)); @@ -141,16 +130,55 @@ void createNewTable(TAOS* pConn, int32_t index) { taos_free_result(p); } } + +void *queryThread(void *arg) { + TAOS* pConn = taos_connect("192.168.0.209", "root", "taosdata", NULL, 0); + if (pConn == NULL) { + printf("failed to connect to db, reason:%s", taos_errstr(pConn)); + return NULL; + } + + int64_t el = 0; + + for (int32_t i = 0; i < 5000000; ++i) { + int64_t st = taosGetTimestampUs(); + TAOS_RES* pRes = taos_query(pConn, + "SELECT _wstart as ts,max(usage_user) FROM benchmarkcpu.host_49 WHERE ts >= 1451618560000 AND ts < 1451622160000 INTERVAL(1m) ;"); + if (taos_errno(pRes) != 0) { + printf("failed, reason:%s\n", taos_errstr(pRes)); + } else { + printResult(pRes); + } + + taos_free_result(pRes); + el += (taosGetTimestampUs() - st); + if (i % 1000 == 0 && i != 0) { + printf("total:%d, avg time:%.2fms\n", i, el/(double)(i*1000)); + } + } + + taos_close(pConn); + return NULL; +} + +static int32_t numOfThreads = 1; } // namespace int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); + if (argc > 1) { + numOfThreads = atoi(argv[1]); + } + + numOfThreads = TMAX(numOfThreads, 1); + printf("the runing threads is:%d", numOfThreads); + return RUN_ALL_TESTS(); } TEST(testCase, driverInit_Test) { // taosInitGlobalCfg(); -// taos_init(); + // taos_init(); } TEST(testCase, connect_Test) { @@ -664,25 +692,25 @@ TEST(testCase, insert_test) { taos_free_result(pRes); taos_close(pConn); } -#endif TEST(testCase, projection_query_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); -// 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)); -// } -// taos_free_result(pRes); + // 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)); + // } + // taos_free_result(pRes); - TAOS_RES* pRes = taos_query(pConn, "use abc1"); + TAOS_RES* pRes = taos_query(pConn, "use benchmarkcpu"); taos_free_result(pRes); pRes = taos_query(pConn, "create stable st1 (ts timestamp, k int) tags(a int)"); if (taos_errno(pRes) != 0) { printf("failed to create table tu, reason:%s\n", taos_errstr(pRes)); } + taos_free_result(pRes); pRes = taos_query(pConn, "create stable st2 (ts timestamp, k int) tags(a int)"); @@ -697,31 +725,41 @@ TEST(testCase, projection_query_tables) { } taos_free_result(pRes); - for(int32_t i = 0; i < 2; ++i) { + for (int32_t i = 0; i < 2; ++i) { printf("create table :%d\n", i); createNewTable(pConn, i); } -// -// pRes = taos_query(pConn, "select * from tu"); -// 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); -// -// char str[512] = {0}; -// while ((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); -// } + // + // pRes = taos_query(pConn, "select * from tu"); + // 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); + // + // char str[512] = {0}; + // while ((pRow = taos_fetch_row(pRes)) != NULL) { + // int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + // printf("%s\n", str); + // } taos_free_result(pRes); taos_close(pConn); } +#endif + +TEST(testCase, tsbs_perf_test) { + TdThread qid[20] = {0}; + + for(int32_t i = 0; i < numOfThreads; ++i) { + taosThreadCreate(&qid[i], NULL, queryThread, NULL); + } + getchar(); +} #if 0 TEST(testCase, projection_query_stables) { @@ -860,5 +898,4 @@ TEST(testCase, update_test) { #endif - #pragma GCC diagnostic pop diff --git a/source/client/test/smlTest.cpp b/source/client/test/smlTest.cpp index b62238ccf26c991a516313270889a05a5b87d6ee..ab4442eca7abda74f851aedf2926cdb3f64ec7a7 100644 --- a/source/client/test/smlTest.cpp +++ b/source/client/test/smlTest.cpp @@ -42,9 +42,9 @@ TEST(testCase, smlParseInfluxString_Test) { // case 1 char *tmp = "\\,st,t1=3,t2=4,t3=t3 c1=3i64,c3=\"passit hello,c1=2\",c2=false,c4=4f64 1626006833639000000 ,32,c=3"; - char *sql = (char*)taosMemoryCalloc(256, 1); + char *sql = (char *)taosMemoryCalloc(256, 1); memcpy(sql, tmp, strlen(tmp) + 1); - int ret = smlParseInfluxString(sql, &elements, &msgBuf); + int ret = smlParseInfluxString(sql, &elements, &msgBuf); ASSERT_EQ(ret, 0); ASSERT_EQ(elements.measure, sql); ASSERT_EQ(elements.measureLen, strlen(",st")); @@ -136,83 +136,81 @@ TEST(testCase, smlParseInfluxString_Test) { } TEST(testCase, smlParseCols_Error_Test) { - const char *data[] = { - "c=\"89sd", // binary, nchar - "c=j\"89sd\"", - "c=\"89sd\"k", - "c=u", // bool - "c=truet", - "c=f64", // double - "c=8f64f", - "c=8ef64", - "c=f32", // float - "c=8f32f", - "c=8wef32", - "c=-3.402823466e+39f32", - "c=", // double - "c=8f", - "c=8we", - "c=i8", // tiny int - "c=-8i8f", - "c=8wei8", - "c=-999i8", - "c=u8", // u tiny int - "c=8fu8", - "c=8weu8", - "c=999u8", - "c=-8u8", - "c=i16", // small int - "c=8fi16u", - "c=8wei16", - "c=-67787i16", - "c=u16", // u small int - "c=8u16f", - "c=8weu16", - "c=-9u16", - "c=67787u16", - "c=i32", // int - "c=8i32f", - "c=8wei32", - "c=2147483649i32", - "c=u32", // u int - "c=8u32f", - "c=8weu32", - "c=-4u32", - "c=42949672958u32", - "c=i64", // big int - "c=8i64i", - "c=8wei64", - "c=-9223372036854775809i64", - "c=i", // big int - "c=8fi", - "c=8wei", - "c=9223372036854775808i", - "c=u64", // u big int - "c=8u64f", - "c=8weu64", - "c=-3.402823466e+39u64", - "c=-339u64", - "c=18446744073709551616u64", - "c=1,c=2", - "c=1=2" - }; + const char *data[] = {"c=\"89sd", // binary, nchar + "c=j\"89sd\"", + "c=\"89sd\"k", + "c=u", // bool + "c=truet", + "c=f64", // double + "c=8f64f", + "c=8ef64", + "c=f32", // float + "c=8f32f", + "c=8wef32", + "c=-3.402823466e+39f32", + "c=", // double + "c=8f", + "c=8we", + "c=i8", // tiny int + "c=-8i8f", + "c=8wei8", + "c=-999i8", + "c=u8", // u tiny int + "c=8fu8", + "c=8weu8", + "c=999u8", + "c=-8u8", + "c=i16", // small int + "c=8fi16u", + "c=8wei16", + "c=-67787i16", + "c=u16", // u small int + "c=8u16f", + "c=8weu16", + "c=-9u16", + "c=67787u16", + "c=i32", // int + "c=8i32f", + "c=8wei32", + "c=2147483649i32", + "c=u32", // u int + "c=8u32f", + "c=8weu32", + "c=-4u32", + "c=42949672958u32", + "c=i64", // big int + "c=8i64i", + "c=8wei64", + "c=-9223372036854775809i64", + "c=i", // big int + "c=8fi", + "c=8wei", + "c=9223372036854775808i", + "c=u64", // u big int + "c=8u64f", + "c=8weu64", + "c=-3.402823466e+39u64", + "c=-339u64", + "c=18446744073709551616u64", + "c=1,c=2", + "c=1=2"}; SHashObj *dumplicateKey = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); - for(int i = 0; i < sizeof(data)/sizeof(data[0]); i++){ + for (int i = 0; i < sizeof(data) / sizeof(data[0]); i++) { char msg[256] = {0}; SSmlMsgBuf msgBuf; msgBuf.buf = msg; msgBuf.len = 256; int32_t len = strlen(data[i]); - char *sql = (char*)taosMemoryCalloc(256, 1); + char *sql = (char *)taosMemoryCalloc(256, 1); memcpy(sql, data[i], len + 1); SArray *cols = taosArrayInit(8, POINTER_BYTES); int32_t ret = smlParseCols(sql, len, cols, NULL, false, dumplicateKey, &msgBuf); - printf("i:%d\n",i); + printf("i:%d\n", i); ASSERT_NE(ret, TSDB_CODE_SUCCESS); taosHashClear(dumplicateKey); taosMemoryFree(sql); - for(int j = 0; j < taosArrayGetSize(cols); j++){ + for (int j = 0; j < taosArrayGetSize(cols); j++) { void *kv = taosArrayGetP(cols, j); taosMemoryFree(kv); } @@ -232,7 +230,10 @@ TEST(testCase, smlParseCols_tag_Test) { SHashObj *dumplicateKey = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); const char *data = - "cbin=\"passit helloc\",cnch=L\"iisdfsf\",cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l\"iuwq\""; + "cbin=\"passit " + "helloc\",cnch=L\"iisdfsf\",cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=" + "898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_" + "=l\"iuwq\""; int32_t len = strlen(data); int32_t ret = smlParseCols(data, len, cols, NULL, true, dumplicateKey, &msgBuf); ASSERT_EQ(ret, TSDB_CODE_SUCCESS); @@ -255,7 +256,7 @@ TEST(testCase, smlParseCols_tag_Test) { ASSERT_EQ(kv->length, 7); ASSERT_EQ(strncasecmp(kv->value, "4.31f64", 7), 0); - for(int i = 0; i < size; i++){ + for (int i = 0; i < size; i++) { void *tmp = taosArrayGetP(cols, i); taosMemoryFree(tmp); } @@ -286,9 +287,13 @@ TEST(testCase, smlParseCols_Test) { SHashObj *dumplicateKey = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); - const char *data = "cb\\=in=\"pass\\,it hello,c=2\",cnch=L\"ii\\=sdfsf\",cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l\"iuwq\""; + const char *data = + "cb\\=in=\"pass\\,it " + "hello,c=2\",cnch=L\"ii\\=sdfsf\",cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=" + "233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t," + "cboolf=f,cnch_=l\"iuwq\""; int32_t len = strlen(data); - char *sql = (char*)taosMemoryCalloc(1024, 1); + char *sql = (char *)taosMemoryCalloc(1024, 1); memcpy(sql, data, len + 1); int32_t ret = smlParseCols(sql, len, cols, NULL, false, dumplicateKey, &msgBuf); ASSERT_EQ(ret, TSDB_CODE_SUCCESS); @@ -328,7 +333,7 @@ TEST(testCase, smlParseCols_Test) { ASSERT_EQ(kv->keyLen, 4); ASSERT_EQ(kv->type, TSDB_DATA_TYPE_DOUBLE); ASSERT_EQ(kv->length, 8); - //ASSERT_EQ(kv->d, 4.31); + // ASSERT_EQ(kv->d, 4.31); printf("4.31 = kv->d:%f\n", kv->d); taosMemoryFree(kv); @@ -338,7 +343,7 @@ TEST(testCase, smlParseCols_Test) { ASSERT_EQ(kv->keyLen, 5); ASSERT_EQ(kv->type, TSDB_DATA_TYPE_DOUBLE); ASSERT_EQ(kv->length, 8); - //ASSERT_EQ(kv->f, 8.32); + // ASSERT_EQ(kv->f, 8.32); printf("8.32 = kv->d:%f\n", kv->d); taosMemoryFree(kv); @@ -348,7 +353,7 @@ TEST(testCase, smlParseCols_Test) { ASSERT_EQ(kv->keyLen, 4); ASSERT_EQ(kv->type, TSDB_DATA_TYPE_FLOAT); ASSERT_EQ(kv->length, 4); - //ASSERT_EQ(kv->f, 8.23); + // ASSERT_EQ(kv->f, 8.23); printf("8.23 = kv->f:%f\n", kv->f); taosMemoryFree(kv); @@ -406,7 +411,6 @@ TEST(testCase, smlParseCols_Test) { ASSERT_EQ(kv->u, 12323); taosMemoryFree(kv); - // bigint kv = (SSmlKv *)taosArrayGetP(cols, 12); ASSERT_EQ(strncasecmp(kv->key, "ci64", 4), 0); @@ -443,7 +447,6 @@ TEST(testCase, smlParseCols_Test) { ASSERT_EQ(kv->i, true); taosMemoryFree(kv); - // bool kv = (SSmlKv *)taosArrayGetP(cols, 16); ASSERT_EQ(strncasecmp(kv->key, "cboolt", 6), 0); @@ -500,15 +503,15 @@ TEST(testCase, smlGetTimestampLen_Test) { } TEST(testCase, smlParseNumber_Test) { - SSmlKv kv = {0}; - char buf[64] = {0}; + SSmlKv kv = {0}; + char buf[64] = {0}; SSmlMsgBuf msg = {0}; msg.buf = buf; msg.len = 64; kv.value = "3.2e-900"; kv.length = 8; bool res = smlParseNumber(&kv, &msg); - printf("res:%d,v:%f, %f\n", res,kv.d, HUGE_VAL); + printf("res:%d,v:%f, %f\n", res, kv.d, HUGE_VAL); } TEST(testCase, smlParseTelnetLine_error_Test) { @@ -538,8 +541,8 @@ TEST(testCase, smlParseTelnetLine_error_Test) { "sys.procs.running 1479496100 42 host=web01=er", "sys.procs.running 1479496100 42 host= web01", }; - for(int i = 0; i < sizeof(sql)/sizeof(sql[0]); i++){ - int ret = smlParseTelnetLine(info, (void*)sql[i]); + for (int i = 0; i < sizeof(sql) / sizeof(sql[0]); i++) { + int ret = smlParseTelnetLine(info, (void *)sql[i]); ASSERT_NE(ret, 0); } @@ -550,16 +553,16 @@ TEST(testCase, smlParseTelnetLine_diff_type_Test) { SSmlHandle *info = smlBuildSmlInfo(NULL, NULL, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); ASSERT_NE(info, nullptr); - const char *sql[] = { - "sys.procs.running 1479496104000 42 host=web01", - "sys.procs.running 1479496104000 42u8 host=web01", - "appywjnuct 1626006833641 True id=\"appywjnuct_40601_49808_1\" t0=t t1=127i8 id=\"appywjnuct_40601_49808_2\" t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7=\"binaryTagValue\" t8=L\"ncharTagValue\"" - }; + const char *sql[] = {"sys.procs.running 1479496104000 42 host=web01", + "sys.procs.running 1479496104000 42u8 host=web01", + "appywjnuct 1626006833641 True id=\"appywjnuct_40601_49808_1\" t0=t t1=127i8 " + "id=\"appywjnuct_40601_49808_2\" t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 " + "t5=11.12345f32 t6=22.123456789f64 t7=\"binaryTagValue\" t8=L\"ncharTagValue\""}; int ret = TSDB_CODE_SUCCESS; - for(int i = 0; i < sizeof(sql)/sizeof(sql[0]); i++){ - ret = smlParseTelnetLine(info, (void*)sql[i]); - if(ret != TSDB_CODE_SUCCESS) break; + for (int i = 0; i < sizeof(sql) / sizeof(sql[0]); i++) { + ret = smlParseTelnetLine(info, (void *)sql[i]); + if (ret != TSDB_CODE_SUCCESS) break; } ASSERT_NE(ret, 0); smlDestroyInfo(info); @@ -613,8 +616,8 @@ TEST(testCase, smlParseTelnetLine_json_error_Test) { }; int ret = TSDB_CODE_SUCCESS; - for(int i = 0; i < sizeof(sql)/sizeof(sql[0]); i++){ - ret = smlParseTelnetLine(info, (void*)sql[i]); + for (int i = 0; i < sizeof(sql) / sizeof(sql[0]); i++) { + ret = smlParseTelnetLine(info, (void *)sql[i]); ASSERT_NE(ret, 0); } @@ -622,7 +625,6 @@ TEST(testCase, smlParseTelnetLine_json_error_Test) { } TEST(testCase, smlParseTelnetLine_diff_json_type1_Test) { - SSmlHandle *info = smlBuildSmlInfo(NULL, NULL, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); ASSERT_NE(info, nullptr); @@ -650,9 +652,9 @@ TEST(testCase, smlParseTelnetLine_diff_json_type1_Test) { }; int ret = TSDB_CODE_SUCCESS; - for(int i = 0; i < sizeof(sql)/sizeof(sql[0]); i++){ - ret = smlParseTelnetLine(info, (void*)sql[i]); - if(ret != TSDB_CODE_SUCCESS) break; + for (int i = 0; i < sizeof(sql) / sizeof(sql[0]); i++) { + ret = smlParseTelnetLine(info, (void *)sql[i]); + if (ret != TSDB_CODE_SUCCESS) break; } ASSERT_NE(ret, 0); smlDestroyInfo(info); @@ -685,9 +687,9 @@ TEST(testCase, smlParseTelnetLine_diff_json_type2_Test) { "]", }; int ret = TSDB_CODE_SUCCESS; - for(int i = 0; i < sizeof(sql)/sizeof(sql[0]); i++){ - ret = smlParseTelnetLine(info, (void*)sql[i]); - if(ret != TSDB_CODE_SUCCESS) break; + for (int i = 0; i < sizeof(sql) / sizeof(sql[0]); i++) { + ret = smlParseTelnetLine(info, (void *)sql[i]); + if (ret != TSDB_CODE_SUCCESS) break; } ASSERT_NE(ret, 0); smlDestroyInfo(info); @@ -698,45 +700,310 @@ TEST(testCase, sml_col_4096_Test) { ASSERT_NE(info, nullptr); const char *sql[] = { - "spgwgvldxv,id=spgwgvldxv_1,t0=f c0=t,c1=t,c2=t,c3=t,c4=t,c5=t,c6=t,c7=t,c8=t,c9=t,c10=t,c11=t,c12=t,c13=t,c14=t,c15=t,c16=t,c17=t,c18=t,c19=t,c20=t,c21=t,c22=t,c23=t,c24=t,c25=t,c26=t,c27=t,c28=t,c29=t,c30=t,c31=t,c32=t,c33=t,c34=t,c35=t,c36=t,c37=t,c38=t,c39=t,c40=t,c41=t,c42=t,c43=t,c44=t,c45=t,c46=t,c47=t,c48=t,c49=t,c50=t,c51=t,c52=t,c53=t,c54=t,c55=t,c56=t,c57=t,c58=t,c59=t,c60=t,c61=t,c62=t,c63=t,c64=t,c65=t,c66=t,c67=t,c68=t,c69=t,c70=t,c71=t,c72=t,c73=t,c74=t,c75=t,c76=t,c77=t,c78=t,c79=t,c80=t,c81=t,c82=t,c83=t,c84=t,c85=t,c86=t,c87=t,c88=t,c89=t,c90=t,c91=t,c92=t,c93=t,c94=t,c95=t,c96=t,c97=t,c98=t,c99=t,c100=t," - "c101=t,c102=t,c103=t,c104=t,c105=t,c106=t,c107=t,c108=t,c109=t,c110=t,c111=t,c112=t,c113=t,c114=t,c115=t,c116=t,c117=t,c118=t,c119=t,c120=t,c121=t,c122=t,c123=t,c124=t,c125=t,c126=t,c127=t,c128=t,c129=t,c130=t,c131=t,c132=t,c133=t,c134=t,c135=t,c136=t,c137=t,c138=t,c139=t,c140=t,c141=t,c142=t,c143=t,c144=t,c145=t,c146=t,c147=t,c148=t,c149=t,c150=t,c151=t,c152=t,c153=t,c154=t,c155=t,c156=t,c157=t,c158=t,c159=t,c160=t,c161=t,c162=t,c163=t,c164=t,c165=t,c166=t,c167=t,c168=t,c169=t,c170=t,c171=t,c172=t,c173=t,c174=t,c175=t,c176=t,c177=t,c178=t,c179=t,c180=t,c181=t,c182=t,c183=t,c184=t,c185=t,c186=t,c187=t,c188=t,c189=t," - "c190=t,c191=t,c192=t,c193=t,c194=t,c195=t,c196=t,c197=t,c198=t,c199=t,c200=t,c201=t,c202=t,c203=t,c204=t,c205=t,c206=t,c207=t,c208=t,c209=t,c210=t,c211=t,c212=t,c213=t,c214=t,c215=t,c216=t,c217=t,c218=t,c219=t,c220=t,c221=t,c222=t,c223=t,c224=t,c225=t,c226=t,c227=t,c228=t,c229=t,c230=t,c231=t,c232=t,c233=t,c234=t,c235=t,c236=t,c237=t,c238=t,c239=t,c240=t,c241=t,c242=t,c243=t,c244=t,c245=t,c246=t,c247=t,c248=t,c249=t,c250=t,c251=t,c252=t,c253=t,c254=t,c255=t,c256=t,c257=t,c258=t,c259=t,c260=t,c261=t,c262=t,c263=t,c264=t,c265=t,c266=t,c267=t,c268=t,c269=t,c270=t,c271=t,c272=t,c273=t,c274=t,c275=t,c276=t,c277=t,c278=t," - "c279=t,c280=t,c281=t,c282=t,c283=t,c284=t,c285=t,c286=t,c287=t,c288=t,c289=t,c290=t,c291=t,c292=t,c293=t,c294=t,c295=t,c296=t,c297=t,c298=t,c299=t,c300=t,c301=t,c302=t,c303=t,c304=t,c305=t,c306=t,c307=t,c308=t,c309=t,c310=t,c311=t,c312=t,c313=t,c314=t,c315=t,c316=t,c317=t,c318=t,c319=t,c320=t,c321=t,c322=t,c323=t,c324=t,c325=t,c326=t,c327=t,c328=t,c329=t,c330=t,c331=t,c332=t,c333=t,c334=t,c335=t,c336=t,c337=t,c338=t,c339=t,c340=t,c341=t,c342=t,c343=t,c344=t,c345=t,c346=t,c347=t,c348=t,c349=t,c350=t,c351=t,c352=t,c353=t,c354=t,c355=t,c356=t,c357=t,c358=t,c359=t,c360=t,c361=t,c362=t,c363=t,c364=t,c365=t,c366=t,c367=t,c368=t,c369=t,c370=t,c371=t,c372=t,c373=t,c374=t,c375=t,c376=t,c377=t,c378=t,c379=t,c380=t,c381=t,c382=t,c383=t,c384=t,c385=t,c386=t,c387=t,c388=t,c389=t,c390=t,c391=t,c392=t,c393=t,c394=t,c395=t,c396=t,c397=t,c398=t,c399=t,c400=t,c401=t,c402=t,c403=t,c404=t,c405=t,c406=t,c407=t,c408=t,c409=t,c410=t,c411=t,c412=t,c413=t,c414=t,c415=t,c416=t,c417=t,c418=t,c419=t,c420=t,c421=t,c422=t,c423=t,c424=t,c425=t,c426=t,c427=t,c428=t,c429=t,c430=t,c431=t,c432=t,c433=t,c434=t,c435=t,c436=t,c437=t,c438=t,c439=t,c440=t,c441=t,c442=t,c443=t,c444=t,c445=t,c446=t," - "c447=t,c448=t,c449=t,c450=t,c451=t,c452=t,c453=t,c454=t,c455=t,c456=t,c457=t,c458=t,c459=t,c460=t,c461=t,c462=t,c463=t,c464=t,c465=t,c466=t,c467=t,c468=t,c469=t,c470=t,c471=t,c472=t,c473=t,c474=t,c475=t,c476=t,c477=t,c478=t,c479=t,c480=t,c481=t,c482=t,c483=t,c484=t,c485=t,c486=t,c487=t,c488=t,c489=t,c490=t,c491=t,c492=t,c493=t,c494=t,c495=t,c496=t,c497=t,c498=t,c499=t,c500=t,c501=t,c502=t,c503=t,c504=t,c505=t,c506=t,c507=t,c508=t,c509=t,c510=t,c511=t,c512=t,c513=t,c514=t,c515=t,c516=t,c517=t,c518=t,c519=t,c520=t,c521=t,c522=t,c523=t,c524=t,c525=t,c526=t,c527=t,c528=t,c529=t,c530=t,c531=t,c532=t,c533=t,c534=t,c535=t,c536=t,c537=t,c538=t,c539=t,c540=t,c541=t,c542=t,c543=t,c544=t,c545=t,c546=t,c547=t,c548=t,c549=t,c550=t,c551=t,c552=t,c553=t,c554=t,c555=t,c556=t,c557=t,c558=t,c559=t,c560=t,c561=t,c562=t,c563=t,c564=t,c565=t,c566=t,c567=t,c568=t,c569=t,c570=t,c571=t,c572=t,c573=t,c574=t,c575=t,c576=t,c577=t,c578=t,c579=t,c580=t,c581=t,c582=t,c583=t,c584=t,c585=t,c586=t,c587=t,c588=t,c589=t,c590=t,c591=t,c592=t,c593=t,c594=t,c595=t,c596=t,c597=t,c598=t,c599=t,c600=t,c601=t,c602=t,c603=t,c604=t,c605=t,c606=t,c607=t,c608=t,c609=t,c610=t,c611=t,c612=t,c613=t,c614=t," - "c615=t,c616=t,c617=t,c618=t,c619=t,c620=t,c621=t,c622=t,c623=t,c624=t,c625=t,c626=t,c627=t,c628=t,c629=t,c630=t,c631=t,c632=t,c633=t,c634=t,c635=t,c636=t,c637=t,c638=t,c639=t,c640=t,c641=t,c642=t,c643=t,c644=t,c645=t,c646=t,c647=t,c648=t,c649=t,c650=t,c651=t,c652=t,c653=t,c654=t,c655=t,c656=t,c657=t,c658=t,c659=t,c660=t,c661=t,c662=t,c663=t,c664=t,c665=t,c666=t,c667=t,c668=t,c669=t,c670=t,c671=t,c672=t,c673=t,c674=t,c675=t,c676=t,c677=t,c678=t,c679=t,c680=t,c681=t,c682=t,c683=t,c684=t,c685=t,c686=t,c687=t,c688=t,c689=t,c690=t,c691=t,c692=t,c693=t,c694=t,c695=t,c696=t,c697=t,c698=t,c699=t,c700=t,c701=t,c702=t,c703=t,c704=t,c705=t,c706=t,c707=t,c708=t,c709=t,c710=t,c711=t,c712=t,c713=t,c714=t,c715=t,c716=t,c717=t,c718=t,c719=t,c720=t,c721=t,c722=t,c723=t,c724=t,c725=t,c726=t,c727=t,c728=t,c729=t,c730=t,c731=t,c732=t,c733=t,c734=t,c735=t,c736=t,c737=t,c738=t,c739=t,c740=t,c741=t,c742=t,c743=t,c744=t,c745=t,c746=t,c747=t,c748=t,c749=t,c750=t,c751=t,c752=t,c753=t,c754=t,c755=t,c756=t,c757=t,c758=t,c759=t,c760=t,c761=t,c762=t,c763=t,c764=t,c765=t,c766=t,c767=t,c768=t,c769=t,c770=t,c771=t,c772=t,c773=t,c774=t,c775=t,c776=t,c777=t,c778=t,c779=t,c780=t,c781=t,c782=t," - "c783=t,c784=t,c785=t,c786=t,c787=t,c788=t,c789=t,c790=t,c791=t,c792=t,c793=t,c794=t,c795=t,c796=t,c797=t,c798=t,c799=t,c800=t,c801=t,c802=t,c803=t,c804=t,c805=t,c806=t,c807=t,c808=t,c809=t,c810=t,c811=t,c812=t,c813=t," - "c814=t,c815=t,c816=t,c817=t,c818=t,c819=t,c820=t,c821=t,c822=t,c823=t,c824=t,c825=t,c826=t,c827=t,c828=t,c829=t,c830=t,c831=t,c832=t,c833=t,c834=t,c835=t,c836=t,c837=t,c838=t,c839=t,c840=t,c841=t,c842=t,c843=t,c844=t,c845=t,c846=t,c847=t,c848=t,c849=t,c850=t,c851=t,c852=t,c853=t,c854=t,c855=t,c856=t,c857=t,c858=t,c859=t,c860=t,c861=t,c862=t," - "c863=t,c864=t,c865=t,c866=t,c867=t,c868=t,c869=t,c870=t,c871=t,c872=t,c873=t,c874=t,c875=t,c876=t,c877=t,c878=t,c879=t,c880=t,c881=t,c882=t,c883=t,c884=t,c885=t,c886=t,c887=t,c888=t,c889=t,c890=t,c891=t,c892=t,c893=t,c894=t,c895=t,c896=t,c897=t,c898=t,c899=t,c900=t,c901=t,c902=t,c903=t,c904=t,c905=t,c906=t,c907=t,c908=t,c909=t,c910=t,c911=t,c912=t,c913=t,c914=t,c915=t,c916=t,c917=t,c918=t,c919=t,c920=t,c921=t,c922=t,c923=t,c924=t,c925=t,c926=t,c927=t,c928=t,c929=t,c930=t,c931=t,c932=t,c933=t,c934=t,c935=t,c936=t,c937=t,c938=t,c939=t,c940=t,c941=t,c942=t,c943=t,c944=t,c945=t,c946=t,c947=t,c948=t,c949=t,c950=t,c951=t,c952=t,c953=t,c954=t,c955=t,c956=t,c957=t,c958=t,c959=t,c960=t,c961=t,c962=t,c963=t,c964=t,c965=t,c966=t,c967=t,c968=t,c969=t,c970=t,c971=t,c972=t,c973=t,c974=t,c975=t,c976=t,c977=t,c978=t,c979=t,c980=t,c981=t,c982=t,c983=t,c984=t,c985=t,c986=t,c987=t,c988=t,c989=t,c990=t,c991=t,c992=t,c993=t,c994=t,c995=t,c996=t,c997=t,c998=t,c999=t,c1000=t,c1001=t,c1002=t,c1003=t,c1004=t,c1005=t,c1006=t,c1007=t,c1008=t,c1009=t,c1010=t,c1011=t,c1012=t,c1013=t,c1014=t,c1015=t,c1016=t,c1017=t,c1018=t,c1019=t,c1020=t,c1021=t,c1022=t,c1023=t,c1024=t,c1025=t,c1026=t," - "c1027=t,c1028=t,c1029=t,c1030=t,c1031=t,c1032=t,c1033=t,c1034=t,c1035=t,c1036=t,c1037=t,c1038=t,c1039=t,c1040=t,c1041=t,c1042=t,c1043=t,c1044=t,c1045=t,c1046=t,c1047=t,c1048=t,c1049=t,c1050=t,c1051=t,c1052=t,c1053=t,c1054=t,c1055=t,c1056=t,c1057=t,c1058=t,c1059=t,c1060=t,c1061=t,c1062=t,c1063=t,c1064=t,c1065=t,c1066=t,c1067=t,c1068=t,c1069=t,c1070=t,c1071=t,c1072=t,c1073=t,c1074=t,c1075=t,c1076=t,c1077=t,c1078=t,c1079=t,c1080=t,c1081=t,c1082=t,c1083=t,c1084=t,c1085=t,c1086=t,c1087=t,c1088=t,c1089=t,c1090=t,c1091=t,c1092=t,c1093=t,c1094=t,c1095=t,c1096=t,c1097=t,c1098=t,c1099=t,c1100=t,c1101=t,c1102=t,c1103=t,c1104=t,c1105=t,c1106=t,c1107=t,c1108=t,c1109=t,c1110=t,c1111=t,c1112=t,c1113=t,c1114=t,c1115=t,c1116=t,c1117=t,c1118=t,c1119=t,c1120=t,c1121=t,c1122=t,c1123=t,c1124=t,c1125=t,c1126=t,c1127=t,c1128=t,c1129=t,c1130=t,c1131=t,c1132=t,c1133=t,c1134=t,c1135=t,c1136=t,c1137=t,c1138=t,c1139=t,c1140=t,c1141=t,c1142=t,c1143=t,c1144=t,c1145=t,c1146=t,c1147=t,c1148=t,c1149=t,c1150=t,c1151=t,c1152=t,c1153=t,c1154=t,c1155=t,c1156=t,c1157=t,c1158=t,c1159=t,c1160=t,c1161=t,c1162=t,c1163=t,c1164=t,c1165=t,c1166=t,c1167=t,c1168=t,c1169=t,c1170=t,c1171=t,c1172=t,c1173=t," - "c1174=t,c1175=t,c1176=t,c1177=t,c1178=t,c1179=t,c1180=t,c1181=t,c1182=t,c1183=t,c1184=t,c1185=t,c1186=t,c1187=t,c1188=t,c1189=t,c1190=t,c1191=t,c1192=t,c1193=t,c1194=t,c1195=t,c1196=t,c1197=t,c1198=t,c1199=t,c1200=t,c1201=t,c1202=t,c1203=t,c1204=t,c1205=t,c1206=t,c1207=t,c1208=t,c1209=t,c1210=t,c1211=t,c1212=t,c1213=t,c1214=t,c1215=t,c1216=t,c1217=t,c1218=t,c1219=t,c1220=t,c1221=t,c1222=t,c1223=t,c1224=t,c1225=t,c1226=t,c1227=t,c1228=t,c1229=t,c1230=t,c1231=t,c1232=t,c1233=t,c1234=t,c1235=t,c1236=t,c1237=t,c1238=t,c1239=t,c1240=t,c1241=t,c1242=t,c1243=t,c1244=t,c1245=t,c1246=t,c1247=t,c1248=t,c1249=t,c1250=t,c1251=t,c1252=t,c1253=t,c1254=t,c1255=t,c1256=t,c1257=t,c1258=t,c1259=t,c1260=t,c1261=t,c1262=t,c1263=t,c1264=t,c1265=t,c1266=t,c1267=t,c1268=t,c1269=t,c1270=t,c1271=t,c1272=t,c1273=t,c1274=t,c1275=t,c1276=t,c1277=t,c1278=t,c1279=t,c1280=t,c1281=t,c1282=t,c1283=t,c1284=t,c1285=t,c1286=t,c1287=t,c1288=t,c1289=t,c1290=t,c1291=t,c1292=t,c1293=t,c1294=t,c1295=t,c1296=t,c1297=t,c1298=t,c1299=t,c1300=t,c1301=t,c1302=t,c1303=t,c1304=t,c1305=t,c1306=t,c1307=t,c1308=t,c1309=t,c1310=t,c1311=t,c1312=t,c1313=t,c1314=t,c1315=t,c1316=t,c1317=t,c1318=t,c1319=t,c1320=t," - "c1321=t,c1322=t,c1323=t,c1324=t,c1325=t,c1326=t,c1327=t,c1328=t,c1329=t,c1330=t,c1331=t,c1332=t,c1333=t,c1334=t,c1335=t,c1336=t,c1337=t,c1338=t,c1339=t,c1340=t,c1341=t,c1342=t,c1343=t,c1344=t,c1345=t,c1346=t,c1347=t," - "c1348=t,c1349=t,c1350=t,c1351=t,c1352=t,c1353=t,c1354=t,c1355=t,c1356=t,c1357=t,c1358=t,c1359=t,c1360=t,c1361=t,c1362=t,c1363=t,c1364=t,c1365=t,c1366=t,c1367=t,c1368=t,c1369=t,c1370=t,c1371=t,c1372=t,c1373=t,c1374=t,c1375=t,c1376=t,c1377=t,c1378=t,c1379=t,c1380=t,c1381=t,c1382=t,c1383=t,c1384=t,c1385=t,c1386=t,c1387=t,c1388=t,c1389=t,c1390=t,c1391=t,c1392=t,c1393=t,c1394=t,c1395=t,c1396=t,c1397=t,c1398=t,c1399=t,c1400=t,c1401=t,c1402=t,c1403=t,c1404=t,c1405=t,c1406=t,c1407=t,c1408=t,c1409=t,c1410=t,c1411=t,c1412=t,c1413=t,c1414=t,c1415=t,c1416=t,c1417=t,c1418=t,c1419=t,c1420=t,c1421=t,c1422=t,c1423=t,c1424=t,c1425=t,c1426=t,c1427=t,c1428=t,c1429=t,c1430=t,c1431=t,c1432=t,c1433=t,c1434=t,c1435=t,c1436=t,c1437=t,c1438=t,c1439=t,c1440=t,c1441=t,c1442=t,c1443=t,c1444=t,c1445=t,c1446=t,c1447=t,c1448=t,c1449=t,c1450=t,c1451=t,c1452=t,c1453=t,c1454=t,c1455=t,c1456=t,c1457=t,c1458=t,c1459=t,c1460=t,c1461=t,c1462=t,c1463=t,c1464=t,c1465=t,c1466=t,c1467=t,c1468=t,c1469=t,c1470=t,c1471=t,c1472=t,c1473=t,c1474=t,c1475=t,c1476=t,c1477=t,c1478=t,c1479=t,c1480=t,c1481=t,c1482=t,c1483=t,c1484=t,c1485=t,c1486=t,c1487=t,c1488=t,c1489=t,c1490=t,c1491=t,c1492=t,c1493=t,c1494=t," - "c1495=t,c1496=t,c1497=t,c1498=t,c1499=t,c1500=t,c1501=t,c1502=t,c1503=t,c1504=t,c1505=t,c1506=t,c1507=t,c1508=t,c1509=t,c1510=t,c1511=t,c1512=t,c1513=t,c1514=t,c1515=t,c1516=t,c1517=t,c1518=t,c1519=t,c1520=t,c1521=t,c1522=t,c1523=t,c1524=t,c1525=t,c1526=t,c1527=t,c1528=t,c1529=t,c1530=t,c1531=t,c1532=t,c1533=t,c1534=t,c1535=t,c1536=t,c1537=t,c1538=t,c1539=t,c1540=t,c1541=t,c1542=t,c1543=t,c1544=t,c1545=t,c1546=t,c1547=t,c1548=t,c1549=t,c1550=t,c1551=t,c1552=t,c1553=t,c1554=t,c1555=t,c1556=t,c1557=t,c1558=t,c1559=t,c1560=t,c1561=t,c1562=t,c1563=t,c1564=t,c1565=t,c1566=t,c1567=t,c1568=t,c1569=t,c1570=t,c1571=t,c1572=t,c1573=t,c1574=t,c1575=t,c1576=t,c1577=t,c1578=t,c1579=t,c1580=t,c1581=t,c1582=t,c1583=t,c1584=t,c1585=t,c1586=t,c1587=t,c1588=t,c1589=t,c1590=t,c1591=t,c1592=t,c1593=t,c1594=t,c1595=t,c1596=t,c1597=t,c1598=t,c1599=t,c1600=t,c1601=t,c1602=t,c1603=t,c1604=t,c1605=t,c1606=t,c1607=t,c1608=t,c1609=t,c1610=t,c1611=t,c1612=t,c1613=t,c1614=t,c1615=t,c1616=t,c1617=t,c1618=t,c1619=t,c1620=t,c1621=t,c1622=t,c1623=t,c1624=t,c1625=t,c1626=t,c1627=t,c1628=t,c1629=t,c1630=t,c1631=t,c1632=t,c1633=t,c1634=t,c1635=t,c1636=t,c1637=t,c1638=t,c1639=t,c1640=t,c1641=t," - "c1642=t,c1643=t,c1644=t,c1645=t,c1646=t,c1647=t,c1648=t,c1649=t,c1650=t,c1651=t,c1652=t,c1653=t,c1654=t,c1655=t,c1656=t,c1657=t,c1658=t,c1659=t,c1660=t,c1661=t,c1662=t,c1663=t,c1664=t,c1665=t,c1666=t,c1667=t,c1668=t,c1669=t,c1670=t,c1671=t,c1672=t,c1673=t,c1674=t,c1675=t,c1676=t,c1677=t,c1678=t,c1679=t,c1680=t,c1681=t,c1682=t,c1683=t,c1684=t,c1685=t,c1686=t,c1687=t,c1688=t,c1689=t,c1690=t,c1691=t,c1692=t,c1693=t,c1694=t,c1695=t,c1696=t,c1697=t,c1698=t,c1699=t,c1700=t,c1701=t,c1702=t,c1703=t,c1704=t,c1705=t,c1706=t,c1707=t,c1708=t,c1709=t,c1710=t,c1711=t,c1712=t,c1713=t,c1714=t,c1715=t,c1716=t,c1717=t,c1718=t,c1719=t,c1720=t,c1721=t,c1722=t,c1723=t,c1724=t,c1725=t,c1726=t,c1727=t,c1728=t,c1729=t,c1730=t,c1731=t,c1732=t,c1733=t,c1734=t,c1735=t,c1736=t,c1737=t,c1738=t,c1739=t,c1740=t,c1741=t,c1742=t,c1743=t,c1744=t,c1745=t,c1746=t,c1747=t,c1748=t,c1749=t,c1750=t,c1751=t,c1752=t,c1753=t,c1754=t,c1755=t,c1756=t,c1757=t,c1758=t,c1759=t,c1760=t,c1761=t,c1762=t,c1763=t,c1764=t,c1765=t,c1766=t,c1767=t,c1768=t,c1769=t,c1770=t,c1771=t,c1772=t,c1773=t,c1774=t,c1775=t,c1776=t,c1777=t,c1778=t,c1779=t,c1780=t,c1781=t,c1782=t,c1783=t,c1784=t,c1785=t,c1786=t,c1787=t,c1788=t," - "c1789=t,c1790=t,c1791=t,c1792=t,c1793=t,c1794=t,c1795=t,c1796=t,c1797=t,c1798=t,c1799=t,c1800=t,c1801=t,c1802=t,c1803=t,c1804=t,c1805=t,c1806=t,c1807=t,c1808=t,c1809=t,c1810=t,c1811=t,c1812=t,c1813=t,c1814=t,c1815=t," - "c1816=t,c1817=t,c1818=t,c1819=t,c1820=t,c1821=t,c1822=t,c1823=t,c1824=t,c1825=t,c1826=t,c1827=t,c1828=t,c1829=t,c1830=t,c1831=t,c1832=t,c1833=t,c1834=t,c1835=t,c1836=t,c1837=t,c1838=t,c1839=t,c1840=t,c1841=t,c1842=t,c1843=t,c1844=t,c1845=t,c1846=t,c1847=t,c1848=t,c1849=t,c1850=t,c1851=t,c1852=t,c1853=t,c1854=t,c1855=t,c1856=t,c1857=t,c1858=t,c1859=t,c1860=t,c1861=t,c1862=t,c1863=t,c1864=t,c1865=t,c1866=t,c1867=t,c1868=t,c1869=t,c1870=t,c1871=t,c1872=t,c1873=t,c1874=t,c1875=t,c1876=t,c1877=t,c1878=t,c1879=t,c1880=t,c1881=t,c1882=t,c1883=t,c1884=t,c1885=t,c1886=t,c1887=t,c1888=t,c1889=t,c1890=t,c1891=t,c1892=t,c1893=t,c1894=t,c1895=t,c1896=t,c1897=t,c1898=t,c1899=t,c1900=t,c1901=t,c1902=t,c1903=t,c1904=t,c1905=t,c1906=t,c1907=t,c1908=t,c1909=t,c1910=t,c1911=t,c1912=t,c1913=t,c1914=t,c1915=t,c1916=t,c1917=t,c1918=t,c1919=t,c1920=t,c1921=t,c1922=t,c1923=t,c1924=t,c1925=t,c1926=t,c1927=t,c1928=t,c1929=t,c1930=t,c1931=t,c1932=t,c1933=t,c1934=t,c1935=t,c1936=t,c1937=t,c1938=t,c1939=t,c1940=t,c1941=t,c1942=t,c1943=t,c1944=t,c1945=t,c1946=t,c1947=t,c1948=t,c1949=t,c1950=t,c1951=t,c1952=t,c1953=t,c1954=t,c1955=t,c1956=t,c1957=t,c1958=t,c1959=t,c1960=t,c1961=t,c1962=t," - "c1963=t,c1964=t,c1965=t,c1966=t,c1967=t,c1968=t,c1969=t,c1970=t,c1971=t,c1972=t,c1973=t,c1974=t,c1975=t,c1976=t,c1977=t,c1978=t,c1979=t,c1980=t,c1981=t,c1982=t,c1983=t,c1984=t,c1985=t,c1986=t,c1987=t,c1988=t,c1989=t,c1990=t,c1991=t,c1992=t,c1993=t,c1994=t,c1995=t,c1996=t,c1997=t,c1998=t,c1999=t,c2000=t,c2001=t,c2002=t,c2003=t,c2004=t,c2005=t,c2006=t,c2007=t,c2008=t,c2009=t,c2010=t,c2011=t,c2012=t,c2013=t,c2014=t,c2015=t,c2016=t,c2017=t,c2018=t,c2019=t,c2020=t,c2021=t,c2022=t,c2023=t,c2024=t,c2025=t,c2026=t,c2027=t,c2028=t,c2029=t,c2030=t,c2031=t,c2032=t,c2033=t,c2034=t,c2035=t,c2036=t,c2037=t,c2038=t,c2039=t,c2040=t,c2041=t,c2042=t,c2043=t,c2044=t,c2045=t,c2046=t,c2047=t,c2048=t,c2049=t,c2050=t,c2051=t,c2052=t,c2053=t,c2054=t,c2055=t,c2056=t,c2057=t,c2058=t,c2059=t,c2060=t,c2061=t,c2062=t,c2063=t,c2064=t,c2065=t,c2066=t,c2067=t,c2068=t,c2069=t,c2070=t,c2071=t,c2072=t,c2073=t,c2074=t,c2075=t,c2076=t,c2077=t,c2078=t,c2079=t,c2080=t,c2081=t,c2082=t,c2083=t,c2084=t,c2085=t,c2086=t,c2087=t,c2088=t,c2089=t,c2090=t,c2091=t,c2092=t,c2093=t,c2094=t,c2095=t,c2096=t,c2097=t,c2098=t,c2099=t,c2100=t,c2101=t,c2102=t,c2103=t,c2104=t,c2105=t,c2106=t,c2107=t,c2108=t,c2109=t," - "c2110=t,c2111=t,c2112=t,c2113=t,c2114=t,c2115=t,c2116=t,c2117=t,c2118=t,c2119=t,c2120=t,c2121=t,c2122=t,c2123=t,c2124=t,c2125=t,c2126=t,c2127=t,c2128=t,c2129=t,c2130=t,c2131=t,c2132=t,c2133=t,c2134=t,c2135=t,c2136=t,c2137=t,c2138=t,c2139=t,c2140=t,c2141=t,c2142=t,c2143=t,c2144=t,c2145=t,c2146=t,c2147=t,c2148=t,c2149=t,c2150=t,c2151=t,c2152=t,c2153=t,c2154=t,c2155=t,c2156=t,c2157=t,c2158=t,c2159=t,c2160=t,c2161=t,c2162=t,c2163=t,c2164=t,c2165=t,c2166=t,c2167=t,c2168=t,c2169=t,c2170=t,c2171=t,c2172=t,c2173=t,c2174=t,c2175=t,c2176=t,c2177=t,c2178=t,c2179=t,c2180=t,c2181=t,c2182=t,c2183=t,c2184=t,c2185=t,c2186=t,c2187=t,c2188=t,c2189=t,c2190=t,c2191=t,c2192=t,c2193=t,c2194=t,c2195=t,c2196=t,c2197=t,c2198=t,c2199=t,c2200=t,c2201=t,c2202=t,c2203=t,c2204=t,c2205=t,c2206=t,c2207=t,c2208=t,c2209=t,c2210=t,c2211=t,c2212=t,c2213=t,c2214=t,c2215=t,c2216=t,c2217=t,c2218=t,c2219=t,c2220=t,c2221=t,c2222=t,c2223=t,c2224=t,c2225=t,c2226=t,c2227=t,c2228=t,c2229=t,c2230=t,c2231=t,c2232=t,c2233=t,c2234=t,c2235=t,c2236=t,c2237=t,c2238=t,c2239=t,c2240=t,c2241=t,c2242=t,c2243=t,c2244=t,c2245=t,c2246=t,c2247=t,c2248=t,c2249=t,c2250=t,c2251=t,c2252=t,c2253=t,c2254=t,c2255=t,c2256=t," - "c2257=t,c2258=t,c2259=t,c2260=t,c2261=t,c2262=t,c2263=t,c2264=t,c2265=t,c2266=t,c2267=t,c2268=t,c2269=t,c2270=t,c2271=t,c2272=t,c2273=t,c2274=t,c2275=t,c2276=t,c2277=t,c2278=t,c2279=t,c2280=t,c2281=t,c2282=t,c2283=t," - "c2284=t,c2285=t,c2286=t,c2287=t,c2288=t,c2289=t,c2290=t,c2291=t,c2292=t,c2293=t,c2294=t,c2295=t,c2296=t,c2297=t,c2298=t,c2299=t,c2300=t,c2301=t,c2302=t,c2303=t,c2304=t,c2305=t,c2306=t,c2307=t,c2308=t,c2309=t,c2310=t,c2311=t,c2312=t,c2313=t,c2314=t,c2315=t,c2316=t,c2317=t,c2318=t,c2319=t,c2320=t,c2321=t,c2322=t,c2323=t,c2324=t,c2325=t,c2326=t,c2327=t,c2328=t,c2329=t,c2330=t,c2331=t,c2332=t,c2333=t,c2334=t,c2335=t,c2336=t,c2337=t,c2338=t,c2339=t,c2340=t,c2341=t,c2342=t,c2343=t,c2344=t,c2345=t,c2346=t,c2347=t,c2348=t,c2349=t,c2350=t,c2351=t,c2352=t,c2353=t,c2354=t,c2355=t,c2356=t,c2357=t,c2358=t,c2359=t,c2360=t,c2361=t,c2362=t,c2363=t,c2364=t,c2365=t,c2366=t,c2367=t,c2368=t,c2369=t,c2370=t,c2371=t,c2372=t,c2373=t,c2374=t,c2375=t,c2376=t,c2377=t,c2378=t,c2379=t,c2380=t,c2381=t,c2382=t,c2383=t,c2384=t,c2385=t,c2386=t,c2387=t,c2388=t,c2389=t,c2390=t,c2391=t,c2392=t,c2393=t,c2394=t,c2395=t,c2396=t,c2397=t,c2398=t,c2399=t,c2400=t,c2401=t,c2402=t,c2403=t,c2404=t,c2405=t,c2406=t,c2407=t,c2408=t,c2409=t,c2410=t,c2411=t,c2412=t,c2413=t,c2414=t,c2415=t,c2416=t,c2417=t,c2418=t,c2419=t,c2420=t,c2421=t,c2422=t,c2423=t,c2424=t,c2425=t,c2426=t,c2427=t,c2428=t,c2429=t,c2430=t," - "c2431=t,c2432=t,c2433=t,c2434=t,c2435=t,c2436=t,c2437=t,c2438=t,c2439=t,c2440=t,c2441=t,c2442=t,c2443=t,c2444=t,c2445=t,c2446=t,c2447=t,c2448=t,c2449=t,c2450=t,c2451=t,c2452=t,c2453=t,c2454=t,c2455=t,c2456=t,c2457=t,c2458=t,c2459=t,c2460=t,c2461=t,c2462=t,c2463=t,c2464=t,c2465=t,c2466=t,c2467=t,c2468=t,c2469=t,c2470=t,c2471=t,c2472=t,c2473=t,c2474=t,c2475=t,c2476=t,c2477=t,c2478=t,c2479=t,c2480=t,c2481=t,c2482=t,c2483=t,c2484=t,c2485=t,c2486=t,c2487=t,c2488=t,c2489=t,c2490=t,c2491=t,c2492=t,c2493=t,c2494=t,c2495=t,c2496=t,c2497=t,c2498=t,c2499=t,c2500=t,c2501=t,c2502=t,c2503=t,c2504=t,c2505=t,c2506=t,c2507=t,c2508=t,c2509=t,c2510=t,c2511=t,c2512=t,c2513=t,c2514=t,c2515=t,c2516=t,c2517=t,c2518=t,c2519=t,c2520=t,c2521=t,c2522=t,c2523=t,c2524=t,c2525=t,c2526=t,c2527=t,c2528=t,c2529=t,c2530=t,c2531=t,c2532=t,c2533=t,c2534=t,c2535=t,c2536=t,c2537=t,c2538=t,c2539=t,c2540=t,c2541=t,c2542=t,c2543=t,c2544=t,c2545=t,c2546=t,c2547=t,c2548=t,c2549=t,c2550=t,c2551=t,c2552=t,c2553=t,c2554=t,c2555=t,c2556=t,c2557=t,c2558=t,c2559=t,c2560=t,c2561=t,c2562=t,c2563=t,c2564=t,c2565=t,c2566=t,c2567=t,c2568=t,c2569=t,c2570=t,c2571=t,c2572=t,c2573=t,c2574=t,c2575=t,c2576=t,c2577=t," - "c2578=t,c2579=t,c2580=t,c2581=t,c2582=t,c2583=t,c2584=t,c2585=t,c2586=t,c2587=t,c2588=t,c2589=t,c2590=t,c2591=t,c2592=t,c2593=t,c2594=t,c2595=t,c2596=t,c2597=t,c2598=t,c2599=t,c2600=t,c2601=t,c2602=t,c2603=t,c2604=t,c2605=t,c2606=t,c2607=t,c2608=t,c2609=t,c2610=t,c2611=t,c2612=t,c2613=t,c2614=t,c2615=t,c2616=t,c2617=t,c2618=t,c2619=t,c2620=t,c2621=t,c2622=t,c2623=t,c2624=t,c2625=t,c2626=t,c2627=t,c2628=t,c2629=t,c2630=t,c2631=t,c2632=t,c2633=t,c2634=t,c2635=t,c2636=t,c2637=t,c2638=t,c2639=t,c2640=t,c2641=t,c2642=t,c2643=t,c2644=t,c2645=t,c2646=t,c2647=t,c2648=t,c2649=t,c2650=t,c2651=t,c2652=t,c2653=t,c2654=t,c2655=t,c2656=t,c2657=t,c2658=t,c2659=t,c2660=t,c2661=t,c2662=t,c2663=t,c2664=t,c2665=t,c2666=t,c2667=t,c2668=t,c2669=t,c2670=t,c2671=t,c2672=t,c2673=t,c2674=t,c2675=t,c2676=t,c2677=t,c2678=t,c2679=t,c2680=t,c2681=t,c2682=t,c2683=t,c2684=t,c2685=t,c2686=t,c2687=t,c2688=t,c2689=t,c2690=t,c2691=t,c2692=t,c2693=t,c2694=t,c2695=t,c2696=t,c2697=t,c2698=t,c2699=t,c2700=t,c2701=t,c2702=t,c2703=t,c2704=t,c2705=t,c2706=t,c2707=t,c2708=t,c2709=t,c2710=t,c2711=t,c2712=t,c2713=t,c2714=t,c2715=t,c2716=t,c2717=t,c2718=t,c2719=t,c2720=t,c2721=t,c2722=t,c2723=t,c2724=t," - "c2725=t,c2726=t,c2727=t,c2728=t,c2729=t,c2730=t,c2731=t,c2732=t,c2733=t,c2734=t,c2735=t,c2736=t,c2737=t,c2738=t,c2739=t,c2740=t,c2741=t,c2742=t,c2743=t,c2744=t,c2745=t,c2746=t,c2747=t,c2748=t,c2749=t,c2750=t,c2751=t,c2752=t,c2753=t,c2754=t,c2755=t,c2756=t,c2757=t,c2758=t,c2759=t,c2760=t,c2761=t,c2762=t,c2763=t,c2764=t,c2765=t,c2766=t,c2767=t,c2768=t,c2769=t,c2770=t,c2771=t,c2772=t,c2773=t,c2774=t,c2775=t,c2776=t,c2777=t,c2778=t,c2779=t,c2780=t,c2781=t,c2782=t,c2783=t,c2784=t,c2785=t,c2786=t,c2787=t,c2788=t,c2789=t,c2790=t,c2791=t,c2792=t,c2793=t,c2794=t,c2795=t,c2796=t,c2797=t,c2798=t,c2799=t,c2800=t,c2801=t,c2802=t,c2803=t,c2804=t,c2805=t,c2806=t,c2807=t,c2808=t,c2809=t,c2810=t,c2811=t,c2812=t,c2813=t,c2814=t,c2815=t,c2816=t,c2817=t,c2818=t,c2819=t,c2820=t,c2821=t,c2822=t,c2823=t,c2824=t,c2825=t,c2826=t,c2827=t,c2828=t,c2829=t,c2830=t,c2831=t,c2832=t,c2833=t,c2834=t,c2835=t,c2836=t,c2837=t,c2838=t,c2839=t,c2840=t,c2841=t,c2842=t,c2843=t,c2844=t,c2845=t,c2846=t,c2847=t,c2848=t,c2849=t,c2850=t,c2851=t,c2852=t,c2853=t,c2854=t,c2855=t,c2856=t,c2857=t,c2858=t,c2859=t,c2860=t,c2861=t,c2862=t,c2863=t,c2864=t,c2865=t,c2866=t,c2867=t,c2868=t,c2869=t,c2870=t,c2871=t," - "c2872=t,c2873=t,c2874=t,c2875=t,c2876=t,c2877=t,c2878=t,c2879=t,c2880=t,c2881=t,c2882=t,c2883=t,c2884=t,c2885=t,c2886=t,c2887=t,c2888=t,c2889=t,c2890=t,c2891=t,c2892=t,c2893=t,c2894=t,c2895=t,c2896=t,c2897=t,c2898=t,c2899=t,c2900=t,c2901=t,c2902=t,c2903=t,c2904=t,c2905=t,c2906=t,c2907=t,c2908=t,c2909=t,c2910=t,c2911=t,c2912=t,c2913=t,c2914=t,c2915=t,c2916=t,c2917=t,c2918=t,c2919=t,c2920=t,c2921=t,c2922=t,c2923=t,c2924=t,c2925=t,c2926=t,c2927=t,c2928=t,c2929=t,c2930=t,c2931=t,c2932=t,c2933=t,c2934=t,c2935=t,c2936=t,c2937=t,c2938=t,c2939=t,c2940=t,c2941=t,c2942=t,c2943=t,c2944=t,c2945=t,c2946=t,c2947=t,c2948=t,c2949=t,c2950=t,c2951=t,c2952=t,c2953=t,c2954=t,c2955=t,c2956=t,c2957=t,c2958=t,c2959=t,c2960=t,c2961=t,c2962=t,c2963=t,c2964=t,c2965=t,c2966=t,c2967=t,c2968=t,c2969=t,c2970=t,c2971=t,c2972=t,c2973=t,c2974=t,c2975=t,c2976=t,c2977=t,c2978=t,c2979=t,c2980=t,c2981=t,c2982=t,c2983=t,c2984=t,c2985=t,c2986=t,c2987=t,c2988=t,c2989=t,c2990=t,c2991=t,c2992=t,c2993=t,c2994=t,c2995=t,c2996=t,c2997=t,c2998=t,c2999=t,c3000=t,c3001=t,c3002=t,c3003=t,c3004=t,c3005=t,c3006=t,c3007=t,c3008=t,c3009=t,c3010=t,c3011=t,c3012=t,c3013=t,c3014=t,c3015=t,c3016=t,c3017=t,c3018=t," - "c3019=t,c3020=t,c3021=t,c3022=t,c3023=t,c3024=t,c3025=t,c3026=t,c3027=t,c3028=t,c3029=t,c3030=t,c3031=t,c3032=t,c3033=t,c3034=t,c3035=t,c3036=t,c3037=t,c3038=t,c3039=t,c3040=t,c3041=t,c3042=t,c3043=t,c3044=t,c3045=t,c3046=t,c3047=t,c3048=t,c3049=t,c3050=t,c3051=t,c3052=t,c3053=t,c3054=t,c3055=t,c3056=t,c3057=t,c3058=t,c3059=t,c3060=t,c3061=t,c3062=t,c3063=t,c3064=t,c3065=t,c3066=t,c3067=t,c3068=t,c3069=t,c3070=t,c3071=t,c3072=t,c3073=t,c3074=t,c3075=t,c3076=t,c3077=t,c3078=t,c3079=t,c3080=t,c3081=t,c3082=t,c3083=t,c3084=t,c3085=t,c3086=t,c3087=t,c3088=t,c3089=t,c3090=t,c3091=t,c3092=t,c3093=t,c3094=t,c3095=t,c3096=t,c3097=t,c3098=t,c3099=t,c3100=t,c3101=t,c3102=t,c3103=t,c3104=t,c3105=t,c3106=t,c3107=t,c3108=t,c3109=t,c3110=t,c3111=t,c3112=t,c3113=t,c3114=t,c3115=t,c3116=t,c3117=t,c3118=t,c3119=t,c3120=t,c3121=t,c3122=t,c3123=t,c3124=t,c3125=t,c3126=t,c3127=t,c3128=t,c3129=t,c3130=t,c3131=t,c3132=t,c3133=t,c3134=t,c3135=t,c3136=t,c3137=t,c3138=t,c3139=t,c3140=t,c3141=t,c3142=t,c3143=t,c3144=t,c3145=t,c3146=t,c3147=t,c3148=t,c3149=t,c3150=t,c3151=t,c3152=t,c3153=t,c3154=t,c3155=t,c3156=t,c3157=t,c3158=t,c3159=t,c3160=t,c3161=t,c3162=t,c3163=t,c3164=t,c3165=t," - "c3166=t,c3167=t,c3168=t,c3169=t,c3170=t,c3171=t,c3172=t,c3173=t,c3174=t,c3175=t,c3176=t,c3177=t,c3178=t,c3179=t,c3180=t,c3181=t,c3182=t,c3183=t,c3184=t,c3185=t,c3186=t,c3187=t,c3188=t,c3189=t,c3190=t,c3191=t,c3192=t,c3193=t,c3194=t,c3195=t,c3196=t,c3197=t,c3198=t,c3199=t,c3200=t,c3201=t,c3202=t,c3203=t,c3204=t,c3205=t,c3206=t,c3207=t,c3208=t,c3209=t,c3210=t,c3211=t,c3212=t,c3213=t,c3214=t,c3215=t,c3216=t,c3217=t,c3218=t,c3219=t,c3220=t,c3221=t,c3222=t,c3223=t,c3224=t,c3225=t,c3226=t,c3227=t,c3228=t,c3229=t,c3230=t,c3231=t,c3232=t,c3233=t,c3234=t,c3235=t,c3236=t,c3237=t,c3238=t,c3239=t,c3240=t,c3241=t,c3242=t,c3243=t,c3244=t,c3245=t,c3246=t,c3247=t,c3248=t,c3249=t,c3250=t,c3251=t,c3252=t,c3253=t,c3254=t,c3255=t,c3256=t,c3257=t,c3258=t,c3259=t,c3260=t,c3261=t,c3262=t,c3263=t,c3264=t,c3265=t,c3266=t,c3267=t,c3268=t,c3269=t,c3270=t,c3271=t,c3272=t,c3273=t,c3274=t,c3275=t,c3276=t,c3277=t,c3278=t,c3279=t,c3280=t,c3281=t,c3282=t,c3283=t,c3284=t,c3285=t,c3286=t,c3287=t,c3288=t,c3289=t,c3290=t,c3291=t,c3292=t,c3293=t,c3294=t,c3295=t,c3296=t,c3297=t,c3298=t,c3299=t,c3300=t,c3301=t,c3302=t,c3303=t,c3304=t,c3305=t,c3306=t,c3307=t,c3308=t,c3309=t,c3310=t,c3311=t,c3312=t," - "c3313=t,c3314=t,c3315=t,c3316=t,c3317=t,c3318=t,c3319=t,c3320=t,c3321=t,c3322=t,c3323=t,c3324=t,c3325=t,c3326=t,c3327=t,c3328=t,c3329=t,c3330=t,c3331=t,c3332=t,c3333=t,c3334=t,c3335=t,c3336=t,c3337=t,c3338=t,c3339=t,c3340=t,c3341=t,c3342=t,c3343=t,c3344=t,c3345=t,c3346=t,c3347=t,c3348=t,c3349=t,c3350=t,c3351=t,c3352=t,c3353=t,c3354=t,c3355=t,c3356=t,c3357=t,c3358=t,c3359=t,c3360=t,c3361=t,c3362=t,c3363=t,c3364=t,c3365=t,c3366=t,c3367=t,c3368=t,c3369=t,c3370=t,c3371=t,c3372=t,c3373=t,c3374=t,c3375=t,c3376=t,c3377=t,c3378=t,c3379=t,c3380=t,c3381=t,c3382=t,c3383=t,c3384=t,c3385=t,c3386=t,c3387=t,c3388=t,c3389=t,c3390=t,c3391=t,c3392=t,c3393=t,c3394=t,c3395=t,c3396=t,c3397=t,c3398=t,c3399=t,c3400=t,c3401=t,c3402=t,c3403=t,c3404=t,c3405=t,c3406=t,c3407=t,c3408=t,c3409=t,c3410=t,c3411=t,c3412=t,c3413=t,c3414=t,c3415=t,c3416=t,c3417=t,c3418=t,c3419=t,c3420=t,c3421=t,c3422=t,c3423=t,c3424=t,c3425=t,c3426=t,c3427=t,c3428=t,c3429=t,c3430=t,c3431=t,c3432=t,c3433=t,c3434=t,c3435=t,c3436=t,c3437=t,c3438=t,c3439=t,c3440=t,c3441=t,c3442=t,c3443=t,c3444=t,c3445=t,c3446=t,c3447=t,c3448=t,c3449=t,c3450=t,c3451=t,c3452=t,c3453=t,c3454=t,c3455=t,c3456=t,c3457=t,c3458=t,c3459=t," - "c3460=t,c3461=t,c3462=t,c3463=t,c3464=t,c3465=t,c3466=t,c3467=t,c3468=t,c3469=t,c3470=t,c3471=t,c3472=t,c3473=t,c3474=t,c3475=t,c3476=t,c3477=t,c3478=t,c3479=t,c3480=t,c3481=t,c3482=t,c3483=t,c3484=t,c3485=t,c3486=t,c3487=t,c3488=t,c3489=t,c3490=t,c3491=t,c3492=t,c3493=t,c3494=t,c3495=t,c3496=t,c3497=t,c3498=t,c3499=t,c3500=t,c3501=t,c3502=t,c3503=t,c3504=t,c3505=t,c3506=t,c3507=t,c3508=t,c3509=t,c3510=t,c3511=t,c3512=t,c3513=t," - "c3514=t,c3515=t,c3516=t,c3517=t,c3518=t,c3519=t,c3520=t,c3521=t,c3522=t,c3523=t,c3524=t,c3525=t,c3526=t,c3527=t,c3528=t,c3529=t,c3530=t,c3531=t,c3532=t,c3533=t,c3534=t,c3535=t,c3536=t,c3537=t,c3538=t,c3539=t,c3540=t,c3541=t,c3542=t,c3543=t,c3544=t,c3545=t,c3546=t,c3547=t,c3548=t,c3549=t,c3550=t,c3551=t,c3552=t,c3553=t,c3554=t,c3555=t,c3556=t,c3557=t,c3558=t,c3559=t,c3560=t,c3561=t,c3562=t,c3563=t,c3564=t,c3565=t,c3566=t,c3567=t,c3568=t,c3569=t,c3570=t,c3571=t,c3572=t,c3573=t,c3574=t,c3575=t,c3576=t,c3577=t,c3578=t,c3579=t,c3580=t,c3581=t,c3582=t,c3583=t,c3584=t,c3585=t,c3586=t,c3587=t,c3588=t,c3589=t,c3590=t,c3591=t,c3592=t,c3593=t,c3594=t,c3595=t,c3596=t,c3597=t,c3598=t,c3599=t,c3600=t,c3601=t,c3602=t,c3603=t,c3604=t,c3605=t,c3606=t,c3607=t,c3608=t,c3609=t,c3610=t,c3611=t,c3612=t,c3613=t,c3614=t,c3615=t,c3616=t,c3617=t,c3618=t,c3619=t,c3620=t,c3621=t,c3622=t,c3623=t,c3624=t,c3625=t,c3626=t,c3627=t,c3628=t,c3629=t,c3630=t,c3631=t,c3632=t,c3633=t,c3634=t,c3635=t,c3636=t,c3637=t,c3638=t,c3639=t,c3640=t,c3641=t,c3642=t,c3643=t,c3644=t,c3645=t,c3646=t,c3647=t,c3648=t,c3649=t,c3650=t,c3651=t,c3652=t,c3653=t,c3654=t,c3655=t,c3656=t,c3657=t,c3658=t,c3659=t,c3660=t," - "c3661=t,c3662=t,c3663=t,c3664=t,c3665=t,c3666=t,c3667=t,c3668=t,c3669=t,c3670=t,c3671=t,c3672=t,c3673=t,c3674=t,c3675=t,c3676=t,c3677=t,c3678=t,c3679=t,c3680=t,c3681=t,c3682=t,c3683=t,c3684=t,c3685=t,c3686=t,c3687=t,c3688=t,c3689=t,c3690=t,c3691=t,c3692=t,c3693=t,c3694=t,c3695=t,c3696=t,c3697=t,c3698=t,c3699=t,c3700=t,c3701=t,c3702=t,c3703=t,c3704=t,c3705=t,c3706=t,c3707=t,c3708=t,c3709=t,c3710=t,c3711=t,c3712=t,c3713=t,c3714=t,c3715=t,c3716=t,c3717=t,c3718=t,c3719=t,c3720=t,c3721=t,c3722=t,c3723=t,c3724=t,c3725=t,c3726=t,c3727=t,c3728=t,c3729=t,c3730=t,c3731=t,c3732=t,c3733=t,c3734=t,c3735=t,c3736=t,c3737=t,c3738=t,c3739=t,c3740=t,c3741=t,c3742=t,c3743=t,c3744=t,c3745=t,c3746=t,c3747=t,c3748=t,c3749=t,c3750=t,c3751=t,c3752=t,c3753=t,c3754=t,c3755=t,c3756=t,c3757=t,c3758=t,c3759=t,c3760=t,c3761=t,c3762=t,c3763=t,c3764=t,c3765=t,c3766=t,c3767=t,c3768=t,c3769=t,c3770=t,c3771=t,c3772=t,c3773=t,c3774=t,c3775=t,c3776=t,c3777=t,c3778=t,c3779=t,c3780=t,c3781=t,c3782=t,c3783=t,c3784=t,c3785=t,c3786=t,c3787=t,c3788=t,c3789=t,c3790=t,c3791=t,c3792=t,c3793=t,c3794=t,c3795=t,c3796=t,c3797=t,c3798=t,c3799=t,c3800=t,c3801=t,c3802=t,c3803=t,c3804=t,c3805=t,c3806=t,c3807=t," - "c3808=t,c3809=t,c3810=t,c3811=t,c3812=t,c3813=t,c3814=t,c3815=t,c3816=t,c3817=t,c3818=t,c3819=t,c3820=t,c3821=t,c3822=t,c3823=t,c3824=t,c3825=t,c3826=t,c3827=t,c3828=t,c3829=t,c3830=t,c3831=t,c3832=t,c3833=t,c3834=t,c3835=t,c3836=t,c3837=t,c3838=t,c3839=t,c3840=t,c3841=t,c3842=t,c3843=t,c3844=t,c3845=t,c3846=t,c3847=t,c3848=t,c3849=t,c3850=t,c3851=t,c3852=t,c3853=t,c3854=t,c3855=t,c3856=t,c3857=t,c3858=t,c3859=t,c3860=t,c3861=t,c3862=t,c3863=t,c3864=t,c3865=t,c3866=t,c3867=t,c3868=t,c3869=t,c3870=t,c3871=t,c3872=t,c3873=t,c3874=t,c3875=t,c3876=t,c3877=t,c3878=t,c3879=t,c3880=t,c3881=t,c3882=t,c3883=t,c3884=t,c3885=t,c3886=t,c3887=t,c3888=t,c3889=t,c3890=t,c3891=t,c3892=t,c3893=t,c3894=t,c3895=t,c3896=t,c3897=t,c3898=t,c3899=t,c3900=t,c3901=t,c3902=t,c3903=t,c3904=t,c3905=t,c3906=t,c3907=t,c3908=t,c3909=t,c3910=t,c3911=t,c3912=t,c3913=t,c3914=t,c3915=t,c3916=t,c3917=t,c3918=t,c3919=t,c3920=t,c3921=t,c3922=t,c3923=t,c3924=t,c3925=t,c3926=t,c3927=t,c3928=t,c3929=t,c3930=t,c3931=t,c3932=t,c3933=t,c3934=t,c3935=t,c3936=t,c3937=t,c3938=t,c3939=t,c3940=t,c3941=t,c3942=t,c3943=t,c3944=t,c3945=t,c3946=t,c3947=t,c3948=t,c3949=t,c3950=t,c3951=t,c3952=t,c3953=t,c3954=t," - "c3955=t,c3956=t,c3957=t,c3958=t,c3959=t,c3960=t,c3961=t,c3962=t,c3963=t,c3964=t,c3965=t,c3966=t,c3967=t,c3968=t,c3969=t,c3970=t,c3971=t,c3972=t,c3973=t,c3974=t,c3975=t,c3976=t,c3977=t,c3978=t,c3979=t,c3980=t,c3981=t,c3982=t,c3983=t,c3984=t,c3985=t,c3986=t,c3987=t,c3988=t,c3989=t,c3990=t,c3991=t,c3992=t,c3993=t,c3994=t,c3995=t,c3996=t,c3997=t,c3998=t,c3999=t,c4000=t,c4001=t,c4002=t,c4003=t,c4004=t,c4005=t,c4006=t,c4007=t,c4008=t,c4009=t,c4010=t,c4011=t,c4012=t,c4013=t,c4014=t,c4015=t,c4016=t,c4017=t,c4018=t,c4019=t,c4020=t,c4021=t,c4022=t,c4023=t,c4024=t,c4025=t,c4026=t,c4027=t,c4028=t,c4029=t,c4030=t,c4031=t,c4032=t,c4033=t,c4034=t,c4035=t,c4036=t,c4037=t,c4038=t,c4039=t,c4040=t,c4041=t,c4042=t,c4043=t,c4044=t,c4045=t,c4046=t,c4047=t,c4048=t,c4049=t,c4050=t,c4051=t,c4052=t,c4053=t,c4054=t,c4055=t,c4056=t,c4057=t,c4058=t,c4059=t,c4060=t,c4061=t,c4062=t,c4063=t,c4064=t,c4065=t,c4066=t,c4067=t,c4068=t,c4069=t,c4070=t,c4071=t,c4072=t,c4073=t,c4074=t,c4075=t,c4076=t,c4077=t,c4078=t,c4079=t,c4080=t,c4081=t,c4082=t,c4083=t,c4084=t,c4085=t,c4086=t,c4087=t,c4088=t,c4089=t,c4090=t,c4091=t,c4092=t,c4093=t 1626006833640000000" - }; + "spgwgvldxv,id=spgwgvldxv_1,t0=f " + "c0=t,c1=t,c2=t,c3=t,c4=t,c5=t,c6=t,c7=t,c8=t,c9=t,c10=t,c11=t,c12=t,c13=t,c14=t,c15=t,c16=t,c17=t,c18=t,c19=t," + "c20=t,c21=t,c22=t,c23=t,c24=t,c25=t,c26=t,c27=t,c28=t,c29=t,c30=t,c31=t,c32=t,c33=t,c34=t,c35=t,c36=t,c37=t,c38=" + "t,c39=t,c40=t,c41=t,c42=t,c43=t,c44=t,c45=t,c46=t,c47=t,c48=t,c49=t,c50=t,c51=t,c52=t,c53=t,c54=t,c55=t,c56=t," + "c57=t,c58=t,c59=t,c60=t,c61=t,c62=t,c63=t,c64=t,c65=t,c66=t,c67=t,c68=t,c69=t,c70=t,c71=t,c72=t,c73=t,c74=t,c75=" + "t,c76=t,c77=t,c78=t,c79=t,c80=t,c81=t,c82=t,c83=t,c84=t,c85=t,c86=t,c87=t,c88=t,c89=t,c90=t,c91=t,c92=t,c93=t," + "c94=t,c95=t,c96=t,c97=t,c98=t,c99=t,c100=t," + "c101=t,c102=t,c103=t,c104=t,c105=t,c106=t,c107=t,c108=t,c109=t,c110=t,c111=t,c112=t,c113=t,c114=t,c115=t,c116=t," + "c117=t,c118=t,c119=t,c120=t,c121=t,c122=t,c123=t,c124=t,c125=t,c126=t,c127=t,c128=t,c129=t,c130=t,c131=t,c132=t," + "c133=t,c134=t,c135=t,c136=t,c137=t,c138=t,c139=t,c140=t,c141=t,c142=t,c143=t,c144=t,c145=t,c146=t,c147=t,c148=t," + "c149=t,c150=t,c151=t,c152=t,c153=t,c154=t,c155=t,c156=t,c157=t,c158=t,c159=t,c160=t,c161=t,c162=t,c163=t,c164=t," + "c165=t,c166=t,c167=t,c168=t,c169=t,c170=t,c171=t,c172=t,c173=t,c174=t,c175=t,c176=t,c177=t,c178=t,c179=t,c180=t," + "c181=t,c182=t,c183=t,c184=t,c185=t,c186=t,c187=t,c188=t,c189=t," + "c190=t,c191=t,c192=t,c193=t,c194=t,c195=t,c196=t,c197=t,c198=t,c199=t,c200=t,c201=t,c202=t,c203=t,c204=t,c205=t," + "c206=t,c207=t,c208=t,c209=t,c210=t,c211=t,c212=t,c213=t,c214=t,c215=t,c216=t,c217=t,c218=t,c219=t,c220=t,c221=t," + "c222=t,c223=t,c224=t,c225=t,c226=t,c227=t,c228=t,c229=t,c230=t,c231=t,c232=t,c233=t,c234=t,c235=t,c236=t,c237=t," + "c238=t,c239=t,c240=t,c241=t,c242=t,c243=t,c244=t,c245=t,c246=t,c247=t,c248=t,c249=t,c250=t,c251=t,c252=t,c253=t," + "c254=t,c255=t,c256=t,c257=t,c258=t,c259=t,c260=t,c261=t,c262=t,c263=t,c264=t,c265=t,c266=t,c267=t,c268=t,c269=t," + "c270=t,c271=t,c272=t,c273=t,c274=t,c275=t,c276=t,c277=t,c278=t," + "c279=t,c280=t,c281=t,c282=t,c283=t,c284=t,c285=t,c286=t,c287=t,c288=t,c289=t,c290=t,c291=t,c292=t,c293=t,c294=t," + "c295=t,c296=t,c297=t,c298=t,c299=t,c300=t,c301=t,c302=t,c303=t,c304=t,c305=t,c306=t,c307=t,c308=t,c309=t,c310=t," + "c311=t,c312=t,c313=t,c314=t,c315=t,c316=t,c317=t,c318=t,c319=t,c320=t,c321=t,c322=t,c323=t,c324=t,c325=t,c326=t," + "c327=t,c328=t,c329=t,c330=t,c331=t,c332=t,c333=t,c334=t,c335=t,c336=t,c337=t,c338=t,c339=t,c340=t,c341=t,c342=t," + "c343=t,c344=t,c345=t,c346=t,c347=t,c348=t,c349=t,c350=t,c351=t,c352=t,c353=t,c354=t,c355=t,c356=t,c357=t,c358=t," + "c359=t,c360=t,c361=t,c362=t,c363=t,c364=t,c365=t,c366=t,c367=t,c368=t,c369=t,c370=t,c371=t,c372=t,c373=t,c374=t," + "c375=t,c376=t,c377=t,c378=t,c379=t,c380=t,c381=t,c382=t,c383=t,c384=t,c385=t,c386=t,c387=t,c388=t,c389=t,c390=t," + "c391=t,c392=t,c393=t,c394=t,c395=t,c396=t,c397=t,c398=t,c399=t,c400=t,c401=t,c402=t,c403=t,c404=t,c405=t,c406=t," + "c407=t,c408=t,c409=t,c410=t,c411=t,c412=t,c413=t,c414=t,c415=t,c416=t,c417=t,c418=t,c419=t,c420=t,c421=t,c422=t," + "c423=t,c424=t,c425=t,c426=t,c427=t,c428=t,c429=t,c430=t,c431=t,c432=t,c433=t,c434=t,c435=t,c436=t,c437=t,c438=t," + "c439=t,c440=t,c441=t,c442=t,c443=t,c444=t,c445=t,c446=t," + "c447=t,c448=t,c449=t,c450=t,c451=t,c452=t,c453=t,c454=t,c455=t,c456=t,c457=t,c458=t,c459=t,c460=t,c461=t,c462=t," + "c463=t,c464=t,c465=t,c466=t,c467=t,c468=t,c469=t,c470=t,c471=t,c472=t,c473=t,c474=t,c475=t,c476=t,c477=t,c478=t," + "c479=t,c480=t,c481=t,c482=t,c483=t,c484=t,c485=t,c486=t,c487=t,c488=t,c489=t,c490=t,c491=t,c492=t,c493=t,c494=t," + "c495=t,c496=t,c497=t,c498=t,c499=t,c500=t,c501=t,c502=t,c503=t,c504=t,c505=t,c506=t,c507=t,c508=t,c509=t,c510=t," + "c511=t,c512=t,c513=t,c514=t,c515=t,c516=t,c517=t,c518=t,c519=t,c520=t,c521=t,c522=t,c523=t,c524=t,c525=t,c526=t," + "c527=t,c528=t,c529=t,c530=t,c531=t,c532=t,c533=t,c534=t,c535=t,c536=t,c537=t,c538=t,c539=t,c540=t,c541=t,c542=t," + "c543=t,c544=t,c545=t,c546=t,c547=t,c548=t,c549=t,c550=t,c551=t,c552=t,c553=t,c554=t,c555=t,c556=t,c557=t,c558=t," + "c559=t,c560=t,c561=t,c562=t,c563=t,c564=t,c565=t,c566=t,c567=t,c568=t,c569=t,c570=t,c571=t,c572=t,c573=t,c574=t," + "c575=t,c576=t,c577=t,c578=t,c579=t,c580=t,c581=t,c582=t,c583=t,c584=t,c585=t,c586=t,c587=t,c588=t,c589=t,c590=t," + "c591=t,c592=t,c593=t,c594=t,c595=t,c596=t,c597=t,c598=t,c599=t,c600=t,c601=t,c602=t,c603=t,c604=t,c605=t,c606=t," + "c607=t,c608=t,c609=t,c610=t,c611=t,c612=t,c613=t,c614=t," + "c615=t,c616=t,c617=t,c618=t,c619=t,c620=t,c621=t,c622=t,c623=t,c624=t,c625=t,c626=t,c627=t,c628=t,c629=t,c630=t," + "c631=t,c632=t,c633=t,c634=t,c635=t,c636=t,c637=t,c638=t,c639=t,c640=t,c641=t,c642=t,c643=t,c644=t,c645=t,c646=t," + "c647=t,c648=t,c649=t,c650=t,c651=t,c652=t,c653=t,c654=t,c655=t,c656=t,c657=t,c658=t,c659=t,c660=t,c661=t,c662=t," + "c663=t,c664=t,c665=t,c666=t,c667=t,c668=t,c669=t,c670=t,c671=t,c672=t,c673=t,c674=t,c675=t,c676=t,c677=t,c678=t," + "c679=t,c680=t,c681=t,c682=t,c683=t,c684=t,c685=t,c686=t,c687=t,c688=t,c689=t,c690=t,c691=t,c692=t,c693=t,c694=t," + "c695=t,c696=t,c697=t,c698=t,c699=t,c700=t,c701=t,c702=t,c703=t,c704=t,c705=t,c706=t,c707=t,c708=t,c709=t,c710=t," + "c711=t,c712=t,c713=t,c714=t,c715=t,c716=t,c717=t,c718=t,c719=t,c720=t,c721=t,c722=t,c723=t,c724=t,c725=t,c726=t," + "c727=t,c728=t,c729=t,c730=t,c731=t,c732=t,c733=t,c734=t,c735=t,c736=t,c737=t,c738=t,c739=t,c740=t,c741=t,c742=t," + "c743=t,c744=t,c745=t,c746=t,c747=t,c748=t,c749=t,c750=t,c751=t,c752=t,c753=t,c754=t,c755=t,c756=t,c757=t,c758=t," + "c759=t,c760=t,c761=t,c762=t,c763=t,c764=t,c765=t,c766=t,c767=t,c768=t,c769=t,c770=t,c771=t,c772=t,c773=t,c774=t," + "c775=t,c776=t,c777=t,c778=t,c779=t,c780=t,c781=t,c782=t," + "c783=t,c784=t,c785=t,c786=t,c787=t,c788=t,c789=t,c790=t,c791=t,c792=t,c793=t,c794=t,c795=t,c796=t,c797=t,c798=t," + "c799=t,c800=t,c801=t,c802=t,c803=t,c804=t,c805=t,c806=t,c807=t,c808=t,c809=t,c810=t,c811=t,c812=t,c813=t," + "c814=t,c815=t,c816=t,c817=t,c818=t,c819=t,c820=t,c821=t,c822=t,c823=t,c824=t,c825=t,c826=t,c827=t,c828=t,c829=t," + "c830=t,c831=t,c832=t,c833=t,c834=t,c835=t,c836=t,c837=t,c838=t,c839=t,c840=t,c841=t,c842=t,c843=t,c844=t,c845=t," + "c846=t,c847=t,c848=t,c849=t,c850=t,c851=t,c852=t,c853=t,c854=t,c855=t,c856=t,c857=t,c858=t,c859=t,c860=t,c861=t," + "c862=t," + "c863=t,c864=t,c865=t,c866=t,c867=t,c868=t,c869=t,c870=t,c871=t,c872=t,c873=t,c874=t,c875=t,c876=t,c877=t,c878=t," + "c879=t,c880=t,c881=t,c882=t,c883=t,c884=t,c885=t,c886=t,c887=t,c888=t,c889=t,c890=t,c891=t,c892=t,c893=t,c894=t," + "c895=t,c896=t,c897=t,c898=t,c899=t,c900=t,c901=t,c902=t,c903=t,c904=t,c905=t,c906=t,c907=t,c908=t,c909=t,c910=t," + "c911=t,c912=t,c913=t,c914=t,c915=t,c916=t,c917=t,c918=t,c919=t,c920=t,c921=t,c922=t,c923=t,c924=t,c925=t,c926=t," + "c927=t,c928=t,c929=t,c930=t,c931=t,c932=t,c933=t,c934=t,c935=t,c936=t,c937=t,c938=t,c939=t,c940=t,c941=t,c942=t," + "c943=t,c944=t,c945=t,c946=t,c947=t,c948=t,c949=t,c950=t,c951=t,c952=t,c953=t,c954=t,c955=t,c956=t,c957=t,c958=t," + "c959=t,c960=t,c961=t,c962=t,c963=t,c964=t,c965=t,c966=t,c967=t,c968=t,c969=t,c970=t,c971=t,c972=t,c973=t,c974=t," + "c975=t,c976=t,c977=t,c978=t,c979=t,c980=t,c981=t,c982=t,c983=t,c984=t,c985=t,c986=t,c987=t,c988=t,c989=t,c990=t," + "c991=t,c992=t,c993=t,c994=t,c995=t,c996=t,c997=t,c998=t,c999=t,c1000=t,c1001=t,c1002=t,c1003=t,c1004=t,c1005=t," + "c1006=t,c1007=t,c1008=t,c1009=t,c1010=t,c1011=t,c1012=t,c1013=t,c1014=t,c1015=t,c1016=t,c1017=t,c1018=t,c1019=t," + "c1020=t,c1021=t,c1022=t,c1023=t,c1024=t,c1025=t,c1026=t," + "c1027=t,c1028=t,c1029=t,c1030=t,c1031=t,c1032=t,c1033=t,c1034=t,c1035=t,c1036=t,c1037=t,c1038=t,c1039=t,c1040=t," + "c1041=t,c1042=t,c1043=t,c1044=t,c1045=t,c1046=t,c1047=t,c1048=t,c1049=t,c1050=t,c1051=t,c1052=t,c1053=t,c1054=t," + "c1055=t,c1056=t,c1057=t,c1058=t,c1059=t,c1060=t,c1061=t,c1062=t,c1063=t,c1064=t,c1065=t,c1066=t,c1067=t,c1068=t," + "c1069=t,c1070=t,c1071=t,c1072=t,c1073=t,c1074=t,c1075=t,c1076=t,c1077=t,c1078=t,c1079=t,c1080=t,c1081=t,c1082=t," + "c1083=t,c1084=t,c1085=t,c1086=t,c1087=t,c1088=t,c1089=t,c1090=t,c1091=t,c1092=t,c1093=t,c1094=t,c1095=t,c1096=t," + "c1097=t,c1098=t,c1099=t,c1100=t,c1101=t,c1102=t,c1103=t,c1104=t,c1105=t,c1106=t,c1107=t,c1108=t,c1109=t,c1110=t," + "c1111=t,c1112=t,c1113=t,c1114=t,c1115=t,c1116=t,c1117=t,c1118=t,c1119=t,c1120=t,c1121=t,c1122=t,c1123=t,c1124=t," + "c1125=t,c1126=t,c1127=t,c1128=t,c1129=t,c1130=t,c1131=t,c1132=t,c1133=t,c1134=t,c1135=t,c1136=t,c1137=t,c1138=t," + "c1139=t,c1140=t,c1141=t,c1142=t,c1143=t,c1144=t,c1145=t,c1146=t,c1147=t,c1148=t,c1149=t,c1150=t,c1151=t,c1152=t," + "c1153=t,c1154=t,c1155=t,c1156=t,c1157=t,c1158=t,c1159=t,c1160=t,c1161=t,c1162=t,c1163=t,c1164=t,c1165=t,c1166=t," + "c1167=t,c1168=t,c1169=t,c1170=t,c1171=t,c1172=t,c1173=t," + "c1174=t,c1175=t,c1176=t,c1177=t,c1178=t,c1179=t,c1180=t,c1181=t,c1182=t,c1183=t,c1184=t,c1185=t,c1186=t,c1187=t," + "c1188=t,c1189=t,c1190=t,c1191=t,c1192=t,c1193=t,c1194=t,c1195=t,c1196=t,c1197=t,c1198=t,c1199=t,c1200=t,c1201=t," + "c1202=t,c1203=t,c1204=t,c1205=t,c1206=t,c1207=t,c1208=t,c1209=t,c1210=t,c1211=t,c1212=t,c1213=t,c1214=t,c1215=t," + "c1216=t,c1217=t,c1218=t,c1219=t,c1220=t,c1221=t,c1222=t,c1223=t,c1224=t,c1225=t,c1226=t,c1227=t,c1228=t,c1229=t," + "c1230=t,c1231=t,c1232=t,c1233=t,c1234=t,c1235=t,c1236=t,c1237=t,c1238=t,c1239=t,c1240=t,c1241=t,c1242=t,c1243=t," + "c1244=t,c1245=t,c1246=t,c1247=t,c1248=t,c1249=t,c1250=t,c1251=t,c1252=t,c1253=t,c1254=t,c1255=t,c1256=t,c1257=t," + "c1258=t,c1259=t,c1260=t,c1261=t,c1262=t,c1263=t,c1264=t,c1265=t,c1266=t,c1267=t,c1268=t,c1269=t,c1270=t,c1271=t," + "c1272=t,c1273=t,c1274=t,c1275=t,c1276=t,c1277=t,c1278=t,c1279=t,c1280=t,c1281=t,c1282=t,c1283=t,c1284=t,c1285=t," + "c1286=t,c1287=t,c1288=t,c1289=t,c1290=t,c1291=t,c1292=t,c1293=t,c1294=t,c1295=t,c1296=t,c1297=t,c1298=t,c1299=t," + "c1300=t,c1301=t,c1302=t,c1303=t,c1304=t,c1305=t,c1306=t,c1307=t,c1308=t,c1309=t,c1310=t,c1311=t,c1312=t,c1313=t," + "c1314=t,c1315=t,c1316=t,c1317=t,c1318=t,c1319=t,c1320=t," + "c1321=t,c1322=t,c1323=t,c1324=t,c1325=t,c1326=t,c1327=t,c1328=t,c1329=t,c1330=t,c1331=t,c1332=t,c1333=t,c1334=t," + "c1335=t,c1336=t,c1337=t,c1338=t,c1339=t,c1340=t,c1341=t,c1342=t,c1343=t,c1344=t,c1345=t,c1346=t,c1347=t," + "c1348=t,c1349=t,c1350=t,c1351=t,c1352=t,c1353=t,c1354=t,c1355=t,c1356=t,c1357=t,c1358=t,c1359=t,c1360=t,c1361=t," + "c1362=t,c1363=t,c1364=t,c1365=t,c1366=t,c1367=t,c1368=t,c1369=t,c1370=t,c1371=t,c1372=t,c1373=t,c1374=t,c1375=t," + "c1376=t,c1377=t,c1378=t,c1379=t,c1380=t,c1381=t,c1382=t,c1383=t,c1384=t,c1385=t,c1386=t,c1387=t,c1388=t,c1389=t," + "c1390=t,c1391=t,c1392=t,c1393=t,c1394=t,c1395=t,c1396=t,c1397=t,c1398=t,c1399=t,c1400=t,c1401=t,c1402=t,c1403=t," + "c1404=t,c1405=t,c1406=t,c1407=t,c1408=t,c1409=t,c1410=t,c1411=t,c1412=t,c1413=t,c1414=t,c1415=t,c1416=t,c1417=t," + "c1418=t,c1419=t,c1420=t,c1421=t,c1422=t,c1423=t,c1424=t,c1425=t,c1426=t,c1427=t,c1428=t,c1429=t,c1430=t,c1431=t," + "c1432=t,c1433=t,c1434=t,c1435=t,c1436=t,c1437=t,c1438=t,c1439=t,c1440=t,c1441=t,c1442=t,c1443=t,c1444=t,c1445=t," + "c1446=t,c1447=t,c1448=t,c1449=t,c1450=t,c1451=t,c1452=t,c1453=t,c1454=t,c1455=t,c1456=t,c1457=t,c1458=t,c1459=t," + "c1460=t,c1461=t,c1462=t,c1463=t,c1464=t,c1465=t,c1466=t,c1467=t,c1468=t,c1469=t,c1470=t,c1471=t,c1472=t,c1473=t," + "c1474=t,c1475=t,c1476=t,c1477=t,c1478=t,c1479=t,c1480=t,c1481=t,c1482=t,c1483=t,c1484=t,c1485=t,c1486=t,c1487=t," + "c1488=t,c1489=t,c1490=t,c1491=t,c1492=t,c1493=t,c1494=t," + "c1495=t,c1496=t,c1497=t,c1498=t,c1499=t,c1500=t,c1501=t,c1502=t,c1503=t,c1504=t,c1505=t,c1506=t,c1507=t,c1508=t," + "c1509=t,c1510=t,c1511=t,c1512=t,c1513=t,c1514=t,c1515=t,c1516=t,c1517=t,c1518=t,c1519=t,c1520=t,c1521=t,c1522=t," + "c1523=t,c1524=t,c1525=t,c1526=t,c1527=t,c1528=t,c1529=t,c1530=t,c1531=t,c1532=t,c1533=t,c1534=t,c1535=t,c1536=t," + "c1537=t,c1538=t,c1539=t,c1540=t,c1541=t,c1542=t,c1543=t,c1544=t,c1545=t,c1546=t,c1547=t,c1548=t,c1549=t,c1550=t," + "c1551=t,c1552=t,c1553=t,c1554=t,c1555=t,c1556=t,c1557=t,c1558=t,c1559=t,c1560=t,c1561=t,c1562=t,c1563=t,c1564=t," + "c1565=t,c1566=t,c1567=t,c1568=t,c1569=t,c1570=t,c1571=t,c1572=t,c1573=t,c1574=t,c1575=t,c1576=t,c1577=t,c1578=t," + "c1579=t,c1580=t,c1581=t,c1582=t,c1583=t,c1584=t,c1585=t,c1586=t,c1587=t,c1588=t,c1589=t,c1590=t,c1591=t,c1592=t," + "c1593=t,c1594=t,c1595=t,c1596=t,c1597=t,c1598=t,c1599=t,c1600=t,c1601=t,c1602=t,c1603=t,c1604=t,c1605=t,c1606=t," + "c1607=t,c1608=t,c1609=t,c1610=t,c1611=t,c1612=t,c1613=t,c1614=t,c1615=t,c1616=t,c1617=t,c1618=t,c1619=t,c1620=t," + "c1621=t,c1622=t,c1623=t,c1624=t,c1625=t,c1626=t,c1627=t,c1628=t,c1629=t,c1630=t,c1631=t,c1632=t,c1633=t,c1634=t," + "c1635=t,c1636=t,c1637=t,c1638=t,c1639=t,c1640=t,c1641=t," + "c1642=t,c1643=t,c1644=t,c1645=t,c1646=t,c1647=t,c1648=t,c1649=t,c1650=t,c1651=t,c1652=t,c1653=t,c1654=t,c1655=t," + "c1656=t,c1657=t,c1658=t,c1659=t,c1660=t,c1661=t,c1662=t,c1663=t,c1664=t,c1665=t,c1666=t,c1667=t,c1668=t,c1669=t," + "c1670=t,c1671=t,c1672=t,c1673=t,c1674=t,c1675=t,c1676=t,c1677=t,c1678=t,c1679=t,c1680=t,c1681=t,c1682=t,c1683=t," + "c1684=t,c1685=t,c1686=t,c1687=t,c1688=t,c1689=t,c1690=t,c1691=t,c1692=t,c1693=t,c1694=t,c1695=t,c1696=t,c1697=t," + "c1698=t,c1699=t,c1700=t,c1701=t,c1702=t,c1703=t,c1704=t,c1705=t,c1706=t,c1707=t,c1708=t,c1709=t,c1710=t,c1711=t," + "c1712=t,c1713=t,c1714=t,c1715=t,c1716=t,c1717=t,c1718=t,c1719=t,c1720=t,c1721=t,c1722=t,c1723=t,c1724=t,c1725=t," + "c1726=t,c1727=t,c1728=t,c1729=t,c1730=t,c1731=t,c1732=t,c1733=t,c1734=t,c1735=t,c1736=t,c1737=t,c1738=t,c1739=t," + "c1740=t,c1741=t,c1742=t,c1743=t,c1744=t,c1745=t,c1746=t,c1747=t,c1748=t,c1749=t,c1750=t,c1751=t,c1752=t,c1753=t," + "c1754=t,c1755=t,c1756=t,c1757=t,c1758=t,c1759=t,c1760=t,c1761=t,c1762=t,c1763=t,c1764=t,c1765=t,c1766=t,c1767=t," + "c1768=t,c1769=t,c1770=t,c1771=t,c1772=t,c1773=t,c1774=t,c1775=t,c1776=t,c1777=t,c1778=t,c1779=t,c1780=t,c1781=t," + "c1782=t,c1783=t,c1784=t,c1785=t,c1786=t,c1787=t,c1788=t," + "c1789=t,c1790=t,c1791=t,c1792=t,c1793=t,c1794=t,c1795=t,c1796=t,c1797=t,c1798=t,c1799=t,c1800=t,c1801=t,c1802=t," + "c1803=t,c1804=t,c1805=t,c1806=t,c1807=t,c1808=t,c1809=t,c1810=t,c1811=t,c1812=t,c1813=t,c1814=t,c1815=t," + "c1816=t,c1817=t,c1818=t,c1819=t,c1820=t,c1821=t,c1822=t,c1823=t,c1824=t,c1825=t,c1826=t,c1827=t,c1828=t,c1829=t," + "c1830=t,c1831=t,c1832=t,c1833=t,c1834=t,c1835=t,c1836=t,c1837=t,c1838=t,c1839=t,c1840=t,c1841=t,c1842=t,c1843=t," + "c1844=t,c1845=t,c1846=t,c1847=t,c1848=t,c1849=t,c1850=t,c1851=t,c1852=t,c1853=t,c1854=t,c1855=t,c1856=t,c1857=t," + "c1858=t,c1859=t,c1860=t,c1861=t,c1862=t,c1863=t,c1864=t,c1865=t,c1866=t,c1867=t,c1868=t,c1869=t,c1870=t,c1871=t," + "c1872=t,c1873=t,c1874=t,c1875=t,c1876=t,c1877=t,c1878=t,c1879=t,c1880=t,c1881=t,c1882=t,c1883=t,c1884=t,c1885=t," + "c1886=t,c1887=t,c1888=t,c1889=t,c1890=t,c1891=t,c1892=t,c1893=t,c1894=t,c1895=t,c1896=t,c1897=t,c1898=t,c1899=t," + "c1900=t,c1901=t,c1902=t,c1903=t,c1904=t,c1905=t,c1906=t,c1907=t,c1908=t,c1909=t,c1910=t,c1911=t,c1912=t,c1913=t," + "c1914=t,c1915=t,c1916=t,c1917=t,c1918=t,c1919=t,c1920=t,c1921=t,c1922=t,c1923=t,c1924=t,c1925=t,c1926=t,c1927=t," + "c1928=t,c1929=t,c1930=t,c1931=t,c1932=t,c1933=t,c1934=t,c1935=t,c1936=t,c1937=t,c1938=t,c1939=t,c1940=t,c1941=t," + "c1942=t,c1943=t,c1944=t,c1945=t,c1946=t,c1947=t,c1948=t,c1949=t,c1950=t,c1951=t,c1952=t,c1953=t,c1954=t,c1955=t," + "c1956=t,c1957=t,c1958=t,c1959=t,c1960=t,c1961=t,c1962=t," + "c1963=t,c1964=t,c1965=t,c1966=t,c1967=t,c1968=t,c1969=t,c1970=t,c1971=t,c1972=t,c1973=t,c1974=t,c1975=t,c1976=t," + "c1977=t,c1978=t,c1979=t,c1980=t,c1981=t,c1982=t,c1983=t,c1984=t,c1985=t,c1986=t,c1987=t,c1988=t,c1989=t,c1990=t," + "c1991=t,c1992=t,c1993=t,c1994=t,c1995=t,c1996=t,c1997=t,c1998=t,c1999=t,c2000=t,c2001=t,c2002=t,c2003=t,c2004=t," + "c2005=t,c2006=t,c2007=t,c2008=t,c2009=t,c2010=t,c2011=t,c2012=t,c2013=t,c2014=t,c2015=t,c2016=t,c2017=t,c2018=t," + "c2019=t,c2020=t,c2021=t,c2022=t,c2023=t,c2024=t,c2025=t,c2026=t,c2027=t,c2028=t,c2029=t,c2030=t,c2031=t,c2032=t," + "c2033=t,c2034=t,c2035=t,c2036=t,c2037=t,c2038=t,c2039=t,c2040=t,c2041=t,c2042=t,c2043=t,c2044=t,c2045=t,c2046=t," + "c2047=t,c2048=t,c2049=t,c2050=t,c2051=t,c2052=t,c2053=t,c2054=t,c2055=t,c2056=t,c2057=t,c2058=t,c2059=t,c2060=t," + "c2061=t,c2062=t,c2063=t,c2064=t,c2065=t,c2066=t,c2067=t,c2068=t,c2069=t,c2070=t,c2071=t,c2072=t,c2073=t,c2074=t," + "c2075=t,c2076=t,c2077=t,c2078=t,c2079=t,c2080=t,c2081=t,c2082=t,c2083=t,c2084=t,c2085=t,c2086=t,c2087=t,c2088=t," + "c2089=t,c2090=t,c2091=t,c2092=t,c2093=t,c2094=t,c2095=t,c2096=t,c2097=t,c2098=t,c2099=t,c2100=t,c2101=t,c2102=t," + "c2103=t,c2104=t,c2105=t,c2106=t,c2107=t,c2108=t,c2109=t," + "c2110=t,c2111=t,c2112=t,c2113=t,c2114=t,c2115=t,c2116=t,c2117=t,c2118=t,c2119=t,c2120=t,c2121=t,c2122=t,c2123=t," + "c2124=t,c2125=t,c2126=t,c2127=t,c2128=t,c2129=t,c2130=t,c2131=t,c2132=t,c2133=t,c2134=t,c2135=t,c2136=t,c2137=t," + "c2138=t,c2139=t,c2140=t,c2141=t,c2142=t,c2143=t,c2144=t,c2145=t,c2146=t,c2147=t,c2148=t,c2149=t,c2150=t,c2151=t," + "c2152=t,c2153=t,c2154=t,c2155=t,c2156=t,c2157=t,c2158=t,c2159=t,c2160=t,c2161=t,c2162=t,c2163=t,c2164=t,c2165=t," + "c2166=t,c2167=t,c2168=t,c2169=t,c2170=t,c2171=t,c2172=t,c2173=t,c2174=t,c2175=t,c2176=t,c2177=t,c2178=t,c2179=t," + "c2180=t,c2181=t,c2182=t,c2183=t,c2184=t,c2185=t,c2186=t,c2187=t,c2188=t,c2189=t,c2190=t,c2191=t,c2192=t,c2193=t," + "c2194=t,c2195=t,c2196=t,c2197=t,c2198=t,c2199=t,c2200=t,c2201=t,c2202=t,c2203=t,c2204=t,c2205=t,c2206=t,c2207=t," + "c2208=t,c2209=t,c2210=t,c2211=t,c2212=t,c2213=t,c2214=t,c2215=t,c2216=t,c2217=t,c2218=t,c2219=t,c2220=t,c2221=t," + "c2222=t,c2223=t,c2224=t,c2225=t,c2226=t,c2227=t,c2228=t,c2229=t,c2230=t,c2231=t,c2232=t,c2233=t,c2234=t,c2235=t," + "c2236=t,c2237=t,c2238=t,c2239=t,c2240=t,c2241=t,c2242=t,c2243=t,c2244=t,c2245=t,c2246=t,c2247=t,c2248=t,c2249=t," + "c2250=t,c2251=t,c2252=t,c2253=t,c2254=t,c2255=t,c2256=t," + "c2257=t,c2258=t,c2259=t,c2260=t,c2261=t,c2262=t,c2263=t,c2264=t,c2265=t,c2266=t,c2267=t,c2268=t,c2269=t,c2270=t," + "c2271=t,c2272=t,c2273=t,c2274=t,c2275=t,c2276=t,c2277=t,c2278=t,c2279=t,c2280=t,c2281=t,c2282=t,c2283=t," + "c2284=t,c2285=t,c2286=t,c2287=t,c2288=t,c2289=t,c2290=t,c2291=t,c2292=t,c2293=t,c2294=t,c2295=t,c2296=t,c2297=t," + "c2298=t,c2299=t,c2300=t,c2301=t,c2302=t,c2303=t,c2304=t,c2305=t,c2306=t,c2307=t,c2308=t,c2309=t,c2310=t,c2311=t," + "c2312=t,c2313=t,c2314=t,c2315=t,c2316=t,c2317=t,c2318=t,c2319=t,c2320=t,c2321=t,c2322=t,c2323=t,c2324=t,c2325=t," + "c2326=t,c2327=t,c2328=t,c2329=t,c2330=t,c2331=t,c2332=t,c2333=t,c2334=t,c2335=t,c2336=t,c2337=t,c2338=t,c2339=t," + "c2340=t,c2341=t,c2342=t,c2343=t,c2344=t,c2345=t,c2346=t,c2347=t,c2348=t,c2349=t,c2350=t,c2351=t,c2352=t,c2353=t," + "c2354=t,c2355=t,c2356=t,c2357=t,c2358=t,c2359=t,c2360=t,c2361=t,c2362=t,c2363=t,c2364=t,c2365=t,c2366=t,c2367=t," + "c2368=t,c2369=t,c2370=t,c2371=t,c2372=t,c2373=t,c2374=t,c2375=t,c2376=t,c2377=t,c2378=t,c2379=t,c2380=t,c2381=t," + "c2382=t,c2383=t,c2384=t,c2385=t,c2386=t,c2387=t,c2388=t,c2389=t,c2390=t,c2391=t,c2392=t,c2393=t,c2394=t,c2395=t," + "c2396=t,c2397=t,c2398=t,c2399=t,c2400=t,c2401=t,c2402=t,c2403=t,c2404=t,c2405=t,c2406=t,c2407=t,c2408=t,c2409=t," + "c2410=t,c2411=t,c2412=t,c2413=t,c2414=t,c2415=t,c2416=t,c2417=t,c2418=t,c2419=t,c2420=t,c2421=t,c2422=t,c2423=t," + "c2424=t,c2425=t,c2426=t,c2427=t,c2428=t,c2429=t,c2430=t," + "c2431=t,c2432=t,c2433=t,c2434=t,c2435=t,c2436=t,c2437=t,c2438=t,c2439=t,c2440=t,c2441=t,c2442=t,c2443=t,c2444=t," + "c2445=t,c2446=t,c2447=t,c2448=t,c2449=t,c2450=t,c2451=t,c2452=t,c2453=t,c2454=t,c2455=t,c2456=t,c2457=t,c2458=t," + "c2459=t,c2460=t,c2461=t,c2462=t,c2463=t,c2464=t,c2465=t,c2466=t,c2467=t,c2468=t,c2469=t,c2470=t,c2471=t,c2472=t," + "c2473=t,c2474=t,c2475=t,c2476=t,c2477=t,c2478=t,c2479=t,c2480=t,c2481=t,c2482=t,c2483=t,c2484=t,c2485=t,c2486=t," + "c2487=t,c2488=t,c2489=t,c2490=t,c2491=t,c2492=t,c2493=t,c2494=t,c2495=t,c2496=t,c2497=t,c2498=t,c2499=t,c2500=t," + "c2501=t,c2502=t,c2503=t,c2504=t,c2505=t,c2506=t,c2507=t,c2508=t,c2509=t,c2510=t,c2511=t,c2512=t,c2513=t,c2514=t," + "c2515=t,c2516=t,c2517=t,c2518=t,c2519=t,c2520=t,c2521=t,c2522=t,c2523=t,c2524=t,c2525=t,c2526=t,c2527=t,c2528=t," + "c2529=t,c2530=t,c2531=t,c2532=t,c2533=t,c2534=t,c2535=t,c2536=t,c2537=t,c2538=t,c2539=t,c2540=t,c2541=t,c2542=t," + "c2543=t,c2544=t,c2545=t,c2546=t,c2547=t,c2548=t,c2549=t,c2550=t,c2551=t,c2552=t,c2553=t,c2554=t,c2555=t,c2556=t," + "c2557=t,c2558=t,c2559=t,c2560=t,c2561=t,c2562=t,c2563=t,c2564=t,c2565=t,c2566=t,c2567=t,c2568=t,c2569=t,c2570=t," + "c2571=t,c2572=t,c2573=t,c2574=t,c2575=t,c2576=t,c2577=t," + "c2578=t,c2579=t,c2580=t,c2581=t,c2582=t,c2583=t,c2584=t,c2585=t,c2586=t,c2587=t,c2588=t,c2589=t,c2590=t,c2591=t," + "c2592=t,c2593=t,c2594=t,c2595=t,c2596=t,c2597=t,c2598=t,c2599=t,c2600=t,c2601=t,c2602=t,c2603=t,c2604=t,c2605=t," + "c2606=t,c2607=t,c2608=t,c2609=t,c2610=t,c2611=t,c2612=t,c2613=t,c2614=t,c2615=t,c2616=t,c2617=t,c2618=t,c2619=t," + "c2620=t,c2621=t,c2622=t,c2623=t,c2624=t,c2625=t,c2626=t,c2627=t,c2628=t,c2629=t,c2630=t,c2631=t,c2632=t,c2633=t," + "c2634=t,c2635=t,c2636=t,c2637=t,c2638=t,c2639=t,c2640=t,c2641=t,c2642=t,c2643=t,c2644=t,c2645=t,c2646=t,c2647=t," + "c2648=t,c2649=t,c2650=t,c2651=t,c2652=t,c2653=t,c2654=t,c2655=t,c2656=t,c2657=t,c2658=t,c2659=t,c2660=t,c2661=t," + "c2662=t,c2663=t,c2664=t,c2665=t,c2666=t,c2667=t,c2668=t,c2669=t,c2670=t,c2671=t,c2672=t,c2673=t,c2674=t,c2675=t," + "c2676=t,c2677=t,c2678=t,c2679=t,c2680=t,c2681=t,c2682=t,c2683=t,c2684=t,c2685=t,c2686=t,c2687=t,c2688=t,c2689=t," + "c2690=t,c2691=t,c2692=t,c2693=t,c2694=t,c2695=t,c2696=t,c2697=t,c2698=t,c2699=t,c2700=t,c2701=t,c2702=t,c2703=t," + "c2704=t,c2705=t,c2706=t,c2707=t,c2708=t,c2709=t,c2710=t,c2711=t,c2712=t,c2713=t,c2714=t,c2715=t,c2716=t,c2717=t," + "c2718=t,c2719=t,c2720=t,c2721=t,c2722=t,c2723=t,c2724=t," + "c2725=t,c2726=t,c2727=t,c2728=t,c2729=t,c2730=t,c2731=t,c2732=t,c2733=t,c2734=t,c2735=t,c2736=t,c2737=t,c2738=t," + "c2739=t,c2740=t,c2741=t,c2742=t,c2743=t,c2744=t,c2745=t,c2746=t,c2747=t,c2748=t,c2749=t,c2750=t,c2751=t,c2752=t," + "c2753=t,c2754=t,c2755=t,c2756=t,c2757=t,c2758=t,c2759=t,c2760=t,c2761=t,c2762=t,c2763=t,c2764=t,c2765=t,c2766=t," + "c2767=t,c2768=t,c2769=t,c2770=t,c2771=t,c2772=t,c2773=t,c2774=t,c2775=t,c2776=t,c2777=t,c2778=t,c2779=t,c2780=t," + "c2781=t,c2782=t,c2783=t,c2784=t,c2785=t,c2786=t,c2787=t,c2788=t,c2789=t,c2790=t,c2791=t,c2792=t,c2793=t,c2794=t," + "c2795=t,c2796=t,c2797=t,c2798=t,c2799=t,c2800=t,c2801=t,c2802=t,c2803=t,c2804=t,c2805=t,c2806=t,c2807=t,c2808=t," + "c2809=t,c2810=t,c2811=t,c2812=t,c2813=t,c2814=t,c2815=t,c2816=t,c2817=t,c2818=t,c2819=t,c2820=t,c2821=t,c2822=t," + "c2823=t,c2824=t,c2825=t,c2826=t,c2827=t,c2828=t,c2829=t,c2830=t,c2831=t,c2832=t,c2833=t,c2834=t,c2835=t,c2836=t," + "c2837=t,c2838=t,c2839=t,c2840=t,c2841=t,c2842=t,c2843=t,c2844=t,c2845=t,c2846=t,c2847=t,c2848=t,c2849=t,c2850=t," + "c2851=t,c2852=t,c2853=t,c2854=t,c2855=t,c2856=t,c2857=t,c2858=t,c2859=t,c2860=t,c2861=t,c2862=t,c2863=t,c2864=t," + "c2865=t,c2866=t,c2867=t,c2868=t,c2869=t,c2870=t,c2871=t," + "c2872=t,c2873=t,c2874=t,c2875=t,c2876=t,c2877=t,c2878=t,c2879=t,c2880=t,c2881=t,c2882=t,c2883=t,c2884=t,c2885=t," + "c2886=t,c2887=t,c2888=t,c2889=t,c2890=t,c2891=t,c2892=t,c2893=t,c2894=t,c2895=t,c2896=t,c2897=t,c2898=t,c2899=t," + "c2900=t,c2901=t,c2902=t,c2903=t,c2904=t,c2905=t,c2906=t,c2907=t,c2908=t,c2909=t,c2910=t,c2911=t,c2912=t,c2913=t," + "c2914=t,c2915=t,c2916=t,c2917=t,c2918=t,c2919=t,c2920=t,c2921=t,c2922=t,c2923=t,c2924=t,c2925=t,c2926=t,c2927=t," + "c2928=t,c2929=t,c2930=t,c2931=t,c2932=t,c2933=t,c2934=t,c2935=t,c2936=t,c2937=t,c2938=t,c2939=t,c2940=t,c2941=t," + "c2942=t,c2943=t,c2944=t,c2945=t,c2946=t,c2947=t,c2948=t,c2949=t,c2950=t,c2951=t,c2952=t,c2953=t,c2954=t,c2955=t," + "c2956=t,c2957=t,c2958=t,c2959=t,c2960=t,c2961=t,c2962=t,c2963=t,c2964=t,c2965=t,c2966=t,c2967=t,c2968=t,c2969=t," + "c2970=t,c2971=t,c2972=t,c2973=t,c2974=t,c2975=t,c2976=t,c2977=t,c2978=t,c2979=t,c2980=t,c2981=t,c2982=t,c2983=t," + "c2984=t,c2985=t,c2986=t,c2987=t,c2988=t,c2989=t,c2990=t,c2991=t,c2992=t,c2993=t,c2994=t,c2995=t,c2996=t,c2997=t," + "c2998=t,c2999=t,c3000=t,c3001=t,c3002=t,c3003=t,c3004=t,c3005=t,c3006=t,c3007=t,c3008=t,c3009=t,c3010=t,c3011=t," + "c3012=t,c3013=t,c3014=t,c3015=t,c3016=t,c3017=t,c3018=t," + "c3019=t,c3020=t,c3021=t,c3022=t,c3023=t,c3024=t,c3025=t,c3026=t,c3027=t,c3028=t,c3029=t,c3030=t,c3031=t,c3032=t," + "c3033=t,c3034=t,c3035=t,c3036=t,c3037=t,c3038=t,c3039=t,c3040=t,c3041=t,c3042=t,c3043=t,c3044=t,c3045=t,c3046=t," + "c3047=t,c3048=t,c3049=t,c3050=t,c3051=t,c3052=t,c3053=t,c3054=t,c3055=t,c3056=t,c3057=t,c3058=t,c3059=t,c3060=t," + "c3061=t,c3062=t,c3063=t,c3064=t,c3065=t,c3066=t,c3067=t,c3068=t,c3069=t,c3070=t,c3071=t,c3072=t,c3073=t,c3074=t," + "c3075=t,c3076=t,c3077=t,c3078=t,c3079=t,c3080=t,c3081=t,c3082=t,c3083=t,c3084=t,c3085=t,c3086=t,c3087=t,c3088=t," + "c3089=t,c3090=t,c3091=t,c3092=t,c3093=t,c3094=t,c3095=t,c3096=t,c3097=t,c3098=t,c3099=t,c3100=t,c3101=t,c3102=t," + "c3103=t,c3104=t,c3105=t,c3106=t,c3107=t,c3108=t,c3109=t,c3110=t,c3111=t,c3112=t,c3113=t,c3114=t,c3115=t,c3116=t," + "c3117=t,c3118=t,c3119=t,c3120=t,c3121=t,c3122=t,c3123=t,c3124=t,c3125=t,c3126=t,c3127=t,c3128=t,c3129=t,c3130=t," + "c3131=t,c3132=t,c3133=t,c3134=t,c3135=t,c3136=t,c3137=t,c3138=t,c3139=t,c3140=t,c3141=t,c3142=t,c3143=t,c3144=t," + "c3145=t,c3146=t,c3147=t,c3148=t,c3149=t,c3150=t,c3151=t,c3152=t,c3153=t,c3154=t,c3155=t,c3156=t,c3157=t,c3158=t," + "c3159=t,c3160=t,c3161=t,c3162=t,c3163=t,c3164=t,c3165=t," + "c3166=t,c3167=t,c3168=t,c3169=t,c3170=t,c3171=t,c3172=t,c3173=t,c3174=t,c3175=t,c3176=t,c3177=t,c3178=t,c3179=t," + "c3180=t,c3181=t,c3182=t,c3183=t,c3184=t,c3185=t,c3186=t,c3187=t,c3188=t,c3189=t,c3190=t,c3191=t,c3192=t,c3193=t," + "c3194=t,c3195=t,c3196=t,c3197=t,c3198=t,c3199=t,c3200=t,c3201=t,c3202=t,c3203=t,c3204=t,c3205=t,c3206=t,c3207=t," + "c3208=t,c3209=t,c3210=t,c3211=t,c3212=t,c3213=t,c3214=t,c3215=t,c3216=t,c3217=t,c3218=t,c3219=t,c3220=t,c3221=t," + "c3222=t,c3223=t,c3224=t,c3225=t,c3226=t,c3227=t,c3228=t,c3229=t,c3230=t,c3231=t,c3232=t,c3233=t,c3234=t,c3235=t," + "c3236=t,c3237=t,c3238=t,c3239=t,c3240=t,c3241=t,c3242=t,c3243=t,c3244=t,c3245=t,c3246=t,c3247=t,c3248=t,c3249=t," + "c3250=t,c3251=t,c3252=t,c3253=t,c3254=t,c3255=t,c3256=t,c3257=t,c3258=t,c3259=t,c3260=t,c3261=t,c3262=t,c3263=t," + "c3264=t,c3265=t,c3266=t,c3267=t,c3268=t,c3269=t,c3270=t,c3271=t,c3272=t,c3273=t,c3274=t,c3275=t,c3276=t,c3277=t," + "c3278=t,c3279=t,c3280=t,c3281=t,c3282=t,c3283=t,c3284=t,c3285=t,c3286=t,c3287=t,c3288=t,c3289=t,c3290=t,c3291=t," + "c3292=t,c3293=t,c3294=t,c3295=t,c3296=t,c3297=t,c3298=t,c3299=t,c3300=t,c3301=t,c3302=t,c3303=t,c3304=t,c3305=t," + "c3306=t,c3307=t,c3308=t,c3309=t,c3310=t,c3311=t,c3312=t," + "c3313=t,c3314=t,c3315=t,c3316=t,c3317=t,c3318=t,c3319=t,c3320=t,c3321=t,c3322=t,c3323=t,c3324=t,c3325=t,c3326=t," + "c3327=t,c3328=t,c3329=t,c3330=t,c3331=t,c3332=t,c3333=t,c3334=t,c3335=t,c3336=t,c3337=t,c3338=t,c3339=t,c3340=t," + "c3341=t,c3342=t,c3343=t,c3344=t,c3345=t,c3346=t,c3347=t,c3348=t,c3349=t,c3350=t,c3351=t,c3352=t,c3353=t,c3354=t," + "c3355=t,c3356=t,c3357=t,c3358=t,c3359=t,c3360=t,c3361=t,c3362=t,c3363=t,c3364=t,c3365=t,c3366=t,c3367=t,c3368=t," + "c3369=t,c3370=t,c3371=t,c3372=t,c3373=t,c3374=t,c3375=t,c3376=t,c3377=t,c3378=t,c3379=t,c3380=t,c3381=t,c3382=t," + "c3383=t,c3384=t,c3385=t,c3386=t,c3387=t,c3388=t,c3389=t,c3390=t,c3391=t,c3392=t,c3393=t,c3394=t,c3395=t,c3396=t," + "c3397=t,c3398=t,c3399=t,c3400=t,c3401=t,c3402=t,c3403=t,c3404=t,c3405=t,c3406=t,c3407=t,c3408=t,c3409=t,c3410=t," + "c3411=t,c3412=t,c3413=t,c3414=t,c3415=t,c3416=t,c3417=t,c3418=t,c3419=t,c3420=t,c3421=t,c3422=t,c3423=t,c3424=t," + "c3425=t,c3426=t,c3427=t,c3428=t,c3429=t,c3430=t,c3431=t,c3432=t,c3433=t,c3434=t,c3435=t,c3436=t,c3437=t,c3438=t," + "c3439=t,c3440=t,c3441=t,c3442=t,c3443=t,c3444=t,c3445=t,c3446=t,c3447=t,c3448=t,c3449=t,c3450=t,c3451=t,c3452=t," + "c3453=t,c3454=t,c3455=t,c3456=t,c3457=t,c3458=t,c3459=t," + "c3460=t,c3461=t,c3462=t,c3463=t,c3464=t,c3465=t,c3466=t,c3467=t,c3468=t,c3469=t,c3470=t,c3471=t,c3472=t,c3473=t," + "c3474=t,c3475=t,c3476=t,c3477=t,c3478=t,c3479=t,c3480=t,c3481=t,c3482=t,c3483=t,c3484=t,c3485=t,c3486=t,c3487=t," + "c3488=t,c3489=t,c3490=t,c3491=t,c3492=t,c3493=t,c3494=t,c3495=t,c3496=t,c3497=t,c3498=t,c3499=t,c3500=t,c3501=t," + "c3502=t,c3503=t,c3504=t,c3505=t,c3506=t,c3507=t,c3508=t,c3509=t,c3510=t,c3511=t,c3512=t,c3513=t," + "c3514=t,c3515=t,c3516=t,c3517=t,c3518=t,c3519=t,c3520=t,c3521=t,c3522=t,c3523=t,c3524=t,c3525=t,c3526=t,c3527=t," + "c3528=t,c3529=t,c3530=t,c3531=t,c3532=t,c3533=t,c3534=t,c3535=t,c3536=t,c3537=t,c3538=t,c3539=t,c3540=t,c3541=t," + "c3542=t,c3543=t,c3544=t,c3545=t,c3546=t,c3547=t,c3548=t,c3549=t,c3550=t,c3551=t,c3552=t,c3553=t,c3554=t,c3555=t," + "c3556=t,c3557=t,c3558=t,c3559=t,c3560=t,c3561=t,c3562=t,c3563=t,c3564=t,c3565=t,c3566=t,c3567=t,c3568=t,c3569=t," + "c3570=t,c3571=t,c3572=t,c3573=t,c3574=t,c3575=t,c3576=t,c3577=t,c3578=t,c3579=t,c3580=t,c3581=t,c3582=t,c3583=t," + "c3584=t,c3585=t,c3586=t,c3587=t,c3588=t,c3589=t,c3590=t,c3591=t,c3592=t,c3593=t,c3594=t,c3595=t,c3596=t,c3597=t," + "c3598=t,c3599=t,c3600=t,c3601=t,c3602=t,c3603=t,c3604=t,c3605=t,c3606=t,c3607=t,c3608=t,c3609=t,c3610=t,c3611=t," + "c3612=t,c3613=t,c3614=t,c3615=t,c3616=t,c3617=t,c3618=t,c3619=t,c3620=t,c3621=t,c3622=t,c3623=t,c3624=t,c3625=t," + "c3626=t,c3627=t,c3628=t,c3629=t,c3630=t,c3631=t,c3632=t,c3633=t,c3634=t,c3635=t,c3636=t,c3637=t,c3638=t,c3639=t," + "c3640=t,c3641=t,c3642=t,c3643=t,c3644=t,c3645=t,c3646=t,c3647=t,c3648=t,c3649=t,c3650=t,c3651=t,c3652=t,c3653=t," + "c3654=t,c3655=t,c3656=t,c3657=t,c3658=t,c3659=t,c3660=t," + "c3661=t,c3662=t,c3663=t,c3664=t,c3665=t,c3666=t,c3667=t,c3668=t,c3669=t,c3670=t,c3671=t,c3672=t,c3673=t,c3674=t," + "c3675=t,c3676=t,c3677=t,c3678=t,c3679=t,c3680=t,c3681=t,c3682=t,c3683=t,c3684=t,c3685=t,c3686=t,c3687=t,c3688=t," + "c3689=t,c3690=t,c3691=t,c3692=t,c3693=t,c3694=t,c3695=t,c3696=t,c3697=t,c3698=t,c3699=t,c3700=t,c3701=t,c3702=t," + "c3703=t,c3704=t,c3705=t,c3706=t,c3707=t,c3708=t,c3709=t,c3710=t,c3711=t,c3712=t,c3713=t,c3714=t,c3715=t,c3716=t," + "c3717=t,c3718=t,c3719=t,c3720=t,c3721=t,c3722=t,c3723=t,c3724=t,c3725=t,c3726=t,c3727=t,c3728=t,c3729=t,c3730=t," + "c3731=t,c3732=t,c3733=t,c3734=t,c3735=t,c3736=t,c3737=t,c3738=t,c3739=t,c3740=t,c3741=t,c3742=t,c3743=t,c3744=t," + "c3745=t,c3746=t,c3747=t,c3748=t,c3749=t,c3750=t,c3751=t,c3752=t,c3753=t,c3754=t,c3755=t,c3756=t,c3757=t,c3758=t," + "c3759=t,c3760=t,c3761=t,c3762=t,c3763=t,c3764=t,c3765=t,c3766=t,c3767=t,c3768=t,c3769=t,c3770=t,c3771=t,c3772=t," + "c3773=t,c3774=t,c3775=t,c3776=t,c3777=t,c3778=t,c3779=t,c3780=t,c3781=t,c3782=t,c3783=t,c3784=t,c3785=t,c3786=t," + "c3787=t,c3788=t,c3789=t,c3790=t,c3791=t,c3792=t,c3793=t,c3794=t,c3795=t,c3796=t,c3797=t,c3798=t,c3799=t,c3800=t," + "c3801=t,c3802=t,c3803=t,c3804=t,c3805=t,c3806=t,c3807=t," + "c3808=t,c3809=t,c3810=t,c3811=t,c3812=t,c3813=t,c3814=t,c3815=t,c3816=t,c3817=t,c3818=t,c3819=t,c3820=t,c3821=t," + "c3822=t,c3823=t,c3824=t,c3825=t,c3826=t,c3827=t,c3828=t,c3829=t,c3830=t,c3831=t,c3832=t,c3833=t,c3834=t,c3835=t," + "c3836=t,c3837=t,c3838=t,c3839=t,c3840=t,c3841=t,c3842=t,c3843=t,c3844=t,c3845=t,c3846=t,c3847=t,c3848=t,c3849=t," + "c3850=t,c3851=t,c3852=t,c3853=t,c3854=t,c3855=t,c3856=t,c3857=t,c3858=t,c3859=t,c3860=t,c3861=t,c3862=t,c3863=t," + "c3864=t,c3865=t,c3866=t,c3867=t,c3868=t,c3869=t,c3870=t,c3871=t,c3872=t,c3873=t,c3874=t,c3875=t,c3876=t,c3877=t," + "c3878=t,c3879=t,c3880=t,c3881=t,c3882=t,c3883=t,c3884=t,c3885=t,c3886=t,c3887=t,c3888=t,c3889=t,c3890=t,c3891=t," + "c3892=t,c3893=t,c3894=t,c3895=t,c3896=t,c3897=t,c3898=t,c3899=t,c3900=t,c3901=t,c3902=t,c3903=t,c3904=t,c3905=t," + "c3906=t,c3907=t,c3908=t,c3909=t,c3910=t,c3911=t,c3912=t,c3913=t,c3914=t,c3915=t,c3916=t,c3917=t,c3918=t,c3919=t," + "c3920=t,c3921=t,c3922=t,c3923=t,c3924=t,c3925=t,c3926=t,c3927=t,c3928=t,c3929=t,c3930=t,c3931=t,c3932=t,c3933=t," + "c3934=t,c3935=t,c3936=t,c3937=t,c3938=t,c3939=t,c3940=t,c3941=t,c3942=t,c3943=t,c3944=t,c3945=t,c3946=t,c3947=t," + "c3948=t,c3949=t,c3950=t,c3951=t,c3952=t,c3953=t,c3954=t," + "c3955=t,c3956=t,c3957=t,c3958=t,c3959=t,c3960=t,c3961=t,c3962=t,c3963=t,c3964=t,c3965=t,c3966=t,c3967=t,c3968=t," + "c3969=t,c3970=t,c3971=t,c3972=t,c3973=t,c3974=t,c3975=t,c3976=t,c3977=t,c3978=t,c3979=t,c3980=t,c3981=t,c3982=t," + "c3983=t,c3984=t,c3985=t,c3986=t,c3987=t,c3988=t,c3989=t,c3990=t,c3991=t,c3992=t,c3993=t,c3994=t,c3995=t,c3996=t," + "c3997=t,c3998=t,c3999=t,c4000=t,c4001=t,c4002=t,c4003=t,c4004=t,c4005=t,c4006=t,c4007=t,c4008=t,c4009=t,c4010=t," + "c4011=t,c4012=t,c4013=t,c4014=t,c4015=t,c4016=t,c4017=t,c4018=t,c4019=t,c4020=t,c4021=t,c4022=t,c4023=t,c4024=t," + "c4025=t,c4026=t,c4027=t,c4028=t,c4029=t,c4030=t,c4031=t,c4032=t,c4033=t,c4034=t,c4035=t,c4036=t,c4037=t,c4038=t," + "c4039=t,c4040=t,c4041=t,c4042=t,c4043=t,c4044=t,c4045=t,c4046=t,c4047=t,c4048=t,c4049=t,c4050=t,c4051=t,c4052=t," + "c4053=t,c4054=t,c4055=t,c4056=t,c4057=t,c4058=t,c4059=t,c4060=t,c4061=t,c4062=t,c4063=t,c4064=t,c4065=t,c4066=t," + "c4067=t,c4068=t,c4069=t,c4070=t,c4071=t,c4072=t,c4073=t,c4074=t,c4075=t,c4076=t,c4077=t,c4078=t,c4079=t,c4080=t," + "c4081=t,c4082=t,c4083=t,c4084=t,c4085=t,c4086=t,c4087=t,c4088=t,c4089=t,c4090=t,c4091=t,c4092=t,c4093=t " + "1626006833640000000"}; int ret = TSDB_CODE_SUCCESS; - for(int i = 0; i < sizeof(sql)/sizeof(sql[0]); i++){ + for (int i = 0; i < sizeof(sql) / sizeof(sql[0]); i++) { ret = smlParseInfluxLine(info, sql[i]); - if(ret != TSDB_CODE_SUCCESS) break; + if (ret != TSDB_CODE_SUCCESS) break; } ASSERT_NE(ret, 0); smlDestroyInfo(info); diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 88df54a9eace1c310af0c0e9787d8a8774803e97..56daa4075a4ca244da17bbd6d32a51b906856393 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -90,6 +90,7 @@ bool tsSmlDataFormat = false; // query int32_t tsQueryPolicy = 1; +int32_t tsQueryRspPolicy = 0; int32_t tsQuerySmaOptimize = 0; int32_t tsQueryRsmaTolerance = 1000; // the tolerance time (ms) to judge from which level to query rsma data. bool tsQueryPlannerTrace = false; @@ -350,6 +351,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "countAlwaysReturnValue", tsCountAlwaysReturnValue, 0, 1, 0) != 0) return -1; if (cfgAddInt32(pCfg, "queryBufferSize", tsQueryBufferSize, -1, 500000000000, 0) != 0) return -1; if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "queryRspPolicy", tsQueryRspPolicy, 0, 1, 0) != 0) return -1; if (cfgAddInt32(pCfg, "multiProcess", tsMultiProcess, 0, 2, 0) != 0) return -1; if (cfgAddInt32(pCfg, "mnodeShmSize", tsMnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; @@ -728,6 +730,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsMonitorPort = (uint16_t)cfgGetItem(pCfg, "monitorPort")->i32; tsMonitorMaxLogs = cfgGetItem(pCfg, "monitorMaxLogs")->i32; tsMonitorComp = cfgGetItem(pCfg, "monitorComp")->bval; + tsQueryRspPolicy = cfgGetItem(pCfg, "queryRspPolicy")->i32; tsEnableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval; tsTelemInterval = cfgGetItem(pCfg, "telemetryInterval")->i32; diff --git a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h index a4c37dd334984ff5e834463ec802b937ff557460..17cbde437b2e94d8d111c76600ddef8fb7767818 100644 --- a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h +++ b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h @@ -41,8 +41,8 @@ typedef struct SMnodeMgmt { } SMnodeMgmt; // mmFile.c -int32_t mmReadFile(SMnodeMgmt *pMgmt, SReplica *pReplica, bool *pDeployed); -int32_t mmWriteFile(SMnodeMgmt *pMgmt, const SReplica *pReplica, bool deployed); +int32_t mmReadFile(const char *path, SMnodeOpt *pOption); +int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption); // mmHandle.c SArray *mmGetMsgHandles(); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c index 27a35ae17a859ba1f5fd7289e04c921c775b904a..c5ddb9f021c65a2ac7f616a9236bced7954a2aa0 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "mmInt.h" -int32_t mmReadFile(SMnodeMgmt *pMgmt, SReplica *pReplica, bool *pDeployed) { +int32_t mmReadFile(const char *path, SMnodeOpt *pOption) { int32_t code = TSDB_CODE_INVALID_JSON_FORMAT; int32_t len = 0; int32_t maxLen = 4096; @@ -25,7 +25,7 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, SReplica *pReplica, bool *pDeployed) { char file[PATH_MAX] = {0}; TdFilePtr pFile = NULL; - snprintf(file, sizeof(file), "%s%smnode.json", pMgmt->path, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { code = 0; @@ -50,38 +50,69 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, SReplica *pReplica, bool *pDeployed) { dError("failed to read %s since deployed not found", file); goto _OVER; } - *pDeployed = deployed->valueint; + pOption->deploy = deployed->valueint; - cJSON *id = cJSON_GetObjectItem(root, "id"); - if (id) { - if (id->type != cJSON_Number) { - dError("failed to read %s since id not found", file); + cJSON *selfIndex = cJSON_GetObjectItem(root, "selfIndex"); + if (selfIndex) { + if (selfIndex->type != cJSON_Number) { + dError("failed to read %s since selfIndex not found", file); goto _OVER; } - if (pReplica) { - pReplica->id = id->valueint; - } + pOption->selfIndex = selfIndex->valueint; } - cJSON *fqdn = cJSON_GetObjectItem(root, "fqdn"); - if (fqdn) { - if (fqdn->type != cJSON_String || fqdn->valuestring == NULL) { - dError("failed to read %s since fqdn not found", file); + cJSON *replicas = cJSON_GetObjectItem(root, "replicas"); + if (replicas) { + if (replicas->type != cJSON_Array) { + dError("failed to read %s since replicas not found", file); goto _OVER; } - if (pReplica) { - tstrncpy(pReplica->fqdn, fqdn->valuestring, TSDB_FQDN_LEN); - } - } - cJSON *port = cJSON_GetObjectItem(root, "port"); - if (port) { - if (port->type != cJSON_Number) { - dError("failed to read %s since port not found", file); + int32_t numOfReplicas = cJSON_GetArraySize(replicas); + if (numOfReplicas <= 0) { + dError("failed to read %s since numOfReplicas:%d invalid", file, numOfReplicas); goto _OVER; } - if (pReplica) { - pReplica->port = (uint16_t)port->valueint; + pOption->numOfReplicas = numOfReplicas; + + for (int32_t i = 0; i < numOfReplicas; ++i) { + SReplica *pReplica = pOption->replicas + i; + + cJSON *replica = cJSON_GetArrayItem(replicas, i); + if (replica == NULL) break; + + cJSON *id = cJSON_GetObjectItem(replica, "id"); + if (id) { + if (id->type != cJSON_Number) { + dError("failed to read %s since id not found", file); + goto _OVER; + } + if (pReplica) { + pReplica->id = id->valueint; + } + } + + cJSON *fqdn = cJSON_GetObjectItem(replica, "fqdn"); + if (fqdn) { + if (fqdn->type != cJSON_String || fqdn->valuestring == NULL) { + dError("failed to read %s since fqdn not found", file); + goto _OVER; + } + if (pReplica) { + tstrncpy(pReplica->fqdn, fqdn->valuestring, TSDB_FQDN_LEN); + } + } + + cJSON *port = cJSON_GetObjectItem(replica, "port"); + if (port) { + if (port->type != cJSON_Number) { + dError("failed to read %s since port not found", file); + goto _OVER; + } + if (pReplica) { + pReplica->port = (uint16_t)port->valueint; + } + } } } @@ -92,18 +123,18 @@ _OVER: if (root != NULL) cJSON_Delete(root); if (pFile != NULL) taosCloseFile(&pFile); if (code == 0) { - dDebug("succcessed to read file %s, deployed:%d", file, *pDeployed); + dDebug("succcessed to read file %s, deployed:%d", file, pOption->deploy); } terrno = code; return code; } -int32_t mmWriteFile(SMnodeMgmt *pMgmt, const SReplica *pReplica, bool deployed) { +int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) { char file[PATH_MAX] = {0}; char realfile[PATH_MAX] = {0}; - snprintf(file, sizeof(file), "%s%smnode.json.bak", pMgmt->path, TD_DIRSEP); - snprintf(realfile, sizeof(realfile), "%s%smnode.json", pMgmt->path, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP); TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { @@ -117,12 +148,25 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, const SReplica *pReplica, bool deployed) char *content = taosMemoryCalloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); - if (pReplica != NULL && pReplica->id > 0) { - len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id); - len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn); - len += snprintf(content + len, maxLen - len, " \"port\": %u\n,", pReplica->port); + if (pOption->deploy && pOption->numOfReplicas > 0) { + len += snprintf(content + len, maxLen - len, " \"selfIndex\": %d,\n", pOption->selfIndex); + len += snprintf(content + len, maxLen - len, " \"replicas\": [{\n"); + + for (int32_t i = 0; i < pOption->numOfReplicas; ++i) { + const SReplica *pReplica = pOption->replicas + i; + if (pReplica != NULL && pReplica->id > 0) { + len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id); + len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn); + len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port); + } + if (i < pOption->numOfReplicas - 1) { + len += snprintf(content + len, maxLen - len, " },{\n"); + } else { + len += snprintf(content + len, maxLen - len, " }],\n"); + } + } } - len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed); + len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", pOption->deploy); len += snprintf(content + len, maxLen - len, "}\n"); taosWriteFile(pFile, content, len); @@ -136,6 +180,6 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, const SReplica *pReplica, bool deployed) return -1; } - dDebug("successed to write %s, deployed:%d", realfile, deployed); + dDebug("successed to write %s, deployed:%d", realfile, pOption->deploy); return 0; } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index ec761e6441ce651db5d6f3b034e4f11b1686fcdc..fc45dbf15f0630cf505db8cf013ff6297f27eb9e 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -80,18 +80,21 @@ int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) { return -1; } - if (createReq.replica != 1) { + SMnodeOpt option = {.deploy = true, .numOfReplicas = createReq.replica, .selfIndex = -1}; + memcpy(option.replicas, createReq.replicas, sizeof(createReq.replicas)); + for (int32_t i = 0; i < option.numOfReplicas; ++i) { + if (createReq.replicas[i].id == pInput->pData->dnodeId) { + option.selfIndex = i; + } + } + + if (option.selfIndex == -1) { terrno = TSDB_CODE_INVALID_OPTION; - dGError("failed to create mnode since %s", terrstr()); + dGError("failed to create mnode since %s, selfIndex is -1", terrstr()); return -1; } - bool deployed = true; - - SMnodeMgmt mgmt = {0}; - mgmt.path = pInput->path; - mgmt.name = pInput->name; - if (mmWriteFile(&mgmt, &createReq.replicas[0], deployed) != 0) { + if (mmWriteFile(pInput->path, &option) != 0) { dGError("failed to write mnode file since %s", terrstr()); return -1; } @@ -113,12 +116,8 @@ int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) { return -1; } - bool deployed = false; - - SMnodeMgmt mgmt = {0}; - mgmt.path = pInput->path; - mgmt.name = pInput->name; - if (mmWriteFile(&mgmt, NULL, deployed) != 0) { + SMnodeOpt option = {.deploy = false}; + if (mmWriteFile(pInput->path, &option) != 0) { dGError("failed to write mnode file since %s", terrstr()); return -1; } @@ -207,7 +206,6 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_HEARTBEAT, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_STATUS, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_SYSTABLE_RETRIEVE, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; - // if (dmSetMgmtHandle(pArray, TDMT_MND_GRANT, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_AUTH, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_SHOW_VARIABLES, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_SERVER_VERSION, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 49207225a5d4877eb138a75fb89bb2c5e7f1e474..e7f71ad4200bd2b1c3c5fcf10e82aa9aa0ea417f 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -25,38 +25,35 @@ static bool mmDeployRequired(const SMgmtInputOpt *pInput) { } static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) { - SMnodeMgmt mgmt = {0}; - mgmt.path = pInput->path; - if (mmReadFile(&mgmt, NULL, required) != 0) { + SMnodeOpt option = {0}; + if (mmReadFile(pInput->path, &option) != 0) { return -1; } - if (!(*required)) { + if (!option.deploy) { *required = mmDeployRequired(pInput); + } else { + *required = true; } return 0; } static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInput, SMnodeOpt *pOption) { - pOption->standby = false; pOption->deploy = true; pOption->msgCb = pMgmt->msgCb; pOption->dnodeId = pMgmt->pData->dnodeId; - pOption->replica.id = 1; - pOption->replica.port = tsServerPort; - tstrncpy(pOption->replica.fqdn, tsLocalFqdn, TSDB_FQDN_LEN); + pOption->selfIndex = 0; + pOption->numOfReplicas = 1; + pOption->replicas[0].id = 1; + pOption->replicas[0].port = tsServerPort; + tstrncpy(pOption->replicas[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); } -static void mmBuildOptionForOpen(SMnodeMgmt *pMgmt, const SReplica *pReplica, SMnodeOpt *pOption) { - pOption->standby = false; +static void mmBuildOptionForOpen(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { pOption->deploy = false; pOption->msgCb = pMgmt->msgCb; pOption->dnodeId = pMgmt->pData->dnodeId; - if (pReplica->id > 0) { - pOption->standby = true; - pOption->replica = *pReplica; - } } static void mmClose(SMnodeMgmt *pMgmt) { @@ -95,22 +92,20 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) { pMgmt->msgCb.mgmt = pMgmt; taosThreadRwlockInit(&pMgmt->lock, NULL); - bool deployed = false; - SReplica replica = {0}; - if (mmReadFile(pMgmt, &replica, &deployed) != 0) { + SMnodeOpt option = {0}; + if (mmReadFile(pMgmt->path, &option) != 0) { dError("failed to read file since %s", terrstr()); mmClose(pMgmt); return -1; } - SMnodeOpt option = {0}; - if (!deployed) { + if (!option.deploy) { dInfo("mnode start to deploy"); pMgmt->pData->dnodeId = 1; mmBuildOptionForDeploy(pMgmt, pInput, &option); } else { dInfo("mnode start to open"); - mmBuildOptionForOpen(pMgmt, &replica, &option); + mmBuildOptionForOpen(pMgmt, &option); } pMgmt->pMnode = mndOpen(pMgmt->path, &option); @@ -128,9 +123,10 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) { } tmsgReportStartup("mnode-worker", "initialized"); - if (!deployed || replica.id > 0) { - deployed = true; - if (mmWriteFile(pMgmt, NULL, deployed) != 0) { + if (option.numOfReplicas > 0) { + option.deploy = true; + option.numOfReplicas = 0; + if (mmWriteFile(pMgmt->path, &option) != 0) { dError("failed to write mnode file since %s", terrstr()); return -1; } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c index d2b071ec61d7343f826ed9975cd6b07745399357..849d3ef39019fcb5ce9dfb987cac4772e91839a7 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c @@ -72,7 +72,7 @@ static void mmProcessRpcMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) { mndPostProcessQueryMsg(pMsg); } - dGTrace("msg:%p, is freed, code:0x%x", pMsg, code); + dGTrace("msg:%p is freed, code:%s", pMsg, tstrerror(code)); rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); } diff --git a/source/dnode/mgmt/node_mgmt/src/dmEnv.c b/source/dnode/mgmt/node_mgmt/src/dmEnv.c index d07ec7abb03501f1fe627f66dce36228df014fad..076826ebc2d0956aad14f8eeec27a574425788b1 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmEnv.c +++ b/source/dnode/mgmt/node_mgmt/src/dmEnv.c @@ -51,26 +51,14 @@ static int32_t dmInitMonitor() { static bool dmCheckDiskSpace() { osUpdate(); - if (!osDataSpaceAvailable()) { - dError("free disk size: %f GB, too little, require %f GB at least at least , quit", - (double)tsDataSpace.size.avail / 1024.0 / 1024.0 / 1024.0, - (double)tsDataSpace.reserved / 1024.0 / 1024.0 / 1024.0); - terrno = TSDB_CODE_NO_AVAIL_DISK; - return false; + if (!osDataSpaceSufficient()) { + dWarn("free data disk size: %f GB, not sufficient, expected %f GB at least", (double)tsDataSpace.size.avail / 1024.0 / 1024.0 / 1024.0, (double)tsDataSpace.reserved / 1024.0 / 1024.0 / 1024.0); } - if (!osLogSpaceAvailable()) { - dError("free disk size: %f GB, too little, require %f GB at least at least, quit", - (double)tsLogSpace.size.avail / 1024.0 / 1024.0 / 1024.0, - (double)tsLogSpace.reserved / 1024.0 / 1024.0 / 1024.0); - terrno = TSDB_CODE_NO_AVAIL_DISK; - return false; + if (!osLogSpaceSufficient()) { + dWarn("free log disk size: %f GB, not sufficient, expected %f GB at least", (double)tsLogSpace.size.avail / 1024.0 / 1024.0 / 1024.0, (double)tsLogSpace.reserved / 1024.0 / 1024.0 / 1024.0); } - if (!osTempSpaceAvailable()) { - dError("free disk size: %f GB, too little, require %f GB at least at least, quit", - (double)tsTempSpace.size.avail / 1024.0 / 1024.0 / 1024.0, - (double)tsTempSpace.reserved / 1024.0 / 1024.0 / 1024.0); - terrno = TSDB_CODE_NO_AVAIL_DISK; - return false; + if (!osTempSpaceSufficient()) { + dWarn("free temp disk size: %f GB, not sufficient, expected %f GB at least", (double)tsTempSpace.size.avail / 1024.0 / 1024.0 / 1024.0, (double)tsTempSpace.reserved / 1024.0 / 1024.0 / 1024.0); } return true; } diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 71315a39fd6c75d7b09e7371a9e0af30577a54d8..f55e830a44c8d341e25cd294ee31c56ed7707277 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -87,12 +87,13 @@ typedef struct { typedef struct { tsem_t syncSem; int64_t sync; - SReplica replica; int32_t errCode; int32_t transId; SRWLatch lock; - int8_t standby; int8_t leaderTransferFinish; + int8_t selfIndex; + int8_t numOfReplicas; + SReplica replicas[TSDB_MAX_REPLICA]; } SSyncMgmt; typedef struct { @@ -130,11 +131,10 @@ typedef struct SMnode { void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); int64_t mndGenerateUid(const char *name, int32_t len); -int32_t mndAcquireRpcRef(SMnode *pMnode); -void mndReleaseRpcRef(SMnode *pMnode); -void mndSetRestore(SMnode *pMnode, bool restored); -void mndSetStop(SMnode *pMnode); -bool mndGetStop(SMnode *pMnode); +void mndSetRestored(SMnode *pMnode, bool restored); +bool mndGetRestored(SMnode *pMnode); +void mndSetStop(SMnode *pMnode); +bool mndGetStop(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndSync.h b/source/dnode/mnode/impl/inc/mndSync.h index cb9d70d5ee48f542dbe58100328b7f2284ea2926..993efbcd084443fccd8ef9776b942e7af671bf60 100644 --- a/source/dnode/mnode/impl/inc/mndSync.h +++ b/source/dnode/mnode/impl/inc/mndSync.h @@ -24,7 +24,7 @@ extern "C" { int32_t mndInitSync(SMnode *pMnode); void mndCleanupSync(SMnode *pMnode); -bool mndIsMaster(SMnode *pMnode); +bool mndIsLeader(SMnode *pMnode); int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId); void mndSyncStart(SMnode *pMnode); void mndSyncStop(SMnode *pMnode); diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 7ffa3cef9992d998f36f34392c0f45d1fdc9d955..46aaa7ffe16c9d684229480ac88a29e0469987b3 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -116,11 +116,13 @@ static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg) { if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL; if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL; - mndTransDrop(pTrans); tDeleteSMqConsumerObj(pConsumerNew); + taosMemoryFree(pConsumerNew); + mndTransDrop(pTrans); return 0; FAIL: tDeleteSMqConsumerObj(pConsumerNew); + taosMemoryFree(pConsumerNew); mndTransDrop(pTrans); return -1; } diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 6670211d7834456af6ed4456881dea149e4e0414..3b3187385771da81d703a270c3f9f07e3171505e 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -1809,7 +1809,7 @@ static int32_t mndRetrieveDbs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc } while (numOfRows < rowsCapacity) { - pShow->pIter = sdbFetchAll(pSdb, SDB_DB, pShow->pIter, (void **)&pDb, &objStatus); + pShow->pIter = sdbFetchAll(pSdb, SDB_DB, pShow->pIter, (void **)&pDb, &objStatus, true); if (pShow->pIter == NULL) break; if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_READ_OR_WRITE_DB, pDb) == 0) { diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 9ade39e8e7c3302389e8f4b339baaad6071ae5b3..fba1fd94d6b537a9f587d898c062f01a0b47df19 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -423,7 +423,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { goto _OVER; } else { pDnode->accessTimes++; - mTrace("dnode:%d, status received, access times %d", pDnode->id, pDnode->accessTimes); + mDebug("dnode:%d, status received, access times %d", pDnode->id, pDnode->accessTimes); } } @@ -471,6 +471,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { } pDnode->lastAccessTime = curMs; + pDnode->accessTimes++; code = 0; _OVER: diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 275fc76e360c19ffb56e76d639a1319ac17d0c4f..5fb23b045c92e27da10486bb54f9343bb23bc81d 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -43,6 +43,37 @@ #include "mndUser.h" #include "mndVgroup.h" +static inline int32_t mndAcquireRpc(SMnode *pMnode) { + int32_t code = 0; + taosThreadRwlockRdlock(&pMnode->lock); + if (pMnode->stopped) { + terrno = TSDB_CODE_APP_NOT_READY; + code = -1; + } else if (!mndIsLeader(pMnode)) { + code = -1; + } else { +#if 1 + atomic_add_fetch_32(&pMnode->rpcRef, 1); +#else + int32_t ref = atomic_add_fetch_32(&pMnode->rpcRef, 1); + mTrace("mnode rpc is acquired, ref:%d", ref); +#endif + } + taosThreadRwlockUnlock(&pMnode->lock); + return code; +} + +static inline void mndReleaseRpc(SMnode *pMnode) { + taosThreadRwlockRdlock(&pMnode->lock); +#if 1 + atomic_sub_fetch_32(&pMnode->rpcRef, 1); +#else + int32_t ref = atomic_sub_fetch_32(&pMnode->rpcRef, 1); + mTrace("mnode rpc is released, ref:%d", ref); +#endif + taosThreadRwlockUnlock(&pMnode->lock); +} + static void *mndBuildTimerMsg(int32_t *pContLen) { SMTimerReq timerReq = {0}; @@ -201,7 +232,7 @@ static int32_t mndInitWal(SMnode *pMnode) { pMnode->pWal = walOpen(path, &cfg); if (pMnode->pWal == NULL) { - mError("failed to open wal since %s", terrstr()); + mError("failed to open wal since %s. wal:%s", terrstr(), path); return -1; } @@ -338,8 +369,9 @@ static int32_t mndExecSteps(SMnode *pMnode) { static void mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->msgCb = pOption->msgCb; pMnode->selfDnodeId = pOption->dnodeId; - pMnode->syncMgmt.replica = pOption->replica; - pMnode->syncMgmt.standby = pOption->standby; + pMnode->syncMgmt.selfIndex = pOption->selfIndex; + pMnode->syncMgmt.numOfReplicas = pOption->numOfReplicas; + memcpy(pMnode->syncMgmt.replicas, pOption->replicas, sizeof(pOption->replicas)); } SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { @@ -430,7 +462,7 @@ int32_t mndStart(SMnode *pMnode) { mError("failed to deploy sdb while start mnode"); return -1; } - mndSetRestore(pMnode, true); + mndSetRestored(pMnode, true); } grantReset(pMnode, TSDB_GRANT_ALL, 0); @@ -570,23 +602,27 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) { pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_SCH_MERGE_FETCH || pMsg->msgType == TDMT_SCH_DROP_TASK) { return 0; } - if (mndAcquireRpcRef(pMsg->info.node) == 0) return 0; + if (mndAcquireRpc(pMsg->info.node) == 0) return 0; if (pMsg->msgType == TDMT_MND_MQ_TIMER || pMsg->msgType == TDMT_MND_TELEM_TIMER || pMsg->msgType == TDMT_MND_TRANS_TIMER || pMsg->msgType == TDMT_MND_TTL_TIMER || pMsg->msgType == TDMT_MND_UPTIME_TIMER) { return -1; } - SEpSet epSet = {0}; - mndGetMnodeEpSet(pMsg->info.node, &epSet); + SEpSet epSet = {0}; + SMnode *pMnode = pMsg->info.node; + mndGetMnodeEpSet(pMnode, &epSet); const STraceId *trace = &pMsg->info.traceId; - mError("msg:%p, failed to check mnode state since %s, type:%s, numOfMnodes:%d inUse:%d", pMsg, terrstr(), - TMSG_INFO(pMsg->msgType), epSet.numOfEps, epSet.inUse); + mDebug( + "msg:%p, failed to check mnode state since %s, mnode restored:%d stopped:%d, sync restored:%d role:%s type:%s " + "numOfEps:%d inUse:%d", + pMsg, terrstr(), pMnode->restored, pMnode->stopped, syncIsRestoreFinish(pMnode->syncMgmt.sync), + syncGetMyRoleStr(pMnode->syncMgmt.sync), TMSG_INFO(pMsg->msgType), epSet.numOfEps, epSet.inUse); if (epSet.numOfEps > 0) { for (int32_t i = 0; i < epSet.numOfEps; ++i) { - mInfo("mnode index:%d, ep:%s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port); + mDebug("mnode index:%d, ep:%s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port); } int32_t contLen = tSerializeSEpSet(NULL, 0, &epSet); @@ -633,7 +669,7 @@ int32_t mndProcessRpcMsg(SRpcMsg *pMsg) { mGTrace("msg:%p, start to process in mnode, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType)); int32_t code = (*fp)(pMsg); - mndReleaseRpcRef(pMnode); + mndReleaseRpc(pMnode); if (code == TSDB_CODE_ACTION_IN_PROGRESS) { mGTrace("msg:%p, won't response immediately since in progress", pMsg); @@ -669,7 +705,7 @@ int64_t mndGenerateUid(const char *name, int32_t len) { int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo, SMonStbInfo *pStbInfo, SMonGrantInfo *pGrantInfo) { - if (mndAcquireRpcRef(pMnode) != 0) return -1; + if (mndAcquireRpc(pMnode) != 0) return -1; SSdb *pSdb = pMnode->pSdb; int64_t ms = taosGetTimestampMs(); @@ -680,7 +716,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr pStbInfo->stbs = taosArrayInit(sdbGetSize(pSdb, SDB_STB), sizeof(SMonStbDesc)); if (pClusterInfo->dnodes == NULL || pClusterInfo->mnodes == NULL || pVgroupInfo->vgroups == NULL || pStbInfo->stbs == NULL) { - mndReleaseRpcRef(pMnode); + mndReleaseRpc(pMnode); return -1; } @@ -800,7 +836,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr pGrantInfo->timeseries_total = INT32_MAX; } - mndReleaseRpcRef(pMnode); + mndReleaseRpc(pMnode); return 0; } @@ -810,32 +846,7 @@ int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) { return 0; } -int32_t mndAcquireRpcRef(SMnode *pMnode) { - int32_t code = 0; - taosThreadRwlockRdlock(&pMnode->lock); - if (pMnode->stopped) { - mTrace("mnode not running"); - terrno = TSDB_CODE_APP_NOT_READY; - code = -1; - } else if (!mndIsMaster(pMnode)) { - mTrace("mnode not ready, role:%s restored:%d", syncGetMyRoleStr(pMnode->syncMgmt.sync), pMnode->restored); - code = -1; - } else { - int32_t ref = atomic_add_fetch_32(&pMnode->rpcRef, 1); - // mTrace("mnode rpc is acquired, ref:%d", ref); - } - taosThreadRwlockUnlock(&pMnode->lock); - return code; -} - -void mndReleaseRpcRef(SMnode *pMnode) { - taosThreadRwlockRdlock(&pMnode->lock); - int32_t ref = atomic_sub_fetch_32(&pMnode->rpcRef, 1); - // mTrace("mnode rpc is released, ref:%d", ref); - taosThreadRwlockUnlock(&pMnode->lock); -} - -void mndSetRestore(SMnode *pMnode, bool restored) { +void mndSetRestored(SMnode *pMnode, bool restored) { if (restored) { taosThreadRwlockWrlock(&pMnode->lock); pMnode->restored = true; diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index d0440359ffa849678b4f2f124059d11ec3214809..c27241317c2f2afa05d4744bc8e4c6e1ceb104f9 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -36,6 +36,7 @@ static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq); static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq); static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextMnode(SMnode *pMnode, void *pIter); +static void mndReloadSyncConfig(SMnode *pMnode); int32_t mndInitMnode(SMnode *pMnode) { SSdbTable table = { @@ -187,6 +188,7 @@ static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) { } pObj->state = TAOS_SYNC_STATE_ERROR; + mndReloadSyncConfig(pSdb->pMnode); return 0; } @@ -203,6 +205,8 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) { static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOld, SMnodeObj *pNew) { mTrace("mnode:%d, perform update action, old row:%p new row:%p", pOld->id, pOld, pNew); pOld->updateTime = pNew->updateTime; + mndReloadSyncConfig(pSdb->pMnode); + return 0; } @@ -233,7 +237,7 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) { if (pIter == NULL) break; if (pObj->id == pMnode->selfDnodeId) { - if (mndIsMaster(pMnode)) { + if (mndIsLeader(pMnode)) { pEpSet->inUse = pEpSet->numOfEps; } else { pEpSet->inUse = (pEpSet->numOfEps + 1) % totalMnodes; @@ -248,6 +252,10 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) { if (pEpSet->numOfEps == 0) { syncGetRetryEpSet(pMnode->syncMgmt.sync, pEpSet); } + + if (pEpSet->inUse >= pEpSet->numOfEps) { + pEpSet->inUse = 0; + } } static int32_t mndSetCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) { @@ -274,13 +282,72 @@ static int32_t mndSetCreateMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnod return 0; } +static int32_t mndBuildCreateMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pCreateReq, SEpSet *pCreateEpSet) { + int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pCreateReq); + void *pReq = taosMemoryMalloc(contLen); + tSerializeSDCreateMnodeReq(pReq, contLen, pCreateReq); + + STransAction action = { + .epSet = *pCreateEpSet, + .pCont = pReq, + .contLen = contLen, + .msgType = TDMT_DND_CREATE_MNODE, + .acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED, + }; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + taosMemoryFree(pReq); + return -1; + } + return 0; +} + +static int32_t mndBuildAlterMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pAlterReq, SEpSet *pAlterEpSet) { + int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterReq); + void *pReq = taosMemoryMalloc(contLen); + tSerializeSDCreateMnodeReq(pReq, contLen, pAlterReq); + + STransAction action = { + .epSet = *pAlterEpSet, + .pCont = pReq, + .contLen = contLen, + .msgType = TDMT_MND_ALTER_MNODE, + .acceptableCode = 0, + }; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + taosMemoryFree(pReq); + return -1; + } + + return 0; +} + +static int32_t mndBuildDropMnodeRedoAction(STrans *pTrans, SDDropMnodeReq *pDropReq, SEpSet *pDroprEpSet) { + int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, pDropReq); + void *pReq = taosMemoryMalloc(contLen); + tSerializeSCreateDropMQSBNodeReq(pReq, contLen, pDropReq); + + STransAction action = { + .epSet = *pDroprEpSet, + .pCont = pReq, + .contLen = contLen, + .msgType = TDMT_DND_DROP_MNODE, + .acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED, + }; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + taosMemoryFree(pReq); + return -1; + } + return 0; +} + static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) { SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; int32_t numOfReplicas = 0; - SDAlterMnodeReq alterReq = {0}; SDCreateMnodeReq createReq = {0}; - SEpSet alterEpset = {0}; SEpSet createEpset = {0}; while (1) { @@ -288,75 +355,25 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj); if (pIter == NULL) break; - alterReq.replicas[numOfReplicas].id = pMObj->id; - alterReq.replicas[numOfReplicas].port = pMObj->pDnode->port; - memcpy(alterReq.replicas[numOfReplicas].fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN); - - alterEpset.eps[numOfReplicas].port = pMObj->pDnode->port; - memcpy(alterEpset.eps[numOfReplicas].fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN); - if (pMObj->state == TAOS_SYNC_STATE_LEADER) { - alterEpset.inUse = numOfReplicas; - } + createReq.replicas[numOfReplicas].id = pMObj->id; + createReq.replicas[numOfReplicas].port = pMObj->pDnode->port; + memcpy(createReq.replicas[numOfReplicas].fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN); numOfReplicas++; sdbRelease(pSdb, pMObj); } - alterReq.replica = numOfReplicas + 1; - alterReq.replicas[numOfReplicas].id = pDnode->id; - alterReq.replicas[numOfReplicas].port = pDnode->port; - memcpy(alterReq.replicas[numOfReplicas].fqdn, pDnode->fqdn, TSDB_FQDN_LEN); - - alterEpset.numOfEps = numOfReplicas + 1; - alterEpset.eps[numOfReplicas].port = pDnode->port; - memcpy(alterEpset.eps[numOfReplicas].fqdn, pDnode->fqdn, TSDB_FQDN_LEN); - - createReq.replica = 1; - createReq.replicas[0].id = pDnode->id; - createReq.replicas[0].port = pDnode->port; - memcpy(createReq.replicas[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN); + createReq.replica = numOfReplicas + 1; + createReq.replicas[numOfReplicas].id = pDnode->id; + createReq.replicas[numOfReplicas].port = pDnode->port; + memcpy(createReq.replicas[numOfReplicas].fqdn, pDnode->fqdn, TSDB_FQDN_LEN); + createEpset.inUse = 0; createEpset.numOfEps = 1; createEpset.eps[0].port = pDnode->port; memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN); - { - int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &createReq); - void *pReq = taosMemoryMalloc(contLen); - tSerializeSDCreateMnodeReq(pReq, contLen, &createReq); - - STransAction action = { - .epSet = createEpset, - .pCont = pReq, - .contLen = contLen, - .msgType = TDMT_DND_CREATE_MNODE, - .acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED, - }; - - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(pReq); - return -1; - } - } - - { - int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &alterReq); - void *pReq = taosMemoryMalloc(contLen); - tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq); - - STransAction action = { - .epSet = alterEpset, - .pCont = pReq, - .contLen = contLen, - .msgType = TDMT_MND_ALTER_MNODE, - .acceptableCode = 0, - }; - - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(pReq); - return -1; - } - } + if (mndBuildCreateMnodeRedoAction(pTrans, &createReq, &createEpset) != 0) return -1; return 0; } @@ -374,9 +391,9 @@ static int32_t mndCreateMnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, mndTransSetSerial(pTrans); mInfo("trans:%d, used to create mnode:%d", pTrans->id, pCreate->dnodeId); + if (mndSetCreateMnodeRedoActions(pMnode, pTrans, pDnode, &mnodeObj) != 0) goto _OVER; if (mndSetCreateMnodeRedoLogs(pMnode, pTrans, &mnodeObj) != 0) goto _OVER; if (mndSetCreateMnodeCommitLogs(pMnode, pTrans, &mnodeObj) != 0) goto _OVER; - if (mndSetCreateMnodeRedoActions(pMnode, pTrans, pDnode, &mnodeObj) != 0) goto _OVER; if (mndTransAppendNullLog(pTrans) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; @@ -459,107 +476,28 @@ static int32_t mndSetDropMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeO } static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) { - SSdb *pSdb = pMnode->pSdb; - void *pIter = NULL; - int32_t numOfReplicas = 0; - SDAlterMnodeReq alterReq = {0}; - SDDropMnodeReq dropReq = {0}; - SSetStandbyReq standbyReq = {0}; - SEpSet alterEpset = {0}; - SEpSet dropEpSet = {0}; - - while (1) { - SMnodeObj *pMObj = NULL; - pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj); - if (pIter == NULL) break; - if (pMObj->id == pObj->id) { - sdbRelease(pSdb, pMObj); - continue; - } - - alterReq.replicas[numOfReplicas].id = pMObj->id; - alterReq.replicas[numOfReplicas].port = pMObj->pDnode->port; - memcpy(alterReq.replicas[numOfReplicas].fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN); - - alterEpset.eps[numOfReplicas].port = pMObj->pDnode->port; - memcpy(alterEpset.eps[numOfReplicas].fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN); - if (pMObj->state == TAOS_SYNC_STATE_LEADER) { - alterEpset.inUse = numOfReplicas; - } - - numOfReplicas++; - sdbRelease(pSdb, pMObj); - } - - alterReq.replica = numOfReplicas; - alterEpset.numOfEps = numOfReplicas; + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + int32_t numOfReplicas = 0; + SDDropMnodeReq dropReq = {0}; + SEpSet dropEpSet = {0}; dropReq.dnodeId = pDnode->id; dropEpSet.numOfEps = 1; dropEpSet.eps[0].port = pDnode->port; memcpy(dropEpSet.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN); - standbyReq.dnodeId = pDnode->id; - standbyReq.standby = 1; - - { - int32_t contLen = tSerializeSSetStandbyReq(NULL, 0, &standbyReq) + sizeof(SMsgHead); - void *pReq = taosMemoryMalloc(contLen); - tSerializeSSetStandbyReq((char *)pReq + sizeof(SMsgHead), contLen, &standbyReq); - SMsgHead *pHead = pReq; - pHead->contLen = htonl(contLen); - pHead->vgId = htonl(MNODE_HANDLE); - - STransAction action = { - .epSet = dropEpSet, - .pCont = pReq, - .contLen = contLen, - .msgType = TDMT_SYNC_SET_MNODE_STANDBY, - .acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED, - }; - - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(pReq); - return -1; - } - } - - { - int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &alterReq); - void *pReq = taosMemoryMalloc(contLen); - tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq); - - STransAction action = { - .epSet = alterEpset, - .pCont = pReq, - .contLen = contLen, - .msgType = TDMT_MND_ALTER_MNODE, - .acceptableCode = 0, - }; - - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(pReq); - return -1; - } - } - - { - int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq); - void *pReq = taosMemoryMalloc(contLen); - tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq); - - STransAction action = { - .epSet = dropEpSet, - .pCont = pReq, - .contLen = contLen, - .msgType = TDMT_DND_DROP_MNODE, - .acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED, - }; - - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(pReq); - return -1; - } + int32_t totalMnodes = sdbGetSize(pSdb, SDB_MNODE); + if (totalMnodes == 2) { + mInfo("vgId:1, has %d mnodes, exec redo log first", totalMnodes); + if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1; + if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1; + } else if (totalMnodes == 3) { + mInfo("vgId:1, has %d mnodes, exec redo action first", totalMnodes); + if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1; + if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1; + } else { + return -1; } return 0; @@ -567,7 +505,6 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) { if (pObj == NULL) return 0; - if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1; if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) return -1; if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj) != 0) return -1; if (mndTransAppendNullLog(pTrans) != 0) return -1; @@ -657,7 +594,7 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB int64_t curMs = taosGetTimestampMs(); while (numOfRows < rows) { - pShow->pIter = sdbFetchAll(pSdb, SDB_MNODE, pShow->pIter, (void **)&pObj, &objStatus); + pShow->pIter = sdbFetchAll(pSdb, SDB_MNODE, pShow->pIter, (void **)&pObj, &objStatus, true); if (pShow->pIter == NULL) break; cols = 0; @@ -712,6 +649,9 @@ static void mndCancelGetNextMnode(SMnode *pMnode, void *pIter) { } static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq) { +#if 1 + return 0; +#else SMnode *pMnode = pReq->info.node; SDAlterMnodeReq alterReq = {0}; @@ -720,41 +660,107 @@ static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq) { return -1; } + SMnodeOpt option = {.deploy = true, .numOfReplicas = alterReq.replica, .selfIndex = -1}; + memcpy(option.replicas, alterReq.replicas, sizeof(alterReq.replicas)); + for (int32_t i = 0; i < option.numOfReplicas; ++i) { + if (alterReq.replicas[i].id == pMnode->selfDnodeId) { + option.selfIndex = i; + } + } + + if (option.selfIndex == -1) { + mInfo("alter mnode not processed since selfIndex is -1", terrstr()); + return 0; + } + + if (mndWriteFile(pMnode->path, &option) != 0) { + mError("failed to write mnode file since %s", terrstr()); + return -1; + } + SSyncCfg cfg = {.replicaNum = alterReq.replica, .myIndex = -1}; for (int32_t i = 0; i < alterReq.replica; ++i) { SNodeInfo *pNode = &cfg.nodeInfo[i]; tstrncpy(pNode->nodeFqdn, alterReq.replicas[i].fqdn, sizeof(pNode->nodeFqdn)); pNode->nodePort = alterReq.replicas[i].port; - if (alterReq.replicas[i].id == pMnode->selfDnodeId) cfg.myIndex = i; + if (alterReq.replicas[i].id == pMnode->selfDnodeId) { + cfg.myIndex = i; + } } if (cfg.myIndex == -1) { mError("failed to alter mnode since myindex is -1"); return -1; } else { - mInfo("start to alter mnode sync, replica:%d myindex:%d", cfg.replicaNum, cfg.myIndex); + mInfo("start to alter mnode sync, replica:%d myIndex:%d", cfg.replicaNum, cfg.myIndex); for (int32_t i = 0; i < alterReq.replica; ++i) { SNodeInfo *pNode = &cfg.nodeInfo[i]; mInfo("index:%d, fqdn:%s port:%d", i, pNode->nodeFqdn, pNode->nodePort); } } - mInfo("trans:-1, sync reconfig will be proposed"); - - SSyncMgmt *pMgmt = &pMnode->syncMgmt; - pMgmt->standby = 0; - int32_t code = syncReconfig(pMgmt->sync, &cfg); + int32_t code = syncReconfig(pMnode->syncMgmt.sync, &cfg); if (code != 0) { - mError("trans:-1, failed to propose sync reconfig since %s", terrstr()); - return code; + mError("failed to sync reconfig since %s", terrstr()); } else { - pMgmt->errCode = 0; - taosWLockLatch(&pMgmt->lock); - pMgmt->transId = -1; - taosWUnLockLatch(&pMgmt->lock); - tsem_wait(&pMgmt->syncSem); - mInfo("alter mnode sync result:0x%x %s", pMgmt->errCode, tstrerror(pMgmt->errCode)); - terrno = pMgmt->errCode; - return pMgmt->errCode; + mInfo("alter mnode sync success"); + } + + return code; +#endif +} + +static void mndReloadSyncConfig(SMnode *pMnode) { + SSdb *pSdb = pMnode->pSdb; + SMnodeObj *pObj = NULL; + ESdbStatus objStatus = 0; + void *pIter = NULL; + bool hasUpdatingMnode = false; + SSyncCfg cfg = {.myIndex = -1}; + + while (1) { + pIter = sdbFetchAll(pSdb, SDB_MNODE, pIter, (void **)&pObj, &objStatus, false); + if (pIter == NULL) break; + if (objStatus == SDB_STATUS_CREATING || objStatus == SDB_STATUS_DROPPING) { + mInfo("vgId:1, has updating mnode:%d, status:%s", pObj->id, sdbStatusName(objStatus)); + hasUpdatingMnode = true; + } + + if (objStatus == SDB_STATUS_READY || objStatus == SDB_STATUS_CREATING) { + SNodeInfo *pNode = &cfg.nodeInfo[cfg.replicaNum]; + tstrncpy(pNode->nodeFqdn, pObj->pDnode->fqdn, sizeof(pNode->nodeFqdn)); + pNode->nodePort = pObj->pDnode->port; + if (pObj->pDnode->id == pMnode->selfDnodeId) { + cfg.myIndex = cfg.replicaNum; + } + cfg.replicaNum++; + } + + sdbReleaseLock(pSdb, pObj, false); + } + + if (cfg.myIndex == -1) { + mInfo("vgId:1, mnode not reload since selfIndex is -1"); + return; + } + + if (!mndGetRestored(pMnode)) { + mInfo("vgId:1, mnode not reload since restore not finished"); + return; + } + + if (hasUpdatingMnode) { + mInfo("vgId:1, start to reload mnode sync, replica:%d myIndex:%d", cfg.replicaNum, cfg.myIndex); + for (int32_t i = 0; i < cfg.replicaNum; ++i) { + SNodeInfo *pNode = &cfg.nodeInfo[i]; + mInfo("vgId:1, index:%d, fqdn:%s port:%d", i, pNode->nodeFqdn, pNode->nodePort); + } + + int32_t code = syncReconfig(pMnode->syncMgmt.sync, &cfg); + if (code != 0) { + mError("vgId:1, failed to reconfig mnode sync since %s", terrstr()); + } else { + mInfo("vgId:1, reconfig mnode sync success"); + } } } diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 0e4dd9fc3c51d121e54be959129cf1e98a508181..866a3fa8b9027e2c5414546ef1648c4b471cbbbb 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -107,7 +107,7 @@ void mndRestoreFinish(struct SSyncFSM *pFsm) { if (!pMnode->deploy) { mInfo("vgId:1, sync restore finished, and will handle outstanding transactions"); mndTransPullup(pMnode); - mndSetRestore(pMnode, true); + mndSetRestored(pMnode, true); } else { mInfo("vgId:1, sync restore finished"); } @@ -225,18 +225,17 @@ int32_t mndInitSync(SMnode *pMnode) { snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", pMnode->path, TD_DIRSEP); syncInfo.pWal = pMnode->pWal; syncInfo.pFsm = mndSyncMakeFsm(pMnode); - syncInfo.isStandBy = pMgmt->standby; syncInfo.snapshotStrategy = SYNC_STRATEGY_STANDARD_SNAPSHOT; - mInfo("vgId:1, start to open sync, standby:%d", pMgmt->standby); - if (pMgmt->standby || pMgmt->replica.id > 0) { - SSyncCfg *pCfg = &syncInfo.syncCfg; - pCfg->replicaNum = 1; - pCfg->myIndex = 0; - SNodeInfo *pNode = &pCfg->nodeInfo[0]; - tstrncpy(pNode->nodeFqdn, pMgmt->replica.fqdn, sizeof(pNode->nodeFqdn)); - pNode->nodePort = pMgmt->replica.port; - mInfo("vgId:1, ep:%s:%u", pNode->nodeFqdn, pNode->nodePort); + mInfo("vgId:1, start to open sync, selfIndex:%d replica:%d", pMgmt->selfIndex, pMgmt->numOfReplicas); + SSyncCfg *pCfg = &syncInfo.syncCfg; + pCfg->replicaNum = pMgmt->numOfReplicas; + pCfg->myIndex = pMgmt->selfIndex; + for (int32_t i = 0; i < pMgmt->numOfReplicas; ++i) { + SNodeInfo *pNode = &pCfg->nodeInfo[i]; + tstrncpy(pNode->nodeFqdn, pMgmt->replicas[i].fqdn, sizeof(pNode->nodeFqdn)); + pNode->nodePort = pMgmt->replicas[i].port; + mInfo("vgId:1, index:%d ep:%s:%u", i, pNode->nodeFqdn, pNode->nodePort); } tsem_init(&pMgmt->syncSem, 0, 0); @@ -250,10 +249,6 @@ int32_t mndInitSync(SMnode *pMnode) { setPingTimerMS(pMgmt->sync, 5000); setElectTimerMS(pMgmt->sync, 3000); setHeartbeatTimerMS(pMgmt->sync, 500); - /* - setElectTimerMS(pMgmt->sync, 600); - setHeartbeatTimerMS(pMgmt->sync, 300); - */ mInfo("mnode-sync is opened, id:%" PRId64, pMgmt->sync); return 0; @@ -319,7 +314,7 @@ void mndSyncStart(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; syncSetMsgCb(pMgmt->sync, &pMnode->msgCb); syncStart(pMgmt->sync); - mInfo("vgId:1, sync started, id:%" PRId64 " standby:%d", pMgmt->sync, pMgmt->standby); + mInfo("vgId:1, sync started, id:%" PRId64, pMgmt->sync); } void mndSyncStop(SMnode *pMnode) { @@ -331,7 +326,7 @@ void mndSyncStop(SMnode *pMnode) { taosWUnLockLatch(&pMnode->syncMgmt.lock); } -bool mndIsMaster(SMnode *pMnode) { +bool mndIsLeader(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; if (!syncIsReady(pMgmt->sync)) { @@ -340,7 +335,7 @@ bool mndIsMaster(SMnode *pMnode) { return false; } - if (!pMnode->restored) { + if (!mndGetRestored(pMnode)) { terrno = TSDB_CODE_APP_NOT_READY; return false; } diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index ae259b95be220a3c1cb0d3c2178b92e322d65ace..90ac69423c5f496bebc156b290264e990cacd615 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -154,6 +154,8 @@ TOPIC_ENCODE_OVER: SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { terrno = TSDB_CODE_OUT_OF_MEMORY; + + void *buf = NULL; int8_t sver = 0; if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto TOPIC_DECODE_OVER; @@ -215,17 +217,15 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &len, TOPIC_DECODE_OVER); if (len) { - void *buf = taosMemoryMalloc(len); + buf = taosMemoryMalloc(len); if (buf == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto TOPIC_DECODE_OVER; } SDB_GET_BINARY(pRaw, dataPos, buf, len, TOPIC_DECODE_OVER); if (taosDecodeSSchemaWrapper(buf, &pTopic->schema) == NULL) { - taosMemoryFree(buf); goto TOPIC_DECODE_OVER; } - taosMemoryFree(buf); } else { pTopic->schema.nCols = 0; pTopic->schema.version = 0; @@ -251,6 +251,7 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { terrno = TSDB_CODE_SUCCESS; TOPIC_DECODE_OVER: + taosMemoryFreeClear(buf); if (terrno != TSDB_CODE_SUCCESS) { mError("topic:%s, failed to decode from raw:%p since %s", pTopic->name, pRaw, terrstr()); taosMemoryFreeClear(pRow); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index d30cc8f9ca65315c0fb9f32b2148d341194c361c..a64b07fdbd6491bb16b7854758029bde06b14808 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -53,7 +53,7 @@ static bool mndTransPerformCommitActionStage(SMnode *pMnode, STrans *pTrans); static bool mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans); static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans); static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans); -static bool mndCannotExecuteTransAction(SMnode *pMnode) { return !pMnode->deploy && !mndIsMaster(pMnode); } +static bool mndCannotExecuteTransAction(SMnode *pMnode) { return !pMnode->deploy && !mndIsLeader(pMnode); } static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans); static int32_t mndProcessTransTimer(SRpcMsg *pReq); diff --git a/source/dnode/mnode/sdb/inc/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h index f922baf329fbba3c747f9be19f5bda30876d68ea..be93bd2f59da8c54c467ae90eadf6df593a087d4 100644 --- a/source/dnode/mnode/sdb/inc/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -298,6 +298,7 @@ void *sdbAcquire(SSdb *pSdb, ESdbType type, const void *pKey); * @param pObj The object of the row. */ void sdbRelease(SSdb *pSdb, void *pObj); +void sdbReleaseLock(SSdb *pSdb, void *pObj, bool lock); /** * @brief Traverse a sdb table @@ -309,7 +310,7 @@ void sdbRelease(SSdb *pSdb, void *pObj); * @return void* The next iterator of the table. */ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj); -void *sdbFetchAll(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj, ESdbStatus *status); +void *sdbFetchAll(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj, ESdbStatus *status, bool lock); /** * @brief Cancel a traversal diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index ecdf8c71a77d1dde73d85b2b582e626f3197c21a..0fee0fbca17685e6ee7b2a106accf87ba0d2b056 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -327,14 +327,16 @@ static void sdbCheckRow(SSdb *pSdb, SSdbRow *pRow) { taosThreadRwlockUnlock(pLock); } -void sdbRelease(SSdb *pSdb, void *pObj) { +void sdbReleaseLock(SSdb *pSdb, void *pObj, bool lock) { if (pObj == NULL) return; SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow)); if (pRow->type >= SDB_MAX) return; TdThreadRwlock *pLock = &pSdb->locks[pRow->type]; - taosThreadRwlockWrlock(pLock); + if (lock) { + taosThreadRwlockWrlock(pLock); + } int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1); sdbPrintOper(pSdb, pRow, "release"); @@ -342,9 +344,13 @@ void sdbRelease(SSdb *pSdb, void *pObj) { sdbFreeRow(pSdb, pRow, true); } - taosThreadRwlockUnlock(pLock); + if (lock) { + taosThreadRwlockUnlock(pLock); + } } +void sdbRelease(SSdb *pSdb, void *pObj) { sdbReleaseLock(pSdb, pObj, true); } + void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { *ppObj = NULL; @@ -372,14 +378,16 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { return ppRow; } -void *sdbFetchAll(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj, ESdbStatus *status) { +void *sdbFetchAll(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj, ESdbStatus *status, bool lock) { *ppObj = NULL; SHashObj *hash = sdbGetHash(pSdb, type); if (hash == NULL) return NULL; TdThreadRwlock *pLock = &pSdb->locks[type]; - taosThreadRwlockRdlock(pLock); + if (lock) { + taosThreadRwlockRdlock(pLock); + } SSdbRow **ppRow = taosHashIterate(hash, pIter); while (ppRow != NULL) { @@ -395,7 +403,9 @@ void *sdbFetchAll(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj, ESdbStat *status = pRow->status; break; } - taosThreadRwlockUnlock(pLock); + if (lock) { + taosThreadRwlockUnlock(pLock); + } return ppRow; } diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index c8a4ff945d0cc1771b0f074b91ee55887a24fe51..1e0e75779342285143ff8713ff03c2a17480c504 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -51,7 +51,7 @@ static int metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema return -1; } - strcpy(pMetaRsp->tbName, tbName); + strncpy(pMetaRsp->tbName, tbName, TSDB_TABLE_NAME_LEN); pMetaRsp->numOfColumns = pSchema->nCols; pMetaRsp->tableType = TSDB_NORMAL_TABLE; pMetaRsp->sversion = pSchema->version; @@ -693,6 +693,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl if (iCol >= pSchema->nCols) break; pColumn = &pSchema->pSchema[iCol]; + ASSERT(pAlterTbReq->colName); if (strcmp(pColumn->name, pAlterTbReq->colName) == 0) break; iCol++; } @@ -816,6 +817,11 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA const void *pData = NULL; int nData = 0; + if (pAlterTbReq->tagName == NULL) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + // search name index ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal); if (ret < 0) { diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index 155086a5a8fd771447d465d5a1685b280823924a..722a3f479e47c5e19fa3419fc244accea5282df6 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -321,7 +321,7 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat } taosMemoryFree(s); } - pStreamState = streamStateOpen(taskInfDir, NULL, true); + pStreamState = streamStateOpen(taskInfDir, NULL, true, -1, -1); if (!pStreamState) { terrno = TSDB_CODE_RSMA_STREAM_STATE_OPEN; return TSDB_CODE_FAILED; diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 83cb3955e3c15b6b83ff8f52a5f458a52ffc0faf..e1578b37f1583547ed8d2738b9ff59b13505e6fb 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -171,11 +171,11 @@ int32_t tqPushDataRsp(STQ* pTq, STqPushEntry* pPushEntry) { ASSERT(taosArrayGetSize(pRsp->blockSchema) == 0); if (pRsp->reqOffset.type == TMQ_OFFSET__LOG) { - if (pRsp->blockNum > 0) { - ASSERT(pRsp->rspOffset.version > pRsp->reqOffset.version); - } else { - ASSERT(pRsp->rspOffset.version >= pRsp->reqOffset.version); - } + /*if (pRsp->blockNum > 0) {*/ + /*ASSERT(pRsp->rspOffset.version > pRsp->reqOffset.version);*/ + /*} else {*/ + ASSERT(pRsp->rspOffset.version > pRsp->reqOffset.version); + /*}*/ } int32_t len = 0; @@ -890,7 +890,7 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask) { // expand executor if (pTask->taskLevel == TASK_LEVEL__SOURCE) { - pTask->pState = streamStateOpen(pTq->pStreamMeta->path, pTask, false); + pTask->pState = streamStateOpen(pTq->pStreamMeta->path, pTask, false, -1, -1); if (pTask->pState == NULL) { return -1; } @@ -904,7 +904,7 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask) { pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle); ASSERT(pTask->exec.executor); } else if (pTask->taskLevel == TASK_LEVEL__AGG) { - pTask->pState = streamStateOpen(pTq->pStreamMeta->path, pTask, false); + pTask->pState = streamStateOpen(pTq->pStreamMeta->path, pTask, false, -1, -1); if (pTask->pState == NULL) { return -1; } diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c index 416113f59f2ee277e178e5787c4b5b34acf19bce..8e4bc34e0cf016878595117e65539ced34440c37 100644 --- a/source/dnode/vnode/src/tq/tqMeta.c +++ b/source/dnode/vnode/src/tq/tqMeta.c @@ -177,6 +177,7 @@ int32_t tqMetaRestoreCheckInfo(STQ* pTq) { tDecoderClear(&decoder); if (taosHashPut(pTq->pCheckInfo, info.topic, strlen(info.topic), &info, sizeof(STqCheckInfo)) < 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; + tdbFree(pKey); tdbTbcClose(pCur); return -1; } diff --git a/source/dnode/vnode/src/tq/tqPush.c b/source/dnode/vnode/src/tq/tqPush.c index bcdac1941a9c1b94d0f67793e073b1e87218381c..4083a1a0aeef2f9a783bdace02fb89bdfeb1fe9c 100644 --- a/source/dnode/vnode/src/tq/tqPush.c +++ b/source/dnode/vnode/src/tq/tqPush.c @@ -245,7 +245,7 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) tqDebug("vgId:%d cannot find handle %s", pTq->pVnode->config.vgId, pPushEntry->subKey); continue; } - if (pPushEntry->dataRsp.reqOffset.version > ver) { + if (pPushEntry->dataRsp.reqOffset.version >= ver) { tqDebug("vgId:%d push entry req version %ld, while push version %ld, skip", pTq->pVnode->config.vgId, pPushEntry->dataRsp.reqOffset.version, ver); continue; diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index ac6be9af2d85fa15387d8fd8b1c760055fe061c0..0ee2e310970179f89229836c2d66735fa3083943 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -378,10 +378,10 @@ static int32_t getTableDelSkyline(STbData *pMem, STbData *pIMem, SDelFReader *pD if (code) goto _err; } +_err: if (aDelData) { taosArrayDestroy(aDelData); } -_err: return code; } @@ -399,14 +399,13 @@ static int32_t getTableDelIdx(SDelFReader *pDelFReader, tb_uid_t suid, tb_uid_t // code = tMapDataSearch(&delIdxMap, &idx, tGetDelIdx, tCmprDelIdx, pDelIdx); SDelIdx *pIdx = taosArraySearch(pDelIdxArray, &idx, tCmprDelIdx, TD_EQ); - if (code) goto _err; *pDelIdx = *pIdx; +_err: if (pDelIdxArray) { taosArrayDestroy(pDelIdxArray); } -_err: return code; } @@ -429,7 +428,8 @@ typedef struct { SDataFReader *pDataFReader; TSDBROW row; - SMergeTree mergeTree; + SMergeTree mergeTree; + SMergeTree *pMergeTree; } SFSLastNextRowIter; static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow) { @@ -444,11 +444,14 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow) { case SFSLASTNEXTROW_FILESET: { SDFileSet *pFileSet = NULL; _next_fileset: + if (state->pMergeTree != NULL) { + tMergeTreeClose(state->pMergeTree); + state->pMergeTree = NULL; + } + if (--state->iFileSet >= 0) { pFileSet = (SDFileSet *)taosArrayGet(state->aDFileSet, state->iFileSet); } else { - tMergeTreeClose(&state->mergeTree); - *ppRow = NULL; return code; } @@ -460,10 +463,10 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow) { tMergeTreeOpen(&state->mergeTree, 1, state->pDataFReader, state->suid, state->uid, &(STimeWindow){.skey = TSKEY_MIN, .ekey = TSKEY_MAX}, &(SVersionRange){.minVer = 0, .maxVer = UINT64_MAX}, pLoadInfo, true, NULL); + state->pMergeTree = &state->mergeTree; bool hasVal = tMergeTreeNext(&state->mergeTree); if (!hasVal) { state->state = SFSLASTNEXTROW_FILESET; - tMergeTreeClose(&state->mergeTree); goto _next_fileset; } state->state = SFSLASTNEXTROW_BLOCKROW; @@ -475,6 +478,7 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow) { if (!hasVal) { state->state = SFSLASTNEXTROW_FILESET; } + return code; default: ASSERT(0); @@ -486,6 +490,11 @@ _err: tsdbDataFReaderClose(&state->pDataFReader); state->pDataFReader = NULL; } + if (state->pMergeTree != NULL) { + tMergeTreeClose(state->pMergeTree); + state->pMergeTree = NULL; + } + *ppRow = NULL; return code; @@ -504,6 +513,11 @@ int32_t clearNextRowFromFSLast(void *iter) { state->pDataFReader = NULL; } + if (state->pMergeTree != NULL) { + tMergeTreeClose(state->pMergeTree); + state->pMergeTree = NULL; + } + return code; } @@ -584,8 +598,6 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) { * &state->blockIdx); */ state->pBlockIdx = taosArraySearch(state->aBlockIdx, state->pBlockIdxExp, tCmprBlockIdx, TD_EQ); - if (code) goto _err; - if (!state->pBlockIdx) { goto _next_fileset; } @@ -883,10 +895,16 @@ static int32_t nextRowIterOpen(CacheNextRowIter *pIter, tb_uid_t uid, STsdb *pTs if (code) goto _err; code = getTableDelIdx(pDelFReader, suid, uid, &delIdx); - if (code) goto _err; + if (code) { + tsdbDelFReaderClose(&pDelFReader); + goto _err; + } code = getTableDelSkyline(pMem, pIMem, pDelFReader, &delIdx, pIter->pSkyline); - if (code) goto _err; + if (code) { + tsdbDelFReaderClose(&pDelFReader); + goto _err; + } tsdbDelFReaderClose(&pDelFReader); } else { @@ -1216,6 +1234,8 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) { _err: nextRowIterClose(&iter); taosMemoryFreeClear(pTSchema); + *ppLastArray = NULL; + taosArrayDestroy(pColArray); return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 995d7a315550aa695b5f3bab816815edaf370800..a4d993bc6c318967d2624aed82ce66918a778d00 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -396,12 +396,19 @@ _exit: return code; } +static int32_t tDataIterCmprFn(const SRBTreeNode *n1, const SRBTreeNode *n2) { + SDataIter *pIter1 = (SDataIter *)((uint8_t *)n1 - offsetof(SDataIter, n)); + SDataIter *pIter2 = (SDataIter *)((uint8_t *)n2 - offsetof(SDataIter, n)); + + return tRowInfoCmprFn(&pIter1->r, &pIter2->r); +} + static int32_t tsdbOpenCommitIter(SCommitter *pCommitter) { int32_t code = 0; int32_t lino = 0; pCommitter->pIter = NULL; - tRBTreeCreate(&pCommitter->rbt, tRowInfoCmprFn); + tRBTreeCreate(&pCommitter->rbt, tDataIterCmprFn); // memory TSDBKEY tKey = {.ts = pCommitter->minKey, .version = VERSION_MIN}; @@ -1038,7 +1045,9 @@ static int32_t tsdbEndCommit(SCommitter *pCommitter, int32_t eno) { STsdb *pTsdb = pCommitter->pTsdb; SMemTable *pMemTable = pTsdb->imem; - ASSERT(eno == 0); + ASSERT(eno == 0 && + "tsdbCommit failure" + "Restart taosd"); code = tsdbFSCommit1(pTsdb, &pCommitter->fs); TSDB_CHECK_CODE(code, lino, _exit); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 85514ed5b607814ef441ad239724e045002c44b8..6fd562959229fd4c75b4f333f118caa86a66555c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -610,9 +610,6 @@ int32_t tsdbFSRollback(STsdbFS *pFS) { ASSERT(0); return code; - -_err: - return code; } int32_t tsdbFSUpsertDelFile(STsdbFS *pFS, SDelFile *pDelFile) { @@ -822,7 +819,7 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) { nRef = atomic_sub_fetch_32(&fSet.pHeadF->nRef, 1); if (nRef == 0) { tsdbHeadFileName(pTsdb, pSetOld->diskId, pSetOld->fid, fSet.pHeadF, fname); - taosRemoveFile(fname); + (void)taosRemoveFile(fname); taosMemoryFree(fSet.pHeadF); } } else { @@ -866,7 +863,7 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) { nRef = atomic_sub_fetch_32(&fSet.pSmaF->nRef, 1); if (nRef == 0) { tsdbSmaFileName(pTsdb, pSetOld->diskId, pSetOld->fid, fSet.pSmaF, fname); - taosRemoveFile(fname); + (void)taosRemoveFile(fname); taosMemoryFree(fSet.pSmaF); } } else { @@ -877,7 +874,7 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) { // stt if (sameDisk) { if (pSetNew->nSttF > pSetOld->nSttF) { - ASSERT(pSetNew->nSttF = pSetOld->nSttF + 1); + ASSERT(pSetNew->nSttF == pSetOld->nSttF + 1); pSetOld->aSttF[pSetOld->nSttF] = (SSttFile *)taosMemoryMalloc(sizeof(SSttFile)); if (pSetOld->aSttF[pSetOld->nSttF] == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -964,7 +961,7 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) { nRef = atomic_sub_fetch_32(&pSetOld->pHeadF->nRef, 1); if (nRef == 0) { tsdbHeadFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSetOld->pHeadF, fname); - taosRemoveFile(fname); + (void)taosRemoveFile(fname); taosMemoryFree(pSetOld->pHeadF); } @@ -1104,7 +1101,7 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) { ASSERT(nRef >= 0); if (nRef == 0) { tsdbDelFileName(pTsdb, pFS->pDelFile, fname); - taosRemoveFile(fname); + (void)taosRemoveFile(fname); taosMemoryFree(pFS->pDelFile); } } @@ -1117,7 +1114,7 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) { ASSERT(nRef >= 0); if (nRef == 0) { tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname); - taosRemoveFile(fname); + (void)taosRemoveFile(fname); taosMemoryFree(pSet->pHeadF); } diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index a6628463f8ff231505052dc3a48d8c7a59a6eaa5..0189ced3c6819f8b4d11adf63bf977579f5efc56 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -160,6 +160,7 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid goto _err; } + ASSERT(pPool != NULL); // do delete SDelData *pDelData = (SDelData *)vnodeBufPoolMalloc(pPool, sizeof(*pDelData)); if (pDelData == NULL) { @@ -353,6 +354,7 @@ static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid SVBufPool *pPool = pMemTable->pTsdb->pVnode->inUse; int8_t maxLevel = pMemTable->pTsdb->pVnode->config.tsdbCfg.slLevel; + ASSERT(pPool != NULL); pTbData = vnodeBufPoolMalloc(pPool, sizeof(*pTbData) + SL_NODE_SIZE(maxLevel) * 2); if (pTbData == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -492,6 +494,7 @@ static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListN // node level = tsdbMemSkipListRandLevel(&pTbData->sl); + ASSERT(pPool != NULL); pNode = (SMemSkipListNode *)vnodeBufPoolMalloc(pPool, SL_NODE_SIZE(level) + tPutTSDBRow(NULL, pRow)); if (pNode == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -559,6 +562,8 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i // backward put first data row.pTSRow = tGetSubmitBlkNext(&blkIter); + if (row.pTSRow == NULL) return code; + key.ts = row.pTSRow->ts; nRow++; tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_BACKWARD); diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index 8e018300e75e1cf655a8fc63d28d324b07266e34..a4c5c60e78cad29d2f55f78e924eeb4bcc98497d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -103,10 +103,20 @@ static SBlockData *loadLastBlock(SLDataIter *pIter, const char *idStr) { SSttBlockLoadInfo *pInfo = pIter->pBlockLoadInfo; if (pInfo->blockIndex[0] == pIter->iSttBlk) { + if (pInfo->currentLoadBlockIndex != 0) { + tsdbDebug("current load index is set to 0, block index:%d, file index:%d, due to uid:%" PRIu64 ", load data, %s", + pIter->iSttBlk, pIter->iStt, pIter->uid, idStr); + pInfo->currentLoadBlockIndex = 0; + } return &pInfo->blockData[0]; } if (pInfo->blockIndex[1] == pIter->iSttBlk) { + if (pInfo->currentLoadBlockIndex != 1) { + tsdbDebug("current load index is set to 1, block index:%d, file index:%d, due to uid:%" PRIu64 ", load data, %s", + pIter->iSttBlk, pIter->iStt, pIter->uid, idStr); + pInfo->currentLoadBlockIndex = 1; + } return &pInfo->blockData[1]; } @@ -123,20 +133,31 @@ static SBlockData *loadLastBlock(SLDataIter *pIter, const char *idStr) { id.uid = pIter->uid; } - tBlockDataInit(pBlock, &id, pInfo->pSchema, pInfo->colIds, pInfo->numOfCols); + code = tBlockDataInit(pBlock, &id, pInfo->pSchema, pInfo->colIds, pInfo->numOfCols); + if (code != TSDB_CODE_SUCCESS) { + goto _exit; + } + code = tsdbReadSttBlock(pIter->pReader, pIter->iStt, pIter->pSttBlk, pBlock); + if (code != TSDB_CODE_SUCCESS) { + goto _exit; + } double el = (taosGetTimestampUs() - st) / 1000.0; pInfo->elapsedTime += el; pInfo->loadBlocks += 1; - tsdbDebug("read last block, index:%d, last file index:%d, elapsed time:%.2f ms, %s", pIter->iSttBlk, pIter->iStt, - el, idStr); + tsdbDebug("read last block, total load:%d, trigger by uid:%" PRIu64 + ", last file index:%d, last block index:%d, entry:%d, %p, elapsed time:%.2f ms, %s", + pInfo->loadBlocks, pIter->uid, pIter->iStt, pIter->iSttBlk, pInfo->currentLoadBlockIndex, pBlock, el, + idStr); if (code != TSDB_CODE_SUCCESS) { goto _exit; } pInfo->blockIndex[pInfo->currentLoadBlockIndex] = pIter->iSttBlk; + tsdbDebug("last block index list:%d, %d, %s", pInfo->blockIndex[0], pInfo->blockIndex[1], idStr); + pIter->iRow = (pIter->backward) ? pInfo->blockData[pInfo->currentLoadBlockIndex].nRow : -1; } @@ -324,8 +345,10 @@ _exit: void tLDataIterClose(SLDataIter *pIter) { taosMemoryFree(pIter); } -void tLDataIterNextBlock(SLDataIter *pIter) { +void tLDataIterNextBlock(SLDataIter *pIter, const char *idStr) { int32_t step = pIter->backward ? -1 : 1; + int32_t oldIndex = pIter->iSttBlk; + pIter->iSttBlk += step; int32_t index = -1; @@ -372,6 +395,10 @@ void tLDataIterNextBlock(SLDataIter *pIter) { if (index != -1) { pIter->iSttBlk = index; pIter->pSttBlk = (SSttBlk *)taosArrayGet(pIter->pBlockLoadInfo->aSttBlk, pIter->iSttBlk); + tsdbDebug("try next last file block:%d from %d, trigger by uid:%" PRIu64 ", file index:%d, %s", pIter->iSttBlk, + oldIndex, pIter->uid, pIter->iStt, idStr); + } else { + tsdbDebug("no more last block qualified, uid:%" PRIu64 ", file index::%d, %s", pIter->uid, oldIndex, idStr); } } @@ -396,16 +423,10 @@ static void findNextValidRow(SLDataIter *pIter, const char *idStr) { for (; i < pBlockData->nRow && i >= 0; i += step) { if (pBlockData->aUid != NULL) { if (!pIter->backward) { - /*if (pBlockData->aUid[i] < pIter->uid) { - continue; - } else */ if (pBlockData->aUid[i] > pIter->uid) { break; } } else { - /*if (pBlockData->aUid[i] > pIter->uid) { - continue; - } else */ if (pBlockData->aUid[i] < pIter->uid) { break; } @@ -461,7 +482,7 @@ bool tLDataIterNextRow(SLDataIter *pIter, const char *idStr) { findNextValidRow(pIter, idStr); if (pIter->iRow >= pBlockData->nRow || pIter->iRow < 0) { - tLDataIterNextBlock(pIter); + tLDataIterNextBlock(pIter, idStr); if (pIter->pSttBlk == NULL) { // no more data goto _exit; } @@ -490,9 +511,9 @@ _exit: SRowInfo *tLDataIterGet(SLDataIter *pIter) { return &pIter->rInfo; } // SMergeTree ================================================= -static FORCE_INLINE int32_t tLDataIterCmprFn(const void *p1, const void *p2) { - SLDataIter *pIter1 = (SLDataIter *)(((uint8_t *)p1) - sizeof(SRBTreeNode)); - SLDataIter *pIter2 = (SLDataIter *)(((uint8_t *)p2) - sizeof(SRBTreeNode)); +static FORCE_INLINE int32_t tLDataIterCmprFn(const SRBTreeNode *p1, const SRBTreeNode *p2) { + SLDataIter *pIter1 = (SLDataIter *)(((uint8_t *)p1) - offsetof(SLDataIter, node)); + SLDataIter *pIter2 = (SLDataIter *)(((uint8_t *)p2) - offsetof(SLDataIter, node)); TSDBKEY key1 = TSDBROW_KEY(&pIter1->rInfo.row); TSDBKEY key2 = TSDBROW_KEY(&pIter2->rInfo.row); @@ -529,6 +550,7 @@ int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFRead pMTree->pLoadInfo = pBlockLoadInfo; pMTree->destroyLoadInfo = destroyLoadInfo; + ASSERT(pMTree->pLoadInfo != NULL); for (int32_t i = 0; i < pFReader->pSet->nSttF; ++i) { // open all last file struct SLDataIter *pIter = NULL; @@ -569,7 +591,7 @@ bool tMergeTreeNext(SMergeTree *pMTree) { // compare with min in RB Tree pIter = (SLDataIter *)tRBTreeMin(&pMTree->rbt); if (pMTree->pIter && pIter) { - int32_t c = pMTree->rbt.cmprFn(RBTREE_NODE_PAYLOAD(&pMTree->pIter->node), RBTREE_NODE_PAYLOAD(&pIter->node)); + int32_t c = pMTree->rbt.cmprFn(&pMTree->pIter->node, &pIter->node); if (c > 0) { tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pMTree->pIter); pMTree->pIter = NULL; diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c index e4080ccf1e36bd04032d0c16fe11b094c3b69d31..51978234901a6a4e26f78d0c7d867818d64fa7eb 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOpen.c +++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c @@ -87,9 +87,13 @@ _err: int tsdbClose(STsdb **pTsdb) { if (*pTsdb) { - taosThreadRwlockDestroy(&(*pTsdb)->rwLock); + taosThreadRwlockWrlock(&(*pTsdb)->rwLock); tsdbMemTableDestroy((*pTsdb)->mem); (*pTsdb)->mem = NULL; + taosThreadRwlockUnlock(&(*pTsdb)->rwLock); + + taosThreadRwlockDestroy(&(*pTsdb)->rwLock); + tsdbFSClose(*pTsdb); tsdbCloseCache(*pTsdb); taosMemoryFreeClear(*pTsdb); diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 1ed050f64f72ced65cd3c39883886f962dabd177..c346eeef1da4a480bf033d6d19b5d2891f1313fd 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -1645,6 +1645,7 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader, STSRow* pTSRow = NULL; SRowMerger merge = {0}; TSDBROW fRow = tMergeTreeGetRow(&pLastBlockReader->mergeTree); + tsdbTrace("fRow ptr:%p, %d, uid:%" PRIu64 ", %s", fRow.pBlockData, fRow.iRow, pLastBlockReader->uid, pReader->idStr); // only last block exists if ((!mergeBlockData) || (tsLastBlock != pBlockData->aTSKEY[pDumpInfo->rowIndex])) { @@ -2675,9 +2676,9 @@ static STsdb* getTsdbByRetentions(SVnode* pVnode, TSKEY winSKey, SRetention* ret int8_t level = 0; int8_t precision = pVnode->config.tsdbCfg.precision; int64_t now = taosGetTimestamp(precision); - int64_t offset = tsQueryRsmaTolerance * ((precision == TSDB_TIME_PRECISION_MILLI) ? 1 - : (precision == TSDB_TIME_PRECISION_MICRO) ? 1000 - : 1000000); + int64_t offset = tsQueryRsmaTolerance * ((precision == TSDB_TIME_PRECISION_MILLI) ? 1L + : (precision == TSDB_TIME_PRECISION_MICRO) ? 1000L + : 1000000L); for (int8_t i = 0; i < TSDB_RETENTION_MAX; ++i) { SRetention* pRetention = retentions + level; @@ -3371,14 +3372,13 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl if (pCond->suid != 0) { pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, pReader->suid, -1, 1); if (pReader->pSchema == NULL) { - tsdbError("failed to get table schema, suid:%" PRIu64 ", ver:%" PRId64 " , %s", pReader->suid, -1, - pReader->idStr); + tsdbError("failed to get table schema, suid:%" PRIu64 ", ver:-1, %s", pReader->suid, pReader->idStr); } } else if (taosArrayGetSize(pTableList) > 0) { STableKeyInfo* pKey = taosArrayGet(pTableList, 0); pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, pKey->uid, -1, 1); if (pReader->pSchema == NULL) { - tsdbError("failed to get table schema, uid:%" PRIu64 ", ver:%" PRId64 " , %s", pKey->uid, -1, pReader->idStr); + tsdbError("failed to get table schema, uid:%" PRIu64 ", ver:-1, %s", pKey->uid, pReader->idStr); } } @@ -3394,19 +3394,20 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl goto _err; } - code = tsdbTakeReadSnap(pReader->pTsdb, &pReader->pReadSnap, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - goto _err; - } - - if (pReader->type == TIMEWINDOW_RANGE_CONTAINED) { - code = doOpenReaderImpl(pReader); + if (numOfTables > 0) { + code = tsdbTakeReadSnap(pReader->pTsdb, &pReader->pReadSnap, pReader->idStr); if (code != TSDB_CODE_SUCCESS) { - return code; + goto _err; } - } else { - STsdbReader* pPrevReader = pReader->innerReader[0]; - STsdbReader* pNextReader = pReader->innerReader[1]; + + if (pReader->type == TIMEWINDOW_RANGE_CONTAINED) { + code = doOpenReaderImpl(pReader); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + } else { + STsdbReader* pPrevReader = pReader->innerReader[0]; + STsdbReader* pNextReader = pReader->innerReader[1]; // we need only one row pPrevReader->capacity = 1; @@ -3421,19 +3422,20 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl pNextReader->pMemSchema = pReader->pMemSchema; pNextReader->pReadSnap = pReader->pReadSnap; - code = doOpenReaderImpl(pPrevReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + code = doOpenReaderImpl(pPrevReader); + if (code != TSDB_CODE_SUCCESS) { + return code; + } - code = doOpenReaderImpl(pNextReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + code = doOpenReaderImpl(pNextReader); + if (code != TSDB_CODE_SUCCESS) { + return code; + } - code = doOpenReaderImpl(pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; + code = doOpenReaderImpl(pReader); + if (code != TSDB_CODE_SUCCESS) { + return code; + } } } @@ -3512,6 +3514,10 @@ void tsdbReaderClose(STsdbReader* pReader) { taosMemoryFree(pLReader); } + if (pReader->innerReader[0] != 0) { + tsdbUntakeReadSnap(pReader->innerReader[0]->pTsdb, pReader->innerReader[0]->pReadSnap, pReader->idStr); + } + tsdbDebug( "%p :io-cost summary: head-file:%" PRIu64 ", head-file time:%.2f ms, SMA:%" PRId64 " SMA-time:%.2f ms, fileBlocks:%" PRId64 diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index 167b4a104c84d73acb4cde1bf192440645adbf31..84b3afe72c70147a28bdb55446c806a1f1ebd70e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -18,7 +18,7 @@ // =============== PAGE-WISE FILE =============== static int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **ppFD) { int32_t code = 0; - STsdbFD *pFD; + STsdbFD *pFD = NULL; *ppFD = NULL; @@ -35,6 +35,7 @@ static int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsd pFD->pFD = taosOpenFile(path, flag); if (pFD->pFD == NULL) { code = TAOS_SYSTEM_ERROR(errno); + taosMemoryFree(pFD); goto _exit; } pFD->szPage = szPage; @@ -42,11 +43,15 @@ static int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsd pFD->pBuf = taosMemoryCalloc(1, szPage); if (pFD->pBuf == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; + taosCloseFile(&pFD->pFD); taosMemoryFree(pFD); goto _exit; } if (taosStatFile(path, &pFD->szFile, NULL) < 0) { code = TAOS_SYSTEM_ERROR(errno); + taosMemoryFree(pFD->pBuf); + taosCloseFile(&pFD->pFD); + taosMemoryFree(pFD); goto _exit; } ASSERT(pFD->szFile % szPage == 0); @@ -59,10 +64,12 @@ _exit: static void tsdbCloseFile(STsdbFD **ppFD) { STsdbFD *pFD = *ppFD; - taosMemoryFree(pFD->pBuf); - taosCloseFile(&pFD->pFD); - taosMemoryFree(pFD); - *ppFD = NULL; + if (pFD) { + taosMemoryFree(pFD->pBuf); + taosCloseFile(&pFD->pFD); + taosMemoryFree(pFD); + *ppFD = NULL; + } } static int32_t tsdbWriteFilePage(STsdbFD *pFD) { @@ -117,7 +124,7 @@ static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno) { } // check - if (!taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) { + if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) { code = TSDB_CODE_FILE_CORRUPTED; goto _exit; } @@ -443,7 +450,7 @@ int32_t tsdbWriteDataBlk(SDataFWriter *pWriter, SMapData *mDataBlk, SBlockIdx *p pBlockIdx->size = size; pHeadFile->size += size; - tsdbTrace("vgId:%d, write block, file ID:%d commit ID:%d suid:%" PRId64 " uid:%" PRId64 " offset:%" PRId64 + tsdbTrace("vgId:%d, write block, file ID:%d commit ID:%" PRId64 " suid:%" PRId64 " uid:%" PRId64 " offset:%" PRId64 " size:%" PRId64 " nItem:%d", TD_VID(pWriter->pTsdb->pVnode), pWriter->wSet.fid, pHeadFile->commitID, pBlockIdx->suid, pBlockIdx->uid, pBlockIdx->offset, pBlockIdx->size, mDataBlk->nItem); @@ -457,7 +464,7 @@ _err: int32_t tsdbWriteSttBlk(SDataFWriter *pWriter, SArray *aSttBlk) { int32_t code = 0; SSttFile *pSttFile = &pWriter->fStt[pWriter->wSet.nSttF - 1]; - int64_t size; + int64_t size = 0; int64_t n; // check @@ -836,7 +843,8 @@ _err: // SDataFReader ==================================================== int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet) { int32_t code = 0; - SDataFReader *pReader; + int32_t lino = 0; + SDataFReader *pReader = NULL; int32_t szPage = pTsdb->pVnode->config.tsdbPageSize; char fname[TSDB_FILENAME_LEN]; @@ -844,7 +852,7 @@ int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pS pReader = (SDataFReader *)taosMemoryCalloc(1, sizeof(*pReader)); if (pReader == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } pReader->pTsdb = pTsdb; pReader->pSet = pSet; @@ -852,31 +860,40 @@ int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pS // head tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname); code = tsdbOpenFile(fname, szPage, TD_FILE_READ, &pReader->pHeadFD); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); // data tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname); code = tsdbOpenFile(fname, szPage, TD_FILE_READ, &pReader->pDataFD); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); // sma tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname); code = tsdbOpenFile(fname, szPage, TD_FILE_READ, &pReader->pSmaFD); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); // stt for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) { tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname); code = tsdbOpenFile(fname, szPage, TD_FILE_READ, &pReader->aSttFD[iStt]); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } - *ppReader = pReader; - return code; - -_err: - tsdbError("vgId:%d, tsdb data file reader open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); - *ppReader = NULL; +_exit: + if (code) { + *ppReader = NULL; + tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + + if (pReader) { + for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) tsdbCloseFile(&pReader->aSttFD[iStt]); + tsdbCloseFile(&pReader->pSmaFD); + tsdbCloseFile(&pReader->pDataFD); + tsdbCloseFile(&pReader->pHeadFD); + taosMemoryFree(pReader); + } + } else { + *ppReader = pReader; + } return code; } @@ -906,10 +923,6 @@ int32_t tsdbDataFReaderClose(SDataFReader **ppReader) { taosMemoryFree(*ppReader); *ppReader = NULL; return code; - -_err: - tsdbError("vgId:%d, data file reader close failed since %s", TD_VID((*ppReader)->pTsdb->pVnode), tstrerror(code)); - return code; } int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx) { @@ -1289,16 +1302,17 @@ _exit: // SDelFWriter ==================================================== int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb) { int32_t code = 0; + int32_t lino = 0; char fname[TSDB_FILENAME_LEN]; uint8_t hdr[TSDB_FHDR_SIZE] = {0}; - SDelFWriter *pDelFWriter; + SDelFWriter *pDelFWriter = NULL; int64_t n; // alloc pDelFWriter = (SDelFWriter *)taosMemoryCalloc(1, sizeof(*pDelFWriter)); if (pDelFWriter == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } pDelFWriter->pTsdb = pTsdb; pDelFWriter->fDel = *pFile; @@ -1306,21 +1320,28 @@ int32_t tsdbDelFWriterOpen(SDelFWriter **ppWriter, SDelFile *pFile, STsdb *pTsdb tsdbDelFileName(pTsdb, pFile, fname); code = tsdbOpenFile(fname, pTsdb->pVnode->config.tsdbPageSize, TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE, &pDelFWriter->pWriteH); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); // update header code = tsdbWriteFile(pDelFWriter->pWriteH, 0, hdr, TSDB_FHDR_SIZE); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); pDelFWriter->fDel.size = TSDB_FHDR_SIZE; pDelFWriter->fDel.offset = 0; *ppWriter = pDelFWriter; - return code; -_err: - tsdbError("vgId:%d, failed to open del file writer since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); - *ppWriter = NULL; +_exit: + if (code) { + if (pDelFWriter) { + taosMemoryFree(pDelFWriter); + tsdbCloseFile(&pDelFWriter->pWriteH); + } + *ppWriter = NULL; + tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(errno)); + } else { + *ppWriter = pDelFWriter; + } return code; } @@ -1456,15 +1477,15 @@ struct SDelFReader { int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb) { int32_t code = 0; + int32_t lino = 0; char fname[TSDB_FILENAME_LEN]; - SDelFReader *pDelFReader; - int64_t n; + SDelFReader *pDelFReader = NULL; // alloc pDelFReader = (SDelFReader *)taosMemoryCalloc(1, sizeof(*pDelFReader)); if (pDelFReader == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + goto _exit; } // open impl @@ -1473,14 +1494,18 @@ int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb tsdbDelFileName(pTsdb, pFile, fname); code = tsdbOpenFile(fname, pTsdb->pVnode->config.tsdbPageSize, TD_FILE_READ, &pDelFReader->pReadH); - if (code) goto _err; - - *ppReader = pDelFReader; - return code; + if (code) { + taosMemoryFree(pDelFReader); + goto _exit; + } -_err: - tsdbError("vgId:%d, del file reader open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); - *ppReader = NULL; +_exit: + if (code) { + *ppReader = NULL; + tsdbError("vgId:%d %s failed at %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + } else { + *ppReader = pDelFReader; + } return code; } @@ -1573,4 +1598,4 @@ int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx) { _err: tsdbError("vgId:%d, read del idx failed since %s", TD_VID(pReader->pTsdb->pVnode), tstrerror(code)); return code; -} \ No newline at end of file +} diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index a928dc3484c67461a8b5a49c39d60e3af4336e8b..74c704598d891d5c50e0fd17766834401891e96d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -67,6 +67,13 @@ extern int32_t tRowInfoCmprFn(const void* p1, const void* p2); extern int32_t tsdbReadDataBlockEx(SDataFReader* pReader, SDataBlk* pDataBlk, SBlockData* pBlockData); extern int32_t tsdbUpdateTableSchema(SMeta* pMeta, int64_t suid, int64_t uid, SSkmInfo* pSkmInfo); +static int32_t tFDataIterCmprFn(const SRBTreeNode* pNode1, const SRBTreeNode* pNode2) { + SFDataIter* pIter1 = (SFDataIter*)(((uint8_t*)pNode1) - offsetof(SFDataIter, n)); + SFDataIter* pIter2 = (SFDataIter*)(((uint8_t*)pNode2) - offsetof(SFDataIter, n)); + + return tRowInfoCmprFn(&pIter1->rInfo, &pIter2->rInfo); +} + static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) { int32_t code = 0; @@ -79,7 +86,7 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) { if (code) goto _err; pReader->pIter = NULL; - tRBTreeCreate(&pReader->rbt, tRowInfoCmprFn); + tRBTreeCreate(&pReader->rbt, tFDataIterCmprFn); // .data file SFDataIter* pIter = &pReader->aFDataIter[0]; @@ -421,7 +428,7 @@ static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) { n += tPutDelData((*ppData) + n, pDelData); } - tsdbInfo("vgId:%d, vnode snapshot tsdb read del data for %s, suid:%" PRId64 " uid:%d" PRId64 " size:%d", + tsdbInfo("vgId:%d, vnode snapshot tsdb read del data for %s, suid:%" PRId64 " uid:%" PRId64 " size:%d", TD_VID(pTsdb->pVnode), pTsdb->path, pDelIdx->suid, pDelIdx->uid, size); break; @@ -431,20 +438,21 @@ _exit: return code; _err: - tsdbError("vgId:%d, vnode snapshot tsdb read del for %s failed since %s", TD_VID(pTsdb->pVnode), pTsdb->pVnode, + tsdbError("vgId:%d, vnode snapshot tsdb read del for %s failed since %s", TD_VID(pTsdb->pVnode), pTsdb->path, tstrerror(code)); return code; } int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, int8_t type, STsdbSnapReader** ppReader) { int32_t code = 0; + int32_t lino = 0; STsdbSnapReader* pReader = NULL; // alloc pReader = (STsdbSnapReader*)taosMemoryCalloc(1, sizeof(*pReader)); if (pReader == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } pReader->pTsdb = pTsdb; pReader->sver = sver; @@ -454,19 +462,19 @@ int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, int8_t type code = taosThreadRwlockRdlock(&pTsdb->rwLock); if (code) { code = TAOS_SYSTEM_ERROR(code); - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } code = tsdbFSRef(pTsdb, &pReader->fs); if (code) { taosThreadRwlockUnlock(&pTsdb->rwLock); - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } code = taosThreadRwlockUnlock(&pTsdb->rwLock); if (code) { code = TAOS_SYSTEM_ERROR(code); - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } // data @@ -478,43 +486,52 @@ int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, int8_t type pIter->aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx)); if (pIter->aBlockIdx == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } } else { pIter->aSttBlk = taosArrayInit(0, sizeof(SSttBlk)); if (pIter->aSttBlk == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } } code = tBlockDataCreate(&pIter->bData); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } code = tBlockDataCreate(&pReader->bData); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); // del pReader->aDelIdx = taosArrayInit(0, sizeof(SDelIdx)); if (pReader->aDelIdx == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } pReader->aDelData = taosArrayInit(0, sizeof(SDelData)); if (pReader->aDelData == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } - tsdbInfo("vgId:%d, vnode snapshot tsdb reader opened for %s", TD_VID(pTsdb->pVnode), pTsdb->path); - *ppReader = pReader; - return code; - -_err: - tsdbError("vgId:%d, vnode snapshot tsdb reader open for %s failed since %s", TD_VID(pTsdb->pVnode), pTsdb->path, - tstrerror(code)); - *ppReader = NULL; +_exit: + if (code) { + tsdbError("vgId:%d %s failed at line %d since %s, TSDB path: %s", TD_VID(pTsdb->pVnode), lino, tstrerror(code), + pTsdb->path); + *ppReader = NULL; + + if (pReader) { + taosArrayDestroy(pReader->aDelData); + taosArrayDestroy(pReader->aDelIdx); + tBlockDataDestroy(&pReader->bData, 1); + tsdbFSDestroy(&pReader->fs); + taosMemoryFree(pReader); + } + } else { + *ppReader = pReader; + tsdbInfo("vgId:%d, vnode snapshot tsdb reader opened for %s", TD_VID(pTsdb->pVnode), pTsdb->path); + } return code; } @@ -1247,20 +1264,21 @@ _err: // APIs int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapWriter** ppWriter) { int32_t code = 0; + int32_t lino = 0; STsdbSnapWriter* pWriter = NULL; // alloc pWriter = (STsdbSnapWriter*)taosMemoryCalloc(1, sizeof(*pWriter)); if (pWriter == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } pWriter->pTsdb = pTsdb; pWriter->sver = sver; pWriter->ever = ever; code = tsdbFSCopy(pTsdb, &pWriter->fs); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); // config pWriter->minutes = pTsdb->keepCfg.days; @@ -1272,7 +1290,7 @@ int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapWr // SNAP_DATA_TSDB code = tBlockDataCreate(&pWriter->bData); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); pWriter->fid = INT32_MIN; pWriter->id = (TABLEID){0}; @@ -1280,53 +1298,67 @@ int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapWr pWriter->dReader.aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx)); if (pWriter->dReader.aBlockIdx == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } code = tBlockDataCreate(&pWriter->dReader.bData); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); // Writer pWriter->dWriter.aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx)); if (pWriter->dWriter.aBlockIdx == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } pWriter->dWriter.aSttBlk = taosArrayInit(0, sizeof(SSttBlk)); if (pWriter->dWriter.aSttBlk == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } code = tBlockDataCreate(&pWriter->dWriter.bData); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); code = tBlockDataCreate(&pWriter->dWriter.sData); - if (code) goto _err; + TSDB_CHECK_CODE(code, lino, _exit); // SNAP_DATA_DEL pWriter->aDelIdxR = taosArrayInit(0, sizeof(SDelIdx)); if (pWriter->aDelIdxR == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } pWriter->aDelData = taosArrayInit(0, sizeof(SDelData)); if (pWriter->aDelData == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } pWriter->aDelIdxW = taosArrayInit(0, sizeof(SDelIdx)); if (pWriter->aDelIdxW == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; + TSDB_CHECK_CODE(code, lino, _exit); } - *ppWriter = pWriter; - - tsdbInfo("vgId:%d, tsdb snapshot writer open for %s succeed", TD_VID(pTsdb->pVnode), pTsdb->path); - return code; - -_err: - tsdbError("vgId:%d, tsdb snapshot writer open for %s failed since %s", TD_VID(pTsdb->pVnode), pTsdb->path, - tstrerror(code)); - *ppWriter = NULL; +_exit: + if (code) { + tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); + *ppWriter = NULL; + + if (pWriter) { + if (pWriter->aDelIdxW) taosArrayDestroy(pWriter->aDelIdxW); + if (pWriter->aDelData) taosArrayDestroy(pWriter->aDelData); + if (pWriter->aDelIdxR) taosArrayDestroy(pWriter->aDelIdxR); + tBlockDataDestroy(&pWriter->dWriter.sData, 1); + tBlockDataDestroy(&pWriter->dWriter.bData, 1); + if (pWriter->dWriter.aSttBlk) taosArrayDestroy(pWriter->dWriter.aSttBlk); + if (pWriter->dWriter.aBlockIdx) taosArrayDestroy(pWriter->dWriter.aBlockIdx); + tBlockDataDestroy(&pWriter->dReader.bData, 1); + if (pWriter->dReader.aBlockIdx) taosArrayDestroy(pWriter->dReader.aBlockIdx); + tBlockDataDestroy(&pWriter->bData, 1); + tsdbFSDestroy(&pWriter->fs); + taosMemoryFree(pWriter); + } + } else { + tsdbDebug("vgId:%d, tsdb snapshot writer open for %s succeed", TD_VID(pTsdb->pVnode), pTsdb->path); + *ppWriter = pWriter; + } return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbWrite.c b/source/dnode/vnode/src/tsdb/tsdbWrite.c index 0a9fbf92a4bf62326aa9755b827b83d0d510d2f7..f38802aee78021c158a29fed44e0fc14e06fc482 100644 --- a/source/dnode/vnode/src/tsdb/tsdbWrite.c +++ b/source/dnode/vnode/src/tsdb/tsdbWrite.c @@ -34,7 +34,9 @@ int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq *pMsg, SSubmitRsp * } // loop to insert - tInitSubmitMsgIter(pMsg, &msgIter); + if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) { + return -1; + } while (true) { SSubmitBlkRsp r = {0}; tGetSubmitMsgNext(&msgIter, &pBlock); diff --git a/source/dnode/vnode/src/vnd/vnodeBufPool.c b/source/dnode/vnode/src/vnd/vnodeBufPool.c index 3c0a041197d372f2540e11e8edb162b15c39c2e7..682f2b4225d6f8151a0061a1a420eca753ede3c3 100644 --- a/source/dnode/vnode/src/vnd/vnodeBufPool.c +++ b/source/dnode/vnode/src/vnd/vnodeBufPool.c @@ -112,6 +112,8 @@ void vnodeBufPoolReset(SVBufPool *pPool) { void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) { SVBufPoolNode *pNode; void *p = NULL; + ASSERT(pPool != NULL); + taosThreadSpinLock(&pPool->lock); if (pPool->node.size >= pPool->ptr - pPool->node.data + size) { // allocate from the anchor node @@ -141,17 +143,17 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) { } void vnodeBufPoolFree(SVBufPool *pPool, void *p) { - uint8_t *ptr = (uint8_t *)p; - SVBufPoolNode *pNode; + // uint8_t *ptr = (uint8_t *)p; + // SVBufPoolNode *pNode; - if (ptr < pPool->node.data || ptr >= pPool->node.data + pPool->node.size) { - pNode = &((SVBufPoolNode *)p)[-1]; - *pNode->pnext = pNode->prev; - pNode->prev->pnext = pNode->pnext; + // if (ptr < pPool->node.data || ptr >= pPool->node.data + pPool->node.size) { + // pNode = &((SVBufPoolNode *)p)[-1]; + // *pNode->pnext = pNode->prev; + // pNode->prev->pnext = pNode->pnext; - pPool->size = pPool->size - sizeof(*pNode) - pNode->size; - taosMemoryFree(pNode); - } + // pPool->size = pPool->size - sizeof(*pNode) - pNode->size; + // taosMemoryFree(pNode); + // } } void vnodeBufPoolRef(SVBufPool *pPool) { diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 07d9b9626137bf7a80f049367fa9f694cbf127fd..07c4c32955ece956b44beaba5ca78bcd0877e916 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -73,7 +73,7 @@ int vnodeBegin(SVnode *pVnode) { int vnodeShouldCommit(SVnode *pVnode) { if (pVnode->inUse) { - return pVnode->inUse->size > pVnode->inUse->node.size; + return osDataSpaceAvailable() && (pVnode->inUse->size > pVnode->inUse->node.size); } return false; } @@ -89,6 +89,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) { data = NULL; if (vnodeEncodeInfo(pInfo, &data) < 0) { + vError("failed to encode json info."); return -1; } @@ -101,7 +102,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) { } if (taosWriteFile(pFile, data, strlen(data)) < 0) { - vError("failed to write info file:%s data:%s", fname, terrstr()); + vError("failed to write info file:%s error:%s", fname, terrstr()); terrno = TAOS_SYSTEM_ERROR(errno); goto _err; } @@ -233,15 +234,15 @@ int vnodeCommit(SVnode *pVnode) { snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path); } if (vnodeSaveInfo(dir, &info) < 0) { - ASSERT(0); + vError("vgId:%d, failed to save vnode info since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } walBeginSnapshot(pVnode->pWal, pVnode->state.applied); // preCommit // smaSyncPreCommit(pVnode->pSma); - if (smaAsyncPreCommit(pVnode->pSma) < 0) { - ASSERT(0); + if(smaAsyncPreCommit(pVnode->pSma) < 0){ + vError("vgId:%d, failed to async pre-commit sma since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } @@ -250,44 +251,44 @@ int vnodeCommit(SVnode *pVnode) { // commit each sub-system if (metaCommit(pVnode->pMeta) < 0) { - ASSERT(0); + vError("vgId:%d, failed to commit meta since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } if (VND_IS_RSMA(pVnode)) { if (smaAsyncCommit(pVnode->pSma) < 0) { - ASSERT(0); + vError("vgId:%d, failed to async commit sma since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } if (tsdbCommit(VND_RSMA0(pVnode)) < 0) { - ASSERT(0); + vError("vgId:%d, failed to commit tsdb rsma0 since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } if (tsdbCommit(VND_RSMA1(pVnode)) < 0) { - ASSERT(0); + vError("vgId:%d, failed to commit tsdb rsma1 since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } if (tsdbCommit(VND_RSMA2(pVnode)) < 0) { - ASSERT(0); + vError("vgId:%d, failed to commit tsdb rsma2 since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } } else { if (tsdbCommit(pVnode->pTsdb) < 0) { - ASSERT(0); + vError("vgId:%d, failed to commit tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } } if (tqCommit(pVnode->pTq) < 0) { - ASSERT(0); + vError("vgId:%d, failed to commit tq since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } // walCommit (TODO) // commit info if (vnodeCommitInfo(dir, &info) < 0) { - ASSERT(0); + vError("vgId:%d, failed to commit vnode info since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } @@ -296,7 +297,7 @@ int vnodeCommit(SVnode *pVnode) { // postCommit // smaSyncPostCommit(pVnode->pSma); if (smaAsyncPostCommit(pVnode->pSma) < 0) { - ASSERT(0); + vError("vgId:%d, failed to async post-commit sma since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } diff --git a/source/dnode/vnode/src/vnd/vnodeModule.c b/source/dnode/vnode/src/vnd/vnodeModule.c index 314c0e7390a6616e8bceba613cf4a57687db8fef..9fe37505add7d2ec768233637f9da2c55f7124fb 100644 --- a/source/dnode/vnode/src/vnd/vnodeModule.c +++ b/source/dnode/vnode/src/vnd/vnodeModule.c @@ -46,11 +46,17 @@ int vnodeInit(int nthreads) { return 0; } - vnodeGlobal.stop = 0; + taosThreadMutexInit(&vnodeGlobal.mutex, NULL); + taosThreadCondInit(&vnodeGlobal.hasTask, NULL); + taosThreadMutexLock(&vnodeGlobal.mutex); + + vnodeGlobal.stop = 0; vnodeGlobal.queue.next = &vnodeGlobal.queue; vnodeGlobal.queue.prev = &vnodeGlobal.queue; + taosThreadMutexUnlock(&(vnodeGlobal.mutex)); + vnodeGlobal.nthreads = nthreads; vnodeGlobal.threads = taosMemoryCalloc(nthreads, sizeof(TdThread)); if (vnodeGlobal.threads == NULL) { @@ -59,9 +65,6 @@ int vnodeInit(int nthreads) { return -1; } - taosThreadMutexInit(&vnodeGlobal.mutex, NULL); - taosThreadCondInit(&vnodeGlobal.hasTask, NULL); - for (int i = 0; i < nthreads; i++) { taosThreadCreate(&(vnodeGlobal.threads[i]), NULL, loop, NULL); } diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index de3af7cde6933d1bce189f3b3c8ba81b52293056..001bb5f7f209f14887d637103574c9e79ab5878d 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -38,7 +38,7 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { if (taosMkDir(path)) { return TAOS_SYSTEM_ERROR(errno); } - strcpy(dir, path); + snprintf(dir, TSDB_FILENAME_LEN, "%s", path); } if (pCfg) { @@ -51,7 +51,7 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { info.state.commitID = 0; if (vnodeSaveInfo(dir, &info) < 0 || vnodeCommitInfo(dir, &info) < 0) { - vError("vgId:%d, failed to save vnode config since %s", pCfg->vgId, tstrerror(terrno)); + vError("vgId:%d, failed to save vnode config since %s", pCfg ? pCfg->vgId : 0, tstrerror(terrno)); return -1; } @@ -140,7 +140,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { pVnode->pWal = walOpen(tdir, &(pVnode->config.walCfg)); if (pVnode->pWal == NULL) { - vError("vgId:%d, failed to open vnode wal since %s", TD_VID(pVnode), tstrerror(terrno)); + vError("vgId:%d, failed to open vnode wal since %s. wal:%s", TD_VID(pVnode), tstrerror(terrno), tdir); goto _err; } diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index 08c3a34699b6f9f83b366e42f77e42a6094f09ed..9cbb1b8af491ea1567c8d9a3ada47614749503bc 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -166,7 +166,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) if (*ppData) { goto _exit; } else { - pReader->tqHandleDone = 1; + pReader->tqOffsetDone = 1; code = tqOffsetReaderClose(&pReader->pTqOffsetReader); if (code) goto _err; } @@ -219,7 +219,7 @@ _exit: return code; _err: - vError("vgId:% vnode snapshot read failed since %s", TD_VID(pReader->pVnode), tstrerror(code)); + vError("vgId:%d vnode snapshot read failed since %s", TD_VID(pReader->pVnode), tstrerror(code)); return code; } @@ -260,7 +260,10 @@ int32_t vnodeSnapWriterOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapWr // commit it code = vnodeCommit(pVnode); - if (code) goto _err; + if (code) { + taosMemoryFree(pWriter); + goto _err; + } // inc commit ID pVnode->state.commitID++; diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 131327976f06d7a610a2319b1f4a40e2c097c51f..3556b47dd3c88b65517ad4706618917e00bcd3d6 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -41,16 +41,28 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) { int32_t nReqs; tDecoderInit(&dc, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead)); - tStartDecode(&dc); + if (tStartDecode(&dc) < 0) { + code = TSDB_CODE_INVALID_MSG; + return code; + } - tDecodeI32v(&dc, &nReqs); + if (tDecodeI32v(&dc, &nReqs) < 0) { + code = TSDB_CODE_INVALID_MSG; + goto _err; + } for (int32_t iReq = 0; iReq < nReqs; iReq++) { tb_uid_t uid = tGenIdPI64(); char *name = NULL; tStartDecode(&dc); - tDecodeI32v(&dc, NULL); - tDecodeCStr(&dc, &name); + if (tDecodeI32v(&dc, NULL) < 0) { + code = TSDB_CODE_INVALID_MSG; + return code; + } + if (tDecodeCStr(&dc, &name) < 0) { + code = TSDB_CODE_INVALID_MSG; + return code; + } *(int64_t *)(dc.data + dc.pos) = uid; *(int64_t *)(dc.data + dc.pos + 8) = ctime; @@ -68,7 +80,10 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) { int64_t ctime = taosGetTimestampMs(); tb_uid_t uid; - tInitSubmitMsgIter(pSubmitReq, &msgIter); + if (tInitSubmitMsgIter(pSubmitReq, &msgIter) < 0) { + code = terrno; + goto _err; + } for (;;) { tGetSubmitMsgNext(&msgIter, &pBlock); @@ -78,10 +93,19 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) { char *name = NULL; tDecoderInit(&dc, pBlock->data, msgIter.schemaLen); - tStartDecode(&dc); + if (tStartDecode(&dc) < 0) { + code = TSDB_CODE_INVALID_MSG; + return code; + } - tDecodeI32v(&dc, NULL); - tDecodeCStr(&dc, &name); + if (tDecodeI32v(&dc, NULL) < 0) { + code = TSDB_CODE_INVALID_MSG; + return code; + } + if (tDecodeCStr(&dc, &name) < 0) { + code = TSDB_CODE_INVALID_MSG; + return code; + } uid = metaGetTableEntryUidByName(pVnode->pMeta, name); if (uid == 0) { @@ -145,6 +169,12 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp int32_t len; int32_t ret; + if (!pVnode->inUse) { + terrno = TSDB_CODE_VND_NOT_SYNCED; + vError("vgId:%d, not ready to write since %s", TD_VID(pVnode), terrstr()); + return -1; + } + vDebug("vgId:%d, start to process write request %s, index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version); @@ -265,10 +295,16 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp _do_commit: vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), version); // commit current change - vnodeCommit(pVnode); + if (vnodeCommit(pVnode) < 0) { + vError("vgId:%d, failed to commit vnode since %s.", TD_VID(pVnode), tstrerror(terrno)); + goto _err; + } // start a new one - vnodeBegin(pVnode); + if (vnodeBegin(pVnode) < 0) { + vError("vgId:%d, failed to begin vnode since %s.", TD_VID(pVnode), tstrerror(terrno)); + goto _err; + } } return 0; diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 9b62581051daac9c232409c0cb30d379e3a4d596..fe71987103aedbee555b67e99c95a7fb6fb2fb0e 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -21,18 +21,18 @@ extern "C" { #endif #include "catalog.h" -#include "tcommon.h" #include "query.h" +#include "tcommon.h" #define CTG_DEFAULT_CACHE_CLUSTER_NUMBER 6 -#define CTG_DEFAULT_CACHE_VGROUP_NUMBER 100 -#define CTG_DEFAULT_CACHE_DB_NUMBER 20 +#define CTG_DEFAULT_CACHE_VGROUP_NUMBER 100 +#define CTG_DEFAULT_CACHE_DB_NUMBER 20 #define CTG_DEFAULT_CACHE_TBLMETA_NUMBER 1000 -#define CTG_DEFAULT_RENT_SECOND 10 -#define CTG_DEFAULT_RENT_SLOT_SIZE 10 -#define CTG_DEFAULT_MAX_RETRY_TIMES 3 -#define CTG_DEFAULT_BATCH_NUM 64 -#define CTG_DEFAULT_FETCH_NUM 8 +#define CTG_DEFAULT_RENT_SECOND 10 +#define CTG_DEFAULT_RENT_SLOT_SIZE 10 +#define CTG_DEFAULT_MAX_RETRY_TIMES 3 +#define CTG_DEFAULT_BATCH_NUM 64 +#define CTG_DEFAULT_FETCH_NUM 8 #define CTG_RENT_SLOT_SECOND 1.5 @@ -90,7 +90,6 @@ typedef enum { CTG_TASK_DONE, } CTG_TASK_STATUS; - typedef struct SCtgDebug { bool lockEnable; bool cacheEnable; @@ -108,19 +107,19 @@ typedef struct SCtgTbCacheInfo { typedef struct SCtgTbMetaCtx { SCtgTbCacheInfo tbInfo; - int32_t vgId; - SName* pName; - int32_t flag; + int32_t vgId; + SName* pName; + int32_t flag; } SCtgTbMetaCtx; typedef struct SCtgFetch { - int32_t dbIdx; - int32_t tbIdx; - int32_t fetchIdx; - int32_t resIdx; - int32_t flag; + int32_t dbIdx; + int32_t tbIdx; + int32_t fetchIdx; + int32_t resIdx; + int32_t flag; SCtgTbCacheInfo tbInfo; - int32_t vgId; + int32_t vgId; } SCtgFetch; typedef struct SCtgTbMetasCtx { @@ -153,7 +152,7 @@ typedef struct SCtgDbInfoCtx { } SCtgDbInfoCtx; typedef struct SCtgTbHashCtx { - char dbFName[TSDB_DB_FNAME_LEN]; + char dbFName[TSDB_DB_FNAME_LEN]; SName* pName; } SCtgTbHashCtx; @@ -164,7 +163,6 @@ typedef struct SCtgTbHashsCtx { SArray* pFetchs; } SCtgTbHashsCtx; - typedef struct SCtgIndexCtx { char indexFName[TSDB_INDEX_FNAME_LEN]; } SCtgIndexCtx; @@ -181,118 +179,116 @@ typedef STableIndexRsp STableIndex; typedef struct SCtgTbCache { SRWLatch metaLock; - STableMeta *pMeta; + STableMeta* pMeta; SRWLatch indexLock; - STableIndex *pIndex; + STableIndex* pIndex; } SCtgTbCache; typedef struct SCtgVgCache { - SRWLatch vgLock; - SDBVgInfo *vgInfo; + SRWLatch vgLock; + SDBVgInfo* vgInfo; } SCtgVgCache; typedef struct SCtgDBCache { - SRWLatch dbLock; // RC between destroy tbCache/stbCache and all reads - uint64_t dbId; - int8_t deleted; - SCtgVgCache vgCache; - SHashObj *tbCache; // key:tbname, value:SCtgTbCache - SHashObj *stbCache; // key:suid, value:char* + SRWLatch dbLock; // RC between destroy tbCache/stbCache and all reads + uint64_t dbId; + int8_t deleted; + SCtgVgCache vgCache; + SHashObj* tbCache; // key:tbname, value:SCtgTbCache + SHashObj* stbCache; // key:suid, value:char* } SCtgDBCache; typedef struct SCtgRentSlot { SRWLatch lock; bool needSort; - SArray *meta; // element is SDbVgVersion or SSTableVersion + SArray* meta; // element is SDbVgVersion or SSTableVersion } SCtgRentSlot; typedef struct SCtgRentMgmt { - int8_t type; - uint16_t slotNum; - uint16_t slotRIdx; - int64_t lastReadMsec; - SCtgRentSlot *slots; + int8_t type; + uint16_t slotNum; + uint16_t slotRIdx; + int64_t lastReadMsec; + SCtgRentSlot* slots; } SCtgRentMgmt; typedef struct SCtgUserAuth { int32_t version; SRWLatch lock; bool superUser; - SHashObj *createdDbs; - SHashObj *readDbs; - SHashObj *writeDbs; + SHashObj* createdDbs; + SHashObj* readDbs; + SHashObj* writeDbs; } SCtgUserAuth; typedef struct SCatalog { - uint64_t clusterId; - SHashObj *userCache; //key:user, value:SCtgUserAuth - SHashObj *dbCache; //key:dbname, value:SCtgDBCache - SCtgRentMgmt dbRent; - SCtgRentMgmt stbRent; + uint64_t clusterId; + SHashObj* userCache; // key:user, value:SCtgUserAuth + SHashObj* dbCache; // key:dbname, value:SCtgDBCache + SCtgRentMgmt dbRent; + SCtgRentMgmt stbRent; } SCatalog; typedef struct SCtgBatch { - int32_t batchId; - int32_t msgType; - int32_t msgSize; - SArray* pMsgs; + int32_t batchId; + int32_t msgType; + int32_t msgSize; + SArray* pMsgs; SRequestConnInfo conn; - char dbFName[TSDB_DB_FNAME_LEN]; - SArray* pTaskIds; - SArray* pMsgIdxs; + char dbFName[TSDB_DB_FNAME_LEN]; + SArray* pTaskIds; + SArray* pMsgIdxs; } SCtgBatch; typedef struct SCtgJob { - int64_t refId; - int32_t batchId; - SHashObj* pBatchs; - SArray* pTasks; - int32_t subTaskNum; - int32_t taskDone; - SMetaData jobRes; - int32_t jobResCode; - int32_t taskIdx; - SRWLatch taskLock; - - uint64_t queryId; - SCatalog* pCtg; - SRequestConnInfo conn; - void* userParam; - catalogCallback userFp; - int32_t tbMetaNum; - int32_t tbHashNum; - int32_t dbVgNum; - int32_t udfNum; - int32_t qnodeNum; - int32_t dnodeNum; - int32_t dbCfgNum; - int32_t indexNum; - int32_t userNum; - int32_t dbInfoNum; - int32_t tbIndexNum; - int32_t tbCfgNum; - int32_t svrVerNum; + int64_t refId; + int32_t batchId; + SHashObj* pBatchs; + SArray* pTasks; + int32_t subTaskNum; + int32_t taskDone; + SMetaData jobRes; + int32_t jobResCode; + int32_t taskIdx; + SRWLatch taskLock; + + uint64_t queryId; + SCatalog* pCtg; + SRequestConnInfo conn; + void* userParam; + catalogCallback userFp; + int32_t tbMetaNum; + int32_t tbHashNum; + int32_t dbVgNum; + int32_t udfNum; + int32_t qnodeNum; + int32_t dnodeNum; + int32_t dbCfgNum; + int32_t indexNum; + int32_t userNum; + int32_t dbInfoNum; + int32_t tbIndexNum; + int32_t tbCfgNum; + int32_t svrVerNum; } SCtgJob; typedef struct SCtgMsgCtx { - int32_t reqType; - void* lastOut; - void* out; - char* target; + int32_t reqType; + void* lastOut; + void* out; + char* target; SHashObj* pBatchs; } SCtgMsgCtx; - typedef struct SCtgTaskCallbackParam { - uint64_t queryId; - int64_t refId; - SArray* taskId; - int32_t reqType; - int32_t batchId; - SArray* msgIdx; + uint64_t queryId; + int64_t refId; + SArray* taskId; + int32_t reqType; + int32_t batchId; + SArray* msgIdx; } SCtgTaskCallbackParam; - typedef struct SCtgTask SCtgTask; typedef int32_t (*ctgSubTaskCbFp)(SCtgTask*); @@ -325,7 +321,7 @@ typedef struct SCtgTaskReq { typedef int32_t (*ctgInitTaskFp)(SCtgJob*, int32_t, void*); typedef int32_t (*ctgLanchTaskFp)(SCtgTask*); -typedef int32_t (*ctgHandleTaskMsgRspFp)(SCtgTaskReq*, int32_t, const SDataBuf *, int32_t); +typedef int32_t (*ctgHandleTaskMsgRspFp)(SCtgTaskReq*, int32_t, const SDataBuf*, int32_t); typedef int32_t (*ctgDumpTaskResFp)(SCtgTask*); typedef int32_t (*ctgCloneTaskResFp)(SCtgTask*, void**); typedef int32_t (*ctgCompTaskFp)(SCtgTask*, void*, bool*); @@ -340,7 +336,6 @@ typedef struct SCtgAsyncFps { } SCtgAsyncFps; typedef struct SCtgApiStat { - #if defined(WINDOWS) || defined(_TD_DARWIN_64) size_t avoidCompilationErrors; #endif @@ -371,9 +366,9 @@ typedef struct SCtgCacheStat { } SCtgCacheStat; typedef struct SCatalogStat { - SCtgApiStat api; - SCtgRuntimeStat runtime; - SCtgCacheStat cache; + SCtgApiStat api; + SCtgRuntimeStat runtime; + SCtgCacheStat cache; } SCatalogStat; typedef struct SCtgUpdateMsgHeader { @@ -381,9 +376,9 @@ typedef struct SCtgUpdateMsgHeader { } SCtgUpdateMsgHeader; typedef struct SCtgUpdateVgMsg { - SCatalog* pCtg; - char dbFName[TSDB_DB_FNAME_LEN]; - uint64_t dbId; + SCatalog* pCtg; + char dbFName[TSDB_DB_FNAME_LEN]; + uint64_t dbId; SDBVgInfo* dbInfo; } SCtgUpdateVgMsg; @@ -394,33 +389,32 @@ typedef struct SCtgUpdateTbMetaMsg { typedef struct SCtgDropDBMsg { SCatalog* pCtg; - char dbFName[TSDB_DB_FNAME_LEN]; - uint64_t dbId; + char dbFName[TSDB_DB_FNAME_LEN]; + uint64_t dbId; } SCtgDropDBMsg; typedef struct SCtgDropDbVgroupMsg { SCatalog* pCtg; - char dbFName[TSDB_DB_FNAME_LEN]; + char dbFName[TSDB_DB_FNAME_LEN]; } SCtgDropDbVgroupMsg; - typedef struct SCtgDropStbMetaMsg { SCatalog* pCtg; - char dbFName[TSDB_DB_FNAME_LEN]; - char stbName[TSDB_TABLE_NAME_LEN]; - uint64_t dbId; - uint64_t suid; + char dbFName[TSDB_DB_FNAME_LEN]; + char stbName[TSDB_TABLE_NAME_LEN]; + uint64_t dbId; + uint64_t suid; } SCtgDropStbMetaMsg; typedef struct SCtgDropTblMetaMsg { SCatalog* pCtg; - char dbFName[TSDB_DB_FNAME_LEN]; - char tbName[TSDB_TABLE_NAME_LEN]; - uint64_t dbId; + char dbFName[TSDB_DB_FNAME_LEN]; + char tbName[TSDB_TABLE_NAME_LEN]; + uint64_t dbId; } SCtgDropTblMetaMsg; typedef struct SCtgUpdateUserMsg { - SCatalog* pCtg; + SCatalog* pCtg; SGetUserAuthRsp userAuth; } SCtgUpdateUserMsg; @@ -430,63 +424,63 @@ typedef struct SCtgUpdateTbIndexMsg { } SCtgUpdateTbIndexMsg; typedef struct SCtgDropTbIndexMsg { - SCatalog* pCtg; - char dbFName[TSDB_DB_FNAME_LEN]; - char tbName[TSDB_TABLE_NAME_LEN]; + SCatalog* pCtg; + char dbFName[TSDB_DB_FNAME_LEN]; + char tbName[TSDB_TABLE_NAME_LEN]; } SCtgDropTbIndexMsg; typedef struct SCtgClearCacheMsg { - SCatalog* pCtg; - bool freeCtg; + SCatalog* pCtg; + bool freeCtg; } SCtgClearCacheMsg; typedef struct SCtgUpdateEpsetMsg { SCatalog* pCtg; - char dbFName[TSDB_DB_FNAME_LEN]; - int32_t vgId; - SEpSet epSet; + char dbFName[TSDB_DB_FNAME_LEN]; + int32_t vgId; + SEpSet epSet; } SCtgUpdateEpsetMsg; typedef struct SCtgCacheOperation { - int32_t opId; - void *data; - bool syncOp; - tsem_t rspSem; - bool stopQueue; - bool unLocked; + int32_t opId; + void* data; + bool syncOp; + tsem_t rspSem; + bool stopQueue; + bool unLocked; } SCtgCacheOperation; typedef struct SCtgQNode { - SCtgCacheOperation *op; - struct SCtgQNode *next; + SCtgCacheOperation* op; + struct SCtgQNode* next; } SCtgQNode; typedef struct SCtgQueue { - SRWLatch qlock; - bool stopQueue; - SCtgQNode *head; - SCtgQNode *tail; - tsem_t reqSem; - uint64_t qRemainNum; + SRWLatch qlock; + bool stopQueue; + SCtgQNode* head; + SCtgQNode* tail; + tsem_t reqSem; + uint64_t qRemainNum; } SCtgQueue; typedef struct SCatalogMgmt { - bool exit; - int32_t jobPool; - SRWLatch lock; - SCtgQueue queue; - TdThread updateThread; - SHashObj *pCluster; //key: clusterId, value: SCatalog* - SCatalogStat stat; - SCatalogCfg cfg; + bool exit; + int32_t jobPool; + SRWLatch lock; + SCtgQueue queue; + TdThread updateThread; + SHashObj* pCluster; // key: clusterId, value: SCatalog* + SCatalogStat stat; + SCatalogCfg cfg; } SCatalogMgmt; -typedef uint32_t (*tableNameHashFp)(const char *, uint32_t); -typedef int32_t (*ctgOpFunc)(SCtgCacheOperation *); +typedef uint32_t (*tableNameHashFp)(const char*, uint32_t); +typedef int32_t (*ctgOpFunc)(SCtgCacheOperation*); typedef struct SCtgOperation { - int32_t opId; - char name[32]; + int32_t opId; + char name[32]; ctgOpFunc func; } SCtgOperation; @@ -495,16 +489,16 @@ typedef struct SCtgOperation { #define CTG_STAT_INC(_item, _n) atomic_add_fetch_64(&(_item), _n) #define CTG_STAT_DEC(_item, _n) atomic_sub_fetch_64(&(_item), _n) -#define CTG_STAT_GET(_item) atomic_load_64(&(_item)) +#define CTG_STAT_GET(_item) atomic_load_64(&(_item)) -#define CTG_RT_STAT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.stat.runtime.item, n)) +#define CTG_RT_STAT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.stat.runtime.item, n)) #define CTG_CACHE_STAT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.stat.cache.item, n)) #define CTG_CACHE_STAT_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.stat.cache.item, n)) -#define CTG_IS_META_NULL(type) ((type) == META_TYPE_NULL_TABLE) +#define CTG_IS_META_NULL(type) ((type) == META_TYPE_NULL_TABLE) #define CTG_IS_META_CTABLE(type) ((type) == META_TYPE_CTABLE) -#define CTG_IS_META_TABLE(type) ((type) == META_TYPE_TABLE) -#define CTG_IS_META_BOTH(type) ((type) == META_TYPE_BOTH_TABLE) +#define CTG_IS_META_TABLE(type) ((type) == META_TYPE_TABLE) +#define CTG_IS_META_BOTH(type) ((type) == META_TYPE_BOTH_TABLE) #define CTG_FLAG_STB 0x1 #define CTG_FLAG_NOT_STB 0x2 @@ -514,199 +508,263 @@ typedef struct SCtgOperation { #define CTG_FLAG_SET(_flag, _v) ((_flag) |= (_v)) -#define CTG_FLAG_IS_STB(_flag) ((_flag) & CTG_FLAG_STB) -#define CTG_FLAG_IS_NOT_STB(_flag) ((_flag) & CTG_FLAG_NOT_STB) -#define CTG_FLAG_IS_UNKNOWN_STB(_flag) ((_flag) & CTG_FLAG_UNKNOWN_STB) -#define CTG_FLAG_IS_SYS_DB(_flag) ((_flag) & CTG_FLAG_SYS_DB) -#define CTG_FLAG_IS_FORCE_UPDATE(_flag) ((_flag) & CTG_FLAG_FORCE_UPDATE) -#define CTG_FLAG_SET_SYS_DB(_flag) ((_flag) |= CTG_FLAG_SYS_DB) -#define CTG_FLAG_SET_STB(_flag, tbType) do { (_flag) |= ((tbType) == TSDB_SUPER_TABLE) ? CTG_FLAG_STB : ((tbType) > TSDB_SUPER_TABLE ? CTG_FLAG_NOT_STB : CTG_FLAG_UNKNOWN_STB); } while (0) -#define CTG_FLAG_MAKE_STB(_isStb) (((_isStb) == 1) ? CTG_FLAG_STB : ((_isStb) == 0 ? CTG_FLAG_NOT_STB : CTG_FLAG_UNKNOWN_STB)) -#define CTG_FLAG_MATCH_STB(_flag, tbType) (CTG_FLAG_IS_UNKNOWN_STB(_flag) || (CTG_FLAG_IS_STB(_flag) && (tbType) == TSDB_SUPER_TABLE) || (CTG_FLAG_IS_NOT_STB(_flag) && (tbType) != TSDB_SUPER_TABLE)) +#define CTG_FLAG_IS_STB(_flag) ((_flag)&CTG_FLAG_STB) +#define CTG_FLAG_IS_NOT_STB(_flag) ((_flag)&CTG_FLAG_NOT_STB) +#define CTG_FLAG_IS_UNKNOWN_STB(_flag) ((_flag)&CTG_FLAG_UNKNOWN_STB) +#define CTG_FLAG_IS_SYS_DB(_flag) ((_flag)&CTG_FLAG_SYS_DB) +#define CTG_FLAG_IS_FORCE_UPDATE(_flag) ((_flag)&CTG_FLAG_FORCE_UPDATE) +#define CTG_FLAG_SET_SYS_DB(_flag) ((_flag) |= CTG_FLAG_SYS_DB) +#define CTG_FLAG_SET_STB(_flag, tbType) \ + do { \ + (_flag) |= ((tbType) == TSDB_SUPER_TABLE) \ + ? CTG_FLAG_STB \ + : ((tbType) > TSDB_SUPER_TABLE ? CTG_FLAG_NOT_STB : CTG_FLAG_UNKNOWN_STB); \ + } while (0) +#define CTG_FLAG_MAKE_STB(_isStb) \ + (((_isStb) == 1) ? CTG_FLAG_STB : ((_isStb) == 0 ? CTG_FLAG_NOT_STB : CTG_FLAG_UNKNOWN_STB)) +#define CTG_FLAG_MATCH_STB(_flag, tbType) \ + (CTG_FLAG_IS_UNKNOWN_STB(_flag) || (CTG_FLAG_IS_STB(_flag) && (tbType) == TSDB_SUPER_TABLE) || \ + (CTG_FLAG_IS_NOT_STB(_flag) && (tbType) != TSDB_SUPER_TABLE)) -#define CTG_GET_TASK_MSGCTX(_task, _id) (((CTG_TASK_GET_TB_META_BATCH == (_task)->type) || (CTG_TASK_GET_TB_HASH_BATCH == (_task)->type)) ? taosArrayGet((_task)->msgCtxs, (_id)) : &(_task)->msgCtx) +#define CTG_GET_TASK_MSGCTX(_task, _id) \ + (((CTG_TASK_GET_TB_META_BATCH == (_task)->type) || (CTG_TASK_GET_TB_HASH_BATCH == (_task)->type)) \ + ? taosArrayGet((_task)->msgCtxs, (_id)) \ + : &(_task)->msgCtx) -#define CTG_META_SIZE(pMeta) (sizeof(STableMeta) + ((pMeta)->tableInfo.numOfTags + (pMeta)->tableInfo.numOfColumns) * sizeof(SSchema)) +#define CTG_META_SIZE(pMeta) \ + (sizeof(STableMeta) + ((pMeta)->tableInfo.numOfTags + (pMeta)->tableInfo.numOfColumns) * sizeof(SSchema)) #define CTG_TABLE_NOT_EXIST(code) (code == CTG_ERR_CODE_TABLE_NOT_EXIST) -#define CTG_DB_NOT_EXIST(code) (code == TSDB_CODE_MND_DB_NOT_EXIST) +#define CTG_DB_NOT_EXIST(code) (code == TSDB_CODE_MND_DB_NOT_EXIST) + +#define ctgFatal(param, ...) qFatal("CTG:%p " param, pCtg, __VA_ARGS__) +#define ctgError(param, ...) qError("CTG:%p " param, pCtg, __VA_ARGS__) +#define ctgWarn(param, ...) qWarn("CTG:%p " param, pCtg, __VA_ARGS__) +#define ctgInfo(param, ...) qInfo("CTG:%p " param, pCtg, __VA_ARGS__) +#define ctgDebug(param, ...) qDebug("CTG:%p " param, pCtg, __VA_ARGS__) +#define ctgTrace(param, ...) qTrace("CTG:%p " param, pCtg, __VA_ARGS__) + +#define CTG_LOCK_DEBUG(...) \ + do { \ + if (gCTGDebug.lockEnable) { \ + qDebug(__VA_ARGS__); \ + } \ + } while (0) +#define CTG_CACHE_DEBUG(...) \ + do { \ + if (gCTGDebug.cacheEnable) { \ + qDebug(__VA_ARGS__); \ + } \ + } while (0) +#define CTG_API_DEBUG(...) \ + do { \ + if (gCTGDebug.apiEnable) { \ + qDebug(__VA_ARGS__); \ + } \ + } while (0) -#define ctgFatal(param, ...) qFatal("CTG:%p " param, pCtg, __VA_ARGS__) -#define ctgError(param, ...) qError("CTG:%p " param, pCtg, __VA_ARGS__) -#define ctgWarn(param, ...) qWarn("CTG:%p " param, pCtg, __VA_ARGS__) -#define ctgInfo(param, ...) qInfo("CTG:%p " param, pCtg, __VA_ARGS__) -#define ctgDebug(param, ...) qDebug("CTG:%p " param, pCtg, __VA_ARGS__) -#define ctgTrace(param, ...) qTrace("CTG:%p " param, pCtg, __VA_ARGS__) +#define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000 -#define CTG_LOCK_DEBUG(...) do { if (gCTGDebug.lockEnable) { qDebug(__VA_ARGS__); } } while (0) -#define CTG_CACHE_DEBUG(...) do { if (gCTGDebug.cacheEnable) { qDebug(__VA_ARGS__); } } while (0) -#define CTG_API_DEBUG(...) do { if (gCTGDebug.apiEnable) { qDebug(__VA_ARGS__); } } while (0) +#define CTG_LOCK(type, _lock) \ + do { \ + if (CTG_READ == (type)) { \ + assert(atomic_load_32((_lock)) >= 0); \ + CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosRLockLatch(_lock); \ + CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) > 0); \ + } else { \ + assert(atomic_load_32((_lock)) >= 0); \ + CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosWLockLatch(_lock); \ + CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ + } \ + } while (0) -#define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000 +#define CTG_UNLOCK(type, _lock) \ + do { \ + if (CTG_READ == (type)) { \ + assert(atomic_load_32((_lock)) > 0); \ + CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosRUnLockLatch(_lock); \ + CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) >= 0); \ + } else { \ + assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ + CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosWUnLockLatch(_lock); \ + CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) >= 0); \ + } \ + } while (0) -#define CTG_LOCK(type, _lock) do { \ - if (CTG_READ == (type)) { \ - assert(atomic_load_32((_lock)) >= 0); \ - CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - taosRLockLatch(_lock); \ - CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) > 0); \ - } else { \ - assert(atomic_load_32((_lock)) >= 0); \ - CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - taosWLockLatch(_lock); \ - CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ - } \ -} while (0) - -#define CTG_UNLOCK(type, _lock) do { \ - if (CTG_READ == (type)) { \ - assert(atomic_load_32((_lock)) > 0); \ - CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - taosRUnLockLatch(_lock); \ - CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) >= 0); \ - } else { \ - assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \ - CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - taosWUnLockLatch(_lock); \ - CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) >= 0); \ - } \ -} while (0) - - -#define CTG_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) -#define CTG_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) -#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) - -#define CTG_API_LEAVE(c) do { \ - int32_t __code = c; \ - CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock); \ - CTG_API_DEBUG("CTG API leave %s", __FUNCTION__); \ - CTG_RET(__code); \ -} while (0) - -#define CTG_API_ENTER() do { \ - CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); \ - CTG_LOCK(CTG_READ, &gCtgMgmt.lock); \ - if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { \ - CTG_API_LEAVE(TSDB_CODE_CTG_OUT_OF_SERVICE); \ - } \ -} while (0) - -#define CTG_API_JENTER() do { \ - CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); \ - CTG_LOCK(CTG_READ, &gCtgMgmt.lock); \ - if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { \ - CTG_ERR_JRET(TSDB_CODE_CTG_OUT_OF_SERVICE); \ - } \ -} while (0) - - -#define CTG_API_LEAVE_NOLOCK(c) do { \ - int32_t __code = c; \ - CTG_API_DEBUG("CTG API leave %s", __FUNCTION__); \ - CTG_RET(__code); \ +#define CTG_ERR_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + return _code; \ + } \ + } while (0) +#define CTG_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + } \ + return _code; \ + } while (0) +#define CTG_ERR_JRET(c) \ + do { \ + code = c; \ + if (code != TSDB_CODE_SUCCESS) { \ + terrno = code; \ + goto _return; \ + } \ } while (0) -#define CTG_API_ENTER_NOLOCK() do { \ - CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); \ - if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { \ - CTG_API_LEAVE_NOLOCK(TSDB_CODE_CTG_OUT_OF_SERVICE); \ - } \ -} while (0) +#define CTG_API_LEAVE(c) \ + do { \ + int32_t __code = c; \ + CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock); \ + CTG_API_DEBUG("CTG API leave %s", __FUNCTION__); \ + CTG_RET(__code); \ + } while (0) +#define CTG_API_ENTER() \ + do { \ + CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); \ + CTG_LOCK(CTG_READ, &gCtgMgmt.lock); \ + if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { \ + CTG_API_LEAVE(TSDB_CODE_CTG_OUT_OF_SERVICE); \ + } \ + } while (0) + +#define CTG_API_JENTER() \ + do { \ + CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); \ + CTG_LOCK(CTG_READ, &gCtgMgmt.lock); \ + if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { \ + CTG_ERR_JRET(TSDB_CODE_CTG_OUT_OF_SERVICE); \ + } \ + } while (0) -void ctgdShowTableMeta(SCatalog* pCtg, const char *tbName, STableMeta* p); +#define CTG_API_LEAVE_NOLOCK(c) \ + do { \ + int32_t __code = c; \ + CTG_API_DEBUG("CTG API leave %s", __FUNCTION__); \ + CTG_RET(__code); \ + } while (0) + +#define CTG_API_ENTER_NOLOCK() \ + do { \ + CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); \ + if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { \ + CTG_API_LEAVE_NOLOCK(TSDB_CODE_CTG_OUT_OF_SERVICE); \ + } \ + } while (0) + +void ctgdShowTableMeta(SCatalog* pCtg, const char* tbName, STableMeta* p); void ctgdShowClusterCache(SCatalog* pCtg); int32_t ctgdShowCacheInfo(void); int32_t ctgRemoveTbMetaFromCache(SCatalog* pCtg, SName* pTableName, bool syncReq); -int32_t ctgGetTbMetaFromCache(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta); -int32_t ctgGetTbMetasFromCache(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgTbMetasCtx* ctx, int32_t dbIdx, int32_t *fetchIdx, int32_t baseResIdx, SArray* pList); - -int32_t ctgOpUpdateVgroup(SCtgCacheOperation *action); -int32_t ctgOpUpdateTbMeta(SCtgCacheOperation *action); -int32_t ctgOpDropDbCache(SCtgCacheOperation *action); -int32_t ctgOpDropDbVgroup(SCtgCacheOperation *action); -int32_t ctgOpDropStbMeta(SCtgCacheOperation *action); -int32_t ctgOpDropTbMeta(SCtgCacheOperation *action); -int32_t ctgOpUpdateUser(SCtgCacheOperation *action); -int32_t ctgOpUpdateEpset(SCtgCacheOperation *operation); -int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char *dbFName, SCtgDBCache **pCache); -void ctgReleaseDBCache(SCatalog *pCtg, SCtgDBCache *dbCache); -void ctgRUnlockVgInfo(SCtgDBCache *dbCache); -int32_t ctgTbMetaExistInCache(SCatalog* pCtg, char *dbFName, char* tbName, int32_t *exist); +int32_t ctgGetTbMetaFromCache(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta); +int32_t ctgGetTbMetasFromCache(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetasCtx* ctx, int32_t dbIdx, + int32_t* fetchIdx, int32_t baseResIdx, SArray* pList); + +int32_t ctgOpUpdateVgroup(SCtgCacheOperation* action); +int32_t ctgOpUpdateTbMeta(SCtgCacheOperation* action); +int32_t ctgOpDropDbCache(SCtgCacheOperation* action); +int32_t ctgOpDropDbVgroup(SCtgCacheOperation* action); +int32_t ctgOpDropStbMeta(SCtgCacheOperation* action); +int32_t ctgOpDropTbMeta(SCtgCacheOperation* action); +int32_t ctgOpUpdateUser(SCtgCacheOperation* action); +int32_t ctgOpUpdateEpset(SCtgCacheOperation* operation); +int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char* dbFName, SCtgDBCache** pCache); +void ctgReleaseDBCache(SCatalog* pCtg, SCtgDBCache* dbCache); +void ctgRUnlockVgInfo(SCtgDBCache* dbCache); +int32_t ctgTbMetaExistInCache(SCatalog* pCtg, char* dbFName, char* tbName, int32_t* exist); int32_t ctgReadTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta); -int32_t ctgReadTbVerFromCache(SCatalog *pCtg, SName *pTableName, int32_t *sver, int32_t *tver, int32_t *tbType, uint64_t *suid, char *stbName); -int32_t ctgChkAuthFromCache(SCatalog* pCtg, char* user, char* dbFName, AUTH_TYPE type, bool *inCache, bool *pass); -int32_t ctgDropDbCacheEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId); -int32_t ctgDropDbVgroupEnqueue(SCatalog* pCtg, const char *dbFName, bool syncReq); -int32_t ctgDropStbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *stbName, uint64_t suid, bool syncReq); -int32_t ctgDropTbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *tbName, bool syncReq); -int32_t ctgUpdateVgroupEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, SDBVgInfo* dbInfo, bool syncReq); -int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool syncReq); -int32_t ctgUpdateUserEnqueue(SCatalog* pCtg, SGetUserAuthRsp *pAuth, bool syncReq); -int32_t ctgUpdateVgEpsetEnqueue(SCatalog* pCtg, char *dbFName, int32_t vgId, SEpSet* pEpSet); -int32_t ctgUpdateTbIndexEnqueue(SCatalog* pCtg, STableIndex **pIndex, bool syncOp); +int32_t ctgReadTbVerFromCache(SCatalog* pCtg, SName* pTableName, int32_t* sver, int32_t* tver, int32_t* tbType, + uint64_t* suid, char* stbName); +int32_t ctgChkAuthFromCache(SCatalog* pCtg, char* user, char* dbFName, AUTH_TYPE type, bool* inCache, bool* pass); +int32_t ctgDropDbCacheEnqueue(SCatalog* pCtg, const char* dbFName, int64_t dbId); +int32_t ctgDropDbVgroupEnqueue(SCatalog* pCtg, const char* dbFName, bool syncReq); +int32_t ctgDropStbMetaEnqueue(SCatalog* pCtg, const char* dbFName, int64_t dbId, const char* stbName, uint64_t suid, + bool syncReq); +int32_t ctgDropTbMetaEnqueue(SCatalog* pCtg, const char* dbFName, int64_t dbId, const char* tbName, bool syncReq); +int32_t ctgUpdateVgroupEnqueue(SCatalog* pCtg, const char* dbFName, int64_t dbId, SDBVgInfo* dbInfo, bool syncReq); +int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput* output, bool syncReq); +int32_t ctgUpdateUserEnqueue(SCatalog* pCtg, SGetUserAuthRsp* pAuth, bool syncReq); +int32_t ctgUpdateVgEpsetEnqueue(SCatalog* pCtg, char* dbFName, int32_t vgId, SEpSet* pEpSet); +int32_t ctgUpdateTbIndexEnqueue(SCatalog* pCtg, STableIndex** pIndex, bool syncOp); int32_t ctgClearCacheEnqueue(SCatalog* pCtg, bool freeCtg, bool stopQueue, bool syncOp); -int32_t ctgMetaRentInit(SCtgRentMgmt *mgmt, uint32_t rentSec, int8_t type); -int32_t ctgMetaRentAdd(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size); -int32_t ctgMetaRentGet(SCtgRentMgmt *mgmt, void **res, uint32_t *num, int32_t size); +int32_t ctgMetaRentInit(SCtgRentMgmt* mgmt, uint32_t rentSec, int8_t type); +int32_t ctgMetaRentAdd(SCtgRentMgmt* mgmt, void* meta, int64_t id, int32_t size); +int32_t ctgMetaRentGet(SCtgRentMgmt* mgmt, void** res, uint32_t* num, int32_t size); int32_t ctgUpdateTbMetaToCache(SCatalog* pCtg, STableMetaOutput* pOut, bool syncReq); int32_t ctgStartUpdateThread(); -int32_t ctgRelaunchGetTbMetaTask(SCtgTask *pTask); -void ctgReleaseVgInfoToCache(SCatalog* pCtg, SCtgDBCache *dbCache); +int32_t ctgRelaunchGetTbMetaTask(SCtgTask* pTask); +void ctgReleaseVgInfoToCache(SCatalog* pCtg, SCtgDBCache* dbCache); int32_t ctgReadTbIndexFromCache(SCatalog* pCtg, SName* pTableName, SArray** pRes); int32_t ctgDropTbIndexEnqueue(SCatalog* pCtg, SName* pName, bool syncOp); -int32_t ctgOpDropTbIndex(SCtgCacheOperation *operation); -int32_t ctgOpUpdateTbIndex(SCtgCacheOperation *operation); -int32_t ctgOpClearCache(SCtgCacheOperation *operation); -int32_t ctgReadTbTypeFromCache(SCatalog* pCtg, char* dbFName, char *tableName, int32_t *tbType); -int32_t ctgGetTbHashVgroupFromCache(SCatalog *pCtg, const SName *pTableName, SVgroupInfo **pVgroup); - - - +int32_t ctgOpDropTbIndex(SCtgCacheOperation* operation); +int32_t ctgOpUpdateTbIndex(SCtgCacheOperation* operation); +int32_t ctgOpClearCache(SCtgCacheOperation* operation); +int32_t ctgReadTbTypeFromCache(SCatalog* pCtg, char* dbFName, char* tableName, int32_t* tbType); +int32_t ctgGetTbHashVgroupFromCache(SCatalog* pCtg, const SName* pTableName, SVgroupInfo** pVgroup); int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize, int32_t rspCode, char* target); -int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SBuildUseDBInput *input, SUseDbOutput *out, SCtgTaskReq* tReq); -int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray *out, SCtgTask* pTask); -int32_t ctgGetDnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray **out, SCtgTask* pTask); -int32_t ctgGetDBCfgFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const char *dbFName, SDbCfgInfo *out, SCtgTask* pTask); -int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const char *indexName, SIndexInfo *out, SCtgTask* pTask); -int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SName *name, STableIndex* out, SCtgTask* pTask); -int32_t ctgGetUdfInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const char *funcName, SFuncInfo *out, SCtgTask* pTask); -int32_t ctgGetUserDbAuthFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const char *user, SGetUserAuthRsp *out, SCtgTask* pTask); -int32_t ctgGetTbMetaFromMnodeImpl(SCatalog* pCtg, SRequestConnInfo *pConn, char *dbFName, char* tbName, STableMetaOutput* out, SCtgTaskReq* tReq); -int32_t ctgGetTbMetaFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, STableMetaOutput* out, SCtgTaskReq* tReq); -int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* out, SCtgTaskReq* tReq); -int32_t ctgGetTableCfgFromVnode(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, SVgroupInfo *vgroupInfo, STableCfg **out, SCtgTask* pTask); -int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, STableCfg **out, SCtgTask* pTask); -int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, char **out, SCtgTask* pTask); -int32_t ctgLaunchBatchs(SCatalog* pCtg, SCtgJob *pJob, SHashObj* pBatchs); - -int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, const SCatalogReq* pReq, catalogCallback fp, void* param); -int32_t ctgLaunchJob(SCtgJob *pJob); -int32_t ctgMakeAsyncRes(SCtgJob *pJob); -int32_t ctgLaunchSubTask(SCtgTask *pTask, CTG_TASK_TYPE type, ctgSubTaskCbFp fp, void* param); -int32_t ctgGetTbCfgCb(SCtgTask *pTask); +int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SBuildUseDBInput* input, SUseDbOutput* out, + SCtgTaskReq* tReq); +int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray* out, SCtgTask* pTask); +int32_t ctgGetDnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray** out, SCtgTask* pTask); +int32_t ctgGetDBCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SDbCfgInfo* out, + SCtgTask* pTask); +int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char* indexName, SIndexInfo* out, + SCtgTask* pTask); +int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* name, STableIndex* out, SCtgTask* pTask); +int32_t ctgGetUdfInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char* funcName, SFuncInfo* out, + SCtgTask* pTask); +int32_t ctgGetUserDbAuthFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, SGetUserAuthRsp* out, + SCtgTask* pTask); +int32_t ctgGetTbMetaFromMnodeImpl(SCatalog* pCtg, SRequestConnInfo* pConn, char* dbFName, char* tbName, + STableMetaOutput* out, SCtgTaskReq* tReq); +int32_t ctgGetTbMetaFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableMetaOutput* out, + SCtgTaskReq* tReq); +int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* vgroupInfo, + STableMetaOutput* out, SCtgTaskReq* tReq); +int32_t ctgGetTableCfgFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, + SVgroupInfo* vgroupInfo, STableCfg** out, SCtgTask* pTask); +int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableCfg** out, + SCtgTask* pTask); +int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, char** out, SCtgTask* pTask); +int32_t ctgLaunchBatchs(SCatalog* pCtg, SCtgJob* pJob, SHashObj* pBatchs); + +int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const SCatalogReq* pReq, catalogCallback fp, + void* param); +int32_t ctgLaunchJob(SCtgJob* pJob); +int32_t ctgMakeAsyncRes(SCtgJob* pJob); +int32_t ctgLaunchSubTask(SCtgTask* pTask, CTG_TASK_TYPE type, ctgSubTaskCbFp fp, void* param); +int32_t ctgGetTbCfgCb(SCtgTask* pTask); void ctgFreeHandle(SCatalog* pCatalog); void ctgFreeMsgSendParam(void* param); -void ctgFreeBatch(SCtgBatch *pBatch); -void ctgFreeBatchs(SHashObj *pBatchs); -int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst); -int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput); -int32_t ctgGenerateVgList(SCatalog *pCtg, SHashObj *vgHash, SArray** pList); +void ctgFreeBatch(SCtgBatch* pBatch); +void ctgFreeBatchs(SHashObj* pBatchs); +int32_t ctgCloneVgInfo(SDBVgInfo* src, SDBVgInfo** dst); +int32_t ctgCloneMetaOutput(STableMetaOutput* output, STableMetaOutput** pOutput); +int32_t ctgGenerateVgList(SCatalog* pCtg, SHashObj* vgHash, SArray** pList); void ctgFreeJob(void* job); void ctgFreeHandleImpl(SCatalog* pCtg); -void ctgFreeVgInfo(SDBVgInfo *vgInfo); -int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName *pTableName, SVgroupInfo *pVgroup); -int32_t ctgGetVgInfosFromHashValue(SCatalog *pCtg, SCtgTaskReq* tReq, SDBVgInfo *dbInfo, SCtgTbHashsCtx *pCtx, char* dbFName, SArray* pNames, bool update); +void ctgFreeVgInfo(SDBVgInfo* vgInfo); +int32_t ctgGetVgInfoFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, const SName* pTableName, SVgroupInfo* pVgroup); +int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SCtgTaskReq* tReq, SDBVgInfo* dbInfo, SCtgTbHashsCtx* pCtx, + char* dbFName, SArray* pNames, bool update); void ctgResetTbMetaTask(SCtgTask* pTask); -void ctgFreeDbCache(SCtgDBCache *dbCache); +void ctgFreeDbCache(SCtgDBCache* dbCache); int32_t ctgStbVersionSortCompare(const void* key1, const void* key2); int32_t ctgDbVgVersionSortCompare(const void* key1, const void* key2); int32_t ctgStbVersionSearchCompare(const void* key1, const void* key2); @@ -714,23 +772,22 @@ int32_t ctgDbVgVersionSearchCompare(const void* key1, const void* key2); void ctgFreeSTableMetaOutput(STableMetaOutput* pOutput); int32_t ctgUpdateMsgCtx(SCtgMsgCtx* pCtx, int32_t reqType, void* out, char* target); int32_t ctgAddMsgCtx(SArray* pCtxs, int32_t reqType, void* out, char* target); -char * ctgTaskTypeStr(CTG_TASK_TYPE type); -int32_t ctgUpdateSendTargetInfo(SMsgSendInfo *pMsgSendInfo, int32_t msgType, char* dbFName, int32_t vgId); -int32_t ctgGetTablesReqNum(SArray *pList); -int32_t ctgAddFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t *fetchIdx, int32_t resIdx, int32_t flag); +char* ctgTaskTypeStr(CTG_TASK_TYPE type); +int32_t ctgUpdateSendTargetInfo(SMsgSendInfo* pMsgSendInfo, int32_t msgType, char* dbFName, int32_t vgId); +int32_t ctgGetTablesReqNum(SArray* pList); +int32_t ctgAddFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t* fetchIdx, int32_t resIdx, int32_t flag); int32_t ctgCloneTableIndex(SArray* pIndex, SArray** pRes); -void ctgFreeSTableIndex(void *info); -void ctgClearSubTaskRes(SCtgSubRes *pRes); -void ctgFreeQNode(SCtgQNode *node); +void ctgFreeSTableIndex(void* info); +void ctgClearSubTaskRes(SCtgSubRes* pRes); +void ctgFreeQNode(SCtgQNode* node); void ctgClearHandle(SCatalog* pCtg); -void ctgFreeTbCacheImpl(SCtgTbCache *pCache); +void ctgFreeTbCacheImpl(SCtgTbCache* pCache); int32_t ctgRemoveTbMeta(SCatalog* pCtg, SName* pTableName); -int32_t ctgGetTbHashVgroup(SCatalog *pCtg, SRequestConnInfo *pConn, const SName *pTableName, SVgroupInfo *pVgroup); +int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup); SName* ctgGetFetchName(SArray* pNames, SCtgFetch* pFetch); - extern SCatalogMgmt gCtgMgmt; -extern SCtgDebug gCTGDebug; +extern SCtgDebug gCTGDebug; extern SCtgAsyncFps gCtgAsyncFps[]; #ifdef __cplusplus diff --git a/source/libs/catalog/inc/ctgRemote.h b/source/libs/catalog/inc/ctgRemote.h index fe0762a88af49d8ed8ee873f03b719b0bc169a79..8edd3b3880994c60d9dc8e1ce27c64e3f271a26f 100644 --- a/source/libs/catalog/inc/ctgRemote.h +++ b/source/libs/catalog/inc/ctgRemote.h @@ -20,8 +20,6 @@ extern "C" { #endif - - #ifdef __cplusplus } #endif diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 7b32eadcd415116f67db8526449c8a6759f45bcd..b027dbcfa5ac9a91a2656778810ae84ae0b72eeb 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -22,7 +22,8 @@ SCatalogMgmt gCtgMgmt = {0}; -int32_t ctgGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char* dbFName, SCtgDBCache** dbCache, SDBVgInfo **pInfo) { +int32_t ctgGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SCtgDBCache** dbCache, + SDBVgInfo** pInfo) { int32_t code = 0; CTG_ERR_RET(ctgAcquireVgInfoFromCache(pCtg, dbFName, dbCache)); @@ -53,8 +54,8 @@ _return: CTG_RET(code); } -int32_t ctgRefreshDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char* dbFName) { - int32_t code = 0; +int32_t ctgRefreshDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName) { + int32_t code = 0; SCtgDBCache* dbCache = NULL; CTG_ERR_RET(ctgAcquireVgInfoFromCache(pCtg, dbFName, &dbCache)); @@ -87,7 +88,8 @@ int32_t ctgRefreshDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char* return TSDB_CODE_SUCCESS; } -int32_t ctgRefreshTbMeta(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgTbMetaCtx* ctx, STableMetaOutput **pOutput, bool syncReq) { +int32_t ctgRefreshTbMeta(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetaCtx* ctx, STableMetaOutput** pOutput, + bool syncReq) { SVgroupInfo vgroupInfo = {0}; int32_t code = 0; @@ -105,7 +107,8 @@ int32_t ctgRefreshTbMeta(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgTbMetaCtx* if (CTG_FLAG_IS_SYS_DB(ctx->flag)) { ctgDebug("will refresh tbmeta, supposed in information_schema, tbName:%s", tNameGetTableName(ctx->pName)); - CTG_ERR_JRET(ctgGetTbMetaFromMnodeImpl(pCtg, pConn, (char *)ctx->pName->dbname, (char *)ctx->pName->tname, output, NULL)); + CTG_ERR_JRET( + ctgGetTbMetaFromMnodeImpl(pCtg, pConn, (char*)ctx->pName->dbname, (char*)ctx->pName->tname, output, NULL)); } else if (CTG_FLAG_IS_STB(ctx->flag)) { ctgDebug("will refresh tbmeta, supposed to be stb, tbName:%s", tNameGetTableName(ctx->pName)); @@ -126,7 +129,7 @@ int32_t ctgRefreshTbMeta(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgTbMetaCtx* ctgDebug("will continue to refresh tbmeta since got stb, tbName:%s", tNameGetTableName(ctx->pName)); taosMemoryFreeClear(output->tbMeta); - + CTG_ERR_JRET(ctgGetTbMetaFromMnodeImpl(pCtg, pConn, output->dbFName, output->tbName, output, NULL)); } else if (CTG_IS_META_BOTH(output->metaType)) { int32_t exist = 0; @@ -182,9 +185,9 @@ _return: CTG_RET(code); } -int32_t ctgGetTbMeta(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta) { - int32_t code = 0; - STableMetaOutput *output = NULL; +int32_t ctgGetTbMeta(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta) { + int32_t code = 0; + STableMetaOutput* output = NULL; CTG_ERR_RET(ctgGetTbMetaFromCache(pCtg, pConn, ctx, pTableMeta)); if (*pTableMeta) { @@ -299,12 +302,13 @@ _return: CTG_RET(code); } -int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo *pConn, const char* user, const char* dbFName, AUTH_TYPE type, bool *pass) { - bool inCache = false; +int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type, + bool* pass) { + bool inCache = false; int32_t code = 0; *pass = false; - + CTG_ERR_RET(ctgChkAuthFromCache(pCtg, (char*)user, (char*)dbFName, type, &inCache, pass)); if (inCache) { @@ -313,7 +317,7 @@ int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo *pConn, const char* user, co SGetUserAuthRsp authRsp = {0}; CTG_ERR_RET(ctgGetUserDbAuthFromMnode(pCtg, pConn, user, &authRsp, NULL)); - + if (authRsp.superAuth) { *pass = true; goto _return; @@ -337,7 +341,7 @@ _return: return TSDB_CODE_SUCCESS; } -int32_t ctgGetTbType(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTableName, int32_t *tbType) { +int32_t ctgGetTbType(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName, int32_t* tbType) { char dbFName[TSDB_DB_FNAME_LEN]; tNameGetFullDbName(pTableName, dbFName); CTG_ERR_RET(ctgReadTbTypeFromCache(pCtg, dbFName, pTableName->tname, tbType)); @@ -345,7 +349,7 @@ int32_t ctgGetTbType(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTableName, return TSDB_CODE_SUCCESS; } - STableMeta* pMeta = NULL; + STableMeta* pMeta = NULL; SCtgTbMetaCtx ctx = {0}; ctx.pName = (SName*)pTableName; ctx.flag = CTG_FLAG_UNKNOWN_STB; @@ -357,24 +361,24 @@ int32_t ctgGetTbType(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTableName, return TSDB_CODE_SUCCESS; } -int32_t ctgGetTbIndex(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTableName, SArray** pRes) { +int32_t ctgGetTbIndex(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName, SArray** pRes) { CTG_ERR_RET(ctgReadTbIndexFromCache(pCtg, pTableName, pRes)); if (*pRes) { return TSDB_CODE_SUCCESS; } - STableIndex *pIndex = taosMemoryCalloc(1, sizeof(STableIndex)); + STableIndex* pIndex = taosMemoryCalloc(1, sizeof(STableIndex)); if (NULL == pIndex) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - + int32_t code = ctgGetTbIndexFromMnode(pCtg, pConn, (SName*)pTableName, pIndex, NULL); if (TSDB_CODE_MND_DB_INDEX_NOT_EXIST == code) { code = 0; goto _return; } CTG_ERR_JRET(code); - + SArray* pInfo = NULL; CTG_ERR_JRET(ctgCloneTableIndex(pIndex->pIndex, &pInfo)); @@ -395,7 +399,7 @@ _return: CTG_RET(code); } -int32_t ctgGetTbCfg(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTableName, STableCfg** pCfg) { +int32_t ctgGetTbCfg(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName, STableCfg** pCfg) { int32_t tbType = 0; CTG_ERR_RET(ctgGetTbType(pCtg, pConn, pTableName, &tbType)); @@ -410,25 +414,25 @@ int32_t ctgGetTbCfg(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTableName, CTG_RET(TSDB_CODE_SUCCESS); } -int32_t ctgGetTbDistVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, SName* pTableName, SArray** pVgList) { - STableMeta *tbMeta = NULL; - int32_t code = 0; - SVgroupInfo vgroupInfo = {0}; - SCtgDBCache* dbCache = NULL; - SArray *vgList = NULL; - SDBVgInfo *vgInfo = NULL; +int32_t ctgGetTbDistVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName, SArray** pVgList) { + STableMeta* tbMeta = NULL; + int32_t code = 0; + SVgroupInfo vgroupInfo = {0}; + SCtgDBCache* dbCache = NULL; + SArray* vgList = NULL; + SDBVgInfo* vgInfo = NULL; SCtgTbMetaCtx ctx = {0}; ctx.pName = pTableName; ctx.flag = CTG_FLAG_UNKNOWN_STB; *pVgList = NULL; - + CTG_ERR_JRET(ctgGetTbMeta(pCtg, pConn, &ctx, &tbMeta)); char db[TSDB_DB_FNAME_LEN] = {0}; tNameGetFullDbName(pTableName, db); - SHashObj *vgHash = NULL; + SHashObj* vgHash = NULL; CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, db, &dbCache, &vgInfo)); if (dbCache) { @@ -489,8 +493,7 @@ _return: CTG_RET(code); } - -int32_t ctgGetTbHashVgroup(SCatalog *pCtg, SRequestConnInfo *pConn, const SName *pTableName, SVgroupInfo *pVgroup) { +int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup) { if (IS_SYS_DBNAME(pTableName->dbname)) { ctgError("no valid vgInfo for db, dbname:%s", pTableName->dbname); CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); @@ -501,7 +504,7 @@ int32_t ctgGetTbHashVgroup(SCatalog *pCtg, SRequestConnInfo *pConn, const SName char db[TSDB_DB_FNAME_LEN] = {0}; tNameGetFullDbName(pTableName, db); - SDBVgInfo *vgInfo = NULL; + SDBVgInfo* vgInfo = NULL; CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, db, &dbCache, &vgInfo)); CTG_ERR_JRET(ctgGetVgInfoFromHashValue(pCtg, vgInfo ? vgInfo : dbCache->vgCache.vgInfo, pTableName, pVgroup)); @@ -539,7 +542,6 @@ _return: CTG_RET(code); } - int32_t catalogInit(SCatalogCfg* cfg) { if (gCtgMgmt.pCluster) { qError("catalog already initialized"); @@ -648,7 +650,8 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle) { CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); } - clusterCtg->userCache = taosHashInit(gCtgMgmt.cfg.maxUserCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); + clusterCtg->userCache = taosHashInit(gCtgMgmt.cfg.maxUserCacheNum, + taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (NULL == clusterCtg->userCache) { qError("taosHashInit %d user cache failed", gCtgMgmt.cfg.maxUserCacheNum); CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); @@ -714,7 +717,7 @@ _return: CTG_API_LEAVE(code); } -int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char* dbFName, SArray** vgroupList) { +int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SArray** vgroupList) { CTG_API_ENTER(); if (NULL == pCtg || NULL == dbFName || NULL == pConn || NULL == vgroupList) { @@ -722,10 +725,10 @@ int32_t catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char* } SCtgDBCache* dbCache = NULL; - int32_t code = 0; - SArray *vgList = NULL; - SHashObj *vgHash = NULL; - SDBVgInfo *vgInfo = NULL; + int32_t code = 0; + SArray* vgList = NULL; + SHashObj* vgHash = NULL; + SDBVgInfo* vgInfo = NULL; CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, dbFName, &dbCache, &vgInfo)); if (dbCache) { vgHash = dbCache->vgCache.vgInfo->vgHash; @@ -808,11 +811,11 @@ _return: CTG_API_LEAVE(code); } -int32_t catalogUpdateTableIndex(SCatalog* pCtg, STableIndexRsp *pRsp) { +int32_t catalogUpdateTableIndex(SCatalog* pCtg, STableIndexRsp* pRsp) { CTG_API_ENTER(); int32_t code = 0; - + if (NULL == pCtg || NULL == pRsp) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } @@ -827,11 +830,10 @@ int32_t catalogUpdateTableIndex(SCatalog* pCtg, STableIndexRsp *pRsp) { CTG_ERR_JRET(ctgUpdateTbIndexEnqueue(pCtg, &pIndex, false)); _return: - + CTG_API_LEAVE(code); } - int32_t catalogRemoveTableMeta(SCatalog* pCtg, SName* pTableName) { CTG_API_ENTER(); @@ -860,17 +862,18 @@ _return: CTG_API_LEAVE(code); } -int32_t catalogGetTableMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, STableMeta** pTableMeta) { +int32_t catalogGetTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableMeta** pTableMeta) { CTG_API_ENTER(); SCtgTbMetaCtx ctx = {0}; ctx.pName = (SName*)pTableName; ctx.flag = CTG_FLAG_UNKNOWN_STB; - + CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta)); } -int32_t catalogGetSTableMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, STableMeta** pTableMeta) { +int32_t catalogGetSTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, + STableMeta** pTableMeta) { CTG_API_ENTER(); SCtgTbMetaCtx ctx = {0}; @@ -895,7 +898,7 @@ _return: CTG_API_LEAVE(code); } -int32_t catalogChkTbMetaVersion(SCatalog* pCtg, SRequestConnInfo *pConn, SArray* pTables) { +int32_t catalogChkTbMetaVersion(SCatalog* pCtg, SRequestConnInfo* pConn, SArray* pTables) { CTG_API_ENTER(); if (NULL == pCtg || NULL == pConn || NULL == pTables) { @@ -944,7 +947,7 @@ int32_t catalogChkTbMetaVersion(SCatalog* pCtg, SRequestConnInfo *pConn, SArray* CTG_API_LEAVE(TSDB_CODE_SUCCESS); } -int32_t catalogRefreshDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char* dbFName) { +int32_t catalogRefreshDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName) { CTG_API_ENTER(); if (NULL == pCtg || NULL == pConn || NULL == dbFName) { @@ -954,7 +957,7 @@ int32_t catalogRefreshDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const ch CTG_API_LEAVE(ctgRefreshDBVgInfo(pCtg, pConn, dbFName)); } -int32_t catalogRefreshTableMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, int32_t isSTable) { +int32_t catalogRefreshTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, int32_t isSTable) { CTG_API_ENTER(); if (NULL == pCtg || NULL == pConn || NULL == pTableName) { @@ -968,7 +971,8 @@ int32_t catalogRefreshTableMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const S CTG_API_LEAVE(ctgRefreshTbMeta(pCtg, pConn, &ctx, NULL, true)); } -int32_t catalogRefreshGetTableMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable) { +int32_t catalogRefreshGetTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, + STableMeta** pTableMeta, int32_t isSTable) { CTG_API_ENTER(); SCtgTbMetaCtx ctx = {0}; @@ -978,7 +982,7 @@ int32_t catalogRefreshGetTableMeta(SCatalog* pCtg, SRequestConnInfo *pConn, cons CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta)); } -int32_t catalogGetTableDistVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, SArray** pVgList) { +int32_t catalogGetTableDistVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SArray** pVgList) { CTG_API_ENTER(); if (NULL == pCtg || NULL == pConn || NULL == pTableName || NULL == pVgList) { @@ -993,13 +997,14 @@ int32_t catalogGetTableDistVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const CTG_API_LEAVE(ctgGetTbDistVgInfo(pCtg, pConn, (SName*)pTableName, pVgList)); } -int32_t catalogGetTableHashVgroup(SCatalog *pCtg, SRequestConnInfo *pConn, const SName *pTableName, SVgroupInfo *pVgroup) { +int32_t catalogGetTableHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, + SVgroupInfo* pVgroup) { CTG_API_ENTER(); CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, pConn, pTableName, pVgroup)); } -int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const SCatalogReq* pReq, SMetaData* pRsp) { +int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalogReq* pReq, SMetaData* pRsp) { CTG_API_ENTER(); if (NULL == pCtg || NULL == pConn || NULL == pReq || NULL == pRsp) { @@ -1028,7 +1033,7 @@ int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const SCatalo SCtgTbMetaCtx ctx = {0}; ctx.pName = name; ctx.flag = CTG_FLAG_UNKNOWN_STB; - + CTG_ERR_JRET(ctgGetTbMeta(pCtg, pConn, &ctx, &pTableMeta)); if (NULL == taosArrayPush(pRsp->pTableMeta, &pTableMeta)) { @@ -1062,15 +1067,16 @@ _return: CTG_API_LEAVE(code); } -int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const SCatalogReq* pReq, catalogCallback fp, void* param, int64_t* jobId) { +int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalogReq* pReq, catalogCallback fp, + void* param, int64_t* jobId) { CTG_API_ENTER(); if (NULL == pCtg || NULL == pConn || NULL == pReq || NULL == fp || NULL == param) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } - int32_t code = 0; - SCtgJob *pJob = NULL; + int32_t code = 0; + SCtgJob* pJob = NULL; CTG_ERR_JRET(ctgInitJob(pCtg, pConn, &pJob, pReq, fp, param)); CTG_ERR_JRET(ctgLaunchJob(pJob)); @@ -1091,7 +1097,7 @@ _return: CTG_API_LEAVE(code); } -int32_t catalogGetQnodeList(SCatalog* pCtg, SRequestConnInfo *pConn, SArray* pQnodeList) { +int32_t catalogGetQnodeList(SCatalog* pCtg, SRequestConnInfo* pConn, SArray* pQnodeList) { CTG_API_ENTER(); int32_t code = 0; @@ -1121,14 +1127,14 @@ _return: CTG_API_LEAVE(TSDB_CODE_SUCCESS); } -int32_t catalogGetExpiredSTables(SCatalog* pCtg, SSTableVersion **stables, uint32_t *num) { +int32_t catalogGetExpiredSTables(SCatalog* pCtg, SSTableVersion** stables, uint32_t* num) { CTG_API_ENTER(); if (NULL == pCtg || NULL == stables || NULL == num) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } - CTG_API_LEAVE(ctgMetaRentGet(&pCtg->stbRent, (void **)stables, num, sizeof(SSTableVersion))); + CTG_API_LEAVE(ctgMetaRentGet(&pCtg->stbRent, (void**)stables, num, sizeof(SSTableVersion))); } int32_t catalogGetExpiredDBs(SCatalog* pCtg, SDbVgVersion** dbs, uint32_t* num) { @@ -1152,7 +1158,7 @@ int32_t catalogGetExpiredUsers(SCatalog* pCtg, SUserAuthVersion** users, uint32_ if (*num <= 0) { CTG_API_LEAVE(TSDB_CODE_SUCCESS); } - + *users = taosMemoryCalloc(*num, sizeof(SUserAuthVersion)); if (NULL == *users) { ctgError("calloc %d userAuthVersion failed", *num); @@ -1172,16 +1178,16 @@ int32_t catalogGetExpiredUsers(SCatalog* pCtg, SUserAuthVersion** users, uint32_ taosHashCancelIterate(pCtg->userCache, pAuth); break; } - + pAuth = taosHashIterate(pCtg->userCache, pAuth); } CTG_API_LEAVE(TSDB_CODE_SUCCESS); } -int32_t catalogGetDBCfg(SCatalog* pCtg, SRequestConnInfo *pConn, const char* dbFName, SDbCfgInfo* pDbCfg) { +int32_t catalogGetDBCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SDbCfgInfo* pDbCfg) { CTG_API_ENTER(); - + if (NULL == pCtg || NULL == pConn || NULL == dbFName || NULL == pDbCfg) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } @@ -1189,9 +1195,9 @@ int32_t catalogGetDBCfg(SCatalog* pCtg, SRequestConnInfo *pConn, const char* dbF CTG_API_LEAVE(ctgGetDBCfgFromMnode(pCtg, pConn, dbFName, pDbCfg, NULL)); } -int32_t catalogGetIndexMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const char* indexName, SIndexInfo* pInfo) { +int32_t catalogGetIndexMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const char* indexName, SIndexInfo* pInfo) { CTG_API_ENTER(); - + if (NULL == pCtg || NULL == pConn || NULL == indexName || NULL == pInfo) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } @@ -1199,24 +1205,24 @@ int32_t catalogGetIndexMeta(SCatalog* pCtg, SRequestConnInfo *pConn, const char* CTG_API_LEAVE(ctgGetIndexInfoFromMnode(pCtg, pConn, indexName, pInfo, NULL)); } -int32_t catalogGetTableIndex(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, SArray** pRes) { +int32_t catalogGetTableIndex(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SArray** pRes) { CTG_API_ENTER(); - + if (NULL == pCtg || NULL == pConn || NULL == pTableName || NULL == pRes) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } int32_t code = 0; CTG_ERR_JRET(ctgGetTbIndex(pCtg, pConn, (SName*)pTableName, pRes)); - + _return: CTG_API_LEAVE(code); } -int32_t catalogRefreshGetTableCfg(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, STableCfg** pCfg) { +int32_t catalogRefreshGetTableCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableCfg** pCfg) { CTG_API_ENTER(); - + if (NULL == pCtg || NULL == pConn || NULL == pTableName || NULL == pCfg) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } @@ -1231,52 +1237,52 @@ _return: CTG_API_LEAVE(code); } -int32_t catalogGetUdfInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char* funcName, SFuncInfo* pInfo) { +int32_t catalogGetUdfInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* funcName, SFuncInfo* pInfo) { CTG_API_ENTER(); - + if (NULL == pCtg || NULL == pConn || NULL == funcName || NULL == pInfo) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } int32_t code = 0; CTG_ERR_JRET(ctgGetUdfInfoFromMnode(pCtg, pConn, funcName, pInfo, NULL)); - + _return: CTG_API_LEAVE(code); } -int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo *pConn, const char* user, const char* dbFName, AUTH_TYPE type, bool *pass) { +int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type, + bool* pass) { CTG_API_ENTER(); - + if (NULL == pCtg || NULL == pConn || NULL == user || NULL == dbFName || NULL == pass) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } int32_t code = 0; CTG_ERR_JRET(ctgChkAuth(pCtg, pConn, user, dbFName, type, pass)); - + _return: CTG_API_LEAVE(code); } -int32_t catalogGetServerVersion(SCatalog* pCtg, SRequestConnInfo *pConn, char** pVersion) { +int32_t catalogGetServerVersion(SCatalog* pCtg, SRequestConnInfo* pConn, char** pVersion) { CTG_API_ENTER(); - + if (NULL == pCtg || NULL == pConn || NULL == pVersion) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } int32_t code = 0; CTG_ERR_JRET(ctgGetSvrVerFromMnode(pCtg, pConn, pVersion, NULL)); - + _return: CTG_API_LEAVE(code); } - int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth) { CTG_API_ENTER(); @@ -1299,11 +1305,10 @@ int32_t catalogClearCache(void) { int32_t code = ctgClearCacheEnqueue(NULL, false, false, true); qInfo("clear catalog cache end, code: %s", tstrerror(code)); - + CTG_API_LEAVE_NOLOCK(code); } - void catalogDestroy(void) { qInfo("start to destroy catalog"); diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 463ea9340aed23217e00cedebe4403fb5070cc56..1305540a5082e59317969b8fdd574f59a059aaf6 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -636,7 +636,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const taosAcquireRef(gCtgMgmt.jobPool, pJob->refId); - double el = (taosGetTimestampUs() - st)/1000.0; + double el = (taosGetTimestampUs() - st) / 1000.0; qDebug("QID:0x%" PRIx64 ", jobId: 0x%" PRIx64 " initialized, task num %d, forceUpdate %d, elapsed time:%.2f ms", pJob->queryId, pJob->refId, taskNum, pReq->forceUpdate, el); return TSDB_CODE_SUCCESS; diff --git a/source/libs/catalog/src/ctgDbg.c b/source/libs/catalog/src/ctgDbg.c index d21524230736c47fb3c81de0c00e1402f09a585e..dbca2ad9776b8b278f6795bebcca4423c55bcc99 100644 --- a/source/libs/catalog/src/ctgDbg.c +++ b/source/libs/catalog/src/ctgDbg.c @@ -13,16 +13,16 @@ * along with this program. If not, see . */ -#include "trpc.h" +#include "catalogInt.h" #include "query.h" #include "tname.h" -#include "catalogInt.h" +#include "trpc.h" extern SCatalogMgmt gCtgMgmt; -SCtgDebug gCTGDebug = {0}; +SCtgDebug gCTGDebug = {0}; -void ctgdUserCallback(SMetaData* pResult, void* param, int32_t code) { - ASSERT(*(int32_t*)param == 1); +void ctgdUserCallback(SMetaData *pResult, void *param, int32_t code) { + ASSERT(*(int32_t *)param == 1); taosMemoryFree(param); qDebug("async call result: %s", tstrerror(code)); @@ -36,16 +36,19 @@ void ctgdUserCallback(SMetaData* pResult, void* param, int32_t code) { if (pResult->pTableMeta && taosArrayGetSize(pResult->pTableMeta) > 0) { num = taosArrayGetSize(pResult->pTableMeta); for (int32_t i = 0; i < num; ++i) { - STableMeta *p = *(STableMeta **)taosArrayGet(pResult->pTableMeta, i); + STableMeta *p = *(STableMeta **)taosArrayGet(pResult->pTableMeta, i); STableComInfo *c = &p->tableInfo; - + if (TSDB_CHILD_TABLE == p->tableType) { - qDebug("table meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64, p->tableType, p->vgId, p->uid, p->suid); + qDebug("table meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64, p->tableType, p->vgId, p->uid, + p->suid); } else { - qDebug("table meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64 ",sv:%d, tv:%d, tagNum:%d, precision:%d, colNum:%d, rowSize:%d", - p->tableType, p->vgId, p->uid, p->suid, p->sversion, p->tversion, c->numOfTags, c->precision, c->numOfColumns, c->rowSize); + qDebug("table meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64 + ",sv:%d, tv:%d, tagNum:%d, precision:%d, colNum:%d, rowSize:%d", + p->tableType, p->vgId, p->uid, p->suid, p->sversion, p->tversion, c->numOfTags, c->precision, + c->numOfColumns, c->rowSize); } - + int32_t colNum = c->numOfColumns + c->numOfTags; for (int32_t j = 0; j < colNum; ++j) { SSchema *s = &p->schema[j]; @@ -59,11 +62,11 @@ void ctgdUserCallback(SMetaData* pResult, void* param, int32_t code) { if (pResult->pDbVgroup && taosArrayGetSize(pResult->pDbVgroup) > 0) { num = taosArrayGetSize(pResult->pDbVgroup); for (int32_t i = 0; i < num; ++i) { - SArray *pDb = *(SArray**)taosArrayGet(pResult->pDbVgroup, i); + SArray *pDb = *(SArray **)taosArrayGet(pResult->pDbVgroup, i); int32_t vgNum = taosArrayGetSize(pDb); qDebug("db %d vgInfo:", i); for (int32_t j = 0; j < vgNum; ++j) { - SVgroupInfo* pInfo = taosArrayGet(pDb, j); + SVgroupInfo *pInfo = taosArrayGet(pDb, j); qDebug("vg :%d info: vgId:%d", j, pInfo->vgId); } } @@ -84,7 +87,7 @@ void ctgdUserCallback(SMetaData* pResult, void* param, int32_t code) { if (pResult->pTableHash && taosArrayGetSize(pResult->pTableHash) > 0) { num = taosArrayGetSize(pResult->pTableHash); for (int32_t i = 0; i < num; ++i) { - SVgroupInfo* pInfo = taosArrayGet(pResult->pTableHash, i); + SVgroupInfo *pInfo = taosArrayGet(pResult->pTableHash, i); qDebug("table %d vg info: vgId:%d", i, pInfo->vgId); } } else { @@ -94,7 +97,7 @@ void ctgdUserCallback(SMetaData* pResult, void* param, int32_t code) { if (pResult->pUdfList && taosArrayGetSize(pResult->pUdfList) > 0) { num = taosArrayGetSize(pResult->pUdfList); for (int32_t i = 0; i < num; ++i) { - SFuncInfo* pInfo = taosArrayGet(pResult->pUdfList, i); + SFuncInfo *pInfo = taosArrayGet(pResult->pUdfList, i); qDebug("udf %d info: name:%s, funcType:%d", i, pInfo->name, pInfo->funcType); } } else { @@ -104,35 +107,34 @@ void ctgdUserCallback(SMetaData* pResult, void* param, int32_t code) { if (pResult->pDbCfg && taosArrayGetSize(pResult->pDbCfg) > 0) { num = taosArrayGetSize(pResult->pDbCfg); for (int32_t i = 0; i < num; ++i) { - SDbCfgInfo* pInfo = taosArrayGet(pResult->pDbCfg, i); + SDbCfgInfo *pInfo = taosArrayGet(pResult->pDbCfg, i); qDebug("db %d info: numOFVgroups:%d, numOfStables:%d", i, pInfo->numOfVgroups, pInfo->numOfStables); } } else { qDebug("empty db cfg info"); - } + } if (pResult->pUser && taosArrayGetSize(pResult->pUser) > 0) { num = taosArrayGetSize(pResult->pUser); for (int32_t i = 0; i < num; ++i) { - bool* auth = taosArrayGet(pResult->pUser, i); + bool *auth = taosArrayGet(pResult->pUser, i); qDebug("user auth %d info: %d", i, *auth); } } else { qDebug("empty user auth info"); - } + } if (pResult->pQnodeList && taosArrayGetSize(pResult->pQnodeList) > 0) { num = taosArrayGetSize(pResult->pQnodeList); for (int32_t i = 0; i < num; ++i) { - SQueryNodeAddr* qaddr = taosArrayGet(pResult->pQnodeList, i); + SQueryNodeAddr *qaddr = taosArrayGet(pResult->pQnodeList, i); qDebug("qnode %d info: id:%d", i, qaddr->nodeId); } } else { qDebug("empty qnode info"); - } + } } - /* prepare SQL: create database db1; @@ -147,8 +149,8 @@ grant write on db2.* to user1; create function udf1 as '/tmp/libudf1.so' outputtype int; create aggregate function udf2 as '/tmp/libudf2.so' outputtype int; */ -int32_t ctgdLaunchAsyncCall(SCatalog* pCtg, SRequestConnInfo* pConn, uint64_t reqId, bool forceUpdate) { - int32_t code = 0; +int32_t ctgdLaunchAsyncCall(SCatalog *pCtg, SRequestConnInfo *pConn, uint64_t reqId, bool forceUpdate) { + int32_t code = 0; SCatalogReq req = {0}; req.pTableMeta = taosArrayInit(2, sizeof(SName)); req.pDbVgroup = taosArrayInit(2, TSDB_DB_FNAME_LEN); @@ -156,16 +158,16 @@ int32_t ctgdLaunchAsyncCall(SCatalog* pCtg, SRequestConnInfo* pConn, uint64_t re req.pTableHash = taosArrayInit(2, sizeof(SName)); req.pUdf = taosArrayInit(2, TSDB_FUNC_NAME_LEN); req.pDbCfg = taosArrayInit(2, TSDB_DB_FNAME_LEN); - req.pIndex = NULL;//taosArrayInit(2, TSDB_INDEX_FNAME_LEN); + req.pIndex = NULL; // taosArrayInit(2, TSDB_INDEX_FNAME_LEN); req.pUser = taosArrayInit(2, sizeof(SUserAuthInfo)); req.qNodeRequired = true; req.forceUpdate = forceUpdate; - SName name = {0}; - char dbFName[TSDB_DB_FNAME_LEN] = {0}; - char funcName[TSDB_FUNC_NAME_LEN] = {0}; + SName name = {0}; + char dbFName[TSDB_DB_FNAME_LEN] = {0}; + char funcName[TSDB_FUNC_NAME_LEN] = {0}; SUserAuthInfo user = {0}; - + tNameFromString(&name, "1.db1.tb1", T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); taosArrayPush(req.pTableMeta, &name); taosArrayPush(req.pTableHash, &name); @@ -207,7 +209,7 @@ int32_t ctgdLaunchAsyncCall(SCatalog* pCtg, SRequestConnInfo* pConn, uint64_t re int32_t *param = taosMemoryCalloc(1, sizeof(int32_t)); *param = 1; - + int64_t jobId = 0; CTG_ERR_JRET(catalogAsyncGetAllMeta(pCtg, pConn, &req, ctgdUserCallback, param, &jobId)); @@ -221,7 +223,7 @@ _return: taosArrayDestroy(req.pDbCfg); taosArrayDestroy(req.pUser); - CTG_RET(code); + CTG_RET(code); } int32_t ctgdEnableDebug(char *option) { @@ -250,7 +252,7 @@ int32_t ctgdEnableDebug(char *option) { } qError("invalid debug option:%s", option); - + return TSDB_CODE_CTG_INTERNAL_ERROR; } @@ -261,7 +263,7 @@ int32_t ctgdGetStatNum(char *option, void *res) { } qError("invalid stat option:%s", option); - + return TSDB_CODE_CTG_INTERNAL_ERROR; } @@ -287,7 +289,7 @@ int32_t ctgdGetRentNum(SCtgRentMgmt *rent) { return num; } -int32_t ctgdGetClusterCacheNum(SCatalog* pCtg, int32_t type) { +int32_t ctgdGetClusterCacheNum(SCatalog *pCtg, int32_t type) { if (NULL == pCtg || NULL == pCtg->dbCache) { return 0; } @@ -304,8 +306,8 @@ int32_t ctgdGetClusterCacheNum(SCatalog* pCtg, int32_t type) { } SCtgDBCache *dbCache = NULL; - int32_t num = 0; - void *pIter = taosHashIterate(pCtg->dbCache, NULL); + int32_t num = 0; + void *pIter = taosHashIterate(pCtg->dbCache, NULL); while (pIter) { dbCache = (SCtgDBCache *)pIter; switch (type) { @@ -325,7 +327,7 @@ int32_t ctgdGetClusterCacheNum(SCatalog* pCtg, int32_t type) { return num; } -void ctgdShowTableMeta(SCatalog* pCtg, const char *tbName, STableMeta* p) { +void ctgdShowTableMeta(SCatalog *pCtg, const char *tbName, STableMeta *p) { if (!gCTGDebug.metaEnable) { return; } @@ -333,11 +335,14 @@ void ctgdShowTableMeta(SCatalog* pCtg, const char *tbName, STableMeta* p) { STableComInfo *c = &p->tableInfo; if (TSDB_CHILD_TABLE == p->tableType) { - ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64, tbName, p->tableType, p->vgId, p->uid, p->suid); + ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64, tbName, p->tableType, p->vgId, + p->uid, p->suid); return; } else { - ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64 ",sv:%d, tv:%d, tagNum:%d, precision:%d, colNum:%d, rowSize:%d", - tbName, p->tableType, p->vgId, p->uid, p->suid, p->sversion, p->tversion, c->numOfTags, c->precision, c->numOfColumns, c->rowSize); + ctgDebug("table [%s] meta: type:%d, vgId:%d, uid:0x%" PRIx64 ",suid:0x%" PRIx64 + ",sv:%d, tv:%d, tagNum:%d, precision:%d, colNum:%d, rowSize:%d", + tbName, p->tableType, p->vgId, p->uid, p->suid, p->sversion, p->tversion, c->numOfTags, c->precision, + c->numOfColumns, c->rowSize); } int32_t colNum = c->numOfColumns + c->numOfTags; @@ -347,18 +352,18 @@ void ctgdShowTableMeta(SCatalog* pCtg, const char *tbName, STableMeta* p) { } } -void ctgdShowDBCache(SCatalog* pCtg, SHashObj *dbHash) { +void ctgdShowDBCache(SCatalog *pCtg, SHashObj *dbHash) { if (NULL == dbHash || !gCTGDebug.cacheEnable) { return; } - int32_t i = 0; + int32_t i = 0; SCtgDBCache *dbCache = NULL; - void *pIter = taosHashIterate(dbHash, NULL); + void *pIter = taosHashIterate(dbHash, NULL); while (pIter) { - char *dbFName = NULL; + char *dbFName = NULL; size_t len = 0; - + dbCache = (SCtgDBCache *)pIter; dbFName = taosHashGetKey(pIter, &len); @@ -380,29 +385,29 @@ void ctgdShowDBCache(SCatalog* pCtg, SHashObj *dbHash) { vgNum = taosHashGetSize(dbCache->vgCache.vgInfo->vgHash); } } - - ctgDebug("[%d] db [%.*s][0x%"PRIx64"] %s: metaNum:%d, stbNum:%d, vgVersion:%d, hashMethod:%d, prefix:%d, suffix:%d, vgNum:%d", - i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted?"deleted":"", metaNum, stbNum, vgVersion, hashMethod, hashPrefix, hashSuffix, vgNum); + + ctgDebug("[%d] db [%.*s][0x%" PRIx64 + "] %s: metaNum:%d, stbNum:%d, vgVersion:%d, hashMethod:%d, prefix:%d, suffix:%d, vgNum:%d", + i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted ? "deleted" : "", metaNum, stbNum, vgVersion, + hashMethod, hashPrefix, hashSuffix, vgNum); pIter = taosHashIterate(dbHash, pIter); } } - - - -void ctgdShowClusterCache(SCatalog* pCtg) { +void ctgdShowClusterCache(SCatalog *pCtg) { if (!gCTGDebug.cacheEnable || NULL == pCtg) { return; } - ctgDebug("## cluster 0x%"PRIx64" %p cache Info BEGIN ##", pCtg->clusterId, pCtg); - ctgDebug("db:%d meta:%d stb:%d dbRent:%d stbRent:%d", ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), - ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM)); - + ctgDebug("## cluster 0x%" PRIx64 " %p cache Info BEGIN ##", pCtg->clusterId, pCtg); + ctgDebug("db:%d meta:%d stb:%d dbRent:%d stbRent:%d", ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), + ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), + ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM)); + ctgdShowDBCache(pCtg, pCtg->dbCache); - ctgDebug("## cluster 0x%"PRIx64" %p cache Info END ##", pCtg->clusterId, pCtg); + ctgDebug("## cluster 0x%" PRIx64 " %p cache Info END ##", pCtg->clusterId, pCtg); } int32_t ctgdShowCacheInfo(void) { @@ -413,19 +418,18 @@ int32_t ctgdShowCacheInfo(void) { CTG_API_ENTER(); qDebug("# total catalog cluster number %d #", taosHashGetSize(gCtgMgmt.pCluster)); - + SCatalog *pCtg = NULL; - void *pIter = taosHashIterate(gCtgMgmt.pCluster, NULL); + void *pIter = taosHashIterate(gCtgMgmt.pCluster, NULL); while (pIter) { pCtg = *(SCatalog **)pIter; if (pCtg) { ctgdShowClusterCache(pCtg); } - + pIter = taosHashIterate(gCtgMgmt.pCluster, pIter); } CTG_API_LEAVE(TSDB_CODE_SUCCESS); } - diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index 7b8c66e36889dde2fe0c624c6adb099151455501..744d6eab0693293df5887e613539cc9935beba6d 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -638,7 +638,7 @@ int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray char* msg = NULL; int32_t msgLen = 0; int32_t reqType = TDMT_MND_QNODE_LIST; - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; ctgDebug("try to get qnode list from mnode, mgmtEpInUse:%d", pConn->mgmtEps.inUse); @@ -692,7 +692,7 @@ int32_t ctgGetDnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray char* msg = NULL; int32_t msgLen = 0; int32_t reqType = TDMT_MND_DNODE_LIST; - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; ctgDebug("try to get dnode list from mnode, mgmtEpInUse:%d", pConn->mgmtEps.inUse); @@ -743,7 +743,7 @@ int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SBuildU int32_t msgLen = 0; int32_t reqType = TDMT_MND_USE_DB; SCtgTask* pTask = tReq ? tReq->pTask : NULL; - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; ctgDebug("try to get db vgInfo from mnode, dbFName:%s", input->db); @@ -795,7 +795,7 @@ int32_t ctgGetDBCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char char* msg = NULL; int32_t msgLen = 0; int32_t reqType = TDMT_MND_GET_DB_CFG; - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; ctgDebug("try to get db cfg from mnode, dbFName:%s", dbFName); @@ -850,7 +850,7 @@ int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char* msg = NULL; int32_t msgLen = 0; int32_t reqType = TDMT_MND_GET_INDEX; - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; ctgDebug("try to get index from mnode, indexName:%s", indexName); @@ -905,7 +905,7 @@ int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* n char* msg = NULL; int32_t msgLen = 0; int32_t reqType = TDMT_MND_GET_TABLE_INDEX; - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; char tbFName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(name, tbFName); @@ -962,7 +962,7 @@ int32_t ctgGetUdfInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const ch char* msg = NULL; int32_t msgLen = 0; int32_t reqType = TDMT_MND_RETRIEVE_FUNC; - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; ctgDebug("try to get udf info from mnode, funcName:%s", funcName); @@ -1017,7 +1017,7 @@ int32_t ctgGetUserDbAuthFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char* msg = NULL; int32_t msgLen = 0; int32_t reqType = TDMT_MND_GET_USER_AUTH; - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; ctgDebug("try to get user auth from mnode, user:%s", user); @@ -1077,7 +1077,7 @@ int32_t ctgGetTbMetaFromMnodeImpl(SCatalog* pCtg, SRequestConnInfo* pConn, char* int32_t reqType = TDMT_MND_TABLE_META; char tbFName[TSDB_TABLE_FNAME_LEN]; sprintf(tbFName, "%s.%s", dbFName, tbName); - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; ctgDebug("try to get table meta from mnode, tbFName:%s", tbFName); @@ -1140,7 +1140,7 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa int32_t reqType = TDMT_VND_TABLE_META; char tbFName[TSDB_TABLE_FNAME_LEN]; sprintf(tbFName, "%s.%s", dbFName, pTableName->tname); - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; SEp* pEp = &vgroupInfo->epSet.eps[vgroupInfo->epSet.inUse]; ctgDebug("try to get table meta from vnode, vgId:%d, ep num:%d, ep %s:%d, tbFName:%s", vgroupInfo->vgId, @@ -1209,7 +1209,7 @@ int32_t ctgGetTableCfgFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const S int32_t reqType = TDMT_VND_TABLE_CFG; char tbFName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(pTableName, tbFName); - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; char dbFName[TSDB_DB_FNAME_LEN]; tNameGetFullDbName(pTableName, dbFName); SBuildTableInput bInput = {.vgId = vgroupInfo->vgId, .dbFName = dbFName, .tbName = (char*)pTableName->tname}; @@ -1274,7 +1274,7 @@ int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const S int32_t reqType = TDMT_MND_TABLE_CFG; char tbFName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(pTableName, tbFName); - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; char dbFName[TSDB_DB_FNAME_LEN]; tNameGetFullDbName(pTableName, dbFName); SBuildTableInput bInput = {.vgId = 0, .dbFName = dbFName, .tbName = (char*)pTableName->tname}; @@ -1326,7 +1326,7 @@ int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, char** ou char* msg = NULL; int32_t msgLen = 0; int32_t reqType = TDMT_MND_SERVER_VERSION; - void* (*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + void* (*mallocFp)(int64_t) = pTask ? taosMemoryMalloc : rpcMallocCont; qDebug("try to get svr ver from mnode"); diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 0c0ca9649a5962e0b1c4bd49796c25f7bc52912a..4a64a8666eabf645d09753ab404c34e2167f7df4 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -13,11 +13,11 @@ * along with this program. If not, see . */ -#include "trpc.h" -#include "query.h" -#include "tname.h" #include "catalogInt.h" +#include "query.h" #include "systable.h" +#include "tname.h" +#include "trpc.h" void ctgFreeMsgSendParam(void* param) { if (NULL == param) { @@ -39,16 +39,16 @@ void ctgFreeBatchMsg(void* msg) { taosMemoryFree(pMsg->msg); } -void ctgFreeBatch(SCtgBatch *pBatch) { +void ctgFreeBatch(SCtgBatch* pBatch) { if (NULL == pBatch) { return; } - + taosArrayDestroyEx(pBatch->pMsgs, ctgFreeBatchMsg); taosArrayDestroy(pBatch->pTaskIds); } -void ctgFreeBatchs(SHashObj *pBatchs) { +void ctgFreeBatchs(SHashObj* pBatchs) { void* p = taosHashIterate(pBatchs, NULL); while (NULL != p) { SCtgBatch* pBatch = (SCtgBatch*)p; @@ -61,7 +61,7 @@ void ctgFreeBatchs(SHashObj *pBatchs) { taosHashCleanup(pBatchs); } -char *ctgTaskTypeStr(CTG_TASK_TYPE type) { +char* ctgTaskTypeStr(CTG_TASK_TYPE type) { switch (type) { case CTG_TASK_GET_QNODE: return "[get qnode list]"; @@ -98,7 +98,7 @@ char *ctgTaskTypeStr(CTG_TASK_TYPE type) { } } -void ctgFreeQNode(SCtgQNode *node) { +void ctgFreeQNode(SCtgQNode* node) { if (NULL == node) { return; } @@ -107,16 +107,16 @@ void ctgFreeQNode(SCtgQNode *node) { taosMemoryFree(node->op->data); taosMemoryFree(node->op); } - + taosMemoryFree(node); } -void ctgFreeSTableIndex(void *info) { +void ctgFreeSTableIndex(void* info) { if (NULL == info) { return; } - STableIndex *pInfo = (STableIndex *)info; + STableIndex* pInfo = (STableIndex*)info; taosArrayDestroyEx(pInfo->pIndex, tFreeSTableIndexInfo); } @@ -125,42 +125,42 @@ void ctgFreeSMetaData(SMetaData* pData) { taosArrayDestroy(pData->pTableMeta); pData->pTableMeta = NULL; -/* - for (int32_t i = 0; i < taosArrayGetSize(pData->pDbVgroup); ++i) { - SArray** pArray = taosArrayGet(pData->pDbVgroup, i); - taosArrayDestroy(*pArray); - } -*/ + /* + for (int32_t i = 0; i < taosArrayGetSize(pData->pDbVgroup); ++i) { + SArray** pArray = taosArrayGet(pData->pDbVgroup, i); + taosArrayDestroy(*pArray); + } + */ taosArrayDestroy(pData->pDbVgroup); pData->pDbVgroup = NULL; - + taosArrayDestroy(pData->pTableHash); pData->pTableHash = NULL; taosArrayDestroy(pData->pTableIndex); pData->pTableIndex = NULL; - + taosArrayDestroy(pData->pUdfList); pData->pUdfList = NULL; -/* - for (int32_t i = 0; i < taosArrayGetSize(pData->pDbCfg); ++i) { - SDbCfgInfo* pInfo = taosArrayGet(pData->pDbCfg, i); - taosArrayDestroy(pInfo->pRetensions); - } -*/ + /* + for (int32_t i = 0; i < taosArrayGetSize(pData->pDbCfg); ++i) { + SDbCfgInfo* pInfo = taosArrayGet(pData->pDbCfg, i); + taosArrayDestroy(pInfo->pRetensions); + } + */ taosArrayDestroy(pData->pDbCfg); pData->pDbCfg = NULL; taosArrayDestroy(pData->pDbInfo); pData->pDbInfo = NULL; - + taosArrayDestroy(pData->pIndex); pData->pIndex = NULL; - + taosArrayDestroy(pData->pUser); pData->pUser = NULL; - + taosArrayDestroy(pData->pQnodeList); pData->pQnodeList = NULL; @@ -173,19 +173,19 @@ void ctgFreeSMetaData(SMetaData* pData) { taosMemoryFreeClear(pData->pSvrVer); } -void ctgFreeSCtgUserAuth(SCtgUserAuth *userCache) { +void ctgFreeSCtgUserAuth(SCtgUserAuth* userCache) { taosHashCleanup(userCache->createdDbs); taosHashCleanup(userCache->readDbs); taosHashCleanup(userCache->writeDbs); } -void ctgFreeMetaRent(SCtgRentMgmt *mgmt) { +void ctgFreeMetaRent(SCtgRentMgmt* mgmt) { if (NULL == mgmt->slots) { return; } for (int32_t i = 0; i < mgmt->slotNum; ++i) { - SCtgRentSlot *slot = &mgmt->slots[i]; + SCtgRentSlot* slot = &mgmt->slots[i]; if (slot->meta) { taosArrayDestroy(slot->meta); slot->meta = NULL; @@ -195,18 +195,18 @@ void ctgFreeMetaRent(SCtgRentMgmt *mgmt) { taosMemoryFreeClear(mgmt->slots); } -void ctgFreeStbMetaCache(SCtgDBCache *dbCache) { +void ctgFreeStbMetaCache(SCtgDBCache* dbCache) { if (NULL == dbCache->stbCache) { return; } - int32_t stbNum = taosHashGetSize(dbCache->stbCache); + int32_t stbNum = taosHashGetSize(dbCache->stbCache); taosHashCleanup(dbCache->stbCache); dbCache->stbCache = NULL; CTG_CACHE_STAT_DEC(numOfStb, stbNum); } -void ctgFreeTbCacheImpl(SCtgTbCache *pCache) { +void ctgFreeTbCacheImpl(SCtgTbCache* pCache) { qDebug("tbMeta freed, p:%p", pCache->pMeta); taosMemoryFreeClear(pCache->pMeta); if (pCache->pIndex) { @@ -215,13 +215,13 @@ void ctgFreeTbCacheImpl(SCtgTbCache *pCache) { } } -void ctgFreeTbCache(SCtgDBCache *dbCache) { +void ctgFreeTbCache(SCtgDBCache* dbCache) { if (NULL == dbCache->tbCache) { return; } - int32_t tblNum = taosHashGetSize(dbCache->tbCache); - SCtgTbCache *pCache = taosHashIterate(dbCache->tbCache, NULL); + int32_t tblNum = taosHashGetSize(dbCache->tbCache); + SCtgTbCache* pCache = taosHashIterate(dbCache->tbCache, NULL); while (NULL != pCache) { ctgFreeTbCacheImpl(pCache); pCache = taosHashIterate(dbCache->tbCache, pCache); @@ -231,7 +231,7 @@ void ctgFreeTbCache(SCtgDBCache *dbCache) { CTG_CACHE_STAT_DEC(numOfTbl, tblNum); } -void ctgFreeVgInfo(SDBVgInfo *vgInfo) { +void ctgFreeVgInfo(SDBVgInfo* vgInfo) { if (NULL == vgInfo) { return; } @@ -240,15 +240,13 @@ void ctgFreeVgInfo(SDBVgInfo *vgInfo) { taosHashCleanup(vgInfo->vgHash); vgInfo->vgHash = NULL; } - + taosMemoryFreeClear(vgInfo); } -void ctgFreeVgInfoCache(SCtgDBCache *dbCache) { - ctgFreeVgInfo(dbCache->vgCache.vgInfo); -} +void ctgFreeVgInfoCache(SCtgDBCache* dbCache) { ctgFreeVgInfo(dbCache->vgCache.vgInfo); } -void ctgFreeDbCache(SCtgDBCache *dbCache) { +void ctgFreeDbCache(SCtgDBCache* dbCache) { if (NULL == dbCache) { return; } @@ -262,20 +260,20 @@ void ctgFreeInstDbCache(SHashObj* pDbCache) { if (NULL == pDbCache) { return; } - + int32_t dbNum = taosHashGetSize(pDbCache); - - void *pIter = taosHashIterate(pDbCache, NULL); + + void* pIter = taosHashIterate(pDbCache, NULL); while (pIter) { - SCtgDBCache *dbCache = pIter; + SCtgDBCache* dbCache = pIter; atomic_store_8(&dbCache->deleted, 1); ctgFreeDbCache(dbCache); - + pIter = taosHashIterate(pDbCache, pIter); - } + } taosHashCleanup(pDbCache); - + CTG_CACHE_STAT_DEC(numOfDb, dbNum); } @@ -283,19 +281,19 @@ void ctgFreeInstUserCache(SHashObj* pUserCache) { if (NULL == pUserCache) { return; } - + int32_t userNum = taosHashGetSize(pUserCache); - - void *pIter = taosHashIterate(pUserCache, NULL); + + void* pIter = taosHashIterate(pUserCache, NULL); while (pIter) { - SCtgUserAuth *userCache = pIter; + SCtgUserAuth* userCache = pIter; ctgFreeSCtgUserAuth(userCache); - + pIter = taosHashIterate(pUserCache, pIter); - } - + } + taosHashCleanup(pUserCache); - + CTG_CACHE_STAT_DEC(numOfUser, userNum); } @@ -309,7 +307,6 @@ void ctgFreeHandleImpl(SCatalog* pCtg) { taosMemoryFree(pCtg); } - void ctgFreeHandle(SCatalog* pCtg) { if (NULL == pCtg) { return; @@ -345,13 +342,15 @@ void ctgClearHandle(SCatalog* pCtg) { ctgMetaRentInit(&pCtg->dbRent, gCtgMgmt.cfg.dbRentSec, CTG_RENT_DB); ctgMetaRentInit(&pCtg->stbRent, gCtgMgmt.cfg.stbRentSec, CTG_RENT_STABLE); - - pCtg->dbCache = taosHashInit(gCtgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); + + pCtg->dbCache = taosHashInit(gCtgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, + HASH_ENTRY_LOCK); if (NULL == pCtg->dbCache) { qError("taosHashInit %d dbCache failed", CTG_DEFAULT_CACHE_DB_NUMBER); } - - pCtg->userCache = taosHashInit(gCtgMgmt.cfg.maxUserCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); + + pCtg->userCache = taosHashInit(gCtgMgmt.cfg.maxUserCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, + HASH_ENTRY_LOCK); if (NULL == pCtg->userCache) { ctgError("taosHashInit %d user cache failed", gCtgMgmt.cfg.maxUserCacheNum); } @@ -370,7 +369,7 @@ void ctgFreeSUseDbOutput(SUseDbOutput* pOutput) { taosHashCleanup(pOutput->dbVgroup->vgHash); taosMemoryFreeClear(pOutput->dbVgroup); } - + taosMemoryFree(pOutput); } @@ -379,7 +378,7 @@ void ctgFreeMsgCtx(SCtgMsgCtx* pCtx) { if (NULL == pCtx->out) { return; } - + switch (pCtx->reqType) { case TDMT_MND_GET_DB_CFG: { SDbCfgInfo* pOut = (SDbCfgInfo*)pCtx->out; @@ -387,7 +386,7 @@ void ctgFreeMsgCtx(SCtgMsgCtx* pCtx) { taosMemoryFreeClear(pCtx->out); break; } - case TDMT_MND_USE_DB:{ + case TDMT_MND_USE_DB: { SUseDbOutput* pOut = (SUseDbOutput*)pCtx->out; ctgFreeSUseDbOutput(pOut); pCtx->out = NULL; @@ -459,17 +458,16 @@ void ctgFreeSTableMetaOutput(STableMetaOutput* pOutput) { if (NULL == pOutput) { return; } - + taosMemoryFree(pOutput->tbMeta); taosMemoryFree(pOutput); } - void ctgResetTbMetaTask(SCtgTask* pTask) { SCtgTbMetaCtx* taskCtx = (SCtgTbMetaCtx*)pTask->taskCtx; memset(&taskCtx->tbInfo, 0, sizeof(taskCtx->tbInfo)); taskCtx->flag = CTG_FLAG_UNKNOWN_STB; - + if (pTask->msgCtx.lastOut) { ctgFreeSTableMetaOutput((STableMetaOutput*)pTask->msgCtx.lastOut); pTask->msgCtx.lastOut = NULL; @@ -486,7 +484,7 @@ void ctgFreeBatchMeta(void* meta) { if (NULL == meta) { return; } - + SMetaRes* pRes = (SMetaRes*)meta; taosMemoryFreeClear(pRes->pRes); } @@ -495,13 +493,12 @@ void ctgFreeBatchHash(void* hash) { if (NULL == hash) { return; } - + SMetaRes* pRes = (SMetaRes*)hash; taosMemoryFreeClear(pRes->pRes); } - -void ctgFreeTaskRes(CTG_TASK_TYPE type, void **pRes) { +void ctgFreeTaskRes(CTG_TASK_TYPE type, void** pRes) { switch (type) { case CTG_TASK_GET_QNODE: case CTG_TASK_GET_DNODE: @@ -534,8 +531,8 @@ void ctgFreeTaskRes(CTG_TASK_TYPE type, void **pRes) { case CTG_TASK_GET_TB_HASH: case CTG_TASK_GET_DB_INFO: case CTG_TASK_GET_INDEX: - case CTG_TASK_GET_UDF: - case CTG_TASK_GET_USER: + case CTG_TASK_GET_UDF: + case CTG_TASK_GET_USER: case CTG_TASK_GET_SVR_VER: case CTG_TASK_GET_TB_META: { taosMemoryFreeClear(*pRes); @@ -547,7 +544,7 @@ void ctgFreeTaskRes(CTG_TASK_TYPE type, void **pRes) { for (int32_t i = 0; i < num; ++i) { ctgFreeBatchMeta(taosArrayGet(pArray, i)); } - *pRes = NULL; // no need to free it + *pRes = NULL; // no need to free it break; } case CTG_TASK_GET_TB_HASH_BATCH: { @@ -556,17 +553,16 @@ void ctgFreeTaskRes(CTG_TASK_TYPE type, void **pRes) { for (int32_t i = 0; i < num; ++i) { ctgFreeBatchHash(taosArrayGet(pArray, i)); } - *pRes = NULL; // no need to free it + *pRes = NULL; // no need to free it break; - } + } default: qError("invalid task type %d", type); break; } } - -void ctgFreeSubTaskRes(CTG_TASK_TYPE type, void **pRes) { +void ctgFreeSubTaskRes(CTG_TASK_TYPE type, void** pRes) { switch (type) { case CTG_TASK_GET_QNODE: case CTG_TASK_GET_DNODE: { @@ -603,12 +599,12 @@ void ctgFreeSubTaskRes(CTG_TASK_TYPE type, void **pRes) { } break; } - case CTG_TASK_GET_TB_META: + case CTG_TASK_GET_TB_META: case CTG_TASK_GET_DB_INFO: case CTG_TASK_GET_TB_HASH: - case CTG_TASK_GET_INDEX: - case CTG_TASK_GET_UDF: - case CTG_TASK_GET_SVR_VER: + case CTG_TASK_GET_INDEX: + case CTG_TASK_GET_UDF: + case CTG_TASK_GET_SVR_VER: case CTG_TASK_GET_USER: { taosMemoryFreeClear(*pRes); break; @@ -629,8 +625,7 @@ void ctgFreeSubTaskRes(CTG_TASK_TYPE type, void **pRes) { } } - -void ctgClearSubTaskRes(SCtgSubRes *pRes) { +void ctgClearSubTaskRes(SCtgSubRes* pRes) { pRes->code = 0; if (NULL == pRes->res) { @@ -659,7 +654,7 @@ void ctgFreeTaskCtx(SCtgTask* pTask) { // NO NEED TO FREE pNames taosArrayDestroyEx(pTask->msgCtxs, (FDelete)ctgFreeTbMetasMsgCtx); - + if (pTask->msgCtx.lastOut) { ctgFreeSTableMetaOutput((STableMetaOutput*)pTask->msgCtx.lastOut); pTask->msgCtx.lastOut = NULL; @@ -670,7 +665,7 @@ void ctgFreeTaskCtx(SCtgTask* pTask) { case CTG_TASK_GET_TB_HASH: { SCtgTbHashCtx* taskCtx = (SCtgTbHashCtx*)pTask->taskCtx; taosMemoryFreeClear(taskCtx->pName); - taosMemoryFreeClear(pTask->taskCtx); + taosMemoryFreeClear(pTask->taskCtx); break; } case CTG_TASK_GET_TB_HASH_BATCH: { @@ -680,10 +675,10 @@ void ctgFreeTaskCtx(SCtgTask* pTask) { // NO NEED TO FREE pNames taosArrayDestroyEx(pTask->msgCtxs, (FDelete)ctgFreeMsgCtx); - + taosMemoryFreeClear(pTask->taskCtx); break; - } + } case CTG_TASK_GET_TB_INDEX: { SCtgTbIndexCtx* taskCtx = (SCtgTbIndexCtx*)pTask->taskCtx; taosMemoryFreeClear(taskCtx->pName); @@ -699,10 +694,10 @@ void ctgFreeTaskCtx(SCtgTask* pTask) { } case CTG_TASK_GET_DB_VGROUP: case CTG_TASK_GET_DB_CFG: - case CTG_TASK_GET_DB_INFO: + case CTG_TASK_GET_DB_INFO: case CTG_TASK_GET_INDEX: case CTG_TASK_GET_UDF: - case CTG_TASK_GET_QNODE: + case CTG_TASK_GET_QNODE: case CTG_TASK_GET_USER: { taosMemoryFreeClear(pTask->taskCtx); break; @@ -713,7 +708,6 @@ void ctgFreeTaskCtx(SCtgTask* pTask) { } } - void ctgFreeTask(SCtgTask* pTask) { ctgFreeMsgCtx(&pTask->msgCtx); ctgFreeTaskRes(pTask->type, &pTask->res); @@ -741,10 +735,10 @@ void ctgFreeJob(void* job) { if (NULL == job) { return; } - + SCtgJob* pJob = (SCtgJob*)job; - int64_t rid = pJob->refId; + int64_t rid = pJob->refId; uint64_t qid = pJob->queryId; ctgFreeTasks(pJob->pTasks); @@ -776,7 +770,7 @@ int32_t ctgUpdateMsgCtx(SCtgMsgCtx* pCtx, int32_t reqType, void* out, char* targ int32_t ctgAddMsgCtx(SArray* pCtxs, int32_t reqType, void* out, char* target) { SCtgMsgCtx ctx = {0}; - + ctx.reqType = reqType; ctx.out = out; if (target) { @@ -791,8 +785,7 @@ int32_t ctgAddMsgCtx(SArray* pCtxs, int32_t reqType, void* out, char* target) { return TSDB_CODE_SUCCESS; } - -int32_t ctgGetHashFunction(int8_t hashMethod, tableNameHashFp *fp) { +int32_t ctgGetHashFunction(int8_t hashMethod, tableNameHashFp* fp) { switch (hashMethod) { default: *fp = MurmurHash3_32; @@ -802,29 +795,29 @@ int32_t ctgGetHashFunction(int8_t hashMethod, tableNameHashFp *fp) { return TSDB_CODE_SUCCESS; } -int32_t ctgGenerateVgList(SCatalog *pCtg, SHashObj *vgHash, SArray** pList) { - SHashObj *vgroupHash = NULL; - SVgroupInfo *vgInfo = NULL; - SArray *vgList = NULL; - int32_t code = 0; - int32_t vgNum = taosHashGetSize(vgHash); +int32_t ctgGenerateVgList(SCatalog* pCtg, SHashObj* vgHash, SArray** pList) { + SHashObj* vgroupHash = NULL; + SVgroupInfo* vgInfo = NULL; + SArray* vgList = NULL; + int32_t code = 0; + int32_t vgNum = taosHashGetSize(vgHash); vgList = taosArrayInit(vgNum, sizeof(SVgroupInfo)); if (NULL == vgList) { ctgError("taosArrayInit failed, num:%d", vgNum); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - void *pIter = taosHashIterate(vgHash, NULL); + void* pIter = taosHashIterate(vgHash, NULL); while (pIter) { vgInfo = pIter; if (NULL == taosArrayPush(vgList, vgInfo)) { ctgError("taosArrayPush failed, vgId:%d", vgInfo->vgId); - taosHashCancelIterate(vgHash, pIter); + taosHashCancelIterate(vgHash, pIter); CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); } - + pIter = taosHashIterate(vgHash, pIter); vgInfo = NULL; } @@ -844,12 +837,11 @@ _return: CTG_RET(code); } - -int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName *pTableName, SVgroupInfo *pVgroup) { +int32_t ctgGetVgInfoFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, const SName* pTableName, SVgroupInfo* pVgroup) { int32_t code = 0; - + int32_t vgNum = taosHashGetSize(dbInfo->vgHash); - char db[TSDB_DB_FNAME_LEN] = {0}; + char db[TSDB_DB_FNAME_LEN] = {0}; tNameGetFullDbName(pTableName, db); if (vgNum <= 0) { @@ -857,40 +849,43 @@ int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName CTG_ERR_RET(TSDB_CODE_TSC_DB_NOT_SELECTED); } - SVgroupInfo *vgInfo = NULL; - char tbFullName[TSDB_TABLE_FNAME_LEN]; + SVgroupInfo* vgInfo = NULL; + char tbFullName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(pTableName, tbFullName); - uint32_t hashValue = taosGetTbHashVal(tbFullName, (uint32_t)strlen(tbFullName), dbInfo->hashMethod, dbInfo->hashPrefix, dbInfo->hashSuffix); + uint32_t hashValue = taosGetTbHashVal(tbFullName, (uint32_t)strlen(tbFullName), dbInfo->hashMethod, + dbInfo->hashPrefix, dbInfo->hashSuffix); - void *pIter = taosHashIterate(dbInfo->vgHash, NULL); + void* pIter = taosHashIterate(dbInfo->vgHash, NULL); while (pIter) { vgInfo = pIter; if (hashValue >= vgInfo->hashBegin && hashValue <= vgInfo->hashEnd) { taosHashCancelIterate(dbInfo->vgHash, pIter); break; } - + pIter = taosHashIterate(dbInfo->vgHash, pIter); vgInfo = NULL; } if (NULL == vgInfo) { - ctgError("no hash range found for hash value [%u], db:%s, numOfVgId:%d", hashValue, db, taosHashGetSize(dbInfo->vgHash)); + ctgError("no hash range found for hash value [%u], db:%s, numOfVgId:%d", hashValue, db, + taosHashGetSize(dbInfo->vgHash)); CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); } *pVgroup = *vgInfo; - ctgDebug("Got tb %s hash vgroup, vgId:%d, epNum %d, current %s port %d", tbFullName, vgInfo->vgId, vgInfo->epSet.numOfEps, - vgInfo->epSet.eps[vgInfo->epSet.inUse].fqdn, vgInfo->epSet.eps[vgInfo->epSet.inUse].port); + ctgDebug("Got tb %s hash vgroup, vgId:%d, epNum %d, current %s port %d", tbFullName, vgInfo->vgId, + vgInfo->epSet.numOfEps, vgInfo->epSet.eps[vgInfo->epSet.inUse].fqdn, + vgInfo->epSet.eps[vgInfo->epSet.inUse].port); CTG_RET(code); } -int32_t ctgHashValueComp(void const *lp, void const *rp) { - uint32_t *key = (uint32_t *)lp; - SVgroupInfo *pVg = *(SVgroupInfo **)rp; +int32_t ctgHashValueComp(void const* lp, void const* rp) { + uint32_t* key = (uint32_t*)lp; + SVgroupInfo* pVg = *(SVgroupInfo**)rp; if (*key < pVg->hashBegin) { return -1; @@ -902,8 +897,8 @@ int32_t ctgHashValueComp(void const *lp, void const *rp) { } int ctgVgInfoComp(const void* lp, const void* rp) { - SVgroupInfo *pLeft = *(SVgroupInfo **)lp; - SVgroupInfo *pRight = *(SVgroupInfo **)rp; + SVgroupInfo* pLeft = *(SVgroupInfo**)lp; + SVgroupInfo* pRight = *(SVgroupInfo**)rp; if (pLeft->hashBegin < pRight->hashBegin) { return -1; } else if (pLeft->hashBegin > pRight->hashBegin) { @@ -913,22 +908,22 @@ int ctgVgInfoComp(const void* lp, const void* rp) { return 0; } - -int32_t ctgGetVgInfosFromHashValue(SCatalog *pCtg, SCtgTaskReq* tReq, SDBVgInfo *dbInfo, SCtgTbHashsCtx *pCtx, char* dbFName, SArray* pNames, bool update) { - int32_t code = 0; +int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SCtgTaskReq* tReq, SDBVgInfo* dbInfo, SCtgTbHashsCtx* pCtx, + char* dbFName, SArray* pNames, bool update) { + int32_t code = 0; SCtgTask* pTask = tReq->pTask; - SMetaRes res = {0}; - int32_t vgNum = taosHashGetSize(dbInfo->vgHash); + SMetaRes res = {0}; + int32_t vgNum = taosHashGetSize(dbInfo->vgHash); if (vgNum <= 0) { ctgError("db vgroup cache invalid, db:%s, vgroup number:%d", dbFName, vgNum); CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); } - SVgroupInfo *vgInfo = NULL; - int32_t tbNum = taosArrayGetSize(pNames); + SVgroupInfo* vgInfo = NULL; + int32_t tbNum = taosArrayGetSize(pNames); if (1 == vgNum) { - void *pIter = taosHashIterate(dbInfo->vgHash, NULL); + void* pIter = taosHashIterate(dbInfo->vgHash, NULL); for (int32_t i = 0; i < tbNum; ++i) { vgInfo = taosMemoryMalloc(sizeof(SVgroupInfo)); if (NULL == vgInfo) { @@ -939,11 +934,11 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog *pCtg, SCtgTaskReq* tReq, SDBVgInfo *vgInfo = *(SVgroupInfo*)pIter; ctgDebug("Got tb hash vgroup, vgId:%d, epNum %d, current %s port %d", vgInfo->vgId, vgInfo->epSet.numOfEps, - vgInfo->epSet.eps[vgInfo->epSet.inUse].fqdn, vgInfo->epSet.eps[vgInfo->epSet.inUse].port); + vgInfo->epSet.eps[vgInfo->epSet.inUse].fqdn, vgInfo->epSet.eps[vgInfo->epSet.inUse].port); if (update) { SCtgFetch* pFetch = taosArrayGet(pCtx->pFetchs, tReq->msgIdx); - SMetaRes *pRes = taosArrayGet(pCtx->pResList, pFetch->resIdx + i); + SMetaRes* pRes = taosArrayGet(pCtx->pResList, pFetch->resIdx + i); pRes->pRes = vgInfo; } else { res.pRes = vgInfo; @@ -956,7 +951,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog *pCtg, SCtgTaskReq* tReq, SDBVgInfo } SArray* pVgList = taosArrayInit(vgNum, POINTER_BYTES); - void *pIter = taosHashIterate(dbInfo->vgHash, NULL); + void* pIter = taosHashIterate(dbInfo->vgHash, NULL); while (pIter) { taosArrayPush(pVgList, &pIter); pIter = taosHashIterate(dbInfo->vgHash, pIter); @@ -967,21 +962,23 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog *pCtg, SCtgTaskReq* tReq, SDBVgInfo char tbFullName[TSDB_TABLE_FNAME_LEN]; sprintf(tbFullName, "%s.", dbFName); int32_t offset = strlen(tbFullName); - SName* pName = NULL; + SName* pName = NULL; int32_t tbNameLen = 0; - + for (int32_t i = 0; i < tbNum; ++i) { pName = taosArrayGet(pNames, i); tbNameLen = offset + strlen(pName->tname); strcpy(tbFullName + offset, pName->tname); - uint32_t hashValue = taosGetTbHashVal(tbFullName, (uint32_t)strlen(tbFullName), dbInfo->hashMethod, dbInfo->hashPrefix, dbInfo->hashSuffix); + uint32_t hashValue = taosGetTbHashVal(tbFullName, (uint32_t)strlen(tbFullName), dbInfo->hashMethod, + dbInfo->hashPrefix, dbInfo->hashSuffix); - SVgroupInfo **p = taosArraySearch(pVgList, &hashValue, ctgHashValueComp, TD_EQ); + SVgroupInfo** p = taosArraySearch(pVgList, &hashValue, ctgHashValueComp, TD_EQ); if (NULL == p) { - ctgError("no hash range found for hash value [%u], db:%s, numOfVgId:%d", hashValue, dbFName, taosHashGetSize(dbInfo->vgHash)); + ctgError("no hash range found for hash value [%u], db:%s, numOfVgId:%d", hashValue, dbFName, + taosHashGetSize(dbInfo->vgHash)); taosArrayDestroy(pVgList); CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); } @@ -996,17 +993,18 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog *pCtg, SCtgTaskReq* tReq, SDBVgInfo *pNewVg = *vgInfo; - ctgDebug("Got tb %s hash vgroup, vgId:%d, epNum %d, current %s port %d", tbFullName, vgInfo->vgId, vgInfo->epSet.numOfEps, - vgInfo->epSet.eps[vgInfo->epSet.inUse].fqdn, vgInfo->epSet.eps[vgInfo->epSet.inUse].port); + ctgDebug("Got tb %s hash vgroup, vgId:%d, epNum %d, current %s port %d", tbFullName, vgInfo->vgId, + vgInfo->epSet.numOfEps, vgInfo->epSet.eps[vgInfo->epSet.inUse].fqdn, + vgInfo->epSet.eps[vgInfo->epSet.inUse].port); if (update) { SCtgFetch* pFetch = taosArrayGet(pCtx->pFetchs, tReq->msgIdx); - SMetaRes *pRes = taosArrayGet(pCtx->pResList, pFetch->resIdx + i); + SMetaRes* pRes = taosArrayGet(pCtx->pResList, pFetch->resIdx + i); pRes->pRes = pNewVg; } else { res.pRes = pNewVg; taosArrayPush(pCtx->pResList, &res); - } + } } taosArrayDestroy(pVgList); @@ -1014,11 +1012,10 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog *pCtg, SCtgTaskReq* tReq, SDBVgInfo CTG_RET(code); } - int32_t ctgStbVersionSearchCompare(const void* key1, const void* key2) { - if (*(uint64_t *)key1 < ((SSTableVersion*)key2)->suid) { + if (*(uint64_t*)key1 < ((SSTableVersion*)key2)->suid) { return -1; - } else if (*(uint64_t *)key1 > ((SSTableVersion*)key2)->suid) { + } else if (*(uint64_t*)key1 > ((SSTableVersion*)key2)->suid) { return 1; } else { return 0; @@ -1026,9 +1023,9 @@ int32_t ctgStbVersionSearchCompare(const void* key1, const void* key2) { } int32_t ctgDbVgVersionSearchCompare(const void* key1, const void* key2) { - if (*(int64_t *)key1 < ((SDbVgVersion*)key2)->dbId) { + if (*(int64_t*)key1 < ((SDbVgVersion*)key2)->dbId) { return -1; - } else if (*(int64_t *)key1 > ((SDbVgVersion*)key2)->dbId) { + } else if (*(int64_t*)key1 > ((SDbVgVersion*)key2)->dbId) { return 1; } else { return 0; @@ -1055,10 +1052,7 @@ int32_t ctgDbVgVersionSortCompare(const void* key1, const void* key2) { } } - - - -int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst) { +int32_t ctgCloneVgInfo(SDBVgInfo* src, SDBVgInfo** dst) { *dst = taosMemoryMalloc(sizeof(SDBVgInfo)); if (NULL == *dst) { qError("malloc %d failed", (int32_t)sizeof(SDBVgInfo)); @@ -1075,29 +1069,26 @@ int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - int32_t *vgId = NULL; - void *pIter = taosHashIterate(src->vgHash, NULL); + int32_t* vgId = NULL; + void* pIter = taosHashIterate(src->vgHash, NULL); while (pIter) { vgId = taosHashGetKey(pIter, NULL); - if (taosHashPut((*dst)->vgHash, (void *)vgId, sizeof(int32_t), pIter, sizeof(SVgroupInfo))) { + if (taosHashPut((*dst)->vgHash, (void*)vgId, sizeof(int32_t), pIter, sizeof(SVgroupInfo))) { qError("taosHashPut failed, hashSize:%d", (int32_t)hashSize); taosHashCancelIterate(src->vgHash, pIter); taosHashCleanup((*dst)->vgHash); taosMemoryFreeClear(*dst); CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - + pIter = taosHashIterate(src->vgHash, pIter); } - return TSDB_CODE_SUCCESS; } - - -int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput) { +int32_t ctgCloneMetaOutput(STableMetaOutput* output, STableMetaOutput** pOutput) { *pOutput = taosMemoryMalloc(sizeof(STableMetaOutput)); if (NULL == *pOutput) { qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); @@ -1135,7 +1126,7 @@ int32_t ctgCloneTableIndex(SArray* pIndex, SArray** pRes) { } for (int32_t i = 0; i < num; ++i) { - STableIndexInfo *pInfo = taosArrayGet(pIndex, i); + STableIndexInfo* pInfo = taosArrayGet(pIndex, i); pInfo = taosArrayPush(*pRes, pInfo); pInfo->expr = strdup(pInfo->expr); } @@ -1143,8 +1134,7 @@ int32_t ctgCloneTableIndex(SArray* pIndex, SArray** pRes) { return TSDB_CODE_SUCCESS; } - -int32_t ctgUpdateSendTargetInfo(SMsgSendInfo *pMsgSendInfo, int32_t msgType, char* dbFName, int32_t vgId) { +int32_t ctgUpdateSendTargetInfo(SMsgSendInfo* pMsgSendInfo, int32_t msgType, char* dbFName, int32_t vgId) { if (msgType == TDMT_VND_TABLE_META || msgType == TDMT_VND_TABLE_CFG || msgType == TDMT_VND_BATCH_META) { pMsgSendInfo->target.type = TARGET_TYPE_VNODE; pMsgSendInfo->target.vgId = vgId; @@ -1156,7 +1146,7 @@ int32_t ctgUpdateSendTargetInfo(SMsgSendInfo *pMsgSendInfo, int32_t msgType, cha return TSDB_CODE_SUCCESS; } -int32_t ctgGetTablesReqNum(SArray *pList) { +int32_t ctgGetTablesReqNum(SArray* pList) { if (NULL == pList) { return 0; } @@ -1164,25 +1154,25 @@ int32_t ctgGetTablesReqNum(SArray *pList) { int32_t total = 0; int32_t n = taosArrayGetSize(pList); for (int32_t i = 0; i < n; ++i) { - STablesReq *pReq = taosArrayGet(pList, i); + STablesReq* pReq = taosArrayGet(pList, i); total += taosArrayGetSize(pReq->pTables); } return total; } -int32_t ctgAddFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t *fetchIdx, int32_t resIdx, int32_t flag) { +int32_t ctgAddFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t* fetchIdx, int32_t resIdx, int32_t flag) { if (NULL == (*pFetchs)) { *pFetchs = taosArrayInit(CTG_DEFAULT_FETCH_NUM, sizeof(SCtgFetch)); } - + SCtgFetch fetch = {0}; fetch.dbIdx = dbIdx; fetch.tbIdx = tbIdx; fetch.fetchIdx = (*fetchIdx)++; fetch.resIdx = resIdx; fetch.flag = flag; - + taosArrayPush(*pFetchs, &fetch); return TSDB_CODE_SUCCESS; @@ -1193,13 +1183,9 @@ SName* ctgGetFetchName(SArray* pNames, SCtgFetch* pFetch) { return (SName*)taosArrayGet(pReq->pTables, pFetch->tbIdx); } -static void* ctgCloneDbVgroup(void* pSrc) { - return taosArrayDup((const SArray*)pSrc); -} +static void* ctgCloneDbVgroup(void* pSrc) { return taosArrayDup((const SArray*)pSrc); } -static void ctgFreeDbVgroup(void* p) { - taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); -} +static void ctgFreeDbVgroup(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); } static void* ctgCloneDbCfgInfo(void* pSrc) { SDbCfgInfo* pDst = taosMemoryMalloc(sizeof(SDbCfgInfo)); @@ -1210,9 +1196,7 @@ static void* ctgCloneDbCfgInfo(void* pSrc) { return pDst; } -static void ctgFreeDbCfgInfo(void* p) { - taosMemoryFree(((SMetaRes*)p)->pRes); -} +static void ctgFreeDbCfgInfo(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); } static void* ctgCloneDbInfo(void* pSrc) { SDbInfo* pDst = taosMemoryMalloc(sizeof(SDbInfo)); @@ -1223,9 +1207,7 @@ static void* ctgCloneDbInfo(void* pSrc) { return pDst; } -static void ctgFreeDbInfo(void* p) { - taosMemoryFree(((SMetaRes*)p)->pRes); -} +static void ctgFreeDbInfo(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); } static void* ctgCloneTableMeta(void* pSrc) { STableMeta* pMeta = pSrc; @@ -1238,9 +1220,7 @@ static void* ctgCloneTableMeta(void* pSrc) { return pDst; } -static void ctgFreeTableMeta(void* p) { - taosMemoryFree(((SMetaRes*)p)->pRes); -} +static void ctgFreeTableMeta(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); } static void* ctgCloneVgroupInfo(void* pSrc) { SVgroupInfo* pDst = taosMemoryMalloc(sizeof(SVgroupInfo)); @@ -1251,17 +1231,11 @@ static void* ctgCloneVgroupInfo(void* pSrc) { return pDst; } -static void ctgFreeVgroupInfo(void* p) { - taosMemoryFree(((SMetaRes*)p)->pRes); -} +static void ctgFreeVgroupInfo(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); } -static void* ctgCloneTableIndices(void* pSrc) { - return taosArrayDup((const SArray*)pSrc); -} +static void* ctgCloneTableIndices(void* pSrc) { return taosArrayDup((const SArray*)pSrc); } -static void ctgFreeTableIndices(void* p) { - taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); -} +static void ctgFreeTableIndices(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); } static void* ctgCloneFuncInfo(void* pSrc) { SFuncInfo* pDst = taosMemoryMalloc(sizeof(SFuncInfo)); @@ -1272,9 +1246,7 @@ static void* ctgCloneFuncInfo(void* pSrc) { return pDst; } -static void ctgFreeFuncInfo(void* p) { - taosMemoryFree(((SMetaRes*)p)->pRes); -} +static void ctgFreeFuncInfo(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); } static void* ctgCloneIndexInfo(void* pSrc) { SIndexInfo* pDst = taosMemoryMalloc(sizeof(SIndexInfo)); @@ -1285,9 +1257,7 @@ static void* ctgCloneIndexInfo(void* pSrc) { return pDst; } -static void ctgFreeIndexInfo(void* p) { - taosMemoryFree(((SMetaRes*)p)->pRes); -} +static void ctgFreeIndexInfo(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); } static void* ctgCloneUserAuth(void* pSrc) { bool* pDst = taosMemoryMalloc(sizeof(bool)); @@ -1298,17 +1268,11 @@ static void* ctgCloneUserAuth(void* pSrc) { return pDst; } -static void ctgFreeUserAuth(void* p) { - taosMemoryFree(((SMetaRes*)p)->pRes); -} +static void ctgFreeUserAuth(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); } -static void* ctgCloneQnodeList(void* pSrc) { - return taosArrayDup((const SArray*)pSrc); -} +static void* ctgCloneQnodeList(void* pSrc) { return taosArrayDup((const SArray*)pSrc); } -static void ctgFreeQnodeList(void* p) { - taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); -} +static void ctgFreeQnodeList(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); } static void* ctgCloneTableCfg(void* pSrc) { STableCfg* pDst = taosMemoryMalloc(sizeof(STableCfg)); @@ -1319,17 +1283,11 @@ static void* ctgCloneTableCfg(void* pSrc) { return pDst; } -static void ctgFreeTableCfg(void* p) { - taosMemoryFree(((SMetaRes*)p)->pRes); -} +static void ctgFreeTableCfg(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); } -static void* ctgCloneDnodeList(void* pSrc) { - return taosArrayDup((const SArray*)pSrc); -} +static void* ctgCloneDnodeList(void* pSrc) { return taosArrayDup((const SArray*)pSrc); } -static void ctgFreeDnodeList(void* p) { - taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); -} +static void ctgFreeDnodeList(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); } static int32_t ctgCloneMetaDataArray(SArray* pSrc, FCopy copyFunc, SArray** pDst) { if (NULL == pSrc) { @@ -1343,7 +1301,7 @@ static int32_t ctgCloneMetaDataArray(SArray* pSrc, FCopy copyFunc, SArray** pDst } for (int32_t i = 0; i < size; ++i) { SMetaRes* pRes = taosArrayGet(pSrc, i); - SMetaRes res = {.code = pRes->code, .pRes = copyFunc(pRes->pRes)}; + SMetaRes res = {.code = pRes->code, .pRes = copyFunc(pRes->pRes)}; if (NULL == res.pRes) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1412,8 +1370,8 @@ void catalogFreeMetaData(SMetaData* pData) { taosArrayDestroyEx(pData->pDbInfo, ctgFreeDbInfo); taosArrayDestroyEx(pData->pTableMeta, ctgFreeTableMeta); taosArrayDestroyEx(pData->pTableHash, ctgFreeVgroupInfo); - taosArrayDestroyEx(pData->pTableIndex, ctgFreeTableIndices); - taosArrayDestroyEx(pData->pUdfList, ctgFreeFuncInfo); + taosArrayDestroyEx(pData->pTableIndex, ctgFreeTableIndices); + taosArrayDestroyEx(pData->pUdfList, ctgFreeFuncInfo); taosArrayDestroyEx(pData->pIndex, ctgFreeIndexInfo); taosArrayDestroyEx(pData->pUser, ctgFreeUserAuth); taosArrayDestroyEx(pData->pQnodeList, ctgFreeQnodeList); diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index c01c269e643b2a1f2a44817a74807c20db718d4b..bb4fd04aac51564144ce8c25d43662b8746aaa62 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -27,20 +27,20 @@ #ifdef WINDOWS #define TD_USE_WINSOCK #endif -#include "os.h" -#include "tglobal.h" #include "catalog.h" #include "catalogInt.h" +#include "os.h" #include "stub.h" #include "taos.h" #include "tdatablock.h" #include "tdef.h" +#include "tglobal.h" #include "trpc.h" #include "tvariant.h" namespace { -extern "C" int32_t ctgdGetClusterCacheNum(struct SCatalog* pCatalog, int32_t type); +extern "C" int32_t ctgdGetClusterCacheNum(struct SCatalog *pCatalog, int32_t type); extern "C" int32_t ctgdEnableDebug(char *option); extern "C" int32_t ctgdGetStatNum(char *option, void *res); @@ -49,7 +49,7 @@ void ctgTestSetRspCTableMeta(); void ctgTestSetRspSTableMeta(); void ctgTestSetRspMultiSTableMeta(); -//extern "C" SCatalogMgmt gCtgMgmt; +// extern "C" SCatalogMgmt gCtgMgmt; enum { CTGT_RSP_VGINFO = 1, @@ -131,7 +131,7 @@ void ctgTestInitLogFile() { if (!ctgTestEnableLog) { return; } - + const char *defaultLogFileNamePrefix = "taoslog"; const int32_t maxLogFileNum = 10; @@ -142,7 +142,7 @@ void ctgTestInitLogFile() { ctgdEnableDebug("api"); ctgdEnableDebug("meta"); ctgdEnableDebug("cache"); - + if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) { printf("failed to open log file in directory:%s\n", tsLogDir); } @@ -153,11 +153,11 @@ int32_t ctgTestGetVgNumFromVgVersion(int32_t vgVersion) { } void ctgTestBuildCTableMetaOutput(STableMetaOutput *output) { - SName cn = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName cn = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(cn.dbname, "db1"); strcpy(cn.tname, ctgTestCTablename); - SName sn = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName sn = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(sn.dbname, "db1"); strcpy(sn.tname, ctgTestSTablename); @@ -175,7 +175,8 @@ void ctgTestBuildCTableMetaOutput(STableMetaOutput *output) { output->ctbMeta.uid = 3; output->ctbMeta.suid = 2; - output->tbMeta = (STableMeta *)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (ctgTestColNum + ctgTestColNum)); + output->tbMeta = + (STableMeta *)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (ctgTestColNum + ctgTestColNum)); output->tbMeta->vgId = 9; output->tbMeta->tableType = TSDB_SUPER_TABLE; output->tbMeta->uid = 2; @@ -211,7 +212,7 @@ void ctgTestBuildDBVgroup(SDBVgInfo **pdbVgroup) { static int32_t vgVersion = ctgTestVgVersion + 1; int32_t vgNum = 0; SVgroupInfo vgInfo = {0}; - SDBVgInfo *dbVgroup = (SDBVgInfo *)taosMemoryCalloc(1, sizeof(SDBVgInfo)); + SDBVgInfo *dbVgroup = (SDBVgInfo *)taosMemoryCalloc(1, sizeof(SDBVgInfo)); dbVgroup->vgVersion = vgVersion++; @@ -256,7 +257,7 @@ void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) { rspMsg->suid = ctgTestSuid + 1; rspMsg->tuid = ctgTestSuid + 1; rspMsg->vgId = 1; - + rspMsg->pSchemas = (SSchema *)taosMemoryCalloc(rspMsg->numOfTags + rspMsg->numOfColumns, sizeof(SSchema)); SSchema *s = NULL; @@ -364,7 +365,6 @@ void ctgTestRspTableMetaNotExist(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, S pRsp->code = CTG_ERR_CODE_TABLE_NOT_EXIST; } - void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { STableMetaRsp metaRsp = {0}; strcpy(metaRsp.dbFName, ctgTestDbname); @@ -573,8 +573,8 @@ void ctgTestSetRspDbVgroups() { stub.set(rpcSendRecv, ctgTestRspDbVgroups); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendRecv", result); #endif #ifdef LINUX @@ -593,8 +593,8 @@ void ctgTestSetRspTableMeta() { stub.set(rpcSendRecv, ctgTestRspTableMeta); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendRecv", result); #endif #ifdef LINUX @@ -613,8 +613,8 @@ void ctgTestSetRspCTableMeta() { stub.set(rpcSendRecv, ctgTestRspCTableMeta); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendRecv", result); #endif #ifdef LINUX @@ -633,8 +633,8 @@ void ctgTestSetRspSTableMeta() { stub.set(rpcSendRecv, ctgTestRspSTableMeta); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendRecv", result); #endif #ifdef LINUX @@ -653,8 +653,8 @@ void ctgTestSetRspMultiSTableMeta() { stub.set(rpcSendRecv, ctgTestRspMultiSTableMeta); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendRecv", result); #endif #ifdef LINUX @@ -673,8 +673,8 @@ void ctgTestSetRspByIdx() { stub.set(rpcSendRecv, ctgTestRspByIdx); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendRecv", result); #endif #ifdef LINUX @@ -688,14 +688,13 @@ void ctgTestSetRspByIdx() { } } - void ctgTestSetRspDbVgroupsAndNormalMeta() { static Stub stub; stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndNormalMeta); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendRecv", result); #endif #ifdef LINUX @@ -714,8 +713,8 @@ void ctgTestSetRspDbVgroupsAndChildMeta() { stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndChildMeta); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendRecv", result); #endif #ifdef LINUX @@ -734,8 +733,8 @@ void ctgTestSetRspDbVgroupsAndSuperMeta() { stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndSuperMeta); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendRecv", result); #endif #ifdef LINUX @@ -754,8 +753,8 @@ void ctgTestSetRspDbVgroupsAndMultiSuperMeta() { stub.set(rpcSendRecv, ctgTestRspDbVgroupsAndMultiSuperMeta); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendRecv", result); #endif #ifdef LINUX @@ -772,11 +771,11 @@ void ctgTestSetRspDbVgroupsAndMultiSuperMeta() { } // namespace void *ctgTestGetDbVgroupThread(void *param) { - struct SCatalog *pCtg = (struct SCatalog *)param; - int32_t code = 0; + struct SCatalog *pCtg = (struct SCatalog *)param; + int32_t code = 0; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SArray *vgList = NULL; - int32_t n = 0; + SArray *vgList = NULL; + int32_t n = 0; while (!ctgTestStop) { code = catalogGetDBVgInfo(pCtg, mockPointer, ctgTestDbname, &vgList); @@ -826,7 +825,7 @@ void *ctgTestSetSameDbVgroupThread(void *param) { void *ctgTestSetDiffDbVgroupThread(void *param) { struct SCatalog *pCtg = (struct SCatalog *)param; int32_t code = 0; - SDBVgInfo *dbVgroup = NULL; + SDBVgInfo *dbVgroup = NULL; int32_t n = 0; while (!ctgTestStop) { @@ -854,7 +853,7 @@ void *ctgTestGetCtableMetaThread(void *param) { STableMeta *tbMeta = NULL; bool inCache = false; - SName cn = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName cn = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(cn.dbname, "db1"); strcpy(cn.tname, ctgTestCTablename); @@ -883,14 +882,14 @@ void *ctgTestGetCtableMetaThread(void *param) { } void *ctgTestSetCtableMetaThread(void *param) { - struct SCatalog *pCtg = (struct SCatalog *)param; - int32_t code = 0; - SDBVgInfo dbVgroup = {0}; - int32_t n = 0; + struct SCatalog *pCtg = (struct SCatalog *)param; + int32_t code = 0; + SDBVgInfo dbVgroup = {0}; + int32_t n = 0; STableMetaOutput *output = NULL; SCtgCacheOperation operation = {0}; - + operation.opId = CTG_OP_UPDATE_TB_META; while (!ctgTestStop) { @@ -920,11 +919,10 @@ void *ctgTestSetCtableMetaThread(void *param) { #if 1 - TEST(tableMeta, normalTable) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; + SVgroupInfo vgInfo = {0}; ctgTestInitLogFile(); @@ -940,7 +938,7 @@ TEST(tableMeta, normalTable) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); @@ -952,7 +950,7 @@ TEST(tableMeta, normalTable) { while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) { taosMsleep(50); } - + ctgTestSetRspTableMeta(); STableMeta *tableMeta = NULL; @@ -977,7 +975,6 @@ TEST(tableMeta, normalTable) { } } - tableMeta = NULL; code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta); ASSERT_EQ(code, 0); @@ -990,10 +987,10 @@ TEST(tableMeta, normalTable) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - SDbVgVersion *dbs = NULL; + SDbVgVersion *dbs = NULL; SSTableVersion *stb = NULL; - uint32_t dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0; - int32_t i = 0; + uint32_t dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0; + int32_t i = 0; while (i < 5) { ++i; code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum); @@ -1030,9 +1027,9 @@ TEST(tableMeta, normalTable) { } TEST(tableMeta, childTableCase) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; + SVgroupInfo vgInfo = {0}; ctgTestInitLogFile(); @@ -1047,7 +1044,7 @@ TEST(tableMeta, childTableCase) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestCTablename); @@ -1072,7 +1069,6 @@ TEST(tableMeta, childTableCase) { } } - tableMeta = NULL; code = catalogGetTableMeta(pCtg, mockPointer, &n, &tableMeta); ASSERT_EQ(code, 0); @@ -1099,10 +1095,10 @@ TEST(tableMeta, childTableCase) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - SDbVgVersion *dbs = NULL; + SDbVgVersion *dbs = NULL; SSTableVersion *stb = NULL; - uint32_t dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0; - int32_t i = 0; + uint32_t dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0; + int32_t i = 0; while (i < 5) { ++i; code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum); @@ -1139,9 +1135,9 @@ TEST(tableMeta, childTableCase) { } TEST(tableMeta, superTableCase) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; + SVgroupInfo vgInfo = {0}; ctgTestSetRspDbVgroupsAndSuperMeta(); @@ -1154,7 +1150,7 @@ TEST(tableMeta, superTableCase) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestSTablename); @@ -1181,7 +1177,6 @@ TEST(tableMeta, superTableCase) { } } - ctgTestSetRspCTableMeta(); tableMeta = NULL; @@ -1208,7 +1203,6 @@ TEST(tableMeta, superTableCase) { } } - tableMeta = NULL; code = catalogRefreshGetTableMeta(pCtg, mockPointer, &n, &tableMeta, 0); ASSERT_EQ(code, 0); @@ -1221,10 +1215,10 @@ TEST(tableMeta, superTableCase) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); - SDbVgVersion *dbs = NULL; + SDbVgVersion *dbs = NULL; SSTableVersion *stb = NULL; - uint32_t dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0; - int32_t i = 0; + uint32_t dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0; + int32_t i = 0; while (i < 5) { ++i; code = catalogGetExpiredDBs(pCtg, &dbs, &dbNum); @@ -1262,9 +1256,9 @@ TEST(tableMeta, superTableCase) { } TEST(tableMeta, rmStbMeta) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; + SVgroupInfo vgInfo = {0}; ctgTestInitLogFile(); @@ -1279,7 +1273,7 @@ TEST(tableMeta, rmStbMeta) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestSTablename); @@ -1306,7 +1300,6 @@ TEST(tableMeta, rmStbMeta) { } } - code = catalogRemoveStbMeta(pCtg, "1.db1", ctgTestDbId, ctgTestSTablename, ctgTestSuid - 1); ASSERT_EQ(code, 0); @@ -1320,7 +1313,6 @@ TEST(tableMeta, rmStbMeta) { } } - ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM), 1); ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), 0); ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 0); @@ -1332,9 +1324,9 @@ TEST(tableMeta, rmStbMeta) { } TEST(tableMeta, updateStbMeta) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; + SVgroupInfo vgInfo = {0}; ctgTestInitLogFile(); @@ -1349,7 +1341,7 @@ TEST(tableMeta, updateStbMeta) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestSTablename); @@ -1376,7 +1368,6 @@ TEST(tableMeta, updateStbMeta) { } } - taosMemoryFreeClear(tableMeta); STableMetaRsp rsp = {0}; @@ -1422,10 +1413,10 @@ TEST(tableMeta, updateStbMeta) { } TEST(refreshGetMeta, normal2normal) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; - SArray *vgList = NULL; + SVgroupInfo vgInfo = {0}; + SArray *vgList = NULL; ctgTestInitLogFile(); @@ -1434,7 +1425,7 @@ TEST(refreshGetMeta, normal2normal) { ctgTestRspFunc[0] = CTGT_RSP_VGINFO; ctgTestRspFunc[1] = CTGT_RSP_TBMETA; ctgTestRspFunc[2] = CTGT_RSP_TBMETA; - + ctgTestSetRspByIdx(); initQueryModuleMsgHandle(); @@ -1447,7 +1438,7 @@ TEST(refreshGetMeta, normal2normal) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); @@ -1470,7 +1461,7 @@ TEST(refreshGetMeta, normal2normal) { ASSERT_EQ(code, 0); ASSERT_EQ(tableMeta->vgId, 8); ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE); - ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1); + ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1); ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); @@ -1487,7 +1478,7 @@ TEST(refreshGetMeta, normal2normal) { ASSERT_EQ(code, 0); ASSERT_EQ(tableMeta->vgId, 8); ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE); - ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1); + ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1); ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); @@ -1501,10 +1492,10 @@ TEST(refreshGetMeta, normal2normal) { } TEST(refreshGetMeta, normal2notexist) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; - SArray *vgList = NULL; + SVgroupInfo vgInfo = {0}; + SArray *vgList = NULL; ctgTestInitLogFile(); @@ -1513,7 +1504,7 @@ TEST(refreshGetMeta, normal2notexist) { ctgTestRspFunc[0] = CTGT_RSP_VGINFO; ctgTestRspFunc[1] = CTGT_RSP_TBMETA; ctgTestRspFunc[2] = CTGT_RSP_TBMETA_NOT_EXIST; - + ctgTestSetRspByIdx(); initQueryModuleMsgHandle(); @@ -1526,7 +1517,7 @@ TEST(refreshGetMeta, normal2notexist) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); @@ -1549,7 +1540,7 @@ TEST(refreshGetMeta, normal2notexist) { ASSERT_EQ(code, 0); ASSERT_EQ(tableMeta->vgId, 8); ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE); - ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1); + ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1); ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); @@ -1570,12 +1561,11 @@ TEST(refreshGetMeta, normal2notexist) { memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } - TEST(refreshGetMeta, normal2child) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; - SArray *vgList = NULL; + SVgroupInfo vgInfo = {0}; + SArray *vgList = NULL; ctgTestInitLogFile(); @@ -1585,7 +1575,7 @@ TEST(refreshGetMeta, normal2child) { ctgTestRspFunc[1] = CTGT_RSP_TBMETA; ctgTestRspFunc[2] = CTGT_RSP_CTBMETA; ctgTestRspFunc[3] = CTGT_RSP_STBMETA; - + ctgTestSetRspByIdx(); initQueryModuleMsgHandle(); @@ -1598,7 +1588,7 @@ TEST(refreshGetMeta, normal2child) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); ctgTestCurrentCTableName = ctgTestTablename; @@ -1623,7 +1613,7 @@ TEST(refreshGetMeta, normal2child) { ASSERT_EQ(code, 0); ASSERT_EQ(tableMeta->vgId, 8); ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE); - ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1); + ASSERT_EQ(tableMeta->uid, ctgTestNormalTblUid - 1); ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); @@ -1655,10 +1645,10 @@ TEST(refreshGetMeta, normal2child) { } TEST(refreshGetMeta, stable2child) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; - SArray *vgList = NULL; + SVgroupInfo vgInfo = {0}; + SArray *vgList = NULL; ctgTestInitLogFile(); @@ -1669,7 +1659,7 @@ TEST(refreshGetMeta, stable2child) { ctgTestRspFunc[2] = CTGT_RSP_STBMETA; ctgTestRspFunc[3] = CTGT_RSP_CTBMETA; ctgTestRspFunc[4] = CTGT_RSP_STBMETA; - + ctgTestSetRspByIdx(); initQueryModuleMsgHandle(); @@ -1682,7 +1672,7 @@ TEST(refreshGetMeta, stable2child) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); ctgTestCurrentSTableName = ctgTestTablename; @@ -1741,10 +1731,10 @@ TEST(refreshGetMeta, stable2child) { } TEST(refreshGetMeta, stable2stable) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; - SArray *vgList = NULL; + SVgroupInfo vgInfo = {0}; + SArray *vgList = NULL; ctgTestInitLogFile(); @@ -1755,7 +1745,7 @@ TEST(refreshGetMeta, stable2stable) { ctgTestRspFunc[2] = CTGT_RSP_STBMETA; ctgTestRspFunc[3] = CTGT_RSP_STBMETA; ctgTestRspFunc[4] = CTGT_RSP_STBMETA; - + ctgTestSetRspByIdx(); initQueryModuleMsgHandle(); @@ -1768,7 +1758,7 @@ TEST(refreshGetMeta, stable2stable) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); ctgTestCurrentSTableName = ctgTestTablename; @@ -1826,12 +1816,11 @@ TEST(refreshGetMeta, stable2stable) { ctgTestCurrentSTableName = NULL; } - TEST(refreshGetMeta, child2stable) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; - SArray *vgList = NULL; + SVgroupInfo vgInfo = {0}; + SArray *vgList = NULL; ctgTestInitLogFile(); @@ -1842,7 +1831,7 @@ TEST(refreshGetMeta, child2stable) { ctgTestRspFunc[2] = CTGT_RSP_STBMETA; ctgTestRspFunc[3] = CTGT_RSP_STBMETA; ctgTestRspFunc[4] = CTGT_RSP_STBMETA; - + ctgTestSetRspByIdx(); initQueryModuleMsgHandle(); @@ -1855,7 +1844,7 @@ TEST(refreshGetMeta, child2stable) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); ctgTestCurrentCTableName = ctgTestTablename; @@ -1913,12 +1902,11 @@ TEST(refreshGetMeta, child2stable) { ctgTestCurrentSTableName = NULL; } - TEST(tableDistVgroup, normalTable) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo *vgInfo = NULL; - SArray *vgList = NULL; + SVgroupInfo *vgInfo = NULL; + SArray *vgList = NULL; ctgTestInitLogFile(); @@ -1927,7 +1915,7 @@ TEST(tableDistVgroup, normalTable) { ctgTestRspFunc[0] = CTGT_RSP_VGINFO; ctgTestRspFunc[1] = CTGT_RSP_TBMETA; ctgTestRspFunc[2] = CTGT_RSP_VGINFO; - + ctgTestSetRspByIdx(); initQueryModuleMsgHandle(); @@ -1940,7 +1928,7 @@ TEST(tableDistVgroup, normalTable) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); @@ -1956,10 +1944,10 @@ TEST(tableDistVgroup, normalTable) { } TEST(tableDistVgroup, childTableCase) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo *vgInfo = NULL; - SArray *vgList = NULL; + SVgroupInfo *vgInfo = NULL; + SArray *vgList = NULL; ctgTestInitLogFile(); @@ -1969,7 +1957,7 @@ TEST(tableDistVgroup, childTableCase) { ctgTestRspFunc[1] = CTGT_RSP_CTBMETA; ctgTestRspFunc[2] = CTGT_RSP_STBMETA; ctgTestRspFunc[3] = CTGT_RSP_VGINFO; - + ctgTestSetRspByIdx(); initQueryModuleMsgHandle(); @@ -1982,7 +1970,7 @@ TEST(tableDistVgroup, childTableCase) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestCTablename); @@ -1998,10 +1986,10 @@ TEST(tableDistVgroup, childTableCase) { } TEST(tableDistVgroup, superTableCase) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo *vgInfo = NULL; - SArray *vgList = NULL; + SVgroupInfo *vgInfo = NULL; + SArray *vgList = NULL; ctgTestInitLogFile(); @@ -2011,10 +1999,8 @@ TEST(tableDistVgroup, superTableCase) { ctgTestRspFunc[1] = CTGT_RSP_STBMETA; ctgTestRspFunc[2] = CTGT_RSP_STBMETA; ctgTestRspFunc[3] = CTGT_RSP_VGINFO; - - ctgTestSetRspByIdx(); - + ctgTestSetRspByIdx(); initQueryModuleMsgHandle(); @@ -2025,7 +2011,7 @@ TEST(tableDistVgroup, superTableCase) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestSTablename); @@ -2047,12 +2033,12 @@ TEST(tableDistVgroup, superTableCase) { } TEST(dbVgroup, getSetDbVgroupCase) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; - SVgroupInfo *pvgInfo = NULL; - SDBVgInfo *dbVgroup = NULL; - SArray *vgList = NULL; + SVgroupInfo vgInfo = {0}; + SVgroupInfo *pvgInfo = NULL; + SDBVgInfo *dbVgroup = NULL; + SArray *vgList = NULL; ctgTestInitLogFile(); @@ -2061,10 +2047,8 @@ TEST(dbVgroup, getSetDbVgroupCase) { ctgTestRspFunc[0] = CTGT_RSP_VGINFO; ctgTestRspFunc[1] = CTGT_RSP_TBMETA; - ctgTestSetRspByIdx(); - initQueryModuleMsgHandle(); // sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet); @@ -2075,7 +2059,7 @@ TEST(dbVgroup, getSetDbVgroupCase) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); @@ -2119,7 +2103,6 @@ TEST(dbVgroup, getSetDbVgroupCase) { } } - code = catalogGetTableHashVgroup(pCtg, mockPointer, &n, &vgInfo); ASSERT_EQ(code, 0); ASSERT_EQ(vgInfo.vgId, 7); @@ -2138,12 +2121,12 @@ TEST(dbVgroup, getSetDbVgroupCase) { } TEST(multiThread, getSetRmSameDbVgroup) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; - SVgroupInfo *pvgInfo = NULL; - SDBVgInfo dbVgroup = {0}; - SArray *vgList = NULL; + SVgroupInfo vgInfo = {0}; + SVgroupInfo *pvgInfo = NULL; + SDBVgInfo dbVgroup = {0}; + SArray *vgList = NULL; ctgTestStop = false; ctgTestInitLogFile(); @@ -2160,7 +2143,7 @@ TEST(multiThread, getSetRmSameDbVgroup) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); @@ -2190,12 +2173,12 @@ TEST(multiThread, getSetRmSameDbVgroup) { } TEST(multiThread, getSetRmDiffDbVgroup) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; - SVgroupInfo *pvgInfo = NULL; - SDBVgInfo dbVgroup = {0}; - SArray *vgList = NULL; + SVgroupInfo vgInfo = {0}; + SVgroupInfo *pvgInfo = NULL; + SDBVgInfo dbVgroup = {0}; + SArray *vgList = NULL; ctgTestStop = false; ctgTestInitLogFile(); @@ -2212,7 +2195,7 @@ TEST(multiThread, getSetRmDiffDbVgroup) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); @@ -2242,12 +2225,12 @@ TEST(multiThread, getSetRmDiffDbVgroup) { } TEST(multiThread, ctableMeta) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; - SVgroupInfo *pvgInfo = NULL; - SDBVgInfo dbVgroup = {0}; - SArray *vgList = NULL; + SVgroupInfo vgInfo = {0}; + SVgroupInfo *pvgInfo = NULL; + SDBVgInfo dbVgroup = {0}; + SArray *vgList = NULL; ctgTestStop = false; ctgTestInitLogFile(); @@ -2264,7 +2247,7 @@ TEST(multiThread, ctableMeta) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); strcpy(n.tname, ctgTestTablename); @@ -2293,16 +2276,16 @@ TEST(multiThread, ctableMeta) { } TEST(rentTest, allRent) { - struct SCatalog *pCtg = NULL; + struct SCatalog *pCtg = NULL; SRequestConnInfo *mockPointer = (SRequestConnInfo *)0x1; - SVgroupInfo vgInfo = {0}; - SVgroupInfo *pvgInfo = NULL; - SDBVgInfo dbVgroup = {0}; - SArray *vgList = NULL; + SVgroupInfo vgInfo = {0}; + SVgroupInfo *pvgInfo = NULL; + SDBVgInfo dbVgroup = {0}; + SArray *vgList = NULL; ctgTestStop = false; - SDbVgVersion *dbs = NULL; + SDbVgVersion *dbs = NULL; SSTableVersion *stable = NULL; - uint32_t num = 0; + uint32_t num = 0; ctgTestInitLogFile(); @@ -2316,7 +2299,7 @@ TEST(rentTest, allRent) { code = catalogGetHandle(ctgTestClusterId, &pCtg); ASSERT_EQ(code, 0); - SName n = { TSDB_TABLE_NAME_T, 1, {0}, {0} }; + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; strcpy(n.dbname, "db1"); for (int32_t i = 1; i <= 10; ++i) { diff --git a/source/libs/command/test/commandTest.cpp b/source/libs/command/test/commandTest.cpp index 59118c501ae8ec9225d310760d71973b22036ce7..8154ee31174cb8cc769abe2efaecabb5f02257fb 100644 --- a/source/libs/command/test/commandTest.cpp +++ b/source/libs/command/test/commandTest.cpp @@ -16,6 +16,6 @@ #include int main(int argc, char* argv[]) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/source/libs/executor/inc/dataSinkInt.h b/source/libs/executor/inc/dataSinkInt.h index 9426c99a0fc4fa55429fb1541f80be3efe0ef62f..220e9c0b6ced01edce3a36a4297f2c76151a4092 100644 --- a/source/libs/executor/inc/dataSinkInt.h +++ b/source/libs/executor/inc/dataSinkInt.h @@ -20,16 +20,16 @@ extern "C" { #endif -#include "tcommon.h" #include "dataSinkMgt.h" #include "plannodes.h" +#include "tcommon.h" struct SDataSink; struct SDataSinkHandle; typedef struct SDataSinkManager { SDataSinkMgtCfg cfg; - TdThreadMutex mutex; + TdThreadMutex mutex; } SDataSinkManager; typedef int32_t (*FPutDataBlock)(struct SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue); @@ -40,17 +40,19 @@ typedef int32_t (*FDestroyDataSinker)(struct SDataSinkHandle* pHandle); typedef int32_t (*FGetCacheSize)(struct SDataSinkHandle* pHandle, uint64_t* size); typedef struct SDataSinkHandle { - FPutDataBlock fPut; - FEndPut fEndPut; - FGetDataLength fGetLen; - FGetDataBlock fGetData; + FPutDataBlock fPut; + FEndPut fEndPut; + FGetDataLength fGetLen; + FGetDataBlock fGetData; FDestroyDataSinker fDestroy; - FGetCacheSize fGetCacheSize; + FGetCacheSize fGetCacheSize; } SDataSinkHandle; int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle); -int32_t createDataDeleter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void *pParam); -int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void *pParam); +int32_t createDataDeleter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, + void* pParam); +int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, + void* pParam); #ifdef __cplusplus } diff --git a/source/libs/executor/inc/executorInt.h b/source/libs/executor/inc/executorInt.h index c8546a1afef5a12ca4bf83e4a174dfaa6cb49bd8..d22a7460bb17f53e77c56ec33c177ab466919b47 100644 --- a/source/libs/executor/inc/executorInt.h +++ b/source/libs/executor/inc/executorInt.h @@ -23,10 +23,10 @@ extern "C" { extern int32_t exchangeObjRefPool; typedef struct { - char* pData; - bool isNull; - int16_t type; - int32_t bytes; + char* pData; + bool isNull; + int16_t type; + int32_t bytes; } SGroupKeys, SStateKeys; uint64_t calcGroupId(char* pData, int32_t len); diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index f9e47f92fecaea8e7cbf5fa0b4cecaa2118c7971..fc996a60033278cc8460c187f73d58e7b7cda441 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -212,6 +212,7 @@ typedef struct SExprSupp { int32_t numOfExprs; // the number of scalar expression in group operator SqlFunctionCtx* pCtx; int32_t* rowEntryInfoOffset; // offset value for each row result cell info + SFilterInfo* pFilterInfo; } SExprSupp; typedef struct SOperatorInfo { @@ -479,6 +480,7 @@ typedef struct SStreamScanInfo { SExprInfo* pPseudoExpr; int32_t numOfPseudoExpr; SExprSupp tbnameCalSup; + SExprSupp tagCalSup; int32_t primaryTsIndex; // primary time stamp slot id SReadHandle readHandle; SInterval interval; // if the upstream is an interval operator, the interval info is also kept here. @@ -775,6 +777,7 @@ typedef struct SStreamPartitionOperatorInfo { SPartitionBySupporter partitionSup; SExprSupp scalarSup; SExprSupp tbnameCalSup; + SExprSupp tagCalSup; SHashObj* pPartitions; void* parIte; SSDataBlock* pInputDataBlock; @@ -924,7 +927,7 @@ int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scan int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz); void doSetOperatorCompleted(SOperatorInfo* pOperator); -void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, const SArray* pColMatchInfo); +void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, const SArray* pColMatchInfo, SFilterInfo* pFilterInfo); int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, SSDataBlock* pBlock, const char* idStr); diff --git a/source/libs/executor/inc/tlinearhash.h b/source/libs/executor/inc/tlinearhash.h index a4190582166d565d42faf062c78b87c65ccdf644..5ec1ae54e0f211b8bdf15e1a83f61aa2268a6498 100644 --- a/source/libs/executor/inc/tlinearhash.h +++ b/source/libs/executor/inc/tlinearhash.h @@ -24,7 +24,7 @@ extern "C" { enum { LINEAR_HASH_STATIS = 0x1, - LINEAR_HASH_DATA = 0x2, + LINEAR_HASH_DATA = 0x2, }; typedef struct SLHashObj SLHashObj; @@ -32,11 +32,11 @@ typedef struct SLHashObj SLHashObj; SLHashObj* tHashInit(int32_t inMemPages, int32_t pageSize, _hash_fn_t fn, int32_t numOfTuplePerPage); void* tHashCleanup(SLHashObj* pHashObj); -int32_t tHashPut(SLHashObj* pHashObj, const void *key, size_t keyLen, void *data, size_t size); -char* tHashGet(SLHashObj* pHashObj, const void *key, size_t keyLen); -int32_t tHashRemove(SLHashObj* pHashObj, const void *key, size_t keyLen); +int32_t tHashPut(SLHashObj* pHashObj, const void* key, size_t keyLen, void* data, size_t size); +char* tHashGet(SLHashObj* pHashObj, const void* key, size_t keyLen); +int32_t tHashRemove(SLHashObj* pHashObj, const void* key, size_t keyLen); -void tHashPrint(const SLHashObj* pHashObj, int32_t type); +void tHashPrint(const SLHashObj* pHashObj, int32_t type); #ifdef __cplusplus } diff --git a/source/libs/executor/inc/tsimplehash.h b/source/libs/executor/inc/tsimplehash.h index 27191e3b7e674df4dcec9dabc7b8cc6fbb35f9f2..7344c3426133758aac51d94e4678bc9367163580 100644 --- a/source/libs/executor/inc/tsimplehash.h +++ b/source/libs/executor/inc/tsimplehash.h @@ -112,7 +112,7 @@ void tSimpleHashCleanup(SSHashObj *pHashObj); size_t tSimpleHashGetMemSize(const SSHashObj *pHashObj); #pragma pack(push, 4) -typedef struct SHNode{ +typedef struct SHNode { struct SHNode *next; uint32_t keyLen : 20; uint32_t dataLen : 12; diff --git a/source/libs/executor/inc/tsort.h b/source/libs/executor/inc/tsort.h index 972f4469e47cef127a0137d3d360cf98f7657976..5591299d308acc0277a31f351e743d4dacf4e60f 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -20,8 +20,8 @@ extern "C" { #endif -#include "tcommon.h" #include "os.h" +#include "tcommon.h" enum { SORT_MULTISOURCE_MERGE = 0x1, @@ -31,29 +31,29 @@ enum { typedef struct SMultiMergeSource { int32_t type; int32_t rowIndex; - SSDataBlock *pBlock; + SSDataBlock* pBlock; } SMultiMergeSource; typedef struct SSortSource { SMultiMergeSource src; - union{ - struct{ - SArray* pageIdList; - int32_t pageIndex; + union { + struct { + SArray* pageIdList; + int32_t pageIndex; }; - void *param; + void* param; }; } SSortSource; typedef struct SMsortComparParam { - void **pSources; - int32_t numOfSources; - SArray *orderInfo; // SArray - bool cmpGroupId; + void** pSources; + int32_t numOfSources; + SArray* orderInfo; // SArray + bool cmpGroupId; } SMsortComparParam; -typedef struct SSortHandle SSortHandle; +typedef struct SSortHandle SSortHandle; typedef struct STupleHandle STupleHandle; typedef SSDataBlock* (*_sort_fetch_block_fn_t)(void* param); @@ -64,7 +64,8 @@ typedef int32_t (*_sort_merge_compar_fn_t)(const void* p1, const void* p2, void* * @param type * @return */ -SSortHandle* tsortCreateSortHandle(SArray* pOrderInfo, int32_t type, int32_t pageSize, int32_t numOfPages, SSDataBlock* pBlock, const char* idstr); +SSortHandle* tsortCreateSortHandle(SArray* pOrderInfo, int32_t type, int32_t pageSize, int32_t numOfPages, + SSDataBlock* pBlock, const char* idstr); /** * @@ -90,7 +91,8 @@ int32_t tsortClose(SSortHandle* pHandle); * * @return */ -int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fetchFp, void (*fp)(SSDataBlock*, void*), void* param); +int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fetchFp, void (*fp)(SSDataBlock*, void*), + void* param); /** * diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c index 1b7448712ead67d8a7b7a14e3520c11150a6efb6..ebf23ba6bc61e99832125bf652c84713d5eed4ed 100644 --- a/source/libs/executor/src/cachescanoperator.c +++ b/source/libs/executor/src/cachescanoperator.c @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#include "os.h" #include "function.h" +#include "os.h" #include "tname.h" #include "tdatablock.h" @@ -26,8 +26,8 @@ #include "ttypes.h" static SSDataBlock* doScanCache(SOperatorInfo* pOperator); -static void destroyLastrowScanOperator(void* param); -static int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds); +static void destroyLastrowScanOperator(void* param); +static int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds); SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SReadHandle* readHandle, SExecTaskInfo* pTaskInfo) { @@ -40,11 +40,11 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe } pInfo->readHandle = *readHandle; - pInfo->pRes = createResDataBlock(pScanNode->scan.node.pOutputDataBlockDesc); + pInfo->pRes = createResDataBlock(pScanNode->scan.node.pOutputDataBlockDesc); int32_t numOfCols = 0; - pInfo->pColMatchInfo = extractColMatchInfo(pScanNode->scan.pScanCols, pScanNode->scan.node.pOutputDataBlockDesc, &numOfCols, - COL_MATCH_FROM_COL_ID); + pInfo->pColMatchInfo = extractColMatchInfo(pScanNode->scan.pScanCols, pScanNode->scan.node.pOutputDataBlockDesc, + &numOfCols, COL_MATCH_FROM_COL_ID); code = extractTargetSlotId(pInfo->pColMatchInfo, pTaskInfo, &pInfo->pSlotIds); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -58,7 +58,7 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe // partition by tbname if (taosArrayGetSize(pTableList->pGroupList) == taosArrayGetSize(pTableList->pTableList)) { - pInfo->retrieveType = CACHESCAN_RETRIEVE_TYPE_ALL|CACHESCAN_RETRIEVE_LAST_ROW; + pInfo->retrieveType = CACHESCAN_RETRIEVE_TYPE_ALL | CACHESCAN_RETRIEVE_LAST_ROW; code = tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pTableList->pTableList, taosArrayGetSize(pInfo->pColMatchInfo), &pInfo->pLastrowReader); if (code != TSDB_CODE_SUCCESS) { @@ -67,23 +67,24 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe pInfo->pBufferredRes = createOneDataBlock(pInfo->pRes, false); blockDataEnsureCapacity(pInfo->pBufferredRes, pOperator->resultInfo.capacity); - } else { // by tags - pInfo->retrieveType = CACHESCAN_RETRIEVE_TYPE_SINGLE|CACHESCAN_RETRIEVE_LAST_ROW; + } else { // by tags + pInfo->retrieveType = CACHESCAN_RETRIEVE_TYPE_SINGLE | CACHESCAN_RETRIEVE_LAST_ROW; } if (pScanNode->scan.pScanPseudoCols != NULL) { SExprSupp* pPseudoExpr = &pInfo->pseudoExprSup; pPseudoExpr->pExprInfo = createExprInfo(pScanNode->scan.pScanPseudoCols, NULL, &pPseudoExpr->numOfExprs); - pPseudoExpr->pCtx = createSqlFunctionCtx(pPseudoExpr->pExprInfo, pPseudoExpr->numOfExprs, &pPseudoExpr->rowEntryInfoOffset); + pPseudoExpr->pCtx = + createSqlFunctionCtx(pPseudoExpr->pExprInfo, pPseudoExpr->numOfExprs, &pPseudoExpr->rowEntryInfoOffset); } - pOperator->name = "LastrowScanOperator"; + pOperator->name = "LastrowScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_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->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock); pOperator->fpSet = @@ -92,7 +93,7 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe pOperator->cost.openCost = 0; return pOperator; - _error: +_error: pTaskInfo->code = code; destroyLastrowScanOperator(pInfo); taosMemoryFree(pOperator); @@ -121,7 +122,8 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { blockDataCleanup(pInfo->pBufferredRes); taosArrayClear(pInfo->pUidList); - int32_t code = tsdbRetrieveCacheRows(pInfo->pLastrowReader, pInfo->pBufferredRes, pInfo->pSlotIds, pInfo->pUidList); + int32_t code = + tsdbRetrieveCacheRows(pInfo->pLastrowReader, pInfo->pBufferredRes, pInfo->pSlotIds, pInfo->pUidList); if (code != TSDB_CODE_SUCCESS) { T_LONG_JMP(pTaskInfo->env, code); } @@ -133,15 +135,15 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { } if (pInfo->indexOfBufferedRes < pInfo->pBufferredRes->info.rows) { - for(int32_t i = 0; i < taosArrayGetSize(pInfo->pColMatchInfo); ++i) { + for (int32_t i = 0; i < taosArrayGetSize(pInfo->pColMatchInfo); ++i) { SColMatchInfo* pMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i); - int32_t slotId = pMatchInfo->targetSlotId; + int32_t slotId = pMatchInfo->targetSlotId; SColumnInfoData* pSrc = taosArrayGet(pInfo->pBufferredRes->pDataBlock, slotId); SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, slotId); char* p = colDataGetData(pSrc, pInfo->indexOfBufferedRes); - bool isNull = colDataIsNull_s(pSrc, pInfo->indexOfBufferedRes); + bool isNull = colDataIsNull_s(pSrc, pInfo->indexOfBufferedRes); colDataAppend(pDst, 0, p, isNull); } @@ -150,8 +152,8 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { if (pInfo->pseudoExprSup.numOfExprs > 0) { SExprSupp* pSup = &pInfo->pseudoExprSup; - int32_t code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pInfo->pRes, - GET_TASKID(pTaskInfo)); + int32_t code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pInfo->pRes, + GET_TASKID(pTaskInfo)); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = code; return NULL; @@ -180,7 +182,7 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { SArray* pGroupTableList = taosArrayGetP(pTableList->pGroupList, pInfo->currentGroupIndex); tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pGroupTableList, - taosArrayGetSize(pInfo->pColMatchInfo), &pInfo->pLastrowReader); + taosArrayGetSize(pInfo->pColMatchInfo), &pInfo->pLastrowReader); taosArrayClear(pInfo->pUidList); int32_t code = tsdbRetrieveCacheRows(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds, pInfo->pUidList); @@ -200,8 +202,8 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { pInfo->pRes->info.groupId = pKeyInfo->groupId; code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pInfo->pRes, - GET_TASKID(pTaskInfo)); - if (code != TSDB_CODE_SUCCESS) { + GET_TASKID(pTaskInfo)); + if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = code; return NULL; } @@ -233,10 +235,10 @@ void destroyLastrowScanOperator(void* param) { } int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds) { - size_t numOfCols = taosArrayGetSize(pColMatchInfo); + size_t numOfCols = taosArrayGetSize(pColMatchInfo); *pSlotIds = taosMemoryMalloc(numOfCols * sizeof(int32_t)); - if (*pSlotIds == NULL) { + if (*pSlotIds == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index 1697ed63fb196aa2a571aa26f8ffe29ee1d6c5d5..8f8e486b3a57576015d8350231b4d52d27e70d1f 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -93,8 +93,8 @@ static void toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pIn pBuf->useSize = sizeof(SDataCacheEntry); blockEncode(pInput->pData, pEntry->data, &pEntry->dataLen, numOfCols, pEntry->compressed); - ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data+8)); - ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data+8+4)); + ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data + 8)); + ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data + 8 + 4)); pBuf->useSize += pEntry->dataLen; @@ -103,14 +103,14 @@ static void toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pIn } static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, SDataDispatchBuf* pBuf) { -/* - uint32_t capacity = pDispatcher->pManager->cfg.maxDataBlockNumPerQuery; - if (taosQueueItemSize(pDispatcher->pDataBlocks) > capacity) { - qError("SinkNode queue is full, no capacity, max:%d, current:%d, no capacity", capacity, - taosQueueItemSize(pDispatcher->pDataBlocks)); - return false; - } -*/ + /* + uint32_t capacity = pDispatcher->pManager->cfg.maxDataBlockNumPerQuery; + if (taosQueueItemSize(pDispatcher->pDataBlocks) > capacity) { + qError("SinkNode queue is full, no capacity, max:%d, current:%d, no capacity", capacity, + taosQueueItemSize(pDispatcher->pDataBlocks)); + return false; + } + */ pBuf->allocSize = sizeof(SDataCacheEntry) + blockGetEncodeSize(pInput->pData); @@ -176,11 +176,12 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, bool* pQueryE SDataCacheEntry* pEntry = (SDataCacheEntry*)pDispatcher->nextOutput.pData; *pLen = pEntry->dataLen; - ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data+8)); - ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data+8+4)); + ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data + 8)); + ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data + 8 + 4)); *pQueryEnd = pDispatcher->queryEnd; - qDebug("got data len %" PRId64 ", row num %d in sink", *pLen, ((SDataCacheEntry*)(pDispatcher->nextOutput.pData))->numOfRows); + qDebug("got data len %" PRId64 ", row num %d in sink", *pLen, + ((SDataCacheEntry*)(pDispatcher->nextOutput.pData))->numOfRows); } static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) { @@ -199,8 +200,8 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) { pOutput->numOfCols = pEntry->numOfCols; pOutput->compressed = pEntry->compressed; - ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data+8)); - ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data+8+4)); + ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data + 8)); + ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data + 8 + 4)); atomic_sub_fetch_64(&pDispatcher->cachedSize, pEntry->dataLen); atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen); diff --git a/source/libs/executor/src/dataInserter.c b/source/libs/executor/src/dataInserter.c index 26e1f0a3ee81a71af81bba97dec97e1a5978b745..ce0ff485ab41e97ac032b987e4558fec2d0c1f4a 100644 --- a/source/libs/executor/src/dataInserter.c +++ b/source/libs/executor/src/dataInserter.c @@ -27,7 +27,7 @@ extern SDataSinkStat gDataSinkStat; typedef struct SSubmitRes { int64_t affectedRows; int32_t code; - SSubmitRsp *pRsp; + SSubmitRsp* pRsp; } SSubmitRes; typedef struct SDataInserterHandle { @@ -44,7 +44,7 @@ typedef struct SDataInserterHandle { uint64_t useconds; uint64_t cachedSize; TdThreadMutex mutex; - tsem_t ready; + tsem_t ready; } SDataInserterHandle; typedef struct SSubmitRspParam { @@ -52,14 +52,14 @@ typedef struct SSubmitRspParam { } SSubmitRspParam; int32_t inserterCallback(void* param, SDataBuf* pMsg, int32_t code) { - SSubmitRspParam* pParam = (SSubmitRspParam*)param; + SSubmitRspParam* pParam = (SSubmitRspParam*)param; SDataInserterHandle* pInserter = pParam->pInserter; pInserter->submitRes.code = code; - + if (code == TSDB_CODE_SUCCESS) { pInserter->submitRes.pRsp = taosMemoryCalloc(1, sizeof(SSubmitRsp)); - SDecoder coder = {0}; + SDecoder coder = {0}; tDecoderInit(&coder, pMsg->pData, pMsg->len); code = tDecodeSSubmitRsp(&coder, pInserter->submitRes.pRsp); if (code) { @@ -67,10 +67,10 @@ int32_t inserterCallback(void* param, SDataBuf* pMsg, int32_t code) { pInserter->submitRes.code = code; goto _return; } - + if (pInserter->submitRes.pRsp->nBlocks > 0) { for (int32_t i = 0; i < pInserter->submitRes.pRsp->nBlocks; ++i) { - SSubmitBlkRsp *blk = pInserter->submitRes.pRsp->pBlocks + i; + SSubmitBlkRsp* blk = pInserter->submitRes.pRsp->pBlocks + i; if (TSDB_CODE_SUCCESS != blk->code) { code = blk->code; tFreeSSubmitRsp(pInserter->submitRes.pRsp); @@ -79,9 +79,10 @@ int32_t inserterCallback(void* param, SDataBuf* pMsg, int32_t code) { } } } - + pInserter->submitRes.affectedRows += pInserter->submitRes.pRsp->affectedRows; - qDebug("submit rsp received, affectedRows:%d, total:%d", pInserter->submitRes.pRsp->affectedRows, pInserter->submitRes.affectedRows); + qDebug("submit rsp received, affectedRows:%d, total:%"PRId64, pInserter->submitRes.pRsp->affectedRows, + pInserter->submitRes.affectedRows); tFreeSSubmitRsp(pInserter->submitRes.pRsp); } @@ -91,11 +92,10 @@ _return: tsem_post(&pInserter->ready); taosMemoryFree(pMsg->pData); - + return TSDB_CODE_SUCCESS; } - static int32_t sendSubmitRequest(SDataInserterHandle* pInserter, SSubmitReq* pMsg, void* pTransporter, SEpSet* pEpset) { // send the fetch remote task result reques SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); @@ -109,7 +109,7 @@ static int32_t sendSubmitRequest(SDataInserterHandle* pInserter, SSubmitReq* pMs pParam->pInserter = pInserter; pMsgSendInfo->param = pParam; - pMsgSendInfo->paramFreeFp = taosMemoryFree; + pMsgSendInfo->paramFreeFp = taosMemoryFree; pMsgSendInfo->msgInfo.pData = pMsg; pMsgSendInfo->msgInfo.len = ntohl(pMsg->length); pMsgSendInfo->msgType = TDMT_VND_SUBMIT; @@ -119,17 +119,16 @@ static int32_t sendSubmitRequest(SDataInserterHandle* pInserter, SSubmitReq* pMs return asyncSendMsgToServer(pTransporter, pEpset, &transporterId, pMsgSendInfo); } - int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) { - const SArray* pBlocks = pInserter->pDataBlocks; - const STSchema* pTSchema = pInserter->pSchema; - int64_t uid = pInserter->pNode->tableId; - int64_t suid = pInserter->pNode->stableId; - int32_t vgId = pInserter->pNode->vgId; - bool fullCol = (pInserter->pNode->pCols->length == pTSchema->numOfCols); + const SArray* pBlocks = pInserter->pDataBlocks; + const STSchema* pTSchema = pInserter->pSchema; + int64_t uid = pInserter->pNode->tableId; + int64_t suid = pInserter->pNode->stableId; + int32_t vgId = pInserter->pNode->vgId; + bool fullCol = (pInserter->pNode->pCols->length == pTSchema->numOfCols); SSubmitReq* ret = NULL; - int32_t sz = taosArrayGetSize(pBlocks); + int32_t sz = taosArrayGetSize(pBlocks); // cal size int32_t cap = sizeof(SSubmitReq); @@ -164,7 +163,7 @@ int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) { int32_t rows = 0; int32_t dataLen = 0; STSRow* rowData = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk)); - int64_t lastTs = TSKEY_MIN; + int64_t lastTs = TSKEY_MIN; bool ignoreRow = false; for (int32_t j = 0; j < pDataBlock->info.rows; j++) { SRowBuilder rb = {0}; @@ -176,13 +175,13 @@ int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) { for (int32_t k = 0; k < pTSchema->numOfCols; k++) { const STColumn* pColumn = &pTSchema->columns[k]; SColumnInfoData* pColData = NULL; - int16_t colIdx = k; + int16_t colIdx = k; if (!fullCol) { - int16_t *slotId = taosHashGet(pInserter->pCols, &pColumn->colId, sizeof(pColumn->colId)); + int16_t* slotId = taosHashGet(pInserter->pCols, &pColumn->colId, sizeof(pColumn->colId)); if (NULL == slotId) { continue; } - + colIdx = *slotId; } @@ -192,13 +191,13 @@ int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) { terrno = TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR; } - + if (colDataIsNull_s(pColData, j)) { if (0 == k && TSDB_DATA_TYPE_TIMESTAMP == pColumn->type) { ignoreRow = true; break; } - + tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, pColumn->offset, k); } else { void* data = colDataGetData(pColData, j); @@ -213,7 +212,7 @@ int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) { tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, pColumn->offset, k); } } - if(!fullCol) { + if (!fullCol) { rb.hasNone = true; } tdSRowEnd(&rb); @@ -221,13 +220,13 @@ int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) { if (ignoreRow) { continue; } - + rows++; int32_t rowLen = TD_ROW_LEN(rowData); rowData = POINTER_SHIFT(rowData, rowLen); dataLen += rowLen; } - + blkHead->dataLen = htonl(dataLen); blkHead->numOfRows = htonl(rows); @@ -242,12 +241,11 @@ int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) { return TSDB_CODE_SUCCESS; } - static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) { SDataInserterHandle* pInserter = (SDataInserterHandle*)pHandle; taosArrayPush(pInserter->pDataBlocks, &pInput->pData); SSubmitReq* pMsg = NULL; - int32_t code = dataBlockToSubmit(pInserter, &pMsg); + int32_t code = dataBlockToSubmit(pInserter, &pMsg); if (code) { return code; } @@ -264,7 +262,7 @@ static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, } *pContinue = true; - + return TSDB_CODE_SUCCESS; } @@ -279,10 +277,9 @@ static void endPut(struct SDataSinkHandle* pHandle, uint64_t useconds) { static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, bool* pQueryEnd) { SDataInserterHandle* pDispatcher = (SDataInserterHandle*)pHandle; *pLen = pDispatcher->submitRes.affectedRows; - qDebug("got total affectedRows %" PRId64 , *pLen); + qDebug("got total affectedRows %" PRId64, *pLen); } - static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { SDataInserterHandle* pInserter = (SDataInserterHandle*)pHandle; atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pInserter->cachedSize); @@ -301,14 +298,15 @@ static int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) { return TSDB_CODE_SUCCESS; } -int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void *pParam) { +int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, + void* pParam) { SDataInserterHandle* inserter = taosMemoryCalloc(1, sizeof(SDataInserterHandle)); if (NULL == inserter) { terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return TSDB_CODE_QRY_OUT_OF_MEMORY; } - SQueryInserterNode* pInserterNode = (SQueryInserterNode *)pDataSink; + SQueryInserterNode* pInserterNode = (SQueryInserterNode*)pDataSink; inserter->sink.fPut = putDataBlock; inserter->sink.fEndPut = endPut; inserter->sink.fGetLen = getDataLength; @@ -322,7 +320,8 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat inserter->queryEnd = false; int64_t suid = 0; - int32_t code = tsdbGetTableSchema(inserter->pParam->readHandle->vnode, pInserterNode->tableId, &inserter->pSchema, &suid); + int32_t code = + tsdbGetTableSchema(inserter->pParam->readHandle->vnode, pInserterNode->tableId, &inserter->pSchema, &suid); if (code) { return code; } @@ -339,15 +338,16 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat return TSDB_CODE_QRY_OUT_OF_MEMORY; } - inserter->pCols = taosHashInit(pInserterNode->pCols->length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_SMALLINT), false, HASH_NO_LOCK); + inserter->pCols = taosHashInit(pInserterNode->pCols->length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_SMALLINT), + false, HASH_NO_LOCK); SNode* pNode = NULL; FOREACH(pNode, pInserterNode->pCols) { SColumnNode* pCol = (SColumnNode*)pNode; taosHashPut(inserter->pCols, &pCol->colId, sizeof(pCol->colId), &pCol->slotId, sizeof(pCol->slotId)); } - + tsem_init(&inserter->ready, 0, 0); - + *pHandle = inserter; return TSDB_CODE_SUCCESS; } diff --git a/source/libs/executor/src/dataSinkMgt.c b/source/libs/executor/src/dataSinkMgt.c index 0aa5e6266c06ff2c0fed2dfc1ee33fc75db801ea..206f3719fa0ad7a175d630c1caa346a8cd203c4c 100644 --- a/source/libs/executor/src/dataSinkMgt.c +++ b/source/libs/executor/src/dataSinkMgt.c @@ -13,28 +13,27 @@ * along with this program. If not, see . */ -#include "tarray.h" #include "dataSinkMgt.h" #include "dataSinkInt.h" #include "planner.h" +#include "tarray.h" static SDataSinkManager gDataSinkManager = {0}; -SDataSinkStat gDataSinkStat = {0}; +SDataSinkStat gDataSinkStat = {0}; -int32_t dsDataSinkMgtInit(SDataSinkMgtCfg *cfg) { +int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg) { gDataSinkManager.cfg = *cfg; taosThreadMutexInit(&gDataSinkManager.mutex, NULL); - return 0; // to avoid compiler eror + return 0; // to avoid compiler eror } -int32_t dsDataSinkGetCacheSize(SDataSinkStat *pStat) { +int32_t dsDataSinkGetCacheSize(SDataSinkStat* pStat) { pStat->cachedSize = atomic_load_64(&gDataSinkStat.cachedSize); return 0; } - -int32_t dsCreateDataSinker(const SDataSinkNode *pDataSink, DataSinkHandle* pHandle, void* pParam) { +int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam) { switch ((int)nodeType(pDataSink)) { case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return createDataDispatcher(&gDataSinkManager, pDataSink, pHandle); @@ -66,12 +65,11 @@ int32_t dsGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) { return pHandleImpl->fGetData(pHandleImpl, pOutput); } -int32_t dsGetCacheSize(DataSinkHandle handle, uint64_t *pSize) { +int32_t dsGetCacheSize(DataSinkHandle handle, uint64_t* pSize) { SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle; return pHandleImpl->fGetCacheSize(pHandleImpl, pSize); } - void dsScheduleProcess(void* ahandle, void* pItem) { // todo } diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 2f6b737f79fcad308f5247de7487c8a9cb42dbf2..8277a4ed889c6e425ca427ae21eb4a675e635ff8 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -1201,14 +1201,21 @@ void createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) { pExp->base.resSchema = createResSchema(pType->type, pType->bytes, slotId, pType->scale, pType->precision, pFuncNode->node.aliasName); - pExp->pExpr->_function.functionId = pFuncNode->funcId; - pExp->pExpr->_function.pFunctNode = pFuncNode; + tExprNode* pExprNode = pExp->pExpr; + + pExprNode->_function.functionId = pFuncNode->funcId; + pExprNode->_function.pFunctNode = pFuncNode; + + tstrncpy(pExprNode->_function.functionName, pFuncNode->functionName, tListLen(pExprNode->_function.functionName)); - strncpy(pExp->pExpr->_function.functionName, pFuncNode->functionName, - tListLen(pExp->pExpr->_function.functionName)); #if 1 // todo refactor: add the parameter for tbname function - if (!pFuncNode->pParameterList && (strcmp(pExp->pExpr->_function.functionName, "tbname") == 0)) { + const char* name = "tbname"; + int32_t len = strlen(name); + + if (!pFuncNode->pParameterList && (memcmp(pExprNode->_function.functionName, name, len) == 0) && + pExprNode->_function.functionName[len] == 0) { + pFuncNode->pParameterList = nodesMakeList(); ASSERT(LIST_LENGTH(pFuncNode->pParameterList) == 0); SValueNode* res = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); @@ -1250,6 +1257,17 @@ void createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) { pExp->base.resSchema = createResSchema(pType->type, pType->bytes, slotId, pType->scale, pType->precision, pOpNode->node.aliasName); pExp->pExpr->_optrRoot.pRootNode = pNode; + } else if (type == QUERY_NODE_CASE_WHEN) { + pExp->pExpr->nodeType = QUERY_NODE_OPERATOR; + SCaseWhenNode* pCaseNode = (SCaseWhenNode*)pNode; + + pExp->base.pParam = taosMemoryCalloc(1, sizeof(SFunctParam)); + pExp->base.numOfParams = 1; + + SDataType* pType = &pCaseNode->node.resType; + pExp->base.resSchema = createResSchema(pType->type, pType->bytes, slotId, pType->scale, + pType->precision, pCaseNode->node.aliasName); + pExp->pExpr->_optrRoot.pRootNode = pNode; } else { ASSERT(0); } diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index e527f7e7c1720a90dd34d1481fbda90c4d6be8a0..413813f58adec76766a741cd758b01c458f4b26e 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -856,15 +856,15 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT tDeleteSSchemaWrapper(pTaskInfo->streamInfo.schema); pTaskInfo->streamInfo.schema = mtInfo.schema; - qDebug("tmqsnap qStreamPrepareScan snapshot data uid %ld ts %ld", mtInfo.uid, pOffset->ts); + qDebug("tmqsnap qStreamPrepareScan snapshot data uid %ld ts %"PRId64, mtInfo.uid, pOffset->ts); } else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_META) { SStreamRawScanInfo* pInfo = pOperator->info; SSnapContext* sContext = pInfo->sContext; if (setForSnapShot(sContext, pOffset->uid) != 0) { - qError("setForSnapShot error. uid:%" PRIi64 " ,version:%" PRIi64, pOffset->uid); + qError("setForSnapShot error. uid:%" PRIu64 " ,version:%" PRId64, pOffset->uid, pOffset->version); return -1; } - qDebug("tmqsnap qStreamPrepareScan snapshot meta uid %ld ts %ld", pOffset->uid); + qDebug("tmqsnap qStreamPrepareScan snapshot meta uid %ld ts %"PRId64, pOffset->uid, pOffset->ts); } else if (pOffset->type == TMQ_OFFSET__LOG) { SStreamRawScanInfo* pInfo = pOperator->info; tsdbReaderClose(pInfo->dataReader); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 8c1104f51988930776d8745fceb7f727289751eb..e59755787ad1c00add25f1f800fd8c86904f9086 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -1113,15 +1113,24 @@ void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numO static void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, bool keep, int32_t status); -void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, const SArray* pColMatchInfo) { +void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, const SArray* pColMatchInfo, SFilterInfo* pFilterInfo) { if (pFilterNode == NULL || pBlock->info.rows == 0) { return; } - SFilterInfo* filter = NULL; + SFilterInfo* filter = pFilterInfo; + int64_t st = taosGetTimestampUs(); + +// pError("start filter"); // todo move to the initialization function - int32_t code = filterInitFromNode((SNode*)pFilterNode, &filter, 0); + int32_t code = 0; + bool needFree = false; + if (filter == NULL) { + needFree = true; + code = filterInitFromNode((SNode*)pFilterNode, &filter, 0); + } + SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m1); @@ -1130,7 +1139,10 @@ void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, const SArray* pColM // todo the keep seems never to be True?? bool keep = filterExecute(filter, pBlock, &p, NULL, param1.numOfCols, &status); - filterFreeInfo(filter); + + if (needFree) { + filterFreeInfo(filter); + } extractQualifiedTupleByFilterResult(pBlock, p, keep, status); @@ -1845,6 +1857,7 @@ static int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInf SResFetchReq* pMsg = taosMemoryCalloc(1, sizeof(SResFetchReq)); if (NULL == pMsg) { pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; + taosMemoryFree(pWrapper); return pTaskInfo->code; } @@ -2479,7 +2492,7 @@ static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) { blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); while (1) { doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf); - doFilter(pAggInfo->pCondition, pInfo->pRes, NULL); + doFilter(pAggInfo->pCondition, pInfo->pRes, NULL, NULL); if (!hasRemainResults(&pAggInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); @@ -2873,7 +2886,7 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) { break; } - doFilter(pInfo->pCondition, fillResult, pInfo->pColMatchColInfo); + doFilter(pInfo->pCondition, fillResult, pInfo->pColMatchColInfo, NULL); if (fillResult->info.rows > 0) { break; } @@ -3049,6 +3062,12 @@ void cleanupExprSupp(SExprSupp* pSupp) { destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs); taosMemoryFreeClear(pSupp->pExprInfo); } + + if (pSupp->pFilterInfo != NULL) { + filterFreeInfo(pSupp->pFilterInfo); + pSupp->pFilterInfo = NULL; + } + taosMemoryFree(pSupp->rowEntryInfoOffset); } diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index f3ae652987eb1ab133dbe7a211c20a7e36f3b48d..e62f72c8f8f1394adf3ae9a50816e4ba4057bc95 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -311,7 +311,7 @@ static SSDataBlock* buildGroupResultDataBlock(SOperatorInfo* pOperator) { SSDataBlock* pRes = pInfo->binfo.pRes; while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - doFilter(pInfo->pCondition, pRes, NULL); + doFilter(pInfo->pCondition, pRes, NULL, NULL); if (!hasRemainResults(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); @@ -991,6 +991,8 @@ static void destroyStreamPartitionOperatorInfo(void* param) { taosMemoryFree(pInfo->partitionSup.keyBuf); cleanupExprSupp(&pInfo->scalarSup); + cleanupExprSupp(&pInfo->tbnameCalSup); + cleanupExprSupp(&pInfo->tagCalSup); blockDataDestroy(pInfo->pDelRes); taosMemoryFreeClear(param); } @@ -1037,6 +1039,19 @@ SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStr } } + if (pPartNode->pTags != NULL) { + int32_t numOfTags; + SExprInfo* pTagExpr = createExprInfo(pPartNode->pTags, NULL, &numOfTags); + if (pTagExpr == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _error; + } + if (initExprSupp(&pInfo->tagCalSup, pTagExpr, numOfTags) != 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _error; + } + } + int32_t keyLen = 0; code = initGroupOptrInfo(&pInfo->partitionSup.pGroupColVals, &keyLen, &pInfo->partitionSup.keyBuf, pInfo->partitionSup.pGroupCols); diff --git a/source/libs/executor/src/joinoperator.c b/source/libs/executor/src/joinoperator.c index 1bc7d458e0ee16decabea988a16713996d2468ce..53cfa6c27a880230aa919b245a8a16687498000c 100644 --- a/source/libs/executor/src/joinoperator.c +++ b/source/libs/executor/src/joinoperator.c @@ -267,18 +267,19 @@ static int32_t mergeJoinJoinDownstreamTsRanges(SOperatorInfo* pOperator, int64_t size_t rightNumJoin = taosArrayGetSize(rightRowLocations); code = blockDataEnsureCapacity(pRes, *nRows + leftNumJoin * rightNumJoin); if (code != TSDB_CODE_SUCCESS) { - qError("%s can not ensure block capacity for join. left: %zu, right: %zu", GET_TASKID(pOperator->pTaskInfo), leftNumJoin, rightNumJoin); + qError("%s can not ensure block capacity for join. left: %zu, right: %zu", GET_TASKID(pOperator->pTaskInfo), + leftNumJoin, rightNumJoin); } if (code == TSDB_CODE_SUCCESS) { - for (int32_t i = 0; i < leftNumJoin; ++i) { - for (int32_t j = 0; j < rightNumJoin; ++j) { - SRowLocation *leftRow = taosArrayGet(leftRowLocations, i); - SRowLocation *rightRow = taosArrayGet(rightRowLocations, j); - mergeJoinJoinLeftRight(pOperator, pRes, *nRows, leftRow->pDataBlock, leftRow->pos, rightRow->pDataBlock, - rightRow->pos); - ++*nRows; - } + for (int32_t i = 0; i < leftNumJoin; ++i) { + for (int32_t j = 0; j < rightNumJoin; ++j) { + SRowLocation* leftRow = taosArrayGet(leftRowLocations, i); + SRowLocation* rightRow = taosArrayGet(rightRowLocations, j); + mergeJoinJoinLeftRight(pOperator, pRes, *nRows, leftRow->pDataBlock, leftRow->pos, rightRow->pDataBlock, + rightRow->pos); + ++*nRows; } + } } for (int i = 0; i < taosArrayGetSize(rightCreatedBlocks); ++i) { @@ -386,7 +387,7 @@ SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) { break; } if (pJoinInfo->pCondAfterMerge != NULL) { - doFilter(pJoinInfo->pCondAfterMerge, pRes, NULL); + doFilter(pJoinInfo->pCondAfterMerge, pRes, NULL, NULL); } if (pRes->info.rows >= pOperator->resultInfo.threshold) { break; diff --git a/source/libs/executor/src/projectoperator.c b/source/libs/executor/src/projectoperator.c index e9e6fed66aad43daf71a99613fb966d16461da76..fe6ee4129a9a0d0bd6dec2eb3e2fddc5452880da 100644 --- a/source/libs/executor/src/projectoperator.c +++ b/source/libs/executor/src/projectoperator.c @@ -315,7 +315,7 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { } // do apply filter - doFilter(pProjectInfo->pFilterNode, pFinalRes, NULL); + doFilter(pProjectInfo->pFilterNode, pFinalRes, NULL, NULL); // when apply the limit/offset for each group, pRes->info.rows may be 0, due to limit constraint. if (pFinalRes->info.rows > 0 || (pOperator->status == OP_EXEC_DONE)) { @@ -325,7 +325,7 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { } else { // do apply filter if (pRes->info.rows > 0) { - doFilter(pProjectInfo->pFilterNode, pRes, NULL); + doFilter(pProjectInfo->pFilterNode, pRes, NULL, NULL); if (pRes->info.rows == 0) { continue; } @@ -518,7 +518,7 @@ SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { } } - doFilter(pIndefInfo->pCondition, pInfo->pRes, NULL); + doFilter(pIndefInfo->pCondition, pInfo->pRes, NULL, NULL); size_t rows = pInfo->pRes->info.rows; if (rows > 0 || pOperator->status == OP_EXEC_DONE) { break; @@ -620,7 +620,7 @@ SSDataBlock* doGenerateSourceData(SOperatorInfo* pOperator) { } pRes->info.rows = 1; - doFilter(pProjectInfo->pFilterNode, pRes, NULL); + doFilter(pProjectInfo->pFilterNode, pRes, NULL, NULL); /*int32_t status = */ doIngroupLimitOffset(&pProjectInfo->limitInfo, 0, pRes, pOperator); diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index c20bb9581164de0a76fee5a1aec983c3802be203..66fad27d71c3c5b6e7d1741ec96ffe36be5c0bff 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -385,7 +385,7 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca if (pTableScanInfo->pFilterNode != NULL) { int64_t st = taosGetTimestampUs(); - doFilter(pTableScanInfo->pFilterNode, pBlock, pTableScanInfo->pColMatchInfo); + doFilter(pTableScanInfo->pFilterNode, pBlock, pTableScanInfo->pColMatchInfo, pOperator->exprSupp.pFilterInfo); double el = (taosGetTimestampUs() - st) / 1000.0; pTableScanInfo->readRecorder.filterTime += el; @@ -754,6 +754,11 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, pInfo->dataBlockLoadFlag = pTableScanNode->dataRequired; pInfo->pResBlock = createResDataBlock(pDescNode); pInfo->pFilterNode = pTableScanNode->scan.node.pConditions; + + if (pInfo->pFilterNode != NULL) { + code = filterInitFromNode((SNode*)pInfo->pFilterNode, &pOperator->exprSupp.pFilterInfo, 0); + } + pInfo->scanFlag = MAIN_SCAN; pInfo->pColMatchInfo = pColList; pInfo->currentGroupId = -1; @@ -1123,7 +1128,7 @@ static SSDataBlock* doRangeScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32 return NULL; } - doFilter(pInfo->pCondition, pResult, NULL); + doFilter(pInfo->pCondition, pResult, NULL, NULL); if (pResult->info.rows == 0) { continue; } @@ -1311,10 +1316,15 @@ static void calBlockTag(SExprSupp* pTagCalSup, SSDataBlock* pBlock, SSDataBlock* blockDataEnsureCapacity(pResBlock, 1); - projectApplyFunctions(pTagCalSup->pExprInfo, pResBlock, pSrcBlock, pTagCalSup->pCtx, 1, NULL); + projectApplyFunctions(pTagCalSup->pExprInfo, pResBlock, pSrcBlock, pTagCalSup->pCtx, pTagCalSup->numOfExprs, NULL); ASSERT(pResBlock->info.rows == 1); // build tagArray + /*SArray* tagArray = taosArrayInit(0, sizeof(void*));*/ + /*STagVal tagVal = {*/ + /*.cid = 0,*/ + /*.type = 0,*/ + /*};*/ // build STag // set STag @@ -1469,7 +1479,7 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock } if (filter) { - doFilter(pInfo->pCondition, pInfo->pRes, NULL); + doFilter(pInfo->pCondition, pInfo->pRes, NULL, NULL); } blockDataUpdateTsWindow(pInfo->pRes, pInfo->primaryTsIndex); blockDataFreeRes((SSDataBlock*)pBlock); @@ -1891,7 +1901,7 @@ FETCH_NEXT_BLOCK: } } - doFilter(pInfo->pCondition, pInfo->pRes, NULL); + doFilter(pInfo->pCondition, pInfo->pRes, NULL, NULL); blockDataUpdateTsWindow(pInfo->pRes, pInfo->primaryTsIndex); if (pBlockInfo->rows > 0 || pInfo->pUpdateDataRes->info.rows > 0) { @@ -2110,6 +2120,9 @@ static void destroyStreamScanOperatorInfo(void* param) { taosMemoryFree(pStreamScan->pPseudoExpr); } + cleanupExprSupp(&pStreamScan->tbnameCalSup); + cleanupExprSupp(&pStreamScan->tagCalSup); + updateInfoDestroy(pStreamScan->pUpdateInfo); blockDataDestroy(pStreamScan->pRes); blockDataDestroy(pStreamScan->pUpdateRes); @@ -2164,6 +2177,19 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys } } + if (pTableScanNode->pTags != NULL) { + int32_t numOfTags; + SExprInfo* pTagExpr = createExprInfo(pTableScanNode->pTags, NULL, &numOfTags); + if (pTagExpr == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _error; + } + if (initExprSupp(&pInfo->tagCalSup, pTagExpr, numOfTags) != 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _error; + } + } + pInfo->pBlockLists = taosArrayInit(4, POINTER_BYTES); if (pInfo->pBlockLists == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -2361,7 +2387,7 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes; } - doFilter(pInfo->pCondition, pInfo->pRes, NULL); + doFilter(pInfo->pCondition, pInfo->pRes, NULL, NULL); return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes; } @@ -2542,16 +2568,27 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { SMetaReader smrChildTable = {0}; metaReaderInit(&smrChildTable, pInfo->readHandle.meta, 0); - metaGetTableEntryByName(&smrChildTable, condTableName); + int32_t code = metaGetTableEntryByName(&smrChildTable, condTableName); + if (code != TSDB_CODE_SUCCESS) { + // terrno has been set by metaGetTableEntryByName, therefore, return directly + return NULL; + } + if (smrChildTable.me.type != TSDB_CHILD_TABLE) { metaReaderClear(&smrChildTable); blockDataDestroy(dataBlock); pInfo->loadInfo.totalRows = 0; return NULL; } + SMetaReader smrSuperTable = {0}; metaReaderInit(&smrSuperTable, pInfo->readHandle.meta, META_READER_NOLOCK); - metaGetTableEntryByUid(&smrSuperTable, smrChildTable.me.ctbEntry.suid); + code = metaGetTableEntryByUid(&smrSuperTable, smrChildTable.me.ctbEntry.suid); + if (code != TSDB_CODE_SUCCESS) { + // terrno has been set by metaGetTableEntryByUid + return NULL; + } + sysTableUserTagsFillOneTableTags(pInfo, &smrSuperTable, &smrChildTable, dbname, tableName, &numOfRows, dataBlock); metaReaderClear(&smrSuperTable); metaReaderClear(&smrChildTable); @@ -3434,7 +3471,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc if (pTableScanInfo->pFilterNode != NULL) { int64_t st = taosGetTimestampMs(); - doFilter(pTableScanInfo->pFilterNode, pBlock, pTableScanInfo->pColMatchInfo); + doFilter(pTableScanInfo->pFilterNode, pBlock, pTableScanInfo->pColMatchInfo, NULL); double el = (taosGetTimestampUs() - st) / 1000.0; pTableScanInfo->readRecorder.filterTime += el; @@ -3769,6 +3806,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN int32_t code = initQueryTableDataCond(&pInfo->cond, pTableScanNode); if (code != TSDB_CODE_SUCCESS) { + taosArrayDestroy(pColList); goto _error; } diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index e2014ec97320c863a6857e94c538bd8d8319c2a1..0d5f52103420dfe874d6e20514e1891db55a2362 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -216,7 +216,7 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) { return NULL; } - doFilter(pInfo->pCondition, pBlock, pInfo->pColMatchInfo); + doFilter(pInfo->pCondition, pBlock, pInfo->pColMatchInfo, NULL); if (blockDataGetNumOfRows(pBlock) == 0) { continue; } @@ -658,7 +658,8 @@ SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pData blockDataDestroy(p); - qDebug("%s get sorted block, groupId:%0x"PRIx64" rows:%d", GET_TASKID(pTaskInfo), pDataBlock->info.groupId, pDataBlock->info.rows); + qDebug("%s get sorted block, groupId:0x%" PRIx64 " rows:%d", GET_TASKID(pTaskInfo), pDataBlock->info.groupId, + pDataBlock->info.rows); return (pDataBlock->info.rows > 0) ? pDataBlock : NULL; } diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c index 85c1d638684b718b280d6d341d73d7909e4b3d62..8b716531e57455a240c9e0054aae06b732320661 100644 --- a/source/libs/executor/src/tfill.c +++ b/source/libs/executor/src/tfill.c @@ -561,7 +561,7 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma int32_t numOfRows = taosNumOfRemainRows(pFillInfo); TSKEY ekey1 = ekey; - + int64_t numOfRes = -1; if (numOfRows > 0) { // still fill gap within current data block, not generating data after the result set. TSKEY lastKey = tsList[pFillInfo->numOfRows - 1]; @@ -1501,7 +1501,7 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) { } doStreamFillImpl(pOperator); - doFilter(pInfo->pCondition, pInfo->pRes, pInfo->pColMatchColInfo); + doFilter(pInfo->pCondition, pInfo->pRes, pInfo->pColMatchColInfo, NULL); pOperator->resultInfo.totalRows += pInfo->pRes->info.rows; if (pInfo->pRes->info.rows > 0) { break; @@ -1681,7 +1681,11 @@ SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFi &numOfOutputCols, COL_MATCH_FROM_SLOT_ID); pInfo->pCondition = pPhyFillNode->node.pConditions; pInfo->pColMatchColInfo = pColMatchColInfo; - initExprSupp(&pOperator->exprSupp, pFillExprInfo, numOfFillCols); + int32_t code = initExprSupp(&pOperator->exprSupp, pFillExprInfo, numOfFillCols); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + pInfo->srcRowIndex = 0; pOperator->name = "FillOperator"; @@ -1693,7 +1697,7 @@ SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFi pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamFill, NULL, NULL, destroyStreamFillOperatorInfo, NULL, NULL, NULL); - int32_t code = appendDownstream(pOperator, &downstream, 1); + code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -1702,5 +1706,6 @@ SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFi _error: destroyStreamFillOperatorInfo(pInfo); taosMemoryFreeClear(pOperator); + pTaskInfo->code = code; return NULL; } diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 560a1d319a8797e9c63049a3de9d1ceab8b5232e..9c219d2765b1c6d4827ec01d387924c7b9f335d5 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -1218,7 +1218,7 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI pBlock->info.rows, numOfOutput); } -static int32_t openStateWindowAggOptr(SOperatorInfo* pOperator) { +static int32_t openStateWindowAggOptr(SOperatorInfo* pOperator) { if (OPTR_IS_OPENED(pOperator)) { return TSDB_CODE_SUCCESS; } @@ -1277,7 +1277,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) { blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity); while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - doFilter(pInfo->pCondition, pBInfo->pRes, NULL); + doFilter(pInfo->pCondition, pBInfo->pRes, NULL, NULL); bool hasRemain = hasRemainResults(&pInfo->groupResInfo); if (!hasRemain) { @@ -1315,7 +1315,7 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator) { blockDataEnsureCapacity(pBlock, pOperator->resultInfo.capacity); while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - doFilter(pInfo->pCondition, pBlock, NULL); + doFilter(pInfo->pCondition, pBlock, NULL, NULL); bool hasRemain = hasRemainResults(&pInfo->groupResInfo); if (!hasRemain) { @@ -1420,8 +1420,9 @@ static void doDeleteWindows(SOperatorInfo* pOperator, SInterval* pInterval, SSDa SColumnInfoData* pGpCol = taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX); uint64_t* pGpDatas = (uint64_t*)pGpCol->pData; for (int32_t i = 0; i < pBlock->info.rows; i++) { - SResultRowInfo dumyInfo; + SResultRowInfo dumyInfo = {0}; dumyInfo.cur.pageId = -1; + STimeWindow win = {0}; if (IS_FINAL_OP(pInfo)) { win.skey = startTsCols[i]; @@ -2019,7 +2020,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) { if (pOperator->status == OP_RES_TO_RETURN) { while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - doFilter(pInfo->pCondition, pBInfo->pRes, NULL); + doFilter(pInfo->pCondition, pBInfo->pRes, NULL, NULL); bool hasRemain = hasRemainResults(&pInfo->groupResInfo); if (!hasRemain) { @@ -2062,7 +2063,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) { blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity); while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - doFilter(pInfo->pCondition, pBInfo->pRes, NULL); + doFilter(pInfo->pCondition, pBInfo->pRes, NULL, NULL); bool hasRemain = hasRemainResults(&pInfo->groupResInfo); if (!hasRemain) { @@ -2757,7 +2758,7 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWi if (pStateNode->window.pExprs != NULL) { int32_t numOfScalarExpr = 0; SExprInfo* pScalarExprInfo = createExprInfo(pStateNode->window.pExprs, NULL, &numOfScalarExpr); - int32_t code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr); + int32_t code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -5251,7 +5252,7 @@ static void doMergeAlignedIntervalAgg(SOperatorInfo* pOperator) { setInputDataBlock(pOperator, pSup->pCtx, pBlock, pIaInfo->inputOrder, scanFlag, true); doMergeAlignedIntervalAggImpl(pOperator, &pIaInfo->binfo.resultRowInfo, pBlock, pRes); - doFilter(pMiaInfo->pCondition, pRes, NULL); + doFilter(pMiaInfo->pCondition, pRes, NULL, NULL); if (pRes->info.rows >= pOperator->resultInfo.capacity) { break; } @@ -5828,27 +5829,30 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys pInfo->ignoreExpiredData = pIntervalPhyNode->window.igExpired; pInfo->isFinal = false; - if (pIntervalPhyNode->window.pExprs != NULL) { - int32_t numOfScalar = 0; - SExprInfo* pScalarExprInfo = createExprInfo(pIntervalPhyNode->window.pExprs, NULL, &numOfScalar); - int32_t code = initExprSupp(&pInfo->scalarSupp, pScalarExprInfo, numOfScalar); - if (code != TSDB_CODE_SUCCESS) { - goto _error; - } - } + pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId; initResultSizeInfo(&pOperator->resultInfo, 4096); SExprSupp* pSup = &pOperator->exprSupp; + + initBasicInfo(&pInfo->binfo, pResBlock); + initStreamFunciton(pSup->pCtx, pSup->numOfExprs); + initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; int32_t code = initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } - initBasicInfo(&pInfo->binfo, pResBlock); - initStreamFunciton(pSup->pCtx, pSup->numOfExprs); - initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window); + if (pIntervalPhyNode->window.pExprs != NULL) { + int32_t numOfScalar = 0; + SExprInfo* pScalarExprInfo = createExprInfo(pIntervalPhyNode->window.pExprs, NULL, &numOfScalar); + code = initExprSupp(&pInfo->scalarSupp, pScalarExprInfo, numOfScalar); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + } pInfo->invertible = allInvertible(pSup->pCtx, numOfCols); pInfo->invertible = false; diff --git a/source/libs/executor/src/tlinearhash.c b/source/libs/executor/src/tlinearhash.c index cffabcb6aca1f1f5ba457fb765828889bc3c03e6..824e988c2f8ac388ff59576eb424697a57eed3b8 100644 --- a/source/libs/executor/src/tlinearhash.c +++ b/source/libs/executor/src/tlinearhash.c @@ -14,27 +14,27 @@ */ #include "tlinearhash.h" -#include "tdef.h" #include "taoserror.h" +#include "tdef.h" #include "tpagedbuf.h" #define LHASH_CAP_RATIO 0.85 // Always located in memory typedef struct SLHashBucket { - SArray *pPageIdList; - int32_t size; // the number of element in this entry + SArray* pPageIdList; + int32_t size; // the number of element in this entry } SLHashBucket; struct SLHashObj { - SDiskbasedBuf *pBuf; + SDiskbasedBuf* pBuf; _hash_fn_t hashFn; - SLHashBucket **pBucket; // entry list + SLHashBucket** pBucket; // entry list int32_t tuplesPerPage; - int32_t numOfAlloc; // number of allocated bucket ptr slot - int32_t bits; // the number of bits used in hash - int32_t numOfBuckets; // the number of buckets - int64_t size; // the number of total items + int32_t numOfAlloc; // number of allocated bucket ptr slot + int32_t bits; // the number of bits used in hash + int32_t numOfBuckets; // the number of buckets + int64_t size; // the number of total items }; /** @@ -44,19 +44,17 @@ struct SLHashObj { * +-----------+-------+--------+ */ typedef struct SLHashNode { - uint16_t keyLen; - uint16_t dataLen; + uint16_t keyLen; + uint16_t dataLen; } SLHashNode; -#define GET_LHASH_NODE_KEY(_n) (((char*)(_n)) + sizeof(SLHashNode)) -#define GET_LHASH_NODE_DATA(_n) ((char*)(_n) + sizeof(SLHashNode) + ((SLHashNode*)(_n))->keyLen) -#define GET_LHASH_NODE_LEN(_n) (sizeof(SLHashNode) + ((SLHashNode*)(_n))->keyLen + ((SLHashNode*)(_n))->dataLen) +#define GET_LHASH_NODE_KEY(_n) (((char*)(_n)) + sizeof(SLHashNode)) +#define GET_LHASH_NODE_DATA(_n) ((char*)(_n) + sizeof(SLHashNode) + ((SLHashNode*)(_n))->keyLen) +#define GET_LHASH_NODE_LEN(_n) (sizeof(SLHashNode) + ((SLHashNode*)(_n))->keyLen + ((SLHashNode*)(_n))->dataLen) static int32_t doAddNewBucket(SLHashObj* pHashObj); -static int32_t doGetBucketIdFromHashVal(int32_t hashv, int32_t bits) { - return hashv & ((1ul << (bits)) - 1); -} +static int32_t doGetBucketIdFromHashVal(int32_t hashv, int32_t bits) { return hashv & ((1ul << (bits)) - 1); } static int32_t doGetAlternativeBucketId(int32_t bucketId, int32_t bits, int32_t numOfBuckets) { int32_t v = bucketId - (1ul << (bits - 1)); @@ -70,9 +68,9 @@ static int32_t doGetRelatedSplitBucketId(int32_t bucketId, int32_t bits) { } static void doCopyObject(char* p, const void* key, int32_t keyLen, const void* data, int32_t size) { - *(uint16_t*) p = keyLen; + *(uint16_t*)p = keyLen; p += sizeof(uint16_t); - *(uint16_t*) p = size; + *(uint16_t*)p = size; p += sizeof(uint16_t); memcpy(p, key, keyLen); @@ -86,7 +84,7 @@ static int32_t doAddToBucket(SLHashObj* pHashObj, SLHashBucket* pBucket, int32_t int32_t pageId = *(int32_t*)taosArrayGetLast(pBucket->pPageIdList); SFilePage* pPage = getBufPage(pHashObj->pBuf, pageId); - ASSERT (pPage != NULL); + ASSERT(pPage != NULL); // put to current buf page size_t nodeSize = sizeof(SLHashNode) + keyLen + size; @@ -96,7 +94,7 @@ static int32_t doAddToBucket(SLHashObj* pHashObj, SLHashBucket* pBucket, int32_t releaseBufPage(pHashObj->pBuf, pPage); // allocate the overflow buffer page to hold this k/v. - int32_t newPageId = -1; + int32_t newPageId = -1; SFilePage* pNewPage = getNewBufPage(pHashObj->pBuf, &newPageId); if (pNewPage == NULL) { return terrno; @@ -110,7 +108,7 @@ static int32_t doAddToBucket(SLHashObj* pHashObj, SLHashBucket* pBucket, int32_t setBufPageDirty(pNewPage, true); releaseBufPage(pHashObj->pBuf, pNewPage); } else { - char* p = (char*) pPage + pPage->num; + char* p = (char*)pPage + pPage->num; doCopyObject(p, key, keyLen, data, size); pPage->num += nodeSize; setBufPageDirty(pPage, true); @@ -118,7 +116,7 @@ static int32_t doAddToBucket(SLHashObj* pHashObj, SLHashBucket* pBucket, int32_t } pBucket->size += 1; -// printf("===> add to bucket:0x%x, num:%d, key:%d\n", index, pBucket->size, *(int*) key); + // printf("===> add to bucket:0x%x, num:%d, key:%d\n", index, pBucket->size, *(int*) key); return TSDB_CODE_SUCCESS; } @@ -127,7 +125,7 @@ static void doRemoveFromBucket(SFilePage* pPage, SLHashNode* pNode, SLHashBucket ASSERT(pPage != NULL && pNode != NULL && pBucket->size >= 1); int32_t len = GET_LHASH_NODE_LEN(pNode); - char* p = (char*) pNode + len; + char* p = (char*)pNode + len; char* pEnd = (char*)pPage + pPage->num; memmove(pNode, p, (pEnd - p)); @@ -141,7 +139,7 @@ static void doRemoveFromBucket(SFilePage* pPage, SLHashNode* pNode, SLHashBucket pBucket->size -= 1; } -static void doTrimBucketPages(SLHashObj *pHashObj, SLHashBucket* pBucket) { +static void doTrimBucketPages(SLHashObj* pHashObj, SLHashBucket* pBucket) { size_t numOfPages = taosArrayGetSize(pBucket->pPageIdList); if (numOfPages <= 1) { return; @@ -188,7 +186,7 @@ static void doTrimBucketPages(SLHashObj *pHashObj, SLHashBucket* pBucket) { } nodeSize = GET_LHASH_NODE_LEN(pStart); - } else { // move to the front of pLast page + } else { // move to the front of pLast page if (pStart != pLast->data) { memmove(pLast->data, pStart, (((char*)pLast) + pLast->num - pStart)); setBufPageDirty(pLast, true); @@ -214,7 +212,7 @@ static int32_t doAddNewBucket(SLHashObj* pHashObj) { } memset(p + POINTER_BYTES * pHashObj->numOfBuckets, 0, newLen - pHashObj->numOfBuckets); - pHashObj->pBucket = (SLHashBucket**) p; + pHashObj->pBucket = (SLHashBucket**)p; pHashObj->numOfAlloc = newLen; } @@ -226,7 +224,7 @@ static int32_t doAddNewBucket(SLHashObj* pHashObj) { return TSDB_CODE_OUT_OF_MEMORY; } - int32_t pageId = -1; + int32_t pageId = -1; SFilePage* p = getNewBufPage(pHashObj->pBuf, &pageId); if (p == NULL) { return terrno; @@ -239,7 +237,7 @@ static int32_t doAddNewBucket(SLHashObj* pHashObj) { taosArrayPush(pBucket->pPageIdList, &pageId); pHashObj->numOfBuckets += 1; -// printf("---------------add new bucket, id:0x%x, total:%d\n", pHashObj->numOfBuckets - 1, pHashObj->numOfBuckets); + // printf("---------------add new bucket, id:0x%x, total:%d\n", pHashObj->numOfBuckets - 1, pHashObj->numOfBuckets); return TSDB_CODE_SUCCESS; } @@ -266,14 +264,14 @@ SLHashObj* tHashInit(int32_t inMemPages, int32_t pageSize, _hash_fn_t fn, int32_ setBufPageCompressOnDisk(pHashObj->pBuf, false); /** - * The number of bits in the hash value, which is used to decide the exact bucket where the object should be located in. - * The initial value is 0. + * The number of bits in the hash value, which is used to decide the exact bucket where the object should be located + * in. The initial value is 0. */ - pHashObj->bits = 0; + pHashObj->bits = 0; pHashObj->hashFn = fn; pHashObj->tuplesPerPage = numOfTuplePerPage; - pHashObj->numOfAlloc = 4; // initial allocated array list + pHashObj->numOfAlloc = 4; // initial allocated array list pHashObj->pBucket = taosMemoryCalloc(pHashObj->numOfAlloc, POINTER_BYTES); code = doAddNewBucket(pHashObj); @@ -289,7 +287,7 @@ SLHashObj* tHashInit(int32_t inMemPages, int32_t pageSize, _hash_fn_t fn, int32_ void* tHashCleanup(SLHashObj* pHashObj) { destroyDiskbasedBuf(pHashObj->pBuf); - for(int32_t i = 0; i < pHashObj->numOfBuckets; ++i) { + for (int32_t i = 0; i < pHashObj->numOfBuckets; ++i) { taosArrayDestroy(pHashObj->pBucket[i]->pPageIdList); taosMemoryFreeClear(pHashObj->pBucket[i]); } @@ -299,7 +297,7 @@ void* tHashCleanup(SLHashObj* pHashObj) { return NULL; } -int32_t tHashPut(SLHashObj* pHashObj, const void *key, size_t keyLen, void *data, size_t size) { +int32_t tHashPut(SLHashObj* pHashObj, const void* key, size_t keyLen, void* data, size_t size) { ASSERT(pHashObj != NULL && key != NULL); if (pHashObj->bits == 0) { @@ -311,12 +309,12 @@ int32_t tHashPut(SLHashObj* pHashObj, const void *key, size_t keyLen, void *data if (v >= pHashObj->numOfBuckets) { int32_t newBucketId = doGetAlternativeBucketId(v, pHashObj->bits, pHashObj->numOfBuckets); -// printf("bucketId: 0x%x not exists, put it into 0x%x instead\n", v, newBucketId); + // printf("bucketId: 0x%x not exists, put it into 0x%x instead\n", v, newBucketId); v = newBucketId; } SLHashBucket* pBucket = pHashObj->pBucket[v]; - int32_t code = doAddToBucket(pHashObj, pBucket, v, key, keyLen, data, size); + int32_t code = doAddToBucket(pHashObj, pBucket, v, key, keyLen, data, size); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -335,7 +333,7 @@ int32_t tHashPut(SLHashObj* pHashObj, const void *key, size_t keyLen, void *data int32_t numOfBits = ceil(log(pHashObj->numOfBuckets) / log(2)); if (numOfBits > pHashObj->bits) { -// printf("extend the bits from %d to %d, new bucket:%d\n", pHashObj->bits, numOfBits, newBucketId); + // printf("extend the bits from %d to %d, new bucket:%d\n", pHashObj->bits, numOfBits, newBucketId); ASSERT(numOfBits == pHashObj->bits + 1); pHashObj->bits = numOfBits; } @@ -344,31 +342,31 @@ int32_t tHashPut(SLHashObj* pHashObj, const void *key, size_t keyLen, void *data // load all data in this bucket and check if the data needs to relocated into the new bucket SLHashBucket* pBucket = pHashObj->pBucket[splitBucketId]; -// printf("split %d items' bucket:0x%x to new bucket:0x%x\n", pBucket->size, splitBucketId, newBucketId); + // printf("split %d items' bucket:0x%x to new bucket:0x%x\n", pBucket->size, splitBucketId, newBucketId); for (int32_t i = 0; i < taosArrayGetSize(pBucket->pPageIdList); ++i) { int32_t pageId = *(int32_t*)taosArrayGet(pBucket->pPageIdList, i); SFilePage* p = getBufPage(pHashObj->pBuf, pageId); char* pStart = p->data; - while (pStart - ((char*) p) < p->num) { + while (pStart - ((char*)p) < p->num) { SLHashNode* pNode = (SLHashNode*)pStart; ASSERT(pNode->keyLen > 0 && pNode->dataLen >= 0); - char* k = GET_LHASH_NODE_KEY(pNode); + char* k = GET_LHASH_NODE_KEY(pNode); int32_t hashv = pHashObj->hashFn(k, pNode->keyLen); int32_t v1 = doGetBucketIdFromHashVal(hashv, pHashObj->bits); if (v1 != splitBucketId) { // place it into the new bucket ASSERT(v1 == newBucketId); -// printf("move key:%d to 0x%x bucket, remain items:%d\n", *(int32_t*)k, v1, pBucket->size - 1); + // printf("move key:%d to 0x%x bucket, remain items:%d\n", *(int32_t*)k, v1, pBucket->size - 1); SLHashBucket* pNewBucket = pHashObj->pBucket[newBucketId]; doAddToBucket(pHashObj, pNewBucket, newBucketId, (void*)GET_LHASH_NODE_KEY(pNode), pNode->keyLen, GET_LHASH_NODE_KEY(pNode), pNode->dataLen); doRemoveFromBucket(p, pNode, pBucket); } else { -// printf("check key:%d, located into: %d, skip it\n", *(int*) k, v1); + // printf("check key:%d, located into: %d, skip it\n", *(int*) k, v1); int32_t nodeSize = GET_LHASH_NODE_LEN(pStart); pStart += nodeSize; @@ -383,7 +381,7 @@ int32_t tHashPut(SLHashObj* pHashObj, const void *key, size_t keyLen, void *data return TSDB_CODE_SUCCESS; } -char* tHashGet(SLHashObj* pHashObj, const void *key, size_t keyLen) { +char* tHashGet(SLHashObj* pHashObj, const void* key, size_t keyLen) { ASSERT(pHashObj != NULL && key != NULL && keyLen > 0); int32_t hashv = pHashObj->hashFn(key, keyLen); @@ -393,7 +391,7 @@ char* tHashGet(SLHashObj* pHashObj, const void *key, size_t keyLen) { } SLHashBucket* pBucket = pHashObj->pBucket[bucketId]; - int32_t num = taosArrayGetSize(pBucket->pPageIdList); + int32_t num = taosArrayGetSize(pBucket->pPageIdList); for (int32_t i = 0; i < num; ++i) { int32_t pageId = *(int32_t*)taosArrayGet(pBucket->pPageIdList, i); @@ -418,7 +416,7 @@ char* tHashGet(SLHashObj* pHashObj, const void *key, size_t keyLen) { return NULL; } -int32_t tHashRemove(SLHashObj* pHashObj, const void *key, size_t keyLen) { +int32_t tHashRemove(SLHashObj* pHashObj, const void* key, size_t keyLen) { // todo return TSDB_CODE_SUCCESS; } @@ -431,8 +429,8 @@ void tHashPrint(const SLHashObj* pHashObj, int32_t type) { if (type == LINEAR_HASH_DATA) { for (int32_t i = 0; i < pHashObj->numOfBuckets; ++i) { -// printf("bucket: 0x%x, obj:%d, page:%d\n", i, pHashObj->pBucket[i]->size, -// (int)taosArrayGetSize(pHashObj->pBucket[i]->pPageIdList)); + // printf("bucket: 0x%x, obj:%d, page:%d\n", i, pHashObj->pBucket[i]->size, + // (int)taosArrayGetSize(pHashObj->pBucket[i]->pPageIdList)); } } else { dBufPrintStatis(pHashObj->pBuf); diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 63fc9d9e1c553bc210c7f525b014cd3d0b4f852b..74da5c45ee1f56b552c3f95f8bfbffd95994606a 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -13,16 +13,16 @@ * along with this program. If not, see . */ -#include "tcommon.h" #include "query.h" +#include "tcommon.h" +#include "tcompare.h" #include "tdatablock.h" #include "tdef.h" #include "tlosertree.h" #include "tpagedbuf.h" #include "tsort.h" #include "tutil.h" -#include "tcompare.h" struct STupleHandle { SSDataBlock* pBlock; @@ -30,37 +30,37 @@ struct STupleHandle { }; struct SSortHandle { - int32_t type; - int32_t pageSize; - int32_t numOfPages; - SDiskbasedBuf *pBuf; + int32_t type; + int32_t pageSize; + int32_t numOfPages; + SDiskbasedBuf* pBuf; - SArray *pSortInfo; - SArray *pOrderedSource; + SArray* pSortInfo; + SArray* pOrderedSource; - int32_t loops; - uint64_t sortElapsed; - int64_t startTs; - uint64_t totalElapsed; + int32_t loops; + uint64_t sortElapsed; + int64_t startTs; + uint64_t totalElapsed; int32_t sourceId; - SSDataBlock *pDataBlock; + SSDataBlock* pDataBlock; SMsortComparParam cmpParam; int32_t numOfCompletedSources; bool opened; - const char *idStr; + const char* idStr; bool inMemSort; bool needAdjust; STupleHandle tupleHandle; - void *param; + void* param; void (*beforeFp)(SSDataBlock* pBlock, void* param); _sort_fetch_block_fn_t fetchfp; _sort_merge_compar_fn_t comparFn; - SMultiwayMergeTreeInfo *pMergeTree; + SMultiwayMergeTreeInfo* pMergeTree; }; -static int32_t msortComparFn(const void *pLeft, const void *pRight, void *param); +static int32_t msortComparFn(const void* pLeft, const void* pRight, void* param); SSDataBlock* tsortGetSortedDataBlock(const SSortHandle* pSortHandle) { return createOneDataBlock(pSortHandle->pDataBlock, false); @@ -71,20 +71,21 @@ SSDataBlock* tsortGetSortedDataBlock(const SSortHandle* pSortHandle) { * @param type * @return */ -SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, int32_t type, int32_t pageSize, int32_t numOfPages, SSDataBlock* pBlock, const char* idstr) { +SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, int32_t type, int32_t pageSize, int32_t numOfPages, + SSDataBlock* pBlock, const char* idstr) { SSortHandle* pSortHandle = taosMemoryCalloc(1, sizeof(SSortHandle)); - pSortHandle->type = type; - pSortHandle->pageSize = pageSize; + pSortHandle->type = type; + pSortHandle->pageSize = pageSize; pSortHandle->numOfPages = numOfPages; - pSortHandle->pSortInfo = pSortInfo; - pSortHandle->loops = 0; + pSortHandle->pSortInfo = pSortInfo; + pSortHandle->loops = 0; if (pBlock != NULL) { pSortHandle->pDataBlock = createOneDataBlock(pBlock, false); } - pSortHandle->pOrderedSource = taosArrayInit(4, POINTER_BYTES); + pSortHandle->pOrderedSource = taosArrayInit(4, POINTER_BYTES); pSortHandle->cmpParam.orderInfo = pSortInfo; pSortHandle->cmpParam.cmpGroupId = false; @@ -98,8 +99,9 @@ SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, int32_t type, int32_t page } static int32_t sortComparCleanup(SMsortComparParam* cmpParam) { - for(int32_t i = 0; i < cmpParam->numOfSources; ++i) { - SSortSource* pSource = cmpParam->pSources[i]; // NOTICE: pSource may be SGenericSource *, if it is SORT_MULTISOURCE_MERGE + for (int32_t i = 0; i < cmpParam->numOfSources; ++i) { + SSortSource* pSource = + cmpParam->pSources[i]; // NOTICE: pSource may be SGenericSource *, if it is SORT_MULTISOURCE_MERGE blockDataDestroy(pSource->src.pBlock); taosMemoryFreeClear(pSource); } @@ -121,7 +123,7 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) { destroyDiskbasedBuf(pSortHandle->pBuf); taosMemoryFreeClear(pSortHandle->idStr); blockDataDestroy(pSortHandle->pDataBlock); - for (size_t i = 0; i < taosArrayGetSize(pSortHandle->pOrderedSource); i++){ + for (size_t i = 0; i < taosArrayGetSize(pSortHandle->pOrderedSource); i++) { SSortSource** pSource = taosArrayGet(pSortHandle->pOrderedSource, i); taosMemoryFreeClear(*pSource); } @@ -134,7 +136,8 @@ int32_t tsortAddSource(SSortHandle* pSortHandle, void* pSource) { return TSDB_CODE_SUCCESS; } -static int32_t doAddNewExternalMemSource(SDiskbasedBuf *pBuf, SArray* pAllSources, SSDataBlock* pBlock, int32_t* sourceId, SArray* pPageIdList) { +static int32_t doAddNewExternalMemSource(SDiskbasedBuf* pBuf, SArray* pAllSources, SSDataBlock* pBlock, + int32_t* sourceId, SArray* pPageIdList) { SSortSource* pSource = taosMemoryCalloc(1, sizeof(SSortSource)); if (pSource == NULL) { return TSDB_CODE_QRY_OUT_OF_MEMORY; @@ -149,7 +152,8 @@ static int32_t doAddNewExternalMemSource(SDiskbasedBuf *pBuf, SArray* pAllSource int32_t rowSize = blockDataGetSerialRowSize(pSource->src.pBlock); // The value of numOfRows must be greater than 0, which is guaranteed by the previous memory allocation - int32_t numOfRows = (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(taosArrayGetSize(pBlock->pDataBlock)))/rowSize; + int32_t numOfRows = + (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(taosArrayGetSize(pBlock->pDataBlock))) / rowSize; ASSERT(numOfRows > 0); return blockDataEnsureCapacity(pSource->src.pBlock, numOfRows); } @@ -163,7 +167,8 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { qError("Add to buf failed since %s", terrstr(terrno)); return terrno; } - int32_t code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, "doAddToBuf", tsTempDir); + int32_t code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, + "doAddToBuf", tsTempDir); dBufSetPrintInfo(pHandle->pBuf); if (code != TSDB_CODE_SUCCESS) { return code; @@ -171,7 +176,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { } SArray* pPageIdList = taosArrayInit(4, sizeof(int32_t)); - while(start < pDataBlock->info.rows) { + while (start < pDataBlock->info.rows) { int32_t stop = 0; blockDataSplitRows(pDataBlock, pDataBlock->info.hasVarCol, start, &stop, pHandle->pageSize); SSDataBlock* p = blockDataExtractBlock(pDataBlock, start, stop - start + 1); @@ -180,7 +185,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { } int32_t pageId = -1; - void* pPage = getNewBufPage(pHandle->pBuf, &pageId); + void* pPage = getNewBufPage(pHandle->pBuf, &pageId); if (pPage == NULL) { blockDataDestroy(p); return terrno; @@ -188,7 +193,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { taosArrayPush(pPageIdList, &pageId); - int32_t size = blockDataGetSize(p) + sizeof(int32_t) + taosArrayGetSize(p->pDataBlock) * sizeof(int32_t); + int32_t size = blockDataGetSize(p) + sizeof(int32_t) + taosArrayGetSize(p->pDataBlock) * sizeof(int32_t); assert(size <= getBufPageSize(pHandle->pBuf)); blockDataToBuf(pPage, p); @@ -211,8 +216,9 @@ static void setCurrentSourceIsDone(SSortSource* pSource, SSortHandle* pHandle) { ++pHandle->numOfCompletedSources; } -static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int32_t startIndex, int32_t endIndex, SSortHandle* pHandle) { - cmpParam->pSources = taosArrayGet(pSources, startIndex); +static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int32_t startIndex, int32_t endIndex, + SSortHandle* pHandle) { + cmpParam->pSources = taosArrayGet(pSources, startIndex); cmpParam->numOfSources = (endIndex - startIndex + 1); int32_t code = 0; @@ -246,7 +252,8 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int qError("Sort compare init failed since %s", terrstr(terrno)); return code; } - code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, "sortComparInit", tsTempDir); + code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, + "sortComparInit", tsTempDir); dBufSetPrintInfo(pHandle->pBuf); if (code != TSDB_CODE_SUCCESS) { return code; @@ -267,12 +274,12 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int return code; } -static void appendOneRowToDataBlock(SSDataBlock *pBlock, const SSDataBlock* pSource, int32_t* rowIndex) { +static void appendOneRowToDataBlock(SSDataBlock* pBlock, const SSDataBlock* pSource, int32_t* rowIndex) { for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); SColumnInfoData* pSrcColInfo = taosArrayGet(pSource->pDataBlock, i); - bool isNull = colDataIsNull(pSrcColInfo, pSource->info.rows, *rowIndex, NULL); + bool isNull = colDataIsNull(pSrcColInfo, pSource->info.rows, *rowIndex, NULL); if (isNull) { colDataAppend(pColInfo, pBlock->info.rows, NULL, true); @@ -286,7 +293,8 @@ static void appendOneRowToDataBlock(SSDataBlock *pBlock, const SSDataBlock* pSou *rowIndex += 1; } -static int32_t adjustMergeTreeForNextTuple(SSortSource *pSource, SMultiwayMergeTreeInfo *pTree, SSortHandle *pHandle, int32_t* numOfCompleted) { +static int32_t adjustMergeTreeForNextTuple(SSortSource* pSource, SMultiwayMergeTreeInfo* pTree, SSortHandle* pHandle, + int32_t* numOfCompleted) { /* * load a new SDataBlock into memory of a given intermediate data-set source, * since it's last record in buffer has been chosen to be processed, as the winner of loser-tree @@ -295,7 +303,7 @@ static int32_t adjustMergeTreeForNextTuple(SSortSource *pSource, SMultiwayMergeT pSource->src.rowIndex = 0; if (pHandle->type == SORT_SINGLESOURCE_SORT) { - pSource->pageIndex ++; + pSource->pageIndex++; if (pSource->pageIndex >= taosArrayGetSize(pSource->pageIdList)) { (*numOfCompleted) += 1; pSource->src.rowIndex = -1; @@ -304,8 +312,8 @@ static int32_t adjustMergeTreeForNextTuple(SSortSource *pSource, SMultiwayMergeT } else { int32_t* pPgId = taosArrayGet(pSource->pageIdList, pSource->pageIndex); - void* pPage = getBufPage(pHandle->pBuf, *pPgId); - int32_t code = blockDataFromBuf(pSource->src.pBlock, pPage); + void* pPage = getBufPage(pHandle->pBuf, *pPgId); + int32_t code = blockDataFromBuf(pSource->src.pBlock, pPage); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -344,14 +352,14 @@ static int32_t adjustMergeTreeForNextTuple(SSortSource *pSource, SMultiwayMergeT static SSDataBlock* getSortedBlockDataInner(SSortHandle* pHandle, SMsortComparParam* cmpParam, int32_t capacity) { blockDataCleanup(pHandle->pDataBlock); - while(1) { + while (1) { if (cmpParam->numOfSources == pHandle->numOfCompletedSources) { break; } int32_t index = tMergeTreeGetChosenIndex(pHandle->pMergeTree); - SSortSource *pSource = (*cmpParam).pSources[index]; + SSortSource* pSource = (*cmpParam).pSources[index]; appendOneRowToDataBlock(pHandle->pDataBlock, pSource->src.pBlock, &pSource->src.rowIndex); int32_t code = adjustMergeTreeForNextTuple(pSource, pHandle->pMergeTree, pHandle, &pHandle->numOfCompletedSources); @@ -365,18 +373,18 @@ static SSDataBlock* getSortedBlockDataInner(SSortHandle* pHandle, SMsortComparPa } } - return (pHandle->pDataBlock->info.rows > 0)? pHandle->pDataBlock:NULL; + return (pHandle->pDataBlock->info.rows > 0) ? pHandle->pDataBlock : NULL; } -int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { - int32_t pLeftIdx = *(int32_t *)pLeft; - int32_t pRightIdx = *(int32_t *)pRight; +int32_t msortComparFn(const void* pLeft, const void* pRight, void* param) { + int32_t pLeftIdx = *(int32_t*)pLeft; + int32_t pRightIdx = *(int32_t*)pRight; - SMsortComparParam *pParam = (SMsortComparParam *)param; + SMsortComparParam* pParam = (SMsortComparParam*)param; - SArray *pInfo = pParam->orderInfo; + SArray* pInfo = pParam->orderInfo; - SSortSource* pLeftSource = pParam->pSources[pLeftIdx]; + SSortSource* pLeftSource = pParam->pSources[pLeftIdx]; SSortSource* pRightSource = pParam->pSources[pRightIdx]; // this input is exhausted, set the special value to denote this @@ -397,42 +405,44 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { } } - for(int32_t i = 0; i < pInfo->size; ++i) { + 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); - bool leftNull = false; + bool leftNull = false; if (pLeftColInfoData->hasNull) { if (pLeftBlock->pBlockAgg == NULL) { leftNull = colDataIsNull_s(pLeftColInfoData, pLeftSource->src.rowIndex); } else { - leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, pLeftBlock->pBlockAgg[i]); + leftNull = + colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, pLeftBlock->pBlockAgg[i]); } } SColumnInfoData* pRightColInfoData = TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->slotId); - bool rightNull = false; + bool rightNull = false; if (pRightColInfoData->hasNull) { if (pLeftBlock->pBlockAgg == NULL) { rightNull = colDataIsNull_s(pRightColInfoData, pRightSource->src.rowIndex); } else { - rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, pRightBlock->pBlockAgg[i]); + rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, + pRightBlock->pBlockAgg[i]); } } if (leftNull && rightNull) { - continue; // continue to next slot + continue; // continue to next slot } if (rightNull) { - return pOrder->nullFirst? 1:-1; + return pOrder->nullFirst ? 1 : -1; } if (leftNull) { - return pOrder->nullFirst? -1:1; + return pOrder->nullFirst ? -1 : 1; } - void* left1 = colDataGetData(pLeftColInfoData, pLeftSource->src.rowIndex); + void* left1 = colDataGetData(pLeftColInfoData, pLeftSource->src.rowIndex); void* right1 = colDataGetData(pRightColInfoData, pRightSource->src.rowIndex); __compar_fn_t fn = getKeyComparFunc(pLeftColInfoData->info.type, pOrder->order); @@ -464,8 +474,8 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { ", sort elapsed:%" PRId64 ", total elapsed:%" PRId64, pHandle->idStr, (int32_t)(sortPass + 1), s, pHandle->sortElapsed, pHandle->totalElapsed); } else { - qDebug("%s ordered source:%"PRIzu", available buf:%d, no need internal sort", pHandle->idStr, numOfSources, - pHandle->numOfPages); + qDebug("%s ordered source:%" PRIzu ", available buf:%d, no need internal sort", pHandle->idStr, numOfSources, + pHandle->numOfPages); } int32_t numOfRows = blockDataGetCapacityInRow(pHandle->pDataBlock, pHandle->pageSize); @@ -475,7 +485,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { pHandle->loops = sortPass + 2; size_t numOfSorted = taosArrayGetSize(pHandle->pOrderedSource); - for(int32_t t = 0; t < sortPass; ++t) { + for (int32_t t = 0; t < sortPass; ++t) { int64_t st = taosGetTimestampUs(); SArray* pResList = taosArrayInit(4, POINTER_BYTES); @@ -484,7 +494,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { int32_t sortGroup = (numOfSorted + numOfInputSources - 1) / numOfInputSources; // Only *numOfInputSources* can be loaded into buffer to perform the external sort. - for(int32_t i = 0; i < sortGroup; ++i) { + for (int32_t i = 0; i < sortGroup; ++i) { pHandle->sourceId += 1; int32_t end = (i + 1) * numOfInputSources - 1; @@ -499,7 +509,8 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { return code; } - code = tMergeTreeCreate(&pHandle->pMergeTree, pHandle->cmpParam.numOfSources, &pHandle->cmpParam, pHandle->comparFn); + code = + tMergeTreeCreate(&pHandle->pMergeTree, pHandle->cmpParam.numOfSources, &pHandle->cmpParam, pHandle->comparFn); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -512,14 +523,15 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { } int32_t pageId = -1; - void* pPage = getNewBufPage(pHandle->pBuf, &pageId); + void* pPage = getNewBufPage(pHandle->pBuf, &pageId); if (pPage == NULL) { return terrno; } taosArrayPush(pPageIdList, &pageId); - int32_t size = blockDataGetSize(pDataBlock) + sizeof(int32_t) + taosArrayGetSize(pDataBlock->pDataBlock) * sizeof(int32_t); + int32_t size = + blockDataGetSize(pDataBlock) + sizeof(int32_t) + taosArrayGetSize(pDataBlock->pDataBlock) * sizeof(int32_t); assert(size <= getBufPageSize(pHandle->pBuf)); blockDataToBuf(pPage, pDataBlock); @@ -551,8 +563,8 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { pHandle->totalElapsed += el; SDiskbasedBufStatis statis = getDBufStatis(pHandle->pBuf); - qDebug("%s %d round mergesort, elapsed:%"PRId64" readDisk:%.2f Kb, flushDisk:%.2f Kb", pHandle->idStr, t + 1, el, statis.loadBytes/1024.0, - statis.flushBytes/1024.0); + qDebug("%s %d round mergesort, elapsed:%" PRId64 " readDisk:%.2f Kb, flushDisk:%.2f Kb", pHandle->idStr, t + 1, el, + statis.loadBytes / 1024.0, statis.flushBytes / 1024.0); if (pHandle->type == SORT_MULTISOURCE_MERGE) { pHandle->type = SORT_SINGLESOURCE_SORT; @@ -645,7 +657,7 @@ static int32_t createInitialSources(SSortHandle* pHandle) { pHandle->inMemSort = true; pHandle->loops = 1; - pHandle->tupleHandle.rowIndex = -1; + pHandle->tupleHandle.rowIndex = -1; pHandle->tupleHandle.pBlock = pHandle->pDataBlock; return 0; } else { @@ -701,7 +713,8 @@ int32_t tsortClose(SSortHandle* pHandle) { return TSDB_CODE_SUCCESS; } -int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fetchFp, void (*fp)(SSDataBlock*, void*), void* param) { +int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fetchFp, void (*fp)(SSDataBlock*, void*), + void* param) { pHandle->fetchfp = fetchFp; pHandle->beforeFp = fp; pHandle->param = param; @@ -734,8 +747,8 @@ STupleHandle* tsortNextTuple(SSortHandle* pHandle) { return &pHandle->tupleHandle; } - int32_t index = tMergeTreeGetChosenIndex(pHandle->pMergeTree); - SSortSource *pSource = pHandle->cmpParam.pSources[index]; + int32_t index = tMergeTreeGetChosenIndex(pHandle->pMergeTree); + SSortSource* pSource = pHandle->cmpParam.pSources[index]; if (pHandle->needAdjust) { int32_t code = adjustMergeTreeForNextTuple(pSource, pHandle->pMergeTree, pHandle, &pHandle->numOfCompletedSources); @@ -778,16 +791,14 @@ void* tsortGetValue(STupleHandle* pVHandle, int32_t colIndex) { } } -uint64_t tsortGetGroupId(STupleHandle* pVHandle) { - return pVHandle->pBlock->info.groupId; -} +uint64_t tsortGetGroupId(STupleHandle* pVHandle) { return pVHandle->pBlock->info.groupId; } SSortExecInfo tsortGetSortExecInfo(SSortHandle* pHandle) { SSortExecInfo info = {0}; info.sortBuffer = pHandle->pageSize * pHandle->numOfPages; - info.sortMethod = pHandle->inMemSort? SORT_QSORT_T:SORT_SPILLED_MERGE_SORT_T; - info.loops = pHandle->loops; + info.sortMethod = pHandle->inMemSort ? SORT_QSORT_T : SORT_SPILLED_MERGE_SORT_T; + info.loops = pHandle->loops; if (pHandle->pBuf != NULL) { SDiskbasedBufStatis st = getDBufStatis(pHandle->pBuf); @@ -797,4 +808,3 @@ SSortExecInfo tsortGetSortExecInfo(SSortHandle* pHandle) { return info; } - diff --git a/source/libs/executor/test/lhashTests.cpp b/source/libs/executor/test/lhashTests.cpp index c9b75395bce345802ff0e563762758601aca0a18..24570ff7889aa09dcd160a8703be88e57bbc35c9 100644 --- a/source/libs/executor/test/lhashTests.cpp +++ b/source/libs/executor/test/lhashTests.cpp @@ -32,41 +32,42 @@ TEST(testCase, linear_hash_Tests) { int64_t st = taosGetTimestampUs(); - SLHashObj* pHashObj = tHashInit(4098*4*2, 512, fn, 40); - for(int32_t i = 0; i < 1000000; ++i) { + SLHashObj* pHashObj = tHashInit(4098 * 4 * 2, 512, fn, 40); + for (int32_t i = 0; i < 1000000; ++i) { int32_t code = tHashPut(pHashObj, &i, sizeof(i), &i, sizeof(i)); assert(code == 0); } -// tHashPrint(pHashObj, LINEAR_HASH_STATIS); + // tHashPrint(pHashObj, LINEAR_HASH_STATIS); int64_t et = taosGetTimestampUs(); - for(int32_t i = 0; i < 1000000; ++i) { + for (int32_t i = 0; i < 1000000; ++i) { if (i == 950000) { printf("kf\n"); } char* v = tHashGet(pHashObj, &i, sizeof(i)); if (v != NULL) { -// printf("find value: %d, key:%d\n", *(int32_t*) v, i); + // printf("find value: %d, key:%d\n", *(int32_t*) v, i); } else { -// printf("failed to found key:%d in hash\n", i); + // printf("failed to found key:%d in hash\n", i); } } -// tHashPrint(pHashObj, LINEAR_HASH_STATIS); + // tHashPrint(pHashObj, LINEAR_HASH_STATIS); tHashCleanup(pHashObj); int64_t et1 = taosGetTimestampUs(); SHashObj* pHashObj1 = taosHashInit(1000, fn, false, HASH_NO_LOCK); - for(int32_t i = 0; i < 1000000; ++i) { + for (int32_t i = 0; i < 1000000; ++i) { taosHashPut(pHashObj1, &i, sizeof(i), &i, sizeof(i)); } - for(int32_t i = 0; i < 1000000; ++i) { + for (int32_t i = 0; i < 1000000; ++i) { void* v = taosHashGet(pHashObj1, &i, sizeof(i)); } taosHashCleanup(pHashObj1); int64_t et2 = taosGetTimestampUs(); - printf("linear hash time:%.2f ms, buildHash:%.2f ms, hash:%.2f\n", (et1-st)/1000.0, (et-st)/1000.0, (et2-et1)/1000.0); + printf("linear hash time:%.2f ms, buildHash:%.2f ms, hash:%.2f\n", (et1 - st) / 1000.0, (et - st) / 1000.0, + (et2 - et1) / 1000.0); } \ No newline at end of file diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 4ac15670ac5dca547572df102f7267de08c0306d..62813453a1398f51bc2667879e9b7cf07194b449 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -25,14 +25,14 @@ #pragma GCC diagnostic ignored "-Wsign-compare" #include "os.h" -#include "executorimpl.h" #include "executor.h" +#include "executorimpl.h" #include "taos.h" +#include "tcompare.h" #include "tdatablock.h" #include "tdef.h" #include "trpc.h" #include "tvariant.h" -#include "tcompare.h" namespace { typedef struct { @@ -44,8 +44,7 @@ typedef struct { int16_t VARCOUNT = 16; -float rand_f2() -{ +float rand_f2() { unsigned r = taosRand(); r &= 0x007fffff; r |= 0x40800000; @@ -53,10 +52,10 @@ float rand_f2() } static const int32_t TEST_NUMBER = 1; -#define bigendian() ((*(char *)&TEST_NUMBER) == 0) +#define bigendian() ((*(char*)&TEST_NUMBER) == 0) SSDataBlock* getSingleColDummyBlock(void* param) { - _info* pInfo = (_info*) param; + _info* pInfo = (_info*)param; if (--pInfo->count < 0) { return NULL; } @@ -65,11 +64,11 @@ SSDataBlock* getSingleColDummyBlock(void* param) { SColumnInfoData colInfo = {0}; colInfo.info.type = pInfo->type; - if (pInfo->type == TSDB_DATA_TYPE_NCHAR){ + if (pInfo->type == TSDB_DATA_TYPE_NCHAR) { colInfo.info.bytes = TSDB_NCHAR_SIZE * VARCOUNT + VARSTR_HEADER_SIZE; - } else if(pInfo->type == TSDB_DATA_TYPE_BINARY) { + } else if (pInfo->type == TSDB_DATA_TYPE_BINARY) { colInfo.info.bytes = VARCOUNT + VARSTR_HEADER_SIZE; - } else{ + } else { colInfo.info.bytes = tDataTypes[pInfo->type].bytes; } colInfo.info.colId = 1; @@ -80,39 +79,39 @@ SSDataBlock* getSingleColDummyBlock(void* param) { for (int32_t i = 0; i < pInfo->pageRows; ++i) { SColumnInfoData* pColInfo = static_cast(TARRAY_GET_ELEM(pBlock->pDataBlock, 0)); - if (pInfo->type == TSDB_DATA_TYPE_NCHAR){ + if (pInfo->type == TSDB_DATA_TYPE_NCHAR) { int32_t size = taosRand() % VARCOUNT; - char str[128] = {0}; - char strOri[128] = {0}; + char str[128] = {0}; + char strOri[128] = {0}; taosRandStr(strOri, size); int32_t len = 0; - bool ret = taosMbsToUcs4(strOri, size, (TdUcs4*)varDataVal(str), size * TSDB_NCHAR_SIZE, &len); - if (!ret){ + bool ret = taosMbsToUcs4(strOri, size, (TdUcs4*)varDataVal(str), size * TSDB_NCHAR_SIZE, &len); + if (!ret) { printf("error\n"); return NULL; } varDataSetLen(str, len); colDataAppend(pColInfo, i, reinterpret_cast(str), false); pBlock->info.hasVarCol = true; - printf("nchar: %s\n",strOri); - } else if(pInfo->type == TSDB_DATA_TYPE_BINARY){ + printf("nchar: %s\n", strOri); + } else if (pInfo->type == TSDB_DATA_TYPE_BINARY) { int32_t size = taosRand() % VARCOUNT; - char str[64] = {0}; + char str[64] = {0}; taosRandStr(varDataVal(str), size); varDataSetLen(str, size); colDataAppend(pColInfo, i, reinterpret_cast(str), false); pBlock->info.hasVarCol = true; printf("binary: %s\n", varDataVal(str)); - } else if(pInfo->type == TSDB_DATA_TYPE_DOUBLE || pInfo->type == TSDB_DATA_TYPE_FLOAT) { + } else if (pInfo->type == TSDB_DATA_TYPE_DOUBLE || pInfo->type == TSDB_DATA_TYPE_FLOAT) { double v = rand_f2(); colDataAppend(pColInfo, i, reinterpret_cast(&v), false); printf("float: %f\n", v); - } else{ + } else { int64_t v = ++pInfo->startVal; - char *result = static_cast(taosMemoryCalloc(tDataTypes[pInfo->type].bytes, 1)); - if (!bigendian()){ + char* result = static_cast(taosMemoryCalloc(tDataTypes[pInfo->type].bytes, 1)); + if (!bigendian()) { memcpy(result, &v, tDataTypes[pInfo->type].bytes); - }else{ + } else { memcpy(result, (char*)(&v) + sizeof(int64_t) - tDataTypes[pInfo->type].bytes, tDataTypes[pInfo->type].bytes); } @@ -126,17 +125,16 @@ SSDataBlock* getSingleColDummyBlock(void* param) { return pBlock; } - int32_t docomp(const void* p1, const void* p2, void* param) { - int32_t pLeftIdx = *(int32_t *)p1; - int32_t pRightIdx = *(int32_t *)p2; + int32_t pLeftIdx = *(int32_t*)p1; + int32_t pRightIdx = *(int32_t*)p2; - SMsortComparParam *pParam = (SMsortComparParam *)param; - SSortSource** px = reinterpret_cast(pParam->pSources); + SMsortComparParam* pParam = (SMsortComparParam*)param; + SSortSource** px = reinterpret_cast(pParam->pSources); - SArray *pInfo = pParam->orderInfo; + SArray* pInfo = pParam->orderInfo; - SSortSource* pLeftSource = px[pLeftIdx]; + SSortSource* pLeftSource = px[pLeftIdx]; SSortSource* pRightSource = px[pRightIdx]; // this input is exhausted, set the special value to denote this @@ -151,36 +149,38 @@ int32_t docomp(const void* p1, const void* p2, void* param) { SSDataBlock* pLeftBlock = pLeftSource->src.pBlock; SSDataBlock* pRightBlock = pRightSource->src.pBlock; - for(int32_t i = 0; i < pInfo->size; ++i) { + for (int32_t i = 0; i < pInfo->size; ++i) { SBlockOrderInfo* pOrder = (SBlockOrderInfo*)TARRAY_GET_ELEM(pInfo, i); SColumnInfoData* pLeftColInfoData = (SColumnInfoData*)TARRAY_GET_ELEM(pLeftBlock->pDataBlock, pOrder->slotId); - bool leftNull = false; + bool leftNull = false; if (pLeftColInfoData->hasNull) { - leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, pLeftBlock->pBlockAgg[pOrder->slotId]); + leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, + pLeftBlock->pBlockAgg[pOrder->slotId]); } - SColumnInfoData* pRightColInfoData = (SColumnInfoData*) TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->slotId); - bool rightNull = false; + SColumnInfoData* pRightColInfoData = (SColumnInfoData*)TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->slotId); + bool rightNull = false; if (pRightColInfoData->hasNull) { - rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, pRightBlock->pBlockAgg[pOrder->slotId]); + rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, + pRightBlock->pBlockAgg[pOrder->slotId]); } if (leftNull && rightNull) { - continue; // continue to next slot + continue; // continue to next slot } if (rightNull) { - return pOrder->nullFirst? 1:-1; + return pOrder->nullFirst ? 1 : -1; } if (leftNull) { - return pOrder->nullFirst? -1:1; + return pOrder->nullFirst ? -1 : 1; } - void* left1 = colDataGetData(pLeftColInfoData, pLeftSource->src.rowIndex); - void* right1 = colDataGetData(pRightColInfoData, pRightSource->src.rowIndex); + void* left1 = colDataGetData(pLeftColInfoData, pLeftSource->src.rowIndex); + void* right1 = colDataGetData(pRightColInfoData, pRightSource->src.rowIndex); __compar_fn_t fn = getKeyComparFunc(pLeftColInfoData->info.type, pOrder->order); int ret = fn(left1, right1); diff --git a/source/libs/executor/test/tSimpleHashTests.cpp b/source/libs/executor/test/tSimpleHashTests.cpp index 3bf339ef9040879c0978f9bedffb2b23bd8ec806..3fbf2e7be8c894211e48ef2e33cfbac419fd18c0 100644 --- a/source/libs/executor/test/tSimpleHashTests.cpp +++ b/source/libs/executor/test/tSimpleHashTests.cpp @@ -31,8 +31,7 @@ // } TEST(testCase, tSimpleHashTest_intKey) { - SSHashObj *pHashObj = - tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT)); + SSHashObj *pHashObj = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT)); assert(pHashObj != nullptr); @@ -76,10 +75,8 @@ TEST(testCase, tSimpleHashTest_intKey) { tSimpleHashCleanup(pHashObj); } - TEST(testCase, tSimpleHashTest_binaryKey) { - SSHashObj *pHashObj = - tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT)); + SSHashObj *pHashObj = tSimpleHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT)); assert(pHashObj != nullptr); @@ -93,7 +90,7 @@ TEST(testCase, tSimpleHashTest_binaryKey) { size_t keyLen = sizeof(SCombineKey); size_t dataLen = sizeof(int64_t); - int64_t originDataSum = 0; + int64_t originDataSum = 0; SCombineKey combineKey = {0}; for (int64_t i = 1; i <= 100; ++i) { combineKey.suid = i; @@ -140,5 +137,4 @@ TEST(testCase, tSimpleHashTest_binaryKey) { tSimpleHashCleanup(pHashObj); } - #pragma GCC diagnostic pop \ No newline at end of file diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index 0880f2f5c73f5715174165e0325839ade28990c8..b5b7453e7a7ec98bd86038d8ffebf25ee2a1367f 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -23,37 +23,37 @@ extern "C" { #include "function.h" #include "functionMgt.h" -bool dummyGetEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* UNUSED_PARAM(pEnv)); -bool dummyInit(SqlFunctionCtx* UNUSED_PARAM(pCtx), SResultRowEntryInfo* UNUSED_PARAM(pResultInfo)); +bool dummyGetEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* UNUSED_PARAM(pEnv)); +bool dummyInit(SqlFunctionCtx* UNUSED_PARAM(pCtx), SResultRowEntryInfo* UNUSED_PARAM(pResultInfo)); int32_t dummyProcess(SqlFunctionCtx* UNUSED_PARAM(pCtx)); int32_t dummyFinalize(SqlFunctionCtx* UNUSED_PARAM(pCtx), SSDataBlock* UNUSED_PARAM(pBlock)); -bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +bool functionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t functionFinalizeWithResultBuf(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, char* finalResult); int32_t combineFunction(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow); -bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -int32_t countFunction(SqlFunctionCtx *pCtx); -int32_t countInvertFunction(SqlFunctionCtx *pCtx); +bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +int32_t countFunction(SqlFunctionCtx* pCtx); +int32_t countInvertFunction(SqlFunctionCtx* pCtx); EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow); -bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -int32_t sumFunction(SqlFunctionCtx *pCtx); -int32_t sumInvertFunction(SqlFunctionCtx *pCtx); -int32_t sumCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); +bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +int32_t sumFunction(SqlFunctionCtx* pCtx); +int32_t sumInvertFunction(SqlFunctionCtx* pCtx); +int32_t sumCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); -bool minmaxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); -bool getMinmaxFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool minmaxFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); +bool getMinmaxFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t minFunction(SqlFunctionCtx* pCtx); -int32_t maxFunction(SqlFunctionCtx *pCtx); +int32_t maxFunction(SqlFunctionCtx* pCtx); int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t minCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); int32_t maxCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); -bool getAvgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool avgFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +bool getAvgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool avgFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t avgFunction(SqlFunctionCtx* pCtx); int32_t avgFunctionMerge(SqlFunctionCtx* pCtx); int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); @@ -62,8 +62,8 @@ int32_t avgInvertFunction(SqlFunctionCtx* pCtx); int32_t avgCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); int32_t getAvgInfoSize(); -bool getStddevFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool stddevFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +bool getStddevFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool stddevFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t stddevFunction(SqlFunctionCtx* pCtx); int32_t stddevFunctionMerge(SqlFunctionCtx* pCtx); int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); @@ -72,63 +72,63 @@ int32_t stddevInvertFunction(SqlFunctionCtx* pCtx); int32_t stddevCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); int32_t getStddevInfoSize(); -bool getLeastSQRFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool leastSQRFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +bool getLeastSQRFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool leastSQRFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t leastSQRFunction(SqlFunctionCtx* pCtx); int32_t leastSQRFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t leastSQRInvertFunction(SqlFunctionCtx* pCtx); int32_t leastSQRCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); -bool getPercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool percentileFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); -int32_t percentileFunction(SqlFunctionCtx *pCtx); +bool getPercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool percentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); +int32_t percentileFunction(SqlFunctionCtx* pCtx); int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); -bool getApercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool apercentileFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); -int32_t apercentileFunction(SqlFunctionCtx *pCtx); +bool getApercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool apercentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); +int32_t apercentileFunction(SqlFunctionCtx* pCtx); int32_t apercentileFunctionMerge(SqlFunctionCtx* pCtx); int32_t apercentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t apercentilePartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t apercentileCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); int32_t getApercentileMaxSize(); -bool getDiffFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool diffFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo); -int32_t diffFunction(SqlFunctionCtx *pCtx); +bool getDiffFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool diffFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo); +int32_t diffFunction(SqlFunctionCtx* pCtx); -bool getDerivativeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool derivativeFuncSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo); -int32_t derivativeFunction(SqlFunctionCtx *pCtx); +bool getDerivativeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool derivativeFuncSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo); +int32_t derivativeFunction(SqlFunctionCtx* pCtx); -bool getIrateFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool irateFuncSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo); -int32_t irateFunction(SqlFunctionCtx *pCtx); +bool getIrateFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool irateFuncSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo); +int32_t irateFunction(SqlFunctionCtx* pCtx); int32_t irateFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t cachedLastRowFunction(SqlFunctionCtx* pCtx); -bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -int32_t firstFunction(SqlFunctionCtx *pCtx); -int32_t firstFunctionMerge(SqlFunctionCtx *pCtx); -int32_t lastFunction(SqlFunctionCtx *pCtx); -int32_t lastFunctionMerge(SqlFunctionCtx *pCtx); -int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); -int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); -int32_t firstCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); -int32_t lastCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); -int32_t getFirstLastInfoSize(int32_t resBytes); +bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +int32_t firstFunction(SqlFunctionCtx* pCtx); +int32_t firstFunctionMerge(SqlFunctionCtx* pCtx); +int32_t lastFunction(SqlFunctionCtx* pCtx); +int32_t lastFunctionMerge(SqlFunctionCtx* pCtx); +int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); +int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); +int32_t firstCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); +int32_t lastCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); +int32_t getFirstLastInfoSize(int32_t resBytes); EFuncDataRequired lastDynDataReq(void* pRes, STimeWindow* pTimeWindow); -int32_t lastRowFunction(SqlFunctionCtx *pCtx); +int32_t lastRowFunction(SqlFunctionCtx* pCtx); -bool getTopBotFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv); -bool getTopBotMergeFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv); -bool topBotFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); -int32_t topFunction(SqlFunctionCtx *pCtx); -int32_t topFunctionMerge(SqlFunctionCtx *pCtx); -int32_t bottomFunction(SqlFunctionCtx *pCtx); -int32_t bottomFunctionMerge(SqlFunctionCtx *pCtx); +bool getTopBotFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv); +bool getTopBotMergeFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv); +bool topBotFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); +int32_t topFunction(SqlFunctionCtx* pCtx); +int32_t topFunctionMerge(SqlFunctionCtx* pCtx); +int32_t bottomFunction(SqlFunctionCtx* pCtx); +int32_t bottomFunctionMerge(SqlFunctionCtx* pCtx); int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t topBotPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t topBotMergeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); @@ -136,8 +136,8 @@ int32_t topCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); int32_t bottomCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); int32_t getTopBotInfoSize(int64_t numOfItems); -bool getSpreadFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool spreadFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +bool getSpreadFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool spreadFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t spreadFunction(SqlFunctionCtx* pCtx); int32_t spreadFunctionMerge(SqlFunctionCtx* pCtx); int32_t spreadFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); @@ -145,8 +145,8 @@ int32_t spreadPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t getSpreadInfoSize(); int32_t spreadCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); -bool getElapsedFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool elapsedFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +bool getElapsedFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool elapsedFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t elapsedFunction(SqlFunctionCtx* pCtx); int32_t elapsedFunctionMerge(SqlFunctionCtx* pCtx); int32_t elapsedFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); @@ -154,8 +154,8 @@ int32_t elapsedPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t getElapsedInfoSize(); int32_t elapsedCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); -bool getHistogramFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool histogramFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +bool getHistogramFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool histogramFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t histogramFunction(SqlFunctionCtx* pCtx); int32_t histogramFunctionPartial(SqlFunctionCtx* pCtx); int32_t histogramFunctionMerge(SqlFunctionCtx* pCtx); @@ -164,7 +164,7 @@ int32_t histogramPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t getHistogramInfoSize(); int32_t histogramCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); -bool getHLLFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool getHLLFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t hllFunction(SqlFunctionCtx* pCtx); int32_t hllFunctionMerge(SqlFunctionCtx* pCtx); int32_t hllFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); @@ -172,48 +172,48 @@ int32_t hllPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t getHLLInfoSize(); int32_t hllCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); -bool getStateFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool stateFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +bool getStateFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool stateFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t stateCountFunction(SqlFunctionCtx* pCtx); int32_t stateDurationFunction(SqlFunctionCtx* pCtx); -bool getCsumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool getCsumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t csumFunction(SqlFunctionCtx* pCtx); -bool getMavgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool mavgFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +bool getMavgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool mavgFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t mavgFunction(SqlFunctionCtx* pCtx); -bool getSampleFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool sampleFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +bool getSampleFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool sampleFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t sampleFunction(SqlFunctionCtx* pCtx); int32_t sampleFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); -bool getTailFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool tailFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +bool getTailFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool tailFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t tailFunction(SqlFunctionCtx* pCtx); -bool getUniqueFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool uniqueFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); -int32_t uniqueFunction(SqlFunctionCtx *pCtx); +bool getUniqueFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool uniqueFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); +int32_t uniqueFunction(SqlFunctionCtx* pCtx); -bool getModeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool modeFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); -int32_t modeFunction(SqlFunctionCtx *pCtx); +bool getModeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool modeFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); +int32_t modeFunction(SqlFunctionCtx* pCtx); int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); -bool getTwaFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool twaFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); -int32_t twaFunction(SqlFunctionCtx *pCtx); -int32_t twaFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock); +bool getTwaFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool twaFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); +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); +bool blockDistSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); +int32_t blockDistFunction(SqlFunctionCtx* pCtx); int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); -bool getGroupKeyFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool getGroupKeyFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t groupKeyFunction(SqlFunctionCtx* pCtx); int32_t groupKeyFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); diff --git a/source/libs/function/inc/tfunctionInt.h b/source/libs/function/inc/tfunctionInt.h index 8f6cbc977effcbab902cb01adf71a9dd42f0d724..821544106fc01ab1332c7bc531b5be26485e0300 100644 --- a/source/libs/function/inc/tfunctionInt.h +++ b/source/libs/function/inc/tfunctionInt.h @@ -22,11 +22,11 @@ extern "C" { #include "os.h" -#include "tname.h" -#include "taosdef.h" -#include "tvariant.h" #include "function.h" +#include "taosdef.h" +#include "tname.h" #include "tudf.h" +#include "tvariant.h" bool topbot_datablock_filter(SqlFunctionCtx *pCtx, const char *minval, const char *maxval); @@ -37,8 +37,8 @@ bool topbot_datablock_filter(SqlFunctionCtx *pCtx, const char *minval, const cha static FORCE_INLINE void initResultRowEntry(SResultRowEntryInfo *pResInfo, int32_t bufLen) { pResInfo->initialized = true; // the this struct has been initialized flag - pResInfo->complete = false; - pResInfo->numOfRes = 0; + pResInfo->complete = false; + pResInfo->numOfRes = 0; memset(GET_ROWCELL_INTERBUF(pResInfo), 0, bufLen); } diff --git a/source/libs/function/inc/thistogram.h b/source/libs/function/inc/thistogram.h index cb6560325bb959ec74a0b34eb89476b353038c24..20111086cd1342600f33cd7a36174d8fbaf5fc8a 100644 --- a/source/libs/function/inc/thistogram.h +++ b/source/libs/function/inc/thistogram.h @@ -43,15 +43,15 @@ typedef struct SHistogramInfo { int64_t numOfElems; int32_t numOfEntries; int32_t maxEntries; - double min; - double max; + double min; + double max; #if defined(USE_ARRAYLIST) SHistBin* elems; #else - tSkipList* pList; + tSkipList* pList; SMultiwayMergeTreeInfo* pLoserTree; - int32_t maxIndex; - bool ordered; + int32_t maxIndex; + bool ordered; #endif } SHistogramInfo; @@ -61,16 +61,16 @@ SHistogramInfo* tHistogramCreateFrom(void* pBuf, int32_t numOfBins); int32_t tHistogramAdd(SHistogramInfo** pHisto, double val); int64_t tHistogramSum(SHistogramInfo* pHisto, double v); -double* tHistogramUniform(SHistogramInfo* pHisto, double* ratio, int32_t num); +double* tHistogramUniform(SHistogramInfo* pHisto, double* ratio, int32_t num); SHistogramInfo* tHistogramMerge(SHistogramInfo* pHisto1, SHistogramInfo* pHisto2, int32_t numOfEntries); -void tHistogramDestroy(SHistogramInfo** pHisto); +void tHistogramDestroy(SHistogramInfo** pHisto); void tHistogramPrint(SHistogramInfo* pHisto); int32_t histoBinarySearch(SHistBin* pEntry, int32_t len, double val); SHeapEntry* tHeapCreate(int32_t numOfEntries); -void tHeapSort(SHeapEntry* pEntry, int32_t len); +void tHeapSort(SHeapEntry* pEntry, int32_t len); #ifdef __cplusplus } diff --git a/source/libs/function/inc/tpercentile.h b/source/libs/function/inc/tpercentile.h index 554f9e567f35cc0272a2a9755153de1b54d34392..873dc46a0890bd6659e86feb294539dddc3a031a 100644 --- a/source/libs/function/inc/tpercentile.h +++ b/source/libs/function/inc/tpercentile.h @@ -61,10 +61,10 @@ typedef struct tMemBucket { MinMaxEntry range; // value range int32_t times; // count that has been checked for deciding the correct data value buckets. __compar_fn_t comparFn; - tMemBucketSlot* pSlots; - SDiskbasedBuf* pBuffer; + tMemBucketSlot *pSlots; + SDiskbasedBuf *pBuffer; __perc_hash_func_t hashFunc; - SHashObj* groupPagesMap; // disk page map for different groups; + SHashObj *groupPagesMap; // disk page map for different groups; } tMemBucket; tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, double maxval); diff --git a/source/libs/function/inc/tscript.h b/source/libs/function/inc/tscript.h index 823e2d61f2baa9a107c59608d757de0f673cc38b..730d29a8c9426f9485931ee13cd61e021c325375 100644 --- a/source/libs/function/inc/tscript.h +++ b/source/libs/function/inc/tscript.h @@ -17,18 +17,18 @@ #define TDENGINE_QSCRIPT_H #if 0 -#include #include +#include #include -#include "tutil.h" #include "hash.h" #include "tlist.h" #include "tudf.h" +#include "tutil.h" #define MAX_FUNC_NAME 64 -#define USER_FUNC_NAME "funcName" +#define USER_FUNC_NAME "funcName" #define USER_FUNC_NAME_LIMIT 48 enum ScriptState { @@ -81,4 +81,4 @@ void scriptEnvPoolCleanup(); bool isValidScript(char *script, int32_t len); #endif -#endif //TDENGINE_QSCRIPT_H +#endif // TDENGINE_QSCRIPT_H diff --git a/source/libs/function/inc/tudfInt.h b/source/libs/function/inc/tudfInt.h index 6f82542aee6966d8b4fd7c613263a0639be190a3..c1b0941d4bd7c7e987999a16357263f87e34dbfc 100644 --- a/source/libs/function/inc/tudfInt.h +++ b/source/libs/function/inc/tudfInt.h @@ -40,33 +40,31 @@ typedef struct SUdfSetupRequest { typedef struct SUdfSetupResponse { int64_t udfHandle; - int8_t outputType; + int8_t outputType; int32_t outputLen; int32_t bufSize; } SUdfSetupResponse; typedef struct SUdfCallRequest { int64_t udfHandle; - int8_t callType; + int8_t callType; - SSDataBlock block; + SSDataBlock block; SUdfInterBuf interBuf; SUdfInterBuf interBuf2; - int8_t initFirst; + int8_t initFirst; } SUdfCallRequest; typedef struct SUdfCallResponse { - int8_t callType; - SSDataBlock resultData; + int8_t callType; + SSDataBlock resultData; SUdfInterBuf resultBuf; } SUdfCallResponse; - typedef struct SUdfTeardownRequest { int64_t udfHandle; } SUdfTeardownRequest; - typedef struct SUdfTeardownResponse { #ifdef WINDOWS size_t avoidCompilationErrors; @@ -79,8 +77,8 @@ typedef struct SUdfRequest { int8_t type; union { - SUdfSetupRequest setup; - SUdfCallRequest call; + SUdfSetupRequest setup; + SUdfCallRequest call; SUdfTeardownRequest teardown; }; } SUdfRequest; @@ -89,29 +87,29 @@ typedef struct SUdfResponse { int32_t msgLen; int64_t seqNum; - int8_t type; + int8_t type; int32_t code; union { - SUdfSetupResponse setupRsp; - SUdfCallResponse callRsp; + SUdfSetupResponse setupRsp; + SUdfCallResponse callRsp; SUdfTeardownResponse teardownRsp; }; } SUdfResponse; -int32_t encodeUdfRequest(void **buf, const SUdfRequest* request); -void* decodeUdfRequest(const void *buf, SUdfRequest* request); +int32_t encodeUdfRequest(void **buf, const SUdfRequest *request); +void *decodeUdfRequest(const void *buf, SUdfRequest *request); int32_t encodeUdfResponse(void **buf, const SUdfResponse *response); -void* decodeUdfResponse(const void* buf, SUdfResponse *response); +void *decodeUdfResponse(const void *buf, SUdfResponse *response); void freeUdfColumnData(SUdfColumnData *data, SUdfColumnMeta *meta); -void freeUdfColumn(SUdfColumn* col); +void freeUdfColumn(SUdfColumn *col); void freeUdfDataDataBlock(SUdfDataBlock *block); int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlock); int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block); -int32_t getUdfdPipeName(char* pipeName, int32_t size); +int32_t getUdfdPipeName(char *pipeName, int32_t size); #ifdef __cplusplus } #endif diff --git a/source/libs/function/inc/udfc.h b/source/libs/function/inc/udfc.h index f414c2b29e85089404e74f03fa4dcb875650d41f..c46e500ccbf035fc9424a3bc961f6f0f81abe650 100644 --- a/source/libs/function/inc/udfc.h +++ b/source/libs/function/inc/udfc.h @@ -14,20 +14,20 @@ #endif enum { - UDF_TASK_SETUP = 0, - UDF_TASK_CALL = 1, - UDF_TASK_TEARDOWN = 2 + UDF_TASK_SETUP = 0, + UDF_TASK_CALL = 1, + UDF_TASK_TEARDOWN = 2 }; -typedef struct SSDataBlock{ - char *data; - int32_t size; +typedef struct SSDataBlock { + char *data; + int32_t size; } SSDataBlock; typedef struct SUdfInfo { - char *udfName; - char *path; + char *udfName; + char *path; } SUdfInfo; typedef void *UdfcFuncHandle; @@ -36,9 +36,9 @@ int32_t createUdfdProxy(); int32_t destroyUdfdProxy(); -//int32_t setupUdf(SUdfInfo *udf, int32_t numOfUdfs, UdfcFuncHandle *handles); +// int32_t setupUdf(SUdfInfo *udf, int32_t numOfUdfs, UdfcFuncHandle *handles); -int32_t setupUdf(SUdfInfo* udf, UdfcFuncHandle* handle); +int32_t setupUdf(SUdfInfo *udf, UdfcFuncHandle *handle); int32_t callUdf(UdfcFuncHandle handle, int8_t step, char *state, int32_t stateSize, SSDataBlock input, char **newstate, int32_t *newStateSize, SSDataBlock *output); @@ -46,43 +46,39 @@ int32_t callUdf(UdfcFuncHandle handle, int8_t step, char *state, int32_t stateSi int32_t doTeardownUdf(UdfcFuncHandle handle); typedef struct SUdfSetupRequest { - char udfName[16]; // - int8_t scriptType; // 0:c, 1: lua, 2:js - int8_t udfType; //udaf, udf, udtf - int16_t pathSize; - char *path; + char udfName[16]; // + int8_t scriptType; // 0:c, 1: lua, 2:js + int8_t udfType; // udaf, udf, udtf + int16_t pathSize; + char *path; } SUdfSetupRequest; typedef struct SUdfSetupResponse { - int64_t udfHandle; + int64_t udfHandle; } SUdfSetupResponse; - typedef struct SUdfCallRequest { - int64_t udfHandle; - int8_t step; + int64_t udfHandle; + int8_t step; - int32_t inputBytes; - char *input; + int32_t inputBytes; + char *input; - int32_t stateBytes; - char *state; + int32_t stateBytes; + char *state; } SUdfCallRequest; - typedef struct SUdfCallResponse { - int32_t outputBytes; - char *output; - int32_t newStateBytes; - char *newState; + int32_t outputBytes; + char *output; + int32_t newStateBytes; + char *newState; } SUdfCallResponse; - typedef struct SUdfTeardownRequest { - int64_t udfHandle; + int64_t udfHandle; } SUdfTeardownRequest; - typedef struct SUdfTeardownResponse { #ifdef WINDOWS size_t avoidCompilationErrors; @@ -90,24 +86,24 @@ typedef struct SUdfTeardownResponse { } SUdfTeardownResponse; typedef struct SUdfRequest { - int32_t msgLen; - int64_t seqNum; + int32_t msgLen; + int64_t seqNum; - int8_t type; - void *subReq; + int8_t type; + void *subReq; } SUdfRequest; typedef struct SUdfResponse { - int32_t msgLen; - int64_t seqNum; + int32_t msgLen; + int64_t seqNum; - int8_t type; - int32_t code; - void *subRsp; + int8_t type; + int32_t code; + void *subRsp; } SUdfResponse; int32_t decodeRequest(char *buf, int32_t bufLen, SUdfRequest **pRequest); int32_t encodeResponse(char **buf, int32_t *bufLen, SUdfResponse *response); int32_t encodeRequest(char **buf, int32_t *bufLen, SUdfRequest *request); int32_t decodeResponse(char *buf, int32_t bufLen, SUdfResponse **pResponse); -#endif //UDF_UDF_H +#endif // UDF_UDF_H diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index d91423ab5c3adbde9932e409d17e59060460183e..7077a9b780c16ce7decc331cd553f62007b58648 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -1557,8 +1557,8 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { numOfElems += 1; } } else if (type == TSDB_DATA_TYPE_FLOAT) { - float* pData = (float*)pCol->pData; - float* val = (float*)&pBuf->v; + float* pData = (float*)pCol->pData; + float* val = (float*)&pBuf->v; for (int32_t i = start; i < start + numOfRows; ++i) { if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) { @@ -2977,7 +2977,8 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) { return TSDB_CODE_SUCCESS; } -static void firstLastTransferInfo(SqlFunctionCtx* pCtx, SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst, int32_t rowIndex) { +static void firstLastTransferInfo(SqlFunctionCtx* pCtx, SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst, + int32_t rowIndex) { SInputColumnInfoData* pColInfo = &pCtx->input; if (pOutput->hasResult) { diff --git a/source/libs/function/src/tfunctionInt.c b/source/libs/function/src/tfunctionInt.c index ff15b7714f7473794b48b28d9cbb46a910ec339f..70378df0c3315c03989ae673ec50ecf1a47d8278 100644 --- a/source/libs/function/src/tfunctionInt.c +++ b/source/libs/function/src/tfunctionInt.c @@ -15,8 +15,8 @@ #include "os.h" #include "taosdef.h" -#include "tmsg.h" #include "thash.h" +#include "tmsg.h" #include "ttypes.h" #include "function.h" @@ -29,15 +29,13 @@ #include "ttszip.h" #include "tudf.h" -void cleanupResultRowEntry(struct SResultRowEntryInfo* pCell) { - pCell->initialized = false; -} +void cleanupResultRowEntry(struct SResultRowEntryInfo* pCell) { pCell->initialized = false; } int32_t getNumOfResult(SqlFunctionCtx* pCtx, int32_t num, SSDataBlock* pResBlock) { int32_t maxRows = 0; for (int32_t j = 0; j < num; ++j) { - SResultRowEntryInfo *pResInfo = GET_RES_INFO(&pCtx[j]); + SResultRowEntryInfo* pResInfo = GET_RES_INFO(&pCtx[j]); if (pResInfo != NULL && maxRows < pResInfo->numOfRes) { maxRows = pResInfo->numOfRes; } @@ -46,12 +44,12 @@ int32_t getNumOfResult(SqlFunctionCtx* pCtx, int32_t num, SSDataBlock* pResBlock assert(maxRows >= 0); blockDataEnsureCapacity(pResBlock, maxRows); - for(int32_t i = 0; i < num; ++i) { + for (int32_t i = 0; i < num; ++i) { SColumnInfoData* pCol = taosArrayGet(pResBlock->pDataBlock, i); - SResultRowEntryInfo *pResInfo = GET_RES_INFO(&pCtx[i]); + SResultRowEntryInfo* pResInfo = GET_RES_INFO(&pCtx[i]); if (pResInfo->numOfRes == 0) { - for(int32_t j = 0; j < pResInfo->numOfRes; ++j) { + for (int32_t j = 0; j < pResInfo->numOfRes; ++j) { colDataAppend(pCol, j, NULL, true); // TODO add set null data api } } else { @@ -70,6 +68,4 @@ bool isRowEntryCompleted(struct SResultRowEntryInfo* pEntry) { return pEntry->complete; } -bool isRowEntryInitialized(struct SResultRowEntryInfo* pEntry) { - return pEntry->initialized; -} +bool isRowEntryInitialized(struct SResultRowEntryInfo* pEntry) { return pEntry->initialized; } diff --git a/source/libs/function/src/thistogram.c b/source/libs/function/src/thistogram.c index 2e60498aba4d339edb5346107c44fac109d54761..b0f23f78df72afa23015a947632e024082cacd46 100644 --- a/source/libs/function/src/thistogram.c +++ b/source/libs/function/src/thistogram.c @@ -14,10 +14,10 @@ */ #include "os.h" -#include "thistogram.h" #include "taosdef.h" -#include "tmsg.h" +#include "thistogram.h" #include "tlosertree.h" +#include "tmsg.h" /** * @@ -54,7 +54,7 @@ SHistogramInfo* tHistogramCreateFrom(void* pBuf, int32_t numOfBins) { SHistogramInfo* pHisto = (SHistogramInfo*)pBuf; pHisto->elems = (SHistBin*)((char*)pBuf + sizeof(SHistogramInfo)); - for(int32_t i = 0; i < numOfBins; ++i) { + for (int32_t i = 0; i < numOfBins; ++i) { pHisto->elems[i].val = -DBL_MAX; } @@ -116,7 +116,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) { pEntry1->delta = ((SHistBin*)pResNode->pForward[0]->pData)->val - val; if ((*pHisto)->ordered) { - int32_t lastIndex = (*pHisto)->maxIndex; + int32_t lastIndex = (*pHisto)->maxIndex; SMultiwayMergeTreeInfo* pTree = (*pHisto)->pLoserTree; (*pHisto)->pLoserTree->pNode[lastIndex + pTree->numOfEntries].pData = pResNode; @@ -156,7 +156,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) { SSkipListPrint((*pHisto)->pList, 1); SMultiwayMergeTreeInfo* pTree = (*pHisto)->pLoserTree; - tSkipListNode* pHead = (*pHisto)->pList->pHead.pForward[0]; + tSkipListNode* pHead = (*pHisto)->pList->pHead.pForward[0]; tSkipListNode* p1 = pHead; @@ -357,7 +357,7 @@ void tHistogramDestroy(SHistogramInfo** pHisto) { } void tHistogramPrint(SHistogramInfo* pHisto) { - printf("total entries: %d, elements: %"PRId64 "\n", pHisto->numOfEntries, pHisto->numOfElems); + printf("total entries: %d, elements: %" PRId64 "\n", pHisto->numOfEntries, pHisto->numOfElems); #if defined(USE_ARRAYLIST) for (int32_t i = 0; i < pHisto->numOfEntries; ++i) { printf("%d: (%f, %" PRId64 ")\n", i + 1, pHisto->elems[i].val, pHisto->elems[i].num); @@ -536,7 +536,7 @@ SHistogramInfo* tHistogramMerge(SHistogramInfo* pHisto1, SHistogramInfo* pHisto2 } SHistBin* pHistoBins = taosMemoryCalloc(1, sizeof(SHistBin) * (pHisto1->numOfEntries + pHisto2->numOfEntries)); - int32_t i = 0, j = 0, k = 0; + int32_t i = 0, j = 0, k = 0; while (i < pHisto1->numOfEntries && j < pHisto2->numOfEntries) { if (pHisto1->elems[i].val < pHisto2->elems[j].val) { diff --git a/source/libs/function/src/tpercentile.c b/source/libs/function/src/tpercentile.c index 4c58c0abe50e5784314445934618265231d4805a..62c5e4b28b9b755b68402ef90405290f3c6d40d1 100644 --- a/source/libs/function/src/tpercentile.c +++ b/source/libs/function/src/tpercentile.c @@ -14,8 +14,8 @@ */ #include "taoserror.h" -#include "tglobal.h" #include "tcompare.h" +#include "tglobal.h" #include "taosdef.h" #include "tcompare.h" @@ -25,21 +25,20 @@ #define DEFAULT_NUM_OF_SLOT 1024 -int32_t getGroupId(int32_t numOfSlots, int32_t slotIndex, int32_t times) { - return (times * numOfSlots) + slotIndex; -} +int32_t getGroupId(int32_t numOfSlots, int32_t slotIndex, int32_t times) { return (times * numOfSlots) + slotIndex; } static SFilePage *loadDataFromFilePage(tMemBucket *pMemBucket, int32_t slotIdx) { - SFilePage *buffer = (SFilePage *)taosMemoryCalloc(1, pMemBucket->bytes * pMemBucket->pSlots[slotIdx].info.size + sizeof(SFilePage)); + SFilePage *buffer = + (SFilePage *)taosMemoryCalloc(1, pMemBucket->bytes * pMemBucket->pSlots[slotIdx].info.size + sizeof(SFilePage)); int32_t groupId = getGroupId(pMemBucket->numOfSlots, slotIdx, pMemBucket->times); - SArray* pIdList = *(SArray**)taosHashGet(pMemBucket->groupPagesMap, &groupId, sizeof(groupId)); + SArray *pIdList = *(SArray **)taosHashGet(pMemBucket->groupPagesMap, &groupId, sizeof(groupId)); int32_t offset = 0; - for(int32_t i = 0; i < taosArrayGetSize(pIdList); ++i) { - int32_t* pageId = taosArrayGet(pIdList, i); + for (int32_t i = 0; i < taosArrayGetSize(pIdList); ++i) { + int32_t *pageId = taosArrayGet(pIdList, i); - SFilePage* pg = getBufPage(pMemBucket->pBuffer, *pageId); + SFilePage *pg = getBufPage(pMemBucket->pBuffer, *pageId); memcpy(buffer->data + offset, pg->data, (size_t)(pg->num * pMemBucket->bytes)); offset += (int32_t)(pg->num * pMemBucket->bytes); @@ -49,7 +48,7 @@ static SFilePage *loadDataFromFilePage(tMemBucket *pMemBucket, int32_t slotIdx) return buffer; } -static void resetBoundingBox(MinMaxEntry* range, int32_t type) { +static void resetBoundingBox(MinMaxEntry *range, int32_t type) { if (IS_SIGNED_NUMERIC_TYPE(type)) { range->i64MaxVal = INT64_MIN; range->i64MinVal = INT64_MAX; @@ -62,17 +61,17 @@ static void resetBoundingBox(MinMaxEntry* range, int32_t type) { } } -static int32_t setBoundingBox(MinMaxEntry* range, int16_t type, double minval, double maxval) { +static int32_t setBoundingBox(MinMaxEntry *range, int16_t type, double minval, double maxval) { if (minval > maxval) { return -1; } if (IS_SIGNED_NUMERIC_TYPE(type)) { - range->i64MinVal = (int64_t) minval; - range->i64MaxVal = (int64_t) maxval; - } else if (IS_UNSIGNED_NUMERIC_TYPE(type)){ - range->u64MinVal = (uint64_t) minval; - range->u64MaxVal = (uint64_t) maxval; + range->i64MinVal = (int64_t)minval; + range->i64MaxVal = (int64_t)maxval; + } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { + range->u64MinVal = (uint64_t)minval; + range->u64MaxVal = (uint64_t)maxval; } else { range->dMinVal = minval; range->dMaxVal = maxval; @@ -81,10 +80,10 @@ static int32_t setBoundingBox(MinMaxEntry* range, int16_t type, double minval, d return 0; } -static void resetPosInfo(SSlotInfo* pInfo) { - pInfo->size = 0; +static void resetPosInfo(SSlotInfo *pInfo) { + pInfo->size = 0; pInfo->pageId = -1; - pInfo->data = NULL; + pInfo->data = NULL; } double findOnlyResult(tMemBucket *pMemBucket) { @@ -92,16 +91,16 @@ double findOnlyResult(tMemBucket *pMemBucket) { for (int32_t i = 0; i < pMemBucket->numOfSlots; ++i) { tMemBucketSlot *pSlot = &pMemBucket->pSlots[i]; - if (pSlot->info.size == 0) { + if (pSlot->info.size == 0) { continue; } int32_t groupId = getGroupId(pMemBucket->numOfSlots, i, pMemBucket->times); - SArray* list = *(SArray**)taosHashGet(pMemBucket->groupPagesMap, &groupId, sizeof(groupId)); + SArray *list = *(SArray **)taosHashGet(pMemBucket->groupPagesMap, &groupId, sizeof(groupId)); assert(list->size == 1); - int32_t* pageId = taosArrayGet(list, 0); - SFilePage* pPage = getBufPage(pMemBucket->pBuffer, *pageId); + int32_t *pageId = taosArrayGet(list, 0); + SFilePage *pPage = getBufPage(pMemBucket->pBuffer, *pageId); assert(pPage->num == 1); double v = 0; @@ -121,14 +120,14 @@ int32_t tBucketIntHash(tMemBucket *pBucket, const void *value) { if (v > pBucket->range.i64MaxVal || v < pBucket->range.i64MinVal) { return index; } - + // divide the value range into 1024 buckets uint64_t span = pBucket->range.i64MaxVal - pBucket->range.i64MinVal; if (span < pBucket->numOfSlots) { int64_t delta = v - pBucket->range.i64MinVal; index = (delta % pBucket->numOfSlots); } else { - double slotSpan = ((double)span) / pBucket->numOfSlots; + double slotSpan = ((double)span) / pBucket->numOfSlots; uint64_t delta = v - pBucket->range.i64MinVal; index = (int32_t)(delta / slotSpan); @@ -150,12 +149,12 @@ int32_t tBucketUintHash(tMemBucket *pBucket, const void *value) { if (v > pBucket->range.u64MaxVal || v < pBucket->range.u64MinVal) { return index; } - + // divide the value range into 1024 buckets uint64_t span = pBucket->range.u64MaxVal - pBucket->range.u64MinVal; if (span < pBucket->numOfSlots) { int64_t delta = v - pBucket->range.u64MinVal; - index = (int32_t) (delta % pBucket->numOfSlots); + index = (int32_t)(delta % pBucket->numOfSlots); } else { double slotSpan = (double)span / pBucket->numOfSlots; index = (int32_t)((v - pBucket->range.u64MinVal) / slotSpan); @@ -209,9 +208,9 @@ static __perc_hash_func_t getHashFunc(int32_t type) { } } -static void resetSlotInfo(tMemBucket* pBucket) { +static void resetSlotInfo(tMemBucket *pBucket) { for (int32_t i = 0; i < pBucket->numOfSlots; ++i) { - tMemBucketSlot* pSlot = &pBucket->pSlots[i]; + tMemBucketSlot *pSlot = &pBucket->pSlots[i]; resetBoundingBox(&pSlot->range, pBucket->type); resetPosInfo(&pSlot->info); @@ -225,9 +224,9 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, } pBucket->numOfSlots = DEFAULT_NUM_OF_SLOT; - pBucket->bufPageSize = 16384 * 4; // 16k per page + pBucket->bufPageSize = 16384 * 4; // 16k per page - pBucket->type = dataType; + pBucket->type = dataType; pBucket->bytes = nElemSize; pBucket->total = 0; pBucket->times = 1; @@ -235,17 +234,17 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, pBucket->maxCapacity = 200000; pBucket->groupPagesMap = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (setBoundingBox(&pBucket->range, pBucket->type, minval, maxval) != 0) { -// qError("MemBucket:%p, invalid value range: %f-%f", pBucket, minval, maxval); + // qError("MemBucket:%p, invalid value range: %f-%f", pBucket, minval, maxval); taosMemoryFree(pBucket); return NULL; } - pBucket->elemPerPage = (pBucket->bufPageSize - sizeof(SFilePage))/pBucket->bytes; + pBucket->elemPerPage = (pBucket->bufPageSize - sizeof(SFilePage)) / pBucket->bytes; pBucket->comparFn = getKeyComparFunc(pBucket->type, TSDB_ORDER_ASC); pBucket->hashFunc = getHashFunc(pBucket->type); if (pBucket->hashFunc == NULL) { -// qError("MemBucket:%p, not support data type %d, failed", pBucket, pBucket->type); + // qError("MemBucket:%p, not support data type %d, failed", pBucket, pBucket->type); taosMemoryFree(pBucket); return NULL; } @@ -270,8 +269,8 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval, tMemBucketDestroy(pBucket); return NULL; } - -// qDebug("MemBucket:%p, elem size:%d", pBucket, pBucket->bytes); + + // qDebug("MemBucket:%p, elem size:%d", pBucket, pBucket->bytes); return pBucket; } @@ -280,9 +279,9 @@ void tMemBucketDestroy(tMemBucket *pBucket) { return; } - void* p = taosHashIterate(pBucket->groupPagesMap, NULL); - while(p) { - SArray** p1 = p; + void *p = taosHashIterate(pBucket->groupPagesMap, NULL); + while (p) { + SArray **p1 = p; p = taosHashIterate(pBucket->groupPagesMap, p); taosArrayDestroy(*p1); } @@ -341,7 +340,7 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) { int32_t count = 0; int32_t bytes = pBucket->bytes; for (int32_t i = 0; i < size; ++i) { - char *d = (char *) data + i * bytes; + char *d = (char *)data + i * bytes; int32_t index = (pBucket->hashFunc)(pBucket, d); if (index < 0) { continue; @@ -365,11 +364,11 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) { pSlot->info.data = NULL; } - SArray* pPageIdList = (SArray*)taosHashGet(pBucket->groupPagesMap, &groupId, sizeof(groupId)); + SArray *pPageIdList = (SArray *)taosHashGet(pBucket->groupPagesMap, &groupId, sizeof(groupId)); if (pPageIdList == NULL) { - SArray* pList = taosArrayInit(4, sizeof(int32_t)); + SArray *pList = taosArrayInit(4, sizeof(int32_t)); taosHashPut(pBucket->groupPagesMap, &groupId, sizeof(groupId), &pList, POINTER_BYTES); - pPageIdList = pList; + pPageIdList = pList; } pSlot->info.data = getNewBufPage(pBucket->pBuffer, &pageId); @@ -396,29 +395,29 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) { * slot of the next segment. */ static MinMaxEntry getMinMaxEntryOfNextSlotWithData(tMemBucket *pMemBucket, int32_t slotIdx) { - int32_t j = slotIdx + 1; - while (j < pMemBucket->numOfSlots && (pMemBucket->pSlots[j].info.size == 0)) { - ++j; - } + int32_t j = slotIdx + 1; + while (j < pMemBucket->numOfSlots && (pMemBucket->pSlots[j].info.size == 0)) { + ++j; + } - assert(j < pMemBucket->numOfSlots); - return pMemBucket->pSlots[j].range; + assert(j < pMemBucket->numOfSlots); + return pMemBucket->pSlots[j].range; } static bool isIdenticalData(tMemBucket *pMemBucket, int32_t index); -static double getIdenticalDataVal(tMemBucket* pMemBucket, int32_t slotIndex) { +static double getIdenticalDataVal(tMemBucket *pMemBucket, int32_t slotIndex) { assert(isIdenticalData(pMemBucket, slotIndex)); tMemBucketSlot *pSlot = &pMemBucket->pSlots[slotIndex]; double finalResult = 0.0; if (IS_SIGNED_NUMERIC_TYPE(pMemBucket->type)) { - finalResult = (double) pSlot->range.i64MinVal; + finalResult = (double)pSlot->range.i64MinVal; } else if (IS_UNSIGNED_NUMERIC_TYPE(pMemBucket->type)) { - finalResult = (double) pSlot->range.u64MinVal; + finalResult = (double)pSlot->range.u64MinVal; } else { - finalResult = (double) pSlot->range.dMinVal; + finalResult = (double)pSlot->range.dMinVal; } return finalResult; @@ -445,14 +444,14 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) double maxOfThisSlot = 0; double minOfNextSlot = 0; if (IS_SIGNED_NUMERIC_TYPE(pMemBucket->type)) { - maxOfThisSlot = (double) pSlot->range.i64MaxVal; - minOfNextSlot = (double) next.i64MinVal; + maxOfThisSlot = (double)pSlot->range.i64MaxVal; + minOfNextSlot = (double)next.i64MinVal; } else if (IS_UNSIGNED_NUMERIC_TYPE(pMemBucket->type)) { - maxOfThisSlot = (double) pSlot->range.u64MaxVal; - minOfNextSlot = (double) next.u64MinVal; + maxOfThisSlot = (double)pSlot->range.u64MaxVal; + minOfNextSlot = (double)next.u64MinVal; } else { - maxOfThisSlot = (double) pSlot->range.dMaxVal; - minOfNextSlot = (double) next.dMinVal; + maxOfThisSlot = (double)pSlot->range.dMaxVal; + minOfNextSlot = (double)next.dMinVal; } assert(minOfNextSlot > maxOfThisSlot); @@ -478,32 +477,32 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) return val; } else { // incur a second round bucket split - if (isIdenticalData(pMemBucket, i)) { - return getIdenticalDataVal(pMemBucket, i); - } + if (isIdenticalData(pMemBucket, i)) { + return getIdenticalDataVal(pMemBucket, i); + } - // try next round - pMemBucket->times += 1; -// qDebug("MemBucket:%p, start next round data bucketing, time:%d", pMemBucket, pMemBucket->times); + // try next round + pMemBucket->times += 1; + // qDebug("MemBucket:%p, start next round data bucketing, time:%d", pMemBucket, pMemBucket->times); - pMemBucket->range = pSlot->range; - pMemBucket->total = 0; + pMemBucket->range = pSlot->range; + pMemBucket->total = 0; - resetSlotInfo(pMemBucket); + resetSlotInfo(pMemBucket); - int32_t groupId = getGroupId(pMemBucket->numOfSlots, i, pMemBucket->times - 1); + int32_t groupId = getGroupId(pMemBucket->numOfSlots, i, pMemBucket->times - 1); SIDList list = taosHashGet(pMemBucket->groupPagesMap, &groupId, sizeof(groupId)); - assert(list->size > 0); + assert(list->size > 0); - for (int32_t f = 0; f < list->size; ++f) { - SPageInfo *pgInfo = *(SPageInfo **)taosArrayGet(list, f); - SFilePage *pg = getBufPage(pMemBucket->pBuffer, getPageId(pgInfo)); + for (int32_t f = 0; f < list->size; ++f) { + SPageInfo *pgInfo = *(SPageInfo **)taosArrayGet(list, f); + SFilePage *pg = getBufPage(pMemBucket->pBuffer, getPageId(pgInfo)); - tMemBucketPut(pMemBucket, pg->data, (int32_t)pg->num); - releaseBufPageInfo(pMemBucket->pBuffer, pgInfo); - } + tMemBucketPut(pMemBucket, pg->data, (int32_t)pg->num); + releaseBufPageInfo(pMemBucket->pBuffer, pgInfo); + } - return getPercentileImpl(pMemBucket, count - num, fraction); + return getPercentileImpl(pMemBucket, count - num, fraction); } } else { num += pSlot->info.size; @@ -527,7 +526,7 @@ double getPercentile(tMemBucket *pMemBucket, double percent) { // find the min/max value, no need to scan all data in bucket if (fabs(percent - 100.0) < DBL_EPSILON || (percent < DBL_EPSILON)) { - MinMaxEntry* pRange = &pMemBucket->range; + MinMaxEntry *pRange = &pMemBucket->range; if (IS_SIGNED_NUMERIC_TYPE(pMemBucket->type)) { double v = (double)(fabs(percent - 100) < DBL_EPSILON ? pRange->i64MaxVal : pRange->i64MinVal); @@ -536,11 +535,11 @@ double getPercentile(tMemBucket *pMemBucket, double percent) { double v = (double)(fabs(percent - 100) < DBL_EPSILON ? pRange->u64MaxVal : pRange->u64MinVal); return v; } else { - return fabs(percent - 100) < DBL_EPSILON? pRange->dMaxVal:pRange->dMinVal; + return fabs(percent - 100) < DBL_EPSILON ? pRange->dMaxVal : pRange->dMinVal; } } - double percentVal = (percent * (pMemBucket->total - 1)) / ((double)100.0); + double percentVal = (percent * (pMemBucket->total - 1)) / ((double)100.0); // do put data by using buckets int32_t orderIdx = (int32_t)percentVal; diff --git a/source/libs/function/src/tscript.c b/source/libs/function/src/tscript.c index 93e8ecf5cfbc7aa67ed7bd12e404d850fa3eb4f4..768581285b58b969cdd916a5b442c2422285faae 100644 --- a/source/libs/function/src/tscript.c +++ b/source/libs/function/src/tscript.c @@ -13,10 +13,10 @@ * along with this program. If not, see . */ -#include "os.h" #include "tscript.h" -#include "ttypes.h" +#include "os.h" #include "tstrbuild.h" +#include "ttypes.h" //#include "queryLog.h" #include "ttokendef.h" #if 0 diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index 060a92f864ec6380a799c77a6790eeeb3175577b..14833945090c1ca9f6cf860e9d51253dcff5a182 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -13,33 +13,35 @@ * along with this program. If not, see . */ #include "uv.h" + #include "os.h" + +#include "builtinsimpl.h" #include "fnLog.h" -#include "tudf.h" -#include "tudfInt.h" +#include "functionMgt.h" +#include "querynodes.h" #include "tarray.h" -#include "tglobal.h" #include "tdatablock.h" -#include "querynodes.h" -#include "builtinsimpl.h" -#include "functionMgt.h" +#include "tglobal.h" +#include "tudf.h" +#include "tudfInt.h" typedef struct SUdfdData { - bool startCalled; - bool needCleanUp; - uv_loop_t loop; - uv_thread_t thread; - uv_barrier_t barrier; - uv_process_t process; + bool startCalled; + bool needCleanUp; + uv_loop_t loop; + uv_thread_t thread; + uv_barrier_t barrier; + uv_process_t process; #ifdef WINDOWS - HANDLE jobHandle; + HANDLE jobHandle; #endif - int spawnErr; - uv_pipe_t ctrlPipe; - uv_async_t stopAsync; - int32_t stopCalled; + int spawnErr; + uv_pipe_t ctrlPipe; + uv_async_t stopAsync; + int32_t stopCalled; - int32_t dnodeId; + int32_t dnodeId; } SUdfdData; SUdfdData udfdGlobal = {0}; @@ -48,11 +50,11 @@ int32_t udfStartUdfd(int32_t startDnodeId); int32_t udfStopUdfd(); static int32_t udfSpawnUdfd(SUdfdData *pData); -void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal); -static int32_t udfSpawnUdfd(SUdfdData* pData); -static void udfUdfdCloseWalkCb(uv_handle_t* handle, void* arg); -static void udfUdfdStopAsyncCb(uv_async_t *async); -static void udfWatchUdfd(void *args); +void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal); +static int32_t udfSpawnUdfd(SUdfdData *pData); +static void udfUdfdCloseWalkCb(uv_handle_t *handle, void *arg); +static void udfUdfdStopAsyncCb(uv_async_t *async); +static void udfWatchUdfd(void *args); void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) { fnInfo("udfd process exited with status %" PRId64 ", signal %d", exitStatus, termSignal); @@ -65,27 +67,27 @@ void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) { } } -static int32_t udfSpawnUdfd(SUdfdData* pData) { +static int32_t udfSpawnUdfd(SUdfdData *pData) { fnInfo("start to init udfd"); uv_process_options_t options = {0}; char path[PATH_MAX] = {0}; if (tsProcPath == NULL) { path[0] = '.'; - #ifdef WINDOWS +#ifdef WINDOWS GetModuleFileName(NULL, path, PATH_MAX); taosDirName(path); - #elif defined(_TD_DARWIN_64) +#elif defined(_TD_DARWIN_64) uint32_t pathSize = sizeof(path); _NSGetExecutablePath(path, &pathSize); taosDirName(path); - #endif +#endif } else { strncpy(path, tsProcPath, PATH_MAX); taosDirName(path); } #ifdef WINDOWS - if (strlen(path)==0) { + if (strlen(path) == 0) { strcat(path, "udfd.exe"); } else { strcat(path, "\\udfd.exe"); @@ -93,7 +95,7 @@ static int32_t udfSpawnUdfd(SUdfdData* pData) { #else strcat(path, "/udfd"); #endif - char* argsUdfd[] = {path, "-c", configDir, NULL}; + char *argsUdfd[] = {path, "-c", configDir, NULL}; options.args = argsUdfd; options.file = path; @@ -103,7 +105,7 @@ static int32_t udfSpawnUdfd(SUdfdData* pData) { uv_stdio_container_t child_stdio[3]; child_stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE; - child_stdio[0].data.stream = (uv_stream_t*) &pData->ctrlPipe; + child_stdio[0].data.stream = (uv_stream_t *)&pData->ctrlPipe; child_stdio[1].flags = UV_IGNORE; child_stdio[2].flags = UV_INHERIT_FD; child_stdio[2].data.fd = 2; @@ -117,12 +119,12 @@ static int32_t udfSpawnUdfd(SUdfdData* pData) { snprintf(dnodeIdEnvItem, 32, "%s=%d", "DNODE_ID", pData->dnodeId); float numCpuCores = 4; taosGetCpuCores(&numCpuCores); - snprintf(thrdPoolSizeEnvItem,32, "%s=%d", "UV_THREADPOOL_SIZE", (int)numCpuCores*2); - char* envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, NULL}; + snprintf(thrdPoolSizeEnvItem, 32, "%s=%d", "UV_THREADPOOL_SIZE", (int)numCpuCores * 2); + char *envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, NULL}; options.env = envUdfd; int err = uv_spawn(&pData->loop, &pData->process, &options); - pData->process.data = (void*)pData; + pData->process.data = (void *)pData; #ifdef WINDOWS // End udfd.exe by Job. @@ -135,7 +137,8 @@ static int32_t udfSpawnUdfd(SUdfdData* pData) { JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info; memset(&limit_info, 0x0, sizeof(limit_info)); limit_info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; - bool set_auto_kill_ok = SetInformationJobObject(pData->jobHandle, JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info)); + bool set_auto_kill_ok = + SetInformationJobObject(pData->jobHandle, JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info)); if (!set_auto_kill_ok) { fnError("Set job auto kill udfd failed."); } @@ -150,7 +153,7 @@ static int32_t udfSpawnUdfd(SUdfdData* pData) { return err; } -static void udfUdfdCloseWalkCb(uv_handle_t* handle, void* arg) { +static void udfUdfdCloseWalkCb(uv_handle_t *handle, void *arg) { if (!uv_is_closing(handle)) { uv_close(handle, NULL); } @@ -180,8 +183,7 @@ static void udfWatchUdfd(void *args) { int32_t udfStartUdfd(int32_t startDnodeId) { if (!tsStartUdfd) { - fnInfo("start udfd is disabled.") - return 0; + fnInfo("start udfd is disabled.") return 0; } SUdfdData *pData = &udfdGlobal; if (pData->startCalled) { @@ -212,8 +214,7 @@ int32_t udfStartUdfd(int32_t startDnodeId) { int32_t udfStopUdfd() { SUdfdData *pData = &udfdGlobal; - fnInfo("udfd start to stop, need cleanup:%d, spawn err:%d", - pData->needCleanUp, pData->spawnErr); + fnInfo("udfd start to stop, need cleanup:%d, spawn err:%d", pData->needCleanUp, pData->spawnErr); if (!pData->needCleanUp || atomic_load_32(&pData->stopCalled)) { return 0; } @@ -237,107 +238,91 @@ int32_t udfStopUdfd() { typedef void *QUEUE[2]; /* Private macros. */ -#define QUEUE_NEXT(q) (*(QUEUE **) &((*(q))[0])) -#define QUEUE_PREV(q) (*(QUEUE **) &((*(q))[1])) -#define QUEUE_PREV_NEXT(q) (QUEUE_NEXT(QUEUE_PREV(q))) -#define QUEUE_NEXT_PREV(q) (QUEUE_PREV(QUEUE_NEXT(q))) +#define QUEUE_NEXT(q) (*(QUEUE **)&((*(q))[0])) +#define QUEUE_PREV(q) (*(QUEUE **)&((*(q))[1])) +#define QUEUE_PREV_NEXT(q) (QUEUE_NEXT(QUEUE_PREV(q))) +#define QUEUE_NEXT_PREV(q) (QUEUE_PREV(QUEUE_NEXT(q))) /* Public macros. */ -#define QUEUE_DATA(ptr, type, field) \ - ((type *) ((char *) (ptr) - offsetof(type, field))) +#define QUEUE_DATA(ptr, type, field) ((type *)((char *)(ptr)-offsetof(type, field))) /* Important note: mutating the list while QUEUE_FOREACH is * iterating over its elements results in undefined behavior. */ -#define QUEUE_FOREACH(q, h) \ - for ((q) = QUEUE_NEXT(h); (q) != (h); (q) = QUEUE_NEXT(q)) - -#define QUEUE_EMPTY(q) \ - ((const QUEUE *) (q) == (const QUEUE *) QUEUE_NEXT(q)) - -#define QUEUE_HEAD(q) \ - (QUEUE_NEXT(q)) - -#define QUEUE_INIT(q) \ - do { \ - QUEUE_NEXT(q) = (q); \ - QUEUE_PREV(q) = (q); \ - } \ - while (0) - -#define QUEUE_ADD(h, n) \ - do { \ - QUEUE_PREV_NEXT(h) = QUEUE_NEXT(n); \ - QUEUE_NEXT_PREV(n) = QUEUE_PREV(h); \ - QUEUE_PREV(h) = QUEUE_PREV(n); \ - QUEUE_PREV_NEXT(h) = (h); \ - } \ - while (0) - -#define QUEUE_SPLIT(h, q, n) \ - do { \ - QUEUE_PREV(n) = QUEUE_PREV(h); \ - QUEUE_PREV_NEXT(n) = (n); \ - QUEUE_NEXT(n) = (q); \ - QUEUE_PREV(h) = QUEUE_PREV(q); \ - QUEUE_PREV_NEXT(h) = (h); \ - QUEUE_PREV(q) = (n); \ - } \ - while (0) - -#define QUEUE_MOVE(h, n) \ - do { \ - if (QUEUE_EMPTY(h)) \ - QUEUE_INIT(n); \ - else { \ - QUEUE* q = QUEUE_HEAD(h); \ - QUEUE_SPLIT(h, q, n); \ - } \ - } \ - while (0) - -#define QUEUE_INSERT_HEAD(h, q) \ - do { \ - QUEUE_NEXT(q) = QUEUE_NEXT(h); \ - QUEUE_PREV(q) = (h); \ - QUEUE_NEXT_PREV(q) = (q); \ - QUEUE_NEXT(h) = (q); \ - } \ - while (0) - -#define QUEUE_INSERT_TAIL(h, q) \ - do { \ - QUEUE_NEXT(q) = (h); \ - QUEUE_PREV(q) = QUEUE_PREV(h); \ - QUEUE_PREV_NEXT(q) = (q); \ - QUEUE_PREV(h) = (q); \ - } \ - while (0) - -#define QUEUE_REMOVE(q) \ - do { \ - QUEUE_PREV_NEXT(q) = QUEUE_NEXT(q); \ - QUEUE_NEXT_PREV(q) = QUEUE_PREV(q); \ - } \ - while (0) - - -enum { - UV_TASK_CONNECT = 0, - UV_TASK_REQ_RSP = 1, - UV_TASK_DISCONNECT = 2 -}; +#define QUEUE_FOREACH(q, h) for ((q) = QUEUE_NEXT(h); (q) != (h); (q) = QUEUE_NEXT(q)) + +#define QUEUE_EMPTY(q) ((const QUEUE *)(q) == (const QUEUE *)QUEUE_NEXT(q)) + +#define QUEUE_HEAD(q) (QUEUE_NEXT(q)) + +#define QUEUE_INIT(q) \ + do { \ + QUEUE_NEXT(q) = (q); \ + QUEUE_PREV(q) = (q); \ + } while (0) + +#define QUEUE_ADD(h, n) \ + do { \ + QUEUE_PREV_NEXT(h) = QUEUE_NEXT(n); \ + QUEUE_NEXT_PREV(n) = QUEUE_PREV(h); \ + QUEUE_PREV(h) = QUEUE_PREV(n); \ + QUEUE_PREV_NEXT(h) = (h); \ + } while (0) + +#define QUEUE_SPLIT(h, q, n) \ + do { \ + QUEUE_PREV(n) = QUEUE_PREV(h); \ + QUEUE_PREV_NEXT(n) = (n); \ + QUEUE_NEXT(n) = (q); \ + QUEUE_PREV(h) = QUEUE_PREV(q); \ + QUEUE_PREV_NEXT(h) = (h); \ + QUEUE_PREV(q) = (n); \ + } while (0) + +#define QUEUE_MOVE(h, n) \ + do { \ + if (QUEUE_EMPTY(h)) \ + QUEUE_INIT(n); \ + else { \ + QUEUE *q = QUEUE_HEAD(h); \ + QUEUE_SPLIT(h, q, n); \ + } \ + } while (0) + +#define QUEUE_INSERT_HEAD(h, q) \ + do { \ + QUEUE_NEXT(q) = QUEUE_NEXT(h); \ + QUEUE_PREV(q) = (h); \ + QUEUE_NEXT_PREV(q) = (q); \ + QUEUE_NEXT(h) = (q); \ + } while (0) + +#define QUEUE_INSERT_TAIL(h, q) \ + do { \ + QUEUE_NEXT(q) = (h); \ + QUEUE_PREV(q) = QUEUE_PREV(h); \ + QUEUE_PREV_NEXT(q) = (q); \ + QUEUE_PREV(h) = (q); \ + } while (0) + +#define QUEUE_REMOVE(q) \ + do { \ + QUEUE_PREV_NEXT(q) = QUEUE_NEXT(q); \ + QUEUE_NEXT_PREV(q) = QUEUE_PREV(q); \ + } while (0) + +enum { UV_TASK_CONNECT = 0, UV_TASK_REQ_RSP = 1, UV_TASK_DISCONNECT = 2 }; int64_t gUdfTaskSeqNum = 0; typedef struct SUdfcFuncStub { - char udfName[TSDB_FUNC_NAME_LEN]; + char udfName[TSDB_FUNC_NAME_LEN]; UdfcFuncHandle handle; - int32_t refCount; - int64_t lastRefTime; + int32_t refCount; + int64_t lastRefTime; } SUdfcFuncStub; typedef struct SUdfcProxy { - char udfdPipeName[PATH_MAX + UDF_LISTEN_PIPE_NAME_LEN + 2]; + char udfdPipeName[PATH_MAX + UDF_LISTEN_PIPE_NAME_LEN + 2]; uv_barrier_t initBarrier; uv_loop_t uvLoop; @@ -352,7 +337,7 @@ typedef struct SUdfcProxy { QUEUE uvProcTaskQueue; uv_mutex_t udfStubsMutex; - SArray* udfStubs; // SUdfcFuncStub + SArray *udfStubs; // SUdfcFuncStub int8_t initialized; } SUdfcProxy; @@ -361,8 +346,8 @@ SUdfcProxy gUdfdProxy = {0}; typedef struct SUdfcUvSession { SUdfcProxy *udfc; - int64_t severHandle; - uv_pipe_t *udfUvPipe; + int64_t severHandle; + uv_pipe_t *udfUvPipe; int8_t outputType; int32_t outputLen; @@ -373,12 +358,12 @@ typedef struct SUdfcUvSession { typedef struct SClientUvTaskNode { SUdfcProxy *udfc; - int8_t type; - int errCode; + int8_t type; + int errCode; uv_pipe_t *pipe; - int64_t seqNum; + int64_t seqNum; uv_buf_t reqBuf; uv_sem_t taskSem; @@ -398,15 +383,15 @@ typedef struct SClientUdfTask { union { struct { - SUdfSetupRequest req; + SUdfSetupRequest req; SUdfSetupResponse rsp; } _setup; struct { - SUdfCallRequest req; + SUdfCallRequest req; SUdfCallResponse rsp; } _call; struct { - SUdfTeardownRequest req; + SUdfTeardownRequest req; SUdfTeardownResponse rsp; } _teardown; }; @@ -414,55 +399,55 @@ typedef struct SClientUdfTask { } SClientUdfTask; typedef struct SClientConnBuf { - char *buf; + char *buf; int32_t len; int32_t cap; int32_t total; } SClientConnBuf; typedef struct SClientUvConn { - uv_pipe_t *pipe; - QUEUE taskQueue; - SClientConnBuf readBuf; + uv_pipe_t *pipe; + QUEUE taskQueue; + SClientConnBuf readBuf; SUdfcUvSession *session; } SClientUvConn; enum { - UDFC_STATE_INITAL = 0, // initial state - UDFC_STATE_STARTNG, // starting after udfcOpen - UDFC_STATE_READY, // started and begin to receive quests - UDFC_STATE_STOPPING, // stopping after udfcClose + UDFC_STATE_INITAL = 0, // initial state + UDFC_STATE_STARTNG, // starting after udfcOpen + UDFC_STATE_READY, // started and begin to receive quests + UDFC_STATE_STOPPING, // stopping after udfcClose }; -int32_t getUdfdPipeName(char* pipeName, int32_t size); +int32_t getUdfdPipeName(char *pipeName, int32_t size); int32_t encodeUdfSetupRequest(void **buf, const SUdfSetupRequest *setup); -void* decodeUdfSetupRequest(const void* buf, SUdfSetupRequest *request); -int32_t encodeUdfInterBuf(void **buf, const SUdfInterBuf* state); -void* decodeUdfInterBuf(const void* buf, SUdfInterBuf* state); +void *decodeUdfSetupRequest(const void *buf, SUdfSetupRequest *request); +int32_t encodeUdfInterBuf(void **buf, const SUdfInterBuf *state); +void *decodeUdfInterBuf(const void *buf, SUdfInterBuf *state); int32_t encodeUdfCallRequest(void **buf, const SUdfCallRequest *call); -void* decodeUdfCallRequest(const void* buf, SUdfCallRequest* call); +void *decodeUdfCallRequest(const void *buf, SUdfCallRequest *call); int32_t encodeUdfTeardownRequest(void **buf, const SUdfTeardownRequest *teardown); -void* decodeUdfTeardownRequest(const void* buf, SUdfTeardownRequest *teardown); -int32_t encodeUdfRequest(void** buf, const SUdfRequest* request); -void* decodeUdfRequest(const void* buf, SUdfRequest* request); +void *decodeUdfTeardownRequest(const void *buf, SUdfTeardownRequest *teardown); +int32_t encodeUdfRequest(void **buf, const SUdfRequest *request); +void *decodeUdfRequest(const void *buf, SUdfRequest *request); int32_t encodeUdfSetupResponse(void **buf, const SUdfSetupResponse *setupRsp); -void* decodeUdfSetupResponse(const void* buf, SUdfSetupResponse* setupRsp); +void *decodeUdfSetupResponse(const void *buf, SUdfSetupResponse *setupRsp); int32_t encodeUdfCallResponse(void **buf, const SUdfCallResponse *callRsp); -void* decodeUdfCallResponse(const void* buf, SUdfCallResponse* callRsp); -int32_t encodeUdfTeardownResponse(void** buf, const SUdfTeardownResponse* teardownRsp); -void* decodeUdfTeardownResponse(const void* buf, SUdfTeardownResponse* teardownResponse); -int32_t encodeUdfResponse(void** buf, const SUdfResponse* rsp); -void* decodeUdfResponse(const void* buf, SUdfResponse* rsp); -void freeUdfColumnData(SUdfColumnData *data, SUdfColumnMeta *meta); -void freeUdfColumn(SUdfColumn* col); -void freeUdfDataDataBlock(SUdfDataBlock *block); -void freeUdfInterBuf(SUdfInterBuf *buf); +void *decodeUdfCallResponse(const void *buf, SUdfCallResponse *callRsp); +int32_t encodeUdfTeardownResponse(void **buf, const SUdfTeardownResponse *teardownRsp); +void *decodeUdfTeardownResponse(const void *buf, SUdfTeardownResponse *teardownResponse); +int32_t encodeUdfResponse(void **buf, const SUdfResponse *rsp); +void *decodeUdfResponse(const void *buf, SUdfResponse *rsp); +void freeUdfColumnData(SUdfColumnData *data, SUdfColumnMeta *meta); +void freeUdfColumn(SUdfColumn *col); +void freeUdfDataDataBlock(SUdfDataBlock *block); +void freeUdfInterBuf(SUdfInterBuf *buf); int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlock); int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block); int32_t convertScalarParamToDataBlock(SScalarParam *input, int32_t numOfCols, SSDataBlock *output); int32_t convertDataBlockToScalarParm(SSDataBlock *input, SScalarParam *output); -int32_t getUdfdPipeName(char* pipeName, int32_t size) { +int32_t getUdfdPipeName(char *pipeName, int32_t size) { char dnodeId[8] = {0}; size_t dnodeIdSize = sizeof(dnodeId); int32_t err = uv_os_getenv(UDF_DNODE_ID_ENV_NAME, dnodeId, &dnodeIdSize); @@ -471,7 +456,8 @@ int32_t getUdfdPipeName(char* pipeName, int32_t size) { dnodeId[0] = '1'; } #ifdef _WIN32 - snprintf(pipeName, size, "%s.%x.%s", UDF_LISTEN_PIPE_NAME_PREFIX,MurmurHash3_32(tsDataDir, strlen(tsDataDir)), dnodeId); + snprintf(pipeName, size, "%s.%x.%s", UDF_LISTEN_PIPE_NAME_PREFIX, MurmurHash3_32(tsDataDir, strlen(tsDataDir)), + dnodeId); #else snprintf(pipeName, size, "%s/%s%s", tsDataDir, UDF_LISTEN_PIPE_NAME_PREFIX, dnodeId); #endif @@ -485,12 +471,12 @@ int32_t encodeUdfSetupRequest(void **buf, const SUdfSetupRequest *setup) { return len; } -void* decodeUdfSetupRequest(const void* buf, SUdfSetupRequest *request) { +void *decodeUdfSetupRequest(const void *buf, SUdfSetupRequest *request) { buf = taosDecodeBinaryTo(buf, request->udfName, TSDB_FUNC_NAME_LEN); - return (void*)buf; + return (void *)buf; } -int32_t encodeUdfInterBuf(void **buf, const SUdfInterBuf* state) { +int32_t encodeUdfInterBuf(void **buf, const SUdfInterBuf *state) { int32_t len = 0; len += taosEncodeFixedI8(buf, state->numOfResult); len += taosEncodeFixedI32(buf, state->bufLen); @@ -498,11 +484,11 @@ int32_t encodeUdfInterBuf(void **buf, const SUdfInterBuf* state) { return len; } -void* decodeUdfInterBuf(const void* buf, SUdfInterBuf* state) { +void *decodeUdfInterBuf(const void *buf, SUdfInterBuf *state) { buf = taosDecodeFixedI8(buf, &state->numOfResult); buf = taosDecodeFixedI32(buf, &state->bufLen); - buf = taosDecodeBinary(buf, (void**)&state->buf, state->bufLen); - return (void*)buf; + buf = taosDecodeBinary(buf, (void **)&state->buf, state->bufLen); + return (void *)buf; } int32_t encodeUdfCallRequest(void **buf, const SUdfCallRequest *call) { @@ -525,7 +511,7 @@ int32_t encodeUdfCallRequest(void **buf, const SUdfCallRequest *call) { return len; } -void* decodeUdfCallRequest(const void* buf, SUdfCallRequest* call) { +void *decodeUdfCallRequest(const void *buf, SUdfCallRequest *call) { buf = taosDecodeFixedI64(buf, &call->udfHandle); buf = taosDecodeFixedI8(buf, &call->callType); switch (call->callType) { @@ -547,7 +533,7 @@ void* decodeUdfCallRequest(const void* buf, SUdfCallRequest* call) { buf = decodeUdfInterBuf(buf, &call->interBuf); break; } - return (void*)buf; + return (void *)buf; } int32_t encodeUdfTeardownRequest(void **buf, const SUdfTeardownRequest *teardown) { @@ -556,17 +542,17 @@ int32_t encodeUdfTeardownRequest(void **buf, const SUdfTeardownRequest *teardown return len; } -void* decodeUdfTeardownRequest(const void* buf, SUdfTeardownRequest *teardown) { +void *decodeUdfTeardownRequest(const void *buf, SUdfTeardownRequest *teardown) { buf = taosDecodeFixedI64(buf, &teardown->udfHandle); - return (void*)buf; + return (void *)buf; } -int32_t encodeUdfRequest(void** buf, const SUdfRequest* request) { +int32_t encodeUdfRequest(void **buf, const SUdfRequest *request) { int32_t len = 0; if (buf == NULL) { len += sizeof(request->msgLen); } else { - *(int32_t*)(*buf) = request->msgLen; + *(int32_t *)(*buf) = request->msgLen; *buf = POINTER_SHIFT(*buf, sizeof(request->msgLen)); } len += taosEncodeFixedI64(buf, request->seqNum); @@ -581,8 +567,8 @@ int32_t encodeUdfRequest(void** buf, const SUdfRequest* request) { return len; } -void* decodeUdfRequest(const void* buf, SUdfRequest* request) { - request->msgLen = *(int32_t*)(buf); +void *decodeUdfRequest(const void *buf, SUdfRequest *request) { + request->msgLen = *(int32_t *)(buf); buf = POINTER_SHIFT(buf, sizeof(request->msgLen)); buf = taosDecodeFixedI64(buf, &request->seqNum); @@ -595,7 +581,7 @@ void* decodeUdfRequest(const void* buf, SUdfRequest* request) { } else if (request->type == UDF_TASK_TEARDOWN) { buf = decodeUdfTeardownRequest(buf, &request->teardown); } - return (void*)buf; + return (void *)buf; } int32_t encodeUdfSetupResponse(void **buf, const SUdfSetupResponse *setupRsp) { @@ -607,12 +593,12 @@ int32_t encodeUdfSetupResponse(void **buf, const SUdfSetupResponse *setupRsp) { return len; } -void* decodeUdfSetupResponse(const void* buf, SUdfSetupResponse* setupRsp) { +void *decodeUdfSetupResponse(const void *buf, SUdfSetupResponse *setupRsp) { buf = taosDecodeFixedI64(buf, &setupRsp->udfHandle); buf = taosDecodeFixedI8(buf, &setupRsp->outputType); buf = taosDecodeFixedI32(buf, &setupRsp->outputLen); buf = taosDecodeFixedI32(buf, &setupRsp->bufSize); - return (void*)buf; + return (void *)buf; } int32_t encodeUdfCallResponse(void **buf, const SUdfCallResponse *callRsp) { @@ -638,7 +624,7 @@ int32_t encodeUdfCallResponse(void **buf, const SUdfCallResponse *callRsp) { return len; } -void* decodeUdfCallResponse(const void* buf, SUdfCallResponse* callRsp) { +void *decodeUdfCallResponse(const void *buf, SUdfCallResponse *callRsp) { buf = taosDecodeFixedI8(buf, &callRsp->callType); switch (callRsp->callType) { case TSDB_UDF_CALL_SCALA_PROC: @@ -657,30 +643,26 @@ void* decodeUdfCallResponse(const void* buf, SUdfCallResponse* callRsp) { buf = decodeUdfInterBuf(buf, &callRsp->resultBuf); break; } - return (void*)buf; + return (void *)buf; } -int32_t encodeUdfTeardownResponse(void** buf, const SUdfTeardownResponse* teardownRsp) { - return 0; -} +int32_t encodeUdfTeardownResponse(void **buf, const SUdfTeardownResponse *teardownRsp) { return 0; } -void* decodeUdfTeardownResponse(const void* buf, SUdfTeardownResponse* teardownResponse) { - return (void*)buf; -} +void *decodeUdfTeardownResponse(const void *buf, SUdfTeardownResponse *teardownResponse) { return (void *)buf; } -int32_t encodeUdfResponse(void** buf, const SUdfResponse* rsp) { +int32_t encodeUdfResponse(void **buf, const SUdfResponse *rsp) { int32_t len = 0; if (buf == NULL) { len += sizeof(rsp->msgLen); } else { - *(int32_t*)(*buf) = rsp->msgLen; + *(int32_t *)(*buf) = rsp->msgLen; *buf = POINTER_SHIFT(*buf, sizeof(rsp->msgLen)); } if (buf == NULL) { len += sizeof(rsp->seqNum); } else { - *(int64_t*)(*buf) = rsp->seqNum; + *(int64_t *)(*buf) = rsp->seqNum; *buf = POINTER_SHIFT(*buf, sizeof(rsp->seqNum)); } @@ -705,10 +687,10 @@ int32_t encodeUdfResponse(void** buf, const SUdfResponse* rsp) { return len; } -void* decodeUdfResponse(const void* buf, SUdfResponse* rsp) { - rsp->msgLen = *(int32_t*)(buf); +void *decodeUdfResponse(const void *buf, SUdfResponse *rsp) { + rsp->msgLen = *(int32_t *)(buf); buf = POINTER_SHIFT(buf, sizeof(rsp->msgLen)); - rsp->seqNum = *(int64_t*)(buf); + rsp->seqNum = *(int64_t *)(buf); buf = POINTER_SHIFT(buf, sizeof(rsp->seqNum)); buf = taosDecodeFixedI64(buf, &rsp->seqNum); buf = taosDecodeFixedI8(buf, &rsp->type); @@ -728,7 +710,7 @@ void* decodeUdfResponse(const void* buf, SUdfResponse* rsp) { fnError("decode udf response, invalid udf response type %d", rsp->type); break; } - return (void*)buf; + return (void *)buf; } void freeUdfColumnData(SUdfColumnData *data, SUdfColumnMeta *meta) { @@ -745,9 +727,7 @@ void freeUdfColumnData(SUdfColumnData *data, SUdfColumnMeta *meta) { } } -void freeUdfColumn(SUdfColumn* col) { - freeUdfColumnData(&col->colData, &col->colMeta); -} +void freeUdfColumn(SUdfColumn *col) { freeUdfColumnData(&col->colData, &col->colMeta); } void freeUdfDataDataBlock(SUdfDataBlock *block) { for (int32_t i = 0; i < block->numOfCols; ++i) { @@ -764,15 +744,14 @@ void freeUdfInterBuf(SUdfInterBuf *buf) { buf->buf = NULL; } - int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlock) { udfBlock->numOfRows = block->info.rows; udfBlock->numOfCols = taosArrayGetSize(block->pDataBlock); - udfBlock->udfCols = taosMemoryCalloc(taosArrayGetSize(block->pDataBlock), sizeof(SUdfColumn*)); + udfBlock->udfCols = taosMemoryCalloc(taosArrayGetSize(block->pDataBlock), sizeof(SUdfColumn *)); for (int32_t i = 0; i < udfBlock->numOfCols; ++i) { udfBlock->udfCols[i] = taosMemoryCalloc(1, sizeof(SUdfColumn)); - SColumnInfoData *col= (SColumnInfoData*)taosArrayGet(block->pDataBlock, i); - SUdfColumn *udfCol = udfBlock->udfCols[i]; + SColumnInfoData *col = (SColumnInfoData *)taosArrayGet(block->pDataBlock, i); + SUdfColumn *udfCol = udfBlock->udfCols[i]; udfCol->colMeta.type = col->info.type; udfCol->colMeta.bytes = col->info.bytes; udfCol->colMeta.scale = col->info.scale; @@ -790,12 +769,12 @@ int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlo udfCol->colData.fixLenCol.nullBitmapLen = BitmapLen(udfCol->colData.numOfRows); int32_t bitmapLen = udfCol->colData.fixLenCol.nullBitmapLen; udfCol->colData.fixLenCol.nullBitmap = taosMemoryMalloc(udfCol->colData.fixLenCol.nullBitmapLen); - char* bitmap = udfCol->colData.fixLenCol.nullBitmap; + char *bitmap = udfCol->colData.fixLenCol.nullBitmap; memcpy(bitmap, col->nullbitmap, bitmapLen); udfCol->colData.fixLenCol.dataLen = colDataGetLength(col, udfBlock->numOfRows); int32_t dataLen = udfCol->colData.fixLenCol.dataLen; udfCol->colData.fixLenCol.data = taosMemoryMalloc(udfCol->colData.fixLenCol.dataLen); - char* data = udfCol->colData.fixLenCol.data; + char *data = udfCol->colData.fixLenCol.data; memcpy(data, col->pData, dataLen); } } @@ -809,7 +788,7 @@ int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block) { block->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); taosArraySetSize(block->pDataBlock, 1); SColumnInfoData *col = taosArrayGet(block->pDataBlock, 0); - SUdfColumnMeta *meta = &udfCol->colMeta; + SUdfColumnMeta *meta = &udfCol->colMeta; col->info.precision = meta->precision; col->info.bytes = meta->bytes; col->info.scale = meta->scale; @@ -837,7 +816,7 @@ int32_t convertScalarParamToDataBlock(SScalarParam *input, int32_t numOfCols, SS for (int32_t i = 0; i < numOfCols; ++i) { taosArrayPush(output->pDataBlock, (input + i)->columnData); - if (IS_VAR_DATA_TYPE((input+i)->columnData->info.type)) { + if (IS_VAR_DATA_TYPE((input + i)->columnData->info.type)) { output->info.hasVarCol = true; } } @@ -852,71 +831,70 @@ int32_t convertDataBlockToScalarParm(SSDataBlock *input, SScalarParam *output) { output->numOfRows = input->info.rows; output->columnData = taosMemoryMalloc(sizeof(SColumnInfoData)); - memcpy(output->columnData, - taosArrayGet(input->pDataBlock, 0), - sizeof(SColumnInfoData)); - output->colAlloced = true; + memcpy(output->columnData, taosArrayGet(input->pDataBlock, 0), sizeof(SColumnInfoData)); + output->colAlloced = true; return 0; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//memory layout |---SUdfAggRes----|-----final result-----|---inter result----| +// memory layout |---SUdfAggRes----|-----final result-----|---inter result----| typedef struct SUdfAggRes { int8_t finalResNum; int8_t interResNum; - char* finalResBuf; - char* interResBuf; + char *finalResBuf; + char *interResBuf; } SUdfAggRes; -void onUdfcPipeClose(uv_handle_t *handle); +void onUdfcPipeClose(uv_handle_t *handle); int32_t udfcGetUdfTaskResultFromUvTask(SClientUdfTask *task, SClientUvTaskNode *uvTask); -void udfcAllocateBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf); -bool isUdfcUvMsgComplete(SClientConnBuf *connBuf); -void udfcUvHandleRsp(SClientUvConn *conn); -void udfcUvHandleError(SClientUvConn *conn); -void onUdfcPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf); -void onUdfcPipeWrite(uv_write_t *write, int status); -void onUdfcPipeConnect(uv_connect_t *connect, int status); +void udfcAllocateBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf); +bool isUdfcUvMsgComplete(SClientConnBuf *connBuf); +void udfcUvHandleRsp(SClientUvConn *conn); +void udfcUvHandleError(SClientUvConn *conn); +void onUdfcPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf); +void onUdfcPipeWrite(uv_write_t *write, int status); +void onUdfcPipeConnect(uv_connect_t *connect, int status); int32_t udfcInitializeUvTask(SClientUdfTask *task, int8_t uvTaskType, SClientUvTaskNode *uvTask); int32_t udfcQueueUvTask(SClientUvTaskNode *uvTask); int32_t udfcStartUvTask(SClientUvTaskNode *uvTask); -void udfcAsyncTaskCb(uv_async_t *async); -void cleanUpUvTasks(SUdfcProxy *udfc); -void udfStopAsyncCb(uv_async_t *async); -void constructUdfService(void *argsThread); +void udfcAsyncTaskCb(uv_async_t *async); +void cleanUpUvTasks(SUdfcProxy *udfc); +void udfStopAsyncCb(uv_async_t *async); +void constructUdfService(void *argsThread); int32_t udfcRunUdfUvTask(SClientUdfTask *task, int8_t uvTaskType); int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle); -int compareUdfcFuncSub(const void* elem1, const void* elem2); +int compareUdfcFuncSub(const void *elem1, const void *elem2); int32_t doTeardownUdf(UdfcFuncHandle handle); int32_t callUdf(UdfcFuncHandle handle, int8_t callType, SSDataBlock *input, SUdfInterBuf *state, SUdfInterBuf *state2, - SSDataBlock* output, SUdfInterBuf *newState); + SSDataBlock *output, SUdfInterBuf *newState); int32_t doCallUdfAggInit(UdfcFuncHandle handle, SUdfInterBuf *interBuf); int32_t doCallUdfAggProcess(UdfcFuncHandle handle, SSDataBlock *block, SUdfInterBuf *state, SUdfInterBuf *newState); -int32_t doCallUdfAggMerge(UdfcFuncHandle handle, SUdfInterBuf *interBuf1, SUdfInterBuf *interBuf2, SUdfInterBuf *resultBuf); +int32_t doCallUdfAggMerge(UdfcFuncHandle handle, SUdfInterBuf *interBuf1, SUdfInterBuf *interBuf2, + SUdfInterBuf *resultBuf); int32_t doCallUdfAggFinalize(UdfcFuncHandle handle, SUdfInterBuf *interBuf, SUdfInterBuf *resultData); -int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t numOfCols, SScalarParam* output); +int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t numOfCols, SScalarParam *output); int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols, SScalarParam *output); int32_t udfcOpen(); int32_t udfcClose(); -int32_t acquireUdfFuncHandle(char* udfName, UdfcFuncHandle* pHandle); -void releaseUdfFuncHandle(char* udfName); +int32_t acquireUdfFuncHandle(char *udfName, UdfcFuncHandle *pHandle); +void releaseUdfFuncHandle(char *udfName); int32_t cleanUpUdfs(); -bool udfAggGetEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); -bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo); +bool udfAggGetEnv(struct SFunctionNode *pFunc, SFuncExecEnv *pEnv); +bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo *pResultCellInfo); int32_t udfAggProcess(struct SqlFunctionCtx *pCtx); -int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock); +int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock *pBlock); -int compareUdfcFuncSub(const void* elem1, const void* elem2) { +int compareUdfcFuncSub(const void *elem1, const void *elem2) { SUdfcFuncStub *stub1 = (SUdfcFuncStub *)elem1; SUdfcFuncStub *stub2 = (SUdfcFuncStub *)elem2; return strcmp(stub1->udfName, stub2->udfName); } -int32_t acquireUdfFuncHandle(char* udfName, UdfcFuncHandle* pHandle) { +int32_t acquireUdfFuncHandle(char *udfName, UdfcFuncHandle *pHandle) { int32_t code = 0; uv_mutex_lock(&gUdfdProxy.udfStubsMutex); SUdfcFuncStub key = {0}; @@ -925,15 +903,15 @@ int32_t acquireUdfFuncHandle(char* udfName, UdfcFuncHandle* pHandle) { if (stubIndex != -1) { SUdfcFuncStub *foundStub = taosArrayGet(gUdfdProxy.udfStubs, stubIndex); UdfcFuncHandle handle = foundStub->handle; - if (handle != NULL && ((SUdfcUvSession*)handle)->udfUvPipe != NULL) { + if (handle != NULL && ((SUdfcUvSession *)handle)->udfUvPipe != NULL) { *pHandle = foundStub->handle; ++foundStub->refCount; foundStub->lastRefTime = taosGetTimestampUs(); uv_mutex_unlock(&gUdfdProxy.udfStubsMutex); return 0; } else { - fnInfo("invalid handle for %s, refCount: %d, last ref time: %"PRId64". remove it from cache", - udfName, foundStub->refCount, foundStub->lastRefTime); + fnInfo("invalid handle for %s, refCount: %d, last ref time: %" PRId64 ". remove it from cache", udfName, + foundStub->refCount, foundStub->lastRefTime); taosArrayRemove(gUdfdProxy.udfStubs, stubIndex); } } @@ -955,7 +933,7 @@ int32_t acquireUdfFuncHandle(char* udfName, UdfcFuncHandle* pHandle) { return code; } -void releaseUdfFuncHandle(char* udfName) { +void releaseUdfFuncHandle(char *udfName) { uv_mutex_lock(&gUdfdProxy.udfStubsMutex); SUdfcFuncStub key = {0}; strcpy(key.udfName, udfName); @@ -977,11 +955,11 @@ int32_t cleanUpUdfs() { } uv_mutex_lock(&gUdfdProxy.udfStubsMutex); - if (gUdfdProxy.udfStubs == NULL || taosArrayGetSize(gUdfdProxy.udfStubs) == 0) { + if (gUdfdProxy.udfStubs == NULL || taosArrayGetSize(gUdfdProxy.udfStubs) == 0) { uv_mutex_unlock(&gUdfdProxy.udfStubsMutex); return TSDB_CODE_SUCCESS; } - SArray* udfStubs = taosArrayInit(16, sizeof(SUdfcFuncStub)); + SArray *udfStubs = taosArrayInit(16, sizeof(SUdfcFuncStub)); int32_t i = 0; while (i < taosArrayGetSize(gUdfdProxy.udfStubs)) { SUdfcFuncStub *stub = taosArrayGet(gUdfdProxy.udfStubs, i); @@ -989,13 +967,13 @@ int32_t cleanUpUdfs() { fnInfo("tear down udf. udf name: %s, handle: %p, ref count: %d", stub->udfName, stub->handle, stub->refCount); doTeardownUdf(stub->handle); } else { - fnInfo("udf still in use. udf name: %s, ref count: %d, last ref time: %"PRId64", handle: %p", - stub->udfName, stub->refCount, stub->lastRefTime, stub->handle); + fnInfo("udf still in use. udf name: %s, ref count: %d, last ref time: %" PRId64 ", handle: %p", stub->udfName, + stub->refCount, stub->lastRefTime, stub->handle); UdfcFuncHandle handle = stub->handle; - if (handle != NULL && ((SUdfcUvSession*)handle)->udfUvPipe != NULL) { + if (handle != NULL && ((SUdfcUvSession *)handle)->udfUvPipe != NULL) { taosArrayPush(udfStubs, stub); } else { - fnInfo("udf invalid handle for %s, refCount: %d, last ref time: %"PRId64". remove it from cache", + fnInfo("udf invalid handle for %s, refCount: %d, last ref time: %" PRId64 ". remove it from cache", stub->udfName, stub->refCount, stub->lastRefTime); } } @@ -1009,7 +987,7 @@ int32_t cleanUpUdfs() { int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols, SScalarParam *output) { UdfcFuncHandle handle = NULL; - int32_t code = acquireUdfFuncHandle(udfName, &handle); + int32_t code = acquireUdfFuncHandle(udfName, &handle); if (code != 0) { return code; } @@ -1020,8 +998,8 @@ int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols, code = TSDB_CODE_UDF_INVALID_OUTPUT_TYPE; } else { if (session->outputType != output->columnData->info.type || session->outputLen != output->columnData->info.bytes) { - fnError("udfc scalar function calculate error. type mismatch. session type: %d(%d), output type: %d(%d)", session->outputType, - session->outputLen, output->columnData->info.type, output->columnData->info.bytes); + fnError("udfc scalar function calculate error. type mismatch. session type: %d(%d), output type: %d(%d)", + session->outputType, session->outputLen, output->columnData->info.type, output->columnData->info.bytes); code = TSDB_CODE_UDF_INVALID_OUTPUT_TYPE; } } @@ -1029,7 +1007,7 @@ int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols, return code; } -bool udfAggGetEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) { +bool udfAggGetEnv(struct SFunctionNode *pFunc, SFuncExecEnv *pEnv) { if (fmIsScalarFunc(pFunc->funcId)) { return false; } @@ -1037,23 +1015,23 @@ bool udfAggGetEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) { return true; } -bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo) { +bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo *pResultCellInfo) { if (functionSetup(pCtx, pResultCellInfo) != true) { return false; } UdfcFuncHandle handle; - int32_t udfCode = 0; + int32_t udfCode = 0; if ((udfCode = acquireUdfFuncHandle((char *)pCtx->udfName, &handle)) != 0) { fnError("udfAggInit error. step doSetupUdf. udf code: %d", udfCode); return false; } SUdfcUvSession *session = (SUdfcUvSession *)handle; - SUdfAggRes *udfRes = (SUdfAggRes*)GET_ROWCELL_INTERBUF(pResultCellInfo); - int32_t envSize = sizeof(SUdfAggRes) + session->outputLen + session->bufSize; + SUdfAggRes *udfRes = (SUdfAggRes *)GET_ROWCELL_INTERBUF(pResultCellInfo); + int32_t envSize = sizeof(SUdfAggRes) + session->outputLen + session->bufSize; memset(udfRes, 0, envSize); - udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes); - udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen; + udfRes->finalResBuf = (char *)udfRes + sizeof(SUdfAggRes); + udfRes->interResBuf = (char *)udfRes + sizeof(SUdfAggRes) + session->outputLen; SUdfInterBuf buf = {0}; if ((udfCode = doCallUdfAggInit(handle, &buf)) != 0) { @@ -1075,7 +1053,7 @@ bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResult } int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) { - int32_t udfCode = 0; + int32_t udfCode = 0; UdfcFuncHandle handle = 0; if ((udfCode = acquireUdfFuncHandle((char *)pCtx->udfName, &handle)) != 0) { fnError("udfAggProcess error. step acquireUdfFuncHandle. udf code: %d", udfCode); @@ -1083,16 +1061,16 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) { } SUdfcUvSession *session = handle; - SUdfAggRes* udfRes = (SUdfAggRes *)GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes); - udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen; + SUdfAggRes *udfRes = (SUdfAggRes *)GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + udfRes->finalResBuf = (char *)udfRes + sizeof(SUdfAggRes); + udfRes->interResBuf = (char *)udfRes + sizeof(SUdfAggRes) + session->outputLen; - SInputColumnInfoData* pInput = &pCtx->input; - int32_t numOfCols = pInput->numOfInputCols; - int32_t start = pInput->startRowIndex; - int32_t numOfRows = pInput->numOfRows; + SInputColumnInfoData *pInput = &pCtx->input; + int32_t numOfCols = pInput->numOfInputCols; + int32_t start = pInput->startRowIndex; + int32_t numOfRows = pInput->numOfRows; - SSDataBlock* pTempBlock = createDataBlock(); + SSDataBlock *pTempBlock = createDataBlock(); pTempBlock->info.rows = pInput->totalRows; pTempBlock->info.uid = pInput->uid; for (int32_t i = 0; i < numOfCols; ++i) { @@ -1101,9 +1079,7 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) { SSDataBlock *inputBlock = blockDataExtractBlock(pTempBlock, start, numOfRows); - SUdfInterBuf state = {.buf = udfRes->interResBuf, - .bufLen = session->bufSize, - .numOfResult = udfRes->interResNum}; + SUdfInterBuf state = {.buf = udfRes->interResBuf, .bufLen = session->bufSize, .numOfResult = udfRes->interResNum}; SUdfInterBuf newState = {0}; udfCode = doCallUdfAggProcess(session, inputBlock, &state, &newState); @@ -1133,8 +1109,8 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) { return udfCode; } -int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) { - int32_t udfCode = 0; +int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock *pBlock) { + int32_t udfCode = 0; UdfcFuncHandle handle = 0; if ((udfCode = acquireUdfFuncHandle((char *)pCtx->udfName, &handle)) != 0) { fnError("udfAggProcess error. step acquireUdfFuncHandle. udf code: %d", udfCode); @@ -1142,17 +1118,14 @@ int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) { } SUdfcUvSession *session = handle; - SUdfAggRes* udfRes = (SUdfAggRes *)GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes); - udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen; - + SUdfAggRes *udfRes = (SUdfAggRes *)GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + udfRes->finalResBuf = (char *)udfRes + sizeof(SUdfAggRes); + udfRes->interResBuf = (char *)udfRes + sizeof(SUdfAggRes) + session->outputLen; SUdfInterBuf resultBuf = {0}; - SUdfInterBuf state = {.buf = udfRes->interResBuf, - .bufLen = session->bufSize, - .numOfResult = udfRes->interResNum}; - int32_t udfCallCode= 0; - udfCallCode= doCallUdfAggFinalize(session, &state, &resultBuf); + SUdfInterBuf state = {.buf = udfRes->interResBuf, .bufLen = session->bufSize, .numOfResult = udfRes->interResNum}; + int32_t udfCallCode = 0; + udfCallCode = doCallUdfAggFinalize(session, &state, &resultBuf); if (udfCallCode != 0) { fnError("udfAggFinalize error. doCallUdfAggFinalize step. udf code:%d", udfCallCode); GET_RES_INFO(pCtx)->numOfRes = 0; @@ -1178,7 +1151,7 @@ int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) { void onUdfcPipeClose(uv_handle_t *handle) { SClientUvConn *conn = handle->data; if (!QUEUE_EMPTY(&conn->taskQueue)) { - QUEUE* h = QUEUE_HEAD(&conn->taskQueue); + QUEUE *h = QUEUE_HEAD(&conn->taskQueue); SClientUvTaskNode *task = QUEUE_DATA(h, SClientUvTaskNode, connTaskQueue); task->errCode = 0; QUEUE_REMOVE(&task->procTaskQueue); @@ -1189,7 +1162,7 @@ void onUdfcPipeClose(uv_handle_t *handle) { } taosMemoryFree(conn->readBuf.buf); taosMemoryFree(conn); - taosMemoryFree((uv_pipe_t *) handle); + taosMemoryFree((uv_pipe_t *)handle); } int32_t udfcGetUdfTaskResultFromUvTask(SClientUdfTask *task, SClientUvTaskNode *uvTask) { @@ -1197,7 +1170,7 @@ int32_t udfcGetUdfTaskResultFromUvTask(SClientUdfTask *task, SClientUvTaskNode * if (uvTask->type == UV_TASK_REQ_RSP) { if (uvTask->rspBuf.base != NULL) { SUdfResponse rsp = {0}; - void* buf = decodeUdfResponse(uvTask->rspBuf.base, &rsp); + void *buf = decodeUdfResponse(uvTask->rspBuf.base, &rsp); assert(uvTask->rspBuf.len == POINTER_DISTANCE(buf, uvTask->rspBuf.base)); task->errCode = rsp.code; @@ -1273,7 +1246,7 @@ void udfcAllocateBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf bool isUdfcUvMsgComplete(SClientConnBuf *connBuf) { if (connBuf->total == -1 && connBuf->len >= sizeof(int32_t)) { - connBuf->total = *(int32_t *) (connBuf->buf); + connBuf->total = *(int32_t *)(connBuf->buf); } if (connBuf->len == connBuf->cap && connBuf->total == connBuf->cap) { fnDebug("udfc complete message is received, now handle it"); @@ -1284,15 +1257,15 @@ bool isUdfcUvMsgComplete(SClientConnBuf *connBuf) { void udfcUvHandleRsp(SClientUvConn *conn) { SClientConnBuf *connBuf = &conn->readBuf; - int64_t seqNum = *(int64_t *) (connBuf->buf + sizeof(int32_t)); // msglen then seqnum + int64_t seqNum = *(int64_t *)(connBuf->buf + sizeof(int32_t)); // msglen then seqnum if (QUEUE_EMPTY(&conn->taskQueue)) { - fnError("udfc no task waiting on connection. response seqnum:%"PRId64, seqNum); + fnError("udfc no task waiting on connection. response seqnum:%" PRId64, seqNum); return; } - bool found = false; + bool found = false; SClientUvTaskNode *taskFound = NULL; - QUEUE* h = QUEUE_NEXT(&conn->taskQueue); + QUEUE *h = QUEUE_NEXT(&conn->taskQueue); SClientUvTaskNode *task = QUEUE_DATA(h, SClientUvTaskNode, connTaskQueue); while (h != &conn->taskQueue) { @@ -1327,7 +1300,7 @@ void udfcUvHandleRsp(SClientUvConn *conn) { void udfcUvHandleError(SClientUvConn *conn) { fnDebug("handle error on conn: %p, pipe: %p", conn, conn->pipe); while (!QUEUE_EMPTY(&conn->taskQueue)) { - QUEUE* h = QUEUE_HEAD(&conn->taskQueue); + QUEUE *h = QUEUE_HEAD(&conn->taskQueue); SClientUvTaskNode *task = QUEUE_DATA(h, SClientUvTaskNode, connTaskQueue); task->errCode = TSDB_CODE_UDF_PIPE_READ_ERR; QUEUE_REMOVE(&task->connTaskQueue); @@ -1335,14 +1308,14 @@ void udfcUvHandleError(SClientUvConn *conn) { uv_sem_post(&task->taskSem); } - uv_close((uv_handle_t *) conn->pipe, onUdfcPipeClose); + uv_close((uv_handle_t *)conn->pipe, onUdfcPipeClose); } void onUdfcPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) { fnDebug("udfc client %p, client read from pipe. nread: %zd", client, nread); if (nread == 0) return; - SClientUvConn *conn = client->data; + SClientUvConn *conn = client->data; SClientConnBuf *connBuf = &conn->readBuf; if (nread > 0) { connBuf->len += nread; @@ -1373,7 +1346,7 @@ void onUdfcPipeWrite(uv_write_t *write, int status) { void onUdfcPipeConnect(uv_connect_t *connect, int status) { SClientUvTaskNode *uvTask = connect->data; if (status != 0) { - fnError("client connect error, task seq: %"PRId64", code: %s", uvTask->seqNum, uv_strerror(status)); + fnError("client connect error, task seq: %" PRId64 ", code: %s", uvTask->seqNum, uv_strerror(status)); } uvTask->errCode = status; @@ -1392,7 +1365,7 @@ int32_t udfcInitializeUvTask(SClientUdfTask *task, int8_t uvTaskType, SClientUvT uvTask->pipe = task->session->udfUvPipe; SUdfRequest request; request.type = task->type; - request.seqNum = atomic_fetch_add_64(&gUdfTaskSeqNum, 1); + request.seqNum = atomic_fetch_add_64(&gUdfTaskSeqNum, 1); if (task->type == UDF_TASK_SETUP) { request.setup = task->_setup.req; @@ -1430,14 +1403,14 @@ int32_t udfcQueueUvTask(SClientUvTaskNode *uvTask) { uv_async_send(&udfc->loopTaskAync); uv_sem_wait(&uvTask->taskSem); - fnInfo("udfc uvTask finished. uvTask:%"PRId64"-%d-%p", uvTask->seqNum, uvTask->type, uvTask); + fnInfo("udfc uvTask finished. uvTask:%" PRId64 "-%d-%p", uvTask->seqNum, uvTask->type, uvTask); uv_sem_destroy(&uvTask->taskSem); return 0; } int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) { - fnDebug("event loop start uv task. uvTask: %"PRId64"-%d-%p", uvTask->seqNum, uvTask->type, uvTask); + fnDebug("event loop start uv task. uvTask: %" PRId64 "-%d-%p", uvTask->seqNum, uvTask->type, uvTask); int32_t code = 0; switch (uvTask->type) { @@ -1469,7 +1442,7 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) { } else { uv_write_t *write = taosMemoryMalloc(sizeof(uv_write_t)); write->data = pipe->data; - QUEUE* connTaskQueue = &((SClientUvConn*)pipe->data)->taskQueue; + QUEUE *connTaskQueue = &((SClientUvConn *)pipe->data)->taskQueue; QUEUE_INSERT_TAIL(connTaskQueue, &uvTask->connTaskQueue); int err = uv_write(write, (uv_stream_t *)pipe, &uvTask->reqBuf, 1, onUdfcPipeWrite); if (err != 0) { @@ -1492,8 +1465,7 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) { break; } default: { - fnError("udfc event loop unknown task type.") - break; + fnError("udfc event loop unknown task type.") break; } } @@ -1502,17 +1474,17 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) { void udfcAsyncTaskCb(uv_async_t *async) { SUdfcProxy *udfc = async->data; - QUEUE wq; + QUEUE wq; uv_mutex_lock(&udfc->taskQueueMutex); QUEUE_MOVE(&udfc->taskQueue, &wq); uv_mutex_unlock(&udfc->taskQueueMutex); while (!QUEUE_EMPTY(&wq)) { - QUEUE* h = QUEUE_HEAD(&wq); + QUEUE *h = QUEUE_HEAD(&wq); QUEUE_REMOVE(h); SClientUvTaskNode *task = QUEUE_DATA(h, SClientUvTaskNode, recvTaskQueue); - int32_t code = udfcStartUvTask(task); + int32_t code = udfcStartUvTask(task); if (code == 0) { QUEUE_INSERT_TAIL(&udfc->uvProcTaskQueue, &task->procTaskQueue); } else { @@ -1520,19 +1492,17 @@ void udfcAsyncTaskCb(uv_async_t *async) { uv_sem_post(&task->taskSem); } } - } void cleanUpUvTasks(SUdfcProxy *udfc) { - fnDebug("clean up uv tasks") - QUEUE wq; + fnDebug("clean up uv tasks") QUEUE wq; uv_mutex_lock(&udfc->taskQueueMutex); QUEUE_MOVE(&udfc->taskQueue, &wq); uv_mutex_unlock(&udfc->taskQueueMutex); while (!QUEUE_EMPTY(&wq)) { - QUEUE* h = QUEUE_HEAD(&wq); + QUEUE *h = QUEUE_HEAD(&wq); QUEUE_REMOVE(h); SClientUvTaskNode *task = QUEUE_DATA(h, SClientUvTaskNode, recvTaskQueue); if (udfc->udfcState == UDFC_STATE_STOPPING) { @@ -1542,7 +1512,7 @@ void cleanUpUvTasks(SUdfcProxy *udfc) { } while (!QUEUE_EMPTY(&udfc->uvProcTaskQueue)) { - QUEUE* h = QUEUE_HEAD(&udfc->uvProcTaskQueue); + QUEUE *h = QUEUE_HEAD(&udfc->uvProcTaskQueue); QUEUE_REMOVE(h); SClientUvTaskNode *task = QUEUE_DATA(h, SClientUvTaskNode, procTaskQueue); if (udfc->udfcState == UDFC_STATE_STOPPING) { @@ -1572,7 +1542,7 @@ void constructUdfService(void *argsThread) { QUEUE_INIT(&udfc->taskQueue); QUEUE_INIT(&udfc->uvProcTaskQueue); uv_barrier_wait(&udfc->initBarrier); - //TODO return value of uv_run + // TODO return value of uv_run uv_run(&udfc->uvLoop, UV_RUN_DEFAULT); uv_loop_close(&udfc->uvLoop); @@ -1596,8 +1566,7 @@ int32_t udfcOpen() { uv_barrier_wait(&proxy->initBarrier); uv_mutex_init(&proxy->udfStubsMutex); proxy->udfStubs = taosArrayInit(8, sizeof(SUdfcFuncStub)); - fnInfo("udfc initialized") - return 0; + fnInfo("udfc initialized") return 0; } int32_t udfcClose() { @@ -1644,7 +1613,7 @@ int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle) { if (gUdfdProxy.udfcState != UDFC_STATE_READY) { return TSDB_CODE_UDF_INVALID_STATE; } - SClientUdfTask *task = taosMemoryCalloc(1,sizeof(SClientUdfTask)); + SClientUdfTask *task = taosMemoryCalloc(1, sizeof(SClientUdfTask)); task->errCode = 0; task->session = taosMemoryCalloc(1, sizeof(SUdfcUvSession)); task->session->udfc = &gUdfdProxy; @@ -1681,16 +1650,16 @@ int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle) { } int32_t callUdf(UdfcFuncHandle handle, int8_t callType, SSDataBlock *input, SUdfInterBuf *state, SUdfInterBuf *state2, - SSDataBlock* output, SUdfInterBuf *newState) { + SSDataBlock *output, SUdfInterBuf *newState) { fnDebug("udfc call udf. callType: %d, funcHandle: %p", callType, handle); - SUdfcUvSession *session = (SUdfcUvSession *) handle; + SUdfcUvSession *session = (SUdfcUvSession *)handle; if (session->udfUvPipe == NULL) { fnError("No pipe to udfd"); return TSDB_CODE_UDF_PIPE_NO_PIPE; } SClientUdfTask *task = taosMemoryCalloc(1, sizeof(SClientUdfTask)); task->errCode = 0; - task->session = (SUdfcUvSession *) handle; + task->session = (SUdfcUvSession *)handle; task->type = UDF_TASK_CALL; SUdfCallRequest *req = &task->_call.req; @@ -1767,15 +1736,16 @@ int32_t doCallUdfAggInit(UdfcFuncHandle handle, SUdfInterBuf *interBuf) { // input: block, state // output: interbuf, int32_t doCallUdfAggProcess(UdfcFuncHandle handle, SSDataBlock *block, SUdfInterBuf *state, SUdfInterBuf *newState) { - int8_t callType = TSDB_UDF_CALL_AGG_PROC; + int8_t callType = TSDB_UDF_CALL_AGG_PROC; int32_t err = callUdf(handle, callType, block, state, NULL, NULL, newState); return err; } // input: interbuf1, interbuf2 // output: resultBuf -int32_t doCallUdfAggMerge(UdfcFuncHandle handle, SUdfInterBuf *interBuf1, SUdfInterBuf *interBuf2, SUdfInterBuf *resultBuf) { - int8_t callType = TSDB_UDF_CALL_AGG_MERGE; +int32_t doCallUdfAggMerge(UdfcFuncHandle handle, SUdfInterBuf *interBuf1, SUdfInterBuf *interBuf2, + SUdfInterBuf *resultBuf) { + int8_t callType = TSDB_UDF_CALL_AGG_MERGE; int32_t err = callUdf(handle, callType, NULL, interBuf1, interBuf2, NULL, resultBuf); return err; } @@ -1783,17 +1753,17 @@ int32_t doCallUdfAggMerge(UdfcFuncHandle handle, SUdfInterBuf *interBuf1, SUdfIn // input: interBuf // output: resultData int32_t doCallUdfAggFinalize(UdfcFuncHandle handle, SUdfInterBuf *interBuf, SUdfInterBuf *resultData) { - int8_t callType = TSDB_UDF_CALL_AGG_FIN; + int8_t callType = TSDB_UDF_CALL_AGG_FIN; int32_t err = callUdf(handle, callType, NULL, interBuf, NULL, NULL, resultData); return err; } -int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t numOfCols, SScalarParam* output) { - int8_t callType = TSDB_UDF_CALL_SCALA_PROC; +int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t numOfCols, SScalarParam *output) { + int8_t callType = TSDB_UDF_CALL_SCALA_PROC; SSDataBlock inputBlock = {0}; convertScalarParamToDataBlock(input, numOfCols, &inputBlock); SSDataBlock resultBlock = {0}; - int32_t err = callUdf(handle, callType, &inputBlock, NULL, NULL, &resultBlock, NULL); + int32_t err = callUdf(handle, callType, &inputBlock, NULL, NULL, &resultBlock, NULL); if (err == 0) { convertDataBlockToScalarParm(&resultBlock, output); taosArrayDestroy(resultBlock.pDataBlock); @@ -1804,7 +1774,7 @@ int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t } int32_t doTeardownUdf(UdfcFuncHandle handle) { - SUdfcUvSession *session = (SUdfcUvSession *) handle; + SUdfcUvSession *session = (SUdfcUvSession *)handle; if (session->udfUvPipe == NULL) { fnError("tear down udf. pipe to udfd does not exist. udf name: %s", session->udfName); @@ -1827,7 +1797,7 @@ int32_t doTeardownUdf(UdfcFuncHandle handle) { udfcRunUdfUvTask(task, UV_TASK_DISCONNECT); fnInfo("tear down udf. udf name: %s, udf func handle: %p", session->udfName, handle); - //TODO: synchronization refactor between libuv event loop and request thread + // TODO: synchronization refactor between libuv event loop and request thread if (session->udfUvPipe != NULL && session->udfUvPipe->data != NULL) { SClientUvConn *conn = session->udfUvPipe->data; conn->session = NULL; diff --git a/source/libs/function/test/runUdf.c b/source/libs/function/test/runUdf.c index 7395f1e14cfba22e497e8bc760a5883bbc4e11cd..f1e3f4c60c281ebac963ac65c7d7d9f8437652cd 100644 --- a/source/libs/function/test/runUdf.c +++ b/source/libs/function/test/runUdf.c @@ -53,7 +53,7 @@ int scalarFuncTest() { blockDataEnsureCapacity(pBlock, 1024); pBlock->info.rows = 1024; - SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, 0); + SColumnInfoData *pCol = taosArrayGet(pBlock->pDataBlock, 0); for (int32_t j = 0; j < pBlock->info.rows; ++j) { colDataAppendInt32(pCol, j, &j); } @@ -68,14 +68,13 @@ int scalarFuncTest() { SColumnInfoData *col = output.columnData; for (int32_t i = 0; i < output.numOfRows; ++i) { - if (i % 100 == 0) - fprintf(stderr, "%d\t%d\n", i, *(int32_t *)(col->pData + i * sizeof(int32_t))); + if (i % 100 == 0) fprintf(stderr, "%d\t%d\n", i, *(int32_t *)(col->pData + i * sizeof(int32_t))); } colDataDestroy(output.columnData); taosMemoryFree(output.columnData); } int64_t end = taosGetTimestampUs(); - fprintf(stderr, "time: %f\n", (end-beg)/1000.0); + fprintf(stderr, "time: %f\n", (end - beg) / 1000.0); doTeardownUdf(handle); return 0; @@ -92,13 +91,13 @@ int aggregateFuncTest() { SSDataBlock *pBlock = createDataBlock(); for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); ++i) { SColumnInfoData colInfo = createColumnInfoData(TSDB_DATA_TYPE_INT, sizeof(int32_t), 1); - blockDataAppendColInfo(pBlock, &colInfo); + blockDataAppendColInfo(pBlock, &colInfo); } blockDataEnsureCapacity(pBlock, 1024); pBlock->info.rows = 1024; - SColumnInfoData* pColInfo = bdGetColumnInfoData(pBlock, 0); + SColumnInfoData *pColInfo = bdGetColumnInfoData(pBlock, 0); for (int32_t j = 0; j < pBlock->info.rows; ++j) { colDataAppendInt32(pColInfo, j, &j); } @@ -111,7 +110,7 @@ int aggregateFuncTest() { taosArrayDestroy(pBlock->pDataBlock); doCallUdfAggFinalize(handle, &newBuf, &resultBuf); - fprintf(stderr, "agg result: %f\n", *(double*)resultBuf.buf); + fprintf(stderr, "agg result: %f\n", *(double *)resultBuf.buf); freeUdfInterBuf(&buf); freeUdfInterBuf(&newBuf); diff --git a/source/libs/function/test/udf1.c b/source/libs/function/test/udf1.c index 5be18af553498bf2b05607b69223c302d3826fae..71d30b67557847dcdf451cefb20c7b144d214cf8 100644 --- a/source/libs/function/test/udf1.c +++ b/source/libs/function/test/udf1.c @@ -1,6 +1,6 @@ -#include -#include #include +#include +#include #ifdef LINUX #include #endif @@ -9,16 +9,11 @@ #endif #include "taosudf.h" +DLL_EXPORT int32_t udf1_init() { return 0; } -DLL_EXPORT int32_t udf1_init() { - return 0; -} - -DLL_EXPORT int32_t udf1_destroy() { - return 0; -} +DLL_EXPORT int32_t udf1_destroy() { return 0; } -DLL_EXPORT int32_t udf1(SUdfDataBlock* block, SUdfColumn *resultCol) { +DLL_EXPORT int32_t udf1(SUdfDataBlock *block, SUdfColumn *resultCol) { SUdfColumnMeta *meta = &resultCol->colMeta; meta->bytes = 4; meta->type = TSDB_DATA_TYPE_INT; @@ -35,14 +30,14 @@ DLL_EXPORT int32_t udf1(SUdfDataBlock* block, SUdfColumn *resultCol) { break; } } - if ( j == block->numOfCols) { + if (j == block->numOfCols) { int32_t luckyNum = 88; udfColDataSet(resultCol, i, (char *)&luckyNum, false); } } - //to simulate actual processing delay by udf + // to simulate actual processing delay by udf #ifdef LINUX - usleep(1 * 1000); // usleep takes sleep time in us (1 millionth of a second) + usleep(1 * 1000); // usleep takes sleep time in us (1 millionth of a second) #endif #ifdef WINDOWS Sleep(1); diff --git a/source/libs/function/test/udf2.c b/source/libs/function/test/udf2.c index 975832209eb6ec8e28967c54faf551b359ded455..e24789d0fb4095f2fdc75d8d1ce3e8dc1355e4c6 100644 --- a/source/libs/function/test/udf2.c +++ b/source/libs/function/test/udf2.c @@ -1,32 +1,27 @@ -#include -#include -#include #include +#include +#include +#include #include "taosudf.h" -DLL_EXPORT int32_t udf2_init() { - return 0; -} +DLL_EXPORT int32_t udf2_init() { return 0; } -DLL_EXPORT int32_t udf2_destroy() { - return 0; -} +DLL_EXPORT int32_t udf2_destroy() { return 0; } -DLL_EXPORT int32_t udf2_start(SUdfInterBuf *buf) { +DLL_EXPORT int32_t udf2_start(SUdfInterBuf* buf) { *(int64_t*)(buf->buf) = 0; buf->bufLen = sizeof(double); buf->numOfResult = 0; return 0; } -DLL_EXPORT int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf) { +DLL_EXPORT int32_t udf2(SUdfDataBlock* block, SUdfInterBuf* interBuf, SUdfInterBuf* newInterBuf) { double sumSquares = *(double*)interBuf->buf; int8_t numNotNull = 0; for (int32_t i = 0; i < block->numOfCols; ++i) { SUdfColumn* col = block->udfCols[i]; - if (!(col->colMeta.type == TSDB_DATA_TYPE_INT || - col->colMeta.type == TSDB_DATA_TYPE_DOUBLE)) { + if (!(col->colMeta.type == TSDB_DATA_TYPE_INT || col->colMeta.type == TSDB_DATA_TYPE_DOUBLE)) { return TSDB_CODE_UDF_INVALID_INPUT; } } @@ -38,18 +33,18 @@ DLL_EXPORT int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterB } switch (col->colMeta.type) { case TSDB_DATA_TYPE_INT: { - char* cell = udfColDataGetData(col, j); + char* cell = udfColDataGetData(col, j); int32_t num = *(int32_t*)cell; sumSquares += (double)num * num; break; } case TSDB_DATA_TYPE_DOUBLE: { - char* cell = udfColDataGetData(col, j); + char* cell = udfColDataGetData(col, j); double num = *(double*)cell; sumSquares += num * num; break; } - default: + default: break; } ++numNotNull; @@ -67,7 +62,7 @@ DLL_EXPORT int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterB return 0; } -DLL_EXPORT int32_t udf2_finish(SUdfInterBuf* buf, SUdfInterBuf *resultData) { +DLL_EXPORT int32_t udf2_finish(SUdfInterBuf* buf, SUdfInterBuf* resultData) { if (buf->numOfResult == 0) { resultData->numOfResult = 0; return 0; diff --git a/source/libs/index/test/index_executor_tests.cpp b/source/libs/index/test/index_executor_tests.cpp index a0ac79a2976243a2097f3e4290951322b2b65f9a..8b03f3b251da4ae8698bf976753f6f7e3a86ab96 100644 --- a/source/libs/index/test/index_executor_tests.cpp +++ b/source/libs/index/test/index_executor_tests.cpp @@ -48,7 +48,7 @@ double sifLeftVd = 21.0, sifRightVd = 10.0; void sifFreeDataBlock(void *block) { blockDataDestroy(*(SSDataBlock **)block); } void sifInitLogFile() { - const char * defaultLogFileNamePrefix = "taoslog"; + const char *defaultLogFileNamePrefix = "taoslog"; const int32_t maxLogFileNum = 10; tsAsyncLog = 0; @@ -96,7 +96,7 @@ void sifAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *sl } void sifMakeValueNode(SNode **pNode, int32_t dataType, void *value) { - SNode * node = (SNode *)nodesMakeNode(QUERY_NODE_VALUE); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_VALUE); SValueNode *vnode = (SValueNode *)node; vnode->node.resType.type = dataType; @@ -113,7 +113,7 @@ void sifMakeValueNode(SNode **pNode, int32_t dataType, void *value) { } void sifMakeColumnNode(SNode **pNode, const char *db, const char *colName, EColumnType colType, uint8_t colValType) { - SNode * node = (SNode *)nodesMakeNode(QUERY_NODE_COLUMN); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_COLUMN); SColumnNode *rnode = (SColumnNode *)node; memcpy(rnode->dbName, db, strlen(db)); memcpy(rnode->colName, colName, strlen(colName)); @@ -125,7 +125,7 @@ void sifMakeColumnNode(SNode **pNode, const char *db, const char *colName, EColu } void sifMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight) { - SNode * node = (SNode *)nodesMakeNode(QUERY_NODE_OPERATOR); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_OPERATOR); SOperatorNode *onode = (SOperatorNode *)node; onode->node.resType.type = resType; onode->node.resType.bytes = tDataTypes[resType].bytes; @@ -138,7 +138,7 @@ void sifMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode * } void sifMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { - SNode * node = (SNode *)nodesMakeNode(QUERY_NODE_NODE_LIST); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_NODE_LIST); SNodeListNode *lnode = (SNodeListNode *)node; lnode->dataType.type = resType; lnode->pNodeList = list; @@ -147,7 +147,7 @@ void sifMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { } void sifMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeList, int32_t nodeNum) { - SNode * node = (SNode *)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); SLogicConditionNode *onode = (SLogicConditionNode *)node; onode->condType = opType; onode->node.resType.type = TSDB_DATA_TYPE_BOOL; @@ -162,7 +162,7 @@ void sifMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeLis } void sifMakeTargetNode(SNode **pNode, int16_t dataBlockId, int16_t slotId, SNode *snode) { - SNode * node = (SNode *)nodesMakeNode(QUERY_NODE_TARGET); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_TARGET); STargetNode *onode = (STargetNode *)node; onode->pExpr = snode; onode->dataBlockId = dataBlockId; diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index d387a432e13d12a55a03af089aab2228f6863ab0..eab5a334508765f876a2289af90190ec2648df2b 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -556,7 +556,7 @@ void monSendReport() { char *pCont = tjsonToString(pMonitor->pJson); // uDebugL("report cont:%s\n", pCont); - if (pCont != NULL) { + if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; if (taosSendHttpReport(tsMonitor.cfg.server, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { uError("failed to send monitor msg"); diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index dac9b857404d202ec56e9d2e7b57c954d1a3c143..b9b365fb42c62ec9400b85450c3bca40ac920730 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -131,7 +131,7 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { COPY_SCALAR_FIELD(placeholderNo); COPY_SCALAR_FIELD(typeData); COPY_SCALAR_FIELD(unit); - if (!pSrc->translate) { + if (!pSrc->translate || pSrc->isNull) { return TSDB_CODE_SUCCESS; } switch (pSrc->node.resType.type) { diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index e401a3da7fe4fdb9815eae3fedfec9e5b281689d..f0f1fc99756bacf892e9a7ce48677b94a06c0fd3 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -3011,7 +3011,7 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddBoolToObject(pJson, jkValueIsNull, pNode->isNull); } - if (TSDB_CODE_SUCCESS == code && pNode->translate) { + if (TSDB_CODE_SUCCESS == code && pNode->translate && !pNode->isNull) { code = datumToJson(pNode, pJson); } @@ -3161,7 +3161,7 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetBoolValue(pJson, jkValueIsNull, &pNode->isNull); } - if (TSDB_CODE_SUCCESS == code && pNode->translate) { + if (TSDB_CODE_SUCCESS == code && pNode->translate && !pNode->isNull) { code = jsonToDatum(pJson, pNode); } diff --git a/source/libs/nodes/src/nodesMsgFuncs.c b/source/libs/nodes/src/nodesMsgFuncs.c index cdc4e66e4247615697a6090e2ad1c1e8a1659529..9e89955ae5394db0923ab8eb82d99bde755a8e53 100644 --- a/source/libs/nodes/src/nodesMsgFuncs.c +++ b/source/libs/nodes/src/nodesMsgFuncs.c @@ -478,7 +478,10 @@ static int32_t tlvDecodeValueEnum(STlvDecoder* pDecoder, void* pValue, int16_t l return code; } -static int32_t tlvDecodeCStr(STlv* pTlv, char* pValue) { +static int32_t tlvDecodeCStr(STlv* pTlv, char* pValue, int32_t size) { + if (pTlv->len > size - 1) { + return TSDB_CODE_FAILED; + } memcpy(pValue, pTlv->value, pTlv->len); return TSDB_CODE_SUCCESS; } @@ -919,9 +922,14 @@ static int32_t msgToDatum(STlv* pTlv, void* pObj) { } break; } - case TSDB_DATA_TYPE_JSON: + case TSDB_DATA_TYPE_JSON: { + if (pTlv->len <= 0 || pTlv->len > TSDB_MAX_JSON_TAG_LEN) { + code = TSDB_CODE_FAILED; + break; + } code = tlvDecodeDynBinary(pTlv, (void**)&pNode->datum.p); break; + } case TSDB_DATA_TYPE_DECIMAL: case TSDB_DATA_TYPE_BLOB: // todo @@ -1097,7 +1105,7 @@ static int32_t msgToFunctionNode(STlvDecoder* pDecoder, void* pObj) { code = tlvDecodeObjFromTlv(pTlv, msgToExprNode, &pNode->node); break; case FUNCTION_CODE_FUNCTION_NAME: - code = tlvDecodeCStr(pTlv, pNode->functionName); + code = tlvDecodeCStr(pTlv, pNode->functionName, sizeof(pNode->functionName)); break; case FUNCTION_CODE_FUNCTION_ID: code = tlvDecodeI32(pTlv, &pNode->funcId); @@ -1226,10 +1234,10 @@ static int32_t msgToName(STlvDecoder* pDecoder, void* pObj) { code = tlvDecodeI32(pTlv, &pNode->acctId); break; case NAME_CODE_DB_NAME: - code = tlvDecodeCStr(pTlv, pNode->dbname); + code = tlvDecodeCStr(pTlv, pNode->dbname, sizeof(pNode->dbname)); break; case NAME_CODE_TABLE_NAME: - code = tlvDecodeCStr(pTlv, pNode->tname); + code = tlvDecodeCStr(pTlv, pNode->tname, sizeof(pNode->tname)); break; default: break; @@ -1538,7 +1546,7 @@ static int32_t msgToEp(STlvDecoder* pDecoder, void* pObj) { tlvForEach(pDecoder, pTlv, code) { switch (pTlv->type) { case EP_CODE_FQDN: - code = tlvDecodeCStr(pTlv, pNode->fqdn); + code = tlvDecodeCStr(pTlv, pNode->fqdn, sizeof(pNode->fqdn)); break; case EP_CODE_port: code = tlvDecodeU16(pTlv, &pNode->port); @@ -3207,7 +3215,7 @@ static int32_t msgToPhysiQueryInsertNode(STlvDecoder* pDecoder, void* pObj) { code = tlvDecodeI8(pTlv, &pNode->tableType); break; case PHY_QUERY_INSERT_CODE_TABLE_NAME: - code = tlvDecodeCStr(pTlv, pNode->tableName); + code = tlvDecodeCStr(pTlv, pNode->tableName, sizeof(pNode->tableName)); break; case PHY_QUERY_INSERT_CODE_VG_ID: code = tlvDecodeI32(pTlv, &pNode->vgId); @@ -3284,10 +3292,10 @@ static int32_t msgToPhysiDeleteNode(STlvDecoder* pDecoder, void* pObj) { code = tlvDecodeI8(pTlv, &pNode->tableType); break; case PHY_DELETER_CODE_TABLE_FNAME: - code = tlvDecodeCStr(pTlv, pNode->tableFName); + code = tlvDecodeCStr(pTlv, pNode->tableFName, sizeof(pNode->tableFName)); break; case PHY_DELETER_CODE_TS_COL_NAME: - code = tlvDecodeCStr(pTlv, pNode->tsColName); + code = tlvDecodeCStr(pTlv, pNode->tsColName, sizeof(pNode->tsColName)); break; case PHY_DELETER_CODE_DELETE_TIME_RANGE: code = tlvDecodeObjFromTlv(pTlv, msgToTimeWindow, &pNode->deleteTimeRange); diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 6e964fb53a7e36b435169f04daced63d43f6a786..bc0c4d42bbccc66e8a00179d523f86159f03e33e 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -209,6 +209,10 @@ int64_t nodesMakeAllocatorWeakRef(int64_t allocatorId) { } SNodeAllocator* pAllocator = taosAcquireRef(g_allocatorReqRefPool, allocatorId); + if (NULL == pAllocator) { + nodesError("allocator id %" PRIx64 " weak reference failed", allocatorId); + return -1; + } return pAllocator->self; } @@ -1604,7 +1608,7 @@ char* nodesGetStrValueFromNode(SValueNode* pNode) { bool nodesIsExprNode(const SNode* pNode) { ENodeType type = nodeType(pNode); return (QUERY_NODE_COLUMN == type || QUERY_NODE_VALUE == type || QUERY_NODE_OPERATOR == type || - QUERY_NODE_FUNCTION == type || QUERY_NODE_LOGIC_CONDITION == type); + QUERY_NODE_FUNCTION == type || QUERY_NODE_LOGIC_CONDITION == type || QUERY_NODE_CASE_WHEN == type); } bool nodesIsUnaryOp(const SOperatorNode* pOp) { @@ -1716,9 +1720,10 @@ static EDealRes doCollect(SCollectColumnsCxt* pCxt, SColumnNode* pCol, SNode* pN char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; int32_t len = 0; if ('\0' == pCol->tableAlias[0]) { - len = sprintf(name, "%s", pCol->colName); + len = snprintf(name, sizeof(name), "%s", pCol->colName); + } else { + len = snprintf(name, sizeof(name), "%s.%s", pCol->tableAlias, pCol->colName); } - len = sprintf(name, "%s.%s", pCol->tableAlias, pCol->colName); if (NULL == taosHashGet(pCxt->pColHash, name, len)) { pCxt->errCode = taosHashPut(pCxt->pColHash, name, len, NULL, 0); if (TSDB_CODE_SUCCESS == pCxt->errCode) { diff --git a/source/libs/parser/inc/parInsertData.h b/source/libs/parser/inc/parInsertData.h index ddfcd3a249afe1767cd50bdb433ce2f712354af8..6d0ba29eb71357b82371566f3e5024e2fcaff239 100644 --- a/source/libs/parser/inc/parInsertData.h +++ b/source/libs/parser/inc/parInsertData.h @@ -18,9 +18,9 @@ #include "catalog.h" #include "os.h" +#include "query.h" #include "tname.h" #include "ttypes.h" -#include "query.h" #define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED) diff --git a/source/libs/parser/inc/parToken.h b/source/libs/parser/inc/parToken.h index 787abf287e3bcf4f42e505d40bea0b7230cfc7e7..fb4b46aa35094fd3ac65171c5499c038eb92d233 100644 --- a/source/libs/parser/inc/parToken.h +++ b/source/libs/parser/inc/parToken.h @@ -175,8 +175,6 @@ _end: void taosCleanupKeywordsTable(); -SToken tscReplaceStrToken(char **str, SToken *token, const char *newToken); - SToken taosTokenDup(SToken *pToken, char *buf, int32_t len); #ifdef __cplusplus diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 2e6f83936848b044b4f13f894ec44672db9bfec1..15b939f14b3bfb32298fac514d22655a8b00d9fe 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -518,7 +518,7 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTa if (NULL != pDbName) { COPY_STRING_FORM_ID_TOKEN(realTable->table.dbName, pDbName); } else { - strcpy(realTable->table.dbName, pCxt->pQueryCxt->db); + snprintf(realTable->table.dbName, sizeof(realTable->table.dbName), "%s", pCxt->pQueryCxt->db); } if (NULL != pTableAlias && TK_NK_NIL != pTableAlias->type) { COPY_STRING_FORM_ID_TOKEN(realTable->table.tableAlias, pTableAlias); @@ -599,7 +599,7 @@ SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) { state->pCol = createPrimaryKeyCol(pCxt, NULL); if (NULL == state->pCol) { nodesDestroyNode((SNode*)state); - CHECK_OUT_OF_MEM(state->pCol); + CHECK_OUT_OF_MEM(NULL); } state->pExpr = pExpr; return (SNode*)state; @@ -613,7 +613,7 @@ SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode interval->pCol = createPrimaryKeyCol(pCxt, NULL); if (NULL == interval->pCol) { nodesDestroyNode((SNode*)interval); - CHECK_OUT_OF_MEM(interval->pCol); + CHECK_OUT_OF_MEM(NULL); } interval->pInterval = pInterval; interval->pOffset = pOffset; @@ -631,7 +631,7 @@ SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues) { fill->pWStartTs = nodesMakeNode(QUERY_NODE_FUNCTION); if (NULL == fill->pWStartTs) { nodesDestroyNode((SNode*)fill); - CHECK_OUT_OF_MEM(fill->pWStartTs); + CHECK_OUT_OF_MEM(NULL); } strcpy(((SFunctionNode*)fill->pWStartTs)->functionName, "_wstart"); return (SNode*)fill; @@ -1495,10 +1495,10 @@ SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool igno CHECK_OUT_OF_MEM(pStmt); pStmt->indexType = type; pStmt->ignoreExists = ignoreExists; - strcpy(pStmt->indexDbName, ((SRealTableNode*)pIndexName)->table.dbName); - strcpy(pStmt->indexName, ((SRealTableNode*)pIndexName)->table.tableName); - strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); - strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); + snprintf(pStmt->indexDbName, sizeof(pStmt->indexDbName), "%s", ((SRealTableNode*)pIndexName)->table.dbName); + snprintf(pStmt->indexName, sizeof(pStmt->indexName), "%s", ((SRealTableNode*)pIndexName)->table.tableName); + snprintf(pStmt->dbName, sizeof(pStmt->dbName), "%s", ((SRealTableNode*)pRealTable)->table.dbName); + snprintf(pStmt->tableName, sizeof(pStmt->tableName), "%s", ((SRealTableNode*)pRealTable)->table.tableName); nodesDestroyNode(pIndexName); nodesDestroyNode(pRealTable); pStmt->pCols = pCols; @@ -1524,8 +1524,8 @@ SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* SDropIndexStmt* pStmt = (SDropIndexStmt*)nodesMakeNode(QUERY_NODE_DROP_INDEX_STMT); CHECK_OUT_OF_MEM(pStmt); pStmt->ignoreNotExists = ignoreNotExists; - strcpy(pStmt->indexDbName, ((SRealTableNode*)pIndexName)->table.dbName); - strcpy(pStmt->indexName, ((SRealTableNode*)pIndexName)->table.tableName); + snprintf(pStmt->indexDbName, sizeof(pStmt->indexDbName), "%s", ((SRealTableNode*)pIndexName)->table.dbName); + snprintf(pStmt->indexName, sizeof(pStmt->indexName), "%s", ((SRealTableNode*)pIndexName)->table.tableName); nodesDestroyNode(pIndexName); return (SNode*)pStmt; } @@ -1818,7 +1818,7 @@ SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDb SNode* createFuncForDelete(SAstCreateContext* pCxt, const char* pFuncName) { SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); CHECK_OUT_OF_MEM(pFunc); - strcpy(pFunc->functionName, pFuncName); + snprintf(pFunc->functionName, sizeof(pFunc->functionName), "%s", pFuncName); if (TSDB_CODE_SUCCESS != nodesListMakeStrictAppend(&pFunc->pParameterList, createPrimaryKeyCol(pCxt, NULL))) { nodesDestroyNode((SNode*)pFunc); CHECK_OUT_OF_MEM(NULL); diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index eec20f91e4ab75c645fd0584ca7213fbd5356514..5b861ef79acbe0bc59d544739297e98e2be7bcc6 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -378,7 +378,9 @@ static int parseTime(char** end, SToken* pToken, int16_t timePrec, int64_t* time } else if (pToken->type == TK_TODAY) { ts = taosGetTimestampToday(timePrec); } else if (pToken->type == TK_NK_INTEGER) { - toInteger(pToken->z, pToken->n, 10, &ts); + if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &ts)) { + return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp format", pToken->z); + } } else { // parse the RFC-3339/ISO-8601 timestamp format string if (taosParseTime(pToken->z, time, pToken->n, timePrec, tsDaylight) != TSDB_CODE_SUCCESS) { return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp format", pToken->z); @@ -591,8 +593,6 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int case TSDB_DATA_TYPE_BIGINT: { if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv)) { return buildSyntaxErrMsg(pMsgBuf, "invalid bigint data", pToken->z); - } else if (!IS_VALID_BIGINT(iv)) { - return buildSyntaxErrMsg(pMsgBuf, "bigint data overflow", pToken->z); } return func(pMsgBuf, &iv, pSchema->bytes, param); } @@ -894,10 +894,7 @@ static int32_t parseTagToken(char** end, SToken* pToken, SSchema* pSchema, int16 case TSDB_DATA_TYPE_BIGINT: { if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv)) { return buildSyntaxErrMsg(pMsgBuf, "invalid bigint data", pToken->z); - } else if (!IS_VALID_BIGINT(iv)) { - return buildSyntaxErrMsg(pMsgBuf, "bigint data overflow", pToken->z); } - val->i64 = iv; break; } @@ -1173,7 +1170,7 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, int32_t tbNo, SName* NEXT_TOKEN(pCxt->pSql, sToken); SName sname; - createSName(&sname, &sToken, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg); + CHECK_CODE(createSName(&sname, &sToken, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg)); char dbFName[TSDB_DB_FNAME_LEN]; tNameGetFullDbName(&sname, dbFName); strcpy(pCxt->sTableName, sname.tname); @@ -1605,7 +1602,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { if (!pCxt->pComCxt->needMultiParse) { continue; } else { - parserInfo("0x%" PRIx64 " insert from csv. File is too large, do it in batches.", pCxt->pComCxt->requestId); + parserDebug("0x%" PRIx64 " insert from csv. File is too large, do it in batches.", pCxt->pComCxt->requestId); break; } } @@ -1613,7 +1610,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { return buildSyntaxErrMsg(&pCxt->msg, "keyword VALUES or FILE is expected", sToken.z); } - parserInfo("0x%" PRIx64 " insert input rows: %d", pCxt->pComCxt->requestId, pCxt->totalNum); + parserDebug("0x%" PRIx64 " insert input rows: %d", pCxt->pComCxt->requestId, pCxt->totalNum); if (TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT)) { SParsedDataColInfo* tags = taosMemoryMalloc(sizeof(pCxt->tags)); @@ -1650,7 +1647,7 @@ static int32_t parseInsertBodyAgain(SInsertParseContext* pCxt) { pCxt->pComCxt->needMultiParse = false; return TSDB_CODE_SUCCESS; } - parserInfo("0x%" PRIx64 " insert again input rows: %d", pCxt->pComCxt->requestId, pCxt->totalNum); + parserDebug("0x%" PRIx64 " insert again input rows: %d", pCxt->pComCxt->requestId, pCxt->totalNum); // merge according to vgId if (taosHashGetSize(pCxt->pTableBlockHashObj) > 0) { CHECK_CODE(mergeTableDataBlocks(pCxt->pTableBlockHashObj, pCxt->pOutput->payloadType, &pCxt->pVgDataBlocks)); diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index e8c877bed2d69346cd718625688b0db3de85ae69..997e680c99c8a93fad53543cd9b5aeec2c9e1154 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -// clang-format off + #include "parInsertData.h" #include "catalog.h" @@ -25,8 +25,8 @@ (((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert typedef struct SBlockKeyTuple { - TSKEY skey; - void* payloadAddr; + TSKEY skey; + void* payloadAddr; int16_t index; } SBlockKeyTuple; @@ -194,8 +194,8 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq) { SEncoder coder = {0}; - char* pBuf; - int32_t len; + char* pBuf; + int32_t len; int32_t ret = 0; tEncodeSize(tEncodeSVCreateTbReq, pCreateTbReq, len, ret); @@ -211,19 +211,19 @@ int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq) } } - pBuf= pBlocks->pData + pBlocks->size; + pBuf = pBlocks->pData + pBlocks->size; tEncoderInit(&coder, pBuf, len); - tEncodeSVCreateTbReq(&coder, pCreateTbReq); + int32_t code = tEncodeSVCreateTbReq(&coder, pCreateTbReq); tEncoderClear(&coder); - pBlocks->size += len; pBlocks->createTbReqLen = len; - return TSDB_CODE_SUCCESS; + + return code; } -int32_t getDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, int32_t size, int32_t startOffset, int32_t rowSize, - STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, +int32_t getDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, int32_t size, int32_t startOffset, + int32_t rowSize, STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq) { *dataBlocks = NULL; STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pHashList, (const char*)id, idLen); @@ -272,12 +272,12 @@ static void destroyDataBlock(STableDataBlocks* pDataBlock) { } taosMemoryFreeClear(pDataBlock->pData); -// if (!pDataBlock->cloned) { - // free the refcount for metermeta - taosMemoryFreeClear(pDataBlock->pTableMeta); + // if (!pDataBlock->cloned) { + // free the refcount for metermeta + taosMemoryFreeClear(pDataBlock->pTableMeta); - destroyBoundColumnInfo(&pDataBlock->boundColumnInfo); -// } + destroyBoundColumnInfo(&pDataBlock->boundColumnInfo); + // } taosMemoryFreeClear(pDataBlock); } @@ -687,16 +687,16 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p STableDataBlocks** p = taosHashIterate(pHashObj, NULL); STableDataBlocks* pOneTableBlock = *p; SBlockKeyInfo blkKeyInfo = {0}; // share by pOneTableBlock - SBlockRowMerger *pBlkRowMerger = NULL; + SBlockRowMerger* pBlkRowMerger = NULL; while (pOneTableBlock) { SSubmitBlk* pBlocks = (SSubmitBlk*)pOneTableBlock->pData; if (pBlocks->numOfRows > 0) { STableDataBlocks* dataBuf = NULL; - pOneTableBlock->pTableMeta->vgId = pOneTableBlock->vgId; // for schemaless, restore origin vgId - int32_t ret = - getDataBlockFromList(pVnodeDataBlockHashList, &pOneTableBlock->vgId, sizeof(pOneTableBlock->vgId), TSDB_PAYLOAD_SIZE, INSERT_HEAD_SIZE, 0, - pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL); + pOneTableBlock->pTableMeta->vgId = pOneTableBlock->vgId; // for schemaless, restore origin vgId + int32_t ret = getDataBlockFromList(pVnodeDataBlockHashList, &pOneTableBlock->vgId, sizeof(pOneTableBlock->vgId), + TSDB_PAYLOAD_SIZE, INSERT_HEAD_SIZE, 0, pOneTableBlock->pTableMeta, &dataBuf, + pVnodeDataBlockList, NULL); if (ret != TSDB_CODE_SUCCESS) { tdFreeSBlockRowMerger(pBlkRowMerger); taosHashCleanup(pVnodeDataBlockHashList); @@ -708,7 +708,8 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p // the maximum expanded size in byte when a row-wise data is converted to SDataRow format int32_t expandSize = isRawPayload ? getRowExpandSize(pOneTableBlock->pTableMeta) : 0; int64_t destSize = dataBuf->size + pOneTableBlock->size + pBlocks->numOfRows * expandSize + - sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta) + pOneTableBlock->createTbReqLen; + sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta) + + pOneTableBlock->createTbReqLen; if (dataBuf->nAllocSize < destSize) { dataBuf->nAllocSize = (uint32_t)(destSize * 1.5); @@ -861,7 +862,7 @@ int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) { STableDataBlocks* pBlock = (STableDataBlocks*)(*pDst); if (pBlock->pTableMeta) { - void *pNewMeta = taosMemoryMalloc(TABLE_META_SIZE(pBlock->pTableMeta)); + void* pNewMeta = taosMemoryMalloc(TABLE_META_SIZE(pBlock->pTableMeta)); if (NULL == pNewMeta) { taosMemoryFreeClear(*pDst); return TSDB_CODE_OUT_OF_MEMORY; @@ -887,20 +888,18 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid, int32_t vgI } pBlock->vgId = vgId; - + if (pBlock->pTableMeta) { pBlock->pTableMeta->uid = uid; pBlock->pTableMeta->vgId = vgId; } - + memset(pBlock->pData, 0, sizeof(SSubmitBlk)); return TSDB_CODE_SUCCESS; } -STableMeta *qGetTableMetaInDataBlock(void* pDataBlock) { - return ((STableDataBlocks*)pDataBlock)->pTableMeta; -} +STableMeta* qGetTableMetaInDataBlock(void* pDataBlock) { return ((STableDataBlocks*)pDataBlock)->pTableMeta; } void qFreeStmtDataBlock(void* pDataBlock) { if (pDataBlock == NULL) { diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 345b9cc5b9e29449d009ab9c0911b1438e44b8b3..76c01cfd90a9a3b52c25d537ee65708295191c15 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -613,27 +613,6 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { return 0; } -SToken tscReplaceStrToken(char** str, SToken* token, const char* newToken) { - char* src = *str; - size_t nsize = strlen(newToken); - int32_t size = (int32_t)strlen(*str) - token->n + (int32_t)nsize + 1; - int32_t bsize = (int32_t)((uint64_t)token->z - (uint64_t)src); - SToken ntoken; - - *str = taosMemoryCalloc(1, size); - - strncpy(*str, src, bsize); - strcat(*str, newToken); - strcat(*str, token->z + token->n); - - ntoken.n = (uint32_t)nsize; - ntoken.z = *str + bsize; - - taosMemoryFreeClear(src); - - return ntoken; -} - SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) { SToken t0 = {0}; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index b398b645b393bbf34bce0515acc524b27fc3b66f..dbe0c97ab6fab0f37f675d6c0372aef20d27abad 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -292,9 +292,13 @@ static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { } else { do { SArray* pTables = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); + if (NULL == pTables) { + return TSDB_CODE_OUT_OF_MEMORY; + } if (pCxt->currLevel == currTotalLevel) { taosArrayPush(pTables, &pTable); if (hasSameTableAlias(pTables)) { + taosArrayDestroy(pTables); return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_UNIQUE_TABLE_ALIAS, "Not unique table/alias: '%s'", ((STableNode*)pTable)->tableAlias); } @@ -308,7 +312,7 @@ static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { static int32_t collectUseDatabaseImpl(const char* pFullDbName, SHashObj* pDbs) { SFullDatabaseName name = {0}; - strcpy(name.fullDbName, pFullDbName); + snprintf(name.fullDbName, sizeof(name.fullDbName), "%s", pFullDbName); return taosHashPut(pDbs, pFullDbName, strlen(pFullDbName), &name, sizeof(SFullDatabaseName)); } @@ -540,15 +544,17 @@ static int32_t getTableIndex(STranslateContext* pCxt, const SName* pName, SArray if (TSDB_CODE_SUCCESS == code) { code = collectUseTable(pName, pCxt->pTables); } - if (pParCxt->async) { - code = getTableIndexFromCache(pCxt->pMetaCache, pName, pIndexes); - } else { - SRequestConnInfo conn = {.pTrans = pParCxt->pTransporter, - .requestId = pParCxt->requestId, - .requestObjRefId = pParCxt->requestRid, - .mgmtEps = pParCxt->mgmtEpSet}; + if (TSDB_CODE_SUCCESS == code) { + if (pParCxt->async) { + code = getTableIndexFromCache(pCxt->pMetaCache, pName, pIndexes); + } else { + SRequestConnInfo conn = {.pTrans = pParCxt->pTransporter, + .requestId = pParCxt->requestId, + .requestObjRefId = pParCxt->requestRid, + .mgmtEps = pParCxt->mgmtEpSet}; - code = catalogGetTableIndex(pParCxt->pCatalog, &conn, pName, pIndexes); + code = catalogGetTableIndex(pParCxt->pCatalog, &conn, pName, pIndexes); + } } if (TSDB_CODE_SUCCESS != code) { parserError("0x%" PRIx64 " getTableIndex error, code:%s, dbName:%s, tbName:%s", pCxt->pParseCxt->requestId, @@ -990,9 +996,9 @@ static int32_t parseTimeFromValueNode(STranslateContext* pCxt, SValueNode* pVal) return pCxt->errCode; } if (IS_UNSIGNED_NUMERIC_TYPE(pVal->node.resType.type)) { - pVal->datum.i = pVal->datum.u; + pVal->datum.i = (int64_t)pVal->datum.u; } else if (IS_FLOAT_TYPE(pVal->node.resType.type)) { - pVal->datum.i = pVal->datum.d; + pVal->datum.i = (int64_t)pVal->datum.d; } else if (TSDB_DATA_TYPE_BOOL == pVal->node.resType.type) { pVal->datum.i = pVal->datum.b; } @@ -1069,7 +1075,7 @@ static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal, } case TSDB_DATA_TYPE_BIGINT: { code = toInteger(pVal->literal, strlen(pVal->literal), 10, &pVal->datum.i); - if (strict && (TSDB_CODE_SUCCESS != code || !IS_VALID_BIGINT(pVal->datum.i))) { + if (strict && TSDB_CODE_SUCCESS != code) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal); } *(int64_t*)&pVal->typeData = pVal->datum.i; @@ -1888,6 +1894,7 @@ static EDealRes translateCaseWhen(STranslateContext* pCxt, SCaseWhenNode* pCaseW pWhenThen->pWhen = pIsTrue; } if (first) { + first = false; pCaseWhen->node.resType = ((SExprNode*)pNode)->resType; } else if (!dataTypeEqual(&pCaseWhen->node.resType, &((SExprNode*)pNode)->resType)) { SNode* pCastFunc = NULL; @@ -3429,10 +3436,10 @@ static SNode* createSetOperProject(const char* pTableAlias, SNode* pNode) { return NULL; } pCol->node.resType = ((SExprNode*)pNode)->resType; - strcpy(pCol->tableAlias, pTableAlias); - strcpy(pCol->colName, ((SExprNode*)pNode)->aliasName); - strcpy(pCol->node.aliasName, pCol->colName); - strcpy(pCol->node.userAlias, ((SExprNode*)pNode)->userAlias); + snprintf(pCol->tableAlias, sizeof(pCol->tableAlias), "%s", pTableAlias); + snprintf(pCol->colName, sizeof(pCol->colName), "%s", ((SExprNode*)pNode)->aliasName); + snprintf(pCol->node.aliasName, sizeof(pCol->node.aliasName), "%s", pCol->colName); + snprintf(pCol->node.userAlias, sizeof(pCol->node.userAlias), "%s", ((SExprNode*)pNode)->userAlias); return (SNode*)pCol; } @@ -3739,8 +3746,8 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS static int32_t checkRangeOption(STranslateContext* pCxt, int32_t code, const char* pName, int32_t val, int32_t minVal, int32_t maxVal) { if (val >= 0 && (val < minVal || val > maxVal)) { - return generateSyntaxErrMsgExt(&pCxt->msgBuf, code, "Invalid option %s: %" PRId64 " valid range: [%d, %d]", pName, - val, minVal, maxVal); + return generateSyntaxErrMsgExt(&pCxt->msgBuf, code, "Invalid option %s: %d valid range: [%d, %d]", pName, val, + minVal, maxVal); } return TSDB_CODE_SUCCESS; } @@ -3877,7 +3884,7 @@ static int32_t checkDbStrictOption(STranslateContext* pCxt, SDatabaseOptions* pO static int32_t checkDbEnumOption(STranslateContext* pCxt, const char* pName, int32_t val, int32_t v1, int32_t v2) { if (val >= 0 && val != v1 && val != v2) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION, - "Invalid option %s: %" PRId64 ", only %d, %d allowed", pName, val, v1, v2); + "Invalid option %s: %d, only %d, %d allowed", pName, val, v1, v2); } return TSDB_CODE_SUCCESS; } @@ -4462,8 +4469,8 @@ static int32_t buildSampleAst(STranslateContext* pCxt, SSampleAstInfo* pInfo, ch nodesDestroyNode((SNode*)pSelect); return TSDB_CODE_OUT_OF_MEMORY; } - strcpy(pTable->table.dbName, pInfo->pDbName); - strcpy(pTable->table.tableName, pInfo->pTableName); + snprintf(pTable->table.dbName, sizeof(pTable->table.dbName), "%s", pInfo->pDbName); + snprintf(pTable->table.tableName, sizeof(pTable->table.tableName), "%s", pInfo->pTableName); TSWAP(pTable->pMeta, pInfo->pRollupTableMeta); pSelect->pFromTable = (SNode*)pTable; @@ -4939,9 +4946,9 @@ static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt alterReq.superUser = 0; alterReq.enable = pStmt->enable; alterReq.sysInfo = pStmt->sysinfo; - strcpy(alterReq.pass, pStmt->password); + snprintf(alterReq.pass, sizeof(alterReq.pass), "%s", pStmt->password); if (NULL != pCxt->pParseCxt->db) { - strcpy(alterReq.dbname, pCxt->pParseCxt->db); + snprintf(alterReq.dbname, sizeof(alterReq.dbname), "%s", pCxt->pParseCxt->db); } return buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &alterReq); @@ -6048,7 +6055,7 @@ static SNode* createProjectCol(const char* pProjCol) { if (NULL == pCol) { return NULL; } - strcpy(pCol->colName, pProjCol); + snprintf(pCol->colName, sizeof(pCol->colName), "%s", pProjCol); return (SNode*)pCol; } @@ -6081,9 +6088,9 @@ static int32_t createSimpleSelectStmt(const char* pDb, const char* pTable, int32 nodesDestroyNode((SNode*)pSelect); return TSDB_CODE_OUT_OF_MEMORY; } - strcpy(pRealTable->table.dbName, pDb); - strcpy(pRealTable->table.tableName, pTable); - strcpy(pRealTable->table.tableAlias, pTable); + snprintf(pRealTable->table.dbName, sizeof(pRealTable->table.dbName), "%s", pDb); + snprintf(pRealTable->table.tableName, sizeof(pRealTable->table.tableName), "%s", pTable); + snprintf(pRealTable->table.tableAlias, sizeof(pRealTable->table.tableAlias), "%s", pTable); pSelect->pFromTable = (SNode*)pRealTable; if (numOfProjs >= 0) { @@ -7124,8 +7131,9 @@ static int32_t buildUpdateOptionsReq(STranslateContext* pCxt, SAlterTableStmt* p pReq->newComment = strdup(pStmt->pOptions->comment); if (NULL == pReq->newComment) { code = TSDB_CODE_OUT_OF_MEMORY; + } else { + pReq->newCommentLen = strlen(pReq->newComment); } - pReq->newCommentLen = strlen(pReq->newComment); } else { pReq->newCommentLen = -1; } diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index dab1f015748187ca1d3870ad6ea821acbbbc01e8..ee82e6c04beb62e58151d23725c1a4bc217e827b 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -381,6 +381,7 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, voi uError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue, strerror(errno)); retCode = buildSyntaxErrMsg(pMsgBuf, "charset convert json error", jsonValue); + taosMemoryFree(tmp); goto end; } val.nData = valLen; @@ -652,8 +653,8 @@ static int32_t buildCatalogReqForInsert(SParseContext* pCxt, const SParseMetaCac } SUserAuthInfo auth = {0}; - strcpy(auth.user, pCxt->pUser); - strcpy(auth.dbFName, p->dbFName); + snprintf(auth.user, sizeof(auth.user), "%s", pCxt->pUser); + snprintf(auth.dbFName, sizeof(auth.dbFName), "%s", p->dbFName); auth.type = AUTH_TYPE_WRITE; taosArrayPush(pCatalogReq->pUser, &auth); diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index e6868f0cebfb5de7bf7321822c5928a6f67cdac7..9e1a01b13ddc1313bff458ed43c83b0d9e005d83 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -66,7 +66,8 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) { switch (nodeType(*pNode)) { case QUERY_NODE_OPERATOR: case QUERY_NODE_LOGIC_CONDITION: - case QUERY_NODE_FUNCTION: { + case QUERY_NODE_FUNCTION: + case QUERY_NODE_CASE_WHEN: { SRewriteExprCxt* pCxt = (SRewriteExprCxt*)pContext; SNode* pExpr; int32_t index = 0; @@ -118,6 +119,17 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) { return DEAL_RES_CONTINUE; } +static int32_t rewriteExprForSelect(SNode* pExpr, SSelectStmt* pSelect, ESqlClause clause) { + nodesWalkExpr(pExpr, doNameExpr, NULL); + SRewriteExprCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pExprs = NULL}; + cxt.errCode = nodesListMakeAppend(&cxt.pExprs, pExpr); + if (TSDB_CODE_SUCCESS == cxt.errCode) { + nodesRewriteSelectStmt(pSelect, clause, doRewriteExpr, &cxt); + nodesClearList(cxt.pExprs); + } + return cxt.errCode; +} + static int32_t rewriteExprsForSelect(SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) { nodesWalkExprs(pExprs, doNameExpr, NULL); SRewriteExprCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs}; @@ -459,9 +471,9 @@ static SColumnNode* createColumnByExpr(const char* pStmtName, SExprNode* pExpr) return NULL; } pCol->node.resType = pExpr->resType; - strcpy(pCol->colName, pExpr->aliasName); + snprintf(pCol->colName, sizeof(pCol->colName), "%s", pExpr->aliasName); if (NULL != pStmtName) { - strcpy(pCol->tableAlias, pStmtName); + snprintf(pCol->tableAlias, sizeof(pCol->tableAlias), "%s", pStmtName); } return pCol; } @@ -711,8 +723,13 @@ static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindo nodesDestroyNode((SNode*)pWindow); return TSDB_CODE_OUT_OF_MEMORY; } - - return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode); + // rewrite the expression in subsequent clauses + int32_t code = rewriteExprForSelect(pWindow->pStateExpr, pSelect, SQL_CLAUSE_WINDOW); + if (TSDB_CODE_SUCCESS == code) { + code = createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode); + } + + return code; } static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionWindowNode* pSession, diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 50f1f4b3691d4cdf474a9ecad3ac445e0e0a6af9..cd02e7a1365051b374e1aae201618a14e48b326e 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -1124,7 +1124,7 @@ static int32_t sortPriKeyOptGetSequencingNodes(SLogicNode* pNode, SNodeList** pS bool notOptimize = false; int32_t code = sortPriKeyOptGetSequencingNodesImpl(pNode, ¬Optimize, pSequencingNodes); if (TSDB_CODE_SUCCESS != code || notOptimize) { - nodesClearList(*pSequencingNodes); + NODES_CLEAR_LIST(*pSequencingNodes); } return code; } @@ -1361,74 +1361,6 @@ static int32_t smaIndexOptCouldApplyIndex(SScanLogicNode* pScan, STableIndexInfo return code; } -static SNode* smaIndexOptCreateWStartTs() { - SFunctionNode* pWStart = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); - if (NULL == pWStart) { - return NULL; - } - strcpy(pWStart->functionName, "_wstart"); - snprintf(pWStart->node.aliasName, sizeof(pWStart->node.aliasName), "%s.%p", pWStart->functionName, pWStart); - if (TSDB_CODE_SUCCESS != fmGetFuncInfo(pWStart, NULL, 0)) { - nodesDestroyNode((SNode*)pWStart); - return NULL; - } - return (SNode*)pWStart; -} - -static int32_t smaIndexOptCreateMergeKey(SNode* pCol, SNodeList** pMergeKeys) { - SOrderByExprNode* pMergeKey = (SOrderByExprNode*)nodesMakeNode(QUERY_NODE_ORDER_BY_EXPR); - if (NULL == pMergeKey) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pMergeKey->pExpr = nodesCloneNode(pCol); - if (NULL == pMergeKey->pExpr) { - nodesDestroyNode((SNode*)pMergeKey); - return TSDB_CODE_OUT_OF_MEMORY; - } - pMergeKey->order = ORDER_ASC; - pMergeKey->nullOrder = NULL_ORDER_FIRST; - return nodesListMakeStrictAppend(pMergeKeys, (SNode*)pMergeKey); -} - -static int32_t smaIndexOptRewriteInterval(SWindowLogicNode* pInterval, int32_t wstrartIndex, SNodeList** pMergeKeys) { - if (wstrartIndex < 0) { - SNode* pWStart = smaIndexOptCreateWStartTs(); - if (NULL == pWStart) { - return TSDB_CODE_OUT_OF_MEMORY; - } - int32_t code = createColumnByRewriteExpr(pWStart, &pInterval->node.pTargets); - if (TSDB_CODE_SUCCESS != code) { - nodesDestroyNode(pWStart); - return code; - } - wstrartIndex = LIST_LENGTH(pInterval->node.pTargets) - 1; - } - return smaIndexOptCreateMergeKey(nodesListGetNode(pInterval->node.pTargets, wstrartIndex), pMergeKeys); -} - -static int32_t smaIndexOptApplyIndexExt(SLogicSubplan* pLogicSubplan, SScanLogicNode* pScan, STableIndexInfo* pIndex, - SNodeList* pSmaCols, int32_t wstrartIndex) { - SWindowLogicNode* pInterval = (SWindowLogicNode*)pScan->node.pParent; - SNodeList* pMergeTargets = nodesCloneList(pInterval->node.pTargets); - if (NULL == pMergeTargets) { - return TSDB_CODE_OUT_OF_MEMORY; - } - SLogicNode* pSmaScan = NULL; - SLogicNode* pMerge = NULL; - SNodeList* pMergeKeys = NULL; - int32_t code = smaIndexOptRewriteInterval(pInterval, wstrartIndex, &pMergeKeys); - if (TSDB_CODE_SUCCESS == code) { - code = smaIndexOptCreateSmaScan(pScan, pIndex, pSmaCols, &pSmaScan); - } - if (TSDB_CODE_SUCCESS == code) { - code = smaIndexOptCreateMerge(pScan->node.pParent, pMergeKeys, pMergeTargets, &pMerge); - } - if (TSDB_CODE_SUCCESS == code) { - code = smaIndexOptRecombinationNode(pLogicSubplan, pScan->node.pParent, pMerge, pSmaScan); - } - return code; -} - static int32_t smaIndexOptApplyIndex(SLogicSubplan* pLogicSubplan, SScanLogicNode* pScan, STableIndexInfo* pIndex, SNodeList* pSmaCols, int32_t wstrartIndex) { SLogicNode* pSmaScan = NULL; @@ -1559,7 +1491,7 @@ static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) { return NULL; } - strcpy(pFunc->functionName, pFuncName); + snprintf(pFunc->functionName, sizeof(pFunc->functionName), "%s", pFuncName); if (QUERY_NODE_COLUMN == nodeType(pNode) && COLUMN_TYPE_TBNAME != ((SColumnNode*)pNode)->colType) { SColumnNode* pCol = (SColumnNode*)pNode; partTagsSetAlias(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), pCol->tableAlias, pCol->colName); @@ -2028,7 +1960,7 @@ static SNode* rewriteUniqueOptCreateFirstFunc(SFunctionNode* pSelectValue, SNode if (NULL != pSelectValue) { strcpy(pFunc->node.aliasName, pSelectValue->node.aliasName); } else { - snprintf(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), "%s.%p", pFunc->functionName, pFunc); + snprintf(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), "%s.%p", pFunc->functionName, (void*)pFunc); } int32_t code = nodesListMakeStrictAppend(&pFunc->pParameterList, nodesCloneNode(pCol)); if (TSDB_CODE_SUCCESS == code) { diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 2935c647aa571f7d29445c3f3cded18fae58eebb..8ff8538c0dbe934ba22beda84dce6c5fdc99749f 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -67,7 +67,7 @@ static SNode* createSlotDesc(SPhysiPlanContext* pCxt, const char* pName, const S if (NULL == pSlot) { return NULL; } - strcpy(pSlot->name, pName); + snprintf(pSlot->name, sizeof(pSlot->name), "%s", pName); pSlot->slotId = slotId; pSlot->dataType = ((SExprNode*)pNode)->resType; pSlot->reserve = reserve; @@ -663,13 +663,17 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc); } - SNodeList* condCols = nodesMakeList(); if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pOnConditions) { - code = nodesCollectColumnsFromNode(pJoinLogicNode->pOnConditions, NULL, COLLECT_COL_TYPE_ALL, &condCols); - } - if (TSDB_CODE_SUCCESS == code) { - code = addDataBlockSlots(pCxt, condCols, pJoin->node.pOutputDataBlockDesc); - nodesDestroyList(condCols); + SNodeList* pCondCols = nodesMakeList(); + if (NULL == pCondCols) { + code = TSDB_CODE_OUT_OF_MEMORY; + } else { + code = nodesCollectColumnsFromNode(pJoinLogicNode->pOnConditions, NULL, COLLECT_COL_TYPE_ALL, &pCondCols); + } + if (TSDB_CODE_SUCCESS == code) { + code = addDataBlockSlots(pCxt, pCondCols, pJoin->node.pOutputDataBlockDesc); + } + nodesDestroyList(pCondCols); } if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pOnConditions) { @@ -761,7 +765,8 @@ static EDealRes doRewritePrecalcExprs(SNode** pNode, void* pContext) { return collectAndRewrite(pCxt, pNode); } case QUERY_NODE_OPERATOR: - case QUERY_NODE_LOGIC_CONDITION: { + case QUERY_NODE_LOGIC_CONDITION: + case QUERY_NODE_CASE_WHEN: { return collectAndRewrite(pCxt, pNode); } case QUERY_NODE_FUNCTION: { @@ -1633,7 +1638,7 @@ static SSubplan* makeSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubpl pSubplan->subplanType = pLogicSubplan->subplanType; pSubplan->level = pLogicSubplan->level; if (NULL != pCxt->pPlanCxt->pUser) { - strcpy(pSubplan->user, pCxt->pPlanCxt->pUser); + snprintf(pSubplan->user, sizeof(pSubplan->user), "%s", pCxt->pPlanCxt->pUser); } return pSubplan; } @@ -1824,7 +1829,7 @@ static int32_t pushSubplan(SPhysiPlanContext* pCxt, SNode* pSubplan, int32_t lev return TSDB_CODE_OUT_OF_MEMORY; } } - return nodesListStrictAppend(pGroup->pNodeList, (SNode*)pSubplan); + return nodesListAppend(pGroup->pNodeList, (SNode*)pSubplan); } static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan* pParent, diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index 74ed3b57a4417aa43662bb722d3b78f3b13ee002..9567a2388f0695c9f2a89f433d921a4cbda35910 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -342,7 +342,7 @@ static int32_t stbSplAppendWStart(SNodeList* pFuncs, int32_t* pIndex) { return TSDB_CODE_OUT_OF_MEMORY; } strcpy(pWStart->functionName, "_wstart"); - snprintf(pWStart->node.aliasName, sizeof(pWStart->node.aliasName), "%s.%p", pWStart->functionName, pWStart); + snprintf(pWStart->node.aliasName, sizeof(pWStart->node.aliasName), "%s.%p", pWStart->functionName, (void*)pWStart); int32_t code = fmGetFuncInfo(pWStart, NULL, 0); if (TSDB_CODE_SUCCESS == code) { code = nodesListStrictAppend(pFuncs, (SNode*)pWStart); @@ -367,7 +367,7 @@ static int32_t stbSplAppendWEnd(SWindowLogicNode* pWin, int32_t* pIndex) { return TSDB_CODE_OUT_OF_MEMORY; } strcpy(pWEnd->functionName, "_wend"); - snprintf(pWEnd->node.aliasName, sizeof(pWEnd->node.aliasName), "%s.%p", pWEnd->functionName, pWEnd); + snprintf(pWEnd->node.aliasName, sizeof(pWEnd->node.aliasName), "%s.%p", pWEnd->functionName, (void*)pWEnd); int32_t code = fmGetFuncInfo(pWEnd, NULL, 0); if (TSDB_CODE_SUCCESS == code) { code = nodesListStrictAppend(pWin->pFuncs, (SNode*)pWEnd); @@ -389,22 +389,19 @@ static int32_t stbSplCreatePartWindowNode(SWindowLogicNode* pMergeWindow, SLogic SNode* pConditions = pMergeWindow->node.pConditions; pMergeWindow->node.pConditions = NULL; - int32_t code = TSDB_CODE_SUCCESS; SWindowLogicNode* pPartWin = (SWindowLogicNode*)nodesCloneNode((SNode*)pMergeWindow); if (NULL == pPartWin) { - code = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_OUT_OF_MEMORY; } pPartWin->node.groupAction = GROUP_ACTION_KEEP; + pMergeWindow->node.pTargets = pTargets; + pMergeWindow->node.pConditions = pConditions; + pPartWin->node.pChildren = pChildren; + splSetParent((SLogicNode*)pPartWin); - if (TSDB_CODE_SUCCESS == code) { - pMergeWindow->node.pTargets = pTargets; - pMergeWindow->node.pConditions = pConditions; - pPartWin->node.pChildren = pChildren; - splSetParent((SLogicNode*)pPartWin); - code = stbSplRewriteFuns(pFunc, &pPartWin->pFuncs, &pMergeWindow->pFuncs); - } int32_t index = 0; + int32_t code = stbSplRewriteFuns(pFunc, &pPartWin->pFuncs, &pMergeWindow->pFuncs); if (TSDB_CODE_SUCCESS == code) { code = stbSplAppendWStart(pPartWin->pFuncs, &index); } @@ -721,15 +718,16 @@ static int32_t stbSplCreatePartAggNode(SAggLogicNode* pMergeAgg, SLogicNode** pO SNode* pConditions = pMergeAgg->node.pConditions; pMergeAgg->node.pConditions = NULL; - int32_t code = TSDB_CODE_SUCCESS; SAggLogicNode* pPartAgg = (SAggLogicNode*)nodesCloneNode((SNode*)pMergeAgg); if (NULL == pPartAgg) { - code = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_OUT_OF_MEMORY; } pPartAgg->node.groupAction = GROUP_ACTION_KEEP; - if (TSDB_CODE_SUCCESS == code && NULL != pGroupKeys) { + int32_t code = TSDB_CODE_SUCCESS; + + if (NULL != pGroupKeys) { pPartAgg->pGroupKeys = pGroupKeys; code = createColumnByRewriteExprs(pPartAgg->pGroupKeys, &pPartAgg->node.pTargets); } diff --git a/source/libs/planner/src/planUtil.c b/source/libs/planner/src/planUtil.c index ac1589bec02a738ccb4e1f7d03b333628d012efe..a13e959a369ff03141e7c1a612529defdb1b5321 100644 --- a/source/libs/planner/src/planUtil.c +++ b/source/libs/planner/src/planUtil.c @@ -53,7 +53,8 @@ static EDealRes doCreateColumn(SNode* pNode, void* pContext) { } case QUERY_NODE_OPERATOR: case QUERY_NODE_LOGIC_CONDITION: - case QUERY_NODE_FUNCTION: { + case QUERY_NODE_FUNCTION: + case QUERY_NODE_CASE_WHEN: { SExprNode* pExpr = (SExprNode*)pNode; SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); if (NULL == pCol) { diff --git a/source/libs/qcom/inc/queryInt.h b/source/libs/qcom/inc/queryInt.h index f120bf26cebdac19896c372ea73159e682f72c0d..8f52f21d231e6fb191bc57e05b22002bdd8375a7 100644 --- a/source/libs/qcom/inc/queryInt.h +++ b/source/libs/qcom/inc/queryInt.h @@ -20,7 +20,6 @@ extern "C" { #endif - #ifdef __cplusplus } #endif diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index e54937114cd1bc0e011e8dc9d8ed44a710bc1807..80ba356e8f194f13c21af403bf9be378a0599134 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -13,18 +13,19 @@ * along with this program. If not, see . */ -#include "tmsg.h" -#include "queryInt.h" #include "query.h" -#include "trpc.h" +#include "queryInt.h" #include "systable.h" +#include "tmsg.h" +#include "trpc.h" #pragma GCC diagnostic push #ifdef COMPILER_SUPPORTS_CXX13 #pragma GCC diagnostic ignored "-Wformat-truncation" #endif -int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallocFp)(int32_t)) = {0}; +int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen, + void *(*mallocFp)(int64_t)) = {0}; int32_t (*queryProcessMsgRsp[TDMT_MAX])(void *output, char *msg, int32_t msgSize) = {0}; int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { @@ -46,7 +47,7 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { if (usedbRsp->vgNum <= 0) { return TSDB_CODE_SUCCESS; } - + pOut->dbVgroup->vgHash = taosHashInit(usedbRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); if (NULL == pOut->dbVgroup->vgHash) { @@ -57,7 +58,7 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { SVgroupInfo *pVgInfo = taosArrayGet(usedbRsp->pVgroupInfos, i); pOut->dbVgroup->numOfTable += pVgInfo->numOfTable; qDebug("the %dth vgroup, id %d, epNum %d, current %s port %d", i, pVgInfo->vgId, pVgInfo->epSet.numOfEps, - pVgInfo->epSet.eps[pVgInfo->epSet.inUse].fqdn, pVgInfo->epSet.eps[pVgInfo->epSet.inUse].port); + pVgInfo->epSet.eps[pVgInfo->epSet.inUse].fqdn, pVgInfo->epSet.eps[pVgInfo->epSet.inUse].port); if (0 != taosHashPut(pOut->dbVgroup->vgHash, &pVgInfo->vgId, sizeof(int32_t), pVgInfo, sizeof(SVgroupInfo))) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -66,7 +67,8 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { return TSDB_CODE_SUCCESS; } -int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { +int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, + void *(*mallcFp)(int64_t)) { SBuildTableInput *pInput = input; if (NULL == input || NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; @@ -89,7 +91,7 @@ int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int3 return TSDB_CODE_SUCCESS; } -int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { +int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { SBuildUseDBInput *pInput = input; if (NULL == pInput || NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; @@ -112,7 +114,7 @@ int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *ms return TSDB_CODE_SUCCESS; } -int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { +int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { if (NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; } @@ -130,7 +132,7 @@ int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t return TSDB_CODE_SUCCESS; } -int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { +int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { if (NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; } @@ -148,7 +150,7 @@ int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t return TSDB_CODE_SUCCESS; } -int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { +int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { if (NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; } @@ -165,8 +167,7 @@ int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t return TSDB_CODE_SUCCESS; } - -int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { +int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { if (NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; } @@ -184,7 +185,7 @@ int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t return TSDB_CODE_SUCCESS; } -int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { +int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { if (NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; } @@ -202,7 +203,8 @@ int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t return TSDB_CODE_SUCCESS; } -int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { +int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, + void *(*mallcFp)(int64_t)) { if (NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; } @@ -225,7 +227,7 @@ int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int3 return TSDB_CODE_SUCCESS; } -int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { +int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { if (NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; } @@ -243,7 +245,7 @@ int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32 return TSDB_CODE_SUCCESS; } -int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { +int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { if (NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; } @@ -261,13 +263,13 @@ int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_ return TSDB_CODE_SUCCESS; } -int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { +int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { if (NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; } SBuildTableInput *pInput = input; - STableCfgReq cfgReq = {0}; + STableCfgReq cfgReq = {0}; cfgReq.header.vgId = pInput->vgId; strcpy(cfgReq.dbFName, pInput->dbFName); strcpy(cfgReq.tbName, pInput->tbName); @@ -282,7 +284,6 @@ int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t return TSDB_CODE_SUCCESS; } - int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) { SUseDbOutput *pOut = output; SUseDbRsp usedbRsp = {0}; @@ -362,13 +363,12 @@ int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) { pMeta->uid = msg->tuid; pMeta->suid = msg->suid; - qDebug("ctable %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s suid %" PRIx64 , - msg->tbName, pMeta->uid, pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid); + qDebug("ctable %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s suid %" PRIx64, msg->tbName, pMeta->uid, + pMeta->tableType, pMeta->vgId, msg->dbFName, pMeta->suid); return TSDB_CODE_SUCCESS; } - int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) { int32_t total = msg->numOfColumns + msg->numOfTags; int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total; @@ -425,7 +425,8 @@ int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) { goto PROCESS_META_OVER; } - if (0 != strcmp(metaRsp.dbFName, TSDB_INFORMATION_SCHEMA_DB) && !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) { + if (0 != strcmp(metaRsp.dbFName, TSDB_INFORMATION_SCHEMA_DB) && + !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) { code = TSDB_CODE_TSC_INVALID_VALUE; goto PROCESS_META_OVER; } @@ -461,7 +462,6 @@ PROCESS_META_OVER: return code; } - int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) { SQnodeListRsp out = {0}; int32_t code = 0; @@ -496,7 +496,7 @@ int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) { return code; } - *(SArray**)output = out.dnodeList; + *(SArray **)output = out.dnodeList; return code; } @@ -516,12 +516,11 @@ int32_t queryProcessGetSerVerRsp(void *output, char *msg, int32_t msgSize) { return code; } - *(char**)output = strdup(out.ver); + *(char **)output = strdup(out.ver); return code; } - int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) { SDbCfgRsp out = {0}; @@ -573,7 +572,7 @@ int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) { return TSDB_CODE_INVALID_MSG; } - SFuncInfo * funcInfo = taosArrayGet(out.pFuncInfos, 0); + SFuncInfo *funcInfo = taosArrayGet(out.pFuncInfos, 0); memcpy(output, funcInfo, sizeof(*funcInfo)); taosArrayDestroy(out.pFuncInfos); @@ -599,12 +598,12 @@ int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) { return TSDB_CODE_TSC_INVALID_INPUT; } - STableIndexRsp *out = (STableIndexRsp*)output; + STableIndexRsp *out = (STableIndexRsp *)output; if (tDeserializeSTableIndexRsp(msg, msgSize, out) != 0) { qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize); return TSDB_CODE_INVALID_MSG; } - + return TSDB_CODE_SUCCESS; } @@ -619,39 +618,39 @@ int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) { return TSDB_CODE_INVALID_MSG; } - *(STableCfgRsp**)output = out; - + *(STableCfgRsp **)output = out; + return TSDB_CODE_SUCCESS; } void initQueryModuleMsgHandle() { - queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryBuildDnodeListMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryBuildGetIndexMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryBuildRetrieveFuncMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryBuildGetUserAuthMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryBuildGetTbIndexMsg; - queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryBuildGetTbCfgMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryBuildGetTbCfgMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryBuildGetSerVerMsg; - - queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryProcessDnodeListRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryProcessGetIndexRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryProcessRetrieveFuncRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryProcessGetUserAuthRsp; + queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryBuildDnodeListMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryBuildGetIndexMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryBuildRetrieveFuncMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryBuildGetUserAuthMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryBuildGetTbIndexMsg; + queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryBuildGetTbCfgMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryBuildGetTbCfgMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryBuildGetSerVerMsg; + + queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryProcessDnodeListRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryProcessGetIndexRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryProcessRetrieveFuncRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_USER_AUTH)] = queryProcessGetUserAuthRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryProcessGetTbIndexRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp; } #pragma GCC diagnostic pop diff --git a/source/libs/qcom/test/queryTest.cpp b/source/libs/qcom/test/queryTest.cpp index 9615557c883f6adf4a22f6a1d14417e4c5fe9839..7134f5c7b81e9c266c9279641105f8f75860567a 100644 --- a/source/libs/qcom/test/queryTest.cpp +++ b/source/libs/qcom/test/queryTest.cpp @@ -15,8 +15,9 @@ #include #include -#include "tmsg.h" + #include "query.h" +#include "tmsg.h" #include "trpc.h" #pragma GCC diagnostic push @@ -37,7 +38,7 @@ int32_t testPrint(void* p) { } int32_t testPrintError(void* p) { - SParam* param = (SParam*) p; + SParam* param = (SParam*)p; taosMemoryFreeClear(p); return -1; @@ -67,8 +68,8 @@ TEST(testCase, async_task_test) { } TEST(testCase, many_async_task_test) { - for(int32_t i = 0; i < 50; ++i) { - SParam* p = (SParam*) taosMemoryCalloc(1, sizeof(SParam)); + for (int32_t i = 0; i < 50; ++i) { + SParam* p = (SParam*)taosMemoryCalloc(1, sizeof(SParam)); p->v = i; taosAsyncExec(testPrint, p, NULL); } @@ -78,7 +79,7 @@ TEST(testCase, many_async_task_test) { TEST(testCase, error_in_async_test) { int32_t code = 0; - SParam* p = (SParam*) taosMemoryCalloc(1, sizeof(SParam)); + SParam* p = (SParam*)taosMemoryCalloc(1, sizeof(SParam)); taosAsyncExec(testPrintError, p, &code); taosMsleep(1); printf("Error code:%d after asynchronously exec function\n", code); diff --git a/source/libs/qworker/inc/qwInt.h b/source/libs/qworker/inc/qwInt.h index 3a3226359998d23da690aa361c5dffd1ce7d12fc..36c6817595d156392a0865958f21ac5b3db1b2f3 100644 --- a/source/libs/qworker/inc/qwInt.h +++ b/source/libs/qworker/inc/qwInt.h @@ -20,22 +20,22 @@ extern "C" { #endif +#include "executor.h" #include "osDef.h" +#include "plannodes.h" #include "qworker.h" #include "tlockfree.h" -#include "ttimer.h" #include "tref.h" -#include "plannodes.h" -#include "executor.h" #include "trpc.h" +#include "ttimer.h" #define QW_DEFAULT_SCHEDULER_NUMBER 100 #define QW_DEFAULT_TASK_NUMBER 10000 #define QW_DEFAULT_SCH_TASK_NUMBER 10000 #define QW_DEFAULT_SHORT_RUN_TIMES 2 #define QW_DEFAULT_HEARTBEAT_MSEC 5000 -#define QW_SCH_TIMEOUT_MSEC 180000 -#define QW_MIN_RES_ROWS 4096 +#define QW_SCH_TIMEOUT_MSEC 180000 +#define QW_MIN_RES_ROWS 4096 enum { QW_PHASE_PRE_QUERY = 1, @@ -123,21 +123,22 @@ typedef struct SQWTaskCtx { int32_t execId; int32_t level; + bool queryGotData; bool queryRsped; bool queryEnd; bool queryContinue; bool queryInQueue; int32_t rspCode; - int64_t affectedRows; // for insert ...select stmt + int64_t affectedRows; // for insert ...select stmt SRpcHandleInfo ctrlConnInfo; SRpcHandleInfo dataConnInfo; int8_t events[QW_EVENT_MAX]; - SArray *explainRes; - void *taskHandle; - void *sinkHandle; + SArray *explainRes; + void *taskHandle; + void *sinkHandle; STbVerInfo tbInfo; } SQWTaskCtx; @@ -157,14 +158,14 @@ typedef struct SQWTimeInQ { typedef struct SQWMsgStat { SQWTimeInQ waitTime[2]; - uint64_t queryProcessed; - uint64_t cqueryProcessed; - uint64_t fetchProcessed; - uint64_t rspProcessed; - uint64_t cancelProcessed; - uint64_t dropProcessed; - uint64_t hbProcessed; - uint64_t deleteProcessed; + uint64_t queryProcessed; + uint64_t cqueryProcessed; + uint64_t fetchProcessed; + uint64_t rspProcessed; + uint64_t cancelProcessed; + uint64_t dropProcessed; + uint64_t hbProcessed; + uint64_t deleteProcessed; } SQWMsgStat; typedef struct SQWRTStat { @@ -173,8 +174,8 @@ typedef struct SQWRTStat { } SQWRTStat; typedef struct SQWStat { - SQWMsgStat msgStat; - SQWRTStat rtStat; + SQWMsgStat msgStat; + SQWRTStat rtStat; } SQWStat; // Qnode/Vnode level task management @@ -183,15 +184,15 @@ typedef struct SQWorker { SQWorkerCfg cfg; int8_t nodeType; int32_t nodeId; - void * timer; + void *timer; tmr_h hbTimer; SRWLatch schLock; // SRWLatch ctxLock; - SHashObj *schHash; // key: schedulerId, value: SQWSchStatus - SHashObj *ctxHash; // key: queryId+taskId, value: SQWTaskCtx - SMsgCb msgCb; - SQWStat stat; - int32_t *destroyed; + SHashObj *schHash; // key: schedulerId, value: SQWSchStatus + SHashObj *ctxHash; // key: queryId+taskId, value: SQWTaskCtx + SMsgCb msgCb; + SQWStat stat; + int32_t *destroyed; } SQWorker; typedef struct SQWorkerMgmt { @@ -208,16 +209,21 @@ typedef struct SQWorkerMgmt { #define QW_STAT_INC(_item, _n) atomic_add_fetch_64(&(_item), _n) #define QW_STAT_DEC(_item, _n) atomic_sub_fetch_64(&(_item), _n) -#define QW_STAT_GET(_item) atomic_load_64(&(_item)) +#define QW_STAT_GET(_item) atomic_load_64(&(_item)) -#define QW_GET_EVENT(ctx, event) atomic_load_8(&(ctx)->events[event]) -#define QW_EVENT_RECEIVED(ctx, event) (QW_GET_EVENT(ctx, event) == QW_EVENT_RECEIVED) -#define QW_EVENT_PROCESSED(ctx, event) (QW_GET_EVENT(ctx, event) == QW_EVENT_PROCESSED) +#define QW_GET_EVENT(ctx, event) atomic_load_8(&(ctx)->events[event]) +#define QW_EVENT_RECEIVED(ctx, event) (QW_GET_EVENT(ctx, event) == QW_EVENT_RECEIVED) +#define QW_EVENT_PROCESSED(ctx, event) (QW_GET_EVENT(ctx, event) == QW_EVENT_PROCESSED) #define QW_SET_EVENT_RECEIVED(ctx, event) atomic_store_8(&(ctx)->events[event], QW_EVENT_RECEIVED) #define QW_SET_EVENT_PROCESSED(ctx, event) atomic_store_8(&(ctx)->events[event], QW_EVENT_PROCESSED) #define QW_GET_PHASE(ctx) atomic_load_8(&(ctx)->phase) -#define QW_SET_PHASE(ctx, _value) do { if ((_value) != QW_PHASE_PRE_FETCH && (_value) != QW_PHASE_POST_FETCH) { atomic_store_8(&(ctx)->phase, _value); } } while (0) +#define QW_SET_PHASE(ctx, _value) \ + do { \ + if ((_value) != QW_PHASE_PRE_FETCH && (_value) != QW_PHASE_POST_FETCH) { \ + atomic_store_8(&(ctx)->phase, _value); \ + } \ + } while (0) #define QW_SET_RSP_CODE(ctx, code) atomic_store_32(&(ctx)->rspCode, code) #define QW_UPDATE_RSP_CODE(ctx, code) atomic_val_compare_exchange_32(&(ctx)->rspCode, 0, code) @@ -230,7 +236,7 @@ typedef struct SQWorkerMgmt { *(uint64_t *)((char *)(id) + sizeof(qId)) = (tId); \ *(int32_t *)((char *)(id) + sizeof(qId) + sizeof(tId)) = (eId); \ } while (0) - + #define QW_GET_QTID(id, qId, tId, eId) \ do { \ (qId) = *(uint64_t *)(id); \ @@ -268,10 +274,10 @@ typedef struct SQWorkerMgmt { #define QW_TLOG(_param, ...) qTrace("QW:%p " _param, mgmt, __VA_ARGS__) #define QW_DUMP(_param, ...) \ - do { \ - if (gQWDebug.dumpEnable) { \ + do { \ + if (gQWDebug.dumpEnable) { \ qDebug("QW:%p " _param, mgmt, __VA_ARGS__); \ - } \ + } \ } while (0) #define QW_SCH_ELOG(param, ...) qError("QW:%p SID:%" PRIx64 " " param, mgmt, sId, __VA_ARGS__) @@ -287,12 +293,15 @@ typedef struct SQWorkerMgmt { #define QW_TASK_WLOG_E(param) qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, tId, eId) #define QW_TASK_DLOG_E(param) qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, tId, eId) -#define QW_SCH_TASK_ELOG(param, ...) \ - qError("QW:%p SID:0x%" PRIx64 ",QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, qId, tId, eId, __VA_ARGS__) -#define QW_SCH_TASK_WLOG(param, ...) \ - qWarn("QW:%p SID:0x%" PRIx64 ",QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, qId, tId, eId, __VA_ARGS__) -#define QW_SCH_TASK_DLOG(param, ...) \ - qDebug("QW:%p SID:0x%" PRIx64 ",QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, qId, tId, eId, __VA_ARGS__) +#define QW_SCH_TASK_ELOG(param, ...) \ + qError("QW:%p SID:0x%" PRIx64 ",QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, qId, tId, eId, \ + __VA_ARGS__) +#define QW_SCH_TASK_WLOG(param, ...) \ + qWarn("QW:%p SID:0x%" PRIx64 ",QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, qId, tId, eId, \ + __VA_ARGS__) +#define QW_SCH_TASK_DLOG(param, ...) \ + qDebug("QW:%p SID:0x%" PRIx64 ",QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, qId, tId, eId, \ + __VA_ARGS__) #define QW_LOCK_DEBUG(...) \ do { \ @@ -337,41 +346,41 @@ typedef struct SQWorkerMgmt { } \ } while (0) - extern SQWorkerMgmt gQwMgmt; -static FORCE_INLINE SQWorker *qwAcquire(int64_t refId) { return (SQWorker *)taosAcquireRef(atomic_load_32(&gQwMgmt.qwRef), refId); } +static FORCE_INLINE SQWorker *qwAcquire(int64_t refId) { + return (SQWorker *)taosAcquireRef(atomic_load_32(&gQwMgmt.qwRef), refId); +} static FORCE_INLINE int32_t qwRelease(int64_t refId) { return taosReleaseRef(gQwMgmt.qwRef, refId); } -char *qwPhaseStr(int32_t phase); -char *qwBufStatusStr(int32_t bufStatus); +char *qwPhaseStr(int32_t phase); +char *qwBufStatusStr(int32_t bufStatus); int32_t qwAcquireAddScheduler(SQWorker *mgmt, uint64_t sId, int32_t rwType, SQWSchStatus **sch); -void qwReleaseScheduler(int32_t rwType, SQWorker *mgmt); +void qwReleaseScheduler(int32_t rwType, SQWorker *mgmt); int32_t qwAddTaskStatus(QW_FPARAMS_DEF, int32_t status); int32_t qwAcquireTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx **ctx); int32_t qwGetTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx **ctx); int32_t qwAddAcquireTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx **ctx); -void qwReleaseTaskCtx(SQWorker *mgmt, void *ctx); +void qwReleaseTaskCtx(SQWorker *mgmt, void *ctx); int32_t qwKillTaskHandle(SQWTaskCtx *ctx); int32_t qwUpdateTaskStatus(QW_FPARAMS_DEF, int8_t status); int32_t qwDropTask(QW_FPARAMS_DEF); -void qwSaveTbVersionInfo(qTaskInfo_t pTaskInfo, SQWTaskCtx *ctx); +void qwSaveTbVersionInfo(qTaskInfo_t pTaskInfo, SQWTaskCtx *ctx); int32_t qwOpenRef(void); -void qwSetHbParam(int64_t refId, SQWHbParam **pParam); +void qwSetHbParam(int64_t refId, SQWHbParam **pParam); int32_t qwUpdateTimeInQueue(SQWorker *mgmt, int64_t ts, EQueueType type); int64_t qwGetTimeInQueue(SQWorker *mgmt, EQueueType type); -void qwClearExpiredSch(SQWorker *mgmt, SArray* pExpiredSch); +void qwClearExpiredSch(SQWorker *mgmt, SArray *pExpiredSch); int32_t qwAcquireScheduler(SQWorker *mgmt, uint64_t sId, int32_t rwType, SQWSchStatus **sch); -void qwFreeTaskCtx(SQWTaskCtx *ctx); +void qwFreeTaskCtx(SQWTaskCtx *ctx); -void qwDbgDumpMgmtInfo(SQWorker *mgmt); +void qwDbgDumpMgmtInfo(SQWorker *mgmt); int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, bool *ignore); int32_t qwDbgBuildAndSendRedirectRsp(int32_t rspType, SRpcHandleInfo *pConn, int32_t code, SEpSet *pEpSet); int32_t qwAddTaskCtx(QW_FPARAMS_DEF); -void qwDbgSimulateRedirect(SQWMsg *qwMsg, SQWTaskCtx *ctx, bool *rsped); -void qwDbgSimulateSleep(void); -void qwDbgSimulateDead(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *rsped); - +void qwDbgSimulateRedirect(SQWMsg *qwMsg, SQWTaskCtx *ctx, bool *rsped); +void qwDbgSimulateSleep(void); +void qwDbgSimulateDead(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *rsped); #ifdef __cplusplus } diff --git a/source/libs/qworker/inc/qwMsg.h b/source/libs/qworker/inc/qwMsg.h index b46c5d6baf90cdbba9883b7a0cfe24f175c7c4b5..f226b223f723c8d95d6c619b5c2f35e9c94574d3 100644 --- a/source/libs/qworker/inc/qwMsg.h +++ b/source/libs/qworker/inc/qwMsg.h @@ -20,12 +20,12 @@ extern "C" { #endif -#include "qwInt.h" #include "dataSinkMgt.h" +#include "qwInt.h" int32_t qwAbortPrerocessQuery(QW_FPARAMS_DEF); int32_t qwPreprocessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg); -int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, char* sql); +int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, char *sql); int32_t qwProcessCQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessReady(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg); @@ -35,11 +35,12 @@ int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SDeleteRes *pRes); int32_t qwBuildAndSendDropRsp(SRpcHandleInfo *pConn, int32_t code); int32_t qwBuildAndSendCancelRsp(SRpcHandleInfo *pConn, int32_t code); -int32_t qwBuildAndSendFetchRsp(int32_t rspType, SRpcHandleInfo *pConn, SRetrieveTableRsp *pRsp, int32_t dataLength, int32_t code); +int32_t qwBuildAndSendFetchRsp(int32_t rspType, SRpcHandleInfo *pConn, SRetrieveTableRsp *pRsp, int32_t dataLength, + int32_t code); void qwBuildFetchRsp(void *msg, SOutputData *input, int32_t len, bool qComplete); int32_t qwBuildAndSendCQueryMsg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn); int32_t qwBuildAndSendQueryRsp(int32_t rspType, SRpcHandleInfo *pConn, int32_t code, SQWTaskCtx *ctx); -int32_t qwBuildAndSendExplainRsp(SRpcHandleInfo *pConn, SArray* pExecList); +int32_t qwBuildAndSendExplainRsp(SRpcHandleInfo *pConn, SArray *pExecList); int32_t qwBuildAndSendErrorRsp(int32_t rspType, SRpcHandleInfo *pConn, int32_t code); void qwFreeFetchRsp(void *msg); int32_t qwMallocFetchRsp(int8_t rpcMalloc, int32_t length, SRetrieveTableRsp **rsp); diff --git a/source/libs/qworker/src/qwDbg.c b/source/libs/qworker/src/qwDbg.c index 98d7825b2c8d6de15991defc176ae35b3141c3da..6997bdfd9c937d19698e65f461b0f23472d9e359 100644 --- a/source/libs/qworker/src/qwDbg.c +++ b/source/libs/qworker/src/qwDbg.c @@ -1,15 +1,19 @@ -#include "qworker.h" #include "dataSinkMgt.h" #include "executor.h" #include "planner.h" #include "query.h" #include "qwInt.h" #include "qwMsg.h" +#include "qworker.h" #include "tcommon.h" #include "tmsg.h" #include "tname.h" -SQWDebug gQWDebug = {.statusEnable = true, .dumpEnable = false, .redirectSimulate = false, .deadSimulate = false, .sleepSimulate = false}; +SQWDebug gQWDebug = {.statusEnable = true, + .dumpEnable = false, + .redirectSimulate = false, + .deadSimulate = false, + .sleepSimulate = false}; int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, bool *ignore) { if (!gQWDebug.statusEnable) { @@ -29,15 +33,13 @@ int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, switch (oriStatus) { case JOB_TASK_STATUS_NULL: - if (newStatus != JOB_TASK_STATUS_EXEC && newStatus != JOB_TASK_STATUS_FAIL && - newStatus != JOB_TASK_STATUS_INIT) { + if (newStatus != JOB_TASK_STATUS_EXEC && newStatus != JOB_TASK_STATUS_FAIL && newStatus != JOB_TASK_STATUS_INIT) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } break; case JOB_TASK_STATUS_INIT: - if (newStatus != JOB_TASK_STATUS_DROP && newStatus != JOB_TASK_STATUS_EXEC - && newStatus != JOB_TASK_STATUS_FAIL) { + if (newStatus != JOB_TASK_STATUS_DROP && newStatus != JOB_TASK_STATUS_EXEC && newStatus != JOB_TASK_STATUS_FAIL) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } @@ -50,8 +52,8 @@ int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, break; case JOB_TASK_STATUS_PART_SUCC: - if (newStatus != JOB_TASK_STATUS_EXEC && newStatus != JOB_TASK_STATUS_SUCC && - newStatus != JOB_TASK_STATUS_FAIL && newStatus != JOB_TASK_STATUS_DROP) { + if (newStatus != JOB_TASK_STATUS_EXEC && newStatus != JOB_TASK_STATUS_SUCC && newStatus != JOB_TASK_STATUS_FAIL && + newStatus != JOB_TASK_STATUS_DROP) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } @@ -89,7 +91,8 @@ _return: void qwDbgDumpSchInfo(SQWorker *mgmt, SQWSchStatus *sch, int32_t i) { QW_LOCK(QW_READ, &sch->tasksLock); - QW_DLOG("the %dth scheduler status, hbBrokenTs:%" PRId64 ",taskNum:%d", i, sch->hbBrokenTs, taosHashGetSize(sch->tasksHash)); + QW_DLOG("the %dth scheduler status, hbBrokenTs:%" PRId64 ",taskNum:%d", i, sch->hbBrokenTs, + taosHashGetSize(sch->tasksHash)); QW_UNLOCK(QW_READ, &sch->tasksLock); } @@ -120,11 +123,10 @@ void qwDbgDumpMgmtInfo(SQWorker *mgmt) { QW_DUMP("total remain ctx num %d", taosHashGetSize(mgmt->ctxHash)); } - int32_t qwDbgBuildAndSendRedirectRsp(int32_t rspType, SRpcHandleInfo *pConn, int32_t code, SEpSet *pEpSet) { int32_t contLen = 0; - char* rsp = NULL; - + char *rsp = NULL; + if (pEpSet) { contLen = tSerializeSEpSet(NULL, 0, pEpSet); rsp = rpcMallocCont(contLen); @@ -152,12 +154,12 @@ void qwDbgSimulateRedirect(SQWMsg *qwMsg, SQWTaskCtx *ctx, bool *rsped) { if (*rsped) { return; } - + if (gQWDebug.redirectSimulate) { if (++ignoreTime <= 10) { return; } - + if (TDMT_SCH_QUERY == qwMsg->msgType && (0 == taosRand() % 3)) { SEpSet epSet = {0}; epSet.inUse = 1; @@ -169,12 +171,12 @@ void qwDbgSimulateRedirect(SQWMsg *qwMsg, SQWTaskCtx *ctx, bool *rsped) { strcpy(epSet.eps[2].fqdn, "localhost"); epSet.eps[2].port = 7300; - ctx->phase = QW_PHASE_POST_QUERY; + ctx->phase = QW_PHASE_POST_QUERY; qwDbgBuildAndSendRedirectRsp(qwMsg->msgType + 1, &qwMsg->connInfo, TSDB_CODE_RPC_REDIRECT, &epSet); *rsped = true; return; } - + if (TDMT_SCH_MERGE_QUERY == qwMsg->msgType && (0 == taosRand() % 3)) { QW_SET_PHASE(ctx, QW_PHASE_POST_QUERY); qwDbgBuildAndSendRedirectRsp(qwMsg->msgType + 1, &qwMsg->connInfo, TSDB_CODE_RPC_REDIRECT, NULL); @@ -213,18 +215,18 @@ void qwDbgSimulateDead(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *rsped) { static int32_t ignoreTime = 0; if (++ignoreTime > 10 && 0 == taosRand() % 9) { - SRpcHandleInfo *pConn = ((ctx->msgType == TDMT_SCH_FETCH || ctx->msgType == TDMT_SCH_MERGE_FETCH) ? &ctx->dataConnInfo : &ctx->ctrlConnInfo); + SRpcHandleInfo *pConn = + ((ctx->msgType == TDMT_SCH_FETCH || ctx->msgType == TDMT_SCH_MERGE_FETCH) ? &ctx->dataConnInfo + : &ctx->ctrlConnInfo); qwBuildAndSendErrorRsp(ctx->msgType + 1, pConn, TSDB_CODE_RPC_BROKEN_LINK); qwBuildAndSendDropMsg(QW_FPARAMS(), pConn); *rsped = true; - + return; } } - - int32_t qwDbgEnableDebug(char *option) { if (0 == strcasecmp(option, "lock")) { gQWDebug.lockEnable = true; @@ -263,8 +265,6 @@ int32_t qwDbgEnableDebug(char *option) { } qError("invalid qw debug option:%s", option); - + return TSDB_CODE_APP_ERROR; } - - diff --git a/source/libs/qworker/src/qwMsg.c b/source/libs/qworker/src/qwMsg.c index e4271dfcdaf2579ce884646a52bee523e419c3c5..24ab45be2c156210989800cba01cea9300b36aae 100644 --- a/source/libs/qworker/src/qwMsg.c +++ b/source/libs/qworker/src/qwMsg.c @@ -3,8 +3,8 @@ #include "executor.h" #include "planner.h" #include "query.h" -#include "qworker.h" #include "qwInt.h" +#include "qworker.h" #include "tcommon.h" #include "tmsg.h" #include "tname.h" @@ -12,7 +12,8 @@ int32_t qwMallocFetchRsp(int8_t rpcMalloc, int32_t length, SRetrieveTableRsp **rsp) { int32_t msgSize = sizeof(SRetrieveTableRsp) + length; - SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)(rpcMalloc ? rpcReallocCont(*rsp, msgSize) : taosMemoryRealloc(*rsp, msgSize)); + SRetrieveTableRsp *pRsp = + (SRetrieveTableRsp *)(rpcMalloc ? rpcReallocCont(*rsp, msgSize) : taosMemoryRealloc(*rsp, msgSize)); if (NULL == pRsp) { qError("rpcMallocCont %d failed", msgSize); QW_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -21,7 +22,7 @@ int32_t qwMallocFetchRsp(int8_t rpcMalloc, int32_t length, SRetrieveTableRsp **r if (NULL == *rsp) { memset(pRsp, 0, sizeof(SRetrieveTableRsp)); } - + *rsp = pRsp; return TSDB_CODE_SUCCESS; @@ -61,8 +62,8 @@ int32_t qwBuildAndSendErrorRsp(int32_t rspType, SRpcHandleInfo *pConn, int32_t c } int32_t qwBuildAndSendQueryRsp(int32_t rspType, SRpcHandleInfo *pConn, int32_t code, SQWTaskCtx *ctx) { - STbVerInfo* tbInfo = ctx ? &ctx->tbInfo : NULL; - int64_t affectedRows = ctx ? ctx->affectedRows : 0; + STbVerInfo *tbInfo = ctx ? &ctx->tbInfo : NULL; + int64_t affectedRows = ctx ? ctx->affectedRows : 0; SQueryTableRsp *pRsp = (SQueryTableRsp *)rpcMallocCont(sizeof(SQueryTableRsp)); pRsp->code = htonl(code); pRsp->affectedRows = htobe64(affectedRows); @@ -85,12 +86,12 @@ int32_t qwBuildAndSendQueryRsp(int32_t rspType, SRpcHandleInfo *pConn, int32_t c return TSDB_CODE_SUCCESS; } -int32_t qwBuildAndSendExplainRsp(SRpcHandleInfo *pConn, SArray* pExecList) { - SExplainExecInfo* pInfo = taosArrayGet(pExecList, 0); - SExplainRsp rsp = {.numOfPlans = taosArrayGetSize(pExecList), .subplanInfo = pInfo}; +int32_t qwBuildAndSendExplainRsp(SRpcHandleInfo *pConn, SArray *pExecList) { + SExplainExecInfo *pInfo = taosArrayGet(pExecList, 0); + SExplainRsp rsp = {.numOfPlans = taosArrayGetSize(pExecList), .subplanInfo = pInfo}; int32_t contLen = tSerializeSExplainRsp(NULL, 0, &rsp); - void * pRsp = rpcMallocCont(contLen); + void *pRsp = rpcMallocCont(contLen); tSerializeSExplainRsp(pRsp, contLen, &rsp); SRpcMsg rpcRsp = { @@ -108,7 +109,7 @@ int32_t qwBuildAndSendExplainRsp(SRpcHandleInfo *pConn, SArray* pExecList) { int32_t qwBuildAndSendHbRsp(SRpcHandleInfo *pConn, SSchedulerHbRsp *pStatus, int32_t code) { int32_t contLen = tSerializeSSchedulerHbRsp(NULL, 0, pStatus); - void * pRsp = rpcMallocCont(contLen); + void *pRsp = rpcMallocCont(contLen); tSerializeSSchedulerHbRsp(pRsp, contLen, pStatus); SRpcMsg rpcRsp = { @@ -124,7 +125,8 @@ int32_t qwBuildAndSendHbRsp(SRpcHandleInfo *pConn, SSchedulerHbRsp *pStatus, int return TSDB_CODE_SUCCESS; } -int32_t qwBuildAndSendFetchRsp(int32_t rspType, SRpcHandleInfo *pConn, SRetrieveTableRsp *pRsp, int32_t dataLength, int32_t code) { +int32_t qwBuildAndSendFetchRsp(int32_t rspType, SRpcHandleInfo *pConn, SRetrieveTableRsp *pRsp, int32_t dataLength, + int32_t code) { if (NULL == pRsp) { pRsp = (SRetrieveTableRsp *)rpcMallocCont(sizeof(SRetrieveTableRsp)); memset(pRsp, 0, sizeof(SRetrieveTableRsp)); @@ -209,7 +211,6 @@ int32_t qwBuildAndSendDropMsg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) { return TSDB_CODE_SUCCESS; } - int32_t qwBuildAndSendCQueryMsg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) { SQueryContinueReq *req = (SQueryContinueReq *)rpcMallocCont(sizeof(SQueryContinueReq)); if (NULL == req) { @@ -309,7 +310,7 @@ int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg) { int32_t code = 0; SSubQueryMsg *msg = pMsg->pCont; - SQWorker * mgmt = (SQWorker *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { QW_ELOG("invalid query msg, msg:%p, msgLen:%d", msg, pMsg->contLen); @@ -330,7 +331,8 @@ int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg) { int64_t rId = msg->refId; int32_t eId = msg->execId; - SQWMsg qwMsg = {.msgType = pMsg->msgType, .msg = msg->msg + msg->sqlLen, .msgLen = msg->phyLen, .connInfo = pMsg->info}; + SQWMsg qwMsg = { + .msgType = pMsg->msgType, .msg = msg->msg + msg->sqlLen, .msgLen = msg->phyLen, .connInfo = pMsg->info}; QW_SCH_TASK_DLOG("prerocessQuery start, handle:%p", pMsg->info.handle); QW_ERR_RET(qwPreprocessQuery(QW_FPARAMS(), &qwMsg)); @@ -345,7 +347,7 @@ int32_t qWorkerAbortPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg) { } SSubQueryMsg *msg = pMsg->pCont; - SQWorker * mgmt = (SQWorker *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; uint64_t sId = msg->sId; uint64_t qId = msg->queryId; @@ -367,7 +369,7 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int int32_t code = 0; SSubQueryMsg *msg = pMsg->pCont; - SQWorker * mgmt = (SQWorker *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; qwUpdateTimeInQueue(mgmt, ts, QUERY_QUEUE); QW_STAT_INC(mgmt->stat.msgStat.queryProcessed, 1); @@ -383,13 +385,18 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int int64_t rId = msg->refId; int32_t eId = msg->execId; - SQWMsg qwMsg = {.node = node, .msg = msg->msg + msg->sqlLen, .msgLen = msg->phyLen, .connInfo = pMsg->info, .msgType = pMsg->msgType}; + SQWMsg qwMsg = {.node = node, + .msg = msg->msg + msg->sqlLen, + .msgLen = msg->phyLen, + .connInfo = pMsg->info, + .msgType = pMsg->msgType}; qwMsg.msgInfo.explain = msg->explain; qwMsg.msgInfo.taskType = msg->taskType; qwMsg.msgInfo.needFetch = msg->needFetch; - - char * sql = strndup(msg->msg, msg->sqlLen); - QW_SCH_TASK_DLOG("processQuery start, node:%p, type:%s, handle:%p, SQL:%s", node, TMSG_INFO(pMsg->msgType), pMsg->info.handle, sql); + + char *sql = strndup(msg->msg, msg->sqlLen); + QW_SCH_TASK_DLOG("processQuery start, node:%p, type:%s, handle:%p, SQL:%s", node, TMSG_INFO(pMsg->msgType), + pMsg->info.handle, sql); QW_ERR_JRET(qwProcessQuery(QW_FPARAMS(), &qwMsg, sql)); _return: @@ -405,8 +412,8 @@ int32_t qWorkerProcessCQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, in bool queryDone = false; SQueryContinueReq *msg = (SQueryContinueReq *)pMsg->pCont; bool needStop = false; - SQWTaskCtx * handles = NULL; - SQWorker * mgmt = (SQWorker *)qWorkerMgmt; + SQWTaskCtx *handles = NULL; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; qwUpdateTimeInQueue(mgmt, ts, QUERY_QUEUE); QW_STAT_INC(mgmt->stat.msgStat.cqueryProcessed, 1); @@ -439,7 +446,7 @@ int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int } SResFetchReq *msg = pMsg->pCont; - SQWorker * mgmt = (SQWorker *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE); QW_STAT_INC(mgmt->stat.msgStat.fetchProcessed, 1); @@ -472,7 +479,7 @@ int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int } int32_t qWorkerProcessRspMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_t ts) { - SQWorker * mgmt = (SQWorker *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; if (mgmt) { qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE); QW_STAT_INC(mgmt->stat.msgStat.rspProcessed, 1); @@ -488,7 +495,7 @@ int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, in return TSDB_CODE_QRY_INVALID_INPUT; } - SQWorker * mgmt = (SQWorker *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; int32_t code = 0; STaskCancelReq *msg = pMsg->pCont; @@ -531,7 +538,7 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int6 int32_t code = 0; STaskDropReq *msg = pMsg->pCont; - SQWorker * mgmt = (SQWorker *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE); QW_STAT_INC(mgmt->stat.msgStat.dropProcessed, 1); @@ -575,7 +582,7 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_ int32_t code = 0; SSchedulerHbReq req = {0}; - SQWorker * mgmt = (SQWorker *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; qwUpdateTimeInQueue(mgmt, ts, FETCH_QUEUE); QW_STAT_INC(mgmt->stat.msgStat.hbProcessed, 1); @@ -606,20 +613,19 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_ return TSDB_CODE_SUCCESS; } - int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SDeleteRes *pRes) { if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - int32_t code = 0; + int32_t code = 0; SVDeleteReq req = {0}; - SQWorker * mgmt = (SQWorker *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; QW_STAT_INC(mgmt->stat.msgStat.deleteProcessed, 1); tDeserializeSVDeleteReq(pMsg->pCont, pMsg->contLen, &req); - + uint64_t sId = req.sId; uint64_t qId = req.queryId; uint64_t tId = req.taskId; @@ -639,5 +645,3 @@ _return: QW_RET(code); } - - diff --git a/source/libs/qworker/src/qwUtil.c b/source/libs/qworker/src/qwUtil.c index 9f1a9a3146b0aeba875d051d731f750779b94e42..3038b8793074f5ab6b03070777eb7fea68bb2bcb 100644 --- a/source/libs/qworker/src/qwUtil.c +++ b/source/libs/qworker/src/qwUtil.c @@ -295,7 +295,7 @@ void qwFreeTaskCtx(SQWTaskCtx *ctx) { if (ctx->ctrlConnInfo.handle) { tmsgReleaseHandle(&ctx->ctrlConnInfo, TAOS_CONN_SERVER); } - + ctx->ctrlConnInfo.handle = NULL; ctx->ctrlConnInfo.refId = -1; @@ -454,21 +454,21 @@ void qwDestroySchStatus(SQWSchStatus *pStatus) { taosHashCleanup(pStatus->tasksH void qwDestroyImpl(void *pMgmt) { SQWorker *mgmt = (SQWorker *)pMgmt; - int8_t nodeType = mgmt->nodeType; - int32_t nodeId = mgmt->nodeId; - - qDebug("start to destroy qworker, type:%d, id:%d, handle:%p", nodeType, nodeId, mgmt); + int8_t nodeType = mgmt->nodeType; + int32_t nodeId = mgmt->nodeId; + + qDebug("start to destroy qworker, type:%d, id:%d, handle:%p", nodeType, nodeId, mgmt); taosTmrStop(mgmt->hbTimer); mgmt->hbTimer = NULL; taosTmrCleanUp(mgmt->timer); uint64_t qId, tId; - int32_t eId; - void *pIter = taosHashIterate(mgmt->ctxHash, NULL); + int32_t eId; + void *pIter = taosHashIterate(mgmt->ctxHash, NULL); while (pIter) { SQWTaskCtx *ctx = (SQWTaskCtx *)pIter; - void *key = taosHashGetKey(pIter, NULL); + void *key = taosHashGetKey(pIter, NULL); QW_GET_QTID(key, qId, tId, eId); qwFreeTaskCtx(ctx); @@ -486,14 +486,14 @@ void qwDestroyImpl(void *pMgmt) { taosHashCleanup(mgmt->schHash); *mgmt->destroyed = 1; - + taosMemoryFree(mgmt); atomic_sub_fetch_32(&gQwMgmt.qwNum, 1); qwCloseRef(); - qDebug("qworker destroyed, type:%d, id:%d, handle:%p", nodeType, nodeId, mgmt); + qDebug("qworker destroyed, type:%d, id:%d, handle:%p", nodeType, nodeId, mgmt); } int32_t qwOpenRef(void) { @@ -550,11 +550,10 @@ int64_t qwGetTimeInQueue(SQWorker *mgmt, EQueueType type) { return -1; } - -void qwClearExpiredSch(SQWorker *mgmt, SArray* pExpiredSch) { +void qwClearExpiredSch(SQWorker *mgmt, SArray *pExpiredSch) { int32_t num = taosArrayGetSize(pExpiredSch); for (int32_t i = 0; i < num; ++i) { - uint64_t *sId = taosArrayGet(pExpiredSch, i); + uint64_t *sId = taosArrayGet(pExpiredSch, i); SQWSchStatus *pSch = NULL; if (qwAcquireScheduler(mgmt, *sId, QW_WRITE, &pSch)) { continue; @@ -569,5 +568,3 @@ void qwClearExpiredSch(SQWorker *mgmt, SArray* pExpiredSch) { qwReleaseScheduler(QW_WRITE, mgmt); } } - - diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index ae9dd82a58eca25aab73a17bc43ef2441e3c08c0..d2c16a1cb5186ed4dd2e399f78f926c0238656d1 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -7,9 +7,10 @@ #include "qwInt.h" #include "qwMsg.h" #include "tcommon.h" +#include "tdatablock.h" #include "tmsg.h" #include "tname.h" -#include "tdatablock.h" +#include "tglobal.h" SQWorkerMgmt gQwMgmt = { .lock = 0, @@ -17,8 +18,8 @@ SQWorkerMgmt gQwMgmt = { .qwNum = 0, }; -static void freeBlock(void* param) { - SSDataBlock* pBlock = *(SSDataBlock**)param; +static void freeBlock(void *param) { + SSDataBlock *pBlock = *(SSDataBlock **)param; blockDataDestroy(pBlock); } @@ -92,6 +93,19 @@ int32_t qwHandleTaskComplete(QW_FPARAMS_DEF, SQWTaskCtx *ctx) { return TSDB_CODE_SUCCESS; } +int32_t qwSendQueryRsp(QW_FPARAMS_DEF, int32_t msgType, SQWTaskCtx *ctx, int32_t rspCode, bool quickRsp) { + if ((!quickRsp) || QUERY_RSP_POLICY_QUICK == tsQueryRspPolicy) { + if (!ctx->localExec) { + qwBuildAndSendQueryRsp(msgType, &ctx->ctrlConnInfo, rspCode, ctx); + QW_TASK_DLOG("query msg rsped, handle:%p, code:%x - %s", ctx->ctrlConnInfo.handle, rspCode, tstrerror(rspCode)); + } + + ctx->queryRsped = true; + } + + return TSDB_CODE_SUCCESS; +} + int32_t qwExecTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *queryStop) { int32_t code = 0; bool qcontinue = true; @@ -100,7 +114,7 @@ int32_t qwExecTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *queryStop) { int32_t execNum = 0; qTaskInfo_t taskHandle = ctx->taskHandle; DataSinkHandle sinkHandle = ctx->sinkHandle; - SLocalFetch localFetch = {(void*)mgmt, ctx->localExec, qWorkerProcessLocalFetch, ctx->explainRes}; + SLocalFetch localFetch = {(void *)mgmt, ctx->localExec, qWorkerProcessLocalFetch, ctx->explainRes}; SArray *pResList = taosArrayInit(4, POINTER_BYTES); while (true) { @@ -144,7 +158,7 @@ int32_t qwExecTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *queryStop) { if (numOfResBlock == 0) { QW_TASK_DLOG("qExecTask end with empty res, useconds:%" PRIu64, useconds); } else { - QW_TASK_DLOG("qExecTask done", ""); + QW_TASK_DLOG("qExecTask done, useconds:%" PRIu64, useconds); } dsEndPut(sinkHandle, useconds); @@ -234,6 +248,10 @@ int32_t qwGetQueryResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, int32_t code = 0; SOutputData output = {0}; + if (NULL == ctx->sinkHandle) { + return TSDB_CODE_SUCCESS; + } + *dataLen = 0; while (true) { @@ -407,6 +425,11 @@ int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inpu QW_ERR_JRET(TSDB_CODE_QRY_DUPLICATTED_OPERATION); } + if (ctx->rspCode) { + QW_TASK_ELOG("task already failed cause of %s, phase:%s", tstrerror(ctx->rspCode), qwPhaseStr(phase)); + QW_ERR_JRET(ctx->rspCode); + } + if (!ctx->queryRsped) { QW_TASK_ELOG("ready msg has not been processed, phase:%s", qwPhaseStr(phase)); QW_ERR_JRET(TSDB_CODE_QRY_TASK_MSG_ERROR); @@ -419,6 +442,11 @@ int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inpu QW_ERR_JRET(TSDB_CODE_QRY_TASK_DROPPED); } + if (ctx->rspCode) { + QW_TASK_ELOG("task already failed cause of %s, phase:%s", tstrerror(ctx->rspCode), qwPhaseStr(phase)); + QW_ERR_JRET(ctx->rspCode); + } + if (QW_EVENT_RECEIVED(ctx, QW_EVENT_DROP)) { QW_ERR_JRET(qwDropTask(QW_FPARAMS())); @@ -499,21 +527,17 @@ _return: if (TSDB_CODE_SUCCESS == code && QW_PHASE_POST_QUERY == phase) { qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_PART_SUCC); + ctx->queryGotData = true; } - if (QW_PHASE_POST_QUERY == phase && ctx) { - if (!ctx->localExec) { - bool rsped = false; - SQWMsg qwMsg = {.msgType = ctx->msgType, .connInfo = ctx->ctrlConnInfo}; - qwDbgSimulateRedirect(&qwMsg, ctx, &rsped); - qwDbgSimulateDead(QW_FPARAMS(), ctx, &rsped); - if (!rsped) { - qwBuildAndSendQueryRsp(input->msgType + 1, &ctx->ctrlConnInfo, code, ctx); - QW_TASK_DLOG("query msg rsped, handle:%p, code:%x - %s", ctx->ctrlConnInfo.handle, code, tstrerror(code)); - } + if (QW_PHASE_POST_QUERY == phase && ctx && !ctx->queryRsped) { + bool rsped = false; + SQWMsg qwMsg = {.msgType = ctx->msgType, .connInfo = ctx->ctrlConnInfo}; + qwDbgSimulateRedirect(&qwMsg, ctx, &rsped); + qwDbgSimulateDead(QW_FPARAMS(), ctx, &rsped); + if (!rsped) { + qwSendQueryRsp(QW_FPARAMS(), input->msgType + 1, ctx, code, false); } - - ctx->queryRsped = true; } if (ctx) { @@ -541,8 +565,8 @@ int32_t qwAbortPrerocessQuery(QW_FPARAMS_DEF) { } int32_t qwPreprocessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) { - int32_t code = 0; - SQWTaskCtx *ctx = NULL; + int32_t code = 0; + SQWTaskCtx *ctx = NULL; QW_ERR_JRET(qwRegisterQueryBrokenLinkArg(QW_FPARAMS(), &qwMsg->connInfo)); @@ -551,6 +575,7 @@ int32_t qwPreprocessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) { QW_ERR_JRET(qwAcquireTaskCtx(QW_FPARAMS(), &ctx)); ctx->ctrlConnInfo = qwMsg->connInfo; + ctx->phase = -1; QW_ERR_JRET(qwAddTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_INIT)); @@ -604,6 +629,8 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, char *sql) { QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } + qwSendQueryRsp(QW_FPARAMS(), qwMsg->msgType + 1, ctx, code, true); + ctx->level = plan->level; atomic_store_ptr(&ctx->taskHandle, pTaskInfo); atomic_store_ptr(&ctx->sinkHandle, sinkHandle); @@ -619,6 +646,31 @@ _return: input.msgType = qwMsg->msgType; code = qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_QUERY, &input, NULL); + if (ctx != NULL && QW_EVENT_RECEIVED(ctx, QW_EVENT_FETCH)) { + void *rsp = NULL; + int32_t dataLen = 0; + SOutputData sOutput = {0}; + QW_ERR_JRET(qwGetQueryResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput)); + + if (rsp) { + bool qComplete = (DS_BUF_EMPTY == sOutput.bufStatus && sOutput.queryEnd); + + qwBuildFetchRsp(rsp, &sOutput, dataLen, qComplete); + if (qComplete) { + atomic_store_8((int8_t *)&ctx->queryEnd, true); + } + + qwMsg->connInfo = ctx->dataConnInfo; + QW_SET_EVENT_PROCESSED(ctx, QW_EVENT_FETCH); + + qwBuildAndSendFetchRsp(ctx->fetchType, &qwMsg->connInfo, rsp, dataLen, code); + rsp = NULL; + + QW_TASK_DLOG("fetch rsp send, handle:%p, code:%x - %s, dataLen:%d", qwMsg->connInfo.handle, code, + tstrerror(code), dataLen); + } + } + QW_RET(TSDB_CODE_SUCCESS); } @@ -740,7 +792,9 @@ int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg) { locked = true; // RC WARNING - if (QW_QUERY_RUNNING(ctx)) { + if (-1 == ctx->phase || false == ctx->queryGotData) { + QW_TASK_DLOG_E("task query unfinished"); + } else if (QW_QUERY_RUNNING(ctx)) { atomic_store_8((int8_t *)&ctx->queryContinue, 1); } else if (0 == atomic_load_8((int8_t *)&ctx->queryInQueue)) { qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_EXEC); @@ -1113,10 +1167,10 @@ void qWorkerDestroy(void **qWorkerMgmt) { return; } - int32_t destroyed = 0; + int32_t destroyed = 0; SQWorker *mgmt = *qWorkerMgmt; mgmt->destroyed = &destroyed; - + if (taosRemoveRef(gQwMgmt.qwRef, mgmt->refId)) { qError("remove qw from ref list failed, refId:%" PRIx64, mgmt->refId); return; @@ -1153,15 +1207,16 @@ int32_t qWorkerGetStat(SReadHandle *handle, void *qWorkerMgmt, SQWorkerStat *pSt return TSDB_CODE_SUCCESS; } -int32_t qWorkerProcessLocalQuery(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t tId, int64_t rId, int32_t eId, SQWMsg *qwMsg, SArray *explainRes) { - SQWorker *mgmt = (SQWorker*)pMgmt; +int32_t qWorkerProcessLocalQuery(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t tId, int64_t rId, int32_t eId, + SQWMsg *qwMsg, SArray *explainRes) { + SQWorker *mgmt = (SQWorker *)pMgmt; int32_t code = 0; SQWTaskCtx *ctx = NULL; SSubplan *plan = (SSubplan *)qwMsg->msg; SQWPhaseInput input = {0}; qTaskInfo_t pTaskInfo = NULL; DataSinkHandle sinkHandle = NULL; - SReadHandle rHandle = {0}; + SReadHandle rHandle = {0}; QW_ERR_JRET(qwAddTaskCtx(QW_FPARAMS())); QW_ERR_JRET(qwAddTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_INIT)); @@ -1178,7 +1233,7 @@ int32_t qWorkerProcessLocalQuery(void *pMgmt, uint64_t sId, uint64_t qId, uint64 rHandle.pMsgCb = taosMemoryCalloc(1, sizeof(SMsgCb)); rHandle.pMsgCb->clientRpc = qwMsg->connInfo.handle; - + code = qCreateExecTask(&rHandle, mgmt->nodeId, tId, plan, &pTaskInfo, &sinkHandle, NULL, OPTR_EXEC_MODEL_BATCH); if (code) { QW_TASK_ELOG("qCreateExecTask failed, code:%x - %s", code, tstrerror(code)); @@ -1199,7 +1254,7 @@ int32_t qWorkerProcessLocalQuery(void *pMgmt, uint64_t sId, uint64_t qId, uint64 _return: taosMemoryFree(rHandle.pMsgCb); - + input.code = code; input.msgType = qwMsg->msgType; code = qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_QUERY, &input, NULL); @@ -1212,13 +1267,14 @@ _return: QW_RET(code); } -int32_t qWorkerProcessLocalFetch(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t tId, int64_t rId, int32_t eId, void** pRsp, SArray* explainRes) { - SQWorker *mgmt = (SQWorker*)pMgmt; - int32_t code = 0; - int32_t dataLen = 0; - SQWTaskCtx *ctx = NULL; - void *rsp = NULL; - bool queryStop = false; +int32_t qWorkerProcessLocalFetch(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t tId, int64_t rId, int32_t eId, + void **pRsp, SArray *explainRes) { + SQWorker *mgmt = (SQWorker *)pMgmt; + int32_t code = 0; + int32_t dataLen = 0; + SQWTaskCtx *ctx = NULL; + void *rsp = NULL; + bool queryStop = false; SQWPhaseInput input = {0}; @@ -1228,15 +1284,15 @@ int32_t qWorkerProcessLocalFetch(void *pMgmt, uint64_t sId, uint64_t qId, uint64 ctx->msgType = TDMT_SCH_MERGE_FETCH; ctx->explainRes = explainRes; - + SOutputData sOutput = {0}; - + while (true) { QW_ERR_JRET(qwGetQueryResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput)); if (NULL == rsp) { QW_ERR_JRET(qwExecTask(QW_FPARAMS(), ctx, &queryStop)); - + continue; } else { bool qComplete = (DS_BUF_EMPTY == sOutput.bufStatus && sOutput.queryEnd); @@ -1259,5 +1315,3 @@ _return: QW_RET(code); } - - diff --git a/source/libs/qworker/test/qworkerTests.cpp b/source/libs/qworker/test/qworkerTests.cpp index 60d6594c1b62389147fd7f8dd7c5de0ee4b4211b..c855f005e779e9871ccb7216130bb23b90f8772e 100644 --- a/source/libs/qworker/test/qworkerTests.cpp +++ b/source/libs/qworker/test/qworkerTests.cpp @@ -32,18 +32,17 @@ #endif #include "os.h" -#include "tglobal.h" -#include "taos.h" -#include "tdef.h" -#include "tvariant.h" -#include "tdatablock.h" -#include "trpc.h" +#include "dataSinkMgt.h" +#include "executor.h" #include "planner.h" #include "qworker.h" #include "stub.h" -#include "executor.h" -#include "dataSinkMgt.h" - +#include "taos.h" +#include "tdatablock.h" +#include "tdef.h" +#include "tglobal.h" +#include "trpc.h" +#include "tvariant.h" namespace { @@ -55,56 +54,52 @@ bool qwtEnableLog = true; int32_t qwtTestMaxExecTaskUsec = 2; int32_t qwtTestReqMaxDelayUsec = 2; -int64_t qwtTestQueryId = 0; -bool qwtTestEnableSleep = true; -bool qwtTestStop = false; -bool qwtTestDeadLoop = false; -int32_t qwtTestMTRunSec = 2; -int32_t qwtTestPrintNum = 10000; +int64_t qwtTestQueryId = 0; +bool qwtTestEnableSleep = true; +bool qwtTestStop = false; +bool qwtTestDeadLoop = false; +int32_t qwtTestMTRunSec = 2; +int32_t qwtTestPrintNum = 10000; uint64_t qwtTestCaseIdx = 0; uint64_t qwtTestCaseNum = 4; -bool qwtTestCaseFinished = false; -tsem_t qwtTestQuerySem; -tsem_t qwtTestFetchSem; -int32_t qwtTestQuitThreadNum = 0; - - -int32_t qwtTestQueryQueueRIdx = 0; -int32_t qwtTestQueryQueueWIdx = 0; -int32_t qwtTestQueryQueueNum = 0; -SRWLatch qwtTestQueryQueueLock = 0; +bool qwtTestCaseFinished = false; +tsem_t qwtTestQuerySem; +tsem_t qwtTestFetchSem; +int32_t qwtTestQuitThreadNum = 0; + +int32_t qwtTestQueryQueueRIdx = 0; +int32_t qwtTestQueryQueueWIdx = 0; +int32_t qwtTestQueryQueueNum = 0; +SRWLatch qwtTestQueryQueueLock = 0; struct SRpcMsg *qwtTestQueryQueue[qwtTestQueryQueueSize] = {0}; -int32_t qwtTestFetchQueueRIdx = 0; -int32_t qwtTestFetchQueueWIdx = 0; -int32_t qwtTestFetchQueueNum = 0; -SRWLatch qwtTestFetchQueueLock = 0; +int32_t qwtTestFetchQueueRIdx = 0; +int32_t qwtTestFetchQueueWIdx = 0; +int32_t qwtTestFetchQueueNum = 0; +SRWLatch qwtTestFetchQueueLock = 0; struct SRpcMsg *qwtTestFetchQueue[qwtTestFetchQueueSize] = {0}; - -int32_t qwtTestSinkBlockNum = 0; -int32_t qwtTestSinkMaxBlockNum = 0; -bool qwtTestSinkQueryEnd = false; +int32_t qwtTestSinkBlockNum = 0; +int32_t qwtTestSinkMaxBlockNum = 0; +bool qwtTestSinkQueryEnd = false; SRWLatch qwtTestSinkLock = 0; -int32_t qwtTestSinkLastLen = 0; - - -SSubQueryMsg qwtqueryMsg = {0}; -SRpcMsg qwtfetchRpc = {0}; -SResFetchReq qwtfetchMsg = {0}; -SRpcMsg qwtreadyRpc = {0}; -SResReadyReq qwtreadyMsg = {0}; -SRpcMsg qwtdropRpc = {0}; -STaskDropReq qwtdropMsg = {0}; +int32_t qwtTestSinkLastLen = 0; + +SSubQueryMsg qwtqueryMsg = {0}; +SRpcMsg qwtfetchRpc = {0}; +SResFetchReq qwtfetchMsg = {0}; +SRpcMsg qwtreadyRpc = {0}; +SResReadyReq qwtreadyMsg = {0}; +SRpcMsg qwtdropRpc = {0}; +STaskDropReq qwtdropMsg = {0}; SSchTasksStatusReq qwtstatusMsg = {0}; - void qwtInitLogFile() { if (!qwtEnableLog) { return; } - const char *defaultLogFileNamePrefix = "taosdlog"; - const int32_t maxLogFileNum = 10; + const char *defaultLogFileNamePrefix = "taosdlog"; + const int32_t maxLogFileNum = 10; tsAsyncLog = 0; qDebugFlag = 159; @@ -113,7 +108,6 @@ void qwtInitLogFile() { if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) { printf("failed to open log file in directory:%s\n", tsLogDir); } - } void qwtBuildQueryReqMsg(SRpcMsg *queryRpc) { @@ -145,7 +139,7 @@ void qwtBuildDropReqMsg(STaskDropReq *dropMsg, SRpcMsg *dropRpc) { dropRpc->contLen = sizeof(STaskDropReq); } -int32_t qwtStringToPlan(const char* str, SSubplan** subplan) { +int32_t qwtStringToPlan(const char *str, SSubplan **subplan) { *subplan = (SSubplan *)0x1; return 0; } @@ -153,12 +147,12 @@ int32_t qwtStringToPlan(const char* str, SSubplan** subplan) { int32_t qwtPutReqToFetchQueue(void *node, struct SRpcMsg *pMsg) { taosWLockLatch(&qwtTestFetchQueueLock); struct SRpcMsg *newMsg = (struct SRpcMsg *)taosMemoryCalloc(1, sizeof(struct SRpcMsg)); - memcpy(newMsg, pMsg, sizeof(struct SRpcMsg)); + memcpy(newMsg, pMsg, sizeof(struct SRpcMsg)); qwtTestFetchQueue[qwtTestFetchQueueWIdx++] = newMsg; if (qwtTestFetchQueueWIdx >= qwtTestFetchQueueSize) { qwtTestFetchQueueWIdx = 0; } - + qwtTestFetchQueueNum++; if (qwtTestFetchQueueWIdx == qwtTestFetchQueueRIdx) { @@ -166,9 +160,9 @@ int32_t qwtPutReqToFetchQueue(void *node, struct SRpcMsg *pMsg) { assert(0); } taosWUnLockLatch(&qwtTestFetchQueueLock); - + tsem_post(&qwtTestFetchSem); - + return 0; } @@ -188,19 +182,15 @@ int32_t qwtPutReqToQueue(void *node, EQueueType qtype, struct SRpcMsg *pMsg) { assert(0); } taosWUnLockLatch(&qwtTestQueryQueueLock); - + tsem_post(&qwtTestQuerySem); - - return 0; -} -void qwtSendReqToDnode(void* pVnode, struct SEpSet* epSet, struct SRpcMsg* pReq) { - + return 0; } +void qwtSendReqToDnode(void *pVnode, struct SEpSet *epSet, struct SRpcMsg *pReq) {} void qwtRpcSendResponse(const SRpcMsg *pRsp) { - switch (pRsp->msgType) { case TDMT_SCH_QUERY_RSP: case TDMT_SCH_MERGE_QUERY_RSP: { @@ -210,14 +200,14 @@ void qwtRpcSendResponse(const SRpcMsg *pRsp) { qwtBuildDropReqMsg(&qwtdropMsg, &qwtdropRpc); qwtPutReqToFetchQueue((void *)0x1, &qwtdropRpc); } - + rpcFreeCont(rsp); break; } case TDMT_SCH_FETCH_RSP: case TDMT_SCH_MERGE_FETCH_RSP: { SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)pRsp->pCont; - + if (0 == pRsp->code && 0 == rsp->completed) { qwtBuildFetchReqMsg(&qwtfetchMsg, &qwtfetchRpc); qwtPutReqToFetchQueue((void *)0x1, &qwtfetchRpc); @@ -228,7 +218,7 @@ void qwtRpcSendResponse(const SRpcMsg *pRsp) { qwtBuildDropReqMsg(&qwtdropMsg, &qwtdropRpc); qwtPutReqToFetchQueue((void *)0x1, &qwtdropRpc); rpcFreeCont(rsp); - + break; } case TDMT_SCH_DROP_TASK_RSP: { @@ -240,26 +230,26 @@ void qwtRpcSendResponse(const SRpcMsg *pRsp) { } } - return; } -int32_t qwtCreateExecTask(void* tsdb, int32_t vgId, uint64_t taskId, struct SSubplan* pPlan, qTaskInfo_t* pTaskInfo, DataSinkHandle* handle) { +int32_t qwtCreateExecTask(void *tsdb, int32_t vgId, uint64_t taskId, struct SSubplan *pPlan, qTaskInfo_t *pTaskInfo, + DataSinkHandle *handle) { qwtTestSinkBlockNum = 0; qwtTestSinkMaxBlockNum = taosRand() % 100 + 1; qwtTestSinkQueryEnd = false; - - *pTaskInfo = (qTaskInfo_t)((char*)qwtTestCaseIdx+1); - *handle = (DataSinkHandle)((char*)qwtTestCaseIdx+2); + + *pTaskInfo = (qTaskInfo_t)((char *)qwtTestCaseIdx + 1); + *handle = (DataSinkHandle)((char *)qwtTestCaseIdx + 2); ++qwtTestCaseIdx; - + return 0; } -int32_t qwtExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) { +int32_t qwtExecTask(qTaskInfo_t tinfo, SSDataBlock **pRes, uint64_t *useconds) { int32_t endExec = 0; - + if (NULL == tinfo) { *pRes = NULL; *useconds = 0; @@ -269,9 +259,9 @@ int32_t qwtExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) { *useconds = taosRand() % 10; return 0; } - + endExec = taosRand() % 5; - + int32_t runTime = 0; if (qwtTestEnableSleep && qwtTestMaxExecTaskUsec > 0) { runTime = taosRand() % qwtTestMaxExecTaskUsec; @@ -282,28 +272,24 @@ int32_t qwtExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) { taosUsleep(runTime); } } - + if (endExec) { - *pRes = (SSDataBlock*)taosMemoryCalloc(1, sizeof(SSDataBlock)); + *pRes = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); (*pRes)->info.rows = taosRand() % 1000 + 1; } else { *pRes = NULL; *useconds = taosRand() % 10; } } - - return 0; -} -int32_t qwtKillTask(qTaskInfo_t qinfo) { return 0; } -void qwtDestroyTask(qTaskInfo_t qHandle) { -} +int32_t qwtKillTask(qTaskInfo_t qinfo) { return 0; } +void qwtDestroyTask(qTaskInfo_t qHandle) {} -int32_t qwtPutDataBlock(DataSinkHandle handle, const SInputData* pInput, bool* pContinue) { +int32_t qwtPutDataBlock(DataSinkHandle handle, const SInputData *pInput, bool *pContinue) { if (NULL == handle || NULL == pInput || NULL == pContinue) { assert(0); } @@ -320,7 +306,7 @@ int32_t qwtPutDataBlock(DataSinkHandle handle, const SInputData* pInput, bool* p *pContinue = true; } taosWUnLockLatch(&qwtTestSinkLock); - + return 0; } @@ -332,7 +318,7 @@ void qwtEndPut(DataSinkHandle handle, uint64_t useconds) { qwtTestSinkQueryEnd = true; } -void qwtGetDataLength(DataSinkHandle handle, int64_t* pLen, bool* pQueryEnd) { +void qwtGetDataLength(DataSinkHandle handle, int64_t *pLen, bool *pQueryEnd) { static int32_t in = 0; if (in > 0) { @@ -340,7 +326,7 @@ void qwtGetDataLength(DataSinkHandle handle, int64_t* pLen, bool* pQueryEnd) { } atomic_add_fetch_32(&in, 1); - + if (NULL == handle) { assert(0); } @@ -360,7 +346,7 @@ void qwtGetDataLength(DataSinkHandle handle, int64_t* pLen, bool* pQueryEnd) { atomic_sub_fetch_32(&in, 1); } -int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) { +int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData *pOutput) { taosWLockLatch(&qwtTestSinkLock); if (qwtTestSinkLastLen > 0) { pOutput->numOfRows = taosRand() % 10 + 1; @@ -368,7 +354,7 @@ int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) { pOutput->queryEnd = qwtTestSinkQueryEnd; if (qwtTestSinkBlockNum == 0) { pOutput->bufStatus = DS_BUF_EMPTY; - } else if (qwtTestSinkBlockNum <= qwtTestSinkMaxBlockNum*0.5) { + } else if (qwtTestSinkBlockNum <= qwtTestSinkMaxBlockNum * 0.5) { pOutput->bufStatus = DS_BUF_LOW; } else { pOutput->bufStatus = DS_BUF_FULL; @@ -382,7 +368,7 @@ int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) { pOutput->queryEnd = qwtTestSinkQueryEnd; if (qwtTestSinkBlockNum == 0) { pOutput->bufStatus = DS_BUF_EMPTY; - } else if (qwtTestSinkBlockNum <= qwtTestSinkMaxBlockNum*0.5) { + } else if (qwtTestSinkBlockNum <= qwtTestSinkMaxBlockNum * 0.5) { pOutput->bufStatus = DS_BUF_LOW; } else { pOutput->bufStatus = DS_BUF_FULL; @@ -393,31 +379,27 @@ int32_t qwtGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) { assert(0); } taosWUnLockLatch(&qwtTestSinkLock); - - return 0; -} - -void qwtDestroyDataSinker(DataSinkHandle handle) { + return 0; } - +void qwtDestroyDataSinker(DataSinkHandle handle) {} void stubSetStringToPlan() { static Stub stub; stub.set(qStringToSubplan, qwtStringToPlan); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("qStringToSubplan", result); #endif #ifdef LINUX - AddrAny any("libplanner.so"); - std::map result; + AddrAny any("libplanner.so"); + std::map result; any.get_global_func_addr_dynsym("^qStringToSubplan$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, qwtStringToPlan); } } @@ -428,38 +410,36 @@ void stubSetExecTask() { stub.set(qExecTask, qwtExecTask); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("qExecTask", result); #endif #ifdef LINUX - AddrAny any("libexecutor.so"); - std::map result; + AddrAny any("libexecutor.so"); + std::map result; any.get_global_func_addr_dynsym("^qExecTask$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, qwtExecTask); } } } - - void stubSetCreateExecTask() { static Stub stub; stub.set(qCreateExecTask, qwtCreateExecTask); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("qCreateExecTask", result); #endif #ifdef LINUX - AddrAny any("libexecutor.so"); - std::map result; + AddrAny any("libexecutor.so"); + std::map result; any.get_global_func_addr_dynsym("^qCreateExecTask$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, qwtCreateExecTask); } } @@ -470,16 +450,16 @@ void stubSetAsyncKillTask() { stub.set(qAsyncKillTask, qwtKillTask); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("qAsyncKillTask", result); #endif #ifdef LINUX - AddrAny any("libexecutor.so"); - std::map result; + AddrAny any("libexecutor.so"); + std::map result; any.get_global_func_addr_dynsym("^qAsyncKillTask$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, qwtKillTask); } } @@ -490,37 +470,36 @@ void stubSetDestroyTask() { stub.set(qDestroyTask, qwtDestroyTask); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("qDestroyTask", result); #endif #ifdef LINUX - AddrAny any("libexecutor.so"); - std::map result; + AddrAny any("libexecutor.so"); + std::map result; any.get_global_func_addr_dynsym("^qDestroyTask$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, qwtDestroyTask); } } } - void stubSetDestroyDataSinker() { static Stub stub; stub.set(dsDestroyDataSinker, qwtDestroyDataSinker); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("dsDestroyDataSinker", result); #endif #ifdef LINUX - AddrAny any("libexecutor.so"); - std::map result; + AddrAny any("libexecutor.so"); + std::map result; any.get_global_func_addr_dynsym("^dsDestroyDataSinker$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, qwtDestroyDataSinker); } } @@ -531,16 +510,16 @@ void stubSetGetDataLength() { stub.set(dsGetDataLength, qwtGetDataLength); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("dsGetDataLength", result); #endif #ifdef LINUX - AddrAny any("libexecutor.so"); - std::map result; + AddrAny any("libexecutor.so"); + std::map result; any.get_global_func_addr_dynsym("^dsGetDataLength$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, qwtGetDataLength); } } @@ -551,16 +530,16 @@ void stubSetEndPut() { stub.set(dsEndPut, qwtEndPut); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("dsEndPut", result); #endif #ifdef LINUX - AddrAny any("libexecutor.so"); - std::map result; + AddrAny any("libexecutor.so"); + std::map result; any.get_global_func_addr_dynsym("^dsEndPut$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, qwtEndPut); } } @@ -571,16 +550,16 @@ void stubSetPutDataBlock() { stub.set(dsPutDataBlock, qwtPutDataBlock); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("dsPutDataBlock", result); #endif #ifdef LINUX - AddrAny any("libexecutor.so"); - std::map result; + AddrAny any("libexecutor.so"); + std::map result; any.get_global_func_addr_dynsym("^dsPutDataBlock$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, qwtPutDataBlock); } } @@ -591,16 +570,16 @@ void stubSetRpcSendResponse() { stub.set(rpcSendResponse, qwtRpcSendResponse); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendResponse", result); #endif #ifdef LINUX - AddrAny any("libtransport.so"); - std::map result; + AddrAny any("libtransport.so"); + std::map result; any.get_global_func_addr_dynsym("^rpcSendResponse$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, qwtRpcSendResponse); } } @@ -611,34 +590,33 @@ void stubSetGetDataBlock() { stub.set(dsGetDataBlock, qwtGetDataBlock); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("dsGetDataBlock", result); #endif #ifdef LINUX - AddrAny any("libtransport.so"); - std::map result; + AddrAny any("libtransport.so"); + std::map result; any.get_global_func_addr_dynsym("^dsGetDataBlock$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, qwtGetDataBlock); } } } - void *queryThread(void *param) { - SRpcMsg queryRpc = {0}; - int32_t code = 0; + SRpcMsg queryRpc = {0}; + int32_t code = 0; uint32_t n = 0; - void *mockPointer = (void *)0x1; - void *mgmt = param; + void *mockPointer = (void *)0x1; + void *mgmt = param; while (!qwtTestStop) { qwtBuildQueryReqMsg(&queryRpc); - qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc, 0); + qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc, 0); if (qwtTestEnableSleep) { - taosUsleep(taosRand()%5); + taosUsleep(taosRand() % 5); } if (++n % qwtTestPrintNum == 0) { printf("query:%d\n", n); @@ -649,55 +627,55 @@ void *queryThread(void *param) { } void *fetchThread(void *param) { - SRpcMsg fetchRpc = {0}; - int32_t code = 0; - uint32_t n = 0; - void *mockPointer = (void *)0x1; - void *mgmt = param; + SRpcMsg fetchRpc = {0}; + int32_t code = 0; + uint32_t n = 0; + void *mockPointer = (void *)0x1; + void *mgmt = param; SResFetchReq fetchMsg = {0}; while (!qwtTestStop) { qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc); code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc, 0); if (qwtTestEnableSleep) { - taosUsleep(taosRand()%5); + taosUsleep(taosRand() % 5); } if (++n % qwtTestPrintNum == 0) { printf("fetch:%d\n", n); - } + } } return NULL; } void *dropThread(void *param) { - SRpcMsg dropRpc = {0}; - int32_t code = 0; - uint32_t n = 0; - void *mockPointer = (void *)0x1; - void *mgmt = param; - STaskDropReq dropMsg = {0}; + SRpcMsg dropRpc = {0}; + int32_t code = 0; + uint32_t n = 0; + void *mockPointer = (void *)0x1; + void *mgmt = param; + STaskDropReq dropMsg = {0}; while (!qwtTestStop) { qwtBuildDropReqMsg(&dropMsg, &dropRpc); code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc, 0); if (qwtTestEnableSleep) { - taosUsleep(taosRand()%5); + taosUsleep(taosRand() % 5); } if (++n % qwtTestPrintNum == 0) { printf("drop:%d\n", n); - } + } } return NULL; } void *qwtclientThread(void *param) { - int32_t code = 0; + int32_t code = 0; uint32_t n = 0; - void *mgmt = param; - void *mockPointer = (void *)0x1; - SRpcMsg queryRpc = {0}; + void *mgmt = param; + void *mockPointer = (void *)0x1; + SRpcMsg queryRpc = {0}; taosSsleep(1); @@ -710,8 +688,7 @@ void *qwtclientThread(void *param) { while (!qwtTestCaseFinished) { taosUsleep(1); } - - + if (++n % qwtTestPrintNum == 0) { printf("case run:%d\n", n); } @@ -723,9 +700,9 @@ void *qwtclientThread(void *param) { } void *queryQueueThread(void *param) { - void *mockPointer = (void *)0x1; + void *mockPointer = (void *)0x1; SRpcMsg *queryRpc = NULL; - void *mgmt = param; + void *mgmt = param; while (true) { tsem_wait(&qwtTestQuerySem); @@ -739,17 +716,16 @@ void *queryQueueThread(void *param) { printf("query queue is empty\n"); assert(0); } - + queryRpc = qwtTestQueryQueue[qwtTestQueryQueueRIdx++]; - + if (qwtTestQueryQueueRIdx >= qwtTestQueryQueueSize) { qwtTestQueryQueueRIdx = 0; } - + qwtTestQueryQueueNum--; taosWUnLockLatch(&qwtTestQueryQueueLock); - if (qwtTestEnableSleep && qwtTestReqMaxDelayUsec > 0) { int32_t delay = taosRand() % qwtTestReqMaxDelayUsec; @@ -757,7 +733,7 @@ void *queryQueueThread(void *param) { taosUsleep(delay); } } - + if (TDMT_SCH_QUERY == queryRpc->msgType) { qWorkerProcessQueryMsg(mockPointer, mgmt, queryRpc, 0); } else if (TDMT_SCH_QUERY_CONTINUE == queryRpc->msgType) { @@ -780,29 +756,29 @@ void *queryQueueThread(void *param) { } void *fetchQueueThread(void *param) { - void *mockPointer = (void *)0x1; + void *mockPointer = (void *)0x1; SRpcMsg *fetchRpc = NULL; - void *mgmt = param; + void *mgmt = param; while (true) { tsem_wait(&qwtTestFetchSem); if (qwtTestStop && qwtTestFetchQueueNum <= 0 && qwtTestCaseFinished) { break; - } + } taosWLockLatch(&qwtTestFetchQueueLock); if (qwtTestFetchQueueNum <= 0 || qwtTestFetchQueueRIdx == qwtTestFetchQueueWIdx) { printf("Fetch queue is empty\n"); assert(0); } - + fetchRpc = qwtTestFetchQueue[qwtTestFetchQueueRIdx++]; - + if (qwtTestFetchQueueRIdx >= qwtTestFetchQueueSize) { qwtTestFetchQueueRIdx = 0; } - + qwtTestFetchQueueNum--; taosWUnLockLatch(&qwtTestFetchQueueLock); @@ -835,7 +811,7 @@ void *fetchQueueThread(void *param) { if (qwtTestStop && qwtTestFetchQueueNum <= 0 && qwtTestCaseFinished) { break; - } + } } atomic_add_fetch_32(&qwtTestQuitThreadNum, 1); @@ -843,15 +819,12 @@ void *fetchQueueThread(void *param) { return NULL; } - - -} - +} // namespace TEST(seqTest, normalCase) { - void *mgmt = NULL; + void *mgmt = NULL; int32_t code = 0; - void *mockPointer = (void *)0x1; + void *mockPointer = (void *)0x1; SRpcMsg queryRpc = {0}; SRpcMsg fetchRpc = {0}; SRpcMsg dropRpc = {0}; @@ -861,7 +834,7 @@ TEST(seqTest, normalCase) { qwtBuildQueryReqMsg(&queryRpc); qwtBuildFetchReqMsg(&qwtfetchMsg, &fetchRpc); qwtBuildDropReqMsg(&qwtdropMsg, &dropRpc); - + stubSetStringToPlan(); stubSetRpcSendResponse(); stubSetExecTask(); @@ -873,7 +846,7 @@ TEST(seqTest, normalCase) { stubSetEndPut(); stubSetPutDataBlock(); stubSetGetDataBlock(); - + SMsgCb msgCb = {0}; msgCb.mgmt = (void *)mockPointer; msgCb.putToQueueFp = (PutToQueueFp)qwtPutReqToQueue; @@ -883,8 +856,8 @@ TEST(seqTest, normalCase) { code = qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc, 0); ASSERT_EQ(code, 0); - //code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc); - //ASSERT_EQ(code, 0); + // code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc); + // ASSERT_EQ(code, 0); code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc, 0); ASSERT_EQ(code, 0); @@ -896,14 +869,14 @@ TEST(seqTest, normalCase) { } TEST(seqTest, cancelFirst) { - void *mgmt = NULL; + void *mgmt = NULL; int32_t code = 0; - void *mockPointer = (void *)0x1; + void *mockPointer = (void *)0x1; SRpcMsg queryRpc = {0}; SRpcMsg dropRpc = {0}; qwtInitLogFile(); - + qwtBuildQueryReqMsg(&queryRpc); qwtBuildDropReqMsg(&qwtdropMsg, &dropRpc); @@ -926,21 +899,21 @@ TEST(seqTest, cancelFirst) { } TEST(seqTest, randCase) { - void *mgmt = NULL; - int32_t code = 0; - void *mockPointer = (void *)0x1; - SRpcMsg queryRpc = {0}; - SRpcMsg readyRpc = {0}; - SRpcMsg fetchRpc = {0}; - SRpcMsg dropRpc = {0}; - SRpcMsg statusRpc = {0}; - SResReadyReq readyMsg = {0}; - SResFetchReq fetchMsg = {0}; - STaskDropReq dropMsg = {0}; + void *mgmt = NULL; + int32_t code = 0; + void *mockPointer = (void *)0x1; + SRpcMsg queryRpc = {0}; + SRpcMsg readyRpc = {0}; + SRpcMsg fetchRpc = {0}; + SRpcMsg dropRpc = {0}; + SRpcMsg statusRpc = {0}; + SResReadyReq readyMsg = {0}; + SResFetchReq fetchMsg = {0}; + STaskDropReq dropMsg = {0}; SSchTasksStatusReq statusMsg = {0}; qwtInitLogFile(); - + stubSetStringToPlan(); stubSetRpcSendResponse(); stubSetCreateExecTask(); @@ -957,37 +930,37 @@ TEST(seqTest, randCase) { int32_t maxr = 10001; while (true) { int32_t r = taosRand() % maxr; - - if (r >= 0 && r < maxr/5) { - printf("Query,%d\n", t++); + + if (r >= 0 && r < maxr / 5) { + printf("Query,%d\n", t++); qwtBuildQueryReqMsg(&queryRpc); code = qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc, 0); - } else if (r >= maxr/5 && r < maxr * 2/5) { - //printf("Ready,%d\n", t++); - //qwtBuildReadyReqMsg(&readyMsg, &readyRpc); - //code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc); - //if (qwtTestEnableSleep) { - // taosUsleep(1); - //} - } else if (r >= maxr * 2/5 && r < maxr* 3/5) { + } else if (r >= maxr / 5 && r < maxr * 2 / 5) { + // printf("Ready,%d\n", t++); + // qwtBuildReadyReqMsg(&readyMsg, &readyRpc); + // code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc); + // if (qwtTestEnableSleep) { + // taosUsleep(1); + // } + } else if (r >= maxr * 2 / 5 && r < maxr * 3 / 5) { printf("Fetch,%d\n", t++); qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc); code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc, 0); if (qwtTestEnableSleep) { taosUsleep(1); } - } else if (r >= maxr * 3/5 && r < maxr * 4/5) { + } else if (r >= maxr * 3 / 5 && r < maxr * 4 / 5) { printf("Drop,%d\n", t++); qwtBuildDropReqMsg(&dropMsg, &dropRpc); code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc, 0); if (qwtTestEnableSleep) { taosUsleep(1); } - } else if (r >= maxr * 4/5 && r < maxr-1) { + } else if (r >= maxr * 4 / 5 && r < maxr - 1) { printf("Status,%d\n", t++); if (qwtTestEnableSleep) { taosUsleep(1); - } + } } else { printf("QUIT RAND NOW"); break; @@ -998,12 +971,12 @@ TEST(seqTest, randCase) { } TEST(seqTest, multithreadRand) { - void *mgmt = NULL; + void *mgmt = NULL; int32_t code = 0; - void *mockPointer = (void *)0x1; + void *mockPointer = (void *)0x1; qwtInitLogFile(); - + stubSetStringToPlan(); stubSetRpcSendResponse(); stubSetExecTask(); @@ -1027,9 +1000,9 @@ TEST(seqTest, multithreadRand) { TdThreadAttr thattr; taosThreadAttrInit(&thattr); - TdThread t1,t2,t3,t4,t5,t6; + TdThread t1, t2, t3, t4, t5, t6; taosThreadCreate(&(t1), &thattr, queryThread, mgmt); - //taosThreadCreate(&(t2), &thattr, readyThread, NULL); + // taosThreadCreate(&(t2), &thattr, readyThread, NULL); taosThreadCreate(&(t3), &thattr, fetchThread, NULL); taosThreadCreate(&(t4), &thattr, dropThread, NULL); taosThreadCreate(&(t6), &thattr, fetchQueueThread, mgmt); @@ -1042,7 +1015,7 @@ TEST(seqTest, multithreadRand) { break; } } - + qwtTestStop = true; taosSsleep(3); @@ -1054,17 +1027,17 @@ TEST(seqTest, multithreadRand) { qwtTestFetchQueueRIdx = 0; qwtTestFetchQueueWIdx = 0; qwtTestFetchQueueLock = 0; - + qWorkerDestroy(&mgmt); } TEST(rcTest, shortExecshortDelay) { - void *mgmt = NULL; + void *mgmt = NULL; int32_t code = 0; - void *mockPointer = (void *)0x1; + void *mockPointer = (void *)0x1; qwtInitLogFile(); - + stubSetStringToPlan(); stubSetRpcSendResponse(); stubSetExecTask(); @@ -1096,7 +1069,7 @@ TEST(rcTest, shortExecshortDelay) { TdThreadAttr thattr; taosThreadAttrInit(&thattr); - TdThread t1,t2,t3,t4,t5; + TdThread t1, t2, t3, t4, t5; taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt); taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt); taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt); @@ -1109,25 +1082,24 @@ TEST(rcTest, shortExecshortDelay) { break; } } - + qwtTestStop = true; while (true) { if (qwtTestQuitThreadNum == 3) { break; } - + taosSsleep(1); if (qwtTestCaseFinished) { - if (qwtTestQuitThreadNum < 3) { + if (qwtTestQuitThreadNum < 3) { tsem_post(&qwtTestQuerySem); tsem_post(&qwtTestFetchSem); taosUsleep(10); } } - } qwtTestQueryQueueNum = 0; @@ -1138,17 +1110,17 @@ TEST(rcTest, shortExecshortDelay) { qwtTestFetchQueueRIdx = 0; qwtTestFetchQueueWIdx = 0; qwtTestFetchQueueLock = 0; - - qWorkerDestroy(&mgmt); + + qWorkerDestroy(&mgmt); } TEST(rcTest, longExecshortDelay) { - void *mgmt = NULL; + void *mgmt = NULL; int32_t code = 0; - void *mockPointer = (void *)0x1; + void *mockPointer = (void *)0x1; qwtInitLogFile(); - + stubSetStringToPlan(); stubSetRpcSendResponse(); stubSetExecTask(); @@ -1180,7 +1152,7 @@ TEST(rcTest, longExecshortDelay) { TdThreadAttr thattr; taosThreadAttrInit(&thattr); - TdThread t1,t2,t3,t4,t5; + TdThread t1, t2, t3, t4, t5; taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt); taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt); taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt); @@ -1193,26 +1165,24 @@ TEST(rcTest, longExecshortDelay) { break; } } - + qwtTestStop = true; - while (true) { if (qwtTestQuitThreadNum == 3) { break; } - + taosSsleep(1); if (qwtTestCaseFinished) { - if (qwtTestQuitThreadNum < 3) { + if (qwtTestQuitThreadNum < 3) { tsem_post(&qwtTestQuerySem); tsem_post(&qwtTestFetchSem); - + taosUsleep(10); } } - } qwtTestQueryQueueNum = 0; @@ -1223,18 +1193,17 @@ TEST(rcTest, longExecshortDelay) { qwtTestFetchQueueRIdx = 0; qwtTestFetchQueueWIdx = 0; qwtTestFetchQueueLock = 0; - + qWorkerDestroy(&mgmt); } - TEST(rcTest, shortExeclongDelay) { - void *mgmt = NULL; + void *mgmt = NULL; int32_t code = 0; - void *mockPointer = (void *)0x1; + void *mockPointer = (void *)0x1; qwtInitLogFile(); - + stubSetStringToPlan(); stubSetRpcSendResponse(); stubSetExecTask(); @@ -1266,7 +1235,7 @@ TEST(rcTest, shortExeclongDelay) { TdThreadAttr thattr; taosThreadAttrInit(&thattr); - TdThread t1,t2,t3,t4,t5; + TdThread t1, t2, t3, t4, t5; taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt); taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt); taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt); @@ -1279,26 +1248,24 @@ TEST(rcTest, shortExeclongDelay) { break; } } - - qwtTestStop = true; + qwtTestStop = true; while (true) { if (qwtTestQuitThreadNum == 3) { break; } - + taosSsleep(1); if (qwtTestCaseFinished) { - if (qwtTestQuitThreadNum < 3) { + if (qwtTestQuitThreadNum < 3) { tsem_post(&qwtTestQuerySem); tsem_post(&qwtTestFetchSem); - + taosUsleep(10); } } - } qwtTestQueryQueueNum = 0; @@ -1309,18 +1276,17 @@ TEST(rcTest, shortExeclongDelay) { qwtTestFetchQueueRIdx = 0; qwtTestFetchQueueWIdx = 0; qwtTestFetchQueueLock = 0; - + qWorkerDestroy(&mgmt); } - TEST(rcTest, dropTest) { - void *mgmt = NULL; + void *mgmt = NULL; int32_t code = 0; - void *mockPointer = (void *)0x1; + void *mockPointer = (void *)0x1; qwtInitLogFile(); - + stubSetStringToPlan(); stubSetRpcSendResponse(); stubSetExecTask(); @@ -1347,7 +1313,7 @@ TEST(rcTest, dropTest) { TdThreadAttr thattr; taosThreadAttrInit(&thattr); - TdThread t1,t2,t3,t4,t5; + TdThread t1, t2, t3, t4, t5; taosThreadCreate(&(t1), &thattr, qwtclientThread, mgmt); taosThreadCreate(&(t2), &thattr, queryQueueThread, mgmt); taosThreadCreate(&(t3), &thattr, fetchQueueThread, mgmt); @@ -1360,15 +1326,14 @@ TEST(rcTest, dropTest) { break; } } - + qwtTestStop = true; taosSsleep(3); - + qWorkerDestroy(&mgmt); } - -int main(int argc, char** argv) { +int main(int argc, char **argv) { taosSeedRand(taosGetTimestampSec()); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/source/libs/scalar/inc/filterInt.h b/source/libs/scalar/inc/filterInt.h index ef3d3f79f959805681d0bc0e2e0b101cd8518388..e26bc59d47e368487370d9f0c260d61b24dc84a7 100644 --- a/source/libs/scalar/inc/filterInt.h +++ b/source/libs/scalar/inc/filterInt.h @@ -28,19 +28,19 @@ extern "C" { #include "thash.h" #include "tname.h" -#define FILTER_DEFAULT_GROUP_SIZE 4 -#define FILTER_DEFAULT_UNIT_SIZE 4 -#define FILTER_DEFAULT_FIELD_SIZE 4 -#define FILTER_DEFAULT_VALUE_SIZE 4 +#define FILTER_DEFAULT_GROUP_SIZE 4 +#define FILTER_DEFAULT_UNIT_SIZE 4 +#define FILTER_DEFAULT_FIELD_SIZE 4 +#define FILTER_DEFAULT_VALUE_SIZE 4 #define FILTER_DEFAULT_GROUP_UNIT_SIZE 2 -#define FILTER_DUMMY_EMPTY_OPTR 127 +#define FILTER_DUMMY_EMPTY_OPTR 127 #define FILTER_RM_UNIT_MIN_ROWS 100 enum { FLD_TYPE_COLUMN = 1, - FLD_TYPE_VALUE = 2, + FLD_TYPE_VALUE = 2, FLD_TYPE_MAX = 3, FLD_DATA_NO_FREE = 8, FLD_DATA_IS_HASH = 16, @@ -56,10 +56,9 @@ enum { enum { RANGE_FLG_EXCLUDE = 1, RANGE_FLG_INCLUDE = 2, - RANGE_FLG_NULL = 4, + RANGE_FLG_NULL = 4, }; - enum { FI_STATUS_ALL = 1, FI_STATUS_EMPTY = 2, @@ -93,63 +92,63 @@ typedef struct OptrStr { typedef struct SFilterRange { int64_t s; int64_t e; - char sflag; - char eflag; + char sflag; + char eflag; } SFilterRange; -typedef bool (*rangeCompFunc) (const void *, const void *, const void *, const void *, __compar_fn_t); -typedef int32_t(*filter_desc_compare_func)(const void *, const void *); -typedef bool(*filter_exec_func)(void*, int32_t, SColumnInfoData*, SColumnDataAgg*, int16_t, int32_t*); -typedef int32_t (*filer_get_col_from_name)(void *, int32_t, char*, void **); +typedef bool (*rangeCompFunc)(const void *, const void *, const void *, const void *, __compar_fn_t); +typedef int32_t (*filter_desc_compare_func)(const void *, const void *); +typedef bool (*filter_exec_func)(void *, int32_t, SColumnInfoData *, SColumnDataAgg *, int16_t, int32_t *); +typedef int32_t (*filer_get_col_from_name)(void *, int32_t, char *, void **); typedef struct SFilterRangeCompare { - int64_t s; - int64_t e; + int64_t s; + int64_t e; rangeCompFunc func; } SFilterRangeCompare; typedef struct SFilterRangeNode { - struct SFilterRangeNode* prev; - struct SFilterRangeNode* next; + struct SFilterRangeNode *prev; + struct SFilterRangeNode *next; union { - SFilterRange ra; + SFilterRange ra; SFilterRangeCompare rc; }; } SFilterRangeNode; typedef struct SFilterRangeCtx { - int32_t type; - int32_t options; - int8_t status; - bool isnull; - bool notnull; - bool isrange; - int16_t colId; - __compar_fn_t pCompareFunc; - SFilterRangeNode *rf; //freed + int32_t type; + int32_t options; + int8_t status; + bool isnull; + bool notnull; + bool isrange; + int16_t colId; + __compar_fn_t pCompareFunc; + SFilterRangeNode *rf; // freed SFilterRangeNode *rs; -} SFilterRangeCtx ; +} SFilterRangeCtx; typedef struct SFilterVarCtx { - int32_t type; - int32_t options; - int8_t status; - bool isnull; - bool notnull; - bool isrange; + int32_t type; + int32_t options; + int8_t status; + bool isnull; + bool notnull; + bool isrange; SHashObj *wild; SHashObj *value; } SFilterVarCtx; typedef struct SFilterField { uint16_t flag; - void* desc; - void* data; + void *desc; + void *data; } SFilterField; typedef struct SFilterFields { - uint32_t size; - uint32_t num; + uint32_t size; + uint32_t num; SFilterField *fields; } SFilterFields; @@ -174,40 +173,40 @@ typedef struct SFilterColInfo { } SFilterColInfo; typedef struct SFilterGroupCtx { - uint32_t colNum; - uint32_t *colIdx; - SFilterColInfo *colInfo; + uint32_t colNum; + uint32_t *colIdx; + SFilterColInfo *colInfo; } SFilterGroupCtx; typedef struct SFilterColCtx { - uint32_t colIdx; - void* ctx; + uint32_t colIdx; + void *ctx; } SFilterColCtx; typedef struct SFilterCompare { - uint8_t type; - int8_t precision; - uint8_t optr; - uint8_t optr2; + uint8_t type; + int8_t precision; + uint8_t optr; + uint8_t optr2; } SFilterCompare; typedef struct SFilterUnit { - SFilterCompare compare; - SFilterFieldId left; - SFilterFieldId right; - SFilterFieldId right2; + SFilterCompare compare; + SFilterFieldId left; + SFilterFieldId right; + SFilterFieldId right2; } SFilterUnit; typedef struct SFilterComUnit { - void *colData; // pointer to SColumnInfoData - void *valData; - void *valData2; + void *colData; // pointer to SColumnInfoData + void *valData; + void *valData2; uint16_t colId; uint16_t dataSize; - uint8_t dataType; - uint8_t optr; - int8_t func; - int8_t rfunc; + uint8_t dataType; + uint8_t optr; + int8_t func; + int8_t rfunc; } SFilterComUnit; typedef struct SFilterPCtx { @@ -219,8 +218,8 @@ typedef struct SFltTreeStat { int32_t code; int8_t precision; bool scalarMode; - SArray* nodeList; - SFilterInfo* info; + SArray *nodeList; + SFilterInfo *info; } SFltTreeStat; typedef struct SFltScalarCtx { @@ -237,7 +236,7 @@ struct SFilterInfo { bool scalarMode; SFltScalarCtx sclCtx; uint32_t options; - uint32_t status; + uint32_t status; uint32_t unitSize; uint32_t unitNum; uint32_t groupNum; @@ -249,7 +248,7 @@ struct SFilterInfo { uint8_t *unitRes; // result uint8_t *unitFlags; // got result SFilterRangeCtx **colRange; - filter_exec_func func; + filter_exec_func func; uint8_t blkFlag; uint32_t blkGroupNum; uint32_t *blkUnits; @@ -257,98 +256,231 @@ struct SFilterInfo { void *pTable; SArray *blkList; - SFilterPCtx pctx; + SFilterPCtx pctx; }; -#define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR || (t) == TSDB_DATA_TYPE_JSON) +#define FILTER_NO_MERGE_DATA_TYPE(t) \ + ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR || (t) == TSDB_DATA_TYPE_JSON) #define FILTER_NO_MERGE_OPTR(o) ((o) == OP_TYPE_IS_NULL || (o) == OP_TYPE_IS_NOT_NULL || (o) == FILTER_DUMMY_EMPTY_OPTR) #define MR_EMPTY_RES(ctx) (ctx->rs == NULL) -#define SET_AND_OPTR(ctx, o) do {if (o == OP_TYPE_IS_NULL) { (ctx)->isnull = true; } else if (o == OP_TYPE_IS_NOT_NULL) { if (!(ctx)->isrange) { (ctx)->notnull = true; } } else if (o != FILTER_DUMMY_EMPTY_OPTR) { (ctx)->isrange = true; (ctx)->notnull = false; } } while (0) -#define SET_OR_OPTR(ctx,o) do {if (o == OP_TYPE_IS_NULL) { (ctx)->isnull = true; } else if (o == OP_TYPE_IS_NOT_NULL) { (ctx)->notnull = true; (ctx)->isrange = false; } else if (o != FILTER_DUMMY_EMPTY_OPTR) { if (!(ctx)->notnull) { (ctx)->isrange = true; } } } while (0) +#define SET_AND_OPTR(ctx, o) \ + do { \ + if (o == OP_TYPE_IS_NULL) { \ + (ctx)->isnull = true; \ + } else if (o == OP_TYPE_IS_NOT_NULL) { \ + if (!(ctx)->isrange) { \ + (ctx)->notnull = true; \ + } \ + } else if (o != FILTER_DUMMY_EMPTY_OPTR) { \ + (ctx)->isrange = true; \ + (ctx)->notnull = false; \ + } \ + } while (0) +#define SET_OR_OPTR(ctx, o) \ + do { \ + if (o == OP_TYPE_IS_NULL) { \ + (ctx)->isnull = true; \ + } else if (o == OP_TYPE_IS_NOT_NULL) { \ + (ctx)->notnull = true; \ + (ctx)->isrange = false; \ + } else if (o != FILTER_DUMMY_EMPTY_OPTR) { \ + if (!(ctx)->notnull) { \ + (ctx)->isrange = true; \ + } \ + } \ + } while (0) #define CHK_OR_OPTR(ctx) ((ctx)->isnull == true && (ctx)->notnull == true) -#define CHK_AND_OPTR(ctx) ((ctx)->isnull == true && (((ctx)->notnull == true) || ((ctx)->isrange == true))) - +#define CHK_AND_OPTR(ctx) ((ctx)->isnull == true && (((ctx)->notnull == true) || ((ctx)->isrange == true))) #define FILTER_GET_FLAG(st, f) (st & f) #define FILTER_SET_FLAG(st, f) st |= (f) #define FILTER_CLR_FLAG(st, f) st &= (~f) #define SIMPLE_COPY_VALUES(dst, src) *((int64_t *)dst) = *((int64_t *)src) -#define FLT_PACKAGE_UNIT_HASH_KEY(v, op1, op2, lidx, ridx, ridx2) do { char *_t = (char *)(v); _t[0] = (op1); _t[1] = (op2); *(uint32_t *)(_t + 2) = (lidx); *(uint32_t *)(_t + 2 + sizeof(uint32_t)) = (ridx); } while (0) -#define FILTER_GREATER(cr,sflag,eflag) ((cr > 0) || ((cr == 0) && (FILTER_GET_FLAG(sflag,RANGE_FLG_EXCLUDE) || FILTER_GET_FLAG(eflag,RANGE_FLG_EXCLUDE)))) -#define FILTER_COPY_RA(dst, src) do { (dst)->sflag = (src)->sflag; (dst)->eflag = (src)->eflag; (dst)->s = (src)->s; (dst)->e = (src)->e; } while (0) - -#define RESET_RANGE(ctx, r) do { (r)->next = (ctx)->rf; (ctx)->rf = r; } while (0) -#define FREE_RANGE(ctx, r) do { if ((r)->prev) { (r)->prev->next = (r)->next; } else { (ctx)->rs = (r)->next;} if ((r)->next) { (r)->next->prev = (r)->prev; } RESET_RANGE(ctx, r); } while (0) -#define FREE_FROM_RANGE(ctx, r) do { SFilterRangeNode *_r = r; if ((_r)->prev) { (_r)->prev->next = NULL; } else { (ctx)->rs = NULL;} while (_r) {SFilterRangeNode *n = (_r)->next; RESET_RANGE(ctx, _r); _r = n; } } while (0) -#define INSERT_RANGE(ctx, r, ra) do { SFilterRangeNode *n = filterNewRange(ctx, ra); n->prev = (r)->prev; if ((r)->prev) { (r)->prev->next = n; } else { (ctx)->rs = n; } (r)->prev = n; n->next = r; } while (0) -#define APPEND_RANGE(ctx, r, ra) do { SFilterRangeNode *n = filterNewRange(ctx, ra); n->prev = (r); if (r) { (r)->next = n; } else { (ctx)->rs = n; } } while (0) +#define FLT_PACKAGE_UNIT_HASH_KEY(v, op1, op2, lidx, ridx, ridx2) \ + do { \ + char *_t = (char *)(v); \ + _t[0] = (op1); \ + _t[1] = (op2); \ + *(uint32_t *)(_t + 2) = (lidx); \ + *(uint32_t *)(_t + 2 + sizeof(uint32_t)) = (ridx); \ + } while (0) +#define FILTER_GREATER(cr, sflag, eflag) \ + ((cr > 0) || ((cr == 0) && (FILTER_GET_FLAG(sflag, RANGE_FLG_EXCLUDE) || FILTER_GET_FLAG(eflag, RANGE_FLG_EXCLUDE)))) +#define FILTER_COPY_RA(dst, src) \ + do { \ + (dst)->sflag = (src)->sflag; \ + (dst)->eflag = (src)->eflag; \ + (dst)->s = (src)->s; \ + (dst)->e = (src)->e; \ + } while (0) + +#define RESET_RANGE(ctx, r) \ + do { \ + (r)->next = (ctx)->rf; \ + (ctx)->rf = r; \ + } while (0) +#define FREE_RANGE(ctx, r) \ + do { \ + if ((r)->prev) { \ + (r)->prev->next = (r)->next; \ + } else { \ + (ctx)->rs = (r)->next; \ + } \ + if ((r)->next) { \ + (r)->next->prev = (r)->prev; \ + } \ + RESET_RANGE(ctx, r); \ + } while (0) +#define FREE_FROM_RANGE(ctx, r) \ + do { \ + SFilterRangeNode *_r = r; \ + if ((_r)->prev) { \ + (_r)->prev->next = NULL; \ + } else { \ + (ctx)->rs = NULL; \ + } \ + while (_r) { \ + SFilterRangeNode *n = (_r)->next; \ + RESET_RANGE(ctx, _r); \ + _r = n; \ + } \ + } while (0) +#define INSERT_RANGE(ctx, r, ra) \ + do { \ + SFilterRangeNode *n = filterNewRange(ctx, ra); \ + n->prev = (r)->prev; \ + if ((r)->prev) { \ + (r)->prev->next = n; \ + } else { \ + (ctx)->rs = n; \ + } \ + (r)->prev = n; \ + n->next = r; \ + } while (0) +#define APPEND_RANGE(ctx, r, ra) \ + do { \ + SFilterRangeNode *n = filterNewRange(ctx, ra); \ + n->prev = (r); \ + if (r) { \ + (r)->next = n; \ + } else { \ + (ctx)->rs = n; \ + } \ + } while (0) #define FLT_IS_COMPARISON_OPERATOR(_op) ((_op) >= OP_TYPE_GREATER_THAN && (_op) < OP_TYPE_IS_NOT_UNKNOWN) -#define fltFatal(...) qFatal(__VA_ARGS__) -#define fltError(...) qError(__VA_ARGS__) -#define fltWarn(...) qWarn(__VA_ARGS__) -#define fltInfo(...) qInfo(__VA_ARGS__) -#define fltDebug(...) qDebug(__VA_ARGS__) -#define fltTrace(...) qTrace(__VA_ARGS__) - - -#define FLT_CHK_JMP(c) do { if (c) { goto _return; } } while (0) -#define FLT_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) -#define FLT_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) -#define FLT_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) - - -#define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx])) -#define FILTER_GET_COL_FIELD(i, idx) (&((i)->fields[FLD_TYPE_COLUMN].fields[idx])) -#define FILTER_GET_COL_FIELD_TYPE(fi) (((SColumnNode *)((fi)->desc))->node.resType.type) +#define fltFatal(...) qFatal(__VA_ARGS__) +#define fltError(...) qError(__VA_ARGS__) +#define fltWarn(...) qWarn(__VA_ARGS__) +#define fltInfo(...) qInfo(__VA_ARGS__) +#define fltDebug(...) qDebug(__VA_ARGS__) +#define fltTrace(...) qTrace(__VA_ARGS__) + +#define FLT_CHK_JMP(c) \ + do { \ + if (c) { \ + goto _return; \ + } \ + } while (0) +#define FLT_ERR_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + return _code; \ + } \ + } while (0) +#define FLT_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + } \ + return _code; \ + } while (0) +#define FLT_ERR_JRET(c) \ + do { \ + code = c; \ + if (code != TSDB_CODE_SUCCESS) { \ + terrno = code; \ + goto _return; \ + } \ + } while (0) + +#define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx])) +#define FILTER_GET_COL_FIELD(i, idx) (&((i)->fields[FLD_TYPE_COLUMN].fields[idx])) +#define FILTER_GET_COL_FIELD_TYPE(fi) (((SColumnNode *)((fi)->desc))->node.resType.type) #define FILTER_GET_COL_FIELD_PRECISION(fi) (((SColumnNode *)((fi)->desc))->node.resType.precision) -#define FILTER_GET_COL_FIELD_SIZE(fi) (((SColumnNode *)((fi)->desc))->node.resType.bytes) -#define FILTER_GET_COL_FIELD_ID(fi) (((SColumnNode *)((fi)->desc))->colId) -#define FILTER_GET_COL_FIELD_SLOT_ID(fi) (((SColumnNode *)((fi)->desc))->slotId) -#define FILTER_GET_COL_FIELD_DESC(fi) ((SColumnNode *)((fi)->desc)) -#define FILTER_GET_COL_FIELD_DATA(fi, ri) (colDataGetData(((SColumnInfoData *)(fi)->data), (ri))) -#define FILTER_GET_VAL_FIELD_TYPE(fi) (((SValueNode *)((fi)->desc))->node.resType.type) -#define FILTER_GET_VAL_FIELD_DATA(fi) ((char *)(fi)->data) -#define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX) - -#define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid]) -#define FILTER_UNIT_LEFT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->left) -#define FILTER_UNIT_RIGHT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right) +#define FILTER_GET_COL_FIELD_SIZE(fi) (((SColumnNode *)((fi)->desc))->node.resType.bytes) +#define FILTER_GET_COL_FIELD_ID(fi) (((SColumnNode *)((fi)->desc))->colId) +#define FILTER_GET_COL_FIELD_SLOT_ID(fi) (((SColumnNode *)((fi)->desc))->slotId) +#define FILTER_GET_COL_FIELD_DESC(fi) ((SColumnNode *)((fi)->desc)) +#define FILTER_GET_COL_FIELD_DATA(fi, ri) (colDataGetData(((SColumnInfoData *)(fi)->data), (ri))) +#define FILTER_GET_VAL_FIELD_TYPE(fi) (((SValueNode *)((fi)->desc))->node.resType.type) +#define FILTER_GET_VAL_FIELD_DATA(fi) ((char *)(fi)->data) +#define FILTER_GET_TYPE(fl) ((fl)&FLD_TYPE_MAX) + +#define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid]) +#define FILTER_UNIT_LEFT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->left) +#define FILTER_UNIT_RIGHT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right) #define FILTER_UNIT_RIGHT2_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right2) -#define FILTER_UNIT_DATA_TYPE(u) ((u)->compare.type) -#define FILTER_UNIT_DATA_PRECISION(u) ((u)->compare.precision) -#define FILTER_UNIT_COL_DESC(i, u) FILTER_GET_COL_FIELD_DESC(FILTER_UNIT_LEFT_FIELD(i, u)) +#define FILTER_UNIT_DATA_TYPE(u) ((u)->compare.type) +#define FILTER_UNIT_DATA_PRECISION(u) ((u)->compare.precision) +#define FILTER_UNIT_COL_DESC(i, u) FILTER_GET_COL_FIELD_DESC(FILTER_UNIT_LEFT_FIELD(i, u)) #define FILTER_UNIT_COL_DATA(i, u, ri) FILTER_GET_COL_FIELD_DATA(FILTER_UNIT_LEFT_FIELD(i, u), ri) -#define FILTER_UNIT_COL_SIZE(i, u) FILTER_GET_COL_FIELD_SIZE(FILTER_UNIT_LEFT_FIELD(i, u)) -#define FILTER_UNIT_COL_ID(i, u) FILTER_GET_COL_FIELD_ID(FILTER_UNIT_LEFT_FIELD(i, u)) -#define FILTER_UNIT_VAL_DATA(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u)) -#define FILTER_UNIT_COL_IDX(u) ((u)->left.idx) -#define FILTER_UNIT_OPTR(u) ((u)->compare.optr) -#define FILTER_UNIT_COMP_FUNC(u) ((u)->compare.func) - -#define FILTER_UNIT_CLR_F(i) memset((i)->unitFlags, 0, (i)->unitNum * sizeof(*info->unitFlags)) -#define FILTER_UNIT_SET_F(i, idx) (i)->unitFlags[idx] = 1 -#define FILTER_UNIT_GET_F(i, idx) ((i)->unitFlags[idx]) -#define FILTER_UNIT_GET_R(i, idx) ((i)->unitRes[idx]) +#define FILTER_UNIT_COL_SIZE(i, u) FILTER_GET_COL_FIELD_SIZE(FILTER_UNIT_LEFT_FIELD(i, u)) +#define FILTER_UNIT_COL_ID(i, u) FILTER_GET_COL_FIELD_ID(FILTER_UNIT_LEFT_FIELD(i, u)) +#define FILTER_UNIT_VAL_DATA(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u)) +#define FILTER_UNIT_COL_IDX(u) ((u)->left.idx) +#define FILTER_UNIT_OPTR(u) ((u)->compare.optr) +#define FILTER_UNIT_COMP_FUNC(u) ((u)->compare.func) + +#define FILTER_UNIT_CLR_F(i) memset((i)->unitFlags, 0, (i)->unitNum * sizeof(*info->unitFlags)) +#define FILTER_UNIT_SET_F(i, idx) (i)->unitFlags[idx] = 1 +#define FILTER_UNIT_GET_F(i, idx) ((i)->unitFlags[idx]) +#define FILTER_UNIT_GET_R(i, idx) ((i)->unitRes[idx]) #define FILTER_UNIT_SET_R(i, idx, v) (i)->unitRes[idx] = (v) -#define FILTER_PUSH_UNIT(colInfo, u) do { (colInfo).type = RANGE_TYPE_UNIT; (colInfo).dataType = FILTER_UNIT_DATA_TYPE(u);taosArrayPush((SArray *)((colInfo).info), &u);} while (0) -#define FILTER_PUSH_VAR_HASH(colInfo, ha) do { (colInfo).type = RANGE_TYPE_VAR_HASH; (colInfo).info = ha;} while (0) -#define FILTER_PUSH_CTX(colInfo, ctx) do { (colInfo).type = RANGE_TYPE_MR_CTX; (colInfo).info = ctx;} while (0) - -#define FILTER_COPY_IDX(dst, src, n) do { *(dst) = taosMemoryMalloc(sizeof(uint32_t) * n); memcpy(*(dst), src, sizeof(uint32_t) * n);} while (0) - -#define FILTER_ADD_CTX_TO_GRES(gres, idx, ctx) do { if ((gres)->colCtxs == NULL) { (gres)->colCtxs = taosArrayInit(gres->colNum, sizeof(SFilterColCtx)); } SFilterColCtx cCtx = {idx, ctx}; taosArrayPush((gres)->colCtxs, &cCtx); } while (0) - - -#define FILTER_ALL_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_ALL) +#define FILTER_PUSH_UNIT(colInfo, u) \ + do { \ + (colInfo).type = RANGE_TYPE_UNIT; \ + (colInfo).dataType = FILTER_UNIT_DATA_TYPE(u); \ + taosArrayPush((SArray *)((colInfo).info), &u); \ + } while (0) +#define FILTER_PUSH_VAR_HASH(colInfo, ha) \ + do { \ + (colInfo).type = RANGE_TYPE_VAR_HASH; \ + (colInfo).info = ha; \ + } while (0) +#define FILTER_PUSH_CTX(colInfo, ctx) \ + do { \ + (colInfo).type = RANGE_TYPE_MR_CTX; \ + (colInfo).info = ctx; \ + } while (0) + +#define FILTER_COPY_IDX(dst, src, n) \ + do { \ + *(dst) = taosMemoryMalloc(sizeof(uint32_t) * n); \ + memcpy(*(dst), src, sizeof(uint32_t) * n); \ + } while (0) + +#define FILTER_ADD_CTX_TO_GRES(gres, idx, ctx) \ + do { \ + if ((gres)->colCtxs == NULL) { \ + (gres)->colCtxs = taosArrayInit(gres->colNum, sizeof(SFilterColCtx)); \ + } \ + SFilterColCtx cCtx = {idx, ctx}; \ + taosArrayPush((gres)->colCtxs, &cCtx); \ + } while (0) + +#define FILTER_ALL_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_ALL) #define FILTER_EMPTY_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_EMPTY) -extern bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right); +extern bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right); extern __compar_fn_t filterGetCompFunc(int32_t type, int32_t optr); extern __compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr); diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index 15e9026ddbc2eea8ad4e066519dd4bbea9767b7e..d3f29c0e49f38954d4856e826595d17bdb426b9d 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -18,9 +18,9 @@ #ifdef __cplusplus extern "C" { #endif +#include "query.h" #include "tcommon.h" #include "thash.h" -#include "query.h" typedef struct SOperatorValueType { int32_t opResType; @@ -29,46 +29,77 @@ typedef struct SOperatorValueType { } SOperatorValueType; typedef struct SScalarCtx { - int32_t code; - bool dual; - SArray *pBlockList; /* element is SSDataBlock* */ - SHashObj *pRes; /* element is SScalarParam */ - void *param; // additional parameter (meta actually) for acquire value such as tbname/tags values + int32_t code; + bool dual; + SArray* pBlockList; /* element is SSDataBlock* */ + SHashObj* pRes; /* element is SScalarParam */ + void* param; // additional parameter (meta actually) for acquire value such as tbname/tags values SOperatorValueType type; } SScalarCtx; - #define SCL_DATA_TYPE_DUMMY_HASH 9000 -#define SCL_DEFAULT_OP_NUM 10 +#define SCL_DEFAULT_OP_NUM 10 -#define SCL_IS_CONST_NODE(_node) ((NULL == (_node)) || (QUERY_NODE_VALUE == (_node)->type) || (QUERY_NODE_NODE_LIST == (_node)->type)) +#define SCL_IS_CONST_NODE(_node) \ + ((NULL == (_node)) || (QUERY_NODE_VALUE == (_node)->type) || (QUERY_NODE_NODE_LIST == (_node)->type)) #define SCL_IS_CONST_CALC(_ctx) (NULL == (_ctx)->pBlockList) -//#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode *)_node)->node.resType.type) && (((SValueNode *)_node)->placeholderNo <= 0)) -#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode *)_node)->node.resType.type)) +//#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode +//*)_node)->node.resType.type) && (((SValueNode *)_node)->placeholderNo <= 0)) +#define SCL_IS_NULL_VALUE_NODE(_node) \ + ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode*)_node)->node.resType.type)) #define SCL_IS_COMPARISON_OPERATOR(_opType) ((_opType) >= OP_TYPE_GREATER_THAN && (_opType) < OP_TYPE_IS_NOT_UNKNOWN) -#define SCL_DOWNGRADE_DATETYPE(_type) ((_type) == TSDB_DATA_TYPE_BIGINT || TSDB_DATA_TYPE_DOUBLE == (_type) || (_type) == TSDB_DATA_TYPE_UBIGINT) -#define SCL_NO_NEED_CONVERT_COMPARISION(_ltype, _rtype, _optr) (IS_NUMERIC_TYPE(_ltype) && IS_NUMERIC_TYPE(_rtype) && ((_optr) >= OP_TYPE_GREATER_THAN && (_optr) <= OP_TYPE_NOT_EQUAL)) +#define SCL_DOWNGRADE_DATETYPE(_type) \ + ((_type) == TSDB_DATA_TYPE_BIGINT || TSDB_DATA_TYPE_DOUBLE == (_type) || (_type) == TSDB_DATA_TYPE_UBIGINT) +#define SCL_NO_NEED_CONVERT_COMPARISION(_ltype, _rtype, _optr) \ + (IS_NUMERIC_TYPE(_ltype) && IS_NUMERIC_TYPE(_rtype) && \ + ((_optr) >= OP_TYPE_GREATER_THAN && (_optr) <= OP_TYPE_NOT_EQUAL)) -#define sclFatal(...) qFatal(__VA_ARGS__) -#define sclError(...) qError(__VA_ARGS__) -#define sclWarn(...) qWarn(__VA_ARGS__) -#define sclInfo(...) qInfo(__VA_ARGS__) -#define sclDebug(...) qDebug(__VA_ARGS__) -#define sclTrace(...) qTrace(__VA_ARGS__) +#define sclFatal(...) qFatal(__VA_ARGS__) +#define sclError(...) qError(__VA_ARGS__) +#define sclWarn(...) qWarn(__VA_ARGS__) +#define sclInfo(...) qInfo(__VA_ARGS__) +#define sclDebug(...) qDebug(__VA_ARGS__) +#define sclTrace(...) qTrace(__VA_ARGS__) -#define SCL_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) -#define SCL_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) -#define SCL_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) +#define SCL_ERR_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + return _code; \ + } \ + } while (0) +#define SCL_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + } \ + return _code; \ + } while (0) +#define SCL_ERR_JRET(c) \ + do { \ + code = c; \ + if (code != TSDB_CODE_SUCCESS) { \ + terrno = code; \ + goto _return; \ + } \ + } while (0) -int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out, int32_t* overflow); +int32_t sclConvertValueToSclParam(SValueNode* pValueNode, SScalarParam* out, int32_t* overflow); int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarParam* pParam); int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode); -#define GET_PARAM_TYPE(_c) ((_c)->columnData ? (_c)->columnData->info.type : (_c)->hashValueType) -#define GET_PARAM_BYTES(_c) ((_c)->columnData->info.bytes) -#define GET_PARAM_PRECISON(_c) ((_c)->columnData->info.precision) +#define GET_PARAM_TYPE(_c) ((_c)->columnData ? (_c)->columnData->info.type : (_c)->hashValueType) +#define GET_PARAM_BYTES(_c) ((_c)->columnData->info.bytes) +#define GET_PARAM_PRECISON(_c) ((_c)->columnData->info.precision) -void sclFreeParam(SScalarParam *param); +void sclFreeParam(SScalarParam* param); +void doVectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t startIndex, int32_t numOfRows, + int32_t _ord, int32_t optr); +void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t startIndex, int32_t numOfRows, + int32_t _ord, int32_t optr); +void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr); #ifdef __cplusplus } diff --git a/source/libs/scalar/inc/sclvector.h b/source/libs/scalar/inc/sclvector.h index a1bf1ce1ef7fa899ccea3b40485925c5b519a97a..e633b3922359f00647a792d247454b38599badea 100644 --- a/source/libs/scalar/inc/sclvector.h +++ b/source/libs/scalar/inc/sclvector.h @@ -20,6 +20,15 @@ extern "C" { #endif +typedef struct SSclVectorConvCtx { + const SScalarParam* pIn; + SScalarParam* pOut; + int32_t startIndex; + int32_t endIndex; + int16_t inType; + int16_t outType; +} SSclVectorConvCtx; + typedef double (*_getDoubleValue_fn_t)(void *src, int32_t index); static FORCE_INLINE double getVectorDoubleValue_TINYINT(void *src, int32_t index) { @@ -94,12 +103,12 @@ static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) return p; } -typedef void (*_bufConverteFunc)(char *buf, SScalarParam* pOut, int32_t outType, int32_t* overflow); -typedef void (*_bin_scalar_fn_t)(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *output, int32_t order); +typedef void (*_bufConverteFunc)(char *buf, SScalarParam *pOut, int32_t outType, int32_t *overflow); +typedef void (*_bin_scalar_fn_t)(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *output, int32_t order); _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binOperator); #ifdef __cplusplus } #endif -#endif /*_TD_COMMON_BIN_SCALAR_OPERATOR_H_*/ +#endif /*_TD_COMMON_BIN_SCALAR_OPERATOR_H_*/ diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index dbb5214415624c4215e2bfe33a7ed5aa3fd74729..81ee173648209c1f490e9e7778ea55c3f063cdf0 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -12,44 +12,44 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "os.h" #include +#include "os.h" #include "thash.h" //#include "queryLog.h" #include "filter.h" #include "filterInt.h" +#include "functionMgt.h" #include "sclInt.h" #include "tcompare.h" #include "tdatablock.h" #include "ttime.h" -#include "functionMgt.h" -bool filterRangeCompGi (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompGi(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { int32_t result = cfunc(maxv, minr); return result >= 0; } -bool filterRangeCompGe (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompGe(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { int32_t result = cfunc(maxv, minr); return result > 0; } -bool filterRangeCompLi (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompLi(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { int32_t result = cfunc(minv, maxr); return result <= 0; } -bool filterRangeCompLe (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompLe(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { int32_t result = cfunc(minv, maxr); return result < 0; } -bool filterRangeCompii (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompii(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(maxv, minr) >= 0 && cfunc(minv, maxr) <= 0; } -bool filterRangeCompee (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompee(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(maxv, minr) > 0 && cfunc(minv, maxr) < 0; } -bool filterRangeCompei (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompei(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(maxv, minr) > 0 && cfunc(minv, maxr) <= 0; } -bool filterRangeCompie (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompie(const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(maxv, minr) >= 0 && cfunc(minv, maxr) < 0; } @@ -85,9 +85,8 @@ rangeCompFunc filterGetRangeCompFunc(char sflag, char eflag) { return filterRangeCompii; } -rangeCompFunc gRangeCompare[] = {filterRangeCompee, filterRangeCompei, filterRangeCompie, filterRangeCompii, filterRangeCompGe, - filterRangeCompGi, filterRangeCompLe, filterRangeCompLi}; - +rangeCompFunc gRangeCompare[] = {filterRangeCompee, filterRangeCompei, filterRangeCompie, filterRangeCompii, + filterRangeCompGe, filterRangeCompGi, filterRangeCompLe, filterRangeCompLi}; int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { if (optr2) { @@ -108,100 +107,91 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { return 3; } else { switch (optr) { - case OP_TYPE_GREATER_THAN: - return 4; - case OP_TYPE_GREATER_EQUAL: - return 5; - case OP_TYPE_LOWER_THAN: - return 6; - case OP_TYPE_LOWER_EQUAL: - return 7; - default: - break; + case OP_TYPE_GREATER_THAN: + return 4; + case OP_TYPE_GREATER_EQUAL: + return 5; + case OP_TYPE_LOWER_THAN: + return 6; + case OP_TYPE_LOWER_EQUAL: + return 7; + default: + break; } } return -1; } -__compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val, compareInt64Val, compareFloatVal, - compareDoubleVal, compareLenPrefixedStr, compareStrPatternMatch, compareChkInString, compareWStrPatternMatch, - compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val, - setChkInBytes1, setChkInBytes2, setChkInBytes4, setChkInBytes8, compareStrRegexCompMatch, - compareStrRegexCompNMatch, setChkNotInBytes1, setChkNotInBytes2, setChkNotInBytes4, setChkNotInBytes8, - compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch -}; - -__compar_fn_t gInt8SignCompare[] = { - compareInt8Val, compareInt8Int16, compareInt8Int32, compareInt8Int64, compareInt8Float, compareInt8Double -}; -__compar_fn_t gInt8UsignCompare[] = { - compareInt8Uint8, compareInt8Uint16, compareInt8Uint32, compareInt8Uint64 -}; - -__compar_fn_t gInt16SignCompare[] = { - compareInt16Int8, compareInt16Val, compareInt16Int32, compareInt16Int64, compareInt16Float, compareInt16Double -}; -__compar_fn_t gInt16UsignCompare[] = { - compareInt16Uint8, compareInt16Uint16, compareInt16Uint32, compareInt16Uint64 -}; - -__compar_fn_t gInt32SignCompare[] = { - compareInt32Int8, compareInt32Int16, compareInt32Val, compareInt32Int64, compareInt32Float, compareInt32Double -}; -__compar_fn_t gInt32UsignCompare[] = { - compareInt32Uint8, compareInt32Uint16, compareInt32Uint32, compareInt32Uint64 -}; - -__compar_fn_t gInt64SignCompare[] = { - compareInt64Int8, compareInt64Int16, compareInt64Int32, compareInt64Val, compareInt64Float, compareInt64Double -}; -__compar_fn_t gInt64UsignCompare[] = { - compareInt64Uint8, compareInt64Uint16, compareInt64Uint32, compareInt64Uint64 -}; - -__compar_fn_t gFloatSignCompare[] = { - compareFloatInt8, compareFloatInt16, compareFloatInt32, compareFloatInt64, compareFloatVal, compareFloatDouble -}; -__compar_fn_t gFloatUsignCompare[] = { - compareFloatUint8, compareFloatUint16, compareFloatUint32, compareFloatUint64 -}; - -__compar_fn_t gDoubleSignCompare[] = { - compareDoubleInt8, compareDoubleInt16, compareDoubleInt32, compareDoubleInt64, compareDoubleFloat, compareDoubleVal -}; -__compar_fn_t gDoubleUsignCompare[] = { - compareDoubleUint8, compareDoubleUint16, compareDoubleUint32, compareDoubleUint64 -}; - -__compar_fn_t gUint8SignCompare[] = { - compareUint8Int8, compareUint8Int16, compareUint8Int32, compareUint8Int64, compareUint8Float, compareUint8Double -}; -__compar_fn_t gUint8UsignCompare[] = { - compareUint8Val, compareUint8Uint16, compareUint8Uint32, compareUint8Uint64 -}; - -__compar_fn_t gUint16SignCompare[] = { - compareUint16Int8, compareUint16Int16, compareUint16Int32, compareUint16Int64, compareUint16Float, compareUint16Double -}; -__compar_fn_t gUint16UsignCompare[] = { - compareUint16Uint8, compareUint16Val, compareUint16Uint32, compareUint16Uint64 -}; - -__compar_fn_t gUint32SignCompare[] = { - compareUint32Int8, compareUint32Int16, compareUint32Int32, compareUint32Int64, compareUint32Float, compareUint32Double -}; -__compar_fn_t gUint32UsignCompare[] = { - compareUint32Uint8, compareUint32Uint16, compareUint32Val, compareUint32Uint64 -}; - -__compar_fn_t gUint64SignCompare[] = { - compareUint64Int8, compareUint64Int16, compareUint64Int32, compareUint64Int64, compareUint64Float, compareUint64Double -}; -__compar_fn_t gUint64UsignCompare[] = { - compareUint64Uint8, compareUint64Uint16, compareUint64Uint32, compareUint64Val -}; - +__compar_fn_t gDataCompare[] = {compareInt32Val, + compareInt8Val, + compareInt16Val, + compareInt64Val, + compareFloatVal, + compareDoubleVal, + compareLenPrefixedStr, + compareStrPatternMatch, + compareChkInString, + compareWStrPatternMatch, + compareLenPrefixedWStr, + compareUint8Val, + compareUint16Val, + compareUint32Val, + compareUint64Val, + setChkInBytes1, + setChkInBytes2, + setChkInBytes4, + setChkInBytes8, + compareStrRegexCompMatch, + compareStrRegexCompNMatch, + setChkNotInBytes1, + setChkNotInBytes2, + setChkNotInBytes4, + setChkNotInBytes8, + compareChkNotInString, + compareStrPatternNotMatch, + compareWStrPatternNotMatch}; + +__compar_fn_t gInt8SignCompare[] = {compareInt8Val, compareInt8Int16, compareInt8Int32, + compareInt8Int64, compareInt8Float, compareInt8Double}; +__compar_fn_t gInt8UsignCompare[] = {compareInt8Uint8, compareInt8Uint16, compareInt8Uint32, compareInt8Uint64}; + +__compar_fn_t gInt16SignCompare[] = {compareInt16Int8, compareInt16Val, compareInt16Int32, + compareInt16Int64, compareInt16Float, compareInt16Double}; +__compar_fn_t gInt16UsignCompare[] = {compareInt16Uint8, compareInt16Uint16, compareInt16Uint32, compareInt16Uint64}; + +__compar_fn_t gInt32SignCompare[] = {compareInt32Int8, compareInt32Int16, compareInt32Val, + compareInt32Int64, compareInt32Float, compareInt32Double}; +__compar_fn_t gInt32UsignCompare[] = {compareInt32Uint8, compareInt32Uint16, compareInt32Uint32, compareInt32Uint64}; + +__compar_fn_t gInt64SignCompare[] = {compareInt64Int8, compareInt64Int16, compareInt64Int32, + compareInt64Val, compareInt64Float, compareInt64Double}; +__compar_fn_t gInt64UsignCompare[] = {compareInt64Uint8, compareInt64Uint16, compareInt64Uint32, compareInt64Uint64}; + +__compar_fn_t gFloatSignCompare[] = {compareFloatInt8, compareFloatInt16, compareFloatInt32, + compareFloatInt64, compareFloatVal, compareFloatDouble}; +__compar_fn_t gFloatUsignCompare[] = {compareFloatUint8, compareFloatUint16, compareFloatUint32, compareFloatUint64}; + +__compar_fn_t gDoubleSignCompare[] = {compareDoubleInt8, compareDoubleInt16, compareDoubleInt32, + compareDoubleInt64, compareDoubleFloat, compareDoubleVal}; +__compar_fn_t gDoubleUsignCompare[] = {compareDoubleUint8, compareDoubleUint16, compareDoubleUint32, + compareDoubleUint64}; + +__compar_fn_t gUint8SignCompare[] = {compareUint8Int8, compareUint8Int16, compareUint8Int32, + compareUint8Int64, compareUint8Float, compareUint8Double}; +__compar_fn_t gUint8UsignCompare[] = {compareUint8Val, compareUint8Uint16, compareUint8Uint32, compareUint8Uint64}; + +__compar_fn_t gUint16SignCompare[] = {compareUint16Int8, compareUint16Int16, compareUint16Int32, + compareUint16Int64, compareUint16Float, compareUint16Double}; +__compar_fn_t gUint16UsignCompare[] = {compareUint16Uint8, compareUint16Val, compareUint16Uint32, compareUint16Uint64}; + +__compar_fn_t gUint32SignCompare[] = {compareUint32Int8, compareUint32Int16, compareUint32Int32, + compareUint32Int64, compareUint32Float, compareUint32Double}; +__compar_fn_t gUint32UsignCompare[] = {compareUint32Uint8, compareUint32Uint16, compareUint32Val, compareUint32Uint64}; + +__compar_fn_t gUint64SignCompare[] = {compareUint64Int8, compareUint64Int16, compareUint64Int32, + compareUint64Int64, compareUint64Float, compareUint64Double}; +__compar_fn_t gUint64UsignCompare[] = {compareUint64Uint8, compareUint64Uint16, compareUint64Uint32, compareUint64Val}; int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { int8_t comparFn = 0; @@ -262,16 +252,27 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { return 28; } - switch (type) { case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_TINYINT: comparFn = 1; break; - case TSDB_DATA_TYPE_SMALLINT: comparFn = 2; break; - case TSDB_DATA_TYPE_INT: comparFn = 0; break; + case TSDB_DATA_TYPE_TINYINT: + comparFn = 1; + break; + case TSDB_DATA_TYPE_SMALLINT: + comparFn = 2; + break; + case TSDB_DATA_TYPE_INT: + comparFn = 0; + break; case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_TIMESTAMP: comparFn = 3; break; - case TSDB_DATA_TYPE_FLOAT: comparFn = 4; break; - case TSDB_DATA_TYPE_DOUBLE: comparFn = 5; break; + case TSDB_DATA_TYPE_TIMESTAMP: + comparFn = 3; + break; + case TSDB_DATA_TYPE_FLOAT: + comparFn = 4; + break; + case TSDB_DATA_TYPE_DOUBLE: + comparFn = 5; + break; case TSDB_DATA_TYPE_BINARY: { if (optr == OP_TYPE_MATCH) { comparFn = 19; @@ -311,10 +312,18 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { break; } - case TSDB_DATA_TYPE_UTINYINT: comparFn = 11; break; - case TSDB_DATA_TYPE_USMALLINT: comparFn = 12;break; - case TSDB_DATA_TYPE_UINT: comparFn = 13;break; - case TSDB_DATA_TYPE_UBIGINT: comparFn = 14;break; + case TSDB_DATA_TYPE_UTINYINT: + comparFn = 11; + break; + case TSDB_DATA_TYPE_USMALLINT: + comparFn = 12; + break; + case TSDB_DATA_TYPE_UINT: + comparFn = 13; + break; + case TSDB_DATA_TYPE_UBIGINT: + comparFn = 14; + break; default: comparFn = 0; @@ -324,9 +333,7 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { return comparFn; } -__compar_fn_t filterGetCompFunc(int32_t type, int32_t optr) { - return gDataCompare[filterGetCompFuncIdx(type, optr)]; -} +__compar_fn_t filterGetCompFunc(int32_t type, int32_t optr) { return gDataCompare[filterGetCompFuncIdx(type, optr)]; } __compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr) { switch (lType) { @@ -417,7 +424,7 @@ __compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr) { } static FORCE_INLINE int32_t filterCompareGroupCtx(const void *pLeft, const void *pRight) { - SFilterGroupCtx *left = *((SFilterGroupCtx**)pLeft), *right = *((SFilterGroupCtx**)pRight); + SFilterGroupCtx *left = *((SFilterGroupCtx **)pLeft), *right = *((SFilterGroupCtx **)pRight); if (left->colNum > right->colNum) return 1; if (left->colNum < right->colNum) return -1; return 0; @@ -437,7 +444,7 @@ int32_t filterInitUnitsFields(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } -static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilterRange* ra) { +static FORCE_INLINE SFilterRangeNode *filterNewRange(SFilterRangeCtx *ctx, SFilterRange *ra) { SFilterRangeNode *r = NULL; if (ctx->rf) { @@ -454,8 +461,9 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilt return r; } -void* filterInitRangeCtx(int32_t type, int32_t options) { - if (type > TSDB_DATA_TYPE_UBIGINT || type < TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { +void *filterInitRangeCtx(int32_t type, int32_t options) { + if (type > TSDB_DATA_TYPE_UBIGINT || type < TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_BINARY || + type == TSDB_DATA_TYPE_NCHAR) { qError("not supported range type:%d", type); return NULL; } @@ -469,7 +477,6 @@ void* filterInitRangeCtx(int32_t type, int32_t options) { return ctx; } - int32_t filterResetRangeCtx(SFilterRangeCtx *ctx) { ctx->status = 0; @@ -504,7 +511,6 @@ int32_t filterReuseRangeCtx(SFilterRangeCtx *ctx, int32_t type, int32_t options) return TSDB_CODE_SUCCESS; } - int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull) { if (!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) { int32_t sr = cur->pCompareFunc(&ra->s, getDataMin(cur->type)); @@ -520,7 +526,6 @@ int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull } } - if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL) && FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) { *notNull = true; } else { @@ -530,7 +535,7 @@ int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull return TSDB_CODE_SUCCESS; } -int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, bool *all) { +int32_t filterAddRangeOptr(void *h, uint8_t raOptr, int32_t optr, bool *empty, bool *all) { SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; if (optr == LOGIC_COND_TYPE_AND) { @@ -550,15 +555,13 @@ int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, b return TSDB_CODE_SUCCESS; } - - -int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { +int32_t filterAddRangeImpl(void *h, SFilterRange *ra, int32_t optr) { SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; if (ctx->rs == NULL) { - if ((FILTER_GET_FLAG(ctx->status, MR_ST_START) == 0) - || (FILTER_GET_FLAG(ctx->status, MR_ST_ALL) && (optr == LOGIC_COND_TYPE_AND)) - || ((!FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) && (optr == LOGIC_COND_TYPE_OR))) { + if ((FILTER_GET_FLAG(ctx->status, MR_ST_START) == 0) || + (FILTER_GET_FLAG(ctx->status, MR_ST_ALL) && (optr == LOGIC_COND_TYPE_AND)) || + ((!FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) && (optr == LOGIC_COND_TYPE_OR))) { APPEND_RANGE(ctx, ctx->rs, ra); FILTER_SET_FLAG(ctx->status, MR_ST_START); } @@ -568,7 +571,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { SFilterRangeNode *r = ctx->rs; SFilterRangeNode *rn = NULL; - int32_t cr = 0; + int32_t cr = 0; if (optr == LOGIC_COND_TYPE_AND) { while (r != NULL) { @@ -605,8 +608,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { return TSDB_CODE_SUCCESS; } - - //TSDB_RELATION_OR + // TSDB_RELATION_OR bool smerged = false; bool emerged = false; @@ -625,7 +627,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { cr = ctx->pCompareFunc(&ra->s, &r->ra.e); if (FILTER_GREATER(cr, ra->sflag, r->ra.eflag)) { if (r->next) { - r= r->next; + r = r->next; continue; } @@ -692,23 +694,22 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { return TSDB_CODE_SUCCESS; } -int32_t filterAddRange(void* h, SFilterRange* ra, int32_t optr) { +int32_t filterAddRange(void *h, SFilterRange *ra, int32_t optr) { SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) { SIMPLE_COPY_VALUES(&ra->s, getDataMin(ctx->type)); - //FILTER_CLR_FLAG(ra->sflag, RA_NULL); + // FILTER_CLR_FLAG(ra->sflag, RA_NULL); } if (FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) { SIMPLE_COPY_VALUES(&ra->e, getDataMax(ctx->type)); - //FILTER_CLR_FLAG(ra->eflag, RA_NULL); + // FILTER_CLR_FLAG(ra->eflag, RA_NULL); } return filterAddRangeImpl(h, ra, optr); } - int32_t filterAddRangeCtx(void *dst, void *src, int32_t optr) { SFilterRangeCtx *dctx = (SFilterRangeCtx *)dst; SFilterRangeCtx *sctx = (SFilterRangeCtx *)src; @@ -755,9 +756,7 @@ int32_t filterCopyRangeCtx(void *dst, void *src) { return TSDB_CODE_SUCCESS; } - - -int32_t filterFinishRange(void* h) { +int32_t filterFinishRange(void *h) { SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; if (FILTER_GET_FLAG(ctx->status, MR_ST_FIN)) { @@ -789,7 +788,7 @@ int32_t filterFinishRange(void* h) { return TSDB_CODE_SUCCESS; } -int32_t filterGetRangeNum(void* h, int32_t* num) { +int32_t filterGetRangeNum(void *h, int32_t *num) { filterFinishRange(h); SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; @@ -806,13 +805,12 @@ int32_t filterGetRangeNum(void* h, int32_t* num) { return TSDB_CODE_SUCCESS; } - -int32_t filterGetRangeRes(void* h, SFilterRange *ra) { +int32_t filterGetRangeRes(void *h, SFilterRange *ra) { filterFinishRange(h); - SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; - uint32_t num = 0; - SFilterRangeNode* r = ctx->rs; + SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; + uint32_t num = 0; + SFilterRangeNode *r = ctx->rs; while (r) { if (num) { @@ -834,11 +832,10 @@ int32_t filterGetRangeRes(void* h, SFilterRange *ra) { return TSDB_CODE_SUCCESS; } - int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr, bool *empty, bool *all) { SFilterRangeCtx *src = (SFilterRangeCtx *)sctx; - if (src->isnull){ + if (src->isnull) { filterAddRangeOptr(ctx, OP_TYPE_IS_NULL, optr, empty, all); if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) { *all = true; @@ -867,14 +864,12 @@ int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr, return TSDB_CODE_SUCCESS; } - - -int32_t filterFreeRangeCtx(void* h) { +int32_t filterFreeRangeCtx(void *h) { if (h == NULL) { return TSDB_CODE_SUCCESS; } - SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; + SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; SFilterRangeNode *r = ctx->rs; SFilterRangeNode *rn = NULL; @@ -896,8 +891,7 @@ int32_t filterFreeRangeCtx(void* h) { return TSDB_CODE_SUCCESS; } - -int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group) { +int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray *group) { SFilterGroup gp = {0}; gp.unitNum = gp1->unitNum + gp2->unitNum; @@ -912,8 +906,7 @@ int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group return TSDB_CODE_SUCCESS; } - -int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) { +int32_t filterDetachCnfGroups(SArray *group, SArray *left, SArray *right) { int32_t leftSize = (int32_t)taosArrayGetSize(left); int32_t rightSize = (int32_t)taosArrayGetSize(right); @@ -950,11 +943,10 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) { } } - return TSDB_CODE_SUCCESS; } -int32_t filterGetFiledByDesc(SFilterFields* fields, int32_t type, void *v) { +int32_t filterGetFiledByDesc(SFilterFields *fields, int32_t type, void *v) { for (uint32_t i = 0; i < fields->num; ++i) { if (nodesEqualNode(fields->fields[i].desc, v)) { return i; @@ -964,7 +956,6 @@ int32_t filterGetFiledByDesc(SFilterFields* fields, int32_t type, void *v) { return -1; } - int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t dataLen) { if (type == FLD_TYPE_VALUE) { if (info->pctx.valHash == false) { @@ -981,10 +972,11 @@ int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t d return -1; } -// In the params, we should use void *data instead of void **data, there is no need to use taosMemoryFreeClear(*data) to set *data = 0 -// Besides, fields data value is a pointer, so dataLen should be POINTER_BYTES for better. -int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, SFilterFieldId *fid, int32_t dataLen, bool freeIfExists) { - int32_t idx = -1; +// In the params, we should use void *data instead of void **data, there is no need to use taosMemoryFreeClear(*data) to +// set *data = 0 Besides, fields data value is a pointer, so dataLen should be POINTER_BYTES for better. +int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, SFilterFieldId *fid, int32_t dataLen, + bool freeIfExists) { + int32_t idx = -1; uint32_t *num; num = &info->fields[type].num; @@ -1001,7 +993,8 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, idx = *num; if (idx >= info->fields[type].size) { info->fields[type].size += FILTER_DEFAULT_FIELD_SIZE; - info->fields[type].fields = taosMemoryRealloc(info->fields[type].fields, info->fields[type].size * sizeof(SFilterField)); + info->fields[type].fields = + taosMemoryRealloc(info->fields[type].fields, info->fields[type].size * sizeof(SFilterField)); } info->fields[type].fields[idx].flag = type; @@ -1016,7 +1009,8 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, if (data && (*data) && dataLen > 0 && FILTER_GET_FLAG(info->options, FLT_OPTION_NEED_UNIQE)) { if (info->pctx.valHash == NULL) { - info->pctx.valHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_VALUE_SIZE, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); + info->pctx.valHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_VALUE_SIZE, + taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); } taosHashPut(info->pctx.valHash, *data, dataLen, &idx, sizeof(idx)); @@ -1041,19 +1035,19 @@ static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilte return TSDB_CODE_SUCCESS; } - int32_t filterAddFieldFromNode(SFilterInfo *info, SNode *node, SFilterFieldId *fid) { if (node == NULL) { fltError("empty node"); FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - if (nodeType(node) != QUERY_NODE_COLUMN && nodeType(node) != QUERY_NODE_VALUE && nodeType(node) != QUERY_NODE_NODE_LIST) { + if (nodeType(node) != QUERY_NODE_COLUMN && nodeType(node) != QUERY_NODE_VALUE && + nodeType(node) != QUERY_NODE_NODE_LIST) { FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } int32_t type; - void *v; + void *v; if (nodeType(node) == QUERY_NODE_COLUMN) { type = FLD_TYPE_COLUMN; @@ -1068,10 +1062,12 @@ int32_t filterAddFieldFromNode(SFilterInfo *info, SNode *node, SFilterFieldId *f return TSDB_CODE_SUCCESS; } -int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right, uint8_t optr2, SFilterFieldId *right2, uint32_t *uidx) { +int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right, uint8_t optr2, + SFilterFieldId *right2, uint32_t *uidx) { if (FILTER_GET_FLAG(info->options, FLT_OPTION_NEED_UNIQE)) { if (info->pctx.unitHash == NULL) { - info->pctx.unitHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_UNIT_SIZE, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, false); + info->pctx.unitHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_UNIT_SIZE, + taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, false); } else { char v[14] = {0}; FLT_PACKAGE_UNIT_HASH_KEY(&v, optr, optr2, left->idx, (right ? right->idx : -1), (right2 ? right2->idx : -1)); @@ -1101,7 +1097,7 @@ int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, if (right2) { u->right2 = *right2; } - + if (u->right.type == FLD_TYPE_VALUE) { SFilterField *val = FILTER_UNIT_RIGHT_FIELD(info, u); assert(FILTER_GET_FLAG(val->flag, FLD_TYPE_VALUE)); @@ -1132,7 +1128,6 @@ int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, return TSDB_CODE_SUCCESS; } - int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right, uint32_t *uidx) { return filterAddUnitImpl(info, optr, left, right, 0, NULL, uidx); } @@ -1148,19 +1143,19 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) { return TSDB_CODE_SUCCESS; } -int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { +int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) { SOperatorNode *node = (SOperatorNode *)tree; - int32_t ret = TSDB_CODE_SUCCESS; + int32_t ret = TSDB_CODE_SUCCESS; SFilterFieldId left = {0}, right = {0}; filterAddFieldFromNode(info, node->pLeft, &left); - uint8_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left)); - int32_t len = 0; + uint8_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left)); + int32_t len = 0; uint32_t uidx = 0; - int32_t code = 0; + int32_t code = 0; if (node->opType == OP_TYPE_IN && (!IS_VAR_DATA_TYPE(type))) { SNodeListNode *listNode = (SNodeListNode *)node->pRight; - SListCell *cell = listNode->pNodeList->pHead; + SListCell *cell = listNode->pNodeList->pHead; SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; out.columnData->info.type = type; @@ -1170,9 +1165,9 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { SValueNode *valueNode = (SValueNode *)cell->pNode; if (valueNode->node.resType.type != type) { int32_t overflow = 0; - code = doConvertDataType(valueNode, &out, &overflow); + code = sclConvertValueToSclParam(valueNode, &out, &overflow); if (code) { - // fltError("convert from %d to %d failed", in.type, out.type); + // fltError("convert from %d to %d failed", in.type, out.type); FLT_ERR_RET(code); } @@ -1183,7 +1178,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { len = tDataTypes[type].bytes; - filterAddField(info, NULL, (void**) &out.columnData->pData, FLD_TYPE_VALUE, &right, len, true); + filterAddField(info, NULL, (void **)&out.columnData->pData, FLD_TYPE_VALUE, &right, len, true); out.columnData->pData = NULL; } else { void *data = taosMemoryCalloc(1, tDataTypes[type].bytes); @@ -1191,7 +1186,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { FLT_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } memcpy(data, nodesGetValueFromNode(valueNode), tDataTypes[type].bytes); - filterAddField(info, NULL, (void**) &data, FLD_TYPE_VALUE, &right, len, true); + filterAddField(info, NULL, (void **)&data, FLD_TYPE_VALUE, &right, len, true); } filterAddUnit(info, OP_TYPE_EQUAL, &left, &right, &uidx); @@ -1217,11 +1212,10 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { return TSDB_CODE_SUCCESS; } - -int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u, uint32_t *uidx) { +int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit *u, uint32_t *uidx) { SFilterFieldId left, right, *pright = &right; - int32_t type = FILTER_UNIT_DATA_TYPE(u); - uint16_t flag = 0; + int32_t type = FILTER_UNIT_DATA_TYPE(u); + uint16_t flag = 0; filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left, 0, false); SFilterField *t = FILTER_UNIT_LEFT_FIELD(src, u); @@ -1229,8 +1223,9 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u if (u->right.type == FLD_TYPE_VALUE) { void *data = FILTER_UNIT_VAL_DATA(src, u); if (IS_VAR_DATA_TYPE(type)) { - if (FILTER_UNIT_OPTR(u) == OP_TYPE_IN) { - filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, POINTER_BYTES, false); // POINTER_BYTES should be sizeof(SHashObj), but POINTER_BYTES is also right. + if (FILTER_UNIT_OPTR(u) == OP_TYPE_IN) { + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, POINTER_BYTES, + false); // POINTER_BYTES should be sizeof(SHashObj), but POINTER_BYTES is also right. t = FILTER_GET_FIELD(dst, right); FILTER_SET_FLAG(t->flag, FLD_DATA_IS_HASH); @@ -1259,9 +1254,10 @@ int32_t filterAddUnitRight(SFilterInfo *info, uint8_t optr, SFilterFieldId *righ return TSDB_CODE_SUCCESS; } -int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRangeCtx *ctx, uint32_t cidx, SFilterGroup *g, int32_t optr, SArray *res) { +int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRangeCtx *ctx, uint32_t cidx, + SFilterGroup *g, int32_t optr, SArray *res) { SFilterFieldId left, right, right2; - uint32_t uidx = 0; + uint32_t uidx = 0; SFilterField *col = FILTER_GET_COL_FIELD(src, cidx); @@ -1312,8 +1308,10 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan SIMPLE_COPY_VALUES(data2, &ra->e); filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true); - filterAddUnitImpl(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, - FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, &uidx); + filterAddUnitImpl( + dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, + &right, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, + &uidx); filterAddUnitToGroup(g, uidx); return TSDB_CODE_SUCCESS; } @@ -1323,7 +1321,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->s); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); - filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, &uidx); + filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, + &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } @@ -1331,7 +1330,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->e); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); - filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &left, &right, &uidx); + filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, + &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } @@ -1371,7 +1371,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan while (r) { memset(g, 0, sizeof(*g)); - if ((!FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) &&(!FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL))) { + if ((!FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) && (!FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL))) { __compar_fn_t func = getComparFunc(type, 0); if (func(&r->ra.s, &r->ra.e) == 0) { void *data = taosMemoryMalloc(sizeof(int64_t)); @@ -1387,8 +1387,10 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan SIMPLE_COPY_VALUES(data2, &r->ra.e); filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true); - filterAddUnitImpl(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, - FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, &uidx); + filterAddUnitImpl( + dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, + &right, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, + &uidx); filterAddUnitToGroup(g, uidx); } @@ -1403,7 +1405,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.s); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); - filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, &uidx); + filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, + &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } @@ -1411,11 +1414,12 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.e); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); - filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &left, &right, &uidx); + filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, + &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } - assert (g->unitNum > 0); + assert(g->unitNum > 0); taosArrayPush(res, g); @@ -1427,24 +1431,22 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan return TSDB_CODE_SUCCESS; } - static void filterFreeGroup(void *pItem) { if (pItem == NULL) { return; } - SFilterGroup* p = (SFilterGroup*) pItem; + SFilterGroup *p = (SFilterGroup *)pItem; taosMemoryFreeClear(p->unitIdxs); taosMemoryFreeClear(p->unitFlags); } - -EDealRes fltTreeToGroup(SNode* pNode, void* pContext) { - int32_t code = TSDB_CODE_SUCCESS; - SArray* preGroup = NULL; - SArray* newGroup = NULL; - SArray* resGroup = NULL; - ENodeType nType = nodeType(pNode); +EDealRes fltTreeToGroup(SNode *pNode, void *pContext) { + int32_t code = TSDB_CODE_SUCCESS; + SArray *preGroup = NULL; + SArray *newGroup = NULL; + SArray *resGroup = NULL; + ENodeType nType = nodeType(pNode); SFltBuildGroupCtx *ctx = (SFltBuildGroupCtx *)pContext; if (QUERY_NODE_LOGIC_CONDITION == nodeType(pNode)) { @@ -1527,24 +1529,24 @@ int32_t fltConverToStr(char *str, int type, void *buf, int32_t bufSize, int32_t break; case TSDB_DATA_TYPE_BOOL: - n = sprintf(str, (*(int8_t*)buf) ? "true" : "false"); + n = sprintf(str, (*(int8_t *)buf) ? "true" : "false"); break; case TSDB_DATA_TYPE_TINYINT: - n = sprintf(str, "%d", *(int8_t*)buf); + n = sprintf(str, "%d", *(int8_t *)buf); break; case TSDB_DATA_TYPE_SMALLINT: - n = sprintf(str, "%d", *(int16_t*)buf); + n = sprintf(str, "%d", *(int16_t *)buf); break; case TSDB_DATA_TYPE_INT: - n = sprintf(str, "%d", *(int32_t*)buf); + n = sprintf(str, "%d", *(int32_t *)buf); break; case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: - n = sprintf(str, "%" PRId64, *(int64_t*)buf); + n = sprintf(str, "%" PRId64, *(int64_t *)buf); break; case TSDB_DATA_TYPE_FLOAT: @@ -1558,7 +1560,7 @@ int32_t fltConverToStr(char *str, int type, void *buf, int32_t bufSize, int32_t case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: if (bufSize < 0) { -// tscError("invalid buf size"); + // tscError("invalid buf size"); return TSDB_CODE_TSC_INVALID_VALUE; } @@ -1569,23 +1571,23 @@ int32_t fltConverToStr(char *str, int type, void *buf, int32_t bufSize, int32_t break; case TSDB_DATA_TYPE_UTINYINT: - n = sprintf(str, "%d", *(uint8_t*)buf); + n = sprintf(str, "%d", *(uint8_t *)buf); break; case TSDB_DATA_TYPE_USMALLINT: - n = sprintf(str, "%d", *(uint16_t*)buf); + n = sprintf(str, "%d", *(uint16_t *)buf); break; case TSDB_DATA_TYPE_UINT: - n = sprintf(str, "%u", *(uint32_t*)buf); + n = sprintf(str, "%u", *(uint32_t *)buf); break; case TSDB_DATA_TYPE_UBIGINT: - n = sprintf(str, "%" PRIu64, *(uint64_t*)buf); + n = sprintf(str, "%" PRIu64, *(uint64_t *)buf); break; default: -// tscError("unsupported type:%d", type); + // tscError("unsupported type:%d", type); return TSDB_CODE_TSC_INVALID_VALUE; } @@ -1606,7 +1608,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) qDebug("COLUMN Field Num:%u", info->fields[FLD_TYPE_COLUMN].num); for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { SFilterField *field = &info->fields[FLD_TYPE_COLUMN].fields[i]; - SColumnNode *refNode = (SColumnNode *)field->desc; + SColumnNode *refNode = (SColumnNode *)field->desc; qDebug("COL%d => [%d][%d]", i, refNode->dataBlockId, refNode->slotId); } @@ -1615,39 +1617,41 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) SFilterField *field = &info->fields[FLD_TYPE_VALUE].fields[i]; if (field->desc) { if (QUERY_NODE_VALUE != nodeType(field->desc)) { - qDebug("VAL%d => [type:not value node][val:NIL]", i); //TODO + qDebug("VAL%d => [type:not value node][val:NIL]", i); // TODO continue; } SValueNode *var = (SValueNode *)field->desc; - SDataType *dType = &var->node.resType; + SDataType *dType = &var->node.resType; if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { - qDebug("VAL%d => [type:TS][val:[%" PRIi64"] - [%" PRId64 "]]", i, *(int64_t *)field->data, *(((int64_t *)field->data) + 1)); + qDebug("VAL%d => [type:TS][val:[%" PRIi64 "] - [%" PRId64 "]]", i, *(int64_t *)field->data, + *(((int64_t *)field->data) + 1)); } else { - qDebug("VAL%d => [type:%d][val:%" PRIx64"]", i, dType->type, var->datum.i); //TODO + qDebug("VAL%d => [type:%d][val:%" PRIx64 "]", i, dType->type, var->datum.i); // TODO } } else if (field->data) { - qDebug("VAL%d => [type:NIL][val:NIL]", i); //TODO + qDebug("VAL%d => [type:NIL][val:NIL]", i); // TODO } } qDebug("UNIT Num:%u", info->unitNum); for (uint32_t i = 0; i < info->unitNum; ++i) { SFilterUnit *unit = &info->units[i]; - int32_t type = FILTER_UNIT_DATA_TYPE(unit); - int32_t len = 0; - int32_t tlen = 0; - char str[512] = {0}; + int32_t type = FILTER_UNIT_DATA_TYPE(unit); + int32_t len = 0; + int32_t tlen = 0; + char str[512] = {0}; SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); - SColumnNode *refNode = (SColumnNode *)left->desc; - if (unit->compare.optr >= 0 && unit->compare.optr <= OP_TYPE_JSON_CONTAINS){ - len = sprintf(str, "UNIT[%d] => [%d][%d] %s [", i, refNode->dataBlockId, refNode->slotId, operatorTypeStr(unit->compare.optr)); + SColumnNode *refNode = (SColumnNode *)left->desc; + if (unit->compare.optr >= 0 && unit->compare.optr <= OP_TYPE_JSON_CONTAINS) { + len = sprintf(str, "UNIT[%d] => [%d][%d] %s [", i, refNode->dataBlockId, refNode->slotId, + operatorTypeStr(unit->compare.optr)); } if (unit->right.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) { SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); - char *data = right->data; + char *data = right->data; if (IS_VAR_DATA_TYPE(type)) { tlen = varDataLen(data); data += VARSTR_HEADER_SIZE; @@ -1660,13 +1664,14 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) if (unit->compare.optr2) { strcat(str, " && "); - if (unit->compare.optr2 >= 0 && unit->compare.optr2 <= OP_TYPE_JSON_CONTAINS){ - sprintf(str + strlen(str), "[%d][%d] %s [", refNode->dataBlockId, refNode->slotId, operatorTypeStr(unit->compare.optr2)); + if (unit->compare.optr2 >= 0 && unit->compare.optr2 <= OP_TYPE_JSON_CONTAINS) { + sprintf(str + strlen(str), "[%d][%d] %s [", refNode->dataBlockId, refNode->slotId, + operatorTypeStr(unit->compare.optr2)); } if (unit->right2.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) { SFilterField *right = FILTER_UNIT_RIGHT2_FIELD(info, unit); - char *data = right->data; + char *data = right->data; if (IS_VAR_DATA_TYPE(type)) { tlen = varDataLen(data); data += VARSTR_HEADER_SIZE; @@ -1678,7 +1683,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) strcat(str, "]"); } - qDebug("%s", str); //TODO + qDebug("%s", str); // TODO } qDebug("GROUP Num:%u", info->groupNum); @@ -1700,26 +1705,27 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) qDebug("RANGE Num:%u", info->colRangeNum); for (uint32_t i = 0; i < info->colRangeNum; ++i) { SFilterRangeCtx *ctx = info->colRange[i]; - qDebug("Column ID[%d] RANGE: isnull[%d],notnull[%d],range[%d]", ctx->colId, ctx->isnull, ctx->notnull, ctx->isrange); + qDebug("Column ID[%d] RANGE: isnull[%d],notnull[%d],range[%d]", ctx->colId, ctx->isnull, ctx->notnull, + ctx->isrange); if (ctx->isrange) { SFilterRangeNode *r = ctx->rs; while (r) { - char str[256] = {0}; + char str[256] = {0}; int32_t tlen = 0; if (FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) { - strcat(str,"(NULL)"); + strcat(str, "(NULL)"); } else { - FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); + FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? strcat(str, "(") : strcat(str, "["); fltConverToStr(str + strlen(str), ctx->type, &r->ra.s, tlen > 32 ? 32 : tlen, &tlen); - FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); + FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? strcat(str, ")") : strcat(str, "]"); } strcat(str, " - "); if (FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL)) { strcat(str, "(NULL)"); } else { - FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); + FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? strcat(str, "(") : strcat(str, "["); fltConverToStr(str + strlen(str), ctx->type, &r->ra.e, tlen > 32 ? 32 : tlen, &tlen); - FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); + FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? strcat(str, ")") : strcat(str, "]"); } qDebug("range: %s", str); @@ -1739,7 +1745,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) } else if (FILTER_GET_FLAG(info->blkFlag, FI_STATUS_BLK_EMPTY)) { qDebug("Flag:%s", "EMPTY"); return; - } else if (FILTER_GET_FLAG(info->blkFlag, FI_STATUS_BLK_ACTIVE)){ + } else if (FILTER_GET_FLAG(info->blkFlag, FI_STATUS_BLK_ACTIVE)) { qDebug("Flag:%s", "ACTIVE"); } @@ -1756,36 +1762,35 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) } void filterFreeColInfo(void *data) { - SFilterColInfo* info = (SFilterColInfo *)data; + SFilterColInfo *info = (SFilterColInfo *)data; if (info->info == NULL) { return; } if (info->type == RANGE_TYPE_VAR_HASH) { - //TODO + // TODO } else if (info->type == RANGE_TYPE_MR_CTX) { filterFreeRangeCtx(info->info); } else if (info->type == RANGE_TYPE_UNIT) { taosArrayDestroy((SArray *)info->info); } - //NO NEED TO FREE UNIT + // NO NEED TO FREE UNIT info->type = 0; info->info = NULL; } void filterFreeColCtx(void *data) { - SFilterColCtx* ctx = (SFilterColCtx *)data; + SFilterColCtx *ctx = (SFilterColCtx *)data; if (ctx->ctx) { filterFreeRangeCtx(ctx->ctx); } } - -void filterFreeGroupCtx(SFilterGroupCtx* gRes) { +void filterFreeGroupCtx(SFilterGroupCtx *gRes) { if (gRes == NULL) { return; } @@ -1807,7 +1812,7 @@ void filterFreeGroupCtx(SFilterGroupCtx* gRes) { taosMemoryFreeClear(gRes); } -void filterFreeField(SFilterField* field, int32_t type) { +void filterFreeField(SFilterField *field, int32_t type) { if (field == NULL) { return; } @@ -1868,7 +1873,7 @@ void filterFreeInfo(SFilterInfo *info) { } } -int32_t filterHandleValueExtInfo(SFilterUnit* unit, char extInfo) { +int32_t filterHandleValueExtInfo(SFilterUnit *unit, char extInfo) { assert(extInfo > 0 || extInfo < 0); uint8_t optr = FILTER_UNIT_OPTR(unit); @@ -1891,24 +1896,23 @@ int32_t filterHandleValueExtInfo(SFilterUnit* unit, char extInfo) { return TSDB_CODE_SUCCESS; } - int32_t fltInitValFieldData(SFilterInfo *info) { for (uint32_t i = 0; i < info->unitNum; ++i) { - SFilterUnit* unit = &info->units[i]; + SFilterUnit *unit = &info->units[i]; if (unit->right.type != FLD_TYPE_VALUE) { assert(unit->compare.optr == FILTER_DUMMY_EMPTY_OPTR || scalarGetOperatorParamNum(unit->compare.optr) == 1); continue; } - SFilterField* right = FILTER_UNIT_RIGHT_FIELD(info, unit); + SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); assert(FILTER_GET_FLAG(right->flag, FLD_TYPE_VALUE)); - uint32_t type = FILTER_UNIT_DATA_TYPE(unit); - int8_t precision = FILTER_UNIT_DATA_PRECISION(unit); - SFilterField* fi = right; + uint32_t type = FILTER_UNIT_DATA_TYPE(unit); + int8_t precision = FILTER_UNIT_DATA_PRECISION(unit); + SFilterField *fi = right; - SValueNode* var = (SValueNode *)fi->desc; + SValueNode *var = (SValueNode *)fi->desc; if (var == NULL) { assert(fi->data != NULL); continue; @@ -1927,27 +1931,29 @@ int32_t fltInitValFieldData(SFilterInfo *info) { } SDataType *dType = &var->node.resType; - size_t bytes = 0; + size_t bytes = 0; if (type == TSDB_DATA_TYPE_BINARY) { - size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; + size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes + : MAX_NUM_STR_SIZE; bytes = len + 1 + VARSTR_HEADER_SIZE; fi->data = taosMemoryCalloc(1, bytes); } else if (type == TSDB_DATA_TYPE_NCHAR) { - size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; + size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes + : MAX_NUM_STR_SIZE; bytes = (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; fi->data = taosMemoryCalloc(1, bytes); } else { - if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { //TIME RANGE -/* - fi->data = taosMemoryCalloc(dType->bytes, tDataTypes[type].bytes); - for (int32_t a = 0; a < dType->bytes; ++a) { - int64_t *v = taosArrayGet(var->arr, a); - assignVal((char *)fi->data + a * tDataTypes[type].bytes, (char *)v, 0, type); - } -*/ + if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { // TIME RANGE + /* + fi->data = taosMemoryCalloc(dType->bytes, tDataTypes[type].bytes); + for (int32_t a = 0; a < dType->bytes; ++a) { + int64_t *v = taosArrayGet(var->arr, a); + assignVal((char *)fi->data + a * tDataTypes[type].bytes, (char *)v, 0, type); + } + */ continue; } else { fi->data = taosMemoryCalloc(1, sizeof(int64_t)); @@ -1967,7 +1973,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) { } // todo refactor the convert - int32_t code = doConvertDataType(var, &out, NULL); + int32_t code = sclConvertValueToSclParam(var, &out, NULL); if (code != TSDB_CODE_SUCCESS) { qError("convert value to type[%d] failed", type); return TSDB_CODE_TSC_INVALID_OPERATION; @@ -1979,11 +1985,10 @@ int32_t fltInitValFieldData(SFilterInfo *info) { } // match/nmatch for nchar type need convert from ucs4 to mbs - if(type == TSDB_DATA_TYPE_NCHAR && - (unit->compare.optr == OP_TYPE_MATCH || unit->compare.optr == OP_TYPE_NMATCH)){ - char newValData[TSDB_REGEX_STRING_DEFAULT_LEN * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE] = {0}; - int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(fi->data), varDataLen(fi->data), varDataVal(newValData)); - if (len < 0){ + if (type == TSDB_DATA_TYPE_NCHAR && (unit->compare.optr == OP_TYPE_MATCH || unit->compare.optr == OP_TYPE_NMATCH)) { + char newValData[TSDB_REGEX_STRING_DEFAULT_LEN * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE] = {0}; + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(fi->data), varDataLen(fi->data), varDataVal(newValData)); + if (len < 0) { qError("filterInitValFieldData taosUcs4ToMbs error 1"); return TSDB_CODE_QRY_APP_ERROR; } @@ -1995,7 +2000,6 @@ int32_t fltInitValFieldData(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } - bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right) { int32_t ret = func(left, right); @@ -2044,13 +2048,12 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right) return true; } - -int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRangeCtx *ctx, int32_t optr) { - int32_t type = FILTER_UNIT_DATA_TYPE(u); - uint8_t uoptr = FILTER_UNIT_OPTR(u); - void *val = FILTER_UNIT_VAL_DATA(info, u); +int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit *u, SFilterRangeCtx *ctx, int32_t optr) { + int32_t type = FILTER_UNIT_DATA_TYPE(u); + uint8_t uoptr = FILTER_UNIT_OPTR(u); + void *val = FILTER_UNIT_VAL_DATA(info, u); SFilterRange ra = {0}; - int64_t tmp = 0; + int64_t tmp = 0; switch (uoptr) { case OP_TYPE_GREATER_THAN: @@ -2125,16 +2128,15 @@ _return: return TSDB_CODE_SUCCESS; } - -int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint32_t colIdx, bool *empty) { - SArray* colArray = (SArray *)gRes->colInfo[colIdx].info; - int32_t size = (int32_t)taosArrayGetSize(colArray); - int32_t type = gRes->colInfo[colIdx].dataType; - SFilterRangeCtx* ctx = filterInitRangeCtx(type, 0); +int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx *gRes, uint32_t colIdx, bool *empty) { + SArray *colArray = (SArray *)gRes->colInfo[colIdx].info; + int32_t size = (int32_t)taosArrayGetSize(colArray); + int32_t type = gRes->colInfo[colIdx].dataType; + SFilterRangeCtx *ctx = filterInitRangeCtx(type, 0); for (uint32_t i = 0; i < size; ++i) { - SFilterUnit* u = taosArrayGetP(colArray, i); - uint8_t optr = FILTER_UNIT_OPTR(u); + SFilterUnit *u = taosArrayGetP(colArray, i); + uint8_t optr = FILTER_UNIT_OPTR(u); filterAddRangeOptr(ctx, optr, LOGIC_COND_TYPE_AND, empty, NULL); FLT_CHK_JMP(*empty); @@ -2143,7 +2145,7 @@ int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint32_t colI filterAddUnitRange(info, u, ctx, LOGIC_COND_TYPE_AND); FLT_CHK_JMP(MR_EMPTY_RES(ctx)); } - if(FILTER_UNIT_OPTR(u) == OP_TYPE_EQUAL && !FILTER_NO_MERGE_DATA_TYPE(FILTER_UNIT_DATA_TYPE(u))){ + if (FILTER_UNIT_OPTR(u) == OP_TYPE_EQUAL && !FILTER_NO_MERGE_DATA_TYPE(FILTER_UNIT_DATA_TYPE(u))) { gRes->colInfo[colIdx].optr = OP_TYPE_EQUAL; SIMPLE_COPY_VALUES(&gRes->colInfo[colIdx].value, FILTER_UNIT_VAL_DATA(info, u)); } @@ -2164,15 +2166,14 @@ _return: return TSDB_CODE_SUCCESS; } - -int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t* gResNum) { - bool empty = false; +int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t *gResNum) { + bool empty = false; uint32_t *colIdx = taosMemoryMalloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint32_t)); - uint32_t colIdxi = 0; - uint32_t gResIdx = 0; + uint32_t colIdxi = 0; + uint32_t gResIdx = 0; for (uint32_t i = 0; i < info->groupNum; ++i) { - SFilterGroup* g = info->groups + i; + SFilterGroup *g = info->groups + i; gRes[gResIdx] = taosMemoryCalloc(1, sizeof(SFilterGroupCtx)); gRes[gResIdx]->colInfo = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo)); @@ -2180,8 +2181,8 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t empty = false; for (uint32_t j = 0; j < g->unitNum; ++j) { - SFilterUnit* u = FILTER_GROUP_UNIT(info, g, j); - uint32_t cidx = FILTER_UNIT_COL_IDX(u); + SFilterUnit *u = FILTER_GROUP_UNIT(info, g, j); + uint32_t cidx = FILTER_UNIT_COL_IDX(u); if (gRes[gResIdx]->colInfo[cidx].info == NULL) { gRes[gResIdx]->colInfo[cidx].info = (SArray *)taosArrayInit(4, POINTER_BYTES); @@ -2238,33 +2239,33 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t return TSDB_CODE_SUCCESS; } -bool filterIsSameUnits(SFilterColInfo* pCol1, SFilterColInfo* pCol2) { +bool filterIsSameUnits(SFilterColInfo *pCol1, SFilterColInfo *pCol2) { if (pCol1->type != pCol2->type) { return false; } if (RANGE_TYPE_MR_CTX == pCol1->type) { - SFilterRangeCtx* pCtx1 = (SFilterRangeCtx*)pCol1->info; - SFilterRangeCtx* pCtx2 = (SFilterRangeCtx*)pCol2->info; + SFilterRangeCtx *pCtx1 = (SFilterRangeCtx *)pCol1->info; + SFilterRangeCtx *pCtx2 = (SFilterRangeCtx *)pCol2->info; if ((pCtx1->isnull != pCtx2->isnull) || (pCtx1->notnull != pCtx2->notnull) || (pCtx1->isrange != pCtx2->isrange)) { return false; } - - SFilterRangeNode* pNode1 = pCtx1->rs; - SFilterRangeNode* pNode2 = pCtx2->rs; + SFilterRangeNode *pNode1 = pCtx1->rs; + SFilterRangeNode *pNode2 = pCtx2->rs; while (true) { if (NULL == pNode1 && NULL == pNode2) { break; } - + if (NULL == pNode1 || NULL == pNode2) { return false; } - if (pNode1->ra.s != pNode2->ra.s || pNode1->ra.e != pNode2->ra.e || pNode1->ra.sflag != pNode2->ra.sflag || pNode1->ra.eflag != pNode2->ra.eflag) { + if (pNode1->ra.s != pNode2->ra.s || pNode1->ra.e != pNode2->ra.e || pNode1->ra.sflag != pNode2->ra.sflag || + pNode1->ra.eflag != pNode2->ra.eflag) { return false; } @@ -2276,9 +2277,9 @@ bool filterIsSameUnits(SFilterColInfo* pCol1, SFilterColInfo* pCol2) { return true; } -void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *conflict) { +void filterCheckColConflict(SFilterGroupCtx *gRes1, SFilterGroupCtx *gRes2, bool *conflict) { uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0; - bool equal = false; + bool equal = false; for (; m < gRes1->colNum; ++m) { idx1 = gRes1->colIdx[m]; @@ -2308,8 +2309,8 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool // for long in operation if (gRes1->colInfo[idx1].optr == OP_TYPE_EQUAL && gRes2->colInfo[idx2].optr == OP_TYPE_EQUAL) { - SFilterRangeCtx* ctx = gRes1->colInfo[idx1].info; - if (ctx->pCompareFunc(&gRes1->colInfo[idx1].value, &gRes2->colInfo[idx2].value)){ + SFilterRangeCtx *ctx = gRes1->colInfo[idx1].info; + if (ctx->pCompareFunc(&gRes1->colInfo[idx1].value, &gRes2->colInfo[idx2].value)) { *conflict = true; return; } @@ -2330,10 +2331,10 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool return; } - -int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32_t optr, uint32_t cidx, SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *empty, bool *all) { +int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32_t optr, uint32_t cidx, + SFilterGroupCtx *gRes1, SFilterGroupCtx *gRes2, bool *empty, bool *all) { SFilterField *fi = FILTER_GET_COL_FIELD(info, cidx); - int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); + int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); if ((*ctx) == NULL) { *ctx = filterInitRangeCtx(type, 0); @@ -2350,8 +2351,7 @@ int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32 return TSDB_CODE_SUCCESS; } - -int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilterGroupCtx** gRes2, bool *all) { +int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx **gRes1, SFilterGroupCtx **gRes2, bool *all) { bool conflict = false; filterCheckColConflict(*gRes1, *gRes2, &conflict); @@ -2361,13 +2361,13 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE); - uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0; - bool numEqual = (*gRes1)->colNum == (*gRes2)->colNum; - bool equal = false; - uint32_t equal1 = 0, equal2 = 0, merNum = 0; + uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0; + bool numEqual = (*gRes1)->colNum == (*gRes2)->colNum; + bool equal = false; + uint32_t equal1 = 0, equal2 = 0, merNum = 0; SFilterRangeCtx *ctx = NULL; - SFilterColCtx colCtx = {0}; - SArray* colCtxs = taosArrayInit((*gRes2)->colNum, sizeof(SFilterColCtx)); + SFilterColCtx colCtx = {0}; + SArray *colCtxs = taosArrayInit((*gRes2)->colNum, sizeof(SFilterColCtx)); for (; m < (*gRes1)->colNum; ++m) { idx1 = (*gRes1)->colIdx[m]; @@ -2432,14 +2432,14 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter assert(merNum > 0); SFilterColInfo *colInfo = NULL; - assert (merNum == equal1 || merNum == equal2); + assert(merNum == equal1 || merNum == equal2); filterFreeGroupCtx(*gRes2); *gRes2 = NULL; assert(colCtxs && taosArrayGetSize(colCtxs) > 0); - int32_t ctxSize = (int32_t)taosArrayGetSize(colCtxs); + int32_t ctxSize = (int32_t)taosArrayGetSize(colCtxs); SFilterColCtx *pctx = NULL; for (int32_t i = 0; i < ctxSize; ++i) { @@ -2469,18 +2469,17 @@ _return: return TSDB_CODE_SUCCESS; } - -int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gResNum) { +int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t *gResNum) { if (*gResNum <= 1) { return TSDB_CODE_SUCCESS; } taosSort(gRes, *gResNum, POINTER_BYTES, filterCompareGroupCtx); - int32_t pEnd = 0, cStart = 0, cEnd = 0; + int32_t pEnd = 0, cStart = 0, cEnd = 0; uint32_t pColNum = 0, cColNum = 0; - int32_t movedNum = 0; - bool all = false; + int32_t movedNum = 0; + bool all = false; cColNum = gRes[0]->colNum; @@ -2502,7 +2501,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR if (gRes[n] == NULL) { if (n < ((*gResNum) - 1)) { - memmove(&gRes[n], &gRes[n+1], (*gResNum-n-1) * POINTER_BYTES); + memmove(&gRes[n], &gRes[n + 1], (*gResNum - n - 1) * POINTER_BYTES); } --cEnd; @@ -2523,7 +2522,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR if (gRes[n] == NULL) { if (n < ((*gResNum) - 1)) { - memmove(&gRes[n], &gRes[n+1], (*gResNum-n-1) * POINTER_BYTES); + memmove(&gRes[n], &gRes[n + 1], (*gResNum - n - 1) * POINTER_BYTES); } --cEnd; @@ -2556,7 +2555,7 @@ _return: return TSDB_CODE_SUCCESS; } -int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) { +int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray *group) { size_t groupSize = taosArrayGetSize(group); info->groupNum = (uint32_t)groupSize; @@ -2574,7 +2573,7 @@ int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) { return TSDB_CODE_SUCCESS; } -int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum) { +int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t gResNum) { if (!FILTER_GET_FLAG(info->status, FI_STATUS_REWRITE)) { qDebug("no need rewrite"); return TSDB_CODE_SUCCESS; @@ -2584,11 +2583,11 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum FILTER_SET_FLAG(oinfo.status, FI_STATUS_CLONED); - SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); + SArray *group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); SFilterGroupCtx *res = NULL; - SFilterColInfo *colInfo = NULL; - int32_t optr = 0; - uint32_t uidx = 0; + SFilterColInfo *colInfo = NULL; + int32_t optr = 0; + uint32_t uidx = 0; memset(info, 0, sizeof(*info)); @@ -2615,7 +2614,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum int32_t usize = (int32_t)taosArrayGetSize((SArray *)colInfo->info); for (int32_t n = 0; n < usize; ++n) { - SFilterUnit* u = taosArrayGetP((SArray *)colInfo->info, n); + SFilterUnit *u = taosArrayGetP((SArray *)colInfo->info, n); filterAddUnitFromUnit(info, &oinfo, u, &uidx); filterAddUnitToGroup(&ng, uidx); @@ -2643,15 +2642,15 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum return TSDB_CODE_SUCCESS; } -int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum) { - uint32_t *idxs = NULL; - uint32_t colNum = 0; +int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t gResNum) { + uint32_t *idxs = NULL; + uint32_t colNum = 0; SFilterGroupCtx *res = NULL; - uint32_t *idxNum = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxNum)); + uint32_t *idxNum = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxNum)); for (int32_t i = 0; i < gResNum; ++i) { for (uint32_t m = 0; m < gRes[i]->colNum; ++m) { - SFilterColInfo *colInfo = &gRes[i]->colInfo[gRes[i]->colIdx[m]]; + SFilterColInfo *colInfo = &gRes[i]->colInfo[gRes[i]->colIdx[m]]; if (FILTER_NO_MERGE_DATA_TYPE(colInfo->dataType)) { continue; } @@ -2691,10 +2690,10 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ assert(res->colIdx[n] == idxs[m]); - SFilterColInfo * colInfo = &res->colInfo[res->colIdx[n]]; + SFilterColInfo *colInfo = &res->colInfo[res->colIdx[n]]; if (info->colRange[m] == NULL) { info->colRange[m] = filterInitRangeCtx(colInfo->dataType, 0); - SFilterField* fi = FILTER_GET_COL_FIELD(info, res->colIdx[n]); + SFilterField *fi = FILTER_GET_COL_FIELD(info, res->colIdx[n]); info->colRange[m]->colId = FILTER_GET_COL_FIELD_ID(fi); } @@ -2732,7 +2731,7 @@ _return: int32_t filterPostProcessRange(SFilterInfo *info) { for (uint32_t i = 0; i < info->colRangeNum; ++i) { - SFilterRangeCtx* ctx = info->colRange[i]; + SFilterRangeCtx *ctx = info->colRange[i]; SFilterRangeNode *r = ctx->rs; while (r) { r->rc.func = filterGetRangeCompFunc(r->ra.sflag, r->ra.eflag); @@ -2743,7 +2742,6 @@ int32_t filterPostProcessRange(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } - int32_t filterGenerateComInfo(SFilterInfo *info) { info->cunits = taosMemoryMalloc(info->unitNum * sizeof(*info->cunits)); info->blkUnitRes = taosMemoryMalloc(sizeof(*info->blkUnitRes) * info->unitNum); @@ -2787,21 +2785,20 @@ int32_t filterUpdateComUnits(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } - int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows) { int32_t rmUnit = 0; memset(info->blkUnitRes, 0, sizeof(*info->blkUnitRes) * info->unitNum); for (uint32_t k = 0; k < info->unitNum; ++k) { - int32_t index = -1; + int32_t index = -1; SFilterComUnit *cunit = &info->cunits[k]; if (FILTER_NO_MERGE_DATA_TYPE(cunit->dataType)) { continue; } - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { if (pDataStatis[i].colId == cunit->colId) { index = i; break; @@ -2838,16 +2835,15 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 } } - if (cunit->optr == OP_TYPE_IS_NULL || cunit->optr == OP_TYPE_IS_NOT_NULL - || cunit->optr == OP_TYPE_IN || cunit->optr == OP_TYPE_LIKE || cunit->optr == OP_TYPE_MATCH - || cunit->optr == OP_TYPE_NOT_EQUAL) { + if (cunit->optr == OP_TYPE_IS_NULL || cunit->optr == OP_TYPE_IS_NOT_NULL || cunit->optr == OP_TYPE_IN || + cunit->optr == OP_TYPE_LIKE || cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NOT_EQUAL) { continue; } - SColumnDataAgg* pDataBlockst = &pDataStatis[index]; - void *minVal, *maxVal; - float minv = 0; - float maxv = 0; + SColumnDataAgg *pDataBlockst = &pDataStatis[index]; + void *minVal, *maxVal; + float minv = 0; + float maxv = 0; if (cunit->dataType == TSDB_DATA_TYPE_FLOAT) { minv = (float)(*(double *)(&pDataBlockst->min)); @@ -2863,8 +2859,10 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 bool minRes = false, maxRes = false; if (cunit->rfunc >= 0) { - minRes = (*gRangeCompare[cunit->rfunc])(minVal, minVal, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); - maxRes = (*gRangeCompare[cunit->rfunc])(maxVal, maxVal, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); + minRes = + (*gRangeCompare[cunit->rfunc])(minVal, minVal, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); + maxRes = + (*gRangeCompare[cunit->rfunc])(maxVal, maxVal, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); if (minRes && maxRes) { info->blkUnitRes[k] = 1; @@ -2903,7 +2901,6 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 rmUnit = 1; } } - } if (rmUnit == 0) { @@ -2915,7 +2912,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 uint32_t *unitNum = info->blkUnits; uint32_t *unitIdx = unitNum + 1; - int32_t all = 0, empty = 0; + int32_t all = 0, empty = 0; for (uint32_t g = 0; g < info->groupNum; ++g) { SFilterGroup *group = &info->groups[g]; @@ -2925,7 +2922,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 empty = 0; // save group idx start pointer - uint32_t * pGroupIdx = unitIdx; + uint32_t *pGroupIdx = unitIdx; for (uint32_t u = 0; u < group->unitNum; ++u) { uint32_t uidx = group->unitIdxs[u]; if (info->blkUnitRes[uidx] == 1) { @@ -2976,15 +2973,16 @@ _return: return TSDB_CODE_SUCCESS; } -bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoData* pRes, SColumnDataAgg *statis, int16_t numOfCols) { +bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis, + int16_t numOfCols) { SFilterInfo *info = (SFilterInfo *)pinfo; - bool all = true; - uint32_t *unitIdx = NULL; + bool all = true; + uint32_t *unitIdx = NULL; - int8_t* p = (int8_t*)pRes->pData; + int8_t *p = (int8_t *)pRes->pData; for (int32_t i = 0; i < numOfRows; ++i) { - //FILTER_UNIT_CLR_F(info); + // FILTER_UNIT_CLR_F(info); unitIdx = info->blkUnits; @@ -2992,30 +2990,31 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD uint32_t unitNum = *(unitIdx++); for (uint32_t u = 0; u < unitNum; ++u) { SFilterComUnit *cunit = &info->cunits[*(unitIdx + u)]; - void *colData = colDataGetData((SColumnInfoData *)cunit->colData, i); + void *colData = colDataGetData((SColumnInfoData *)cunit->colData, i); - //if (FILTER_UNIT_GET_F(info, uidx)) { - // p[i] = FILTER_UNIT_GET_R(info, uidx); - //} else { - uint8_t optr = cunit->optr; + // if (FILTER_UNIT_GET_F(info, uidx)) { + // p[i] = FILTER_UNIT_GET_R(info, uidx); + // } else { + uint8_t optr = cunit->optr; - if (colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) { - p[i] = (optr == OP_TYPE_IS_NULL) ? true : false; + if (colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) { + p[i] = (optr == OP_TYPE_IS_NULL) ? true : false; + } else { + if (optr == OP_TYPE_IS_NOT_NULL) { + p[i] = 1; + } else if (optr == OP_TYPE_IS_NULL) { + p[i] = 0; + } else if (cunit->rfunc >= 0) { + p[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, + gDataCompare[cunit->func]); } else { - if (optr == OP_TYPE_IS_NOT_NULL) { - p[i] = 1; - } else if (optr == OP_TYPE_IS_NULL) { - p[i] = 0; - } else if (cunit->rfunc >= 0) { - p[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); - } else { - p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); - } - - //FILTER_UNIT_SET_R(info, uidx, p[i]); - //FILTER_UNIT_SET_F(info, uidx); + p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); } + // FILTER_UNIT_SET_R(info, uidx, p[i]); + // FILTER_UNIT_SET_F(info, uidx); + } + if (p[i] == 0) { break; } @@ -3036,9 +3035,8 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, SColumnInfoD return all; } - - -int32_t filterExecuteBasedOnStatis(SFilterInfo *info, int32_t numOfRows, SColumnInfoData* p, SColumnDataAgg *statis, int16_t numOfCols, bool* all) { +int32_t filterExecuteBasedOnStatis(SFilterInfo *info, int32_t numOfRows, SColumnInfoData *p, SColumnDataAgg *statis, + int16_t numOfCols, bool *all) { if (statis && numOfRows >= FILTER_RM_UNIT_MIN_ROWS) { info->blkFlag = 0; @@ -3067,20 +3065,22 @@ _return: return TSDB_CODE_SUCCESS; } -static FORCE_INLINE bool filterExecuteImplAll(void *info, int32_t numOfRows, SColumnInfoData* p, SColumnDataAgg *statis, int16_t numOfCols, int32_t* numOfQualified) { +static FORCE_INLINE bool filterExecuteImplAll(void *info, int32_t numOfRows, SColumnInfoData *p, SColumnDataAgg *statis, + int16_t numOfCols, int32_t *numOfQualified) { return true; } -static FORCE_INLINE bool filterExecuteImplEmpty(void *info, int32_t numOfRows, SColumnInfoData* p, SColumnDataAgg *statis, int16_t numOfCols, int32_t* numOfQualified) { +static FORCE_INLINE bool filterExecuteImplEmpty(void *info, int32_t numOfRows, SColumnInfoData *p, + SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) { return false; } static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) { SFilterInfo *info = (SFilterInfo *)pinfo; - bool all = true; + bool all = true; - int8_t* p = (int8_t*)pRes->pData; + int8_t *p = (int8_t *)pRes->pData; if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) { return all; @@ -3088,7 +3088,7 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, for (int32_t i = 0; i < numOfRows; ++i) { uint32_t uidx = info->groups[0].unitIdxs[0]; - void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); + void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); p[i] = ((colData == NULL) || colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)); if (p[i] == 0) { @@ -3104,17 +3104,17 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) { SFilterInfo *info = (SFilterInfo *)pinfo; - bool all = true; + bool all = true; if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) { return all; } - int8_t* p = (int8_t*)pRes->pData; + int8_t *p = (int8_t *)pRes->pData; for (int32_t i = 0; i < numOfRows; ++i) { uint32_t uidx = info->groups[0].unitIdxs[0]; - void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); + void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); p[i] = ((colData != NULL) && !colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)); if (p[i] == 0) { @@ -3127,23 +3127,24 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows return all; } -bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData* pRes, SColumnDataAgg *statis, int16_t numOfCols, int32_t* numOfQualified) { - SFilterInfo *info = (SFilterInfo *)pinfo; - bool all = true; - uint16_t dataSize = info->cunits[0].dataSize; +bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis, + int16_t numOfCols, int32_t *numOfQualified) { + SFilterInfo *info = (SFilterInfo *)pinfo; + bool all = true; + uint16_t dataSize = info->cunits[0].dataSize; rangeCompFunc rfunc = gRangeCompare[info->cunits[0].rfunc]; - void *valData = info->cunits[0].valData; - void *valData2 = info->cunits[0].valData2; + void *valData = info->cunits[0].valData; + void *valData2 = info->cunits[0].valData2; __compar_fn_t func = gDataCompare[info->cunits[0].func]; if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) { return all; } - int8_t* p = (int8_t*) pRes->pData; + int8_t *p = (int8_t *)pRes->pData; for (int32_t i = 0; i < numOfRows; ++i) { - SColumnInfoData* pData = info->cunits[0].colData; + SColumnInfoData *pData = info->cunits[0].colData; void *colData = colDataGetData(pData, i); if (colData == NULL || colDataIsNull_s(pData, i)) { @@ -3166,17 +3167,17 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, SColumnInfoData* pRe bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) { SFilterInfo *info = (SFilterInfo *)pinfo; - bool all = true; + bool all = true; if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) { return all; } - int8_t* p = (int8_t*) pRes->pData; + int8_t *p = (int8_t *)pRes->pData; for (int32_t i = 0; i < numOfRows; ++i) { uint32_t uidx = info->groups[0].unitIdxs[0]; - void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); + void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); if (colData == NULL || colDataIsNull_s((SColumnInfoData *)info->cunits[uidx].colData, i)) { p[i] = 0; all = false; @@ -3184,18 +3185,21 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes } // match/nmatch for nchar type need convert from ucs4 to mbs - if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_NCHAR && (info->cunits[uidx].optr == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_NMATCH)){ - char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); - int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); - if (len < 0){ + if (info->cunits[uidx].dataType == TSDB_DATA_TYPE_NCHAR && + (info->cunits[uidx].optr == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_NMATCH)) { + char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); + if (len < 0) { qError("castConvert1 taosUcs4ToMbs error"); - }else{ + } else { varDataSetLen(newColData, len); - p[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, newColData, info->cunits[uidx].valData); + p[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, newColData, + info->cunits[uidx].valData); } taosMemoryFreeClear(newColData); - }else{ - p[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, colData, info->cunits[uidx].valData); + } else { + p[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, colData, + info->cunits[uidx].valData); } if (p[i] == 0) { @@ -3211,58 +3215,60 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes bool filterExecuteImpl(void *pinfo, int32_t numOfRows, SColumnInfoData *pRes, SColumnDataAgg *statis, int16_t numOfCols, int32_t *numOfQualified) { SFilterInfo *info = (SFilterInfo *)pinfo; - bool all = true; + bool all = true; if (filterExecuteBasedOnStatis(info, numOfRows, pRes, statis, numOfCols, &all) == 0) { return all; } - int8_t* p = (int8_t*) pRes->pData; + int8_t *p = (int8_t *)pRes->pData; for (int32_t i = 0; i < numOfRows; ++i) { - //FILTER_UNIT_CLR_F(info); + // FILTER_UNIT_CLR_F(info); for (uint32_t g = 0; g < info->groupNum; ++g) { SFilterGroup *group = &info->groups[g]; for (uint32_t u = 0; u < group->unitNum; ++u) { - uint32_t uidx = group->unitIdxs[u]; + uint32_t uidx = group->unitIdxs[u]; SFilterComUnit *cunit = &info->cunits[uidx]; - void *colData = colDataGetData((SColumnInfoData *)(cunit->colData), i); + void *colData = colDataGetData((SColumnInfoData *)(cunit->colData), i); - //if (FILTER_UNIT_GET_F(info, uidx)) { - // p[i] = FILTER_UNIT_GET_R(info, uidx); - //} else { - uint8_t optr = cunit->optr; + // if (FILTER_UNIT_GET_F(info, uidx)) { + // p[i] = FILTER_UNIT_GET_R(info, uidx); + // } else { + uint8_t optr = cunit->optr; - if (colData == NULL || colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) { - p[i] = optr == OP_TYPE_IS_NULL ? true : false; + if (colData == NULL || colDataIsNull((SColumnInfoData *)(cunit->colData), 0, i, NULL)) { + p[i] = optr == OP_TYPE_IS_NULL ? true : false; + } else { + if (optr == OP_TYPE_IS_NOT_NULL) { + p[i] = 1; + } else if (optr == OP_TYPE_IS_NULL) { + p[i] = 0; + } else if (cunit->rfunc >= 0) { + p[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, + gDataCompare[cunit->func]); } else { - if (optr == OP_TYPE_IS_NOT_NULL) { - p[i] = 1; - } else if (optr == OP_TYPE_IS_NULL) { - p[i] = 0; - } else if (cunit->rfunc >= 0) { - p[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); - } else { - if(cunit->dataType == TSDB_DATA_TYPE_NCHAR && (cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)){ - char *newColData = taosMemoryCalloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); - int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); - if (len < 0){ - qError("castConvert1 taosUcs4ToMbs error"); - }else{ - varDataSetLen(newColData, len); - p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, newColData, cunit->valData); - } - taosMemoryFreeClear(newColData); - }else{ - p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); + if (cunit->dataType == TSDB_DATA_TYPE_NCHAR && + (cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)) { + char *newColData = taosMemoryCalloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); + if (len < 0) { + qError("castConvert1 taosUcs4ToMbs error"); + } else { + varDataSetLen(newColData, len); + p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, newColData, cunit->valData); } + taosMemoryFreeClear(newColData); + } else { + p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); } - - //FILTER_UNIT_SET_R(info, uidx, p[i]); - //FILTER_UNIT_SET_F(info, uidx); } + // FILTER_UNIT_SET_R(info, uidx, p[i]); + // FILTER_UNIT_SET_F(info, uidx); + } + if (p[i] == 0) { break; } @@ -3318,11 +3324,9 @@ int32_t filterSetExecFunc(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } - - int32_t filterPreprocess(SFilterInfo *info) { - SFilterGroupCtx** gRes = taosMemoryCalloc(info->groupNum, sizeof(SFilterGroupCtx *)); - int32_t gResNum = 0; + SFilterGroupCtx **gRes = taosMemoryCalloc(info->groupNum, sizeof(SFilterGroupCtx *)); + int32_t gResNum = 0; filterMergeGroupUnits(info, gRes, &gResNum); @@ -3333,7 +3337,6 @@ int32_t filterPreprocess(SFilterInfo *info) { goto _return; } - if (FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY)) { fltInfo("Final - FilterInfo: [EMPTY]"); goto _return; @@ -3362,14 +3365,13 @@ _return: return TSDB_CODE_SUCCESS; } - int32_t fltSetColFieldDataImpl(SFilterInfo *info, void *param, filer_get_col_from_id fp, bool fromColId) { if (FILTER_ALL_RES(info) || FILTER_EMPTY_RES(info)) { return TSDB_CODE_SUCCESS; } for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { - SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; + SFilterField *fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; if (fromColId) { (*fp)(param, FILTER_GET_COL_FIELD_ID(fi), &fi->data); @@ -3383,11 +3385,10 @@ int32_t fltSetColFieldDataImpl(SFilterInfo *info, void *param, filer_get_col_fro return TSDB_CODE_SUCCESS; } - -int32_t fltInitFromNode(SNode* tree, SFilterInfo *info, uint32_t options) { +int32_t fltInitFromNode(SNode *tree, SFilterInfo *info, uint32_t options) { int32_t code = TSDB_CODE_SUCCESS; - SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); + SArray *group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); filterInitUnitsFields(info); @@ -3436,13 +3437,13 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t return true; } - bool ret = true; + bool ret = true; void *minVal, *maxVal; for (uint32_t k = 0; k < info->colRangeNum; ++k) { - int32_t index = -1; + int32_t index = -1; SFilterRangeCtx *ctx = info->colRange[k]; - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { if (pDataStatis[i] != NULL && pDataStatis[i]->colId == ctx->colId) { index = i; break; @@ -3479,11 +3480,11 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t } } - SColumnDataAgg* pDataBlockst = pDataStatis[index]; + SColumnDataAgg *pDataBlockst = pDataStatis[index]; SFilterRangeNode *r = ctx->rs; - float minv = 0; - float maxv = 0; + float minv = 0; + float maxv = 0; if (ctx->type == TSDB_DATA_TYPE_FLOAT) { minv = (float)(*(double *)(&pDataBlockst->min)); @@ -3512,17 +3513,15 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg **pDataStatis, int32_t return ret; } - - -int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool *isStrict) { - SFilterRange ra = {0}; +int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool *isStrict) { + SFilterRange ra = {0}; SFilterRangeCtx *prev = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP); SFilterRangeCtx *tmpc = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP); SFilterRangeCtx *cur = NULL; - int32_t num = 0; - int32_t optr = 0; - int32_t code = 0; - bool empty = false, all = false; + int32_t num = 0; + int32_t optr = 0; + int32_t code = 0; + bool empty = false, all = false; for (uint32_t i = 0; i < info->groupNum; ++i) { SFilterGroup *group = &info->groups[i]; @@ -3535,7 +3534,7 @@ int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool * } for (uint32_t u = 0; u < group->unitNum; ++u) { - uint32_t uidx = group->unitIdxs[u]; + uint32_t uidx = group->unitIdxs[u]; SFilterUnit *unit = &info->units[uidx]; uint8_t raOptr = FILTER_UNIT_OPTR(unit); @@ -3591,7 +3590,7 @@ int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool * filterFreeRangeCtx(prev); filterFreeRangeCtx(tmpc); - qDebug("qFilter time range:[%"PRId64 "]-[%"PRId64 "]", win->skey, win->ekey); + qDebug("qFilter time range:[%" PRId64 "]-[%" PRId64 "]", win->skey, win->ekey); return TSDB_CODE_SUCCESS; _return: @@ -3601,19 +3600,18 @@ _return: filterFreeRangeCtx(prev); filterFreeRangeCtx(tmpc); - qDebug("qFilter time range:[%"PRId64 "]-[%"PRId64 "]", win->skey, win->ekey); + qDebug("qFilter time range:[%" PRId64 "]-[%" PRId64 "]", win->skey, win->ekey); return code; } - int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict) { SFilterInfo *info = NULL; - int32_t code = 0; + int32_t code = 0; *isStrict = true; - FLT_ERR_RET(filterInitFromNode(pNode, &info, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP)); + FLT_ERR_RET(filterInitFromNode(pNode, &info, FLT_OPTION_NO_REWRITE | FLT_OPTION_TIMESTAMP)); if (info->scalarMode) { *win = TSWINDOW_INITIALIZER; @@ -3630,15 +3628,14 @@ _return: FLT_RET(code); } - -int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar) { +int32_t filterConverNcharColumns(SFilterInfo *info, int32_t rows, bool *gotNchar) { if (FILTER_EMPTY_RES(info) || FILTER_ALL_RES(info)) { return TSDB_CODE_SUCCESS; } for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { - SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; - int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); + SFilterField *fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; + int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); if (type == TSDB_DATA_TYPE_NCHAR) { SFilterField nfi = {0}; nfi.desc = fi->desc; @@ -3646,20 +3643,21 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar nfi.data = taosMemoryMalloc(rows * bytes); int32_t bufSize = bytes - VARSTR_HEADER_SIZE; for (int32_t j = 0; j < rows; ++j) { - char *src = FILTER_GET_COL_FIELD_DATA(fi, j); - char *dst = FILTER_GET_COL_FIELD_DATA(&nfi, j); + char *src = FILTER_GET_COL_FIELD_DATA(fi, j); + char *dst = FILTER_GET_COL_FIELD_DATA(&nfi, j); int32_t len = 0; - char *varSrc = varDataVal(src); - size_t k = 0, varSrcLen = varDataLen(src); - while (k < varSrcLen && varSrc[k++] == -1) {} + char *varSrc = varDataVal(src); + size_t k = 0, varSrcLen = varDataLen(src); + while (k < varSrcLen && varSrc[k++] == -1) { + } if (k == varSrcLen) { /* NULL */ - varDataLen(dst) = (VarDataLenT) varSrcLen; + varDataLen(dst) = (VarDataLenT)varSrcLen; varDataCopy(dst, src); continue; } - bool ret = taosMbsToUcs4(varDataVal(src), varDataLen(src), (TdUcs4*)varDataVal(dst), bufSize, &len); - if(!ret) { + bool ret = taosMbsToUcs4(varDataVal(src), varDataLen(src), (TdUcs4 *)varDataVal(dst), bufSize, &len); + if (!ret) { qError("filterConverNcharColumns taosMbsToUcs4 error"); return TSDB_CODE_FAILED; } @@ -3679,10 +3677,10 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar return TSDB_CODE_SUCCESS; } -int32_t filterFreeNcharColumns(SFilterInfo* info) { +int32_t filterFreeNcharColumns(SFilterInfo *info) { for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { - SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; - int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); + SFilterField *fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; + int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); if (type == TSDB_DATA_TYPE_NCHAR) { taosMemoryFreeClear(fi->data); } @@ -3691,7 +3689,7 @@ int32_t filterFreeNcharColumns(SFilterInfo* info) { return TSDB_CODE_SUCCESS; } -int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode* pNode) { +int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode *pNode) { if (NULL == stat->nodeList) { stat->nodeList = taosArrayInit(10, POINTER_BYTES); if (NULL == stat->nodeList) { @@ -3706,12 +3704,12 @@ int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode* pNode) { return TSDB_CODE_SUCCESS; } -EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { +EDealRes fltReviseRewriter(SNode **pNode, void *pContext) { SFltTreeStat *stat = (SFltTreeStat *)pContext; if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pNode)) { SLogicConditionNode *node = (SLogicConditionNode *)*pNode; - SListCell *cell = node->pParameterList->pHead; + SListCell *cell = node->pParameterList->pHead; for (int32_t i = 0; i < node->pParameterList->length; ++i) { if (NULL == cell || NULL == cell->pNode) { fltError("invalid cell, cell:%p, pNode:%p", cell, cell->pNode); @@ -3777,8 +3775,8 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { } SValueNode *valueNode = (SValueNode *)listNode->pNodeList->pHead->pNode; - uint8_t type = valueNode->node.resType.type; - SNode *node = NULL; + uint8_t type = valueNode->node.resType.type; + SNode *node = NULL; FOREACH(node, listNode->pNodeList) { if (type != ((SValueNode *)node)->node.resType.type) { stat->scalarMode = true; @@ -3794,6 +3792,11 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } + if (QUERY_NODE_CASE_WHEN == nodeType(*pNode) || QUERY_NODE_WHEN_THEN == nodeType(*pNode)) { + stat->scalarMode = true; + return DEAL_RES_CONTINUE; + } + if (QUERY_NODE_OPERATOR == nodeType(*pNode)) { SOperatorNode *node = (SOperatorNode *)*pNode; if (!FLT_IS_COMPARISON_OPERATOR(node->opType)) { @@ -3801,13 +3804,14 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } - if (node->opType == OP_TYPE_NOT_IN || node->opType == OP_TYPE_NOT_LIKE || node->opType > OP_TYPE_IS_NOT_NULL || node->opType == OP_TYPE_NOT_EQUAL) { + if (node->opType == OP_TYPE_NOT_IN || node->opType == OP_TYPE_NOT_LIKE || node->opType > OP_TYPE_IS_NOT_NULL || + node->opType == OP_TYPE_NOT_EQUAL) { stat->scalarMode = true; return DEAL_RES_CONTINUE; } - if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && - (node->opType >= OP_TYPE_NOT_EQUAL) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { + if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && (node->opType >= OP_TYPE_NOT_EQUAL) && + (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { stat->scalarMode = true; return DEAL_RES_CONTINUE; } @@ -3824,8 +3828,9 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } - if (OP_TYPE_IS_TRUE == node->opType || OP_TYPE_IS_FALSE == node->opType || OP_TYPE_IS_UNKNOWN == node->opType - || OP_TYPE_IS_NOT_TRUE == node->opType || OP_TYPE_IS_NOT_FALSE == node->opType || OP_TYPE_IS_NOT_UNKNOWN == node->opType) { + if (OP_TYPE_IS_TRUE == node->opType || OP_TYPE_IS_FALSE == node->opType || OP_TYPE_IS_UNKNOWN == node->opType || + OP_TYPE_IS_NOT_TRUE == node->opType || OP_TYPE_IS_NOT_FALSE == node->opType || + OP_TYPE_IS_NOT_UNKNOWN == node->opType) { stat->scalarMode = true; return DEAL_RES_CONTINUE; } @@ -3835,7 +3840,8 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } - if ((QUERY_NODE_COLUMN != nodeType(node->pRight)) && (QUERY_NODE_VALUE != nodeType(node->pRight)) && (QUERY_NODE_NODE_LIST != nodeType(node->pRight))) { + if ((QUERY_NODE_COLUMN != nodeType(node->pRight)) && (QUERY_NODE_VALUE != nodeType(node->pRight)) && + (QUERY_NODE_NODE_LIST != nodeType(node->pRight))) { stat->scalarMode = true; return DEAL_RES_CONTINUE; } @@ -3880,9 +3886,9 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { if (OP_TYPE_IN != node->opType) { SColumnNode *refNode = (SColumnNode *)node->pLeft; - SValueNode *valueNode = (SValueNode *)node->pRight; - if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) - && TSDB_DATA_TYPE_UBIGINT == valueNode->node.resType.type && valueNode->datum.u <= INT64_MAX) { + SValueNode *valueNode = (SValueNode *)node->pRight; + if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && + TSDB_DATA_TYPE_UBIGINT == valueNode->node.resType.type && valueNode->datum.u <= INT64_MAX) { valueNode->node.resType.type = TSDB_DATA_TYPE_BIGINT; } int32_t type = vectorGetConvertType(refNode->node.resType.type, valueNode->node.resType.type); @@ -3891,9 +3897,9 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } } else { - SColumnNode *refNode = (SColumnNode *)node->pLeft; + SColumnNode *refNode = (SColumnNode *)node->pLeft; SNodeListNode *listNode = (SNodeListNode *)node->pRight; - int32_t type = vectorGetConvertType(refNode->node.resType.type, listNode->dataType.type); + int32_t type = vectorGetConvertType(refNode->node.resType.type, listNode->dataType.type); if (0 != type && type != refNode->node.resType.type) { stat->scalarMode = true; return DEAL_RES_CONTINUE; @@ -3911,7 +3917,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_ERROR; } -int32_t fltReviseNodes(SFilterInfo *pInfo, SNode** pNode, SFltTreeStat *pStat) { +int32_t fltReviseNodes(SFilterInfo *pInfo, SNode **pNode, SFltTreeStat *pStat) { int32_t code = 0; nodesRewriteExprPostOrder(pNode, fltReviseRewriter, (void *)pStat); @@ -3930,18 +3936,17 @@ _return: FLT_RET(code); } -int32_t fltOptimizeNodes(SFilterInfo *pInfo, SNode** pNode, SFltTreeStat *pStat) { - //TODO +int32_t fltOptimizeNodes(SFilterInfo *pInfo, SNode **pNode, SFltTreeStat *pStat) { + // TODO return TSDB_CODE_SUCCESS; } - int32_t fltGetDataFromColId(void *param, int32_t id, void **data) { int32_t numOfCols = ((SFilterColumnParam *)param)->numOfCols; - SArray* pDataBlock = ((SFilterColumnParam *)param)->pDataBlock; + SArray *pDataBlock = ((SFilterColumnParam *)param)->pDataBlock; for (int32_t j = 0; j < numOfCols; ++j) { - SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, j); + SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, j); if (id == pColInfo->info.colId) { *data = pColInfo; break; @@ -3953,20 +3958,19 @@ int32_t fltGetDataFromColId(void *param, int32_t id, void **data) { int32_t fltGetDataFromSlotId(void *param, int32_t id, void **data) { int32_t numOfCols = ((SFilterColumnParam *)param)->numOfCols; - SArray* pDataBlock = ((SFilterColumnParam *)param)->pDataBlock; + SArray *pDataBlock = ((SFilterColumnParam *)param)->pDataBlock; if (id < 0 || id >= numOfCols || id >= taosArrayGetSize(pDataBlock)) { - fltError("invalid slot id, id:%d, numOfCols:%d, arraySize:%d", id, numOfCols, (int32_t)taosArrayGetSize(pDataBlock)); + fltError("invalid slot id, id:%d, numOfCols:%d, arraySize:%d", id, numOfCols, + (int32_t)taosArrayGetSize(pDataBlock)); return TSDB_CODE_QRY_APP_ERROR; } - SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, id); + SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, id); *data = pColInfo; return TSDB_CODE_SUCCESS; } - - int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param) { if (NULL == info) { return TSDB_CODE_QRY_INVALID_INPUT; @@ -3979,10 +3983,8 @@ int32_t filterSetDataFromColId(SFilterInfo *info, void *param) { return fltSetColFieldDataImpl(info, param, fltGetDataFromColId, true); } - - -int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options) { - int32_t code = 0; +int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pInfo, uint32_t options) { + int32_t code = 0; SFilterInfo *info = NULL; if (pNode == NULL || pInfo == NULL) { @@ -4028,14 +4030,15 @@ _return: FLT_RET(code); } -bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData** p, SColumnDataAgg *statis, int16_t numOfCols, int32_t *pResultStatus) { +bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData **p, SColumnDataAgg *statis, int16_t numOfCols, + int32_t *pResultStatus) { if (NULL == info) { *pResultStatus = FILTER_RESULT_ALL_QUALIFIED; return false; } SScalarParam output = {0}; - SDataType type = {.type = TSDB_DATA_TYPE_BOOL, .bytes = sizeof(bool)}; + SDataType type = {.type = TSDB_DATA_TYPE_BOOL, .bytes = sizeof(bool)}; int32_t code = sclCreateColumnInfoData(&type, pSrc->info.rows, &output); if (code != TSDB_CODE_SUCCESS) { @@ -4067,8 +4070,8 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData** p, SC // todo this should be return during filter procedure int32_t num = 0; - for(int32_t i = 0; i < output.numOfRows; ++i) { - if (((int8_t*)((*p)->pData))[i] == 1) { + for (int32_t i = 0; i < output.numOfRows; ++i) { + if (((int8_t *)((*p)->pData))[i] == 1) { ++num; } } @@ -4092,10 +4095,10 @@ typedef struct SClassifyConditionCxt { bool hasOtherCol; } SClassifyConditionCxt; -static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) { - SClassifyConditionCxt* pCxt = (SClassifyConditionCxt*)pContext; +static EDealRes classifyConditionImpl(SNode *pNode, void *pContext) { + SClassifyConditionCxt *pCxt = (SClassifyConditionCxt *)pContext; if (QUERY_NODE_COLUMN == nodeType(pNode)) { - SColumnNode* pCol = (SColumnNode*)pNode; + SColumnNode *pCol = (SColumnNode *)pNode; if (PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId && TSDB_SYSTEM_TABLE != pCol->tableType) { pCxt->hasPrimaryKey = true; } else if (pCol->hasIndex) { @@ -4107,9 +4110,9 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) { pCxt->hasOtherCol = true; } } else if (QUERY_NODE_FUNCTION == nodeType(pNode)) { - SFunctionNode* pFunc = (SFunctionNode*)pNode; + SFunctionNode *pFunc = (SFunctionNode *)pNode; if (fmIsPseudoColumnFunc(pFunc->funcId)) { - if (FUNCTION_TYPE_TBNAME==pFunc->funcType) { + if (FUNCTION_TYPE_TBNAME == pFunc->funcType) { pCxt->hasTagCol = true; } else { pCxt->hasOtherCol = true; @@ -4126,7 +4129,7 @@ typedef enum EConditionType { COND_TYPE_NORMAL } EConditionType; -static EConditionType classifyCondition(SNode* pNode) { +static EConditionType classifyCondition(SNode *pNode) { SClassifyConditionCxt cxt = {.hasPrimaryKey = false, .hasTagIndexCol = false, .hasOtherCol = false}; nodesWalkExpr(pNode, classifyConditionImpl, &cxt); return cxt.hasOtherCol ? COND_TYPE_NORMAL @@ -4136,16 +4139,16 @@ static EConditionType classifyCondition(SNode* pNode) { : (cxt.hasTagIndexCol ? COND_TYPE_TAG_INDEX : COND_TYPE_TAG))); } -static bool isCondColumnsFromMultiTable(SNode* pCond) { - SNodeList* pCondCols = nodesMakeList(); - int32_t code = nodesCollectColumnsFromNode(pCond, NULL, COLLECT_COL_TYPE_ALL, &pCondCols); +static bool isCondColumnsFromMultiTable(SNode *pCond) { + SNodeList *pCondCols = nodesMakeList(); + int32_t code = nodesCollectColumnsFromNode(pCond, NULL, COLLECT_COL_TYPE_ALL, &pCondCols); if (code == TSDB_CODE_SUCCESS) { if (LIST_LENGTH(pCondCols) >= 2) { - SColumnNode* pFirstCol = (SColumnNode*)nodesListGetNode(pCondCols, 0); - SNode* pColNode = NULL; + SColumnNode *pFirstCol = (SColumnNode *)nodesListGetNode(pCondCols, 0); + SNode *pColNode = NULL; FOREACH(pColNode, pCondCols) { - if (strcmp(((SColumnNode*)pColNode)->dbName, pFirstCol->dbName) != 0 || - strcmp(((SColumnNode*)pColNode)->tableAlias, pFirstCol->tableAlias) != 0) { + if (strcmp(((SColumnNode *)pColNode)->dbName, pFirstCol->dbName) != 0 || + strcmp(((SColumnNode *)pColNode)->tableAlias, pFirstCol->tableAlias) != 0) { nodesDestroyList(pCondCols); return true; } @@ -4156,17 +4159,17 @@ static bool isCondColumnsFromMultiTable(SNode* pCond) { return false; } -static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagIndexCond, SNode** pTagCond, - SNode** pOtherCond) { - SLogicConditionNode* pLogicCond = (SLogicConditionNode*)(*pCondition); +static int32_t partitionLogicCond(SNode **pCondition, SNode **pPrimaryKeyCond, SNode **pTagIndexCond, SNode **pTagCond, + SNode **pOtherCond) { + SLogicConditionNode *pLogicCond = (SLogicConditionNode *)(*pCondition); int32_t code = TSDB_CODE_SUCCESS; - SNodeList* pPrimaryKeyConds = NULL; - SNodeList* pTagIndexConds = NULL; - SNodeList* pTagConds = NULL; - SNodeList* pOtherConds = NULL; - SNode* pCond = NULL; + SNodeList *pPrimaryKeyConds = NULL; + SNodeList *pTagIndexConds = NULL; + SNodeList *pTagConds = NULL; + SNodeList *pOtherConds = NULL; + SNode *pCond = NULL; FOREACH(pCond, pLogicCond->pParameterList) { if (isCondColumnsFromMultiTable(pCond)) { if (NULL != pOtherCond) { @@ -4205,10 +4208,10 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S } } - SNode* pTempPrimaryKeyCond = NULL; - SNode* pTempTagIndexCond = NULL; - SNode* pTempTagCond = NULL; - SNode* pTempOtherCond = NULL; + SNode *pTempPrimaryKeyCond = NULL; + SNode *pTempTagIndexCond = NULL; + SNode *pTempTagCond = NULL; + SNode *pTempOtherCond = NULL; if (TSDB_CODE_SUCCESS == code) { code = nodesMergeConds(&pTempPrimaryKeyCond, &pPrimaryKeyConds); } @@ -4251,10 +4254,10 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S return code; } -int32_t filterPartitionCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagIndexCond, SNode** pTagCond, - SNode** pOtherCond) { +int32_t filterPartitionCond(SNode **pCondition, SNode **pPrimaryKeyCond, SNode **pTagIndexCond, SNode **pTagCond, + SNode **pOtherCond) { if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pCondition) && - LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)*pCondition)->condType) { + LOGIC_COND_TYPE_AND == ((SLogicConditionNode *)*pCondition)->condType) { return partitionLogicCond(pCondition, pPrimaryKeyCond, pTagIndexCond, pTagCond, pOtherCond); } diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index b4b99be6362c31ac752df190920f55b22a6aec32..1f09fd4799d7ba87ed545d97ed931c88cb4e8517 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -1,3 +1,4 @@ +#include "scalar.h" #include "function.h" #include "functionMgt.h" #include "nodes.h" @@ -5,25 +6,25 @@ #include "sclInt.h" #include "sclvector.h" #include "tcommon.h" +#include "tcompare.h" #include "tdatablock.h" -#include "scalar.h" -#include "tudf.h" #include "ttime.h" -#include "tcompare.h" +#include "tudf.h" int32_t scalarGetOperatorParamNum(EOperatorType type) { - if (OP_TYPE_IS_NULL == type || OP_TYPE_IS_NOT_NULL == type || OP_TYPE_IS_TRUE == type || OP_TYPE_IS_NOT_TRUE == type - || OP_TYPE_IS_FALSE == type || OP_TYPE_IS_NOT_FALSE == type || OP_TYPE_IS_UNKNOWN == type || OP_TYPE_IS_NOT_UNKNOWN == type - || OP_TYPE_MINUS == type) { + if (OP_TYPE_IS_NULL == type || OP_TYPE_IS_NOT_NULL == type || OP_TYPE_IS_TRUE == type || + OP_TYPE_IS_NOT_TRUE == type || OP_TYPE_IS_FALSE == type || OP_TYPE_IS_NOT_FALSE == type || + OP_TYPE_IS_UNKNOWN == type || OP_TYPE_IS_NOT_UNKNOWN == type || OP_TYPE_MINUS == type) { return 1; } return 2; } -int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode) { - char *timeStr = valueNode->datum.p; - int32_t code = convertStringToTimestamp(valueNode->node.resType.type, valueNode->datum.p, precision, &valueNode->datum.i); +int32_t sclConvertToTsValueNode(int8_t precision, SValueNode *valueNode) { + char *timeStr = valueNode->datum.p; + int32_t code = + convertStringToTimestamp(valueNode->node.resType.type, valueNode->datum.p, precision, &valueNode->datum.i); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -36,16 +37,16 @@ int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode) { return TSDB_CODE_SUCCESS; } -int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarParam* pParam) { - SColumnInfoData* pColumnData = taosMemoryCalloc(1, sizeof(SColumnInfoData)); +int32_t sclCreateColumnInfoData(SDataType *pType, int32_t numOfRows, SScalarParam *pParam) { + SColumnInfoData *pColumnData = taosMemoryCalloc(1, sizeof(SColumnInfoData)); if (pColumnData == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return terrno; } - pColumnData->info.type = pType->type; - pColumnData->info.bytes = pType->bytes; - pColumnData->info.scale = pType->scale; + pColumnData->info.type = pType->type; + pColumnData->info.bytes = pType->bytes; + pColumnData->info.scale = pType->scale; pColumnData->info.precision = pType->precision; int32_t code = colInfoDataEnsureCapacity(pColumnData, numOfRows); @@ -60,9 +61,9 @@ int32_t sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows, SScalarPara return TSDB_CODE_SUCCESS; } -int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out, int32_t* overflow) { +int32_t sclConvertValueToSclParam(SValueNode* pValueNode, SScalarParam* out, int32_t* overflow) { SScalarParam in = {.numOfRows = 1}; - int32_t code = sclCreateColumnInfoData(&pValueNode->node.resType, 1, &in); + int32_t code = sclCreateColumnInfoData(&pValueNode->node.resType, 1, &in); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -70,12 +71,34 @@ int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out, int32_t* ov colDataAppend(in.columnData, 0, nodesGetValueFromNode(pValueNode), false); colInfoDataEnsureCapacity(out->columnData, 1); - code = vectorConvertImpl(&in, out, overflow); + code = vectorConvertSingleColImpl(&in, out, overflow, -1, -1); sclFreeParam(&in); return code; } +int32_t sclExtendResRows(SScalarParam *pDst, SScalarParam *pSrc, SArray *pBlockList) { + SSDataBlock* pb = taosArrayGetP(pBlockList, 0); + SScalarParam *pLeft = taosMemoryCalloc(1, sizeof(SScalarParam)); + if (NULL == pLeft) { + sclError("calloc %d failed", (int32_t)sizeof(SScalarParam)); + SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + pLeft->numOfRows = pb->info.rows; + + if (pDst->numOfRows < pb->info.rows) { + colInfoDataEnsureCapacity(pDst->columnData, pb->info.rows); + } + + _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(OP_TYPE_ASSIGN); + OperatorFn(pLeft, pSrc, pDst, TSDB_ORDER_ASC); + + taosMemoryFree(pLeft); + + return TSDB_CODE_SUCCESS; +} + int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(type), true, false); if (NULL == pObj) { @@ -85,13 +108,13 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(type)); - int32_t code = 0; + int32_t code = 0; SNodeListNode *nodeList = (SNodeListNode *)pNode; - SListCell *cell = nodeList->pNodeList->pHead; - SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; + SListCell *cell = nodeList->pNodeList->pHead; + SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; int32_t len = 0; - void *buf = NULL; + void *buf = NULL; for (int32_t i = 0; i < nodeList->pNodeList->length; ++i) { SValueNode *valueNode = (SValueNode *)cell->pNode; @@ -109,9 +132,9 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { } int32_t overflow = 0; - code = doConvertDataType(valueNode, &out, &overflow); + code = sclConvertValueToSclParam(valueNode, &out, &overflow); if (code != TSDB_CODE_SUCCESS) { -// sclError("convert data from %d to %d failed", in.type, out.type); + // sclError("convert data from %d to %d failed", in.type, out.type); SCL_ERR_JRET(code); } @@ -164,7 +187,7 @@ _return: void sclFreeRes(SHashObj *res) { SScalarParam *p = NULL; - void *pIter = taosHashIterate(res, NULL); + void *pIter = taosHashIterate(res, NULL); while (pIter) { p = (SScalarParam *)pIter; @@ -177,10 +200,10 @@ void sclFreeRes(SHashObj *res) { } void sclFreeParam(SScalarParam *param) { - if (!param->colAlloced) { + if (NULL == param || !param->colAlloced) { return; } - + if (param->columnData != NULL) { colDataDestroy(param->columnData); taosMemoryFreeClear(param->columnData); @@ -213,7 +236,7 @@ void sclFreeParamList(SScalarParam *param, int32_t paramNum) { } for (int32_t i = 0; i < paramNum; ++i) { - SScalarParam* p = param + i; + SScalarParam *p = param + i; sclFreeParam(p); } @@ -226,33 +249,33 @@ void sclDowngradeValueType(SValueNode *valueNode) { int8_t i8 = valueNode->datum.i; if (i8 == valueNode->datum.i) { valueNode->node.resType.type = TSDB_DATA_TYPE_TINYINT; - *(int8_t*)&valueNode->typeData = i8; + *(int8_t *)&valueNode->typeData = i8; break; } int16_t i16 = valueNode->datum.i; if (i16 == valueNode->datum.i) { valueNode->node.resType.type = TSDB_DATA_TYPE_SMALLINT; - *(int16_t*)&valueNode->typeData = i16; + *(int16_t *)&valueNode->typeData = i16; break; } int32_t i32 = valueNode->datum.i; if (i32 == valueNode->datum.i) { valueNode->node.resType.type = TSDB_DATA_TYPE_INT; - *(int32_t*)&valueNode->typeData = i32; + *(int32_t *)&valueNode->typeData = i32; break; } break; } - case TSDB_DATA_TYPE_UBIGINT:{ + case TSDB_DATA_TYPE_UBIGINT: { uint8_t u8 = valueNode->datum.i; if (u8 == valueNode->datum.i) { int8_t i8 = valueNode->datum.i; if (i8 == valueNode->datum.i) { valueNode->node.resType.type = TSDB_DATA_TYPE_TINYINT; - *(int8_t*)&valueNode->typeData = i8; + *(int8_t *)&valueNode->typeData = i8; } else { valueNode->node.resType.type = TSDB_DATA_TYPE_UTINYINT; - *(uint8_t*)&valueNode->typeData = u8; + *(uint8_t *)&valueNode->typeData = u8; } break; } @@ -261,10 +284,10 @@ void sclDowngradeValueType(SValueNode *valueNode) { int16_t i16 = valueNode->datum.i; if (i16 == valueNode->datum.i) { valueNode->node.resType.type = TSDB_DATA_TYPE_SMALLINT; - *(int16_t*)&valueNode->typeData = i16; + *(int16_t *)&valueNode->typeData = i16; } else { valueNode->node.resType.type = TSDB_DATA_TYPE_USMALLINT; - *(uint16_t*)&valueNode->typeData = u16; + *(uint16_t *)&valueNode->typeData = u16; } break; } @@ -273,10 +296,10 @@ void sclDowngradeValueType(SValueNode *valueNode) { int32_t i32 = valueNode->datum.i; if (i32 == valueNode->datum.i) { valueNode->node.resType.type = TSDB_DATA_TYPE_INT; - *(int32_t*)&valueNode->typeData = i32; + *(int32_t *)&valueNode->typeData = i32; } else { valueNode->node.resType.type = TSDB_DATA_TYPE_UINT; - *(uint32_t*)&valueNode->typeData = u32; + *(uint32_t *)&valueNode->typeData = u32; } break; } @@ -286,7 +309,7 @@ void sclDowngradeValueType(SValueNode *valueNode) { float f = valueNode->datum.d; if (FLT_EQUAL(f, valueNode->datum.d)) { valueNode->node.resType.type = TSDB_DATA_TYPE_FLOAT; - *(float*)&valueNode->typeData = f; + *(float *)&valueNode->typeData = f; break; } break; @@ -296,10 +319,10 @@ void sclDowngradeValueType(SValueNode *valueNode) { } } -int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t *rowNum) { +int32_t sclInitParam(SNode *node, SScalarParam *param, SScalarCtx *ctx, int32_t *rowNum) { switch (nodeType(node)) { case QUERY_NODE_LEFT_VALUE: { - SSDataBlock* pb = taosArrayGetP(ctx->pBlockList, 0); + SSDataBlock *pb = taosArrayGetP(ctx->pBlockList, 0); param->numOfRows = pb->info.rows; break; } @@ -308,7 +331,7 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t ASSERT(param->columnData == NULL); param->numOfRows = 1; - /*int32_t code = */sclCreateColumnInfoData(&valueNode->node.resType, 1, param); + /*int32_t code = */ sclCreateColumnInfoData(&valueNode->node.resType, 1, param); if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) { colDataAppendNULL(param->columnData, 0); } else { @@ -349,8 +372,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t SColumnNode *ref = (SColumnNode *)node; int32_t index = -1; - for(int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) { - SSDataBlock* pb = taosArrayGetP(ctx->pBlockList, i); + for (int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) { + SSDataBlock *pb = taosArrayGetP(ctx->pBlockList, i); if (pb->info.blockId == ref->dataBlockId) { index = i; break; @@ -358,7 +381,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t } if (index == -1) { - sclError("column tupleId is too big, tupleId:%d, dataBlockNum:%d", ref->dataBlockId, (int32_t)taosArrayGetSize(ctx->pBlockList)); + sclError("column tupleId is too big, tupleId:%d, dataBlockNum:%d", ref->dataBlockId, + (int32_t)taosArrayGetSize(ctx->pBlockList)); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } @@ -368,13 +392,15 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t } if (ref->slotId >= taosArrayGetSize(block->pDataBlock)) { - sclError("column slotId is too big, slodId:%d, dataBlockSize:%d", ref->slotId, (int32_t)taosArrayGetSize(block->pDataBlock)); + sclError("column slotId is too big, slodId:%d, dataBlockSize:%d", ref->slotId, + (int32_t)taosArrayGetSize(block->pDataBlock)); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } SColumnInfoData *columnData = (SColumnInfoData *)taosArrayGet(block->pDataBlock, ref->slotId); #if TAG_FILTER_DEBUG - qDebug("tagfilter column info, slotId:%d, colId:%d, type:%d", ref->slotId, columnData->info.colId, columnData->info.type); + qDebug("tagfilter column info, slotId:%d, colId:%d, type:%d", ref->slotId, columnData->info.colId, + columnData->info.type); #endif param->numOfRows = block->info.rows; param->columnData = columnData; @@ -382,7 +408,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t } case QUERY_NODE_FUNCTION: case QUERY_NODE_OPERATOR: - case QUERY_NODE_LOGIC_CONDITION: { + case QUERY_NODE_LOGIC_CONDITION: + case QUERY_NODE_CASE_WHEN: { SScalarParam *res = (SScalarParam *)taosHashGet(ctx->pRes, &node, POINTER_BYTES); if (NULL == res) { sclError("no result for node, type:%d, node:%p", nodeType(node), node); @@ -409,7 +436,8 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t return TSDB_CODE_SUCCESS; } -int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarCtx *ctx, int32_t *paramNum, int32_t *rowNum) { +int32_t sclInitParamList(SScalarParam **pParams, SNodeList *pParamList, SScalarCtx *ctx, int32_t *paramNum, + int32_t *rowNum) { int32_t code = 0; if (NULL == pParamList) { if (ctx->pBlockList) { @@ -431,10 +459,10 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarC } if (pParamList) { - SNode *tnode = NULL; + SNode *tnode = NULL; int32_t i = 0; if (SCL_IS_CONST_CALC(ctx)) { - WHERE_EACH (tnode, pParamList) { + WHERE_EACH(tnode, pParamList) { if (!SCL_IS_CONST_NODE(tnode)) { WHERE_NEXT; } else { @@ -499,7 +527,6 @@ int32_t sclGetNodeType(SNode *pNode, SScalarCtx *ctx) { return -1; } - void sclSetOperatorValueType(SOperatorNode *node, SScalarCtx *ctx) { ctx->type.opResType = node->node.resType.type; ctx->type.selfType = sclGetNodeType(node->pLeft, ctx); @@ -536,11 +563,140 @@ _return: SCL_RET(code); } -int32_t sclExecFunction(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *output) { - SScalarParam *params = NULL; +int32_t sclGetNodeRes(SNode* node, SScalarCtx *ctx, SScalarParam **res) { + if (NULL == node) { + return TSDB_CODE_SUCCESS; + } + int32_t rowNum = 0; - int32_t paramNum = 0; + *res = taosMemoryCalloc(1, sizeof(**res)); + if (NULL == *res) { + SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + + SCL_ERR_RET(sclInitParam(node, *res, ctx, &rowNum)); + + return TSDB_CODE_SUCCESS; +} + +int32_t sclWalkCaseWhenList(SScalarCtx *ctx, SNodeList* pList, struct SListCell* pCell, SScalarParam *pCase, SScalarParam *pElse, SScalarParam *pComp, SScalarParam *output, int32_t rowIdx, int32_t totalRows, bool *complete) { + SNode *node = NULL; + SWhenThenNode* pWhenThen = NULL; + SScalarParam *pWhen = NULL; + SScalarParam *pThen = NULL; + int32_t code = 0; + + for (SListCell* cell = pCell; (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)); cell = cell->pNext) { + pWhenThen = (SWhenThenNode*)node; + + SCL_ERR_RET(sclGetNodeRes(pWhenThen->pWhen, ctx, &pWhen)); + SCL_ERR_RET(sclGetNodeRes(pWhenThen->pThen, ctx, &pThen)); + + vectorCompareImpl(pCase, pWhen, pComp, rowIdx, 1, TSDB_ORDER_ASC, OP_TYPE_EQUAL); + + bool *equal = (bool*)colDataGetData(pComp->columnData, rowIdx); + if (*equal) { + colDataAppend(output->columnData, rowIdx, colDataGetData(pThen->columnData, (pThen->numOfRows > 1 ? rowIdx : 0)), colDataIsNull_s(pThen->columnData, (pThen->numOfRows > 1 ? rowIdx : 0))); + + if (0 == rowIdx && 1 == pCase->numOfRows && 1 == pWhen->numOfRows && 1 == pThen->numOfRows && totalRows > 1) { + SCL_ERR_JRET(sclExtendResRows(output, output, ctx->pBlockList)); + *complete = true; + } + + goto _return; + } + } + + if (pElse) { + colDataAppend(output->columnData, rowIdx, colDataGetData(pElse->columnData, (pElse->numOfRows > 1 ? rowIdx : 0)), colDataIsNull_s(pElse->columnData, (pElse->numOfRows > 1 ? rowIdx : 0))); + + if (0 == rowIdx && 1 == pCase->numOfRows && 1 == pElse->numOfRows && totalRows > 1) { + SCL_ERR_JRET(sclExtendResRows(output, output, ctx->pBlockList)); + *complete = true; + } + + goto _return; + } + + colDataAppend(output->columnData, rowIdx, NULL, true); + + if (0 == rowIdx && 1 == pCase->numOfRows && totalRows > 1) { + SCL_ERR_JRET(sclExtendResRows(output, output, ctx->pBlockList)); + *complete = true; + } + +_return: + + sclFreeParam(pWhen); + sclFreeParam(pThen); + + SCL_RET(code); +} + +int32_t sclWalkWhenList(SScalarCtx *ctx, SNodeList* pList, struct SListCell* pCell, SScalarParam *pElse, SScalarParam *output, + int32_t rowIdx, int32_t totalRows, bool *complete, bool preSingle) { + SNode *node = NULL; + SWhenThenNode* pWhenThen = NULL; + SScalarParam *pWhen = NULL; + SScalarParam *pThen = NULL; int32_t code = 0; + + for (SListCell* cell = pCell; (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)); cell = cell->pNext) { + pWhenThen = (SWhenThenNode*)node; + pWhen = NULL; + pThen = NULL; + + SCL_ERR_JRET(sclGetNodeRes(pWhenThen->pWhen, ctx, &pWhen)); + SCL_ERR_JRET(sclGetNodeRes(pWhenThen->pThen, ctx, &pThen)); + + bool *whenValue = (bool*)colDataGetData(pWhen->columnData, (pWhen->numOfRows > 1 ? rowIdx : 0)); + + if (*whenValue) { + colDataAppend(output->columnData, rowIdx, colDataGetData(pThen->columnData, (pThen->numOfRows > 1 ? rowIdx : 0)), colDataIsNull_s(pThen->columnData, (pThen->numOfRows > 1 ? rowIdx : 0))); + + if (preSingle && 0 == rowIdx && 1 == pWhen->numOfRows && 1 == pThen->numOfRows && totalRows > 1) { + SCL_ERR_JRET(sclExtendResRows(output, output, ctx->pBlockList)); + *complete = true; + } + + goto _return; + } + + sclFreeParam(pWhen); + sclFreeParam(pThen); + } + + if (pElse) { + colDataAppend(output->columnData, rowIdx, colDataGetData(pElse->columnData, (pElse->numOfRows > 1 ? rowIdx : 0)), colDataIsNull_s(pElse->columnData, (pElse->numOfRows > 1 ? rowIdx : 0))); + + if (preSingle && 0 == rowIdx && 1 == pElse->numOfRows && totalRows > 1) { + SCL_ERR_JRET(sclExtendResRows(output, output, ctx->pBlockList)); + *complete = true; + } + + goto _return; + } + + colDataAppend(output->columnData, rowIdx, NULL, true); + + if (preSingle && 0 == rowIdx && totalRows > 1) { + SCL_ERR_JRET(sclExtendResRows(output, output, ctx->pBlockList)); + *complete = true; + } + +_return: + + sclFreeParam(pWhen); + sclFreeParam(pThen); + + SCL_RET(code); +} + +int32_t sclExecFunction(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *output) { + SScalarParam *params = NULL; + int32_t rowNum = 0; + int32_t paramNum = 0; + int32_t code = 0; SCL_ERR_RET(sclInitParamList(¶ms, node->pParameterList, ctx, ¶mNum, &rowNum)); if (fmIsUserDefinedFunc(node->funcId)) { @@ -577,7 +733,8 @@ _return: int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *output) { if (NULL == node->pParameterList || node->pParameterList->length <= 0) { - sclError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0); + sclError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList, + node->pParameterList ? node->pParameterList->length : 0); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } @@ -592,9 +749,9 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o } SScalarParam *params = NULL; - int32_t rowNum = 0; - int32_t paramNum = 0; - int32_t code = 0; + int32_t rowNum = 0; + int32_t paramNum = 0; + int32_t code = 0; SCL_ERR_RET(sclInitParamList(¶ms, node->pParameterList, ctx, ¶mNum, &rowNum)); if (NULL == params) { output->numOfRows = 0; @@ -621,7 +778,7 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o complete = false; continue; } - char* p = colDataGetData(params[m].columnData, i); + char *p = colDataGetData(params[m].columnData, i); GET_TYPED_DATA(value, bool, params[m].columnData->info.type, p); if (LOGIC_COND_TYPE_AND == node->condType && (false == value)) { @@ -636,7 +793,7 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o } if (complete) { - colDataAppend(output->columnData, i, (char*) &value, false); + colDataAppend(output->columnData, i, (char *)&value, false); if (value) { numOfQualified++; } @@ -657,13 +814,14 @@ _return: int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *output) { SScalarParam *params = NULL; - int32_t rowNum = 0; - int32_t code = 0; + int32_t rowNum = 0; + int32_t code = 0; // json not support in in operator if (nodeType(node->pLeft) == QUERY_NODE_VALUE) { SValueNode *valueNode = (SValueNode *)node->pLeft; - if (valueNode->node.resType.type == TSDB_DATA_TYPE_JSON && (node->opType == OP_TYPE_IN || node->opType == OP_TYPE_NOT_IN)) { + if (valueNode->node.resType.type == TSDB_DATA_TYPE_JSON && + (node->opType == OP_TYPE_IN || node->opType == OP_TYPE_NOT_IN)) { SCL_RET(TSDB_CODE_QRY_JSON_IN_ERROR); } } @@ -678,9 +836,9 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(node->opType); - int32_t paramNum = scalarGetOperatorParamNum(node->opType); - SScalarParam* pLeft = ¶ms[0]; - SScalarParam* pRight = paramNum > 1 ? ¶ms[1] : NULL; + int32_t paramNum = scalarGetOperatorParamNum(node->opType); + SScalarParam *pLeft = ¶ms[0]; + SScalarParam *pRight = paramNum > 1 ? ¶ms[1] : NULL; terrno = TSDB_CODE_SUCCESS; OperatorFn(pLeft, pRight, output, TSDB_ORDER_ASC); @@ -692,7 +850,102 @@ _return: SCL_RET(code); } -EDealRes sclRewriteNullInOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opType) { +int32_t sclExecCaseWhen(SCaseWhenNode *node, SScalarCtx *ctx, SScalarParam *output) { + int32_t code = 0; + SScalarParam *pCase = NULL; + SScalarParam *pElse = NULL; + SScalarParam *pWhen = NULL; + SScalarParam *pThen = NULL; + SScalarParam comp = {0}; + int32_t rowNum = 1; + bool complete = false; + + if (NULL == node->pWhenThenList || node->pWhenThenList->length <= 0) { + sclError("invalid whenThen list"); + SCL_ERR_RET(TSDB_CODE_INVALID_PARA); + } + + if (ctx->pBlockList) { + SSDataBlock* pb = taosArrayGetP(ctx->pBlockList, 0); + rowNum = pb->info.rows; + output->numOfRows = pb->info.rows; + } + + SCL_ERR_JRET(sclCreateColumnInfoData(&node->node.resType, rowNum, output)); + + SCL_ERR_JRET(sclGetNodeRes(node->pCase, ctx, &pCase)); + SCL_ERR_JRET(sclGetNodeRes(node->pElse, ctx, &pElse)); + + SDataType compType = {0}; + compType.type = TSDB_DATA_TYPE_BOOL; + compType.bytes = tDataTypes[compType.type].bytes; + + SCL_ERR_JRET(sclCreateColumnInfoData(&compType, rowNum, &comp)); + + SNode* tnode = NULL; + SWhenThenNode* pWhenThen = (SWhenThenNode*)node->pWhenThenList->pHead->pNode; + + SCL_ERR_JRET(sclGetNodeRes(pWhenThen->pWhen, ctx, &pWhen)); + SCL_ERR_JRET(sclGetNodeRes(pWhenThen->pThen, ctx, &pThen)); + + if (pCase) { + vectorCompare(pCase, pWhen, &comp, TSDB_ORDER_ASC, OP_TYPE_EQUAL); + + for (int32_t i = 0; i < rowNum; ++i) { + bool *equal = (bool*)colDataGetData(comp.columnData, (comp.numOfRows > 1 ? i : 0)); + if (*equal) { + colDataAppend(output->columnData, i, colDataGetData(pThen->columnData, (pThen->numOfRows > 1 ? i : 0)), colDataIsNull_s(pThen->columnData, (pThen->numOfRows > 1 ? i : 0))); + if (0 == i && 1 == pCase->numOfRows && 1 == pWhen->numOfRows && 1 == pThen->numOfRows && rowNum > 1) { + SCL_ERR_JRET(sclExtendResRows(output, output, ctx->pBlockList)); + break; + } + } else { + SCL_ERR_JRET(sclWalkCaseWhenList(ctx, node->pWhenThenList, node->pWhenThenList->pHead->pNext, pCase, pElse, &comp, output, i, rowNum, &complete)); + if (complete) { + break; + } + } + } + } else { + for (int32_t i = 0; i < rowNum; ++i) { + bool *whenValue = (bool*)colDataGetData(pWhen->columnData, (pWhen->numOfRows > 1 ? i : 0)); + if (*whenValue) { + colDataAppend(output->columnData, i, colDataGetData(pThen->columnData, (pThen->numOfRows > 1 ? i : 0)), colDataIsNull_s(pThen->columnData, (pThen->numOfRows > 1 ? i : 0))); + if (0 == i && 1 == pWhen->numOfRows && 1 == pThen->numOfRows && rowNum > 1) { + SCL_ERR_JRET(sclExtendResRows(output, output, ctx->pBlockList)); + break; + } + } else { + SCL_ERR_JRET(sclWalkWhenList(ctx, node->pWhenThenList, node->pWhenThenList->pHead->pNext, pElse, output, i, rowNum, &complete, (pWhen->numOfRows == 1 && pThen->numOfRows == 1))); + if (complete) { + break; + } + } + } + } + + sclFreeParam(pCase); + sclFreeParam(pElse); + sclFreeParam(&comp); + sclFreeParam(pWhen); + sclFreeParam(pThen); + + return TSDB_CODE_SUCCESS; + +_return: + + sclFreeParam(pCase); + sclFreeParam(pElse); + sclFreeParam(&comp); + sclFreeParam(pWhen); + sclFreeParam(pThen); + sclFreeParam(output); + + SCL_RET(code); +} + + +EDealRes sclRewriteNullInOptr(SNode **pNode, SScalarCtx *ctx, EOperatorType opType) { if (opType <= OP_TYPE_CALC_MAX) { SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); if (NULL == res) { @@ -704,7 +957,7 @@ EDealRes sclRewriteNullInOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opTy res->node.resType.type = TSDB_DATA_TYPE_NULL; nodesDestroyNode(*pNode); - *pNode = (SNode*)res; + *pNode = (SNode *)res; } else { SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); if (NULL == res) { @@ -718,17 +971,17 @@ EDealRes sclRewriteNullInOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opTy res->datum.b = false; nodesDestroyNode(*pNode); - *pNode = (SNode*)res; + *pNode = (SNode *)res; } return DEAL_RES_CONTINUE; } -EDealRes sclAggFuncWalker(SNode* pNode, void* pContext) { +EDealRes sclAggFuncWalker(SNode *pNode, void *pContext) { if (QUERY_NODE_FUNCTION == nodeType(pNode)) { - SFunctionNode* pFunc = (SFunctionNode*)pNode; - *(bool*)pContext = fmIsAggFunc(pFunc->funcId); - if (*(bool*)pContext) { + SFunctionNode *pFunc = (SFunctionNode *)pNode; + *(bool *)pContext = fmIsAggFunc(pFunc->funcId); + if (*(bool *)pContext) { return DEAL_RES_END; } } @@ -736,27 +989,26 @@ EDealRes sclAggFuncWalker(SNode* pNode, void* pContext) { return DEAL_RES_CONTINUE; } - -bool sclContainsAggFuncNode(SNode* pNode) { +bool sclContainsAggFuncNode(SNode *pNode) { bool aggFunc = false; nodesWalkExpr(pNode, sclAggFuncWalker, (void *)&aggFunc); return aggFunc; } -EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { +EDealRes sclRewriteNonConstOperator(SNode **pNode, SScalarCtx *ctx) { SOperatorNode *node = (SOperatorNode *)*pNode; - int32_t code = 0; + int32_t code = 0; if (node->pLeft && (QUERY_NODE_VALUE == nodeType(node->pLeft))) { SValueNode *valueNode = (SValueNode *)node->pLeft; - if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) - && (!sclContainsAggFuncNode(node->pRight))) { + if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) && + (!sclContainsAggFuncNode(node->pRight))) { return sclRewriteNullInOptr(pNode, ctx, node->opType); } - if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pRight && nodesIsExprNode(node->pRight) - && ((SExprNode*)node->pRight)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) { - code = sclConvertToTsValueNode(((SExprNode*)node->pRight)->resType.precision, valueNode); + if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pRight && nodesIsExprNode(node->pRight) && + ((SExprNode *)node->pRight)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) { + code = sclConvertToTsValueNode(((SExprNode *)node->pRight)->resType.precision, valueNode); if (code) { ctx->code = code; return DEAL_RES_ERROR; @@ -765,19 +1017,19 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { if (SCL_IS_COMPARISON_OPERATOR(node->opType) && SCL_DOWNGRADE_DATETYPE(valueNode->node.resType.type)) { sclDowngradeValueType(valueNode); - } + } } if (node->pRight && (QUERY_NODE_VALUE == nodeType(node->pRight))) { SValueNode *valueNode = (SValueNode *)node->pRight; - if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) - && (!sclContainsAggFuncNode(node->pLeft))) { + if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL) && + (!sclContainsAggFuncNode(node->pLeft))) { return sclRewriteNullInOptr(pNode, ctx, node->opType); } - if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pLeft && nodesIsExprNode(node->pLeft) - && ((SExprNode*)node->pLeft)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) { - code = sclConvertToTsValueNode(((SExprNode*)node->pLeft)->resType.precision, valueNode); + if (IS_STR_DATA_TYPE(valueNode->node.resType.type) && node->pLeft && nodesIsExprNode(node->pLeft) && + ((SExprNode *)node->pLeft)->resType.type == TSDB_DATA_TYPE_TIMESTAMP) { + code = sclConvertToTsValueNode(((SExprNode *)node->pLeft)->resType.precision, valueNode); if (code) { ctx->code = code; return DEAL_RES_ERROR; @@ -786,18 +1038,18 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { if (SCL_IS_COMPARISON_OPERATOR(node->opType) && SCL_DOWNGRADE_DATETYPE(valueNode->node.resType.type)) { sclDowngradeValueType(valueNode); - } + } } if (node->pRight && (QUERY_NODE_NODE_LIST == nodeType(node->pRight))) { SNodeListNode *listNode = (SNodeListNode *)node->pRight; - SNode* tnode = NULL; + SNode *tnode = NULL; WHERE_EACH(tnode, listNode->pNodeList) { if (SCL_IS_NULL_VALUE_NODE(tnode)) { if (node->opType == OP_TYPE_IN) { ERASE_NODE(listNode->pNodeList); continue; - } else { //OP_TYPE_NOT_IN + } else { // OP_TYPE_NOT_IN return sclRewriteNullInOptr(pNode, ctx, node->opType); } } @@ -813,9 +1065,9 @@ EDealRes sclRewriteNonConstOperator(SNode** pNode, SScalarCtx *ctx) { return DEAL_RES_CONTINUE; } -EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { +EDealRes sclRewriteFunction(SNode **pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)*pNode; - SNode* tnode = NULL; + SNode *tnode = NULL; if (!fmIsScalarFunc(node->funcId) && (!ctx->dual)) { return DEAL_RES_CONTINUE; } @@ -851,12 +1103,12 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { res->isNull = true; } else { int32_t type = output.columnData->info.type; - if (type == TSDB_DATA_TYPE_JSON){ + if (type == TSDB_DATA_TYPE_JSON) { int32_t len = getJsonValueLen(output.columnData->pData); res->datum.p = taosMemoryCalloc(len, 1); memcpy(res->datum.p, output.columnData->pData, len); } else if (IS_VAR_DATA_TYPE(type)) { - //res->datum.p = taosMemoryCalloc(res->node.resType.bytes + VARSTR_HEADER_SIZE + 1, 1); + // res->datum.p = taosMemoryCalloc(res->node.resType.bytes + VARSTR_HEADER_SIZE + 1, 1); res->datum.p = taosMemoryCalloc(varDataTLen(output.columnData->pData) + 1, 1); res->node.resType.bytes = varDataTLen(output.columnData->pData); memcpy(res->datum.p, output.columnData->pData, varDataTLen(output.columnData->pData)); @@ -866,13 +1118,13 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { } nodesDestroyNode(*pNode); - *pNode = (SNode*)res; + *pNode = (SNode *)res; sclFreeParam(&output); return DEAL_RES_CONTINUE; } -EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { +EDealRes sclRewriteLogic(SNode **pNode, SScalarCtx *ctx) { SLogicConditionNode *node = (SLogicConditionNode *)*pNode; SScalarParam output = {0}; @@ -905,13 +1157,13 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { } nodesDestroyNode(*pNode); - *pNode = (SNode*)res; + *pNode = (SNode *)res; sclFreeParam(&output); return DEAL_RES_CONTINUE; } -EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { +EDealRes sclRewriteOperator(SNode **pNode, SScalarCtx *ctx) { SOperatorNode *node = (SOperatorNode *)*pNode; if ((!SCL_IS_CONST_NODE(node->pLeft)) || (!SCL_IS_CONST_NODE(node->pRight))) { @@ -948,6 +1200,58 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { } } + nodesDestroyNode(*pNode); + *pNode = (SNode *)res; + + sclFreeParam(&output); + return DEAL_RES_CONTINUE; +} + +EDealRes sclRewriteCaseWhen(SNode** pNode, SScalarCtx *ctx) { + SCaseWhenNode *node = (SCaseWhenNode *)*pNode; + + if ((!SCL_IS_CONST_NODE(node->pCase)) || (!SCL_IS_CONST_NODE(node->pElse))) { + return DEAL_RES_CONTINUE; + } + + SNode* tnode = NULL; + FOREACH(tnode, node->pWhenThenList) { + SWhenThenNode* pWhenThen = (SWhenThenNode*)tnode; + if (!SCL_IS_CONST_NODE(pWhenThen->pWhen) || !SCL_IS_CONST_NODE(pWhenThen->pThen)) { + return DEAL_RES_CONTINUE; + } + } + + SScalarParam output = {0}; + ctx->code = sclExecCaseWhen(node, ctx, &output); + if (ctx->code) { + return DEAL_RES_ERROR; + } + + SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); + if (NULL == res) { + sclError("make value node failed"); + sclFreeParam(&output); + ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY; + return DEAL_RES_ERROR; + } + + res->translate = true; + + res->node.resType = node->node.resType; + if (colDataIsNull_s(output.columnData, 0)) { + res->isNull = true; + res->node.resType = node->node.resType; + } else { + int32_t type = output.columnData->info.type; + if (IS_VAR_DATA_TYPE(type)) { // todo refactor + res->datum.p = output.columnData->pData; + output.columnData->pData = NULL; + } else { + nodesSetValueNodeValue(res, output.columnData->pData); + } + } + nodesDestroyNode(*pNode); *pNode = (SNode*)res; @@ -955,9 +1259,14 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { return DEAL_RES_CONTINUE; } -EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { + +EDealRes sclConstantsRewriter(SNode **pNode, void *pContext) { SScalarCtx *ctx = (SScalarCtx *)pContext; + if (QUERY_NODE_OPERATOR == nodeType(*pNode)) { + return sclRewriteOperator(pNode, ctx); + } + if (QUERY_NODE_FUNCTION == nodeType(*pNode)) { return sclRewriteFunction(pNode, ctx); } @@ -966,16 +1275,16 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { return sclRewriteLogic(pNode, ctx); } - if (QUERY_NODE_OPERATOR == nodeType(*pNode)) { - return sclRewriteOperator(pNode, ctx); + if (QUERY_NODE_CASE_WHEN == nodeType(*pNode)) { + return sclRewriteCaseWhen(pNode, ctx); } return DEAL_RES_CONTINUE; } -EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { +EDealRes sclWalkFunction(SNode *pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)pNode; - SScalarParam output = {0}; + SScalarParam output = {0}; ctx->code = sclExecFunction(node, ctx, &output); if (ctx->code) { @@ -990,9 +1299,9 @@ EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_CONTINUE; } -EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) { +EDealRes sclWalkLogic(SNode *pNode, SScalarCtx *ctx) { SLogicConditionNode *node = (SLogicConditionNode *)pNode; - SScalarParam output = {0}; + SScalarParam output = {0}; ctx->code = sclExecLogic(node, ctx, &output); if (ctx->code) { @@ -1007,9 +1316,9 @@ EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_CONTINUE; } -EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) { +EDealRes sclWalkOperator(SNode *pNode, SScalarCtx *ctx) { SOperatorNode *node = (SOperatorNode *)pNode; - SScalarParam output = {0}; + SScalarParam output = {0}; ctx->code = sclExecOperator(node, ctx, &output); if (ctx->code) { @@ -1024,18 +1333,19 @@ EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_CONTINUE; } -EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { +EDealRes sclWalkTarget(SNode *pNode, SScalarCtx *ctx) { STargetNode *target = (STargetNode *)pNode; if (target->dataBlockId >= taosArrayGetSize(ctx->pBlockList)) { - sclError("target tupleId is too big, tupleId:%d, dataBlockNum:%d", target->dataBlockId, (int32_t)taosArrayGetSize(ctx->pBlockList)); + sclError("target tupleId is too big, tupleId:%d, dataBlockNum:%d", target->dataBlockId, + (int32_t)taosArrayGetSize(ctx->pBlockList)); ctx->code = TSDB_CODE_QRY_INVALID_INPUT; return DEAL_RES_ERROR; } int32_t index = -1; - for(int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) { - SSDataBlock* pb = taosArrayGetP(ctx->pBlockList, i); + for (int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) { + SSDataBlock *pb = taosArrayGetP(ctx->pBlockList, i); if (pb->info.blockId == target->dataBlockId) { index = i; break; @@ -1043,7 +1353,8 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { } if (index == -1) { - sclError("column tupleId is too big, tupleId:%d, dataBlockNum:%d", target->dataBlockId, (int32_t)taosArrayGetSize(ctx->pBlockList)); + sclError("column tupleId is too big, tupleId:%d, dataBlockNum:%d", target->dataBlockId, + (int32_t)taosArrayGetSize(ctx->pBlockList)); ctx->code = TSDB_CODE_QRY_INVALID_INPUT; return DEAL_RES_ERROR; } @@ -1051,7 +1362,8 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { SSDataBlock *block = *(SSDataBlock **)taosArrayGet(ctx->pBlockList, index); if (target->slotId >= taosArrayGetSize(block->pDataBlock)) { - sclError("target slot not exist, dataBlockId:%d, slotId:%d, dataBlockNum:%d", target->dataBlockId, target->slotId, (int32_t)taosArrayGetSize(block->pDataBlock)); + sclError("target slot not exist, dataBlockId:%d, slotId:%d, dataBlockNum:%d", target->dataBlockId, target->slotId, + (int32_t)taosArrayGetSize(block->pDataBlock)); ctx->code = TSDB_CODE_QRY_INVALID_INPUT; return DEAL_RES_ERROR; } @@ -1074,12 +1386,36 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_CONTINUE; } -EDealRes sclCalcWalker(SNode* pNode, void* pContext) { - if (QUERY_NODE_VALUE == nodeType(pNode) || QUERY_NODE_NODE_LIST == nodeType(pNode) || QUERY_NODE_COLUMN == nodeType(pNode)|| QUERY_NODE_LEFT_VALUE == nodeType(pNode)) { +EDealRes sclWalkCaseWhen(SNode* pNode, SScalarCtx *ctx) { + SCaseWhenNode *node = (SCaseWhenNode *)pNode; + SScalarParam output = {0}; + + ctx->code = sclExecCaseWhen(node, ctx, &output); + if (ctx->code) { + return DEAL_RES_ERROR; + } + + if (taosHashPut(ctx->pRes, &pNode, POINTER_BYTES, &output, sizeof(output))) { + ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY; + return DEAL_RES_ERROR; + } + + return DEAL_RES_CONTINUE; +} + + +EDealRes sclCalcWalker(SNode *pNode, void *pContext) { + if (QUERY_NODE_VALUE == nodeType(pNode) || QUERY_NODE_NODE_LIST == nodeType(pNode) + || QUERY_NODE_COLUMN == nodeType(pNode) || QUERY_NODE_LEFT_VALUE == nodeType(pNode) + || QUERY_NODE_WHEN_THEN == nodeType(pNode)) { return DEAL_RES_CONTINUE; } SScalarCtx *ctx = (SScalarCtx *)pContext; + if (QUERY_NODE_OPERATOR == nodeType(pNode)) { + return sclWalkOperator(pNode, ctx); + } + if (QUERY_NODE_FUNCTION == nodeType(pNode)) { return sclWalkFunction(pNode, ctx); } @@ -1088,44 +1424,25 @@ EDealRes sclCalcWalker(SNode* pNode, void* pContext) { return sclWalkLogic(pNode, ctx); } - if (QUERY_NODE_OPERATOR == nodeType(pNode)) { - return sclWalkOperator(pNode, ctx); - } - if (QUERY_NODE_TARGET == nodeType(pNode)) { return sclWalkTarget(pNode, ctx); } + if (QUERY_NODE_CASE_WHEN == nodeType(pNode)) { + return sclWalkCaseWhen(pNode, ctx); + } + sclError("invalid node type for scalar calculating, type:%d", nodeType(pNode)); ctx->code = TSDB_CODE_QRY_INVALID_INPUT; return DEAL_RES_ERROR; } -int32_t sclExtendResRows(SScalarParam *pDst, SScalarParam *pSrc, SArray *pBlockList) { - SSDataBlock* pb = taosArrayGetP(pBlockList, 0); - SScalarParam *pLeft = taosMemoryCalloc(1, sizeof(SScalarParam)); - if (NULL == pLeft) { - sclError("calloc %d failed", (int32_t)sizeof(SScalarParam)); - SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - pLeft->numOfRows = pb->info.rows; - colInfoDataEnsureCapacity(pDst->columnData, pb->info.rows); - - _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(OP_TYPE_ASSIGN); - OperatorFn(pLeft, pSrc, pDst, TSDB_ORDER_ASC); - - taosMemoryFree(pLeft); - - return TSDB_CODE_SUCCESS; -} - int32_t sclCalcConstants(SNode *pNode, bool dual, SNode **pRes) { if (NULL == pNode) { SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - int32_t code = 0; + int32_t code = 0; SScalarCtx ctx = {0}; ctx.dual = dual; ctx.pRes = taosHashInit(SCL_DEFAULT_OP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); @@ -1144,8 +1461,8 @@ _return: return code; } -static int32_t sclGetMinusOperatorResType(SOperatorNode* pOp) { - if (!IS_MATHABLE_TYPE(((SExprNode*)(pOp->pLeft))->resType.type)) { +static int32_t sclGetMinusOperatorResType(SOperatorNode *pOp) { + if (!IS_MATHABLE_TYPE(((SExprNode *)(pOp->pLeft))->resType.type)) { return TSDB_CODE_TSC_INVALID_OPERATION; } pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; @@ -1153,9 +1470,9 @@ static int32_t sclGetMinusOperatorResType(SOperatorNode* pOp) { return TSDB_CODE_SUCCESS; } -static int32_t sclGetMathOperatorResType(SOperatorNode* pOp) { - SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; - SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; +static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) { + SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType; + SDataType rdt = ((SExprNode *)(pOp->pRight))->resType; if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) || (TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type) || IS_FLOAT_TYPE(rdt.type))) || (TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) { @@ -1175,12 +1492,12 @@ static int32_t sclGetMathOperatorResType(SOperatorNode* pOp) { return TSDB_CODE_SUCCESS; } -static int32_t sclGetCompOperatorResType(SOperatorNode* pOp) { - SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; +static int32_t sclGetCompOperatorResType(SOperatorNode *pOp) { + SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType; if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) { - ((SExprNode*)(pOp->pRight))->resType = ldt; + ((SExprNode *)(pOp->pRight))->resType = ldt; } else if (nodesIsRegularOp(pOp)) { - SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; + SDataType rdt = ((SExprNode *)(pOp->pRight))->resType; if (!IS_VAR_DATA_TYPE(ldt.type) || QUERY_NODE_VALUE != nodeType(pOp->pRight) || (!IS_STR_DATA_TYPE(rdt.type) && (rdt.type != TSDB_DATA_TYPE_NULL))) { return TSDB_CODE_TSC_INVALID_OPERATION; @@ -1191,9 +1508,9 @@ static int32_t sclGetCompOperatorResType(SOperatorNode* pOp) { return TSDB_CODE_SUCCESS; } -static int32_t sclGetJsonOperatorResType(SOperatorNode* pOp) { - SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; - SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; +static int32_t sclGetJsonOperatorResType(SOperatorNode *pOp) { + SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType; + SDataType rdt = ((SExprNode *)(pOp->pRight))->resType; if (TSDB_DATA_TYPE_JSON != ldt.type || !IS_STR_DATA_TYPE(rdt.type)) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -1206,27 +1523,22 @@ static int32_t sclGetJsonOperatorResType(SOperatorNode* pOp) { return TSDB_CODE_SUCCESS; } -static int32_t sclGetBitwiseOperatorResType(SOperatorNode* pOp) { +static int32_t sclGetBitwiseOperatorResType(SOperatorNode *pOp) { pOp->node.resType.type = TSDB_DATA_TYPE_BIGINT; pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; return TSDB_CODE_SUCCESS; } +int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { return sclCalcConstants(pNode, false, pRes); } -int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { - return sclCalcConstants(pNode, false, pRes); -} - -int32_t scalarCalculateConstantsFromDual(SNode *pNode, SNode **pRes) { - return sclCalcConstants(pNode, true, pRes); -} +int32_t scalarCalculateConstantsFromDual(SNode *pNode, SNode **pRes) { return sclCalcConstants(pNode, true, pRes); } int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { if (NULL == pNode || NULL == pBlockList) { SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - int32_t code = 0; + int32_t code = 0; SScalarCtx ctx = {.code = 0, .pBlockList = pBlockList, .param = pDst ? pDst->param : NULL}; // TODO: OPT performance @@ -1264,9 +1576,9 @@ _return: return code; } -int32_t scalarGetOperatorResultType(SOperatorNode* pOp) { - if (TSDB_DATA_TYPE_BLOB == ((SExprNode*)(pOp->pLeft))->resType.type || - (NULL != pOp->pRight && TSDB_DATA_TYPE_BLOB == ((SExprNode*)(pOp->pRight))->resType.type)) { +int32_t scalarGetOperatorResultType(SOperatorNode *pOp) { + if (TSDB_DATA_TYPE_BLOB == ((SExprNode *)(pOp->pLeft))->resType.type || + (NULL != pOp->pRight && TSDB_DATA_TYPE_BLOB == ((SExprNode *)(pOp->pRight))->resType.type)) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -1280,7 +1592,7 @@ int32_t scalarGetOperatorResultType(SOperatorNode* pOp) { case OP_TYPE_MINUS: return sclGetMinusOperatorResType(pOp); case OP_TYPE_ASSIGN: - pOp->node.resType = ((SExprNode*)(pOp->pLeft))->resType; + pOp->node.resType = ((SExprNode *)(pOp->pLeft))->resType; break; case OP_TYPE_BIT_AND: case OP_TYPE_BIT_OR: diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 91044a96b53aed1c8d32c8fc57278f9b14499fd5..339065633bce5107df2879d45fbf259609a544a6 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1,3 +1,4 @@ +#include "cJSON.h" #include "function.h" #include "scalar.h" #include "sclInt.h" @@ -5,20 +6,17 @@ #include "tdatablock.h" #include "tjson.h" #include "ttime.h" -#include "cJSON.h" #include "vnode.h" typedef float (*_float_fn)(float); typedef double (*_double_fn)(double); typedef double (*_double_fn_2)(double, double); typedef int (*_conv_fn)(int); -typedef void (*_trim_fn)(char *, char*, int32_t, int32_t); +typedef void (*_trim_fn)(char *, char *, int32_t, int32_t); typedef int16_t (*_len_fn)(char *, int32_t); /** Math functions **/ -static double tlog(double v) { - return log(v); -} +static double tlog(double v) { return log(v); } static double tlog2(double v, double base) { double a = log(v); @@ -33,86 +31,86 @@ static double tlog2(double v, double base) { } int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t type = GET_PARAM_TYPE(pInput); switch (type) { case TSDB_DATA_TYPE_FLOAT: { - float *in = (float *)pInputData->pData; + float *in = (float *)pInputData->pData; float *out = (float *)pOutputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { colDataAppendNULL(pOutputData, i); continue; } - out[i] = (in[i] >= 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0) ? in[i] : -in[i]; } break; } case TSDB_DATA_TYPE_DOUBLE: { - double *in = (double *)pInputData->pData; + double *in = (double *)pInputData->pData; double *out = (double *)pOutputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { colDataAppendNULL(pOutputData, i); continue; } - out[i] = (in[i] >= 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0) ? in[i] : -in[i]; } break; } case TSDB_DATA_TYPE_TINYINT: { - int8_t *in = (int8_t *)pInputData->pData; + int8_t *in = (int8_t *)pInputData->pData; int8_t *out = (int8_t *)pOutputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { colDataAppendNULL(pOutputData, i); continue; } - out[i] = (in[i] >= 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0) ? in[i] : -in[i]; } break; } case TSDB_DATA_TYPE_SMALLINT: { - int16_t *in = (int16_t *)pInputData->pData; + int16_t *in = (int16_t *)pInputData->pData; int16_t *out = (int16_t *)pOutputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { colDataAppendNULL(pOutputData, i); continue; } - out[i] = (in[i] >= 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0) ? in[i] : -in[i]; } break; } case TSDB_DATA_TYPE_INT: { - int32_t *in = (int32_t *)pInputData->pData; + int32_t *in = (int32_t *)pInputData->pData; int32_t *out = (int32_t *)pOutputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { colDataAppendNULL(pOutputData, i); continue; } - out[i] = (in[i] >= 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0) ? in[i] : -in[i]; } break; } case TSDB_DATA_TYPE_BIGINT: { - int64_t *in = (int64_t *)pInputData->pData; + int64_t *in = (int64_t *)pInputData->pData; int64_t *out = (int64_t *)pOutputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { colDataAppendNULL(pOutputData, i); continue; } - out[i] = (in[i] >= 0)? in[i] : -in[i]; + out[i] = (in[i] >= 0) ? in[i] : -in[i]; } break; } @@ -133,7 +131,7 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu return TSDB_CODE_SUCCESS; } -static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn valFn) { +static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _double_fn valFn) { int32_t type = GET_PARAM_TYPE(pInput); SColumnInfoData *pInputData = pInput->columnData; @@ -160,28 +158,26 @@ static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SS return TSDB_CODE_SUCCESS; } -static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn_2 valFn) { - SColumnInfoData *pInputData[2]; - SColumnInfoData *pOutputData = pOutput->columnData; +static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, + _double_fn_2 valFn) { + SColumnInfoData *pInputData[2]; + SColumnInfoData *pOutputData = pOutput->columnData; _getDoubleValue_fn_t getValueFn[2]; for (int32_t i = 0; i < inputNum; ++i) { pInputData[i] = pInput[i].columnData; - getValueFn[i]= getVectorDoubleValueFn(GET_PARAM_TYPE(&pInput[i])); + getValueFn[i] = getVectorDoubleValueFn(GET_PARAM_TYPE(&pInput[i])); } double *out = (double *)pOutputData->pData; - double result; + double result; - bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || - IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1]))); + bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1]))); int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows); if (pInput[0].numOfRows == pInput[1].numOfRows) { for (int32_t i = 0; i < numOfRows; ++i) { - if (colDataIsNull_s(pInputData[0], i) || - colDataIsNull_s(pInputData[1], i) || - hasNullType) { + if (colDataIsNull_s(pInputData[0], i) || colDataIsNull_s(pInputData[1], i) || hasNullType) { colDataAppendNULL(pOutputData, i); continue; } @@ -192,7 +188,7 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S out[i] = result; } } - } else if (pInput[0].numOfRows == 1) { //left operand is constant + } else if (pInput[0].numOfRows == 1) { // left operand is constant if (colDataIsNull_s(pInputData[0], 0) || hasNullType) { colDataAppendNNULL(pOutputData, 0, pInput[1].numOfRows); } else { @@ -236,15 +232,16 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S return TSDB_CODE_SUCCESS; } -static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _float_fn f1, _double_fn d1) { +static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _float_fn f1, + _double_fn d1) { int32_t type = GET_PARAM_TYPE(pInput); - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; switch (type) { case TSDB_DATA_TYPE_FLOAT: { - float *in = (float *)pInputData->pData; + float *in = (float *)pInputData->pData; float *out = (float *)pOutputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { @@ -258,7 +255,7 @@ static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP } case TSDB_DATA_TYPE_DOUBLE: { - double *in = (double *)pInputData->pData; + double *in = (double *)pInputData->pData; double *out = (double *)pOutputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { @@ -288,14 +285,12 @@ static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP } /** String functions **/ -static int16_t tlength(char *input, int32_t type) { - return varDataLen(input); -} +static int16_t tlength(char *input, int32_t type) { return varDataLen(input); } static int16_t tcharlength(char *input, int32_t type) { if (type == TSDB_DATA_TYPE_VARCHAR) { return varDataLen(input); - } else { //NCHAR + } else { // NCHAR return varDataLen(input) / TSDB_NCHAR_SIZE; } } @@ -309,7 +304,7 @@ static void tltrim(char *input, char *output, int32_t type, int32_t charLen) { } numOfSpaces++; } - } else { //NCHAR + } else { // NCHAR for (int32_t i = 0; i < charLen; ++i) { if (!iswspace(*((uint32_t *)varDataVal(input) + i))) { break; @@ -339,7 +334,7 @@ static void trtrim(char *input, char *output, int32_t type, int32_t charLen) { } numOfSpaces++; } - } else { //NCHAR + } else { // NCHAR for (int32_t i = charLen - 1; i >= 0; --i) { if (!iswspace(*((uint32_t *)varDataVal(input) + i))) { break; @@ -362,7 +357,7 @@ static void trtrim(char *input, char *output, int32_t type, int32_t charLen) { static int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _len_fn lenFn) { int32_t type = GET_PARAM_TYPE(pInput); - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; ASSERT(pOutputData->info.type == TSDB_DATA_TYPE_BIGINT); @@ -386,7 +381,7 @@ static int32_t concatCopyHelper(const char *input, char *output, bool hasNchar, if (hasNchar && type == TSDB_DATA_TYPE_VARCHAR) { TdUcs4 *newBuf = taosMemoryCalloc((varDataLen(input) + 1) * TSDB_NCHAR_SIZE, 1); int32_t len = varDataLen(input); - bool ret = taosMbsToUcs4(varDataVal(input), len, newBuf, (varDataLen(input) + 1) * TSDB_NCHAR_SIZE, &len); + bool ret = taosMbsToUcs4(varDataVal(input), len, newBuf, (varDataLen(input) + 1) * TSDB_NCHAR_SIZE, &len); if (!ret) { taosMemoryFree(newBuf); return TSDB_CODE_FAILED; @@ -415,15 +410,15 @@ static int32_t getNumOfNullEntries(SColumnInfoData *pColumnInfoData, int32_t num } int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - int32_t ret = TSDB_CODE_SUCCESS; + int32_t ret = TSDB_CODE_SUCCESS; SColumnInfoData **pInputData = taosMemoryCalloc(inputNum, sizeof(SColumnInfoData *)); - SColumnInfoData *pOutputData = pOutput->columnData; - char **input = taosMemoryCalloc(inputNum, POINTER_BYTES); - char *outputBuf = NULL; + SColumnInfoData *pOutputData = pOutput->columnData; + char **input = taosMemoryCalloc(inputNum, POINTER_BYTES); + char *outputBuf = NULL; int32_t inputLen = 0; int32_t numOfRows = 0; - bool hasNchar = (GET_PARAM_TYPE(pOutput) == TSDB_DATA_TYPE_NCHAR) ? true : false; + bool hasNchar = (GET_PARAM_TYPE(pOutput) == TSDB_DATA_TYPE_NCHAR) ? true : false; for (int32_t i = 0; i < inputNum; ++i) { if (pInput[i].numOfRows > numOfRows) { numOfRows = pInput[i].numOfRows; @@ -451,8 +446,7 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu for (int32_t k = 0; k < numOfRows; ++k) { bool hasNull = false; for (int32_t i = 0; i < inputNum; ++i) { - if (colDataIsNull_s(pInputData[i], k) || - IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) { + if (colDataIsNull_s(pInputData[i], k) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) { colDataAppendNULL(pOutputData, k); hasNull = true; break; @@ -463,7 +457,6 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu continue; } - int16_t dataLen = 0; for (int32_t i = 0; i < inputNum; ++i) { int32_t rowIdx = (pInput[i].numOfRows == 1) ? 0 : k; @@ -489,17 +482,16 @@ DONE: return ret; } - int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - int32_t ret = TSDB_CODE_SUCCESS; + int32_t ret = TSDB_CODE_SUCCESS; SColumnInfoData **pInputData = taosMemoryCalloc(inputNum, sizeof(SColumnInfoData *)); - SColumnInfoData *pOutputData = pOutput->columnData; - char **input = taosMemoryCalloc(inputNum, POINTER_BYTES); - char *outputBuf = NULL; + SColumnInfoData *pOutputData = pOutput->columnData; + char **input = taosMemoryCalloc(inputNum, POINTER_BYTES); + char *outputBuf = NULL; int32_t inputLen = 0; int32_t numOfRows = 0; - bool hasNchar = (GET_PARAM_TYPE(pOutput) == TSDB_DATA_TYPE_NCHAR) ? true : false; + bool hasNchar = (GET_PARAM_TYPE(pOutput) == TSDB_DATA_TYPE_NCHAR) ? true : false; for (int32_t i = 1; i < inputNum; ++i) { if (pInput[i].numOfRows > numOfRows) { numOfRows = pInput[i].numOfRows; @@ -515,7 +507,8 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p int32_t numOfNulls = getNumOfNullEntries(pInputData[i], pInput[i].numOfRows); if (i == 0) { // calculate required separator space - inputLen += (pInputData[0]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * (inputNum - 2) * factor; + inputLen += + (pInputData[0]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * (inputNum - 2) * factor; } else if (pInput[i].numOfRows == 1) { inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * factor; } else { @@ -528,17 +521,15 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p char *output = outputBuf; for (int32_t k = 0; k < numOfRows; ++k) { - if (colDataIsNull_s(pInputData[0], k) || - IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0]))) { + if (colDataIsNull_s(pInputData[0], k) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0]))) { colDataAppendNULL(pOutputData, k); continue; } int16_t dataLen = 0; - bool hasNull = false; + bool hasNull = false; for (int32_t i = 1; i < inputNum; ++i) { - if (colDataIsNull_s(pInputData[i], k) || - IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) { + if (colDataIsNull_s(pInputData[i], k) || IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[i]))) { hasNull = true; break; } @@ -551,11 +542,10 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p goto DONE; } - if (i < inputNum - 1) { - //insert the separator + // insert the separator char *sep = (pInput[0].numOfRows == 1) ? colDataGetData(pInputData[0], 0) : colDataGetData(pInputData[0], k); - ret = concatCopyHelper(sep, output, hasNchar, GET_PARAM_TYPE(&pInput[0]), &dataLen); + ret = concatCopyHelper(sep, output, hasNchar, GET_PARAM_TYPE(&pInput[0]), &dataLen); if (ret != TSDB_CODE_SUCCESS) { goto DONE; } @@ -585,12 +575,12 @@ DONE: static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _conv_fn convFn) { int32_t type = GET_PARAM_TYPE(pInput); - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t outputLen = pInputData->varmeta.length; - char *outputBuf = taosMemoryCalloc(outputLen, 1); - char *output = outputBuf; + char *outputBuf = taosMemoryCalloc(outputLen, 1); + char *output = outputBuf; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { @@ -598,13 +588,13 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala continue; } - char *input = colDataGetData(pInput[0].columnData, i); + char *input = colDataGetData(pInput[0].columnData, i); int32_t len = varDataLen(input); if (type == TSDB_DATA_TYPE_VARCHAR) { for (int32_t j = 0; j < len; ++j) { *(varDataVal(output) + j) = convFn(*(varDataVal(input) + j)); } - } else { //NCHAR + } else { // NCHAR for (int32_t j = 0; j < len / TSDB_NCHAR_SIZE; ++j) { *((uint32_t *)varDataVal(output) + j) = convFn(*((uint32_t *)varDataVal(input) + j)); } @@ -620,16 +610,15 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala return TSDB_CODE_SUCCESS; } - static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, _trim_fn trimFn) { int32_t type = GET_PARAM_TYPE(pInput); - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t outputLen = pInputData->varmeta.length; - char *outputBuf = taosMemoryCalloc(outputLen, 1); - char *output = outputBuf; + char *outputBuf = taosMemoryCalloc(outputLen, 1); + char *output = outputBuf; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { @@ -637,7 +626,7 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar continue; } - char *input = colDataGetData(pInputData, i); + char *input = colDataGetData(pInputData, i); int32_t len = varDataLen(input); int32_t charLen = (type == TSDB_DATA_TYPE_VARCHAR) ? len : len / TSDB_NCHAR_SIZE; trimFn(input, output, type, charLen); @@ -662,19 +651,19 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu subLen = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subLen : subLen * TSDB_NCHAR_SIZE; } - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t outputLen = pInputData->varmeta.length * pInput->numOfRows; - char *outputBuf = taosMemoryCalloc(outputLen, 1); - char *output = outputBuf; + char *outputBuf = taosMemoryCalloc(outputLen, 1); + char *output = outputBuf; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { colDataAppendNULL(pOutputData, i); continue; } - char *input = colDataGetData(pInput[0].columnData, i); + char *input = colDataGetData(pInput[0].columnData, i); int32_t len = varDataLen(input); int32_t startPosBytes; @@ -682,7 +671,8 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu startPosBytes = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? subPos - 1 : (subPos - 1) * TSDB_NCHAR_SIZE; startPosBytes = TMIN(startPosBytes, len); } else { - startPosBytes = (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? len + subPos : len + subPos * TSDB_NCHAR_SIZE; + startPosBytes = + (GET_PARAM_TYPE(pInput) == TSDB_DATA_TYPE_VARCHAR) ? len + subPos : len + subPos * TSDB_NCHAR_SIZE; startPosBytes = TMAX(startPosBytes, 0); } @@ -692,7 +682,7 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu } varDataSetLen(output, resLen); - colDataAppend(pOutputData, i , output, false); + colDataAppend(pOutputData, i, output, false); output += varDataTLen(output); } @@ -704,14 +694,14 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu /** Conversion functions **/ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - int16_t inputType = GET_PARAM_TYPE(&pInput[0]); - int16_t inputLen = GET_PARAM_BYTES(&pInput[0]); + int16_t inputType = GET_PARAM_TYPE(&pInput[0]); + int16_t inputLen = GET_PARAM_BYTES(&pInput[0]); int16_t outputType = GET_PARAM_TYPE(&pOutput[0]); - int64_t outputLen = GET_PARAM_BYTES(&pOutput[0]); + int64_t outputLen = GET_PARAM_BYTES(&pOutput[0]); int32_t code = TSDB_CODE_SUCCESS; - char * convBuf = taosMemoryMalloc(inputLen); - char * output = taosMemoryCalloc(1, outputLen + TSDB_NCHAR_SIZE); + char *convBuf = taosMemoryMalloc(inputLen); + char *output = taosMemoryCalloc(1, outputLen + TSDB_NCHAR_SIZE); char buf[400] = {0}; if (convBuf == NULL || output == NULL) { @@ -727,14 +717,14 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp char *input = colDataGetData(pInput[0].columnData, i); - switch(outputType) { + switch (outputType) { case TSDB_DATA_TYPE_TINYINT: { if (inputType == TSDB_DATA_TYPE_BINARY) { memcpy(buf, varDataVal(input), varDataLen(input)); buf[varDataLen(input)] = 0; *(int8_t *)output = taosStr2Int8(buf, NULL, 10); } else if (inputType == TSDB_DATA_TYPE_NCHAR) { - int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); if (len < 0) { code = TSDB_CODE_FAILED; goto _end; @@ -753,7 +743,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp buf[varDataLen(input)] = 0; *(int16_t *)output = taosStr2Int16(buf, NULL, 10); } else if (inputType == TSDB_DATA_TYPE_NCHAR) { - int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); if (len < 0) { code = TSDB_CODE_FAILED; goto _end; @@ -771,7 +761,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp buf[varDataLen(input)] = 0; *(int32_t *)output = taosStr2Int32(buf, NULL, 10); } else if (inputType == TSDB_DATA_TYPE_NCHAR) { - int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); if (len < 0) { code = TSDB_CODE_FAILED; goto _end; @@ -790,7 +780,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp buf[varDataLen(input)] = 0; *(int64_t *)output = taosStr2Int64(buf, NULL, 10); } else if (inputType == TSDB_DATA_TYPE_NCHAR) { - int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); if (len < 0) { code = TSDB_CODE_FAILED; goto _end; @@ -881,7 +871,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp buf[varDataLen(input)] = 0; *(float *)output = taosStr2Float(buf, NULL); } else if (inputType == TSDB_DATA_TYPE_NCHAR) { - int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); if (len < 0) { code = TSDB_CODE_FAILED; goto _end; @@ -899,7 +889,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp buf[varDataLen(input)] = 0; *(double *)output = taosStr2Double(buf, NULL); } else if (inputType == TSDB_DATA_TYPE_NCHAR) { - int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); if (len < 0) { code = TSDB_CODE_FAILED; goto _end; @@ -917,7 +907,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp buf[varDataLen(input)] = 0; *(bool *)output = taosStr2Int8(buf, NULL, 10); } else if (inputType == TSDB_DATA_TYPE_NCHAR) { - int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), convBuf); if (len < 0) { code = TSDB_CODE_FAILED; goto _end; @@ -948,7 +938,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp case TSDB_DATA_TYPE_BINARY: { if (inputType == TSDB_DATA_TYPE_BOOL) { // NOTE: sprintf will append '\0' at the end of string - int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), *(int8_t *)input ? "true" : "false"); + int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), + *(int8_t *)input ? "true" : "false"); varDataSetLen(output, len); } else if (inputType == TSDB_DATA_TYPE_BINARY) { int32_t len = TMIN(varDataLen(input), outputLen - VARSTR_HEADER_SIZE); @@ -977,7 +968,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp int32_t len; if (inputType == TSDB_DATA_TYPE_BOOL) { char tmp[8] = {0}; - len = sprintf(tmp, "%.*s", outputCharLen, *(int8_t *)input ? "true" : "false" ); + len = sprintf(tmp, "%.*s", outputCharLen, *(int8_t *)input ? "true" : "false"); bool ret = taosMbsToUcs4(tmp, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len); if (!ret) { code = TSDB_CODE_FAILED; @@ -987,7 +978,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp varDataSetLen(output, len); } else if (inputType == TSDB_DATA_TYPE_BINARY) { len = outputCharLen > varDataLen(input) ? varDataLen(input) : outputCharLen; - bool ret = taosMbsToUcs4(input + VARSTR_HEADER_SIZE, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len); + bool ret = taosMbsToUcs4(input + VARSTR_HEADER_SIZE, len, (TdUcs4 *)varDataVal(output), + outputLen - VARSTR_HEADER_SIZE, &len); if (!ret) { code = TSDB_CODE_FAILED; goto _end; @@ -1009,7 +1001,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp varDataSetLen(output, len); } - //for constant conversion, need to set proper length of pOutput description + // for constant conversion, need to set proper length of pOutput description if (len < outputLen) { pOutput->columnData->info.bytes = len + VARSTR_HEADER_SIZE; } @@ -1027,7 +1019,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp pOutput->numOfRows = pInput->numOfRows; - _end: +_end: taosMemoryFree(output); taosMemoryFree(convBuf); return code; @@ -1036,8 +1028,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t type = GET_PARAM_TYPE(pInput); - bool tzPresent = (inputNum == 2) ? true : false; - char* tz; + bool tzPresent = (inputNum == 2) ? true : false; + char *tz; int32_t tzLen; if (tzPresent) { tz = varDataVal(pInput[1].columnData->pData); @@ -1051,12 +1043,12 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * } char *input = colDataGetData(pInput[0].columnData, i); - char fraction[20] = {0}; - bool hasFraction = false; + char fraction[20] = {0}; + bool hasFraction = false; NUM_TO_STRING(type, input, sizeof(fraction), fraction); int32_t tsDigits = (int32_t)strlen(fraction); - char buf[64] = {0}; + char buf[64] = {0}; int64_t timeVal; GET_TYPED_DATA(timeVal, int64_t, type, input); if (tsDigits > TSDB_TIME_PRECISION_SEC_DIGITS) { @@ -1079,7 +1071,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S", &tmInfo); int32_t len = (int32_t)strlen(buf); - //add timezone string + // add timezone string snprintf(buf + len, tzLen + 1, "%s", tz); len += tzLen; @@ -1095,7 +1087,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * if (tzInfo) { memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); } else { - //search '-' backwards + // search '-' backwards tzInfo = strrchr(buf, '-'); if (tzInfo) { memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); @@ -1151,25 +1143,25 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu char tmp[TSDB_MAX_JSON_TAG_LEN] = {0}; for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { - SArray* pTagVals = taosArrayInit(8, sizeof(STagVal)); - STag* pTag = NULL; + SArray *pTagVals = taosArrayInit(8, sizeof(STagVal)); + STag *pTag = NULL; if (colDataIsNull_s(pInput[0].columnData, i)) { tTagNew(pTagVals, 1, true, &pTag); - }else{ + } else { char *input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[i]; - if (varDataLen(input) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE){ + if (varDataLen(input) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) { taosArrayDestroy(pTagVals); return TSDB_CODE_FAILED; } memcpy(tmp, varDataVal(input), varDataLen(input)); tmp[varDataLen(input)] = 0; - if(parseJsontoTagData(tmp, pTagVals, &pTag, NULL)){ + if (parseJsontoTagData(tmp, pTagVals, &pTag, NULL)) { tTagNew(pTagVals, 1, true, &pTag); } } - colDataAppend(pOutput->columnData, i, (const char*)pTag, false); + colDataAppend(pOutput->columnData, i, (const char *)pTag, false); tTagFree(pTag); taosArrayDestroy(pTagVals); } @@ -1186,8 +1178,8 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData); GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData); - int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : - (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); + int64_t factor = + (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); int64_t unit = timeUnit * 1000 / factor; @@ -1205,7 +1197,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara colDataAppendNULL(pOutput->columnData, i); continue; } - //If converted value is less than 10digits in second, use value in second instead + // If converted value is less than 10digits in second, use value in second instead int64_t timeValSec = timeVal / 1000000000; if (timeValSec < 1000000000) { timeVal = timeValSec; @@ -1246,7 +1238,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara timeVal = timeVal / 1000 * 1000; } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { timeVal = timeVal / 1000000 * 1000000; - } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS){ + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { timeVal = timeVal * factor; } else { colDataAppendNULL(pOutput->columnData, i); @@ -1307,7 +1299,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { timeVal = timeVal / 1000000000 / 86400 * 86400 * 1000000000; } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { - timeVal = timeVal * factor / factor / 86400* 86400 * factor; + timeVal = timeVal * factor / factor / 86400 * 86400 * factor; } else { colDataAppendNULL(pOutput->columnData, i); continue; @@ -1322,7 +1314,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { timeVal = timeVal / 1000000000 / 604800 * 604800 * 1000000000; } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { - timeVal = timeVal * factor / factor / 604800 * 604800* factor; + timeVal = timeVal * factor / factor / 604800 * 604800 * factor; } else { colDataAppendNULL(pOutput->columnData, i); continue; @@ -1335,7 +1327,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara } } - //truncate the timestamp to db precision + // truncate the timestamp to db precision switch (timePrec) { case TSDB_TIME_PRECISION_MILLI: { if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { @@ -1380,8 +1372,8 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p GET_TYPED_DATA(timePrec, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData); } - int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : - (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); + int64_t factor = + (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); int32_t numOfRows = 0; for (int32_t i = 0; i < inputNum; ++i) { @@ -1441,11 +1433,10 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p continue; } - int64_t result = (timeVal[0] >= timeVal[1]) ? (timeVal[0] - timeVal[1]) : - (timeVal[1] - timeVal[0]); + int64_t result = (timeVal[0] >= timeVal[1]) ? (timeVal[0] - timeVal[1]) : (timeVal[1] - timeVal[0]); - if (timeUnit < 0) { // if no time unit given use db precision - switch(timePrec) { + if (timeUnit < 0) { // if no time unit given use db precision + switch (timePrec) { case TSDB_TIME_PRECISION_MILLI: { result = result / 1000000; break; @@ -1461,7 +1452,7 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p } } else { int64_t unit = timeUnit * 1000 / factor; - switch(unit) { + switch (unit) { case 0: { /* 1u or 1b */ if (timePrec == TSDB_TIME_PRECISION_NANO && timeUnit == 1) { result = result / 1; @@ -1694,7 +1685,7 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf } #endif -bool getTimePseudoFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { +bool getTimePseudoFuncEnv(SFunctionNode *UNUSED_PARAM(pFunc), SFuncExecEnv *pEnv) { pEnv->calcMemSize = sizeof(int64_t); return true; } @@ -1719,13 +1710,13 @@ int32_t winDurFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu int32_t winStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { ASSERT(inputNum == 1); - colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t*) colDataGetData(pInput->columnData, 3)); + colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t *)colDataGetData(pInput->columnData, 3)); return TSDB_CODE_SUCCESS; } int32_t winEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { ASSERT(inputNum == 1); - colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t*) colDataGetData(pInput->columnData, 4)); + colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t *)colDataGetData(pInput->columnData, 4)); return TSDB_CODE_SUCCESS; } @@ -1743,7 +1734,7 @@ int32_t qTbnameFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pO /** Aggregation functions **/ int32_t countScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int64_t *out = (int64_t *)pOutputData->pData; @@ -1760,11 +1751,11 @@ int32_t countScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam } int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t type = GET_PARAM_TYPE(pInput); - bool hasNull = false; + bool hasNull = false; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { hasNull = true; @@ -1772,15 +1763,15 @@ int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * } if (IS_SIGNED_NUMERIC_TYPE(type)) { - int64_t *in = (int64_t *)pInputData->pData; + int64_t *in = (int64_t *)pInputData->pData; int64_t *out = (int64_t *)pOutputData->pData; *out += in[i]; } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { - uint64_t *in = (uint64_t *)pInputData->pData; + uint64_t *in = (uint64_t *)pInputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData; *out += in[i]; } else if (IS_FLOAT_TYPE(type)) { - double *in = (double *)pInputData->pData; + double *in = (double *)pInputData->pData; double *out = (double *)pOutputData->pData; *out += in[i]; } @@ -1795,7 +1786,7 @@ int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * } static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput, bool isMinFunc) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t type = GET_PARAM_TYPE(pInput); @@ -1813,84 +1804,84 @@ static int32_t doMinMaxScalarFunction(SScalarParam *pInput, int32_t inputNum, SS break; } - switch(type) { + switch (type) { case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_TINYINT: { - int8_t *in = (int8_t *)pInputData->pData; + int8_t *in = (int8_t *)pInputData->pData; int8_t *out = (int8_t *)pOutputData->pData; - if((in[i] > *out) ^ isMinFunc) { + if ((in[i] > *out) ^ isMinFunc) { *out = in[i]; } break; } case TSDB_DATA_TYPE_SMALLINT: { - int16_t *in = (int16_t *)pInputData->pData; + int16_t *in = (int16_t *)pInputData->pData; int16_t *out = (int16_t *)pOutputData->pData; - if((in[i] > *out) ^ isMinFunc) { + if ((in[i] > *out) ^ isMinFunc) { *out = in[i]; } break; } case TSDB_DATA_TYPE_INT: { - int32_t *in = (int32_t *)pInputData->pData; + int32_t *in = (int32_t *)pInputData->pData; int32_t *out = (int32_t *)pOutputData->pData; - if((in[i] > *out) ^ isMinFunc) { + if ((in[i] > *out) ^ isMinFunc) { *out = in[i]; } break; } case TSDB_DATA_TYPE_BIGINT: { - int64_t *in = (int64_t *)pInputData->pData; + int64_t *in = (int64_t *)pInputData->pData; int64_t *out = (int64_t *)pOutputData->pData; - if((in[i] > *out) ^ isMinFunc) { + if ((in[i] > *out) ^ isMinFunc) { *out = in[i]; } break; } case TSDB_DATA_TYPE_UTINYINT: { - uint8_t *in = (uint8_t *)pInputData->pData; + uint8_t *in = (uint8_t *)pInputData->pData; uint8_t *out = (uint8_t *)pOutputData->pData; - if((in[i] > *out) ^ isMinFunc) { + if ((in[i] > *out) ^ isMinFunc) { *out = in[i]; } break; } case TSDB_DATA_TYPE_USMALLINT: { - uint16_t *in = (uint16_t *)pInputData->pData; + uint16_t *in = (uint16_t *)pInputData->pData; uint16_t *out = (uint16_t *)pOutputData->pData; - if((in[i] > *out) ^ isMinFunc) { + if ((in[i] > *out) ^ isMinFunc) { *out = in[i]; } break; } case TSDB_DATA_TYPE_UINT: { - uint32_t *in = (uint32_t *)pInputData->pData; + uint32_t *in = (uint32_t *)pInputData->pData; uint32_t *out = (uint32_t *)pOutputData->pData; - if((in[i] > *out) ^ isMinFunc) { + if ((in[i] > *out) ^ isMinFunc) { *out = in[i]; } break; } case TSDB_DATA_TYPE_UBIGINT: { - uint64_t *in = (uint64_t *)pInputData->pData; + uint64_t *in = (uint64_t *)pInputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData; - if((in[i] > *out) ^ isMinFunc) { + if ((in[i] > *out) ^ isMinFunc) { *out = in[i]; } break; } case TSDB_DATA_TYPE_FLOAT: { - float *in = (float *)pInputData->pData; + float *in = (float *)pInputData->pData; float *out = (float *)pOutputData->pData; - if((in[i] > *out) ^ isMinFunc) { + if ((in[i] > *out) ^ isMinFunc) { *out = in[i]; } break; } case TSDB_DATA_TYPE_DOUBLE: { - double *in = (double *)pInputData->pData; + double *in = (double *)pInputData->pData; double *out = (double *)pOutputData->pData; - if((in[i] > *out) ^ isMinFunc) { + if ((in[i] > *out) ^ isMinFunc) { *out = in[i]; } break; @@ -1915,12 +1906,12 @@ int32_t maxScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * } int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t type = GET_PARAM_TYPE(pInput); int64_t count = 0; - bool hasNull = false; + bool hasNull = false; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { @@ -1928,72 +1919,72 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * break; } - switch(type) { + switch (type) { case TSDB_DATA_TYPE_TINYINT: { - int8_t *in = (int8_t *)pInputData->pData; + int8_t *in = (int8_t *)pInputData->pData; int64_t *out = (int64_t *)pOutputData->pData; *out += in[i]; count++; break; } case TSDB_DATA_TYPE_SMALLINT: { - int16_t *in = (int16_t *)pInputData->pData; + int16_t *in = (int16_t *)pInputData->pData; int64_t *out = (int64_t *)pOutputData->pData; *out += in[i]; count++; break; } case TSDB_DATA_TYPE_INT: { - int32_t *in = (int32_t *)pInputData->pData; + int32_t *in = (int32_t *)pInputData->pData; int64_t *out = (int64_t *)pOutputData->pData; *out += in[i]; count++; break; } case TSDB_DATA_TYPE_BIGINT: { - int64_t *in = (int64_t *)pInputData->pData; + int64_t *in = (int64_t *)pInputData->pData; int64_t *out = (int64_t *)pOutputData->pData; *out += in[i]; count++; break; } case TSDB_DATA_TYPE_UTINYINT: { - uint8_t *in = (uint8_t *)pInputData->pData; + uint8_t *in = (uint8_t *)pInputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData; *out += in[i]; count++; break; } case TSDB_DATA_TYPE_USMALLINT: { - uint16_t *in = (uint16_t *)pInputData->pData; + uint16_t *in = (uint16_t *)pInputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData; *out += in[i]; count++; break; } case TSDB_DATA_TYPE_UINT: { - uint32_t *in = (uint32_t *)pInputData->pData; + uint32_t *in = (uint32_t *)pInputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData; *out += in[i]; count++; break; } case TSDB_DATA_TYPE_UBIGINT: { - uint64_t *in = (uint64_t *)pInputData->pData; + uint64_t *in = (uint64_t *)pInputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData; *out += in[i]; count++; break; } case TSDB_DATA_TYPE_FLOAT: { - float *in = (float *)pInputData->pData; + float *in = (float *)pInputData->pData; float *out = (float *)pOutputData->pData; *out += in[i]; count++; break; } case TSDB_DATA_TYPE_DOUBLE: { - double *in = (double *)pInputData->pData; + double *in = (double *)pInputData->pData; double *out = (double *)pOutputData->pData; *out += in[i]; count++; @@ -2006,13 +1997,13 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * colDataAppendNULL(pOutputData, 0); } else { if (IS_SIGNED_NUMERIC_TYPE(type)) { - int64_t *out = (int64_t *)pOutputData->pData; + int64_t *out = (int64_t *)pOutputData->pData; *(double *)out = *out / (double)count; } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { - uint64_t *out = (uint64_t *)pOutputData->pData; + uint64_t *out = (uint64_t *)pOutputData->pData; *(double *)out = *out / (double)count; } else if (IS_FLOAT_TYPE(type)) { - double *out = (double *)pOutputData->pData; + double *out = (double *)pOutputData->pData; *(double *)out = *out / (double)count; } } @@ -2022,11 +2013,11 @@ int32_t avgScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * } int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t type = GET_PARAM_TYPE(pInput); - //int64_t count = 0, sum = 0, qSum = 0; + // int64_t count = 0, sum = 0, qSum = 0; bool hasNull = false; for (int32_t i = 0; i < pInput->numOfRows; ++i) { @@ -2110,7 +2101,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara #endif } - double *out = (double *)pOutputData->pData; + double *out = (double *)pOutputData->pData; if (hasNull) { colDataAppendNULL(pOutputData, 0); } else { @@ -2144,7 +2135,7 @@ int32_t stddevScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara } while (0) int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; double startVal, stepVal; @@ -2155,9 +2146,9 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa int32_t type = GET_PARAM_TYPE(pInput); int64_t count = 0; - switch(type) { + switch (type) { case TSDB_DATA_TYPE_TINYINT: { - int8_t *in = (int8_t *)pInputData->pData; + int8_t *in = (int8_t *)pInputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { continue; @@ -2169,7 +2160,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa break; } case TSDB_DATA_TYPE_SMALLINT: { - int16_t *in = (int16_t *)pInputData->pData; + int16_t *in = (int16_t *)pInputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { continue; @@ -2181,7 +2172,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa break; } case TSDB_DATA_TYPE_INT: { - int32_t *in = (int32_t *)pInputData->pData; + int32_t *in = (int32_t *)pInputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { continue; @@ -2193,7 +2184,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa break; } case TSDB_DATA_TYPE_BIGINT: { - int64_t *in = (int64_t *)pInputData->pData; + int64_t *in = (int64_t *)pInputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { continue; @@ -2205,7 +2196,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa break; } case TSDB_DATA_TYPE_UTINYINT: { - uint8_t *in = (uint8_t *)pInputData->pData; + uint8_t *in = (uint8_t *)pInputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { continue; @@ -2217,7 +2208,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa break; } case TSDB_DATA_TYPE_USMALLINT: { - uint16_t *in = (uint16_t *)pInputData->pData; + uint16_t *in = (uint16_t *)pInputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { continue; @@ -2229,7 +2220,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa break; } case TSDB_DATA_TYPE_UINT: { - uint32_t *in = (uint32_t *)pInputData->pData; + uint32_t *in = (uint32_t *)pInputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { continue; @@ -2241,7 +2232,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa break; } case TSDB_DATA_TYPE_UBIGINT: { - uint64_t *in = (uint64_t *)pInputData->pData; + uint64_t *in = (uint64_t *)pInputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { continue; @@ -2253,7 +2244,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa break; } case TSDB_DATA_TYPE_FLOAT: { - float *in = (float *)pInputData->pData; + float *in = (float *)pInputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { continue; @@ -2265,7 +2256,7 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa break; } case TSDB_DATA_TYPE_DOUBLE: { - double *in = (double *)pInputData->pData; + double *in = (double *)pInputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { continue; @@ -2292,11 +2283,10 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa matrix12 /= matrix[1][1]; char buf[64] = {0}; - size_t len = - snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%.6lf, intercept:%.6lf}", matrix02, matrix12); + size_t len = snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%.6lf, intercept:%.6lf}", matrix02, + matrix12); varDataSetLen(buf, len); colDataAppend(pOutputData, 0, buf, false); - } pOutput->numOfRows = 1; @@ -2304,13 +2294,13 @@ int32_t leastSQRScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPa } int32_t percentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t type = GET_PARAM_TYPE(pInput); double val; - bool hasNull = false; + bool hasNull = false; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { hasNull = true; @@ -2335,7 +2325,7 @@ int32_t apercentileScalarFunction(SScalarParam *pInput, int32_t inputNum, SScala } int32_t spreadScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t type = GET_PARAM_TYPE(pInput); @@ -2377,11 +2367,11 @@ int32_t spreadScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara } int32_t nonCalcScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t type = GET_PARAM_TYPE(pInput); - bool hasNull = false; + bool hasNull = false; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { @@ -2390,7 +2380,7 @@ int32_t nonCalcScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar } } - double *out = (double *)pOutputData->pData; + double *out = (double *)pOutputData->pData; if (hasNull) { colDataAppendNULL(pOutputData, 0); } else { @@ -2469,7 +2459,7 @@ typedef enum { } \ } while (0) -static int8_t getStateOpType(char* opStr) { +static int8_t getStateOpType(char *opStr) { int8_t opType; if (strncasecmp(opStr, "LT", 2) == 0) { opType = STATE_OPER_LT; @@ -2490,58 +2480,58 @@ static int8_t getStateOpType(char* opStr) { return opType; } -static bool checkStateOp(int8_t op, SColumnInfoData* pCol, int32_t index, SScalarParam *pCondParam) { - char* data = colDataGetData(pCol, index); - char* param = pCondParam->columnData->pData; +static bool checkStateOp(int8_t op, SColumnInfoData *pCol, int32_t index, SScalarParam *pCondParam) { + char *data = colDataGetData(pCol, index); + char *param = pCondParam->columnData->pData; int32_t paramType = GET_PARAM_TYPE(pCondParam); switch (pCol->info.type) { case TSDB_DATA_TYPE_TINYINT: { - int8_t v = *(int8_t*)data; + int8_t v = *(int8_t *)data; STATE_COMP(op, v, param, paramType); break; } case TSDB_DATA_TYPE_UTINYINT: { - uint8_t v = *(uint8_t*)data; + uint8_t v = *(uint8_t *)data; STATE_COMP(op, v, param, paramType); break; } case TSDB_DATA_TYPE_SMALLINT: { - int16_t v = *(int16_t*)data; + int16_t v = *(int16_t *)data; STATE_COMP(op, v, param, paramType); break; } case TSDB_DATA_TYPE_USMALLINT: { - uint16_t v = *(uint16_t*)data; + uint16_t v = *(uint16_t *)data; STATE_COMP(op, v, param, paramType); break; } case TSDB_DATA_TYPE_INT: { - int32_t v = *(int32_t*)data; + int32_t v = *(int32_t *)data; STATE_COMP(op, v, param, paramType); break; } case TSDB_DATA_TYPE_UINT: { - uint32_t v = *(uint32_t*)data; + uint32_t v = *(uint32_t *)data; STATE_COMP(op, v, param, paramType); break; } case TSDB_DATA_TYPE_BIGINT: { - int64_t v = *(int64_t*)data; + int64_t v = *(int64_t *)data; STATE_COMP(op, v, param, paramType); break; } case TSDB_DATA_TYPE_UBIGINT: { - uint64_t v = *(uint64_t*)data; + uint64_t v = *(uint64_t *)data; STATE_COMP(op, v, param, paramType); break; } case TSDB_DATA_TYPE_FLOAT: { - float v = *(float*)data; + float v = *(float *)data; STATE_COMP(op, v, param, paramType); break; } case TSDB_DATA_TYPE_DOUBLE: { - double v = *(double*)data; + double v = *(double *)data; STATE_COMP(op, v, param, paramType); break; } @@ -2553,10 +2543,10 @@ static bool checkStateOp(int8_t op, SColumnInfoData* pCol, int32_t index, SScala } int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; - int8_t op = getStateOpType(varDataVal(pInput[1].columnData->pData)); + int8_t op = getStateOpType(varDataVal(pInput[1].columnData->pData)); int64_t count = 0; for (int32_t i = 0; i < pInput->numOfRows; ++i) { @@ -2565,14 +2555,14 @@ int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar continue; } - bool ret = checkStateOp(op, pInputData, i, &pInput[2]); + bool ret = checkStateOp(op, pInputData, i, &pInput[2]); int64_t out = -1; if (ret) { out = ++count; } else { count = 0; } - colDataAppend(pOutputData, i, (char*)&out, false); + colDataAppend(pOutputData, i, (char *)&out, false); } pOutput->numOfRows = pInput->numOfRows; @@ -2580,7 +2570,7 @@ int32_t stateCountScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalar } int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int8_t op = getStateOpType(varDataVal(pInput[1].columnData->pData)); @@ -2591,12 +2581,12 @@ int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SSca continue; } - bool ret = checkStateOp(op, pInputData, i, &pInput[2]); + bool ret = checkStateOp(op, pInputData, i, &pInput[2]); int64_t out = -1; if (ret) { out = 0; } - colDataAppend(pOutputData, i, (char*)&out, false); + colDataAppend(pOutputData, i, (char *)&out, false); } pOutput->numOfRows = pInput->numOfRows; @@ -2605,7 +2595,7 @@ int32_t stateDurationScalarFunction(SScalarParam *pInput, int32_t inputNum, SSca typedef enum { UNKNOWN_BIN = 0, USER_INPUT_BIN, LINEAR_BIN, LOG_BIN } EHistoBinType; -static int8_t getHistogramBinType(char* binTypeStr) { +static int8_t getHistogramBinType(char *binTypeStr) { int8_t binType; if (strcasecmp(binTypeStr, "user_input") == 0) { binType = USER_INPUT_BIN; @@ -2627,10 +2617,11 @@ typedef struct SHistoFuncBin { double percentage; } SHistoFuncBin; -static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* binDescStr, int8_t binType, bool normalized) { - cJSON* binDesc = cJSON_Parse(binDescStr); +static bool getHistogramBinDesc(SHistoFuncBin **bins, int32_t *binNum, char *binDescStr, int8_t binType, + bool normalized) { + cJSON *binDesc = cJSON_Parse(binDescStr); int32_t numOfBins; - double* intervals; + double *intervals; if (cJSON_IsObject(binDesc)) { /* linaer/log bins */ int32_t numOfParams = cJSON_GetArraySize(binDesc); int32_t startIndex; @@ -2638,11 +2629,11 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin return false; } - cJSON* start = cJSON_GetObjectItem(binDesc, "start"); - cJSON* factor = cJSON_GetObjectItem(binDesc, "factor"); - cJSON* width = cJSON_GetObjectItem(binDesc, "width"); - cJSON* count = cJSON_GetObjectItem(binDesc, "count"); - cJSON* infinity = cJSON_GetObjectItem(binDesc, "infinity"); + cJSON *start = cJSON_GetObjectItem(binDesc, "start"); + cJSON *factor = cJSON_GetObjectItem(binDesc, "factor"); + cJSON *width = cJSON_GetObjectItem(binDesc, "width"); + cJSON *count = cJSON_GetObjectItem(binDesc, "count"); + cJSON *infinity = cJSON_GetObjectItem(binDesc, "infinity"); if (!cJSON_IsNumber(start) || !cJSON_IsNumber(count) || !cJSON_IsBool(infinity)) { return false; @@ -2719,7 +2710,7 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin } numOfBins = cJSON_GetArraySize(binDesc); intervals = taosMemoryCalloc(numOfBins, sizeof(double)); - cJSON* bin = binDesc->child; + cJSON *bin = binDesc->child; if (bin == NULL) { taosMemoryFree(intervals); return false; @@ -2756,15 +2747,15 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin } int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; SHistoFuncBin *bins; - int32_t numOfBins = 0; - int32_t totalCount = 0; + int32_t numOfBins = 0; + int32_t totalCount = 0; - int8_t binType = getHistogramBinType(varDataVal(pInput[1].columnData->pData)); - char* binDesc = varDataVal(pInput[2].columnData->pData); + int8_t binType = getHistogramBinType(varDataVal(pInput[1].columnData->pData)); + char *binDesc = varDataVal(pInput[2].columnData->pData); int64_t normalized = *(int64_t *)(pInput[3].columnData->pData); int32_t type = GET_PARAM_TYPE(pInput); @@ -2777,7 +2768,7 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP continue; } - char* data = colDataGetData(pInputData, i); + char *data = colDataGetData(pInputData, i); double v; GET_TYPED_DATA(v, double, type, data); @@ -2804,11 +2795,11 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP int32_t len; char buf[512] = {0}; if (!normalized) { - len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%" PRId64 "}", - bins[k].lower, bins[k].upper, bins[k].count); + len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%" PRId64 "}", bins[k].lower, + bins[k].upper, bins[k].count); } else { - len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%lf}", - bins[k].lower, bins[k].upper, bins[k].percentage); + len = sprintf(varDataVal(buf), "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%lf}", bins[k].lower, + bins[k].upper, bins[k].percentage); } varDataSetLen(buf, len); colDataAppend(pOutputData, k, buf, false); @@ -2820,7 +2811,7 @@ int32_t histogramScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP } int32_t selectScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - SColumnInfoData *pInputData = pInput->columnData; + SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; int32_t type = GET_PARAM_TYPE(pInput); @@ -2831,11 +2822,10 @@ int32_t selectScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara continue; } - char* data = colDataGetData(pInputData, i); + char *data = colDataGetData(pInputData, i); colDataAppend(pOutputData, i, data, false); } - pOutput->numOfRows = 1; return TSDB_CODE_SUCCESS; } diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 339b18bc06e20f5e42b75927c01429dbc32b06b3..f467721248a5949ac2cdf22abb81342c89d531b9 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -24,19 +24,20 @@ #include "tcompare.h" #include "tdatablock.h" #include "tdataformat.h" -#include "ttypes.h" #include "ttime.h" +#include "ttypes.h" -#define LEFT_COL ((pLeftCol->info.type == TSDB_DATA_TYPE_JSON ? (void*)pLeftCol : pLeftCol->pData)) -#define RIGHT_COL ((pRightCol->info.type == TSDB_DATA_TYPE_JSON ? (void*)pRightCol : pRightCol->pData)) +#define LEFT_COL ((pLeftCol->info.type == TSDB_DATA_TYPE_JSON ? (void *)pLeftCol : pLeftCol->pData)) +#define RIGHT_COL ((pRightCol->info.type == TSDB_DATA_TYPE_JSON ? (void *)pRightCol : pRightCol->pData)) -#define IS_NULL colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i) \ - || IS_JSON_NULL(pLeft->columnData->info.type, colDataGetVarData(pLeft->columnData, i)) \ - || IS_JSON_NULL(pRight->columnData->info.type, colDataGetVarData(pRight->columnData, i)) +#define IS_NULL \ + colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i) || \ + IS_JSON_NULL(pLeft->columnData->info.type, colDataGetVarData(pLeft->columnData, i)) || \ + IS_JSON_NULL(pRight->columnData->info.type, colDataGetVarData(pRight->columnData, i)) -#define IS_HELPER_NULL(col,i) colDataIsNull_s(col, i) || IS_JSON_NULL(col->info.type, colDataGetVarData(col, i)) +#define IS_HELPER_NULL(col, i) colDataIsNull_s(col, i) || IS_JSON_NULL(col->info.type, colDataGetVarData(col, i)) -void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int8_t outType){ +void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int8_t outType) { switch (outType) { case TSDB_DATA_TYPE_BOOL: { GET_TYPED_DATA(*((bool *)outData), bool, inType, inData); @@ -83,15 +84,15 @@ void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int GET_TYPED_DATA(*((double *)outData), double, inType, inData); break; } - default:{ + default: { ASSERT(0); } } } -void convertNcharToDouble(const void *inData, void *outData){ +void convertNcharToDouble(const void *inData, void *outData) { char *tmp = taosMemoryMalloc(varDataTLen(inData)); - int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(inData), varDataLen(inData), tmp); + int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(inData), varDataLen(inData), tmp); if (len < 0) { sclError("castConvert taosUcs4ToMbs error 1"); } @@ -104,9 +105,9 @@ void convertNcharToDouble(const void *inData, void *outData){ taosMemoryFreeClear(tmp); } -void convertBinaryToDouble(const void *inData, void *outData){ +void convertBinaryToDouble(const void *inData, void *outData) { char *tmp = taosMemoryCalloc(1, varDataTLen(inData)); - if(tmp == NULL){ + if (tmp == NULL) { *((double *)outData) = 0.; return; } @@ -118,165 +119,119 @@ void convertBinaryToDouble(const void *inData, void *outData){ typedef int64_t (*_getBigintValue_fn_t)(void *src, int32_t index); -int64_t getVectorBigintValue_TINYINT(void *src, int32_t index) { - return (int64_t)*((int8_t *)src + index); -} -int64_t getVectorBigintValue_UTINYINT(void *src, int32_t index) { - return (int64_t)*((uint8_t *)src + index); -} -int64_t getVectorBigintValue_SMALLINT(void *src, int32_t index) { - return (int64_t)*((int16_t *)src + index); -} -int64_t getVectorBigintValue_USMALLINT(void *src, int32_t index) { - return (int64_t)*((uint16_t *)src + index); -} -int64_t getVectorBigintValue_INT(void *src, int32_t index) { - return (int64_t)*((int32_t *)src + index); -} -int64_t getVectorBigintValue_UINT(void *src, int32_t index) { - return (int64_t)*((uint32_t *)src + index); -} -int64_t getVectorBigintValue_BIGINT(void *src, int32_t index) { - return (int64_t)*((int64_t *)src + index); -} -int64_t getVectorBigintValue_UBIGINT(void *src, int32_t index) { - return (int64_t)*((uint64_t *)src + index); -} -int64_t getVectorBigintValue_FLOAT(void *src, int32_t index) { - return (int64_t)*((float *)src + index); -} -int64_t getVectorBigintValue_DOUBLE(void *src, int32_t index) { - return (int64_t)*((double *)src + index); -} -int64_t getVectorBigintValue_BOOL(void *src, int32_t index) { - return (int64_t)*((bool *)src + index); -} - -int64_t getVectorBigintValue_JSON(void *src, int32_t index){ - ASSERT(!colDataIsNull_var(((SColumnInfoData*)src), index)); - char *data = colDataGetVarData((SColumnInfoData*)src, index); +int64_t getVectorBigintValue_TINYINT(void *src, int32_t index) { return (int64_t) * ((int8_t *)src + index); } +int64_t getVectorBigintValue_UTINYINT(void *src, int32_t index) { return (int64_t) * ((uint8_t *)src + index); } +int64_t getVectorBigintValue_SMALLINT(void *src, int32_t index) { return (int64_t) * ((int16_t *)src + index); } +int64_t getVectorBigintValue_USMALLINT(void *src, int32_t index) { return (int64_t) * ((uint16_t *)src + index); } +int64_t getVectorBigintValue_INT(void *src, int32_t index) { return (int64_t) * ((int32_t *)src + index); } +int64_t getVectorBigintValue_UINT(void *src, int32_t index) { return (int64_t) * ((uint32_t *)src + index); } +int64_t getVectorBigintValue_BIGINT(void *src, int32_t index) { return (int64_t) * ((int64_t *)src + index); } +int64_t getVectorBigintValue_UBIGINT(void *src, int32_t index) { return (int64_t) * ((uint64_t *)src + index); } +int64_t getVectorBigintValue_FLOAT(void *src, int32_t index) { return (int64_t) * ((float *)src + index); } +int64_t getVectorBigintValue_DOUBLE(void *src, int32_t index) { return (int64_t) * ((double *)src + index); } +int64_t getVectorBigintValue_BOOL(void *src, int32_t index) { return (int64_t) * ((bool *)src + index); } + +int64_t getVectorBigintValue_JSON(void *src, int32_t index) { + ASSERT(!colDataIsNull_var(((SColumnInfoData *)src), index)); + char *data = colDataGetVarData((SColumnInfoData *)src, index); double out = 0; - if (*data == TSDB_DATA_TYPE_NULL){ + if (*data == TSDB_DATA_TYPE_NULL) { return 0; - } else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY - convertNcharToDouble(data+CHAR_BYTES, &out); - } else if(tTagIsJson(data)){ + } else if (*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY + convertNcharToDouble(data + CHAR_BYTES, &out); + } else if (tTagIsJson(data)) { terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR; return 0; } else { - convertNumberToNumber(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); + convertNumberToNumber(data + CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); } return (int64_t)out; } _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) { - _getBigintValue_fn_t p = NULL; - if (srcType==TSDB_DATA_TYPE_TINYINT) { - p = getVectorBigintValue_TINYINT; - } else if (srcType==TSDB_DATA_TYPE_UTINYINT) { - p = getVectorBigintValue_UTINYINT; - } else if (srcType==TSDB_DATA_TYPE_SMALLINT) { - p = getVectorBigintValue_SMALLINT; - } else if (srcType==TSDB_DATA_TYPE_USMALLINT) { - p = getVectorBigintValue_USMALLINT; - } else if (srcType==TSDB_DATA_TYPE_INT) { - p = getVectorBigintValue_INT; - } else if (srcType==TSDB_DATA_TYPE_UINT) { - p = getVectorBigintValue_UINT; - } else if (srcType==TSDB_DATA_TYPE_BIGINT) { - p = getVectorBigintValue_BIGINT; - } else if (srcType==TSDB_DATA_TYPE_UBIGINT) { - p = getVectorBigintValue_UBIGINT; - } else if (srcType==TSDB_DATA_TYPE_FLOAT) { - p = getVectorBigintValue_FLOAT; - } else if (srcType==TSDB_DATA_TYPE_DOUBLE) { - p = getVectorBigintValue_DOUBLE; - } else if (srcType==TSDB_DATA_TYPE_TIMESTAMP) { - p = getVectorBigintValue_BIGINT; - } else if (srcType==TSDB_DATA_TYPE_BOOL) { - p = getVectorBigintValue_BOOL; - } else if (srcType==TSDB_DATA_TYPE_JSON) { - p = getVectorBigintValue_JSON; - } else if (srcType==TSDB_DATA_TYPE_NULL){ - p = NULL; - } else { - ASSERT(0); - } - return p; + _getBigintValue_fn_t p = NULL; + if (srcType == TSDB_DATA_TYPE_TINYINT) { + p = getVectorBigintValue_TINYINT; + } else if (srcType == TSDB_DATA_TYPE_UTINYINT) { + p = getVectorBigintValue_UTINYINT; + } else if (srcType == TSDB_DATA_TYPE_SMALLINT) { + p = getVectorBigintValue_SMALLINT; + } else if (srcType == TSDB_DATA_TYPE_USMALLINT) { + p = getVectorBigintValue_USMALLINT; + } else if (srcType == TSDB_DATA_TYPE_INT) { + p = getVectorBigintValue_INT; + } else if (srcType == TSDB_DATA_TYPE_UINT) { + p = getVectorBigintValue_UINT; + } else if (srcType == TSDB_DATA_TYPE_BIGINT) { + p = getVectorBigintValue_BIGINT; + } else if (srcType == TSDB_DATA_TYPE_UBIGINT) { + p = getVectorBigintValue_UBIGINT; + } else if (srcType == TSDB_DATA_TYPE_FLOAT) { + p = getVectorBigintValue_FLOAT; + } else if (srcType == TSDB_DATA_TYPE_DOUBLE) { + p = getVectorBigintValue_DOUBLE; + } else if (srcType == TSDB_DATA_TYPE_TIMESTAMP) { + p = getVectorBigintValue_BIGINT; + } else if (srcType == TSDB_DATA_TYPE_BOOL) { + p = getVectorBigintValue_BOOL; + } else if (srcType == TSDB_DATA_TYPE_JSON) { + p = getVectorBigintValue_JSON; + } else if (srcType == TSDB_DATA_TYPE_NULL) { + p = NULL; + } else { + ASSERT(0); + } + return p; } -typedef void* (*_getValueAddr_fn_t)(void *src, int32_t index); +typedef void *(*_getValueAddr_fn_t)(void *src, int32_t index); -void* getVectorValueAddr_TINYINT(void *src, int32_t index) { - return (void*)((int8_t *)src + index); -} -void* getVectorValueAddr_UTINYINT(void *src, int32_t index) { - return (void*)((uint8_t *)src + index); -} -void* getVectorValueAddr_SMALLINT(void *src, int32_t index) { - return (void*)((int16_t *)src + index); -} -void* getVectorValueAddr_USMALLINT(void *src, int32_t index) { - return (void*)((uint16_t *)src + index); -} -void* getVectorValueAddr_INT(void *src, int32_t index) { - return (void*)((int32_t *)src + index); -} -void* getVectorValueAddr_UINT(void *src, int32_t index) { - return (void*)((uint32_t *)src + index); -} -void* getVectorValueAddr_BIGINT(void *src, int32_t index) { - return (void*)((int64_t *)src + index); -} -void* getVectorValueAddr_UBIGINT(void *src, int32_t index) { - return (void*)((uint64_t *)src + index); -} -void* getVectorValueAddr_FLOAT(void *src, int32_t index) { - return (void*)((float *)src + index); -} -void* getVectorValueAddr_DOUBLE(void *src, int32_t index) { - return (void*)((double *)src + index); -} -void* getVectorValueAddr_default(void *src, int32_t index) { - return src; -} -void* getVectorValueAddr_VAR(void *src, int32_t index) { - return colDataGetData((SColumnInfoData *)src, index); -} +void *getVectorValueAddr_TINYINT(void *src, int32_t index) { return (void *)((int8_t *)src + index); } +void *getVectorValueAddr_UTINYINT(void *src, int32_t index) { return (void *)((uint8_t *)src + index); } +void *getVectorValueAddr_SMALLINT(void *src, int32_t index) { return (void *)((int16_t *)src + index); } +void *getVectorValueAddr_USMALLINT(void *src, int32_t index) { return (void *)((uint16_t *)src + index); } +void *getVectorValueAddr_INT(void *src, int32_t index) { return (void *)((int32_t *)src + index); } +void *getVectorValueAddr_UINT(void *src, int32_t index) { return (void *)((uint32_t *)src + index); } +void *getVectorValueAddr_BIGINT(void *src, int32_t index) { return (void *)((int64_t *)src + index); } +void *getVectorValueAddr_UBIGINT(void *src, int32_t index) { return (void *)((uint64_t *)src + index); } +void *getVectorValueAddr_FLOAT(void *src, int32_t index) { return (void *)((float *)src + index); } +void *getVectorValueAddr_DOUBLE(void *src, int32_t index) { return (void *)((double *)src + index); } +void *getVectorValueAddr_default(void *src, int32_t index) { return src; } +void *getVectorValueAddr_VAR(void *src, int32_t index) { return colDataGetData((SColumnInfoData *)src, index); } _getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) { - _getValueAddr_fn_t p = NULL; - if(srcType==TSDB_DATA_TYPE_TINYINT) { - p = getVectorValueAddr_TINYINT; - }else if(srcType==TSDB_DATA_TYPE_UTINYINT) { - p = getVectorValueAddr_UTINYINT; - }else if(srcType==TSDB_DATA_TYPE_SMALLINT) { - p = getVectorValueAddr_SMALLINT; - }else if(srcType==TSDB_DATA_TYPE_USMALLINT) { - p = getVectorValueAddr_USMALLINT; - }else if(srcType==TSDB_DATA_TYPE_INT) { - p = getVectorValueAddr_INT; - }else if(srcType==TSDB_DATA_TYPE_UINT) { - p = getVectorValueAddr_UINT; - }else if(srcType==TSDB_DATA_TYPE_BIGINT) { - p = getVectorValueAddr_BIGINT; - }else if(srcType==TSDB_DATA_TYPE_UBIGINT) { - p = getVectorValueAddr_UBIGINT; - }else if(srcType==TSDB_DATA_TYPE_FLOAT) { - p = getVectorValueAddr_FLOAT; - }else if(srcType==TSDB_DATA_TYPE_DOUBLE) { - p = getVectorValueAddr_DOUBLE; - }else if(srcType==TSDB_DATA_TYPE_BINARY) { - p = getVectorValueAddr_VAR; - }else if(srcType==TSDB_DATA_TYPE_NCHAR) { - p = getVectorValueAddr_VAR; - }else { - p = getVectorValueAddr_default; - } - return p; -} - -static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { + _getValueAddr_fn_t p = NULL; + if (srcType == TSDB_DATA_TYPE_TINYINT) { + p = getVectorValueAddr_TINYINT; + } else if (srcType == TSDB_DATA_TYPE_UTINYINT) { + p = getVectorValueAddr_UTINYINT; + } else if (srcType == TSDB_DATA_TYPE_SMALLINT) { + p = getVectorValueAddr_SMALLINT; + } else if (srcType == TSDB_DATA_TYPE_USMALLINT) { + p = getVectorValueAddr_USMALLINT; + } else if (srcType == TSDB_DATA_TYPE_INT) { + p = getVectorValueAddr_INT; + } else if (srcType == TSDB_DATA_TYPE_UINT) { + p = getVectorValueAddr_UINT; + } else if (srcType == TSDB_DATA_TYPE_BIGINT) { + p = getVectorValueAddr_BIGINT; + } else if (srcType == TSDB_DATA_TYPE_UBIGINT) { + p = getVectorValueAddr_UBIGINT; + } else if (srcType == TSDB_DATA_TYPE_FLOAT) { + p = getVectorValueAddr_FLOAT; + } else if (srcType == TSDB_DATA_TYPE_DOUBLE) { + p = getVectorValueAddr_DOUBLE; + } else if (srcType == TSDB_DATA_TYPE_BINARY) { + p = getVectorValueAddr_VAR; + } else if (srcType == TSDB_DATA_TYPE_NCHAR) { + p = getVectorValueAddr_VAR; + } else { + p = getVectorValueAddr_default; + } + return p; +} + +static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) { int64_t value = 0; if (taosParseTime(buf, &value, strlen(buf), pOut->columnData->info.precision, tsDaylight) != TSDB_CODE_SUCCESS) { value = 0; @@ -285,7 +240,7 @@ static FORCE_INLINE void varToTimestamp(char *buf, SScalarParam* pOut, int32_t r colDataAppendInt64(pOut->columnData, rowIndex, &value); } -static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { +static FORCE_INLINE void varToSigned(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) { if (overflow) { int64_t minValue = tDataTypes[pOut->columnData->info.type].minValue; int64_t maxValue = tDataTypes[pOut->columnData->info.type].maxValue; @@ -305,28 +260,28 @@ static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowI case TSDB_DATA_TYPE_TINYINT: { int8_t value = (int8_t)taosStr2Int8(buf, NULL, 10); - colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*)&value); + colDataAppendInt8(pOut->columnData, rowIndex, (int8_t *)&value); break; } case TSDB_DATA_TYPE_SMALLINT: { int16_t value = (int16_t)taosStr2Int16(buf, NULL, 10); - colDataAppendInt16(pOut->columnData, rowIndex, (int16_t*)&value); + colDataAppendInt16(pOut->columnData, rowIndex, (int16_t *)&value); break; } case TSDB_DATA_TYPE_INT: { int32_t value = (int32_t)taosStr2Int32(buf, NULL, 10); - colDataAppendInt32(pOut->columnData, rowIndex, (int32_t*)&value); + colDataAppendInt32(pOut->columnData, rowIndex, (int32_t *)&value); break; } case TSDB_DATA_TYPE_BIGINT: { int64_t value = (int64_t)taosStr2Int64(buf, NULL, 10); - colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*)&value); + colDataAppendInt64(pOut->columnData, rowIndex, (int64_t *)&value); break; } } } -static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { +static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) { if (overflow) { uint64_t minValue = (uint64_t)tDataTypes[pOut->columnData->info.type].minValue; uint64_t maxValue = (uint64_t)tDataTypes[pOut->columnData->info.type].maxValue; @@ -345,28 +300,28 @@ static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t ro switch (pOut->columnData->info.type) { case TSDB_DATA_TYPE_UTINYINT: { uint8_t value = (uint8_t)taosStr2UInt8(buf, NULL, 10); - colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*)&value); + colDataAppendInt8(pOut->columnData, rowIndex, (int8_t *)&value); break; } case TSDB_DATA_TYPE_USMALLINT: { uint16_t value = (uint16_t)taosStr2UInt16(buf, NULL, 10); - colDataAppendInt16(pOut->columnData, rowIndex, (int16_t*)&value); + colDataAppendInt16(pOut->columnData, rowIndex, (int16_t *)&value); break; } case TSDB_DATA_TYPE_UINT: { uint32_t value = (uint32_t)taosStr2UInt32(buf, NULL, 10); - colDataAppendInt32(pOut->columnData, rowIndex, (int32_t*)&value); + colDataAppendInt32(pOut->columnData, rowIndex, (int32_t *)&value); break; } case TSDB_DATA_TYPE_UBIGINT: { uint64_t value = (uint64_t)taosStr2UInt64(buf, NULL, 10); - colDataAppendInt64(pOut->columnData, rowIndex, (int64_t*)&value); + colDataAppendInt64(pOut->columnData, rowIndex, (int64_t *)&value); break; } } } -static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { +static FORCE_INLINE void varToFloat(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) { if (TSDB_DATA_TYPE_FLOAT == pOut->columnData->info.type) { float value = taosStr2Float(buf, NULL); colDataAppendFloat(pOut->columnData, rowIndex, &value); @@ -377,30 +332,31 @@ static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIn colDataAppendDouble(pOut->columnData, rowIndex, &value); } -static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { +static FORCE_INLINE void varToBool(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) { int64_t value = taosStr2Int64(buf, NULL, 10); - bool v = (value != 0)? true:false; - colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*) &v); + bool v = (value != 0) ? true : false; + colDataAppendInt8(pOut->columnData, rowIndex, (int8_t *)&v); } -static FORCE_INLINE void varToNchar(char* buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { +static FORCE_INLINE void varToNchar(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) { int32_t len = 0; int32_t inputLen = varDataLen(buf); int32_t outputMaxLen = (inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; - char* t = taosMemoryCalloc(1, outputMaxLen); - /*int32_t resLen = */taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4*) varDataVal(t), outputMaxLen - VARSTR_HEADER_SIZE, &len); + char *t = taosMemoryCalloc(1, outputMaxLen); + /*int32_t resLen = */ taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4 *)varDataVal(t), + outputMaxLen - VARSTR_HEADER_SIZE, &len); varDataSetLen(t, len); colDataAppend(pOut->columnData, rowIndex, t, false); taosMemoryFree(t); } -static FORCE_INLINE void ncharToVar(char* buf, SScalarParam* pOut, int32_t rowIndex, int32_t* overflow) { +static FORCE_INLINE void ncharToVar(char *buf, SScalarParam *pOut, int32_t rowIndex, int32_t *overflow) { int32_t inputLen = varDataLen(buf); - char* t = taosMemoryCalloc(1, inputLen + VARSTR_HEADER_SIZE); - int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t)); + char *t = taosMemoryCalloc(1, inputLen + VARSTR_HEADER_SIZE); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t)); if (len < 0) { taosMemoryFree(t); return; @@ -411,59 +367,58 @@ static FORCE_INLINE void ncharToVar(char* buf, SScalarParam* pOut, int32_t rowIn taosMemoryFree(t); } - //TODO opt performance, tmp is not needed. -int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType, int32_t* overflow) { +int32_t vectorConvertFromVarData(SSclVectorConvCtx *pCtx, int32_t* overflow) { bool vton = false; _bufConverteFunc func = NULL; - if (TSDB_DATA_TYPE_BOOL == outType) { + if (TSDB_DATA_TYPE_BOOL == pCtx->outType) { func = varToBool; - } else if (IS_SIGNED_NUMERIC_TYPE(outType)) { + } else if (IS_SIGNED_NUMERIC_TYPE(pCtx->outType)) { func = varToSigned; - } else if (IS_UNSIGNED_NUMERIC_TYPE(outType)) { + } else if (IS_UNSIGNED_NUMERIC_TYPE(pCtx->outType)) { func = varToUnsigned; - } else if (IS_FLOAT_TYPE(outType)) { + } else if (IS_FLOAT_TYPE(pCtx->outType)) { func = varToFloat; - } else if (outType == TSDB_DATA_TYPE_BINARY) { // nchar -> binary - ASSERT(inType == TSDB_DATA_TYPE_NCHAR); + } else if (pCtx->outType == TSDB_DATA_TYPE_BINARY) { // nchar -> binary + ASSERT(pCtx->inType == TSDB_DATA_TYPE_NCHAR); func = ncharToVar; vton = true; - } else if (outType == TSDB_DATA_TYPE_NCHAR) { // binary -> nchar - ASSERT(inType == TSDB_DATA_TYPE_VARCHAR); + } else if (pCtx->outType == TSDB_DATA_TYPE_NCHAR) { // binary -> nchar + ASSERT(pCtx->inType == TSDB_DATA_TYPE_VARCHAR); func = varToNchar; vton = true; - } else if (TSDB_DATA_TYPE_TIMESTAMP == outType) { + } else if (TSDB_DATA_TYPE_TIMESTAMP == pCtx->outType) { func = varToTimestamp; } else { - sclError("invalid convert outType:%d", outType); + sclError("invalid convert outType:%d", pCtx->outType); return TSDB_CODE_QRY_APP_ERROR; } - pOut->numOfRows = pIn->numOfRows; - for (int32_t i = 0; i < pIn->numOfRows; ++i) { - if (IS_HELPER_NULL(pIn->columnData, i)) { - colDataAppendNULL(pOut->columnData, i); + pCtx->pOut->numOfRows = pCtx->pIn->numOfRows; + for (int32_t i = pCtx->startIndex; i <= pCtx->endIndex; ++i) { + if (IS_HELPER_NULL(pCtx->pIn->columnData, i)) { + colDataAppendNULL(pCtx->pOut->columnData, i); continue; } - char* data = colDataGetVarData(pIn->columnData, i); - int32_t convertType = inType; - if(inType == TSDB_DATA_TYPE_JSON){ + char* data = colDataGetVarData(pCtx->pIn->columnData, i); + int32_t convertType = pCtx->inType; + if(pCtx->inType == TSDB_DATA_TYPE_JSON){ if(*data == TSDB_DATA_TYPE_NULL) { ASSERT(0); - } else if(*data == TSDB_DATA_TYPE_NCHAR) { + } else if (*data == TSDB_DATA_TYPE_NCHAR) { data += CHAR_BYTES; convertType = TSDB_DATA_TYPE_NCHAR; - } else if(tTagIsJson(data)){ + } else if (tTagIsJson(data)) { terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR; return terrno; } else { - convertNumberToNumber(data+CHAR_BYTES, colDataGetNumData(pOut->columnData, i), *data, outType); + convertNumberToNumber(data+CHAR_BYTES, colDataGetNumData(pCtx->pOut->columnData, i), *data, pCtx->outType); continue; } } - int32_t bufSize = pIn->columnData->info.bytes; + int32_t bufSize = pCtx->pIn->columnData->info.bytes; char *tmp = taosMemoryMalloc(varDataTLen(data)); if(!tmp){ sclError("out of memory in vectorConvertFromVarData"); @@ -475,7 +430,7 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in if (TSDB_DATA_TYPE_VARCHAR == convertType) { memcpy(tmp, varDataVal(data), varDataLen(data)); tmp[varDataLen(data)] = 0; - } else if (TSDB_DATA_TYPE_NCHAR == convertType){ + } else if (TSDB_DATA_TYPE_NCHAR == convertType) { ASSERT(varDataLen(data) <= bufSize); int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(data), varDataLen(data), tmp); @@ -488,38 +443,38 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in tmp[len] = 0; } } - - (*func)(tmp, pOut, i, overflow); + + (*func)(tmp, pCtx->pOut, i, overflow); taosMemoryFreeClear(tmp); } return TSDB_CODE_SUCCESS; } -double getVectorDoubleValue_JSON(void *src, int32_t index){ - char *data = colDataGetVarData((SColumnInfoData*)src, index); +double getVectorDoubleValue_JSON(void *src, int32_t index) { + char *data = colDataGetVarData((SColumnInfoData *)src, index); double out = 0; - if (*data == TSDB_DATA_TYPE_NULL){ + if (*data == TSDB_DATA_TYPE_NULL) { return out; - } else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY - convertNcharToDouble(data+CHAR_BYTES, &out); - } else if(tTagIsJson(data)){ + } else if (*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY + convertNcharToDouble(data + CHAR_BYTES, &out); + } else if (tTagIsJson(data)) { terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR; return 0; - } else{ - convertNumberToNumber(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); + } else { + convertNumberToNumber(data + CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); } return out; } -void* ncharTobinary(void *buf){ // todo need to remove , if tobinary is nchar +void *ncharTobinary(void *buf) { // todo need to remove , if tobinary is nchar int32_t inputLen = varDataTLen(buf); - void* t = taosMemoryCalloc(1, inputLen); - int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t)); + void *t = taosMemoryCalloc(1, inputLen); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t)); if (len < 0) { sclError("charset:%s to %s. val:%s convert ncharTobinary failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, - (char*)varDataVal(buf)); + (char *)varDataVal(buf)); taosMemoryFree(t); return NULL; } @@ -527,8 +482,9 @@ void* ncharTobinary(void *buf){ // todo need to remove , if tobinary return t; } -bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t typeRight, char **pLeftData, char **pRightData, - void *pLeftOut, void *pRightOut, bool *isNull, bool *freeLeft, bool *freeRight){ +bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t typeRight, char **pLeftData, + char **pRightData, void *pLeftOut, void *pRightOut, bool *isNull, bool *freeLeft, + bool *freeRight) { if (optr == OP_TYPE_JSON_CONTAINS) { return true; } @@ -543,7 +499,7 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t return false; } typeLeft = **pLeftData; - (*pLeftData) ++; + (*pLeftData)++; } if (typeRight == TSDB_DATA_TYPE_JSON) { if (tTagIsJson(*pLeftData)) { @@ -551,7 +507,7 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t return false; } typeRight = **pRightData; - (*pRightData) ++; + (*pRightData)++; } if (optr == OP_TYPE_LIKE || optr == OP_TYPE_NOT_LIKE || optr == OP_TYPE_MATCH || optr == OP_TYPE_NMATCH) { @@ -569,7 +525,6 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t ((typeRight == TSDB_DATA_TYPE_BOOL) && (typeLeft != TSDB_DATA_TYPE_BOOL))) return false; - if (typeLeft == TSDB_DATA_TYPE_NULL || typeRight == TSDB_DATA_TYPE_NULL) { *isNull = true; return true; @@ -586,12 +541,12 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t if (IS_NUMERIC_TYPE(type)) { if (typeLeft == TSDB_DATA_TYPE_NCHAR) { ASSERT(0); -// convertNcharToDouble(*pLeftData, pLeftOut); -// *pLeftData = pLeftOut; + // convertNcharToDouble(*pLeftData, pLeftOut); + // *pLeftData = pLeftOut; } else if (typeLeft == TSDB_DATA_TYPE_BINARY) { ASSERT(0); -// convertBinaryToDouble(*pLeftData, pLeftOut); -// *pLeftData = pLeftOut; + // convertBinaryToDouble(*pLeftData, pLeftOut); + // *pLeftData = pLeftOut; } else if (typeLeft != type) { convertNumberToNumber(*pLeftData, pLeftOut, typeLeft, type); *pLeftData = pLeftOut; @@ -599,12 +554,12 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t if (typeRight == TSDB_DATA_TYPE_NCHAR) { ASSERT(0); -// convertNcharToDouble(*pRightData, pRightOut); -// *pRightData = pRightOut; + // convertNcharToDouble(*pRightData, pRightOut); + // *pRightData = pRightOut; } else if (typeRight == TSDB_DATA_TYPE_BINARY) { ASSERT(0); -// convertBinaryToDouble(*pRightData, pRightOut); -// *pRightData = pRightOut; + // convertBinaryToDouble(*pRightData, pRightOut); + // *pRightData = pRightOut; } else if (typeRight != type) { convertNumberToNumber(*pRightData, pRightOut, typeRight, type); *pRightData = pRightOut; @@ -625,64 +580,64 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t return true; } -int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int16_t inType, int16_t outType) { - SColumnInfoData* pInputCol = pIn->columnData; - SColumnInfoData* pOutputCol = pOut->columnData; +int32_t vectorConvertToVarData(SSclVectorConvCtx *pCtx) { + SColumnInfoData* pInputCol = pCtx->pIn->columnData; + SColumnInfoData* pOutputCol = pCtx->pOut->columnData; char tmp[128] = {0}; - if (IS_SIGNED_NUMERIC_TYPE(inType) || inType == TSDB_DATA_TYPE_BOOL || inType == TSDB_DATA_TYPE_TIMESTAMP) { - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (IS_SIGNED_NUMERIC_TYPE(pCtx->inType) || pCtx->inType == TSDB_DATA_TYPE_BOOL || pCtx->inType == TSDB_DATA_TYPE_TIMESTAMP) { + for (int32_t i = pCtx->startIndex; i <= pCtx->endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } int64_t value = 0; - GET_TYPED_DATA(value, int64_t, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, int64_t, pCtx->inType, colDataGetData(pInputCol, i)); int32_t len = sprintf(varDataVal(tmp), "%" PRId64, value); varDataLen(tmp) = len; - if (outType == TSDB_DATA_TYPE_NCHAR) { - varToNchar(tmp, pOut, i, NULL); + if (pCtx->outType == TSDB_DATA_TYPE_NCHAR) { + varToNchar(tmp, pCtx->pOut, i, NULL); } else { colDataAppend(pOutputCol, i, (char *)tmp, false); } } - } else if (IS_UNSIGNED_NUMERIC_TYPE(inType)) { - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + } else if (IS_UNSIGNED_NUMERIC_TYPE(pCtx->inType)) { + for (int32_t i = pCtx->startIndex; i <= pCtx->endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } uint64_t value = 0; - GET_TYPED_DATA(value, uint64_t, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, uint64_t, pCtx->inType, colDataGetData(pInputCol, i)); int32_t len = sprintf(varDataVal(tmp), "%" PRIu64, value); varDataLen(tmp) = len; - if (outType == TSDB_DATA_TYPE_NCHAR) { - varToNchar(tmp, pOut, i, NULL); + if (pCtx->outType == TSDB_DATA_TYPE_NCHAR) { + varToNchar(tmp, pCtx->pOut, i, NULL); } else { colDataAppend(pOutputCol, i, (char *)tmp, false); } } - } else if (IS_FLOAT_TYPE(inType)) { - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + } else if (IS_FLOAT_TYPE(pCtx->inType)) { + for (int32_t i = pCtx->startIndex; i <= pCtx->endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } double value = 0; - GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, double, pCtx->inType, colDataGetData(pInputCol, i)); int32_t len = sprintf(varDataVal(tmp), "%lf", value); varDataLen(tmp) = len; - if (outType == TSDB_DATA_TYPE_NCHAR) { - varToNchar(tmp, pOut, i, NULL); + if (pCtx->outType == TSDB_DATA_TYPE_NCHAR) { + varToNchar(tmp, pCtx->pOut, i, NULL); } else { colDataAppend(pOutputCol, i, (char *)tmp, false); } } } else { - sclError("not supported input type:%d", inType); + sclError("not supported input type:%d", pCtx->inType); return TSDB_CODE_QRY_APP_ERROR; } @@ -690,7 +645,7 @@ int32_t vectorConvertToVarData(const SScalarParam* pIn, SScalarParam* pOut, int1 } // TODO opt performance -int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* overflow) { +int32_t vectorConvertSingleColImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* overflow, int32_t startIndex, int32_t numOfRows) { SColumnInfoData* pInputCol = pIn->columnData; SColumnInfoData* pOutputCol = pOut->columnData; @@ -699,25 +654,26 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* return TSDB_CODE_APP_ERROR; } - int16_t inType = pInputCol->info.type; - int16_t outType = pOutputCol->info.type; + int32_t rstart = startIndex >= 0 ? startIndex : 0; + int32_t rend = numOfRows > 0 ? rstart + numOfRows - 1 : rstart + pIn->numOfRows - 1; + SSclVectorConvCtx cCtx = {pIn, pOut, rstart, rend, pInputCol->info.type, pOutputCol->info.type}; - if (IS_VAR_DATA_TYPE(inType)) { - return vectorConvertFromVarData(pIn, pOut, inType, outType, overflow); + if (IS_VAR_DATA_TYPE(cCtx.inType)) { + return vectorConvertFromVarData(&cCtx, overflow); } if (overflow) { ASSERT(1 == pIn->numOfRows); pOut->numOfRows = 0; - - if (IS_SIGNED_NUMERIC_TYPE(outType)) { - int64_t minValue = tDataTypes[outType].minValue; - int64_t maxValue = tDataTypes[outType].maxValue; - + + if (IS_SIGNED_NUMERIC_TYPE(cCtx.outType)) { + int64_t minValue = tDataTypes[cCtx.outType].minValue; + int64_t maxValue = tDataTypes[cCtx.outType].maxValue; + double value = 0; - GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, 0)); - + GET_TYPED_DATA(value, double, cCtx.inType, colDataGetData(pInputCol, 0)); + if (value > maxValue) { *overflow = 1; return TSDB_CODE_SUCCESS; @@ -727,13 +683,13 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* } else { *overflow = 0; } - } else if (IS_UNSIGNED_NUMERIC_TYPE(outType)) { - uint64_t minValue = (uint64_t)tDataTypes[outType].minValue; - uint64_t maxValue = (uint64_t)tDataTypes[outType].maxValue; - + } else if (IS_UNSIGNED_NUMERIC_TYPE(cCtx.outType)) { + uint64_t minValue = (uint64_t)tDataTypes[cCtx.outType].minValue; + uint64_t maxValue = (uint64_t)tDataTypes[cCtx.outType].maxValue; + double value = 0; - GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, 0)); - + GET_TYPED_DATA(value, double, cCtx.inType, colDataGetData(pInputCol, 0)); + if (value > maxValue) { *overflow = 1; return TSDB_CODE_SUCCESS; @@ -747,187 +703,184 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t* } pOut->numOfRows = pIn->numOfRows; - switch (outType) { + switch (cCtx.outType) { case TSDB_DATA_TYPE_BOOL: { - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + for (int32_t i = cCtx.startIndex; i <= cCtx.endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } bool value = 0; - GET_TYPED_DATA(value, bool, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, bool, cCtx.inType, colDataGetData(pInputCol, i)); colDataAppendInt8(pOutputCol, i, (int8_t *)&value); } break; } case TSDB_DATA_TYPE_TINYINT: { - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + for (int32_t i = cCtx.startIndex; i <= cCtx.endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } int8_t value = 0; - GET_TYPED_DATA(value, int8_t, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, int8_t, cCtx.inType, colDataGetData(pInputCol, i)); colDataAppendInt8(pOutputCol, i, (int8_t *)&value); } break; } case TSDB_DATA_TYPE_SMALLINT:{ - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + for (int32_t i = cCtx.startIndex; i <= cCtx.endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } int16_t value = 0; - GET_TYPED_DATA(value, int16_t, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, int16_t, cCtx.inType, colDataGetData(pInputCol, i)); colDataAppendInt16(pOutputCol, i, (int16_t *)&value); } break; } case TSDB_DATA_TYPE_INT:{ - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + for (int32_t i = cCtx.startIndex; i <= cCtx.endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } int32_t value = 0; - GET_TYPED_DATA(value, int32_t, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, int32_t, cCtx.inType, colDataGetData(pInputCol, i)); colDataAppendInt32(pOutputCol, i, (int32_t *)&value); } break; } case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: { - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + for (int32_t i = cCtx.startIndex; i <= cCtx.endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } int64_t value = 0; - GET_TYPED_DATA(value, int64_t, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, int64_t, cCtx.inType, colDataGetData(pInputCol, i)); colDataAppendInt64(pOutputCol, i, (int64_t *)&value); } break; } case TSDB_DATA_TYPE_UTINYINT:{ - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + for (int32_t i = cCtx.startIndex; i <= cCtx.endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } uint8_t value = 0; - GET_TYPED_DATA(value, uint8_t, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, uint8_t, cCtx.inType, colDataGetData(pInputCol, i)); colDataAppendInt8(pOutputCol, i, (int8_t *)&value); } break; } case TSDB_DATA_TYPE_USMALLINT:{ - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + for (int32_t i = cCtx.startIndex; i <= cCtx.endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } uint16_t value = 0; - GET_TYPED_DATA(value, uint16_t, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, uint16_t, cCtx.inType, colDataGetData(pInputCol, i)); colDataAppendInt16(pOutputCol, i, (int16_t *)&value); } break; } case TSDB_DATA_TYPE_UINT:{ - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + for (int32_t i = cCtx.startIndex; i <= cCtx.endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } uint32_t value = 0; - GET_TYPED_DATA(value, uint32_t, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, uint32_t, cCtx.inType, colDataGetData(pInputCol, i)); colDataAppendInt32(pOutputCol, i, (int32_t *)&value); } break; } case TSDB_DATA_TYPE_UBIGINT: { - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + for (int32_t i = cCtx.startIndex; i <= cCtx.endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } uint64_t value = 0; - GET_TYPED_DATA(value, uint64_t, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, uint64_t, cCtx.inType, colDataGetData(pInputCol, i)); colDataAppendInt64(pOutputCol, i, (int64_t*)&value); } break; } case TSDB_DATA_TYPE_FLOAT:{ - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + for (int32_t i = cCtx.startIndex; i <= cCtx.endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } float value = 0; - GET_TYPED_DATA(value, float, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, float, cCtx.inType, colDataGetData(pInputCol, i)); colDataAppendFloat(pOutputCol, i, (float*)&value); } break; } case TSDB_DATA_TYPE_DOUBLE: { - for (int32_t i = 0; i < pIn->numOfRows; ++i) { + for (int32_t i = cCtx.startIndex; i <= cCtx.endIndex; ++i) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { colDataAppendNULL(pOutputCol, i); continue; } double value = 0; - GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, i)); + GET_TYPED_DATA(value, double, cCtx.inType, colDataGetData(pInputCol, i)); colDataAppendDouble(pOutputCol, i, (double*)&value); } break; } case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: { - return vectorConvertToVarData(pIn, pOut, inType, outType); + return vectorConvertToVarData(&cCtx); } default: - sclError("invalid convert output type:%d", outType); + sclError("invalid convert output type:%d", cCtx.outType); return TSDB_CODE_QRY_APP_ERROR; } return TSDB_CODE_SUCCESS; } - - -int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB+1][TSDB_DATA_TYPE_BLOB+1] = { -/* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB */ -/*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*BOOL*/ 0, 0, 2, 3, 4, 5, 6, 7, 7, 9, 7, 11, 12, 13, 14, 0, 7, 0, 0, -/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0, -/*SMAL*/ 0, 0, 0, 0, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0, -/*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 7, 9, 7, 4, 4, 5, 7, 0, 7, 0, 0, -/*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 7, 5, 5, 5, 7, 0, 7, 0, 0, -/*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 0, 7, 0, 0, -/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 0, 7, 0, 0, -/*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 7, 7, 7, 0, 0, 0, 0, -/*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 7, 0, 7, 0, 0, -/*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, -/*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 0, 7, 0, 0, -/*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 0, 7, 0, 0, -/*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 7, 0, 0, -/*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, -/*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; +int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB + 1][TSDB_DATA_TYPE_BLOB + 1] = { + /* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB */ + /*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /*BOOL*/ 0, 0, 2, 3, 4, 5, 6, 7, 7, 9, 7, 11, 12, 13, 14, 0, 7, 0, 0, + /*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0, + /*SMAL*/ 0, 0, 0, 0, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0, + /*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 7, 9, 7, 4, 4, 5, 7, 0, 7, 0, 0, + /*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 7, 5, 5, 5, 7, 0, 7, 0, 0, + /*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 0, 7, 0, 0, + /*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 0, 7, 0, 0, + /*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 7, 7, 7, 0, 0, 0, 0, + /*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 7, 0, 7, 0, 0, + /*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, + /*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 0, 7, 0, 0, + /*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 0, 7, 0, 0, + /*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 7, 0, 0, + /*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, + /*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int32_t vectorGetConvertType(int32_t type1, int32_t type2) { if (type1 == type2) { @@ -941,7 +894,7 @@ int32_t vectorGetConvertType(int32_t type1, int32_t type2) { return gConvertTypes[type2][type1]; } -int32_t vectorConvertScalarParam(SScalarParam *input, SScalarParam *output, int32_t type) { +int32_t vectorConvertSingleCol(SScalarParam *input, SScalarParam *output, int32_t type, int32_t startIndex, int32_t numOfRows) { SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; output->numOfRows = input->numOfRows; @@ -950,16 +903,15 @@ int32_t vectorConvertScalarParam(SScalarParam *input, SScalarParam *output, int3 return TSDB_CODE_OUT_OF_MEMORY; } - code = vectorConvertImpl(input, output, NULL); + code = vectorConvertSingleColImpl(input, output, NULL, startIndex, numOfRows); if (code) { -// taosMemoryFreeClear(paramOut1->data); return code; } return TSDB_CODE_SUCCESS; } -int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* pLeftOut, SScalarParam* pRightOut) { +int32_t vectorConvertCols(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* pLeftOut, SScalarParam* pRightOut, int32_t startIndex, int32_t numOfRows) { int32_t leftType = GET_PARAM_TYPE(pLeft); int32_t rightType = GET_PARAM_TYPE(pRight); if (leftType == rightType) { @@ -968,7 +920,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p SScalarParam *param1 = NULL, *paramOut1 = NULL; SScalarParam *param2 = NULL, *paramOut2 = NULL; - int32_t code = 0; + int32_t code = 0; if (leftType < rightType) { param1 = pLeft; @@ -988,14 +940,14 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p } if (type != GET_PARAM_TYPE(param1)) { - code = vectorConvertScalarParam(param1, paramOut1, type); + code = vectorConvertSingleCol(param1, paramOut1, type, startIndex, numOfRows); if (code) { return code; } } if (type != GET_PARAM_TYPE(param2)) { - code = vectorConvertScalarParam(param2, paramOut2, type); + code = vectorConvertSingleCol(param2, paramOut2, type, startIndex, numOfRows); if (code) { return code; } @@ -1009,34 +961,10 @@ enum { VECTOR_UN_CONVERT = 0x2, }; -static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SScalarParam* pParam, int32_t type) { - SColumnInfoData* pCol = pParam->columnData; - - if (IS_VAR_DATA_TYPE(pCol->info.type) && pCol->info.type != TSDB_DATA_TYPE_JSON) { - pDest->numOfRows = pParam->numOfRows; - - SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; - int32_t code = sclCreateColumnInfoData(&t, pParam->numOfRows, pDest); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - code = vectorConvertImpl(pParam, pDest, NULL); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - *convert = VECTOR_DO_CONVERT; - } else { - *convert = VECTOR_UN_CONVERT; - } - - return TSDB_CODE_SUCCESS; -} - // TODO not correct for descending order scan -static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); +static void vectorMathAddHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol, + int32_t numOfRows, int32_t step, int32_t i) { + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); double *output = (double *)pOutputCol->pData; @@ -1049,14 +977,14 @@ static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig colDataAppendNULL(pOutputCol, i); continue; // TODO set null or ignore } - *output = getVectorDoubleValueFnLeft(LEFT_COL, i) - + getVectorDoubleValueFnRight(RIGHT_COL, 0); + *output = getVectorDoubleValueFnLeft(LEFT_COL, i) + getVectorDoubleValueFnRight(RIGHT_COL, 0); } } } -static void vectorMathTsAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { - _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); +static void vectorMathTsAddHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol, + int32_t numOfRows, int32_t step, int32_t i) { + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); int64_t *output = (int64_t *)pOutputCol->pData; @@ -1069,53 +997,60 @@ static void vectorMathTsAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR colDataAppendNULL(pOutputCol, i); continue; // TODO set null or ignore } - *output = taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), getVectorBigintValueFnRight(pRightCol->pData, 0), - pRightCol->info.scale, pRightCol->info.precision); + *output = + taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), getVectorBigintValueFnRight(pRightCol->pData, 0), + pRightCol->info.scale, pRightCol->info.precision); } } } -static SColumnInfoData* doVectorConvert(SScalarParam* pInput, int32_t* doConvert) { - SScalarParam convertParam = {0}; +static SColumnInfoData* vectorConvertVarToDouble(SScalarParam* pInput, int32_t* converted) { + SScalarParam output = {0}; + SColumnInfoData* pCol = pInput->columnData; - int32_t code = doConvertHelper(&convertParam, doConvert, pInput, TSDB_DATA_TYPE_DOUBLE); - if (code != TSDB_CODE_SUCCESS) { - terrno = code; - return NULL; - } + if (IS_VAR_DATA_TYPE(pCol->info.type) && pCol->info.type != TSDB_DATA_TYPE_JSON) { + int32_t code = vectorConvertSingleCol(pInput, &output, TSDB_DATA_TYPE_DOUBLE, -1, -1); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + return NULL; + } - if (*doConvert == VECTOR_DO_CONVERT) { - return convertParam.columnData; - } else { - return pInput->columnData; + *converted = VECTOR_DO_CONVERT; + + return output.columnData; } + + *converted = VECTOR_UN_CONVERT; + + return pInput->columnData; } -static void doReleaseVec(SColumnInfoData* pCol, int32_t type) { +static void doReleaseVec(SColumnInfoData *pCol, int32_t type) { if (type == VECTOR_DO_CONVERT) { colDataDestroy(pCol); taosMemoryFree(pCol); } } -void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorMathAdd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; - int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); int32_t leftConvert = 0, rightConvert = 0; - SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); - SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + SColumnInfoData *pLeftCol = vectorConvertVarToDouble(pLeft, &leftConvert); + SColumnInfoData *pRightCol = vectorConvertVarToDouble(pRight, &rightConvert); if ((GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && IS_INTEGER_TYPE(GET_PARAM_TYPE(pRight))) || (GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && IS_INTEGER_TYPE(GET_PARAM_TYPE(pLeft))) || (GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_BOOL) || - (GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BOOL)) { //timestamp plus duration - int64_t *output = (int64_t *)pOutputCol->pData; - _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); + (GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && + GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BOOL)) { // timestamp plus duration + int64_t *output = (int64_t *)pOutputCol->pData; + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); if (pLeft->numOfRows == 1 && pRight->numOfRows == 1) { @@ -1138,13 +1073,13 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut } } } else { - double *output = (double *)pOutputCol->pData; - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + double *output = (double *)pOutputCol->pData; + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { - if (IS_NULL){ + if (IS_NULL) { colDataAppendNULL(pOutputCol, i); continue; // TODO set null or ignore } @@ -1162,8 +1097,9 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut } // TODO not correct for descending order scan -static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t factor, int32_t i) { - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); +static void vectorMathSubHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol, + int32_t numOfRows, int32_t step, int32_t factor, int32_t i) { + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); double *output = (double *)pOutputCol->pData; @@ -1176,14 +1112,14 @@ static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig colDataAppendNULL(pOutputCol, i); continue; // TODO set null or ignore } - *output = (getVectorDoubleValueFnLeft(LEFT_COL, i) - - getVectorDoubleValueFnRight(RIGHT_COL, 0)) * factor; + *output = (getVectorDoubleValueFnLeft(LEFT_COL, i) - getVectorDoubleValueFnRight(RIGHT_COL, 0)) * factor; } } } -static void vectorMathTsSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t factor, int32_t i) { - _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); +static void vectorMathTsSubHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol, + int32_t numOfRows, int32_t step, int32_t factor, int32_t i) { + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); int64_t *output = (int64_t *)pOutputCol->pData; @@ -1196,29 +1132,30 @@ static void vectorMathTsSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR colDataAppendNULL(pOutputCol, i); continue; // TODO set null or ignore } - *output = taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), -getVectorBigintValueFnRight(pRightCol->pData, 0), - pRightCol->info.scale, pRightCol->info.precision); - + *output = + taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), -getVectorBigintValueFnRight(pRightCol->pData, 0), + pRightCol->info.scale, pRightCol->info.precision); } } } -void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorMathSub(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); - int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; int32_t leftConvert = 0, rightConvert = 0; - SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); - SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + SColumnInfoData *pLeftCol = vectorConvertVarToDouble(pLeft, &leftConvert); + SColumnInfoData *pRightCol = vectorConvertVarToDouble(pRight, &rightConvert); if ((GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_BIGINT) || - (GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BIGINT)) { //timestamp minus duration - int64_t *output = (int64_t *)pOutputCol->pData; - _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); + (GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && + GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BIGINT)) { // timestamp minus duration + int64_t *output = (int64_t *)pOutputCol->pData; + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); if (pLeft->numOfRows == 1 && pRight->numOfRows == 1) { @@ -1237,8 +1174,8 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut } } } else { - double *output = (double *)pOutputCol->pData; - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + double *output = (double *)pOutputCol->pData; + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); if (pLeft->numOfRows == pRight->numOfRows) { @@ -1256,13 +1193,14 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut } } - doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pLeftCol, leftConvert); doReleaseVec(pRightCol, rightConvert); } // TODO not correct for descending order scan -static void vectorMathMultiplyHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); +static void vectorMathMultiplyHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol, + int32_t numOfRows, int32_t step, int32_t i) { + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); double *output = (double *)pOutputCol->pData; @@ -1280,18 +1218,18 @@ static void vectorMathMultiplyHelper(SColumnInfoData* pLeftCol, SColumnInfoData* } } -void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorMathMultiply(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); - int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; int32_t leftConvert = 0, rightConvert = 0; - SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); - SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + SColumnInfoData *pLeftCol = vectorConvertVarToDouble(pLeft, &leftConvert); + SColumnInfoData *pRightCol = vectorConvertVarToDouble(pRight, &rightConvert); - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); double *output = (double *)pOutputCol->pData; @@ -1313,45 +1251,44 @@ void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam doReleaseVec(pRightCol, rightConvert); } -void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorMathDivide(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); - int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; int32_t leftConvert = 0, rightConvert = 0; - SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); - SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + SColumnInfoData *pLeftCol = vectorConvertVarToDouble(pLeft, &leftConvert); + SColumnInfoData *pRightCol = vectorConvertVarToDouble(pRight, &rightConvert); - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); double *output = (double *)pOutputCol->pData; if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { - if (IS_NULL || (getVectorDoubleValueFnRight(RIGHT_COL, i) == 0)) { //divide by 0 check + if (IS_NULL || (getVectorDoubleValueFnRight(RIGHT_COL, i) == 0)) { // divide by 0 check colDataAppendNULL(pOutputCol, i); continue; } - *output = getVectorDoubleValueFnLeft(LEFT_COL, i) - / getVectorDoubleValueFnRight(RIGHT_COL, i); + *output = getVectorDoubleValueFnLeft(LEFT_COL, i) / getVectorDoubleValueFnRight(RIGHT_COL, i); } } else if (pLeft->numOfRows == 1) { if (IS_HELPER_NULL(pLeftCol, 0)) { // Set pLeft->numOfRows NULL value colDataAppendNNULL(pOutputCol, 0, pRight->numOfRows); } else { for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { - if (IS_HELPER_NULL(pRightCol, i) || (getVectorDoubleValueFnRight(RIGHT_COL, i) == 0)) { // divide by 0 check + if (IS_HELPER_NULL(pRightCol, i) || (getVectorDoubleValueFnRight(RIGHT_COL, i) == 0)) { // divide by 0 check colDataAppendNULL(pOutputCol, i); continue; } - *output = getVectorDoubleValueFnLeft(LEFT_COL, 0) - / getVectorDoubleValueFnRight(RIGHT_COL, i); + *output = getVectorDoubleValueFnLeft(LEFT_COL, 0) / getVectorDoubleValueFnRight(RIGHT_COL, i); } } } else if (pRight->numOfRows == 1) { - if (IS_HELPER_NULL(pRightCol, 0) || (getVectorDoubleValueFnRight(RIGHT_COL, 0) == 0)) { // Set pLeft->numOfRows NULL value (divde by 0 check) + if (IS_HELPER_NULL(pRightCol, 0) || + (getVectorDoubleValueFnRight(RIGHT_COL, 0) == 0)) { // Set pLeft->numOfRows NULL value (divde by 0 check) colDataAppendNNULL(pOutputCol, 0, pLeft->numOfRows); } else { for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { @@ -1359,28 +1296,27 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p colDataAppendNULL(pOutputCol, i); continue; } - *output = getVectorDoubleValueFnLeft(LEFT_COL, i) - / getVectorDoubleValueFnRight(RIGHT_COL, 0); + *output = getVectorDoubleValueFnLeft(LEFT_COL, i) / getVectorDoubleValueFnRight(RIGHT_COL, 0); } } } - doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pLeftCol, leftConvert); doReleaseVec(pRightCol, rightConvert); } -void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorMathRemainder(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); - int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; int32_t leftConvert = 0, rightConvert = 0; - SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); - SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + SColumnInfoData *pLeftCol = vectorConvertVarToDouble(pLeft, &leftConvert); + SColumnInfoData *pRightCol = vectorConvertVarToDouble(pRight, &rightConvert); - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); double *output = (double *)pOutputCol->pData; @@ -1447,18 +1383,18 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam doReleaseVec(pRightCol, rightConvert); } -void vectorMathMinus(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorMathMinus(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; pOut->numOfRows = pLeft->numOfRows; - int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : (pLeft->numOfRows - 1); - int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : (pLeft->numOfRows - 1); + int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; int32_t leftConvert = 0; - SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); + SColumnInfoData *pLeftCol = vectorConvertVarToDouble(pLeft, &leftConvert); - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); double *output = (double *)pOutputCol->pData; for (; i < pLeft->numOfRows && i >= 0; i += step, output += 1) { @@ -1470,17 +1406,17 @@ void vectorMathMinus(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO *output = (result == 0) ? 0 : -result; } - doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pLeftCol, leftConvert); } -void vectorAssign(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorAssign(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; pOut->numOfRows = pLeft->numOfRows; - if(colDataIsNull_s(pRight->columnData, 0)){ + if (colDataIsNull_s(pRight->columnData, 0)) { colDataAppendNNULL(pOutputCol, 0, pOut->numOfRows); } else { - char* d = colDataGetData(pRight->columnData, 0); + char *d = colDataGetData(pRight->columnData, 0); for (int32_t i = 0; i < pOut->numOfRows; ++i) { colDataAppend(pOutputCol, i, d, false); } @@ -1490,7 +1426,7 @@ void vectorAssign(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, pOut->numOfQualified = pRight->numOfQualified * pOut->numOfRows; } -void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +void vectorConcat(SScalarParam *pLeft, SScalarParam *pRight, void *out, int32_t _ord) { #if 0 int32_t len = pLeft->bytes + pRight->bytes; @@ -1541,8 +1477,9 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t #endif } -static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { - _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); +static void vectorBitAndHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol, + int32_t numOfRows, int32_t step, int32_t i) { + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); int64_t *output = (int64_t *)pOutputCol->pData; @@ -1560,7 +1497,7 @@ static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRigh } } -void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorBitAnd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); @@ -1568,10 +1505,10 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; int32_t leftConvert = 0, rightConvert = 0; - SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); - SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + SColumnInfoData *pLeftCol = vectorConvertVarToDouble(pLeft, &leftConvert); + SColumnInfoData *pRightCol = vectorConvertVarToDouble(pRight, &rightConvert); - _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); int64_t *output = (int64_t *)pOutputCol->pData; @@ -1589,12 +1526,13 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, vectorBitAndHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); } - doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pLeftCol, leftConvert); doReleaseVec(pRightCol, rightConvert); } -static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { - _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); +static void vectorBitOrHelper(SColumnInfoData *pLeftCol, SColumnInfoData *pRightCol, SColumnInfoData *pOutputCol, + int32_t numOfRows, int32_t step, int32_t i) { + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); int64_t *output = (int64_t *)pOutputCol->pData; @@ -1613,7 +1551,7 @@ static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRight } } -void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorBitOr(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); @@ -1621,10 +1559,10 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; int32_t leftConvert = 0, rightConvert = 0; - SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert); - SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert); + SColumnInfoData *pLeftCol = vectorConvertVarToDouble(pLeft, &leftConvert); + SColumnInfoData *pRightCol = vectorConvertVarToDouble(pRight, &rightConvert); - _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); int64_t *output = (int64_t *)pOutputCol->pData; @@ -1642,17 +1580,17 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, vectorBitOrHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); } - doReleaseVec(pLeftCol, leftConvert); + doReleaseVec(pLeftCol, leftConvert); doReleaseVec(pRightCol, rightConvert); } -int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t startIndex, int32_t step, __compar_fn_t fp, - SScalarParam *pLeft, SScalarParam *pRight, int32_t optr) { +int32_t doVectorCompareImpl(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t startIndex, int32_t numOfRows, + int32_t step, __compar_fn_t fp, int32_t optr) { int32_t num = 0; for (int32_t i = startIndex; i < numOfRows && i >= 0; i += step) { - int32_t leftIndex = (i >= pLeft->numOfRows)? 0:i; - int32_t rightIndex = (i >= pRight->numOfRows)? 0:i; + int32_t leftIndex = (i >= pLeft->numOfRows) ? 0 : i; + int32_t rightIndex = (i >= pRight->numOfRows) ? 0 : i; if (IS_HELPER_NULL(pLeft->columnData, leftIndex) || IS_HELPER_NULL(pRight->columnData, rightIndex)) { bool res = false; @@ -1660,15 +1598,15 @@ int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t start continue; } - char * pLeftData = colDataGetData(pLeft->columnData, leftIndex); - char * pRightData = colDataGetData(pRight->columnData, rightIndex); + char *pLeftData = colDataGetData(pLeft->columnData, leftIndex); + char *pRightData = colDataGetData(pRight->columnData, rightIndex); int64_t leftOut = 0; int64_t rightOut = 0; bool freeLeft = false; bool freeRight = false; bool isJsonnull = false; - bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, + bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull, &freeLeft, &freeRight); if (isJsonnull) { ASSERT(0); @@ -1700,43 +1638,53 @@ int32_t doVectorCompareImpl(int32_t numOfRows, SScalarParam *pOut, int32_t start return num; } -void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; +void doVectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t startIndex, int32_t numOfRows, + int32_t _ord, int32_t optr) { + int32_t i = 0; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; int32_t lType = GET_PARAM_TYPE(pLeft); int32_t rType = GET_PARAM_TYPE(pRight); __compar_fn_t fp = NULL; - + int32_t compRows = 0; + if (lType == rType) { fp = filterGetCompFunc(lType, optr); } else { fp = filterGetCompFuncEx(lType, rType, optr); } - pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + if (startIndex < 0) { + i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + compRows = pOut->numOfRows; + } else { + compRows = startIndex + numOfRows; + i = startIndex; + } if (pRight->pHashFilter != NULL) { for (; i >= 0 && i < pLeft->numOfRows; i += step) { if (IS_HELPER_NULL(pLeft->columnData, i)) { - bool res = false; - colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); + bool res = false; + colDataAppendInt8(pOut->columnData, i, (int8_t *)&res); continue; } char *pLeftData = colDataGetData(pLeft->columnData, i); bool res = filterDoCompare(fp, optr, pLeftData, pRight->pHashFilter); - colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); + colDataAppendInt8(pOut->columnData, i, (int8_t *)&res); if (res) { pOut->numOfQualified++; } } } else { // normal compare - pOut->numOfQualified = doVectorCompareImpl(pOut->numOfRows, pOut, i, step, fp, pLeft, pRight, optr); + pOut->numOfQualified = doVectorCompareImpl(pLeft, pRight, pOut, i, compRows, step, fp, optr); } } -void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) { - SScalarParam pLeftOut = {0}; +void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t startIndex, int32_t numOfRows, + int32_t _ord, int32_t optr) { + SScalarParam pLeftOut = {0}; SScalarParam pRightOut = {0}; SScalarParam *param1 = NULL; SScalarParam *param2 = NULL; @@ -1745,7 +1693,7 @@ void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut param1 = pLeft; param2 = pRight; } else { - vectorConvert(pLeft, pRight, &pLeftOut, &pRightOut); + vectorConvertCols(pLeft, pRight, &pLeftOut, &pRightOut, startIndex, numOfRows); if (pLeftOut.columnData != NULL) { param1 = &pLeftOut; @@ -1760,69 +1708,74 @@ void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut } } - vectorCompareImpl(param1, param2, pOut, _ord, optr); + doVectorCompare(param1, param2, pOut, startIndex, numOfRows, _ord, optr); + sclFreeParam(&pLeftOut); sclFreeParam(&pRightOut); } +void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) { + vectorCompareImpl(pLeft, pRight, pOut, -1, -1, _ord, optr); +} + void vectorGreater(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_GREATER_THAN); } -void vectorGreaterEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorGreaterEqual(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_GREATER_EQUAL); } -void vectorLower(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorLower(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LOWER_THAN); } -void vectorLowerEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorLowerEqual(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LOWER_EQUAL); } -void vectorEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorEqual(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_EQUAL); } -void vectorNotEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorNotEqual(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_EQUAL); } -void vectorIn(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorIn(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_IN); } -void vectorNotIn(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorNotIn(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_IN); } -void vectorLike(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorLike(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LIKE); } -void vectorNotLike(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorNotLike(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_LIKE); } -void vectorMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorMatch(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_MATCH); } -void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorNotMatch(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NMATCH); } -void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - for(int32_t i = 0; i < pLeft->numOfRows; ++i) { +void vectorIsNull(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { + for (int32_t i = 0; i < pLeft->numOfRows; ++i) { int8_t v = IS_HELPER_NULL(pLeft->columnData, i) ? 1 : 0; colDataAppendInt8(pOut->columnData, i, &v); } pOut->numOfRows = pLeft->numOfRows; } -void vectorNotNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - for(int32_t i = 0; i < pLeft->numOfRows; ++i) { +void vectorNotNull(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { + for (int32_t i = 0; i < pLeft->numOfRows; ++i) { int8_t v = IS_HELPER_NULL(pLeft->columnData, i) ? 0 : 1; colDataAppendInt8(pOut->columnData, i, &v); } @@ -1830,7 +1783,7 @@ void vectorNotNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut } void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - vectorConvertImpl(pLeft, pOut, NULL); + vectorConvertSingleColImpl(pLeft, pOut, NULL, -1, -1); for(int32_t i = 0; i < pOut->numOfRows; ++i) { if(colDataIsNull_s(pOut->columnData, i)) { int8_t v = 0; @@ -1843,26 +1796,26 @@ void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, STagVal getJsonValue(char *json, char *key, bool *isExist) { STagVal val = {.pKey = key}; - if (tTagIsJson((const STag *)json) == false){ + if (tTagIsJson((const STag *)json) == false) { terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR; - if(isExist){ + if (isExist) { *isExist = false; } return val; } bool find = tTagGet(((const STag *)json), &val); // json value is null and not exist is different - if(isExist){ + if (isExist) { *isExist = find; } return val; } -void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorJsonContains(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; - int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); @@ -1877,17 +1830,16 @@ void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam getJsonValue(pLeftData, jsonKey, &isExist); } - colDataAppend(pOutputCol, i, (const char*)(&isExist), false); - + colDataAppend(pOutputCol, i, (const char *)(&isExist), false); } taosMemoryFree(jsonKey); } -void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { +void vectorJsonArrow(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; - int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); @@ -1900,12 +1852,12 @@ void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO pOutputCol->hasNull = true; continue; } - char *pLeftData = colDataGetVarData(pLeft->columnData, i); - bool isExist = false; + char *pLeftData = colDataGetVarData(pLeft->columnData, i); + bool isExist = false; STagVal value = getJsonValue(pLeftData, jsonKey, &isExist); - char *data = isExist ? tTagValToData(&value, true) : NULL; + char *data = isExist ? tTagValToData(&value, true) : NULL; colDataAppend(pOutputCol, i, data, data == NULL); - if(isExist && IS_VAR_DATA_TYPE(value.type) && data){ + if (isExist && IS_VAR_DATA_TYPE(value.type) && data) { taosMemoryFree(data); } } @@ -1971,4 +1923,3 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) { return NULL; } } - diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp index bb7745dbd9a7af32e735e8131834d139221af9bd..ca304cd3291643d437083521409b997d327ffb1a 100644 --- a/source/libs/scalar/test/filter/filterTests.cpp +++ b/source/libs/scalar/test/filter/filterTests.cpp @@ -32,26 +32,21 @@ #endif #include "os.h" -#include "tglobal.h" -#include "taos.h" -#include "tdef.h" -#include "tvariant.h" -#include "tdatablock.h" -#include "stub.h" -#include "scalar.h" #include "filter.h" #include "nodes.h" #include "scalar.h" #include "stub.h" #include "taos.h" +#include "tdatablock.h" #include "tdef.h" +#include "tglobal.h" #include "tlog.h" #include "tvariant.h" namespace { int64_t flttLeftV = 21, flttRightV = 10; -double flttLeftVd = 21.0, flttRightVd = 10.0; +double flttLeftVd = 21.0, flttRightVd = 10.0; void flttInitLogFile() { const char *defaultLogFileNamePrefix = "taoslog"; @@ -66,9 +61,8 @@ void flttInitLogFile() { } } - void flttMakeValueNode(SNode **pNode, int32_t dataType, void *value) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_VALUE); SValueNode *vnode = (SValueNode *)node; vnode->node.resType.type = dataType; @@ -80,19 +74,20 @@ void flttMakeValueNode(SNode **pNode, int32_t dataType, void *value) { vnode->node.resType.bytes = tDataTypes[dataType].bytes; assignVal((char *)nodesGetValueFromNode(vnode), (const char *)value, 0, dataType); } - + *pNode = (SNode *)vnode; } -void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, int32_t dataBytes, int32_t rowNum, void *value) { +void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, int32_t dataBytes, int32_t rowNum, + void *value) { static uint64_t dbidx = 0; - - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_COLUMN); + + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_COLUMN); SColumnNode *rnode = (SColumnNode *)node; rnode->node.resType.type = dataType; rnode->node.resType.bytes = dataBytes; rnode->dataBlockId = 0; - + sprintf(rnode->dbName, "%" PRIu64, dbidx++); if (NULL == block) { @@ -106,7 +101,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in if (NULL == *block) { SSDataBlock *res = createDataBlock(); for (int32_t i = 0; i < 2; ++i) { - SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, 10, 1+i); + SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, 10, 1 + i); blockDataAppendColInfo(res, &idata); } @@ -131,9 +126,9 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in *block = res; } else { SSDataBlock *res = *block; - - int32_t idx = taosArrayGetSize(res->pDataBlock); - SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1+idx); + + int32_t idx = taosArrayGetSize(res->pDataBlock); + SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1 + idx); blockDataAppendColInfo(res, &idata); blockDataEnsureCapacity(res, rowNum); @@ -147,7 +142,7 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in value = (char *)value + dataBytes; } } - + rnode->slotId = idx; rnode->colId = 1 + idx; } @@ -156,11 +151,11 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in } void flttMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_OPERATOR); SOperatorNode *onode = (SOperatorNode *)node; onode->node.resType.type = resType; onode->node.resType.bytes = tDataTypes[resType].bytes; - + onode->opType = opType; onode->pLeft = pLeft; onode->pRight = pRight; @@ -169,7 +164,7 @@ void flttMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode } void flttMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeList, int32_t nodeNum) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); SLogicConditionNode *onode = (SLogicConditionNode *)node; onode->condType = opType; onode->node.resType.type = TSDB_DATA_TYPE_BOOL; @@ -179,24 +174,24 @@ void flttMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeLi for (int32_t i = 0; i < nodeNum; ++i) { nodesListAppend(onode->pParameterList, nodeList[i]); } - + *pNode = (SNode *)onode; } void flttMakeLogicNodeFromList(SNode **pNode, ELogicConditionType opType, SNodeList *nodeList) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); SLogicConditionNode *onode = (SLogicConditionNode *)node; onode->condType = opType; onode->node.resType.type = TSDB_DATA_TYPE_BOOL; onode->node.resType.bytes = sizeof(bool); onode->pParameterList = nodeList; - + *pNode = (SNode *)onode; } void flttMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_NODE_LIST); SNodeListNode *lnode = (SNodeListNode *)node; lnode->dataType.type = resType; lnode->pNodeList = list; @@ -204,169 +199,166 @@ void flttMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { *pNode = (SNode *)lnode; } -void initScalarParam(SScalarParam* pParam) { +void initScalarParam(SScalarParam *pParam) { memset(pParam, 0, sizeof(SScalarParam)); pParam->colAlloced = true; } -} +} // namespace TEST(timerangeTest, greater) { - SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL; - bool eRes[5] = {false, false, true, true, true}; + SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL; + bool eRes[5] = {false, false, true, true, true}; SScalarParam res; initScalarParam(&res); int64_t tsmall = 222, tbig = 333; - flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); - //SFilterInfo *filter = NULL; - //int32_t code = filterInitFromNode(opNode1, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); - //ASSERT_EQ(code, 0); + // SFilterInfo *filter = NULL; + // int32_t code = filterInitFromNode(opNode1, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); + // ASSERT_EQ(code, 0); STimeWindow win = {0}; - bool isStrict = false; - int32_t code = filterGetTimeRange(opNode1, &win, &isStrict); + bool isStrict = false; + int32_t code = filterGetTimeRange(opNode1, &win, &isStrict); ASSERT_EQ(code, 0); - ASSERT_EQ(isStrict, true); - ASSERT_EQ(win.skey, tsmall+1); - ASSERT_EQ(win.ekey, INT64_MAX); - //filterFreeInfo(filter); + ASSERT_EQ(isStrict, true); + ASSERT_EQ(win.skey, tsmall + 1); + ASSERT_EQ(win.ekey, INT64_MAX); + // filterFreeInfo(filter); nodesDestroyNode(opNode1); } TEST(timerangeTest, greater_and_lower) { - SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; - bool eRes[5] = {false, false, true, true, true}; + SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; + bool eRes[5] = {false, false, true, true, true}; SScalarParam res; initScalarParam(&res); int64_t tsmall = 222, tbig = 333; - flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); - flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); SNode *list[2] = {0}; list[0] = opNode1; list[1] = opNode2; - + flttMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); - //SFilterInfo *filter = NULL; - //int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); - //ASSERT_EQ(code, 0); + // SFilterInfo *filter = NULL; + // int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); + // ASSERT_EQ(code, 0); STimeWindow win = {0}; - bool isStrict = false; - int32_t code = filterGetTimeRange(logicNode, &win, &isStrict); + bool isStrict = false; + int32_t code = filterGetTimeRange(logicNode, &win, &isStrict); ASSERT_EQ(isStrict, true); ASSERT_EQ(code, 0); - ASSERT_EQ(win.skey, tsmall+1); - ASSERT_EQ(win.ekey, tbig-1); - //filterFreeInfo(filter); + ASSERT_EQ(win.skey, tsmall + 1); + ASSERT_EQ(win.ekey, tbig - 1); + // filterFreeInfo(filter); nodesDestroyNode(logicNode); } TEST(timerangeTest, greater_equal_and_lower_equal) { - SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; - bool eRes[5] = {false, false, true, true, true}; - SScalarParam res; + SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; + bool eRes[5] = {false, false, true, true, true}; + SScalarParam res; initScalarParam(&res); int64_t tsmall = 222, tbig = 333; - flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_EQUAL, TSDB_DATA_TYPE_BOOL, pcol, pval); - flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pcol, pval); SNode *list[2] = {0}; list[0] = opNode1; list[1] = opNode2; - + flttMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); - //SFilterInfo *filter = NULL; - //int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); - //ASSERT_EQ(code, 0); + // SFilterInfo *filter = NULL; + // int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); + // ASSERT_EQ(code, 0); STimeWindow win = {0}; - bool isStrict = false; - int32_t code = filterGetTimeRange(logicNode, &win, &isStrict); + bool isStrict = false; + int32_t code = filterGetTimeRange(logicNode, &win, &isStrict); ASSERT_EQ(isStrict, true); ASSERT_EQ(code, 0); ASSERT_EQ(win.skey, tsmall); - ASSERT_EQ(win.ekey, tbig); - //filterFreeInfo(filter); + ASSERT_EQ(win.ekey, tbig); + // filterFreeInfo(filter); nodesDestroyNode(logicNode); } - TEST(timerangeTest, greater_and_lower_not_strict) { - SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode1 = NULL, *logicNode2 = NULL; - bool eRes[5] = {false, false, true, true, true}; + SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode1 = NULL, *logicNode2 = NULL; + bool eRes[5] = {false, false, true, true, true}; SScalarParam res; initScalarParam(&res); int64_t tsmall1 = 222, tbig1 = 333; int64_t tsmall2 = 444, tbig2 = 555; - SNode *list[2] = {0}; + SNode *list[2] = {0}; - flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall1); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); - flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig1); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); list[0] = opNode1; list[1] = opNode2; - + flttMakeLogicNode(&logicNode1, LOGIC_COND_TYPE_AND, list, 2); - flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall2); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); - flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig2); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); list[0] = opNode1; list[1] = opNode2; - + flttMakeLogicNode(&logicNode2, LOGIC_COND_TYPE_AND, list, 2); list[0] = logicNode1; list[1] = logicNode2; flttMakeLogicNode(&logicNode1, LOGIC_COND_TYPE_OR, list, 2); - //SFilterInfo *filter = NULL; - //int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); - //ASSERT_EQ(code, 0); + // SFilterInfo *filter = NULL; + // int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); + // ASSERT_EQ(code, 0); STimeWindow win = {0}; - bool isStrict = false; - int32_t code = filterGetTimeRange(logicNode1, &win, &isStrict); + bool isStrict = false; + int32_t code = filterGetTimeRange(logicNode1, &win, &isStrict); ASSERT_EQ(isStrict, false); ASSERT_EQ(code, 0); - ASSERT_EQ(win.skey, tsmall1+1); - ASSERT_EQ(win.ekey, tbig2-1); - //filterFreeInfo(filter); + ASSERT_EQ(win.skey, tsmall1 + 1); + ASSERT_EQ(win.ekey, tbig2 - 1); + // filterFreeInfo(filter); nodesDestroyNode(logicNode1); } - - TEST(columnTest, smallint_column_greater_double_value) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int16_t leftv[5]= {1, 2, 3, 4, 5}; - double rightv= 2.5; - int8_t eRes[5] = {0, 0, 1, 1, 1}; + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int16_t leftv[5] = {1, 2, 3, 4, 5}; + double rightv = 2.5; + int8_t eRes[5] = {0, 0, 1, 1, 1}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - + SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; @@ -388,7 +380,7 @@ TEST(columnTest, smallint_column_greater_double_value) { keep = filterRangeExecute(filter, &stat, 1, rowNum); ASSERT_EQ(keep, true); - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -396,7 +388,7 @@ TEST(columnTest, smallint_column_greater_double_value) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); + keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -409,20 +401,20 @@ TEST(columnTest, smallint_column_greater_double_value) { } TEST(columnTest, int_column_greater_smallint_value) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int32_t leftv[5]= {1, 3, 5, 7, 9}; - int16_t rightv= 4; - int8_t eRes[5] = {0, 0, 1, 1, 1}; + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int32_t leftv[5] = {1, 3, 5, 7, 9}; + int16_t rightv = 4; + int8_t eRes[5] = {0, 0, 1, 1, 1}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; @@ -444,7 +436,7 @@ TEST(columnTest, int_column_greater_smallint_value) { keep = filterRangeExecute(filter, &stat, 1, rowNum); ASSERT_EQ(keep, false); - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -452,7 +444,7 @@ TEST(columnTest, int_column_greater_smallint_value) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); + keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -465,31 +457,31 @@ TEST(columnTest, int_column_greater_smallint_value) { } TEST(columnTest, int_column_in_double_list) { - SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; - int32_t leftv[5] = {1, 2, 3, 4, 5}; - double rightv1 = 1.1,rightv2 = 2.2,rightv3 = 3.3; - bool eRes[5] = {true, true, true, false, false}; + SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; + int32_t leftv[5] = {1, 2, 3, 4, 5}; + double rightv1 = 1.1, rightv2 = 2.2, rightv3 = 3.3; + bool eRes[5] = {true, true, true, false, false}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); - SNodeList* list = nodesMakeList(); + SNodeList *list = nodesMakeList(); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1); nodesListAppend(list, pRight); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2); nodesListAppend(list, pRight); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3); nodesListAppend(list, pRight); - flttMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); + flttMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT); flttMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -497,7 +489,7 @@ TEST(columnTest, int_column_in_double_list) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -511,13 +503,13 @@ TEST(columnTest, int_column_in_double_list) { } TEST(columnTest, binary_column_in_binary_list) { - SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; - bool eRes[5] = {true, true, false, false, false}; + SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; + bool eRes[5] = {true, true, false, false, false}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); - char leftv[5][5]= {0}; - char rightv[3][5]= {0}; + char leftv[5][5] = {0}; + char rightv[3][5] = {0}; for (int32_t i = 0; i < 5; ++i) { leftv[i][2] = 'a' + i; leftv[i][3] = 'b' + i; @@ -537,24 +529,24 @@ TEST(columnTest, binary_column_in_binary_list) { varDataSetLen(rightv[i], 3); } - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); - SNodeList* list = nodesMakeList(); + SNodeList *list = nodesMakeList(); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]); nodesListAppend(list, pRight); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]); nodesListAppend(list, pRight); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]); nodesListAppend(list, pRight); - flttMakeListNode(&listNode,list, TSDB_DATA_TYPE_BINARY); + flttMakeListNode(&listNode, list, TSDB_DATA_TYPE_BINARY); flttMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -562,7 +554,7 @@ TEST(columnTest, binary_column_in_binary_list) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -575,9 +567,9 @@ TEST(columnTest, binary_column_in_binary_list) { } TEST(columnTest, binary_column_like_binary) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - char rightv[64] = {0}; - char leftv[5][5]= {0}; + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + char rightv[64] = {0}; + char leftv[5][5] = {0}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); @@ -590,7 +582,7 @@ TEST(columnTest, binary_column_like_binary) { varDataSetLen(leftv[i], 3); } - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); sprintf(&rightv[2], "%s", "__0"); @@ -599,11 +591,11 @@ TEST(columnTest, binary_column_like_binary) { flttMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -611,7 +603,7 @@ TEST(columnTest, binary_column_like_binary) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -624,8 +616,8 @@ TEST(columnTest, binary_column_like_binary) { } TEST(columnTest, binary_column_is_null) { - SNode *pLeft = NULL, *opNode = NULL; - char leftv[5][5]= {0}; + SNode *pLeft = NULL, *opNode = NULL; + char leftv[5][5] = {0}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); @@ -638,7 +630,7 @@ TEST(columnTest, binary_column_is_null) { varDataSetLen(leftv[i], 3); } - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); @@ -647,11 +639,11 @@ TEST(columnTest, binary_column_is_null) { flttMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -659,7 +651,7 @@ TEST(columnTest, binary_column_is_null) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -672,8 +664,8 @@ TEST(columnTest, binary_column_is_null) { } TEST(columnTest, binary_column_is_not_null) { - SNode *pLeft = NULL, *opNode = NULL; - char leftv[5][5]= {0}; + SNode *pLeft = NULL, *opNode = NULL; + char leftv[5][5] = {0}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); @@ -686,7 +678,7 @@ TEST(columnTest, binary_column_is_not_null) { varDataSetLen(leftv[i], 3); } - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); @@ -695,11 +687,11 @@ TEST(columnTest, binary_column_is_not_null) { flttMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -707,7 +699,7 @@ TEST(columnTest, binary_column_is_not_null) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -720,24 +712,24 @@ TEST(columnTest, binary_column_is_not_null) { } TEST(opTest, smallint_column_greater_int_column) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int16_t leftv[5] = {1, -6, -2, 11, 101}; - int32_t rightv[5]= {0, -5, -4, 23, 100}; - bool eRes[5] = {true, false, true, false, true}; + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int16_t leftv[5] = {1, -6, -2, 11, 101}; + int32_t rightv[5] = {0, -5, -4, 23, 100}; + bool eRes[5] = {true, false, true, false, true}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); - int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); + int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv); flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -745,7 +737,7 @@ TEST(opTest, smallint_column_greater_int_column) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -758,25 +750,25 @@ TEST(opTest, smallint_column_greater_int_column) { } TEST(opTest, smallint_value_add_int_column) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int32_t leftv = 1; - int16_t rightv[5]= {0, -1, -4, -1, 100}; - bool eRes[5] = {true, false, true, false, true}; + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int32_t leftv = 1; + int16_t rightv[5] = {0, -1, -4, -1, 100}; + bool eRes[5] = {true, false, true, false, true}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); - int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); + int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]); flttMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv); flttMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -784,7 +776,7 @@ TEST(opTest, smallint_value_add_int_column) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -797,30 +789,30 @@ TEST(opTest, smallint_value_add_int_column) { } TEST(opTest, bigint_column_multi_binary_column) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int64_t leftv[5]= {1, 2, 3, 4, 5}; - char rightv[5][5]= {0}; + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int64_t leftv[5] = {1, 2, 3, 4, 5}; + char rightv[5][5] = {0}; for (int32_t i = 0; i < 5; ++i) { rightv[i][2] = rightv[i][3] = '0'; rightv[i][4] = '0' + i; varDataSetLen(rightv[i], 3); } - bool eRes[5] = {false, true, true, true, true}; + bool eRes[5] = {false, true, true, true, true}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); - int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); + int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); flttMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -828,7 +820,7 @@ TEST(opTest, bigint_column_multi_binary_column) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -841,30 +833,30 @@ TEST(opTest, bigint_column_multi_binary_column) { } TEST(opTest, smallint_column_and_binary_column) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int16_t leftv[5]= {1, 2, 3, 4, 5}; - char rightv[5][5]= {0}; + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int16_t leftv[5] = {1, 2, 3, 4, 5}; + char rightv[5][5] = {0}; for (int32_t i = 0; i < 5; ++i) { rightv[i][2] = rightv[i][3] = '0'; rightv[i][4] = '0' + i; varDataSetLen(rightv[i], 3); } - bool eRes[5] = {false, false, true, false, true}; + bool eRes[5] = {false, false, true, false, true}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); - int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); + int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); flttMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -872,7 +864,7 @@ TEST(opTest, smallint_column_and_binary_column) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t)taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -885,25 +877,25 @@ TEST(opTest, smallint_column_and_binary_column) { } TEST(opTest, smallint_column_or_float_column) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int16_t leftv[5]= {1, 2, 0, 4, 5}; - float rightv[5]= {2.0, 3.0, 0, 5.2, 6.0}; - bool eRes[5] = {true, true, false, true, true}; + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int16_t leftv[5] = {1, 2, 0, 4, 5}; + float rightv[5] = {2.0, 3.0, 0, 5.2, 6.0}; + bool eRes[5] = {true, true, false, true, true}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); - int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); + int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv); flttMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -911,7 +903,7 @@ TEST(opTest, smallint_column_or_float_column) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -924,25 +916,25 @@ TEST(opTest, smallint_column_or_float_column) { } TEST(opTest, smallint_column_or_double_value) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int16_t leftv[5]= {0, 2, 3, 0, -1}; - double rightv= 10.2; - bool eRes[5] = {true, true, true, true, true}; + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int16_t leftv[5] = {0, 2, 3, 0, -1}; + double rightv = 10.2; + bool eRes[5] = {true, true, true, true, true}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); flttMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -950,7 +942,7 @@ TEST(opTest, smallint_column_or_double_value) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, true); for (int32_t i = 0; i < rowNum; ++i) { @@ -963,8 +955,8 @@ TEST(opTest, smallint_column_or_double_value) { } TEST(opTest, binary_column_is_true) { - SNode *pLeft = NULL, *opNode = NULL; - char leftv[5][5]= {0}; + SNode *pLeft = NULL, *opNode = NULL; + char leftv[5][5] = {0}; SSDataBlock *src = NULL; SScalarParam res; initScalarParam(&res); @@ -977,17 +969,17 @@ TEST(opTest, binary_column_is_true) { varDataSetLen(leftv[i], 3); } - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL); SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(opNode, &filter, 0); + int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -995,7 +987,7 @@ TEST(opTest, binary_column_is_true) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -1010,16 +1002,16 @@ TEST(opTest, binary_column_is_true) { TEST(filterModelogicTest, diff_columns_and_or_and) { flttInitLogFile(); - SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; - SNode *logicNode1 = NULL, *logicNode2 = NULL; - double leftv1[8]= {1, 2, 3, 4, 5,-1,-2,-3}, leftv2[8]= {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2}; - int32_t rightv1= 3, rightv2= 3; - int8_t eRes[8] = {1, 1, 0, 0, 1, 1, 1, 1}; + SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; + SNode *logicNode1 = NULL, *logicNode2 = NULL; + double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3}, leftv2[8] = {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2}; + int32_t rightv1 = 3, rightv2 = 3; + int8_t eRes[8] = {1, 1, 0, 0, 1, 1, 1, 1}; SSDataBlock *src = NULL; - SNodeList* list = nodesMakeList(); + SNodeList *list = nodesMakeList(); - int32_t rowNum = sizeof(leftv1)/sizeof(leftv1[0]); + int32_t rowNum = sizeof(leftv1) / sizeof(leftv1[0]); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); @@ -1032,7 +1024,6 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); - list = nodesMakeList(); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); @@ -1052,13 +1043,12 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { nodesListAppend(list, logicNode2); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); - SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(logicNode1, &filter, 0); + int32_t code = filterInitFromNode(logicNode1, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -1066,7 +1056,7 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -1079,16 +1069,16 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { } TEST(filterModelogicTest, same_column_and_or_and) { - SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; - SNode *logicNode1 = NULL, *logicNode2 = NULL; - double leftv1[8]= {1, 2, 3, 4, 5,-1,-2,-3}; - int32_t rightv1= 3, rightv2= 0, rightv3 = 2, rightv4 = -2; - int8_t eRes[8] = {1, 1, 0, 0, 0, 1, 1, 0}; + SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; + SNode *logicNode1 = NULL, *logicNode2 = NULL; + double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3}; + int32_t rightv1 = 3, rightv2 = 0, rightv3 = 2, rightv4 = -2; + int8_t eRes[8] = {1, 1, 0, 0, 0, 1, 1, 0}; SSDataBlock *src = NULL; - SNodeList* list = nodesMakeList(); + SNodeList *list = nodesMakeList(); - int32_t rowNum = sizeof(leftv1)/sizeof(leftv1[0]); + int32_t rowNum = sizeof(leftv1) / sizeof(leftv1[0]); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); @@ -1101,7 +1091,6 @@ TEST(filterModelogicTest, same_column_and_or_and) { flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); - list = nodesMakeList(); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); @@ -1121,13 +1110,12 @@ TEST(filterModelogicTest, same_column_and_or_and) { nodesListAppend(list, logicNode2); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); - SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(logicNode1, &filter, 0); + int32_t code = filterInitFromNode(logicNode1, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -1135,7 +1123,7 @@ TEST(filterModelogicTest, same_column_and_or_and) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -1148,16 +1136,16 @@ TEST(filterModelogicTest, same_column_and_or_and) { } TEST(filterModelogicTest, diff_columns_or_and_or) { - SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; - SNode *logicNode1 = NULL, *logicNode2 = NULL; - double leftv1[8]= {1, 2, 3, 4, 5,-1,-2,-3}, leftv2[8]= {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2}; - int32_t rightv1= 3, rightv2= 3; - int8_t eRes[8] = {1, 0, 1, 1, 0, 0, 0, 0}; + SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; + SNode *logicNode1 = NULL, *logicNode2 = NULL; + double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3}, leftv2[8] = {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2}; + int32_t rightv1 = 3, rightv2 = 3; + int8_t eRes[8] = {1, 0, 1, 1, 0, 0, 0, 0}; SSDataBlock *src = NULL; - SNodeList* list = nodesMakeList(); + SNodeList *list = nodesMakeList(); - int32_t rowNum = sizeof(leftv1)/sizeof(leftv1[0]); + int32_t rowNum = sizeof(leftv1) / sizeof(leftv1[0]); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); @@ -1170,7 +1158,6 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); - list = nodesMakeList(); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); @@ -1190,13 +1177,12 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { nodesListAppend(list, logicNode2); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); - SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(logicNode1, &filter, 0); + int32_t code = filterInitFromNode(logicNode1, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -1204,7 +1190,7 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -1217,16 +1203,16 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { } TEST(filterModelogicTest, same_column_or_and_or) { - SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; - SNode *logicNode1 = NULL, *logicNode2 = NULL; - double leftv1[8]= {1, 2, 3, 4, 5,-1,-2,-3}; - int32_t rightv1= 3, rightv2= 0, rightv3 = 2, rightv4 = -2; - int8_t eRes[8] = {0, 0, 0, 1, 1, 1, 1, 1}; + SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; + SNode *logicNode1 = NULL, *logicNode2 = NULL; + double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3}; + int32_t rightv1 = 3, rightv2 = 0, rightv3 = 2, rightv4 = -2; + int8_t eRes[8] = {0, 0, 0, 1, 1, 1, 1, 1}; SSDataBlock *src = NULL; - SNodeList* list = nodesMakeList(); + SNodeList *list = nodesMakeList(); - int32_t rowNum = sizeof(leftv1)/sizeof(leftv1[0]); + int32_t rowNum = sizeof(leftv1) / sizeof(leftv1[0]); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); @@ -1239,7 +1225,6 @@ TEST(filterModelogicTest, same_column_or_and_or) { flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); - list = nodesMakeList(); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); @@ -1259,13 +1244,12 @@ TEST(filterModelogicTest, same_column_or_and_or) { nodesListAppend(list, logicNode2); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); - SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(logicNode1, &filter, 0); + int32_t code = filterInitFromNode(logicNode1, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -1273,7 +1257,7 @@ TEST(filterModelogicTest, same_column_or_and_or) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { @@ -1288,16 +1272,16 @@ TEST(filterModelogicTest, same_column_or_and_or) { TEST(scalarModelogicTest, diff_columns_or_and_or) { flttInitLogFile(); - SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; - SNode *logicNode1 = NULL, *logicNode2 = NULL; - double leftv1[8] = {1, 2, 3, 4, 5,-1,-2,-3}, leftv2[8]= {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2}; - int32_t rightv1[8]= {5, 8, 2, -3, 9,-7,10, 0}, rightv2[8]= {-3, 5, 8, 2, -9, 11, -4, 0}; - int8_t eRes[8] = {0, 1, 1, 0, 0, 1, 0, 0}; + SNode *pLeft1 = NULL, *pRight1 = NULL, *pLeft2 = NULL, *pRight2 = NULL, *opNode1 = NULL, *opNode2 = NULL; + SNode *logicNode1 = NULL, *logicNode2 = NULL; + double leftv1[8] = {1, 2, 3, 4, 5, -1, -2, -3}, leftv2[8] = {3.0, 4, 2, 9, -3, 3.9, 4.1, 5.2}; + int32_t rightv1[8] = {5, 8, 2, -3, 9, -7, 10, 0}, rightv2[8] = {-3, 5, 8, 2, -9, 11, -4, 0}; + int8_t eRes[8] = {0, 1, 1, 0, 0, 1, 0, 0}; SSDataBlock *src = NULL; - SNodeList* list = nodesMakeList(); + SNodeList *list = nodesMakeList(); - int32_t rowNum = sizeof(leftv1)/sizeof(leftv1[0]); + int32_t rowNum = sizeof(leftv1) / sizeof(leftv1[0]); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pRight1, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv1); flttMakeOpNode(&opNode1, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); @@ -1310,7 +1294,6 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); - list = nodesMakeList(); flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); @@ -1330,13 +1313,12 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { nodesListAppend(list, logicNode2); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); - SFilterInfo *filter = NULL; - int32_t code = filterInitFromNode(logicNode1, &filter, 0); + int32_t code = filterInitFromNode(logicNode1, &filter, 0); ASSERT_EQ(code, 0); - SColumnDataAgg stat = {0}; - SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; + SColumnDataAgg stat = {0}; + SFilterColumnParam param = {(int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -1344,9 +1326,9 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -1356,7 +1338,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { blockDataDestroy(src); } -int main(int argc, char** argv) { +int main(int argc, char **argv) { taosSeedRand(taosGetTimestampSec()); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index 7229fdec386b7df5bb626ea0524144d4f42dd995..39055b534d937ca74ecde5d017710534112fc91a 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -1,17 +1,17 @@ /* -* Copyright (c) 2019 TAOS Data, Inc. -* -* This program is free software: you can use, redistribute, and/or modify -* it under the terms of the GNU Affero General Public License, version 3 -* or later ("AGPL"), as published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -* FITNESS FOR A PARTICULAR PURPOSE. -* -* You should have received a copy of the GNU Affero General Public License -* along with this program. If not, see . -*/ + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ #include #include @@ -32,17 +32,17 @@ #endif #include "os.h" -#include "tglobal.h" +#include "filterInt.h" +#include "nodes.h" +#include "parUtil.h" +#include "scalar.h" +#include "stub.h" #include "taos.h" -#include "tdef.h" -#include "tvariant.h" #include "tdatablock.h" -#include "stub.h" -#include "scalar.h" -#include "nodes.h" +#include "tdef.h" +#include "tglobal.h" #include "tlog.h" -#include "parUtil.h" -#include "filterInt.h" +#include "tvariant.h" #define _DEBUG_PRINT_ 0 @@ -55,3595 +55,3582 @@ namespace { SColumnInfo createColumnInfo(int32_t colId, int32_t type, int32_t bytes) { - SColumnInfo info = {0}; - info.colId = colId; - info.type = type; - info.bytes = bytes; - return info; + SColumnInfo info = {0}; + info.colId = colId; + info.type = type; + info.bytes = bytes; + return info; } int64_t scltLeftV = 21, scltRightV = 10; -double scltLeftVd = 21.0, scltRightVd = 10.0; +double scltLeftVd = 21.0, scltRightVd = 10.0; -void scltFreeDataBlock(void *block) { - blockDataDestroy(*(SSDataBlock **)block); -} +void scltFreeDataBlock(void *block) { blockDataDestroy(*(SSDataBlock **)block); } void scltInitLogFile() { - const char *defaultLogFileNamePrefix = "taoslog"; - const int32_t maxLogFileNum = 10; + const char *defaultLogFileNamePrefix = "taoslog"; + const int32_t maxLogFileNum = 10; - tsAsyncLog = 0; - qDebugFlag = 159; - strcpy(tsLogDir, TD_LOG_DIR_PATH); + tsAsyncLog = 0; + qDebugFlag = 159; + strcpy(tsLogDir, TD_LOG_DIR_PATH); - if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) { - printf("failed to open log file in directory:%s\n", tsLogDir); - } + if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) { + printf("failed to open log file in directory:%s\n", tsLogDir); + } } -void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *slotId, bool newBlock, int32_t rows, SColumnInfo *colInfo) { - if (newBlock) { - SSDataBlock *res = createDataBlock(); +void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *slotId, bool newBlock, int32_t rows, + SColumnInfo *colInfo) { + if (newBlock) { + SSDataBlock *res = createDataBlock(); - SColumnInfoData idata = {0}; - idata.info = *colInfo; - colInfoDataEnsureCapacity(&idata, rows); + SColumnInfoData idata = {0}; + idata.info = *colInfo; + colInfoDataEnsureCapacity(&idata, rows); - blockDataAppendColInfo(res, &idata); + blockDataAppendColInfo(res, &idata); - res->info.capacity = rows; - res->info.rows = rows; - SColumnInfoData* p = static_cast(taosArrayGet(res->pDataBlock, 0)); - ASSERT(p->pData != NULL && p->nullbitmap != NULL); + res->info.capacity = rows; + res->info.rows = rows; + SColumnInfoData *p = static_cast(taosArrayGet(res->pDataBlock, 0)); + ASSERT(p->pData != NULL && p->nullbitmap != NULL); - taosArrayPush(pBlockList, &res); - *dataBlockId = taosArrayGetSize(pBlockList) - 1; - res->info.blockId = *dataBlockId; - *slotId = 0; - } else { - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(pBlockList); - SColumnInfoData idata = {0}; - idata.info = *colInfo; - colInfoDataEnsureCapacity(&idata, rows); - blockDataAppendColInfo(res, &idata); + taosArrayPush(pBlockList, &res); + *dataBlockId = taosArrayGetSize(pBlockList) - 1; + res->info.blockId = *dataBlockId; + *slotId = 0; + } else { + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(pBlockList); + SColumnInfoData idata = {0}; + idata.info = *colInfo; + colInfoDataEnsureCapacity(&idata, rows); + blockDataAppendColInfo(res, &idata); - *dataBlockId = taosArrayGetSize(pBlockList) - 1; - *slotId = taosArrayGetSize(res->pDataBlock) - 1; - } + *dataBlockId = taosArrayGetSize(pBlockList) - 1; + *slotId = taosArrayGetSize(res->pDataBlock) - 1; + } } void scltMakeValueNode(SNode **pNode, int32_t dataType, void *value) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); - SValueNode *vnode = (SValueNode *)node; - vnode->node.resType.type = dataType; - - if (IS_VAR_DATA_TYPE(dataType)) { - vnode->datum.p = (char *)taosMemoryMalloc(varDataTLen(value)); - varDataCopy(vnode->datum.p, value); - vnode->node.resType.bytes = varDataTLen(value); - } else { - vnode->node.resType.bytes = tDataTypes[dataType].bytes; - assignVal((char *)nodesGetValueFromNode(vnode), (const char *)value, 0, dataType); - } - - *pNode = (SNode *)vnode; -} - -void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, int32_t dataBytes, int32_t rowNum, void *value) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_COLUMN); - SColumnNode *rnode = (SColumnNode *)node; - rnode->node.resType.type = dataType; - rnode->node.resType.bytes = dataBytes; - rnode->dataBlockId = 0; - - if (NULL == block) { - *pNode = (SNode *)rnode; - return; - } - - if (NULL == *block) { - SSDataBlock *res = createDataBlock(); - for (int32_t i = 0; i < 2; ++i) { - SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_INT, 10, i + 1); - colInfoDataEnsureCapacity(&idata, rowNum); - blockDataAppendColInfo(res, &idata); - } - - SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 3); - colInfoDataEnsureCapacity(&idata, rowNum); - blockDataAppendColInfo(res, &idata); - res->info.capacity = rowNum; - - res->info.rows = rowNum; - SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pColumn, i, (const char *)value, false); - if (IS_VAR_DATA_TYPE(dataType)) { - value = (char *)value + varDataTLen(value); - } else { - value = (char *)value + dataBytes; - } - } - - rnode->slotId = 2; - rnode->colId = 3; - - *block = res; - } else { - SSDataBlock *res = *block; - - int32_t idx = taosArrayGetSize(res->pDataBlock); - SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1 + idx); - colInfoDataEnsureCapacity(&idata, rowNum); - - res->info.capacity = rowNum; - blockDataAppendColInfo(res, &idata); - - SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pColumn, i, (const char *)value, false); - if (IS_VAR_DATA_TYPE(dataType)) { - value = (char *)value + varDataTLen(value); - } else { - value = (char *)value + dataBytes; - } - } - - rnode->slotId = idx; - rnode->colId = 1 + idx; - } - - *pNode = (SNode *)rnode; -} - -void scltMakeOpNode2(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight, bool isReverse) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR); - SOperatorNode *onode = (SOperatorNode *)node; - onode->node.resType.type = resType; - onode->node.resType.bytes = tDataTypes[resType].bytes; - - onode->opType = opType; - if(isReverse){ - onode->pLeft = pRight; - onode->pRight = pLeft; - }else{ - onode->pLeft = pLeft; - onode->pRight = pRight; - } - - *pNode = (SNode *)onode; + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_VALUE); + SValueNode *vnode = (SValueNode *)node; + vnode->node.resType.type = dataType; + + if (IS_VAR_DATA_TYPE(dataType)) { + vnode->datum.p = (char *)taosMemoryMalloc(varDataTLen(value)); + varDataCopy(vnode->datum.p, value); + vnode->node.resType.bytes = varDataTLen(value); + } else { + vnode->node.resType.bytes = tDataTypes[dataType].bytes; + assignVal((char *)nodesGetValueFromNode(vnode), (const char *)value, 0, dataType); + } + + *pNode = (SNode *)vnode; +} + +void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, int32_t dataBytes, int32_t rowNum, + void *value) { + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_COLUMN); + SColumnNode *rnode = (SColumnNode *)node; + rnode->node.resType.type = dataType; + rnode->node.resType.bytes = dataBytes; + rnode->dataBlockId = 0; + + if (NULL == block) { + *pNode = (SNode *)rnode; + return; + } + + if (NULL == *block) { + SSDataBlock *res = createDataBlock(); + for (int32_t i = 0; i < 2; ++i) { + SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_INT, 10, i + 1); + colInfoDataEnsureCapacity(&idata, rowNum); + blockDataAppendColInfo(res, &idata); + } + + SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 3); + colInfoDataEnsureCapacity(&idata, rowNum); + blockDataAppendColInfo(res, &idata); + res->info.capacity = rowNum; + + res->info.rows = rowNum; + SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pColumn, i, (const char *)value, false); + if (IS_VAR_DATA_TYPE(dataType)) { + value = (char *)value + varDataTLen(value); + } else { + value = (char *)value + dataBytes; + } + } + + rnode->slotId = 2; + rnode->colId = 3; + + *block = res; + } else { + SSDataBlock *res = *block; + + int32_t idx = taosArrayGetSize(res->pDataBlock); + SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1 + idx); + colInfoDataEnsureCapacity(&idata, rowNum); + + res->info.capacity = rowNum; + blockDataAppendColInfo(res, &idata); + + SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pColumn, i, (const char *)value, false); + if (IS_VAR_DATA_TYPE(dataType)) { + value = (char *)value + varDataTLen(value); + } else { + value = (char *)value + dataBytes; + } + } + + rnode->slotId = idx; + rnode->colId = 1 + idx; + } + + *pNode = (SNode *)rnode; +} + +void scltMakeOpNode2(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight, + bool isReverse) { + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_OPERATOR); + SOperatorNode *onode = (SOperatorNode *)node; + onode->node.resType.type = resType; + onode->node.resType.bytes = tDataTypes[resType].bytes; + + onode->opType = opType; + if (isReverse) { + onode->pLeft = pRight; + onode->pRight = pLeft; + } else { + onode->pLeft = pLeft; + onode->pRight = pRight; + } + + *pNode = (SNode *)onode; } void scltMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR); - SOperatorNode *onode = (SOperatorNode *)node; - onode->node.resType.type = resType; - onode->node.resType.bytes = tDataTypes[resType].bytes; + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_OPERATOR); + SOperatorNode *onode = (SOperatorNode *)node; + onode->node.resType.type = resType; + onode->node.resType.bytes = tDataTypes[resType].bytes; - onode->opType = opType; - onode->pLeft = pLeft; - onode->pRight = pRight; + onode->opType = opType; + onode->pLeft = pLeft; + onode->pRight = pRight; - *pNode = (SNode *)onode; + *pNode = (SNode *)onode; } - void scltMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); - SNodeListNode *lnode = (SNodeListNode *)node; - lnode->dataType.type = resType; - lnode->pNodeList = list; + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_NODE_LIST); + SNodeListNode *lnode = (SNodeListNode *)node; + lnode->dataType.type = resType; + lnode->pNodeList = list; - *pNode = (SNode *)lnode; + *pNode = (SNode *)lnode; } - void scltMakeLogicNode(SNode **pNode, ELogicConditionType opType, SNode **nodeList, int32_t nodeNum) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); - SLogicConditionNode *onode = (SLogicConditionNode *)node; - onode->condType = opType; - onode->node.resType.type = TSDB_DATA_TYPE_BOOL; - onode->node.resType.bytes = sizeof(bool); + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); + SLogicConditionNode *onode = (SLogicConditionNode *)node; + onode->condType = opType; + onode->node.resType.type = TSDB_DATA_TYPE_BOOL; + onode->node.resType.bytes = sizeof(bool); - onode->pParameterList = nodesMakeList(); - for (int32_t i = 0; i < nodeNum; ++i) { - nodesListAppend(onode->pParameterList, nodeList[i]); - } + onode->pParameterList = nodesMakeList(); + for (int32_t i = 0; i < nodeNum; ++i) { + nodesListAppend(onode->pParameterList, nodeList[i]); + } - *pNode = (SNode *)onode; + *pNode = (SNode *)onode; } void scltMakeTargetNode(SNode **pNode, int16_t dataBlockId, int16_t slotId, SNode *snode) { - SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_TARGET); - STargetNode *onode = (STargetNode *)node; - onode->pExpr = snode; - onode->dataBlockId = dataBlockId; - onode->slotId = slotId; + SNode *node = (SNode *)nodesMakeNode(QUERY_NODE_TARGET); + STargetNode *onode = (STargetNode *)node; + onode->pExpr = snode; + onode->dataBlockId = dataBlockId; + onode->slotId = slotId; - *pNode = (SNode *)onode; -} + *pNode = (SNode *)onode; } +} // namespace TEST(constantTest, bigint_add_bigint) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BIGINT, &scltLeftV); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BIGINT, &scltRightV); - scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BIGINT, &scltLeftV); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BIGINT, &scltRightV); + scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE); - ASSERT_FLOAT_EQ(v->datum.d, (scltLeftV + scltRightV)); - nodesDestroyNode(res); + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE); + ASSERT_FLOAT_EQ(v->datum.d, (scltLeftV + scltRightV)); + nodesDestroyNode(res); } TEST(constantTest, double_sub_bigint) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_DOUBLE, &scltLeftVd); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BIGINT, &scltRightV); - scltMakeOpNode(&opNode, OP_TYPE_SUB, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_DOUBLE, &scltLeftVd); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BIGINT, &scltRightV); + scltMakeOpNode(&opNode, OP_TYPE_SUB, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE); - ASSERT_FLOAT_EQ(v->datum.d, (scltLeftVd - scltRightV)); - nodesDestroyNode(res); + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE); + ASSERT_FLOAT_EQ(v->datum.d, (scltLeftVd - scltRightV)); + nodesDestroyNode(res); } TEST(constantTest, tinyint_and_smallint) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_TINYINT, &scltLeftV); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &scltRightV); - scltMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_TINYINT, &scltLeftV); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &scltRightV); + scltMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT); - ASSERT_EQ(v->datum.i, (int64_t)scltLeftV & (int64_t)scltRightV); - nodesDestroyNode(res); + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT); + ASSERT_EQ(v->datum.i, (int64_t)scltLeftV & (int64_t)scltRightV); + nodesDestroyNode(res); } TEST(constantTest, bigint_or_double) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BIGINT, &scltLeftV); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &scltRightVd); - scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BIGINT, &scltLeftV); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &scltRightVd); + scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT); - ASSERT_EQ(v->datum.i, (int64_t)scltLeftV | (int64_t)scltRightVd); - nodesDestroyNode(res); + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT); + ASSERT_EQ(v->datum.i, (int64_t)scltLeftV | (int64_t)scltRightVd); + nodesDestroyNode(res); } TEST(constantTest, int_or_binary) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - char binaryStr[64] = {0}; - sprintf(&binaryStr[2], "%d", scltRightV); - varDataSetLen(binaryStr, strlen(&binaryStr[2])); - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, binaryStr); - scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT); - ASSERT_EQ(v->datum.b, scltLeftV | scltRightV); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + char binaryStr[64] = {0}; + sprintf(&binaryStr[2], "%d", scltRightV); + varDataSetLen(binaryStr, strlen(&binaryStr[2])); + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, binaryStr); + scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT); + ASSERT_EQ(v->datum.b, scltLeftV | scltRightV); + nodesDestroyNode(res); } TEST(constantTest, int_greater_double) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &scltRightVd); - scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &scltRightVd); + scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, scltLeftV > scltRightVd); - nodesDestroyNode(res); + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, scltLeftV > scltRightVd); + nodesDestroyNode(res); } TEST(constantTest, int_greater_equal_binary) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - char binaryStr[64] = {0}; - sprintf(&binaryStr[2], "%d", scltRightV); - varDataSetLen(binaryStr, strlen(&binaryStr[2])); - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, binaryStr); - scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, scltLeftV > scltRightVd); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + char binaryStr[64] = {0}; + sprintf(&binaryStr[2], "%d", scltRightV); + varDataSetLen(binaryStr, strlen(&binaryStr[2])); + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, binaryStr); + scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, scltLeftV > scltRightVd); + nodesDestroyNode(res); } TEST(constantTest, tinyint_lower_ubigint) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_TINYINT, &scltLeftV); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_UBIGINT, &scltRightV); - scltMakeOpNode(&opNode, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_TINYINT, &scltLeftV); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_UBIGINT, &scltRightV); + scltMakeOpNode(&opNode, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, scltLeftV < scltRightV); - nodesDestroyNode(res); + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, scltLeftV < scltRightV); + nodesDestroyNode(res); } TEST(constantTest, usmallint_lower_equal_ubigint) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1; - int64_t rightv = 1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_USMALLINT, &leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_UBIGINT, &rightv); - scltMakeOpNode(&opNode, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, leftv <= rightv); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 1; + int64_t rightv = 1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_USMALLINT, &leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_UBIGINT, &rightv); + scltMakeOpNode(&opNode, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, leftv <= rightv); + nodesDestroyNode(res); } TEST(constantTest, int_equal_smallint1) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1; - int16_t rightv = 1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); - scltMakeOpNode(&opNode, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, leftv == rightv); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 1; + int16_t rightv = 1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); + scltMakeOpNode(&opNode, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, leftv == rightv); + nodesDestroyNode(res); } TEST(constantTest, int_equal_smallint2) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 0, rightv = 1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); - scltMakeOpNode(&opNode, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, leftv == rightv); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 0, rightv = 1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); + scltMakeOpNode(&opNode, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, leftv == rightv); + nodesDestroyNode(res); } TEST(constantTest, int_not_equal_smallint1) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1, rightv = 1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); - scltMakeOpNode(&opNode, OP_TYPE_NOT_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, leftv != rightv); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 1, rightv = 1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); + scltMakeOpNode(&opNode, OP_TYPE_NOT_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, leftv != rightv); + nodesDestroyNode(res); } TEST(constantTest, int_not_equal_smallint2) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 0, rightv = 1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); - scltMakeOpNode(&opNode, OP_TYPE_NOT_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, leftv != rightv); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 0, rightv = 1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); + scltMakeOpNode(&opNode, OP_TYPE_NOT_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, leftv != rightv); + nodesDestroyNode(res); } TEST(constantTest, int_in_smallint1) { - scltInitLogFile(); - - SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; - int32_t leftv = 1, rightv1 = 1,rightv2 = 2,rightv3 = 3; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - SNodeList* list = nodesMakeList(); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); - nodesListAppend(list, pRight); - scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); - scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + scltInitLogFile(); + + SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; + int32_t leftv = 1, rightv1 = 1, rightv2 = 2, rightv3 = 3; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + SNodeList *list = nodesMakeList(); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); + nodesListAppend(list, pRight); + scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT); + scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, int_in_smallint2) { - scltInitLogFile(); - - SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; - int32_t leftv = 4, rightv1 = 1,rightv2 = 2,rightv3 = 3; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - SNodeList* list = nodesMakeList(); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); - nodesListAppend(list, pRight); - scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); - scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, false); - nodesDestroyNode(res); + scltInitLogFile(); + + SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; + int32_t leftv = 4, rightv1 = 1, rightv2 = 2, rightv3 = 3; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + SNodeList *list = nodesMakeList(); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); + nodesListAppend(list, pRight); + scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT); + scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, false); + nodesDestroyNode(res); } TEST(constantTest, int_not_in_smallint1) { - SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; - int32_t leftv = 1, rightv1 = 1,rightv2 = 2,rightv3 = 3; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - SNodeList* list = nodesMakeList(); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); - nodesListAppend(list, pRight); - scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); - scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, false); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; + int32_t leftv = 1, rightv1 = 1, rightv2 = 2, rightv3 = 3; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + SNodeList *list = nodesMakeList(); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); + nodesListAppend(list, pRight); + scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT); + scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, false); + nodesDestroyNode(res); } TEST(constantTest, int_not_in_smallint2) { - scltInitLogFile(); - - SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; - int32_t leftv = 4, rightv1 = 1,rightv2 = 2,rightv3 = 3; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - SNodeList* list = nodesMakeList(); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); - nodesListAppend(list, pRight); - scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); - scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + scltInitLogFile(); + + SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL; + int32_t leftv = 4, rightv1 = 1, rightv2 = 2, rightv3 = 3; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + SNodeList *list = nodesMakeList(); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3); + nodesListAppend(list, pRight); + scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT); + scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, binary_like_binary1) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - char leftv[64] = {0}, rightv[64] = {0}; - sprintf(&leftv[2], "%s", "abc"); - varDataSetLen(leftv, strlen(&leftv[2])); - sprintf(&rightv[2], "%s", "a_c"); - varDataSetLen(rightv, strlen(&rightv[2])); - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); - scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + char leftv[64] = {0}, rightv[64] = {0}; + sprintf(&leftv[2], "%s", "abc"); + varDataSetLen(leftv, strlen(&leftv[2])); + sprintf(&rightv[2], "%s", "a_c"); + varDataSetLen(rightv, strlen(&rightv[2])); + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); + scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, binary_like_binary2) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - char leftv[64] = {0}, rightv[64] = {0}; - sprintf(&leftv[2], "%s", "abc"); - varDataSetLen(leftv, strlen(&leftv[2])); - sprintf(&rightv[2], "%s", "ac"); - varDataSetLen(rightv, strlen(&rightv[2])); - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); - scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, false); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + char leftv[64] = {0}, rightv[64] = {0}; + sprintf(&leftv[2], "%s", "abc"); + varDataSetLen(leftv, strlen(&leftv[2])); + sprintf(&rightv[2], "%s", "ac"); + varDataSetLen(rightv, strlen(&rightv[2])); + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); + scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, false); + nodesDestroyNode(res); } TEST(constantTest, binary_not_like_binary1) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - char leftv[64] = {0}, rightv[64] = {0}; - sprintf(&leftv[2], "%s", "abc"); - varDataSetLen(leftv, strlen(&leftv[2])); - sprintf(&rightv[2], "%s", "a%c"); - varDataSetLen(rightv, strlen(&rightv[2])); - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); - scltMakeOpNode(&opNode, OP_TYPE_NOT_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, false); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + char leftv[64] = {0}, rightv[64] = {0}; + sprintf(&leftv[2], "%s", "abc"); + varDataSetLen(leftv, strlen(&leftv[2])); + sprintf(&rightv[2], "%s", "a%c"); + varDataSetLen(rightv, strlen(&rightv[2])); + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); + scltMakeOpNode(&opNode, OP_TYPE_NOT_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, false); + nodesDestroyNode(res); } TEST(constantTest, binary_not_like_binary2) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - char leftv[64] = {0}, rightv[64] = {0}; - sprintf(&leftv[2], "%s", "abc"); - varDataSetLen(leftv, strlen(&leftv[2])); - sprintf(&rightv[2], "%s", "ac"); - varDataSetLen(rightv, strlen(&rightv[2])); - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); - scltMakeOpNode(&opNode, OP_TYPE_NOT_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + char leftv[64] = {0}, rightv[64] = {0}; + sprintf(&leftv[2], "%s", "abc"); + varDataSetLen(leftv, strlen(&leftv[2])); + sprintf(&rightv[2], "%s", "ac"); + varDataSetLen(rightv, strlen(&rightv[2])); + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); + scltMakeOpNode(&opNode, OP_TYPE_NOT_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, binary_match_binary1) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - char leftv[64] = {0}, rightv[64] = {0}; - sprintf(&leftv[2], "%s", "abc"); - varDataSetLen(leftv, strlen(&leftv[2])); - sprintf(&rightv[2], "%s", ".*"); - varDataSetLen(rightv, strlen(&rightv[2])); - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); - scltMakeOpNode(&opNode, OP_TYPE_MATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + char leftv[64] = {0}, rightv[64] = {0}; + sprintf(&leftv[2], "%s", "abc"); + varDataSetLen(leftv, strlen(&leftv[2])); + sprintf(&rightv[2], "%s", ".*"); + varDataSetLen(rightv, strlen(&rightv[2])); + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); + scltMakeOpNode(&opNode, OP_TYPE_MATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, binary_match_binary2) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - char leftv[64] = {0}, rightv[64] = {0}; - sprintf(&leftv[2], "%s", "abc"); - varDataSetLen(leftv, strlen(&leftv[2])); - sprintf(&rightv[2], "%s", "abc.+"); - varDataSetLen(rightv, strlen(&rightv[2])); - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); - scltMakeOpNode(&opNode, OP_TYPE_MATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, false); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + char leftv[64] = {0}, rightv[64] = {0}; + sprintf(&leftv[2], "%s", "abc"); + varDataSetLen(leftv, strlen(&leftv[2])); + sprintf(&rightv[2], "%s", "abc.+"); + varDataSetLen(rightv, strlen(&rightv[2])); + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); + scltMakeOpNode(&opNode, OP_TYPE_MATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, false); + nodesDestroyNode(res); } TEST(constantTest, binary_not_match_binary1) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - char leftv[64] = {0}, rightv[64] = {0}; - sprintf(&leftv[2], "%s", "abc"); - varDataSetLen(leftv, strlen(&leftv[2])); - sprintf(&rightv[2], "%s", "a[1-9]c"); - varDataSetLen(rightv, strlen(&rightv[2])); - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); - scltMakeOpNode(&opNode, OP_TYPE_NMATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + char leftv[64] = {0}, rightv[64] = {0}; + sprintf(&leftv[2], "%s", "abc"); + varDataSetLen(leftv, strlen(&leftv[2])); + sprintf(&rightv[2], "%s", "a[1-9]c"); + varDataSetLen(rightv, strlen(&rightv[2])); + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); + scltMakeOpNode(&opNode, OP_TYPE_NMATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, binary_not_match_binary2) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - char leftv[64] = {0}, rightv[64] = {0}; - sprintf(&leftv[2], "%s", "abc"); - varDataSetLen(leftv, strlen(&leftv[2])); - sprintf(&rightv[2], "%s", "a[ab]c"); - varDataSetLen(rightv, strlen(&rightv[2])); - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); - scltMakeOpNode(&opNode, OP_TYPE_NMATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, false); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + char leftv[64] = {0}, rightv[64] = {0}; + sprintf(&leftv[2], "%s", "abc"); + varDataSetLen(leftv, strlen(&leftv[2])); + sprintf(&rightv[2], "%s", "a[ab]c"); + varDataSetLen(rightv, strlen(&rightv[2])); + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); + scltMakeOpNode(&opNode, OP_TYPE_NMATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, false); + nodesDestroyNode(res); } TEST(constantTest, int_is_null1) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1, rightv = 1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 1, rightv = 1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, false); - nodesDestroyNode(res); + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, false); + nodesDestroyNode(res); } TEST(constantTest, int_is_null2) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = TSDB_DATA_INT_NULL, rightv = 1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_NULL, &leftv); - scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = TSDB_DATA_INT_NULL, rightv = 1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_NULL, &leftv); + scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, int_is_not_null1) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1, rightv = 1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 1, rightv = 1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, int_is_not_null2) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1, rightv = 1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_NULL, &leftv); - scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 1, rightv = 1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_NULL, &leftv); + scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, false); - nodesDestroyNode(res); + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, false); + nodesDestroyNode(res); } TEST(constantTest, int_add_int_is_true1) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1, rightv = 1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv); - scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); - scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 1, rightv = 1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv); + scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); + scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, int_add_int_is_true2) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1, rightv = -1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv); - scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); - scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, false); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 1, rightv = -1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv); + scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); + scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, false); + nodesDestroyNode(res); } TEST(constantTest, int_greater_int_is_true1) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1, rightv = 1; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv); - scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, false); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 1, rightv = 1; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv); + scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, false); + nodesDestroyNode(res); } TEST(constantTest, int_greater_int_is_true2) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; - int32_t leftv = 1, rightv = 0; - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv); - scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); - - int32_t code = scalarCalculateConstants(opNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; + int32_t leftv = 1, rightv = 0; + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv); + scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); + + int32_t code = scalarCalculateConstants(opNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, greater_and_lower) { - scltInitLogFile(); - - SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL; - bool eRes[5] = {false, false, true, true, true}; - int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20; - SNode *list[2] = {0}; - scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1); - scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2); - scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); - scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3); - scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v4); - scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); - list[0] = opNode1; - list[1] = opNode2; - scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); - - int32_t code = scalarCalculateConstants(logicNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + scltInitLogFile(); + + SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL; + bool eRes[5] = {false, false, true, true, true}; + int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20; + SNode *list[2] = {0}; + scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1); + scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2); + scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); + scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3); + scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v4); + scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); + list[0] = opNode1; + list[1] = opNode2; + scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); + + int32_t code = scalarCalculateConstants(logicNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, column_and_value1) { - scltInitLogFile(); - - SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL; - bool eRes[5] = {false, false, true, true, true}; - int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20; - SNode *list[2] = {0}; - scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1); - scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2); - scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); - scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3); - scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL); - scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); - list[0] = opNode1; - list[1] = opNode2; - scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); - - int32_t code = scalarCalculateConstants(logicNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_LOGIC_CONDITION); - SLogicConditionNode *v = (SLogicConditionNode *)res; - ASSERT_EQ(v->condType, LOGIC_COND_TYPE_AND); - ASSERT_EQ(v->pParameterList->length, 1); - nodesDestroyNode(res); + scltInitLogFile(); + + SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL; + bool eRes[5] = {false, false, true, true, true}; + int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20; + SNode *list[2] = {0}; + scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1); + scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2); + scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); + scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3); + scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL); + scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); + list[0] = opNode1; + list[1] = opNode2; + scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); + + int32_t code = scalarCalculateConstants(logicNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_LOGIC_CONDITION); + SLogicConditionNode *v = (SLogicConditionNode *)res; + ASSERT_EQ(v->condType, LOGIC_COND_TYPE_AND); + ASSERT_EQ(v->pParameterList->length, 1); + nodesDestroyNode(res); } TEST(constantTest, column_and_value2) { - scltInitLogFile(); - - SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL; - bool eRes[5] = {false, false, true, true, true}; - int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20; - SNode *list[2] = {0}; - scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1); - scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2); - scltMakeOpNode(&opNode1, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); - scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3); - scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL); - scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); - list[0] = opNode1; - list[1] = opNode2; - scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); - - int32_t code = scalarCalculateConstants(logicNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, false); - nodesDestroyNode(res); + scltInitLogFile(); + + SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL; + bool eRes[5] = {false, false, true, true, true}; + int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20; + SNode *list[2] = {0}; + scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1); + scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2); + scltMakeOpNode(&opNode1, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); + scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3); + scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL); + scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); + list[0] = opNode1; + list[1] = opNode2; + scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); + + int32_t code = scalarCalculateConstants(logicNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, false); + nodesDestroyNode(res); } TEST(constantTest, column_and_value3) { - scltInitLogFile(); - - SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL; - bool eRes[5] = {false, false, true, true, true}; - int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20; - SNode *list[2] = {0}; - scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1); - scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2); - scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); - scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3); - scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL); - scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); - list[0] = opNode1; - list[1] = opNode2; - scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_OR, list, 2); - - int32_t code = scalarCalculateConstants(logicNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); - SValueNode *v = (SValueNode *)res; - ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(v->datum.b, true); - nodesDestroyNode(res); + scltInitLogFile(); + + SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL; + bool eRes[5] = {false, false, true, true, true}; + int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20; + SNode *list[2] = {0}; + scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1); + scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2); + scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); + scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3); + scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL); + scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); + list[0] = opNode1; + list[1] = opNode2; + scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_OR, list, 2); + + int32_t code = scalarCalculateConstants(logicNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); + SValueNode *v = (SValueNode *)res; + ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(v->datum.b, true); + nodesDestroyNode(res); } TEST(constantTest, column_and_value4) { - scltInitLogFile(); - - SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL; - bool eRes[5] = {false, false, true, true, true}; - int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20; - SNode *list[2] = {0}; - scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1); - scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2); - scltMakeOpNode(&opNode1, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); - scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3); - scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL); - scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); - list[0] = opNode1; - list[1] = opNode2; - scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_OR, list, 2); - - int32_t code = scalarCalculateConstants(logicNode, &res); - ASSERT_EQ(code, 0); - ASSERT_TRUE(res); - ASSERT_EQ(nodeType(res), QUERY_NODE_LOGIC_CONDITION); - SLogicConditionNode *v = (SLogicConditionNode *)res; - ASSERT_EQ(v->condType, LOGIC_COND_TYPE_OR); - ASSERT_EQ(v->pParameterList->length, 1); - nodesDestroyNode(res); -} - - -void makeJsonArrow(SSDataBlock **src, SNode **opNode, void *json, char *key){ - char keyVar[32] = {0}; - memcpy(varDataVal(keyVar), key, strlen(key)); - varDataLen(keyVar) = strlen(key); - - SNode *pLeft = NULL, *pRight = NULL; - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, keyVar); - scltMakeColumnNode(&pLeft, src, TSDB_DATA_TYPE_JSON, ((STag*)json)->len, 1, json); - scltMakeOpNode(opNode, OP_TYPE_JSON_GET_VALUE, TSDB_DATA_TYPE_JSON, pLeft, pRight); -} - -void makeOperator(SNode **opNode, SArray *blockList, EOperatorType opType, int32_t rightType, void *rightData, bool isReverse){ - int32_t resType = TSDB_DATA_TYPE_NULL; - if(opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || - opType == OP_TYPE_DIV || opType == OP_TYPE_REM || opType == OP_TYPE_MINUS){ - resType = TSDB_DATA_TYPE_DOUBLE; - }else if(opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR){ - resType = TSDB_DATA_TYPE_BIGINT; - }else if(opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || - opType == OP_TYPE_LOWER_THAN || opType == OP_TYPE_LOWER_EQUAL || - opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL || - opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE || - opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH || - opType == OP_TYPE_NMATCH){ - resType = TSDB_DATA_TYPE_BOOL; - } - - SNode *right = NULL; - scltMakeValueNode(&right, rightType, rightData); - scltMakeOpNode2(opNode, opType, resType, *opNode, right, isReverse); - - SColumnInfo colInfo = createColumnInfo(1, resType, tDataTypes[resType].bytes); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, 1, &colInfo); - scltMakeTargetNode(opNode, dataBlockId, slotId, *opNode); -} - -void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, double exceptValue, EOperatorType opType, bool isReverse){ - SArray *blockList = taosArrayInit(2, POINTER_BYTES); - SSDataBlock *src = NULL; - SNode *opNode = NULL; - - makeJsonArrow(&src, &opNode, json, (char*)key); - taosArrayPush(blockList, &src); - - makeOperator(&opNode, blockList, opType, rightType, rightData, isReverse); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, 1); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - - if(colDataIsNull_f(column->nullbitmap, 0)){ - ASSERT_EQ(DBL_MAX, exceptValue); - printf("result:NULL\n"); - - }else if(opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || opType == OP_TYPE_DIV || - opType == OP_TYPE_REM || opType == OP_TYPE_MINUS){ - printf("op:%s,1result:%f,except:%f\n", operatorTypeStr(opType), *((double *)colDataGetData(column, 0)), exceptValue); - ASSERT_TRUE(fabs(*((double *)colDataGetData(column, 0)) - exceptValue) < 0.0001); - }else if(opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR){ - printf("op:%s,2result:%" PRId64 ",except:%f\n", operatorTypeStr(opType), *((int64_t *)colDataGetData(column, 0)), exceptValue); - ASSERT_EQ(*((int64_t *)colDataGetData(column, 0)), exceptValue); - }else if(opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN || - opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL || - opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE || - opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH || opType == OP_TYPE_NMATCH){ - printf("op:%s,3result:%d,except:%f\n", operatorTypeStr(opType), *((bool *)colDataGetData(column, 0)), exceptValue); - ASSERT_EQ(*((bool *)colDataGetData(column, 0)), exceptValue); - } - - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + scltInitLogFile(); + + SNode *pval1 = NULL, *pval2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL, *res = NULL; + bool eRes[5] = {false, false, true, true, true}; + int64_t v1 = 333, v2 = 222, v3 = -10, v4 = 20; + SNode *list[2] = {0}; + scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v1); + scltMakeValueNode(&pval2, TSDB_DATA_TYPE_BIGINT, &v2); + scltMakeOpNode(&opNode1, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); + scltMakeValueNode(&pval1, TSDB_DATA_TYPE_BIGINT, &v3); + scltMakeColumnNode(&pval2, NULL, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), 0, NULL); + scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pval1, pval2); + list[0] = opNode1; + list[1] = opNode2; + scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_OR, list, 2); + + int32_t code = scalarCalculateConstants(logicNode, &res); + ASSERT_EQ(code, 0); + ASSERT_TRUE(res); + ASSERT_EQ(nodeType(res), QUERY_NODE_LOGIC_CONDITION); + SLogicConditionNode *v = (SLogicConditionNode *)res; + ASSERT_EQ(v->condType, LOGIC_COND_TYPE_OR); + ASSERT_EQ(v->pParameterList->length, 1); + nodesDestroyNode(res); +} + +void makeJsonArrow(SSDataBlock **src, SNode **opNode, void *json, char *key) { + char keyVar[32] = {0}; + memcpy(varDataVal(keyVar), key, strlen(key)); + varDataLen(keyVar) = strlen(key); + + SNode *pLeft = NULL, *pRight = NULL; + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, keyVar); + scltMakeColumnNode(&pLeft, src, TSDB_DATA_TYPE_JSON, ((STag *)json)->len, 1, json); + scltMakeOpNode(opNode, OP_TYPE_JSON_GET_VALUE, TSDB_DATA_TYPE_JSON, pLeft, pRight); +} + +void makeOperator(SNode **opNode, SArray *blockList, EOperatorType opType, int32_t rightType, void *rightData, + bool isReverse) { + int32_t resType = TSDB_DATA_TYPE_NULL; + if (opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || opType == OP_TYPE_DIV || + opType == OP_TYPE_REM || opType == OP_TYPE_MINUS) { + resType = TSDB_DATA_TYPE_DOUBLE; + } else if (opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR) { + resType = TSDB_DATA_TYPE_BIGINT; + } else if (opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN || + opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL || + opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE || + opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH || + opType == OP_TYPE_NMATCH) { + resType = TSDB_DATA_TYPE_BOOL; + } + + SNode *right = NULL; + scltMakeValueNode(&right, rightType, rightData); + scltMakeOpNode2(opNode, opType, resType, *opNode, right, isReverse); + + SColumnInfo colInfo = createColumnInfo(1, resType, tDataTypes[resType].bytes); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, 1, &colInfo); + scltMakeTargetNode(opNode, dataBlockId, slotId, *opNode); +} + +void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, double exceptValue, EOperatorType opType, + bool isReverse) { + SArray *blockList = taosArrayInit(2, POINTER_BYTES); + SSDataBlock *src = NULL; + SNode *opNode = NULL; + + makeJsonArrow(&src, &opNode, json, (char *)key); + taosArrayPush(blockList, &src); + + makeOperator(&opNode, blockList, opType, rightType, rightData, isReverse); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, 1); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + + if (colDataIsNull_f(column->nullbitmap, 0)) { + ASSERT_EQ(DBL_MAX, exceptValue); + printf("result:NULL\n"); + + } else if (opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || opType == OP_TYPE_DIV || + opType == OP_TYPE_REM || opType == OP_TYPE_MINUS) { + printf("op:%s,1result:%f,except:%f\n", operatorTypeStr(opType), *((double *)colDataGetData(column, 0)), + exceptValue); + ASSERT_TRUE(fabs(*((double *)colDataGetData(column, 0)) - exceptValue) < 0.0001); + } else if (opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR) { + printf("op:%s,2result:%" PRId64 ",except:%f\n", operatorTypeStr(opType), *((int64_t *)colDataGetData(column, 0)), + exceptValue); + ASSERT_EQ(*((int64_t *)colDataGetData(column, 0)), exceptValue); + } else if (opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN || + opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL || + opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE || + opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH || + opType == OP_TYPE_NMATCH) { + printf("op:%s,3result:%d,except:%f\n", operatorTypeStr(opType), *((bool *)colDataGetData(column, 0)), exceptValue); + ASSERT_EQ(*((bool *)colDataGetData(column, 0)), exceptValue); + } + + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, json_column_arith_op) { - scltInitLogFile(); - char *rightvTmp= "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":\"8hel\"}"; - - char rightv[256] = {0}; - memcpy(rightv, rightvTmp, strlen(rightvTmp)); - SArray *tags = taosArrayInit(1, sizeof(STagVal)); - STag* row = NULL; - parseJsontoTagData(rightv, tags, &row, NULL); - - const int32_t len = 8; - EOperatorType op[len] = {OP_TYPE_ADD, OP_TYPE_SUB, OP_TYPE_MULTI, OP_TYPE_DIV, - OP_TYPE_REM, OP_TYPE_MINUS, OP_TYPE_BIT_AND, OP_TYPE_BIT_OR}; - int32_t input[len] = {1, 8, 2, 2, 3, 0, -4, 9}; - - printf("--------------------json int-4 op {1, 8, 2, 2, 3, 0, -4, 9}--------------------\n"); - char *key = "k1"; - double eRes00[len] = {5.0, -4, 8.0, 2.0, 1.0, -4, 4&-4, 4|9}; - double eRes01[len] = {5.0, 4, 8.0, 0.5, 3, 0, 4&-4, 4|9}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes00[i], op[i], false); - } - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes01[i], op[i], true); - } - - printf("--------------------json string- 0 op {1, 8, 2, 2, 3, 0, -4, 9}--------------------\n"); - - key = "k2"; - double eRes10[len] = {1.0, -8, 0, 0, 0, 0, 0, 9}; - double eRes11[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes10[i], op[i], false); - } - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes11[i], op[i], true); - } - - printf("---------------------json null- null op {1, 8, 2, 2, 3, 0, -4, 9}-------------------\n"); - - key = "k3"; - double eRes20[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX}; - double eRes21[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes20[i], op[i], false); - } - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes21[i], op[i], true); - } - - printf("---------------------json bool- true op {1, 8, 2, 2, 3, 0, -4, 9}-------------------\n"); - - key = "k4"; - double eRes30[len] = {2.0, -7, 2, 0.5, 1, -1, 1&-4, 1|9}; - double eRes31[len] = {2.0, 7, 2, 2, 0, 0, 1&-4, 1|9}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes30[i], op[i], false); - } - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes31[i], op[i], true); - } - - printf("----------------------json double-- 5.44 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); - - key = "k5"; - double eRes40[len] = {6.44, -2.56, 10.88, 2.72, 2.44, -5.44, 5&-4, 5|9}; - double eRes41[len] = {6.44, 2.56, 10.88, 0.3676470588235294, 3, 0, 5&-4, 5|9}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes40[i], op[i], false); - } - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes41[i], op[i], true); - } - - printf("----------------------json int-- -10 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); - - key = "k6"; - double eRes50[len] = {-9, -18, -20, -5, -10%3, 10, -10&-4, -10|9}; - double eRes51[len] = {-9, 18, -20, -0.2, 3%-10, 0, -10&-4, -10|9}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes50[i], op[i], false); - } - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes51[i], op[i], true); - } - - printf("----------------------json double-- -9.8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); - - key = "k7"; - double eRes60[len] = {-8.8, -17.8, -19.6, -4.9, -0.8, 9.8, -9&-4, -9|9}; - double eRes61[len] = {-8.8, 17.8, -19.6, -0.2040816326530612, 3, 0, -9&-4, -9|9}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes60[i], op[i], false); - } - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes61[i], op[i], true); - } - - printf("----------------------json bool-- 0 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); - - key = "k8"; - double eRes70[len] = {1.0, -8, 0, 0, 0, 0, 0, 9}; - double eRes71[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes70[i], op[i], false); - } - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes71[i], op[i], true); - } - - printf("----------------------json string-- 8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); - - key = "k9"; - double eRes80[len] = {9, 0, 16, 4, 8%3, -8, 8&-4, 8|9}; - double eRes81[len] = {9, 0, 16, 0.25, 3%8, 0, 8&-4, 8|9}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes80[i], op[i], false); - } - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes81[i], op[i], true); - } - - printf("---------------------json not exist-- NULL op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); - - key = "k10"; - double eRes90[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX}; - double eRes91[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes90[i], op[i], false); - } - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes91[i], op[i], true); - } - - taosArrayDestroy(tags); - taosMemoryFree(row); -} - -void *prepareNchar(char* rightData){ - int32_t len = 0; - int32_t inputLen = strlen(rightData); - - char* t = (char*)taosMemoryCalloc(1,(inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); - taosMbsToUcs4(rightData, inputLen, (TdUcs4*) varDataVal(t), inputLen * TSDB_NCHAR_SIZE, &len); - varDataSetLen(t, len); - return t; + scltInitLogFile(); + char *rightvTmp = + "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":" + "\"8hel\"}"; + + char rightv[256] = {0}; + memcpy(rightv, rightvTmp, strlen(rightvTmp)); + SArray *tags = taosArrayInit(1, sizeof(STagVal)); + STag *row = NULL; + parseJsontoTagData(rightv, tags, &row, NULL); + + const int32_t len = 8; + EOperatorType op[len] = {OP_TYPE_ADD, OP_TYPE_SUB, OP_TYPE_MULTI, OP_TYPE_DIV, + OP_TYPE_REM, OP_TYPE_MINUS, OP_TYPE_BIT_AND, OP_TYPE_BIT_OR}; + int32_t input[len] = {1, 8, 2, 2, 3, 0, -4, 9}; + + printf("--------------------json int-4 op {1, 8, 2, 2, 3, 0, -4, 9}--------------------\n"); + char *key = "k1"; + double eRes00[len] = {5.0, -4, 8.0, 2.0, 1.0, -4, 4 & -4, 4 | 9}; + double eRes01[len] = {5.0, 4, 8.0, 0.5, 3, 0, 4 & -4, 4 | 9}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes00[i], op[i], false); + } + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes01[i], op[i], true); + } + + printf("--------------------json string- 0 op {1, 8, 2, 2, 3, 0, -4, 9}--------------------\n"); + + key = "k2"; + double eRes10[len] = {1.0, -8, 0, 0, 0, 0, 0, 9}; + double eRes11[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes10[i], op[i], false); + } + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes11[i], op[i], true); + } + + printf("---------------------json null- null op {1, 8, 2, 2, 3, 0, -4, 9}-------------------\n"); + + key = "k3"; + double eRes20[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX}; + double eRes21[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes20[i], op[i], false); + } + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes21[i], op[i], true); + } + + printf("---------------------json bool- true op {1, 8, 2, 2, 3, 0, -4, 9}-------------------\n"); + + key = "k4"; + double eRes30[len] = {2.0, -7, 2, 0.5, 1, -1, 1 & -4, 1 | 9}; + double eRes31[len] = {2.0, 7, 2, 2, 0, 0, 1 & -4, 1 | 9}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes30[i], op[i], false); + } + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes31[i], op[i], true); + } + + printf("----------------------json double-- 5.44 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); + + key = "k5"; + double eRes40[len] = {6.44, -2.56, 10.88, 2.72, 2.44, -5.44, 5 & -4, 5 | 9}; + double eRes41[len] = {6.44, 2.56, 10.88, 0.3676470588235294, 3, 0, 5 & -4, 5 | 9}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes40[i], op[i], false); + } + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes41[i], op[i], true); + } + + printf("----------------------json int-- -10 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); + + key = "k6"; + double eRes50[len] = {-9, -18, -20, -5, -10 % 3, 10, -10 & -4, -10 | 9}; + double eRes51[len] = {-9, 18, -20, -0.2, 3 % -10, 0, -10 & -4, -10 | 9}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes50[i], op[i], false); + } + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes51[i], op[i], true); + } + + printf("----------------------json double-- -9.8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); + + key = "k7"; + double eRes60[len] = {-8.8, -17.8, -19.6, -4.9, -0.8, 9.8, -9 & -4, -9 | 9}; + double eRes61[len] = {-8.8, 17.8, -19.6, -0.2040816326530612, 3, 0, -9 & -4, -9 | 9}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes60[i], op[i], false); + } + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes61[i], op[i], true); + } + + printf("----------------------json bool-- 0 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); + + key = "k8"; + double eRes70[len] = {1.0, -8, 0, 0, 0, 0, 0, 9}; + double eRes71[len] = {1.0, 8, 0, DBL_MAX, DBL_MAX, 0, 0, 9}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes70[i], op[i], false); + } + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes71[i], op[i], true); + } + + printf("----------------------json string-- 8 op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); + + key = "k9"; + double eRes80[len] = {9, 0, 16, 4, 8 % 3, -8, 8 & -4, 8 | 9}; + double eRes81[len] = {9, 0, 16, 0.25, 3 % 8, 0, 8 & -4, 8 | 9}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes80[i], op[i], false); + } + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes81[i], op[i], true); + } + + printf("---------------------json not exist-- NULL op {1, 8, 2, 2, 3, 0, -4, 9}------------------\n"); + + key = "k10"; + double eRes90[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX}; + double eRes91[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, 0, DBL_MAX, DBL_MAX}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes90[i], op[i], false); + } + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes91[i], op[i], true); + } + + taosArrayDestroy(tags); + taosMemoryFree(row); +} + +void *prepareNchar(char *rightData) { + int32_t len = 0; + int32_t inputLen = strlen(rightData); + + char *t = (char *)taosMemoryCalloc(1, (inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); + taosMbsToUcs4(rightData, inputLen, (TdUcs4 *)varDataVal(t), inputLen * TSDB_NCHAR_SIZE, &len); + varDataSetLen(t, len); + return t; } TEST(columnTest, json_column_logic_op) { - scltInitLogFile(); - char *rightvTmp= "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":\"6.6hello\"}"; - - char rightv[256] = {0}; - memcpy(rightv, rightvTmp, strlen(rightvTmp)); - SArray *tags = taosArrayInit(1, sizeof(STagVal)); - STag* row = NULL; - parseJsontoTagData(rightv, tags, &row, NULL); - - const int32_t len0 = 6; - const int32_t len = 9; - const int32_t len1 = 4; - EOperatorType op[len+len1] = {OP_TYPE_GREATER_THAN, OP_TYPE_GREATER_EQUAL, OP_TYPE_LOWER_THAN, OP_TYPE_LOWER_EQUAL, OP_TYPE_EQUAL, OP_TYPE_NOT_EQUAL, - OP_TYPE_IS_NULL, OP_TYPE_IS_NOT_NULL, OP_TYPE_IS_TRUE, OP_TYPE_LIKE, OP_TYPE_NOT_LIKE, OP_TYPE_MATCH, OP_TYPE_NMATCH}; - - int32_t input[len] = {1, 8, 2, 2, 3, 0, 0, 0, 0}; - char *inputNchar[len1] = {"hell_", "hel%", "hell", "llll"}; - - printf("--------------------json int---4 {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n"); - char *key = "k1"; - bool eRes[len+len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes[i], op[i], false); - } - bool eRes_0[len0] = {false, true, true, true, false, true}; - for(int i = 0; i < len0; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_0[i], op[i], true); - } - for(int i = len; i < len + len1; i++){ - void* rightData = prepareNchar(inputNchar[i-len]); - makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes[i], op[i], false); - taosMemoryFree(rightData); - } - - printf("--------------------json string--0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); - - key = "k2"; - bool eRes1[len+len1] = {false, false, false, false, false, false, false, true, false, true, false, true, true}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes1[i], op[i], false); - } - bool eRes_1[len0] = {false, false, false, false, false, false}; - for(int i = 0; i < len0; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_1[i], op[i], true); - } - - for(int i = len; i < len + len1; i++){ - void* rightData = prepareNchar(inputNchar[i-len]); - makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes1[i], op[i], false); - taosMemoryFree(rightData); - } - - printf("--------------------json null---null {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n"); - - key = "k3"; // (null is true) return NULL, so use DBL_MAX represent NULL - bool eRes2[len+len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes2[i], op[i], false); - } - bool eRes_2[len0] = {false, false, false, false, false, false}; - for(int i = 0; i < len0; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_2[i], op[i], true); - } - - for(int i = len; i < len + len1; i++){ - void* rightData = prepareNchar(inputNchar[i-len]); - makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes2[i], op[i], false); - taosMemoryFree(rightData); - } - - printf("--------------------json bool--1 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); - - key = "k4"; - bool eRes3[len+len1] = {false, false, false, false, false, false, false, true, true, false, false, false, false}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes3[i], op[i], false); - } - bool eRes_3[len0] = {false, false, false, false, false, false}; - for(int i = 0; i < len0; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_3[i], op[i], true); - } - - for(int i = len; i < len + len1; i++){ - void* rightData = prepareNchar(inputNchar[i-len]); - makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes3[i], op[i], false); - taosMemoryFree(rightData); - } - - printf("--------------------json double--5.44 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); - - key = "k5"; - bool eRes4[len+len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes4[i], op[i], false); - } - bool eRes_4[len0] = {false, true, true, true, false, true}; - for(int i = 0; i < len0; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_4[i], op[i], true); - } - - for(int i = len; i < len + len1; i++){ - void* rightData = prepareNchar(inputNchar[i-len]); - makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes4[i], op[i], false); - taosMemoryFree(rightData); - } - - printf("--------------------json int-- -10 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); - - key = "k6"; - bool eRes5[len+len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes5[i], op[i], false); - } - bool eRes_5[len0] = {true, true, false, false, false, true}; - for(int i = 0; i < len0; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_5[i], op[i], true); - } - - for(int i = len; i < len + len1; i++){ - void* rightData = prepareNchar(inputNchar[i-len]); - makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes5[i], op[i], false); - taosMemoryFree(rightData); - } - - printf("--------------------json double-- -9.8 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); - - key = "k7"; - bool eRes6[len+len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes6[i], op[i], false); - } - bool eRes_6[len0] = {true, true, false, false, false, true}; - for(int i = 0; i < len0; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_6[i], op[i], true); - } - - for(int i = len; i < len + len1; i++){ - void* rightData = prepareNchar(inputNchar[i-len]); - makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes6[i], op[i], false); - taosMemoryFree(rightData); - } - - - printf("--------------------json bool-- 0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); - - key = "k8"; - bool eRes7[len+len1] = {false, false, false, false, false, false, false, true, false, false, false, false, false}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes7[i], op[i], false); - } - bool eRes_7[len0] = {false, false, false, false, false, false}; - for(int i = 0; i < len0; i++) { - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_7[i], op[i], true); - } - - for(int i = len; i < len + len1; i++){ - void* rightData = prepareNchar(inputNchar[i-len]); - makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes7[i], op[i], false); - taosMemoryFree(rightData); - } - - - printf("--------------------json string-- 6.6hello {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); - - key = "k9"; - bool eRes8[len+len1] = {false, false, false, false, false, false, false, true, true, false, true, false, true}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes8[i], op[i], false); - } - bool eRes_8[len0] = {false, false, false, false, false, false}; - for(int i = 0; i < len0; i++) { - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_8[i], op[i], true); - } - - for(int i = len; i < len + len1; i++){ - void* rightData = prepareNchar(inputNchar[i-len]); - makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes8[i], op[i], false); - taosMemoryFree(rightData); - } - - printf("---------------------json not exist-- NULL {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n"); - - key = "k10"; // (NULL is true) return NULL, so use DBL_MAX represent NULL - bool eRes9[len+len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false}; - for(int i = 0; i < len; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes9[i], op[i], false); - } - bool eRes_9[len0] = {false, false, false, false, false, false}; - for(int i = 0; i < len0; i++) { - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_9[i], op[i], true); - } - - for(int i = len; i < len + len1; i++){ - void* rightData = prepareNchar(inputNchar[i-len]); - makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes9[i], op[i], false); - taosMemoryFree(rightData); - } - - taosArrayDestroy(tags); - taosMemoryFree(row); + scltInitLogFile(); + char *rightvTmp = + "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":-10,\"k7\":-9.8,\"k8\":false,\"k9\":\"6." + "6hello\"}"; + + char rightv[256] = {0}; + memcpy(rightv, rightvTmp, strlen(rightvTmp)); + SArray *tags = taosArrayInit(1, sizeof(STagVal)); + STag *row = NULL; + parseJsontoTagData(rightv, tags, &row, NULL); + + const int32_t len0 = 6; + const int32_t len = 9; + const int32_t len1 = 4; + EOperatorType op[len + len1] = {OP_TYPE_GREATER_THAN, OP_TYPE_GREATER_EQUAL, OP_TYPE_LOWER_THAN, OP_TYPE_LOWER_EQUAL, + OP_TYPE_EQUAL, OP_TYPE_NOT_EQUAL, OP_TYPE_IS_NULL, OP_TYPE_IS_NOT_NULL, + OP_TYPE_IS_TRUE, OP_TYPE_LIKE, OP_TYPE_NOT_LIKE, OP_TYPE_MATCH, + OP_TYPE_NMATCH}; + + int32_t input[len] = {1, 8, 2, 2, 3, 0, 0, 0, 0}; + char *inputNchar[len1] = {"hell_", "hel%", "hell", "llll"}; + + printf("--------------------json int---4 {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n"); + char *key = "k1"; + bool eRes[len + len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes[i], op[i], false); + } + bool eRes_0[len0] = {false, true, true, true, false, true}; + for (int i = 0; i < len0; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_0[i], op[i], true); + } + for (int i = len; i < len + len1; i++) { + void *rightData = prepareNchar(inputNchar[i - len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes[i], op[i], false); + taosMemoryFree(rightData); + } + + printf("--------------------json string--0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); + + key = "k2"; + bool eRes1[len + len1] = {false, false, false, false, false, false, false, true, false, true, false, true, true}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes1[i], op[i], false); + } + bool eRes_1[len0] = {false, false, false, false, false, false}; + for (int i = 0; i < len0; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_1[i], op[i], true); + } + + for (int i = len; i < len + len1; i++) { + void *rightData = prepareNchar(inputNchar[i - len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes1[i], op[i], false); + taosMemoryFree(rightData); + } + + printf("--------------------json null---null {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n"); + + key = "k3"; // (null is true) return NULL, so use DBL_MAX represent NULL + bool eRes2[len + len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes2[i], op[i], false); + } + bool eRes_2[len0] = {false, false, false, false, false, false}; + for (int i = 0; i < len0; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_2[i], op[i], true); + } + + for (int i = len; i < len + len1; i++) { + void *rightData = prepareNchar(inputNchar[i - len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes2[i], op[i], false); + taosMemoryFree(rightData); + } + + printf("--------------------json bool--1 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); + + key = "k4"; + bool eRes3[len + len1] = {false, false, false, false, false, false, false, true, true, false, false, false, false}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes3[i], op[i], false); + } + bool eRes_3[len0] = {false, false, false, false, false, false}; + for (int i = 0; i < len0; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_3[i], op[i], true); + } + + for (int i = len; i < len + len1; i++) { + void *rightData = prepareNchar(inputNchar[i - len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes3[i], op[i], false); + taosMemoryFree(rightData); + } + + printf("--------------------json double--5.44 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); + + key = "k5"; + bool eRes4[len + len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes4[i], op[i], false); + } + bool eRes_4[len0] = {false, true, true, true, false, true}; + for (int i = 0; i < len0; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_4[i], op[i], true); + } + + for (int i = len; i < len + len1; i++) { + void *rightData = prepareNchar(inputNchar[i - len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes4[i], op[i], false); + taosMemoryFree(rightData); + } + + printf("--------------------json int-- -10 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); + + key = "k6"; + bool eRes5[len + len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes5[i], op[i], false); + } + bool eRes_5[len0] = {true, true, false, false, false, true}; + for (int i = 0; i < len0; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_5[i], op[i], true); + } + + for (int i = len; i < len + len1; i++) { + void *rightData = prepareNchar(inputNchar[i - len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes5[i], op[i], false); + taosMemoryFree(rightData); + } + + printf("--------------------json double-- -9.8 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); + + key = "k7"; + bool eRes6[len + len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes6[i], op[i], false); + } + bool eRes_6[len0] = {true, true, false, false, false, true}; + for (int i = 0; i < len0; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_6[i], op[i], true); + } + + for (int i = len; i < len + len1; i++) { + void *rightData = prepareNchar(inputNchar[i - len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes6[i], op[i], false); + taosMemoryFree(rightData); + } + + printf("--------------------json bool-- 0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); + + key = "k8"; + bool eRes7[len + len1] = {false, false, false, false, false, false, false, true, false, false, false, false, false}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes7[i], op[i], false); + } + bool eRes_7[len0] = {false, false, false, false, false, false}; + for (int i = 0; i < len0; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_7[i], op[i], true); + } + + for (int i = len; i < len + len1; i++) { + void *rightData = prepareNchar(inputNchar[i - len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes7[i], op[i], false); + taosMemoryFree(rightData); + } + + printf("--------------------json string-- 6.6hello {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); + + key = "k9"; + bool eRes8[len + len1] = {false, false, false, false, false, false, false, true, true, false, true, false, true}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes8[i], op[i], false); + } + bool eRes_8[len0] = {false, false, false, false, false, false}; + for (int i = 0; i < len0; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_8[i], op[i], true); + } + + for (int i = len; i < len + len1; i++) { + void *rightData = prepareNchar(inputNchar[i - len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes8[i], op[i], false); + taosMemoryFree(rightData); + } + + printf("---------------------json not exist-- NULL {1, 8, 2, 2, 3, 0, 0, 0, 0}------------------\n"); + + key = "k10"; // (NULL is true) return NULL, so use DBL_MAX represent NULL + bool eRes9[len + len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false}; + for (int i = 0; i < len; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes9[i], op[i], false); + } + bool eRes_9[len0] = {false, false, false, false, false, false}; + for (int i = 0; i < len0; i++) { + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_9[i], op[i], true); + } + + for (int i = len; i < len + len1; i++) { + void *rightData = prepareNchar(inputNchar[i - len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes9[i], op[i], false); + taosMemoryFree(rightData); + } + + taosArrayDestroy(tags); + taosMemoryFree(row); } TEST(columnTest, smallint_value_add_int_column) { - scltInitLogFile(); - - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int32_t leftv = 1; - int16_t rightv[5]= {0, -5, -4, 23, 100}; - double eRes[5] = {1.0, -4, -3, 24, 101}; - SSDataBlock *src = NULL; - int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); - scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); - scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv); - scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); - - SArray *blockList = taosArrayInit(2, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_DOUBLE); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(column, i)), eRes[i]); - } - - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + scltInitLogFile(); + + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int32_t leftv = 1; + int16_t rightv[5] = {0, -5, -4, 23, 100}; + double eRes[5] = {1.0, -4, -3, 24, 101}; + SSDataBlock *src = NULL; + int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]); + scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv); + scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv); + scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); + + SArray *blockList = taosArrayInit(2, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_DOUBLE); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(column, i)), eRes[i]); + } + + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, bigint_column_multi_binary_column) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int64_t leftv[5]= {1, 2, 3, 4, 5}; - char rightv[5][5]= {0}; - for (int32_t i = 0; i < 5; ++i) { - rightv[i][2] = rightv[i][3] = '0'; - rightv[i][4] = '0' + i; - varDataSetLen(rightv[i], 3); - } - double eRes[5] = {0, 2, 6, 12, 20}; - SSDataBlock *src = NULL; - int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv); - scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); - scltMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_DOUBLE); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(column, i)), eRes[i]); - } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int64_t leftv[5] = {1, 2, 3, 4, 5}; + char rightv[5][5] = {0}; + for (int32_t i = 0; i < 5; ++i) { + rightv[i][2] = rightv[i][3] = '0'; + rightv[i][4] = '0' + i; + varDataSetLen(rightv[i], 3); + } + double eRes[5] = {0, 2, 6, 12, 20}; + SSDataBlock *src = NULL; + int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv); + scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); + scltMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_DOUBLE); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(column, i)), eRes[i]); + } + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, smallint_column_and_binary_column) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int16_t leftv[5]= {1, 2, 3, 4, 5}; - char rightv[5][5]= {0}; - for (int32_t i = 0; i < 5; ++i) { - rightv[i][2] = rightv[i][3] = '0'; - rightv[i][4] = '0' + i; - varDataSetLen(rightv[i], 3); - } - int64_t eRes[5] = {0, 0, 2, 0, 4}; - SSDataBlock *src = NULL; - int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); - scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); - scltMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]); - } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int16_t leftv[5] = {1, 2, 3, 4, 5}; + char rightv[5][5] = {0}; + for (int32_t i = 0; i < 5; ++i) { + rightv[i][2] = rightv[i][3] = '0'; + rightv[i][4] = '0' + i; + varDataSetLen(rightv[i], 3); + } + int64_t eRes[5] = {0, 0, 2, 0, 4}; + SSDataBlock *src = NULL; + int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); + scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); + scltMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]); + } + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, smallint_column_or_float_column) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int16_t leftv[5]= {1, 2, 3, 4, 5}; - float rightv[5]= {2.0, 3.0, 4.1, 5.2, 6.0}; - int64_t eRes[5] = {3, 3, 7, 5, 7}; - SSDataBlock *src = NULL; - int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); - scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv); - scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]); - } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int16_t leftv[5] = {1, 2, 3, 4, 5}; + float rightv[5] = {2.0, 3.0, 4.1, 5.2, 6.0}; + int64_t eRes[5] = {3, 3, 7, 5, 7}; + SSDataBlock *src = NULL; + int32_t rowNum = sizeof(rightv) / sizeof(rightv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); + scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv); + scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]); + } + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, smallint_column_or_double_value) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int16_t leftv[5]= {1, 2, 3, 4, 5}; - double rightv= 10.2; - int64_t eRes[5] = {11, 10, 11, 14, 15}; - SSDataBlock *src = NULL; - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); - scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]); - } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int16_t leftv[5] = {1, 2, 3, 4, 5}; + double rightv = 10.2; + int64_t eRes[5] = {11, 10, 11, 14, 15}; + SSDataBlock *src = NULL; + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); + scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BIGINT); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int64_t *)colDataGetData(column, i)), eRes[i]); + } + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, smallint_column_greater_double_value) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - int16_t leftv[5]= {1, 2, 3, 4, 5}; - double rightv= 2.5; - bool eRes[5] = {false, false, true, true, true}; - SSDataBlock *src = NULL; - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); - scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); - } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + int16_t leftv[5] = {1, 2, 3, 4, 5}; + double rightv = 2.5; + bool eRes[5] = {false, false, true, true, true}; + SSDataBlock *src = NULL; + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); + scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); + } + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, int_column_in_double_list) { - SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; - int32_t leftv[5] = {1, 2, 3, 4, 5}; - double rightv1 = 1.1,rightv2 = 2.2,rightv3 = 3.3; - bool eRes[5] = {true, true, true, false, false}; - SSDataBlock *src = NULL; - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); - SNodeList* list = nodesMakeList(); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3); - nodesListAppend(list, pRight); - scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT); - scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); - } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; + int32_t leftv[5] = {1, 2, 3, 4, 5}; + double rightv1 = 1.1, rightv2 = 2.2, rightv3 = 3.3; + bool eRes[5] = {true, true, true, false, false}; + SSDataBlock *src = NULL; + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); + SNodeList *list = nodesMakeList(); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3); + nodesListAppend(list, pRight); + scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_INT); + scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); + } + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, binary_column_in_binary_list) { - SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; - bool eRes[5] = {true, true, false, false, false}; - SSDataBlock *src = NULL; - char leftv[5][5]= {0}; - char rightv[3][5]= {0}; - for (int32_t i = 0; i < 5; ++i) { - leftv[i][2] = 'a' + i; - leftv[i][3] = 'b' + i; - leftv[i][4] = '0' + i; - varDataSetLen(leftv[i], 3); - } - for (int32_t i = 0; i < 2; ++i) { - rightv[i][2] = 'a' + i; - rightv[i][3] = 'b' + i; - rightv[i][4] = '0' + i; - varDataSetLen(rightv[i], 3); - } - for (int32_t i = 2; i < 3; ++i) { - rightv[i][2] = 'a' + i; - rightv[i][3] = 'a' + i; - rightv[i][4] = 'a' + i; - varDataSetLen(rightv[i], 3); - } - - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); - SNodeList* list = nodesMakeList(); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]); - nodesListAppend(list, pRight); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]); - nodesListAppend(list, pRight); - scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_BINARY); - scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); - } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; + bool eRes[5] = {true, true, false, false, false}; + SSDataBlock *src = NULL; + char leftv[5][5] = {0}; + char rightv[3][5] = {0}; + for (int32_t i = 0; i < 5; ++i) { + leftv[i][2] = 'a' + i; + leftv[i][3] = 'b' + i; + leftv[i][4] = '0' + i; + varDataSetLen(leftv[i], 3); + } + for (int32_t i = 0; i < 2; ++i) { + rightv[i][2] = 'a' + i; + rightv[i][3] = 'b' + i; + rightv[i][4] = '0' + i; + varDataSetLen(rightv[i], 3); + } + for (int32_t i = 2; i < 3; ++i) { + rightv[i][2] = 'a' + i; + rightv[i][3] = 'a' + i; + rightv[i][4] = 'a' + i; + varDataSetLen(rightv[i], 3); + } + + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); + SNodeList *list = nodesMakeList(); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]); + nodesListAppend(list, pRight); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]); + nodesListAppend(list, pRight); + scltMakeListNode(&listNode, list, TSDB_DATA_TYPE_BINARY); + scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); + } + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, binary_column_like_binary) { - SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; - char rightv[64] = {0}; - char leftv[5][5]= {0}; - SSDataBlock *src = NULL; - bool eRes[5] = {true, false, true, false, true}; - - for (int32_t i = 0; i < 5; ++i) { - leftv[i][2] = 'a'; - leftv[i][3] = 'a'; - leftv[i][4] = '0' + i % 2; - varDataSetLen(leftv[i], 3); - } - - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); - - sprintf(&rightv[2], "%s", "__0"); - varDataSetLen(rightv, strlen(&rightv[2])); - scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); - scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); - } - - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; + char rightv[64] = {0}; + char leftv[5][5] = {0}; + SSDataBlock *src = NULL; + bool eRes[5] = {true, false, true, false, true}; + + for (int32_t i = 0; i < 5; ++i) { + leftv[i][2] = 'a'; + leftv[i][3] = 'a'; + leftv[i][4] = '0' + i % 2; + varDataSetLen(leftv[i], 3); + } + + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); + + sprintf(&rightv[2], "%s", "__0"); + varDataSetLen(rightv, strlen(&rightv[2])); + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); + scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); + } + + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, binary_column_is_true) { - SNode *pLeft = NULL, *opNode = NULL; - char leftv[5][5]= {0}; - SSDataBlock *src = NULL; - bool eRes[5] = {false, true, false, true, false}; - - for (int32_t i = 0; i < 5; ++i) { - leftv[i][2] = '0' + i % 2; - leftv[i][3] = 'a'; - leftv[i][4] = '0' + i % 2; - varDataSetLen(leftv[i], 3); - } - - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, leftv); - - scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); - } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + SNode *pLeft = NULL, *opNode = NULL; + char leftv[5][5] = {0}; + SSDataBlock *src = NULL; + bool eRes[5] = {false, true, false, true, false}; + + for (int32_t i = 0; i < 5; ++i) { + leftv[i][2] = '0' + i % 2; + leftv[i][3] = 'a'; + leftv[i][4] = '0' + i % 2; + varDataSetLen(leftv[i], 3); + } + + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, leftv); + + scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); + } + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, binary_column_is_null) { - SNode *pLeft = NULL, *opNode = NULL; - char leftv[5][5]= {0}; - SSDataBlock *src = NULL; - bool eRes[5] = {false, false, true, false, true}; - - for (int32_t i = 0; i < 5; ++i) { - leftv[i][2] = '0' + i % 2; - leftv[i][3] = 'a'; - leftv[i][4] = '0' + i % 2; - varDataSetLen(leftv[i], 3); - } - - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); - - SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); - colDataAppend(pcolumn, 2, NULL, true); - colDataAppend(pcolumn, 4, NULL, true); - - scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); - } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + SNode *pLeft = NULL, *opNode = NULL; + char leftv[5][5] = {0}; + SSDataBlock *src = NULL; + bool eRes[5] = {false, false, true, false, true}; + + for (int32_t i = 0; i < 5; ++i) { + leftv[i][2] = '0' + i % 2; + leftv[i][3] = 'a'; + leftv[i][4] = '0' + i % 2; + varDataSetLen(leftv[i], 3); + } + + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); + + SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); + colDataAppend(pcolumn, 2, NULL, true); + colDataAppend(pcolumn, 4, NULL, true); + + scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); + } + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, binary_column_is_not_null) { - SNode *pLeft = NULL, *opNode = NULL; - char leftv[5][5]= {0}; - SSDataBlock *src = NULL; - bool eRes[5] = {true, true, true, true, false}; - - for (int32_t i = 0; i < 5; ++i) { - leftv[i][2] = '0' + i % 2; - leftv[i][3] = 'a'; - leftv[i][4] = '0' + i % 2; - varDataSetLen(leftv[i], 3); - } - - int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); - - SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); - colDataAppend(pcolumn, 4, NULL, true); - - scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); - scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); - } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + SNode *pLeft = NULL, *opNode = NULL; + char leftv[5][5] = {0}; + SSDataBlock *src = NULL; + bool eRes[5] = {true, true, true, true, false}; + + for (int32_t i = 0; i < 5; ++i) { + leftv[i][2] = '0' + i % 2; + leftv[i][3] = 'a'; + leftv[i][4] = '0' + i % 2; + varDataSetLen(leftv[i], 3); + } + + int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); + + SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); + colDataAppend(pcolumn, 4, NULL, true); + + scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); + scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); + } + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); } TEST(columnTest, greater_and_lower) { - SNode *pcol1 = NULL, *pcol2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; - SNode *list[2] = {0}; - int16_t v1[5]= {1, 2, 3, 4, 5}; - int32_t v2[5]= {5, 1, 4, 2, 6}; - int64_t v3[5]= {1, 2, 3, 4, 5}; - int32_t v4[5]= {5, 3, 4, 2, 6}; - bool eRes[5] = {false, true, false, false, false}; - SSDataBlock *src = NULL; - int32_t rowNum = sizeof(v1)/sizeof(v1[0]); - scltMakeColumnNode(&pcol1, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, v1); - scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, v2); - scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol1, pcol2); - scltMakeColumnNode(&pcol1, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, v3); - scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, v4); - scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol1, pcol2); - list[0] = opNode1; - list[1] = opNode2; - scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); - - SArray *blockList = taosArrayInit(1, POINTER_BYTES); - taosArrayPush(blockList, &src); - SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); - int16_t dataBlockId = 0, slotId = 0; - scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); - scltMakeTargetNode(&logicNode, dataBlockId, slotId, logicNode); - - int32_t code = scalarCalculate(logicNode, blockList, NULL); - ASSERT_EQ(code, 0); - - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); - ASSERT_EQ(res->info.rows, rowNum); - SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); - ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); - } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(logicNode); + SNode *pcol1 = NULL, *pcol2 = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode = NULL; + SNode *list[2] = {0}; + int16_t v1[5] = {1, 2, 3, 4, 5}; + int32_t v2[5] = {5, 1, 4, 2, 6}; + int64_t v3[5] = {1, 2, 3, 4, 5}; + int32_t v4[5] = {5, 3, 4, 2, 6}; + bool eRes[5] = {false, true, false, false, false}; + SSDataBlock *src = NULL; + int32_t rowNum = sizeof(v1) / sizeof(v1[0]); + scltMakeColumnNode(&pcol1, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, v1); + scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, v2); + scltMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol1, pcol2); + scltMakeColumnNode(&pcol1, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, v3); + scltMakeColumnNode(&pcol2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, v4); + scltMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol1, pcol2); + list[0] = opNode1; + list[1] = opNode2; + scltMakeLogicNode(&logicNode, LOGIC_COND_TYPE_AND, list, 2); + + SArray *blockList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_BOOL, sizeof(bool)); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); + scltMakeTargetNode(&logicNode, dataBlockId, slotId, logicNode); + + int32_t code = scalarCalculate(logicNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, rowNum); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + ASSERT_EQ(column->info.type, TSDB_DATA_TYPE_BOOL); + ASSERT_EQ(column->info.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((bool *)colDataGetData(column, i)), eRes[i]); + } + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(logicNode); } void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t num, bool setVal) { - SScalarParam *input = (SScalarParam *)taosMemoryCalloc(1, sizeof(SScalarParam)); - int32_t bytes; - switch (type) { - case TSDB_DATA_TYPE_TINYINT: { - bytes = sizeof(int8_t); - break; - } - case TSDB_DATA_TYPE_SMALLINT: { - bytes = sizeof(int16_t); - break; - } - case TSDB_DATA_TYPE_INT: { - bytes = sizeof(int32_t); - break; - } - case TSDB_DATA_TYPE_BIGINT: { - bytes = sizeof(int64_t); - break; - } - case TSDB_DATA_TYPE_FLOAT: { - bytes = sizeof(float); - break; - } - case TSDB_DATA_TYPE_DOUBLE: { - bytes = sizeof(double); - break; - } - } - - input->columnData = (SColumnInfoData*) taosMemoryCalloc(1, sizeof(SColumnInfoData)); - input->numOfRows = num; - - input->columnData->info = createColumnInfo(0, type, bytes); - colInfoDataEnsureCapacity(input->columnData, num); - - if (setVal) { - for (int32_t i = 0; i < num; ++i) { - colDataAppend(input->columnData, i, (const char*) pVal, false); - } - } else { - // memset(input->data, 0, num * bytes); - } - - *pInput = input; + SScalarParam *input = (SScalarParam *)taosMemoryCalloc(1, sizeof(SScalarParam)); + int32_t bytes; + switch (type) { + case TSDB_DATA_TYPE_TINYINT: { + bytes = sizeof(int8_t); + break; + } + case TSDB_DATA_TYPE_SMALLINT: { + bytes = sizeof(int16_t); + break; + } + case TSDB_DATA_TYPE_INT: { + bytes = sizeof(int32_t); + break; + } + case TSDB_DATA_TYPE_BIGINT: { + bytes = sizeof(int64_t); + break; + } + case TSDB_DATA_TYPE_FLOAT: { + bytes = sizeof(float); + break; + } + case TSDB_DATA_TYPE_DOUBLE: { + bytes = sizeof(double); + break; + } + } + + input->columnData = (SColumnInfoData *)taosMemoryCalloc(1, sizeof(SColumnInfoData)); + input->numOfRows = num; + + input->columnData->info = createColumnInfo(0, type, bytes); + colInfoDataEnsureCapacity(input->columnData, num); + + if (setVal) { + for (int32_t i = 0; i < num; ++i) { + colDataAppend(input->columnData, i, (const char *)pVal, false); + } + } else { + // memset(input->data, 0, num * bytes); + } + + *pInput = input; } void scltDestroyDataBlock(SScalarParam *pInput) { - colDataDestroy(pInput->columnData); - taosMemoryFree(pInput->columnData); - taosMemoryFree(pInput); + colDataDestroy(pInput->columnData); + taosMemoryFree(pInput->columnData); + taosMemoryFree(pInput); } TEST(ScalarFunctionTest, absFunction_constant) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - - //TINYINT - int8_t val_tinyint = 10; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - val_tinyint = -10; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -val_tinyint); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //SMALLINT - int16_t val_smallint = 10; - type = TSDB_DATA_TYPE_SMALLINT; - scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - val_smallint = -10; - scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -val_smallint); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //INT - int32_t val_int = 10; - type = TSDB_DATA_TYPE_INT; - scltMakeDataBlock(&pInput, type, &val_int, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - val_int = -10; - scltMakeDataBlock(&pInput, type, &val_int, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -val_int); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //BIGINT - int64_t val_bigint = 10; - type = TSDB_DATA_TYPE_BIGINT; - scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), val_bigint); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - val_bigint = -10; - scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), -val_bigint); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 10.15; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - PRINTF("float before ABS:%f\n", *(float *)pInput->data); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float); - PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - val_float = -10.15; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - PRINTF("float before ABS:%f\n", *(float *)pInput->data); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -val_float); - PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //DOUBLE - double val_double = 10.15; - type = TSDB_DATA_TYPE_DOUBLE; - scltMakeDataBlock(&pInput, type, &val_double, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - val_double = -10.15; - scltMakeDataBlock(&pInput, type, &val_double, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -val_double); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + + // TINYINT + int8_t val_tinyint = 10; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + val_tinyint = -10; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -val_tinyint); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // SMALLINT + int16_t val_smallint = 10; + type = TSDB_DATA_TYPE_SMALLINT; + scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + val_smallint = -10; + scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -val_smallint); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // INT + int32_t val_int = 10; + type = TSDB_DATA_TYPE_INT; + scltMakeDataBlock(&pInput, type, &val_int, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + val_int = -10; + scltMakeDataBlock(&pInput, type, &val_int, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -val_int); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // BIGINT + int64_t val_bigint = 10; + type = TSDB_DATA_TYPE_BIGINT; + scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), val_bigint); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + val_bigint = -10; + scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), -val_bigint); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 10.15; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + PRINTF("float before ABS:%f\n", *(float *)pInput->data); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float); + PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + val_float = -10.15; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + PRINTF("float before ABS:%f\n", *(float *)pInput->data); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -val_float); + PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // DOUBLE + double val_double = 10.15; + type = TSDB_DATA_TYPE_DOUBLE; + scltMakeDataBlock(&pInput, type, &val_double, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + val_double = -10.15; + scltMakeDataBlock(&pInput, type, &val_double, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -val_double); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, absFunction_column) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 5; - int32_t type; - - //TINYINT - int8_t val_tinyint = 10; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - int8_t v = val_tinyint + i; - colDataAppend(pInput->columnData, i, (const char*) &v, false); - PRINTF("tiny_int before ABS:%d\n", v); - } - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint + i); - PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - val_tinyint = -10; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - int8_t v = val_tinyint + i; - colDataAppend(pInput->columnData, i, (const char*) &v, false); - PRINTF("tiny_int before ABS:%d\n", v); - } - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -(val_tinyint + i)); - PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //SMALLINT - int16_t val_smallint = 10; - type = TSDB_DATA_TYPE_SMALLINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - int16_t v = val_smallint + i; - colDataAppend(pInput->columnData, i, (const char*) &v, false); - PRINTF("small_int before ABS:%d\n", v); - } - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint + i); - PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - val_smallint = -10; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - int16_t v = val_smallint + i; - colDataAppend(pInput->columnData, i, (const char*) &v, false); - PRINTF("small_int before ABS:%d\n", v); - } - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -(val_smallint + i)); - PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //INT - int32_t val_int = 10; - type = TSDB_DATA_TYPE_INT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - int32_t v = val_int + i; - colDataAppend(pInput->columnData, i, (const char*) &v, false); - PRINTF("int before ABS:%d\n", v); - } - - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int + i); - PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - val_int = -10; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - int32_t v = val_int + i; - colDataAppend(pInput->columnData, i, (const char*) &v, false); - PRINTF("int before ABS:%d\n", v); - } - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -(val_int + i)); - PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 10.15; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - float v = val_float + i; - colDataAppend(pInput->columnData, i, (const char*) &v, false); - PRINTF("float before ABS:%f\n", v); - } - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float + i); - PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - val_float = -10.15; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - float v = val_float + i; - colDataAppend(pInput->columnData, i, (const char*) &v, false); - PRINTF("float before ABS:%f\n", v); - } - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -(val_float + i)); - PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //DOUBLE - double val_double = 10.15; - type = TSDB_DATA_TYPE_DOUBLE; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - double v = val_double + i; - colDataAppend(pInput->columnData, i, (const char*) &v, false); - PRINTF("double before ABS:%f\n", v); - } - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double + i); - PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - val_double = -10.15; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - double v = val_double + i; - colDataAppend(pInput->columnData, i, (const char*) &v, false); - PRINTF("double before ABS:%f\n", v); - } - - code = absFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -(val_double + i)); - PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 5; + int32_t type; + + // TINYINT + int8_t val_tinyint = 10; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + int8_t v = val_tinyint + i; + colDataAppend(pInput->columnData, i, (const char *)&v, false); + PRINTF("tiny_int before ABS:%d\n", v); + } + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint + i); + PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + val_tinyint = -10; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + int8_t v = val_tinyint + i; + colDataAppend(pInput->columnData, i, (const char *)&v, false); + PRINTF("tiny_int before ABS:%d\n", v); + } + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -(val_tinyint + i)); + PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // SMALLINT + int16_t val_smallint = 10; + type = TSDB_DATA_TYPE_SMALLINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + int16_t v = val_smallint + i; + colDataAppend(pInput->columnData, i, (const char *)&v, false); + PRINTF("small_int before ABS:%d\n", v); + } + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint + i); + PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + val_smallint = -10; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + int16_t v = val_smallint + i; + colDataAppend(pInput->columnData, i, (const char *)&v, false); + PRINTF("small_int before ABS:%d\n", v); + } + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -(val_smallint + i)); + PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // INT + int32_t val_int = 10; + type = TSDB_DATA_TYPE_INT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + int32_t v = val_int + i; + colDataAppend(pInput->columnData, i, (const char *)&v, false); + PRINTF("int before ABS:%d\n", v); + } + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int + i); + PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + val_int = -10; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + int32_t v = val_int + i; + colDataAppend(pInput->columnData, i, (const char *)&v, false); + PRINTF("int before ABS:%d\n", v); + } + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -(val_int + i)); + PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 10.15; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + float v = val_float + i; + colDataAppend(pInput->columnData, i, (const char *)&v, false); + PRINTF("float before ABS:%f\n", v); + } + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float + i); + PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + val_float = -10.15; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + float v = val_float + i; + colDataAppend(pInput->columnData, i, (const char *)&v, false); + PRINTF("float before ABS:%f\n", v); + } + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -(val_float + i)); + PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // DOUBLE + double val_double = 10.15; + type = TSDB_DATA_TYPE_DOUBLE; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + double v = val_double + i; + colDataAppend(pInput->columnData, i, (const char *)&v, false); + PRINTF("double before ABS:%f\n", v); + } + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double + i); + PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + val_double = -10.15; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + double v = val_double + i; + colDataAppend(pInput->columnData, i, (const char *)&v, false); + PRINTF("double before ABS:%f\n", v); + } + + code = absFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -(val_double + i)); + PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, sinFunction_constant) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result = 0.42016703682664092; - - //TINYINT - int8_t val_tinyint = 13; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("tiny_int before SIN:%d\n", *((int8_t *)pInput->data)); - - code = sinFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 13.00; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("float before SIN:%f\n", *((float *)pInput->data)); - - code = sinFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result = 0.42016703682664092; + + // TINYINT + int8_t val_tinyint = 13; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("tiny_int before SIN:%d\n", *((int8_t *)pInput->data)); + + code = sinFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 13.00; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("float before SIN:%f\n", *((float *)pInput->data)); + + code = sinFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, sinFunction_column) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result[] = {0.42016703682664092, 0.99060735569487035, 0.65028784015711683}; - - - //TINYINT - int8_t val_tinyint[] = {13, 14, 15}; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); - PRINTF("tiny_int before SIN:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i)); - } - - code = sinFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {13.00, 14.00, 15.00}; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false); - PRINTF("float before SIN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); - } - - code = sinFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result[] = {0.42016703682664092, 0.99060735569487035, 0.65028784015711683}; + + // TINYINT + int8_t val_tinyint[] = {13, 14, 15}; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false); + PRINTF("tiny_int before SIN:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i)); + } + + code = sinFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {13.00, 14.00, 15.00}; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pInput->columnData, i, (const char *)&val_float[i], false); + PRINTF("float before SIN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); + } + + code = sinFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, cosFunction_constant) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result = 0.90744678145019619; - - //TINYINT - int8_t val_tinyint = 13; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("tiny_int before COS:%d\n", *((int8_t *)pInput->data)); - - code = cosFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 13.00; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("float before COS:%f\n", *((float *)pInput->data)); - - code = cosFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result = 0.90744678145019619; + + // TINYINT + int8_t val_tinyint = 13; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("tiny_int before COS:%d\n", *((int8_t *)pInput->data)); + + code = cosFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 13.00; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("float before COS:%f\n", *((float *)pInput->data)); + + code = cosFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, cosFunction_column) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result[] = {0.90744678145019619, 0.13673721820783361, -0.75968791285882131}; - - //TINYINT - int8_t val_tinyint[] = {13, 14, 15}; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); - PRINTF("tiny_int before COS:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i)); - } - - code = cosFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {13.00, 14.00, 15.00}; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false); - PRINTF("float before COS:%f\n", *(float *)colDataGetData(pInput->columnData, i)); - } - - code = cosFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result[] = {0.90744678145019619, 0.13673721820783361, -0.75968791285882131}; + + // TINYINT + int8_t val_tinyint[] = {13, 14, 15}; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false); + PRINTF("tiny_int before COS:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i)); + } + + code = cosFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {13.00, 14.00, 15.00}; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pInput->columnData, i, (const char *)&val_float[i], false); + PRINTF("float before COS:%f\n", *(float *)colDataGetData(pInput->columnData, i)); + } + + code = cosFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, tanFunction_constant) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result = 0.46302113293648961; - - //TINYINT - int8_t val_tinyint = 13; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("tiny_int before TAN:%d\n", *((int8_t *)pInput->data)); - - code = tanFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 13.00; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("float before TAN:%f\n", *((float *)pInput->data)); - - code = tanFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result = 0.46302113293648961; + + // TINYINT + int8_t val_tinyint = 13; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("tiny_int before TAN:%d\n", *((int8_t *)pInput->data)); + + code = tanFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 13.00; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("float before TAN:%f\n", *((float *)pInput->data)); + + code = tanFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, tanFunction_column) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result[] = {0.46302113293648961, 7.24460661609480550, -0.85599340090851872}; - - //TINYINT - int8_t val_tinyint[] = {13, 14, 15}; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); - PRINTF("tiny_int before TAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); - } - - code = tanFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_NEAR(*((double *)colDataGetData(pOutput->columnData, i)), result[i], 1e-15); - PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {13.00, 14.00, 15.00}; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false); - PRINTF("float before TAN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); - } - - code = tanFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_NEAR(*((double *)colDataGetData(pOutput->columnData, i)), result[i], 1e-15); - PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result[] = {0.46302113293648961, 7.24460661609480550, -0.85599340090851872}; + + // TINYINT + int8_t val_tinyint[] = {13, 14, 15}; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false); + PRINTF("tiny_int before TAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); + } + + code = tanFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_NEAR(*((double *)colDataGetData(pOutput->columnData, i)), result[i], 1e-15); + PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {13.00, 14.00, 15.00}; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pInput->columnData, i, (const char *)&val_float[i], false); + PRINTF("float before TAN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); + } + + code = tanFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_NEAR(*((double *)colDataGetData(pOutput->columnData, i)), result[i], 1e-15); + PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, asinFunction_constant) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result = 1.57079632679489656; - - //TINYINT - int8_t val_tinyint = 1; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)pInput->data)); - - code = asinFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 1.00; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("float before ASIN:%f\n", *((float *)pInput->data)); - - code = asinFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result = 1.57079632679489656; + + // TINYINT + int8_t val_tinyint = 1; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)pInput->data)); + + code = asinFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 1.00; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("float before ASIN:%f\n", *((float *)pInput->data)); + + code = asinFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, asinFunction_column) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result[] = {-1.57079632679489656, 0.0, 1.57079632679489656}; - - - //TINYINT - int8_t val_tinyint[] = {-1, 0, 1}; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false); - PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); - } - - code = asinFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {-1.0, 0.0, 1.0}; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; - PRINTF("float before ASIN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); - } - - code = asinFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result[] = {-1.57079632679489656, 0.0, 1.57079632679489656}; + + // TINYINT + int8_t val_tinyint[] = {-1, 0, 1}; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pInput->columnData, i, (const char *)&val_tinyint[i], false); + PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); + } + + code = asinFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {-1.0, 0.0, 1.0}; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before ASIN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); + } + + code = asinFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, acosFunction_constant) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result = 0.0; - - //TINYINT - int8_t val_tinyint = 1; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)pInput->data)); - - code = acosFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 1.00; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("float before ACOS:%f\n", *((float *)pInput->data)); - - code = acosFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result = 0.0; + + // TINYINT + int8_t val_tinyint = 1; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)pInput->data)); + + code = acosFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 1.00; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("float before ACOS:%f\n", *((float *)pInput->data)); + + code = acosFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, acosFunction_column) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result[] = {3.14159265358979312, 1.57079632679489656, 0.0}; - - //TINYINT - int8_t val_tinyint[] = {-1, 0, 1}; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; - PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); - } - - code = acosFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {-1.0, 0.0, 1.0}; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; - PRINTF("float before ACOS:%f\n", *((float *)colDataGetData(pInput->columnData, i))); - } - - code = acosFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result[] = {3.14159265358979312, 1.57079632679489656, 0.0}; + + // TINYINT + int8_t val_tinyint[] = {-1, 0, 1}; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); + } + + code = acosFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {-1.0, 0.0, 1.0}; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before ACOS:%f\n", *((float *)colDataGetData(pInput->columnData, i))); + } + + code = acosFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, atanFunction_constant) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result = 0.78539816339744828; - - //TINYINT - int8_t val_tinyint = 1; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)pInput->data)); - - code = atanFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 1.00; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("float before ATAN:%f\n", *((float *)pInput->data)); - - code = atanFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result = 0.78539816339744828; + + // TINYINT + int8_t val_tinyint = 1; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)pInput->data)); + + code = atanFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 1.00; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("float before ATAN:%f\n", *((float *)pInput->data)); + + code = atanFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, atanFunction_column) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result[] = {-0.78539816339744828, 0.0, 0.78539816339744828}; - - //TINYINT - int8_t val_tinyint[] = {-1, 0, 1}; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; - PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); - } - - code = atanFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {-1.0, 0.0, 1.0}; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; - PRINTF("float before ATAN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); - } - - code = atanFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result[] = {-0.78539816339744828, 0.0, 0.78539816339744828}; + + // TINYINT + int8_t val_tinyint[] = {-1, 0, 1}; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); + } + + code = atanFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {-1.0, 0.0, 1.0}; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before ATAN:%f\n", *((float *)colDataGetData(pInput->columnData, i))); + } + + code = atanFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, ceilFunction_constant) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - double result = 10.0; - - //TINYINT - int8_t val_tinyint = 10; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)pInput->data)); - - code = ceilFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result); - PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 9.5; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - PRINTF("float before CEIL:%f\n", *((float *)pInput->data)); - - code = ceilFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result); - PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + double result = 10.0; + + // TINYINT + int8_t val_tinyint = 10; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)pInput->data)); + + code = ceilFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result); + PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 9.5; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + PRINTF("float before CEIL:%f\n", *((float *)pInput->data)); + + code = ceilFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result); + PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, ceilFunction_column) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - double result[] = {-10.0, 0.0, 10.0}; - - //TINYINT - int8_t val_tinyint[] = {-10, 0, 10}; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; - PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); - } - - code = ceilFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {-10.5, 0.0, 9.5}; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; - PRINTF("float before CEIL:%f\n", *((float *)colDataGetData(pInput->columnData, i))); - } - - code = ceilFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + double result[] = {-10.0, 0.0, 10.0}; + + // TINYINT + int8_t val_tinyint[] = {-10, 0, 10}; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); + } + + code = ceilFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {-10.5, 0.0, 9.5}; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before CEIL:%f\n", *((float *)colDataGetData(pInput->columnData, i))); + } + + code = ceilFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, floorFunction_constant) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - double result = 10.0; - - //TINYINT - int8_t val_tinyint = 10; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)pInput->data)); - - code = floorFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result); - PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 10.5; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - PRINTF("float before FLOOR:%f\n", *((float *)pInput->data)); - - code = floorFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result); - PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + double result = 10.0; + + // TINYINT + int8_t val_tinyint = 10; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)pInput->data)); + + code = floorFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result); + PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 10.5; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + PRINTF("float before FLOOR:%f\n", *((float *)pInput->data)); + + code = floorFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result); + PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, floorFunction_column) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - double result[] = {-10.0, 0.0, 10.0}; - - //TINYINT - int8_t val_tinyint[] = {-10, 0, 10}; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; - PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); - } - - code = floorFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {-9.5, 0.0, 10.5}; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; - PRINTF("float before FLOOR:%f\n", *((float *)colDataGetData(pInput->columnData, i))); - } - - code = floorFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + double result[] = {-10.0, 0.0, 10.0}; + + // TINYINT + int8_t val_tinyint[] = {-10, 0, 10}; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); + } + + code = floorFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {-9.5, 0.0, 10.5}; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before FLOOR:%f\n", *((float *)colDataGetData(pInput->columnData, i))); + } + + code = floorFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, roundFunction_constant) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - double result = 10.0; - - //TINYINT - int8_t val_tinyint = 10; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)pInput->data)); - - code = roundFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result); - PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 9.5; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - PRINTF("float before ROUND:%f\n", *((float *)pInput->data)); - - code = roundFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result); - PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + double result = 10.0; + + // TINYINT + int8_t val_tinyint = 10; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)pInput->data)); + + code = roundFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result); + PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 9.5; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + PRINTF("float before ROUND:%f\n", *((float *)pInput->data)); + + code = roundFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result); + PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, roundFunction_column) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - double result[] = {-10.0, 0.0, 10.0}; - - //TINYINT - int8_t val_tinyint[] = {-10, 0, 10}; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; - PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); - } - - code = roundFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {-9.5, 0.0, 9.5}; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, type, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; - PRINTF("float before ROUND:%f\n", *((float *)colDataGetData(pInput->columnData, i))); - } - - code = roundFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + double result[] = {-10.0, 0.0, 10.0}; + + // TINYINT + int8_t val_tinyint[] = {-10, 0, 10}; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); + } + + code = roundFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {-9.5, 0.0, 9.5}; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, type, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before ROUND:%f\n", *((float *)colDataGetData(pInput->columnData, i))); + } + + code = roundFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, sqrtFunction_constant) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result = 5.0; - - //TINYINT - int8_t val_tinyint = 25; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)pInput->data)); - - code = sqrtFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float = 25.0; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("float before SQRT:%f\n", *((float *)pInput->data)); - - code = sqrtFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result = 5.0; + + // TINYINT + int8_t val_tinyint = 25; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)pInput->data)); + + code = sqrtFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float = 25.0; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, &val_float, rowNum, true); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("float before SQRT:%f\n", *((float *)pInput->data)); + + code = sqrtFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, sqrtFunction_column) { - SScalarParam *pInput, *pOutput; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result[] = {5.0, 9.0, 10.0}; - - //TINYINT - int8_t val_tinyint[] = {25, 81, 100}; - type = TSDB_DATA_TYPE_TINYINT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; - PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); - } - - code = sqrtFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {25.0, 81.0, 100.0}; - type = TSDB_DATA_TYPE_FLOAT; - scltMakeDataBlock(&pInput, type, 0, rowNum, false); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - for (int32_t i = 0; i < rowNum; ++i) { - *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; - PRINTF("float before SQRT:%f\n", *((float *)colDataGetData(pInput->columnData, i))); - } - - code = sqrtFunction(pInput, 1, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(pInput); - scltDestroyDataBlock(pOutput); + SScalarParam *pInput, *pOutput; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result[] = {5.0, 9.0, 10.0}; + + // TINYINT + int8_t val_tinyint[] = {25, 81, 100}; + type = TSDB_DATA_TYPE_TINYINT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i]; + PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i))); + } + + code = sqrtFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {25.0, 81.0, 100.0}; + type = TSDB_DATA_TYPE_FLOAT; + scltMakeDataBlock(&pInput, type, 0, rowNum, false); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + for (int32_t i = 0; i < rowNum; ++i) { + *((float *)colDataGetData(pInput->columnData, i)) = val_float[i]; + PRINTF("float before SQRT:%f\n", *((float *)colDataGetData(pInput->columnData, i))); + } + + code = sqrtFunction(pInput, 1, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(pInput); + scltDestroyDataBlock(pOutput); } TEST(ScalarFunctionTest, logFunction_constant) { - SScalarParam *pInput, *pOutput; - SScalarParam *input[2]; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result = 3.0; - pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); - - //TINYINT - int8_t val_tinyint[] = {27, 3}; - type = TSDB_DATA_TYPE_TINYINT; - for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true); - pInput[i] = *input[i]; - } - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("tiny_int before LOG: %d,%d\n", *((int8_t *)pInput[0].data), - *((int8_t *)pInput[1].data)); - - code = logFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {64.0, 4.0}; - type = TSDB_DATA_TYPE_FLOAT; - for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true); - pInput[i] = *input[i]; - } - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("float before LOG: %f,%f\n", *((float *)pInput[0].data), - *((float *)pInput[1].data)); - - code = logFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - - //TINYINT AND FLOAT - int8_t param0 = 64; - float param1 = 4.0; - scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, rowNum, true); - pInput[0] = *input[0]; - scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, rowNum, true); - pInput[1] = *input[1]; - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - - PRINTF("tiny_int,float before LOG: %d,%f\n", *((int8_t *)pInput[0].data), *((float *)pInput[1].data)); - - code = logFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - taosMemoryFree(pInput); + SScalarParam *pInput, *pOutput; + SScalarParam *input[2]; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result = 3.0; + pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); + + // TINYINT + int8_t val_tinyint[] = {27, 3}; + type = TSDB_DATA_TYPE_TINYINT; + for (int32_t i = 0; i < 2; ++i) { + scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true); + pInput[i] = *input[i]; + } + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("tiny_int before LOG: %d,%d\n", *((int8_t *)pInput[0].data), *((int8_t *)pInput[1].data)); + + code = logFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {64.0, 4.0}; + type = TSDB_DATA_TYPE_FLOAT; + for (int32_t i = 0; i < 2; ++i) { + scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true); + pInput[i] = *input[i]; + } + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("float before LOG: %f,%f\n", *((float *)pInput[0].data), *((float *)pInput[1].data)); + + code = logFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + + // TINYINT AND FLOAT + int8_t param0 = 64; + float param1 = 4.0; + scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, rowNum, true); + pInput[0] = *input[0]; + scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, rowNum, true); + pInput[1] = *input[1]; + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + + PRINTF("tiny_int,float before LOG: %d,%f\n", *((int8_t *)pInput[0].data), *((float *)pInput[1].data)); + + code = logFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + taosMemoryFree(pInput); } TEST(ScalarFunctionTest, logFunction_column) { - SScalarParam *pInput, *pOutput; - SScalarParam *input[2]; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result[] = {2.0, 3.0, 4.0}; - pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); - - //TINYINT - int8_t val_tinyint[2][3] = {{9, 27, 81}, {3, 3, 3}}; - type = TSDB_DATA_TYPE_TINYINT; - for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, 0, rowNum, false); - pInput[i] = *input[i]; - for (int32_t j = 0; j < rowNum; ++j) { - colDataAppend(pInput[i].columnData, j, (const char*) &val_tinyint[i][j], false); - - } - PRINTF("tiny_int before LOG:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), - *((int8_t *)pInput[i].data + 1), - *((int8_t *)pInput[i].data + 2)); - } - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - - code = logFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[2][3] = {{9.0, 27.0, 81.0}, {3.0, 3.0, 3.0}}; - type = TSDB_DATA_TYPE_FLOAT; - for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, 0, rowNum, false); - pInput[i] = *input[i]; - for (int32_t j = 0; j < rowNum; ++j) { - colDataAppend(pInput[i].columnData, j, (const char*) &val_float[i][j], false); - } - PRINTF("float before LOG:%f,%f,%f\n", *((float *)colDataGetData(pInput[i], 0)), - *((float *)colDataGetData(pInput[i], 1)), - *((float *)colDataGetData(pInput[i], 2))); - } - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - - code = logFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - - //TINYINT AND FLOAT - int8_t param0[] = {9, 27, 81}; - float param1[] = {3.0, 3.0, 3.0}; - scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false); - pInput[0] = *input[0]; - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pInput[0].columnData, i, (const char*) ¶m0[i], false); - - } - scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false); - pInput[1] = *input[1]; - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pInput[1].columnData, i, (const char*) ¶m1[i], false); - - } - PRINTF("tiny_int, float before LOG:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0), - *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1), - *((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2)); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - - code = logFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - taosMemoryFree(pInput); + SScalarParam *pInput, *pOutput; + SScalarParam *input[2]; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result[] = {2.0, 3.0, 4.0}; + pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); + + // TINYINT + int8_t val_tinyint[2][3] = {{9, 27, 81}, {3, 3, 3}}; + type = TSDB_DATA_TYPE_TINYINT; + for (int32_t i = 0; i < 2; ++i) { + scltMakeDataBlock(&input[i], type, 0, rowNum, false); + pInput[i] = *input[i]; + for (int32_t j = 0; j < rowNum; ++j) { + colDataAppend(pInput[i].columnData, j, (const char *)&val_tinyint[i][j], false); + } + PRINTF("tiny_int before LOG:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), *((int8_t *)pInput[i].data + 1), + *((int8_t *)pInput[i].data + 2)); + } + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + + code = logFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[2][3] = {{9.0, 27.0, 81.0}, {3.0, 3.0, 3.0}}; + type = TSDB_DATA_TYPE_FLOAT; + for (int32_t i = 0; i < 2; ++i) { + scltMakeDataBlock(&input[i], type, 0, rowNum, false); + pInput[i] = *input[i]; + for (int32_t j = 0; j < rowNum; ++j) { + colDataAppend(pInput[i].columnData, j, (const char *)&val_float[i][j], false); + } + PRINTF("float before LOG:%f,%f,%f\n", *((float *)colDataGetData(pInput[i], 0)), + *((float *)colDataGetData(pInput[i], 1)), *((float *)colDataGetData(pInput[i], 2))); + } + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + + code = logFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + + // TINYINT AND FLOAT + int8_t param0[] = {9, 27, 81}; + float param1[] = {3.0, 3.0, 3.0}; + scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false); + pInput[0] = *input[0]; + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pInput[0].columnData, i, (const char *)¶m0[i], false); + } + scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false); + pInput[1] = *input[1]; + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pInput[1].columnData, i, (const char *)¶m1[i], false); + } + PRINTF("tiny_int, float before LOG:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), + *((float *)pInput[1].data + 0), *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1), + *((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2)); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + + code = logFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + taosMemoryFree(pInput); } TEST(ScalarFunctionTest, powFunction_constant) { - SScalarParam *pInput, *pOutput; - SScalarParam *input[2]; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result = 16.0; - pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); - - //TINYINT - int8_t val_tinyint[] = {2, 4}; - type = TSDB_DATA_TYPE_TINYINT; - for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true); - pInput[i] = *input[i]; - } - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("tiny_int before POW: %d,%d\n", *((int8_t *)pInput[0].data), - *((int8_t *)pInput[1].data)); - - code = powFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[] = {2.0, 4.0}; - type = TSDB_DATA_TYPE_FLOAT; - for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true); - pInput[i] = *input[i]; - } - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - PRINTF("float before POW: %f,%f\n", *((float *)pInput[0].data), - *((float *)pInput[1].data)); - - code = powFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - - //TINYINT AND FLOAT - int8_t param0 = 2; - float param1 = 4.0; - scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, rowNum, true); - pInput[0] = *input[0]; - scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, rowNum, true); - pInput[1] = *input[1]; - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - - PRINTF("tiny_int,float before POW: %d,%f\n", *((int8_t *)pInput[0].data), *((float *)pInput[1].data)); - - code = powFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); - PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - taosMemoryFree(pInput); + SScalarParam *pInput, *pOutput; + SScalarParam *input[2]; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result = 16.0; + pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); + + // TINYINT + int8_t val_tinyint[] = {2, 4}; + type = TSDB_DATA_TYPE_TINYINT; + for (int32_t i = 0; i < 2; ++i) { + scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true); + pInput[i] = *input[i]; + } + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("tiny_int before POW: %d,%d\n", *((int8_t *)pInput[0].data), *((int8_t *)pInput[1].data)); + + code = powFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[] = {2.0, 4.0}; + type = TSDB_DATA_TYPE_FLOAT; + for (int32_t i = 0; i < 2; ++i) { + scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true); + pInput[i] = *input[i]; + } + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + PRINTF("float before POW: %f,%f\n", *((float *)pInput[0].data), *((float *)pInput[1].data)); + + code = powFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + + // TINYINT AND FLOAT + int8_t param0 = 2; + float param1 = 4.0; + scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, ¶m0, rowNum, true); + pInput[0] = *input[0]; + scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, ¶m1, rowNum, true); + pInput[1] = *input[1]; + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + + PRINTF("tiny_int,float before POW: %d,%f\n", *((int8_t *)pInput[0].data), *((float *)pInput[1].data)); + + code = powFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result); + PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + taosMemoryFree(pInput); } TEST(ScalarFunctionTest, powFunction_column) { - SScalarParam *pInput, *pOutput; - SScalarParam *input[2]; - int32_t code = TSDB_CODE_SUCCESS; - int32_t rowNum = 3; - int32_t type; - int32_t otype = TSDB_DATA_TYPE_DOUBLE; - double result[] = {8.0, 27.0, 64.0}; - pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); - - //TINYINT - int8_t val_tinyint[2][3] = {{2, 3, 4}, {3, 3, 3}}; - type = TSDB_DATA_TYPE_TINYINT; - for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, 0, rowNum, false); - pInput[i] = *input[i]; - for (int32_t j = 0; j < rowNum; ++j) { - colDataAppend(pInput[i].columnData, j, (const char*) &val_tinyint[i][j], false); - - } - PRINTF("tiny_int before POW:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), - *((int8_t *)pInput[i].data + 1), - *((int8_t *)pInput[i].data + 2)); - } - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - - code = powFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - - //FLOAT - float val_float[2][3] = {{2.0, 3.0, 4.0}, {3.0, 3.0, 3.0}}; - type = TSDB_DATA_TYPE_FLOAT; - for (int32_t i = 0; i < 2; ++i) { - scltMakeDataBlock(&input[i], type, 0, rowNum, false); - pInput[i] = *input[i]; - for (int32_t j = 0; j < rowNum; ++j) { - colDataAppend(pInput[i].columnData, j, (const char*) &val_float[i][j], false); - } - PRINTF("float before POW:%f,%f,%f\n", *((float *)pInput[i].data + 0), - *((float *)pInput[i].data + 1), - *((float *)pInput[i].data + 2)); - } - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - - code = powFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - - //TINYINT AND FLOAT - int8_t param0[] = {2, 3, 4}; - float param1[] = {3.0, 3.0, 3.0}; - scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false); - pInput[0] = *input[0]; - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pInput[0].columnData, i, (const char*) ¶m0[i], false); - - } - scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false); - pInput[1] = *input[1]; - for (int32_t i = 0; i < rowNum; ++i) { - colDataAppend(pInput[1].columnData, i, (const char*) ¶m1[i], false); - } - PRINTF("tiny_int, float before POW:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0), - *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1), - *((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2)); - scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); - - code = powFunction(pInput, 2, pOutput); - ASSERT_EQ(code, TSDB_CODE_SUCCESS); - for (int32_t i = 0; i < rowNum; ++i) { - ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); - PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); - } - - scltDestroyDataBlock(input[0]); - scltDestroyDataBlock(input[1]); - scltDestroyDataBlock(pOutput); - taosMemoryFree(pInput); -} - -int main(int argc, char** argv) { - taosSeedRand(taosGetTimestampSec()); - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + SScalarParam *pInput, *pOutput; + SScalarParam *input[2]; + int32_t code = TSDB_CODE_SUCCESS; + int32_t rowNum = 3; + int32_t type; + int32_t otype = TSDB_DATA_TYPE_DOUBLE; + double result[] = {8.0, 27.0, 64.0}; + pInput = (SScalarParam *)taosMemoryCalloc(2, sizeof(SScalarParam)); + + // TINYINT + int8_t val_tinyint[2][3] = {{2, 3, 4}, {3, 3, 3}}; + type = TSDB_DATA_TYPE_TINYINT; + for (int32_t i = 0; i < 2; ++i) { + scltMakeDataBlock(&input[i], type, 0, rowNum, false); + pInput[i] = *input[i]; + for (int32_t j = 0; j < rowNum; ++j) { + colDataAppend(pInput[i].columnData, j, (const char *)&val_tinyint[i][j], false); + } + PRINTF("tiny_int before POW:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), *((int8_t *)pInput[i].data + 1), + *((int8_t *)pInput[i].data + 2)); + } + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + + code = powFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + + // FLOAT + float val_float[2][3] = {{2.0, 3.0, 4.0}, {3.0, 3.0, 3.0}}; + type = TSDB_DATA_TYPE_FLOAT; + for (int32_t i = 0; i < 2; ++i) { + scltMakeDataBlock(&input[i], type, 0, rowNum, false); + pInput[i] = *input[i]; + for (int32_t j = 0; j < rowNum; ++j) { + colDataAppend(pInput[i].columnData, j, (const char *)&val_float[i][j], false); + } + PRINTF("float before POW:%f,%f,%f\n", *((float *)pInput[i].data + 0), *((float *)pInput[i].data + 1), + *((float *)pInput[i].data + 2)); + } + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + + code = powFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + + // TINYINT AND FLOAT + int8_t param0[] = {2, 3, 4}; + float param1[] = {3.0, 3.0, 3.0}; + scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false); + pInput[0] = *input[0]; + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pInput[0].columnData, i, (const char *)¶m0[i], false); + } + scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false); + pInput[1] = *input[1]; + for (int32_t i = 0; i < rowNum; ++i) { + colDataAppend(pInput[1].columnData, i, (const char *)¶m1[i], false); + } + PRINTF("tiny_int, float before POW:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), + *((float *)pInput[1].data + 0), *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1), + *((int8_t *)pInput[0].data + 2), *((float *)pInput[1].data + 2)); + scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); + + code = powFunction(pInput, 2, pOutput); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + for (int32_t i = 0; i < rowNum; ++i) { + ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]); + PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i))); + } + + scltDestroyDataBlock(input[0]); + scltDestroyDataBlock(input[1]); + scltDestroyDataBlock(pOutput); + taosMemoryFree(pInput); +} + +int main(int argc, char **argv) { + taosSeedRand(taosGetTimestampSec()); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } #pragma GCC diagnostic pop - diff --git a/source/libs/scheduler/inc/schInt.h b/source/libs/scheduler/inc/schInt.h index 7ced4f626c413d7f208d524e833c3b2626678751..1a88992840cd649d2538f66e19d86a96df34c594 100644 --- a/source/libs/scheduler/inc/schInt.h +++ b/source/libs/scheduler/inc/schInt.h @@ -20,13 +20,13 @@ extern "C" { #endif +#include "command.h" #include "os.h" -#include "tarray.h" #include "planner.h" #include "scheduler.h" +#include "tarray.h" #include "thash.h" #include "trpc.h" -#include "command.h" enum { SCH_READ = 1, @@ -51,20 +51,20 @@ typedef enum { SCH_ALL, } SCH_POLICY; -#define SCHEDULE_DEFAULT_MAX_JOB_NUM 1000 -#define SCHEDULE_DEFAULT_MAX_TASK_NUM 1000 +#define SCHEDULE_DEFAULT_MAX_JOB_NUM 1000 +#define SCHEDULE_DEFAULT_MAX_TASK_NUM 1000 #define SCHEDULE_DEFAULT_MAX_NODE_TABLE_NUM 200 // unit is TSDB_TABLE_NUM_UNIT -#define SCHEDULE_DEFAULT_POLICY SCH_LOAD_SEQ -#define SCHEDULE_DEFAULT_MAX_NODE_NUM 20 +#define SCHEDULE_DEFAULT_POLICY SCH_LOAD_SEQ +#define SCHEDULE_DEFAULT_MAX_NODE_NUM 20 #define SCH_DEFAULT_TASK_TIMEOUT_USEC 10000000 -#define SCH_MAX_TASK_TIMEOUT_USEC 60000000 -#define SCH_DEFAULT_MAX_RETRY_NUM 6 -#define SCH_MIN_AYSNC_EXEC_NUM 3 +#define SCH_MAX_TASK_TIMEOUT_USEC 60000000 +#define SCH_DEFAULT_MAX_RETRY_NUM 6 +#define SCH_MIN_AYSNC_EXEC_NUM 3 typedef struct SSchDebug { - bool lockEnable; - bool apiEnable; + bool lockEnable; + bool apiEnable; } SSchDebug; typedef struct SSchTrans { @@ -80,7 +80,6 @@ typedef struct SSchHbTrans { } SSchHbTrans; typedef struct SSchApiStat { - #if defined(WINDOWS) || defined(_TD_DARWIN_64) size_t avoidCompilationErrors; #endif @@ -88,7 +87,6 @@ typedef struct SSchApiStat { } SSchApiStat; typedef struct SSchRuntimeStat { - #if defined(WINDOWS) || defined(_TD_DARWIN_64) size_t avoidCompilationErrors; #endif @@ -96,7 +94,6 @@ typedef struct SSchRuntimeStat { } SSchRuntimeStat; typedef struct SSchJobStat { - #if defined(WINDOWS) || defined(_TD_DARWIN_64) size_t avoidCompilationErrors; #endif @@ -104,17 +101,17 @@ typedef struct SSchJobStat { } SSchJobStat; typedef struct SSchStat { - SSchApiStat api; - SSchRuntimeStat runtime; - SSchJobStat job; + SSchApiStat api; + SSchRuntimeStat runtime; + SSchJobStat job; } SSchStat; typedef struct SSchResInfo { - SExecResult* execRes; - void** fetchRes; - schedulerExecFp execFp; - schedulerFetchFp fetchFp; - void* cbParam; + SExecResult *execRes; + void **fetchRes; + schedulerExecFp execFp; + schedulerFetchFp fetchFp; + void *cbParam; } SSchResInfo; typedef struct SSchOpEvent { @@ -123,9 +120,9 @@ typedef struct SSchOpEvent { SSchedulerReq *pReq; } SSchOpEvent; -typedef int32_t (*schStatusEnterFp)(void* pHandle, void* pParam); -typedef int32_t (*schStatusLeaveFp)(void* pHandle, void* pParam); -typedef int32_t (*schStatusEventFp)(void* pHandle, void* pParam, void* pEvent); +typedef int32_t (*schStatusEnterFp)(void *pHandle, void *pParam); +typedef int32_t (*schStatusLeaveFp)(void *pHandle, void *pParam); +typedef int32_t (*schStatusEventFp)(void *pHandle, void *pParam, void *pEvent); typedef struct SSchStatusFps { EJobTaskType status; @@ -142,16 +139,16 @@ typedef struct SSchedulerCfg { } SSchedulerCfg; typedef struct SSchedulerMgmt { - uint64_t taskId; // sequential taksId - uint64_t sId; // schedulerId - SSchedulerCfg cfg; - bool exit; - int32_t jobRef; - int32_t jobNum; - SSchStat stat; - SRWLatch hbLock; - SHashObj *hbConnections; - void *queryMgmt; + uint64_t taskId; // sequential taksId + uint64_t sId; // schedulerId + SSchedulerCfg cfg; + bool exit; + int32_t jobRef; + int32_t jobNum; + SSchStat stat; + SRWLatch hbLock; + SHashObj *hbConnections; + void *queryMgmt; } SSchedulerMgmt; typedef struct SSchCallbackParamHeader { @@ -174,11 +171,11 @@ typedef struct SSchHbCallbackParam { } SSchHbCallbackParam; typedef struct SSchFlowControl { - SRWLatch lock; - bool sorted; - int32_t tableNumSum; - uint32_t execTaskNum; - SArray *taskList; // Element is SSchTask* + SRWLatch lock; + bool sorted; + int32_t tableNumSum; + uint32_t execTaskNum; + SArray *taskList; // Element is SSchTask* } SSchFlowControl; typedef struct SSchNodeInfo { @@ -187,50 +184,50 @@ typedef struct SSchNodeInfo { } SSchNodeInfo; typedef struct SSchLevel { - int32_t level; - int8_t status; - SRWLatch lock; - int32_t taskFailed; - int32_t taskSucceed; - int32_t taskNum; - int32_t taskLaunchedNum; - int32_t taskDoneNum; - SArray *subTasks; // Element is SSchTask + int32_t level; + int8_t status; + SRWLatch lock; + int32_t taskFailed; + int32_t taskSucceed; + int32_t taskNum; + int32_t taskLaunchedNum; + int32_t taskDoneNum; + SArray *subTasks; // Element is SSchTask } SSchLevel; typedef struct SSchTaskProfile { - int64_t startTs; - SArray* execTime; - int64_t waitTime; - int64_t endTs; + int64_t startTs; + SArray *execTime; + int64_t waitTime; + int64_t endTs; } SSchTaskProfile; typedef struct SSchTask { - uint64_t taskId; // task id - SRWLatch lock; // task reentrant lock - int32_t maxExecTimes; // task max exec times - int32_t maxRetryTimes; // task max retry times - int32_t retryTimes; // task retry times - bool waitRetry; // wait for retry - int32_t execId; // task current execute index - SSchLevel *level; // level - SRWLatch planLock; // task update plan lock - SSubplan *plan; // subplan - char *msg; // operator tree - int32_t msgLen; // msg length - int8_t status; // task status - int32_t lastMsgType; // last sent msg type - int64_t timeoutUsec; // task timeout useconds before reschedule - SQueryNodeAddr succeedAddr; // task executed success node address - int8_t candidateIdx; // current try condidation index - SArray *candidateAddrs; // condidate node addresses, element is SQueryNodeAddr - SHashObj *execNodes; // all tried node for current task, element is SSchNodeInfo - SSchTaskProfile profile; // task execution profile - int32_t childReady; // child task ready number - SArray *children; // the datasource tasks,from which to fetch the result, element is SQueryTask* - SArray *parents; // the data destination tasks, get data from current task, element is SQueryTask* - void* handle; // task send handle - bool registerdHb; // registered in hb + uint64_t taskId; // task id + SRWLatch lock; // task reentrant lock + int32_t maxExecTimes; // task max exec times + int32_t maxRetryTimes; // task max retry times + int32_t retryTimes; // task retry times + bool waitRetry; // wait for retry + int32_t execId; // task current execute index + SSchLevel *level; // level + SRWLatch planLock; // task update plan lock + SSubplan *plan; // subplan + char *msg; // operator tree + int32_t msgLen; // msg length + int8_t status; // task status + int32_t lastMsgType; // last sent msg type + int64_t timeoutUsec; // task timeout useconds before reschedule + SQueryNodeAddr succeedAddr; // task executed success node address + int8_t candidateIdx; // current try condidation index + SArray *candidateAddrs; // condidate node addresses, element is SQueryNodeAddr + SHashObj *execNodes; // all tried node for current task, element is SSchNodeInfo + SSchTaskProfile profile; // task execution profile + int32_t childReady; // child task ready number + SArray *children; // the datasource tasks,from which to fetch the result, element is SQueryTask* + SArray *parents; // the data destination tasks, get data from current task, element is SQueryTask* + void *handle; // task send handle + bool registerdHb; // registered in hb } SSchTask; typedef struct SSchJobAttr { @@ -243,46 +240,46 @@ typedef struct SSchJobAttr { } SSchJobAttr; typedef struct { - int32_t op; - SRWLatch lock; - bool syncReq; + int32_t op; + SRWLatch lock; + bool syncReq; } SSchOpStatus; typedef struct SSchJob { - int64_t refId; - uint64_t queryId; - SSchJobAttr attr; - int32_t levelNum; - int32_t taskNum; - SRequestConnInfo conn; - SArray *nodeList; // qnode/vnode list, SArray - SArray *levels; // starting from 0. SArray - SQueryPlan *pDag; - int64_t allocatorRefId; - - SArray *dataSrcTasks; // SArray - int32_t levelIdx; - SEpSet dataSrcEps; - SHashObj *taskList; - SHashObj *execTasks; // executing and executed tasks, key:taskid, value:SQueryTask* - SHashObj *flowCtrl; // key is ep, element is SSchFlowControl - - SExplainCtx *explainCtx; - int8_t status; - SQueryNodeAddr resNode; - tsem_t rspSem; - SSchOpStatus opStatus; - schedulerChkKillFp chkKillFp; - void* chkKillParam; - SSchTask *fetchTask; - int32_t errCode; - SRWLatch resLock; - SExecResult execRes; - void *fetchRes; //TODO free it or not - bool fetched; - int32_t resNumOfRows; - SSchResInfo userRes; - char *sql; + int64_t refId; + uint64_t queryId; + SSchJobAttr attr; + int32_t levelNum; + int32_t taskNum; + SRequestConnInfo conn; + SArray *nodeList; // qnode/vnode list, SArray + SArray *levels; // starting from 0. SArray + SQueryPlan *pDag; + int64_t allocatorRefId; + + SArray *dataSrcTasks; // SArray + int32_t levelIdx; + SEpSet dataSrcEps; + SHashObj *taskList; + SHashObj *execTasks; // executing and executed tasks, key:taskid, value:SQueryTask* + SHashObj *flowCtrl; // key is ep, element is SSchFlowControl + + SExplainCtx *explainCtx; + int8_t status; + SQueryNodeAddr resNode; + tsem_t rspSem; + SSchOpStatus opStatus; + schedulerChkKillFp chkKillFp; + void *chkKillParam; + SSchTask *fetchTask; + int32_t errCode; + SRWLatch resLock; + SExecResult execRes; + void *fetchRes; // TODO free it or not + bool fetched; + int32_t resNumOfRows; + SSchResInfo userRes; + char *sql; SQueryProfileSummary summary; } SSchJob; @@ -294,226 +291,282 @@ typedef struct SSchTaskCtx { extern SSchedulerMgmt schMgmt; -#define SCH_TASK_TIMEOUT(_task) ((taosGetTimestampUs() - *(int64_t*)taosArrayGet((_task)->profile.execTime, (_task)->execId)) > (_task)->timeoutUsec) +#define SCH_TASK_TIMEOUT(_task) \ + ((taosGetTimestampUs() - *(int64_t *)taosArrayGet((_task)->profile.execTime, (_task)->execId)) > (_task)->timeoutUsec) #define SCH_TASK_READY_FOR_LAUNCH(readyNum, task) ((readyNum) >= taosArrayGetSize((task)->children)) -#define SCH_LOCK_TASK(_task) SCH_LOCK(SCH_WRITE, &(_task)->lock) +#define SCH_LOCK_TASK(_task) SCH_LOCK(SCH_WRITE, &(_task)->lock) #define SCH_UNLOCK_TASK(_task) SCH_UNLOCK(SCH_WRITE, &(_task)->lock) -#define SCH_TASK_ID(_task) ((_task) ? (_task)->taskId : -1) +#define SCH_TASK_ID(_task) ((_task) ? (_task)->taskId : -1) #define SCH_TASK_EID(_task) ((_task) ? (_task)->execId : -1) #define SCH_IS_DATA_BIND_QRY_TASK(task) ((task)->plan->subplanType == SUBPLAN_TYPE_SCAN) -#define SCH_IS_DATA_BIND_TASK(task) (((task)->plan->subplanType == SUBPLAN_TYPE_SCAN) || ((task)->plan->subplanType == SUBPLAN_TYPE_MODIFY)) +#define SCH_IS_DATA_BIND_TASK(task) \ + (((task)->plan->subplanType == SUBPLAN_TYPE_SCAN) || ((task)->plan->subplanType == SUBPLAN_TYPE_MODIFY)) #define SCH_IS_LEAF_TASK(_job, _task) (((_task)->level->level + 1) == (_job)->levelNum) -#define SCH_IS_DATA_MERGE_TASK(task) (!SCH_IS_DATA_BIND_TASK(task)) -#define SCH_IS_LOCAL_EXEC_TASK(_job, _task) ((_job)->attr.localExec && SCH_IS_QUERY_JOB(_job) && (!SCH_IS_INSERT_JOB(_job)) && (!SCH_IS_DATA_BIND_QRY_TASK(_task))) +#define SCH_IS_DATA_MERGE_TASK(task) (!SCH_IS_DATA_BIND_TASK(task)) +#define SCH_IS_LOCAL_EXEC_TASK(_job, _task) \ + ((_job)->attr.localExec && SCH_IS_QUERY_JOB(_job) && (!SCH_IS_INSERT_JOB(_job)) && \ + (!SCH_IS_DATA_BIND_QRY_TASK(_task))) #define SCH_SET_TASK_STATUS(task, st) atomic_store_8(&(task)->status, st) -#define SCH_GET_TASK_STATUS(task) atomic_load_8(&(task)->status) +#define SCH_GET_TASK_STATUS(task) atomic_load_8(&(task)->status) #define SCH_GET_TASK_STATUS_STR(task) jobTaskStatusStr(SCH_GET_TASK_STATUS(task)) -#define SCH_GET_TASK_HANDLE(_task) ((_task) ? (_task)->handle : NULL) +#define SCH_GET_TASK_HANDLE(_task) ((_task) ? (_task)->handle : NULL) #define SCH_SET_TASK_HANDLE(_task, _handle) ((_task)->handle = (_handle)) #define SCH_SET_JOB_STATUS(job, st) atomic_store_8(&(job)->status, st) -#define SCH_GET_JOB_STATUS(job) atomic_load_8(&(job)->status) +#define SCH_GET_JOB_STATUS(job) atomic_load_8(&(job)->status) #define SCH_GET_JOB_STATUS_STR(job) jobTaskStatusStr(SCH_GET_JOB_STATUS(job)) #define SCH_JOB_IN_SYNC_OP(job) ((job)->opStatus.op && (job)->opStatus.syncReq) -#define SCH_JOB_IN_ASYNC_EXEC_OP(job) ((SCH_OP_EXEC == atomic_val_compare_exchange_32(&(job)->opStatus.op, SCH_OP_EXEC, SCH_OP_NULL)) && (!(job)->opStatus.syncReq)) -#define SCH_JOB_IN_ASYNC_FETCH_OP(job) ((SCH_OP_FETCH == atomic_val_compare_exchange_32(&(job)->opStatus.op, SCH_OP_FETCH, SCH_OP_NULL)) && (!(job)->opStatus.syncReq)) +#define SCH_JOB_IN_ASYNC_EXEC_OP(job) \ + ((SCH_OP_EXEC == atomic_val_compare_exchange_32(&(job)->opStatus.op, SCH_OP_EXEC, SCH_OP_NULL)) && \ + (!(job)->opStatus.syncReq)) +#define SCH_JOB_IN_ASYNC_FETCH_OP(job) \ + ((SCH_OP_FETCH == atomic_val_compare_exchange_32(&(job)->opStatus.op, SCH_OP_FETCH, SCH_OP_NULL)) && \ + (!(job)->opStatus.syncReq)) #define SCH_SET_JOB_NEED_FLOW_CTRL(_job) (_job)->attr.needFlowCtrl = true -#define SCH_JOB_NEED_FLOW_CTRL(_job) ((_job)->attr.needFlowCtrl) -#define SCH_TASK_NEED_FLOW_CTRL(_job, _task) (SCH_IS_DATA_BIND_QRY_TASK(_task) && SCH_JOB_NEED_FLOW_CTRL(_job) && SCH_IS_LEVEL_UNFINISHED((_task)->level)) -#define SCH_FETCH_TYPE(_pSrcTask) (SCH_IS_DATA_BIND_QRY_TASK(_pSrcTask) ? TDMT_SCH_FETCH : TDMT_SCH_MERGE_FETCH) +#define SCH_JOB_NEED_FLOW_CTRL(_job) ((_job)->attr.needFlowCtrl) +#define SCH_TASK_NEED_FLOW_CTRL(_job, _task) \ + (SCH_IS_DATA_BIND_QRY_TASK(_task) && SCH_JOB_NEED_FLOW_CTRL(_job) && SCH_IS_LEVEL_UNFINISHED((_task)->level)) +#define SCH_FETCH_TYPE(_pSrcTask) (SCH_IS_DATA_BIND_QRY_TASK(_pSrcTask) ? TDMT_SCH_FETCH : TDMT_SCH_MERGE_FETCH) #define SCH_TASK_NEED_FETCH(_task) ((_task)->plan->subplanType != SUBPLAN_TYPE_MODIFY) -#define SCH_SET_JOB_TYPE(_job, type) do { if ((type) != SUBPLAN_TYPE_MODIFY) { (_job)->attr.queryJob = true; } else { (_job)->attr.insertJob = true; } } while (0) -#define SCH_IS_QUERY_JOB(_job) ((_job)->attr.queryJob) -#define SCH_IS_INSERT_JOB(_job) ((_job)->attr.insertJob) +#define SCH_SET_JOB_TYPE(_job, type) \ + do { \ + if ((type) != SUBPLAN_TYPE_MODIFY) { \ + (_job)->attr.queryJob = true; \ + } else { \ + (_job)->attr.insertJob = true; \ + } \ + } while (0) +#define SCH_IS_QUERY_JOB(_job) ((_job)->attr.queryJob) +#define SCH_IS_INSERT_JOB(_job) ((_job)->attr.insertJob) #define SCH_JOB_NEED_FETCH(_job) ((_job)->attr.needFetch) -#define SCH_JOB_NEED_WAIT(_job) (!SCH_IS_QUERY_JOB(_job)) -#define SCH_JOB_NEED_DROP(_job) (SCH_IS_QUERY_JOB(_job)) +#define SCH_JOB_NEED_WAIT(_job) (!SCH_IS_QUERY_JOB(_job)) +#define SCH_JOB_NEED_DROP(_job) (SCH_IS_QUERY_JOB(_job)) #define SCH_IS_EXPLAIN_JOB(_job) (EXPLAIN_MODE_ANALYZE == (_job)->attr.explainMode) -#define SCH_NETWORK_ERR(_code) ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL) -#define SCH_MERGE_TASK_NETWORK_ERR(_task, _code, _len) (SCH_NETWORK_ERR(_code) && (((_len) > 0) || (!SCH_IS_DATA_BIND_TASK(_task)))) -#define SCH_REDIRECT_MSGTYPE(_msgType) ((_msgType) == TDMT_SCH_LINK_BROKEN || (_msgType) == TDMT_SCH_QUERY || (_msgType) == TDMT_SCH_MERGE_QUERY || (_msgType) == TDMT_SCH_FETCH || (_msgType) == TDMT_SCH_MERGE_FETCH) -#define SCH_TASK_NEED_REDIRECT(_task, _msgType, _code, _rspLen) (SCH_REDIRECT_MSGTYPE(_msgType) && (NEED_SCHEDULER_REDIRECT_ERROR(_code) || SCH_MERGE_TASK_NETWORK_ERR((_task), (_code), (_rspLen)))) -#define SCH_NEED_RETRY(_msgType, _code) ((SCH_NETWORK_ERR(_code) && SCH_REDIRECT_MSGTYPE(_msgType)) || (_code) == TSDB_CODE_SCH_TIMEOUT_ERROR) +#define SCH_NETWORK_ERR(_code) ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL) +#define SCH_MERGE_TASK_NETWORK_ERR(_task, _code, _len) \ + (SCH_NETWORK_ERR(_code) && (((_len) > 0) || (!SCH_IS_DATA_BIND_TASK(_task)))) +#define SCH_REDIRECT_MSGTYPE(_msgType) \ + ((_msgType) == TDMT_SCH_LINK_BROKEN || (_msgType) == TDMT_SCH_QUERY || (_msgType) == TDMT_SCH_MERGE_QUERY || \ + (_msgType) == TDMT_SCH_FETCH || (_msgType) == TDMT_SCH_MERGE_FETCH) +#define SCH_TASK_NEED_REDIRECT(_task, _msgType, _code, _rspLen) \ + (SCH_REDIRECT_MSGTYPE(_msgType) && \ + (NEED_SCHEDULER_REDIRECT_ERROR(_code) || SCH_MERGE_TASK_NETWORK_ERR((_task), (_code), (_rspLen)))) +#define SCH_NEED_RETRY(_msgType, _code) \ + ((SCH_NETWORK_ERR(_code) && SCH_REDIRECT_MSGTYPE(_msgType)) || (_code) == TSDB_CODE_SCH_TIMEOUT_ERROR) #define SCH_IS_LEVEL_UNFINISHED(_level) ((_level)->taskLaunchedNum < (_level)->taskNum) -#define SCH_GET_CUR_EP(_addr) (&(_addr)->epSet.eps[(_addr)->epSet.inUse]) -#define SCH_SWITCH_EPSET(_addr) ((_addr)->epSet.inUse = ((_addr)->epSet.inUse + 1) % (_addr)->epSet.numOfEps) -#define SCH_TASK_NUM_OF_EPS(_addr) ((_addr)->epSet.numOfEps) - -#define SCH_LOG_TASK_START_TS(_task) \ - do { \ - int64_t us = taosGetTimestampUs(); \ - taosArrayPush((_task)->profile.execTime, &us); \ - if (0 == (_task)->execId) { \ - (_task)->profile.startTs = us; \ - } \ - } while (0) - -#define SCH_LOG_TASK_WAIT_TS(_task) \ - do { \ - int64_t us = taosGetTimestampUs(); \ - (_task)->profile.waitTime += us - *(int64_t*)taosArrayGet((_task)->profile.execTime, (_task)->execId); \ - } while (0) - - -#define SCH_LOG_TASK_END_TS(_task) \ - do { \ - int64_t us = taosGetTimestampUs(); \ - int32_t idx = (_task)->execId % (_task)->maxExecTimes; \ +#define SCH_GET_CUR_EP(_addr) (&(_addr)->epSet.eps[(_addr)->epSet.inUse]) +#define SCH_SWITCH_EPSET(_addr) ((_addr)->epSet.inUse = ((_addr)->epSet.inUse + 1) % (_addr)->epSet.numOfEps) +#define SCH_TASK_NUM_OF_EPS(_addr) ((_addr)->epSet.numOfEps) + +#define SCH_LOG_TASK_START_TS(_task) \ + do { \ + int64_t us = taosGetTimestampUs(); \ + taosArrayPush((_task)->profile.execTime, &us); \ + if (0 == (_task)->execId) { \ + (_task)->profile.startTs = us; \ + } \ + } while (0) + +#define SCH_LOG_TASK_WAIT_TS(_task) \ + do { \ + int64_t us = taosGetTimestampUs(); \ + (_task)->profile.waitTime += us - *(int64_t *)taosArrayGet((_task)->profile.execTime, (_task)->execId); \ + } while (0) + +#define SCH_LOG_TASK_END_TS(_task) \ + do { \ + int64_t us = taosGetTimestampUs(); \ + int32_t idx = (_task)->execId % (_task)->maxExecTimes; \ int64_t *startts = taosArrayGet((_task)->profile.execTime, (_task)->execId); \ - *startts = us - *startts; \ - (_task)->profile.endTs = us; \ - } while (0) - + *startts = us - *startts; \ + (_task)->profile.endTs = us; \ + } while (0) #define SCH_JOB_ELOG(param, ...) qError("QID:0x%" PRIx64 " " param, pJob->queryId, __VA_ARGS__) #define SCH_JOB_DLOG(param, ...) qDebug("QID:0x%" PRIx64 " " param, pJob->queryId, __VA_ARGS__) -#define SCH_TASK_ELOG(param, ...) \ - qError("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask),__VA_ARGS__) -#define SCH_TASK_DLOG(param, ...) \ - qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask),__VA_ARGS__) -#define SCH_TASK_TLOG(param, ...) \ - qTrace("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask),__VA_ARGS__) -#define SCH_TASK_DLOGL(param, ...) \ - qDebugL("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask),__VA_ARGS__) -#define SCH_TASK_WLOG(param, ...) \ - qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask),__VA_ARGS__) - -#define SCH_SET_ERRNO(_err) do { if (TSDB_CODE_SCH_IGNORE_ERROR != (_err)) { terrno = (_err); } } while (0) -#define SCH_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(_code); return _code; } } while (0) -#define SCH_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(_code); } return _code; } while (0) -#define SCH_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(code); goto _return; } } while (0) - -#define SCH_LOCK_DEBUG(...) do { if (gSCHDebug.lockEnable) { qDebug(__VA_ARGS__); } } while (0) +#define SCH_TASK_ELOG(param, ...) \ + qError("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), \ + __VA_ARGS__) +#define SCH_TASK_DLOG(param, ...) \ + qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), \ + __VA_ARGS__) +#define SCH_TASK_TLOG(param, ...) \ + qTrace("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), \ + __VA_ARGS__) +#define SCH_TASK_DLOGL(param, ...) \ + qDebugL("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), \ + __VA_ARGS__) +#define SCH_TASK_WLOG(param, ...) \ + qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), \ + __VA_ARGS__) + +#define SCH_SET_ERRNO(_err) \ + do { \ + if (TSDB_CODE_SCH_IGNORE_ERROR != (_err)) { \ + terrno = (_err); \ + } \ + } while (0) +#define SCH_ERR_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + SCH_SET_ERRNO(_code); \ + return _code; \ + } \ + } while (0) +#define SCH_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + SCH_SET_ERRNO(_code); \ + } \ + return _code; \ + } while (0) +#define SCH_ERR_JRET(c) \ + do { \ + code = c; \ + if (code != TSDB_CODE_SUCCESS) { \ + SCH_SET_ERRNO(code); \ + goto _return; \ + } \ + } while (0) + +#define SCH_LOCK_DEBUG(...) \ + do { \ + if (gSCHDebug.lockEnable) { \ + qDebug(__VA_ARGS__); \ + } \ + } while (0) #define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000 -#define SCH_LOCK(type, _lock) do { \ - if (SCH_READ == (type)) { \ - assert(atomic_load_32(_lock) >= 0); \ - SCH_LOCK_DEBUG("SCH RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - taosRLockLatch(_lock); \ - SCH_LOCK_DEBUG("SCH RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32(_lock) > 0); \ - } else { \ - assert(atomic_load_32(_lock) >= 0); \ - SCH_LOCK_DEBUG("SCH WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - taosWLockLatch(_lock); \ - SCH_LOCK_DEBUG("SCH WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32(_lock) == TD_RWLATCH_WRITE_FLAG_COPY); \ - } \ -} while (0) - -#define SCH_UNLOCK(type, _lock) do { \ - if (SCH_READ == (type)) { \ - assert(atomic_load_32((_lock)) > 0); \ - SCH_LOCK_DEBUG("SCH RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - taosRUnLockLatch(_lock); \ - SCH_LOCK_DEBUG("SCH RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) >= 0); \ - } else { \ - assert(atomic_load_32((_lock)) & TD_RWLATCH_WRITE_FLAG_COPY); \ - SCH_LOCK_DEBUG("SCH WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - taosWUnLockLatch(_lock); \ - SCH_LOCK_DEBUG("SCH WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ - assert(atomic_load_32((_lock)) >= 0); \ - } \ -} while (0) - - -void schDeregisterTaskHb(SSchJob *pJob, SSchTask *pTask); -void schCleanClusterHb(void* pTrans); -int32_t schLaunchTask(SSchJob *job, SSchTask *task); -int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, SQueryNodeAddr *addr, int32_t msgType); +#define SCH_LOCK(type, _lock) \ + do { \ + if (SCH_READ == (type)) { \ + assert(atomic_load_32(_lock) >= 0); \ + SCH_LOCK_DEBUG("SCH RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosRLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32(_lock) > 0); \ + } else { \ + assert(atomic_load_32(_lock) >= 0); \ + SCH_LOCK_DEBUG("SCH WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosWLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32(_lock) == TD_RWLATCH_WRITE_FLAG_COPY); \ + } \ + } while (0) + +#define SCH_UNLOCK(type, _lock) \ + do { \ + if (SCH_READ == (type)) { \ + assert(atomic_load_32((_lock)) > 0); \ + SCH_LOCK_DEBUG("SCH RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosRUnLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) >= 0); \ + } else { \ + assert(atomic_load_32((_lock)) & TD_RWLATCH_WRITE_FLAG_COPY); \ + SCH_LOCK_DEBUG("SCH WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosWUnLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) >= 0); \ + } \ + } while (0) + +void schDeregisterTaskHb(SSchJob *pJob, SSchTask *pTask); +void schCleanClusterHb(void *pTrans); +int32_t schLaunchTask(SSchJob *job, SSchTask *task); +int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, SQueryNodeAddr *addr, int32_t msgType); SSchJob *schAcquireJob(int64_t refId); -int32_t schReleaseJob(int64_t refId); -void schFreeFlowCtrl(SSchJob *pJob); -int32_t schChkJobNeedFlowCtrl(SSchJob *pJob, SSchLevel *pLevel); -int32_t schDecTaskFlowQuota(SSchJob *pJob, SSchTask *pTask); -int32_t schCheckIncTaskFlowQuota(SSchJob *pJob, SSchTask *pTask, bool *enough); -int32_t schLaunchTasksInFlowCtrlList(SSchJob *pJob, SSchTask *pTask); -int32_t schAsyncLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask); -int32_t schLaunchFetchTask(SSchJob *pJob); -int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode); -int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId, SArray* taskAction); -int32_t schCloneSMsgSendInfo(void *src, void **dst); -int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob); -void schFreeJobImpl(void *job); -int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx); -int32_t schEnsureHbConnection(SSchJob *pJob, SSchTask *pTask); -int32_t schUpdateHbConnection(SQueryNodeEpId *epId, SSchTrans *trans); -int32_t schHandleHbCallback(void *param, SDataBuf *pMsg, int32_t code); -void schFreeRpcCtx(SRpcCtx *pCtx); -int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp); -bool schJobNeedToStop(SSchJob *pJob, int8_t *pStatus); -int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask); -int32_t schSaveJobExecRes(SSchJob *pJob, SQueryTableRsp *rsp); -int32_t schProcessOnExplainDone(SSchJob *pJob, SSchTask *pTask, SRetrieveTableRsp *pRsp); -void schProcessOnDataFetched(SSchJob *job); -int32_t schGetTaskInJob(SSchJob *pJob, uint64_t taskId, SSchTask **pTask); -void schFreeRpcCtxVal(const void *arg); -int32_t schMakeBrokenLinkVal(SSchJob *pJob, SSchTask *pTask, SRpcBrokenlinkVal *brokenVal, bool isHb); -int32_t schAppendTaskExecNode(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, int32_t execId); -int32_t schExecStaticExplainJob(SSchedulerReq *pReq, int64_t *job, bool sync); -int32_t schUpdateJobStatus(SSchJob *pJob, int8_t newStatus); -int32_t schCancelJob(SSchJob *pJob); -int32_t schProcessOnJobDropped(SSchJob *pJob, int32_t errCode); +int32_t schReleaseJob(int64_t refId); +void schFreeFlowCtrl(SSchJob *pJob); +int32_t schChkJobNeedFlowCtrl(SSchJob *pJob, SSchLevel *pLevel); +int32_t schDecTaskFlowQuota(SSchJob *pJob, SSchTask *pTask); +int32_t schCheckIncTaskFlowQuota(SSchJob *pJob, SSchTask *pTask, bool *enough); +int32_t schLaunchTasksInFlowCtrlList(SSchJob *pJob, SSchTask *pTask); +int32_t schAsyncLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask); +int32_t schLaunchFetchTask(SSchJob *pJob); +int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode); +int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId, SArray *taskAction); +int32_t schCloneSMsgSendInfo(void *src, void **dst); +int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob); +void schFreeJobImpl(void *job); +int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx); +int32_t schEnsureHbConnection(SSchJob *pJob, SSchTask *pTask); +int32_t schUpdateHbConnection(SQueryNodeEpId *epId, SSchTrans *trans); +int32_t schHandleHbCallback(void *param, SDataBuf *pMsg, int32_t code); +void schFreeRpcCtx(SRpcCtx *pCtx); +int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp); +bool schJobNeedToStop(SSchJob *pJob, int8_t *pStatus); +int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask); +int32_t schSaveJobExecRes(SSchJob *pJob, SQueryTableRsp *rsp); +int32_t schProcessOnExplainDone(SSchJob *pJob, SSchTask *pTask, SRetrieveTableRsp *pRsp); +void schProcessOnDataFetched(SSchJob *job); +int32_t schGetTaskInJob(SSchJob *pJob, uint64_t taskId, SSchTask **pTask); +void schFreeRpcCtxVal(const void *arg); +int32_t schMakeBrokenLinkVal(SSchJob *pJob, SSchTask *pTask, SRpcBrokenlinkVal *brokenVal, bool isHb); +int32_t schAppendTaskExecNode(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, int32_t execId); +int32_t schExecStaticExplainJob(SSchedulerReq *pReq, int64_t *job, bool sync); +int32_t schUpdateJobStatus(SSchJob *pJob, int8_t newStatus); +int32_t schCancelJob(SSchJob *pJob); +int32_t schProcessOnJobDropped(SSchJob *pJob, int32_t errCode); uint64_t schGenTaskId(void); -void schCloseJobRef(void); -int32_t schAsyncExecJob(SSchedulerReq *pReq, int64_t *pJob); -int32_t schJobFetchRows(SSchJob *pJob); -int32_t schJobFetchRowsA(SSchJob *pJob); -int32_t schUpdateTaskHandle(SSchJob *pJob, SSchTask *pTask, bool dropExecNode, void *handle, int32_t execId); -int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId* pEpId, SArray* pStatusList); -char* schGetOpStr(SCH_OP_TYPE type); -int32_t schBeginOperation(SSchJob *pJob, SCH_OP_TYPE type, bool sync); -int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq); -int32_t schExecJob(SSchJob *pJob, SSchedulerReq *pReq); -int32_t schDumpJobExecRes(SSchJob* pJob, SExecResult* pRes); -int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet* pEpSet); -int32_t schHandleRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32_t rspCode); -void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode); -int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq); -void schProcessOnCbEnd(SSchJob *pJob, SSchTask *pTask, int32_t errCode); -int32_t schProcessOnCbBegin(SSchJob** job, SSchTask** task, uint64_t qId, int64_t rId, uint64_t tId); -void schDropTaskOnExecNode(SSchJob *pJob, SSchTask *pTask); -bool schJobDone(SSchJob *pJob); -int32_t schRemoveTaskFromExecList(SSchJob *pJob, SSchTask *pTask); -int32_t schLaunchJobLowerLevel(SSchJob *pJob, SSchTask *pTask); -int32_t schSwitchJobStatus(SSchJob* pJob, int32_t status, void* param); -int32_t schHandleOpBeginEvent(int64_t jobId, SSchJob** job, SCH_OP_TYPE type, SSchedulerReq* pReq); -int32_t schHandleOpEndEvent(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode); -int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask); -void schUpdateJobErrCode(SSchJob *pJob, int32_t errCode); -int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bool *needRetry); -int32_t schProcessOnJobFailure(SSchJob *pJob, int32_t errCode); -int32_t schProcessOnJobPartialSuccess(SSchJob *pJob); -void schFreeTask(SSchJob *pJob, SSchTask *pTask); -void schDropTaskInHashList(SSchJob *pJob, SHashObj *list); -int32_t schLaunchLevelTasks(SSchJob *pJob, SSchLevel *level); -int32_t schGetTaskFromList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTask); -int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel); -int32_t schSwitchTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask); -void schDirectPostJobRes(SSchedulerReq* pReq, int32_t errCode); -int32_t schHandleJobFailure(SSchJob *pJob, int32_t errCode); -int32_t schHandleJobDrop(SSchJob *pJob, int32_t errCode); -bool schChkCurrentOp(SSchJob *pJob, int32_t op, int8_t sync); -int32_t schProcessFetchRsp(SSchJob *pJob, SSchTask *pTask, char *msg, int32_t rspCode); -int32_t schProcessExplainRsp(SSchJob *pJob, SSchTask *pTask, SExplainRsp *rsp); +void schCloseJobRef(void); +int32_t schAsyncExecJob(SSchedulerReq *pReq, int64_t *pJob); +int32_t schJobFetchRows(SSchJob *pJob); +int32_t schJobFetchRowsA(SSchJob *pJob); +int32_t schUpdateTaskHandle(SSchJob *pJob, SSchTask *pTask, bool dropExecNode, void *handle, int32_t execId); +int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId *pEpId, SArray *pStatusList); +char *schGetOpStr(SCH_OP_TYPE type); +int32_t schBeginOperation(SSchJob *pJob, SCH_OP_TYPE type, bool sync); +int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq); +int32_t schExecJob(SSchJob *pJob, SSchedulerReq *pReq); +int32_t schDumpJobExecRes(SSchJob *pJob, SExecResult *pRes); +int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet *pEpSet); +int32_t schHandleRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf *pData, int32_t rspCode); +void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq *pReq, int32_t errCode); +int32_t schProcessOnOpBegin(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq *pReq); +void schProcessOnCbEnd(SSchJob *pJob, SSchTask *pTask, int32_t errCode); +int32_t schProcessOnCbBegin(SSchJob **job, SSchTask **task, uint64_t qId, int64_t rId, uint64_t tId); +void schDropTaskOnExecNode(SSchJob *pJob, SSchTask *pTask); +bool schJobDone(SSchJob *pJob); +int32_t schRemoveTaskFromExecList(SSchJob *pJob, SSchTask *pTask); +int32_t schLaunchJobLowerLevel(SSchJob *pJob, SSchTask *pTask); +int32_t schSwitchJobStatus(SSchJob *pJob, int32_t status, void *param); +int32_t schHandleOpBeginEvent(int64_t jobId, SSchJob **job, SCH_OP_TYPE type, SSchedulerReq *pReq); +int32_t schHandleOpEndEvent(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq *pReq, int32_t errCode); +int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask); +void schUpdateJobErrCode(SSchJob *pJob, int32_t errCode); +int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bool *needRetry); +int32_t schProcessOnJobFailure(SSchJob *pJob, int32_t errCode); +int32_t schProcessOnJobPartialSuccess(SSchJob *pJob); +void schFreeTask(SSchJob *pJob, SSchTask *pTask); +void schDropTaskInHashList(SSchJob *pJob, SHashObj *list); +int32_t schLaunchLevelTasks(SSchJob *pJob, SSchLevel *level); +int32_t schGetTaskFromList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTask); +int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel); +int32_t schSwitchTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask); +void schDirectPostJobRes(SSchedulerReq *pReq, int32_t errCode); +int32_t schHandleJobFailure(SSchJob *pJob, int32_t errCode); +int32_t schHandleJobDrop(SSchJob *pJob, int32_t errCode); +bool schChkCurrentOp(SSchJob *pJob, int32_t op, int8_t sync); +int32_t schProcessFetchRsp(SSchJob *pJob, SSchTask *pTask, char *msg, int32_t rspCode); +int32_t schProcessExplainRsp(SSchJob *pJob, SSchTask *pTask, SExplainRsp *rsp); extern SSchDebug gSCHDebug; - #ifdef __cplusplus } #endif diff --git a/source/libs/scheduler/src/schDbg.c b/source/libs/scheduler/src/schDbg.c index a6398522d3358a5867fae171f90a1e5d5fb30077..d6c2b638b8c223dedce533825af4a3c62cf4da3c 100644 --- a/source/libs/scheduler/src/schDbg.c +++ b/source/libs/scheduler/src/schDbg.c @@ -16,19 +16,17 @@ #include "query.h" #include "schInt.h" -tsem_t schdRspSem; +tsem_t schdRspSem; SSchDebug gSCHDebug = {0}; void schdExecCallback(SExecResult* pResult, void* param, int32_t code) { if (code) { pResult->code = code; } - + *(SExecResult*)param = *pResult; taosMemoryFree(pResult); tsem_post(&schdRspSem); } - - diff --git a/source/libs/scheduler/src/schFlowCtrl.c b/source/libs/scheduler/src/schFlowCtrl.c index c5c2bfb2bb943da6ff85e686cff46b95dc194821..8980d08e891d58f4bbc7e1e88d0d3ea5d1c067ee 100644 --- a/source/libs/scheduler/src/schFlowCtrl.c +++ b/source/libs/scheduler/src/schFlowCtrl.c @@ -13,10 +13,10 @@ * along with this program. If not, see . */ +#include "catalog.h" +#include "query.h" #include "schInt.h" #include "tmsg.h" -#include "query.h" -#include "catalog.h" #include "tref.h" void schFreeFlowCtrl(SSchJob *pJob) { @@ -25,14 +25,14 @@ void schFreeFlowCtrl(SSchJob *pJob) { } SSchFlowControl *ctrl = NULL; - void *pIter = taosHashIterate(pJob->flowCtrl, NULL); + void *pIter = taosHashIterate(pJob->flowCtrl, NULL); while (pIter) { ctrl = (SSchFlowControl *)pIter; if (ctrl->taskList) { taosArrayDestroy(ctrl->taskList); } - + pIter = taosHashIterate(pJob->flowCtrl, pIter); } @@ -59,7 +59,8 @@ int32_t schChkJobNeedFlowCtrl(SSchJob *pJob, SSchLevel *pLevel) { return TSDB_CODE_SUCCESS; } - pJob->flowCtrl = taosHashInit(pJob->taskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); + pJob->flowCtrl = + taosHashInit(pJob->taskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (NULL == pJob->flowCtrl) { SCH_JOB_ELOG("taosHashInit %d flowCtrl failed", pJob->taskNum); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -73,17 +74,17 @@ int32_t schChkJobNeedFlowCtrl(SSchJob *pJob, SSchLevel *pLevel) { } int32_t schDecTaskFlowQuota(SSchJob *pJob, SSchTask *pTask) { - SSchLevel *pLevel = pTask->level; + SSchLevel *pLevel = pTask->level; SSchFlowControl *ctrl = NULL; - int32_t code = 0; - SEp *ep = SCH_GET_CUR_EP(&pTask->plan->execNode); - + int32_t code = 0; + SEp *ep = SCH_GET_CUR_EP(&pTask->plan->execNode); + ctrl = (SSchFlowControl *)taosHashGet(pJob->flowCtrl, ep, sizeof(SEp)); if (NULL == ctrl) { SCH_TASK_ELOG("taosHashGet node from flowCtrl failed, fqdn:%s, port:%d", ep->fqdn, ep->port); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } - + SCH_LOCK(SCH_WRITE, &ctrl->lock); if (ctrl->execTaskNum <= 0) { SCH_TASK_ELOG("taosHashGet node from flowCtrl failed, fqdn:%s, port:%d", ep->fqdn, ep->port); @@ -93,8 +94,8 @@ int32_t schDecTaskFlowQuota(SSchJob *pJob, SSchTask *pTask) { --ctrl->execTaskNum; ctrl->tableNumSum -= pTask->plan->execNodeStat.tableNum; - SCH_TASK_DLOG("task quota removed, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", - ep->fqdn, ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum); + SCH_TASK_DLOG("task quota removed, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", ep->fqdn, + ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum); _return: @@ -104,11 +105,11 @@ _return: } int32_t schCheckIncTaskFlowQuota(SSchJob *pJob, SSchTask *pTask, bool *enough) { - SSchLevel *pLevel = pTask->level; - int32_t code = 0; + SSchLevel *pLevel = pTask->level; + int32_t code = 0; SSchFlowControl *ctrl = NULL; - SEp *ep = SCH_GET_CUR_EP(&pTask->plan->execNode); - + SEp *ep = SCH_GET_CUR_EP(&pTask->plan->execNode); + do { ctrl = (SSchFlowControl *)taosHashGet(pJob->flowCtrl, ep, sizeof(SEp)); if (NULL == ctrl) { @@ -119,34 +120,34 @@ int32_t schCheckIncTaskFlowQuota(SSchJob *pJob, SSchTask *pTask, bool *enough) { if (HASH_NODE_EXIST(code)) { continue; } - + SCH_TASK_ELOG("taosHashPut flowCtrl failed, size:%d", (int32_t)sizeof(nctrl)); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SCH_TASK_DLOG("task quota added, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", - ep->fqdn, ep->port, pTask->plan->execNodeStat.tableNum, nctrl.tableNumSum, nctrl.execTaskNum); + SCH_TASK_DLOG("task quota added, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", ep->fqdn, + ep->port, pTask->plan->execNodeStat.tableNum, nctrl.tableNumSum, nctrl.execTaskNum); *enough = true; return TSDB_CODE_SUCCESS; } SCH_LOCK(SCH_WRITE, &ctrl->lock); - + if (0 == ctrl->execTaskNum) { ctrl->tableNumSum = pTask->plan->execNodeStat.tableNum; ++ctrl->execTaskNum; - + *enough = true; break; } - + int32_t sum = pTask->plan->execNodeStat.tableNum + ctrl->tableNumSum; - + if (sum <= schMgmt.cfg.maxNodeTableNum) { ctrl->tableNumSum = sum; ++ctrl->execTaskNum; - + *enough = true; break; } @@ -166,24 +167,25 @@ int32_t schCheckIncTaskFlowQuota(SSchJob *pJob, SSchTask *pTask, bool *enough) { *enough = false; ctrl->sorted = false; - + break; } while (true); _return: - SCH_TASK_DLOG("task quota %s added, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", - ((*enough)?"":"NOT"), ep->fqdn, ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum); + SCH_TASK_DLOG("task quota %s added, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", + ((*enough) ? "" : "NOT"), ep->fqdn, ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, + ctrl->execTaskNum); SCH_UNLOCK(SCH_WRITE, &ctrl->lock); - + SCH_RET(code); } -int32_t schTaskTableNumCompare(const void* key1, const void* key2) { +int32_t schTaskTableNumCompare(const void *key1, const void *key2) { SSchTask *pTask1 = *(SSchTask **)key1; SSchTask *pTask2 = *(SSchTask **)key2; - + if (pTask1->plan->execNodeStat.tableNum < pTask2->plan->execNodeStat.tableNum) { return 1; } else if (pTask1->plan->execNodeStat.tableNum > pTask2->plan->execNodeStat.tableNum) { @@ -193,22 +195,21 @@ int32_t schTaskTableNumCompare(const void* key1, const void* key2) { } } - int32_t schLaunchTasksInFlowCtrlListImpl(SSchJob *pJob, SSchFlowControl *ctrl) { SCH_LOCK(SCH_WRITE, &ctrl->lock); - + if (NULL == ctrl->taskList || taosArrayGetSize(ctrl->taskList) <= 0) { SCH_UNLOCK(SCH_WRITE, &ctrl->lock); return TSDB_CODE_SUCCESS; } - int32_t remainNum = schMgmt.cfg.maxNodeTableNum - ctrl->tableNumSum; - int32_t taskNum = taosArrayGetSize(ctrl->taskList); - int32_t code = 0; + int32_t remainNum = schMgmt.cfg.maxNodeTableNum - ctrl->tableNumSum; + int32_t taskNum = taosArrayGetSize(ctrl->taskList); + int32_t code = 0; SSchTask *pTask = NULL; - + if (taskNum > 1 && !ctrl->sorted) { - taosArraySort(ctrl->taskList, schTaskTableNumCompare); // desc order + taosArraySort(ctrl->taskList, schTaskTableNumCompare); // desc order } for (int32_t i = 0; i < taskNum; ++i) { @@ -216,36 +217,36 @@ int32_t schLaunchTasksInFlowCtrlListImpl(SSchJob *pJob, SSchFlowControl *ctrl) { SEp *ep = SCH_GET_CUR_EP(&pTask->plan->execNode); if (pTask->plan->execNodeStat.tableNum > remainNum && ctrl->execTaskNum > 0) { - SCH_TASK_DLOG("task NOT to launch, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", - ep->fqdn, ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum); + SCH_TASK_DLOG("task NOT to launch, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", ep->fqdn, + ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum); continue; } - + ctrl->tableNumSum += pTask->plan->execNodeStat.tableNum; ++ctrl->execTaskNum; taosArrayRemove(ctrl->taskList, i); - - SCH_TASK_DLOG("task to launch, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", - ep->fqdn, ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum); - + + SCH_TASK_DLOG("task to launch, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", ep->fqdn, + ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum); + SCH_ERR_JRET(schAsyncLaunchTaskImpl(pJob, pTask)); - + remainNum -= pTask->plan->execNodeStat.tableNum; if (remainNum <= 0) { - SCH_TASK_DLOG("no more task to launch, fqdn:%s, port:%d, remainNum:%d, remainExecTaskNum:%d", - ep->fqdn, ep->port, ctrl->tableNumSum, ctrl->execTaskNum); - + SCH_TASK_DLOG("no more task to launch, fqdn:%s, port:%d, remainNum:%d, remainExecTaskNum:%d", ep->fqdn, ep->port, + ctrl->tableNumSum, ctrl->execTaskNum); + break; } if (i < (taskNum - 1)) { SSchTask *pLastTask = *(SSchTask **)taosArrayGetLast(ctrl->taskList); if (remainNum < pLastTask->plan->execNodeStat.tableNum) { - SCH_TASK_DLOG("no more task to launch, fqdn:%s, port:%d, remainNum:%d, remainExecTaskNum:%d, smallestInList:%d", - ep->fqdn, ep->port, ctrl->tableNumSum, ctrl->execTaskNum, pLastTask->plan->execNodeStat.tableNum); - + SCH_TASK_DLOG("no more task to launch, fqdn:%s, port:%d, remainNum:%d, remainExecTaskNum:%d, smallestInList:%d", + ep->fqdn, ep->port, ctrl->tableNumSum, ctrl->execTaskNum, pLastTask->plan->execNodeStat.tableNum); + break; } } @@ -253,7 +254,7 @@ int32_t schLaunchTasksInFlowCtrlListImpl(SSchJob *pJob, SSchFlowControl *ctrl) { --i; --taskNum; } - + _return: SCH_UNLOCK(SCH_WRITE, &ctrl->lock); @@ -261,11 +262,10 @@ _return: if (code) { code = schProcessOnTaskFailure(pJob, pTask, code); } - + SCH_RET(code); } - int32_t schLaunchTasksInFlowCtrlList(SSchJob *pJob, SSchTask *pTask) { if (!SCH_TASK_NEED_FLOW_CTRL(pJob, pTask)) { return TSDB_CODE_SUCCESS; @@ -274,17 +274,16 @@ int32_t schLaunchTasksInFlowCtrlList(SSchJob *pJob, SSchTask *pTask) { SCH_ERR_RET(schDecTaskFlowQuota(pJob, pTask)); SEp *ep = SCH_GET_CUR_EP(&pTask->plan->execNode); - + SSchFlowControl *ctrl = (SSchFlowControl *)taosHashGet(pJob->flowCtrl, ep, sizeof(SEp)); if (NULL == ctrl) { SCH_TASK_ELOG("taosHashGet node from flowCtrl failed, fqdn:%s, port:%d", ep->fqdn, ep->port); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } - - int32_t code = schLaunchTasksInFlowCtrlListImpl(pJob, ctrl);; - SCH_ERR_RET(code); - - return code; // to avoid compiler error -} + int32_t code = schLaunchTasksInFlowCtrlListImpl(pJob, ctrl); + ; + SCH_ERR_RET(code); + return code; // to avoid compiler error +} diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index 69495c8b7aa0901807ed81a146418f0c6b6264db..bb8451ba37bf9dbc79e762f421cde624b440b9f7 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -52,9 +52,8 @@ _return: bool schJobDone(SSchJob *pJob) { int8_t status = SCH_GET_JOB_STATUS(pJob); - - return (status == JOB_TASK_STATUS_FAIL || status == JOB_TASK_STATUS_DROP || - status == JOB_TASK_STATUS_SUCC); + + return (status == JOB_TASK_STATUS_FAIL || status == JOB_TASK_STATUS_DROP || status == JOB_TASK_STATUS_SUCC); } FORCE_INLINE bool schJobNeedToStop(SSchJob *pJob, int8_t *pStatus) { @@ -221,7 +220,7 @@ int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SCH_TASK_DLOG("parents info, the %d parent TID 0x%" PRIx64, n, (*parentTask)->taskId); + SCH_TASK_DLOG("parents info, the %d parent TID 0x%" PRIx64, n, (*parentTask)->taskId); } SCH_TASK_DLOG("level:%d, parentNum:%d, childNum:%d", i, parentNum, childNum); @@ -235,7 +234,7 @@ int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) { SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } - SSchTask* pTask = taosArrayGet(pLevel->subTasks, 0); + SSchTask *pTask = taosArrayGet(pLevel->subTasks, 0); if (SUBPLAN_TYPE_MODIFY != pTask->plan->subplanType) { pJob->attr.needFetch = true; } @@ -244,7 +243,6 @@ int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) { return TSDB_CODE_SUCCESS; } - int32_t schAppendJobDataSrc(SSchJob *pJob, SSchTask *pTask) { if (!SCH_IS_DATA_BIND_QRY_TASK(pTask)) { return TSDB_CODE_SUCCESS; @@ -255,7 +253,6 @@ int32_t schAppendJobDataSrc(SSchJob *pJob, SSchTask *pTask) { return TSDB_CODE_SUCCESS; } - int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { int32_t code = 0; pJob->queryId = pDag->queryId; @@ -365,7 +362,7 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { SCH_ERR_JRET(schBuildTaskRalation(pJob, planToTask)); _return: - + if (planToTask) { taosHashCleanup(planToTask); } @@ -373,8 +370,7 @@ _return: SCH_RET(code); } - -int32_t schDumpJobExecRes(SSchJob* pJob, SExecResult* pRes) { +int32_t schDumpJobExecRes(SSchJob *pJob, SExecResult *pRes) { pRes->code = atomic_load_32(&pJob->errCode); pRes->numOfRows = pJob->resNumOfRows; pRes->res = pJob->execRes.res; @@ -387,13 +383,13 @@ int32_t schDumpJobExecRes(SSchJob* pJob, SExecResult* pRes) { return TSDB_CODE_SUCCESS; } -int32_t schDumpJobFetchRes(SSchJob* pJob, void** pData) { +int32_t schDumpJobFetchRes(SSchJob *pJob, void **pData) { int32_t code = 0; - + SCH_LOCK(SCH_WRITE, &pJob->resLock); pJob->fetched = true; - + if (pJob->fetchRes && ((SRetrieveTableRsp *)pJob->fetchRes)->completed) { SCH_ERR_JRET(schSwitchJobStatus(pJob, JOB_TASK_STATUS_SUCC, NULL)); } @@ -422,12 +418,12 @@ int32_t schDumpJobFetchRes(SSchJob* pJob, void** pData) { _return: SCH_UNLOCK(SCH_WRITE, &pJob->resLock); - + return code; } -int32_t schNotifyUserExecRes(SSchJob* pJob) { - SExecResult* pRes = taosMemoryCalloc(1, sizeof(SExecResult)); +int32_t schNotifyUserExecRes(SSchJob *pJob) { + SExecResult *pRes = taosMemoryCalloc(1, sizeof(SExecResult)); if (pRes) { schDumpJobExecRes(pJob, pRes); } @@ -439,9 +435,9 @@ int32_t schNotifyUserExecRes(SSchJob* pJob) { return TSDB_CODE_SUCCESS; } -int32_t schNotifyUserFetchRes(SSchJob* pJob) { - void* pRes = NULL; - +int32_t schNotifyUserFetchRes(SSchJob *pJob) { + void *pRes = NULL; + schDumpJobFetchRes(pJob, &pRes); SCH_JOB_DLOG("sch start to invoke fetch cb, code: %s", tstrerror(pJob->errCode)); @@ -453,17 +449,17 @@ int32_t schNotifyUserFetchRes(SSchJob* pJob) { void schPostJobRes(SSchJob *pJob, SCH_OP_TYPE op) { SCH_LOCK(SCH_WRITE, &pJob->opStatus.lock); - + if (SCH_OP_NULL == pJob->opStatus.op) { SCH_JOB_DLOG("job not in any operation, no need to post job res, status:%s", jobTaskStatusStr(pJob->status)); goto _return; } - + if (op && pJob->opStatus.op != op) { SCH_JOB_ELOG("job in operation %s mis-match with expected %s", schGetOpStr(pJob->opStatus.op), schGetOpStr(op)); goto _return; } - + if (SCH_JOB_IN_SYNC_OP(pJob)) { SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock); tsem_post(&pJob->rspSem); @@ -487,7 +483,7 @@ _return: int32_t schProcessOnJobFailure(SSchJob *pJob, int32_t errCode) { schUpdateJobErrCode(pJob, errCode); - + int32_t code = atomic_load_32(&pJob->errCode); if (code) { SCH_JOB_DLOG("job failed with error %s", tstrerror(code)); @@ -507,9 +503,7 @@ int32_t schHandleJobFailure(SSchJob *pJob, int32_t errCode) { return TSDB_CODE_SCH_IGNORE_ERROR; } -int32_t schProcessOnJobDropped(SSchJob *pJob, int32_t errCode) { - SCH_RET(schProcessOnJobFailure(pJob, errCode)); -} +int32_t schProcessOnJobDropped(SSchJob *pJob, int32_t errCode) { SCH_RET(schProcessOnJobFailure(pJob, errCode)); } int32_t schHandleJobDrop(SSchJob *pJob, int32_t errCode) { if (TSDB_CODE_SCH_IGNORE_ERROR == errCode) { @@ -520,8 +514,7 @@ int32_t schHandleJobDrop(SSchJob *pJob, int32_t errCode) { return TSDB_CODE_SCH_IGNORE_ERROR; } - -int32_t schProcessOnJobPartialSuccess(SSchJob *pJob) { +int32_t schProcessOnJobPartialSuccess(SSchJob *pJob) { if (schChkCurrentOp(pJob, SCH_OP_FETCH, -1)) { SCH_ERR_RET(schLaunchFetchTask(pJob)); } else { @@ -531,9 +524,7 @@ int32_t schProcessOnJobPartialSuccess(SSchJob *pJob) { return TSDB_CODE_SUCCESS; } -void schProcessOnDataFetched(SSchJob *pJob) { - schPostJobRes(pJob, SCH_OP_FETCH); -} +void schProcessOnDataFetched(SSchJob *pJob) { schPostJobRes(pJob, SCH_OP_FETCH); } int32_t schProcessOnExplainDone(SSchJob *pJob, SSchTask *pTask, SRetrieveTableRsp *pRsp) { SCH_TASK_DLOG("got explain rsp, rows:%d, complete:%d", htonl(pRsp->numOfRows), pRsp->completed); @@ -548,14 +539,13 @@ int32_t schProcessOnExplainDone(SSchJob *pJob, SSchTask *pTask, SRetrieveTableRs return TSDB_CODE_SUCCESS; } - int32_t schLaunchJobLowerLevel(SSchJob *pJob, SSchTask *pTask) { if (!SCH_IS_QUERY_JOB(pJob)) { return TSDB_CODE_SUCCESS; } SSchLevel *pLevel = pTask->level; - int32_t doneNum = atomic_add_fetch_32(&pLevel->taskDoneNum, 1); + int32_t doneNum = atomic_add_fetch_32(&pLevel->taskDoneNum, 1); if (doneNum == pLevel->taskNum) { pJob->levelIdx--; @@ -566,7 +556,7 @@ int32_t schLaunchJobLowerLevel(SSchJob *pJob, SSchTask *pTask) { if (pTask->children && taosArrayGetSize(pTask->children) > 0) { continue; } - + SCH_ERR_RET(schLaunchTask(pJob, pTask)); } } @@ -577,11 +567,11 @@ int32_t schLaunchJobLowerLevel(SSchJob *pJob, SSchTask *pTask) { int32_t schSaveJobExecRes(SSchJob *pJob, SQueryTableRsp *rsp) { if (rsp->tbFName[0]) { SCH_LOCK(SCH_WRITE, &pJob->resLock); - + if (NULL == pJob->execRes.res) { pJob->execRes.res = taosArrayInit(pJob->taskNum, sizeof(STbVerInfo)); if (NULL == pJob->execRes.res) { - SCH_UNLOCK(SCH_WRITE, &pJob->resLock); + SCH_UNLOCK(SCH_WRITE, &pJob->resLock); SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } @@ -610,7 +600,6 @@ int32_t schGetTaskInJob(SSchJob *pJob, uint64_t taskId, SSchTask **pTask) { return TSDB_CODE_SUCCESS; } - int32_t schLaunchJob(SSchJob *pJob) { if (EXPLAIN_MODE_STATIC == pJob->attr.explainMode) { SCH_ERR_RET(qExecStaticExplain(pJob->pDag, (SRetrieveTableRsp **)&pJob->fetchRes)); @@ -623,11 +612,10 @@ int32_t schLaunchJob(SSchJob *pJob) { return TSDB_CODE_SUCCESS; } - void schDropJobAllTasks(SSchJob *pJob) { schDropTaskInHashList(pJob, pJob->execTasks); -// schDropTaskInHashList(pJob, pJob->succTasks); -// schDropTaskInHashList(pJob, pJob->failTasks); + // schDropTaskInHashList(pJob, pJob->succTasks); + // schDropTaskInHashList(pJob, pJob->failTasks); } void schFreeJobImpl(void *job) { @@ -659,10 +647,10 @@ void schFreeJobImpl(void *job) { schFreeFlowCtrl(pJob); taosHashCleanup(pJob->execTasks); -// taosHashCleanup(pJob->failTasks); -// taosHashCleanup(pJob->succTasks); + // taosHashCleanup(pJob->failTasks); + // taosHashCleanup(pJob->succTasks); taosHashCleanup(pJob->taskList); - + taosArrayDestroy(pJob->levels); taosArrayDestroy(pJob->nodeList); taosArrayDestroy(pJob->dataSrcTasks); @@ -688,19 +676,19 @@ void schFreeJobImpl(void *job) { } int32_t schJobFetchRows(SSchJob *pJob) { - int32_t code = 0; + int32_t code = 0; if (!(pJob->attr.explainMode == EXPLAIN_MODE_STATIC)) { SCH_ERR_RET(schLaunchFetchTask(pJob)); - + if (schChkCurrentOp(pJob, SCH_OP_FETCH, true)) { SCH_JOB_DLOG("sync wait for rsp now, job status:%s", SCH_GET_JOB_STATUS_STR(pJob)); tsem_wait(&pJob->rspSem); - SCH_RET(schDumpJobFetchRes(pJob, pJob->userRes.fetchRes)); + SCH_RET(schDumpJobFetchRes(pJob, pJob->userRes.fetchRes)); } } else { if (schChkCurrentOp(pJob, SCH_OP_FETCH, true)) { - SCH_RET(schDumpJobFetchRes(pJob, pJob->userRes.fetchRes)); + SCH_RET(schDumpJobFetchRes(pJob, pJob->userRes.fetchRes)); } else { schPostJobRes(pJob, SCH_OP_FETCH); } @@ -736,9 +724,9 @@ int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq) { } else { pJob->nodeList = taosArrayDup(pReq->pNodeList); } - - pJob->taskList = - taosHashInit(pReq->pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); + + pJob->taskList = taosHashInit(pReq->pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, + HASH_ENTRY_LOCK); if (NULL == pJob->taskList) { SCH_JOB_ELOG("taosHashInit %d taskList failed", pReq->pDag->numOfSubplans); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -750,8 +738,8 @@ int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq) { SCH_ERR_JRET(qExecExplainBegin(pReq->pDag, &pJob->explainCtx, pReq->startTs)); } - pJob->execTasks = - taosHashInit(pReq->pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); + pJob->execTasks = taosHashInit(pReq->pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, + HASH_ENTRY_LOCK); if (NULL == pJob->execTasks) { SCH_JOB_ELOG("taosHashInit %d execTasks failed", pReq->pDag->numOfSubplans); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -769,7 +757,7 @@ int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq) { *pJobId = pJob->refId; - SCH_JOB_DLOG("job refId:0x%" PRIx64" created", pJob->refId); + SCH_JOB_DLOG("job refId:0x%" PRIx64 " created", pJob->refId); return TSDB_CODE_SUCCESS; @@ -782,31 +770,31 @@ _return: } else { taosRemoveRef(schMgmt.jobRef, pJob->refId); } - + SCH_RET(code); } int32_t schExecJob(SSchJob *pJob, SSchedulerReq *pReq) { int32_t code = 0; - qDebug("QID:0x%" PRIx64 " sch job refId 0x%"PRIx64 " started", pReq->pDag->queryId, pJob->refId); + qDebug("QID:0x%" PRIx64 " sch job refId 0x%" PRIx64 " started", pReq->pDag->queryId, pJob->refId); SCH_ERR_RET(schLaunchJob(pJob)); - + if (pReq->syncReq) { SCH_JOB_DLOG("sync wait for rsp now, job status:%s", SCH_GET_JOB_STATUS_STR(pJob)); tsem_wait(&pJob->rspSem); } SCH_JOB_DLOG("job exec done, job status:%s, jobId:0x%" PRIx64, SCH_GET_JOB_STATUS_STR(pJob), pJob->refId); - + return TSDB_CODE_SUCCESS; } -void schDirectPostJobRes(SSchedulerReq* pReq, int32_t errCode) { +void schDirectPostJobRes(SSchedulerReq *pReq, int32_t errCode) { if (NULL == pReq || pReq->syncReq) { return; } - + if (pReq->execFp) { (*pReq->execFp)(NULL, pReq->cbParam, errCode); } else if (pReq->fetchFp) { @@ -827,16 +815,17 @@ bool schChkCurrentOp(SSchJob *pJob, int32_t op, int8_t sync) { return r; } -void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode) { +void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq *pReq, int32_t errCode) { int32_t op = 0; - + switch (type) { case SCH_OP_EXEC: if (pReq && pReq->syncReq) { SCH_LOCK(SCH_WRITE, &pJob->opStatus.lock); op = atomic_val_compare_exchange_32(&pJob->opStatus.op, type, SCH_OP_NULL); if (SCH_OP_NULL == op || op != type) { - SCH_JOB_ELOG("job not in %s operation, op:%s, status:%s", schGetOpStr(type), schGetOpStr(op), jobTaskStatusStr(pJob->status)); + SCH_JOB_ELOG("job not in %s operation, op:%s, status:%s", schGetOpStr(type), schGetOpStr(op), + jobTaskStatusStr(pJob->status)); } SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock); schDumpJobExecRes(pJob, pReq->pExecRes); @@ -847,7 +836,8 @@ void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int SCH_LOCK(SCH_WRITE, &pJob->opStatus.lock); op = atomic_val_compare_exchange_32(&pJob->opStatus.op, type, SCH_OP_NULL); if (SCH_OP_NULL == op || op != type) { - SCH_JOB_ELOG("job not in %s operation, op:%s, status:%s", schGetOpStr(type), schGetOpStr(op), jobTaskStatusStr(pJob->status)); + SCH_JOB_ELOG("job not in %s operation, op:%s, status:%s", schGetOpStr(type), schGetOpStr(op), + jobTaskStatusStr(pJob->status)); } SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock); } @@ -866,10 +856,10 @@ void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int SCH_JOB_DLOG("job end %s operation with code %s", schGetOpStr(type), tstrerror(errCode)); } -int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq) { +int32_t schProcessOnOpBegin(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq *pReq) { int32_t code = 0; - int8_t status = SCH_GET_JOB_STATUS(pJob); - + int8_t status = SCH_GET_JOB_STATUS(pJob); + switch (type) { case SCH_OP_EXEC: SCH_LOCK(SCH_WRITE, &pJob->opStatus.lock); @@ -879,9 +869,9 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq schDirectPostJobRes(pReq, TSDB_CODE_TSC_APP_ERROR); SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR); } - + SCH_JOB_DLOG("job start %s operation", schGetOpStr(pJob->opStatus.op)); - + pJob->opStatus.syncReq = pReq->syncReq; SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock); break; @@ -893,16 +883,16 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq schDirectPostJobRes(pReq, TSDB_CODE_TSC_APP_ERROR); SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR); } - + SCH_JOB_DLOG("job start %s operation", schGetOpStr(pJob->opStatus.op)); - + pJob->userRes.fetchRes = pReq->pFetchRes; pJob->userRes.fetchFp = pReq->fetchFp; pJob->userRes.cbParam = pReq->cbParam; - + pJob->opStatus.syncReq = pReq->syncReq; SCH_UNLOCK(SCH_WRITE, &pJob->opStatus.lock); - + if (!SCH_JOB_NEED_FETCH(pJob)) { SCH_JOB_ELOG("no need to fetch data, status:%s", SCH_GET_JOB_STATUS_STR(pJob)); SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR); @@ -912,7 +902,7 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq SCH_JOB_ELOG("job status error for fetch, status:%s", jobTaskStatusStr(status)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } - + break; case SCH_OP_GET_STATUS: if (pJob->status < JOB_TASK_STATUS_INIT || pJob->levelNum <= 0 || NULL == pJob->levels) { @@ -941,23 +931,23 @@ void schProcessOnCbEnd(SSchJob *pJob, SSchTask *pTask, int32_t errCode) { if (errCode) { schHandleJobFailure(pJob, errCode); } - + if (pJob) { schReleaseJob(pJob->refId); } } -int32_t schProcessOnCbBegin(SSchJob** job, SSchTask** task, uint64_t qId, int64_t rId, uint64_t tId) { +int32_t schProcessOnCbBegin(SSchJob **job, SSchTask **task, uint64_t qId, int64_t rId, uint64_t tId) { int32_t code = 0; - int8_t status = 0; + int8_t status = 0; SSchTask *pTask = NULL; - SSchJob *pJob = schAcquireJob(rId); + SSchJob *pJob = schAcquireJob(rId); if (NULL == pJob) { qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 "job no exist, may be dropped, refId:0x%" PRIx64, qId, tId, rId); SCH_ERR_RET(TSDB_CODE_QRY_JOB_NOT_EXIST); } - + if (schJobNeedToStop(pJob, &status)) { SCH_TASK_DLOG("will not do further processing cause of job status %s", jobTaskStatusStr(status)); SCH_ERR_JRET(TSDB_CODE_SCH_IGNORE_ERROR); @@ -980,9 +970,6 @@ _return: if (pJob) { schReleaseJob(rId); } - + SCH_RET(code); } - - - diff --git a/source/libs/scheduler/src/schStatus.c b/source/libs/scheduler/src/schStatus.c index 64cda573f1fa8bd022a548787151b2b9fd64d44f..66d58c95d1c3a36938fb0b5b1fa420c558a33e4a 100644 --- a/source/libs/scheduler/src/schStatus.c +++ b/source/libs/scheduler/src/schStatus.c @@ -29,25 +29,25 @@ int32_t schSwitchJobStatus(SSchJob* pJob, int32_t status, void* param) { case JOB_TASK_STATUS_INIT: break; case JOB_TASK_STATUS_EXEC: - SCH_ERR_JRET(schExecJob(pJob, (SSchedulerReq*)param)); + SCH_ERR_JRET(schExecJob(pJob, (SSchedulerReq*)param)); break; case JOB_TASK_STATUS_PART_SUCC: SCH_ERR_JRET(schProcessOnJobPartialSuccess(pJob)); break; case JOB_TASK_STATUS_SUCC: break; - case JOB_TASK_STATUS_FAIL: + case JOB_TASK_STATUS_FAIL: SCH_RET(schProcessOnJobFailure(pJob, (param ? *(int32_t*)param : 0))); break; case JOB_TASK_STATUS_DROP: schProcessOnJobDropped(pJob, *(int32_t*)param); - + if (taosRemoveRef(schMgmt.jobRef, pJob->refId)) { SCH_JOB_ELOG("remove job from job list failed, refId:0x%" PRIx64, pJob->refId); } else { SCH_JOB_DLOG("job removed from jobRef list, refId:0x%" PRIx64, pJob->refId); } - break; + break; default: { SCH_JOB_ELOG("unknown job status %d", status); SCH_RET(TSDB_CODE_SCH_STATUS_ERROR); @@ -62,7 +62,7 @@ _return: } int32_t schHandleOpBeginEvent(int64_t jobId, SSchJob** job, SCH_OP_TYPE type, SSchedulerReq* pReq) { - SSchJob *pJob = schAcquireJob(jobId); + SSchJob* pJob = schAcquireJob(jobId); if (NULL == pJob) { qWarn("Acquire sch job failed, may be dropped, jobId:0x%" PRIx64, jobId); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); @@ -75,12 +75,12 @@ int32_t schHandleOpBeginEvent(int64_t jobId, SSchJob** job, SCH_OP_TYPE type, SS int32_t schHandleOpEndEvent(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode) { int32_t code = errCode; - + if (NULL == pJob) { schDirectPostJobRes(pReq, errCode); SCH_RET(code); } - + schProcessOnOpEnd(pJob, type, pReq, errCode); if (TSDB_CODE_SCH_IGNORE_ERROR == errCode) { @@ -91,5 +91,3 @@ int32_t schHandleOpEndEvent(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq return code; } - - diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c index b6f96a188e4fc06f365b6ccf527c3587abb959af..33bf50d85313a6fa5f9709568f525bd98894c215 100644 --- a/source/libs/scheduler/src/schTask.c +++ b/source/libs/scheduler/src/schTask.c @@ -16,12 +16,12 @@ #include "catalog.h" #include "command.h" #include "query.h" +#include "qworker.h" #include "schInt.h" +#include "tglobal.h" #include "tmsg.h" #include "tref.h" #include "trpc.h" -#include "qworker.h" -#include "tglobal.h" void schFreeTask(SSchJob *pJob, SSchTask *pTask) { schDeregisterTaskHb(pJob, pTask); @@ -94,7 +94,7 @@ int32_t schRecordTaskSucceedNode(SSchJob *pJob, SSchTask *pTask) { if (SCH_IS_LOCAL_EXEC_TASK(pJob, pTask)) { return TSDB_CODE_SUCCESS; } - + SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); if (NULL == addr) { SCH_TASK_ELOG("taosArrayGet candidate addr failed, idx:%d, size:%d", pTask->candidateIdx, @@ -162,14 +162,15 @@ int32_t schUpdateTaskHandle(SSchJob *pJob, SSchTask *pTask, bool dropExecNode, v if (dropExecNode) { SCH_RET(schDropTaskExecNode(pJob, pTask, handle, execId)); } - + schUpdateTaskExecNode(pJob, pTask, handle, execId); if ((execId != pTask->execId) || pTask->waitRetry) { // ignore it - SCH_TASK_DLOG("handle not updated since execId %d is already not current execId %d, waitRetry %d", execId, pTask->execId, pTask->waitRetry); + SCH_TASK_DLOG("handle not updated since execId %d is already not current execId %d, waitRetry %d", execId, + pTask->execId, pTask->waitRetry); SCH_ERR_RET(TSDB_CODE_SCH_IGNORE_ERROR); } - + SCH_SET_TASK_HANDLE(pTask, handle); return TSDB_CODE_SUCCESS; @@ -837,17 +838,18 @@ int32_t schHandleExplainRes(SArray *pExplainRes) { goto _return; } - SSchTask *pTask = NULL; - SSchJob *pJob = NULL; + SSchTask *pTask = NULL; + SSchJob *pJob = NULL; for (int32_t i = 0; i < resNum; ++i) { - SExplainLocalRsp* localRsp = taosArrayGet(pExplainRes, i); + SExplainLocalRsp *localRsp = taosArrayGet(pExplainRes, i); qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ", begin to handle LOCAL explain rsp msg", localRsp->qId, localRsp->tId); pJob = schAcquireJob(localRsp->rId); if (NULL == pJob) { - qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 "job no exist, may be dropped, refId:0x%" PRIx64, localRsp->qId, localRsp->tId, localRsp->rId); + qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 "job no exist, may be dropped, refId:0x%" PRIx64, localRsp->qId, + localRsp->tId, localRsp->rId); SCH_ERR_JRET(TSDB_CODE_QRY_JOB_NOT_EXIST); } @@ -857,16 +859,17 @@ int32_t schHandleExplainRes(SArray *pExplainRes) { schReleaseJob(pJob->refId); SCH_ERR_JRET(TSDB_CODE_SCH_IGNORE_ERROR); } - + code = schGetTaskInJob(pJob, localRsp->tId, &pTask); if (TSDB_CODE_SUCCESS == code) { code = schProcessExplainRsp(pJob, pTask, &localRsp->rsp); } - + schReleaseJob(pJob->refId); - qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ", end to handle LOCAL explain rsp msg, code:%x", localRsp->qId, localRsp->tId, code); + qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ", end to handle LOCAL explain rsp msg, code:%x", localRsp->qId, + localRsp->tId, code); SCH_ERR_JRET(code); @@ -879,7 +882,7 @@ int32_t schHandleExplainRes(SArray *pExplainRes) { _return: for (int32_t i = 0; i < resNum; ++i) { - SExplainLocalRsp* localRsp = taosArrayGet(pExplainRes, i); + SExplainLocalRsp *localRsp = taosArrayGet(pExplainRes, i); tFreeSExplainRsp(&localRsp->rsp); } @@ -890,7 +893,7 @@ _return: int32_t schLaunchRemoteTask(SSchJob *pJob, SSchTask *pTask) { SSubplan *plan = pTask->plan; - int32_t code = 0; + int32_t code = 0; if (NULL == pTask->msg) { // TODO add more detailed reason for failure code = qSubPlanToMsg(plan, &pTask->msg, &pTask->msgLen); @@ -899,7 +902,7 @@ int32_t schLaunchRemoteTask(SSchJob *pJob, SSchTask *pTask) { pTask->msgLen); SCH_ERR_RET(code); } else if (tsQueryPlannerTrace) { - char *msg = NULL; + char *msg = NULL; int32_t msgLen = 0; qSubPlanToString(plan, &msg, &msgLen); SCH_TASK_DLOGL("physical plan len:%d, %s", msgLen, msg); @@ -910,20 +913,20 @@ int32_t schLaunchRemoteTask(SSchJob *pJob, SSchTask *pTask) { SCH_ERR_RET(schSetTaskCandidateAddrs(pJob, pTask)); if (SCH_IS_QUERY_JOB(pJob)) { - SCH_ERR_RET(schEnsureHbConnection(pJob, pTask)); +// SCH_ERR_RET(schEnsureHbConnection(pJob, pTask)); } - + SCH_RET(schBuildAndSendMsg(pJob, pTask, NULL, plan->msgType)); } int32_t schLaunchLocalTask(SSchJob *pJob, SSchTask *pTask) { - //SCH_ERR_JRET(schSetTaskCandidateAddrs(pJob, pTask)); + // SCH_ERR_JRET(schSetTaskCandidateAddrs(pJob, pTask)); if (NULL == schMgmt.queryMgmt) { SCH_ERR_RET(qWorkerInit(NODE_TYPE_CLIENT, CLIENT_HANDLE, (void **)&schMgmt.queryMgmt, NULL)); } SArray *explainRes = NULL; - SQWMsg qwMsg = {0}; + SQWMsg qwMsg = {0}; qwMsg.msgInfo.taskType = TASK_TYPE_TEMP; qwMsg.msgInfo.explain = SCH_IS_EXPLAIN_JOB(pJob); qwMsg.msgInfo.needFetch = SCH_TASK_NEED_FETCH(pTask); @@ -934,8 +937,9 @@ int32_t schLaunchLocalTask(SSchJob *pJob, SSchTask *pTask) { if (SCH_IS_EXPLAIN_JOB(pJob)) { explainRes = taosArrayInit(pJob->taskNum, sizeof(SExplainLocalRsp)); } - - SCH_ERR_RET(qWorkerProcessLocalQuery(schMgmt.queryMgmt, schMgmt.sId, pJob->queryId, pTask->taskId, pJob->refId, pTask->execId, &qwMsg, explainRes)); + + SCH_ERR_RET(qWorkerProcessLocalQuery(schMgmt.queryMgmt, schMgmt.sId, pJob->queryId, pTask->taskId, pJob->refId, + pTask->execId, &qwMsg, explainRes)); if (SCH_IS_EXPLAIN_JOB(pJob)) { SCH_ERR_RET(schHandleExplainRes(explainRes)); @@ -958,17 +962,17 @@ int32_t schLaunchTaskImpl(void *param) { if (pCtx->asyncLaunch) { SCH_LOCK_TASK(pTask); } - - int8_t status = 0; - int32_t code = 0; + + int8_t status = 0; + int32_t code = 0; atomic_add_fetch_32(&pTask->level->taskLaunchedNum, 1); pTask->execId++; pTask->retryTimes++; pTask->waitRetry = false; - SCH_TASK_DLOG("start to launch %s task, execId %d, retry %d", SCH_IS_LOCAL_EXEC_TASK(pJob, pTask) ? "LOCAL" : "REMOTE", - pTask->execId, pTask->retryTimes); + SCH_TASK_DLOG("start to launch %s task, execId %d, retry %d", + SCH_IS_LOCAL_EXEC_TASK(pJob, pTask) ? "LOCAL" : "REMOTE", pTask->execId, pTask->retryTimes); SCH_LOG_TASK_START_TS(pTask); @@ -989,6 +993,12 @@ int32_t schLaunchTaskImpl(void *param) { SCH_ERR_JRET(schLaunchRemoteTask(pJob, pTask)); } +#if 0 + if (SCH_IS_QUERY_JOB(pJob)) { + SCH_ERR_JRET(schEnsureHbConnection(pJob, pTask)); + } +#endif + _return: if (pJob->taskNum >= SCH_MIN_AYSNC_EXEC_NUM) { @@ -1086,19 +1096,20 @@ int32_t schExecRemoteFetch(SSchJob *pJob, SSchTask *pTask) { } int32_t schExecLocalFetch(SSchJob *pJob, SSchTask *pTask) { - void *pRsp = NULL; + void *pRsp = NULL; SArray *explainRes = NULL; if (SCH_IS_EXPLAIN_JOB(pJob)) { explainRes = taosArrayInit(pJob->taskNum, sizeof(SExplainLocalRsp)); } - SCH_ERR_RET(qWorkerProcessLocalFetch(schMgmt.queryMgmt, schMgmt.sId, pJob->queryId, pTask->taskId, pJob->refId, pTask->execId, &pRsp, explainRes)); + SCH_ERR_RET(qWorkerProcessLocalFetch(schMgmt.queryMgmt, schMgmt.sId, pJob->queryId, pTask->taskId, pJob->refId, + pTask->execId, &pRsp, explainRes)); if (SCH_IS_EXPLAIN_JOB(pJob)) { SCH_ERR_RET(schHandleExplainRes(explainRes)); } - + SCH_ERR_RET(schProcessFetchRsp(pJob, pTask, pRsp, TSDB_CODE_SUCCESS)); return TSDB_CODE_SUCCESS; diff --git a/source/libs/scheduler/src/schUtil.c b/source/libs/scheduler/src/schUtil.c index 6f12780ff932a01a3303a175ec0d2be45b0875a2..7099dbb2c0c20682ee59bb4b3b0275c2684dedca 100644 --- a/source/libs/scheduler/src/schUtil.c +++ b/source/libs/scheduler/src/schUtil.c @@ -21,21 +21,21 @@ #include "tref.h" #include "trpc.h" -FORCE_INLINE SSchJob *schAcquireJob(int64_t refId) { - qDebug("sch acquire jobId:0x%"PRIx64, refId); - return (SSchJob *)taosAcquireRef(schMgmt.jobRef, refId); +FORCE_INLINE SSchJob *schAcquireJob(int64_t refId) { + qDebug("sch acquire jobId:0x%" PRIx64, refId); + return (SSchJob *)taosAcquireRef(schMgmt.jobRef, refId); } -FORCE_INLINE int32_t schReleaseJob(int64_t refId) { +FORCE_INLINE int32_t schReleaseJob(int64_t refId) { if (0 == refId) { return TSDB_CODE_SUCCESS; } - - qDebug("sch release jobId:0x%"PRIx64, refId); - return taosReleaseRef(schMgmt.jobRef, refId); + + qDebug("sch release jobId:0x%" PRIx64, refId); + return taosReleaseRef(schMgmt.jobRef, refId); } -char* schGetOpStr(SCH_OP_TYPE type) { +char *schGetOpStr(SCH_OP_TYPE type) { switch (type) { case SCH_OP_NULL: return "NULL"; @@ -53,28 +53,28 @@ char* schGetOpStr(SCH_OP_TYPE type) { void schFreeHbTrans(SSchHbTrans *pTrans) { rpcReleaseHandle(pTrans->trans.pHandle, TAOS_CONN_CLIENT); - schFreeRpcCtx(&pTrans->rpcCtx); + schFreeRpcCtx(&pTrans->rpcCtx); } -void schCleanClusterHb(void* pTrans) { +void schCleanClusterHb(void *pTrans) { SCH_LOCK(SCH_WRITE, &schMgmt.hbLock); SSchHbTrans *hb = taosHashIterate(schMgmt.hbConnections, NULL); while (hb) { if (hb->trans.pTrans == pTrans) { - SQueryNodeEpId* pEpId = taosHashGetKey(hb, NULL); + SQueryNodeEpId *pEpId = taosHashGetKey(hb, NULL); schFreeHbTrans(hb); taosHashRemove(schMgmt.hbConnections, pEpId, sizeof(SQueryNodeEpId)); } - + hb = taosHashIterate(schMgmt.hbConnections, hb); } - + SCH_UNLOCK(SCH_WRITE, &schMgmt.hbLock); } int32_t schRemoveHbConnection(SSchJob *pJob, SSchTask *pTask, SQueryNodeEpId *epId) { - int32_t code = 0; + int32_t code = 0; SCH_LOCK(SCH_WRITE, &schMgmt.hbLock); SSchHbTrans *hb = taosHashGet(schMgmt.hbConnections, epId, sizeof(SQueryNodeEpId)); @@ -94,7 +94,6 @@ int32_t schRemoveHbConnection(SSchJob *pJob, SSchTask *pTask, SQueryNodeEpId *ep return TSDB_CODE_SUCCESS; } - int32_t schAddHbConnection(SSchJob *pJob, SSchTask *pTask, SQueryNodeEpId *epId, bool *exist) { int32_t code = 0; SSchHbTrans hb = {0}; @@ -155,13 +154,13 @@ void schDeregisterTaskHb(SSchJob *pJob, SSchTask *pTask) { if (!pTask->registerdHb) { return; } - + SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); SQueryNodeEpId epId = {0}; epId.nodeId = addr->nodeId; - SEp* pEp = SCH_GET_CUR_EP(addr); + SEp *pEp = SCH_GET_CUR_EP(addr); strcpy(epId.ep.fqdn, pEp->fqdn); epId.ep.port = pEp->port; @@ -180,24 +179,22 @@ void schDeregisterTaskHb(SSchJob *pJob, SSchTask *pTask) { } else { SCH_UNLOCK(SCH_READ, &schMgmt.hbLock); } - + pTask->registerdHb = false; } - - int32_t schEnsureHbConnection(SSchJob *pJob, SSchTask *pTask) { SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); SQueryNodeEpId epId = {0}; epId.nodeId = addr->nodeId; - SEp* pEp = SCH_GET_CUR_EP(addr); + SEp *pEp = SCH_GET_CUR_EP(addr); strcpy(epId.ep.fqdn, pEp->fqdn); epId.ep.port = pEp->port; SCH_ERR_RET(schRegisterHbConnection(pJob, pTask, &epId)); - + pTask->registerdHb = true; return TSDB_CODE_SUCCESS; @@ -226,7 +223,6 @@ int32_t schUpdateHbConnection(SQueryNodeEpId *epId, SSchTrans *trans) { return TSDB_CODE_SUCCESS; } - void schCloseJobRef(void) { if (!atomic_load_8((int8_t *)&schMgmt.exit)) { return; @@ -242,7 +238,7 @@ uint64_t schGenTaskId(void) { return atomic_add_fetch_64(&schMgmt.taskId, 1); } uint64_t schGenUUID(void) { static uint64_t hashId = 0; - static int32_t requestSerialId = 0; + static int32_t requestSerialId = 0; if (hashId == 0) { char uid[64] = {0}; @@ -254,15 +250,14 @@ uint64_t schGenUUID(void) { } } - int64_t ts = taosGetTimestampMs(); - uint64_t pid = taosGetPId(); - int32_t val = atomic_add_fetch_32(&requestSerialId, 1); + int64_t ts = taosGetTimestampMs(); + uint64_t pid = taosGetPId(); + int32_t val = atomic_add_fetch_32(&requestSerialId, 1); uint64_t id = ((hashId & 0x0FFF) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF); return id; } - void schFreeRpcCtxVal(const void *arg) { if (NULL == arg) { return; @@ -307,5 +302,3 @@ int32_t schGetTaskFromList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTas return TSDB_CODE_SUCCESS; } - - diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 0ccaef385744738969973b19a38182cbac4399d9..c4b45649a43691c737dd2b929f763d9c704dcd9d 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -14,10 +14,10 @@ */ #include "query.h" +#include "qworker.h" #include "schInt.h" #include "tmsg.h" #include "tref.h" -#include "qworker.h" SSchedulerMgmt schMgmt = { .jobRef = -1, @@ -35,7 +35,7 @@ int32_t schedulerInit() { schMgmt.cfg.enableReSchedule = true; qDebug("schedule policy init to %d", schMgmt.cfg.schPolicy); - + schMgmt.jobRef = taosOpenRef(schMgmt.cfg.maxJobNum, schFreeJobImpl); if (schMgmt.jobRef < 0) { qError("init schduler jobRef failed, num:%u", schMgmt.cfg.maxJobNum); @@ -61,7 +61,7 @@ int32_t schedulerInit() { int32_t schedulerExecJob(SSchedulerReq *pReq, int64_t *pJobId) { qDebug("scheduler %s exec job start", pReq->syncReq ? "SYNC" : "ASYNC"); - int32_t code = 0; + int32_t code = 0; SSchJob *pJob = NULL; SCH_ERR_JRET(schInitJob(pJobId, pReq)); @@ -73,7 +73,7 @@ int32_t schedulerExecJob(SSchedulerReq *pReq, int64_t *pJobId) { SCH_ERR_JRET(schSwitchJobStatus(pJob, JOB_TASK_STATUS_EXEC, pReq)); _return: - + SCH_RET(schHandleOpEndEvent(pJob, SCH_OP_EXEC, pReq, code)); } @@ -144,7 +144,7 @@ int32_t schedulerEnableReSchedule(bool enableResche) { return TSDB_CODE_SUCCESS; } -void schedulerFreeJob(int64_t* jobId, int32_t errCode) { +void schedulerFreeJob(int64_t *jobId, int32_t errCode) { if (0 == *jobId) { return; } @@ -155,10 +155,9 @@ void schedulerFreeJob(int64_t* jobId, int32_t errCode) { return; } - SCH_JOB_DLOG("start to free job 0x%" PRIx64 ", errCode:0x%x", *jobId, errCode); - + SCH_JOB_DLOG("start to free job 0x%" PRIx64 ", code:%s", *jobId, tstrerror(errCode)); schHandleJobDrop(pJob, errCode); - + schReleaseJob(*jobId); *jobId = 0; } diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index ca2122ed8f433c4b8dd70eb120e0eba972dda9fe..97e14b617c1304f7b3003e2f77e9bfee79f05d0b 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -30,15 +30,12 @@ #endif #include "os.h" -#include "tglobal.h" -#include "taos.h" -#include "tdef.h" -#include "tvariant.h" #include "catalog.h" #include "scheduler.h" #include "taos.h" #include "tdatablock.h" #include "tdef.h" +#include "tglobal.h" #include "trpc.h" #include "tvariant.h" @@ -56,8 +53,9 @@ namespace { -extern "C" int32_t schHandleResponseMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *msg, int32_t msgSize, int32_t rspCode); -extern "C" int32_t schHandleCallback(void* param, const SDataBuf* pMsg, int32_t msgType, int32_t rspCode); +extern "C" int32_t schHandleResponseMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *msg, int32_t msgSize, + int32_t rspCode); +extern "C" int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, int32_t rspCode); int64_t insertJobRefId = 0; int64_t queryJobRefId = 0; @@ -66,16 +64,15 @@ uint64_t schtMergeTemplateId = 0x4; uint64_t schtFetchTaskId = 0; uint64_t schtQueryId = 1; -bool schtTestStop = false; -bool schtTestDeadLoop = false; +bool schtTestStop = false; +bool schtTestDeadLoop = false; int32_t schtTestMTRunSec = 10; int32_t schtTestPrintNum = 1000; int32_t schtStartFetch = 0; - void schtInitLogFile() { - const char *defaultLogFileNamePrefix = "taoslog"; - const int32_t maxLogFileNum = 10; + const char *defaultLogFileNamePrefix = "taoslog"; + const int32_t maxLogFileNum = 10; tsAsyncLog = 0; qDebugFlag = 159; @@ -84,24 +81,22 @@ void schtInitLogFile() { if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) { printf("failed to open log file in directory:%s\n", tsLogDir); } - } -void schtQueryCb(SExecResult* pResult, void* param, int32_t code) { +void schtQueryCb(SExecResult *pResult, void *param, int32_t code) { assert(TSDB_CODE_SUCCESS == code); - *(int32_t*)param = 1; + *(int32_t *)param = 1; } - void schtBuildQueryDag(SQueryPlan *dag) { uint64_t qId = schtQueryId; - + dag->queryId = qId; dag->numOfSubplans = 2; dag->pSubplans = nodesMakeList(); - SNodeListNode *scan = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); - SNodeListNode *merge = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); - + SNodeListNode *scan = (SNodeListNode *)nodesMakeNode(QUERY_NODE_NODE_LIST); + SNodeListNode *merge = (SNodeListNode *)nodesMakeNode(QUERY_NODE_NODE_LIST); + SSubplan *scanPlan = (SSubplan *)taosMemoryCalloc(1, sizeof(SSubplan)); SSubplan *mergePlan = (SSubplan *)taosMemoryCalloc(1, sizeof(SSubplan)); @@ -117,7 +112,7 @@ void schtBuildQueryDag(SQueryPlan *dag) { scanPlan->pChildren = NULL; scanPlan->level = 1; scanPlan->pParents = nodesMakeList(); - scanPlan->pNode = (SPhysiNode*)taosMemoryCalloc(1, sizeof(SPhysiNode)); + scanPlan->pNode = (SPhysiNode *)taosMemoryCalloc(1, sizeof(SPhysiNode)); scanPlan->msgType = TDMT_SCH_QUERY; mergePlan->id.queryId = qId; @@ -129,32 +124,32 @@ void schtBuildQueryDag(SQueryPlan *dag) { mergePlan->pChildren = nodesMakeList(); mergePlan->pParents = NULL; - mergePlan->pNode = (SPhysiNode*)taosMemoryCalloc(1, sizeof(SPhysiNode)); + mergePlan->pNode = (SPhysiNode *)taosMemoryCalloc(1, sizeof(SPhysiNode)); mergePlan->msgType = TDMT_SCH_QUERY; merge->pNodeList = nodesMakeList(); scan->pNodeList = nodesMakeList(); - nodesListAppend(merge->pNodeList, (SNode*)mergePlan); - nodesListAppend(scan->pNodeList, (SNode*)scanPlan); + nodesListAppend(merge->pNodeList, (SNode *)mergePlan); + nodesListAppend(scan->pNodeList, (SNode *)scanPlan); - nodesListAppend(mergePlan->pChildren, (SNode*)scanPlan); - nodesListAppend(scanPlan->pParents, (SNode*)mergePlan); + nodesListAppend(mergePlan->pChildren, (SNode *)scanPlan); + nodesListAppend(scanPlan->pParents, (SNode *)mergePlan); - nodesListAppend(dag->pSubplans, (SNode*)merge); - nodesListAppend(dag->pSubplans, (SNode*)scan); + nodesListAppend(dag->pSubplans, (SNode *)merge); + nodesListAppend(dag->pSubplans, (SNode *)scan); } void schtBuildQueryFlowCtrlDag(SQueryPlan *dag) { uint64_t qId = schtQueryId; - int32_t scanPlanNum = 20; - + int32_t scanPlanNum = 20; + dag->queryId = qId; dag->numOfSubplans = 2; dag->pSubplans = nodesMakeList(); - SNodeListNode *scan = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); - SNodeListNode *merge = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); - + SNodeListNode *scan = (SNodeListNode *)nodesMakeNode(QUERY_NODE_NODE_LIST); + SNodeListNode *merge = (SNodeListNode *)nodesMakeNode(QUERY_NODE_NODE_LIST); + SSubplan *scanPlan = (SSubplan *)taosMemoryCalloc(scanPlanNum, sizeof(SSubplan)); SSubplan *mergePlan = (SSubplan *)taosMemoryCalloc(1, sizeof(SSubplan)); @@ -180,13 +175,13 @@ void schtBuildQueryFlowCtrlDag(SQueryPlan *dag) { scanPlan[i].pChildren = NULL; scanPlan[i].level = 1; scanPlan[i].pParents = nodesMakeList(); - scanPlan[i].pNode = (SPhysiNode*)taosMemoryCalloc(1, sizeof(SPhysiNode)); + scanPlan[i].pNode = (SPhysiNode *)taosMemoryCalloc(1, sizeof(SPhysiNode)); scanPlan[i].msgType = TDMT_SCH_QUERY; - nodesListAppend(scanPlan[i].pParents, (SNode*)mergePlan); - nodesListAppend(mergePlan->pChildren, (SNode*)(scanPlan + i)); + nodesListAppend(scanPlan[i].pParents, (SNode *)mergePlan); + nodesListAppend(mergePlan->pChildren, (SNode *)(scanPlan + i)); - nodesListAppend(scan->pNodeList, (SNode*)(scanPlan + i)); + nodesListAppend(scan->pNodeList, (SNode *)(scanPlan + i)); } mergePlan->id.queryId = qId; @@ -197,29 +192,25 @@ void schtBuildQueryFlowCtrlDag(SQueryPlan *dag) { mergePlan->execNode.epSet.numOfEps = 0; mergePlan->pParents = NULL; - mergePlan->pNode = (SPhysiNode*)taosMemoryCalloc(1, sizeof(SPhysiNode)); + mergePlan->pNode = (SPhysiNode *)taosMemoryCalloc(1, sizeof(SPhysiNode)); mergePlan->msgType = TDMT_SCH_QUERY; - nodesListAppend(merge->pNodeList, (SNode*)mergePlan); - - nodesListAppend(dag->pSubplans, (SNode*)merge); - nodesListAppend(dag->pSubplans, (SNode*)scan); -} - - -void schtFreeQueryDag(SQueryPlan *dag) { + nodesListAppend(merge->pNodeList, (SNode *)mergePlan); + nodesListAppend(dag->pSubplans, (SNode *)merge); + nodesListAppend(dag->pSubplans, (SNode *)scan); } +void schtFreeQueryDag(SQueryPlan *dag) {} void schtBuildInsertDag(SQueryPlan *dag) { uint64_t qId = 0x0000000000000002; - + dag->queryId = qId; dag->numOfSubplans = 2; dag->pSubplans = nodesMakeList(); - SNodeListNode *inserta = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); - + SNodeListNode *inserta = (SNodeListNode *)nodesMakeNode(QUERY_NODE_NODE_LIST); + SSubplan *insertPlan = (SSubplan *)taosMemoryCalloc(2, sizeof(SSubplan)); insertPlan[0].id.queryId = qId; @@ -235,7 +226,7 @@ void schtBuildInsertDag(SQueryPlan *dag) { insertPlan[0].pChildren = NULL; insertPlan[0].pParents = NULL; insertPlan[0].pNode = NULL; - insertPlan[0].pDataSink = (SDataSinkNode*)taosMemoryCalloc(1, sizeof(SDataSinkNode)); + insertPlan[0].pDataSink = (SDataSinkNode *)taosMemoryCalloc(1, sizeof(SDataSinkNode)); insertPlan[0].msgType = TDMT_VND_SUBMIT; insertPlan[1].id.queryId = qId; @@ -251,48 +242,43 @@ void schtBuildInsertDag(SQueryPlan *dag) { insertPlan[1].pChildren = NULL; insertPlan[1].pParents = NULL; insertPlan[1].pNode = NULL; - insertPlan[1].pDataSink = (SDataSinkNode*)taosMemoryCalloc(1, sizeof(SDataSinkNode)); + insertPlan[1].pDataSink = (SDataSinkNode *)taosMemoryCalloc(1, sizeof(SDataSinkNode)); insertPlan[1].msgType = TDMT_VND_SUBMIT; inserta->pNodeList = nodesMakeList(); - nodesListAppend(inserta->pNodeList, (SNode*)insertPlan); + nodesListAppend(inserta->pNodeList, (SNode *)insertPlan); insertPlan += 1; - nodesListAppend(inserta->pNodeList, (SNode*)insertPlan); + nodesListAppend(inserta->pNodeList, (SNode *)insertPlan); - nodesListAppend(dag->pSubplans, (SNode*)inserta); + nodesListAppend(dag->pSubplans, (SNode *)inserta); } - -int32_t schtPlanToString(const SSubplan *subplan, char** str, int32_t* len) { +int32_t schtPlanToString(const SSubplan *subplan, char **str, int32_t *len) { *str = (char *)taosMemoryCalloc(1, 20); *len = 20; return 0; } -void schtExecNode(SSubplan* subplan, uint64_t groupId, SQueryNodeAddr* ep) { +void schtExecNode(SSubplan *subplan, uint64_t groupId, SQueryNodeAddr *ep) {} -} - -void schtRpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *pRid) { - -} +void schtRpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *pRid) {} void schtSetPlanToString() { static Stub stub; stub.set(qSubPlanToString, schtPlanToString); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("qSubPlanToString", result); #endif #ifdef LINUX - AddrAny any("libplanner.so"); - std::map result; + AddrAny any("libplanner.so"); + std::map result; any.get_global_func_addr_dynsym("^qSubPlanToString$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, schtPlanToString); } } @@ -303,16 +289,16 @@ void schtSetExecNode() { stub.set(qSetSubplanExecutionNode, schtExecNode); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("qSetSubplanExecutionNode", result); #endif #ifdef LINUX - AddrAny any("libplanner.so"); - std::map result; + AddrAny any("libplanner.so"); + std::map result; any.get_global_func_addr_dynsym("^qSetSubplanExecutionNode$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, schtExecNode); } } @@ -323,22 +309,22 @@ void schtSetRpcSendRequest() { stub.set(rpcSendRequest, schtRpcSendRequest); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("rpcSendRequest", result); #endif #ifdef LINUX - AddrAny any("libtransport.so"); - std::map result; + AddrAny any("libtransport.so"); + std::map result; any.get_global_func_addr_dynsym("^rpcSendRequest$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, schtRpcSendRequest); } } } -int32_t schtAsyncSendMsgToServer(void *pTransporter, SEpSet* epSet, int64_t* pTransporterId, SMsgSendInfo* pInfo) { +int32_t schtAsyncSendMsgToServer(void *pTransporter, SEpSet *epSet, int64_t *pTransporterId, SMsgSendInfo *pInfo) { if (pInfo) { taosMemoryFreeClear(pInfo->param); taosMemoryFreeClear(pInfo->msgInfo.pData); @@ -347,32 +333,30 @@ int32_t schtAsyncSendMsgToServer(void *pTransporter, SEpSet* epSet, int64_t* pTr return 0; } - void schtSetAsyncSendMsgToServer() { static Stub stub; stub.set(asyncSendMsgToServer, schtAsyncSendMsgToServer); { #ifdef WINDOWS - AddrAny any; - std::map result; + AddrAny any; + std::map result; any.get_func_addr("asyncSendMsgToServer", result); #endif #ifdef LINUX - AddrAny any("libtransport.so"); - std::map result; + AddrAny any("libtransport.so"); + std::map result; any.get_global_func_addr_dynsym("^asyncSendMsgToServer$", result); #endif - for (const auto& f : result) { + for (const auto &f : result) { stub.set(f.second, schtAsyncSendMsgToServer); } } } - void *schtSendRsp(void *param) { SSchJob *pJob = NULL; - int64_t job = 0; - int32_t code = 0; + int64_t job = 0; + int32_t code = 0; while (true) { job = *(int64_t *)param; @@ -384,7 +368,7 @@ void *schtSendRsp(void *param) { } pJob = schAcquireJob(job); - + void *pIter = taosHashIterate(pJob->execTasks, NULL); while (pIter) { SSchTask *task = *(SSchTask **)pIter; @@ -392,9 +376,9 @@ void *schtSendRsp(void *param) { SSubmitRsp rsp = {0}; rsp.affectedRows = 10; schHandleResponseMsg(pJob, task, TDMT_VND_SUBMIT_RSP, (char *)&rsp, sizeof(rsp), 0); - + pIter = taosHashIterate(pJob->execTasks, pIter); - } + } schReleaseJob(job); @@ -402,28 +386,27 @@ void *schtSendRsp(void *param) { } void *schtCreateFetchRspThread(void *param) { - int64_t job = *(int64_t *)param; - SSchJob* pJob = schAcquireJob(job); + int64_t job = *(int64_t *)param; + SSchJob *pJob = schAcquireJob(job); taosSsleep(1); - int32_t code = 0; + int32_t code = 0; SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, sizeof(SRetrieveTableRsp)); rsp->completed = 1; rsp->numOfRows = 10; - + code = schHandleResponseMsg(pJob, pJob->fetchTask, TDMT_SCH_FETCH_RSP, (char *)rsp, sizeof(*rsp), 0); schReleaseJob(job); - + assert(code == 0); return NULL; } - void *schtFetchRspThread(void *aa) { - SDataBuf dataBuf = {0}; - SSchTaskCallbackParam* param = NULL; + SDataBuf dataBuf = {0}; + SSchTaskCallbackParam *param = NULL; while (!schtTestStop) { if (0 == atomic_val_compare_exchange_32(&schtStartFetch, 1, 0)) { @@ -431,13 +414,13 @@ void *schtFetchRspThread(void *aa) { } taosUsleep(1); - + param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param)); - param->queryId = schtQueryId; + param->queryId = schtQueryId; param->taskId = schtFetchTaskId; - int32_t code = 0; + int32_t code = 0; SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, sizeof(SRetrieveTableRsp)); rsp->completed = 1; rsp->numOfRows = 10; @@ -446,7 +429,7 @@ void *schtFetchRspThread(void *aa) { dataBuf.len = sizeof(*rsp); code = schHandleCallback(param, &dataBuf, TDMT_SCH_FETCH_RSP, 0); - + assert(code == 0 || code); } return NULL; @@ -454,8 +437,8 @@ void *schtFetchRspThread(void *aa) { void schtFreeQueryJob(int32_t freeThread) { static uint32_t freeNum = 0; - int64_t job = queryJobRefId; - + int64_t job = queryJobRefId; + if (job && atomic_val_compare_exchange_64(&queryJobRefId, job, 0)) { schedulerFreeJob(&job, 0); if (freeThread) { @@ -466,31 +449,29 @@ void schtFreeQueryJob(int32_t freeThread) { } } -void* schtRunJobThread(void *aa) { - void *mockPointer = (void *)0x1; - char *clusterId = "cluster1"; - char *dbname = "1.db1"; - char *tablename = "table1"; +void *schtRunJobThread(void *aa) { + void *mockPointer = (void *)0x1; + char *clusterId = "cluster1"; + char *dbname = "1.db1"; + char *tablename = "table1"; SVgroupInfo vgInfo = {0}; - SQueryPlan dag; + SQueryPlan dag; schtInitLogFile(); - int32_t code = schedulerInit(); assert(code == 0); - schtSetPlanToString(); schtSetExecNode(); schtSetAsyncSendMsgToServer(); - SSchJob *pJob = NULL; + SSchJob *pJob = NULL; SSchTaskCallbackParam *param = NULL; - SHashObj *execTasks = NULL; - SDataBuf dataBuf = {0}; - uint32_t jobFinished = 0; - int32_t queryDone = 0; + SHashObj *execTasks = NULL; + SDataBuf dataBuf = {0}; + uint32_t jobFinished = 0; + int32_t queryDone = 0; while (!schtTestStop) { schtBuildQueryDag(&dag); @@ -503,10 +484,10 @@ void* schtRunJobThread(void *aa) { taosArrayPush(qnodeList, &qnodeAddr); queryDone = 0; - + SRequestConnInfo conn = {0}; conn.pTrans = mockPointer; - SSchedulerReq req = {0}; + SSchedulerReq req = {0}; req.syncReq = false; req.pConn = &conn; req.pNodeList = qnodeList; @@ -514,8 +495,8 @@ void* schtRunJobThread(void *aa) { req.sql = "select * from tb"; req.execFp = schtQueryCb; req.cbParam = &queryDone; - - code = schedulerExecJob(&req, &queryJobRefId); + + code = schedulerExecJob(&req, &queryJobRefId); assert(code == 0); pJob = schAcquireJob(queryJobRefId); @@ -524,20 +505,20 @@ void* schtRunJobThread(void *aa) { schtFreeQueryDag(&dag); continue; } - + execTasks = taosHashInit(5, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); void *pIter = taosHashIterate(pJob->execTasks, NULL); while (pIter) { SSchTask *task = *(SSchTask **)pIter; schtFetchTaskId = task->taskId - 1; - + taosHashPut(execTasks, &task->taskId, sizeof(task->taskId), task, sizeof(*task)); pIter = taosHashIterate(pJob->execTasks, pIter); - } + } param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param)); param->refId = queryJobRefId; - param->queryId = pJob->queryId; + param->queryId = pJob->queryId; pIter = taosHashIterate(execTasks, NULL); while (pIter) { @@ -547,16 +528,16 @@ void* schtRunJobThread(void *aa) { SQueryTableRsp rsp = {0}; dataBuf.pData = &rsp; dataBuf.len = sizeof(rsp); - + code = schHandleCallback(param, &dataBuf, TDMT_SCH_QUERY_RSP, 0); assert(code == 0 || code); pIter = taosHashIterate(execTasks, pIter); - } + } param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param)); param->refId = queryJobRefId; - param->queryId = pJob->queryId; + param->queryId = pJob->queryId; pIter = taosHashIterate(execTasks, NULL); while (pIter) { @@ -566,28 +547,27 @@ void* schtRunJobThread(void *aa) { SQueryTableRsp rsp = {0}; dataBuf.pData = &rsp; dataBuf.len = sizeof(rsp); - + code = schHandleCallback(param, &dataBuf, TDMT_SCH_QUERY_RSP, 0); assert(code == 0 || code); - - pIter = taosHashIterate(execTasks, pIter); - } + pIter = taosHashIterate(execTasks, pIter); + } while (true) { if (queryDone) { break; } - + taosUsleep(10000); } atomic_store_32(&schtStartFetch, 1); - void *data = NULL; + void *data = NULL; req.syncReq = true; req.pFetchRes = &data; - + code = schedulerFetchRows(queryJobRefId, &req); assert(code == 0 || code); @@ -600,7 +580,7 @@ void* schtRunJobThread(void *aa) { data = NULL; code = schedulerFetchRows(queryJobRefId, &req); assert(code == 0 || code); - + schtFreeQueryJob(0); taosHashCleanup(execTasks); @@ -620,7 +600,7 @@ void* schtRunJobThread(void *aa) { return NULL; } -void* schtFreeJobThread(void *aa) { +void *schtFreeJobThread(void *aa) { while (!schtTestStop) { taosUsleep(taosRand() % 100); schtFreeQueryJob(1); @@ -628,17 +608,16 @@ void* schtFreeJobThread(void *aa) { return NULL; } - -} +} // namespace TEST(queryTest, normalCase) { - void *mockPointer = (void *)0x1; - char *clusterId = "cluster1"; - char *dbname = "1.db1"; - char *tablename = "table1"; + void *mockPointer = (void *)0x1; + char *clusterId = "cluster1"; + char *dbname = "1.db1"; + char *tablename = "table1"; SVgroupInfo vgInfo = {0}; - int64_t job = 0; - SQueryPlan dag; + int64_t job = 0; + SQueryPlan dag; memset(&dag, 0, sizeof(dag)); @@ -648,7 +627,7 @@ TEST(queryTest, normalCase) { strcpy(qnodeAddr.fqdn, "qnode0.ep"); qnodeAddr.port = 6031; taosArrayPush(qnodeList, &qnodeAddr); - + int32_t code = schedulerInit(); ASSERT_EQ(code, 0); @@ -662,30 +641,29 @@ TEST(queryTest, normalCase) { SRequestConnInfo conn = {0}; conn.pTrans = mockPointer; - SSchedulerReq req = {0}; + SSchedulerReq req = {0}; req.pConn = &conn; req.pNodeList = qnodeList; req.pDag = &dag; req.sql = "select * from tb"; req.execFp = schtQueryCb; req.cbParam = &queryDone; - - code = schedulerExecJob(&req, &job); + + code = schedulerExecJob(&req, &job); ASSERT_EQ(code, 0); - SSchJob *pJob = schAcquireJob(job); - + void *pIter = taosHashIterate(pJob->execTasks, NULL); while (pIter) { SSchTask *task = *(SSchTask **)pIter; SQueryTableRsp rsp = {0}; code = schHandleResponseMsg(pJob, task, TDMT_SCH_QUERY_RSP, (char *)&rsp, sizeof(rsp), 0); - + ASSERT_EQ(code, 0); pIter = taosHashIterate(pJob->execTasks, pIter); - } + } pIter = taosHashIterate(pJob->execTasks, NULL); while (pIter) { @@ -693,10 +671,10 @@ TEST(queryTest, normalCase) { SQueryTableRsp rsp = {0}; code = schHandleResponseMsg(pJob, task, TDMT_SCH_QUERY_RSP, (char *)&rsp, sizeof(rsp), 0); - + ASSERT_EQ(code, 0); pIter = taosHashIterate(pJob->execTasks, pIter); - } + } while (true) { if (queryDone) { @@ -705,14 +683,14 @@ TEST(queryTest, normalCase) { taosUsleep(10000); } - + TdThreadAttr thattr; taosThreadAttrInit(&thattr); TdThread thread1; taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job); - void *data = NULL; + void *data = NULL; req.syncReq = true; req.pFetchRes = &data; @@ -739,13 +717,13 @@ TEST(queryTest, normalCase) { } TEST(queryTest, readyFirstCase) { - void *mockPointer = (void *)0x1; - char *clusterId = "cluster1"; - char *dbname = "1.db1"; - char *tablename = "table1"; + void *mockPointer = (void *)0x1; + char *clusterId = "cluster1"; + char *dbname = "1.db1"; + char *tablename = "table1"; SVgroupInfo vgInfo = {0}; - int64_t job = 0; - SQueryPlan dag; + int64_t job = 0; + SQueryPlan dag; memset(&dag, 0, sizeof(dag)); @@ -755,7 +733,7 @@ TEST(queryTest, readyFirstCase) { strcpy(qnodeAddr.fqdn, "qnode0.ep"); qnodeAddr.port = 6031; taosArrayPush(qnodeList, &qnodeAddr); - + int32_t code = schedulerInit(); ASSERT_EQ(code, 0); @@ -765,11 +743,11 @@ TEST(queryTest, readyFirstCase) { schtSetExecNode(); schtSetAsyncSendMsgToServer(); - int32_t queryDone = 0; + int32_t queryDone = 0; SRequestConnInfo conn = {0}; conn.pTrans = mockPointer; - SSchedulerReq req = {0}; + SSchedulerReq req = {0}; req.pConn = &conn; req.pNodeList = qnodeList; req.pDag = &dag; @@ -779,19 +757,18 @@ TEST(queryTest, readyFirstCase) { code = schedulerExecJob(&req, &job); ASSERT_EQ(code, 0); - SSchJob *pJob = schAcquireJob(job); - + void *pIter = taosHashIterate(pJob->execTasks, NULL); while (pIter) { SSchTask *task = *(SSchTask **)pIter; SQueryTableRsp rsp = {0}; code = schHandleResponseMsg(pJob, task, TDMT_SCH_QUERY_RSP, (char *)&rsp, sizeof(rsp), 0); - + ASSERT_EQ(code, 0); pIter = taosHashIterate(pJob->execTasks, pIter); - } + } pIter = taosHashIterate(pJob->execTasks, NULL); while (pIter) { @@ -799,10 +776,10 @@ TEST(queryTest, readyFirstCase) { SQueryTableRsp rsp = {0}; code = schHandleResponseMsg(pJob, task, TDMT_SCH_QUERY_RSP, (char *)&rsp, sizeof(rsp), 0); - + ASSERT_EQ(code, 0); pIter = taosHashIterate(pJob->execTasks, pIter); - } + } while (true) { if (queryDone) { @@ -812,14 +789,13 @@ TEST(queryTest, readyFirstCase) { taosUsleep(10000); } - TdThreadAttr thattr; taosThreadAttrInit(&thattr); TdThread thread1; taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job); - void *data = NULL; + void *data = NULL; req.syncReq = true; req.pFetchRes = &data; code = schedulerFetchRows(job, &req); @@ -844,28 +820,26 @@ TEST(queryTest, readyFirstCase) { schedulerDestroy(); } - - TEST(queryTest, flowCtrlCase) { - void *mockPointer = (void *)0x1; - char *clusterId = "cluster1"; - char *dbname = "1.db1"; - char *tablename = "table1"; + void *mockPointer = (void *)0x1; + char *clusterId = "cluster1"; + char *dbname = "1.db1"; + char *tablename = "table1"; SVgroupInfo vgInfo = {0}; - int64_t job = 0; - SQueryPlan dag; + int64_t job = 0; + SQueryPlan dag; schtInitLogFile(); taosSeedRand(taosGetTimestampSec()); - + SArray *qnodeList = taosArrayInit(1, sizeof(SEp)); SEp qnodeAddr = {0}; strcpy(qnodeAddr.fqdn, "qnode0.ep"); qnodeAddr.port = 6031; taosArrayPush(qnodeList, &qnodeAddr); - + int32_t code = schedulerInit(); ASSERT_EQ(code, 0); @@ -875,10 +849,10 @@ TEST(queryTest, flowCtrlCase) { schtSetExecNode(); schtSetAsyncSendMsgToServer(); - int32_t queryDone = 0; + int32_t queryDone = 0; SRequestConnInfo conn = {0}; conn.pTrans = mockPointer; - SSchedulerReq req = {0}; + SSchedulerReq req = {0}; req.pConn = &conn; req.pNodeList = qnodeList; req.pDag = &dag; @@ -889,17 +863,16 @@ TEST(queryTest, flowCtrlCase) { code = schedulerExecJob(&req, &job); ASSERT_EQ(code, 0); - SSchJob *pJob = schAcquireJob(job); bool qDone = false; - + while (!qDone) { void *pIter = taosHashIterate(pJob->execTasks, NULL); if (NULL == pIter) { break; } - + while (pIter) { SSchTask *task = *(SSchTask **)pIter; @@ -908,15 +881,15 @@ TEST(queryTest, flowCtrlCase) { if (task->lastMsgType == TDMT_SCH_QUERY) { SQueryTableRsp rsp = {0}; code = schHandleResponseMsg(pJob, task, TDMT_SCH_QUERY_RSP, (char *)&rsp, sizeof(rsp), 0); - + ASSERT_EQ(code, 0); } else { qDone = true; break; } - + pIter = NULL; - } + } } while (true) { @@ -933,7 +906,7 @@ TEST(queryTest, flowCtrlCase) { TdThread thread1; taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job); - void *data = NULL; + void *data = NULL; req.syncReq = true; req.pFetchRes = &data; code = schedulerFetchRows(job, &req); @@ -958,15 +931,14 @@ TEST(queryTest, flowCtrlCase) { schedulerDestroy(); } - TEST(insertTest, normalCase) { - void *mockPointer = (void *)0x1; - char *clusterId = "cluster1"; - char *dbname = "1.db1"; - char *tablename = "table1"; + void *mockPointer = (void *)0x1; + char *clusterId = "cluster1"; + char *dbname = "1.db1"; + char *tablename = "table1"; SVgroupInfo vgInfo = {0}; - SQueryPlan dag; - uint64_t numOfRows = 0; + SQueryPlan dag; + uint64_t numOfRows = 0; SArray *qnodeList = taosArrayInit(1, sizeof(SEp)); @@ -974,7 +946,7 @@ TEST(insertTest, normalCase) { strcpy(qnodeAddr.fqdn, "qnode0.ep"); qnodeAddr.port = 6031; taosArrayPush(qnodeList, &qnodeAddr); - + int32_t code = schedulerInit(); ASSERT_EQ(code, 0); @@ -993,21 +965,21 @@ TEST(insertTest, normalCase) { SRequestConnInfo conn = {0}; conn.pTrans = mockPointer; - SSchedulerReq req = {0}; + SSchedulerReq req = {0}; req.pConn = &conn; req.pNodeList = qnodeList; req.pDag = &dag; req.sql = "insert into tb values(now,1)"; req.execFp = schtQueryCb; req.cbParam = NULL; - + code = schedulerExecJob(&req, &insertJobRefId); ASSERT_EQ(code, 0); ASSERT_EQ(res.numOfRows, 20); schedulerFreeJob(&insertJobRefId, 0); - schedulerDestroy(); + schedulerDestroy(); } TEST(multiThread, forceFree) { @@ -1027,12 +999,12 @@ TEST(multiThread, forceFree) { break; } } - + schtTestStop = true; taosSsleep(3); } -int main(int argc, char** argv) { +int main(int argc, char **argv) { taosSeedRand(taosGetTimestampSec()); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/source/libs/stream/src/stream.c b/source/libs/stream/src/stream.c index 4a63cd3bb28cdbb31ad4f2ca7531787fccb7e7d4..ee317d0751c90f4f63669a228ce35f640b5bde1b 100644 --- a/source/libs/stream/src/stream.c +++ b/source/libs/stream/src/stream.c @@ -67,7 +67,11 @@ void streamSchedByTimer(void* param, void* tmrId) { atomic_store_8(&pTask->triggerStatus, TASK_TRIGGER_STATUS__INACTIVE); - streamTaskInput(pTask, (SStreamQueueItem*)trigger); + if (streamTaskInput(pTask, (SStreamQueueItem*)trigger) < 0) { + taosFreeQitem(trigger); + taosTmrReset(streamSchedByTimer, (int32_t)pTask->triggerParam, pTask, streamEnv.timer, &pTask->timer); + return; + } streamSchedExec(pTask); } diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index 63a28e17ed7461d8b0eb95c8eece7f31f0f43710..53e49a6ba5e0be669329c5ff6414c3648ee14fb3 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -28,6 +28,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF sprintf(streamPath, "%s/%s", path, "stream"); pMeta->path = strdup(streamPath); if (tdbOpen(pMeta->path, 16 * 1024, 1, &pMeta->db) < 0) { + taosMemoryFree(streamPath); goto _err; } @@ -58,7 +59,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF return pMeta; _err: - if (pMeta->path) taosMemoryFree(pMeta->path); + taosMemoryFree(pMeta->path); if (pMeta->pTasks) taosHashCleanup(pMeta->pTasks); if (pMeta->pTaskDb) tdbTbClose(pMeta->pTaskDb); if (pMeta->pCheckpointDb) tdbTbClose(pMeta->pCheckpointDb); @@ -250,6 +251,8 @@ int32_t streamLoadTasks(SStreamMeta* pMeta) { while (tdbTbcNext(pCur, &pKey, &kLen, &pVal, &vLen) == 0) { SStreamTask* pTask = taosMemoryCalloc(1, sizeof(SStreamTask)); if (pTask == NULL) { + tdbFree(pKey); + tdbFree(pVal); return -1; } tDecoderInit(&decoder, (uint8_t*)pVal, vLen); @@ -257,10 +260,14 @@ int32_t streamLoadTasks(SStreamMeta* pMeta) { tDecoderClear(&decoder); if (pMeta->expandFunc(pMeta->ahandle, pTask) < 0) { + tdbFree(pKey); + tdbFree(pVal); return -1; } if (taosHashPut(pMeta->pTasks, &pTask->taskId, sizeof(int32_t), &pTask, sizeof(void*)) < 0) { + tdbFree(pKey); + tdbFree(pVal); return -1; } } diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c index 85592881cd9b160077fa6d8c8ada783db6ef6cfd..c0ed135d74343395be1147fa72d012e032cd1f2b 100644 --- a/source/libs/stream/src/streamState.c +++ b/source/libs/stream/src/streamState.c @@ -49,7 +49,9 @@ static inline int stateKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, return 0; } -SStreamState* streamStateOpen(char* path, SStreamTask* pTask, bool specPath) { +SStreamState* streamStateOpen(char* path, SStreamTask* pTask, bool specPath, int32_t szPage, int32_t pages) { + szPage = szPage < 0 ? 4096 : szPage; + pages = pages < 0 ? 256 : pages; SStreamState* pState = taosMemoryCalloc(1, sizeof(SStreamState)); if (pState == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -61,9 +63,9 @@ SStreamState* streamStateOpen(char* path, SStreamTask* pTask, bool specPath) { sprintf(statePath, "%s/%d", path, pTask->taskId); } else { memset(statePath, 0, 300); - strncpy(statePath, path, 300); + tstrncpy(statePath, path, 300); } - if (tdbOpen(statePath, 4096, 256, &pState->db) < 0) { + if (tdbOpen(statePath, szPage, pages, &pState->db) < 0) { goto _err; } diff --git a/source/libs/stream/src/streamUpdate.c b/source/libs/stream/src/streamUpdate.c index 332f7ad2fd7be60f532b1394eb2d72adf985b82a..5aadb599a30b0df5cc2b89608ea0afcfb79298c1 100644 --- a/source/libs/stream/src/streamUpdate.c +++ b/source/libs/stream/src/streamUpdate.c @@ -174,13 +174,9 @@ bool updateInfoIsUpdated(SUpdateInfo *pInfo, uint64_t tableId, TSKEY ts) { if (res == TSDB_CODE_SUCCESS) { return false; } else { - qDebug("===stream===Update close window sbf. tableId:%" PRIu64 ", maxTs:%" PRIu64 ", mapMaxTs:%" PRIu64 ", ts:%" PRIu64, tableId, - maxTs, *pMapMaxTs, ts); return true; } } - qDebug("===stream===Update close window. tableId:%" PRIu64 ", maxTs:%" PRIu64 ", mapMaxTs:%" PRIu64 ", ts:%" PRIu64, tableId, - maxTs, *pMapMaxTs, ts); return true; } @@ -202,14 +198,10 @@ bool updateInfoIsUpdated(SUpdateInfo *pInfo, uint64_t tableId, TSKEY ts) { } if (ts < pInfo->minTS) { - qDebug("===stream===Update min ts. tableId:%" PRIu64 ", maxTs:%" PRIu64 ", mapMaxTs:%" PRIu64 ", ts:%" PRIu64, tableId, - maxTs, *pMapMaxTs, ts); return true; } else if (res == TSDB_CODE_SUCCESS) { return false; } - qDebug("===stream===Update. tableId:%" PRIu64 ", maxTs:%" PRIu64 ", mapMaxTs:%" PRIu64 ", ts:%" PRIu64, tableId, - maxTs, *pMapMaxTs, ts); // check from tsdb api return true; } diff --git a/source/libs/stream/test/tstreamUpdateTest.cpp b/source/libs/stream/test/tstreamUpdateTest.cpp index 933549b8a6b423bc5a3a497ecdbee13ffc7fb448..adfd7cf87675cc18020bdfaa99fa69e6cc3ca00d 100644 --- a/source/libs/stream/test/tstreamUpdateTest.cpp +++ b/source/libs/stream/test/tstreamUpdateTest.cpp @@ -4,17 +4,17 @@ #include "ttime.h" using namespace std; -#define MAX_NUM_SCALABLE_BF 100000 +#define MAX_NUM_SCALABLE_BF 100000 -bool equalSBF(SScalableBf* left, SScalableBf* right) { +bool equalSBF(SScalableBf *left, SScalableBf *right) { if (left->growth != right->growth) return false; if (left->numBits != right->numBits) return false; int lsize = taosArrayGetSize(left->bfArray); int rsize = taosArrayGetSize(right->bfArray); if (lsize != rsize) return false; for (int32_t i = 0; i < lsize; i++) { - SBloomFilter* pLeftBF = (SBloomFilter*)taosArrayGetP(left->bfArray, i); - SBloomFilter* pRightBF = (SBloomFilter*)taosArrayGetP(right->bfArray, i); + SBloomFilter *pLeftBF = (SBloomFilter *)taosArrayGetP(left->bfArray, i); + SBloomFilter *pRightBF = (SBloomFilter *)taosArrayGetP(right->bfArray, i); if (pLeftBF->errorRate != pRightBF->errorRate) return false; if (pLeftBF->expectedEntries != pRightBF->expectedEntries) return false; if (pLeftBF->hashFn1 != pRightBF->hashFn1) return false; @@ -23,8 +23,8 @@ bool equalSBF(SScalableBf* left, SScalableBf* right) { if (pLeftBF->numBits != pRightBF->numBits) return false; if (pLeftBF->numUnits != pRightBF->numUnits) return false; if (pLeftBF->size != pRightBF->size) return false; - uint64_t* leftUint = (uint64_t*) pLeftBF->buffer; - uint64_t* rightUint = (uint64_t*) pRightBF->buffer; + uint64_t *leftUint = (uint64_t *)pLeftBF->buffer; + uint64_t *rightUint = (uint64_t *)pRightBF->buffer; for (int32_t j = 0; j < pLeftBF->numUnits; j++) { if (leftUint[j] != rightUint[j]) return false; } @@ -35,86 +35,86 @@ bool equalSBF(SScalableBf* left, SScalableBf* right) { TEST(TD_STREAM_UPDATE_TEST, update) { const int64_t interval = 20 * 1000; const int64_t watermark = 10 * 60 * 1000; - SUpdateInfo *pSU = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark); - GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,1, 0), false); - GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,1, -1), true); + SUpdateInfo *pSU = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark); + GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU, 1, 0), false); + GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU, 1, -1), true); - for(int i=0; i < 1024; i++) { - GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,i, 1), false); + for (int i = 0; i < 1024; i++) { + GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU, i, 1), false); } - for(int i=0; i < 1024; i++) { - GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,i, 1), true); + for (int i = 0; i < 1024; i++) { + GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU, i, 1), true); } - for(int i=0; i < 1024; i++) { - GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,i, 2), false); + for (int i = 0; i < 1024; i++) { + GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU, i, 2), false); } - for(int i=0; i < 1024; i++) { - GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,i, 2), true); + for (int i = 0; i < 1024; i++) { + GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU, i, 2), true); } - for(int i=0; i < 1024; i++) { - GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,i, 1), true); + for (int i = 0; i < 1024; i++) { + GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU, i, 1), true); } TSKEY uid = 0; - for(int i=3; i < 1024; i++) { + for (int i = 3; i < 1024; i++) { GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU, uid, i), false); } - GTEST_ASSERT_EQ(*(TSKEY*)taosHashGet(pSU->pMap, &uid, sizeof(uint64_t)), 1023); + GTEST_ASSERT_EQ(*(TSKEY *)taosHashGet(pSU->pMap, &uid, sizeof(uint64_t)), 1023); - for(int i=3; i < 1024; i++) { + for (int i = 3; i < 1024; i++) { GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU, uid, i), true); } - GTEST_ASSERT_EQ(*(TSKEY*)taosHashGet(pSU->pMap, &uid, sizeof(uint64_t)), 1023); + GTEST_ASSERT_EQ(*(TSKEY *)taosHashGet(pSU->pMap, &uid, sizeof(uint64_t)), 1023); SUpdateInfo *pSU1 = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark); - for(int i=1; i <= watermark / interval; i++) { + for (int i = 1; i <= watermark / interval; i++) { GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU1, 1, i * interval + 5), false); GTEST_ASSERT_EQ(pSU1->minTS, interval); GTEST_ASSERT_EQ(pSU1->numSBFs, watermark / interval); } - for(int i=0; i < pSU1->numSBFs; i++) { - SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU1->pTsSBFs, i); + for (int i = 0; i < pSU1->numSBFs; i++) { + SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU1->pTsSBFs, i); SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF->bfArray, 0); GTEST_ASSERT_EQ(pBF->size, 1); } - for(int i= watermark / interval + 1, j = 2 ; i <= watermark / interval + 10; i++,j++) { + for (int i = watermark / interval + 1, j = 2; i <= watermark / interval + 10; i++, j++) { GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU1, 1, i * interval + 5), false); - GTEST_ASSERT_EQ(pSU1->minTS, interval*j); + GTEST_ASSERT_EQ(pSU1->minTS, interval * j); GTEST_ASSERT_EQ(pSU1->numSBFs, watermark / interval); - SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU1->pTsSBFs, pSU1->numSBFs - 1); + SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU1->pTsSBFs, pSU1->numSBFs - 1); SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF->bfArray, 0); GTEST_ASSERT_EQ(pBF->size, 1); } - - for(int i= watermark / interval * 100, j = 0; j < 10; i+= (watermark / interval * 2), j++) { + + for (int i = watermark / interval * 100, j = 0; j < 10; i += (watermark / interval * 2), j++) { GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU1, 1, i * interval + 5), false); - GTEST_ASSERT_EQ(pSU1->minTS, (i-(pSU1->numSBFs-1))*interval); + GTEST_ASSERT_EQ(pSU1->minTS, (i - (pSU1->numSBFs - 1)) * interval); GTEST_ASSERT_EQ(pSU1->numSBFs, watermark / interval); } SUpdateInfo *pSU2 = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark); GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU2, 1, 1 * interval + 5), false); GTEST_ASSERT_EQ(pSU2->minTS, interval); - for(int i= watermark / interval * 100, j = 0; j < 10; i+= (watermark / interval * 10), j++) { + for (int i = watermark / interval * 100, j = 0; j < 10; i += (watermark / interval * 10), j++) { GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU2, 1, i * interval + 5), false); - GTEST_ASSERT_EQ(pSU2->minTS, (i-(pSU2->numSBFs-1))*interval); + GTEST_ASSERT_EQ(pSU2->minTS, (i - (pSU2->numSBFs - 1)) * interval); GTEST_ASSERT_EQ(pSU2->numSBFs, watermark / interval); TSKEY uid2 = 1; - GTEST_ASSERT_EQ(*(TSKEY*)taosHashGet(pSU2->pMap, &uid2, sizeof(uint64_t)), i * interval + 5); + GTEST_ASSERT_EQ(*(TSKEY *)taosHashGet(pSU2->pMap, &uid2, sizeof(uint64_t)), i * interval + 5); } - + SUpdateInfo *pSU3 = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark); - for(int j = 1; j < 100; j++) { - for(int i = 0; i < pSU3->numSBFs; i++) { + for (int j = 1; j < 100; j++) { + for (int i = 0; i < pSU3->numSBFs; i++) { GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU3, i, i * interval + 5 * j), false); GTEST_ASSERT_EQ(pSU3->minTS, 0); GTEST_ASSERT_EQ(pSU3->numSBFs, watermark / interval); uint64_t uid3 = i; - GTEST_ASSERT_EQ(*(TSKEY*)taosHashGet(pSU3->pMap, &uid3, sizeof(uint64_t)), i * interval + 5 * j); - SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU3->pTsSBFs, i); + GTEST_ASSERT_EQ(*(TSKEY *)taosHashGet(pSU3->pMap, &uid3, sizeof(uint64_t)), i * interval + 5 * j); + SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU3->pTsSBFs, i); SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF->bfArray, 0); GTEST_ASSERT_EQ(pBF->size, j); } @@ -130,19 +130,19 @@ TEST(TD_STREAM_UPDATE_TEST, update) { SUpdateInfo *pSU7 = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark); updateInfoAddCloseWindowSBF(pSU7); - for(int64_t i = 1; i < 2048000; i++) { - GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU7,i, i), false); + for (int64_t i = 1; i < 2048000; i++) { + GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU7, i, i), false); } - GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU7,100, 1), true); - GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU7,110, 10), true); - GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU7,200, 20), true); + GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU7, 100, 1), true); + GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU7, 110, 10), true); + GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU7, 200, 20), true); int32_t bufLen = updateInfoSerialize(NULL, 0, pSU7); - void* buf = taosMemoryCalloc(1, bufLen); + void *buf = taosMemoryCalloc(1, bufLen); int32_t resSize = updateInfoSerialize(buf, bufLen, pSU7); SUpdateInfo *pSU6 = updateInfoInit(0, TSDB_TIME_PRECISION_MILLI, 0); - int32_t desSize = updateInfoDeserialize(buf, bufLen, pSU6); + int32_t desSize = updateInfoDeserialize(buf, bufLen, pSU6); GTEST_ASSERT_EQ(desSize, 0); GTEST_ASSERT_EQ(pSU7->interval, pSU6->interval); @@ -150,7 +150,7 @@ TEST(TD_STREAM_UPDATE_TEST, update) { GTEST_ASSERT_EQ(pSU7->minTS, pSU6->minTS); GTEST_ASSERT_EQ(pSU7->numBuckets, pSU6->numBuckets); GTEST_ASSERT_EQ(pSU7->numSBFs, pSU6->numSBFs); - GTEST_ASSERT_EQ(pSU7->scanGroupId, pSU6->scanGroupId); + GTEST_ASSERT_EQ(pSU7->scanGroupId, pSU6->scanGroupId); GTEST_ASSERT_EQ(pSU7->scanWindow.ekey, pSU6->scanWindow.ekey); GTEST_ASSERT_EQ(pSU7->scanWindow.skey, pSU6->scanWindow.skey); GTEST_ASSERT_EQ(pSU7->watermark, pSU6->watermark); @@ -158,27 +158,27 @@ TEST(TD_STREAM_UPDATE_TEST, update) { int32_t mapSize = taosHashGetSize(pSU7->pMap); GTEST_ASSERT_EQ(mapSize, taosHashGetSize(pSU6->pMap)); - void* pIte = NULL; + void *pIte = NULL; size_t keyLen = 0; while ((pIte = taosHashIterate(pSU7->pMap, pIte)) != NULL) { - void* key = taosHashGetKey(pIte, &keyLen); - void* value6 = taosHashGet(pSU6->pMap, key, keyLen); - GTEST_ASSERT_EQ(*(TSKEY*)pIte, *(TSKEY*)value6); + void *key = taosHashGetKey(pIte, &keyLen); + void *value6 = taosHashGet(pSU6->pMap, key, keyLen); + GTEST_ASSERT_EQ(*(TSKEY *)pIte, *(TSKEY *)value6); } int32_t buSize = taosArrayGetSize(pSU7->pTsBuckets); GTEST_ASSERT_EQ(buSize, taosArrayGetSize(pSU6->pTsBuckets)); for (int32_t i = 0; i < buSize; i++) { - TSKEY ts1 = *(TSKEY*)taosArrayGet(pSU7->pTsBuckets, i); - TSKEY ts2 = *(TSKEY*)taosArrayGet(pSU6->pTsBuckets, i); + TSKEY ts1 = *(TSKEY *)taosArrayGet(pSU7->pTsBuckets, i); + TSKEY ts2 = *(TSKEY *)taosArrayGet(pSU6->pTsBuckets, i); GTEST_ASSERT_EQ(ts1, ts2); } int32_t lSize = taosArrayGetSize(pSU7->pTsSBFs); int32_t rSize = taosArrayGetSize(pSU6->pTsSBFs); GTEST_ASSERT_EQ(lSize, rSize); for (int32_t i = 0; i < lSize; i++) { - SScalableBf* pLeftSBF = (SScalableBf*)taosArrayGetP(pSU7->pTsSBFs, i); - SScalableBf* pRightSBF = (SScalableBf*)taosArrayGetP(pSU6->pTsSBFs, i); + SScalableBf *pLeftSBF = (SScalableBf *)taosArrayGetP(pSU7->pTsSBFs, i); + SScalableBf *pRightSBF = (SScalableBf *)taosArrayGetP(pSU6->pTsSBFs, i); GTEST_ASSERT_EQ(equalSBF(pLeftSBF, pRightSBF), true); } @@ -190,10 +190,9 @@ TEST(TD_STREAM_UPDATE_TEST, update) { updateInfoDestroy(pSU5); updateInfoDestroy(pSU6); updateInfoDestroy(pSU7); - } -int main(int argc, char* argv[]) { +int main(int argc, char *argv[]) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } \ No newline at end of file diff --git a/source/libs/sync/inc/syncIO.h b/source/libs/sync/inc/syncIO.h index f3064e668df575d51dbd1efc333e373543522de1..68d2334101b3e9bff70b7e77c2fcbfaf84fa8d57 100644 --- a/source/libs/sync/inc/syncIO.h +++ b/source/libs/sync/inc/syncIO.h @@ -29,15 +29,15 @@ extern "C" { #include "tqueue.h" #include "trpc.h" -#define TICK_Q_TIMER_MS 1000 +#define TICK_Q_TIMER_MS 1000 #define TICK_Ping_TIMER_MS 1000 typedef struct SSyncIO { STaosQueue *pMsgQ; - STaosQset * pQset; + STaosQset *pQset; TdThread consumerTid; - void * serverRpc; - void * clientRpc; + void *serverRpc; + void *clientRpc; SEpSet myAddr; SMsgCb msgcb; diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index 0afc373f2d0d90333002245e43817d12ef02df8c..101e99afea8db60011fa535a53320a32c2dd376c 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -169,7 +169,7 @@ typedef struct SSyncNode { } SSyncNode; // open/close -------------- -SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo); +SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo); void syncNodeStart(SSyncNode* pSyncNode); void syncNodeStartStandBy(SSyncNode* pSyncNode); void syncNodeClose(SSyncNode* pSyncNode); diff --git a/source/libs/sync/inc/syncRaftStore.h b/source/libs/sync/inc/syncRaftStore.h index e0cbcf074458f90e861a27ca4a0a1c026ed0fa03..ac298c537510e77982bc2edc1d6f026dc16e7f95 100644 --- a/source/libs/sync/inc/syncRaftStore.h +++ b/source/libs/sync/inc/syncRaftStore.h @@ -28,7 +28,7 @@ extern "C" { #include "taosdef.h" #define RAFT_STORE_BLOCK_SIZE 512 -#define RAFT_STORE_PATH_LEN (TSDB_FILENAME_LEN * 2) +#define RAFT_STORE_PATH_LEN (TSDB_FILENAME_LEN * 2) typedef struct SRaftStore { SyncTerm currentTerm; @@ -49,8 +49,8 @@ void raftStoreClearVote(SRaftStore *pRaftStore); void raftStoreNextTerm(SRaftStore *pRaftStore); void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term); int32_t raftStoreFromJson(SRaftStore *pRaftStore, cJSON *pJson); -cJSON * raftStore2Json(SRaftStore *pRaftStore); -char * raftStore2Str(SRaftStore *pRaftStore); +cJSON *raftStore2Json(SRaftStore *pRaftStore); +char *raftStore2Str(SRaftStore *pRaftStore); // for debug ------------------- void raftStorePrint(SRaftStore *pObj); diff --git a/source/libs/sync/inc/syncVoteMgr.h b/source/libs/sync/inc/syncVoteMgr.h index 716d2f620c09bdf0b842f7661e5f238d2821644f..aa245ce32c20a02ea450581daed949076704e446 100644 --- a/source/libs/sync/inc/syncVoteMgr.h +++ b/source/libs/sync/inc/syncVoteMgr.h @@ -46,8 +46,8 @@ void voteGrantedUpdate(SVotesGranted *pVotesGranted, SSyncNode *pSyncN bool voteGrantedMajority(SVotesGranted *pVotesGranted); void voteGrantedVote(SVotesGranted *pVotesGranted, SyncRequestVoteReply *pMsg); void voteGrantedReset(SVotesGranted *pVotesGranted, SyncTerm term); -cJSON * voteGranted2Json(SVotesGranted *pVotesGranted); -char * voteGranted2Str(SVotesGranted *pVotesGranted); +cJSON *voteGranted2Json(SVotesGranted *pVotesGranted); +char *voteGranted2Str(SVotesGranted *pVotesGranted); // for debug ------------------- void voteGrantedPrint(SVotesGranted *pObj); @@ -70,8 +70,8 @@ void votesRespondUpdate(SVotesRespond *pVotesRespond, SSyncNode *pSync bool votesResponded(SVotesRespond *pVotesRespond, const SRaftId *pRaftId); void votesRespondAdd(SVotesRespond *pVotesRespond, const SyncRequestVoteReply *pMsg); void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term); -cJSON * votesRespond2Json(SVotesRespond *pVotesRespond); -char * votesRespond2Str(SVotesRespond *pVotesRespond); +cJSON *votesRespond2Json(SVotesRespond *pVotesRespond); +char *votesRespond2Str(SVotesRespond *pVotesRespond); // for debug ------------------- void votesRespondPrint(SVotesRespond *pObj); diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index e000ba8bf869454a0276411d7312190be98348b9..4a35a15d3e35189daa291094c575e35d05ed8e02 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -579,6 +579,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc SSyncRaftEntry* pAppendEntry = (SSyncRaftEntry*)(pMsg->data + metaTableArr[i].offset); code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); if (code != 0) { + sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); return -1; } @@ -710,6 +711,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc SSyncRaftEntry* pAppendEntry = (SSyncRaftEntry*)(pMsg->data + metaTableArr[i].offset); code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); if (code != 0) { + sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); return -1; } @@ -859,6 +861,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); if (code != 0) { + sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); return -1; } @@ -974,6 +977,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); if (code != 0) { + sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); return -1; } diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index b604d25816e300560571458fde7153196e77eee5..511113352ea07625b3cbf223add13d2c807ddbac 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -76,7 +76,10 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { pEntry = (SSyncRaftEntry*)taosLRUCacheValue(pCache, h); } else { pEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, index); - ASSERT(pEntry != NULL); + if (pEntry == NULL) { + sError("failed to get entry since %s. index:%lld", tstrerror(terrno), index); + return; + } } // cannot commit, even if quorum agree. need check term! if (pEntry->term <= pSyncNode->pRaftStore->currentTerm) { @@ -127,7 +130,9 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { // execute fsm if (pSyncNode->pFsm != NULL) { int32_t code = syncNodeCommit(pSyncNode, beginIndex, endIndex, pSyncNode->state); - ASSERT(code == 0); + if (code != 0) { + wError("failed to commit sync node since %s", tstrerror(terrno)); + } } } } diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c index b00be6edb6a6b9473ea1483a4bb508033151f313..e9899a3e33701d425b85878cfa1253e111e3964c 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/src/syncIO.c @@ -30,7 +30,7 @@ static int32_t syncIODestroy(SSyncIO *io); static int32_t syncIOStartInternal(SSyncIO *io); static int32_t syncIOStopInternal(SSyncIO *io); -static void * syncIOConsumerFunc(void *param); +static void *syncIOConsumerFunc(void *param); static void syncIOProcessRequest(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet); static void syncIOProcessReply(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet); static int32_t syncIOAuth(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey); @@ -242,9 +242,9 @@ static int32_t syncIOStopInternal(SSyncIO *io) { } static void *syncIOConsumerFunc(void *param) { - SSyncIO * io = param; + SSyncIO *io = param; STaosQall *qall = taosAllocateQall(); - SRpcMsg * pRpcMsg, rpcMsg; + SRpcMsg *pRpcMsg, rpcMsg; SQueueInfo qinfo = {0}; while (1) { diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 76fd345bdd1226a960c13c94de9d86ea7d954f1e..907eb21f4c84a4b26169ef81beb9d272d1a14bce 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -52,9 +52,9 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg); int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg); // --------------------------------- -static void syncNodeFreeCb(void *param) { - syncNodeClose(param); - param = NULL; +static void syncNodeFreeCb(void* param) { + syncNodeClose(param); + param = NULL; } int32_t syncInit() { @@ -86,10 +86,10 @@ void syncCleanUp() { } } -int64_t syncOpen(const SSyncInfo* pSyncInfo) { +int64_t syncOpen(SSyncInfo* pSyncInfo) { SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo); if (pSyncNode == NULL) { - sError("failed to open sync node. vgId:%d", pSyncInfo->vgId); + sError("vgId:%d, failed to open sync node since %s", pSyncInfo->vgId, terrstr()); return -1; } @@ -230,7 +230,7 @@ int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg return ret; } -int32_t syncReconfig(int64_t rid, const SSyncCfg* pNewCfg) { +int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) { SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { terrno = TSDB_CODE_SYN_INTERNAL_ERROR; @@ -238,6 +238,7 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg* pNewCfg) { } ASSERT(rid == pSyncNode->rid); +#if 0 if (!syncNodeCheckNewConfig(pSyncNode, pNewCfg)) { taosReleaseRef(tsNodeRefId, pSyncNode->rid); terrno = TSDB_CODE_SYN_NEW_CONFIG_ERROR; @@ -259,6 +260,12 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg* pNewCfg) { taosReleaseRef(tsNodeRefId, pSyncNode->rid); return ret; +#else + syncNodeUpdateNewConfigIndex(pSyncNode, pNewCfg); + syncNodeDoConfigChange(pSyncNode, pNewCfg, SYNC_INDEX_INVALID); + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return 0; +#endif } int32_t syncLeaderTransfer(int64_t rid) { @@ -919,9 +926,7 @@ _END: } // open/close -------------- -SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { - SSyncInfo* pSyncInfo = (SSyncInfo*)pOldSyncInfo; - +SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { SSyncNode* pSyncNode = (SSyncNode*)taosMemoryCalloc(1, sizeof(SSyncNode)); if (pSyncNode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -947,17 +952,19 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { meta.batchSize = pSyncInfo->batchSize; ret = raftCfgCreateFile((SSyncCfg*)&(pSyncInfo->syncCfg), meta, pSyncNode->configPath); if (ret != 0) { - sError("failed to create raft cfg file. configPath: %s", pSyncNode->configPath); - goto _error; + sError("failed to create raft cfg file. configPath: %s", pSyncNode->configPath); + goto _error; } } else { // update syncCfg by raft_config.json pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath); if (pSyncNode->pRaftCfg == NULL) { - sError("failed to open raft cfg file. path:%s", pSyncNode->configPath); - goto _error; + sError("failed to open raft cfg file. path:%s", pSyncNode->configPath); + goto _error; + } + if (pSyncInfo->syncCfg.replicaNum == 0) { + pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg; } - pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg; raftCfgClose(pSyncNode->pRaftCfg); pSyncNode->pRaftCfg = NULL; @@ -985,8 +992,8 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { // init internal pSyncNode->myNodeInfo = pSyncNode->pRaftCfg->cfg.nodeInfo[pSyncNode->pRaftCfg->cfg.myIndex]; if (!syncUtilnodeInfo2raftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId)) { - sError("failed to determine my raft member id. vgId:%d", pSyncNode->vgId); - goto _error; + sError("failed to determine my raft member id. vgId:%d", pSyncNode->vgId); + goto _error; } // init peersNum, peers, peersId @@ -1000,17 +1007,17 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { } for (int i = 0; i < pSyncNode->peersNum; ++i) { if (!syncUtilnodeInfo2raftId(&pSyncNode->peersNodeInfo[i], pSyncNode->vgId, &pSyncNode->peersId[i])) { - sError("failed to determine raft member id. vgId:%d, peer:%d", pSyncNode->vgId, i); - goto _error; + sError("failed to determine raft member id. vgId:%d, peer:%d", pSyncNode->vgId, i); + goto _error; } } // init replicaNum, replicasId pSyncNode->replicaNum = pSyncNode->pRaftCfg->cfg.replicaNum; for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { - if(!syncUtilnodeInfo2raftId(&pSyncNode->pRaftCfg->cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i])) { - sError("failed to determine raft member id. vgId:%d, replica:%d", pSyncNode->vgId, i); - goto _error; + if (!syncUtilnodeInfo2raftId(&pSyncNode->pRaftCfg->cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i])) { + sError("failed to determine raft member id. vgId:%d, replica:%d", pSyncNode->vgId, i); + goto _error; } } @@ -1090,8 +1097,8 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { SSnapshot snapshot = {0}; int32_t code = pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); if (code != 0) { - sError("failed to get snapshot info. vgId:%d, code:%d", pSyncNode->vgId, code); - goto _error; + sError("failed to get snapshot info. vgId:%d, code:%d", pSyncNode->vgId, code); + goto _error; } if (snapshot.lastApplyIndex > commitIndex) { commitIndex = snapshot.lastApplyIndex; @@ -1191,8 +1198,8 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { _error: if (pSyncInfo->pFsm) { - taosMemoryFree(pSyncInfo->pFsm); - pSyncInfo->pFsm = NULL; + taosMemoryFree(pSyncInfo->pFsm); + pSyncInfo->pFsm = NULL; } syncNodeClose(pSyncNode); pSyncNode = NULL; @@ -2650,7 +2657,10 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) { if (ths->state == TAOS_SYNC_STATE_LEADER) { int32_t code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry); - ASSERT(code == 0); + if (code != 0) { + sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); + return -1; + } syncNodeReplicate(ths, false); } @@ -2726,7 +2736,7 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry); if (code != 0) { // del resp mgr, call FpCommitCb - ASSERT(0); + sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); return -1; } @@ -2790,8 +2800,8 @@ int32_t syncNodeOnClientRequestBatchCb(SSyncNode* ths, SyncClientRequestBatch* p code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry); if (code != 0) { + sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno)); // del resp mgr, call FpCommitCb - ASSERT(0); return -1; } @@ -3043,7 +3053,10 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, pEntry = (SSyncRaftEntry*)taosLRUCacheValue(pCache, h); } else { code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, i, &pEntry); - ASSERT(code == 0); + if (code != 0) { + sError("vgId:%d, failed to get log entry since %s. index:%lld", ths->vgId, tstrerror(terrno), i); + return -1; + } ASSERT(pEntry != NULL); } diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index 496c8419de7f56a96d544997f989ef6d16de4de3..c3dad104d1629cf127a1eae5034fdf0844930e74 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -234,8 +234,6 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", pEntry->index, err, err, errStr, sysErr, sysErrStr); syncNodeErrorLog(pData->pSyncNode, logBuf); - - ASSERT(0); return -1; } pEntry->index = index; @@ -414,13 +412,11 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { return 0; } -SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { +SSyncRaftEntry* logStoreGetEntryWithoutLock(SSyncLogStore* pLogStore, SyncIndex index) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; if (index >= SYNC_INDEX_BEGIN && index <= logStoreLastIndex(pLogStore)) { - taosThreadMutexLock(&(pData->mutex)); - // SWalReadHandle* pWalHandle = walOpenReadHandle(pWal); SWalReader* pWalHandle = pData->pWalHandle; ASSERT(pWalHandle != NULL); @@ -444,7 +440,8 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { } } while (0); - ASSERT(0); + sError("failed to read ver since %s. index:%lld", tstrerror(terrno), index); + return NULL; } SSyncRaftEntry* pEntry = syncEntryBuild(pWalHandle->pHead->head.bodyLen); @@ -465,7 +462,6 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { terrno = saveErr; */ - taosThreadMutexUnlock(&(pData->mutex)); return pEntry; } else { @@ -473,6 +469,16 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { } } +SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { + SSyncLogStoreData* pData = pLogStore->data; + SSyncRaftEntry *pEntry = NULL; + + taosThreadMutexLock(&pData->mutex); + pEntry = logStoreGetEntryWithoutLock(pLogStore, index); + taosThreadMutexUnlock(&pData->mutex); + return pEntry; +} + int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index 22b47a2c45e14216b1554c9e606f2d66b1d07b5e..6d4d54a9b1708fb5db6eac81df1addc2536b8cfb 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -218,7 +218,7 @@ cJSON *raftStore2Json(SRaftStore *pRaftStore) { char *raftStore2Str(SRaftStore *pRaftStore) { cJSON *pJson = raftStore2Json(pRaftStore); - char * serialized = cJSON_Print(pJson); + char *serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index 68d81813ac760a37b78bfdc12aee59624b296c48..6167d41141735e1800848a989e1d3a0b75454e41 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -36,8 +36,8 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI if (condition) { pSender = taosMemoryMalloc(sizeof(SSyncSnapshotSender)); if (pSender == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; } memset(pSender, 0, sizeof(*pSender)); diff --git a/source/libs/sync/src/syncVoteMgr.c b/source/libs/sync/src/syncVoteMgr.c index 641bb32d2d56a0bf745c6cb4c5fb43ccaaaa6f75..09b79825d04f83ebe8e729b362fd05f95d3b24a4 100644 --- a/source/libs/sync/src/syncVoteMgr.c +++ b/source/libs/sync/src/syncVoteMgr.c @@ -130,7 +130,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) { char *voteGranted2Str(SVotesGranted *pVotesGranted) { cJSON *pJson = voteGranted2Json(pVotesGranted); - char * serialized = cJSON_Print(pJson); + char *serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -259,7 +259,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) { char *votesRespond2Str(SVotesRespond *pVotesRespond) { cJSON *pJson = votesRespond2Json(pVotesRespond); - char * serialized = cJSON_Print(pJson); + char *serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } diff --git a/source/libs/sync/test/syncAppendEntriesReplyTest.cpp b/source/libs/sync/test/syncAppendEntriesReplyTest.cpp index 72d3fd5ef34d83d9a2db7c674abd58a989bfed3e..a5e96233c24bf7746bec6330958a2cfe12621f70 100644 --- a/source/libs/sync/test/syncAppendEntriesReplyTest.cpp +++ b/source/libs/sync/test/syncAppendEntriesReplyTest.cpp @@ -37,7 +37,7 @@ void test1() { void test2() { SyncAppendEntriesReply *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncAppendEntriesReplySerialize(pMsg, serialized, len); SyncAppendEntriesReply *pMsg2 = syncAppendEntriesReplyBuild(1000); syncAppendEntriesReplyDeserialize(serialized, len, pMsg2); @@ -52,7 +52,7 @@ void test2() { void test3() { SyncAppendEntriesReply *pMsg = createMsg(); uint32_t len; - char * serialized = syncAppendEntriesReplySerialize2(pMsg, &len); + char *serialized = syncAppendEntriesReplySerialize2(pMsg, &len); SyncAppendEntriesReply *pMsg2 = syncAppendEntriesReplyDeserialize2(serialized, len); syncAppendEntriesReplyLog2((char *)"test3: syncAppendEntriesReplySerialize3 -> syncAppendEntriesReplyDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncAppendEntriesTest.cpp b/source/libs/sync/test/syncAppendEntriesTest.cpp index 98b392274ec86937a6e4c6e99f130d9973d7a33a..256c13e26749b432f627d90f814661566fbf9d21 100644 --- a/source/libs/sync/test/syncAppendEntriesTest.cpp +++ b/source/libs/sync/test/syncAppendEntriesTest.cpp @@ -37,7 +37,7 @@ void test1() { void test2() { SyncAppendEntries *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncAppendEntriesSerialize(pMsg, serialized, len); SyncAppendEntries *pMsg2 = syncAppendEntriesBuild(pMsg->dataLen, 1000); syncAppendEntriesDeserialize(serialized, len, pMsg2); @@ -51,7 +51,7 @@ void test2() { void test3() { SyncAppendEntries *pMsg = createMsg(); uint32_t len; - char * serialized = syncAppendEntriesSerialize2(pMsg, &len); + char *serialized = syncAppendEntriesSerialize2(pMsg, &len); SyncAppendEntries *pMsg2 = syncAppendEntriesDeserialize2(serialized, len); syncAppendEntriesLog2((char *)"test3: syncAppendEntriesSerialize3 -> syncAppendEntriesDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncApplyMsgTest.cpp b/source/libs/sync/test/syncApplyMsgTest.cpp index 30019f71e5d6ffa327a0e3fd2731883397c9ec7b..9d5e7dd8e1de635ea5cbc64352eb25bafa40d99d 100644 --- a/source/libs/sync/test/syncApplyMsgTest.cpp +++ b/source/libs/sync/test/syncApplyMsgTest.cpp @@ -43,7 +43,7 @@ void test1() { void test2() { SyncApplyMsg *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncApplyMsgSerialize(pMsg, serialized, len); SyncApplyMsg *pMsg2 = syncApplyMsgBuild(pMsg->dataLen); syncApplyMsgDeserialize(serialized, len, pMsg2); @@ -57,7 +57,7 @@ void test2() { void test3() { SyncApplyMsg *pMsg = createMsg(); uint32_t len; - char * serialized = syncApplyMsgSerialize2(pMsg, &len); + char *serialized = syncApplyMsgSerialize2(pMsg, &len); SyncApplyMsg *pMsg2 = syncApplyMsgDeserialize2(serialized, len); syncApplyMsgLog2((char *)"test3: syncApplyMsgSerialize2 -> syncApplyMsgDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncClientRequestBatchTest.cpp b/source/libs/sync/test/syncClientRequestBatchTest.cpp index 84d037be01028167584bfcaf912fc090540c0c7e..5586b7a6ce55c8f4f6aa6aebbd5c295e6562e1d4 100644 --- a/source/libs/sync/test/syncClientRequestBatchTest.cpp +++ b/source/libs/sync/test/syncClientRequestBatchTest.cpp @@ -33,7 +33,7 @@ SyncClientRequestBatch *createMsg() { for (int32_t i = 0; i < 5; ++i) { SRpcMsg *pRpcMsg = createRpcMsg(i, 20); rpcMsgPArr[i] = pRpcMsg; - //taosMemoryFree(pRpcMsg); + // taosMemoryFree(pRpcMsg); } SRaftMeta raftArr[5]; diff --git a/source/libs/sync/test/syncClientRequestTest.cpp b/source/libs/sync/test/syncClientRequestTest.cpp index 9376aca91f8c31a2133f6e860568ffd4f3ba5072..56e53cc1c93bbb5d024797c47936d10bf8fa8a3b 100644 --- a/source/libs/sync/test/syncClientRequestTest.cpp +++ b/source/libs/sync/test/syncClientRequestTest.cpp @@ -35,7 +35,7 @@ void test1() { void test2() { SyncClientRequest *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncClientRequestSerialize(pMsg, serialized, len); SyncClientRequest *pMsg2 = syncClientRequestBuild(pMsg->dataLen); syncClientRequestDeserialize(serialized, len, pMsg2); @@ -49,7 +49,7 @@ void test2() { void test3() { SyncClientRequest *pMsg = createMsg(); uint32_t len; - char * serialized = syncClientRequestSerialize2(pMsg, &len); + char *serialized = syncClientRequestSerialize2(pMsg, &len); SyncClientRequest *pMsg2 = syncClientRequestDeserialize2(serialized, len); syncClientRequestLog2((char *)"test3: syncClientRequestSerialize3 -> syncClientRequestDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp index fbfc4cda8eb01de93b8d50c3002b1d59c97faaa9..c523fbc1c3115b2c27c0dd48b2f08cffc234c18c 100644 --- a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp +++ b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp @@ -149,7 +149,7 @@ 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) { +void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta) { sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64, cbMeta->flag, cbMeta->index, cbMeta->code, cbMeta->currentTerm, cbMeta->term); } diff --git a/source/libs/sync/test/syncConfigChangeTest.cpp b/source/libs/sync/test/syncConfigChangeTest.cpp index cfab3b6ae37133155cc8b2de91edf44abd33a76c..c04ab9b000e1f595d03838e36e555eff9541c08f 100644 --- a/source/libs/sync/test/syncConfigChangeTest.cpp +++ b/source/libs/sync/test/syncConfigChangeTest.cpp @@ -80,7 +80,7 @@ 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) { +void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta) { sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64, cbMeta->flag, cbMeta->index, cbMeta->code, cbMeta->currentTerm, cbMeta->term); } diff --git a/source/libs/sync/test/syncEncodeTest.cpp b/source/libs/sync/test/syncEncodeTest.cpp index 454c823c6a501ac0cb2532892159957056d7e1fa..4016f0744201e69aaab2531ab4e64932327b4df0 100644 --- a/source/libs/sync/test/syncEncodeTest.cpp +++ b/source/libs/sync/test/syncEncodeTest.cpp @@ -25,8 +25,8 @@ int32_t myIndex = 0; SRaftId ids[TSDB_MAX_REPLICA]; SSyncInfo syncInfo; -SSyncFSM * pFsm; -SWal * pWal; +SSyncFSM *pFsm; +SWal *pWal; SSyncNode *pSyncNode; SSyncNode *syncNodeInit() { @@ -187,8 +187,8 @@ int main(int argc, char **argv) { // step5 uint32_t len; - char * pMsg5 = step5(pMsg4, &len); - char * s = syncUtilprintBin(pMsg5, len); + char *pMsg5 = step5(pMsg4, &len); + char *s = syncUtilprintBin(pMsg5, len); printf("==step5== [%s] \n", s); taosMemoryFree(s); diff --git a/source/libs/sync/test/syncHeartbeatReplyTest.cpp b/source/libs/sync/test/syncHeartbeatReplyTest.cpp index 0ccd7b70bb8f552fa14c0a615993abbab678a8a0..f5519fe6d4bd4870813937eaaddab088ec3889ca 100644 --- a/source/libs/sync/test/syncHeartbeatReplyTest.cpp +++ b/source/libs/sync/test/syncHeartbeatReplyTest.cpp @@ -35,13 +35,12 @@ void test1() { void test2() { SyncHeartbeatReply *pMsg = createMsg(); - uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + uint32_t len = pMsg->bytes; + char *serialized = (char *)taosMemoryMalloc(len); syncHeartbeatReplySerialize(pMsg, serialized, len); SyncHeartbeatReply *pMsg2 = syncHeartbeatReplyBuild(1000); syncHeartbeatReplyDeserialize(serialized, len, pMsg2); - syncHeartbeatReplyLog2((char *)"test2: syncHeartbeatReplySerialize -> syncHeartbeatReplyDeserialize ", - pMsg2); + syncHeartbeatReplyLog2((char *)"test2: syncHeartbeatReplySerialize -> syncHeartbeatReplyDeserialize ", pMsg2); taosMemoryFree(serialized); syncHeartbeatReplyDestroy(pMsg); @@ -50,11 +49,10 @@ void test2() { void test3() { SyncHeartbeatReply *pMsg = createMsg(); - uint32_t len; - char * serialized = syncHeartbeatReplySerialize2(pMsg, &len); + uint32_t len; + char *serialized = syncHeartbeatReplySerialize2(pMsg, &len); SyncHeartbeatReply *pMsg2 = syncHeartbeatReplyDeserialize2(serialized, len); - syncHeartbeatReplyLog2((char *)"test3: syncHeartbeatReplySerialize3 -> syncHeartbeatReplyDeserialize2 ", - pMsg2); + syncHeartbeatReplyLog2((char *)"test3: syncHeartbeatReplySerialize3 -> syncHeartbeatReplyDeserialize2 ", pMsg2); taosMemoryFree(serialized); syncHeartbeatReplyDestroy(pMsg); @@ -63,12 +61,11 @@ void test3() { void test4() { SyncHeartbeatReply *pMsg = createMsg(); - SRpcMsg rpcMsg; + SRpcMsg rpcMsg; syncHeartbeatReply2RpcMsg(pMsg, &rpcMsg); SyncHeartbeatReply *pMsg2 = syncHeartbeatReplyBuild(1000); syncHeartbeatReplyFromRpcMsg(&rpcMsg, pMsg2); - syncHeartbeatReplyLog2((char *)"test4: syncHeartbeatReply2RpcMsg -> syncHeartbeatReplyFromRpcMsg ", - pMsg2); + syncHeartbeatReplyLog2((char *)"test4: syncHeartbeatReply2RpcMsg -> syncHeartbeatReplyFromRpcMsg ", pMsg2); rpcFreeCont(rpcMsg.pCont); syncHeartbeatReplyDestroy(pMsg); @@ -77,11 +74,10 @@ void test4() { void test5() { SyncHeartbeatReply *pMsg = createMsg(); - SRpcMsg rpcMsg; + SRpcMsg rpcMsg; syncHeartbeatReply2RpcMsg(pMsg, &rpcMsg); SyncHeartbeatReply *pMsg2 = syncHeartbeatReplyFromRpcMsg2(&rpcMsg); - syncHeartbeatReplyLog2((char *)"test5: syncHeartbeatReply2RpcMsg -> syncHeartbeatReplyFromRpcMsg2 ", - pMsg2); + syncHeartbeatReplyLog2((char *)"test5: syncHeartbeatReply2RpcMsg -> syncHeartbeatReplyFromRpcMsg2 ", pMsg2); rpcFreeCont(rpcMsg.pCont); syncHeartbeatReplyDestroy(pMsg); diff --git a/source/libs/sync/test/syncHeartbeatTest.cpp b/source/libs/sync/test/syncHeartbeatTest.cpp index d910c828f1e13f4e6484c7b8ad7ea6758f626750..577af33b9c2587ceff1412e499fbc9670d7e98a1 100644 --- a/source/libs/sync/test/syncHeartbeatTest.cpp +++ b/source/libs/sync/test/syncHeartbeatTest.cpp @@ -19,7 +19,7 @@ SyncHeartbeat *createMsg() { pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234); pMsg->srcId.vgId = 100; pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678); - pMsg->destId.vgId = 100; + pMsg->destId.vgId = 100; pMsg->term = 8; pMsg->commitIndex = 33; pMsg->privateTerm = 44; @@ -34,8 +34,8 @@ void test1() { void test2() { SyncHeartbeat *pMsg = createMsg(); - uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + uint32_t len = pMsg->bytes; + char *serialized = (char *)taosMemoryMalloc(len); syncHeartbeatSerialize(pMsg, serialized, len); SyncHeartbeat *pMsg2 = syncHeartbeatBuild(789); syncHeartbeatDeserialize(serialized, len, pMsg2); @@ -48,8 +48,8 @@ void test2() { void test3() { SyncHeartbeat *pMsg = createMsg(); - uint32_t len; - char * serialized = syncHeartbeatSerialize2(pMsg, &len); + uint32_t len; + char *serialized = syncHeartbeatSerialize2(pMsg, &len); SyncHeartbeat *pMsg2 = syncHeartbeatDeserialize2(serialized, len); syncHeartbeatLog2((char *)"test3: syncHeartbeatSerialize2 -> syncHeartbeatDeserialize2 ", pMsg2); @@ -60,7 +60,7 @@ void test3() { void test4() { SyncHeartbeat *pMsg = createMsg(); - SRpcMsg rpcMsg; + SRpcMsg rpcMsg; syncHeartbeat2RpcMsg(pMsg, &rpcMsg); SyncHeartbeat *pMsg2 = (SyncHeartbeat *)taosMemoryMalloc(rpcMsg.contLen); syncHeartbeatFromRpcMsg(&rpcMsg, pMsg2); @@ -73,9 +73,9 @@ void test4() { void test5() { SyncHeartbeat *pMsg = createMsg(); - SRpcMsg rpcMsg; + SRpcMsg rpcMsg; syncHeartbeat2RpcMsg(pMsg, &rpcMsg); - SyncHeartbeat *pMsg2 =syncHeartbeatFromRpcMsg2(&rpcMsg); + SyncHeartbeat *pMsg2 = syncHeartbeatFromRpcMsg2(&rpcMsg); syncHeartbeatLog2((char *)"test5: syncHeartbeat2RpcMsg -> syncHeartbeatFromRpcMsg2 ", pMsg2); rpcFreeCont(rpcMsg.pCont); diff --git a/source/libs/sync/test/syncIndexTest.cpp b/source/libs/sync/test/syncIndexTest.cpp index 91c7800756a05495942f33a1adcc02fba65502b6..93cd5f79f07ab5da62f0255b2b7409b43547b9a3 100644 --- a/source/libs/sync/test/syncIndexTest.cpp +++ b/source/libs/sync/test/syncIndexTest.cpp @@ -9,7 +9,7 @@ void print(SHashObj *pNextIndex) { uint64_t *p = (uint64_t *)taosHashIterate(pNextIndex, NULL); while (p) { size_t len; - void * key = taosHashGetKey(p, &len); + void *key = taosHashGetKey(p, &len); SRaftId *pRaftId = (SRaftId *)key; diff --git a/source/libs/sync/test/syncLeaderTransferTest.cpp b/source/libs/sync/test/syncLeaderTransferTest.cpp index 1c3891d49219a142b532246fa36e36e631095568..62a9106c159123545f412d7040619af64c5a7ef2 100644 --- a/source/libs/sync/test/syncLeaderTransferTest.cpp +++ b/source/libs/sync/test/syncLeaderTransferTest.cpp @@ -36,7 +36,7 @@ void test1() { void test2() { SyncLeaderTransfer *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncLeaderTransferSerialize(pMsg, serialized, len); SyncLeaderTransfer *pMsg2 = syncLeaderTransferBuild(1000); syncLeaderTransferDeserialize(serialized, len, pMsg2); @@ -50,7 +50,7 @@ void test2() { void test3() { SyncLeaderTransfer *pMsg = createMsg(); uint32_t len; - char * serialized = syncLeaderTransferSerialize2(pMsg, &len); + char *serialized = syncLeaderTransferSerialize2(pMsg, &len); SyncLeaderTransfer *pMsg2 = syncLeaderTransferDeserialize2(serialized, len); syncLeaderTransferLog2((char *)"test3: syncLeaderTransferSerialize2 -> syncLeaderTransferDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncPingReplyTest.cpp b/source/libs/sync/test/syncPingReplyTest.cpp index 2bd8671e6c8dbd7bb2e7b5f3f97c13cc46f8213f..e5158a7932f63cf50399727e03e6f49274d5d0ad 100644 --- a/source/libs/sync/test/syncPingReplyTest.cpp +++ b/source/libs/sync/test/syncPingReplyTest.cpp @@ -33,7 +33,7 @@ void test1() { void test2() { SyncPingReply *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncPingReplySerialize(pMsg, serialized, len); SyncPingReply *pMsg2 = syncPingReplyBuild(pMsg->dataLen); syncPingReplyDeserialize(serialized, len, pMsg2); @@ -47,7 +47,7 @@ void test2() { void test3() { SyncPingReply *pMsg = createMsg(); uint32_t len; - char * serialized = syncPingReplySerialize2(pMsg, &len); + char *serialized = syncPingReplySerialize2(pMsg, &len); SyncPingReply *pMsg2 = syncPingReplyDeserialize2(serialized, len); syncPingReplyLog2((char *)"test3: syncPingReplySerialize2 -> syncPingReplyDeserialize2 ", pMsg2); @@ -84,7 +84,7 @@ void test5() { void test6() { SyncPingReply *pMsg = createMsg(); int32_t bufLen = syncPingReplySerialize3(pMsg, NULL, 0); - char * serialized = (char *)taosMemoryMalloc(bufLen); + char *serialized = (char *)taosMemoryMalloc(bufLen); syncPingReplySerialize3(pMsg, serialized, bufLen); SyncPingReply *pMsg2 = syncPingReplyDeserialize3(serialized, bufLen); assert(pMsg2 != NULL); diff --git a/source/libs/sync/test/syncPingTest.cpp b/source/libs/sync/test/syncPingTest.cpp index a02f5e4b43b177b618e4150ad96423dd23236af0..1777b9b9e2c494b25fd8b5af99f9335d82d09b5d 100644 --- a/source/libs/sync/test/syncPingTest.cpp +++ b/source/libs/sync/test/syncPingTest.cpp @@ -33,7 +33,7 @@ void test1() { void test2() { SyncPing *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncPingSerialize(pMsg, serialized, len); SyncPing *pMsg2 = syncPingBuild(pMsg->dataLen); syncPingDeserialize(serialized, len, pMsg2); @@ -47,7 +47,7 @@ void test2() { void test3() { SyncPing *pMsg = createMsg(); uint32_t len; - char * serialized = syncPingSerialize2(pMsg, &len); + char *serialized = syncPingSerialize2(pMsg, &len); SyncPing *pMsg2 = syncPingDeserialize2(serialized, len); syncPingLog2((char *)"test3: syncPingSerialize2 -> syncPingDeserialize2 ", pMsg2); @@ -84,7 +84,7 @@ void test5() { void test6() { SyncPing *pMsg = createMsg(); int32_t bufLen = syncPingSerialize3(pMsg, NULL, 0); - char * serialized = (char *)taosMemoryMalloc(bufLen); + char *serialized = (char *)taosMemoryMalloc(bufLen); syncPingSerialize3(pMsg, serialized, bufLen); SyncPing *pMsg2 = syncPingDeserialize3(serialized, bufLen); assert(pMsg2 != NULL); diff --git a/source/libs/sync/test/syncRaftCfgIndexTest.cpp b/source/libs/sync/test/syncRaftCfgIndexTest.cpp index 6338383f92ceac88549753a415a5c7ba729c976f..bd8ffc45b6bcaf5780aa6f7a5331316cc37224fe 100644 --- a/source/libs/sync/test/syncRaftCfgIndexTest.cpp +++ b/source/libs/sync/test/syncRaftCfgIndexTest.cpp @@ -53,20 +53,20 @@ SSyncCfg* createSyncCfg() { return pCfg; } -const char *pFile = "./raft_config_index.json"; +const char* pFile = "./raft_config_index.json"; void test1() { int32_t code = raftCfgIndexCreateFile(pFile); ASSERT(code == 0); - SRaftCfgIndex *pRaftCfgIndex = raftCfgIndexOpen(pFile); + SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile); raftCfgIndexLog2((char*)"==test1==", pRaftCfgIndex); raftCfgIndexClose(pRaftCfgIndex); } void test2() { - SRaftCfgIndex *pRaftCfgIndex = raftCfgIndexOpen(pFile); + SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile); for (int i = 0; i < 500; ++i) { raftCfgIndexAddConfigIndex(pRaftCfgIndex, i); } @@ -77,7 +77,7 @@ void test2() { } void test3() { - SRaftCfgIndex *pRaftCfgIndex = raftCfgIndexOpen(pFile); + SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile); raftCfgIndexLog2((char*)"==test3==", pRaftCfgIndex); raftCfgIndexClose(pRaftCfgIndex); diff --git a/source/libs/sync/test/syncReconfigFinishTest.cpp b/source/libs/sync/test/syncReconfigFinishTest.cpp index 2aac38bbd1c71effe2662fa90b5cdfff3fa2db19..5b283c5829464891e6a2529a1b038bd2a1501c48 100644 --- a/source/libs/sync/test/syncReconfigFinishTest.cpp +++ b/source/libs/sync/test/syncReconfigFinishTest.cpp @@ -69,7 +69,7 @@ void test1() { void test2() { SyncReconfigFinish *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncReconfigFinishSerialize(pMsg, serialized, len); SyncReconfigFinish *pMsg2 = syncReconfigFinishBuild(1000); syncReconfigFinishDeserialize(serialized, len, pMsg2); @@ -83,7 +83,7 @@ void test2() { void test3() { SyncReconfigFinish *pMsg = createMsg(); uint32_t len; - char * serialized = syncReconfigFinishSerialize2(pMsg, &len); + char *serialized = syncReconfigFinishSerialize2(pMsg, &len); SyncReconfigFinish *pMsg2 = syncReconfigFinishDeserialize2(serialized, len); syncReconfigFinishLog2((char *)"test3: SyncReconfigFinishSerialize2 -> syncReconfigFinishDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncRefTest.cpp b/source/libs/sync/test/syncRefTest.cpp index 90923a87ee98031898351147bdd355aa5ba89beb..c5132018a22f525bd74b934a6ea0906120d90172 100644 --- a/source/libs/sync/test/syncRefTest.cpp +++ b/source/libs/sync/test/syncRefTest.cpp @@ -25,7 +25,7 @@ int g = 100; typedef struct SyncObj { int64_t rid; - void * data; + void *data; char name[32]; int counter; } SyncObj; diff --git a/source/libs/sync/test/syncRequestVoteReplyTest.cpp b/source/libs/sync/test/syncRequestVoteReplyTest.cpp index d9fe6fa0118ea3daee3adf679816e0cd81c4980f..3d9db17725adfa76333e1368bbae27774384f85c 100644 --- a/source/libs/sync/test/syncRequestVoteReplyTest.cpp +++ b/source/libs/sync/test/syncRequestVoteReplyTest.cpp @@ -34,7 +34,7 @@ void test1() { void test2() { SyncRequestVoteReply *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncRequestVoteReplySerialize(pMsg, serialized, len); SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyBuild(1000); syncRequestVoteReplyDeserialize(serialized, len, pMsg2); @@ -48,7 +48,7 @@ void test2() { void test3() { SyncRequestVoteReply *pMsg = createMsg(); uint32_t len; - char * serialized = syncRequestVoteReplySerialize2(pMsg, &len); + char *serialized = syncRequestVoteReplySerialize2(pMsg, &len); SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyDeserialize2(serialized, len); syncRequestVoteReplyLog2((char *)"test3: syncRequestVoteReplySerialize3 -> syncRequestVoteReplyDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncRequestVoteTest.cpp b/source/libs/sync/test/syncRequestVoteTest.cpp index 4c6d7f94ad940e56264b17e80bb1e2b7b2a17997..94e1504add73294cc445b59b1a7158bb38af39b1 100644 --- a/source/libs/sync/test/syncRequestVoteTest.cpp +++ b/source/libs/sync/test/syncRequestVoteTest.cpp @@ -35,7 +35,7 @@ void test1() { void test2() { SyncRequestVote *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncRequestVoteSerialize(pMsg, serialized, len); SyncRequestVote *pMsg2 = syncRequestVoteBuild(1000); syncRequestVoteDeserialize(serialized, len, pMsg2); @@ -49,7 +49,7 @@ void test2() { void test3() { SyncRequestVote *pMsg = createMsg(); uint32_t len; - char * serialized = syncRequestVoteSerialize2(pMsg, &len); + char *serialized = syncRequestVoteSerialize2(pMsg, &len); SyncRequestVote *pMsg2 = syncRequestVoteDeserialize2(serialized, len); syncRequestVoteLog2((char *)"test3: syncRequestVoteSerialize3 -> syncRequestVoteDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncSnapshotRspTest.cpp b/source/libs/sync/test/syncSnapshotRspTest.cpp index f689d47aaffc938138838f96ee3a3b6e999a509c..89348da6175403f36d9edf25d70a587e3e3617f7 100644 --- a/source/libs/sync/test/syncSnapshotRspTest.cpp +++ b/source/libs/sync/test/syncSnapshotRspTest.cpp @@ -38,7 +38,7 @@ void test1() { void test2() { SyncSnapshotRsp *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncSnapshotRspSerialize(pMsg, serialized, len); SyncSnapshotRsp *pMsg2 = syncSnapshotRspBuild(1000); syncSnapshotRspDeserialize(serialized, len, pMsg2); @@ -52,7 +52,7 @@ void test2() { void test3() { SyncSnapshotRsp *pMsg = createMsg(); uint32_t len; - char * serialized = syncSnapshotRspSerialize2(pMsg, &len); + char *serialized = syncSnapshotRspSerialize2(pMsg, &len); SyncSnapshotRsp *pMsg2 = syncSnapshotRspDeserialize2(serialized, len); syncSnapshotRspLog2((char *)"test3: syncSnapshotRspSerialize2 -> syncSnapshotRspDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncSnapshotSendTest.cpp b/source/libs/sync/test/syncSnapshotSendTest.cpp index ca7916359ef2338dea9bf56e6a84cbf52abc839b..6fcfa6f6c490134e13a581963b200e0d7c466d42 100644 --- a/source/libs/sync/test/syncSnapshotSendTest.cpp +++ b/source/libs/sync/test/syncSnapshotSendTest.cpp @@ -48,7 +48,7 @@ void test1() { void test2() { SyncSnapshotSend *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncSnapshotSendSerialize(pMsg, serialized, len); SyncSnapshotSend *pMsg2 = syncSnapshotSendBuild(pMsg->dataLen, 1000); syncSnapshotSendDeserialize(serialized, len, pMsg2); @@ -62,7 +62,7 @@ void test2() { void test3() { SyncSnapshotSend *pMsg = createMsg(); uint32_t len; - char * serialized = syncSnapshotSendSerialize2(pMsg, &len); + char *serialized = syncSnapshotSendSerialize2(pMsg, &len); SyncSnapshotSend *pMsg2 = syncSnapshotSendDeserialize2(serialized, len); syncSnapshotSendLog2((char *)"test3: syncSnapshotSendSerialize2 -> syncSnapshotSendDeserialize2 ", pMsg2); diff --git a/source/libs/sync/test/syncSnapshotTest.cpp b/source/libs/sync/test/syncSnapshotTest.cpp index e0d33598b0706fe1ad000313e34bdcebc19fea2a..3dc85180728c4a287758156b47309e48a7cc01cd 100644 --- a/source/libs/sync/test/syncSnapshotTest.cpp +++ b/source/libs/sync/test/syncSnapshotTest.cpp @@ -25,8 +25,8 @@ int32_t myIndex = 0; SRaftId ids[TSDB_MAX_REPLICA]; SSyncInfo syncInfo; -SSyncFSM * pFsm; -SWal * pWal; +SSyncFSM *pFsm; +SWal *pWal; SSyncNode *gSyncNode; SyncIndex snapshotLastApplyIndex = SYNC_INDEX_INVALID; diff --git a/source/libs/sync/test/syncTimeoutTest.cpp b/source/libs/sync/test/syncTimeoutTest.cpp index e60fabe38bd007d3f7d0b62bbe275cfacc1cc10b..bb0d71f00327722644273a62a3dd592b88207561 100644 --- a/source/libs/sync/test/syncTimeoutTest.cpp +++ b/source/libs/sync/test/syncTimeoutTest.cpp @@ -30,7 +30,7 @@ void test1() { void test2() { SyncTimeout *pMsg = createMsg(); uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); + char *serialized = (char *)taosMemoryMalloc(len); syncTimeoutSerialize(pMsg, serialized, len); SyncTimeout *pMsg2 = syncTimeoutBuild(); syncTimeoutDeserialize(serialized, len, pMsg2); @@ -44,7 +44,7 @@ void test2() { void test3() { SyncTimeout *pMsg = createMsg(); uint32_t len; - char * serialized = syncTimeoutSerialize2(pMsg, &len); + char *serialized = syncTimeoutSerialize2(pMsg, &len); SyncTimeout *pMsg2 = syncTimeoutDeserialize2(serialized, len); syncTimeoutLog2((char *)"test3: syncTimeoutSerialize3 -> syncTimeoutDeserialize2 ", pMsg2); @@ -80,7 +80,7 @@ void test5() { void test6() { SyncTimeout *pMsg = createMsg(); - char * jsonStr = syncTimeout2Str(pMsg); + char *jsonStr = syncTimeout2Str(pMsg); sTrace("jsonStr: %s", jsonStr); syncUtilJson2Line(jsonStr); diff --git a/source/libs/sync/test/syncWriteTest.cpp b/source/libs/sync/test/syncWriteTest.cpp index 3bf068e3c7c45025f13b614d0ef73df6017d6a10..b185f52f7547d1a60541177f3a7374f3ed694081 100644 --- a/source/libs/sync/test/syncWriteTest.cpp +++ b/source/libs/sync/test/syncWriteTest.cpp @@ -25,8 +25,8 @@ int32_t myIndex = 0; SRaftId ids[TSDB_MAX_REPLICA]; SSyncInfo syncInfo; -SSyncFSM * pFsm; -SWal * pWal; +SSyncFSM *pFsm; +SWal *pWal; SSyncNode *gSyncNode; const char *pDir = "./syncWriteTest"; diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index a148c1e36bbdabb249f6dc64dc7c86c6934e641e..13b7e0ac0aef3640e0959d7b6cf1a7cd96040a72 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -121,6 +121,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg ret = tdbPagerWrite(pPager, pPage); if (ret < 0) { + tdbError("failed to write page since %s", terrstr()); return -1; } @@ -483,9 +484,8 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild, TXN ret = tdbPagerWrite(pPager, pChild); if (ret < 0) { - // TODO - ASSERT(0); - return 0; + tdbError("failed to write page since %s", terrstr()); + return -1; } // Copy the root page content to the child page @@ -556,8 +556,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx ret = tdbPagerWrite(pBt->pPager, pOlds[i]); if (ret < 0) { - // TODO - ASSERT(0); + tdbError("failed to write page since %s", terrstr()); return -1; } } @@ -583,8 +582,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx ret = tdbPagerWrite(pBt->pPager, pParent); if (ret < 0) { - // TODO - ASSERT(0); + tdbError("failed to write page since %s", terrstr()); return -1; } @@ -719,8 +717,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx ret = tdbPagerWrite(pBt->pPager, pNews[iNew]); if (ret < 0) { - // TODO - ASSERT(0); + tdbError("failed to write page since %s", terrstr()); return -1; } } @@ -937,7 +934,7 @@ static int tdbFetchOvflPage(SPgno *pPgno, SPage **ppOfp, TXN *pTxn, SBTree *pBt) // mark dirty ret = tdbPagerWrite(pBt->pPager, *ppOfp); if (ret < 0) { - ASSERT(0); + tdbError("failed to write page since %s", terrstr()); return -1; } @@ -987,7 +984,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const // fetch a new ofp and make it dirty SPgno pgno = 0; - SPage *ofp, *nextOfp; + SPage *ofp = NULL, *nextOfp = NULL; ret = tdbFetchOvflPage(&pgno, &ofp, pTxn, pBt); if (ret < 0) { @@ -1942,7 +1939,7 @@ int tdbBtcDelete(SBTC *pBtc) { // drop the cell on the leaf ret = tdbPagerWrite(pPager, pBtc->pPage); if (ret < 0) { - ASSERT(0); + tdbError("failed to write page since %s", terrstr()); return -1; } @@ -1964,7 +1961,7 @@ int tdbBtcDelete(SBTC *pBtc) { if (idx < nCells) { ret = tdbPagerWrite(pPager, pPage); if (ret < 0) { - ASSERT(0); + tdbError("failed to write page since %s", terrstr()); return -1; } @@ -2029,7 +2026,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int // mark dirty ret = tdbPagerWrite(pBtc->pBt->pPager, pBtc->pPage); if (ret < 0) { - ASSERT(0); + tdbError("failed to write page since %s", terrstr()); return -1; } diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index ea16e805628e69128eb548eb1a58084eb384282a..6c01348bc29261622469c5458963505fac388c5a 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -106,7 +106,7 @@ int32_t tdbBegin(TDB *pDb, TXN *pTxn) { for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) { ret = tdbPagerBegin(pPager, pTxn); if (ret < 0) { - ASSERT(0); + tdbError("failed to begin pager since %s. dbName:%s, txnId:%d", tstrerror(terrno), pDb->dbName, pTxn->txnId); return -1; } } @@ -121,7 +121,7 @@ int32_t tdbCommit(TDB *pDb, TXN *pTxn) { for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) { ret = tdbPagerCommit(pPager, pTxn); if (ret < 0) { - ASSERT(0); + tdbError("failed to commit pager since %s. dbName:%s, txnId:%d", tstrerror(terrno), pDb->dbName, pTxn->txnId); return -1; } } @@ -136,7 +136,7 @@ int32_t tdbAbort(TDB *pDb, TXN *pTxn) { for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) { ret = tdbPagerAbort(pPager, pTxn); if (ret < 0) { - ASSERT(0); + tdbError("failed to abort pager since %s. dbName:%s, txnId:%d", tstrerror(terrno), pDb->dbName, pTxn->txnId); return -1; } } diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 04711eb6a0af802f61cc39da3fba1282dcaf0c83..dd2416e5b80aa35271ce19560cd88b3bcb91b9fd 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -34,9 +34,9 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage); static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage); -static FORCE_INLINE int32_t pageCmpFn(const void *lhs, const void *rhs) { - SPage *pPageL = (SPage *)(((uint8_t *)lhs) - sizeof(SRBTreeNode)); - SPage *pPageR = (SPage *)(((uint8_t *)rhs) - sizeof(SRBTreeNode)); +static FORCE_INLINE int32_t pageCmpFn(const SRBTreeNode *lhs, const SRBTreeNode *rhs) { + SPage *pPageL = (SPage *)(((uint8_t *)lhs) - offsetof(SPage, node)); + SPage *pPageR = (SPage *)(((uint8_t *)rhs) - offsetof(SPage, node)); SPgno pgnoL = TDB_PAGE_PGNO(pPageL); SPgno pgnoR = TDB_PAGE_PGNO(pPageR); @@ -156,6 +156,7 @@ int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate, SBTree *pBt) { ret = tdbPagerWrite(pPager, pPage); if (ret < 0) { + tdbError("failed to write page since %s", terrstr()); return -1; } @@ -210,7 +211,7 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) { if (TDB_PAGE_PGNO(pPage) <= pPager->dbOrigSize) { ret = tdbPagerWritePageToJournal(pPager, pPage); if (ret < 0) { - ASSERT(0); + tdbError("failed to write page to journal since %s", tstrerror(terrno)); return -1; } } @@ -226,6 +227,8 @@ int tdbPagerBegin(SPager *pPager, TXN *pTxn) { // Open the journal pPager->jfd = tdbOsOpen(pPager->jFileName, TDB_O_CREAT | TDB_O_RDWR, 0755); if (pPager->jfd < 0) { + tdbError("failed to open file due to %s. jFileName:%s", strerror(errno), pPager->jFileName); + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } @@ -243,9 +246,9 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) { // sync the journal file ret = tdbOsFSync(pPager->jfd); if (ret < 0) { - // TODO - ASSERT(0); - return 0; + tdbError("failed to fsync jfd due to %s. jFileName:%s", strerror(errno), pPager->jFileName); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; } // loop to write the dirty pages to file @@ -255,7 +258,7 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) { pPage = (SPage *)pNode; ret = tdbPagerWritePageToDB(pPager, pPage); if (ret < 0) { - ASSERT(0); + tdbError("failed to write page to db since %s", tstrerror(terrno)); return -1; } } @@ -277,11 +280,25 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) { tRBTreeCreate(&pPager->rbt, pageCmpFn); // sync the db file - tdbOsFSync(pPager->fd); + if (tdbOsFSync(pPager->fd) < 0) { + tdbError("failed to fsync fd due to %s. file:%s", strerror(errno), pPager->dbFileName); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } // remove the journal file - tdbOsClose(pPager->jfd); - tdbOsRemove(pPager->jFileName); + if (tdbOsClose(pPager->jfd) < 0) { + tdbError("failed to close jfd due to %s. file:%s", strerror(errno), pPager->jFileName); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + if (tdbOsRemove(pPager->jFileName) < 0 && errno != ENOENT) { + tdbError("failed to remove file due to %s. file:%s", strerror(errno), pPager->jFileName); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + pPager->inTran = 0; return 0; @@ -297,14 +314,14 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) { // 0, sync the journal file ret = tdbOsFSync(pPager->jfd); if (ret < 0) { - // TODO - ASSERT(0); - return 0; + tdbError("failed to fsync jfd due to %s. file:%s", strerror(errno), pPager->jFileName); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; } tdb_fd_t jfd = tdbOsOpen(pPager->jFileName, TDB_O_RDWR, 0755); if (jfd == NULL) { - return 0; + return -1; } ret = tdbGetFileSize(jfd, pPager->pageSize, &journalSize); @@ -516,11 +533,15 @@ static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage) { ret = tdbOsWrite(pPager->jfd, &pgno, sizeof(pgno)); if (ret < 0) { + tdbError("failed to write pgno due to %s. file:%s, pgno:%u", strerror(errno), pPager->jFileName, pgno); + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } ret = tdbOsWrite(pPager->jfd, pPage->pData, pPage->pageSize); if (ret < 0) { + tdbError("failed to write page data due to %s. file:%s, pageSize:%ld", strerror(errno), pPager->jFileName, pPage->pageSize); + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } @@ -540,13 +561,15 @@ static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage) { offset = (i64)pPage->pageSize * (TDB_PAGE_PGNO(pPage) - 1); if (tdbOsLSeek(pPager->fd, offset, SEEK_SET) < 0) { - ASSERT(0); + tdbError("failed to lseek due to %s. file:%s, offset:%ld", strerror(errno), pPager->dbFileName, offset); + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } ret = tdbOsWrite(pPager->fd, pPage->pData, pPage->pageSize); if (ret < 0) { - ASSERT(0); + tdbError("failed to write page data due to %s. file:%s, pageSize:%ld", strerror(errno), pPager->dbFileName, pPage->pageSize); + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } @@ -590,23 +613,38 @@ int tdbPagerRestore(SPager *pPager, SBTree *pBt) { i64 offset = pPager->pageSize * (pgno - 1); if (tdbOsLSeek(pPager->fd, offset, SEEK_SET) < 0) { - ASSERT(0); + tdbError("failed to lseek fd due to %s. file:%s, offset:%ld", strerror(errno), pPager->dbFileName, offset); + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } ret = tdbOsWrite(pPager->fd, pageBuf, pPager->pageSize); if (ret < 0) { - ASSERT(0); + tdbError("failed to write buf due to %s. file: %s, bufsize:%d", strerror(errno), pPager->dbFileName, pPager->pageSize); + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } } - tdbOsFSync(pPager->fd); + if (tdbOsFSync(pPager->fd) < 0) { + tdbError("failed to fsync fd due to %s. dbfile:%s", strerror(errno), pPager->dbFileName); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } tdbOsFree(pageBuf); - tdbOsClose(jfd); - tdbOsRemove(pPager->jFileName); + if (tdbOsClose(jfd) < 0) { + tdbError("failed to close jfd due to %s. jFileName:%s", strerror(errno), pPager->jFileName); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + if (tdbOsRemove(pPager->jFileName) < 0 && errno != ENOENT) { + tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), pPager->jFileName); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } return 0; } diff --git a/source/libs/tfs/inc/tfsInt.h b/source/libs/tfs/inc/tfsInt.h index 8e77dc8c0cfbc69d116a2f874aa24a5b01256e1d..713f548e9ece3486f744097c42ddd81614175b94 100644 --- a/source/libs/tfs/inc/tfsInt.h +++ b/source/libs/tfs/inc/tfsInt.h @@ -26,12 +26,14 @@ #include "tlog.h" // For debug purpose +// clang-format off #define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("TFS FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} #define fError(...) { if (fsDebugFlag & DEBUG_ERROR) { taosPrintLog("TFS ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} #define fWarn(...) { if (fsDebugFlag & DEBUG_WARN) { taosPrintLog("TFS WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} #define fInfo(...) { if (fsDebugFlag & DEBUG_INFO) { taosPrintLog("TFS ", DEBUG_INFO, 255, __VA_ARGS__); }} #define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("TFS ", DEBUG_DEBUG, fsDebugFlag, __VA_ARGS__); }} #define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("TFS ", DEBUG_TRACE, fsDebugFlag, __VA_ARGS__); }} +// clang-format on typedef struct { int32_t level; @@ -42,12 +44,12 @@ typedef struct { typedef struct { TdThreadSpinlock lock; - int32_t level; - int32_t nextid; // next disk id to allocate - int32_t ndisk; // # of disks mounted to this tier - int32_t nAvailDisks; // # of Available disks - STfsDisk *disks[TFS_MAX_DISKS_PER_TIER]; - SDiskSize size; + int32_t level; + int32_t nextid; // next disk id to allocate + int32_t ndisk; // # of disks mounted to this tier + int32_t nAvailDisks; // # of Available disks + STfsDisk *disks[TFS_MAX_DISKS_PER_TIER]; + SDiskSize size; } STfsTier; typedef struct { @@ -65,10 +67,10 @@ typedef struct STfsDir { typedef struct STfs { TdThreadSpinlock lock; - SDiskSize size; - int32_t nlevel; - STfsTier tiers[TFS_MAX_TIERS]; - SHashObj *hash; // name to did map + SDiskSize size; + int32_t nlevel; + STfsTier tiers[TFS_MAX_TIERS]; + SHashObj *hash; // name to did map } STfs; STfsDisk *tfsNewDisk(int32_t level, int32_t id, const char *dir); @@ -82,15 +84,15 @@ void tfsUpdateTierSize(STfsTier *pTier); int32_t tfsAllocDiskOnTier(STfsTier *pTier); void tfsPosNextId(STfsTier *pTier); -#define tfsLockTier(pTier) taosThreadSpinLock(&(pTier)->lock) +#define tfsLockTier(pTier) taosThreadSpinLock(&(pTier)->lock) #define tfsUnLockTier(pTier) taosThreadSpinUnlock(&(pTier)->lock) -#define tfsLock(pTfs) taosThreadSpinLock(&(pTfs)->lock) +#define tfsLock(pTfs) taosThreadSpinLock(&(pTfs)->lock) #define tfsUnLock(pTfs) taosThreadSpinUnlock(&(pTfs)->lock) #define TFS_TIER_AT(pTfs, level) (&(pTfs)->tiers[level]) -#define TFS_DISK_AT(pTfs, did) ((pTfs)->tiers[(did).level].disks[(did).id]) -#define TFS_PRIMARY_DISK(pTfs) ((pTfs)->tiers[0].disks[0]) +#define TFS_DISK_AT(pTfs, did) ((pTfs)->tiers[(did).level].disks[(did).id]) +#define TFS_PRIMARY_DISK(pTfs) ((pTfs)->tiers[0].disks[0]) #define TMPNAME_LEN (TSDB_FILENAME_LEN * 2 + 32) diff --git a/source/libs/tfs/src/tfs.c b/source/libs/tfs/src/tfs.c index b8786a85a971b658ebc91b2040c5b7078ac9fbfb..943611ee27c6f1d6bfa51dfff211bf723764f88f 100644 --- a/source/libs/tfs/src/tfs.c +++ b/source/libs/tfs/src/tfs.c @@ -213,7 +213,7 @@ void tfsDirname(const STfsFile *pFile, char *dest) { void tfsAbsoluteName(STfs *pTfs, SDiskID diskId, const char *rname, char *aname) { STfsDisk *pDisk = TFS_DISK_AT(pTfs, diskId); - + snprintf(aname, TSDB_FILENAME_LEN, "%s%s%s", pDisk->path, TD_DIRSEP, rname); } @@ -285,7 +285,7 @@ int32_t tfsMkdir(STfs *pTfs, const char *rname) { int32_t tfsRmdir(STfs *pTfs, const char *rname) { ASSERT(rname[0] != 0); - + char aname[TMPNAME_LEN] = "\0"; for (int32_t level = 0; level < pTfs->nlevel; level++) { diff --git a/source/libs/tfs/test/tfsTest.cpp b/source/libs/tfs/test/tfsTest.cpp index b7858a22ebce50046e48ab05a32874639ab43aba..f4b0adf1f7256618f80e09ce234997719edbb004 100644 --- a/source/libs/tfs/test/tfsTest.cpp +++ b/source/libs/tfs/test/tfsTest.cpp @@ -16,7 +16,7 @@ class TfsTest : public ::testing::Test { protected: - #ifdef _TD_DARWIN_64 +#ifdef _TD_DARWIN_64 static void SetUpTestSuite() { root = "/private" TD_TMP_DIR_PATH "tfsTest"; } #else static void SetUpTestSuite() { root = TD_TMP_DIR_PATH "tfsTest"; } @@ -303,7 +303,7 @@ TEST_F(TfsTest, 04_File) { TEST_F(TfsTest, 05_MultiDisk) { int32_t code = 0; - #ifdef _TD_DARWIN_64 +#ifdef _TD_DARWIN_64 const char *root00 = "/private" TD_TMP_DIR_PATH "tfsTest00"; const char *root01 = "/private" TD_TMP_DIR_PATH "tfsTest01"; const char *root10 = "/private" TD_TMP_DIR_PATH "tfsTest10"; diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index e5a783292dc56f88432093848d039df3c005a1e2..c82af0d0e9b68a3606718bdef47bb783c7289c54 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -100,8 +100,8 @@ void rpcCloseImpl(void* arg) { taosMemoryFree(pRpc); } -void* rpcMallocCont(int32_t contLen) { - int32_t size = contLen + TRANS_MSG_OVERHEAD; +void* rpcMallocCont(int64_t contLen) { + int64_t size = contLen + TRANS_MSG_OVERHEAD; char* start = taosMemoryCalloc(1, size); if (start == NULL) { tError("failed to malloc msg, size:%d", size); @@ -120,11 +120,11 @@ void rpcFreeCont(void* cont) { tTrace("rpc free cont:%p", (char*)cont - TRANS_MSG_OVERHEAD); } -void* rpcReallocCont(void* ptr, int32_t contLen) { +void* rpcReallocCont(void* ptr, int64_t contLen) { if (ptr == NULL) return rpcMallocCont(contLen); char* st = (char*)ptr - TRANS_MSG_OVERHEAD; - int32_t sz = contLen + TRANS_MSG_OVERHEAD; + int64_t sz = contLen + TRANS_MSG_OVERHEAD; st = taosMemoryRealloc(st, sz); if (st == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 83323725bed859b755490f56029bb1bab6f621d0..359b9824cf437159dafa8ed76f93e0a6231cba98 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -597,6 +597,7 @@ static int32_t specifyConnRef(SCliConn* conn, bool update, int64_t handle) { static void cliAllocRecvBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { SCliConn* conn = handle->data; SConnBuffer* pBuf = &conn->readBuf; + tDebug("%s conn %p alloc read buf", CONN_GET_INST_LABEL(conn), conn); transAllocBuffer(pBuf, buf); } static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { @@ -609,7 +610,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { if (nread > 0) { pBuf->len += nread; while (transReadComplete(pBuf)) { - tTrace("%s conn %p read complete", CONN_GET_INST_LABEL(conn), conn); + tDebug("%s conn %p read complete", CONN_GET_INST_LABEL(conn), conn); if (pBuf->invalid) { cliHandleExcept(conn); break; diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 42079ff005bf7fac9802c2435fbb64ed8912c68d..f843c8559cae4e2b1595de93cb73c11ec5c77c14 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -203,7 +203,7 @@ bool transReadComplete(SConnBuffer* connBuf) { } int transSetConnOption(uv_tcp_t* stream) { - uv_tcp_nodelay(stream, 1); + uv_tcp_nodelay(stream, 0); int ret = uv_tcp_keepalive(stream, 5, 60); return ret; } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 57bf8a34b3c9dc0d74516b456deab8eba27083f4..3616b4808f8869633bce34f1840644318489bdda 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -332,7 +332,10 @@ void uvOnSendCb(uv_write_t* req, int status) { if (status == 0) { tTrace("conn %p data already was written on stream", conn); if (!transQueueEmpty(&conn->srvMsgs)) { - SSvrMsg* msg = transQueuePop(&conn->srvMsgs); + SSvrMsg* msg = transQueuePop(&conn->srvMsgs); + STraceId* trace = &msg->msg.info.traceId; + tGDebug("conn %p write data out", conn); + destroySmsg(msg); // send cached data if (!transQueueEmpty(&conn->srvMsgs)) { diff --git a/source/libs/transport/test/transUT.cpp b/source/libs/transport/test/transUT.cpp index b55f771ebd5181503d1f85cd1dccb986218f88d1..92f0bf11cf8fae8670cf625f3f0453f66ba5aef4 100644 --- a/source/libs/transport/test/transUT.cpp +++ b/source/libs/transport/test/transUT.cpp @@ -99,7 +99,7 @@ class Client { private: tsem_t sem; SRpcInit rpcInit_; - void * transCli; + void *transCli; SRpcMsg resp; }; class Server { @@ -146,7 +146,7 @@ class Server { private: SRpcInit rpcInit_; - void * transSrv; + void *transSrv; }; static void processReq(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { SRpcMsg rpcMsg = {0}; @@ -330,7 +330,7 @@ TEST_F(TransEnv, clientUserDefined) { TEST_F(TransEnv, cliPersistHandle) { SRpcMsg resp = {0}; - void * handle = NULL; + void *handle = NULL; for (int i = 0; i < 10; i++) { SRpcMsg req = {0}; req.info = resp.info; @@ -366,7 +366,7 @@ TEST_F(TransEnv, srvReleaseHandle) { SRpcMsg resp = {0}; tr->SetSrvContinueSend(processReleaseHandleCb); // tr->Restart(processReleaseHandleCb); - void * handle = NULL; + void *handle = NULL; SRpcMsg req = {0}; for (int i = 0; i < 1; i++) { memset(&req, 0, sizeof(req)); diff --git a/source/libs/transport/test/uv.c b/source/libs/transport/test/uv.c index 1d99bf8fef2a2882d6d59bee4ce04af0a3b3b556..a44f1ca4357b4376891f8f941cfcf29799fd4f2e 100644 --- a/source/libs/transport/test/uv.c +++ b/source/libs/transport/test/uv.c @@ -11,23 +11,23 @@ typedef struct SThreadObj { TdThread thread; - uv_pipe_t * pipe; - uv_loop_t * loop; + uv_pipe_t *pipe; + uv_loop_t *loop; uv_async_t *workerAsync; // int fd; } SThreadObj; typedef struct SServerObj { uv_tcp_t server; - uv_loop_t * loop; + uv_loop_t *loop; int workerIdx; int numOfThread; SThreadObj **pThreadObj; - uv_pipe_t ** pipe; + uv_pipe_t **pipe; } SServerObj; typedef struct SConnCtx { - uv_tcp_t * pClient; + uv_tcp_t *pClient; uv_timer_t *pTimer; uv_async_t *pWorkerAsync; int ref; diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index e49a9631911e57d7f30cc66d5b1db4036d8e3dac..279f4dc6562d45b11240628821a7b2ba3c8e6eab 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -35,113 +35,251 @@ int64_t FORCE_INLINE walGetCommittedVer(SWal* pWal) { return pWal->vers.commitVe int64_t FORCE_INLINE walGetAppliedVer(SWal* pWal) { return pWal->vers.appliedVer; } -static FORCE_INLINE void walBuildMetaName(SWal* pWal, int metaVer, char* buf) { - sprintf(buf, "%s/meta-ver%d", pWal->path, metaVer); +static FORCE_INLINE int walBuildMetaName(SWal* pWal, int metaVer, char* buf) { + return sprintf(buf, "%s/meta-ver%d", pWal->path, metaVer); } -static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { +static FORCE_INLINE int walBuildTmpMetaName(SWal* pWal, char* buf) { + return sprintf(buf, "%s/meta-ver.tmp", pWal->path); +} + +static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) { int32_t sz = taosArrayGetSize(pWal->fileInfoSet); - ASSERT(sz > 0); -#if 0 - for (int i = 0; i < sz; i++) { - SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, i); - } -#endif + terrno = TSDB_CODE_SUCCESS; + ASSERT(fileIdx >= 0 && fileIdx < sz); - SWalFileInfo* pLastFileInfo = taosArrayGet(pWal->fileInfoSet, sz - 1); + SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx); char fnameStr[WAL_FILE_LEN]; - walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr); + walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); int64_t fileSize = 0; taosStatFile(fnameStr, &fileSize, NULL); - int32_t readSize = TMIN(WAL_SCAN_BUF_SIZE, fileSize); - pLastFileInfo->fileSize = fileSize; - TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ); + TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE); if (pFile == NULL) { + wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); terrno = TAOS_SYSTEM_ERROR(errno); return -1; } + // ensure size as non-negative + pFileInfo->fileSize = TMAX(0, pFileInfo->fileSize); + uint64_t magic = WAL_MAGIC; + int64_t walCkHeadSz = sizeof(SWalCkHead); + int64_t end = fileSize; + int64_t offset = 0; + int32_t capacity = 0; + int32_t readSize = 0; + char* buf = NULL; + char* found = NULL; + bool firstTrial = pFileInfo->fileSize < fileSize; + + // search for the valid last WAL entry, e.g. block by block + while (1) { + offset = (firstTrial) ? pFileInfo->fileSize : TMAX(0, end - WAL_SCAN_BUF_SIZE); + ASSERT(offset <= end); + readSize = end - offset; + capacity = readSize + sizeof(magic); + + int64_t limit = WAL_RECOV_SIZE_LIMIT; + if (limit < readSize) { + wError("vgId:%d, possibly corrupted WAL range exceeds size limit (i.e. %" PRId64 " bytes). offset:%" PRId64 + ", end:%" PRId64 ", file:%s", + pWal->cfg.vgId, limit, offset, end, fnameStr); + terrno = TSDB_CODE_WAL_SIZE_LIMIT; + goto _err; + } - char* buf = taosMemoryMalloc(readSize + 5); - if (buf == NULL) { - taosCloseFile(&pFile); - terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; - return -1; - } + void* ptr = taosMemoryRealloc(buf, capacity); + if (ptr == NULL) { + terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; + goto _err; + } + buf = ptr; - int64_t offset; - offset = taosLSeekFile(pFile, -readSize, SEEK_END); - if (readSize != taosReadFile(pFile, buf, readSize)) { - taosMemoryFree(buf); - taosCloseFile(&pFile); - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } + int64_t ret = taosLSeekFile(pFile, offset, SEEK_SET); + if (ret < 0) { + wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(errno), offset); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } - char* found = NULL; - while (1) { + if (readSize != taosReadFile(pFile, buf, readSize)) { + wError("vgId:%d, failed to read file due to %s. readSize:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), + readSize, fnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + char* candidate = NULL; char* haystack = buf; - char* candidate; - while ((candidate = tmemmem(haystack, readSize - (haystack - buf), (char*)&magic, sizeof(uint64_t))) != NULL) { - // read and validate + + while ((candidate = tmemmem(haystack, readSize - (haystack - buf), (char*)&magic, sizeof(magic))) != NULL) { + // validate head + int64_t len = readSize - (candidate - buf); + if (len < walCkHeadSz) { + break; + } SWalCkHead* logContent = (SWalCkHead*)candidate; - if (walValidHeadCksum(logContent) == 0 && walValidBodyCksum(logContent) == 0) { - found = candidate; + if (walValidHeadCksum(logContent) != 0) { + wError("vgId:%d, failed to validate checksum of wal entry header. offset:% %" PRId64 ", file:%s", + ((char*)(logContent)-buf), fnameStr); + haystack = candidate + 1; + if (firstTrial) { + break; + } else { + continue; + } } + + // validate body + int64_t size = walCkHeadSz + logContent->head.bodyLen; + if (len < size) { + int64_t extraSize = size - len; + if (capacity < readSize + extraSize + sizeof(magic)) { + capacity += extraSize; + void* ptr = taosMemoryRealloc(buf, capacity); + if (ptr == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + buf = ptr; + } + int64_t ret = taosLSeekFile(pFile, offset + readSize, SEEK_SET); + if (ret < 0) { + wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(errno), + offset); + terrno = TAOS_SYSTEM_ERROR(errno); + break; + } + if (extraSize != taosReadFile(pFile, buf + readSize, extraSize)) { + wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", extraSize:%" PRId64 ", file:%s", + pWal->cfg.vgId, strerror(errno), offset + readSize, extraSize, fnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + break; + } + } + if (walValidBodyCksum(logContent) != 0) { + terrno = TSDB_CODE_WAL_CHKSUM_MISMATCH; + wError("vgId:%d, failed to validate checksum of wal entry body. offset:% %" PRId64 ", file:%s", + ((char*)(logContent)-buf), fnameStr); + haystack = candidate + 1; + if (firstTrial) { + break; + } else { + continue; + } + } + + // found one + found = candidate; haystack = candidate + 1; } + if (found || offset == 0) break; - offset = TMIN(0, offset - readSize + sizeof(uint64_t)); - int64_t offset2 = taosLSeekFile(pFile, offset, SEEK_SET); - ASSERT(offset == offset2); - if (readSize != taosReadFile(pFile, buf, readSize)) { - taosMemoryFree(buf); - taosCloseFile(&pFile); - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } -#if 0 - if (found == buf) { - SWalCkHead* logContent = (SWalCkHead*)found; - if (walValidHeadCksum(logContent) != 0 || walValidBodyCksum(logContent) != 0) { - // file has to be deleted - taosMemoryFree(buf); - taosCloseFile(&pFile); - terrno = TSDB_CODE_WAL_FILE_CORRUPTED; - return -1; - } - } -#endif + + // go backwards, e.g. by at most one WAL scan buf size + end = offset + walCkHeadSz - 1; + firstTrial = false; } - if (found == NULL) { - // file corrupted, no complete log - // TODO delete and search in previous files - /*ASSERT(0);*/ - terrno = TSDB_CODE_WAL_FILE_CORRUPTED; - return -1; + // determine end of last entry + SWalCkHead* lastEntry = (SWalCkHead*)found; + int64_t retVer = -1; + int64_t lastEntryBeginOffset = 0; + int64_t lastEntryEndOffset = 0; + + if (lastEntry == NULL) { + terrno = TSDB_CODE_WAL_LOG_NOT_EXIST; + } else { + retVer = lastEntry->head.version; + lastEntryBeginOffset = offset + (int64_t)((char*)lastEntry - (char*)buf); + lastEntryEndOffset = lastEntryBeginOffset + sizeof(SWalCkHead) + lastEntry->head.bodyLen; } // truncate file - SWalCkHead* lastEntry = (SWalCkHead*)found; - int64_t retVer = lastEntry->head.version; - int64_t lastEntryBeginOffset = offset + (int64_t)((char*)found - (char*)buf); - int64_t lastEntryEndOffset = lastEntryBeginOffset + sizeof(SWalCkHead) + lastEntry->head.bodyLen; if (lastEntryEndOffset != fileSize) { - wWarn("vgId:%d repair meta truncate file %s to %ld, orig size %ld", pWal->cfg.vgId, fnameStr, lastEntryEndOffset, + wWarn("vgId:%d, repair meta truncate file %s to %ld, orig size %ld", pWal->cfg.vgId, fnameStr, lastEntryEndOffset, fileSize); - taosFtruncateFile(pFile, lastEntryEndOffset); - ((SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet))->fileSize = lastEntryEndOffset; - pWal->totSize -= (fileSize - lastEntryEndOffset); + if (taosFtruncateFile(pFile, lastEntryEndOffset) < 0) { + wError("failed to truncate file due to %s. file:%s", strerror(errno), fnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + if (taosFsyncFile(pFile) < 0) { + wError("failed to fsync file due to %s. file:%s", strerror(errno), fnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } } + pFileInfo->fileSize = lastEntryEndOffset; taosCloseFile(&pFile); taosMemoryFree(buf); - return retVer; + +_err: + taosCloseFile(&pFile); + taosMemoryFree(buf); + return -1; +} + +static void walRebuildFileInfoSet(SArray* metaLogList, SArray* actualLogList) { + int metaFileNum = taosArrayGetSize(metaLogList); + int actualFileNum = taosArrayGetSize(actualLogList); + int j = 0; + + // both of the lists in asc order + for (int i = 0; i < actualFileNum; i++) { + SWalFileInfo* pLogInfo = taosArrayGet(actualLogList, i); + while (j < metaFileNum) { + SWalFileInfo* pMetaInfo = taosArrayGet(metaLogList, j); + ASSERT(pMetaInfo != NULL); + if (pMetaInfo->firstVer < pLogInfo->firstVer) { + j++; + } else if (pMetaInfo->firstVer == pLogInfo->firstVer) { + (*pLogInfo) = *pMetaInfo; + j++; + break; + } else { + break; + } + } + } + + taosArrayClear(metaLogList); + + for (int i = 0; i < actualFileNum; i++) { + SWalFileInfo* pFileInfo = taosArrayGet(actualLogList, i); + taosArrayPush(metaLogList, pFileInfo); + } +} + +void walAlignVersions(SWal* pWal) { + if (pWal->vers.firstVer > pWal->vers.snapshotVer + 1) { + wWarn("vgId:%d, firstVer:%" PRId64 " is larger than snapshotVer:%" PRId64 " + 1. align with it.", pWal->cfg.vgId, + pWal->vers.firstVer, pWal->vers.snapshotVer); + pWal->vers.firstVer = pWal->vers.snapshotVer + 1; + } + if (pWal->vers.lastVer < pWal->vers.snapshotVer) { + wWarn("vgId:%d, lastVer:%" PRId64 " is less than snapshotVer:%" PRId64 ". align with it.", pWal->cfg.vgId, + pWal->vers.lastVer, pWal->vers.snapshotVer); + pWal->vers.lastVer = pWal->vers.snapshotVer; + } + if (pWal->vers.commitVer < pWal->vers.snapshotVer) { + wWarn("vgId:%d, commitVer:%" PRId64 " is less than snapshotVer:%" PRId64 ". align with it.", pWal->cfg.vgId, + pWal->vers.commitVer, pWal->vers.snapshotVer); + pWal->vers.commitVer = pWal->vers.snapshotVer; + } + if (pWal->vers.appliedVer < pWal->vers.snapshotVer) { + wWarn("vgId:%d, appliedVer:%" PRId64 " is less than snapshotVer:%" PRId64 ". align with it.", pWal->cfg.vgId, + pWal->vers.appliedVer, pWal->vers.snapshotVer); + pWal->vers.appliedVer = pWal->vers.snapshotVer; + } + + pWal->vers.commitVer = TMIN(pWal->vers.lastVer, pWal->vers.commitVer); + pWal->vers.appliedVer = TMIN(pWal->vers.commitVer, pWal->vers.appliedVer); } int walCheckAndRepairMeta(SWal* pWal) { @@ -150,7 +288,6 @@ int walCheckAndRepairMeta(SWal* pWal) { const char* idxPattern = "^[0-9]+.idx$"; regex_t logRegPattern; regex_t idxRegPattern; - bool fixed = false; regcomp(&logRegPattern, logPattern, REG_EXTENDED); regcomp(&idxRegPattern, idxPattern, REG_EXTENDED); @@ -184,222 +321,237 @@ int walCheckAndRepairMeta(SWal* pWal) { taosArraySort(actualLog, compareWalFileInfo); - int metaFileNum = taosArrayGetSize(pWal->fileInfoSet); - int actualFileNum = taosArrayGetSize(actualLog); + int metaFileNum = taosArrayGetSize(pWal->fileInfoSet); + int actualFileNum = taosArrayGetSize(actualLog); + int64_t firstVerPrev = pWal->vers.firstVer; + int64_t lastVerPrev = pWal->vers.lastVer; + int64_t totSize = 0; + bool updateMeta = (metaFileNum != actualFileNum); + + // rebuild meta of file info + walRebuildFileInfoSet(pWal->fileInfoSet, actualLog); + taosArrayDestroy(actualLog); -#if 0 - for (int32_t fileNo = actualFileNum - 1; fileNo >= 0; fileNo--) { - SWalFileInfo* pFileInfo = taosArrayGet(pLogInfoArray, fileNo); + int32_t sz = taosArrayGetSize(pWal->fileInfoSet); + ASSERT(sz == actualFileNum); + + // scan and determine the lastVer + int32_t fileIdx = sz; + + while (--fileIdx >= 0) { char fnameStr[WAL_FILE_LEN]; + int64_t fileSize = 0; + SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx); + walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); - int64_t fileSize = 0; - taosStatFile(fnameStr, &fileSize, NULL); - if (fileSize == 0) { - taosRemoveFile(fnameStr); - walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); - taosRemoveFile(fnameStr); - taosArrayPop(pLogInfoArray); - } else { - break; + int32_t code = taosStatFile(fnameStr, &fileSize, NULL); + if (code < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + wError("failed to stat file since %s. file:%s", terrstr(), fnameStr); + return -1; } - } - actualFileNum = taosArrayGetSize(pLogInfoArray); -#endif - - { - int32_t i = 0, j = 0; - while (i < actualFileNum && j < metaFileNum) { - SWalFileInfo* pActualFile = taosArrayGet(actualLog, i); - SWalFileInfo* pMetaFile = taosArrayGet(pWal->fileInfoSet, j); - if (pActualFile->firstVer < pMetaFile->firstVer) { - char fNameStr[WAL_FILE_LEN]; - walBuildLogName(pWal, pActualFile->firstVer, fNameStr); - taosRemoveFile(fNameStr); - walBuildIdxName(pWal, pActualFile->firstVer, fNameStr); - taosRemoveFile(fNameStr); - i++; - } else if (pActualFile->firstVer > pMetaFile->firstVer) { - taosArrayRemove(pWal->fileInfoSet, j); - metaFileNum--; - } else { - i++; - j++; - } + ASSERT(pFileInfo->firstVer >= 0); + + if (pFileInfo->lastVer >= pFileInfo->firstVer && fileSize == pFileInfo->fileSize) { + totSize += pFileInfo->fileSize; + continue; } - if (i == actualFileNum && j == metaFileNum) { - if (j > 0) { - SWalFileInfo* pLastInfo = taosArrayGet(pWal->fileInfoSet, j - 1); - int64_t fsize = 0; - char fNameStr[WAL_FILE_LEN]; - walBuildLogName(pWal, pLastInfo->firstVer, fNameStr); - taosStatFile(fNameStr, &fsize, NULL); - if (pLastInfo->fileSize != fsize) { - fixed = true; - pLastInfo->fileSize = fsize; - pLastInfo->lastVer = walScanLogGetLastVer(pWal); - } - } - } else { - fixed = true; - while (i < actualFileNum) { - SWalFileInfo* pActualFile = taosArrayGet(actualLog, i); - char fNameStr[WAL_FILE_LEN]; - walBuildLogName(pWal, pActualFile->firstVer, fNameStr); - taosStatFile(fNameStr, &pActualFile->fileSize, NULL); - - if (pActualFile->fileSize == 0) { - ASSERT(i == actualFileNum - 1); - taosRemoveFile(fNameStr); - - walBuildIdxName(pWal, pActualFile->firstVer, fNameStr); - taosRemoveFile(fNameStr); - break; - } + updateMeta = true; - if (i < actualFileNum - 1) { - pActualFile->lastVer = ((SWalFileInfo*)taosArrayGet(actualLog, i + 1))->firstVer - 1; - taosArrayPush(pWal->fileInfoSet, pActualFile); - i++; - } else { - pActualFile = taosArrayPush(pWal->fileInfoSet, pActualFile); - pActualFile->lastVer = walScanLogGetLastVer(pWal); - if (pActualFile->lastVer == -1) { - taosRemoveFile(fNameStr); - - walBuildIdxName(pWal, pActualFile->firstVer, fNameStr); - taosRemoveFile(fNameStr); - taosArrayPop(pWal->fileInfoSet); - } - break; - } + int64_t lastVer = walScanLogGetLastVer(pWal, fileIdx); + if (lastVer < 0) { + if (terrno != TSDB_CODE_WAL_LOG_NOT_EXIST) { + wError("failed to scan wal last ver since %s", terrstr()); + return -1; } + ASSERT(pFileInfo->fileSize == 0); + // remove the empty wal log, and its idx + taosRemoveFile(fnameStr); + walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); + taosRemoveFile(fnameStr); + // remove its meta entry + taosArrayRemove(pWal->fileInfoSet, fileIdx); + continue; } - } -#if 0 - if (metaFileNum > actualFileNum) { - taosArrayPopFrontBatch(pWal->fileInfoSet, metaFileNum - actualFileNum); - } else if (metaFileNum < actualFileNum) { - for (int i = metaFileNum; i < actualFileNum; i++) { - SWalFileInfo* pFileInfo = taosArrayGet(actualLog, i); - taosArrayPush(pWal->fileInfoSet, pFileInfo); - } + // update lastVer + pFileInfo->lastVer = lastVer; + totSize += pFileInfo->fileSize; } -#endif - - taosArrayDestroy(actualLog); + // reset vers info and so on actualFileNum = taosArrayGetSize(pWal->fileInfoSet); pWal->writeCur = actualFileNum - 1; - + pWal->totSize = totSize; + pWal->vers.lastVer = -1; if (actualFileNum > 0) { - int64_t fLastVer = ((SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur))->lastVer; - if (fLastVer != -1 && pWal->vers.lastVer != fLastVer) { - fixed = true; - pWal->vers.lastVer = fLastVer; - } - int64_t fFirstVer = ((SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, 0))->firstVer; - if (fFirstVer != pWal->vers.firstVer) { - fixed = true; - pWal->vers.firstVer = fFirstVer; - } + pWal->vers.firstVer = ((SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, 0))->firstVer; + pWal->vers.lastVer = ((SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet))->lastVer; } + (void)walAlignVersions(pWal); - if (fixed) { - walSaveMeta(pWal); + // update meta file + if (updateMeta) { + (void)walSaveMeta(pWal); + } + return 0; +} + +int walReadLogHead(TdFilePtr pLogFile, int64_t offset, SWalCkHead* pCkHead) { + if (taosLSeekFile(pLogFile, offset, SEEK_SET) < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + if (taosReadFile(pLogFile, pCkHead, sizeof(SWalCkHead)) != sizeof(SWalCkHead)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + if (walValidHeadCksum(pCkHead) != 0) { + terrno = TSDB_CODE_WAL_CHKSUM_MISMATCH; + return -1; } return 0; } -int walCheckAndRepairIdx(SWal* pWal) { +int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { int32_t sz = taosArrayGetSize(pWal->fileInfoSet); - for (int32_t i = 0; i < sz; i++) { - SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, i); - - char fnameStr[WAL_FILE_LEN]; - walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); - int64_t fsize; - TdFilePtr pIdxFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE); - if (pIdxFile == NULL) { - ASSERT(0); + ASSERT(fileIdx >= 0 && fileIdx < sz); + SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx); + char fnameStr[WAL_FILE_LEN]; + walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); + char fLogNameStr[WAL_FILE_LEN]; + walBuildLogName(pWal, pFileInfo->firstVer, fLogNameStr); + int64_t fileSize = 0; + + if (taosStatFile(fnameStr, &fileSize, NULL) < 0 && errno != ENOENT) { + wError("vgId:%d, failed to stat file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + ASSERT(pFileInfo->fileSize > 0 && pFileInfo->firstVer >= 0 && pFileInfo->lastVer >= pFileInfo->firstVer); + if (fileSize == (pFileInfo->lastVer - pFileInfo->firstVer + 1) * sizeof(SWalIdxEntry)) { + return 0; + } + + // start to repair + int64_t offset = fileSize - fileSize % sizeof(SWalIdxEntry); + TdFilePtr pLogFile = NULL; + TdFilePtr pIdxFile = NULL; + SWalIdxEntry idxEntry = {.ver = pFileInfo->firstVer - 1, .offset = -sizeof(SWalCkHead)}; + SWalCkHead ckHead; + memset(&ckHead, 0, sizeof(ckHead)); + ckHead.head.version = idxEntry.ver; + + pIdxFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE); + if (pIdxFile == NULL) { + wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + pLogFile = taosOpenFile(fLogNameStr, TD_FILE_READ); + if (pLogFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + wError("vgId:%d, cannot open file %s, since %s", pWal->cfg.vgId, fLogNameStr, terrstr()); + goto _err; + } + + // determine the last valid entry end, i.e. offset + while ((offset -= sizeof(SWalIdxEntry)) >= 0) { + if (taosLSeekFile(pIdxFile, offset, SEEK_SET) < 0) { + wError("vgId:%d, failed to seek file due to %s. offset:" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), + offset, fnameStr); terrno = TAOS_SYSTEM_ERROR(errno); - wError("vgId:%d, cannot open file %s, since %s", pWal->cfg.vgId, fnameStr, terrstr()); - return -1; + goto _err; + } + + if (taosReadFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) { + wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), + offset, fnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; } - taosFStatFile(pIdxFile, &fsize, NULL); - if (fsize == (pFileInfo->lastVer - pFileInfo->firstVer + 1) * sizeof(SWalIdxEntry)) { - taosCloseFile(&pIdxFile); + if (idxEntry.ver > pFileInfo->lastVer) { continue; } - int32_t left = fsize % sizeof(SWalIdxEntry); - int64_t offset = taosLSeekFile(pIdxFile, -left, SEEK_END); - if (left != 0) { - taosFtruncateFile(pIdxFile, offset); - wWarn("vgId:%d wal truncate file %s to offset %ld since size invalid, file size %ld", pWal->cfg.vgId, fnameStr, - offset, fsize); + if (walReadLogHead(pLogFile, idxEntry.offset, &ckHead) < 0) { + wWarn("vgId:%d, failed to read log file since %s. file:%s, offset:%" PRId64 ", idx entry ver:%" PRId64 "", + pWal->cfg.vgId, terrstr(), fLogNameStr, idxEntry.offset, idxEntry.ver); + continue; } - offset -= sizeof(SWalIdxEntry); - SWalIdxEntry idxEntry = {.ver = pFileInfo->firstVer}; - while (1) { - if (offset < 0) { - taosLSeekFile(pIdxFile, 0, SEEK_SET); - taosWriteFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)); - break; - } - taosLSeekFile(pIdxFile, offset, SEEK_SET); - int64_t contLen = taosReadFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)); - if (contLen < 0 || contLen != sizeof(SWalIdxEntry)) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - if ((idxEntry.ver - pFileInfo->firstVer) * sizeof(SWalIdxEntry) != offset) { - taosFtruncateFile(pIdxFile, offset); - wWarn("vgId:%d wal truncate file %s to offset %ld since entry invalid, entry ver %ld, entry offset %ld", - pWal->cfg.vgId, fnameStr, offset, idxEntry.ver, idxEntry.offset); - offset -= sizeof(SWalIdxEntry); - } else { - break; - } + if (idxEntry.ver == ckHead.head.version) { + break; } + } + offset += sizeof(SWalIdxEntry); - if (idxEntry.ver < pFileInfo->lastVer) { - char fLogNameStr[WAL_FILE_LEN]; - walBuildLogName(pWal, pFileInfo->firstVer, fLogNameStr); - TdFilePtr pLogFile = taosOpenFile(fLogNameStr, TD_FILE_READ); - if (pLogFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); - wError("vgId:%d, cannot open file %s, since %s", pWal->cfg.vgId, fLogNameStr, terrstr()); - return -1; - } - while (idxEntry.ver < pFileInfo->lastVer) { - if (taosLSeekFile(pLogFile, idxEntry.offset, SEEK_SET) == -1) { - terrno = TAOS_SYSTEM_ERROR(errno); - wError("vgId:%d, cannot seek file %s at %ld, since %s", pWal->cfg.vgId, fLogNameStr, idxEntry.offset, - terrstr()); - return -1; - } - SWalCkHead ckHead; - taosReadFile(pLogFile, &ckHead, sizeof(SWalCkHead)); - if (idxEntry.ver != ckHead.head.version) { - // todo truncate this idx also - taosCloseFile(&pLogFile); - wError("vgId:%d, invalid repair case, log seek to %ld to find ver %ld, actual ver %ld", pWal->cfg.vgId, - idxEntry.offset, idxEntry.ver, ckHead.head.version); - return -1; - } - idxEntry.ver = ckHead.head.version + 1; - idxEntry.offset = idxEntry.offset + sizeof(SWalCkHead) + ckHead.head.bodyLen; - wWarn("vgId:%d wal idx append new entry %ld %ld", pWal->cfg.vgId, idxEntry.ver, idxEntry.offset); - taosWriteFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)); - } - taosCloseFile(&pLogFile); + // ftruncate idx file + if (offset < fileSize) { + if (taosFtruncateFile(pIdxFile, offset) < 0) { + wError("vgId:%d, failed to ftruncate file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, + strerror(errno), offset, fnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + } + + // rebuild idx file + if (taosLSeekFile(pIdxFile, 0, SEEK_END) < 0) { + wError("vgId:%d, failed to seek file due to %s. offset:" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), + offset, fnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + while (idxEntry.ver < pFileInfo->lastVer) { + ASSERT(idxEntry.ver == ckHead.head.version); + + idxEntry.ver += 1; + idxEntry.offset += sizeof(SWalCkHead) + ckHead.head.bodyLen; + + if (walReadLogHead(pLogFile, idxEntry.offset, &ckHead) < 0) { + wError("vgId:%d, failed to read wal log head since %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, terrstr(), + idxEntry.offset, fLogNameStr); + goto _err; + } + wWarn("vgId:%d wal idx append new entry %ld %ld", pWal->cfg.vgId, idxEntry.ver, idxEntry.offset); + if (taosWriteFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) < 0) { + wError("vgId:%d, failed to append file since %s. file:%s", pWal->cfg.vgId, terrstr(), fnameStr); + goto _err; + } + } + + if (taosFsyncFile(pIdxFile) < 0) { + wError("vgId:%d, faild to fsync file since %s. file:%s", pWal->cfg.vgId, terrstr(), fnameStr); + goto _err; + } + + (void)taosCloseFile(&pLogFile); + (void)taosCloseFile(&pIdxFile); + return 0; + +_err: + (void)taosCloseFile(&pLogFile); + (void)taosCloseFile(&pIdxFile); + return -1; +} + +int walCheckAndRepairIdx(SWal* pWal) { + int32_t sz = taosArrayGetSize(pWal->fileInfoSet); + int32_t fileIdx = sz; + while (--fileIdx >= 0) { + if (walCheckAndRepairIdxFile(pWal, fileIdx) < 0) { + wError("vgId:%d, failed to repair idx file since %s. fileIdx:%d", pWal->cfg.vgId, terrstr(), fileIdx); + return -1; } - taosCloseFile(&pIdxFile); } return 0; } @@ -492,14 +644,20 @@ int walMetaDeserialize(SWal* pWal, const char* bytes) { ASSERT(taosArrayGetSize(pWal->fileInfoSet) == 0); cJSON *pRoot, *pMeta, *pFiles, *pInfoJson, *pField; pRoot = cJSON_Parse(bytes); + if (!pRoot) goto _err; pMeta = cJSON_GetObjectItem(pRoot, "meta"); + if (!pMeta) goto _err; pField = cJSON_GetObjectItem(pMeta, "firstVer"); + if (!pField) goto _err; pWal->vers.firstVer = atoll(cJSON_GetStringValue(pField)); pField = cJSON_GetObjectItem(pMeta, "snapshotVer"); + if (!pField) goto _err; pWal->vers.snapshotVer = atoll(cJSON_GetStringValue(pField)); pField = cJSON_GetObjectItem(pMeta, "commitVer"); + if (!pField) goto _err; pWal->vers.commitVer = atoll(cJSON_GetStringValue(pField)); pField = cJSON_GetObjectItem(pMeta, "lastVer"); + if (!pField) goto _err; pWal->vers.lastVer = atoll(cJSON_GetStringValue(pField)); pFiles = cJSON_GetObjectItem(pRoot, "files"); @@ -509,17 +667,23 @@ int walMetaDeserialize(SWal* pWal, const char* bytes) { taosArrayEnsureCap(pArray, sz); SWalFileInfo* pData = pArray->pData; for (int i = 0; i < sz; i++) { - cJSON* pInfoJson = cJSON_GetArrayItem(pFiles, i); + cJSON* pInfoJson = cJSON_GetArrayItem(pFiles, i); + if (!pInfoJson) goto _err; SWalFileInfo* pInfo = &pData[i]; pField = cJSON_GetObjectItem(pInfoJson, "firstVer"); + if (!pField) goto _err; pInfo->firstVer = atoll(cJSON_GetStringValue(pField)); pField = cJSON_GetObjectItem(pInfoJson, "lastVer"); + if (!pField) goto _err; pInfo->lastVer = atoll(cJSON_GetStringValue(pField)); pField = cJSON_GetObjectItem(pInfoJson, "createTs"); + if (!pField) goto _err; pInfo->createTs = atoll(cJSON_GetStringValue(pField)); pField = cJSON_GetObjectItem(pInfoJson, "closeTs"); + if (!pField) goto _err; pInfo->closeTs = atoll(cJSON_GetStringValue(pField)); pField = cJSON_GetObjectItem(pInfoJson, "fileSize"); + if (!pField) goto _err; pInfo->fileSize = atoll(cJSON_GetStringValue(pField)); } taosArraySetSize(pArray, sz); @@ -527,6 +691,10 @@ int walMetaDeserialize(SWal* pWal, const char* bytes) { pWal->writeCur = sz - 1; cJSON_Delete(pRoot); return 0; + +_err: + cJSON_Delete(pRoot); + return -1; } static int walFindCurMetaVer(SWal* pWal) { @@ -562,22 +730,63 @@ static int walFindCurMetaVer(SWal* pWal) { int walSaveMeta(SWal* pWal) { int metaVer = walFindCurMetaVer(pWal); char fnameStr[WAL_FILE_LEN]; - walBuildMetaName(pWal, metaVer + 1, fnameStr); - TdFilePtr pMetaFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE); + char tmpFnameStr[WAL_FILE_LEN]; + int n; + + // fsync the idx and log file at first to ensure validity of meta + if (taosFsyncFile(pWal->pIdxFile) < 0) { + wError("vgId:%d, failed to sync idx file due to %s", pWal->cfg.vgId, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + if (taosFsyncFile(pWal->pLogFile) < 0) { + wError("vgId:%d, failed to sync log file due to %s", pWal->cfg.vgId, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + // flush to a tmpfile + n = walBuildTmpMetaName(pWal, tmpFnameStr); + ASSERT(n < sizeof(tmpFnameStr) && "Buffer overflow of file name"); + + TdFilePtr pMetaFile = taosOpenFile(tmpFnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pMetaFile == NULL) { + wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } + char* serialized = walMetaSerialize(pWal); int len = strlen(serialized); if (len != taosWriteFile(pMetaFile, serialized, len)) { - // TODO:clean file + wError("vgId:%d, failed to write file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } - taosCloseFile(&pMetaFile); - taosRemoveFile(fnameStr); - return -1; + if (taosFsyncFile(pMetaFile) < 0) { + wError("vgId:%d, failed to sync file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + if (taosCloseFile(&pMetaFile) < 0) { + wError("vgId:%d, failed to close file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + // rename it + n = walBuildMetaName(pWal, metaVer + 1, fnameStr); + ASSERT(n < sizeof(fnameStr) && "Buffer overflow of file name"); + + if (taosRenameFile(tmpFnameStr, fnameStr) < 0) { + wError("failed to rename file due to %s. dest:%s", strerror(errno), fnameStr); + terrno = TAOS_SYSTEM_ERROR(errno); + goto _err; } - taosCloseFile(&pMetaFile); // delete old file if (metaVer > -1) { walBuildMetaName(pWal, metaVer, fnameStr); @@ -585,6 +794,11 @@ int walSaveMeta(SWal* pWal) { } taosMemoryFree(serialized); return 0; + +_err: + taosCloseFile(&pMetaFile); + taosMemoryFree(serialized); + return -1; } int walLoadMeta(SWal* pWal) { @@ -626,6 +840,10 @@ int walLoadMeta(SWal* pWal) { } // load into fileInfoSet int code = walMetaDeserialize(pWal, buf); + if (code < 0) { + wError("failed to deserialize wal meta. file:%s", fnameStr); + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + } taosCloseFile(&pFile); taosMemoryFree(buf); return code; @@ -636,6 +854,5 @@ int walRemoveMeta(SWal* pWal) { if (metaVer == -1) return 0; char fnameStr[WAL_FILE_LEN]; walBuildMetaName(pWal, metaVer, fnameStr); - taosRemoveFile(fnameStr); - return 0; + return taosRemoveFile(fnameStr); } diff --git a/source/libs/wal/src/walMgmt.c b/source/libs/wal/src/walMgmt.c index 7974f3e32e52b7434086bf438ba84c6e9772407b..29058cada1ce665882606ee186074a44452d6533 100644 --- a/source/libs/wal/src/walMgmt.c +++ b/source/libs/wal/src/walMgmt.c @@ -81,6 +81,12 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { return NULL; } + if (taosThreadMutexInit(&pWal->mutex, NULL) < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + taosMemoryFree(pWal); + return NULL; + } + // set config memcpy(&pWal->cfg, pCfg, sizeof(SWalCfg)); @@ -98,15 +104,14 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { tstrncpy(pWal->path, path, sizeof(pWal->path)); if (taosMkDir(pWal->path) != 0) { wError("vgId:%d, path:%s, failed to create directory since %s", pWal->cfg.vgId, pWal->path, strerror(errno)); - taosMemoryFree(pWal); - return NULL; + goto _err; } // init ref pWal->pRefHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK); if (pWal->pRefHash == NULL) { - taosMemoryFree(pWal); - return NULL; + wError("failed to init hash since %s", tstrerror(terrno)); + goto _err; } // open meta @@ -117,9 +122,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { pWal->fileInfoSet = taosArrayInit(8, sizeof(SWalFileInfo)); if (pWal->fileInfoSet == NULL) { wError("vgId:%d, path:%s, failed to init taosArray %s", pWal->cfg.vgId, pWal->path, strerror(errno)); - taosHashCleanup(pWal->pRefHash); - taosMemoryFree(pWal); - return NULL; + goto _err; } // init status @@ -131,46 +134,37 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { pWal->writeHead.head.protoVer = WAL_PROTO_VER; pWal->writeHead.magic = WAL_MAGIC; - if (taosThreadMutexInit(&pWal->mutex, NULL) < 0) { - taosArrayDestroy(pWal->fileInfoSet); - taosHashCleanup(pWal->pRefHash); - taosMemoryFree(pWal); - return NULL; - } - - pWal->refId = taosAddRef(tsWal.refSetId, pWal); - if (pWal->refId < 0) { - taosHashCleanup(pWal->pRefHash); - taosThreadMutexDestroy(&pWal->mutex); - taosArrayDestroy(pWal->fileInfoSet); - taosMemoryFree(pWal); - return NULL; - } - - walLoadMeta(pWal); + // load meta + (void)walLoadMeta(pWal); if (walCheckAndRepairMeta(pWal) < 0) { wError("vgId:%d cannot open wal since repair meta file failed", pWal->cfg.vgId); - taosHashCleanup(pWal->pRefHash); - taosRemoveRef(tsWal.refSetId, pWal->refId); - taosThreadMutexDestroy(&pWal->mutex); - taosArrayDestroy(pWal->fileInfoSet); - return NULL; + goto _err; } if (walCheckAndRepairIdx(pWal) < 0) { wError("vgId:%d cannot open wal since repair idx file failed", pWal->cfg.vgId); - taosHashCleanup(pWal->pRefHash); - taosRemoveRef(tsWal.refSetId, pWal->refId); - taosThreadMutexDestroy(&pWal->mutex); - taosArrayDestroy(pWal->fileInfoSet); - return NULL; + goto _err; + } + + // add ref + pWal->refId = taosAddRef(tsWal.refSetId, pWal); + if (pWal->refId < 0) { + wError("failed to add ref for Wal since %s", tstrerror(terrno)); + goto _err; } wDebug("vgId:%d, wal:%p is opened, level:%d fsyncPeriod:%d", pWal->cfg.vgId, pWal, pWal->cfg.level, pWal->cfg.fsyncPeriod); - return pWal; + +_err: + taosArrayDestroy(pWal->fileInfoSet); + taosHashCleanup(pWal->pRefHash); + taosThreadMutexDestroy(&pWal->mutex); + taosMemoryFree(pWal); + pWal = NULL; + return NULL; } int32_t walAlter(SWal *pWal, SWalCfg *pCfg) { @@ -195,11 +189,11 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) { void walClose(SWal *pWal) { taosThreadMutexLock(&pWal->mutex); + (void)walSaveMeta(pWal); taosCloseFile(&pWal->pLogFile); pWal->pLogFile = NULL; taosCloseFile(&pWal->pIdxFile); pWal->pIdxFile = NULL; - walSaveMeta(pWal); taosArrayDestroy(pWal->fileInfoSet); pWal->fileInfoSet = NULL; taosHashCleanup(pWal->pRefHash); diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index c4f1a81eeb10a46594efc9e2c4bfa89228b16ed6..179d809c84c5773c138ae7dc35284d5b3fb461eb 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -181,7 +181,11 @@ int32_t walReadSeekVerImpl(SWalReader *pReader, int64_t ver) { SWalFileInfo tmpInfo; tmpInfo.firstVer = ver; SWalFileInfo *pRet = taosArraySearch(pWal->fileInfoSet, &tmpInfo, compareWalFileInfo, TD_LE); - ASSERT(pRet != NULL); + if (pRet == NULL) { + wError("failed to find WAL log file with ver:%lld", ver); + terrno = TSDB_CODE_WAL_INVALID_VER; + return -1; + } if (pReader->curFileFirstVer != pRet->firstVer) { // error code was set inner if (walReadChangeFile(pReader, pRet->firstVer) < 0) { @@ -472,7 +476,8 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) { } else { terrno = TSDB_CODE_WAL_FILE_CORRUPTED; } - ASSERT(0); + wError("vgId:%d, failed to read WAL record head, index:%" PRId64 ", from log file since %s", + pReader->pWal->cfg.vgId, ver, terrstr()); taosThreadMutexUnlock(&pReader->mutex); return -1; } @@ -505,6 +510,8 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) { else { terrno = TSDB_CODE_WAL_FILE_CORRUPTED; } + wError("vgId:%d, failed to read WAL record body, index:%" PRId64 ", from log file since %s", + pReader->pWal->cfg.vgId, ver, terrstr()); taosThreadMutexUnlock(&pReader->mutex); return -1; } @@ -514,7 +521,6 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) { pReader->pHead->head.version, ver); pReader->curInvalid = 1; terrno = TSDB_CODE_WAL_FILE_CORRUPTED; - ASSERT(0); taosThreadMutexUnlock(&pReader->mutex); return -1; } @@ -528,7 +534,6 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) { wError("checksum written into log:%u, checksum calculated:%u", logCkSum, readCkSum); pReader->curInvalid = 1; terrno = TSDB_CODE_WAL_FILE_CORRUPTED; - ASSERT(0); taosThreadMutexUnlock(&pReader->mutex); return -1; } diff --git a/source/libs/wal/src/walSeek.c b/source/libs/wal/src/walSeek.c index 1196914daea766159f20b507d2bfb908d6c309e0..4b75db52b710fd5a084ba1c13f5270006d385967 100644 --- a/source/libs/wal/src/walSeek.c +++ b/source/libs/wal/src/walSeek.c @@ -79,6 +79,11 @@ int64_t walChangeWrite(SWal* pWal, int64_t ver) { TdFilePtr pIdxTFile, pLogTFile; char fnameStr[WAL_FILE_LEN]; if (pWal->pLogFile != NULL) { + code = taosFsyncFile(pWal->pLogFile); + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } code = taosCloseFile(&pWal->pLogFile); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -86,6 +91,11 @@ int64_t walChangeWrite(SWal* pWal, int64_t ver) { } } if (pWal->pIdxFile != NULL) { + code = taosFsyncFile(pWal->pIdxFile); + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } code = taosCloseFile(&pWal->pIdxFile); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(errno); diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 628b432446dd8e1d650b07d0a00d16ed108ec5fb..1e5c63fa8d1ba35ea160e93f7a3b8bf785c0aaf0 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -42,10 +42,20 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) { SWalFileInfo *pFileInfo = taosArrayGet(pWal->fileInfoSet, i); char fnameStr[WAL_FILE_LEN]; walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); - taosRemoveFile(fnameStr); + if (taosRemoveFile(fnameStr) < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + wError("vgId:%d restore from snapshot, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); + return -1; + } + wInfo("vgId:%d restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr); walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); - taosRemoveFile(fnameStr); + if (taosRemoveFile(fnameStr) < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + wError("vgId:%d cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); + return -1; + } + wInfo("vgId:%d restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr); } } walRemoveMeta(pWal); @@ -209,10 +219,12 @@ int32_t walRollback(SWal *pWal, int64_t ver) { taosCloseFile(&pIdxFile); taosCloseFile(&pLogFile); - taosFsyncFile(pWal->pLogFile); - taosFsyncFile(pWal->pIdxFile); - - walSaveMeta(pWal); + code = walSaveMeta(pWal); + if (code < 0) { + wError("vgId:%d, failed to save meta since %s", pWal->cfg.vgId, terrstr()); + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } // unlock taosThreadMutexUnlock(&pWal->mutex); @@ -384,7 +396,11 @@ int32_t walRollImpl(SWal *pWal) { pWal->lastRollSeq = walGetSeq(); - walSaveMeta(pWal); + code = walSaveMeta(pWal); + if (code < 0) { + wError("vgId:%d, failed to save meta since %s", pWal->cfg.vgId, terrstr()); + goto END; + } END: return code; @@ -540,6 +556,11 @@ int32_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, in void walFsync(SWal *pWal, bool forceFsync) { if (forceFsync || (pWal->cfg.level == TAOS_WAL_FSYNC && pWal->cfg.fsyncPeriod == 0)) { + wTrace("vgId:%d, fileId:%" PRId64 ".idx, do fsync", pWal->cfg.vgId, walGetCurFileFirstVer(pWal)); + if (taosFsyncFile(pWal->pIdxFile) < 0) { + wError("vgId:%d, file:%" PRId64 ".idx, fsync failed since %s", pWal->cfg.vgId, walGetCurFileFirstVer(pWal), + strerror(errno)); + } wTrace("vgId:%d, fileId:%" PRId64 ".log, do fsync", pWal->cfg.vgId, walGetCurFileFirstVer(pWal)); if (taosFsyncFile(pWal->pLogFile) < 0) { wError("vgId:%d, file:%" PRId64 ".log, fsync failed since %s", pWal->cfg.vgId, walGetCurFileFirstVer(pWal), diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c index f0442c6fd12a352bc41c36104ed87551de8236e2..616ab7875dd9634b4ad4258c51320b589dd744ae 100644 --- a/source/os/src/osEnv.c +++ b/source/os/src/osEnv.c @@ -87,11 +87,17 @@ void osUpdate() { void osCleanup() {} -bool osLogSpaceAvailable() { return tsLogSpace.reserved <= tsLogSpace.size.avail; } +bool osLogSpaceAvailable() { return tsLogSpace.size.avail > 0; } -bool osDataSpaceAvailable() { return tsDataSpace.reserved <= tsDataSpace.size.avail; } +bool osDataSpaceAvailable() { return tsDataSpace.size.avail > 0; } -bool osTempSpaceAvailable() { return tsTempSpace.reserved <= tsTempSpace.size.avail; } +bool osTempSpaceAvailable() { return tsTempSpace.size.avail > 0; } + +bool osLogSpaceSufficient() { return tsLogSpace.size.avail > tsLogSpace.reserved; } + +bool osDataSpaceSufficient() { return tsDataSpace.size.avail > tsDataSpace.reserved; } + +bool osTempSpaceSufficient() { return tsTempSpace.size.avail > tsTempSpace.reserved; } void osSetTimezone(const char *timezone) { taosSetSystemTimezone(timezone, tsTimezoneStr, &tsDaylight, &tsTimezone); } diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index 8f026f68907f16953ef8e1149ccaaf908dab2f3a..75a963d5c7551ad290d1d2190c24ab07e1ed0953 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -228,7 +228,7 @@ void taosPrintBackTrace() { void taosPrintBackTrace() { return; } #endif -void *taosMemoryMalloc(int32_t size) { +void *taosMemoryMalloc(int64_t size) { #ifdef USE_TD_MEMORY void *tmp = malloc(size + sizeof(TdMemoryInfo)); if (tmp == NULL) return NULL; @@ -244,7 +244,7 @@ void *taosMemoryMalloc(int32_t size) { #endif } -void *taosMemoryCalloc(int32_t num, int32_t size) { +void *taosMemoryCalloc(int64_t num, int64_t size) { #ifdef USE_TD_MEMORY int32_t memorySize = num * size; char *tmp = calloc(memorySize + sizeof(TdMemoryInfo), 1); @@ -261,7 +261,7 @@ void *taosMemoryCalloc(int32_t num, int32_t size) { #endif } -void *taosMemoryRealloc(void *ptr, int32_t size) { +void *taosMemoryRealloc(void *ptr, int64_t size) { #ifdef USE_TD_MEMORY if (ptr == NULL) return taosMemoryMalloc(size); @@ -318,7 +318,7 @@ void taosMemoryFree(void *ptr) { #endif } -int32_t taosMemorySize(void *ptr) { +int64_t taosMemorySize(void *ptr) { if (ptr == NULL) return 0; #ifdef USE_TD_MEMORY diff --git a/source/util/src/terror.c b/source/util/src/terror.c index eb13a08be442ea0365a5e71d01cf1e5f1d999d04..9a117c6eb48c1bc06d4063101531579ba6369fb4 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -447,12 +447,13 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND, "TQ table schema not f TAOS_DEFINE_ERROR(TSDB_CODE_TQ_NO_COMMITTED_OFFSET, "TQ no commited offset") // wal -TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, "Wal unexpected generic error") +TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, "WAL unexpected generic error") TAOS_DEFINE_ERROR(TSDB_CODE_WAL_FILE_CORRUPTED, "WAL file is corrupted") TAOS_DEFINE_ERROR(TSDB_CODE_WAL_SIZE_LIMIT, "WAL size exceeds limit") TAOS_DEFINE_ERROR(TSDB_CODE_WAL_INVALID_VER, "WAL use invalid version") TAOS_DEFINE_ERROR(TSDB_CODE_WAL_OUT_OF_MEMORY, "WAL out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_WAL_LOG_NOT_EXIST, "WAL log not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_WAL_CHKSUM_MISMATCH, "WAL checksum mismatch") // tfs TAOS_DEFINE_ERROR(TSDB_CODE_FS_INVLD_CFG, "tfs invalid mount config") diff --git a/source/util/src/trbtree.c b/source/util/src/trbtree.c index 65f1bac60aa51c48fe65895dbe0ded241d22590d..cbbf53d8f1c18e4770c513bc678fc68646268ff7 100644 --- a/source/util/src/trbtree.c +++ b/source/util/src/trbtree.c @@ -219,7 +219,7 @@ SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *z) { while (temp != pTree->NIL) { y = temp; - int32_t c = pTree->cmprFn(RBTREE_NODE_PAYLOAD(z), RBTREE_NODE_PAYLOAD(temp)); + int32_t c = pTree->cmprFn(z, temp); if (c < 0) { temp = temp->left; } else if (c > 0) { @@ -232,7 +232,7 @@ SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *z) { if (y == pTree->NIL) { pTree->root = z; - } else if (pTree->cmprFn(RBTREE_NODE_PAYLOAD(z), RBTREE_NODE_PAYLOAD(y)) < 0) { + } else if (pTree->cmprFn(z, y) < 0) { y->left = z; } else { y->right = z; @@ -245,10 +245,10 @@ SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *z) { tRBTreePutFix(pTree, z); // update min/max node - if (pTree->min == pTree->NIL || pTree->cmprFn(RBTREE_NODE_PAYLOAD(pTree->min), RBTREE_NODE_PAYLOAD(z)) > 0) { + if (pTree->min == pTree->NIL || pTree->cmprFn(pTree->min, z) > 0) { pTree->min = z; } - if (pTree->max == pTree->NIL || pTree->cmprFn(RBTREE_NODE_PAYLOAD(pTree->max), RBTREE_NODE_PAYLOAD(z)) < 0) { + if (pTree->max == pTree->NIL || pTree->cmprFn(pTree->max, z) < 0) { pTree->max = z; } pTree->n++; @@ -309,11 +309,11 @@ SRBTreeNode *tRBTreeDropByKey(SRBTree *pTree, void *pKey) { return pNode; } -SRBTreeNode *tRBTreeGet(SRBTree *pTree, void *pKey) { +SRBTreeNode *tRBTreeGet(SRBTree *pTree, const SRBTreeNode *pKeyNode) { SRBTreeNode *pNode = pTree->root; while (pNode != pTree->NIL) { - int32_t c = pTree->cmprFn(pKey, RBTREE_NODE_PAYLOAD(pNode)); + int32_t c = pTree->cmprFn(pKeyNode, pNode); if (c < 0) { pNode = pNode->left; diff --git a/source/util/src/tskiplist.c b/source/util/src/tskiplist.c index 4ce668e6bab22abc74f509114ab84b0693469634..d93e9fc5695904995041307b1ec333f780ff2b6f 100644 --- a/source/util/src/tskiplist.c +++ b/source/util/src/tskiplist.c @@ -145,7 +145,10 @@ void tSkipListPutBatchByIter(SSkipList *pSkipList, void *iter, iter_next_fn_t it tSkipListWLock(pSkipList); void *pData = iterate(iter); - if (pData == NULL) return; + if (pData == NULL) { + tSkipListUnlock(pSkipList); + return; + } // backward to put the first data hasDup = tSkipListGetPosToPut(pSkipList, backward, pData); diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/default_json.py b/tests/develop-test/5-taos-tools/taosbenchmark/default_json.py index 0a835ec5643d8901db475dddcdaf60d0baf317c9..c68375894c6f34bdccc33789384f6113aeb6e105 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/default_json.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/default_json.py @@ -32,6 +32,10 @@ class TDTestCase: if "community" in selfPath: projPath = selfPath[: selfPath.find("community")] + elif "src" in selfPath: + projPath = selfPath[: selfPath.find("src")] + elif "/tools/" in selfPath: + projPath = selfPath[: selfPath.find("/tools/")] else: projPath = selfPath[: selfPath.find("tests")] @@ -55,11 +59,10 @@ class TDTestCase: tdLog.info("%s" % cmd) os.system("%s" % cmd) tdSql.execute("reset query cache") - tdSql.query("select count(*) from (select distinct(tbname) from db.stb)") - tdSql.checkData(0, 0, 10) + tdSql.query("show db.tables") + tdSql.checkRows(10) tdSql.query("select count(*) from db.stb") - if len(tdSql.queryResult): - tdLog.exit("query result is %d" % len(tdSql.queryResult)) + tdSql.checkData(0, 0, 100) def stop(self): tdSql.close() diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/json/default.json b/tests/develop-test/5-taos-tools/taosbenchmark/json/default.json index d4b2aae2fb7bf1a3612e60f395a1c5ed26ceca8f..da22ef75e2a648e897341338bb762e4fedc6662b 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/json/default.json +++ b/tests/develop-test/5-taos-tools/taosbenchmark/json/default.json @@ -20,8 +20,10 @@ "super_tables": [{ "name": "stb", "childtable_prefix": "stb_", + "childtable_count": 10, + "insert_rows": 10, "columns": [{"type": "INT"}], "tags": [{"type": "INT"}] }] }] -} \ No newline at end of file +} diff --git a/tests/script/coverage_test.sh b/tests/script/coverage_test.sh new file mode 100755 index 0000000000000000000000000000000000000000..457c9eae20795d03cc0b63de7f81df68cb91d735 --- /dev/null +++ b/tests/script/coverage_test.sh @@ -0,0 +1,291 @@ +#!/bin/bash + +branch= +if [ x$1 != x ];then + branch=$1 + echo "Testing branch: $branch" +else + echo "Please enter branch name as a parameter" + exit 1 +fi + +today=`date +"%Y%m%d"` +TDENGINE_DIR=/root/pxiao/TDengine +TDENGINE_COVERAGE_REPORT=$TDENGINE_DIR/tests/coverage-report-$today.log + +# Color setting +RED='\033[0;31m' +GREEN='\033[1;32m' +GREEN_DARK='\033[0;32m' +GREEN_UNDERLINE='\033[4;32m' +NC='\033[0m' + +function buildTDengine { + echo "check if TDengine need build" + cd $TDENGINE_DIR + git remote prune origin > /dev/null + git remote update > /dev/null + REMOTE_COMMIT=`git rev-parse --short remotes/origin/$branch` + LOCAL_COMMIT=`git rev-parse --short @` + echo " LOCAL: $LOCAL_COMMIT" + echo "REMOTE: $REMOTE_COMMIT" + + # reset counter + lcov -d . --zerocounters + + + if [ "$LOCAL_COMMIT" == "$REMOTE_COMMIT" ]; then + echo "repo up-to-date" + else + echo "repo need to pull" + fi + + git reset --hard + git checkout -- . + git checkout $branch + git clean -dfx + git pull + git submodule update --init --recursive -f + + [ -d $TDENGINE_DIR/debug ] || mkdir $TDENGINE_DIR/debug + cd $TDENGINE_DIR/debug + + echo "rebuild.." + LOCAL_COMMIT=`git rev-parse --short @` + + rm -rf * + if [ "$branch" == "3.0" ]; then + echo "3.0 =============" + cmake -DCOVER=true -DBUILD_TEST=true .. + else + cmake -DCOVER=true -DBUILD_TOOLS=true -DBUILD_HTTP=false .. > /dev/null + fi + make -j4 + make install +} + +function runGeneralCaseOneByOne { + while read -r line; do + if [[ $line =~ ^./test.sh* ]]; then + case=`echo $line | grep sim$ | awk '{print $NF}'` + + if [ -n "$case" ]; then + date +%F\ %T | tee -a $TDENGINE_COVERAGE_REPORT && ./test.sh -f $case > /dev/null 2>&1 && \ + echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_COVERAGE_REPORT \ + || echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_COVERAGE_REPORT + fi + fi + done < $1 +} + +function runTestNGCaseOneByOne { + while read -r line; do + if [[ $line =~ ^taostest* ]]; then + case=`echo $line | cut -d' ' -f 3 | cut -d'=' -f 2` + yaml=`echo $line | cut -d' ' -f 2` + + if [ -n "$case" ]; then + date +%F\ %T | tee -a $TDENGINE_COVERAGE_REPORT && taostest $yaml --case=$case --keep --disable_collection > /dev/null 2>&1 && \ + echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_COVERAGE_REPORT \ + || echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_COVERAGE_REPORT + fi + fi + done < $1 +} + +function runTest { + echo "run Test" + + if [ "$branch" == "3.0" ]; then + echo "start run unit test case ................" + echo " $TDENGINE_DIR/debug " + cd $TDENGINE_DIR/debug + ctest -j12 + echo "3.0 unit test done" + fi + + cd $TDENGINE_DIR/tests/script + + [ -d ../../sim ] && rm -rf ../../sim + [ -f $TDENGINE_COVERAGE_REPORT ] && rm $TDENGINE_COVERAGE_REPORT + + runGeneralCaseOneByOne jenkins/basic.txt + + sed -i "1i\SIM cases test result" $TDENGINE_COVERAGE_REPORT + + totalSuccess=`grep 'success' $TDENGINE_COVERAGE_REPORT | wc -l` + if [ "$totalSuccess" -gt "0" ]; then + sed -i -e "2i\ ### Total $totalSuccess SIM test case(s) succeed! ###" $TDENGINE_COVERAGE_REPORT + fi + + totalFailed=`grep 'failed\|fault' $TDENGINE_COVERAGE_REPORT | wc -l` + if [ "$totalFailed" -ne "0" ]; then + sed -i "3i\### Total $totalFailed SIM test case(s) failed! ###" $TDENGINE_COVERAGE_REPORT + fi + sed "3G" $TDENGINE_COVERAGE_REPORT + + stopTaosd + echo "run TestNG cases" + rm -rf /var/lib/taos/* + rm -rf /var/log/taos/* + nohup $TDENGINE_DIR/debug/build/bin/taosd -c /etc/taos > /dev/null 2>&1 & + sleep 10 + cd $TDENGINE_DIR/../TestNG/cases + runTestNGCaseOneByOne ../scripts/cases.txt + echo "TestNG cases done" + + cd $TDENGINE_DIR/tests + rm -rf ../sim + /root/pxiao/test-all-coverage.sh full python $branch | tee -a $TDENGINE_COVERAGE_REPORT + + + sed -i "4i\Python cases test result" $TDENGINE_COVERAGE_REPORT + totalPySuccess=`grep 'python case(s) succeed!' $TDENGINE_COVERAGE_REPORT | awk '{print $4}'` + if [ "$totalPySuccess" -gt "0" ]; then + sed -i -e "5i\ ### Total $totalPySuccess Python test case(s) succeed! ###" $TDENGINE_COVERAGE_REPORT + fi + + totalPyFailed=`grep 'python case(s) failed!' $TDENGINE_COVERAGE_REPORT | awk '{print $4}'` + if [ -z $totalPyFailed ]; then + sed -i "6i\\n" $TDENGINE_COVERAGE_REPORT + else + sed -i "6i\### Total $totalPyFailed Python test case(s) failed! ###" $TDENGINE_COVERAGE_REPORT + fi + + echo "### run JDBC test cases ###" | tee -a $TDENGINE_COVERAGE_REPORT + # Test Connector + stopTaosd + nohup $TDENGINE_DIR/debug/build/bin/taosd -c /etc/taos > /dev/null 2>&1 & + sleep 10 + + cd $TDENGINE_DIR/src/connector/jdbc + mvn clean package > /dev/null 2>&1 + mvn test > jdbc-out.log 2>&1 + tail -n 20 jdbc-out.log 2>&1 | tee -a $TDENGINE_COVERAGE_REPORT + + # Test C Demo + stopTaosd + $TDENGINE_DIR/debug/build/bin/taosd -c $TDENGINE_DIR/debug/test/cfg > /dev/null & + sleep 10 + yes | $TDENGINE_DIR/debug/build/bin/demo 127.0.0.1 > /dev/null 2>&1 | tee -a $TDENGINE_COVERAGE_REPORT + + # Test waltest + dataDir=`grep dataDir $TDENGINE_DIR/debug/test/cfg/taos.cfg|awk '{print $2}'` + walDir=`find $dataDir -name "wal"|head -n1` + echo "dataDir: $dataDir" | tee -a $TDENGINE_COVERAGE_REPORT + echo "walDir: $walDir" | tee -a $TDENGINE_COVERAGE_REPORT + if [ -n "$walDir" ]; then + yes | $TDENGINE_DIR/debug/build/bin/waltest -p $walDir > /dev/null 2>&1 | tee -a $TDENGINE_COVERAGE_REPORT + fi + + # run Unit Test + echo "Run Unit Test: utilTest, queryTest and cliTest" + #$TDENGINE_DIR/debug/build/bin/utilTest > /dev/null 2>&1 && echo "utilTest pass!" || echo "utilTest failed!" + #$TDENGINE_DIR/debug/build/bin/queryTest > /dev/null 2>&1 && echo "queryTest pass!" || echo "queryTest failed!" + #$TDENGINE_DIR/debug/build/bin/cliTest > /dev/null 2>&1 && echo "cliTest pass!" || echo "cliTest failed!" + + stopTaosd + + cd $TDENGINE_DIR/tests/script + find . -name '*.sql' | xargs rm -f + + cd $TDENGINE_DIR/tests/pytest + find . -name '*.sql' | xargs rm -f +} + +function lcovFunc { + echo "collect data by lcov" + cd $TDENGINE_DIR + + # collect data + lcov -d . --capture --rc lcov_branch_coverage=1 --rc genhtml_branch_coverage=1 --no-external -b $TDENGINE_DIR -o coverage.info + + # remove exclude paths + if [ "$branch" == "3.0" ]; then + lcov --remove coverage.info \ + '*/contrib/*' '*/tests/*' '*/test/*'\ + '*/AccessBridgeCalls.c' '*/ttszip.c' '*/dataInserter.c' '*/tlinearhash.c' '*/tsimplehash.c'\ + '*/texpr.c' '*/runUdf.c' '*/schDbg.c' '*/syncIO.c' '*/tdbOs.c' '*/pushServer.c' '*/osLz4.c'\ + '*/tbase64.c' '*/tbuffer.c' '*/tdes.c' '*/texception.c' '*/tidpool.c' '*/tmempool.c'\ + '*/tthread.c' '*/tversion.c'\ + --rc lcov_branch_coverage=1 -o coverage.info + else + lcov --remove coverage.info \ + '*/tests/*' '*/test/*' '*/deps/*' '*/plugins/*' '*/taosdef.h' '*/ttype.h' '*/tarithoperator.c' '*/TSDBJNIConnector.c' '*/taosdemo.c'\ + --rc lcov_branch_coverage=1 -o coverage.info + fi + + + # generate result + echo "generate result" + lcov -l --rc lcov_branch_coverage=1 coverage.info | tee -a $TDENGINE_COVERAGE_REPORT + + # push result to coveralls.io + echo "push result to coveralls.io" + /usr/local/bin/coveralls-lcov coverage.info -t o7uY02qEAgKyJHrkxLGiCOTfL3IGQR2zm | tee -a $TDENGINE_COVERAGE_REPORT + + #/root/pxiao/checkCoverageFile.sh -s $TDENGINE_DIR/source -f $TDENGINE_COVERAGE_REPORT + #cat /root/pxiao/fileListNoCoverage.log | tee -a $TDENGINE_COVERAGE_REPORT + cat $TDENGINE_COVERAGE_REPORT | grep "| 0.0%" | awk -F "%" '{print $1}' | awk -F "|" '{if($2==0.0)print $1}' | tee -a $TDENGINE_COVERAGE_REPORT + +} + +function sendReport { + echo "send report" + receiver="develop@taosdata.com" + mimebody="MIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n" + + cd $TDENGINE_DIR + + sed -i 's/\x1b\[[0-9;]*m//g' $TDENGINE_COVERAGE_REPORT + BODY_CONTENT=`cat $TDENGINE_COVERAGE_REPORT` + echo -e "from: \nto: ${receiver}\nsubject: Coverage test report ${branch} ${today}, commit ID: ${LOCAL_COMMIT}\n\n${today}:\n${BODY_CONTENT}" | \ + (cat - && uuencode $TDENGINE_COVERAGE_REPORT coverage-report-$today.log) | \ + /usr/sbin/ssmtp "${receiver}" && echo "Report Sent!" +} + +function stopTaosd { + echo "Stop taosd start" + systemctl stop taosd + PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'` + while [ -n "$PID" ] + do + pkill -TERM -x taosd + sleep 1 + PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'` + done + echo "Stop tasod end" +} + +function runTestRandomFail { + exec_random_fail_sh=$1 + default_exec_sh=$TDENGINE_DIR/tests/script/sh/exec.sh + [ -f $exec_random_fail_sh ] && cp $exec_random_fail_sh $default_exec_sh || exit 1 + + dnodes_random_fail_py=$TDENGINE_DIR/tests/pytest/util/dnodes-no-random-fail.py + default_dnodes_py=$TDENGINE_DIR/tests/pytest/util/dnodes.py + [ -f $dnodes_random_fail_py ] && cp $dnodes_random_fail_py $default_dnodes_py || exit 1 + + runTest NoRandomFail +} + +WORK_DIR=/root/pxiao + +date >> $WORK_DIR/cron.log +echo "Run Coverage Test" | tee -a $WORK_DIR/cron.log + +stopTaosd +buildTDengine + +#runTestRandomFail $TDENGINE_DIR/tests/script/sh/exec-random-fail.sh +#runTestRandomFail $TDENGINE_DIR/tests/script/sh/exec-default.sh +#runTestRandomFail $TDENGINE_DIR/tests/script/sh/exec-no-random-fail.sh + +runTest + +lcovFunc +#sendReport +stopTaosd + +date >> $WORK_DIR/cron.log +echo "End of Coverage Test" | tee -a $WORK_DIR/cron.log diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 82f73a4fdd209e84d85d8616ece777cf37e02dfb..d8f4a36261d3607d91b89d42aa06fbbd1b01ab57 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -155,7 +155,7 @@ ./test.sh -f tsim/parser/select_with_tags.sim ./test.sh -f tsim/parser/selectResNum.sim ./test.sh -f tsim/parser/set_tag_vals.sim -./test.sh -f tsim/parser/single_row_in_tb.sim +# TD-19572 ./test.sh -f tsim/parser/single_row_in_tb.sim ./test.sh -f tsim/parser/sliding.sim ./test.sh -f tsim/parser/slimit_alter_tags.sim ./test.sh -f tsim/parser/slimit.sim @@ -194,7 +194,7 @@ ./test.sh -f tsim/mnode/basic1.sim ./test.sh -f tsim/mnode/basic2.sim ./test.sh -f tsim/mnode/basic3.sim -# TD-17919 ./test.sh -f tsim/mnode/basic4.sim +./test.sh -f tsim/mnode/basic4.sim ./test.sh -f tsim/mnode/basic5.sim # ---- show ---- @@ -352,6 +352,7 @@ ./test.sh -f tsim/scalar/in.sim ./test.sh -f tsim/scalar/scalar.sim ./test.sh -f tsim/scalar/filter.sim +./test.sh -f tsim/scalar/caseWhen.sim # ---- alter ---- ./test.sh -f tsim/alter/cached_schema_after_alter.sim diff --git a/tests/script/tsim/mnode/basic1.sim b/tests/script/tsim/mnode/basic1.sim index 59156080c823c9b54b29ce7da864e04198ca5aac..31fc276298e85bdc852ced81f5e1c765058378f8 100644 --- a/tests/script/tsim/mnode/basic1.sim +++ b/tests/script/tsim/mnode/basic1.sim @@ -42,6 +42,7 @@ sql_error drop mnode on dnode 1 print =============== create mnode 2 sql create mnode on dnode 2 +print =============== create mnode 2 finished $x = 0 step2: $x = $x + 1 @@ -69,9 +70,10 @@ if $data(2)[2] != follower then goto step2 endi -sleep 2000 print ============ drop mnode 2 sql drop mnode on dnode 2 + +print ============ drop mnode 2 finished sql select * from information_schema.ins_mnodes if $rows != 1 then return -1 @@ -109,6 +111,8 @@ sleep 2000 print =============== create mnodes sql create mnode on dnode 2 + +print =============== create mnode 2 finished sql select * from information_schema.ins_mnodes if $rows != 2 then return -1 diff --git a/tests/script/tsim/mnode/basic4.sim b/tests/script/tsim/mnode/basic4.sim index a2b8aa2f967a6c8e56ed4281b25cbef3400615d2..6739a87b4233f4b57f70d886494ff5a8c55f7058 100644 --- a/tests/script/tsim/mnode/basic4.sim +++ b/tests/script/tsim/mnode/basic4.sim @@ -45,49 +45,12 @@ endi if $data(2)[4] != ready then goto step2 endi - -system sh/exec.sh -n dnode3 -s stop -sql_error create mnode on dnode 3 - -print =============== step3: select * from information_schema.ins_mnodes - -$x = 0 -step3: - $x = $x + 1 - sleep 1000 - if $x == 10 then - return -1 - endi -sql select * from information_schema.ins_mnodes -x step3 -print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] -print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] -print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] - -$leaderNum = 0 -if $data(1)[2] == leader then - $leaderNum = 1 -endi -if $data(2)[2] == leader then - $leaderNum = 1 -endi -if $leaderNum == 0 then - goto step3 -endi -if $data(3)[2] != offline then - goto step3 -endi -if $data(1)[3] != ready then - goto step3 -endi -if $data(2)[3] != ready then - goto step3 -endi -if $data(3)[3] != creating then - goto step3 +if $data(3)[4] != ready then + goto step2 endi -print =============== step4: start dnode3 -system sh/exec.sh -n dnode3 -s start +print =============== step4: create mnode 3 +sql create mnode on dnode 3 $x = 0 step4: @@ -159,12 +122,11 @@ endi if $data(2)[3] != ready then goto step5 endi -if $data(3)[3] != dropping then - goto step5 -endi print =============== step6: start dnode3 system sh/exec.sh -n dnode3 -s start +sql drop mnode on dnode 1 -x step60 +step60: $x = 0 step6: diff --git a/tests/script/tsim/mnode/basic5.sim b/tests/script/tsim/mnode/basic5.sim index 387f38a71793a0d6dad928d398db8ebdfab97692..16e8fa3dfaf9d3b8254de7e013e2383ee17a9e01 100644 --- a/tests/script/tsim/mnode/basic5.sim +++ b/tests/script/tsim/mnode/basic5.sim @@ -232,12 +232,11 @@ endi if $leaderNum != 1 then goto step81 endi -if $data(1)[3] != dropping then - goto step81 -endi print =============== step9: start mnode1 and wait it dropped system sh/exec.sh -n dnode1 -s start +sql drop mnode on dnode 1 -x step90 +step90: $x = 0 step91: diff --git a/tests/script/tsim/scalar/caseWhen.sim b/tests/script/tsim/scalar/caseWhen.sim new file mode 100644 index 0000000000000000000000000000000000000000..f6b9c3ff081a69a16851b2f9fee6cd0d5c3935c3 --- /dev/null +++ b/tests/script/tsim/scalar/caseWhen.sim @@ -0,0 +1,1064 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +print ======== prepare data + +sql drop database if exists db1; +sql create database db1 vgroups 5; +sql use db1; +sql create stable sta (ts timestamp, f1 int, f2 binary(10), f3 bool) tags(t1 int, t2 bool, t3 binary(10)); +sql create table tba1 using sta tags(0, false, '0'); +sql create table tba2 using sta tags(1, true, '1'); +sql create table tba3 using sta tags(null, null, ''); +sql create table tba4 using sta tags(1, false, null); +sql create table tba5 using sta tags(3, true, 'aa'); +sql insert into tba1 values ('2022-09-26 15:15:01', 0, "a", false); +sql insert into tba1 values ('2022-09-26 15:15:02', 1, "0", true); +sql insert into tba1 values ('2022-09-26 15:15:03', 5, "5", false); +sql insert into tba1 values ('2022-09-26 15:15:04', null, null, null); +sql insert into tba2 values ('2022-09-27 15:15:01', 0, "a", false); +sql insert into tba2 values ('2022-09-27 15:15:02', 1, "0", true); +sql insert into tba2 values ('2022-09-27 15:15:03', 5, "5", false); +sql insert into tba2 values ('2022-09-27 15:15:04', null, null, null); +sql insert into tba3 values ('2022-09-28 15:15:01', 0, "a", false); +sql insert into tba3 values ('2022-09-28 15:15:02', 1, "0", true); +sql insert into tba3 values ('2022-09-28 15:15:03', 5, "5", false); +sql insert into tba3 values ('2022-09-28 15:15:04', null, null, null); +sql insert into tba4 values ('2022-09-29 15:15:01', 0, "a", false); +sql insert into tba4 values ('2022-09-29 15:15:02', 1, "0", true); +sql insert into tba4 values ('2022-09-29 15:15:03', 5, "5", false); +sql insert into tba4 values ('2022-09-29 15:15:04', null, null, null); +sql insert into tba5 values ('2022-09-30 15:15:01', 0, "a", false); +sql insert into tba5 values ('2022-09-30 15:15:02', 1, "0", true); +sql insert into tba5 values ('2022-09-30 15:15:03', 5, "5", false); +sql insert into tba5 values ('2022-09-30 15:15:04', null, null, null); + +print ======== case when xx + +sql select case when 3 then 4 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 4 then + return -1 +endi +if $data10 != 4 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data30 != 4 then + return -1 +endi + +sql select case when 0 then 4 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != NULL then + return -1 +endi +if $data20 != NULL then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select case when null then 4 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != NULL then + return -1 +endi +if $data20 != NULL then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select case when 1 then 4+1 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 5.000000000 then + return -1 +endi +if $data10 != 5.000000000 then + return -1 +endi +if $data20 != 5.000000000 then + return -1 +endi +if $data30 != 5.000000000 then + return -1 +endi + +sql select case when 1-1 then 0 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != NULL then + return -1 +endi +if $data20 != NULL then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select case when 1+1 then 0 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 0 then + return -1 +endi +if $data10 != 0 then + return -1 +endi +if $data20 != 0 then + return -1 +endi +if $data30 != 0 then + return -1 +endi + +sql select case when 1 then 1-1+2 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 2.000000000 then + return -1 +endi +if $data10 != 2.000000000 then + return -1 +endi +if $data20 != 2.000000000 then + return -1 +endi +if $data30 != 2.000000000 then + return -1 +endi + +sql select case when 1 > 0 then 1 < 2 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data10 != 1 then + return -1 +endi +if $data20 != 1 then + return -1 +endi +if $data30 != 1 then + return -1 +endi + +sql select case when 1 > 2 then 1 < 2 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != NULL then + return -1 +endi +if $data20 != NULL then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select case when abs(3) then abs(-1) end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data10 != 1 then + return -1 +endi +if $data20 != 1 then + return -1 +endi +if $data30 != 1 then + return -1 +endi + +sql select case when abs(1+1) then abs(-1)+abs(3) end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 4.000000000 then + return -1 +endi +if $data10 != 4.000000000 then + return -1 +endi +if $data20 != 4.000000000 then + return -1 +endi +if $data30 != 4.000000000 then + return -1 +endi + +sql select case when 0 then 1 else 3 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 3 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data20 != 3 then + return -1 +endi +if $data30 != 3 then + return -1 +endi + +sql select case when 0 then 1 when 1 then 0 else 3 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 0 then + return -1 +endi +if $data10 != 0 then + return -1 +endi +if $data20 != 0 then + return -1 +endi +if $data30 != 0 then + return -1 +endi + +sql select case when 0 then 1 when 1 then 0 when 2 then 3 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 0 then + return -1 +endi +if $data10 != 0 then + return -1 +endi +if $data20 != 0 then + return -1 +endi +if $data30 != 0 then + return -1 +endi + +sql select case when 'a' then 'b' when null then 0 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != NULL then + return -1 +endi +if $data20 != NULL then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select case when '2' then 'b' when null then 0 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != b then + return -1 +endi +if $data10 != b then + return -1 +endi +if $data20 != b then + return -1 +endi +if $data30 != b then + return -1 +endi + +sql select case when 0 then 'b' else null end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != NULL then + return -1 +endi +if $data20 != NULL then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select case when 0 then 'b' else 2 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 2 then + return -1 +endi +if $data10 != 2 then + return -1 +endi +if $data20 != 2 then + return -1 +endi +if $data30 != 2 then + return -1 +endi + +sql select case when sum(2) then sum(2)-sum(1) end from tba1; +if $rows != 1 then + return -1 +endi +if $data00 != 4.000000000 then + return -1 +endi + +sql select case when sum(2) then abs(-2) end from tba1; +if $rows != 1 then + return -1 +endi +if $data00 != 2 then + return -1 +endi + +sql select case when ts then ts end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != @22-09-26 15:15:01.000@ then + return -1 +endi +if $data10 != @22-09-26 15:15:02.000@ then + return -1 +endi +if $data20 != @22-09-26 15:15:03.000@ then + return -1 +endi +if $data30 != @22-09-26 15:15:04.000@ then + return -1 +endi + +sql select case when f1 then ts end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != @22-09-26 15:15:02.000@ then + return -1 +endi +if $data20 != @22-09-26 15:15:03.000@ then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select case when f1 then f1 when f1 + 1 then f1 + 1 else f1 is null end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data10 != 1 then + return -1 +endi +if $data20 != 5 then + return -1 +endi +if $data30 != 1 then + return -1 +endi + +sql select case when f1 then 3 when ts then ts end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 1664176501000 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data20 != 3 then + return -1 +endi +if $data30 != 1664176504000 then + return -1 +endi + +sql select case when 3 then f1 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 0 then + return -1 +endi +if $data10 != 1 then + return -1 +endi +if $data20 != 5 then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select case when f1 then 3 when 1 then 2 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 2 then + return -1 +endi +if $data10 != 3 then + return -1 +endi +if $data20 != 3 then + return -1 +endi +if $data30 != 2 then + return -1 +endi + +sql select case when sum(f1) then sum(f1)-abs(-1) end from tba1; +if $rows != 1 then + return -1 +endi +if $data00 != 5.000000000 then + return -1 +endi + +sql select case when sum(f1) then sum(f1)-abs(f1) end from tba1 group by f1 order by f1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != NULL then + return -1 +endi +if $data20 != 0.000000000 then + return -1 +endi +if $data30 != 0.000000000 then + return -1 +endi + +sql select case when f1 then sum(f1) when f1 is not null then 9 else 8 end from tba1 group by f1 order by f1; +if $rows != 4 then + return -1 +endi +if $data00 != 8 then + return -1 +endi +if $data10 != 9 then + return -1 +endi +if $data20 != 1 then + return -1 +endi +if $data30 != 5 then + return -1 +endi + +sql select f1 from tba1 where f1 > case when f1 then 0 else 3 end; +if $rows != 2 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data10 != 5 then + return -1 +endi + +sql select f1 from tba1 where ts > case when ts then ts end; +if $rows != 0 then + return -1 +endi + +sql select sum(f1),count(f1) from tba1 partition by case when f1 then f1 when 1 then 1 end; +if $rows != 2 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != 5 then + return -1 +endi +if $data11 != 1 then + return -1 +endi + +sql select case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end caseWhen, sum(f1),count(f1) from tba1 group by case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end order by caseWhen; +if $rows != 3 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 2 then + return -1 +endi +if $data10 != 2 then + return -1 +endi +if $data11 != 5 then + return -1 +endi +if $data12 != 1 then + return -1 +endi +if $data20 != 3 then + return -1 +endi +if $data21 != NULL then + return -1 +endi +if $data22 != 0 then + return -1 +endi + +sql select f1 from tba1 order by case when f1 <= 0 then 3 when f1 = 1 then 4 when f1 >= 3 then 2 else 1 end desc; +if $rows != 4 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data10 != 0 then + return -1 +endi +if $data20 != 5 then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select cast(case f1 when f1 then f1 + 1 else f1 is null end as double) from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 1.000000000 then + return -1 +endi +if $data10 != 2.000000000 then + return -1 +endi +if $data20 != 6.000000000 then + return -1 +endi +if $data30 != 1.000000000 then + return -1 +endi + +sql select sum(case f1 when f1 then f1 + 1 else f1 is null end + 1) from tba1; +if $rows != 1 then + return -1 +endi +if $data00 != 14.000000000 then + return -1 +endi + +sql select case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end,sum(f1),count(f1) from tba1 state_window(case when f1 < 3 then 1 when f1 >= 3 then 2 else 3 end); +if $rows != 3 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 2 then + return -1 +endi +if $data10 != 2 then + return -1 +endi +if $data11 != 5 then + return -1 +endi +if $data12 != 1 then + return -1 +endi +if $data20 != 3 then + return -1 +endi +if $data21 != NULL then + return -1 +endi +if $data22 != 0 then + return -1 +endi + +sql select f1 from tba1 where case when case when f1 <= 0 then 3 when f1 = 1 then 4 when f1 >= 3 then 2 else 1 end > 2 then 1 else 0 end > 0; +if $rows != 2 then + return -1 +endi +if $data00 != 0 then + return -1 +endi +if $data10 != 1 then + return -1 +endi + +sql select case when f1 is not null then case when f1 <= 0 then f1 else f1 * 10 end else -1 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 0 then + return -1 +endi +if $data10 != 10 then + return -1 +endi +if $data20 != 50 then + return -1 +endi +if $data30 != -1 then + return -1 +endi + + +print ======== case xx when xx + +sql select case 3 when 3 then 4 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 4 then + return -1 +endi +if $data10 != 4 then + return -1 +endi +if $data20 != 4 then + return -1 +endi +if $data30 != 4 then + return -1 +endi + +sql select case 3 when 1 then 4 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != NULL then + return -1 +endi +if $data20 != NULL then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select case 3 when 1 then 4 else 2 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 2 then + return -1 +endi +if $data10 != 2 then + return -1 +endi +if $data20 != 2 then + return -1 +endi +if $data30 != 2 then + return -1 +endi + +sql select case 3 when null then 4 when '3' then 1 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data10 != 1 then + return -1 +endi +if $data20 != 1 then + return -1 +endi +if $data30 != 1 then + return -1 +endi + +sql select case '3' when null then 4 when 3 then 1 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data10 != 1 then + return -1 +endi +if $data20 != 1 then + return -1 +endi +if $data30 != 1 then + return -1 +endi + +sql select case null when null then 4 when 3 then 1 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != NULL then + return -1 +endi +if $data20 != NULL then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select case 3.0 when null then 4 when '3' then 1 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data10 != 1 then + return -1 +endi +if $data20 != 1 then + return -1 +endi +if $data30 != 1 then + return -1 +endi + +sql select case f2 when 'a' then 4 when '0' then 1 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 4 then + return -1 +endi +if $data10 != 1 then + return -1 +endi +if $data20 != NULL then + return -1 +endi +if $data30 != NULL then + return -1 +endi + +sql select case f2 when f1 then f1 when f1 - 1 then f1 else 99 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 0 then + return -1 +endi +if $data10 != 1 then + return -1 +endi +if $data20 != 5 then + return -1 +endi +if $data30 != 99 then + return -1 +endi + +sql select case cast(f2 as int) when 0 then f2 when f1 then 11 else ts end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != a then + return -1 +endi +if $data10 != 0 then + return -1 +endi +if $data20 != 11 then + return -1 +endi +if $data30 != 1664176504 then + return -1 +endi + +sql select case f1 + 1 when 1 then 1 when 2 then 2 else 3 end from tba1; +if $rows != 4 then + return -1 +endi +if $data00 != 1 then + return -1 +endi +if $data10 != 2 then + return -1 +endi +if $data20 != 3 then + return -1 +endi +if $data30 != 3 then + return -1 +endi + +sql select case f1 when sum(f1) then sum(f1)-abs(f1) end from tba1 group by f1 order by f1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != 0.000000000 then + return -1 +endi +if $data20 != 0.000000000 then + return -1 +endi +if $data30 != 0.000000000 then + return -1 +endi + +sql select f1, case sum(f1) when 1 then f1 + 99 when f1 then f1 -99 else f1 end from tba1 group by f1 order by f1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != 0 then + return -1 +endi +if $data11 != -99.000000000 then + return -1 +endi +if $data20 != 1 then + return -1 +endi +if $data21 != 100.000000000 then + return -1 +endi +if $data30 != 5 then + return -1 +endi +if $data31 != -94.000000000 then + return -1 +endi + +sql select case when 3 then 4 end from sta; +if $rows != 20 then + return -1 +endi +sql select case when 0 then 4 end from sta; +if $rows != 20 then + return -1 +endi +sql select case when null then 4 end from sta; +if $rows != 20 then + return -1 +endi +sql select case when 1 then 4+1 end from sta; +if $rows != 20 then + return -1 +endi +sql select case when 1-1 then 0 end from sta; +if $rows != 20 then + return -1 +endi +sql select case when 1+1 then 0 end from sta; +if $rows != 20 then + return -1 +endi +sql select case when abs(3) then abs(-1) end from sta; +if $rows != 20 then + return -1 +endi +sql select case when abs(1+1) then abs(-1)+abs(3) end from sta; +if $rows != 20 then + return -1 +endi +sql select case when 0 then 1 else 3 end from sta; +if $rows != 20 then + return -1 +endi +sql select case when 0 then 1 when 1 then 0 else 3 end from sta; +if $rows != 20 then + return -1 +endi +sql select case when 0 then 1 when 1 then 0 when 2 then 3 end from sta; +if $rows != 20 then + return -1 +endi +sql select case when 'a' then 'b' when null then 0 end from sta; +if $rows != 20 then + return -1 +endi +sql select case when '2' then 'b' when null then 0 end from sta; +if $rows != 20 then + return -1 +endi +sql select case when 0 then 'b' else null end from sta; +if $rows != 20 then + return -1 +endi +sql select case when 0 then 'b' else 2+abs(-2) end from sta; +if $rows != 20 then + return -1 +endi +sql select case 3 when 3 then 4 end from sta; +if $rows != 20 then + return -1 +endi +sql select case 3 when 1 then 4 end from sta; +if $rows != 20 then + return -1 +endi +sql select case 3 when 1 then 4 else 2 end from sta; +if $rows != 20 then + return -1 +endi +sql select case 3 when null then 4 when '3' then 1 end from sta; +if $rows != 20 then + return -1 +endi +sql select case null when null then 4 when 3 then 1 end from sta; +if $rows != 20 then + return -1 +endi +sql select case 3.0 when null then 4 when '3' then 1 end from sta; +if $rows != 20 then + return -1 +endi +sql select f2,case f2 when 'a' then 4 when '0' then 1 end from sta order by f2; +if $rows != 20 then + return -1 +endi +sql select f2,f1,case f2 when f1 then f1 when f1 - 1 then f1 else 99 end from sta order by f2; +if $rows != 20 then + return -1 +endi +sql select case cast(f2 as int) when 0 then f2 when f1 then 11 else ts end from sta; +if $rows != 20 then + return -1 +endi +sql select f1, case f1 + 1 when 1 then 1 when 2 then 2 else 3 end from sta order by f1; +if $rows != 20 then + return -1 +endi +sql select case f1 when sum(f1) then sum(f1)-abs(f1) end from sta group by f1 order by f1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != 0.000000000 then + return -1 +endi +if $data20 != NULL then + return -1 +endi +if $data30 != NULL then + return -1 +endi +sql select case sum(f1) when 1 then f1 + 99 when f1 then f1 -99 else f1 end from sta group by f1 order by f1; +if $rows != 4 then + return -1 +endi +if $data00 != NULL then + return -1 +endi +if $data10 != -99.000000000 then + return -1 +endi +if $data20 != 1.000000000 then + return -1 +endi +if $data30 != 5.000000000 then + return -1 +endi + +sql select distinct tbname, case t1 when t2 then t1 else t1 + 100 end from sta order by tbname; +if $rows != 5 then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data21 != NULL then + return -1 +endi +if $data31 != 101 then + return -1 +endi +if $data41 != 103 then + return -1 +endi + +sql_error select case when sum(f1) then sum(f1)-abs(f1) end from tba1; + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/valgrind/checkError3.sim b/tests/script/tsim/valgrind/checkError3.sim index 6fa7e393351b9378427e27f9695704ec8ad72006..252ef10b1a1c2813f073fe82590ee461b411361a 100644 --- a/tests/script/tsim/valgrind/checkError3.sim +++ b/tests/script/tsim/valgrind/checkError3.sim @@ -62,7 +62,16 @@ system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s start -v print =============== stepa: query data -sql select * from c1 + +$x = 0 +steps: + $x = $x + 1 + sleep 500 + if $x == 50 then + return -1 + endi +sql select * from c1 -x steps + sql select * from stb sql select * from stb_1 sql select ts, c1, c2, c3 from c1 diff --git a/tests/script/tsim/valgrind/checkError6.sim b/tests/script/tsim/valgrind/checkError6.sim index 11a387ed4dffd7258120154adb9d7874ee0b21b5..89b6cadef88eb5a7d363b5fd6c784b7606095e66 100644 --- a/tests/script/tsim/valgrind/checkError6.sim +++ b/tests/script/tsim/valgrind/checkError6.sim @@ -158,9 +158,15 @@ print =============== restart system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s start -v -sleep 1000 +$x = 0 +steps: + $x = $x + 1 + sleep 500 + if $x == 50 then + return -1 + endi +sql select avg(tbcol) as c from stb -x steps -sql select avg(tbcol) as c from stb sql select avg(tbcol) as c from stb where ts <= 1601481840000 sql select avg(tbcol) as c from stb where tgcol < 5 and ts <= 1601481840000 sql select avg(tbcol) as c from stb interval(1m) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 32eaa6dc34927127b3c0a13af90ed5982edd7f56..2686156f0f04a453d85785b8013191a235bef406 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -232,7 +232,7 @@ python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeStop.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeStop2Follower.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeStopLoop.py -N 5 -M 3 -# unstable python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py -N 5 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateDb.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDbRep3.py -N 5 -M 3 @@ -248,8 +248,8 @@ python3 ./test.py -f 6-cluster/5dnode3mnodeRestartDnodeInsertDataAsync.py -N 5 - python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 6 -M 3 -C 5 # BUG python3 ./test.py -f 6-cluster/5dnode3mnodeStopInsert.py -# python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -N 5 -# python3 test.py -f 6-cluster/5dnode3mnodeStopConnect.py -N 5 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -N 5 +python3 test.py -f 6-cluster/5dnode3mnodeStopConnect.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeRecreateMnode.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeStopFollowerLeader.py -N 5 -M 3 @@ -302,7 +302,7 @@ python3 ./test.py -f 7-tmq/tmqCheckData.py python3 ./test.py -f 7-tmq/tmqCheckData1.py #python3 ./test.py -f 7-tmq/tmq3mnodeSwitch.py -N 5 python3 ./test.py -f 7-tmq/tmqConsumerGroup.py -python3 ./test.py -f 7-tmq/tmqShow.py +#python3 ./test.py -f 7-tmq/tmqShow.py python3 ./test.py -f 7-tmq/tmqAlterSchema.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb1.py diff --git a/tools/scripts/codeFormat.py b/tools/scripts/codeFormat.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tools/scripts/codeFormat.sh b/tools/scripts/codeFormat.sh old mode 100644 new mode 100755 index cf940eec34472b19365334d170961ed72780b423..cc7db5c723efcac9182956dda43c50aae4494e4f --- a/tools/scripts/codeFormat.sh +++ b/tools/scripts/codeFormat.sh @@ -8,19 +8,30 @@ ORIGIN_DIR=$(pwd) cd ${PRJ_ROOT_DIR} FORMAT_DIR_LIST=( - "include" - "source/os" - "source/util" - "source/common" - # "source/libs" - # "source/client" - "source/dnode" + "${PRJ_ROOT_DIR}/include" + "${PRJ_ROOT_DIR}/source/os" + "${PRJ_ROOT_DIR}/source/util" + "${PRJ_ROOT_DIR}/source/common" + "${PRJ_ROOT_DIR}/source/libs" + "${PRJ_ROOT_DIR}/source/client/inc" + "${PRJ_ROOT_DIR}/source/client/src" + "${PRJ_ROOT_DIR}/source/client/test" + "${PRJ_ROOT_DIR}/source/dnode" +) + +EXCLUDE_DIR_LIST=( +) + +EXCLUDE_FILE_LIST=( + "source/libs/parser/sql.c" ) for d in ${FORMAT_DIR_LIST[@]}; do - for f in $(find ${PRJ_ROOT_DIR}/$d/ -regex '.*\.\(cpp\|hpp\|c\|h\)'); do + for f in $(find $d -type f -not -name '*sql.c' -regex '.*\.\(cpp\|hpp\|c\|h\)'); do ${FORMAT_BIN} -i $f done done cd ${ORIGIN_DIR} + +# find source -type f -regex '.*\.\(cpp\|hpp\|c\|h\)' ! -name diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 8aafd747afe2f5972e0010d0be0222a7d56e961b..46eaf6cff1a7d070a88ae4fa1dc67cb0512de75a 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -325,24 +325,23 @@ int cntDel = 0; // delete byte count after next press tab // show auto tab introduction void printfIntroduction() { - printf(" **************************** How To Use TAB Key ********************************\n"); - printf(" * TDengine Command Line supports pressing TAB key to complete word, *\n"); - printf(" * including database name, table name, function name and keywords. *\n"); - printf(" * Press TAB key anywhere, you'll get surprise. *\n"); - printf(" * KEYBOARD SHORTCUT: *\n"); - printf(" * [ TAB ] ...... Complete the word or show help if no input *\n"); - printf(" * [ Ctrl + A ] ...... move cursor to [A]head of line *\n"); - printf(" * [ Ctrl + E ] ...... move cursor to [E]nd of line *\n"); - printf(" * [ Ctrl + W ] ...... move cursor to line of middle *\n"); - printf(" * [ Ctrl + L ] ...... clean screen *\n"); - printf(" * [ Ctrl + K ] ...... clean after cursor *\n"); - printf(" * [ Ctrl + U ] ...... clean before cursor *\n"); - printf(" * *\n"); + printf(" ****************************** Tab Completion **********************************\n"); + printf(" * The TDengine CLI supports tab completion for a variety of items, *\n"); + printf(" * including database names, table names, function names and keywords. *\n"); + printf(" * The full list of shortcut keys is as follows: *\n"); + printf(" * [ TAB ] ...... complete the current word *\n"); + printf(" * ...... if used on a blank line, display all valid commands *\n"); + printf(" * [ Ctrl + A ] ...... move cursor to the st[A]rt of the line *\n"); + printf(" * [ Ctrl + E ] ...... move cursor to the [E]nd of the line *\n"); + printf(" * [ Ctrl + W ] ...... move cursor to the middle of the line *\n"); + printf(" * [ Ctrl + L ] ...... clear the entire screen *\n"); + printf(" * [ Ctrl + K ] ...... clear the screen after the cursor *\n"); + printf(" * [ Ctrl + U ] ...... clear the screen before the cursor *\n"); printf(" **********************************************************************************\n\n"); } void showHelp() { - printf("\nThe following are supported commands for TDengine Command Line:"); + printf("\nThe TDengine CLI supports the following commands:"); printf( "\n\ ----- A ----- \n\ diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index fd0ea6032357db68fc523a61f56de6aa0df54017..37d00c0a7ce9d5a2d91ae7a2f9747097361e2c1f 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -229,7 +229,7 @@ void shellRunSingleCommandImp(char *command) { printf("Query OK, %d of %d rows affected (%.6fs)\r\n", num_rows_affacted, num_rows_affacted, (et - st) / 1E6); // call auto tab - callbackAutoTab(command, pSql, false); + callbackAutoTab(command, NULL, false); } printf("\r\n"); @@ -998,7 +998,9 @@ void *shellCancelHandler(void *arg) { shell.stop_query = true; } else { #endif - taos_kill_query(shell.conn); + if (shell.conn) { + taos_kill_query(shell.conn); + } #ifdef WEBSOCKET } #endif