Merge branch 'main' of https://github.com/taosdata/TDengine into test/main/TD-32845

This commit is contained in:
chenhaoran 2024-12-20 15:02:49 +08:00
commit 41bec2c052
93 changed files with 3801 additions and 615 deletions

View File

@ -78,7 +78,7 @@ def check_docs(){
file_only_tdgpt_change_except = sh (
script: '''
cd ${WKC}
git --no-pager diff --name-only FETCH_HEAD `git merge-base FETCH_HEAD ${CHANGE_TARGET}`|grep -v "^docs/en/"|grep -v "^docs/zh/"|grep -v ".md$" | grep -v "forecastoperator.c\\|anomalywindowoperator.c" |grep -v "tsim/analytics" |grep -v "tdgpt_cases.task" || :
git --no-pager diff --name-only FETCH_HEAD `git merge-base FETCH_HEAD ${CHANGE_TARGET}`|grep -v "^docs/en/"|grep -v "^docs/zh/"|grep -v ".md$" | grep -v "forecastoperator.c\\|anomalywindowoperator.c\\|tanalytics.h\\|tanalytics.c" |grep -v "tsim/analytics" |grep -v "tdgpt_cases.task" || :
''',
returnStdout: true
).trim()

View File

@ -10,8 +10,6 @@
</p>
<p>
[![Build Status](https://cloud.drone.io/api/badges/taosdata/TDengine/status.svg?ref=refs/heads/master)](https://cloud.drone.io/taosdata/TDengine)
[![Build status](https://ci.appveyor.com/api/projects/status/kf3pwh2or5afsgl9/branch/master?svg=true)](https://ci.appveyor.com/project/sangshuduo/tdengine-2n8ge/branch/master)
[![Coverage Status](https://coveralls.io/repos/github/taosdata/TDengine/badge.svg?branch=3.0)](https://coveralls.io/github/taosdata/TDengine?branch=3.0)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/4201/badge)](https://bestpractices.coreinfrastructure.org/projects/4201)
<br />

View File

@ -14,6 +14,7 @@ The default configuration file for `Agent` is located at `/etc/taos/agent.toml`,
- `token`: Required, the Token generated when creating `Agent` in `Explorer`.
- `instanceId`: The instance ID of the current taosx-agent service. If multiple taosx-agent instances are started on the same machine, it is necessary to ensure that the instance IDs of each instance are unique.
- `compression`: Optional, can be configured as `true` or `false`, default is `false`. If set to `true`, it enables data compression in communication between `Agent` and `taosX`.
- `in_memory_cache_capacity`: Optional, signifies the maximum number of message batches that can be cached in memory and can be configured as a positive integer greater than zero. The default value is set at 64.
- `log_level`: Optional, log level, default is `info`. Like `taosX`, it supports five levels: `error`, `warn`, `info`, `debug`, `trace`. Deprecated, please use `log.level` instead.
- `log_keep_days`: Optional, the number of days to keep logs, default is `30` days. Deprecated, please use `log.keepDays` instead.
- `log.path`: The directory where log files are stored.
@ -45,6 +46,10 @@ As shown below:
#
#compression = true
# In-memory cache capacity
#
#in_memory_cache_capacity = 64
# log configuration
[log]
# All log files are stored in this directory

View File

@ -190,6 +190,7 @@ ROUND(expr[, digits])
- `digits` less than zero means discarding the decimal places and rounding the number to the left of the decimal point by `digits` places. If the number of places to the left of the decimal point is less than `digits`, returns 0.
- Since the DECIMAL type is not yet supported, this function will use DOUBLE and FLOAT to represent results containing decimals, but DOUBLE and FLOAT have precision limits, and using this function may be meaningless when there are too many digits.
- Can only be used with regular columns, selection (Selection), projection (Projection) functions, and cannot be used with aggregation (Aggregation) functions.
- `digits` is supported from version 3.3.3.0.
**Example**:
@ -249,6 +250,8 @@ TAN(expr)
**Function Description**: Obtains the tangent result of the specified field.
**Version**: ver-3.3.3.0
**Return Result Type**: DOUBLE.
**Applicable Data Types**: Numeric types.
@ -297,6 +300,8 @@ TRUNCATE(expr, digits)
**Function Description**: Gets the truncated value of the specified field to the specified number of digits.
**Version**: ver-3.3.3.0
**Return Type**: Consistent with the original data type of the `expr` field.
**Applicable Data Types**:
@ -340,6 +345,8 @@ EXP(expr)
**Function Description**: Returns the value of e (the base of natural logarithms) raised to the specified power.
**Version**: ver-3.3.3.0
**Return Type**: DOUBLE.
**Applicable Data Types**: Numeric type.
@ -370,6 +377,8 @@ LN(expr)
**Function Description**: Returns the natural logarithm of the specified parameter.
**Version**: ver-3.3.3.0
**Return Type**: DOUBLE.
**Applicable Data Types**: Numeric type.
@ -401,6 +410,8 @@ MOD(expr1, expr2)
**Function Description**: Calculates the result of expr1 % expr2.
**Version**: ver-3.3.3.0
**Return Type**: DOUBLE.
**Applicable Data Types**: Numeric type.
@ -437,6 +448,8 @@ RAND([seed])
**Function Description**: Returns a uniformly distributed random number from 0 to 1.
**Version**: ver-3.3.3.0
**Return Result Type**: DOUBLE.
**Applicable Data Types**:
@ -484,6 +497,8 @@ SIGN(expr)
**Function Description**: Returns the sign of the specified parameter.
**Version**: ver-3.3.3.0
**Return Result Type**: Consistent with the original data type of the specified field.
**Applicable Data Types**: Numeric types.
@ -527,6 +542,8 @@ DEGREES(expr)
**Function Description**: Calculates the value of the specified parameter converted from radians to degrees.
**Version**: ver-3.3.3.0
**Return Result Type**: DOUBLE.
**Applicable Data Types**: Numeric types.
@ -558,6 +575,8 @@ RADIANS(expr)
**Function Description**: Calculates the value of the specified parameter converted from degrees to radians.
**Version**: ver-3.3.3.0
**Return Type**: DOUBLE.
**Applicable Data Types**: Numeric types.
@ -729,6 +748,8 @@ TRIM([remstr FROM] expr)
**Function Description**: Returns the string expr with all prefixes or suffixes of remstr removed.
**Version**: ver-3.3.3.0
**Return Result Type**: Same as the original type of the input field expr.
**Applicable Data Types**:
@ -807,6 +828,8 @@ SUBSTRING/SUBSTR(expr FROM pos [FOR len])
- If `len` is less than 1, returns an empty string.
- `pos` is 1-based; if `pos` is 0, returns an empty string.
- If `pos` + `len` exceeds `len(expr)`, returns the substring from `pos` to the end of the string, equivalent to executing `substring(expr, pos)`.
- Function `SUBSTRING` is equal to `SUBSTR`, supported from ver-3.3.3.0.
- Syntax `SUBSTRING/SUBSTR(expr FROM pos [FOR len])` is supported from ver-3.3.3.0.
**Examples**:
@ -845,6 +868,8 @@ SUBSTRING_INDEX(expr, delim, count)
**Function Description**: Returns a substring of `expr` cut at the position where the delimiter appears the specified number of times.
**Version**: ver-3.3.3.0
**Return Result Type**: Same as the original type of the input field `expr`.
**Applicable Data Types**:
@ -902,6 +927,8 @@ CHAR(expr1 [, expr2] [, expr3] ...)
**Function Description**: Treats the input parameters as integers and returns the characters corresponding to these integers in ASCII encoding.
**Version**: ver-3.3.3.0
**Return Result Type**: VARCHAR.
**Applicable Data Types**: Integer types, VARCHAR, NCHAR.
@ -949,6 +976,8 @@ ASCII(expr)
**Function Description**: Returns the ASCII code of the first character of the string.
**Version**: ver-3.3.3.0
**Return Result Data Type**: BIGINT.
**Applicable Data Types**: VARCHAR, NCHAR.
@ -979,6 +1008,8 @@ POSITION(expr1 IN expr2)
**Function Description**: Calculates the position of string `expr1` in string `expr2`.
**Version**: ver-3.3.3.0
**Return Result Type**: BIGINT.
**Applicable Data Types**:
@ -1026,6 +1057,8 @@ REPLACE(expr, from_str, to_str)
**Function Description**: Replaces all occurrences of `from_str` in the string with `to_str`.
**Version**: ver-3.3.3.0
**Return Type**: Same as the original type of the input field `expr`.
**Applicable Data Types**:
@ -1061,6 +1094,8 @@ REPEAT(expr, count)
**Function Description**: Returns a string that repeats the string `expr` a specified number of times.
**Version**: ver-3.3.3.0
**Return Type**: Same as the original type of the input field `expr`.
**Applicable Data Types**:
@ -1319,6 +1354,7 @@ TIMEDIFF(expr1, expr2 [, time_unit])
- `expr1`: BIGINT, TIMESTAMP types representing timestamps, or VARCHAR, NCHAR types in ISO8601/RFC3339 standard date-time format.
- `expr2`: BIGINT, TIMESTAMP types representing timestamps, or VARCHAR, NCHAR types in ISO8601/RFC3339 standard date-time format.
- `time_unit`: See usage instructions.
- `timediff` return the absolute value of the difference between timestamp `expr1` and `expr2` before ver-3.3.3.0.
**Nested Subquery Support**: Applicable to both inner and outer queries.
@ -1423,6 +1459,8 @@ WEEK(expr [, mode])
**Function Description**: Returns the week number of the input date.
**Version**: ver-3.3.3.0
**Return Result Type**: BIGINT.
**Applicable Data Types**:
@ -1490,6 +1528,8 @@ WEEKOFYEAR(expr)
**Function Description**: Returns the week number of the input date.
**Version**: ver-3.3.3.0
**Return Type**: BIGINT.
**Applicable Data Types**: BIGINT, TIMESTAMP types representing timestamps, or VARCHAR, NCHAR types in ISO8601/RFC3339 date-time format.
@ -1521,6 +1561,8 @@ WEEKDAY(expr)
**Function Description**: Returns the weekday of the input date.
**Version**: ver-3.3.3.0
**Return Type**: BIGINT.
**Applicable Data Types**: BIGINT, TIMESTAMP types representing timestamps, or VARCHAR, NCHAR types in ISO8601/RFC3339 date-time format.
@ -1552,6 +1594,8 @@ DAYOFWEEK(expr)
**Function Description**: Returns the weekday of the input date.
**Version**: ver-3.3.3.0
**Return Type**: BIGINT.
**Applicable Data Types**: BIGINT, TIMESTAMP types representing timestamps, or VARCHAR, NCHAR types in ISO8601/RFC3339 date-time format.
@ -1707,6 +1751,9 @@ STDDEV/STDDEV_POP(expr)
**Applicable to**: Tables and supertables.
**Description**:
- Function `STDDEV_POP` equals `STDDEV` and is supported from ver-3.3.3.0.
**Example**:
```sql
@ -1733,6 +1780,8 @@ VAR_POP(expr)
**Function Description**: Calculates the population variance of a column in a table.
**Version**: ver-3.3.3.0
**Return Data Type**: DOUBLE.
**Applicable Data Types**: Numeric types.
@ -1975,7 +2024,8 @@ MAX(expr)
**Applicable to**: Tables and supertables.
**Usage Instructions**: The max function can accept strings as input parameters, and when the input parameter is a string type, it returns the largest string value.
**Usage Instructions**:
- The max function can accept strings as input parameters, and when the input parameter is a string type, it returns the largest string value(supported from ver-3.3.3.0, function `max` only accept numeric parameter before ver-3.3.3.0).
### MIN
@ -1991,7 +2041,8 @@ MIN(expr)
**Applicable to**: Tables and supertables.
**Usage Instructions**: The min function can accept strings as input parameters, and when the input parameter is a string type, it returns the largest string value.
**Usage Instructions**:
- The min function can accept strings as input parameters, and when the input parameter is a string type, it returns the largest string value(supported from ver-3.3.3.0, function `min` only accept numeric parameter before ver-3.3.3.0).
### MODE

View File

@ -16,7 +16,7 @@ TDengine 采用 SQL 作为查询语言,大大降低学习成本、降低迁移
如果你是系统管理员,关心安装、升级、容错灾备、关心数据导入、导出、配置参数,如何监测 TDengine 是否健康运行,如何提升系统运行的性能,请仔细参考[运维指南](./operation)一章。
如果你对数据库内核设计感兴趣,或是开源爱好者,建议仔细阅读[技术内幕](./tdinterna)一章。该章从分布式架构到存储引擎、查询引擎、数据订阅再到流计算引擎都做了详细阐述。建议对照文档查看TDengine在GitHub的源代码对TDengine的设计和编码做深入了解更欢迎加入开源社区贡献代码。
如果你对数据库内核设计感兴趣,或是开源爱好者,建议仔细阅读[技术内幕](./tdinternal)一章。该章从分布式架构到存储引擎、查询引擎、数据订阅再到流计算引擎都做了详细阐述。建议对照文档查看TDengine在GitHub的源代码对TDengine的设计和编码做深入了解更欢迎加入开源社区贡献代码。
最后,作为一个开源软件,欢迎大家的参与。如果发现文档有任何错误、描述不清晰的地方,请在每个页面的最下方,点击“编辑本文档”直接进行修改。

View File

@ -8,8 +8,6 @@ import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import PkgListV3 from "/components/PkgListV3";
您可以[用 Docker 立即体验](../../get-started/docker/) TDengine。如果您希望对 TDengine 贡献代码或对内部实现感兴趣,请参考我们的 [TDengine GitHub 主页](https://github.com/taosdata/TDengine) 下载源码构建和安装.
TDengine 完整的软件包包括服务端taosd、应用驱动taosc、用于与第三方系统对接并提供 RESTful 接口的 taosAdapter、命令行程序CLItaos和一些工具软件。目前 TDinsight 仅在 Linux 系统上安装和运行,后续将支持 Windows、macOS 等系统。TDengine 除了提供多种语言的连接器之外,还通过 [taosAdapter](../../reference/components/taosadapter/) 提供 [RESTful 接口](../../reference/connector/rest-api/)。
为方便使用,标准的服务端安装包包含了 taosd、taosAdapter、taosc、taos、taosdump、taosBenchmark、TDinsight 安装脚本和示例代码;如果您只需要用到服务端程序和客户端连接的 C/C++ 语言支持,也可以仅下载 Lite 版本的安装包。
@ -319,4 +317,4 @@ SELECT AVG(current), MAX(voltage), MIN(phase) FROM test.meters WHERE groupId = 1
SELECT _wstart, AVG(current), MAX(voltage), MIN(phase) FROM test.d1001 INTERVAL(10s);
```
在上面的查询中,使用系统提供的伪列 _wstart 来给出每个窗口的开始时间。
在上面的查询中,使用系统提供的伪列 _wstart 来给出每个窗口的开始时间。

View File

@ -10,7 +10,7 @@ import official_account from './official-account.webp'
TDengine 完整的软件包包括服务端taosd、用于与第三方系统对接并提供 RESTful 接口的 taosAdapter、应用驱动taosc、命令行程序 (CLItaos) 和一些工具软件。TDengine 除了提供多种语言的连接器之外,还通过 [taosAdapter](../reference/components/taosadapter) 提供 [RESTful 接口](../reference/connector/rest-api)。
本章主要介绍如何利用 Docker 或者安装包快速设置 TDengine 环境并体验其高效写入和查询。
本章主要介绍如何快速设置 TDengine 环境并体验其高效写入和查询。
```mdx-code-block
import DocCardList from '@theme/DocCardList';
@ -34,4 +34,4 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
<td style={{padding:'1em 3em',border:0}}>关注 TDengine 视频号<br/>收看技术直播与教学视频</td>
<td style={{padding:'1em 3em',border:0}}>关注 TDengine 公众号<br/>阅读技术文章与行业案例</td>
</tr>
</table>
</table>

View File

@ -175,7 +175,7 @@ TDengine 对于修改数据提供两种处理方式,由 IGNORE UPDATE 选项
用户可以为每个 partition 对应的子表生成自定义的 TAG 值,如下创建流的语句,
```sql
CREATE STREAM output_tag trigger at_once INTO output_tag_s TAGS(alias_tag varchar(100)) as select _wstart, count(*) from power.meters partition by concat("tag-", tbname) as alias_tag interval(10s));
CREATE STREAM output_tag trigger at_once INTO output_tag_s TAGS(alias_tag varchar(100)) as select _wstart, count(*) from power.meters partition by concat("tag-", tbname) as alias_tag interval(10s);
```
在 PARTITION 子句中,为 concat"tag-" tbname定义了一个别名 alias_tag 对应超级表 output_tag_s 的自定义 TAG 的名字。在上述示例中,流新创建的子表的 TAG 将以前缀 'tag-' 连接原表名作为 TAG 的值。会对 TAG 信息进行如下检查。

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -294,9 +294,32 @@ let v3 = data["voltage"].split(",");
在任务列表页面,还可以对任务进行启动、停止、查看、删除、复制等操作,也可以查看各个任务的运行情况,包括写入的记录条数、流量等。
### 健康状态
从 3.3.5.0 开始,在任务管理列表中,增加了一项 ”健康状态“,用于指示当前任务运行过程中的健康状态。
在数据源的”高级选项“列表中,增加了多项健康状态监测的配置项,包括:
![health options](./health-options.png)
1. 健康监测时段Health Check Duration可选项表示对最近多长时间的任务状态进行统计。
2. Busy 状态阈值Busy State Threshold百分比表示写入队列中入队元素数量与队列长度之比默认 100%。
3. 写入队列长度Max Write Queue Length表示对应的写入队列长度最大值。
4. 写入错误阈值Write Error Threshold数值类型表示健康监测时段中允许写入错误的数量。超出阈值则报错。
在任务管理列表展示中,有如下状态:
- Ready数据源和目标端健康检查通过可以进行数据读取和写入。
- Idle表示监测时段内无数据处理没有数据进入处理流程
- Busy表示写入队列已满超出一定阈值表示写入繁忙在一定程度上意味着当前可能存在性能瓶颈需要调整参数或配置等来进行改善但并不说明存在错误
- Bounce数据源和目标端均正常但在写入过程中存在错误一定周期内超出阈值可能意味着存在大量非正常数据或正在发生数据丢失。
- SourceError: 数据源错误导致无法进行读取。此时工作负载将尝试重连数据源。
- SinkError写入端错误导致无法进行写入。此时工作负载将尝试重连数据库恢复后进入 Ready 状态。
- Fatal严重或无法恢复的错误。
```mdx-code-block
import DocCardList from '@theme/DocCardList';
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
<DocCardList items={useCurrentSidebarCategory().items}/>
```
```

View File

@ -12,7 +12,8 @@ sidebar_label: taosX-Agent
- `endpoint`: 必填,`taosX` 的 GRPC 服务地址。
- `token`: 必填,在 `Explorer` 上创建 `Agent` 时,产生的 Token。
- `instanceId`:当前 taosx-agent 服务的实例 ID如果同一台机器上启动了多个 taosx-agent 实例,必须保证各个实例的实例 ID 互不相同。
- `compression`: 非必填,可配置为 `ture``false`, 默认为 `false`。配置为`true`, 则开启 `Agent``taosX` 通信数据压缩。
- `compression`: 非必填,可配置为 `true``false`, 默认为 `false`。配置为`true`, 则开启 `Agent``taosX` 通信数据压缩。
- `in_memory_cache_capacity`: 非必填,表示可在内存中缓存的最大消息批次数,可配置为大于 0 的整数。默认为 `64`
- `log_level`: 非必填,日志级别,默认为 `info`, 同 `taosX` 一样,支持 `error``warn``info``debug``trace` 五级。已弃用,请使用 `log.level` 代替。
- `log_keep_days`:非必填,日志保存天数,默认为 `30` 天。已弃用,请使用 `log.keepDays` 代替。
- `log.path`:日志文件存放的目录。
@ -44,6 +45,10 @@ sidebar_label: taosX-Agent
#
#compression = true
# In-memory cache capacity
#
#in_memory_cache_capacity = 64
# log configuration
[log]
# All log files are stored in this directory

View File

@ -193,6 +193,7 @@ ROUND(expr[, digits])
- `digits` 小于零表示丢掉小数位,并将数字四舍五入到小数点左侧 `digits` 位。若小数点左侧的位数小于 `digits`位,返回 0。
- 由于暂未支持 DECIMAL 类型,所以该函数会用 DOUBLE 和 FLOAT 来表示包含小数的结果,但是 DOUBLE 和 FLOAT 是有精度上限的,当位数太多时使用该函数可能没有意义。
- 只能与普通列选择Selection、投影Projection函数一起使用不能与聚合Aggregation函数一起使用。
- `digits` 从 ver-3.3.3.0 开始支持。
**举例**
```sql
@ -268,6 +269,8 @@ PI()
**功能说明**:返回圆周率 π 的值。
**版本**: ver-3.3.3.0
**返回结果类型**DOUBLE。
**适用数据类型**:无。
@ -295,6 +298,8 @@ TRUNCATE(expr, digits)
**功能说明**:获得指定字段按照指定位数截断的值。
**版本**: ver-3.3.3.0
**返回结果类型**:与 `expr` 字段的原始数据类型一致。
**适用数据类型**
@ -333,6 +338,8 @@ EXP(expr)
```
**功能说明**:返回 e自然对数的底的指定乘方后的值。
**版本**: ver-3.3.3.0
**返回结果类型**DOUBLE。
**适用数据类型**:数值类型。
@ -360,6 +367,8 @@ LN(expr)
**功能说明**:返回指定参数的自然对数。
**版本**: ver-3.3.3.0
**返回结果类型**DOUBLE。
**适用数据类型**:数值类型。
@ -388,6 +397,8 @@ MOD(expr1, expr2)
**功能说明**:计算 expr1 % expr2 的结果。
**版本**: ver-3.3.3.0
**返回结果类型**DOUBLE。
**适用数据类型**:数值类型。
@ -421,6 +432,8 @@ RAND([seed])
**功能说明**返回一个从0到1均匀分布的随机数。
**版本**: ver-3.3.3.0
**返回结果类型**DOUBLE。
**适用数据类型**
@ -464,6 +477,8 @@ SIGN(expr)
**功能说明**:返回指定参数的符号。
**版本**: ver-3.3.3.0
**返回结果类型**:与指定字段的原始数据类型一致。
**适用数据类型**:数值类型。
@ -504,6 +519,8 @@ DEGREES(expr)
**功能说明**:计算指定参数由弧度值转为角度后的值。
**版本**: ver-3.3.3.0
**返回结果类型**DOUBLE。
**适用数据类型**:数值类型。
@ -532,6 +549,8 @@ RADIANS(expr)
**功能说明**:计算指定参数由角度值转为弧度后的值。
**版本**: ver-3.3.3.0
**返回结果类型**DOUBLE。
**适用数据类型**:数值类型。
@ -702,6 +721,8 @@ TRIM([remstr FROM] expr)
**功能说明**:返回去掉了所有 remstr 前缀或后缀的字符串 epxr 。
**版本**: ver-3.3.3.0
**返回结果类型**:与输入字段 epxr 的原始类型相同。
**适用数据类型**
@ -773,6 +794,8 @@ SUBSTRING/SUBSTR(expr FROM pos [FOR len])
- 若 `len` 小于 1返回空串。
- `pos` 是 1-base 的,若 `pos` 为 0返回空串。
- 若 `pos` + `len` 大于 `len(expr)`,返回从 `pos` 开始到字符串结尾的子串,等同于执行 `substring(expr, pos)`
- `SUBSTRING` 函数等价于 `SUBSTR`, 从 ver-3.3.3.0 开始支持。
- `SUBSTRING/SUBSTR(expr FROM pos [FOR len])` 语法从 ver-3.3.3.0 开始支持。
**举例**
```sql
@ -809,6 +832,8 @@ SUBSTRING_INDEX(expr, delim, count)
**功能说明**:返回字符串 `expr` 在出现指定次数分隔符的位置截取的子串。
**版本**: ver-3.3.3.0
**返回结果类型**:与输入字段 `expr` 的原始类型相同。
**适用数据类型**
@ -862,6 +887,8 @@ CHAR(expr1 [, expr2] [, epxr3] ...)
**功能说明**:将输入参数当作整数,并返回这些整数在 ASCII 编码中对应的字符。
**版本**: ver-3.3.3.0
**返回结果类型**VARCHAR。
**适用数据类型**:整数类型,VARCHAR,NCHAR。
@ -906,6 +933,8 @@ ASCII(expr)
**功能说明**:返回字符串第一个字符的 ASCII 码。
**版本**: ver-3.3.3.0
**返回结果数据类型**BIGINT。
**适用数据类型**VARCHAR, NCHAR。
@ -933,6 +962,8 @@ POSITION(expr1 IN expr2)
**功能说明**:计算字符串 `expr1` 在字符串 `expr2` 中的位置。
**版本**: ver-3.3.3.0
**返回结果类型**BIGINT。
**适用数据类型**
@ -975,6 +1006,8 @@ REPLACE(expr, from_str, to_str)
```
**功能说明**:将字符串中的 `from_str` 全部替换为 `to_str`
**版本**: ver-3.3.3.0
**返回结果类型**:与输入字段 `expr` 的原始类型相同。
**适用数据类型**
@ -1005,6 +1038,8 @@ REPEAT(expr, count)
```
**功能说明**:返回将字符串重复指定次数得到的字符串。
**版本**: ver-3.3.3.0
**返回结果类型**:与输入字段 `expr` 的原始类型相同。
**适用数据类型**
@ -1260,6 +1295,7 @@ TIMEDIFF(expr1, expr2 [, time_unit])
- `expr1`:表示时间戳的 BIGINT, TIMESTAMP 类型,或符合 ISO8601/RFC3339 标准的日期时间格式的 VARCHAR, NCHAR 类型。
- `expr2`:表示时间戳的 BIGINT, TIMESTAMP 类型,或符合 ISO8601/RFC3339 标准的日期时间格式的 VARCHAR, NCHAR 类型。
- `time_unit`:见使用说明。
- ver-3.3.3.0 之前该函数结果为时间戳 `expr1``expr2` 的差值的绝对值,结果为正数。
**嵌套子查询支持**:适用于内层查询和外层查询。
@ -1361,6 +1397,8 @@ WEEK(expr [, mode])
```
**功能说明**:返回输入日期的周数。
**版本**: ver-3.3.3.0
**返回结果类型**BIGINT。
**适用数据类型**
@ -1422,6 +1460,8 @@ WEEKOFYEAR(expr)
```
**功能说明**:返回输入日期的周数。
**版本**: ver-3.3.3.0
**返回结果类型**BIGINT。
**适用数据类型**:表示时间戳的 BIGINT, TIMESTAMP 类型,或符合 ISO8601/RFC3339 标准的日期时间格式的 VARCHAR, NCHAR 类型。
@ -1449,6 +1489,8 @@ WEEKDAY(expr)
```
**功能说明**:返回输入日期是周几。
**版本**: ver-3.3.3.0
**返回结果类型**BIGINT。
**适用数据类型**:表示 表示时间戳的 BIGINT, TIMESTAMP 类型,或符合 ISO8601/RFC3339 标准的日期时间格式的 VARCHAR, NCHAR 类型。
@ -1476,6 +1518,8 @@ DAYOFWEEK(expr)
```
**功能说明**:返回输入日期是周几。
**版本**: ver-3.3.3.0
**返回结果类型**BIGINT。
**适用数据类型**:表示时间戳的 BIGINT, TIMESTAMP 类型,或符合 ISO8601/RFC3339 标准的日期时间格式的 VARCHAR, NCHAR 类型。
@ -1633,6 +1677,9 @@ STDDEV/STDDEV_POP(expr)
**适用于**:表和超级表。
**说明**
- `STDDEV_POP` 函数等价于 `STDDEV` 函数,从 ver-3.3.3.0 开始支持。
**举例**
```sql
taos> select id from test_stddev;
@ -1656,6 +1703,8 @@ VAR_POP(expr)
**功能说明**:统计表中某列的总体方差。
**版本**: ver-3.3.3.0
**返回数据类型**DOUBLE。
**适用数据类型**:数值类型。
@ -1898,7 +1947,8 @@ MAX(expr)
**适用于**:表和超级表。
**使用说明**max 函数可以接受字符串作为输入参数,当输入参数为字符串类型时,返回最大的字符串值。
**使用说明**
- max 函数可以接受字符串作为输入参数,当输入参数为字符串类型时,返回最大的字符串值,从 ver-3.3.3.0 开始支持,之前的版本不支持字符串参数。
### MIN
@ -1914,7 +1964,8 @@ MIN(expr)
**适用于**:表和超级表。
**使用说明**min 函数可以接受字符串作为输入参数,当输入参数为字符串类型时,返回最大的字符串值。
**使用说明**
- min 函数可以接受字符串作为输入参数,当输入参数为字符串类型时,返回最大的字符串值,从 ver-3.3.3.0 开始支持,之前的版本不支持字符串参数。
### MODE

View File

@ -155,7 +155,7 @@ SHOW QNODES;
SHOW QUERIES;
```
显示当前系统中正在进行的查询。
显示当前系统中正在进行的写入(更新)/查询/删除(由于内部 API 命名原因,所以统称 QUERIES
## SHOW SCORES

View File

@ -28,8 +28,8 @@ extern "C" {
#define ANAL_FORECAST_DEFAULT_ROWS 10
#define ANAL_FORECAST_DEFAULT_CONF 95
#define ANAL_FORECAST_DEFAULT_WNCHECK 1
#define ANAL_FORECAST_MAX_ROWS 10000
#define ANAL_ANOMALY_WINDOW_MAX_ROWS 10000
#define ANAL_FORECAST_MAX_ROWS 40000
#define ANAL_ANOMALY_WINDOW_MAX_ROWS 40000
typedef struct {
EAnalAlgoType type;

View File

@ -378,7 +378,7 @@ typedef struct {
TAOS_MULTI_BIND *bind;
} SBindInfo;
int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema,
SArray *rowArray);
SArray *rowArray, bool *pOrdered, bool *pDupTs);
// stmt2 binding
int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int32_t buffMaxLen, initGeosFn igeos,
@ -392,7 +392,7 @@ typedef struct {
} SBindInfo2;
int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema,
SArray *rowArray);
SArray *rowArray, bool *pOrdered, bool *pDupTs);
#endif

View File

@ -26,7 +26,7 @@ typedef struct SCryptOpts {
char* source;
char* result;
int32_t unitLen;
char key[17];
char key[ENCRYPT_KEY_LEN + 1];
} SCryptOpts;
int32_t CBC_Decrypt(SCryptOpts* opts);

View File

@ -288,6 +288,7 @@ struct SScalarParam {
bool colAlloced;
SColumnInfoData *columnData;
SHashObj *pHashFilter;
SHashObj *pHashFilterOthers;
int32_t hashValueType;
void *param; // other parameter, such as meta handle from vnode, to extract table name/tag value
int32_t numOfRows;

View File

@ -40,7 +40,7 @@ pDst need to freed in caller
int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst);
int32_t scalarGetOperatorParamNum(EOperatorType type);
int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type);
int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type, int8_t processType);
int32_t vectorGetConvertType(int32_t type1, int32_t type2);
int32_t vectorConvertSingleColImpl(const SScalarParam *pIn, SScalarParam *pOut, int32_t *overflow, int32_t startIndex, int32_t numOfRows);

View File

@ -207,7 +207,6 @@ typedef struct {
typedef struct {
int32_t nodeId;
SEpSet epset;
} SDownstreamTaskEpset;
typedef enum {

View File

@ -2168,17 +2168,41 @@ int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col
pStmt->semWaited = true;
}
int32_t code = 0;
SSHashObj *hashTbnames = tSimpleHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR));
if (NULL == hashTbnames) {
tscError("stmt2 bind failed: %s", tstrerror(terrno));
return terrno;
}
int32_t code = TSDB_CODE_SUCCESS;
for (int i = 0; i < bindv->count; ++i) {
if (bindv->tbnames && bindv->tbnames[i]) {
if (pStmt->sql.stbInterlaceMode) {
if (tSimpleHashGet(hashTbnames, bindv->tbnames[i], strlen(bindv->tbnames[i])) != NULL) {
code = terrno = TSDB_CODE_PAR_TBNAME_DUPLICATED;
tscError("stmt2 bind failed: %s %s", tstrerror(terrno), bindv->tbnames[i]);
goto out;
}
code = tSimpleHashPut(hashTbnames, bindv->tbnames[i], strlen(bindv->tbnames[i]), NULL, 0);
if (code) {
goto out;
}
}
code = stmtSetTbName2(stmt, bindv->tbnames[i]);
if (code) {
return code;
goto out;
}
}
if (bindv->tags && bindv->tags[i]) {
code = stmtSetTbTags2(stmt, bindv->tags[i]);
if (code) {
goto out;
}
} else {
code = stmtSetTbTags2(stmt, NULL);
if (code) {
return code;
}
@ -2189,26 +2213,29 @@ int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col
if (bind->num <= 0 || bind->num > INT16_MAX) {
tscError("invalid bind num %d", bind->num);
terrno = TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR;
return terrno;
code = terrno = TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR;
goto out;
}
int32_t insert = 0;
(void)stmtIsInsert2(stmt, &insert);
if (0 == insert && bind->num > 1) {
tscError("only one row data allowed for query");
terrno = TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR;
return terrno;
code = terrno = TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR;
goto out;
}
code = stmtBindBatch2(stmt, bind, col_idx);
if (TSDB_CODE_SUCCESS != code) {
return code;
goto out;
}
}
}
return TSDB_CODE_SUCCESS;
out:
tSimpleHashCleanup(hashTbnames);
return code;
}
int taos_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows) {

View File

@ -39,7 +39,7 @@ static FORCE_INLINE int32_t stmtAllocQNodeFromBuf(STableBufInfo* pTblBuf, void**
}
static bool stmtDequeue(STscStmt2* pStmt, SStmtQNode** param) {
while (0 == atomic_load_64(&pStmt->queue.qRemainNum)) {
while (0 == atomic_load_64((int64_t*)&pStmt->queue.qRemainNum)) {
taosUsleep(1);
return false;
}
@ -53,7 +53,7 @@ static bool stmtDequeue(STscStmt2* pStmt, SStmtQNode** param) {
*param = node;
(void)atomic_sub_fetch_64(&pStmt->queue.qRemainNum, 1);
(void)atomic_sub_fetch_64((int64_t*)&pStmt->queue.qRemainNum, 1);
return true;
}
@ -63,7 +63,7 @@ static void stmtEnqueue(STscStmt2* pStmt, SStmtQNode* param) {
pStmt->queue.tail = param;
pStmt->stat.bindDataNum++;
(void)atomic_add_fetch_64(&pStmt->queue.qRemainNum, 1);
(void)atomic_add_fetch_64((int64_t*)&pStmt->queue.qRemainNum, 1);
}
static int32_t stmtCreateRequest(STscStmt2* pStmt) {
@ -77,7 +77,7 @@ static int32_t stmtCreateRequest(STscStmt2* pStmt) {
}
if (pStmt->db != NULL) {
taosMemoryFreeClear(pStmt->exec.pRequest->pDb);
pStmt->exec.pRequest->pDb = strdup(pStmt->db);
pStmt->exec.pRequest->pDb = taosStrdup(pStmt->db);
}
if (TSDB_CODE_SUCCESS == code) {
pStmt->exec.pRequest->syncQuery = true;
@ -1012,10 +1012,10 @@ int stmtSetTbTags2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* tags) {
}
SBoundColInfo* tags_info = (SBoundColInfo*)pStmt->bInfo.boundTags;
if (tags_info->numOfBound <= 0 || tags_info->numOfCols <= 0) {
tscWarn("no tags or cols bound in sql, will not bound tags");
return TSDB_CODE_SUCCESS;
}
// if (tags_info->numOfBound <= 0 || tags_info->numOfCols <= 0) {
// tscWarn("no tags or cols bound in sql, will not bound tags");
// return TSDB_CODE_SUCCESS;
// }
STableDataCxt** pDataBlock =
(STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName));

View File

@ -788,6 +788,8 @@ TEST(clientCase, insert_test) {
}
TEST(clientCase, projection_query_tables) {
taos_options(TSDB_OPTION_CONFIGDIR, "/home/lisa/first/cfg");
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
ASSERT_NE(pConn, nullptr);
@ -796,6 +798,12 @@ TEST(clientCase, projection_query_tables) {
pRes= taos_query(pConn, "use abc1");
taos_free_result(pRes);
pRes = taos_query(pConn, "select forecast(k,'algo=arima,wncheck=0') from t1 where ts<='2024-11-15 1:7:44'");
if (taos_errno(pRes) != 0) {
(void)printf("failed to create table tu, reason:%s\n", taos_errstr(pRes));
}
taos_free_result(pRes);
pRes = taos_query(pConn, "create table tu using st2 tags(2)");
if (taos_errno(pRes) != 0) {
(void)printf("failed to create table tu, reason:%s\n", taos_errstr(pRes));

View File

@ -449,9 +449,11 @@ static int32_t tBindInfoCompare(const void *p1, const void *p2, const void *para
* `infoSorted` is whether the bind information is sorted by column id
* `pTSchema` is the schema of the table
* `rowArray` is the array to store the rows
* `pOrdered` is the pointer to store ordered
* `pDupTs` is the pointer to store duplicateTs
*/
int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema,
SArray *rowArray) {
SArray *rowArray, bool *pOrdered, bool *pDupTs) {
if (infos == NULL || numOfInfos <= 0 || numOfInfos > pTSchema->numOfCols || pTSchema == NULL || rowArray == NULL) {
return TSDB_CODE_INVALID_PARA;
}
@ -469,6 +471,7 @@ int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted,
return terrno;
}
SRowKey rowKey, lastRowKey;
for (int32_t iRow = 0; iRow < numOfRows; iRow++) {
taosArrayClear(colValArray);
@ -507,6 +510,22 @@ int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted,
code = terrno;
goto _exit;
}
if (pOrdered && pDupTs) {
tRowGetKey(row, &rowKey);
if (iRow == 0) {
*pOrdered = true;
*pDupTs = false;
} else {
// no more compare if we already get disordered or duplicate rows
if (*pOrdered && !*pDupTs) {
int32_t code = tRowKeyCompare(&rowKey, &lastRowKey);
*pOrdered = (code >= 0);
*pDupTs = (code == 0);
}
}
lastRowKey = rowKey;
}
}
_exit:
@ -3235,9 +3254,11 @@ _exit:
* `infoSorted` is whether the bind information is sorted by column id
* `pTSchema` is the schema of the table
* `rowArray` is the array to store the rows
* `pOrdered` is the pointer to store ordered
* `pDupTs` is the pointer to store duplicateTs
*/
int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema,
SArray *rowArray) {
SArray *rowArray, bool *pOrdered, bool *pDupTs) {
if (infos == NULL || numOfInfos <= 0 || numOfInfos > pTSchema->numOfCols || pTSchema == NULL || rowArray == NULL) {
return TSDB_CODE_INVALID_PARA;
}
@ -3266,6 +3287,7 @@ int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorte
}
}
SRowKey rowKey, lastRowKey;
for (int32_t iRow = 0; iRow < numOfRows; iRow++) {
taosArrayClear(colValArray);
@ -3317,6 +3339,22 @@ int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorte
code = terrno;
goto _exit;
}
if (pOrdered && pDupTs) {
tRowGetKey(row, &rowKey);
if (iRow == 0) {
*pOrdered = true;
*pDupTs = false;
} else {
// no more compare if we already get disordered or duplicate rows
if (*pOrdered && !*pDupTs) {
int32_t code = tRowKeyCompare(&rowKey, &lastRowKey);
*pOrdered = (code >= 0);
*pDupTs = (code == 0);
}
}
lastRowKey = rowKey;
}
}
_exit:

View File

@ -18,7 +18,7 @@
#include "tcompression.h"
const int32_t TYPE_BYTES[21] = {
-1, // TSDB_DATA_TYPE_NULL
2, // TSDB_DATA_TYPE_NULL
CHAR_BYTES, // TSDB_DATA_TYPE_BOOL
CHAR_BYTES, // TSDB_DATA_TYPE_TINYINT
SHORT_BYTES, // TSDB_DATA_TYPE_SMALLINT
@ -42,7 +42,7 @@ const int32_t TYPE_BYTES[21] = {
};
tDataTypeDescriptor tDataTypes[TSDB_DATA_TYPE_MAX] = {
{TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE", 0, 0, NULL, NULL},
{TSDB_DATA_TYPE_NULL, 6, 2, "NOTYPE", 0, 0, NULL, NULL},
{TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", false, true, tsCompressBool, tsDecompressBool},
{TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT", INT8_MIN, INT8_MAX, tsCompressTinyint, tsDecompressTinyint},
{TSDB_DATA_TYPE_SMALLINT, 8, SHORT_BYTES, "SMALLINT", INT16_MIN, INT16_MAX, tsCompressSmallint,

View File

@ -69,6 +69,7 @@ int32_t dmStartStatusThread(SDnodeMgmt *pMgmt);
int32_t dmStartConfigThread(SDnodeMgmt *pMgmt);
int32_t dmStartStatusInfoThread(SDnodeMgmt *pMgmt);
void dmStopStatusThread(SDnodeMgmt *pMgmt);
void dmStopConfigThread(SDnodeMgmt *pMgmt);
void dmStopStatusInfoThread(SDnodeMgmt *pMgmt);
int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt);
void dmStopNotifyThread(SDnodeMgmt *pMgmt);

View File

@ -52,6 +52,7 @@ static void dmStopMgmt(SDnodeMgmt *pMgmt) {
dmStopMonitorThread(pMgmt);
dmStopAuditThread(pMgmt);
dmStopStatusThread(pMgmt);
dmStopConfigThread(pMgmt);
dmStopStatusInfoThread(pMgmt);
#if defined(TD_ENTERPRISE)
dmStopNotifyThread(pMgmt);

View File

@ -343,7 +343,7 @@ int32_t dmStartConfigThread(SDnodeMgmt *pMgmt) {
int32_t code = 0;
TdThreadAttr thAttr;
(void)taosThreadAttrInit(&thAttr);
(void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_DETACHED);
(void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
if (taosThreadCreate(&pMgmt->configThread, &thAttr, dmConfigThreadFp, pMgmt) != 0) {
code = TAOS_SYSTEM_ERROR(errno);
dError("failed to create config thread since %s", tstrerror(code));
@ -378,6 +378,13 @@ void dmStopStatusThread(SDnodeMgmt *pMgmt) {
}
}
void dmStopConfigThread(SDnodeMgmt *pMgmt) {
if (taosCheckPthreadValid(pMgmt->configThread)) {
(void)taosThreadJoin(pMgmt->configThread, NULL);
taosThreadClear(&pMgmt->configThread);
}
}
void dmStopStatusInfoThread(SDnodeMgmt *pMgmt) {
if (taosCheckPthreadValid(pMgmt->statusInfoThread)) {
(void)taosThreadJoin(pMgmt->statusInfoThread, NULL);

View File

@ -211,7 +211,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
#if defined(TD_ENTERPRISE)
pCfg->tdbEncryptAlgorithm = pCreate->encryptAlgorithm;
if (pCfg->tdbEncryptAlgorithm == DND_CA_SM4) {
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
}
#else
pCfg->tdbEncryptAlgorithm = 0;

View File

@ -673,8 +673,6 @@ static int32_t mndSetUpdateIdxStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStb
code = TSDB_CODE_MND_TAG_NOT_EXIST;
TAOS_RETURN(code);
}
col_id_t colId = pOld->pTags[tag].colId;
TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId));
TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew));
SSchema *pTag = pNew->pTags + tag;
@ -806,16 +804,7 @@ static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *re
TAOS_RETURN(code);
}
col_id_t colId = pStb->pTags[tag].colId;
TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pStb->name, pStb->uid, colId));
// SSchema *pTag = pStb->pTags + tag;
// if (IS_IDX_ON(pTag)) {
// terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
// return -1;
// }
code = mndAddIndexImpl(pMnode, pReq, pDb, pStb, &idxObj);
TAOS_RETURN(code);
}

View File

@ -1805,7 +1805,6 @@ static int32_t mndUpdateSuperTableColumnCompress(SMnode *pMnode, const SStbObj *
}
SSchema *pTarget = &pOld->pColumns[idx];
col_id_t colId = pTarget->colId;
TAOS_CHECK_RETURN(mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId));
TAOS_CHECK_RETURN(mndAllocStbSchemas(pOld, pNew));
code = validColCmprByType(pTarget->type, p->bytes);
@ -3702,10 +3701,6 @@ static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *ta
terrno = TSDB_CODE_MND_TAG_NOT_EXIST;
return -1;
}
col_id_t colId = pOld->pTags[tag].colId;
if (mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId) != 0) {
return -1;
}
if (mndAllocStbSchemas(pOld, pNew) != 0) {
return -1;
}

View File

@ -1685,11 +1685,6 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) {
mInfo("stream:%s,%" PRId64 " start to pause stream", pauseReq.name, pStream->uid);
if (pStream->status == STREAM_STATUS__PAUSE) {
sdbRelease(pMnode->pSdb, pStream);
return 0;
}
if ((code = mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pStream->targetDb)) != 0) {
sdbRelease(pMnode->pSdb, pStream);
return code;
@ -1778,7 +1773,6 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) {
// pause stream
taosWLockLatch(&pStream->lock);
pStream->status = STREAM_STATUS__PAUSE;
code = mndPersistTransLog(pStream, pTrans, SDB_STATUS_READY);
if (code) {
taosWUnLockLatch(&pStream->lock);
@ -1829,11 +1823,6 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) {
}
}
if (pStream->status != STREAM_STATUS__PAUSE) {
sdbRelease(pMnode->pSdb, pStream);
return 0;
}
mInfo("stream:%s,%" PRId64 " start to resume stream from pause", resumeReq.name, pStream->uid);
if (mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pStream->targetDb) != 0) {
sdbRelease(pMnode->pSdb, pStream);

View File

@ -914,8 +914,7 @@ int32_t mndResetChkptReportInfo(SHashObj *pHash, int64_t streamId) {
return TSDB_CODE_MND_STREAM_NOT_EXIST;
}
static void mndShowStreamStatus(char *dst, SStreamObj *pStream) {
int8_t status = atomic_load_8(&pStream->status);
static void mndShowStreamStatus(char *dst, int8_t status) {
if (status == STREAM_STATUS__NORMAL) {
tstrncpy(dst, "ready", MND_STREAM_TRIGGER_NAME_SIZE);
} else if (status == STREAM_STATUS__STOP) {
@ -951,6 +950,41 @@ static void int64ToHexStr(int64_t id, char *pBuf, int32_t bufLen) {
varDataSetLen(pBuf, len + 2);
}
static int32_t isAllTaskPaused(SStreamObj *pStream, bool *pRes) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
SStreamTaskIter *pIter = NULL;
bool isPaused = true;
taosRLockLatch(&pStream->lock);
code = createStreamTaskIter(pStream, &pIter);
TSDB_CHECK_CODE(code, lino, _end);
while (streamTaskIterNextTask(pIter)) {
SStreamTask *pTask = NULL;
code = streamTaskIterGetCurrent(pIter, &pTask);
TSDB_CHECK_CODE(code, lino, _end);
STaskId id = {.streamId = pTask->id.streamId, .taskId = pTask->id.taskId};
STaskStatusEntry *pe = taosHashGet(execInfo.pTaskMap, &id, sizeof(id));
if (pe == NULL) {
continue;
}
if (pe->status != TASK_STATUS__PAUSE) {
isPaused = false;
}
}
(*pRes) = isPaused;
_end:
destroyStreamTaskIter(pIter);
taosRUnLockLatch(&pStream->lock);
if (code != TSDB_CODE_SUCCESS) {
mError("error happens when get stream status, lino:%d, code:%s", lino, tstrerror(code));
}
return code;
}
int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_t numOfRows) {
int32_t code = 0;
int32_t cols = 0;
@ -999,7 +1033,15 @@ int32_t setStreamAttrInResBlock(SStreamObj *pStream, SSDataBlock *pBlock, int32_
char status[20 + VARSTR_HEADER_SIZE] = {0};
char status2[MND_STREAM_TRIGGER_NAME_SIZE] = {0};
mndShowStreamStatus(status2, pStream);
bool isPaused = false;
code = isAllTaskPaused(pStream, &isPaused);
TSDB_CHECK_CODE(code, lino, _end);
int8_t streamStatus = atomic_load_8(&pStream->status);
if (isPaused) {
streamStatus = STREAM_STATUS__PAUSE;
}
mndShowStreamStatus(status2, streamStatus);
STR_WITH_MAXSIZE_TO_VARSTR(status, status2, sizeof(status));
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
TSDB_CHECK_NULL(pColInfo, code, lino, _end, terrno);
@ -1430,7 +1472,7 @@ int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, cons
return TSDB_CODE_INVALID_PARA;
}
pInfo->pUpdateNodeList = taosArrayInit(4, sizeof(SNodeUpdateInfo)),
pInfo->pUpdateNodeList = taosArrayInit(4, sizeof(SNodeUpdateInfo));
pInfo->pDBMap = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK);
if (pInfo->pUpdateNodeList == NULL || pInfo->pDBMap == NULL) {

View File

@ -327,7 +327,7 @@ struct SVnodeCfg {
int16_t hashSuffix;
int32_t tsdbPageSize;
int32_t tdbEncryptAlgorithm;
char tdbEncryptKey[ENCRYPT_KEY_LEN];
char tdbEncryptKey[ENCRYPT_KEY_LEN + 1];
int32_t s3ChunkSize;
int32_t s3KeepLocal;
int8_t s3Compact;

View File

@ -104,7 +104,7 @@ int32_t tsdbOpenFile(const char *path, STsdb *pTsdb, int32_t flag, STsdbFD **ppF
}
pFD->path = (char *)&pFD[1];
tstrncpy(pFD->path, path, strlen(path) + 1);
memcpy(pFD->path, path, strlen(path) + 1);
pFD->szPage = szPage;
pFD->flag = flag;
pFD->szPage = szPage;

View File

@ -330,7 +330,7 @@ static int32_t vnodeAsyncInit(SVAsync **async, const char *label) {
return terrno;
}
tstrncpy((char *)((*async) + 1), label, strlen(label) + 1);
memcpy((char *)((*async) + 1), label, strlen(label) + 1);
(*async)->label = (const char *)((*async) + 1);
(void)taosThreadMutexInit(&(*async)->mutex, NULL);

View File

@ -303,7 +303,7 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
if (tsEncryptKey[0] == 0) {
return terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
} else {
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
tstrncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN + 1);
}
}
#endif

View File

@ -417,7 +417,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC
}
pVnode->path = (char *)&pVnode[1];
tstrncpy(pVnode->path, path, strlen(path) + 1);
memcpy(pVnode->path, path, strlen(path) + 1);
pVnode->config = info.config;
pVnode->state.committed = info.state.committed;
pVnode->state.commitTerm = info.state.commitTerm;

View File

@ -830,7 +830,7 @@ int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
vTrace("message in vnode query queue is processing");
if ((pMsg->msgType == TDMT_SCH_QUERY || pMsg->msgType == TDMT_VND_TMQ_CONSUME) && !syncIsReadyForRead(pVnode->sync)) {
if (pMsg->msgType == TDMT_VND_TMQ_CONSUME && !syncIsReadyForRead(pVnode->sync)) {
vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
return 0;
}
@ -842,9 +842,21 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
SReadHandle handle = {.vnode = pVnode, .pMsgCb = &pVnode->msgCb, .pWorkerCb = pInfo->workerCb};
initStorageAPI(&handle.api);
int32_t code = TSDB_CODE_SUCCESS;
bool redirected = false;
switch (pMsg->msgType) {
case TDMT_SCH_QUERY:
if (!syncIsReadyForRead(pVnode->sync)) {
pMsg->code = (terrno) ? terrno : TSDB_CODE_SYN_NOT_LEADER;
redirected = true;
}
code = qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
if (redirected) {
vnodeRedirectRpcMsg(pVnode, pMsg, pMsg->code);
return 0;
}
return code;
case TDMT_SCH_MERGE_QUERY:
return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
case TDMT_SCH_QUERY_CONTINUE:

View File

@ -497,6 +497,8 @@ typedef struct SCtgAsyncFps {
ctgDumpTaskResFp dumpResFp;
ctgCompTaskFp compFp;
ctgCloneTaskResFp cloneFp;
int32_t subTaskFactor; // to indicate how many sub tasks this task will generate by ctgLaunchSubTask
// default to 1, means no sub task, 2 means 1 sub task, 3 means 2 sub tasks...
} SCtgAsyncFps;
typedef struct SCtgApiStat {

View File

@ -861,6 +861,16 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
int32_t taskNum = tbMetaNum + dbVgNum + udfNum + tbHashNum + qnodeNum + dnodeNum + svrVerNum + dbCfgNum + indexNum +
userNum + dbInfoNum + tbIndexNum + tbCfgNum + tbTagNum + viewNum + tbTsmaNum + tbNameNum;
int32_t taskNumWithSubTasks = tbMetaNum * gCtgAsyncFps[CTG_TASK_GET_TB_META].subTaskFactor + dbVgNum * gCtgAsyncFps[CTG_TASK_GET_DB_VGROUP].subTaskFactor +
udfNum * gCtgAsyncFps[CTG_TASK_GET_UDF].subTaskFactor + tbHashNum * gCtgAsyncFps[CTG_TASK_GET_TB_HASH].subTaskFactor +
qnodeNum * gCtgAsyncFps[CTG_TASK_GET_QNODE].subTaskFactor + dnodeNum * gCtgAsyncFps[CTG_TASK_GET_DNODE].subTaskFactor +
svrVerNum * gCtgAsyncFps[CTG_TASK_GET_SVR_VER].subTaskFactor + dbCfgNum * gCtgAsyncFps[CTG_TASK_GET_DB_CFG].subTaskFactor +
indexNum * gCtgAsyncFps[CTG_TASK_GET_INDEX_INFO].subTaskFactor + userNum * gCtgAsyncFps[CTG_TASK_GET_USER].subTaskFactor +
dbInfoNum * gCtgAsyncFps[CTG_TASK_GET_DB_INFO].subTaskFactor + tbIndexNum * gCtgAsyncFps[CTG_TASK_GET_TB_SMA_INDEX].subTaskFactor +
tbCfgNum * gCtgAsyncFps[CTG_TASK_GET_TB_CFG].subTaskFactor + tbTagNum * gCtgAsyncFps[CTG_TASK_GET_TB_TAG].subTaskFactor +
viewNum * gCtgAsyncFps[CTG_TASK_GET_VIEW].subTaskFactor + tbTsmaNum * gCtgAsyncFps[CTG_TASK_GET_TB_TSMA].subTaskFactor +
tsmaNum * gCtgAsyncFps[CTG_TASK_GET_TSMA].subTaskFactor + tbNameNum * gCtgAsyncFps[CTG_TASK_GET_TB_NAME].subTaskFactor;
*job = taosMemoryCalloc(1, sizeof(SCtgJob));
if (NULL == *job) {
ctgError("failed to calloc, size:%d,QID:0x%" PRIx64, (int32_t)sizeof(SCtgJob), pConn->requestId);
@ -905,7 +915,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
}
#endif
pJob->pTasks = taosArrayInit(taskNum, sizeof(SCtgTask));
pJob->pTasks = taosArrayInit(taskNumWithSubTasks, sizeof(SCtgTask));
if (NULL == pJob->pTasks) {
ctgError("taosArrayInit %d tasks failed", taskNum);
CTG_ERR_JRET(terrno);
@ -4178,27 +4188,27 @@ int32_t ctgCloneDbVg(SCtgTask* pTask, void** pRes) {
}
SCtgAsyncFps gCtgAsyncFps[] = {
{ctgInitGetQnodeTask, ctgLaunchGetQnodeTask, ctgHandleGetQnodeRsp, ctgDumpQnodeRes, NULL, NULL},
{ctgInitGetDnodeTask, ctgLaunchGetDnodeTask, ctgHandleGetDnodeRsp, ctgDumpDnodeRes, NULL, NULL},
{ctgInitGetDbVgTask, ctgLaunchGetDbVgTask, ctgHandleGetDbVgRsp, ctgDumpDbVgRes, ctgCompDbVgTasks, ctgCloneDbVg},
{ctgInitGetDbCfgTask, ctgLaunchGetDbCfgTask, ctgHandleGetDbCfgRsp, ctgDumpDbCfgRes, NULL, NULL},
{ctgInitGetDbInfoTask, ctgLaunchGetDbInfoTask, ctgHandleGetDbInfoRsp, ctgDumpDbInfoRes, NULL, NULL},
{ctgInitGetQnodeTask, ctgLaunchGetQnodeTask, ctgHandleGetQnodeRsp, ctgDumpQnodeRes, NULL, NULL, 1},
{ctgInitGetDnodeTask, ctgLaunchGetDnodeTask, ctgHandleGetDnodeRsp, ctgDumpDnodeRes, NULL, NULL, 1},
{ctgInitGetDbVgTask, ctgLaunchGetDbVgTask, ctgHandleGetDbVgRsp, ctgDumpDbVgRes, ctgCompDbVgTasks, ctgCloneDbVg, 1},
{ctgInitGetDbCfgTask, ctgLaunchGetDbCfgTask, ctgHandleGetDbCfgRsp, ctgDumpDbCfgRes, NULL, NULL, 1},
{ctgInitGetDbInfoTask, ctgLaunchGetDbInfoTask, ctgHandleGetDbInfoRsp, ctgDumpDbInfoRes, NULL, NULL, 1},
{ctgInitGetTbMetaTask, ctgLaunchGetTbMetaTask, ctgHandleGetTbMetaRsp, ctgDumpTbMetaRes, ctgCompTbMetaTasks,
ctgCloneTbMeta},
{ctgInitGetTbHashTask, ctgLaunchGetTbHashTask, ctgHandleGetTbHashRsp, ctgDumpTbHashRes, NULL, NULL},
{ctgInitGetTbIndexTask, ctgLaunchGetTbIndexTask, ctgHandleGetTbIndexRsp, ctgDumpTbIndexRes, NULL, NULL},
{ctgInitGetTbCfgTask, ctgLaunchGetTbCfgTask, ctgHandleGetTbCfgRsp, ctgDumpTbCfgRes, NULL, NULL},
{ctgInitGetIndexTask, ctgLaunchGetIndexTask, ctgHandleGetIndexRsp, ctgDumpIndexRes, NULL, NULL},
{ctgInitGetUdfTask, ctgLaunchGetUdfTask, ctgHandleGetUdfRsp, ctgDumpUdfRes, NULL, NULL},
{ctgInitGetUserTask, ctgLaunchGetUserTask, ctgHandleGetUserRsp, ctgDumpUserRes, NULL, NULL},
{ctgInitGetSvrVerTask, ctgLaunchGetSvrVerTask, ctgHandleGetSvrVerRsp, ctgDumpSvrVer, NULL, NULL},
{ctgInitGetTbMetasTask, ctgLaunchGetTbMetasTask, ctgHandleGetTbMetasRsp, ctgDumpTbMetasRes, NULL, NULL},
{ctgInitGetTbHashsTask, ctgLaunchGetTbHashsTask, ctgHandleGetTbHashsRsp, ctgDumpTbHashsRes, NULL, NULL},
{ctgInitGetTbTagTask, ctgLaunchGetTbTagTask, ctgHandleGetTbTagRsp, ctgDumpTbTagRes, NULL, NULL},
{ctgInitGetViewsTask, ctgLaunchGetViewsTask, ctgHandleGetViewsRsp, ctgDumpViewsRes, NULL, NULL},
{ctgInitGetTbTSMATask, ctgLaunchGetTbTSMATask, ctgHandleGetTbTSMARsp, ctgDumpTbTSMARes, NULL, NULL},
{ctgInitGetTSMATask, ctgLaunchGetTSMATask, ctgHandleGetTSMARsp, ctgDumpTSMARes, NULL, NULL},
{ctgInitGetTbNamesTask, ctgLaunchGetTbNamesTask, ctgHandleGetTbNamesRsp, ctgDumpTbNamesRes, NULL, NULL},
ctgCloneTbMeta, 1},
{ctgInitGetTbHashTask, ctgLaunchGetTbHashTask, ctgHandleGetTbHashRsp, ctgDumpTbHashRes, NULL, NULL, 1},
{ctgInitGetTbIndexTask, ctgLaunchGetTbIndexTask, ctgHandleGetTbIndexRsp, ctgDumpTbIndexRes, NULL, NULL, 1},
{ctgInitGetTbCfgTask, ctgLaunchGetTbCfgTask, ctgHandleGetTbCfgRsp, ctgDumpTbCfgRes, NULL, NULL, 2},
{ctgInitGetIndexTask, ctgLaunchGetIndexTask, ctgHandleGetIndexRsp, ctgDumpIndexRes, NULL, NULL, 1},
{ctgInitGetUdfTask, ctgLaunchGetUdfTask, ctgHandleGetUdfRsp, ctgDumpUdfRes, NULL, NULL, 1},
{ctgInitGetUserTask, ctgLaunchGetUserTask, ctgHandleGetUserRsp, ctgDumpUserRes, NULL, NULL, 2},
{ctgInitGetSvrVerTask, ctgLaunchGetSvrVerTask, ctgHandleGetSvrVerRsp, ctgDumpSvrVer, NULL, NULL, 1},
{ctgInitGetTbMetasTask, ctgLaunchGetTbMetasTask, ctgHandleGetTbMetasRsp, ctgDumpTbMetasRes, NULL, NULL, 1},
{ctgInitGetTbHashsTask, ctgLaunchGetTbHashsTask, ctgHandleGetTbHashsRsp, ctgDumpTbHashsRes, NULL, NULL, 1},
{ctgInitGetTbTagTask, ctgLaunchGetTbTagTask, ctgHandleGetTbTagRsp, ctgDumpTbTagRes, NULL, NULL, 2},
{ctgInitGetViewsTask, ctgLaunchGetViewsTask, ctgHandleGetViewsRsp, ctgDumpViewsRes, NULL, NULL, 1},
{ctgInitGetTbTSMATask, ctgLaunchGetTbTSMATask, ctgHandleGetTbTSMARsp, ctgDumpTbTSMARes, NULL, NULL, 1},
{ctgInitGetTSMATask, ctgLaunchGetTSMATask, ctgHandleGetTSMARsp, ctgDumpTSMARes, NULL, NULL, 1},
{ctgInitGetTbNamesTask, ctgLaunchGetTbNamesTask, ctgHandleGetTbNamesRsp, ctgDumpTbNamesRes, NULL, NULL, 1},
};
int32_t ctgMakeAsyncRes(SCtgJob* pJob) {

View File

@ -72,17 +72,20 @@ static FORCE_INLINE int32_t forecastEnsureBlockCapacity(SSDataBlock* pBlock, int
return TSDB_CODE_SUCCESS;
}
static int32_t forecastCacheBlock(SForecastSupp* pSupp, SSDataBlock* pBlock) {
if (pSupp->cachedRows > ANAL_FORECAST_MAX_ROWS) {
return TSDB_CODE_ANA_ANODE_TOO_MANY_ROWS;
}
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
static int32_t forecastCacheBlock(SForecastSupp* pSupp, SSDataBlock* pBlock, const char* id) {
int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0;
SAnalyticBuf* pBuf = &pSupp->analBuf;
qDebug("block:%d, %p rows:%" PRId64, pSupp->numOfBlocks, pBlock, pBlock->info.rows);
if (pSupp->cachedRows > ANAL_FORECAST_MAX_ROWS) {
code = TSDB_CODE_ANA_ANODE_TOO_MANY_ROWS;
qError("%s rows:%" PRId64 " for forecast cache, error happens, code:%s, upper limit:%d", id, pSupp->cachedRows,
tstrerror(code), ANAL_FORECAST_MAX_ROWS);
return code;
}
pSupp->numOfBlocks++;
qDebug("%s block:%d, %p rows:%" PRId64, id, pSupp->numOfBlocks, pBlock, pBlock->info.rows);
for (int32_t j = 0; j < pBlock->info.rows; ++j) {
SColumnInfoData* pValCol = taosArrayGet(pBlock->pDataBlock, pSupp->inputValSlot);
@ -98,10 +101,16 @@ static int32_t forecastCacheBlock(SForecastSupp* pSupp, SSDataBlock* pBlock) {
pSupp->numOfRows++;
code = taosAnalBufWriteColData(pBuf, 0, TSDB_DATA_TYPE_TIMESTAMP, &ts);
if (TSDB_CODE_SUCCESS != code) return code;
if (TSDB_CODE_SUCCESS != code) {
qError("%s failed to write ts in buf, code:%s", id, tstrerror(code));
return code;
}
code = taosAnalBufWriteColData(pBuf, 1, valType, val);
if (TSDB_CODE_SUCCESS != code) return code;
if (TSDB_CODE_SUCCESS != code) {
qError("%s failed to write val in buf, code:%s", id, tstrerror(code));
return code;
}
}
return 0;
@ -394,7 +403,7 @@ static int32_t forecastNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
pSupp->cachedRows += pBlock->info.rows;
qDebug("%s group:%" PRId64 ", blocks:%d, rows:%" PRId64 ", total rows:%" PRId64, pId, pSupp->groupId, numOfBlocks,
pBlock->info.rows, pSupp->cachedRows);
code = forecastCacheBlock(pSupp, pBlock);
code = forecastCacheBlock(pSupp, pBlock, pId);
QUERY_CHECK_CODE(code, lino, _end);
} else {
qDebug("%s group:%" PRId64 ", read finish for new group coming, blocks:%d", pId, pSupp->groupId, numOfBlocks);
@ -405,7 +414,7 @@ static int32_t forecastNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
pSupp->cachedRows = pBlock->info.rows;
qDebug("%s group:%" PRId64 ", new group, rows:%" PRId64 ", total rows:%" PRId64, pId, pSupp->groupId,
pBlock->info.rows, pSupp->cachedRows);
code = forecastCacheBlock(pSupp, pBlock);
code = forecastCacheBlock(pSupp, pBlock, pId);
QUERY_CHECK_CODE(code, lino, _end);
}

View File

@ -326,7 +326,7 @@ static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
indexError("invalid length for node:%p, length: %d", node, LIST_LENGTH(nl->pNodeList));
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
}
SIF_ERR_RET(scalarGenerateSetFromList((void **)&param->pFilter, node, nl->node.resType.type));
SIF_ERR_RET(scalarGenerateSetFromList((void **)&param->pFilter, node, nl->node.resType.type, 0));
if (taosHashPut(ctx->pRes, &node, POINTER_BYTES, param, sizeof(*param))) {
taosHashCleanup(param->pFilter);
param->pFilter = NULL;

View File

@ -611,7 +611,12 @@ static void resetProjectNullType(SNode* pStmt) {
resetProjectNullTypeImpl(((SSelectStmt*)pStmt)->pProjectionList);
break;
case QUERY_NODE_SET_OPERATOR: {
resetProjectNullTypeImpl(((SSetOperator*)pStmt)->pProjectionList);
SSetOperator* pSetOp = (SSetOperator*)pStmt;
resetProjectNullTypeImpl(pSetOp->pProjectionList);
if (pSetOp->pLeft)
resetProjectNullType(pSetOp->pLeft);
if (pSetOp->pRight)
resetProjectNullType(pSetOp->pRight);
break;
}
default:

View File

@ -368,7 +368,7 @@ int32_t qBindStmtStbColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind
// }
}
code = tRowBuildFromBind(pBindInfos, boundInfo->numOfBound, colInOrder, *pTSchema, pCols);
code = tRowBuildFromBind(pBindInfos, boundInfo->numOfBound, colInOrder, *pTSchema, pCols, &pDataBlock->ordered, &pDataBlock->duplicateTs);
qDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum);
@ -745,7 +745,7 @@ int32_t qBindStmtStbColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bin
pBindInfos[c].bytes = pColSchema->bytes;
}
code = tRowBuildFromBind2(pBindInfos, boundInfo->numOfBound, colInOrder, *pTSchema, pCols);
code = tRowBuildFromBind2(pBindInfos, boundInfo->numOfBound, colInOrder, *pTSchema, pCols, &pDataBlock->ordered, &pDataBlock->duplicateTs);
qDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum);

View File

@ -101,10 +101,13 @@ int32_t insCreateSName(SName* pName, SToken* pTableName, int32_t acctId, const c
return buildInvalidOperationMsg(pMsgBuf, msg1);
}
} else { // get current DB name first, and then set it into path
if (pTableName->n >= TSDB_TABLE_NAME_LEN) {
char tbname[TSDB_TABLE_FNAME_LEN] = {0};
strncpy(tbname, pTableName->z, pTableName->n);
int32_t tbLen = strdequote(tbname);
if (tbLen >= TSDB_TABLE_NAME_LEN) {
return buildInvalidOperationMsg(pMsgBuf, msg1);
}
if (pTableName->n == 0) {
if (tbLen == 0) {
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, "invalid table name");
}

View File

@ -2270,6 +2270,7 @@ static bool dataTypeEqual(const SDataType* l, const SDataType* r) {
// 0 means equal, 1 means the left shall prevail, -1 means the right shall prevail
static int32_t dataTypeComp(const SDataType* l, const SDataType* r) {
if (l->type == TSDB_DATA_TYPE_NULL) return -1;
if (l->type != r->type) {
return 1;
}

View File

@ -320,9 +320,8 @@ extern SQueryMgmt gQueryMgmt;
case QW_PHASE_POST_QUERY: \
case QW_PHASE_PRE_CQUERY: \
case QW_PHASE_POST_CQUERY: \
atomic_store_8(&(ctx)->phase, _value); \
break; \
default: \
atomic_store_8(&(ctx)->phase, _value); \
break; \
} \
} while (0)

View File

@ -83,13 +83,16 @@ void qwDestroySession(QW_FPARAMS_DEF, SQWJobInfo *pJobInfo, void* session) {
taosMemPoolDestroySession(gMemPoolHandle, session);
QW_LOCK(QW_WRITE, &pJobInfo->lock);
int32_t remainSessions = atomic_sub_fetch_32(&pJobInfo->memInfo->remainSession, 1);
if (remainSessions != 0) {
QW_UNLOCK(QW_WRITE, &pJobInfo->lock);
}
QW_TASK_DLOG("task session destoryed, remainSessions:%d", remainSessions);
if (0 == remainSessions) {
QW_LOCK(QW_WRITE, &pJobInfo->lock);
if (/*0 == taosHashGetSize(pJobInfo->pSessions) && */0 == atomic_load_32(&pJobInfo->memInfo->remainSession)) {
// if (/*0 == taosHashGetSize(pJobInfo->pSessions) && */0 == atomic_load_32(&pJobInfo->memInfo->remainSession)) {
atomic_store_8(&pJobInfo->destroyed, 1);
QW_UNLOCK(QW_WRITE, &pJobInfo->lock);
@ -98,10 +101,10 @@ void qwDestroySession(QW_FPARAMS_DEF, SQWJobInfo *pJobInfo, void* session) {
TAOS_UNUSED(taosHashRemove(gQueryMgmt.pJobInfo, id2, sizeof(id2)));
QW_TASK_DLOG_E("the whole query job removed");
} else {
QW_TASK_DLOG("job not removed, remainSessions:%d, %d", taosHashGetSize(pJobInfo->pSessions), pJobInfo->memInfo->remainSession);
QW_UNLOCK(QW_WRITE, &pJobInfo->lock);
}
// } else {
// QW_TASK_DLOG("job not removed, remainSessions:%d, %d", taosHashGetSize(pJobInfo->pSessions), pJobInfo->memInfo->remainSession);
// QW_UNLOCK(QW_WRITE, &pJobInfo->lock);
// }
}
}
@ -147,12 +150,15 @@ int32_t qwRetrieveJobInfo(QW_FPARAMS_DEF, SQWJobInfo** ppJob) {
}
QW_LOCK(QW_READ, &pJob->lock);
if (atomic_load_8(&pJob->destroyed)) {
QW_UNLOCK(QW_READ, &pJob->lock);
taosHashRelease(gQueryMgmt.pJobInfo, pJob);
continue;
}
(void)atomic_add_fetch_32(&pJob->memInfo->remainSession, 1);
QW_UNLOCK(QW_READ, &pJob->lock);
break;

View File

@ -498,14 +498,14 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int
int64_t rId = msg.refId;
int32_t eId = msg.execId;
SQWMsg qwMsg = {.node = node, .msg = msg.msg, .msgLen = msg.msgLen, .connInfo = pMsg->info, .msgType = pMsg->msgType};
SQWMsg qwMsg = {.node = node, .msg = msg.msg, .msgLen = msg.msgLen, .connInfo = pMsg->info, .msgType = pMsg->msgType, .code = pMsg->code};
qwMsg.msgInfo.explain = msg.explain;
qwMsg.msgInfo.taskType = msg.taskType;
qwMsg.msgInfo.needFetch = msg.needFetch;
qwMsg.msgInfo.compressMsg = msg.compress;
QW_SCH_TASK_DLOG("processQuery start, node:%p, type:%s, compress:%d, handle:%p, SQL:%s", node, TMSG_INFO(pMsg->msgType),
msg.compress, pMsg->info.handle, msg.sql);
QW_SCH_TASK_DLOG("processQuery start, node:%p, type:%s, compress:%d, handle:%p, SQL:%s, code:0x%x", node, TMSG_INFO(pMsg->msgType),
msg.compress, pMsg->info.handle, msg.sql, qwMsg.code);
code = qwProcessQuery(QW_FPARAMS(), &qwMsg, msg.sql);
msg.sql = NULL;

View File

@ -449,51 +449,64 @@ int32_t qwGetDeleteResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, SDeleteRes *pRes
return TSDB_CODE_SUCCESS;
}
int32_t qwQuickRspFetchReq(QW_FPARAMS_DEF, SQWTaskCtx *ctx, SQWMsg *qwMsg, int32_t code) {
if (QUERY_RSP_POLICY_QUICK == tsQueryRspPolicy && ctx != NULL) {
if (QW_EVENT_RECEIVED(ctx, QW_EVENT_FETCH)) {
void *rsp = NULL;
int32_t dataLen = 0;
int32_t rawLen = 0;
SOutputData sOutput = {0};
if (TSDB_CODE_SUCCESS == code) {
code = qwGetQueryResFromSink(QW_FPARAMS(), ctx, &dataLen, &rawLen, &rsp, &sOutput);
int32_t qwQuickRspFetchReq(QW_FPARAMS_DEF, SQWMsg *qwMsg, int32_t code) {
if (QUERY_RSP_POLICY_QUICK != tsQueryRspPolicy) {
return TSDB_CODE_SUCCESS;
}
SQWTaskCtx *ctx = NULL;
QW_ERR_JRET(qwAcquireTaskCtx(QW_FPARAMS(), &ctx));
if (!QW_EVENT_RECEIVED(ctx, QW_EVENT_FETCH)) {
goto _return;
}
void *rsp = NULL;
int32_t dataLen = 0;
int32_t rawLen = 0;
SOutputData sOutput = {0};
if (TSDB_CODE_SUCCESS == code) {
code = qwGetQueryResFromSink(QW_FPARAMS(), ctx, &dataLen, &rawLen, &rsp, &sOutput);
}
if (code) {
qwFreeFetchRsp(rsp);
rsp = NULL;
dataLen = 0;
}
if (NULL == rsp && TSDB_CODE_SUCCESS == code) {
goto _return;
}
if (NULL != rsp) {
bool qComplete = (DS_BUF_EMPTY == sOutput.bufStatus && sOutput.queryEnd);
qwBuildFetchRsp(rsp, &sOutput, dataLen, rawLen, qComplete);
if (qComplete) {
atomic_store_8((int8_t *)&ctx->queryEnd, true);
if (!ctx->dynamicTask) {
qwFreeSinkHandle(ctx);
}
if (code) {
qwFreeFetchRsp(rsp);
rsp = NULL;
dataLen = 0;
}
if (NULL == rsp && TSDB_CODE_SUCCESS == code) {
return TSDB_CODE_SUCCESS;
}
if (NULL != rsp) {
bool qComplete = (DS_BUF_EMPTY == sOutput.bufStatus && sOutput.queryEnd);
qwBuildFetchRsp(rsp, &sOutput, dataLen, rawLen, qComplete);
if (qComplete) {
atomic_store_8((int8_t *)&ctx->queryEnd, true);
if (!ctx->dynamicTask) {
qwFreeSinkHandle(ctx);
}
}
}
qwMsg->connInfo = ctx->dataConnInfo;
QW_SET_EVENT_PROCESSED(ctx, QW_EVENT_FETCH);
QW_ERR_RET(qwBuildAndSendFetchRsp(ctx, ctx->fetchMsgType + 1, &qwMsg->connInfo, rsp, dataLen, code));
rsp = NULL;
QW_TASK_DLOG("fetch rsp send, handle:%p, code:%x - %s, dataLen:%d", qwMsg->connInfo.handle, code, tstrerror(code),
dataLen);
}
}
return TSDB_CODE_SUCCESS;
qwMsg->connInfo = ctx->dataConnInfo;
QW_SET_EVENT_PROCESSED(ctx, QW_EVENT_FETCH);
QW_ERR_JRET(qwBuildAndSendFetchRsp(ctx, ctx->fetchMsgType + 1, &qwMsg->connInfo, rsp, dataLen, code));
rsp = NULL;
QW_TASK_DLOG("fetch rsp send, handle:%p, code:%x - %s, dataLen:%d", qwMsg->connInfo.handle, code, tstrerror(code),
dataLen);
_return:
if (ctx) {
qwReleaseTaskCtx(mgmt, ctx);
}
return code;
}
int32_t qwStartDynamicTaskNewExec(QW_FPARAMS_DEF, SQWTaskCtx *ctx, SQWMsg *qwMsg) {
@ -567,6 +580,14 @@ int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inpu
QW_ERR_JRET(ctx->rspCode);
}
if (TSDB_CODE_SUCCESS != input->code) {
QW_TASK_ELOG("task already failed at phase %s, code:0x%x", qwPhaseStr(phase), input->code);
ctx->ctrlConnInfo.handle = NULL;
(void)qwDropTask(QW_FPARAMS());
QW_ERR_JRET(input->code);
}
QW_ERR_JRET(qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_EXEC, ctx->dynamicTask));
break;
}
@ -631,6 +652,10 @@ _return:
if (ctx) {
QW_UPDATE_RSP_CODE(ctx, code);
if (QW_PHASE_PRE_CQUERY == phase && code) {
QW_SET_PHASE(ctx, QW_PHASE_POST_CQUERY);
}
QW_UNLOCK(QW_WRITE, &ctx->lock);
qwReleaseTaskCtx(mgmt, ctx);
}
@ -736,6 +761,8 @@ int32_t qwPreprocessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
QW_ERR_JRET(qwAcquireTaskCtx(QW_FPARAMS(), &ctx));
QW_LOCK(QW_WRITE, &ctx->lock);
ctx->ctrlConnInfo = qwMsg->connInfo;
ctx->sId = sId;
ctx->phase = -1;
@ -755,7 +782,8 @@ _return:
if (code) {
(void)qwDropTask(QW_FPARAMS());
}
QW_UNLOCK(QW_WRITE, &ctx->lock);
qwReleaseTaskCtx(mgmt, ctx);
}
@ -767,7 +795,7 @@ _return:
int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, char *sql) {
int32_t code = 0;
SSubplan *plan = NULL;
SQWPhaseInput input = {0};
SQWPhaseInput input = {.code = qwMsg->code};
qTaskInfo_t pTaskInfo = NULL;
DataSinkHandle sinkHandle = NULL;
SQWTaskCtx *ctx = NULL;
@ -808,10 +836,10 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, char *sql) {
QW_ERR_JRET(TSDB_CODE_APP_ERROR);
}
atomic_add_fetch_64(&gQueryMgmt.stat.taskRunNum, 1);
(void)atomic_add_fetch_64(&gQueryMgmt.stat.taskRunNum, 1);
uint64_t flags = 0;
dsGetSinkFlags(sinkHandle, &flags);
(void)dsGetSinkFlags(sinkHandle, &flags);
ctx->level = plan->level;
ctx->dynamicTask = qIsDynamicExecTask(pTaskInfo);
@ -836,7 +864,7 @@ _return:
input.msgType = qwMsg->msgType;
code = qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_QUERY, &input, NULL);
QW_ERR_RET(qwQuickRspFetchReq(QW_FPARAMS(), ctx, qwMsg, code));
QW_ERR_RET(qwQuickRspFetchReq(QW_FPARAMS(), qwMsg, code));
QW_RET(TSDB_CODE_SUCCESS);
}
@ -1342,7 +1370,7 @@ int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SDeleteRes *pRes) {
ctx.sinkHandle = sinkHandle;
uint64_t flags = 0;
dsGetSinkFlags(sinkHandle, &flags);
(void)dsGetSinkFlags(sinkHandle, &flags);
ctx.sinkWithMemPool = flags & DS_FLAG_USE_MEMPOOL;

View File

@ -236,6 +236,7 @@ typedef struct SFltBuildGroupCtx {
SFilterInfo *info;
SArray *group;
int32_t code;
bool ignore;
} SFltBuildGroupCtx;
typedef struct {
@ -266,6 +267,7 @@ struct SFilterInfo {
int8_t *blkUnitRes;
void *pTable;
SArray *blkList;
bool isStrict;
SFilterPCtx pctx;
};

View File

@ -21,6 +21,8 @@ extern "C" {
#include "query.h"
#include "tcommon.h"
#include "thash.h"
#include "querynodes.h"
#include "function.h"
typedef struct SOperatorValueType {
int32_t opResType;
@ -141,12 +143,14 @@ int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode);
#define GET_PARAM_PRECISON(_c) ((_c)->columnData->info.precision)
void sclFreeParam(SScalarParam* param);
int32_t doVectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t startIndex, int32_t numOfRows,
int32_t doVectorCompare(SScalarParam* pLeft, SScalarParam *pLeftVar, SScalarParam* pRight, SScalarParam *pOut, int32_t startIndex, int32_t numOfRows,
int32_t _ord, int32_t optr);
int32_t vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t startIndex, int32_t numOfRows,
int32_t _ord, int32_t optr);
int32_t vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr);
bool checkOperatorRestypeIsTimestamp(EOperatorType opType, int32_t ldt, int32_t rdt);
#ifdef __cplusplus
}
#endif

View File

@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <tlog.h>
#include "nodes.h"
#include "os.h"
#include "tglobal.h"
#include "thash.h"
@ -1284,7 +1285,8 @@ static void filterFreeGroup(void *pItem) {
taosMemoryFreeClear(p->unitFlags);
}
int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) {
int32_t fltAddGroupUnitFromNode(void *pContext, SFilterInfo *info, SNode *tree, SArray *group) {
SFltBuildGroupCtx *ctx = (SFltBuildGroupCtx *)pContext;
SOperatorNode *node = (SOperatorNode *)tree;
int32_t ret = TSDB_CODE_SUCCESS;
SFilterFieldId left = {0}, right = {0};
@ -1296,7 +1298,6 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) {
if (node->opType == OP_TYPE_IN && (!IS_VAR_DATA_TYPE(type))) {
SNodeListNode *listNode = (SNodeListNode *)node->pRight;
SListCell *cell = listNode->pNodeList->pHead;
SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))};
if (out.columnData == NULL) {
@ -1305,8 +1306,10 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) {
out.columnData->info.type = type;
out.columnData->info.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; // reserved space for simple_copy
for (int32_t i = 0; i < listNode->pNodeList->length; ++i) {
SValueNode *valueNode = (SValueNode *)cell->pNode;
int32_t overflowCount = 0;
SNode* nodeItem = NULL;
FOREACH(nodeItem, listNode->pNodeList) {
SValueNode *valueNode = (SValueNode *)nodeItem;
if (valueNode->node.resType.type != type) {
int32_t overflow = 0;
code = sclConvertValueToSclParam(valueNode, &out, &overflow);
@ -1316,7 +1319,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) {
}
if (overflow) {
cell = cell->pNext;
++overflowCount;
continue;
}
@ -1354,8 +1357,9 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) {
code = terrno;
break;
}
cell = cell->pNext;
}
if(overflowCount == listNode->pNodeList->length) {
ctx->ignore = true;
}
colDataDestroy(out.columnData);
taosMemoryFree(out.columnData);
@ -1692,10 +1696,17 @@ EDealRes fltTreeToGroup(SNode *pNode, void *pContext) {
FLT_ERR_RET(terrno);
}
SFltBuildGroupCtx tctx = {.info = ctx->info, .group = newGroup};
SFltBuildGroupCtx tctx = {.info = ctx->info, .group = newGroup, .ignore = false};
nodesWalkExpr(cell->pNode, fltTreeToGroup, (void *)&tctx);
FLT_ERR_JRET(tctx.code);
if(tctx.ignore) {
ctx->ignore = true;
taosArrayDestroyEx(newGroup, filterFreeGroup);
newGroup = NULL;
taosArrayDestroyEx(resGroup, filterFreeGroup);
resGroup = NULL;
break;
}
FLT_ERR_JRET(filterDetachCnfGroups(resGroup, preGroup, newGroup));
taosArrayDestroyEx(newGroup, filterFreeGroup);
@ -1707,9 +1718,10 @@ EDealRes fltTreeToGroup(SNode *pNode, void *pContext) {
cell = cell->pNext;
}
if (NULL == taosArrayAddAll(ctx->group, preGroup)) {
FLT_ERR_JRET(terrno);
if (!ctx->ignore) {
if (NULL == taosArrayAddAll(ctx->group, preGroup)) {
FLT_ERR_JRET(terrno);
}
}
taosArrayDestroy(preGroup);
@ -1721,6 +1733,9 @@ EDealRes fltTreeToGroup(SNode *pNode, void *pContext) {
SListCell *cell = node->pParameterList->pHead;
for (int32_t i = 0; i < node->pParameterList->length; ++i) {
nodesWalkExpr(cell->pNode, fltTreeToGroup, (void *)pContext);
if(ctx->ignore) {
ctx->ignore = false;
}
FLT_ERR_JRET(ctx->code);
cell = cell->pNext;
@ -1735,7 +1750,7 @@ EDealRes fltTreeToGroup(SNode *pNode, void *pContext) {
}
if (QUERY_NODE_OPERATOR == nType) {
FLT_ERR_JRET(fltAddGroupUnitFromNode(ctx->info, pNode, ctx->group));
FLT_ERR_JRET(fltAddGroupUnitFromNode(ctx, ctx->info, pNode, ctx->group));
return DEAL_RES_IGNORE_CHILD;
}
@ -2210,7 +2225,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
}
if (unit->compare.optr == OP_TYPE_IN) {
FLT_ERR_RET(scalarGenerateSetFromList((void **)&fi->data, fi->desc, type));
FLT_ERR_RET(scalarGenerateSetFromList((void **)&fi->data, fi->desc, type, 0));
if (fi->data == NULL) {
fltError("failed to convert in param");
FLT_ERR_RET(TSDB_CODE_APP_ERROR);
@ -3831,13 +3846,21 @@ int32_t fltInitFromNode(SNode *tree, SFilterInfo *info, uint32_t options) {
goto _return;
}
SFltBuildGroupCtx tctx = {.info = info, .group = group};
SFltBuildGroupCtx tctx = {.info = info, .group = group, .ignore = false};
nodesWalkExpr(tree, fltTreeToGroup, (void *)&tctx);
if (TSDB_CODE_SUCCESS != tctx.code) {
taosArrayDestroyEx(group, filterFreeGroup);
code = tctx.code;
goto _return;
}
if (tctx.ignore) {
FILTER_SET_FLAG(info->status, FI_STATUS_EMPTY);
}
if (FILTER_EMPTY_RES(info)) {
info->func = filterExecuteImplEmpty;
taosArrayDestroyEx(group, filterFreeGroup);
return TSDB_CODE_SUCCESS;
}
code = filterConvertGroupFromArray(info, group);
if (TSDB_CODE_SUCCESS != code) {
taosArrayDestroyEx(group, filterFreeGroup);
@ -3871,7 +3894,7 @@ int32_t fltInitFromNode(SNode *tree, SFilterInfo *info, uint32_t options) {
_return:
if (code) {
qInfo("init from node failed, code:%d", code);
qInfo("init from node failed, code:%d, %s", code, tstrerror(code));
}
return code;
}
@ -4561,8 +4584,7 @@ int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict) {
FLT_ERR_JRET(fltSclGetTimeStampDatum(endPt, &end));
win->skey = start.i;
win->ekey = end.i;
if(optNode->opType == OP_TYPE_IN) *isStrict = false;
else *isStrict = true;
*isStrict = info->isStrict;
goto _return;
} else if (taosArrayGetSize(points) == 0) {
*win = TSWINDOW_DESC_INITIALIZER;
@ -4740,7 +4762,7 @@ EDealRes fltReviseRewriter(SNode **pNode, void *pContext) {
return DEAL_RES_CONTINUE;
}
if (node->opType == OP_TYPE_NOT_IN || node->opType == OP_TYPE_NOT_LIKE || node->opType > OP_TYPE_IS_NOT_NULL ||
if (node->opType == OP_TYPE_NOT_LIKE || node->opType > OP_TYPE_IS_NOT_NULL ||
node->opType == OP_TYPE_NOT_EQUAL) {
stat->scalarMode = true;
return DEAL_RES_CONTINUE;
@ -4814,7 +4836,7 @@ EDealRes fltReviseRewriter(SNode **pNode, void *pContext) {
}
}
if (OP_TYPE_IN == node->opType && QUERY_NODE_NODE_LIST != nodeType(node->pRight)) {
if ((OP_TYPE_IN == node->opType || OP_TYPE_NOT_IN == node->opType) && QUERY_NODE_NODE_LIST != nodeType(node->pRight)) {
fltError("invalid IN operator node, rightType:%d", nodeType(node->pRight));
stat->code = TSDB_CODE_APP_ERROR;
return DEAL_RES_ERROR;
@ -4822,25 +4844,37 @@ EDealRes fltReviseRewriter(SNode **pNode, void *pContext) {
SColumnNode *refNode = (SColumnNode *)node->pLeft;
SExprNode *exprNode = NULL;
if (OP_TYPE_IN != node->opType) {
if (OP_TYPE_IN != node->opType && OP_TYPE_NOT_IN != node->opType) {
SValueNode *valueNode = (SValueNode *)node->pRight;
if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) &&
TSDB_DATA_TYPE_UBIGINT == valueNode->node.resType.type && valueNode->datum.u <= INT64_MAX) {
valueNode->node.resType.type = TSDB_DATA_TYPE_BIGINT;
}
exprNode = &valueNode->node;
int32_t type = vectorGetConvertType(refNode->node.resType.type, exprNode->resType.type);
if (0 != type && type != refNode->node.resType.type) {
stat->scalarMode = true;
}
} else {
SNodeListNode *listNode = (SNodeListNode *)node->pRight;
if (LIST_LENGTH(listNode->pNodeList) > 10) {
if (LIST_LENGTH(listNode->pNodeList) > 10 || OP_TYPE_NOT_IN == node->opType) {
stat->scalarMode = true;
return DEAL_RES_CONTINUE;
}
int32_t type = refNode->node.resType.type;
exprNode = &listNode->node;
}
int32_t type = vectorGetConvertType(refNode->node.resType.type, exprNode->resType.type);
if (0 != type && type != refNode->node.resType.type) {
stat->scalarMode = true;
return DEAL_RES_CONTINUE;
SNode* nodeItem = NULL;
FOREACH(nodeItem, listNode->pNodeList) {
SValueNode *valueNode = (SValueNode *)nodeItem;
int32_t tmp = vectorGetConvertType(type, valueNode->node.resType.type);
if (tmp != 0){
stat->scalarMode = true;
type = tmp;
}
}
if (IS_NUMERIC_TYPE(type)){
exprNode->resType.type = type;
}
}
}
@ -4991,11 +5025,11 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) {
}
case OP_TYPE_IN: {
SNodeListNode *listNode = (SNodeListNode *)oper->valNode;
SListCell *cell = listNode->pNodeList->pHead;
SFltSclDatum minDatum = {.kind = FLT_SCL_DATUM_KIND_INT64, .i = INT64_MAX, .type = oper->colNode->node.resType};
SFltSclDatum maxDatum = {.kind = FLT_SCL_DATUM_KIND_INT64, .i = INT64_MIN, .type = oper->colNode->node.resType};
for (int32_t i = 0; i < listNode->pNodeList->length; ++i) {
SValueNode *valueNode = (SValueNode *)cell->pNode;
SNode* nodeItem = NULL;
FOREACH(nodeItem, listNode->pNodeList) {
SValueNode *valueNode = (SValueNode *)nodeItem;
SFltSclDatum valDatum;
FLT_ERR_RET(fltSclBuildDatumFromValueNode(&valDatum, valueNode));
if(valueNode->node.resType.type == TSDB_DATA_TYPE_FLOAT || valueNode->node.resType.type == TSDB_DATA_TYPE_DOUBLE) {
@ -5005,7 +5039,6 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) {
minDatum.i = TMIN(minDatum.i, valDatum.i);
maxDatum.i = TMAX(maxDatum.i, valDatum.i);
}
cell = cell->pNext;
}
SFltSclPoint startPt = {.start = true, .excl = false, .val = minDatum};
SFltSclPoint endPt = {.start = false, .excl = false, .val = maxDatum};
@ -5026,7 +5059,8 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) {
}
// TODO: process DNF composed of CNF
int32_t fltSclProcessCNF(SArray *sclOpListCNF, SArray *colRangeList) {
static int32_t fltSclProcessCNF(SFilterInfo *pInfo, SArray *sclOpListCNF, SArray *colRangeList) {
pInfo->isStrict = true;
size_t sz = taosArrayGetSize(sclOpListCNF);
for (int32_t i = 0; i < sz; ++i) {
SFltSclOperator *sclOper = taosArrayGet(sclOpListCNF, i);
@ -5049,10 +5083,16 @@ int32_t fltSclProcessCNF(SArray *sclOpListCNF, SArray *colRangeList) {
taosArrayDestroy(colRange->points);
taosArrayDestroy(points);
colRange->points = merged;
if(merged->size == 0) {
return TSDB_CODE_SUCCESS;
}
} else {
taosArrayDestroy(colRange->points);
colRange->points = points;
}
if (sclOper->type == OP_TYPE_IN) {
pInfo->isStrict = false;
}
}
return TSDB_CODE_SUCCESS;
}
@ -5154,7 +5194,7 @@ int32_t fltOptimizeNodes(SFilterInfo *pInfo, SNode **pNode, SFltTreeStat *pStat)
if (NULL == colRangeList) {
FLT_ERR_JRET(terrno);
}
FLT_ERR_JRET(fltSclProcessCNF(sclOpList, colRangeList));
FLT_ERR_JRET(fltSclProcessCNF(pInfo, sclOpList, colRangeList));
pInfo->sclCtx.fltSclRange = colRangeList;
for (int32_t i = 0; i < taosArrayGetSize(sclOpList); ++i) {

View File

@ -116,7 +116,8 @@ _return:
SCL_RET(code);
}
int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) {
// processType = 0 means all type. 1 means number, 2 means var, 3 means float, 4 means var&integer
int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type, int8_t processType) {
SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(type), true, false);
if (NULL == pObj) {
sclError("taosHashInit failed, size:%d", 256);
@ -127,7 +128,6 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) {
int32_t code = 0;
SNodeListNode *nodeList = (SNodeListNode *)pNode;
SListCell *cell = nodeList->pNodeList->pHead;
SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))};
if (out.columnData == NULL) {
SCL_ERR_JRET(terrno);
@ -135,8 +135,14 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) {
int32_t len = 0;
void *buf = NULL;
for (int32_t i = 0; i < nodeList->pNodeList->length; ++i) {
SValueNode *valueNode = (SValueNode *)cell->pNode;
SNode* nodeItem = NULL;
FOREACH(nodeItem, nodeList->pNodeList) {
SValueNode *valueNode = (SValueNode *)nodeItem;
if ((IS_VAR_DATA_TYPE(valueNode->node.resType.type) && (processType == 1 || processType == 3)) ||
(IS_INTEGER_TYPE(valueNode->node.resType.type) && (processType == 2 || processType == 3)) ||
(IS_FLOAT_TYPE(valueNode->node.resType.type) && (processType == 2 || processType == 4))) {
continue;
}
if (valueNode->node.resType.type != type) {
out.columnData->info.type = type;
@ -158,7 +164,6 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) {
}
if (overflow) {
cell = cell->pNext;
continue;
}
@ -184,7 +189,6 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) {
}
colInfoDataCleanup(out.columnData, out.numOfRows);
cell = cell->pNext;
}
*data = pObj;
@ -230,6 +234,11 @@ void sclFreeParam(SScalarParam *param) {
taosHashCleanup(param->pHashFilter);
param->pHashFilter = NULL;
}
if (param->pHashFilterOthers != NULL) {
taosHashCleanup(param->pHashFilterOthers);
param->pHashFilterOthers = NULL;
}
}
int32_t sclCopyValueNodeValue(SValueNode *pNode, void **res) {
@ -369,17 +378,37 @@ int32_t sclInitParam(SNode *node, SScalarParam *param, SScalarCtx *ctx, int32_t
SCL_RET(TSDB_CODE_QRY_INVALID_INPUT);
}
int32_t type = vectorGetConvertType(ctx->type.selfType, ctx->type.peerType);
if (type == 0) {
type = nodeList->node.resType.type;
int32_t type = ctx->type.selfType;
SNode* nodeItem = NULL;
FOREACH(nodeItem, nodeList->pNodeList) {
SValueNode *valueNode = (SValueNode *)nodeItem;
int32_t tmp = vectorGetConvertType(type, valueNode->node.resType.type);
if (tmp != 0){
type = tmp;
}
}
if (IS_NUMERIC_TYPE(type)){
ctx->type.peerType = type;
}
type = ctx->type.peerType;
if (IS_VAR_DATA_TYPE(ctx->type.selfType) && IS_NUMERIC_TYPE(type)){
SCL_ERR_RET(scalarGenerateSetFromList((void **)&param->pHashFilter, node, type, 1));
SCL_ERR_RET(scalarGenerateSetFromList((void **)&param->pHashFilterOthers, node, ctx->type.selfType, 2));
} else if (IS_INTEGER_TYPE(ctx->type.selfType) && IS_FLOAT_TYPE(type)){
SCL_ERR_RET(scalarGenerateSetFromList((void **)&param->pHashFilter, node, type, 3));
SCL_ERR_RET(scalarGenerateSetFromList((void **)&param->pHashFilterOthers, node, ctx->type.selfType, 4));
} else {
SCL_ERR_RET(scalarGenerateSetFromList((void **)&param->pHashFilter, node, type, 0));
}
SCL_ERR_RET(scalarGenerateSetFromList((void **)&param->pHashFilter, node, type));
param->hashValueType = type;
param->colAlloced = true;
if (taosHashPut(ctx->pRes, &node, POINTER_BYTES, param, sizeof(*param))) {
taosHashCleanup(param->pHashFilter);
param->pHashFilter = NULL;
taosHashCleanup(param->pHashFilterOthers);
param->pHashFilterOthers = NULL;
sclError("taosHashPut nodeList failed, size:%d", (int32_t)sizeof(*param));
return terrno;
}
@ -512,14 +541,15 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList *pParamList, SScalarC
}
if (0 == *rowNum) {
taosMemoryFreeClear(paramList);
sclFreeParamList(paramList, *paramNum);
paramList = NULL;
}
*pParams = paramList;
return TSDB_CODE_SUCCESS;
_return:
taosMemoryFreeClear(paramList);
sclFreeParamList(paramList, *paramNum);
SCL_RET(code);
}
@ -588,7 +618,6 @@ int32_t sclInitOperatorParams(SScalarParam **pParams, SOperatorNode *node, SScal
SCL_ERR_JRET(sclInitParam(node->pLeft, &paramList[0], ctx, rowNum));
setTzCharset(&paramList[0], node->tz, node->charsetCxt);
if (paramNum > 1) {
TSWAP(ctx->type.selfType, ctx->type.peerType);
SCL_ERR_JRET(sclInitParam(node->pRight, &paramList[1], ctx, rowNum));
setTzCharset(&paramList[1], node->tz, node->charsetCxt);
}
@ -1695,15 +1724,12 @@ static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) {
if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) ||
TSDB_DATA_TYPE_VARBINARY == ldt.type || TSDB_DATA_TYPE_VARBINARY == rdt.type ||
(TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type) || IS_FLOAT_TYPE(rdt.type))) ||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) {
(TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type))) ||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type)))) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && IS_INTEGER_TYPE(rdt.type)) ||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && IS_INTEGER_TYPE(ldt.type)) ||
(TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_BOOL == rdt.type) ||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && TSDB_DATA_TYPE_BOOL == ldt.type)) {
if (checkOperatorRestypeIsTimestamp(pOp->opType, ldt.type, rdt.type)) {
pOp->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
} else {

View File

@ -24,6 +24,7 @@
#include "tcompare.h"
#include "tdatablock.h"
#include "tdataformat.h"
#include "tdef.h"
#include "ttime.h"
#include "ttypes.h"
#include "geosWrapper.h"
@ -1008,28 +1009,29 @@ int32_t vectorConvertSingleColImpl(const SScalarParam *pIn, SScalarParam *pOut,
}
int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
/* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
/*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*BOOL*/ 0, 0, 2, 3, 4, 5, 6, 7, 5, 9, 7, 11, 12, 13, 14, 0, -1, 0, 0, 0, -1,
/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 5, 9, 7, 3, 4, 5, 7, 0, -1, 0, 0, 0, -1,
/*SMAL*/ 0, 0, 0, 0, 4, 5, 6, 7, 5, 9, 7, 3, 4, 5, 7, 0, -1, 0, 0, 0, -1,
/*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 5, 9, 7, 4, 4, 5, 7, 0, -1, 0, 0, 0, -1,
/*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 5, 9, 7, 5, 5, 5, 7, 0, -1, 0, 0, 0, -1,
/*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 0, -1, 0, 0, 0, -1,
/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 0, -1, 0, 0, 0, -1,
/*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 7, 7, 7, 0, 16, 0, 0, 0, 20,
/*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 7, 0, -1, 0, 0, 0, -1,
/*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 16, 0, 0, 0, -1,
/*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 0, -1, 0, 0, 0, -1,
/*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 0, -1, 0, 0, 0, -1,
/*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, -1, 0, 0, 0, -1,
/*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1,
/*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1,
/*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1,-1, -1,
/*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1,
/*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1,
/*MEDB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1,
/*GEOM*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0};
/*NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
/*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*BOOL*/ 0, 0, 2, 3, 4, 5, 6, 7, 5, 9, 5, 11, 12, 13, 14, 0, -1, 0, 0, 0, -1,
/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 5, 9, 5, 3, 4, 5, 7, 0, -1, 0, 0, 0, -1,
/*SMAL*/ 0, 0, 0, 0, 4, 5, 6, 7, 5, 9, 5, 3, 4, 5, 7, 0, -1, 0, 0, 0, -1,
/*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 5, 9, 5, 4, 4, 5, 7, 0, -1, 0, 0, 0, -1,
/*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 5, 9, 5, 5, 5, 5, 7, 0, -1, 0, 0, 0, -1,
/*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 6, 6, 6, 6, 6, 6, 6, 0, -1, 0, 0, 0, -1,
/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 0, -1, 0, 0, 0, -1,
/*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 7, 7, 7, 0, 16, 0, 0, 0, 20,
/*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 7, 0, -1, 0, 0, 0, -1,
/*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 16, 0, 0, 0, -1,
/*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 0, -1, 0, 0, 0, -1,
/*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 0, -1, 0, 0, 0, -1,
/*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, -1, 0, 0, 0, -1,
/*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1,
/*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1,
/*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1,
/*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1,
/*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1,
/*MEDB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1,
/*GEOM*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0
};
int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
/*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIM NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
@ -1070,6 +1072,9 @@ int32_t vectorGetConvertType(int32_t type1, int32_t type2) {
int32_t vectorConvertSingleCol(SScalarParam *input, SScalarParam *output, int32_t type, int32_t startIndex,
int32_t numOfRows) {
if (input->columnData == NULL && (input->pHashFilter != NULL || input->pHashFilterOthers != NULL)){
return TSDB_CODE_SUCCESS;
}
output->numOfRows = input->numOfRows;
SDataType t = {.type = type};
@ -1100,36 +1105,18 @@ int32_t vectorConvertCols(SScalarParam *pLeft, SScalarParam *pRight, SScalarPara
int8_t type = 0;
int32_t code = 0;
SScalarParam *param1 = NULL, *paramOut1 = NULL;
SScalarParam *param2 = NULL, *paramOut2 = NULL;
SScalarParam *param1 = pLeft, *paramOut1 = pLeftOut;
SScalarParam *param2 = pRight, *paramOut2 = pRightOut;
// always convert least data
if (IS_VAR_DATA_TYPE(leftType) && IS_VAR_DATA_TYPE(rightType) && (pLeft->numOfRows != pRight->numOfRows) &&
leftType != TSDB_DATA_TYPE_JSON && rightType != TSDB_DATA_TYPE_JSON) {
param1 = pLeft;
param2 = pRight;
paramOut1 = pLeftOut;
paramOut2 = pRightOut;
if (pLeft->numOfRows > pRight->numOfRows) {
type = leftType;
} else {
type = rightType;
}
} else {
// we only define half value in the convert-matrix, so make sure param1 always less equal than param2
if (leftType < rightType) {
param1 = pLeft;
param2 = pRight;
paramOut1 = pLeftOut;
paramOut2 = pRightOut;
} else {
param1 = pRight;
param2 = pLeft;
paramOut1 = pRightOut;
paramOut2 = pLeftOut;
}
type = vectorGetConvertType(GET_PARAM_TYPE(param1), GET_PARAM_TYPE(param2));
if (0 == type) {
return TSDB_CODE_SUCCESS;
@ -1262,12 +1249,7 @@ int32_t vectorMathAdd(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *p
SColumnInfoData *pRightCol = NULL;
SCL_ERR_JRET(vectorConvertVarToDouble(pLeft, &leftConvert, &pLeftCol));
SCL_ERR_JRET(vectorConvertVarToDouble(pRight, &rightConvert, &pRightCol));
if ((GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && IS_INTEGER_TYPE(GET_PARAM_TYPE(pRight))) ||
(GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && IS_INTEGER_TYPE(GET_PARAM_TYPE(pLeft))) ||
(GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_BOOL) ||
(GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP &&
GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BOOL)) { // timestamp plus duration
if(checkOperatorRestypeIsTimestamp(OP_TYPE_ADD, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight))) { // timestamp plus duration
int64_t *output = (int64_t *)pOutputCol->pData;
_getBigintValue_fn_t getVectorBigintValueFnLeft;
_getBigintValue_fn_t getVectorBigintValueFnRight;
@ -1399,9 +1381,7 @@ int32_t vectorMathSub(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *p
SCL_ERR_JRET(vectorConvertVarToDouble(pLeft, &leftConvert, &pLeftCol));
SCL_ERR_JRET(vectorConvertVarToDouble(pRight, &rightConvert, &pRightCol));
if ((GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_BIGINT) ||
(GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP &&
GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BIGINT)) { // timestamp minus duration
if (checkOperatorRestypeIsTimestamp(OP_TYPE_SUB, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight))) { // timestamp minus duration
int64_t *output = (int64_t *)pOutputCol->pData;
_getBigintValue_fn_t getVectorBigintValueFnLeft;
_getBigintValue_fn_t getVectorBigintValueFnRight;
@ -1992,13 +1972,14 @@ int32_t doVectorCompareImpl(SScalarParam *pLeft, SScalarParam *pRight, SScalarPa
return code;
}
int32_t doVectorCompare(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam *pOut, int32_t startIndex,
int32_t doVectorCompare(SScalarParam *pLeft, SScalarParam *pLeftVar, SScalarParam *pRight, SScalarParam *pOut, int32_t startIndex,
int32_t numOfRows, int32_t _ord, int32_t optr) {
int32_t i = 0;
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
int32_t lType = GET_PARAM_TYPE(pLeft);
int32_t rType = GET_PARAM_TYPE(pRight);
__compar_fn_t fp = NULL;
__compar_fn_t fpVar = NULL;
int32_t compRows = 0;
if (lType == rType) {
SCL_ERR_RET(filterGetCompFunc(&fp, lType, optr));
@ -2006,6 +1987,9 @@ int32_t doVectorCompare(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam
fp = filterGetCompFuncEx(lType, rType, optr);
}
if (pLeftVar != NULL) {
SCL_ERR_RET(filterGetCompFunc(&fpVar, GET_PARAM_TYPE(pLeftVar), optr));
}
if (startIndex < 0) {
i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
@ -2025,6 +2009,18 @@ int32_t doVectorCompare(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam
char *pLeftData = colDataGetData(pLeft->columnData, i);
bool res = filterDoCompare(fp, optr, pLeftData, pRight->pHashFilter);
if (pLeftVar != NULL && taosHashGetSize(pRight->pHashFilterOthers) > 0){
do{
if (optr == OP_TYPE_IN && res){
break;
}
if (optr == OP_TYPE_NOT_IN && !res){
break;
}
pLeftData = colDataGetData(pLeftVar->columnData, i);
res = filterDoCompare(fpVar, optr, pLeftData, pRight->pHashFilterOthers);
}while(0);
}
colDataSetInt8(pOut->columnData, i, (int8_t *)&res);
if (res) {
pOut->numOfQualified++;
@ -2042,6 +2038,7 @@ int32_t vectorCompareImpl(SScalarParam *pLeft, SScalarParam *pRight, SScalarPara
SScalarParam pRightOut = {0};
SScalarParam *param1 = NULL;
SScalarParam *param2 = NULL;
SScalarParam *param3 = NULL;
int32_t code = TSDB_CODE_SUCCESS;
setTzCharset(&pLeftOut, pLeft->tz, pLeft->charsetCxt);
setTzCharset(&pRightOut, pLeft->tz, pLeft->charsetCxt);
@ -2052,9 +2049,12 @@ int32_t vectorCompareImpl(SScalarParam *pLeft, SScalarParam *pRight, SScalarPara
SCL_ERR_JRET(vectorConvertCols(pLeft, pRight, &pLeftOut, &pRightOut, startIndex, numOfRows));
param1 = (pLeftOut.columnData != NULL) ? &pLeftOut : pLeft;
param2 = (pRightOut.columnData != NULL) ? &pRightOut : pRight;
if (pRight->pHashFilterOthers != NULL){
param3 = pLeft;
}
}
SCL_ERR_JRET(doVectorCompare(param1, param2, pOut, startIndex, numOfRows, _ord, optr));
SCL_ERR_JRET(doVectorCompare(param1, param3, param2, pOut, startIndex, numOfRows, _ord, optr));
_return:
sclFreeParam(&pLeftOut);
@ -2306,3 +2306,16 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
return NULL;
}
}
bool checkOperatorRestypeIsTimestamp(EOperatorType opType, int32_t lType, int32_t rType) {
if (opType != OP_TYPE_ADD && opType != OP_TYPE_SUB && opType != OP_TYPE_MINUS) {
return false;
}
if ((TSDB_DATA_TYPE_TIMESTAMP == lType && IS_INTEGER_TYPE(rType) && rType != TSDB_DATA_TYPE_UBIGINT) ||
(TSDB_DATA_TYPE_TIMESTAMP == rType && IS_INTEGER_TYPE(lType) && lType != TSDB_DATA_TYPE_UBIGINT) ||
(TSDB_DATA_TYPE_TIMESTAMP == lType && TSDB_DATA_TYPE_BOOL == rType) ||
(TSDB_DATA_TYPE_TIMESTAMP == rType && TSDB_DATA_TYPE_BOOL == lType)) {
return true;
}
return false;
}

View File

@ -2106,7 +2106,7 @@ 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};
bool eRes[5] = {false, false, false, false, false};
SSDataBlock *src = NULL;
int32_t rowNum = sizeof(leftv) / sizeof(leftv[0]);
int32_t code = TSDB_CODE_SUCCESS;

View File

@ -1361,14 +1361,14 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
taosMemoryFree(msg);
SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask));
} else {
if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY) {
SCH_ERR_JRET(schAppendTaskExecNode(pJob, pTask, addr, pTask->execId));
}
SSchTrans trans = {.pTrans = pJob->conn.pTrans, .pHandle = SCH_GET_TASK_HANDLE(pTask)};
code = schAsyncSendMsg(pJob, pTask, &trans, addr, msgType, msg, (uint32_t)msgSize, persistHandle, (rpcCtx.args ? &rpcCtx : NULL));
msg = NULL;
SCH_ERR_JRET(code);
if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY) {
SCH_ERR_RET(schAppendTaskExecNode(pJob, pTask, addr, pTask->execId));
}
}
return TSDB_CODE_SUCCESS;

View File

@ -200,6 +200,7 @@ void streamTaskInitForLaunchHTask(SHistoryTaskInfo* pInfo);
void streamTaskSetRetryInfoForLaunch(SHistoryTaskInfo* pInfo);
int32_t streamTaskResetTimewindowFilter(SStreamTask* pTask);
void streamTaskClearActiveInfo(SActiveCheckpointInfo* pInfo);
int32_t streamTaskAddIntoNodeUpdateList(SStreamTask* pTask, int32_t nodeId);
void streamClearChkptReadyMsg(SActiveCheckpointInfo* pActiveInfo);
EExtractDataCode streamTaskGetDataFromInputQ(SStreamTask* pTask, SStreamQueueItem** pInput, int32_t* numOfBlocks,
@ -243,6 +244,8 @@ int32_t flushStateDataInExecutor(SStreamTask* pTask, SStreamQueueItem* pCheckpoi
int32_t streamCreateSinkResTrigger(SStreamTrigger** pTrigger);
int32_t streamCreateForcewindowTrigger(SStreamTrigger** pTrigger, int32_t trigger, SInterval* pInterval,
STimeWindow* pLatestWindow, const char* id);
// inject stream errors
void chkptFailedByRetrieveReqToSource(SStreamTask* pTask, int64_t checkpointId);
// inject stream errors
void chkptFailedByRetrieveReqToSource(SStreamTask* pTask, int64_t checkpointId);

View File

@ -21,7 +21,6 @@
#define CHECK_NOT_RSP_DURATION 10 * 1000 // 10 sec
static void processDownstreamReadyRsp(SStreamTask* pTask);
static int32_t addIntoNodeUpdateList(SStreamTask* pTask, int32_t nodeId);
static void rspMonitorFn(void* param, void* tmrId);
static void streamTaskInitTaskCheckInfo(STaskCheckInfo* pInfo, STaskOutputInfo* pOutputInfo, int64_t startTs);
static int32_t streamTaskStartCheckDownstream(STaskCheckInfo* pInfo, const char* id);
@ -226,13 +225,13 @@ int32_t streamTaskProcessCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp*
stError("s-task:%s vgId:%d self vnode-transfer/leader-change/restart detected, old stage:%" PRId64
", current stage:%" PRId64 ", not check wait for downstream task nodeUpdate, and all tasks restart",
id, pRsp->upstreamNodeId, pRsp->oldStage, pTask->pMeta->stage);
code = addIntoNodeUpdateList(pTask, pRsp->upstreamNodeId);
code = streamTaskAddIntoNodeUpdateList(pTask, pRsp->upstreamNodeId);
} else {
stError(
"s-task:%s downstream taskId:0x%x (vgId:%d) not leader, self dispatch epset needs to be updated, not check "
"downstream again, nodeUpdate needed",
id, pRsp->downstreamTaskId, pRsp->downstreamNodeId);
code = addIntoNodeUpdateList(pTask, pRsp->downstreamNodeId);
code = streamTaskAddIntoNodeUpdateList(pTask, pRsp->downstreamNodeId);
}
streamMetaAddFailedTaskSelf(pTask, now);
@ -373,11 +372,10 @@ void processDownstreamReadyRsp(SStreamTask* pTask) {
}
}
int32_t addIntoNodeUpdateList(SStreamTask* pTask, int32_t nodeId) {
int32_t streamTaskAddIntoNodeUpdateList(SStreamTask* pTask, int32_t nodeId) {
int32_t vgId = pTask->pMeta->vgId;
int32_t code = 0;
;
bool existed = false;
bool existed = false;
streamMutexLock(&pTask->lock);
@ -675,8 +673,8 @@ void handleTimeoutDownstreamTasks(SStreamTask* pTask, SArray* pTimeoutList) {
SDownstreamStatusInfo* p = NULL;
findCheckRspStatus(pInfo, *pTaskId, &p);
if (p != NULL) {
code = addIntoNodeUpdateList(pTask, p->vgId);
stDebug("s-task:%s vgId:%d downstream task:0x%x (vgId:%d) timeout more than 100sec, add into nodeUpate list",
code = streamTaskAddIntoNodeUpdateList(pTask, p->vgId);
stDebug("s-task:%s vgId:%d downstream task:0x%x (vgId:%d) timeout more than 100sec, add into nodeUpdate list",
id, vgId, p->taskId, p->vgId);
}
}
@ -717,7 +715,7 @@ void handleNotReadyDownstreamTask(SStreamTask* pTask, SArray* pNotReadyList) {
// the action of add status may incur the restart procedure, which should NEVER be executed in the timer thread.
// The restart of all tasks requires that all tasks should not have active timer for now. Therefore, the execution
// of restart in timer thread will result in a dead lock.
// of restart in timer thread will result in a deadlock.
int32_t addDownstreamFailedStatusResultAsync(SMsgCb* pMsgCb, int32_t vgId, int64_t streamId, int32_t taskId) {
return streamTaskSchedTask(pMsgCb, vgId, streamId, taskId, STREAM_EXEC_T_ADD_FAILED_TASK);
}

View File

@ -1552,7 +1552,6 @@ static bool setDispatchRspInfo(SDispatchMsgInfo* pMsgInfo, int32_t vgId, int32_t
int32_t* pFailed, const char* id) {
int32_t numOfRsp = 0;
int32_t numOfFailed = 0;
bool allRsp = false;
int32_t numOfDispatchBranch = taosArrayGetSize(pMsgInfo->pSendInfo);
@ -1639,6 +1638,7 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i
int32_t notRsp = 0;
int32_t numOfFailed = 0;
bool triggerDispatchRsp = false;
bool addFailure = false;
SActiveCheckpointInfo* pInfo = pTask->chkInfo.pActiveInfo;
int64_t tmpCheckpointId = -1;
int32_t tmpTranId = -1;
@ -1698,6 +1698,7 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i
} else {
if (pRsp->inputStatus == TASK_INPUT_STATUS__REFUSED) {
// todo handle the role-changed during checkpoint generation, add test case
addFailure = true;
stError(
"s-task:%s downstream task:0x%x(vgId:%d) refused the dispatch msg, downstream may become follower or "
"restart already, treat it as success",
@ -1745,6 +1746,11 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i
msgId, pRsp->downstreamTaskId, pRsp->downstreamNodeId, pRsp->inputStatus, tstrerror(code));
}
if (addFailure) { // add failure downstream node id, and start the nodeEp update procedure
// ignore the return error and continue
int32_t unused = streamTaskAddIntoNodeUpdateList(pTask, pRsp->downstreamNodeId);
}
// all msg rsp already, continue
// we need to re-try send dispatch msg to downstream tasks
if (allRsp && (numOfFailed == 0)) {
@ -1866,6 +1872,11 @@ int32_t streamProcessDispatchMsg(SStreamTask* pTask, SStreamDispatchReq* pReq, S
}
}
#if 0
// inject errors, and always refuse the upstream dispatch msg and trigger the task nodeEpset update trans.
status = TASK_INPUT_STATUS__REFUSED;
#endif
{
// do send response with the input status
int32_t code = buildDispatchRsp(pTask, pReq, status, &pRsp->pCont);

View File

@ -355,7 +355,7 @@ void atomic_store_double(double volatile* ptr, double val) {
double_number ret_num = {0};
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
if (ret_num.i == old_num.i) return;
if (ret_num.i == old_num.i) break;
}
}
@ -414,6 +414,8 @@ int64_t atomic_exchange_64(int64_t volatile* ptr, int64_t val) {
}
double atomic_exchange_double(double volatile* ptr, double val) {
double ret = 0;
for (;;) {
double_number old_num = {0};
old_num.d = *ptr; // current old value
@ -425,9 +427,11 @@ double atomic_exchange_double(double volatile* ptr, double val) {
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
if (ret_num.i == old_num.i) {
return ret_num.d;
ret = ret_num.d;
break;
}
}
return ret;
}
void* atomic_exchange_ptr(void* ptr, void* val) {
@ -589,6 +593,8 @@ int64_t atomic_fetch_add_64(int64_t volatile* ptr, int64_t val) {
}
double atomic_fetch_add_double(double volatile* ptr, double val) {
double ret = 0;
for (;;) {
double_number old_num = {0};
old_num.d = *ptr; // current old value
@ -599,8 +605,13 @@ double atomic_fetch_add_double(double volatile* ptr, double val) {
double_number ret_num = {0};
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
if (ret_num.i == old_num.i) return ret_num.d;
if (ret_num.i == old_num.i) {
ret = ret_num.d;
break;
}
}
return ret;
}
void* atomic_fetch_add_ptr(void* ptr, int64_t val) {
@ -710,6 +721,8 @@ int64_t atomic_fetch_sub_64(int64_t volatile* ptr, int64_t val) {
}
double atomic_fetch_sub_double(double volatile* ptr, double val) {
double ret = 0;
for (;;) {
double_number old_num = {0};
old_num.d = *ptr; // current old value
@ -720,8 +733,13 @@ double atomic_fetch_sub_double(double volatile* ptr, double val) {
double_number ret_num = {0};
ret_num.i = atomic_val_compare_exchange_64((volatile int64_t*)ptr, old_num.i, new_num.i);
if (ret_num.i == old_num.i) return ret_num.d;
if (ret_num.i == old_num.i) {
ret = ret_num.d;
break;
}
}
return ret;
}
void* atomic_fetch_sub_ptr(void* ptr, int64_t val) {

View File

@ -23,18 +23,16 @@ int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void *(*start)
int32_t code = pthread_create(tid, attr, start, arg);
if (code) {
taosThreadClear(tid);
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) {
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_destroy(attr);
int32_t code = pthread_attr_destroy(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -44,8 +42,7 @@ int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *detachst
OS_PARAM_CHECK(detachstate);
int32_t code = pthread_attr_getdetachstate(attr, detachstate);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -55,8 +52,7 @@ int32_t taosThreadAttrGetInheritSched(const TdThreadAttr *attr, int32_t *inherit
OS_PARAM_CHECK(inheritsched);
int32_t code = pthread_attr_getinheritsched(attr, inheritsched);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -66,8 +62,7 @@ int32_t taosThreadAttrGetSchedParam(const TdThreadAttr *attr, struct sched_param
OS_PARAM_CHECK(param);
int32_t code = pthread_attr_getschedparam(attr, param);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -77,8 +72,7 @@ int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr *attr, int32_t *policy)
OS_PARAM_CHECK(policy);
int32_t code = pthread_attr_getschedpolicy(attr, policy);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -88,8 +82,7 @@ int32_t taosThreadAttrGetScope(const TdThreadAttr *attr, int32_t *contentionscop
OS_PARAM_CHECK(contentionscope);
int32_t code = pthread_attr_getscope(attr, contentionscope);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -99,18 +92,16 @@ int32_t taosThreadAttrGetStackSize(const TdThreadAttr *attr, size_t *stacksize)
OS_PARAM_CHECK(stacksize);
int32_t code = pthread_attr_getstacksize(attr, stacksize);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
int32_t taosThreadAttrInit(TdThreadAttr *attr) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_init(attr);
int32_t code = pthread_attr_init(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -119,8 +110,7 @@ int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachstate) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setdetachstate(attr, detachstate);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -129,8 +119,7 @@ int32_t taosThreadAttrSetInheritSched(TdThreadAttr *attr, int32_t inheritsched)
OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setinheritsched(attr, inheritsched);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -139,8 +128,7 @@ int32_t taosThreadAttrSetSchedParam(TdThreadAttr *attr, const struct sched_param
OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setschedparam(attr, param);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -149,8 +137,7 @@ int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr *attr, int32_t policy) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setschedpolicy(attr, policy);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -159,8 +146,7 @@ int32_t taosThreadAttrSetScope(TdThreadAttr *attr, int32_t contentionscope) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setscope(attr, contentionscope);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -169,17 +155,15 @@ int32_t taosThreadAttrSetStackSize(TdThreadAttr *attr, size_t stacksize) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_attr_setstacksize(attr, stacksize);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
int32_t taosThreadCancel(TdThread thread) {
int32_t code = pthread_cancel(thread);
int32_t taosThreadCancel(TdThread thread) {
int32_t code = pthread_cancel(thread);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -191,8 +175,7 @@ int32_t taosThreadCondDestroy(TdThreadCond *cond) {
#else
int32_t code = pthread_cond_destroy(cond);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -206,8 +189,7 @@ int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) {
#else
int32_t code = pthread_cond_init(cond, attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -221,8 +203,7 @@ int32_t taosThreadCondSignal(TdThreadCond *cond) {
#else
int32_t code = pthread_cond_signal(cond);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -236,8 +217,7 @@ int32_t taosThreadCondBroadcast(TdThreadCond *cond) {
#else
int32_t code = pthread_cond_broadcast(cond);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -254,8 +234,7 @@ int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) {
#else
int32_t code = pthread_cond_wait(cond, mutex);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -274,7 +253,7 @@ int32_t taosThreadCondTimedWait(TdThreadCond *cond, TdThreadMutex *mutex, const
return TAOS_SYSTEM_WINAPI_ERROR(error);
#else
int32_t code = pthread_cond_timedwait(cond, mutex, abstime);
if(code == ETIMEDOUT) {
if (code == ETIMEDOUT) {
return TSDB_CODE_TIMEOUT_ERROR;
} else if (code) {
return TAOS_SYSTEM_ERROR(code);
@ -291,14 +270,14 @@ int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_condattr_destroy(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
}
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *pshared) {
OS_PARAM_CHECK(attr);
OS_PARAM_CHECK(pshared);
#ifdef __USE_WIN_THREAD
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
@ -307,8 +286,7 @@ int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *psha
OS_PARAM_CHECK(attr);
int32_t code = pthread_condattr_getpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -321,8 +299,7 @@ int32_t taosThreadCondAttrInit(TdThreadCondAttr *attr) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_condattr_init(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -337,8 +314,7 @@ int32_t taosThreadCondAttrSetclock(TdThreadCondAttr *attr, int clockId) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_condattr_setclock(attr, clockId);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -351,28 +327,24 @@ int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr *attr, int32_t pshared) {
#else
int32_t code = pthread_condattr_setpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
}
int32_t taosThreadDetach(TdThread thread) {
int32_t code = pthread_detach(thread);
int32_t taosThreadDetach(TdThread thread) {
int32_t code = pthread_detach(thread);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
int32_t taosThreadEqual(TdThread t1, TdThread t2) {
return pthread_equal(t1, t2);
}
int32_t taosThreadEqual(TdThread t1, TdThread t2) { return pthread_equal(t1, t2); }
void taosThreadExit(void *valuePtr) {
if(valuePtr) return pthread_exit(valuePtr);
void taosThreadExit(void *valuePtr) {
if (valuePtr) return pthread_exit(valuePtr);
}
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) {
@ -380,21 +352,17 @@ int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_p
OS_PARAM_CHECK(param);
int32_t code = pthread_getschedparam(thread, policy, param);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
void *taosThreadGetSpecific(TdThreadKey key) {
return pthread_getspecific(key);
}
void *taosThreadGetSpecific(TdThreadKey key) { return pthread_getspecific(key); }
int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
int32_t code = pthread_join(thread, valuePtr);
int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
int32_t code = pthread_join(thread, valuePtr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -403,26 +371,23 @@ int32_t taosThreadKeyCreate(TdThreadKey *key, void (*destructor)(void *)) {
OS_PARAM_CHECK(key);
int32_t code = pthread_key_create(key, destructor);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
int32_t taosThreadKeyDelete(TdThreadKey key) {
int32_t code = pthread_key_delete(key);
int32_t taosThreadKeyDelete(TdThreadKey key) {
int32_t code = pthread_key_delete(key);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
int32_t taosThreadKill(TdThread thread, int32_t sig) {
int32_t code = pthread_kill(thread, sig);
int32_t taosThreadKill(TdThread thread, int32_t sig) {
int32_t code = pthread_kill(thread, sig);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -439,8 +404,7 @@ int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) {
#else
int32_t code = pthread_mutex_destroy(mutex);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -459,8 +423,7 @@ int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr)
#else
int32_t code = pthread_mutex_init(mutex, attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -474,8 +437,7 @@ int32_t taosThreadMutexLock(TdThreadMutex *mutex) {
#else
int32_t code = pthread_mutex_lock(mutex);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -507,8 +469,7 @@ int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) {
#else
int32_t code = pthread_mutex_unlock(mutex);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -521,8 +482,7 @@ int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_destroy(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -537,8 +497,7 @@ int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *ps
OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_getpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -557,8 +516,7 @@ int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr *attr, int32_t *kind)
OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_gettype(attr, kind);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -571,8 +529,7 @@ int32_t taosThreadMutexAttrInit(TdThreadMutexAttr *attr) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_init(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -585,8 +542,7 @@ int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr *attr, int32_t pshared)
OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_setpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -603,8 +559,7 @@ int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr *attr, int32_t kind) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_mutexattr_settype(attr, kind);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -613,8 +568,7 @@ int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr *attr, int32_t kind) {
int32_t taosThreadOnce(TdThreadOnce *onceControl, void (*initRoutine)(void)) {
int32_t code = pthread_once(onceControl, initRoutine);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -626,11 +580,10 @@ int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) {
*/
return 0;
#else
OS_PARAM_CHECK(rwlock);
OS_PARAM_CHECK(rwlock);
int32_t code = pthread_rwlock_destroy(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -645,8 +598,7 @@ int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *a
#else
int32_t code = pthread_rwlock_init(rwlock, attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -660,8 +612,7 @@ int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) {
#else
int32_t code = pthread_rwlock_rdlock(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -683,8 +634,7 @@ int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) {
#else
int32_t code = pthread_rwlock_tryrdlock(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -699,8 +649,7 @@ int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) {
#else
int32_t code = pthread_rwlock_trywrlock(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -718,8 +667,7 @@ int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) {
#else
int32_t code = pthread_rwlock_unlock(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -734,8 +682,7 @@ int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) {
#else
int32_t code = pthread_rwlock_wrlock(rwlock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -748,14 +695,14 @@ int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_rwlockattr_destroy(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
}
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *pshared) {
OS_PARAM_CHECK(attr);
OS_PARAM_CHECK(pshared);
#ifdef __USE_WIN_THREAD
if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE;
@ -763,8 +710,7 @@ int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *
#else
int32_t code = pthread_rwlockattr_getpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -777,8 +723,7 @@ int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr *attr) {
OS_PARAM_CHECK(attr);
int32_t code = pthread_rwlockattr_init(attr);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -791,8 +736,7 @@ int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared
OS_PARAM_CHECK(attr);
int32_t code = pthread_rwlockattr_setpshared(attr, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -800,20 +744,18 @@ int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared
TdThread taosThreadSelf(void) { return pthread_self(); }
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
int32_t code = pthread_setcancelstate(state, oldstate);
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
int32_t code = pthread_setcancelstate(state, oldstate);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
int32_t code = pthread_setcanceltype(type, oldtype);
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
int32_t code = pthread_setcanceltype(type, oldtype);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -822,18 +764,16 @@ int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sc
OS_PARAM_CHECK(param);
int32_t code = pthread_setschedparam(thread, policy, param);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
OS_PARAM_CHECK(value);
int32_t code = pthread_setspecific(key, value);
int32_t code = pthread_setspecific(key, value);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
}
@ -845,8 +785,7 @@ int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) {
#else
int32_t code = pthread_spin_destroy((pthread_spinlock_t *)lock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -860,8 +799,7 @@ int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int32_t pshared) {
#else
int32_t code = pthread_spin_init((pthread_spinlock_t *)lock, pshared);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -874,8 +812,7 @@ int32_t taosThreadSpinLock(TdThreadSpinlock *lock) {
#else
int32_t code = pthread_spin_lock((pthread_spinlock_t *)lock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
@ -901,20 +838,17 @@ int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) {
#else
int32_t code = pthread_spin_unlock((pthread_spinlock_t *)lock);
if (code) {
terrno = TAOS_SYSTEM_ERROR(code);
return terrno;
return (terrno = TAOS_SYSTEM_ERROR(code));
}
return code;
#endif
}
void taosThreadTestCancel(void) {
return pthread_testcancel();
}
void taosThreadTestCancel(void) { return pthread_testcancel(); }
void taosThreadClear(TdThread *thread) {
void taosThreadClear(TdThread *thread) {
if (!thread) return;
(void)memset(thread, 0, sizeof(TdThread));
(void)memset(thread, 0, sizeof(TdThread));
}
#ifdef WINDOWS

View File

@ -31,7 +31,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
//#define TM_YEAR_BASE 1970 //origin
// #define TM_YEAR_BASE 1970 //origin
#define TM_YEAR_BASE 1900 // slguan
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
@ -345,8 +345,7 @@ char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
#endif
}
size_t
taosStrfTime(char *s, size_t maxsize, char const *format, struct tm const *t){
size_t taosStrfTime(char *s, size_t maxsize, char const *format, struct tm const *t) {
if (!s || !format || !t) return 0;
return strftime(s, maxsize, format, t);
}
@ -379,7 +378,7 @@ int32_t taosTime(time_t *t) {
if (t == NULL) {
return TSDB_CODE_INVALID_PARA;
}
time_t r = time(t);
time_t r = time(t);
if (r == (time_t)-1) {
return TAOS_SYSTEM_ERROR(errno);
}
@ -433,15 +432,15 @@ time_t taosMktime(struct tm *timep, timezone_t tz) {
return result;
}
int64_t tzw = 0;
#ifdef _MSC_VER
#if _MSC_VER >= 1900
tzw = _timezone;
#endif
#endif
#ifdef _MSC_VER
#if _MSC_VER >= 1900
tzw = _timezone;
#endif
#endif
return user_mktime64(timep->tm_year + 1900, timep->tm_mon + 1, timep->tm_mday, timep->tm_hour, timep->tm_min,
timep->tm_sec, tzw);
#else
time_t r = tz != NULL ? mktime_z(tz, timep) : mktime(timep);
time_t r = (tz != NULL ? mktime_z(tz, timep) : mktime(timep));
if (r == (time_t)-1) {
terrno = TAOS_SYSTEM_ERROR(errno);
}
@ -450,7 +449,7 @@ time_t taosMktime(struct tm *timep, timezone_t tz) {
#endif
}
struct tm *taosGmTimeR(const time_t *timep, struct tm *result){
struct tm *taosGmTimeR(const time_t *timep, struct tm *result) {
if (timep == NULL || result == NULL) {
return NULL;
}
@ -461,7 +460,7 @@ struct tm *taosGmTimeR(const time_t *timep, struct tm *result){
#endif
}
time_t taosTimeGm(struct tm *tmp){
time_t taosTimeGm(struct tm *tmp) {
if (tmp == NULL) {
return -1;
}
@ -530,7 +529,7 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf, int3
}
return result;
#else
res = tz != NULL ? localtime_rz(tz, timep, result): localtime_r(timep, result);
res = (tz != NULL ? localtime_rz(tz, timep, result) : localtime_r(timep, result));
if (res == NULL && buf != NULL) {
(void)snprintf(buf, bufSize, "NaN");
}
@ -544,8 +543,8 @@ int32_t taosGetTimestampSec() { return (int32_t)time(NULL); }
int32_t taosClockGetTime(int clock_id, struct timespec *pTS) {
int32_t code = 0;
#ifdef WINDOWS
LARGE_INTEGER t;
FILETIME f;
LARGE_INTEGER t;
FILETIME f;
GetSystemTimeAsFileTime(&f);
t.QuadPart = f.dwHighDateTime;

View File

@ -750,13 +750,14 @@ int32_t taosSetGlobalTimezone(const char *tz) {
int32_t code = TSDB_CODE_SUCCESS;
uDebug("[tz]set timezone to %s", tz)
#ifdef WINDOWS
char winStr[TD_TIMEZONE_LEN * 2] = {0};
char winStr[TD_TIMEZONE_LEN * 2] = {0};
for (size_t i = 0; i < W_TZ_CITY_NUM; i++) {
if (strcmp(tz_win[i][0], tz) == 0) {
char keyPath[256] = {0};
char keyValue[100] = {0};
DWORD keyValueSize = sizeof(keyValue);
snprintf(keyPath, sizeof(keyPath), "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s", tz_win[i][1]);
snprintf(keyPath, sizeof(keyPath), "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s",
tz_win[i][1]);
RegGetValue(HKEY_LOCAL_MACHINE, keyPath, "Display", RRF_RT_ANY, NULL, (PVOID)&keyValue, &keyValueSize);
if (keyValueSize > 0) {
keyValue[4] = (keyValue[4] == '+' ? '-' : '+');
@ -770,7 +771,7 @@ int32_t taosSetGlobalTimezone(const char *tz) {
_putenv(winStr);
_tzset();
#else
code = setenv("TZ", tz, 1);
code = setenv("TZ", tz, 1);
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
@ -779,7 +780,7 @@ int32_t taosSetGlobalTimezone(const char *tz) {
tzset();
#endif
time_t tx1 = taosGetTimestampSec();
time_t tx1 = taosGetTimestampSec();
return taosFormatTimezoneStr(tx1, tz, NULL, tsTimezoneStr);
}
@ -797,7 +798,7 @@ int32_t taosGetLocalTimezoneOffset() {
#endif
}
int32_t taosFormatTimezoneStr(time_t t, const char* tz, timezone_t sp, char *outTimezoneStr){
int32_t taosFormatTimezoneStr(time_t t, const char *tz, timezone_t sp, char *outTimezoneStr) {
struct tm tm1;
if (taosLocalTime(&t, &tm1, NULL, 0, sp) == NULL) {
uError("%s failed to get local time: code:%d", __FUNCTION__, errno);
@ -813,16 +814,17 @@ int32_t taosFormatTimezoneStr(time_t t, const char* tz, timezone_t sp, char *out
*/
char str1[TD_TIMEZONE_LEN] = {0};
if (taosStrfTime(str1, sizeof(str1), "%Z", &tm1) == 0){
if (taosStrfTime(str1, sizeof(str1), "%Z", &tm1) == 0) {
uError("failed to get timezone name");
return TSDB_CODE_TIME_ERROR;
}
char str2[TD_TIMEZONE_LEN] = {0};
if (taosStrfTime(str2, sizeof(str2), "%z", &tm1) == 0){
if (taosStrfTime(str2, sizeof(str2), "%z", &tm1) == 0) {
uError("failed to get timezone offset");
return TSDB_CODE_TIME_ERROR;
}
(void)snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s)", tz, str1, str2);
uDebug("[tz] system timezone:%s", outTimezoneStr);
return 0;
@ -847,7 +849,6 @@ void getTimezoneStr(char *tz) {
goto END;
} while (0);
TdFilePtr pFile = taosOpenFile("/etc/timezone", TD_FILE_READ);
if (pFile == NULL) {
uWarn("[tz] failed to open /etc/timezone, reason:%s", strerror(errno));
@ -876,8 +877,8 @@ int32_t taosGetSystemTimezone(char *outTimezoneStr) {
char value[100] = {0};
char keyPath[100] = {0};
DWORD bufferSize = sizeof(value);
LONG result = RegGetValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", "TimeZoneKeyName",
RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
LONG result = RegGetValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation",
"TimeZoneKeyName", RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
if (result != ERROR_SUCCESS) {
return TAOS_SYSTEM_WINAPI_ERROR(result);
}
@ -891,9 +892,9 @@ int32_t taosGetSystemTimezone(char *outTimezoneStr) {
if (result != ERROR_SUCCESS) {
return TAOS_SYSTEM_WINAPI_ERROR(result);
}
if (bufferSize > 0) { // value like (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (UTC, %c%c%c%c%c)", outTimezoneStr,
value[4], value[5], value[6], value[8], value[9]);
if (bufferSize > 0) { // value like (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (UTC, %c%c%c%c%c)", outTimezoneStr, value[4], value[5],
value[6], value[8], value[9]);
}
break;
}
@ -903,7 +904,7 @@ int32_t taosGetSystemTimezone(char *outTimezoneStr) {
#else
char tz[TD_TIMEZONE_LEN] = {0};
getTimezoneStr(tz);
time_t tx1 = taosGetTimestampSec();
time_t tx1 = taosGetTimestampSec();
return taosFormatTimezoneStr(tx1, tz, NULL, outTimezoneStr);
#endif
}

View File

@ -14,20 +14,32 @@ ENDIF()
INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc)
# osTests
add_executable(osTests "osTests.cpp")
target_link_libraries(osTests os util gtest_main)
if(TD_LINUX)
add_executable(osAtomicTests "osAtomicTests.cpp")
target_link_libraries(osAtomicTests os util gtest_main)
add_test(
NAME osTests
COMMAND osTests
NAME osAtomicTests
COMMAND osAtomicTests
)
endif()
add_executable(osSystemTests "osSystemTests.cpp")
target_link_libraries(osSystemTests os util gtest_main)
if(TD_LINUX)
add_executable(osDirTests "osDirTests.cpp")
target_link_libraries(osDirTests os util gtest_main)
add_test(
NAME osSystemTests
COMMAND osSystemTests
NAME osDirTests
COMMAND osDirTests
)
endif()
if(TD_LINUX)
add_executable(osEnvTests "osEnvTests.cpp")
target_link_libraries(osEnvTests os util gtest_main)
add_test(
NAME osEnvTests
COMMAND osEnvTests
)
endif()
add_executable(osMathTests "osMathTests.cpp")
target_link_libraries(osMathTests os util gtest_main)
@ -36,6 +48,13 @@ add_test(
COMMAND osMathTests
)
add_executable(osSemaphoreTests "osSemaphoreTests.cpp")
target_link_libraries(osSemaphoreTests os util gtest_main)
add_test(
NAME osSemaphoreTests
COMMAND osSemaphoreTests
)
add_executable(osSignalTests "osSignalTests.cpp")
target_link_libraries(osSignalTests os util gtest_main)
add_test(
@ -57,12 +76,28 @@ add_test(
COMMAND osStringTests
)
add_executable(osTests "osTests.cpp")
target_link_libraries(osTests os util gtest_main)
add_test(
NAME osTests
COMMAND osTests
)
add_executable(osSystemTests "osSystemTests.cpp")
target_link_libraries(osSystemTests os util gtest_main)
add_test(
NAME osSystemTests
COMMAND osSystemTests
)
if(TD_LINUX)
add_executable(osThreadTests "osThreadTests.cpp")
target_link_libraries(osThreadTests os util gtest_main)
add_test(
NAME osThreadTests
COMMAND osThreadTests
)
endif()
add_executable(osTimeTests "osTimeTests.cpp")
target_link_libraries(osTimeTests os util gtest_main)
@ -71,35 +106,3 @@ add_test(
COMMAND osTimeTests
)
if(TD_LINUX)
add_executable(osAtomicTests "osAtomicTests.cpp")
target_link_libraries(osAtomicTests os util gtest_main)
add_test(
NAME osAtomicTests
COMMAND osAtomicTests
)
add_executable(osDirTests "osDirTests.cpp")
target_link_libraries(osDirTests os util gtest_main)
add_test(
NAME osDirTests
COMMAND osDirTests
)
add_executable(osEnvTests "osEnvTests.cpp")
target_link_libraries(osEnvTests os util gtest_main)
add_test(
NAME osEnvTests
COMMAND osEnvTests
)
endif()
add_executable(osSemaphoreTests "osSemaphoreTests.cpp")
target_link_libraries(osSemaphoreTests os util gtest_main)
add_test(
NAME osSemaphoreTests
COMMAND osSemaphoreTests
)

View File

@ -29,6 +29,473 @@
#include "os.h"
#include "tlog.h"
TEST(osThreadTests, osThreadTests1) {
static int32_t globalVar = 0;
static void funcPtrKey(void *param) { taosMsleep(100); }
static void *funcPtr200(void *param) {
TdThread thread = taosThreadSelf();
TdThreadKey key = {0};
taosThreadKeyCreate(&key, funcPtrKey);
void *oldVal = taosThreadGetSpecific(key);
taosThreadSetSpecific(key, oldVal);
taosThreadKeyDelete(key);
int32_t oldType = 0;
taosThreadSetCancelType(-1, &oldType);
taosThreadSetCancelType(0, &oldType);
int32_t oldState = 0;
taosThreadSetCancelState(-1, &oldState);
taosThreadSetCancelState(0, &oldState);
int32_t policy;
struct sched_param para;
taosThreadGetSchedParam(thread, &policy, &para);
taosThreadGetSchedParam(thread, NULL, &para);
taosThreadGetSchedParam(thread, &policy, NULL);
// taosThreadSetSchedParam(NULL, 0, &para);
taosThreadSetSchedParam(thread, 0, &para);
taosMsleep(200);
return NULL;
}
static void *funcPtr501(void *param) {
taosMsleep(500);
TdThread thread = taosThreadSelf();
return NULL;
}
static void *funcPtr502(void *param) {
taosMsleep(500);
TdThread thread = taosThreadSelf();
return NULL;
}
static void *funcPtr503(void *param) {
taosMsleep(500);
TdThread thread = taosThreadSelf();
return NULL;
}
static void *funcPtr504(void *param) {
taosMsleep(500);
TdThread thread = taosThreadSelf();
return NULL;
}
static void *funcPtrExit1(void *param) {
taosThreadExit(NULL);
return NULL;
}
static void *funcPtrExit2(void *param) {
taosThreadExit(&globalVar);
return NULL;
}
TEST(osThreadTests, thread) {
TdThread tid1 = {0};
TdThread tid2 = {0};
int32_t reti = 0;
reti = taosThreadCreate(NULL, NULL, funcPtr200, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCreate(&tid1, NULL, NULL, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCreate(&tid1, NULL, funcPtr200, NULL);
EXPECT_EQ(reti, 0);
taosMsleep(300);
(void)taosThreadCancel(tid1);
reti = taosThreadCreate(&tid2, NULL, funcPtr501, NULL);
EXPECT_EQ(reti, 0);
taosMsleep(1000);
(void)taosThreadCancel(tid2);
taosThreadDetach(tid1);
reti = taosThreadCreate(&tid2, NULL, funcPtr502, NULL);
EXPECT_EQ(reti, 0);
reti = taosThreadDetach(tid2);
reti = taosThreadEqual(tid1, tid2);
EXPECT_NE(reti, 0);
reti = taosThreadCreate(&tid2, NULL, funcPtrExit1, NULL);
EXPECT_EQ(reti, 0);
reti = taosThreadCreate(&tid2, NULL, funcPtrExit2, NULL);
EXPECT_EQ(reti, 0);
taosMsleep(1000);
// reti = taosThreadCreate(&tid2, NULL, funcPtr503, NULL);
// EXPECT_EQ(reti, 0);
// taosThreadKill(tid2, SIGINT);
int32_t policy;
struct sched_param para;
taosThreadGetSchedParam(tid2, &policy, &para);
taosThreadGetSchedParam(tid2, NULL, &para);
taosThreadGetSchedParam(tid2, &policy, NULL);
// taosThreadSetSchedParam(NULL, 0, &para);
taosThreadSetSchedParam(tid2, 0, &para);
TdThreadKey key = {0};
taosThreadKeyCreate(&key, funcPtrKey);
void *oldVal = taosThreadGetSpecific(key);
taosThreadSetSpecific(key, oldVal);
taosThreadKeyDelete(key);
}
TEST(osThreadTests, attr) {
int32_t reti = 0;
TdThreadAttr attr = {0};
int32_t param = 0;
reti = taosThreadAttrInit(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrDestroy(NULL);
EXPECT_NE(reti, 0);
(void)taosThreadAttrInit(&attr);
reti = taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_JOINABLE);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetDetachState(&attr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetDetachState(NULL, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetDetachState(NULL, &param);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetDetachState(&attr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetDetachState(&attr, &param);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetInheritSched(&attr, PTHREAD_INHERIT_SCHED);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetInheritSched(&attr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetInheritSched(NULL, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetInheritSched(NULL, &param);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetInheritSched(&attr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetInheritSched(&attr, &param);
EXPECT_EQ(reti, 0);
struct sched_param schedparam = {0};
reti = taosThreadAttrGetSchedParam(&attr, &schedparam);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetSchedParam(&attr, &schedparam);
EXPECT_EQ(reti, 0);
schedparam.sched_priority = -1;
reti = taosThreadAttrSetSchedParam(&attr, &schedparam);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetSchedParam(NULL, &schedparam);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetSchedParam(NULL, &schedparam);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetSchedParam(&attr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetSchedPolicy(&attr, SCHED_FIFO);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetSchedPolicy(&attr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetSchedPolicy(NULL, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetSchedPolicy(NULL, &param);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetSchedPolicy(&attr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetSchedPolicy(&attr, &param);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetScope(&attr, PTHREAD_SCOPE_SYSTEM);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetScope(&attr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetScope(NULL, -1);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetScope(NULL, &param);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetScope(&attr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetScope(&attr, &param);
EXPECT_EQ(reti, 0);
size_t stacksize;
reti = taosThreadAttrGetStackSize(&attr, &stacksize);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetStackSize(&attr, stacksize);
EXPECT_EQ(reti, 0);
reti = taosThreadAttrSetStackSize(&attr, 2048);
EXPECT_NE(reti, 0);
reti = taosThreadAttrSetStackSize(NULL, stacksize);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetStackSize(NULL, &stacksize);
EXPECT_NE(reti, 0);
reti = taosThreadAttrGetStackSize(&attr, NULL);
EXPECT_NE(reti, 0);
}
TEST(osThreadTests, cond) {
int32_t reti = 0;
reti = taosThreadCondInit(NULL, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondDestroy(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondSignal(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondBroadcast(NULL);
EXPECT_NE(reti, 0);
TdThreadCond cond{0};
TdThreadMutex mutex = {0};
reti = taosThreadCondWait(&cond, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondWait(NULL, &mutex);
EXPECT_NE(reti, 0);
struct timespec abstime = {0};
reti = taosThreadCondTimedWait(&cond, NULL, &abstime);
EXPECT_NE(reti, 0);
reti = taosThreadCondTimedWait(NULL, &mutex, &abstime);
EXPECT_NE(reti, 0);
reti = taosThreadCondTimedWait(&cond, &mutex, NULL);
EXPECT_EQ(reti, 0);
TdThreadCondAttr condattr = {0};
(void)taosThreadCondAttrInit(&condattr);
reti = taosThreadCondAttrInit(NULL);
EXPECT_NE(reti, 0);
int32_t pshared;
reti = taosThreadCondAttrGetPshared(&condattr, &pshared);
EXPECT_EQ(reti, 0);
reti = taosThreadCondAttrSetPshared(&condattr, pshared);
EXPECT_EQ(reti, 0);
reti = taosThreadCondAttrSetPshared(&condattr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadCondAttrSetPshared(NULL, pshared);
EXPECT_NE(reti, 0);
reti = taosThreadCondAttrGetPshared(NULL, &pshared);
EXPECT_NE(reti, 0);
reti = taosThreadCondAttrGetPshared(&condattr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondAttrSetclock(NULL, -1);
EXPECT_NE(reti, 0);
reti = taosThreadCondAttrDestroy(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadCondAttrDestroy(&condattr);
EXPECT_EQ(reti, 0);
}
TEST(osThreadTests, mutex) {
int32_t reti = 0;
TdThreadMutex mutex;
reti = taosThreadMutexInit(NULL, 0);
EXPECT_NE(reti, 0);
reti = taosThreadMutexInit(&mutex, 0);
EXPECT_EQ(reti, 0);
reti = taosThreadMutexTryLock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadMutexTryLock(&mutex);
EXPECT_EQ(reti, 0);
reti = taosThreadMutexTryLock(&mutex);
EXPECT_NE(reti, 0);
reti = taosThreadMutexUnlock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadMutexUnlock(&mutex);
EXPECT_EQ(reti, 0);
reti = taosThreadMutexLock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadMutexLock(&mutex);
EXPECT_EQ(reti, 0);
reti = taosThreadMutexUnlock(&mutex);
EXPECT_EQ(reti, 0);
reti = taosThreadMutexDestroy(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadMutexDestroy(&mutex);
EXPECT_EQ(reti, 0);
}
TEST(osThreadTests, mutexAttr) {
int32_t reti = 0;
TdThreadMutexAttr mutexAttr;
reti = taosThreadMutexAttrInit(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadMutexAttrInit(&mutexAttr);
EXPECT_EQ(reti, 0);
int32_t pshared;
reti = taosThreadMutexAttrGetPshared(&mutexAttr, &pshared);
EXPECT_EQ(reti, 0);
reti = taosThreadMutexAttrSetPshared(&mutexAttr, pshared);
EXPECT_EQ(reti, 0);
reti = taosThreadMutexAttrSetPshared(&mutexAttr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadMutexAttrSetPshared(NULL, pshared);
EXPECT_NE(reti, 0);
reti = taosThreadMutexAttrGetPshared(NULL, &pshared);
EXPECT_NE(reti, 0);
reti = taosThreadMutexAttrGetPshared(&mutexAttr, NULL);
EXPECT_NE(reti, 0);
int32_t kind;
reti = taosThreadMutexAttrGetType(&mutexAttr, &kind);
EXPECT_EQ(reti, 0);
reti = taosThreadMutexAttrSetType(&mutexAttr, kind);
EXPECT_EQ(reti, 0);
reti = taosThreadMutexAttrSetType(&mutexAttr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadMutexAttrSetType(NULL, kind);
EXPECT_NE(reti, 0);
reti = taosThreadMutexAttrGetType(NULL, &kind);
EXPECT_NE(reti, 0);
reti = taosThreadMutexAttrGetType(&mutexAttr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadMutexAttrDestroy(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadMutexAttrDestroy(&mutexAttr);
EXPECT_EQ(reti, 0);
}
TEST(osThreadTests, rwlock) {
int32_t reti = 0;
TdThreadRwlock rwlock;
reti = taosThreadRwlockInit(NULL, 0);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockInit(&rwlock, 0);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockTryRdlock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockTryRdlock(&rwlock);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockUnlock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockUnlock(&rwlock);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockRdlock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockRdlock(&rwlock);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockUnlock(&rwlock);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockDestroy(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockDestroy(&rwlock);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockInit(NULL, 0);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockInit(&rwlock, 0);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockTryWrlock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockTryWrlock(&rwlock);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockUnlock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockUnlock(&rwlock);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockWrlock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockWrlock(&rwlock);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockUnlock(&rwlock);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockDestroy(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockDestroy(&rwlock);
EXPECT_EQ(reti, 0);
}
TEST(osThreadTests, rdlockAttr) {
int32_t reti = 0;
TdThreadRwlockAttr rdlockAttr;
reti = taosThreadRwlockAttrInit(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockAttrInit(&rdlockAttr);
EXPECT_EQ(reti, 0);
int32_t pshared;
reti = taosThreadRwlockAttrGetPshared(&rdlockAttr, &pshared);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockAttrSetPshared(&rdlockAttr, pshared);
EXPECT_EQ(reti, 0);
reti = taosThreadRwlockAttrSetPshared(&rdlockAttr, -1);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockAttrSetPshared(NULL, pshared);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockAttrGetPshared(NULL, &pshared);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockAttrGetPshared(&rdlockAttr, NULL);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockAttrDestroy(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadRwlockAttrDestroy(&rdlockAttr);
EXPECT_EQ(reti, 0);
}
TEST(osThreadTests, spinlock) {
int32_t reti = 0;
TdThreadSpinlock lock = {0};
reti = taosThreadSpinInit(&lock, -1);
EXPECT_EQ(reti, 0);
reti = taosThreadSpinLock(&lock);
EXPECT_EQ(reti, 0);
reti = taosThreadSpinTrylock(&lock);
EXPECT_NE(reti, 0);
reti = taosThreadSpinUnlock(&lock);
EXPECT_EQ(reti, 0);
reti = taosThreadSpinDestroy(&lock);
EXPECT_EQ(reti, 0);
reti = taosThreadSpinInit(&lock, -1);
EXPECT_EQ(reti, 0);
reti = taosThreadSpinTrylock(&lock);
EXPECT_EQ(reti, 0);
reti = taosThreadSpinUnlock(&lock);
EXPECT_EQ(reti, 0);
reti = taosThreadSpinDestroy(&lock);
EXPECT_EQ(reti, 0);
reti = taosThreadSpinInit(NULL, 0);
EXPECT_NE(reti, 0);
reti = taosThreadSpinLock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadSpinTrylock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadSpinUnlock(NULL);
EXPECT_NE(reti, 0);
reti = taosThreadSpinDestroy(NULL);
EXPECT_NE(reti, 0);
}
TEST(osThreadTests, others) {
taosThreadTestCancel();
taosThreadClear(NULL);
}

View File

@ -33,7 +33,7 @@ TEST(osTimeTests, taosLocalTime) {
// Test 1: Test when both timep and result are not NULL
time_t timep = 1617531000; // 2021-04-04 18:10:00
struct tm result;
struct tm* local_time = taosLocalTime(&timep, &result, NULL, 0, NULL);
struct tm *local_time = taosLocalTime(&timep, &result, NULL, 0, NULL);
ASSERT_NE(local_time, nullptr);
ASSERT_EQ(local_time->tm_year, 121);
ASSERT_EQ(local_time->tm_mon, 3);
@ -92,4 +92,55 @@ TEST(osTimeTests, taosLocalTime) {
local_time = taosLocalTime(&neg_timep3, &result, NULL, 0, NULL);
ASSERT_EQ(local_time, nullptr);
#endif
}
TEST(osTimeTests, invalidParameter) {
void *retp = NULL;
int32_t reti = 0;
char buf[1024] = {0};
char fmt[1024] = {0};
struct tm tm = {0};
struct timeval tv = {0};
retp = taosStrpTime(buf, fmt, NULL);
EXPECT_EQ(retp, nullptr);
retp = taosStrpTime(NULL, fmt, &tm);
EXPECT_EQ(retp, nullptr);
retp = taosStrpTime(buf, NULL, &tm);
EXPECT_EQ(retp, nullptr);
reti = taosGetTimeOfDay(NULL);
EXPECT_NE(reti, 0);
reti = taosTime(NULL);
EXPECT_NE(reti, 0);
tm.tm_year = 2024;
tm.tm_mon = 10;
tm.tm_mday = 23;
tm.tm_hour = 12;
tm.tm_min = 1;
tm.tm_sec = 0;
tm.tm_isdst = -1;
time_t rett = taosMktime(&tm, NULL);
EXPECT_NE(rett, 0);
retp = taosLocalTime(NULL, &tm, NULL, 0, NULL);
EXPECT_EQ(retp, nullptr);
retp = taosLocalTime(&rett, NULL, NULL, 0, NULL);
EXPECT_EQ(retp, nullptr);
reti = taosSetGlobalTimezone(NULL);
EXPECT_NE(reti, 0);
}
TEST(osTimeTests, user_mktime64) {
int64_t reti = 0;
reti = user_mktime64(2024, 10, 23, 12, 3, 2, 1);
EXPECT_NE(reti, 0);
reti = user_mktime64(2024, 1, 23, 12, 3, 2, 1);
EXPECT_NE(reti, 0);
}

View File

@ -218,6 +218,8 @@
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/slimit.py -Q 2
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/slimit.py -Q 3
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/slimit.py -Q 4
,,n,system-test,./pytest.sh python3 ./test.py -f 2-query/ts-5761.py
,,n,system-test,./pytest.sh python3 ./test.py -f 2-query/ts-5761-scalemode.py
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/ts-5712.py
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/ts-4233.py
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/ts-4233.py -Q 2
@ -315,6 +317,7 @@
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_ts5466.py
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_ts-5473.py
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/td-32187.py
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/td-33225.py
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_ts4563.py
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_td32526.py
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_replay.py
@ -1089,6 +1092,10 @@
,,n,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/insertMix.py -N 3
,,n,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/stt.py -N 3
,,n,system-test,python3 ./test.py -f eco-system/meta/database/keep_time_offset.py
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/operator.py
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/operator.py -Q 2
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/operator.py -Q 3
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/operator.py -Q 4
,,y,system-test,./pytest.sh python3 ./test.py -f eco-system/manager/schema_change.py -N 3 -M 3
#tsim test

388
tests/run_local_coverage.sh Executable file
View File

@ -0,0 +1,388 @@
#!/bin/bash
# Color setting
RED='\033[0;31m'
GREEN='\033[1;32m'
GREEN_DARK='\033[0;32m'
GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'
function print_color() {
local color="$1"
local message="$2"
echo -e "${color}${message}${NC}"
}
# Initialization parameter
TDENGINE_DIR="/root/TDinternal/community"
BRANCH=""
TDENGINE_GCDA_DIR="/root/TDinternal/community/debug/"
# Parse command line parameters
while getopts "hd:b:f:c:u:i:" arg; do
case $arg in
d)
TDENGINE_DIR=$OPTARG
;;
b)
BRANCH=$OPTARG
;;
f)
TDENGINE_GCDA_DIR=$OPTARG
;;
c)
TEST_CASE=$OPTARG
;;
u)
UNIT_TEST_CASE=$OPTARG
;;
i)
BRANCH_BUILD=$OPTARG
;;
h)
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case]"
echo " -d [TDengine dir] [default /root/TDinternal/community; eg: /home/TDinternal/community] "
echo " -b [Test branch] [default local branch; eg:cover/3.0] "
echo " -i [Build test branch] [default no:not build, but still install ;yes:will build and install ] "
echo " -f [TDengine gcda dir] [default /root/TDinternal/community/debug; eg:/root/TDinternal/community/debug/community/source/dnode/vnode/CMakeFiles/vnode.dir/src/tq/] "
echo " -c [Test single case/all cases] [default null; -c all : include parallel_test/longtimeruning_cases.task and all unit cases; -c task : include parallel_test/longtimeruning_cases.task; single case: eg: -c './test.sh -f tsim/stream/streamFwcIntervalFill.sim' ] "
echo " -u [Unit test case] [default null; eg: './schedulerTest' ] "
exit 0
;;
?)
echo "Usage: ./$(basename $0) -h"
exit 1
;;
esac
done
# Check if the command name is provided
if [ -z "$TDENGINE_DIR" ]; then
echo "Error: TDengine dir is required."
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case] "
echo " -d [TDengine dir] [default /root/TDinternal/community; eg: /home/TDinternal/community] "
echo " -b [Test branch] [default local branch; eg:cover/3.0] "
echo " -i [Build test branch] [default no:not build, but still install ;yes:will build and install ] "
echo " -f [TDengine gcda dir] [default /root/TDinternal/community/debug; eg:/root/TDinternal/community/debug/community/source/dnode/vnode/CMakeFiles/vnode.dir/src/tq/] "
echo " -c [Test casingle case/all casesse] [default null; -c all : include parallel_test/longtimeruning_cases.task and all unit cases; -c task : include parallel_test/longtimeruning_cases.task; single case: eg: -c './test.sh -f tsim/stream/streamFwcIntervalFill.sim' ] "
echo " -u [Unit test case] [default null; eg: './schedulerTest' ] "
exit 1
fi
echo "TDENGINE_DIR = $TDENGINE_DIR"
today=`date +"%Y%m%d"`
TDENGINE_ALLCI_REPORT="$TDENGINE_DIR/tests/all-ci-report-$today.log"
function pullTDengine() {
print_color "$GREEN" "TDengine pull start"
# pull parent code
cd "$TDENGINE_DIR/../"
print_color "$GREEN" "git pull parent code..."
git reset --hard
git checkout -- .
git checkout $branch
git checkout -- .
git clean -f
git pull
# pull tdengine code
cd $TDENGINE_DIR
print_color "$GREEN" "git pull tdengine code..."
git reset --hard
git checkout -- .
git checkout $branch
git checkout -- .
git clean -f
git pull
print_color "$GREEN" "TDengine pull end"
}
function buildTDengine() {
print_color "$GREEN" "TDengine build start"
[ -d $TDENGINE_DIR/debug ] || mkdir $TDENGINE_DIR/debug
cd $TDENGINE_DIR/debug
print_color "$GREEN" "rebuild.."
rm -rf *
makecmd="cmake -DCOVER=true -DBUILD_TEST=false -DBUILD_HTTP=false -DBUILD_DEPENDENCY_TESTS=0 -DBUILD_TOOLS=true -DBUILD_GEOS=true -DBUILD_TEST=true -DBUILD_CONTRIB=false ../../"
print_color "$GREEN" "$makecmd"
$makecmd
make -j 8 install
}
# Check and get the branch name and build branch
if [ -n "$BRANCH" ] && [ -z "$BRANCH_BUILD" ] ; then
branch="$BRANCH"
print_color "$GREEN" "Testing branch: $branch "
print_color "$GREEN" "Build is required for this test!"
pullTDengine
buildTDengine
elif [ -n "$BRANCH_BUILD" ] && [ "$BRANCH_BUILD" == "yes" ] ; then
branch="$BRANCH"
print_color "$GREEN" "Testing branch: $branch "
print_color "$GREEN" "Build is required for this test!"
pullTDengine
buildTDengine
elif [ -n "$BRANCH_BUILD" ] && [ "$BRANCH_BUILD" == "no" ] ; then
branch="$BRANCH"
print_color "$GREEN" "Testing branch: $branch "
print_color "$GREEN" "not build,only install!"
cd "$TDENGINE_DIR/../"
git pull
cd "$TDENGINE_DIR/"
git pull
cd $TDENGINE_DIR/debug
make -j 8 install
else
print_color "$GREEN" "Build is not required for this test!"
fi
function runCasesOneByOne () {
while read -r line; do
if [[ "$line" != "#"* ]]; then
cmd=`echo $line | cut -d',' -f 5`
if [[ "$2" == "sim" ]] && [[ $line == *"script"* ]]; then
echo $cmd
case=`echo $cmd | cut -d' ' -f 3`
case_file=`echo $case | tr -d ' /' `
start_time=`date +%s`
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > $TDENGINE_DIR/tests/$case_file.log 2>&1 && \
echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_ALLCI_REPORT || \
echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
end_time=`date +%s`
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
elif [[ "$line" == *"$2"* ]]; then
echo $cmd
if [[ "$cmd" == *"pytest.sh"* ]]; then
cmd=`echo $cmd | cut -d' ' -f 2-20`
fi
case=`echo $cmd | cut -d' ' -f 4-20`
case_file=`echo $case | tr -d ' /' `
start_time=`date +%s`
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > $TDENGINE_DIR/tests/$case_file.log 2>&1 && \
echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_ALLCI_REPORT || \
echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
end_time=`date +%s`
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
fi
fi
done < $1
}
function runUnitTest() {
print_color "$GREEN" "=== Run unit test case ==="
print_color "$GREEN" " $TDENGINE_DIR/debug"
cd $TDENGINE_DIR/debug
ctest -j12
print_color "$GREEN" "3.0 unit test done"
}
function runSimCases() {
print_color "$GREEN" "=== Run sim cases ==="
cd $TDENGINE_DIR/tests/script
runCasesOneByOne $TDENGINE_DIR/tests/parallel_test/longtimeruning_cases.task sim
totalSuccess=`grep 'sim success' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalSuccess" -gt "0" ]; then
print_color "$GREEN" "### Total $totalSuccess SIM test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
totalFailed=`grep 'sim failed\|fault' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalFailed" -ne "0" ]; then
print_color "$RED" "### Total $totalFailed SIM test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
}
function runPythonCases() {
print_color "$GREEN" "=== Run python cases ==="
cd $TDENGINE_DIR/tests/parallel_test
sed -i '/compatibility.py/d' longtimeruning_cases.task
# army
cd $TDENGINE_DIR/tests/army
runCasesOneByOne ../parallel_test/longtimeruning_cases.task army
# system-test
cd $TDENGINE_DIR/tests/system-test
runCasesOneByOne ../parallel_test/longtimeruning_cases.task system-test
# develop-test
cd $TDENGINE_DIR/tests/develop-test
runCasesOneByOne ../parallel_test/longtimeruning_cases.task develop-test
totalSuccess=`grep 'py success' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalSuccess" -gt "0" ]; then
print_color "$GREEN" "### Total $totalSuccess python test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
totalFailed=`grep 'py failed\|fault' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalFailed" -ne "0" ]; then
print_color "$RED" "### Total $totalFailed python test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
}
function runTest_all() {
print_color "$GREEN" "run Test"
cd $TDENGINE_DIR
[ -d sim ] && rm -rf sim
[ -f $TDENGINE_ALLCI_REPORT ] && rm $TDENGINE_ALLCI_REPORT
runUnitTest
runSimCases
runPythonCases
stopTaosd
cd $TDENGINE_DIR/tests/script
find . -name '*.sql' | xargs rm -f
cd $TDENGINE_DIR/tests/pytest
find . -name '*.sql' | xargs rm -f
}
function runTest() {
print_color "$GREEN" "run Test"
cd $TDENGINE_DIR
[ -d sim ] && rm -rf sim
[ -f $TDENGINE_ALLCI_REPORT ] && rm $TDENGINE_ALLCI_REPORT
if [ -n "$TEST_CASE" ] && [ "$TEST_CASE" != "all" ] && [ "$TEST_CASE" != "task" ]; then
TEST_CASE="$TEST_CASE"
print_color "$GREEN" "Test case: $TEST_CASE "
cd $TDENGINE_DIR/tests/script/ && $TEST_CASE
cd $TDENGINE_DIR/tests/army/ && $TEST_CASE
cd $TDENGINE_DIR/tests/system-test/ && $TEST_CASE
cd $TDENGINE_DIR/tests/develop-test/ && $TEST_CASE
elif [ "$TEST_CASE" == "all" ]; then
print_color "$GREEN" "Test case is : parallel_test/longtimeruning_cases.task and all unit cases"
runTest_all
elif [ "$TEST_CASE" == "task" ]; then
print_color "$GREEN" "Test case is only: parallel_test/longtimeruning_cases.task "
runSimCases
runPythonCases
elif [ -n "$UNIT_TEST_CASE" ]; then
UNIT_TEST_CASE="$UNIT_TEST_CASE"
cd $TDENGINE_DIR/debug/build/bin/ && $UNIT_TEST_CASE
else
print_color "$GREEN" "Test case is null"
fi
stopTaosd
cd $TDENGINE_DIR/tests/script
find . -name '*.sql' | xargs rm -f
cd $TDENGINE_DIR/tests/pytest
find . -name '*.sql' | xargs rm -f
}
function lcovFunc {
echo "collect data by lcov"
cd $TDENGINE_DIR
if [ -n "$TDENGINE_GCDA_DIR" ]; then
TDENGINE_GCDA_DIR="$TDENGINE_GCDA_DIR"
print_color "$GREEN" "Test gcda file dir: $TDENGINE_GCDA_DIR "
else
print_color "$GREEN" "Test gcda file dir is default: /root/TDinternal/community/debug"
fi
# collect data
lcov -d "$TDENGINE_GCDA_DIR" -capture --rc lcov_branch_coverage=1 --rc genhtml_branch_coverage=1 --no-external -b $TDENGINE_DIR -o coverage.info
# remove exclude paths
lcov --remove coverage.info \
'*/contrib/*' '*/test/*' '*/packaging/*' '*/taos-tools/*' '*/taosadapter/*' '*/TSZ/*' \
'*/AccessBridgeCalls.c' '*/ttszip.c' '*/dataInserter.c' '*/tlinearhash.c' '*/tsimplehash.c' '*/tsdbDiskData.c' '/*/enterprise/*' '*/docs/*' '*/sim/*'\
'*/texpr.c' '*/runUdf.c' '*/schDbg.c' '*/syncIO.c' '*/tdbOs.c' '*/pushServer.c' '*/osLz4.c'\
'*/tbase64.c' '*/tbuffer.c' '*/tdes.c' '*/texception.c' '*/examples/*' '*/tidpool.c' '*/tmempool.c'\
'*/clientJniConnector.c' '*/clientTmqConnector.c' '*/version.cc'\
'*/tthread.c' '*/tversion.c' '*/ctgDbg.c' '*/schDbg.c' '*/qwDbg.c' '*/tencode.h' \
'*/shellAuto.c' '*/shellTire.c' '*/shellCommand.c'\
'*/sql.c' '*/sql.y' '*/smaSnapshot.c' '*/smaCommit.c' '*/debug/*' '*/tests/*'\
--rc lcov_branch_coverage=1 -o coverage.info
# generate result
echo "generate result"
lcov -l --rc lcov_branch_coverage=1 coverage.info | tee -a $TDENGINE_COVERAGE_REPORT
}
function stopTaosd {
print_color "$GREEN" "Stop taosd start"
systemctl stop taosd
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
while [ -n "$PID" ]
do
pkill -TERM -x taosd
sleep 1
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
done
print_color "$GREEN" "Stop tasod end"
}
function stopTaosadapter {
print_color "$GREEN" "Stop taosadapter"
systemctl stop taosadapter.service
PID=`ps -ef|grep -w taosadapter | grep -v grep | awk '{print $2}'`
while [ -n "$PID" ]
do
pkill -TERM -x taosadapter
sleep 1
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
done
print_color "$GREEN" "Stop tasoadapter end"
}
WORK_DIR=/root
date >> $WORK_DIR/date.log
print_color "$GREEN" "Run local coverage test cases" | tee -a $WORK_DIR/date.log
stopTaosd
runTest
lcovFunc
date >> $WORK_DIR/date.log
print_color "$GREEN" "End of local coverage test cases" | tee -a $WORK_DIR/date.log
# Define coverage information files and output directories
COVERAGE_INFO="$TDENGINE_DIR/coverage.info"
OUTPUT_DIR="$WORK_DIR/coverage_report"
# Check whether the coverage information file exists
if [ ! -f "$COVERAGE_INFO" ]; then
echo "Error: $COVERAGE_INFO not found!"
exit 1
fi
# Generate local HTML reports
genhtml "$COVERAGE_INFO" --branch-coverage --function-coverage --output-directory "$OUTPUT_DIR"
# Check whether the report was generated successfully
if [ $? -eq 0 ]; then
echo "HTML coverage report generated successfully in $OUTPUT_DIR"
echo "For more details : "
echo "http://192.168.1.61:7000/"
else
echo "Error generating HTML coverage report"
exit 1
fi

View File

@ -0,0 +1,388 @@
#!/bin/bash
# Color setting
RED='\033[0;31m'
GREEN='\033[1;32m'
GREEN_DARK='\033[0;32m'
GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'
function print_color() {
local color="$1"
local message="$2"
echo -e "${color}${message}${NC}"
}
# Initialization parameter
TDENGINE_DIR="/root/TDinternal/community"
BRANCH=""
TDENGINE_GCDA_DIR="/root/TDinternal/community/debug/"
# Parse command line parameters
while getopts "hd:b:f:c:u:i:" arg; do
case $arg in
d)
TDENGINE_DIR=$OPTARG
;;
b)
BRANCH=$OPTARG
;;
f)
TDENGINE_GCDA_DIR=$OPTARG
;;
c)
TEST_CASE=$OPTARG
;;
u)
UNIT_TEST_CASE=$OPTARG
;;
i)
BRANCH_BUILD=$OPTARG
;;
h)
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case]"
echo " -d [TDengine dir] [default /root/TDinternal/community; eg: /home/TDinternal/community] "
echo " -b [Test branch] [default local branch; eg:cover/3.0] "
echo " -i [Build test branch] [default no:not build, but still install ;yes:will build and install ] "
echo " -f [TDengine gcda dir] [default /root/TDinternal/community/debug; eg:/root/TDinternal/community/debug/community/source/dnode/vnode/CMakeFiles/vnode.dir/src/tq/] "
echo " -c [Test single case/all cases] [default null; -c all : include parallel_test/longtimeruning_cases.task and all unit cases; -c task : include parallel_test/longtimeruning_cases.task; single case: eg: -c './test.sh -f tsim/stream/streamFwcIntervalFill.sim' ] "
echo " -u [Unit test case] [default null; eg: './schedulerTest' ] "
exit 0
;;
?)
echo "Usage: ./$(basename $0) -h"
exit 1
;;
esac
done
# Check if the command name is provided
if [ -z "$TDENGINE_DIR" ]; then
echo "Error: TDengine dir is required."
echo "Usage: $(basename $0) -d [TDengine dir] -b [Test branch] -i [Build test branch] -f [TDengine gcda dir] -c [Test single case/all cases] -u [Unit test case] "
echo " -d [TDengine dir] [default /root/TDinternal/community; eg: /home/TDinternal/community] "
echo " -b [Test branch] [default local branch; eg:cover/3.0] "
echo " -i [Build test branch] [default no:not build, but still install ;yes:will build and install ] "
echo " -f [TDengine gcda dir] [default /root/TDinternal/community/debug; eg:/root/TDinternal/community/debug/community/source/dnode/vnode/CMakeFiles/vnode.dir/src/tq/] "
echo " -c [Test casingle case/all casesse] [default null; -c all : include parallel_test/longtimeruning_cases.task and all unit cases; -c task : include parallel_test/longtimeruning_cases.task; single case: eg: -c './test.sh -f tsim/stream/streamFwcIntervalFill.sim' ] "
echo " -u [Unit test case] [default null; eg: './schedulerTest' ] "
exit 1
fi
echo "TDENGINE_DIR = $TDENGINE_DIR"
today=`date +"%Y%m%d"`
TDENGINE_ALLCI_REPORT="$TDENGINE_DIR/tests/all-ci-report-$today.log"
function pullTDengine() {
print_color "$GREEN" "TDengine pull start"
# pull parent code
cd "$TDENGINE_DIR/../"
print_color "$GREEN" "git pull parent code..."
git reset --hard
git checkout -- .
git checkout $branch
git checkout -- .
git clean -f
git pull
# pull tdengine code
cd $TDENGINE_DIR
print_color "$GREEN" "git pull tdengine code..."
git reset --hard
git checkout -- .
git checkout $branch
git checkout -- .
git clean -f
git pull
print_color "$GREEN" "TDengine pull end"
}
function buildTDengine() {
print_color "$GREEN" "TDengine build start"
[ -d $TDENGINE_DIR/debug ] || mkdir $TDENGINE_DIR/debug
cd $TDENGINE_DIR/debug
print_color "$GREEN" "rebuild.."
rm -rf *
makecmd="cmake -DCOVER=true -DBUILD_TEST=false -DBUILD_HTTP=false -DBUILD_DEPENDENCY_TESTS=0 -DBUILD_TOOLS=true -DBUILD_GEOS=true -DBUILD_TEST=true -DBUILD_CONTRIB=false ../../"
print_color "$GREEN" "$makecmd"
$makecmd
make -j 8 install
}
# Check and get the branch name and build branch
if [ -n "$BRANCH" ] && [ -z "$BRANCH_BUILD" ] ; then
branch="$BRANCH"
print_color "$GREEN" "Testing branch: $branch "
print_color "$GREEN" "Build is required for this test!"
pullTDengine
buildTDengine
elif [ -n "$BRANCH_BUILD" ] && [ "$BRANCH_BUILD" == "yes" ] ; then
branch="$BRANCH"
print_color "$GREEN" "Testing branch: $branch "
print_color "$GREEN" "Build is required for this test!"
pullTDengine
buildTDengine
elif [ -n "$BRANCH_BUILD" ] && [ "$BRANCH_BUILD" == "no" ] ; then
branch="$BRANCH"
print_color "$GREEN" "Testing branch: $branch "
print_color "$GREEN" "not build,only install!"
cd "$TDENGINE_DIR/../"
git pull
cd "$TDENGINE_DIR/"
git pull
cd $TDENGINE_DIR/debug
make -j 8 install
else
print_color "$GREEN" "Build is not required for this test!"
fi
function runCasesOneByOne () {
while read -r line; do
if [[ "$line" != "#"* ]]; then
cmd=`echo $line | cut -d',' -f 5`
if [[ "$2" == "sim" ]] && [[ $line == *"script"* ]]; then
echo $cmd
case=`echo $cmd | cut -d' ' -f 3`
case_file=`echo $case | tr -d ' /' `
start_time=`date +%s`
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > $TDENGINE_DIR/tests/$case_file.log 2>&1 && \
echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_ALLCI_REPORT || \
echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
end_time=`date +%s`
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
elif [[ "$line" == *"$2"* ]]; then
echo $cmd
if [[ "$cmd" == *"pytest.sh"* ]]; then
cmd=`echo $cmd | cut -d' ' -f 2-20`
fi
case=`echo $cmd | cut -d' ' -f 4-20`
case_file=`echo $case | tr -d ' /' `
start_time=`date +%s`
date +%F\ %T | tee -a $TDENGINE_ALLCI_REPORT && timeout 20m $cmd > $TDENGINE_DIR/tests/$case_file.log 2>&1 && \
echo -e "${GREEN}$case success${NC}" | tee -a $TDENGINE_ALLCI_REPORT || \
echo -e "${RED}$case failed${NC}" | tee -a $TDENGINE_ALLCI_REPORT
end_time=`date +%s`
echo execution time of $case was `expr $end_time - $start_time`s. | tee -a $TDENGINE_ALLCI_REPORT
fi
fi
done < $1
}
function runUnitTest() {
print_color "$GREEN" "=== Run unit test case ==="
print_color "$GREEN" " $TDENGINE_DIR/debug"
cd $TDENGINE_DIR/debug
ctest -j12
print_color "$GREEN" "3.0 unit test done"
}
function runSimCases() {
print_color "$GREEN" "=== Run sim cases ==="
cd $TDENGINE_DIR/tests/script
runCasesOneByOne $TDENGINE_DIR/tests/parallel_test/longtimeruning_cases.task sim
totalSuccess=`grep 'sim success' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalSuccess" -gt "0" ]; then
print_color "$GREEN" "### Total $totalSuccess SIM test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
totalFailed=`grep 'sim failed\|fault' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalFailed" -ne "0" ]; then
print_color "$RED" "### Total $totalFailed SIM test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
}
function runPythonCases() {
print_color "$GREEN" "=== Run python cases ==="
cd $TDENGINE_DIR/tests/parallel_test
sed -i '/compatibility.py/d' longtimeruning_cases.task
# army
cd $TDENGINE_DIR/tests/army
runCasesOneByOne ../parallel_test/longtimeruning_cases.task army
# system-test
cd $TDENGINE_DIR/tests/system-test
runCasesOneByOne ../parallel_test/longtimeruning_cases.task system-test
# develop-test
cd $TDENGINE_DIR/tests/develop-test
runCasesOneByOne ../parallel_test/longtimeruning_cases.task develop-test
totalSuccess=`grep 'py success' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalSuccess" -gt "0" ]; then
print_color "$GREEN" "### Total $totalSuccess python test case(s) succeed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
totalFailed=`grep 'py failed\|fault' $TDENGINE_ALLCI_REPORT | wc -l`
if [ "$totalFailed" -ne "0" ]; then
print_color "$RED" "### Total $totalFailed python test case(s) failed! ###" | tee -a $TDENGINE_ALLCI_REPORT
fi
}
function runTest_all() {
print_color "$GREEN" "run Test"
cd $TDENGINE_DIR
[ -d sim ] && rm -rf sim
[ -f $TDENGINE_ALLCI_REPORT ] && rm $TDENGINE_ALLCI_REPORT
runUnitTest
runSimCases
runPythonCases
stopTaosd
cd $TDENGINE_DIR/tests/script
find . -name '*.sql' | xargs rm -f
cd $TDENGINE_DIR/tests/pytest
find . -name '*.sql' | xargs rm -f
}
function runTest() {
print_color "$GREEN" "run Test"
cd $TDENGINE_DIR
[ -d sim ] && rm -rf sim
[ -f $TDENGINE_ALLCI_REPORT ] && rm $TDENGINE_ALLCI_REPORT
if [ -n "$TEST_CASE" ] && [ "$TEST_CASE" != "all" ] && [ "$TEST_CASE" != "task" ]; then
TEST_CASE="$TEST_CASE"
print_color "$GREEN" "Test case: $TEST_CASE "
cd $TDENGINE_DIR/tests/script/ && $TEST_CASE
cd $TDENGINE_DIR/tests/army/ && $TEST_CASE
cd $TDENGINE_DIR/tests/system-test/ && $TEST_CASE
cd $TDENGINE_DIR/tests/develop-test/ && $TEST_CASE
elif [ "$TEST_CASE" == "all" ]; then
print_color "$GREEN" "Test case is : parallel_test/longtimeruning_cases.task and all unit cases"
runTest_all
elif [ "$TEST_CASE" == "task" ]; then
print_color "$GREEN" "Test case is only: parallel_test/longtimeruning_cases.task "
runSimCases
runPythonCases
elif [ -n "$UNIT_TEST_CASE" ]; then
UNIT_TEST_CASE="$UNIT_TEST_CASE"
cd $TDENGINE_DIR/debug/build/bin/ && $UNIT_TEST_CASE
else
print_color "$GREEN" "Test case is null"
fi
stopTaosd
cd $TDENGINE_DIR/tests/script
find . -name '*.sql' | xargs rm -f
cd $TDENGINE_DIR/tests/pytest
find . -name '*.sql' | xargs rm -f
}
function lcovFunc {
echo "collect data by lcov"
cd $TDENGINE_DIR
if [ -n "$TDENGINE_GCDA_DIR" ]; then
TDENGINE_GCDA_DIR="$TDENGINE_GCDA_DIR"
print_color "$GREEN" "Test gcda file dir: $TDENGINE_GCDA_DIR "
else
print_color "$GREEN" "Test gcda file dir is default: /root/TDinternal/community/debug"
fi
# collect data
lcov -d "$TDENGINE_GCDA_DIR" -capture --rc lcov_branch_coverage=0 --rc genhtml_branch_coverage=1 --no-external -b $TDENGINE_DIR -o coverage.info
# remove exclude paths
lcov --remove coverage.info \
'*/contrib/*' '*/test/*' '*/packaging/*' '*/taos-tools/*' '*/taosadapter/*' '*/TSZ/*' \
'*/AccessBridgeCalls.c' '*/ttszip.c' '*/dataInserter.c' '*/tlinearhash.c' '*/tsimplehash.c' '*/tsdbDiskData.c' '/*/enterprise/*' '*/docs/*' '*/sim/*'\
'*/texpr.c' '*/runUdf.c' '*/schDbg.c' '*/syncIO.c' '*/tdbOs.c' '*/pushServer.c' '*/osLz4.c'\
'*/tbase64.c' '*/tbuffer.c' '*/tdes.c' '*/texception.c' '*/examples/*' '*/tidpool.c' '*/tmempool.c'\
'*/clientJniConnector.c' '*/clientTmqConnector.c' '*/version.cc' '*/branch/*'\
'*/tthread.c' '*/tversion.c' '*/ctgDbg.c' '*/schDbg.c' '*/qwDbg.c' '*/tencode.h' \
'*/shellAuto.c' '*/shellTire.c' '*/shellCommand.c'\
'*/sql.c' '*/sql.y' '*/smaSnapshot.c' '*/smaCommit.c' '*/debug/*' '*/tests/*'\
--rc lcov_branch_coverage=1 -o coverage.info
# generate result
echo "generate result"
lcov -l --rc lcov_branch_coverage=1 coverage.info | tee -a $TDENGINE_COVERAGE_REPORT
}
function stopTaosd {
print_color "$GREEN" "Stop taosd start"
systemctl stop taosd
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
while [ -n "$PID" ]
do
pkill -TERM -x taosd
sleep 1
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
done
print_color "$GREEN" "Stop tasod end"
}
function stopTaosadapter {
print_color "$GREEN" "Stop taosadapter"
systemctl stop taosadapter.service
PID=`ps -ef|grep -w taosadapter | grep -v grep | awk '{print $2}'`
while [ -n "$PID" ]
do
pkill -TERM -x taosadapter
sleep 1
PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'`
done
print_color "$GREEN" "Stop tasoadapter end"
}
WORK_DIR=/root
date >> $WORK_DIR/date.log
print_color "$GREEN" "Run local coverage test cases" | tee -a $WORK_DIR/date.log
stopTaosd
runTest
lcovFunc
date >> $WORK_DIR/date.log
print_color "$GREEN" "End of local coverage test cases" | tee -a $WORK_DIR/date.log
# Define coverage information files and output directories
COVERAGE_INFO="$TDENGINE_DIR/coverage.info"
OUTPUT_DIR="$WORK_DIR/coverage_report"
# Check whether the coverage information file exists
if [ ! -f "$COVERAGE_INFO" ]; then
echo "Error: $COVERAGE_INFO not found!"
exit 1
fi
# Generate local HTML reports
genhtml "$COVERAGE_INFO" --branch-coverage --function-coverage --output-directory "$OUTPUT_DIR"
# Check whether the report was generated successfully
if [ $? -eq 0 ]; then
echo "HTML coverage report generated successfully in $OUTPUT_DIR"
echo "For more details : "
echo "http://192.168.1.61:7000/"
else
echo "Error generating HTML coverage report"
exit 1
fi

View File

@ -29,6 +29,8 @@ exe:
# gcc $(CFLAGS) ./stmt2-get-fields.c -o $(ROOT)stmt2-get-fields $(LFLAGS)
# gcc $(CFLAGS) ./stmt2-nohole.c -o $(ROOT)stmt2-nohole $(LFLAGS)
gcc $(CFLAGS) ./stmt-crash.c -o $(ROOT)stmt-crash $(LFLAGS)
gcc $(CFLAGS) ./stmt-insert-dupkeys.c -o $(ROOT)stmt-insert-dupkeys $(LFLAGS)
gcc $(CFLAGS) ./stmt2-insert-dupkeys.c -o $(ROOT)stmt2-insert-dupkeys $(LFLAGS)
clean:
rm $(ROOT)batchprepare
@ -47,3 +49,5 @@ clean:
rm $(ROOT)stmt2-get-fields
rm $(ROOT)stmt2-nohole
rm $(ROOT)stmt-crash
rm $(ROOT)stmt-insert-dupkeys
rm $(ROOT)stmt2-insert-dupkeys

View File

@ -0,0 +1,234 @@
// compile with
// gcc -o stmt-insert-dupkeys stmt-insert-dupkeys.c -ltaos
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "taos.h"
#define NUMROWS 3
/**
* @brief execute sql only and ignore result set
*
* @param taos
* @param sql
*/
void executeSQL(TAOS *taos, const char *sql) {
TAOS_RES *res = taos_query(taos, sql);
int code = taos_errno(res);
if (code != 0) {
printf("%s\n", taos_errstr(res));
taos_free_result(res);
taos_close(taos);
exit(EXIT_FAILURE);
}
taos_free_result(res);
}
/**
* @brief exit program when error occur.
*
* @param stmt
* @param code
* @param msg
*/
void checkErrorCode(TAOS_STMT *stmt, int code, const char *msg) {
if (code != 0) {
printf("%s. error: %s\n", msg, taos_stmt_errstr(stmt));
exit(EXIT_FAILURE);
}
}
void prepareBindTags(TAOS_MULTI_BIND *tags) {
// bind table name and tags
char *location = "California.SanFrancisco";
int groupId = 2;
tags[0].buffer_type = TSDB_DATA_TYPE_BINARY;
tags[0].buffer_length = strlen(location);
tags[0].length = (int32_t *)&tags[0].buffer_length;
tags[0].buffer = location;
tags[0].is_null = NULL;
tags[1].buffer_type = TSDB_DATA_TYPE_INT;
tags[1].buffer_length = sizeof(int);
tags[1].length = (int32_t *)&tags[1].buffer_length;
tags[1].buffer = &groupId;
tags[1].is_null = NULL;
}
void prepareBindParams(TAOS_MULTI_BIND *params, int64_t *ts, float *current, int *voltage, float *phase) {
// is_null array
char is_null[NUMROWS] = {0};
// length array
int32_t int64Len[NUMROWS] = {sizeof(int64_t)};
int32_t floatLen[NUMROWS] = {sizeof(float)};
int32_t intLen[NUMROWS] = {sizeof(int)};
params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
params[0].buffer_length = sizeof(int64_t);
params[0].buffer = ts;
params[0].length = int64Len;
params[0].is_null = is_null;
params[0].num = NUMROWS;
params[1].buffer_type = TSDB_DATA_TYPE_FLOAT;
params[1].buffer_length = sizeof(float);
params[1].buffer = current;
params[1].length = floatLen;
params[1].is_null = is_null;
params[1].num = NUMROWS;
params[2].buffer_type = TSDB_DATA_TYPE_INT;
params[2].buffer_length = sizeof(int);
params[2].buffer = voltage;
params[2].length = intLen;
params[2].is_null = is_null;
params[2].num = NUMROWS;
params[3].buffer_type = TSDB_DATA_TYPE_FLOAT;
params[3].buffer_length = sizeof(float);
params[3].buffer = phase;
params[3].length = floatLen;
params[3].is_null = is_null;
params[3].num = NUMROWS;
}
/**
* @brief insert data using stmt API
*
* @param taos
*/
void insertData(TAOS *taos, int64_t *ts, float *current, int *voltage, float *phase) {
// init
TAOS_STMT *stmt = taos_stmt_init(taos);
// prepare
const char *sql = "INSERT INTO ? USING meters TAGS(?, ?) values(?, ?, ?, ?)";
int code = taos_stmt_prepare(stmt, sql, 0);
checkErrorCode(stmt, code, "failed to execute taos_stmt_prepare");
// bind table name and tags
TAOS_MULTI_BIND tags[2];
prepareBindTags(tags);
code = taos_stmt_set_tbname_tags(stmt, "d1001", tags);
checkErrorCode(stmt, code, "failed to execute taos_stmt_set_tbname_tags");
TAOS_MULTI_BIND params[4];
prepareBindParams(params, ts, current, voltage, phase);
code = taos_stmt_bind_param_batch(stmt, params); // bind batch
checkErrorCode(stmt, code, "failed to execute taos_stmt_bind_param_batch");
code = taos_stmt_add_batch(stmt); // add batch
checkErrorCode(stmt, code, "failed to execute taos_stmt_add_batch");
// execute
code = taos_stmt_execute(stmt);
checkErrorCode(stmt, code, "failed to execute taos_stmt_execute");
int affectedRows = taos_stmt_affected_rows(stmt);
printf("successfully inserted %d rows\n", affectedRows);
// close
(void)taos_stmt_close(stmt);
}
void insertDataInterlace(TAOS *taos, int64_t *ts, float *current, int *voltage, float *phase) {
// init with interlace mode
TAOS_STMT_OPTIONS op;
op.reqId = 0;
op.singleStbInsert = true;
op.singleTableBindOnce = true;
TAOS_STMT *stmt = taos_stmt_init_with_options(taos, &op);
// prepare
const char *sql = "INSERT INTO ? values(?, ?, ?, ?)";
int code = taos_stmt_prepare(stmt, sql, 0);
checkErrorCode(stmt, code, "failed to execute taos_stmt_prepare");
// bind table name and tags
TAOS_MULTI_BIND tags[2];
prepareBindTags(tags);
code = taos_stmt_set_tbname_tags(stmt, "d1001", tags);
checkErrorCode(stmt, code, "failed to execute taos_stmt_set_tbname_tags");
TAOS_MULTI_BIND params[4];
prepareBindParams(params, ts, current, voltage, phase);
code = taos_stmt_bind_param_batch(stmt, params); // bind batch
checkErrorCode(stmt, code, "failed to execute taos_stmt_bind_param_batch");
code = taos_stmt_add_batch(stmt); // add batch
checkErrorCode(stmt, code, "failed to execute taos_stmt_add_batch");
// execute
code = taos_stmt_execute(stmt);
checkErrorCode(stmt, code, "failed to execute taos_stmt_execute");
int affectedRows = taos_stmt_affected_rows(stmt);
printf("successfully inserted %d rows\n", affectedRows);
// close
(void)taos_stmt_close(stmt);
}
int main() {
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 6030);
if (taos == NULL) {
printf("failed to connect to server\n");
exit(EXIT_FAILURE);
}
executeSQL(taos, "DROP DATABASE IF EXISTS power");
executeSQL(taos, "CREATE DATABASE power");
executeSQL(taos, "USE power");
executeSQL(taos,
"CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), "
"groupId INT)");
// initial insert, expect insert 3 rows
int64_t ts0[] = {1648432611234, 1648432611345, 1648432611456};
float current0[] = {10.1f, 10.2f, 10.3f};
int voltage0[] = {216, 217, 218};
float phase0[] = {0.31f, 0.32f, 0.33f};
insertData(taos, ts0, current0, voltage0, phase0);
// insert with interlace mode, send non-duplicate ts, expect insert 3 overlapped rows
int64_t ts1[] = {1648432611234, 1648432611345, 1648432611456};
int voltage1[] = {219, 220, 221};
insertDataInterlace(taos, ts1, current0, voltage1, phase0);
// insert with interlace mode, send duplicate ts, expect insert 2 rows with dups merged
int64_t ts2[] = {1648432611678, 1648432611678, 1648432611789};
int voltage2[] = {222, 223, 224};
insertDataInterlace(taos, ts2, current0, voltage2, phase0);
// insert with interlace mode, send disordered rows, expect insert 3 sorted rows
int64_t ts3[] = {1648432611900, 1648432611890, 1648432611910};
int voltage3[] = {225, 226, 227};
insertDataInterlace(taos, ts3, current0, voltage3, phase0);
// insert with interlace mode, send disordered and duplicate rows, expect insert 2 sorted and dup-merged rows
int64_t ts4[] = {1648432611930, 1648432611920, 1648432611930};
int voltage4[] = {228, 229, 230};
insertDataInterlace(taos, ts4, current0, voltage4, phase0);
taos_close(taos);
taos_cleanup();
// final results
// taos> select * from d1001;
// ts | current | voltage | phase |
// ======================================================================================
// 2022-03-28 09:56:51.234 | 10.1000004 | 219 | 0.3100000 |
// 2022-03-28 09:56:51.345 | 10.1999998 | 220 | 0.3200000 |
// 2022-03-28 09:56:51.456 | 10.3000002 | 221 | 0.3300000 |
// 2022-03-28 09:56:51.678 | 10.1999998 | 223 | 0.3200000 |
// 2022-03-28 09:56:51.789 | 10.3000002 | 224 | 0.3300000 |
// 2022-03-28 09:56:51.890 | 10.1999998 | 226 | 0.3200000 |
// 2022-03-28 09:56:51.900 | 10.1000004 | 225 | 0.3100000 |
// 2022-03-28 09:56:51.910 | 10.3000002 | 227 | 0.3300000 |
// 2022-03-28 09:56:51.920 | 10.1999998 | 229 | 0.3200000 |
// 2022-03-28 09:56:51.930 | 10.3000002 | 230 | 0.3300000 |
// Query OK, 10 row(s) in set (0.005083s)
}

View File

@ -0,0 +1,235 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "taos.h"
int CTB_NUMS = 3;
int ROW_NUMS = 3;
void do_query(TAOS* taos, const char* sql) {
TAOS_RES* result = taos_query(taos, sql);
int code = taos_errno(result);
if (code) {
printf("failed to query: %s, reason:%s\n", sql, taos_errstr(result));
taos_free_result(result);
return;
}
taos_free_result(result);
}
void createdb(TAOS* taos) {
do_query(taos, "drop database if exists db");
do_query(taos, "create database db");
do_query(taos, "create stable db.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))");
do_query(taos, "use db");
}
#define INIT(tbs, ts, ts_len, b, b_len, tags, paramv) \
do { \
/* tbname */ \
tbs = (char**)malloc(CTB_NUMS * sizeof(char*)); \
for (int i = 0; i < CTB_NUMS; i++) { \
tbs[i] = (char*)malloc(sizeof(char) * 20); \
sprintf(tbs[i], "ctb_%d", i); \
} \
/* col params */ \
ts = (int64_t**)malloc(CTB_NUMS * sizeof(int64_t*)); \
b = (char**)malloc(CTB_NUMS * sizeof(char*)); \
ts_len = (int*)malloc(ROW_NUMS * sizeof(int)); \
b_len = (int*)malloc(ROW_NUMS * sizeof(int)); \
for (int i = 0; i < ROW_NUMS; i++) { \
ts_len[i] = sizeof(int64_t); \
b_len[i] = 1; \
} \
for (int i = 0; i < CTB_NUMS; i++) { \
ts[i] = (int64_t*)malloc(ROW_NUMS * sizeof(int64_t)); \
b[i] = (char*)malloc(ROW_NUMS * sizeof(char)); \
for (int j = 0; j < ROW_NUMS; j++) { \
ts[i][j] = 1591060628000 + j; \
b[i][j] = (char)('a' + j); \
} \
} \
/*tag params */ \
int t1 = 0; \
int t1len = sizeof(int); \
int t2len = 3; \
/* bind params */ \
paramv = (TAOS_STMT2_BIND**)malloc(CTB_NUMS * sizeof(TAOS_STMT2_BIND*)); \
tags = (TAOS_STMT2_BIND**)malloc(CTB_NUMS * sizeof(TAOS_STMT2_BIND*)); \
for (int i = 0; i < CTB_NUMS; i++) { \
/* create tags */ \
tags[i] = (TAOS_STMT2_BIND*)malloc(2 * sizeof(TAOS_STMT2_BIND)); \
tags[i][0] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_INT, &t1, &t1len, NULL, 0}; \
tags[i][1] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_BINARY, "after", &t2len, NULL, 0}; \
/* create col params */ \
paramv[i] = (TAOS_STMT2_BIND*)malloc(2 * sizeof(TAOS_STMT2_BIND)); \
paramv[i][0] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_TIMESTAMP, &ts[i][0], &ts_len[0], NULL, ROW_NUMS}; \
paramv[i][1] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_BINARY, &b[i][0], &b_len[0], NULL, ROW_NUMS}; \
} \
} while (0)
#define UINIT(tbs, ts, ts_len, b, b_len, tags, paramv) \
do { \
for (int i = 0; i < CTB_NUMS; i++) { \
free(tbs[i]); \
} \
free(tbs); \
for (int i = 0; i < CTB_NUMS; i++) { \
free(ts[i]); \
free(b[i]); \
} \
free(ts); \
free(b); \
free(ts_len); \
free(b_len); \
for (int i = 0; i < CTB_NUMS; i++) { \
free(tags[i]); \
free(paramv[i]); \
} \
free(tags); \
free(paramv); \
} while (0)
void insert(TAOS* taos, char **tbs, TAOS_STMT2_BIND **tags, TAOS_STMT2_BIND **paramv, const char* sql)
{
clock_t start, end;
double cpu_time_used;
TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
TAOS_STMT2 *stmt = taos_stmt2_init(taos, &option);
int code = taos_stmt2_prepare(stmt, sql, 0);
if (code != 0) {
printf("failed to execute taos_stmt2_prepare. error:%s\n", taos_stmt2_error(stmt));
taos_stmt2_close(stmt);
exit(EXIT_FAILURE);
}
// bind
start = clock();
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, tags, paramv};
if (taos_stmt2_bind_param(stmt, &bindv, -1)) {
printf("failed to execute taos_stmt2_bind_param statement.error:%s\n", taos_stmt2_error(stmt));
taos_stmt2_close(stmt);
exit(EXIT_FAILURE);
}
end = clock();
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("stmt2-bind [%s] insert Time used: %f seconds\n", sql, cpu_time_used);
start = clock();
// exec
if (taos_stmt2_exec(stmt, NULL)) {
printf("failed to execute taos_stmt2_exec statement.error:%s\n", taos_stmt2_error(stmt));
taos_stmt2_close(stmt);
exit(EXIT_FAILURE);
}
end = clock();
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("stmt2-exec [%s] insert Time used: %f seconds\n", sql, cpu_time_used);
taos_stmt2_close(stmt);
}
void insert_dist(TAOS* taos, const char *sql) {
char **tbs, **b;
int64_t **ts;
int *ts_len, *b_len;
TAOS_STMT2_BIND **paramv, **tags;
INIT(tbs, ts, ts_len, b, b_len, tags, paramv);
insert(taos, tbs, tags, paramv, sql);
UINIT(tbs, ts, ts_len, b, b_len, tags, paramv);
}
void insert_dup_rows(TAOS* taos, const char *sql) {
char **tbs, **b;
int64_t **ts;
int *ts_len, *b_len;
TAOS_STMT2_BIND **paramv, **tags;
INIT(tbs, ts, ts_len, b, b_len, tags, paramv);
// insert duplicate rows
for (int i = 0; i < CTB_NUMS; i++) {
for (int j = 0; j < ROW_NUMS; j++) {
ts[i][j] = 1591060628000;
b[i][j] = (char)('x' + j);
}
}
for (int i = 0; i < CTB_NUMS; i++) {
paramv[i][0] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_TIMESTAMP, &ts[i][0], &ts_len[0], NULL, ROW_NUMS};
paramv[i][1] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_BINARY, &b[i][0], &b_len[0], NULL, ROW_NUMS};
}
insert(taos, tbs, tags, paramv, sql);
UINIT(tbs, ts, ts_len, b, b_len, tags, paramv);
}
void insert_dup_tables(TAOS* taos, const char *sql) {
char **tbs, **b;
int64_t **ts;
int *ts_len, *b_len;
TAOS_STMT2_BIND **paramv, **tags;
INIT(tbs, ts, ts_len, b, b_len, tags, paramv);
for (int i = 0; i < CTB_NUMS; i++) {
sprintf(tbs[i], "ctb_%d", i % 2);
}
for (int i = 0; i < CTB_NUMS; i++) {
paramv[i][0] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_TIMESTAMP, &ts[i][0], &ts_len[0], NULL, ROW_NUMS};
paramv[i][1] = (TAOS_STMT2_BIND){TSDB_DATA_TYPE_BINARY, &b[i][0], &b_len[0], NULL, ROW_NUMS};
}
insert(taos, tbs, tags, paramv, sql);
UINIT(tbs, ts, ts_len, b, b_len, tags, paramv);
}
int main() {
TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
if (!taos) {
printf("failed to connect to db, reason:%s\n", taos_errstr(taos));
exit(EXIT_FAILURE);
}
createdb(taos);
// insert distinct rows
insert_dist(taos, "insert into db.? using db.stb tags(?,?)values(?,?)");
// insert duplicate rows
insert_dup_rows(taos, "insert into db.? values(?,?)");
// insert duplicate tables
insert_dup_tables(taos, "insert into db.? values(?,?)");
taos_close(taos);
taos_cleanup();
}
// final results
// taos> select * from ctb_0;
// ts | b |
// =========================================
// 2020-06-02 09:17:08.000 | z |
// 2020-06-02 09:17:08.001 | b |
// 2020-06-02 09:17:08.002 | c |
// Query OK, 3 row(s) in set (0.003975s)
//
// taos> select * from ctb_1;
// ts | b |
// =========================================
// 2020-06-02 09:17:08.000 | z |
// 2020-06-02 09:17:08.001 | b |
// 2020-06-02 09:17:08.002 | c |
// Query OK, 3 row(s) in set (0.007241s)
// taos> select * from ctb_2;
// ts | b |
// =========================================
// 2020-06-02 09:17:08.000 | z |
// 2020-06-02 09:17:08.001 | b |
// 2020-06-02 09:17:08.002 | c |
// Query OK, 3 row(s) in set (0.005443s)

View File

@ -5,9 +5,9 @@
#include <unistd.h>
#include "taos.h"
int CTB_NUMS = 1000;
int ROW_NUMS = 10;
int CYC_NUMS = 5;
int CTB_NUMS = 2;
int ROW_NUMS = 2;
int CYC_NUMS = 2;
void do_query(TAOS* taos, const char* sql) {
TAOS_RES* result = taos_query(taos, sql);
@ -57,7 +57,7 @@ void do_stmt(TAOS* taos, const char* sql) {
return;
}
int fieldNum = 0;
TAOS_FIELD_STB* pFields = NULL;
TAOS_FIELD_ALL* pFields = NULL;
// code = taos_stmt2_get_stb_fields(stmt, &fieldNum, &pFields);
// if (code != 0) {
// printf("failed get col,ErrCode: 0x%x, ErrMessage: %s.\n", code, taos_stmt2_error(stmt));
@ -74,7 +74,7 @@ void do_stmt(TAOS* taos, const char* sql) {
for (int i = 0; i < CTB_NUMS; i++) {
tbs[i] = (char*)malloc(sizeof(char) * 20);
sprintf(tbs[i], "ctb_%d", i);
createCtb(taos, tbs[i]);
// createCtb(taos, tbs[i]);
}
for (int r = 0; r < CYC_NUMS; r++) {
// col params
@ -138,7 +138,24 @@ void do_stmt(TAOS* taos, const char* sql) {
end = clock();
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("stmt2-exec [%s] insert Time used: %f seconds\n", sql, cpu_time_used);
for (int i = 0; i < CTB_NUMS; i++) {
free(tags[i]);
free(paramv[i]);
free(ts[i]);
free(b[i]);
}
free(ts);
free(b);
free(ts_len);
free(b_len);
free(paramv);
free(tags);
}
for (int i = 0; i < CTB_NUMS; i++) {
free(tbs[i]);
}
free(tbs);
// taos_stmt2_free_fields(stmt, pFields);
taos_stmt2_close(stmt);
@ -200,10 +217,9 @@ int main() {
exit(1);
}
sleep(3);
do_stmt(taos, "insert into db.stb(tbname,ts,b,t1,t2) values(?,?,?,?,?)");
// do_stmt(taos, "insert into db.? using db.stb tags(?,?)values(?,?)");
do_taosc(taos);
// do_taosc(taos);
taos_close(taos);
taos_cleanup();
}

View File

@ -44,7 +44,7 @@ if $data20 != @ Time Range: [-9223372036854775808, 9223372036854775807]@ th
endi
sql select * from tb1 where fbool in (0, 3);
if $rows != 5 then
if $rows != 3 then
return -1
endi
@ -69,7 +69,7 @@ if $rows != 10 then
endi
sql select * from st1 where tbool in (0, 3);
if $rows != 15 then
if $rows != 5 then
return -1
endi

View File

@ -254,5 +254,7 @@ if $rows <= 0 then
return -1
endi
system taos -P7100 -d db -s " show create table db.t0"
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT

View File

@ -398,4 +398,204 @@ endi
print ===== step5 over
print ===== step6
sql drop database if exists test6;
sql create database test7 vgroups 1;
sql use test7;
sql create stable st(ts timestamp, a int, b int , c int, d double) tags(ta int,tb int,tc int);
sql create table ts1 using st tags(1,1,1);
sql create stream streams8 trigger at_once IGNORE EXPIRED 0 IGNORE UPDATE 0 watermark 1d into streamt8 as select _wstart, count(*) c1 from st interval(10s);
sql create stream streams9 trigger at_once IGNORE EXPIRED 0 IGNORE UPDATE 0 watermark 1d into streamt9 as select _wstart, count(*) c1 from st partition by tbname interval(10s);
run tsim/stream/checkTaskStatus.sim
$loop_count = 0
loop7:
$loop_count = $loop_count + 1
if $loop_count == 40 then
return -1
endi
sleep 500
sql select status, * from information_schema.ins_streams where status != "ready";
if $rows != 0 then
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
print $data20 $data21 $data22 $data23 $data24
print $data30 $data31 $data32 $data33 $data34
print $data40 $data41 $data42 $data43 $data44
print $data50 $data51 $data52 $data53 $data54
goto loop7
endi
sql pause stream streams8;
sql pause stream streams9;
sql pause stream streams8;
sql pause stream streams9;
sleep 1000
sql pause stream streams8;
sql pause stream streams9;
sleep 1000
$loop_count = 0
loop80:
$loop_count = $loop_count + 1
if $loop_count == 40 then
print pause stream failed
goto end_step_6
endi
sleep 1000
sql select status, * from information_schema.ins_stream_tasks where status != "paused";
if $rows != 2 then
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
print $data20 $data21 $data22 $data23 $data24
print $data30 $data31 $data32 $data33 $data34
print $data40 $data41 $data42 $data43 $data44
print $data50 $data51 $data52 $data53 $data54
goto loop80
endi
$loop_count = 0
loop8:
$loop_count = $loop_count + 1
if $loop_count == 40 then
return -1
endi
sleep 1000
sql select status, * from information_schema.ins_streams where status == "paused";
if $rows != 2 then
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
print $data20 $data21 $data22 $data23 $data24
print $data30 $data31 $data32 $data33 $data34
print $data40 $data41 $data42 $data43 $data44
print $data50 $data51 $data52 $data53 $data54
goto loop8
endi
sql resume stream streams8;
sql resume stream streams9;
sql resume stream streams8;
sql resume stream streams9;
sleep 1000
sql resume stream streams8;
sql resume stream streams9;
sleep 1000
$loop_count = 0
loop90:
$loop_count = $loop_count + 1
if $loop_count == 40 then
print pause stream failed
goto end_step_6
endi
sleep 1000
sql select status, * from information_schema.ins_stream_tasks where status == "paused";
if $rows != 0 then
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
print $data20 $data21 $data22 $data23 $data24
print $data30 $data31 $data32 $data33 $data34
print $data40 $data41 $data42 $data43 $data44
print $data50 $data51 $data52 $data53 $data54
goto loop90
endi
$loop_count = 0
loop9:
$loop_count = $loop_count + 1
if $loop_count == 40 then
return -1
endi
sleep 1000
sql select status, * from information_schema.ins_streams where status != "paused";
if $rows != 2 then
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
print $data20 $data21 $data22 $data23 $data24
print $data30 $data31 $data32 $data33 $data34
print $data40 $data41 $data42 $data43 $data44
print $data50 $data51 $data52 $data53 $data54
goto loop9
endi
run tsim/stream/checkTaskStatus.sim
sql insert into ts1 values(1648791213001,1,12,3,1.0);
$loop_count = 0
loop11:
$loop_count = $loop_count + 1
if $loop_count == 40 then
return -1
endi
sleep 1000
sql select * from streamt8;
if $rows != 1 then
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
print $data20 $data21 $data22 $data23 $data24
print $data30 $data31 $data32 $data33 $data34
print $data40 $data41 $data42 $data43 $data44
print $data50 $data51 $data52 $data53 $data54
goto loop11
endi
sql select * from streamt9;
if $rows != 1 then
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
print $data20 $data21 $data22 $data23 $data24
print $data30 $data31 $data32 $data33 $data34
print $data40 $data41 $data42 $data43 $data44
print $data50 $data51 $data52 $data53 $data54
goto loop11
endi
end_step_6:
print ===== step6 over
system sh/stop_dnodes.sh

View File

@ -41,8 +41,9 @@ class TDTestCase:
]
self.time_unit = ['b','u','a','s','m','h','d','w']
self.symbol = ['+','-','*','/']
self.error_values = [1.5,'abc','"abc"','!@','today()']
self.error_values = ['abc','"abc"','!@','today()']
self.db_percision = ['ms','us','ns']
self.test_values = [1.5, 10]
def tbtype_check(self,tb_type):
if tb_type == 'normal table' or tb_type == 'child table':
tdSql.checkRows(len(self.values_list))
@ -71,6 +72,9 @@ class TDTestCase:
self.tbtype_check(tb_type)
for i in range(len(self.values_list)):
tdSql.checkData(i,0,None)
for param in self.test_values:
tdSql.query(f'select now() {symbol}{param} from {tbname}')
tdSql.query(f'select 1 {symbol}{param} from {tbname}')
def now_check_ntb(self):
for time_unit in self.db_percision:

View File

@ -18,7 +18,7 @@ class TDTestCase:
self.today_ts = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d").timestamp()
self.today_ts_ns = 0
self.time_unit = ['b','u','a','s','m','h','d','w']
self.error_param = ['1.5','abc','!@#','"abc"','today()']
self.error_param = ['abc','!@#','"abc"','today()']
self.arithmetic_operators = ['+','-','*','/']
self.relational_operator = ['<','<=','=','>=','>']
# prepare data

View File

@ -0,0 +1,347 @@
from wsgiref.headers import tspecials
from util.log import *
from util.cases import *
from util.sql import *
from util.common import tdCom
import numpy as np
class TDTestCase:
def init(self, conn, logSql, replicaVar=1):
self.replicaVar = int(replicaVar)
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
self.dbname = "db"
self.rowNum = 10
self.ts = 1537146000000
# test in/not in contidion with invalid value
def ts5757(self):
tdSql.execute(f"create database if not exists {self.dbname}")
tdSql.execute(f"DROP STABLE IF EXISTS {self.dbname}.super_t1;")
tdSql.execute(f"DROP TABLE IF EXISTS {self.dbname}.t1;")
tdSql.execute(f"CREATE STABLE IF NOT EXISTS {self.dbname}.super_t1(time TIMESTAMP, c0 BIGINT UNSIGNED) TAGS (location BINARY(64))")
tdSql.execute(f"CREATE TABLE {self.dbname}.t1 USING {self.dbname}.super_t1 TAGS ('ek')")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c0) VALUES (1641024000000, 1);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c0) VALUES (1641024005000, 2);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c0) VALUES (1641024010000, NULL);")
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NOT NULL AND c0 IN (-1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NULL AND c0 IN (-1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NOT NULL AND c0 IN (-1, 1);")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NULL AND c0 IN (2, -1, 1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NOT NULL AND c0 NOT IN (-1);")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NULL AND c0 NOT IN (-1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NULL AND c0 NOT IN (3);")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NOT NULL AND c0 NOT IN (-1, 1);")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NULL AND c0 NOT IN (2, -1, 1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE (c0 IS NULL AND c0 IN (-1)) or c0 in(1)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NOT NULL OR c0 IN (-1);")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NULL OR c0 IN (-1);")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NOT NULL OR c0 IN (-1, 1);")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NULL OR c0 IN (2, -1, 1);")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NOT NULL OR c0 NOT IN (-1);")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NULL OR c0 NOT IN (-1);")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NULL OR c0 NOT IN (3);")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NOT NULL OR c0 NOT IN (-1, 1);")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NOT NULL OR c0 NOT IN (-1);")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NULL OR c0 NOT IN (2, -1, 1);")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE ((c0 is NULL) AND (c0 in (-1)) )")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE ((c0 in (-1)) AND (c0 is NULL) )")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE ((c0 in (-1)) AND (c0 is NULL) ) OR c0 in(1)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IN (-1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IS NOT NULL;")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IN (-1) or c0 in(1);")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IN (1) or c0 in(-1);")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IN (-1) or c0 in(-1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IN (-1) and c0 in(1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IN (1) and c0 in(-1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM {self.dbname}.t1 WHERE c0 IN (-1) and c0 in(-1);")
tdSql.checkRows(0)
def ts5760(self):
tdSql.execute(f"create database if not exists {self.dbname}")
tdSql.execute(f"DROP TABLE IF EXISTS {self.dbname}.t1;")
tdSql.execute(f"CREATE TABLE {self.dbname}.t1( time TIMESTAMP, c0 INT);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c0) VALUES (1641024000000, 1);")
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE (time - c0) > 0;")
tdSql.checkRows(1)
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE (time + c0) > 0;")
tdSql.checkRows(1)
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE (-(- c0)) > 0;")
tdSql.checkRows(1)
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE -(- c0) > 0;")
tdSql.checkRows(1)
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE -(- c0) < 0;")
tdSql.checkRows(0)
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE -(- c0) = 0;")
tdSql.checkRows(0)
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE (- c0) > 0;")
tdSql.checkRows(0)
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE (- c0) < 0;")
tdSql.checkRows(1)
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE (time + (- c0)) > 0;")
tdSql.checkRows(1)
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE (time + (- c0)) > 0;")
tdSql.checkRows(1)
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE (time - (- (- c0)) ) > 0;")
tdSql.checkRows(1)
tdSql.query(f"SELECT time, c0 FROM {self.dbname}.t1 WHERE (time + (-(- c0))) > 0;")
tdSql.checkRows(1)
def ts5758(self):
tdSql.execute(f"create database if not exists {self.dbname}")
tdSql.execute(f"DROP TABLE IF EXISTS {self.dbname}.t1;")
tdSql.execute(f"CREATE TABLE {self.dbname}.t1( time TIMESTAMP, c1 BIGINT);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c1) VALUES (1641024000000, 0);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c1) VALUES (1641024000001, 1);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c1) VALUES (1641024000002, 2);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c1) VALUES (1641024000003, 3);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c1) VALUES (1641024000004, 4);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c1) VALUES (1641024000005, 5);")
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1) AND time BETWEEN (1741024000000) AND (1741024000000);")
tdSql.checkRows(0)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time BETWEEN (1741024000000) AND (1741024000000) AND time IN (1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1) and time BETWEEN (1741024000000) AND (1741024000000) AND time IN (1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1641024000000) and time BETWEEN (1741024000000) AND (1741024000000) AND time IN (1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1) AND time BETWEEN (1641024000000) AND (1741024000000);")
tdSql.checkRows(0)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1641024000001) AND time BETWEEN (1641024000000) AND (1741024000000);")
tdSql.checkRows(1)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1641024000001, 1641024000002, 1641024000003) AND time BETWEEN (1641024000000) AND (1741024000000);")
tdSql.checkRows(3)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1641024000001, 1641024000002, 1641024000005) AND time BETWEEN (1641024000000) AND (1641024000004);")
tdSql.checkRows(2)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1) OR time = 1741024000000;")
tdSql.checkRows(0)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time = 1741024000000 OR time IN (1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1, 2, 3) OR time BETWEEN (1641024000000) and (1741024000000);")
tdSql.checkRows(6)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1, 2, 3) OR time = 1641024000000;")
tdSql.checkRows(1)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time = 1641024000001 OR time BETWEEN (1641024000000) and (1641024000002);")
tdSql.checkRows(3)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time = 1641024000004 OR time BETWEEN (1641024000000) and (1641024000002);")
tdSql.checkRows(4)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time = 1641024000001 OR time = 1741024000000;")
tdSql.checkRows(1)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1641024000001, 1641024000002) OR time = 1741024000000;")
tdSql.checkRows(2)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE time IN (1641024000001, 1641024000002) OR time BETWEEN (1641024000000) and (1741024000000);")
tdSql.checkRows(6)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time = 1641024000004 OR time BETWEEN (1641024000000) and (1641024000002)) and time in(1);")
tdSql.checkRows(0)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time = 1641024000004 OR time BETWEEN (1641024000000) and (1641024000002)) and time in(1641024000004, 1641024000002);")
tdSql.checkRows(2)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time = 1641024000004 OR time BETWEEN (1641024000000) and (1641024000002)) or time in(1);")
tdSql.checkRows(4)
def ts5759(self):
tdSql.execute(f"create database if not exists {self.dbname}")
tdSql.execute(f"DROP TABLE IF EXISTS {self.dbname}.t1;")
tdSql.execute(f"CREATE TABLE {self.dbname}.t1( time TIMESTAMP, c1 BIGINT);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c1) VALUES (1641024000000, 0);")
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time BETWEEN 1641024000000 AND 1641024000001)")
tdSql.checkRows(1)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time BETWEEN 1641024000000 AND 1641024000001) OR (1 < 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time BETWEEN 1641024000000 AND 1641024000001) OR (3 < 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time BETWEEN 1641024000000 AND 1641024000001) and (1 < 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time BETWEEN 1641024000000 AND 1641024000001) OR (1 > 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time BETWEEN 1641024000000 AND 1641024000001) and (1 > 2)")
tdSql.checkRows(0)
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c1) VALUES (1641024000001, 1);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1(time, c1) VALUES (1641024000002, 2);")
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time BETWEEN 1641024000000 AND 1641024000001) OR (1 < 2)")
tdSql.checkRows(3)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time BETWEEN 1641024000000 AND 1641024000001) OR (1 > 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT c1 FROM {self.dbname}.t1 WHERE (time BETWEEN 1641024000000 AND 1641024000001) and (1 < 2)")
tdSql.checkRows(2)
def operOnTime(self):
tdSql.execute(f"create database if not exists {self.dbname}")
tdSql.execute(f"DROP TABLE IF EXISTS {self.dbname}.t1;")
tdSql.execute(f"CREATE TABLE {self.dbname}.t1( ts TIMESTAMP, c0 INT, c1 INT UNSIGNED, \
c2 BIGINT, c3 BIGINT UNSIGNED, c4 SMALLINT, c5 SMALLINT UNSIGNED, c6 TINYINT, c7 TINYINT UNSIGNED);")
tdSql.execute(f"INSERT INTO {self.dbname}.t1 VALUES (1641024000001, 1, 1, 1, 1, 1, 1, 1, 1);")
columns = ["c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7"]
for col in columns:
tdLog.debug(f"oper on time test, {col} start ...")
tdSql.query(f"SELECT ts, ts+1, ts+{col}, ts+(-{col}) FROM {self.dbname}.t1")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 1641024000001)
tdSql.checkData(0, 1, 1641024000002)
tdSql.checkData(0, 2, 1641024000002)
tdSql.checkData(0, 3, 1641024000000)
tdSql.query(f"SELECT ts, ts+1, ts+{col}, ts+(-{col}) FROM {self.dbname}.t1 where (ts-(-{col})) > 0")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 1641024000001)
tdSql.checkData(0, 1, 1641024000002)
tdSql.checkData(0, 2, 1641024000002)
tdSql.checkData(0, 3, 1641024000000)
tdSql.query(f"SELECT ts, ts-1, ts-{col}, ts-(-{col}) FROM {self.dbname}.t1")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 1641024000001)
tdSql.checkData(0, 1, 1641024000000)
tdSql.checkData(0, 2, 1641024000000)
tdSql.checkData(0, 3, 1641024000002)
tdSql.query(f"SELECT ts, ts+true, ts-true, ts-false, ts+false FROM {self.dbname}.t1")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 1641024000001)
tdSql.checkData(0, 1, 1641024000002)
tdSql.checkData(0, 2, 1641024000000)
tdSql.checkData(0, 3, 1641024000001)
tdSql.checkData(0, 4, 1641024000001)
tdSql.execute(f"DROP TABLE IF EXISTS {self.dbname}.t2;")
tdSql.execute(f"CREATE TABLE {self.dbname}.t2( ts TIMESTAMP, c1 float, c2 double);")
tdSql.execute(f"INSERT INTO {self.dbname}.t2(ts, c1, c2) VALUES (1641024000001, 1.0, 1.0);")
columns = ["c1", "c2"]
for col in columns:
tdSql.query(f"SELECT ts, ts+{col}, ts+(-{col}), ts-{col}, ts-(-{col}) FROM {self.dbname}.t2")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 1641024000001)
tdSql.checkData(0, 1, 1641024000002)
tdSql.checkData(0, 2, 1641024000000)
tdSql.checkData(0, 3, 1641024000000)
tdSql.checkData(0, 4, 1641024000002)
tdSql.query(f"SELECT ts, ts+{col}, ts+(-{col}), ts-{col}, ts-(-{col}) FROM {self.dbname}.t2 where (ts-(-{col})) > 0")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 1641024000001)
tdSql.checkData(0, 1, 1641024000002)
tdSql.checkData(0, 2, 1641024000000)
tdSql.checkData(0, 3, 1641024000000)
tdSql.checkData(0, 4, 1641024000002)
tdSql.query(f"SELECT ts, cast(ts+{col} as bigint), cast(ts+(-{col}) as bigint), cast(ts-{col} as bigint),\
cast(ts-(-{col}) as bigint) FROM {self.dbname}.t2")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 1641024000001)
tdSql.checkData(0, 1, 1641024000002)
tdSql.checkData(0, 2, 1641024000000)
tdSql.checkData(0, 3, 1641024000000)
tdSql.checkData(0, 4, 1641024000002)
tdSql.query(f"SELECT sum(ts + c1), sum(ts+c2) from {self.dbname}.t2")
tdSql.checkData(0, 0, 1641024000002)
tdSql.checkData(0, 1, 1641024000002)
tdSql.query(f"SELECT sum(ts * c1), sum(ts*c2) from {self.dbname}.t2")
tdSql.checkData(0, 0, 1641024000001)
tdSql.checkData(0, 1, 1641024000001)
tdSql.query(f"SELECT sum(ts / c1), sum(ts/c2) from {self.dbname}.t2")
tdSql.checkData(0, 0, 1641024000001)
tdSql.checkData(0, 1, 1641024000001)
tdSql.execute(f"INSERT INTO {self.dbname}.t2(ts, c1, c2) VALUES (1641024000002, 2.0, 2.0);")
tdSql.query(f"SELECT sum(ts + c1), sum(ts+c2) from {self.dbname}.t2")
tdSql.checkData(0, 0, 3282048000006)
tdSql.checkData(0, 1, 3282048000006)
tdSql.query(f"SELECT sum(ts - c1), sum(ts-c2) from {self.dbname}.t2")
tdSql.checkData(0, 0, 3282048000000)
tdSql.checkData(0, 1, 3282048000000)
tdSql.query(f"SELECT sum(ts * c1), sum(ts*c2) from {self.dbname}.t2")
tdSql.checkData(0, 0, 4923072000005)
tdSql.checkData(0, 1, 4923072000005)
tdSql.query(f"SELECT ts / c1, ts/c2 from {self.dbname}.t2 order by ts")
tdSql.checkData(0, 0, 1641024000001)
tdSql.checkData(0, 1, 1641024000001)
tdSql.checkData(1, 0, 820512000001)
tdSql.checkData(1, 1, 820512000001)
tdSql.query(f"SELECT sum(ts / c1), sum(ts/c2) from {self.dbname}.t2")
tdSql.checkData(0, 0, 2461536000002)
tdSql.checkData(0, 1, 2461536000002)
# data overflow
tdSql.query(f"SELECT ts + 9223372036854775807 from {self.dbname}.t2 order by ts")
tdSql.query(f"SELECT ts - 9223372036854775808 from {self.dbname}.t2 order by ts")
tdSql.query(f"SELECT ts + 8223372036854775807 from {self.dbname}.t2 order by ts")
tdSql.query(f"SELECT ts - 8223372036854775808 from {self.dbname}.t2 order by ts")
def run(self):
dbname = "db"
tdSql.prepare()
tdSql.execute(f"create database if not exists {self.dbname}")
self.ts5757()
self.ts5760()
self.ts5758()
self.ts5759()
self.operOnTime()
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())

View File

@ -78,7 +78,7 @@ class TDTestCase:
)
# sqls.extend( f"select sum( {un_num_col} + {un_num_col_2} ) from {tbanme} " for un_num_col_2 in UN_NUM_COL )
sqls.extend( f"select sum( {num_col} + {ts_col} ) from {DBNAME}.{tbanme} " for num_col in NUM_COL for ts_col in TS_TYPE_COL)
#sqls.extend( f"select sum( {num_col} + {ts_col} ) from {DBNAME}.{tbanme} " for num_col in NUM_COL for ts_col in TS_TYPE_COL)
sqls.extend(
(
f"select sum() from {DBNAME}.{tbanme} ",

View File

@ -0,0 +1,150 @@
import taos
from util.log import *
from util.sql import *
from util.cases import *
from util.dnodes import *
from util.common import *
class TDTestCase:
updatecfgDict = {'filterScalarMode':1}
def init(self, conn, logSql, replicaVar=1):
self.replicaVar = int(replicaVar)
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor(), True)
self.dbname = 'db'
self.stbname = 'st'
def prepareData(self):
# db
tdSql.execute(f"create database db;")
tdSql.execute(f"use db")
# super tableUNSIGNED
tdSql.execute("CREATE TABLE st( time TIMESTAMP, c1 BIGINT, c2 smallint, c3 double, c4 int UNSIGNED, c5 bool, c6 binary(32), c7 nchar(32)) tags(t1 binary(32), t2 nchar(32))")
tdSql.execute("create table t1 using st tags('1', '1.7')")
tdSql.execute("create table t2 using st tags('0', '')")
tdSql.execute("create table t3 using st tags('1', 'er')")
# create index for all tags
tdSql.execute("INSERT INTO t1 VALUES (1641024000000, 1, 1, 1, 1, 1, '1', '1.7')")
tdSql.execute("INSERT INTO t1 VALUES (1641024000001, 0, 0, 1.7, 0, 0, '0', '')")
tdSql.execute("INSERT INTO t1 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
tdSql.execute("INSERT INTO t2 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
tdSql.execute("INSERT INTO t3 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
tdSql.execute("CREATE TABLE stt( time TIMESTAMP, c1 BIGINT, c2 timestamp, c3 int, c4 int UNSIGNED, c5 bool, c6 binary(32), c7 nchar(32)) tags(t1 binary(32), t2 nchar(32))")
tdSql.execute("create table tt1 using stt tags('1', '1.7')")
# create index for all tags
tdSql.execute("INSERT INTO tt1 VALUES (1641024000000, 9223372036854775807, 1641024000000, 1, 1, 1, '1', '1.7')")
def check(self):
tdSql.query(f"SELECT * FROM tt1 WHERE c1 in (1.7, 9223372036854775803, '')")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM tt1 WHERE c1 = 9223372036854775803")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c1 = 1.7")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c1 in (1.7, 2)")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c1 not in (1.7, 2)")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM t1 WHERE c2 = 1.7")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c2 in (1.7, 2)")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c2 not in (1.7, 2)")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM t1 WHERE c3 = 1.7")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c3 in (1.7, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c3 not in (1.7, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c4 = 1.7")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c4 in (1.7, 2)")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c4 not in (1.7, 2)")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM t1 WHERE c5 = 1.7")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c5 in (1.7, 2)")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c5 not in (1.7, 2)")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM t1 WHERE c6 = 1.7")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c6 in (1.7, 2)")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (1.7, 2)")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM t1 WHERE c6 = 1")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c6 in (1, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (1, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c6 = 0")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c6 in (0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (0, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (0, 2, 'sef')")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c7 = 1.7")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c7 in (1.7, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c7 not in (1.7, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c7 = 0")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c7 in (0, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c7 not in (0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c7 = ''")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c7 in ('', 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c7 not in ('', 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM st WHERE t2 in ('', 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t2 not in ('', 2)")
tdSql.checkRows(4)
tdSql.query(f"SELECT * FROM st WHERE t1 in ('d343', 0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t1 in (0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t1 not in (0, 2)")
tdSql.checkRows(4)
def run(self):
self.prepareData()
self.check()
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())

View File

@ -0,0 +1,149 @@
import taos
from util.log import *
from util.sql import *
from util.cases import *
from util.dnodes import *
from util.common import *
class TDTestCase:
def init(self, conn, logSql, replicaVar=1):
self.replicaVar = int(replicaVar)
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor(), True)
self.dbname = 'db'
self.stbname = 'st'
def prepareData(self):
# db
tdSql.execute(f"create database db;")
tdSql.execute(f"use db")
# super tableUNSIGNED
tdSql.execute("CREATE TABLE st( time TIMESTAMP, c1 BIGINT, c2 smallint, c3 double, c4 int UNSIGNED, c5 bool, c6 binary(32), c7 nchar(32)) tags(t1 binary(32), t2 nchar(32))")
tdSql.execute("create table t1 using st tags('1', '1.7')")
tdSql.execute("create table t2 using st tags('0', '')")
tdSql.execute("create table t3 using st tags('1', 'er')")
# create index for all tags
tdSql.execute("INSERT INTO t1 VALUES (1641024000000, 1, 1, 1, 1, 1, '1', '1.7')")
tdSql.execute("INSERT INTO t1 VALUES (1641024000001, 0, 0, 1.7, 0, 0, '0', '')")
tdSql.execute("INSERT INTO t1 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
tdSql.execute("INSERT INTO t2 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
tdSql.execute("INSERT INTO t3 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
tdSql.execute("CREATE TABLE stt( time TIMESTAMP, c1 BIGINT, c2 timestamp, c3 int, c4 int UNSIGNED, c5 bool, c6 binary(32), c7 nchar(32)) tags(t1 binary(32), t2 nchar(32))")
tdSql.execute("create table tt1 using stt tags('1', '1.7')")
# create index for all tags
tdSql.execute("INSERT INTO tt1 VALUES (1641024000000, 9223372036854775807, 1641024000000, 1, 1, 1, '1', '1.7')")
def check(self):
tdSql.query(f"SELECT * FROM tt1 WHERE c1 in (1.7, 9223372036854775803, '')")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM tt1 WHERE c1 = 9223372036854775803")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c1 = 1.7")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c1 in (1.7, 2)")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c1 not in (1.7, 2)")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM t1 WHERE c2 = 1.7")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c2 in (1.7, 2)")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c2 not in (1.7, 2)")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM t1 WHERE c3 = 1.7")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c3 in (1.7, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c3 not in (1.7, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c4 = 1.7")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c4 in (1.7, 2)")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c4 not in (1.7, 2)")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM t1 WHERE c5 = 1.7")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c5 in (1.7, 2)")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c5 not in (1.7, 2)")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM t1 WHERE c6 = 1.7")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c6 in (1.7, 2)")
tdSql.checkRows(0)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (1.7, 2)")
tdSql.checkRows(3)
tdSql.query(f"SELECT * FROM t1 WHERE c6 = 1")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c6 in (1, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (1, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c6 = 0")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c6 in (0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (0, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (0, 2, 'sef')")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c7 = 1.7")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c7 in (1.7, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c7 not in (1.7, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c7 = 0")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c7 in (0, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c7 not in (0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c7 = ''")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c7 in ('', 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c7 not in ('', 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM st WHERE t2 in ('', 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t2 not in ('', 2)")
tdSql.checkRows(4)
tdSql.query(f"SELECT * FROM st WHERE t1 in ('d343', 0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t1 in (0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t1 not in (0, 2)")
tdSql.checkRows(4)
def run(self):
self.prepareData()
self.check()
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())

View File

@ -436,6 +436,29 @@ class TDTestCase:
tdSql.query(sql, queryTimes=1)
tdSql.checkRows(49)
sql = "select null union select null"
tdSql.query(sql, queryTimes=1)
tdSql.checkRows(1)
tdSql.checkData(0, 0, None)
sql = "select null union all select null"
tdSql.query(sql, queryTimes=1)
tdSql.checkRows(2)
tdSql.checkData(0, 0, None)
tdSql.checkData(1, 0, None)
sql = "select null union select 1"
tdSql.query(sql, queryTimes=1)
tdSql.checkRows(2)
tdSql.checkData(0, 0, None)
tdSql.checkData(1, 0, 1)
sql = "select null union select 'asd'"
tdSql.query(sql, queryTimes=1)
tdSql.checkRows(2)
tdSql.checkData(0, 0, None)
tdSql.checkData(1, 0, 'asd')
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")

View File

@ -0,0 +1,44 @@
import taos
import sys
import time
import socket
import os
import threading
from util.log import *
from util.sql import *
from util.cases import *
from util.dnodes import *
from util.common import *
from taos.tmq import *
sys.path.append("./7-tmq")
from tmqCommon import *
class TDTestCase:
updatecfgDict = {'debugFlag': 135, 'asynclog': 0}
def init(self, conn, logSql, replicaVar=1):
self.replicaVar = int(replicaVar)
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor())
#tdSql.init(conn.cursor(), logSql) # output sql.txt file
def run(self):
tdSql.execute(f'create database if not exists db_33225')
tdSql.execute(f'use db_33225')
tdSql.execute(f'create stable if not exists s33225 (ts timestamp, c1 int, c2 int) tags (t binary(32), t2 int)')
tdSql.execute(f'insert into t1 using s33225 tags("__devicid__", 1) values(1669092069068, 0, 1)')
tdSql.execute("create topic db_33225_topic as select ts,c1,t2 from s33225")
tdSql.execute(f'create stream s1 into st1 as select _wstart, count(*), avg(c2),t2 from s33225 PARTITION BY tbname INTERVAL(1m)')
tdSql.execute(f'alter table s33225 modify column c2 COMPRESS "zlib"')
tdSql.execute(f'create index dex1 on s33225(t2)')
return
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())

View File

@ -1,14 +1,29 @@
aux_source_directory(src TSIM_SRC)
add_executable(tsim ${TSIM_SRC})
target_link_libraries(
tsim
LIST(APPEND TSIM_SRC src/simEntry.c)
LIST(APPEND TSIM_SRC src/simExec.c)
LIST(APPEND TSIM_SRC src/simParse.c)
LIST(APPEND TSIM_SRC src/simSystem.c)
ADD_LIBRARY(tsim_static STATIC ${TSIM_SRC})
TARGET_INCLUDE_DIRECTORIES(
tsim_static
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
TARGET_LINK_LIBRARIES(
tsim_static
PUBLIC ${TAOS_LIB}
PUBLIC util
PUBLIC common
PUBLIC os
PUBLIC cjson
)
target_include_directories(
LIST(APPEND TSIM_EXE_SRC src/simMain.c)
ADD_EXECUTABLE(tsim ${TSIM_EXE_SRC})
TARGET_LINK_LIBRARIES(
tsim
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
PUBLIC tsim_static
)
IF(${BUILD_TEST})
ADD_SUBDIRECTORY(test)
ENDIF(${BUILD_TEST})

View File

@ -16,6 +16,10 @@
#ifndef _TD_SIM_INT_H_
#define _TD_SIM_INT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "os.h"
#include "cJSON.h"
@ -161,8 +165,8 @@ typedef struct _script_t {
int32_t type;
bool killed;
void *taos;
char rows[12]; // number of rows data retrieved
char cols[12]; // number of columns data retrieved
char rows[12]; // number of rows data retrieved
char cols[12]; // number of columns data retrieved
char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM][MAX_QUERY_VALUE_LEN]; // query results
char system_exit_code[12];
char system_ret_content[MAX_SYSTEM_RESULT_LEN];
@ -192,7 +196,7 @@ SScript *simParseScript(char *fileName);
SScript *simProcessCallOver(SScript *script);
void *simExecuteScript(void *script);
void simInitsimCmdList();
bool simSystemInit();
void simSystemInit();
void simSystemCleanUp();
char *simGetVariable(SScript *script, char *varName, int32_t varLen);
bool simExecuteExpCmd(SScript *script, char *option);
@ -214,4 +218,11 @@ bool simExecuteLineInsertErrorCmd(SScript *script, char *option);
bool simExecuteSetBIModeCmd(SScript *script, char *option);
void simVisuallizeOption(SScript *script, char *src, char *dst);
int32_t simEntry(int32_t argc, char **argv);
void simHandleSignal(int32_t signo, void *sigInfo, void *context);
#ifdef __cplusplus
}
#endif
#endif /*_TD_SIM_INT_H_*/

64
utils/tsim/src/simEntry.c Normal file
View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "simInt.h"
bool simExecSuccess = false;
bool abortExecution = false;
bool useValgrind = false;
void simHandleSignal(int32_t signo, void *sigInfo, void *context) {
simSystemCleanUp();
abortExecution = true;
}
int32_t simEntry(int32_t argc, char **argv) {
char scriptFile[MAX_FILE_NAME_LEN] = "sim_main_test.sim";
for (int32_t i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-c") == 0 && i < argc - 1) {
tstrncpy(configDir, argv[++i], 128);
} else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
tstrncpy(scriptFile, argv[++i], MAX_FILE_NAME_LEN);
} else if (strcmp(argv[i], "-v") == 0) {
useValgrind = true;
} else {
printf("usage: %s [options] \n", argv[0]);
printf(" [-c config]: config directory, default is: %s\n", configDir);
printf(" [-f script]: script filename\n");
return 0;
}
}
simInfo("simulator is running ...");
simSystemInit();
taosSetSignal(SIGINT, simHandleSignal);
SScript *script = simParseScript(scriptFile);
if (script == NULL) {
simError("parse script file:%s failed", scriptFile);
return -1;
}
simScriptList[++simScriptPos] = script;
simExecuteScript(script);
int32_t ret = simExecSuccess ? 0 : -1;
simInfo("execute result %d", ret);
return ret;
}

View File

@ -382,8 +382,8 @@ bool simExecuteRunBackCmd(SScript *script, char *option) {
return true;
}
void simReplaceDirSep(char *buf) {
#ifdef WINDOWS
void simReplaceDirSep(char *buf) {
int i = 0;
while (buf[i] != '\0') {
if (buf[i] == '/') {
@ -391,8 +391,8 @@ void simReplaceDirSep(char *buf) {
}
i++;
}
#endif
}
#endif
bool simReplaceStr(char *buf, char *src, char *dst) {
bool replaced = false;

View File

@ -16,58 +16,7 @@
#define _DEFAULT_SOURCE
#include "simInt.h"
bool simExecSuccess = false;
bool abortExecution = false;
bool useValgrind = false;
void simHandleSignal(int32_t signo, void *sigInfo, void *context) {
simSystemCleanUp();
abortExecution = true;
}
int32_t main(int32_t argc, char *argv[]) {
char scriptFile[MAX_FILE_NAME_LEN] = "sim_main_test.sim";
for (int32_t i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-c") == 0 && i < argc - 1) {
tstrncpy(configDir, argv[++i], 128);
} else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
tstrncpy(scriptFile, argv[++i], MAX_FILE_NAME_LEN);
} else if (strcmp(argv[i], "-v") == 0) {
useValgrind = true;
} else {
printf("usage: %s [options] \n", argv[0]);
printf(" [-c config]: config directory, default is: %s\n", configDir);
printf(" [-f script]: script filename\n");
return 0;
}
}
if (!simSystemInit()) {
simError("failed to initialize the system");
simSystemCleanUp();
return -1;
}
simInfo("simulator is running ...");
taosSetSignal(SIGINT, simHandleSignal);
SScript *script = simParseScript(scriptFile);
if (script == NULL) {
simError("parse script file:%s failed", scriptFile);
return -1;
}
if (abortExecution) {
simError("execute abort");
return -1;
}
simScriptList[++simScriptPos] = script;
simExecuteScript(script);
int32_t ret = simExecSuccess ? 0 : -1;
simInfo("execute result %d", ret);
return ret;
// entry function used for unit testing.
return simEntry(argc, argv);
}

View File

@ -35,11 +35,10 @@ int32_t simInitCfg() {
return 0;
}
bool simSystemInit() {
void simSystemInit() {
simInitCfg();
simInitsimCmdList();
memset(simScriptList, 0, sizeof(SScript *) * MAX_MAIN_SCRIPT_NUM);
return true;
}
void simSystemCleanUp() {}

View File

@ -0,0 +1,23 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20)
PROJECT(TDengine)
FIND_PATH(HEADER_GTEST_INCLUDE_DIR gtest.h /usr/include/gtest /usr/local/include/gtest)
FIND_LIBRARY(LIB_GTEST_STATIC_DIR libgtest.a /usr/lib/ /usr/local/lib /usr/lib64)
FIND_LIBRARY(LIB_GTEST_SHARED_DIR libgtest.so /usr/lib/ /usr/local/lib /usr/lib64)
IF(HEADER_GTEST_INCLUDE_DIR AND(LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR))
MESSAGE(STATUS "gTest library found, build os test")
INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
ENDIF()
INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc)
ADD_EXECUTABLE(simTests "simTests.cpp")
TARGET_LINK_LIBRARIES(simTests os util tsim_static gtest_main)
ADD_TEST(
NAME simTests
COMMAND simTests
)

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include <iostream>
#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"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
#pragma GCC diagnostic ignored "-Wpointer-arith"
#include "simInt.h"
void simHandleSignal(int32_t signo, void *sigInfo, void *context);
TEST(simTests, parameters) {
int32_t ret = 0;
int32_t argc = 2;
char *argv[4] = {0};
simSystemCleanUp();
// argv[1] = "-c";
// ret = simEntry(argc, argv);
// EXPECT_EQ(ret, 0);
// argv[1] = "-f";
// ret = simEntry(argc, argv);
// EXPECT_EQ(ret, 0);
// argv[1] = "-v";
// ret = simEntry(argc, argv);
// EXPECT_EQ(ret, 0);
// argv[1] = "-h";
// ret = simEntry(argc, argv);
// EXPECT_EQ(ret, 0);
// simHandleSignal(0, NULL, NULL);
// simDebugFlag = 0;
// argc = 1;
// ret = simEntry(argc, argv);
// EXPECT_EQ(ret, -1);
}