diff --git a/docs-cn/07-develop/01-connect/index.md b/docs-cn/07-develop/01-connect/index.md index 3a15d03f93..b1857b9739 100644 --- a/docs-cn/07-develop/01-connect/index.md +++ b/docs-cn/07-develop/01-connect/index.md @@ -212,7 +212,7 @@ curl -L -o php-tdengine.tar.gz https://github.com/Yurunsoft/php-tdengine/archive && tar -xzf php-tdengine.tar.gz -C php-tdengine --strip-components=1 ``` -> 版本 `v1.0.0` 可替换为任意更新的版本,可在 Release 中查看最新版本。 +> 版本 `v1.0.2` 只是示例,可替换为任意更新的版本,可在 [TDengine PHP Connector 发布历史](https://github.com/Yurunsoft/php-tdengine/releases) 中查看可用版本。 **非 Swoole 环境:** diff --git a/docs-cn/14-reference/03-connector/java.mdx b/docs-cn/14-reference/03-connector/java.mdx index 2677571606..ddab9e5f24 100644 --- a/docs-cn/14-reference/03-connector/java.mdx +++ b/docs-cn/14-reference/03-connector/java.mdx @@ -93,8 +93,8 @@ Maven 项目中,在 pom.xml 中添加以下依赖: 可以通过下载 TDengine 的源码,自己编译最新版本的 Java connector ```shell -git clone https://github.com/taosdata/TDengine.git -cd TDengine/src/connector/jdbc +git clone https://github.com/taosdata/taos-connector-jdbc.git +cd taos-connector-jdbc mvn clean install -Dmaven.test.skip=true ``` @@ -199,6 +199,7 @@ url 中的配置参数如下: - user:登录 TDengine 用户名,默认值 'root'。 - password:用户登录密码,默认值 'taosdata'。 - batchfetch: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:false。逐行拉取结果集使用 HTTP 方式进行数据传输。从 taos-jdbcdriver-2.0.38 和 TDengine 2.4.0.12 版本开始,JDBC REST 连接增加批量拉取数据功能。taos-jdbcdriver 与 TDengine 之间通过 WebSocket 连接进行数据传输。相较于 HTTP,WebSocket 可以使 JDBC REST 连接支持大数据量查询,并提升查询性能。 +- charset: 当开启批量拉取数据时,指定解析字符串数据的字符集。 - batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败,继续执行下面的 SQL 了。false:不再执行失败 SQL 后的任何语句。默认值为:false。 **注意**:部分配置项(比如:locale、timezone)在 REST 连接中不生效。 @@ -260,7 +261,7 @@ properties 中的配置参数如下: - TSDBDriver.PROPERTY_KEY_BATCH_LOAD: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:false。 - TSDBDriver.PROPERTY_KEY_BATCH_ERROR_IGNORE:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败,继续执行下面的 sq 了。false:不再执行失败 SQL 后的任何语句。默认值为:false。 - TSDBDriver.PROPERTY_KEY_CONFIG_DIR:仅在使用 JDBC 原生连接时生效。客户端配置文件目录路径,Linux OS 上默认值 `/etc/taos`,Windows OS 上默认值 `C:/TDengine/cfg`。 -- TSDBDriver.PROPERTY_KEY_CHARSET:仅在使用 JDBC 原生连接时生效。 客户端使用的字符集,默认值为系统字符集。 +- TSDBDriver.PROPERTY_KEY_CHARSET:客户端使用的字符集,默认值为系统字符集。 - TSDBDriver.PROPERTY_KEY_LOCALE:仅在使用 JDBC 原生连接时生效。 客户端语言环境,默认值系统当前 locale。 - TSDBDriver.PROPERTY_KEY_TIME_ZONE:仅在使用 JDBC 原生连接时生效。 客户端使用的时区,默认值为系统当前时区。 - 此外对 JDBC 原生连接,通过指定 URL 和 Properties 还可以指定其他参数,比如日志级别、SQL 长度等。更多详细配置请参考[客户端配置](/reference/config/#仅客户端适用)。 @@ -348,7 +349,7 @@ JDBC 连接器可能报错的错误码包括 3 种:JDBC driver 本身的报错 具体的错误码请参考: -- [TDengine Java Connector](https://github.com/taosdata/TDengine/blob/develop/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java) +- [TDengine Java Connector](https://github.com/taosdata/taos-connector-jdbc/blob/main/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java) - [TDengine_ERROR_CODE](https://github.com/taosdata/TDengine/blob/develop/src/inc/taoserror.h) ### 通过参数绑定写入数据 diff --git a/docs-cn/14-reference/03-connector/php.mdx b/docs-cn/14-reference/03-connector/php.mdx new file mode 100644 index 0000000000..f150aed4c8 --- /dev/null +++ b/docs-cn/14-reference/03-connector/php.mdx @@ -0,0 +1,150 @@ +--- +sidebar_position: 1 +sidebar_label: PHP +title: PHP Connector +--- + +`php-tdengine` 是由社区贡献的 PHP 连接器扩展,还特别支持了 Swoole 协程化。 + +PHP 连接器依赖 TDengine 客户端驱动。 + +项目地址: + +TDengine 服务端或客户端安装后,`taos.h` 位于: + +- Linux:`/usr/local/taos/include` +- Windows:`C:\TDengine\include` + +TDengine 客户端驱动的动态库位于: + +- Linux: `/usr/local/taos/driver/libtaos.so` +- Windows: `C:\TDengine\taos.dll` + +## 支持的平台 + +* Windows、Linux、MacOS + +* PHP >= 7.4 + +* TDengine >= 2.0 + +* Swoole >= 4.8 (可选) + +## 支持的版本 + +TDengine 客户端驱动的版本号与 TDengine 服务端的版本号是一一对应的强对应关系,建议使用与 TDengine 服务端完全相同的客户端驱动。虽然低版本的客户端驱动在前三段版本号一致(即仅第四段版本号不同)的情况下也能够与高版本的服务端相兼容,但这并非推荐用法。强烈不建议使用高版本的客户端驱动访问低版本的服务端。 + +## 安装步骤 + +### 安装 TDengine 客户端驱动 + +TDengine 客户端驱动的安装请参考 [安装指南](/reference/connector#安装步骤) + +### 编译安装 php-tdengine + +**下载代码并解压:** + +```shell +curl -L -o php-tdengine.tar.gz https://github.com/Yurunsoft/php-tdengine/archive/refs/tags/v1.0.2.tar.gz \ +&& mkdir php-tdengine \ +&& tar -xzf php-tdengine.tar.gz -C php-tdengine --strip-components=1 +``` + +> 版本 `v1.0.2` 可替换为任意更新的版本,可在 [TDengine PHP Connector 发布历史](https://github.com/Yurunsoft/php-tdengine/releases)。 + +**非 Swoole 环境:** + +```shell +phpize && ./configure && make -j && make install +``` + +**手动指定 tdengine 目录:** + +```shell +phpize && ./configure --with-tdengine-dir=/usr/local/Cellar/tdengine/2.4.0.0 && make -j && make install +``` + +> `--with-tdengine-dir=` 后跟上 tdengine 目录。 +> 适用于默认找不到的情况,或者 MacOS 系统用户。 + +**Swoole 环境:** + +```shell +phpize && ./configure --enable-swoole && make -j && make install +``` + +**启用扩展:** + +方法一:在 `php.ini` 中加入 `extension=tdengine` + +方法二:运行带参数 `php -dextension=tdengine test.php` + +## 示例程序 + +本节展示了使用客户端驱动访问 TDengine 集群的常见访问方式的示例代码。 + +> 所有错误都会抛出异常: `TDengine\Exception\TDengineException` + +### 建立连接 + +
+建立连接 + +```c +{{#include docs-examples/php/connect.php}} +``` + +
+ +### 插入数据 + +
+插入数据 + +```c +{{#include docs-examples/php/insert.php}} +``` + +
+ +### 同步查询 + +
+同步查询 + +```c +{{#include docs-examples/php/query.php}} +``` + +
+ +### 参数绑定 + +
+参数绑定 + +```c +{{#include docs-examples/php/insert_stmt.php}} +``` + +
+ +## 常量 + +| 常量 | 说明 | +| ------------ | ------------ +| `TDengine\TSDB_DATA_TYPE_NULL` | null | +| `TDengine\TSDB_DATA_TYPE_BOOL` | bool | +| `TDengine\TSDB_DATA_TYPE_TINYINT` | tinyint | +| `TDengine\TSDB_DATA_TYPE_SMALLINT` | smallint | +| `TDengine\TSDB_DATA_TYPE_INT` | int | +| `TDengine\TSDB_DATA_TYPE_BIGINT` | bigint | +| `TDengine\TSDB_DATA_TYPE_FLOAT` | float | +| `TDengine\TSDB_DATA_TYPE_DOUBLE` | double | +| `TDengine\TSDB_DATA_TYPE_BINARY` | binary | +| `TDengine\TSDB_DATA_TYPE_TIMESTAMP` | timestamp | +| `TDengine\TSDB_DATA_TYPE_NCHAR` | nchar | +| `TDengine\TSDB_DATA_TYPE_UTINYINT` | utinyint | +| `TDengine\TSDB_DATA_TYPE_USMALLINT` | usmallint | +| `TDengine\TSDB_DATA_TYPE_UINT` | uint | +| `TDengine\TSDB_DATA_TYPE_UBIGINT` | ubigint | diff --git a/docs-cn/14-reference/03-connector/python.mdx b/docs-cn/14-reference/03-connector/python.mdx index 6608fb7bd2..828e0a4abb 100644 --- a/docs-cn/14-reference/03-connector/python.mdx +++ b/docs-cn/14-reference/03-connector/python.mdx @@ -199,10 +199,9 @@ curl -u root:taosdata http://:/rest/sql -d "select server_version()" `connect()` 函数的所有参数都是可选的关键字参数。下面是连接参数的具体说明: -- `host`: 要连接的主机。默认是 localhost。 +- `url`: taosAdapter REST 服务的 URL。默认是 。 - `user`: TDenigne 用户名。默认是 root。 - `password`: TDeingine 用户密码。默认是 taosdata。 -- `port`: taosAdapter REST 服务监听端口。默认是 6041. - `timeout`: HTTP 请求超时时间。单位为秒。默认为 `socket._GLOBAL_DEFAULT_TIMEOUT`。 一般无需配置。 diff --git a/docs-cn/14-reference/05-taosbenchmark.md b/docs-cn/14-reference/05-taosbenchmark.md index f34d12a546..6b694543b1 100644 --- a/docs-cn/14-reference/05-taosbenchmark.md +++ b/docs-cn/14-reference/05-taosbenchmark.md @@ -21,7 +21,7 @@ taosBenchmark 有两种安装方式: ### 配置和运行方式 -taosBenchmark 支持两种配置方式:[命令行参数](#命令行参数详解) 和 [JSON 配置文件](#配置文件参数详解)。这两种方式是互斥的,在使用配置文件时只能使用一个命令行参数 `-f ` 指定配置文件。在使用命令行参数运行 taosBenchmark 并控制其行为时则不能使用 `-f` 参数而要用其它参数来进行配置。除此之外,taosBenchmark 还提供了一种特殊的运行方式,即无参数运行。 +taosBenchmark 需要在操作系统的终端执行,该工具支持两种配置方式:[命令行参数](#命令行参数详解) 和 [JSON 配置文件](#配置文件参数详解)。这两种方式是互斥的,在使用配置文件时只能使用一个命令行参数 `-f ` 指定配置文件。在使用命令行参数运行 taosBenchmark 并控制其行为时则不能使用 `-f` 参数而要用其它参数来进行配置。除此之外,taosBenchmark 还提供了一种特殊的运行方式,即无参数运行。 taosBenchmark 支持对 TDengine 做完备的性能测试,其所支持的 TDengine 功能分为三大类:写入、查询和订阅。这三种功能之间是互斥的,每次运行 taosBenchmark 只能选择其中之一。值得注意的是,所要测试的功能类型在使用命令行配置方式时是不可配置的,命令行配置方式只能测试写入性能。若要测试 TDengine 的查询和订阅性能,必须使用配置文件的方式,通过配置文件中的参数 `filetype` 指定所要测试的功能类型。 diff --git a/docs-cn/14-reference/12-config/index.md b/docs-cn/14-reference/12-config/index.md index 89c414a5b8..2d1866d5dd 100644 --- a/docs-cn/14-reference/12-config/index.md +++ b/docs-cn/14-reference/12-config/index.md @@ -134,7 +134,7 @@ taos --dump-config | 适用范围 | 仅服务端适用 | | 含义 | 服务器内部的系统监控开关。监控主要负责收集物理节点的负载状况,包括 CPU、内存、硬盘、网络带宽、HTTP 请求量的监控记录,记录信息存储在`LOG`库中。 | | 取值范围 | 0:关闭监控服务, 1:激活监控服务。 | -| 缺省值 | 0 | +| 缺省值 | 1 | ### monitorInterval diff --git a/docs-cn/20-third-party/01-grafana.mdx b/docs-cn/20-third-party/01-grafana.mdx index 40b5c0ff4f..31cd434080 100644 --- a/docs-cn/20-third-party/01-grafana.mdx +++ b/docs-cn/20-third-party/01-grafana.mdx @@ -3,6 +3,9 @@ sidebar_label: Grafana title: Grafana --- +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + TDengine 能够与开源数据可视化系统 [Grafana](https://www.grafana.com/) 快速集成搭建数据监测报警系统,整个过程无需任何代码开发,TDengine 中数据表的内容可以在仪表盘(DashBoard)上进行可视化展现。关于 TDengine 插件的使用您可以在[GitHub](https://github.com/taosdata/grafanaplugin/blob/master/README.md)中了解更多。 ## 前置条件 @@ -12,12 +15,42 @@ TDengine 能够与开源数据可视化系统 [Grafana](https://www.grafana.com/ - TDengine 集群已经部署并正常运行 - taosAdapter 已经安装并正常运行。具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter) +记录以下信息: + +- TDengine 集群 REST API 地址,如:`http://tdengine.local:6041`。 +- TDengine 集群认证信息,可使用用户名及密码。 + ## 安装 Grafana -目前 TDengine 支持 Grafana 7.0 以上的版本。用户可以根据当前的操作系统,到 Grafana 官网下载安装包,并执行安装。下载地址如下:。 +目前 TDengine 支持 Grafana 7.5 以上的版本。用户可以根据当前的操作系统,到 Grafana 官网下载安装包,并执行安装。下载地址如下:。 ## 配置 Grafana +### 安装 Grafana Plugin 并配置数据源 + + + + +将集群信息设置为环境变量;也可以使用 `.env` 文件,请参考 [dotenv](https://hexdocs.pm/dotenvy/dotenv-file-format.html): + +```sh +export TDENGINE_API=http://tdengine.local:6041 +# user + password +export TDENGINE_USER=user +export TDENGINE_PASSWORD=password +``` + +运行安装脚本: + +```sh +bash -c "$(curl -fsSL https://raw.githubusercontent.com/taosdata/grafanaplugin/master/install.sh)" +``` + +该脚本将自动安装 Grafana 插件并配置数据源。安装完毕后,需要重启 Grafana 服务后生效。 + + + + 使用 [`grafana-cli` 命令行工具](https://grafana.com/docs/grafana/latest/administration/cli/) 进行插件[安装](https://grafana.com/grafana/plugins/tdengine-datasource/?tab=installation)。 ```bash @@ -48,11 +81,7 @@ sudo unzip tdengine-datasource-$GF_VERSION.zip -d /var/lib/grafana/plugins/ GF_INSTALL_PLUGINS=tdengine-datasource ``` -## 使用 Grafana - -### 配置数据源 - -用户可以直接通过 的网址,登录 Grafana 服务器(用户名/密码:admin/admin),通过左侧 `Configuration -> Data Sources` 可以添加数据源,如下图所示: +之后,用户可以直接通过 的网址,登录 Grafana 服务器(用户名/密码:admin/admin),通过左侧 `Configuration -> Data Sources` 可以添加数据源,如下图所示: ![TDengine Database Grafana plugin add data source](./add_datasource1.webp) @@ -72,6 +101,9 @@ GF_INSTALL_PLUGINS=tdengine-datasource ![TDengine Database Grafana plugin add data source](./add_datasource4.webp) + + + ### 创建 Dashboard 回到主界面创建 Dashboard,点击 Add Query 进入面板查询页面: @@ -92,4 +124,11 @@ GF_INSTALL_PLUGINS=tdengine-datasource ### 导入 Dashboard -在 2.3.3.0 及以上版本,您可以导入 TDinsight Dashboard (Grafana Dashboard ID: [15167](https://grafana.com/grafana/dashboards/15167)) 作为 TDengine 集群的监控可视化工具。安装和使用说明请见 [TDinsight 用户手册](/reference/tdinsight/)。 +在数据源配置页面,您可以为该数据源导入 TDinsight 面板,作为 TDengine 集群的监控可视化工具。该 Dashboard 已发布在 Grafana:[Dashboard 15167 - TDinsight](https://grafana.com/grafana/dashboards/15167)) 。其他安装方式和相关使用说明请见 [TDinsight 用户手册](/reference/tdinsight/)。 + +使用 TDengine 作为数据源的其他面板,可以[在此搜索](https://grafana.com/grafana/dashboards/?dataSource=tdengine-datasource)。以下是一份不完全列表: + +- [15146](https://grafana.com/grafana/dashboards/15146): 监控多个 TDengine 集群 +- [15155](https://grafana.com/grafana/dashboards/15155): TDengine 告警示例 +- [15167](https://grafana.com/grafana/dashboards/15167): TDinsight +- [16388](https://grafana.com/grafana/dashboards/16388): Telegraf 采集节点信息的数据展示 diff --git a/docs-cn/20-third-party/09-emq-broker.md b/docs-cn/20-third-party/09-emq-broker.md index 833fa97e2e..2125545f39 100644 --- a/docs-cn/20-third-party/09-emq-broker.md +++ b/docs-cn/20-third-party/09-emq-broker.md @@ -8,31 +8,24 @@ MQTT 是流行的物联网数据传输协议,[EMQX](https://github.com/emqx/em ## 前置条件 要让 EMQX 能正常添加 TDengine 数据源,需要以下几方面的准备工作。 + - TDengine 集群已经部署并正常运行 - taosAdapter 已经安装并正常运行。具体细节请参考 [taosAdapter 的使用手册](/reference/taosadapter) -- 如果使用后文介绍的模拟写入程序,需要安装合适版本的 Node.js,推荐安装 v12。 +- 如果使用后文介绍的模拟写入程序,需要安装合适版本的 Node.js,推荐安装 v12 ## 安装并启动 EMQX 用户可以根据当前的操作系统,到 EMQX 官网下载安装包,并执行安装。下载地址如下:。安装后使用 `sudo emqx start` 或 `sudo systemctl start emqx` 启动 EMQX 服务。 -## 在 TDengine 中为接收 MQTT 数据创建相应数据库和表结构 -### 以 Docker 安装 TDengine 为例 +## 创建数据库和表 -```bash - docker exec -it tdengine bash - taos -``` - -### 创建数据库和表 +在 TDengine 中为接收 MQTT 数据创建相应数据库和表结构。进入 TDengine CLI 复制并执行以下 SQL 语句: ```sql - create database test; - use test; - create table: - - CREATE TABLE sensor_data (ts timestamp, temperature float, humidity float, volume float, PM10 float, pm25 float, SO2 float, NO2 float, CO float, sensor_id NCHAR(255), area TINYINT, coll_time timestamp); +CREATE DATABASE test; +USE test; +CREATE TABLE sensor_data (ts TIMESTAMP, temperature FLOAT, humidity FLOAT, volume FLOAT, pm10 FLOAT, pm25 FLOAT, so2 FLOAT, no2 FLOAT, co FLOAT, sensor_id NCHAR(255), area TINYINT, coll_time TIMESTAMP); ``` 注:表结构以博客[数据传输、存储、展现,EMQX + TDengine 搭建 MQTT 物联网数据可视化平台](https://www.taosdata.com/blog/2020/08/04/1722.html)为例。后续操作均以此博客场景为例进行,请你根据实际应用场景进行修改。 @@ -43,7 +36,7 @@ MQTT 是流行的物联网数据传输协议,[EMQX](https://github.com/emqx/em ### 登录 EMQX Dashboard -使用浏览器打开网址 http://IP:18083 并登录 EMQX Dashboard。初次安装用户名为 `admin` 密码为:`public` +使用浏览器打开网址 http://IP:18083 并登录 EMQX Dashboard。初次安装用户名为 `admin` 密码为:`public`。 ![TDengine Database EMQX login dashboard](./emqx/login-dashboard.webp) @@ -55,6 +48,17 @@ MQTT 是流行的物联网数据传输协议,[EMQX](https://github.com/emqx/em ### 编辑 SQL 字段 +复制以下内容输入到 SQL 编辑框: + +```sql +SELECT + payload +FROM + "sensor/data" +``` + +其中 `payload` 代表整个消息体, `sensor/data` 为本规则选取的消息主题。 + ![TDengine Database EMQX create rule](./emqx/create-rule.webp) ### 新增“动作(action handler)” @@ -65,101 +69,54 @@ MQTT 是流行的物联网数据传输协议,[EMQX](https://github.com/emqx/em ![TDengine Database EMQX create resource](./emqx/create-resource.webp) -选择“发送数据到 Web 服务“并点击“新建资源”按钮: +选择“发送数据到 Web 服务”并点击“新建资源”按钮: ### 编辑“资源(Resource)” -选择“发送数据到 Web 服务“并填写 请求 URL 为 运行 taosAdapter 的服务器地址和端口(默认为 6041)。其他属性请保持默认值。 +选择“WebHook”并填写“请求 URL”为 taosAdapter 提供 REST 服务的地址,如果是本地启动的 taosadapter, 那么默认地址为: + +``` +http://127.0.0.1:6041/rest/sql +``` + +其他属性请保持默认值。 ![TDengine Database EMQX edit resource](./emqx/edit-resource.webp) ### 编辑“动作(action)” -编辑资源配置,增加 Authorization 认证的键/值配对项,相关文档请参考[ TDengine REST API 文档](https://docs.taosdata.com/reference/rest-api/)。在消息体中输入规则引擎替换模板。 +编辑资源配置,增加 Authorization 认证的键/值配对项。默认用户名和密码对应的 Authorization 值为: +``` +Basic cm9vdDp0YW9zZGF0YQ== +``` +相关文档请参考[ TDengine REST API 文档](/reference/rest-api/)。 + +在消息体中输入规则引擎替换模板: + +```sql +INSERT INTO test.sensor_data VALUES( + now, + ${payload.temperature}, + ${payload.humidity}, + ${payload.volume}, + ${payload.PM10}, + ${payload.pm25}, + ${payload.SO2}, + ${payload.NO2}, + ${payload.CO}, + '${payload.id}', + ${payload.area}, + ${payload.ts} +) +``` ![TDengine Database EMQX edit action](./emqx/edit-action.webp) +最后点击左下方的 “Create” 按钮,保存规则。 ## 编写模拟测试程序 ```javascript - // mock.js - const mqtt = require('mqtt') - const Mock = require('mockjs') - const EMQX_SERVER = 'mqtt://localhost:1883' - const CLIENT_NUM = 10 - const STEP = 5000 // 模拟采集时间间隔 ms - const AWAIT = 5000 // 每次发送完后休眠时间,防止消息速率过快 ms - const CLIENT_POOL = [] - startMock() - function sleep(timer = 100) { - return new Promise(resolve => { - setTimeout(resolve, timer) - }) - } - async function startMock() { - const now = Date.now() - for (let i = 0; i < CLIENT_NUM; i++) { - const client = await createClient(`mock_client_${i}`) - CLIENT_POOL.push(client) - } - // last 24h every 5s - const last = 24 * 3600 * 1000 - for (let ts = now - last; ts <= now; ts += STEP) { - for (const client of CLIENT_POOL) { - const mockData = generateMockData() - const data = { - ...mockData, - id: client.clientId, - area: 0, - ts, - } - client.publish('sensor/data', JSON.stringify(data)) - } - const dateStr = new Date(ts).toLocaleTimeString() - console.log(`${dateStr} send success.`) - await sleep(AWAIT) - } - console.log(`Done, use ${(Date.now() - now) / 1000}s`) - } - /** - * Init a virtual mqtt client - * @param {string} clientId ClientID - */ - function createClient(clientId) { - return new Promise((resolve, reject) => { - const client = mqtt.connect(EMQX_SERVER, { - clientId, - }) - client.on('connect', () => { - console.log(`client ${clientId} connected`) - resolve(client) - }) - client.on('reconnect', () => { - console.log('reconnect') - }) - client.on('error', (e) => { - console.error(e) - reject(e) - }) - }) - } - /** - * Generate mock data - */ - function generateMockData() { - return { - "temperature": parseFloat(Mock.Random.float(22, 100).toFixed(2)), - "humidity": parseFloat(Mock.Random.float(12, 86).toFixed(2)), - "volume": parseFloat(Mock.Random.float(20, 200).toFixed(2)), - "PM10": parseFloat(Mock.Random.float(0, 300).toFixed(2)), - "pm25": parseFloat(Mock.Random.float(0, 300).toFixed(2)), - "SO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)), - "NO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)), - "CO": parseFloat(Mock.Random.float(0, 50).toFixed(2)), - "area": Mock.Random.integer(0, 20), - "ts": 1596157444170, - } - } +{{#include docs-examples/other/mock.js}} ``` 注意:代码中 CLIENT_NUM 在开始测试中可以先设置一个较小的值,避免硬件性能不能完全处理较大并发客户端数量。 @@ -189,4 +146,3 @@ node mock.js TDengine 详细使用方法请参考 [TDengine 官方文档](https://docs.taosdata.com/)。 EMQX 详细使用方法请参考 [EMQX 官方文档](https://www.emqx.io/docs/zh/v4.4/rule/rule-engine.html)。 - diff --git a/docs-cn/27-train-faq/01-faq.md b/docs-cn/27-train-faq/01-faq.md index f298d7e14d..5b57e345c8 100644 --- a/docs-cn/27-train-faq/01-faq.md +++ b/docs-cn/27-train-faq/01-faq.md @@ -74,7 +74,7 @@ title: 常见问题及反馈 检查服务器侧 TCP 端口连接是否工作:`nc -l {port}` 检查客户端侧 TCP 端口连接是否工作:`nc {hostIP} {port}` - - Windows 系统请使用 PowerShell 命令 Net-TestConnection -ComputerName {fqdn} -Port {port} 检测服务段端口是否访问 + - Windows 系统请使用 PowerShell 命令 Test-NetConnection -ComputerName {fqdn} -Port {port} 检测服务段端口是否访问 10. 也可以使用 taos 程序内嵌的网络连通检测功能,来验证服务器和客户端之间指定的端口连接是否通畅(包括 TCP 和 UDP):[TDengine 内嵌网络检测工具使用指南](https://www.taosdata.com/blog/2020/09/08/1816.html)。 diff --git a/docs-en/07-develop/01-connect/index.md b/docs-en/07-develop/01-connect/index.md index b9217b828d..720f8e2384 100644 --- a/docs-en/07-develop/01-connect/index.md +++ b/docs-en/07-develop/01-connect/index.md @@ -19,7 +19,7 @@ import InstallOnLinux from "../../14-reference/03-connector/\_windows_install.md import VerifyLinux from "../../14-reference/03-connector/\_verify_linux.mdx"; import VerifyWindows from "../../14-reference/03-connector/\_verify_windows.mdx"; -Any application programs running on any kind of platform can access TDengine through the REST API provided by TDengine. For details, please refer to [REST API](/reference/rest-api/). Additionally, application programs can use the connectors of multiple programming languages including C/C++, Java, Python, Go, Node.js, C#, and Rust to access TDengine. This chapter describes how to establish a connection to TDengine and briefly introduces how to install and use connectors. For details about the connectors, please refer to [Connectors](/reference/connector/) +Any application programs running on any kind of platform can access TDengine through the REST API provided by TDengine. For details, please refer to [REST API](/reference/rest-api/). Additionally, application programs can use the connectors of multiple programming languages including C/C++, Java, Python, Go, Node.js, C#, Rust to access TDengine. This chapter describes how to establish a connection to TDengine and briefly introduces how to install and use connectors. TDengine community also provides connectors in LUA and PHP languages. For details about the connectors, please refer to [Connectors](/reference/connector/). ## Establish Connection @@ -200,6 +200,46 @@ install.packages("RJDBC") If the client driver (taosc) is already installed, then the C connector is already available.
+ + + +**Download Source Code Package and Unzip:** + +```shell +curl -L -o php-tdengine.tar.gz https://github.com/Yurunsoft/php-tdengine/archive/refs/tags/v1.0.2.tar.gz \ +&& mkdir php-tdengine \ +&& tar -xzf php-tdengine.tar.gz -C php-tdengine --strip-components=1 +``` + +> Version number `v1.0.2` is only for example, it can be replaced to any newer version, please check available version from [TDengine PHP Connector Releases](https://github.com/Yurunsoft/php-tdengine/releases). + +**Non-Swoole Environment:** + +```shell +phpize && ./configure && make -j && make install +``` + +**Specify TDengine Location:** + +```shell +phpize && ./configure --with-tdengine-dir=/usr/local/Cellar/tdengine/2.4.0.0 && make -j && make install +``` + +> `--with-tdengine-dir=` is followed by the TDengine installation location. +> This way is useful in case TDengine location can't be found automatically or macOS. + +**Swoole Environment:** + +```shell +phpize && ./configure --enable-swoole && make -j && make install +``` + +**Enable The Extension:** + +Option One: Add `extension=tdengine` in `php.ini` + +Option Two: Specify the extension on CLI `php -d extension=tdengine test.php` + diff --git a/docs-en/14-reference/03-connector/cpp.mdx b/docs-en/14-reference/03-connector/cpp.mdx index d549413012..e0cdf2bf2c 100644 --- a/docs-en/14-reference/03-connector/cpp.mdx +++ b/docs-en/14-reference/03-connector/cpp.mdx @@ -26,7 +26,7 @@ Please refer to [list of supported platforms](/reference/connector#supported-pla ## Supported versions -The version number of the TDengine client driver and the version number of the TDengine server should be the same. A lower version of the client driver is compatible with a higher version of the server, if the first three version numbers are the same (i.e., only the fourth version number is different). For e.g. if the client version is x.y.z.1 and the server version is x.y.z.2 the client and server are compatible. But in general we do not recommend using a lower client version with a newer server version. It is also strongly discouraged to use a higher version of the client driver to access a lower version of the TDengine server. +The version number of the TDengine client driver and the version number of the TDengine server should be same. A lower version of the client driver is compatible with a higher version of the server, if the first three version numbers are the same (i.e., only the fourth version number is different). For e.g. if the client version is x.y.z.1 and the server version is x.y.z.2 the client and server are compatible. But in general we do not recommend using a lower client version with a newer server version. It is also strongly discouraged to use a higher version of the client driver to access a lower version of the TDengine server. ## Installation steps diff --git a/docs-en/14-reference/03-connector/java.mdx b/docs-en/14-reference/03-connector/java.mdx index 33d715c2e2..6c40f753be 100644 --- a/docs-en/14-reference/03-connector/java.mdx +++ b/docs-en/14-reference/03-connector/java.mdx @@ -42,18 +42,18 @@ Please refer to [Version Support List](/reference/connector#version-support). TDengine currently supports timestamp, number, character, Boolean type, and the corresponding type conversion with Java is as follows: | TDengine DataType | JDBCType (driver version < 2.0.24) | JDBCType (driver version > = 2.0.24) | -| ----------------- | --------------------------------- | ---------------------------------- | -| TIMESTAMP | java.lang.Long | java.sql.Timestamp | -| INT | java.lang.Integer | java.lang.Integer | -| BIGINT | java.lang.Long | java.lang.Long | -| FLOAT | java.lang.Float | java.lang.Float | -| DOUBLE | java.lang.Double | java.lang.Double | -| SMALLINT | java.lang.Short | java.lang.Short | -| TINYINT | java.lang.Byte | java.lang.Byte | -| BOOL | java.lang.Boolean | java.lang.Boolean | -| BINARY | java.lang.String | byte array | -| NCHAR | java.lang.String | java.lang.String | -| JSON | - | java.lang.String | +| ----------------- | ---------------------------------- | ------------------------------------ | +| TIMESTAMP | java.lang.Long | java.sql.Timestamp | +| INT | java.lang.Integer | java.lang.Integer | +| BIGINT | java.lang.Long | java.lang.Long | +| FLOAT | java.lang.Float | java.lang.Float | +| DOUBLE | java.lang.Double | java.lang.Double | +| SMALLINT | java.lang.Short | java.lang.Short | +| TINYINT | java.lang.Byte | java.lang.Byte | +| BOOL | java.lang.Boolean | java.lang.Boolean | +| BINARY | java.lang.String | byte array | +| NCHAR | java.lang.String | java.lang.String | +| JSON | - | java.lang.String | **Note**: Only TAG supports JSON types @@ -91,8 +91,8 @@ Add following dependency in the `pom.xml` file of your Maven project: You can build Java connector from source code after cloning the TDengine project: ```shell -git clone https://github.com/taosdata/TDengine.git -cd TDengine/src/connector/jdbc +git clone https://github.com/taosdata/taos-connector-jdbc.git +cd taos-connector-jdbc mvn clean install -Dmaven.test.skip=true ``` @@ -197,6 +197,7 @@ The configuration parameters in the URL are as follows. - user: Login TDengine user name, default value 'root'. - password: user login password, default value 'taosdata'. - batchfetch: true: pull the result set in batch when executing the query; false: pull the result set row by row. The default value is false. batchfetch uses HTTP for data transfer. The JDBC REST connection supports bulk data pulling function in taos-jdbcdriver-2.0.38 and TDengine 2.4.0.12 and later versions. taos-jdbcdriver and TDengine transfer data via WebSocket connection. Compared with HTTP, WebSocket enables JDBC REST connection to support large data volume querying and improve query performance. +- charset: specify the charset to parse the string, this parameter is valid only when set batchfetch to true. - batchErrorIgnore: true: when executing executeBatch of Statement, if one SQL execution fails in the middle, continue to execute the following SQL. false: no longer execute any statement after the failed SQL. The default value is: false. **Note**: Some configuration items (e.g., locale, timezone) do not work in the REST connection. @@ -258,10 +259,10 @@ The configuration parameters in properties are as follows. - TSDBDriver.PROPERTY_KEY_BATCH_LOAD: true: pull the result set in batch when executing query; false: pull the result set row by row. The default value is: false. - TSDBDriver.PROPERTY_KEY_BATCH_ERROR_IGNORE: true: when executing executeBatch of Statement, if there is a SQL execution failure in the middle, continue to execute the following sq. false: no longer execute any statement after the failed SQL. The default value is: false. - TSDBDriver.PROPERTY_KEY_CONFIG_DIR: Only works when using JDBC native connection. Client configuration file directory path, default value `/etc/taos` on Linux OS, default value `C:/TDengine/cfg` on Windows OS. -- TSDBDriver.PROPERTY_KEY_CHARSET: takes effect only when using JDBC native connection. In the character set used by the client, the default value is the system character set. +- TSDBDriver.PROPERTY_KEY_CHARSET: In the character set used by the client, the default value is the system character set. - TSDBDriver.PROPERTY_KEY_LOCALE: this only takes effect when using JDBC native connection. Client language environment, the default value is system current locale. - TSDBDriver.PROPERTY_KEY_TIME_ZONE: only takes effect when using JDBC native connection. In the time zone used by the client, the default value is the system's current time zone. -For JDBC native connections, you can specify other parameters, such as log level, SQL length, etc., by specifying URL and Properties. For more detailed configuration, please refer to [Client Configuration](/reference/config/#Client-Only). + For JDBC native connections, you can specify other parameters, such as log level, SQL length, etc., by specifying URL and Properties. For more detailed configuration, please refer to [Client Configuration](/reference/config/#Client-Only). ### Priority of configuration parameters @@ -350,7 +351,7 @@ There are three types of error codes that the JDBC connector can report: For specific error codes, please refer to. -- [TDengine Java Connector](https://github.com/taosdata/TDengine/blob/develop/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java) +- [TDengine Java Connector](https://github.com/taosdata/taos-connector-jdbc/blob/main/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java) - [TDengine_ERROR_CODE](https://github.com/taosdata/TDengine/blob/develop/src/inc/taoserror.h) ### Writing data via parameter binding @@ -808,11 +809,11 @@ Please refer to: [JDBC example](https://github.com/taosdata/TDengine/tree/develo ## Recent update logs -| taos-jdbcdriver version | major changes | -| :------------------: | :----------------------------: | -| 2.0.38 | JDBC REST connections add bulk pull function | -| 2.0.37 | Added support for json tags | -| 2.0.36 | Add support for schemaless writing | +| taos-jdbcdriver version | major changes | +| :---------------------: | :------------------------------------------: | +| 2.0.38 | JDBC REST connections add bulk pull function | +| 2.0.37 | Added support for json tags | +| 2.0.36 | Add support for schemaless writing | ## Frequently Asked Questions diff --git a/docs-en/14-reference/03-connector/php.mdx b/docs-en/14-reference/03-connector/php.mdx new file mode 100644 index 0000000000..839a5c8c3c --- /dev/null +++ b/docs-en/14-reference/03-connector/php.mdx @@ -0,0 +1,150 @@ +--- +sidebar_position: 1 +sidebar_label: PHP +title: PHP Connector +--- + +`php-tdengine` is the TDengine PHP connector provided by TDengine community. In particular, it supports Swoole coroutine. + +PHP Connector relies on TDengine client driver. + +Project Repository: + +After TDengine client or server is installed, `taos.h` is located at: + +- Linux:`/usr/local/taos/include` +- Windows:`C:\TDengine\include` + +TDengine client driver is located at: + +- Linux: `/usr/local/taos/driver/libtaos.so` +- Windows: `C:\TDengine\taos.dll` + +## Supported Platforms + +- Windows、Linux、MacOS + +- PHP >= 7.4 + +- TDengine >= 2.0 + +- Swoole >= 4.8 (Optional) + +## Supported Versions + +Because the version of TDengine client driver is tightly associated with that of TDengine server, it's strongly suggested to use the client driver of same version as TDengine server, even though the client driver can work with TDengine server if the first 3 sections of the versions are same. + +## Installation + +### Install TDengine Client Driver + +Regarding how to install TDengine client driver please refer to [Install Client Driver](/reference/connector#installation-steps) + +### Install php-tdengine + +**Download Source Code Package and Unzip:** + +```shell +curl -L -o php-tdengine.tar.gz https://github.com/Yurunsoft/php-tdengine/archive/refs/tags/v1.0.2.tar.gz \ +&& mkdir php-tdengine \ +&& tar -xzf php-tdengine.tar.gz -C php-tdengine --strip-components=1 +``` + +> Version number `v1.0.2` is only for example, it can be replaced to any newer version, please find available versions in [TDengine PHP Connector Releases](https://github.com/Yurunsoft/php-tdengine/releases). + +**Non-Swoole Environment:** + +```shell +phpize && ./configure && make -j && make install +``` + +**Specify TDengine location:** + +```shell +phpize && ./configure --with-tdengine-dir=/usr/local/Cellar/tdengine/2.4.0.0 && make -j && make install +``` + +> `--with-tdengine-dir=` is followed by TDengine location. +> It's useful in case TDengine installatio location can't be found automatically or MacOS. + +**Swoole Environment:** + +```shell +phpize && ./configure --enable-swoole && make -j && make install +``` + +**Enable Extension:** + +Option One: Add `extension=tdengine` in `php.ini`. + +Option Two: Use CLI `php -dextension=tdengine test.php`. + +## Sample Programs + +In this section a few sample programs which use TDengine PHP connector to access TDengine cluster are demonstrated. + +> Any error would throw exception: `TDengine\Exception\TDengineException` + +### Establish Conection + +
+Establish Connection + +```c +{{#include docs-examples/php/connect.php}} +``` + +
+ +### Insert Data + +
+Insert Data + +```c +{{#include docs-examples/php/insert.php}} +``` + +
+ +### Synchronous Query + +
+Synchronous Query + +```c +{{#include docs-examples/php/query.php}} +``` + +
+ +### Parameter Binding + +
+Parameter Binding + +```c +{{#include docs-examples/php/insert_stmt.php}} +``` + +
+ +## Constants + +| Constant | Description | +| ----------------------------------- | ----------- | +| `TDengine\TSDB_DATA_TYPE_NULL` | null | +| `TDengine\TSDB_DATA_TYPE_BOOL` | bool | +| `TDengine\TSDB_DATA_TYPE_TINYINT` | tinyint | +| `TDengine\TSDB_DATA_TYPE_SMALLINT` | smallint | +| `TDengine\TSDB_DATA_TYPE_INT` | int | +| `TDengine\TSDB_DATA_TYPE_BIGINT` | bigint | +| `TDengine\TSDB_DATA_TYPE_FLOAT` | float | +| `TDengine\TSDB_DATA_TYPE_DOUBLE` | double | +| `TDengine\TSDB_DATA_TYPE_BINARY` | binary | +| `TDengine\TSDB_DATA_TYPE_TIMESTAMP` | timestamp | +| `TDengine\TSDB_DATA_TYPE_NCHAR` | nchar | +| `TDengine\TSDB_DATA_TYPE_UTINYINT` | utinyint | +| `TDengine\TSDB_DATA_TYPE_USMALLINT` | usmallint | +| `TDengine\TSDB_DATA_TYPE_UINT` | uint | +| `TDengine\TSDB_DATA_TYPE_UBIGINT` | ubigint | diff --git a/docs-en/14-reference/03-connector/python.mdx b/docs-en/14-reference/03-connector/python.mdx index 69eec2388d..58b94f13ae 100644 --- a/docs-en/14-reference/03-connector/python.mdx +++ b/docs-en/14-reference/03-connector/python.mdx @@ -199,10 +199,9 @@ The `connect()` function returns a `taos.TaosConnection` instance. In client-sid All arguments to the `connect()` function are optional keyword arguments. The following are the connection parameters specified. -- `host`: The host to connect to. The default is localhost. +- `url`: The URL of taosAdapter REST service. The default is . - `user`: TDengine user name. The default is `root`. - `password`: TDengine user password. The default is `taosdata`. -- `port`: The port on which the taosAdapter REST service listens. Default is 6041. - `timeout`: HTTP request timeout in seconds. The default is `socket._GLOBAL_DEFAULT_TIMEOUT`. Usually, no configuration is needed. diff --git a/docs-en/14-reference/05-taosbenchmark.md b/docs-en/14-reference/05-taosbenchmark.md index b029f3d3ee..7cf1f95eb1 100644 --- a/docs-en/14-reference/05-taosbenchmark.md +++ b/docs-en/14-reference/05-taosbenchmark.md @@ -21,7 +21,7 @@ There are two ways to install taosBenchmark: ### Configuration and running methods -taosBenchmark supports two configuration methods: [Command-line arguments](#Command-line arguments in detailed) and [JSON configuration file](#Configuration file arguments in detailed). These two methods are mutually exclusive. Users can use `-f ` to specify a configuration file. When running taosBenchmark with command-line arguments to control its behavior, users should use other parameters for configuration, but not the `-f` parameter. In addition, taosBenchmark offers a special way of running without parameters. +TaosBenchmark needs to be executed on the terminal of the operating system, it supports two configuration methods: [Command-line arguments](#Command-line arguments in detailed) and [JSON configuration file](#Configuration file arguments in detailed). These two methods are mutually exclusive. Users can use `-f ` to specify a configuration file. When running taosBenchmark with command-line arguments to control its behavior, users should use other parameters for configuration, but not the `-f` parameter. In addition, taosBenchmark offers a special way of running without parameters. taosBenchmark supports complete performance testing of TDengine. taosBenchmark supports the TDengine functions in three categories: write, query, and subscribe. These three functions are mutually exclusive, and users can select only one of them each time taosBenchmark runs. It is important to note that the type of functionality to be tested is not configurable when using the command-line configuration method, which can only test writing performance. To test the query and subscription performance of the TDengine, you must use the configuration file method and specify the function type to test via the parameter `filetype` in the configuration file. diff --git a/docs-en/14-reference/12-config/index.md b/docs-en/14-reference/12-config/index.md index 8ad9a474a0..b6b535429b 100644 --- a/docs-en/14-reference/12-config/index.md +++ b/docs-en/14-reference/12-config/index.md @@ -134,7 +134,7 @@ TDengine uses 13 continuous ports, both TCP and UDP, starting with the port spec | Applicable | Server Only | | Meaning | The switch for monitoring inside server. The workload of the hosts, including CPU, memory, disk, network, TTP requests, are collected and stored in a system builtin database `LOG` | | Value Range | 0: monitoring disabled, 1: monitoring enabled | -| Default Value | 0 | +| Default Value | 1 | ### monitorInterval diff --git a/docs-en/20-third-party/01-grafana.mdx b/docs-en/20-third-party/01-grafana.mdx index 1a84e02c66..033ef3b206 100644 --- a/docs-en/20-third-party/01-grafana.mdx +++ b/docs-en/20-third-party/01-grafana.mdx @@ -3,6 +3,9 @@ sidebar_label: Grafana title: Grafana --- +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + TDengine can be quickly integrated with the open-source data visualization system [Grafana](https://www.grafana.com/) to build a data monitoring and alerting system. The whole process does not require any code development. And you can visualize the contents of the data tables in TDengine on a dashboard. You can learn more about using the TDengine plugin on [GitHub](https://github.com/taosdata/grafanaplugin/blob/master/README.md). @@ -14,12 +17,44 @@ In order for Grafana to add the TDengine data source successfully, the following 1. The TDengine cluster is deployed and functioning properly 2. taosAdapter is installed and running properly. Please refer to the taosAdapter manual for details. +Record these values: + +- TDengine REST API url: `http://tdengine.local:6041`. +- TDengine cluster authorization, with user + password. + ## Installing Grafana -TDengine currently supports Grafana versions 7.0 and above. Users can go to the Grafana official website to download the installation package and execute the installation according to the current operating system. The download address is as follows: . +TDengine currently supports Grafana versions 7.5 and above. Users can go to the Grafana official website to download the installation package and execute the installation according to the current operating system. The download address is as follows: . ## Configuring Grafana +### Install Grafana Plugin and Configure Data Source + + + + +Set the url and authorization environment variables by `export` or a [`.env`(dotenv) file](https://hexdocs.pm/dotenvy/dotenv-file-format.html): + +```sh +export TDENGINE_API=http://tdengine.local:6041 +# user + password +export TDENGINE_USER=user +export TDENGINE_PASSWORD=password +``` + +Run `install.sh`: + +```sh +bash -c "$(curl -fsSL https://raw.githubusercontent.com/taosdata/grafanaplugin/master/install.sh)" +``` + +With this script, TDengine data source plugin and the Grafana data source will be installed and created automatically with Grafana provisioning configurations. + +And then, restart Grafana service and open Grafana in web-browser, usually . + + + + Follow the installation steps in [Grafana](https://grafana.com/grafana/plugins/tdengine-datasource/?tab=installation) with the [``grafana-cli`` command-line tool](https://grafana.com/docs/grafana/latest/administration/cli/) for plugin installation. ```bash @@ -50,11 +85,7 @@ If Grafana is running in a Docker environment, the TDengine plugin can be automa GF_INSTALL_PLUGINS=tdengine-datasource ``` -## Using Grafana - -### Configuring Data Sources - -Users can log in to the Grafana server (username/password: admin/admin) directly through the URL `http://localhost:3000` and add a datasource through `Configuration -> Data Sources` on the left side, as shown in the following figure. +Now users can log in to the Grafana server (username/password: admin/admin) directly through the URL `http://localhost:3000` and add a datasource through `Configuration -> Data Sources` on the left side, as shown in the following figure. ![TDengine Database TDinsight plugin add datasource 1](./grafana/add_datasource1.webp) @@ -74,6 +105,9 @@ Click `Save & Test` to test. You should see a success message if the test worked ![TDengine Database TDinsight plugin add database 4](./grafana/add_datasource4.webp) + + + ### Create Dashboard Go back to the main interface to create a dashboard and click Add Query to enter the panel query page: @@ -94,4 +128,11 @@ Follow the default prompt to query the average system memory usage for the speci ### Importing the Dashboard -In version 2.3.3.0 and above, you can import the TDinsight Dashboard (Grafana Dashboard ID: [15168](https://grafana.com/grafana/dashboards/15167)) as a monitoring visualization tool for TDengine clusters. You can find installation and usage instructions in the TDinsight User Manual (/reference/tdinsight/). +You can install TDinsight dashboard in data source configuration page (like `http://localhost:3000/datasources/edit/1/dashboards`) as a monitoring visualization tool for TDengine cluster. The dashboard is published in Grafana as [Dashboard 15167 - TDinsight](https://grafana.com/grafana/dashboards/15167). Check the [TDinsight User Manual](/reference/tdinsight/) for the details. + +For more dashboards using TDengine data source, [search here in Grafana](https://grafana.com/grafana/dashboards/?dataSource=tdengine-datasource). Here is a sub list: + +- [15146](https://grafana.com/grafana/dashboards/15146): Monitor multiple TDengine clusters. +- [15155](https://grafana.com/grafana/dashboards/15155): TDengine alert demo. +- [15167](https://grafana.com/grafana/dashboards/15167): TDinsight. +- [16388](https://grafana.com/grafana/dashboards/16388): Telegraf node metrics dashboard using TDengine data source. diff --git a/docs-en/20-third-party/09-emq-broker.md b/docs-en/20-third-party/09-emq-broker.md index d3eafebc14..7c6b83cf99 100644 --- a/docs-en/20-third-party/09-emq-broker.md +++ b/docs-en/20-third-party/09-emq-broker.md @@ -16,22 +16,15 @@ The following preparations are required for EMQX to add TDengine data sources co Depending on the current operating system, users can download the installation package from the [EMQX official website](https://www.emqx.io/downloads) and execute the installation. After installation, use `sudo emqx start` or `sudo systemctl start emqx` to start the EMQX service. -## Create the appropriate database and table schema in TDengine for receiving MQTT data -### Take the Docker installation of TDengine as an example +## Create Database and Table -```bash - docker exec -it tdengine bash - taos -``` - -### Create Database and Table +In this step we create the appropriate database and table schema in TDengine for receiving MQTT data. Open TDengine CLI and execute SQL bellow: ```sql - CREATE DATABASE test; - USE test; - - CREATE TABLE sensor_data (ts timestamp, temperature float, humidity float, volume float, PM10 float, pm25 float, SO2 float, NO2 float, CO float, sensor_id NCHAR(255), area TINYINT, coll_time timestamp); +CREATE DATABASE test; +USE test; +CREATE TABLE sensor_data (ts TIMESTAMP, temperature FLOAT, humidity FLOAT, volume FLOAT, pm10 FLOAT, pm25 FLOAT, so2 FLOAT, no2 FLOAT, co FLOAT, sensor_id NCHAR(255), area TINYINT, coll_time TIMESTAMP); ``` Note: The table schema is based on the blog [(In Chinese) Data Transfer, Storage, Presentation, EMQX + TDengine Build MQTT IoT Data Visualization Platform](https://www.taosdata.com/blog/2020/08/04/1722.html) as an example. Subsequent operations are carried out with this blog scenario too. Please modify it according to your actual application scenario. @@ -54,6 +47,15 @@ Select "Rule" in the "Rule Engine" on the left and click the "Create" button: ! ### Edit SQL fields +Copy SQL bellow and paste it to the SQL edit area: + +```sql +SELECT + payload +FROM + "sensor/data" +``` + ![TDengine Database EMQX create rule](./emqx/create-rule.webp) ### Add "action handler" @@ -68,97 +70,45 @@ Select "Data to Web Service" and click the "New Resource" button. ### Edit "Resource" -Select "Data to Web Service" and fill in the request URL as the address and port of the server running taosAdapter (default is 6041). Leave the other properties at their default values. +Select "WebHook" and fill in the request URL as the address and port of the server running taosAdapter (default is 6041). Leave the other properties at their default values. ![TDengine Database EMQX edit resource](./emqx/edit-resource.webp) ### Edit "action" -Edit the resource configuration to add the key/value pairing for Authorization. Please refer to the [ TDengine REST API documentation ](https://docs.taosdata.com/reference/rest-api/) for the authorization in details. Enter the rule engine replacement template in the message body. +Edit the resource configuration to add the key/value pairing for Authorization. If you use the default TDengine username and password then the value of key Authorization is: +``` +Basic cm9vdDp0YW9zZGF0YQ== +``` + +Please refer to the [ TDengine REST API documentation ](/reference/rest-api/) for the authorization in details. + +Enter the rule engine replacement template in the message body: + +```sql +INSERT INTO test.sensor_data VALUES( + now, + ${payload.temperature}, + ${payload.humidity}, + ${payload.volume}, + ${payload.PM10}, + ${payload.pm25}, + ${payload.SO2}, + ${payload.NO2}, + ${payload.CO}, + '${payload.id}', + ${payload.area}, + ${payload.ts} +) +``` ![TDengine Database EMQX edit action](./emqx/edit-action.webp) +Finally, click the "Create" button at bottom left corner saving the rule. ## Compose program to mock data ```javascript - // mock.js - const mqtt = require('mqtt') - const Mock = require('mockjs') - const EMQX_SERVER = 'mqtt://localhost:1883' - const CLIENT_NUM = 10 - const STEP = 5000 // Data interval in ms - const AWAIT = 5000 // Sleep time after data be written once to avoid data writing too fast - const CLIENT_POOL = [] - startMock() - function sleep(timer = 100) { - return new Promise(resolve => { - setTimeout(resolve, timer) - }) - } - async function startMock() { - const now = Date.now() - for (let i = 0; i < CLIENT_NUM; i++) { - const client = await createClient(`mock_client_${i}`) - CLIENT_POOL.push(client) - } - // last 24h every 5s - const last = 24 * 3600 * 1000 - for (let ts = now - last; ts <= now; ts += STEP) { - for (const client of CLIENT_POOL) { - const mockData = generateMockData() - const data = { - ...mockData, - id: client.clientId, - area: 0, - ts, - } - client.publish('sensor/data', JSON.stringify(data)) - } - const dateStr = new Date(ts).toLocaleTimeString() - console.log(`${dateStr} send success.`) - await sleep(AWAIT) - } - console.log(`Done, use ${(Date.now() - now) / 1000}s`) - } - /** - * Init a virtual mqtt client - * @param {string} clientId ClientID - */ - function createClient(clientId) { - return new Promise((resolve, reject) => { - const client = mqtt.connect(EMQX_SERVER, { - clientId, - }) - client.on('connect', () => { - console.log(`client ${clientId} connected`) - resolve(client) - }) - client.on('reconnect', () => { - console.log('reconnect') - }) - client.on('error', (e) => { - console.error(e) - reject(e) - }) - }) - } - /** - * Generate mock data - */ - function generateMockData() { - return { - "temperature": parseFloat(Mock.Random.float(22, 100).toFixed(2)), - "humidity": parseFloat(Mock.Random.float(12, 86).toFixed(2)), - "volume": parseFloat(Mock.Random.float(20, 200).toFixed(2)), - "PM10": parseFloat(Mock.Random.float(0, 300).toFixed(2)), - "pm25": parseFloat(Mock.Random.float(0, 300).toFixed(2)), - "SO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)), - "NO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)), - "CO": parseFloat(Mock.Random.float(0, 50).toFixed(2)), - "area": Mock.Random.integer(0, 20), - "ts": 1596157444170, - } - } +{{#include docs-examples/other/mock.js}} ``` Note: `CLIENT_NUM` in the code can be set to a smaller value at the beginning of the test to avoid hardware performance be not capable to handle a more significant number of concurrent clients. diff --git a/docs-en/27-train-faq/01-faq.md b/docs-en/27-train-faq/01-faq.md index e182e25b9e..c10bca1d05 100644 --- a/docs-en/27-train-faq/01-faq.md +++ b/docs-en/27-train-faq/01-faq.md @@ -45,7 +45,7 @@ When the client is unable to connect to the server, you can try the following wa Check whether a TCP port on server side is open: `nc -l {port}` Check whether a TCP port on client side is open: `nc {hostIP} {port}` - - On Windows system `Net-TestConnection -ComputerName {fqdn} -Port {port}` on PowerShell can be used to check whether the port on server side is open for access. + - On Windows system `Test-NetConnection -ComputerName {fqdn} -Port {port}` on PowerShell can be used to check whether the port on server side is open for access. 7. TDengine CLI `taos` can also be used to check network, please refer to [TDengine CLI](/reference/taos-shell). diff --git a/docs-examples/other/mock.js b/docs-examples/other/mock.js new file mode 100644 index 0000000000..136c5afa96 --- /dev/null +++ b/docs-examples/other/mock.js @@ -0,0 +1,78 @@ +// mock.js +const mqtt = require('mqtt') +const Mock = require('mockjs') +const EMQX_SERVER = 'mqtt://localhost:1883' +const CLIENT_NUM = 10 +const STEP = 5000 // Data interval in ms +const AWAIT = 5000 // Sleep time after data be written once to avoid data writing too fast +const CLIENT_POOL = [] +startMock() +function sleep(timer = 100) { + return new Promise(resolve => { + setTimeout(resolve, timer) + }) +} +async function startMock() { + const now = Date.now() + for (let i = 0; i < CLIENT_NUM; i++) { + const client = await createClient(`mock_client_${i}`) + CLIENT_POOL.push(client) + } + // last 24h every 5s + const last = 24 * 3600 * 1000 + for (let ts = now - last; ts <= now; ts += STEP) { + for (const client of CLIENT_POOL) { + const mockData = generateMockData() + const data = { + ...mockData, + id: client.clientId, + area: 0, + ts, + } + client.publish('sensor/data', JSON.stringify(data)) + } + const dateStr = new Date(ts).toLocaleTimeString() + console.log(`${dateStr} send success.`) + await sleep(AWAIT) + } + console.log(`Done, use ${(Date.now() - now) / 1000}s`) +} +/** + * Init a virtual mqtt client + * @param {string} clientId ClientID + */ +function createClient(clientId) { + return new Promise((resolve, reject) => { + const client = mqtt.connect(EMQX_SERVER, { + clientId, + }) + client.on('connect', () => { + console.log(`client ${clientId} connected`) + resolve(client) + }) + client.on('reconnect', () => { + console.log('reconnect') + }) + client.on('error', (e) => { + console.error(e) + reject(e) + }) + }) +} +/** +* Generate mock data +*/ +function generateMockData() { + return { + "temperature": parseFloat(Mock.Random.float(22, 100).toFixed(2)), + "humidity": parseFloat(Mock.Random.float(12, 86).toFixed(2)), + "volume": parseFloat(Mock.Random.float(20, 200).toFixed(2)), + "PM10": parseFloat(Mock.Random.float(0, 300).toFixed(2)), + "pm25": parseFloat(Mock.Random.float(0, 300).toFixed(2)), + "SO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)), + "NO2": parseFloat(Mock.Random.float(0, 50).toFixed(2)), + "CO": parseFloat(Mock.Random.float(0, 50).toFixed(2)), + "area": Mock.Random.integer(0, 20), + "ts": 1596157444170, + } +} \ No newline at end of file diff --git a/docs-examples/php/insert_stmt.php b/docs-examples/php/insert_stmt.php index 99a9a6aef3..c927a9b0ce 100644 --- a/docs-examples/php/insert_stmt.php +++ b/docs-examples/php/insert_stmt.php @@ -22,7 +22,7 @@ try { // set table name and tags $stmt->setTableNameTags('d1001', [ - // 支持格式同参数绑定 + // same format as parameter binding [TDengine\TSDB_DATA_TYPE_BINARY, 'California.SanFrancisco'], [TDengine\TSDB_DATA_TYPE_INT, 2], ]); diff --git a/docs-examples/python/connect_rest_examples.py b/docs-examples/python/connect_rest_examples.py index 3303eb0e19..900ec1022e 100644 --- a/docs-examples/python/connect_rest_examples.py +++ b/docs-examples/python/connect_rest_examples.py @@ -1,10 +1,9 @@ # ANCHOR: connect from taosrest import connect, TaosRestConnection, TaosRestCursor -conn: TaosRestConnection = connect(host="localhost", +conn: TaosRestConnection = connect(url="http://localhost:6041", user="root", password="taosdata", - port=6041, timeout=30) # ANCHOR_END: connect diff --git a/docs-examples/python/rest_client_example.py b/docs-examples/python/rest_client_example.py index 46d33a1d79..59c629df95 100644 --- a/docs-examples/python/rest_client_example.py +++ b/docs-examples/python/rest_client_example.py @@ -1,6 +1,6 @@ from taosrest import RestClient -client = RestClient("localhost", 6041, "root", "taosdata") +client = RestClient("http://localhost:6041", user="root", password="taosdata") res: dict = client.sql("SELECT ts, current FROM power.meters LIMIT 1") print(res) diff --git a/examples/c/stream_demo.c b/examples/c/stream_demo.c index 97ff2886fc..943fcbdb53 100644 --- a/examples/c/stream_demo.c +++ b/examples/c/stream_demo.c @@ -25,7 +25,7 @@ int32_t init_env() { return -1; } - TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1"); + TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2"); if (taos_errno(pRes) != 0) { printf("error in create db, reason:%s\n", taos_errstr(pRes)); return -1; @@ -82,7 +82,7 @@ int32_t create_stream() { /*const char* sql = "select sum(k) from tu1 interval(10m)";*/ /*pRes = tmq_create_stream(pConn, "stream1", "out1", sql);*/ pRes = taos_query( - pConn, "create stream stream1 trigger at_once into outstb as select _wstartts, sum(k) from tu1 interval(10m)"); + pConn, "create stream stream1 trigger at_once into outstb as select _wstartts, sum(k) from st1 interval(10m)"); if (taos_errno(pRes) != 0) { printf("failed to create stream stream1, reason:%s\n", taos_errstr(pRes)); return -1; diff --git a/include/client/taos.h b/include/client/taos.h index 7f317b3a9d..b4e5a41ccf 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -103,10 +103,10 @@ typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code); typedef struct TAOS_MULTI_BIND { int buffer_type; - void * buffer; + void *buffer; uintptr_t buffer_length; - int32_t * length; - char * is_null; + int32_t *length; + char *is_null; int num; } TAOS_MULTI_BIND; @@ -130,7 +130,7 @@ DLL_EXPORT void taos_cleanup(void); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); DLL_EXPORT setConfRet taos_set_config(const char *config); DLL_EXPORT int taos_init(void); -DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); +DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen, const char *db, int dbLen, uint16_t port); DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port); @@ -147,17 +147,17 @@ DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name DLL_EXPORT int taos_stmt_get_tag_fields(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields); DLL_EXPORT int taos_stmt_get_col_fields(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields); -DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert); -DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums); -DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes); -DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); -DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); -DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx); -DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt); -DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt); +DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert); +DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums); +DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes); +DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); +DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); +DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx); +DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt); +DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt); DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt); -DLL_EXPORT char * taos_stmt_errstr(TAOS_STMT *stmt); +DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt); @@ -179,11 +179,11 @@ DLL_EXPORT bool taos_is_update_query(TAOS_RES *res); DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows); DLL_EXPORT int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows); DLL_EXPORT int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData); -DLL_EXPORT int * taos_get_column_data_offset(TAOS_RES *res, int columnIndex); +DLL_EXPORT int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex); DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql); DLL_EXPORT void taos_reset_current_db(TAOS *taos); -DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res); +DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res); DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res); DLL_EXPORT const char *taos_get_server_info(TAOS *taos); @@ -194,6 +194,7 @@ DLL_EXPORT int taos_errno(TAOS_RES *tres); DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param); DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param); +DLL_EXPORT void taos_fetch_raw_block_a(TAOS_RES* res, __taos_async_fn_t fp, void* param); // Shuduo: temporary enable for app build #if 1 @@ -204,17 +205,17 @@ DLL_EXPORT TAOS_RES *taos_consume(TAOS_SUB *tsub); DLL_EXPORT void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress); #endif -DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList); +DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList); DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision); /* --------------------------TMQ INTERFACE------------------------------- */ -enum tmq_resp_err_t { +enum { TMQ_RESP_ERR__FAIL = -1, TMQ_RESP_ERR__SUCCESS = 0, }; -typedef enum tmq_resp_err_t tmq_resp_err_t; +typedef int32_t tmq_resp_err_t; typedef struct tmq_t tmq_t; typedef struct tmq_topic_vgroup_t tmq_topic_vgroup_t; @@ -229,7 +230,7 @@ DLL_EXPORT tmq_list_t *tmq_list_new(); DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *); DLL_EXPORT void tmq_list_destroy(tmq_list_t *); DLL_EXPORT int32_t tmq_list_get_size(const tmq_list_t *); -DLL_EXPORT char ** tmq_list_to_c_array(const tmq_list_t *); +DLL_EXPORT char **tmq_list_to_c_array(const tmq_list_t *); DLL_EXPORT tmq_t *tmq_consumer_new(tmq_conf_t *conf, char *errstr, int32_t errstrLen); @@ -240,7 +241,7 @@ DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t); DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, const tmq_list_t *topic_list); DLL_EXPORT tmq_resp_err_t tmq_unsubscribe(tmq_t *tmq); DLL_EXPORT tmq_resp_err_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics); -DLL_EXPORT TAOS_RES * tmq_consumer_poll(tmq_t *tmq, int64_t timeout); +DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t timeout); DLL_EXPORT tmq_resp_err_t tmq_consumer_close(tmq_t *tmq); DLL_EXPORT tmq_resp_err_t tmq_commit_sync(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets); DLL_EXPORT void tmq_commit_async(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets, tmq_commit_cb *cb, void *param); @@ -260,7 +261,7 @@ enum tmq_conf_res_t { typedef enum tmq_conf_res_t tmq_conf_res_t; -DLL_EXPORT tmq_conf_t * tmq_conf_new(); +DLL_EXPORT tmq_conf_t *tmq_conf_new(); DLL_EXPORT tmq_conf_res_t tmq_conf_set(tmq_conf_t *conf, const char *key, const char *value); DLL_EXPORT void tmq_conf_destroy(tmq_conf_t *conf); DLL_EXPORT void tmq_conf_set_auto_commit_cb(tmq_conf_t *conf, tmq_commit_cb *cb, void *param); diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 88fa0e728f..61286cd675 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -77,7 +77,9 @@ typedef struct SDataBlockInfo { int16_t numOfCols; int16_t hasVarCol; int32_t capacity; - EStreamType type; + // TODO: optimize and remove following + int32_t childId; // used for stream, do not serialize + EStreamType type; // used for stream, do not serialize } SDataBlockInfo; typedef struct SSDataBlock { @@ -105,14 +107,15 @@ typedef struct SColumnInfoData { } SColumnInfoData; typedef struct SQueryTableDataCond { - //STimeWindow twindow; + // STimeWindow twindow; + uint64_t suid; int32_t order; // desc|asc order to iterate the data block int32_t numOfCols; - SColumnInfo *colList; + SColumnInfo* colList; bool loadExternalRows; // load external rows or not int32_t type; // data block load type: int32_t numOfTWindows; - STimeWindow *twindows; + STimeWindow* twindows; } SQueryTableDataCond; void* blockDataDestroy(SSDataBlock* pBlock); @@ -202,17 +205,17 @@ typedef struct SExprInfo { } SExprInfo; typedef struct { - const char* key; - int32_t keyLen; - uint8_t type; - union{ + const char* key; + int32_t keyLen; + uint8_t type; + union { const char* value; int64_t i; uint64_t u; double d; float f; }; - int32_t length; + int32_t length; } SSmlKv; #define QUERY_ASC_FORWARD_STEP 1 @@ -220,7 +223,7 @@ typedef struct { #define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP) -#define SORT_QSORT_T 0x1 +#define SORT_QSORT_T 0x1 #define SORT_SPILLED_MERGE_SORT_T 0x2 typedef struct SSortExecInfo { int32_t sortMethod; diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 8d69bb6c70..af46535c94 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -71,7 +71,7 @@ SEpSet getEpSet_s(SCorEpSet* pEpSet); #define colDataGetData(p1_, r_) \ ((IS_VAR_DATA_TYPE((p1_)->info.type)) ? colDataGetVarData(p1_, r_) : colDataGetNumData(p1_, r_)) -#define IS_JSON_NULL(type,data) ((type) == TSDB_DATA_TYPE_JSON && *(data) == TSDB_DATA_TYPE_NULL) +#define IS_JSON_NULL(type, data) ((type) == TSDB_DATA_TYPE_JSON && *(data) == TSDB_DATA_TYPE_NULL) static FORCE_INLINE bool colDataIsNull_s(const SColumnInfoData* pColumnInfoData, uint32_t row) { if (!pColumnInfoData->hasNull) { @@ -180,7 +180,7 @@ static FORCE_INLINE void colDataAppendDouble(SColumnInfoData* pColumnInfoData, u *(double*)p = *(double*)v; } -int32_t getJsonValueLen(const char *data); +int32_t getJsonValueLen(const char* data); int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull); int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, int32_t* capacity, @@ -206,7 +206,7 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3 size_t blockDataGetSize(const SSDataBlock* pBlock); size_t blockDataGetRowSize(SSDataBlock* pBlock); double blockDataGetSerialRowSize(const SSDataBlock* pBlock); -size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock); +size_t blockDataGetSerialMetaSize(uint32_t numOfCols); int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo); int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst); @@ -223,7 +223,8 @@ int32_t blockDataTrimFirstNRows(SSDataBlock* pBlock, size_t n); SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData); -void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, int8_t needCompress); +void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, + int8_t needCompress); const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t numOfRows, const char* pData); void blockDebugShowData(const SArray* dataBlocks, const char* flag); @@ -231,11 +232,13 @@ void blockDebugShowData(const SArray* dataBlocks, const char* flag); int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks, STSchema* pTSchema, int32_t vgId, tb_uid_t suid); +char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId); + SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema, bool createTb, int64_t suid, const char* stbFullName, int32_t vgId); static FORCE_INLINE int32_t blockGetEncodeSize(const SSDataBlock* pBlock) { - return blockDataGetSerialMetaSize(pBlock) + blockDataGetSize(pBlock); + return blockDataGetSerialMetaSize(pBlock->info.numOfCols) + blockDataGetSize(pBlock); } static FORCE_INLINE int32_t blockCompressColData(SColumnInfoData* pColRes, int32_t numOfRows, char* data, diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 47c26ed431..5453c8d0ea 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -933,6 +933,7 @@ typedef struct { int64_t numOfProcessedFetch; int64_t numOfProcessedDrop; int64_t numOfProcessedHb; + int64_t numOfProcessedDelete; int64_t cacheDataSize; int64_t numOfQueryInQueue; int64_t numOfFetchInQueue; @@ -1314,6 +1315,31 @@ typedef struct { int32_t tSerializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq); int32_t tDeserializeSKillTransReq(void* buf, int32_t bufLen, SKillTransReq* pReq); +typedef struct { + int32_t useless; // useless +} SBalanceVgroupReq; + +int32_t tSerializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq); +int32_t tDeserializeSBalanceVgroupReq(void* buf, int32_t bufLen, SBalanceVgroupReq* pReq); + +typedef struct { + int32_t vgId1; + int32_t vgId2; +} SMergeVgroupReq; + +int32_t tSerializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq); +int32_t tDeserializeSMergeVgroupReq(void* buf, int32_t bufLen, SMergeVgroupReq* pReq); + +typedef struct { + int32_t vgId; + int32_t dnodeId1; + int32_t dnodeId2; + int32_t dnodeId3; +} SRedistributeVgroupReq; + +int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq); +int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq); + typedef struct { char user[TSDB_USER_LEN]; char spi; @@ -2459,6 +2485,33 @@ typedef struct { int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp); int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp); +typedef struct { + char tbFName[TSDB_TABLE_FNAME_LEN]; +} STableIndexReq; + +int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq); +int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq); + +typedef struct { + int8_t intervalUnit; + int8_t slidingUnit; + int64_t interval; + int64_t offset; + int64_t sliding; + int64_t dstTbUid; + int32_t dstVgId; // for stream + SEpSet epSet; + char* expr; +} STableIndexInfo; + +typedef struct { + SArray* pIndex; +} STableIndexRsp; + +int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp); +int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp); + + typedef struct { int8_t mqMsgType; int32_t code; @@ -2689,20 +2742,20 @@ int32_t tEncodeSVSubmitReq(SEncoder* pCoder, const SVSubmitReq* pReq); int32_t tDecodeSVSubmitReq(SDecoder* pCoder, SVSubmitReq* pReq); typedef struct { - int64_t delUid; - int64_t tbUid; // super/child/normal table - int8_t type; // table type - int16_t nWnds; - char* tbFullName; - char* subPlan; - STimeWindow wnds[]; + SMsgHead header; + uint64_t sId; + uint64_t queryId; + uint64_t taskId; + uint32_t sqlLen; + uint32_t phyLen; + char* sql; + char* msg; } SVDeleteReq; -int32_t tEncodeSVDeleteReq(SEncoder* pCoder, const SVDeleteReq* pReq); -int32_t tDecodeSVDeleteReq(SDecoder* pCoder, SVDeleteReq* pReq); +int32_t tSerializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq); +int32_t tDeserializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq); typedef struct { - int32_t code; int64_t affectedRows; } SVDeleteRsp; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 73f8515f22..e922df64b3 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -130,6 +130,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_CREATE_INDEX, "create-index", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_DROP_INDEX, "drop-index", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_GET_INDEX, "get-index", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_GET_TABLE_INDEX, "get-table-index", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "create-topic", SMCreateTopicReq, SMCreateTopicRsp) TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "alter-topic", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "drop-topic", NULL, NULL) @@ -153,6 +154,9 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_GRANT, "grant", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_AUTH, "auth", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_APPLY_MSG, "mnode-apply", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_BALANCE_VGROUP, "balance-vgroup", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_MERGE_VGROUP, "merge-vgroup", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_REDISTRIBUTE_VGROUP, "redistribute-vgroup", NULL, NULL) TD_NEW_MSG_SEG(TDMT_VND_MSG) TD_DEF_MSG_TYPE(TDMT_VND_SUBMIT, "submit", SSubmitReq, SSubmitRsp) @@ -169,10 +173,6 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateStbReq, NULL) TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", SVDropStbReq, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONSUME, "vnode-mq-consume", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_MQ_QUERY, "vnode-mq-query", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONNECT, "vnode-mq-connect", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_MQ_DISCONNECT, "vnode-mq-disconnect", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_CHANGE, "vnode-mq-vg-change", SMqRebVgReq, SMqRebVgRsp) TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_DELETE, "vnode-mq-vg-delete", SMqVDeleteReq, SMqVDeleteRsp) TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_TASK, "vnode-cancel-task", NULL, NULL) @@ -183,11 +183,8 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_EXPLAIN, "vnode-explain", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_SUBSCRIBE, "vnode-subscribe", SMVSubscribeReq, SMVSubscribeRsp) TD_DEF_MSG_TYPE(TDMT_VND_CONSUME, "vnode-consume", SMqPollReq, SMqDataBlkRsp) - TD_DEF_MSG_TYPE(TDMT_VND_TASK_DEPLOY, "vnode-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp) TD_DEF_MSG_TYPE(TDMT_VND_STREAM_TRIGGER, "vnode-stream-trigger", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_TASK_RUN, "vnode-stream-task-run", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_TASK_DISPATCH, "vnode-stream-task-dispatch", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_TASK_RECOVER, "vnode-stream-task-recover", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_STREAM_DISPATCH_WRITE, "vnode-stream-task-dispatch-write", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_CREATE_SMA, "vnode-create-sma", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_SMA, "vnode-cancel-sma", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_SMA, "vnode-drop-sma", NULL, NULL) @@ -201,11 +198,12 @@ enum { TD_NEW_MSG_SEG(TDMT_QND_MSG) - TD_NEW_MSG_SEG(TDMT_SND_MSG) - TD_DEF_MSG_TYPE(TDMT_SND_TASK_DEPLOY, "snode-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp) - TD_DEF_MSG_TYPE(TDMT_SND_TASK_RUN, "snode-stream-task-run", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_SND_TASK_DISPATCH, "snode-stream-task-dispatch", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_SND_TASK_RECOVER, "snode-stream-task-recover", NULL, NULL) + //shared by snode and vnode + TD_NEW_MSG_SEG(TDMT_STREAM_MSG) + TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DEPLOY, "stream-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp) + TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RUN, "stream-task-run", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DISPATCH, "stream-task-dispatch", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RECOVER, "stream-task-recover", NULL, NULL) TD_NEW_MSG_SEG(TDMT_SCH_MSG) TD_DEF_MSG_TYPE(TDMT_SCH_LINK_BROKEN, "link-broken", NULL, NULL) diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index d28f87cb6a..715da5cc99 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -188,10 +188,10 @@ #define TK_KILL 170 #define TK_CONNECTION 171 #define TK_TRANSACTION 172 -#define TK_MERGE 173 +#define TK_BALANCE 173 #define TK_VGROUP 174 -#define TK_REDISTRIBUTE 175 -#define TK_SPLIT 176 +#define TK_MERGE 175 +#define TK_REDISTRIBUTE 176 #define TK_SYNCDB 177 #define TK_DELETE 178 #define TK_NULL 179 diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index ee237741c3..4d074db08d 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -71,16 +71,21 @@ typedef struct SCatalogReq { bool forceUpdate; } SCatalogReq; +typedef struct SMetaRes { + int32_t code; + void* pRes; +} SMetaRes; + typedef struct SMetaData { - SArray *pDbVgroup; // SArray*> - SArray *pDbCfg; // SArray - SArray *pDbInfo; // SArray - SArray *pTableMeta; // SArray - SArray *pTableHash; // SArray - SArray *pUdfList; // SArray - SArray *pIndex; // SArray - SArray *pUser; // SArray - SArray *pQnodeList; // SArray + SArray *pDbVgroup; // pRes = SArray* + SArray *pDbCfg; // pRes = SDbCfgInfo* + SArray *pDbInfo; // pRes = SDbInfo* + SArray *pTableMeta; // pRes = STableMeta* + SArray *pTableHash; // pRes = SVgroupInfo* + SArray *pUdfList; // pRes = SFuncInfo* + SArray *pIndex; // pRes = SIndexInfo* + SArray *pUser; // pRes = bool* + SArray *pQnodeList; // pRes = SQueryNodeAddr* } SMetaData; typedef struct SCatalogCfg { @@ -272,6 +277,8 @@ int32_t catalogGetDBCfg(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, cons int32_t catalogGetIndexMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* indexName, SIndexInfo* pInfo); +int32_t catalogGetTableIndex(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const char* tbFName, SArray** pRes); + int32_t catalogGetUdfInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* funcName, SFuncInfo* pInfo); int32_t catalogChkAuth(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* user, const char* dbFName, AUTH_TYPE type, bool *pass); @@ -280,7 +287,6 @@ int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth); int32_t catalogUpdateVgEpSet(SCatalog* pCtg, const char* dbFName, int32_t vgId, SEpSet *epSet); - int32_t ctgdLaunchAsyncCall(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, uint64_t reqId, bool forceUpdate); diff --git a/include/libs/executor/dataSinkMgt.h b/include/libs/executor/dataSinkMgt.h index 2cc9caca6f..c23cf162aa 100644 --- a/include/libs/executor/dataSinkMgt.h +++ b/include/libs/executor/dataSinkMgt.h @@ -32,6 +32,18 @@ extern "C" { struct SDataSink; struct SSDataBlock; +typedef struct SDeleterRes { + uint64_t uid; + SArray* uidList; + int64_t skey; + int64_t ekey; + int64_t affectedRows; +} SDeleterRes; + +typedef struct SDeleterParam { + SArray* pUidList; +} SDeleterParam; + typedef struct SDataSinkStat { uint64_t cachedSize; } SDataSinkStat; @@ -64,7 +76,7 @@ typedef struct SOutputData { * @param pHandle output * @return error code */ -int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle); +int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam); int32_t dsDataSinkGetCacheSize(SDataSinkStat *pStat); diff --git a/include/libs/function/function.h b/include/libs/function/function.h index e8cb363e08..810991f770 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -197,6 +197,7 @@ typedef struct SAggFunctionInfo { struct SScalarParam { SColumnInfoData *columnData; SHashObj *pHashFilter; + int32_t hashValueType; void *param; // other parameter, such as meta handle from vnode, to extract table name/tag value int32_t numOfRows; }; diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index f3e28936af..77376a05d9 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -122,6 +122,14 @@ typedef enum EFunctionType { // internal function FUNCTION_TYPE_SELECT_VALUE, + // distributed splitting functions + FUNCTION_TYPE_APERCENTILE_PARTIAL, + FUNCTION_TYPE_APERCENTILE_MERGE, + FUNCTION_TYPE_SPREAD_PARTIAL, + FUNCTION_TYPE_SPREAD_MERGE, + FUNCTION_TYPE_HISTOGRAM_PARTIAL, + FUNCTION_TYPE_HISTOGRAM_MERGE, + // user defined funcion FUNCTION_TYPE_UDF = 10000 } EFunctionType; diff --git a/include/libs/index/index.h b/include/libs/index/index.h index bd601f1d9f..9e71c941d3 100644 --- a/include/libs/index/index.h +++ b/include/libs/index/index.h @@ -136,14 +136,14 @@ int indexRebuild(SIndex* index, SIndexOpts* opt); * @param index (output, index json object) * @return error code */ -int tIndexJsonOpen(SIndexJsonOpts* opts, const char* path, SIndexJson** index); +int indexJsonOpen(SIndexJsonOpts* opts, const char* path, SIndexJson** index); /* * close index * @param index (input, index to be closed) * @return void */ -void tIndexJsonClose(SIndexJson* index); +void indexJsonClose(SIndexJson* index); /* * insert terms into index @@ -152,7 +152,7 @@ void tIndexJsonClose(SIndexJson* index); * @param uid (input, uid of terms) * @return error code */ -int tIndexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid); +int indexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid); /* * search index * @param index (input, index object) @@ -161,7 +161,7 @@ int tIndexJsonPut(SIndexJson* index, SIndexJsonMultiTerm* terms, uint64_t uid); * @return error code */ -int tIndexJsonSearch(SIndexJson* index, SIndexJsonMultiTermQuery* query, SArray* result); +int indexJsonSearch(SIndexJson* index, SIndexJsonMultiTermQuery* query, SArray* result); /* * @param * @param diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 82924bef3f..c267c89384 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -28,6 +28,14 @@ extern "C" { #define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE) #define DESCRIBE_RESULT_NOTE_LEN (8 + VARSTR_HEADER_SIZE) +#define PRIVILEGE_TYPE_MASK(n) (1 << n) + +#define PRIVILEGE_TYPE_ALL PRIVILEGE_TYPE_MASK(0) +#define PRIVILEGE_TYPE_READ PRIVILEGE_TYPE_MASK(1) +#define PRIVILEGE_TYPE_WRITE PRIVILEGE_TYPE_MASK(2) + +#define PRIVILEGE_TYPE_TEST_MASK(val, mask) (((val) & (mask)) != 0) + typedef struct SDatabaseOptions { ENodeType type; int32_t buffer; @@ -316,14 +324,6 @@ typedef struct SDropFunctionStmt { bool ignoreNotExists; } SDropFunctionStmt; -#define PRIVILEGE_TYPE_MASK(n) (1 << n) - -#define PRIVILEGE_TYPE_ALL PRIVILEGE_TYPE_MASK(0) -#define PRIVILEGE_TYPE_READ PRIVILEGE_TYPE_MASK(1) -#define PRIVILEGE_TYPE_WRITE PRIVILEGE_TYPE_MASK(2) - -#define PRIVILEGE_TYPE_TEST_MASK(val, mask) (((val) & (mask)) != 0) - typedef struct SGrantStmt { ENodeType type; char userName[TSDB_USER_LEN]; @@ -333,6 +333,30 @@ typedef struct SGrantStmt { typedef SGrantStmt SRevokeStmt; +typedef struct SBalanceVgroupStmt { + ENodeType type; +} SBalanceVgroupStmt; + +typedef struct SMergeVgroupStmt { + ENodeType type; + int32_t vgId1; + int32_t vgId2; +} SMergeVgroupStmt; + +typedef struct SRedistributeVgroupStmt { + ENodeType type; + int32_t vgId; + int32_t dnodeId1; + int32_t dnodeId2; + int32_t dnodeId3; + SNodeList* pDnodes; +} SRedistributeVgroupStmt; + +typedef struct SSplitVgroupStmt { + ENodeType type; + int32_t vgId; +} SSplitVgroupStmt; + #ifdef __cplusplus } #endif diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 29fabb5418..7df731b95c 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -140,6 +140,7 @@ typedef enum ENodeType { QUERY_NODE_DROP_FUNCTION_STMT, QUERY_NODE_CREATE_STREAM_STMT, QUERY_NODE_DROP_STREAM_STMT, + QUERY_NODE_BALANCE_VGROUP_STMT, QUERY_NODE_MERGE_VGROUP_STMT, QUERY_NODE_REDISTRIBUTE_VGROUP_STMT, QUERY_NODE_SPLIT_VGROUP_STMT, @@ -195,6 +196,7 @@ typedef enum ENodeType { QUERY_NODE_LOGIC_PLAN_FILL, QUERY_NODE_LOGIC_PLAN_SORT, QUERY_NODE_LOGIC_PLAN_PARTITION, + QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC, QUERY_NODE_LOGIC_SUBPLAN, QUERY_NODE_LOGIC_PLAN, @@ -205,23 +207,24 @@ typedef enum ENodeType { QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN, QUERY_NODE_PHYSICAL_PLAN_PROJECT, - QUERY_NODE_PHYSICAL_PLAN_JOIN, - QUERY_NODE_PHYSICAL_PLAN_AGG, + QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN, + QUERY_NODE_PHYSICAL_PLAN_HASH_AGG, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE, QUERY_NODE_PHYSICAL_PLAN_MERGE, QUERY_NODE_PHYSICAL_PLAN_SORT, QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL, - QUERY_NODE_PHYSICAL_PLAN_SORT_MERGE_INTERVAL, + QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL, QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL, QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL, QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL, QUERY_NODE_PHYSICAL_PLAN_FILL, - QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW, - QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW, - QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION_WINDOW, - QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW, - QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW, + QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION, + QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION, + QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION, + QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE, + QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE, QUERY_NODE_PHYSICAL_PLAN_PARTITION, + QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC, QUERY_NODE_PHYSICAL_PLAN_DISPATCH, QUERY_NODE_PHYSICAL_PLAN_INSERT, QUERY_NODE_PHYSICAL_PLAN_DELETE, diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index 38c3f150ef..00380724b3 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -42,6 +42,7 @@ typedef struct SScanLogicNode { SNodeList* pScanPseudoCols; int8_t tableType; uint64_t tableId; + uint64_t stableId; SVgroupsInfo* pVgroupList; EScanType scanType; uint8_t scanSeq[2]; // first is scan count, and second is reverse scan count @@ -86,6 +87,11 @@ typedef struct SProjectLogicNode { int64_t soffset; } SProjectLogicNode; +typedef struct SIndefRowsFuncLogicNode { + SLogicNode node; + SNodeList* pVectorFuncs; +} SIndefRowsFuncLogicNode; + typedef enum EModifyTableType { MODIFY_TABLE_TYPE_INSERT = 1, MODIFY_TABLE_TYPE_DELETE } EModifyTableType; typedef struct SVnodeModifyLogicNode { @@ -94,7 +100,7 @@ typedef struct SVnodeModifyLogicNode { int32_t msgType; SArray* pDataBlocks; SVgDataBlocks* pVgDataBlocks; - SNode* pModifyRows; // SColumnNode + SNode* pAffectedRows; // SColumnNode uint64_t tableId; int8_t tableType; // table type char tableFName[TSDB_TABLE_FNAME_LEN]; @@ -109,6 +115,7 @@ typedef struct SExchangeLogicNode { typedef struct SMergeLogicNode { SLogicNode node; SNodeList* pMergeKeys; + SNodeList* pInputs; int32_t numOfChannels; int32_t srcGroupId; } SMergeLogicNode; @@ -117,7 +124,7 @@ typedef enum EWindowType { WINDOW_TYPE_INTERVAL = 1, WINDOW_TYPE_SESSION, WINDOW typedef enum EIntervalAlgorithm { INTERVAL_ALGO_HASH = 1, - INTERVAL_ALGO_SORT_MERGE, + INTERVAL_ALGO_MERGE, INTERVAL_ALGO_STREAM_FINAL, INTERVAL_ALGO_STREAM_SEMI, INTERVAL_ALGO_STREAM_SINGLE, @@ -220,6 +227,7 @@ typedef struct SScanPhysiNode { SNodeList* pScanCols; SNodeList* pScanPseudoCols; uint64_t uid; // unique id of the table + uint64_t suid; int8_t tableType; SName tableName; } SScanPhysiNode; @@ -264,6 +272,12 @@ typedef struct SProjectPhysiNode { int64_t soffset; } SProjectPhysiNode; +typedef struct SIndefRowsFuncPhysiNode { + SPhysiNode node; + SNodeList* pExprs; + SNodeList* pVectorFuncs; +} SIndefRowsFuncPhysiNode; + typedef struct SJoinPhysiNode { SPhysiNode node; EJoinType joinType; @@ -296,6 +310,7 @@ typedef struct SExchangePhysiNode { typedef struct SMergePhysiNode { SPhysiNode node; SNodeList* pMergeKeys; + SNodeList* pTargets; int32_t numOfChannels; int32_t srcGroupId; } SMergePhysiNode; @@ -319,7 +334,7 @@ typedef struct SIntervalPhysiNode { int8_t slidingUnit; } SIntervalPhysiNode; -typedef SIntervalPhysiNode SSortMergeIntervalPhysiNode; +typedef SIntervalPhysiNode SMergeIntervalPhysiNode; typedef SIntervalPhysiNode SStreamIntervalPhysiNode; typedef SIntervalPhysiNode SStreamFinalIntervalPhysiNode; typedef SIntervalPhysiNode SStreamSemiIntervalPhysiNode; @@ -388,6 +403,7 @@ typedef struct SDataDeleterNode { int8_t tableType; // table type char tableFName[TSDB_TABLE_FNAME_LEN]; STimeWindow deleteTimeRange; + SNode* pAffectedRows; } SDataDeleterNode; typedef struct SSubplan { diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index a17be44846..94e68ad48a 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -210,8 +210,8 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t #define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \ ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST || \ (_code) == TSDB_CODE_PAR_INVALID_COLUMNS_NUM || (_code) == TSDB_CODE_PAR_INVALID_COLUMN || \ - (_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code == TSDB_CODE_PAR_VALUE_TOO_LONG) || \ - (_code == TSDB_CODE_PAR_INVALID_DROP_COL)) + (_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code) == TSDB_CODE_PAR_VALUE_TOO_LONG || \ + (_code) == TSDB_CODE_PAR_INVALID_DROP_COL || ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID)) #define NEED_CLIENT_REFRESH_VG_ERROR(_code) \ ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID) #define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED) @@ -224,7 +224,7 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t #define NEED_SCHEDULER_RETRY_ERROR(_code) \ ((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL || (_code) == TSDB_CODE_SCH_TIMEOUT_ERROR) -#define REQUEST_MAX_TRY_TIMES 1 +#define REQUEST_TOTAL_EXEC_TIMES 2 #define qFatal(...) \ do { \ diff --git a/include/libs/qworker/qworker.h b/include/libs/qworker/qworker.h index aa20082fe0..f3f147955a 100644 --- a/include/libs/qworker/qworker.h +++ b/include/libs/qworker/qworker.h @@ -31,7 +31,12 @@ enum { NODE_TYPE_MNODE, }; - +typedef struct SDeleteRes { + uint64_t uid; + SArray* uidList; + int64_t skey; + int64_t ekey; +} SDeleteRes; typedef struct SQWorkerCfg { uint32_t maxSchedulerNum; @@ -47,6 +52,7 @@ typedef struct { uint64_t fetchProcessed; uint64_t dropProcessed; uint64_t hbProcessed; + uint64_t deleteProcessed; uint64_t numOfQueryInQueue; uint64_t numOfFetchInQueue; @@ -74,6 +80,8 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int6 int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_t ts); +int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *pRsp, SDeleteRes *pRes); + void qWorkerDestroy(void **qWorkerMgmt); int32_t qWorkerGetStat(SReadHandle *handle, void *qWorkerMgmt, SQWorkerStat *pStat); diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index f7ad7b4ed8..6b5eb3b491 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -24,8 +24,8 @@ extern "C" { #endif -#ifndef _TSTREAM_H_ -#define _TSTREAM_H_ +#ifndef _STREAM_H_ +#define _STREAM_H_ typedef struct SStreamTask SStreamTask; @@ -39,6 +39,7 @@ enum { TASK_INPUT_STATUS__NORMAL = 1, TASK_INPUT_STATUS__BLOCKED, TASK_INPUT_STATUS__RECOVER, + TASK_INPUT_STATUS__PROCESSING, TASK_INPUT_STATUS__STOP, TASK_INPUT_STATUS__FAILED, }; @@ -60,6 +61,10 @@ enum { STREAM_INPUT__CHECKPOINT, }; +typedef struct { + int8_t type; +} SStreamQueueItem; + typedef struct { int8_t type; int64_t ver; @@ -80,69 +85,60 @@ typedef struct { int8_t type; } SStreamCheckpoint; +enum { + STREAM_QUEUE__SUCESS = 1, + STREAM_QUEUE__FAILED, + STREAM_QUEUE__PROCESSING, +}; + typedef struct { STaosQueue* queue; STaosQall* qall; void* qItem; - int8_t failed; -} SStreamQ; + int8_t status; +} SStreamQueue; -static FORCE_INLINE void* streamQCurItem(SStreamQ* queue) { - // - return queue->qItem; +SStreamQueue* streamQueueOpen(); +void streamQueueClose(SStreamQueue* queue); + +static FORCE_INLINE void streamQueueProcessSuccess(SStreamQueue* queue) { + ASSERT(atomic_load_8(&queue->status) == STREAM_QUEUE__PROCESSING); + queue->qItem = NULL; + atomic_store_8(&queue->status, STREAM_QUEUE__SUCESS); } -static FORCE_INLINE void* streamQNextItem(SStreamQ* queue) { - int8_t failed = atomic_load_8(&queue->failed); - if (failed) { +static FORCE_INLINE void streamQueueProcessFail(SStreamQueue* queue) { + ASSERT(atomic_load_8(&queue->status) == STREAM_QUEUE__PROCESSING); + atomic_store_8(&queue->status, STREAM_QUEUE__FAILED); +} + +static FORCE_INLINE void* streamQueueCurItem(SStreamQueue* queue) { return queue->qItem; } + +static FORCE_INLINE void* streamQueueNextItem(SStreamQueue* queue) { + int8_t dequeueFlag = atomic_exchange_8(&queue->status, STREAM_QUEUE__PROCESSING); + if (dequeueFlag == STREAM_QUEUE__FAILED) { ASSERT(queue->qItem != NULL); - return streamQCurItem(queue); + return streamQueueCurItem(queue); } else { taosGetQitem(queue->qall, &queue->qItem); if (queue->qItem == NULL) { taosReadAllQitems(queue->queue, queue->qall); taosGetQitem(queue->qall, &queue->qItem); } - return streamQCurItem(queue); + return streamQueueCurItem(queue); } } -static FORCE_INLINE void streamQSetFail(SStreamQ* queue) { atomic_store_8(&queue->failed, 1); } +SStreamDataSubmit* streamDataSubmitNew(SSubmitReq* pReq); -static FORCE_INLINE void streamQSetSuccess(SStreamQ* queue) { atomic_store_8(&queue->failed, 0); } - -static FORCE_INLINE SStreamDataSubmit* streamDataSubmitNew(SSubmitReq* pReq) { - SStreamDataSubmit* pDataSubmit = (SStreamDataSubmit*)taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM); - if (pDataSubmit == NULL) return NULL; - pDataSubmit->dataRef = (int32_t*)taosMemoryMalloc(sizeof(int32_t)); - if (pDataSubmit->dataRef == NULL) goto FAIL; - pDataSubmit->data = pReq; - *pDataSubmit->dataRef = 1; - pDataSubmit->type = STREAM_INPUT__DATA_SUBMIT; - return pDataSubmit; -FAIL: - taosFreeQitem(pDataSubmit); - return NULL; -} - -static FORCE_INLINE void streamDataSubmitRefInc(SStreamDataSubmit* pDataSubmit) { - // - atomic_add_fetch_32(pDataSubmit->dataRef, 1); -} - -static FORCE_INLINE void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit) { - int32_t ref = atomic_sub_fetch_32(pDataSubmit->dataRef, 1); - ASSERT(ref >= 0); - if (ref == 0) { - taosMemoryFree(pDataSubmit->data); - taosMemoryFree(pDataSubmit->dataRef); - } -} +void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit); SStreamDataSubmit* streamSubmitRefClone(SStreamDataSubmit* pSubmit); +#if 0 int32_t streamDataBlockEncode(void** buf, const SStreamDataBlock* pOutput); void* streamDataBlockDecode(const void* buf, SStreamDataBlock* pInput); +#endif typedef struct { int8_t parallelizable; @@ -186,6 +182,7 @@ typedef void FSmaSink(void* vnode, int64_t smaId, const SArray* data); typedef struct { int64_t smaId; // following are not applicable to encoder and decoder + void* vnode; FSmaSink* smaSink; } STaskSinkSma; @@ -236,13 +233,17 @@ struct SStreamTask { int8_t dispatchType; int16_t dispatchMsgType; + // node info + int32_t childId; int32_t nodeId; SEpSet epSet; // exec STaskExec exec; - // local sink + // TODO: merge sink and dispatch + + // local sink union { STaskSinkTb tbSink; STaskSinkSma smaSink; @@ -259,50 +260,72 @@ struct SStreamTask { int8_t inputStatus; int8_t outputStatus; - STaosQueue* inputQ; - STaosQall* inputQAll; - STaosQueue* outputQ; - STaosQall* outputQAll; + SStreamQueue* inputQueue; + SStreamQueue* outputQueue; // application storage - void* ahandle; + // void* ahandle; }; -SStreamTask* tNewSStreamTask(int64_t streamId); +SStreamTask* tNewSStreamTask(int64_t streamId, int32_t childId); int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask); int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask); void tFreeSStreamTask(SStreamTask* pTask); -typedef struct { - // SMsgHead head; - SStreamTask* task; -} SStreamTaskDeployReq; +static FORCE_INLINE int32_t streamTaskInput(SStreamTask* pTask, SStreamQueueItem* pItem) { + while (1) { + int8_t inputStatus = + atomic_val_compare_exchange_8(&pTask->inputStatus, TASK_INPUT_STATUS__NORMAL, TASK_INPUT_STATUS__PROCESSING); + if (inputStatus == TASK_INPUT_STATUS__NORMAL) { + break; + } + ASSERT(0); + } + + if (pItem->type == STREAM_INPUT__DATA_SUBMIT) { + SStreamDataSubmit* pSubmitClone = streamSubmitRefClone((SStreamDataSubmit*)pItem); + if (pSubmitClone == NULL) { + atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED); + return -1; + } + taosWriteQitem(pTask->inputQueue->queue, pSubmitClone); + } else if (pItem->type == STREAM_INPUT__DATA_BLOCK) { + taosWriteQitem(pTask->inputQueue->queue, pItem); + } else if (pItem->type == STREAM_INPUT__CHECKPOINT) { + taosWriteQitem(pTask->inputQueue->queue, pItem); + } + + // TODO: back pressure + atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__NORMAL); + return 0; +} + +static FORCE_INLINE void streamTaskInputFail(SStreamTask* pTask) { + atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED); +} + +static FORCE_INLINE int32_t streamTaskOutput(SStreamTask* pTask, SStreamDataBlock* pBlock) { + if (pTask->sinkType == TASK_SINK__TABLE) { + ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE); + pTask->tbSink.tbSinkFunc(pTask, pTask->tbSink.vnode, 0, pBlock->blocks); + } else if (pTask->sinkType == TASK_SINK__SMA) { + ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE); + pTask->smaSink.smaSink(pTask->smaSink.vnode, pTask->smaSink.smaId, pBlock->blocks); + } else { + ASSERT(pTask->dispatchType != TASK_DISPATCH__NONE); + taosWriteQitem(pTask->outputQueue->queue, pBlock); + } + return 0; +} typedef struct { int32_t reserved; } SStreamTaskDeployRsp; typedef struct { - // SMsgHead head; - int64_t streamId; - int32_t taskId; - SArray* data; // SArray -} SStreamTaskExecReq; - -int32_t tEncodeSStreamTaskExecReq(void** buf, const SStreamTaskExecReq* pReq); -void* tDecodeSStreamTaskExecReq(const void* buf, SStreamTaskExecReq* pReq); -void tFreeSStreamTaskExecReq(SStreamTaskExecReq* pReq); - -typedef struct { - int32_t reserved; -} SStreamTaskExecRsp; - -typedef struct { - // SMsgHead head; - int64_t streamId; - int64_t version; - SArray* res; // SArray -} SStreamSinkReq; + // SMsgHead head; + SStreamTask* task; +} SStreamTaskDeployReq; typedef struct { SMsgHead head; @@ -315,10 +338,14 @@ typedef struct { int32_t taskId; int32_t sourceTaskId; int32_t sourceVg; + int32_t sourceChildId; + int32_t upstreamNodeId; #if 0 int64_t sourceVer; #endif - SArray* data; // SArray + int32_t blockNum; + SArray* dataLen; // SArray + SArray* data; // SArray } SStreamDispatchReq; typedef struct { @@ -340,9 +367,9 @@ typedef struct { int8_t inputStatus; } SStreamTaskRecoverRsp; -int32_t streamEnqueueDataSubmit(SStreamTask* pTask, SStreamDataSubmit* input); -int32_t streamEnqueueDataBlk(SStreamTask* pTask, SStreamDataBlock* input); -int32_t streamDequeueOutput(SStreamTask* pTask, void** output); +int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq); + +int32_t streamTriggerByWrite(SStreamTask* pTask, int32_t vgId, SMsgCb* pMsgCb); int32_t streamTaskRun(SStreamTask* pTask); @@ -356,4 +383,4 @@ int32_t streamProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp) } #endif -#endif /* ifndef _TSTREAM_H_ */ +#endif /* ifndef _STREAM_H_ */ diff --git a/include/libs/sync/syncTools.h b/include/libs/sync/syncTools.h index 4b160c9e61..bd396edf55 100644 --- a/include/libs/sync/syncTools.h +++ b/include/libs/sync/syncTools.h @@ -33,7 +33,7 @@ SSyncNode* syncNodeAcquire(int64_t rid); void syncNodeRelease(SSyncNode* pNode); int32_t syncGetRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg); -int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg); +int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo); void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb); char* sync2SimpleStr(int64_t rid); diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 839194da94..fd57eef83a 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -33,7 +33,10 @@ extern int32_t tsRpcHeadSize; typedef struct { uint32_t clientIp; uint16_t clientPort; - char user[TSDB_USER_LEN]; + union { + char user[TSDB_USER_LEN]; + int64_t applyIndex; + }; } SRpcConnInfo; typedef struct SRpcHandleInfo { @@ -43,6 +46,7 @@ typedef struct SRpcHandleInfo { int32_t noResp; // has response or not(default 0, 0: resp, 1: no resp); int32_t persistHandle; // persist handle or not + SRpcConnInfo connInfo; // app info void *ahandle; // app handle set by client void *wrapper; // wrapper handle diff --git a/include/util/talgo.h b/include/util/talgo.h index 3ce2652608..2ffca029bf 100644 --- a/include/util/talgo.h +++ b/include/util/talgo.h @@ -65,7 +65,7 @@ void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ * @param flags * @return */ -void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size, __compar_fn_t fn, int32_t flags); +void *taosbsearch(const void *key, const void *base, int32_t nmemb, int32_t size, __compar_fn_t compar, int32_t flags); /** * adjust heap @@ -82,7 +82,7 @@ void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size * @return */ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar, - __ext_compar_fn_t compar, char* buf, bool maxroot); + __ext_compar_fn_t compar, char *buf, bool maxroot); /** * sort heap to make sure it is a max/min root heap @@ -97,8 +97,7 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const * @param maxroot: if heap is max root heap * @return */ -void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar, - bool maxroot); +void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar, bool maxroot); #ifdef __cplusplus } diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 0b331abf8a..ae0191e6d2 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -185,7 +185,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_BNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0357) #define TSDB_CODE_MND_TOO_FEW_MNODES TAOS_DEF_ERROR_CODE(0, 0x0358) #define TSDB_CODE_MND_TOO_MANY_MNODES TAOS_DEF_ERROR_CODE(0, 0x0359) -#define TSDB_CODE_MND_CANT_DROP_MASTER TAOS_DEF_ERROR_CODE(0, 0x035A) +#define TSDB_CODE_MND_CANT_DROP_LEADER TAOS_DEF_ERROR_CODE(0, 0x035A) // mnode-acct #define TSDB_CODE_MND_ACCT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360) @@ -218,6 +218,8 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_VGROUP_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0390) #define TSDB_CODE_MND_VGROUP_NOT_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0391) #define TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0392) +#define TSDB_CODE_MND_VGROUP_UN_CHANGED TAOS_DEF_ERROR_CODE(0, 0x0393) +#define TSDB_CODE_MND_HAS_OFFLINE_DNODE TAOS_DEF_ERROR_CODE(0, 0x0394) // mnode-stable #define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A0) @@ -337,9 +339,9 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE TAOS_DEF_ERROR_CODE(0, 0x060D) #define TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x060E) #define TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP TAOS_DEF_ERROR_CODE(0, 0x060F) -#define TSDB_CODE_TDB_INVALID_ACTION TAOS_DEF_ERROR_CODE(0, 0x0600) -#define TSDB_CODE_TDB_INVALID_CREATE_TB_MSG TAOS_DEF_ERROR_CODE(0, 0x0601) -#define TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM TAOS_DEF_ERROR_CODE(0, 0x0602) +#define TSDB_CODE_TDB_INVALID_ACTION TAOS_DEF_ERROR_CODE(0, 0x0610) +#define TSDB_CODE_TDB_INVALID_CREATE_TB_MSG TAOS_DEF_ERROR_CODE(0, 0x0611) +#define TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM TAOS_DEF_ERROR_CODE(0, 0x0612) #define TSDB_CODE_TDB_FILE_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0613) #define TSDB_CODE_TDB_TABLE_RECONFIGURE TAOS_DEF_ERROR_CODE(0, 0x0614) #define TSDB_CODE_TDB_IVD_CREATE_TABLE_INFO TAOS_DEF_ERROR_CODE(0, 0x0615) @@ -651,6 +653,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_VALUE_TOO_LONG TAOS_DEF_ERROR_CODE(0, 0x2653) #define TSDB_CODE_PAR_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2654) #define TSDB_CODE_PAR_INVALID_DELETE_WHERE TAOS_DEF_ERROR_CODE(0, 0x2655) +#define TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG TAOS_DEF_ERROR_CODE(0, 0x2656) //planner #define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) diff --git a/include/util/tcompare.h b/include/util/tcompare.h index ed07ae1c9c..cc9e8ae464 100644 --- a/include/util/tcompare.h +++ b/include/util/tcompare.h @@ -105,8 +105,6 @@ int32_t compareStrPatternNotMatch(const void *pLeft, const void *pRight); int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight); int32_t compareWStrPatternNotMatch(const void *pLeft, const void *pRight); -int32_t compareJsonContainsKey(const void *pLeft, const void *pRight); - __compar_fn_t getComparFunc(int32_t type, int32_t optr); __compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order); int32_t doCompare(const char *a, const char *b, int32_t type, size_t size); diff --git a/include/util/tdef.h b/include/util/tdef.h index ebfb7b696a..1fa8ad1912 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -32,7 +32,7 @@ extern "C" { #define TD_VER_MAX UINT64_MAX // TODO: use the real max version from query handle // Bytes for each type. -extern const int32_t TYPE_BYTES[15]; +extern const int32_t TYPE_BYTES[16]; // TODO: replace and remove code below #define CHAR_BYTES sizeof(char) @@ -356,8 +356,8 @@ typedef enum ELogicConditionType { #define TSDB_DEFAULT_EXPLAIN_VERBOSE false -#define TSDB_EXPLAIN_RESULT_ROW_SIZE 1024 -#define TSDB_EXPLAIN_RESULT_COLUMN_NAME "QUERY PLAN" +#define TSDB_EXPLAIN_RESULT_ROW_SIZE 512 +#define TSDB_EXPLAIN_RESULT_COLUMN_NAME "QUERY_PLAN" #define TSDB_MAX_FIELD_LEN 16384 #define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN - TSDB_KEYSIZE) // keep 16384 diff --git a/include/util/tpagedbuf.h b/include/util/tpagedbuf.h index acaff759b7..af82e29ec5 100644 --- a/include/util/tpagedbuf.h +++ b/include/util/tpagedbuf.h @@ -188,6 +188,13 @@ SDiskbasedBufStatis getDBufStatis(const SDiskbasedBuf* pBuf); */ void dBufPrintStatis(const SDiskbasedBuf* pBuf); +/** + * Set all of page buffer are not need + * @param pBuf + * @return + */ +void clearDiskbasedBuf(SDiskbasedBuf* pBuf); + #ifdef __cplusplus } #endif diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index eaf18884c6..6aa83e9575 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -45,7 +45,7 @@ extern "C" { #define ERROR_MSG_BUF_DEFAULT_SIZE 512 #define HEARTBEAT_INTERVAL 1500 // ms -#define SYNC_ON_TOP_OF_ASYNC 0 +#define SYNC_ON_TOP_OF_ASYNC 1 enum { RES_TYPE__QUERY = 1, @@ -144,7 +144,7 @@ typedef struct STscObj { int32_t numOfReqs; // number of sqlObj bound to this connection SAppInstInfo* pAppInfo; SHashObj* pRequests; - int8_t schemalessType; + int8_t schemalessType; // todo remove it, this attribute should be move to request } STscObj; typedef struct SResultColumn { @@ -171,6 +171,7 @@ typedef struct SReqResultInfo { uint32_t current; bool completed; int32_t precision; + bool convertUcs4; int32_t payloadLen; } SReqResultInfo; @@ -212,6 +213,9 @@ typedef struct SRequestObj { SArray* tableList; SQueryExecMetric metric; SRequestSendRecvBody body; + + uint32_t prevCode; //previous error code: todo refactor, add update flag for catalog + uint32_t retry; } SRequestObj; typedef struct SSyncQueryParam { @@ -219,7 +223,7 @@ typedef struct SSyncQueryParam { SRequestObj* pRequest; } SSyncQueryParam; -void* doAsyncFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); +void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); void doSetOneRowPtr(SReqResultInfo* pResultInfo); @@ -263,8 +267,8 @@ extern SAppInfo appInfo; extern int32_t clientReqRefPool; extern int32_t clientConnRefPool; -extern int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code); -int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code); +__async_send_cb_fn_t getMsgRspHandle(int32_t msgType); + SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pReqObj); void* createTscObj(const char* user, const char* auth, const char* db, int32_t connType, SAppInstInfo* pAppInfo); @@ -274,7 +278,7 @@ int32_t releaseTscObj(int64_t rid); uint64_t generateRequestId(); -void* createRequest(STscObj* pObj, void* param, int32_t type); +void* createRequest(STscObj* pObj, int32_t type); void destroyRequest(SRequestObj* pRequest); SRequestObj* acquireRequest(int64_t rid); int32_t releaseRequest(int64_t rid); @@ -290,8 +294,6 @@ void* openTransporter(const char* user, const char* auth, int32_t numOfThreads); bool persistConnForSpecificMsg(void* parenct, tmsg_t msgType); void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet); -void initMsgHandleFp(); - TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, uint16_t port, int connType); @@ -325,6 +327,9 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNod void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery); int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest); int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList); +void doAsyncQuery(SRequestObj* pRequest, bool forceUpdateMeta); +int32_t removeMeta(STscObj* pTscObj, SArray* tbList);// todo move to clientImpl.c and become a static function +int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog);// todo move to xxx #ifdef __cplusplus } diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index be0a41ba40..171f06c257 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -177,7 +177,7 @@ STscObj *acquireTscObj(int64_t rid) { return (STscObj *)taosAcquireRef(clientCon int32_t releaseTscObj(int64_t rid) { return taosReleaseRef(clientConnRefPool, rid); } -void *createRequest(STscObj *pObj, void *param, int32_t type) { +void *createRequest(STscObj *pObj, int32_t type) { assert(pObj != NULL); SRequestObj *pRequest = (SRequestObj *)taosMemoryCalloc(1, sizeof(SRequestObj)); @@ -191,7 +191,7 @@ void *createRequest(STscObj *pObj, void *param, int32_t type) { pRequest->requestId = generateRequestId(); pRequest->metric.start = taosGetTimestampUs(); - pRequest->body.param = param; + pRequest->body.resInfo.convertUcs4 = true; // convert ucs4 by default pRequest->type = type; pRequest->pTscObj = pObj; @@ -280,7 +280,6 @@ void taos_init_imp(void) { return; } - initMsgHandleFp(); initQueryModuleMsgHandle(); rpcInit(); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 916017543d..9025121854 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -133,7 +133,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, } int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest) { - *pRequest = createRequest(pTscObj, NULL, TSDB_SQL_SELECT); + *pRequest = createRequest(pTscObj, TSDB_SQL_SELECT); if (*pRequest == NULL) { tscError("failed to malloc sqlObj"); return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -207,6 +207,7 @@ int32_t execLocalCmd(SRequestObj* pRequest, SQuery* pQuery) { if (TSDB_CODE_SUCCESS == code && NULL != pRsp) { code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false, false); } + return code; } @@ -235,6 +236,31 @@ static SAppInstInfo* getAppInfo(SRequestObj* pRequest) { return pRequest->pTscObj->pAppInfo; } +void asyncExecLocalCmd(SRequestObj* pRequest, SQuery* pQuery) { + SRetrieveTableRsp* pRsp = NULL; + + int32_t code = qExecCommand(pQuery->pRoot, &pRsp); + if (TSDB_CODE_SUCCESS == code && NULL != pRsp) { + code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false, false); + } + + SReqResultInfo* pResultInfo = &pRequest->body.resInfo; + + if (pRequest->code != TSDB_CODE_SUCCESS) { + pResultInfo->numOfRows = 0; + pRequest->code = code; + tscError("0x%" PRIx64 " fetch results failed, code:%s, reqId:0x%" PRIx64, pRequest->self, tstrerror(code), + pRequest->requestId); + } else { + tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64, + pRequest->self, pResultInfo->numOfRows, pResultInfo->totalRows, pResultInfo->completed, + pRequest->requestId); + } + + pRequest->body.queryFp(pRequest->body.param, pRequest, 0); +// pRequest->body.fetchFp(pRequest->body.param, pRequest, pResultInfo->numOfRows); +} + int32_t asyncExecDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { // drop table if exists not_exists_table if (NULL == pQuery->pCmdMsg) { @@ -431,7 +457,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList return pRequest->code; } - if (TDMT_VND_SUBMIT == pRequest->type || TDMT_VND_CREATE_TABLE == pRequest->type) { + if (TDMT_VND_SUBMIT == pRequest->type || TDMT_VND_DELETE == pRequest->type || TDMT_VND_CREATE_TABLE == pRequest->type) { pRequest->body.resInfo.numOfRows = res.numOfRows; if (pRequest->body.queryJob != 0) { @@ -509,19 +535,20 @@ int32_t handleAlterTbExecRes(void* res, SCatalog* pCatalog) { return catalogUpdateTableMeta(pCatalog, (STableMetaRsp*)res); } -int32_t handleExecRes(SRequestObj* pRequest) { +int32_t handleQueryExecRsp(SRequestObj* pRequest) { if (NULL == pRequest->body.resInfo.execRes.res) { return TSDB_CODE_SUCCESS; } - int32_t code = 0; SCatalog* pCatalog = NULL; - code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); + SAppInstInfo* pAppInfo = getAppInfo(pRequest); + + int32_t code = catalogGetHandle(pAppInfo->clusterId, &pCatalog); if (code) { return code; } - SEpSet epset = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp); + SEpSet epset = getEpSet_s(&pAppInfo->mgmtEp); SQueryExecRes* pRes = &pRequest->body.resInfo.execRes; switch (pRes->msgType) { @@ -539,8 +566,9 @@ int32_t handleExecRes(SRequestObj* pRequest) { break; } default: - tscError("invalid exec result for request type %d", pRequest->type); - return TSDB_CODE_APP_ERROR; + tscError("0x%"PRIx64", invalid exec result for request type %d, reqId:0x%"PRIx64, pRequest->self, + pRequest->type, pRequest->requestId); + code = TSDB_CODE_APP_ERROR; } return code; @@ -548,6 +576,27 @@ int32_t handleExecRes(SRequestObj* pRequest) { void schedulerExecCb(SQueryResult* pResult, void* param, int32_t code) { SRequestObj* pRequest = (SRequestObj*) param; + pRequest->code = code; + + STscObj* pTscObj = pRequest->pTscObj; + if (code != TSDB_CODE_SUCCESS && NEED_CLIENT_HANDLE_ERROR(code)) { + tscDebug("0x%"PRIx64" client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%"PRIx64, pRequest->self, code, tstrerror(code), + pRequest->retry, pRequest->requestId); + pRequest->prevCode = code; + doAsyncQuery(pRequest, true); + return; + } + + if (code == TSDB_CODE_SUCCESS) { + code = handleQueryExecRsp(pRequest); + ASSERT(pRequest->code == TSDB_CODE_SUCCESS); + pRequest->code = code; + } + + tscDebug("schedulerExecCb request type %s", TMSG_INFO(pRequest->type)); + if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) { + removeMeta(pTscObj, pRequest->tableList); + } // return to client pRequest->body.queryFp(pRequest->body.param, pRequest, code); @@ -583,7 +632,7 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue qDestroyQuery(pQuery); } - handleExecRes(pRequest); + handleQueryExecRsp(pRequest); if (NULL != pRequest && TSDB_CODE_SUCCESS != code) { pRequest->code = terrno; @@ -617,13 +666,12 @@ SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen) { } void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) { - void* pRes = NULL; - int32_t code = 0; + switch (pQuery->execMode) { case QUERY_EXEC_MODE_LOCAL: - code = execLocalCmd(pRequest, pQuery); - break; + asyncExecLocalCmd(pRequest, pQuery); + return; case QUERY_EXEC_MODE_RPC: code = asyncExecDdlQuery(pRequest, pQuery); break; @@ -649,16 +697,17 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) { if (TSDB_CODE_SUCCESS == code) { schedulerAsyncExecJob(pAppInfo->pTransporter, pNodeList, pRequest->body.pDag, &pRequest->body.queryJob, pRequest->sqlstr, pRequest->metric.start, schedulerExecCb, pRequest); - // if (NULL != pRes) { - // code = validateSversion(pRequest, pRes); - // } + } else { + pRequest->body.queryFp(pRequest->body.param, pRequest, code); } + //todo not to be released here taosArrayDestroy(pNodeList); break; } case QUERY_EXEC_MODE_EMPTY_RESULT: - pRequest->type = TSDB_SQL_RETRIEVE_EMPTY_RESULT; + pRequest->type = TSDB_SQL_RETRIEVE_EMPTY_RESULT; + pRequest->body.queryFp(pRequest->body.param, pRequest, 0); break; default: break; @@ -671,12 +720,6 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) { if (NULL != pRequest && TSDB_CODE_SUCCESS != code) { pRequest->code = terrno; } - - // if (res) { - // *res = pRes; - // } else { -// freeRequestRes(pRequest, pRes); -// pRes = NULL; } int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) { @@ -750,7 +793,7 @@ SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) { pRequest->code = code; break; } - } while (retryNum++ < REQUEST_MAX_TRY_TIMES); + } while (retryNum++ < REQUEST_TOTAL_EXEC_TIMES); if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) { removeMeta(pTscObj, pRequest->tableList); @@ -808,7 +851,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t return pTscObj; } - SRequestObj* pRequest = createRequest(pTscObj, param, TDMT_MND_CONNECT); + SRequestObj* pRequest = createRequest(pTscObj, TDMT_MND_CONNECT); if (pRequest == NULL) { destroyTscObj(pTscObj); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -850,7 +893,7 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) { pMsgSendInfo->requestObjRefId = pRequest->self; pMsgSendInfo->requestId = pRequest->requestId; - pMsgSendInfo->fp = handleRequestRspFp[TMSG_INDEX(pMsgSendInfo->msgType)]; + pMsgSendInfo->fp = getMsgRspHandle(pMsgSendInfo->msgType); pMsgSendInfo->param = pRequest; SConnectReq connectReq = {0}; @@ -1071,7 +1114,7 @@ static void syncFetchFn(void* param, TAOS_RES* res, int32_t numOfRows) { tsem_post(&pParam->sem); } -void* doAsyncFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) { +void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) { assert(pRequest != NULL); SReqResultInfo* pResultInfo = &pRequest->body.resInfo; @@ -1083,6 +1126,10 @@ void* doAsyncFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUc } SSyncQueryParam* pParam = pRequest->body.param; + + // convert ucs4 to native multi-bytes string + pResultInfo->convertUcs4 = convertUcs4; + taos_fetch_rows_a(pRequest, syncFetchFn, pParam); tsem_wait(&pParam->sem); } @@ -1242,8 +1289,7 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int int32_t length = taosUcs4ToMbs((TdUcs4*)varDataVal(jsonInnerData), varDataLen(jsonInnerData), varDataVal(dst) + CHAR_BYTES); if (length <= 0) { - tscError("charset:%s to %s. val:%s convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, - varDataVal(jsonInnerData)); + tscError("charset:%s to %s. convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset); length = 0; } varDataSetLen(dst, length + CHAR_BYTES * 2); @@ -1302,6 +1348,17 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 uint64_t groupId = *(uint64_t*)p; p += sizeof(uint64_t); + // check fields + for(int32_t i = 0; i < numOfCols; ++i) { + int16_t type = *(int16_t*) p; + p += sizeof(int16_t); + + int32_t bytes = *(int32_t*) p; + p += sizeof(int32_t); + +// ASSERT(type == pFields[i].type && bytes == pFields[i].bytes); + } + int32_t* colLength = (int32_t*)p; p += sizeof(int32_t) * numOfCols; @@ -1429,7 +1486,7 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de } code = statusRsp.statusCode; - if (details != NULL && statusRsp.details != NULL) { + if (details != NULL) { tstrncpy(details, statusRsp.details, maxlen); } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index bddc32ea20..5e442c4bf1 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -30,6 +30,7 @@ #define TSC_VAR_RELEASED 0 static int32_t sentinel = TSC_VAR_NOT_RELEASE; +static int32_t createParseContext(const SRequestObj *pRequest, SParseContext** pCxt); int taos_options(TSDB_OPTION option, const void *arg, ...) { static int32_t lock = 0; @@ -192,7 +193,7 @@ TAOS_RES *taos_query(TAOS *taos, const char *sql) { STscObj* pTscObj = (STscObj*)taos; #if SYNC_ON_TOP_OF_ASYNC - SSyncQueryParam* param = taosMemoryCalloc(1, sizeof(struct SSyncQueryParam)); + SSyncQueryParam* param = taosMemoryCalloc(1, sizeof(SSyncQueryParam)); tsem_init(¶m->sem, 0, 0); taos_query_a(pTscObj, sql, syncQueryFn, param); @@ -218,14 +219,13 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { if (TD_RES_QUERY(res)) { SRequestObj *pRequest = (SRequestObj *)res; +#if SYNC_ON_TOP_OF_ASYNC + return doAsyncFetchRows(pRequest, true, true); +#else if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { return NULL; } - -#if SYNC_ON_TOP_OF_ASYNC - return doAsyncFetchRow(pRequest, true, true); -#else return doFetchRows(pRequest, true, true); #endif @@ -488,6 +488,7 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) { if (res == NULL) { return 0; } + if (TD_RES_QUERY(res)) { SRequestObj *pRequest = (SRequestObj *)res; @@ -499,7 +500,11 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) { return 0; } - doFetchRows(pRequest, false, true); +#if SYNC_ON_TOP_OF_ASYNC + doAsyncFetchRows(pRequest, false, true); +#else + doFetchRows(pRequest, true, true); +#endif // TODO refactor SReqResultInfo *pResultInfo = &pRequest->body.resInfo; @@ -547,7 +552,11 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) { return 0; } +#if SYNC_ON_TOP_OF_ASYNC + doAsyncFetchRows(pRequest, false, false); +#else doFetchRows(pRequest, false, false); +#endif SReqResultInfo *pResultInfo = &pRequest->body.resInfo; @@ -608,36 +617,40 @@ void retrieveMetaCallback(SMetaData* pResultMeta, void* param, int32_t code) { SQuery* pQuery = pWrapper->pQuery; SRequestObj* pRequest = pWrapper->pRequest; - if (code != TSDB_CODE_SUCCESS) { - goto _error; + if (code == TSDB_CODE_SUCCESS) { + code = qAnalyseSqlSemantic(pWrapper->pCtx, &pWrapper->catalogReq, pResultMeta, pQuery); } - code = qAnalyseSqlSemantic(pWrapper->pCtx, &pWrapper->catalogReq, pResultMeta, pQuery); - if (code != TSDB_CODE_SUCCESS) { - goto _error; + if (code == TSDB_CODE_SUCCESS) { + if (pQuery->haveResultSet) { + setResSchemaInfo(&pRequest->body.resInfo, pQuery->pResSchema, pQuery->numOfResCols); + setResPrecision(&pRequest->body.resInfo, pQuery->precision); + } + + TSWAP(pRequest->dbList, (pQuery)->pDbList); + TSWAP(pRequest->tableList, (pQuery)->pTableList); + + taosMemoryFree(pWrapper); + launchAsyncQuery(pRequest, pQuery); + } else { + tscDebug("error happens, code:%d", code); + if (NEED_CLIENT_HANDLE_ERROR(code)) { + tscDebug("0x%"PRIx64" client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%"PRIx64, pRequest->self, code, tstrerror(code), + pRequest->retry, pRequest->requestId); + pRequest->prevCode = code; + doAsyncQuery(pRequest, true); + return; + } + + // return to app directly + taosMemoryFree(pWrapper); + tscError("0x%" PRIx64 " error occurs, code:%s, return to user app, reqId:0x%" PRIx64, pRequest->self, tstrerror(code), + pRequest->requestId); + pRequest->code = code; + pRequest->body.queryFp(pRequest->body.param, pRequest, code); } - - if (pQuery->haveResultSet) { - setResSchemaInfo(&pRequest->body.resInfo, pQuery->pResSchema, (pQuery)->numOfResCols); - setResPrecision(&pRequest->body.resInfo, (pQuery)->precision); - } - - TSWAP(pRequest->dbList, (pQuery)->pDbList); - TSWAP(pRequest->tableList, (pQuery)->pTableList); - - taosMemoryFree(pWrapper); - launchAsyncQuery(pRequest, pQuery); - return; - - _error: - taosMemoryFree(pWrapper); - tscError("0x%" PRIx64 " error occurs, code:%s, return to user app, reqId:%" PRIx64, pRequest->self, tstrerror(code), - pRequest->requestId); - pRequest->code = code; - pRequest->body.queryFp(pRequest->body.param, pRequest, code); } -// todo add retry before return user's callback void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) { ASSERT(fp != NULL); @@ -657,24 +670,27 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param } SRequestObj *pRequest = NULL; - int32_t retryNum = 0; - int32_t code = 0; - - // while (retryNum++ < REQUEST_MAX_TRY_TIMES) { - code = buildRequest(taos, sql, sqlLen, &pRequest); + int32_t code = buildRequest(taos, sql, sqlLen, &pRequest); if (code != TSDB_CODE_SUCCESS) { terrno = code; - fp(param, NULL, code); + fp(param, NULL, terrno); return; } pRequest->body.queryFp = fp; pRequest->body.param = param; + doAsyncQuery(pRequest, false); +} - STscObj *pTscObj = pRequest->pTscObj; +int32_t createParseContext(const SRequestObj *pRequest, SParseContext** pCxt) { + const STscObj *pTscObj = pRequest->pTscObj; - SParseContext* pCxt = taosMemoryCalloc(1, sizeof(SParseContext)); - *pCxt = (SParseContext){.requestId = pRequest->requestId, + *pCxt = taosMemoryCalloc(1, sizeof(SParseContext)); + if (*pCxt == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + **pCxt = (SParseContext){.requestId = pRequest->requestId, .acctId = pTscObj->acctId, .db = pRequest->pDb, .topicQuery = false, @@ -685,8 +701,26 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param .pTransporter = pTscObj->pAppInfo->pTransporter, .pStmtCb = NULL, .pUser = pTscObj->user, + .schemalessType = pTscObj->schemalessType, .isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)), .async = true,}; + return TSDB_CODE_SUCCESS; +} + +void doAsyncQuery(SRequestObj* pRequest, bool updateMetaForce) { + SParseContext* pCxt = NULL; + STscObj *pTscObj = pRequest->pTscObj; + int32_t code = 0; + + if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) { + code = pRequest->prevCode; + goto _error; + } + + code = createParseContext(pRequest, &pCxt); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } pCxt->mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCxt->pCatalog); @@ -694,39 +728,36 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param goto _error; } - SQuery * pQuery = NULL; - SCatalogReq catalogReq = {0}; + SQuery *pQuery = NULL; + + SCatalogReq catalogReq = {.forceUpdate = updateMetaForce}; code = qParseSqlSyntax(pCxt, &pQuery, &catalogReq); if (code != TSDB_CODE_SUCCESS) { goto _error; } SqlParseWrapper *pWrapper = taosMemoryCalloc(1, sizeof(SqlParseWrapper)); + if (pWrapper == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _error; + } + pWrapper->pCtx = pCxt; pWrapper->pQuery = pQuery; pWrapper->pRequest = pRequest; pWrapper->catalogReq = catalogReq; code = catalogAsyncGetAllMeta(pCxt->pCatalog, pCxt->pTransporter, &pCxt->mgmtEpSet, pRequest->requestId, - &catalogReq, retrieveMetaCallback, pWrapper, &pRequest->body.queryJob); - - if (code != TSDB_CODE_SUCCESS) { - goto _error; + &catalogReq, retrieveMetaCallback, pWrapper, &pRequest->body.queryJob); + if (code == TSDB_CODE_SUCCESS) { + return; } - return; - - // todo handle the retry process - - // if (TSDB_CODE_SUCCESS == code || NEED_CLIENT_HANDLE_ERROR(code)) { - // TSWAP(pRequest->dbList, (pQuery)->pDbList); - // TSWAP(pRequest->tableList, (pQuery)->pTableList); - // } - _error: + tscError("0x%"PRIx64" error happens, code:%d - %s, reqId:0x%"PRIx64, pRequest->self, code, tstrerror(code), pRequest->requestId); terrno = code; pRequest->code = code; - fp(param, pRequest, code); + pRequest->body.queryFp(pRequest->body.param, pRequest, code); } static void fetchCallback(void* pResult, void* param, int32_t code) { @@ -744,21 +775,22 @@ static void fetchCallback(void* pResult, void* param, int32_t code) { } if (pRequest->code != TSDB_CODE_SUCCESS) { - pRequest->code = code; pRequest->body.fetchFp(pRequest->body.param, pRequest, 0); + return; } - pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResultInfo->pData, true, false); + pRequest->code = setQueryResultFromRsp(pResultInfo, (SRetrieveTableRsp*)pResultInfo->pData, pResultInfo->convertUcs4, false); if (pRequest->code != TSDB_CODE_SUCCESS) { pResultInfo->numOfRows = 0; - pRequest->code = code; - pRequest->body.fetchFp(pRequest->body.param, pRequest, 0); + tscError("0x%" PRIx64 " fetch results failed, code:%s, reqId:0x%" PRIx64, pRequest->self, tstrerror(code), + pRequest->requestId); + } else { + tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64, + pRequest->self, pResultInfo->numOfRows, pResultInfo->totalRows, pResultInfo->completed, + pRequest->requestId); } - tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64, - pRequest->self, pResultInfo->numOfRows, pResultInfo->totalRows, pResultInfo->completed, pRequest->requestId); - pRequest->body.fetchFp(pRequest->body.param, pRequest, pResultInfo->numOfRows); } @@ -787,6 +819,13 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { schedulerAsyncFetchRows(pRequest->body.queryJob, fetchCallback, pRequest); } +void taos_fetch_raw_block_a(TAOS_RES* res, __taos_async_fn_t fp, void* param) { + ASSERT(res != NULL && fp != NULL); + SRequestObj *pRequest = res; + pRequest->body.resInfo.convertUcs4 = false; + taos_fetch_rows_a(res, fp, param); +} + TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char *topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) { // TODO diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 2d5199f181..14e2798d3b 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -21,8 +21,6 @@ #include "tdef.h" #include "tname.h" -int32_t (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code); - static void setErrno(SRequestObj* pRequest, int32_t code) { pRequest->code = code; terrno = code; @@ -107,10 +105,7 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pRequest) { assert(pRequest != NULL); pMsgSendInfo->msgInfo = pRequest->body.requestMsg; - - pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL) - ? genericRspCallback - : handleRequestRspFp[TMSG_INDEX(pRequest->type)]; + pMsgSendInfo->fp = getMsgRspHandle(pRequest->type); return pMsgSendInfo; } @@ -209,7 +204,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { return 0; } -int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) { +int32_t processCreateSTableRsp(void* param, const SDataBuf* pMsg, int32_t code) { assert(pMsg != NULL && param != NULL); SRequestObj* pRequest = param; @@ -219,6 +214,7 @@ int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) { } if (pRequest->body.queryFp != NULL) { + removeMeta(pRequest->pTscObj, pRequest->tableList); pRequest->body.queryFp(pRequest->body.param, pRequest, code); } else { tsem_post(&pRequest->body.rspSem); @@ -251,30 +247,54 @@ int32_t processAlterStbRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; if (code != TSDB_CODE_SUCCESS) { setErrno(pRequest, code); - tsem_post(&pRequest->body.rspSem); - return code; + } else { + SMAlterStbRsp alterRsp = {0}; + SDecoder coder = {0}; + tDecoderInit(&coder, pMsg->pData, pMsg->len); + tDecodeSMAlterStbRsp(&coder, &alterRsp); + tDecoderClear(&coder); + + pRequest->body.resInfo.execRes.msgType = TDMT_MND_ALTER_STB; + pRequest->body.resInfo.execRes.res = alterRsp.pMeta; } - SMAlterStbRsp alterRsp = {0}; - SDecoder coder = {0}; - tDecoderInit(&coder, pMsg->pData, pMsg->len); - tDecodeSMAlterStbRsp(&coder, &alterRsp); - tDecoderClear(&coder); + if (pRequest->body.queryFp != NULL) { + SQueryExecRes* pRes = &pRequest->body.resInfo.execRes; - pRequest->body.resInfo.execRes.msgType = TDMT_MND_ALTER_STB; - pRequest->body.resInfo.execRes.res = alterRsp.pMeta; + if (code == TSDB_CODE_SUCCESS) { + SCatalog* pCatalog = NULL; + int32_t ret = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); + if (pRes->res != NULL) { + ret = handleAlterTbExecRes(pRes->res, pCatalog); + } - tsem_post(&pRequest->body.rspSem); + if (ret != TSDB_CODE_SUCCESS) { + code = ret; + } + } + + pRequest->body.queryFp(pRequest->body.param, pRequest, code); + } else { + tsem_post(&pRequest->body.rspSem); + } return code; } - -// todo refactor: this arraylist is too large -void initMsgHandleFp() { - handleRequestRspFp[TMSG_INDEX(TDMT_MND_CONNECT)] = processConnectRsp; - handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = processCreateDbRsp; - handleRequestRspFp[TMSG_INDEX(TDMT_MND_USE_DB)] = processUseDbRsp; - handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = processCreateTableRsp; - handleRequestRspFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = processDropDbRsp; - handleRequestRspFp[TMSG_INDEX(TDMT_MND_ALTER_STB)] = processAlterStbRsp; +__async_send_cb_fn_t getMsgRspHandle(int32_t msgType) { + switch (msgType) { + case TDMT_MND_CONNECT: + return processConnectRsp; + case TDMT_MND_CREATE_DB: + return processCreateDbRsp; + case TDMT_MND_USE_DB: + return processUseDbRsp; + case TDMT_MND_CREATE_STB: + return processCreateSTableRsp; + case TDMT_MND_DROP_DB: + return processDropDbRsp; + case TDMT_MND_ALTER_STB: + return processAlterStbRsp; + default: + return genericRspCallback; + } } diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 93e193f0ce..d1d7325909 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -2378,7 +2378,7 @@ static int32_t isSchemalessDb(SSmlHandle* info){ */ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision) { - SRequestObj* request = (SRequestObj*)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT); + SRequestObj* request = (SRequestObj*)createRequest((STscObj *)taos, TSDB_SQL_INSERT); if(!request){ uError("SML:taos_schemaless_insert error request is null"); return NULL; diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index c2170631c2..b5011a19a2 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -195,7 +195,7 @@ typedef struct { tmq_conf_t* tmq_conf_new() { tmq_conf_t* conf = taosMemoryCalloc(1, sizeof(tmq_conf_t)); - conf->withTbName = -1; + conf->withTbName = false; conf->autoCommit = true; conf->autoCommitInterval = 5000; conf->resetOffset = TMQ_CONF__RESET_OFFSET__EARLIEAST; @@ -256,13 +256,10 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value if (strcmp(key, "msg.with.table.name") == 0) { if (strcmp(value, "true") == 0) { - conf->withTbName = 1; + conf->withTbName = true; return TMQ_CONF_OK; } else if (strcmp(value, "false") == 0) { - conf->withTbName = 0; - return TMQ_CONF_OK; - } else if (strcmp(value, "none") == 0) { - conf->withTbName = -1; + conf->withTbName = false; return TMQ_CONF_OK; } else { return TMQ_CONF_INVALID; @@ -326,7 +323,7 @@ static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) { int32_t tmqCommitCb(void* param, const SDataBuf* pMsg, int32_t code) { SMqCommitCbParam* pParam = (SMqCommitCbParam*)param; - pParam->rspErr = code == 0 ? TMQ_RESP_ERR__SUCCESS : TMQ_RESP_ERR__FAIL; + pParam->rspErr = code; if (pParam->async) { if (pParam->automatic && pParam->tmq->commitCb) { pParam->tmq->commitCb(pParam->tmq, pParam->rspErr, (tmq_topic_vgroup_list_t*)pParam->offsets, @@ -435,12 +432,13 @@ int32_t tmqCommitInner(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8_ code = pParam->rspErr; tsem_destroy(&pParam->rspSem); taosMemoryFree(pParam); + } else { + code = 0; } // avoid double free if msg is sent buf = NULL; - code = 0; END: if (buf) taosMemoryFree(buf); /*if (pParam) taosMemoryFree(pParam);*/ @@ -448,9 +446,9 @@ END: if (code != 0 && async) { if (automatic) { - tmq->commitCb(tmq, TMQ_RESP_ERR__FAIL, (tmq_topic_vgroup_list_t*)pOffsets, tmq->commitCbUserParam); + tmq->commitCb(tmq, code, (tmq_topic_vgroup_list_t*)pOffsets, tmq->commitCbUserParam); } else { - userCb(tmq, TMQ_RESP_ERR__FAIL, (tmq_topic_vgroup_list_t*)pOffsets, userParam); + userCb(tmq, code, (tmq_topic_vgroup_list_t*)pOffsets, userParam); } } @@ -496,7 +494,6 @@ int32_t tmqHandleAllDelayedTask(tmq_t* tmq) { tmqAskEp(tmq, true); taosTmrReset(tmqAssignDelayedHbTask, 1000, tmq, tmqMgmt.timer, &tmq->hbTimer); } else if (*pTaskType == TMQ_DELAYED_TASK__COMMIT) { - /*tmq_commit(tmq, NULL, true);*/ tmqCommitInner(tmq, NULL, 1, 1, tmq->commitCb, tmq->commitCbUserParam); taosTmrReset(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, tmq, tmqMgmt.timer, &tmq->commitTimer); } else if (*pTaskType == TMQ_DELAYED_TASK__REPORT) { @@ -669,94 +666,6 @@ FAIL: tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int32_t async) { return tmqCommitInner(tmq, offsets, 0, async, tmq->commitCb, tmq->commitCbUserParam); -#if 0 - // TODO: add read write lock - SRequestObj* pRequest = NULL; - tmq_resp_err_t resp = TMQ_RESP_ERR__SUCCESS; - // build msg - // send to mnode - SMqCMCommitOffsetReq req; - SArray* pOffsets = NULL; - - if (offsets == NULL) { - pOffsets = taosArrayInit(0, sizeof(SMqOffset)); - for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) { - SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i); - for (int j = 0; j < taosArrayGetSize(pTopic->vgs); j++) { - SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j); - SMqOffset offset; - strcpy(offset.topicName, pTopic->topicName); - strcpy(offset.cgroup, tmq->groupId); - offset.vgId = pVg->vgId; - offset.offset = pVg->currentOffset; - taosArrayPush(pOffsets, &offset); - } - } - req.num = pOffsets->size; - req.offsets = pOffsets->pData; - } else { - req.num = taosArrayGetSize(&offsets->container); - req.offsets = (SMqOffset*)offsets->container.pData; - } - - SEncoder encoder; - - tEncoderInit(&encoder, NULL, 0); - tEncodeSMqCMCommitOffsetReq(&encoder, &req); - int32_t tlen = encoder.pos; - void* buf = taosMemoryMalloc(tlen); - if (buf == NULL) { - tEncoderClear(&encoder); - return -1; - } - tEncoderClear(&encoder); - - tEncoderInit(&encoder, buf, tlen); - tEncodeSMqCMCommitOffsetReq(&encoder, &req); - tEncoderClear(&encoder); - - pRequest = createRequest(tmq->pTscObj, NULL, NULL, TDMT_MND_MQ_COMMIT_OFFSET); - if (pRequest == NULL) { - tscError("failed to malloc request"); - } - - SMqCommitCbParam* pParam = taosMemoryCalloc(1, sizeof(SMqCommitCbParam)); - if (pParam == NULL) { - return -1; - } - pParam->tmq = tmq; - tsem_init(&pParam->rspSem, 0, 0); - pParam->async = async; - pParam->offsets = pOffsets; - - pRequest->body.requestMsg = (SDataBuf){ - .pData = buf, - .len = tlen, - .handle = NULL, - }; - - SMsgSendInfo* sendInfo = buildMsgInfoImpl(pRequest); - sendInfo->requestObjRefId = 0; - sendInfo->param = pParam; - sendInfo->fp = tmqCommitCb; - SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp); - - int64_t transporterId = 0; - asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo); - - if (!async) { - tsem_wait(&pParam->rspSem); - resp = pParam->rspErr; - tsem_destroy(&pParam->rspSem); - taosMemoryFree(pParam); - - if (pOffsets) { - taosArrayDestroy(pOffsets); - } - } - - return resp; -#endif } tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { @@ -861,93 +770,6 @@ void tmq_conf_set_auto_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb, void* para conf->commitCbUserParam = param; } -#if 0 -TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbName, const char* sql) { - STscObj* pTscObj = (STscObj*)taos; - SRequestObj* pRequest = NULL; - SQuery* pQueryNode = NULL; - char* astStr = NULL; - int32_t sqlLen; - - terrno = TSDB_CODE_SUCCESS; - if (taos == NULL || streamName == NULL || sql == NULL) { - tscError("invalid parameters for creating stream, connObj:%p, stream name:%s, sql:%s", taos, streamName, sql); - terrno = TSDB_CODE_TSC_INVALID_INPUT; - goto _return; - } - sqlLen = strlen(sql); - - if (strlen(tbName) >= TSDB_TABLE_NAME_LEN) { - tscError("output tb name too long, max length:%d", TSDB_TABLE_NAME_LEN - 1); - terrno = TSDB_CODE_TSC_INVALID_INPUT; - goto _return; - } - - if (sqlLen > TSDB_MAX_ALLOWED_SQL_LEN) { - tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN); - terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; - goto _return; - } - - tscDebug("start to create stream: %s", streamName); - - int32_t code = 0; - CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return); - CHECK_CODE_GOTO(parseSql(pRequest, false, &pQueryNode, NULL), _return); - CHECK_CODE_GOTO(nodesNodeToString(pQueryNode->pRoot, false, &astStr, NULL), _return); - - /*printf("%s\n", pStr);*/ - - SName name = {.acctId = pTscObj->acctId, .type = TSDB_TABLE_NAME_T}; - strcpy(name.dbname, pRequest->pDb); - strcpy(name.tname, streamName); - - SCMCreateStreamReq req = { - .igExists = 1, - .ast = astStr, - .sql = (char*)sql, - }; - tNameExtractFullName(&name, req.name); - strcpy(req.targetStbFullName, tbName); - - int tlen = tSerializeSCMCreateStreamReq(NULL, 0, &req); - void* buf = taosMemoryMalloc(tlen); - if (buf == NULL) { - goto _return; - } - - tSerializeSCMCreateStreamReq(buf, tlen, &req); - - pRequest->body.requestMsg = (SDataBuf){ - .pData = buf, - .len = tlen, - .handle = NULL, - }; - pRequest->type = TDMT_MND_CREATE_STREAM; - - SMsgSendInfo* sendInfo = buildMsgInfoImpl(pRequest); - SEpSet epSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); - - int64_t transporterId = 0; - asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo); - - tsem_wait(&pRequest->body.rspSem); - -_return: - taosMemoryFreeClear(astStr); - qDestroyQuery(pQueryNode); - /*if (sendInfo != NULL) {*/ - /*destroySendMsgInfo(sendInfo);*/ - /*}*/ - - if (pRequest != NULL && terrno != TSDB_CODE_SUCCESS) { - pRequest->code = terrno; - } - - return pRequest; -} -#endif - #if 0 int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) { if (tmq_message == NULL) return 0; @@ -1477,16 +1299,16 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) { tmq_resp_err_t tmq_consumer_close(tmq_t* tmq) { if (tmq->status == TMQ_CONSUMER_STATUS__READY) { tmq_resp_err_t rsp = tmq_commit_sync(tmq, NULL); - if (rsp == TMQ_RESP_ERR__FAIL) { - return TMQ_RESP_ERR__FAIL; + if (rsp != TMQ_RESP_ERR__SUCCESS) { + return rsp; } tmq_list_t* lst = tmq_list_new(); rsp = tmq_subscribe(tmq, lst); tmq_list_destroy(lst); - if (rsp == TMQ_RESP_ERR__FAIL) { - return TMQ_RESP_ERR__FAIL; + if (rsp != TMQ_RESP_ERR__SUCCESS) { + return rsp; } } // TODO: free resources @@ -1496,8 +1318,11 @@ tmq_resp_err_t tmq_consumer_close(tmq_t* tmq) { const char* tmq_err2str(tmq_resp_err_t err) { if (err == TMQ_RESP_ERR__SUCCESS) { return "success"; + } else if (err == TMQ_RESP_ERR__FAIL) { + return "fail"; + } else { + return tstrerror(err); } - return "fail"; } const char* tmq_get_topic_name(TAOS_RES* res) { @@ -1539,10 +1364,11 @@ const char* tmq_get_table_name(TAOS_RES* res) { } return NULL; } -DLL_EXPORT void tmq_commit_async(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, tmq_commit_cb* cb, void* param) { + +void tmq_commit_async(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, tmq_commit_cb* cb, void* param) { tmqCommitInner(tmq, offsets, 0, 1, cb, param); } -DLL_EXPORT tmq_resp_err_t tmq_commit_sync(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets) { +tmq_resp_err_t tmq_commit_sync(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets) { return tmqCommitInner(tmq, offsets, 0, 0, NULL, NULL); } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index a0f33627c4..f9825c50ff 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -778,7 +778,32 @@ TEST(testCase, async_api_test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); - taos_query_a(pConn, "drop table test.tm0", queryCallback, pConn); + taos_query(pConn, "use test"); + + TAOS_RES* pRes = taos_query(pConn, "desc abc1.tu"); + if (taos_errno(pRes) != 0) { + printf("failed, reason:%s\n", taos_errstr(pRes)); + } + + int32_t n = 0; + 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* length = taos_fetch_lengths(pRes); + for(int32_t i = 0; i < numOfFields; ++i) { + printf("(%d):%d " , i, length[i]); + } + printf("\n"); + + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + memset(str, 0, sizeof(str)); + } + + taos_query_a(pConn, "alter table test.m1 comment 'abcde' ", queryCallback, pConn); getchar(); taos_close(pConn); } diff --git a/source/client/test/smlTest.cpp b/source/client/test/smlTest.cpp index 8ec411fbff..8137583978 100644 --- a/source/client/test/smlTest.cpp +++ b/source/client/test/smlTest.cpp @@ -486,7 +486,7 @@ TEST(testCase, smlProcess_influx_Test) { pRes = taos_query(taos, "use inflx_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -607,7 +607,7 @@ TEST(testCase, smlParseLine_error_Test) { pRes = taos_query(taos, "use sml_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -656,7 +656,7 @@ TEST(testCase, smlProcess_telnet_Test) { pRes = taos_query(taos, "use telnet_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -710,7 +710,7 @@ TEST(testCase, smlProcess_json1_Test) { pRes = taos_query(taos, "use json_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -779,7 +779,7 @@ TEST(testCase, smlProcess_json2_Test) { pRes = taos_query(taos, "use sml_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -823,7 +823,7 @@ TEST(testCase, smlProcess_json3_Test) { pRes = taos_query(taos, "use sml_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -895,7 +895,7 @@ TEST(testCase, smlProcess_json4_Test) { pRes = taos_query(taos, "use sml_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -957,7 +957,7 @@ TEST(testCase, smlParseTelnetLine_error_Test) { pRes = taos_query(taos, "use sml_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -1006,7 +1006,7 @@ TEST(testCase, smlParseTelnetLine_diff_type_Test) { pRes = taos_query(taos, "use sml_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -1033,7 +1033,7 @@ TEST(testCase, smlParseTelnetLine_json_error_Test) { pRes = taos_query(taos, "use sml_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -1101,7 +1101,7 @@ TEST(testCase, smlParseTelnetLine_diff_json_type1_Test) { pRes = taos_query(taos, "use sml_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -1146,7 +1146,7 @@ TEST(testCase, smlParseTelnetLine_diff_json_type2_Test) { pRes = taos_query(taos, "use sml_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -1191,7 +1191,7 @@ TEST(testCase, sml_TD15662_Test) { pRes = taos_query(taos, "use db_15662"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS); @@ -1218,7 +1218,7 @@ TEST(testCase, sml_TD15735_Test) { pRes = taos_query(taos, "use sml_db"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); @@ -1244,7 +1244,7 @@ TEST(testCase, sml_TD15742_Test) { pRes = taos_query(taos, "use TD15742"); taos_free_result(pRes); - SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT); ASSERT_NE(request, nullptr); SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS); diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index c615af705a..4ebedc98c1 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -18,6 +18,7 @@ #include "tcompare.h" #include "tglobal.h" #include "tlog.h" +#include "tname.h" int32_t taosGetFqdnPortFromEp(const char* ep, SEp* pEp) { pEp->port = 0; @@ -99,7 +100,7 @@ void colDataTrim(SColumnInfoData* pColumnInfoData) { // TODO } -int32_t getJsonValueLen(const char *data) { +int32_t getJsonValueLen(const char* data) { int32_t dataLen = 0; if (*data == TSDB_DATA_TYPE_NULL) { dataLen = CHAR_BYTES; @@ -109,7 +110,7 @@ int32_t getJsonValueLen(const char *data) { dataLen = DOUBLE_BYTES + CHAR_BYTES; } else if (*data == TSDB_DATA_TYPE_BOOL) { dataLen = CHAR_BYTES + CHAR_BYTES; - } else if (*data & TD_TAG_JSON) { // json string + } else if (*data & TD_TAG_JSON) { // json string dataLen = ((STag*)(data))->len; } else { ASSERT(0); @@ -137,7 +138,7 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con int32_t dataLen = 0; if (type == TSDB_DATA_TYPE_JSON) { dataLen = getJsonValueLen(pData); - }else { + } else { dataLen = varDataTLen(pData); } @@ -681,9 +682,10 @@ size_t blockDataGetRowSize(SSDataBlock* pBlock) { * @param pBlock * @return */ -size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) { - // | total rows/total length | block group id | each column length | - return sizeof(int32_t) + sizeof(uint64_t) + pBlock->info.numOfCols * sizeof(int32_t); +size_t blockDataGetSerialMetaSize(uint32_t numOfCols) { + // | total rows/total length | block group id | column schema | each column length | + return sizeof(int32_t) + sizeof(uint64_t) + numOfCols * (sizeof(int16_t) + sizeof(int32_t)) + + numOfCols * sizeof(int32_t); } double blockDataGetSerialRowSize(const SSDataBlock* pBlock) { @@ -1130,6 +1132,7 @@ int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, size_t existRows, ui if (IS_VAR_DATA_TYPE(pColumn->info.type)) { char* tmp = taosMemoryRealloc(pColumn->varmeta.offset, sizeof(int32_t) * numOfRows); + if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1155,6 +1158,7 @@ int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, size_t existRows, ui if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } + memset(tmp + pColumn->info.bytes * existRows, 0, pColumn->info.bytes * (numOfRows - existRows)); pColumn->pData = tmp; } @@ -1213,7 +1217,8 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData) { pBlock->info.numOfCols = numOfCols; pBlock->info.hasVarCol = pDataBlock->info.hasVarCol; - pBlock->info.rowSize = pDataBlock->info.rows; + pBlock->info.rowSize = pDataBlock->info.rowSize; + pBlock->info.groupId = pDataBlock->info.groupId; for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData colInfo = {0}; @@ -1243,7 +1248,7 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData) { } size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize) { - int32_t payloadSize = pageSize - blockDataGetSerialMetaSize(pBlock); + int32_t payloadSize = pageSize - blockDataGetSerialMetaSize(pBlock->info.numOfCols); int32_t rowSize = pBlock->info.rowSize; @@ -1268,12 +1273,12 @@ size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize) { void colDataDestroy(SColumnInfoData* pColData) { if (IS_VAR_DATA_TYPE(pColData->info.type)) { - taosMemoryFree(pColData->varmeta.offset); + taosMemoryFreeClear(pColData->varmeta.offset); } else { - taosMemoryFree(pColData->nullbitmap); + taosMemoryFreeClear(pColData->nullbitmap); } - taosMemoryFree(pColData->pData); + taosMemoryFreeClear(pColData->pData); } static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) { @@ -1283,7 +1288,7 @@ static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) { if (n % 8 == 0) { memmove(nullBitmap, nullBitmap + n / 8, newLen); } else { - int32_t tail = n % 8; + int32_t tail = n % 8; int32_t i = 0; uint8_t* p = (uint8_t*)nullBitmap; @@ -1301,7 +1306,7 @@ static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) { } } else if (n > 8) { int32_t gap = len - newLen; - while(i < newLen) { + while (i < newLen) { uint8_t v = p[i + gap]; p[i] = (v << tail); @@ -1316,7 +1321,6 @@ static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) { } } - static void colDataTrimFirstNRows(SColumnInfoData* pColInfoData, size_t n, size_t total) { if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { memmove(pColInfoData->varmeta.offset, &pColInfoData->varmeta.offset[n], (total - n) * sizeof(int32_t)); @@ -1500,7 +1504,7 @@ void blockDebugShowData(const SArray* dataBlocks, const char* flag) { for (int32_t k = 0; k < colNum; k++) { SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k); void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); - if (pColInfoData->hasNull) { + if (colDataIsNull(pColInfoData, rows, j, NULL)) { printf(" %15s |", "NULL"); continue; } @@ -1544,7 +1548,8 @@ void blockDebugShowData(const SArray* dataBlocks, const char* flag) { * * TODO: colId should be set */ -int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks, STSchema* pTSchema, int32_t vgId, tb_uid_t suid) { +int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks, STSchema* pTSchema, int32_t vgId, + tb_uid_t suid) { int32_t sz = taosArrayGetSize(pDataBlocks); int32_t bufSize = sizeof(SSubmitReq); for (int32_t i = 0; i < sz; ++i) { @@ -1585,13 +1590,12 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks int32_t dataLen = 0; for (int32_t j = 0; j < rows; ++j) { // iterate by row tdSRowResetBuf(&rb, POINTER_SHIFT(pDataBuf, msgLen)); // set row buf - bool isStartKey = false; + bool isStartKey = false; int32_t offset = 0; for (int32_t k = 0; k < colNum; ++k) { // iterate by column SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k); - STColumn* pCol = &pTSchema->columns[k]; - ASSERT(pCol->type == pColInfoData->info.type); - void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); + STColumn* pCol = &pTSchema->columns[k]; + void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); switch (pColInfoData->info.type) { case TSDB_DATA_TYPE_TIMESTAMP: if (!isStartKey) { @@ -1600,34 +1604,56 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks offset, k); } else { - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var, true, offset, k); + tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var, + true, offset, k); } break; case TSDB_DATA_TYPE_NCHAR: { - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_NCHAR, TD_VTYPE_NORM, var, true, offset, k); + tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_NCHAR, TD_VTYPE_NORM, var, true, + offset, k); break; } case TSDB_DATA_TYPE_VARCHAR: { // TSDB_DATA_TYPE_BINARY - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_VARCHAR, TD_VTYPE_NORM, var, true, offset, k); + tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_VARCHAR, TD_VTYPE_NORM, var, true, + offset, k); break; } case TSDB_DATA_TYPE_VARBINARY: case TSDB_DATA_TYPE_DECIMAL: case TSDB_DATA_TYPE_BLOB: + case TSDB_DATA_TYPE_JSON: case TSDB_DATA_TYPE_MEDIUMBLOB: uError("the column type %" PRIi16 " is defined but not implemented yet", pColInfoData->info.type); TASSERT(0); break; default: if (pColInfoData->info.type < TSDB_DATA_TYPE_MAX && pColInfoData->info.type > TSDB_DATA_TYPE_NULL) { - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pColInfoData->info.type, TD_VTYPE_NORM, var, true, offset, k); + char tv[8] = {0}; + if (pColInfoData->info.type == TSDB_DATA_TYPE_FLOAT) { + float v = 0; + GET_TYPED_DATA(v, float, pColInfoData->info.type, var); + SET_TYPED_DATA(&tv, pCol->type, v); + } else if (pColInfoData->info.type == TSDB_DATA_TYPE_DOUBLE) { + double v = 0; + GET_TYPED_DATA(v, double, pColInfoData->info.type, var); + SET_TYPED_DATA(&tv, pCol->type, v); + } else if (IS_SIGNED_NUMERIC_TYPE(pColInfoData->info.type)) { + int64_t v = 0; + GET_TYPED_DATA(v, int64_t, pColInfoData->info.type, var); + SET_TYPED_DATA(&tv, pCol->type, v); + } else { + uint64_t v = 0; + GET_TYPED_DATA(v, uint64_t, pColInfoData->info.type, var); + SET_TYPED_DATA(&tv, pCol->type, v); + } + tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, tv, true, offset, k); } else { uError("the column type %" PRIi16 " is undefined\n", pColInfoData->info.type); TASSERT(0); } break; } - offset += TYPE_BYTES[pColInfoData->info.type]; + offset += TYPE_BYTES[pCol->type]; // sum/avg would convert to int64_t/uint64_t/double during aggregation } dataLen += TD_ROW_LEN(rb.pBuf); #ifdef TD_DEBUG_PRINT_ROW @@ -1663,11 +1689,38 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks return TSDB_CODE_SUCCESS; } +char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId) { + SArray* tags = taosArrayInit(0, sizeof(void*)); + SSmlKv* pTag = taosMemoryCalloc(1, sizeof(SSmlKv)); + pTag->key = "group_id"; + pTag->keyLen = strlen(pTag->key); + pTag->type = TSDB_DATA_TYPE_UBIGINT; + pTag->u = groupId; + taosArrayPush(tags, &pTag); + + void* cname = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1); + + RandTableName rname = { + .tags = tags, + .sTableName = stbName, + .sTableNameLen = strlen(stbName), + .childTableName = cname, + }; + + buildChildTableName(&rname); + + taosMemoryFree(pTag); + taosArrayDestroy(tags); + + ASSERT(rname.childTableName && rname.childTableName[0]); + return rname.childTableName; +} + SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, bool createTb, int64_t suid, const char* stbFullName, int32_t vgId) { SSubmitReq* ret = NULL; SArray* tagArray = taosArrayInit(1, sizeof(STagVal)); - if(!tagArray) { + if (!tagArray) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -1685,15 +1738,12 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo if (createTb) { SVCreateTbReq createTbReq = {0}; - char* cname = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN); - snprintf(cname, TSDB_TABLE_FNAME_LEN, "%s:%ld", stbFullName, pDataBlock->info.groupId); + char* cname = buildCtbNameByGroupId(stbFullName, pDataBlock->info.groupId); createTbReq.name = cname; createTbReq.flags = 0; createTbReq.type = TSDB_CHILD_TABLE; createTbReq.ctb.suid = suid; - - STagVal tagVal = {.cid = 1, .type = TSDB_DATA_TYPE_UBIGINT, .pData = (uint8_t*)&pDataBlock->info.groupId, @@ -1831,39 +1881,50 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo } ret->length = htonl(ret->length); - taosArrayDestroy(tagArray); + taosArrayDestroy(tagArray); return ret; } -void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, int8_t needCompress) { +void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, + int8_t needCompress) { + // todo extract method int32_t* actualLen = (int32_t*)data; data += sizeof(int32_t); uint64_t* groupId = (uint64_t*)data; data += sizeof(uint64_t); + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); + *((int16_t*)data) = pColInfoData->info.type; + data += sizeof(int16_t); + + *((int32_t*)data) = pColInfoData->info.bytes; + data += sizeof(int32_t); + } + int32_t* colSizes = (int32_t*)data; data += numOfCols * sizeof(int32_t); - *dataLen = (numOfCols * sizeof(int32_t) + sizeof(uint64_t) + sizeof(int32_t)); + *dataLen = blockDataGetSerialMetaSize(numOfCols); int32_t numOfRows = pBlock->info.rows; for (int32_t col = 0; col < numOfCols; ++col) { SColumnInfoData* pColRes = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, col); // copy the null bitmap + size_t metaSize = 0; if (IS_VAR_DATA_TYPE(pColRes->info.type)) { - size_t metaSize = numOfRows * sizeof(int32_t); + metaSize = numOfRows * sizeof(int32_t); memcpy(data, pColRes->varmeta.offset, metaSize); - data += metaSize; - (*dataLen) += metaSize; } else { - int32_t len = BitmapLen(numOfRows); - memcpy(data, pColRes->nullbitmap, len); - data += len; - (*dataLen) += len; + metaSize = BitmapLen(numOfRows); + memcpy(data, pColRes->nullbitmap, metaSize); } + data += metaSize; + (*dataLen) += metaSize; + if (needCompress) { colSizes[col] = blockCompressColData(pColRes, numOfRows, data, needCompress); data += colSizes[col]; @@ -1884,6 +1945,8 @@ void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t numOfRows, const char* pData) { blockDataEnsureCapacity(pBlock, numOfRows); + pBlock->info.rows = numOfRows; + const char* pStart = pData; int32_t dataLen = *(int32_t*)pStart; @@ -1892,6 +1955,29 @@ const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t pBlock->info.groupId = *(uint64_t*)pStart; pStart += sizeof(uint64_t); + if (pBlock->pDataBlock == NULL) { + pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); + taosArraySetSize(pBlock->pDataBlock, numOfCols); + } + + pBlock->info.numOfCols = taosArrayGetSize(pBlock->pDataBlock); + ASSERT(pBlock->pDataBlock->size >= numOfCols); + + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); + pColInfoData->info.type = *(int16_t*)pStart; + pStart += sizeof(int16_t); + + pColInfoData->info.bytes = *(int32_t*)pStart; + pStart += sizeof(int32_t); + + if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { + pBlock->info.hasVarCol = true; + } + } + + blockDataEnsureCapacity(pBlock, numOfRows); + int32_t* colLen = (int32_t*)pStart; pStart += sizeof(int32_t) * numOfCols; @@ -1912,11 +1998,17 @@ const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t pColInfoData->pData = taosMemoryMalloc(colLen[i]); } } else { + if (pColInfoData->nullbitmap == NULL) { + pColInfoData->nullbitmap = taosMemoryCalloc(1, BitmapLen(numOfRows)); + } memcpy(pColInfoData->nullbitmap, pStart, BitmapLen(numOfRows)); pStart += BitmapLen(numOfRows); } if (colLen[i] > 0) { + if (pColInfoData->pData == NULL) { + pColInfoData->pData = taosMemoryCalloc(1, colLen[i]); + } memcpy(pColInfoData->pData, pStart, colLen[i]); } @@ -1929,4 +2021,4 @@ const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t ASSERT(pStart - pData == dataLen); return pStart; -} \ No newline at end of file +} diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 9aa94b0216..84a2cf0544 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -208,7 +208,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S if (iColumn == 0) { ASSERT(pColVal->cid == pTColumn->colId); ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP); - ASSERT(pTColumn->colId == 0); + ASSERT(pTColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID); iColVal++; } else { @@ -244,7 +244,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S } } - ASSERT(flags); + // ASSERT(flags); // only 1 column(ts) // decide uint32_t nData = 0; @@ -268,7 +268,8 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S nDataT = BIT2_SIZE(pTSchema->numOfCols - 1) + pTSchema->flen + ntv; break; default: - ASSERT(0); + break; // only ts column + // ASSERT(0); } uint8_t tflags = 0; @@ -283,7 +284,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S tflags |= TSROW_KV_BIG; } - if (nDataT < nDataK) { + if (nDataT <= nDataK) { nData = nDataT; } else { nData = nDataK; @@ -352,7 +353,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S ntv = 0; iColVal = 1; - if (flags & 0xf0 == 0) { + if ((flags & 0xf0) == 0) { switch (flags & 0xf) { case TSROW_HAS_VAL: pf = (*ppRow)->pData; @@ -373,7 +374,8 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S ptv = pf + pTSchema->flen; break; default: - ASSERT(0); + // ASSERT(0); + break; } } else { pTSKVRow = (STSKVRow *)(*ppRow)->pData; @@ -417,13 +419,13 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S } _set_none: - if (flags & 0xf0 == 0) { + if ((flags & 0xf0) == 0) { setBitMap(pb, 0, iColumn - 1, flags); } continue; _set_null: - if (flags & 0xf0 == 0) { + if ((flags & 0xf0) == 0) { setBitMap(pb, 1, iColumn - 1, flags); } else { SET_IDX(pidx, pTSKVRow->nCols, nkv, flags); @@ -433,7 +435,7 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S continue; _set_value: - if (flags & 0xf0 == 0) { + if ((flags & 0xf0) == 0) { setBitMap(pb, 2, iColumn - 1, flags); if (IS_VAR_DATA_TYPE(pTColumn->type)) { @@ -489,13 +491,13 @@ void tTSRowFree(STSRow2 *pRow) { } void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) { - uint8_t isTuple = (pRow->flags & 0xf0 == 0) ? 1 : 0; + uint8_t isTuple = ((pRow->flags & 0xf0) == 0) ? 1 : 0; STColumn *pTColumn = &pTSchema->columns[iCol]; uint8_t flags = pRow->flags & (uint8_t)0xf; SValue value; ASSERT(iCol < pTSchema->numOfCols); - ASSERT(flags); + // ASSERT(flags); // only 1 ts column ASSERT(pRow->sver == pTSchema->version); if (iCol == 0) { @@ -505,7 +507,7 @@ void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal if (flags == TSROW_HAS_NONE) { goto _return_none; - } else if (flags == TSROW_HAS_NONE) { + } else if (flags == TSROW_HAS_NULL) { goto _return_null; } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index e77c462e5a..91b740fc96 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -332,7 +332,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { if (cfgAddBool(pCfg, "keepColumnName", tsKeepOriginalColumnName, 1) != 0) return -1; if (cfgAddInt32(pCfg, "queryPolicy", tsQueryPolicy, 1, 3, 1) != 0) return -1; if (cfgAddString(pCfg, "smlChildTableName", "", 1) != 0) return -1; - if (cfgAddString(pCfg, "smlTagNullName", tsSmlTagName, 1) != 0) return -1; + if (cfgAddString(pCfg, "smlTagName", tsSmlTagName, 1) != 0) return -1; if (cfgAddBool(pCfg, "smlDataFormat", tsSmlDataFormat, 1) != 0) return -1; tsNumOfTaskQueueThreads = tsNumOfCores / 4; @@ -532,7 +532,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { } tstrncpy(tsSmlChildTableName, cfgGetItem(pCfg, "smlChildTableName")->str, TSDB_TABLE_NAME_LEN); - tstrncpy(tsSmlTagName, cfgGetItem(pCfg, "smlTagNullName")->str, TSDB_COL_NAME_LEN); + tstrncpy(tsSmlTagName, cfgGetItem(pCfg, "smlTagName")->str, TSDB_COL_NAME_LEN); tsSmlDataFormat = cfgGetItem(pCfg, "smlDataFormat")->bval; tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->i32; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 7041c9478e..b9b4556255 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -932,6 +932,7 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { if (tEncodeI64(&encoder, pReq->qload.numOfProcessedFetch) < 0) return -1; if (tEncodeI64(&encoder, pReq->qload.numOfProcessedDrop) < 0) return -1; if (tEncodeI64(&encoder, pReq->qload.numOfProcessedHb) < 0) return -1; + if (tEncodeI64(&encoder, pReq->qload.numOfProcessedDelete) < 0) return -1; if (tEncodeI64(&encoder, pReq->qload.cacheDataSize) < 0) return -1; if (tEncodeI64(&encoder, pReq->qload.numOfQueryInQueue) < 0) return -1; if (tEncodeI64(&encoder, pReq->qload.numOfFetchInQueue) < 0) return -1; @@ -1001,6 +1002,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedFetch) < 0) return -1; if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedDrop) < 0) return -1; if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedHb) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedDelete) < 0) return -1; if (tDecodeI64(&decoder, &pReq->qload.cacheDataSize) < 0) return -1; if (tDecodeI64(&decoder, &pReq->qload.numOfQueryInQueue) < 0) return -1; if (tDecodeI64(&decoder, &pReq->qload.numOfFetchInQueue) < 0) return -1; @@ -2392,6 +2394,104 @@ int32_t tDeserializeSUserIndexRsp(void *buf, int32_t bufLen, SUserIndexRsp *pRsp return 0; } +int32_t tSerializeSTableIndexReq(void *buf, int32_t bufLen, STableIndexReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->tbFName) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSTableIndexReq(void *buf, int32_t bufLen, STableIndexReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->tbFName) < 0) return -1; + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + +int32_t tSerializeSTableIndexInfo(SEncoder *pEncoder, STableIndexInfo* pInfo) { + if (tEncodeI8(pEncoder, pInfo->intervalUnit) < 0) return -1; + if (tEncodeI8(pEncoder, pInfo->slidingUnit) < 0) return -1; + if (tEncodeI64(pEncoder, pInfo->interval) < 0) return -1; + if (tEncodeI64(pEncoder, pInfo->offset) < 0) return -1; + if (tEncodeI64(pEncoder, pInfo->sliding) < 0) return -1; + if (tEncodeI64(pEncoder, pInfo->dstTbUid) < 0) return -1; + if (tEncodeI32(pEncoder, pInfo->dstVgId) < 0) return -1; + if (tEncodeSEpSet(pEncoder, &pInfo->epSet) < 0) return -1; + if (tEncodeCStr(pEncoder, pInfo->expr) < 0) return -1; + return 0; +} + +int32_t tSerializeSTableIndexRsp(void *buf, int32_t bufLen, const STableIndexRsp *pRsp) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + int32_t num = taosArrayGetSize(pRsp->pIndex); + if (tEncodeI32(&encoder, num) < 0) return -1; + if (num > 0) { + for (int32_t i = 0; i < num; ++i) { + STableIndexInfo* pInfo = (STableIndexInfo*)taosArrayGet(pRsp->pIndex, i); + if (tSerializeSTableIndexInfo(&encoder, pInfo) < 0) return -1; + } + } + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSTableIndexInfo(SDecoder *pDecoder, STableIndexInfo *pInfo) { + if (tDecodeI8(pDecoder, &pInfo->intervalUnit) < 0) return -1; + if (tDecodeI8(pDecoder, &pInfo->slidingUnit) < 0) return -1; + if (tDecodeI64(pDecoder, &pInfo->interval) < 0) return -1; + if (tDecodeI64(pDecoder, &pInfo->offset) < 0) return -1; + if (tDecodeI64(pDecoder, &pInfo->sliding) < 0) return -1; + if (tDecodeI64(pDecoder, &pInfo->dstTbUid) < 0) return -1; + if (tDecodeI32(pDecoder, &pInfo->dstVgId) < 0) return -1; + if (tDecodeSEpSet(pDecoder, &pInfo->epSet) < 0) return -1; + if (tDecodeCStrAlloc(pDecoder, &pInfo->expr) < 0) return -1; + + return 0; +} + +int32_t tDeserializeSTableIndexRsp(void *buf, int32_t bufLen, STableIndexRsp *pRsp) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + int32_t num = 0; + if (tDecodeI32(&decoder, &num) < 0) return -1; + if (num > 0) { + pRsp->pIndex = taosArrayInit(num, sizeof(STableIndexInfo)); + if (NULL == pRsp->pIndex) return -1; + STableIndexInfo info; + for (int32_t i = 0; i < num; ++i) { + if (tDeserializeSTableIndexInfo(&decoder, &info) < 0) return -1; + if (NULL == taosArrayPush(pRsp->pIndex, &info)) { + taosMemoryFree(info.expr); + return -1; + } + } + } + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + + int32_t tSerializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); @@ -3256,6 +3356,89 @@ int32_t tDeserializeSKillTransReq(void *buf, int32_t bufLen, SKillTransReq *pReq return 0; } +int32_t tSerializeSBalanceVgroupReq(void *buf, int32_t bufLen, SBalanceVgroupReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeI32(&encoder, pReq->useless) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSBalanceVgroupReq(void *buf, int32_t bufLen, SBalanceVgroupReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->useless) < 0) return -1; + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + +int32_t tSerializeSMergeVgroupReq(void *buf, int32_t bufLen, SMergeVgroupReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeI32(&encoder, pReq->vgId1) < 0) return -1; + if (tEncodeI32(&encoder, pReq->vgId2) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMergeVgroupReq(void *buf, int32_t bufLen, SMergeVgroupReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->vgId1) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->vgId2) < 0) return -1; + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + +int32_t tSerializeSRedistributeVgroupReq(void *buf, int32_t bufLen, SRedistributeVgroupReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeI32(&encoder, pReq->vgId) < 0) return -1; + if (tEncodeI32(&encoder, pReq->dnodeId1) < 0) return -1; + if (tEncodeI32(&encoder, pReq->dnodeId2) < 0) return -1; + if (tEncodeI32(&encoder, pReq->dnodeId3) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSRedistributeVgroupReq(void *buf, int32_t bufLen, SRedistributeVgroupReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->vgId) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->dnodeId1) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->dnodeId2) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->dnodeId3) < 0) return -1; + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + int32_t tSerializeSDCreateMnodeReq(void *buf, int32_t bufLen, SDCreateMnodeReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); @@ -3823,46 +4006,70 @@ int32_t tDecodeSVGetTsmaExpWndsRsp(SDecoder *pCoder, SVGetTsmaExpWndsRsp *pReq) return 0; } -int32_t tEncodeSVDeleteReq(SEncoder *pCoder, const SVDeleteReq *pReq) { - if (tStartEncode(pCoder) < 0) return -1; - - if (tEncodeI64(pCoder, pReq->delUid) < 0) return -1; - if (tEncodeI64(pCoder, pReq->tbUid) < 0) return -1; - if (tEncodeI8(pCoder, pReq->type) < 0) return -1; - if (tEncodeI16v(pCoder, pReq->nWnds) < 0) return -1; - if (tEncodeCStr(pCoder, pReq->tbFullName) < 0) return -1; - if (tEncodeCStr(pCoder, pReq->subPlan) < 0) return -1; - for (int16_t i = 0; i < pReq->nWnds; ++i) { - if (tEncodeI64(pCoder, pReq->wnds[i].skey) < 0) return -1; - if (tEncodeI64(pCoder, pReq->wnds[i].ekey) < 0) return -1; +int32_t tSerializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq) { + int32_t headLen = sizeof(SMsgHead); + if (buf != NULL) { + buf = (char *)buf + headLen; + bufLen -= headLen; } - tEndEncode(pCoder); - return 0; + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeU64(&encoder, pReq->sId) < 0) return -1; + if (tEncodeU64(&encoder, pReq->queryId) < 0) return -1; + if (tEncodeU64(&encoder, pReq->taskId) < 0) return -1; + if (tEncodeU32(&encoder, pReq->sqlLen) < 0) return -1; + if (tEncodeU32(&encoder, pReq->phyLen) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->msg) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + + if (buf != NULL) { + SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen); + pHead->vgId = htonl(pReq->header.vgId); + pHead->contLen = htonl(tlen + headLen); + } + + return tlen + headLen; } -int32_t tDecodeSVDeleteReq(SDecoder *pCoder, SVDeleteReq *pReq) { - if (tStartDecode(pCoder) < 0) return -1; +int32_t tDeserializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq) { + int32_t headLen = sizeof(SMsgHead); - if (tDecodeI64(pCoder, &pReq->delUid) < 0) return -1; - if (tDecodeI64(pCoder, &pReq->tbUid) < 0) return -1; - if (tDecodeI8(pCoder, &pReq->type) < 0) return -1; - if (tDecodeI16v(pCoder, &pReq->nWnds) < 0) return -1; - if (tDecodeCStr(pCoder, &pReq->tbFullName) < 0) return -1; - if (tDecodeCStr(pCoder, &pReq->subPlan) < 0) return -1; - for (int16_t i = 0; i < pReq->nWnds; ++i) { - if (tDecodeI64(pCoder, &pReq->wnds[i].skey) < 0) return -1; - if (tDecodeI64(pCoder, &pReq->wnds[i].ekey) < 0) return -1; - } + SMsgHead *pHead = buf; + pHead->vgId = pReq->header.vgId; + pHead->contLen = pReq->header.contLen; - tEndDecode(pCoder); + SDecoder decoder = {0}; + tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeU64(&decoder, &pReq->sId) < 0) return -1; + if (tDecodeU64(&decoder, &pReq->queryId) < 0) return -1; + if (tDecodeU64(&decoder, &pReq->taskId) < 0) return -1; + if (tDecodeU32(&decoder, &pReq->sqlLen) < 0) return -1; + if (tDecodeU32(&decoder, &pReq->phyLen) < 0) return -1; + pReq->sql = taosMemoryCalloc(1, pReq->sqlLen + 1); + if (NULL == pReq->sql) return -1; + pReq->msg = taosMemoryCalloc(1, pReq->phyLen + 1); + if (NULL == pReq->msg) return -1; + if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->msg) < 0) return -1; + + tEndDecode(&decoder); + + tDecoderClear(&decoder); return 0; } int32_t tEncodeSVDeleteRsp(SEncoder *pCoder, const SVDeleteRsp *pReq) { if (tStartEncode(pCoder) < 0) return -1; - if (tEncodeI32(pCoder, pReq->code) < 0) return -1; if (tEncodeI64(pCoder, pReq->affectedRows) < 0) return -1; tEndEncode(pCoder); @@ -3872,7 +4079,6 @@ int32_t tEncodeSVDeleteRsp(SEncoder *pCoder, const SVDeleteRsp *pReq) { int32_t tDecodeSVDeleteRsp(SDecoder *pCoder, SVDeleteRsp *pReq) { if (tStartDecode(pCoder) < 0) return -1; - if (tDecodeI32(pCoder, &pReq->code) < 0) return -1; if (tDecodeI64(pCoder, &pReq->affectedRows) < 0) return -1; tEndDecode(pCoder); diff --git a/source/common/src/ttypes.c b/source/common/src/ttypes.c index b3999a49e7..156b66ae86 100644 --- a/source/common/src/ttypes.c +++ b/source/common/src/ttypes.c @@ -18,7 +18,7 @@ #include "tcompression.h" #include "trow.h" -const int32_t TYPE_BYTES[15] = { +const int32_t TYPE_BYTES[16] = { -1, // TSDB_DATA_TYPE_NULL CHAR_BYTES, // TSDB_DATA_TYPE_BOOL CHAR_BYTES, // TSDB_DATA_TYPE_TINYINT @@ -34,6 +34,7 @@ const int32_t TYPE_BYTES[15] = { SHORT_BYTES, // TSDB_DATA_TYPE_USMALLINT INT_BYTES, // TSDB_DATA_TYPE_UINT sizeof(uint64_t), // TSDB_DATA_TYPE_UBIGINT + TSDB_MAX_JSON_TAG_LEN, // TSDB_DATA_TYPE_JSON }; #define DO_STATICS(__sum, __min, __max, __minIndex, __maxIndex, _list, _index) \ diff --git a/source/common/test/CMakeLists.txt b/source/common/test/CMakeLists.txt index 0535b08be7..eb79e79afa 100644 --- a/source/common/test/CMakeLists.txt +++ b/source/common/test/CMakeLists.txt @@ -5,7 +5,12 @@ MESSAGE(STATUS "build parser unit test") SET(CMAKE_CXX_STANDARD 11) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) -ADD_EXECUTABLE(commonTest ${SOURCE_LIST}) +ADD_EXECUTABLE(commonTest "") +TARGET_SOURCES( + commonTest + PRIVATE + "commonTests.cpp" +) TARGET_LINK_LIBRARIES( commonTest PUBLIC os util common gtest @@ -24,7 +29,12 @@ target_sources( PRIVATE "dataformatTest.cpp" ) -target_link_libraries(dataformatTest gtest gtest_main util) +target_link_libraries(dataformatTest gtest gtest_main util common) +target_include_directories( + dataformatTest + PUBLIC "${TD_SOURCE_DIR}/include/common" + PUBLIC "${TD_SOURCE_DIR}/include/util" +) # tmsg test # add_executable(tmsgTest "") diff --git a/source/common/test/dataformatTest.cpp b/source/common/test/dataformatTest.cpp index 3497014c22..81e91da0d6 100644 --- a/source/common/test/dataformatTest.cpp +++ b/source/common/test/dataformatTest.cpp @@ -1 +1,481 @@ -#include "gtest/gtest.h" \ No newline at end of file +/* + * 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 +#include +#include +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" + +#define NONE_CSTR "no" +#define NULL_CSTR "nu" +#define NONE_LEN 2 +#define NULL_LEN 2 +const static int16_t MAX_COLS = 14; + +int main(int argc, char **argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +// ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(10), c6 nchar(10), c7 tinyint, c8 smallint, c9 bool +STSchema *genSTSchema(int16_t nCols) { + EXPECT_LE(nCols, MAX_COLS); + SSchema *pSchema = (SSchema *)taosMemoryCalloc(nCols, sizeof(SSchema)); + EXPECT_NE(pSchema, nullptr); + + for (int16_t i = 0; i < nCols; ++i) { + pSchema[i].colId = PRIMARYKEY_TIMESTAMP_COL_ID + i; + char colName[TSDB_COL_NAME_LEN] = {0}; + snprintf(colName, TSDB_COL_NAME_LEN, "c%" PRIi16, i); + strncpy(pSchema[i].name, colName, TSDB_COL_NAME_LEN); + + switch (i) { + case 0: { + pSchema[0].type = TSDB_DATA_TYPE_TIMESTAMP; + pSchema[0].bytes = TYPE_BYTES[pSchema[0].type]; + } break; + case 1: { + pSchema[1].type = TSDB_DATA_TYPE_INT; + pSchema[1].bytes = TYPE_BYTES[pSchema[1].type]; + ; + } break; + case 2: { + pSchema[2].type = TSDB_DATA_TYPE_BIGINT; + pSchema[2].bytes = TYPE_BYTES[pSchema[2].type]; + } break; + case 3: { + pSchema[3].type = TSDB_DATA_TYPE_FLOAT; + pSchema[3].bytes = TYPE_BYTES[pSchema[3].type]; + } break; + case 4: { + pSchema[4].type = TSDB_DATA_TYPE_DOUBLE; + pSchema[4].bytes = TYPE_BYTES[pSchema[4].type]; + } break; + case 5: { + pSchema[5].type = TSDB_DATA_TYPE_BINARY; + pSchema[5].bytes = 12; + } break; + case 6: { + pSchema[6].type = TSDB_DATA_TYPE_NCHAR; + pSchema[6].bytes = 42; + } break; + case 7: { + pSchema[7].type = TSDB_DATA_TYPE_TINYINT; + pSchema[7].bytes = TYPE_BYTES[pSchema[7].type]; + } break; + case 8: { + pSchema[8].type = TSDB_DATA_TYPE_SMALLINT; + pSchema[8].bytes = TYPE_BYTES[pSchema[8].type]; + } break; + case 9: { + pSchema[9].type = TSDB_DATA_TYPE_BOOL; + pSchema[9].bytes = TYPE_BYTES[pSchema[9].type]; + } break; + case 10: { + pSchema[10].type = TSDB_DATA_TYPE_UTINYINT; + pSchema[10].bytes = TYPE_BYTES[pSchema[10].type]; + } break; + case 11: { + pSchema[11].type = TSDB_DATA_TYPE_USMALLINT; + pSchema[11].bytes = TYPE_BYTES[pSchema[11].type]; + } break; + case 12: { + pSchema[12].type = TSDB_DATA_TYPE_UINT; + pSchema[12].bytes = TYPE_BYTES[pSchema[12].type]; + } break; + case 13: { + pSchema[13].type = TSDB_DATA_TYPE_UBIGINT; + pSchema[13].bytes = TYPE_BYTES[pSchema[13].type]; + } break; + + default: + ASSERT(0); + break; + } + } + + STSchema *pResult = NULL; + pResult = tdGetSTSChemaFromSSChema(&pSchema, nCols); + + taosMemoryFree(pSchema); + return pResult; +} + +// ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(10), c6 nchar(10), c7 tinyint, c8 smallint, c9 bool +static int32_t genTestData(const char **data, int16_t nCols, SArray **pArray) { + if (!(*pArray)) { + *pArray = taosArrayInit(nCols, sizeof(SColVal)); + if (!(*pArray)) return -1; + } + + for (int16_t i = 0; i < nCols; ++i) { + SColVal colVal = {0}; + colVal.cid = PRIMARYKEY_TIMESTAMP_COL_ID + i; + if (strncasecmp(data[i], NONE_CSTR, NONE_LEN) == 0) { + colVal.isNone = 1; + taosArrayPush(*pArray, &colVal); + continue; + } else if (strncasecmp(data[i], NULL_CSTR, NULL_LEN) == 0) { + colVal.isNull = 1; + taosArrayPush(*pArray, &colVal); + continue; + } + + switch (i) { + case 0: + sscanf(data[i], "%" PRIi64, &colVal.value.ts); + break; + case 1: { + sscanf(data[i], "%" PRIi32, &colVal.value.i32); + } break; + case 2: + sscanf(data[i], "%" PRIi64, &colVal.value.i64); + break; + case 3: + sscanf(data[i], "%f", &colVal.value.f); + break; + case 4: + sscanf(data[i], "%lf", &colVal.value.d); + break; + case 5: { + int16_t dataLen = strlen(data[i]) + 1; + colVal.value.nData = dataLen < 10 ? dataLen : 10; + colVal.value.pData = (uint8_t *)data[i]; + } break; + case 6: { + int16_t dataLen = strlen(data[i]) + 1; + colVal.value.nData = dataLen < 40 ? dataLen : 40; + colVal.value.pData = (uint8_t *)data[i]; // just for test, not real nchar + } break; + case 7: + case 9: { + int32_t d8; + sscanf(data[i], "%" PRId32, &d8); + colVal.value.i8 = (int8_t)d8; + } break; + case 8: { + int32_t d16; + sscanf(data[i], "%" PRId32, &d16); + colVal.value.i16 = (int16_t)d16; + } break; + case 10: { + uint32_t u8; + sscanf(data[i], "%" PRId32, &u8); + colVal.value.u8 = (uint8_t)u8; + } break; + case 11: { + uint32_t u16; + sscanf(data[i], "%" PRId32, &u16); + colVal.value.u16 = (uint16_t)u16; + } break; + case 12: { + sscanf(data[i], "%" PRIu32, &colVal.value.u32); + } break; + case 13: { + sscanf(data[i], "%" PRIu64, &colVal.value.u64); + } break; + default: + ASSERT(0); + } + taosArrayPush(*pArray, &colVal); + } + return 0; +} + +int32_t debugPrintSColVal(SColVal *cv, int8_t type) { + if (cv->isNone) { + printf("None "); + return 0; + } + if (cv->isNull) { + printf("Null "); + return 0; + } + switch (type) { + case TSDB_DATA_TYPE_BOOL: + printf("%s ", cv->value.i8 == 0 ? "false" : "true"); + break; + case TSDB_DATA_TYPE_TINYINT: + printf("%" PRIi8 " ", cv->value.i8); + break; + case TSDB_DATA_TYPE_SMALLINT: + printf("%" PRIi16 " ", cv->value.i16); + break; + case TSDB_DATA_TYPE_INT: + printf("%" PRIi32 " ", cv->value.i32); + break; + case TSDB_DATA_TYPE_BIGINT: + printf("%" PRIi64 " ", cv->value.i64); + break; + case TSDB_DATA_TYPE_FLOAT: + printf("%f ", cv->value.f); + break; + case TSDB_DATA_TYPE_DOUBLE: + printf("%lf ", cv->value.d); + break; + case TSDB_DATA_TYPE_VARCHAR: { + char tv[15] = {0}; + snprintf(tv, 15, "%s", cv->value.pData); + printf("%s ", tv); + } break; + case TSDB_DATA_TYPE_TIMESTAMP: + printf("%" PRIi64 " ", cv->value.i64); + break; + case TSDB_DATA_TYPE_NCHAR: { + char tv[15] = {0}; + snprintf(tv, 15, "%s", cv->value.pData); + printf("%s ", tv); + } break; + case TSDB_DATA_TYPE_UTINYINT: + printf("%" PRIu8 " ", cv->value.u8); + break; + case TSDB_DATA_TYPE_USMALLINT: + printf("%" PRIu16 " ", cv->value.u16); + break; + case TSDB_DATA_TYPE_UINT: + printf("%" PRIu32 " ", cv->value.u32); + break; + case TSDB_DATA_TYPE_UBIGINT: + printf("%" PRIu64 " ", cv->value.u64); + break; + case TSDB_DATA_TYPE_JSON: + printf("JSON "); + break; + case TSDB_DATA_TYPE_VARBINARY: + printf("VARBIN "); + break; + case TSDB_DATA_TYPE_DECIMAL: + printf("DECIMAL "); + break; + case TSDB_DATA_TYPE_BLOB: + printf("BLOB "); + break; + case TSDB_DATA_TYPE_MEDIUMBLOB: + printf("MedBLOB "); + break; + // case TSDB_DATA_TYPE_BINARY: + // printf("BINARY "); + // break; + case TSDB_DATA_TYPE_MAX: + printf("UNDEF "); + break; + default: + printf("UNDEF "); + break; + } + return 0; +} + +void debugPrintTSRow(STSRow2 *row, STSchema *pTSchema, const char *tags, int32_t ln) { + printf("%s:%d %s:v%d:%d ", tags, ln, (row->flags & 0xf0) ? "KV" : "TP", row->sver, row->nData); + for (int16_t i = 0; i < schemaNCols(pTSchema); ++i) { + SColVal cv = {0}; + tTSRowGet(row, pTSchema, i, &cv); + debugPrintSColVal(&cv, pTSchema->columns[i].type); + } + printf("\n"); + fflush(stdout); +} + +static int32_t checkSColVal(const char *rawVal, SColVal *cv, int8_t type) { + ASSERT(rawVal); + + if (cv->isNone) { + EXPECT_STRCASEEQ(rawVal, NONE_CSTR); + return 0; + } + if (cv->isNull) { + EXPECT_STRCASEEQ(rawVal, NULL_CSTR); + return 0; + } + + SValue rawSVal = {0}; + switch (type) { + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: { + int32_t d8; + sscanf(rawVal, "%" PRId32, &d8); + EXPECT_EQ(cv->value.i8, (int8_t)d8); + } break; + case TSDB_DATA_TYPE_SMALLINT: { + int32_t d16; + sscanf(rawVal, "%" PRId32, &d16); + EXPECT_EQ(cv->value.i16, (int16_t)d16); + } break; + case TSDB_DATA_TYPE_INT: { + sscanf(rawVal, "%" PRId32, &rawSVal.i32); + EXPECT_EQ(cv->value.i32, rawSVal.i32); + } break; + case TSDB_DATA_TYPE_BIGINT: { + sscanf(rawVal, "%" PRIi64, &rawSVal.i64); + EXPECT_EQ(cv->value.i64, rawSVal.i64); + } break; + case TSDB_DATA_TYPE_FLOAT: { + sscanf(rawVal, "%f", &rawSVal.f); + EXPECT_FLOAT_EQ(cv->value.f, rawSVal.f); + } break; + case TSDB_DATA_TYPE_DOUBLE: { + sscanf(rawVal, "%lf", &rawSVal.d); + EXPECT_DOUBLE_EQ(cv->value.d, rawSVal.d); + } break; + case TSDB_DATA_TYPE_VARCHAR: { + EXPECT_STRCASEEQ(rawVal, (const char *)cv->value.pData); + } break; + case TSDB_DATA_TYPE_TIMESTAMP: { + sscanf(rawVal, "%" PRIi64, &rawSVal.ts); + EXPECT_DOUBLE_EQ(cv->value.ts, rawSVal.ts); + } break; + case TSDB_DATA_TYPE_NCHAR: { + EXPECT_STRCASEEQ(rawVal, (const char *)cv->value.pData); // informal nchar comparsion + } break; + case TSDB_DATA_TYPE_UTINYINT: { + uint32_t u8; + sscanf(rawVal, "%" PRIu32, &u8); + EXPECT_EQ(cv->value.u8, (uint8_t)u8); + } break; + case TSDB_DATA_TYPE_USMALLINT: { + uint32_t u16; + sscanf(rawVal, "%" PRIu32, &u16); + EXPECT_EQ(cv->value.u16, (uint16_t)u16); + } break; + case TSDB_DATA_TYPE_UINT: { + sscanf(rawVal, "%" PRIu32, &rawSVal.u32); + EXPECT_EQ(cv->value.u32, rawSVal.u32); + } break; + case TSDB_DATA_TYPE_UBIGINT: { + sscanf(rawVal, "%" PRIu64, &rawSVal.u64); + EXPECT_EQ(cv->value.u64, rawSVal.u64); + } break; + case TSDB_DATA_TYPE_JSON: + printf("JSON "); + break; + case TSDB_DATA_TYPE_VARBINARY: + printf("VARBIN "); + break; + case TSDB_DATA_TYPE_DECIMAL: + printf("DECIMAL "); + break; + case TSDB_DATA_TYPE_BLOB: + printf("BLOB "); + break; + case TSDB_DATA_TYPE_MEDIUMBLOB: + printf("MedBLOB "); + break; + // case TSDB_DATA_TYPE_BINARY: + // printf("BINARY "); + // break; + case TSDB_DATA_TYPE_MAX: + printf("UNDEF "); + break; + default: + printf("UNDEF "); + break; + } + return 0; +} + +static void checkTSRow(const char **data, STSRow2 *row, STSchema *pTSchema) { + for (int16_t i = 0; i < schemaNCols(pTSchema); ++i) { + SColVal cv = {0}; + tTSRowGet(row, pTSchema, i, &cv); + checkSColVal(data[i], &cv, pTSchema->columns[i].type); + } +} + +TEST(testCase, AllNormTest) { + int16_t nCols = 1; + STSRow2 *row = nullptr; + SArray *pArray = taosArrayInit(nCols, sizeof(SColVal)); + EXPECT_NE(pArray, nullptr); + + STSchema *pTSchema = genSTSchema(nCols); + EXPECT_NE(pTSchema, nullptr); + + // ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(10), c6 nchar(10), c7 tinyint, c8 smallint, + // c9 bool + char *data[10] = {"1653694220000", "10", "20", "10.1", "10.1", "binary10", "nchar10", "10", "10", "1"}; + + genTestData((const char **)&data, nCols, &pArray); + + tTSRowNew(NULL, pArray, pTSchema, &row); + + debugPrintTSRow(row, pTSchema, __func__, __LINE__); + checkTSRow((const char **)&data, row, pTSchema); + + taosArrayDestroy(pArray); + taosMemoryFree(pTSchema); +} + +#if 1 +TEST(testCase, NoneTest) { + const static int nCols = 14; + const static int nRows = 20; + STSRow2 *row = nullptr; + SArray *pArray = taosArrayInit(nCols, sizeof(SColVal)); + EXPECT_NE(pArray, nullptr); + + STSchema *pTSchema = genSTSchema(nCols); + EXPECT_NE(pTSchema, nullptr); + + // ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(10), c6 nchar(10), c7 tinyint, c8 smallint, + // c9 bool c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned + const char *data[nRows][nCols] = { + {"1653694220000", "no", "20", "10.1", "10.1", "binary10", "no", "10", "10", "nu", "10", "20", "30", "40"}, + {"1653694220001", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no", "no"}, + {"1653694220002", "no", "no", "no", "no", "no", "nu", "no", "no", "no", "no", "no", "no", "nu"}, + {"1653694220003", "nu", "no", "no", "no", "no", "nu", "no", "no", "no", "no", "no", "no", "no"}, + {"1653694220004", "no", "20", "no", "no", "no", "nchar10", "no", "no", "no", "no", "no", "no", "no"}, + {"1653694220005", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu"}, + {"1653694220006", "no", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu"}, + {"1653694220007", "no", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "no"}, + {"1653694220008", "no", "nu", "nu", "nu", "binary10", "nu", "nu", "nu", "nu", "nu", "nu", "nu", "no"}, + {"1653694220009", "no", "nu", "nu", "nu", "binary10", "nu", "nu", "10", "no", "nu", "nu", "nu", "100"}, + {"1653694220010", "-1", "-1", "-1", "-1", "binary10", "nu", "-1", "0", "0", "0", "0", "0", "0"}, + {"1653694220011", "-2147483648", "nu", "nu", "nu", "biy10", "nu", "nu", "32767", "no", "nu", "nu", "nu", "100"}, + {"1653694220012", "2147483647", "nu", "nu", "nu", "ary10", "nu", "nu", "-32768", "no", "nu", "nu", "nu", "100"}, + {"1653694220013", "no", "-9223372036854775818", "nu", "nu", "b1", "nu", "nu", "10", "no", "nu", "nu", "nu", "nu"}, + {"1653694220014", "no", "nu", "nu", "nu", "b0", "nu", "nu", "10", "no", "nu", "nu", "nu", "9223372036854775808"}, + {"1653694220015", "no", "nu", "nu", "nu", "binary30", "char4", "nu", "10", "no", "nu", "nu", "nu", + "18446744073709551615"}, + {"1653694220016", "2147483647", "nu", "nu", "nu", "bin50", "nu", "nu", "10", "no", "nu", "nu", "nu", "100"}, + {"1653694220017", "2147483646", "0", "0", "0", "binary10", "0", "0", "0", "0", "255", "0", "0", "0"}, + {"1653694220018", "no", "-9223372036854775808", "nu", "nu", "binary10", "nu", "nu", "10", "no", "nu", "nu", + "4294967295", "100"}, + {"1653694220019", "no", "9223372036854775807", "nu", "nu", "bin10", "nu", "nu", "10", "no", "254", "nu", "nu", + "no"}}; + + + for (int r = 0; r < nRows; ++r) { + genTestData((const char **)&data[r], nCols, &pArray); + tTSRowNew(NULL, pArray, pTSchema, &row); + debugPrintTSRow(row, pTSchema, __func__, __LINE__); // debug print + checkTSRow((const char **)&data[r], row, pTSchema); // check + taosMemoryFreeClear(row); + taosArrayClear(pArray); + } + + taosArrayDestroy(pArray); + taosMemoryFree(pTSchema); +} +#endif \ No newline at end of file diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index 27f5e6f7af..6c2783cb5c 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -181,6 +181,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_SMA, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_STREAM, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_GET_INDEX, mmPutNodeMsgToReadQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_GET_TABLE_INDEX, mmPutNodeMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_TOPIC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_TOPIC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_TOPIC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; @@ -210,7 +211,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TASK, mmPutNodeMsgToQueryQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DEPLOY_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIRM_RSP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_snode/src/smHandle.c b/source/dnode/mgmt/mgmt_snode/src/smHandle.c index a3aab439de..66ab627e32 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smHandle.c +++ b/source/dnode/mgmt/mgmt_snode/src/smHandle.c @@ -94,9 +94,10 @@ SArray *smGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MON_SM_INFO, smPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER; - // Requests handled by SNODE - if (dmSetMgmtHandle(pArray, TDMT_SND_TASK_DEPLOY, smPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER; - /*if (dmSetMgmtHandle(pArray, TDMT_SND_TASK_EXEC, smPutNodeMsgToExecQueue, 0) == NULL) goto _OVER;*/ + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; code = 0; _OVER: diff --git a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h index adc18fdced..7e5379b0f8 100644 --- a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h +++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h @@ -34,6 +34,7 @@ typedef struct SVnodeMgmt { SQWorkerPool fetchPool; SWWorkerPool syncPool; SWWorkerPool writePool; + SWWorkerPool applyPool; SWWorkerPool mergePool; SSingleWorker mgmtWorker; SSingleWorker monitorWorker; @@ -52,10 +53,9 @@ typedef struct { typedef struct { int32_t vgId; - int32_t refCount; int32_t vgVersion; + int32_t refCount; int8_t dropped; - int8_t accessState; char *path; SVnode *pImpl; STaosQueue *pWriteQ; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 77109ab52f..90e4e30261 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -210,8 +210,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return -1; } - dDebug("vgId:%d, start to create vnode, tsma:%d standby:%d", createReq.vgId, createReq.isTsma, - createReq.standby); + dDebug("vgId:%d, start to create vnode, tsma:%d standby:%d", createReq.vgId, createReq.isTsma, createReq.standby); vmGenerateVnodeCfg(&createReq, &vnodeCfg); if (vmTsmaAdjustDays(&vnodeCfg, &createReq) < 0) { @@ -324,7 +323,6 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MON_VM_INFO, vmPutMsgToMonitorQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MON_VM_LOAD, vmPutMsgToMonitorQueue, 0) == NULL) goto _OVER; - // Requests handled by VNODE if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_CONTINUE, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER; @@ -333,11 +331,6 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_UPDATE_TAG_VAL, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_TABLE_META, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_TABLES_META, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_CONSUME, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_QUERY, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_CONNECT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_DISCONNECT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - // if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_SET_CUR, vmPutMsgToWriteQueue, 0)== NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; @@ -352,12 +345,16 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_CONSUME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DEPLOY, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_HEARTBEAT, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RUN, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DISPATCH, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RECOVER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER_RSP, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index 23927255bb..9e4e7713f2 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -49,10 +49,9 @@ int32_t vmOpenVnode(SVnodeMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) { } pVnode->vgId = pCfg->vgId; - pVnode->refCount = 0; pVnode->vgVersion = pCfg->vgVersion; + pVnode->refCount = 0; pVnode->dropped = 0; - pVnode->accessState = TSDB_VN_ALL_ACCCESS; pVnode->path = tstrdup(pCfg->path); pVnode->pImpl = pImpl; @@ -96,7 +95,7 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { dDebug("vgId:%d, vnode is closed", pVnode->vgId); if (pVnode->dropped) { - dDebug("vgId:%d, vnode is destroyed for dropped:%d", pVnode->vgId, pVnode->dropped); + dInfo("vgId:%d, vnode is destroyed, dropped:%d", pVnode->vgId, pVnode->dropped); snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, pVnode->vgId); vnodeDestroy(path, pMgmt->pTfs); } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index 427b3d5c94..88831384d4 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -16,10 +16,8 @@ #define _DEFAULT_SOURCE #include "vmInt.h" -#include "sync.h" -#include "syncTools.h" - static inline void vmSendRsp(SRpcMsg *pMsg, int32_t code) { + if (pMsg->info.handle == NULL) return; SRpcMsg rsp = { .code = code, .pCont = pMsg->info.rsp, @@ -53,9 +51,9 @@ static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { } if (IsReq(pMsg)) { - if (code != 0 && terrno != 0) { - dError("msg:%p failed to process since %s", pMsg, terrstr()); - code = terrno; + if (code != 0) { + if (terrno != 0) code = terrno; + dError("msg:%p, failed to process since %s", pMsg, terrstr()); } vmSendRsp(pMsg, code); } @@ -97,110 +95,6 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { taosFreeQitem(pMsg); } -static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { - int32_t code = 0; - SRpcMsg *pMsg = NULL; - SVnodeObj *pVnode = pInfo->ahandle; - int64_t sync = vnodeGetSyncHandle(pVnode->pImpl); - SArray *pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg **)); - - for (int32_t m = 0; m < numOfMsgs; m++) { - if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; - dTrace("vgId:%d, msg:%p get from vnode-write queue", pVnode->vgId, pMsg); - - if (taosArrayPush(pArray, &pMsg) == NULL) { - dError("vgId:%d, failed to push msg:%p to vnode-write array", pVnode->vgId, pMsg); - vmSendRsp(pMsg, TSDB_CODE_OUT_OF_MEMORY); - } - } - - for (int32_t m = 0; m < taosArrayGetSize(pArray); m++) { - pMsg = *(SRpcMsg **)taosArrayGet(pArray, m); - code = vnodePreprocessReq(pVnode->pImpl, pMsg); - - if (code == TSDB_CODE_ACTION_IN_PROGRESS) { - dTrace("vgId:%d, msg:%p in progress and no rsp", pVnode->vgId, pMsg); - continue; - } - - if (pMsg->msgType != TDMT_VND_ALTER_REPLICA) { - code = syncPropose(sync, pMsg, false); - } - - if (code == TAOS_SYNC_PROPOSE_SUCCESS) { - dTrace("vgId:%d, msg:%p is proposed and no rsp", pVnode->vgId, pMsg); - continue; - } else if (code == TAOS_SYNC_PROPOSE_NOT_LEADER) { - SEpSet newEpSet = {0}; - syncGetEpSet(sync, &newEpSet); - SEp *pEp = &newEpSet.eps[newEpSet.inUse]; - if (pEp->port == tsServerPort && strcmp(pEp->fqdn, tsLocalFqdn) == 0) { - newEpSet.inUse = (newEpSet.inUse + 1) % newEpSet.numOfEps; - } - - dTrace("vgId:%d, msg:%p is redirect since not leader, numOfEps:%d inUse:%d", pVnode->vgId, pMsg, - newEpSet.numOfEps, newEpSet.inUse); - for (int32_t i = 0; i < newEpSet.numOfEps; ++i) { - dTrace("vgId:%d, msg:%p ep:%s:%u", pVnode->vgId, pMsg, newEpSet.eps[i].fqdn, newEpSet.eps[i].port); - } - - SRpcMsg rsp = {.code = TSDB_CODE_RPC_REDIRECT, .info = pMsg->info}; - tmsgSendRedirectRsp(&rsp, &newEpSet); - } else { - dError("vgId:%d, msg:%p failed to propose write since %s, code:0x%x", pVnode->vgId, pMsg, tstrerror(code), code); - vmSendRsp(pMsg, code); - } - } - - for (int32_t i = 0; i < numOfMsgs; i++) { - pMsg = *(SRpcMsg **)taosArrayGet(pArray, i); - dTrace("vgId:%d, msg:%p is freed", pVnode->vgId, pMsg); - rpcFreeCont(pMsg->pCont); - taosFreeQitem(pMsg); - } - - taosArrayDestroy(pArray); -} - -static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { - SVnodeObj *pVnode = pInfo->ahandle; - SRpcMsg *pMsg = NULL; - - for (int32_t i = 0; i < numOfMsgs; ++i) { - if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; - dTrace("vgId:%d, msg:%p get from vnode-apply queue", pVnode->vgId, pMsg); - - // init response rpc msg - SRpcMsg rsp = {0}; - - // get original rpc msg - assert(pMsg->msgType == TDMT_SYNC_APPLY_MSG); - SyncApplyMsg *pSyncApplyMsg = syncApplyMsgFromRpcMsg2(pMsg); - syncApplyMsgLog2("==vmProcessApplyQueue==", pSyncApplyMsg); - SRpcMsg originalRpcMsg; - syncApplyMsg2OriginalRpcMsg(pSyncApplyMsg, &originalRpcMsg); - - // apply data into tsdb - if (vnodeProcessWriteReq(pVnode->pImpl, &originalRpcMsg, pSyncApplyMsg->fsmMeta.index, &rsp) < 0) { - rsp.code = terrno; - dError("vgId:%d, msg:%p failed to apply since %s", pVnode->vgId, pMsg, terrstr()); - } - - syncApplyMsgDestroy(pSyncApplyMsg); - rpcFreeCont(originalRpcMsg.pCont); - - // if leader, send response - if (pMsg->info.handle != NULL) { - rsp.info = pMsg->info; - tmsgSendRsp(&rsp); - } - - dTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, rsp.code); - rpcFreeCont(pMsg->pCont); - taosFreeQitem(pMsg); - } -} - static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { SVnodeObj *pVnode = pInfo->ahandle; SRpcMsg *pMsg = NULL; @@ -211,11 +105,9 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf int32_t code = vnodeProcessSyncReq(pVnode->pImpl, pMsg, NULL); if (code != 0) { + if (terrno != 0) code = terrno; dError("vgId:%d, msg:%p failed to sync since %s", pVnode->vgId, pMsg, terrstr()); - if (pMsg->info.handle != NULL) { - if (terrno != 0) code = terrno; - vmSendRsp(pMsg, code); - } + vmSendRsp(pMsg, code); } dTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); @@ -234,8 +126,8 @@ static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo); if (code != 0) { - dError("vgId:%d, msg:%p failed to merge since %s", pVnode->vgId, pMsg, terrstr()); if (terrno != 0) code = terrno; + dError("vgId:%d, msg:%p failed to merge since %s", pVnode->vgId, pMsg, terrstr()); vmSendRsp(pMsg, code); } @@ -254,7 +146,7 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId); if (pVnode == NULL) { - dError("vgId:%d, failed to put msg:%p into vnode queue since %s, type:%s", pHead->vgId, pMsg, terrstr(), + dError("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s", pHead->vgId, pMsg, terrstr(), TMSG_INFO(pMsg->msgType)); return terrno != 0 ? terrno : -1; } @@ -322,7 +214,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) { if (pMsg == NULL) return -1; SMsgHead *pHead = pRpc->pCont; - dTrace("vgId:%d, msg:%p is created, type:%s", pHead->vgId, pMsg, TMSG_INFO(pMsg->msgType)); + dTrace("vgId:%d, msg:%p is created, type:%s", pHead->vgId, pMsg, TMSG_INFO(pRpc->msgType)); pHead->contLen = htonl(pHead->contLen); pHead->vgId = htonl(pHead->vgId); @@ -362,9 +254,9 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) { } int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { - pVnode->pWriteQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode, (FItems)vmProcessWriteQueue); + pVnode->pWriteQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode->pImpl, (FItems)vnodeProposeMsg); pVnode->pSyncQ = tWWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FItems)vmProcessSyncQueue); - pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode, (FItems)vmProcessApplyQueue); + pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->applyPool, pVnode->pImpl, (FItems)vnodeApplyMsg); pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue); pVnode->pFetchQ = tQWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItem)vmProcessFetchQueue); pVnode->pMergeQ = tWWorkerAllocQueue(&pMgmt->mergePool, pVnode, (FItems)vmProcessMergeQueue); @@ -381,8 +273,8 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { tWWorkerFreeQueue(&pMgmt->writePool, pVnode->pWriteQ); + tWWorkerFreeQueue(&pMgmt->applyPool, pVnode->pApplyQ); tWWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ); - tWWorkerFreeQueue(&pMgmt->writePool, pVnode->pApplyQ); tQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ); tQWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ); tWWorkerFreeQueue(&pMgmt->mergePool, pVnode->pMergeQ); @@ -413,6 +305,11 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) { pWPool->max = tsNumOfVnodeWriteThreads; if (tWWorkerInit(pWPool) != 0) return -1; + SWWorkerPool *pAPool = &pMgmt->applyPool; + pAPool->name = "vnode-apply"; + pAPool->max = tsNumOfVnodeWriteThreads; + if (tWWorkerInit(pAPool) != 0) return -1; + SWWorkerPool *pSPool = &pMgmt->syncPool; pSPool->name = "vnode-sync"; pSPool->max = tsNumOfVnodeSyncThreads; @@ -449,6 +346,7 @@ void vmStopWorker(SVnodeMgmt *pMgmt) { tSingleWorkerCleanup(&pMgmt->monitorWorker); tSingleWorkerCleanup(&pMgmt->mgmtWorker); tWWorkerCleanup(&pMgmt->writePool); + tWWorkerCleanup(&pMgmt->applyPool); tWWorkerCleanup(&pMgmt->syncPool); tQWorkerCleanup(&pMgmt->queryPool); tQWorkerCleanup(&pMgmt->fetchPool); diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 8b939d15ce..b66e559370 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -22,17 +22,17 @@ static void dmSendRsp(SRpcMsg *pMsg); static void dmBuildMnodeRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg); static inline int32_t dmBuildNodeMsg(SRpcMsg *pMsg, SRpcMsg *pRpc) { - SRpcConnInfo connInfo = {0}; - if (IsReq(pRpc) && rpcGetConnInfo(pRpc->info.handle, &connInfo) != 0) { - terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; - dError("failed to build msg since %s, app:%p handle:%p", terrstr(), pRpc->info.ahandle, pRpc->info.handle); - return -1; - } + SRpcConnInfo *pConnInfo = &(pRpc->info.connInfo); + // if (IsReq(pRpc)) { + // terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; + // dError("failed to build msg since %s, app:%p handle:%p", terrstr(), pRpc->info.ahandle, pRpc->info.handle); + // return -1; + //} memcpy(pMsg, pRpc, sizeof(SRpcMsg)); - memcpy(pMsg->conn.user, connInfo.user, TSDB_USER_LEN); - pMsg->conn.clientIp = connInfo.clientIp; - pMsg->conn.clientPort = connInfo.clientPort; + memcpy(pMsg->conn.user, pConnInfo->user, TSDB_USER_LEN); + pMsg->conn.clientIp = pConnInfo->clientIp; + pMsg->conn.clientPort = pConnInfo->clientPort; return 0; } @@ -49,9 +49,9 @@ int32_t dmProcessNodeMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) { } static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) { - SDnodeTrans *pTrans = &pDnode->trans; + SDnodeTrans * pTrans = &pDnode->trans; int32_t code = -1; - SRpcMsg *pMsg = NULL; + SRpcMsg * pMsg = NULL; SMgmtWrapper *pWrapper = NULL; SDnodeHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(pRpc->msgType)]; @@ -95,6 +95,8 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) { int32_t vgId = ntohl(pHead->vgId); if (vgId == QNODE_HANDLE) { pWrapper = &pDnode->wrappers[QNODE]; + } else if (vgId == SNODE_HANDLE) { + pWrapper = &pDnode->wrappers[SNODE]; } else if (vgId == MNODE_HANDLE) { pWrapper = &pDnode->wrappers[MNODE]; } else { @@ -131,7 +133,8 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) { _OVER: if (code != 0) { - dTrace("msg:%p, failed to process since %s, type:%s", pMsg, terrstr(), TMSG_INFO(pRpc->msgType)); + dTrace("failed to process msg:%p since %s, handle:%p", pMsg, terrstr(), pRpc->info.handle); + if (terrno != 0) code = terrno; if (IsReq(pRpc)) { @@ -149,8 +152,10 @@ _OVER: } } - dTrace("msg:%p, is freed", pMsg); - taosFreeQitem(pMsg); + if (pMsg != NULL) { + dTrace("msg:%p, is freed", pMsg); + taosFreeQitem(pMsg); + } rpcFreeCont(pRpc->pCont); } @@ -162,11 +167,11 @@ int32_t dmInitMsgHandle(SDnode *pDnode) { for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - SArray *pArray = (*pWrapper->func.getHandlesFp)(); + SArray * pArray = (*pWrapper->func.getHandlesFp)(); if (pArray == NULL) return -1; for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) { - SMgmtHandle *pMgmt = taosArrayGet(pArray, i); + SMgmtHandle * pMgmt = taosArrayGet(pArray, i); SDnodeHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(pMgmt->msgType)]; if (pMgmt->needCheckVgId) { pHandle->needCheckVgId = pMgmt->needCheckVgId; diff --git a/source/dnode/mgmt/node_util/src/dmEps.c b/source/dnode/mgmt/node_util/src/dmEps.c index 937c1ab7fa..6f6896ff9f 100644 --- a/source/dnode/mgmt/node_util/src/dmEps.c +++ b/source/dnode/mgmt/node_util/src/dmEps.c @@ -318,9 +318,9 @@ void dmGetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet) { void dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet) { dmGetMnodeEpSet(pData, pEpSet); - dDebug("msg:%p, is redirected, num:%d use:%d", pMsg, pEpSet->numOfEps, pEpSet->inUse); + dTrace("msg is redirected, handle:%p num:%d use:%d", pMsg->info.handle, pEpSet->numOfEps, pEpSet->inUse); for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { - dDebug("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port); + dTrace("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port); if (strcmp(pEpSet->eps[i].fqdn, tsLocalFqdn) == 0 && pEpSet->eps[i].port == tsServerPort) { pEpSet->inUse = (i + 1) % pEpSet->numOfEps; } diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 8ea172ef94..382f8dd55f 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -309,6 +309,7 @@ typedef struct { int8_t slidingUnit; int8_t timezone; int32_t dstVgId; // for stream + int64_t dstTbUid; int64_t interval; int64_t offset; int64_t sliding; diff --git a/source/dnode/mnode/impl/inc/mndDnode.h b/source/dnode/mnode/impl/inc/mndDnode.h index c76186c0a2..cf1e7422be 100644 --- a/source/dnode/mnode/impl/inc/mndDnode.h +++ b/source/dnode/mnode/impl/inc/mndDnode.h @@ -28,7 +28,7 @@ SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId); void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode); SEpSet mndGetDnodeEpset(SDnodeObj *pDnode); int32_t mndGetDnodeSize(SMnode *pMnode); -bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs); +bool mndIsDnodeOnline(SDnodeObj *pDnode, int64_t curMs); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndMnode.h b/source/dnode/mnode/impl/inc/mndMnode.h index fd62b3ce75..a433af9947 100644 --- a/source/dnode/mnode/impl/inc/mndMnode.h +++ b/source/dnode/mnode/impl/inc/mndMnode.h @@ -28,6 +28,7 @@ SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId); void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj); bool mndIsMnode(SMnode *pMnode, int32_t dnodeId); void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet); +int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index 736fa3b361..5ac9d2233f 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -36,19 +36,19 @@ typedef enum { } ETrnAct; typedef struct { - int32_t id; - int32_t errCode; - int32_t acceptableCode; - int8_t stage; - ETrnAct actionType; - int8_t rawWritten; - int8_t msgSent; - int8_t msgReceived; - tmsg_t msgType; - SEpSet epSet; - int32_t contLen; - void *pCont; - SSdbRaw *pRaw; + int32_t id; + int32_t errCode; + int32_t acceptableCode; + ETrnStage stage; + ETrnAct actionType; + int8_t rawWritten; + int8_t msgSent; + int8_t msgReceived; + tmsg_t msgType; + SEpSet epSet; + int32_t contLen; + void *pCont; + SSdbRaw *pRaw; } STransAction; typedef void (*TransCbFp)(SMnode *pMnode, void *param, int32_t paramLen); diff --git a/source/dnode/mnode/impl/inc/mndVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h index 2119320de5..89f93d30b5 100644 --- a/source/dnode/mnode/impl/inc/mndVgroup.h +++ b/source/dnode/mnode/impl/inc/mndVgroup.h @@ -30,15 +30,21 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup); SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup); int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId); -int32_t mndAllocSmaVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup); -int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups); -SArray *mndBuildDnodesArray(SMnode *pMnode); -int32_t mndAddVnodeToVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray); -int32_t mndRemoveVnodeFromVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray, SVnodeGid *pVgId); +SArray *mndBuildDnodesArray(SMnode *, int32_t exceptDnodeId); +int32_t mndAllocSmaVgroup(SMnode *, SDbObj *pDb, SVgObj *pVgroup); +int32_t mndAllocVgroup(SMnode *, SDbObj *pDb, SVgObj **ppVgroups); +int32_t mndAddVnodeToVgroup(SMnode *, SVgObj *pVgroup, SArray *pArray); +int32_t mndRemoveVnodeFromVgroup(SMnode *, SVgObj *pVgroup, SArray *pArray, SVnodeGid *pDelVgid); +int32_t mndAddCreateVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, bool standby); +int32_t mndAddAlterVnodeConfirmAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup); +int32_t mndAddAlterVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, tmsg_t msgType); +int32_t mndAddDropVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, bool isRedo); +int32_t mndSetMoveVgroupInfoToTrans(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t vn, SArray *pArray); +int32_t mndSetMoveVgroupsInfoToTrans(SMnode *, STrans *pTrans, int32_t dropDnodeId); -void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen, bool standby); -void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen); -void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen); +void *mndBuildCreateVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *cntlen, bool standby); +void *mndBuildDropVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen); +void *mndBuildAlterVnodeReq(SMnode *, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index 38a166900d..ed07e15c63 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -299,7 +299,7 @@ static int32_t mndProcessCreateBnodeReq(SRpcMsg *pReq) { goto _OVER; } - if (mndCheckNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser) != 0) { goto _OVER; } @@ -409,7 +409,7 @@ static int32_t mndProcessDropBnodeReq(SRpcMsg *pReq) { goto _OVER; } - if (mndCheckNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser) != 0) { goto _OVER; } diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 1f8bf06993..7f3c0a9fa8 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -92,6 +92,15 @@ static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg) { SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pLostMsg->consumerId); ASSERT(pConsumer); + + mInfo("receive consumer lost msg, consumer id %ld, status %s", pLostMsg->consumerId, + mndConsumerStatusName(pConsumer->status)); + + if (pConsumer->status != MQ_CONSUMER_STATUS__READY) { + mndReleaseConsumer(pMnode, pConsumer); + return -1; + } + SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup); pConsumerNew->updateType = CONSUMER_UPDATE__LOST; diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 1ce1a2590a..61d6e7be6c 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -263,111 +263,6 @@ void mndReleaseDb(SMnode *pMnode, SDbObj *pDb) { sdbRelease(pSdb, pDb); } -static int32_t mndAddCreateVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, - bool standby) { - STransAction action = {0}; - - SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); - if (pDnode == NULL) return -1; - action.epSet = mndGetDnodeEpset(pDnode); - mndReleaseDnode(pMnode, pDnode); - - int32_t contLen = 0; - void *pReq = mndBuildCreateVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen, standby); - if (pReq == NULL) return -1; - - action.pCont = pReq; - action.contLen = contLen; - action.msgType = TDMT_DND_CREATE_VNODE; - action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED; - - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(pReq); - return -1; - } - - return 0; -} - -static int32_t mndAddAlterVnodeConfirmAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) { - STransAction action = {0}; - action.epSet = mndGetVgroupEpset(pMnode, pVgroup); - - int32_t contLen = sizeof(SMsgHead); - SMsgHead *pHead = taosMemoryMalloc(contLen); - if (pHead == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - pHead->contLen = htonl(contLen); - pHead->vgId = htonl(pVgroup->vgId); - - action.pCont = pHead; - action.contLen = contLen; - action.msgType = TDMT_VND_ALTER_CONFIRM; - - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(pHead); - return -1; - } - - return 0; -} - -static int32_t mndAddAlterVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, tmsg_t msgType) { - STransAction action = {0}; - action.epSet = mndGetVgroupEpset(pMnode, pVgroup); - - int32_t contLen = 0; - void *pReq = mndBuildAlterVnodeReq(pMnode, pDb, pVgroup, &contLen); - if (pReq == NULL) return -1; - - action.pCont = pReq; - action.contLen = contLen; - action.msgType = msgType; - - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(pReq); - return -1; - } - - return 0; -} - -static int32_t mndAddDropVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, - bool isRedo) { - STransAction action = {0}; - - SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); - if (pDnode == NULL) return -1; - action.epSet = mndGetDnodeEpset(pDnode); - mndReleaseDnode(pMnode, pDnode); - - int32_t contLen = 0; - void *pReq = mndBuildDropVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen); - if (pReq == NULL) return -1; - - action.pCont = pReq; - action.contLen = contLen; - action.msgType = TDMT_DND_DROP_VNODE; - action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED; - - if (isRedo) { - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(pReq); - return -1; - } - } else { - if (mndTransAppendUndoAction(pTrans, &action) != 0) { - taosMemoryFree(pReq); - return -1; - } - } - - return 0; -} - static int32_t mndCheckDbName(const char *dbName, SUserObj *pUser) { char *pos = strstr(dbName, TS_PATH_DELIMITER); if (pos == NULL) { @@ -795,7 +690,7 @@ static int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOld, SDbObj *pNew) { SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; - SArray *pArray = mndBuildDnodesArray(pMnode); + SArray *pArray = mndBuildDnodesArray(pMnode, 0); while (1) { SVgObj *pVgroup = NULL; @@ -1497,20 +1392,26 @@ char *buildRetension(SArray *pRetension) { int64_t v1 = getValOfDiffPrecision(p->freqUnit, p->freq); int64_t v2 = getValOfDiffPrecision(p->keepUnit, p->keep); - len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c,", v1, p->freqUnit, v2, p->keepUnit); - - p = taosArrayGet(pRetension, 1); - - v1 = getValOfDiffPrecision(p->freqUnit, p->freq); - v2 = getValOfDiffPrecision(p->keepUnit, p->keep); - len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c,", v1, p->freqUnit, v2, p->keepUnit); - - p = taosArrayGet(pRetension, 2); - - v1 = getValOfDiffPrecision(p->freqUnit, p->freq); - v2 = getValOfDiffPrecision(p->keepUnit, p->keep); len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit); + if (size > 1) { + len += sprintf(p1 + len, ","); + p = taosArrayGet(pRetension, 1); + + v1 = getValOfDiffPrecision(p->freqUnit, p->freq); + v2 = getValOfDiffPrecision(p->keepUnit, p->keep); + len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit); + } + + if (size > 2) { + len += sprintf(p1 + len, ","); + p = taosArrayGet(pRetension, 2); + + v1 = getValOfDiffPrecision(p->freqUnit, p->freq); + v2 = getValOfDiffPrecision(p->keepUnit, p->keep); + len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit); + } + varDataSetLen(p1, len); return p1; } @@ -1742,3 +1643,4 @@ static void mndCancelGetNextDb(SMnode *pMnode, void *pIter) { SSdb *pSdb = pMnode->pSdb; sdbCancelFetch(pSdb, pIter); } + diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index aeff018aa8..7be4939337 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -87,6 +87,10 @@ int32_t mndInitDnode(SMnode *pMnode) { void mndCleanupDnode(SMnode *pMnode) {} static int32_t mndCreateDefaultDnode(SMnode *pMnode) { + int32_t code = -1; + SSdbRaw *pRaw = NULL; + STrans *pTrans = NULL; + SDnodeObj dnodeObj = {0}; dnodeObj.id = 1; dnodeObj.createdTime = taosGetTimestampMs(); @@ -95,54 +99,42 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) { memcpy(&dnodeObj.fqdn, pMnode->replicas[0].fqdn, TSDB_FQDN_LEN); snprintf(dnodeObj.ep, TSDB_EP_LEN, "%s:%u", dnodeObj.fqdn, dnodeObj.port); - SSdbRaw *pRaw = mndDnodeActionEncode(&dnodeObj); - if (pRaw == NULL) return -1; - if (sdbSetRawStatus(pRaw, SDB_STATUS_READY) != 0) return -1; + pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, NULL); + if (pTrans == NULL) goto _OVER; + mDebug("trans:%d, used to create dnode:%s on first deploy", pTrans->id, dnodeObj.ep); - mDebug("dnode:%d, will be created when deploying, raw:%p", dnodeObj.id, pRaw); - - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, NULL); - if (pTrans == NULL) { - mError("dnode:%s, failed to create since %s", dnodeObj.ep, terrstr()); - return -1; - } - mDebug("trans:%d, used to create dnode:%s", pTrans->id, dnodeObj.ep); - - if (mndTransAppendCommitlog(pTrans, pRaw) != 0) { - mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } + pRaw = mndDnodeActionEncode(&dnodeObj); + if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER; sdbSetRawStatus(pRaw, SDB_STATUS_READY); + pRaw = NULL; - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } + if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + code = 0; +_OVER: mndTransDrop(pTrans); - return 0; + sdbFreeRaw(pRaw); + return code; } static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) { terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER_NUMBER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE); - if (pRaw == NULL) goto DNODE_ENCODE_OVER; + if (pRaw == NULL) goto _OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pDnode->id, DNODE_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pDnode->createdTime, DNODE_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime, DNODE_ENCODE_OVER) - SDB_SET_INT16(pRaw, dataPos, pDnode->port, DNODE_ENCODE_OVER) - SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, DNODE_ENCODE_OVER) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, DNODE_ENCODE_OVER) - SDB_SET_DATALEN(pRaw, dataPos, DNODE_ENCODE_OVER); + SDB_SET_INT32(pRaw, dataPos, pDnode->id, _OVER) + SDB_SET_INT64(pRaw, dataPos, pDnode->createdTime, _OVER) + SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime, _OVER) + SDB_SET_INT16(pRaw, dataPos, pDnode->port, _OVER) + SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, _OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, _OVER) + SDB_SET_DATALEN(pRaw, dataPos, _OVER); terrno = 0; -DNODE_ENCODE_OVER: +_OVER: if (terrno != 0) { mError("dnode:%d, failed to encode to raw:%p since %s", pDnode->id, pRaw, terrstr()); sdbFreeRaw(pRaw); @@ -154,33 +146,32 @@ DNODE_ENCODE_OVER: } static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) { + SSdbRow *pRow = NULL; terrno = TSDB_CODE_OUT_OF_MEMORY; int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto DNODE_DECODE_OVER; - + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER; if (sver != TSDB_DNODE_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - goto DNODE_DECODE_OVER; + goto _OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(SDnodeObj)); - if (pRow == NULL) goto DNODE_DECODE_OVER; - + pRow = sdbAllocRow(sizeof(SDnodeObj)); + if (pRow == NULL) goto _OVER; SDnodeObj *pDnode = sdbGetRowObj(pRow); - if (pDnode == NULL) goto DNODE_DECODE_OVER; + if (pDnode == NULL) goto _OVER; int32_t dataPos = 0; - SDB_GET_INT32(pRaw, dataPos, &pDnode->id, DNODE_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pDnode->createdTime, DNODE_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pDnode->updateTime, DNODE_DECODE_OVER) - SDB_GET_INT16(pRaw, dataPos, &pDnode->port, DNODE_DECODE_OVER) - SDB_GET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, DNODE_DECODE_OVER) - SDB_GET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, DNODE_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDnode->id, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pDnode->createdTime, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pDnode->updateTime, _OVER) + SDB_GET_INT16(pRaw, dataPos, &pDnode->port, _OVER) + SDB_GET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, _OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, _OVER) terrno = 0; -DNODE_DECODE_OVER: +_OVER: if (terrno != 0) { mError("dnode:%d, failed to decode from raw:%p since %s", pDnode->id, pRaw, terrstr()); taosMemoryFreeClear(pRow); @@ -246,6 +237,7 @@ static SDnodeObj *mndAcquireDnodeByEp(SMnode *pMnode, char *pEpStr) { sdbRelease(pSdb, pDnode); } + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; return NULL; } @@ -254,7 +246,7 @@ int32_t mndGetDnodeSize(SMnode *pMnode) { return sdbGetSize(pSdb, SDB_DNODE); } -bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs) { +bool mndIsDnodeOnline(SDnodeObj *pDnode, int64_t curMs) { int64_t interval = TABS(pDnode->lastAccessTime - curMs); if (interval > 5000 * tsStatusInterval) { if (pDnode->rebootTime > 0) { @@ -290,25 +282,26 @@ static void mndGetDnodeData(SMnode *pMnode, SArray *pDnodeEps) { } } -static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) { +static int32_t mndCheckClusterCfgPara(SMnode *pMnode, SDnodeObj *pDnode, const SClusterCfg *pCfg) { if (pCfg->statusInterval != tsStatusInterval) { - mError("statusInterval [%d - %d] cfg inconsistent", pCfg->statusInterval, tsStatusInterval); + mError("dnode:%d, statusInterval:%d inconsistent with cluster:%d", pDnode->id, pCfg->statusInterval, + tsStatusInterval); return DND_REASON_STATUS_INTERVAL_NOT_MATCH; } if ((0 != strcasecmp(pCfg->timezone, tsTimezoneStr)) && (pMnode->checkTime != pCfg->checkTime)) { - mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezoneStr, - pCfg->checkTime, pMnode->checkTime); + mError("dnode:%d, timezone:%s checkTime:%" PRId64 " inconsistent with cluster %s %" PRId64, pDnode->id, + pCfg->timezone, pCfg->checkTime, tsTimezoneStr, pMnode->checkTime); return DND_REASON_TIME_ZONE_NOT_MATCH; } if (0 != strcasecmp(pCfg->locale, tsLocale)) { - mError("locale [%s - %s] cfg inconsistent", pCfg->locale, tsLocale); + mError("dnode:%d, locale:%s inconsistent with cluster:%s", pDnode->id, pCfg->locale, tsLocale); return DND_REASON_LOCALE_NOT_MATCH; } if (0 != strcasecmp(pCfg->charset, tsCharset)) { - mError("charset [%s - %s] cfg inconsistent.", pCfg->charset, tsCharset); + mError("dnode:%d, charset:%s inconsistent with cluster:%s", pDnode->id, pCfg->charset, tsCharset); return DND_REASON_CHARSET_NOT_MATCH; } @@ -323,15 +316,14 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { if (tDeserializeSStatusReq(pReq->pCont, pReq->contLen, &statusReq) != 0) { terrno = TSDB_CODE_INVALID_MSG; - goto PROCESS_STATUS_MSG_OVER; + goto _OVER; } if (statusReq.dnodeId == 0) { pDnode = mndAcquireDnodeByEp(pMnode, statusReq.dnodeEp); if (pDnode == NULL) { mDebug("dnode:%s, not created yet", statusReq.dnodeEp); - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; - goto PROCESS_STATUS_MSG_OVER; + goto _OVER; } } else { pDnode = mndAcquireDnode(pMnode, statusReq.dnodeId); @@ -341,13 +333,11 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { pDnode->offlineReason = DND_REASON_DNODE_ID_NOT_MATCH; } mError("dnode:%d, %s not exist", statusReq.dnodeId, statusReq.dnodeEp); - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; - goto PROCESS_STATUS_MSG_OVER; + goto _OVER; } } - int32_t numOfVloads = (int32_t)taosArrayGetSize(statusReq.pVloads); - for (int32_t v = 0; v < numOfVloads; ++v) { + for (int32_t v = 0; v < taosArrayGetSize(statusReq.pVloads); ++v) { SVnodeLoad *pVload = taosArrayGet(statusReq.pVloads, v); SVgObj *pVgroup = mndAcquireVgroup(pMnode, pVload->vgId); @@ -366,6 +356,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { roleChanged = true; } pVgroup->vnodeGid[vg].role = pVload->syncState; + break; } } if (roleChanged) { @@ -393,7 +384,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { int64_t dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE) + sdbGetTableVer(pMnode->pSdb, SDB_MNODE); int64_t curMs = taosGetTimestampMs(); - bool online = mndIsDnodeOnline(pMnode, pDnode, curMs); + bool online = mndIsDnodeOnline(pDnode, curMs); bool dnodeChanged = (statusReq.dnodeVer != dnodeVer); bool reboot = (pDnode->rebootTime != statusReq.rebootTime); bool needCheck = !online || dnodeChanged || reboot; @@ -405,11 +396,11 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { } mError("dnode:%d, status msg version:%d not match cluster:%d", statusReq.dnodeId, statusReq.sver, tsVersion); terrno = TSDB_CODE_VERSION_NOT_COMPATIBLE; - goto PROCESS_STATUS_MSG_OVER; + goto _OVER; } if (statusReq.dnodeId == 0) { - mDebug("dnode:%d, %s first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId); + mInfo("dnode:%d, %s first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId); } else { if (statusReq.clusterId != pMnode->clusterId) { if (pDnode != NULL) { @@ -418,7 +409,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { mError("dnode:%d, clusterId %" PRId64 " not match exist %" PRId64, pDnode->id, statusReq.clusterId, pMnode->clusterId); terrno = TSDB_CODE_MND_INVALID_CLUSTER_ID; - goto PROCESS_STATUS_MSG_OVER; + goto _OVER; } else { pDnode->accessTimes++; mTrace("dnode:%d, status received, access times %d", pDnode->id, pDnode->accessTimes); @@ -426,18 +417,17 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { } // Verify whether the cluster parameters are consistent when status change from offline to ready - int32_t ret = mndCheckClusterCfgPara(pMnode, &statusReq.clusterCfg); - if (0 != ret) { - pDnode->offlineReason = ret; - mError("dnode:%d, cluster cfg inconsistent since:%s", pDnode->id, offlineReason[ret]); + pDnode->offlineReason = mndCheckClusterCfgPara(pMnode, pDnode, &statusReq.clusterCfg); + if (pDnode->offlineReason != 0) { + mError("dnode:%d, cluster cfg inconsistent since:%s", pDnode->id, offlineReason[pDnode->offlineReason]); terrno = TSDB_CODE_MND_INVALID_CLUSTER_CFG; - goto PROCESS_STATUS_MSG_OVER; + goto _OVER; } if (!online) { mInfo("dnode:%d, from offline to online", pDnode->id); } else { - mDebug("dnode:%d, send dnode epset, online:%d ver:% " PRId64 ":%" PRId64 " reboot:%d", pDnode->id, online, + mDebug("dnode:%d, send dnode epset, online:%d dnode_ver:%" PRId64 ":%" PRId64 " reboot:%d", pDnode->id, online, statusReq.dnodeVer, dnodeVer, reboot); } @@ -452,7 +442,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { statusRsp.pDnodeEps = taosArrayInit(mndGetDnodeSize(pMnode), sizeof(SDnodeEp)); if (statusRsp.pDnodeEps == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - goto PROCESS_STATUS_MSG_OVER; + goto _OVER; } mndGetDnodeData(pMnode, statusRsp.pDnodeEps); @@ -469,13 +459,17 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { pDnode->lastAccessTime = curMs; code = 0; -PROCESS_STATUS_MSG_OVER: +_OVER: mndReleaseDnode(pMnode, pDnode); taosArrayDestroy(statusReq.pVloads); return code; } static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pCreate) { + int32_t code = -1; + SSdbRaw *pRaw = NULL; + STrans *pTrans = NULL; + SDnodeObj dnodeObj = {0}; dnodeObj.id = sdbGetMaxId(pMnode->pSdb, SDB_DNODE); dnodeObj.createdTime = taosGetTimestampMs(); @@ -484,29 +478,22 @@ static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pC memcpy(dnodeObj.fqdn, pCreate->fqdn, TSDB_FQDN_LEN); snprintf(dnodeObj.ep, TSDB_EP_LEN, "%s:%u", dnodeObj.fqdn, dnodeObj.port); - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_GLOBAL, pReq); - if (pTrans == NULL) { - mError("dnode:%s, failed to create since %s", dnodeObj.ep, terrstr()); - return -1; - } + pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_GLOBAL, pReq); + if (pTrans == NULL) goto _OVER; mDebug("trans:%d, used to create dnode:%s", pTrans->id, dnodeObj.ep); - SSdbRaw *pCommitRaw = mndDnodeActionEncode(&dnodeObj); - if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { - mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } - sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); + pRaw = mndDnodeActionEncode(&dnodeObj); + if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER; + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + pRaw = NULL; - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } + if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + code = 0; +_OVER: mndTransDrop(pTrans); - return 0; + sdbFreeRaw(pRaw); + return code; } static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) { @@ -518,38 +505,37 @@ static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) { if (tDeserializeSCreateDnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) { terrno = TSDB_CODE_INVALID_MSG; - goto CREATE_DNODE_OVER; + goto _OVER; } mDebug("dnode:%s:%d, start to create", createReq.fqdn, createReq.port); if (createReq.fqdn[0] == 0 || createReq.port <= 0 || createReq.port > UINT16_MAX) { terrno = TSDB_CODE_MND_INVALID_DNODE_EP; - goto CREATE_DNODE_OVER; + goto _OVER; } char ep[TSDB_EP_LEN]; snprintf(ep, TSDB_EP_LEN, "%s:%d", createReq.fqdn, createReq.port); pDnode = mndAcquireDnodeByEp(pMnode, ep); if (pDnode != NULL) { - terrno = TSDB_CODE_MND_DNODE_ALREADY_EXIST; - goto CREATE_DNODE_OVER; + goto _OVER; } pUser = mndAcquireUser(pMnode, pReq->conn.user); if (pUser == NULL) { terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; - goto CREATE_DNODE_OVER; + goto _OVER; } - if (mndCheckNodeAuth(pUser)) { - goto CREATE_DNODE_OVER; + if (mndCheckNodeAuth(pUser) != 0) { + goto _OVER; } code = mndCreateDnode(pMnode, pReq, &createReq); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; -CREATE_DNODE_OVER: +_OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("dnode:%s:%d, failed to create since %s", createReq.fqdn, createReq.port, terrstr()); } @@ -559,30 +545,40 @@ CREATE_DNODE_OVER: return code; } -static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_GLOBAL, pReq); - if (pTrans == NULL) { - mError("dnode:%d, failed to drop since %s", pDnode->id, terrstr()); - return -1; - } +static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMnodeObj *pMObj, int32_t numOfVnodes) { + int32_t code = -1; + SSdbRaw *pRaw = NULL; + STrans *pTrans = NULL; + + pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq); + if (pTrans == NULL) goto _OVER; + mndTransSetSerial(pTrans); mDebug("trans:%d, used to drop dnode:%d", pTrans->id, pDnode->id); - SSdbRaw *pCommitRaw = mndDnodeActionEncode(pDnode); - if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { - mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } - sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED); + pRaw = mndDnodeActionEncode(pDnode); + if (pRaw == NULL || mndTransAppendRedolog(pTrans, pRaw) != 0) goto _OVER; + sdbSetRawStatus(pRaw, SDB_STATUS_DROPPING); + pRaw = NULL; - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } + pRaw = mndDnodeActionEncode(pDnode); + if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER; + sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED); + pRaw = NULL; + if (pMObj != NULL) { + if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pMObj) != 0) goto _OVER; + } + if (numOfVnodes > 0) { + if (mndSetMoveVgroupsInfoToTrans(pMnode, pTrans, pDnode->id) != 0) goto _OVER; + } + if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + + code = 0; + +_OVER: mndTransDrop(pTrans); - return 0; + sdbFreeRaw(pRaw); + return code; } static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) { @@ -595,42 +591,58 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) { if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { terrno = TSDB_CODE_INVALID_MSG; - goto DROP_DNODE_OVER; + goto _OVER; } mDebug("dnode:%d, start to drop", dropReq.dnodeId); if (dropReq.dnodeId <= 0) { terrno = TSDB_CODE_MND_INVALID_DNODE_ID; - goto DROP_DNODE_OVER; + goto _OVER; } pDnode = mndAcquireDnode(pMnode, dropReq.dnodeId); if (pDnode == NULL) { terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; - goto DROP_DNODE_OVER; + goto _OVER; } pMObj = mndAcquireMnode(pMnode, dropReq.dnodeId); if (pMObj != NULL) { - terrno = TSDB_CODE_MND_MNODE_NOT_EXIST; - goto DROP_DNODE_OVER; + if (sdbGetSize(pMnode->pSdb, SDB_MNODE) <= 1) { + terrno = TSDB_CODE_MND_TOO_FEW_MNODES; + goto _OVER; + } + if (pMnode->selfDnodeId == dropReq.dnodeId) { + terrno = TSDB_CODE_MND_CANT_DROP_LEADER; + goto _OVER; + } + } + + int32_t numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id); + if (numOfVnodes > 0 || pMObj != NULL) { + if (!mndIsDnodeOnline(pDnode, taosGetTimestampMs())) { + terrno = TSDB_CODE_NODE_OFFLINE; + mError("dnode:%d, failed to drop since %s, has_mnode:%d numOfVnodes:%d", pDnode->id, terrstr(), pMObj != NULL, + numOfVnodes); + goto _OVER; + } } pUser = mndAcquireUser(pMnode, pReq->conn.user); if (pUser == NULL) { terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; - goto DROP_DNODE_OVER; + goto _OVER; } - if (mndCheckNodeAuth(pUser)) { - goto DROP_DNODE_OVER; + if (mndCheckNodeAuth(pUser) != 0) { + goto _OVER; } - code = mndDropDnode(pMnode, pReq, pDnode); + code = mndDropDnode(pMnode, pReq, pDnode, pMObj, numOfVnodes); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; -DROP_DNODE_OVER: +_OVER: if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("dnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr()); } @@ -638,7 +650,6 @@ DROP_DNODE_OVER: mndReleaseDnode(pMnode, pDnode); mndReleaseUser(pMnode, pUser); mndReleaseMnode(pMnode, pMObj); - return code; } @@ -653,7 +664,6 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { SDnodeObj *pDnode = mndAcquireDnode(pMnode, cfgReq.dnodeId); if (pDnode == NULL) { - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; mError("dnode:%d, failed to config since %s ", cfgReq.dnodeId, terrstr()); return -1; } @@ -663,17 +673,18 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { int32_t bufLen = tSerializeSMCfgDnodeReq(NULL, 0, &cfgReq); void *pBuf = rpcMallocCont(bufLen); + + if (pBuf == NULL) return -1; tSerializeSMCfgDnodeReq(pBuf, bufLen, &cfgReq); + mDebug("dnode:%d, send config req to dnode, app:%p", cfgReq.dnodeId, pReq->info.ahandle); SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pBuf, .contLen = bufLen, .info = pReq->info}; - - mDebug("dnode:%d, send config req to dnode, app:%p", cfgReq.dnodeId, rpcMsg.info.ahandle); return tmsgSendReq(&epSet, &rpcMsg); } static int32_t mndProcessConfigDnodeRsp(SRpcMsg *pRsp) { mDebug("config rsp from dnode, app:%p", pRsp->info.ahandle); - return TSDB_CODE_SUCCESS; + return 0; } static int32_t mndRetrieveConfigs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { @@ -682,7 +693,7 @@ static int32_t mndRetrieveConfigs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p int32_t numOfRows = 0; char *cfgOpts[TSDB_CONFIG_NUMBER] = {0}; char cfgVals[TSDB_CONFIG_NUMBER][TSDB_CONIIG_VALUE_LEN + 1] = {0}; - char *pWrite; + char *pWrite = NULL; int32_t cols = 0; cfgOpts[totalRows] = "statusInterval"; @@ -708,7 +719,6 @@ static int32_t mndRetrieveConfigs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p cols = 0; STR_WITH_MAXSIZE_TO_VARSTR(buf, cfgOpts[i], TSDB_CONFIG_OPTION_LEN); - SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)buf, false); @@ -736,7 +746,7 @@ static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB while (numOfRows < rows) { pShow->pIter = sdbFetch(pSdb, SDB_DNODE, pShow->pIter, (void **)&pDnode); if (pShow->pIter == NULL) break; - bool online = mndIsDnodeOnline(pMnode, pDnode, curMs); + bool online = mndIsDnodeOnline(pDnode, curMs); cols = 0; @@ -758,7 +768,6 @@ static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB char b1[9] = {0}; STR_TO_VARSTR(b1, online ? "ready" : "offline"); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, b1, false); @@ -776,7 +785,6 @@ static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB } pShow->numOfRows += numOfRows; - return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index d989ba6ec3..69300c0889 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -529,7 +529,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr SMonDnodeDesc desc = {0}; desc.dnode_id = pObj->id; tstrncpy(desc.dnode_ep, pObj->ep, sizeof(desc.dnode_ep)); - if (mndIsDnodeOnline(pMnode, pObj, ms)) { + if (mndIsDnodeOnline(pObj, ms)) { tstrncpy(desc.status, "ready", sizeof(desc.status)); } else { tstrncpy(desc.status, "offline", sizeof(desc.status)); diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 1cc832b3af..027de66b42 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -358,9 +358,9 @@ static int32_t mndCreateMnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq); if (pTrans == NULL) goto _OVER; - - mDebug("trans:%d, used to create mnode:%d", pTrans->id, pCreate->dnodeId); mndTransSetSerial(pTrans); + mDebug("trans:%d, used to create mnode:%d", pTrans->id, pCreate->dnodeId); + 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; @@ -408,7 +408,7 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) { goto _OVER; } - if (!mndIsDnodeOnline(pMnode, pDnode, taosGetTimestampMs())) { + if (!mndIsDnodeOnline(pDnode, taosGetTimestampMs())) { terrno = TSDB_CODE_NODE_OFFLINE; goto _OVER; } @@ -419,7 +419,7 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) { goto _OVER; } - if (mndCheckNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser) != 0) { goto _OVER; } @@ -535,18 +535,25 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode return 0; } +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; + return 0; +} + static int32_t mndDropMnode(SMnode *pMnode, SRpcMsg *pReq, SMnodeObj *pObj) { int32_t code = -1; + STrans *pTrans = NULL; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq); + pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq); if (pTrans == NULL) goto _OVER; - - mDebug("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id); mndTransSetSerial(pTrans); - if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) goto _OVER; - if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) goto _OVER; - if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj) != 0) goto _OVER; - if (mndTransAppendNullLog(pTrans) != 0) goto _OVER; + mDebug("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id); + + if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pObj) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; code = 0; @@ -581,7 +588,7 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) { } if (pMnode->selfDnodeId == dropReq.dnodeId) { - terrno = TSDB_CODE_MND_CANT_DROP_MASTER; + terrno = TSDB_CODE_MND_CANT_DROP_LEADER; goto _OVER; } @@ -596,7 +603,7 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) { goto _OVER; } - if (mndCheckNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser) != 0) { goto _OVER; } @@ -642,7 +649,7 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB if (pObj->id == pMnode->selfDnodeId) { roles = syncStr(TAOS_SYNC_STATE_LEADER); } - if (pObj->pDnode && mndIsDnodeOnline(pMnode, pObj->pDnode, curMs)) { + if (pObj->pDnode && mndIsDnodeOnline(pObj->pDnode, curMs)) { roles = syncStr(pObj->state); } char b2[12 + VARSTR_HEADER_SIZE] = {0}; diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 4fb9226144..aac6eaba47 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -301,7 +301,7 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) { goto _OVER; } - if (mndCheckNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser) != 0) { goto _OVER; } @@ -411,7 +411,7 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) { goto _OVER; } - if (mndCheckNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser) != 0) { goto _OVER; } diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index b390a7fe4a..3d5dab1894 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -132,7 +132,7 @@ int32_t mndAssignTaskToVg(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SS terrno = TSDB_CODE_QRY_INVALID_INPUT; return -1; } - mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId); + mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_STREAM_TASK_DEPLOY, pVgroup->vgId); return 0; } @@ -156,7 +156,7 @@ int32_t mndAssignTaskToSnode(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, terrno = TSDB_CODE_QRY_INVALID_INPUT; return -1; } - mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_SND_TASK_DEPLOY, 0); + mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_STREAM_TASK_DEPLOY, 0); return 0; } @@ -190,7 +190,7 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p sdbRelease(pSdb, pVgroup); continue; } - SStreamTask* pTask = tNewSStreamTask(pStream->uid); + SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0); if (pTask == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -222,7 +222,7 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p // dispatch pTask->dispatchType = TASK_DISPATCH__NONE; - mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId); + mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_STREAM_TASK_DEPLOY, pVgroup->vgId); } return 0; } @@ -230,7 +230,7 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { ASSERT(pStream->fixedSinkVgId != 0); SArray* tasks = taosArrayGetP(pStream->tasks, 0); - SStreamTask* pTask = tNewSStreamTask(pStream->uid); + SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0); if (pTask == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -267,8 +267,7 @@ int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStr // dispatch pTask->dispatchType = TASK_DISPATCH__NONE; - /*mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId);*/ - mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pStream->fixedSinkVg.vgId); + mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_STREAM_TASK_DEPLOY, pStream->fixedSinkVg.vgId); return 0; } @@ -322,7 +321,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { sdbRelease(pSdb, pVgroup); continue; } - SStreamTask* pTask = tNewSStreamTask(pStream->uid); + SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0); // source part pTask->sourceType = TASK_SOURCE__SCAN; pTask->inputType = TASK_INPUT_TYPE__SUMBIT_BLOCK; @@ -361,7 +360,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { ASSERT(taosArrayGetSize(pArray) == 1); SStreamTask* lastLevelTask = taosArrayGetP(pArray, 0); /*pTask->dispatchMsgType = TDMT_VND_TASK_MERGE_EXEC;*/ - pTask->dispatchMsgType = TDMT_VND_TASK_DISPATCH; + pTask->dispatchMsgType = TDMT_STREAM_TASK_DISPATCH; pTask->dispatchType = TASK_DISPATCH__FIXED; pTask->fixedEpDispatcher.taskId = lastLevelTask->taskId; @@ -387,7 +386,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { // else, assign to vnode ASSERT(plan->subplanType == SUBPLAN_TYPE_MERGE); - SStreamTask* pTask = tNewSStreamTask(pStream->uid); + SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0); // source part, currently only support multi source pTask->sourceType = TASK_SOURCE__PIPE; @@ -407,7 +406,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { pTask->dispatchType = TASK_DISPATCH__SHUFFLE; /*pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC;*/ - pTask->dispatchMsgType = TDMT_VND_TASK_DISPATCH; + pTask->dispatchMsgType = TDMT_STREAM_TASK_DISPATCH; SDbObj* pDb = mndAcquireDb(pMnode, pStream->targetDb); ASSERT(pDb); if (mndExtractDbInfo(pMnode, pDb, &pTask->shuffleDispatcher.dbInfo, NULL) < 0) { @@ -438,7 +437,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { } else { pTask->dispatchType = TASK_DISPATCH__FIXED; /*pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC;*/ - pTask->dispatchMsgType = TDMT_VND_TASK_DISPATCH; + pTask->dispatchMsgType = TDMT_STREAM_TASK_DISPATCH; SArray* pArray = taosArrayGetP(pStream->tasks, 0); // one sink only ASSERT(taosArrayGetSize(pArray) == 1); @@ -477,7 +476,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { sdbRelease(pSdb, pVgroup); continue; } - SStreamTask* pTask = tNewSStreamTask(pStream->uid); + SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0); // source part pTask->sourceType = TASK_SOURCE__MERGE; diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 6b70825ed4..6e569a04cc 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -266,7 +266,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { } size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns + - blockDataGetSize(pBlock) + blockDataGetSerialMetaSize(pBlock); + blockDataGetSize(pBlock) + blockDataGetSerialMetaSize(pBlock->info.numOfCols); SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size); if (pRsp == NULL) { diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index f9cb63dc74..cde36eac58 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -40,6 +40,7 @@ static int32_t mndSmaGetVgEpSet(SMnode *pMnode, SDbObj *pDb, SVgEpSet **ppVgEpS static int32_t mndProcessMCreateSmaReq(SRpcMsg *pReq); static int32_t mndProcessMDropSmaReq(SRpcMsg *pReq); static int32_t mndProcessGetSmaReq(SRpcMsg *pReq); +static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq); static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextSma(SMnode *pMnode, void *pIter); @@ -59,6 +60,7 @@ int32_t mndInitSma(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_VND_CREATE_SMA_RSP, mndTransProcessRsp); mndSetMsgHandle(pMnode, TDMT_VND_DROP_SMA_RSP, mndTransProcessRsp); mndSetMsgHandle(pMnode, TDMT_MND_GET_INDEX, mndProcessGetSmaReq); + mndSetMsgHandle(pMnode, TDMT_MND_GET_TABLE_INDEX, mndProcessGetTbSmaReq); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndRetrieveSma); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndCancelGetNextSma); @@ -522,10 +524,9 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea int32_t code = -1; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq); if (pTrans == NULL) goto _OVER; - - mDebug("trans:%d, used to create sma:%s", pTrans->id, pCreate->name); mndTransSetDbName(pTrans, pDb->name); mndTransSetSerial(pTrans); + mDebug("trans:%d, used to create sma:%s", pTrans->id, pCreate->name); if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaVgroupRedoLogs(pMnode, pTrans, &streamObj.fixedSinkVg) != 0) goto _OVER; @@ -871,6 +872,64 @@ static int32_t mndGetSma(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp return code; } +static int32_t mndGetTableSma(SMnode *pMnode, STableIndexReq *indexReq, STableIndexRsp *rsp, bool *exist) { + int32_t code = 0; + SSmaObj *pSma = NULL; + SSdb *pSdb = pMnode->pSdb; + void *pIter = NULL; + STableIndexInfo info; + + while (1) { + pIter = sdbFetch(pSdb, SDB_SMA, pIter, (void **)&pSma); + if (pIter == NULL) break; + + if (pSma->stb[0] != indexReq->tbFName[0] || strcmp(pSma->stb, indexReq->tbFName)) { + continue; + } + + info.intervalUnit = pSma->intervalUnit; + info.slidingUnit = pSma->slidingUnit; + info.interval = pSma->interval; + info.offset = pSma->offset; + info.sliding = pSma->sliding; + info.dstTbUid = pSma->dstTbUid; + info.dstVgId = pSma->dstVgId; + + SVgObj* pVg = mndAcquireVgroup(pMnode, pSma->dstVgId); + if (pVg == NULL) { + code = -1; + sdbRelease(pSdb, pSma); + return code; + } + info.epSet = mndGetVgroupEpset(pMnode, pVg); + + info.expr = taosMemoryMalloc(pSma->exprLen + 1); + if (info.expr == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + code = -1; + sdbRelease(pSdb, pSma); + return code; + } + + memcpy(info.expr, pSma->expr, pSma->exprLen); + info.expr[pSma->exprLen] = 0; + + if (NULL == taosArrayPush(rsp->pIndex, &info)) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + code = -1; + taosMemoryFree(info.expr); + sdbRelease(pSdb, pSma); + return code; + } + + *exist = true; + + sdbRelease(pSdb, pSma); + } + + return code; +} + static int32_t mndProcessGetSmaReq(SRpcMsg *pReq) { SUserIndexReq indexReq = {0}; SMnode *pMnode = pReq->info.node; @@ -917,6 +976,59 @@ _OVER: return code; } +static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) { + STableIndexReq indexReq = {0}; + SMnode *pMnode = pReq->info.node; + int32_t code = -1; + STableIndexRsp rsp = {0}; + bool exist = false; + + if (tDeserializeSTableIndexReq(pReq->pCont, pReq->contLen, &indexReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + goto _OVER; + } + + rsp.pIndex = taosArrayInit(10, sizeof(STableIndexInfo)); + if (NULL == rsp.pIndex) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + code = -1; + goto _OVER; + } + + code = mndGetTableSma(pMnode, &indexReq, &rsp, &exist); + if (code) { + goto _OVER; + } + + if (!exist) { + code = -1; + terrno = TSDB_CODE_MND_DB_INDEX_NOT_EXIST; + } else { + int32_t contLen = tSerializeSTableIndexRsp(NULL, 0, &rsp); + void *pRsp = rpcMallocCont(contLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + code = -1; + goto _OVER; + } + + tSerializeSTableIndexRsp(pRsp, contLen, &rsp); + + pReq->info.rsp = pRsp; + pReq->info.rspLen = contLen; + + code = 0; + } + +_OVER: + if (code != 0) { + mError("failed to get table index %s since %s", indexReq.tbFName, terrstr()); + } + + return code; +} + + static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->info.node; SSdb *pSdb = pMnode->pSdb; diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index f5a1e76723..7d21528260 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -307,7 +307,7 @@ static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) { goto _OVER; } - if (mndCheckNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser) != 0) { goto _OVER; } @@ -419,7 +419,7 @@ static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) { goto _OVER; } - if (mndCheckNodeAuth(pUser)) { + if (mndCheckNodeAuth(pUser) != 0) { goto _OVER; } diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 388172f6ae..9981dc8530 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -1108,7 +1108,7 @@ static int32_t mndDropSuperTableColumn(SMnode *pMnode, const SStbObj *pOld, SStb return -1; } - col_id_t colId = pOld->pTags[col].colId; + col_id_t colId = pOld->pColumns[col].colId; if (mndCheckColAndTagModifiable(pMnode, pOld->uid, colId) != 0) { return -1; } @@ -1142,7 +1142,7 @@ static int32_t mndAlterStbColumnBytes(SMnode *pMnode, const SStbObj *pOld, SStbO return -1; } - col_id_t colId = pOld->pTags[col].colId; + col_id_t colId = pOld->pColumns[col].colId; if (mndCheckColAndTagModifiable(pMnode, pOld->uid, colId) != 0) { return -1; } diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index a0aa2067d3..7abe9e3c0d 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -54,8 +54,8 @@ int32_t mndInitStream(SMnode *pMnode) { }; mndSetMsgHandle(pMnode, TDMT_MND_CREATE_STREAM, mndProcessCreateStreamReq); - mndSetMsgHandle(pMnode, TDMT_VND_TASK_DEPLOY_RSP, mndTransProcessRsp); - mndSetMsgHandle(pMnode, TDMT_SND_TASK_DEPLOY_RSP, mndTransProcessRsp); + mndSetMsgHandle(pMnode, TDMT_STREAM_TASK_DEPLOY_RSP, mndTransProcessRsp); + /*mndSetMsgHandle(pMnode, TDMT_SND_TASK_DEPLOY_RSP, mndTransProcessRsp);*/ /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM, mndProcessDropStreamReq);*/ /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM_RSP, mndProcessDropStreamInRsp);*/ diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 245f0938b9..ce025d5547 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -193,7 +193,7 @@ int32_t mndInitSync(SMnode *pMnode) { void mndCleanupSync(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; syncStop(pMgmt->sync); - mDebug("sync:%" PRId64 " is stopped", pMgmt->sync); + mDebug("mnode sync is stopped, id:%" PRId64, pMgmt->sync); tsem_destroy(&pMgmt->syncSem); if (pMgmt->pWal != NULL) { diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index a810a6a487..605e446e2e 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -91,7 +91,7 @@ int32_t mndCheckColAndTagModifiable(SMnode *pMnode, int64_t suid, col_id_t colId } SHashObj *pColHash = NULL; - SNodeList *pNodeList; + SNodeList *pNodeList = NULL; nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList); SNode *pNode = NULL; FOREACH(pNode, pNodeList) { @@ -103,6 +103,7 @@ int32_t mndCheckColAndTagModifiable(SMnode *pMnode, int64_t suid, col_id_t colId if (pCol->colId > 0) { taosHashPut(pColHash, &pCol->colId, sizeof(int16_t), NULL, 0); } + mTrace("topic:%s, colId:%d is used", pTopic->name, pCol->colId); } if (taosHashGet(pColHash, &colId, sizeof(int16_t)) != NULL) { diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 8c0ba65fb2..c2097c069b 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -117,10 +117,10 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { int32_t dataPos = 0; SDB_SET_INT32(pRaw, dataPos, pTrans->id, _OVER) - SDB_SET_INT16(pRaw, dataPos, pTrans->stage, _OVER) - SDB_SET_INT16(pRaw, dataPos, pTrans->policy, _OVER) - SDB_SET_INT16(pRaw, dataPos, pTrans->conflict, _OVER) - SDB_SET_INT16(pRaw, dataPos, pTrans->exec, _OVER) + SDB_SET_INT8(pRaw, dataPos, pTrans->stage, _OVER) + SDB_SET_INT8(pRaw, dataPos, pTrans->policy, _OVER) + SDB_SET_INT8(pRaw, dataPos, pTrans->conflict, _OVER) + SDB_SET_INT8(pRaw, dataPos, pTrans->exec, _OVER) SDB_SET_INT64(pRaw, dataPos, pTrans->createdTime, _OVER) SDB_SET_BINARY(pRaw, dataPos, pTrans->dbname, TSDB_DB_FNAME_LEN, _OVER) SDB_SET_INT32(pRaw, dataPos, pTrans->redoActionPos, _OVER) @@ -256,15 +256,15 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pTrans->id, _OVER) - int16_t stage = 0; - int16_t policy = 0; - int16_t conflict = 0; - int16_t exec = 0; - int8_t actionType = 0; - SDB_GET_INT16(pRaw, dataPos, &stage, _OVER) - SDB_GET_INT16(pRaw, dataPos, &policy, _OVER) - SDB_GET_INT16(pRaw, dataPos, &conflict, _OVER) - SDB_GET_INT16(pRaw, dataPos, &exec, _OVER) + int8_t stage = 0; + int8_t policy = 0; + int8_t conflict = 0; + int8_t exec = 0; + int8_t actionType = 0; + SDB_GET_INT8(pRaw, dataPos, &stage, _OVER) + SDB_GET_INT8(pRaw, dataPos, &policy, _OVER) + SDB_GET_INT8(pRaw, dataPos, &conflict, _OVER) + SDB_GET_INT8(pRaw, dataPos, &exec, _OVER) pTrans->stage = stage; pTrans->policy = policy; pTrans->conflict = conflict; @@ -290,7 +290,8 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, _OVER) SDB_GET_INT8(pRaw, dataPos, &actionType, _OVER) action.actionType = actionType; - SDB_GET_INT8(pRaw, dataPos, &action.stage, _OVER) + SDB_GET_INT8(pRaw, dataPos, &stage, _OVER) + action.stage = stage; if (action.actionType == TRANS_ACTION_RAW) { SDB_GET_INT8(pRaw, dataPos, &action.rawWritten, _OVER) SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER) @@ -322,7 +323,8 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, _OVER) SDB_GET_INT8(pRaw, dataPos, &actionType, _OVER) action.actionType = actionType; - SDB_GET_INT8(pRaw, dataPos, &action.stage, _OVER) + SDB_GET_INT8(pRaw, dataPos, &stage, _OVER) + action.stage = stage; if (action.actionType == TRANS_ACTION_RAW) { SDB_GET_INT8(pRaw, dataPos, &action.rawWritten, _OVER) SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER) @@ -354,7 +356,8 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, _OVER) SDB_GET_INT8(pRaw, dataPos, &actionType, _OVER) action.actionType = actionType; - SDB_GET_INT8(pRaw, dataPos, &action.stage, _OVER) + SDB_GET_INT8(pRaw, dataPos, &stage, _OVER) + action.stage = stage; if (action.actionType) { SDB_GET_INT8(pRaw, dataPos, &action.rawWritten, _OVER) SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER) @@ -878,7 +881,6 @@ static void mndTransResetActions(SMnode *pMnode, STrans *pTrans, SArray *pArray) mDebug("trans:%d, %s:%d execute status is reset", pTrans->id, mndTransStr(pAction->stage), action); } pAction->errCode = 0; - } } @@ -890,11 +892,12 @@ static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransActi pAction->rawWritten = true; pAction->errCode = 0; code = 0; - mDebug("trans:%d, %s:%d write to sdb", pTrans->id, mndTransStr(pAction->stage), pAction->id); + mDebug("trans:%d, %s:%d write to sdb, type:%s status:%s", pTrans->id, mndTransStr(pAction->stage), pAction->id, + sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status)); } else { pAction->errCode = (terrno != 0) ? terrno : code; - mError("trans:%d, %s:%d failed to write sdb since %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, - terrstr()); + mError("trans:%d, %s:%d failed to write sdb since %s, type:%s status:%s", pTrans->id, mndTransStr(pAction->stage), + pAction->id, terrstr(), sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status)); } return code; @@ -916,18 +919,26 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio } memcpy(rpcMsg.pCont, pAction->pCont, pAction->contLen); + char detail[1024] = {0}; + int32_t len = snprintf(detail, sizeof(detail), "msgType:%s numOfEps:%d inUse:%d", TMSG_INFO(pAction->msgType), + pAction->epSet.numOfEps, pAction->epSet.inUse); + for (int32_t i = 0; i < pTrans->lastErrorEpset.numOfEps; ++i) { + len += snprintf(detail + len, sizeof(detail) - len, " ep:%d-%s:%u", i, pAction->epSet.eps[i].fqdn, + pAction->epSet.eps[i].port); + } + int32_t code = tmsgSendReq(&pAction->epSet, &rpcMsg); if (code == 0) { pAction->msgSent = 1; pAction->msgReceived = 0; pAction->errCode = 0; - mDebug("trans:%d, %s:%d is sent to %s:%u", pTrans->id, mndTransStr(pAction->stage), pAction->id, - pAction->epSet.eps[pAction->epSet.inUse].fqdn, pAction->epSet.eps[pAction->epSet.inUse].port); + mDebug("trans:%d, %s:%d is sent, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, detail); } else { pAction->msgSent = 0; pAction->msgReceived = 0; pAction->errCode = (terrno != 0) ? terrno : code; - mError("trans:%d, %s:%d not send since %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, terrstr()); + mError("trans:%d, %s:%d not send since %s, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, terrstr(), + detail); } return code; @@ -1424,9 +1435,9 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl if (epset.numOfEps > 0) { len += snprintf(detail + len, sizeof(detail) - len, "msgType:%s numOfEps:%d inUse:%d ", TMSG_INFO(pTrans->lastErrorMsgType), epset.numOfEps, epset.inUse); - } - for (int32_t i = 0; i < pTrans->lastErrorEpset.numOfEps; ++i) { - len += snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port); + for (int32_t i = 0; i < pTrans->lastErrorEpset.numOfEps; ++i) { + len += snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port); + } } } STR_WITH_MAXSIZE_TO_VARSTR(lastError, detail, pShow->pMeta->pSchemas[cols].bytes); diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 4f09eda733..5244bc657b 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -15,11 +15,13 @@ #define _DEFAULT_SOURCE #include "mndVgroup.h" +#include "mndAuth.h" #include "mndDb.h" #include "mndDnode.h" #include "mndMnode.h" #include "mndShow.h" #include "mndTrans.h" +#include "mndUser.h" #define VGROUP_VER_NUMBER 1 #define VGROUP_RESERVE_SIZE 64 @@ -34,6 +36,10 @@ static void mndCancelGetNextVgroup(SMnode *pMnode, void *pIter); static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextVnode(SMnode *pMnode, void *pIter); +static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq); +static int32_t mndProcessSplitVgroupMsg(SRpcMsg *pReq); +static int32_t mndProcessBalanceVgroupMsg(SRpcMsg *pReq); + int32_t mndInitVgroup(SMnode *pMnode) { SSdbTable table = { .sdbType = SDB_VGROUP, @@ -344,9 +350,14 @@ static bool mndResetDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2 static bool mndBuildDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) { SDnodeObj *pDnode = pObj; SArray *pArray = p1; + int32_t exceptDnodeId = *(int32_t *)p2; + + if (exceptDnodeId == pDnode->id) { + return true; + } int64_t curMs = taosGetTimestampMs(); - bool online = mndIsDnodeOnline(pMnode, pDnode, curMs); + bool online = mndIsDnodeOnline(pDnode, curMs); bool isMnode = mndIsMnode(pMnode, pDnode->id); pDnode->numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id); @@ -363,7 +374,7 @@ static bool mndBuildDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2 return true; } -SArray *mndBuildDnodesArray(SMnode *pMnode) { +SArray *mndBuildDnodesArray(SMnode *pMnode, int32_t exceptDnodeId) { SSdb *pSdb = pMnode->pSdb; int32_t numOfDnodes = mndGetDnodeSize(pMnode); @@ -374,7 +385,7 @@ SArray *mndBuildDnodesArray(SMnode *pMnode) { } sdbTraverse(pSdb, SDB_DNODE, mndResetDnodesArrayFp, NULL, NULL, NULL); - sdbTraverse(pSdb, SDB_DNODE, mndBuildDnodesArrayFp, pArray, NULL, NULL); + sdbTraverse(pSdb, SDB_DNODE, mndBuildDnodesArrayFp, pArray, &exceptDnodeId, NULL); return pArray; } @@ -422,7 +433,7 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup, SArray *pAr } int32_t mndAllocSmaVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup) { - SArray *pArray = mndBuildDnodesArray(pMnode); + SArray *pArray = mndBuildDnodesArray(pMnode, 0); if (pArray == NULL) return -1; pVgroup->vgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP); @@ -451,7 +462,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { goto _OVER; } - pArray = mndBuildDnodesArray(pMnode); + pArray = mndBuildDnodesArray(pMnode, 0); if (pArray == NULL) goto _OVER; mInfo("db:%s, total %d dnodes used to create %d vgroups (%d vnodes)", pDb->name, (int32_t)taosArrayGetSize(pArray), @@ -501,86 +512,6 @@ _OVER: return code; } -int32_t mndAddVnodeToVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray) { - taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes); - for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) { - SDnodeObj *pDnode = taosArrayGet(pArray, i); - mDebug("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes); - } - - SVnodeGid *pVgid = &pVgroup->vnodeGid[pVgroup->replica]; - for (int32_t d = 0; d < taosArrayGetSize(pArray); ++d) { - SDnodeObj *pDnode = taosArrayGet(pArray, d); - - bool used = false; - for (int32_t vn = 0; vn < pVgroup->replica; ++vn) { - if (pDnode->id == pVgroup->vnodeGid[vn].dnodeId) { - used = true; - break; - } - } - if (used) continue; - - if (pDnode == NULL || pDnode->numOfVnodes > pDnode->numOfSupportVnodes) { - terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; - return -1; - } - - pVgid->dnodeId = pDnode->id; - pVgid->role = TAOS_SYNC_STATE_ERROR; - mInfo("db:%s, vgId:%d, vn:%d dnode:%d, is added", pVgroup->dbName, pVgroup->vgId, pVgroup->replica, - pVgid->dnodeId); - - pVgroup->replica++; - pDnode->numOfVnodes++; - return 0; - } - - terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; - mError("db:%s, failed to add vnode to vgId:%d since %s", pVgroup->dbName, pVgroup->vgId, terrstr()); - return -1; -} - -int32_t mndRemoveVnodeFromVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray, SVnodeGid *pDelVgid) { - taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes); - for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) { - SDnodeObj *pDnode = taosArrayGet(pArray, i); - mDebug("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes); - } - - int32_t code = -1; - for (int32_t d = taosArrayGetSize(pArray) - 1; d >= 0; --d) { - SDnodeObj *pDnode = taosArrayGet(pArray, d); - - for (int32_t vn = 0; vn < pVgroup->replica; ++vn) { - SVnodeGid *pVgid = &pVgroup->vnodeGid[vn]; - if (pVgid->dnodeId == pDnode->id) { - mInfo("db:%s, vgId:%d, vn:%d dnode:%d, is removed", pVgroup->dbName, pVgroup->vgId, vn, pVgid->dnodeId); - pDnode->numOfVnodes--; - pVgroup->replica--; - *pDelVgid = *pVgid; - *pVgid = pVgroup->vnodeGid[pVgroup->replica]; - memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid)); - code = 0; - goto _OVER; - } - } - } - -_OVER: - if (code != 0) { - terrno = TSDB_CODE_APP_ERROR; - mError("db:%s, failed to remove vnode from vgId:%d since %s", pVgroup->dbName, pVgroup->vgId, terrstr()); - return -1; - } - - for (int32_t vn = 0; vn < pVgroup->replica; ++vn) { - SVnodeGid *pVgid = &pVgroup->vnodeGid[vn]; - mInfo("db:%s, vgId:%d, vn:%d dnode:%d is reserved", pVgroup->dbName, pVgroup->vgId, vn, pVgid->dnodeId); - } - return 0; -} - SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup) { SEpSet epset = {0}; @@ -678,7 +609,7 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p bool online = false; SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgroup->vnodeGid[i].dnodeId); if (pDnode != NULL) { - online = mndIsDnodeOnline(pMnode, pDnode, curMs); + online = mndIsDnodeOnline(pDnode, curMs); mndReleaseDnode(pMnode, pDnode); } @@ -797,3 +728,597 @@ static void mndCancelGetNextVnode(SMnode *pMnode, void *pIter) { SSdb *pSdb = pMnode->pSdb; sdbCancelFetch(pSdb, pIter); } + +int32_t mndAddVnodeToVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray) { + taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes); + for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) { + SDnodeObj *pDnode = taosArrayGet(pArray, i); + mDebug("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes); + } + + SVnodeGid *pVgid = &pVgroup->vnodeGid[pVgroup->replica]; + for (int32_t d = 0; d < taosArrayGetSize(pArray); ++d) { + SDnodeObj *pDnode = taosArrayGet(pArray, d); + + bool used = false; + for (int32_t vn = 0; vn < pVgroup->replica; ++vn) { + if (pDnode->id == pVgroup->vnodeGid[vn].dnodeId) { + used = true; + break; + } + } + if (used) continue; + + if (pDnode == NULL || pDnode->numOfVnodes > pDnode->numOfSupportVnodes) { + terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; + return -1; + } + + pVgid->dnodeId = pDnode->id; + pVgid->role = TAOS_SYNC_STATE_ERROR; + mInfo("db:%s, vgId:%d, vn:%d dnode:%d, is added", pVgroup->dbName, pVgroup->vgId, pVgroup->replica, pVgid->dnodeId); + + pVgroup->replica++; + pDnode->numOfVnodes++; + return 0; + } + + terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; + mError("db:%s, failed to add vnode to vgId:%d since %s", pVgroup->dbName, pVgroup->vgId, terrstr()); + return -1; +} + +int32_t mndRemoveVnodeFromVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray, SVnodeGid *pDelVgid) { + taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes); + for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) { + SDnodeObj *pDnode = taosArrayGet(pArray, i); + mDebug("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes); + } + + int32_t code = -1; + for (int32_t d = taosArrayGetSize(pArray) - 1; d >= 0; --d) { + SDnodeObj *pDnode = taosArrayGet(pArray, d); + + for (int32_t vn = 0; vn < pVgroup->replica; ++vn) { + SVnodeGid *pVgid = &pVgroup->vnodeGid[vn]; + if (pVgid->dnodeId == pDnode->id) { + mInfo("db:%s, vgId:%d, vn:%d dnode:%d, is removed", pVgroup->dbName, pVgroup->vgId, vn, pVgid->dnodeId); + pDnode->numOfVnodes--; + pVgroup->replica--; + *pDelVgid = *pVgid; + *pVgid = pVgroup->vnodeGid[pVgroup->replica]; + memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid)); + code = 0; + goto _OVER; + } + } + } + +_OVER: + if (code != 0) { + terrno = TSDB_CODE_APP_ERROR; + mError("db:%s, failed to remove vnode from vgId:%d since %s", pVgroup->dbName, pVgroup->vgId, terrstr()); + return -1; + } + + for (int32_t vn = 0; vn < pVgroup->replica; ++vn) { + SVnodeGid *pVgid = &pVgroup->vnodeGid[vn]; + mInfo("db:%s, vgId:%d, vn:%d dnode:%d is reserved", pVgroup->dbName, pVgroup->vgId, vn, pVgid->dnodeId); + } + return 0; +} + +int32_t mndAddCreateVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, + bool standby) { + STransAction action = {0}; + + SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); + if (pDnode == NULL) return -1; + action.epSet = mndGetDnodeEpset(pDnode); + mndReleaseDnode(pMnode, pDnode); + + int32_t contLen = 0; + void *pReq = mndBuildCreateVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen, standby); + if (pReq == NULL) return -1; + + action.pCont = pReq; + action.contLen = contLen; + action.msgType = TDMT_DND_CREATE_VNODE; + action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + taosMemoryFree(pReq); + return -1; + } + + return 0; +} + +int32_t mndAddAlterVnodeConfirmAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) { + STransAction action = {0}; + action.epSet = mndGetVgroupEpset(pMnode, pVgroup); + + int32_t contLen = sizeof(SMsgHead); + SMsgHead *pHead = taosMemoryMalloc(contLen); + if (pHead == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + pHead->contLen = htonl(contLen); + pHead->vgId = htonl(pVgroup->vgId); + + action.pCont = pHead; + action.contLen = contLen; + action.msgType = TDMT_VND_ALTER_CONFIRM; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + taosMemoryFree(pHead); + return -1; + } + + return 0; +} + +int32_t mndAddAlterVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, tmsg_t msgType) { + STransAction action = {0}; + action.epSet = mndGetVgroupEpset(pMnode, pVgroup); + + int32_t contLen = 0; + void *pReq = mndBuildAlterVnodeReq(pMnode, pDb, pVgroup, &contLen); + if (pReq == NULL) return -1; + + action.pCont = pReq; + action.contLen = contLen; + action.msgType = msgType; + + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + taosMemoryFree(pReq); + return -1; + } + + return 0; +} + +int32_t mndAddDropVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, + bool isRedo) { + STransAction action = {0}; + + SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); + if (pDnode == NULL) return -1; + action.epSet = mndGetDnodeEpset(pDnode); + mndReleaseDnode(pMnode, pDnode); + + int32_t contLen = 0; + void *pReq = mndBuildDropVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen); + if (pReq == NULL) return -1; + + action.pCont = pReq; + action.contLen = contLen; + action.msgType = TDMT_DND_DROP_VNODE; + action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED; + + if (isRedo) { + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + taosMemoryFree(pReq); + return -1; + } + } else { + if (mndTransAppendUndoAction(pTrans, &action) != 0) { + taosMemoryFree(pReq); + return -1; + } + } + + return 0; +} + +int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t vnIndex, + SArray *pArray) { + SVgObj newVg = {0}; + memcpy(&newVg, pVgroup, sizeof(SVgObj)); + + mInfo("vgId:%d, vgroup info before move, replica:%d", newVg.vgId, newVg.replica); + for (int32_t i = 0; i < newVg.replica; ++i) { + mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId); + } + + mInfo("vgId:%d, will add 1 vnodes", pVgroup->vgId); + if (mndAddVnodeToVgroup(pMnode, &newVg, pArray) != 0) return -1; + if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[1], true) != 0) return -1; + if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg, TDMT_VND_ALTER_REPLICA) != 0) return -1; + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; + + mInfo("vgId:%d, will remove 1 vnodes", pVgroup->vgId); + newVg.replica--; + SVnodeGid del = newVg.vnodeGid[vnIndex]; + newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica]; + memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid)); + if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg, TDMT_VND_ALTER_REPLICA) != 0) return -1; + if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1; + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; + + mInfo("vgId:%d, vgroup info after move, replica:%d", newVg.vgId, newVg.replica); + for (int32_t i = 0; i < newVg.replica; ++i) { + mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId); + } + return 0; +} + +int32_t mndSetMoveVgroupsInfoToTrans(SMnode *pMnode, STrans *pTrans, int32_t delDnodeId) { + SArray *pArray = mndBuildDnodesArray(pMnode, delDnodeId); + if (pArray == NULL) return -1; + + void *pIter = NULL; + while (1) { + SVgObj *pVgroup = NULL; + pIter = sdbFetch(pMnode->pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + int32_t vnIndex = -1; + for (int32_t i = 0; i < pVgroup->replica; ++i) { + if (pVgroup->vnodeGid[i].dnodeId == delDnodeId) { + vnIndex = i; + break; + } + } + + if (vnIndex != -1) { + mInfo("vgId:%d, vnode:%d will be removed from dnode:%d", pVgroup->vgId, vnIndex, delDnodeId); + SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName); + mndSetMoveVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, vnIndex, pArray); + mndReleaseDb(pMnode, pDb); + } + + sdbRelease(pMnode->pSdb, pVgroup); + } + + taosArrayDestroy(pArray); + return 0; +} + +static int32_t mndAddIncVgroupReplicaToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, + int32_t newDnodeId) { + mDebug("vgId:%d, will add 1 vnode, replica:%d, dnode:%d", pVgroup->vgId, pVgroup->replica, newDnodeId); + + SVnodeGid *pGid = &pVgroup->vnodeGid[pVgroup->replica]; + pVgroup->replica++; + pGid->dnodeId = newDnodeId; + pGid->role = TAOS_SYNC_STATE_ERROR; + + if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pGid, true) != 0) return -1; + if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, pVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1; + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1; + + return 0; +} + +static int32_t mndAddDecVgroupReplicaFromTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, + int32_t delDnodeId) { + mDebug("vgId:%d, will remove 1 vnode, replica:%d, dnode:%d", pVgroup->vgId, pVgroup->replica, delDnodeId); + + SVnodeGid *pGid = NULL; + SVnodeGid delGid = {0}; + for (int32_t i = 0; i < pVgroup->replica; ++i) { + if (pVgroup->vnodeGid[i].dnodeId == delDnodeId) { + pGid = &pVgroup->vnodeGid[i]; + break; + } + } + + if (pGid == NULL) return 0; + + memcpy(&delGid, pGid, sizeof(SVnodeGid)); + memcpy(pGid, &pVgroup->vnodeGid[pVgroup->replica], sizeof(SVnodeGid)); + memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid)); + pVgroup->replica--; + + if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, pVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1; + if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1; + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1; + + return 0; +} + +static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgroup, SDnodeObj *pNew1, + SDnodeObj *pOld1, SDnodeObj *pNew2, SDnodeObj *pOld2, SDnodeObj *pNew3, + SDnodeObj *pOld3) { + int32_t code = -1; + SSdbRaw *pRaw = NULL; + STrans *pTrans = NULL; + + pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq); + if (pTrans == NULL) goto _OVER; + mndTransSetSerial(pTrans); + mDebug("trans:%d, used to drop redistribute vgId:%d", pTrans->id, pVgroup->vgId); + + SVgObj newVg = {0}; + memcpy(&newVg, pVgroup, sizeof(SVgObj)); + mInfo("vgId:%d, vgroup info before redistribute, replica:%d", newVg.vgId, newVg.replica); + for (int32_t i = 0; i < newVg.replica; ++i) { + mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId); + } + + if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew1->id) != 0) goto _OVER; + if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld1->id) != 0) goto _OVER; + if (pNew2 != NULL) { + if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew2->id) != 0) goto _OVER; + if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld2->id) != 0) goto _OVER; + if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew3->id) != 0) goto _OVER; + if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld3->id) != 0) goto _OVER; + } + + pRaw = mndVgroupActionEncode(&newVg); + if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER; + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + pRaw = NULL; + + mInfo("vgId:%d, vgroup info after redistribute, replica:%d", newVg.vgId, newVg.replica); + for (int32_t i = 0; i < newVg.replica; ++i) { + mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId); + } + + if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + code = 0; + +_OVER: + mndTransDrop(pTrans); + sdbFreeRaw(pRaw); + mndReleaseDb(pMnode, pDb); + return code; +} + +static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq) { + SMnode *pMnode = pReq->info.node; + SUserObj *pUser = NULL; + SDnodeObj *pNew1 = NULL; + SDnodeObj *pNew2 = NULL; + SDnodeObj *pNew3 = NULL; + SDnodeObj *pOld1 = NULL; + SDnodeObj *pOld2 = NULL; + SDnodeObj *pOld3 = NULL; + SVgObj *pVgroup = NULL; + SDbObj *pDb = NULL; + int32_t code = -1; + int64_t curMs = taosGetTimestampMs(); + SMDropMnodeReq redReq = {0}; + +#if 0 + if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + goto _OVER; + } +#endif + + mDebug("vgId:%d, start to redistribute", 2); + pUser = mndAcquireUser(pMnode, pReq->conn.user); + if (pUser == NULL) { + terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; + goto _OVER; + } + + if (mndCheckNodeAuth(pUser) != 0) { + goto _OVER; + } + + pVgroup = mndAcquireVgroup(pMnode, 2); + if (pVgroup == NULL) goto _OVER; + + pDb = mndAcquireDb(pMnode, pVgroup->dbName); + if (pDb == NULL) goto _OVER; + + if (pVgroup->replica == 1) { + pNew1 = mndAcquireDnode(pMnode, 1); + pOld1 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[0].dnodeId); + if (pNew1 == NULL || pOld1 == NULL) goto _OVER; + if (!mndIsDnodeOnline(pNew1, curMs) || !mndIsDnodeOnline(pOld1, curMs)) { + terrno = TSDB_CODE_NODE_OFFLINE; + goto _OVER; + } + if (pNew1 == pOld1) { + terrno = TSDB_CODE_MND_VGROUP_UN_CHANGED; + goto _OVER; + } + if (mndRedistributeVgroup(pMnode, pReq, pDb, pVgroup, pNew1, pOld1, NULL, NULL, NULL, NULL) != 0) goto _OVER; + } + + if (pVgroup->replica == 3) { + pNew1 = mndAcquireDnode(pMnode, 1); + pNew2 = mndAcquireDnode(pMnode, 2); + pNew3 = mndAcquireDnode(pMnode, 3); + pOld1 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[0].dnodeId); + pOld2 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[1].dnodeId); + pOld3 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[2].dnodeId); + if (pNew1 == NULL || pOld1 == NULL || pNew2 == NULL || pOld2 == NULL || pNew3 == NULL || pOld3 == NULL) goto _OVER; + if (!mndIsDnodeOnline(pNew1, curMs) || !mndIsDnodeOnline(pOld1, curMs) || !mndIsDnodeOnline(pNew2, curMs) || + !mndIsDnodeOnline(pOld2, curMs) || !mndIsDnodeOnline(pNew3, curMs) || !mndIsDnodeOnline(pOld3, curMs)) { + terrno = TSDB_CODE_NODE_OFFLINE; + goto _OVER; + } + bool changed = true; + if (pNew1 != pOld1 || pNew1 != pOld2 || pNew1 != pOld3) changed = true; + if (pNew2 != pOld1 || pNew2 != pOld2 || pNew2 != pOld3) changed = true; + if (pNew3 != pOld1 || pNew3 != pOld2 || pNew3 != pOld3) changed = true; + if (!changed) { + terrno = TSDB_CODE_MND_VGROUP_UN_CHANGED; + goto _OVER; + } + if (mndRedistributeVgroup(pMnode, pReq, pDb, pVgroup, pNew1, pOld1, pNew2, pOld2, pNew3, pOld3) != 0) goto _OVER; + } + + if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; + +_OVER: + if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { + mDebug("vgId:%d, failed to redistribute since %s", 1, terrstr()); + } + + mndReleaseDnode(pMnode, pNew1); + mndReleaseDnode(pMnode, pNew2); + mndReleaseDnode(pMnode, pNew3); + mndReleaseDnode(pMnode, pOld1); + mndReleaseDnode(pMnode, pOld2); + mndReleaseDnode(pMnode, pOld3); + mndReleaseUser(pMnode, pUser); + mndReleaseVgroup(pMnode, pVgroup); + mndReleaseDb(pMnode, pDb); + + return code; +} + +static int32_t mndProcessSplitVgroupMsg(SRpcMsg *pReq) { return 0; } + +static int32_t mndSetBalanceVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, + SDnodeObj *pSrc, SDnodeObj *pDst) { + SVgObj newVg = {0}; + memcpy(&newVg, pVgroup, sizeof(SVgObj)); + mInfo("vgId:%d, vgroup info before balance, replica:%d", newVg.vgId, newVg.replica); + for (int32_t i = 0; i < newVg.replica; ++i) { + mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId); + } + + if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pDst->id) != 0) return -1; + if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pSrc->id) != 0) return -1; + + SSdbRaw *pRaw = mndVgroupActionEncode(&newVg); + if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) { + sdbFreeRaw(pRaw); + return -1; + } + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + + mInfo("vgId:%d, vgroup info after balance, replica:%d", newVg.vgId, newVg.replica); + for (int32_t i = 0; i < newVg.replica; ++i) { + mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId); + } + return 0; +} + +static int32_t mndBalanceVgroupBetweenDnode(SMnode *pMnode, STrans *pTrans, SDnodeObj *pSrc, SDnodeObj *pDst) { + void *pIter = NULL; + int32_t code = -1; + + while (1) { + SVgObj *pVgroup = NULL; + pIter = sdbFetch(pMnode->pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + bool existInSrc = false; + bool existInDst = false; + for (int32_t i = 0; i < pVgroup->replica; ++i) { + SVnodeGid *pGid = &pVgroup->vnodeGid[i]; + if (pGid->dnodeId == pSrc->id) existInSrc = true; + if (pGid->dnodeId == pDst->id) existInDst = true; + } + + if (!existInSrc || existInDst) { + sdbRelease(pMnode->pSdb, pVgroup); + } + + SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName); + code = mndSetBalanceVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, pSrc, pDst); + mndReleaseDb(pMnode, pDb); + sdbRelease(pMnode->pSdb, pVgroup); + break; + } + + return code; +} + +static int32_t mndBalanceVgroup(SMnode *pMnode, SRpcMsg *pReq, SArray *pArray) { + int32_t code = -1; + int32_t numOfVgroups = 0; + STrans *pTrans = NULL; + + pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq); + if (pTrans == NULL) goto _OVER; + mndTransSetSerial(pTrans); + mDebug("trans:%d, used to balance vgroup", pTrans->id); + + while (1) { + taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes); + SDnodeObj *pSrc = taosArrayGet(pArray, 0); + SDnodeObj *pDst = taosArrayGet(pArray, taosArrayGetSize(pArray) - 1); + + float srcScore = (float)(pSrc->numOfVnodes - 1) / pSrc->numOfSupportVnodes; + float dstScore = (float)(pDst->numOfVnodes + 1) / pDst->numOfSupportVnodes; + if (srcScore + 0.0001 < dstScore) { + mDebug("trans:%d, balance vgroup from dnode:%d to dnode:%d", pTrans->id, pSrc->id, pDst->id); + code = mndBalanceVgroupBetweenDnode(pMnode, pTrans, pSrc, pDst); + if (code == 0) { + numOfVgroups++; + continue; + } else { + mError("trans:%d, failed to balance vgroup from dnode:%d to dnode:%d", pTrans->id, pSrc->id, pDst->id); + return -1; + } + } else { + mDebug("trans:%d, no vgroup need to balance vgroup any more", pTrans->id); + break; + } + } + + if (numOfVgroups <= 0) { + mDebug("no need to balance vgroup"); + code = 0; + } else { + mDebug("start to balance vgroup, numOfVgroups:%d", numOfVgroups); + if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + code = TSDB_CODE_ACTION_IN_PROGRESS; + } + +_OVER: + mndTransDrop(pTrans); + return code; +} + +static int32_t mndProcessBalanceVgroupMsg(SRpcMsg *pReq) { + SMnode *pMnode = pReq->info.node; + int32_t code = -1; + SUserObj *pUser = NULL; + SArray *pArray = NULL; + void *pIter = NULL; + int64_t curMs = taosGetTimestampMs(); + + mDebug("start to balance vgroup"); + pUser = mndAcquireUser(pMnode, pReq->conn.user); + if (pUser == NULL) { + terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; + goto _OVER; + } + + if (mndCheckNodeAuth(pUser) != 0) goto _OVER; + + while (1) { + SDnodeObj *pDnode = NULL; + pIter = sdbFetch(pMnode->pSdb, SDB_DNODE, pIter, (void **)&pDnode); + if (pIter == NULL) break; + if (!mndIsDnodeOnline(pDnode, curMs)) { + terrno = TSDB_CODE_MND_HAS_OFFLINE_DNODE; + mError("failed to balance vgroup since %s, dnode:%d", terrstr(), pDnode->id); + sdbRelease(pMnode->pSdb, pDnode); + goto _OVER; + } + + sdbRelease(pMnode->pSdb, pDnode); + } + + pArray = mndBuildDnodesArray(pMnode, 0); + if (pArray == NULL) goto _OVER; + + if (taosArrayGetSize(pArray) < 2) { + mDebug("no need to balance vgroup since dnode num less than 2"); + code = 0; + } else { + code = mndBalanceVgroup(pMnode, pReq, pArray); + } + +_OVER: + if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { + mError("failed to balance vgroup since %s", terrstr()); + } + + mndReleaseUser(pMnode, pUser); + taosArrayDestroy(pArray); + return code; +} \ No newline at end of file diff --git a/source/dnode/mnode/sdb/inc/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h index 4a00befa1e..9444543804 100644 --- a/source/dnode/mnode/sdb/inc/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -392,6 +392,7 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply); int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len); const char *sdbTableName(ESdbType type); +const char *sdbStatusName(ESdbStatus status); void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper); int32_t sdbGetIdFromRaw(SSdb *pSdb, SSdbRaw *pRaw); diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 162da2bd0a..d1b1e31635 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -65,7 +65,7 @@ const char *sdbTableName(ESdbType type) { } } -static const char *sdbStatusName(ESdbStatus status) { +const char *sdbStatusName(ESdbStatus status) { switch (status) { case SDB_STATUS_CREATING: return "creating"; diff --git a/source/dnode/mnode/sdb/src/sdbRaw.c b/source/dnode/mnode/sdb/src/sdbRaw.c index 90643a54a9..7720a8e88a 100644 --- a/source/dnode/mnode/sdb/src/sdbRaw.c +++ b/source/dnode/mnode/sdb/src/sdbRaw.c @@ -42,8 +42,10 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) { } void sdbFreeRaw(SSdbRaw *pRaw) { - mTrace("raw:%p, is freed", pRaw); - taosMemoryFree(pRaw); + if (pRaw != NULL) { + mTrace("raw:%p, is freed", pRaw); + taosMemoryFree(pRaw); + } } int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) { diff --git a/source/dnode/qnode/src/qnode.c b/source/dnode/qnode/src/qnode.c index 45b88318c4..ebaf73a952 100644 --- a/source/dnode/qnode/src/qnode.c +++ b/source/dnode/qnode/src/qnode.c @@ -59,6 +59,7 @@ int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { pLoad->numOfProcessedFetch = stat.fetchProcessed; pLoad->numOfProcessedDrop = stat.dropProcessed; pLoad->numOfProcessedHb = stat.hbProcessed; + pLoad->numOfProcessedDelete = stat.deleteProcessed; return 0; } diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c index 37b406466d..cbbe071c5f 100644 --- a/source/dnode/snode/src/snode.c +++ b/source/dnode/snode/src/snode.c @@ -90,7 +90,7 @@ void sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) { // stream deploy // stream stop/resume // operator exec - if (pMsg->msgType == TDMT_SND_TASK_DEPLOY) { + if (pMsg->msgType == TDMT_STREAM_TASK_DEPLOY) { void *msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); SStreamTask *pTask = taosMemoryMalloc(sizeof(SStreamTask)); if (pTask == NULL) { diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 05b4a270d6..978fd9013a 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -36,12 +36,10 @@ target_sources( # tsdb "src/tsdb/tsdbCommit.c" - "src/tsdb/tsdbCommit2.c" "src/tsdb/tsdbFile.c" "src/tsdb/tsdbFS.c" "src/tsdb/tsdbOpen.c" "src/tsdb/tsdbMemTable.c" - "src/tsdb/tsdbMemTable2.c" "src/tsdb/tsdbRead.c" "src/tsdb/tsdbReadImpl.c" "src/tsdb/tsdbWrite.c" diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 8c7a78a5af..01e57d5eaf 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -71,6 +71,9 @@ int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader); int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, const void **ppData, uint32_t *nData); int32_t vnodeProcessCreateTSma(SVnode *pVnode, void *pCont, uint32_t contLen); +void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs); +void vnodeApplyMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs); + // meta typedef struct SMeta SMeta; // todo: remove typedef struct SMetaReader SMetaReader; diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h index 7cd82b0ac3..e7a744748b 100644 --- a/source/dnode/vnode/src/inc/tq.h +++ b/source/dnode/vnode/src/inc/tq.h @@ -78,10 +78,10 @@ typedef struct { tmr_h timerId; int8_t tmrStopped; // exec - int8_t inputStatus; - int8_t execStatus; - SStreamQ inputQ; - SRWLatch lock; + int8_t inputStatus; + int8_t execStatus; + SStreamQueue inputQ; + SRWLatch lock; } STqPushHandle; // tqExec @@ -107,7 +107,7 @@ typedef struct { STqExecCol execCol; STqExecTb execTb; STqExecDb execDb; - } exec; + }; } STqExecHandle; typedef struct { diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 171d52164c..657b55a0c6 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -39,24 +39,24 @@ typedef struct SDelOp SDelOp; static int tsdbKeyCmprFn(const void *p1, const void *p2); -// tsdbMemTable2.c ============================================================================================== -typedef struct SMemTable SMemTable; -typedef struct SMemData SMemData; -typedef struct SMemDataIter SMemDataIter; +// tsdbMemTable ============================================================================================== +typedef struct STbData STbData; +typedef struct SMemTable SMemTable; +typedef struct STbDataIter STbDataIter; +typedef struct SMergeInfo SMergeInfo; +typedef struct STable STable; -int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTable); -void tsdbMemTableDestroy2(SMemTable *pMemTable); -int32_t tsdbInsertTableData2(STsdb *pTsdb, int64_t version, SVSubmitBlk *pSubmitBlk); -int32_t tsdbDeleteTableData2(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey); +// SMemTable +int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable); +void tsdbMemTableDestroy(SMemTable *pMemTable); +void tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData); -/* SMemDataIter */ -void tsdbMemDataIterOpen(SMemData *pMemData, TSDBKEY *pKey, int8_t backward, SMemDataIter *pIter); -bool tsdbMemDataIterNext(SMemDataIter *pIter); -void tsdbMemDataIterGet(SMemDataIter *pIter, TSDBROW **ppRow); - -// tsdbCommit2.c ============================================================================================== -int32_t tsdbBegin2(STsdb *pTsdb); -int32_t tsdbCommit2(STsdb *pTsdb); +// STbDataIter +int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter **ppIter); +void *tsdbTbDataIterDestroy(STbDataIter *pIter); +void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter); +bool tsdbTbDataIterNext(STbDataIter *pIter); +bool tsdbTbDataIterGet(STbDataIter *pIter, TSDBROW *pRow); // tsdbFile.c ============================================================================================== typedef int32_t TSDB_FILE_T; @@ -124,17 +124,6 @@ int tsdbRLockFS(STsdbFS *pFs); int tsdbWLockFS(STsdbFS *pFs); int tsdbUnLockFS(STsdbFS *pFs); -// tsdbMemTable ================ -typedef struct STbData STbData; -typedef struct STsdbMemTable STsdbMemTable; -typedef struct SMergeInfo SMergeInfo; -typedef struct STable STable; - -int tsdbMemTableCreate(STsdb *pTsdb, STsdbMemTable **ppMemTable); -void tsdbMemTableDestroy(STsdbMemTable *pMemTable); -int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, - SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo); - // structs typedef struct { int minFid; @@ -145,30 +134,27 @@ typedef struct { #define TSDB_DATA_DIR_LEN 6 // adapt accordingly struct STsdb { - char *path; - SVnode *pVnode; - TdThreadMutex mutex; - char dir[TSDB_DATA_DIR_LEN]; - bool repoLocked; - STsdbKeepCfg keepCfg; - STsdbMemTable *mem; - STsdbMemTable *imem; - SRtn rtn; - STsdbFS *fs; + char *path; + SVnode *pVnode; + TdThreadMutex mutex; + char dir[TSDB_DATA_DIR_LEN]; + bool repoLocked; + STsdbKeepCfg keepCfg; + SMemTable *mem; + SMemTable *imem; + SRtn rtn; + STsdbFS *fs; }; #if 1 // ====================================== struct STable { - uint64_t tid; + uint64_t suid; uint64_t uid; STSchema *pSchema; // latest schema STSchema *pCacheSchema; // cached cache }; -#define TABLE_TID(t) (t)->tid -#define TABLE_UID(t) (t)->uid - // int tsdbPrepareCommit(STsdb *pTsdb); typedef enum { TSDB_FILE_HEAD = 0, // .head @@ -206,27 +192,44 @@ struct SDFileSet { SDFile files[TSDB_FILE_MAX]; }; -struct STbData { - tb_uid_t uid; - TSKEY keyMin; - TSKEY keyMax; - int64_t minVer; - int64_t maxVer; - int64_t nrows; - SSkipList *pData; +struct TSDBKEY { + int64_t version; + TSKEY ts; }; -struct STsdbMemTable { - SVBufPool *pPool; - T_REF_DECLARE() - SRWLatch latch; - TSKEY keyMin; - TSKEY keyMax; - int64_t minVer; - int64_t maxVer; - int64_t nRow; - SSkipList *pSlIdx; // SSkiplist - SHashObj *pHashIdx; +typedef struct SMemSkipListNode SMemSkipListNode; +struct SMemSkipListNode { + int8_t level; + SMemSkipListNode *forwards[0]; +}; +typedef struct SMemSkipList { + uint32_t seed; + int64_t size; + int8_t maxLevel; + int8_t level; + SMemSkipListNode *pHead; + SMemSkipListNode *pTail; +} SMemSkipList; + +struct STbData { + tb_uid_t suid; + tb_uid_t uid; + TSDBKEY minKey; + TSDBKEY maxKey; + SDelOp *pHead; + SDelOp *pTail; + SMemSkipList sl; +}; + +struct SMemTable { + SRWLatch latch; + STsdb *pTsdb; + int32_t nRef; + TSDBKEY minKey; + TSDBKEY maxKey; + int64_t nRow; + int64_t nDelOp; + SArray *aTbData; // SArray }; struct STsdbFSMeta { @@ -237,9 +240,11 @@ struct STsdbFSMeta { // ================== typedef struct { - STsdbFSMeta meta; // FS meta - SArray *df; // data file array - SArray *sf; // sma data file array v2f1900.index_name_1 + STsdbFSMeta meta; // FS meta + SDFile cacheFile; // cache file + SDFile tombstone; // tomestome file + SArray *df; // data file array + SArray *sf; // sma data file array v2f1900.index_name_1 } SFSStatus; struct STsdbFS { @@ -292,16 +297,24 @@ static void *taosTZfree(void *ptr); static size_t taosTSizeof(void *ptr); static void taosTMemset(void *ptr, int c); -static FORCE_INLINE STSRow *tsdbNextIterRow(SSkipListIterator *pIter) { +struct TSDBROW { + int64_t version; + STSRow *pTSRow; +}; + +static FORCE_INLINE STSRow *tsdbNextIterRow(STbDataIter *pIter) { + TSDBROW row; + if (pIter == NULL) return NULL; - SSkipListNode *node = tSkipListIterGet(pIter); - if (node == NULL) return NULL; + if (tsdbTbDataIterGet(pIter, &row)) { + return row.pTSRow; + } - return (STSRow *)SL_GET_NODE_DATA(node); + return NULL; } -static FORCE_INLINE TSKEY tsdbNextIterKey(SSkipListIterator *pIter) { +static FORCE_INLINE TSKEY tsdbNextIterKey(STbDataIter *pIter) { STSRow *row = tsdbNextIterRow(pIter); if (row == NULL) return TSDB_DATA_TIMESTAMP_NULL; @@ -311,11 +324,6 @@ static FORCE_INLINE TSKEY tsdbNextIterKey(SSkipListIterator *pIter) { // tsdbReadImpl typedef struct SReadH SReadH; -struct TSDBKEY { - int64_t version; - TSKEY ts; -}; - typedef struct { uint64_t suid; uint64_t uid; @@ -354,7 +362,7 @@ typedef struct { typedef struct { int32_t delimiter; // For recovery usage - int32_t tid; + uint64_t suid; uint64_t uid; SBlock blocks[]; } SBlockInfo; @@ -650,11 +658,6 @@ struct SFSIter { #define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC #define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC -struct TSDBROW { - int64_t version; - STSRow2 tsRow; -}; - struct TABLEID { tb_uid_t suid; tb_uid_t uid; @@ -675,17 +678,6 @@ typedef struct { TSKEY eKey; } SDelInfo; -struct SMemTable { - STsdb *pTsdb; - int32_t nRef; - TSDBKEY minKey; - TSDBKEY maxKey; - int64_t nRows; - int64_t nDelOp; - SArray *aSkmInfo; - SArray *aMemData; -}; - static FORCE_INLINE int tsdbKeyCmprFn(const void *p1, const void *p2) { TSDBKEY *pKey1 = (TSDBKEY *)p1; TSDBKEY *pKey2 = (TSDBKEY *)p2; @@ -705,32 +697,10 @@ static FORCE_INLINE int tsdbKeyCmprFn(const void *p1, const void *p2) { return 0; } -typedef struct SMemSkipListNode SMemSkipListNode; -typedef struct SMemSkipList { - uint32_t seed; - int32_t size; - int8_t maxLevel; - int8_t level; - SMemSkipListNode *pHead; - SMemSkipListNode *pTail; -} SMemSkipList; - -struct SMemData { - tb_uid_t suid; - tb_uid_t uid; - TSDBKEY minKey; - TSDBKEY maxKey; - SDelOp *delOpHead; - SDelOp *delOpTail; - SMemSkipList sl; -}; - -struct SMemDataIter { - SMemData *pMemData; +struct STbDataIter { + STbData *pTbData; int8_t backward; - TSDBROW *pRow; - SMemSkipListNode *pNode; // current node - TSDBROW row; + SMemSkipListNode *pNode; }; #endif diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 5f4f7e70da..b0599b82ef 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -84,7 +84,6 @@ int32_t vnodeAsyncCommit(SVnode* pVnode); int32_t vnodeSyncOpen(SVnode* pVnode, char* path); void vnodeSyncStart(SVnode* pVnode); void vnodeSyncClose(SVnode* pVnode); -int32_t vnodeSyncAlter(SVnode* pVnode, SRpcMsg* pMsg); #ifdef __cplusplus } diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 15469786e0..5532f202fc 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -112,11 +112,13 @@ int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid); // tsdb int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg); int tsdbClose(STsdb** pTsdb); -int tsdbBegin(STsdb* pTsdb); +int32_t tsdbBegin(STsdb* pTsdb); int32_t tsdbCommit(STsdb* pTsdb); int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq* pMsg); int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp); -int tsdbInsertTableData(STsdb* pTsdb, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkRsp* pRsp); +int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, + SSubmitBlkRsp* pRsp); +int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey); tsdbReaderT* tsdbQueryTables(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, uint64_t taskId); tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, @@ -159,18 +161,6 @@ int32_t tdUpdateTbUidList(SSma* pSma, STbUidStore* pUidStore); void tdUidStoreDestory(STbUidStore* pStore); void* tdUidStoreFree(STbUidStore* pStore); -#if 0 -int32_t tsdbUpdateSmaWindow(STsdb* pTsdb, SSubmitReq* pMsg, int64_t version); -int32_t tsdbCreateTSma(STsdb* pTsdb, char* pMsg); -int32_t tsdbInsertTSmaData(STsdb* pTsdb, int64_t indexUid, const char* msg); -int32_t tsdbRegisterRSma(STsdb* pTsdb, SMeta* pMeta, SVCreateStbReq* pReq, SMsgCb* pMsgCb); -int32_t tsdbFetchTbUidList(STsdb* pTsdb, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid); -int32_t tsdbUpdateTbUidList(STsdb* pTsdb, STbUidStore* pUidStore); -void tsdbUidStoreDestory(STbUidStore* pStore); -void* tsdbUidStoreFree(STbUidStore* pStore); -int32_t tsdbTriggerRSma(STsdb* pTsdb, void* pMsg, int32_t inputType); -#endif - typedef struct { int8_t streamType; // sma or other int8_t dstType; @@ -230,8 +220,10 @@ struct SVnode { SWal* pWal; STQ* pTq; SSink* pSink; - int64_t sync; tsem_t canCommit; + int64_t sync; + int32_t syncCount; + sem_t syncSem; SQHandle* pQuery; }; diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 21a55d6463..063a78b0c6 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -31,7 +31,7 @@ void metaReaderClear(SMetaReader *pReader) { } int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) { - SMeta * pMeta = pReader->pMeta; + SMeta *pMeta = pReader->pMeta; STbDbKey tbDbKey = {.version = version, .uid = uid}; // query table.db @@ -54,7 +54,7 @@ _err: } int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) { - SMeta * pMeta = pReader->pMeta; + SMeta *pMeta = pReader->pMeta; int64_t version; // query uid.idx @@ -68,7 +68,7 @@ int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) { } int metaGetTableEntryByName(SMetaReader *pReader, const char *name) { - SMeta * pMeta = pReader->pMeta; + SMeta *pMeta = pReader->pMeta; tb_uid_t uid; // query name.idx @@ -82,7 +82,7 @@ int metaGetTableEntryByName(SMetaReader *pReader, const char *name) { } tb_uid_t metaGetTableEntryUidByName(SMeta *pMeta, const char *name) { - void * pData = NULL; + void *pData = NULL; int nData = 0; tb_uid_t uid = 0; @@ -134,7 +134,7 @@ void metaCloseTbCursor(SMTbCursor *pTbCur) { int metaTbCursorNext(SMTbCursor *pTbCur) { int ret; - void * pBuf; + void *pBuf; STbCfg tbCfg; for (;;) { @@ -155,7 +155,7 @@ int metaTbCursorNext(SMTbCursor *pTbCur) { } SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) { - void * pData = NULL; + void *pData = NULL; int nData = 0; int64_t version; SSchemaWrapper schema = {0}; @@ -163,37 +163,47 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo SDecoder dc = {0}; metaRLock(pMeta); - if (sver < 0) { - if (tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData) < 0) { - goto _err; - } - - version = *(int64_t *)pData; - - tdbTbGet(pMeta->pTbDb, &(STbDbKey){.uid = uid, .version = version}, sizeof(STbDbKey), &pData, &nData); - - SMetaEntry me = {0}; - tDecoderInit(&dc, pData, nData); - metaDecodeEntry(&dc, &me); - if (me.type == TSDB_SUPER_TABLE) { - pSchema = tCloneSSchemaWrapper(&me.stbEntry.schemaRow); - } else if (me.type == TSDB_NORMAL_TABLE) { - pSchema = tCloneSSchemaWrapper(&me.ntbEntry.schemaRow); - } else { - ASSERT(0); - } - tDecoderClear(&dc); - } else { - if (tdbTbGet(pMeta->pSkmDb, &(SSkmDbKey){.uid = uid, .sver = sver}, sizeof(SSkmDbKey), &pData, &nData) < 0) { - goto _err; - } - - tDecoderInit(&dc, pData, nData); - tDecodeSSchemaWrapper(&dc, &schema); - pSchema = tCloneSSchemaWrapper(&schema); - tDecoderClear(&dc); +_query: + if (tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData) < 0) { + goto _err; } + version = *(int64_t *)pData; + + tdbTbGet(pMeta->pTbDb, &(STbDbKey){.uid = uid, .version = version}, sizeof(STbDbKey), &pData, &nData); + SMetaEntry me = {0}; + tDecoderInit(&dc, pData, nData); + metaDecodeEntry(&dc, &me); + if (me.type == TSDB_SUPER_TABLE) { + if (sver == -1 || sver == me.stbEntry.schemaRow.version) { + pSchema = tCloneSSchemaWrapper(&me.stbEntry.schemaRow); + tDecoderClear(&dc); + goto _exit; + } + } else if (me.type == TSDB_CHILD_TABLE) { + uid = me.ctbEntry.suid; + tDecoderClear(&dc); + goto _query; + } else { + if (sver == -1 || sver == me.ntbEntry.schemaRow.version) { + pSchema = tCloneSSchemaWrapper(&me.ntbEntry.schemaRow); + tDecoderClear(&dc); + goto _exit; + } + } + tDecoderClear(&dc); + + // query from skm db + if (tdbTbGet(pMeta->pSkmDb, &(SSkmDbKey){.uid = uid, .sver = sver}, sizeof(SSkmDbKey), &pData, &nData) < 0) { + goto _err; + } + + tDecoderInit(&dc, pData, nData); + tDecodeSSchemaWrapper(&dc, &schema); + pSchema = tCloneSSchemaWrapper(&schema); + tDecoderClear(&dc); + +_exit: metaULock(pMeta); tdbFree(pData); return pSchema; @@ -205,11 +215,11 @@ _err: } struct SMCtbCursor { - SMeta * pMeta; - TBC * pCur; + SMeta *pMeta; + TBC *pCur; tb_uid_t suid; - void * pKey; - void * pVal; + void *pKey; + void *pVal; int kLen; int vLen; }; @@ -279,25 +289,13 @@ tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) { } STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { - tb_uid_t quid; - SMetaReader mr = {0}; - STSchema * pTSchema = NULL; + // SMetaReader mr = {0}; + STSchema *pTSchema = NULL; SSchemaWrapper *pSW = NULL; STSchemaBuilder sb = {0}; - SSchema * pSchema; + SSchema *pSchema; - metaReaderInit(&mr, pMeta, 0); - metaGetTableEntryByUid(&mr, uid); - - if (mr.me.type == TSDB_CHILD_TABLE) { - quid = mr.me.ctbEntry.suid; - } else { - quid = uid; - } - - metaReaderClear(&mr); - - pSW = metaGetTableSchema(pMeta, quid, sver, 0); + pSW = metaGetTableSchema(pMeta, uid, sver, 0); if (!pSW) return NULL; tdInitTSchemaBuilder(&sb, pSW->version); @@ -321,11 +319,11 @@ int metaGetTbNum(SMeta *pMeta) { } typedef struct { - SMeta * pMeta; - TBC * pCur; + SMeta *pMeta; + TBC *pCur; tb_uid_t uid; - void * pKey; - void * pVal; + void *pKey; + void *pVal; int kLen; int vLen; } SMSmaCursor; @@ -397,7 +395,7 @@ tb_uid_t metaSmaCursorNext(SMSmaCursor *pSmaCur) { STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) { STSmaWrapper *pSW = NULL; - SArray * pSmaIds = NULL; + SArray *pSmaIds = NULL; if (!(pSmaIds = metaGetSmaIdsByTable(pMeta, uid))) { return NULL; @@ -421,7 +419,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) { metaReaderInit(&mr, pMeta, 0); int64_t smaId; int smaIdx = 0; - STSma * pTSma = NULL; + STSma *pTSma = NULL; for (int i = 0; i < pSW->number; ++i) { smaId = *(tb_uid_t *)taosArrayGet(pSmaIds, i); if (metaGetTableEntryByUid(&mr, smaId) < 0) { @@ -469,7 +467,7 @@ _err: } STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) { - STSma * pTSma = NULL; + STSma *pTSma = NULL; SMetaReader mr = {0}; metaReaderInit(&mr, pMeta, 0); if (metaGetTableEntryByUid(&mr, indexUid) < 0) { @@ -491,7 +489,7 @@ STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) { } SArray *metaGetSmaIdsByTable(SMeta *pMeta, tb_uid_t uid) { - SArray * pUids = NULL; + SArray *pUids = NULL; SSmaIdxKey *pSmaIdxKey = NULL; SMSmaCursor *pCur = metaOpenSmaCursor(pMeta, uid); @@ -529,7 +527,7 @@ SArray *metaGetSmaIdsByTable(SMeta *pMeta, tb_uid_t uid) { } SArray *metaGetSmaTbUids(SMeta *pMeta) { - SArray * pUids = NULL; + SArray *pUids = NULL; SSmaIdxKey *pSmaIdxKey = NULL; tb_uid_t lastUid = 0; @@ -591,13 +589,13 @@ const void *metaGetTableTagVal(SMetaEntry *pEntry, int16_t type, STagVal *val) { } typedef struct { - SMeta * pMeta; - TBC * pCur; + SMeta *pMeta; + TBC *pCur; tb_uid_t suid; int16_t cid; int16_t type; - void * pKey; - void * pVal; + void *pKey; + void *pVal; int32_t kLen; int32_t vLen; } SIdxCursor; @@ -621,7 +619,7 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { int32_t nKey = 0; int32_t nTagData = 0; - void * tagData = NULL; + void *tagData = NULL; if (IS_VAR_DATA_TYPE(param->type)) { tagData = varDataVal(param->val); @@ -640,7 +638,7 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { goto END; } - void * entryKey = NULL, *entryVal = NULL; + void *entryKey = NULL, *entryVal = NULL; int32_t nEntryKey, nEntryVal; while (1) { valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, (const void **)&entryVal, &nEntryVal); diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index c6a6dd8147..9a05f9e5a0 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -61,14 +61,14 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const if (tTagToValArray((const STag *)data, &pTagVals) != 0) { return -1; } - char key[512] = {0}; SIndexMultiTerm *terms = indexMultiTermCreate(); int16_t nCols = taosArrayGetSize(pTagVals); for (int i = 0; i < nCols; i++) { STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i); char type = pTagVal->type; - sprintf(key, "%s_%s", tagName, pTagVal->pKey); + + char * key = pTagVal->pKey; int32_t nKey = strlen(key); SIndexTerm *term = NULL; @@ -93,14 +93,13 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const } else if (type == TSDB_DATA_TYPE_BOOL) { int val = *(int *)(&pTagVal->i64); int len = 0; - term = indexTermCreate(suid, ADD_VALUE, type, key, nKey, (const char *)&val, len); + term = indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_INT, key, nKey, (const char *)&val, len); } if (term != NULL) { indexMultiTermAdd(terms, term); } - memset(key, 0, sizeof(key)); } - tIndexJsonPut(pMeta->pTagIvtIdx, terms, tuid); + indexJsonPut(pMeta->pTagIvtIdx, terms, tuid); indexMultiTermDestroy(terms); #endif return 0; diff --git a/source/dnode/vnode/src/sma/sma.c b/source/dnode/vnode/src/sma/sma.c index 04f65275d7..fd5dd080ca 100644 --- a/source/dnode/vnode/src/sma/sma.c +++ b/source/dnode/vnode/src/sma/sma.c @@ -47,15 +47,16 @@ int32_t tdUpdateExpireWindow(SSma* pSma, const SSubmitReq* pMsg, int64_t version int32_t tdGetTSmaData(SSma* pSma, char* pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult) { int32_t code = TSDB_CODE_SUCCESS; if ((code = tdGetTSmaDataImpl(pSma, pData, indexUid, querySKey, nMaxResult)) < 0) { - smaWarn("vgId:%d, get tSma data failed since %s", SMA_VID(pSma), tstrerror(terrno)); + smaWarn("vgId:%d, get tsma data failed since %s", SMA_VID(pSma), tstrerror(terrno)); } return code; } -int32_t smaGetTSmaDays(SVnodeCfg* pCfg, void* pCont, uint32_t contLen, int32_t *days) { +int32_t smaGetTSmaDays(SVnodeCfg* pCfg, void* pCont, uint32_t contLen, int32_t* days) { int32_t code = TSDB_CODE_SUCCESS; if ((code = tdGetTSmaDaysImpl(pCfg, pCont, contLen, days)) < 0) { - smaWarn("vgId:%d get tSma days failed since %s", pCfg->vgId, tstrerror(terrno)); + smaWarn("vgId:%d, get tsma days failed since %s", pCfg->vgId, tstrerror(terrno)); } + smaDebug("vgId:%d, get tsma days %d", pCfg->vgId, *days); return code; } diff --git a/source/dnode/vnode/src/sma/smaTimeRange2.c b/source/dnode/vnode/src/sma/smaTimeRange2.c index 5ef171c799..09adc1a6a2 100644 --- a/source/dnode/vnode/src/sma/smaTimeRange2.c +++ b/source/dnode/vnode/src/sma/smaTimeRange2.c @@ -97,12 +97,16 @@ int32_t tdGetTSmaDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_ goto _err; } STsdbCfg *pTsdbCfg = &pCfg->tsdbCfg; - int64_t mInterval = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_MINUTE); - int64_t records = pTsdbCfg->days / mInterval; - + int64_t sInterval = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_SECOND); + if (sInterval <= 0) { + *days = pTsdbCfg->days; + return 0; + } + int64_t records = pTsdbCfg->days * 60 / sInterval; if (records >= SMA_STORAGE_SPLIT_FACTOR) { *days = pTsdbCfg->days; } else { + int64_t mInterval = convertTimeFromPrecisionToUnit(tsma.interval, pTsdbCfg->precision, TIME_UNIT_MINUTE); int64_t daysPerFile = mInterval * SMA_STORAGE_MINUTES_DAY * 2; if (daysPerFile > SMA_STORAGE_MINUTES_MAX) { @@ -111,7 +115,7 @@ int32_t tdGetTSmaDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_ *days = (int32_t)daysPerFile; } - if(*days < pTsdbCfg->days) { + if (*days < pTsdbCfg->days) { *days = pTsdbCfg->days; } } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 310b59b2e8..a1b8d81d58 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -216,8 +216,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { } // TODO wrap in destroy func - taosArrayDestroy(rsp.blockData); taosArrayDestroy(rsp.blockDataLen); + taosArrayDestroyP(rsp.blockData, (FDelete)taosMemoryFree); if (rsp.withSchema) { taosArrayDestroyP(rsp.blockSchema, (FDelete)tDeleteSSchemaWrapper); @@ -266,7 +266,7 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { pHandle->execHandle.pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta); } if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { - pHandle->execHandle.exec.execCol.qmsg = req.qmsg; + pHandle->execHandle.execCol.qmsg = req.qmsg; req.qmsg = NULL; for (int32_t i = 0; i < 5; i++) { SReadHandle handle = { @@ -274,15 +274,14 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { .meta = pTq->pVnode->pMeta, .pMsgCb = &pTq->pVnode->msgCb, }; - pHandle->execHandle.exec.execCol.task[i] = - qCreateStreamExecTaskInfo(pHandle->execHandle.exec.execCol.qmsg, &handle); - ASSERT(pHandle->execHandle.exec.execCol.task[i]); + pHandle->execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle); + ASSERT(pHandle->execHandle.execCol.task[i]); } } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) { - pHandle->execHandle.exec.execDb.pFilterOutTbUid = + pHandle->execHandle.execDb.pFilterOutTbUid = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) { - pHandle->execHandle.exec.execTb.suid = req.suid; + pHandle->execHandle.execTb.suid = req.suid; SArray* tbUidList = taosArrayInit(0, sizeof(int64_t)); tsdbGetCtbIdList(pTq->pVnode->pMeta, req.suid, tbUidList); tqDebug("vg %d, tq try get suid: %ld", pTq->pVnode->config.vgId, req.suid); @@ -296,17 +295,20 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { taosArrayDestroy(tbUidList); } taosHashPut(pTq->handles, req.subKey, strlen(req.subKey), pHandle, sizeof(STqHandle)); + if (tqMetaSaveHandle(pTq, req.subKey, pHandle) < 0) { + // TODO + } } else { /*ASSERT(pExec->consumerId == req.oldConsumerId);*/ // TODO handle qmsg and exec modification atomic_store_32(&pHandle->epoch, -1); atomic_store_64(&pHandle->consumerId, req.newConsumerId); atomic_add_fetch_32(&pHandle->epoch, 1); + if (tqMetaSaveHandle(pTq, req.subKey, pHandle) < 0) { + // TODO + } } - if (tqMetaSaveHandle(pTq, req.subKey, pHandle) < 0) { - // TODO - } return 0; } @@ -323,16 +325,13 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { tDecoderClear(&decoder); pTask->status = TASK_STATUS__IDLE; + + pTask->inputQueue = streamQueueOpen(); + pTask->outputQueue = streamQueueOpen(); pTask->inputStatus = TASK_INPUT_STATUS__NORMAL; pTask->outputStatus = TASK_OUTPUT_STATUS__NORMAL; - pTask->inputQ = taosOpenQueue(); - pTask->outputQ = taosOpenQueue(); - pTask->inputQAll = taosAllocateQall(); - pTask->outputQAll = taosAllocateQall(); - - if (pTask->inputQ == NULL || pTask->outputQ == NULL || pTask->inputQAll == NULL || pTask->outputQAll == NULL) - goto FAIL; + if (pTask->inputQueue == NULL || pTask->outputQueue == NULL) goto FAIL; // exec if (pTask->execType != TASK_EXEC__NONE) { @@ -350,8 +349,9 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { } // sink - pTask->ahandle = pTq->pVnode; + /*pTask->ahandle = pTq->pVnode;*/ if (pTask->sinkType == TASK_SINK__SMA) { + pTask->smaSink.vnode = pTq->pVnode; pTask->smaSink.smaSink = smaHandleRes; } else if (pTask->sinkType == TASK_SINK__TABLE) { pTask->tbSink.vnode = pTq->pVnode; @@ -369,10 +369,8 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { return 0; FAIL: - if (pTask->inputQ) taosCloseQueue(pTask->inputQ); - if (pTask->outputQ) taosCloseQueue(pTask->outputQ); - if (pTask->inputQAll) taosFreeQall(pTask->inputQAll); - if (pTask->outputQAll) taosFreeQall(pTask->outputQAll); + if (pTask->inputQueue) streamQueueClose(pTask->inputQueue); + if (pTask->outputQueue) streamQueueClose(pTask->outputQueue); if (pTask) taosMemoryFree(pTask); return -1; } @@ -393,38 +391,16 @@ int32_t tqProcessStreamTrigger(STQ* pTq, SSubmitReq* pReq) { SStreamTask* pTask = (SStreamTask*)pIter; if (pTask->inputType != STREAM_INPUT__DATA_SUBMIT) continue; - int8_t inputStatus = atomic_load_8(&pTask->inputStatus); - if (inputStatus == TASK_INPUT_STATUS__NORMAL) { - if (failed) { - atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED); + if (!failed) { + if (streamTaskInput(pTask, (SStreamQueueItem*)pSubmit) < 0) { continue; } - SStreamDataSubmit* pSubmitClone = streamSubmitRefClone(pSubmit); - if (pSubmitClone == NULL) { - atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED); + if (streamTriggerByWrite(pTask, pTq->pVnode->config.vgId, &pTq->pVnode->msgCb) < 0) { continue; } - taosWriteQitem(pTask->inputQ, pSubmitClone); - - int8_t execStatus = atomic_load_8(&pTask->status); - if (execStatus == TASK_STATUS__IDLE || execStatus == TASK_STATUS__CLOSING) { - SStreamTaskRunReq* pRunReq = taosMemoryMalloc(sizeof(SStreamTaskRunReq)); - if (pRunReq == NULL) continue; - // TODO: do we need htonl? - pRunReq->head.vgId = pTq->pVnode->config.vgId; - pRunReq->streamId = pTask->streamId; - pRunReq->taskId = pTask->taskId; - SRpcMsg msg = { - .msgType = TDMT_VND_TASK_RUN, - .pCont = pRunReq, - .contLen = sizeof(SStreamTaskRunReq), - }; - tmsgPutToQueue(&pTq->pVnode->msgCb, FETCH_QUEUE, &msg); - } - } else { - // blocked or stopped, do nothing + streamTaskInputFail(pTask); } } @@ -446,10 +422,20 @@ int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) { } int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg) { - SStreamDispatchReq* pReq = pMsg->pCont; - int32_t taskId = pReq->taskId; - SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - streamProcessDispatchReq(pTask, &pTq->pVnode->msgCb, pReq, pMsg); + char* msgStr = pMsg->pCont; + char* msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + SStreamDispatchReq req; + SDecoder decoder; + tDecoderInit(&decoder, msgBody, msgLen); + tDecodeStreamDispatchReq(&decoder, &req); + int32_t taskId = req.taskId; + SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + SRpcMsg rsp = { + .info = pMsg->info, + .code = 0, + }; + streamProcessDispatchReq(pTask, &pTq->pVnode->msgCb, &req, &rsp); return 0; } @@ -462,7 +448,7 @@ int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg) { } int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) { - SStreamDispatchRsp* pRsp = pMsg->pCont; + SStreamDispatchRsp* pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); int32_t taskId = pRsp->taskId; SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); streamProcessDispatchRsp(pTask, &pTq->pVnode->msgCb, pRsp); diff --git a/source/dnode/vnode/src/tq/tqExec.c b/source/dnode/vnode/src/tq/tqExec.c index b8fec34b57..7c75d88a83 100644 --- a/source/dnode/vnode/src/tq/tqExec.c +++ b/source/dnode/vnode/src/tq/tqExec.c @@ -39,6 +39,9 @@ static int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, SMqDataBlkRsp* pRs static int32_t tqAddBlockSchemaToRsp(const STqExecHandle* pExec, int32_t workerId, SMqDataBlkRsp* pRsp) { SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pExecReader[workerId]->pSchemaWrapper); + if (pSW == NULL) { + return -1; + } taosArrayPush(pRsp->blockSchema, &pSW); return 0; } @@ -59,7 +62,7 @@ static int32_t tqAddTbNameToRsp(const STQ* pTq, const STqExecHandle* pExec, SMqD int32_t tqDataExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataBlkRsp* pRsp, int32_t workerId) { if (pExec->subType == TOPIC_SUB_TYPE__COLUMN) { - qTaskInfo_t task = pExec->exec.execCol.task[workerId]; + qTaskInfo_t task = pExec->execCol.task[workerId]; ASSERT(task); qSetStreamInput(task, pReq, STREAM_DATA_TYPE_SUBMIT_BLOCK, false); while (1) { @@ -101,7 +104,7 @@ int32_t tqDataExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataBlkR pRsp->withSchema = 1; STqReadHandle* pReader = pExec->pExecReader[workerId]; tqReadHandleSetMsg(pReader, pReq, 0); - while (tqNextDataBlockFilterOut(pReader, pExec->exec.execDb.pFilterOutTbUid)) { + while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) { SSDataBlock block = {0}; if (tqRetrieveDataBlock(&block.pDataBlock, pReader, &block.info.groupId, &block.info.uid, &block.info.rows, &block.info.numOfCols) < 0) { diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c index 9447c4007b..398a09ecbc 100644 --- a/source/dnode/vnode/src/tq/tqMeta.c +++ b/source/dnode/vnode/src/tq/tqMeta.c @@ -22,7 +22,7 @@ static int32_t tEncodeSTqHandle(SEncoder* pEncoder, const STqHandle* pHandle) { if (tEncodeI32(pEncoder, pHandle->epoch) < 0) return -1; if (tEncodeI8(pEncoder, pHandle->execHandle.subType) < 0) return -1; if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { - if (tEncodeCStr(pEncoder, pHandle->execHandle.exec.execCol.qmsg) < 0) return -1; + if (tEncodeCStr(pEncoder, pHandle->execHandle.execCol.qmsg) < 0) return -1; } tEndEncode(pEncoder); return pEncoder->pos; @@ -35,7 +35,7 @@ static int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle) { if (tDecodeI32(pDecoder, &pHandle->epoch) < 0) return -1; if (tDecodeI8(pDecoder, &pHandle->execHandle.subType) < 0) return -1; if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { - if (tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.exec.execCol.qmsg) < 0) return -1; + if (tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.execCol.qmsg) < 0) return -1; } tEndDecode(pDecoder); return 0; @@ -88,12 +88,11 @@ int32_t tqMetaOpen(STQ* pTq) { .meta = pTq->pVnode->pMeta, .pMsgCb = &pTq->pVnode->msgCb, }; - handle.execHandle.exec.execCol.task[i] = - qCreateStreamExecTaskInfo(handle.execHandle.exec.execCol.qmsg, &reader); - ASSERT(handle.execHandle.exec.execCol.task[i]); + handle.execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(handle.execHandle.execCol.qmsg, &reader); + ASSERT(handle.execHandle.execCol.task[i]); } } else { - handle.execHandle.exec.execDb.pFilterOutTbUid = + handle.execHandle.execDb.pFilterOutTbUid = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); } taosHashPut(pTq->handles, pKey, kLen, &handle, sizeof(STqHandle)); diff --git a/source/dnode/vnode/src/tq/tqPush.c b/source/dnode/vnode/src/tq/tqPush.c index d94c3e387a..9be94eb5b6 100644 --- a/source/dnode/vnode/src/tq/tqPush.c +++ b/source/dnode/vnode/src/tq/tqPush.c @@ -29,13 +29,13 @@ static int32_t tqLoopExecFromQueue(STQ* pTq, STqHandle* pHandle, SStreamDataSubm } // update processed atomic_store_64(&pHandle->pushHandle.processedVer, pSubmit->ver); - streamQSetSuccess(&pHandle->pushHandle.inputQ); + streamQueueProcessSuccess(&pHandle->pushHandle.inputQ); streamDataSubmitRefDec(pSubmit); if (pRsp->blockNum > 0) { *ppSubmit = pSubmit; return 0; } else { - pSubmit = streamQNextItem(&pHandle->pushHandle.inputQ); + pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ); } } *ppSubmit = pSubmit; @@ -52,14 +52,14 @@ int32_t tqExecFromInputQ(STQ* pTq, STqHandle* pHandle) { // 2. check processedVer // 2.1. if not missed, get msg from queue // 2.2. if missed, scan wal - pSubmit = streamQNextItem(&pHandle->pushHandle.inputQ); + pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ); while (pHandle->pushHandle.processedVer <= pSubmit->ver) { // read from wal } while (pHandle->pushHandle.processedVer > pSubmit->ver + 1) { - streamQSetSuccess(&pHandle->pushHandle.inputQ); + streamQueueProcessSuccess(&pHandle->pushHandle.inputQ); streamDataSubmitRefDec(pSubmit); - pSubmit = streamQNextItem(&pHandle->pushHandle.inputQ); + pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ); if (pSubmit == NULL) break; } // 3. exec, after each success, update processed ver diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index 8909a00c72..2ecaeff747 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -141,10 +141,10 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p } // this interface use suid instead of uid - pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, pHandle->msgIter.suid, sversion, true); + pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, pHandle->msgIter.uid, sversion, true); if (pHandle->pSchemaWrapper == NULL) { tqWarn("cannot found schema wrapper for table: suid: %ld, version %d, possibly dropped table", - pHandle->msgIter.suid, pHandle->cachedSchemaVer); + pHandle->msgIter.uid, pHandle->cachedSchemaVer); /*ASSERT(0);*/ terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND; return -1; @@ -307,7 +307,7 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) { STqHandle* pExec = (STqHandle*)pIter; if (pExec->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { for (int32_t i = 0; i < 5; i++) { - int32_t code = qUpdateQualifiedTableId(pExec->execHandle.exec.execCol.task[i], tbUidList, isAdd); + int32_t code = qUpdateQualifiedTableId(pExec->execHandle.execCol.task[i], tbUidList, isAdd); ASSERT(code == 0); } } else if (pExec->execHandle.subType == TOPIC_SUB_TYPE__DB) { @@ -315,7 +315,7 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) { int32_t sz = taosArrayGetSize(tbUidList); for (int32_t i = 0; i < sz; i++) { int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i); - taosHashPut(pExec->execHandle.exec.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0); + taosHashPut(pExec->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0); } } } else { diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 59a795b77a..17b8afda4b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -18,8 +18,8 @@ #define TSDB_MAX_SUBBLOCKS 8 typedef struct { - STable *pTable; - SSkipListIterator *pIter; + STable *pTable; + STbDataIter *pIter; } SCommitIter; typedef struct { @@ -28,6 +28,8 @@ typedef struct { int niters; // memory iterators SCommitIter *iters; bool isRFileSet; // read and commit FSET + int32_t fid; + SDFileSet *pSet; SReadH readh; SDFileSet wSet; bool isDFileSame; @@ -58,26 +60,29 @@ typedef struct { #define TSDB_COMMIT_DEFAULT_ROWS(ch) TSDB_DEFAULT_BLOCK_ROWS(TSDB_COMMIT_REPO(ch)->pVnode->config.tsdbCfg.maxRows) #define TSDB_COMMIT_TXN_VERSION(ch) FS_TXN_VERSION(REPO_FS(TSDB_COMMIT_REPO(ch))) -static void tsdbStartCommit(STsdb *pRepo); -static void tsdbEndCommit(STsdb *pTsdb, int eno); -static int tsdbInitCommitH(SCommitH *pCommith, STsdb *pRepo); -static void tsdbSeekCommitIter(SCommitH *pCommith, TSKEY key); -static int tsdbNextCommitFid(SCommitH *pCommith); -static void tsdbDestroyCommitH(SCommitH *pCommith); -static int tsdbCreateCommitIters(SCommitH *pCommith); -static void tsdbDestroyCommitIters(SCommitH *pCommith); -static int tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid); -static void tsdbResetCommitFile(SCommitH *pCommith); -static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid); -static int tsdbCommitToTable(SCommitH *pCommith, int tid); -static bool tsdbCommitIsSameFile(SCommitH *pCommith, int bidx); -static int tsdbMoveBlkIdx(SCommitH *pCommith, SBlockIdx *pIdx); -static int tsdbSetCommitTable(SCommitH *pCommith, STable *pTable); -static int tsdbComparKeyBlock(const void *arg1, const void *arg2); -static int tsdbWriteBlockInfo(SCommitH *pCommih); -static int tsdbCommitMemData(SCommitH *pCommith, SCommitIter *pIter, TSKEY keyLimit, bool toData); -static int tsdbMergeMemData(SCommitH *pCommith, SCommitIter *pIter, int bidx); -static int tsdbMoveBlock(SCommitH *pCommith, int bidx); +static int32_t tsdbCommitData(SCommitH *pCommith); +static int32_t tsdbCommitDel(SCommitH *pCommith); +static int32_t tsdbCommitCache(SCommitH *pCommith); +static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitH *pCHandle); +static int32_t tsdbEndCommit(SCommitH *pCHandle, int eno); + +static int tsdbInitCommitH(SCommitH *pCommith, STsdb *pRepo); +static void tsdbSeekCommitIter(SCommitH *pCommith, TSKEY key); +static int tsdbNextCommitFid(SCommitH *pCommith); +static void tsdbDestroyCommitH(SCommitH *pCommith); +static int32_t tsdbCreateCommitIters(SCommitH *pCommith); +static void tsdbDestroyCommitIters(SCommitH *pCommith); +static int tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid); +static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid); +static int tsdbCommitToTable(SCommitH *pCommith, int tid); +static bool tsdbCommitIsSameFile(SCommitH *pCommith, int bidx); +static int tsdbMoveBlkIdx(SCommitH *pCommith, SBlockIdx *pIdx); +static int tsdbSetCommitTable(SCommitH *pCommith, STable *pTable); +static int tsdbComparKeyBlock(const void *arg1, const void *arg2); +static int tsdbWriteBlockInfo(SCommitH *pCommih); +static int tsdbCommitMemData(SCommitH *pCommith, SCommitIter *pIter, TSKEY keyLimit, bool toData); +static int tsdbMergeMemData(SCommitH *pCommith, SCommitIter *pIter, int bidx); +static int tsdbMoveBlock(SCommitH *pCommith, int bidx); static int tsdbCommitAddBlock(SCommitH *pCommith, const SBlock *pSupBlock, const SBlock *pSubBlocks, int nSubBlocks); static int tsdbMergeBlockData(SCommitH *pCommith, SCommitIter *pIter, SDataCols *pDataCols, TSKEY keyLimit, bool isLastOneBlock); @@ -88,11 +93,14 @@ static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *i SDataCols *pTarget, TSKEY maxKey, int maxRows, int8_t update); static int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf); static int tsdbApplyRtnOnFSet(STsdb *pRepo, SDFileSet *pSet, SRtn *pRtn); +static int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, STbDataIter *pIter, TSKEY maxKey, int maxRowsToRead, + SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, + SMergeInfo *pMergeInfo); -int tsdbBegin(STsdb *pTsdb) { +int32_t tsdbBegin(STsdb *pTsdb) { if (!pTsdb) return 0; - STsdbMemTable *pMem; + SMemTable *pMem; if (tsdbMemTableCreate(pTsdb, &pTsdb->mem) < 0) { return -1; @@ -112,15 +120,50 @@ int32_t tsdbCommit(STsdb *pTsdb) { pTsdb->mem = NULL; // start commit - tsdbStartCommit(pTsdb); - if (tsdbInitCommitH(&commith, pTsdb) < 0) { - return -1; + code = tsdbStartCommit(pTsdb, &commith); + if (code) { + goto _err; } + // commit impl + code = tsdbCommitData(&commith); + if (code) { + goto _err; + } + + code = tsdbCommitDel(&commith); + if (code) { + goto _err; + } + + code = tsdbCommitCache(&commith); + if (code) { + goto _err; + } + + // end commit + code = tsdbEndCommit(&commith, 0); + if (code) { + goto _err; + } + + return code; + +_err: + tsdbError("vgId:%d failed to commit since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} + +static int32_t tsdbCommitData(SCommitH *pCommith) { + int32_t fid; + SDFileSet *pSet = NULL; + int32_t code = 0; + STsdb *pTsdb = TSDB_COMMIT_REPO(pCommith); + // Skip expired memory data and expired FSET - tsdbSeekCommitIter(&commith, commith.rtn.minKey); - while ((pSet = tsdbFSIterNext(&(commith.fsIter)))) { - if (pSet->fid < commith.rtn.minFid) { + tsdbSeekCommitIter(pCommith, pCommith->rtn.minKey); + while ((pSet = tsdbFSIterNext(&(pCommith->fsIter)))) { + if (pSet->fid < pCommith->rtn.minFid) { tsdbInfo("vgId:%d, FSET %d on level %d disk id %d expires, remove it", REPO_ID(pTsdb), pSet->fid, TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet)); } else { @@ -129,7 +172,7 @@ int32_t tsdbCommit(STsdb *pTsdb) { } // commit - fid = tsdbNextCommitFid(&(commith)); + fid = tsdbNextCommitFid(pCommith); while (true) { // Loop over both on disk and memory if (pSet == NULL && fid == TSDB_IVLD_FID) break; @@ -137,12 +180,12 @@ int32_t tsdbCommit(STsdb *pTsdb) { if (pSet && (fid == TSDB_IVLD_FID || pSet->fid < fid)) { // Only has existing FSET but no memory data to commit in this // existing FSET, only check if file in correct retention - if (tsdbApplyRtnOnFSet(pTsdb, pSet, &(commith.rtn)) < 0) { - tsdbDestroyCommitH(&commith); + if (tsdbApplyRtnOnFSet(TSDB_COMMIT_REPO(pCommith), pSet, &(pCommith->rtn)) < 0) { + tsdbDestroyCommitH(pCommith); return -1; } - pSet = tsdbFSIterNext(&(commith.fsIter)); + pSet = tsdbFSIterNext(&(pCommith->fsIter)); } else { // Has memory data to commit SDFileSet *pCSet; @@ -156,22 +199,30 @@ int32_t tsdbCommit(STsdb *pTsdb) { // Commit to an existing FSET pCSet = pSet; cfid = pSet->fid; - pSet = tsdbFSIterNext(&(commith.fsIter)); + pSet = tsdbFSIterNext(&(pCommith->fsIter)); } - if (tsdbCommitToFile(&commith, pCSet, cfid) < 0) { - tsdbDestroyCommitH(&commith); + if (tsdbCommitToFile(pCommith, pCSet, cfid) < 0) { + tsdbDestroyCommitH(pCommith); return -1; } - fid = tsdbNextCommitFid(&commith); + fid = tsdbNextCommitFid(pCommith); } } - // end commit - tsdbDestroyCommitH(&commith); - tsdbEndCommit(pTsdb, TSDB_CODE_SUCCESS); + return code; +} +static int32_t tsdbCommitDel(SCommitH *pCommith) { + int32_t code = 0; + // TODO + return code; +} + +static int32_t tsdbCommitCache(SCommitH *pCommith) { + int32_t code = 0; + // TODO return code; } @@ -216,16 +267,6 @@ static int tsdbApplyRtnOnFSet(STsdb *pRepo, SDFileSet *pSet, SRtn *pRtn) { return 0; } -// int tsdbPrepareCommit(STsdb *pTsdb) { -// if (pTsdb->mem == NULL) return 0; - -// ASSERT(pTsdb->imem == NULL); - -// pTsdb->imem = pTsdb->mem; -// pTsdb->mem = NULL; -// return 0; -// } - void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) { STsdbKeepCfg *pCfg = REPO_KEEP_CFG(pRepo); TSKEY minKey, midKey, maxKey, now; @@ -243,19 +284,32 @@ void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) { pRtn->minFid, pRtn->midFid, pRtn->maxFid); } -static void tsdbStartCommit(STsdb *pRepo) { - STsdbMemTable *pMem = pRepo->imem; +static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitH *pCHandle) { + int32_t code = 0; - tsdbInfo("vgId:%d, start to commit", REPO_ID(pRepo)); + tsdbInfo("vgId:%d, start to commit", REPO_ID(pTsdb)); - tsdbStartFSTxn(pRepo, 0, 0); + if (tsdbInitCommitH(pCHandle, pTsdb) < 0) { + return -1; + } + + tsdbStartFSTxn(pTsdb, 0, 0); + + return code; } -static void tsdbEndCommit(STsdb *pTsdb, int eno) { +static int32_t tsdbEndCommit(SCommitH *pCHandle, int eno) { + int32_t code = 0; + STsdb *pTsdb = TSDB_COMMIT_REPO(pCHandle); + + tsdbDestroyCommitH(pCHandle); tsdbEndFSTxn(pTsdb); tsdbMemTableDestroy(pTsdb->imem); pTsdb->imem = NULL; + tsdbInfo("vgId:%d, commit over, %s", REPO_ID(pTsdb), (eno == TSDB_CODE_SUCCESS) ? "succeed" : "failed"); + + return code; } static int tsdbInitCommitH(SCommitH *pCommith, STsdb *pRepo) { @@ -354,34 +408,73 @@ static void tsdbDestroyCommitH(SCommitH *pCommith) { tsdbCloseDFileSet(TSDB_COMMIT_WRITE_FSET(pCommith)); } -static int tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid) { - STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); +static int32_t tsdbCommitToFileStart(SCommitH *pCHandle, SDFileSet *pSet, int32_t fid) { + int32_t code = 0; + STsdb *pRepo = TSDB_COMMIT_REPO(pCHandle); STsdbKeepCfg *pCfg = REPO_KEEP_CFG(pRepo); ASSERT(pSet == NULL || pSet->fid == fid); - tsdbResetCommitFile(pCommith); - tsdbGetFidKeyRange(pCfg->days, pCfg->precision, fid, &(pCommith->minKey), &(pCommith->maxKey)); + pCHandle->fid = fid; + pCHandle->pSet = pSet; + pCHandle->isRFileSet = false; + pCHandle->isDFileSame = false; + pCHandle->isLFileSame = false; + taosArrayClear(pCHandle->aBlkIdx); - // Set and open files - if (tsdbSetAndOpenCommitFile(pCommith, pSet, fid) < 0) { + tsdbGetFidKeyRange(pCfg->days, pCfg->precision, fid, &(pCHandle->minKey), &(pCHandle->maxKey)); + + code = tsdbSetAndOpenCommitFile(pCHandle, pSet, fid); + + return code; +} +static int32_t tsdbCommitToFileImpl(SCommitH *pCHandle) { + int32_t code = 0; + // TODO + return code; +} +static int32_t tsdbCommitToFileEnd(SCommitH *pCommith) { + int32_t code = 0; + STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); + + if (tsdbWriteBlockIdx(TSDB_COMMIT_HEAD_FILE(pCommith), pCommith->aBlkIdx, (void **)(&(TSDB_COMMIT_BUF(pCommith)))) < + 0) { + tsdbError("vgId:%d, failed to write SBlockIdx part to FSET %d since %s", REPO_ID(pRepo), pCommith->fid, + tstrerror(terrno)); + tsdbCloseCommitFile(pCommith, true); + // revert the file change + tsdbApplyDFileSetChange(TSDB_COMMIT_WRITE_FSET(pCommith), pCommith->pSet); return -1; } -#if 0 - // Loop to commit each table data - for (int tid = 0; tid < pCommith->niters; tid++) { - SCommitIter *pIter = pCommith->iters + tid; - if (pIter->pTable == NULL) continue; - - if (tsdbCommitToTable(pCommith, tid) < 0) { - tsdbCloseCommitFile(pCommith, true); - // revert the file change - tsdbApplyDFileSetChange(TSDB_COMMIT_WRITE_FSET(pCommith), pSet); - return -1; - } + if (tsdbUpdateDFileSetHeader(&(pCommith->wSet)) < 0) { + tsdbError("vgId:%d, failed to update FSET %d header since %s", REPO_ID(pRepo), pCommith->fid, tstrerror(terrno)); + tsdbCloseCommitFile(pCommith, true); + // revert the file change + tsdbApplyDFileSetChange(TSDB_COMMIT_WRITE_FSET(pCommith), pCommith->pSet); + return -1; } -#endif + + // Close commit file + tsdbCloseCommitFile(pCommith, false); + + if (tsdbUpdateDFileSet(REPO_FS(pRepo), &(pCommith->wSet)) < 0) { + return -1; + } + + return code; +} +static int32_t tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid) { + int32_t code = 0; + STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); + STsdbKeepCfg *pCfg = REPO_KEEP_CFG(pRepo); + + // commit to file start + code = tsdbCommitToFileStart(pCommith, pSet, fid); + if (code) { + goto _err; + } + // Loop to commit each table data in mem and file int mIter = 0, fIter = 0; int nBlkIdx = taosArrayGetSize(pCommith->readh.aBlkIdx); @@ -400,7 +493,7 @@ static int tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid) { break; } - if (pIter && pIter->pTable && (!pIdx || (pIter->pTable->uid <= pIdx->uid))) { + if (pIter && pIter->pTable && (!pIdx || (pIter->pTable->suid <= pIdx->suid || pIter->pTable->uid <= pIdx->uid))) { if (tsdbCommitToTable(pCommith, mIter) < 0) { tsdbCloseCommitFile(pCommith, true); // revert the file change @@ -426,84 +519,60 @@ static int tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid) { } } - if (tsdbWriteBlockIdx(TSDB_COMMIT_HEAD_FILE(pCommith), pCommith->aBlkIdx, (void **)(&(TSDB_COMMIT_BUF(pCommith)))) < - 0) { - tsdbError("vgId:%d, failed to write SBlockIdx part to FSET %d since %s", REPO_ID(pRepo), fid, tstrerror(terrno)); - tsdbCloseCommitFile(pCommith, true); - // revert the file change - tsdbApplyDFileSetChange(TSDB_COMMIT_WRITE_FSET(pCommith), pSet); - return -1; + // commit to file end + code = tsdbCommitToFileEnd(pCommith); + if (code) { + goto _err; } - if (tsdbUpdateDFileSetHeader(&(pCommith->wSet)) < 0) { - tsdbError("vgId:%d, failed to update FSET %d header since %s", REPO_ID(pRepo), fid, tstrerror(terrno)); - tsdbCloseCommitFile(pCommith, true); - // revert the file change - tsdbApplyDFileSetChange(TSDB_COMMIT_WRITE_FSET(pCommith), pSet); - return -1; - } + return code; - // Close commit file - tsdbCloseCommitFile(pCommith, false); - - if (tsdbUpdateDFileSet(REPO_FS(pRepo), &(pCommith->wSet)) < 0) { - return -1; - } - - return 0; +_err: + return code; } -static int tsdbCreateCommitIters(SCommitH *pCommith) { - STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); - STsdbMemTable *pMem = pRepo->imem; - SSkipListIterator *pSlIter; - SCommitIter *pCommitIter; - SSkipListNode *pNode; - STbData *pTbData; - STSchema *pTSchema = NULL; +static int32_t tsdbCreateCommitIters(SCommitH *pCommith) { + int32_t code = 0; + STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); + SMemTable *pMem = pRepo->imem; + STbData *pTbData; + SCommitIter *pCommitIter; + STSchema *pTSchema = NULL; - pCommith->niters = SL_SIZE(pMem->pSlIdx); + pCommith->niters = taosArrayGetSize(pMem->aTbData); pCommith->iters = (SCommitIter *)taosMemoryCalloc(pCommith->niters, sizeof(SCommitIter)); if (pCommith->iters == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; } - // Loop to create iters for each skiplist - pSlIter = tSkipListCreateIter(pMem->pSlIdx); - if (pSlIter == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } - for (int i = 0; i < pCommith->niters; i++) { - tSkipListIterNext(pSlIter); - pNode = tSkipListIterGet(pSlIter); - pTbData = (STbData *)pNode->pData; + for (int32_t iIter = 0; iIter < pCommith->niters; iIter++) { + pTbData = (STbData *)taosArrayGetP(pMem->aTbData, iIter); + pCommitIter = &pCommith->iters[iIter]; - pCommitIter = pCommith->iters + i; pTSchema = metaGetTbTSchema(REPO_META(pRepo), pTbData->uid, -1); - if (pTSchema) { - pCommitIter->pIter = tSkipListCreateIter(pTbData->pData); - tSkipListIterNext(pCommitIter->pIter); + tsdbTbDataIterCreate(pTbData, NULL, 0, &pCommitIter->pIter); pCommitIter->pTable = (STable *)taosMemoryMalloc(sizeof(STable)); pCommitIter->pTable->uid = pTbData->uid; - pCommitIter->pTable->tid = pTbData->uid; + pCommitIter->pTable->suid = pTbData->suid; pCommitIter->pTable->pSchema = pTSchema; pCommitIter->pTable->pCacheSchema = NULL; } } - tSkipListDestroyIter(pSlIter); - return 0; + return code; + +_err: + return code; } static void tsdbDestroyCommitIters(SCommitH *pCommith) { if (pCommith->iters == NULL) return; for (int i = 1; i < pCommith->niters; i++) { - tSkipListDestroyIter(pCommith->iters[i].pIter); + tsdbTbDataIterDestroy(pCommith->iters[i].pIter); if (pCommith->iters[i].pTable) { tdFreeSchema(pCommith->iters[i].pTable->pSchema); tdFreeSchema(pCommith->iters[i].pTable->pCacheSchema); @@ -516,13 +585,6 @@ static void tsdbDestroyCommitIters(SCommitH *pCommith) { pCommith->niters = 0; } -static void tsdbResetCommitFile(SCommitH *pCommith) { - pCommith->isRFileSet = false; - pCommith->isDFileSame = false; - pCommith->isLFileSame = false; - taosArrayClear(pCommith->aBlkIdx); -} - static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid) { SDiskID did; STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); @@ -743,8 +805,8 @@ static int tsdbWriteBlockInfoImpl(SDFile *pHeadf, STable *pTable, SArray *pSupA, pBlkInfo = *ppBuf; pBlkInfo->delimiter = TSDB_FILE_DELIMITER; - pBlkInfo->tid = TABLE_TID(pTable); - pBlkInfo->uid = TABLE_UID(pTable); + pBlkInfo->suid = pTable->suid; + pBlkInfo->uid = pTable->uid; memcpy((void *)(pBlkInfo->blocks), taosArrayGet(pSupA, 0), nSupBlocks * sizeof(SBlock)); if (nSubBlocks > 0) { @@ -770,7 +832,8 @@ static int tsdbWriteBlockInfoImpl(SDFile *pHeadf, STable *pTable, SArray *pSupA, // Set pIdx pBlock = taosArrayGetLast(pSupA); - pIdx->uid = TABLE_UID(pTable); + pIdx->suid = pTable->suid; + pIdx->uid = pTable->uid; pIdx->hasLast = pBlock->last ? 1 : 0; pIdx->maxKey = pBlock->maxKey; pIdx->numOfBlocks = (uint32_t)nSupBlocks; @@ -925,7 +988,7 @@ static int tsdbMoveBlkIdx(SCommitH *pCommith, SBlockIdx *pIdx) { return -1; } - STable table = {.tid = pIdx->uid, .uid = pIdx->uid, .pSchema = NULL}; + STable table = {.suid = pIdx->suid, .uid = pIdx->uid, .pSchema = NULL}; pCommith->pTable = &table; while (bidx < nBlocks) { @@ -1186,7 +1249,7 @@ static int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFi } pBlockData->delimiter = TSDB_FILE_DELIMITER; - pBlockData->uid = TABLE_UID(pTable); + pBlockData->uid = pTable->uid; pBlockData->numOfCols = nColsNotAllNull; taosCalcChecksumAppend(0, (uint8_t *)pBlockData, tsize); @@ -1226,7 +1289,7 @@ static int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFi tsdbDebug("vgId:%d, uid:%" PRId64 " a block of data is written to file %s, offset %" PRId64 " numOfRows %d len %d numOfCols %" PRId16 " keyFirst %" PRId64 " keyLast %" PRId64, - REPO_ID(pRepo), TABLE_UID(pTable), TSDB_FILE_FULL_NAME(pDFile), offset, rowsToWrite, pBlock->len, + REPO_ID(pRepo), pTable->uid, TSDB_FILE_FULL_NAME(pDFile), offset, rowsToWrite, pBlock->len, pBlock->numOfCols, pBlock->minKey.ts, pBlock->maxKey.ts); return 0; @@ -1313,7 +1376,7 @@ static int tsdbMergeMemData(SCommitH *pCommith, SCommitIter *pIter, int bidx) { keyLimit = pBlock[1].minKey.ts - 1; } - SSkipListIterator titer = *(pIter->pIter); + STbDataIter titer = *(pIter->pIter); if (tsdbLoadBlockDataCols(&(pCommith->readh), pBlock, NULL, &colId, 1, false) < 0) return -1; tsdbLoadDataFromCache(TSDB_COMMIT_REPO(pCommith), pIter->pTable, &titer, keyLimit, INT32_MAX, NULL, @@ -1522,7 +1585,7 @@ static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *i lastKey = key2; } - tSkipListIterNext(pCommitIter->pIter); + tsdbTbDataIterNext(pCommitIter->pIter); } else { if (lastKey != key1) { if (lastKey != TSKEY_INITIAL_VAL) { @@ -1554,7 +1617,7 @@ static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *i tdAppendSTSRowToDataCol(row, pSchema, pTarget, true); } ++(*iter); - tSkipListIterNext(pCommitIter->pIter); + tsdbTbDataIterNext(pCommitIter->pIter); } if (pTarget->numOfRows >= (maxRows - 1)) break; @@ -1598,4 +1661,171 @@ static bool tsdbCanAddSubBlock(SCommitH *pCommith, SBlock *pBlock, SMergeInfo *p } return false; +} + +static int tsdbAppendTableRowToCols(STsdb *pTsdb, STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row, + bool merge) { + if (pCols) { + if (*ppSchema == NULL || schemaVersion(*ppSchema) != TD_ROW_SVER(row)) { + *ppSchema = tsdbGetTableSchemaImpl(pTsdb, pTable, false, false, TD_ROW_SVER(row)); + if (*ppSchema == NULL) { + ASSERT(false); + return -1; + } + } + + tdAppendSTSRowToDataCol(row, *ppSchema, pCols, merge); + } + + return 0; +} + +static int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, STbDataIter *pIter, TSKEY maxKey, int maxRowsToRead, + SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, + SMergeInfo *pMergeInfo) { + ASSERT(maxRowsToRead > 0 && nFilterKeys >= 0); + if (pIter == NULL) return 0; + STSchema *pSchema = NULL; + TSKEY rowKey = 0; + TSKEY fKey = 0; + // only fetch lastKey from mem data as file data not used in this function actually + TSKEY lastKey = TSKEY_INITIAL_VAL; + bool isRowDel = false; + int filterIter = 0; + STSRow *row = NULL; + SMergeInfo mInfo; + + // TODO: support Multi-Version(the rows with the same TS keys in memory can't be merged if its version refered by + // query handle) + + if (pMergeInfo == NULL) pMergeInfo = &mInfo; + + memset(pMergeInfo, 0, sizeof(*pMergeInfo)); + pMergeInfo->keyFirst = INT64_MAX; + pMergeInfo->keyLast = INT64_MIN; + if (pCols) tdResetDataCols(pCols); + + row = tsdbNextIterRow(pIter); + if (row == NULL || TD_ROW_KEY(row) > maxKey) { + rowKey = INT64_MAX; + isRowDel = false; + } else { + rowKey = TD_ROW_KEY(row); + isRowDel = TD_ROW_IS_DELETED(row); + } + + if (filterIter >= nFilterKeys) { + fKey = INT64_MAX; + } else { + fKey = tdGetKey(filterKeys[filterIter]); + } + // 1. fkey - no dup since merged up to maxVersion of each query handle by tsdbLoadBlockDataCols + // 2. rowKey - would dup since Multi-Version supported + while (true) { + if (fKey == INT64_MAX && rowKey == INT64_MAX) break; + + if (fKey < rowKey) { + pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, fKey); + pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, fKey); + + filterIter++; + if (filterIter >= nFilterKeys) { + fKey = INT64_MAX; + } else { + fKey = tdGetKey(filterKeys[filterIter]); + } +#if 1 + } else if (fKey > rowKey) { + if (isRowDel) { + // TODO: support delete function + pMergeInfo->rowsDeleteFailed++; + } else { + if (pMergeInfo->rowsInserted - pMergeInfo->rowsDeleteSucceed >= maxRowsToRead) break; + if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break; + + if (lastKey != rowKey) { + pMergeInfo->rowsInserted++; + pMergeInfo->nOperations++; + pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey); + pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, rowKey); + if (pCols) { + if (lastKey != TSKEY_INITIAL_VAL) { + ++pCols->numOfRows; + } + tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false); + } + lastKey = rowKey; + } else { + if (keepDup) { + tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, true); + } else { + // discard + } + } + } + + tsdbTbDataIterNext(pIter); + row = tsdbNextIterRow(pIter); + if (row == NULL || TD_ROW_KEY(row) > maxKey) { + rowKey = INT64_MAX; + isRowDel = false; + } else { + rowKey = TD_ROW_KEY(row); + isRowDel = TD_ROW_IS_DELETED(row); + } + } else { // fkey == rowKey + if (isRowDel) { // TODO: support delete function(How to stands for delete in file? rowVersion = -1?) + ASSERT(!keepDup); + if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break; + pMergeInfo->rowsDeleteSucceed++; + pMergeInfo->nOperations++; + tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false); + } else { + if (keepDup) { + if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break; + if (lastKey != rowKey) { + pMergeInfo->rowsUpdated++; + pMergeInfo->nOperations++; + pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey); + pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, rowKey); + if (pCols) { + if (lastKey != TSKEY_INITIAL_VAL) { + ++pCols->numOfRows; + } + tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false); + } + lastKey = rowKey; + } else { + tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, true); + } + } else { + pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, fKey); + pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, fKey); + } + } + + tsdbTbDataIterNext(pIter); + row = tsdbNextIterRow(pIter); + if (row == NULL || TD_ROW_KEY(row) > maxKey) { + rowKey = INT64_MAX; + isRowDel = false; + } else { + rowKey = TD_ROW_KEY(row); + isRowDel = TD_ROW_IS_DELETED(row); + } + + filterIter++; + if (filterIter >= nFilterKeys) { + fKey = INT64_MAX; + } else { + fKey = tdGetKey(filterKeys[filterIter]); + } + } +#endif + } + if (pCols && (lastKey != TSKEY_INITIAL_VAL)) { + ++pCols->numOfRows; + } + + return 0; } \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c deleted file mode 100644 index 321667c55b..0000000000 --- a/source/dnode/vnode/src/tsdb/tsdbCommit2.c +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "tsdb.h" - -typedef struct { - SMemTable *pMemTable; - int32_t minutes; - int8_t precision; - TSKEY nCommitKey; - int32_t fid; - TSKEY minKey; - TSKEY maxKey; - SReadH readh; - SDFileSet wSet; - SArray *aBlkIdx; - SArray *aSupBlk; - SArray *aSubBlk; - SArray *aDelInfo; -} SCommitH; - -static int32_t tsdbCommitStart(SCommitH *pCHandle, STsdb *pTsdb); -static int32_t tsdbCommitEnd(SCommitH *pCHandle); -static int32_t tsdbCommitImpl(SCommitH *pCHandle); - -int32_t tsdbBegin2(STsdb *pTsdb) { - int32_t code = 0; - - ASSERT(pTsdb->mem == NULL); - code = tsdbMemTableCreate2(pTsdb, (SMemTable **)&pTsdb->mem); - if (code) { - tsdbError("vgId:%d failed to begin TSDB since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); - goto _exit; - } - -_exit: - return code; -} - -int32_t tsdbCommit2(STsdb *pTsdb) { - int32_t code = 0; - SCommitH ch = {0}; - - // start to commit - code = tsdbCommitStart(&ch, pTsdb); - if (code) { - goto _exit; - } - - // commit - code = tsdbCommitImpl(&ch); - if (code) { - goto _err; - } - - // end commit - code = tsdbCommitEnd(&ch); - if (code) { - goto _exit; - } - -_exit: - return code; - -_err: - tsdbError("vgId:%d failed to commit since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); - return code; -} - -static int32_t tsdbCommitStart(SCommitH *pCHandle, STsdb *pTsdb) { - int32_t code = 0; - SMemTable *pMemTable = (SMemTable *)pTsdb->mem; - - tsdbInfo("vgId:%d start to commit", TD_VID(pTsdb->pVnode)); - - // switch to commit - ASSERT(pTsdb->imem == NULL && pTsdb->mem); - pTsdb->imem = pTsdb->mem; - pTsdb->mem = NULL; - - // open handle - pCHandle->pMemTable = pMemTable; - pCHandle->minutes = pTsdb->keepCfg.days; - pCHandle->precision = pTsdb->keepCfg.precision; - pCHandle->nCommitKey = pMemTable->minKey.ts; - - code = tsdbInitReadH(&pCHandle->readh, pTsdb); - if (code) { - goto _err; - } - pCHandle->aBlkIdx = taosArrayInit(0, sizeof(SBlockIdx)); - if (pCHandle->aBlkIdx == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - pCHandle->aSupBlk = taosArrayInit(0, sizeof(SBlock)); - if (pCHandle->aSupBlk == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - pCHandle->aSubBlk = taosArrayInit(0, sizeof(SBlock)); - if (pCHandle->aSubBlk == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - pCHandle->aDelInfo = taosArrayInit(0, sizeof(SDelInfo)); - if (pCHandle->aDelInfo == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - - // start FS transaction - tsdbStartFSTxn(pTsdb, 0, 0); - - return code; - -_err: - return code; -} - -static int32_t tsdbCommitEnd(SCommitH *pCHandle) { - int32_t code = 0; - STsdb *pTsdb = pCHandle->pMemTable->pTsdb; - SMemTable *pMemTable = (SMemTable *)pTsdb->imem; - - // end transaction - code = tsdbEndFSTxn(pTsdb); - if (code) { - goto _err; - } - - // close handle - taosArrayClear(pCHandle->aDelInfo); - taosArrayClear(pCHandle->aSubBlk); - taosArrayClear(pCHandle->aSupBlk); - taosArrayClear(pCHandle->aBlkIdx); - tsdbDestroyReadH(&pCHandle->readh); - - // destroy memtable (todo: unref it) - pTsdb->imem = NULL; - tsdbMemTableDestroy2(pMemTable); - - tsdbInfo("vgId:%d commit over", TD_VID(pTsdb->pVnode)); - return code; - -_err: - return code; -} - -static int32_t tsdbCommitTableStart(SCommitH *pCHandle) { - int32_t code = 0; - // TODO - return code; -} - -static int32_t tsdbCommitTableEnd(SCommitH *pCHandle) { - int32_t code = 0; - // TODO - return code; -} - -static int32_t tsdbCommitTable(SCommitH *pCHandle, SMemData *pMemData, SBlockIdx *pBlockIdx) { - int32_t code = 0; - SMemDataIter iter = {0}; - - // commit table start - code = tsdbCommitTableStart(pCHandle); - if (code) { - goto _err; - } - - // commit table impl - if (pMemData && pBlockIdx) { - // TODO - } else if (pMemData) { - // TODO - } else { - // TODO - } - - // commit table end - code = tsdbCommitTableEnd(pCHandle); - if (code) { - goto _err; - } - - return code; - -_err: - return code; -} - -static int32_t tsdbTableIdCmprFn(const void *p1, const void *p2) { - TABLEID *pId1 = (TABLEID *)p1; - TABLEID *pId2 = (TABLEID *)p2; - - if (pId1->suid < pId2->suid) { - return -1; - } else if (pId1->suid > pId2->suid) { - return 1; - } - - if (pId1->uid < pId2->uid) { - return -1; - } else if (pId1->uid > pId2->uid) { - return 1; - } - - return 0; -} - -static int32_t tsdbWriteBlockIdx(SDFile *pFile, SArray *pArray, uint8_t **ppBuf) { - int32_t code = 0; - // TODO - return code; -} - -static int32_t tsdbCommitFileStart(SCommitH *pCHandle) { - int32_t code = 0; - STsdb *pTsdb = pCHandle->pMemTable->pTsdb; - SDFileSet *pSet = NULL; - - taosArrayClear(pCHandle->aBlkIdx); - - return code; -} - -static int32_t tsdbCommitFileEnd(SCommitH *pCHandle) { - int32_t code = 0; - // TODO - return code; -} - -static int32_t tsdbCommitFile(SCommitH *pCHandle) { - int32_t code = 0; - SMemData *pMemData; - SBlockIdx *pBlockIdx; - int32_t iMemData; - int32_t nMemData; - int32_t iBlockIdx; - int32_t nBlockIdx; - - // commit file start - code = tsdbCommitFileStart(pCHandle); - if (code) { - goto _err; - } - - // commit file impl - iMemData = 0; - nMemData = taosArrayGetSize(pCHandle->pMemTable->aMemData); - iBlockIdx = 0; - nBlockIdx = 0; // todo - - for (;;) { - if (iMemData >= nMemData && iBlockIdx >= nBlockIdx) break; - - pMemData = NULL; - pBlockIdx = NULL; - if (iMemData < nMemData) { - pMemData = (SMemData *)taosArrayGetP(pCHandle->pMemTable->aMemData, iMemData); - } - if (iBlockIdx < nBlockIdx) { - // pBlockIdx = ; - } - - if (pMemData && pBlockIdx) { - int32_t c = tsdbTableIdCmprFn(pMemData, pBlockIdx); - if (c < 0) { - iMemData++; - pBlockIdx = NULL; - } else if (c == 0) { - iMemData++; - iBlockIdx++; - } else { - iBlockIdx++; - pMemData = NULL; - } - } else { - if (pMemData) { - iMemData++; - } else { - iBlockIdx++; - } - } - - code = tsdbCommitTable(pCHandle, pMemData, pBlockIdx); - if (code) { - goto _err; - } - } - - // commit file end - code = tsdbCommitFileEnd(pCHandle); - if (code) { - goto _err; - } - - return code; - -_err: - return code; -} - -static int32_t tsdbCommitData(SCommitH *pCHandle) { - int32_t code = 0; - int32_t fid; - - if (pCHandle->pMemTable->nRows == 0) goto _exit; - - // loop to commit to each file - for (;;) { - if (pCHandle->nCommitKey == TSKEY_MAX) break; - - pCHandle->fid = TSDB_KEY_FID(pCHandle->nCommitKey, pCHandle->minutes, pCHandle->precision); - tsdbGetFidKeyRange(pCHandle->minutes, pCHandle->precision, pCHandle->fid, &pCHandle->minKey, &pCHandle->maxKey); - code = tsdbCommitFile(pCHandle); - if (code) { - goto _err; - } - } - -_exit: - return code; - -_err: - return code; -} - -static int32_t delInfoCmprFn(const void *p1, const void *p2) { - SDelInfo *pDelInfo1 = (SDelInfo *)p1; - SDelInfo *pDelInfo2 = (SDelInfo *)p2; - - if (pDelInfo1->suid < pDelInfo2->suid) { - return -1; - } else if (pDelInfo1->suid > pDelInfo2->suid) { - return 1; - } - - if (pDelInfo1->uid < pDelInfo2->uid) { - return -1; - } else if (pDelInfo1->uid > pDelInfo2->uid) { - return 1; - } - - if (pDelInfo1->version < pDelInfo2->version) { - return -1; - } else if (pDelInfo1->version > pDelInfo2->version) { - return 1; - } - - return 0; -} -static int32_t tsdbCommitDelete(SCommitH *pCHandle) { - int32_t code = 0; - SDelInfo delInfo; - SMemData *pMemData; - - if (pCHandle->pMemTable->nDelOp == 0) goto _exit; - - // load del array (todo) - - // loop to append SDelInfo - for (int32_t iMemData = 0; iMemData < taosArrayGetSize(pCHandle->pMemTable->aMemData); iMemData++) { - pMemData = (SMemData *)taosArrayGetP(pCHandle->pMemTable->aMemData, iMemData); - - for (SDelOp *pDelOp = pMemData->delOpHead; pDelOp; pDelOp = pDelOp->pNext) { - delInfo = (SDelInfo){.suid = pMemData->suid, - .uid = pMemData->uid, - .version = pDelOp->version, - .sKey = pDelOp->sKey, - .eKey = pDelOp->eKey}; - if (taosArrayPush(pCHandle->aDelInfo, &delInfo) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - } - } - - taosArraySort(pCHandle->aDelInfo, delInfoCmprFn); - - // write to new file - -_exit: - return code; - -_err: - return code; -} - -static int32_t tsdbCommitCache(SCommitH *pCHandle) { - int32_t code = 0; - // TODO - return code; -} - -static int32_t tsdbCommitImpl(SCommitH *pCHandle) { - int32_t code = 0; - - // commit data - code = tsdbCommitData(pCHandle); - if (code) { - goto _err; - } - - // commit delete - code = tsdbCommitDelete(pCHandle); - if (code) { - goto _err; - } - - // commit cache if need (todo) - if (0) { - code = tsdbCommitCache(pCHandle); - if (code) { - goto _err; - } - } - - return code; - -_err: - return code; -} \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index a88cb8a353..11d206dc35 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -25,8 +25,7 @@ static const char *TSDB_FNAME_SUFFIX[] = { "meta", // TSDB_FILE_META }; -static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, const char *dname, char *fname); -// static int tsdbRollBackMFile(SMFile *pMFile); +static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, const char *dname, char *fname); static int tsdbEncodeDFInfo(void **buf, SDFInfo *pInfo); static void *tsdbDecodeDFInfo(void *buf, SDFInfo *pInfo); static int tsdbRollBackDFile(SDFile *pDFile); diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index fa392baa16..ffbef4e765 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -15,248 +15,102 @@ #include "tsdb.h" -static STbData *tsdbNewTbData(tb_uid_t uid); -static void tsdbFreeTbData(STbData *pTbData); -static char *tsdbGetTsTupleKey(const void *data); -static int tsdbTbDataComp(const void *arg1, const void *arg2); -static char *tsdbTbDataGetUid(const void *arg); -static int tsdbAppendTableRowToCols(STsdb *pTsdb, STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row, - bool merge); +#define SL_MAX_LEVEL 5 -int tsdbMemTableCreate(STsdb *pTsdb, STsdbMemTable **ppMemTable) { - STsdbMemTable *pMemTable; - SVnode *pVnode; +#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l)*2) +#define SL_NODE_FORWARD(n, l) ((n)->forwards[l]) +#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)]) +#define SL_NODE_DATA(n) (&SL_NODE_BACKWARD(n, (n)->level)) - *ppMemTable = NULL; - pVnode = pTsdb->pVnode; +#define SL_MOVE_BACKWARD 0x1 +#define SL_MOVE_FROM_POS 0x2 - // alloc handle - pMemTable = (STsdbMemTable *)taosMemoryCalloc(1, sizeof(*pMemTable)); +static int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow); +static int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow); +static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *pKey, int32_t flags); +static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData); +static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, int64_t version, + SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkRsp *pRsp); + +int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) { + int32_t code = 0; + SMemTable *pMemTable = NULL; + + pMemTable = (SMemTable *)taosMemoryCalloc(1, sizeof(*pMemTable)); if (pMemTable == NULL) { - return -1; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; } - - pMemTable->pPool = pTsdb->pVnode->inUse; - T_REF_INIT_VAL(pMemTable, 1); taosInitRWLatch(&pMemTable->latch); - pMemTable->keyMin = TSKEY_MAX; - pMemTable->keyMax = TSKEY_MIN; + pMemTable->pTsdb = pTsdb; + pMemTable->nRef = 1; + pMemTable->minKey = (TSDBKEY){.ts = TSKEY_MAX, .version = INT64_MAX}; + pMemTable->maxKey = (TSDBKEY){.ts = TSKEY_MIN, .version = -1}; pMemTable->nRow = 0; - pMemTable->pSlIdx = tSkipListCreate(pVnode->config.tsdbCfg.slLevel, TSDB_DATA_TYPE_BIGINT, sizeof(tb_uid_t), - tsdbTbDataComp, SL_DISCARD_DUP_KEY, tsdbTbDataGetUid); - if (pMemTable->pSlIdx == NULL) { + pMemTable->nDelOp = 0; + pMemTable->aTbData = taosArrayInit(128, sizeof(STbData *)); + if (pMemTable->aTbData == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(pMemTable); - return -1; - } - - pMemTable->pHashIdx = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); - if (pMemTable->pHashIdx == NULL) { - tSkipListDestroy(pMemTable->pSlIdx); - taosMemoryFree(pMemTable); - return -1; + goto _err; } *ppMemTable = pMemTable; - return 0; + return code; + +_err: + *ppMemTable = NULL; + return code; } -void tsdbMemTableDestroy(STsdbMemTable *pMemTable) { +void tsdbMemTableDestroy(SMemTable *pMemTable) { if (pMemTable) { - taosHashCleanup(pMemTable->pHashIdx); - SSkipListIterator *pIter = tSkipListCreateIter(pMemTable->pSlIdx); - SSkipListNode *pNode = NULL; - STbData *pTbData = NULL; - for (;;) { - if (!tSkipListIterNext(pIter)) break; - pNode = tSkipListIterGet(pIter); - pTbData = (STbData *)pNode->pData; - tsdbFreeTbData(pTbData); - } - tSkipListDestroyIter(pIter); - tSkipListDestroy(pMemTable->pSlIdx); + taosArrayDestroy(pMemTable->aTbData); taosMemoryFree(pMemTable); } } -/** - * This is an important function to load data or try to load data from memory skiplist iterator. - * - * This function load memory data until: - * 1. iterator ends - * 2. data key exceeds maxKey - * 3. rowsIncreased = rowsInserted - rowsDeleteSucceed >= maxRowsToRead - * 4. operations in pCols not exceeds its max capacity if pCols is given - * - * The function tries to procceed AS MUCH AS POSSIBLE. - */ -int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, - SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo) { - ASSERT(maxRowsToRead > 0 && nFilterKeys >= 0); - if (pIter == NULL) return 0; - STSchema *pSchema = NULL; - TSKEY rowKey = 0; - TSKEY fKey = 0; - // only fetch lastKey from mem data as file data not used in this function actually - TSKEY lastKey = TSKEY_INITIAL_VAL; - bool isRowDel = false; - int filterIter = 0; - STSRow *row = NULL; - SMergeInfo mInfo; +static int32_t tbDataPCmprFn(const void *p1, const void *p2) { + STbData *pTbData1 = *(STbData **)p1; + STbData *pTbData2 = *(STbData **)p2; - // TODO: support Multi-Version(the rows with the same TS keys in memory can't be merged if its version refered by - // query handle) - - if (pMergeInfo == NULL) pMergeInfo = &mInfo; - - memset(pMergeInfo, 0, sizeof(*pMergeInfo)); - pMergeInfo->keyFirst = INT64_MAX; - pMergeInfo->keyLast = INT64_MIN; - if (pCols) tdResetDataCols(pCols); - - row = tsdbNextIterRow(pIter); - if (row == NULL || TD_ROW_KEY(row) > maxKey) { - rowKey = INT64_MAX; - isRowDel = false; - } else { - rowKey = TD_ROW_KEY(row); - isRowDel = TD_ROW_IS_DELETED(row); + if (pTbData1->suid < pTbData2->suid) { + return -1; + } else if (pTbData1->suid > pTbData2->suid) { + return 1; } - if (filterIter >= nFilterKeys) { - fKey = INT64_MAX; - } else { - fKey = tdGetKey(filterKeys[filterIter]); - } - // 1. fkey - no dup since merged up to maxVersion of each query handle by tsdbLoadBlockDataCols - // 2. rowKey - would dup since Multi-Version supported - while (true) { - if (fKey == INT64_MAX && rowKey == INT64_MAX) break; - - if (fKey < rowKey) { - pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, fKey); - pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, fKey); - - filterIter++; - if (filterIter >= nFilterKeys) { - fKey = INT64_MAX; - } else { - fKey = tdGetKey(filterKeys[filterIter]); - } -#if 1 - } else if (fKey > rowKey) { - if (isRowDel) { - // TODO: support delete function - pMergeInfo->rowsDeleteFailed++; - } else { - if (pMergeInfo->rowsInserted - pMergeInfo->rowsDeleteSucceed >= maxRowsToRead) break; - if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break; - - if (lastKey != rowKey) { - pMergeInfo->rowsInserted++; - pMergeInfo->nOperations++; - pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey); - pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, rowKey); - if (pCols) { - if (lastKey != TSKEY_INITIAL_VAL) { - ++pCols->numOfRows; - } - tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false); - } - lastKey = rowKey; - } else { - if (keepDup) { - tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, true); - } else { - // discard - } - } - } - - tSkipListIterNext(pIter); - row = tsdbNextIterRow(pIter); - if (row == NULL || TD_ROW_KEY(row) > maxKey) { - rowKey = INT64_MAX; - isRowDel = false; - } else { - rowKey = TD_ROW_KEY(row); - isRowDel = TD_ROW_IS_DELETED(row); - } - } else { // fkey == rowKey - if (isRowDel) { // TODO: support delete function(How to stands for delete in file? rowVersion = -1?) - ASSERT(!keepDup); - if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break; - pMergeInfo->rowsDeleteSucceed++; - pMergeInfo->nOperations++; - tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false); - } else { - if (keepDup) { - if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break; - if (lastKey != rowKey) { - pMergeInfo->rowsUpdated++; - pMergeInfo->nOperations++; - pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey); - pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, rowKey); - if (pCols) { - if (lastKey != TSKEY_INITIAL_VAL) { - ++pCols->numOfRows; - } - tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false); - } - lastKey = rowKey; - } else { - tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, true); - } - } else { - pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, fKey); - pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, fKey); - } - } - - tSkipListIterNext(pIter); - row = tsdbNextIterRow(pIter); - if (row == NULL || TD_ROW_KEY(row) > maxKey) { - rowKey = INT64_MAX; - isRowDel = false; - } else { - rowKey = TD_ROW_KEY(row); - isRowDel = TD_ROW_IS_DELETED(row); - } - - filterIter++; - if (filterIter >= nFilterKeys) { - fKey = INT64_MAX; - } else { - fKey = tdGetKey(filterKeys[filterIter]); - } - } -#endif - } - if (pCols && (lastKey != TSKEY_INITIAL_VAL)) { - ++pCols->numOfRows; + if (pTbData1->uid < pTbData2->uid) { + return -1; + } else if (pTbData1->uid > pTbData2->uid) { + return 1; } return 0; } +void tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData) { + STbData *pTbData = &(STbData){.suid = suid, .uid = uid}; + void *p = taosArraySearch(pMemTable->aTbData, &pTbData, tbDataPCmprFn, TD_EQ); + *ppTbData = p ? *(STbData **)p : NULL; +} -int tsdbInsertTableData(STsdb *pTsdb, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkRsp *pRsp) { - SSubmitBlkIter blkIter = {0}; - STsdbMemTable *pMemTable = pTsdb->mem; - void *tptr; - STbData *pTbData; - STSRow *row; - TSKEY keyMin; - TSKEY keyMax; - SSubmitBlk *pBlkCopy; - int64_t sverNew; +int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, + SSubmitBlkRsp *pRsp) { + int32_t code = 0; + SMemTable *pMemTable = pTsdb->mem; + STbData *pTbData = NULL; + tb_uid_t suid = pMsgIter->suid; + tb_uid_t uid = pMsgIter->uid; + int32_t sverNew; - // check if table exists + // check if table exists (todo: refact) SMetaReader mr = {0}; SMetaEntry me = {0}; metaReaderInit(&mr, pTsdb->pVnode->pMeta, 0); if (metaGetTableEntryByUid(&mr, pMsgIter->uid) < 0) { metaReaderClear(&mr); - terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; - return -1; + code = TSDB_CODE_PAR_TABLE_NOT_EXIST; + goto _err; } if (pRsp->tblFName) strcat(pRsp->tblFName, mr.me.name); @@ -267,122 +121,453 @@ int tsdbInsertTableData(STsdb *pTsdb, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlo sverNew = mr.me.stbEntry.schemaRow.version; } metaReaderClear(&mr); - - // create container is nedd - tptr = taosHashGet(pMemTable->pHashIdx, &(pMsgIter->uid), sizeof(pMsgIter->uid)); - if (tptr == NULL) { - pTbData = tsdbNewTbData(pMsgIter->uid); - if (pTbData == NULL) { - return -1; - } - - // Put into hash - taosHashPut(pMemTable->pHashIdx, &(pMsgIter->uid), sizeof(pMsgIter->uid), &(pTbData), sizeof(pTbData)); - - // Put into skiplist - tSkipListPut(pMemTable->pSlIdx, pTbData); - } else { - pTbData = *(STbData **)tptr; - } - - // copy data to buffer pool - int32_t tlen = pMsgIter->dataLen + pMsgIter->schemaLen + sizeof(*pBlock); - pBlkCopy = (SSubmitBlk *)vnodeBufPoolMalloc(pTsdb->mem->pPool, tlen); - memcpy(pBlkCopy, pBlock, tlen); - - tInitSubmitBlkIter(pMsgIter, pBlkCopy, &blkIter); - if (blkIter.row == NULL) return 0; - keyMin = TD_ROW_KEY(blkIter.row); - - tSkipListPutBatchByIter(pTbData->pData, &blkIter, (iter_next_fn_t)tGetSubmitBlkNext); - -#ifdef TD_DEBUG_PRINT_ROW - printf("!!! %s:%d vgId:%d dir:%s table:%" PRIi64 " has %d rows in skiplist\n\n", __func__, __LINE__, - TD_VID(pTsdb->pVnode), pTsdb->dir, pTbData->uid, SL_SIZE(pTbData->pData)); -#endif - - // Set statistics - keyMax = TD_ROW_KEY(blkIter.row); - - pTbData->nrows += pMsgIter->numOfRows; - if (pTbData->keyMin > keyMin) pTbData->keyMin = keyMin; - if (pTbData->keyMax < keyMax) pTbData->keyMax = keyMax; - - pMemTable->nRow += pMsgIter->numOfRows; - if (pMemTable->keyMin > keyMin) pMemTable->keyMin = keyMin; - if (pMemTable->keyMax < keyMax) pMemTable->keyMax = keyMax; - - pRsp->numOfRows = pMsgIter->numOfRows; - pRsp->affectedRows = pMsgIter->numOfRows; pRsp->sver = sverNew; - return 0; -} - -static STbData *tsdbNewTbData(tb_uid_t uid) { - STbData *pTbData = (STbData *)taosMemoryCalloc(1, sizeof(*pTbData)); - if (pTbData == NULL) { - return NULL; + // create/get STbData to op + code = tsdbGetOrCreateTbData(pMemTable, suid, uid, &pTbData); + if (code) { + goto _err; } - pTbData->uid = uid; - pTbData->keyMin = TSKEY_MAX; - pTbData->keyMax = TSKEY_MIN; - pTbData->nrows = 0; -#if 0 - pTbData->pData = tSkipListCreate(5, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), tkeyComparFn, SL_DISCARD_DUP_KEY, - tsdbGetTsTupleKey); -#endif - pTbData->pData = - tSkipListCreate(5, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), tkeyComparFn, SL_ALLOW_DUP_KEY, tsdbGetTsTupleKey); - if (pTbData->pData == NULL) { - taosMemoryFree(pTbData); - return NULL; + // do insert impl + code = tsdbInsertTableDataImpl(pMemTable, pTbData, version, pMsgIter, pBlock, pRsp); + if (code) { + goto _err; } - return pTbData; + return code; + +_err: + return code; } -static void tsdbFreeTbData(STbData *pTbData) { - if (pTbData) { - tSkipListDestroy(pTbData->pData); - taosMemoryFree(pTbData); +int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey) { + int32_t code = 0; + SMemTable *pMemTable = pTsdb->mem; + STbData *pTbData = NULL; + SVBufPool *pPool = pTsdb->pVnode->inUse; + + // check if table exists (todo) + + code = tsdbGetOrCreateTbData(pMemTable, suid, uid, &pTbData); + if (code) { + goto _err; } -} -static char *tsdbGetTsTupleKey(const void *data) { return (char *)TD_ROW_KEY_ADDR((STSRow *)data); } - -static int tsdbTbDataComp(const void *arg1, const void *arg2) { - STbData *pTbData1 = (STbData *)arg1; - STbData *pTbData2 = (STbData *)arg2; - - if (pTbData1->uid > pTbData2->uid) { - return 1; - } else if (pTbData1->uid == pTbData2->uid) { - return 0; + // do delete + SDelOp *pDelOp = (SDelOp *)vnodeBufPoolMalloc(pPool, sizeof(*pDelOp)); + if (pDelOp == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + pDelOp->version = version; + pDelOp->sKey = sKey; + pDelOp->eKey = eKey; + pDelOp->pNext = NULL; + if (pTbData->pHead == NULL) { + ASSERT(pTbData->pTail == NULL); + pTbData->pHead = pTbData->pTail = pDelOp; } else { - return -1; + pTbData->pTail->pNext = pDelOp; + pTbData->pTail = pDelOp; + } + + // update the state of pMemTable and other (todo) + + pMemTable->nDelOp++; + + tsdbError("vgId:%d delete data from table suid:%" PRId64 " uid:%" PRId64 " skey:%" PRId64 " eKey:%" PRId64 + " since %s", + TD_VID(pTsdb->pVnode), suid, uid, sKey, eKey, tstrerror(code)); + return code; + +_err: + tsdbError("vgId:%d failed to delete data from table suid:%" PRId64 " uid:%" PRId64 " skey:%" PRId64 " eKey:%" PRId64 + " since %s", + TD_VID(pTsdb->pVnode), suid, uid, sKey, eKey, tstrerror(code)); + return code; +} + +int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter **ppIter) { + int32_t code = 0; + + (*ppIter) = (STbDataIter *)taosMemoryCalloc(1, sizeof(STbDataIter)); + if ((*ppIter) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + tsdbTbDataIterOpen(pTbData, pFrom, backward, *ppIter); + +_exit: + return code; +} + +void *tsdbTbDataIterDestroy(STbDataIter *pIter) { + if (pIter) { + taosMemoryFree(pIter); + } + + return NULL; +} + +void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter) { + SMemSkipListNode *pos[SL_MAX_LEVEL]; + + pIter->pTbData = pTbData; + pIter->backward = backward; + if (pFrom == NULL) { + // create from head or tail + if (backward) { + pIter->pNode = SL_NODE_BACKWARD(pTbData->sl.pTail, 0); + } else { + pIter->pNode = SL_NODE_FORWARD(pTbData->sl.pHead, 0); + } + } else { + // create from a key + if (backward) { + tbDataMovePosTo(pTbData, pos, pFrom, SL_MOVE_BACKWARD); + pIter->pNode = SL_NODE_BACKWARD(pos[0], 0); + } else { + tbDataMovePosTo(pTbData, pos, pFrom, 0); + pIter->pNode = SL_NODE_FORWARD(pos[0], 0); + } } } -static char *tsdbTbDataGetUid(const void *arg) { - STbData *pTbData = (STbData *)arg; - return (char *)(&(pTbData->uid)); -} +bool tsdbTbDataIterNext(STbDataIter *pIter) { + SMemSkipListNode *pHead = pIter->pTbData->sl.pHead; + SMemSkipListNode *pTail = pIter->pTbData->sl.pTail; -static int tsdbAppendTableRowToCols(STsdb *pTsdb, STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row, - bool merge) { - if (pCols) { - if (*ppSchema == NULL || schemaVersion(*ppSchema) != TD_ROW_SVER(row)) { - *ppSchema = tsdbGetTableSchemaImpl(pTsdb, pTable, false, false, TD_ROW_SVER(row)); - if (*ppSchema == NULL) { - ASSERT(false); - return -1; - } + if (pIter->backward) { + ASSERT(pIter->pNode != pTail); + + if (pIter->pNode == pHead) { + return false; } - tdAppendSTSRowToDataCol(row, *ppSchema, pCols, merge); + pIter->pNode = SL_NODE_BACKWARD(pIter->pNode, 0); + if (pIter->pNode == pHead) { + return false; + } + } else { + ASSERT(pIter->pNode != pHead); + + if (pIter->pNode == pTail) { + return false; + } + + pIter->pNode = SL_NODE_FORWARD(pIter->pNode, 0); + if (pIter->pNode == pTail) { + return false; + } } - return 0; + return true; +} + +bool tsdbTbDataIterGet(STbDataIter *pIter, TSDBROW *pRow) { + SMemSkipListNode *pHead = pIter->pTbData->sl.pHead; + SMemSkipListNode *pTail = pIter->pTbData->sl.pTail; + TSDBROW row = {0}; + + if (pRow == NULL) { + pRow = &row; + } + + if (pIter->backward) { + ASSERT(pIter->pNode != pTail); + + if (pIter->pNode == pHead) { + return false; + } + } else { + ASSERT(pIter->pNode != pHead); + + if (pIter->pNode == pTail) { + return false; + } + } + + tGetTSDBRow((uint8_t *)SL_NODE_DATA(pIter->pNode), pRow); + return true; +} + +static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, STbData **ppTbData) { + int32_t code = 0; + int32_t idx = 0; + STbData *pTbData = NULL; + STbData *pTbDataT = &(STbData){.suid = suid, .uid = uid}; + + // get + idx = taosArraySearchIdx(pMemTable->aTbData, &pTbDataT, tbDataPCmprFn, TD_GE); + if (idx >= 0) { + pTbData = (STbData *)taosArrayGetP(pMemTable->aTbData, idx); + if (tbDataPCmprFn(&pTbDataT, &pTbData) == 0) goto _exit; + } + + // create + SVBufPool *pPool = pMemTable->pTsdb->pVnode->inUse; + int8_t maxLevel = pMemTable->pTsdb->pVnode->config.tsdbCfg.slLevel; + + pTbData = vnodeBufPoolMalloc(pPool, sizeof(*pTbData) + SL_NODE_SIZE(maxLevel) * 2); + if (pTbData == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + pTbData->suid = suid; + pTbData->uid = uid; + pTbData->minKey = (TSDBKEY){.ts = TSKEY_MAX, .version = INT64_MAX}; + pTbData->maxKey = (TSDBKEY){.ts = TSKEY_MIN, .version = -1}; + pTbData->pHead = NULL; + pTbData->pTail = NULL; + pTbData->sl.seed = taosRand(); + pTbData->sl.size = 0; + pTbData->sl.maxLevel = maxLevel; + pTbData->sl.level = 0; + pTbData->sl.pHead = (SMemSkipListNode *)&pTbData[1]; + pTbData->sl.pTail = (SMemSkipListNode *)POINTER_SHIFT(pTbData->sl.pHead, SL_NODE_SIZE(maxLevel)); + pTbData->sl.pHead->level = maxLevel; + pTbData->sl.pTail->level = maxLevel; + for (int8_t iLevel = 0; iLevel < maxLevel; iLevel++) { + SL_NODE_FORWARD(pTbData->sl.pHead, iLevel) = pTbData->sl.pTail; + SL_NODE_BACKWARD(pTbData->sl.pTail, iLevel) = pTbData->sl.pHead; + + SL_NODE_BACKWARD(pTbData->sl.pHead, iLevel) = NULL; + SL_NODE_FORWARD(pTbData->sl.pTail, iLevel) = NULL; + } + + void *p; + if (idx < 0) { + p = taosArrayPush(pMemTable->aTbData, &pTbData); + } else { + p = taosArrayInsert(pMemTable->aTbData, idx, &pTbData); + } + if (p == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + +_exit: + *ppTbData = pTbData; + return code; + +_err: + *ppTbData = NULL; + return code; +} + +static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *pKey, int32_t flags) { + SMemSkipListNode *px; + SMemSkipListNode *pn; + TSDBKEY *pTKey; + int c; + int backward = flags & SL_MOVE_BACKWARD; + int fromPos = flags & SL_MOVE_FROM_POS; + + if (backward) { + px = pTbData->sl.pTail; + + for (int8_t iLevel = pTbData->sl.maxLevel - 1; iLevel >= pTbData->sl.level; iLevel--) { + pos[iLevel] = px; + } + + if (pTbData->sl.level) { + if (fromPos) px = pos[pTbData->sl.level - 1]; + + for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) { + pn = SL_NODE_BACKWARD(px, iLevel); + while (pn != pTbData->sl.pHead) { + pTKey = (TSDBKEY *)SL_NODE_DATA(pn); + + c = tsdbKeyCmprFn(pTKey, pKey); + if (c <= 0) { + break; + } else { + px = pn; + pn = SL_NODE_BACKWARD(px, iLevel); + } + } + + pos[iLevel] = px; + } + } + } else { + px = pTbData->sl.pHead; + + for (int8_t iLevel = pTbData->sl.maxLevel - 1; iLevel >= pTbData->sl.level; iLevel--) { + pos[iLevel] = px; + } + + if (pTbData->sl.level) { + if (fromPos) px = pos[pTbData->sl.level - 1]; + + for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) { + pn = SL_NODE_FORWARD(px, iLevel); + while (pn != pTbData->sl.pTail) { + pTKey = (TSDBKEY *)SL_NODE_DATA(pn); + + c = tsdbKeyCmprFn(pTKey, pKey); + if (c >= 0) { + break; + } else { + px = pn; + pn = SL_NODE_FORWARD(px, iLevel); + } + } + + pos[iLevel] = px; + } + } + } +} + +static FORCE_INLINE int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) { + int8_t level = 1; + int8_t tlevel = TMIN(pSl->maxLevel, pSl->level + 1); + const uint32_t factor = 4; + + while ((taosRandR(&pSl->seed) % factor) == 0 && level < tlevel) { + level++; + } + + return level; +} +static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListNode **pos, TSDBROW *pRow, + int8_t forward) { + int32_t code = 0; + int8_t level; + SMemSkipListNode *pNode; + SVBufPool *pPool = pMemTable->pTsdb->pVnode->inUse; + + // node + level = tsdbMemSkipListRandLevel(&pTbData->sl); + pNode = (SMemSkipListNode *)vnodeBufPoolMalloc(pPool, SL_NODE_SIZE(level) + tPutTSDBRow(NULL, pRow)); + if (pNode == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + pNode->level = level; + for (int8_t iLevel = 0; iLevel < level; iLevel++) { + SL_NODE_FORWARD(pNode, iLevel) = NULL; + SL_NODE_BACKWARD(pNode, iLevel) = NULL; + } + + tPutTSDBRow((uint8_t *)SL_NODE_DATA(pNode), pRow); + + // put + for (int8_t iLevel = 0; iLevel < pNode->level; iLevel++) { + SMemSkipListNode *px = pos[iLevel]; + + if (forward) { + SMemSkipListNode *pNext = SL_NODE_FORWARD(px, iLevel); + + SL_NODE_FORWARD(pNode, iLevel) = pNext; + SL_NODE_BACKWARD(pNode, iLevel) = px; + + SL_NODE_BACKWARD(pNext, iLevel) = pNode; + SL_NODE_FORWARD(px, iLevel) = pNode; + } else { + SMemSkipListNode *pPrev = SL_NODE_BACKWARD(px, iLevel); + + SL_NODE_FORWARD(pNode, iLevel) = px; + SL_NODE_BACKWARD(pNode, iLevel) = pPrev; + + SL_NODE_FORWARD(pPrev, iLevel) = pNode; + SL_NODE_BACKWARD(px, iLevel) = pNode; + } + } + + pTbData->sl.size++; + if (pTbData->sl.level < pNode->level) { + pTbData->sl.level = pNode->level; + } + +_exit: + return code; +} + +static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, int64_t version, + SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkRsp *pRsp) { + int32_t code = 0; + SSubmitBlkIter blkIter = {0}; + TSDBKEY key = {.version = version}; + SMemSkipListNode *pos[SL_MAX_LEVEL]; + TSDBROW row = {.version = version, .pTSRow = NULL}; + int32_t nRow = 0; + + tInitSubmitBlkIter(pMsgIter, pBlock, &blkIter); + + // backward put first data + row.pTSRow = tGetSubmitBlkNext(&blkIter); + key.ts = row.pTSRow->ts; + nRow++; + tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_BACKWARD); + code = tbDataDoPut(pMemTable, pTbData, pos, &row, 0); + if (code) { + goto _err; + } + + if (tsdbKeyCmprFn(&key, &pTbData->minKey) < 0) { + pTbData->minKey = key; + } + + if (tsdbKeyCmprFn(&key, &pMemTable->minKey) < 0) { + pMemTable->minKey = key; + } + + // forward put rest data + row.pTSRow = tGetSubmitBlkNext(&blkIter); + if (row.pTSRow) { + for (int8_t iLevel = 0; iLevel < pTbData->sl.maxLevel; iLevel++) { + pos[iLevel] = SL_NODE_BACKWARD(pos[iLevel], iLevel); + } + do { + key.ts = row.pTSRow->ts; + nRow++; + tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_FROM_POS); + code = tbDataDoPut(pMemTable, pTbData, pos, &row, 1); + if (code) { + goto _err; + } + + row.pTSRow = tGetSubmitBlkNext(&blkIter); + } while (row.pTSRow); + } + + if (tsdbKeyCmprFn(&key, &pTbData->maxKey) > 0) { + pTbData->maxKey = key; + } + + if (tsdbKeyCmprFn(&key, &pMemTable->maxKey) > 0) { + pMemTable->maxKey = key; + } + pMemTable->nRef++; + pRsp->numOfRows = nRow; + pRsp->affectedRows = nRow; + + return code; + +_err: + return code; +} + +static int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow) { + int32_t n = 0; + + n += tPutI64(p, pRow->version); + if (p) memcpy(p + n, pRow->pTSRow, pRow->pTSRow->len); + n += pRow->pTSRow->len; + + return n; +} + +static int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow) { + int32_t n = 0; + + n += tGetI64(p, &pRow->version); + pRow->pTSRow = (STSRow *)(p + n); + n += pRow->pTSRow->len; + + return n; } \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable2.c b/source/dnode/vnode/src/tsdb/tsdbMemTable2.c deleted file mode 100644 index cf8557bba3..0000000000 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable2.c +++ /dev/null @@ -1,535 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "tsdb.h" - -struct SMemSkipListNode { - int8_t level; - SMemSkipListNode *forwards[0]; -}; - -typedef struct { - tb_uid_t uid; - STSchema *pTSchema; -} SSkmInfo; - -#define SL_MAX_LEVEL 5 - -#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l)*2) -#define SL_NODE_FORWARD(n, l) ((n)->forwards[l]) -#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)]) -#define SL_NODE_DATA(n) (&SL_NODE_BACKWARD(n, (n)->level)) - -#define SL_MOVE_BACKWARD 0x1 -#define SL_MOVE_FROM_POS 0x2 - -static int32_t tsdbGetOrCreateMemData(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, SMemData **ppMemData); -static int memDataPCmprFn(const void *p1, const void *p2); -static int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow); -static int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow); -static int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl); -static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, SMemData *pMemData, int64_t version, - SVSubmitBlk *pSubmitBlk); -static void memDataMovePosTo(SMemData *pMemData, SMemSkipListNode **pos, TSDBKEY *pKey, int32_t flags); - -// SMemTable ============================================== -int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTable) { - int32_t code = 0; - SMemTable *pMemTable = NULL; - - pMemTable = (SMemTable *)taosMemoryCalloc(1, sizeof(*pMemTable)); - if (pMemTable == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - pMemTable->pTsdb = pTsdb; - pMemTable->nRef = 1; - pMemTable->minKey = (TSDBKEY){.version = INT64_MAX, .ts = TSKEY_MAX}; - pMemTable->maxKey = (TSDBKEY){.version = -1, .ts = TSKEY_MIN}; - pMemTable->nRows = 0; - pMemTable->nDelOp = 0; - pMemTable->aMemData = taosArrayInit(512, sizeof(SMemData *)); - if (pMemTable->aMemData == NULL) { - taosMemoryFree(pMemTable); - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - - *ppMemTable = pMemTable; - return code; - -_err: - *ppMemTable = NULL; - return code; -} - -void tsdbMemTableDestroy2(SMemTable *pMemTable) { - taosArrayDestroyEx(pMemTable->aMemData, NULL /*TODO*/); - taosMemoryFree(pMemTable); -} - -int32_t tsdbInsertTableData2(STsdb *pTsdb, int64_t version, SVSubmitBlk *pSubmitBlk) { - int32_t code = 0; - SMemTable *pMemTable = (SMemTable *)pTsdb->mem; // TODO - SMemData *pMemData; - TSDBROW row = {.version = version}; - - ASSERT(pMemTable); - ASSERT(pSubmitBlk->nData > 0); - - { - // check if table exists (todo) - } - - code = tsdbGetOrCreateMemData(pMemTable, pSubmitBlk->suid, pSubmitBlk->uid, &pMemData); - if (code) { - tsdbError("vgId:%d, failed to create/get table data since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); - goto _err; - } - - // do insert - code = tsdbInsertTableDataImpl(pMemTable, pMemData, version, pSubmitBlk); - if (code) { - goto _err; - } - - return code; - -_err: - return code; -} - -int32_t tsdbDeleteTableData2(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey) { - int32_t code = 0; - SMemTable *pMemTable = (SMemTable *)pTsdb->mem; // TODO - SMemData *pMemData; - SVBufPool *pPool = pTsdb->pVnode->inUse; - - ASSERT(pMemTable); - - { - // check if table exists (todo) - } - - code = tsdbGetOrCreateMemData(pMemTable, suid, uid, &pMemData); - if (code) { - goto _err; - } - - // do delete - SDelOp *pDelOp = (SDelOp *)vnodeBufPoolMalloc(pPool, sizeof(*pDelOp)); - if (pDelOp == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - pDelOp->version = version; - pDelOp->sKey = sKey; - pDelOp->eKey = eKey; - pDelOp->pNext = NULL; - if (pMemData->delOpHead == NULL) { - ASSERT(pMemData->delOpTail == NULL); - pMemData->delOpHead = pMemData->delOpTail = pDelOp; - } else { - pMemData->delOpTail->pNext = pDelOp; - pMemData->delOpTail = pDelOp; - } - - { - // update the state of pMemTable, pMemData, last and lastrow (todo) - } - - pMemTable->nDelOp++; - - tsdbDebug("vgId:%d, delete data from table suid:%" PRId64 " uid:%" PRId64 " sKey:%" PRId64 " eKey:%" PRId64 - " since %s", - TD_VID(pTsdb->pVnode), suid, uid, sKey, eKey, tstrerror(code)); - return code; - -_err: - tsdbError("vgId:%d, failed to delete data from table suid:%" PRId64 " uid:%" PRId64 " sKey:%" PRId64 " eKey:%" PRId64 - " since %s", - TD_VID(pTsdb->pVnode), suid, uid, sKey, eKey, tstrerror(code)); - return code; -} - -void tsdbMemDataIterOpen(SMemData *pMemData, TSDBKEY *pKey, int8_t backward, SMemDataIter *pIter) { - SMemSkipListNode *pos[SL_MAX_LEVEL]; - - pIter->pMemData = pMemData; - pIter->backward = backward; - pIter->pRow = NULL; - if (pKey == NULL) { - // create from head or tail - if (backward) { - pIter->pNode = SL_NODE_BACKWARD(pMemData->sl.pTail, 0); - } else { - pIter->pNode = SL_NODE_FORWARD(pMemData->sl.pHead, 0); - } - } else { - // create from a key - if (backward) { - memDataMovePosTo(pMemData, pos, pKey, SL_MOVE_BACKWARD); - pIter->pNode = SL_NODE_BACKWARD(pos[0], 0); - } else { - memDataMovePosTo(pMemData, pos, pKey, 0); - pIter->pNode = SL_NODE_FORWARD(pos[0], 0); - } - } -} - -bool tsdbMemDataIterNext(SMemDataIter *pIter) { - SMemSkipListNode *pHead = pIter->pMemData->sl.pHead; - SMemSkipListNode *pTail = pIter->pMemData->sl.pTail; - - pIter->pRow = NULL; - if (pIter->backward) { - ASSERT(pIter->pNode != pTail); - - if (pIter->pNode == pHead) { - return false; - } - - pIter->pNode = SL_NODE_BACKWARD(pIter->pNode, 0); - if (pIter->pNode == pHead) { - return false; - } - } else { - ASSERT(pIter->pNode != pHead); - - if (pIter->pNode == pTail) { - return false; - } - - pIter->pNode = SL_NODE_FORWARD(pIter->pNode, 0); - if (pIter->pNode == pTail) { - return false; - } - } - - return true; -} - -void tsdbMemDataIterGet(SMemDataIter *pIter, TSDBROW **ppRow) { - if (pIter->pRow) { - *ppRow = pIter->pRow; - } else { - SMemSkipListNode *pHead = pIter->pMemData->sl.pHead; - SMemSkipListNode *pTail = pIter->pMemData->sl.pTail; - - if (pIter->backward) { - ASSERT(pIter->pNode != pTail); - - if (pIter->pNode == pHead) { - *ppRow = NULL; - } else { - tGetTSDBRow((uint8_t *)SL_NODE_DATA(pIter->pNode), &pIter->row); - *ppRow = &pIter->row; - } - } else { - ASSERT(pIter->pNode != pHead); - - if (pIter->pNode == pTail) { - *ppRow = NULL; - } else { - tGetTSDBRow((uint8_t *)SL_NODE_DATA(pIter->pNode), &pIter->row); - *ppRow = &pIter->row; - } - } - } -} - -static int32_t tsdbGetOrCreateMemData(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid, SMemData **ppMemData) { - int32_t code = 0; - int32_t idx = 0; - SMemData *pMemDataT = &(SMemData){.suid = suid, .uid = uid}; - SMemData *pMemData = NULL; - SVBufPool *pPool = pMemTable->pTsdb->pVnode->inUse; - int8_t maxLevel = pMemTable->pTsdb->pVnode->config.tsdbCfg.slLevel; - - // get - idx = taosArraySearchIdx(pMemTable->aMemData, &pMemDataT, memDataPCmprFn, TD_GE); - if (idx >= 0) { - pMemData = (SMemData *)taosArrayGet(pMemTable->aMemData, idx); - if (memDataPCmprFn(&pMemDataT, &pMemData) == 0) goto _exit; - } - - // create - pMemData = vnodeBufPoolMalloc(pPool, sizeof(*pMemData) + SL_NODE_SIZE(maxLevel) * 2); - if (pMemData == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - pMemData->suid = suid; - pMemData->uid = uid; - pMemData->minKey = (TSDBKEY){.version = INT64_MAX, .ts = TSKEY_MAX}; - pMemData->maxKey = (TSDBKEY){.version = -1, .ts = TSKEY_MIN}; - pMemData->delOpHead = pMemData->delOpTail = NULL; - pMemData->sl.seed = taosRand(); - pMemData->sl.size = 0; - pMemData->sl.maxLevel = maxLevel; - pMemData->sl.level = 0; - pMemData->sl.pHead = (SMemSkipListNode *)&pMemData[1]; - pMemData->sl.pTail = (SMemSkipListNode *)POINTER_SHIFT(pMemData->sl.pHead, SL_NODE_SIZE(maxLevel)); - pMemData->sl.pHead->level = maxLevel; - pMemData->sl.pTail->level = maxLevel; - - for (int8_t iLevel = 0; iLevel < pMemData->sl.maxLevel; iLevel++) { - SL_NODE_FORWARD(pMemData->sl.pHead, iLevel) = pMemData->sl.pTail; - SL_NODE_BACKWARD(pMemData->sl.pHead, iLevel) = NULL; - SL_NODE_BACKWARD(pMemData->sl.pTail, iLevel) = pMemData->sl.pHead; - SL_NODE_FORWARD(pMemData->sl.pTail, iLevel) = NULL; - } - - if (idx < 0) idx = 0; - if (taosArrayInsert(pMemTable->aMemData, idx, &pMemData) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } - -_exit: - *ppMemData = pMemData; - return code; - -_err: - *ppMemData = NULL; - return code; -} - -static int memDataPCmprFn(const void *p1, const void *p2) { - SMemData *pMemData1 = *(SMemData **)p1; - SMemData *pMemData2 = *(SMemData **)p2; - - if (pMemData1->suid < pMemData2->suid) { - return -1; - } else if (pMemData1->suid > pMemData2->suid) { - return 1; - } - - if (pMemData1->uid < pMemData2->uid) { - return -1; - } else if (pMemData1->uid > pMemData2->uid) { - return 1; - } - - return 0; -} - -static int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow) { - int32_t n = 0; - - n += tPutI64(p ? p + n : p, pRow->version); - n += tPutTSRow(p ? p + n : p, &pRow->tsRow); - - return n; -} - -static int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow) { - int32_t n = 0; - - n += tGetI64(p + n, &pRow->version); - n += tGetTSRow(p + n, &pRow->tsRow); - - return n; -} - -static FORCE_INLINE int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) { - int8_t level = 1; - int8_t tlevel = TMIN(pSl->maxLevel, pSl->level + 1); - const uint32_t factor = 4; - - while ((taosRandR(&pSl->seed) % factor) == 0 && level < tlevel) { - level++; - } - - return level; -} - -static void memDataMovePosTo(SMemData *pMemData, SMemSkipListNode **pos, TSDBKEY *pKey, int32_t flags) { - SMemSkipListNode *px; - SMemSkipListNode *pn; - TSDBKEY *pTKey; - int c; - int backward = flags & SL_MOVE_BACKWARD; - int fromPos = flags & SL_MOVE_FROM_POS; - - if (backward) { - px = pMemData->sl.pTail; - - for (int8_t iLevel = pMemData->sl.maxLevel - 1; iLevel >= pMemData->sl.level; iLevel--) { - pos[iLevel] = px; - } - - if (pMemData->sl.level) { - if (fromPos) px = pos[pMemData->sl.level - 1]; - - for (int8_t iLevel = pMemData->sl.level - 1; iLevel >= 0; iLevel--) { - pn = SL_NODE_BACKWARD(px, iLevel); - while (pn != pMemData->sl.pHead) { - pTKey = (TSDBKEY *)SL_NODE_DATA(pn); - - c = tsdbKeyCmprFn(pTKey, pKey); - if (c <= 0) { - break; - } else { - px = pn; - pn = SL_NODE_BACKWARD(px, iLevel); - } - } - - pos[iLevel] = px; - } - } - } else { - px = pMemData->sl.pHead; - - for (int8_t iLevel = pMemData->sl.maxLevel - 1; iLevel >= pMemData->sl.level; iLevel--) { - pos[iLevel] = px; - } - - if (pMemData->sl.level) { - if (fromPos) px = pos[pMemData->sl.level - 1]; - - for (int8_t iLevel = pMemData->sl.level - 1; iLevel >= 0; iLevel--) { - pn = SL_NODE_FORWARD(px, iLevel); - while (pn != pMemData->sl.pHead) { - pTKey = (TSDBKEY *)SL_NODE_DATA(pn); - - c = tsdbKeyCmprFn(pTKey, pKey); - if (c >= 0) { - break; - } else { - px = pn; - pn = SL_NODE_FORWARD(px, iLevel); - } - } - - pos[iLevel] = px; - } - } - } -} - -static int32_t memDataDoPut(SMemTable *pMemTable, SMemData *pMemData, SMemSkipListNode **pos, TSDBROW *pRow, - int8_t forward) { - int32_t code = 0; - int8_t level; - SMemSkipListNode *pNode; - SVBufPool *pPool = pMemTable->pTsdb->pVnode->inUse; - - // node - level = tsdbMemSkipListRandLevel(&pMemData->sl); - pNode = (SMemSkipListNode *)vnodeBufPoolMalloc(pPool, SL_NODE_SIZE(level) + tPutTSDBRow(NULL, pRow)); - if (pNode == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; - } - pNode->level = level; - for (int8_t iLevel = 0; iLevel < level; iLevel++) { - SL_NODE_FORWARD(pNode, iLevel) = NULL; - SL_NODE_BACKWARD(pNode, iLevel) = NULL; - } - - tPutTSDBRow((uint8_t *)SL_NODE_DATA(pNode), pRow); - - // put - for (int8_t iLevel = 0; iLevel < pNode->level; iLevel++) { - SMemSkipListNode *px = pos[iLevel]; - - if (forward) { - SMemSkipListNode *pNext = SL_NODE_FORWARD(px, iLevel); - - SL_NODE_FORWARD(pNode, iLevel) = pNext; - SL_NODE_BACKWARD(pNode, iLevel) = px; - - SL_NODE_BACKWARD(pNext, iLevel) = pNode; - SL_NODE_FORWARD(px, iLevel) = pNode; - } else { - SMemSkipListNode *pPrev = SL_NODE_BACKWARD(px, iLevel); - - SL_NODE_FORWARD(pNode, iLevel) = px; - SL_NODE_BACKWARD(pNode, iLevel) = pPrev; - - SL_NODE_FORWARD(pPrev, iLevel) = pNode; - SL_NODE_BACKWARD(px, iLevel) = pNode; - } - } - - pMemData->sl.size++; - if (pMemData->sl.level < pNode->level) { - pMemData->sl.level = pNode->level; - } - -_exit: - return code; -} - -static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, SMemData *pMemData, int64_t version, - SVSubmitBlk *pSubmitBlk) { - int32_t code = 0; - int32_t n = 0; - uint8_t *p = pSubmitBlk->pData; - int32_t nRow = 0; - TSDBROW row = {.version = version}; - - SMemSkipListNode *pos[SL_MAX_LEVEL]; - - ASSERT(pSubmitBlk->nData); - - // backward put first data - n += tGetTSRow(p + n, &row.tsRow); - ASSERT(n <= pSubmitBlk->nData); - - memDataMovePosTo(pMemData, pos, &(TSDBKEY){.version = version, .ts = row.tsRow.ts}, SL_MOVE_BACKWARD); - code = memDataDoPut(pMemTable, pMemData, pos, &row, 0); - if (code) { - goto _exit; - } - nRow++; - - if (tsdbKeyCmprFn((TSDBKEY *)&row, &pMemData->minKey) < 0) { - pMemData->minKey = *(TSDBKEY *)&row; - } - if (tsdbKeyCmprFn((TSDBKEY *)&row, &pMemTable->minKey) < 0) { - pMemTable->minKey = *(TSDBKEY *)&row; - } - - // forward put rest - for (int8_t iLevel = 0; iLevel < pMemData->sl.maxLevel; iLevel++) { - pos[iLevel] = SL_NODE_BACKWARD(pos[iLevel], iLevel); - } - while (n < pSubmitBlk->nData) { - n += tGetTSRow(p + n, &row.tsRow); - ASSERT(n <= pSubmitBlk->nData); - - memDataMovePosTo(pMemData, pos, &(TSDBKEY){.version = version, .ts = row.tsRow.ts}, SL_MOVE_FROM_POS); - code = memDataDoPut(pMemTable, pMemData, pos, &row, 1); - if (code) { - goto _exit; - } - - nRow++; - } - - if (tsdbKeyCmprFn((TSDBKEY *)&row, &pMemData->maxKey) > 0) { - pMemData->maxKey = *(TSDBKEY *)&row; - } - if (tsdbKeyCmprFn((TSDBKEY *)&row, &pMemTable->maxKey) > 0) { - pMemTable->maxKey = *(TSDBKEY *)&row; - } - pMemTable->nRows += nRow; - -_exit: - return code; -} diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 5fdb052ee5..146757096f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -67,15 +67,16 @@ enum { }; typedef struct STableCheckInfo { - uint64_t tableId; - TSKEY lastKey; - SBlockInfo* pCompInfo; - int32_t compSize; - int32_t numOfBlocks : 29; // number of qualified data blocks not the original blocks - uint8_t chosen : 2; // indicate which iterator should move forward - bool initBuf : 1; // whether to initialize the in-memory skip list iterator or not - SSkipListIterator* iter; // mem buffer skip list iterator - SSkipListIterator* iiter; // imem buffer skip list iterator + uint64_t suid; + uint64_t tableId; + TSKEY lastKey; + SBlockInfo* pCompInfo; + int32_t compSize; + int32_t numOfBlocks : 29; // number of qualified data blocks not the original blocks + uint8_t chosen : 2; // indicate which iterator should move forward + bool initBuf : 1; // whether to initialize the in-memory skip list iterator or not + STbDataIter* iter; // mem buffer skip list iterator + STbDataIter* iiter; // imem buffer skip list iterator } STableCheckInfo; typedef struct STableBlockInfo { @@ -107,6 +108,7 @@ typedef struct SBlockLoadSuppInfo { typedef struct STsdbReadHandle { STsdb* pTsdb; + uint64_t suid; SQueryFilePos cur; // current position int16_t order; STimeWindow window; // the primary query time window that applies to all queries @@ -200,8 +202,8 @@ static SArray* getDefaultLoadColumns(STsdbReadHandle* pTsdbReadHandle, bool load int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT* pHandle) { STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; - int64_t rows = 0; - STsdbMemTable* pMemTable = NULL; // pTsdbReadHandle->pMemTable; + int64_t rows = 0; + SMemTable* pMemTable = NULL; // pTsdbReadHandle->pMemTable; if (pMemTable == NULL) { return rows; } @@ -237,6 +239,7 @@ static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, S STableKeyInfo* pKeyInfo = (STableKeyInfo*)taosArrayGet(pTableList->pTableList, j); STableCheckInfo info = {.lastKey = pKeyInfo->lastKey, .tableId = pKeyInfo->uid}; + info.suid = pTsdbReadHandle->suid; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { if (info.lastKey == INT64_MIN || info.lastKey < pTsdbReadHandle->window.skey) { info.lastKey = pTsdbReadHandle->window.skey; @@ -265,8 +268,8 @@ static void resetCheckInfo(STsdbReadHandle* pTsdbReadHandle) { for (int32_t i = 0; i < numOfTables; ++i) { STableCheckInfo* pCheckInfo = (STableCheckInfo*)taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); pCheckInfo->lastKey = pTsdbReadHandle->window.skey; - pCheckInfo->iter = tSkipListDestroyIter(pCheckInfo->iter); - pCheckInfo->iiter = tSkipListDestroyIter(pCheckInfo->iiter); + pCheckInfo->iter = tsdbTbDataIterDestroy(pCheckInfo->iter); + pCheckInfo->iiter = tsdbTbDataIterDestroy(pCheckInfo->iiter); pCheckInfo->initBuf = false; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { @@ -387,6 +390,7 @@ static STsdbReadHandle* tsdbQueryTablesImpl(SVnode* pVnode, SQueryTableDataCond* pReadHandle->locateStart = false; pReadHandle->loadType = pCond->type; + pReadHandle->suid = pCond->suid; pReadHandle->outputCapacity = 4096; //((STsdb*)tsdb)->config.maxRowsPerFileBlock; pReadHandle->loadExternalRow = pCond->loadExternalRows; pReadHandle->currentLoadExternalRows = pCond->loadExternalRows; @@ -658,7 +662,7 @@ tsdbReaderT tsdbQueryLastRow(SVnode* pVnode, SQueryTableDataCond* pCond, STableL } #if 0 -tsdbReaderT tsdbQueryCacheLastT(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId, STsdbMemTable* pMemRef) { +tsdbReaderT tsdbQueryCacheLastT(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId, SMemTable* pMemRef) { STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) tsdbQueryTablesT(tsdb, pCond, groupList, qId, pMemRef); if (pTsdbReadHandle == NULL) { return NULL; @@ -752,23 +756,22 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe pCheckInfo->initBuf = true; int32_t order = pHandle->order; - STbData** pMem = NULL; - STbData** pIMem = NULL; + STbData* pMem = NULL; + STbData* pIMem = NULL; + int8_t backward = (pHandle->order == TSDB_ORDER_DESC) ? 1 : 0; TSKEY tLastKey = keyToTkey(pCheckInfo->lastKey); if (pHandle->pTsdb->mem != NULL) { - pMem = taosHashGet(pHandle->pTsdb->mem->pHashIdx, &pCheckInfo->tableId, sizeof(pCheckInfo->tableId)); + tsdbGetTbDataFromMemTable(pHandle->pTsdb->mem, pCheckInfo->suid, pCheckInfo->tableId, &pMem); if (pMem != NULL) { - pCheckInfo->iter = - tSkipListCreateIterFromVal((*pMem)->pData, (const char*)&tLastKey, TSDB_DATA_TYPE_TIMESTAMP, order); + tsdbTbDataIterCreate(pMem, &(TSDBKEY){.version = 0, .ts = tLastKey}, backward, &pCheckInfo->iter); } } if (pHandle->pTsdb->imem != NULL) { - pIMem = taosHashGet(pHandle->pTsdb->imem->pHashIdx, &pCheckInfo->tableId, sizeof(pCheckInfo->tableId)); + tsdbGetTbDataFromMemTable(pHandle->pTsdb->mem, pCheckInfo->suid, pCheckInfo->tableId, &pIMem); if (pIMem != NULL) { - pCheckInfo->iiter = - tSkipListCreateIterFromVal((*pIMem)->pData, (const char*)&tLastKey, TSDB_DATA_TYPE_TIMESTAMP, order); + tsdbTbDataIterCreate(pIMem, &(TSDBKEY){.version = 0, .ts = tLastKey}, backward, &pCheckInfo->iiter); } } @@ -777,22 +780,23 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe return false; } - bool memEmpty = (pCheckInfo->iter == NULL) || (pCheckInfo->iter != NULL && !tSkipListIterNext(pCheckInfo->iter)); - bool imemEmpty = (pCheckInfo->iiter == NULL) || (pCheckInfo->iiter != NULL && !tSkipListIterNext(pCheckInfo->iiter)); + bool memEmpty = + (pCheckInfo->iter == NULL) || (pCheckInfo->iter != NULL && !tsdbTbDataIterGet(pCheckInfo->iter, NULL)); + bool imemEmpty = + (pCheckInfo->iiter == NULL) || (pCheckInfo->iiter != NULL && !tsdbTbDataIterGet(pCheckInfo->iiter, NULL)); if (memEmpty && imemEmpty) { // buffer is empty return false; } if (!memEmpty) { - SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter); - assert(node != NULL); + TSDBROW row; - STSRow* row = (STSRow*)SL_GET_NODE_DATA(node); - TSKEY key = TD_ROW_KEY(row); // first timestamp in buffer + tsdbTbDataIterGet(pCheckInfo->iter, &row); + TSKEY key = row.pTSRow->ts; // first timestamp in buffer tsdbDebug("%p uid:%" PRId64 ", check data in mem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%" PRId64 ", %s", - pHandle, pCheckInfo->tableId, key, order, (*pMem)->keyMin, (*pMem)->keyMax, pCheckInfo->lastKey, - (*pMem)->nrows, pHandle->idStr); + pHandle, pCheckInfo->tableId, key, order, pMem->minKey.ts, pMem->maxKey.ts, pCheckInfo->lastKey, + pMem->sl.size, pHandle->idStr); if (ASCENDING_TRAVERSE(order)) { assert(pCheckInfo->lastKey <= key); @@ -805,15 +809,14 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe } if (!imemEmpty) { - SSkipListNode* node = tSkipListIterGet(pCheckInfo->iiter); - assert(node != NULL); + TSDBROW row; - STSRow* row = (STSRow*)SL_GET_NODE_DATA(node); - TSKEY key = TD_ROW_KEY(row); // first timestamp in buffer + tsdbTbDataIterGet(pCheckInfo->iter, &row); + TSKEY key = row.pTSRow->ts; // first timestamp in buffer tsdbDebug("%p uid:%" PRId64 ", check data in imem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%" PRId64 ", %s", - pHandle, pCheckInfo->tableId, key, order, (*pIMem)->keyMin, (*pIMem)->keyMax, pCheckInfo->lastKey, - (*pIMem)->nrows, pHandle->idStr); + pHandle, pCheckInfo->tableId, key, order, pIMem->minKey.ts, pIMem->maxKey.ts, pCheckInfo->lastKey, + pIMem->sl.size, pHandle->idStr); if (ASCENDING_TRAVERSE(order)) { assert(pCheckInfo->lastKey <= key); @@ -828,31 +831,23 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe } static void destroyTableMemIterator(STableCheckInfo* pCheckInfo) { - tSkipListDestroyIter(pCheckInfo->iter); - tSkipListDestroyIter(pCheckInfo->iiter); + tsdbTbDataIterDestroy(pCheckInfo->iter); + tsdbTbDataIterDestroy(pCheckInfo->iiter); } static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, int32_t update, TDRowVerT maxVer) { + TSDBROW row = {0}; STSRow *rmem = NULL, *rimem = NULL; + if (pCheckInfo->iter) { - SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter); - if (node != NULL) { - rmem = (STSRow*)SL_GET_NODE_DATA(node); - // TODO: filter max version - // if (TD_ROW_VER(rmem) > maxVer) { - // rmem = NULL; - // } + if (tsdbTbDataIterGet(pCheckInfo->iter, &row)) { + rmem = row.pTSRow; } } if (pCheckInfo->iiter) { - SSkipListNode* node = tSkipListIterGet(pCheckInfo->iiter); - if (node != NULL) { - rimem = (STSRow*)SL_GET_NODE_DATA(node); - // TODO: filter max version - // if (TD_ROW_VER(rimem) > maxVer) { - // rimem = NULL; - // } + if (tsdbTbDataIterGet(pCheckInfo->iiter, &row)) { + rimem = row.pTSRow; } } @@ -889,7 +884,7 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH; } else { pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - tSkipListIterNext(pCheckInfo->iter); + tsdbTbDataIterNext(pCheckInfo->iter); } return r1; } else if (r1 < r2 && ASCENDING_TRAVERSE(order)) { @@ -903,28 +898,17 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int32_t update, STSRow** extraRow, TDRowVerT maxVer) { + TSDBROW row; STSRow *rmem = NULL, *rimem = NULL; if (pCheckInfo->iter) { - SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter); - if (node != NULL) { - rmem = (STSRow*)SL_GET_NODE_DATA(node); -#if 0 // TODO: skiplist refactor - if (TD_ROW_VER(rmem) > maxVer) { - rmem = NULL; - } -#endif + if (tsdbTbDataIterGet(pCheckInfo->iter, &row)) { + rmem = row.pTSRow; } } if (pCheckInfo->iiter) { - SSkipListNode* node = tSkipListIterGet(pCheckInfo->iiter); - if (node != NULL) { - rimem = (STSRow*)SL_GET_NODE_DATA(node); -#if 0 // TODO: skiplist refactor - if (TD_ROW_VER(rimem) > maxVer) { - rimem = NULL; - } -#endif + if (tsdbTbDataIterGet(pCheckInfo->iiter, &row)) { + rimem = row.pTSRow; } } @@ -966,7 +950,7 @@ static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int *extraRow = rimem; return rmem; } else { - tSkipListIterNext(pCheckInfo->iter); + tsdbTbDataIterNext(pCheckInfo->iter); pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; return rimem; } @@ -995,7 +979,7 @@ static bool moveToNextRowInMem(STableCheckInfo* pCheckInfo) { bool hasNext = false; if (pCheckInfo->chosen == CHECKINFO_CHOSEN_MEM) { if (pCheckInfo->iter != NULL) { - hasNext = tSkipListIterNext(pCheckInfo->iter); + hasNext = tsdbTbDataIterNext(pCheckInfo->iter); } if (hasNext) { @@ -1003,11 +987,11 @@ static bool moveToNextRowInMem(STableCheckInfo* pCheckInfo) { } if (pCheckInfo->iiter != NULL) { - return tSkipListIterGet(pCheckInfo->iiter) != NULL; + return tsdbTbDataIterGet(pCheckInfo->iiter, NULL); } } else if (pCheckInfo->chosen == CHECKINFO_CHOSEN_IMEM) { if (pCheckInfo->iiter != NULL) { - hasNext = tSkipListIterNext(pCheckInfo->iiter); + hasNext = tsdbTbDataIterNext(pCheckInfo->iiter); } if (hasNext) { @@ -1015,14 +999,14 @@ static bool moveToNextRowInMem(STableCheckInfo* pCheckInfo) { } if (pCheckInfo->iter != NULL) { - return tSkipListIterGet(pCheckInfo->iter) != NULL; + return tsdbTbDataIterGet(pCheckInfo->iter, NULL); } } else { if (pCheckInfo->iter != NULL) { - hasNext = tSkipListIterNext(pCheckInfo->iter); + hasNext = tsdbTbDataIterNext(pCheckInfo->iter); } if (pCheckInfo->iiter != NULL) { - hasNext = tSkipListIterNext(pCheckInfo->iiter) || hasNext; + hasNext = tsdbTbDataIterNext(pCheckInfo->iiter) || hasNext; } } @@ -1126,7 +1110,7 @@ static int32_t loadBlockInfo(STsdbReadHandle* pTsdbReadHandle, int32_t index, in STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, index); pCheckInfo->numOfBlocks = 0; - STable table = {.uid = pCheckInfo->tableId, .tid = pCheckInfo->tableId}; + STable table = {.uid = pCheckInfo->tableId, .suid = pCheckInfo->suid}; table.pSchema = pTsdbReadHandle->pSchema; if (tsdbSetReadTable(&pTsdbReadHandle->rhelper, &table) != TSDB_CODE_SUCCESS) { @@ -2924,7 +2908,7 @@ static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { // current result is empty if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey && pTsdbReadHandle->cur.rows == 0) { - // STsdbMemTable* pMemRef = pTsdbReadHandle->pMemTable; + // SMemTable* pMemRef = pTsdbReadHandle->pMemTable; // doGetExternalRow(pTsdbReadHandle, TSDB_PREV_ROW, pMemRef); // doGetExternalRow(pTsdbReadHandle, TSDB_NEXT_ROW, pMemRef); @@ -3222,7 +3206,7 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { } } -// static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, STsdbMemTable* pMemRef) { +// static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, SMemTable* pMemRef) { // STsdbReadHandle* pSecQueryHandle = NULL; // // if (type == TSDB_PREV_ROW && pTsdbReadHandle->prev) { diff --git a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c index a26436156d..1c2514d46f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c @@ -156,6 +156,24 @@ int tsdbLoadBlockIdx(SReadH *pReadh) { return 0; } +static int32_t tsdbBlockIdxCmprFn(const void *p1, const void *p2) { + SBlockIdx *pBlockIdx1 = (SBlockIdx *)p1; + SBlockIdx *pBlockIdx2 = (SBlockIdx *)p2; + + if (pBlockIdx1->suid < pBlockIdx2->suid) { + return -1; + } else if (pBlockIdx1->suid > pBlockIdx2->suid) { + return 1; + } + + if (pBlockIdx1->uid < pBlockIdx2->uid) { + return -1; + } else if (pBlockIdx1->uid > pBlockIdx2->uid) { + return 1; + } + + return 0; +} int tsdbSetReadTable(SReadH *pReadh, STable *pTable) { STSchema *pSchema = tsdbGetTableSchemaImpl(TSDB_READ_REPO(pReadh), pTable, false, false, -1); @@ -171,32 +189,12 @@ int tsdbSetReadTable(SReadH *pReadh, STable *pTable) { return -1; } - size_t size = taosArrayGetSize(pReadh->aBlkIdx); - if (size > 0) { - while (true) { - if (pReadh->cidx >= size) { - pReadh->pBlkIdx = NULL; - break; - } - - SBlockIdx *pBlkIdx = taosArrayGet(pReadh->aBlkIdx, pReadh->cidx); - if (pBlkIdx->uid == TABLE_TID(pTable)) { - if (pBlkIdx->uid == TABLE_UID(pTable)) { - pReadh->pBlkIdx = pBlkIdx; - } else { - pReadh->pBlkIdx = NULL; - } - pReadh->cidx++; - break; - } else if (pBlkIdx->uid > TABLE_TID(pTable)) { - pReadh->pBlkIdx = NULL; - break; - } else { - pReadh->cidx++; - } - } - } else { + uint8_t *p = taosArraySearch(pReadh->aBlkIdx, &(SBlockIdx){.suid = pTable->suid, .uid = pTable->uid}, + tsdbBlockIdxCmprFn, TD_EQ); + if (p == NULL) { pReadh->pBlkIdx = NULL; + } else { + pReadh->pBlkIdx = (SBlockIdx *)p; } return 0; @@ -553,12 +551,12 @@ static int tsdbLoadBlockOffset(SReadH *pReadh, SBlock *pBlock) { int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx) { int tlen = 0; - // tlen += taosEncodeVariantI32(buf, pIdx->tid); + tlen += taosEncodeFixedU64(buf, pIdx->suid); + tlen += taosEncodeFixedU64(buf, pIdx->uid); tlen += taosEncodeVariantU32(buf, pIdx->len); tlen += taosEncodeVariantU32(buf, pIdx->offset); tlen += taosEncodeFixedU8(buf, pIdx->hasLast); tlen += taosEncodeVariantU32(buf, pIdx->numOfBlocks); - tlen += taosEncodeFixedU64(buf, pIdx->uid); tlen += taosEncodeFixedU64(buf, pIdx->maxKey.ts); return tlen; @@ -570,6 +568,10 @@ void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx) { uint64_t value = 0; // if ((buf = taosDecodeVariantI32(buf, &(pIdx->tid))) == NULL) return NULL; + if ((buf = taosDecodeFixedU64(buf, &value)) == NULL) return NULL; + pIdx->suid = (int64_t)value; + if ((buf = taosDecodeFixedU64(buf, &value)) == NULL) return NULL; + pIdx->uid = (int64_t)value; if ((buf = taosDecodeVariantU32(buf, &(pIdx->len))) == NULL) return NULL; if ((buf = taosDecodeVariantU32(buf, &(pIdx->offset))) == NULL) return NULL; if ((buf = taosDecodeFixedU8(buf, &(hasLast))) == NULL) return NULL; @@ -577,8 +579,6 @@ void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx) { if ((buf = taosDecodeVariantU32(buf, &(numOfBlocks))) == NULL) return NULL; pIdx->numOfBlocks = numOfBlocks; if ((buf = taosDecodeFixedU64(buf, &value)) == NULL) return NULL; - pIdx->uid = (int64_t)value; - if ((buf = taosDecodeFixedU64(buf, &value)) == NULL) return NULL; pIdx->maxKey.ts = (TSKEY)value; return buf; diff --git a/source/dnode/vnode/src/tsdb/tsdbWrite.c b/source/dnode/vnode/src/tsdb/tsdbWrite.c index 6faf6bd167..e184763bc8 100644 --- a/source/dnode/vnode/src/tsdb/tsdbWrite.c +++ b/source/dnode/vnode/src/tsdb/tsdbWrite.c @@ -39,7 +39,7 @@ int tsdbInsertData(STsdb *pTsdb, int64_t version, SSubmitReq *pMsg, SSubmitRsp * SSubmitBlkRsp r = {0}; tGetSubmitMsgNext(&msgIter, &pBlock); if (pBlock == NULL) break; - if (tsdbInsertTableData(pTsdb, &msgIter, pBlock, &r) < 0) { + if (tsdbInsertTableData(pTsdb, version, &msgIter, pBlock, &r) < 0) { return -1; } diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index a85b830616..dfc258b42b 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -81,7 +81,9 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { pVnode->state.applied = info.state.committed; pVnode->pTfs = pTfs; pVnode->msgCb = msgCb; + pVnode->syncCount = 0; + tsem_init(&pVnode->syncSem, 0, 0); tsem_init(&(pVnode->canCommit), 0, 1); // open buffer pool @@ -175,6 +177,7 @@ void vnodeClose(SVnode *pVnode) { vnodeCloseBufPool(pVnode); // destroy handle tsem_destroy(&(pVnode->canCommit)); + tsem_destroy(&pVnode->syncSem); taosMemoryFree(pVnode); } } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 4bcd5fc095..1524d8fe6f 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -24,6 +24,7 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); +static int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRpcMsg *pRsp); int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) { int32_t code = 0; @@ -90,9 +91,6 @@ int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) { } } break; - case TDMT_VND_ALTER_REPLICA: { - code = vnodeSyncAlter(pVnode, pMsg); - } break; default: break; } @@ -106,7 +104,7 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp int32_t len; int32_t ret; - vTrace("vgId:%d, start to process write request %s, version %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), + vTrace("vgId:%d, start to process write request %s, index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version); pVnode->state.applied = version; @@ -142,6 +140,9 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp case TDMT_VND_SUBMIT: if (vnodeProcessSubmitReq(pVnode, version, pMsg->pCont, pMsg->contLen, pRsp) < 0) goto _err; break; + case TDMT_VND_DELETE: + if (vnodeProcessWriteMsg(pVnode, version, pMsg, pRsp) < 0) goto _err; + break; /* TQ */ case TDMT_VND_MQ_VG_CHANGE: if (tqProcessVgChangeReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), @@ -154,7 +155,7 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp // TODO: handle error } break; - case TDMT_VND_TASK_DEPLOY: { + case TDMT_STREAM_TASK_DEPLOY: { if (tqProcessTaskDeploy(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead)) < 0) { } @@ -169,7 +170,7 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp break; } - vTrace("vgId:%d, process %s request success, version: %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version); + vTrace("vgId:%d, process %s request success, index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version); if (tqPushMsg(pVnode->pTq, pMsg->pCont, pMsg->contLen, pMsg->msgType, version) < 0) { vError("vgId:%d, failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno)); @@ -234,21 +235,19 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { case TDMT_VND_TABLE_META: return vnodeGetTableMeta(pVnode, pMsg); + case TDMT_VND_CONSUME: return tqProcessPollReq(pVnode->pTq, pMsg, pInfo->workerId); - case TDMT_VND_TASK_RUN: { - int32_t code = tqProcessTaskRunReq(pVnode->pTq, pMsg); - pMsg->pCont = NULL; - return code; - } - case TDMT_VND_TASK_DISPATCH: + case TDMT_STREAM_TASK_RUN: + return tqProcessTaskRunReq(pVnode->pTq, pMsg); + case TDMT_STREAM_TASK_DISPATCH: return tqProcessTaskDispatchReq(pVnode->pTq, pMsg); - case TDMT_VND_TASK_RECOVER: + case TDMT_STREAM_TASK_RECOVER: return tqProcessTaskRecoverReq(pVnode->pTq, pMsg); - case TDMT_VND_TASK_DISPATCH_RSP: + case TDMT_STREAM_TASK_DISPATCH_RSP: return tqProcessTaskDispatchRsp(pVnode->pTq, pMsg); - case TDMT_VND_TASK_RECOVER_RSP: + case TDMT_STREAM_TASK_RECOVER_RSP: return tqProcessTaskRecoverRsp(pVnode->pTq, pMsg); default: vError("unknown msg type:%d in fetch queue", pMsg->msgType); @@ -256,6 +255,22 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { } } +int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRpcMsg *pRsp) { + vTrace("message in write queue is processing"); + char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + SDeleteRes res = {0}; + SReadHandle handle = {.meta = pVnode->pMeta, .config = &pVnode->config, .vnode = pVnode, .pMsgCb = &pVnode->msgCb}; + + switch (pMsg->msgType) { + case TDMT_VND_DELETE: + return qWorkerProcessDeleteMsg(&handle, pVnode->pQuery, pMsg, pRsp, &res); + default: + vError("unknown msg type:%d in write queue", pMsg->msgType); + return TSDB_CODE_VND_APP_ERROR; + } +} + // TODO: remove the function void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { // TODO @@ -779,7 +794,7 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq sprintf(submitBlkRsp.tblFName, "%s.", pVnode->config.dbname); } - if (tsdbInsertTableData(pVnode->pTsdb, &msgIter, pBlock, &submitBlkRsp) < 0) { + if (tsdbInsertTableData(pVnode->pTsdb, version, &msgIter, pBlock, &submitBlkRsp) < 0) { submitBlkRsp.code = terrno; } @@ -873,4 +888,4 @@ static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void pRsp->contLen = 0; return 0; -} \ No newline at end of file +} diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c index 8f98e9cec5..203eecd8ab 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -16,13 +16,239 @@ #define _DEFAULT_SOURCE #include "vnd.h" -static int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg); -static int32_t vnodeSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg); -static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode); -static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta); -static void vnodeSyncPreCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta); -static void vnodeSyncRollBackMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta); -static int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot); +static inline bool vnodeIsMsgBlock(tmsg_t type) { + return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_ALTER_REPLICA); +} + +static inline bool vnodeIsMsgWeak(tmsg_t type) { return false; } + +static inline void vnodeAccumBlockMsg(SVnode *pVnode, tmsg_t type) { + if (!vnodeIsMsgBlock(type)) return; + + int32_t count = atomic_add_fetch_32(&pVnode->syncCount, 1); + vTrace("vgId:%d, accum block, count:%d type:%s", pVnode->config.vgId, count, TMSG_INFO(type)); +} + +static inline void vnodeWaitBlockMsg(SVnode *pVnode) { + int32_t count = atomic_load_32(&pVnode->syncCount); + if (count <= 0) return; + + vTrace("vgId:%d, wait block finish, count:%d", pVnode->config.vgId, count); + tsem_wait(&pVnode->syncSem); +} + +static inline void vnodePostBlockMsg(SVnode *pVnode, tmsg_t type) { + if (!vnodeIsMsgBlock(type)) return; + + int32_t count = atomic_load_32(&pVnode->syncCount); + if (count <= 0) return; + + count = atomic_sub_fetch_32(&pVnode->syncCount, 1); + vTrace("vgId:%d, post block, count:%d type:%s", pVnode->config.vgId, count, TMSG_INFO(type)); + if (count <= 0) { + tsem_post(&pVnode->syncSem); + } +} + +static int32_t vnodeProcessSyncReconfigReq(SVnode *pVnode, SRpcMsg *pMsg) { + SAlterVnodeReq req = {0}; + if (tDeserializeSAlterVnodeReq((char *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead), &req) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return TSDB_CODE_INVALID_MSG; + } + + vInfo("vgId:%d, start to alter vnode replica to %d", TD_VID(pVnode), req.replica); + SSyncCfg cfg = {.replicaNum = req.replica, .myIndex = req.selfIndex}; + for (int32_t r = 0; r < req.replica; ++r) { + SNodeInfo *pNode = &cfg.nodeInfo[r]; + tstrncpy(pNode->nodeFqdn, req.replicas[r].fqdn, sizeof(pNode->nodeFqdn)); + pNode->nodePort = req.replicas[r].port; + vInfo("vgId:%d, replica:%d %s:%u", TD_VID(pVnode), r, pNode->nodeFqdn, pNode->nodePort); + } + + return syncReconfig(pVnode->sync, &cfg); +} + +void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { + SVnode *pVnode = pInfo->ahandle; + int32_t vgId = pVnode->config.vgId; + int32_t code = 0; + SRpcMsg *pMsg = NULL; + + for (int32_t m = 0; m < numOfMsgs; m++) { + if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; + vTrace("vgId:%d, msg:%p get from vnode-write queue handle:%p", vgId, pMsg, pMsg->info.handle); + + if (pMsg->msgType == TDMT_VND_ALTER_REPLICA) { + code = vnodeProcessSyncReconfigReq(pVnode, pMsg); + } else { + code = vnodePreprocessReq(pVnode, pMsg); + if (code != 0) { + vError("vgId:%d, failed to pre-process msg:%p since %s", vgId, pMsg, terrstr()); + } else { + code = syncPropose(pVnode->sync, pMsg, vnodeIsMsgWeak(pMsg->msgType)); + } + } + + if (code == 0) { + vnodeAccumBlockMsg(pVnode, pMsg->msgType); + if (pMsg->msgType == TDMT_VND_ALTER_REPLICA) { + // todo refactor + SRpcMsg rsp = {.code = code, .info = pMsg->info}; + tmsgSendRsp(&rsp); + } + } else if (code == TAOS_SYNC_PROPOSE_NOT_LEADER) { + SEpSet newEpSet = {0}; + syncGetEpSet(pVnode->sync, &newEpSet); + SEp *pEp = &newEpSet.eps[newEpSet.inUse]; + if (pEp->port == tsServerPort && strcmp(pEp->fqdn, tsLocalFqdn) == 0) { + newEpSet.inUse = (newEpSet.inUse + 1) % newEpSet.numOfEps; + } + + vTrace("vgId:%d, msg:%p is redirect since not leader, numOfEps:%d inUse:%d", vgId, pMsg, newEpSet.numOfEps, + newEpSet.inUse); + for (int32_t i = 0; i < newEpSet.numOfEps; ++i) { + vTrace("vgId:%d, msg:%p redirect:%d ep:%s:%u", vgId, pMsg, i, newEpSet.eps[i].fqdn, newEpSet.eps[i].port); + } + + SRpcMsg rsp = {.code = TSDB_CODE_RPC_REDIRECT, .info = pMsg->info}; + tmsgSendRedirectRsp(&rsp, &newEpSet); + } else { + if (terrno != 0) code = terrno; + vError("vgId:%d, msg:%p failed to propose since %s, code:0x%x", vgId, pMsg, tstrerror(code), code); + SRpcMsg rsp = {.code = code, .info = pMsg->info}; + tmsgSendRsp(&rsp); + } + + vTrace("vgId:%d, msg:%p is freed, code:0x%x", vgId, pMsg, code); + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); + } + + vnodeWaitBlockMsg(pVnode); +} + +void vnodeApplyMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { + SVnode *pVnode = pInfo->ahandle; + int32_t vgId = pVnode->config.vgId; + int32_t code = 0; + SRpcMsg *pMsg = NULL; + + for (int32_t i = 0; i < numOfMsgs; ++i) { + if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; + vTrace("vgId:%d, msg:%p get from vnode-apply queue, handle:%p", vgId, pMsg, pMsg->info.handle); + + SRpcMsg rsp = {.code = pMsg->code, .info = pMsg->info}; + if (rsp.code == 0) { + if (vnodeProcessWriteReq(pVnode, pMsg, pMsg->conn.applyIndex, &rsp) < 0) { + rsp.code = terrno; + vError("vgId:%d, msg:%p failed to apply since %s", vgId, pMsg, terrstr()); + } + } + + vnodePostBlockMsg(pVnode, pMsg->msgType); + if (rsp.info.handle != NULL) { + tmsgSendRsp(&rsp); + } + + vTrace("vgId:%d, msg:%p is freed, code:0x%x", vgId, pMsg, rsp.code); + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); + } +} + +static int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { + int32_t code = tmsgPutToQueue(msgcb, SYNC_QUEUE, pMsg); + if (code != 0) { + rpcFreeCont(pMsg->pCont); + pMsg->pCont = NULL; + } + return code; +} + +static int32_t vnodeSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) { + int32_t code = tmsgSendReq(pEpSet, pMsg); + if (code != 0) { + rpcFreeCont(pMsg->pCont); + pMsg->pCont = NULL; + } + return code; +} + +static int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) { + vnodeGetSnapshot(pFsm->data, pSnapshot); + return 0; +} + +static void vnodeSyncReconfig(struct SSyncFSM *pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) { + SVnode *pVnode = pFsm->data; + vInfo("vgId:%d, sync reconfig is confirmed", TD_VID(pVnode)); + + // todo rpc response here + // build rpc msg + // put into apply queue +} + +static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { + SVnode *pVnode = pFsm->data; + SSnapshot snapshot = {0}; + SyncIndex beginIndex = SYNC_INDEX_INVALID; + char logBuf[256] = {0}; + + if (pFsm->FpGetSnapshot != NULL) { + (*pFsm->FpGetSnapshot)(pFsm, &snapshot); + beginIndex = snapshot.lastApplyIndex; + } + + if (cbMeta.index > beginIndex) { + snprintf( + logBuf, sizeof(logBuf), + "==callback== ==CommitCb== execute, pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, beginIndex :%ld\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), beginIndex); + syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); + + SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen, .conn.applyIndex = cbMeta.index}; + rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); + memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen); + syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info); + tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, &rpcMsg); + } else { + char logBuf[256] = {0}; + snprintf(logBuf, sizeof(logBuf), + "==callback== ==CommitCb== do not execute, pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, " + "beginIndex :%ld\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), + beginIndex); + syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); + } +} + +static void vnodeSyncPreCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { + char logBuf[256] = {0}; + snprintf(logBuf, sizeof(logBuf), + "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", pFsm, cbMeta.index, + cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); +} + +static void vnodeSyncRollBackMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { + char logBuf[256] = {0}; + snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); +} + +static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) { + SSyncFSM *pFsm = taosMemoryCalloc(1, sizeof(SSyncFSM)); + pFsm->data = pVnode; + pFsm->FpCommitCb = vnodeSyncCommitMsg; + pFsm->FpPreCommitCb = vnodeSyncPreCommitMsg; + pFsm->FpRollBackCb = vnodeSyncRollBackMsg; + pFsm->FpGetSnapshot = vnodeSyncGetSnapshot; + pFsm->FpRestoreFinishCb = NULL; + pFsm->FpReConfigCb = vnodeSyncReconfig; + return pFsm; +} int32_t vnodeSyncOpen(SVnode *pVnode, char *path) { SSyncInfo syncInfo = { @@ -50,33 +276,6 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) { return 0; } -int32_t vnodeSyncAlter(SVnode *pVnode, SRpcMsg *pMsg) { - SAlterVnodeReq req = {0}; - if (tDeserializeSAlterVnodeReq((char *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead), &req) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return TSDB_CODE_INVALID_MSG; - } - - vInfo("vgId:%d, start to alter vnode replica to %d", TD_VID(pVnode), req.replica); - SSyncCfg cfg = {.replicaNum = req.replica, .myIndex = req.selfIndex}; - for (int32_t r = 0; r < req.replica; ++r) { - SNodeInfo *pNode = &cfg.nodeInfo[r]; - tstrncpy(pNode->nodeFqdn, req.replicas[r].fqdn, sizeof(pNode->nodeFqdn)); - pNode->nodePort = req.replicas[r].port; - vInfo("vgId:%d, replica:%d %s:%u", TD_VID(pVnode), r, pNode->nodeFqdn, pNode->nodePort); - } - - int32_t code = syncReconfig(pVnode->sync, &cfg); - if (code == TAOS_SYNC_PROPOSE_SUCCESS) { - // todo refactor - SRpcMsg rsp = {.info = pMsg->info, .code = 0}; - tmsgSendRsp(&rsp); - return TSDB_CODE_ACTION_IN_PROGRESS; - } - - return code; -} - void vnodeSyncStart(SVnode *pVnode) { syncSetMsgCb(pVnode->sync, &pVnode->msgCb); if (pVnode->config.standby) { @@ -87,107 +286,3 @@ void vnodeSyncStart(SVnode *pVnode) { } void vnodeSyncClose(SVnode *pVnode) { syncStop(pVnode->sync); } - -int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { - int32_t code = tmsgPutToQueue(msgcb, SYNC_QUEUE, pMsg); - if (code != 0) { - rpcFreeCont(pMsg->pCont); - pMsg->pCont = NULL; - } - return code; -} - -int32_t vnodeSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) { - int32_t code = tmsgSendReq(pEpSet, pMsg); - if (code != 0) { - rpcFreeCont(pMsg->pCont); - pMsg->pCont = NULL; - } - return code; -} - -int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) { - vnodeGetSnapshot(pFsm->data, pSnapshot); - return 0; -} - -void vnodeSyncReconfig(struct SSyncFSM *pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) { - SVnode *pVnode = pFsm->data; - vInfo("vgId:%d, sync reconfig is confirmed", TD_VID(pVnode)); - - // todo rpc response here -} - -void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { - SyncIndex beginIndex = SYNC_INDEX_INVALID; - if (pFsm->FpGetSnapshot != NULL) { - SSnapshot snapshot = {0}; - pFsm->FpGetSnapshot(pFsm, &snapshot); - beginIndex = snapshot.lastApplyIndex; - } - - if (cbMeta.index > beginIndex) { - char logBuf[256] = {0}; - snprintf( - logBuf, sizeof(logBuf), - "==callback== ==CommitCb== execute, pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, beginIndex :%ld\n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), beginIndex); - syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); - - SVnode *pVnode = pFsm->data; - SyncApplyMsg *pSyncApplyMsg = syncApplyMsgBuild2(pMsg, pVnode->config.vgId, &cbMeta); - SRpcMsg applyMsg; - syncApplyMsg2RpcMsg(pSyncApplyMsg, &applyMsg); - syncApplyMsgDestroy(pSyncApplyMsg); - - // recover handle for response - SRpcMsg saveRpcMsg; - int32_t ret = syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &saveRpcMsg); - if (ret == 1 && cbMeta.state == TAOS_SYNC_STATE_LEADER) { - applyMsg.info = saveRpcMsg.info; - } else { - applyMsg.info.handle = NULL; - applyMsg.info.ahandle = NULL; - } - - // put to applyQ - tmsgPutToQueue(&(pVnode->msgCb), APPLY_QUEUE, &applyMsg); - - } else { - char logBuf[256] = {0}; - snprintf(logBuf, sizeof(logBuf), - "==callback== ==CommitCb== do not execute, pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, " - "beginIndex :%ld\n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), - beginIndex); - syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); - } -} - -void vnodeSyncPreCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { - char logBuf[256] = {0}; - snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", pFsm, cbMeta.index, - cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); - syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); -} - -void vnodeSyncRollBackMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { - char logBuf[256] = {0}; - snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); - syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); -} - -SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) { - SSyncFSM *pFsm = taosMemoryCalloc(1, sizeof(SSyncFSM)); - pFsm->data = pVnode; - pFsm->FpCommitCb = vnodeSyncCommitMsg; - pFsm->FpPreCommitCb = vnodeSyncPreCommitMsg; - pFsm->FpRollBackCb = vnodeSyncRollBackMsg; - pFsm->FpGetSnapshot = vnodeSyncGetSnapshot; - pFsm->FpRestoreFinishCb = NULL; - pFsm->FpReConfigCb = vnodeSyncReconfig; - - return pFsm; -} \ No newline at end of file diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 9219a382e4..3de9ba5f0e 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -173,7 +173,6 @@ typedef struct SCtgJob { SArray* pTasks; int32_t taskDone; SMetaData jobRes; - int32_t rspCode; uint64_t queryId; SCatalog* pCtg; @@ -201,11 +200,12 @@ typedef struct SCtgMsgCtx { typedef struct SCtgTask { CTG_TASK_TYPE type; - int32_t taskId; - SCtgJob *pJob; - void* taskCtx; - SCtgMsgCtx msgCtx; - void* res; + int32_t taskId; + SCtgJob* pJob; + void* taskCtx; + SCtgMsgCtx msgCtx; + int32_t code; + void* res; } SCtgTask; typedef int32_t (*ctgLanchTaskFp)(SCtgTask*); @@ -310,22 +310,19 @@ typedef struct SCtgCacheOperation { int32_t opId; void *data; bool syncOp; - uint64_t seqId; + tsem_t rspSem; } SCtgCacheOperation; typedef struct SCtgQNode { - SCtgCacheOperation op; + SCtgCacheOperation *op; struct SCtgQNode *next; } SCtgQNode; typedef struct SCtgQueue { SRWLatch qlock; - uint64_t seqId; - uint64_t seqDone; SCtgQNode *head; SCtgQNode *tail; tsem_t reqSem; - tsem_t rspSem; uint64_t qRemainNum; } SCtgQueue; @@ -493,6 +490,7 @@ int32_t ctgGetDBVgInfoFromMnode(CTG_PARAMS, SBuildUseDBInput *input, SUseDbOutpu int32_t ctgGetQnodeListFromMnode(CTG_PARAMS, SArray *out, SCtgTask* pTask); int32_t ctgGetDBCfgFromMnode(CTG_PARAMS, const char *dbFName, SDbCfgInfo *out, SCtgTask* pTask); int32_t ctgGetIndexInfoFromMnode(CTG_PARAMS, const char *indexName, SIndexInfo *out, SCtgTask* pTask); +int32_t ctgGetTbIndexFromMnode(CTG_PARAMS, const char *tbFName, SArray** out, SCtgTask* pTask); int32_t ctgGetUdfInfoFromMnode(CTG_PARAMS, const char *funcName, SFuncInfo *out, SCtgTask* pTask); int32_t ctgGetUserDbAuthFromMnode(CTG_PARAMS, const char *user, SGetUserAuthRsp *out, SCtgTask* pTask); int32_t ctgGetTbMetaFromMnodeImpl(CTG_PARAMS, char *dbFName, char* tbName, STableMetaOutput* out, SCtgTask* pTask); @@ -518,6 +516,7 @@ int32_t ctgStbVersionSearchCompare(const void* key1, const void* key2); 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); +char *ctgTaskTypeStr(CTG_TASK_TYPE type); extern SCatalogMgmt gCtgMgmt; diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 040156eca2..0f6a79c14c 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -506,11 +506,6 @@ int32_t catalogInit(SCatalogCfg *cfg) { CTG_ERR_RET(TSDB_CODE_CTG_SYS_ERROR); } - if (tsem_init(&gCtgMgmt.queue.rspSem, 0, 0)) { - qError("tsem_init failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno))); - CTG_ERR_RET(TSDB_CODE_CTG_SYS_ERROR); - } - gCtgMgmt.queue.head = taosMemoryCalloc(1, sizeof(SCtgQNode)); if (NULL == gCtgMgmt.queue.head) { qError("calloc %d failed", (int32_t)sizeof(SCtgQNode)); @@ -1141,6 +1136,17 @@ int32_t catalogGetIndexMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps CTG_API_LEAVE(ctgGetIndexInfoFromMnode(CTG_PARAMS_LIST(), indexName, pInfo, NULL)); } +int32_t catalogGetTableIndex(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const char* tbFName, SArray** pRes) { + CTG_API_ENTER(); + + if (NULL == pCtg || NULL == pTrans || NULL == pMgmtEps || NULL == tbFName || NULL == pRes) { + CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); + } + + CTG_API_LEAVE(ctgGetTbIndexFromMnode(CTG_PARAMS_LIST(), tbFName, pRes, NULL)); +} + + int32_t catalogGetUdfInfo(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const char* funcName, SFuncInfo* pInfo) { CTG_API_ENTER(); @@ -1194,10 +1200,6 @@ void catalogDestroy(void) { if (tsem_post(&gCtgMgmt.queue.reqSem)) { qError("tsem_post failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno))); } - - if (tsem_post(&gCtgMgmt.queue.rspSem)) { - qError("tsem_post failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno))); - } while (CTG_IS_LOCKED(&gCtgMgmt.lock)) { taosUsleep(1); diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 6998d8c778..bc2c8dad7a 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -44,7 +44,7 @@ int32_t ctgInitGetTbMetaTask(SCtgJob *pJob, int32_t taskIdx, SName *name) { taosArrayPush(pJob->pTasks, &task); - qDebug("QID:0x%" PRIx64 " task %d type %d initialized, tableName:%s", pJob->queryId, taskIdx, task.type, name->tname); + qDebug("QID:0x%" PRIx64 " the %d task type %s initialized, tableName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), name->tname); return TSDB_CODE_SUCCESS; } @@ -67,7 +67,7 @@ int32_t ctgInitGetDbVgTask(SCtgJob *pJob, int32_t taskIdx, char *dbFName) { taosArrayPush(pJob->pTasks, &task); - qDebug("QID:%" PRIx64 " task %d type %d initialized, dbFName:%s", pJob->queryId, taskIdx, task.type, dbFName); + qDebug("QID:0x%" PRIx64 " the %d task type %s initialized, dbFName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), dbFName); return TSDB_CODE_SUCCESS; } @@ -90,7 +90,7 @@ int32_t ctgInitGetDbCfgTask(SCtgJob *pJob, int32_t taskIdx, char *dbFName) { taosArrayPush(pJob->pTasks, &task); - qDebug("QID:%" PRIx64 " task %d type %d initialized, dbFName:%s", pJob->queryId, taskIdx, task.type, dbFName); + qDebug("QID:0x%" PRIx64 " the %d task type %s initialized, dbFName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), dbFName); return TSDB_CODE_SUCCESS; } @@ -113,7 +113,7 @@ int32_t ctgInitGetDbInfoTask(SCtgJob *pJob, int32_t taskIdx, char *dbFName) { taosArrayPush(pJob->pTasks, &task); - qDebug("QID:%" PRIx64 " task %d type %d initialized, dbFName:%s", pJob->queryId, taskIdx, task.type, dbFName); + qDebug("QID:0x%" PRIx64 " the %d task type %s initialized, dbFName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), dbFName); return TSDB_CODE_SUCCESS; } @@ -143,7 +143,7 @@ int32_t ctgInitGetTbHashTask(SCtgJob *pJob, int32_t taskIdx, SName *name) { taosArrayPush(pJob->pTasks, &task); - qDebug("QID:0x%" PRIx64 " task %d type %d initialized, tableName:%s", pJob->queryId, taskIdx, task.type, name->tname); + qDebug("QID:0x%" PRIx64 " the %d task type %s initialized, tableName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), name->tname); return TSDB_CODE_SUCCESS; } @@ -158,7 +158,7 @@ int32_t ctgInitGetQnodeTask(SCtgJob *pJob, int32_t taskIdx) { taosArrayPush(pJob->pTasks, &task); - qDebug("QID:%" PRIx64 " task %d type %d initialized", pJob->queryId, taskIdx, task.type); + qDebug("QID:%" PRIx64 " the %d task type %s initialized", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type)); return TSDB_CODE_SUCCESS; } @@ -181,7 +181,7 @@ int32_t ctgInitGetIndexTask(SCtgJob *pJob, int32_t taskIdx, char *name) { taosArrayPush(pJob->pTasks, &task); - qDebug("QID:%" PRIx64 " task %d type %d initialized, indexFName:%s", pJob->queryId, taskIdx, task.type, name); + qDebug("QID:%" PRIx64 " the %d task type %s initialized, indexFName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), name); return TSDB_CODE_SUCCESS; } @@ -204,7 +204,7 @@ int32_t ctgInitGetUdfTask(SCtgJob *pJob, int32_t taskIdx, char *name) { taosArrayPush(pJob->pTasks, &task); - qDebug("QID:%" PRIx64 " task %d type %d initialized, udfName:%s", pJob->queryId, taskIdx, task.type, name); + qDebug("QID:%" PRIx64 " the %d task type %s initialized, udfName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), name); return TSDB_CODE_SUCCESS; } @@ -227,11 +227,96 @@ int32_t ctgInitGetUserTask(SCtgJob *pJob, int32_t taskIdx, SUserAuthInfo *user) taosArrayPush(pJob->pTasks, &task); - qDebug("QID:%" PRIx64 " task %d type %d initialized, user:%s", pJob->queryId, taskIdx, task.type, user->user); + qDebug("QID:%" PRIx64 " the %d task type %s initialized, user:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), user->user); return TSDB_CODE_SUCCESS; } +int32_t ctgHandleForceUpdate(SCatalog* pCtg, SCtgJob *pJob, const SCatalogReq* pReq) { + int32_t dbNum = pJob->dbCfgNum + pJob->dbVgNum + pJob->dbInfoNum; + if (dbNum > 0) { + if (dbNum > pJob->dbCfgNum && dbNum > pJob->dbVgNum && dbNum > pJob->dbInfoNum) { + SHashObj* pDb = taosHashInit(dbNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + if (NULL == pDb) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + + for (int32_t i = 0; i < pJob->dbVgNum; ++i) { + char* dbFName = taosArrayGet(pReq->pDbVgroup, i); + taosHashPut(pDb, dbFName, strlen(dbFName), dbFName, TSDB_DB_FNAME_LEN); + } + + for (int32_t i = 0; i < pJob->dbCfgNum; ++i) { + char* dbFName = taosArrayGet(pReq->pDbCfg, i); + taosHashPut(pDb, dbFName, strlen(dbFName), dbFName, TSDB_DB_FNAME_LEN); + } + + for (int32_t i = 0; i < pJob->dbInfoNum; ++i) { + char* dbFName = taosArrayGet(pReq->pDbInfo, i); + taosHashPut(pDb, dbFName, strlen(dbFName), dbFName, TSDB_DB_FNAME_LEN); + } + + char* dbFName = taosHashIterate(pDb, NULL); + while (dbFName) { + ctgDropDbVgroupEnqueue(pCtg, dbFName, true); + dbFName = taosHashIterate(pDb, dbFName); + } + + taosHashCleanup(pDb); + } else { + for (int32_t i = 0; i < pJob->dbVgNum; ++i) { + char* dbFName = taosArrayGet(pReq->pDbVgroup, i); + CTG_ERR_RET(ctgDropDbVgroupEnqueue(pCtg, dbFName, true)); + } + + for (int32_t i = 0; i < pJob->dbCfgNum; ++i) { + char* dbFName = taosArrayGet(pReq->pDbCfg, i); + CTG_ERR_RET(ctgDropDbVgroupEnqueue(pCtg, dbFName, true)); + } + + for (int32_t i = 0; i < pJob->dbInfoNum; ++i) { + char* dbFName = taosArrayGet(pReq->pDbInfo, i); + CTG_ERR_RET(ctgDropDbVgroupEnqueue(pCtg, dbFName, true)); + } + } + } + + int32_t tbNum = pJob->tbMetaNum + pJob->tbHashNum; + if (tbNum > 0) { + if (tbNum > pJob->tbMetaNum && tbNum > pJob->tbHashNum) { + SHashObj* pTb = taosHashInit(tbNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + for (int32_t i = 0; i < pJob->tbMetaNum; ++i) { + SName* name = taosArrayGet(pReq->pTableMeta, i); + taosHashPut(pTb, name, sizeof(SName), name, sizeof(SName)); + } + + for (int32_t i = 0; i < pJob->tbHashNum; ++i) { + SName* name = taosArrayGet(pReq->pTableHash, i); + taosHashPut(pTb, name, sizeof(SName), name, sizeof(SName)); + } + + SName* name = taosHashIterate(pTb, NULL); + while (name) { + catalogRemoveTableMeta(pCtg, name); + name = taosHashIterate(pTb, name); + } + + taosHashCleanup(pTb); + } else { + for (int32_t i = 0; i < pJob->tbMetaNum; ++i) { + SName* name = taosArrayGet(pReq->pTableMeta, i); + catalogRemoveTableMeta(pCtg, name); + } + + for (int32_t i = 0; i < pJob->tbHashNum; ++i) { + SName* name = taosArrayGet(pReq->pTableHash, i); + catalogRemoveTableMeta(pCtg, name); + } + } + } + + return TSDB_CODE_SUCCESS; +} int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq* pReq, catalogCallback fp, void* param, int32_t* taskNum) { int32_t code = 0; @@ -283,12 +368,13 @@ int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq* CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); } + if (pReq->forceUpdate) { + CTG_ERR_JRET(ctgHandleForceUpdate(pCtg, pJob, pReq)); + } + int32_t taskIdx = 0; for (int32_t i = 0; i < dbVgNum; ++i) { char* dbFName = taosArrayGet(pReq->pDbVgroup, i); - if (pReq->forceUpdate) { - ctgDropDbVgroupEnqueue(pCtg, dbFName, true); - } CTG_ERR_JRET(ctgInitGetDbVgTask(pJob, taskIdx++, dbFName)); } @@ -304,9 +390,6 @@ int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq* for (int32_t i = 0; i < tbMetaNum; ++i) { SName* name = taosArrayGet(pReq->pTableMeta, i); - if (pReq->forceUpdate) { - catalogRemoveTableMeta(pCtg, name); - } CTG_ERR_JRET(ctgInitGetTbMetaTask(pJob, taskIdx++, name)); } @@ -342,7 +425,7 @@ int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq* taosAcquireRef(gCtgMgmt.jobPool, pJob->refId); - qDebug("QID:%" PRIx64 ", job %" PRIx64 " initialized, task num %d", pJob->queryId, pJob->refId, *taskNum); + qDebug("QID:0x%" PRIx64 ", jobId: 0x%" PRIx64 " initialized, task num %d, forceUpdate %d", pJob->queryId, pJob->refId, *taskNum, pReq->forceUpdate); return TSDB_CODE_SUCCESS; @@ -354,13 +437,14 @@ _return: int32_t ctgDumpTbMetaRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pTableMeta) { - pJob->jobRes.pTableMeta = taosArrayInit(pJob->tbMetaNum, POINTER_BYTES); + pJob->jobRes.pTableMeta = taosArrayInit(pJob->tbMetaNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pTableMeta) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pTableMeta, &pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pTableMeta, &res); return TSDB_CODE_SUCCESS; } @@ -368,14 +452,14 @@ int32_t ctgDumpTbMetaRes(SCtgTask* pTask) { int32_t ctgDumpDbVgRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pDbVgroup) { - pJob->jobRes.pDbVgroup = taosArrayInit(pJob->dbVgNum, POINTER_BYTES); + pJob->jobRes.pDbVgroup = taosArrayInit(pJob->dbVgNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pDbVgroup) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pDbVgroup, &pTask->res); - pTask->res = NULL; + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pDbVgroup, &res); return TSDB_CODE_SUCCESS; } @@ -383,13 +467,14 @@ int32_t ctgDumpDbVgRes(SCtgTask* pTask) { int32_t ctgDumpTbHashRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pTableHash) { - pJob->jobRes.pTableHash = taosArrayInit(pJob->tbHashNum, sizeof(SVgroupInfo)); + pJob->jobRes.pTableHash = taosArrayInit(pJob->tbHashNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pTableHash) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pTableHash, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pTableHash, &res); return TSDB_CODE_SUCCESS; } @@ -397,21 +482,29 @@ int32_t ctgDumpTbHashRes(SCtgTask* pTask) { int32_t ctgDumpIndexRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pIndex) { - pJob->jobRes.pIndex = taosArrayInit(pJob->indexNum, sizeof(SIndexInfo)); + pJob->jobRes.pIndex = taosArrayInit(pJob->indexNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pIndex) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pIndex, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pIndex, &res); return TSDB_CODE_SUCCESS; } int32_t ctgDumpQnodeRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; + if (NULL == pJob->jobRes.pQnodeList) { + pJob->jobRes.pQnodeList = taosArrayInit(1, sizeof(SMetaRes)); + if (NULL == pJob->jobRes.pQnodeList) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + } - TSWAP(pJob->jobRes.pQnodeList, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pQnodeList, &res); return TSDB_CODE_SUCCESS; } @@ -419,13 +512,14 @@ int32_t ctgDumpQnodeRes(SCtgTask* pTask) { int32_t ctgDumpDbCfgRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pDbCfg) { - pJob->jobRes.pDbCfg = taosArrayInit(pJob->dbCfgNum, sizeof(SDbCfgInfo)); + pJob->jobRes.pDbCfg = taosArrayInit(pJob->dbCfgNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pDbCfg) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pDbCfg, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pDbCfg, &res); return TSDB_CODE_SUCCESS; } @@ -433,13 +527,14 @@ int32_t ctgDumpDbCfgRes(SCtgTask* pTask) { int32_t ctgDumpDbInfoRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pDbInfo) { - pJob->jobRes.pDbInfo = taosArrayInit(pJob->dbInfoNum, sizeof(SDbInfo)); + pJob->jobRes.pDbInfo = taosArrayInit(pJob->dbInfoNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pDbInfo) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pDbInfo, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pDbInfo, &res); return TSDB_CODE_SUCCESS; } @@ -447,13 +542,14 @@ int32_t ctgDumpDbInfoRes(SCtgTask* pTask) { int32_t ctgDumpUdfRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pUdfList) { - pJob->jobRes.pUdfList = taosArrayInit(pJob->udfNum, sizeof(SFuncInfo)); + pJob->jobRes.pUdfList = taosArrayInit(pJob->udfNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pUdfList) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pUdfList, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pUdfList, &res); return TSDB_CODE_SUCCESS; } @@ -461,13 +557,14 @@ int32_t ctgDumpUdfRes(SCtgTask* pTask) { int32_t ctgDumpUserRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pUser) { - pJob->jobRes.pUser = taosArrayInit(pJob->userNum, sizeof(bool)); + pJob->jobRes.pUser = taosArrayInit(pJob->userNum, sizeof(SMetaRes)); if (NULL == pJob->jobRes.pUser) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } - taosArrayPush(pJob->jobRes.pUser, pTask->res); + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pUser, &res); return TSDB_CODE_SUCCESS; } @@ -476,20 +573,13 @@ int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) { SCtgJob* pJob = pTask->pJob; int32_t code = 0; - qDebug("QID:%" PRIx64 " task %d end with rsp %s", pJob->queryId, pTask->taskId, tstrerror(rspCode)); + qDebug("QID:0x%" PRIx64 " task %d end with rsp %s", pJob->queryId, pTask->taskId, tstrerror(rspCode)); - if (rspCode) { - int32_t lastCode = atomic_val_compare_exchange_32(&pJob->rspCode, 0, rspCode); - if (0 == lastCode) { - CTG_ERR_JRET(rspCode); - } - - return TSDB_CODE_SUCCESS; - } + pTask->code = rspCode; int32_t taskDone = atomic_add_fetch_32(&pJob->taskDone, 1); if (taskDone < taosArrayGetSize(pJob->pTasks)) { - qDebug("task done: %d, total: %d", taskDone, (int32_t)taosArrayGetSize(pJob->pTasks)); + qDebug("QID:0x%" PRIx64 " task done: %d, total: %d", pJob->queryId, taskDone, (int32_t)taosArrayGetSize(pJob->pTasks)); return TSDB_CODE_SUCCESS; } @@ -1108,7 +1198,7 @@ int32_t ctgLaunchJob(SCtgJob *pJob) { for (int32_t i = 0; i < taskNum; ++i) { SCtgTask *pTask = taosArrayGet(pJob->pTasks, i); - qDebug("QID:%" PRIx64 " start to launch task %d", pJob->queryId, pTask->taskId); + qDebug("QID:0x%" PRIx64 " start to launch task %d", pJob->queryId, pTask->taskId); CTG_ERR_RET((*gCtgAsyncFps[pTask->type].launchFp)(pTask)); } diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c index 8332c7b068..59aab9fd22 100644 --- a/source/libs/catalog/src/ctgCache.c +++ b/source/libs/catalog/src/ctgCache.c @@ -501,25 +501,6 @@ _return: return TSDB_CODE_SUCCESS; } - -void ctgWaitOpDone(SCtgCacheOperation *action) { - while (true) { - tsem_wait(&gCtgMgmt.queue.rspSem); - - if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { - tsem_post(&gCtgMgmt.queue.rspSem); - break; - } - - if (gCtgMgmt.queue.seqDone >= action->seqId) { - break; - } - - tsem_post(&gCtgMgmt.queue.rspSem); - sched_yield(); - } -} - void ctgDequeue(SCtgCacheOperation **op) { SCtgQNode *orig = gCtgMgmt.queue.head; @@ -530,7 +511,7 @@ void ctgDequeue(SCtgCacheOperation **op) { taosMemoryFreeClear(orig); - *op = &node->op; + *op = node->op; } @@ -541,9 +522,11 @@ int32_t ctgEnqueue(SCatalog* pCtg, SCtgCacheOperation *operation) { CTG_RET(TSDB_CODE_CTG_MEM_ERROR); } - operation->seqId = atomic_add_fetch_64(&gCtgMgmt.queue.seqId, 1); + if (operation->syncOp) { + tsem_init(&operation->rspSem, 0, 0); + } - node->op = *operation; + node->op = operation; CTG_LOCK(CTG_WRITE, &gCtgMgmt.queue.qlock); gCtgMgmt.queue.tail->next = node; @@ -558,7 +541,8 @@ int32_t ctgEnqueue(SCatalog* pCtg, SCtgCacheOperation *operation) { ctgDebug("action [%s] added into queue", gCtgCacheOperation[operation->opId].name); if (operation->syncOp) { - ctgWaitOpDone(operation); + tsem_wait(&operation->rspSem); + taosMemoryFree(operation); } return TSDB_CODE_SUCCESS; @@ -567,7 +551,9 @@ int32_t ctgEnqueue(SCatalog* pCtg, SCtgCacheOperation *operation) { int32_t ctgDropDbCacheEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_DROP_DB_CACHE}; + SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation)); + op->opId = CTG_OP_DROP_DB_CACHE; + SCtgDropDBMsg *msg = taosMemoryMalloc(sizeof(SCtgDropDBMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgDropDBMsg)); @@ -583,21 +569,24 @@ int32_t ctgDropDbCacheEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId) strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName)); msg->dbId = dbId; - action.data = msg; + op->data = msg; - CTG_ERR_JRET(ctgEnqueue(pCtg, &action)); + CTG_ERR_JRET(ctgEnqueue(pCtg, op)); return TSDB_CODE_SUCCESS; _return: - taosMemoryFreeClear(action.data); + taosMemoryFreeClear(op->data); CTG_RET(code); } int32_t ctgDropDbVgroupEnqueue(SCatalog* pCtg, const char *dbFName, bool syncOp) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_DROP_DB_VGROUP, .syncOp = syncOp}; + SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation)); + op->opId = CTG_OP_DROP_DB_VGROUP; + op->syncOp = syncOp; + SCtgDropDbVgroupMsg *msg = taosMemoryMalloc(sizeof(SCtgDropDbVgroupMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgDropDbVgroupMsg)); @@ -612,15 +601,15 @@ int32_t ctgDropDbVgroupEnqueue(SCatalog* pCtg, const char *dbFName, bool syncOp) msg->pCtg = pCtg; strncpy(msg->dbFName, dbFName, sizeof(msg->dbFName)); - action.data = msg; + op->data = msg; - CTG_ERR_JRET(ctgEnqueue(pCtg, &action)); + CTG_ERR_JRET(ctgEnqueue(pCtg, op)); return TSDB_CODE_SUCCESS; _return: - taosMemoryFreeClear(action.data); + taosMemoryFreeClear(op->data); CTG_RET(code); } @@ -628,7 +617,10 @@ _return: int32_t ctgDropStbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *stbName, uint64_t suid, bool syncOp) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_DROP_STB_META, .syncOp = syncOp}; + SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation)); + op->opId = CTG_OP_DROP_STB_META; + op->syncOp = syncOp; + SCtgDropStbMetaMsg *msg = taosMemoryMalloc(sizeof(SCtgDropStbMetaMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgDropStbMetaMsg)); @@ -641,15 +633,15 @@ int32_t ctgDropStbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, msg->dbId = dbId; msg->suid = suid; - action.data = msg; + op->data = msg; - CTG_ERR_JRET(ctgEnqueue(pCtg, &action)); + CTG_ERR_JRET(ctgEnqueue(pCtg, op)); return TSDB_CODE_SUCCESS; _return: - taosMemoryFreeClear(action.data); + taosMemoryFreeClear(op->data); CTG_RET(code); } @@ -657,7 +649,10 @@ _return: int32_t ctgDropTbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *tbName, bool syncOp) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_DROP_TB_META, .syncOp = syncOp}; + SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation)); + op->opId = CTG_OP_DROP_TB_META; + op->syncOp = syncOp; + SCtgDropTblMetaMsg *msg = taosMemoryMalloc(sizeof(SCtgDropTblMetaMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgDropTblMetaMsg)); @@ -669,21 +664,24 @@ int32_t ctgDropTbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, strncpy(msg->tbName, tbName, sizeof(msg->tbName)); msg->dbId = dbId; - action.data = msg; + op->data = msg; - CTG_ERR_JRET(ctgEnqueue(pCtg, &action)); + CTG_ERR_JRET(ctgEnqueue(pCtg, op)); return TSDB_CODE_SUCCESS; _return: - taosMemoryFreeClear(action.data); + taosMemoryFreeClear(op->data); CTG_RET(code); } int32_t ctgUpdateVgroupEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, SDBVgInfo* dbInfo, bool syncOp) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_UPDATE_VGROUP, .syncOp = syncOp}; + SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation)); + op->opId = CTG_OP_UPDATE_VGROUP; + op->syncOp = syncOp; + SCtgUpdateVgMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateVgMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateVgMsg)); @@ -701,22 +699,25 @@ int32_t ctgUpdateVgroupEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId msg->dbId = dbId; msg->dbInfo = dbInfo; - action.data = msg; + op->data = msg; - CTG_ERR_JRET(ctgEnqueue(pCtg, &action)); + CTG_ERR_JRET(ctgEnqueue(pCtg, op)); return TSDB_CODE_SUCCESS; _return: ctgFreeVgInfo(dbInfo); - taosMemoryFreeClear(action.data); + taosMemoryFreeClear(op->data); CTG_RET(code); } int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool syncOp) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_UPDATE_TB_META, .syncOp = syncOp}; + SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation)); + op->opId = CTG_OP_UPDATE_TB_META; + op->syncOp = syncOp; + SCtgUpdateTblMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateTblMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateTblMsg)); @@ -731,9 +732,9 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool sy msg->pCtg = pCtg; msg->output = output; - action.data = msg; + op->data = msg; - CTG_ERR_JRET(ctgEnqueue(pCtg, &action)); + CTG_ERR_JRET(ctgEnqueue(pCtg, op)); return TSDB_CODE_SUCCESS; @@ -746,7 +747,9 @@ _return: int32_t ctgUpdateVgEpsetEnqueue(SCatalog* pCtg, char *dbFName, int32_t vgId, SEpSet* pEpSet) { int32_t code = 0; - SCtgCacheOperation operation= {.opId = CTG_OP_UPDATE_VG_EPSET}; + SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation)); + op->opId = CTG_OP_UPDATE_VG_EPSET; + SCtgUpdateEpsetMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateEpsetMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateEpsetMsg)); @@ -758,9 +761,9 @@ int32_t ctgUpdateVgEpsetEnqueue(SCatalog* pCtg, char *dbFName, int32_t vgId, SEp msg->vgId = vgId; msg->epSet = *pEpSet; - operation.data = msg; + op->data = msg; - CTG_ERR_JRET(ctgEnqueue(pCtg, &operation)); + CTG_ERR_JRET(ctgEnqueue(pCtg, op)); return TSDB_CODE_SUCCESS; @@ -775,7 +778,10 @@ _return: int32_t ctgUpdateUserEnqueue(SCatalog* pCtg, SGetUserAuthRsp *pAuth, bool syncOp) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_UPDATE_USER, .syncOp = syncOp}; + SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation)); + op->opId = CTG_OP_UPDATE_USER; + op->syncOp = syncOp; + SCtgUpdateUserMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateUserMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateUserMsg)); @@ -785,9 +791,9 @@ int32_t ctgUpdateUserEnqueue(SCatalog* pCtg, SGetUserAuthRsp *pAuth, bool syncOp msg->pCtg = pCtg; msg->userAuth = *pAuth; - action.data = msg; + op->data = msg; - CTG_ERR_JRET(ctgEnqueue(pCtg, &action)); + CTG_ERR_JRET(ctgEnqueue(pCtg, op)); return TSDB_CODE_SUCCESS; @@ -1607,6 +1613,39 @@ void ctgUpdateThreadUnexpectedStopped(void) { if (CTG_IS_LOCKED(&gCtgMgmt.lock) > 0) CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock); } +void ctgCleanupCacheQueue(void) { + SCtgQNode *node = NULL; + SCtgQNode *nodeNext = NULL; + + while (true) { + node = gCtgMgmt.queue.head->next; + while (node) { + if (node->op) { + taosMemoryFree(node->op->data); + if (node->op->syncOp) { + tsem_post(&node->op->rspSem); + } else { + taosMemoryFree(node->op); + } + } + + nodeNext = node->next; + taosMemoryFree(node); + + node = nodeNext; + } + + if (CTG_IS_LOCKED(&gCtgMgmt.lock)) { + taosUsleep(1); + } else { + break; + } + } + + taosMemoryFreeClear(gCtgMgmt.queue.head); + gCtgMgmt.queue.tail = NULL; +} + void* ctgUpdateThreadFunc(void* param) { setThreadName("catalog"); #ifdef WINDOWS @@ -1622,7 +1661,8 @@ void* ctgUpdateThreadFunc(void* param) { } if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { - tsem_post(&gCtgMgmt.queue.rspSem); + CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock); + ctgCleanupCacheQueue(); break; } @@ -1634,10 +1674,8 @@ void* ctgUpdateThreadFunc(void* param) { (*gCtgCacheOperation[operation->opId].func)(operation); - gCtgMgmt.queue.seqDone = operation->seqId; - if (operation->syncOp) { - tsem_post(&gCtgMgmt.queue.rspSem); + tsem_post(&operation->rspSem); } CTG_RT_STAT_INC(qDoneNum, 1); diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index b16a082f75..94c59ddc53 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -85,6 +85,21 @@ int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize, qDebug("Got index from mnode, indexName:%s", target); break; } + case TDMT_MND_GET_TABLE_INDEX: { + if (TSDB_CODE_SUCCESS != rspCode) { + qError("error rsp for get table index, error:%s, tbFName:%s", tstrerror(rspCode), target); + CTG_ERR_RET(rspCode); + } + + code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize); + if (code) { + qError("Process get table index rsp failed, error:%s, tbFName:%s", tstrerror(code), target); + CTG_ERR_RET(code); + } + + qDebug("Got table index from mnode, tbFName:%s", target); + break; + } case TDMT_MND_RETRIEVE_FUNC: { if (TSDB_CODE_SUCCESS != rspCode) { qError("error rsp for get udf, error:%s, funcName:%s", tstrerror(rspCode), target); @@ -177,7 +192,7 @@ int32_t ctgHandleMsgCallback(void *param, const SDataBuf *pMsg, int32_t rspCode) SCtgTask *pTask = taosArrayGet(pJob->pTasks, cbParam->taskId); - qDebug("QID:%" PRIx64 " task %d start to handle rsp %s", pJob->queryId, pTask->taskId, TMSG_INFO(cbParam->reqType + 1)); + qDebug("QID:0x%" PRIx64 " task %d start to handle rsp %s", pJob->queryId, pTask->taskId, TMSG_INFO(cbParam->reqType + 1)); CTG_ERR_JRET((*gCtgAsyncFps[pTask->type].handleRspFp)(pTask, cbParam->reqType, pMsg, rspCode)); @@ -244,7 +259,7 @@ int32_t ctgAsyncSendMsg(CTG_PARAMS, SCtgTask* pTask, int32_t msgType, void *msg, CTG_ERR_JRET(code); } - ctgDebug("req msg sent, reqId:%" PRIx64 ", msg type:%d, %s", pTask->pJob->queryId, msgType, TMSG_INFO(msgType)); + ctgDebug("req msg sent, reqId:0x%" PRIx64 ", msg type:%d, %s", pTask->pJob->queryId, msgType, TMSG_INFO(msgType)); return TSDB_CODE_SUCCESS; _return: @@ -412,6 +427,44 @@ int32_t ctgGetIndexInfoFromMnode(CTG_PARAMS, const char *indexName, SIndexInfo * return TSDB_CODE_SUCCESS; } +int32_t ctgGetTbIndexFromMnode(CTG_PARAMS, const char *tbFName, SArray** out, SCtgTask* pTask) { + char *msg = NULL; + int32_t msgLen = 0; + int32_t reqType = TDMT_MND_GET_TABLE_INDEX; + void*(*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + + ctgDebug("try to get tb index from mnode, tbFName:%s", tbFName); + + int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)tbFName, &msg, 0, &msgLen, mallocFp); + if (code) { + ctgError("Build get index msg failed, code:%s, tbFName:%s", tstrerror(code), tbFName); + CTG_ERR_RET(code); + } + + if (pTask) { + void* pOut = taosMemoryCalloc(1, POINTER_BYTES); + if (NULL == pOut) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)tbFName)); + + CTG_RET(ctgAsyncSendMsg(CTG_PARAMS_LIST(), pTask, reqType, msg, msgLen)); + } + + SRpcMsg rpcMsg = { + .msgType = reqType, + .pCont = msg, + .contLen = msgLen, + }; + + SRpcMsg rpcRsp = {0}; + rpcSendRecv(pTrans, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp); + + CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)tbFName)); + + return TSDB_CODE_SUCCESS; +} + int32_t ctgGetUdfInfoFromMnode(CTG_PARAMS, const char *funcName, SFuncInfo *out, SCtgTask* pTask) { char *msg = NULL; int32_t msgLen = 0; @@ -565,7 +618,7 @@ int32_t ctgGetTbMetaFromVnode(CTG_PARAMS, const SName* pTableName, SVgroupInfo * } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, tbFName)); - CTG_RET(ctgAsyncSendMsg(CTG_PARAMS_LIST(), pTask, reqType, msg, msgLen)); + CTG_RET(ctgAsyncSendMsg(pCtg, pTrans, &vgroupInfo->epSet, pTask, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 4625203dd8..b5160fe8de 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -19,14 +19,41 @@ #include "catalogInt.h" #include "systable.h" +char *ctgTaskTypeStr(CTG_TASK_TYPE type) { + switch (type) { + case CTG_TASK_GET_QNODE: + return "[get qnode list]"; + case CTG_TASK_GET_DB_VGROUP: + return "[get db vgroup]"; + case CTG_TASK_GET_DB_CFG: + return "[get db cfg]"; + case CTG_TASK_GET_DB_INFO: + return "[get db info]"; + case CTG_TASK_GET_TB_META: + return "[get table meta]"; + case CTG_TASK_GET_TB_HASH: + return "[get table hash]"; + case CTG_TASK_GET_INDEX: + return "[get index]"; + case CTG_TASK_GET_UDF: + return "[get udf]"; + case CTG_TASK_GET_USER: + return "[get user]"; + default: + return "unknown"; + } +} + 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); } +*/ taosArrayDestroy(pData->pDbVgroup); pData->pDbVgroup = NULL; @@ -36,10 +63,12 @@ void ctgFreeSMetaData(SMetaData* pData) { 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); } +*/ taosArrayDestroy(pData->pDbCfg); pData->pDbCfg = NULL; @@ -295,8 +324,12 @@ void ctgFreeTask(SCtgTask* pTask) { break; } case CTG_TASK_GET_DB_CFG: { - taosMemoryFreeClear(pTask->taskCtx); - taosMemoryFreeClear(pTask->res); + taosMemoryFreeClear(pTask->taskCtx); + if (pTask->res) { + SDbCfgInfo* pInfo = (SDbCfgInfo*)pTask->res; + taosArrayDestroy(pInfo->pRetensions); + taosMemoryFreeClear(pTask->res); + } break; } case CTG_TASK_GET_DB_INFO: { @@ -477,6 +510,9 @@ int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName *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); + CTG_RET(code); } diff --git a/source/libs/command/inc/commandInt.h b/source/libs/command/inc/commandInt.h index 100e35bc3c..c8412afdc7 100644 --- a/source/libs/command/inc/commandInt.h +++ b/source/libs/command/inc/commandInt.h @@ -47,6 +47,9 @@ extern "C" { #define EXPLAIN_TIME_WINDOWS_FORMAT "Time Window: interval=%" PRId64 "%c offset=%" PRId64 "%c sliding=%" PRId64 "%c" #define EXPLAIN_WINDOW_FORMAT "Window: gap=%" PRId64 #define EXPLAIN_RATIO_TIME_FORMAT "Ratio: %f" +#define EXPLAIN_MERGE_FORMAT "Merge" +#define EXPLAIN_MERGE_KEYS_FORMAT "Merge Key: " + #define EXPLAIN_PLANNING_TIME_FORMAT "Planning Time: %.3f ms" #define EXPLAIN_EXEC_TIME_FORMAT "Execution Time: %.3f ms" @@ -112,9 +115,9 @@ typedef struct SExplainCtx { #define EXPLAIN_ROW_NEW(level, ...) \ do { \ if (isVerboseLine) { \ - tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s", (level) * 2 + 3, ""); \ + tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s", (level) * 3 + 3, ""); \ } else { \ - tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s%s", (level) * 2, "", "-> "); \ + tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s%s", (level) * 3, "", "-> "); \ } \ tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE - tlen, __VA_ARGS__); \ } while (0) diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 3034b4b02a..f330b7ce16 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -28,91 +28,94 @@ static int32_t getSchemaBytes(const SSchema* pSchema) { } } -// todo : to convert data according to SSDatablock -static void buildRspData(const STableMeta* pMeta, char* pData) { - int32_t* payloadLen = (int32_t*) pData; - uint64_t* groupId = (uint64_t*)(pData + sizeof(int32_t)); +static SSDataBlock* buildDescResultDataBlock() { + SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); + pBlock->info.numOfCols = DESCRIBE_RESULT_COLS; + pBlock->info.hasVarCol = true; - int32_t* pColSizes = (int32_t*)(pData + sizeof(int32_t) + sizeof(uint64_t)); - pData = (char*) pColSizes + DESCRIBE_RESULT_COLS * sizeof(int32_t); + pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); - int32_t numOfRows = TABLE_TOTAL_COL_NUM(pMeta); + SColumnInfoData infoData = {0}; + infoData.info.type = TSDB_DATA_TYPE_VARCHAR; + infoData.info.bytes = DESCRIBE_RESULT_FIELD_LEN; - // Field - int32_t* pOffset = (int32_t*)pData; - pData += numOfRows * sizeof(int32_t); + taosArrayPush(pBlock->pDataBlock, &infoData); + + infoData.info.type = TSDB_DATA_TYPE_VARCHAR; + infoData.info.bytes = DESCRIBE_RESULT_TYPE_LEN; + taosArrayPush(pBlock->pDataBlock, &infoData); + + infoData.info.type = TSDB_DATA_TYPE_INT; + infoData.info.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes;; + taosArrayPush(pBlock->pDataBlock, &infoData); + + infoData.info.type = TSDB_DATA_TYPE_VARCHAR; + infoData.info.bytes = DESCRIBE_RESULT_NOTE_LEN; + taosArrayPush(pBlock->pDataBlock, &infoData); + + return pBlock; +} + +static void setDescResultIntoDataBlock(SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta) { + blockDataEnsureCapacity(pBlock, numOfRows); + pBlock->info.rows = numOfRows; + + // field + SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0); + char buf[DESCRIBE_RESULT_FIELD_LEN] = {0}; for (int32_t i = 0; i < numOfRows; ++i) { - STR_TO_VARSTR(pData, pMeta->schema[i].name); - int16_t len = varDataTLen(pData); - pData += len; - *pOffset = pColSizes[0]; - pOffset += 1; - pColSizes[0] += len; + STR_TO_VARSTR(buf, pMeta->schema[i].name); + colDataAppend(pCol1, i, buf, false); } - + // Type - pOffset = (int32_t*)pData; - pData += numOfRows * sizeof(int32_t); + SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1); for (int32_t i = 0; i < numOfRows; ++i) { - STR_TO_VARSTR(pData, tDataTypes[pMeta->schema[i].type].name); - int16_t len = varDataTLen(pData); - pData += len; - *pOffset = pColSizes[1]; - pOffset += 1; - pColSizes[1] += len; + STR_TO_VARSTR(buf, tDataTypes[pMeta->schema[i].type].name); + colDataAppend(pCol2, i, buf, false); } // Length - pData += BitmapLen(numOfRows); + SColumnInfoData* pCol3 = taosArrayGet(pBlock->pDataBlock, 2); for (int32_t i = 0; i < numOfRows; ++i) { - *(int32_t*)pData = getSchemaBytes(pMeta->schema + i); - pData += sizeof(int32_t); + int32_t bytes = getSchemaBytes(pMeta->schema + i); + colDataAppend(pCol3, i, (const char*)&bytes, false); } - pColSizes[2] = sizeof(int32_t) * numOfRows; // Note - pOffset = (int32_t*)pData; - pData += numOfRows * sizeof(int32_t); + SColumnInfoData* pCol4 = taosArrayGet(pBlock->pDataBlock, 3); for (int32_t i = 0; i < numOfRows; ++i) { - STR_TO_VARSTR(pData, i >= pMeta->tableInfo.numOfColumns ? "TAG" : ""); - int16_t len = varDataTLen(pData); - pData += len; - *pOffset = pColSizes[3]; - pOffset += 1; - pColSizes[3] += len; + STR_TO_VARSTR(buf, i >= pMeta->tableInfo.numOfColumns ? "TAG" : ""); + colDataAppend(pCol4, i, buf, false); } - - for (int32_t i = 0; i < DESCRIBE_RESULT_COLS; ++i) { - pColSizes[i] = htonl(pColSizes[i]); - } - - - *payloadLen = (int32_t)(pData - (char*)payloadLen); -} - -static int32_t calcRspSize(const STableMeta* pMeta) { - int32_t numOfRows = TABLE_TOTAL_COL_NUM(pMeta); - return sizeof(SRetrieveTableRsp) + - (numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_FIELD_LEN) + - (numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_TYPE_LEN) + - (BitmapLen(numOfRows) + numOfRows * sizeof(int32_t)) + - (numOfRows * sizeof(int32_t) + numOfRows * DESCRIBE_RESULT_NOTE_LEN) + - sizeof(int32_t) + sizeof(uint64_t); } static int32_t execDescribe(SNode* pStmt, SRetrieveTableRsp** pRsp) { - SDescribeStmt* pDesc = (SDescribeStmt*)pStmt; - *pRsp = taosMemoryCalloc(1, calcRspSize(pDesc->pMeta)); + SDescribeStmt* pDesc = (SDescribeStmt*) pStmt; + int32_t numOfRows = TABLE_TOTAL_COL_NUM(pDesc->pMeta); + + SSDataBlock* pBlock = buildDescResultDataBlock(); + setDescResultIntoDataBlock(pBlock, numOfRows, pDesc->pMeta); + + size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock); + *pRsp = taosMemoryCalloc(1, rspSize); if (NULL == *pRsp) { return TSDB_CODE_OUT_OF_MEMORY; } + (*pRsp)->useconds = 0; (*pRsp)->completed = 1; (*pRsp)->precision = 0; (*pRsp)->compressed = 0; (*pRsp)->compLen = 0; - (*pRsp)->numOfRows = htonl(TABLE_TOTAL_COL_NUM(pDesc->pMeta)); - buildRspData(pDesc->pMeta, (*pRsp)->data); + (*pRsp)->numOfRows = htonl(numOfRows); + (*pRsp)->numOfCols = htonl(DESCRIBE_RESULT_COLS); + + int32_t len = 0; + blockCompressEncode(pBlock, (*pRsp)->data, &len, DESCRIBE_RESULT_COLS, false); + ASSERT(len == rspSize - sizeof(SRetrieveTableRsp)); + + blockDataDestroy(pBlock); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 98ae5e2fb1..dc9215b527 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include "tdatablock.h" #include "commandInt.h" #include "plannodes.h" #include "query.h" @@ -133,12 +134,12 @@ int32_t qExplainGenerateResChildren(SPhysiNode *pNode, SExplainGroup *group, SNo pPhysiChildren = pPrjNode->node.pChildren; break; } - case QUERY_NODE_PHYSICAL_PLAN_JOIN: { + case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: { SJoinPhysiNode *pJoinNode = (SJoinPhysiNode *)pNode; pPhysiChildren = pJoinNode->node.pChildren; break; } - case QUERY_NODE_PHYSICAL_PLAN_AGG: { + case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: { SAggPhysiNode *pAggNode = (SAggPhysiNode *)pNode; pPhysiChildren = pAggNode->node.pChildren; break; @@ -158,12 +159,12 @@ int32_t qExplainGenerateResChildren(SPhysiNode *pNode, SExplainGroup *group, SNo pPhysiChildren = pIntNode->window.node.pChildren; break; } - case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW: { + case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION: { SSessionWinodwPhysiNode *pSessNode = (SSessionWinodwPhysiNode *)pNode; pPhysiChildren = pSessNode->window.node.pChildren; break; } - case QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW: { + case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE: { SStateWinodwPhysiNode *pStateNode = (SStateWinodwPhysiNode *)pNode; pPhysiChildren = pStateNode->window.node.pChildren; break; @@ -173,6 +174,11 @@ int32_t qExplainGenerateResChildren(SPhysiNode *pNode, SExplainGroup *group, SNo pPhysiChildren = partitionPhysiNode->node.pChildren; break; } + case QUERY_NODE_PHYSICAL_PLAN_MERGE: { + SMergePhysiNode *mergePhysiNode = (SMergePhysiNode *)pNode; + pPhysiChildren = mergePhysiNode->node.pChildren; + break; + } default: qError("not supported physical node type %d", pNode->type); QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR); @@ -513,7 +519,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i } break; } - case QUERY_NODE_PHYSICAL_PLAN_JOIN: { + case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: { SJoinPhysiNode *pJoinNode = (SJoinPhysiNode *)pNode; EXPLAIN_ROW_NEW(level, EXPLAIN_JOIN_FORMAT, EXPLAIN_JOIN_STRING(pJoinNode->joinType)); EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT); @@ -553,7 +559,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i } break; } - case QUERY_NODE_PHYSICAL_PLAN_AGG: { + case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: { SAggPhysiNode *pAggNode = (SAggPhysiNode *)pNode; EXPLAIN_ROW_NEW(level, EXPLAIN_AGG_FORMAT); EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT); @@ -652,7 +658,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i if (EXPLAIN_MODE_ANALYZE == ctx->mode) { // sort key - EXPLAIN_ROW_NEW(level, "Sort Key: "); + EXPLAIN_ROW_NEW(level + 1, "Sort Key: "); if (pResNode->pExecInfo) { for (int32_t i = 0; i < LIST_LENGTH(pSortNode->pSortKeys); ++i) { SOrderByExprNode *ptn = nodesListGetNode(pSortNode->pSortKeys, i); @@ -664,7 +670,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); // sort method - EXPLAIN_ROW_NEW(level, "Sort Method: "); + EXPLAIN_ROW_NEW(level + 1, "Sort Method: "); int32_t nodeNum = taosArrayGetSize(pResNode->pExecInfo); SExplainExecInfo *execInfo = taosArrayGet(pResNode->pExecInfo, 0); @@ -744,7 +750,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i } break; } - case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW: { + case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION: { SSessionWinodwPhysiNode *pSessNode = (SSessionWinodwPhysiNode *)pNode; EXPLAIN_ROW_NEW(level, EXPLAIN_SESSION_FORMAT); EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT); @@ -782,7 +788,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i } break; } - case QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW: { + case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE: { SStateWinodwPhysiNode *pStateNode = (SStateWinodwPhysiNode *)pNode; EXPLAIN_ROW_NEW(level, EXPLAIN_STATE_WINDOW_FORMAT, @@ -857,6 +863,50 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i } break; } + case QUERY_NODE_PHYSICAL_PLAN_MERGE: { + SMergePhysiNode *pMergeNode = (SMergePhysiNode *)pNode; + EXPLAIN_ROW_NEW(level, EXPLAIN_MERGE_FORMAT); + EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT); + if (pResNode->pExecInfo) { + QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); + EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + } + + SDataBlockDescNode *pDescNode = pMergeNode->node.pOutputDataBlockDesc; + EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, nodesGetOutputNumFromSlotList(pDescNode->pSlots)); + EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pDescNode->totalRowSize); + EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + if (verbose) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_OUTPUT_FORMAT); + EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, + nodesGetOutputNumFromSlotList(pMergeNode->node.pOutputDataBlockDesc->pSlots)); + EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pMergeNode->node.pOutputDataBlockDesc->outputRowSize); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_MERGE_KEYS_FORMAT); + for (int32_t i = 0; i < LIST_LENGTH(pMergeNode->pMergeKeys); ++i) { + SOrderByExprNode *ptn = nodesListGetNode(pMergeNode->pMergeKeys, i); + EXPLAIN_ROW_APPEND("%s ", nodesGetNameFromColumnNode(ptn->pExpr)); + } + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + + if (pMergeNode->node.pConditions) { + EXPLAIN_ROW_NEW(level + 1, EXPLAIN_FILTER_FORMAT); + QRY_ERR_RET(nodesNodeToSQL(pMergeNode->node.pConditions, tbuf + VARSTR_HEADER_SIZE, + TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen)); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1)); + } + } + break; + } default: qError("not supported physical node type %d", pNode->type); return TSDB_CODE_QRY_APP_ERROR; @@ -916,9 +966,32 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - int32_t colNum = 1; - int32_t rspSize = sizeof(SRetrieveTableRsp) + sizeof(int32_t) + sizeof(uint64_t) + sizeof(int32_t) * colNum + - sizeof(int32_t) * rowNum + pCtx->dataSize; + SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); + SColumnInfoData infoData = {0}; + infoData.info.type = TSDB_DATA_TYPE_VARCHAR; + infoData.info.bytes = TSDB_EXPLAIN_RESULT_ROW_SIZE; + + pBlock->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); + taosArrayPush(pBlock->pDataBlock, &infoData); + + SColumnInfoData* pInfoData = taosArrayGet(pBlock->pDataBlock, 0); + pInfoData->hasNull = false; + colInfoDataEnsureCapacity(pInfoData, 0, rowNum); + + char buf[1024] = {0}; + for (int32_t i = 0; i < rowNum; ++i) { + SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i); + varDataCopy(buf, row->buf); + ASSERT(varDataTLen(row->buf) == row->len); + colDataAppend(pInfoData, i, buf, false); + } + + pBlock->info.numOfCols = 1; + pBlock->info.rows = rowNum; + pBlock->info.hasVarCol = true; + + int32_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock); + SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize); if (NULL == rsp) { qError("malloc SRetrieveTableRsp failed, size:%d", rspSize); @@ -928,34 +1001,13 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { rsp->completed = 1; rsp->numOfRows = htonl(rowNum); - // payload length - *(int32_t *)rsp->data = - sizeof(int32_t) + sizeof(uint64_t) + sizeof(int32_t) * colNum + sizeof(int32_t) * rowNum + pCtx->dataSize; + int32_t len = 0; + blockCompressEncode(pBlock, rsp->data, &len, pBlock->info.numOfCols, 0); + ASSERT(len == rspSize - sizeof(SRetrieveTableRsp)); - // group id - *(uint64_t *)(rsp->data + sizeof(int32_t)) = 0; + rsp->compLen = htonl(len); - // column length - int32_t *colLength = (int32_t *)(rsp->data + sizeof(int32_t) + sizeof(uint64_t)); - - // varchar column offset segment - int32_t *offset = (int32_t *)((char *)colLength + sizeof(int32_t)); - - // varchar data real payload - char *data = (char *)(offset + rowNum); - - char *start = data; - for (int32_t i = 0; i < rowNum; ++i) { - SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i); - offset[i] = data - start; - - varDataCopy(data, row->buf); - ASSERT(varDataTLen(row->buf) == row->len); - data += row->len; - } - - *colLength = htonl(data - start); - rsp->compLen = htonl(rspSize); + blockDataDestroy(pBlock); *pRsp = rsp; return TSDB_CODE_SUCCESS; diff --git a/source/libs/executor/inc/dataSinkInt.h b/source/libs/executor/inc/dataSinkInt.h index 8f49440105..dead1aff73 100644 --- a/source/libs/executor/inc/dataSinkInt.h +++ b/source/libs/executor/inc/dataSinkInt.h @@ -49,6 +49,7 @@ typedef struct SDataSinkHandle { } SDataSinkHandle; int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle); +int32_t createDataDeleter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void *pParam); #ifdef __cplusplus } diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 7d597217ee..68d71a0c24 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -353,6 +353,7 @@ typedef struct STagScanInfo { int32_t curPos; SReadHandle readHandle; STableListInfo *pTableList; + SNode* pFilterNode; // filter info, } STagScanInfo; typedef enum EStreamScanMode { @@ -488,6 +489,8 @@ typedef struct SStreamFinalIntervalOperatorInfo { int32_t order; // current SSDataBlock scan order STimeWindowAggSupp twAggSup; SArray* pChildren; + SSDataBlock* pUpdateRes; + SPhysiNode* pPhyNode; // create new child } SStreamFinalIntervalOperatorInfo; typedef struct SAggOperatorInfo { @@ -524,6 +527,17 @@ typedef struct SProjectOperatorInfo { int64_t curOutput; } SProjectOperatorInfo; +typedef struct SIndefOperatorInfo { + SOptrBasicInfo binfo; + SAggSupporter aggSup; + SArray* pPseudoColInfo; + + SExprInfo* pScalarExpr; + int32_t numOfScalarExpr; + SqlFunctionCtx* pScalarCtx; + int32_t* rowCellInfoOffset; +} SIndefOperatorInfo; + typedef struct SFillOperatorInfo { struct SFillInfo* pFillInfo; SSDataBlock* pRes; @@ -674,6 +688,10 @@ typedef struct SSortedMergeOperatorInfo { int32_t numOfResPerPage; char** groupVal; SArray *groupInfo; + + bool hasGroupId; + uint64_t groupId; + STupleHandle* prefetchedTuple; } SSortedMergeOperatorInfo; typedef struct SSortOperatorInfo { @@ -686,6 +704,10 @@ typedef struct SSortOperatorInfo { int64_t startTs; // sort start time uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included. + + STupleHandle *prefetchedTuple; + bool hasGroupId; + uint64_t groupId; } SSortOperatorInfo; typedef struct STagFilterOperatorInfo { @@ -734,7 +756,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); +void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, bool needFree); SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset); void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols); void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow); @@ -745,7 +767,7 @@ void setTbNameColData(void* pMeta, const SSDataBlock* pBlock, SColumnInfoData SInterval extractIntervalInfo(const STableScanPhysiNode* pTableScanNode); SColumn extractColumnFromColumnNode(SColumnNode* pColNode); -SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, SArray* pColMatchInfo); +SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, SArray* pColMatchInfo, SSortOperatorInfo* pInfo); SSDataBlock* loadNextDataBlock(void* param); void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowCellInfoOffset); @@ -764,24 +786,27 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode* pExNode, SExecTaskInfo* pTaskInfo); SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, tsdbReaderT pDataReader, SReadHandle* pHandle, SArray* groupKyes, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pPhyNode, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pPhyNode, + STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode *pScanPhyNode, SExecTaskInfo* pTaskInfo); SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhysiNode *pNode, SExecTaskInfo* pTaskInfo); SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, SSDataBlock* pResBlock, SLimit* pLimit, SLimit* pSlimit, SNode* pCondition, SExecTaskInfo* pTaskInfo); SOperatorInfo *createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExprInfo* pExprInfo, int32_t numOfCols, SArray* pIndexMap, SExecTaskInfo* pTaskInfo); - +SOperatorInfo* createMultiwaySortMergeOperatorInfo(SOperatorInfo** downStreams, int32_t numStreams, SSDataBlock* pInputBlock, + SSDataBlock* pResBlock, SArray* pSortInfo, SArray* pColMatchColInfo, + SExecTaskInfo* pTaskInfo); SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pSortInfo, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId, STimeWindowAggSupp *pTwAggSupp, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId, - STimeWindowAggSupp *pTwAggSupp, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, + SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, int32_t numOfChild); SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId, STimeWindowAggSupp *pTwAggSupp, SExecTaskInfo* pTaskInfo); @@ -855,6 +880,7 @@ int32_t decodeOperator(SOperatorInfo* ops, char* data, int32_t length); void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status); int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId, EOPTR_EXEC_MODEL model); +int32_t createDataSinkParam(SDataSinkNode *pNode, void **pParam, qTaskInfo_t* pTaskInfo); int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SExplainExecInfo** pRes, int32_t* capacity, int32_t* resNum); diff --git a/source/libs/executor/inc/tsort.h b/source/libs/executor/inc/tsort.h index c8b1b3ee51..fd3581e2bf 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -130,6 +130,12 @@ bool tsortIsNullVal(STupleHandle* pVHandle, int32_t colId); */ void* tsortGetValue(STupleHandle* pVHandle, int32_t colId); +/** + * + * @param pVHandle + * @return + */ +uint64_t tsortGetGroupId(STupleHandle* pVHandle); /** * * @param pSortHandle diff --git a/source/libs/executor/src/dataDeleter.c b/source/libs/executor/src/dataDeleter.c new file mode 100644 index 0000000000..33b7811e6c --- /dev/null +++ b/source/libs/executor/src/dataDeleter.c @@ -0,0 +1,254 @@ +/* + * 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 "dataSinkInt.h" +#include "dataSinkMgt.h" +#include "executorimpl.h" +#include "planner.h" +#include "tcompression.h" +#include "tdatablock.h" +#include "tglobal.h" +#include "tqueue.h" + +extern SDataSinkStat gDataSinkStat; + +typedef struct SDataDeleterBuf { + int32_t useSize; + int32_t allocSize; + char* pData; +} SDataDeleterBuf; + +typedef struct SDataCacheEntry { + int32_t dataLen; + int32_t numOfRows; + int32_t numOfCols; + int8_t compressed; + char data[]; +} SDataCacheEntry; + +typedef struct SDataDeleterHandle { + SDataSinkHandle sink; + SDataSinkManager* pManager; + SDataBlockDescNode* pSchema; + SDataDeleterNode* pDeleter; + SDeleterParam* pParam; + STaosQueue* pDataBlocks; + SDataDeleterBuf nextOutput; + int32_t status; + bool queryEnd; + uint64_t useconds; + uint64_t cachedSize; + TdThreadMutex mutex; +} SDataDeleterHandle; + +static bool needCompress(const SSDataBlock* pData, int32_t numOfCols) { + if (tsCompressColData < 0 || 0 == pData->info.rows) { + return false; + } + + for (int32_t col = 0; col < numOfCols; ++col) { + SColumnInfoData* pColRes = taosArrayGet(pData->pDataBlock, col); + int32_t colSize = pColRes->info.bytes * pData->info.rows; + if (NEEDTO_COMPRESS_QUERY(colSize)) { + return true; + } + } + + return false; +} + +static void toDataCacheEntry(SDataDeleterHandle* pHandle, const SInputData* pInput, SDataDeleterBuf* pBuf) { + int32_t numOfCols = LIST_LENGTH(pHandle->pSchema->pSlots); + + SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData; + pEntry->compressed = 0; + pEntry->numOfRows = pInput->pData->info.rows; + pEntry->numOfCols = pInput->pData->info.numOfCols; + pEntry->dataLen = sizeof(SDeleterRes); + + ASSERT(1 == pEntry->numOfRows); + ASSERT(1 == pEntry->numOfCols); + + pBuf->useSize = sizeof(SDataCacheEntry); + + SColumnInfoData* pColRes = (SColumnInfoData*)taosArrayGet(pInput->pData->pDataBlock, 0); + + SDeleterRes* pRes = (SDeleterRes*)pEntry->data; + pRes->uid = pHandle->pDeleter->tableId; + pRes->uidList = pHandle->pParam->pUidList; + pRes->skey = pHandle->pDeleter->deleteTimeRange.skey; + pRes->ekey = pHandle->pDeleter->deleteTimeRange.ekey; + pRes->affectedRows = *(int64_t*)pColRes->pData; + + pBuf->useSize += pEntry->dataLen; + + atomic_add_fetch_64(&pHandle->cachedSize, pEntry->dataLen); + atomic_add_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen); +} + +static bool allocBuf(SDataDeleterHandle* pDeleter, const SInputData* pInput, SDataDeleterBuf* pBuf) { + uint32_t capacity = pDeleter->pManager->cfg.maxDataBlockNumPerQuery; + if (taosQueueItemSize(pDeleter->pDataBlocks) > capacity) { + qError("SinkNode queue is full, no capacity, max:%d, current:%d, no capacity", capacity, + taosQueueItemSize(pDeleter->pDataBlocks)); + return false; + } + + pBuf->allocSize = sizeof(SDataCacheEntry) + sizeof(SDeleterRes); + + pBuf->pData = taosMemoryMalloc(pBuf->allocSize); + if (pBuf->pData == NULL) { + qError("SinkNode failed to malloc memory, size:%d, code:%d", pBuf->allocSize, TAOS_SYSTEM_ERROR(errno)); + } + + return NULL != pBuf->pData; +} + +static int32_t updateStatus(SDataDeleterHandle* pDeleter) { + taosThreadMutexLock(&pDeleter->mutex); + int32_t blockNums = taosQueueItemSize(pDeleter->pDataBlocks); + int32_t status = + (0 == blockNums ? DS_BUF_EMPTY + : (blockNums < pDeleter->pManager->cfg.maxDataBlockNumPerQuery ? DS_BUF_LOW : DS_BUF_FULL)); + pDeleter->status = status; + taosThreadMutexUnlock(&pDeleter->mutex); + return status; +} + +static int32_t getStatus(SDataDeleterHandle* pDeleter) { + taosThreadMutexLock(&pDeleter->mutex); + int32_t status = pDeleter->status; + taosThreadMutexUnlock(&pDeleter->mutex); + return status; +} + +static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) { + SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle; + SDataDeleterBuf* pBuf = taosAllocateQitem(sizeof(SDataDeleterBuf), DEF_QITEM); + if (NULL == pBuf || !allocBuf(pDeleter, pInput, pBuf)) { + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + toDataCacheEntry(pDeleter, pInput, pBuf); + taosWriteQitem(pDeleter->pDataBlocks, pBuf); + *pContinue = (DS_BUF_LOW == updateStatus(pDeleter) ? true : false); + return TSDB_CODE_SUCCESS; +} + +static void endPut(struct SDataSinkHandle* pHandle, uint64_t useconds) { + SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle; + taosThreadMutexLock(&pDeleter->mutex); + pDeleter->queryEnd = true; + pDeleter->useconds = useconds; + taosThreadMutexUnlock(&pDeleter->mutex); +} + +static void getDataLength(SDataSinkHandle* pHandle, int32_t* pLen, bool* pQueryEnd) { + SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle; + if (taosQueueEmpty(pDeleter->pDataBlocks)) { + *pQueryEnd = pDeleter->queryEnd; + *pLen = 0; + return; + } + + SDataDeleterBuf* pBuf = NULL; + taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf); + memcpy(&pDeleter->nextOutput, pBuf, sizeof(SDataDeleterBuf)); + taosFreeQitem(pBuf); + *pLen = ((SDataCacheEntry*)(pDeleter->nextOutput.pData))->dataLen; + *pQueryEnd = pDeleter->queryEnd; + qDebug("got data len %d, row num %d in sink", *pLen, ((SDataCacheEntry*)(pDeleter->nextOutput.pData))->numOfRows); +} + +static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) { + SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle; + if (NULL == pDeleter->nextOutput.pData) { + assert(pDeleter->queryEnd); + pOutput->useconds = pDeleter->useconds; + pOutput->precision = pDeleter->pSchema->precision; + pOutput->bufStatus = DS_BUF_EMPTY; + pOutput->queryEnd = pDeleter->queryEnd; + return TSDB_CODE_SUCCESS; + } + SDataCacheEntry* pEntry = (SDataCacheEntry*)(pDeleter->nextOutput.pData); + memcpy(pOutput->pData, pEntry->data, pEntry->dataLen); + pOutput->numOfRows = pEntry->numOfRows; + pOutput->numOfCols = pEntry->numOfCols; + pOutput->compressed = pEntry->compressed; + + atomic_sub_fetch_64(&pDeleter->cachedSize, pEntry->dataLen); + atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen); + + taosMemoryFreeClear(pDeleter->nextOutput.pData); // todo persistent + pOutput->bufStatus = updateStatus(pDeleter); + taosThreadMutexLock(&pDeleter->mutex); + pOutput->queryEnd = pDeleter->queryEnd; + pOutput->useconds = pDeleter->useconds; + pOutput->precision = pDeleter->pSchema->precision; + taosThreadMutexUnlock(&pDeleter->mutex); + + return TSDB_CODE_SUCCESS; +} + +static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { + SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle; + atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pDeleter->cachedSize); + taosMemoryFreeClear(pDeleter->nextOutput.pData); + while (!taosQueueEmpty(pDeleter->pDataBlocks)) { + SDataDeleterBuf* pBuf = NULL; + taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf); + taosMemoryFreeClear(pBuf->pData); + taosFreeQitem(pBuf); + } + taosCloseQueue(pDeleter->pDataBlocks); + taosThreadMutexDestroy(&pDeleter->mutex); + return TSDB_CODE_SUCCESS; +} + +static int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) { + SDataDeleterHandle* pDispatcher = (SDataDeleterHandle*)pHandle; + + *size = atomic_load_64(&pDispatcher->cachedSize); + return TSDB_CODE_SUCCESS; +} + +int32_t createDataDeleter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void *pParam) { + SDataDeleterHandle* deleter = taosMemoryCalloc(1, sizeof(SDataDeleterHandle)); + if (NULL == deleter) { + terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + + SDataDeleterNode* pDeleterNode = (SDataDeleterNode *)pDataSink; + deleter->sink.fPut = putDataBlock; + deleter->sink.fEndPut = endPut; + deleter->sink.fGetLen = getDataLength; + deleter->sink.fGetData = getDataBlock; + deleter->sink.fDestroy = destroyDataSinker; + deleter->sink.fGetCacheSize = getCacheSize; + deleter->pManager = pManager; + deleter->pDeleter = pDeleterNode; + deleter->pSchema = pDataSink->pInputDataBlockDesc; + deleter->pParam = pParam; + deleter->status = DS_BUF_EMPTY; + deleter->queryEnd = false; + deleter->pDataBlocks = taosOpenQueue(); + taosThreadMutexInit(&deleter->mutex, NULL); + if (NULL == deleter->pDataBlocks) { + terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + *pHandle = deleter; + return TSDB_CODE_SUCCESS; +} diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index 080cf5c2ad..b7c7102143 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -68,10 +68,10 @@ static bool needCompress(const SSDataBlock* pData, int32_t numOfCols) { } // data format: -// +----------------+--------------+----------+--------------------------------------+-------------+-----------+-------------+-----------+ -// |SDataCacheEntry | total length | group id | column#1 length, column#2 length ... | col1 bitmap | col1 data | col2 bitmap | col2 data | .... -// | | (4 bytes) |(8 bytes) | sizeof(int32_t) * numOfCols | actual size | | actual size | | -// +----------------+--------------+----------+--------------------------------------+-------------+-----------+-------------+-----------+ +// +----------------+--------------+----------+--------------------------------------------+--------------------------------------+-------------+-----------+-------------+-----------+ +// |SDataCacheEntry | total length | group id | col1_schema | col2_schema | col3_schema ...| column#1 length, column#2 length ... | col1 bitmap | col1 data | col2 bitmap | col2 data | .... +// | | (4 bytes) |(8 bytes) |(sizeof(int16_t)+sizeof(int32_t))*numOfCols | sizeof(int32_t) * numOfCols | actual size | | actual size | | +// +----------------+--------------+----------+--------------------------------------------+--------------------------------------+-------------+-----------+-------------+-----------+ // The length of bitmap is decided by number of rows of this data block, and the length of each column data is // recorded in the first segment, next to the struct header static void toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pInput, SDataDispatchBuf* pBuf) { @@ -83,7 +83,7 @@ static void toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pIn pEntry->numOfCols = pInput->pData->info.numOfCols; pEntry->dataLen = 0; - pBuf->useSize = sizeof(SRetrieveTableRsp); + pBuf->useSize = sizeof(SDataCacheEntry); blockCompressEncode(pInput->pData, pEntry->data, &pEntry->dataLen, numOfCols, pEntry->compressed); pBuf->useSize += pEntry->dataLen; @@ -100,7 +100,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, return false; } - pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pInput->pData); + pBuf->allocSize = sizeof(SDataCacheEntry) + blockGetEncodeSize(pInput->pData); pBuf->pData = taosMemoryMalloc(pBuf->allocSize); if (pBuf->pData == NULL) { @@ -211,7 +211,7 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { return TSDB_CODE_SUCCESS; } -int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) { +static int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) { SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle; *size = atomic_load_64(&pDispatcher->cachedSize); diff --git a/source/libs/executor/src/dataSinkMgt.c b/source/libs/executor/src/dataSinkMgt.c index 9016ca274a..ffa9822e92 100644 --- a/source/libs/executor/src/dataSinkMgt.c +++ b/source/libs/executor/src/dataSinkMgt.c @@ -34,9 +34,12 @@ int32_t dsDataSinkGetCacheSize(SDataSinkStat *pStat) { } -int32_t dsCreateDataSinker(const SDataSinkNode *pDataSink, DataSinkHandle* pHandle) { - if (QUERY_NODE_PHYSICAL_PLAN_DISPATCH == nodeType(pDataSink)) { - return createDataDispatcher(&gDataSinkManager, pDataSink, pHandle); +int32_t dsCreateDataSinker(const SDataSinkNode *pDataSink, DataSinkHandle* pHandle, void* pParam) { + switch (nodeType(pDataSink)) { + case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: + return createDataDispatcher(&gDataSinkManager, pDataSink, pHandle); + case QUERY_NODE_PHYSICAL_PLAN_DELETE: + return createDataDeleter(&gDataSinkManager, pDataSink, pHandle, pParam); } return TSDB_CODE_FAILED; } diff --git a/source/libs/executor/src/executorMain.c b/source/libs/executor/src/executorMain.c index 7757825733..c014b23953 100644 --- a/source/libs/executor/src/executorMain.c +++ b/source/libs/executor/src/executorMain.c @@ -45,8 +45,15 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, if (code != TSDB_CODE_SUCCESS) { goto _error; } + if (handle) { - code = dsCreateDataSinker(pSubplan->pDataSink, handle); + void* pSinkParam = NULL; + code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, pTaskInfo); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + + code = dsCreateDataSinker(pSubplan->pDataSink, handle, pSinkParam); } _error: diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 92b3195f36..b4579b90b2 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -108,8 +108,6 @@ static SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutpu static void releaseQueryBuf(size_t numOfTables); -static int32_t getNumOfScanTimes(STaskAttr* pQueryAttr); - static void destroySFillOperatorInfo(void* param, int32_t numOfOutput); static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput); static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput); @@ -1820,9 +1818,9 @@ void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numO } } -static void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const int8_t* rowRes, bool keep); +static void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const int8_t* rowRes, bool keep, bool needFree); -void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock) { +void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, bool needFree) { if (pFilterNode == NULL) { return; } @@ -1841,11 +1839,11 @@ void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock) { bool keep = filterExecute(filter, pBlock, &rowRes, NULL, param1.numOfCols); filterFreeInfo(filter); - extractQualifiedTupleByFilterResult(pBlock, rowRes, keep); + extractQualifiedTupleByFilterResult(pBlock, rowRes, keep, needFree); blockDataUpdateTsWindow(pBlock, 0); } -void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const int8_t* rowRes, bool keep) { +void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const int8_t* rowRes, bool keep, bool needFree) { if (keep) { return; } @@ -1885,8 +1883,20 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const int8_t* rowR ASSERT(pBlock->info.rows == numOfRows); } + SColumnInfoData tmp = *pSrc; *pSrc = *pDst; + *pDst = tmp; + + if (!needFree) { + if (IS_VAR_DATA_TYPE(pDst->info.type)) { // this elements do not need free + pDst->varmeta.offset = NULL; + } else { + pDst->nullbitmap = NULL; + } + pDst->pData = NULL; + } } + blockDataDestroy(px); // fix memory leak } else { // do nothing pBlock->info.rows = 0; @@ -2522,8 +2532,8 @@ void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray } int32_t setDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows, char* pData, - int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, - SArray* pColList) { + int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, + SArray* pColList) { if (pColList == NULL) { // data from other sources blockCompressDecode(pRes, numOfOutput, numOfRows, pData); } else { // extract data according to pColList @@ -2561,37 +2571,7 @@ int32_t setDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadIn } } - blockDataEnsureCapacity(pBlock, numOfRows); - - int32_t dataLen = *(int32_t*)pStart; - uint64_t groupId = *(uint64_t*)(pStart + sizeof(int32_t)); - pStart += sizeof(int32_t) + sizeof(uint64_t); - - int32_t* colLen = (int32_t*)(pStart); - pStart += sizeof(int32_t) * numOfCols; - - for (int32_t i = 0; i < numOfCols; ++i) { - colLen[i] = htonl(colLen[i]); - ASSERT(colLen[i] >= 0); - - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); - if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { - pColInfoData->varmeta.length = colLen[i]; - pColInfoData->varmeta.allocLen = colLen[i]; - - memcpy(pColInfoData->varmeta.offset, pStart, sizeof(int32_t) * numOfRows); - pStart += sizeof(int32_t) * numOfRows; - - pColInfoData->pData = taosMemoryMalloc(colLen[i]); - } else { - memcpy(pColInfoData->nullbitmap, pStart, BitmapLen(numOfRows)); - pStart += BitmapLen(numOfRows); - } - - memcpy(pColInfoData->pData, pStart, colLen[i]); - pStart += colLen[i]; - } - + blockCompressDecode(pBlock, numOfCols, numOfRows, pStart); // data from mnode relocateColumnData(pRes, pColList, pBlock->pDataBlock); taosArrayDestroy(pBlock->pDataBlock); @@ -2677,7 +2657,7 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SEx SRetrieveTableRsp* pTableRsp = pDataInfo->pRsp; code = setDataBlockFromFetchRsp(pExchangeInfo->pResult, pLoadInfo, pTableRsp->numOfRows, pTableRsp->data, - pTableRsp->compLen, pTableRsp->numOfCols, startTs, &pDataInfo->totalRows, NULL); + pTableRsp->compLen, pTableRsp->numOfCols, startTs, &pDataInfo->totalRows, NULL); if (code != 0) { taosMemoryFreeClear(pDataInfo->pRsp); goto _error; @@ -2790,7 +2770,7 @@ static SSDataBlock* seqLoadRemoteData(SOperatorInfo* pOperator) { SRetrieveTableRsp* pTableRsp = pDataInfo->pRsp; int32_t code = setDataBlockFromFetchRsp(pExchangeInfo->pResult, pLoadInfo, pTableRsp->numOfRows, pTableRsp->data, - pTableRsp->compLen, pTableRsp->numOfCols, startTs, &pDataInfo->totalRows, NULL); + pTableRsp->compLen, pTableRsp->numOfCols, startTs, &pDataInfo->totalRows, NULL); if (pRsp->completed == 1) { qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, rowsOfSource:%" PRIu64 @@ -2856,7 +2836,7 @@ static SSDataBlock* doLoadRemoteData(SOperatorInfo* pOperator) { return seqLoadRemoteData(pOperator); } else { return concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo); -// return concurrentlyLoadRemoteData(pOperator); + // return concurrentlyLoadRemoteData(pOperator); } } @@ -2911,18 +2891,18 @@ SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode goto _error; } - pInfo->seqLoadData = false; + pInfo->seqLoadData = false; pInfo->pTransporter = pTransporter; - pInfo->pResult = createResDataBlock(pExNode->node.pOutputDataBlockDesc); + pInfo->pResult = createResDataBlock(pExNode->node.pOutputDataBlockDesc); tsem_init(&pInfo->ready, 0, 0); - pOperator->name = "ExchangeOperator"; + pOperator->name = "ExchangeOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_EXCHANGE; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfExprs = pInfo->pResult->info.numOfCols; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfExprs = pInfo->pResult->info.numOfCols; + pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, NULL, destroyExchangeOperatorInfo, NULL, NULL, NULL); @@ -3123,6 +3103,68 @@ static SSDataBlock* doMerge(SOperatorInfo* pOperator) { return (pInfo->binfo.pRes->info.rows > 0) ? pInfo->binfo.pRes : NULL; } +SSDataBlock* getSortedMergeBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, SArray* pColMatchInfo, + SSortedMergeOperatorInfo *pInfo) { + blockDataCleanup(pDataBlock); + + SSDataBlock* p = tsortGetSortedDataBlock(pHandle); + if (p == NULL) { + return NULL; + } + + blockDataEnsureCapacity(p, capacity); + + while (1) { + STupleHandle* pTupleHandle = NULL; + if (pInfo->prefetchedTuple == NULL) { + pTupleHandle = tsortNextTuple(pHandle); + } else { + pTupleHandle = pInfo->prefetchedTuple; + pInfo->groupId = tsortGetGroupId(pTupleHandle); + pInfo->prefetchedTuple = NULL; + } + + if (pTupleHandle == NULL) { + break; + } + + uint64_t tupleGroupId = tsortGetGroupId(pTupleHandle); + if (!pInfo->hasGroupId) { + pInfo->groupId = tupleGroupId; + pInfo->hasGroupId = true; + appendOneRowToDataBlock(p, pTupleHandle); + } else if (pInfo->groupId == tupleGroupId) { + appendOneRowToDataBlock(p, pTupleHandle); + } else { + pInfo->prefetchedTuple = pTupleHandle; + break; + } + + if (p->info.rows >= capacity) { + break; + } + } + + if (p->info.rows > 0) { + int32_t numOfCols = taosArrayGetSize(pColMatchInfo); + for (int32_t i = 0; i < numOfCols; ++i) { + SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, i); + ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID); + + SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId); + SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->targetSlotId); + colDataAssign(pDst, pSrc, p->info.rows); + } + + pDataBlock->info.rows = p->info.rows; + pDataBlock->info.capacity = p->info.rows; + pDataBlock->info.groupId = pInfo->groupId; + } + + blockDataDestroy(p); + return (pDataBlock->info.rows > 0) ? pDataBlock : NULL; +} + static SSDataBlock* doSortedMerge(SOperatorInfo* pOperator) { if (pOperator->status == OP_EXEC_DONE) { return NULL; @@ -3131,7 +3173,7 @@ static SSDataBlock* doSortedMerge(SOperatorInfo* pOperator) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SSortedMergeOperatorInfo* pInfo = pOperator->info; if (pOperator->status == OP_RES_TO_RETURN) { - return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, NULL); + return getSortedMergeBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, NULL, pInfo); } int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; @@ -3636,25 +3678,13 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { break; } -#if 0 - // Return result of the previous group in the firstly. - if (false) { - if (pRes->info.rows > 0) { - pProjectInfo->existDataBlock = pBlock; - break; - } else { // init output buffer for a new group data - initCtxOutputBuffer(pInfo->pCtx, pOperator->numOfExprs); - } - } -#endif - // the pDataBlock are always the same one, no need to call this again int32_t code = getTableScanInfo(pOperator->pDownstream[0], &order, &scanFlag); if (code != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, code); } - doFilter(pProjectInfo->pFilterNode, pBlock); + doFilter(pProjectInfo->pFilterNode, pBlock, true); setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order, scanFlag, false); blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); @@ -3793,6 +3823,17 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) { } } +static void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) { + for (int32_t i = 0; i < numOfExprs; ++i) { + SExprInfo* pExprInfo = &pExpr[i]; + if (pExprInfo->pExpr->nodeType == QUERY_NODE_COLUMN) { + taosMemoryFree(pExprInfo->base.pParam[0].pCol); + } + taosMemoryFree(pExprInfo->base.pParam); + taosMemoryFree(pExprInfo->pExpr); + } +} + static void destroyOperatorInfo(SOperatorInfo* pOperator) { if (pOperator == NULL) { return; @@ -3812,14 +3853,7 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) { } if (pOperator->pExpr != NULL) { - for (int32_t i = 0; i < pOperator->numOfExprs; ++i) { - SExprInfo* pExprInfo = &pOperator->pExpr[i]; - if (pExprInfo->pExpr->nodeType == QUERY_NODE_COLUMN) { - taosMemoryFree(pExprInfo->base.pParam[0].pCol); - } - taosMemoryFree(pExprInfo->base.pParam); - taosMemoryFree(pExprInfo->pExpr); - } + destroyExprInfo(pOperator->pExpr, pOperator->numOfExprs); } taosMemoryFreeClear(pOperator->pExpr); @@ -3946,7 +3980,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* } pOperator->name = "TableAggregate"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_AGG; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_HASH_AGG; pOperator->blocking = true; pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; @@ -4008,6 +4042,19 @@ static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) { taosArrayDestroy(pInfo->pPseudoColInfo); } +static void destroyIndefinitOperatorInfo(void* param, int32_t numOfOutput) { + SIndefOperatorInfo* pInfo = (SIndefOperatorInfo*)param; + doDestroyBasicInfo(&pInfo->binfo, numOfOutput); + + taosArrayDestroy(pInfo->pPseudoColInfo); + cleanupAggSup(&pInfo->aggSup); + + destroySqlFunctionCtx(pInfo->pScalarCtx, numOfOutput); + destroyExprInfo(pInfo->pScalarExpr, pInfo->numOfScalarExpr); + + taosMemoryFree(pInfo->rowCellInfoOffset); +} + void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput) { SExchangeInfo* pExInfo = (SExchangeInfo*)param; taosArrayDestroy(pExInfo->pSources); @@ -4085,6 +4132,136 @@ _error: return NULL; } +static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { + SIndefOperatorInfo* pIndefInfo = pOperator->info; + SOptrBasicInfo* pInfo = &pIndefInfo->binfo; + + SSDataBlock* pRes = pInfo->pRes; + blockDataCleanup(pRes); + + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + int64_t st = 0; + int32_t order = 0; + int32_t scanFlag = 0; + + if (pOperator->cost.openCost == 0) { + st = taosGetTimestampUs(); + } + + SOperatorInfo* downstream = pOperator->pDownstream[0]; + + while (1) { + // The downstream exec may change the value of the newgroup, so use a local variable instead. + SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); + if (pBlock == NULL) { + doSetOperatorCompleted(pOperator); + break; + } + + // the pDataBlock are always the same one, no need to call this again + int32_t code = getTableScanInfo(pOperator->pDownstream[0], &order, &scanFlag); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + + // there is an scalar expression that needs to be calculated before apply the group aggregation. + if (pIndefInfo->pScalarExpr != NULL) { + code = projectApplyFunctions(pIndefInfo->pScalarExpr, pBlock, pBlock, pIndefInfo->pScalarCtx, + pIndefInfo->numOfScalarExpr, pIndefInfo->pPseudoColInfo); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + } + + setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order, scanFlag, false); + blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); + + code = projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfExprs, + pIndefInfo->pPseudoColInfo); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + } + + size_t rows = pInfo->pRes->info.rows; + pOperator->resultInfo.totalRows += rows; + + if (pOperator->cost.openCost == 0) { + pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0; + } + + return (rows > 0) ? pInfo->pRes : NULL; +} + +SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pNode, + SExecTaskInfo* pTaskInfo) { + SIndefOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SIndefOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + if (pInfo == NULL || pOperator == NULL) { + goto _error; + } + + SIndefRowsFuncPhysiNode* pPhyNode = (SIndefRowsFuncPhysiNode*)pNode; + + int32_t numOfExpr = 0; + SExprInfo* pExprInfo = createExprInfo(pPhyNode->pVectorFuncs, NULL, &numOfExpr); + + int32_t numOfScalarExpr = 0; + if (pPhyNode->pExprs != NULL) { + pInfo->pScalarExpr = createExprInfo(pPhyNode->pExprs, NULL, &numOfScalarExpr); + pInfo->pScalarCtx = createSqlFunctionCtx(pInfo->pScalarExpr, numOfScalarExpr, &pInfo->rowCellInfoOffset); + } + + SSDataBlock* pResBlock = createResDataBlock(pPhyNode->node.pOutputDataBlockDesc); + ; + + int32_t numOfRows = 4096; + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + + // Make sure the size of SSDataBlock will never exceed the size of 2MB. + int32_t TWOMB = 2 * 1024 * 1024; + if (numOfRows * pResBlock->info.rowSize > TWOMB) { + numOfRows = TWOMB / pResBlock->info.rowSize; + } + initResultSizeInfo(pOperator, numOfRows); + + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfExpr, pResBlock, keyBufSize, pTaskInfo->id.str); + setFunctionResultOutput(&pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, numOfExpr, pTaskInfo); + + pInfo->binfo.pRes = pResBlock; + pInfo->numOfScalarExpr = numOfScalarExpr; + pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pInfo->binfo.pCtx, numOfExpr); + + pOperator->name = "IndefinitOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PROJECT; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pExpr = pExprInfo; + pOperator->numOfExprs = numOfExpr; + pOperator->pTaskInfo = pTaskInfo; + + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doApplyIndefinitFunction, NULL, NULL, + destroyIndefinitOperatorInfo, NULL, NULL, NULL); + + int32_t code = appendDownstream(pOperator, &downstream, 1); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + + return pOperator; + +_error: + taosMemoryFree(pInfo); + taosMemoryFree(pOperator); + pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; + return NULL; +} + static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t numOfCols, SNodeListNode* pValNode, STimeWindow win, int32_t capacity, const char* id, SInterval* pInterval, int32_t fillType) { SFillColInfo* pColInfo = createFillColInfo(pExpr, numOfCols, pValNode); @@ -4449,7 +4626,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SLimit slimit = {.limit = pProjPhyNode->slimit, .offset = pProjPhyNode->soffset}; pOptr = createProjectOperatorInfo(ops[0], pExprInfo, num, pResBlock, &limit, &slimit, pProjPhyNode->node.pConditions, pTaskInfo); - } else if (QUERY_NODE_PHYSICAL_PLAN_AGG == type) { + } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_AGG == type) { SAggPhysiNode* pAggNode = (SAggPhysiNode*)pPhyNode; SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num); SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc); @@ -4501,6 +4678,12 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo int32_t tsSlotId = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId; pOptr = createIntervalOperatorInfo(ops[0], pExprInfo, num, pResBlock, &interval, tsSlotId, &as, pTaskInfo); + } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL == type) { + int32_t children = 8; + pOptr = createStreamFinalIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo, children); + } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL == type) { + int32_t children = 0; + pOptr = createStreamFinalIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo, children); } else if (QUERY_NODE_PHYSICAL_PLAN_SORT == type) { SSortPhysiNode* pSortPhyNode = (SSortPhysiNode*)pPhyNode; @@ -4517,7 +4700,20 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo extractColMatchInfo(pSortPhyNode->pTargets, pDescNode, &numOfOutputCols, pTaskInfo, COL_MATCH_FROM_SLOT_ID); pOptr = createSortOperatorInfo(ops[0], pResBlock, info, pExprInfo, numOfCols, pColList, pTaskInfo); - } else if (QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW == type) { + } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE == type) { + SMergePhysiNode* pMergePhyNode = (SMergePhysiNode*)pPhyNode; + + SDataBlockDescNode* pDescNode = pPhyNode->pOutputDataBlockDesc; + SSDataBlock* pResBlock = createResDataBlock(pDescNode); + + SArray* sortInfo = createSortInfo(pMergePhyNode->pMergeKeys); + int32_t numOfOutputCols = 0; + SArray* pColList = + extractColMatchInfo(pMergePhyNode->pTargets, pDescNode, &numOfOutputCols, pTaskInfo, COL_MATCH_FROM_SLOT_ID); + SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0); + SSDataBlock* pInputDataBlock = createResDataBlock(pChildNode->pOutputDataBlockDesc); + pOptr = createMultiwaySortMergeOperatorInfo(ops, size, pInputDataBlock, pResBlock, sortInfo, pColList, pTaskInfo); + } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION == type) { SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode; STimeWindowAggSupp as = {.waterMark = pSessionNode->window.watermark, @@ -4529,7 +4725,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo pOptr = createSessionAggOperatorInfo(ops[0], pExprInfo, num, pResBlock, pSessionNode->gap, tsSlotId, &as, pTaskInfo); - } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW == type) { + } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION == type) { SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode; STimeWindowAggSupp as = {.waterMark = pSessionNode->window.watermark, @@ -4549,7 +4745,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SExprInfo* pExprInfo = createExprInfo(pPartNode->pTargets, NULL, &num); pOptr = createPartitionOperatorInfo(ops[0], pExprInfo, num, pResBlock, pColList, pTaskInfo); - } else if (QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW == type) { + } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE == type) { SStateWinodwPhysiNode* pStateNode = (SStateWinodwPhysiNode*)pPhyNode; STimeWindowAggSupp as = {.waterMark = pStateNode->window.watermark, .calTrigger = pStateNode->window.triggerType}; @@ -4561,9 +4757,9 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SColumnNode* pColNode = (SColumnNode*)((STargetNode*)pStateNode->pStateKey)->pExpr; SColumn col = extractColumnFromColumnNode(pColNode); pOptr = createStatewindowOperatorInfo(ops[0], pExprInfo, num, pResBlock, &as, tsSlotId, &col, pTaskInfo); - } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW == type) { + } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE == type) { pOptr = createStreamStateAggOperatorInfo(ops[0], pPhyNode, pTaskInfo); - } else if (QUERY_NODE_PHYSICAL_PLAN_JOIN == type) { + } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN == type) { SJoinPhysiNode* pJoinNode = (SJoinPhysiNode*)pPhyNode; SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc); @@ -4577,6 +4773,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SInterval* pInterval = &((SIntervalAggOperatorInfo*)ops[0]->info)->interval; pOptr = createFillOperatorInfo(ops[0], pExprInfo, num, pInterval, &pFillNode->timeRange, pResBlock, pFillNode->mode, (SNodeListNode*)pFillNode->pValues, false, pTaskInfo); + } else if (QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC == type) { + pOptr = createIndefinitOutputOperatorInfo(ops[0], pPhyNode, pTaskInfo); } else { ASSERT(0); } @@ -4613,6 +4811,7 @@ int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysi pCond->numOfTWindows = 1; pCond->twindows = taosMemoryCalloc(pCond->numOfTWindows, sizeof(STimeWindow)); pCond->twindows[0] = pTableScanNode->scanRange; + pCond->suid = pTableScanNode->scan.suid; #if 1 // todo work around a problem, remove it later @@ -4952,6 +5151,36 @@ int32_t decodeOperator(SOperatorInfo* ops, char* result, int32_t length) { return TDB_CODE_SUCCESS; } +int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, qTaskInfo_t* pTaskInfo) { + SExecTaskInfo* pTask = *(SExecTaskInfo**)pTaskInfo; + + switch (pNode->type) { + case QUERY_NODE_PHYSICAL_PLAN_DELETE: { + SDeleterParam* pDeleterParam = taosMemoryCalloc(1, sizeof(SDeleterParam)); + if (NULL == pDeleterParam) { + return TSDB_CODE_OUT_OF_MEMORY; + } + int32_t tbNum = taosArrayGetSize(pTask->tableqinfoList.pTableList); + pDeleterParam->pUidList = taosArrayInit(tbNum, sizeof(uint64_t)); + if (NULL == pDeleterParam->pUidList) { + taosMemoryFree(pDeleterParam); + return TSDB_CODE_OUT_OF_MEMORY; + } + for (int32_t i = 0; i < tbNum; ++i) { + STableKeyInfo* pTable = taosArrayGet(pTask->tableqinfoList.pTableList, i); + taosArrayPush(pDeleterParam->pUidList, &pTable->uid); + } + + *pParam = pDeleterParam; + break; + } + default: + break; + } + + return TSDB_CODE_SUCCESS; +} + int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId, EOPTR_EXEC_MODEL model) { uint64_t queryId = pPlan->id.queryId; diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 132f93a6a5..5965f5d7ad 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -359,7 +359,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) { while(1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - doFilter(pInfo->pCondition, pRes); + doFilter(pInfo->pCondition, pRes, true); bool hasRemain = hashRemainDataInGroupInfo(&pInfo->groupResInfo); if (!hasRemain) { diff --git a/source/libs/executor/src/joinoperator.c b/source/libs/executor/src/joinoperator.c index ad9e4d63f0..7c8ab244a1 100644 --- a/source/libs/executor/src/joinoperator.c +++ b/source/libs/executor/src/joinoperator.c @@ -13,20 +13,20 @@ * along with this program. If not, see . */ +#include "executorimpl.h" #include "function.h" #include "os.h" #include "querynodes.h" -#include "tdatablock.h" -#include "tmsg.h" -#include "executorimpl.h" #include "tcompare.h" +#include "tdatablock.h" #include "thash.h" +#include "tmsg.h" #include "ttypes.h" -static void setJoinColumnInfo(SColumnInfo* pColumn, const SColumnNode* pColumnNode); +static void setJoinColumnInfo(SColumnInfo* pColumn, const SColumnNode* pColumnNode); static SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator); -static void destroyMergeJoinOperator(void* param, int32_t numOfOutput); -static void extractTimeCondition(SJoinOperatorInfo *Info, SLogicConditionNode* pLogicConditionNode); +static void destroyMergeJoinOperator(void* param, int32_t numOfOutput); +static void extractTimeCondition(SJoinOperatorInfo* Info, SLogicConditionNode* pLogicConditionNode); SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SNode* pOnCondition, @@ -39,22 +39,22 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t initResultSizeInfo(pOperator, 4096); - pInfo->pRes = pResBlock; - pOperator->name = "MergeJoinOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_JOIN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExprInfo; + pInfo->pRes = pResBlock; + pOperator->name = "MergeJoinOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExprInfo; pOperator->numOfExprs = numOfCols; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; if (nodeType(pOnCondition) == QUERY_NODE_OPERATOR) { SOperatorNode* pNode = (SOperatorNode*)pOnCondition; setJoinColumnInfo(&pInfo->leftCol, (SColumnNode*)pNode->pLeft); setJoinColumnInfo(&pInfo->rightCol, (SColumnNode*)pNode->pRight); } else if (nodeType(pOnCondition) == QUERY_NODE_LOGIC_CONDITION) { - extractTimeCondition(pInfo, (SLogicConditionNode*) pOnCondition); + extractTimeCondition(pInfo, (SLogicConditionNode*)pOnCondition); } pOperator->fpSet = @@ -66,7 +66,7 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t return pOperator; - _error: +_error: taosMemoryFree(pInfo); taosMemoryFree(pOperator); pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; @@ -180,10 +180,10 @@ SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) { return (pRes->info.rows > 0) ? pRes : NULL; } -static void extractTimeCondition(SJoinOperatorInfo *pInfo, SLogicConditionNode* pLogicConditionNode) { +static void extractTimeCondition(SJoinOperatorInfo* pInfo, SLogicConditionNode* pLogicConditionNode) { int32_t len = LIST_LENGTH(pLogicConditionNode->pParameterList); - for(int32_t i = 0; i < len; ++i) { + for (int32_t i = 0; i < len; ++i) { SNode* pNode = nodesListGetNode(pLogicConditionNode->pParameterList, i); if (nodeType(pNode) == QUERY_NODE_OPERATOR) { SOperatorNode* pn1 = (SOperatorNode*)pNode; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index ba0397fd34..f502a1a27c 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -42,10 +42,11 @@ static int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capac static int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size, const char* dbName); -static void addTagPseudoColumnData(SReadHandle *pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, SSDataBlock* pBlock); -static bool processBlockWithProbability(const SSampleExecInfo *pInfo); +static void addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, + SSDataBlock* pBlock); +static bool processBlockWithProbability(const SSampleExecInfo* pInfo); -bool processBlockWithProbability(const SSampleExecInfo *pInfo) { +bool processBlockWithProbability(const SSampleExecInfo* pInfo) { #if 0 if (pInfo->sampleRatio == 1) { return true; @@ -261,11 +262,12 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca // currently only the tbname pseudo column if (pTableScanInfo->numOfPseudoExpr > 0) { - addTagPseudoColumnData(&pTableScanInfo->readHandle, pTableScanInfo->pPseudoExpr, pTableScanInfo->numOfPseudoExpr, pBlock); + addTagPseudoColumnData(&pTableScanInfo->readHandle, pTableScanInfo->pPseudoExpr, pTableScanInfo->numOfPseudoExpr, + pBlock); } int64_t st = taosGetTimestampMs(); - doFilter(pTableScanInfo->pFilterNode, pBlock); + doFilter(pTableScanInfo->pFilterNode, pBlock, false); int64_t et = taosGetTimestampMs(); pTableScanInfo->readRecorder.filterTime += (et - st); @@ -295,7 +297,8 @@ static void prepareForDescendingScan(STableScanInfo* pTableScanInfo, SqlFunction taosqsort(pCond->twindows, pCond->numOfTWindows, sizeof(STimeWindow), pCond, compareTimeWindow); } -void addTagPseudoColumnData(SReadHandle *pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, SSDataBlock* pBlock) { +void addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, + SSDataBlock* pBlock) { // currently only the tbname pseudo column if (numOfPseudoExpr == 0) { return; @@ -311,7 +314,7 @@ void addTagPseudoColumnData(SReadHandle *pHandle, SExprInfo* pPseudoExpr, int32_ int32_t dstSlotId = pExpr->base.resSchema.slotId; SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId); - + colInfoDataEnsureCapacity(pColInfoData, 0, pBlock->info.rows); colInfoDataCleanup(pColInfoData, pBlock->info.rows); @@ -391,10 +394,10 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) { recordNewGroupKeys(pTableScanInfo->pGroupCols, pTableScanInfo->pGroupColVals, pBlock, 0); int32_t len = buildGroupKeys(pTableScanInfo->keyBuf, pTableScanInfo->pGroupColVals); - uint64_t *groupId = taosHashGet(pTableScanInfo->pGroupSet, pTableScanInfo->keyBuf, len); + uint64_t* groupId = taosHashGet(pTableScanInfo->pGroupSet, pTableScanInfo->keyBuf, len); if (groupId) { pBlock->info.groupId = *groupId; - }else if(len != 0){ + } else if (len != 0) { pBlock->info.groupId = calcGroupId(pTableScanInfo->keyBuf, len); taosHashPut(pTableScanInfo->pGroupSet, pTableScanInfo->keyBuf, len, &pBlock->info.groupId, sizeof(uint64_t)); } @@ -483,7 +486,8 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) { setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); pTableScanInfo->scanFlag = REPEAT_SCAN; - qDebug("%s start to repeat descending order scan data blocks due to query func required", GET_TASKID(pTaskInfo)); + qDebug("%s start to repeat descending order scan data blocks due to query func required", + GET_TASKID(pTaskInfo)); for (int32_t i = 0; i < pTableScanInfo->cond.numOfTWindows; ++i) { STimeWindow* pWin = &pTableScanInfo->cond.twindows[i]; qDebug("%s\t qrange:%" PRId64 "-%" PRId64, GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey); @@ -525,7 +529,7 @@ static void destroyTableScanOperatorInfo(void* param, int32_t numOfOutput) { tsdbCleanupReadHandle(pTableScanInfo->dataReader); taosArrayDestroy(pTableScanInfo->pGroupCols); - for(int i = 0; i < taosArrayGetSize(pTableScanInfo->pGroupColVals); i++){ + for (int i = 0; i < taosArrayGetSize(pTableScanInfo->pGroupColVals); i++) { SGroupKeys key = *(SGroupKeys*)taosArrayGet(pTableScanInfo->pGroupColVals, i); taosMemoryFree(key.pData); } @@ -562,28 +566,28 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, } pInfo->scanInfo = (SScanInfo){.numOfAsc = pTableScanNode->scanSeq[0], .numOfDesc = pTableScanNode->scanSeq[1]}; -// pInfo->scanInfo = (SScanInfo){.numOfAsc = 0, .numOfDesc = 1}; // for debug purpose + // pInfo->scanInfo = (SScanInfo){.numOfAsc = 0, .numOfDesc = 1}; // for debug purpose - pInfo->readHandle = *readHandle; - pInfo->interval = extractIntervalInfo(pTableScanNode); - pInfo->sample.sampleRatio= pTableScanNode->ratio; - pInfo->sample.seed = taosGetTimestampSec(); + pInfo->readHandle = *readHandle; + pInfo->interval = extractIntervalInfo(pTableScanNode); + pInfo->sample.sampleRatio = pTableScanNode->ratio; + pInfo->sample.seed = taosGetTimestampSec(); pInfo->dataBlockLoadFlag = pTableScanNode->dataRequired; - pInfo->pResBlock = createResDataBlock(pDescNode); - pInfo->pFilterNode = pTableScanNode->scan.node.pConditions; - pInfo->dataReader = pDataReader; - pInfo->scanFlag = MAIN_SCAN; - pInfo->pColMatchInfo = pColList; - pInfo->curTWinIdx = 0; + pInfo->pResBlock = createResDataBlock(pDescNode); + pInfo->pFilterNode = pTableScanNode->scan.node.pConditions; + pInfo->dataReader = pDataReader; + pInfo->scanFlag = MAIN_SCAN; + pInfo->pColMatchInfo = pColList; + pInfo->curTWinIdx = 0; - pOperator->name = "TableScanOperator"; // for debug purpose + pOperator->name = "TableScanOperator"; // for debug purpose pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfExprs = numOfCols; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfExprs = numOfCols; + pOperator->pTaskInfo = pTaskInfo; // for table group pInfo->pGroupCols = groupKyes; @@ -604,7 +608,7 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, pOperator->cost.openCost = 0; return pOperator; - _error: +_error: taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -723,16 +727,19 @@ static void doClearBufferedBlocks(SStreamBlockScanInfo* pInfo) { } static bool isSessionWindow(SStreamBlockScanInfo* pInfo) { - return pInfo->sessionSup.parentType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW; + return pInfo->sessionSup.parentType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION; } static bool isStateWindow(SStreamBlockScanInfo* pInfo) { - return pInfo->sessionSup.parentType == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW; + return pInfo->sessionSup.parentType == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE; } static bool prepareDataScan(SStreamBlockScanInfo* pInfo) { SSDataBlock* pSDB = pInfo->pUpdateRes; - STimeWindow win = {.skey = INT64_MIN, .ekey = INT64_MAX,}; + STimeWindow win = { + .skey = INT64_MIN, + .ekey = INT64_MAX, + }; bool needRead = false; if (!isStateWindow(pInfo) && pInfo->updateResIndex < pSDB->info.rows) { SColumnInfoData* pColDataInfo = taosArrayGet(pSDB->pDataBlock, pInfo->primaryTsIndex); @@ -759,7 +766,7 @@ static bool prepareDataScan(SStreamBlockScanInfo* pInfo) { SArray* pWins = pInfo->sessionSup.pStreamAggSup->pScanWindow; int32_t size = taosArrayGetSize(pWins); if (pInfo->scanWinIndex < size) { - win = *(STimeWindow *)taosArrayGet(pWins, pInfo->scanWinIndex); + win = *(STimeWindow*)taosArrayGet(pWins, pInfo->scanWinIndex); pInfo->scanWinIndex++; needRead = true; } else { @@ -790,11 +797,11 @@ static SSDataBlock* doDataScan(SStreamBlockScanInfo* pInfo) { return pResult; } -static void getUpdateDataBlock(SStreamBlockScanInfo* pInfo, bool invertible, - SSDataBlock* pBlock, SSDataBlock* pUpdateBlock) { +static void getUpdateDataBlock(SStreamBlockScanInfo* pInfo, bool invertible, SSDataBlock* pBlock, + SSDataBlock* pUpdateBlock) { SColumnInfoData* pColDataInfo = taosArrayGet(pBlock->pDataBlock, pInfo->primaryTsIndex); ASSERT(pColDataInfo->info.type == TSDB_DATA_TYPE_TIMESTAMP); - TSKEY* ts = (TSKEY*)pColDataInfo->pData; + TSKEY* ts = (TSKEY*)pColDataInfo->pData; for (int32_t i = 0; i < pBlock->info.rows; i++) { if (updateInfoIsUpdated(pInfo->pUpdateInfo, pBlock->info.uid, ts[i])) { taosArrayPush(pInfo->tsArray, ts + i); @@ -839,7 +846,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { size_t total = taosArrayGetSize(pInfo->pBlockLists); if (pInfo->blockType == STREAM_DATA_TYPE_SSDATA_BLOCK) { if (pInfo->validBlockIndex >= total) { - doClearBufferedBlocks(pInfo); + /*doClearBufferedBlocks(pInfo);*/ pOperator->status = OP_EXEC_DONE; return NULL; } @@ -859,8 +866,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { } return pInfo->pUpdateRes; } else { - if (isStateWindow(pInfo) && - taosArrayGetSize(pInfo->sessionSup.pStreamAggSup->pScanWindow) > 0) { + if (isStateWindow(pInfo) && taosArrayGetSize(pInfo->sessionSup.pStreamAggSup->pScanWindow) > 0) { pInfo->scanMode = STREAM_SCAN_FROM_DATAREADER; pInfo->updateResIndex = pInfo->pUpdateRes->info.rows; prepareDataScan(pInfo); @@ -944,7 +950,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { addTagPseudoColumnData(&pInfo->readHandle, pInfo->pPseudoExpr, pInfo->numOfPseudoExpr, pInfo->pRes); } - doFilter(pInfo->pCondition, pInfo->pRes); + doFilter(pInfo->pCondition, pInfo->pRes, false); blockDataUpdateTsWindow(pInfo->pRes, 0); break; } @@ -956,16 +962,15 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { if (rows == 0) { pOperator->status = OP_EXEC_DONE; } else if (pInfo->pUpdateInfo) { - SSDataBlock* upRes = createOneDataBlock(pInfo->pRes, false); - getUpdateDataBlock(pInfo, true, pInfo->pRes, upRes); - if (upRes) { - pInfo->pUpdateRes = upRes; - if (upRes->info.type == STREAM_REPROCESS) { + blockDataCleanup(pInfo->pUpdateRes); + getUpdateDataBlock(pInfo, true, pInfo->pRes, pInfo->pUpdateRes); + if (pInfo->pUpdateRes->info.rows > 0) { + if (pInfo->pUpdateRes->info.type == STREAM_REPROCESS) { pInfo->updateResIndex = 0; pInfo->scanMode = STREAM_SCAN_FROM_UPDATERES; - } else if (upRes->info.type == STREAM_INVERT) { + } else if (pInfo->pUpdateRes->info.type == STREAM_INVERT) { pInfo->scanMode = STREAM_SCAN_FROM_RES; - return upRes; + return pInfo->pUpdateRes; } } } @@ -974,9 +979,9 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { } } -SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHandle, - SArray* pTableIdList, STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo, - STimeWindowAggSupp* pTwSup) { +SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHandle, SArray* pTableIdList, + STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo, + STimeWindowAggSupp* pTwSup) { SStreamBlockScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamBlockScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -987,12 +992,13 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan SScanPhysiNode* pScanPhyNode = &pTableScanNode->scan; SDataBlockDescNode* pDescNode = pScanPhyNode->node.pOutputDataBlockDesc; - SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, NULL, pTaskInfo); + SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, NULL, pTaskInfo); STableScanInfo* pSTInfo = (STableScanInfo*)pTableScanDummy->info; int32_t numOfCols = 0; - pInfo->pColMatchInfo = extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, pTaskInfo, COL_MATCH_FROM_COL_ID); + pInfo->pColMatchInfo = + extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, pTaskInfo, COL_MATCH_FROM_COL_ID); int32_t numOfOutput = taosArrayGetSize(pInfo->pColMatchInfo); SArray* pColIds = taosArrayInit(numOfOutput, sizeof(int16_t)); @@ -1025,8 +1031,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan } if (isSmaStream(pTableScanNode->triggerType)) { - pTwSup->waterMark = getSmaWaterMark(pSTInfo->interval.interval, - pTableScanNode->filesFactor); + pTwSup->waterMark = getSmaWaterMark(pSTInfo->interval.interval, pTableScanNode->filesFactor); } if (pSTInfo->interval.interval > 0 && pDataReader) { @@ -1040,27 +1045,27 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan pInfo->pPseudoExpr = createExprInfo(pTableScanNode->scan.pScanPseudoCols, NULL, &pInfo->numOfPseudoExpr); } - pInfo->readHandle = *pHandle; - pInfo->tableUid = pScanPhyNode->uid; + pInfo->readHandle = *pHandle; + pInfo->tableUid = pScanPhyNode->uid; pInfo->streamBlockReader = pHandle->reader; - pInfo->pRes = createResDataBlock(pDescNode); - pInfo->pCondition = pScanPhyNode->node.pConditions; - pInfo->pDataReader = pDataReader; - pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE; - pInfo->pOperatorDumy = pTableScanDummy; - pInfo->interval = pSTInfo->interval; - pInfo->sessionSup = (SessionWindowSupporter){.pStreamAggSup = NULL, .gap = -1}; - - pOperator->name = "StreamBlockScanOperator"; + pInfo->pRes = createResDataBlock(pDescNode); + pInfo->pUpdateRes = createResDataBlock(pDescNode); + pInfo->pCondition = pScanPhyNode->node.pConditions; + pInfo->pDataReader = pDataReader; + pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE; + pInfo->pOperatorDumy = pTableScanDummy; + pInfo->interval = pSTInfo->interval; + pInfo->sessionSup = (SessionWindowSupporter){.pStreamAggSup = NULL, .gap = -1}; + pOperator->name = "StreamBlockScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfExprs = pInfo->pRes->info.numOfCols; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfExprs = pInfo->pRes->info.numOfCols; + pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamBlockScan, NULL, - NULL, operatorDummyCloseFn, NULL, NULL, NULL); + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, doStreamBlockScan, NULL, NULL, operatorDummyCloseFn, NULL, NULL, NULL); return pOperator; @@ -1445,8 +1450,8 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { } SRetrieveMetaTableRsp* pTableRsp = pInfo->pRsp; - setDataBlockFromFetchRsp(pInfo->pRes, &pInfo->loadInfo, pTableRsp->numOfRows, pTableRsp->data, - pTableRsp->compLen, pOperator->numOfExprs, startTs, NULL, pInfo->scanCols); + setDataBlockFromFetchRsp(pInfo->pRes, &pInfo->loadInfo, pTableRsp->numOfRows, pTableRsp->data, pTableRsp->compLen, + pOperator->numOfExprs, startTs, NULL, pInfo->scanCols); // todo log the filter info doFilterResult(pInfo); @@ -1519,7 +1524,8 @@ int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbT return numOfRows; } -SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode *pScanPhyNode, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode* pScanPhyNode, + SExecTaskInfo* pTaskInfo) { SSysTableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SSysTableScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -1529,16 +1535,16 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan SScanPhysiNode* pScanNode = &pScanPhyNode->scan; SDataBlockDescNode* pDescNode = pScanNode->node.pOutputDataBlockDesc; - SSDataBlock* pResBlock = createResDataBlock(pDescNode); + SSDataBlock* pResBlock = createResDataBlock(pDescNode); int32_t num = 0; SArray* colList = extractColMatchInfo(pScanNode->pScanCols, pDescNode, &num, pTaskInfo, COL_MATCH_FROM_COL_ID); - pInfo->accountId = pScanPhyNode->accountId; + pInfo->accountId = pScanPhyNode->accountId; pInfo->showRewrite = pScanPhyNode->showRewrite; - pInfo->pRes = pResBlock; - pInfo->pCondition = pScanNode->node.pConditions; - pInfo->scanCols = colList; + pInfo->pRes = pResBlock; + pInfo->pCondition = pScanNode->node.pConditions; + pInfo->scanCols = colList; initResultSizeInfo(pOperator, 4096); @@ -1554,20 +1560,20 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan pInfo->readHandle = *(SReadHandle*)readHandle; } - pOperator->name = "SysTableScanOperator"; + pOperator->name = "SysTableScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfExprs = pResBlock->info.numOfCols; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfExprs = pResBlock->info.numOfCols; + pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, NULL, destroySysScanOperator, NULL, NULL, NULL); return pOperator; - _error: +_error: taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; @@ -1687,16 +1693,16 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) { val.cid = pExprInfo[j].base.pParam[0].pCol->colId; const char* p = metaGetTableTagVal(&mr.me, pDst->info.type, &val); - char *data = NULL; - if(pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL){ - data = tTagValToData((const STagVal *)p, false); - }else { + char* data = NULL; + if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL) { + data = tTagValToData((const STagVal*)p, false); + } else { data = (char*)p; } colDataAppend(pDst, count, data, (data == NULL)); - if(pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL - && IS_VAR_DATA_TYPE(((const STagVal *)p)->type) && data != NULL){ + if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) && + data != NULL) { taosMemoryFree(data); } } @@ -1716,7 +1722,9 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) { } pRes->info.rows = count; - pOperator->resultInfo.totalRows += count; + doFilter(pInfo->pFilterNode, pRes, true); + + pOperator->resultInfo.totalRows += pRes->info.rows; return (pRes->info.rows == 0) ? NULL : pInfo->pRes; } @@ -1726,7 +1734,8 @@ static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) { pInfo->pRes = blockDataDestroy(pInfo->pRes); } -SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pPhyNode, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pPhyNode, + STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo) { STagScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STagScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -1741,19 +1750,21 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi int32_t num = 0; SArray* colList = extractColMatchInfo(pPhyNode->pScanPseudoCols, pDescNode, &num, pTaskInfo, COL_MATCH_FROM_COL_ID); - pInfo->pTableList = pTableListInfo; - pInfo->pColMatchInfo = colList; - pInfo->pRes = createResDataBlock(pDescNode);; - pInfo->readHandle = *pReadHandle; - pInfo->curPos = 0; - pOperator->name = "TagScanOperator"; + pInfo->pTableList = pTableListInfo; + pInfo->pColMatchInfo = colList; + pInfo->pRes = createResDataBlock(pDescNode); + ; + pInfo->readHandle = *pReadHandle; + pInfo->curPos = 0; + pInfo->pFilterNode = pPhyNode->node.pConditions; + pOperator->name = "TagScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pExpr = pExprInfo; - pOperator->numOfExprs = numOfExprs; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pExpr = pExprInfo; + pOperator->numOfExprs = numOfExprs; + pOperator->pTaskInfo = pTaskInfo; initResultSizeInfo(pOperator, 4096); blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index 5e1b47cc91..dcaa95e28a 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -13,17 +13,18 @@ * along with this program. If not, see . */ -#include "tdatablock.h" #include "executorimpl.h" +#include "tdatablock.h" static SSDataBlock* doSort(SOperatorInfo* pOperator); -static int32_t doOpenSortOperator(SOperatorInfo* pOperator); -static int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len); +static int32_t doOpenSortOperator(SOperatorInfo* pOperator); +static int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len); static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput); -SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExprInfo* pExprInfo, int32_t numOfCols, - SArray* pColMatchColInfo, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, + SExprInfo* pExprInfo, int32_t numOfCols, SArray* pColMatchColInfo, + SExecTaskInfo* pTaskInfo) { SSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); int32_t rowSize = pResBlock->info.rowSize; @@ -32,33 +33,35 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR goto _error; } - pOperator->pExpr = pExprInfo; + pOperator->pExpr = pExprInfo; pOperator->numOfExprs = numOfCols; - pInfo->binfo.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pInfo->binfo.rowCellInfoOffset); - pInfo->binfo.pRes = pResBlock; + pInfo->binfo.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pInfo->binfo.rowCellInfoOffset); + pInfo->binfo.pRes = pResBlock; initResultSizeInfo(pOperator, 1024); - pInfo->pSortInfo = pSortInfo; - pInfo->pColMatchInfo= pColMatchColInfo; - pOperator->name = "SortOperator"; + pInfo->pSortInfo = pSortInfo; + pInfo->pColMatchInfo = pColMatchColInfo; + pInfo->hasGroupId = false; + pInfo->prefetchedTuple = NULL; + pOperator->name = "SortOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT; pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; // lazy evaluation for the following parameter since the input datablock is not known till now. -// pInfo->bufPageSize = rowSize < 1024 ? 1024 * 2 : rowSize * 2; // there are headers, so pageSize = rowSize + header -// pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer + // pInfo->bufPageSize = rowSize < 1024 ? 1024 * 2 : rowSize * 2; // there are headers, so pageSize = rowSize + + // header pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = - createOperatorFpSet(doOpenSortOperator, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, getExplainExecInfo); + pOperator->fpSet = createOperatorFpSet(doOpenSortOperator, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, + getExplainExecInfo); int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; - _error: +_error: pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(pInfo); taosMemoryFree(pOperator); @@ -68,7 +71,7 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle) { for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); - bool isNull = tsortIsNullVal(pTupleHandle, i); + bool isNull = tsortIsNullVal(pTupleHandle, i); if (isNull) { colDataAppendNULL(pColInfo, pBlock->info.rows); } else { @@ -80,9 +83,9 @@ void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle) { pBlock->info.rows += 1; } -SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, SArray* pColMatchInfo) { +SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, SArray* pColMatchInfo, + SSortOperatorInfo* pInfo) { blockDataCleanup(pDataBlock); - ASSERT(taosArrayGetSize(pColMatchInfo) == pDataBlock->info.numOfCols); SSDataBlock* p = tsortGetSortedDataBlock(pHandle); if (p == NULL) { @@ -92,14 +95,33 @@ SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, i blockDataEnsureCapacity(p, capacity); while (1) { - STupleHandle* pTupleHandle = tsortNextTuple(pHandle); + STupleHandle* pTupleHandle = NULL; + if (pInfo->prefetchedTuple == NULL) { + pTupleHandle = tsortNextTuple(pHandle); + } else { + pTupleHandle = pInfo->prefetchedTuple; + pInfo->groupId = tsortGetGroupId(pTupleHandle); + pInfo->prefetchedTuple = NULL; + } + if (pTupleHandle == NULL) { break; } - appendOneRowToDataBlock(p, pTupleHandle); + uint64_t tupleGroupId = tsortGetGroupId(pTupleHandle); + if (!pInfo->hasGroupId) { + pInfo->groupId = tupleGroupId; + pInfo->hasGroupId = true; + appendOneRowToDataBlock(p, pTupleHandle); + } else if (pInfo->groupId == tupleGroupId) { + appendOneRowToDataBlock(p, pTupleHandle); + } else { + pInfo->prefetchedTuple = pTupleHandle; + break; + } + if (p->info.rows >= capacity) { - return pDataBlock; + break; } } @@ -116,6 +138,7 @@ SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, i pDataBlock->info.rows = p->info.rows; pDataBlock->info.capacity = p->info.rows; + pDataBlock->info.groupId = pInfo->groupId; } blockDataDestroy(p); @@ -129,10 +152,11 @@ SSDataBlock* loadNextDataBlock(void* param) { // todo refactor: merged with fetch fp void applyScalarFunction(SSDataBlock* pBlock, void* param) { - SOperatorInfo* pOperator = param; + SOperatorInfo* pOperator = param; SSortOperatorInfo* pSort = pOperator->info; if (pOperator->pExpr != NULL) { - int32_t code = projectApplyFunctions(pOperator->pExpr, pBlock, pBlock, pSort->binfo.pCtx, pOperator->numOfExprs, NULL); + int32_t code = + projectApplyFunctions(pOperator->pExpr, pBlock, pBlock, pSort->binfo.pCtx, pOperator->numOfExprs, NULL); if (code != TSDB_CODE_SUCCESS) { longjmp(pOperator->pTaskInfo->env, code); } @@ -141,7 +165,7 @@ void applyScalarFunction(SSDataBlock* pBlock, void* param) { int32_t doOpenSortOperator(SOperatorInfo* pOperator) { SSortOperatorInfo* pInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; if (OPTR_IS_OPENED(pOperator)) { return TSDB_CODE_SUCCESS; @@ -150,8 +174,8 @@ int32_t doOpenSortOperator(SOperatorInfo* pOperator) { pInfo->startTs = taosGetTimestampUs(); // pInfo->binfo.pRes is not equalled to the input datablock. - pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->pColMatchInfo, SORT_SINGLESOURCE_SORT, - -1, -1, NULL, pTaskInfo->id.str); + pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->pColMatchInfo, SORT_SINGLESOURCE_SORT, -1, -1, + NULL, pTaskInfo->id.str); tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, applyScalarFunction, pOperator); @@ -166,7 +190,7 @@ int32_t doOpenSortOperator(SOperatorInfo* pOperator) { longjmp(pTaskInfo->env, terrno); } - pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs)/1000.0; + pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs) / 1000.0; pOperator->status = OP_RES_TO_RETURN; OPTR_SET_OPENED(pOperator); @@ -186,7 +210,8 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) { longjmp(pTaskInfo->env, code); } - SSDataBlock* pBlock = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo); + SSDataBlock* pBlock = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, + pInfo->pColMatchInfo, pInfo); if (pBlock != NULL) { pOperator->resultInfo.totalRows += pBlock->info.rows; @@ -208,10 +233,217 @@ int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* ASSERT(pOptr != NULL); SSortExecInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortExecInfo)); - SSortOperatorInfo *pOperatorInfo = (SSortOperatorInfo*)pOptr->info; + SSortOperatorInfo* pOperatorInfo = (SSortOperatorInfo*)pOptr->info; *pInfo = tsortGetSortExecInfo(pOperatorInfo->pSortHandle); *pOptrExplain = pInfo; *len = sizeof(SSortExecInfo); return TSDB_CODE_SUCCESS; } + +typedef struct SMultiwaySortMergeOperatorInfo { + SOptrBasicInfo binfo; + + int32_t bufPageSize; + uint32_t sortBufSize; // max buffer size for in-memory sort + + SArray* pSortInfo; + SSortHandle* pSortHandle; + SArray* pColMatchInfo; // for index map from table scan output + + SSDataBlock* pInputBlock; + int64_t startTs; // sort start time + + bool hasGroupId; + uint64_t groupId; + STupleHandle* prefetchedTuple; +} SMultiwaySortMergeOperatorInfo; + +int32_t doOpenMultiwaySortMergeOperator(SOperatorInfo* pOperator) { + SMultiwaySortMergeOperatorInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + if (OPTR_IS_OPENED(pOperator)) { + return TSDB_CODE_SUCCESS; + } + + pInfo->startTs = taosGetTimestampUs(); + + int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; + + pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->pColMatchInfo, SORT_MULTISOURCE_MERGE, + pInfo->bufPageSize, numOfBufPage, pInfo->pInputBlock, pTaskInfo->id.str); + + tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, NULL, NULL); + + for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) { + SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); + ps->param = pOperator->pDownstream[i]; + tsortAddSource(pInfo->pSortHandle, ps); + } + + int32_t code = tsortOpen(pInfo->pSortHandle); + + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, terrno); + } + + pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs) / 1000.0; + pOperator->status = OP_RES_TO_RETURN; + + OPTR_SET_OPENED(pOperator); + return TSDB_CODE_SUCCESS; +} + +SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, + SArray* pColMatchInfo, SMultiwaySortMergeOperatorInfo* pInfo) { + blockDataCleanup(pDataBlock); + + SSDataBlock* p = tsortGetSortedDataBlock(pHandle); + if (p == NULL) { + return NULL; + } + + blockDataEnsureCapacity(p, capacity); + + while (1) { + STupleHandle* pTupleHandle = NULL; + if (pInfo->prefetchedTuple == NULL) { + pTupleHandle = tsortNextTuple(pHandle); + } else { + pTupleHandle = pInfo->prefetchedTuple; + pInfo->groupId = tsortGetGroupId(pTupleHandle); + pInfo->prefetchedTuple = NULL; + } + + if (pTupleHandle == NULL) { + break; + } + + uint64_t tupleGroupId = tsortGetGroupId(pTupleHandle); + if (!pInfo->hasGroupId) { + pInfo->groupId = tupleGroupId; + pInfo->hasGroupId = true; + appendOneRowToDataBlock(p, pTupleHandle); + } else if (pInfo->groupId == tupleGroupId) { + appendOneRowToDataBlock(p, pTupleHandle); + } else { + pInfo->prefetchedTuple = pTupleHandle; + break; + } + + if (p->info.rows >= capacity) { + break; + } + } + + if (p->info.rows > 0) { + int32_t numOfCols = taosArrayGetSize(pColMatchInfo); + for (int32_t i = 0; i < numOfCols; ++i) { + SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, i); + ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID); + + SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId); + SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->targetSlotId); + colDataAssign(pDst, pSrc, p->info.rows); + } + + pDataBlock->info.rows = p->info.rows; + pDataBlock->info.capacity = p->info.rows; + pDataBlock->info.groupId = pInfo->groupId; + } + + blockDataDestroy(p); + return (pDataBlock->info.rows > 0) ? pDataBlock : NULL; +} + +SSDataBlock* doMultiwaySortMerge(SOperatorInfo* pOperator) { + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SMultiwaySortMergeOperatorInfo* pInfo = pOperator->info; + + int32_t code = pOperator->fpSet._openFn(pOperator); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + + SSDataBlock* pBlock = getMultiwaySortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, + pOperator->resultInfo.capacity, pInfo->pColMatchInfo, pInfo); + + if (pBlock != NULL) { + pOperator->resultInfo.totalRows += pBlock->info.rows; + } else { + doSetOperatorCompleted(pOperator); + } + return pBlock; +} + +void destroyMultiwaySortMergeOperatorInfo(void* param, int32_t numOfOutput) { + SMultiwaySortMergeOperatorInfo* pInfo = (SMultiwaySortMergeOperatorInfo*)param; + pInfo->binfo.pRes = blockDataDestroy(pInfo->binfo.pRes); + pInfo->pInputBlock = blockDataDestroy(pInfo->pInputBlock); + + taosArrayDestroy(pInfo->pSortInfo); + taosArrayDestroy(pInfo->pColMatchInfo); +} + +int32_t getMultiwaySortMergeExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) { + ASSERT(pOptr != NULL); + SSortExecInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortExecInfo)); + + SMultiwaySortMergeOperatorInfo* pOperatorInfo = (SMultiwaySortMergeOperatorInfo*)pOptr->info; + + *pInfo = tsortGetSortExecInfo(pOperatorInfo->pSortHandle); + *pOptrExplain = pInfo; + *len = sizeof(SSortExecInfo); + return TSDB_CODE_SUCCESS; +} + +SOperatorInfo* createMultiwaySortMergeOperatorInfo(SOperatorInfo** downStreams, int32_t numStreams, + SSDataBlock* pInputBlock, SSDataBlock* pResBlock, SArray* pSortInfo, + SArray* pColMatchColInfo, SExecTaskInfo* pTaskInfo) { + SMultiwaySortMergeOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SMultiwaySortMergeOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + int32_t rowSize = pResBlock->info.rowSize; + + if (pInfo == NULL || pOperator == NULL || rowSize > 100 * 1024 * 1024) { + goto _error; + } + + pInfo->binfo.pRes = pResBlock; + + initResultSizeInfo(pOperator, 1024); + + pInfo->pSortInfo = pSortInfo; + pInfo->pColMatchInfo = pColMatchColInfo; + pInfo->pInputBlock = pInputBlock; + pOperator->name = "MultiwaySortMerge"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE; + pOperator->blocking = true; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + + pInfo->bufPageSize = rowSize < 1024 ? 1024 : rowSize * 2; + pInfo->sortBufSize = pInfo->bufPageSize * 16; + pInfo->hasGroupId = false; + pInfo->prefetchedTuple = NULL; + pOperator->pTaskInfo = pTaskInfo; + pOperator->fpSet = + createOperatorFpSet(doOpenMultiwaySortMergeOperator, doMultiwaySortMerge, NULL, NULL, + destroyMultiwaySortMergeOperatorInfo, NULL, NULL, getMultiwaySortMergeExplainExecInfo); + + int32_t code = appendDownstream(pOperator, downStreams, numStreams); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + return pOperator; + +_error: + pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFree(pInfo); + taosMemoryFree(pOperator); + return NULL; +} \ No newline at end of file diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index b621d729e0..b309478556 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -1,3 +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 . + */ #include "executorimpl.h" #include "function.h" #include "functionMgt.h" @@ -9,7 +23,6 @@ typedef enum SResultTsInterpType { RESULT_ROW_END_INTERP = 2, } SResultTsInterpType; -static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator); static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator); static int64_t* extractTsCol(SSDataBlock* pBlock, const SIntervalAggOperatorInfo* pInfo); @@ -764,6 +777,22 @@ static int32_t saveResult(SResultRow* result, uint64_t groupId, SArray* pUpdated return TSDB_CODE_SUCCESS; } +static void removeResult(SArray* pUpdated, TSKEY key) { + int32_t size = taosArrayGetSize(pUpdated); + int32_t index = binarySearch(pUpdated, size, key, TSDB_ORDER_DESC, getReskey); + if (index >= 0 && key == getReskey(pUpdated, index)) { + taosArrayRemove(pUpdated, index); + } +} + +static void removeResults(SArray* pWins, SArray* pUpdated) { + int32_t size = taosArrayGetSize(pWins); + for (int32_t i = 0; i < size; i++) { + STimeWindow* pW = taosArrayGet(pWins, i); + removeResult(pUpdated, pW->skey); + } +} + static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pBlock, int32_t scanFlag, SArray* pUpdated) { SIntervalAggOperatorInfo* pInfo = (SIntervalAggOperatorInfo*)pOperatorInfo->info; @@ -1198,6 +1227,10 @@ void doClearWindow(SAggSupporter* pSup, SOptrBasicInfo* pBinfo, char* pData, int SET_RES_WINDOW_KEY(pSup->keyBuf, pData, bytes, groupId); SResultRowPosition* p1 = (SResultRowPosition*)taosHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes)); + if (!p1) { + // window has been closed + return; + } doClearWindowImpl(p1, pSup->pResultBuf, pBinfo, numOfOutput); } @@ -1349,6 +1382,7 @@ void destroyStreamFinalIntervalOperatorInfo(void* param, int32_t numOfOutput) { taosMemoryFreeClear(pChildOp); } } + nodesDestroyNode(pInfo->pPhyNode); } static bool allInvertible(SqlFunctionCtx* pFCtx, int32_t numOfCols) { @@ -1471,69 +1505,6 @@ _error: return NULL; } -SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResBlock, SInterval* pInterval, - int32_t primaryTsSlotId, STimeWindowAggSupp* pTwAggSupp, - SExecTaskInfo* pTaskInfo) { - SStreamFinalIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamFinalIntervalOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - if (pInfo == NULL || pOperator == NULL) { - goto _error; - } - pInfo->order = TSDB_ORDER_ASC; - pInfo->interval = *pInterval; - pInfo->twAggSup = *pTwAggSupp; - pInfo->primaryTsIndex = primaryTsSlotId; - size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); - int32_t code = - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, pResBlock, keyBufSize, pTaskInfo->id.str); - initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window); - if (code != TSDB_CODE_SUCCESS) { - goto _error; - } - initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)1); - int32_t numOfChild = 8; // Todo(liuyao) get it from phy plan - pInfo->pChildren = taosArrayInit(numOfChild, sizeof(SOperatorInfo)); - for (int32_t i = 0; i < numOfChild; i++) { - SSDataBlock* chRes = createOneDataBlock(pResBlock, false); - SOperatorInfo* pChildOp = createIntervalOperatorInfo(NULL, pExprInfo, numOfCols, chRes, pInterval, primaryTsSlotId, - pTwAggSupp, pTaskInfo); - if (pChildOp && chRes) { - taosArrayPush(pInfo->pChildren, &pChildOp); - continue; - } - goto _error; - } - - pOperator->name = "StreamFinalIntervalOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExprInfo; - pOperator->pTaskInfo = pTaskInfo; - pOperator->numOfExprs = numOfCols; - pOperator->info = pInfo; - - pOperator->fpSet = - createOperatorFpSet(NULL, doStreamFinalIntervalAgg, NULL, NULL, destroyStreamFinalIntervalOperatorInfo, - aggEncodeResultRow, aggDecodeResultRow, NULL); - - code = appendDownstream(pOperator, &downstream, 1); - if (code != TSDB_CODE_SUCCESS) { - goto _error; - } - - return pOperator; - -_error: - destroyStreamFinalIntervalOperatorInfo(pInfo, numOfCols); - taosMemoryFreeClear(pInfo); - taosMemoryFreeClear(pOperator); - pTaskInfo->code = code; - return NULL; -} - SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId, STimeWindowAggSupp* pTwAggSupp, SExecTaskInfo* pTaskInfo) { @@ -1822,7 +1793,7 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf pInfo->tsSlotId = tsSlotId; pOperator->name = "StateWindowOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE; pOperator->blocking = true; pOperator->status = OP_NOT_OPENED; pOperator->pExpr = pExpr; @@ -1874,7 +1845,7 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo pInfo->winSup.prevTs = INT64_MIN; pInfo->reptScan = false; pOperator->name = "SessionWindowAggOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION; pOperator->blocking = true; pOperator->status = OP_NOT_OPENED; pOperator->pExpr = pExprInfo; @@ -1899,12 +1870,12 @@ _error: return NULL; } -static SArray* doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBlock, int32_t tableGroupId) { +static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBlock, + int32_t tableGroupId, SArray* pUpdated) { SStreamFinalIntervalOperatorInfo* pInfo = (SStreamFinalIntervalOperatorInfo*)pOperatorInfo->info; SResultRowInfo* pResultRowInfo = &(pInfo->binfo.resultRowInfo); SExecTaskInfo* pTaskInfo = pOperatorInfo->pTaskInfo; int32_t numOfOutput = pOperatorInfo->numOfExprs; - SArray* pUpdated = taosArrayInit(4, POINTER_BYTES); int32_t step = 1; bool ascScan = true; TSKEY* tsCols = NULL; @@ -1915,7 +1886,7 @@ static SArray* doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataB SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex); tsCols = (int64_t*)pColDataInfo->pData; } else { - return pUpdated; + return ; } int32_t startPos = ascScan ? 0 : (pSDataBlock->info.rows - 1); @@ -1932,13 +1903,13 @@ static SArray* doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataB pos->groupId = tableGroupId; pos->pos = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset}; *(int64_t*)pos->key = pResult->win.skey; - taosArrayPush(pUpdated, &pos); - forwardRows = getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, nextWin.ekey, binarySearchForKey, NULL, - TSDB_ORDER_ASC); + forwardRows = getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, + nextWin.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC); + if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pUpdated) { + saveResult(pResult, tableGroupId, pUpdated); + } // window start(end) key interpolation - // disable it temporarily - // doWindowBorderInterpolation(pInfo, pSDataBlock, numOfOutput, pInfo->binfo.pCtx, pResult, &nextWin, startPos, - // forwardRows); + // doWindowBorderInterpolation(pInfo, pSDataBlock, numOfOutput, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardRows); updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, true); doApplyFunctions(pTaskInfo, pInfo->binfo.pCtx, &nextWin, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC); @@ -1948,7 +1919,6 @@ static SArray* doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataB break; } } - return pUpdated; } bool isFinalInterval(SStreamFinalIntervalOperatorInfo* pInfo) { return pInfo->pChildren != NULL; } @@ -1992,24 +1962,72 @@ static void rebuildIntervalWindow(SStreamFinalIntervalOperatorInfo* pInfo, SArra } } +static void clearStreamIntervalOperator(SStreamFinalIntervalOperatorInfo* pInfo) { + taosHashClear(pInfo->aggSup.pResultRowHashTable); + clearDiskbasedBuf(pInfo->aggSup.pResultBuf); + cleanupResultRowInfo(&pInfo->binfo.resultRowInfo); + initResultRowInfo(&pInfo->binfo.resultRowInfo, 1); +} + +static void clearUpdateDataBlock(SSDataBlock* pBlock) { + if (pBlock->info.rows <= 0) { + return; + } + blockDataCleanup(pBlock); +} + +static void copyUpdateDataBlock(SSDataBlock* pDest, SSDataBlock* pSource, int32_t tsColIndex) { + ASSERT(pDest->info.capacity >= pSource->info.rows); + clearUpdateDataBlock(pDest); + SColumnInfoData* pDestCol = taosArrayGet(pDest->pDataBlock, 0); + SColumnInfoData* pSourceCol = taosArrayGet(pSource->pDataBlock, tsColIndex); + // copy timestamp column + colDataAssign(pDestCol, pSourceCol, pSource->info.rows); + for (int32_t i = 1; i < pDest->info.numOfCols; i++) { + SColumnInfoData* pCol = taosArrayGet(pDest->pDataBlock, i); + colDataAppendNNULL(pCol, 0, pSource->info.rows); + } + pDest->info.rows = pSource->info.rows; + blockDataUpdateTsWindow(pDest, 0); +} + +static int32_t getChildIndex(SSDataBlock* pBlock) { + // if (pBlock->info.type != STREAM_INVALID && pBlock->info.rows < 4) { // for test + // return pBlock->info.rows - 1; + // } + return 0; +} + static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { SStreamFinalIntervalOperatorInfo* pInfo = pOperator->info; SOperatorInfo* downstream = pOperator->pDownstream[0]; - SArray* pUpdated = NULL; + SArray* pUpdated = taosArrayInit(4, POINTER_BYTES); + SArray* pClosed = taosArrayInit(4, POINTER_BYTES); if (pOperator->status == OP_EXEC_DONE) { return NULL; } else if (pOperator->status == OP_RES_TO_RETURN) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - if (pInfo->binfo.pRes->info.rows == 0 || !hashRemainDataInGroupInfo(&pInfo->groupResInfo)) { + if (pInfo->binfo.pRes->info.rows == 0) { pOperator->status = OP_EXEC_DONE; + if (isFinalInterval(pInfo) || pInfo->pUpdateRes->info.rows == 0) { + if (!isFinalInterval(pInfo)) { + // semi interval operator clear disk buffer + clearStreamIntervalOperator(pInfo); + } + return NULL; + } + // process the rest of the data + pOperator->status = OP_OPENED; + return pInfo->pUpdateRes; } - return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes; + return pInfo->binfo.pRes; } while (1) { SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); if (pBlock == NULL) { + clearUpdateDataBlock(pInfo->pUpdateRes); break; } @@ -2019,31 +2037,149 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { doClearWindows(&pInfo->aggSup, &pInfo->binfo, &pInfo->interval, pInfo->primaryTsIndex, pOperator->numOfExprs, pBlock, pUpWins); if (isFinalInterval(pInfo)) { - int32_t childIndex = 0; // Todo(liuyao) get child id from SSDataBlock + int32_t childIndex = getChildIndex(pBlock); SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, childIndex); SIntervalAggOperatorInfo* pChildInfo = pChildOp->info; - doClearWindows(&pChildInfo->aggSup, &pChildInfo->binfo, &pChildInfo->interval, pChildInfo->primaryTsIndex, - pChildOp->numOfExprs, pBlock, NULL); - rebuildIntervalWindow(pInfo, pUpWins, pInfo->binfo.pRes->info.groupId, pOperator->numOfExprs, - pOperator->pTaskInfo); + doClearWindows(&pChildInfo->aggSup, &pChildInfo->binfo, &pChildInfo->interval, + pChildInfo->primaryTsIndex, pChildOp->numOfExprs, pBlock, NULL); + rebuildIntervalWindow(pInfo, pUpWins, pInfo->binfo.pRes->info.groupId, + pOperator->numOfExprs, pOperator->pTaskInfo); + taosArrayDestroy(pUpWins); + continue; } + removeResults(pUpWins, pUpdated); + copyUpdateDataBlock(pInfo->pUpdateRes, pBlock, pInfo->primaryTsIndex); taosArrayDestroy(pUpWins); - continue; + break; } if (isFinalInterval(pInfo)) { - int32_t chIndex = 1; // Todo(liuyao) get it from SSDataBlock + int32_t chIndex = getChildIndex(pBlock); + int32_t size = taosArrayGetSize(pInfo->pChildren); + // if chIndex + 1 - size > 0, add new child + for (int32_t i = 0; i < chIndex + 1 - size; i++) { + SOperatorInfo* pChildOp = createStreamFinalIntervalOperatorInfo(NULL, pInfo->pPhyNode, pOperator->pTaskInfo, 0); + if (!pChildOp) { + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); + } + taosArrayPush(pInfo->pChildren, &pChildOp); + } SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, chIndex); - doStreamIntervalAgg(pChildOp); + SStreamFinalIntervalOperatorInfo* pChInfo = pChildOp->info; + setInputDataBlock(pChildOp, pChInfo->binfo.pCtx, pBlock, pChInfo->order, MAIN_SCAN, true); + doHashInterval(pChildOp, pBlock, pBlock->info.groupId, NULL); } - pUpdated = doHashInterval(pOperator, pBlock, 0); + doHashInterval(pOperator, pBlock, pBlock->info.groupId, pUpdated); + pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, pBlock->info.window.ekey); } + + if (isFinalInterval(pInfo)) { + closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, + &pInfo->interval, pClosed); + finalizeUpdatedResult(pOperator->numOfExprs, pInfo->aggSup.pResultBuf, pClosed, + pInfo->binfo.rowCellInfoOffset); + if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) { + taosArrayAddAll(pUpdated, pClosed); + } + } + taosArrayDestroy(pClosed); finalizeUpdatedResult(pOperator->numOfExprs, pInfo->aggSup.pResultBuf, pUpdated, pInfo->binfo.rowCellInfoOffset); initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated); blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity); doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); pOperator->status = OP_RES_TO_RETURN; - return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes; + if (pInfo->binfo.pRes->info.rows == 0) { + pOperator->status = OP_EXEC_DONE; + if (pInfo->pUpdateRes->info.rows == 0) { + return NULL; + } + // process the rest of the data + pOperator->status = OP_OPENED; + return pInfo->pUpdateRes; + } + return pInfo->binfo.pRes; +} + +SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, + SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, int32_t numOfChild) { + SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode; + SStreamFinalIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamFinalIntervalOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + if (pInfo == NULL || pOperator == NULL) { + goto _error; + } + pInfo->order = TSDB_ORDER_ASC; + pInfo->interval = (SInterval) {.interval = pIntervalPhyNode->interval, + .sliding = pIntervalPhyNode->sliding, + .intervalUnit = pIntervalPhyNode->intervalUnit, + .slidingUnit = pIntervalPhyNode->slidingUnit, + .offset = pIntervalPhyNode->offset, + .precision = + ((SColumnNode*)pIntervalPhyNode->window.pTspk)->node.resType.precision}; + pInfo->twAggSup = (STimeWindowAggSupp){.waterMark = pIntervalPhyNode->window.watermark, + .calTrigger = pIntervalPhyNode->window.triggerType, + .maxTs = INT64_MIN, + .winMap = NULL, }; + pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId; + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + initResultSizeInfo(pOperator, 4096); + int32_t numOfCols = 0; + SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &numOfCols); + SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc); + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, + pResBlock, keyBufSize, pTaskInfo->id.str); + initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)1); + pInfo->pChildren = NULL; + if (numOfChild > 0) { + pInfo->pChildren = taosArrayInit(numOfChild, sizeof(SOperatorInfo)); + for (int32_t i = 0; i < numOfChild; i++) { + SOperatorInfo* pChildOp = createStreamFinalIntervalOperatorInfo(NULL, pPhyNode, pTaskInfo, 0); + if (pChildOp) { + taosArrayPush(pInfo->pChildren, &pChildOp); + continue; + } + goto _error; + } + } + // semi interval operator does not catch result + if (!isFinalInterval(pInfo)) { + pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE; + } + pInfo->pUpdateRes = createResDataBlock(pPhyNode->pOutputDataBlockDesc);\ + pInfo->pUpdateRes->info.type = STREAM_REPROCESS; + blockDataEnsureCapacity(pInfo->pUpdateRes, 128); + pInfo->pPhyNode = nodesCloneNode(pPhyNode); + + pOperator->name = "StreamFinalIntervalOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL; + pOperator->blocking = true; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExprInfo; + pOperator->pTaskInfo = pTaskInfo; + pOperator->numOfExprs = numOfCols; + pOperator->info = pInfo; + + pOperator->fpSet = createOperatorFpSet(NULL, doStreamFinalIntervalAgg, NULL, NULL, + destroyStreamFinalIntervalOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, + NULL); + + code = appendDownstream(pOperator, &downstream, 1); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + + return pOperator; + +_error: + destroyStreamFinalIntervalOperatorInfo(pInfo, numOfCols); + taosMemoryFreeClear(pInfo); + taosMemoryFreeClear(pOperator); + pTaskInfo->code = code; + return NULL; } void destroyStreamAggSupporter(SStreamAggSupporter* pSup) { @@ -2069,12 +2205,12 @@ void destroyStreamSessionAggOperatorInfo(void* param, int32_t numOfOutput) { } } -int32_t initBiasicInfo(SOptrBasicInfo* pBasicInfo, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, - SDiskbasedBuf* pResultBuf) { +int32_t initBiasicInfo(SOptrBasicInfo* pBasicInfo, SExprInfo* pExprInfo, + int32_t numOfCols, SSDataBlock* pResultBlock) { pBasicInfo->pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pBasicInfo->rowCellInfoOffset); pBasicInfo->pRes = pResultBlock; for (int32_t i = 0; i < numOfCols; ++i) { - pBasicInfo->pCtx[i].pBuf = pResultBuf; + pBasicInfo->pCtx[i].pBuf = NULL; } return TSDB_CODE_SUCCESS; } @@ -2104,16 +2240,15 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SEx initResultSizeInfo(pOperator, 4096); - code = initSessionAggSupporter(&pInfo->streamAggSup, "StreamSessionAggOperatorInfo"); - if (code != TSDB_CODE_SUCCESS) { - goto _error; - } - - code = initBiasicInfo(&pInfo->binfo, pExprInfo, numOfCols, pResBlock, pInfo->streamAggSup.pResultBuf); + code = initBiasicInfo(&pInfo->binfo, pExprInfo, numOfCols, pResBlock); if (code != TSDB_CODE_SUCCESS) { goto _error; } pInfo->streamAggSup.resultRowSize = getResultRowSize(pInfo->binfo.pCtx, numOfCols); + code = initSessionAggSupporter(&pInfo->streamAggSup, "StreamSessionAggOperatorInfo"); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } pInfo->pDummyCtx = (SqlFunctionCtx*)taosMemoryCalloc(numOfCols, sizeof(SqlFunctionCtx)); if (pInfo->pDummyCtx == NULL) { @@ -2137,7 +2272,7 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SEx pInfo->pChildren = NULL; pOperator->name = "StreamSessionWindowAggOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION; pOperator->blocking = true; pOperator->status = OP_NOT_OPENED; pOperator->pExpr = pExprInfo; @@ -2624,7 +2759,7 @@ SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream goto _error; } pOperator->name = "StreamFinalSessionWindowAggOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION_WINDOW; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION; int32_t numOfChild = 1; // Todo(liuyao) get it from phy plan pInfo = pOperator->info; pInfo->pChildren = taosArrayInit(8, sizeof(void*)); @@ -2968,6 +3103,7 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc); int32_t tsSlotId = ((SColumnNode*)pStateNode->window.pTspk)->slotId; SColumnNode* pColNode = (SColumnNode*)((STargetNode*)pStateNode->pStateKey)->pExpr; + int32_t code = TSDB_CODE_OUT_OF_MEMORY; SStreamStateAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamStateAggOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); @@ -2988,17 +3124,18 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys .winMap = NULL, }; initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window); - int32_t code = initStateAggSupporter(&pInfo->streamAggSup, "StreamStateAggOperatorInfo"); - if (code != TSDB_CODE_SUCCESS) { - goto _error; - } - code = initBiasicInfo(&pInfo->binfo, pExprInfo, numOfCols, pResBlock, pInfo->streamAggSup.pResultBuf); + code = initBiasicInfo(&pInfo->binfo, pExprInfo, numOfCols, pResBlock); if (code != TSDB_CODE_SUCCESS) { goto _error; } pInfo->streamAggSup.resultRowSize = getResultRowSize(pInfo->binfo.pCtx, numOfCols); + code = initStateAggSupporter(&pInfo->streamAggSup, "StreamStateAggOperatorInfo"); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + pInfo->pDummyCtx = (SqlFunctionCtx*)taosMemoryCalloc(numOfCols, sizeof(SqlFunctionCtx)); if (pInfo->pDummyCtx == NULL) { goto _error; @@ -3015,7 +3152,7 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys pInfo->pChildren = NULL; pOperator->name = "StreamStateAggOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE; pOperator->blocking = true; pOperator->status = OP_NOT_OPENED; pOperator->numOfExprs = numOfCols; diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 7581836d59..ea8ded2c30 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -144,7 +144,9 @@ static int32_t doAddNewExternalMemSource(SDiskbasedBuf *pBuf, SArray* pAllSource (*sourceId) += 1; int32_t rowSize = blockDataGetSerialRowSize(pSource->src.pBlock); - int32_t numOfRows = (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(pBlock))/rowSize; // The value of numOfRows must be greater than 0, which is guaranteed by the previous memory allocation + + // The value of numOfRows must be greater than 0, which is guaranteed by the previous memory allocation + int32_t numOfRows = (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(pBlock->info.numOfCols))/rowSize; ASSERT(numOfRows > 0); return blockDataEnsureCapacity(pSource->src.pBlock, numOfRows); } @@ -225,6 +227,10 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int for (int32_t i = 0; i < cmpParam->numOfSources; ++i) { SSortSource* pSource = cmpParam->pSources[i]; pSource->src.pBlock = pHandle->fetchfp(pSource->param); + if (pSource->src.pBlock == NULL) { + pSource->src.rowIndex = -1; + ++pHandle->numOfCompletedSources; + } } } @@ -355,19 +361,32 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { SSDataBlock* pLeftBlock = pLeftSource->src.pBlock; SSDataBlock* pRightBlock = pRightSource->src.pBlock; + // first sort by block groupId + if (pLeftBlock->info.groupId != pRightBlock->info.groupId) { + return pLeftBlock->info.groupId < pRightBlock->info.groupId ? -1 : 1; + } + for(int32_t i = 0; i < pInfo->size; ++i) { SBlockOrderInfo* pOrder = TARRAY_GET_ELEM(pInfo, i); SColumnInfoData* pLeftColInfoData = TARRAY_GET_ELEM(pLeftBlock->pDataBlock, pOrder->slotId); bool leftNull = false; if (pLeftColInfoData->hasNull) { - leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, pLeftBlock->pBlockAgg[pOrder->slotId]); + if (pLeftBlock->pBlockAgg == NULL) { + leftNull = colDataIsNull_s(pLeftColInfoData, pLeftSource->src.rowIndex); + } else { + leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, pLeftBlock->pBlockAgg[i]); + } } SColumnInfoData* pRightColInfoData = 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]); + if (pLeftBlock->pBlockAgg == NULL) { + rightNull = colDataIsNull_s(pRightColInfoData, pRightSource->src.rowIndex); + } else { + rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, pRightBlock->pBlockAgg[i]); + } } if (leftNull && rightNull) { @@ -408,7 +427,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { pHandle->totalElapsed = taosGetTimestampUs() - pHandle->startTs; qDebug("%s %d rounds mergesort required to complete the sort, first-round sorted data size:%"PRIzu", sort elapsed:%"PRId64", total elapsed:%"PRId64, - pHandle->idStr, (int32_t) (sortPass + 1), getTotalBufSize(pHandle->pBuf), pHandle->sortElapsed, pHandle->totalElapsed); + pHandle->idStr, (int32_t) (sortPass + 1), pHandle->pBuf ? getTotalBufSize(pHandle->pBuf) : 0, pHandle->sortElapsed, pHandle->totalElapsed); int32_t numOfRows = blockDataGetCapacityInRow(pHandle->pDataBlock, pHandle->pageSize); blockDataEnsureCapacity(pHandle->pDataBlock, numOfRows); @@ -509,16 +528,24 @@ static int32_t createInitialSources(SSortHandle* pHandle) { if (pHandle->type == SORT_SINGLESOURCE_SORT) { SSortSource* source = taosArrayGetP(pHandle->pOrderedSource, 0); taosArrayClear(pHandle->pOrderedSource); - + + bool hasGroupId = false; + SSDataBlock* prefetchedDataBlock = NULL; + while (1) { - SSDataBlock* pBlock = pHandle->fetchfp(source->param); + SSDataBlock* pBlock = NULL; + if (prefetchedDataBlock == NULL) { + pBlock = pHandle->fetchfp(source->param); + } else { + pBlock = prefetchedDataBlock; + prefetchedDataBlock = NULL; + } + if (pBlock == NULL) { break; } - if (pHandle->pDataBlock == NULL) { - pHandle->pDataBlock = createOneDataBlock(pBlock, false); - + if (!hasGroupId) { // calculate the buffer pages according to the total available buffers. int32_t rowSize = blockDataGetRowSize(pBlock); if (rowSize * 4 > 4096) { @@ -530,29 +557,36 @@ static int32_t createInitialSources(SSortHandle* pHandle) { // todo!! pHandle->numOfPages = 1024; sortBufSize = pHandle->numOfPages * pHandle->pageSize; + + hasGroupId = true; + pHandle->pDataBlock = createOneDataBlock(pBlock, false); } - // perform the scalar function calculation before apply the sort - if (pHandle->beforeFp != NULL) { - pHandle->beforeFp(pBlock, pHandle->param); - } + if (pHandle->pDataBlock->info.groupId == pBlock->info.groupId) { + // perform the scalar function calculation before apply the sort + if (pHandle->beforeFp != NULL) { + pHandle->beforeFp(pBlock, pHandle->param); + } + // todo relocate the columns + int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock); + if (code != 0) { + return code; + } - // todo relocate the columns - int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock); - if (code != 0) { - return code; - } + size_t size = blockDataGetSize(pHandle->pDataBlock); + if (size > sortBufSize) { + // Perform the in-memory sort and then flush data in the buffer into disk. + int64_t p = taosGetTimestampUs(); + blockDataSort(pHandle->pDataBlock, pHandle->pSortInfo); - size_t size = blockDataGetSize(pHandle->pDataBlock); - if (size > sortBufSize) { - // Perform the in-memory sort and then flush data in the buffer into disk. - int64_t p = taosGetTimestampUs(); - blockDataSort(pHandle->pDataBlock, pHandle->pSortInfo); + int64_t el = taosGetTimestampUs() - p; + pHandle->sortElapsed += el; - int64_t el = taosGetTimestampUs() - p; - pHandle->sortElapsed += el; - - doAddToBuf(pHandle->pDataBlock, pHandle); + doAddToBuf(pHandle->pDataBlock, pHandle); + } + } else { + prefetchedDataBlock = pBlock; + pHandle->pDataBlock = createOneDataBlock(pBlock, false); } } @@ -697,6 +731,10 @@ void* tsortGetValue(STupleHandle* pVHandle, int32_t colIndex) { return colDataGetData(pColInfo, pVHandle->rowIndex); } +uint64_t tsortGetGroupId(STupleHandle* pVHandle) { + return pVHandle->pBlock->info.groupId; +} + SSortExecInfo tsortGetSortExecInfo(SSortHandle* pHandle) { SSortExecInfo info = {0}; diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index 68b83f4a19..3a9b94d71e 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -23,9 +23,13 @@ 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)); +int32_t dummyProcess(SqlFunctionCtx* UNUSED_PARAM(pCtx)); +int32_t dummyFinalize(SqlFunctionCtx* UNUSED_PARAM(pCtx), SSDataBlock* UNUSED_PARAM(pBlock)); + bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); -int32_t dummyProcess(SqlFunctionCtx* UNUSED_PARAM(pCtx)); int32_t functionFinalizeWithResultBuf(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, char* finalResult); int32_t combineFunction(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); @@ -67,6 +71,7 @@ bool leastSQRFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInf 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); @@ -76,7 +81,11 @@ 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); +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); @@ -97,7 +106,10 @@ int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); 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); +int32_t spreadPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); +int32_t getSpreadInfoSize(); bool getElapsedFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); bool elapsedFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); @@ -107,7 +119,10 @@ int32_t elapsedFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); bool getHistogramFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); bool histogramFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); int32_t histogramFunction(SqlFunctionCtx* pCtx); +int32_t histogramFunctionMerge(SqlFunctionCtx* pCtx); int32_t histogramFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); +int32_t histogramPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); +int32_t getHistogramInfoSize(); bool getHLLFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t hllFunction(SqlFunctionCtx* pCtx); diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index c9c63169c9..eca4587c03 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -177,13 +177,6 @@ static int32_t translatePercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - // param0 - SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0); - if (nodeType(pParamNode0) != QUERY_NODE_COLUMN) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The first parameter of PERCENTILE function can only be column"); - } - // param1 SValueNode* pValue = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 1); @@ -218,13 +211,6 @@ static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - // param0 - SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0); - if (nodeType(pParamNode0) != QUERY_NODE_COLUMN) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The first parameter of APERCENTILE function can only be column"); - } - // param1 SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1); if (nodeType(pParamNode1) != QUERY_NODE_VALUE) { @@ -265,6 +251,72 @@ static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t return TSDB_CODE_SUCCESS; } +static int32_t translateApercentileImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isPartial) { + int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList); + + if (isPartial) { + if (2 != numOfParams && 3 != numOfParams) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + // param1 + SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1); + if (nodeType(pParamNode1) != QUERY_NODE_VALUE) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + SValueNode* pValue = (SValueNode*)pParamNode1; + if (pValue->datum.i < 0 || pValue->datum.i > 100) { + return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); + } + + pValue->notReserved = true; + + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if (!IS_NUMERIC_TYPE(para1Type) || !IS_INTEGER_TYPE(para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + // param2 + if (3 == numOfParams) { + uint8_t para3Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 2))->resType.type; + if (!IS_VAR_DATA_TYPE(para3Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + SNode* pParamNode2 = nodesListGetNode(pFunc->pParameterList, 2); + if (QUERY_NODE_VALUE != nodeType(pParamNode2) || !validateApercentileAlgo((SValueNode*)pParamNode2)) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "Third parameter algorithm of apercentile must be 'default' or 't-digest'"); + } + + pValue = (SValueNode*)pParamNode2; + pValue->notReserved = true; + } + + pFunc->node.resType = (SDataType){.bytes = getApercentileMaxSize() + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}; + } else { + if (1 != numOfParams) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (TSDB_DATA_TYPE_BINARY != para1Type) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t translateApercentilePartial(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + return translateApercentileImpl(pFunc, pErrBuf, len, true); +} +static int32_t translateApercentileMerge(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + return translateApercentileImpl(pFunc, pErrBuf, len, false); +} + static int32_t translateTbnameColumn(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { // pseudo column do not need to check parameters pFunc->node.resType = @@ -284,13 +336,6 @@ static int32_t translateTop(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - // param0 - SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0); - if (nodeType(pParamNode0) != QUERY_NODE_COLUMN) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The first parameter of TOP/BOTTOM function can only be column"); - } - // param1 SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1); if (nodeType(pParamNode1) != QUERY_NODE_VALUE) { @@ -332,19 +377,40 @@ static int32_t translateSpread(SFunctionNode* pFunc, char* pErrBuf, int32_t len) return TSDB_CODE_SUCCESS; } +static int32_t translateSpreadImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isPartial) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (isPartial) { + if (!IS_NUMERIC_TYPE(paraType) && TSDB_DATA_TYPE_TIMESTAMP != paraType) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + pFunc->node.resType = (SDataType){.bytes = getSpreadInfoSize() + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}; + } else { + if (TSDB_DATA_TYPE_BINARY != paraType) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t translateSpreadPartial(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + return translateSpreadImpl(pFunc, pErrBuf, len, true); +} +static int32_t translateSpreadMerge(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + return translateSpreadImpl(pFunc, pErrBuf, len, false); +} + static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList); if (1 != numOfParams && 2 != numOfParams) { return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - // param0 - SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0); - if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The first parameter of ELAPSED function can only be column"); - } - uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; if (TSDB_DATA_TYPE_TIMESTAMP != paraType) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); @@ -410,13 +476,6 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - // param0 - SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0); - if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The first parameter of HISTOGRAM function can only be column"); - } - uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; if (!IS_NUMERIC_TYPE(colType)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); @@ -444,17 +503,63 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l return TSDB_CODE_SUCCESS; } +static int32_t translateHistogramImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isPartial) { + int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList); + if (isPartial) { + if (4 != numOfParams) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (!IS_NUMERIC_TYPE(colType)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + // param1 ~ param3 + for (int32_t i = 1; i < numOfParams; ++i) { + SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, i); + if (QUERY_NODE_VALUE != nodeType(pParamNode)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + SValueNode* pValue = (SValueNode*)pParamNode; + + pValue->notReserved = true; + } + + if (((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type != TSDB_DATA_TYPE_BINARY || + ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 2))->resType.type != TSDB_DATA_TYPE_BINARY || + ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 3))->resType.type != TSDB_DATA_TYPE_BIGINT) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType){.bytes = getHistogramInfoSize() + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}; + } else { + if (1 != numOfParams) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + if (((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type != TSDB_DATA_TYPE_BINARY) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType){.bytes = 512, .type = TSDB_DATA_TYPE_BINARY}; + } + return TSDB_CODE_SUCCESS; +} + +static int32_t translateHistogramPartial(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + return translateHistogramImpl(pFunc, pErrBuf, len, true); +} +static int32_t translateHistogramMerge(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + return translateHistogramImpl(pFunc, pErrBuf, len, false); +} + static int32_t translateHLL(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { if (1 != LIST_LENGTH(pFunc->pParameterList)) { return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0); - if (QUERY_NODE_COLUMN != nodeType(pPara)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The input parameter of HYPERLOGLOG function can only be column"); - } - pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; return TSDB_CODE_SUCCESS; } @@ -474,12 +579,6 @@ static int32_t translateStateCount(SFunctionNode* pFunc, char* pErrBuf, int32_t return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - // param0 - SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0); - if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The input parameter of STATECOUNT function can only be column"); - } uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; if (!IS_NUMERIC_TYPE(colType)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); @@ -520,12 +619,6 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32 return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - // param0 - SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0); - if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The input parameter of STATEDURATION function can only be column"); - } uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; if (!IS_NUMERIC_TYPE(colType)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); @@ -573,12 +666,6 @@ static int32_t translateCsum(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0); - if (QUERY_NODE_COLUMN != nodeType(pPara)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The input parameter of CSUM function can only be column"); - } - uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; uint8_t resType; if (!IS_NUMERIC_TYPE(colType)) { @@ -604,13 +691,6 @@ static int32_t translateMavg(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - // param0 - SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0); - if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The first parameter of MAVG function can only be column"); - } - uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; // param1 @@ -640,13 +720,6 @@ static int32_t translateSample(SFunctionNode* pFunc, char* pErrBuf, int32_t len) return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - // param0 - SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0); - if (QUERY_NODE_COLUMN != nodeType(pParamNode0)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The first parameter of SAMPLE function can only be column"); - } - SExprNode* pCol = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); uint8_t colType = pCol->resType.type; @@ -684,12 +757,6 @@ static int32_t translateTail(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - // param0 - SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0); - if (QUERY_NODE_COLUMN != nodeType(pPara)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The first parameter of TAIL function can only be column"); - } SExprNode* pCol = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); uint8_t colType = pCol->resType.type; @@ -766,13 +833,6 @@ static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - // param0 - SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0); - if (nodeType(pParamNode0) != QUERY_NODE_COLUMN) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "The first parameter of DIFF function can only be column"); - } - uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; if (!IS_SIGNED_NUMERIC_TYPE(colType) && !IS_FLOAT_TYPE(colType) && TSDB_DATA_TYPE_BOOL != colType) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); @@ -1142,9 +1202,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .processFunc = countFunction, .finalizeFunc = functionFinalize, .invertFunc = countInvertFunction, - .combineFunc = combineFunction, - // .pPartialFunc = "count", - // .pMergeFunc = "sum" + .combineFunc = combineFunction, + .pPartialFunc = "count", + .pMergeFunc = "sum" }, { .name = "sum", @@ -1157,7 +1217,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .processFunc = sumFunction, .finalizeFunc = functionFinalize, .invertFunc = sumInvertFunction, - .combineFunc = sumCombine, + .combineFunc = sumCombine, + .pPartialFunc = "sum", + .pMergeFunc = "sum" }, { .name = "min", @@ -1169,7 +1231,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .initFunc = minmaxFunctionSetup, .processFunc = minFunction, .finalizeFunc = minmaxFunctionFinalize, - .combineFunc = minCombine + .combineFunc = minCombine, + .pPartialFunc = "min", + .pMergeFunc = "min" }, { .name = "max", @@ -1181,7 +1245,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .initFunc = minmaxFunctionSetup, .processFunc = maxFunction, .finalizeFunc = minmaxFunctionFinalize, - .combineFunc = maxCombine + .combineFunc = maxCombine, + .pPartialFunc = "max", + .pMergeFunc = "max" }, { .name = "stddev", @@ -1204,7 +1270,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .initFunc = leastSQRFunctionSetup, .processFunc = leastSQRFunction, .finalizeFunc = leastSQRFinalize, - .invertFunc = leastSQRInvertFunction, + .invertFunc = NULL, + .combineFunc = leastSQRCombine, }, { .name = "avg", @@ -1226,7 +1293,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getPercentileFuncEnv, .initFunc = percentileFunctionSetup, .processFunc = percentileFunction, - .finalizeFunc = percentileFinalize + .finalizeFunc = percentileFinalize, + .invertFunc = NULL, + .combineFunc = NULL, }, { .name = "apercentile", @@ -1236,6 +1305,29 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getApercentileFuncEnv, .initFunc = apercentileFunctionSetup, .processFunc = apercentileFunction, + .finalizeFunc = apercentileFinalize, + .combineFunc = apercentileCombine, + .pPartialFunc = "_apercentile_partial", + .pMergeFunc = "_apercentile_merge" + }, + { + .name = "_apercentile_partial", + .type = FUNCTION_TYPE_APERCENTILE_PARTIAL, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateApercentilePartial, + .getEnvFunc = getApercentileFuncEnv, + .initFunc = apercentileFunctionSetup, + .processFunc = apercentileFunction, + .finalizeFunc = apercentilePartialFinalize + }, + { + .name = "_apercentile_merge", + .type = FUNCTION_TYPE_APERCENTILE_MERGE, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateApercentileMerge, + .getEnvFunc = getApercentileFuncEnv, + .initFunc = functionSetup, + .processFunc = apercentileFunctionMerge, .finalizeFunc = apercentileFinalize }, { @@ -1267,6 +1359,30 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getSpreadFuncEnv, .initFunc = spreadFunctionSetup, .processFunc = spreadFunction, + .finalizeFunc = spreadFinalize, + .pPartialFunc = "_spread_partial", + .pMergeFunc = "_spread_merge" + }, + { + .name = "_spread_partial", + .type = FUNCTION_TYPE_SPREAD_PARTIAL, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateSpreadPartial, + .dataRequiredFunc = statisDataRequired, + .getEnvFunc = getSpreadFuncEnv, + .initFunc = spreadFunctionSetup, + .processFunc = spreadFunction, + .finalizeFunc = spreadPartialFinalize + }, + { + .name = "_spread_merge", + .type = FUNCTION_TYPE_SPREAD_MERGE, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateSpreadMerge, + .dataRequiredFunc = statisDataRequired, + .getEnvFunc = getSpreadFuncEnv, + .initFunc = spreadFunctionSetup, + .processFunc = spreadFunctionMerge, .finalizeFunc = spreadFinalize }, { @@ -1299,7 +1415,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .initFunc = functionSetup, .processFunc = firstFunction, .finalizeFunc = firstLastFinalize, - .combineFunc = firstCombine, + .combineFunc = firstCombine, }, { .name = "last", @@ -1330,6 +1446,28 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .getEnvFunc = getHistogramFuncEnv, .initFunc = histogramFunctionSetup, .processFunc = histogramFunction, + .finalizeFunc = histogramFinalize, + .pPartialFunc = "_histogram_partial", + .pMergeFunc = "_histogram_merge" + }, + { + .name = "_histogram_partial", + .type = FUNCTION_TYPE_HISTOGRAM_PARTIAL, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateHistogramPartial, + .getEnvFunc = getHistogramFuncEnv, + .initFunc = histogramFunctionSetup, + .processFunc = histogramFunction, + .finalizeFunc = histogramPartialFinalize + }, + { + .name = "_histogram_merge", + .type = FUNCTION_TYPE_HISTOGRAM_MERGE, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateHistogramMerge, + .getEnvFunc = getHistogramFuncEnv, + .initFunc = functionSetup, + .processFunc = histogramFunctionMerge, .finalizeFunc = histogramFinalize }, { diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 4c7984c602..e0302f9598 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -100,6 +100,7 @@ typedef struct SPercentileInfo { typedef struct SAPercentileInfo { double result; + double percent; int8_t algo; SHistogramInfo *pHisto; TDigest *pTDigest; @@ -283,6 +284,22 @@ typedef struct SUniqueInfo { } \ } while (0) +bool dummyGetEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* UNUSED_PARAM(pEnv)) { + return true; +} + +bool dummyInit(SqlFunctionCtx* UNUSED_PARAM(pCtx), SResultRowEntryInfo* UNUSED_PARAM(pResultInfo)) { + return true; +} + +int32_t dummyProcess(SqlFunctionCtx* UNUSED_PARAM(pCtx)) { + return 0; +} + +int32_t dummyFinalize(SqlFunctionCtx* UNUSED_PARAM(pCtx), SSDataBlock* UNUSED_PARAM(pBlock)) { + return 0; +} + bool functionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { if (pResultInfo->initialized) { return false; @@ -327,10 +344,6 @@ int32_t firstCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) { return TSDB_CODE_SUCCESS; } -int32_t dummyProcess(SqlFunctionCtx* UNUSED_PARAM(pCtx)) { - return 0; -} - int32_t functionFinalizeWithResultBuf(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, char* finalResult) { int32_t slotId = pCtx->pExpr->base.resSchema.slotId; SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); @@ -602,7 +615,7 @@ int32_t sumCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) { SResultRowEntryInfo* pSResInfo = GET_RES_INFO(pSourceCtx); SSumRes* pSBuf = GET_ROWCELL_INTERBUF(pSResInfo); - + if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) { pDBuf->isum += pSBuf->isum; } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { @@ -1799,17 +1812,17 @@ int32_t leastSQRFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { param[1][1] = (double)pInfo->num; param[1][0] = param[0][1]; - param[0][0] -= param[1][0] * (param[0][1] / param[1][1]); - param[0][2] -= param[1][2] * (param[0][1] / param[1][1]); - param[0][1] = 0; - param[1][2] -= param[0][2] * (param[1][0] / param[0][0]); - param[1][0] = 0; - param[0][2] /= param[0][0]; + double param00 = param[0][0] - param[1][0] * (param[0][1] / param[1][1]); + double param02 = param[0][2] - param[1][2] * (param[0][1] / param[1][1]); + // param[0][1] = 0; + double param12 = param[1][2] - param02 * (param[1][0] / param00); + // param[1][0] = 0; + param02 /= param00; - param[1][2] /= param[1][1]; + param12 /= param[1][1]; char buf[64] = {0}; - size_t len = snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%.6lf, intercept:%.6lf}", param[0][2], param[1][2]); + size_t len = snprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{slop:%.6lf, intercept:%.6lf}", param02, param12); varDataSetLen(buf, len); colDataAppend(pCol, currentRow, buf, pResInfo->isNullRes); @@ -1822,6 +1835,27 @@ int32_t leastSQRInvertFunction(SqlFunctionCtx* pCtx) { return TSDB_CODE_SUCCESS; } +int32_t leastSQRCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) { + SResultRowEntryInfo* pDResInfo = GET_RES_INFO(pDestCtx); + SLeastSQRInfo* pDBuf = GET_ROWCELL_INTERBUF(pDResInfo); + int32_t type = pDestCtx->input.pData[0]->info.type; + double (*pDparam)[3] = pDBuf->matrix; + + SResultRowEntryInfo* pSResInfo = GET_RES_INFO(pSourceCtx); + SLeastSQRInfo* pSBuf = GET_ROWCELL_INTERBUF(pSResInfo); + double (*pSparam)[3] = pSBuf->matrix; + for (int32_t i = 0; i < pSBuf->num; i++) { + pDparam[0][0] += pDBuf->startVal * pDBuf->startVal; + pDparam[0][1] += pDBuf->startVal; + pDBuf->startVal += pDBuf->stepVal; + } + pDparam[0][2] += pSparam[0][2] + pDBuf->num * pDBuf->stepVal * pSparam[1][2]; + pDparam[1][2] += pSparam[1][2]; + pDBuf->num += pSBuf->num; + pDResInfo->numOfRes = TMAX(pDResInfo->numOfRes, pSResInfo->numOfRes); + return TSDB_CODE_SUCCESS; +} + bool getPercentileFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { pEnv->calcMemSize = sizeof(SPercentileInfo); return true; @@ -1953,6 +1987,12 @@ bool getApercentileFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { return true; } +int32_t getApercentileMaxSize() { + int32_t bytesHist = (int32_t)(sizeof(SAPercentileInfo) + sizeof(SHistogramInfo) + sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1)); + int32_t bytesDigest = (int32_t)(sizeof(SAPercentileInfo) + TDIGEST_SIZE(COMPRESSION)); + return TMAX(bytesHist, bytesDigest); +} + static int8_t getApercentileAlgo(char *algoStr) { int8_t algoType; if (strcasecmp(algoStr, "default") == 0) { @@ -1967,16 +2007,24 @@ static int8_t getApercentileAlgo(char *algoStr) { } static void buildHistogramInfo(SAPercentileInfo* pInfo) { - pInfo->pHisto = (SHistogramInfo*) ((char*) pInfo + sizeof(SAPercentileInfo)); + pInfo->pHisto = (SHistogramInfo*) ((char*)pInfo + sizeof(SAPercentileInfo)); pInfo->pHisto->elems = (SHistBin*) ((char*)pInfo->pHisto + sizeof(SHistogramInfo)); } +static void buildTDigestInfo(SAPercentileInfo* pInfo) { + pInfo->pTDigest = (TDigest*)((char*)pInfo + sizeof(SAPercentileInfo)); +} + bool apercentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { if (!functionSetup(pCtx, pResultInfo)) { return false; } SAPercentileInfo* pInfo = GET_ROWCELL_INTERBUF(pResultInfo); + + SVariant* pVal = &pCtx->param[1].param; + pInfo->percent = (pVal->nType == TSDB_DATA_TYPE_BIGINT) ? pVal->i : pVal->d; + if (pCtx->numOfParams == 2) { pInfo->algo = APERCT_ALGO_DEFAULT; } else if (pCtx->numOfParams == 3) { @@ -2041,23 +2089,87 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) { return TSDB_CODE_SUCCESS; } -int32_t apercentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { - SVariant* pVal = &pCtx->param[1].param; - double percent = (pVal->nType == TSDB_DATA_TYPE_BIGINT) ? pVal->i : pVal->d; +int32_t apercentileFunctionMerge(SqlFunctionCtx* pCtx) { + int32_t numOfElems = 0; + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + SInputColumnInfoData* pInput = &pCtx->input; + + SColumnInfoData* pCol = pInput->pData[0]; + ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY); + + SAPercentileInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo); + SAPercentileInfo* pInputInfo; + + int32_t start = pInput->startRowIndex; + for (int32_t i = start; i < pInput->numOfRows + start; ++i) { + //if (colDataIsNull_s(pCol, i)) { + // continue; + //} + numOfElems += 1; + char* data = colDataGetData(pCol, i); + + pInputInfo = (SAPercentileInfo *)varDataVal(data); + } + + pInfo->percent = pInputInfo->percent; + pInfo->algo = pInputInfo->algo; + if (pInfo->algo == APERCT_ALGO_TDIGEST) { + buildTDigestInfo(pInputInfo); + tdigestAutoFill(pInputInfo->pTDigest, COMPRESSION); + + if(pInputInfo->pTDigest->num_centroids == 0 && pInputInfo->pTDigest->num_buffered_pts == 0) { + return TSDB_CODE_SUCCESS; + } + + buildTDigestInfo(pInfo); + TDigest *pTDigest = pInfo->pTDigest; + + if(pTDigest->num_centroids <= 0) { + memcpy(pTDigest, pInputInfo->pTDigest, (size_t)TDIGEST_SIZE(COMPRESSION)); + tdigestAutoFill(pTDigest, COMPRESSION); + } else { + tdigestMerge(pTDigest, pInputInfo->pTDigest); + } + } else { + buildHistogramInfo(pInputInfo); + if (pInputInfo->pHisto->numOfElems <= 0) { + return TSDB_CODE_SUCCESS; + } + + buildHistogramInfo(pInfo); + SHistogramInfo *pHisto = pInfo->pHisto; + + if (pHisto->numOfElems <= 0) { + memcpy(pHisto, pInputInfo->pHisto, sizeof(SHistogramInfo) + sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1)); + pHisto->elems = (SHistBin*) ((char *)pHisto + sizeof(SHistogramInfo)); + } else { + pHisto->elems = (SHistBin*) ((char *)pHisto + sizeof(SHistogramInfo)); + SHistogramInfo *pRes = tHistogramMerge(pHisto, pInputInfo->pHisto, MAX_HISTOGRAM_BIN); + memcpy(pHisto, pRes, sizeof(SHistogramInfo) + sizeof(SHistBin) * MAX_HISTOGRAM_BIN); + pHisto->elems = (SHistBin*) ((char *)pHisto + sizeof(SHistogramInfo)); + tHistogramDestroy(&pRes); + } + } + + SET_VAL(pResInfo, numOfElems, 1); + return TSDB_CODE_SUCCESS; +} + +int32_t apercentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); SAPercentileInfo* pInfo = (SAPercentileInfo*)GET_ROWCELL_INTERBUF(pResInfo); if (pInfo->algo == APERCT_ALGO_TDIGEST) { if (pInfo->pTDigest->size > 0) { - pInfo->result = tdigestQuantile(pInfo->pTDigest, percent/100); + pInfo->result = tdigestQuantile(pInfo->pTDigest, pInfo->percent / 100); } else { // no need to free //setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes); return TSDB_CODE_SUCCESS; } } else { if (pInfo->pHisto->numOfElems > 0) { - double ratio[] = {percent}; + double ratio[] = {pInfo->percent}; double *res = tHistogramUniform(pInfo->pHisto, ratio, 1); pInfo->result = *res; //memcpy(pCtx->pOutput, res, sizeof(double)); @@ -2071,6 +2183,58 @@ int32_t apercentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return functionFinalize(pCtx, pBlock); } +int32_t apercentilePartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + SAPercentileInfo* pInfo = (SAPercentileInfo*)GET_ROWCELL_INTERBUF(pResInfo); + + int32_t resultBytes = getApercentileMaxSize(); + char *res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); + + if (pInfo->algo == APERCT_ALGO_TDIGEST) { + if (pInfo->pTDigest->size > 0) { + memcpy(varDataVal(res), pInfo, resultBytes); + varDataSetLen(res, resultBytes); + } else { + return TSDB_CODE_SUCCESS; + } + } else { + if (pInfo->pHisto->numOfElems > 0) { + memcpy(varDataVal(res), pInfo, resultBytes); + varDataSetLen(res, resultBytes); + } else { + return TSDB_CODE_SUCCESS; + } + } + + int32_t slotId = pCtx->pExpr->base.resSchema.slotId; + SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); + + colDataAppend(pCol, pBlock->info.rows, res, false); + + taosMemoryFree(res); + return pResInfo->numOfRes; +} + +int32_t apercentileCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) { + SResultRowEntryInfo* pDResInfo = GET_RES_INFO(pDestCtx); + SAPercentileInfo* pDBuf = GET_ROWCELL_INTERBUF(pDResInfo); + int32_t type = pDestCtx->input.pData[0]->info.type; + + SResultRowEntryInfo* pSResInfo = GET_RES_INFO(pSourceCtx); + SAPercentileInfo* pSBuf = GET_ROWCELL_INTERBUF(pSResInfo); + ASSERT(pDBuf->algo == pSBuf->algo); + if (pDBuf->algo == APERCT_ALGO_TDIGEST) { + tdigestMerge(pDBuf->pTDigest, pSBuf->pTDigest); + } else { + SHistogramInfo* pTmp = tHistogramMerge(pDBuf->pHisto, pSBuf->pHisto, MAX_HISTOGRAM_BIN); + memcpy(pDBuf->pHisto, pTmp, sizeof(SHistogramInfo) + sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1)); + pDBuf->pHisto->elems = (SHistBin*) ((char *)pDBuf->pHisto + sizeof(SHistogramInfo)); + tHistogramDestroy(&pTmp); + } + pDResInfo->numOfRes = TMAX(pDResInfo->numOfRes, pSResInfo->numOfRes); + return TSDB_CODE_SUCCESS; +} + bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { SColumnNode* pNode = nodesListGetNode(pFunc->pParameterList, 0); pEnv->calcMemSize = pNode->node.resType.bytes + sizeof(int64_t); @@ -2722,6 +2886,10 @@ bool getSpreadFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { return true; } +int32_t getSpreadInfoSize() { + return (int32_t)sizeof(SSpreadInfo); +} + bool spreadFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { if (!functionSetup(pCtx, pResultInfo)) { return false; @@ -2807,6 +2975,32 @@ _spread_over: return TSDB_CODE_SUCCESS; } +int32_t spreadFunctionMerge(SqlFunctionCtx *pCtx) { + SInputColumnInfoData* pInput = &pCtx->input; + SColumnInfoData* pCol = pInput->pData[0]; + ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY); + + SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + SSpreadInfo* pInputInfo; + + int32_t start = pInput->startRowIndex; + char* data = colDataGetData(pCol, start); + pInputInfo = (SSpreadInfo *)varDataVal(data); + + pInfo->hasResult = pInputInfo->hasResult; + if (pInputInfo->max > pInfo->max) { + pInfo->max = pInputInfo->max; + } + + if (pInputInfo->min < pInfo->min) { + pInfo->min = pInputInfo->min; + } + + SET_VAL(GET_RES_INFO(pCtx), 1, 1); + + return TSDB_CODE_SUCCESS; +} + int32_t spreadFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); if (pInfo->hasResult == true) { @@ -2815,6 +3009,24 @@ int32_t spreadFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return functionFinalize(pCtx, pBlock); } +int32_t spreadPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + int32_t resultBytes = (int32_t)sizeof(SSpreadInfo); + char *res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); + + memcpy(varDataVal(res), pInfo, resultBytes); + varDataSetLen(res, resultBytes); + + int32_t slotId = pCtx->pExpr->base.resSchema.slotId; + SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); + + colDataAppend(pCol, pBlock->info.rows, res, false); + + taosMemoryFree(res); + return pResInfo->numOfRes; +} + bool getElapsedFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { pEnv->calcMemSize = sizeof(SElapsedInfo); return true; @@ -2924,6 +3136,10 @@ int32_t elapsedFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return functionFinalize(pCtx, pBlock); } +int32_t getHistogramInfoSize() { + return (int32_t)sizeof(SHistoFuncInfo) + HISTOGRAM_MAX_BINS_NUM * sizeof(SHistoFuncBin); +} + bool getHistogramFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { pEnv->calcMemSize = sizeof(SHistoFuncInfo) + HISTOGRAM_MAX_BINS_NUM * sizeof(SHistoFuncBin); return true; @@ -3134,6 +3350,30 @@ int32_t histogramFunction(SqlFunctionCtx *pCtx) { return TSDB_CODE_SUCCESS; } +int32_t histogramFunctionMerge(SqlFunctionCtx *pCtx) { + SInputColumnInfoData* pInput = &pCtx->input; + SColumnInfoData* pCol = pInput->pData[0]; + ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY); + + SHistoFuncInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + + int32_t start = pInput->startRowIndex; + char* data = colDataGetData(pCol, start); + SHistoFuncInfo* pInputInfo = (SHistoFuncInfo *)varDataVal(data); + + pInfo->normalized = pInputInfo->normalized; + pInfo->numOfBins = pInputInfo->numOfBins; + pInfo->totalCount += pInputInfo->totalCount; + for (int32_t k = 0; k < pInfo->numOfBins; ++k) { + pInfo->bins[k].lower = pInputInfo->bins[k].lower; + pInfo->bins[k].upper = pInputInfo->bins[k].upper; + pInfo->bins[k].count += pInputInfo->bins[k].count; + } + + SET_VAL(GET_RES_INFO(pCtx), pInfo->numOfBins, pInfo->numOfBins); + return TSDB_CODE_SUCCESS; +} + int32_t histogramFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); SHistoFuncInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); @@ -3170,6 +3410,24 @@ int32_t histogramFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return pResInfo->numOfRes; } +int32_t histogramPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + SHistoFuncInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + int32_t resultBytes = getHistogramInfoSize(); + char *res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); + + memcpy(varDataVal(res), pInfo, resultBytes); + varDataSetLen(res, resultBytes); + + int32_t slotId = pCtx->pExpr->base.resSchema.slotId; + SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); + + colDataAppend(pCol, pBlock->info.rows, res, false); + + taosMemoryFree(res); + return 1; +} + bool getHLLFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { pEnv->calcMemSize = sizeof(SHLLInfo); return true; diff --git a/source/libs/index/inc/indexCache.h b/source/libs/index/inc/indexCache.h index 6e68163d74..6c95eb987b 100644 --- a/source/libs/index/inc/indexCache.h +++ b/source/libs/index/inc/indexCache.h @@ -70,7 +70,7 @@ void indexCacheBroadcast(void* cache); void indexCacheWait(void* cache); Iterate* indexCacheIteratorCreate(IndexCache* cache); -void indexCacheIteratorDestroy(Iterate* iiter); +void idxCacheIteratorDestroy(Iterate* iiter); int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid); @@ -82,7 +82,7 @@ void indexCacheUnRef(IndexCache* cache); void indexCacheDebug(IndexCache* cache); -void indexCacheDestroyImm(IndexCache* cache); +void idxCacheDestroyImm(IndexCache* cache); #ifdef __cplusplus } #endif diff --git a/source/libs/index/inc/indexComm.h b/source/libs/index/inc/indexComm.h index c338300b57..bccba98116 100644 --- a/source/libs/index/inc/indexComm.h +++ b/source/libs/index/inc/indexComm.h @@ -26,8 +26,9 @@ extern "C" { extern char JSON_COLUMN[]; extern char JSON_VALUE_DELIM; -char* indexPackJsonData(SIndexTerm* itm); -char* indexPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip); +char* idxPackJsonData(SIndexTerm* itm); +char* idxPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip); +char* idxPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip); typedef enum { MATCH, CONTINUE, BREAK } TExeCond; @@ -39,13 +40,14 @@ TExeCond tDoCompare(__compar_fn_t func, int8_t cmpType, void* a, void* b); _cache_range_compare indexGetCompare(RangeType ty); -int32_t indexConvertData(void* src, int8_t type, void** dst); -int32_t indexConvertDataToStr(void* src, int8_t type, void** dst); +int32_t idxConvertData(void* src, int8_t type, void** dst); +int32_t idxConvertDataToStr(void* src, int8_t type, void** dst); -int32_t indexGetDataByteLen(int8_t type); +int32_t idxGetDataByteLen(int8_t type); -char* indexInt2str(int64_t val, char* dst, int radix); +char* idxInt2str(int64_t val, char* dst, int radix); +int idxUidCompare(const void* a, const void* b); #ifdef __cplusplus } #endif diff --git a/source/libs/index/inc/indexFst.h b/source/libs/index/inc/indexFst.h index 0a360c1c72..6fd12c110c 100644 --- a/source/libs/index/inc/indexFst.h +++ b/source/libs/index/inc/indexFst.h @@ -29,9 +29,9 @@ extern "C" { #define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a) -typedef struct Fst Fst; -typedef struct FstNode FstNode; -typedef struct StreamWithState StreamWithState; +typedef struct Fst Fst; +typedef struct FstNode FstNode; +typedef struct FStmSt FStmSt; typedef enum { Included, Excluded, Unbounded } FstBound; @@ -40,12 +40,12 @@ typedef struct FstBoundWithData { FstBound type; } FstBoundWithData; -typedef struct FstStreamBuilder { +typedef struct FStmBuilder { Fst* fst; - AutomationCtx* aut; + FAutoCtx* aut; FstBoundWithData* min; FstBoundWithData* max; -} FstStreamBuilder, FstStreamWithStateBuilder; +} FStmBuilder, FStmStBuilder; typedef struct FstRange { uint64_t start; @@ -267,17 +267,17 @@ typedef struct Fst { Fst* fstCreate(FstSlice* data); void fstDestroy(Fst* fst); -bool fstGet(Fst* fst, FstSlice* b, Output* out); -FstNode* fstGetNode(Fst* fst, CompiledAddr); -FstNode* fstGetRoot(Fst* fst); -FstType fstGetType(Fst* fst); -CompiledAddr fstGetRootAddr(Fst* fst); -Output fstEmptyFinalOutput(Fst* fst, bool* null); -FstStreamBuilder* fstSearch(Fst* fst, AutomationCtx* ctx); +bool fstGet(Fst* fst, FstSlice* b, Output* out); +FstNode* fstGetNode(Fst* fst, CompiledAddr); +FstNode* fstGetRoot(Fst* fst); +FstType fstGetType(Fst* fst); +CompiledAddr fstGetRootAddr(Fst* fst); +Output fstEmptyFinalOutput(Fst* fst, bool* null); +FStmBuilder* fstSearch(Fst* fst, FAutoCtx* ctx); -FstStreamWithStateBuilder* fstSearchWithState(Fst* fst, AutomationCtx* ctx); +FStmStBuilder* fstSearchWithState(Fst* fst, FAutoCtx* ctx); // into stream to expand later -StreamWithState* streamBuilderIntoStream(FstStreamBuilder* sb); +FStmSt* stmBuilderIntoStm(FStmBuilder* sb); bool fstVerify(Fst* fst); @@ -293,41 +293,40 @@ typedef struct StreamState { void streamStateDestroy(void* s); -typedef struct StreamWithState { +typedef struct FStmSt { Fst* fst; - AutomationCtx* aut; + FAutoCtx* aut; SArray* inp; FstOutput emptyOutput; SArray* stack; // FstBoundWithData* endAt; -} StreamWithState; +} FStmSt; -typedef struct StreamWithStateResult { +typedef struct FStmStRslt { FstSlice data; FstOutput out; void* state; -} StreamWithStateResult; +} FStmStRslt; -StreamWithStateResult* swsResultCreate(FstSlice* data, FstOutput fOut, void* state); -void swsResultDestroy(StreamWithStateResult* result); +FStmStRslt* swsResultCreate(FstSlice* data, FstOutput fOut, void* state); +void swsResultDestroy(FStmStRslt* result); typedef void* (*StreamCallback)(void*); -StreamWithState* streamWithStateCreate(Fst* fst, AutomationCtx* automation, FstBoundWithData* min, - FstBoundWithData* max); +FStmSt* stmStCreate(Fst* fst, FAutoCtx* automation, FstBoundWithData* min, FstBoundWithData* max); -void streamWithStateDestroy(StreamWithState* sws); +void stmStDestroy(FStmSt* sws); -bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min); +bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min); -StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallback callback); +FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback); -FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut); +FStmBuilder* stmBuilderCreate(Fst* fst, FAutoCtx* aut); -void fstStreamBuilderDestroy(FstStreamBuilder* b); +void stmBuilderDestroy(FStmBuilder* b); // set up bound range // refator later: to simple code by marco -void fstStreamBuilderSetRange(FstStreamBuilder* b, FstSlice* val, RangeType type); +void stmBuilderSetRange(FStmBuilder* b, FstSlice* val, RangeType type); #ifdef __cplusplus } diff --git a/source/libs/index/inc/indexFstAutomation.h b/source/libs/index/inc/indexFstAutomation.h index 3a0f74ee76..583bbfedae 100644 --- a/source/libs/index/inc/indexFstAutomation.h +++ b/source/libs/index/inc/indexFstAutomation.h @@ -22,24 +22,24 @@ extern "C" { #include "indexFstUtil.h" #include "indexInt.h" -typedef struct AutomationCtx AutomationCtx; +typedef struct FAutoCtx FAutoCtx; typedef enum AutomationType { AUTOMATION_ALWAYS, AUTOMATION_PREFIX, AUTMMATION_MATCH } AutomationType; typedef struct StartWith { - AutomationCtx* autoSelf; + FAutoCtx* autoSelf; } StartWith; typedef struct Complement { - AutomationCtx* autoSelf; + FAutoCtx* autoSelf; } Complement; // automation -typedef struct AutomationCtx { +typedef struct FAutoCtx { AutomationType type; void* stdata; char* data; -} AutomationCtx; +} FAutoCtx; typedef enum ValueType { FST_INT, FST_CHAR, FST_ARRAY } ValueType; typedef enum StartWithStateKind { Done, Running } StartWithStateKind; @@ -60,16 +60,16 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv); void startWithStateValueDestroy(void* sv); typedef struct AutomationFunc { - void* (*start)(AutomationCtx* ctx); - bool (*isMatch)(AutomationCtx* ctx, void*); - bool (*canMatch)(AutomationCtx* ctx, void* data); - bool (*willAlwaysMatch)(AutomationCtx* ctx, void* state); - void* (*accept)(AutomationCtx* ctx, void* state, uint8_t byte); - void* (*acceptEof)(AutomationCtx* ct, void* state); + void* (*start)(FAutoCtx* ctx); + bool (*isMatch)(FAutoCtx* ctx, void*); + bool (*canMatch)(FAutoCtx* ctx, void* data); + bool (*willAlwaysMatch)(FAutoCtx* ctx, void* state); + void* (*accept)(FAutoCtx* ctx, void* state, uint8_t byte); + void* (*acceptEof)(FAutoCtx* ct, void* state); } AutomationFunc; -AutomationCtx* automCtxCreate(void* data, AutomationType atype); -void automCtxDestroy(AutomationCtx* ctx); +FAutoCtx* automCtxCreate(void* data, AutomationType atype); +void automCtxDestroy(FAutoCtx* ctx); extern AutomationFunc automFuncs[]; #ifdef __cplusplus diff --git a/source/libs/index/inc/indexInt.h b/source/libs/index/inc/indexInt.h index 24a4e99970..47f7260d3a 100644 --- a/source/libs/index/inc/indexInt.h +++ b/source/libs/index/inc/indexInt.h @@ -35,15 +35,15 @@ extern "C" { #endif // clang-format off -#define indexFatal(...) do { if (idxDebugFlag & DEBUG_FATAL) { taosPrintLog("INDEX FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while (0) -#define indexError(...) do { if (idxDebugFlag & DEBUG_ERROR) { taosPrintLog("INDEX ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while (0) -#define indexWarn(...) do { if (idxDebugFlag & DEBUG_WARN) { taosPrintLog("INDEX WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while (0) -#define indexInfo(...) do { if (idxDebugFlag & DEBUG_INFO) { taosPrintLog("INDEX ", DEBUG_INFO, 255, __VA_ARGS__); } } while (0) -#define indexDebug(...) do { if (idxDebugFlag & DEBUG_DEBUG) { taosPrintLog("INDEX ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__);} } while (0) -#define indexTrace(...) do { if (idxDebugFlag & DEBUG_TRACE) { taosPrintLog("INDEX ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__);} } while (0) +#define indexFatal(...) do { if (idxDebugFlag & DEBUG_FATAL) { taosPrintLog("IDX FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while (0) +#define indexError(...) do { if (idxDebugFlag & DEBUG_ERROR) { taosPrintLog("IDX ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while (0) +#define indexWarn(...) do { if (idxDebugFlag & DEBUG_WARN) { taosPrintLog("IDX WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while (0) +#define indexInfo(...) do { if (idxDebugFlag & DEBUG_INFO) { taosPrintLog("IDX ", DEBUG_INFO, 255, __VA_ARGS__); } } while (0) +#define indexDebug(...) do { if (idxDebugFlag & DEBUG_DEBUG) { taosPrintLog("IDX ", DEBUG_DEBUG, idxDebugFlag, __VA_ARGS__);} } while (0) +#define indexTrace(...) do { if (idxDebugFlag & DEBUG_TRACE) { taosPrintLog("IDX", DEBUG_TRACE, idxDebugFlag, __VA_ARGS__);} } while (0) // clang-format on -typedef enum { LT, LE, GT, GE } RangeType; +typedef enum { LT, LE, GT, GE, CONTAINS, EQ } RangeType; typedef enum { kTypeValue, kTypeDeletion } STermValueType; typedef struct SIndexStat { @@ -131,7 +131,7 @@ typedef struct TFileCacheKey { char* colName; int32_t nColName; } ICacheKey; -int indexFlushCacheToTFile(SIndex* sIdx, void*, bool quit); +int idxFlushCacheToTFile(SIndex* sIdx, void*, bool quit); int64_t indexAddRef(void* p); int32_t indexRemoveRef(int64_t ref); diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 058f3c1915..9b8bee5623 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -77,15 +77,15 @@ typedef struct SIdxColInfo { static TdThreadOnce isInit = PTHREAD_ONCE_INIT; // static void indexInit(); -static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* term, SArray** result); +static int idxTermSearch(SIndex* sIdx, SIndexTermQuery* term, SArray** result); -static void indexInterResultsDestroy(SArray* results); -static int indexMergeFinalResults(SArray* in, EIndexOperatorType oType, SArray* out); +static void idxInterRsltDestroy(SArray* results); +static int idxMergeFinalResults(SArray* in, EIndexOperatorType oType, SArray* out); -static int indexGenTFile(SIndex* index, IndexCache* cache, SArray* batch); +static int idxGenTFile(SIndex* index, IndexCache* cache, SArray* batch); // merge cache and tfile by opera type -static void indexMergeCacheAndTFile(SArray* result, IterateValue* icache, IterateValue* iTfv, SIdxTRslt* helper); +static void idxMergeCacheAndTFile(SArray* result, IterateValue* icache, IterateValue* iTfv, SIdxTRslt* helper); // static int32_t indexSerialTermKey(SIndexTerm* itm, char* buf); // int32_t indexSerialKey(ICacheKey* key, char* buf); @@ -221,11 +221,11 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result for (size_t i = 0; i < nQuery; i++) { SIndexTermQuery* qterm = taosArrayGet(multiQuerys->query, i); SArray* trslt = NULL; - indexTermSearch(index, qterm, &trslt); + idxTermSearch(index, qterm, &trslt); taosArrayPush(iRslts, (void*)&trslt); } - indexMergeFinalResults(iRslts, opera, result); - indexInterResultsDestroy(iRslts); + idxMergeFinalResults(iRslts, opera, result); + idxInterRsltDestroy(iRslts); return 0; } @@ -289,7 +289,7 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy tm->nColName = nColName; char* buf = NULL; - int32_t len = indexConvertDataToStr((void*)colVal, INDEX_TYPE_GET_TYPE(colType), (void**)&buf); + int32_t len = idxConvertDataToStr((void*)colVal, INDEX_TYPE_GET_TYPE(colType), (void**)&buf); assert(len != -1); tm->colVal = buf; @@ -319,7 +319,7 @@ void indexMultiTermDestroy(SIndexMultiTerm* terms) { taosArrayDestroy(terms); } -static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result) { +static int idxTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result) { SIndexTerm* term = query->term; const char* colName = term->colName; int32_t nColName = term->nColName; @@ -374,7 +374,7 @@ END: idxTRsltDestroy(tr); return -1; } -static void indexInterResultsDestroy(SArray* results) { +static void idxInterRsltDestroy(SArray* results) { if (results == NULL) { return; } @@ -387,7 +387,7 @@ static void indexInterResultsDestroy(SArray* results) { taosArrayDestroy(results); } -static int indexMergeFinalResults(SArray* in, EIndexOperatorType oType, SArray* out) { +static int idxMergeFinalResults(SArray* in, EIndexOperatorType oType, SArray* out) { // refactor, merge interResults into fResults by oType for (int i = 0; i < taosArrayGetSize(in); i--) { SArray* t = taosArrayGetP(in, i); @@ -407,7 +407,7 @@ static int indexMergeFinalResults(SArray* in, EIndexOperatorType oType, SArray* return 0; } -static void indexMayMergeTempToFinalResult(SArray* result, TFileValue* tfv, SIdxTRslt* tr) { +static void idxMayMergeTempToFinalRslt(SArray* result, TFileValue* tfv, SIdxTRslt* tr) { int32_t sz = taosArrayGetSize(result); if (sz > 0) { TFileValue* lv = taosArrayGetP(result, sz - 1); @@ -427,11 +427,11 @@ static void indexMayMergeTempToFinalResult(SArray* result, TFileValue* tfv, SIdx taosArrayPush(result, &tfv); } } -static void indexMergeCacheAndTFile(SArray* result, IterateValue* cv, IterateValue* tv, SIdxTRslt* tr) { +static void idxMergeCacheAndTFile(SArray* result, IterateValue* cv, IterateValue* tv, SIdxTRslt* tr) { char* colVal = (cv != NULL) ? cv->colVal : tv->colVal; TFileValue* tfv = tfileValueCreate(colVal); - indexMayMergeTempToFinalResult(result, tfv, tr); + idxMayMergeTempToFinalRslt(result, tfv, tr); if (cv != NULL) { uint64_t id = *(uint64_t*)taosArrayGet(cv->val, 0); @@ -446,7 +446,7 @@ static void indexMergeCacheAndTFile(SArray* result, IterateValue* cv, IterateVal taosArrayAddAll(tr->total, tv->val); } } -static void indexDestroyFinalResult(SArray* result) { +static void idxDestroyFinalRslt(SArray* result) { int32_t sz = result ? taosArrayGetSize(result) : 0; for (size_t i = 0; i < sz; i++) { TFileValue* tv = taosArrayGetP(result, i); @@ -455,7 +455,7 @@ static void indexDestroyFinalResult(SArray* result) { taosArrayDestroy(result); } -int indexFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) { +int idxFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) { if (sIdx == NULL) { return -1; } @@ -475,7 +475,7 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) { Iterate* cacheIter = indexCacheIteratorCreate(pCache); if (cacheIter == NULL) { indexError("%p immtable is empty, ignore merge opera", pCache); - indexCacheDestroyImm(pCache); + idxCacheDestroyImm(pCache); tfileReaderUnRef(pReader); atomic_store_32(&pCache->merging, 0); if (quit) { @@ -509,26 +509,26 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) { comp = 1; } if (comp == 0) { - indexMergeCacheAndTFile(result, cv, tv, tr); + idxMergeCacheAndTFile(result, cv, tv, tr); cn = cacheIter->next(cacheIter); tn = tfileIter->next(tfileIter); } else if (comp < 0) { - indexMergeCacheAndTFile(result, cv, NULL, tr); + idxMergeCacheAndTFile(result, cv, NULL, tr); cn = cacheIter->next(cacheIter); } else { - indexMergeCacheAndTFile(result, NULL, tv, tr); + idxMergeCacheAndTFile(result, NULL, tv, tr); tn = tfileIter->next(tfileIter); } } - indexMayMergeTempToFinalResult(result, NULL, tr); + idxMayMergeTempToFinalRslt(result, NULL, tr); idxTRsltDestroy(tr); - int ret = indexGenTFile(sIdx, pCache, result); - indexDestroyFinalResult(result); + int ret = idxGenTFile(sIdx, pCache, result); + idxDestroyFinalRslt(result); - indexCacheDestroyImm(pCache); + idxCacheDestroyImm(pCache); - indexCacheIteratorDestroy(cacheIter); + idxCacheIteratorDestroy(cacheIter); tfileIteratorDestroy(tfileIter); tfileReaderUnRef(pReader); @@ -578,7 +578,7 @@ static int64_t indexGetAvaialbleVer(SIndex* sIdx, IndexCache* cache) { tfileReaderUnRef(rd); return ver; } -static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { +static int idxGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { int64_t version = indexGetAvaialbleVer(sIdx, cache); indexInfo("file name version: %" PRId64 "", version); uint8_t colType = cache->type; @@ -625,7 +625,7 @@ int32_t indexSerialCacheKey(ICacheKey* key, char* buf) { char* p = buf; char tbuf[65] = {0}; - indexInt2str((int64_t)key->suid, tbuf, 0); + idxInt2str((int64_t)key->suid, tbuf, 0); SERIALIZE_STR_VAR_TO_BUF(buf, tbuf, strlen(tbuf)); SERIALIZE_VAR_TO_BUF(buf, '_', char); diff --git a/source/libs/index/src/indexCache.c b/source/libs/index/src/indexCache.c index 4e7be245ef..20cd9c8b4c 100644 --- a/source/libs/index/src/indexCache.c +++ b/source/libs/index/src/indexCache.c @@ -26,15 +26,15 @@ #define MEM_SIGNAL_QUIT MEM_THRESHOLD * 20 #define MEM_ESTIMATE_RADIO 1.5 -static void indexMemRef(MemTable* tbl); -static void indexMemUnRef(MemTable* tbl); +static void idxMemRef(MemTable* tbl); +static void idxMemUnRef(MemTable* tbl); -static void indexCacheTermDestroy(CacheTerm* ct); -static int32_t indexCacheTermCompare(const void* l, const void* r); -static int32_t indexCacheJsonTermCompare(const void* l, const void* r); -static char* indexCacheTermGet(const void* pData); +static void idxCacheTermDestroy(CacheTerm* ct); +static int32_t idxCacheTermCompare(const void* l, const void* r); +static int32_t idxCacheJsonTermCompare(const void* l, const void* r); +static char* idxCacheTermGet(const void* pData); -static MemTable* indexInternalCacheCreate(int8_t type); +static MemTable* idxInternalCacheCreate(int8_t type); static int32_t cacheSearchTerm(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s); static int32_t cacheSearchPrefix(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s); @@ -48,6 +48,7 @@ static int32_t cacheSearchRange(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STer /*comm func of compare, used in (LE/LT/GE/GT compare)*/ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s, RangeType type); static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s); +static int32_t cacheSearchEqual_JSON(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s); static int32_t cacheSearchPrefix_JSON(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s); static int32_t cacheSearchSuffix_JSON(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s); static int32_t cacheSearchRegex_JSON(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s); @@ -63,12 +64,12 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR static int32_t (*cacheSearch[][QUERY_MAX])(void* cache, SIndexTerm* ct, SIdxTRslt* tr, STermValueType* s) = { {cacheSearchTerm, cacheSearchPrefix, cacheSearchSuffix, cacheSearchRegex, cacheSearchLessThan, cacheSearchLessEqual, cacheSearchGreaterThan, cacheSearchGreaterEqual, cacheSearchRange}, - {cacheSearchTerm_JSON, cacheSearchPrefix_JSON, cacheSearchSuffix_JSON, cacheSearchRegex_JSON, + {cacheSearchEqual_JSON, cacheSearchPrefix_JSON, cacheSearchSuffix_JSON, cacheSearchRegex_JSON, cacheSearchLessThan_JSON, cacheSearchLessEqual_JSON, cacheSearchGreaterThan_JSON, cacheSearchGreaterEqual_JSON, cacheSearchRange_JSON}}; static void doMergeWork(SSchedMsg* msg); -static bool indexCacheIteratorNext(Iterate* itera); +static bool idxCacheIteratorNext(Iterate* itera); static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { if (cache == NULL) { @@ -81,7 +82,7 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTRslt* tr, STe pCt->colVal = term->colVal; pCt->version = atomic_load_64(&pCache->version); - char* key = indexCacheTermGet(pCt); + char* key = idxCacheTermGet(pCt); SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); while (tSkipListIterNext(iter)) { @@ -90,7 +91,7 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTRslt* tr, STe break; } CacheTerm* c = (CacheTerm*)SL_GET_NODE_DATA(node); - if (0 == strcmp(c->colVal, pCt->colVal)) { + if (0 == strcmp(c->colVal, pCt->colVal) && strlen(pCt->colVal) == strlen(c->colVal)) { if (c->operaType == ADD_VALUE) { INDEX_MERGE_ADD_DEL(tr->del, tr->add, c->uid) // taosArrayPush(result, &c->uid); @@ -123,18 +124,17 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt* if (cache == NULL) { return 0; } - - _cache_range_compare cmpFn = indexGetCompare(type); - MemTable* mem = cache; IndexCache* pCache = mem->pCache; + _cache_range_compare cmpFn = indexGetCompare(type); + CacheTerm* pCt = taosMemoryCalloc(1, sizeof(CacheTerm)); pCt->colVal = term->colVal; pCt->colType = term->colType; pCt->version = atomic_load_64(&pCache->version); - char* key = indexCacheTermGet(pCt); + char* key = idxCacheTermGet(pCt); SSkipListIterator* iter = tSkipListCreateIter(mem->mem); while (tSkipListIterNext(iter)) { @@ -188,10 +188,10 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr char* exBuf = NULL; if (INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) { - exBuf = indexPackJsonData(term); + exBuf = idxPackJsonData(term); pCt->colVal = exBuf; } - char* key = indexCacheTermGet(pCt); + char* key = idxCacheTermGet(pCt); SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); while (tSkipListIterNext(iter)) { @@ -221,15 +221,18 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr return TSDB_CODE_SUCCESS; } -static int32_t cacheSearchPrefix_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { - return TSDB_CODE_SUCCESS; -} static int32_t cacheSearchSuffix_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { return TSDB_CODE_SUCCESS; } static int32_t cacheSearchRegex_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { return TSDB_CODE_SUCCESS; } +static int32_t cacheSearchEqual_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { + return cacheSearchCompareFunc_JSON(cache, term, tr, s, EQ); +} +static int32_t cacheSearchPrefix_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { + return cacheSearchCompareFunc_JSON(cache, term, tr, s, CONTAINS); +} static int32_t cacheSearchLessThan_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { return cacheSearchCompareFunc_JSON(cache, term, tr, s, LT); } @@ -242,6 +245,9 @@ static int32_t cacheSearchGreaterThan_JSON(void* cache, SIndexTerm* term, SIdxTR static int32_t cacheSearchGreaterEqual_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { return cacheSearchCompareFunc_JSON(cache, term, tr, s, GE); } +static int32_t cacheSearchContain_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { + return cacheSearchCompareFunc_JSON(cache, term, tr, s, CONTAINS); +} static int32_t cacheSearchRange_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { return TSDB_CODE_SUCCESS; } @@ -263,14 +269,20 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR int8_t dType = INDEX_TYPE_GET_TYPE(term->colType); int skip = 0; char* exBuf = NULL; - - if (INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) { - exBuf = indexPackJsonDataPrefix(term, &skip); + if (type == CONTAINS) { + SIndexTerm tm = {.suid = term->suid, + .operType = term->operType, + .colType = term->colType, + .colName = term->colVal, + .nColName = term->nColVal}; + exBuf = idxPackJsonDataPrefixNoType(&tm, &skip); + pCt->colVal = exBuf; + } else { + exBuf = idxPackJsonDataPrefix(term, &skip); pCt->colVal = exBuf; } - char* key = indexCacheTermGet(pCt); + char* key = idxCacheTermGet(pCt); - // SSkipListIterator* iter = tSkipListCreateIter(mem->mem); SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); while (tSkipListIterNext(iter)) { SSkipListNode* node = tSkipListIterGet(iter); @@ -278,14 +290,22 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR break; } CacheTerm* c = (CacheTerm*)SL_GET_NODE_DATA(node); - // printf("json val: %s\n", c->colVal); - if (0 != strncmp(c->colVal, pCt->colVal, skip)) { - break; + TExeCond cond = CONTINUE; + if (type == CONTAINS) { + if (0 == strncmp(c->colVal, pCt->colVal, skip)) { + cond = MATCH; + } + } else { + if (0 != strncmp(c->colVal, pCt->colVal, skip - 1)) { + break; + } else if (0 != strncmp(c->colVal, pCt->colVal, skip)) { + continue; + } else { + char* p = taosMemoryCalloc(1, strlen(c->colVal) + 1); + memcpy(p, c->colVal, strlen(c->colVal)); + cond = cmpFn(p + skip, term->colVal, dType); + } } - char* p = taosMemoryCalloc(1, strlen(c->colVal) + 1); - memcpy(p, c->colVal, strlen(c->colVal)); - - TExeCond cond = cmpFn(p + skip, term->colVal, dType); if (cond == MATCH) { if (c->operaType == ADD_VALUE) { INDEX_MERGE_ADD_DEL(tr->del, tr->add, c->uid) @@ -299,7 +319,6 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR } else if (cond == BREAK) { break; } - taosMemoryFree(p); } taosMemoryFree(pCt); @@ -321,7 +340,7 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in return NULL; }; - cache->mem = indexInternalCacheCreate(type); + cache->mem = idxInternalCacheCreate(type); cache->mem->pCache = cache; cache->colName = INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? tstrdup(JSON_COLUMN) : tstrdup(colName); cache->type = type; @@ -344,7 +363,7 @@ void indexCacheDebug(IndexCache* cache) { taosThreadMutexLock(&cache->mtx); tbl = cache->mem; - indexMemRef(tbl); + idxMemRef(tbl); taosThreadMutexUnlock(&cache->mtx); { @@ -360,13 +379,13 @@ void indexCacheDebug(IndexCache* cache) { } tSkipListDestroyIter(iter); - indexMemUnRef(tbl); + idxMemUnRef(tbl); } { taosThreadMutexLock(&cache->mtx); tbl = cache->imm; - indexMemRef(tbl); + idxMemRef(tbl); taosThreadMutexUnlock(&cache->mtx); if (tbl != NULL) { SSkipList* slt = tbl->mem; @@ -382,7 +401,7 @@ void indexCacheDebug(IndexCache* cache) { tSkipListDestroyIter(iter); } - indexMemUnRef(tbl); + idxMemUnRef(tbl); } } @@ -407,7 +426,7 @@ void indexCacheWait(void* cache) { IndexCache* pCache = cache; taosThreadCondWait(&pCache->finished, &pCache->mtx); } -void indexCacheDestroyImm(IndexCache* cache) { +void idxCacheDestroyImm(IndexCache* cache) { if (cache == NULL) { return; } @@ -420,8 +439,8 @@ void indexCacheDestroyImm(IndexCache* cache) { taosThreadMutexUnlock(&cache->mtx); - indexMemUnRef(tbl); - indexMemUnRef(tbl); + idxMemUnRef(tbl); + idxMemUnRef(tbl); } void indexCacheDestroy(void* cache) { IndexCache* pCache = cache; @@ -429,8 +448,8 @@ void indexCacheDestroy(void* cache) { return; } - indexMemUnRef(pCache->mem); - indexMemUnRef(pCache->imm); + idxMemUnRef(pCache->mem); + idxMemUnRef(pCache->imm); taosMemoryFree(pCache->colName); taosThreadMutexDestroy(&pCache->mtx); @@ -451,20 +470,20 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) { } taosThreadMutexLock(&cache->mtx); - indexMemRef(cache->imm); + idxMemRef(cache->imm); MemTable* tbl = cache->imm; iiter->val.val = taosArrayInit(1, sizeof(uint64_t)); iiter->val.colVal = NULL; iiter->iter = tbl != NULL ? tSkipListCreateIter(tbl->mem) : NULL; - iiter->next = indexCacheIteratorNext; + iiter->next = idxCacheIteratorNext; iiter->getValue = indexCacheIteratorGetValue; taosThreadMutexUnlock(&cache->mtx); return iiter; } -void indexCacheIteratorDestroy(Iterate* iter) { +void idxCacheIteratorDestroy(Iterate* iter) { if (iter == NULL) { return; } @@ -498,7 +517,7 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) { indexCacheRef(cache); cache->imm = cache->mem; - cache->mem = indexInternalCacheCreate(cache->type); + cache->mem = idxInternalCacheCreate(cache->type); cache->mem->pCache = cache; cache->occupiedMem = 0; if (quit == false) { @@ -526,7 +545,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) { // set up key ct->colType = term->colType; if (hasJson) { - ct->colVal = indexPackJsonData(term); + ct->colVal = idxPackJsonData(term); } else { ct->colVal = (char*)taosMemoryCalloc(1, sizeof(char) * (term->nColVal + 1)); memcpy(ct->colVal, term->colVal, term->nColVal); @@ -542,9 +561,9 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) { pCache->occupiedMem += estimate; indexCacheMakeRoomForWrite(pCache); MemTable* tbl = pCache->mem; - indexMemRef(tbl); + idxMemRef(tbl); tSkipListPut(tbl->mem, (char*)ct); - indexMemUnRef(tbl); + idxMemUnRef(tbl); taosThreadMutexUnlock(&pCache->mtx); @@ -595,8 +614,8 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STe taosThreadMutexLock(&pCache->mtx); mem = pCache->mem; imm = pCache->imm; - indexMemRef(mem); - indexMemRef(imm); + idxMemRef(mem); + idxMemRef(imm); taosThreadMutexUnlock(&pCache->mtx); int ret = (mem && mem->mem) ? indexQueryMem(mem, query, result, s) : 0; @@ -605,8 +624,8 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STe ret = (imm && imm->mem) ? indexQueryMem(imm, query, result, s) : 0; } - indexMemUnRef(mem); - indexMemUnRef(imm); + idxMemUnRef(mem); + idxMemUnRef(imm); indexInfo("cache search, time cost %" PRIu64 "us", taosGetTimestampUs() - st); return ret; @@ -629,14 +648,14 @@ void indexCacheUnRef(IndexCache* cache) { } } -void indexMemRef(MemTable* tbl) { +void idxMemRef(MemTable* tbl) { if (tbl == NULL) { return; } int ref = T_REF_INC(tbl); UNUSED(ref); } -void indexMemUnRef(MemTable* tbl) { +void idxMemUnRef(MemTable* tbl) { if (tbl == NULL) { return; } @@ -648,18 +667,18 @@ void indexMemUnRef(MemTable* tbl) { } } -static void indexCacheTermDestroy(CacheTerm* ct) { +static void idxCacheTermDestroy(CacheTerm* ct) { if (ct == NULL) { return; } taosMemoryFree(ct->colVal); taosMemoryFree(ct); } -static char* indexCacheTermGet(const void* pData) { +static char* idxCacheTermGet(const void* pData) { CacheTerm* p = (CacheTerm*)pData; return (char*)p; } -static int32_t indexCacheTermCompare(const void* l, const void* r) { +static int32_t idxCacheTermCompare(const void* l, const void* r) { CacheTerm* lt = (CacheTerm*)l; CacheTerm* rt = (CacheTerm*)r; // compare colVal @@ -680,7 +699,7 @@ static int indexFindCh(char* a, char c) { } return p - a; } -static int indexCacheJsonTermCompareImpl(char* a, char* b) { +static int idxCacheJsonTermCompareImpl(char* a, char* b) { // int alen = indexFindCh(a, '&'); // int blen = indexFindCh(b, '&'); @@ -700,7 +719,7 @@ static int indexCacheJsonTermCompareImpl(char* a, char* b) { //} return 0; } -static int32_t indexCacheJsonTermCompare(const void* l, const void* r) { +static int32_t idxCacheJsonTermCompare(const void* l, const void* r) { CacheTerm* lt = (CacheTerm*)l; CacheTerm* rt = (CacheTerm*)r; // compare colVal @@ -710,16 +729,15 @@ static int32_t indexCacheJsonTermCompare(const void* l, const void* r) { } return cmp; } -static MemTable* indexInternalCacheCreate(int8_t type) { +static MemTable* idxInternalCacheCreate(int8_t type) { int ttype = INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? TSDB_DATA_TYPE_BINARY : TSDB_DATA_TYPE_BINARY; int32_t (*cmpFn)(const void* l, const void* r) = - INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? indexCacheJsonTermCompare : indexCacheTermCompare; + INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? idxCacheJsonTermCompare : idxCacheTermCompare; MemTable* tbl = taosMemoryCalloc(1, sizeof(MemTable)); - indexMemRef(tbl); + idxMemRef(tbl); if (ttype == TSDB_DATA_TYPE_BINARY || ttype == TSDB_DATA_TYPE_NCHAR) { - tbl->mem = - tSkipListCreate(MAX_SKIP_LIST_LEVEL, ttype, MAX_INDEX_KEY_LEN, cmpFn, SL_ALLOW_DUP_KEY, indexCacheTermGet); + tbl->mem = tSkipListCreate(MAX_SKIP_LIST_LEVEL, ttype, MAX_INDEX_KEY_LEN, cmpFn, SL_ALLOW_DUP_KEY, idxCacheTermGet); } return tbl; } @@ -730,9 +748,9 @@ static void doMergeWork(SSchedMsg* msg) { int quit = msg->thandle ? true : false; taosMemoryFree(msg->thandle); - indexFlushCacheToTFile(sidx, pCache, quit); + idxFlushCacheToTFile(sidx, pCache, quit); } -static bool indexCacheIteratorNext(Iterate* itera) { +static bool idxCacheIteratorNext(Iterate* itera) { SSkipListIterator* iter = itera->iter; if (iter == NULL) { return false; diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index 74b1773e87..be9243b8dd 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -48,7 +48,7 @@ char JSON_COLUMN[] = "JSON"; char JSON_VALUE_DELIM = '&'; -char* indexInt2str(int64_t val, char* dst, int radix) { +char* idxInt2str(int64_t val, char* dst, int radix) { char buffer[65] = {0}; char* p; int64_t new_val; @@ -97,6 +97,15 @@ static TExeCond tCompareGreaterEqual(void* a, void* b, int8_t type) { __compar_fn_t func = indexGetCompar(type); return tCompare(func, QUERY_GREATER_EQUAL, a, b, type); } + +static TExeCond tCompareContains(void* a, void* b, int8_t type) { + __compar_fn_t func = indexGetCompar(type); + return tCompare(func, QUERY_TERM, a, b, type); +} +static TExeCond tCompareEqual(void* a, void* b, int8_t type) { + __compar_fn_t func = indexGetCompar(type); + return tCompare(func, QUERY_TERM, a, b, type); +} TExeCond tCompare(__compar_fn_t func, int8_t cmptype, void* a, void* b, int8_t dtype) { if (dtype == TSDB_DATA_TYPE_BINARY || dtype == TSDB_DATA_TYPE_NCHAR || dtype == TSDB_DATA_TYPE_VARBINARY) { return tDoCompare(func, cmptype, a, b); @@ -181,20 +190,24 @@ TExeCond tDoCompare(__compar_fn_t func, int8_t comparType, void* a, void* b) { } case QUERY_GREATER_EQUAL: { if (ret >= 0) return MATCH; + break; } case QUERY_TERM: { if (ret == 0) return MATCH; + break; } + default: + return BREAK; } return CONTINUE; } -static TExeCond (*rangeCompare[])(void* a, void* b, int8_t type) = {tCompareLessThan, tCompareLessEqual, - tCompareGreaterThan, tCompareGreaterEqual}; +static TExeCond (*rangeCompare[])(void* a, void* b, int8_t type) = { + tCompareLessThan, tCompareLessEqual, tCompareGreaterThan, tCompareGreaterEqual, tCompareContains, tCompareEqual}; _cache_range_compare indexGetCompare(RangeType ty) { return rangeCompare[ty]; } -char* indexPackJsonData(SIndexTerm* itm) { +char* idxPackJsonData(SIndexTerm* itm) { /* * |<-----colname---->|<-----dataType---->|<--------colVal---------->| * |<-----string----->|<-----uint8_t----->|<----depend on dataType-->| @@ -222,7 +235,7 @@ char* indexPackJsonData(SIndexTerm* itm) { return buf; } -char* indexPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) { +char* idxPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) { /* * |<-----colname---->|<-----dataType---->|<--------colVal---------->| * |<-----string----->|<-----uint8_t----->|<----depend on dataType-->| @@ -249,8 +262,33 @@ char* indexPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) { return buf; } +char* idxPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip) { + /* + * |<-----colname---->|<-----dataType---->|<--------colVal---------->| + * |<-----string----->|<-----uint8_t----->|<----depend on dataType-->| + */ + uint8_t ty = INDEX_TYPE_GET_TYPE(itm->colType); -int32_t indexConvertData(void* src, int8_t type, void** dst) { + int32_t sz = itm->nColName + itm->nColVal + sizeof(uint8_t) + sizeof(JSON_VALUE_DELIM) * 2 + 1; + char* buf = (char*)taosMemoryCalloc(1, sz); + char* p = buf; + + memcpy(p, itm->colName, itm->nColName); + p += itm->nColName; + + memcpy(p, &JSON_VALUE_DELIM, sizeof(JSON_VALUE_DELIM)); + p += sizeof(JSON_VALUE_DELIM); + *skip = p - buf; + + return buf; +} + +int idxUidCompare(const void* a, const void* b) { + uint64_t l = *(uint64_t*)a; + uint64_t r = *(uint64_t*)b; + return l - r; +} +int32_t idxConvertData(void* src, int8_t type, void** dst) { int tlen = -1; switch (type) { case TSDB_DATA_TYPE_TIMESTAMP: @@ -335,44 +373,44 @@ int32_t indexConvertData(void* src, int8_t type, void** dst) { // indexMayFillNumbericData(*dst, tlen); return tlen; } -int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) { +int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { int tlen = tDataTypes[type].bytes; int32_t bufSize = 64; switch (type) { case TSDB_DATA_TYPE_TIMESTAMP: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(int64_t*)src, *dst, -1); + idxInt2str(*(int64_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_UTINYINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(uint8_t*)src, *dst, 1); + idxInt2str(*(uint8_t*)src, *dst, 1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_TINYINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(int8_t*)src, *dst, 1); + idxInt2str(*(int8_t*)src, *dst, 1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_SMALLINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(int16_t*)src, *dst, -1); + idxInt2str(*(int16_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_USMALLINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(uint16_t*)src, *dst, -1); + idxInt2str(*(uint16_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_INT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(int32_t*)src, *dst, -1); + idxInt2str(*(int32_t*)src, *dst, -1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_UINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(uint32_t*)src, *dst, 1); + idxInt2str(*(uint32_t*)src, *dst, 1); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_BIGINT: @@ -382,7 +420,7 @@ int32_t indexConvertDataToStr(void* src, int8_t type, void** dst) { break; case TSDB_DATA_TYPE_UBIGINT: *dst = taosMemoryCalloc(1, bufSize + 1); - indexInt2str(*(uint64_t*)src, *dst, 1); + idxInt2str(*(uint64_t*)src, *dst, 1); tlen = strlen(*dst); case TSDB_DATA_TYPE_FLOAT: *dst = taosMemoryCalloc(1, bufSize + 1); diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c index 2e30ca704a..e4af4a7a3f 100644 --- a/source/libs/index/src/indexFilter.c +++ b/source/libs/index/src/indexFilter.c @@ -64,6 +64,8 @@ static int32_t sifGetFuncFromSql(EOperatorType src, EIndexQueryType *dst) { *dst = QUERY_TERM; } else if (src == OP_TYPE_LIKE || src == OP_TYPE_MATCH || src == OP_TYPE_NMATCH) { *dst = QUERY_REGEX; + } else if (src == OP_TYPE_JSON_CONTAINS) { + *dst = QUERY_PREFIX; } else { return TSDB_CODE_QRY_INVALID_INPUT; } @@ -171,8 +173,8 @@ static int32_t sifInitJsonParam(SNode *node, SIFParam *param, SIFCtx *ctx) { param->colId = l->colId; param->colValType = l->node.resType.type; memcpy(param->dbName, l->dbName, sizeof(l->dbName)); - - sprintf(param->colName, "%s_%s", l->colName, r->literal); + memcpy(param->colName, r->literal, strlen(r->literal)); + // sprintf(param->colName, "%s_%s", l->colName, r->literal); param->colValType = r->typeData; return 0; // memcpy(param->colName, l->colName, sizeof(l->colName)); @@ -184,6 +186,10 @@ static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) { SIF_ERR_RET(sifGetValueFromNode(node, ¶m->condValue)); param->colId = -1; param->colValType = (uint8_t)(vn->node.resType.type); + if (vn->literal == NULL || strlen(vn->literal) == 0) { + return TSDB_CODE_QRY_INVALID_INPUT; + } + memcpy(param->colName, vn->literal, strlen(vn->literal)); break; } case QUERY_NODE_COLUMN: { @@ -235,7 +241,7 @@ static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx indexError("invalid operation node, left: %p, rigth: %p", node->pLeft, node->pRight); SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - if (node->opType == OP_TYPE_JSON_GET_VALUE || node->opType == OP_TYPE_JSON_CONTAINS) { + if (node->opType == OP_TYPE_JSON_GET_VALUE) { return code; } SIFParam *paramList = taosMemoryCalloc(nParam, sizeof(SIFParam)); @@ -335,9 +341,9 @@ static Filter sifGetFilterFunc(EIndexQueryType type, bool *reverse) { return NULL; } static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFParam *output) { - SIndexMetaArg *arg = &output->arg; - int ret = 0; + int ret = 0; + SIndexMetaArg * arg = &output->arg; EIndexQueryType qtype = 0; SIF_ERR_RET(sifGetFuncFromSql(operType, &qtype)); if (left->colValType == TSDB_DATA_TYPE_JSON) { @@ -349,7 +355,7 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP SIndexMultiTermQuery *mtm = indexMultiTermQueryCreate(MUST); indexMultiTermQueryAdd(mtm, tm, qtype); - ret = tIndexJsonSearch(arg->ivtIdx, mtm, output->result); + ret = indexJsonSearch(arg->ivtIdx, mtm, output->result); } else { bool reverse; Filter filterFunc = sifGetFilterFunc(qtype, &reverse); @@ -418,8 +424,8 @@ static int32_t sifNotMatchFunc(SIFParam *left, SIFParam *right, SIFParam *output return sifDoIndex(left, right, id, output); } static int32_t sifJsonContains(SIFParam *left, SIFParam *right, SIFParam *output) { - // return 0 - return 0; + int id = OP_TYPE_JSON_CONTAINS; + return sifDoIndex(left, right, id, output); } static int32_t sifJsonGetValue(SIFParam *left, SIFParam *rigth, SIFParam *output) { // return 0 @@ -499,9 +505,10 @@ static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) { int32_t code = 0; int32_t nParam = sifGetOperParamNum(node->opType); if (nParam <= 1) { - SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + output->status = SFLT_NOT_INDEX; + return code; } - if (node->opType == OP_TYPE_JSON_GET_VALUE || node->opType == OP_TYPE_JSON_CONTAINS) { + if (node->opType == OP_TYPE_JSON_GET_VALUE) { return code; } SIFParam *params = NULL; @@ -540,6 +547,8 @@ static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *ou } else if (node->condType == LOGIC_COND_TYPE_NOT) { // taosArrayAddAll(output->result, params[m].result); } + taosArraySort(output->result, idxUidCompare); + taosArrayRemoveDuplicate(output->result, idxUidCompare, NULL); } } else { for (int32_t m = 0; m < node->pParameterList->length; m++) { @@ -615,11 +624,11 @@ EDealRes sifCalcWalker(SNode *node, void *context) { } if (QUERY_NODE_OPERATOR == nodeType(node)) { - indexInfo("node type for index filter, type: %d", nodeType(node)); + // indexInfo("node type for index filter, type: %d", nodeType(node)); return sifWalkOper(node, ctx); } - indexError("invalid node type for index filter calculating, type:%d", nodeType(node)); + // indexError("invalid node type for index filter calculating, type:%d", nodeType(node)); ctx->code = TSDB_CODE_QRY_INVALID_INPUT; return DEAL_RES_ERROR; } diff --git a/source/libs/index/src/indexFst.c b/source/libs/index/src/indexFst.c index 892716f387..b368c6faf3 100644 --- a/source/libs/index/src/indexFst.c +++ b/source/libs/index/src/indexFst.c @@ -1087,19 +1087,19 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) { *out = tOut; return true; } -FstStreamBuilder* fstSearch(Fst* fst, AutomationCtx* ctx) { +FStmBuilder* fstSearch(Fst* fst, FAutoCtx* ctx) { // refactor later - return fstStreamBuilderCreate(fst, ctx); + return stmBuilderCreate(fst, ctx); } -StreamWithState* streamBuilderIntoStream(FstStreamBuilder* sb) { +FStmSt* stmBuilderIntoStm(FStmBuilder* sb) { if (sb == NULL) { return NULL; } - return streamWithStateCreate(sb->fst, sb->aut, sb->min, sb->max); + return stmStCreate(sb->fst, sb->aut, sb->min, sb->max); } -FstStreamWithStateBuilder* fstSearchWithState(Fst* fst, AutomationCtx* ctx) { +FStmStBuilder* fstSearchWithState(Fst* fst, FAutoCtx* ctx) { // refactor later - return fstStreamBuilderCreate(fst, ctx); + return stmBuilderCreate(fst, ctx); } FstNode* fstGetRoot(Fst* fst) { @@ -1176,9 +1176,8 @@ bool fstBoundWithDataIsIncluded(FstBoundWithData* bound) { return bound->type == void fstBoundDestroy(FstBoundWithData* bound) { taosMemoryFree(bound); } -StreamWithState* streamWithStateCreate(Fst* fst, AutomationCtx* automation, FstBoundWithData* min, - FstBoundWithData* max) { - StreamWithState* sws = taosMemoryCalloc(1, sizeof(StreamWithState)); +FStmSt* stmStCreate(Fst* fst, FAutoCtx* automation, FstBoundWithData* min, FstBoundWithData* max) { + FStmSt* sws = taosMemoryCalloc(1, sizeof(FStmSt)); if (sws == NULL) { return NULL; } @@ -1192,11 +1191,11 @@ StreamWithState* streamWithStateCreate(Fst* fst, AutomationCtx* automation, FstB sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState)); sws->endAt = max; - streamWithStateSeekMin(sws, min); + stmStSeekMin(sws, min); return sws; } -void streamWithStateDestroy(StreamWithState* sws) { +void stmStDestroy(FStmSt* sws) { if (sws == NULL) { return; } @@ -1207,8 +1206,8 @@ void streamWithStateDestroy(StreamWithState* sws) { taosMemoryFree(sws); } -bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min) { - AutomationCtx* aut = sws->aut; +bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { + FAutoCtx* aut = sws->aut; if (fstBoundWithDataIsEmpty(min)) { if (fstBoundWithDataIsIncluded(min)) { sws->emptyOutput.out = fstEmptyFinalOutput(sws->fst, &(sws->emptyOutput.null)); @@ -1301,9 +1300,9 @@ bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min) { return false; } -StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallback callback) { - AutomationCtx* aut = sws->aut; - FstOutput output = sws->emptyOutput; +FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) { + FAutoCtx* aut = sws->aut; + FstOutput output = sws->emptyOutput; if (output.null == false) { FstSlice emptySlice = fstSliceCreate(NULL, 0); if (fstBoundWithDataExceededBy(sws->endAt, &emptySlice)) { @@ -1367,8 +1366,8 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb return NULL; } if (FST_NODE_IS_FINAL(nextNode) && isMatch) { - FstOutput fOutput = {.null = false, .out = out + FST_NODE_FINAL_OUTPUT(nextNode)}; - StreamWithStateResult* result = swsResultCreate(&slice, fOutput, tState); + FstOutput fOutput = {.null = false, .out = out + FST_NODE_FINAL_OUTPUT(nextNode)}; + FStmStRslt* result = swsResultCreate(&slice, fOutput, tState); taosMemoryFreeClear(buf); fstSliceDestroy(&slice); taosArrayDestroy(nodes); @@ -1382,8 +1381,8 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb return NULL; } -StreamWithStateResult* swsResultCreate(FstSlice* data, FstOutput fOut, void* state) { - StreamWithStateResult* result = taosMemoryCalloc(1, sizeof(StreamWithStateResult)); +FStmStRslt* swsResultCreate(FstSlice* data, FstOutput fOut, void* state) { + FStmStRslt* result = taosMemoryCalloc(1, sizeof(FStmStRslt)); if (result == NULL) { return NULL; } @@ -1393,7 +1392,7 @@ StreamWithStateResult* swsResultCreate(FstSlice* data, FstOutput fOut, void* sta result->state = state; return result; } -void swsResultDestroy(StreamWithStateResult* result) { +void swsResultDestroy(FStmStRslt* result) { if (NULL == result) { return; } @@ -1411,8 +1410,8 @@ void streamStateDestroy(void* s) { fstNodeDestroy(ss->node); } -FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut) { - FstStreamBuilder* b = taosMemoryCalloc(1, sizeof(FstStreamBuilder)); +FStmBuilder* stmBuilderCreate(Fst* fst, FAutoCtx* aut) { + FStmBuilder* b = taosMemoryCalloc(1, sizeof(FStmBuilder)); if (NULL == b) { return NULL; } @@ -1423,14 +1422,14 @@ FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut) { b->max = fstBoundStateCreate(Unbounded, NULL); return b; } -void fstStreamBuilderDestroy(FstStreamBuilder* b) { +void stmBuilderDestroy(FStmBuilder* b) { fstSliceDestroy(&b->min->data); fstSliceDestroy(&b->max->data); taosMemoryFreeClear(b->min); taosMemoryFreeClear(b->max); taosMemoryFree(b); } -void fstStreamBuilderSetRange(FstStreamBuilder* b, FstSlice* val, RangeType type) { +void stmBuilderSetRange(FStmBuilder* b, FstSlice* val, RangeType type) { if (b == NULL) { return; } diff --git a/source/libs/index/src/indexFstAutomation.c b/source/libs/index/src/indexFstAutomation.c index 0702e3b94e..385e832763 100644 --- a/source/libs/index/src/indexFstAutomation.c +++ b/source/libs/index/src/indexFstAutomation.c @@ -71,19 +71,19 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv) { } // iterate fst -static void* alwaysMatchStart(AutomationCtx* ctx) { return NULL; } -static bool alwaysMatchIsMatch(AutomationCtx* ctx, void* state) { return true; } -static bool alwaysMatchCanMatch(AutomationCtx* ctx, void* state) { return true; } -static bool alwaysMatchWillAlwaysMatch(AutomationCtx* ctx, void* state) { return true; } -static void* alwaysMatchAccpet(AutomationCtx* ctx, void* state, uint8_t byte) { return NULL; } -static void* alwaysMatchAccpetEof(AutomationCtx* ctx, void* state) { return NULL; } +static void* alwaysMatchStart(FAutoCtx* ctx) { return NULL; } +static bool alwaysMatchIsMatch(FAutoCtx* ctx, void* state) { return true; } +static bool alwaysMatchCanMatch(FAutoCtx* ctx, void* state) { return true; } +static bool alwaysMatchWillAlwaysMatch(FAutoCtx* ctx, void* state) { return true; } +static void* alwaysMatchAccpet(FAutoCtx* ctx, void* state, uint8_t byte) { return NULL; } +static void* alwaysMatchAccpetEof(FAutoCtx* ctx, void* state) { return NULL; } // prefix query, impl later -static void* prefixStart(AutomationCtx* ctx) { +static void* prefixStart(FAutoCtx* ctx) { StartWithStateValue* data = (StartWithStateValue*)(ctx->stdata); return startWithStateValueDump(data); }; -static bool prefixIsMatch(AutomationCtx* ctx, void* sv) { +static bool prefixIsMatch(FAutoCtx* ctx, void* sv) { StartWithStateValue* ssv = (StartWithStateValue*)sv; if (ssv == NULL) { return false; @@ -94,15 +94,15 @@ static bool prefixIsMatch(AutomationCtx* ctx, void* sv) { return false; } } -static bool prefixCanMatch(AutomationCtx* ctx, void* sv) { +static bool prefixCanMatch(FAutoCtx* ctx, void* sv) { StartWithStateValue* ssv = (StartWithStateValue*)sv; if (ssv == NULL) { return false; } return ssv->val >= 0; } -static bool prefixWillAlwaysMatch(AutomationCtx* ctx, void* state) { return true; } -static void* prefixAccept(AutomationCtx* ctx, void* state, uint8_t byte) { +static bool prefixWillAlwaysMatch(FAutoCtx* ctx, void* state) { return true; } +static void* prefixAccept(FAutoCtx* ctx, void* state, uint8_t byte) { StartWithStateValue* ssv = (StartWithStateValue*)state; if (ssv == NULL || ctx == NULL) { return NULL; @@ -125,18 +125,18 @@ static void* prefixAccept(AutomationCtx* ctx, void* state, uint8_t byte) { } return NULL; } -static void* prefixAcceptEof(AutomationCtx* ctx, void* state) { return NULL; } +static void* prefixAcceptEof(FAutoCtx* ctx, void* state) { return NULL; } // pattern query, impl later -static void* patternStart(AutomationCtx* ctx) { return NULL; } -static bool patternIsMatch(AutomationCtx* ctx, void* data) { return true; } -static bool patternCanMatch(AutomationCtx* ctx, void* data) { return true; } -static bool patternWillAlwaysMatch(AutomationCtx* ctx, void* state) { return true; } +static void* patternStart(FAutoCtx* ctx) { return NULL; } +static bool patternIsMatch(FAutoCtx* ctx, void* data) { return true; } +static bool patternCanMatch(FAutoCtx* ctx, void* data) { return true; } +static bool patternWillAlwaysMatch(FAutoCtx* ctx, void* state) { return true; } -static void* patternAccept(AutomationCtx* ctx, void* state, uint8_t byte) { return NULL; } +static void* patternAccept(FAutoCtx* ctx, void* state, uint8_t byte) { return NULL; } -static void* patternAcceptEof(AutomationCtx* ctx, void* state) { return NULL; } +static void* patternAcceptEof(FAutoCtx* ctx, void* state) { return NULL; } AutomationFunc automFuncs[] = { {alwaysMatchStart, alwaysMatchIsMatch, alwaysMatchCanMatch, alwaysMatchWillAlwaysMatch, alwaysMatchAccpet, @@ -146,8 +146,8 @@ AutomationFunc automFuncs[] = { // add more search type }; -AutomationCtx* automCtxCreate(void* data, AutomationType atype) { - AutomationCtx* ctx = taosMemoryCalloc(1, sizeof(AutomationCtx)); +FAutoCtx* automCtxCreate(void* data, AutomationType atype) { + FAutoCtx* ctx = taosMemoryCalloc(1, sizeof(FAutoCtx)); if (ctx == NULL) { return NULL; } @@ -169,7 +169,7 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) { ctx->stdata = (void*)sv; return ctx; } -void automCtxDestroy(AutomationCtx* ctx) { +void automCtxDestroy(FAutoCtx* ctx) { startWithStateValueDestroy(ctx->stdata); taosMemoryFree(ctx->data); taosMemoryFree(ctx); diff --git a/source/libs/index/src/indexJson.c b/source/libs/index/src/indexJson.c index a2f0563d47..88b3d907bb 100644 --- a/source/libs/index/src/indexJson.c +++ b/source/libs/index/src/indexJson.c @@ -15,30 +15,46 @@ #include "index.h" #include "indexInt.h" -int tIndexJsonOpen(SIndexJsonOpts *opts, const char *path, SIndexJson **index) { +int indexJsonOpen(SIndexJsonOpts *opts, const char *path, SIndexJson **index) { // handle return indexOpen(opts, path, index); } -int tIndexJsonPut(SIndexJson *index, SIndexJsonMultiTerm *terms, uint64_t uid) { +int indexJsonPut(SIndexJson *index, SIndexJsonMultiTerm *terms, uint64_t uid) { for (int i = 0; i < taosArrayGetSize(terms); i++) { SIndexJsonTerm *p = taosArrayGetP(terms, i); + if (p->colType == TSDB_DATA_TYPE_BOOL) { + p->colType = TSDB_DATA_TYPE_INT; + } else if (p->colType == TSDB_DATA_TYPE_VARCHAR || p->colType == TSDB_DATA_TYPE_NCHAR || + p->colType == TSDB_DATA_TYPE_BINARY) { + // p->colType = TSDB_DATA_TYPE_NCHAR; + } else { + p->colType = TSDB_DATA_TYPE_DOUBLE; + } INDEX_TYPE_ADD_EXTERN_TYPE(p->colType, TSDB_DATA_TYPE_JSON); } // handle put return indexPut(index, terms, uid); } -int tIndexJsonSearch(SIndexJson *index, SIndexJsonMultiTermQuery *tq, SArray *result) { +int indexJsonSearch(SIndexJson *index, SIndexJsonMultiTermQuery *tq, SArray *result) { SArray *terms = tq->query; for (int i = 0; i < taosArrayGetSize(terms); i++) { SIndexJsonTerm *p = taosArrayGetP(terms, i); + if (p->colType == TSDB_DATA_TYPE_BOOL) { + p->colType = TSDB_DATA_TYPE_INT; + } else if (p->colType == TSDB_DATA_TYPE_VARCHAR || p->colType == TSDB_DATA_TYPE_NCHAR || + p->colType == TSDB_DATA_TYPE_BINARY) { + // p->colType = TSDB_DATA_TYPE_NCHAR; + } else { + p->colType = TSDB_DATA_TYPE_DOUBLE; + } INDEX_TYPE_ADD_EXTERN_TYPE(p->colType, TSDB_DATA_TYPE_JSON); } // handle search return indexSearch(index, tq, result); } -void tIndexJsonClose(SIndexJson *index) { +void indexJsonClose(SIndexJson *index) { // handle close return indexClose(index); } diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 53dd2923ac..b64db1dde4 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -26,15 +26,14 @@ const static uint64_t tfileMagicNumber = 0xdb4775248b80fb57ull; typedef struct TFileFstIter { - FstStreamBuilder* fb; - StreamWithState* st; - AutomationCtx* ctx; - TFileReader* rdr; + FStmBuilder* fb; + FStmSt* st; + FAutoCtx* ctx; + TFileReader* rdr; } TFileFstIter; #define TF_TABLE_TATOAL_SIZE(sz) (sizeof(sz) + sz * sizeof(uint64_t)) -static int tfileUidCompare(const void* a, const void* b); static int tfileStrCompare(const void* a, const void* b); static int tfileValueCompare(const void* a, const void* b, const void* param); static void tfileSerialTableIdsToBuf(char* buf, SArray* tableIds); @@ -73,6 +72,7 @@ static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTRslt* tr); static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTRslt* tr, RangeType ctype); static int32_t tfSearchTerm_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr); +static int32_t tfSearchEqual_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr); static int32_t tfSearchPrefix_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr); static int32_t tfSearchSuffix_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr); static int32_t tfSearchRegex_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr); @@ -87,7 +87,7 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt static int32_t (*tfSearch[][QUERY_MAX])(void* reader, SIndexTerm* tem, SIdxTRslt* tr) = { {tfSearchTerm, tfSearchPrefix, tfSearchSuffix, tfSearchRegex, tfSearchLessThan, tfSearchLessEqual, tfSearchGreaterThan, tfSearchGreaterEqual, tfSearchRange}, - {tfSearchTerm_JSON, tfSearchPrefix_JSON, tfSearchSuffix_JSON, tfSearchRegex_JSON, tfSearchLessThan_JSON, + {tfSearchEqual_JSON, tfSearchPrefix_JSON, tfSearchSuffix_JSON, tfSearchRegex_JSON, tfSearchLessThan_JSON, tfSearchLessEqual_JSON, tfSearchGreaterThan_JSON, tfSearchGreaterEqual_JSON, tfSearchRange_JSON}}; TFileCache* tfileCacheCreate(const char* path) { @@ -244,26 +244,21 @@ static int32_t tfSearchTerm(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { } static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { - bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON); char* p = tem->colVal; uint64_t sz = tem->nColVal; - if (hasJson) { - p = indexPackJsonData(tem); - sz = strlen(p); - } SArray* offsets = taosArrayInit(16, sizeof(uint64_t)); - AutomationCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX); - FstStreamBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx); - StreamWithState* st = streamBuilderIntoStream(sb); - StreamWithStateResult* rt = NULL; - while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { + FAutoCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX); + FStmBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx); + FStmSt* st = stmBuilderIntoStm(sb); + FStmStRslt* rt = NULL; + while ((rt = stmStNextWith(st, NULL)) != NULL) { taosArrayPush(offsets, &(rt->out.out)); swsResultDestroy(rt); } - streamWithStateDestroy(st); - fstStreamBuilderDestroy(sb); + stmStDestroy(st); + stmBuilderDestroy(sb); int32_t ret = 0; for (int i = 0; i < taosArrayGetSize(offsets); i++) { @@ -274,27 +269,14 @@ static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { return TSDB_CODE_TDB_FILE_CORRUPTED; } } - if (hasJson) { - taosMemoryFree(p); - } return 0; } static int32_t tfSearchSuffix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { - bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON); - int ret = 0; char* p = tem->colVal; uint64_t sz = tem->nColVal; - if (hasJson) { - p = indexPackJsonData(tem); - sz = strlen(p); - } int64_t st = taosGetTimestampUs(); FstSlice key = fstSliceCreate(p, sz); - /*impl later*/ - if (hasJson) { - taosMemoryFree(p); - } fstSliceDestroy(&key); return 0; } @@ -305,7 +287,7 @@ static int32_t tfSearchRegex(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { char* p = tem->colVal; uint64_t sz = tem->nColVal; if (hasJson) { - p = indexPackJsonData(tem); + p = idxPackJsonData(tem); sz = strlen(p); } int64_t st = taosGetTimestampUs(); @@ -327,16 +309,16 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTRslt* tr, SArray* offsets = taosArrayInit(16, sizeof(uint64_t)); - AutomationCtx* ctx = automCtxCreate((void*)p, AUTOMATION_ALWAYS); - FstStreamBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx); + FAutoCtx* ctx = automCtxCreate((void*)p, AUTOMATION_ALWAYS); + FStmBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx); FstSlice h = fstSliceCreate((uint8_t*)p, skip); - fstStreamBuilderSetRange(sb, &h, type); + stmBuilderSetRange(sb, &h, type); fstSliceDestroy(&h); - StreamWithState* st = streamBuilderIntoStream(sb); - StreamWithStateResult* rt = NULL; - while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { + FStmSt* st = stmBuilderIntoStm(sb); + FStmStRslt* rt = NULL; + while ((rt = stmStNextWith(st, NULL)) != NULL) { FstSlice* s = &rt->data; char* ch = (char*)fstSliceData(s, NULL); // if (0 != strncmp(ch, tem->colName, tem->nColName)) { @@ -354,8 +336,8 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTRslt* tr, } swsResultDestroy(rt); } - streamWithStateDestroy(st); - fstStreamBuilderDestroy(sb); + stmStDestroy(st); + stmBuilderDestroy(sb); return TSDB_CODE_SUCCESS; } static int32_t tfSearchLessThan(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { @@ -371,37 +353,17 @@ static int32_t tfSearchGreaterEqual(void* reader, SIndexTerm* tem, SIdxTRslt* tr return tfSearchCompareFunc(reader, tem, tr, GE); } static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { - bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON); int ret = 0; char* p = tem->colVal; uint64_t sz = tem->nColVal; - if (hasJson) { - p = indexPackJsonData(tem); - sz = strlen(p); - } int64_t st = taosGetTimestampUs(); FstSlice key = fstSliceCreate(p, sz); - // uint64_t offset; - // if (fstGet(((TFileReader*)reader)->fst, &key, &offset)) { - // int64_t et = taosGetTimestampUs(); - // int64_t cost = et - st; - // indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex, time cost: %" PRIu64 "us", - // tem->suid, tem->colName, tem->colVal, cost); - - // ret = tfileReaderLoadTableIds((TFileReader*)reader, offset, tr->total); - // cost = taosGetTimestampUs() - et; - // indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", tem->suid, - // tem->colName, tem->colVal, cost); - //} - if (hasJson) { - taosMemoryFree(p); - } fstSliceDestroy(&key); return 0; } static int32_t tfSearchTerm_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { int ret = 0; - char* p = indexPackJsonData(tem); + char* p = idxPackJsonData(tem); int sz = strlen(p); int64_t st = taosGetTimestampUs(); @@ -421,12 +383,12 @@ static int32_t tfSearchTerm_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { } fstSliceDestroy(&key); return 0; - // deprecate api - return TSDB_CODE_SUCCESS; +} +static int32_t tfSearchEqual_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { + return tfSearchCompareFunc_JSON(reader, tem, tr, EQ); } static int32_t tfSearchPrefix_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { - // impl later - return TSDB_CODE_SUCCESS; + return tfSearchCompareFunc_JSON(reader, tem, tr, CONTAINS); } static int32_t tfSearchSuffix_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { // impl later @@ -457,36 +419,46 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt int ret = 0; int skip = 0; - char* p = indexPackJsonDataPrefix(tem, &skip); + char* p = NULL; + if (ctype == CONTAINS) { + SIndexTerm tm = {.suid = tem->suid, + .operType = tem->operType, + .colType = tem->colType, + .colName = tem->colVal, + .nColName = tem->nColVal}; + p = idxPackJsonDataPrefixNoType(&tm, &skip); + } else { + p = idxPackJsonDataPrefix(tem, &skip); + } _cache_range_compare cmpFn = indexGetCompare(ctype); SArray* offsets = taosArrayInit(16, sizeof(uint64_t)); - AutomationCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX); - FstStreamBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx); + FAutoCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX); + FStmBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx); - // FstSlice h = fstSliceCreate((uint8_t*)p, skip); - // fstStreamBuilderSetRange(sb, &h, ctype); - // fstSliceDestroy(&h); - - StreamWithState* st = streamBuilderIntoStream(sb); - StreamWithStateResult* rt = NULL; - while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { + FStmSt* st = stmBuilderIntoStm(sb); + FStmStRslt* rt = NULL; + while ((rt = stmStNextWith(st, NULL)) != NULL) { FstSlice* s = &rt->data; - int32_t sz = 0; - char* ch = (char*)fstSliceData(s, &sz); - char* tmp = taosMemoryCalloc(1, sz + 1); - memcpy(tmp, ch, sz); - - if (0 != strncmp(tmp, p, skip)) { - swsResultDestroy(rt); - taosMemoryFree(tmp); - break; + int32_t sz = 0; + char* ch = (char*)fstSliceData(s, &sz); + TExeCond cond = CONTINUE; + if (ctype == CONTAINS) { + if (0 == strncmp(ch, p, skip)) { + cond = MATCH; + } + } else { + if (0 != strncmp(ch, p, skip - 1)) { + swsResultDestroy(rt); + break; + } else if (0 != strncmp(ch, p, skip)) { + continue; + } + cond = cmpFn(ch + skip, tem->colVal, INDEX_TYPE_GET_TYPE(tem->colType)); } - - TExeCond cond = cmpFn(tmp + skip, tem->colVal, INDEX_TYPE_GET_TYPE(tem->colType)); if (MATCH == cond) { tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total); } else if (CONTINUE == cond) { @@ -494,11 +466,10 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt swsResultDestroy(rt); break; } - taosMemoryFree(tmp); swsResultDestroy(rt); } - streamWithStateDestroy(st); - fstStreamBuilderDestroy(sb); + stmStDestroy(st); + stmBuilderDestroy(sb); return TSDB_CODE_SUCCESS; } int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTRslt* tr) { @@ -583,8 +554,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // ugly code, refactor later for (size_t i = 0; i < sz; i++) { TFileValue* v = taosArrayGetP((SArray*)data, i); - taosArraySort(v->tableId, tfileUidCompare); - taosArrayRemoveDuplicate(v->tableId, tfileUidCompare, NULL); + taosArraySort(v->tableId, idxUidCompare); + taosArrayRemoveDuplicate(v->tableId, idxUidCompare, NULL); int32_t tbsz = taosArrayGetSize(v->tableId); fstOffset += TF_TABLE_TATOAL_SIZE(tbsz); } @@ -709,8 +680,8 @@ static bool tfileIteratorNext(Iterate* iiter) { char* colVal = NULL; uint64_t offset = 0; - TFileFstIter* tIter = iiter->iter; - StreamWithStateResult* rt = streamWithStateNextWith(tIter->st, NULL); + TFileFstIter* tIter = iiter->iter; + FStmStRslt* rt = stmStNextWith(tIter->st, NULL); if (rt == NULL) { return false; } @@ -744,7 +715,7 @@ static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) { iter->ctx = automCtxCreate(NULL, AUTOMATION_ALWAYS); iter->fb = fstSearch(reader->fst, iter->ctx); - iter->st = streamBuilderIntoStream(iter->fb); + iter->st = stmBuilderIntoStm(iter->fb); iter->rdr = reader; return iter; } @@ -775,8 +746,8 @@ void tfileIteratorDestroy(Iterate* iter) { iterateValueDestroy(iv, true); TFileFstIter* tIter = iter->iter; - streamWithStateDestroy(tIter->st); - fstStreamBuilderDestroy(tIter->fb); + stmStDestroy(tIter->st); + stmBuilderDestroy(tIter->fb); automCtxDestroy(tIter->ctx); taosMemoryFree(tIter); @@ -796,11 +767,6 @@ TFileReader* tfileGetReaderByCol(IndexTFile* tf, uint64_t suid, char* colName) { return rd; } -static int tfileUidCompare(const void* a, const void* b) { - uint64_t l = *(uint64_t*)a; - uint64_t r = *(uint64_t*)b; - return l - r; -} static int tfileStrCompare(const void* a, const void* b) { int ret = strcmp((char*)a, (char*)b); if (ret == 0) { diff --git a/source/libs/index/test/fstTest.cc b/source/libs/index/test/fstTest.cc index a2d7adf1c7..332b7370df 100644 --- a/source/libs/index/test/fstTest.cc +++ b/source/libs/index/test/fstTest.cc @@ -85,11 +85,11 @@ class FstReadMemory { return ok; } // add later - bool Search(AutomationCtx* ctx, std::vector& result) { - FstStreamBuilder* sb = fstSearch(_fst, ctx); - StreamWithState* st = streamBuilderIntoStream(sb); - StreamWithStateResult* rt = NULL; - while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { + bool Search(FAutoCtx* ctx, std::vector& result) { + FStmBuilder* sb = fstSearch(_fst, ctx); + FStmSt* st = stmBuilderIntoStm(sb); + FStmStRslt* rt = NULL; + while ((rt = stmStNextWith(st, NULL)) != NULL) { // result.push_back((uint64_t)(rt->out.out)); FstSlice* s = &rt->data; int32_t sz = 0; @@ -99,27 +99,27 @@ class FstReadMemory { result.push_back(rt->out.out); swsResultDestroy(rt); } - streamWithStateDestroy(st); - fstStreamBuilderDestroy(sb); + stmStDestroy(st); + stmBuilderDestroy(sb); return true; } - bool SearchRange(AutomationCtx* ctx, const std::string& low, RangeType lowType, const std::string& high, + bool SearchRange(FAutoCtx* ctx, const std::string& low, RangeType lowType, const std::string& high, RangeType highType, std::vector& result) { - FstStreamBuilder* sb = fstSearch(_fst, ctx); + FStmBuilder* sb = fstSearch(_fst, ctx); FstSlice l = fstSliceCreate((uint8_t*)low.c_str(), low.size()); FstSlice h = fstSliceCreate((uint8_t*)high.c_str(), high.size()); // range [low, high); - fstStreamBuilderSetRange(sb, &l, lowType); - fstStreamBuilderSetRange(sb, &h, highType); + stmBuilderSetRange(sb, &l, lowType); + stmBuilderSetRange(sb, &h, highType); fstSliceDestroy(&l); fstSliceDestroy(&h); - StreamWithState* st = streamBuilderIntoStream(sb); - StreamWithStateResult* rt = NULL; - while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { + FStmSt* st = stmBuilderIntoStm(sb); + FStmStRslt* rt = NULL; + while ((rt = stmStNextWith(st, NULL)) != NULL) { // result.push_back((uint64_t)(rt->out.out)); FstSlice* s = &rt->data; int32_t sz = 0; @@ -129,11 +129,11 @@ class FstReadMemory { result.push_back(rt->out.out); swsResultDestroy(rt); } - streamWithStateDestroy(st); - fstStreamBuilderDestroy(sb); + stmStDestroy(st); + stmBuilderDestroy(sb); return true; } - bool SearchWithTimeCostUs(AutomationCtx* ctx, std::vector& result) { + bool SearchWithTimeCostUs(FAutoCtx* ctx, std::vector& result) { int64_t s = taosGetTimestampUs(); bool ok = this->Search(ctx, result); int64_t e = taosGetTimestampUs(); @@ -253,7 +253,7 @@ void checkFstLongTerm() { // prefix search // std::vector result; - // AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS); + // FAutoCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS); // m->Search(ctx, result); // std::cout << "size: " << result.size() << std::endl; // assert(result.size() == count); @@ -286,7 +286,7 @@ void checkFstCheckIterator1() { // prefix search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"He", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"He", AUTOMATION_ALWAYS); m->Search(ctx, result); std::cout << "size: " << result.size() << std::endl; // assert(result.size() == count); @@ -321,7 +321,7 @@ void checkFstCheckIterator2() { // prefix search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"He", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"He", AUTOMATION_ALWAYS); m->Search(ctx, result); std::cout << "size: " << result.size() << std::endl; // assert(result.size() == count); @@ -361,7 +361,7 @@ void checkFstCheckIteratorPrefix() { // prefix search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_PREFIX); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_PREFIX); m->Search(ctx, result); assert(result.size() == 1); automCtxDestroy(ctx); @@ -370,7 +370,7 @@ void checkFstCheckIteratorPrefix() { // prefix search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"Hello", AUTOMATION_PREFIX); + FAutoCtx* ctx = automCtxCreate((void*)"Hello", AUTOMATION_PREFIX); m->Search(ctx, result); assert(result.size() == 2); automCtxDestroy(ctx); @@ -378,7 +378,7 @@ void checkFstCheckIteratorPrefix() { { std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"jddd", AUTOMATION_PREFIX); + FAutoCtx* ctx = automCtxCreate((void*)"jddd", AUTOMATION_PREFIX); m->Search(ctx, result); assert(result.size() == 1); automCtxDestroy(ctx); @@ -412,7 +412,7 @@ void checkFstCheckIteratorRange1() { { // prefix search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "b", GE, "e", LT, result); assert(result.size() == 3); @@ -421,7 +421,7 @@ void checkFstCheckIteratorRange1() { { // prefix search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "b", GT, "e", LT, result); assert(result.size() == 2); @@ -430,7 +430,7 @@ void checkFstCheckIteratorRange1() { { // prefix search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "b", GT, "e", LE, result); assert(result.size() == 3); @@ -439,7 +439,7 @@ void checkFstCheckIteratorRange1() { { // prefix search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "b", GE, "e", LE, result); assert(result.size() == 4); @@ -473,7 +473,7 @@ void checkFstCheckIteratorRange2() { { // range search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "b", GE, "ed", LT, result); assert(result.size() == 4); @@ -482,7 +482,7 @@ void checkFstCheckIteratorRange2() { { // range search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "bb", GE, "ed", LT, result); assert(result.size() == 3); @@ -491,7 +491,7 @@ void checkFstCheckIteratorRange2() { { // range search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "b", GE, "ed", LE, result); assert(result.size() == 5); @@ -501,7 +501,7 @@ void checkFstCheckIteratorRange2() { { // range search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "b", GT, "ed", LE, result); assert(result.size() == 4); @@ -510,7 +510,7 @@ void checkFstCheckIteratorRange2() { { // range search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "b", GT, "ed", LT, result); assert(result.size() == 3); @@ -544,7 +544,7 @@ void checkFstCheckIteratorRange3() { { // range search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "b", GE, "", (RangeType)10, result); assert(result.size() == 5); @@ -553,7 +553,7 @@ void checkFstCheckIteratorRange3() { { // range search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "", (RangeType)20, "ab", LE, result); assert(result.size() == 1); @@ -563,7 +563,7 @@ void checkFstCheckIteratorRange3() { { // range search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "", (RangeType)30, "ab", LT, result); assert(result.size() == 0); @@ -572,7 +572,7 @@ void checkFstCheckIteratorRange3() { { // range search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"he", AUTOMATION_ALWAYS); // [b, e) m->SearchRange(ctx, "ed", GT, "ed", (RangeType)40, result); assert(result.size() == 0); diff --git a/source/libs/index/test/fstUT.cc b/source/libs/index/test/fstUT.cc index 136c4dafec..b9388e62f7 100644 --- a/source/libs/index/test/fstUT.cc +++ b/source/libs/index/test/fstUT.cc @@ -106,11 +106,11 @@ class FstReadMemory { return ok; } // add later - bool Search(AutomationCtx* ctx, std::vector& result) { - FstStreamBuilder* sb = fstSearch(_fst, ctx); - StreamWithState* st = streamBuilderIntoStream(sb); - StreamWithStateResult* rt = NULL; - while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { + bool Search(FAutoCtx* ctx, std::vector& result) { + FStmBuilder* sb = fstSearch(_fst, ctx); + FStmSt* st = stmBuilderIntoStm(sb); + FStmStRslt* rt = NULL; + while ((rt = stmStNextWith(st, NULL)) != NULL) { // result.push_back((uint64_t)(rt->out.out)); FstSlice* s = &rt->data; int32_t sz = 0; @@ -122,7 +122,7 @@ class FstReadMemory { std::cout << std::endl; return true; } - bool SearchWithTimeCostUs(AutomationCtx* ctx, std::vector& result) { + bool SearchWithTimeCostUs(FAutoCtx* ctx, std::vector& result) { int64_t s = taosGetTimestampUs(); bool ok = this->Search(ctx, result); int64_t e = taosGetTimestampUs(); @@ -192,7 +192,7 @@ class TFst { } return fr->Get(k, v); } - bool Search(AutomationCtx* ctx, std::vector& result) { + bool Search(FAutoCtx* ctx, std::vector& result) { // add more return fr->Search(ctx, result); } @@ -231,7 +231,7 @@ TEST_F(FstEnv, writeNormal) { assert(val == 0); std::vector rlt; - AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS); + FAutoCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS); assert(fst->Search(ctx, rlt) == true); } TEST_F(FstEnv, WriteMillonrRecord) {} diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 327a4ae219..90dea3a377 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -106,17 +106,17 @@ class FstReadMemory { return ok; } // add later - bool Search(AutomationCtx* ctx, std::vector& result) { - FstStreamBuilder* sb = fstSearch(_fst, ctx); - StreamWithState* st = streamBuilderIntoStream(sb); - StreamWithStateResult* rt = NULL; + bool Search(FAutoCtx* ctx, std::vector& result) { + FStmBuilder* sb = fstSearch(_fst, ctx); + FStmSt* st = stmBuilderIntoStm(sb); + FStmStRslt* rt = NULL; - while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { + while ((rt = stmStNextWith(st, NULL)) != NULL) { result.push_back((uint64_t)(rt->out.out)); } return true; } - bool SearchWithTimeCostUs(AutomationCtx* ctx, std::vector& result) { + bool SearchWithTimeCostUs(FAutoCtx* ctx, std::vector& result) { int64_t s = taosGetTimestampUs(); bool ok = this->Search(ctx, result); int64_t e = taosGetTimestampUs(); @@ -220,7 +220,7 @@ void checkFstPrefixSearch() { // prefix search std::vector result; - AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_PREFIX); + FAutoCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_PREFIX); m->Search(ctx, result); assert(result.size() == count); for (int i = 0; i < result.size(); i++) { diff --git a/source/libs/index/test/jsonUT.cc b/source/libs/index/test/jsonUT.cc index f795fbad01..134fb53d2b 100644 --- a/source/libs/index/test/jsonUT.cc +++ b/source/libs/index/test/jsonUT.cc @@ -56,11 +56,11 @@ class JsonEnv : public ::testing::Test { initLog(); opts = indexOptsCreate(); - int ret = tIndexJsonOpen(opts, dir.c_str(), &index); + int ret = indexJsonOpen(opts, dir.c_str(), &index); assert(ret == 0); } virtual void TearDown() { - tIndexJsonClose(index); + indexJsonClose(index); indexOptsDestroy(opts); printf("destory\n"); taosMsleep(1000); @@ -75,7 +75,7 @@ static void WriteData(SIndexJson* index, const std::string& colName, int8_t dtyp (const char*)data, dlen); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); - tIndexJsonPut(index, terms, (int64_t)tableId); + indexJsonPut(index, terms, (int64_t)tableId); indexMultiTermDestroy(terms); } @@ -86,7 +86,7 @@ static void delData(SIndexJson* index, const std::string& colName, int8_t dtype, (const char*)data, dlen); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); - tIndexJsonPut(index, terms, (int64_t)tableId); + indexJsonPut(index, terms, (int64_t)tableId); indexMultiTermDestroy(terms); } @@ -99,7 +99,7 @@ static void Search(SIndexJson* index, const std::string& colNam, int8_t dtype, v SArray* res = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, (EIndexQueryType)filterType); - tIndexJsonSearch(index, mq, res); + indexJsonSearch(index, mq, res); indexMultiTermQueryDestroy(mq); *result = res; } @@ -107,41 +107,40 @@ TEST_F(JsonEnv, testWrite) { { std::string colName("test"); std::string colVal("ab"); - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); - - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); - for (size_t i = 0; i < 100; i++) { - tIndexJsonPut(index, terms, i); + for (int i = 0; i < 100; i++) { + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("voltage"); std::string colVal("ab1"); - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); + for (int i = 0; i < 100; i++) { + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); - for (size_t i = 0; i < 100; i++) { - tIndexJsonPut(index, terms, i); + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("voltage"); std::string colVal("123"); - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); - - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); for (size_t i = 0; i < 100; i++) { - tIndexJsonPut(index, terms, i); + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("test"); @@ -153,8 +152,8 @@ TEST_F(JsonEnv, testWrite) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_TERM); - tIndexJsonSearch(index, mq, result); - assert(100 == taosArrayGetSize(result)); + indexJsonSearch(index, mq, result); + EXPECT_EQ(100, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } } @@ -162,44 +161,44 @@ TEST_F(JsonEnv, testWriteMillonData) { { std::string colName("test"); std::string colVal("ab"); - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); - - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); for (size_t i = 0; i < 10; i++) { - tIndexJsonPut(index, terms, i); - } - indexMultiTermDestroy(terms); - } - { - std::string colName("voltagefdadfa"); - std::string colVal("abxxxxxxxxxxxx"); - for (int i = 0; i < 10; i++) { - colVal[i % colVal.size()] = '0' + i % 128; SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size()); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term); - for (size_t i = 0; i < 100; i++) { - tIndexJsonPut(index, terms, i); - } + indexJsonPut(index, terms, i); indexMultiTermDestroy(terms); } } { std::string colName("voltagefdadfa"); std::string colVal("abxxxxxxxxxxxx"); - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); + for (int i = 0; i < 10; i++) { + colVal[i % colVal.size()] = '0' + i % 128; + for (size_t i = 0; i < 100; i++) { + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); - for (size_t i = 0; i < 1000; i++) { - tIndexJsonPut(index, terms, i); + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); + } + } + } + { + std::string colName("voltagefdadfa"); + std::string colVal("abxxxxxxxxxxxx"); + for (size_t i = 0; i < 1000; i++) { + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("test"); @@ -211,7 +210,7 @@ TEST_F(JsonEnv, testWriteMillonData) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_TERM); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(10, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -226,8 +225,8 @@ TEST_F(JsonEnv, testWriteMillonData) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_GREATER_THAN); - tIndexJsonSearch(index, mq, result); - assert(0 == taosArrayGetSize(result)); + indexJsonSearch(index, mq, result); + EXPECT_EQ(0, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } { @@ -241,7 +240,7 @@ TEST_F(JsonEnv, testWriteMillonData) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_GREATER_EQUAL); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(10, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -252,55 +251,55 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { { std::string colName("test"); // std::string colVal("10"); - int val = 10; - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), - (const char*)&val, sizeof(val)); - - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); + int val = 10; for (size_t i = 0; i < 1000; i++) { - tIndexJsonPut(index, terms, i); + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(val)); + + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("test2"); int val = 20; - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), - (const char*)&val, sizeof(val)); - - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); for (size_t i = 0; i < 1000; i++) { - tIndexJsonPut(index, terms, i); + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(val)); + + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("test"); int val = 15; - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), - (const char*)&val, sizeof(val)); - - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); for (size_t i = 0; i < 1000; i++) { - tIndexJsonPut(index, terms, i); + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(val)); + + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("test2"); const char* val = "test"; - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), - (const char*)val, strlen(val)); - - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); for (size_t i = 0; i < 1000; i++) { - tIndexJsonPut(index, terms, i); + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + (const char*)val, strlen(val)); + + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("test"); @@ -311,7 +310,7 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_TERM); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(1000, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -325,7 +324,7 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_GREATER_THAN); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(0, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -340,7 +339,7 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_GREATER_EQUAL); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(1000, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -355,7 +354,7 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_LESS_THAN); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(0, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -370,7 +369,7 @@ TEST_F(JsonEnv, testWriteJsonNumberData) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_LESS_EQUAL); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(1000, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -380,28 +379,28 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) { { std::string colName("test1"); int val = 10; - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), - (const char*)&val, sizeof(val)); - - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); for (size_t i = 0; i < 1000; i++) { - tIndexJsonPut(index, terms, i); + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(val)); + + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("test"); std::string colVal("xxxxxxxxxxxxxxxxxxx"); - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), - colVal.c_str(), colVal.size()); - - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); for (size_t i = 0; i < 1000; i++) { - tIndexJsonPut(index, terms, i); + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("test1"); @@ -413,7 +412,7 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_TERM); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(1000, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -427,7 +426,7 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_GREATER_THAN); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(0, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -442,7 +441,7 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_GREATER_EQUAL); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(1000, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -456,7 +455,7 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_GREATER_THAN); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(0, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -470,7 +469,7 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_LESS_EQUAL); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(1000, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } @@ -478,15 +477,15 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) { std::string colName("other_column"); int val = 100; - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), - (const char*)&val, sizeof(val)); - - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); for (size_t i = 0; i < 1000; i++) { - tIndexJsonPut(index, terms, i); + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(val)); + + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("test1"); @@ -499,22 +498,22 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_LESS_THAN); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(0, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } { std::string colName("test1"); int val = 15; - SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), - (const char*)&val, sizeof(val)); - - SIndexMultiTerm* terms = indexMultiTermCreate(); - indexMultiTermAdd(terms, term); for (size_t i = 0; i < 1000; i++) { - tIndexJsonPut(index, terms, i + 1000); + SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(), + (const char*)&val, sizeof(val)); + + SIndexMultiTerm* terms = indexMultiTermCreate(); + indexMultiTermAdd(terms, term); + indexJsonPut(index, terms, i + 1000); + indexMultiTermDestroy(terms); } - indexMultiTermDestroy(terms); } { std::string colName("test1"); @@ -527,7 +526,7 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) { SArray* result = taosArrayInit(1, sizeof(uint64_t)); indexMultiTermQueryAdd(mq, q, QUERY_GREATER_EQUAL); - tIndexJsonSearch(index, mq, result); + indexJsonSearch(index, mq, result); EXPECT_EQ(2000, taosArrayGetSize(result)); indexMultiTermQueryDestroy(mq); } diff --git a/source/libs/index/test/utilUT.cc b/source/libs/index/test/utilUT.cc index 4a30160244..6858d31325 100644 --- a/source/libs/index/test/utilUT.cc +++ b/source/libs/index/test/utilUT.cc @@ -327,13 +327,13 @@ TEST_F(UtilEnv, testFill) { for (int i = 0; i < 1000000; i++) { int64_t val = i; char buf[65] = {0}; - indexInt2str(val, buf, 1); + idxInt2str(val, buf, 1); EXPECT_EQ(val, taosStr2int64(buf)); } for (int i = 0; i < 1000000; i++) { int64_t val = 0 - i; char buf[65] = {0}; - indexInt2str(val, buf, -1); + idxInt2str(val, buf, -1); EXPECT_EQ(val, taosStr2int64(buf)); } } diff --git a/source/libs/monitor/src/monMsg.c b/source/libs/monitor/src/monMsg.c index 944a7b5475..a041b582a9 100644 --- a/source/libs/monitor/src/monMsg.c +++ b/source/libs/monitor/src/monMsg.c @@ -569,6 +569,7 @@ int32_t tSerializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) { if (tEncodeI64(&encoder, pInfo->numOfProcessedFetch) < 0) return -1; if (tEncodeI64(&encoder, pInfo->numOfProcessedDrop) < 0) return -1; if (tEncodeI64(&encoder, pInfo->numOfProcessedHb) < 0) return -1; + if (tEncodeI64(&encoder, pInfo->numOfProcessedDelete) < 0) return -1; if (tEncodeI64(&encoder, pInfo->cacheDataSize) < 0) return -1; if (tEncodeI64(&encoder, pInfo->numOfQueryInQueue) < 0) return -1; if (tEncodeI64(&encoder, pInfo->numOfFetchInQueue) < 0) return -1; @@ -591,6 +592,7 @@ int32_t tDeserializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) { if (tDecodeI64(&decoder, &pInfo->numOfProcessedFetch) < 0) return -1; if (tDecodeI64(&decoder, &pInfo->numOfProcessedDrop) < 0) return -1; if (tDecodeI64(&decoder, &pInfo->numOfProcessedHb) < 0) return -1; + if (tDecodeI64(&decoder, &pInfo->numOfProcessedDelete) < 0) return -1; if (tDecodeI64(&decoder, &pInfo->cacheDataSize) < 0) return -1; if (tDecodeI64(&decoder, &pInfo->numOfQueryInQueue) < 0) return -1; if (tDecodeI64(&decoder, &pInfo->numOfFetchInQueue) < 0) return -1; diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index f277d30eb1..7e6a1f5e0c 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -318,6 +318,7 @@ static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) { CLONE_NODE_LIST_FIELD(pScanPseudoCols); COPY_SCALAR_FIELD(tableType); COPY_SCALAR_FIELD(tableId); + COPY_SCALAR_FIELD(stableId); CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone); COPY_SCALAR_FIELD(scanType); COPY_OBJECT_FIELD(scanSeq[0], sizeof(uint8_t) * 2); @@ -370,7 +371,7 @@ static SNode* logicVnodeModifCopy(const SVnodeModifyLogicNode* pSrc, SVnodeModif COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); COPY_SCALAR_FIELD(modifyType); COPY_SCALAR_FIELD(msgType); - CLONE_NODE_FIELD(pModifyRows); + CLONE_NODE_FIELD(pAffectedRows); COPY_SCALAR_FIELD(tableId); COPY_SCALAR_FIELD(tableType); COPY_CHAR_ARRAY_FIELD(tableFName); @@ -387,6 +388,7 @@ static SNode* logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNo static SNode* logicMergeCopy(const SMergeLogicNode* pSrc, SMergeLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pMergeKeys); + CLONE_NODE_LIST_FIELD(pInputs); COPY_SCALAR_FIELD(numOfChannels); COPY_SCALAR_FIELD(srcGroupId); return (SNode*)pDst; @@ -432,6 +434,12 @@ static SNode* logicPartitionCopy(const SPartitionLogicNode* pSrc, SPartitionLogi return (SNode*)pDst; } +static SNode* logicIndefRowsFuncCopy(const SIndefRowsFuncLogicNode* pSrc, SIndefRowsFuncLogicNode* pDst) { + COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); + CLONE_NODE_LIST_FIELD(pVectorFuncs); + return (SNode*)pDst; +} + static SNode* logicSubplanCopy(const SLogicSubplan* pSrc, SLogicSubplan* pDst) { COPY_OBJECT_FIELD(id, sizeof(SSubplanId)); CLONE_NODE_FIELD(pNode); @@ -441,6 +449,77 @@ static SNode* logicSubplanCopy(const SLogicSubplan* pSrc, SLogicSubplan* pDst) { return (SNode*)pDst; } +static SNode* physiNodeCopy(const SPhysiNode* pSrc, SPhysiNode* pDst) { + CLONE_NODE_FIELD(pOutputDataBlockDesc); + CLONE_NODE_FIELD(pConditions); + CLONE_NODE_LIST_FIELD(pChildren); + return (SNode*)pDst; +} + +static SNode* physiScanCopy(const SScanPhysiNode* pSrc, SScanPhysiNode* pDst) { + COPY_BASE_OBJECT_FIELD(node, physiNodeCopy); + CLONE_NODE_LIST_FIELD(pScanCols); + CLONE_NODE_LIST_FIELD(pScanPseudoCols); + COPY_SCALAR_FIELD(uid); + COPY_SCALAR_FIELD(suid); + COPY_SCALAR_FIELD(tableType); + COPY_OBJECT_FIELD(tableName, sizeof(SName)); + return (SNode*)pDst; +} + +static SNode* physiTagScanCopy(const STagScanPhysiNode* pSrc, STagScanPhysiNode* pDst) { + return physiScanCopy(pSrc, pDst); +} + +static SNode* physiTableScanCopy(const STableScanPhysiNode* pSrc, STableScanPhysiNode* pDst) { + COPY_BASE_OBJECT_FIELD(scan, physiScanCopy); + COPY_OBJECT_FIELD(scanSeq[0], sizeof(uint8_t) * 2); + COPY_OBJECT_FIELD(scanRange, sizeof(STimeWindow)); + COPY_SCALAR_FIELD(ratio); + COPY_SCALAR_FIELD(dataRequired); + CLONE_NODE_LIST_FIELD(pDynamicScanFuncs); + CLONE_NODE_LIST_FIELD(pPartitionKeys); + COPY_SCALAR_FIELD(interval); + COPY_SCALAR_FIELD(offset); + COPY_SCALAR_FIELD(sliding); + COPY_SCALAR_FIELD(intervalUnit); + COPY_SCALAR_FIELD(slidingUnit); + COPY_SCALAR_FIELD(triggerType); + COPY_SCALAR_FIELD(watermark); + COPY_SCALAR_FIELD(tsColId); + COPY_SCALAR_FIELD(filesFactor); + return (SNode*)pDst; +} + +static SNode* physiSysTableScanCopy(const SSystemTableScanPhysiNode* pSrc, SSystemTableScanPhysiNode* pDst) { + COPY_BASE_OBJECT_FIELD(scan, physiScanCopy); + COPY_OBJECT_FIELD(mgmtEpSet, sizeof(SEpSet)); + COPY_SCALAR_FIELD(showRewrite); + COPY_SCALAR_FIELD(accountId); + return (SNode*)pDst; +} + +static SNode* physiWindowCopy(const SWinodwPhysiNode* pSrc, SWinodwPhysiNode* pDst) { + COPY_BASE_OBJECT_FIELD(node, physiNodeCopy); + CLONE_NODE_LIST_FIELD(pExprs); + CLONE_NODE_LIST_FIELD(pFuncs); + CLONE_NODE_FIELD(pTspk); + COPY_SCALAR_FIELD(triggerType); + COPY_SCALAR_FIELD(watermark); + COPY_SCALAR_FIELD(filesFactor); + return (SNode*)pDst; +} + +static SNode* physiIntervalCopy(const SIntervalPhysiNode* pSrc, SIntervalPhysiNode* pDst) { + COPY_BASE_OBJECT_FIELD(window, physiWindowCopy); + COPY_SCALAR_FIELD(interval); + COPY_SCALAR_FIELD(offset); + COPY_SCALAR_FIELD(sliding); + COPY_SCALAR_FIELD(intervalUnit); + COPY_SCALAR_FIELD(slidingUnit); + return (SNode*)pDst; +} + static SNode* dataBlockDescCopy(const SDataBlockDescNode* pSrc, SDataBlockDescNode* pDst) { COPY_SCALAR_FIELD(dataBlockId); CLONE_NODE_LIST_FIELD(pSlots); @@ -563,8 +642,24 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) { return logicSortCopy((const SSortLogicNode*)pNode, (SSortLogicNode*)pDst); case QUERY_NODE_LOGIC_PLAN_PARTITION: return logicPartitionCopy((const SPartitionLogicNode*)pNode, (SPartitionLogicNode*)pDst); + case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: + return logicIndefRowsFuncCopy((const SIndefRowsFuncLogicNode*)pNode, (SIndefRowsFuncLogicNode*)pDst); case QUERY_NODE_LOGIC_SUBPLAN: return logicSubplanCopy((const SLogicSubplan*)pNode, (SLogicSubplan*)pDst); + case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: + return physiTagScanCopy((const STagScanPhysiNode*)pNode, (STagScanPhysiNode*)pDst); + case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: + return physiTableScanCopy((const STableScanPhysiNode*)pNode, (STableScanPhysiNode*)pDst); + case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: + return physiSysTableScanCopy((const SSystemTableScanPhysiNode*)pNode, (SSystemTableScanPhysiNode*)pDst); + case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL: + return physiIntervalCopy((const SIntervalPhysiNode*)pNode, (SIntervalPhysiNode*)pDst); default: break; } diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index c54289bc56..0735092c1a 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -202,6 +202,8 @@ const char* nodesNodeName(ENodeType type) { return "LogicSort"; case QUERY_NODE_LOGIC_PLAN_PARTITION: return "LogicPartition"; + case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: + return "LogicIndefRowsFunc"; case QUERY_NODE_LOGIC_SUBPLAN: return "LogicSubplan"; case QUERY_NODE_LOGIC_PLAN: @@ -218,9 +220,9 @@ const char* nodesNodeName(ENodeType type) { return "PhysiSystemTableScan"; case QUERY_NODE_PHYSICAL_PLAN_PROJECT: return "PhysiProject"; - case QUERY_NODE_PHYSICAL_PLAN_JOIN: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: return "PhysiJoin"; - case QUERY_NODE_PHYSICAL_PLAN_AGG: + case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: return "PhysiAgg"; case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: return "PhysiExchange"; @@ -230,6 +232,8 @@ const char* nodesNodeName(ENodeType type) { return "PhysiSort"; case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL: return "PhysiHashInterval"; + case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL: + return "PhysiMergeInterval"; case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL: return "PhysiStreamInterval"; case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL: @@ -238,16 +242,18 @@ const char* nodesNodeName(ENodeType type) { return "PhysiStreamSemiInterval"; case QUERY_NODE_PHYSICAL_PLAN_FILL: return "PhysiFill"; - case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION: return "PhysiSessionWindow"; - case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION: return "PhysiStreamSessionWindow"; - case QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE: return "PhysiStateWindow"; - case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE: return "PhysiStreamStateWindow"; case QUERY_NODE_PHYSICAL_PLAN_PARTITION: return "PhysiPartition"; + case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC: + return "PhysiIndefRowsFunc"; case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return "PhysiDispatch"; case QUERY_NODE_PHYSICAL_PLAN_INSERT: @@ -611,7 +617,7 @@ static int32_t jsonToLogicProjectNode(const SJson* pJson, void* pObj) { static const char* jkVnodeModifyLogicPlanModifyType = "ModifyType"; static const char* jkVnodeModifyLogicPlanMsgType = "MsgType"; -static const char* jkVnodeModifyLogicPlanModifyRows = "ModifyRows"; +static const char* jkVnodeModifyLogicPlanAffectedRows = "AffectedRows"; static int32_t logicVnodeModifyNodeToJson(const void* pObj, SJson* pJson) { const SVnodeModifyLogicNode* pNode = (const SVnodeModifyLogicNode*)pObj; @@ -624,7 +630,7 @@ static int32_t logicVnodeModifyNodeToJson(const void* pObj, SJson* pJson) { code = tjsonAddIntegerToObject(pJson, jkVnodeModifyLogicPlanMsgType, pNode->msgType); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddObject(pJson, jkVnodeModifyLogicPlanModifyRows, nodeToJson, pNode->pModifyRows); + code = tjsonAddObject(pJson, jkVnodeModifyLogicPlanAffectedRows, nodeToJson, pNode->pAffectedRows); } return code; @@ -641,7 +647,7 @@ static int32_t jsonToLogicVnodeModifyNode(const SJson* pJson, void* pObj) { code = tjsonGetIntValue(pJson, jkVnodeModifyLogicPlanMsgType, &pNode->msgType); } if (TSDB_CODE_SUCCESS == code) { - code = jsonToNodeObject(pJson, jkVnodeModifyLogicPlanModifyRows, &pNode->pModifyRows); + code = jsonToNodeObject(pJson, jkVnodeModifyLogicPlanAffectedRows, &pNode->pAffectedRows); } return code; @@ -911,6 +917,30 @@ static int32_t jsonToLogicPartitionNode(const SJson* pJson, void* pObj) { return code; } +static const char* jkIndefRowsFuncLogicPlanVectorFuncs = "VectorFuncs"; + +static int32_t logicIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) { + const SIndefRowsFuncLogicNode* pNode = (const SIndefRowsFuncLogicNode*)pObj; + + int32_t code = logicPlanNodeToJson(pObj, pJson); + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkIndefRowsFuncLogicPlanVectorFuncs, pNode->pVectorFuncs); + } + + return code; +} + +static int32_t jsonToLogicIndefRowsFuncNode(const SJson* pJson, void* pObj) { + SIndefRowsFuncLogicNode* pNode = (SIndefRowsFuncLogicNode*)pObj; + + int32_t code = jsonToLogicPlanNode(pJson, pObj); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkIndefRowsFuncLogicPlanVectorFuncs, &pNode->pVectorFuncs); + } + + return code; +} + static const char* jkSubplanIdQueryId = "QueryId"; static const char* jkSubplanIdGroupId = "GroupId"; static const char* jkSubplanIdSubplanId = "SubplanId"; @@ -1249,6 +1279,7 @@ static int32_t jsonToName(const SJson* pJson, void* pObj) { static const char* jkScanPhysiPlanScanCols = "ScanCols"; static const char* jkScanPhysiPlanScanPseudoCols = "ScanPseudoCols"; static const char* jkScanPhysiPlanTableId = "TableId"; +static const char* jkScanPhysiPlanSTableId = "STableId"; static const char* jkScanPhysiPlanTableType = "TableType"; static const char* jkScanPhysiPlanTableName = "TableName"; @@ -1265,6 +1296,9 @@ static int32_t physiScanNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanTableId, pNode->uid); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanSTableId, pNode->suid); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanTableType, pNode->tableType); } @@ -1288,6 +1322,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetUBigIntValue(pJson, jkScanPhysiPlanTableId, &pNode->uid); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetUBigIntValue(pJson, jkScanPhysiPlanSTableId, &pNode->suid); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetTinyIntValue(pJson, jkScanPhysiPlanTableType, &pNode->tableType); } @@ -1644,6 +1681,7 @@ static int32_t jsonToPhysiExchangeNode(const SJson* pJson, void* pObj) { } static const char* jkMergePhysiPlanMergeKeys = "MergeKeys"; +static const char* jkMergePhysiPlanTargets = "Targets"; static const char* jkMergePhysiPlanNumOfChannels = "NumOfChannels"; static const char* jkMergePhysiPlanSrcGroupId = "SrcGroupId"; @@ -1654,6 +1692,9 @@ static int32_t physiMergeNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkMergePhysiPlanMergeKeys, pNode->pMergeKeys); } + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkMergePhysiPlanTargets, pNode->pTargets); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkMergePhysiPlanNumOfChannels, pNode->numOfChannels); } @@ -1671,6 +1712,9 @@ static int32_t jsonToPhysiMergeNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkMergePhysiPlanMergeKeys, &pNode->pMergeKeys); } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkMergePhysiPlanTargets, &pNode->pTargets); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetIntValue(pJson, jkMergePhysiPlanNumOfChannels, &pNode->numOfChannels); } @@ -1979,6 +2023,37 @@ static int32_t jsonToPhysiPartitionNode(const SJson* pJson, void* pObj) { return code; } +static const char* jkIndefRowsFuncPhysiPlanExprs = "Exprs"; +static const char* jkIndefRowsFuncPhysiPlanVectorFuncs = "VectorFuncs"; + +static int32_t physiIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) { + const SIndefRowsFuncPhysiNode* pNode = (const SIndefRowsFuncPhysiNode*)pObj; + + int32_t code = physicPlanNodeToJson(pObj, pJson); + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanExprs, pNode->pExprs); + } + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanVectorFuncs, pNode->pVectorFuncs); + } + + return code; +} + +static int32_t jsonToPhysiIndefRowsFuncNode(const SJson* pJson, void* pObj) { + SIndefRowsFuncPhysiNode* pNode = (SIndefRowsFuncPhysiNode*)pObj; + + int32_t code = jsonToPhysicPlanNode(pJson, pObj); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanExprs, &pNode->pExprs); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanVectorFuncs, &pNode->pVectorFuncs); + } + + return code; +} + static const char* jkDataSinkInputDataBlockDesc = "InputDataBlockDesc"; static int32_t physicDataSinkNodeToJson(const void* pObj, SJson* pJson) { @@ -2000,6 +2075,7 @@ static const char* jkDeletePhysiPlanTableType = "TableType"; static const char* jkDeletePhysiPlanTableFName = "TableFName"; static const char* jkDeletePhysiPlanDeleteTimeRangeStartKey = "DeleteTimeRangeStartKey"; static const char* jkDeletePhysiPlanDeleteTimeRangeEndKey = "DeleteTimeRangeEndKey"; +static const char* jkDeletePhysiPlanAffectedRows = "AffectedRows"; static int32_t physiDeleteNodeToJson(const void* pObj, SJson* pJson) { const SDataDeleterNode* pNode = (const SDataDeleterNode*)pObj; @@ -2020,6 +2096,9 @@ static int32_t physiDeleteNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkDeletePhysiPlanDeleteTimeRangeEndKey, pNode->deleteTimeRange.ekey); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkDeletePhysiPlanAffectedRows, nodeToJson, pNode->pAffectedRows); + } return code; } @@ -2043,6 +2122,9 @@ static int32_t jsonToPhysiDeleteNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetBigIntValue(pJson, jkDeletePhysiPlanDeleteTimeRangeEndKey, &pNode->deleteTimeRange.ekey); } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkDeletePhysiPlanAffectedRows, &pNode->pAffectedRows); + } return code; } @@ -2359,6 +2441,7 @@ static const char* jkValueLiteralSize = "LiteralSize"; static const char* jkValueLiteral = "Literal"; static const char* jkValueDuration = "Duration"; static const char* jkValueTranslate = "Translate"; +static const char* jkValueNotReserved = "NotReserved"; static const char* jkValueDatum = "Datum"; static int32_t datumToJson(const void* pObj, SJson* pJson) { @@ -2431,6 +2514,9 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddBoolToObject(pJson, jkValueTranslate, pNode->translate); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddBoolToObject(pJson, jkValueNotReserved, pNode->notReserved); + } if (TSDB_CODE_SUCCESS == code && pNode->translate) { code = datumToJson(pNode, pJson); } @@ -2552,6 +2638,9 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetBoolValue(pJson, jkValueTranslate, &pNode->translate); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBoolValue(pJson, jkValueNotReserved, &pNode->notReserved); + } if (TSDB_CODE_SUCCESS == code && pNode->translate) { code = jsonToDatum(pJson, pNode); } @@ -3777,6 +3866,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { return logicSortNodeToJson(pObj, pJson); case QUERY_NODE_LOGIC_PLAN_PARTITION: return logicPartitionNodeToJson(pObj, pJson); + case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: + return logicIndefRowsFuncNodeToJson(pObj, pJson); case QUERY_NODE_LOGIC_SUBPLAN: return logicSubplanToJson(pObj, pJson); case QUERY_NODE_LOGIC_PLAN: @@ -3791,9 +3882,9 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { return physiSysTableScanNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_PROJECT: return physiProjectNodeToJson(pObj, pJson); - case QUERY_NODE_PHYSICAL_PLAN_JOIN: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: return physiJoinNodeToJson(pObj, pJson); - case QUERY_NODE_PHYSICAL_PLAN_AGG: + case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: return physiAggNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: return physiExchangeNodeToJson(pObj, pJson); @@ -3802,20 +3893,23 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { case QUERY_NODE_PHYSICAL_PLAN_SORT: return physiSortNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL: case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL: case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL: case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL: return physiIntervalNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_FILL: return physiFillNodeToJson(pObj, pJson); - case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW: - case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION: return physiSessionWindowNodeToJson(pObj, pJson); - case QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW: - case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE: return physiStateWindowNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_PARTITION: return physiPartitionNodeToJson(pObj, pJson); + case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC: + return physiIndefRowsFuncNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return physiDispatchNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_INSERT: @@ -3905,6 +3999,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToLogicSortNode(pJson, pObj); case QUERY_NODE_LOGIC_PLAN_PARTITION: return jsonToLogicPartitionNode(pJson, pObj); + case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: + return jsonToLogicIndefRowsFuncNode(pJson, pObj); case QUERY_NODE_LOGIC_SUBPLAN: return jsonToLogicSubplan(pJson, pObj); case QUERY_NODE_LOGIC_PLAN: @@ -3919,9 +4015,9 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToPhysiSysTableScanNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_PROJECT: return jsonToPhysiProjectNode(pJson, pObj); - case QUERY_NODE_PHYSICAL_PLAN_JOIN: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: return jsonToPhysiJoinNode(pJson, pObj); - case QUERY_NODE_PHYSICAL_PLAN_AGG: + case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: return jsonToPhysiAggNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: return jsonToPhysiExchangeNode(pJson, pObj); @@ -3930,20 +4026,23 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { case QUERY_NODE_PHYSICAL_PLAN_SORT: return jsonToPhysiSortNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL: case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL: case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL: case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL: return jsonToPhysiIntervalNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_FILL: return jsonToPhysiFillNode(pJson, pObj); - case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW: - case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION: return jsonToPhysiSessionWindowNode(pJson, pObj); - case QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW: - case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE: return jsonToPhysiStateWindowNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_PARTITION: return jsonToPhysiPartitionNode(pJson, pObj); + case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC: + return jsonToPhysiIndefRowsFuncNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return jsonToPhysiDispatchNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_DELETE: diff --git a/source/libs/nodes/src/nodesTraverseFuncs.c b/source/libs/nodes/src/nodesTraverseFuncs.c index d9b61bb002..d8130d5650 100644 --- a/source/libs/nodes/src/nodesTraverseFuncs.c +++ b/source/libs/nodes/src/nodesTraverseFuncs.c @@ -350,6 +350,7 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa case SQL_CLAUSE_GROUP_BY: nodesWalkExpr(pSelect->pHaving, walker, pContext); case SQL_CLAUSE_HAVING: + case SQL_CLAUSE_SELECT: case SQL_CLAUSE_DISTINCT: nodesWalkExprs(pSelect->pOrderByList, walker, pContext); case SQL_CLAUSE_ORDER_BY: @@ -382,6 +383,7 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit case SQL_CLAUSE_GROUP_BY: nodesRewriteExpr(&(pSelect->pHaving), rewriter, pContext); case SQL_CLAUSE_HAVING: + case SQL_CLAUSE_SELECT: case SQL_CLAUSE_DISTINCT: nodesRewriteExprs(pSelect->pOrderByList, rewriter, pContext); case SQL_CLAUSE_ORDER_BY: @@ -465,7 +467,7 @@ static EDealRes dispatchPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalk } break; } - case QUERY_NODE_PHYSICAL_PLAN_JOIN: { + case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: { SJoinPhysiNode* pJoin = (SJoinPhysiNode*)pNode; res = walkPhysiNode((SPhysiNode*)pNode, order, walker, pContext); if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { @@ -476,7 +478,7 @@ static EDealRes dispatchPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalk } break; } - case QUERY_NODE_PHYSICAL_PLAN_AGG: { + case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: { SAggPhysiNode* pAgg = (SAggPhysiNode*)pNode; res = walkPhysiNode((SPhysiNode*)pNode, order, walker, pContext); if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { @@ -516,12 +518,12 @@ static EDealRes dispatchPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalk case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL: res = walkWindowPhysi((SWinodwPhysiNode*)pNode, order, walker, pContext); break; - case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW: - case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION: res = walkWindowPhysi((SWinodwPhysiNode*)pNode, order, walker, pContext); break; - case QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW: - case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW: { + case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE: { SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)pNode; res = walkWindowPhysi((SWinodwPhysiNode*)pNode, order, walker, pContext); if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 16ce4d7a48..1ea9124839 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -164,9 +164,14 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SCreateStreamStmt)); case QUERY_NODE_DROP_STREAM_STMT: return makeNode(type, sizeof(SDropStreamStmt)); + case QUERY_NODE_BALANCE_VGROUP_STMT: + return makeNode(type, sizeof(SBalanceVgroupStmt)); case QUERY_NODE_MERGE_VGROUP_STMT: + return makeNode(type, sizeof(SMergeVgroupStmt)); case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT: + return makeNode(type, sizeof(SRedistributeVgroupStmt)); case QUERY_NODE_SPLIT_VGROUP_STMT: + return makeNode(type, sizeof(SSplitVgroupStmt)); case QUERY_NODE_SYNCDB_STMT: break; case QUERY_NODE_GRANT_STMT: @@ -232,6 +237,8 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SSortLogicNode)); case QUERY_NODE_LOGIC_PLAN_PARTITION: return makeNode(type, sizeof(SPartitionLogicNode)); + case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: + return makeNode(type, sizeof(SIndefRowsFuncLogicNode)); case QUERY_NODE_LOGIC_SUBPLAN: return makeNode(type, sizeof(SLogicSubplan)); case QUERY_NODE_LOGIC_PLAN: @@ -248,9 +255,9 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SSystemTableScanPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_PROJECT: return makeNode(type, sizeof(SProjectPhysiNode)); - case QUERY_NODE_PHYSICAL_PLAN_JOIN: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: return makeNode(type, sizeof(SJoinPhysiNode)); - case QUERY_NODE_PHYSICAL_PLAN_AGG: + case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: return makeNode(type, sizeof(SAggPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: return makeNode(type, sizeof(SExchangePhysiNode)); @@ -260,8 +267,8 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SSortPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL: return makeNode(type, sizeof(SIntervalPhysiNode)); - case QUERY_NODE_PHYSICAL_PLAN_SORT_MERGE_INTERVAL: - return makeNode(type, sizeof(SSortMergeIntervalPhysiNode)); + case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL: + return makeNode(type, sizeof(SMergeIntervalPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL: return makeNode(type, sizeof(SStreamIntervalPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL: @@ -270,16 +277,18 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SStreamSemiIntervalPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_FILL: return makeNode(type, sizeof(SFillPhysiNode)); - case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION: return makeNode(type, sizeof(SSessionWinodwPhysiNode)); - case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION: return makeNode(type, sizeof(SStreamSessionWinodwPhysiNode)); - case QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE: return makeNode(type, sizeof(SStateWinodwPhysiNode)); - case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE: return makeNode(type, sizeof(SStreamStateWinodwPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_PARTITION: return makeNode(type, sizeof(SPartitionPhysiNode)); + case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC: + return makeNode(type, sizeof(SIndefRowsFuncPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return makeNode(type, sizeof(SDataDispatcherNode)); case QUERY_NODE_PHYSICAL_PLAN_INSERT: @@ -648,14 +657,14 @@ void nodesDestroyNode(SNodeptr pNode) { nodesDestroyList(pPhyNode->pProjections); break; } - case QUERY_NODE_PHYSICAL_PLAN_JOIN: { + case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: { SJoinPhysiNode* pPhyNode = (SJoinPhysiNode*)pNode; destroyPhysiNode((SPhysiNode*)pPhyNode); nodesDestroyNode(pPhyNode->pOnConditions); nodesDestroyList(pPhyNode->pTargets); break; } - case QUERY_NODE_PHYSICAL_PLAN_AGG: { + case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: { SAggPhysiNode* pPhyNode = (SAggPhysiNode*)pNode; destroyPhysiNode((SPhysiNode*)pPhyNode); nodesDestroyList(pPhyNode->pExprs); @@ -680,8 +689,8 @@ void nodesDestroyNode(SNodeptr pNode) { case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL: destroyWinodwPhysiNode((SWinodwPhysiNode*)pNode); break; - case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW: - case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW: + case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION: destroyWinodwPhysiNode((SWinodwPhysiNode*)pNode); break; case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index ca7fa7a4c6..0c6663d29a 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -187,6 +187,7 @@ SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SNode* pOptions, SNode* pQuery); SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pStreamName); SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId); +SNode* createBalanceVgroupStmt(SAstCreateContext* pCxt); SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2); SNode* createRedistributeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId, SNodeList* pDnodes); SNode* createSplitVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId); diff --git a/source/libs/parser/inc/parInsertData.h b/source/libs/parser/inc/parInsertData.h index aeebf51c96..167970838b 100644 --- a/source/libs/parser/inc/parInsertData.h +++ b/source/libs/parser/inc/parInsertData.h @@ -116,8 +116,7 @@ static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo } static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks *dataBuf, int32_t numOfRows) { - pBlocks->suid = - (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? dataBuf->pTableMeta->uid : dataBuf->pTableMeta->suid); + pBlocks->suid = (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? 0 : dataBuf->pTableMeta->suid); pBlocks->uid = dataBuf->pTableMeta->uid; pBlocks->sversion = dataBuf->pTableMeta->sversion; pBlocks->schemaLen = dataBuf->createTbReqLen; diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index d63ce74fa7..bf23ff08b2 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -469,9 +469,10 @@ cmd ::= KILL QUERY NK_INTEGER(A). cmd ::= KILL TRANSACTION NK_INTEGER(A). { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_TRANSACTION_STMT, &A); } /************************************************ merge/redistribute/ vgroup ******************************************/ +cmd ::= BALANCE VGROUP. { pCxt->pRootNode = createBalanceVgroupStmt(pCxt); } cmd ::= MERGE VGROUP NK_INTEGER(A) NK_INTEGER(B). { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &A, &B); } cmd ::= REDISTRIBUTE VGROUP NK_INTEGER(A) dnode_list(B). { pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &A, B); } -cmd ::= SPLIT VGROUP NK_INTEGER(A). { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &A); } +//cmd ::= SPLIT VGROUP NK_INTEGER(A). { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &A); } %type dnode_list { SNodeList* } %destructor dnode_list { nodesDestroyList($$); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 24db0671ac..613a2d867d 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -1435,25 +1435,37 @@ SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId return (SNode*)pStmt; } +SNode* createBalanceVgroupStmt(SAstCreateContext* pCxt) { + CHECK_PARSER_STATUS(pCxt); + SBalanceVgroupStmt* pStmt = nodesMakeNode(QUERY_NODE_BALANCE_VGROUP_STMT); + CHECK_OUT_OF_MEM(pStmt); + return (SNode*)pStmt; +} + SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2) { CHECK_PARSER_STATUS(pCxt); - SNode* pStmt = nodesMakeNode(QUERY_NODE_MERGE_VGROUP_STMT); + SMergeVgroupStmt* pStmt = nodesMakeNode(QUERY_NODE_MERGE_VGROUP_STMT); CHECK_OUT_OF_MEM(pStmt); - return pStmt; + pStmt->vgId1 = taosStr2Int32(pVgId1->z, NULL, 10); + pStmt->vgId2 = taosStr2Int32(pVgId2->z, NULL, 10); + return (SNode*)pStmt; } SNode* createRedistributeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId, SNodeList* pDnodes) { CHECK_PARSER_STATUS(pCxt); - SNode* pStmt = nodesMakeNode(QUERY_NODE_REDISTRIBUTE_VGROUP_STMT); + SRedistributeVgroupStmt* pStmt = nodesMakeNode(QUERY_NODE_REDISTRIBUTE_VGROUP_STMT); CHECK_OUT_OF_MEM(pStmt); - return pStmt; + pStmt->vgId = taosStr2Int32(pVgId->z, NULL, 10); + pStmt->pDnodes = pDnodes; + return (SNode*)pStmt; } SNode* createSplitVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId) { CHECK_PARSER_STATUS(pCxt); - SNode* pStmt = nodesMakeNode(QUERY_NODE_SPLIT_VGROUP_STMT); + SSplitVgroupStmt* pStmt = nodesMakeNode(QUERY_NODE_SPLIT_VGROUP_STMT); CHECK_OUT_OF_MEM(pStmt); - return pStmt; + pStmt->vgId = taosStr2Int32(pVgId->z, NULL, 10); + return (SNode*)pStmt; } SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName) { diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index 6c44ce4c3c..6555ec3a7d 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -108,9 +108,10 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt); static EDealRes collectMetaKeyFromFunction(SCollectMetaKeyFromExprCxt* pCxt, SFunctionNode* pFunc) { if (fmIsBuiltinFunc(pFunc->functionName)) { - return TSDB_CODE_SUCCESS; + return DEAL_RES_CONTINUE; } - return reserveUdfInCache(pFunc->functionName, pCxt->pComCxt->pMetaCache); + pCxt->errCode = reserveUdfInCache(pFunc->functionName, pCxt->pComCxt->pMetaCache); + return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR; } static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, SRealTableNode* pRealTable, @@ -179,6 +180,10 @@ static int32_t collectMetaKeyFromSelect(SCollectMetaKeyCxt* pCxt, SSelectStmt* p return cxt.errCode; } +static int32_t collectMetaKeyFromAlterDatabase(SCollectMetaKeyCxt* pCxt, SAlterDatabaseStmt* pStmt) { + return reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache); +} + static int32_t collectMetaKeyFromCreateTable(SCollectMetaKeyCxt* pCxt, SCreateTableStmt* pStmt) { int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache); if (TSDB_CODE_SUCCESS == code && NULL == pStmt->pTags) { @@ -258,6 +263,17 @@ static int32_t collectMetaKeyFromExplain(SCollectMetaKeyCxt* pCxt, SExplainStmt* return collectMetaKeyFromQuery(pCxt, pStmt->pQuery); } +static int32_t collectMetaKeyFromDescribe(SCollectMetaKeyCxt* pCxt, SDescribeStmt* pStmt) { + SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId}; + strcpy(name.dbname, pStmt->dbName); + strcpy(name.tname, pStmt->tableName); + int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name); + if (TSDB_CODE_SUCCESS == code) { + code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache); + } + return code; +} + static int32_t collectMetaKeyFromCreateStream(SCollectMetaKeyCxt* pCxt, SCreateStreamStmt* pStmt) { return collectMetaKeyFromQuery(pCxt, pStmt->pQuery); } @@ -365,6 +381,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { return collectMetaKeyFromSetOperator(pCxt, (SSetOperator*)pStmt); case QUERY_NODE_SELECT_STMT: return collectMetaKeyFromSelect(pCxt, (SSelectStmt*)pStmt); + case QUERY_NODE_ALTER_DATABASE_STMT: + return collectMetaKeyFromAlterDatabase(pCxt, (SAlterDatabaseStmt*)pStmt); case QUERY_NODE_CREATE_TABLE_STMT: return collectMetaKeyFromCreateTable(pCxt, (SCreateTableStmt*)pStmt); case QUERY_NODE_CREATE_MULTI_TABLE_STMT: @@ -381,6 +399,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { return collectMetaKeyFromCreateTopic(pCxt, (SCreateTopicStmt*)pStmt); case QUERY_NODE_EXPLAIN_STMT: return collectMetaKeyFromExplain(pCxt, (SExplainStmt*)pStmt); + case QUERY_NODE_DESCRIBE_STMT: + return collectMetaKeyFromDescribe(pCxt, (SDescribeStmt*)pStmt); case QUERY_NODE_CREATE_STREAM_STMT: return collectMetaKeyFromCreateStream(pCxt, (SCreateStreamStmt*)pStmt); case QUERY_NODE_SHOW_DNODES_STMT: diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index efe0bd75b2..54c8a18218 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -1006,7 +1006,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint } SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i]]; - char* tmpTokenBuf = taosMemoryCalloc(1, sToken.n); // this can be optimize with parse column + char* tmpTokenBuf = taosMemoryCalloc(1, sToken.n); // todo this can be optimize with parse column code = checkAndTrimValue(&sToken, tmpTokenBuf, &pCxt->msg); if (code != TSDB_CODE_SUCCESS) { taosMemoryFree(tmpTokenBuf); @@ -1018,7 +1018,11 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint taosMemoryFree(tmpTokenBuf); goto end; } - code = parseJsontoTagData(sToken.z, pTagVals, &pTag, &pCxt->msg); + if (isNullStr(&sToken)) { + code = tTagNew(pTagVals, 1, true, &pTag); + } else { + code = parseJsontoTagData(sToken.z, pTagVals, &pTag, &pCxt->msg); + } taosMemoryFree(tmpTokenBuf); if (code != TSDB_CODE_SUCCESS) { goto end; @@ -1526,10 +1530,13 @@ typedef struct SInsertParseSyntaxCxt { } SInsertParseSyntaxCxt; static int32_t skipParentheses(SInsertParseSyntaxCxt* pCxt) { - SToken sToken; + SToken sToken; + int32_t expectRightParenthesis = 1; while (1) { NEXT_TOKEN(pCxt->pSql, sToken); - if (TK_NK_RP == sToken.type) { + if (TK_NK_LP == sToken.type) { + ++expectRightParenthesis; + } else if (TK_NK_RP == sToken.type && 0 == --expectRightParenthesis) { break; } if (0 == sToken.n) { @@ -2036,6 +2043,10 @@ int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TA return TSDB_CODE_QRY_APP_ERROR; } + if (pDataBlock->pTableMeta->tableType != TSDB_SUPER_TABLE && pDataBlock->pTableMeta->tableType != TSDB_CHILD_TABLE) { + return TSDB_CODE_TSC_STMT_API_ERROR; + } + SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta); if (tags->numOfBound <= 0) { *fieldNum = 0; diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 685c299c01..284a3a620b 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -41,6 +41,7 @@ static SKeyword keywordTable[] = { {"AS", TK_AS}, {"ASC", TK_ASC}, {"AT_ONCE", TK_AT_ONCE}, + {"BALANCE", TK_BALANCE}, {"BETWEEN", TK_BETWEEN}, {"BINARY", TK_BINARY}, {"BIGINT", TK_BIGINT}, @@ -64,6 +65,7 @@ static SKeyword keywordTable[] = { {"CONSUMER", TK_CONSUMER}, {"COUNT", TK_COUNT}, {"CREATE", TK_CREATE}, + {"CONTAINS", TK_CONTAINS}, {"DATABASE", TK_DATABASE}, {"DATABASES", TK_DATABASES}, {"DAYS", TK_DAYS}, @@ -115,6 +117,7 @@ static SKeyword keywordTable[] = { {"LOCAL", TK_LOCAL}, {"MATCH", TK_MATCH}, {"MAXROWS", TK_MAXROWS}, + {"MERGE", TK_MERGE}, {"MINROWS", TK_MINROWS}, {"MINUS", TK_MINUS}, {"MNODE", TK_MNODE}, @@ -150,6 +153,7 @@ static SKeyword keywordTable[] = { {"QUERY", TK_QUERY}, {"RATIO", TK_RATIO}, {"READ", TK_READ}, + {"REDISTRIBUTE", TK_REDISTRIBUTE}, {"RENAME", TK_RENAME}, {"REPLICA", TK_REPLICA}, {"RESET", TK_RESET}, @@ -170,6 +174,7 @@ static SKeyword keywordTable[] = { {"SNODE", TK_SNODE}, {"SNODES", TK_SNODES}, {"SOFFSET", TK_SOFFSET}, + // {"SPLIT", TK_SPLIT}, {"STABLE", TK_STABLE}, {"STABLES", TK_STABLES}, {"STATE", TK_STATE}, @@ -207,6 +212,7 @@ static SKeyword keywordTable[] = { {"VARCHAR", TK_VARCHAR}, {"VARIABLES", TK_VARIABLES}, {"VERBOSE", TK_VERBOSE}, + {"VGROUP", TK_VGROUP}, {"VGROUPS", TK_VGROUPS}, {"VNODES", TK_VNODES}, {"WAL", TK_WAL}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index f1892d0040..96a5c09bbf 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -103,15 +103,14 @@ static int32_t collectUseTable(const SName* pName, SHashObj* pDbs) { static int32_t getTableMetaImpl(STranslateContext* pCxt, const SName* pName, STableMeta** pMeta) { SParseContext* pParCxt = pCxt->pParseCxt; - int32_t code = TSDB_CODE_SUCCESS; - if (pParCxt->async) { - code = getTableMetaFromCache(pCxt->pMetaCache, pName, pMeta); - } else { - code = collectUseDatabase(pName, pCxt->pDbs); - if (TSDB_CODE_SUCCESS == code) { - code = collectUseTable(pName, pCxt->pTables); - } - if (TSDB_CODE_SUCCESS == code) { + int32_t code = collectUseDatabase(pName, pCxt->pDbs); + if (TSDB_CODE_SUCCESS == code) { + code = collectUseTable(pName, pCxt->pTables); + } + if (TSDB_CODE_SUCCESS == code) { + if (pParCxt->async) { + code = getTableMetaFromCache(pCxt->pMetaCache, pName, pMeta); + } else { code = catalogGetTableMeta(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pMeta); } } @@ -150,12 +149,11 @@ static int32_t getDBVgInfoImpl(STranslateContext* pCxt, const SName* pName, SArr SParseContext* pParCxt = pCxt->pParseCxt; char fullDbName[TSDB_DB_FNAME_LEN]; tNameGetFullDbName(pName, fullDbName); - int32_t code = TSDB_CODE_SUCCESS; - if (pParCxt->async) { - code = getDbVgInfoFromCache(pCxt->pMetaCache, fullDbName, pVgInfo); - } else { - code = collectUseDatabaseImpl(fullDbName, pCxt->pDbs); - if (TSDB_CODE_SUCCESS == code) { + int32_t code = collectUseDatabaseImpl(fullDbName, pCxt->pDbs); + if (TSDB_CODE_SUCCESS == code) { + if (pParCxt->async) { + code = getDbVgInfoFromCache(pCxt->pMetaCache, fullDbName, pVgInfo); + } else { code = catalogGetDBVgInfo(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, fullDbName, pVgInfo); } } @@ -175,15 +173,14 @@ static int32_t getDBVgInfo(STranslateContext* pCxt, const char* pDbName, SArray* static int32_t getTableHashVgroupImpl(STranslateContext* pCxt, const SName* pName, SVgroupInfo* pInfo) { SParseContext* pParCxt = pCxt->pParseCxt; - int32_t code = TSDB_CODE_SUCCESS; - if (pParCxt->async) { - code = getTableVgroupFromCache(pCxt->pMetaCache, pName, pInfo); - } else { - code = collectUseDatabase(pName, pCxt->pDbs); - if (TSDB_CODE_SUCCESS == code) { - code = collectUseTable(pName, pCxt->pTables); - } - if (TSDB_CODE_SUCCESS == code) { + int32_t code = collectUseDatabase(pName, pCxt->pDbs); + if (TSDB_CODE_SUCCESS == code) { + code = collectUseTable(pName, pCxt->pTables); + } + if (TSDB_CODE_SUCCESS == code) { + if (pParCxt->async) { + code = getTableVgroupFromCache(pCxt->pMetaCache, pName, pInfo); + } else { code = catalogGetTableHashVgroup(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pInfo); } } @@ -203,12 +200,11 @@ static int32_t getTableHashVgroup(STranslateContext* pCxt, const char* pDbName, static int32_t getDBVgVersion(STranslateContext* pCxt, const char* pDbFName, int32_t* pVersion, int64_t* pDbId, int32_t* pTableNum) { SParseContext* pParCxt = pCxt->pParseCxt; - int32_t code = TSDB_CODE_SUCCESS; - if (pParCxt->async) { - code = getDbVgVersionFromCache(pCxt->pMetaCache, pDbFName, pVersion, pDbId, pTableNum); - } else { - code = collectUseDatabaseImpl(pDbFName, pCxt->pDbs); - if (TSDB_CODE_SUCCESS == code) { + int32_t code = collectUseDatabaseImpl(pDbFName, pCxt->pDbs); + if (TSDB_CODE_SUCCESS == code) { + if (pParCxt->async) { + code = getDbVgVersionFromCache(pCxt->pMetaCache, pDbFName, pVersion, pDbId, pTableNum); + } else { code = catalogGetDBVgVersion(pParCxt->pCatalog, pDbFName, pVersion, pDbId, pTableNum); } } @@ -224,12 +220,11 @@ static int32_t getDBCfg(STranslateContext* pCxt, const char* pDbName, SDbCfgInfo tNameSetDbName(&name, pCxt->pParseCxt->acctId, pDbName, strlen(pDbName)); char dbFname[TSDB_DB_FNAME_LEN] = {0}; tNameGetFullDbName(&name, dbFname); - int32_t code = TSDB_CODE_SUCCESS; - if (pParCxt->async) { - code = getDbCfgFromCache(pCxt->pMetaCache, dbFname, pInfo); - } else { - code = collectUseDatabaseImpl(dbFname, pCxt->pDbs); - if (TSDB_CODE_SUCCESS == code) { + int32_t code = collectUseDatabaseImpl(dbFname, pCxt->pDbs); + if (TSDB_CODE_SUCCESS == code) { + if (pParCxt->async) { + code = getDbCfgFromCache(pCxt->pMetaCache, dbFname, pInfo); + } else { code = catalogGetDBCfg(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, dbFname, pInfo); } } @@ -817,6 +812,10 @@ static EDealRes translateArithmeticOperator(STranslateContext* pCxt, SOperatorNo return DEAL_RES_CONTINUE; } +static bool dataTypeEqual(const SDataType* l, const SDataType* r) { + return (l->type == r->type && l->bytes == r->bytes && l->precision == r->precision && l->scale == r->scale); +} + static EDealRes translateComparisonOperator(STranslateContext* pCxt, SOperatorNode* pOp) { SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; @@ -824,7 +823,24 @@ static EDealRes translateComparisonOperator(STranslateContext* pCxt, SOperatorNo return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); } if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) { - ((SExprNode*)pOp->pRight)->resType = ((SExprNode*)pOp->pLeft)->resType; + SNodeListNode* pRight = (SNodeListNode*)pOp->pRight; + bool first = true; + SDataType targetDt = {0}; + SNode* pNode = NULL; + FOREACH(pNode, pRight->pNodeList) { + SDataType dt = ((SExprNode*)pNode)->resType; + if (first) { + targetDt = dt; + if (targetDt.type != TSDB_DATA_TYPE_NULL) { + first = false; + } + } else if (dt.type != targetDt.type && dt.type != TSDB_DATA_TYPE_NULL) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)pNode)->aliasName); + } else if (dt.bytes > targetDt.bytes) { + targetDt.bytes = dt.bytes; + } + } + pRight->dataType = targetDt; } if (nodesIsRegularOp(pOp)) { if (!IS_VAR_DATA_TYPE(((SExprNode*)(pOp->pLeft))->resType.type)) { @@ -847,8 +863,12 @@ static EDealRes translateJsonOperator(STranslateContext* pCxt, SOperatorNode* pO if (TSDB_DATA_TYPE_JSON != ldt.type || TSDB_DATA_TYPE_BINARY != rdt.type) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); } - pOp->node.resType.type = TSDB_DATA_TYPE_JSON; - pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_JSON].bytes; + if (pOp->opType == OP_TYPE_JSON_GET_VALUE) { + pOp->node.resType.type = TSDB_DATA_TYPE_JSON; + } else if (pOp->opType == OP_TYPE_JSON_CONTAINS) { + pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; + } + pOp->node.resType.bytes = tDataTypes[pOp->node.resType.type].bytes; return DEAL_RES_CONTINUE; } @@ -2011,10 +2031,6 @@ static SNode* createSetOperProject(const char* pTableAlias, SNode* pNode) { return (SNode*)pCol; } -static bool dataTypeEqual(const SDataType* l, const SDataType* r) { - return (l->type == r->type && l->bytes == r->bytes && l->precision == r->precision && l->scale == r->scale); -} - static int32_t createCastFunc(STranslateContext* pCxt, SNode* pExpr, SDataType dt, SNode** pCast) { SFunctionNode* pFunc = nodesMakeNode(QUERY_NODE_FUNCTION); if (NULL == pFunc) { @@ -2903,7 +2919,6 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt, } } - taosArrayDestroy(dbCfg.pRetensions); return code; } @@ -3608,6 +3623,55 @@ static int32_t translateRevoke(STranslateContext* pCxt, SRevokeStmt* pStmt) { return buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &req); } +static int32_t translateBalanceVgroup(STranslateContext* pCxt, SBalanceVgroupStmt* pStmt) { + SBalanceVgroupReq req = {0}; + return buildCmdMsg(pCxt, TDMT_MND_BALANCE_VGROUP, (FSerializeFunc)tSerializeSBalanceVgroupReq, &req); +} + +static int32_t translateMergeVgroup(STranslateContext* pCxt, SMergeVgroupStmt* pStmt) { + SMergeVgroupReq req = {.vgId1 = pStmt->vgId1, .vgId2 = pStmt->vgId2}; + return buildCmdMsg(pCxt, TDMT_MND_MERGE_VGROUP, (FSerializeFunc)tSerializeSMergeVgroupReq, &req); +} + +static int32_t checkDnodeIds(STranslateContext* pCxt, SRedistributeVgroupStmt* pStmt) { + int32_t numOfDnodes = LIST_LENGTH(pStmt->pDnodes); + if (numOfDnodes > 3 || numOfDnodes < 1) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG); + } + + SNode* pNode = NULL; + FOREACH(pNode, pStmt->pDnodes) { + SValueNode* pVal = (SValueNode*)pNode; + if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { + return pCxt->errCode; + } + } + + pStmt->dnodeId1 = getBigintFromValueNode((SValueNode*)nodesListGetNode(pStmt->pDnodes, 0)); + pStmt->dnodeId2 = -1; + pStmt->dnodeId3 = -1; + if (numOfDnodes > 1) { + pStmt->dnodeId2 = getBigintFromValueNode((SValueNode*)nodesListGetNode(pStmt->pDnodes, 1)); + } + if (numOfDnodes > 2) { + pStmt->dnodeId3 = getBigintFromValueNode((SValueNode*)nodesListGetNode(pStmt->pDnodes, 2)); + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t translateRedistributeVgroup(STranslateContext* pCxt, SRedistributeVgroupStmt* pStmt) { + SRedistributeVgroupReq req = {.vgId = pStmt->vgId}; + int32_t code = checkDnodeIds(pCxt, pStmt); + if (TSDB_CODE_SUCCESS == code) { + req.dnodeId1 = pStmt->dnodeId1; + req.dnodeId2 = pStmt->dnodeId2; + req.dnodeId3 = pStmt->dnodeId3; + code = buildCmdMsg(pCxt, TDMT_MND_REDISTRIBUTE_VGROUP, (FSerializeFunc)tSerializeSRedistributeVgroupReq, &req); + } + return code; +} + static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pNode)) { @@ -3730,6 +3794,15 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_REVOKE_STMT: code = translateRevoke(pCxt, (SRevokeStmt*)pNode); break; + case QUERY_NODE_BALANCE_VGROUP_STMT: + code = translateBalanceVgroup(pCxt, (SBalanceVgroupStmt*)pNode); + break; + case QUERY_NODE_MERGE_VGROUP_STMT: + code = translateMergeVgroup(pCxt, (SMergeVgroupStmt*)pNode); + break; + case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT: + code = translateRedistributeVgroup(pCxt, (SRedistributeVgroupStmt*)pNode); + break; default: break; } @@ -5012,6 +5085,10 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { pQuery->haveResultSet = true; pQuery->msgType = TDMT_VND_QUERY; break; + case QUERY_NODE_DELETE_STMT: + pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE; + pQuery->msgType = TDMT_VND_DELETE; + break; case QUERY_NODE_VNODE_MODIF_STMT: pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE; pQuery->msgType = toMsgType(((SVnodeModifOpStmt*)pQuery->pRoot)->sqlNodeType); diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index f30cc1111f..29443876a6 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -180,6 +180,8 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "Value too long for column/tag: %s"; case TSDB_CODE_PAR_INVALID_DELETE_WHERE: return "The DELETE statement must have a definite time window range"; + case TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG: + return "The REDISTRIBUTE VGROUP statement only support 1 to 3 dnodes"; case TSDB_CODE_OUT_OF_MEMORY: return "Out of memory"; default: @@ -482,20 +484,6 @@ static int32_t buildDbReq(SHashObj* pDbsHash, SArray** pDbs) { return TSDB_CODE_SUCCESS; } -static int32_t buildTableMetaReq(SHashObj* pTableMetaHash, SArray** pTableMeta) { - return buildTableReq(pTableMetaHash, pTableMeta); -} - -static int32_t buildDbVgroupReq(SHashObj* pDbVgroupHash, SArray** pDbVgroup) { - return buildDbReq(pDbVgroupHash, pDbVgroup); -} - -static int32_t buildTableVgroupReq(SHashObj* pTableVgroupHash, SArray** pTableVgroup) { - return buildTableReq(pTableVgroupHash, pTableVgroup); -} - -static int32_t buildDbCfgReq(SHashObj* pDbCfgHash, SArray** pDbCfg) { return buildDbReq(pDbCfgHash, pDbCfg); } - static int32_t buildUserAuthReq(SHashObj* pUserAuthHash, SArray** pUserAuth) { if (NULL != pUserAuthHash) { *pUserAuth = taosArrayInit(taosHashGetSize(pUserAuthHash), sizeof(SUserAuthInfo)); @@ -535,15 +523,18 @@ static int32_t buildUdfReq(SHashObj* pUdfHash, SArray** pUdf) { } int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq) { - int32_t code = buildTableMetaReq(pMetaCache->pTableMeta, &pCatalogReq->pTableMeta); + int32_t code = buildTableReq(pMetaCache->pTableMeta, &pCatalogReq->pTableMeta); if (TSDB_CODE_SUCCESS == code) { - code = buildDbVgroupReq(pMetaCache->pDbVgroup, &pCatalogReq->pDbVgroup); + code = buildDbReq(pMetaCache->pDbVgroup, &pCatalogReq->pDbVgroup); } if (TSDB_CODE_SUCCESS == code) { - code = buildTableVgroupReq(pMetaCache->pTableVgroup, &pCatalogReq->pTableHash); + code = buildTableReq(pMetaCache->pTableVgroup, &pCatalogReq->pTableHash); } if (TSDB_CODE_SUCCESS == code) { - code = buildDbCfgReq(pMetaCache->pDbCfg, &pCatalogReq->pDbCfg); + code = buildDbReq(pMetaCache->pDbCfg, &pCatalogReq->pDbCfg); + } + if (TSDB_CODE_SUCCESS == code) { + code = buildDbReq(pMetaCache->pDbInfo, &pCatalogReq->pDbInfo); } if (TSDB_CODE_SUCCESS == code) { code = buildUserAuthReq(pMetaCache->pUserAuth, &pCatalogReq->pUser); @@ -554,51 +545,39 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog return code; } -static int32_t putTableMetaToCache(const SArray* pTableMetaReq, const SArray* pTableMetaData, SHashObj* pTableMeta) { - int32_t ntables = taosArrayGetSize(pTableMetaReq); +static int32_t putMetaDataToHash(const char* pKey, int32_t len, const SArray* pData, int32_t index, SHashObj* pHash) { + SMetaRes* pRes = taosArrayGet(pData, index); + return taosHashPut(pHash, pKey, len, &pRes, POINTER_BYTES); +} + +static int32_t getMetaDataFromHash(const char* pKey, int32_t len, SHashObj* pHash, void** pOutput) { + SMetaRes** pRes = taosHashGet(pHash, pKey, len); + if (NULL == pRes || NULL == *pRes) { + return TSDB_CODE_PAR_INTERNAL_ERROR; + } + if (TSDB_CODE_SUCCESS == (*pRes)->code) { + *pOutput = (*pRes)->pRes; + } + return (*pRes)->code; +} + +static int32_t putTableDataToCache(const SArray* pTableReq, const SArray* pTableData, SHashObj* pTable) { + int32_t ntables = taosArrayGetSize(pTableReq); for (int32_t i = 0; i < ntables; ++i) { char fullName[TSDB_TABLE_FNAME_LEN]; - tNameExtractFullName(taosArrayGet(pTableMetaReq, i), fullName); - if (TSDB_CODE_SUCCESS != - taosHashPut(pTableMeta, fullName, strlen(fullName), taosArrayGet(pTableMetaData, i), POINTER_BYTES)) { + tNameExtractFullName(taosArrayGet(pTableReq, i), fullName); + if (TSDB_CODE_SUCCESS != putMetaDataToHash(fullName, strlen(fullName), pTableData, i, pTable)) { return TSDB_CODE_OUT_OF_MEMORY; } } return TSDB_CODE_SUCCESS; } -static int32_t putDbVgroupToCache(const SArray* pDbVgroupReq, const SArray* pDbVgroupData, SHashObj* pDbVgroup) { - int32_t nvgs = taosArrayGetSize(pDbVgroupReq); +static int32_t putDbDataToCache(const SArray* pDbReq, const SArray* pDbData, SHashObj* pDb) { + int32_t nvgs = taosArrayGetSize(pDbReq); for (int32_t i = 0; i < nvgs; ++i) { - char* pDbFName = taosArrayGet(pDbVgroupReq, i); - if (TSDB_CODE_SUCCESS != - taosHashPut(pDbVgroup, pDbFName, strlen(pDbFName), taosArrayGet(pDbVgroupData, i), POINTER_BYTES)) { - return TSDB_CODE_OUT_OF_MEMORY; - } - } - return TSDB_CODE_SUCCESS; -} - -static int32_t putTableVgroupToCache(const SArray* pTableVgroupReq, const SArray* pTableVgroupData, - SHashObj* pTableVgroup) { - int32_t ntables = taosArrayGetSize(pTableVgroupReq); - for (int32_t i = 0; i < ntables; ++i) { - char fullName[TSDB_TABLE_FNAME_LEN]; - tNameExtractFullName(taosArrayGet(pTableVgroupReq, i), fullName); - SVgroupInfo* pInfo = taosArrayGet(pTableVgroupData, i); - if (TSDB_CODE_SUCCESS != taosHashPut(pTableVgroup, fullName, strlen(fullName), &pInfo, POINTER_BYTES)) { - return TSDB_CODE_OUT_OF_MEMORY; - } - } - return TSDB_CODE_SUCCESS; -} - -static int32_t putDbCfgToCache(const SArray* pDbCfgReq, const SArray* pDbCfgData, SHashObj* pDbCfg) { - int32_t nvgs = taosArrayGetSize(pDbCfgReq); - for (int32_t i = 0; i < nvgs; ++i) { - char* pDbFName = taosArrayGet(pDbCfgReq, i); - SDbCfgInfo* pInfo = taosArrayGet(pDbCfgData, i); - if (TSDB_CODE_SUCCESS != taosHashPut(pDbCfg, pDbFName, strlen(pDbFName), &pInfo, POINTER_BYTES)) { + char* pDbFName = taosArrayGet(pDbReq, i); + if (TSDB_CODE_SUCCESS != putMetaDataToHash(pDbFName, strlen(pDbFName), pDbData, i, pDb)) { return TSDB_CODE_OUT_OF_MEMORY; } } @@ -611,7 +590,7 @@ static int32_t putUserAuthToCache(const SArray* pUserAuthReq, const SArray* pUse SUserAuthInfo* pUser = taosArrayGet(pUserAuthReq, i); char key[USER_AUTH_KEY_MAX_LEN] = {0}; int32_t len = userAuthToStringExt(pUser->user, pUser->dbFName, pUser->type, key); - if (TSDB_CODE_SUCCESS != taosHashPut(pUserAuth, key, len, taosArrayGet(pUserAuthData, i), sizeof(bool))) { + if (TSDB_CODE_SUCCESS != putMetaDataToHash(key, len, pUserAuthData, i, pUserAuth)) { return TSDB_CODE_OUT_OF_MEMORY; } } @@ -621,9 +600,8 @@ static int32_t putUserAuthToCache(const SArray* pUserAuthReq, const SArray* pUse static int32_t putUdfToCache(const SArray* pUdfReq, const SArray* pUdfData, SHashObj* pUdf) { int32_t num = taosArrayGetSize(pUdfReq); for (int32_t i = 0; i < num; ++i) { - char* pFunc = taosArrayGet(pUdfReq, i); - SFuncInfo* pInfo = taosArrayGet(pUdfData, i); - if (TSDB_CODE_SUCCESS != taosHashPut(pUdf, pFunc, strlen(pFunc), &pInfo, POINTER_BYTES)) { + char* pFunc = taosArrayGet(pUdfReq, i); + if (TSDB_CODE_SUCCESS != putMetaDataToHash(pFunc, strlen(pFunc), pUdfData, i, pUdf)) { return TSDB_CODE_OUT_OF_MEMORY; } } @@ -631,15 +609,18 @@ static int32_t putUdfToCache(const SArray* pUdfReq, const SArray* pUdfData, SHas } int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache) { - int32_t code = putTableMetaToCache(pCatalogReq->pTableMeta, pMetaData->pTableMeta, pMetaCache->pTableMeta); + int32_t code = putTableDataToCache(pCatalogReq->pTableMeta, pMetaData->pTableMeta, pMetaCache->pTableMeta); if (TSDB_CODE_SUCCESS == code) { - code = putDbVgroupToCache(pCatalogReq->pDbVgroup, pMetaData->pDbVgroup, pMetaCache->pDbVgroup); + code = putDbDataToCache(pCatalogReq->pDbVgroup, pMetaData->pDbVgroup, pMetaCache->pDbVgroup); } if (TSDB_CODE_SUCCESS == code) { - code = putTableVgroupToCache(pCatalogReq->pTableHash, pMetaData->pTableHash, pMetaCache->pTableVgroup); + code = putTableDataToCache(pCatalogReq->pTableHash, pMetaData->pTableHash, pMetaCache->pTableVgroup); } if (TSDB_CODE_SUCCESS == code) { - code = putDbCfgToCache(pCatalogReq->pDbCfg, pMetaData->pDbCfg, pMetaCache->pDbCfg); + code = putDbDataToCache(pCatalogReq->pDbCfg, pMetaData->pDbCfg, pMetaCache->pDbCfg); + } + if (TSDB_CODE_SUCCESS == code) { + code = putDbDataToCache(pCatalogReq->pDbInfo, pMetaData->pDbInfo, pMetaCache->pDbInfo); } if (TSDB_CODE_SUCCESS == code) { code = putUserAuthToCache(pCatalogReq->pUser, pMetaData->pUser, pMetaCache->pUserAuth); @@ -679,16 +660,15 @@ int32_t reserveTableMetaInCacheExt(const SName* pName, SParseMetaCache* pMetaCac int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta) { char fullName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(pName, fullName); - STableMeta** pRes = taosHashGet(pMetaCache->pTableMeta, fullName, strlen(fullName)); - if (NULL == pRes || NULL == *pRes) { - parserError("getTableMetaFromCache error: %s", fullName); - return TSDB_CODE_PAR_INTERNAL_ERROR; + STableMeta* pTableMeta = NULL; + int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableMeta, (void**)&pTableMeta); + if (TSDB_CODE_SUCCESS == code) { + *pMeta = tableMetaDup(pTableMeta); + if (NULL == *pMeta) { + code = TSDB_CODE_OUT_OF_MEMORY; + } } - *pMeta = tableMetaDup(*pRes); - if (NULL == *pMeta) { - return TSDB_CODE_OUT_OF_MEMORY; - } - return TSDB_CODE_SUCCESS; + return code; } static int32_t reserveDbReqInCache(int32_t acctId, const char* pDb, SHashObj** pDbs) { @@ -708,19 +688,16 @@ int32_t reserveDbVgInfoInCache(int32_t acctId, const char* pDb, SParseMetaCache* } int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SArray** pVgInfo) { - SArray** pRes = taosHashGet(pMetaCache->pDbVgroup, pDbFName, strlen(pDbFName)); - if (NULL == pRes) { - parserError("getDbVgInfoFromCache error: %s", pDbFName); - return TSDB_CODE_PAR_INTERNAL_ERROR; - } - // *pRes is null, which is a legal value, indicating that the user DB has not been created - if (NULL != *pRes) { - *pVgInfo = taosArrayDup(*pRes); + SArray* pVgList = NULL; + int32_t code = getMetaDataFromHash(pDbFName, strlen(pDbFName), pMetaCache->pDbVgroup, (void**)&pVgList); + // pVgList is null, which is a legal value, indicating that the user DB has not been created + if (TSDB_CODE_SUCCESS == code && NULL != pVgList) { + *pVgInfo = taosArrayDup(pVgList); if (NULL == *pVgInfo) { - return TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; } } - return TSDB_CODE_SUCCESS; + return code; } int32_t reserveTableVgroupInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache) { @@ -736,30 +713,28 @@ int32_t reserveTableVgroupInCacheExt(const SName* pName, SParseMetaCache* pMetaC int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup) { char fullName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(pName, fullName); - SVgroupInfo** pRes = taosHashGet(pMetaCache->pTableVgroup, fullName, strlen(fullName)); - if (NULL == pRes || NULL == *pRes) { - parserError("getTableVgroupFromCache error: %s", fullName); - return TSDB_CODE_PAR_INTERNAL_ERROR; + SVgroupInfo* pVg = NULL; + int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableVgroup, (void**)&pVg); + if (TSDB_CODE_SUCCESS == code) { + memcpy(pVgroup, pVg, sizeof(SVgroupInfo)); } - memcpy(pVgroup, *pRes, sizeof(SVgroupInfo)); - return TSDB_CODE_SUCCESS; + return code; } int32_t reserveDbVgVersionInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache) { - return reserveDbReqInCache(acctId, pDb, &pMetaCache->pDbCfg); + return reserveDbReqInCache(acctId, pDb, &pMetaCache->pDbInfo); } int32_t getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId, int32_t* pTableNum) { - SDbInfo** pRes = taosHashGet(pMetaCache->pDbCfg, pDbFName, strlen(pDbFName)); - if (NULL == pRes || NULL == *pRes) { - parserError("getDbVgVersionFromCache error: %s", pDbFName); - return TSDB_CODE_PAR_INTERNAL_ERROR; + SDbInfo* pDbInfo = NULL; + int32_t code = getMetaDataFromHash(pDbFName, strlen(pDbFName), pMetaCache->pDbInfo, (void**)&pDbInfo); + if (TSDB_CODE_SUCCESS == code) { + *pVersion = pDbInfo->vgVer; + *pDbId = pDbInfo->dbId; + *pTableNum = pDbInfo->tbNum; } - *pVersion = (*pRes)->vgVer; - *pDbId = (*pRes)->dbId; - *pTableNum = (*pRes)->tbNum; - return TSDB_CODE_SUCCESS; + return code; } int32_t reserveDbCfgInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache) { @@ -767,13 +742,12 @@ int32_t reserveDbCfgInCache(int32_t acctId, const char* pDb, SParseMetaCache* pM } int32_t getDbCfgFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SDbCfgInfo* pInfo) { - SDbCfgInfo** pRes = taosHashGet(pMetaCache->pDbCfg, pDbFName, strlen(pDbFName)); - if (NULL == pRes || NULL == *pRes) { - parserError("getDbCfgFromCache error: %s", pDbFName); - return TSDB_CODE_PAR_INTERNAL_ERROR; + SDbCfgInfo* pDbCfg = NULL; + int32_t code = getMetaDataFromHash(pDbFName, strlen(pDbFName), pMetaCache->pDbCfg, (void**)&pDbCfg); + if (TSDB_CODE_SUCCESS == code) { + memcpy(pInfo, pDbCfg, sizeof(SDbCfgInfo)); } - memcpy(pInfo, *pRes, sizeof(SDbCfgInfo)); - return TSDB_CODE_SUCCESS; + return code; } static int32_t reserveUserAuthInCacheImpl(const char* pKey, int32_t len, SParseMetaCache* pMetaCache) { @@ -806,13 +780,12 @@ int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, const char* pUser, con bool* pPass) { char key[USER_AUTH_KEY_MAX_LEN] = {0}; int32_t len = userAuthToStringExt(pUser, pDbFName, type, key); - bool* pRes = taosHashGet(pMetaCache->pUserAuth, key, len); - if (NULL == pRes) { - parserError("getUserAuthFromCache error: %s, %s, %d", pUser, pDbFName, type); - return TSDB_CODE_PAR_INTERNAL_ERROR; + bool* pRes = NULL; + int32_t code = getMetaDataFromHash(key, len, pMetaCache->pUserAuth, (void**)&pRes); + if (TSDB_CODE_SUCCESS == code) { + *pPass = *pRes; } - *pPass = *pRes; - return TSDB_CODE_SUCCESS; + return code; } int32_t reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache) { @@ -826,11 +799,10 @@ int32_t reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache) { } int32_t getUdfInfoFromCache(SParseMetaCache* pMetaCache, const char* pFunc, SFuncInfo* pInfo) { - SFuncInfo** pRes = taosHashGet(pMetaCache->pUdf, pFunc, strlen(pFunc)); - if (NULL == pRes || NULL == *pRes) { - parserError("getUdfInfoFromCache error: %s", pFunc); - return TSDB_CODE_PAR_INTERNAL_ERROR; + SFuncInfo* pFuncInfo = NULL; + int32_t code = getMetaDataFromHash(pFunc, strlen(pFunc), pMetaCache->pUdf, (void**)&pFuncInfo); + if (TSDB_CODE_SUCCESS == code) { + memcpy(pInfo, pFuncInfo, sizeof(SFuncInfo)); } - memcpy(pInfo, *pRes, sizeof(SFuncInfo)); - return TSDB_CODE_SUCCESS; + return code; } diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index ed837ae20f..1626c05454 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -138,17 +138,17 @@ typedef union { #define ParseCTX_FETCH #define ParseCTX_STORE #define YYFALLBACK 1 -#define YYNSTATE 616 +#define YYNSTATE 615 #define YYNRULE 452 #define YYNTOKEN 238 -#define YY_MAX_SHIFT 615 -#define YY_MIN_SHIFTREDUCE 902 -#define YY_MAX_SHIFTREDUCE 1353 -#define YY_ERROR_ACTION 1354 -#define YY_ACCEPT_ACTION 1355 -#define YY_NO_ACTION 1356 -#define YY_MIN_REDUCE 1357 -#define YY_MAX_REDUCE 1808 +#define YY_MAX_SHIFT 614 +#define YY_MIN_SHIFTREDUCE 901 +#define YY_MAX_SHIFTREDUCE 1352 +#define YY_ERROR_ACTION 1353 +#define YY_ACCEPT_ACTION 1354 +#define YY_NO_ACTION 1355 +#define YY_MIN_REDUCE 1356 +#define YY_MAX_REDUCE 1807 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -217,223 +217,223 @@ typedef union { *********** Begin parsing tables **********************************************/ #define YY_ACTTAB_COUNT (2165) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 72, 355, 1655, 1642, 28, 230, 296, 1465, 1642, 608, - /* 10 */ 607, 313, 35, 33, 530, 36, 34, 32, 31, 30, - /* 20 */ 305, 1481, 1167, 1639, 530, 490, 106, 1477, 1639, 389, - /* 30 */ 1671, 390, 1389, 428, 490, 277, 152, 349, 514, 1635, - /* 40 */ 1641, 529, 133, 1488, 1635, 1641, 1445, 1165, 513, 132, - /* 50 */ 533, 1369, 1625, 1488, 114, 533, 529, 494, 14, 530, - /* 60 */ 35, 33, 1294, 114, 1173, 1416, 932, 63, 305, 1684, - /* 70 */ 1167, 353, 82, 1656, 516, 1658, 1659, 512, 1786, 533, - /* 80 */ 110, 1, 1724, 56, 1532, 1308, 278, 1720, 1488, 1483, - /* 90 */ 147, 295, 112, 517, 1783, 1165, 1530, 529, 1786, 1578, - /* 100 */ 564, 112, 39, 612, 936, 937, 14, 145, 1731, 1732, - /* 110 */ 149, 1736, 1173, 1166, 1783, 492, 144, 1731, 1732, 563, - /* 120 */ 1736, 562, 561, 560, 407, 588, 587, 586, 320, 2, - /* 130 */ 585, 584, 583, 116, 578, 577, 576, 575, 574, 573, - /* 140 */ 572, 571, 123, 567, 1358, 36, 34, 32, 31, 30, - /* 150 */ 397, 612, 390, 1389, 142, 317, 1168, 1191, 38, 1671, - /* 160 */ 55, 1166, 1568, 1570, 1466, 96, 1526, 483, 95, 94, - /* 170 */ 93, 92, 91, 90, 89, 88, 87, 479, 388, 1171, - /* 180 */ 1172, 392, 1218, 1219, 1221, 1222, 1223, 1224, 1225, 509, - /* 190 */ 531, 1233, 1234, 1235, 1236, 1237, 1238, 36, 34, 32, - /* 200 */ 31, 30, 517, 482, 1168, 308, 581, 96, 1577, 150, + /* 0 */ 72, 354, 1654, 1641, 28, 230, 296, 1464, 1641, 607, + /* 10 */ 606, 313, 35, 33, 529, 36, 34, 32, 31, 30, + /* 20 */ 305, 1480, 1166, 1638, 529, 489, 106, 1476, 1638, 388, + /* 30 */ 1670, 389, 1388, 427, 489, 277, 152, 348, 513, 1634, + /* 40 */ 1640, 528, 133, 1487, 1634, 1640, 1444, 1164, 512, 132, + /* 50 */ 532, 1368, 1624, 1487, 114, 532, 528, 493, 14, 529, + /* 60 */ 35, 33, 1293, 114, 1172, 1415, 931, 63, 305, 1683, + /* 70 */ 1166, 352, 82, 1655, 515, 1657, 1658, 511, 1785, 532, + /* 80 */ 110, 1, 1723, 56, 1531, 1307, 278, 1719, 1487, 1482, + /* 90 */ 147, 295, 112, 516, 1782, 1164, 1529, 528, 1785, 1577, + /* 100 */ 563, 112, 39, 611, 935, 936, 14, 145, 1730, 1731, + /* 110 */ 149, 1735, 1172, 1165, 1782, 491, 144, 1730, 1731, 562, + /* 120 */ 1735, 561, 560, 559, 406, 587, 586, 585, 320, 2, + /* 130 */ 584, 583, 582, 116, 577, 576, 575, 574, 573, 572, + /* 140 */ 571, 570, 123, 566, 1357, 36, 34, 32, 31, 30, + /* 150 */ 396, 611, 389, 1388, 142, 317, 1167, 1190, 38, 1670, + /* 160 */ 55, 1165, 1567, 1569, 1465, 96, 1525, 482, 95, 94, + /* 170 */ 93, 92, 91, 90, 89, 88, 87, 478, 387, 1170, + /* 180 */ 1171, 391, 1217, 1218, 1220, 1221, 1222, 1223, 1224, 508, + /* 190 */ 530, 1232, 1233, 1234, 1235, 1236, 1237, 36, 34, 32, + /* 200 */ 31, 30, 516, 481, 1167, 308, 580, 96, 1576, 150, /* 210 */ 95, 94, 93, 92, 91, 90, 89, 88, 87, 288, - /* 220 */ 130, 407, 36, 34, 32, 31, 30, 1171, 1172, 1491, - /* 230 */ 1218, 1219, 1221, 1222, 1223, 1224, 1225, 509, 531, 1233, - /* 240 */ 1234, 1235, 1236, 1237, 1238, 35, 33, 343, 485, 480, - /* 250 */ 1355, 442, 441, 305, 1655, 1167, 440, 200, 252, 111, - /* 260 */ 437, 1518, 379, 436, 435, 434, 35, 33, 289, 447, - /* 270 */ 287, 286, 1001, 430, 305, 1479, 1167, 432, 129, 309, - /* 280 */ 1165, 79, 1671, 55, 455, 66, 150, 130, 150, 1003, - /* 290 */ 514, 14, 1205, 484, 115, 1639, 1490, 1173, 193, 431, - /* 300 */ 513, 1165, 1480, 949, 1625, 948, 161, 160, 321, 494, - /* 310 */ 450, 1635, 1641, 394, 2, 444, 1192, 1643, 1173, 1189, - /* 320 */ 192, 1684, 533, 490, 82, 1656, 516, 1658, 1659, 512, - /* 330 */ 24, 533, 950, 1350, 1724, 8, 612, 1639, 278, 1720, - /* 340 */ 36, 34, 32, 31, 30, 51, 1166, 1464, 50, 1786, - /* 350 */ 1786, 566, 114, 1635, 1641, 65, 294, 612, 1380, 194, - /* 360 */ 559, 147, 147, 1463, 533, 1783, 1783, 1166, 1357, 1039, - /* 370 */ 556, 555, 554, 1043, 553, 1045, 1046, 552, 1048, 549, - /* 380 */ 1379, 1054, 546, 1056, 1057, 543, 540, 7, 55, 1168, - /* 390 */ 112, 1190, 105, 104, 103, 102, 101, 100, 99, 98, - /* 400 */ 97, 32, 31, 30, 566, 146, 1731, 1732, 1625, 1736, - /* 410 */ 1168, 150, 1171, 1172, 1349, 1218, 1219, 1221, 1222, 1223, - /* 420 */ 1224, 1225, 509, 531, 1233, 1234, 1235, 1236, 1237, 1238, - /* 430 */ 1625, 569, 157, 1171, 1172, 463, 1218, 1219, 1221, 1222, - /* 440 */ 1223, 1224, 1225, 509, 531, 1233, 1234, 1235, 1236, 1237, - /* 450 */ 1238, 35, 33, 1239, 26, 1378, 564, 61, 466, 305, - /* 460 */ 60, 1167, 564, 150, 36, 34, 32, 31, 30, 63, - /* 470 */ 1406, 396, 35, 33, 392, 563, 1655, 562, 561, 560, - /* 480 */ 305, 563, 1167, 562, 561, 560, 1165, 1193, 530, 1318, - /* 490 */ 530, 1484, 443, 36, 34, 32, 31, 30, 1786, 1786, - /* 500 */ 354, 1645, 106, 1173, 1671, 1625, 1473, 1165, 55, 433, - /* 510 */ 1785, 147, 493, 456, 1783, 1783, 150, 1488, 1377, 1488, - /* 520 */ 9, 570, 513, 1460, 1173, 1419, 1625, 454, 476, 1316, - /* 530 */ 1317, 1319, 1320, 36, 34, 32, 31, 30, 1647, 279, - /* 540 */ 452, 9, 612, 1684, 439, 438, 83, 1656, 516, 1658, - /* 550 */ 1659, 512, 1166, 533, 1786, 1475, 1724, 1532, 1289, 315, - /* 560 */ 298, 1720, 143, 612, 310, 1786, 147, 130, 1625, 1530, - /* 570 */ 1783, 1256, 1301, 1166, 222, 1786, 1490, 148, 1191, 472, - /* 580 */ 1751, 1783, 348, 1738, 347, 442, 441, 1784, 530, 340, - /* 590 */ 440, 1783, 1532, 111, 437, 1168, 1532, 436, 435, 434, - /* 600 */ 364, 582, 580, 316, 1531, 1569, 1570, 1735, 1530, 342, - /* 610 */ 338, 1293, 221, 1376, 936, 937, 1168, 1488, 1171, 1172, - /* 620 */ 1257, 1218, 1219, 1221, 1222, 1223, 1224, 1225, 509, 531, - /* 630 */ 1233, 1234, 1235, 1236, 1237, 1238, 150, 11, 10, 1171, - /* 640 */ 1172, 1262, 1218, 1219, 1221, 1222, 1223, 1224, 1225, 509, - /* 650 */ 531, 1233, 1234, 1235, 1236, 1237, 1238, 35, 33, 276, - /* 660 */ 1655, 1189, 530, 1625, 530, 305, 1375, 1167, 372, 54, - /* 670 */ 1374, 384, 1373, 1471, 365, 197, 406, 508, 27, 303, - /* 680 */ 1251, 1252, 1253, 1254, 1255, 1259, 1260, 1261, 1671, 385, - /* 690 */ 530, 1488, 1165, 1488, 1244, 530, 514, 1372, 1565, 530, - /* 700 */ 1191, 432, 1485, 1371, 318, 159, 513, 1604, 1191, 1173, - /* 710 */ 1625, 464, 130, 530, 1151, 1152, 1625, 1194, 1270, 1488, - /* 720 */ 1625, 1490, 1625, 431, 1488, 527, 2, 1684, 1488, 1258, - /* 730 */ 83, 1656, 516, 1658, 1659, 512, 948, 533, 1368, 1367, - /* 740 */ 1724, 1220, 1488, 498, 298, 1720, 1799, 1625, 612, 120, - /* 750 */ 1263, 1743, 1289, 1625, 1366, 1758, 1365, 1364, 1166, 383, - /* 760 */ 1363, 426, 378, 377, 376, 375, 374, 371, 370, 369, - /* 770 */ 368, 367, 363, 362, 361, 360, 359, 358, 357, 356, - /* 780 */ 530, 131, 530, 530, 1738, 1370, 258, 25, 1625, 1625, - /* 790 */ 468, 1738, 528, 1362, 243, 319, 1361, 501, 256, 53, - /* 800 */ 1613, 1168, 52, 1360, 1625, 506, 1625, 1625, 1734, 1488, - /* 810 */ 1625, 1488, 1488, 185, 1446, 1733, 183, 1292, 187, 162, - /* 820 */ 189, 186, 1176, 188, 1171, 1172, 46, 1218, 1219, 1221, - /* 830 */ 1222, 1223, 1224, 1225, 509, 531, 1233, 1234, 1235, 1236, - /* 840 */ 1237, 1238, 206, 1625, 55, 330, 1625, 36, 34, 32, - /* 850 */ 31, 30, 191, 1625, 1401, 190, 1167, 1399, 209, 11, - /* 860 */ 10, 1352, 1353, 1220, 46, 37, 37, 1315, 37, 232, - /* 870 */ 558, 1220, 457, 118, 119, 78, 445, 120, 1175, 448, - /* 880 */ 81, 1165, 538, 225, 973, 74, 119, 477, 1179, 120, - /* 890 */ 496, 216, 1672, 279, 121, 1390, 1655, 1527, 1173, 211, - /* 900 */ 425, 974, 119, 1754, 491, 251, 1264, 1226, 322, 1124, - /* 910 */ 234, 59, 58, 352, 522, 240, 156, 1205, 1032, 1189, - /* 920 */ 224, 346, 3, 1060, 1671, 1256, 1248, 1064, 499, 227, - /* 930 */ 1070, 229, 493, 275, 5, 1068, 336, 612, 332, 328, - /* 940 */ 153, 323, 513, 122, 1178, 329, 1625, 1166, 325, 284, - /* 950 */ 1001, 285, 312, 311, 248, 1135, 158, 366, 1567, 373, - /* 960 */ 381, 380, 1181, 1684, 382, 386, 83, 1656, 516, 1658, - /* 970 */ 1659, 512, 150, 533, 1257, 1655, 1724, 1195, 1198, 387, - /* 980 */ 298, 1720, 143, 395, 502, 398, 399, 1174, 1197, 400, - /* 990 */ 1168, 165, 167, 1199, 170, 1262, 172, 404, 401, 403, - /* 1000 */ 1752, 1196, 175, 1671, 1173, 62, 405, 408, 178, 427, - /* 1010 */ 1173, 514, 86, 1171, 1172, 429, 293, 1478, 1608, 182, - /* 1020 */ 1474, 513, 184, 124, 249, 1625, 125, 1476, 1655, 1472, - /* 1030 */ 126, 127, 27, 303, 1251, 1252, 1253, 1254, 1255, 1259, - /* 1040 */ 1260, 1261, 1684, 534, 195, 83, 1656, 516, 1658, 1659, - /* 1050 */ 512, 458, 533, 1177, 198, 1724, 1671, 462, 465, 298, - /* 1060 */ 1720, 1799, 201, 467, 514, 469, 459, 470, 478, 204, - /* 1070 */ 1781, 1194, 1765, 207, 513, 520, 1764, 475, 1625, 1655, - /* 1080 */ 297, 1755, 210, 481, 215, 6, 487, 1745, 474, 217, - /* 1090 */ 1655, 1289, 113, 1193, 40, 1684, 1182, 503, 83, 1656, - /* 1100 */ 516, 1658, 1659, 512, 1739, 533, 218, 1671, 1724, 137, - /* 1110 */ 500, 299, 298, 1720, 1799, 514, 18, 518, 1671, 1185, - /* 1120 */ 519, 1705, 1576, 1742, 1782, 513, 514, 223, 226, 1625, - /* 1130 */ 531, 1233, 1234, 228, 494, 1575, 513, 1802, 1655, 523, - /* 1140 */ 1625, 307, 236, 497, 524, 494, 1684, 238, 504, 263, - /* 1150 */ 1656, 516, 1658, 1659, 512, 525, 533, 1684, 250, 71, - /* 1160 */ 263, 1656, 516, 1658, 1659, 512, 1671, 533, 1489, 73, - /* 1170 */ 1461, 536, 253, 245, 514, 1786, 611, 47, 1655, 255, - /* 1180 */ 136, 264, 274, 265, 513, 1619, 1786, 149, 1625, 257, - /* 1190 */ 1618, 1783, 57, 1617, 324, 1614, 326, 327, 147, 331, - /* 1200 */ 1160, 1161, 1783, 154, 1612, 1684, 1671, 333, 84, 1656, - /* 1210 */ 516, 1658, 1659, 512, 514, 533, 334, 335, 1724, 1611, - /* 1220 */ 180, 337, 1723, 1720, 513, 1610, 339, 1609, 1625, 341, - /* 1230 */ 1594, 155, 141, 1138, 344, 345, 1137, 1655, 424, 420, - /* 1240 */ 416, 412, 179, 1588, 1587, 1684, 350, 351, 84, 1656, - /* 1250 */ 516, 1658, 1659, 512, 1586, 533, 1585, 1107, 1724, 1109, - /* 1260 */ 117, 1542, 505, 1720, 1560, 1671, 1559, 64, 1558, 1557, - /* 1270 */ 177, 1556, 1555, 511, 1554, 1553, 1552, 1551, 1550, 1549, - /* 1280 */ 1548, 1547, 1546, 513, 1545, 1544, 1543, 1625, 1541, 1655, - /* 1290 */ 1540, 1539, 1538, 1537, 1536, 1535, 1534, 1533, 1655, 1418, - /* 1300 */ 1386, 140, 163, 939, 1684, 1385, 1602, 272, 1656, 516, - /* 1310 */ 1658, 1659, 512, 510, 533, 507, 1696, 1671, 938, 1596, - /* 1320 */ 108, 1584, 171, 1583, 109, 514, 1671, 176, 1573, 168, - /* 1330 */ 1467, 173, 967, 402, 514, 513, 1417, 1415, 1413, 1625, - /* 1340 */ 164, 1411, 391, 1409, 513, 393, 169, 174, 1625, 411, - /* 1350 */ 409, 166, 410, 415, 1655, 413, 1684, 1398, 414, 134, - /* 1360 */ 1656, 516, 1658, 1659, 512, 1684, 533, 417, 84, 1656, - /* 1370 */ 516, 1658, 1659, 512, 418, 533, 419, 422, 1724, 615, - /* 1380 */ 421, 423, 1671, 1721, 1397, 1384, 1469, 1074, 1073, 1468, - /* 1390 */ 514, 579, 1000, 247, 999, 998, 997, 581, 994, 993, - /* 1400 */ 513, 992, 495, 1800, 1625, 107, 181, 473, 1655, 1407, - /* 1410 */ 290, 604, 600, 596, 592, 246, 45, 1655, 1402, 291, - /* 1420 */ 446, 1684, 1400, 292, 273, 1656, 516, 1658, 1659, 512, - /* 1430 */ 449, 533, 1383, 451, 1382, 453, 1671, 85, 1601, 1145, - /* 1440 */ 80, 1595, 460, 241, 514, 1671, 1582, 1581, 1580, 1572, - /* 1450 */ 67, 203, 15, 514, 513, 208, 4, 37, 1625, 49, - /* 1460 */ 461, 135, 48, 513, 199, 43, 213, 1625, 16, 1314, - /* 1470 */ 1655, 205, 212, 214, 22, 1684, 526, 1307, 268, 1656, - /* 1480 */ 516, 1658, 1659, 512, 1684, 533, 128, 134, 1656, 516, - /* 1490 */ 1658, 1659, 512, 68, 533, 1645, 23, 220, 1671, 42, - /* 1500 */ 1655, 471, 17, 1286, 202, 1285, 514, 138, 1343, 1338, - /* 1510 */ 1332, 1337, 300, 1342, 1341, 486, 513, 301, 10, 19, - /* 1520 */ 1625, 1228, 1143, 302, 196, 1249, 29, 139, 1671, 151, - /* 1530 */ 1213, 1801, 1227, 12, 515, 20, 511, 1684, 21, 521, - /* 1540 */ 273, 1656, 516, 1658, 1659, 512, 513, 533, 13, 41, - /* 1550 */ 1625, 231, 1655, 1312, 233, 235, 69, 1571, 70, 237, - /* 1560 */ 1687, 1644, 242, 74, 1230, 532, 1183, 1684, 1655, 44, - /* 1570 */ 272, 1656, 516, 1658, 1659, 512, 239, 533, 535, 1697, - /* 1580 */ 1671, 1061, 537, 314, 539, 541, 1058, 542, 514, 1055, - /* 1590 */ 544, 545, 547, 1049, 548, 550, 1671, 1047, 513, 1053, - /* 1600 */ 551, 1052, 1625, 1051, 514, 304, 1050, 1038, 1655, 75, - /* 1610 */ 76, 1069, 77, 557, 513, 1067, 1066, 965, 1625, 1684, - /* 1620 */ 1655, 306, 273, 1656, 516, 1658, 1659, 512, 565, 533, - /* 1630 */ 989, 1007, 244, 568, 987, 1684, 1671, 986, 273, 1656, - /* 1640 */ 516, 1658, 1659, 512, 514, 533, 985, 984, 1671, 983, - /* 1650 */ 982, 981, 980, 1004, 513, 1002, 514, 977, 1625, 976, - /* 1660 */ 975, 972, 971, 970, 1414, 589, 513, 590, 1655, 591, - /* 1670 */ 1625, 1412, 593, 595, 594, 1684, 1410, 597, 259, 1656, - /* 1680 */ 516, 1658, 1659, 512, 598, 533, 599, 1684, 1408, 601, - /* 1690 */ 267, 1656, 516, 1658, 1659, 512, 1671, 533, 602, 603, - /* 1700 */ 1655, 605, 606, 1395, 514, 1396, 1381, 609, 610, 1356, - /* 1710 */ 1356, 1169, 254, 613, 513, 614, 1356, 1356, 1625, 1356, - /* 1720 */ 1356, 1356, 1356, 1356, 1356, 1356, 1356, 1356, 1671, 1356, - /* 1730 */ 1655, 1356, 1356, 1356, 1356, 1684, 514, 1356, 269, 1656, - /* 1740 */ 516, 1658, 1659, 512, 1356, 533, 513, 1356, 1356, 1356, - /* 1750 */ 1625, 1356, 1356, 1356, 1356, 1356, 1356, 1356, 1671, 1356, - /* 1760 */ 1356, 1356, 1655, 1356, 1356, 1356, 514, 1684, 1356, 1356, - /* 1770 */ 260, 1656, 516, 1658, 1659, 512, 513, 533, 1655, 1356, - /* 1780 */ 1625, 1356, 1356, 1356, 1356, 1356, 1356, 1356, 1356, 1356, - /* 1790 */ 1671, 1356, 1356, 1356, 1655, 1356, 1356, 1684, 514, 1356, - /* 1800 */ 270, 1656, 516, 1658, 1659, 512, 1671, 533, 513, 1356, - /* 1810 */ 1655, 1356, 1625, 1356, 514, 1356, 1356, 1356, 1356, 1356, - /* 1820 */ 1356, 1356, 1671, 1356, 513, 1356, 1356, 1356, 1625, 1684, - /* 1830 */ 514, 1356, 261, 1656, 516, 1658, 1659, 512, 1671, 533, - /* 1840 */ 513, 1356, 1356, 1356, 1625, 1684, 514, 1356, 271, 1656, - /* 1850 */ 516, 1658, 1659, 512, 1356, 533, 513, 1356, 1356, 1356, - /* 1860 */ 1625, 1684, 1655, 1356, 262, 1656, 516, 1658, 1659, 512, - /* 1870 */ 1356, 533, 1356, 1356, 1356, 1356, 1356, 1684, 1655, 1356, - /* 1880 */ 1667, 1656, 516, 1658, 1659, 512, 1356, 533, 1356, 1356, - /* 1890 */ 1671, 1356, 1356, 1356, 1356, 1356, 1356, 1356, 514, 1356, - /* 1900 */ 1356, 1356, 1356, 1356, 1356, 1356, 1671, 1356, 513, 1356, - /* 1910 */ 1655, 1356, 1625, 1356, 514, 1356, 1356, 1356, 1356, 1356, - /* 1920 */ 1356, 1356, 1356, 1356, 513, 1356, 1356, 1356, 1625, 1684, - /* 1930 */ 1356, 1356, 1666, 1656, 516, 1658, 1659, 512, 1671, 533, - /* 1940 */ 1356, 1356, 1655, 1356, 1356, 1684, 514, 1356, 1665, 1656, - /* 1950 */ 516, 1658, 1659, 512, 1356, 533, 513, 1356, 1356, 1356, - /* 1960 */ 1625, 1356, 1356, 1356, 1356, 1356, 1356, 1356, 1356, 1356, - /* 1970 */ 1671, 1356, 1655, 1356, 1356, 1356, 1356, 1684, 514, 1356, - /* 1980 */ 282, 1656, 516, 1658, 1659, 512, 1356, 533, 513, 1356, - /* 1990 */ 1356, 1356, 1625, 1356, 1356, 1356, 1356, 1356, 1356, 1356, - /* 2000 */ 1671, 1356, 1356, 1356, 1655, 1356, 1356, 1356, 514, 1684, - /* 2010 */ 1356, 1356, 281, 1656, 516, 1658, 1659, 512, 513, 533, - /* 2020 */ 1655, 1356, 1625, 1356, 1356, 1356, 1356, 1356, 1356, 1356, - /* 2030 */ 1356, 1356, 1671, 1356, 1356, 1356, 1356, 1356, 1356, 1684, - /* 2040 */ 514, 1356, 283, 1656, 516, 1658, 1659, 512, 1671, 533, - /* 2050 */ 513, 490, 1356, 1356, 1625, 1356, 514, 1356, 1356, 490, - /* 2060 */ 1356, 1356, 1356, 1356, 1356, 1356, 513, 1356, 1356, 1356, - /* 2070 */ 1625, 1684, 1356, 1356, 280, 1656, 516, 1658, 1659, 512, - /* 2080 */ 114, 533, 1356, 1356, 1356, 1356, 1356, 1684, 114, 1356, - /* 2090 */ 266, 1656, 516, 1658, 1659, 512, 1356, 533, 1356, 494, - /* 2100 */ 1356, 1356, 1356, 1356, 1356, 1356, 1356, 494, 1356, 1356, - /* 2110 */ 1356, 1356, 1356, 1356, 1356, 1356, 1356, 1356, 112, 1356, - /* 2120 */ 1356, 1356, 1356, 1356, 1356, 1356, 112, 1356, 1356, 1356, - /* 2130 */ 1356, 1356, 1356, 219, 1731, 489, 1356, 488, 1356, 1356, - /* 2140 */ 1786, 219, 1731, 489, 1356, 488, 1356, 1356, 1786, 1356, - /* 2150 */ 1356, 1356, 149, 1356, 1356, 1356, 1783, 1356, 1356, 1356, - /* 2160 */ 147, 1356, 1356, 1356, 1783, + /* 220 */ 130, 406, 36, 34, 32, 31, 30, 1170, 1171, 1490, + /* 230 */ 1217, 1218, 1220, 1221, 1222, 1223, 1224, 508, 530, 1232, + /* 240 */ 1233, 1234, 1235, 1236, 1237, 35, 33, 342, 484, 479, + /* 250 */ 1354, 441, 440, 305, 1654, 1166, 439, 200, 252, 111, + /* 260 */ 436, 1517, 378, 435, 434, 433, 35, 33, 289, 446, + /* 270 */ 287, 286, 1000, 429, 305, 1478, 1166, 431, 129, 309, + /* 280 */ 1164, 79, 1670, 55, 454, 66, 150, 130, 150, 1002, + /* 290 */ 513, 14, 1204, 483, 115, 1638, 1489, 1172, 193, 430, + /* 300 */ 512, 1164, 1479, 948, 1624, 947, 161, 160, 321, 493, + /* 310 */ 449, 1634, 1640, 393, 2, 443, 1191, 1642, 1172, 1188, + /* 320 */ 192, 1683, 532, 489, 82, 1655, 515, 1657, 1658, 511, + /* 330 */ 24, 532, 949, 1349, 1723, 8, 611, 1638, 278, 1719, + /* 340 */ 36, 34, 32, 31, 30, 51, 1165, 1463, 50, 1785, + /* 350 */ 1785, 565, 114, 1634, 1640, 65, 294, 611, 1379, 194, + /* 360 */ 558, 147, 147, 1462, 532, 1782, 1782, 1165, 1356, 1038, + /* 370 */ 555, 554, 553, 1042, 552, 1044, 1045, 551, 1047, 548, + /* 380 */ 1378, 1053, 545, 1055, 1056, 542, 539, 7, 55, 1167, + /* 390 */ 112, 1189, 105, 104, 103, 102, 101, 100, 99, 98, + /* 400 */ 97, 32, 31, 30, 565, 146, 1730, 1731, 1624, 1735, + /* 410 */ 1167, 150, 1170, 1171, 1348, 1217, 1218, 1220, 1221, 1222, + /* 420 */ 1223, 1224, 508, 530, 1232, 1233, 1234, 1235, 1236, 1237, + /* 430 */ 1624, 568, 157, 1170, 1171, 462, 1217, 1218, 1220, 1221, + /* 440 */ 1222, 1223, 1224, 508, 530, 1232, 1233, 1234, 1235, 1236, + /* 450 */ 1237, 35, 33, 1238, 26, 1377, 563, 61, 465, 305, + /* 460 */ 60, 1166, 563, 150, 36, 34, 32, 31, 30, 63, + /* 470 */ 1405, 395, 35, 33, 391, 562, 1654, 561, 560, 559, + /* 480 */ 305, 562, 1166, 561, 560, 559, 1164, 1192, 529, 1317, + /* 490 */ 529, 1483, 442, 36, 34, 32, 31, 30, 1785, 1785, + /* 500 */ 353, 1644, 106, 1172, 1670, 1624, 1472, 1164, 55, 432, + /* 510 */ 1784, 147, 492, 455, 1782, 1782, 150, 1487, 1376, 1487, + /* 520 */ 9, 569, 512, 1459, 1172, 1418, 1624, 453, 475, 1315, + /* 530 */ 1316, 1318, 1319, 36, 34, 32, 31, 30, 1646, 279, + /* 540 */ 451, 9, 611, 1683, 438, 437, 83, 1655, 515, 1657, + /* 550 */ 1658, 511, 1165, 532, 1785, 1474, 1723, 1531, 1288, 315, + /* 560 */ 298, 1719, 143, 611, 310, 1785, 147, 130, 1624, 1529, + /* 570 */ 1782, 1255, 1300, 1165, 222, 1785, 1489, 148, 1190, 471, + /* 580 */ 1750, 1782, 347, 1737, 346, 441, 440, 1783, 529, 339, + /* 590 */ 439, 1782, 1531, 111, 436, 1167, 1531, 435, 434, 433, + /* 600 */ 363, 581, 579, 316, 1530, 1568, 1569, 1734, 1529, 341, + /* 610 */ 337, 1292, 221, 1375, 935, 936, 1167, 1487, 1170, 1171, + /* 620 */ 1256, 1217, 1218, 1220, 1221, 1222, 1223, 1224, 508, 530, + /* 630 */ 1232, 1233, 1234, 1235, 1236, 1237, 150, 11, 10, 1170, + /* 640 */ 1171, 1261, 1217, 1218, 1220, 1221, 1222, 1223, 1224, 508, + /* 650 */ 530, 1232, 1233, 1234, 1235, 1236, 1237, 35, 33, 276, + /* 660 */ 1654, 1188, 529, 1624, 529, 305, 1374, 1166, 371, 54, + /* 670 */ 1373, 383, 1372, 1470, 364, 197, 405, 507, 27, 303, + /* 680 */ 1250, 1251, 1252, 1253, 1254, 1258, 1259, 1260, 1670, 384, + /* 690 */ 529, 1487, 1164, 1487, 1243, 529, 513, 1371, 1564, 529, + /* 700 */ 1190, 431, 1484, 1370, 318, 159, 512, 1603, 1190, 1172, + /* 710 */ 1624, 463, 130, 529, 1150, 1151, 1624, 1193, 1269, 1487, + /* 720 */ 1624, 1489, 1624, 430, 1487, 526, 2, 1683, 1487, 1257, + /* 730 */ 83, 1655, 515, 1657, 1658, 511, 947, 532, 1367, 1366, + /* 740 */ 1723, 1219, 1487, 497, 298, 1719, 1798, 1624, 611, 120, + /* 750 */ 1262, 1742, 1288, 1624, 1365, 1757, 1364, 1363, 1165, 382, + /* 760 */ 1362, 425, 377, 376, 375, 374, 373, 370, 369, 368, + /* 770 */ 367, 366, 362, 361, 360, 359, 358, 357, 356, 355, + /* 780 */ 529, 131, 529, 529, 1737, 1369, 258, 25, 1624, 1624, + /* 790 */ 467, 1737, 527, 1361, 243, 319, 1360, 500, 256, 53, + /* 800 */ 1613, 1167, 52, 1359, 1624, 505, 1624, 1624, 1733, 1487, + /* 810 */ 1624, 1487, 1487, 185, 1445, 1732, 183, 1291, 187, 162, + /* 820 */ 189, 186, 1175, 188, 1170, 1171, 46, 1217, 1218, 1220, + /* 830 */ 1221, 1222, 1223, 1224, 508, 530, 1232, 1233, 1234, 1235, + /* 840 */ 1236, 1237, 206, 1624, 55, 327, 1624, 36, 34, 32, + /* 850 */ 31, 30, 191, 1624, 1400, 190, 1166, 1398, 209, 11, + /* 860 */ 10, 1351, 1352, 1219, 46, 37, 37, 1314, 37, 232, + /* 870 */ 557, 1219, 456, 118, 119, 78, 444, 120, 1174, 447, + /* 880 */ 81, 1164, 537, 225, 972, 74, 119, 476, 1178, 120, + /* 890 */ 495, 216, 1671, 279, 121, 1389, 1654, 1526, 1172, 211, + /* 900 */ 424, 973, 119, 1753, 490, 251, 1263, 1225, 322, 1123, + /* 910 */ 234, 59, 58, 351, 521, 240, 156, 1204, 1031, 1188, + /* 920 */ 224, 345, 3, 1059, 1670, 1255, 1247, 1063, 498, 227, + /* 930 */ 1069, 229, 492, 275, 5, 1067, 335, 611, 333, 329, + /* 940 */ 153, 323, 512, 122, 1177, 326, 1624, 1165, 325, 284, + /* 950 */ 1000, 285, 312, 311, 248, 1134, 158, 365, 1566, 372, + /* 960 */ 380, 379, 1180, 1683, 381, 385, 83, 1655, 515, 1657, + /* 970 */ 1658, 511, 150, 532, 1256, 1654, 1723, 1194, 1197, 386, + /* 980 */ 298, 1719, 143, 394, 501, 397, 398, 1173, 1196, 399, + /* 990 */ 1167, 165, 167, 1198, 170, 1261, 172, 403, 400, 402, + /* 1000 */ 1751, 1195, 175, 1670, 1172, 62, 404, 407, 178, 426, + /* 1010 */ 1172, 513, 86, 1170, 1171, 428, 293, 1477, 1607, 182, + /* 1020 */ 1473, 512, 184, 124, 249, 1624, 125, 1475, 1654, 1471, + /* 1030 */ 126, 127, 27, 303, 1250, 1251, 1252, 1253, 1254, 1258, + /* 1040 */ 1259, 1260, 1683, 533, 195, 83, 1655, 515, 1657, 1658, + /* 1050 */ 511, 457, 532, 1176, 198, 1723, 1670, 461, 464, 298, + /* 1060 */ 1719, 1798, 201, 466, 513, 468, 458, 469, 477, 204, + /* 1070 */ 1780, 1193, 1764, 207, 512, 519, 1763, 474, 1624, 1654, + /* 1080 */ 297, 1754, 210, 480, 215, 6, 486, 1744, 473, 217, + /* 1090 */ 1654, 1288, 113, 1192, 40, 1683, 1181, 502, 83, 1655, + /* 1100 */ 515, 1657, 1658, 511, 1738, 532, 218, 1670, 1723, 137, + /* 1110 */ 499, 299, 298, 1719, 1798, 513, 18, 517, 1670, 1184, + /* 1120 */ 518, 1704, 1575, 1741, 1781, 512, 513, 223, 226, 1624, + /* 1130 */ 530, 1232, 1233, 228, 493, 1574, 512, 1801, 1654, 522, + /* 1140 */ 1624, 307, 236, 496, 523, 493, 1683, 238, 503, 263, + /* 1150 */ 1655, 515, 1657, 1658, 511, 524, 532, 1683, 250, 71, + /* 1160 */ 263, 1655, 515, 1657, 1658, 511, 1670, 532, 1488, 73, + /* 1170 */ 1460, 535, 253, 245, 513, 1785, 610, 47, 1654, 255, + /* 1180 */ 136, 264, 274, 265, 512, 1618, 1785, 149, 1624, 257, + /* 1190 */ 1617, 1782, 57, 1616, 324, 1159, 1160, 154, 147, 328, + /* 1200 */ 1612, 330, 1782, 331, 332, 1683, 1670, 1611, 84, 1655, + /* 1210 */ 515, 1657, 1658, 511, 513, 532, 334, 1610, 1723, 336, + /* 1220 */ 180, 1609, 1722, 1719, 512, 338, 1608, 340, 1624, 343, + /* 1230 */ 344, 1137, 141, 1593, 155, 1136, 1587, 1654, 423, 419, + /* 1240 */ 415, 411, 179, 1586, 349, 1683, 350, 1585, 84, 1655, + /* 1250 */ 515, 1657, 1658, 511, 1584, 532, 1106, 1559, 1723, 117, + /* 1260 */ 1541, 1540, 504, 1719, 1558, 1670, 1557, 64, 1556, 1555, + /* 1270 */ 177, 1554, 1553, 510, 1552, 1551, 1550, 1549, 1548, 1547, + /* 1280 */ 1546, 1545, 1544, 512, 1543, 1542, 1539, 1624, 1538, 1654, + /* 1290 */ 1537, 1536, 1108, 1535, 1534, 1533, 1532, 1417, 1654, 1385, + /* 1300 */ 108, 938, 163, 937, 1683, 1384, 140, 272, 1655, 515, + /* 1310 */ 1657, 1658, 511, 509, 532, 506, 1695, 1670, 1601, 1595, + /* 1320 */ 1583, 164, 171, 1582, 1572, 513, 1670, 176, 1466, 168, + /* 1330 */ 1416, 173, 966, 401, 513, 512, 390, 109, 169, 1624, + /* 1340 */ 174, 1414, 392, 410, 512, 1412, 414, 1410, 1624, 408, + /* 1350 */ 1408, 166, 409, 418, 1654, 412, 1683, 413, 417, 134, + /* 1360 */ 1655, 515, 1657, 1658, 511, 1683, 532, 421, 84, 1655, + /* 1370 */ 515, 1657, 1658, 511, 422, 532, 416, 1397, 1723, 614, + /* 1380 */ 420, 1396, 1670, 1720, 1383, 1468, 1073, 1072, 1467, 999, + /* 1390 */ 513, 998, 578, 247, 45, 997, 996, 580, 181, 993, + /* 1400 */ 512, 992, 494, 1799, 1624, 107, 991, 472, 1654, 1406, + /* 1410 */ 1401, 603, 599, 595, 591, 246, 290, 1654, 291, 445, + /* 1420 */ 1399, 1683, 292, 448, 273, 1655, 515, 1657, 1658, 511, + /* 1430 */ 1382, 532, 1381, 450, 452, 85, 1670, 1600, 1144, 1594, + /* 1440 */ 80, 459, 1581, 241, 513, 1670, 1580, 1579, 1571, 67, + /* 1450 */ 203, 15, 208, 513, 512, 4, 1313, 37, 1624, 49, + /* 1460 */ 460, 205, 48, 512, 43, 1306, 213, 1624, 199, 16, + /* 1470 */ 1654, 135, 214, 212, 22, 1683, 525, 1644, 268, 1655, + /* 1480 */ 515, 1657, 1658, 511, 1683, 532, 128, 134, 1655, 515, + /* 1490 */ 1657, 1658, 511, 23, 532, 220, 42, 138, 1670, 68, + /* 1500 */ 1654, 470, 17, 1285, 202, 1337, 513, 1336, 1284, 300, + /* 1510 */ 1341, 1342, 1340, 1331, 301, 485, 512, 10, 19, 1248, + /* 1520 */ 1624, 29, 1142, 302, 196, 1227, 1226, 139, 1670, 151, + /* 1530 */ 12, 1800, 1212, 1570, 514, 20, 510, 1683, 41, 231, + /* 1540 */ 273, 1655, 515, 1657, 1658, 511, 512, 532, 13, 21, + /* 1550 */ 1624, 1311, 1654, 233, 235, 69, 237, 70, 1643, 1686, + /* 1560 */ 520, 74, 239, 1229, 242, 531, 1182, 1683, 1654, 44, + /* 1570 */ 272, 1655, 515, 1657, 1658, 511, 1060, 532, 534, 1696, + /* 1580 */ 1670, 536, 314, 538, 1052, 1057, 540, 541, 513, 1054, + /* 1590 */ 543, 1048, 544, 546, 547, 549, 1670, 550, 512, 1046, + /* 1600 */ 1051, 1050, 1624, 1049, 513, 304, 1037, 75, 1654, 76, + /* 1610 */ 1068, 556, 77, 1066, 512, 1065, 964, 564, 1624, 1683, + /* 1620 */ 1654, 306, 273, 1655, 515, 1657, 1658, 511, 988, 532, + /* 1630 */ 1006, 567, 244, 986, 985, 1683, 1670, 984, 273, 1655, + /* 1640 */ 515, 1657, 1658, 511, 513, 532, 983, 982, 1670, 981, + /* 1650 */ 980, 979, 1003, 1001, 512, 976, 513, 975, 1624, 974, + /* 1660 */ 971, 970, 969, 1413, 588, 589, 512, 590, 1654, 592, + /* 1670 */ 1624, 1411, 594, 593, 1409, 1683, 596, 597, 259, 1655, + /* 1680 */ 515, 1657, 1658, 511, 598, 532, 1407, 1683, 600, 601, + /* 1690 */ 267, 1655, 515, 1657, 1658, 511, 1670, 532, 602, 1395, + /* 1700 */ 1654, 604, 605, 1394, 513, 1380, 608, 1168, 609, 613, + /* 1710 */ 254, 612, 1355, 1355, 512, 1355, 1355, 1355, 1624, 1355, + /* 1720 */ 1355, 1355, 1355, 1355, 1355, 1355, 1355, 1355, 1670, 1355, + /* 1730 */ 1654, 1355, 1355, 1355, 1355, 1683, 513, 1355, 269, 1655, + /* 1740 */ 515, 1657, 1658, 511, 1355, 532, 512, 1355, 1355, 1355, + /* 1750 */ 1624, 1355, 1355, 1355, 1355, 1355, 1355, 1355, 1670, 1355, + /* 1760 */ 1355, 1355, 1654, 1355, 1355, 1355, 513, 1683, 1355, 1355, + /* 1770 */ 260, 1655, 515, 1657, 1658, 511, 512, 532, 1654, 1355, + /* 1780 */ 1624, 1355, 1355, 1355, 1355, 1355, 1355, 1355, 1355, 1355, + /* 1790 */ 1670, 1355, 1355, 1355, 1654, 1355, 1355, 1683, 513, 1355, + /* 1800 */ 270, 1655, 515, 1657, 1658, 511, 1670, 532, 512, 1355, + /* 1810 */ 1654, 1355, 1624, 1355, 513, 1355, 1355, 1355, 1355, 1355, + /* 1820 */ 1355, 1355, 1670, 1355, 512, 1355, 1355, 1355, 1624, 1683, + /* 1830 */ 513, 1355, 261, 1655, 515, 1657, 1658, 511, 1670, 532, + /* 1840 */ 512, 1355, 1355, 1355, 1624, 1683, 513, 1355, 271, 1655, + /* 1850 */ 515, 1657, 1658, 511, 1355, 532, 512, 1355, 1355, 1355, + /* 1860 */ 1624, 1683, 1654, 1355, 262, 1655, 515, 1657, 1658, 511, + /* 1870 */ 1355, 532, 1355, 1355, 1355, 1355, 1355, 1683, 1654, 1355, + /* 1880 */ 1666, 1655, 515, 1657, 1658, 511, 1355, 532, 1355, 1355, + /* 1890 */ 1670, 1355, 1355, 1355, 1355, 1355, 1355, 1355, 513, 1355, + /* 1900 */ 1355, 1355, 1355, 1355, 1355, 1355, 1670, 1355, 512, 1355, + /* 1910 */ 1654, 1355, 1624, 1355, 513, 1355, 1355, 1355, 1355, 1355, + /* 1920 */ 1355, 1355, 1355, 1355, 512, 1355, 1355, 1355, 1624, 1683, + /* 1930 */ 1355, 1355, 1665, 1655, 515, 1657, 1658, 511, 1670, 532, + /* 1940 */ 1355, 1355, 1654, 1355, 1355, 1683, 513, 1355, 1664, 1655, + /* 1950 */ 515, 1657, 1658, 511, 1355, 532, 512, 1355, 1355, 1355, + /* 1960 */ 1624, 1355, 1355, 1355, 1355, 1355, 1355, 1355, 1355, 1355, + /* 1970 */ 1670, 1355, 1654, 1355, 1355, 1355, 1355, 1683, 513, 1355, + /* 1980 */ 282, 1655, 515, 1657, 1658, 511, 1355, 532, 512, 1355, + /* 1990 */ 1355, 1355, 1624, 1355, 1355, 1355, 1355, 1355, 1355, 1355, + /* 2000 */ 1670, 1355, 1355, 1355, 1654, 1355, 1355, 1355, 513, 1683, + /* 2010 */ 1355, 1355, 281, 1655, 515, 1657, 1658, 511, 512, 532, + /* 2020 */ 1654, 1355, 1624, 1355, 1355, 1355, 1355, 1355, 1355, 1355, + /* 2030 */ 1355, 1355, 1670, 1355, 1355, 1355, 1355, 1355, 1355, 1683, + /* 2040 */ 513, 1355, 283, 1655, 515, 1657, 1658, 511, 1670, 532, + /* 2050 */ 512, 489, 1355, 1355, 1624, 1355, 513, 1355, 1355, 489, + /* 2060 */ 1355, 1355, 1355, 1355, 1355, 1355, 512, 1355, 1355, 1355, + /* 2070 */ 1624, 1683, 1355, 1355, 280, 1655, 515, 1657, 1658, 511, + /* 2080 */ 114, 532, 1355, 1355, 1355, 1355, 1355, 1683, 114, 1355, + /* 2090 */ 266, 1655, 515, 1657, 1658, 511, 1355, 532, 1355, 493, + /* 2100 */ 1355, 1355, 1355, 1355, 1355, 1355, 1355, 493, 1355, 1355, + /* 2110 */ 1355, 1355, 1355, 1355, 1355, 1355, 1355, 1355, 112, 1355, + /* 2120 */ 1355, 1355, 1355, 1355, 1355, 1355, 112, 1355, 1355, 1355, + /* 2130 */ 1355, 1355, 1355, 219, 1730, 488, 1355, 487, 1355, 1355, + /* 2140 */ 1785, 219, 1730, 488, 1355, 487, 1355, 1355, 1785, 1355, + /* 2150 */ 1355, 1355, 149, 1355, 1355, 1355, 1782, 1355, 1355, 1355, + /* 2160 */ 147, 1355, 1355, 1355, 1782, }; static const YYCODETYPE yy_lookahead[] = { /* 0 */ 251, 248, 241, 271, 322, 323, 274, 0, 271, 249, @@ -555,59 +555,59 @@ static const YYCODETYPE yy_lookahead[] = { /* 1160 */ 311, 312, 313, 314, 315, 316, 269, 318, 277, 81, /* 1170 */ 259, 273, 248, 251, 277, 337, 243, 299, 241, 252, /* 1180 */ 303, 263, 263, 263, 287, 0, 337, 349, 291, 239, - /* 1190 */ 0, 353, 40, 0, 72, 0, 47, 174, 349, 174, - /* 1200 */ 47, 47, 353, 47, 0, 308, 269, 47, 311, 312, - /* 1210 */ 313, 314, 315, 316, 277, 318, 47, 174, 321, 0, - /* 1220 */ 33, 47, 325, 326, 287, 0, 47, 0, 291, 47, - /* 1230 */ 0, 81, 45, 113, 160, 159, 156, 241, 51, 52, - /* 1240 */ 53, 54, 55, 0, 0, 308, 152, 151, 311, 312, - /* 1250 */ 313, 314, 315, 316, 0, 318, 0, 44, 321, 22, - /* 1260 */ 40, 0, 325, 326, 0, 269, 0, 80, 0, 0, + /* 1190 */ 0, 353, 40, 0, 72, 47, 47, 47, 349, 174, + /* 1200 */ 0, 47, 353, 47, 174, 308, 269, 0, 311, 312, + /* 1210 */ 313, 314, 315, 316, 277, 318, 174, 0, 321, 47, + /* 1220 */ 33, 0, 325, 326, 287, 47, 0, 47, 291, 160, + /* 1230 */ 159, 113, 45, 0, 81, 156, 0, 241, 51, 52, + /* 1240 */ 53, 54, 55, 0, 152, 308, 151, 0, 311, 312, + /* 1250 */ 313, 314, 315, 316, 0, 318, 44, 0, 321, 40, + /* 1260 */ 0, 0, 325, 326, 0, 269, 0, 80, 0, 0, /* 1270 */ 83, 0, 0, 277, 0, 0, 0, 0, 0, 0, /* 1280 */ 0, 0, 0, 287, 0, 0, 0, 291, 0, 241, - /* 1290 */ 0, 0, 0, 0, 0, 0, 0, 0, 241, 0, - /* 1300 */ 0, 41, 40, 14, 308, 0, 0, 311, 312, 313, - /* 1310 */ 314, 315, 316, 317, 318, 319, 320, 269, 14, 0, - /* 1320 */ 37, 0, 147, 0, 37, 277, 269, 140, 0, 142, - /* 1330 */ 0, 144, 59, 146, 277, 287, 0, 0, 0, 291, - /* 1340 */ 38, 0, 44, 0, 287, 44, 37, 37, 291, 37, - /* 1350 */ 47, 164, 45, 37, 241, 47, 308, 0, 45, 311, - /* 1360 */ 312, 313, 314, 315, 316, 308, 318, 47, 311, 312, - /* 1370 */ 313, 314, 315, 316, 45, 318, 37, 45, 321, 19, - /* 1380 */ 47, 37, 269, 326, 0, 0, 0, 47, 22, 0, - /* 1390 */ 277, 41, 47, 33, 47, 47, 47, 41, 47, 47, - /* 1400 */ 287, 47, 354, 355, 291, 45, 88, 294, 241, 0, - /* 1410 */ 22, 51, 52, 53, 54, 55, 90, 241, 0, 22, - /* 1420 */ 48, 308, 0, 22, 311, 312, 313, 314, 315, 316, - /* 1430 */ 47, 318, 0, 22, 0, 22, 269, 20, 0, 47, - /* 1440 */ 80, 0, 22, 83, 277, 269, 0, 0, 0, 0, - /* 1450 */ 81, 37, 213, 277, 287, 82, 41, 41, 291, 145, - /* 1460 */ 145, 81, 145, 287, 142, 41, 41, 291, 213, 82, - /* 1470 */ 241, 140, 81, 44, 81, 308, 116, 82, 311, 312, + /* 1290 */ 0, 0, 22, 0, 0, 0, 0, 0, 241, 0, + /* 1300 */ 37, 14, 40, 14, 308, 0, 41, 311, 312, 313, + /* 1310 */ 314, 315, 316, 317, 318, 319, 320, 269, 0, 0, + /* 1320 */ 0, 38, 147, 0, 0, 277, 269, 140, 0, 142, + /* 1330 */ 0, 144, 59, 146, 277, 287, 44, 37, 37, 291, + /* 1340 */ 37, 0, 44, 37, 287, 0, 37, 0, 291, 47, + /* 1350 */ 0, 164, 45, 37, 241, 47, 308, 45, 45, 311, + /* 1360 */ 312, 313, 314, 315, 316, 308, 318, 45, 311, 312, + /* 1370 */ 313, 314, 315, 316, 37, 318, 47, 0, 321, 19, + /* 1380 */ 47, 0, 269, 326, 0, 0, 47, 22, 0, 47, + /* 1390 */ 277, 47, 41, 33, 90, 47, 47, 41, 88, 47, + /* 1400 */ 287, 47, 354, 355, 291, 45, 47, 294, 241, 0, + /* 1410 */ 0, 51, 52, 53, 54, 55, 22, 241, 22, 48, + /* 1420 */ 0, 308, 22, 47, 311, 312, 313, 314, 315, 316, + /* 1430 */ 0, 318, 0, 22, 22, 20, 269, 0, 47, 0, + /* 1440 */ 80, 22, 0, 83, 277, 269, 0, 0, 0, 81, + /* 1450 */ 37, 213, 82, 277, 287, 41, 82, 41, 291, 145, + /* 1460 */ 145, 140, 145, 287, 41, 82, 41, 291, 142, 213, + /* 1470 */ 241, 81, 44, 81, 81, 308, 116, 44, 311, 312, /* 1480 */ 313, 314, 315, 316, 308, 318, 161, 311, 312, 313, - /* 1490 */ 314, 315, 316, 81, 318, 44, 41, 44, 269, 41, - /* 1500 */ 241, 141, 41, 82, 144, 82, 277, 44, 82, 47, - /* 1510 */ 82, 47, 47, 47, 47, 348, 287, 47, 2, 41, - /* 1520 */ 291, 82, 162, 294, 164, 179, 81, 44, 269, 44, - /* 1530 */ 22, 355, 82, 81, 181, 81, 277, 308, 81, 143, - /* 1540 */ 311, 312, 313, 314, 315, 316, 287, 318, 213, 207, - /* 1550 */ 291, 82, 241, 82, 81, 81, 81, 0, 81, 37, - /* 1560 */ 81, 44, 44, 91, 82, 81, 22, 308, 241, 81, - /* 1570 */ 311, 312, 313, 314, 315, 316, 140, 318, 92, 320, - /* 1580 */ 269, 82, 47, 47, 81, 47, 82, 81, 277, 82, - /* 1590 */ 47, 81, 47, 82, 81, 47, 269, 82, 287, 105, - /* 1600 */ 81, 105, 291, 105, 277, 294, 105, 22, 241, 81, - /* 1610 */ 81, 47, 81, 93, 287, 113, 22, 59, 291, 308, - /* 1620 */ 241, 294, 311, 312, 313, 314, 315, 316, 58, 318, - /* 1630 */ 47, 64, 41, 79, 47, 308, 269, 47, 311, 312, - /* 1640 */ 313, 314, 315, 316, 277, 318, 47, 47, 269, 47, - /* 1650 */ 22, 47, 47, 64, 287, 47, 277, 47, 291, 47, - /* 1660 */ 47, 47, 47, 47, 0, 47, 287, 45, 241, 37, - /* 1670 */ 291, 0, 47, 37, 45, 308, 0, 47, 311, 312, - /* 1680 */ 313, 314, 315, 316, 45, 318, 37, 308, 0, 47, - /* 1690 */ 311, 312, 313, 314, 315, 316, 269, 318, 45, 37, - /* 1700 */ 241, 47, 46, 0, 277, 0, 0, 22, 21, 358, - /* 1710 */ 358, 22, 22, 21, 287, 20, 358, 358, 291, 358, + /* 1490 */ 314, 315, 316, 41, 318, 44, 41, 44, 269, 81, + /* 1500 */ 241, 141, 41, 82, 144, 47, 277, 47, 82, 47, + /* 1510 */ 47, 82, 47, 82, 47, 348, 287, 2, 41, 179, + /* 1520 */ 291, 81, 162, 294, 164, 82, 82, 44, 269, 44, + /* 1530 */ 81, 355, 22, 0, 181, 81, 277, 308, 207, 82, + /* 1540 */ 311, 312, 313, 314, 315, 316, 287, 318, 213, 81, + /* 1550 */ 291, 82, 241, 81, 81, 81, 37, 81, 44, 81, + /* 1560 */ 143, 91, 140, 82, 44, 81, 22, 308, 241, 81, + /* 1570 */ 311, 312, 313, 314, 315, 316, 82, 318, 92, 320, + /* 1580 */ 269, 47, 47, 81, 105, 82, 47, 81, 277, 82, + /* 1590 */ 47, 82, 81, 47, 81, 47, 269, 81, 287, 82, + /* 1600 */ 105, 105, 291, 105, 277, 294, 22, 81, 241, 81, + /* 1610 */ 47, 93, 81, 113, 287, 22, 59, 58, 291, 308, + /* 1620 */ 241, 294, 311, 312, 313, 314, 315, 316, 47, 318, + /* 1630 */ 64, 79, 41, 47, 47, 308, 269, 47, 311, 312, + /* 1640 */ 313, 314, 315, 316, 277, 318, 47, 47, 269, 22, + /* 1650 */ 47, 47, 64, 47, 287, 47, 277, 47, 291, 47, + /* 1660 */ 47, 47, 47, 0, 47, 45, 287, 37, 241, 47, + /* 1670 */ 291, 0, 37, 45, 0, 308, 47, 45, 311, 312, + /* 1680 */ 313, 314, 315, 316, 37, 318, 0, 308, 47, 45, + /* 1690 */ 311, 312, 313, 314, 315, 316, 269, 318, 37, 0, + /* 1700 */ 241, 47, 46, 0, 277, 0, 22, 22, 21, 20, + /* 1710 */ 22, 21, 358, 358, 287, 358, 358, 358, 291, 358, /* 1720 */ 358, 358, 358, 358, 358, 358, 358, 358, 269, 358, /* 1730 */ 241, 358, 358, 358, 358, 308, 277, 358, 311, 312, /* 1740 */ 313, 314, 315, 316, 358, 318, 287, 358, 358, 358, @@ -654,9 +654,9 @@ static const YYCODETYPE yy_lookahead[] = { /* 2150 */ 358, 358, 349, 358, 358, 358, 353, 358, 358, 358, /* 2160 */ 349, 358, 358, 358, 353, }; -#define YY_SHIFT_COUNT (615) +#define YY_SHIFT_COUNT (614) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1706) +#define YY_SHIFT_MAX (1705) static const unsigned short int yy_shift_ofst[] = { /* 0 */ 763, 0, 0, 48, 233, 233, 233, 233, 254, 254, /* 10 */ 233, 233, 439, 460, 645, 460, 460, 460, 460, 460, @@ -690,36 +690,36 @@ static const unsigned short int yy_shift_ofst[] = { /* 290 */ 470, 854, 857, 506, 547, 708, 785, 817, 858, 667, /* 300 */ 702, 756, 824, 747, 825, 457, 827, 828, 832, 833, /* 310 */ 836, 775, 831, 823, 841, 845, 848, 853, 861, 794, - /* 320 */ 837, 1185, 1190, 1152, 1193, 1122, 1195, 1149, 1023, 1153, - /* 330 */ 1154, 1156, 1025, 1204, 1160, 1169, 1043, 1219, 1174, 1225, - /* 340 */ 1179, 1227, 1182, 1230, 1150, 1074, 1076, 1120, 1080, 1243, - /* 350 */ 1244, 1094, 1096, 1254, 1256, 1213, 1264, 1266, 1268, 1269, + /* 320 */ 837, 1185, 1190, 1152, 1193, 1122, 1148, 1149, 1150, 1025, + /* 330 */ 1200, 1154, 1156, 1030, 1207, 1042, 1217, 1172, 1221, 1178, + /* 340 */ 1226, 1180, 1233, 1153, 1069, 1071, 1118, 1079, 1236, 1243, + /* 350 */ 1092, 1095, 1247, 1254, 1212, 1257, 1264, 1266, 1268, 1269, /* 360 */ 1271, 1272, 1274, 1275, 1276, 1277, 1278, 1279, 1280, 1281, - /* 370 */ 1282, 1284, 1285, 1286, 1220, 1261, 1288, 1290, 1291, 1292, - /* 380 */ 1293, 1237, 1294, 1295, 1296, 1297, 1299, 1300, 1262, 1283, - /* 390 */ 1260, 1289, 1298, 1304, 1301, 1305, 1302, 1287, 1306, 1319, - /* 400 */ 1321, 1309, 1175, 1323, 1328, 1310, 1330, 1273, 1336, 1337, - /* 410 */ 1303, 1307, 1312, 1338, 1308, 1313, 1316, 1341, 1320, 1329, - /* 420 */ 1339, 1343, 1333, 1332, 1344, 1357, 1384, 1385, 1386, 1326, - /* 430 */ 1318, 1340, 1366, 1389, 1345, 1347, 1348, 1349, 1350, 1356, - /* 440 */ 1351, 1352, 1354, 1409, 1388, 1418, 1397, 1372, 1422, 1401, - /* 450 */ 1383, 1432, 1411, 1434, 1413, 1417, 1438, 1314, 1392, 1441, - /* 460 */ 1325, 1420, 1315, 1322, 1446, 1447, 1448, 1317, 1449, 1369, - /* 470 */ 1414, 1331, 1415, 1416, 1239, 1373, 1424, 1387, 1380, 1391, - /* 480 */ 1393, 1395, 1425, 1429, 1451, 1412, 1455, 1255, 1421, 1423, - /* 490 */ 1453, 1342, 1458, 1463, 1426, 1461, 1335, 1428, 1462, 1464, - /* 500 */ 1465, 1466, 1467, 1470, 1428, 1516, 1346, 1478, 1439, 1445, - /* 510 */ 1450, 1483, 1452, 1454, 1485, 1508, 1353, 1457, 1469, 1471, - /* 520 */ 1473, 1474, 1396, 1475, 1557, 1522, 1436, 1477, 1472, 1517, - /* 530 */ 1518, 1479, 1482, 1484, 1544, 1488, 1486, 1499, 1535, 1536, - /* 540 */ 1503, 1504, 1538, 1506, 1507, 1543, 1510, 1511, 1545, 1513, - /* 550 */ 1515, 1548, 1519, 1494, 1496, 1498, 1501, 1585, 1520, 1528, - /* 560 */ 1529, 1564, 1531, 1502, 1594, 1558, 1570, 1583, 1567, 1554, - /* 570 */ 1591, 1587, 1590, 1599, 1600, 1602, 1628, 1604, 1605, 1589, - /* 580 */ 1350, 1608, 1356, 1610, 1612, 1613, 1614, 1615, 1616, 1664, - /* 590 */ 1618, 1622, 1632, 1671, 1625, 1629, 1636, 1676, 1630, 1639, - /* 600 */ 1649, 1688, 1642, 1653, 1662, 1705, 1654, 1656, 1703, 1706, - /* 610 */ 1685, 1687, 1689, 1690, 1692, 1695, + /* 370 */ 1282, 1284, 1285, 1219, 1260, 1261, 1286, 1288, 1290, 1291, + /* 380 */ 1270, 1293, 1294, 1295, 1296, 1297, 1299, 1262, 1263, 1265, + /* 390 */ 1287, 1292, 1289, 1298, 1305, 1283, 1300, 1318, 1319, 1320, + /* 400 */ 1301, 1175, 1323, 1324, 1303, 1328, 1273, 1330, 1341, 1302, + /* 410 */ 1307, 1306, 1345, 1308, 1312, 1309, 1347, 1329, 1313, 1316, + /* 420 */ 1350, 1333, 1322, 1337, 1377, 1381, 1384, 1385, 1304, 1310, + /* 430 */ 1339, 1365, 1388, 1342, 1344, 1348, 1349, 1351, 1356, 1352, + /* 440 */ 1354, 1359, 1409, 1394, 1410, 1396, 1371, 1420, 1400, 1376, + /* 450 */ 1430, 1411, 1432, 1412, 1415, 1437, 1314, 1391, 1439, 1325, + /* 460 */ 1419, 1315, 1326, 1442, 1446, 1447, 1317, 1448, 1368, 1413, + /* 470 */ 1321, 1414, 1416, 1238, 1370, 1423, 1374, 1390, 1392, 1393, + /* 480 */ 1383, 1425, 1428, 1433, 1418, 1452, 1256, 1421, 1426, 1451, + /* 490 */ 1331, 1455, 1453, 1429, 1461, 1335, 1431, 1458, 1460, 1462, + /* 500 */ 1463, 1465, 1467, 1431, 1515, 1340, 1477, 1443, 1440, 1444, + /* 510 */ 1483, 1449, 1454, 1485, 1510, 1353, 1468, 1457, 1469, 1472, + /* 520 */ 1473, 1417, 1474, 1533, 1519, 1422, 1476, 1470, 1514, 1520, + /* 530 */ 1478, 1481, 1484, 1544, 1488, 1486, 1494, 1534, 1535, 1502, + /* 540 */ 1503, 1539, 1506, 1507, 1543, 1511, 1509, 1546, 1513, 1517, + /* 550 */ 1548, 1516, 1479, 1495, 1496, 1498, 1584, 1518, 1526, 1528, + /* 560 */ 1563, 1531, 1500, 1593, 1557, 1559, 1581, 1566, 1552, 1591, + /* 570 */ 1586, 1587, 1590, 1599, 1600, 1627, 1603, 1604, 1588, 1351, + /* 580 */ 1606, 1356, 1608, 1610, 1612, 1613, 1614, 1615, 1663, 1617, + /* 590 */ 1620, 1630, 1671, 1622, 1628, 1635, 1674, 1629, 1632, 1647, + /* 600 */ 1686, 1641, 1644, 1661, 1699, 1654, 1656, 1703, 1705, 1684, + /* 610 */ 1687, 1685, 1688, 1690, 1689, }; #define YY_REDUCE_COUNT (254) #define YY_REDUCE_MIN (-318) @@ -753,68 +753,68 @@ static const short yy_reduce_ofst[] = { /* 250 */ 918, 919, 920, 927, 950, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 10 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 20 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 30 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 40 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 50 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 60 */ 1354, 1354, 1354, 1354, 1423, 1354, 1354, 1354, 1354, 1354, - /* 70 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 80 */ 1421, 1561, 1354, 1726, 1354, 1354, 1354, 1354, 1354, 1354, - /* 90 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 100 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 110 */ 1423, 1354, 1737, 1737, 1737, 1421, 1354, 1354, 1354, 1354, - /* 120 */ 1354, 1354, 1517, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 130 */ 1354, 1597, 1354, 1354, 1803, 1354, 1603, 1761, 1354, 1354, - /* 140 */ 1354, 1354, 1470, 1753, 1729, 1743, 1730, 1788, 1788, 1788, - /* 150 */ 1746, 1354, 1757, 1354, 1354, 1354, 1589, 1354, 1354, 1566, - /* 160 */ 1563, 1563, 1354, 1354, 1354, 1354, 1423, 1354, 1423, 1354, - /* 170 */ 1354, 1423, 1354, 1423, 1354, 1354, 1423, 1423, 1354, 1423, - /* 180 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 190 */ 1354, 1354, 1354, 1354, 1354, 1354, 1421, 1599, 1354, 1421, - /* 200 */ 1354, 1354, 1421, 1354, 1354, 1421, 1354, 1768, 1766, 1354, - /* 210 */ 1768, 1766, 1354, 1354, 1354, 1780, 1776, 1759, 1757, 1743, - /* 220 */ 1354, 1354, 1354, 1794, 1790, 1806, 1794, 1790, 1794, 1790, - /* 230 */ 1354, 1766, 1354, 1354, 1766, 1354, 1574, 1354, 1354, 1421, - /* 240 */ 1354, 1421, 1354, 1486, 1354, 1354, 1421, 1354, 1591, 1605, - /* 250 */ 1520, 1520, 1520, 1424, 1359, 1354, 1354, 1354, 1354, 1354, - /* 260 */ 1354, 1354, 1354, 1354, 1354, 1354, 1670, 1779, 1778, 1702, - /* 270 */ 1701, 1700, 1698, 1669, 1482, 1354, 1354, 1354, 1354, 1354, - /* 280 */ 1663, 1664, 1662, 1661, 1354, 1354, 1354, 1354, 1354, 1354, - /* 290 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1727, 1354, - /* 300 */ 1791, 1795, 1354, 1354, 1354, 1646, 1354, 1354, 1354, 1354, - /* 310 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 320 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 330 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 340 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 350 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 360 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 370 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 380 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 390 */ 1388, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 400 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 410 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 420 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 430 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1451, 1450, - /* 440 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 450 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 460 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 470 */ 1354, 1354, 1750, 1760, 1354, 1354, 1354, 1354, 1354, 1354, - /* 480 */ 1354, 1354, 1354, 1354, 1646, 1354, 1777, 1354, 1736, 1732, - /* 490 */ 1354, 1354, 1728, 1354, 1354, 1789, 1354, 1354, 1354, 1354, - /* 500 */ 1354, 1354, 1354, 1354, 1354, 1722, 1354, 1695, 1354, 1354, - /* 510 */ 1354, 1354, 1354, 1354, 1354, 1354, 1657, 1354, 1354, 1354, - /* 520 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1645, - /* 530 */ 1354, 1686, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 540 */ 1514, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 550 */ 1354, 1354, 1354, 1499, 1497, 1496, 1495, 1354, 1492, 1354, - /* 560 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 570 */ 1443, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 580 */ 1434, 1354, 1433, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 590 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 600 */ 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, 1354, - /* 610 */ 1354, 1354, 1354, 1354, 1354, 1354, + /* 0 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 10 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 20 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 30 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 40 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 50 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 60 */ 1353, 1353, 1353, 1353, 1422, 1353, 1353, 1353, 1353, 1353, + /* 70 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 80 */ 1420, 1560, 1353, 1725, 1353, 1353, 1353, 1353, 1353, 1353, + /* 90 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 100 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 110 */ 1422, 1353, 1736, 1736, 1736, 1420, 1353, 1353, 1353, 1353, + /* 120 */ 1353, 1353, 1516, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 130 */ 1353, 1596, 1353, 1353, 1802, 1353, 1602, 1760, 1353, 1353, + /* 140 */ 1353, 1353, 1469, 1752, 1728, 1742, 1729, 1787, 1787, 1787, + /* 150 */ 1745, 1353, 1756, 1353, 1353, 1353, 1588, 1353, 1353, 1565, + /* 160 */ 1562, 1562, 1353, 1353, 1353, 1353, 1422, 1353, 1422, 1353, + /* 170 */ 1353, 1422, 1353, 1422, 1353, 1353, 1422, 1422, 1353, 1422, + /* 180 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 190 */ 1353, 1353, 1353, 1353, 1353, 1353, 1420, 1598, 1353, 1420, + /* 200 */ 1353, 1353, 1420, 1353, 1353, 1420, 1353, 1767, 1765, 1353, + /* 210 */ 1767, 1765, 1353, 1353, 1353, 1779, 1775, 1758, 1756, 1742, + /* 220 */ 1353, 1353, 1353, 1793, 1789, 1805, 1793, 1789, 1793, 1789, + /* 230 */ 1353, 1765, 1353, 1353, 1765, 1353, 1573, 1353, 1353, 1420, + /* 240 */ 1353, 1420, 1353, 1485, 1353, 1353, 1420, 1353, 1590, 1604, + /* 250 */ 1519, 1519, 1519, 1423, 1358, 1353, 1353, 1353, 1353, 1353, + /* 260 */ 1353, 1353, 1353, 1353, 1353, 1353, 1669, 1778, 1777, 1701, + /* 270 */ 1700, 1699, 1697, 1668, 1481, 1353, 1353, 1353, 1353, 1353, + /* 280 */ 1662, 1663, 1661, 1660, 1353, 1353, 1353, 1353, 1353, 1353, + /* 290 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1726, 1353, + /* 300 */ 1790, 1794, 1353, 1353, 1353, 1645, 1353, 1353, 1353, 1353, + /* 310 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 320 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 330 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 340 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 350 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 360 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 370 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 380 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1387, + /* 390 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 400 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 410 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 420 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 430 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1450, 1449, 1353, + /* 440 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 450 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 460 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 470 */ 1353, 1749, 1759, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 480 */ 1353, 1353, 1353, 1645, 1353, 1776, 1353, 1735, 1731, 1353, + /* 490 */ 1353, 1727, 1353, 1353, 1788, 1353, 1353, 1353, 1353, 1353, + /* 500 */ 1353, 1353, 1353, 1353, 1721, 1353, 1694, 1353, 1353, 1353, + /* 510 */ 1353, 1353, 1353, 1353, 1353, 1656, 1353, 1353, 1353, 1353, + /* 520 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1644, 1353, + /* 530 */ 1685, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1513, + /* 540 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 550 */ 1353, 1353, 1498, 1496, 1495, 1494, 1353, 1491, 1353, 1353, + /* 560 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1442, + /* 570 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1433, + /* 580 */ 1353, 1432, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 590 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 600 */ 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, 1353, + /* 610 */ 1353, 1353, 1353, 1353, 1353, }; /********** End of lemon-generated parsing tables *****************************/ @@ -1007,10 +1007,10 @@ static const YYCODETYPE yyFallback[] = { 0, /* KILL => nothing */ 0, /* CONNECTION => nothing */ 0, /* TRANSACTION => nothing */ - 0, /* MERGE => nothing */ + 0, /* BALANCE => nothing */ 0, /* VGROUP => nothing */ + 0, /* MERGE => nothing */ 0, /* REDISTRIBUTE => nothing */ - 0, /* SPLIT => nothing */ 0, /* SYNCDB => nothing */ 0, /* DELETE => nothing */ 0, /* NULL => nothing */ @@ -1332,10 +1332,10 @@ static const char *const yyTokenName[] = { /* 170 */ "KILL", /* 171 */ "CONNECTION", /* 172 */ "TRANSACTION", - /* 173 */ "MERGE", + /* 173 */ "BALANCE", /* 174 */ "VGROUP", - /* 175 */ "REDISTRIBUTE", - /* 176 */ "SPLIT", + /* 175 */ "MERGE", + /* 176 */ "REDISTRIBUTE", /* 177 */ "SYNCDB", /* 178 */ "DELETE", /* 179 */ "NULL", @@ -1779,9 +1779,9 @@ static const char *const yyRuleName[] = { /* 252 */ "cmd ::= KILL CONNECTION NK_INTEGER", /* 253 */ "cmd ::= KILL QUERY NK_INTEGER", /* 254 */ "cmd ::= KILL TRANSACTION NK_INTEGER", - /* 255 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", - /* 256 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", - /* 257 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 255 */ "cmd ::= BALANCE VGROUP", + /* 256 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 257 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", /* 258 */ "dnode_list ::= DNODE NK_INTEGER", /* 259 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", /* 260 */ "cmd ::= SYNCDB db_name REPLICA", @@ -2823,9 +2823,9 @@ static const struct { { 238, -3 }, /* (252) cmd ::= KILL CONNECTION NK_INTEGER */ { 238, -3 }, /* (253) cmd ::= KILL QUERY NK_INTEGER */ { 238, -3 }, /* (254) cmd ::= KILL TRANSACTION NK_INTEGER */ - { 238, -4 }, /* (255) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ - { 238, -4 }, /* (256) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ - { 238, -3 }, /* (257) cmd ::= SPLIT VGROUP NK_INTEGER */ + { 238, -2 }, /* (255) cmd ::= BALANCE VGROUP */ + { 238, -4 }, /* (256) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + { 238, -4 }, /* (257) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ { 305, -2 }, /* (258) dnode_list ::= DNODE NK_INTEGER */ { 305, -3 }, /* (259) dnode_list ::= dnode_list DNODE NK_INTEGER */ { 238, -3 }, /* (260) cmd ::= SYNCDB db_name REPLICA */ @@ -3900,15 +3900,15 @@ static YYACTIONTYPE yy_reduce( case 254: /* cmd ::= KILL TRANSACTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_TRANSACTION_STMT, &yymsp[0].minor.yy0); } break; - case 255: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + case 255: /* cmd ::= BALANCE VGROUP */ +{ pCxt->pRootNode = createBalanceVgroupStmt(pCxt); } + break; + case 256: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 256: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + case 257: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ { pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy60); } break; - case 257: /* cmd ::= SPLIT VGROUP NK_INTEGER */ -{ pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } - break; case 258: /* dnode_list ::= DNODE NK_INTEGER */ { yymsp[-1].minor.yy60 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } break; diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index 8fb28ce395..c7f0990132 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -207,6 +207,13 @@ int32_t __catalogGetUdfInfo(SCatalog* pCtg, void* pTrans, const SEpSet* pMgmtEps return g_mockCatalogService->catalogGetUdfInfo(funcName, pInfo); } +int32_t __catalogRefreshGetTableMeta(SCatalog* pCatalog, void* pTransporter, const SEpSet* pMgmtEps, + const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable) { + return g_mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta); +} + +int32_t __catalogRemoveTableMeta(SCatalog* pCtg, SName* pTableName) { return 0; } + void initMetaDataEnv() { g_mockCatalogService.reset(new MockCatalogService()); @@ -221,6 +228,8 @@ void initMetaDataEnv() { stub.set(catalogGetDBCfg, __catalogGetDBCfg); stub.set(catalogChkAuth, __catalogChkAuth); stub.set(catalogGetUdfInfo, __catalogGetUdfInfo); + stub.set(catalogRefreshGetTableMeta, __catalogRefreshGetTableMeta); + stub.set(catalogRemoveTableMeta, __catalogRemoveTableMeta); // { // AddrAny any("libcatalog.so"); // std::map result; diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index 4834d2d377..0c37c875c0 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -367,49 +367,40 @@ class MockCatalogServiceImpl { } int32_t getAllTableMeta(SArray* pTableMetaReq, SArray** pTableMetaData) const { - int32_t code = TSDB_CODE_SUCCESS; if (NULL != pTableMetaReq) { int32_t ntables = taosArrayGetSize(pTableMetaReq); - *pTableMetaData = taosArrayInit(ntables, POINTER_BYTES); + *pTableMetaData = taosArrayInit(ntables, sizeof(SMetaRes)); for (int32_t i = 0; i < ntables; ++i) { - STableMeta* pMeta = NULL; - code = catalogGetTableMeta((const SName*)taosArrayGet(pTableMetaReq, i), &pMeta); - if (TSDB_CODE_SUCCESS == code) { - taosArrayPush(*pTableMetaData, &pMeta); - } else { - break; - } + SMetaRes res = {0}; + res.code = catalogGetTableMeta((const SName*)taosArrayGet(pTableMetaReq, i), (STableMeta**)&res.pRes); + taosArrayPush(*pTableMetaData, &res); } } - return code; + return TSDB_CODE_SUCCESS; } int32_t getAllTableVgroup(SArray* pTableVgroupReq, SArray** pTableVgroupData) const { - int32_t code = TSDB_CODE_SUCCESS; if (NULL != pTableVgroupReq) { int32_t ntables = taosArrayGetSize(pTableVgroupReq); - *pTableVgroupData = taosArrayInit(ntables, sizeof(SVgroupInfo)); + *pTableVgroupData = taosArrayInit(ntables, sizeof(SMetaRes)); for (int32_t i = 0; i < ntables; ++i) { - SVgroupInfo vgInfo = {0}; - code = catalogGetTableHashVgroup((const SName*)taosArrayGet(pTableVgroupReq, i), &vgInfo); - if (TSDB_CODE_SUCCESS == code) { - taosArrayPush(*pTableVgroupData, &vgInfo); - } else { - break; - } + SMetaRes res = {0}; + res.pRes = taosMemoryCalloc(1, sizeof(SVgroupInfo)); + res.code = catalogGetTableHashVgroup((const SName*)taosArrayGet(pTableVgroupReq, i), (SVgroupInfo*)res.pRes); + taosArrayPush(*pTableVgroupData, &res); } } - return code; + return TSDB_CODE_SUCCESS; } int32_t getAllDbVgroup(SArray* pDbVgroupReq, SArray** pDbVgroupData) const { int32_t code = TSDB_CODE_SUCCESS; if (NULL != pDbVgroupReq) { int32_t ndbs = taosArrayGetSize(pDbVgroupReq); - *pDbVgroupData = taosArrayInit(ndbs, POINTER_BYTES); + *pDbVgroupData = taosArrayInit(ndbs, sizeof(SMetaRes)); for (int32_t i = 0; i < ndbs; ++i) { - int64_t zeroVg = 0; - taosArrayPush(*pDbVgroupData, &zeroVg); + SMetaRes res = {0}; + taosArrayPush(*pDbVgroupData, &res); } } return code; @@ -419,10 +410,11 @@ class MockCatalogServiceImpl { int32_t code = TSDB_CODE_SUCCESS; if (NULL != pDbCfgReq) { int32_t ndbs = taosArrayGetSize(pDbCfgReq); - *pDbCfgData = taosArrayInit(ndbs, sizeof(SDbCfgInfo)); + *pDbCfgData = taosArrayInit(ndbs, sizeof(SMetaRes)); for (int32_t i = 0; i < ndbs; ++i) { - SDbCfgInfo dbCfg = {0}; - taosArrayPush(*pDbCfgData, &dbCfg); + SMetaRes res = {0}; + res.pRes = taosMemoryCalloc(1, sizeof(SDbCfgInfo)); + taosArrayPush(*pDbCfgData, &res); } } return code; @@ -432,10 +424,11 @@ class MockCatalogServiceImpl { int32_t code = TSDB_CODE_SUCCESS; if (NULL != pDbInfoReq) { int32_t ndbs = taosArrayGetSize(pDbInfoReq); - *pDbInfoData = taosArrayInit(ndbs, sizeof(SDbCfgInfo)); + *pDbInfoData = taosArrayInit(ndbs, sizeof(SMetaRes)); for (int32_t i = 0; i < ndbs; ++i) { - SDbInfo dbInfo = {0}; - taosArrayPush(*pDbInfoData, &dbInfo); + SMetaRes res = {0}; + res.pRes = taosMemoryCalloc(1, sizeof(SDbInfo)); + taosArrayPush(*pDbInfoData, &res); } } return code; @@ -445,31 +438,29 @@ class MockCatalogServiceImpl { int32_t code = TSDB_CODE_SUCCESS; if (NULL != pUserAuthReq) { int32_t num = taosArrayGetSize(pUserAuthReq); - *pUserAuthData = taosArrayInit(num, sizeof(bool)); + *pUserAuthData = taosArrayInit(num, sizeof(SMetaRes)); for (int32_t i = 0; i < num; ++i) { - bool pass = true; - taosArrayPush(*pUserAuthData, &pass); + SMetaRes res = {0}; + res.pRes = taosMemoryCalloc(1, sizeof(bool)); + *(bool*)(res.pRes) = true; + taosArrayPush(*pUserAuthData, &res); } } return code; } int32_t getAllUdf(SArray* pUdfReq, SArray** pUdfData) const { - int32_t code = TSDB_CODE_SUCCESS; if (NULL != pUdfReq) { int32_t num = taosArrayGetSize(pUdfReq); - *pUdfData = taosArrayInit(num, sizeof(SFuncInfo)); + *pUdfData = taosArrayInit(num, sizeof(SMetaRes)); for (int32_t i = 0; i < num; ++i) { - SFuncInfo info = {0}; - code = catalogGetUdfInfo((char*)taosArrayGet(pUdfReq, i), &info); - if (TSDB_CODE_SUCCESS == code) { - taosArrayPush(*pUdfData, &info); - } else { - break; - } + SMetaRes res = {0}; + res.pRes = taosMemoryCalloc(1, sizeof(SFuncInfo)); + res.code = catalogGetUdfInfo((char*)taosArrayGet(pUdfReq, i), (SFuncInfo*)res.pRes); + taosArrayPush(*pUdfData, &res); } } - return code; + return TSDB_CODE_SUCCESS; } uint64_t id_; diff --git a/source/libs/parser/test/parExplainToSyncdbTest.cpp b/source/libs/parser/test/parExplainToSyncdbTest.cpp index a040721031..4a5a92e621 100644 --- a/source/libs/parser/test/parExplainToSyncdbTest.cpp +++ b/source/libs/parser/test/parExplainToSyncdbTest.cpp @@ -19,7 +19,7 @@ using namespace std; namespace ParserTest { -class ParserExplainToSyncdbTest : public ParserTestBase {}; +class ParserExplainToSyncdbTest : public ParserDdlTest {}; TEST_F(ParserExplainToSyncdbTest, explain) { useDb("root", "test"); @@ -43,8 +43,62 @@ TEST_F(ParserExplainToSyncdbTest, grant) { // todo kill connection // todo kill query // todo kill stream -// todo merge vgroup -// todo redistribute vgroup + +TEST_F(ParserExplainToSyncdbTest, mergeVgroup) { + useDb("root", "test"); + + SMergeVgroupReq expect = {0}; + + auto setMergeVgroupReqFunc = [&](int32_t vgId1, int32_t vgId2) { + expect.vgId1 = vgId1; + expect.vgId2 = vgId2; + }; + + setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) { + ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_MERGE_VGROUP_STMT); + ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_MERGE_VGROUP); + SMergeVgroupReq req = {0}; + ASSERT_EQ(tDeserializeSMergeVgroupReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS); + ASSERT_EQ(req.vgId1, expect.vgId1); + ASSERT_EQ(req.vgId2, expect.vgId2); + }); + + setMergeVgroupReqFunc(1, 2); + run("MERGE VGROUP 1 2"); +} + +TEST_F(ParserExplainToSyncdbTest, redistributeVgroup) { + useDb("root", "test"); + + SRedistributeVgroupReq expect = {0}; + + auto setRedistributeVgroupReqFunc = [&](int32_t vgId, int32_t dnodeId1, int32_t dnodeId2 = -1, + int32_t dnodeId3 = -1) { + expect.vgId = vgId; + expect.dnodeId1 = dnodeId1; + expect.dnodeId2 = dnodeId2; + expect.dnodeId3 = dnodeId3; + }; + + setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) { + ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_REDISTRIBUTE_VGROUP_STMT); + ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_REDISTRIBUTE_VGROUP); + SRedistributeVgroupReq req = {0}; + ASSERT_EQ(tDeserializeSRedistributeVgroupReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), + TSDB_CODE_SUCCESS); + ASSERT_EQ(req.vgId, expect.vgId); + ASSERT_EQ(req.dnodeId1, expect.dnodeId1); + ASSERT_EQ(req.dnodeId2, expect.dnodeId2); + ASSERT_EQ(req.dnodeId3, expect.dnodeId3); + }); + + setRedistributeVgroupReqFunc(3, 1); + run("REDISTRIBUTE VGROUP 3 DNODE 1"); + + setRedistributeVgroupReqFunc(5, 10, 20, 30); + run("REDISTRIBUTE VGROUP 5 DNODE 10 DNODE 20 DNODE 30"); +} + // todo reset query cache TEST_F(ParserExplainToSyncdbTest, revoke) { diff --git a/source/libs/parser/test/parInitialATest.cpp b/source/libs/parser/test/parInitialATest.cpp index 784586dfb2..22b244145b 100644 --- a/source/libs/parser/test/parInitialATest.cpp +++ b/source/libs/parser/test/parInitialATest.cpp @@ -39,6 +39,8 @@ TEST_F(ParserInitialATest, alterDatabase) { useDb("root", "test"); run("ALTER DATABASE wxy_db CACHELAST 1 FSYNC 200 WAL 1"); + + run("ALTER DATABASE wxy_db KEEP 2400"); } // todo ALTER local @@ -305,6 +307,19 @@ TEST_F(ParserInitialATest, alterUser) { run("ALTER user wxy privilege 'write'"); } +TEST_F(ParserInitialATest, balanceVgroup) { + useDb("root", "test"); + + setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) { + ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_BALANCE_VGROUP_STMT); + ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_BALANCE_VGROUP); + SBalanceVgroupReq req = {0}; + ASSERT_EQ(tDeserializeSBalanceVgroupReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS); + }); + + run("BALANCE VGROUP"); +} + TEST_F(ParserInitialATest, bug001) { useDb("root", "test"); diff --git a/source/libs/parser/test/parInitialDTest.cpp b/source/libs/parser/test/parInitialDTest.cpp index d4f9a540ae..8562926789 100644 --- a/source/libs/parser/test/parInitialDTest.cpp +++ b/source/libs/parser/test/parInitialDTest.cpp @@ -21,7 +21,7 @@ namespace ParserTest { class ParserInitialDTest : public ParserDdlTest {}; -// DELETE FROM tb_name [WHERE condition] +// DELETE FROM table_name [WHERE condition] TEST_F(ParserInitialDTest, delete) { useDb("root", "test"); @@ -40,7 +40,15 @@ TEST_F(ParserInitialDTest, deleteSemanticCheck) { run("DELETE FROM t1 WHERE c1 > 10", TSDB_CODE_PAR_INVALID_DELETE_WHERE, PARSER_STAGE_TRANSLATE); } -// todo desc +// DESC table_name +TEST_F(ParserInitialDTest, describe) { + useDb("root", "test"); + + run("DESC t1"); + + run("DESCRIBE st1"); +} + // todo describe // todo DROP account @@ -51,7 +59,7 @@ TEST_F(ParserInitialDTest, dropBnode) { } // DROP CONSUMER GROUP [ IF EXISTS ] cgroup_name ON topic_name -TEST_F(ParserInitialDTest, dropCGroup) { +TEST_F(ParserInitialDTest, dropConsumerGroup) { useDb("root", "test"); SMDropCgroupReq expect = {0}; diff --git a/source/libs/parser/test/parTestUtil.h b/source/libs/parser/test/parTestUtil.h index 44be7a2474..07f3d3cece 100644 --- a/source/libs/parser/test/parTestUtil.h +++ b/source/libs/parser/test/parTestUtil.h @@ -50,11 +50,13 @@ class ParserDdlTest : public ParserTestBase { virtual void checkDdl(const SQuery* pQuery, ParserStage stage) { ASSERT_NE(pQuery, nullptr); - ASSERT_EQ(pQuery->haveResultSet, false); ASSERT_NE(pQuery->pRoot, nullptr); - ASSERT_EQ(pQuery->numOfResCols, 0); - ASSERT_EQ(pQuery->pResSchema, nullptr); - ASSERT_EQ(pQuery->precision, 0); + if (QUERY_EXEC_MODE_RPC == pQuery->execMode) { + ASSERT_EQ(pQuery->haveResultSet, false); + ASSERT_EQ(pQuery->numOfResCols, 0); + ASSERT_EQ(pQuery->pResSchema, nullptr); + ASSERT_EQ(pQuery->precision, 0); + } if (nullptr != checkDdl_) { checkDdl_(pQuery, stage); } diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index c3aad632c7..a9f3909af6 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -219,9 +219,9 @@ static int32_t makeScanLogicNode(SLogicPlanContext* pCxt, SRealTableNode* pRealT return TSDB_CODE_OUT_OF_MEMORY; } - // TSWAP(pScan->pMeta, pRealTable->pMeta); TSWAP(pScan->pVgroupList, pRealTable->pVgroupList); pScan->tableId = pRealTable->pMeta->uid; + pScan->stableId = pRealTable->pMeta->suid; pScan->tableType = pRealTable->pMeta->tableType; pScan->scanSeq[0] = hasRepeatScanFuncs ? 2 : 1; pScan->scanSeq[1] = 0; @@ -456,6 +456,37 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, return code; } +static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { + // top/bottom are both an aggregate function and a indefinite rows function + if (!pSelect->hasIndefiniteRowsFunc || pSelect->hasAggFuncs || NULL != pSelect->pWindow) { + return TSDB_CODE_SUCCESS; + } + + SIndefRowsFuncLogicNode* pIdfRowsFunc = + (SIndefRowsFuncLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC); + if (NULL == pIdfRowsFunc) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, fmIsVectorFunc, &pIdfRowsFunc->pVectorFuncs); + if (TSDB_CODE_SUCCESS == code) { + code = rewriteExprForSelect(pIdfRowsFunc->pVectorFuncs, pSelect, SQL_CLAUSE_SELECT); + } + + // set the output + if (TSDB_CODE_SUCCESS == code) { + code = createColumnByRewriteExps(pIdfRowsFunc->pVectorFuncs, &pIdfRowsFunc->node.pTargets); + } + + if (TSDB_CODE_SUCCESS == code) { + *pLogicNode = (SLogicNode*)pIdfRowsFunc; + } else { + nodesDestroyNode(pIdfRowsFunc); + } + + return code; +} + static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow, SLogicNode** pLogicNode) { int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_WINDOW, fmIsWindowClauseFunc, &pWindow->pFuncs); @@ -772,6 +803,9 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele if (TSDB_CODE_SUCCESS == code) { code = createSelectRootLogicNode(pCxt, pSelect, createAggLogicNode, &pRoot); } + if (TSDB_CODE_SUCCESS == code) { + code = createSelectRootLogicNode(pCxt, pSelect, createIndefRowsFuncLogicNode, &pRoot); + } if (TSDB_CODE_SUCCESS == code) { code = createSelectRootLogicNode(pCxt, pSelect, createDistinctLogicNode, &pRoot); } @@ -1057,8 +1091,8 @@ static int32_t createVnodeModifLogicNodeByDelete(SLogicPlanContext* pCxt, SDelet snprintf(pModify->tableFName, sizeof(pModify->tableFName), "%d.%s.%s", pCxt->pPlanCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName); pModify->deleteTimeRange = pDelete->timeRange; - pModify->pModifyRows = nodesCloneNode(pDelete->pCountFunc); - if (NULL == pModify->pModifyRows) { + pModify->pAffectedRows = nodesCloneNode(pDelete->pCountFunc); + if (NULL == pModify->pAffectedRows) { nodesDestroyNode(pModify); return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 3c000e3ff7..52add839b4 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -425,6 +425,7 @@ static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SSubplan* pS if (TSDB_CODE_SUCCESS == code) { pScanPhysiNode->uid = pScanLogicNode->tableId; + pScanPhysiNode->suid = pScanLogicNode->stableId; pScanPhysiNode->tableType = pScanLogicNode->tableType; memcpy(&pScanPhysiNode->tableName, &pScanLogicNode->tableName, sizeof(SName)); if (NULL != pScanLogicNode->pTagCond) { @@ -555,7 +556,7 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) { SJoinPhysiNode* pJoin = - (SJoinPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN); + (SJoinPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN); if (NULL == pJoin) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -737,7 +738,8 @@ static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeLi static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, SPhysiNode** pPhyNode) { - SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG); + SAggPhysiNode* pAgg = + (SAggPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_HASH_AGG); if (NULL == pAgg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -790,6 +792,43 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, return code; } +static int32_t createIndefRowsFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SIndefRowsFuncLogicNode* pFuncLogicNode, SPhysiNode** pPhyNode) { + SIndefRowsFuncPhysiNode* pIdfRowsFunc = (SIndefRowsFuncPhysiNode*)makePhysiNode( + pCxt, (SLogicNode*)pFuncLogicNode, QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC); + if (NULL == pIdfRowsFunc) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + SNodeList* pPrecalcExprs = NULL; + SNodeList* pVectorFuncs = NULL; + int32_t code = rewritePrecalcExprs(pCxt, pFuncLogicNode->pVectorFuncs, &pPrecalcExprs, &pVectorFuncs); + + SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); + // push down expression to pOutputDataBlockDesc of child node + if (TSDB_CODE_SUCCESS == code && NULL != pPrecalcExprs) { + code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs, &pIdfRowsFunc->pExprs); + if (TSDB_CODE_SUCCESS == code) { + code = pushdownDataBlockSlots(pCxt, pIdfRowsFunc->pExprs, pChildTupe); + } + } + + if (TSDB_CODE_SUCCESS == code && NULL != pVectorFuncs) { + code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pVectorFuncs, &pIdfRowsFunc->pVectorFuncs); + if (TSDB_CODE_SUCCESS == code) { + code = addDataBlockSlots(pCxt, pIdfRowsFunc->pVectorFuncs, pIdfRowsFunc->node.pOutputDataBlockDesc); + } + } + + if (TSDB_CODE_SUCCESS == code) { + *pPhyNode = (SPhysiNode*)pIdfRowsFunc; + } else { + nodesDestroyNode(pIdfRowsFunc); + } + + return code; +} + static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) { SProjectPhysiNode* pProject = @@ -923,8 +962,8 @@ static ENodeType getIntervalOperatorType(EIntervalAlgorithm intervalAlgo) { switch (intervalAlgo) { case INTERVAL_ALGO_HASH: return QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL; - case INTERVAL_ALGO_SORT_MERGE: - return QUERY_NODE_PHYSICAL_PLAN_SORT_MERGE_INTERVAL; + case INTERVAL_ALGO_MERGE: + return QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL; case INTERVAL_ALGO_STREAM_FINAL: return QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL; case INTERVAL_ALGO_STREAM_SEMI: @@ -958,8 +997,7 @@ static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode( pCxt, (SLogicNode*)pWindowLogicNode, - (pCxt->pPlanCxt->streamQuery ? QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW - : QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW)); + (pCxt->pPlanCxt->streamQuery ? QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION : QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION)); if (NULL == pSession) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -971,10 +1009,9 @@ static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SStateWinodwPhysiNode* pState = - (SStateWinodwPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, - (pCxt->pPlanCxt->streamQuery ? QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW - : QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW)); + SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode( + pCxt, (SLogicNode*)pWindowLogicNode, + (pCxt->pPlanCxt->streamQuery ? QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE : QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE)); if (NULL == pState) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1155,6 +1192,8 @@ static int32_t createExchangePhysiNodeByMerge(SMergePhysiNode* pMerge) { nodesDestroyNode(pExchange); return TSDB_CODE_OUT_OF_MEMORY; } + SNode* pSlot = NULL; + FOREACH(pSlot, pExchange->node.pOutputDataBlockDesc->pSlots) { ((SSlotDescNode*)pSlot)->output = true; } return nodesListMakeStrictAppend(&pMerge->node.pChildren, pExchange); } @@ -1168,12 +1207,14 @@ static int32_t createMergePhysiNode(SPhysiPlanContext* pCxt, SMergeLogicNode* pM pMerge->numOfChannels = pMergeLogicNode->numOfChannels; pMerge->srcGroupId = pMergeLogicNode->srcGroupId; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = addDataBlockSlots(pCxt, pMergeLogicNode->pInputs, pMerge->node.pOutputDataBlockDesc); - for (int32_t i = 0; i < pMerge->numOfChannels; ++i) { - code = createExchangePhysiNodeByMerge(pMerge); - if (TSDB_CODE_SUCCESS != code) { - break; + if (TSDB_CODE_SUCCESS == code) { + for (int32_t i = 0; i < pMerge->numOfChannels; ++i) { + code = createExchangePhysiNodeByMerge(pMerge); + if (TSDB_CODE_SUCCESS != code) { + break; + } } } @@ -1182,6 +1223,14 @@ static int32_t createMergePhysiNode(SPhysiPlanContext* pCxt, SMergeLogicNode* pM &pMerge->pMergeKeys); } + if (TSDB_CODE_SUCCESS == code) { + code = setListSlotId(pCxt, pMerge->node.pOutputDataBlockDesc->dataBlockId, -1, pMergeLogicNode->node.pTargets, + &pMerge->pTargets); + } + if (TSDB_CODE_SUCCESS == code) { + code = addDataBlockSlots(pCxt, pMerge->pTargets, pMerge->node.pOutputDataBlockDesc); + } + if (TSDB_CODE_SUCCESS == code) { *pPhyNode = (SPhysiNode*)pMerge; } else { @@ -1212,6 +1261,8 @@ static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode return createPartitionPhysiNode(pCxt, pChildren, (SPartitionLogicNode*)pLogicNode, pPhyNode); case QUERY_NODE_LOGIC_PLAN_FILL: return createFillPhysiNode(pCxt, pChildren, (SFillLogicNode*)pLogicNode, pPhyNode); + case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: + return createIndefRowsFuncPhysiNode(pCxt, pChildren, (SIndefRowsFuncLogicNode*)pLogicNode, pPhyNode); case QUERY_NODE_LOGIC_PLAN_MERGE: return createMergePhysiNode(pCxt, (SMergeLogicNode*)pLogicNode, pPhyNode); default: @@ -1319,13 +1370,21 @@ static int32_t createDataDeleter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* strcpy(pDeleter->tableFName, pModify->tableFName); pDeleter->deleteTimeRange = pModify->deleteTimeRange; - pDeleter->sink.pInputDataBlockDesc = nodesCloneNode(pRoot->pOutputDataBlockDesc); - if (NULL == pDeleter->sink.pInputDataBlockDesc) { - nodesDestroyNode(pDeleter); - return TSDB_CODE_OUT_OF_MEMORY; + int32_t code = setNodeSlotId(pCxt, pRoot->pOutputDataBlockDesc->dataBlockId, -1, pModify->pAffectedRows, + &pDeleter->pAffectedRows); + if (TSDB_CODE_SUCCESS == code) { + pDeleter->sink.pInputDataBlockDesc = nodesCloneNode(pRoot->pOutputDataBlockDesc); + if (NULL == pDeleter->sink.pInputDataBlockDesc) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + } + + if (TSDB_CODE_SUCCESS == code) { + *pSink = (SDataSinkNode*)pDeleter; + } else { + nodesDestroyNode(pDeleter); } - *pSink = (SDataSinkNode*)pDeleter; return TSDB_CODE_SUCCESS; } @@ -1335,6 +1394,7 @@ static int32_t buildDeleteSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode if (TSDB_CODE_SUCCESS == code) { code = createDataDeleter(pCxt, pModify, pSubplan->pNode, &pSubplan->pDataSink); } + pSubplan->msgType = TDMT_VND_DELETE; return code; } diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index 9e6c25ce78..a7f53bb752 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -80,30 +80,36 @@ static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicNode* pChild, SE return TSDB_CODE_SUCCESS; } -static int32_t splCreateExchangeNodeForSubplan(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pSplitNode, - ESubplanType subplanType) { - SExchangeLogicNode* pExchange = NULL; - if (TSDB_CODE_SUCCESS != splCreateExchangeNode(pCxt, pSplitNode, &pExchange)) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - pSubplan->subplanType = subplanType; - - if (NULL == pSplitNode->pParent) { - pSubplan->pNode = (SLogicNode*)pExchange; +static int32_t splReplaceLogicNode(SLogicSubplan* pSubplan, SLogicNode* pOld, SLogicNode* pNew) { + if (NULL == pOld->pParent) { + pSubplan->pNode = (SLogicNode*)pNew; return TSDB_CODE_SUCCESS; } SNode* pNode; - FOREACH(pNode, pSplitNode->pParent->pChildren) { - if (nodesEqualNode(pNode, pSplitNode)) { - REPLACE_NODE(pExchange); - pExchange->node.pParent = pSplitNode->pParent; + FOREACH(pNode, pOld->pParent->pChildren) { + if (nodesEqualNode(pNode, pOld)) { + REPLACE_NODE(pNew); + pNew->pParent = pOld->pParent; return TSDB_CODE_SUCCESS; } } - nodesDestroyNode(pExchange); - return TSDB_CODE_FAILED; + return TSDB_CODE_PLAN_INTERNAL_ERROR; +} + +static int32_t splCreateExchangeNodeForSubplan(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pSplitNode, + ESubplanType subplanType) { + SExchangeLogicNode* pExchange = NULL; + int32_t code = splCreateExchangeNode(pCxt, pSplitNode, &pExchange); + if (TSDB_CODE_SUCCESS == code) { + code = splReplaceLogicNode(pSubplan, pSplitNode, (SLogicNode*)pExchange); + } + if (TSDB_CODE_SUCCESS == code) { + pSubplan->subplanType = subplanType; + } else { + nodesDestroyNode(pExchange); + } + return code; } static bool splMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, int32_t flag, FSplFindSplitNode func, void* pInfo) { @@ -160,8 +166,8 @@ static bool stbSplNeedSplit(bool streamQuery, SLogicNode* pNode) { } return !stbSplHasGatherExecFunc(pWindow->pFuncs) && stbSplHasMultiTbScan(streamQuery, pNode); } - // case QUERY_NODE_LOGIC_PLAN_SORT: - // return stbSplHasMultiTbScan(streamQuery, pNode); + case QUERY_NODE_LOGIC_PLAN_SORT: + return stbSplHasMultiTbScan(streamQuery, pNode); case QUERY_NODE_LOGIC_PLAN_SCAN: return stbSplIsMultiTbScan(streamQuery, (SScanLogicNode*)pNode); default: @@ -295,24 +301,34 @@ static int32_t stbSplCreatePartWindowNode(SWindowLogicNode* pMergeWindow, SLogic return code; } -static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicNode* pParent, SNodeList* pMergeKeys, - SLogicNode* pPartChild) { +static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pSplitNode, + SNodeList* pMergeKeys, SLogicNode* pPartChild) { SMergeLogicNode* pMerge = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_MERGE); if (NULL == pMerge) { return TSDB_CODE_OUT_OF_MEMORY; } pMerge->numOfChannels = ((SScanLogicNode*)nodesListGetNode(pPartChild->pChildren, 0))->pVgroupList->numOfVgroups; pMerge->srcGroupId = pCxt->groupId; - pMerge->node.pParent = pParent; pMerge->node.precision = pPartChild->precision; pMerge->pMergeKeys = pMergeKeys; - pMerge->node.pTargets = nodesCloneList(pPartChild->pTargets); - if (NULL == pMerge->node.pTargets) { - nodesDestroyNode(pMerge); - return TSDB_CODE_OUT_OF_MEMORY; - } - return nodesListMakeAppend(&pParent->pChildren, pMerge); + int32_t code = TSDB_CODE_SUCCESS; + pMerge->pInputs = nodesCloneList(pPartChild->pTargets); + pMerge->node.pTargets = nodesCloneList(pSplitNode->pTargets); + if (NULL == pMerge->node.pTargets || NULL == pMerge->pInputs) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + if (TSDB_CODE_SUCCESS == code) { + if (NULL == pSubplan) { + code = nodesListMakeAppend(&pSplitNode->pChildren, pMerge); + } else { + code = splReplaceLogicNode(pSubplan, pSplitNode, (SLogicNode*)pMerge); + } + } + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyNode(pMerge); + } + return code; } static int32_t stbSplCreateExchangeNode(SSplitContext* pCxt, SLogicNode* pParent, SLogicNode* pPartChild) { @@ -324,13 +340,20 @@ static int32_t stbSplCreateExchangeNode(SSplitContext* pCxt, SLogicNode* pParent return code; } -static int32_t stbSplSplitWindowNodeForBatch(SSplitContext* pCxt, SStableSplitInfo* pInfo) { +static int32_t stbSplSplitIntervalForBatch(SSplitContext* pCxt, SStableSplitInfo* pInfo) { SLogicNode* pPartWindow = NULL; int32_t code = stbSplCreatePartWindowNode((SWindowLogicNode*)pInfo->pSplitNode, &pPartWindow); if (TSDB_CODE_SUCCESS == code) { ((SWindowLogicNode*)pPartWindow)->intervalAlgo = INTERVAL_ALGO_HASH; - ((SWindowLogicNode*)pInfo->pSplitNode)->intervalAlgo = INTERVAL_ALGO_SORT_MERGE; - code = stbSplCreateExchangeNode(pCxt, pInfo->pSplitNode, pPartWindow); + ((SWindowLogicNode*)pInfo->pSplitNode)->intervalAlgo = INTERVAL_ALGO_MERGE; + SNodeList* pMergeKeys = NULL; + code = nodesListMakeStrictAppend(&pMergeKeys, nodesCloneNode(((SWindowLogicNode*)pInfo->pSplitNode)->pTspk)); + if (TSDB_CODE_SUCCESS == code) { + code = stbSplCreateMergeNode(pCxt, NULL, pInfo->pSplitNode, pMergeKeys, pPartWindow); + } + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyList(pMergeKeys); + } } if (TSDB_CODE_SUCCESS == code) { code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren, @@ -340,7 +363,7 @@ static int32_t stbSplSplitWindowNodeForBatch(SSplitContext* pCxt, SStableSplitIn return code; } -static int32_t stbSplSplitWindowNodeForStream(SSplitContext* pCxt, SStableSplitInfo* pInfo) { +static int32_t stbSplSplitIntervalForStream(SSplitContext* pCxt, SStableSplitInfo* pInfo) { SLogicNode* pPartWindow = NULL; int32_t code = stbSplCreatePartWindowNode((SWindowLogicNode*)pInfo->pSplitNode, &pPartWindow); if (TSDB_CODE_SUCCESS == code) { @@ -356,14 +379,30 @@ static int32_t stbSplSplitWindowNodeForStream(SSplitContext* pCxt, SStableSplitI return code; } -static int32_t stbSplSplitWindowNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) { +static int32_t stbSplSplitInterval(SSplitContext* pCxt, SStableSplitInfo* pInfo) { if (pCxt->pPlanCxt->streamQuery) { - return stbSplSplitWindowNodeForStream(pCxt, pInfo); + return stbSplSplitIntervalForStream(pCxt, pInfo); } else { - return stbSplSplitWindowNodeForBatch(pCxt, pInfo); + return stbSplSplitIntervalForBatch(pCxt, pInfo); } } +static int32_t stbSplSplitSession(SSplitContext* pCxt, SStableSplitInfo* pInfo) { + return TSDB_CODE_PLAN_INTERNAL_ERROR; +} + +static int32_t stbSplSplitWindowNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) { + switch (((SWindowLogicNode*)pInfo->pSplitNode)->winType) { + case WINDOW_TYPE_INTERVAL: + return stbSplSplitInterval(pCxt, pInfo); + case WINDOW_TYPE_SESSION: + return stbSplSplitSession(pCxt, pInfo); + default: + break; + } + return TSDB_CODE_PLAN_INTERNAL_ERROR; +} + static int32_t stbSplCreatePartAggNode(SAggLogicNode* pMergeAgg, SLogicNode** pOutput) { SNodeList* pFunc = pMergeAgg->pAggFuncs; pMergeAgg->pAggFuncs = NULL; @@ -424,37 +463,99 @@ static int32_t stbSplSplitAggNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) return code; } -static int32_t stbSplCreatePartSortNode(SSortLogicNode* pMergeSort, SLogicNode** pOutput) { - SNodeList* pSortKeys = pMergeSort->pSortKeys; - pMergeSort->pSortKeys = NULL; - SNodeList* pTargets = pMergeSort->node.pTargets; - pMergeSort->node.pTargets = NULL; - SNodeList* pChildren = pMergeSort->node.pChildren; - pMergeSort->node.pChildren = NULL; +static SNode* stbSplCreateColumnNode(SExprNode* pExpr) { + SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN); + if (NULL == pCol) { + return NULL; + } + if (QUERY_NODE_COLUMN == nodeType(pExpr)) { + strcpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias); + } + strcpy(pCol->colName, pExpr->aliasName); + strcpy(pCol->node.aliasName, pExpr->aliasName); + pCol->node.resType = pExpr->resType; + return (SNode*)pCol; +} + +static SNode* stbSplCreateOrderByExpr(SOrderByExprNode* pSortKey, SNode* pCol) { + SOrderByExprNode* pOutput = nodesMakeNode(QUERY_NODE_ORDER_BY_EXPR); + if (NULL == pOutput) { + return NULL; + } + pOutput->pExpr = nodesCloneNode(pCol); + if (NULL == pOutput->pExpr) { + nodesDestroyNode(pOutput); + return NULL; + } + pOutput->order = pSortKey->order; + pOutput->nullOrder = pSortKey->nullOrder; + return (SNode*)pOutput; +} + +static int32_t stbSplCreateMergeKeys(SNodeList* pSortKeys, SNodeList* pTargets, SNodeList** pOutput) { + int32_t code = TSDB_CODE_SUCCESS; + SNodeList* pMergeKeys = NULL; + SNode* pNode = NULL; + FOREACH(pNode, pSortKeys) { + SOrderByExprNode* pSortKey = (SOrderByExprNode*)pNode; + SNode* pTarget = NULL; + bool found = false; + FOREACH(pTarget, pTargets) { + if (0 == strcmp(((SExprNode*)pSortKey->pExpr)->aliasName, ((SColumnNode*)pTarget)->colName)) { + code = nodesListMakeStrictAppend(&pMergeKeys, stbSplCreateOrderByExpr(pSortKey, pTarget)); + if (TSDB_CODE_SUCCESS != code) { + break; + } + found = true; + } + } + if (TSDB_CODE_SUCCESS == code && !found) { + SNode* pCol = stbSplCreateColumnNode((SExprNode*)pSortKey->pExpr); + code = nodesListMakeStrictAppend(&pMergeKeys, stbSplCreateOrderByExpr(pSortKey, pCol)); + if (TSDB_CODE_SUCCESS == code) { + code = nodesListStrictAppend(pTargets, pCol); + } else { + nodesDestroyNode(pCol); + } + } + if (TSDB_CODE_SUCCESS != code) { + break; + } + } + if (TSDB_CODE_SUCCESS == code) { + *pOutput = pMergeKeys; + } else { + nodesDestroyList(pMergeKeys); + } + return code; +} + +static int32_t stbSplCreatePartSortNode(SSortLogicNode* pSort, SLogicNode** pOutputPartSort, + SNodeList** pOutputMergeKeys) { + SNodeList* pSortKeys = pSort->pSortKeys; + pSort->pSortKeys = NULL; + SNodeList* pChildren = pSort->node.pChildren; + pSort->node.pChildren = NULL; int32_t code = TSDB_CODE_SUCCESS; - SSortLogicNode* pPartSort = nodesCloneNode(pMergeSort); + SSortLogicNode* pPartSort = nodesCloneNode(pSort); if (NULL == pPartSort) { code = TSDB_CODE_OUT_OF_MEMORY; } - pMergeSort->node.pTargets = pTargets; - pPartSort->node.pChildren = pChildren; + SNodeList* pMergeKeys = NULL; if (TSDB_CODE_SUCCESS == code) { + pPartSort->node.pChildren = pChildren; pPartSort->pSortKeys = pSortKeys; - code = createColumnByRewriteExps(pPartSort->pSortKeys, &pPartSort->node.pTargets); - } - if (TSDB_CODE_SUCCESS == code) { - pMergeSort->pSortKeys = nodesCloneList(pPartSort->node.pTargets); - if (NULL == pMergeSort->pSortKeys) { - code = TSDB_CODE_OUT_OF_MEMORY; - } + code = stbSplCreateMergeKeys(pPartSort->pSortKeys, pPartSort->node.pTargets, &pMergeKeys); } if (TSDB_CODE_SUCCESS == code) { - *pOutput = (SLogicNode*)pPartSort; + *pOutputPartSort = (SLogicNode*)pPartSort; + *pOutputMergeKeys = pMergeKeys; } else { nodesDestroyNode(pPartSort); + nodesDestroyList(pMergeKeys); } return code; @@ -462,17 +563,10 @@ static int32_t stbSplCreatePartSortNode(SSortLogicNode* pMergeSort, SLogicNode** static int32_t stbSplSplitSortNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) { SLogicNode* pPartSort = NULL; - int32_t code = stbSplCreatePartSortNode((SSortLogicNode*)pInfo->pSplitNode, &pPartSort); + SNodeList* pMergeKeys = NULL; + int32_t code = stbSplCreatePartSortNode((SSortLogicNode*)pInfo->pSplitNode, &pPartSort, &pMergeKeys); if (TSDB_CODE_SUCCESS == code) { - SNodeList* pMergeKeys = nodesCloneList(((SSortLogicNode*)pInfo->pSplitNode)->pSortKeys); - if (NULL != pMergeKeys) { - code = stbSplCreateMergeNode(pCxt, pInfo->pSplitNode, pMergeKeys, pPartSort); - if (TSDB_CODE_SUCCESS != code) { - nodesDestroyList(pMergeKeys); - } - } else { - code = TSDB_CODE_OUT_OF_MEMORY; - } + code = stbSplCreateMergeNode(pCxt, pInfo->pSubplan, pInfo->pSplitNode, pMergeKeys, pPartSort); } if (TSDB_CODE_SUCCESS == code) { code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren, diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index f8d240c7b2..1921b16388 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -88,7 +88,7 @@ int32_t qSetSubplanExecutionNode(SSubplan* subplan, int32_t groupId, SDownstream } int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen) { - if (SUBPLAN_TYPE_MODIFY == pSubplan->subplanType) { + if (SUBPLAN_TYPE_MODIFY == pSubplan->subplanType && NULL == pSubplan->pNode) { SDataInserterNode* insert = (SDataInserterNode*)pSubplan->pDataSink; *pLen = insert->size; *pStr = insert->pData; diff --git a/source/libs/planner/test/planIntervalTest.cpp b/source/libs/planner/test/planIntervalTest.cpp index a04f47741e..edd735922b 100644 --- a/source/libs/planner/test/planIntervalTest.cpp +++ b/source/libs/planner/test/planIntervalTest.cpp @@ -50,6 +50,8 @@ TEST_F(PlanIntervalTest, selectFunc) { run("SELECT MAX(c1), MIN(c1) FROM t1 INTERVAL(10s)"); // select function along with the columns of select row, and with INTERVAL clause run("SELECT MAX(c1), c2 FROM t1 INTERVAL(10s)"); + + run("SELECT TOP(c1, 1) FROM t1 INTERVAL(10s) ORDER BY c1"); } TEST_F(PlanIntervalTest, stable) { diff --git a/source/libs/planner/test/planOrderByTest.cpp b/source/libs/planner/test/planOrderByTest.cpp index ef6f438b55..851eda81b5 100644 --- a/source/libs/planner/test/planOrderByTest.cpp +++ b/source/libs/planner/test/planOrderByTest.cpp @@ -46,4 +46,7 @@ TEST_F(PlanOrderByTest, stable) { // ORDER BY key is in the projection list run("SELECT c1 FROM st1 ORDER BY c1"); + + // ORDER BY key is not in the projection list + run("SELECT c2 FROM st1 ORDER BY c1"); } diff --git a/source/libs/stream/inc/tstreamInc.h b/source/libs/planner/test/planProjectTest.cpp similarity index 64% rename from source/libs/stream/inc/tstreamInc.h rename to source/libs/planner/test/planProjectTest.cpp index c96901e567..3ef0038ae0 100644 --- a/source/libs/stream/inc/tstreamInc.h +++ b/source/libs/planner/test/planProjectTest.cpp @@ -13,15 +13,22 @@ * along with this program. If not, see . */ -#ifdef __cplusplus -extern "C" { -#endif +#include "planTestUtil.h" -#ifndef _TSTREAM_H_ -#define _TSTREAM_H_ +using namespace std; -#ifdef __cplusplus +class PlanProjectTest : public PlannerTestBase {}; + +TEST_F(PlanProjectTest, basic) { + useDb("root", "test"); + + run("SELECT CEIL(c1) FROM t1"); } -#endif -#endif /* ifndef _TSTREAM_H_ */ +TEST_F(PlanProjectTest, indefiniteRowsFunc) { + useDb("root", "test"); + + run("SELECT MAVG(c1, 10) FROM t1"); + + run("SELECT MAVG(CEIL(c1), 20) + 2 FROM t1"); +} diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index e2082d4936..f5c8b58e43 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -81,6 +81,8 @@ int32_t getLogLevel() { return g_logLevel; } class PlannerTestBaseImpl { public: + PlannerTestBaseImpl() : sqlNo_(0) {} + void useDb(const string& acctId, const string& db) { caseEnv_.acctId_ = acctId; caseEnv_.db_ = db; @@ -88,6 +90,7 @@ class PlannerTestBaseImpl { } void run(const string& sql) { + ++sqlNo_; if (caseEnv_.nsql_ > 0) { --(caseEnv_.nsql_); return; @@ -187,6 +190,8 @@ class PlannerTestBaseImpl { string acctId_; string db_; int32_t nsql_; + + caseEnv() : nsql_(0) {} }; struct stmtEnv { @@ -194,6 +199,7 @@ class PlannerTestBaseImpl { array msgBuf_; SQuery* pQuery_; + stmtEnv() : pQuery_(nullptr) {} ~stmtEnv() { qDestroyQuery(pQuery_); } }; @@ -229,7 +235,7 @@ class PlannerTestBaseImpl { return; } - cout << "==========================================sql : [" << stmtEnv_.sql_ << "]" << endl; + cout << "========================================== " << sqlNo_ << " sql : [" << stmtEnv_.sql_ << "]" << endl; if (DUMP_MODULE_ALL == module || DUMP_MODULE_PARSER == module) { if (res_.prepareAst_.empty()) { @@ -382,6 +388,7 @@ class PlannerTestBaseImpl { caseEnv caseEnv_; stmtEnv stmtEnv_; stmtRes res_; + int32_t sqlNo_; }; PlannerTestBase::PlannerTestBase() : impl_(new PlannerTestBaseImpl()) {} diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index e77f2b0ca4..10d0f4a44a 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -37,6 +37,8 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { pOut->dbVgroup->vgVersion = usedbRsp->vgVersion; pOut->dbVgroup->hashMethod = usedbRsp->hashMethod; + qDebug("Got %d vgroup for db %s", usedbRsp->vgNum, usedbRsp->db); + if (usedbRsp->vgNum <= 0) { return TSDB_CODE_SUCCESS; } @@ -50,6 +52,8 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { for (int32_t i = 0; i < usedbRsp->vgNum; ++i) { 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); if (0 != taosHashPut(pOut->dbVgroup->vgHash, &pVgInfo->vgId, sizeof(int32_t), pVgInfo, sizeof(SVgroupInfo))) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -199,6 +203,24 @@ 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)) { + if (NULL == msg || NULL == msgLen) { + return TSDB_CODE_TSC_INVALID_INPUT; + } + + STableIndexReq indexReq = {0}; + strcpy(indexReq.tbFName, input); + + int32_t bufLen = tSerializeSTableIndexReq(NULL, 0, &indexReq); + void *pBuf = (*mallcFp)(bufLen); + tSerializeSTableIndexReq(pBuf, bufLen, &indexReq); + + *msg = pBuf; + *msgLen = bufLen; + + return TSDB_CODE_SUCCESS; +} + int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) { SUseDbOutput *pOut = output; @@ -290,10 +312,6 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta * pTableMeta->sversion = msg->sversion; pTableMeta->tversion = msg->tversion; - if (isStb) { - qDebug("stable %s meta returned, suid:%" PRIx64, msg->stbName, pTableMeta->suid); - } - pTableMeta->tableInfo.numOfTags = msg->numOfTags; pTableMeta->tableInfo.precision = msg->precision; pTableMeta->tableInfo.numOfColumns = msg->numOfColumns; @@ -304,6 +322,12 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta * pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes; } + qDebug("table %s uid %" PRIx64 " meta returned, type %d vgId %d db %s stb %s suid %" PRIx64 " sver %d tver %d" PRIx64 + " tagNum %d colNum %d precision %d rowSize %d", + msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName, pTableMeta->suid, + pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags, pTableMeta->tableInfo.numOfColumns, + pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize); + *pMeta = pTableMeta; return TSDB_CODE_SUCCESS; } @@ -455,26 +479,43 @@ int32_t queryProcessGetUserAuthRsp(void *output, char *msg, int32_t msgSize) { return TSDB_CODE_SUCCESS; } +int32_t queryProcessGetTbIndexRsp(void *output, char *msg, int32_t msgSize) { + if (NULL == output || NULL == msg || msgSize <= 0) { + return TSDB_CODE_TSC_INVALID_INPUT; + } + + STableIndexRsp out = {0}; + if (tDeserializeSTableIndexRsp(msg, msgSize, &out) != 0) { + qError("tDeserializeSTableIndexRsp failed, msgSize:%d", msgSize); + return TSDB_CODE_INVALID_MSG; + } + + *(void **)output = out.pIndex; + + 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_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_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_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; - 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_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_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_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; } #pragma GCC diagnostic pop diff --git a/source/libs/qworker/inc/qwInt.h b/source/libs/qworker/inc/qwInt.h index 082db6428f..2368b13dd6 100644 --- a/source/libs/qworker/inc/qwInt.h +++ b/source/libs/qworker/inc/qwInt.h @@ -160,6 +160,7 @@ typedef struct SQWMsgStat { uint64_t cancelProcessed; uint64_t dropProcessed; uint64_t hbProcessed; + uint64_t deleteProcessed; } SQWMsgStat; typedef struct SQWRTStat { @@ -355,8 +356,9 @@ int32_t qwOpenRef(void); 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(SArray* pExpiredSch); +void qwClearExpiredSch(SQWorker *mgmt, SArray* pExpiredSch); int32_t qwAcquireScheduler(SQWorker *mgmt, uint64_t sId, int32_t rwType, SQWSchStatus **sch); +void qwFreeTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx *ctx); void qwDbgDumpMgmtInfo(SQWorker *mgmt); int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, bool *ignore); diff --git a/source/libs/qworker/inc/qwMsg.h b/source/libs/qworker/inc/qwMsg.h index 5a8a45cd51..29861d87ac 100644 --- a/source/libs/qworker/inc/qwMsg.h +++ b/source/libs/qworker/inc/qwMsg.h @@ -30,6 +30,7 @@ int32_t qwProcessReady(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessHb(SQWorker *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req); +int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SRpcMsg *pRsp, SDeleteRes *pRes); int32_t qwBuildAndSendDropRsp(SRpcHandleInfo *pConn, int32_t code); int32_t qwBuildAndSendCancelRsp(SRpcHandleInfo *pConn, int32_t code); diff --git a/source/libs/qworker/src/qwDbg.c b/source/libs/qworker/src/qwDbg.c index 3914541157..368c3bb517 100644 --- a/source/libs/qworker/src/qwDbg.c +++ b/source/libs/qworker/src/qwDbg.c @@ -9,7 +9,7 @@ #include "tmsg.h" #include "tname.h" -SQWDebug gQWDebug = {.statusEnable = true, .dumpEnable = true}; +SQWDebug gQWDebug = {.statusEnable = true, .dumpEnable = false}; int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, bool *ignore) { if (!gQWDebug.statusEnable) { @@ -97,7 +97,11 @@ _return: QW_RET(code); } -void qwDbgDumpSchInfo(SQWSchStatus *sch, int32_t i) {} +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_UNLOCK(QW_READ, &sch->tasksLock); +} void qwDbgDumpMgmtInfo(SQWorker *mgmt) { if (!gQWDebug.dumpEnable) { @@ -106,7 +110,7 @@ void qwDbgDumpMgmtInfo(SQWorker *mgmt) { QW_LOCK(QW_READ, &mgmt->schLock); - /*QW_DUMP("total remain schduler num:%d", taosHashGetSize(mgmt->schHash));*/ + QW_DUMP("total remain scheduler num %d", taosHashGetSize(mgmt->schHash)); void *key = NULL; size_t keyLen = 0; @@ -116,14 +120,14 @@ void qwDbgDumpMgmtInfo(SQWorker *mgmt) { void *pIter = taosHashIterate(mgmt->schHash, NULL); while (pIter) { sch = (SQWSchStatus *)pIter; - qwDbgDumpSchInfo(sch, i); + qwDbgDumpSchInfo(mgmt, sch, i); ++i; pIter = taosHashIterate(mgmt->schHash, pIter); } QW_UNLOCK(QW_READ, &mgmt->schLock); - /*QW_DUMP("total remain ctx num:%d", taosHashGetSize(mgmt->ctxHash));*/ + QW_DUMP("total remain ctx num %d", taosHashGetSize(mgmt->ctxHash)); } diff --git a/source/libs/qworker/src/qwMsg.c b/source/libs/qworker/src/qwMsg.c index 2f1ecc5172..848a0420ca 100644 --- a/source/libs/qworker/src/qwMsg.c +++ b/source/libs/qworker/src/qwMsg.c @@ -300,13 +300,6 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - msg->sId = msg->sId; - msg->queryId = msg->queryId; - msg->taskId = msg->taskId; - msg->refId = msg->refId; - msg->phyLen = msg->phyLen; - msg->sqlLen = msg->sqlLen; - uint64_t sId = msg->sId; uint64_t qId = msg->queryId; uint64_t tId = msg->taskId; @@ -523,3 +516,37 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_ return TSDB_CODE_SUCCESS; } + + +int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *pRsp, SDeleteRes *pRes) { + if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == pRsp) { + QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + int32_t code = 0; + SVDeleteReq req = {0}; + 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; + int64_t rId = 0; + + SQWMsg qwMsg = {.node = node, .msg = req.msg, .msgLen = req.phyLen, .connInfo = pMsg->info}; + QW_SCH_TASK_DLOG("processDelete start, node:%p, handle:%p, sql:%s", node, pMsg->info.handle, req.sql); + taosMemoryFreeClear(req.sql); + + QW_ERR_JRET(qwProcessDelete(QW_FPARAMS(), &qwMsg, pRsp, pRes)); + + QW_SCH_TASK_DLOG("processDelete end, node:%p", node); + +_return: + + QW_RET(code); +} + + diff --git a/source/libs/qworker/src/qwUtil.c b/source/libs/qworker/src/qwUtil.c index 8bfb80f061..e5dd9e71df 100644 --- a/source/libs/qworker/src/qwUtil.c +++ b/source/libs/qworker/src/qwUtil.c @@ -290,8 +290,11 @@ int32_t qwKillTaskHandle(QW_FPARAMS_DEF, SQWTaskCtx *ctx) { QW_RET(code); } -void qwFreeTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx) { - tmsgReleaseHandle(&ctx->ctrlConnInfo, TAOS_CONN_SERVER); +void qwFreeTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx *ctx) { + if (ctx->ctrlConnInfo.handle) { + tmsgReleaseHandle(&ctx->ctrlConnInfo, TAOS_CONN_SERVER); + } + ctx->ctrlConnInfo.handle = NULL; ctx->ctrlConnInfo.refId = -1; @@ -333,7 +336,7 @@ int32_t qwDropTaskCtx(QW_FPARAMS_DEF) { QW_ERR_RET(TSDB_CODE_QRY_TASK_CTX_NOT_EXIST); } - qwFreeTask(QW_FPARAMS(), &octx); + qwFreeTaskCtx(QW_FPARAMS(), &octx); QW_TASK_DLOG_E("task ctx dropped"); @@ -536,8 +539,23 @@ int64_t qwGetTimeInQueue(SQWorker *mgmt, EQueueType type) { } -void qwClearExpiredSch(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); + SQWSchStatus *pSch = NULL; + if (qwAcquireScheduler(mgmt, *sId, QW_WRITE, &pSch)) { + continue; + } + if (taosHashGetSize(pSch->tasksHash) <= 0) { + qwDestroySchStatus(pSch); + taosHashRemove(mgmt->schHash, sId, sizeof(*sId)); + qError("sch %" PRIx64 "destroyed", *sId); + } + + qwReleaseScheduler(QW_WRITE, mgmt); + } } diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 44a8fdf7f4..ae0eda5449 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -183,7 +183,7 @@ int32_t qwGenerateSchHbRsp(SQWorker *mgmt, SQWSchStatus *sch, SQWHbInfo *hbInfo) return TSDB_CODE_SUCCESS; } -int32_t qwGetResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void **rspMsg, SOutputData *pOutput) { +int32_t qwGetQueryResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void **rspMsg, SOutputData *pOutput) { int32_t len = 0; SRetrieveTableRsp *rsp = NULL; bool queryEnd = false; @@ -242,6 +242,53 @@ int32_t qwGetResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void return TSDB_CODE_SUCCESS; } +int32_t qwGetDeleteResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void **rspMsg, SDeleteRes *pRes) { + int32_t len = 0; + SVDeleteRsp rsp = {0}; + bool queryEnd = false; + int32_t code = 0; + SOutputData output = {0}; + + dsGetDataLength(ctx->sinkHandle, &len, &queryEnd); + + if (len <= 0 || len != sizeof(SDeleterRes)) { + QW_TASK_ELOG("invalid length from dsGetDataLength, length:%d", len); + QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + output.pData = taosMemoryCalloc(1, len); + if (NULL == output.pData) { + QW_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + + code = dsGetDataBlock(ctx->sinkHandle, &output); + if (code) { + QW_TASK_ELOG("dsGetDataBlock failed, code:%x - %s", code, tstrerror(code)); + taosMemoryFree(output.pData); + QW_ERR_RET(code); + } + + SDeleterRes* pDelRes = (SDeleterRes*)output.pData; + + rsp.affectedRows = pDelRes->affectedRows; + pRes->uid = pDelRes->uid; + pRes->uidList = pDelRes->uidList; + pRes->skey = pDelRes->skey; + pRes->ekey = pDelRes->ekey; + + SEncoder coder = {0}; + tEncodeSize(tEncodeSVDeleteRsp, &rsp, len, code); + void *msg = rpcMallocCont(len); + tEncoderInit(&coder, msg, len); + tEncodeSVDeleteRsp(&coder, &rsp); + tEncoderClear(&coder); + + *rspMsg = msg; + *dataLen = len; + + return TSDB_CODE_SUCCESS; +} + int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *input, SQWPhaseOutput *output) { int32_t code = 0; @@ -547,7 +594,7 @@ int32_t qwProcessCQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) { if (QW_IS_EVENT_RECEIVED(ctx, QW_EVENT_FETCH)) { SOutputData sOutput = {0}; - QW_ERR_JRET(qwGetResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput)); + QW_ERR_JRET(qwGetQueryResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput)); if ((!sOutput.queryEnd) && (DS_BUF_LOW == sOutput.bufStatus || DS_BUF_EMPTY == sOutput.bufStatus)) { QW_TASK_DLOG("task not end and buf is %s, need to continue query", qwBufStatusStr(sOutput.bufStatus)); @@ -620,7 +667,7 @@ int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg) { QW_ERR_JRET(qwGetTaskCtx(QW_FPARAMS(), &ctx)); SOutputData sOutput = {0}; - QW_ERR_JRET(qwGetResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput)); + QW_ERR_JRET(qwGetQueryResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput)); if (NULL == rsp) { ctx->dataConnInfo = qwMsg->connInfo; @@ -743,9 +790,10 @@ int32_t qwProcessHb(SQWorker *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req) { } QW_ERR_JRET(qwAcquireAddScheduler(mgmt, req->sId, QW_READ, &sch)); - QW_ERR_JRET(qwRegisterHbBrokenLinkArg(mgmt, req->sId, &qwMsg->connInfo)); + sch->hbBrokenTs = 0; + QW_LOCK(QW_WRITE, &sch->hbConnLock); if (sch->hbConnInfo.handle) { @@ -865,7 +913,7 @@ _return: } if (taosArrayGetSize(pExpiredSch) > 0) { - qwClearExpiredSch(pExpiredSch); + qwClearExpiredSch(mgmt, pExpiredSch); } taosMemoryFreeClear(rspList); @@ -875,6 +923,47 @@ _return: qwRelease(refId); } +int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SRpcMsg *pRsp, SDeleteRes *pRes) { + int32_t code = 0; + SSubplan *plan = NULL; + qTaskInfo_t pTaskInfo = NULL; + DataSinkHandle sinkHandle = NULL; + SQWTaskCtx ctx = {0}; + + code = qStringToSubplan(qwMsg->msg, &plan); + if (TSDB_CODE_SUCCESS != code) { + code = TSDB_CODE_INVALID_MSG; + QW_TASK_ELOG("task physical plan to subplan failed, code:%x - %s", code, tstrerror(code)); + QW_ERR_JRET(code); + } + + ctx.plan = plan; + + code = qCreateExecTask(qwMsg->node, mgmt->nodeId, tId, plan, &pTaskInfo, &sinkHandle, OPTR_EXEC_MODEL_BATCH); + if (code) { + QW_TASK_ELOG("qCreateExecTask failed, code:%x - %s", code, tstrerror(code)); + QW_ERR_JRET(code); + } + + if (NULL == sinkHandle || NULL == pTaskInfo) { + QW_TASK_ELOG("create task result error, taskHandle:%p, sinkHandle:%p", pTaskInfo, sinkHandle); + QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); + } + + ctx.taskHandle = pTaskInfo; + ctx.sinkHandle = sinkHandle; + + QW_ERR_JRET(qwExecTask(QW_FPARAMS(), &ctx, NULL)); + + QW_ERR_JRET(qwGetDeleteResFromSink(QW_FPARAMS(), &ctx, &pRsp->contLen, &pRsp->pCont, pRes)); + +_return: + + qwFreeTaskCtx(QW_FPARAMS(), &ctx); + + QW_RET(TSDB_CODE_SUCCESS); +} + int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, SQWorkerCfg *cfg, void **qWorkerMgmt, const SMsgCb *pMsgCb) { if (NULL == qWorkerMgmt || pMsgCb->mgmt == NULL) { @@ -1007,6 +1096,7 @@ int32_t qWorkerGetStat(SReadHandle *handle, void *qWorkerMgmt, SQWorkerStat *pSt pStat->fetchProcessed = QW_STAT_GET(mgmt->stat.msgStat.fetchProcessed); pStat->dropProcessed = QW_STAT_GET(mgmt->stat.msgStat.dropProcessed); pStat->hbProcessed = QW_STAT_GET(mgmt->stat.msgStat.hbProcessed); + pStat->deleteProcessed = QW_STAT_GET(mgmt->stat.msgStat.deleteProcessed); pStat->numOfQueryInQueue = handle->pMsgCb->qsizeFp(handle->pMsgCb->mgmt, mgmt->nodeId, QUERY_QUEUE); pStat->numOfFetchInQueue = handle->pMsgCb->qsizeFp(handle->pMsgCb->mgmt, mgmt->nodeId, FETCH_QUEUE); diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index 1c2e4a358a..4dd16098ff 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -22,11 +22,18 @@ extern "C" { #include "thash.h" #include "query.h" +typedef struct SOperatorValueType { + int32_t opResType; + int32_t selfType; + int32_t peerType; +} SOperatorValueType; + typedef struct SScalarCtx { int32_t code; 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; @@ -53,7 +60,7 @@ int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out); SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows); int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode); -#define GET_PARAM_TYPE(_c) ((_c)->columnData->info.type) +#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) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 5fdbbfe810..6704bfdde3 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -168,7 +168,7 @@ __compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val, setChkInBytes1, setChkInBytes2, setChkInBytes4, setChkInBytes8, compareStrRegexCompMatch, compareStrRegexCompNMatch, setChkNotInBytes1, setChkNotInBytes2, setChkNotInBytes4, setChkNotInBytes8, - compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch, compareJsonContainsKey + compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch }; int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { @@ -3669,6 +3669,14 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { stat->scalarMode = true; return DEAL_RES_CONTINUE; } + } else { + SColumnNode *refNode = (SColumnNode *)node->pLeft; + SNodeListNode *listNode = (SNodeListNode *)node->pRight; + 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; + } } } diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index d2436b9948..66e4af5ded 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -208,7 +208,13 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t SCL_RET(TSDB_CODE_QRY_INVALID_INPUT); } - SCL_ERR_RET(scalarGenerateSetFromList((void **)¶m->pHashFilter, node, nodeList->dataType.type)); + int32_t type = vectorGetConvertType(ctx->type.selfType, ctx->type.peerType); + if (type == 0) { + type = nodeList->dataType.type; + } + + SCL_ERR_RET(scalarGenerateSetFromList((void **)¶m->pHashFilter, node, type)); + param->hashValueType = type; if (taosHashPut(ctx->pRes, &node, POINTER_BYTES, param, sizeof(*param))) { taosHashCleanup(param->pHashFilter); sclError("taosHashPut nodeList failed, size:%d", (int32_t)sizeof(*param)); @@ -334,6 +340,46 @@ _return: SCL_RET(code); } +int32_t sclGetNodeType(SNode *pNode, SScalarCtx *ctx) { + if (NULL == pNode) { + return -1; + } + + switch (nodeType(pNode)) { + case QUERY_NODE_VALUE: { + SValueNode *valueNode = (SValueNode *)pNode; + return valueNode->node.resType.type; + } + case QUERY_NODE_NODE_LIST: { + SNodeListNode *nodeList = (SNodeListNode *)pNode; + return nodeList->dataType.type; + } + case QUERY_NODE_COLUMN: { + SColumnNode *colNode = (SColumnNode *)pNode; + return colNode->node.resType.type; + } + case QUERY_NODE_FUNCTION: + case QUERY_NODE_OPERATOR: + case QUERY_NODE_LOGIC_CONDITION: { + SScalarParam *res = (SScalarParam *)taosHashGet(ctx->pRes, &pNode, POINTER_BYTES); + if (NULL == res) { + sclError("no result for node, type:%d, node:%p", nodeType(pNode), pNode); + return -1; + } + return res->columnData->info.type; + } + } + + return -1; +} + + +void sclSetOperatorValueType(SOperatorNode *node, SScalarCtx *ctx) { + ctx->type.opResType = node->node.resType.type; + ctx->type.selfType = sclGetNodeType(node->pLeft, ctx); + ctx->type.peerType = sclGetNodeType(node->pRight, ctx); +} + int32_t sclInitOperatorParams(SScalarParam **pParams, SOperatorNode *node, SScalarCtx *ctx, int32_t *rowNum) { int32_t code = 0; int32_t paramNum = scalarGetOperatorParamNum(node->opType); @@ -348,8 +394,11 @@ int32_t sclInitOperatorParams(SScalarParam **pParams, SOperatorNode *node, SScal SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + sclSetOperatorValueType(node, ctx); + SCL_ERR_JRET(sclInitParam(node->pLeft, ¶mList[0], ctx, rowNum)); if (paramNum > 1) { + TSWAP(ctx->type.selfType, ctx->type.peerType); SCL_ERR_JRET(sclInitParam(node->pRight, ¶mList[1], ctx, rowNum)); } diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 2b15f5031e..2369779105 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -901,12 +901,22 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * if (hasFraction) { int32_t fracLen = (int32_t)strlen(fraction) + 1; - char *tzInfo = strchr(buf, '+'); - if (tzInfo) { + + char *tzInfo; + if (buf[len - 1] == 'z' || buf[len - 1] == 'Z') { + tzInfo = &buf[len - 1]; memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); } else { - tzInfo = strchr(buf, '-'); - memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); + tzInfo = strchr(buf, '+'); + if (tzInfo) { + memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); + } else { + //search '-' backwards + tzInfo = strrchr(buf, '-'); + if (tzInfo) { + memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); + } + } } char tmp[32] = {0}; diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index d9f582e669..7d96a89e85 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -88,7 +88,7 @@ void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int } } -void convertStringToDouble(const void *inData, void *outData, int8_t inType, int8_t outType){ +void convertNcharToDouble(const void *inData, void *outData){ char *tmp = taosMemoryMalloc(varDataTLen(inData)); int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(inData), varDataLen(inData), tmp); if (len < 0) { @@ -97,13 +97,24 @@ void convertStringToDouble(const void *inData, void *outData, int8_t inType, int tmp[len] = 0; - ASSERT(outType == TSDB_DATA_TYPE_DOUBLE); double value = taosStr2Double(tmp, NULL); *((double *)outData) = value; taosMemoryFreeClear(tmp); } +void convertBinaryToDouble(const void *inData, void *outData){ + char *tmp = taosMemoryCalloc(1, varDataTLen(inData)); + if(tmp == NULL){ + *((double *)outData) = 0.; + return; + } + memcpy(tmp, varDataVal(inData), varDataLen(inData)); + double ret = taosStr2Double(tmp, NULL); + taosMemoryFree(tmp); + *((double *)outData) = ret; +} + typedef int64_t (*_getBigintValue_fn_t)(void *src, int32_t index); int64_t getVectorBigintValue_TINYINT(void *src, int32_t index) { @@ -147,7 +158,7 @@ int64_t getVectorBigintValue_JSON(void *src, int32_t index){ if (*data == TSDB_DATA_TYPE_NULL){ return 0; } else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY - convertStringToDouble(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); + convertNcharToDouble(data+CHAR_BYTES, &out); } else { convertNumberToNumber(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); } @@ -362,9 +373,6 @@ static FORCE_INLINE void ncharToVar(char* buf, SScalarParam* pOut, int32_t rowIn //TODO opt performance, tmp is not needed. int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) { - int32_t bufSize = pIn->columnData->info.bytes; - char *tmp = taosMemoryMalloc(bufSize + VARSTR_HEADER_SIZE); - bool vton = false; _bufConverteFunc func = NULL; @@ -412,6 +420,12 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in continue; } } + int32_t bufSize = pIn->columnData->info.bytes; + char *tmp = taosMemoryMalloc(varDataTLen(data)); + if(!tmp){ + sclError("out of memory in vectorConvertFromVarData"); + return TSDB_CODE_OUT_OF_MEMORY; + } if (vton) { memcpy(tmp, data, varDataTLen(data)); } else { @@ -433,9 +447,9 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in } (*func)(tmp, pOut, i); + taosMemoryFreeClear(tmp); } - taosMemoryFreeClear(tmp); return TSDB_CODE_SUCCESS; } @@ -445,14 +459,30 @@ double getVectorDoubleValue_JSON(void *src, int32_t index){ if (*data == TSDB_DATA_TYPE_NULL){ return out; } else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY - convertStringToDouble(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); + convertNcharToDouble(data+CHAR_BYTES, &out); } else { convertNumberToNumber(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); } return out; } -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){ +void* ncharTobinary(void *buf){ // todo need to remove , if tobinary is nchar + int32_t inputLen = varDataLen(buf); + + 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)); + taosMemoryFree(t); + return NULL; + } + varDataSetLen(t, len); + 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){ if(optr == OP_TYPE_JSON_CONTAINS) { return true; } @@ -489,21 +519,41 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t *fp = filterGetCompFunc(type, optr); - if(typeLeft == TSDB_DATA_TYPE_NCHAR) { - convertStringToDouble(*pLeftData, pLeftOut, typeLeft, type); - *pLeftData = pLeftOut; - } else if(typeLeft != type) { - convertNumberToNumber(*pLeftData, pLeftOut, typeLeft, type); - *pLeftData = pLeftOut; + if(IS_NUMERIC_TYPE(type) || IS_FLOAT_TYPE(type)){ + if(typeLeft == TSDB_DATA_TYPE_NCHAR) { + convertNcharToDouble(*pLeftData, pLeftOut); + *pLeftData = pLeftOut; + } else if(typeLeft == TSDB_DATA_TYPE_BINARY) { + convertBinaryToDouble(*pLeftData, pLeftOut); + *pLeftData = pLeftOut; + } else if(typeLeft != type) { + convertNumberToNumber(*pLeftData, pLeftOut, typeLeft, type); + *pLeftData = pLeftOut; + } + + if(typeRight == TSDB_DATA_TYPE_NCHAR) { + convertNcharToDouble(*pRightData, pRightOut); + *pRightData = pRightOut; + } else if(typeRight == TSDB_DATA_TYPE_BINARY) { + convertBinaryToDouble(*pRightData, pRightOut); + *pRightData = pRightOut; + } else if(typeRight != type) { + convertNumberToNumber(*pRightData, pRightOut, typeRight, type); + *pRightData = pRightOut; + } + }else if(type == TSDB_DATA_TYPE_BINARY){ + if(typeLeft == TSDB_DATA_TYPE_NCHAR){ + *pLeftData = ncharTobinary(*pLeftData); + *freeLeft = true; + } + if(typeRight == TSDB_DATA_TYPE_NCHAR){ + *pRightData = ncharTobinary(*pRightData); + *freeRight = true; + } + }else{ + ASSERT(0); } - if(typeRight == TSDB_DATA_TYPE_NCHAR) { - convertStringToDouble(*pRightData, pRightOut, typeRight, type); - *pRightData = pRightOut; - } else if(typeRight != type) { - convertNumberToNumber(*pRightData, pRightOut, typeRight, type); - *pRightData = pRightOut; - } return true; } @@ -577,13 +627,19 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { SColumnInfoData* pInputCol = pIn->columnData; SColumnInfoData* pOutputCol = pOut->columnData; + if (NULL == pInputCol) { + sclError("input column is NULL, hashFilter %p", pIn->pHashFilter); + return TSDB_CODE_APP_ERROR; + } + int16_t inType = pInputCol->info.type; int16_t outType = pOutputCol->info.type; if (IS_VAR_DATA_TYPE(inType)) { return vectorConvertFromVarData(pIn, pOut, inType, outType); } - + + pOut->numOfRows = pIn->numOfRows; switch (outType) { case TSDB_DATA_TYPE_BOOL: { for (int32_t i = 0; i < pIn->numOfRows; ++i) { @@ -776,11 +832,26 @@ int32_t vectorGetConvertType(int32_t type1, int32_t type2) { return gConvertTypes[type2][type1]; } -int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* pLeftOut, SScalarParam* pRightOut) { - if (pLeft->pHashFilter != NULL || pRight->pHashFilter != NULL) { - return TSDB_CODE_SUCCESS; +int32_t vectorConvertScalarParam(SScalarParam *input, SScalarParam *output, int32_t type) { + int32_t code = 0; + SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; + output->numOfRows = input->numOfRows; + + output->columnData = createColumnInfoData(&t, input->numOfRows); + if (output->columnData == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; } + code = vectorConvertImpl(input, output); + if (code) { +// taosMemoryFreeClear(paramOut1->data); + return code; + } + + return TSDB_CODE_SUCCESS; +} + +int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* pLeftOut, SScalarParam* pRightOut) { int32_t leftType = GET_PARAM_TYPE(pLeft); int32_t rightType = GET_PARAM_TYPE(pRight); if (leftType == rightType) { @@ -809,31 +880,14 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p } if (type != GET_PARAM_TYPE(param1)) { - SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; - paramOut1->numOfRows = param1->numOfRows; - - paramOut1->columnData = createColumnInfoData(&t, param1->numOfRows); - if (paramOut1->columnData == NULL) { - return terrno; - } - - code = vectorConvertImpl(param1, paramOut1); + code = vectorConvertScalarParam(param1, paramOut1, type); if (code) { -// taosMemoryFreeClear(paramOut1->data); return code; } } if (type != GET_PARAM_TYPE(param2)) { - SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; - paramOut2->numOfRows = param2->numOfRows; - - paramOut2->columnData = createColumnInfoData(&t, param2->numOfRows); - if (paramOut2->columnData == NULL) { - return terrno; - } - - code = vectorConvertImpl(param2, paramOut2); + code = vectorConvertScalarParam(param2, paramOut2, type); if (code) { return code; } @@ -935,44 +989,6 @@ static void doReleaseVec(SColumnInfoData* pCol, int32_t type) { } } -STagVal getJsonValue(char *json, char *key, bool *isExist) { - STagVal val = {.pKey = key}; - bool find = tTagGet(((const STag *)json), &val); // json value is null and not exist is different - if(isExist){ - *isExist = find; - } - return val; -} - -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; - - pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); - - char *pRightData = colDataGetVarData(pRight->columnData, 0); - char *jsonKey = taosMemoryCalloc(1, varDataLen(pRightData) + 1); - memcpy(jsonKey, varDataVal(pRightData), varDataLen(pRightData)); - for (; i >= 0 && i < pLeft->numOfRows; i += step) { - if (colDataIsNull_var(pLeft->columnData, i)) { - colDataSetNull_var(pOutputCol, i); - pOutputCol->hasNull = true; - continue; - } - char *pLeftData = colDataGetVarData(pLeft->columnData, i); - bool isExist = false; - STagVal value = getJsonValue(pLeftData, jsonKey, &isExist); - char *data = isExist ? tTagValToData(&value, true) : NULL; - colDataAppend(pOutputCol, i, data, data == NULL); - if(isExist && IS_VAR_DATA_TYPE(value.type) && data){ - taosMemoryFree(data); - } - } - taosMemoryFree(jsonKey); -} - void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; @@ -1510,6 +1526,38 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, doReleaseVec(pRightCol, rightConvert); } +#define VEC_COM_INNER(pCol, index1, index2) \ + for (; i < pCol->numOfRows && i >= 0; i += step) {\ + if (IS_HELPER_NULL(pLeft->columnData, index1) || IS_HELPER_NULL(pRight->columnData, index2)) {\ + bool res = false;\ + colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);\ + continue;\ + }\ + char *pLeftData = colDataGetData(pLeft->columnData, index1);\ + char *pRightData = colDataGetData(pRight->columnData, index2);\ + 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, &leftOut, &rightOut, &isJsonnull, &freeLeft, &freeRight);\ + if(isJsonnull){\ + ASSERT(0);\ + }\ + if(!pLeftData || !pRightData){\ + result = false;\ + }\ + if(!result){\ + colDataAppendInt8(pOut->columnData, i, (int8_t*)&result);\ + }else{\ + bool res = filterDoCompare(fp, optr, pLeftData, pRightData);\ + colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);\ + }\ + if(freeLeft) taosMemoryFreeClear(pLeftData);\ + if(freeRight) taosMemoryFreeClear(pRightData);\ + } + 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; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; @@ -1533,79 +1581,11 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam * } if (pLeft->numOfRows == pRight->numOfRows) { - for (; i < pRight->numOfRows && i >= 0; i += step) { - if (IS_HELPER_NULL(pLeft->columnData, i) || IS_HELPER_NULL(pRight->columnData, i)) { - bool res = false; - colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); - continue; // TODO set null or ignore - } - - char *pLeftData = colDataGetData(pLeft->columnData, i); - char *pRightData = colDataGetData(pRight->columnData, i); - - int64_t leftOut = 0; - int64_t rightOut = 0; - bool isJsonnull = false; - bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull); - if(isJsonnull){ - ASSERT(0); - } - if(!result){ - colDataAppendInt8(pOut->columnData, i, (int8_t*)&result); - }else{ - bool res = filterDoCompare(fp, optr, pLeftData, pRightData); - colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); - } - } + VEC_COM_INNER(pLeft, i, i) } else if (pRight->numOfRows == 1) { - ASSERT(pLeft->pHashFilter == NULL); - for (; i >= 0 && i < pLeft->numOfRows; i += step) { - if (IS_HELPER_NULL(pLeft->columnData, i) || IS_HELPER_NULL(pRight->columnData, 0)) { - bool res = false; - colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); - continue; - } - - char *pLeftData = colDataGetData(pLeft->columnData, i); - char *pRightData = colDataGetData(pRight->columnData, 0); - int64_t leftOut = 0; - int64_t rightOut = 0; - bool isJsonnull = false; - bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull); - if(isJsonnull){ - ASSERT(0); - } - if(!result){ - colDataAppendInt8(pOut->columnData, i, (int8_t*)&result); - }else{ - bool res = filterDoCompare(fp, optr, pLeftData, pRightData); - colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); - } - } + VEC_COM_INNER(pLeft, i, 0) } else if (pLeft->numOfRows == 1) { - for (; i >= 0 && i < pRight->numOfRows; i += step) { - if (IS_HELPER_NULL(pRight->columnData, i) || IS_HELPER_NULL(pLeft->columnData, 0)) { - bool res = false; - colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); - continue; - } - - char *pLeftData = colDataGetData(pLeft->columnData, 0); - char *pRightData = colDataGetData(pLeft->columnData, i); - int64_t leftOut = 0; - int64_t rightOut = 0; - bool isJsonnull = false; - bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull); - if(isJsonnull){ - ASSERT(0); - } - if(!result){ - colDataAppendInt8(pOut->columnData, i, (int8_t*)&result); - }else{ - bool res = filterDoCompare(fp, optr, pLeftData, pRightData); - colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); - } - } + VEC_COM_INNER(pRight, 0, i) } } @@ -1683,10 +1663,6 @@ void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NMATCH); } -void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { - vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_JSON_CONTAINS); -} - 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; @@ -1705,6 +1681,77 @@ void vectorNotNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { vectorConvertImpl(pLeft, pOut); + for(int32_t i = 0; i < pOut->numOfRows; ++i) { + if(colDataIsNull_s(pOut->columnData, i)) { + int8_t v = 0; + colDataAppendInt8(pOut->columnData, i, &v); + colDataSetNotNull_f(pOut->columnData->nullbitmap, i); + } + } + pOut->columnData->hasNull = false; +} + +STagVal getJsonValue(char *json, char *key, bool *isExist) { + STagVal val = {.pKey = key}; + bool find = tTagGet(((const STag *)json), &val); // json value is null and not exist is different + if(isExist){ + *isExist = find; + } + return val; +} + +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; + + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + + char *pRightData = colDataGetVarData(pRight->columnData, 0); + char *jsonKey = taosMemoryCalloc(1, varDataLen(pRightData) + 1); + memcpy(jsonKey, varDataVal(pRightData), varDataLen(pRightData)); + for (; i >= 0 && i < pLeft->numOfRows; i += step) { + bool isExist = false; + + if (!colDataIsNull_var(pLeft->columnData, i)) { + char *pLeftData = colDataGetVarData(pLeft->columnData, i); + getJsonValue(pLeftData, jsonKey, &isExist); + } + + colDataAppend(pOutputCol, i, (const char*)(&isExist), false); + + } + taosMemoryFree(jsonKey); +} + +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; + + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + + char *pRightData = colDataGetVarData(pRight->columnData, 0); + char *jsonKey = taosMemoryCalloc(1, varDataLen(pRightData) + 1); + memcpy(jsonKey, varDataVal(pRightData), varDataLen(pRightData)); + for (; i >= 0 && i < pLeft->numOfRows; i += step) { + if (colDataIsNull_var(pLeft->columnData, i)) { + colDataSetNull_var(pOutputCol, i); + pOutputCol->hasNull = true; + continue; + } + char *pLeftData = colDataGetVarData(pLeft->columnData, i); + bool isExist = false; + STagVal value = getJsonValue(pLeftData, jsonKey, &isExist); + char *data = isExist ? tTagValToData(&value, true) : NULL; + colDataAppend(pOutputCol, i, data, data == NULL); + if(isExist && IS_VAR_DATA_TYPE(value.type) && data){ + taosMemoryFree(data); + } + } + taosMemoryFree(jsonKey); } _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) { diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index 284ce4b95c..d879150200 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 @@ -55,229 +55,229 @@ 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; void scltFreeDataBlock(void *block) { - blockDataDestroy(*(SSDataBlock **)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 = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); - res->info.numOfCols = 1; - res->info.rows = rows; - res->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); - SColumnInfoData idata = {0}; - idata.info = *colInfo; + if (newBlock) { + SSDataBlock *res = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); + res->info.numOfCols = 1; + res->info.rows = rows; + res->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); + SColumnInfoData idata = {0}; + idata.info = *colInfo; - taosArrayPush(res->pDataBlock, &idata); - taosArrayPush(pBlockList, &res); - - blockDataEnsureCapacity(res, rows); + taosArrayPush(res->pDataBlock, &idata); + taosArrayPush(pBlockList, &res); - *dataBlockId = taosArrayGetSize(pBlockList) - 1; - res->info.blockId = *dataBlockId; - *slotId = 0; - } else { - SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(pBlockList); - res->info.numOfCols++; - SColumnInfoData idata = {0}; - idata.info = *colInfo; + blockDataEnsureCapacity(res, rows); - colInfoDataEnsureCapacity(&idata, 0, rows); + *dataBlockId = taosArrayGetSize(pBlockList) - 1; + res->info.blockId = *dataBlockId; + *slotId = 0; + } else { + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(pBlockList); + res->info.numOfCols++; + SColumnInfoData idata = {0}; + idata.info = *colInfo; - taosArrayPush(res->pDataBlock, &idata); - - *dataBlockId = taosArrayGetSize(pBlockList) - 1; - *slotId = taosArrayGetSize(res->pDataBlock) - 1; - } + colInfoDataEnsureCapacity(&idata, 0, rows); + + taosArrayPush(res->pDataBlock, &idata); + + *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; + 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; + 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; + 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) { + *pNode = (SNode *)rnode; + return; + } - if (NULL == *block) { - SSDataBlock *res = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); - res->info.numOfCols = 3; - res->info.rows = rowNum; - res->pDataBlock = taosArrayInit(3, sizeof(SColumnInfoData)); - for (int32_t i = 0; i < 2; ++i) { - SColumnInfoData idata = {{0}}; - idata.info.type = TSDB_DATA_TYPE_NULL; - idata.info.bytes = 10; - idata.info.colId = i + 1; + if (NULL == *block) { + SSDataBlock *res = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); + res->info.numOfCols = 3; + res->info.rows = rowNum; + res->pDataBlock = taosArrayInit(3, sizeof(SColumnInfoData)); + for (int32_t i = 0; i < 2; ++i) { + SColumnInfoData idata = {{0}}; + idata.info.type = TSDB_DATA_TYPE_NULL; + idata.info.bytes = 10; + idata.info.colId = i + 1; - int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)taosMemoryCalloc(1, size); - taosArrayPush(res->pDataBlock, &idata); - } + int32_t size = idata.info.bytes * rowNum; + idata.pData = (char *)taosMemoryCalloc(1, size); + taosArrayPush(res->pDataBlock, &idata); + } - SColumnInfoData idata = {{0}}; - idata.info.type = dataType; - idata.info.bytes = dataBytes; - idata.info.colId = 3; - int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)taosMemoryCalloc(1, size); - colInfoDataEnsureCapacity(&idata, 0, rowNum); - taosArrayPush(res->pDataBlock, &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; - } - } + SColumnInfoData idata = {{0}}; + idata.info.type = dataType; + idata.info.bytes = dataBytes; + idata.info.colId = 3; + int32_t size = idata.info.bytes * rowNum; + idata.pData = (char *)taosMemoryCalloc(1, size); + colInfoDataEnsureCapacity(&idata, 0, rowNum); + taosArrayPush(res->pDataBlock, &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 = 2; - rnode->colId = 3; + rnode->slotId = 2; + rnode->colId = 3; - *block = res; - } else { - SSDataBlock *res = *block; - - int32_t idx = taosArrayGetSize(res->pDataBlock); - SColumnInfoData idata = {{0}}; - idata.info.type = dataType; - idata.info.bytes = dataBytes; - idata.info.colId = 1 + idx; - int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)taosMemoryCalloc(1, size); - taosArrayPush(res->pDataBlock, &idata); - res->info.numOfCols++; - SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - - colInfoDataEnsureCapacity(pColumn, 0, rowNum); + *block = res; + } else { + SSDataBlock *res = *block; - 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; - } + int32_t idx = taosArrayGetSize(res->pDataBlock); + SColumnInfoData idata = {{0}}; + idata.info.type = dataType; + idata.info.bytes = dataBytes; + idata.info.colId = 1 + idx; + int32_t size = idata.info.bytes * rowNum; + idata.pData = (char *)taosMemoryCalloc(1, size); + taosArrayPush(res->pDataBlock, &idata); + res->info.numOfCols++; + SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - *pNode = (SNode *)rnode; + colInfoDataEnsureCapacity(pColumn, 0, rowNum); + + 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; + 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; - } + onode->opType = opType; + if(isReverse){ + onode->pLeft = pRight; + onode->pRight = pLeft; + }else{ + onode->pLeft = pLeft; + onode->pRight = pRight; + } - *pNode = (SNode *)onode; + *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]); - } - - *pNode = (SNode *)onode; + onode->pParameterList = nodesMakeList(); + for (int32_t i = 0; i < nodeNum; ++i) { + nodesListAppend(onode->pParameterList, nodeList[i]); + } + + *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; - - *pNode = (SNode *)onode; + SNode *node = (SNode*)nodesMakeNode(QUERY_NODE_TARGET); + STargetNode *onode = (STargetNode *)node; + onode->pExpr = snode; + onode->dataBlockId = dataBlockId; + onode->slotId = slotId; + + *pNode = (SNode *)onode; } @@ -285,3381 +285,3381 @@ void scltMakeTargetNode(SNode **pNode, int16_t dataBlockId, int16_t slotId, SNod } 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); - - 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); + 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); } 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); - - 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); + 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); } 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); - - 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); + 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); } 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); - - 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); + 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); } 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); - - 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; + 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); } 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); - - 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); + 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); } 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); - - 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); + 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); } 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); - - 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 = 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); } 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); - - 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); + 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); } 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); - - 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_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); } 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(); + 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); + 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(); + 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); + 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(); + 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); + 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(); + 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); + 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(); + 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); + 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); + 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); + 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; - } + 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); + 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); + 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; + SArray *blockList = taosArrayInit(2, POINTER_BYTES); + SSDataBlock *src = NULL; + SNode *opNode = NULL; - makeJsonArrow(&src, &opNode, json, (char*)key); - taosArrayPush(blockList, &src); + makeJsonArrow(&src, &opNode, json, (char*)key); + taosArrayPush(blockList, &src); - makeOperator(&opNode, blockList, opType, rightType, rightData, isReverse); + makeOperator(&opNode, blockList, opType, rightType, rightData, isReverse); - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); + 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); + 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"); + 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", gOptrStr[opType].str, *((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:%ld,except:%f\n", gOptrStr[opType].str, *((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", gOptrStr[opType].str, *((bool *)colDataGetData(column, 0)), exceptValue); - ASSERT_EQ(*((bool *)colDataGetData(column, 0)), exceptValue); - } + }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", gOptrStr[opType].str, *((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:%ld,except:%f\n", gOptrStr[opType].str, *((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", gOptrStr[opType].str, *((bool *)colDataGetData(column, 0)), exceptValue); + ASSERT_EQ(*((bool *)colDataGetData(column, 0)), exceptValue); + } - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + 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\"}"; + 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); + 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}; + 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 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"); + 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); - } + 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"); + 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); - } + 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"); + 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); - } + 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"); + 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); - } + 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"); + 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); - } + 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"); + 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); - } + 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"); + 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); - } + 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"); + 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); - } + 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"); + 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); - } + 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); + taosArrayDestroy(tags); + taosMemoryFree(row); } void *prepareNchar(char* rightData){ - int32_t len = 0; - int32_t inputLen = strlen(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; + 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\"}"; + 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); + 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}; + 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"}; + 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 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"); + printf("--------------------json string--0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); - key = "k2"; - bool eRes1[len+len1] = {false, false, true, true, 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] = {true, true, 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); - } + key = "k2"; + bool eRes1[len+len1] = {false, false, true, true, 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] = {true, true, 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); - } + 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"); + 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 - double eRes2[len+len1] = {false, false, false, false, false, false, true, false, DBL_MAX, 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); - } + 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); - } + 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"); + printf("--------------------json bool--1 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); - key = "k4"; - bool eRes3[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], eRes3[i], op[i], false); - } - bool eRes_3[len0] = {false, true, false, false, false, true}; - for(int i = 0; i < len0; i++){ - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_3[i], op[i], true); - } + key = "k4"; + bool eRes3[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], eRes3[i], op[i], false); + } + bool eRes_3[len0] = {false, true, false, false, false, true}; + 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); - } + 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"); + 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); - } + 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); - } + 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"); + 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); - } + 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); - } + 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"); + 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); - } + 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); - } + 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"); + printf("--------------------json bool-- 0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); - key = "k8"; - bool eRes7[len+len1] = {false, false, true, true, 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] = {true, true, 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); - } + key = "k8"; + bool eRes7[len+len1] = {false, false, true, true, 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] = {true, true, 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); - } + 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"); + printf("--------------------json string-- 6.6hello {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); - key = "k9"; - bool eRes8[len+len1] = {true, false, false, false, false, true, 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, true, true, true, false, true}; - for(int i = 0; i < len0; i++) { - makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_8[i], op[i], true); - } + key = "k9"; + bool eRes8[len+len1] = {true, false, false, false, false, true, 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, true, true, true, false, true}; + 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); - } + 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"); + 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 - double eRes9[len+len1] = {false, false, false, false, false, false, true, false, DBL_MAX, 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); - } + 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); - } + 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); + 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); + scltInitLogFile(); - 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); + 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); - int32_t code = scalarCalculate(opNode, blockList, NULL); - ASSERT_EQ(code, 0); + 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); - 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]); - } + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + 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); + 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); + 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); - 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); + 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); + 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); - 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); + 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); + 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); - 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); + 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); + 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); - 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); + 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); + 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); - 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); + 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); + 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); + 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); - 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); + 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); + 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); + } - 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); + 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); + 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}; - 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); + 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); + } - 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]); - } + int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); - taosArrayDestroyEx(blockList, scltFreeDataBlock); - nodesDestroyNode(opNode); + 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); + SNode *pLeft = NULL, *opNode = NULL; + char leftv[5][5]= {0}; + SSDataBlock *src = NULL; + bool eRes[5] = {false, true, false, true, false}; - 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); + 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); + } - 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); + 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); + SNode *pLeft = NULL, *opNode = NULL; + char leftv[5][5]= {0}; + SSDataBlock *src = NULL; + bool eRes[5] = {false, false, true, false, true}; - SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); - colDataAppend(pcolumn, 2, NULL, true); - colDataAppend(pcolumn, 4, NULL, 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); + } - 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); + int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); + scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); - 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); + 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); + SNode *pLeft = NULL, *opNode = NULL; + char leftv[5][5]= {0}; + SSDataBlock *src = NULL; + bool eRes[5] = {true, true, true, true, false}; - 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); + 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); + } - 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); + 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); + 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); - 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); + 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; - } - } + 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 = (SColumnInfoData*) taosMemoryCalloc(1, sizeof(SColumnInfoData)); + input->numOfRows = num; - input->columnData->info = createColumnInfo(0, type, bytes); - colInfoDataEnsureCapacity(input->columnData, 0, num); + input->columnData->info = createColumnInfo(0, type, bytes); + colInfoDataEnsureCapacity(input->columnData, 0, 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); - } + 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; + *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; + 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); + //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); + 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); + 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); + 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); + //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); + 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); + 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); + 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); + //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); + 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); + 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); + 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); + //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); + 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); + 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); + 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); + //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); + 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); + 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); + 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); + //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); + 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); + 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); + 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; + 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); - } + //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); + 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); - } + 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); + 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); - } + //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); + 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); - } + 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); + 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); - } + //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); + 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); - } + 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); + 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); - } + //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); + 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); - } + 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); + 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); - } + //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); + 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); - } + 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))); - } + 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); + 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; + 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)); + //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); + 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)); + //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))); - } + 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); + 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}; + 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)); - } + //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); + 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))); - } + //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))); - } + 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); + 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; + 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)); + //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); + 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)); + //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))); - } + 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); + 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}; + 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)); - } + //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); + 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)); - } + //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))); - } + 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); + 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; + 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)); + //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); + 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)); + //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))); - } + 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); + 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}; + 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))); - } + //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); + 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))); - } + //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))); - } + 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); + 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; + 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)); + //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); + 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)); + //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))); - } + 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); + 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}; + 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))); - } + //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); + 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))); - } + //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))); - } + 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); + 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; + 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)); + //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); + 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)); + //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))); - } + 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); + 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}; + 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))); - } + //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); + 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))); - } + //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))); - } + 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); + 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; + 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)); + //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); + 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)); + //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))); - } + 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); + 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}; + 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))); - } + //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); + 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))); - } + //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))); - } + 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); + 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; + 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)); + //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); + 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)); + //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))); - } + 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); + 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}; + 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))); - } + //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); + 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))); - } + //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))); - } + 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); + 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; + 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)); + //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); + 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)); + //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))); - } + 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); + 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}; + 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))); - } + //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); + 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))); - } + //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))); - } + 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); + 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; + 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)); + //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); + 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)); + //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))); - } + 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); + 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}; + 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))); - } + //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); + 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))); - } + //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))); - } + 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); + 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; + 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)); + //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); + 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)); + //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))); - } + 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); + 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}; + 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))); - } + //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); + 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))); - } + //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))); - } + 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); + 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)); + 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)); + //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); + 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)); + //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); + 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); + //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)); + 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))); - } + 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); + 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)); + 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); + //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); + } + 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); + 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); + //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); + 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); + //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); + } + 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); + } + 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))); - } + 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); + 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)); + 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)); + //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); + 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)); + //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); + 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); + //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)); + 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))); - } + 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); + 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)); + 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); + //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); + } + 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))); - } + 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); + 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); + //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); + 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); + //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); + } + 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))); - } + 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); + 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(); + taosSeedRand(taosGetTimestampSec()); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } #pragma GCC diagnostic pop diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schedulerInt.h index d961780ae5..9e302e569a 100644 --- a/source/libs/scheduler/inc/schedulerInt.h +++ b/source/libs/scheduler/inc/schedulerInt.h @@ -207,6 +207,7 @@ typedef struct SSchJob { SArray *dataSrcTasks; // SArray int32_t levelIdx; SEpSet dataSrcEps; + SHashObj *taskList; SHashObj *execTasks; // executing tasks, key:taskid, value:SQueryTask* SHashObj *succTasks; // succeed tasks, key:taskid, value:SQueryTask* SHashObj *failTasks; // failed tasks, key:taskid, value:SQueryTask* diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index ca90d2fe34..0128b9292c 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -63,6 +63,13 @@ int32_t schInitJob(SSchJob **pSchJob, SQueryPlan *pDag, void *pTrans, SArray *pN if (pNodeList != NULL) { pJob->nodeList = taosArrayDup(pNodeList); } + + pJob->taskList = + taosHashInit(pDag->numOfSubplans, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK); + if (NULL == pJob->taskList) { + SCH_JOB_ELOG("taosHashInit %d taskList failed", pDag->numOfSubplans); + SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } SCH_ERR_JRET(schValidateAndBuildJob(pDag, pJob)); @@ -108,7 +115,7 @@ int32_t schInitJob(SSchJob **pSchJob, SQueryPlan *pDag, void *pTrans, SArray *pN pJob->refId = refId; - SCH_JOB_DLOG("job refId:%" PRIx64, pJob->refId); + SCH_JOB_DLOG("job refId:0x%" PRIx64" created", pJob->refId); pJob->status = JOB_TASK_STATUS_NOT_START; @@ -486,23 +493,26 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { SCH_SET_JOB_TYPE(pJob, plan->subplanType); SSchTask task = {0}; - SSchTask *pTask = &task; - SCH_ERR_JRET(schInitTask(pJob, &task, plan, pLevel)); - void *p = taosArrayPush(pLevel->subTasks, &task); - if (NULL == p) { + SSchTask *pTask = taosArrayPush(pLevel->subTasks, &task); + if (NULL == pTask) { SCH_TASK_ELOG("taosArrayPush task to level failed, level:%d, taskIdx:%d", pLevel->level, n); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SCH_ERR_JRET(schRecordQueryDataSrc(pJob, p)); + SCH_ERR_JRET(schRecordQueryDataSrc(pJob, pTask)); - if (0 != taosHashPut(planToTask, &plan, POINTER_BYTES, &p, POINTER_BYTES)) { + if (0 != taosHashPut(planToTask, &plan, POINTER_BYTES, &pTask, POINTER_BYTES)) { SCH_TASK_ELOG("taosHashPut to planToTaks failed, taskIdx:%d", n); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + if (0 != taosHashPut(pJob->taskList, &pTask->taskId, sizeof(pTask->taskId), &pTask, POINTER_BYTES)) { + SCH_TASK_ELOG("taosHashPut to taskList failed, taskIdx:%d", n); + SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + ++pJob->taskNum; } @@ -535,7 +545,7 @@ int32_t schSetAddrsFromNodeList(SSchJob *pJob, SSchTask *pTask) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SCH_TASK_DLOG("set %dth condidate addr, id %d, fqdn:%s, port:%d", i, naddr->nodeId, SCH_GET_CUR_EP(naddr)->fqdn, SCH_GET_CUR_EP(naddr)->port); + SCH_TASK_DLOG("set %dth candidate addr, id %d, fqdn:%s, port:%d", i, naddr->nodeId, SCH_GET_CUR_EP(naddr)->fqdn, SCH_GET_CUR_EP(naddr)->port); ++addNum; } @@ -887,6 +897,7 @@ int32_t schProcessOnJobFailureImpl(SSchJob *pJob, int32_t status, int32_t errCod if (SCH_EXEC_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_EXEC_CB, 0)) { schNotifyUserQueryRes(pJob); } else if (SCH_FETCH_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_FETCH_CB, 0)) { + atomic_val_compare_exchange_8(&pJob->userFetch, 1, 0); schNotifyUserFetchRes(pJob); } } @@ -915,6 +926,7 @@ int32_t schProcessOnJobPartialSuccess(SSchJob *pJob) { } else if (SCH_EXEC_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_EXEC_CB, 0)) { schNotifyUserQueryRes(pJob); } else if (SCH_FETCH_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_FETCH_CB, 0)) { + atomic_val_compare_exchange_8(&pJob->userFetch, 1, 0); schNotifyUserFetchRes(pJob); } @@ -935,6 +947,8 @@ void schProcessOnDataFetched(SSchJob *job) { if (job->attr.syncSchedule) { tsem_post(&job->rspSem); } else if (SCH_FETCH_CB == atomic_val_compare_exchange_32(&job->userCb, SCH_FETCH_CB, 0)) { + atomic_val_compare_exchange_8(&job->userFetch, 1, 0); + schNotifyUserFetchRes(job); } } @@ -1276,14 +1290,10 @@ int32_t schGetTaskFromList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTas } int32_t schGetTaskInJob(SSchJob *pJob, uint64_t taskId, SSchTask **pTask) { - schGetTaskFromList(pJob->execTasks, taskId, pTask); + schGetTaskFromList(pJob->taskList, taskId, pTask); if (NULL == *pTask) { - schGetTaskFromList(pJob->succTasks, taskId, pTask); - - if (NULL == *pTask) { - SCH_JOB_ELOG("task not found in execList & succList, taskId:%" PRIx64, taskId); - SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); - } + SCH_JOB_ELOG("task not found in job task list, taskId:%" PRIx64, taskId); + SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } return TSDB_CODE_SUCCESS; @@ -1445,7 +1455,8 @@ void schFreeJobImpl(void *job) { taosHashCleanup(pJob->execTasks); taosHashCleanup(pJob->failTasks); taosHashCleanup(pJob->succTasks); - + taosHashCleanup(pJob->taskList); + taosArrayDestroy(pJob->levels); taosArrayDestroy(pJob->nodeList); taosArrayDestroy(pJob->dataSrcTasks); @@ -1476,7 +1487,7 @@ int32_t schExecJobImpl(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_ SSchJob *pJob = NULL; SCH_ERR_RET(schInitJob(&pJob, pDag, pTrans, pNodeList, sql, pRes, startTs, sync)); - qDebug("QID:0x%" PRIx64 " jobId:0x%"PRIx64 " started", pDag->queryId, pJob->refId); + qDebug("QID:0x%" PRIx64 " job refId 0x%"PRIx64 " started", pDag->queryId, pJob->refId); *job = pJob->refId; SCH_ERR_JRET(schLaunchJob(pJob)); @@ -1673,9 +1684,9 @@ int32_t schAsyncFetchRows(SSchJob *pJob) { } if (pJob->attr.explainMode == EXPLAIN_MODE_STATIC) { - SCH_ERR_JRET(schNotifyUserFetchRes(pJob)); - atomic_val_compare_exchange_8(&pJob->userFetch, 1, 0); + + SCH_ERR_JRET(schNotifyUserFetchRes(pJob)); } else { pJob->userCb = SCH_FETCH_CB; diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index bf51d8d631..e40db48401 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -62,10 +62,11 @@ int32_t schValidateReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgTy case TDMT_VND_DROP_TABLE_RSP: case TDMT_VND_ALTER_TABLE_RSP: case TDMT_VND_SUBMIT_RSP: + case TDMT_VND_DELETE_RSP: break; default: SCH_TASK_ELOG("unknown rsp msg, type:%s, status:%s", TMSG_INFO(msgType), jobTaskStatusStr(taskStatus)); - SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + SCH_ERR_RET(TSDB_CODE_INVALID_MSG); } if (lastMsgType != reqMsgType) { @@ -227,6 +228,25 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch break; } + case TDMT_VND_DELETE_RSP: { + SCH_ERR_JRET(rspCode); + + if (msg) { + SDecoder coder = {0}; + SVDeleteRsp rsp = {0}; + tDecoderInit(&coder, msg, msgSize); + tDecodeSVDeleteRsp(&coder, &rsp); + + atomic_add_fetch_32(&pJob->resNumOfRows, rsp.affectedRows); + SCH_TASK_DLOG("delete succeed, affectedRows:%" PRId64, rsp.affectedRows); + } + + taosMemoryFreeClear(msg); + + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); + + break; + } case TDMT_VND_QUERY_RSP: { SQueryTableRsp *rsp = (SQueryTableRsp *)msg; @@ -411,6 +431,10 @@ int32_t schHandleQueryCallback(void *param, const SDataBuf *pMsg, int32_t code) return schHandleCallback(param, pMsg, TDMT_VND_QUERY_RSP, code); } +int32_t schHandleDeleteCallback(void *param, const SDataBuf *pMsg, int32_t code) { + return schHandleCallback(param, pMsg, TDMT_VND_DELETE_RSP, code); +} + int32_t schHandleFetchCallback(void *param, const SDataBuf *pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_FETCH_RSP, code); } @@ -501,6 +525,9 @@ int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) { case TDMT_VND_QUERY: *fp = schHandleQueryCallback; break; + case TDMT_VND_DELETE: + *fp = schHandleDeleteCallback; + break; case TDMT_VND_EXPLAIN: *fp = schHandleExplainCallback; break; @@ -982,6 +1009,26 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, break; } + case TDMT_VND_DELETE: { + SVDeleteReq req = {0}; + req.header.vgId = addr->nodeId; + req.sId = schMgmt.sId; + req.queryId = pJob->queryId; + req.taskId = pTask->taskId; + req.phyLen = pTask->msgLen; + req.sqlLen = strlen(pJob->sql); + req.sql = (char*)pJob->sql; + req.msg = pTask->msg; + msgSize = tSerializeSVDeleteReq(NULL, 0, &req); + msg = taosMemoryCalloc(1, msgSize); + if (NULL == msg) { + SCH_TASK_ELOG("calloc %d failed", msgSize); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + tSerializeSVDeleteReq(msg, msgSize, &req); + break; + } case TDMT_VND_QUERY: { SCH_ERR_RET(schMakeQueryRpcCtx(pJob, pTask, &rpcCtx)); diff --git a/source/libs/scheduler/src/schUtil.c b/source/libs/scheduler/src/schUtil.c index 18398802db..38c03c74d9 100644 --- a/source/libs/scheduler/src/schUtil.c +++ b/source/libs/scheduler/src/schUtil.c @@ -257,6 +257,8 @@ void schFreeRpcCtx(SRpcCtx *pCtx) { taosHashCleanup(pCtx->args); - (*pCtx->freeFunc)(pCtx->brokenVal.val); + if (pCtx->freeFunc) { + (*pCtx->freeFunc)(pCtx->brokenVal.val); + } } diff --git a/source/libs/stream/inc/streamInc.h b/source/libs/stream/inc/streamInc.h new file mode 100644 index 0000000000..27746fff78 --- /dev/null +++ b/source/libs/stream/inc/streamInc.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _STREAM_INC_H_ +#define _STREAM_INC_H_ + +#include "executor.h" +#include "tstream.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb); +int32_t streamDispatch(SStreamTask* pTask, SMsgCb* pMsgCb); +int32_t streamDispatchReqToData(const SStreamDispatchReq* pReq, SStreamDataBlock* pData); +int32_t streamBuildDispatchMsg(SStreamTask* pTask, SStreamDataBlock* data, SRpcMsg* pMsg, SEpSet** ppEpSet); + +#ifdef __cplusplus +} +#endif + +#endif /* ifndef _STREAM_INC_H_ */ diff --git a/source/libs/stream/src/stream.c b/source/libs/stream/src/stream.c new file mode 100644 index 0000000000..069595390d --- /dev/null +++ b/source/libs/stream/src/stream.c @@ -0,0 +1,135 @@ +/* + * 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 "streamInc.h" + +int32_t streamTriggerByWrite(SStreamTask* pTask, int32_t vgId, SMsgCb* pMsgCb) { + int8_t execStatus = atomic_load_8(&pTask->status); + if (execStatus == TASK_STATUS__IDLE || execStatus == TASK_STATUS__CLOSING) { + SStreamTaskRunReq* pRunReq = rpcMallocCont(sizeof(SStreamTaskRunReq)); + if (pRunReq == NULL) return -1; + + // TODO: do we need htonl? + pRunReq->head.vgId = vgId; + pRunReq->streamId = pTask->streamId; + pRunReq->taskId = pTask->taskId; + SRpcMsg msg = { + .msgType = TDMT_STREAM_TASK_RUN, + .pCont = pRunReq, + .contLen = sizeof(SStreamTaskRunReq), + }; + tmsgPutToQueue(pMsgCb, FETCH_QUEUE, &msg); + } + return 0; +} + +int32_t streamTaskEnqueue(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pRsp) { + SStreamDataBlock* pData = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM); + int8_t status; + + // enqueue + if (pData != NULL) { + pData->type = STREAM_DATA_TYPE_SSDATA_BLOCK; + pData->sourceVg = pReq->sourceVg; + // decode + /*pData->blocks = pReq->data;*/ + /*pBlock->sourceVer = pReq->sourceVer;*/ + streamDispatchReqToData(pReq, pData); + if (streamTaskInput(pTask, (SStreamQueueItem*)pData) == 0) { + status = TASK_INPUT_STATUS__NORMAL; + } else { + status = TASK_INPUT_STATUS__FAILED; + } + } else { + streamTaskInputFail(pTask); + status = TASK_INPUT_STATUS__FAILED; + } + + // rsp by input status + void* buf = rpcMallocCont(sizeof(SMsgHead) + sizeof(SStreamDispatchRsp)); + ((SMsgHead*)buf)->vgId = htonl(pReq->upstreamNodeId); + SStreamDispatchRsp* pCont = POINTER_SHIFT(buf, sizeof(SMsgHead)); + pCont->inputStatus = status; + pCont->streamId = pReq->streamId; + pCont->taskId = pReq->sourceTaskId; + pRsp->pCont = buf; + pRsp->contLen = sizeof(SMsgHead) + sizeof(SStreamDispatchRsp); + tmsgSendRsp(pRsp); + return status == TASK_INPUT_STATUS__NORMAL ? 0 : -1; +} + +int32_t streamProcessDispatchReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchReq* pReq, SRpcMsg* pRsp) { + // 1. handle input + streamTaskEnqueue(pTask, pReq, pRsp); + + // 2. try exec + // 2.1. idle: exec + // 2.2. executing: return + // 2.3. closing: keep trying + if (pTask->execType != TASK_EXEC__NONE) { + streamExec(pTask, pMsgCb); + } else { + ASSERT(pTask->sinkType != TASK_SINK__NONE); + while (1) { + void* data = streamQueueNextItem(pTask->inputQueue); + if (data == NULL) return 0; + if (streamTaskOutput(pTask, data) < 0) { + ASSERT(0); + } + } + } + + // 3. handle output + // 3.1 check and set status + // 3.2 dispatch / sink + if (pTask->dispatchType != TASK_DISPATCH__NONE) { + streamDispatch(pTask, pMsgCb); + } + + return 0; +} + +int32_t streamProcessDispatchRsp(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchRsp* pRsp) { + ASSERT(pRsp->inputStatus == TASK_OUTPUT_STATUS__NORMAL || pRsp->inputStatus == TASK_OUTPUT_STATUS__BLOCKED); + int8_t old = atomic_exchange_8(&pTask->outputStatus, pRsp->inputStatus); + ASSERT(old == TASK_OUTPUT_STATUS__WAIT); + if (pRsp->inputStatus == TASK_INPUT_STATUS__BLOCKED) { + // TODO: init recover timer + return 0; + } + // continue dispatch + if (pTask->dispatchType != TASK_DISPATCH__NONE) { + streamDispatch(pTask, pMsgCb); + } + return 0; +} + +int32_t streamTaskProcessRunReq(SStreamTask* pTask, SMsgCb* pMsgCb) { + streamExec(pTask, pMsgCb); + if (pTask->dispatchType != TASK_DISPATCH__NONE) { + streamDispatch(pTask, pMsgCb); + } + return 0; +} + +int32_t streamProcessRecoverReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamTaskRecoverReq* pReq, SRpcMsg* pMsg) { + // + return 0; +} + +int32_t streamProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp) { + // + return 0; +} diff --git a/source/libs/stream/src/streamData.c b/source/libs/stream/src/streamData.c new file mode 100644 index 0000000000..473ad32752 --- /dev/null +++ b/source/libs/stream/src/streamData.c @@ -0,0 +1,88 @@ +/* + * 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 "streamInc.h" + +#if 0 +int32_t streamDataBlockEncode(void** buf, const SStreamDataBlock* pOutput) { + int32_t tlen = 0; + tlen += taosEncodeFixedI8(buf, pOutput->type); + tlen += taosEncodeFixedI32(buf, pOutput->sourceVg); + tlen += taosEncodeFixedI64(buf, pOutput->sourceVer); + ASSERT(pOutput->type == STREAM_INPUT__DATA_BLOCK); + tlen += tEncodeDataBlocks(buf, pOutput->blocks); + return tlen; +} + +void* streamDataBlockDecode(const void* buf, SStreamDataBlock* pInput) { + buf = taosDecodeFixedI8(buf, &pInput->type); + buf = taosDecodeFixedI32(buf, &pInput->sourceVg); + buf = taosDecodeFixedI64(buf, &pInput->sourceVer); + ASSERT(pInput->type == STREAM_INPUT__DATA_BLOCK); + buf = tDecodeDataBlocks(buf, &pInput->blocks); + return (void*)buf; +} +#endif + +int32_t streamDispatchReqToData(const SStreamDispatchReq* pReq, SStreamDataBlock* pData) { + int32_t blockNum = pReq->blockNum; + SArray* pArray = taosArrayInit(blockNum, sizeof(SSDataBlock)); + if (pArray == NULL) { + return -1; + } + taosArraySetSize(pArray, blockNum); + + ASSERT(pReq->blockNum == taosArrayGetSize(pReq->data)); + ASSERT(pReq->blockNum == taosArrayGetSize(pReq->dataLen)); + + for (int32_t i = 0; i < blockNum; i++) { + int32_t len = *(int32_t*)taosArrayGet(pReq->dataLen, i); + SRetrieveTableRsp* pRetrieve = taosArrayGetP(pReq->data, i); + SSDataBlock* pDataBlock = taosArrayGet(pArray, i); + blockCompressDecode(pDataBlock, htonl(pRetrieve->numOfCols), htonl(pRetrieve->numOfRows), pRetrieve->data); + // TODO: refactor + pDataBlock->info.childId = pReq->sourceChildId; + } + pData->blocks = pArray; + return 0; +} + +SStreamDataSubmit* streamDataSubmitNew(SSubmitReq* pReq) { + SStreamDataSubmit* pDataSubmit = (SStreamDataSubmit*)taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM); + if (pDataSubmit == NULL) return NULL; + pDataSubmit->dataRef = (int32_t*)taosMemoryMalloc(sizeof(int32_t)); + if (pDataSubmit->dataRef == NULL) goto FAIL; + pDataSubmit->data = pReq; + *pDataSubmit->dataRef = 1; + pDataSubmit->type = STREAM_INPUT__DATA_SUBMIT; + return pDataSubmit; +FAIL: + taosFreeQitem(pDataSubmit); + return NULL; +} + +static FORCE_INLINE void streamDataSubmitRefInc(SStreamDataSubmit* pDataSubmit) { + atomic_add_fetch_32(pDataSubmit->dataRef, 1); +} + +SStreamDataSubmit* streamSubmitRefClone(SStreamDataSubmit* pSubmit) { + SStreamDataSubmit* pSubmitClone = taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM); + if (pSubmitClone == NULL) { + return NULL; + } + streamDataSubmitRefInc(pSubmit); + memcpy(pSubmitClone, pSubmit, sizeof(SStreamDataSubmit)); + return pSubmitClone; +} diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c new file mode 100644 index 0000000000..16da418677 --- /dev/null +++ b/source/libs/stream/src/streamDispatch.c @@ -0,0 +1,206 @@ +/* + * 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 "streamInc.h" + +int32_t tEncodeStreamDispatchReq(SEncoder* pEncoder, const SStreamDispatchReq* pReq) { + if (tStartEncode(pEncoder) < 0) return -1; + if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->sourceTaskId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->sourceVg) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->sourceChildId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->upstreamNodeId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->blockNum) < 0) return -1; + ASSERT(taosArrayGetSize(pReq->data) == pReq->blockNum); + ASSERT(taosArrayGetSize(pReq->dataLen) == pReq->blockNum); + for (int32_t i = 0; i < pReq->blockNum; i++) { + int32_t len = *(int32_t*)taosArrayGet(pReq->dataLen, i); + void* data = taosArrayGetP(pReq->data, i); + if (tEncodeI32(pEncoder, len) < 0) return -1; + if (tEncodeBinary(pEncoder, data, len) < 0) return -1; + } + tEndEncode(pEncoder); + return pEncoder->pos; +} + +int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq) { + if (tStartDecode(pDecoder) < 0) return -1; + if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->sourceTaskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->sourceVg) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->sourceChildId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->upstreamNodeId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->blockNum) < 0) return -1; + ASSERT(pReq->blockNum > 0); + pReq->data = taosArrayInit(pReq->blockNum, sizeof(void*)); + pReq->dataLen = taosArrayInit(pReq->blockNum, sizeof(int32_t)); + for (int32_t i = 0; i < pReq->blockNum; i++) { + int32_t len1; + uint64_t len2; + void* data; + if (tDecodeI32(pDecoder, &len1) < 0) return -1; + if (tDecodeBinaryAlloc(pDecoder, &data, &len2) < 0) return -1; + ASSERT(len1 == len2); + taosArrayPush(pReq->dataLen, &len1); + taosArrayPush(pReq->data, &data); + } + tEndDecode(pDecoder); + return 0; +} + +static int32_t streamAddBlockToDispatchMsg(const SSDataBlock* pBlock, SStreamDispatchReq* pReq) { + int32_t dataStrLen = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock); + void* buf = taosMemoryCalloc(1, dataStrLen); + if (buf == NULL) return -1; + + SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)buf; + pRetrieve->useconds = 0; + pRetrieve->precision = TSDB_DEFAULT_PRECISION; + pRetrieve->compressed = 0; + pRetrieve->completed = 1; + pRetrieve->numOfRows = htonl(pBlock->info.rows); + pRetrieve->numOfCols = htonl(pBlock->info.numOfCols); + + int32_t actualLen = 0; + blockCompressEncode(pBlock, pRetrieve->data, &actualLen, pBlock->info.numOfCols, false); + actualLen += sizeof(SRetrieveTableRsp); + ASSERT(actualLen <= dataStrLen); + taosArrayPush(pReq->dataLen, &actualLen); + taosArrayPush(pReq->data, &buf); + + return 0; +} + +int32_t streamBuildDispatchMsg(SStreamTask* pTask, SStreamDataBlock* data, SRpcMsg* pMsg, SEpSet** ppEpSet) { + void* buf = NULL; + int32_t code = -1; + int32_t blockNum = taosArrayGetSize(data->blocks); + ASSERT(blockNum != 0); + + SStreamDispatchReq req = { + .streamId = pTask->streamId, + .sourceTaskId = pTask->taskId, + .sourceVg = data->sourceVg, + .sourceChildId = pTask->childId, + .upstreamNodeId = pTask->nodeId, + .blockNum = blockNum, + }; + + req.data = taosArrayInit(blockNum, sizeof(void*)); + req.dataLen = taosArrayInit(blockNum, sizeof(int32_t)); + if (req.data == NULL || req.dataLen == NULL) { + goto FAIL; + } + for (int32_t i = 0; i < blockNum; i++) { + SSDataBlock* pDataBlock = taosArrayGet(data->blocks, i); + if (streamAddBlockToDispatchMsg(pDataBlock, &req) < 0) { + goto FAIL; + } + } + int32_t vgId = 0; + int32_t downstreamTaskId = 0; + // find ep + if (pTask->dispatchType == TASK_DISPATCH__FIXED) { + vgId = pTask->fixedEpDispatcher.nodeId; + *ppEpSet = &pTask->fixedEpDispatcher.epSet; + downstreamTaskId = pTask->fixedEpDispatcher.taskId; + } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { + // TODO get ctbName for each block + SSDataBlock* pBlock = taosArrayGet(data->blocks, 0); + char* ctbName = buildCtbNameByGroupId(pTask->shuffleDispatcher.stbFullName, pBlock->info.groupId); + // TODO: get hash function by hashMethod + + // get groupId, compute hash value + uint32_t hashValue = MurmurHash3_32(ctbName, strlen(ctbName)); + + // get node + // TODO: optimize search process + SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; + int32_t sz = taosArrayGetSize(vgInfo); + for (int32_t i = 0; i < sz; i++) { + SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i); + if (hashValue >= pVgInfo->hashBegin && hashValue <= pVgInfo->hashEnd) { + vgId = pVgInfo->vgId; + downstreamTaskId = pVgInfo->taskId; + *ppEpSet = &pVgInfo->epSet; + break; + } + } + ASSERT(vgId != 0); + } + + req.taskId = downstreamTaskId; + + // serialize + int32_t tlen; + tEncodeSize(tEncodeStreamDispatchReq, &req, tlen, code); + if (code < 0) goto FAIL; + code = -1; + buf = rpcMallocCont(sizeof(SMsgHead) + tlen); + if (buf == NULL) { + goto FAIL; + } + + ((SMsgHead*)buf)->vgId = htonl(vgId); + void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + + SEncoder encoder; + tEncoderInit(&encoder, abuf, tlen); + if ((code = tEncodeStreamDispatchReq(&encoder, &req)) < 0) { + goto FAIL; + } + tEncoderClear(&encoder); + + pMsg->contLen = tlen + sizeof(SMsgHead); + pMsg->pCont = buf; + pMsg->msgType = pTask->dispatchMsgType; + + code = 0; +FAIL: + if (code < 0 && buf) rpcFreeCont(buf); + if (req.data) taosArrayDestroyP(req.data, (FDelete)taosMemoryFree); + if (req.dataLen) taosArrayDestroy(req.dataLen); + return code; +} + +int32_t streamDispatch(SStreamTask* pTask, SMsgCb* pMsgCb) { +#if 1 + int8_t old = + atomic_val_compare_exchange_8(&pTask->outputStatus, TASK_OUTPUT_STATUS__NORMAL, TASK_OUTPUT_STATUS__WAIT); + if (old != TASK_OUTPUT_STATUS__NORMAL) { + return 0; + } +#endif + + SStreamDataBlock* pBlock = streamQueueNextItem(pTask->outputQueue); + if (pBlock == NULL) { + atomic_store_8(&pTask->outputStatus, TASK_OUTPUT_STATUS__NORMAL); + return 0; + } + ASSERT(pBlock->type == STREAM_DATA_TYPE_SSDATA_BLOCK); + + SRpcMsg dispatchMsg = {0}; + SEpSet* pEpSet = NULL; + if (streamBuildDispatchMsg(pTask, pBlock, &dispatchMsg, &pEpSet) < 0) { + ASSERT(0); + atomic_store_8(&pTask->outputStatus, TASK_OUTPUT_STATUS__NORMAL); + return -1; + } + + tmsgSendReq(pEpSet, &dispatchMsg); + return 0; +} diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c new file mode 100644 index 0000000000..fe1a857743 --- /dev/null +++ b/source/libs/stream/src/streamExec.c @@ -0,0 +1,125 @@ +/* + * 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 "executor.h" +#include "tstream.h" + +static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) { + void* exec = pTask->exec.executor; + + // set input + if (pTask->inputType == STREAM_INPUT__DATA_SUBMIT) { + SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)data; + ASSERT(pSubmit->type == STREAM_INPUT__DATA_SUBMIT); + + qSetStreamInput(exec, pSubmit->data, STREAM_DATA_TYPE_SUBMIT_BLOCK, false); + } else if (pTask->inputType == STREAM_INPUT__DATA_BLOCK) { + SStreamDataBlock* pBlock = (SStreamDataBlock*)data; + ASSERT(pBlock->type == STREAM_INPUT__DATA_BLOCK); + + SArray* blocks = pBlock->blocks; + qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_DATA_TYPE_SSDATA_BLOCK, false); + } + + // exec + while (1) { + SSDataBlock* output = NULL; + uint64_t ts = 0; + if (qExecTask(exec, &output, &ts) < 0) { + ASSERT(false); + } + if (output == NULL) break; + // TODO: do we need free memory? + SSDataBlock* outputCopy = createOneDataBlock(output, true); + outputCopy->info.childId = pTask->childId; + taosArrayPush(pRes, outputCopy); + } + return 0; +} + +static SArray* streamExecForQall(SStreamTask* pTask, SArray* pRes) { + while (1) { + void* data = streamQueueNextItem(pTask->inputQueue); + if (data == NULL) break; + + streamTaskExecImpl(pTask, data, pRes); + + if (taosArrayGetSize(pRes) != 0) { + SStreamDataBlock* qRes = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM); + if (qRes == NULL) { + streamQueueProcessFail(pTask->inputQueue); + taosArrayDestroy(pRes); + return NULL; + } + qRes->type = STREAM_INPUT__DATA_BLOCK; + qRes->blocks = pRes; + /*qRes->sourceVg = pTask->nodeId;*/ + if (streamTaskOutput(pTask, qRes) < 0) { + streamQueueProcessFail(pTask->inputQueue); + taosArrayDestroy(pRes); + taosFreeQitem(qRes); + return NULL; + } + + if (pTask->inputType == STREAM_INPUT__DATA_SUBMIT) { + streamDataSubmitRefDec((SStreamDataSubmit*)data); + taosFreeQitem(data); + } else { + taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)tDeleteSSDataBlock); + taosFreeQitem(data); + } + streamQueueProcessSuccess(pTask->inputQueue); + return taosArrayInit(0, sizeof(SSDataBlock)); + } + } + return pRes; +} + +// TODO: handle version +int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) { + SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); + if (pRes == NULL) return -1; + while (1) { + int8_t execStatus = atomic_val_compare_exchange_8(&pTask->status, TASK_STATUS__IDLE, TASK_STATUS__EXECUTING); + if (execStatus == TASK_STATUS__IDLE) { + // first run + pRes = streamExecForQall(pTask, pRes); + if (pRes == NULL) goto FAIL; + + // set status closing + atomic_store_8(&pTask->status, TASK_STATUS__CLOSING); + + // second run, make sure inputQ and qall are cleared + pRes = streamExecForQall(pTask, pRes); + if (pRes == NULL) goto FAIL; + + break; + } else if (execStatus == TASK_STATUS__CLOSING) { + continue; + } else if (execStatus == TASK_STATUS__EXECUTING) { + break; + } else { + ASSERT(0); + } + } + if (pRes) taosArrayDestroy(pRes); + atomic_store_8(&pTask->status, TASK_STATUS__IDLE); + return 0; +FAIL: + if (pRes) taosArrayDestroy(pRes); + atomic_store_8(&pTask->status, TASK_STATUS__IDLE); + return -1; +} + diff --git a/source/libs/stream/src/streamQueue.c b/source/libs/stream/src/streamQueue.c new file mode 100644 index 0000000000..d5a4da60f5 --- /dev/null +++ b/source/libs/stream/src/streamQueue.c @@ -0,0 +1,52 @@ +/* + * 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 "tstream.h" + +SStreamQueue* streamQueueOpen() { + SStreamQueue* pQueue = taosMemoryCalloc(1, sizeof(SStreamQueue)); + if (pQueue == NULL) return NULL; + pQueue->queue = taosOpenQueue(); + pQueue->qall = taosAllocateQall(); + if (pQueue->queue == NULL || pQueue->qall == NULL) { + goto FAIL; + } + pQueue->status = STREAM_QUEUE__SUCESS; + return pQueue; +FAIL: + if (pQueue->queue) taosCloseQueue(pQueue->queue); + if (pQueue->qall) taosFreeQall(pQueue->qall); + taosMemoryFree(pQueue); + return NULL; +} + +void streamQueueClose(SStreamQueue* queue) { + while (1) { + void* qItem = streamQueueNextItem(queue); + if (qItem) + taosFreeQitem(qItem); + else + return; + } +} + +void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit) { + int32_t ref = atomic_sub_fetch_32(pDataSubmit->dataRef, 1); + ASSERT(ref >= 0); + if (ref == 0) { + taosMemoryFree(pDataSubmit->data); + taosMemoryFree(pDataSubmit->dataRef); + } +} diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c new file mode 100644 index 0000000000..890ae1f3b5 --- /dev/null +++ b/source/libs/stream/src/streamTask.c @@ -0,0 +1,138 @@ +/* + * 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 "executor.h" +#include "tstream.h" + +SStreamTask* tNewSStreamTask(int64_t streamId, int32_t childId) { + SStreamTask* pTask = (SStreamTask*)taosMemoryCalloc(1, sizeof(SStreamTask)); + if (pTask == NULL) { + return NULL; + } + pTask->taskId = tGenIdPI32(); + pTask->streamId = streamId; + pTask->childId = childId; + pTask->status = TASK_STATUS__IDLE; + pTask->inputStatus = TASK_INPUT_STATUS__NORMAL; + pTask->outputStatus = TASK_OUTPUT_STATUS__NORMAL; + + return pTask; +} + +int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) { + /*if (tStartEncode(pEncoder) < 0) return -1;*/ + if (tEncodeI64(pEncoder, pTask->streamId) < 0) return -1; + if (tEncodeI32(pEncoder, pTask->taskId) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->inputType) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->status) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->sourceType) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->execType) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->sinkType) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->dispatchType) < 0) return -1; + if (tEncodeI16(pEncoder, pTask->dispatchMsgType) < 0) return -1; + + if (tEncodeI32(pEncoder, pTask->childId) < 0) return -1; + if (tEncodeI32(pEncoder, pTask->nodeId) < 0) return -1; + if (tEncodeSEpSet(pEncoder, &pTask->epSet) < 0) return -1; + + if (pTask->execType != TASK_EXEC__NONE) { + if (tEncodeI8(pEncoder, pTask->exec.parallelizable) < 0) return -1; + if (tEncodeCStr(pEncoder, pTask->exec.qmsg) < 0) return -1; + } + + if (pTask->sinkType == TASK_SINK__TABLE) { + if (tEncodeI64(pEncoder, pTask->tbSink.stbUid) < 0) return -1; + if (tEncodeCStr(pEncoder, pTask->tbSink.stbFullName) < 0) return -1; + if (tEncodeSSchemaWrapper(pEncoder, pTask->tbSink.pSchemaWrapper) < 0) return -1; + } else if (pTask->sinkType == TASK_SINK__SMA) { + if (tEncodeI64(pEncoder, pTask->smaSink.smaId) < 0) return -1; + } else if (pTask->sinkType == TASK_SINK__FETCH) { + if (tEncodeI8(pEncoder, pTask->fetchSink.reserved) < 0) return -1; + } else { + ASSERT(pTask->sinkType == TASK_SINK__NONE); + } + + if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { + if (tEncodeI32(pEncoder, pTask->inplaceDispatcher.taskId) < 0) return -1; + } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { + if (tEncodeI32(pEncoder, pTask->fixedEpDispatcher.taskId) < 0) return -1; + if (tEncodeI32(pEncoder, pTask->fixedEpDispatcher.nodeId) < 0) return -1; + if (tEncodeSEpSet(pEncoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1; + } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { + if (tSerializeSUseDbRspImp(pEncoder, &pTask->shuffleDispatcher.dbInfo) < 0) return -1; + /*if (tEncodeI8(pEncoder, pTask->shuffleDispatcher.hashMethod) < 0) return -1;*/ + } + + /*tEndEncode(pEncoder);*/ + return pEncoder->pos; +} + +int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) { + /*if (tStartDecode(pDecoder) < 0) return -1;*/ + if (tDecodeI64(pDecoder, &pTask->streamId) < 0) return -1; + if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->inputType) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->status) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->sourceType) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->execType) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->sinkType) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->dispatchType) < 0) return -1; + if (tDecodeI16(pDecoder, &pTask->dispatchMsgType) < 0) return -1; + + if (tDecodeI32(pDecoder, &pTask->childId) < 0) return -1; + if (tDecodeI32(pDecoder, &pTask->nodeId) < 0) return -1; + if (tDecodeSEpSet(pDecoder, &pTask->epSet) < 0) return -1; + + if (pTask->execType != TASK_EXEC__NONE) { + if (tDecodeI8(pDecoder, &pTask->exec.parallelizable) < 0) return -1; + if (tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg) < 0) return -1; + } + + if (pTask->sinkType == TASK_SINK__TABLE) { + if (tDecodeI64(pDecoder, &pTask->tbSink.stbUid) < 0) return -1; + if (tDecodeCStrTo(pDecoder, pTask->tbSink.stbFullName) < 0) return -1; + pTask->tbSink.pSchemaWrapper = taosMemoryCalloc(1, sizeof(SSchemaWrapper)); + if (pTask->tbSink.pSchemaWrapper == NULL) return -1; + if (tDecodeSSchemaWrapper(pDecoder, pTask->tbSink.pSchemaWrapper) < 0) return -1; + } else if (pTask->sinkType == TASK_SINK__SMA) { + if (tDecodeI64(pDecoder, &pTask->smaSink.smaId) < 0) return -1; + } else if (pTask->sinkType == TASK_SINK__FETCH) { + if (tDecodeI8(pDecoder, &pTask->fetchSink.reserved) < 0) return -1; + } else { + ASSERT(pTask->sinkType == TASK_SINK__NONE); + } + + if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { + if (tDecodeI32(pDecoder, &pTask->inplaceDispatcher.taskId) < 0) return -1; + } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { + if (tDecodeI32(pDecoder, &pTask->fixedEpDispatcher.taskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pTask->fixedEpDispatcher.nodeId) < 0) return -1; + if (tDecodeSEpSet(pDecoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1; + } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { + /*if (tDecodeI8(pDecoder, &pTask->shuffleDispatcher.hashMethod) < 0) return -1;*/ + if (tDeserializeSUseDbRspImp(pDecoder, &pTask->shuffleDispatcher.dbInfo) < 0) return -1; + } + + /*tEndDecode(pDecoder);*/ + return 0; +} + +void tFreeSStreamTask(SStreamTask* pTask) { + streamQueueClose(pTask->inputQueue); + streamQueueClose(pTask->outputQueue); + if (pTask->exec.qmsg) taosMemoryFree(pTask->exec.qmsg); + qDestroyTask(pTask->exec.executor); + taosMemoryFree(pTask); +} diff --git a/source/libs/stream/src/tstreamUpdate.c b/source/libs/stream/src/streamUpdate.c similarity index 100% rename from source/libs/stream/src/tstreamUpdate.c rename to source/libs/stream/src/streamUpdate.c diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c deleted file mode 100644 index 7d406a7144..0000000000 --- a/source/libs/stream/src/tstream.c +++ /dev/null @@ -1,594 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "tstream.h" -#include "executor.h" - -int32_t streamDataBlockEncode(void** buf, const SStreamDataBlock* pOutput) { - int32_t tlen = 0; - tlen += taosEncodeFixedI8(buf, pOutput->type); - tlen += taosEncodeFixedI32(buf, pOutput->sourceVg); - tlen += taosEncodeFixedI64(buf, pOutput->sourceVer); - ASSERT(pOutput->type == STREAM_INPUT__DATA_BLOCK); - tlen += tEncodeDataBlocks(buf, pOutput->blocks); - return tlen; -} - -void* streamDataBlockDecode(const void* buf, SStreamDataBlock* pInput) { - buf = taosDecodeFixedI8(buf, &pInput->type); - buf = taosDecodeFixedI32(buf, &pInput->sourceVg); - buf = taosDecodeFixedI64(buf, &pInput->sourceVer); - ASSERT(pInput->type == STREAM_INPUT__DATA_BLOCK); - buf = tDecodeDataBlocks(buf, &pInput->blocks); - return (void*)buf; -} - -SStreamDataSubmit* streamSubmitRefClone(SStreamDataSubmit* pSubmit) { - SStreamDataSubmit* pSubmitClone = taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM); - if (pSubmitClone == NULL) { - return NULL; - } - streamDataSubmitRefInc(pSubmit); - memcpy(pSubmitClone, pSubmit, sizeof(SStreamDataSubmit)); - return pSubmitClone; -} - -static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* pMsg, SEpSet** ppEpSet) { - SStreamDispatchReq req = { - .streamId = pTask->streamId, - .data = data, - }; - return 0; -} - -static int32_t streamBuildExecMsg(SStreamTask* pTask, SArray* data, SRpcMsg* pMsg, SEpSet** ppEpSet) { - SStreamTaskExecReq req = { - .streamId = pTask->streamId, - .data = data, - }; - - int32_t tlen = sizeof(SMsgHead) + tEncodeSStreamTaskExecReq(NULL, &req); - void* buf = rpcMallocCont(tlen); - - if (buf == NULL) { - return -1; - } - - if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { - ((SMsgHead*)buf)->vgId = 0; - req.taskId = pTask->inplaceDispatcher.taskId; - - } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { - ((SMsgHead*)buf)->vgId = htonl(pTask->fixedEpDispatcher.nodeId); - *ppEpSet = &pTask->fixedEpDispatcher.epSet; - req.taskId = pTask->fixedEpDispatcher.taskId; - - } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - // TODO use general name rule of schemaless - char ctbName[TSDB_TABLE_FNAME_LEN + 22] = {0}; - // all groupId must be the same in an array - SSDataBlock* pBlock = taosArrayGet(data, 0); - sprintf(ctbName, "%s:%ld", pTask->shuffleDispatcher.stbFullName, pBlock->info.groupId); - - // TODO: get hash function by hashMethod - - // get groupId, compute hash value - uint32_t hashValue = MurmurHash3_32(ctbName, strlen(ctbName)); - - // get node - // TODO: optimize search process - SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; - int32_t sz = taosArrayGetSize(vgInfo); - int32_t nodeId = 0; - for (int32_t i = 0; i < sz; i++) { - SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i); - if (hashValue >= pVgInfo->hashBegin && hashValue <= pVgInfo->hashEnd) { - nodeId = pVgInfo->vgId; - req.taskId = pVgInfo->taskId; - *ppEpSet = &pVgInfo->epSet; - break; - } - } - ASSERT(nodeId != 0); - ((SMsgHead*)buf)->vgId = htonl(nodeId); - } - - void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tEncodeSStreamTaskExecReq(&abuf, &req); - - pMsg->pCont = buf; - pMsg->contLen = tlen; - pMsg->code = 0; - pMsg->msgType = pTask->dispatchMsgType; - pMsg->info.noResp = 1; - - return 0; -} - -static int32_t streamShuffleDispatch(SStreamTask* pTask, SMsgCb* pMsgCb, SHashObj* data) { - void* pIter = NULL; - while (1) { - pIter = taosHashIterate(data, pIter); - if (pIter == NULL) return 0; - SArray* pData = *(SArray**)pIter; - SRpcMsg dispatchMsg = {0}; - SEpSet* pEpSet; - if (streamBuildExecMsg(pTask, pData, &dispatchMsg, &pEpSet) < 0) { - ASSERT(0); - return -1; - } - tmsgSendReq(pEpSet, &dispatchMsg); - } - return 0; -} - -int32_t streamEnqueueDataSubmit(SStreamTask* pTask, SStreamDataSubmit* input) { - ASSERT(pTask->inputType == TASK_INPUT_TYPE__SUMBIT_BLOCK); - int8_t inputStatus = atomic_load_8(&pTask->inputStatus); - if (inputStatus == TASK_INPUT_STATUS__NORMAL) { - streamDataSubmitRefInc(input); - taosWriteQitem(pTask->inputQ, input); - } - return inputStatus; -} - -int32_t streamEnqueueDataBlk(SStreamTask* pTask, SStreamDataBlock* input) { - ASSERT(pTask->inputType == TASK_INPUT_TYPE__DATA_BLOCK); - taosWriteQitem(pTask->inputQ, input); - int8_t inputStatus = atomic_load_8(&pTask->inputStatus); - return inputStatus; -} - -static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) { - void* exec = pTask->exec.executor; - - // set input - if (pTask->inputType == STREAM_INPUT__DATA_SUBMIT) { - SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)data; - ASSERT(pSubmit->type == STREAM_INPUT__DATA_SUBMIT); - - qSetStreamInput(exec, pSubmit->data, STREAM_DATA_TYPE_SUBMIT_BLOCK, false); - } else if (pTask->inputType == STREAM_INPUT__DATA_BLOCK) { - SStreamDataBlock* pBlock = (SStreamDataBlock*)data; - ASSERT(pBlock->type == STREAM_INPUT__DATA_BLOCK); - - SArray* blocks = pBlock->blocks; - qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_DATA_TYPE_SSDATA_BLOCK, false); - } - - // exec - while (1) { - SSDataBlock* output = NULL; - uint64_t ts = 0; - if (qExecTask(exec, &output, &ts) < 0) { - ASSERT(false); - } - if (output == NULL) break; - // TODO: do we need free memory? - SSDataBlock* outputCopy = createOneDataBlock(output, true); - taosArrayPush(pRes, outputCopy); - } - - // destroy - if (pTask->inputType == STREAM_INPUT__DATA_SUBMIT) { - streamDataSubmitRefDec((SStreamDataSubmit*)data); - taosFreeQitem(data); - } else { - taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)tDeleteSSDataBlock); - taosFreeQitem(data); - } - return 0; -} - -static SArray* streamExecForQall(SStreamTask* pTask, SArray* pRes) { - while (1) { - void* data = NULL; - taosGetQitem(pTask->inputQAll, &data); - if (data == NULL) break; - - streamTaskExecImpl(pTask, data, pRes); - - if (taosArrayGetSize(pRes) != 0) { - SStreamDataBlock* qRes = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM); - qRes->type = STREAM_INPUT__DATA_BLOCK; - qRes->blocks = pRes; - taosWriteQitem(pTask->outputQ, qRes); - return taosArrayInit(0, sizeof(SSDataBlock)); - } - } - return pRes; -} - -// TODO: handle version -int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) { - SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); - if (pRes == NULL) return -1; - while (1) { - int8_t execStatus = atomic_val_compare_exchange_8(&pTask->status, TASK_STATUS__IDLE, TASK_STATUS__EXECUTING); - if (execStatus == TASK_STATUS__IDLE) { - // first run, from qall, handle failure from last exec - pRes = streamExecForQall(pTask, pRes); - if (pRes == NULL) goto FAIL; - - // second run, from inputQ - taosReadAllQitems(pTask->inputQ, pTask->inputQAll); - pRes = streamExecForQall(pTask, pRes); - if (pRes == NULL) goto FAIL; - - // set status closing - atomic_store_8(&pTask->status, TASK_STATUS__CLOSING); - - // third run, make sure inputQ and qall are cleared - taosReadAllQitems(pTask->inputQ, pTask->inputQAll); - pRes = streamExecForQall(pTask, pRes); - if (pRes == NULL) goto FAIL; - - atomic_store_8(&pTask->status, TASK_STATUS__IDLE); - break; - } else if (execStatus == TASK_STATUS__CLOSING) { - continue; - } else if (execStatus == TASK_STATUS__EXECUTING) { - break; - } else { - ASSERT(0); - } - } - return 0; -FAIL: - atomic_store_8(&pTask->status, TASK_STATUS__IDLE); - return -1; -} - -int32_t streamSink(SStreamTask* pTask, SMsgCb* pMsgCb) { - bool firstRun = 1; - while (1) { - SStreamDataBlock* pBlock = NULL; - if (!firstRun) { - taosReadAllQitems(pTask->outputQ, pTask->outputQAll); - } - taosGetQitem(pTask->outputQAll, (void**)&pBlock); - if (pBlock == NULL) { - if (firstRun) { - firstRun = 0; - continue; - } else { - break; - } - } - - SArray* pRes = pBlock->blocks; - - // sink - if (pTask->sinkType == TASK_SINK__TABLE) { - // blockDebugShowData(pRes); - pTask->tbSink.tbSinkFunc(pTask, pTask->tbSink.vnode, 0, pRes); - } else if (pTask->sinkType == TASK_SINK__SMA) { - pTask->smaSink.smaSink(pTask->ahandle, pTask->smaSink.smaId, pRes); - // - } else if (pTask->sinkType == TASK_SINK__FETCH) { - // - } else { - ASSERT(pTask->sinkType == TASK_SINK__NONE); - } - - // dispatch - // TODO dispatch guard - int8_t outputStatus = atomic_load_8(&pTask->outputStatus); - if (outputStatus == TASK_OUTPUT_STATUS__NORMAL) { - if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { - SRpcMsg dispatchMsg = {0}; - if (streamBuildExecMsg(pTask, pRes, &dispatchMsg, NULL) < 0) { - ASSERT(0); - return -1; - } - - int32_t qType; - if (pTask->dispatchMsgType == TDMT_VND_TASK_DISPATCH || pTask->dispatchMsgType == TDMT_SND_TASK_DISPATCH) { - qType = FETCH_QUEUE; - /*} else if (pTask->dispatchMsgType == TDMT_VND_TASK_MERGE_EXEC ||*/ - /*pTask->dispatchMsgType == TDMT_SND_TASK_MERGE_EXEC) {*/ - /*qType = MERGE_QUEUE;*/ - /*} else if (pTask->dispatchMsgType == TDMT_VND_TASK_WRITE_EXEC) {*/ - /*qType = WRITE_QUEUE;*/ - } else { - ASSERT(0); - } - tmsgPutToQueue(pMsgCb, qType, &dispatchMsg); - - } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { - SRpcMsg dispatchMsg = {0}; - SEpSet* pEpSet = NULL; - if (streamBuildExecMsg(pTask, pRes, &dispatchMsg, &pEpSet) < 0) { - ASSERT(0); - return -1; - } - - tmsgSendReq(pEpSet, &dispatchMsg); - - } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - SHashObj* pShuffleRes = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); - if (pShuffleRes == NULL) { - return -1; - } - - int32_t sz = taosArrayGetSize(pRes); - for (int32_t i = 0; i < sz; i++) { - SSDataBlock* pDataBlock = taosArrayGet(pRes, i); - SArray* pArray = taosHashGet(pShuffleRes, &pDataBlock->info.groupId, sizeof(int64_t)); - if (pArray == NULL) { - pArray = taosArrayInit(0, sizeof(SSDataBlock)); - if (pArray == NULL) { - return -1; - } - taosHashPut(pShuffleRes, &pDataBlock->info.groupId, sizeof(int64_t), &pArray, sizeof(void*)); - } - taosArrayPush(pArray, pDataBlock); - } - - if (streamShuffleDispatch(pTask, pMsgCb, pShuffleRes) < 0) { - return -1; - } - - } else { - ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE); - } - } - } - return 0; -} - -int32_t streamTaskEnqueue(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pRsp) { - SStreamDataBlock* pBlock = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM); - int8_t status; - - // 1.1 update status - // TODO cal backpressure - if (pBlock == NULL) { - atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED); - status = TASK_INPUT_STATUS__FAILED; - } else { - status = atomic_load_8(&pTask->inputStatus); - } - - // 1.2 enqueue - pBlock->type = STREAM_DATA_TYPE_SSDATA_BLOCK; - pBlock->sourceVg = pReq->sourceVg; - /*pBlock->sourceVer = pReq->sourceVer;*/ - taosWriteQitem(pTask->inputQ, pBlock); - - // 1.3 rsp by input status - SStreamDispatchRsp* pCont = rpcMallocCont(sizeof(SStreamDispatchRsp)); - pCont->inputStatus = status; - pCont->streamId = pReq->streamId; - pCont->taskId = pReq->sourceTaskId; - pRsp->pCont = pCont; - pRsp->contLen = sizeof(SStreamDispatchRsp); - tmsgSendRsp(pRsp); - - return 0; -} - -int32_t streamProcessDispatchReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchReq* pReq, SRpcMsg* pRsp) { - // 1. handle input - streamTaskEnqueue(pTask, pReq, pRsp); - - // 2. try exec - // 2.1. idle: exec - // 2.2. executing: return - // 2.3. closing: keep trying - streamExec(pTask, pMsgCb); - - // 3. handle output - // 3.1 check and set status - // 3.2 dispatch / sink - streamSink(pTask, pMsgCb); - - return 0; -} - -int32_t streamProcessDispatchRsp(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchRsp* pRsp) { - atomic_store_8(&pTask->inputStatus, pRsp->inputStatus); - if (pRsp->inputStatus == TASK_INPUT_STATUS__BLOCKED) { - // TODO: init recover timer - } - // continue dispatch - streamSink(pTask, pMsgCb); - return 0; -} - -int32_t streamTaskProcessRunReq(SStreamTask* pTask, SMsgCb* pMsgCb) { - streamExec(pTask, pMsgCb); - streamSink(pTask, pMsgCb); - return 0; -} - -int32_t streamProcessRecoverReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamTaskRecoverReq* pReq, SRpcMsg* pMsg) { - // - return 0; -} - -int32_t streamProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp) { - // - return 0; -} - -int32_t tEncodeStreamDispatchReq(SEncoder* pEncoder, const SStreamDispatchReq* pReq) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->sourceTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->sourceVg) < 0) return -1; - tEndEncode(pEncoder); - return 0; -} - -int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->sourceTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->sourceVg) < 0) return -1; - tEndDecode(pDecoder); - return 0; -} - -int32_t tEncodeSStreamTaskExecReq(void** buf, const SStreamTaskExecReq* pReq) { - int32_t tlen = 0; - tlen += taosEncodeFixedI64(buf, pReq->streamId); - tlen += taosEncodeFixedI32(buf, pReq->taskId); - tlen += tEncodeDataBlocks(buf, pReq->data); - return tlen; -} - -void* tDecodeSStreamTaskExecReq(const void* buf, SStreamTaskExecReq* pReq) { - buf = taosDecodeFixedI64(buf, &pReq->streamId); - buf = taosDecodeFixedI32(buf, &pReq->taskId); - buf = tDecodeDataBlocks(buf, &pReq->data); - return (void*)buf; -} - -void tFreeSStreamTaskExecReq(SStreamTaskExecReq* pReq) { taosArrayDestroy(pReq->data); } - -SStreamTask* tNewSStreamTask(int64_t streamId) { - SStreamTask* pTask = (SStreamTask*)taosMemoryCalloc(1, sizeof(SStreamTask)); - if (pTask == NULL) { - return NULL; - } - pTask->taskId = tGenIdPI32(); - pTask->streamId = streamId; - pTask->status = TASK_STATUS__IDLE; - - return pTask; -} - -int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) { - /*if (tStartEncode(pEncoder) < 0) return -1;*/ - if (tEncodeI64(pEncoder, pTask->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pTask->taskId) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->inputType) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->status) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->sourceType) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->execType) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->sinkType) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->dispatchType) < 0) return -1; - if (tEncodeI16(pEncoder, pTask->dispatchMsgType) < 0) return -1; - - if (tEncodeI32(pEncoder, pTask->nodeId) < 0) return -1; - if (tEncodeSEpSet(pEncoder, &pTask->epSet) < 0) return -1; - - if (pTask->execType != TASK_EXEC__NONE) { - if (tEncodeI8(pEncoder, pTask->exec.parallelizable) < 0) return -1; - if (tEncodeCStr(pEncoder, pTask->exec.qmsg) < 0) return -1; - } - - if (pTask->sinkType == TASK_SINK__TABLE) { - if (tEncodeI64(pEncoder, pTask->tbSink.stbUid) < 0) return -1; - if (tEncodeCStr(pEncoder, pTask->tbSink.stbFullName) < 0) return -1; - if (tEncodeSSchemaWrapper(pEncoder, pTask->tbSink.pSchemaWrapper) < 0) return -1; - } else if (pTask->sinkType == TASK_SINK__SMA) { - if (tEncodeI64(pEncoder, pTask->smaSink.smaId) < 0) return -1; - } else if (pTask->sinkType == TASK_SINK__FETCH) { - if (tEncodeI8(pEncoder, pTask->fetchSink.reserved) < 0) return -1; - } else { - ASSERT(pTask->sinkType == TASK_SINK__NONE); - } - - if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { - if (tEncodeI32(pEncoder, pTask->inplaceDispatcher.taskId) < 0) return -1; - } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { - if (tEncodeI32(pEncoder, pTask->fixedEpDispatcher.taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pTask->fixedEpDispatcher.nodeId) < 0) return -1; - if (tEncodeSEpSet(pEncoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1; - } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - if (tSerializeSUseDbRspImp(pEncoder, &pTask->shuffleDispatcher.dbInfo) < 0) return -1; - /*if (tEncodeI8(pEncoder, pTask->shuffleDispatcher.hashMethod) < 0) return -1;*/ - } - - /*tEndEncode(pEncoder);*/ - return pEncoder->pos; -} - -int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) { - /*if (tStartDecode(pDecoder) < 0) return -1;*/ - if (tDecodeI64(pDecoder, &pTask->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->inputType) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->status) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->sourceType) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->execType) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->sinkType) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->dispatchType) < 0) return -1; - if (tDecodeI16(pDecoder, &pTask->dispatchMsgType) < 0) return -1; - - if (tDecodeI32(pDecoder, &pTask->nodeId) < 0) return -1; - if (tDecodeSEpSet(pDecoder, &pTask->epSet) < 0) return -1; - - if (pTask->execType != TASK_EXEC__NONE) { - if (tDecodeI8(pDecoder, &pTask->exec.parallelizable) < 0) return -1; - if (tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg) < 0) return -1; - } - - if (pTask->sinkType == TASK_SINK__TABLE) { - if (tDecodeI64(pDecoder, &pTask->tbSink.stbUid) < 0) return -1; - if (tDecodeCStrTo(pDecoder, pTask->tbSink.stbFullName) < 0) return -1; - pTask->tbSink.pSchemaWrapper = taosMemoryCalloc(1, sizeof(SSchemaWrapper)); - if (pTask->tbSink.pSchemaWrapper == NULL) return -1; - if (tDecodeSSchemaWrapper(pDecoder, pTask->tbSink.pSchemaWrapper) < 0) return -1; - } else if (pTask->sinkType == TASK_SINK__SMA) { - if (tDecodeI64(pDecoder, &pTask->smaSink.smaId) < 0) return -1; - } else if (pTask->sinkType == TASK_SINK__FETCH) { - if (tDecodeI8(pDecoder, &pTask->fetchSink.reserved) < 0) return -1; - } else { - ASSERT(pTask->sinkType == TASK_SINK__NONE); - } - - if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { - if (tDecodeI32(pDecoder, &pTask->inplaceDispatcher.taskId) < 0) return -1; - } else if (pTask->dispatchType == TASK_DISPATCH__FIXED) { - if (tDecodeI32(pDecoder, &pTask->fixedEpDispatcher.taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pTask->fixedEpDispatcher.nodeId) < 0) return -1; - if (tDecodeSEpSet(pDecoder, &pTask->fixedEpDispatcher.epSet) < 0) return -1; - } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - /*if (tDecodeI8(pDecoder, &pTask->shuffleDispatcher.hashMethod) < 0) return -1;*/ - if (tDeserializeSUseDbRspImp(pDecoder, &pTask->shuffleDispatcher.dbInfo) < 0) return -1; - } - - /*tEndDecode(pDecoder);*/ - return 0; -} - -void tFreeSStreamTask(SStreamTask* pTask) { - taosCloseQueue(pTask->inputQ); - taosCloseQueue(pTask->outputQ); - // TODO - if (pTask->exec.qmsg) taosMemoryFree(pTask->exec.qmsg); - qDestroyTask(pTask->exec.executor); - taosMemoryFree(pTask); -} - -#if 0 -int32_t tEncodeSStreamTaskExecReq(SCoder* pEncoder, const SStreamTaskExecReq* pReq) { - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; - /*if (tEncodeDataBlocks(buf, pReq->streamId) < 0) return -1;*/ - return pEncoder->size; -} -int32_t tDecodeSStreamTaskExecReq(SCoder* pDecoder, SStreamTaskExecReq* pReq) { - return pEncoder->size; -} -void tFreeSStreamTaskExecReq(SStreamTaskExecReq* pReq) { - taosArrayDestroyEx(pReq->data, tDeleteSSDataBlock); -} -#endif diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index d522b829dd..795d3e3c27 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -281,7 +281,7 @@ int32_t syncGetRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg) { return ret; } -int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg) { +int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo) { SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { return TAOS_SYNC_STATE_ERROR; @@ -291,7 +291,7 @@ int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg) { SRespStub stub; int32_t ret = syncRespMgrGetAndDel(pSyncNode->pSyncRespMgr, index, &stub); if (ret == 1) { - memcpy(msg, &(stub.rpcMsg), sizeof(SRpcMsg)); + *pInfo = stub.rpcMsg.info; } taosReleaseRef(tsNodeRefId, pSyncNode->rid); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 0090701ba5..e62a73b7fa 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -338,8 +338,7 @@ void cliHandleResp(SCliConn* conn) { return; } - int ret = cliAppCb(conn, &transMsg, pMsg); - if (ret != 0) { + if (cliAppCb(conn, &transMsg, pMsg) != 0) { tTrace("try to send req to next node"); return; } @@ -403,15 +402,13 @@ void cliHandleExcept(SCliConn* pConn) { continue; } } - int ret = cliAppCb(pConn, &transMsg, pMsg); - if (ret != 0) { + if (cliAppCb(pConn, &transMsg, pMsg) != 0) { tTrace("try to send req to next node"); return; } destroyCmsg(pMsg); tTrace("%s cli conn %p start to destroy", CONN_GET_INST_LABEL(pConn), pConn); } while (!transQueueEmpty(&pConn->cliMsgs)); - transUnrefCliHandle(pConn); } @@ -976,7 +973,7 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { arg->param1 = pMsg; arg->param2 = pThrd; transDQSched(pThrd->delayQueue, doDelayTask, arg, TRANS_RETRY_INTERVAL); - cliDestroyConn(pConn, true); + transUnrefCliHandle(pConn); return -1; } } else if (pCtx->retryCount < TRANS_RETRY_COUNT_LIMIT) { diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 50f99128b2..cfd711e6eb 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -307,6 +307,13 @@ static void uvHandleReq(SSvrConn* pConn) { if (pHead->noResp == 1) { transMsg.info.refId = -1; } + + // set up conn info + SRpcConnInfo* pConnInfo = &(transMsg.info.connInfo); + pConnInfo->clientIp = (uint32_t)(pConn->addr.sin_addr.s_addr); + pConnInfo->clientPort = ntohs(pConn->addr.sin_port); + tstrncpy(pConnInfo->user, pConn->user, sizeof(pConnInfo->user)); + transReleaseExHandle(refMgt, pConn->refId); STrans* pTransInst = pConn->pTransInst; @@ -1153,23 +1160,6 @@ _return2: rpcFreeCont(msg->pCont); } -int transGetConnInfo(void* thandle, STransHandleInfo* pInfo) { - if (thandle == NULL) { - tTrace("invalid handle %p, failed to Get Conn info", thandle); - return -1; - } - SExHandle* ex = thandle; - SSvrConn* pConn = ex->handle; - if (pConn == NULL) { - tTrace("invalid handle %p, failed to Get Conn info", thandle); - return -1; - } - - struct sockaddr_in addr = pConn->addr; - pInfo->clientIp = (uint32_t)(addr.sin_addr.s_addr); - pInfo->clientPort = ntohs(addr.sin_port); - tstrncpy(pInfo->user, pConn->user, sizeof(pInfo->user)); - return 0; -} +int transGetConnInfo(void* thandle, STransHandleInfo* pConnInfo) { return -1; } #endif diff --git a/source/util/src/talgo.c b/source/util/src/talgo.c index 8675670cfe..866ac5757b 100644 --- a/source/util/src/talgo.c +++ b/source/util/src/talgo.c @@ -158,82 +158,48 @@ void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ taosMemoryFreeClear(buf); } -void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size, __compar_fn_t compar, int32_t flags) { - // TODO: need to check the correctness of this function - int32_t l = 0; - int32_t r = (int32_t)nmemb; - int32_t idx = 0; - int32_t comparison; +void *taosbsearch(const void *key, const void *base, int32_t nmemb, int32_t size, __compar_fn_t compar, int32_t flags) { + uint8_t *p; + int32_t lidx; + int32_t ridx; + int32_t midx; + int32_t c; - if (flags == TD_EQ) { - return bsearch(key, base, nmemb, size, compar); - } else if (flags == TD_GE) { - if (nmemb <= 0) return NULL; - if ((*compar)(key, elePtrAt(base, size, 0)) <= 0) return elePtrAt(base, size, 0); - if ((*compar)(key, elePtrAt(base, size, nmemb - 1)) > 0) return NULL; + if (nmemb <= 0) return NULL; - while (l < r) { - idx = (l + r) / 2; - comparison = (*compar)(key, elePtrAt(base, size, idx)); - if (comparison < 0) { - r = idx; - } else if (comparison > 0) { - l = idx + 1; - } else { - return elePtrAt(base, size, idx); - } - } + lidx = 0; + ridx = nmemb - 1; + while (lidx <= ridx) { + midx = (lidx + ridx) / 2; + p = (uint8_t *)base + size * midx; - if ((*compar)(key, elePtrAt(base, size, idx)) < 0) { - return elePtrAt(base, size, idx); + c = compar(key, p); + if (c == 0) { + break; + } else if (c < 0) { + ridx = midx - 1; } else { - if (idx + 1 > nmemb - 1) { - return NULL; - } else { - return elePtrAt(base, size, idx + 1); - } + lidx = midx + 1; } - } else if (flags == TD_LE) { - if (nmemb <= 0) return NULL; - if ((*compar)(key, elePtrAt(base, size, nmemb - 1)) >= 0) return elePtrAt(base, size, nmemb - 1); - if ((*compar)(key, elePtrAt(base, size, 0)) < 0) return NULL; - - while (l < r) { - idx = (l + r) / 2; - comparison = (*compar)(key, elePtrAt(base, size, idx)); - if (comparison < 0) { - r = idx; - } else if (comparison > 0) { - l = idx + 1; - } else { - return elePtrAt(base, size, idx); - } - } - - if ((*compar)(key, elePtrAt(base, size, idx)) > 0) { - return elePtrAt(base, size, idx); - } else { - if (idx == 0) { - return NULL; - } else { - return elePtrAt(base, size, idx - 1); - } - } - - } else { - assert(0); - return NULL; } - return NULL; + if (flags == TD_EQ) { + return c ? NULL : p; + } else if (flags == TD_GE) { + return (c <= 0) ? p : (midx + 1 < nmemb ? p + size : NULL); + } else if (flags == TD_LE) { + return (c >= 0) ? p : (midx > 0 ? p - size : NULL); + } else { + ASSERT(0); + } } void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar, - __ext_compar_fn_t compar, char* buf, bool maxroot) { + __ext_compar_fn_t compar, char *buf, bool maxroot) { int32_t parent; int32_t child; - char* tmp = NULL; + char *tmp = NULL; if (buf == NULL) { tmp = taosMemoryMalloc(size); } else { @@ -288,7 +254,7 @@ void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, bool maxroot) { int32_t i; - char* buf = taosMemoryCalloc(1, size); + char *buf = taosMemoryCalloc(1, size); if (buf == NULL) { return; } diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index b660927899..11a1cc1c71 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -222,11 +222,6 @@ int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight) { return compareLenPrefixedWStr(pRight, pLeft); } -int32_t compareJsonContainsKey(const void* pLeft, const void* pRight) { - if(pLeft) return 0; - return 1; -} - // string > number > bool > null // ref: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison int32_t compareJsonVal(const void *pLeft, const void *pRight) { diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 8d7bc0851b..71c348f810 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -188,9 +188,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_SNODE_ALREADY_EXIST, "Snode already exists" TAOS_DEFINE_ERROR(TSDB_CODE_MND_SNODE_NOT_EXIST, "Snode not there") TAOS_DEFINE_ERROR(TSDB_CODE_MND_BNODE_ALREADY_EXIST, "Bnode already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_BNODE_NOT_EXIST, "Bnode not there") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_FEW_MNODES, "The replicas of mnode cannot less than 1") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_MNODES, "The replicas of mnode cannot exceed 3") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_CANT_DROP_MASTER, "Can't drop mnode which is leader") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_FEW_MNODES, "The replica of mnode cannot less than 1") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_MNODES, "The replica of mnode cannot exceed 3") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_CANT_DROP_LEADER, "Cannot drop mnode which is leader") // mnode-acct TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, "Account already exists") @@ -222,7 +222,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_INDEX_NOT_EXIST, "Index not exist") // mnode-vgroup TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE, "Vgroup already in dnode") TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_IN_DNODE, "Vgroup not in dnode") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_EXIST, "VGroup does not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_EXIST, "Vgroup does not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_UN_CHANGED, "Vgroup distribution has not changed") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_HAS_OFFLINE_DNODE, "Offline dnode exists") // mnode-stable TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_ALREADY_EXIST, "STable already exists") @@ -449,9 +451,89 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SCH_TIMEOUT_ERROR, "Task timeout") TAOS_DEFINE_ERROR(TSDB_CODE_QW_MSG_ERROR, "Invalid msg order") // parser -TAOS_DEFINE_ERROR(TSDB_CODE_PAR_TABLE_NOT_EXIST, "Table does not exist") -TAOS_DEFINE_ERROR(TSDB_CODE_PAR_PERMISSION_DENIED, "Permission denied") -TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTERNAL_ERROR, "Parser internal error") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_PERMISSION_DENIED, "Permission denied") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTERNAL_ERROR, "Parser internal error") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_SYNTAX_ERROR, "syntax error near") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INCOMPLETE_SQL, "Incomplete SQL statement") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_COLUMN, "Invalid column name") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_TABLE_NOT_EXIST, "Table does not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_AMBIGUOUS_COLUMN, "Column ambiguously defined") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Invalid value type") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION, "There mustn't be aggregation") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT, "ORDER BY item must be the number of a SELECT-list expression") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION, "Not a GROUP BY expression") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION, "Not SELECTed expression") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_SINGLE_GROUP, "Not a single-group group function") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_TAGS_NOT_MATCHED, "Tags number not matched") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_TAG_NAME, "Invalid tag name") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG, "Name or password too long") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_PASSWD_EMPTY, "Password can not be empty") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_PORT, "Port should be an integer that is less than 65535 and greater than 0") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_ENDPOINT, "Endpoint should be in the format of 'fqdn:port'") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_EXPRIE_STATEMENT, "This statement is no longer supported") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTER_VALUE_TOO_SMALL, "Interval too small") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_DB_NOT_SPECIFIED, "Database not specified") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, "Invalid identifier name") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR, "Corresponding super table not in this db") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_RANGE_OPTION, "Invalid option") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_STR_OPTION, "Invalid option") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_ENUM_OPTION, "Invalid option") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_KEEP_NUM, "Invalid number of keep options") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_KEEP_ORDER, "Invalid keep value, should be keep0 <= keep1 <= keep2") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_KEEP_VALUE, "Invalid option keep") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_COMMENT_OPTION, "Invalid option comment") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_F_RANGE_OPTION, "Invalid option") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_ROLLUP_OPTION, "Invalid option rollup: only one function is allowed") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION, "Invalid option retentions") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST, "GROUP BY and WINDOW-clause can't be used together") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_OPTION_UNIT, "Invalid option unit: only m, h, d allowed") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_KEEP_UNIT, "Invalid option keep unit: only m, h, d allowed") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_AGG_FUNC_NESTING, "Aggregate functions do not support nesting") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE, "Only support STATE_WINDOW on integer/bool/varchar column") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_STATE_WIN_COL, "Not support STATE_WINDOW on tag column") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_STATE_WIN_TABLE, "STATE_WINDOW not support for super table query") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTER_SESSION_GAP, "SESSION gap should be fixed time window, and greater than 0") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTER_SESSION_COL, "Only support SESSION on primary timestamp column") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTER_OFFSET_NEGATIVE, "Interval offset cannot be negative") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTER_OFFSET_UNIT, "Cannot use 'year' as offset when interval is 'month'") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTER_OFFSET_TOO_BIG, "Interval offset should be shorter than interval") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTER_SLIDING_UNIT, "Does not support sliding when interval is natural month/year") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTER_SLIDING_TOO_BIG, "sliding value no larger than the interval value") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTER_SLIDING_TOO_SMALL, "sliding value can not less than 1% of interval value") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_ONLY_ONE_JSON_TAG, "Only one tag if there is a json tag") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INCORRECT_NUM_OF_COL, "Query block has incorrect number of result columns") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INCORRECT_TIMESTAMP_VAL, "Incorrect TIMESTAMP value") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_DAYS_VALUE, "Invalid days value, should be keep2 >= keep1 >= keep0 >= days") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_OFFSET_LESS_ZERO, "soffset/offset can not be less than 0") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_SLIMIT_LEAK_PARTITION_BY, "slimit/soffset only available for PARTITION BY query") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_TOPIC_QUERY, "Invalid topic query") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_DROP_STABLE, "Cannot drop super table in batch") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE, "Start(end) time of query range required or time range too large") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_DUPLICATED_COLUMN, "Duplicated column names") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_TAGS_LENGTH, "Tags length exceeds max length") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_ROW_LENGTH, "Row length exceeds max length") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_COLUMNS_NUM, "Illegal number of columns") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_TOO_MANY_COLUMNS, "Too many columns") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_FIRST_COLUMN, "First column must be timestamp") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN, "Invalid binary/nchar column length") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_TAGS_NUM, "Invalid number of tag columns") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_INTERNAL_PK, "Invalid _c0 or _rowts expression") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_TIMELINE_FUNC, "Invalid timeline function") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_PASSWD, "Invalid password") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid alter table statement") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_CANNOT_DROP_PRIMARY_KEY, "Primary timestamp column cannot be dropped") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_MODIFY_COL, "Only binary/nchar column length could be modified") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_TBNAME, "Invalid tbname pseudo column") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_FUNCTION_NAME, "Invalid function name") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_COMMENT_TOO_LONG, "Comment too long") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_ALLOWED_FUNC, "Some functions are allowed only in the SELECT list of a query. " + "And, cannot be mixed with other non scalar functions or columns.") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY, "Window query not supported, since the result of subquery not include valid timestamp column") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_DROP_COL, "No columns can be dropped") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_COL_JSON, "Only tag can be json type") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_VALUE_TOO_LONG, "Value too long for column/tag") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_DELETE_WHERE, "The DELETE statement must have a definite time window range") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG, "The REDISTRIBUTE VGROUP statement only support 1 to 3 dnodes") //planner TAOS_DEFINE_ERROR(TSDB_CODE_PLAN_INTERNAL_ERROR, "Planner internal error") diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 101ac78e18..cdf2629671 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -651,3 +651,31 @@ void dBufPrintStatis(const SDiskbasedBuf* pBuf) { ps->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f, ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages)); } + +void clearDiskbasedBuf(SDiskbasedBuf* pBuf) { + SArray** p = taosHashIterate(pBuf->groupSet, NULL); + while (p) { + size_t n = taosArrayGetSize(*p); + for (int32_t i = 0; i < n; ++i) { + SPageInfo* pi = taosArrayGetP(*p, i); + taosMemoryFreeClear(pi->pData); + taosMemoryFreeClear(pi); + } + taosArrayDestroy(*p); + p = taosHashIterate(pBuf->groupSet, p); + } + + tdListEmpty(pBuf->lruList); + tdListEmpty(pBuf->freePgList); + + taosArrayClear(pBuf->emptyDummyIdList); + taosArrayClear(pBuf->pFree); + + taosHashClear(pBuf->groupSet); + taosHashClear(pBuf->all); + + pBuf->numOfPages = 0; // all pages are in buffer in the first place + pBuf->totalBufSize = 0; + pBuf->allocateId = -1; + pBuf->fileSize = 0; +} \ No newline at end of file diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index 37935087fa..94311bc435 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -34,11 +34,11 @@ typedef struct STaosQnode { } STaosQnode; typedef struct STaosQueue { - STaosQnode * head; - STaosQnode * tail; - STaosQueue * next; // for queue set - STaosQset * qset; // for queue set - void * ahandle; // for queue set + STaosQnode *head; + STaosQnode *tail; + STaosQueue *next; // for queue set + STaosQset *qset; // for queue set + void *ahandle; // for queue set FItem itemFp; FItems itemsFp; TdThreadMutex mutex; @@ -47,8 +47,8 @@ typedef struct STaosQueue { } STaosQueue; typedef struct STaosQset { - STaosQueue * head; - STaosQueue * current; + STaosQueue *head; + STaosQueue *current; TdThreadMutex mutex; tsem_t sem; int32_t numOfQueues; @@ -86,7 +86,7 @@ void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp) { void taosCloseQueue(STaosQueue *queue) { if (queue == NULL) return; STaosQnode *pTemp; - STaosQset * qset; + STaosQset *qset; taosThreadMutexLock(&queue->mutex); STaosQnode *pNode = queue->head; @@ -282,6 +282,8 @@ int32_t taosGetQitem(STaosQall *qall, void **ppItem) { *ppItem = pNode->item; num = 1; uTrace("item:%p is fetched", *ppItem); + } else { + *ppItem = NULL; } return num; diff --git a/source/util/test/CMakeLists.txt b/source/util/test/CMakeLists.txt index 8c0f0c76ef..d2a503e661 100644 --- a/source/util/test/CMakeLists.txt +++ b/source/util/test/CMakeLists.txt @@ -67,4 +67,12 @@ target_link_libraries(bloomFilterTest os util gtest_main) add_test( NAME bloomFilterTest COMMAND bloomFilterTest +) + +# taosbsearchTest +add_executable(taosbsearchTest "taosbsearchTest.cpp") +target_link_libraries(taosbsearchTest os util gtest_main) +add_test( + NAME taosbsearchTest + COMMAND taosbsearchTest ) \ No newline at end of file diff --git a/tests/pytest/test.py b/tests/pytest/test.py index 30ab6ae3cc..1b185ef189 100644 --- a/tests/pytest/test.py +++ b/tests/pytest/test.py @@ -131,7 +131,7 @@ if __name__ == "__main__": is_test_framework = 0 key_word = 'tdCases.addWindows' try: - if key_word in open(fileName).read(): + if key_word in open(fileName, encoding='UTF-8').read(): is_test_framework = 1 except: pass diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index b6ffda5c86..c2aed6555d 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -388,14 +388,14 @@ class TDDnode: if os.system(cmd) != 0: tdLog.exit(cmd) else: - self.remoteExec(self.cfgDict, "tdDnodes.deploy(%d,updateCfgDict)\ntdDnodes.startWithoutSleep(%d)"%(self.index, self.index)) + self.remoteExec(self.cfgDict, "tdDnodes.dnodes[%d].deployed=1\ntdDnodes.dnodes[%d].logDir=\"%%s/sim/dnode%%d/log\"%%(tdDnodes.dnodes[%d].path,%d)\ntdDnodes.dnodes[%d].cfgDir=\"%%s/sim/dnode%%d/cfg\"%%(tdDnodes.dnodes[%d].path,%d)\ntdDnodes.startWithoutSleep(%d)"%(self.index-1,self.index-1,self.index-1,self.index,self.index-1,self.index-1,self.index,self.index)) self.running = 1 tdLog.debug("dnode:%d is running with %s " % (self.index, cmd)) def stop(self): if (not self.remoteIP == ""): - self.remoteExec(self.cfgDict, "tdDnodes.stop(%d)"%self.index) + self.remoteExec(self.cfgDict, "tdDnodes.dnodes[%d].running=1\ntdDnodes.dnodes[%d].stop()"%(self.index-1,self.index-1)) tdLog.info("stop dnode%d"%self.index) return if self.valgrind == 0: @@ -416,7 +416,7 @@ class TDDnode: psCmd, shell=True).decode("utf-8") if not platform.system().lower() == 'windows': for port in range(6030, 6041): - fuserCmd = "fuser -k -n tcp %d" % port + fuserCmd = "fuser -k -n tcp %d > /dev/null" % port os.system(fuserCmd) if self.valgrind: time.sleep(2) @@ -426,7 +426,7 @@ class TDDnode: def forcestop(self): if (not self.remoteIP == ""): - self.remoteExec(self.cfgDict, "tdDnodes.forcestop(%d)"%self.index) + self.remoteExec(self.cfgDict, "tdDnodes.dnodes[%d].running=1\ntdDnodes.dnodes[%d].forcestop()"%(self.index-1,self.index-1)) return if self.valgrind == 0: toBeKilled = "taosd" @@ -497,46 +497,12 @@ class TDDnodes: self.killValgrind = 1 def init(self, path, remoteIP = ""): - psCmd = "ps -ef|grep -w taosd| grep -v grep| grep -v defunct | awk '{print $2}'" - processID = subprocess.check_output(psCmd, shell=True).decode("utf-8") - while(processID): - killCmd = "kill -9 %s > /dev/null 2>&1" % processID - os.system(killCmd) - time.sleep(1) - processID = subprocess.check_output( - psCmd, shell=True).decode("utf-8") - - if self.killValgrind == 1: - psCmd = "ps -ef|grep -w valgrind.bin| grep -v grep | awk '{print $2}'" - processID = subprocess.check_output(psCmd, shell=True).decode("utf-8") - while(processID): - killCmd = "kill -9 %s > /dev/null 2>&1" % processID - os.system(killCmd) - time.sleep(1) - processID = subprocess.check_output( - psCmd, shell=True).decode("utf-8") - binPath = self.dnodes[0].getPath() + "/../../../" # tdLog.debug("binPath %s" % (binPath)) binPath = os.path.realpath(binPath) # tdLog.debug("binPath real path %s" % (binPath)) - # cmd = "sudo cp %s/build/lib/libtaos.so /usr/local/lib/taos/" % (binPath) - # tdLog.debug(cmd) - # os.system(cmd) - - # cmd = "sudo cp %s/build/bin/taos /usr/local/bin/taos/" % (binPath) - # if os.system(cmd) != 0 : - # tdLog.exit(cmd) - # tdLog.debug("execute %s" % (cmd)) - - # cmd = "sudo cp %s/build/bin/taosd /usr/local/bin/taos/" % (binPath) - # if os.system(cmd) != 0 : - # tdLog.exit(cmd) - # tdLog.debug("execute %s" % (cmd)) - if path == "": - # self.path = os.path.expanduser('~') self.path = os.path.abspath(binPath + "../../") else: self.path = os.path.realpath(path) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 32056e8d0c..28bc98a972 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -21,7 +21,7 @@ ./test.sh -f tsim/db/taosdlog.sim # ---- dnode -./test.sh -f tsim/dnode/basic1.sim +./test.sh -f tsim/dnode/create_dnode.sim # ---- insert ./test.sh -f tsim/insert/basic0.sim @@ -72,6 +72,10 @@ ./test.sh -f tsim/stream/basic2.sim # ./test.sh -f tsim/stream/session0.sim # ./test.sh -f tsim/stream/session1.sim +# ./test.sh -f tsim/stream/state0.sim +# ./test.sh -f tsim/stream/triggerInterval0.sim +# ./test.sh -f tsim/stream/triggerSession0.sim + # ---- transaction ./test.sh -f tsim/trans/lossdata1.sim diff --git a/tests/script/tsim/dnode/basic1.sim b/tests/script/tsim/dnode/create_dnode.sim similarity index 96% rename from tests/script/tsim/dnode/basic1.sim rename to tests/script/tsim/dnode/create_dnode.sim index a5b5427e03..8a28897d5a 100644 --- a/tests/script/tsim/dnode/basic1.sim +++ b/tests/script/tsim/dnode/create_dnode.sim @@ -183,15 +183,15 @@ if $rows != 15 then endi print =============== drop dnode -sql drop dnode 2; -sql show dnodes; -if $rows != 1 then - return -1 -endi +#sql drop dnode 2; +#sql show dnodes; +#if $rows != 1 then +# return -1 +#endi -if $data00 != 1 then - return -1 -endi +#if $data00 != 1 then +# return -1 +#endi system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT diff --git a/tests/script/tsim/query/complex_having.sim b/tests/script/tsim/query/complex_having.sim index ef58228f34..6a4aa6ea28 100644 --- a/tests/script/tsim/query/complex_having.sim +++ b/tests/script/tsim/query/complex_having.sim @@ -105,7 +105,7 @@ endi sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; print ====> rows: $rows -if $rows != 7 then +if $rows != 8 then return -1 endi @@ -214,9 +214,9 @@ print =================== count all rows sql select count(c1) from stb1 print ====> sql : select count(c1) from stb1 print ====> rows: $data00 -if $data00 != 20 then - print expect 20, actual: $data00 - return -1 +if $data00 != 17 then + print expect 17, actual: $data00 + return -1 endi #================================================= @@ -246,7 +246,7 @@ print =================== count all rows sql select count(c1) from stb1 print ====> sql : select count(c1) from stb1 print ====> rows: $data00 -if $data00 != 20 then +if $data00 != 17 then return -1 endi @@ -279,7 +279,7 @@ endi sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; print ====> rows: $rows -if $rows != 7 then +if $rows != 8 then return -1 endi diff --git a/tests/script/tsim/query/crash_sql.sim b/tests/script/tsim/query/crash_sql.sim index 44671fbb0d..b2b9239232 100644 --- a/tests/script/tsim/query/crash_sql.sim +++ b/tests/script/tsim/query/crash_sql.sim @@ -25,7 +25,7 @@ sql connect print =============== create database sql create database db sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi @@ -96,8 +96,6 @@ sql insert into ct4 values ( '2022-05-21 01:01:01.000', NULL, NULL, NULL, NULL, print ================ start query ====================== print ================ SQL used to cause taosd or taos shell crash -sql select sum(c1) ,count(c1) from ct4 group by c1 having sum(c10) between 0 and 1 ; - - +sql_error select sum(c1) ,count(c1) from ct4 group by c1 having sum(c10) between 0 and 1 ; #system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/explain.sim b/tests/script/tsim/query/explain.sim index 2b0d52d253..c853022281 100644 --- a/tests/script/tsim/query/explain.sim +++ b/tests/script/tsim/query/explain.sim @@ -42,14 +42,12 @@ sql explain select count(*),sum(f1) from tb1; sql explain select count(*),sum(f1) from st1; sql explain select count(*),sum(f1) from st1 group by f1; #sql explain select count(f1) from tb1 interval(10s, 2s) sliding(3s) fill(prev); -sql explain select min(f1) from st1 interval(1m, 2a) sliding(30s); print ======== step3 sql explain verbose true select * from st1 where -2; sql explain verbose true select ts from tb1 where f1 > 0; sql explain verbose true select * from st1 where f1 > 0 and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00'; sql explain verbose true select * from information_schema.user_stables where db_name='db2'; -sql explain verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; print ======== step4 sql explain analyze select ts from st1 where -2; @@ -61,8 +59,6 @@ sql explain analyze select * from information_schema.user_stables; sql explain analyze select count(*),sum(f1) from tb1; sql explain analyze select count(*),sum(f1) from st1; sql explain analyze select count(*),sum(f1) from st1 group by f1; -#sql explain analyze select count(f1) from tb1 interval(10s, 2s) sliding(3s) fill(prev); -sql explain analyze select min(f1) from st1 interval(3m, 2a) sliding(1m); print ======== step5 sql explain analyze verbose true select ts from st1 where -2; @@ -78,8 +74,6 @@ sql explain analyze verbose true select count(*),sum(f1) from st1 group by f1; sql explain analyze verbose true select ts from tb1 where f1 > 0; sql explain analyze verbose true select f1 from st1 where f1 > 0 and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00'; sql explain analyze verbose true select * from information_schema.user_stables where db_name='db2'; -sql explain analyze verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; -sql explain analyze verbose true select min(f1) from st1 interval(3m, 2a) sliding(1m); sql explain analyze verbose true select * from (select min(f1),count(*) a from st1 where f1 > 0) where a < 0; #not pass case @@ -93,6 +87,12 @@ sql explain analyze verbose true select * from (select min(f1),count(*) a from s #sql explain select * from tb1, tb2 where tb1.ts=tb2.ts; #sql explain select * from st1, st2 where tb1.ts=tb2.ts; #sql explain analyze verbose true select sum(a+b) from (select _rowts, min(f1) b,count(*) a from st1 where f1 > 0 interval(1a)) where a < 0 interval(1s); +#sql explain select min(f1) from st1 interval(1m, 2a) sliding(30s); +#sql explain verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; +#sql explain analyze select min(f1) from st1 interval(3m, 2a) sliding(1m); +#sql explain analyze select count(f1) from tb1 interval(10s, 2s) sliding(3s) fill(prev); +#sql explain analyze verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; +#sql explain analyze verbose true select min(f1) from st1 interval(3m, 2a) sliding(1m); system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/query/scalarNull.sim b/tests/script/tsim/query/scalarNull.sim index b08ac1d3d9..07bd5e57cd 100644 --- a/tests/script/tsim/query/scalarNull.sim +++ b/tests/script/tsim/query/scalarNull.sim @@ -66,6 +66,7 @@ if $rows != 0 then return -1 endi sql select * from tb1 where null; +print $rows if $rows != 0 then return -1 endi diff --git a/tests/script/tsim/stable/column_drop.sim b/tests/script/tsim/stable/column_drop.sim index 3401465103..63ac44eccd 100644 --- a/tests/script/tsim/stable/column_drop.sim +++ b/tests/script/tsim/stable/column_drop.sim @@ -118,6 +118,7 @@ if $data[0][5] != 5 then return -1 endi if $data[0][6] != 101 then + print expect 101, actual: $data06 return -1 endi diff --git a/tests/script/tsim/stable/tag_filter.sim b/tests/script/tsim/stable/tag_filter.sim index c8edfb1ee3..04b8f21de9 100644 --- a/tests/script/tsim/stable/tag_filter.sim +++ b/tests/script/tsim/stable/tag_filter.sim @@ -31,6 +31,7 @@ if $rows != 1 then return -1 endi + sql select * from db.stb where t1 < 1 if $rows != 0 then return -=1 @@ -56,4 +57,21 @@ if $rows != 5 then return -1 endi +sql select * from db.stb where t1 between 1 and 1 +if $rows != 1 then + return -1 +endi + +sql select * from db.stb where t1 between 1 and 6 +if $rows != 6 then + return -1 +endi + +sql select * from db.stb where t1 between 1 and 7 +if $rows != 6 then + return -1 +endi + + + system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/stream/session0.sim b/tests/script/tsim/stream/session0.sim index a5cd73d17e..a2fe773edb 100644 --- a/tests/script/tsim/stream/session0.sim +++ b/tests/script/tsim/stream/session0.sim @@ -23,89 +23,98 @@ sql insert into t1 values(1648791223001,10,2,3,1.1,2); sql insert into t1 values(1648791233002,3,2,3,2.1,3); sql insert into t1 values(1648791243003,NULL,NULL,NULL,NULL,4); sql insert into t1 values(1648791213002,NULL,NULL,NULL,NULL,5) (1648791233012,NULL,NULL,NULL,NULL,6); + +$loop_count = 0 +loop0: + sleep 300 sql select * from streamt order by s desc; +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + # row 0 if $data01 != 3 then - print ======$data01 - return -1 + print ======data01=$data01 + goto loop0 endi if $data02 != 3 then - print ======$data02 - return -1 + print ======data02=$data02 + goto loop0 endi if $data03 != 3 then - print ======$data03 - return -1 + print ======data03=$data03 + goto loop0 endi if $data04 != 2.100000000 then - print ======$data04 + print ======data04=$data04 return -1 endi if $data05 != 0.000000000 then - print ======$data05 + print ======data05=$data05 return -1 endi if $data06 != 3 then - print ======$data05 + print ======data06=$data06 return -1 endi if $data07 != 2.100000000 then - print ======$data05 + print ======data07=$data07 return -1 endi if $data08 != 6 then - print ======$data05 + print ======data08=$data08 return -1 endi # row 1 if $data11 != 3 then - print ======$data11 - return -1 + print ======data11=$data11 + goto loop0 endi if $data12 != 10 then - print ======$data12 - return -1 + print ======data12=$data12 + goto loop0 endi if $data13 != 10 then - print ======$data13 - return -1 + print ======data13=$data13 + goto loop0 endi if $data14 != 1.100000000 then - print ======$data14 + print ======data14=$data14 return -1 endi if $data15 != 0.000000000 then - print ======$data15 + print ======data15=$data15 return -1 endi if $data16 != 10 then - print ======$data15 + print ======data16=$data16 return -1 endi if $data17 != 1.100000000 then - print ======$data17 + print ======data17=$data17 return -1 endi if $data18 != 5 then - print ======$data18 + print ======data18=$data18 return -1 endi @@ -115,23 +124,31 @@ sql insert into t1 values(1648791233002,3,2,3,2.1,9); sql insert into t1 values(1648791243003,4,2,3,3.1,10); sql insert into t1 values(1648791213002,4,2,3,4.1,11) ; sql insert into t1 values(1648791213002,4,2,3,4.1,12) (1648791223009,4,2,3,4.1,13); + +$loop_count = 0 +loop1: sleep 300 sql select * from streamt order by s desc ; +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + # row 0 if $data01 != 7 then - print ======$data01 - return -1 + print =====data01=$data01 + goto loop1 endi if $data02 != 9 then - print ======$data02 - return -1 + print =====data02=$data02 + goto loop1 endi if $data03 != 4 then - print ======$data03 - return -1 + print =====data03=$data03 + goto loop1 endi if $data04 != 1.100000000 then diff --git a/tests/script/tsim/stream/state0.sim b/tests/script/tsim/stream/state0.sim index 3529f836f4..2f2038b914 100644 --- a/tests/script/tsim/stream/state0.sim +++ b/tests/script/tsim/stream/state0.sim @@ -20,21 +20,33 @@ sql create stream streams1 trigger at_once into streamt1 as select _wstartts, sql insert into t1 values(1648791213000,1,2,3,1.0,1); sql insert into t1 values(1648791213000,1,2,3,1.0,2); +$loop_count = 0 +loop0: sql select * from streamt1 order by c desc; sleep 300 +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi if $rows != 1 then - print ======$rows - return -1; + print =====rows=$rows + goto loop0 endi sql insert into t1 values(1648791214000,1,2,3,1.0,3); +$loop_count = 0 +loop00: sql select * from streamt1 order by c desc; sleep 300 +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi if $rows != 1 then - print ======$rows - return -1; + print =====rows=$rows + goto loop00 endi sql insert into t1 values(1648791213010,2,2,3,1.0,4); @@ -44,27 +56,25 @@ $loop_count = 0 loop1: sql select * from streamt1 where c >=4 order by `_wstartts`; sleep 300 - $loop_count = $loop_count + 1 if $loop_count == 10 then return -1 endi if $rows != 3 then - print ======$rows + print =====rows=$rows goto loop1 - return -1 endi # row 0 if $data01 != 1 then - print ======$data01 - return -1 + print =====data01=$data01 + goto loop1 endi if $data02 != 1 then - print ======$data02 - return -1 + print =====data02=$data02 + goto loop1 endi if $data03 != 1 then @@ -151,11 +161,10 @@ endi sql insert into t1 values(1648791213011,1,2,3,1.0,7); -loop2: $loop_count = 0 +loop2: sql select * from streamt1 where c in (5,4,7) order by `_wstartts`; sleep 300 - $loop_count = $loop_count + 1 if $loop_count == 10 then return -1 @@ -163,57 +172,51 @@ endi # row 2 if $data21 != 2 then - print ======$data21 + print =====data21=$data21 goto loop2 return -1 endi if $data22 != 2 then - print ======$data22 + print =====data22=$data22 goto loop2 return -1 endi if $data23 != 2 then print ======$data23 - goto loop2 return -1 endi if $data24 != 1 then print ======$data24 - goto loop2 return -1 endi if $data25 != 3 then print ======$data25 - goto loop2 return -1 endi if $data26 != 7 then print ======$data26 - goto loop2 return -1 endi sql insert into t1 values(1648791213011,1,2,3,1.0,8); -loop21: $loop_count = 0 +loop21: sql select * from streamt1 where c in (5,4,8) order by `_wstartts`; sleep 300 - $loop_count = $loop_count + 1 if $loop_count == 10 then return -1 endi if $data26 != 8 then - print ======$data26 + print =====data26=$data26 goto loop21 - return -1 endi @@ -222,11 +225,10 @@ sql insert into t1 values(1648791213020,3,2,3,1.0,10); sql insert into t1 values(1648791214000,1,2,3,1.0,11); sql insert into t1 values(1648791213011,10,20,10,10.0,12); -loop3: $loop_count = 0 +loop3: sql select * from streamt1 where c in (5,4,10,11,12) order by `_wstartts`; sleep 300 - $loop_count = $loop_count + 1 if $loop_count == 10 then return -1 @@ -234,112 +236,100 @@ endi # row 2 if $data21 != 1 then - print ======$data21 + print =====data21=$data21 goto loop3 return -1 endi if $data22 != 1 then - print ======$data22 + print =====data22=$data22 goto loop3 return -1 endi if $data23 != 10 then print ======$data23 - goto loop3 return -1 endi if $data24 != 10 then print ======$data24 - goto loop3 return -1 endi if $data25 != 10 then print ======$data25 - goto loop3 return -1 endi if $data26 != 12 then print ======$data26 - goto loop3 return -1 endi # row 3 if $data31 != 1 then - print ======$data31 + print =====data31=$data31 goto loop3 return -1 endi if $data32 != 1 then - print ======$data32 + print =====data32=$data32 goto loop3 return -1 endi if $data33 != 3 then print ======$data33 - goto loop3 return -1 endi if $data34 != 3 then print ======$data34 - goto loop3 return -1 endi if $data35 != 3 then print ======$data35 - goto loop3 return -1 endi if $data36 != 10 then print ======$data36 - goto loop3 return -1 endi # row 4 if $data41 != 1 then - print ======$data41 + print =====data41=$data41 goto loop3 return -1 endi if $data42 != 1 then - print ======$data42 + print =====data42=$data42 goto loop3 return -1 endi if $data43 != 1 then print ======$data43 - goto loop3 return -1 endi if $data44 != 1 then print ======$data44 - goto loop3 return -1 endi if $data45 != 3 then print ======$data45 - goto loop3 return -1 endi if $data46 != 11 then print ======$data46 - goto loop3 return -1 endi @@ -347,8 +337,8 @@ sql insert into t1 values(1648791213030,3,12,12,12.0,13); sql insert into t1 values(1648791214040,1,13,13,13.0,14); sql insert into t1 values(1648791213030,3,14,14,14.0,15) (1648791214020,15,15,15,15.0,16); -loop4: $loop_count = 0 +loop4: sql select * from streamt1 where c in (14,15,16) order by `_wstartts`; sleep 300 @@ -358,119 +348,104 @@ if $loop_count == 10 then endi if $rows != 3 then - print ======$rows - goto loop4 - return -1; + print ====loop4=rows=$rows +# goto loop4 endi # row 0 if $data01 != 2 then - print ======$data01 + print =====data01=$data01 goto loop4 - return -1 endi if $data02 != 2 then print ======$data02 - goto loop4 return -1 endi if $data03 != 6 then print ======$data03 - goto loop4 return -1 endi if $data04 != 3 then print ======$data04 - goto loop4 return -1 endi if $data05 != 3 then print ======$data05 - goto loop4 return -1 endi if $data06 != 15 then print ======$data06 - goto loop4 return -1 endi # row 1 if $data11 != 1 then - print ======$data11 + print =====data11=$data11 goto loop4 return -1 endi if $data12 != 1 then - print ======$data12 + print =====data12=$data12 goto loop4 return -1 endi if $data13 != 15 then print ======$data13 - goto loop4 return -1 endi if $data14 != 15 then print ======$data14 - goto loop4 return -1 endi if $data15 != 15 then print ======$data15 - goto loop4 return -1 endi if $data16 != 16 then print ======$data16 - goto loop4 return -1 endi # row 2 if $data21 != 1 then - print ======$data21 + print =====data21=$data21 goto loop4 return -1 endi if $data22 != 1 then - print ======$data22 + print =====data22=$data22 goto loop4 return -1 endi if $data23 != 1 then print ======$data23 - goto loop4 return -1 endi if $data24 != 1 then print ======$data24 - goto loop4 return -1 endi if $data25 != 13 then print ======$data25 - goto loop4 return -1 endi if $data26 != 14 then print ======$data26 - goto loop4 return -1 endi diff --git a/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim b/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim index 06a67b3c1b..b816226cff 100644 --- a/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim +++ b/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim @@ -31,7 +31,7 @@ if $data[0][4] != ready then goto check_dnode_ready endi -#sql connect +sql connect sql create dnode $hostname port 7200 sql create dnode $hostname port 7300 sql create dnode $hostname port 7400 @@ -71,7 +71,7 @@ sql create database db replica $replica vgroups $vgroups $loop_cnt = 0 check_db_ready: $loop_cnt = $loop_cnt + 1 -sleep 200 +sleep 20 if $loop_cnt == 10 then print ====> db not ready! return -1 @@ -93,13 +93,12 @@ $loop_cnt = 0 check_vg_ready: $loop_cnt = $loop_cnt + 1 sleep 200 -if $loop_cnt == 10 then +if $loop_cnt == 300 then print ====> vgroups not ready! return -1 endi sql show vgroups print ===> rows: $rows -print $data(2)[0] $data(2)[1] $data(2)[2] $data(2)[3] $data(2)[4] $data(2)[5] $data(2)[6] $data(2)[7] $data(2)[8] $data(2)[9] $data(2)[10] $data(2)[11] $data(2)[12] $data(2)[13] print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[10][6] $data[0][11] $data[0][12] $data[0][13] if $rows != $vgroups then return -1 @@ -132,10 +131,12 @@ if $data[0][8] == leader then goto check_vg_ready endi print ---- vgroup $data[0][0] leader locate on dnode $data[0][7] - goto vg_ready + goto vg_ready +else + goto check_vg_ready endi -vg_ready: +vg_ready: print ====> create stable/child table sql create table stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) @@ -156,27 +157,13 @@ while $i < $tbNum sql create table $ctb using stb tags( $i ) $ntb = $ntbPrefix . $i sql create table $ntb (ts timestamp, c1 int, c2 float, c3 binary(10)) - -# $x = 0 -# while $x < $rowNum -# $binary = ' . binary -# $binary = $binary . $i -# $binary = $binary . ' -# -# sql insert into $ctb values ($tstart , $i , $x , $binary ) -# sql insert into $ntb values ($tstart , 999 , 999 , 'binary-ntb' ) -# $tstart = $tstart + 1 -# $x = $x + 1 -# endw - -# print ====> insert rows: $rowNum into $ctb and $ntb - $i = $i + 1 -# $tstart = 1640966400000 endw $totalTblNum = $tbNum * 2 +sleep 1000 sql show tables +print ====> expect $totalTblNum and infinsert $rows in fact if $rows != $totalTblNum then return -1 endi @@ -185,7 +172,7 @@ print ====> create a normal table for interaction between main and back threads sql create table interaction (ts timestamp, flag binary(10), childrows int, stbrows int) print ====> start to run_back to insert data -run_back tsim/tmq/insertDataByRunBack.sim +run_back tsim/sync/insertDataByRunBack.sim print ====> waiting insert thread starting insert data @@ -222,12 +209,15 @@ endi $dnodeId = dnode . $dnodeId print ====> stop $dnodeId system sh/exec.sh -n $dnodeId -s stop -x SIGINT +sleep 1000 +print ====> start $dnodeId +system sh/exec.sh -n $dnodeId -s start $loop_cnt = 0 check_vg_ready_2: $loop_cnt = $loop_cnt + 1 sleep 200 -if $loop_cnt == 10 then +if $loop_cnt == 300 then print ====> vgroups switch fail!!! return -1 endi @@ -242,38 +232,38 @@ if $data[0][4] == leader then if $data[0][6] != NULL then goto check_vg_ready_2 endi - if $data[0][8] != NULL then + if $data[0][8] != FOLLOWER then goto check_vg_ready_2 endi - print ---- vgroup $data[0][0] leader switch to dnode $data[0][3] + print ---- vgroup $dnodeId leader switch to dnode $data[0][3] goto vg_ready_2 endi if $data[0][6] == leader then if $data[0][4] != NULL then goto check_vg_ready_2 endi - if $data[0][8] != NULL then + if $data[0][8] != FOLLOWER then goto check_vg_ready_2 endi - print ---- vgroup $data[0][0] leader switch to dnode $data[0][5] + print ---- vgroup $dnodeId leader switch to dnode $data[0][5] goto vg_ready_2 endi if $data[0][8] == leader then if $data[0][4] != NULL then goto check_vg_ready_2 endi - if $data[0][6] != NULL then + if $data[0][6] != FOLLOWER then goto check_vg_ready_2 endi - print ---- vgroup $data[0][0] leader switch to dnode $data[0][7] + print ---- vgroup $dnodeId leader switch to dnode $data[0][7] goto vg_ready_2 +else + goto check_vg_ready_2 endi vg_ready_2: $switch_loop_cnt = $switch_loop_cnt + 1 if $switch_loop_cnt < 3 then - print ====> start $dnodeId - system sh/exec.sh -n $dnodeId -s start goto switch_leader_loop endi @@ -347,7 +337,7 @@ if $data[0][4] == leader then if $data[0][6] != NULL then goto check_vg_ready_1 endi - if $data[0][8] != NULL then + if $data[0][8] != FOLLOWER then goto check_vg_ready_1 endi goto vg_ready_1 @@ -356,7 +346,7 @@ if $data[0][6] == leader then if $data[0][4] != NULL then goto check_vg_ready_1 endi - if $data[0][8] != NULL then + if $data[0][8] != FOLLOWER then goto check_vg_ready_1 endi goto vg_ready_1 @@ -365,7 +355,7 @@ if $data[0][8] == leader then if $data[0][4] != NULL then goto check_vg_ready_1 endi - if $data[0][6] != NULL then + if $data[0][6] != FOLLOWER then goto check_vg_ready_1 endi goto vg_ready_1 @@ -394,6 +384,73 @@ if $data[0][0] != $totalRowsOfStb then return -1 endi +print ====> once stop one dnode by loop, and do query every time +$i = 2 +loop_stop_dnode: +$dnodeId = dnode . $i +print ====> stop $dnodeId +system sh/exec.sh -n $dnodeId -s stop -x SIGINT + +check_vg_ready_3: +sql show vgroups +print $data(2)[0] $data(2)[1] $data(2)[2] $data(2)[3] $data(2)[4] $data(2)[5] $data(2)[6] $data(2)[7] $data(2)[8] $data(2)[9] $data(2)[10] $data(2)[11] $data(2)[12] $data(2)[13] +if $data[0][4] == LEADER then + if $data[0][6] == LEADER then + goto check_vg_ready_3 + endi + if $data[0][8] == LEADER then + goto check_vg_ready_3 + endi + print ---- vgroup $data[0][0] leader locating dnode $data[0][5] +elif $data[0][6] == LEADER then + if $data[0][4] == LEADER then + goto check_vg_ready_3 + endi + if $data[0][8] == LEADER then + goto check_vg_ready_3 + endi + print ---- vgroup $data[0][0] leader locating dnode $data[0][7] +elif $data[0][8] == LEADER then + if $data[0][4] == LEADER then + goto check_vg_ready_3 + endi + if $data[0][6] == LEADER then + goto check_vg_ready_3 + endi + print ---- vgroup $data[0][0] leader locating dnode $data[0][9] +else + print ====> no leader vnode!!! + return -1 +endi + +sql select count(*) from ntb0 +print rows: $rows +print $data[0][0] $data[0][1] +if $data[0][0] != $totalRowsOfCtb then + return -1 +endi + +sql select count(*) from ctb0 +print rows: $rows +print $data[0][0] $data[0][1] +if $data[0][0] != $totalRowsOfCtb then + return -1 +endi + +sql select count(*) from stb +print rows: $rows +print $data[0][0] $data[0][1] +if $data[0][0] != $totalRowsOfStb then + return -1 +endi + +$i = $i + 1 +if $i <= 4 then + print ====> start $dnodeId + system sh/exec.sh -n $dnodeId -s start + goto loop_stop_dnode +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec.sh -n dnode3 -s stop -x SIGINT diff --git a/tests/script/tsim/testsuit.sim b/tests/script/tsim/testsuit.sim index c73efde9d5..1f258028cc 100644 --- a/tests/script/tsim/testsuit.sim +++ b/tests/script/tsim/testsuit.sim @@ -7,57 +7,57 @@ #run tsim/table/basic1.sim #run tsim/trans/lossdata1.sim #run tsim/trans/create_db.sim -##run tsim/stable/alter_metrics.sim -##run tsim/stable/tag_modify.sim -##run tsim/stable/alter_comment.sim -##run tsim/stable/column_drop.sim -##run tsim/stable/column_modify.sim -##run tsim/stable/tag_rename.sim +#run tsim/stable/alter_metrics.sim +#run tsim/stable/tag_modify.sim +#run tsim/stable/alter_comment.sim +#run tsim/stable/column_drop.sim +#run tsim/stable/column_modify.sim +#run tsim/stable/tag_rename.sim #run tsim/stable/vnode3.sim #run tsim/stable/metrics.sim -##run tsim/stable/alter_insert2.sim +#run tsim/stable/alter_insert2.sim #run tsim/stable/show.sim #run tsim/stable/alter_import.sim -##run tsim/stable/tag_add.sim +#run tsim/stable/tag_add.sim #run tsim/stable/tag_drop.sim #run tsim/stable/column_add.sim #run tsim/stable/alter_count.sim #run tsim/stable/values.sim -#run tsim/stable/dnode3.sim +run tsim/stable/dnode3.sim #run tsim/stable/alter_insert1.sim #run tsim/stable/refcount.sim #run tsim/stable/disk.sim -#run tsim/db/basic1.sim -#run tsim/db/basic3.sim -##run tsim/db/basic7.sim -#run tsim/db/basic6.sim -#run tsim/db/create_all_options.sim -#run tsim/db/basic2.sim -#run tsim/db/error1.sim -#run tsim/db/taosdlog.sim -#run tsim/db/alter_option.sim -#run tsim/mnode/basic1.sim -#run tsim/mnode/basic3.sim -#run tsim/mnode/basic2.sim -#run tsim/parser/fourArithmetic-basic.sim -#run tsim/parser/groupby-basic.sim -#run tsim/snode/basic1.sim -#run tsim/query/time_process.sim -#run tsim/query/stddev.sim -#run tsim/query/interval-offset.sim -#run tsim/query/charScalarFunction.sim -#run tsim/query/complex_select.sim -#run tsim/query/explain.sim -#run tsim/query/crash_sql.sim -#run tsim/query/diff.sim -#run tsim/query/complex_limit.sim -#run tsim/query/complex_having.sim -#run tsim/query/udf.sim -#run tsim/query/complex_group.sim -#run tsim/query/interval.sim -#run tsim/query/session.sim -#run tsim/query/scalarFunction.sim -##run tsim/query/scalarNull.sim +run tsim/db/basic1.sim +run tsim/db/basic3.sim +#run tsim/db/basic7.sim +run tsim/db/basic6.sim +run tsim/db/create_all_options.sim +run tsim/db/basic2.sim +run tsim/db/error1.sim +run tsim/db/taosdlog.sim +run tsim/db/alter_option.sim +run tsim/mnode/basic1.sim +run tsim/mnode/basic3.sim +run tsim/mnode/basic2.sim +run tsim/parser/fourArithmetic-basic.sim +run tsim/parser/groupby-basic.sim +run tsim/snode/basic1.sim +run tsim/query/time_process.sim +run tsim/query/stddev.sim +run tsim/query/interval-offset.sim +run tsim/query/charScalarFunction.sim +run tsim/query/complex_select.sim +run tsim/query/explain.sim +run tsim/query/crash_sql.sim +run tsim/query/diff.sim +run tsim/query/complex_limit.sim +run tsim/query/complex_having.sim +run tsim/query/udf.sim +run tsim/query/complex_group.sim +run tsim/query/interval.sim +run tsim/query/session.sim +run tsim/query/scalarFunction.sim +#run tsim/query/scalarNull.sim run tsim/query/complex_where.sim run tsim/tmq/basic1.sim run tsim/tmq/basic4.sim diff --git a/tests/system-test/0-others/taosShellNetChk.py b/tests/system-test/0-others/taosShellNetChk.py index 3c99ddb8d6..22c9c8c0c5 100644 --- a/tests/system-test/0-others/taosShellNetChk.py +++ b/tests/system-test/0-others/taosShellNetChk.py @@ -187,50 +187,51 @@ class TDTestCase: # stop taosd tdDnodes.stop(1) - role = 'server' - if platform.system().lower() == 'windows': - taosCmd = 'mintty -h never -w hide ' + buildPath + '\\build\\bin\\taos.exe -c ' + keyDict['c'] - taosCmd = taosCmd.replace('\\','\\\\') - taosCmd = taosCmd + ' -n ' + role - else: - taosCmd = 'nohup ' + buildPath + '/build/bin/taos -c ' + keyDict['c'] - taosCmd = taosCmd + ' -n ' + role + ' > /dev/null 2>&1 &' - print (taosCmd) - os.system(taosCmd) + try: + role = 'server' + if platform.system().lower() == 'windows': + taosCmd = 'mintty -h never -w hide ' + buildPath + '\\build\\bin\\taos.exe -c ' + keyDict['c'] + taosCmd = taosCmd.replace('\\','\\\\') + taosCmd = taosCmd + ' -n ' + role + else: + taosCmd = 'nohup ' + buildPath + '/build/bin/taos -c ' + keyDict['c'] + taosCmd = taosCmd + ' -n ' + role + ' > /dev/null 2>&1 &' + print (taosCmd) + os.system(taosCmd) - pktLen = '2000' - pktNum = '10' - role = 'client' - if platform.system().lower() == 'windows': - taosCmd = buildPath + '\\build\\bin\\taos.exe -h 127.0.0.1 -c ' + keyDict['c'] - taosCmd = taosCmd.replace('\\','\\\\') - else: - taosCmd = buildPath + '/build/bin/taos -c ' + keyDict['c'] - taosCmd = taosCmd + ' -n ' + role + ' -l ' + pktLen + ' -N ' + pktNum - print (taosCmd) - child = taosExpect.spawn(taosCmd, timeout=3) - i = child.expect([taosExpect.TIMEOUT, taosExpect.EOF], timeout=6) + pktLen = '2000' + pktNum = '10' + role = 'client' + if platform.system().lower() == 'windows': + taosCmd = buildPath + '\\build\\bin\\taos.exe -h 127.0.0.1 -c ' + keyDict['c'] + taosCmd = taosCmd.replace('\\','\\\\') + else: + taosCmd = buildPath + '/build/bin/taos -c ' + keyDict['c'] + taosCmd = taosCmd + ' -n ' + role + ' -l ' + pktLen + ' -N ' + pktNum + print (taosCmd) + child = taosExpect.spawn(taosCmd, timeout=3) + i = child.expect([taosExpect.TIMEOUT, taosExpect.EOF], timeout=6) - if platform.system().lower() == 'windows': - retResult = child.before - else: - retResult = child.before.decode() - print("expect() return code: %d, content:\n %s\n"%(i, retResult)) - #print(child.after.decode()) - if i == 0: - tdLog.exit('taos -n server fail!') - - expectString1 = 'response is received, size:' + pktLen - expectSTring2 = pktNum + '/' + pktNum - if expectString1 in retResult and expectSTring2 in retResult: - tdLog.info("taos -n client success") - else: - tdLog.exit('taos -n client fail!') - - if platform.system().lower() == 'windows': - os.system('ps -a | grep taos | awk \'{print $2}\' | xargs kill -9') - else: - os.system('pkill taos') + if platform.system().lower() == 'windows': + retResult = child.before + else: + retResult = child.before.decode() + print("expect() return code: %d, content:\n %s\n"%(i, retResult)) + #print(child.after.decode()) + if i == 0: + tdLog.exit('taos -n server fail!') + + expectString1 = 'response is received, size:' + pktLen + expectSTring2 = pktNum + '/' + pktNum + if expectString1 in retResult and expectSTring2 in retResult: + tdLog.info("taos -n client success") + else: + tdLog.exit('taos -n client fail!') + finally: + if platform.system().lower() == 'windows': + os.system('ps -a | grep taos | awk \'{print $2}\' | xargs kill -9') + else: + os.system('pkill taos') def stop(self): tdSql.close() diff --git a/tests/system-test/0-others/taosdMonitor.py b/tests/system-test/0-others/taosdMonitor.py index a219c54e59..4c5a434f0c 100644 --- a/tests/system-test/0-others/taosdMonitor.py +++ b/tests/system-test/0-others/taosdMonitor.py @@ -8,6 +8,7 @@ import http.server import gzip import threading import json +import pickle from util.log import * from util.sql import * @@ -15,206 +16,203 @@ from util.cases import * from util.dnodes import * telemetryPort = '6043' +serverPort = '7080' +hostname = socket.gethostname() +class RequestHandlerImpl(http.server.BaseHTTPRequestHandler): + hostPort = hostname + ":" + serverPort -def telemetryInfoCheck(infoDict=''): + def telemetryInfoCheck(self, infoDict=''): + if "ts" not in infoDict or len(infoDict["ts"]) == 0: + tdLog.exit("ts is null!") - hostname = socket.gethostname() - serverPort = 7080 + if "dnode_id" not in infoDict or infoDict["dnode_id"] != 1: + tdLog.exit("dnode_id is null!") - if "ts" not in infoDict or len(infoDict["ts"]) == 0: - tdLog.exit("ts is null!") + if "dnode_ep" not in infoDict: + tdLog.exit("dnode_ep is null!") - if "dnode_id" not in infoDict or infoDict["dnode_id"] != 1: - tdLog.exit("dnode_id is null!") + if "cluster_id" not in infoDict: + tdLog.exit("cluster_id is null!") - if "dnode_ep" not in infoDict: - tdLog.exit("dnode_ep is null!") + if "protocol" not in infoDict or infoDict["protocol"] != 1: + tdLog.exit("protocol is null!") - if "cluster_id" not in infoDict: - tdLog.exit("cluster_id is null!") + if "cluster_info" not in infoDict : + tdLog.exit("cluster_info is null!") - if "protocol" not in infoDict or infoDict["protocol"] != 1: - tdLog.exit("protocol is null!") + # cluster_info ==================================== - if "cluster_info" not in infoDict : - tdLog.exit("cluster_info is null!") + if "first_ep" not in infoDict["cluster_info"] or infoDict["cluster_info"]["first_ep"] == None: + tdLog.exit("first_ep is null!") - # cluster_info ==================================== + if "first_ep_dnode_id" not in infoDict["cluster_info"] or infoDict["cluster_info"]["first_ep_dnode_id"] != 1: + tdLog.exit("first_ep_dnode_id is null!") - if "first_ep" not in infoDict["cluster_info"] or infoDict["cluster_info"]["first_ep"] == None: - tdLog.exit("first_ep is null!") - - if "first_ep_dnode_id" not in infoDict["cluster_info"] or infoDict["cluster_info"]["first_ep_dnode_id"] != 1: - tdLog.exit("first_ep_dnode_id is null!") - - if "version" not in infoDict["cluster_info"] or infoDict["cluster_info"]["version"] == None: - tdLog.exit("first_ep_dnode_id is null!") - - if "master_uptime" not in infoDict["cluster_info"] or infoDict["cluster_info"]["master_uptime"] == None: - tdLog.exit("master_uptime is null!") - - if "monitor_interval" not in infoDict["cluster_info"] or infoDict["cluster_info"]["monitor_interval"] !=5: - tdLog.exit("monitor_interval is null!") - - if "vgroups_total" not in infoDict["cluster_info"] or infoDict["cluster_info"]["vgroups_total"] < 0: - tdLog.exit("vgroups_total is null!") - - if "vgroups_alive" not in infoDict["cluster_info"] or infoDict["cluster_info"]["vgroups_alive"] < 0: - tdLog.exit("vgroups_alive is null!") - - if "connections_total" not in infoDict["cluster_info"] or infoDict["cluster_info"]["connections_total"] < 0 : - tdLog.exit("connections_total is null!") - - if "dnodes" not in infoDict["cluster_info"] or infoDict["cluster_info"]["dnodes"] == None : - tdLog.exit("dnodes is null!") - - dnodes_info = { "dnode_id": 1,"dnode_ep": f"{hostname}:{serverPort}","status":"ready"} - - for k ,v in dnodes_info.items(): - if k not in infoDict["cluster_info"]["dnodes"][0] or v != infoDict["cluster_info"]["dnodes"][0][k] : - tdLog.exit("dnodes info is null!") - - mnodes_info = { "mnode_id":1, "mnode_ep":f"{hostname}:{serverPort}","role": "leader" } - - for k ,v in mnodes_info.items(): - if k not in infoDict["cluster_info"]["mnodes"][0] or v != infoDict["cluster_info"]["mnodes"][0][k] : - tdLog.exit("mnodes info is null!") - - # vgroup_infos ==================================== - - if "vgroup_infos" not in infoDict or infoDict["vgroup_infos"]== None: - tdLog.exit("vgroup_infos is null!") - - vgroup_infos_nums = len(infoDict["vgroup_infos"]) - - for index in range(vgroup_infos_nums): - if "vgroup_id" not in infoDict["vgroup_infos"][index] or infoDict["vgroup_infos"][index]["vgroup_id"]<0: - tdLog.exit("vgroup_id is null!") - if "database_name" not in infoDict["vgroup_infos"][index] or len(infoDict["vgroup_infos"][index]["database_name"]) < 0: - tdLog.exit("database_name is null!") - if "tables_num" not in infoDict["vgroup_infos"][index] or infoDict["vgroup_infos"][index]["tables_num"]!= 0: - tdLog.exit("tables_num is null!") - if "status" not in infoDict["vgroup_infos"][index] or len(infoDict["vgroup_infos"][index]["status"]) < 0 : - tdLog.exit("status is null!") - if "vnodes" not in infoDict["vgroup_infos"][index] or infoDict["vgroup_infos"][index]["vnodes"] ==None : - tdLog.exit("vnodes is null!") - if "dnode_id" not in infoDict["vgroup_infos"][index]["vnodes"][0] or infoDict["vgroup_infos"][index]["vnodes"][0]["dnode_id"] < 0 : - tdLog.exit("vnodes is null!") - - # grant_info ==================================== - - if "grant_info" not in infoDict or infoDict["grant_info"]== None: - tdLog.exit("grant_info is null!") - - if "expire_time" not in infoDict["grant_info"] or not infoDict["grant_info"]["expire_time"] > 0: - tdLog.exit("expire_time is null!") - - if "timeseries_used" not in infoDict["grant_info"] or not infoDict["grant_info"]["timeseries_used"] > 0: - tdLog.exit("timeseries_used is null!") - - if "timeseries_total" not in infoDict["grant_info"] or not infoDict["grant_info"]["timeseries_total"] > 0: - tdLog.exit("timeseries_total is null!") + if "version" not in infoDict["cluster_info"] or infoDict["cluster_info"]["version"] == None: + tdLog.exit("first_ep_dnode_id is null!") - # dnode_info ==================================== + if "master_uptime" not in infoDict["cluster_info"] or infoDict["cluster_info"]["master_uptime"] == None: + tdLog.exit("master_uptime is null!") - if "dnode_info" not in infoDict or infoDict["dnode_info"]== None: - tdLog.exit("dnode_info is null!") + if "monitor_interval" not in infoDict["cluster_info"] or infoDict["cluster_info"]["monitor_interval"] !=5: + tdLog.exit("monitor_interval is null!") - dnode_infos = ['uptime', 'cpu_engine', 'cpu_system', 'cpu_cores', 'mem_engine', 'mem_system', 'mem_total', 'disk_engine', - 'disk_used', 'disk_total', 'net_in', 'net_out', 'io_read', 'io_write', 'io_read_disk', 'io_write_disk', 'req_select', - 'req_select_rate', 'req_insert', 'req_insert_success', 'req_insert_rate', 'req_insert_batch', 'req_insert_batch_success', - 'req_insert_batch_rate', 'errors', 'vnodes_num', 'masters', 'has_mnode', 'has_qnode', 'has_snode', 'has_bnode'] - for elem in dnode_infos: - if elem not in infoDict["dnode_info"] or infoDict["dnode_info"][elem] < 0: - tdLog.exit(f"{elem} is null!") + if "vgroups_total" not in infoDict["cluster_info"] or infoDict["cluster_info"]["vgroups_total"] < 0: + tdLog.exit("vgroups_total is null!") - # dnode_info ==================================== + if "vgroups_alive" not in infoDict["cluster_info"] or infoDict["cluster_info"]["vgroups_alive"] < 0: + tdLog.exit("vgroups_alive is null!") - if "disk_infos" not in infoDict or infoDict["disk_infos"]== None: - tdLog.exit("disk_infos is null!") - - # bug for data_dir - if "datadir" not in infoDict["disk_infos"] or len(infoDict["disk_infos"]["datadir"]) <=0 : - tdLog.exit("datadir is null!") + if "connections_total" not in infoDict["cluster_info"] or infoDict["cluster_info"]["connections_total"] < 0 : + tdLog.exit("connections_total is null!") - if "name" not in infoDict["disk_infos"]["datadir"][0] or len(infoDict["disk_infos"]["datadir"][0]["name"]) <= 0: - tdLog.exit("name is null!") + if "dnodes" not in infoDict["cluster_info"] or infoDict["cluster_info"]["dnodes"] == None : + tdLog.exit("dnodes is null!") + + dnodes_info = { "dnode_id": 1,"dnode_ep": self.hostPort,"status":"ready"} + + for k ,v in dnodes_info.items(): + if k not in infoDict["cluster_info"]["dnodes"][0] or v != infoDict["cluster_info"]["dnodes"][0][k] : + tdLog.exit("dnodes info is null!") + + mnodes_info = { "mnode_id":1, "mnode_ep": self.hostPort,"role": "leader" } - if "level" not in infoDict["disk_infos"]["datadir"][0] or infoDict["disk_infos"]["datadir"][0]["level"] < 0: - tdLog.exit("level is null!") + for k ,v in mnodes_info.items(): + if k not in infoDict["cluster_info"]["mnodes"][0] or v != infoDict["cluster_info"]["mnodes"][0][k] : + tdLog.exit("mnodes info is null!") - if "avail" not in infoDict["disk_infos"]["datadir"][0] or infoDict["disk_infos"]["datadir"][0]["avail"] <= 0: - tdLog.exit("avail is null!") + # vgroup_infos ==================================== - if "used" not in infoDict["disk_infos"]["datadir"][0] or infoDict["disk_infos"]["datadir"][0]["used"] <= 0: - tdLog.exit("used is null!") + if "vgroup_infos" not in infoDict or infoDict["vgroup_infos"]== None: + tdLog.exit("vgroup_infos is null!") + + vgroup_infos_nums = len(infoDict["vgroup_infos"]) - if "total" not in infoDict["disk_infos"]["datadir"][0] or infoDict["disk_infos"]["datadir"][0]["total"] <= 0: - tdLog.exit("total is null!") + for index in range(vgroup_infos_nums): + if "vgroup_id" not in infoDict["vgroup_infos"][index] or infoDict["vgroup_infos"][index]["vgroup_id"]<0: + tdLog.exit("vgroup_id is null!") + if "database_name" not in infoDict["vgroup_infos"][index] or len(infoDict["vgroup_infos"][index]["database_name"]) < 0: + tdLog.exit("database_name is null!") + if "tables_num" not in infoDict["vgroup_infos"][index] or infoDict["vgroup_infos"][index]["tables_num"]!= 0: + tdLog.exit("tables_num is null!") + if "status" not in infoDict["vgroup_infos"][index] or len(infoDict["vgroup_infos"][index]["status"]) < 0 : + tdLog.exit("status is null!") + if "vnodes" not in infoDict["vgroup_infos"][index] or infoDict["vgroup_infos"][index]["vnodes"] ==None : + tdLog.exit("vnodes is null!") + if "dnode_id" not in infoDict["vgroup_infos"][index]["vnodes"][0] or infoDict["vgroup_infos"][index]["vnodes"][0]["dnode_id"] < 0 : + tdLog.exit("vnodes is null!") + + # grant_info ==================================== + + if "grant_info" not in infoDict or infoDict["grant_info"]== None: + tdLog.exit("grant_info is null!") + + if "expire_time" not in infoDict["grant_info"] or not infoDict["grant_info"]["expire_time"] > 0: + tdLog.exit("expire_time is null!") + + if "timeseries_used" not in infoDict["grant_info"] or not infoDict["grant_info"]["timeseries_used"] > 0: + tdLog.exit("timeseries_used is null!") + + if "timeseries_total" not in infoDict["grant_info"] or not infoDict["grant_info"]["timeseries_total"] > 0: + tdLog.exit("timeseries_total is null!") + + # dnode_info ==================================== + + if "dnode_info" not in infoDict or infoDict["dnode_info"]== None: + tdLog.exit("dnode_info is null!") + + dnode_infos = ['uptime', 'cpu_engine', 'cpu_system', 'cpu_cores', 'mem_engine', 'mem_system', 'mem_total', 'disk_engine', + 'disk_used', 'disk_total', 'net_in', 'net_out', 'io_read', 'io_write', 'io_read_disk', 'io_write_disk', 'req_select', + 'req_select_rate', 'req_insert', 'req_insert_success', 'req_insert_rate', 'req_insert_batch', 'req_insert_batch_success', + 'req_insert_batch_rate', 'errors', 'vnodes_num', 'masters', 'has_mnode', 'has_qnode', 'has_snode', 'has_bnode'] + for elem in dnode_infos: + if elem not in infoDict["dnode_info"] or infoDict["dnode_info"][elem] < 0: + tdLog.exit(f"{elem} is null!") + + # dnode_info ==================================== + + if "disk_infos" not in infoDict or infoDict["disk_infos"]== None: + tdLog.exit("disk_infos is null!") + + # bug for data_dir + if "datadir" not in infoDict["disk_infos"] or len(infoDict["disk_infos"]["datadir"]) <=0 : + tdLog.exit("datadir is null!") + + if "name" not in infoDict["disk_infos"]["datadir"][0] or len(infoDict["disk_infos"]["datadir"][0]["name"]) <= 0: + tdLog.exit("name is null!") + + if "level" not in infoDict["disk_infos"]["datadir"][0] or infoDict["disk_infos"]["datadir"][0]["level"] < 0: + tdLog.exit("level is null!") + + if "avail" not in infoDict["disk_infos"]["datadir"][0] or infoDict["disk_infos"]["datadir"][0]["avail"] <= 0: + tdLog.exit("avail is null!") + + if "used" not in infoDict["disk_infos"]["datadir"][0] or infoDict["disk_infos"]["datadir"][0]["used"] <= 0: + tdLog.exit("used is null!") + + if "total" not in infoDict["disk_infos"]["datadir"][0] or infoDict["disk_infos"]["datadir"][0]["total"] <= 0: + tdLog.exit("total is null!") - if "logdir" not in infoDict["disk_infos"] or infoDict["disk_infos"]["logdir"]== None: - tdLog.exit("logdir is null!") + if "logdir" not in infoDict["disk_infos"] or infoDict["disk_infos"]["logdir"]== None: + tdLog.exit("logdir is null!") - if "name" not in infoDict["disk_infos"]["logdir"] or len(infoDict["disk_infos"]["logdir"]["name"]) <= 0: - tdLog.exit("name is null!") + if "name" not in infoDict["disk_infos"]["logdir"] or len(infoDict["disk_infos"]["logdir"]["name"]) <= 0: + tdLog.exit("name is null!") - if "avail" not in infoDict["disk_infos"]["logdir"] or infoDict["disk_infos"]["logdir"]["avail"] <= 0: - tdLog.exit("avail is null!") + if "avail" not in infoDict["disk_infos"]["logdir"] or infoDict["disk_infos"]["logdir"]["avail"] <= 0: + tdLog.exit("avail is null!") - if "used" not in infoDict["disk_infos"]["logdir"] or infoDict["disk_infos"]["logdir"]["used"] <= 0: - tdLog.exit("used is null!") + if "used" not in infoDict["disk_infos"]["logdir"] or infoDict["disk_infos"]["logdir"]["used"] <= 0: + tdLog.exit("used is null!") - if "total" not in infoDict["disk_infos"]["logdir"] or infoDict["disk_infos"]["logdir"]["total"] <= 0: - tdLog.exit("total is null!") + if "total" not in infoDict["disk_infos"]["logdir"] or infoDict["disk_infos"]["logdir"]["total"] <= 0: + tdLog.exit("total is null!") + if "tempdir" not in infoDict["disk_infos"] or infoDict["disk_infos"]["tempdir"]== None: + tdLog.exit("tempdir is null!") + + if "name" not in infoDict["disk_infos"]["tempdir"] or len(infoDict["disk_infos"]["tempdir"]["name"]) <= 0: + tdLog.exit("name is null!") + + if "avail" not in infoDict["disk_infos"]["tempdir"] or infoDict["disk_infos"]["tempdir"]["avail"] <= 0: + tdLog.exit("avail is null!") + + if "used" not in infoDict["disk_infos"]["tempdir"] or infoDict["disk_infos"]["tempdir"]["used"] <= 0: + tdLog.exit("used is null!") + + if "total" not in infoDict["disk_infos"]["tempdir"] or infoDict["disk_infos"]["tempdir"]["total"] <= 0: + tdLog.exit("total is null!") + + + # log_infos ==================================== + + if "log_infos" not in infoDict or infoDict["log_infos"]== None: + tdLog.exit("log_infos is null!") + + if "logs" not in infoDict["log_infos"] or len(infoDict["log_infos"]["logs"])!= 10: + tdLog.exit("logs is null!") + + if "ts" not in infoDict["log_infos"]["logs"][0] or len(infoDict["log_infos"]["logs"][0]["ts"]) <= 10: + tdLog.exit("ts is null!") + + if "level" not in infoDict["log_infos"]["logs"][0] or infoDict["log_infos"]["logs"][0]["level"] not in ["error" ,"info" , "debug" ,"trace"]: + tdLog.exit("level is null!") + + if "content" not in infoDict["log_infos"]["logs"][0] or len(infoDict["log_infos"]["logs"][0]["ts"]) <= 1: + tdLog.exit("content is null!") + + if "summary" not in infoDict["log_infos"] or len(infoDict["log_infos"]["summary"])!= 4: + tdLog.exit("summary is null!") + + + if "total" not in infoDict["log_infos"]["summary"][0] or infoDict["log_infos"]["summary"][0]["total"] < 0 : + tdLog.exit("total is null!") + + if "level" not in infoDict["log_infos"]["summary"][0] or infoDict["log_infos"]["summary"][0]["level"] not in ["error" ,"info" , "debug" ,"trace"]: + tdLog.exit("level is null!") - - if "tempdir" not in infoDict["disk_infos"] or infoDict["disk_infos"]["tempdir"]== None: - tdLog.exit("tempdir is null!") - - if "name" not in infoDict["disk_infos"]["tempdir"] or len(infoDict["disk_infos"]["tempdir"]["name"]) <= 0: - tdLog.exit("name is null!") - - if "avail" not in infoDict["disk_infos"]["tempdir"] or infoDict["disk_infos"]["tempdir"]["avail"] <= 0: - tdLog.exit("avail is null!") - - if "used" not in infoDict["disk_infos"]["tempdir"] or infoDict["disk_infos"]["tempdir"]["used"] <= 0: - tdLog.exit("used is null!") - - if "total" not in infoDict["disk_infos"]["tempdir"] or infoDict["disk_infos"]["tempdir"]["total"] <= 0: - tdLog.exit("total is null!") - - - # log_infos ==================================== - - if "log_infos" not in infoDict or infoDict["log_infos"]== None: - tdLog.exit("log_infos is null!") - - if "logs" not in infoDict["log_infos"] or len(infoDict["log_infos"]["logs"])!= 10: - tdLog.exit("logs is null!") - - if "ts" not in infoDict["log_infos"]["logs"][0] or len(infoDict["log_infos"]["logs"][0]["ts"]) <= 10: - tdLog.exit("ts is null!") - - if "level" not in infoDict["log_infos"]["logs"][0] or infoDict["log_infos"]["logs"][0]["level"] not in ["error" ,"info" , "debug" ,"trace"]: - tdLog.exit("level is null!") - - if "content" not in infoDict["log_infos"]["logs"][0] or len(infoDict["log_infos"]["logs"][0]["ts"]) <= 1: - tdLog.exit("content is null!") - - if "summary" not in infoDict["log_infos"] or len(infoDict["log_infos"]["summary"])!= 4: - tdLog.exit("summary is null!") - - - if "total" not in infoDict["log_infos"]["summary"][0] or infoDict["log_infos"]["summary"][0]["total"] < 0 : - tdLog.exit("total is null!") - - if "level" not in infoDict["log_infos"]["summary"][0] or infoDict["log_infos"]["summary"][0]["level"] not in ["error" ,"info" , "debug" ,"trace"]: - tdLog.exit("level is null!") - -class RequestHandlerImpl(http.server.BaseHTTPRequestHandler): def do_GET(self): """ process GET request @@ -245,17 +243,23 @@ class RequestHandlerImpl(http.server.BaseHTTPRequestHandler): infoDict = json.loads(plainText) #print("================") # print(infoDict) - telemetryInfoCheck(infoDict) + self.telemetryInfoCheck(infoDict) # 4. shutdown the server and exit case - assassin = threading.Thread(target=httpServer.shutdown) + assassin = threading.Thread(target=self.server.shutdown) assassin.daemon = True assassin.start() print ("==== shutdown http server ====") class TDTestCase: - hostname = socket.gethostname() - serverPort = '7080' + global hostname + global serverPort + if (platform.system().lower() == 'windows' and not tdDnodes.dnodes[0].remoteIP == ""): + try: + config = eval(tdDnodes.dnodes[0].remoteIP ) + hostname = config["host"] + except Exception: + hostname = tdDnodes.dnodes[0].remoteIP rpcDebugFlagVal = '143' clientCfgDict = {'serverPort': '', 'firstEp': '', 'secondEp':'', 'rpcDebugFlag':'135', 'fqdn':''} clientCfgDict["serverPort"] = serverPort @@ -291,21 +295,19 @@ class TDTestCase: sql = "create database db3 vgroups " + vgroups tdSql.query(sql) - # loop to wait request - httpServer.serve_forever() + # create http server: bing ip/port , and request processor + if (platform.system().lower() == 'windows' and not tdDnodes.dnodes[0].remoteIP == ""): + RequestHandlerImplStr = base64.b64encode(pickle.dumps(RequestHandlerImpl)).decode() + cmdStr = "import pickle\nimport http\nRequestHandlerImpl=pickle.loads(base64.b64decode(\"%s\".encode()))\nclass NewRequestHandlerImpl(RequestHandlerImpl):\n hostPort = \'%s\'\nhttp.server.HTTPServer((\"\", %s), NewRequestHandlerImpl).serve_forever()"%(RequestHandlerImplStr,hostname+":"+serverPort,telemetryPort) + tdDnodes.dnodes[0].remoteExec({}, cmdStr) + else: + serverAddress = ("", int(telemetryPort)) + http.server.HTTPServer(serverAddress, RequestHandlerImpl).serve_forever() def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") -# create http server: bing ip/port , and request processor -serverAddress = ("", int(telemetryPort)) -httpServer = http.server.HTTPServer(serverAddress, RequestHandlerImpl) - tdCases.addLinux(__file__, TDTestCase()) tdCases.addWindows(__file__, TDTestCase()) - - - - diff --git a/tests/system-test/0-others/telemetry.py b/tests/system-test/0-others/telemetry.py index 203f87c085..4483e113bf 100644 --- a/tests/system-test/0-others/telemetry.py +++ b/tests/system-test/0-others/telemetry.py @@ -8,6 +8,7 @@ import http.server import gzip import threading import json +import pickle from util.log import * from util.sql import * @@ -136,13 +137,19 @@ class RequestHandlerImpl(http.server.BaseHTTPRequestHandler): telemetryInfoCheck(infoDict) # 4. shutdown the server and exit case - assassin = threading.Thread(target=httpServer.shutdown) + assassin = threading.Thread(target=self.server.shutdown) assassin.daemon = True assassin.start() print ("==== shutdown http server ====") class TDTestCase: hostname = socket.gethostname() + if (platform.system().lower() == 'windows' and not tdDnodes.dnodes[0].remoteIP == ""): + try: + config = eval(tdDnodes.dnodes[0].remoteIP) + hostname = config["host"] + except Exception: + hostname = tdDnodes.dnodes[0].remoteIP serverPort = '7080' rpcDebugFlagVal = '143' clientCfgDict = {'serverPort': '', 'firstEp': '', 'secondEp':'', 'rpcDebugFlag':'135', 'fqdn':''} @@ -177,17 +184,20 @@ class TDTestCase: sql = "create database db3 vgroups " + vgroups tdSql.query(sql) - # loop to wait request - httpServer.serve_forever() + # create http server: bing ip/port , and request processor + if (platform.system().lower() == 'windows' and not tdDnodes.dnodes[0].remoteIP == ""): + RequestHandlerImplStr = base64.b64encode(pickle.dumps(RequestHandlerImpl)).decode() + telemetryInfoCheckStr = base64.b64encode(pickle.dumps(telemetryInfoCheck)).decode() + cmdStr = "import pickle\nimport http\ntelemetryInfoCheck=pickle.loads(base64.b64decode(\"%s\".encode()))\nRequestHandlerImpl=pickle.loads(base64.b64decode(\"%s\".encode()))\nhttp.server.HTTPServer((\"\", %d), RequestHandlerImpl).serve_forever()"%(telemetryInfoCheckStr,RequestHandlerImplStr,int(telemetryPort)) + tdDnodes.dnodes[0].remoteExec({}, cmdStr) + else: + serverAddress = ("", int(telemetryPort)) + http.server.HTTPServer(serverAddress, RequestHandlerImpl).serve_forever() def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") -# create http server: bing ip/port , and request processor -serverAddress = ("", int(telemetryPort)) -httpServer = http.server.HTTPServer(serverAddress, RequestHandlerImpl) - tdCases.addLinux(__file__, TDTestCase()) tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/0-others/udf_create.py b/tests/system-test/0-others/udf_create.py index 88ed667161..0d24b09616 100644 --- a/tests/system-test/0-others/udf_create.py +++ b/tests/system-test/0-others/udf_create.py @@ -9,6 +9,8 @@ from util.sql import * from util.cases import * from util.dnodes import * import subprocess +# import win32gui +# import threading class TDTestCase: @@ -533,8 +535,17 @@ class TDTestCase: return udf1_sqls ,udf2_sqls + # def checkRunTimeError(self): + # while 1: + # time.sleep(1) + # hwnd = win32gui.FindWindow(None, "Microsoft Visual C++ Runtime Library") + # if hwnd: + # os.system("TASKKILL /F /IM udfd.exe") def unexpected_create(self): + # if (platform.system().lower() == 'windows' and tdDnodes.dnodes[0].remoteIP == ""): + # checkErrorThread = threading.Thread(target=self.checkRunTimeError,daemon=True) + # checkErrorThread.start() tdLog.info(" create function with out bufsize ") tdSql.query("drop function udf1 ") diff --git a/tests/system-test/1-insert/create_table_comment.py b/tests/system-test/1-insert/create_table_comment.py new file mode 100644 index 0000000000..92ea083c5a --- /dev/null +++ b/tests/system-test/1-insert/create_table_comment.py @@ -0,0 +1,113 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import random +import string +from util.log import * +from util.cases import * +from util.sql import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + def get_long_name(self, length, mode="mixed"): + """ + generate long name + mode could be numbers/letters/letters_mixed/mixed + """ + if mode == "numbers": + population = string.digits + elif mode == "letters": + population = string.ascii_letters.lower() + elif mode == "letters_mixed": + population = string.ascii_letters.upper() + string.ascii_letters.lower() + else: + population = string.ascii_letters.lower() + string.digits + return "".join(random.choices(population, k=length)) + + def __create_tb(self,dbname,stbname,tbname,comment): + tdSql.execute(f'create database if not exists {dbname}') + tdSql.execute(f'use {dbname}') + tdSql.execute( + f'create table {stbname} (ts timestamp,c0 int) tags(t0 int) ') + tdSql.execute( + f'create table {tbname} using {stbname} tags(1) comment "{comment}"') + def __create_normaltb(self,dbname,tbname,comment): + tdSql.execute(f'create database if not exists {dbname}') + tdSql.execute(f'use {dbname}') + tdSql.execute( + f'create table {tbname} (ts timestamp,c0 int) comment "{comment}"') + + def check_comment(self): + dbname = self.get_long_name(length=10, mode="letters") + ntbname = self.get_long_name(length=5, mode="letters") + + # create normal table with comment + comment = self.get_long_name(length=10, mode="letters") + self.__create_normaltb(dbname,ntbname,comment) + ntb_kv_list = tdSql.getResult("show tables") + print(ntb_kv_list) + tdSql.checkEqual(ntb_kv_list[0][8], comment) + tdSql.error('alter table {ntbname} comment "test1"') + tdSql.execute(f'drop database {dbname}') + + # max length(1024) + comment = self.get_long_name(length=1024, mode="letters") + self.__create_normaltb(dbname,ntbname,comment) + ntb_kv_list = tdSql.getResult("show tables") + tdSql.checkEqual(ntb_kv_list[0][8], comment) + tdSql.execute(f'drop database {dbname}') + + # error overlength + comment = self.get_long_name(length=1025, mode="letters") + tdSql.execute(f'create database if not exists {dbname}') + tdSql.execute(f'use {dbname}') + tdSql.error(f"create table ntb (ts timestamp,c0 int) comment '{comment}'") + tdSql.execute(f'drop database {dbname}') + + # create child table with comment + comment = self.get_long_name(length=10, mode="letters") + stbname = self.get_long_name(length=5, mode="letters") + tbname = self.get_long_name(length=3, mode="letters") + self.__create_tb(dbname,stbname,tbname,comment) + ntb_kv_list = tdSql.getResult("show tables") + tdSql.checkEqual(ntb_kv_list[0][8], comment) + tdSql.error(f'alter table {tbname} comment "test1"') + tdSql.execute(f'drop database {dbname}') + + # max length 1024 + comment = self.get_long_name(length=1024, mode="letters") + self.__create_tb(dbname,ntbname,comment) + ntb_kv_list = tdSql.getResult("show tables") + tdSql.checkEqual(ntb_kv_list[0][8], comment) + tdSql.execute(f'drop database {dbname}') + + # error overlength + comment = self.get_long_name(length=1025, mode="letters") + tdSql.execute(f'create database if not exists {dbname}') + tdSql.execute(f'use {dbname}') + tdSql.execute(f"create table stb (ts timestamp,c0 int) tags(t0 int)") + tdSql.error(f'create table stb_1 us stb tags(1) comment "{comment}"') + tdSql.execute(f'drop database {dbname}') + + def run(self): + self.check_comment() + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/1-insert/test_stmt_insert_query_ex.py b/tests/system-test/1-insert/test_stmt_insert_query_ex.py index 376b60d615..c0836b79c8 100644 --- a/tests/system-test/1-insert/test_stmt_insert_query_ex.py +++ b/tests/system-test/1-insert/test_stmt_insert_query_ex.py @@ -80,93 +80,9 @@ class TDTestCase: con=taos.connect(host=host, user=user, password=password, config=cfg ,port=port) print(con) return con - - def test_stmt_insert_multi(self,conn): - # type: (TaosConnection) -> None - - dbname = "pytest_taos_stmt_multi" - try: - conn.execute("drop database if exists %s" % dbname) - conn.execute("create database if not exists %s" % dbname) - conn.select_db(dbname) - - conn.execute( - "create table if not exists log(ts timestamp, bo bool, nil tinyint, ti tinyint, si smallint, ii int,\ - bi bigint, tu tinyint unsigned, su smallint unsigned, iu int unsigned, bu bigint unsigned, \ - ff float, dd double, bb binary(100), nn nchar(100), tt timestamp)", - ) - # conn.load_table_info("log") - - start = datetime.now() - stmt = conn.statement("insert into log values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") - - params = new_multi_binds(16) - params[0].timestamp((1626861392589, 1626861392590, 1626861392591)) - params[1].bool((True, None, False)) - params[2].tinyint([-128, -128, None]) # -128 is tinyint null - params[3].tinyint([0, 127, None]) - params[4].smallint([3, None, 2]) - params[5].int([3, 4, None]) - params[6].bigint([3, 4, None]) - params[7].tinyint_unsigned([3, 4, None]) - params[8].smallint_unsigned([3, 4, None]) - params[9].int_unsigned([3, 4, None]) - params[10].bigint_unsigned([3, 4, None]) - params[11].float([3, None, 1]) - params[12].double([3, None, 1.2]) - params[13].binary(["abc", "dddafadfadfadfadfa", None]) - params[14].nchar(["涛思数据", None, "a long string with 中文字符"]) - params[15].timestamp([None, None, 1626861392591]) - # print(type(stmt)) - stmt.bind_param_batch(params) - stmt.execute() - end = datetime.now() - print("elapsed time: ", end - start) - assert stmt.affected_rows == 3 - - #query - querystmt=conn.statement("select ?,bu from log") - queryparam=new_bind_params(1) - print(type(queryparam)) - queryparam[0].binary("ts") - querystmt.bind_param(queryparam) - querystmt.execute() - result=querystmt.use_result() - # rows=result.fetch_all() - # print( querystmt.use_result()) - - # result = conn.query("select * from log") - rows=result.fetch_all() - # rows=result.fetch_all() - print(rows) - assert rows[1][0] == "ts" - assert rows[0][1] == 3 - - #query - querystmt1=conn.statement("select * from log where bu < ?") - queryparam1=new_bind_params(1) - print(type(queryparam1)) - queryparam1[0].int(4) - querystmt1.bind_param(queryparam1) - querystmt1.execute() - result1=querystmt1.use_result() - rows1=result1.fetch_all() - assert str(rows1[0][0]) == "2021-07-21 17:56:32.589000" - assert rows1[0][10] == 3 - - - stmt.close() - - # conn.execute("drop database if exists %s" % dbname) - conn.close() - - except Exception as err: - # conn.execute("drop database if exists %s" % dbname) - conn.close() - raise err def test_stmt_set_tbname_tag(self,conn): - dbname = "pytest_taos_stmt_set_tbname_tag" + dbname = "stmt_set_tbname_tag" try: conn.execute("drop database if exists %s" % dbname) @@ -174,16 +90,16 @@ class TDTestCase: conn.select_db(dbname) conn.execute("create table if not exists log(ts timestamp, bo bool, nil tinyint, ti tinyint, si smallint, ii int,\ bi bigint, tu tinyint unsigned, su smallint unsigned, iu int unsigned, bu bigint unsigned, \ - ff float, dd double, bb binary(100), nn nchar(100), tt timestamp) tags (t1 timestamp, t2 bool,\ + ff float, dd double, bb binary(100), nn nchar(100), tt timestamp , vc varchar(100)) tags (t1 timestamp, t2 bool,\ t3 tinyint, t4 tinyint, t5 smallint, t6 int, t7 bigint, t8 tinyint unsigned, t9 smallint unsigned, \ t10 int unsigned, t11 bigint unsigned, t12 float, t13 double, t14 binary(100), t15 nchar(100), t16 timestamp)") stmt = conn.statement("insert into ? using log tags (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) \ - values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)") + values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)") tags = new_bind_params(16) tags[0].timestamp(1626861392589123, PrecisionEnum.Microseconds) tags[1].bool(True) - tags[2].null() + tags[2].bool(False) tags[3].tinyint(2) tags[4].smallint(3) tags[5].int(4) @@ -198,7 +114,7 @@ class TDTestCase: tags[14].nchar("stmt") tags[15].timestamp(1626861392589, PrecisionEnum.Milliseconds) stmt.set_tbname_tags("tb1", tags) - params = new_multi_binds(16) + params = new_multi_binds(17) params[0].timestamp((1626861392589111, 1626861392590111, 1626861392591111)) params[1].bool((True, None, False)) params[2].tinyint([-128, -128, None]) # -128 is tinyint null @@ -213,25 +129,32 @@ class TDTestCase: params[11].float([3, None, 1]) params[12].double([3, None, 1.2]) params[13].binary(["abc", "dddafadfadfadfadfa", None]) - params[14].nchar(["涛思数据", None, "a? long string with 中文字符"]) + params[14].nchar(["涛思数据", None, "a long string with 中文字符"]) params[15].timestamp([None, None, 1626861392591]) - + params[16].binary(["涛思数据16", None, "a long string with 中文-字符"]) + stmt.bind_param_batch(params) stmt.execute() assert stmt.affected_rows == 3 - #query + #query all querystmt1=conn.statement("select * from log where bu < ?") queryparam1=new_bind_params(1) print(type(queryparam1)) - queryparam1[0].int(5) + queryparam1[0].int(10) querystmt1.bind_param(queryparam1) querystmt1.execute() result1=querystmt1.use_result() rows1=result1.fetch_all() - print("1",rows1) + print(rows1[0]) + print(rows1[1]) + print(rows1[2]) + assert str(rows1[0][0]) == "2021-07-21 17:56:32.589111" + assert rows1[0][10] == 3 + assert rows1[1][10] == 4 + #query: Numeric Functions querystmt2=conn.statement("select abs(?) from log where bu < ?") queryparam2=new_bind_params(2) print(type(queryparam2)) @@ -242,6 +165,11 @@ class TDTestCase: result2=querystmt2.use_result() rows2=result2.fetch_all() print("2",rows2) + assert rows2[0][0] == 5 + assert rows2[1][0] == 5 + + + #query: Numeric Functions and escapes querystmt3=conn.statement("select abs(?) from log where nn= 'a? long string with 中文字符' ") queryparam3=new_bind_params(1) @@ -252,9 +180,63 @@ class TDTestCase: result3=querystmt3.use_result() rows3=result3.fetch_all() print("3",rows3) - # assert str(rows1[0][0]) == "2021-07-21 17:56:32.589111" - # assert rows1[0][10] == 3 - # assert rows1[1][10] == 4 + assert rows3 == [] + + #query: string Functions + + querystmt3=conn.statement("select CHAR_LENGTH(?) from log ") + queryparam3=new_bind_params(1) + print(type(queryparam3)) + queryparam3[0].binary('中文字符') + querystmt3.bind_param(queryparam3) + querystmt3.execute() + result3=querystmt3.use_result() + rows3=result3.fetch_all() + print("4",rows3) + assert rows3[0][0] == 12, 'fourth case is failed' + assert rows3[1][0] == 12, 'fourth case is failed' + + # #query: conversion Functions + + # querystmt4=conn.statement("select cast( ? as bigint) from log ") + # queryparam4=new_bind_params(1) + # print(type(queryparam4)) + # queryparam4[0].binary('1232a') + # querystmt4.bind_param(queryparam4) + # querystmt4.execute() + # result4=querystmt4.use_result() + # rows4=result4.fetch_all() + # print("5",rows4) + # assert rows4[0][0] == 1232 + # assert rows4[1][0] == 1232 + + # querystmt4=conn.statement("select cast( ? as binary(10)) from log ") + # queryparam4=new_bind_params(1) + # print(type(queryparam4)) + # queryparam4[0].int(123) + # querystmt4.bind_param(queryparam4) + # querystmt4.execute() + # result4=querystmt4.use_result() + # rows4=result4.fetch_all() + # print("6",rows4) + # assert rows4[0][0] == '123' + # assert rows4[1][0] == '123' + + # #query: datatime Functions + + # querystmt4=conn.statement(" select timediff('2021-07-21 17:56:32.590111',?,1s) from log ") + # queryparam4=new_bind_params(1) + # print(type(queryparam4)) + # queryparam4[0].timestamp(1626861392591111) + # querystmt4.bind_param(queryparam4) + # querystmt4.execute() + # result4=querystmt4.use_result() + # rows4=result4.fetch_all() + # print("7",rows4) + # assert rows4[0][0] == 1, 'seventh case is failed' + # assert rows4[1][0] == 1, 'seventh case is failed' + + # conn.execute("drop database if exists %s" % dbname) conn.close() @@ -269,8 +251,6 @@ class TDTestCase: config = buildPath+ "../sim/dnode1/cfg/" host="localhost" connectstmt=self.newcon(host,config) - self.test_stmt_insert_multi(connectstmt) - connectstmt=self.newcon(host,config) self.test_stmt_set_tbname_tag(connectstmt) return diff --git a/tests/system-test/1-insert/test_stmt_muti_insert_query.py b/tests/system-test/1-insert/test_stmt_muti_insert_query.py index 486bcd8062..f838fd90f5 100644 --- a/tests/system-test/1-insert/test_stmt_muti_insert_query.py +++ b/tests/system-test/1-insert/test_stmt_muti_insert_query.py @@ -124,7 +124,7 @@ class TDTestCase: print("elapsed time: ", end - start) assert stmt.affected_rows == 3 - #query + #query 1 querystmt=conn.statement("select ?,bu from log") queryparam=new_bind_params(1) print(type(queryparam)) @@ -141,8 +141,9 @@ class TDTestCase: print(rows) assert rows[1][0] == "ts" assert rows[0][1] == 3 + assert rows[2][1] == None - #query + #query 2 querystmt1=conn.statement("select * from log where bu < ?") queryparam1=new_bind_params(1) print(type(queryparam1)) diff --git a/tests/system-test/1-insert/test_stmt_set_tbname_tag.py b/tests/system-test/1-insert/test_stmt_set_tbname_tag.py index 54d5cfbafb..fb9f455d4d 100644 --- a/tests/system-test/1-insert/test_stmt_set_tbname_tag.py +++ b/tests/system-test/1-insert/test_stmt_set_tbname_tag.py @@ -82,7 +82,7 @@ class TDTestCase: return con def test_stmt_set_tbname_tag(self,conn): - dbname = "pytest_taos_stmt_set_tbname_tag" + dbname = "stmt_set_tbname_tag" try: conn.execute("drop database if exists %s" % dbname) @@ -99,7 +99,7 @@ class TDTestCase: tags = new_bind_params(16) tags[0].timestamp(1626861392589123, PrecisionEnum.Microseconds) tags[1].bool(True) - tags[2].null() + tags[2].bool(False) tags[3].tinyint(2) tags[4].smallint(3) tags[5].int(4) @@ -114,7 +114,7 @@ class TDTestCase: tags[14].nchar("stmt") tags[15].timestamp(1626861392589, PrecisionEnum.Milliseconds) stmt.set_tbname_tags("tb1", tags) - params = new_multi_binds(16) + params = new_multi_binds(17) params[0].timestamp((1626861392589111, 1626861392590111, 1626861392591111)) params[1].bool((True, None, False)) params[2].tinyint([-128, -128, None]) # -128 is tinyint null @@ -129,28 +129,153 @@ class TDTestCase: params[11].float([3, None, 1]) params[12].double([3, None, 1.2]) params[13].binary(["abc", "dddafadfadfadfadfa", None]) - params[14].nchar(["涛思数据", None, "a long string with 中文字符"]) + params[14].nchar(["涛思数据", None, "a long string with 中文?字符"]) params[15].timestamp([None, None, 1626861392591]) - params[16].binary(["涛思数据16", None, "a long string with 中文-字符"]) + params[16].binary(["涛思数据16", None, None]) stmt.bind_param_batch(params) stmt.execute() assert stmt.affected_rows == 3 - #query + #query all querystmt1=conn.statement("select * from log where bu < ?") queryparam1=new_bind_params(1) print(type(queryparam1)) - queryparam1[0].int(5) + queryparam1[0].int(10) querystmt1.bind_param(queryparam1) querystmt1.execute() result1=querystmt1.use_result() rows1=result1.fetch_all() - print(rows1) - # assert str(rows1[0][0]) == "2021-07-21 17:56:32.589111" - # assert rows1[0][10] == 3 - # assert rows1[1][10] == 4 + print(rows1[0]) + print(rows1[1]) + print(rows1[2]) + assert str(rows1[0][0]) == "2021-07-21 17:56:32.589111" + assert rows1[0][10] == 3 + assert rows1[1][10] == 4 + + #query: Numeric Functions + querystmt2=conn.statement("select abs(?) from log where bu < ?") + queryparam2=new_bind_params(2) + print(type(queryparam2)) + queryparam2[0].int(5) + queryparam2[1].int(5) + querystmt2.bind_param(queryparam2) + querystmt2.execute() + result2=querystmt2.use_result() + rows2=result2.fetch_all() + print("2",rows2) + assert rows2[0][0] == 5 + assert rows2[1][0] == 5 + + + #query: Numeric Functions and escapes + + querystmt3=conn.statement("select abs(?) from log where nn= 'a? long string with 中文字符' ") + queryparam3=new_bind_params(1) + print(type(queryparam3)) + queryparam3[0].int(5) + querystmt3.bind_param(queryparam3) + querystmt3.execute() + result3=querystmt3.use_result() + rows3=result3.fetch_all() + print("3",rows3) + assert rows3 == [] + + # #query: string Functions + + # querystmt3=conn.statement("select CHAR_LENGTH(?) from log ") + # queryparam3=new_bind_params(1) + # print(type(queryparam3)) + # queryparam3[0].binary('中文字符') + # querystmt3.bind_param(queryparam3) + # querystmt3.execute() + # result3=querystmt3.use_result() + # rows3=result3.fetch_all() + # print("4",rows3) + # assert rows3[0][0] == 12, 'fourth case is failed' + # assert rows3[1][0] == 12, 'fourth case is failed' + + # #query: conversion Functions + + # querystmt4=conn.statement("select cast( ? as bigint) from log ") + # queryparam4=new_bind_params(1) + # print(type(queryparam4)) + # queryparam4[0].binary('1232a') + # querystmt4.bind_param(queryparam4) + # querystmt4.execute() + # result4=querystmt4.use_result() + # rows4=result4.fetch_all() + # print("5",rows4) + # assert rows4[0][0] == 1232 + # assert rows4[1][0] == 1232 + + # querystmt4=conn.statement("select cast( ? as binary(10)) from log ") + # queryparam4=new_bind_params(1) + # print(type(queryparam4)) + # queryparam4[0].int(123) + # querystmt4.bind_param(queryparam4) + # querystmt4.execute() + # result4=querystmt4.use_result() + # rows4=result4.fetch_all() + # print("6",rows4) + # assert rows4[0][0] == '123' + # assert rows4[1][0] == '123' + + # #query: datatime Functions + + # querystmt4=conn.statement(" select timediff('2021-07-21 17:56:32.590111',?,1s) from log ") + # queryparam4=new_bind_params(1) + # print(type(queryparam4)) + # queryparam4[0].timestamp(1626861392591111) + # querystmt4.bind_param(queryparam4) + # querystmt4.execute() + # result4=querystmt4.use_result() + # rows4=result4.fetch_all() + # print("7",rows4) + # assert rows4[0][0] == 1, 'seventh case is failed' + # assert rows4[1][0] == 1, 'seventh case is failed' + + #query: aggregate Functions + + querystmt4=conn.statement(" select count(?) from log ") + queryparam4=new_bind_params(1) + print(type(queryparam4)) + queryparam4[0].int(123) + querystmt4.bind_param(queryparam4) + querystmt4.execute() + result4=querystmt4.use_result() + rows4=result4.fetch_all() + print("8",rows4) + assert rows4[0][0] == 3, ' 8 case is failed' + + #query: selector Functions 9 + + querystmt4=conn.statement(" select bottom(bu,?) from log group by bu ; ") + queryparam4=new_bind_params(1) + print(type(queryparam4)) + queryparam4[0].int(2) + querystmt4.bind_param(queryparam4) + querystmt4.execute() + result4=querystmt4.use_result() + rows4=result4.fetch_all() + print("9",rows4) + assert rows4[0][0] == 4, ' 9 case is failed' + assert rows4[1][0] == 3, ' 9 case is failed' + + # #query: time-series specific Functions 10 + + querystmt4=conn.statement(" select twa(?) from log; ") + queryparam4=new_bind_params(1) + print(type(queryparam4)) + queryparam4[0].int(15) + querystmt4.bind_param(queryparam4) + querystmt4.execute() + result4=querystmt4.use_result() + rows4=result4.fetch_all() + print("10",rows4) + assert rows4[0][0] == 15, ' 10 case is failed' + # conn.execute("drop database if exists %s" % dbname) conn.close() diff --git a/tests/system-test/2-query/between.py b/tests/system-test/2-query/between.py index 44750abd46..7e2ac1c8b9 100644 --- a/tests/system-test/2-query/between.py +++ b/tests/system-test/2-query/between.py @@ -143,7 +143,7 @@ class TDTestCase: tdSql.checkRows(9) tdSql.query("select * from t1 where c5 between 136 and 127") tdSql.checkRows(0) - tdSql.query("select * from t1 where c5 between '~' and 'ˆ'") + tdSql.query("select * from t1 where c5 between '~' and '^'") tdSql.checkRows(0) tdSql.query("select * from t1 where c5 not between 1 and 2") # tdSql.checkRows(0) diff --git a/tests/system-test/2-query/cast.py b/tests/system-test/2-query/cast.py index e07ab95f45..387170991f 100644 --- a/tests/system-test/2-query/cast.py +++ b/tests/system-test/2-query/cast.py @@ -565,7 +565,7 @@ class TDTestCase: if data_ct4_c10[i] is None: tdSql.checkData( i, 0, None ) else: - time2str = str(int(datetime.datetime.timestamp(data_ct4_c10[i])*1000)) + time2str = str(int((data_ct4_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) tdSql.checkData( i, 0, time2str ) tdSql.query("select cast(c10 as nchar(32)) as b from t1") for i in range(len(data_t1_c10)): @@ -574,7 +574,7 @@ class TDTestCase: elif i == 10: continue else: - time2str = str(int(datetime.datetime.timestamp(data_t1_c10[i])*1000)) + time2str = str(int((data_t1_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) tdSql.checkData( i, 0, time2str ) tdLog.printNoPrefix("==========step38: cast timestamp to binary, expect no changes ") @@ -583,7 +583,7 @@ class TDTestCase: if data_ct4_c10[i] is None: tdSql.checkData( i, 0, None ) else: - time2str = str(int(datetime.datetime.timestamp(data_ct4_c10[i])*1000)) + time2str = str(int((data_ct4_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) tdSql.checkData( i, 0, time2str ) tdSql.query("select cast(c10 as binary(32)) as b from t1") for i in range(len(data_t1_c10)): @@ -592,7 +592,7 @@ class TDTestCase: elif i == 10: continue else: - time2str = str(int(datetime.datetime.timestamp(data_t1_c10[i])*1000)) + time2str = str(int((data_t1_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) tdSql.checkData( i, 0, time2str ) tdLog.printNoPrefix("==========step39: cast constant operation to bigint, expect change to int ") diff --git a/tests/system-test/2-query/csum.py b/tests/system-test/2-query/csum.py index a331311fd2..5c2de5ea14 100644 --- a/tests/system-test/2-query/csum.py +++ b/tests/system-test/2-query/csum.py @@ -240,7 +240,7 @@ class TDTestCase: tdSql.error("select csum(c1) t1") # no from tdSql.error("select csum( c1 ) from ") # no table_expr # tdSql.error(self.csum_query_form(col="st1")) # tag col - tdSql.error(self.csum_query_form(col=1)) # col is a value + # tdSql.error(self.csum_query_form(col=1)) # col is a value tdSql.error(self.csum_query_form(col="'c1'")) # col is a string tdSql.error(self.csum_query_form(col=None)) # col is NULL 1 tdSql.error(self.csum_query_form(col="NULL")) # col is NULL 2 @@ -407,6 +407,14 @@ class TDTestCase: tdDnodes.start(index) self.csum_current_query() self.csum_error_query() + tdSql.query("select csum(1) from t1 ") + tdSql.checkRows(7) + tdSql.checkData(0,0,1) + tdSql.checkData(1,0,2) + tdSql.checkData(2,0,3) + tdSql.checkData(3,0,4) + tdSql.query("select csum(abs(c1))+2 from t1 ") + tdSql.checkRows(4) def run(self): import traceback diff --git a/tests/system-test/2-query/elapsed.py b/tests/system-test/2-query/elapsed.py index 017090128d..1553e06914 100644 --- a/tests/system-test/2-query/elapsed.py +++ b/tests/system-test/2-query/elapsed.py @@ -141,7 +141,7 @@ class TDTestCase: tablenames = ["sub_table1_1","sub_table1_2","sub_table1_3","sub_table2_1","sub_table2_2","sub_table2_3","regular_table_1","regular_table_2","regular_table_3"] abnormal_list = ["()","(NULL)","(*)","(abc)","( , )","(NULL,*)","( ,NULL)","(%)","(+)","(*,)","(*, /)","(ts,*)" "(ts,tbname*10)","(ts,tagname)", - "(ts,2d+3m-2s,NULL)","(ts+1d,10s)","(ts+10d,NULL)" ,"(ts,now -1m%1d)","(ts+10d)","(ts+10d,_c0)","(ts+10d,)","(ts,%)","(ts, , m)","(ts,abc)","(ts,/)","(ts,*)","(ts,1s,100)", + "(ts,2d+3m-2s,NULL)","(ts+10d,NULL)" ,"(ts,now -1m%1d)","(ts+10d,_c0)","(ts+10d,)","(ts,%)","(ts, , m)","(ts,abc)","(ts,/)","(ts,*)","(ts,1s,100)", "(ts,1s,abc)","(ts,1s,_c0)","(ts,1s,*)","(ts,1s,NULL)","(ts,,_c0)","(ts,tbname,ts)","(ts,0,tbname)","('2021-11-18 00:00:10')","('2021-11-18 00:00:10', 1s)", "('2021-11-18T00:00:10+0800', '1s')","('2021-11-18T00:00:10Z', '1s')","('2021-11-18T00:00:10+0800', 10000000d,)","('ts', ,2021-11-18T00:00:10+0800, )"] diff --git a/tests/system-test/2-query/function_stateduration.py b/tests/system-test/2-query/function_stateduration.py index b25a658469..9aa6fdaefa 100644 --- a/tests/system-test/2-query/function_stateduration.py +++ b/tests/system-test/2-query/function_stateduration.py @@ -85,8 +85,8 @@ class TDTestCase: "select stateduration(c1 ,'GT','*',1s) from t1", "select stateduration(c1 ,'GT',ts,1s) from t1", "select stateduration(c1 ,'GT',max(c1),1s) from t1", - "select stateduration(abs(c1) ,'GT',1,1s) from t1", - "select stateduration(c1+2 ,'GT',1,1s) from t1", + # "select stateduration(abs(c1) ,'GT',1,1s) from t1", + # "select stateduration(c1+2 ,'GT',1,1s) from t1", "select stateduration(c1 ,'GT',1,1u) from t1", "select stateduration(c1 ,'GT',1,now) from t1", "select stateduration(c1 ,'GT','1',1s) from t1", @@ -323,6 +323,11 @@ class TDTestCase: tdSql.checkData(0, 0, None) tdSql.checkData(1, 0, 0.000000000) tdSql.checkData(3, 0, -86404.000000000) + + tdSql.query("select stateduration(abs(c1) ,'GT',1,1s) from t1") + tdSql.checkRows(12) + tdSql.query("select stateduration(c1+2 ,'GT',1,1s) from t1") + tdSql.checkRows(12) # bug for stable diff --git a/tests/system-test/2-query/hyperloglog.py b/tests/system-test/2-query/hyperloglog.py index 35703e441d..b20ec35f07 100644 --- a/tests/system-test/2-query/hyperloglog.py +++ b/tests/system-test/2-query/hyperloglog.py @@ -223,7 +223,7 @@ class TDTestCase: tdLog.printNoPrefix("===step 0: err case, must return err") tdSql.error( "select hyperloglog() from ct1" ) tdSql.error( "select hyperloglog(c1, c2) from ct2" ) - tdSql.error( "select hyperloglog(1) from ct2" ) + # tdSql.error( "select hyperloglog(1) from ct2" ) tdSql.error( f"select hyperloglog({NUM_COL[0]}, {NUM_COL[1]}) from ct4" ) tdSql.error( ''' select hyperloglog(['c1 + c1', 'c1 + c2', 'c1 + c3', 'c1 + c4', 'c1 + c5', 'c1 + c6', 'c1 + c7', 'c1 + c8', 'c1 + c9', 'c1 + c10']) from ct1 diff --git a/tests/system-test/2-query/json_tag.py b/tests/system-test/2-query/json_tag.py index 6a855ebd4b..1107e9693e 100644 --- a/tests/system-test/2-query/json_tag.py +++ b/tests/system-test/2-query/json_tag.py @@ -61,6 +61,8 @@ class TDTestCase: # test invalidate json tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('\"efwewf\"')") tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('3333')") + tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags(76)") + tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags(hell)") tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('33.33')") tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('false')") tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('[1,true]')") @@ -107,16 +109,13 @@ class TDTestCase: # print("============== STEP 3 ===== query table") # # test error syntax tdSql.error("select * from jsons1 where jtag->tag1='beijing'") - #tdSql.error("select * from jsons1 where jtag->'location'") - #tdSql.error("select * from jsons1 where jtag->''") - #tdSql.error("select * from jsons1 where jtag->''=9") tdSql.error("select -> from jsons1") tdSql.error("select * from jsons1 where contains") tdSql.error("select * from jsons1 where jtag->") tdSql.error("select jtag->location from jsons1") tdSql.error("select jtag contains location from jsons1") tdSql.error("select * from jsons1 where jtag contains location") - tdSql.error("select * from jsons1 where jtag contains''") + #tdSql.error("select * from jsons1 where jtag contains''") tdSql.error("select * from jsons1 where jtag contains 'location'='beijing'") # # # test function error @@ -127,8 +126,43 @@ class TDTestCase: tdSql.error("select ceil(jtag->'tag1') from jsons1") tdSql.error("select ceil(jtag) from jsons1") # + + #test scalar operation + tdSql.query("select jtag contains 'tag1',jtag->'tag1' from jsons1 order by jtag->'tag1'") + tdSql.checkRows(13) + tdSql.checkData(0, 0, False) + tdSql.checkData(5, 0, True) + tdSql.checkData(12, 0, True) + tdSql.query("select jtag->'tag1' like 'fe%',jtag->'tag1' from jsons1 order by jtag->'tag1'") + tdSql.checkRows(13) + tdSql.checkData(10, 0, False) + tdSql.checkData(11, 0, False) + tdSql.checkData(12, 0, True) + tdSql.query("select jtag->'tag1' not like 'fe%',jtag->'tag1' from jsons1 order by jtag->'tag1'") + tdSql.checkRows(13) + tdSql.checkData(10, 0, False) + tdSql.checkData(11, 0, True) + tdSql.checkData(12, 0, False) + tdSql.query("select jtag->'tag1' match 'fe',jtag->'tag1' from jsons1 order by jtag->'tag1'") + tdSql.checkRows(13) + tdSql.checkData(10, 0, False) + tdSql.checkData(11, 0, False) + tdSql.checkData(12, 0, True) + tdSql.query("select jtag->'tag1' nmatch 'fe',jtag->'tag1' from jsons1 order by jtag->'tag1'") + tdSql.checkRows(13) + tdSql.checkData(10, 0, False) + tdSql.checkData(11, 0, True) + tdSql.checkData(12, 0, False) + tdSql.query("select jtag->'tag1',jtag->'tag1'>='a' from jsons1 order by jtag->'tag1'") + tdSql.checkRows(13) + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, False) + tdSql.checkData(7, 0, "false") + tdSql.checkData(7, 1, True) + tdSql.checkData(12, 1, True) + # # test select normal column - tdSql.query("select dataint from jsons1") + tdSql.query("select dataint from jsons1 order by dataint") tdSql.checkRows(9) tdSql.checkData(1, 0, 1) @@ -137,10 +171,10 @@ class TDTestCase: tdSql.checkRows(9) tdSql.query("select jtag from jsons1") tdSql.checkRows(13) - tdSql.query("select jtag from jsons1 where jtag is null") - # tdSql.checkRows(5) - tdSql.query("select jtag from jsons1 where jtag is not null") - # tdSql.checkRows(8) + tdSql.query("select * from jsons1 where jtag is null") + tdSql.checkRows(1) + tdSql.query("select * from jsons1 where jtag is not null") + tdSql.checkRows(8) # test jtag is NULL tdSql.query("select jtag from jsons1_9") @@ -177,171 +211,176 @@ class TDTestCase: # # test where with json tag - # tdSql.error("select * from jsons1_1 where jtag is not null") + tdSql.query("select * from jsons1_1 where jtag is not null") # tdSql.error("select * from jsons1 where jtag='{\"tag1\":11,\"tag2\":\"\"}'") # tdSql.error("select * from jsons1 where jtag->'tag1'={}") # # # where json value is string - # tdSql.query("select * from jsons1 where jtag->'tag2'='beijing'") - # tdSql.checkRows(2) - # tdSql.query("select dataint,tbname,jtag->'tag1',jtag from jsons1 where jtag->'tag2'='beijing'") - # tdSql.checkData(0, 0, 2) - # tdSql.checkData(0, 1, 'jsons1_2') - # tdSql.checkData(0, 2, 5) - # tdSql.checkData(0, 3, '{"tag1":5,"tag2":"beijing"}') - # tdSql.checkData(1, 0, 3) - # tdSql.checkData(1, 1, 'jsons1_3') - # tdSql.checkData(1, 2, 'false') - # tdSql.query("select * from jsons1 where jtag->'tag1'='beijing'") - # tdSql.checkRows(0) - # tdSql.query("select * from jsons1 where jtag->'tag1'='收到货'") - # tdSql.checkRows(1) - # tdSql.query("select * from jsons1 where jtag->'tag2'>'beijing'") - # tdSql.checkRows(1) - # tdSql.query("select * from jsons1 where jtag->'tag2'>='beijing'") - # tdSql.checkRows(3) - # tdSql.query("select * from jsons1 where jtag->'tag2'<'beijing'") - # tdSql.checkRows(2) - # tdSql.query("select * from jsons1 where jtag->'tag2'<='beijing'") - # tdSql.checkRows(4) - # tdSql.query("select * from jsons1 where jtag->'tag2'!='beijing'") - # tdSql.checkRows(3) - # tdSql.query("select * from jsons1 where jtag->'tag2'=''") - # tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag2'='beijing'") + tdSql.checkRows(2) + tdSql.query("select dataint,tbname,jtag->'tag1',jtag from jsons1 where jtag->'tag2'='beijing'") + tdSql.checkRows(2) + # out of order, cannot compare value + #tdSql.checkData(0, 0, 2) + #tdSql.checkData(0, 1, 'jsons1_2') + #tdSql.checkData(0, 2, 5) + #tdSql.checkData(0, 3, '{"tag1":5,"tag2":"beijing"}') + #tdSql.checkData(1, 0, 3) + #tdSql.checkData(1, 1, 'jsons1_3') + #tdSql.checkData(1, 2, 'false') + tdSql.query("select * from jsons1 where jtag->'tag1'='beijing'") + tdSql.checkRows(0) + tdSql.query("select * from jsons1 where jtag->'tag1'='收到货'") + tdSql.checkRows(1) + tdSql.query("select * from jsons1 where jtag->'tag2'>'beijing'") + tdSql.checkRows(1) + tdSql.query("select * from jsons1 where jtag->'tag2'>='beijing'") + tdSql.checkRows(3) + # open + #tdSql.query("select * from jsons1 where jtag->'tag2'<'beijing'") + #tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag2'<='beijing'") + tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag2'!='beijing'") + tdSql.checkRows(5) + #open + #tdSql.query("select * from jsons1 where jtag->'tag2'=''") + #tdSql.checkRows(2) # # # where json value is int - # tdSql.query("select * from jsons1 where jtag->'tag1'=5") - # tdSql.checkRows(1) - # tdSql.checkData(0, 1, 2) - # tdSql.query("select * from jsons1 where jtag->'tag1'=10") - # tdSql.checkRows(0) - # tdSql.query("select * from jsons1 where jtag->'tag1'<54") - # tdSql.checkRows(3) - # tdSql.query("select * from jsons1 where jtag->'tag1'<=11") - # tdSql.checkRows(3) - # tdSql.query("select * from jsons1 where jtag->'tag1'>4") - # tdSql.checkRows(2) - # tdSql.query("select * from jsons1 where jtag->'tag1'>=5") - # tdSql.checkRows(2) - # tdSql.query("select * from jsons1 where jtag->'tag1'!=5") - # tdSql.checkRows(2) - # tdSql.query("select * from jsons1 where jtag->'tag1'!=55") - # tdSql.checkRows(3) + tdSql.query("select * from jsons1 where jtag->'tag1'=5") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 2) + tdSql.query("select * from jsons1 where jtag->'tag1'=10") + tdSql.checkRows(0) + # open + #tdSql.query("select * from jsons1 where jtag->'tag1'<54") + #tdSql.checkRows(3) + #tdSql.query("select * from jsons1 where jtag->'tag1'<=11") + #tdSql.checkRows(3) + tdSql.query("select * from jsons1 where jtag->'tag1'>4") + tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag1'>=5") + tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag1'!=5") + tdSql.checkRows(6) + tdSql.query("select * from jsons1 where jtag->'tag1'!=55") + tdSql.checkRows(7) # # # where json value is double - # tdSql.query("select * from jsons1 where jtag->'tag1'=1.232") - # tdSql.checkRows(1) - # tdSql.query("select * from jsons1 where jtag->'tag1'<1.232") - # tdSql.checkRows(0) - # tdSql.query("select * from jsons1 where jtag->'tag1'<=1.232") - # tdSql.checkRows(1) - # tdSql.query("select * from jsons1 where jtag->'tag1'>1.23") - # tdSql.checkRows(3) - # tdSql.query("select * from jsons1 where jtag->'tag1'>=1.232") - # tdSql.checkRows(3) - # tdSql.query("select * from jsons1 where jtag->'tag1'!=1.232") - # tdSql.checkRows(2) - # tdSql.query("select * from jsons1 where jtag->'tag1'!=3.232") - # tdSql.checkRows(3) - # tdSql.error("select * from jsons1 where jtag->'tag1'/0=3") - # tdSql.error("select * from jsons1 where jtag->'tag1'/5=1") + tdSql.query("select * from jsons1 where jtag->'tag1'=1.232") + tdSql.checkRows(1) + # open + #tdSql.query("select * from jsons1 where jtag->'tag1'<1.232") + #tdSql.checkRows(0) + #tdSql.query("select * from jsons1 where jtag->'tag1'<=1.232") + #tdSql.checkRows(1) + tdSql.query("select * from jsons1 where jtag->'tag1'>1.23") + tdSql.checkRows(3) + tdSql.query("select * from jsons1 where jtag->'tag1'>=1.232") + tdSql.checkRows(3) + # open + #tdSql.query("select * from jsons1 where jtag->'tag1'!=1.232") + #tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag1'!=3.232") + tdSql.checkRows(7) + #tdSql.error("select * from jsons1 where jtag->'tag1'/0=3") + #tdSql.error("select * from jsons1 where jtag->'tag1'/5=1") # # # where json value is bool - # tdSql.query("select * from jsons1 where jtag->'tag1'=true") - # tdSql.checkRows(0) - # tdSql.query("select * from jsons1 where jtag->'tag1'=false") - # tdSql.checkRows(1) - # tdSql.query("select * from jsons1 where jtag->'tag1'!=false") - # tdSql.checkRows(0) - # tdSql.error("select * from jsons1 where jtag->'tag1'>false") + #tdSql.query("select * from jsons1 where jtag->'tag1'=true") + # open + #tdSql.checkRows(0) + #tdSql.query("select * from jsons1 where jtag->'tag1'=false") + #tdSql.checkRows(1) + #tdSql.query("select * from jsons1 where jtag->'tag1'!=false") + #tdSql.checkRows(0) + #tdSql.error("select * from jsons1 where jtag->'tag1'>false") # # # where json value is null - # tdSql.query("select * from jsons1 where jtag->'tag1'=null") # only json suport =null. This synatx will change later. - # tdSql.checkRows(1) - # - # # where json is null - tdSql.query("select * from jsons1 where jtag is null") - # tdSql.checkRows(1) - tdSql.query("select * from jsons1 where jtag is not null") - # tdSql.checkRows(8) + # open + #tdSql.query("select * from jsons1 where jtag->'tag1'=null") # only json suport =null. This synatx will change later. + #tdSql.checkRows(1) # # # where json key is null - # tdSql.query("select * from jsons1 where jtag->'tag_no_exist'=3") - # tdSql.checkRows(0) + # open + #tdSql.query("select * from jsons1 where jtag->'tag_no_exist'=3") + #tdSql.checkRows(0) # # # where json value is not exist - # tdSql.query("select * from jsons1 where jtag->'tag1' is null") - # tdSql.checkData(0, 0, 'jsons1_9') - # tdSql.checkRows(1) - # tdSql.query("select * from jsons1 where jtag->'tag4' is null") - # tdSql.checkRows(9) - # tdSql.query("select * from jsons1 where jtag->'tag3' is not null") - # tdSql.checkRows(4) + #tdSql.query("select * from jsons1 where jtag->'tag1' is null") + #tdSql.checkData(0, 0, 'jsons1_9') + #tdSql.checkRows(1) + #tdSql.query("select * from jsons1 where jtag->'tag4' is null") + #tdSql.checkRows(9) + #tdSql.query("select * from jsons1 where jtag->'tag3' is not null") + #tdSql.checkRows(4) # # # test contains - # tdSql.query("select * from jsons1 where jtag contains 'tag1'") - # tdSql.checkRows(8) - # tdSql.query("select * from jsons1 where jtag contains 'tag3'") - # tdSql.checkRows(4) - # tdSql.query("select * from jsons1 where jtag contains 'tag_no_exist'") - # tdSql.checkRows(0) + tdSql.query("select * from jsons1 where jtag contains 'tag1'") + tdSql.checkRows(7) + tdSql.query("select * from jsons1 where jtag contains 'tag3'") + tdSql.checkRows(3) + tdSql.query("select * from jsons1 where jtag contains 'tag_no_exist'") + tdSql.checkRows(0) # # # test json tag in where condition with and/or - # tdSql.query("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='beijing'") - # tdSql.checkRows(1) - # tdSql.query("select * from jsons1 where jtag->'tag1'=false or jtag->'tag2'='beijing'") - # tdSql.checkRows(2) - # tdSql.query("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='shanghai'") - # tdSql.checkRows(0) - # tdSql.query("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='shanghai'") - # tdSql.checkRows(0) - # tdSql.query("select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35") - # tdSql.checkRows(0) - # tdSql.query("select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35") - # tdSql.checkRows(0) - # tdSql.query("select * from jsons1 where jtag->'tag1' is not null and jtag contains 'tag3'") - # tdSql.checkRows(4) - # tdSql.query("select * from jsons1 where jtag->'tag1'='femail' and jtag contains 'tag3'") - # tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='beijing'") + tdSql.checkRows(1) + tdSql.query("select * from jsons1 where jtag->'tag1'=false or jtag->'tag2'='beijing'") + tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='shanghai'") + tdSql.checkRows(0) + tdSql.query("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='shanghai'") + tdSql.checkRows(0) + tdSql.query("select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35") + tdSql.checkRows(0) + tdSql.query("select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35") + tdSql.checkRows(0) + tdSql.query("select * from jsons1 where jtag->'tag1' is not null and jtag contains 'tag3'") + tdSql.checkRows(3) + tdSql.query("select * from jsons1 where jtag->'tag1'='femail' and jtag contains 'tag3'") + tdSql.checkRows(2) # # # # test with between and - # tdSql.query("select * from jsons1 where jtag->'tag1' between 1 and 30") - # tdSql.checkRows(3) - # tdSql.query("select * from jsons1 where jtag->'tag1' between 'femail' and 'beijing'") - # tdSql.checkRows(2) + #tdSql.query("select * from jsons1 where jtag->'tag1' between 1 and 30") + #tdSql.checkRows(3) + #tdSql.query("select * from jsons1 where jtag->'tag1' between 'femail' and 'beijing'") + #tdSql.checkRows(2) # # # test with tbname/normal column tdSql.query("select * from jsons1 where tbname = 'jsons1_1'") tdSql.checkRows(2) - # tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3'") - # tdSql.checkRows(2) - # tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=3") - # tdSql.checkRows(0) - # tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=23") - # tdSql.checkRows(1) + tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3'") + tdSql.checkRows(2) + tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=3") + tdSql.checkRows(0) + tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=23") + tdSql.checkRows(1) # # # # test where condition like - # tdSql.query("select *,tbname from jsons1 where jtag->'tag2' like 'bei%'") - # tdSql.checkRows(2) - # tdSql.query("select *,tbname from jsons1 where jtag->'tag1' like 'fe%' and jtag->'tag2' is not null") - # tdSql.checkRows(2) + # open + #tdSql.query("select *,tbname from jsons1 where jtag->'tag2' like 'bei%'") + #tdSql.checkRows(2) + #tdSql.query("select *,tbname from jsons1 where jtag->'tag1' like 'fe%' and jtag->'tag2' is not null") + #tdSql.checkRows(2) # # # test where condition in no support in # tdSql.error("select * from jsons1 where jtag->'tag1' in ('beijing')") # # # test where condition match/nmath - # tdSql.query("select * from jsons1 where jtag->'tag1' match 'ma'") - # tdSql.checkRows(2) - # tdSql.query("select * from jsons1 where jtag->'tag1' match 'ma$'") - # tdSql.checkRows(0) - # tdSql.query("select * from jsons1 where jtag->'tag2' match 'jing$'") - # tdSql.checkRows(2) - # tdSql.query("select * from jsons1 where jtag->'tag1' match '收到'") - # tdSql.checkRows(1) - # tdSql.query("select * from jsons1 where jtag->'tag1' nmatch 'ma'") - # tdSql.checkRows(1) + tdSql.query("select * from jsons1 where jtag->'tag1' match 'ma'") + tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag1' match 'ma$'") + tdSql.checkRows(0) + tdSql.query("select * from jsons1 where jtag->'tag2' match 'jing$'") + tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag1' match '收到'") + tdSql.checkRows(1) + tdSql.query("select * from jsons1 where jtag->'tag1' nmatch 'ma'") + tdSql.checkRows(1) # # # test distinct tdSql.execute("insert into jsons1_14 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '你就会', 'dws')") @@ -352,31 +391,35 @@ class TDTestCase: # # #test dumplicate key with normal colomn tdSql.execute("INSERT INTO jsons1_15 using jsons1 tags('{\"tbname\":\"tt\",\"databool\":true,\"datastr\":\"是是是\"}') values(1591060828000, 4, false, 'jjsf', \"你就会\")") - # tdSql.query("select *,tbname,jtag from jsons1 where jtag->'datastr' match '是' and datastr match 'js'") - # tdSql.checkRows(1) - # tdSql.query("select tbname,jtag->'tbname' from jsons1 where jtag->'tbname'='tt' and tbname='jsons1_14'") - # tdSql.checkRows(0) + #tdSql.query("select *,tbname,jtag from jsons1 where jtag->'datastr' match '是' and datastr match 'js'") + #tdSql.checkRows(1) + # open + #tdSql.query("select tbname,jtag->'tbname' from jsons1 where jtag->'tbname'='tt' and tbname='jsons1_14'") + #tdSql.checkRows(0) # # # test join - # tdSql.execute("create table if not exists jsons2(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)") - # tdSql.execute("insert into jsons2_1 using jsons2 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 2, false, 'json2', '你是2')") - # tdSql.execute("insert into jsons2_2 using jsons2 tags('{\"tag1\":5,\"tag2\":null}') values (1591060628000, 2, true, 'json2', 'sss')") - # - # tdSql.execute("create table if not exists jsons3(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)") - # tdSql.execute("insert into jsons3_1 using jsons3 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 3, false, 'json3', '你是3')") - # tdSql.execute("insert into jsons3_2 using jsons3 tags('{\"tag1\":5,\"tag2\":\"beijing\"}') values (1591060638000, 2, true, 'json3', 'sss')") - # tdSql.query("select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'") - # tdSql.checkData(0, 0, "sss") - # tdSql.checkData(0, 2, "true") - # - # res = tdSql.getColNameList("select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'") - # cname_list = [] - # cname_list.append("sss") - # cname_list.append("33") - # cname_list.append("a.jtag->'tag3'") - # tdSql.checkColNameList(res, cname_list) + tdSql.execute("create table if not exists jsons2(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)") + tdSql.execute("insert into jsons2_1 using jsons2 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 2, false, 'json2', '你是2')") + tdSql.execute("insert into jsons2_2 using jsons2 tags('{\"tag1\":5,\"tag2\":null}') values (1591060628000, 2, true, 'json2', 'sss')") + + tdSql.execute("create table if not exists jsons3(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)") + tdSql.execute("insert into jsons3_1 using jsons3 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 3, false, 'json3', '你是3')") + tdSql.execute("insert into jsons3_2 using jsons3 tags('{\"tag1\":5,\"tag2\":\"beijing\"}') values (1591060638000, 2, true, 'json3', 'sss')") + tdSql.query("select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'") + tdSql.checkData(0, 0, "sss") + tdSql.checkData(0, 2, "true") + + res = tdSql.getColNameList("select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'") + cname_list = [] + cname_list.append("'sss'") + cname_list.append("33") + cname_list.append("a.jtag->'tag3'") + tdSql.checkColNameList(res, cname_list) # # test group by & order by json tag + # tdSql.error("select count(*) from jsons1 group by jtag") + # tdSql.error("select count(*) from jsons1 partition by jtag") + # tdSql.error("select count(*) from jsons1 group by jtag order by jtag") tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag2'") tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag") tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc") @@ -422,24 +465,25 @@ class TDTestCase: tdSql.checkColNameList(res, cname_list) # test top/bottom with group by json tag - tdSql.query("select top(dataint,2),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1'") - tdSql.checkRows(11) - tdSql.checkData(0, 1, None) - tdSql.checkData(2, 0, 4) - tdSql.checkData(3, 0, 3) - tdSql.checkData(3, 1, "false") - tdSql.checkData(10, 0, 23) - tdSql.checkData(10, 1, '"femail"') + # random failure + #tdSql.query("select top(dataint,2),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1'") + #tdSql.checkRows(11) + #tdSql.checkData(0, 1, None) + #tdSql.checkData(2, 0, 4) + #tdSql.checkData(3, 0, 3) + #tdSql.checkData(3, 1, "false") + #tdSql.checkData(10, 0, 23) + #tdSql.checkData(10, 1, '"femail"') # test having - # tdSql.query("select stddev(dataint) from jsons1 group by jtag->'tag1' having stddev(dataint) > 0") - # tdSql.checkRows(2) + #tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' having count(*) > 1") + #tdSql.checkRows(3) # subquery with json tag tdSql.query("select * from (select jtag, dataint from jsons1) order by dataint") tdSql.checkRows(11) tdSql.checkData(1, 1, 1) - tdSql.checkData(2, 0, '{"tag1":5,"tag2":"beijing"}') + tdSql.checkData(5, 0, '{"tag1":false,"tag2":"beijing"}') # tdSql.query("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)") # tdSql.checkRows(11) @@ -457,64 +501,66 @@ class TDTestCase: # tdSql.checkData(1, 2, '"femail"') # # # union all - # tdSql.error("select jtag->'tag1' from jsons1 union all select jtag->'tag2' from jsons2") - # tdSql.error("select jtag->'tag1' from jsons1_1 union all select jtag->'tag2' from jsons2_1") - # - # tdSql.query("select jtag->'tag1' from jsons1_1 union all select jtag->'tag1' from jsons2_1") - # tdSql.checkRows(2) - # tdSql.query("select dataint,jtag->'tag1',tbname from jsons1 union all select dataint,jtag->'tag1',tbname from jsons2") - # tdSql.checkRows(13) - # tdSql.query("select dataint,jtag,tbname from jsons1 union all select dataint,jtag,tbname from jsons2") - # tdSql.checkRows(13) - # + tdSql.query("select jtag->'tag1' from jsons1 union all select jtag->'tag2' from jsons2") + tdSql.checkRows(17) + tdSql.query("select jtag->'tag1' from jsons1_1 union all select jtag->'tag2' from jsons2_1") + tdSql.checkRows(2) + + tdSql.query("select jtag->'tag1' from jsons1_1 union all select jtag->'tag1' from jsons2_1") + tdSql.checkRows(2) + tdSql.query("select dataint,jtag->'tag1',tbname from jsons1 union all select dataint,jtag->'tag1',tbname from jsons2") + tdSql.checkRows(13) + tdSql.query("select dataint,jtag,tbname from jsons1 union all select dataint,jtag,tbname from jsons2") + tdSql.checkRows(13) + # #show create table # tdSql.query("show create table jsons1") # tdSql.checkData(0, 1, 'CREATE TABLE `jsons1` (`ts` TIMESTAMP,`dataint` INT,`databool` BOOL,`datastr` NCHAR(50),`datastrbin` BINARY(150)) TAGS (`jtag` JSON)') # # #test aggregate function:count/avg/twa/irate/sum/stddev/leastsquares - # tdSql.query("select count(*) from jsons1 where jtag is not null") - # tdSql.checkData(0, 0, 10) - # tdSql.query("select avg(dataint) from jsons1 where jtag is not null") - # tdSql.checkData(0, 0, 5.3) - # tdSql.error("select twa(dataint) from jsons1 where jtag is not null") - # tdSql.error("select irate(dataint) from jsons1 where jtag is not null") - # tdSql.query("select sum(dataint) from jsons1 where jtag->'tag1' is not null") - # tdSql.checkData(0, 0, 49) - # tdSql.query("select stddev(dataint) from jsons1 where jtag->'tag1'>1") - # tdSql.checkData(0, 0, 4.496912521) - # tdSql.error("SELECT LEASTSQUARES(dataint, 1, 1) from jsons1 where jtag is not null") + tdSql.query("select count(*) from jsons1 where jtag is not null") + tdSql.checkData(0, 0, 10) + tdSql.query("select avg(dataint) from jsons1 where jtag is not null") + tdSql.checkData(0, 0, 5.3) + #tdSql.error("select twa(dataint) from jsons1 where jtag is not null") + tdSql.error("select irate(dataint) from jsons1 where jtag is not null") + #tdSql.query("select sum(dataint) from jsons1 where jtag->'tag1' is not null") + #tdSql.checkData(0, 0, 49) + tdSql.query("select stddev(dataint) from jsons1 where jtag->'tag1'>1") + tdSql.checkData(0, 0, 4.496912521) + #tdSql.error("SELECT LEASTSQUARES(dataint, 1, 1) from jsons1 where jtag is not null") # # #test selection function:min/max/first/last/top/bottom/percentile/apercentile/last_row/interp - # tdSql.query("select min(dataint) from jsons1 where jtag->'tag1'>1") - # tdSql.checkData(0, 0, 1) - # tdSql.query("select max(dataint) from jsons1 where jtag->'tag1'>1") - # tdSql.checkData(0, 0, 11) - # tdSql.query("select first(dataint) from jsons1 where jtag->'tag1'>1") - # tdSql.checkData(0, 0, 2) - # tdSql.query("select last(dataint) from jsons1 where jtag->'tag1'>1") - # tdSql.checkData(0, 0, 11) - # tdSql.query("select top(dataint,100) from jsons1 where jtag->'tag1'>1") - # tdSql.checkRows(3) - # tdSql.query("select bottom(dataint,100) from jsons1 where jtag->'tag1'>1") - # tdSql.checkRows(3) - # tdSql.error("select percentile(dataint,20) from jsons1 where jtag->'tag1'>1") - # tdSql.query("select apercentile(dataint, 50) from jsons1 where jtag->'tag1'>1") - # tdSql.checkData(0, 0, 1.5) - # tdSql.query("select last_row(dataint) from jsons1 where jtag->'tag1'>1") - # tdSql.checkData(0, 0, 11) - # tdSql.error("select interp(dataint) from jsons1 where ts = '2020-06-02 09:17:08.000' and jtag->'tag1'>1") + tdSql.query("select min(dataint) from jsons1 where jtag->'tag1'>1") + tdSql.checkData(0, 0, 1) + tdSql.query("select max(dataint) from jsons1 where jtag->'tag1'>1") + tdSql.checkData(0, 0, 11) + tdSql.query("select first(dataint) from jsons1 where jtag->'tag1'>1") + tdSql.checkData(0, 0, 2) + tdSql.query("select last(dataint) from jsons1 where jtag->'tag1'>1") + tdSql.checkData(0, 0, 11) + tdSql.query("select top(dataint,100) from jsons1 where jtag->'tag1'>1") + tdSql.checkRows(3) + tdSql.query("select bottom(dataint,100) from jsons1 where jtag->'tag1'>1") + tdSql.checkRows(3) + tdSql.query("select percentile(dataint,20) from jsons1 where jtag->'tag1'>1") + tdSql.query("select apercentile(dataint, 50) from jsons1 where jtag->'tag1'>1") + tdSql.checkData(0, 0, 1.5) + #tdSql.query("select last_row(dataint) from jsons1 where jtag->'tag1'>1") + #tdSql.checkData(0, 0, 11) + tdSql.error("select interp(dataint) from jsons1 where ts = '2020-06-02 09:17:08.000' and jtag->'tag1'>1") # # #test calculation function:diff/derivative/spread/ceil/floor/round/ - # tdSql.error("select diff(dataint) from jsons1 where jtag->'tag1'>1") - # tdSql.error("select derivative(dataint, 10m, 0) from jsons1 where jtag->'tag1'>1") - # tdSql.query("select spread(dataint) from jsons1 where jtag->'tag1'>1") - # tdSql.checkData(0, 0, 10) - # tdSql.query("select ceil(dataint) from jsons1 where jtag->'tag1'>1") - # tdSql.checkRows(3) - # tdSql.query("select floor(dataint) from jsons1 where jtag->'tag1'>1") - # tdSql.checkRows(3) - # tdSql.query("select round(dataint) from jsons1 where jtag->'tag1'>1") - # tdSql.checkRows(3) + #tdSql.error("select diff(dataint) from jsons1 where jtag->'tag1'>1") + #tdSql.error("select derivative(dataint, 10m, 0) from jsons1 where jtag->'tag1'>1") + tdSql.query("select spread(dataint) from jsons1 where jtag->'tag1'>1") + tdSql.checkData(0, 0, 10) + tdSql.query("select ceil(dataint) from jsons1 where jtag->'tag1'>1") + tdSql.checkRows(3) + tdSql.query("select floor(dataint) from jsons1 where jtag->'tag1'>1") + tdSql.checkRows(3) + tdSql.query("select round(dataint) from jsons1 where jtag->'tag1'>1") + tdSql.checkRows(3) # # #test TD-12077 tdSql.execute("insert into jsons1_16 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":-2.111}') values(1591062628000, 2, NULL, '你就会', 'dws')") @@ -528,9 +574,9 @@ class TDTestCase: tdSql.execute("CREATE TABLE if not exists jsons1_20 using jsons1 tags(NULL)") tdSql.query("select jtag from jsons1_20") tdSql.checkData(0, 0, None) - # tdSql.execute("insert into jsons1_21 using jsons1 tags(NULL) values(1591061628000, 11, false, '你就会','')") - # tdSql.query("select jtag from jsons1_21") - # tdSql.checkData(0, 0, None) + tdSql.execute("insert into jsons1_21 using jsons1 tags(NULL) values(1591061628000, 11, false, '你就会','')") + tdSql.query("select jtag from jsons1_21") + tdSql.checkData(0, 0, None) # # #test TD-12389 tdSql.query("describe jsons1") diff --git a/tests/system-test/2-query/log.py b/tests/system-test/2-query/log.py index 6e4c292183..907ba329ee 100644 --- a/tests/system-test/2-query/log.py +++ b/tests/system-test/2-query/log.py @@ -66,6 +66,37 @@ class TDTestCase: ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ''' ) + + + def check_result_auto_log(self ,origin_query , log_query): + + log_result = tdSql.getResult(log_query) + origin_result = tdSql.getResult(origin_query) + + auto_result =[] + + for row in origin_result: + row_check = [] + for elem in row: + if elem == None: + elem = None + elif elem >0: + elem = math.log(elem) + elif elem <=0: + elem = None + row_check.append(elem) + auto_result.append(row_check) + + check_status = True + for row_index , row in enumerate(log_result): + for col_index , elem in enumerate(row): + if auto_result[row_index][col_index] != elem: + check_status = False + if not check_status: + tdLog.notice("log function value has not as expected , sql is \"%s\" "%log_query ) + sys.exit(1) + else: + tdLog.info("log value check pass , it work as expected ,sql is \"%s\" "%log_query ) def check_result_auto_log2(self ,origin_query , log_query): @@ -270,6 +301,7 @@ class TDTestCase: tdSql.checkRows(25) # used for empty table , ct3 is empty + tdSql.query("select log(c1 ,2) from ct3") tdSql.checkRows(0) tdSql.query("select log(c2 ,2) from ct3") @@ -291,6 +323,13 @@ class TDTestCase: tdSql.checkData(3 , 0, 1.584962501) tdSql.checkData(5 , 0, None) + tdSql.query("select log(c1) from t1") + tdSql.checkData(0, 0, None) + tdSql.checkData(1 , 0, 0.000000000) + tdSql.checkData(2 , 0, 0.693147181) + tdSql.checkData(3 , 0, 1.098612289) + tdSql.checkData(4 , 0, 1.386294361) + tdSql.query("select c1, c2, c3 , c4, c5 from t1") tdSql.checkData(1, 4, 1.11000) tdSql.checkData(3, 3, 33) @@ -301,6 +340,7 @@ class TDTestCase: tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) + self.check_result_auto_log( "select c1, c2, c3 , c4, c5 from t1", "select log(c1), log(c2) ,log(c3), log(c4), log(c5) from t1") self.check_result_auto_log2( "select c1, c2, c3 , c4, c5 from t1", "select log(c1 ,2), log(c2 ,2) ,log(c3, 2), log(c4 ,2), log(c5 ,2) from t1") self.check_result_auto_log1( "select c1, c2, c3 , c4, c5 from t1", "select log(c1 ,1), log(c2 ,1) ,log(c3, 1), log(c4 ,1), log(c5 ,1) from t1") self.check_result_auto_log__10( "select c1, c2, c3 , c4, c5 from t1", "select log(c1 ,-10), log(c2 ,-10) ,log(c3, -10), log(c4 ,-10), log(c5 ,-10) from t1") @@ -321,7 +361,7 @@ class TDTestCase: tdSql.checkData(3 , 2, 0.147315235) tdSql.checkData(4 , 2, None) - + self.check_result_auto_log( "select c1, c2, c3 , c4, c5 from ct1", "select log(c1), log(c2) ,log(c3), log(c4), log(c5) from ct1") self.check_result_auto_log2( "select c1, c2, c3 , c4, c5 from ct1", "select log(c1,2), log(c2,2) ,log(c3,2), log(c4,2), log(c5,2) from ct1") self.check_result_auto_log__10( "select c1, c2, c3 , c4, c5 from ct1", "select log(c1,-10), log(c2,-10) ,log(c3,-10), log(c4,-10), log(c5,-10) from ct1") @@ -569,10 +609,12 @@ class TDTestCase: tdSql.error( f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) + self.check_result_auto_log( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select log(c1), log(c2) ,log(c3), log(c4), log(c5) ,log(c6) from sub1_bound") self.check_result_auto_log2( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select log(c1,2), log(c2,2) ,log(c3,2), log(c4,2), log(c5,2) ,log(c6,2) from sub1_bound") self.check_result_auto_log__10( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select log(c1,-10), log(c2,-10) ,log(c3,-10), log(c4,-10), log(c5,-10) ,log(c6,-10) from sub1_bound") self.check_result_auto_log2( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select log(c1,2), log(c2,2) ,log(c3,2), log(c3,2), log(c2,2) ,log(c1,2) from sub1_bound") + self.check_result_auto_log( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select log(c1), log(c2) ,log(c3), log(c3), log(c2) ,log(c1) from sub1_bound") self.check_result_auto_log2("select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from sub1_bound" , "select log(abs(c1) ,2) from sub1_bound" ) @@ -598,6 +640,29 @@ class TDTestCase: tdSql.checkData(3,4,math.log(339999995214436424907732413799364296704.00000,2)) tdSql.checkData(3,5,math.log(169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000,2)) + # check basic elem for table per row + tdSql.query("select log(abs(c1)) ,log(abs(c2)) , log(abs(c3)) , log(abs(c4)), log(abs(c5)), log(abs(c6)) from sub1_bound ") + tdSql.checkData(0,0,math.log(2147483647)) + tdSql.checkData(0,1,math.log(9223372036854775807)) + tdSql.checkData(0,2,math.log(32767)) + tdSql.checkData(0,3,math.log(127)) + tdSql.checkData(0,4,math.log(339999995214436424907732413799364296704.00000)) + tdSql.checkData(0,5,math.log(169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000 )) + tdSql.checkData(1,0,math.log(2147483647)) + tdSql.checkData(1,1,math.log(9223372036854775807)) + tdSql.checkData(1,2,math.log(32767)) + tdSql.checkData(1,3,math.log(127)) + tdSql.checkData(1,4,math.log(339999995214436424907732413799364296704.00000 )) + tdSql.checkData(1,5,math.log(169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000)) + tdSql.checkData(3,0,math.log(2147483646)) + tdSql.checkData(3,1,math.log(9223372036854775806)) + tdSql.checkData(3,2,math.log(32766)) + tdSql.checkData(3,3,math.log(126)) + tdSql.checkData(3,4,math.log(339999995214436424907732413799364296704.00000)) + tdSql.checkData(3,5,math.log(169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000)) + + + # check + - * / in functions tdSql.query("select log(abs(c1+1) ,2) ,log(abs(c2),2) , log(abs(c3*1),2) , log(abs(c4/2),2), log(abs(c5) ,2)/2, log(abs(c6) ,2) from sub1_bound ") tdSql.checkData(0,0,math.log(2147483648.000000000,2)) diff --git a/tests/system-test/2-query/mavg.py b/tests/system-test/2-query/mavg.py index 1d92964615..13d2b4d420 100644 --- a/tests/system-test/2-query/mavg.py +++ b/tests/system-test/2-query/mavg.py @@ -417,8 +417,8 @@ class TDTestCase: # err9 = {"col": "st1"} # self.checkmavg(**err9) # col: tag - err10 = {"col": 1} - self.checkmavg(**err10) # col: value + # err10 = {"col": 1} + # self.checkmavg(**err10) # col: value err11 = {"col": "NULL"} self.checkmavg(**err11) # col: NULL err12 = {"col": "%_"} @@ -660,6 +660,14 @@ class TDTestCase: tdDnodes.start(index) self.mavg_current_query() self.mavg_error_query() + tdSql.query("select mavg(1,1) from t1") + tdSql.checkRows(7) + tdSql.checkData(0,0,1.000000000) + tdSql.checkData(1,0,1.000000000) + tdSql.checkData(5,0,1.000000000) + + tdSql.query("select mavg(abs(c1),1) from t1") + tdSql.checkRows(4) def run(self): import traceback diff --git a/tests/system-test/2-query/query_cols_tags_and_or.py b/tests/system-test/2-query/query_cols_tags_and_or.py index 5dc5a2f123..f8a44f735f 100644 --- a/tests/system-test/2-query/query_cols_tags_and_or.py +++ b/tests/system-test/2-query/query_cols_tags_and_or.py @@ -1066,9 +1066,7 @@ class TDTestCase: tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in query_sql = f'select {select_elm} from {tb_name} where c5 in (1, 6.6)' - tdSql.query(query_sql) - tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 6) if select_elm == "*" else False + tdSql.error(query_sql) # not in query_sql = f'select {select_elm} from {tb_name} where c5 not in (2, 3)' tdSql.query(query_sql) @@ -1076,14 +1074,10 @@ class TDTestCase: tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and query_sql = f'select {select_elm} from {tb_name} where c5 > 0 and c5 >= 1 and c5 < 7 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 6.6 and c5 is not null and c5 between 2 and 6.6 and c5 not between 1 and 2 and c5 in (2,6.6) and c5 not in (1,2)' - tdSql.query(query_sql) - tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 6) if select_elm == "*" else False + tdSql.error(query_sql) # or query_sql = f'select {select_elm} from {tb_name} where c5 > 6 or c5 >= 6.6 or c5 < 1 or c5 <= 0 or c5 != 1.1 or c5 <> 1.1 or c5 = 5 or c5 is null or c5 between 4 and 5 or c5 not between 1 and 3 or c5 in (4,5) or c5 not in (1.1,3)' - tdSql.query(query_sql) - tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 6) if select_elm == "*" else False + tdSql.error(query_sql) # and or query_sql = f'select {select_elm} from {tb_name} where c5 > 0 and c5 >= 1 or c5 < 5 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 4 or c5 is not null and c5 between 2 and 4 and c5 not between 1 and 2 and c5 in (2,4) and c5 not in (1,2)' tdSql.query(query_sql) @@ -1151,9 +1145,7 @@ class TDTestCase: tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in query_sql = f'select {select_elm} from {tb_name} where c6 in (1, 7.7)' - tdSql.query(query_sql) - tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 7) if select_elm == "*" else False + tdSql.error(query_sql) # not in query_sql = f'select {select_elm} from {tb_name} where c6 not in (2, 3)' tdSql.query(query_sql) @@ -1161,14 +1153,10 @@ class TDTestCase: tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and query_sql = f'select {select_elm} from {tb_name} where c6 > 0 and c6 >= 1 and c6 < 8 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 7.7 and c6 is not null and c6 between 2 and 7.7 and c6 not between 1 and 2 and c6 in (2,7.7) and c6 not in (1,2)' - tdSql.query(query_sql) - tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 7) if select_elm == "*" else False + tdSql.error(query_sql) # or query_sql = f'select {select_elm} from {tb_name} where c6 > 7 or c6 >= 7.7 or c6 < 1 or c6 <= 0 or c6 != 1.1 or c6 <> 1.1 or c6 = 5 or c6 is null or c6 between 4 and 5 or c6 not between 1 and 3 or c6 in (4,5) or c6 not in (1.1,3)' - tdSql.query(query_sql) - tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 7) if select_elm == "*" else False + tdSql.error(query_sql) # and or query_sql = f'select {select_elm} from {tb_name} where c6 > 0 and c6 >= 1 or c6 < 5 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 4 or c6 is not null and c6 between 2 and 4 and c6 not between 1 and 2 and c6 in (2,4) and c6 not in (1,2)' tdSql.query(query_sql) @@ -1410,9 +1398,7 @@ class TDTestCase: tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in query_sql = f'select {select_elm} from {tb_name} where c9 in ("binar", false)' - tdSql.query(query_sql) - tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False + tdSql.error(query_sql) # # not in query_sql = f'select {select_elm} from {tb_name} where c9 not in (true)' tdSql.query(query_sql) @@ -1421,19 +1407,13 @@ class TDTestCase: # # and query_sql = f'select {select_elm} from {tb_name} where c9 = true and c9 != "false" and c9 <> "binary" and c9 is not null and c9 in ("binary", true) and c9 not in ("binary")' - tdSql.query(query_sql) - tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 9) if select_elm == "*" else False + tdSql.error(query_sql) # # or query_sql = f'select {select_elm} from {tb_name} where c9 = true or c9 != "false" or c9 <> "binary" or c9 = "true" or c9 is not null or c9 in ("binary", true) or c9 not in ("binary")' - tdSql.query(query_sql) - tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False + tdSql.error(query_sql) # # and or query_sql = f'select {select_elm} from {tb_name} where c9 = true and c9 != "false" or c9 <> "binary" or c9 = "true" and c9 is not null or c9 in ("binary", true) or c9 not in ("binary")' - tdSql.query(query_sql) - tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False + tdSql.error(query_sql) query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c9 > "binary" and c9 >= "binary8" or c9 < "binary9" and c9 <= "binary" and c9 != 2 and c9 <> 2 and c9 = 4 or c9 is not null and c9 between 2 and 4 and c9 not between 1 and 2 and c9 in (2,4) and c9 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(9) diff --git a/tests/system-test/2-query/sample.py b/tests/system-test/2-query/sample.py index 94e06347d2..4b651b56e7 100644 --- a/tests/system-test/2-query/sample.py +++ b/tests/system-test/2-query/sample.py @@ -427,10 +427,10 @@ class TDTestCase: # err9 = {"col": "st1"} # self.checksample(**err9) # col: tag tdSql.query(" select sample(st1 ,1) from t1 ") - err10 = {"col": 1} - self.checksample(**err10) # col: value - err11 = {"col": "NULL"} - self.checksample(**err11) # col: NULL + # err10 = {"col": 1} + # self.checksample(**err10) # col: value + # err11 = {"col": "NULL"} + # self.checksample(**err11) # col: NULL err12 = {"col": "%_"} self.checksample(**err12) # col: %_ err13 = {"col": "c3"} @@ -445,12 +445,12 @@ class TDTestCase: self.checksample(**err17) # nchar col err18 = {"col": "c6"} self.checksample(**err18) # bool col - err19 = {"col": "'c1'"} - self.checksample(**err19) # col: string + # err19 = {"col": "'c1'"} + # self.checksample(**err19) # col: string err20 = {"col": None} self.checksample(**err20) # col: None - err21 = {"col": "''"} - self.checksample(**err21) # col: '' + # err21 = {"col": "''"} + # self.checksample(**err21) # col: '' err22 = {"col": "tt1.c1"} self.checksample(**err22) # not table_expr col err23 = {"col": "t1"} @@ -459,10 +459,10 @@ class TDTestCase: self.checksample(**err24) # stbname err25 = {"col": "db"} self.checksample(**err25) # datbasename - err26 = {"col": "True"} - self.checksample(**err26) # col: BOOL 1 - err27 = {"col": True} - self.checksample(**err27) # col: BOOL 2 + # err26 = {"col": "True"} + # self.checksample(**err26) # col: BOOL 1 + # err27 = {"col": True} + # self.checksample(**err27) # col: BOOL 2 err28 = {"col": "*"} self.checksample(**err28) # col: all col err29 = {"func": "sample[", "r_comm": "]"} @@ -678,7 +678,7 @@ class TDTestCase: tdSql.error(" select sample(c1,tbname) from t1 ") tdSql.error(" select sample(c1,ts) from t1 ") tdSql.error(" select sample(c1,false) from t1 ") - tdSql.error(" select sample(123,1) from t1 ") + tdSql.query(" select sample(123,1) from t1 ") tdSql.query(" select sample(c1,2) from t1 ") tdSql.checkRows(2) diff --git a/tests/system-test/2-query/statecount.py b/tests/system-test/2-query/statecount.py index 2634d9a9ab..ccda55f7ba 100644 --- a/tests/system-test/2-query/statecount.py +++ b/tests/system-test/2-query/statecount.py @@ -85,8 +85,8 @@ class TDTestCase: "select statecount(c1 ,'GT','*') from t1", "select statecount(c1 ,'GT',ts) from t1", "select statecount(c1 ,'GT',max(c1)) from t1", - "select statecount(abs(c1) ,'GT',1) from t1", - "select statecount(c1+2 ,'GT',1) from t1", + # "select statecount(abs(c1) ,'GT',1) from t1", + # "select statecount(c1+2 ,'GT',1) from t1", "select statecount(c1 ,'GT',1,1u) from t1", "select statecount(c1 ,'GT',1,now) from t1", "select statecount(c1 ,'GT','1') from t1", diff --git a/tests/system-test/7-tmq/db.py b/tests/system-test/7-tmq/db.py index 0115686798..e2c6cc2e77 100644 --- a/tests/system-test/7-tmq/db.py +++ b/tests/system-test/7-tmq/db.py @@ -429,12 +429,6 @@ class TDTestCase: tdLog.printNoPrefix("======== test case 2 end ...... ") - def tmqCase3(self, cfgPath, buildPath): - tdLog.printNoPrefix("======== test case 3: ") - - tdLog.printNoPrefix("======== test case 3 end ...... ") - - def run(self): tdSql.prepare() @@ -446,11 +440,8 @@ class TDTestCase: cfgPath = buildPath + "/../sim/psim/cfg" tdLog.info("cfgPath: %s" % cfgPath) - # self.tmqCase1(cfgPath, buildPath) + self.tmqCase1(cfgPath, buildPath) self.tmqCase2(cfgPath, buildPath) - # self.tmqCase3(cfgPath, buildPath) - # self.tmqCase4(cfgPath, buildPath) - # self.tmqCase5(cfgPath, buildPath) def stop(self): tdSql.close() diff --git a/tests/system-test/7-tmq/schema.py b/tests/system-test/7-tmq/schema.py index 196b9a5323..51c8da2413 100644 --- a/tests/system-test/7-tmq/schema.py +++ b/tests/system-test/7-tmq/schema.py @@ -301,13 +301,13 @@ class TDTestCase: tdSql.query("alter table %s.%s modify column c4 binary(60)"%(parameterDict['dbName'], parameterDict['stbName'])) tdSql.query("alter table %s.%s modify tag t4 binary(60)"%(parameterDict['dbName'], parameterDict['stbName'])) - tdSql.query("alter table %s.%s rename column c3 c3new"%(parameterDict['dbName'], parameterDict['stbName'])) - tdSql.query("alter table %s.%s rename column c4 c4new"%(parameterDict['dbName'], parameterDict['stbName'])) + # tdSql.query("alter table %s.%s rename column c3 c3new"%(parameterDict['dbName'], parameterDict['stbName'])) + # tdSql.query("alter table %s.%s rename column c4 c4new"%(parameterDict['dbName'], parameterDict['stbName'])) tdSql.query("alter table %s.%s rename tag t3 t3new"%(parameterDict['dbName'], parameterDict['stbName'])) tdSql.query("alter table %s.%s rename tag t4 t4new"%(parameterDict['dbName'], parameterDict['stbName'])) - tdSql.query("alter table %s.%s drop column c3new"%(parameterDict['dbName'], parameterDict['stbName'])) - tdSql.query("alter table %s.%s drop column c4new"%(parameterDict['dbName'], parameterDict['stbName'])) + tdSql.query("alter table %s.%s drop column c3"%(parameterDict['dbName'], parameterDict['stbName'])) + tdSql.query("alter table %s.%s drop column c4"%(parameterDict['dbName'], parameterDict['stbName'])) tdSql.query("alter table %s.%s drop tag t3new"%(parameterDict['dbName'], parameterDict['stbName'])) tdSql.query("alter table %s.%s drop tag t4new"%(parameterDict['dbName'], parameterDict['stbName'])) @@ -408,6 +408,7 @@ class TDTestCase: parameterDict['cfg'] = cfgPath # tdLog.info("create database, super table, child table, normal table") + # self.create_database(tdSql, parameterDict["dbName"]) ntbName = 'ntb2' tdSql.query("create table %s.%s (ts timestamp, c1 int, c2 binary(32), c3 double, c4 binary(32), c5 nchar(10)) tags (t1 int, t2 binary(32), t3 double, t4 binary(32), t5 nchar(10))"%(parameterDict["dbName"],parameterDict["stbName"])) tdSql.query("create table %s.%s (ts timestamp, c1 int, c2 binary(32), c3 double, c4 binary(32), c5 nchar(10))"%(parameterDict["dbName"],ntbName)) @@ -687,7 +688,7 @@ class TDTestCase: tdLog.info("cfgPath: %s" % cfgPath) self.tmqCase1(cfgPath, buildPath) - # self.tmqCase2(cfgPath, buildPath) + self.tmqCase2(cfgPath, buildPath) # self.tmqCase3(cfgPath, buildPath) def stop(self): diff --git a/tests/system-test/fulltest.bat b/tests/system-test/fulltest.bat index ea57bc7427..6ef66c58c2 100644 --- a/tests/system-test/fulltest.bat +++ b/tests/system-test/fulltest.bat @@ -2,6 +2,102 @@ python3 .\test.py -f 0-others\taosShell.py python3 .\test.py -f 0-others\taosShellError.py python3 .\test.py -f 0-others\taosShellNetChk.py +python3 .\test.py -f 0-others\telemetry.py +python3 .\test.py -f 0-others\taosdMonitor.py python3 .\test.py -f 0-others\udfTest.py python3 .\test.py -f 0-others\udf_create.py -python3 .\test.py -f 0-others\udf_restart_taosd.py \ No newline at end of file +python3 .\test.py -f 0-others\udf_restart_taosd.py +@REM python3 .\test.py -f 0-others\cachelast.py + +@REM python3 .\test.py -f 0-others\user_control.py +@REM python3 .\test.py -f 0-others\fsync.py + +@REM python3 .\test.py -f 1-insert\influxdb_line_taosc_insert.py +@REM python3 .\test.py -f 1-insert\opentsdb_telnet_line_taosc_insert.py +@REM python3 .\test.py -f 1-insert\opentsdb_json_taosc_insert.py +@REM #python3 .\test.py -f 1-insert\test_stmt_muti_insert_query.py +@REM python3 .\test.py -f 1-insert\alter_stable.py +@REM python3 .\test.py -f 1-insert\alter_table.py +@REM python3 .\test.py -f 2-query\between.py +@REM python3 .\test.py -f 2-query\distinct.py +@REM python3 .\test.py -f 2-query\varchar.py +@REM python3 .\test.py -f 2-query\ltrim.py +@REM python3 .\test.py -f 2-query\rtrim.py +@REM python3 .\test.py -f 2-query\length.py +@REM python3 .\test.py -f 2-query\char_length.py +@REM python3 .\test.py -f 2-query\upper.py +@REM python3 .\test.py -f 2-query\lower.py +@REM python3 .\test.py -f 2-query\join.py +@REM python3 .\test.py -f 2-query\join2.py +@REM python3 .\test.py -f 2-query\cast.py +@REM python3 .\test.py -f 2-query\union.py +@REM python3 .\test.py -f 2-query\union1.py +@REM python3 .\test.py -f 2-query\concat.py +@REM python3 .\test.py -f 2-query\concat2.py +@REM python3 .\test.py -f 2-query\concat_ws.py +@REM python3 .\test.py -f 2-query\concat_ws2.py +@REM python3 .\test.py -f 2-query\check_tsdb.py +@REM python3 .\test.py -f 2-query\spread.py +@REM python3 .\test.py -f 2-query\hyperloglog.py + + +@REM python3 .\test.py -f 2-query\timezone.py +@REM python3 .\test.py -f 2-query\Now.py +@REM python3 .\test.py -f 2-query\Today.py +@REM python3 .\test.py -f 2-query\max.py +@REM python3 .\test.py -f 2-query\min.py +@REM python3 .\test.py -f 2-query\count.py +@REM python3 .\test.py -f 2-query\last.py +@REM python3 .\test.py -f 2-query\first.py +@REM python3 .\test.py -f 2-query\To_iso8601.py +@REM python3 .\test.py -f 2-query\To_unixtimestamp.py +@REM python3 .\test.py -f 2-query\timetruncate.py +@REM python3 .\test.py -f 2-query\diff.py +@REM python3 .\test.py -f 2-query\Timediff.py + +@REM python3 .\test.py -f 2-query\top.py +@REM python3 .\test.py -f 2-query\bottom.py +@REM python3 .\test.py -f 2-query\percentile.py +@REM python3 .\test.py -f 2-query\apercentile.py +@REM python3 .\test.py -f 2-query\abs.py +@REM python3 .\test.py -f 2-query\ceil.py +@REM python3 .\test.py -f 2-query\floor.py +@REM python3 .\test.py -f 2-query\round.py +@REM python3 .\test.py -f 2-query\log.py +@REM python3 .\test.py -f 2-query\pow.py +@REM python3 .\test.py -f 2-query\sqrt.py +@REM python3 .\test.py -f 2-query\sin.py +@REM python3 .\test.py -f 2-query\cos.py +@REM python3 .\test.py -f 2-query\tan.py +@REM python3 .\test.py -f 2-query\arcsin.py +@REM python3 .\test.py -f 2-query\arccos.py +@REM python3 .\test.py -f 2-query\arctan.py +@REM python3 .\test.py -f 2-query\query_cols_tags_and_or.py +@REM # python3 .\test.py -f 2-query\nestedQuery.py +@REM # TD-15983 subquery output duplicate name column. +@REM # Please Xiangyang Guo modify the following script +@REM # python3 .\test.py -f 2-query\nestedQuery_str.py + +@REM python3 .\test.py -f 2-query\avg.py +@REM python3 .\test.py -f 2-query\elapsed.py +@REM python3 .\test.py -f 2-query\csum.py +@REM python3 .\test.py -f 2-query\mavg.py +@REM python3 .\test.py -f 2-query\diff.py +@REM python3 .\test.py -f 2-query\sample.py +@REM python3 .\test.py -f 2-query\function_diff.py +@REM python3 .\test.py -f 2-query\unique.py +@REM python3 .\test.py -f 2-query\stateduration.py +@REM python3 .\test.py -f 2-query\function_stateduration.py +@REM python3 .\test.py -f 2-query\statecount.py + +@REM python3 .\test.py -f 7-tmq\basic5.py +@REM python3 .\test.py -f 7-tmq\subscribeDb.py +@REM python3 .\test.py -f 7-tmq\subscribeDb0.py +@REM python3 .\test.py -f 7-tmq\subscribeDb1.py +@REM python3 .\test.py -f 7-tmq\subscribeStb.py +@REM python3 .\test.py -f 7-tmq\subscribeStb0.py +@REM python3 .\test.py -f 7-tmq\subscribeStb1.py +@REM python3 .\test.py -f 7-tmq\subscribeStb2.py +@REM python3 .\test.py -f 7-tmq\subscribeStb3.py +@REM python3 .\test.py -f 7-tmq\subscribeStb4.py +@REM python3 .\test.py -f 7-tmq\db.py \ No newline at end of file diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 3991654350..abc8a81248 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -21,6 +21,7 @@ python3 ./test.py -f 1-insert/opentsdb_json_taosc_insert.py #python3 ./test.py -f 1-insert/test_stmt_muti_insert_query.py python3 ./test.py -f 1-insert/alter_stable.py python3 ./test.py -f 1-insert/alter_table.py +# python3 ./test.py -f 1-inerst/create_table_comment.py python3 ./test.py -f 2-query/between.py python3 ./test.py -f 2-query/distinct.py python3 ./test.py -f 2-query/varchar.py @@ -57,6 +58,7 @@ python3 ./test.py -f 2-query/To_unixtimestamp.py python3 ./test.py -f 2-query/timetruncate.py python3 ./test.py -f 2-query/diff.py python3 ./test.py -f 2-query/Timediff.py +python3 ./test.py -f 2-query/json_tag.py python3 ./test.py -f 2-query/top.py python3 ./test.py -f 2-query/bottom.py diff --git a/tests/system-test/test-all.bat b/tests/system-test/test-all.bat index ae6c98b06f..9c2e58ea3f 100644 --- a/tests/system-test/test-all.bat +++ b/tests/system-test/test-all.bat @@ -11,15 +11,46 @@ set /a a=0 @REM ) echo Linux Taosd Test for /F "usebackq tokens=*" %%i in (fulltest.bat) do ( - echo Processing %%i - set /a a+=1 - call %%i ARG1 -m %1 > result_!a!.txt 2>error_!a!.txt - if errorlevel 1 ( call :colorEcho 0c "failed" &echo. && exit 8 ) else ( call :colorEcho 0a "Success" &echo. ) + for /f "tokens=1* delims= " %%a in ("%%i") do if not "%%a" == "@REM" ( + echo Processing %%i + call :GetTimeSeconds %time% + set time1=!_timeTemp! + echo Start at %time% + set /a a+=1 + call %%i ARG1 -m %1 > result_!a!.txt 2>error_!a!.txt + if errorlevel 1 ( call :colorEcho 0c "failed" &echo. && echo result: && cat result_!a!.txt && echo error: && cat error_!a!.txt && exit 8 ) else ( call :colorEcho 0a "Success" &echo. ) + ) ) exit :colorEcho +call :GetTimeSeconds %time% +set time2=%_timeTemp% +set /a interTime=%time2% - %time1% +echo End at %time% , cast %interTime%s echo off "%~2" findstr /v /a:%1 /R "^$" "%~2" nul -del "%~2" > nul 2>&1i \ No newline at end of file +del "%~2" > nul 2>&1i +goto :eof + +:GetTimeSeconds +set tt=%1 +set tt=%tt:.= % +set tt=%tt::= % +set index=1 +for %%a in (%tt%) do ( + if !index! EQU 1 ( + set hh=%%a + )^ + else if !index! EQU 2 ( + set mm=%%a + + )^ + else if !index! EQU 3 ( + set ss=%%a + ) + set /a index=index+1 +) +set /a _timeTemp=(%hh%*60+%mm%)*60+%ss% +goto :eof \ No newline at end of file diff --git a/tests/system-test/test.py b/tests/system-test/test.py index a11085708c..8350f6752f 100644 --- a/tests/system-test/test.py +++ b/tests/system-test/test.py @@ -114,6 +114,7 @@ if __name__ == "__main__": if not execCmd == "": tdDnodes.init(deployPath) + print(execCmd) exec(execCmd) quit() @@ -167,7 +168,7 @@ if __name__ == "__main__": key_word = 'tdCases.addWindows' is_test_framework = 0 try: - if key_word in open(fileName).read(): + if key_word in open(fileName, encoding='UTF-8').read(): is_test_framework = 1 except: pass diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index d0b582f375..4d9e2275f4 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -514,14 +514,14 @@ void* consumeThreadFunc(void* param) { err = tmq_unsubscribe(pInfo->tmq); if (err) { pError("tmq_unsubscribe() fail, reason: %s\n", tmq_err2str(err)); - pInfo->consumeMsgCnt = -1; - return NULL; + /*pInfo->consumeMsgCnt = -1;*/ + /*return NULL;*/ } err = tmq_consumer_close(pInfo->tmq); if (err) { pError("tmq_consumer_close() fail, reason: %s\n", tmq_err2str(err)); - exit(-1); + /*exit(-1);*/ } pInfo->tmq = NULL; diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 851d9a2070..329842aeb3 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -1003,7 +1003,7 @@ int32_t shellExecute() { taosSetSignal(SIGINT, shellSigintHandler); - shellGetGrantInfo(shell.conn); + shellGetGrantInfo(); while (1) { taosThreadCreate(&shell.pid, NULL, shellThreadLoop, shell.conn);