test: reproduce bugs (#32474)

This commit is contained in:
Simon Guan 2025-08-06 18:13:54 +08:00 committed by GitHub
parent 5e3c15e82f
commit 24ff2bee2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 233 additions and 136 deletions

View file

@ -138,11 +138,13 @@ DEGREES(expr)
**适用于**:表和超级表。
**使用说明**
- 如果 `expr` 为 NULL则返回 NULL。
- degree = radian * 180 / π。
- 只能与普通列选择Selection、投影Projection函数一起使用不能与聚合Aggregation函数一起使用。
**举例**
```sql
taos> select degrees(PI());
degrees(pi()) |
@ -155,6 +157,7 @@ taos> select degrees(PI());
```sql
EXP(expr)
```
**功能说明**:返回 e自然对数的底的指定乘方后的值。
**版本**v3.3.3.0
@ -168,10 +171,12 @@ EXP(expr)
**适用于**:表和超级表。
**使用说明**
- 如果 `expr` 为 NULL返回 NULL。
- 只能与普通列选择Selection、投影Projection函数一起使用不能与聚合Aggregation函数一起使用。
**举例**
```sql
taos> select exp(2);
exp(2) |
@ -185,10 +190,10 @@ taos> select exp(2);
FLOOR(expr)
```
**功能说明**:获得指定字段的向下取整数的结果。
其他使用说明参见 [CEIL](#ceil) 函数描述。
**功能说明**:获得指定字段的向下取整数的结果。其他使用说明参见 [CEIL](#ceil) 函数描述。
#### GREATEST
```sql
GREATEST(expr1, expr2[, expr]...)
```
@ -200,10 +205,12 @@ GREATEST(expr1, expr2[, expr]...)
**返回结果类型**:参考比较规则,比较类型即为最终返回类型。
**适用数据类型**
- 数值类型:包括 bool 型,整型和浮点型
- 字符串类型:包括 nchar 和 varchar 类型。
**比较规则**:以下规则描述了比较操作的转换方式:
- 如果有任何一个参数为 NULL则比较结果为 NULL。
- 如果比较操作中的所有参数都是字符串类型,按照字符串类型比较
- 如果所有参数都是数值类型,则将它们作为数值类型进行比较。
@ -213,6 +220,7 @@ GREATEST(expr1, expr2[, expr]...)
**相关配置项**客户端配置compareAsStrInGreatest 为 1 表示同时存在字符串类型和数值类型统一转为字符串比较,为 0 表示统一转为数值类型比较。默认为 1。
#### LEAST
```sql
LEAST(expr1, expr2[, expr]...)
```
@ -238,11 +246,13 @@ LN(expr)
**适用于**:表和超级表。
**使用说明**
- 如果 `expr` 为 NULL返回 NULL。
- 如果 `epxr` 小于等于 0返回 NULL。
- 只能与普通列选择Selection、投影Projection函数一起使用不能与聚合Aggregation函数一起使用。
**举例**
```sql
taos> select ln(10);
ln(10) |
@ -287,11 +297,13 @@ MOD(expr1, expr2)
**适用于**:表和超级表。
**使用说明**
- 如果 `expr2` 为 0 则返回 NULL。
- 如果 `expr1``expr2` 为 NULL返回 NULL。
- 只能与普通列选择Selection、投影Projection函数一起使用不能与聚合Aggregation函数一起使用。
**举例**
``` sql
taos> select mod(10,3);
mod(10,3) |
@ -323,10 +335,12 @@ PI()
**适用于**:表和超级表。
**使用说明**
- π ≈ 3.141592653589793。
- 只能与普通列选择Selection、投影Projection函数一起使用不能与聚合Aggregation函数一起使用。
**举例**
```sql
taos> select pi();
pi() |
@ -371,11 +385,13 @@ RADIANS(expr)
**适用于**:表和超级表。
**使用说明**
- 如果 `expr` 为 NULL则返回 NULL。
- radian = degree * π / 180。
- 只能与普通列选择Selection、投影Projection函数一起使用不能与聚合Aggregation函数一起使用。
**举例**
```sql
taos> select radians(180);
radians(180) |
@ -396,6 +412,7 @@ RAND([seed])
**返回结果类型**DOUBLE。
**适用数据类型**
- `seed`INTEGER。
**嵌套子查询支持**:适用于内层查询和外层查询。
@ -403,10 +420,12 @@ RAND([seed])
**适用于**:表和超级表。
**使用说明**
- 如果指定了 `seed` 值,那么将会用指定的 `seed` 作为随机种子,确保生成的随机数序列具有确定性。
- 只能与普通列选择Selection、投影Projection函数一起使用不能与聚合Aggregation函数一起使用。
**举例**
``` sql
taos> select rand();
rand() |
@ -440,6 +459,7 @@ ROUND(expr[, digits])
**返回结果类型**:与指定字段的原始数据类型一致。
**适用数据类型**
- `expr`:数值类型。
- `digits`:数值类型。
@ -448,6 +468,7 @@ ROUND(expr[, digits])
**适用于**:表和超级表。
**使用说明**
- 若 `expr``digits` 为 NULL返回 NULL。
- 若指定了`digits`,则会保留 `digits` 位小数,默认为 0。
- 若输入值是 INTEGER 类型,无论 `digits` 值为多少,都只会返回 INTEGER 类型,不会保留小数。
@ -458,6 +479,7 @@ ROUND(expr[, digits])
- `digits` 从 v3.3.3.0 开始支持。
**举例**
```sql
taos> select round(8888.88);
round(8888.88) |
@ -489,6 +511,7 @@ SIGN(expr)
**适用于**:表和超级表。
**使用说明**
- 如果 `expr` 为负,返回 -1。
- 如果 `expr` 为正,返回 1。
- 如果 `expr` 为 0返回 0。
@ -496,6 +519,7 @@ SIGN(expr)
- 只能与普通列选择Selection、投影Projection函数一起使用不能与聚合Aggregation函数一起使用。
**举例**
```sql
taos> select sign(-1);
sign(-1) |
@ -580,6 +604,7 @@ TRUNCATE(expr, digits)
**返回结果类型**:与 `expr` 字段的原始数据类型一致。
**适用数据类型**
- `expr`:数值类型。
- `digits`:数值类型。
@ -588,6 +613,7 @@ TRUNCATE(expr, digits)
**适用于**:表和超级表。
**使用说明**
- 若 `expr``digits` 为 NULL返回 NULL。
- 截取指按保留位数直接进行截取,没有四舍五入。
- `digits` 大于零表示对小数位进行操作,截取到 `digits` 位小数,若小数位数小于 `digits` 位,不进行截取操作,直接返回。
@ -597,6 +623,7 @@ TRUNCATE(expr, digits)
- 只能与普通列选择Selection、投影Projection函数一起使用不能与聚合Aggregation函数一起使用。
**举例**
```sql
taos> select truncate(8888.88, 0);
truncate(8888.88, 0) |
@ -614,6 +641,7 @@ taos> select truncate(8888.88, -1);
```sql
CRC32(expr)
```
**功能说明**: 传回代表循环冗余检查 (CRC) 的无符号 32 位整数。
**返回结果类型**: 无符号 32 位整数。
@ -707,10 +735,12 @@ ASCII(expr)
**适用于**:表和超级表。
**使用说明**
- 如果 `expr` 为 NULL返回 NULL。
- 如果 `expr` 的第一个字符为多字节字符,只会返回该字符第一个字节的值对应的 ASCII 码。
**举例**
```sql
taos> select ascii('testascii');
ascii('testascii') |
@ -737,6 +767,7 @@ CHAR(expr1 [, expr2] [, epxr3] ...)
**适用于**:表和超级表。
**使用说明**
- 输入的值超过 255 会被转化成多字节的结果,如 `CHAR(256)` 等同于 `CHAR(1,0)`、`CHAR(256 * 256)` 等同于 `CHAR(1,0,0)`
- 输入参数的 NULL 值会被跳过。
- 输入参数若为字符串类型,会将其转换为数值类型处理。
@ -744,6 +775,7 @@ CHAR(expr1 [, expr2] [, epxr3] ...)
- 输入参数的个数上限为 2^31 - 1 个。
**举例**
```sql
taos> select char(77);
char(77) |
@ -787,10 +819,12 @@ CHAR_LENGTH(expr)
**适用于**:表和超级表。
**使用说明**
- 与 `LENGTH()` 函数不同在于,对于多字节字符,比如中文字符,`CHAR_LENGTH()` 函数会将其算做一个字符,长度为 1`LENGTH()` 会计算其字节数,长度为 3。比如 `CHAR_LENGTH('你好') = 2``LENGTH('你好') = 6`。
- 如果 `expr` 为 NULL返回 NULL。
**举例**
```sql
taos> select char_length('Hello world');
char_length('Hello world') |
@ -897,6 +931,7 @@ POSITION(expr1 IN expr2)
**返回结果类型**BIGINT。
**适用数据类型**
- `expr1`VARCHAR、NCHAR。
- `expr2`VARCHAR、NCHAR。
@ -905,6 +940,7 @@ POSITION(expr1 IN expr2)
**适用于**:表和超级表。
**使用说明**
- 若 `expr1``expr2` 为 NULL返回 NULL。
- 若 `expr1``expr2` 中不存在,返回 0。
- 若 `expr1` 为空串,认为 `expr1``expr2` 中总能匹配成功,返回 1。
@ -912,6 +948,7 @@ POSITION(expr1 IN expr2)
- 该函数是多字节安全的。
**举例**
```sql
taos> select position('a' in 'cba');
position('a' in 'cba') |
@ -935,6 +972,7 @@ taos> select position('d' in 'cba');
```sql
REPEAT(expr, count)
```
**功能说明**:返回将字符串重复指定次数得到的字符串。
**版本**v3.3.3.0
@ -942,6 +980,7 @@ REPEAT(expr, count)
**返回结果类型**:与输入字段 `expr` 的原始类型相同。
**适用数据类型**
- `expr`VARCHAR、NCHAR。
- `count`INTEGER。
@ -950,10 +989,12 @@ REPEAT(expr, count)
**适用于**:表和超级表。
**使用说明**
- 若 `count < 1`,返回空串。
- 若 `expr``count` 为 NULL返回 NULL。
**举例**
```sql
taos> select repeat('abc',5);
repeat('abc',5) |
@ -971,6 +1012,7 @@ taos> select repeat('abc',-1);
```sql
REPLACE(expr, from_str, to_str)
```
**功能说明**:将字符串中的 `from_str` 全部替换为 `to_str`
**版本**v3.3.3.0
@ -978,6 +1020,7 @@ REPLACE(expr, from_str, to_str)
**返回结果类型**:与输入字段 `expr` 的原始类型相同。
**适用数据类型**
- `expr`VARCHAR、NCHAR。
- `from_str`VARCHAR、NCHAR。
- `to_str`VARCHAR、NCHAR。
@ -987,11 +1030,13 @@ REPLACE(expr, from_str, to_str)
**适用于**:表和超级表。
**使用说明**
- 该函数是大小写敏感的。
- 任意参数为 NULL返回 NULL。
- 该函数是多字节安全的。
**举例**
```sql
taos> select replace('aabbccAABBCC', 'AA', 'DD');
replace('aabbccAABBCC', 'AA', 'DD') |
@ -1021,11 +1066,13 @@ RTRIM(expr)
SUBSTRING/SUBSTR(expr, pos [, len])
SUBSTRING/SUBSTR(expr FROM pos [FOR len])
```
**功能说明**:返回字符串 `expr``pos` 位置开始的子串,若指定了 `len`,则返回在 `pos` 位置开始,长度为 `len` 的子串。
**返回结果类型**:与输入字段 `expr` 的原始类型相同。
**适用数据类型**
- `expr`VARCHAR、NCHAR。
- `pos`:整数类型。
- `len`:整数类型。
@ -1035,6 +1082,7 @@ SUBSTRING/SUBSTR(expr FROM pos [FOR len])
**适用于**:表和超级表。
**使用说明**
- 若 `pos` 为正数,则返回的结果为 `expr` 从左到右开始数 `pos` 位置开始的右侧的子串。
- 若 `pos` 为负数,则返回的结果为 `expr` 从右到左开始数 `pos` 位置开始的右侧的子串。
- 任意参数为 NULL返回 NULL。
@ -1046,6 +1094,7 @@ SUBSTRING/SUBSTR(expr FROM pos [FOR len])
- `SUBSTRING/SUBSTR(expr FROM pos [FOR len])` 语法从 v3.3.3.0 开始支持。
**举例**
```sql
taos> select substring('tdengine', 0);
substring('tdengine', 0) |
@ -1086,6 +1135,7 @@ SUBSTRING_INDEX(expr, delim, count)
**返回结果类型**:与输入字段 `expr` 的原始类型相同。
**适用数据类型**
- `expr`VARCHAR、NCHAR。
- `delim`VARCHAR、NCHAR。
- `count`INTEGER。
@ -1095,12 +1145,14 @@ SUBSTRING_INDEX(expr, delim, count)
**适用于**:表和超级表。
**使用说明**
- 若 `count` 为正数,则返回的结果为 `expr` 从左到右开始数第 `count` 次 出现 `delim` 的位置左侧的字符串。
- 若 `count` 为负数,则返回的结果为 `expr` 从右到左开始数第 `count` 的绝对值次 出现 `delim` 的位置右侧的字符串。
- 任意参数为 NULL返回 NULL。
- 该函数是多字节安全的。
**举例**
```sql
taos> select substring_index('www.taosdata.com','.',2);
substring_index('www.taosdata.com','.',2) |
@ -1127,6 +1179,7 @@ TRIM([remstr FROM] expr)
**返回结果类型**:与输入字段 epxr 的原始类型相同。
**适用数据类型**
- remstrVARCHAR、NCHAR。
- epxrVARCHAR、NCHAR。
@ -1135,6 +1188,7 @@ TRIM([remstr FROM] expr)
**适用于**:表和超级表。
**使用说明**
- 第一个可选变量[LEADING | BOTH | TRAILING]指定要剪裁字符串的哪一侧:
- LEADING 将移除字符串开头的指定字符。
- TRAILING 将移除字符串末尾的指定字符。
@ -1146,6 +1200,7 @@ TRIM([remstr FROM] expr)
- 该函数是多字节安全的。
**举例**
```sql
taos> select trim(' a ');
trim(' a ') |
@ -1309,6 +1364,7 @@ TO_CHAR(ts, format_str_literal)
| TZH,tzh | 时区小时 | 2023-01-30 11:59:59PM +08 |
**使用说明**
- `Month`、`Day`等的输出格式是左对齐的,右侧添加空格,如 `2023-OCTOBER -01`、`2023-SEPTEMBER-01`9 月是月份中英文字母数最长的,因此 9 月没有空格。星期类似。
- 使用`ms`、`us`、`ns`时,以上三种格式的输出只在精度上不同,比如 ts 为 `1697182085123``ms` 的输出为 `123``us` 的输出为 `123000``ns` 的输出为 `123000000`
- 时间格式中无法匹配规则的内容会直接输出。如果想要在格式串中指定某些能够匹配规则的部分不做转换,可以使用双引号,如 `to_char(ts, 'yyyy-mm-dd "is formatted by yyyy-mm-dd"')`。如果想要输出双引号,那么在双引号之前加一个反斜杠,如 `to_char(ts, '\"yyyy-mm-dd\"')` 将会输出 `"2023-10-10"`
@ -1374,6 +1430,7 @@ TO_TIMESTAMP(ts_str_literal, format_str_literal)
**使用说明**:与 `to_char` 相同。
**使用说明**
- 若 `ms`、`us`、`ns` 同时指定,那么结果时间戳包含上述三个字段的和,如 `to_timestamp('2023-10-10 10:10:10.123.000456.000000789', 'yyyy-mm-dd hh:mi:ss.ms.us.ns')` 输出为 `2023-10-10 10:10:10.123456789`对应的时间戳。
- `MONTH`、`MON`、`DAY`、`DY` 以及其他输出为数字的格式的大小写意义相同,如 `to_timestamp('2023-JANUARY-01', 'YYYY-month-dd')``month`可以被替换为 `MONTH` 或者 `Month`
- 如果同一字段被指定了多次,那么前面的指定将会被覆盖,如 `to_timestamp('2023-22-10-10', 'yyyy-yy-MM-dd')`,输出年份是 `2022`
@ -1420,6 +1477,7 @@ return_timestamp: {
```sql
DAYOFWEEK(expr)
```
**功能说明**:返回输入日期是周几。
**版本**v3.3.3.0
@ -1433,11 +1491,13 @@ DAYOFWEEK(expr)
**适用于**:表和超级表。
**使用说明**
- 返回值 1 代表周日2 代表周一 ... 7 代表周六
- 若 `expr` 为 NULL返回 NULL。
- 输入时间戳的精度由所查询表的精度确定,若未指定表,则精度为毫秒。
**举例**
```sql
taos> select dayofweek('2000-01-01');
dayofweek('2000-01-01') |
@ -1478,6 +1538,7 @@ TIMEDIFF(expr1, expr2 [, time_unit])
**返回结果类型**BIGINT。
**适用数据类型**
- `expr1`:表示时间戳的 BIGINT、TIMESTAMP 类型,或符合 ISO8601/RFC3339 标准的日期时间格式的 VARCHAR、NCHAR 类型。
- `expr2`:表示时间戳的 BIGINT、TIMESTAMP 类型,或符合 ISO8601/RFC3339 标准的日期时间格式的 VARCHAR、NCHAR 类型。
- `time_unit`:见使用说明。
@ -1488,6 +1549,7 @@ TIMEDIFF(expr1, expr2 [, time_unit])
**适用于**:表和超级表。
**使用说明**
- `expr1``expr2` 为 NULL返回 NULL。
- 输入包含不符合时间日期格式的字符串则返回 NULL。
- 输入时间戳的精度由所查询表的精度确定,若未指定表,则精度为毫秒。
@ -1495,6 +1557,7 @@ TIMEDIFF(expr1, expr2 [, time_unit])
- `time_unit` 为 NULL等同于未指定时间单位。
**举例**
```sql
taos> select timediff('2022-01-01 08:00:00', '2022-01-01 08:00:01',1s);
timediff('2022-01-01 08:00:00', '2022-01-01 08:00:01',1s) |
@ -1532,6 +1595,7 @@ use_current_timezone: {
**适用于**:表和超级表。
**使用说明**
- 支持的时间单位 time_unit 包括 1b(纳秒)、1u(微秒)、1a(毫秒)、1s(秒)、1m(分)、1h(小时)、1d(天)、1w(周)。
- 返回的时间戳精度与当前 DATABASE 设置的时间精度一致。
- 输入时间戳的精度由所查询表的精度确定,若未指定表,则精度为毫秒。
@ -1583,6 +1647,7 @@ TODAY()
```sql
WEEK(expr [, mode])
```
**功能说明**:返回输入日期的周数。
**版本**v3.3.3.0
@ -1590,6 +1655,7 @@ WEEK(expr [, mode])
**返回结果类型**BIGINT。
**适用数据类型**
- `expr`:表示时间戳的 BIGINT、TIMESTAMP 类型,或符合 ISO8601/RFC3339 标准的日期时间格式的 VARCHAR、NCHAR 类型。
- `mode`0 - 7 之间的整数。
@ -1598,6 +1664,7 @@ WEEK(expr [, mode])
**适用于**:表和超级表。
**使用说明**
- 若 `expr` 为 NULL返回 NULL。
- 输入时间戳的精度由所查询表的精度确定,若未指定表,则精度为毫秒。
- `mode` 用来指定一周是从周日开始还是周一开始,以及指定返回值范围是 1 - 53 还是 0 - 53。下表详细描述不同的 mode 对应的计算方法:
@ -1612,6 +1679,7 @@ WEEK(expr [, mode])
| 5 | 周一 | 0 - 53 | 第一个包含周一的周为第 1 周 |
| 6 | 周日 | 1 - 53 | 第一个包含四天及以上的周为第 1 周 |
| 7 | 周一 | 1 - 53 | 第一个包含周一的周为第 1 周 |
- 当返回值范围为 0 - 53 时,第 1 周之前的日期为第 0 周。
- 当返回值范围为 1 - 53 时,第 1 周之前的日期为上一年的最后一周。
- 以`2000-01-01`为例,
@ -1620,6 +1688,7 @@ WEEK(expr [, mode])
- 在 `mode=2` 时返回值为 `52`,因为从 `2000-01-02` 起才是第 1 周,并且返回值范围为 1-53所以 `2000-01-01` 算做上一年的最后一周,即 1999 年的第 52 周,返回 52。
**举例**
```sql
taos> select week('2000-01-01',0);
week('2000-01-01',0) |
@ -1643,9 +1712,11 @@ taos> select week('2000-01-01',3);
```
#### WEEKDAY
```sql
WEEKDAY(expr)
```
**功能说明**:返回输入日期是周几。
**版本**v3.3.3.0
@ -1659,11 +1730,13 @@ WEEKDAY(expr)
**适用于**:表和超级表。
**使用说明**
- 返回值 0 代表周一1 代表周二 ... 6 代表周日。
- 若 `expr` 为 NULL返回 NULL。
- 输入时间戳的精度由所查询表的精度确定,若未指定表,则精度为毫秒。
**举例**
```sql
taos> select weekday('2000-01-01');
weekday('2000-01-01') |
@ -1676,6 +1749,7 @@ taos> select weekday('2000-01-01');
```sql
WEEKOFYEAR(expr)
```
**功能说明**:返回输入日期的周数。
**版本**v3.3.3.0
@ -1689,11 +1763,13 @@ WEEKOFYEAR(expr)
**适用于**:表和超级表。
**使用说明**
- 等同于`WEEK(expr, 3)`,即在每周第一天是周一,返回值范围为 1 - 53第一个包含四天及以上的周为第 1 周的条件下判断输入日期的周数。
- 若 `expr` 为 NULL返回 NULL。
- 输入时间戳的精度由所查询表的精度确定,未指定表,则精度为毫秒。
**举例**
```sql
taos> select weekofyear('2000-01-01');
weekofyear('2000-01-01') |
@ -1727,7 +1803,8 @@ algo_type: {
**适用于**:表和超级表。
**说明**
- p 值范围是 [0,100],当为 0 时等同 于 MIN为 100 时等同于 MAX。
- p 值范围是 [0,100],当为 0 时等同于 MIN为 100 时等同于 MAX。
- algo_type 取值为 "default" 或 "t-digest"。输入为 "default" 时函数使用基于直方图算法进行计算。输入为 "t-digest" 时使用 t-digest 算法计算分位数的近似结果。如果不指定 algo_type 则使用 "default" 算法。
- t-digest 算法的近似结果对于输入数据顺序敏感,对超级表查询时不同的输入排序结果可能会有微小的误差。
@ -1772,7 +1849,7 @@ COUNT({* | expr})
ELAPSED(ts_primary_key [, time_unit])
```
**功能说明**`elapsed` 函数表达了统计周期内连续的时间长度,和 twa 函数配合使用可以计算统计曲线下的面积。在通过 INTERVAL 子句指定窗口的情况下,统计在给定时间范围内的每个窗口内有数据覆盖的时间范围;如果没有 INTERVAL 子句则返回整个给定时间范围内的有数据覆盖的时间范围。注意ELAPSED 返回的并不是时间范围的绝对值,而是绝对值除以 time_unit 所得到的单位个数。流计算仅在 FORCE_WINDOW_CLOSE 模式下支持该函数。
**功能说明**`elapsed` 函数表达了统计周期内连续的时间长度,和 twa 函数配合使用可以计算统计曲线下的面积。在通过 INTERVAL 子句指定窗口的情况下,统计在给定时间范围内的每个窗口内有数据覆盖的时间范围;如果没有 INTERVAL 子句则返回整个给定时间范围内的有数据覆盖的时间范围。注意ELAPSED 返回的并不是时间范围的绝对值,而是绝对值除以 time_unit 所得到的单位个数。
**返回结果类型**DOUBLE。
@ -1780,7 +1857,8 @@ ELAPSED(ts_primary_key [, time_unit])
**适用于**:表、超级表、嵌套查询的外层查询。
**说明**
**使用说明**
- `ts_primary_key` 参数只能是表的第一列,即 TIMESTAMP 类型的主键列。
- 返回值的时间单位由 `time_unit` 参数指定,最小是数据库的时间分辨率。`time_unit` 参数未指定时,以数据库的时间分辨率为时间单位。支持的时间单位 `time_unit` 如下1b(纳秒)、1u(微秒)、1a(毫秒)、1s(秒)、1m(分)、1h(小时)、1d(天)、1w(周)。
- 可以和 interval 组合使用,返回每个时间窗口的时间戳差值。需要特别注意的是,除第一个时间窗口和最后一个时间窗口外,中间窗口的时间戳差值均为窗口长度。
@ -1805,6 +1883,7 @@ HISTOGRAM(exprbin_type, bin_description, normalized)
**适用于**:表和超级表。
**详细说明**
- bin_type 用户指定的分桶类型,有效输入类型为 "user_input"、"linear_bin"、"log_bin"。
- bin_description 描述如何生成分桶区间,针对三种桶类型,分别为以下描述格式 (均为 JSON 格式字符串)
- "user_input": "[1, 3, 5, 7]"
@ -1826,8 +1905,9 @@ HYPERLOGLOG(expr)
```
**功能说明**
- 采用 hyperloglog 算法,返回某列的基数。该算法在数据量很大的情况下,可以明显降低内存的占用,求出来的基数是个估算值,标准误差(标准误差是多次实验,每次的平均数的标准差,不是与真实结果的误差)为 0.81%。
- 在数据量较少的时候该算法不是很准确,可以使用 `select count(data) from (select unique(col) as data from table)` 的方法。
- 采用 hyperloglog 算法,返回某列的基数。该算法在数据量很大的情况下,可以明显降低内存的占用,求出来的基数是个估算值,标准误差(标准误差是多次实验,每次的平均数的标准差,不是与真实结果的误差)为 0.81%。
- 在数据量较少的时候该算法不是很准确,可以使用 `select count(data) from (select unique(col) as data from table)` 的方法。
**返回结果类型**INTEGER。
@ -1849,7 +1929,6 @@ LEASTSQUARES(expr, start_val, step_val)
**适用于**:表。
### PERCENTILE
```sql
@ -1884,7 +1963,6 @@ SPREAD(expr)
**适用于**:表和超级表。
### STDDEV/STDDEV_POP
```sql
@ -1899,10 +1977,12 @@ STDDEV/STDDEV_POP(expr)
**适用于**:表和超级表。
**说明**
**使用说明**
- `STDDEV_POP` 函数等价于 `STDDEV` 函数,从 v3.3.3.0 开始支持。
**举例**
```sql
taos> select id from test_stddev;
id |
@ -1952,6 +2032,7 @@ VAR_POP(expr)
**适用于**:表和超级表。
**举例**
```sql
taos> select id from test_var;
id |
@ -1978,7 +2059,7 @@ taos> select var_pop(id) from test_var;
BOTTOM(expr, k)
```
**功能说明**:统计表/超级表中某列的值最小 _k_ 个非 NULL 值。如果多条数据取值一样,全部取用又会超出 k 条限制时,系统会从相同值中随机选取符合要求的数量返回。
**功能说明**:统计表/超级表中某列的值最小 **k** 个非 NULL 值。如果多条数据取值一样,全部取用又会超出 k 条限制时,系统会从相同值中随机选取符合要求的数量返回。
**返回数据类型**:同应用的字段。
@ -2049,6 +2130,7 @@ LAST_ROW(expr)
**适用于**:表和超级表。
**使用说明**
- 如果要返回各个列的最后一条记录(时间戳最大),可以使用 LAST_ROW(\*) 查询超级表,且 multiResultFunctionStarReturnTags 设置为 0 (默认值) 时LAST_ROW(\*) 只返回超级表的普通列;设置为 1 时,返回超级表的普通列和标签列。
- 在用于超级表时,时间戳完全一样且同为最大的数据行可能有多个,那么会从中随机返回一条,而并不保证多次运行所挑选的数据行必然一致。
- 不能与 INTERVAL 一起使用。
@ -2069,6 +2151,7 @@ MAX(expr)
**适用于**:表和超级表。
**使用说明**
- max 函数可以接受字符串作为输入参数,当输入参数为字符串类型时,返回最大的字符串值,从 v3.3.3.0 开始支持,之前的版本不支持字符串参数。
### MIN
@ -2086,6 +2169,7 @@ MIN(expr)
**适用于**:表和超级表。
**使用说明**
- min 函数可以接受字符串作为输入参数,当输入参数为字符串类型时,返回最大的字符串值,从 v3.3.3.0 开始支持,之前的版本不支持字符串参数。
### MODE
@ -2140,7 +2224,7 @@ TAIL(expr, k [, offset_rows])
TOP(expr, k)
```
**功能说明**:统计表/超级表中某列的值最大 _k_ 个非 NULL 值。如果多条数据取值一样,全部取用又会超出 k 条限制时,系统会从相同值中随机选取符合要求的数量返回。
**功能说明**:统计表/超级表中某列的值最大 **k** 个非 NULL 值。如果多条数据取值一样,全部取用又会超出 k 条限制时,系统会从相同值中随机选取符合要求的数量返回。
**返回数据类型**:同应用的字段。
@ -2183,13 +2267,13 @@ COLS(func(expr), output_expr1, [, output_expr2] ... )
**适用于**:表和超级表。
**使用说明**
- func 函数类型:必须是单行选择函数(输出结果为一行的选择函数,例如 last 是单行选择函数,但 top 是多行选择函数)。
- 主要用于一个 sql 中获取多个选择函数结果关联列的场景,例如 `select cols(max(c0), ts), cols(max(c1), ts) from ...` 可用于获取 c0、c1 列最大值的不同 ts 值。
- 注意,函数 func 的结果并没有返回,如需输出 func 结果,可额外增加输出列,如 `select fist(ts), cols(first(ts), c1) from ...`
- 输出只有一列时,可以对 cols 函数设置别名。例如 `select cols(first(ts), c1) as c11 from ...`
- 输出一列或者多列时,可以对 cols 函数的每个输出列设置命名。例如 `select cols(first(ts), c1 as c11, c2 as c22)`
## 时序数据特有函数
时序数据特有函数是 TDengine 为了满足时序数据的查询场景而量身定做出来的。在通用数据库中实现类似功能通常需要复杂的查询语法且效率很低。TDengine 以函数的方式内置了这些功能,最大程度的减轻了用户的使用成本。
@ -2211,6 +2295,7 @@ CSUM(expr)
**适用于**:表和超级表。
**使用说明**
- 不支持 +、-、*、/ 运算,如 csum(col1) + csum(col2)。
- 只能与聚合Aggregation函数一起使用。该函数可以应用在普通表和超级表上。
@ -2251,6 +2336,7 @@ ignore_option: {
```
**功能说明**统计表中特定列与之前行的当前列有效值之差。ignore_option 取值为 0|1|2|3可以不填默认值为 0。
- `0` 表示 diff 结果不忽略负值不忽略 null 值
- `1` 表示 diff 结果的负值作为 null 值
- `2` 表示 diff 结果不忽略负值但忽略 null 值
@ -2294,7 +2380,8 @@ ignore_null_values: {
**适用于**:表和超级表。
**使用说明**
**使用说明**
- INTERP 用于在指定时间断面获取指定列的记录值,使用时有专用语法 (interp_clause),语法介绍[参考链接](../select/#interp) 。
- 当指定时间断面不存在符合条件的行数据时INTERP 函数会根据 [FILL](../distinguished/#fill-子句) 参数的设定进行插值。
- INTERP 作用于超级表时,会将该超级表下的所有子表数据按照主键列排序后进行插值计算,也可以搭配 PARTITION BY tbname 使用,将结果强制规约到单个时间线。
@ -2396,7 +2483,7 @@ STATEDURATION(expr, oper, val, unit)
TWA(expr)
```
**功能说明**:时间加权平均函数。统计表中某列在一段时间内的时间加权平均。对于存在复合主键的表的查询,若时间戳相同的数据存在多条,则只有对应的复合主键最小的数据参与运算。流计算仅在 FORCE_WINDOW_CLOSE 模式下支持该函数。
**功能说明**:时间加权平均函数。统计表中某列在一段时间内的时间加权平均。对于存在复合主键的表的查询,若时间戳相同的数据存在多条,则只有对应的复合主键最小的数据参与运算。
**返回数据类型**DOUBLE。
@ -2550,14 +2637,13 @@ ST_Equals(GEOMETRY geomA, GEOMETRY geomB)
**使用说明**"空间相等"意味着 ST_Contains(A,B) = true 和 ST_Contains(B,A) = true并且点的顺序可能不同但表示相同的几何结构。
#### ST_Intersects
```sql
ST_Intersects(GEOMETRY geomA, GEOMETRY geomB)
```
##功能说明**:比较两个几何对象,并在它们相交时返回 true。
**功能说明**:比较两个几何对象,并在它们相交时返回 true。
**返回值类型**BOOL。

View file

@ -28,29 +28,30 @@ description: TDengine 支持的所有运算符
集合运算符将两个查询的结果合并为一个结果。包含集合运算符的查询称之为复合查询。复合查询中每条查询的选择列表中的相应表达式在数量上必须匹配,且结果类型以第一条查询为准,后续查询的结果类型必须可转换到第一条查询的结果类型,转换规则同 CAST 函数。
TDengine 支持 `UNION ALL``UNION` 操作符。UNION ALL 将查询返回的结果集合并返回并不去重。UNION 将查询返回的结果集合并并去重后返回。在同一个 SQL 语句中,集合操作符最多支持 100 个。
TDengine 支持 `UNION ALL``UNION` 操作符。`UNION ALL` 将查询返回的结果集合并返回,并不去重。`UNION` 将查询返回的结果集合并并去重后返回。在同一个 SQL 语句中,集合操作符最多支持 100 个。
## 比较运算符
| # | **运算符** | **支持的类型** | **说明** |
| --- | :---------------: | -------------------------------------------------------------------- | -------------------- |
| 1 | = | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型 | 相等 |
| 2 | \<>, != | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型,且不可以为表的时间戳主键列 | 不相等 |
| 3 | >, \< | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型 | 大于,小于 |
| 4 | >=, \<= | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型 | 大于等于,小于等于 |
| 5 | IS [NOT] NULL | 所有类型 | 是否为空值 |
| 6 | [NOT] BETWEEN AND | 除 BOOL、BLOB、MEDIUMBLOB、JSON 和 GEOMETRY 外的所有类型 | 闭区间比较 |
| 7 | IN | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型,且不可以为表的时间戳主键列 | 与列表内的任意值相等 |
| 8 | NOT IN | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型,且不可以为表的时间戳主键列 | 与列表内的任意值都不相等 |
| 9 | LIKE | BINARY、NCHAR 和 VARCHAR | 通配符匹配所指定的模式串 |
| 10 | NOT LIKE | BINARY、NCHAR 和 VARCHAR | 通配符不匹配所指定的模式串 |
| 11 | MATCH, NMATCH | BINARY、NCHAR 和 VARCHAR | 正则表达式匹配 |
| 12 | REGEXP, NOT REGEXP | BINARY、NCHAR 和 VARCHAR | 正则表达式匹配 |
| 13 | CONTAINS | JSON | JSON 中是否存在某键 |
| # | **运算符** | **支持的类型** | **说明** |
| --- | :--------------------: | -------------------------------------------------------------------- | ---------------------- |
| 1 | = | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型 | 相等 |
| 2 | \<>, != | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型,且不可以为表的时间戳主键列 | 不相等 |
| 3 | >, \< | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型 | 大于,小于 |
| 4 | >=, \<= | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型 | 大于等于,小于等于 |
| 5 | IS [NOT] NULL | 所有类型 | 是否为空值 |
| 6 | [NOT] BETWEEN AND | 除 BOOL、BLOB、MEDIUMBLOB、JSON 和 GEOMETRY 外的所有类型 | 闭区间比较 |
| 7 | IN | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型,且不可以为表的时间戳主键列 | 与列表内的任意值相等 |
| 8 | NOT IN | 除 BLOB、MEDIUMBLOB 和 JSON 外的所有类型,且不可以为表的时间戳主键列 | 与列表内的任意值都不相等 |
| 9 | LIKE | BINARY、NCHAR 和 VARCHAR | 通配符匹配所指定的模式串 |
| 10 | NOT LIKE | BINARY、NCHAR 和 VARCHAR | 通配符不匹配所指定的模式串 |
| 11 | MATCH, NMATCH | BINARY、NCHAR 和 VARCHAR | 正则表达式匹配 |
| 12 | REGEXP, NOT REGEXP | BINARY、NCHAR 和 VARCHAR | 正则表达式匹配 |
| 13 | CONTAINS | JSON | JSON 中是否存在某键 |
LIKE 条件使用通配符字符串进行匹配检查,规则如下:
- '%'(百分号)匹配 0 到任意个字符;'\_'(下划线)匹配单个任意 ASCII 字符。
- '%'(百分号)匹配 0 到任意个字符。
- '\_'(下划线)匹配单个任意 ASCII 字符。
- 如果希望匹配字符串中原本就带有的 \_下划线字符那么可以在通配符字符串中写作 \_即加一个反斜线来进行转义。
- 通配符字符串最长不能超过 100 字节。不建议使用太长的通配符字符串,否则将有可能严重影响 LIKE 操作的执行性能。
@ -63,9 +64,9 @@ MATCH/REGEXP 条件和 NMATCH/NOT REGEXP 条件使用正则表达式进行匹配
## 逻辑运算符
| # | **运算符** | **支持的类型** | **说明** |
| --- | :--------: | -------------- | --------------------------------------------------------------------------- |
| # | **运算符** | **支持的类型** | **说明** |
| --- | :--------: | -------------- | ---------------------------------------------------------------------- |
| 1 | AND | BOOL | 逻辑与,如果两个条件均为 TRUE则返回 TRUE。如果任一为 FALSE则返回 FALSE |
| 2 | OR | BOOL | 逻辑或,如果任一条件为 TRUE则返回 TRUE。如果两者都是 FALSE则返回 FALSE |
TDengine 在计算逻辑条件时,会进行短路径优化,即对于 AND第一个条件为 FALSE则不再计算第二个条件直接返回 FALSE对于 OR第一个条件为 TRUE则不再计算第二个条件直接返回 TRUE。
TDengine 在计算逻辑条件时,会进行短路径优化对于 AND第一个条件为 FALSE则不再计算第二个条件直接返回 FALSE对于 OR第一个条件为 TRUE则不再计算第二个条件直接返回 TRUE。

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseBasic1:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseBasic2:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseCheck:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -22,7 +22,7 @@ class TestStreamOldCaseCheckPoint:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseConcat:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -15,12 +15,12 @@ class TestStreamOldCaseContinueWindowClose:
def test_stream_oldcase_continue_window_close(self):
"""Stream continue window close
To mimic the original CONTINUOUS_WINDOW_CLOSE behavior
Verify the alternative approach to the original continuous window close trigger mode in the new streaming computation
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -13,14 +13,14 @@ class TestStreamOldCaseCount:
tdLog.debug(f"start to execute {__file__}")
def test_stream_oldcase_count(self):
"""Stream count
"""Stream count window
Basic use cases of count window, include expired-data, out-of-order data, and data-deletion
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -15,12 +15,12 @@ class TestStreamOldCaseDelete:
def test_stream_oldcase_delete(self):
"""Stream delete
Testing the correctness of results when deleting data in various trigger windows
Test the correctness of results when deleting data in various trigger windows
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseDistribute:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -13,14 +13,14 @@ class TestStreamOldCaseEvent:
tdLog.debug(f"start to execute {__file__}")
def test_stream_oldcase_event(self):
"""Stream event
"""Stream event window
Test event window deletion and update
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseFillHistory:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -18,7 +18,7 @@ class TestStreamOldCaseFillInterval:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseForceWindowClose:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseInterpDelete:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseInterpFill:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseInterpHistory:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseInterpPartitionBy:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -13,14 +13,14 @@ class TestStreamOldCaseInterpPrimary:
tdLog.debug(f"start to execute {__file__}")
def test_stream_oldcase_interp_primary(self):
"""Stream interp primary
"""Stream interp compisite key
Validate the calculation results of the interp function with cmposite keys
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -15,12 +15,12 @@ class TestStreamOldCaseInterpUpdate:
def test_stream_oldcase_interp_update(self):
"""Stream interp update
Validate the calculation results of the interp function during data updates
Validate the calculation results of the interp function during data updates
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -13,14 +13,14 @@ class TestStreamOldCaseOptions:
tdLog.debug(f"start to execute {__file__}")
def test_stream_oldcase_options(self):
"""Stream stream_options
"""Stream options
Validate the calculation results when ignore update and ignore delete are applied
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -19,7 +19,7 @@ class TestStreamOldCasePartitionBy:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -13,14 +13,14 @@ class TestStreamOldCaseInterpPrimary:
tdLog.debug(f"start to execute {__file__}")
def test_stream_oldcase_interp_primary(self):
"""Stream interp primary
"""Stream composite key
Validate the calculation results with composite keys
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -13,14 +13,14 @@ class TestStreamOldCaseSession:
tdLog.debug(f"start to execute {__file__}")
def test_stream_oldcase_session(self):
"""Stream session
"""Stream session window
Test the correctness of session windows
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -20,7 +20,7 @@ class TestStreamOldCaseSnode:
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -13,14 +13,14 @@ class TestStreamOldCaseState:
tdLog.debug(f"start to execute {__file__}")
def test_stream_oldcase_state(self):
"""Stream state
"""Stream state window
Test the correctness of state windows
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci

View file

@ -15,12 +15,12 @@ class TestStreamOldCaseTwa:
def test_stream_oldcase_twa(self):
"""Stream twa
Verify the behavior of the legacy TWA (Time-Weighted Average) function in the new streaming computation system
Verify the behavior of the legacy TWA function in the new streaming computation system
Catalog:
- Streams:OldTsimCases
Since: v3.0.0.0
Since: v3.3.7.0
Labels: common, ci
@ -39,19 +39,29 @@ class TestStreamOldCaseTwa:
tdStream.createSnode()
streams = []
streams.append(self.TwaError())
streams.append(self.TwaFwcFill())
# streams.append(self.TwaFwcFill21())
# streams.append(self.TwaError()) pass
# streams.append(self.TwaFill1()) pass
# streams.append(self.TwaFill2()) pass
# streams.append(self.TwaFill3()) pass
# streams.append(self.TwaFwcFillPK1()) TD-37328
# streams.append(self.TwaFwcFillPK2()) pass
# streams.append(self.TwaFwcInterval1()) TD-37328
# streams.append(self.TwaFwcInterval2()) TD-37328
# streams.append(self.TwaFwcInterval3()) TD-37328
# streams.append(self.TwaFwcIntervalPK()) TD-37328
# streams.append(self.TwaFwcInterp1()) interp
# streams.append(self.TwaFwcInterp2()) interp
# streams.append(self.TwaFwcInterp3()) interp
tdStream.checkAll(streams)
class TwaError(StreamCheckItem):
def __init__(self):
self.db = "twa_error"
self.db = "twaerror"
def create(self):
tdSql.execute(f"create database twa_error vgroups 1 buffer 8;")
tdSql.execute(f"use twa_error;")
tdSql.execute(f"create database twaerror vgroups 1 buffer 8;")
tdSql.execute(f"use twaerror;")
tdSql.execute(
f"create stable st(ts timestamp, a int, b int, c int) tags(ta int, tb int, tc int);"
@ -100,26 +110,26 @@ class TestStreamOldCaseTwa:
)
def check1(self):
tdSql.query("show twa_error.streams;")
tdSql.query("show twaerror.streams;")
tdSql.checkRows(12)
tdSql.checkKeyData("streams1", 0, "streams1")
tdSql.checkKeyData("streams2", 0, "streams2")
tdSql.checkKeyData("streams3", 0, "streams3")
tdSql.query(
"select * from information_schema.ins_streams where db_name = 'twa_error';"
"select * from information_schema.ins_streams where db_name = 'twaerror';"
)
tdSql.checkRows(12)
tdSql.checkKeyData("streams5", 1, "twa_error")
tdSql.checkKeyData("streams6", 1, "twa_error")
tdSql.checkKeyData("streams5", 1, "twaerror")
tdSql.checkKeyData("streams6", 1, "twaerror")
class TwaFwcFill(StreamCheckItem):
class TwaFill1(StreamCheckItem):
def __init__(self):
self.db = "twa_fwc_fill"
self.db = "twafill1"
def create(self):
tdSql.execute(f"create database twa_fwc_fill vgroups 1 buffer 32;")
tdSql.execute(f"use twa_fwc_fill;")
tdSql.execute(f"create database twafill1 vgroups 1 buffer 32;")
tdSql.execute(f"use twafill1;")
tdSql.execute(
f"create stable st(ts timestamp, a int, b int, c int) tags(ta int, tb int, tc int);"
@ -141,22 +151,22 @@ class TestStreamOldCaseTwa:
def check1(self):
tdSql.checkResultsByFunc(
f"select * from twa_fwc_fill.streamt where ta == 1;",
f"select * from twafill1.streamt where ta == 1;",
lambda: tdSql.getRows() == 5,
)
tdSql.checkResultsByFunc(
f"select * from twa_fwc_fill.streamt where ta == 2;",
f"select * from twafill1.streamt where ta == 2;",
lambda: tdSql.getRows() == 5,
)
class TwaFwcFill21(StreamCheckItem):
class TwaFill2(StreamCheckItem):
def __init__(self):
self.db = "twa_fwc_fill21"
self.db = "twafill2"
def create(self):
tdSql.execute(f"create database twa_fwc_fill21 vgroups 1 buffer 32;")
tdSql.execute(f"use twa_fwc_fill21;")
tdSql.execute(f"create database twafill2 vgroups 1 buffer 32;")
tdSql.execute(f"use twafill2;")
tdSql.execute(
f"create stable st(ts timestamp, a int, b int, c int) tags(ta int, tb int, tc int);"
@ -178,7 +188,7 @@ class TestStreamOldCaseTwa:
def check1(self):
tdSql.checkResultsByFunc(
f"select * from twa_fwc_fill21.streamt;",
f"select * from twafill2.streamt;",
lambda: tdSql.getRows() > 0,
retry=100,
)
@ -199,13 +209,13 @@ class TestStreamOldCaseTwa:
else:
tdLog.info(f"triggered within 60000 ms (actual:{tcalc - tnow} ms).")
class TwaFwcFill22(StreamCheckItem):
class TwaFill3(StreamCheckItem):
def __init__(self):
self.db = "twa_fwc_fill22"
self.db = "twafill3"
def create(self):
tdSql.execute(f"create database test3 vgroups 1;")
tdSql.execute(f"use test3;")
tdSql.execute(f"create database twafill3 vgroups 1 buffer 8;")
tdSql.execute(f"use twafill3;")
tdSql.execute(
f"create stable st(ts timestamp, a int, b int, c int) tags(ta int, tb int, tc int);"
@ -213,7 +223,7 @@ class TestStreamOldCaseTwa:
tdSql.execute(f"create table t1 using st tags(1, 1, 1);")
tdSql.execute(f"create table t2 using st tags(2, 2, 2);")
tdSql.execute(
f"create stream streams3 trigger force_window_close IGNORE EXPIRED 1 IGNORE UPDATE 1 into streamt as select _wstart, twa(a), twa(b), elapsed(ts), now, timezone(), ta from st partition by tbname interval(2s) fill(value, 100, 200, 300);"
f"create stream streams3 interval(2s) sliding(2s) from st partition by tbname stream_options(expired_time(0s) | ignore_disorder) into streamt as select ts, case t1 when null then 100 else t1 end t1, case t2 when null then 100 else t2 end t2, case t3 when null then 100 else t3 end t3, t4, t5, ta from (select _twstart ts, twa(a) t1, twa(b) t2, elapsed(ts) t3, now t4, timezone() t5, ta from %%trows);"
)
def insert1(self):
@ -239,7 +249,7 @@ class TestStreamOldCaseTwa:
self.db = "twa_fwc_fill_pk1"
def create(self):
tdSql.execute(f"create database test vgroups 1;")
tdSql.execute(f"create database test vgroups 1 buffer 8;")
tdSql.execute(f"use test;")
tdSql.execute(
@ -283,11 +293,11 @@ class TestStreamOldCaseTwa:
class TwaFwcFillPK2(StreamCheckItem):
def __init__(self):
self.db = "twa_fwc_fill_pk2"
self.db = "twafwcfillpk2"
def create(self):
tdSql.execute(f"create database test2 vgroups 1;")
tdSql.execute(f"use test2;")
tdSql.execute(f"create database twafwcfillpk2 vgroups 1 buffer 8;")
tdSql.execute(f"use twafwcfillpk2;")
tdSql.execute(
f"create stable st(ts timestamp, a int primary key, b int, c int) tags(ta int, tb int, tc int);"
@ -295,7 +305,7 @@ class TestStreamOldCaseTwa:
tdSql.execute(f"create table t1 using st tags(1, 1, 1);")
tdSql.execute(f"create table t2 using st tags(2, 2, 2);")
tdSql.execute(
f"create stream streams2 trigger force_window_close IGNORE EXPIRED 1 IGNORE UPDATE 1 into streamt as select _wstart, twa(b), ta from st partition by tbname, ta interval(2s) fill(NULL);"
f"create stream streams2 interval(2s) sliding(2s) from st partition by tbname, ta stream_options(expired_time(0s) | ignore_disorder | FORCE_OUTPUT | max_delay(3s)) into streamt as select _twstart, twa(b), %%2 as ta2 from %%tbname where ts >= _twstart and ts < _twend;"
)
def insert1(self):
@ -319,24 +329,24 @@ class TestStreamOldCaseTwa:
tdSql.checkResultsByFunc(
f"select * from streamt where ta == 1;",
lambda: tdSql.getRows() >= 6 and tdSql.getData(0, 1) == query1_data,
lambda: tdSql.getRows() == 1 and tdSql.getData(0, 1) == query1_data,
)
tdLog.info(f"2 sql select * from streamt where ta == 2;")
tdSql.checkResultsByFunc(
f"select * from streamt where ta == 2;",
lambda: tdSql.getRows() >= 6 and tdSql.getData(0, 1) == query2_data,
lambda: tdSql.getRows() == 1 and tdSql.getData(0, 1) == query2_data,
)
class TwaFwcInterval1(StreamCheckItem):
def __init__(self):
self.db = "twa_fwc_interval1"
self.db = "twafwcinterval1"
def create(self):
tdLog.info(f"step1")
tdLog.info(f"=============== create database")
tdSql.execute(f"create database test vgroups 1 buffer 16;")
tdSql.execute(f"use test;")
tdSql.execute(f"create database twafwcinterval1 vgroups 1 buffer 16;")
tdSql.execute(f"use twafwcinterval1;")
tdSql.execute(
f"create stable st(ts timestamp, a int, b int, c int) tags(ta int, tb int, tc int);"
@ -345,23 +355,23 @@ class TestStreamOldCaseTwa:
tdSql.execute(f"create table t2 using st tags(2, 2, 2);")
tdSql.execute(
f"create stream streams1 trigger force_window_close IGNORE EXPIRED 1 IGNORE UPDATE 1 into streamt as select _wstart, twa(a), ta from st partition by tbname, ta interval(2s);"
f"create stream streams1 interval(2s) sliding(2s) from st partition by tbname, ta stream_options(expired_time(0s) | ignore_disorder | max_delay(3s)) into streamt as select _twstart, twa(a), _twend from %%tbname where ts >= _twstart and ts < _twend;"
)
def insert1(self):
tdSql.execute(
f"insert into t1 values(now + 3000a, 1, 1, 1) (now + 3100a, 5, 10, 10) (now + 3200a, 5, 10, 10) (now + 5100a, 20, 1, 1) (now + 5200a, 30, 10, 10) (now + 5300a, 40, 10, 10);"
f"insert into t1 values('2025-08-06 16:16:45.885', 1, 1, 1) ('2025-08-06 16:16:45.985', 5, 10, 10) ('2025-08-06 16:16:46.085', 5, 10, 10) ('2025-08-06 16:16:47.985', 20, 1, 1) ('2025-08-06 16:16:48.085', 30, 10, 10) ('2025-08-06 16:16:48.185', 40, 10, 10);"
)
tdSql.execute(
f"insert into t2 values(now + 3000a, 1, 1, 1) (now + 3100a, 2, 10, 10) (now + 3200a, 30, 10, 10) (now + 5100a, 10, 1, 1) (now + 5200a, 40, 10, 10) (now + 5300a, 7, 10, 10);"
f"insert into t2 values('2025-08-06 16:16:45.885', 1, 1, 1) ('2025-08-06 16:16:45.985', 2, 10, 10) ('2025-08-06 16:16:46.085', 30, 10, 10) ('2025-08-06 16:16:47.985', 10, 1, 1) ('2025-08-06 16:16:48.085', 40, 10, 10) ('2025-08-06 16:16:48.185', 7, 10, 10);"
)
def check1(self):
tdSql.query(f"select _wstart, twa(a) from t1 interval(2s);")
tdSql.query(f"select _wstart, twa(a), _wend from t1 interval(2s);")
query1_data01 = tdSql.getData(0, 1)
query1_data11 = tdSql.getData(1, 1)
tdSql.query(f"select _wstart, twa(a) from t2 interval(2s);")
tdSql.query(f"select _wstart, twa(a), _wend from t2 interval(2s);")
query2_data01 = tdSql.getData(0, 1)
query2_data11 = tdSql.getData(1, 1)
@ -381,11 +391,11 @@ class TestStreamOldCaseTwa:
class TwaFwcInterval2(StreamCheckItem):
def __init__(self):
self.db = "twa_fwc_interval2"
self.db = "twafwcinterval2"
def create(self):
tdSql.execute(f"create database test2 vgroups 4 buffer 16;")
tdSql.execute(f"use test2;")
tdSql.execute(f"create database twafwcinterval2 vgroups 4 buffer 16;")
tdSql.execute(f"use twafwcinterval2;")
tdSql.execute(
f"create stable st(ts timestamp, a int, b int, c int) tags(ta int, tb int, tc int);"
@ -394,7 +404,7 @@ class TestStreamOldCaseTwa:
tdSql.execute(f"create table t2 using st tags(2, 2, 2);")
tdSql.execute(
f"create stream streams2 trigger force_window_close IGNORE EXPIRED 1 IGNORE UPDATE 1 into streamt as select _wstart, count(*), ta from st partition by tbname, ta interval(2s);"
f"create stream streams2 interval(2s) sliding(2s) from st partition by tbname, ta stream_options(expired_time(0s) | ignore_disorder | max_delay(3s)) into streamt as select _wstart, count(*) from %%trows;"
)
def insert1(self):
@ -468,12 +478,12 @@ class TestStreamOldCaseTwa:
class TwaFwcInterval3(StreamCheckItem):
def __init__(self):
self.db = "twa_fwc_interval3"
self.db = "twafwcinterval3"
def create(self):
tdLog.info(f"======step3")
tdSql.execute(f"create database test3 vgroups 1 buffer 16;")
tdSql.execute(f"use test3;")
tdSql.execute(f"create database twafwcinterval3 vgroups 1 buffer 16;")
tdSql.execute(f"use twafwcinterval3;")
tdSql.execute(
f"create stable st(ts timestamp, a int, b int, c int) tags(ta int, tb int, tc int);"
@ -482,7 +492,7 @@ class TestStreamOldCaseTwa:
tdSql.execute(f"create table t2 using st tags(2, 2, 2);")
tdSql.execute(
f"create stream streams3 trigger force_window_close IGNORE EXPIRED 1 IGNORE UPDATE 1 into streamt3 as select _wstart, twa(a), ta from st partition by tbname, ta interval(10s);"
f"create stream streams3 interval(2s) sliding(2s) from st partition by tbname, ta stream_options(expired_time(0s) | ignore_disorder | max_delay(3s)) into streamt3 as select _wstart, twa(a), ta from st where tbname=%%tbname and ts >= _twstart and ts < _twend;"
)
def insert1(self):
@ -509,13 +519,13 @@ class TestStreamOldCaseTwa:
class TwaFwcIntervalPK(StreamCheckItem):
def __init__(self):
self.db = "twa_fwc_interval_pk"
self.db = "twafwcintervalpk"
def create(self):
tdLog.info(f"step1")
tdLog.info(f"=============== create database")
tdSql.execute(f"create database test vgroups 1;")
tdSql.execute(f"use test;")
tdSql.execute(f"create database twafwcintervalpk vgroups 1 buffer 8;")
tdSql.execute(f"use twafwcintervalpk;")
tdSql.execute(
f"create stable st(ts timestamp, a int primary key, b int, c int) tags(ta int, tb int, tc int);"
@ -524,7 +534,7 @@ class TestStreamOldCaseTwa:
tdSql.execute(f"create table t2 using st tags(2, 2, 2);")
tdSql.execute(
f"create stream streams1 trigger force_window_close IGNORE EXPIRED 1 IGNORE UPDATE 1 into streamt as select _wstart, count(*), ta from st partition by tbname, ta interval(2s);"
f"create stream streams1 interval(2s) sliding(2s) from st partition by tbname, ta stream_options(expired_time(0s) | ignore_disorder | max_delay(3s)) into streamt as select _wstart, count(*), ta from %%trows;"
)
def insert1(self):
@ -561,14 +571,14 @@ class TestStreamOldCaseTwa:
class TwaFwcInterp1(StreamCheckItem):
def __init__(self):
self.db = "twa_fwc_interp1"
self.db = "twafwcinterp1"
def create(self):
tdLog.info(f"step1")
tdLog.info(f"=============== create database")
tdSql.execute(f"create database test vgroups 4;")
tdSql.execute(f"use test;")
tdSql.execute(f"create database twafwcinterp1 vgroups 4 buffer 8;")
tdSql.execute(f"use twafwcinterp1;")
tdSql.execute(
f"create stable st(ts timestamp, a int, b int, c int) tags(ta int, tb int, tc int);"
@ -653,11 +663,11 @@ class TestStreamOldCaseTwa:
class TwaFwcInterp2(StreamCheckItem):
def __init__(self):
self.db = "twa_fwc_interp2"
self.db = "twafwcinterp2"
def create(self):
tdSql.execute(f"create database test4 vgroups 4;")
tdSql.execute(f"use test4;")
tdSql.execute(f"create database twafwcinterp2 vgroups 4 buffer 8;")
tdSql.execute(f"use twafwcinterp2;")
tdSql.execute(
f"create stable st(ts timestamp, a int, b int, c int) tags(ta int, tb int, tc int);"
@ -748,13 +758,13 @@ class TestStreamOldCaseTwa:
class TwaFwcInterp3(StreamCheckItem):
def __init__(self):
self.db = "twa_fwc_interp3"
self.db = "twafwcinterp3"
def create(self):
tdLog.info(f"=============== create database")
tdSql.execute(f"create database test4 vgroups 4;")
tdSql.execute(f"use test4;")
tdSql.execute(f"create database twafwcinterp3 vgroups 4 buffer 8;")
tdSql.execute(f"use twafwcinterp3;")
tdSql.execute(
f"create stable st(ts timestamp, a int, b int, c int) tags(ta int, tb int, tc int);"