Merge branch 'develop' into test/testcase
This commit is contained in:
commit
93e872166f
14
.travis.yml
14
.travis.yml
|
@ -34,6 +34,7 @@ matrix:
|
|||
- psmisc
|
||||
- unixodbc
|
||||
- unixodbc-dev
|
||||
- mono-complete
|
||||
|
||||
before_script:
|
||||
- export TZ=Asia/Harbin
|
||||
|
@ -59,6 +60,18 @@ matrix:
|
|||
pip3 install guppy3
|
||||
pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/
|
||||
|
||||
cd ${TRAVIS_BUILD_DIR}/tests/examples/C#/taosdemo
|
||||
mcs -out:taosdemo *.cs || travis_terminate $?
|
||||
pkill -TERM -x taosd
|
||||
fuser -k -n tcp 6030
|
||||
sleep 1
|
||||
${TRAVIS_BUILD_DIR}/debug/build/bin/taosd -c ${TRAVIS_BUILD_DIR}/debug/test/cfg > /dev/null &
|
||||
sleep 5
|
||||
mono taosdemo -Q DEFAULT -y || travis_terminate $?
|
||||
pkill -KILL -x taosd
|
||||
fuser -k -n tcp 6030
|
||||
sleep 1
|
||||
|
||||
cd ${TRAVIS_BUILD_DIR}/tests
|
||||
./test-all.sh smoke || travis_terminate $?
|
||||
sleep 1
|
||||
|
@ -74,6 +87,7 @@ matrix:
|
|||
./valgrind-test.sh 2>&1 > mem-error-out.log
|
||||
sleep 1
|
||||
|
||||
|
||||
# Color setting
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[1;32m'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
IF (CMAKE_VERSION VERSION_LESS 3.0)
|
||||
PROJECT(TDengine CXX)
|
||||
SET(PROJECT_VERSION_MAJOR "${LIB_MAJOR_VERSION}")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
ADD_SUBDIRECTORY(zlib-1.2.11)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
|
||||
# MQTT-C build options
|
||||
option(MQTT_C_OpenSSL_SUPPORT "Build MQTT-C with OpenSSL support?" OFF)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_WINDOWS)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_WINDOWS)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_WINDOWS)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_WINDOWS)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_WINDOWS)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_WINDOWS)
|
||||
|
|
|
@ -68,7 +68,9 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
|
|||
2) UPDATE 标志数据库支持更新相同时间戳数据;
|
||||
|
||||
3) 数据库名最大长度为33;
|
||||
|
||||
4) 一条SQL 语句的最大长度为65480个字符;
|
||||
|
||||
5) 数据库还有更多与存储相关的配置参数,请参见系统管理。
|
||||
|
||||
- **显示系统当前参数**
|
||||
|
@ -130,12 +132,37 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
|
|||
CREATE TABLE [IF NOT EXISTS] tb_name (timestamp_field_name TIMESTAMP, field1_name data_type1 [, field2_name data_type2 ...]);
|
||||
```
|
||||
说明:
|
||||
|
||||
1) 表的第一个字段必须是TIMESTAMP,并且系统自动将其设为主键;
|
||||
2) 表名最大长度为193;
|
||||
|
||||
2) 表名最大长度为192;
|
||||
|
||||
3) 表的每行长度不能超过16k个字符;
|
||||
|
||||
4) 子表名只能由字母、数字和下划线组成,且不能以数字开头
|
||||
|
||||
5) 使用数据类型binary或nchar,需指定其最长的字节数,如binary(20),表示20字节;
|
||||
|
||||
- **以超级表为模板创建数据表**
|
||||
|
||||
```mysql
|
||||
CREATE TABLE [IF NOT EXISTS] tb_name USING stb_name TAGS (tag_value1, ...);
|
||||
```
|
||||
以指定的超级表为模板,指定 tags 的值来创建数据表。
|
||||
|
||||
- **批量创建数据表**
|
||||
|
||||
```mysql
|
||||
CREATE TABLE [IF NOT EXISTS] tb_name1 USING stb_name TAGS (tag_value1, ...) tb_name2 USING stb_name TAGS (tag_value2, ...) ...;
|
||||
```
|
||||
以更快的速度批量创建大量数据表。(服务器端 2.0.14 及以上版本)
|
||||
|
||||
说明:
|
||||
|
||||
1)批量建表方式要求数据表必须以超级表为模板。
|
||||
|
||||
2)在不超出 SQL 语句长度限制的前提下,单条语句中的建表数量建议控制在 1000~3000 之间,将会获得比较理想的建表速度。
|
||||
|
||||
- **删除数据表**
|
||||
|
||||
```mysql
|
||||
|
@ -148,7 +175,11 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
|
|||
SHOW TABLES [LIKE tb_name_wildcar];
|
||||
```
|
||||
|
||||
显示当前数据库下的所有数据表信息。说明:可在 like 中使用通配符进行名称的匹配。 通配符匹配:1)“%”(百分号)匹配 0 到任意个字符;2)“\_”(下划线)匹配一个字符。
|
||||
显示当前数据库下的所有数据表信息。
|
||||
|
||||
说明:可在like中使用通配符进行名称的匹配,这一通配符字符串最长不能超过24字节。
|
||||
|
||||
通配符匹配:1)’%’ (百分号)匹配0到任意个字符;2)’\_’下划线匹配一个字符。
|
||||
|
||||
- **在线修改显示字符宽度**
|
||||
|
||||
|
@ -168,8 +199,10 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
|
|||
ALTER TABLE tb_name ADD COLUMN field_name data_type;
|
||||
```
|
||||
说明:
|
||||
|
||||
1) 列的最大个数为1024,最小个数为2;
|
||||
2) 列名最大长度为65;
|
||||
|
||||
2) 列名最大长度为64;
|
||||
|
||||
- **表删除列**
|
||||
|
||||
|
@ -187,10 +220,14 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
|
|||
创建STable, 与创建表的SQL语法相似,但需指定TAGS字段的名称和类型
|
||||
|
||||
说明:
|
||||
|
||||
1) TAGS 列的数据类型不能是timestamp类型;
|
||||
|
||||
2) TAGS 列名不能与其他列名相同;
|
||||
|
||||
3) TAGS 列名不能为预留关键字;
|
||||
4) TAGS 最多允许128个,可以0个,总长度不超过16k个字符
|
||||
|
||||
4) TAGS 最多允许128个,至少1个,总长度不超过16k个字符。
|
||||
|
||||
- **删除超级表**
|
||||
|
||||
|
@ -316,7 +353,9 @@ SELECT select_expr [, select_expr ...]
|
|||
[LIMIT limit_val [, OFFSET offset_val]]
|
||||
[>> export_file]
|
||||
```
|
||||
|
||||
说明:针对 insert 类型的 SQL 语句,我们采用的流式解析策略,在发现后面的错误之前,前面正确的部分SQL仍会执行。下面的sql中,insert语句是无效的,但是d1001仍会被创建。
|
||||
|
||||
```mysql
|
||||
taos> CREATE TABLE meters(ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS(location BINARY(30), groupId INT);
|
||||
Query OK, 0 row(s) affected (0.008245s)
|
||||
|
@ -551,8 +590,8 @@ Query OK, 1 row(s) in set (0.001091s)
|
|||
| % | match with any char sequences | **`binary`** **`nchar`** |
|
||||
| _ | match with a single char | **`binary`** **`nchar`** |
|
||||
|
||||
1. 同时进行多个字段的范围过滤需要使用关键词AND进行连接不同的查询条件,暂不支持OR连接的不同列之间的查询过滤条件。
|
||||
2. 针对某一字段的过滤只支持单一时间区间过滤条件。但是针对其他的(普通)列或标签列,可以使用``` OR``` 条件进行组合条件的查询过滤。例如:((value > 20 and value < 30) OR (value < 12)) 。
|
||||
1. 同时进行多个字段的范围过滤,需要使用关键词 AND 来连接不同的查询条件,暂不支持 OR 连接的不同列之间的查询过滤条件。
|
||||
2. 针对单一字段的过滤,如果是时间过滤条件,则一条语句中只支持设定一个;但针对其他的(普通)列或标签列,则可以使用``` OR``` 关键字进行组合条件的查询过滤。例如:((value > 20 and value < 30) OR (value < 12)) 。
|
||||
|
||||
### SQL 示例
|
||||
|
||||
|
@ -597,10 +636,20 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT COUNT([*|field_name]) FROM tb_name [WHERE clause];
|
||||
```
|
||||
功能说明:统计表/超级表中记录行数或某列的非空值个数。
|
||||
|
||||
返回结果数据类型:长整型INT64。
|
||||
|
||||
应用字段:应用全部字段。
|
||||
|
||||
适用于:表、超级表。
|
||||
说明:1)可以使用星号*来替代具体的字段,使用星号(*)返回全部记录数量。2)针对同一表的(不包含NULL值)字段查询结果均相同。3)如果统计对象是具体的列,则返回该列中非NULL值的记录数量。
|
||||
|
||||
说明:
|
||||
|
||||
1)可以使用星号*来替代具体的字段,使用星号(*)返回全部记录数量。
|
||||
|
||||
2)针对同一表的(不包含NULL值)字段查询结果均相同。
|
||||
|
||||
3)如果统计对象是具体的列,则返回该列中非NULL值的记录数量。
|
||||
|
||||
示例:
|
||||
```mysql
|
||||
|
@ -622,8 +671,11 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT AVG(field_name) FROM tb_name [WHERE clause];
|
||||
```
|
||||
功能说明:统计表/超级表中某列的平均值。
|
||||
|
||||
返回结果数据类型:双精度浮点数Double。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool字段。
|
||||
|
||||
适用于:表、超级表。
|
||||
|
||||
示例:
|
||||
|
@ -646,9 +698,11 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT TWA(field_name) FROM tb_name WHERE clause;
|
||||
```
|
||||
功能说明:时间加权平均函数。统计表/超级表中某列在一段时间内的时间加权平均。
|
||||
|
||||
返回结果数据类型:双精度浮点数Double。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
说明:时间加权平均(time weighted average, TWA)查询需要指定查询时间段的 _开始时间_ 和 _结束时间_ 。
|
||||
|
||||
适用于:表、超级表。
|
||||
|
||||
- **SUM**
|
||||
|
@ -656,8 +710,11 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT SUM(field_name) FROM tb_name [WHERE clause];
|
||||
```
|
||||
功能说明:统计表/超级表中某列的和。
|
||||
|
||||
返回结果数据类型:双精度浮点数Double和长整型INT64。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:表、超级表。
|
||||
|
||||
示例:
|
||||
|
@ -680,8 +737,11 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
|
||||
```
|
||||
功能说明:统计表中某列的均方差。
|
||||
|
||||
返回结果数据类型:双精度浮点数Double。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
适用于:表。
|
||||
|
||||
示例:
|
||||
|
@ -698,9 +758,13 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause];
|
||||
```
|
||||
功能说明:统计表中某列的值是主键(时间戳)的拟合直线方程。start_val是自变量初始值,step_val是自变量的步长值。
|
||||
|
||||
返回结果数据类型:字符串表达式(斜率, 截距)。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
说明:自变量是时间戳,因变量是该列的值。
|
||||
|
||||
适用于:表。
|
||||
|
||||
示例:
|
||||
|
@ -719,7 +783,9 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
|
||||
```
|
||||
功能说明:统计表/超级表中某列的值最小值。
|
||||
|
||||
返回结果数据类型:同应用的字段。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
示例:
|
||||
|
@ -742,7 +808,9 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
功能说明:统计表/超级表中某列的值最大值。
|
||||
|
||||
返回结果数据类型:同应用的字段。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
示例:
|
||||
|
@ -765,9 +833,18 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
功能说明:统计表/超级表中某列的值最先写入的非NULL值。
|
||||
|
||||
返回结果数据类型:同应用的字段。
|
||||
|
||||
应用字段:所有字段。
|
||||
说明:1)如果要返回各个列的首个(时间戳最小)非NULL值,可以使用FIRST(\*);2) 如果结果集中的某列全部为NULL值,则该列的返回结果也是NULL;3) 如果结果集中所有列全部为NULL值,则不返回结果。
|
||||
|
||||
说明:
|
||||
|
||||
1)如果要返回各个列的首个(时间戳最小)非NULL值,可以使用FIRST(\*);
|
||||
|
||||
2) 如果结果集中的某列全部为NULL值,则该列的返回结果也是NULL;
|
||||
|
||||
3) 如果结果集中所有列全部为NULL值,则不返回结果。
|
||||
|
||||
示例:
|
||||
```mysql
|
||||
|
@ -789,9 +866,16 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
功能说明:统计表/超级表中某列的值最后写入的非NULL值。
|
||||
|
||||
返回结果数据类型:同应用的字段。
|
||||
|
||||
应用字段:所有字段。
|
||||
说明:1)如果要返回各个列的最后(时间戳最大)一个非NULL值,可以使用LAST(\*);2)如果结果集中的某列全部为NULL值,则该列的返回结果也是NULL;如果结果集中所有列全部为NULL值,则不返回结果。
|
||||
|
||||
说明:
|
||||
|
||||
1)如果要返回各个列的最后(时间戳最大)一个非NULL值,可以使用LAST(\*);
|
||||
|
||||
2)如果结果集中的某列全部为NULL值,则该列的返回结果也是NULL;如果结果集中所有列全部为NULL值,则不返回结果。
|
||||
|
||||
示例:
|
||||
```mysql
|
||||
|
@ -813,9 +897,16 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
功能说明: 统计表/超级表中某列的值最大*k*个非NULL值。若多于k个列值并列最大,则返回时间戳小的。
|
||||
|
||||
返回结果数据类型:同应用的字段。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
说明:1)*k*值取值范围1≤*k*≤100;2)系统同时返回该记录关联的时间戳列。
|
||||
|
||||
说明:
|
||||
|
||||
1)*k*值取值范围1≤*k*≤100;
|
||||
|
||||
2)系统同时返回该记录关联的时间戳列。
|
||||
|
||||
示例:
|
||||
```mysql
|
||||
|
@ -840,9 +931,16 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
功能说明:统计表/超级表中某列的值最小*k*个非NULL值。若多于k个列值并列最小,则返回时间戳小的。
|
||||
|
||||
返回结果数据类型:同应用的字段。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
说明:1)*k*值取值范围1≤*k*≤100;2)系统同时返回该记录关联的时间戳列。
|
||||
|
||||
说明:
|
||||
|
||||
1)*k*值取值范围1≤*k*≤100;
|
||||
|
||||
2)系统同时返回该记录关联的时间戳列。
|
||||
|
||||
示例:
|
||||
```mysql
|
||||
|
@ -866,8 +964,11 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT PERCENTILE(field_name, P) FROM { tb_name } [WHERE clause];
|
||||
```
|
||||
功能说明:统计表中某列的值百分比分位数。
|
||||
|
||||
返回结果数据类型: 双精度浮点数Double。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
说明:*P*值取值范围0≤*P*≤100,为0的时候等同于MIN,为100的时候等同于MAX。
|
||||
|
||||
示例:
|
||||
|
@ -884,9 +985,13 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT APERCENTILE(field_name, P) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
功能说明:统计表中某列的值百分比分位数,与PERCENTILE函数相似,但是返回近似结果。
|
||||
|
||||
返回结果数据类型: 双精度浮点数Double。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
说明:*P*值取值范围0≤*P*≤100,为0的时候等同于MIN,为100的时候等同于MAX。推荐使用```APERCENTILE```函数,该函数性能远胜于```PERCENTILE```函数
|
||||
|
||||
```mysql
|
||||
taos> SELECT APERCENTILE(current, 20) FROM d1001;
|
||||
apercentile(current, 20) |
|
||||
|
@ -900,8 +1005,11 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT LAST_ROW(field_name) FROM { tb_name | stb_name };
|
||||
```
|
||||
功能说明:返回表(超级表)的最后一条记录。
|
||||
|
||||
返回结果数据类型:同应用的字段。
|
||||
|
||||
应用字段:所有字段。
|
||||
|
||||
说明:与last函数不同,last_row不支持时间范围限制,强制返回最后一条记录。
|
||||
|
||||
示例:
|
||||
|
@ -925,8 +1033,11 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT DIFF(field_name) FROM tb_name [WHERE clause];
|
||||
```
|
||||
功能说明:统计表中某列的值与前一行对应值的差。
|
||||
|
||||
返回结果数据类型: 同应用字段。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
|
||||
说明:输出结果行数是范围内总行数减一,第一行没有结果输出。
|
||||
|
||||
示例:
|
||||
|
@ -944,8 +1055,11 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
功能说明:统计表/超级表中某列的最大值和最小值之差。
|
||||
|
||||
返回结果数据类型: 双精度浮点数。
|
||||
|
||||
应用字段:不能应用在binary、nchar、bool类型字段。
|
||||
|
||||
说明:可用于TIMESTAMP字段,此时表示记录的时间覆盖范围。
|
||||
|
||||
示例:
|
||||
|
@ -969,9 +1083,16 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
SELECT field_name [+|-|*|/|%][Value|field_name] FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
功能说明:统计表/超级表中某列或多列间的值加、减、乘、除、取余计算结果。
|
||||
|
||||
返回结果数据类型:双精度浮点数。
|
||||
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
说明:1)支持两列或多列之间进行计算,可使用括号控制计算优先级;2)NULL字段不参与计算,如果参与计算的某行中包含NULL,该行的计算结果为NULL。
|
||||
|
||||
说明:
|
||||
|
||||
1)支持两列或多列之间进行计算,可使用括号控制计算优先级;
|
||||
|
||||
2)NULL字段不参与计算,如果参与计算的某行中包含NULL,该行的计算结果为NULL。
|
||||
|
||||
```mysql
|
||||
taos> SELECT current + voltage * phase FROM d1001;
|
||||
|
|
|
@ -105,7 +105,7 @@ taosd -C
|
|||
- queryBufferSize: 为所有并发查询占用保留的内存大小。计算规则可以根据实际应用可能的最大并发数和表的数字相乘,再乘 170 。单位为字节。
|
||||
- ratioOfQueryCores: 设置查询线程的最大数量。最小值0 表示只有1个查询线程;最大值2表示最大建立2倍CPU核数的查询线程。默认为1,表示最大和CPU核数相等的查询线程。该值可以为小数,即0.5表示最大建立CPU核数一半的查询线程。
|
||||
|
||||
**注意:**对于端口,TDengine会使用从serverPort起13个连续的TCP和UDP端口号,请务必在防火墙打开。因此如果是缺省配置,需要打开从6030都6042共13个端口,而且必须TCP和UDP都打开。
|
||||
**注意:**对于端口,TDengine会使用从serverPort起13个连续的TCP和UDP端口号,请务必在防火墙打开。因此如果是缺省配置,需要打开从6030到6042共13个端口,而且必须TCP和UDP都打开。
|
||||
|
||||
不同应用场景的数据往往具有不同的数据特征,比如保留天数、副本数、采集频次、记录大小、采集点的数量、压缩等都可完全不同。为获得在存储上的最高效率,TDengine提供如下存储相关的系统配置参数:
|
||||
|
||||
|
@ -255,7 +255,7 @@ taos -C 或 taos --dump-config
|
|||
CREATE USER <user_name> PASS <'password'>;
|
||||
```
|
||||
|
||||
创建用户,并指定用户名和密码,密码需要用单引号引起来,单引号为英文半角
|
||||
创建用户,并指定用户名和密码,密码需要用单引号引起来,单引号为英文半角
|
||||
|
||||
```sql
|
||||
DROP USER <user_name>;
|
||||
|
@ -267,13 +267,15 @@ DROP USER <user_name>;
|
|||
ALTER USER <user_name> PASS <'password'>;
|
||||
```
|
||||
|
||||
修改用户密码, 为避免被转换为小写,密码需要用单引号引用,单引号为英文半角
|
||||
修改用户密码,为避免被转换为小写,密码需要用单引号引用,单引号为英文半角
|
||||
|
||||
```sql
|
||||
ALTER USER <user_name> PRIVILEGE <super|write|read>;
|
||||
ALTER USER <user_name> PRIVILEGE <write|read>;
|
||||
```
|
||||
|
||||
修改用户权限为:super/write/read,不需要添加单引号
|
||||
修改用户权限为:write 或 read,不需要添加单引号
|
||||
|
||||
说明:系统内共有 super/write/read 三种权限级别,但目前不允许通过 alter 指令把 super 权限赋予用户。
|
||||
|
||||
```mysql
|
||||
SHOW USERS;
|
||||
|
@ -432,11 +434,12 @@ TDengine的所有可执行文件默认存放在 _/usr/local/taos/bin_ 目录下
|
|||
- 数据库名:不能包含“.”以及特殊字符,不能超过32个字符
|
||||
- 表名:不能包含“.”以及特殊字符,与所属数据库名一起,不能超过192个字符
|
||||
- 表的列名:不能包含特殊字符,不能超过64个字符
|
||||
- 数据库名、表名、列名,都不能以数字开头
|
||||
- 表的列数:不能超过1024列
|
||||
- 记录的最大长度:包括时间戳8 byte,不能超过16KB
|
||||
- 单条SQL语句默认最大字符串长度:65480 byte
|
||||
- 数据库副本数:不能超过3
|
||||
- 用户名:不能超过20个byte
|
||||
- 用户名:不能超过23个byte
|
||||
- 用户密码:不能超过15个byte
|
||||
- 标签(Tags)数量:不能超过128个
|
||||
- 标签的总长度:不能超过16Kbyte
|
||||
|
|
|
@ -89,6 +89,8 @@ SHOW DNODES;
|
|||
```
|
||||
它将列出集群中所有的dnode,每个dnode的fqdn:port, 状态(ready, offline等),vnode数目,还未使用的vnode数目等信息。在添加或删除一个节点后,可以使用该命令查看。
|
||||
|
||||
如果集群配置了Arbitrator,那么它也会在这个节点列表中显示出来,其role列的值会是“arb”。
|
||||
|
||||
###查看虚拟节点组
|
||||
|
||||
为充分利用多核技术,并提供scalability,数据需要分片处理。因此TDengine会将一个DB的数据切分成多份,存放在多个vnode里。这些vnode可能分布在多个dnode里,这样就实现了水平扩展。一个vnode仅仅属于一个DB,但一个DB可以有多个vnode。vnode的是mnode根据当前系统资源的情况,自动进行分配的,无需任何人工干预。
|
||||
|
@ -139,4 +141,6 @@ SHOW MNODES;
|
|||
|
||||
如果副本数为偶数,当一个vnode group里一半vnode不工作时,是无法从中选出master的。同理,一半mnode不工作时,是无法选出mnode的master的,因为存在“split brain”问题。为解决这个问题,TDengine引入了arbitrator的概念。Arbitrator模拟一个vnode或mnode在工作,但只简单的负责网络连接,不处理任何数据插入或访问。只要包含arbitrator在内,超过半数的vnode或mnode工作,那么该vnode group或mnode组就可以正常的提供数据插入或查询服务。比如对于副本数为2的情形,如果一个节点A离线,但另外一个节点B正常,而且能连接到arbitrator, 那么节点B就能正常工作。
|
||||
|
||||
TDengine安装包里带有一个执行程序tarbitrator, 找任何一台Linux服务器运行它即可。该程序对系统资源几乎没有要求,只需要保证有网络连接即可。该应用的命令行参数`-p`可以指定其对外服务的端口号,缺省是6030。配置每个taosd实例时,可以在配置文件taos.cfg里将参数arbitrator设置为arbitrator的End Point。如果该参数配置了,当副本数为偶数数,系统将自动连接配置的arbitrator。
|
||||
TDengine安装包里带有一个执行程序tarbitrator, 找任何一台Linux服务器运行它即可。该程序对系统资源几乎没有要求,只需要保证有网络连接即可。该应用的命令行参数`-p`可以指定其对外服务的端口号,缺省是6030。配置每个taosd实例时,可以在配置文件taos.cfg里将参数arbitrator设置为Arbitrator的End Point。如果该参数配置了,当副本数为偶数数,系统将自动连接配置的Arbitrator。
|
||||
|
||||
在配置了Arbitrator的情况下,它也会显示在“show dnodes;”指令给出的节点列表中。
|
||||
|
|
|
@ -178,11 +178,11 @@ C/C++的API类似于MySQL的C API。应用程序使用时,需要包含TDengine
|
|||
|
||||
获取客户端版本信息。
|
||||
|
||||
- `TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, int port)`
|
||||
- `TAOS *taos_connect(const char *host, const char *user, const char *pass, const char *db, int port)`
|
||||
|
||||
创建数据库连接,初始化连接上下文。其中需要用户提供的参数包含:
|
||||
|
||||
- ip:TDengine管理主节点的IP地址
|
||||
- host:TDengine管理主节点的FQDN
|
||||
- user:用户名
|
||||
- pass:密码
|
||||
- db:数据库名字,如果用户没有提供,也可以正常连接,用户可以通过该连接创建新的数据库,如果用户提供了数据库名字,则说明该数据库用户已经创建好,缺省使用该数据库
|
||||
|
@ -252,7 +252,7 @@ C/C++的API类似于MySQL的C API。应用程序使用时,需要包含TDengine
|
|||
|
||||
- `void taos_free_result(TAOS_RES *res)`
|
||||
|
||||
释放查询结果集以及相关的资源。查询完成后,务必调用该API释放资源,否则可能导致应用内存泄露。
|
||||
释放查询结果集以及相关的资源。查询完成后,务必调用该API释放资源,否则可能导致应用内存泄露。但也需注意,释放资源后,如果再调用`taos_consume`等获取查询结果的函数,将导致应用Crash。
|
||||
|
||||
- `char *taos_errstr(TAOS_RES *res)`
|
||||
|
||||
|
@ -262,11 +262,11 @@ C/C++的API类似于MySQL的C API。应用程序使用时,需要包含TDengine
|
|||
|
||||
获取最近一次API调用失败的原因,返回值为错误代码。
|
||||
|
||||
**注意**:对于每个数据库应用,2.0及以上版本 TDengine 推荐只建立一个连接。同时在应用中将该连接 (TAOS*) 结构体传递到不同的线程共享使用。基于 TAOS 结构体发出的查询、写入等操作具有多线程安全性。C 语言的连接器可以按照需求动态建立面向数据库的新连接(该过程对用户不可见),同时建议只有在程序最后退出的时候才调用 taos_close 关闭连接。
|
||||
**注意**:2.0及以上版本 TDengine 推荐数据库应用的每个线程都建立一个独立的连接,或基于线程建立连接池。而不推荐在应用中将该连接 (TAOS\*) 结构体传递到不同的线程共享使用。基于 TAOS 结构体发出的查询、写入等操作具有多线程安全性,但 “USE statement” 等状态量有可能在线程之间相互干扰。此外,C 语言的连接器可以按照需求动态建立面向数据库的新连接(该过程对用户不可见),同时建议只有在程序最后退出的时候才调用 taos_close 关闭连接。
|
||||
|
||||
### 异步查询API
|
||||
|
||||
同步API之外,TDengine还提供性能更高的异步调用API处理数据插入、查询操作。在软硬件环境相同的情况下,异步API处理数据插入的速度比同步API快2~4倍。异步API采用非阻塞式的调用方式,在系统真正完成某个具体数据库操作前,立即返回。调用的线程可以去处理其他工作,从而可以提升整个应用的性能。异步API在网络延迟严重的情况下,优点尤为突出。
|
||||
同步API之外,TDengine还提供性能更高的异步调用API处理数据插入、查询操作。在软硬件环境相同的情况下,异步API处理数据插入的速度比同步API快2\~4倍。异步API采用非阻塞式的调用方式,在系统真正完成某个具体数据库操作前,立即返回。调用的线程可以去处理其他工作,从而可以提升整个应用的性能。异步API在网络延迟严重的情况下,优点尤为突出。
|
||||
|
||||
异步API都需要应用提供相应的回调函数,回调函数参数设置如下:前两个参数都是一致的,第三个参数依不同的API而定。第一个参数param是应用调用异步API时提供给系统的,用于回调时,应用能够找回具体操作的上下文,依具体实现而定。第二个参数是SQL操作的结果集,如果为空,比如insert操作,表示没有记录返回,如果不为空,比如select操作,表示有记录返回。
|
||||
|
||||
|
@ -425,7 +425,7 @@ cd C:\TDengine\connector\python\windows
|
|||
python -m pip install python3\
|
||||
```
|
||||
|
||||
*如果机器上没有pip命令,用户可将src/connector/python/python3或src/connector/python/python2下的taos文件夹拷贝到应用程序的目录使用。
|
||||
* 如果机器上没有pip命令,用户可将src/connector/python/python3或src/connector/python/python2下的taos文件夹拷贝到应用程序的目录使用。
|
||||
对于windows 客户端,安装TDengine windows 客户端后,将C:\TDengine\driver\taos.dll拷贝到C:\windows\system32目录下即可。
|
||||
|
||||
### 使用
|
||||
|
@ -442,7 +442,7 @@ import taos
|
|||
conn = taos.connect(host="127.0.0.1", user="root", password="taosdata", config="/etc/taos")
|
||||
c1 = conn.cursor()
|
||||
```
|
||||
*<em>host</em> 是TDengine 服务端所有IP, <em>config</em> 为客户端配置文件所在目录
|
||||
* <em>host</em> 是TDengine 服务端所有IP, <em>config</em> 为客户端配置文件所在目录
|
||||
|
||||
* 写入数据
|
||||
```python
|
||||
|
@ -510,17 +510,17 @@ conn.close()
|
|||
|
||||
用户可通过python的帮助信息直接查看模块的使用信息,或者参考tests/examples/python中的示例程序。以下为部分常用类和方法:
|
||||
|
||||
- _TDengineConnection_类
|
||||
- _TDengineConnection_ 类
|
||||
|
||||
参考python中help(taos.TDengineConnection)。
|
||||
这个类对应客户端和TDengine建立的一个连接。在客户端多线程的场景下,这个连接实例可以是每个线程申请一个,也可以多线程共享一个连接。
|
||||
这个类对应客户端和TDengine建立的一个连接。在客户端多线程的场景下,推荐每个线程申请一个独立的连接实例,而不建议多线程共享一个连接。
|
||||
|
||||
- _TDengineCursor_类
|
||||
- _TDengineCursor_ 类
|
||||
|
||||
参考python中help(taos.TDengineCursor)。
|
||||
这个类对应客户端进行的写入、查询操作。在客户端多线程的场景下,这个游标实例必须保持线程独享,不能夸线程共享使用,否则会导致返回结果出现错误。
|
||||
|
||||
- _connect_方法
|
||||
- _connect_ 方法
|
||||
|
||||
用于生成taos.TDengineConnection的实例。
|
||||
|
||||
|
@ -800,7 +800,7 @@ go env -w GOPROXY=https://goproxy.io,direct
|
|||
|
||||
- `sql.Open(DRIVER_NAME string, dataSourceName string) *DB`
|
||||
|
||||
该API用来打开DB,返回一个类型为*DB的对象,一般情况下,DRIVER_NAME设置为字符串`taosSql`, dataSourceName设置为字符串`user:password@/tcp(host:port)/dbname`,如果客户想要用多个goroutine并发访问TDengine, 那么需要在各个goroutine中分别创建一个sql.Open对象并用之访问TDengine
|
||||
该API用来打开DB,返回一个类型为\*DB的对象,一般情况下,DRIVER_NAME设置为字符串`taosSql`, dataSourceName设置为字符串`user:password@/tcp(host:port)/dbname`,如果客户想要用多个goroutine并发访问TDengine, 那么需要在各个goroutine中分别创建一个sql.Open对象并用之访问TDengine
|
||||
|
||||
**注意**: 该API成功创建的时候,并没有做权限等检查,只有在真正执行Query或者Exec的时候才能真正的去创建连接,并同时检查user/password/host/port是不是合法。 另外,由于整个驱动程序大部分实现都下沉到taosSql所依赖的libtaos中。所以,sql.Open本身特别轻量。
|
||||
|
||||
|
@ -822,7 +822,7 @@ go env -w GOPROXY=https://goproxy.io,direct
|
|||
|
||||
- `func (s *Stmt) Query(args ...interface{}) (*Rows, error)`
|
||||
|
||||
sql.Open内置的方法,Query executes a prepared query statement with the given arguments and returns the query results as a *Rows.
|
||||
sql.Open内置的方法,Query executes a prepared query statement with the given arguments and returns the query results as a \*Rows.
|
||||
|
||||
- `func (s *Stmt) Close() error`
|
||||
|
||||
|
@ -894,7 +894,7 @@ Node-example-raw.js
|
|||
|
||||
验证方法:
|
||||
|
||||
1. 新建安装验证目录,例如:~/tdengine-test,拷贝github上nodejsChecker.js源程序。下载地址:(https://github.com/taosdata/TDengine/tree/develop/tests/examples/nodejs/nodejsChecker.js)。
|
||||
1. 新建安装验证目录,例如:\~/tdengine-test,拷贝github上nodejsChecker.js源程序。下载地址:(https://github.com/taosdata/TDengine/tree/develop/tests/examples/nodejs/nodejsChecker.js)。
|
||||
|
||||
2. 在命令中执行以下命令:
|
||||
|
||||
|
|
|
@ -72,9 +72,6 @@
|
|||
# time interval of heart beat from shell to dnode, seconds
|
||||
# shellActivityTimer 3
|
||||
|
||||
# time of keeping table meta data in cache, seconds
|
||||
# tableMetaKeepTimer 7200
|
||||
|
||||
# minimum sliding window time, milli-second
|
||||
# minSlidingTime 10
|
||||
|
||||
|
@ -162,10 +159,10 @@
|
|||
# stop writing logs when the disk size of the log folder is less than this value
|
||||
# minimalLogDirGB 0.1
|
||||
|
||||
# stop writing temporary files when the disk size of the log folder is less than this value
|
||||
# stop writing temporary files when the disk size of the tmp folder is less than this value
|
||||
# minimalTmpDirGB 0.1
|
||||
|
||||
# stop writing data when the disk size of the log folder is less than this value
|
||||
# if disk free space is less than this value, taosd service exit directly within startup process
|
||||
# minimalDataDirGB 0.1
|
||||
|
||||
# One mnode is equal to the number of vnode consumed
|
||||
|
|
|
@ -348,7 +348,7 @@ function set_ipAsFqdn() {
|
|||
}
|
||||
|
||||
function local_fqdn_check() {
|
||||
#serverFqdn=$(hostname -f)
|
||||
#serverFqdn=$(hostname)
|
||||
echo
|
||||
echo -e -n "System hostname is: ${GREEN}$serverFqdn${NC}"
|
||||
echo
|
||||
|
@ -911,7 +911,7 @@ function install_TDengine() {
|
|||
|
||||
|
||||
## ==============================Main program starts from here============================
|
||||
serverFqdn=$(hostname -f)
|
||||
serverFqdn=$(hostname)
|
||||
if [ "$verType" == "server" ]; then
|
||||
# Install server and client
|
||||
if [ -x ${bin_dir}/taosd ]; then
|
||||
|
|
|
@ -345,7 +345,7 @@ function set_ipAsFqdn() {
|
|||
}
|
||||
|
||||
function local_fqdn_check() {
|
||||
#serverFqdn=$(hostname -f)
|
||||
#serverFqdn=$(hostname)
|
||||
echo
|
||||
echo -e -n "System hostname is: ${GREEN}$serverFqdn${NC}"
|
||||
echo
|
||||
|
@ -881,7 +881,7 @@ function install_PowerDB() {
|
|||
|
||||
|
||||
## ==============================Main program starts from here============================
|
||||
serverFqdn=$(hostname -f)
|
||||
serverFqdn=$(hostname)
|
||||
if [ "$verType" == "server" ]; then
|
||||
# Install server and client
|
||||
if [ -x ${bin_dir}/powerd ]; then
|
||||
|
|
|
@ -228,7 +228,7 @@ function set_ipAsFqdn() {
|
|||
}
|
||||
|
||||
function local_fqdn_check() {
|
||||
#serverFqdn=$(hostname -f)
|
||||
#serverFqdn=$(hostname)
|
||||
echo
|
||||
echo -e -n "System hostname is: ${GREEN}$serverFqdn${NC}"
|
||||
echo
|
||||
|
@ -492,5 +492,5 @@ function install_TDengine() {
|
|||
|
||||
|
||||
## ==============================Main program starts from here============================
|
||||
serverFqdn=$(hostname -f)
|
||||
serverFqdn=$(hostname)
|
||||
install_TDengine
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
# Base compile
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/inc)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
|
|
|
@ -43,6 +43,11 @@ TAOS_ROW doSetResultRowData(SSqlObj *pSql);
|
|||
|
||||
char *getArithmeticInputSrc(void *param, const char *name, int32_t colId);
|
||||
|
||||
void tscLockByThread(int64_t *lockedBy);
|
||||
|
||||
void tscUnlockByThread(int64_t *lockedBy);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -26,7 +26,7 @@ extern "C" {
|
|||
|
||||
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
|
||||
|
||||
//struct SSchema;
|
||||
#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS)
|
||||
|
||||
/**
|
||||
* get the number of tags of this table
|
||||
|
@ -91,7 +91,7 @@ SSchema* tscGetColumnSchemaById(STableMeta* pTableMeta, int16_t colId);
|
|||
* @param numOfCols
|
||||
* @return
|
||||
*/
|
||||
bool isValidSchema(struct SSchema *pSchema, int32_t numOfCols);
|
||||
bool isValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
|
||||
|
||||
/**
|
||||
* get the schema for the "tbname" column. it is a built column
|
||||
|
|
|
@ -300,8 +300,8 @@ typedef struct STscObj {
|
|||
void * pTimer;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
char acctId[TSDB_ACCT_LEN];
|
||||
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||
char acctId[TSDB_ACCT_ID_LEN];
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
char sversion[TSDB_VERSION_LEN];
|
||||
char writeAuth : 1;
|
||||
char superAuth : 1;
|
||||
|
@ -347,6 +347,11 @@ typedef struct SSqlObj {
|
|||
SSubqueryState subState;
|
||||
struct SSqlObj **pSubs;
|
||||
|
||||
int64_t metaRid;
|
||||
int64_t svgroupRid;
|
||||
|
||||
int64_t squeryLock;
|
||||
|
||||
struct SSqlObj *prev, *next;
|
||||
int64_t self;
|
||||
} SSqlObj;
|
||||
|
@ -460,7 +465,7 @@ static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pField
|
|||
} else {
|
||||
assert(bytes == tDataTypeDesc[type].nSize);
|
||||
|
||||
pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : (unsigned char*)&pInfo->pSqlExpr->param[1].i64Key;
|
||||
pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : (unsigned char*)&pInfo->pSqlExpr->param[1].i64;
|
||||
pRes->length[columnIndex] = bytes;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -95,7 +95,7 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa
|
|||
return;
|
||||
}
|
||||
|
||||
nPrintTsc(sqlstr);
|
||||
nPrintTsc("%s", sqlstr);
|
||||
|
||||
SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
|
||||
if (pSql == NULL) {
|
||||
|
@ -365,7 +365,7 @@ static void tscProcessAsyncError(SSchedMsg *pMsg) {
|
|||
void (*fp)() = pMsg->ahandle;
|
||||
terrno = *(int32_t*) pMsg->msg;
|
||||
tfree(pMsg->msg);
|
||||
(*fp)(pMsg->thandle, NULL, *(int32_t*)pMsg->msg);
|
||||
(*fp)(pMsg->thandle, NULL, terrno);
|
||||
}
|
||||
|
||||
void tscQueueAsyncError(void(*fp), void *param, int32_t code) {
|
||||
|
@ -388,7 +388,7 @@ void tscAsyncResultOnError(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
assert(pSql->res.code != TSDB_CODE_SUCCESS);
|
||||
tscError("%p add into queued async res, code:%s", pSql, tstrerror(pSql->res.code));
|
||||
tscError("%p invoke user specified function due to error occured, code:%s", pSql, tstrerror(pSql->res.code));
|
||||
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
if (pSql->fp == NULL || pSql->fetchFp == NULL){
|
||||
|
@ -402,8 +402,10 @@ void tscAsyncResultOnError(SSqlObj *pSql) {
|
|||
int tscSendMsgToServer(SSqlObj *pSql);
|
||||
|
||||
void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||
SSqlObj *pSql = (SSqlObj *)param;
|
||||
if (pSql == NULL || pSql->signature != pSql) return;
|
||||
SSqlObj* pSql = (SSqlObj*)taosAcquireRef(tscObjRef, (int64_t)param);
|
||||
if (pSql == NULL) return;
|
||||
|
||||
assert(pSql->signature == pSql && (int64_t)param == pSql->self);
|
||||
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
@ -428,7 +430,8 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||
assert(code == TSDB_CODE_TSC_ACTION_IN_PROGRESS || code == TSDB_CODE_SUCCESS);
|
||||
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -436,6 +439,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
|
||||
// tscProcessSql can add error into async res
|
||||
tscProcessSql(pSql);
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
} else { // continue to process normal async query
|
||||
if (pCmd->parseFinished) {
|
||||
|
@ -446,6 +450,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
|
||||
assert(code == TSDB_CODE_TSC_ACTION_IN_PROGRESS || code == TSDB_CODE_SUCCESS);
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -458,6 +463,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
|
||||
code = tsParseSql(pSql, true);
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
} else if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
@ -468,12 +474,14 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
tscProcessSql(pSql);
|
||||
}
|
||||
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
} else {
|
||||
tscDebug("%p continue parse sql after get table meta", pSql);
|
||||
|
||||
code = tsParseSql(pSql, false);
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
} else if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
@ -483,12 +491,14 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
} else {
|
||||
assert(code == TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
(*pSql->fp)(pSql->param, pSql, code);
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -501,6 +511,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
|
||||
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
} else if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
@ -509,6 +520,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
||||
code = tscGetSTableVgroupInfo(pSql, pCmd->clauseIndex);
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
return;
|
||||
} else if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
@ -521,11 +533,16 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
}
|
||||
|
||||
(*pSql->fp)(pSql->param, pSql, code);
|
||||
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
tscDoQuery(pSql);
|
||||
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
|
||||
return;
|
||||
|
||||
_error:
|
||||
|
@ -533,4 +550,6 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
|||
pSql->res.code = code;
|
||||
tscAsyncResultOnError(pSql);
|
||||
}
|
||||
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
}
|
||||
|
|
|
@ -204,7 +204,7 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
|
|||
assert(tscGetMetaInfo(pQueryInfo, 0)->pTableMeta != NULL);
|
||||
|
||||
const int32_t NUM_OF_DESC_TABLE_COLUMNS = 4;
|
||||
const int32_t TYPE_COLUMN_LENGTH = 16;
|
||||
const int32_t TYPE_COLUMN_LENGTH = 20;
|
||||
const int32_t NOTE_COLUMN_MIN_LENGTH = 8;
|
||||
|
||||
int32_t noteFieldLen = NOTE_COLUMN_MIN_LENGTH;
|
||||
|
|
|
@ -95,11 +95,11 @@ static void tscInitSqlContext(SSqlCmd *pCmd, SLocalReducer *pReducer, tOrderDesc
|
|||
int32_t functionId = pExpr->functionId;
|
||||
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) {
|
||||
pCtx->ptsOutputBuf = pReducer->pCtx[0].aOutputBuf;
|
||||
pCtx->param[2].i64Key = pQueryInfo->order.order;
|
||||
pCtx->param[2].i64 = pQueryInfo->order.order;
|
||||
pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT;
|
||||
pCtx->param[1].i64Key = pQueryInfo->order.orderColId;
|
||||
pCtx->param[1].i64 = pQueryInfo->order.orderColId;
|
||||
} else if (functionId == TSDB_FUNC_APERCT) {
|
||||
pCtx->param[0].i64Key = pExpr->param[0].i64Key;
|
||||
pCtx->param[0].i64 = pExpr->param[0].i64;
|
||||
pCtx->param[0].nType = pExpr->param[0].nType;
|
||||
}
|
||||
|
||||
|
@ -1064,7 +1064,7 @@ static void doExecuteSecondaryMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer,
|
|||
}
|
||||
} else if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, j);
|
||||
pCtx->param[0].i64Key = pExpr->param[0].i64Key;
|
||||
pCtx->param[0].i64 = pExpr->param[0].i64;
|
||||
}
|
||||
|
||||
pCtx->currentStage = MERGE_STAGE;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "os.h"
|
||||
|
||||
#include "ttype.h"
|
||||
#include "hash.h"
|
||||
#include "tscUtil.h"
|
||||
#include "tschemautil.h"
|
||||
|
@ -40,46 +41,9 @@ enum {
|
|||
|
||||
static int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t * numOfRows);
|
||||
|
||||
static int32_t tscToInteger(SStrToken *pToken, int64_t *value, char **endPtr) {
|
||||
if (pToken->n == 0) {
|
||||
return TK_ILLEGAL;
|
||||
}
|
||||
|
||||
|
||||
int32_t radix = 10;
|
||||
if (pToken->type == TK_HEX) {
|
||||
radix = 16;
|
||||
} else if (pToken->type == TK_BIN) {
|
||||
radix = 2;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
*value = strtoll(pToken->z, endPtr, radix);
|
||||
if (**endPtr == 'e' || **endPtr == 'E' || **endPtr == '.') {
|
||||
errno = 0;
|
||||
double v = round(strtod(pToken->z, endPtr));
|
||||
if (v > INT64_MAX || v <= INT64_MIN) {
|
||||
errno = ERANGE;
|
||||
} else {
|
||||
*value = (int64_t)v;
|
||||
}
|
||||
}
|
||||
|
||||
// not a valid integer number, return error
|
||||
if (*endPtr - pToken->z != pToken->n) {
|
||||
return TK_ILLEGAL;
|
||||
}
|
||||
|
||||
return pToken->type;
|
||||
}
|
||||
|
||||
static int32_t tscToDouble(SStrToken *pToken, double *value, char **endPtr) {
|
||||
if (pToken->n == 0) {
|
||||
return TK_ILLEGAL;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
*value = strtod(pToken->z, endPtr);
|
||||
*value = strtold(pToken->z, endPtr);
|
||||
|
||||
// not a valid integer number, return error
|
||||
if ((*endPtr - pToken->z) != pToken->n) {
|
||||
|
@ -163,86 +127,119 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// todo extract the null value check
|
||||
static bool isNullStr(SStrToken* pToken) {
|
||||
return (pToken->type == TK_NULL) || ((pToken->type == TK_STRING) && (pToken->n != 0) &&
|
||||
(strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0));
|
||||
}
|
||||
int32_t tsParseOneColumnData(SSchema *pSchema, SStrToken *pToken, char *payload, char *msg, char **str, bool primaryKey,
|
||||
int16_t timePrec) {
|
||||
int64_t iv;
|
||||
int32_t numType;
|
||||
char * endptr = NULL;
|
||||
errno = 0; // clear the previous existed error information
|
||||
int32_t ret;
|
||||
char *endptr = NULL;
|
||||
|
||||
if (IS_NUMERIC_TYPE(pSchema->type) && pToken->n == 0) {
|
||||
return tscInvalidSQLErrMsg(msg, "invalid numeric data", pToken->z);
|
||||
}
|
||||
|
||||
switch (pSchema->type) {
|
||||
case TSDB_DATA_TYPE_BOOL: { // bool
|
||||
if ((pToken->type == TK_BOOL || pToken->type == TK_STRING) && (pToken->n != 0)) {
|
||||
if (strncmp(pToken->z, "true", pToken->n) == 0) {
|
||||
*(uint8_t *)payload = TSDB_TRUE;
|
||||
} else if (strncmp(pToken->z, "false", pToken->n) == 0) {
|
||||
*(uint8_t *)payload = TSDB_FALSE;
|
||||
} else if (strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0) {
|
||||
*(uint8_t *)payload = TSDB_DATA_BOOL_NULL;
|
||||
} else {
|
||||
return tscSQLSyntaxErrMsg(msg, "invalid bool data", pToken->z);
|
||||
}
|
||||
} else if (pToken->type == TK_INTEGER) {
|
||||
iv = strtoll(pToken->z, NULL, 10);
|
||||
*(uint8_t *)payload = (int8_t)((iv == 0) ? TSDB_FALSE : TSDB_TRUE);
|
||||
} else if (pToken->type == TK_FLOAT) {
|
||||
double dv = strtod(pToken->z, NULL);
|
||||
*(uint8_t *)payload = (int8_t)((dv == 0) ? TSDB_FALSE : TSDB_TRUE);
|
||||
} else if (pToken->type == TK_NULL) {
|
||||
*(uint8_t *)payload = TSDB_DATA_BOOL_NULL;
|
||||
if (isNullStr(pToken)) {
|
||||
*((uint8_t *)payload) = TSDB_DATA_BOOL_NULL;
|
||||
} else {
|
||||
return tscInvalidSQLErrMsg(msg, "invalid bool data", pToken->z);
|
||||
if ((pToken->type == TK_BOOL || pToken->type == TK_STRING) && (pToken->n != 0)) {
|
||||
if (strncmp(pToken->z, "true", pToken->n) == 0) {
|
||||
*(uint8_t *)payload = TSDB_TRUE;
|
||||
} else if (strncmp(pToken->z, "false", pToken->n) == 0) {
|
||||
*(uint8_t *)payload = TSDB_FALSE;
|
||||
} else {
|
||||
return tscSQLSyntaxErrMsg(msg, "invalid bool data", pToken->z);
|
||||
}
|
||||
} else if (pToken->type == TK_INTEGER) {
|
||||
iv = strtoll(pToken->z, NULL, 10);
|
||||
*(uint8_t *)payload = (int8_t)((iv == 0) ? TSDB_FALSE : TSDB_TRUE);
|
||||
} else if (pToken->type == TK_FLOAT) {
|
||||
double dv = strtod(pToken->z, NULL);
|
||||
*(uint8_t *)payload = (int8_t)((dv == 0) ? TSDB_FALSE : TSDB_TRUE);
|
||||
} else {
|
||||
return tscInvalidSQLErrMsg(msg, "invalid bool data", pToken->z);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
if (pToken->type == TK_NULL) {
|
||||
*((int8_t *)payload) = TSDB_DATA_TINYINT_NULL;
|
||||
} else if ((pToken->type == TK_STRING) && (pToken->n != 0) &&
|
||||
(strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0)) {
|
||||
*((int8_t *)payload) = TSDB_DATA_TINYINT_NULL;
|
||||
if (isNullStr(pToken)) {
|
||||
*((uint8_t *)payload) = TSDB_DATA_TINYINT_NULL;
|
||||
} else {
|
||||
numType = tscToInteger(pToken, &iv, &endptr);
|
||||
if (TK_ILLEGAL == numType) {
|
||||
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return tscInvalidSQLErrMsg(msg, "invalid tinyint data", pToken->z);
|
||||
} else if (errno == ERANGE || iv > INT8_MAX || iv <= INT8_MIN) {
|
||||
return tscInvalidSQLErrMsg(msg, "tinyint data overflow", pToken->z);
|
||||
} else if (!IS_VALID_TINYINT(iv)) {
|
||||
return tscInvalidSQLErrMsg(msg, "data overflow", pToken->z);
|
||||
}
|
||||
|
||||
*((int8_t *)payload) = (int8_t)iv;
|
||||
*((uint8_t *)payload) = (uint8_t)iv;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
if (isNullStr(pToken)) {
|
||||
*((uint8_t *)payload) = TSDB_DATA_UTINYINT_NULL;
|
||||
} else {
|
||||
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return tscInvalidSQLErrMsg(msg, "invalid unsigned tinyint data", pToken->z);
|
||||
} else if (!IS_VALID_UTINYINT(iv)) {
|
||||
return tscInvalidSQLErrMsg(msg, "unsigned tinyint data overflow", pToken->z);
|
||||
}
|
||||
|
||||
*((uint8_t *)payload) = (uint8_t)iv;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
if (pToken->type == TK_NULL) {
|
||||
*((int16_t *)payload) = TSDB_DATA_SMALLINT_NULL;
|
||||
} else if ((pToken->type == TK_STRING) && (pToken->n != 0) &&
|
||||
(strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0)) {
|
||||
if (isNullStr(pToken)) {
|
||||
*((int16_t *)payload) = TSDB_DATA_SMALLINT_NULL;
|
||||
} else {
|
||||
numType = tscToInteger(pToken, &iv, &endptr);
|
||||
if (TK_ILLEGAL == numType) {
|
||||
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return tscInvalidSQLErrMsg(msg, "invalid smallint data", pToken->z);
|
||||
} else if (errno == ERANGE || iv > INT16_MAX || iv <= INT16_MIN) {
|
||||
} else if (!IS_VALID_SMALLINT(iv)) {
|
||||
return tscInvalidSQLErrMsg(msg, "smallint data overflow", pToken->z);
|
||||
}
|
||||
|
||||
*((int16_t *)payload) = (int16_t)iv;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
if (isNullStr(pToken)) {
|
||||
*((uint16_t *)payload) = TSDB_DATA_USMALLINT_NULL;
|
||||
} else {
|
||||
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return tscInvalidSQLErrMsg(msg, "invalid unsigned smallint data", pToken->z);
|
||||
} else if (!IS_VALID_USMALLINT(iv)) {
|
||||
return tscInvalidSQLErrMsg(msg, "unsigned smallint data overflow", pToken->z);
|
||||
}
|
||||
|
||||
*((uint16_t *)payload) = (uint16_t)iv;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
if (pToken->type == TK_NULL) {
|
||||
*((int32_t *)payload) = TSDB_DATA_INT_NULL;
|
||||
} else if ((pToken->type == TK_STRING) && (pToken->n != 0) &&
|
||||
(strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0)) {
|
||||
if (isNullStr(pToken)) {
|
||||
*((int32_t *)payload) = TSDB_DATA_INT_NULL;
|
||||
} else {
|
||||
numType = tscToInteger(pToken, &iv, &endptr);
|
||||
if (TK_ILLEGAL == numType) {
|
||||
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return tscInvalidSQLErrMsg(msg, "invalid int data", pToken->z);
|
||||
} else if (errno == ERANGE || iv > INT32_MAX || iv <= INT32_MIN) {
|
||||
} else if (!IS_VALID_INT(iv)) {
|
||||
return tscInvalidSQLErrMsg(msg, "int data overflow", pToken->z);
|
||||
}
|
||||
|
||||
|
@ -251,17 +248,30 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SStrToken *pToken, char *payload,
|
|||
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
if (isNullStr(pToken)) {
|
||||
*((uint32_t *)payload) = TSDB_DATA_UINT_NULL;
|
||||
} else {
|
||||
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return tscInvalidSQLErrMsg(msg, "invalid unsigned int data", pToken->z);
|
||||
} else if (!IS_VALID_UINT(iv)) {
|
||||
return tscInvalidSQLErrMsg(msg, "unsigned int data overflow", pToken->z);
|
||||
}
|
||||
|
||||
*((uint32_t *)payload) = (uint32_t)iv;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
if (pToken->type == TK_NULL) {
|
||||
*((int64_t *)payload) = TSDB_DATA_BIGINT_NULL;
|
||||
} else if ((pToken->type == TK_STRING) && (pToken->n != 0) &&
|
||||
(strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0)) {
|
||||
if (isNullStr(pToken)) {
|
||||
*((int64_t *)payload) = TSDB_DATA_BIGINT_NULL;
|
||||
} else {
|
||||
numType = tscToInteger(pToken, &iv, &endptr);
|
||||
if (TK_ILLEGAL == numType) {
|
||||
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return tscInvalidSQLErrMsg(msg, "invalid bigint data", pToken->z);
|
||||
} else if (errno == ERANGE || iv == INT64_MIN) {
|
||||
} else if (!IS_VALID_BIGINT(iv)) {
|
||||
return tscInvalidSQLErrMsg(msg, "bigint data overflow", pToken->z);
|
||||
}
|
||||
|
||||
|
@ -269,11 +279,23 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SStrToken *pToken, char *payload,
|
|||
}
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
if (isNullStr(pToken)) {
|
||||
*((uint64_t *)payload) = TSDB_DATA_UBIGINT_NULL;
|
||||
} else {
|
||||
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return tscInvalidSQLErrMsg(msg, "invalid unsigned bigint data", pToken->z);
|
||||
} else if (!IS_VALID_UBIGINT((uint64_t)iv)) {
|
||||
return tscInvalidSQLErrMsg(msg, "unsigned bigint data overflow", pToken->z);
|
||||
}
|
||||
|
||||
*((uint64_t *)payload) = iv;
|
||||
}
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
if (pToken->type == TK_NULL) {
|
||||
*((int32_t *)payload) = TSDB_DATA_FLOAT_NULL;
|
||||
} else if ((pToken->type == TK_STRING) && (pToken->n != 0) &&
|
||||
(strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0)) {
|
||||
if (isNullStr(pToken)) {
|
||||
*((int32_t *)payload) = TSDB_DATA_FLOAT_NULL;
|
||||
} else {
|
||||
double dv;
|
||||
|
@ -281,24 +303,16 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SStrToken *pToken, char *payload,
|
|||
return tscInvalidSQLErrMsg(msg, "illegal float data", pToken->z);
|
||||
}
|
||||
|
||||
float fv = (float)dv;
|
||||
if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || (fv > FLT_MAX || fv < -FLT_MAX)) {
|
||||
if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || dv > FLT_MAX || dv < -FLT_MAX || isinf(dv) || isnan(dv)) {
|
||||
return tscInvalidSQLErrMsg(msg, "illegal float data", pToken->z);
|
||||
}
|
||||
|
||||
if (isinf(fv) || isnan(fv)) {
|
||||
*((int32_t *)payload) = TSDB_DATA_FLOAT_NULL;
|
||||
}
|
||||
|
||||
*((float *)payload) = fv;
|
||||
*((float *)payload) = (float)dv;
|
||||
}
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
if (pToken->type == TK_NULL) {
|
||||
*((int64_t *)payload) = TSDB_DATA_DOUBLE_NULL;
|
||||
} else if ((pToken->type == TK_STRING) && (pToken->n != 0) &&
|
||||
(strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0)) {
|
||||
if (isNullStr(pToken)) {
|
||||
*((int64_t *)payload) = TSDB_DATA_DOUBLE_NULL;
|
||||
} else {
|
||||
double dv;
|
||||
|
@ -306,15 +320,11 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SStrToken *pToken, char *payload,
|
|||
return tscInvalidSQLErrMsg(msg, "illegal double data", pToken->z);
|
||||
}
|
||||
|
||||
if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || (dv > DBL_MAX || dv < -DBL_MAX)) {
|
||||
if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || isinf(dv) || isnan(dv)) {
|
||||
return tscInvalidSQLErrMsg(msg, "illegal double data", pToken->z);
|
||||
}
|
||||
|
||||
if (isinf(dv) || isnan(dv)) {
|
||||
*((int64_t *)payload) = TSDB_DATA_DOUBLE_NULL;
|
||||
} else {
|
||||
*((double *)payload) = dv;
|
||||
}
|
||||
*((double *)payload) = dv;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -337,7 +347,7 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SStrToken *pToken, char *payload,
|
|||
setVardataNull(payload, TSDB_DATA_TYPE_NCHAR);
|
||||
} else {
|
||||
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
|
||||
size_t output = 0;
|
||||
int32_t output = 0;
|
||||
if (!taosMbsToUcs4(pToken->z, pToken->n, varDataVal(payload), pSchema->bytes - VARSTR_HEADER_SIZE, &output)) {
|
||||
char buf[512] = {0};
|
||||
snprintf(buf, tListLen(buf), "%s", strerror(errno));
|
||||
|
@ -752,6 +762,8 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
|||
|
||||
char *sql = *sqlstr;
|
||||
|
||||
pSql->cmd.autoCreated = false;
|
||||
|
||||
// get the token of specified table
|
||||
index = 0;
|
||||
tableToken = tStrGetToken(sql, &index, false, 0, NULL);
|
||||
|
@ -935,11 +947,15 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
|||
SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder);
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
if (row == NULL) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return tscInvalidSQLErrMsg(pCmd->payload, "tag value expected", NULL);
|
||||
}
|
||||
tdSortKVRowByColIdx(row);
|
||||
|
||||
pCmd->tagData.dataLen = kvRowLen(row);
|
||||
if (pCmd->tagData.dataLen <= 0){
|
||||
return tscInvalidSQLErrMsg(pCmd->payload, "tag value expected", NULL);
|
||||
}
|
||||
|
||||
char* pTag = realloc(pCmd->tagData.data, pCmd->tagData.dataLen);
|
||||
if (pTag == NULL) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
|
|
@ -84,35 +84,35 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
|
|||
var->nLen = 0;
|
||||
if (tb->is_null != NULL && *(tb->is_null)) {
|
||||
var->nType = TSDB_DATA_TYPE_NULL;
|
||||
var->i64Key = 0;
|
||||
var->i64 = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
var->nType = tb->buffer_type;
|
||||
switch (tb->buffer_type) {
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
var->i64Key = 0;
|
||||
var->i64 = 0;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
var->i64Key = (*(int8_t*)tb->buffer) ? 1 : 0;
|
||||
var->i64 = (*(int8_t*)tb->buffer) ? 1 : 0;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
var->i64Key = *(int8_t*)tb->buffer;
|
||||
var->i64 = *(int8_t*)tb->buffer;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
var->i64Key = *(int16_t*)tb->buffer;
|
||||
var->i64 = *(int16_t*)tb->buffer;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
var->i64Key = *(int32_t*)tb->buffer;
|
||||
var->i64 = *(int32_t*)tb->buffer;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
var->i64Key = *(int64_t*)tb->buffer;
|
||||
var->i64 = *(int64_t*)tb->buffer;
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
|
@ -219,7 +219,7 @@ static char* normalStmtBuildSql(STscStmt* stmt) {
|
|||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
taosStringBuilderAppendInteger(&sb, var->i64Key);
|
||||
taosStringBuilderAppendInteger(&sb, var->i64);
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
|
@ -616,7 +616,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) {
|
|||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
switch (bind->buffer_type) {
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
size_t output = 0;
|
||||
int32_t output = 0;
|
||||
if (!taosMbsToUcs4(bind->buffer, *bind->length, varDataVal(data + param->offset), param->bytes - VARSTR_HEADER_SIZE, &output)) {
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
@ -678,7 +678,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
size_t output = 0;
|
||||
int32_t output = 0;
|
||||
if (!taosMbsToUcs4(bind->buffer, *bind->length, varDataVal(data + param->offset), param->bytes - VARSTR_HEADER_SIZE, &output)) {
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#define _GNU_SOURCE
|
||||
|
||||
#include "os.h"
|
||||
#include "ttype.h"
|
||||
#include "qAst.h"
|
||||
#include "taos.h"
|
||||
#include "taosmsg.h"
|
||||
|
@ -220,7 +221,7 @@ static int32_t handlePassword(SSqlCmd* pCmd, SStrToken* pPwd) {
|
|||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
if (pPwd->n >= TSDB_PASSWORD_LEN) {
|
||||
if (pPwd->n >= TSDB_KEY_LEN) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||
}
|
||||
|
||||
|
@ -484,10 +485,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
|
||||
case TSDB_SQL_CREATE_USER:
|
||||
case TSDB_SQL_ALTER_USER: {
|
||||
const char* msg5 = "invalid user rights";
|
||||
const char* msg7 = "not support options";
|
||||
const char* msg2 = "invalid user/account name";
|
||||
const char* msg3 = "name too long";
|
||||
const char* msg5 = "invalid user rights";
|
||||
const char* msg7 = "not support options";
|
||||
|
||||
pCmd->command = pInfo->type;
|
||||
|
||||
|
@ -950,7 +951,7 @@ static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (pField->type < TSDB_DATA_TYPE_BOOL || pField->type > TSDB_DATA_TYPE_NCHAR) {
|
||||
if (!isValidDataType(pField->type)) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
|
||||
return false;
|
||||
}
|
||||
|
@ -1011,7 +1012,7 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
|
|||
return false;
|
||||
}
|
||||
|
||||
if (p->type < TSDB_DATA_TYPE_BOOL || p->type > TSDB_DATA_TYPE_NCHAR) {
|
||||
if (!isValidDataType(p->type)) {
|
||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg5);
|
||||
return false;
|
||||
}
|
||||
|
@ -1241,7 +1242,7 @@ int32_t setObjFullName(char* fullName, const char* account, SStrToken* pDB, SStr
|
|||
|
||||
/* db name is not specified, the tableName dose not include db name */
|
||||
if (pDB != NULL) {
|
||||
if (pDB->n >= TSDB_ACCT_LEN + TSDB_DB_NAME_LEN || pDB->n == 0) {
|
||||
if (pDB->n >= TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN || pDB->n == 0) {
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
|
@ -1754,7 +1755,7 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS
|
|||
// set reverse order scan data blocks for last query
|
||||
if (functionID == TSDB_FUNC_LAST) {
|
||||
pExpr->numOfParams = 1;
|
||||
pExpr->param[0].i64Key = TSDB_ORDER_DESC;
|
||||
pExpr->param[0].i64 = TSDB_ORDER_DESC;
|
||||
pExpr->param[0].nType = TSDB_DATA_TYPE_INT;
|
||||
}
|
||||
|
||||
|
@ -1945,7 +1946,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
|
|||
SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index.columnIndex);
|
||||
int16_t colType = pSchema->type;
|
||||
|
||||
if (colType <= TSDB_DATA_TYPE_BOOL || colType >= TSDB_DATA_TYPE_BINARY) {
|
||||
if (!IS_NUMERIC_TYPE(colType)) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
|
@ -2105,7 +2106,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
|
|||
if (!TSDB_COL_IS_TAG(pIndex->flag) && pIndex->colIndex < tscGetNumOfColumns(pTableMetaInfo->pTableMeta)) { // group by normal columns
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, colIndex + i);
|
||||
pExpr->numOfParams = 1;
|
||||
pExpr->param->i64Key = TSDB_ORDER_ASC;
|
||||
pExpr->param->i64 = TSDB_ORDER_ASC;
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -2182,7 +2183,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
|
|||
|
||||
// 2. valid the column type
|
||||
int16_t colType = pSchema[index.columnIndex].type;
|
||||
if (colType == TSDB_DATA_TYPE_BOOL || colType >= TSDB_DATA_TYPE_BINARY) {
|
||||
if (!IS_NUMERIC_TYPE(colType)) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
|
||||
|
@ -2727,7 +2728,7 @@ int32_t tscTansformSQLFuncForSTableQuery(SQueryInfo* pQueryInfo) {
|
|||
if ((functionId >= TSDB_FUNC_SUM && functionId <= TSDB_FUNC_TWA) ||
|
||||
(functionId >= TSDB_FUNC_FIRST_DST && functionId <= TSDB_FUNC_LAST_DST) ||
|
||||
(functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_AVG_IRATE)) {
|
||||
if (getResultDataInfo(pSrcSchema->type, pSrcSchema->bytes, functionId, (int32_t)pExpr->param[0].i64Key, &type, &bytes,
|
||||
if (getResultDataInfo(pSrcSchema->type, pSrcSchema->bytes, functionId, (int32_t)pExpr->param[0].i64, &type, &bytes,
|
||||
&interBytes, 0, true) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
@ -2827,7 +2828,7 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool
|
|||
int32_t factor = functionCompatList[tscSqlExprGet(pQueryInfo, startIdx)->functionId];
|
||||
|
||||
if (tscSqlExprGet(pQueryInfo, 0)->functionId == TSDB_FUNC_LAST_ROW && (joinQuery || intervalQuery)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// diff function cannot be executed with other function
|
||||
|
@ -4396,8 +4397,8 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t
|
|||
*
|
||||
* Additional check to avoid data overflow
|
||||
*/
|
||||
if (pRight->val.i64Key <= INT64_MAX / 1000) {
|
||||
pRight->val.i64Key *= 1000;
|
||||
if (pRight->val.i64 <= INT64_MAX / 1000) {
|
||||
pRight->val.i64 *= 1000;
|
||||
}
|
||||
} else if (pRight->nSQLOptr == TK_FLOAT && timePrecision == TSDB_TIME_PRECISION_MILLI) {
|
||||
pRight->val.dKey *= 1000;
|
||||
|
@ -5380,22 +5381,22 @@ static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* p
|
|||
tVariantListItem* p0 = taosArrayGet(pKeep, 0);
|
||||
switch (s) {
|
||||
case 1: {
|
||||
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64Key);
|
||||
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64);
|
||||
}
|
||||
break;
|
||||
case 2: {
|
||||
tVariantListItem* p1 = taosArrayGet(pKeep, 1);
|
||||
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64Key);
|
||||
pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64Key);
|
||||
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64);
|
||||
pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64);
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
tVariantListItem* p1 = taosArrayGet(pKeep, 1);
|
||||
tVariantListItem* p2 = taosArrayGet(pKeep, 2);
|
||||
|
||||
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64Key);
|
||||
pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64Key);
|
||||
pMsg->daysToKeep2 = htonl((int32_t)p2->pVar.i64Key);
|
||||
pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64);
|
||||
pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64);
|
||||
pMsg->daysToKeep2 = htonl((int32_t)p2->pVar.i64);
|
||||
break;
|
||||
}
|
||||
default: { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg); }
|
||||
|
@ -5561,7 +5562,7 @@ static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) {
|
|||
if ((pExpr->functionId != TSDB_FUNC_TAG_DUMMY && pExpr->functionId != TSDB_FUNC_TS_DUMMY) &&
|
||||
!(pExpr->functionId == TSDB_FUNC_PRJ && TSDB_COL_IS_UD_COL(pExpr->colInfo.flag))) {
|
||||
SSchema* pColSchema = &pSchema[pExpr->colInfo.colIndex];
|
||||
getResultDataInfo(pColSchema->type, pColSchema->bytes, pExpr->functionId, (int32_t)pExpr->param[0].i64Key, &pExpr->resType,
|
||||
getResultDataInfo(pColSchema->type, pColSchema->bytes, pExpr->functionId, (int32_t)pExpr->param[0].i64, &pExpr->resType,
|
||||
&pExpr->resBytes, &pExpr->interBytes, tagLength, isSTable);
|
||||
}
|
||||
}
|
||||
|
@ -6021,9 +6022,9 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate) {
|
|||
}
|
||||
|
||||
if (pCreate->quorum != -1 &&
|
||||
(pCreate->quorum < TSDB_MIN_DB_REPLICA_OPTION || pCreate->quorum > TSDB_MAX_DB_REPLICA_OPTION)) {
|
||||
(pCreate->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCreate->quorum > TSDB_MAX_DB_QUORUM_OPTION)) {
|
||||
snprintf(msg, tListLen(msg), "invalid db option quorum: %d valid range: [%d, %d]", pCreate->quorum,
|
||||
TSDB_MIN_DB_REPLICA_OPTION, TSDB_MAX_DB_REPLICA_OPTION);
|
||||
TSDB_MIN_DB_QUORUM_OPTION, TSDB_MAX_DB_QUORUM_OPTION);
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
||||
}
|
||||
|
||||
|
@ -6100,7 +6101,9 @@ void tscPrintSelectClause(SSqlObj* pSql, int32_t subClauseIndex) {
|
|||
int32_t tmpLen = 0;
|
||||
tmpLen =
|
||||
sprintf(tmpBuf, "%s(uid:%" PRId64 ", %d)", aAggs[pExpr->functionId].aName, pExpr->uid, pExpr->colInfo.colId);
|
||||
if (tmpLen + offset > totalBufSize) break;
|
||||
|
||||
if (tmpLen + offset >= totalBufSize - 1) break;
|
||||
|
||||
|
||||
offset += sprintf(str + offset, "%s", tmpBuf);
|
||||
|
||||
|
@ -6109,7 +6112,9 @@ void tscPrintSelectClause(SSqlObj* pSql, int32_t subClauseIndex) {
|
|||
}
|
||||
}
|
||||
|
||||
assert(offset < totalBufSize);
|
||||
str[offset] = ']';
|
||||
assert(offset < totalBufSize);
|
||||
tscDebug("%p select clause:%s", pSql, str);
|
||||
}
|
||||
|
||||
|
@ -6760,7 +6765,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
|
|||
// check for dividing by 0
|
||||
if ((*pExpr)->_node.optr == TSDB_BINARY_OP_DIVIDE) {
|
||||
if (pRight->nodeType == TSQL_NODE_VALUE) {
|
||||
if (pRight->pVal->nType == TSDB_DATA_TYPE_INT && pRight->pVal->i64Key == 0) {
|
||||
if (pRight->pVal->nType == TSDB_DATA_TYPE_INT && pRight->pVal->i64 == 0) {
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
} else if (pRight->pVal->nType == TSDB_DATA_TYPE_FLOAT && pRight->pVal->dKey == 0) {
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
|
|
|
@ -66,30 +66,24 @@ STableComInfo tscGetTableInfo(const STableMeta* pTableMeta) {
|
|||
return pTableMeta->tableInfo;
|
||||
}
|
||||
|
||||
bool isValidSchema(struct SSchema* pSchema, int32_t numOfCols) {
|
||||
if (!VALIDNUMOFCOLS(numOfCols)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* first column must be the timestamp, which is a primary key */
|
||||
if (pSchema[0].type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* type is valid, length is valid */
|
||||
static bool doValidateSchema(SSchema* pSchema, int32_t numOfCols, int32_t maxLen) {
|
||||
int32_t rowLen = 0;
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
// 1. valid types
|
||||
if (pSchema[i].type > TSDB_DATA_TYPE_TIMESTAMP || pSchema[i].type < TSDB_DATA_TYPE_BOOL) {
|
||||
if (!isValidDataType(pSchema[i].type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. valid length for each type
|
||||
if (pSchema[i].type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
if (pSchema[i].type == TSDB_DATA_TYPE_BINARY) {
|
||||
if (pSchema[i].bytes > TSDB_MAX_BINARY_LEN) {
|
||||
return false;
|
||||
}
|
||||
} else if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) {
|
||||
if (pSchema[i].bytes > TSDB_MAX_NCHAR_LEN) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (pSchema[i].bytes != tDataTypeDesc[pSchema[i].type].nSize) {
|
||||
return false;
|
||||
|
@ -106,8 +100,32 @@ bool isValidSchema(struct SSchema* pSchema, int32_t numOfCols) {
|
|||
rowLen += pSchema[i].bytes;
|
||||
}
|
||||
|
||||
// valid total length
|
||||
return (rowLen <= TSDB_MAX_BYTES_PER_ROW);
|
||||
return rowLen <= maxLen;
|
||||
}
|
||||
|
||||
bool isValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags) {
|
||||
if (!VALIDNUMOFCOLS(numOfCols)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!VALIDNUMOFTAGS(numOfTags)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* first column must be the timestamp, which is a primary key */
|
||||
if (pSchema[0].type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!doValidateSchema(pSchema, numOfCols, TSDB_MAX_BYTES_PER_ROW)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!doValidateSchema(&pSchema[numOfCols], numOfTags, TSDB_MAX_TAGS_LEN)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SSchema* tscGetTableColumnSchema(const STableMeta* pTableMeta, int32_t colIndex) {
|
||||
|
|
|
@ -423,7 +423,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
|
|||
|
||||
if (shouldFree) { // in case of table-meta/vgrouplist query, automatically free it
|
||||
taosRemoveRef(tscObjRef, pSql->self);
|
||||
tscDebug("%p sqlObj is automatically freed", pSql);
|
||||
tscDebug("%p sqlObj is automatically freed", pSql);
|
||||
}
|
||||
|
||||
rpcFreeCont(rpcMsg->pCont);
|
||||
|
@ -755,12 +755,10 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
SColumn *pCol = taosArrayGetP(pQueryInfo->colList, i);
|
||||
SSchema *pColSchema = &pSchema[pCol->colIndex.columnIndex];
|
||||
|
||||
if (pCol->colIndex.columnIndex >= tscGetNumOfColumns(pTableMeta) || pColSchema->type < TSDB_DATA_TYPE_BOOL ||
|
||||
pColSchema->type > TSDB_DATA_TYPE_NCHAR) {
|
||||
if (pCol->colIndex.columnIndex >= tscGetNumOfColumns(pTableMeta) || !isValidDataType(pColSchema->type)) {
|
||||
tscError("%p tid:%d uid:%" PRIu64" id:%s, column index out of range, numOfColumns:%d, index:%d, column name:%s",
|
||||
pSql, pTableMeta->id.tid, pTableMeta->id.uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex.columnIndex,
|
||||
pColSchema->name);
|
||||
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
}
|
||||
|
||||
|
@ -826,7 +824,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
memcpy(pMsg, pExpr->param[j].pz, pExpr->param[j].nLen);
|
||||
pMsg += pExpr->param[j].nLen;
|
||||
} else {
|
||||
pSqlFuncExpr->arg[j].argValue.i64 = htobe64(pExpr->param[j].i64Key);
|
||||
pSqlFuncExpr->arg[j].argValue.i64 = htobe64(pExpr->param[j].i64);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -866,7 +864,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
memcpy(pMsg, pExpr->param[j].pz, pExpr->param[j].nLen);
|
||||
pMsg += pExpr->param[j].nLen;
|
||||
} else {
|
||||
pSqlFuncExpr1->arg[j].argValue.i64 = htobe64(pExpr->param[j].i64Key);
|
||||
pSqlFuncExpr1->arg[j].argValue.i64 = htobe64(pExpr->param[j].i64);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -944,7 +942,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
SSchema *pColSchema = &pSchema[pCol->colIndex.columnIndex];
|
||||
|
||||
if ((pCol->colIndex.columnIndex >= numOfTagColumns || pCol->colIndex.columnIndex < -1) ||
|
||||
(pColSchema->type < TSDB_DATA_TYPE_BOOL || pColSchema->type > TSDB_DATA_TYPE_NCHAR)) {
|
||||
(!isValidDataType(pColSchema->type))) {
|
||||
tscError("%p tid:%d uid:%" PRIu64 " id:%s, tag index out of range, totalCols:%d, numOfTags:%d, index:%d, column name:%s",
|
||||
pSql, pTableMeta->id.tid, pTableMeta->id.uid, pTableMetaInfo->name, total, numOfTagColumns,
|
||||
pCol->colIndex.columnIndex, pColSchema->name);
|
||||
|
@ -1830,7 +1828,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
|
|||
assert(i == 0);
|
||||
}
|
||||
|
||||
assert(pSchema->type >= TSDB_DATA_TYPE_BOOL && pSchema->type <= TSDB_DATA_TYPE_NCHAR);
|
||||
assert(isValidDataType(pSchema->type));
|
||||
pSchema++;
|
||||
}
|
||||
|
||||
|
@ -1977,9 +1975,6 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) {
|
|||
//
|
||||
// rsp += tagLen;
|
||||
// int32_t size = (int32_t)(rsp - ((char *)pMeta)); // Consistent with STableMeta in cache
|
||||
//
|
||||
// pMeta->index = 0;
|
||||
// (void)taosCachePut(tscMetaCache, pMeta->tableId, (char *)pMeta, size, tsTableMetaKeepTimer);
|
||||
// }
|
||||
}
|
||||
|
||||
|
@ -1992,16 +1987,20 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
int tscProcessSTableVgroupRsp(SSqlObj *pSql) {
|
||||
// master sqlObj locates in param
|
||||
SSqlObj* parent = (SSqlObj*)taosAcquireRef(tscObjRef, (int64_t)pSql->param);
|
||||
if(parent == NULL) {
|
||||
return pSql->res.code;
|
||||
}
|
||||
|
||||
assert(parent->signature == parent && (int64_t)pSql->param == parent->self);
|
||||
|
||||
SSqlRes* pRes = &pSql->res;
|
||||
|
||||
// NOTE: the order of several table must be preserved.
|
||||
SSTableVgroupRspMsg *pStableVgroup = (SSTableVgroupRspMsg *)pRes->pRsp;
|
||||
pStableVgroup->numOfTables = htonl(pStableVgroup->numOfTables);
|
||||
char *pMsg = pRes->pRsp + sizeof(SSTableVgroupRspMsg);
|
||||
|
||||
// master sqlObj locates in param
|
||||
SSqlObj* parent = pSql->param;
|
||||
assert(parent != NULL);
|
||||
|
||||
SSqlCmd* pCmd = &parent->cmd;
|
||||
for(int32_t i = 0; i < pStableVgroup->numOfTables; ++i) {
|
||||
|
@ -2035,6 +2034,8 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) {
|
|||
|
||||
pMsg += size;
|
||||
}
|
||||
|
||||
taosReleaseRef(tscObjRef, parent->self);
|
||||
|
||||
return pSql->res.code;
|
||||
}
|
||||
|
@ -2328,11 +2329,15 @@ static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaIn
|
|||
|
||||
tscDebug("%p new pSqlObj:%p to get tableMeta, auto create:%d", pSql, pNew, pNew->cmd.autoCreated);
|
||||
|
||||
pNew->fp = tscTableMetaCallBack;
|
||||
pNew->param = pSql;
|
||||
|
||||
registerSqlObj(pNew);
|
||||
|
||||
pNew->fp = tscTableMetaCallBack;
|
||||
pNew->param = (void *)pSql->self;
|
||||
|
||||
tscDebug("%p metaRid from %" PRId64 " to %" PRId64 , pSql, pSql->metaRid, pNew->self);
|
||||
|
||||
pSql->metaRid = pNew->self;
|
||||
|
||||
int32_t code = tscProcessSql(pNew);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; // notify application that current process needs to be terminated
|
||||
|
@ -2348,6 +2353,7 @@ int32_t tscGetTableMeta(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) {
|
|||
uint32_t size = tscGetTableMetaMaxSize();
|
||||
pTableMetaInfo->pTableMeta = calloc(1, size);
|
||||
|
||||
pTableMetaInfo->pTableMeta->tableType = -1;
|
||||
pTableMetaInfo->pTableMeta->tableInfo.numOfColumns = -1;
|
||||
int32_t len = (int32_t) strlen(pTableMetaInfo->name);
|
||||
|
||||
|
@ -2447,10 +2453,15 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
|
|||
pNewQueryInfo->numOfTables = pQueryInfo->numOfTables;
|
||||
registerSqlObj(pNew);
|
||||
|
||||
tscDebug("%p svgroupRid from %" PRId64 " to %" PRId64 , pSql, pSql->svgroupRid, pNew->self);
|
||||
|
||||
pSql->svgroupRid = pNew->self;
|
||||
|
||||
|
||||
tscDebug("%p new sqlObj:%p to get vgroupInfo, numOfTables:%d", pSql, pNew, pNewQueryInfo->numOfTables);
|
||||
|
||||
pNew->fp = tscTableMetaCallBack;
|
||||
pNew->param = pSql;
|
||||
pNew->param = (void *)pSql->self;
|
||||
code = tscProcessSql(pNew);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_TSC_ACTION_IN_PROGRESS;
|
||||
|
|
|
@ -47,7 +47,7 @@ static bool validUserName(const char* user) {
|
|||
}
|
||||
|
||||
static bool validPassword(const char* passwd) {
|
||||
return validImpl(passwd, TSDB_PASSWORD_LEN - 1);
|
||||
return validImpl(passwd, TSDB_KEY_LEN - 1);
|
||||
}
|
||||
|
||||
static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, const char *auth, const char *db,
|
||||
|
@ -238,11 +238,11 @@ TAOS *taos_connect_c(const char *ip, uint8_t ipLen, const char *user, uint8_t us
|
|||
uint8_t passLen, const char *db, uint8_t dbLen, uint16_t port) {
|
||||
char ipBuf[TSDB_EP_LEN] = {0};
|
||||
char userBuf[TSDB_USER_LEN] = {0};
|
||||
char passBuf[TSDB_PASSWORD_LEN] = {0};
|
||||
char passBuf[TSDB_KEY_LEN] = {0};
|
||||
char dbBuf[TSDB_DB_NAME_LEN] = {0};
|
||||
strncpy(ipBuf, ip, MIN(TSDB_EP_LEN - 1, ipLen));
|
||||
strncpy(userBuf, user, MIN(TSDB_USER_LEN - 1, userLen));
|
||||
strncpy(passBuf, pass, MIN(TSDB_PASSWORD_LEN - 1, passLen));
|
||||
strncpy(passBuf, pass, MIN(TSDB_KEY_LEN - 1, passLen));
|
||||
strncpy(dbBuf, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen));
|
||||
return taos_connect(ipBuf, userBuf, passBuf, dbBuf, port);
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ TAOS_RES* taos_query_c(TAOS *taos, const char *sqlstr, uint32_t sqlLen, int64_t*
|
|||
return NULL;
|
||||
}
|
||||
|
||||
nPrintTsc(sqlstr);
|
||||
nPrintTsc("%s", sqlstr);
|
||||
|
||||
SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
|
||||
if (pSql == NULL) {
|
||||
|
@ -694,6 +694,8 @@ static void tscKillSTableQuery(SSqlObj *pSql) {
|
|||
// set the master sqlObj flag to cancel query
|
||||
pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
||||
|
||||
tscLockByThread(&pSql->squeryLock);
|
||||
|
||||
for (int i = 0; i < pSql->subState.numOfSub; ++i) {
|
||||
// NOTE: pSub may have been released already here
|
||||
SSqlObj *pSub = pSql->pSubs[i];
|
||||
|
@ -713,6 +715,12 @@ static void tscKillSTableQuery(SSqlObj *pSql) {
|
|||
taosReleaseRef(tscObjRef, pSubObj->self);
|
||||
}
|
||||
|
||||
if (pSql->subState.numOfSub <= 0) {
|
||||
tscAsyncResultOnError(pSql);
|
||||
}
|
||||
|
||||
tscUnlockByThread(&pSql->squeryLock);
|
||||
|
||||
tscDebug("%p super table query cancelled", pSql);
|
||||
}
|
||||
|
||||
|
@ -788,18 +796,34 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
|
|||
len += sprintf(str + len, "%d", *((int8_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
len += sprintf(str + len, "%u", *((uint8_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
len += sprintf(str + len, "%d", *((int16_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
len += sprintf(str + len, "%u", *((uint16_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
len += sprintf(str + len, "%d", *((int32_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
len += sprintf(str + len, "%u", *((uint32_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
len += sprintf(str + len, "%" PRIu64, *((uint64_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float fv = 0;
|
||||
fv = GET_FLOAT_VAL(row[i]);
|
||||
|
@ -962,7 +986,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
|
|||
return code;
|
||||
}
|
||||
|
||||
if (++pCmd->count > TSDB_MULTI_METERMETA_MAX_NUM) {
|
||||
if (++pCmd->count > TSDB_MULTI_TABLEMETA_MAX_NUM) {
|
||||
code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
|
||||
sprintf(pCmd->payload, "tables over the max number");
|
||||
return code;
|
||||
|
|
|
@ -65,15 +65,30 @@ static int64_t tscGetRetryDelayTime(SSqlStream* pStream, int64_t slidingTime, in
|
|||
return retryDelta;
|
||||
}
|
||||
|
||||
static void setRetryInfo(SSqlStream* pStream, int32_t code) {
|
||||
SSqlObj* pSql = pStream->pSql;
|
||||
|
||||
pSql->res.code = code;
|
||||
int64_t retryDelayTime = tscGetRetryDelayTime(pStream, pStream->interval.sliding, pStream->precision);
|
||||
tscDebug("%p stream:%p, get table Meta failed, retry in %" PRId64 "ms", pSql, pStream, retryDelayTime);
|
||||
tscSetRetryTimer(pStream, pSql, retryDelayTime);
|
||||
}
|
||||
|
||||
static void doLaunchQuery(void* param, TAOS_RES* tres, int32_t code) {
|
||||
SSqlStream *pStream = (SSqlStream *)param;
|
||||
assert(pStream->pSql == tres && code == TSDB_CODE_SUCCESS);
|
||||
assert(pStream->pSql == tres);
|
||||
|
||||
SSqlObj* pSql = (SSqlObj*) tres;
|
||||
pSql->fp = doLaunchQuery;
|
||||
|
||||
pSql->fp = doLaunchQuery;
|
||||
pSql->fetchFp = doLaunchQuery;
|
||||
pSql->res.completed = false;
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
setRetryInfo(pStream, code);
|
||||
return;
|
||||
}
|
||||
|
||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
||||
|
@ -82,6 +97,10 @@ static void doLaunchQuery(void* param, TAOS_RES* tres, int32_t code) {
|
|||
code = tscGetSTableVgroupInfo(pSql, 0);
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// failed to get table Meta or vgroup list, retry in 10sec.
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
tscTansformSQLFuncForSTableQuery(pQueryInfo);
|
||||
|
@ -91,11 +110,8 @@ static void doLaunchQuery(void* param, TAOS_RES* tres, int32_t code) {
|
|||
pSql->fetchFp = tscProcessStreamQueryCallback;
|
||||
tscDoQuery(pSql);
|
||||
tscIncStreamExecutionCount(pStream);
|
||||
} else if (code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
pSql->res.code = code;
|
||||
int64_t retryDelayTime = tscGetRetryDelayTime(pStream, pStream->interval.sliding, pStream->precision);
|
||||
tscDebug("%p stream:%p, get table Meta failed, retry in %" PRId64 "ms", pSql, pStream, retryDelayTime);
|
||||
tscSetRetryTimer(pStream, pSql, retryDelayTime);
|
||||
} else {
|
||||
setRetryInfo(pStream, code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -535,7 +551,6 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) {
|
|||
int64_t starttime = tscGetLaunchTimestamp(pStream);
|
||||
pCmd->command = TSDB_SQL_SELECT;
|
||||
|
||||
registerSqlObj(pSql);
|
||||
tscAddIntoStreamList(pStream);
|
||||
|
||||
taosTmrReset(tscProcessStreamTimer, (int32_t)starttime, pStream, tscTmr, &pStream->pTimer);
|
||||
|
@ -594,12 +609,15 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
|
|||
|
||||
pSql->fp = tscCreateStream;
|
||||
pSql->fetchFp = tscCreateStream;
|
||||
|
||||
registerSqlObj(pSql);
|
||||
|
||||
int32_t code = tsParseSql(pSql, true);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
tscCreateStream(pStream, pSql, code);
|
||||
} else if (code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||
tscError("%p open stream failed, sql:%s, code:%s", pSql, sqlstr, tstrerror(pRes->code));
|
||||
tscFreeSqlObj(pSql);
|
||||
taosReleaseRef(tscObjRef, pSql->self);
|
||||
free(pStream);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -465,7 +465,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
|
|||
int16_t colId = tscGetJoinTagColIdByUid(&pQueryInfo->tagCond, pTableMetaInfo->pTableMeta->id.uid);
|
||||
|
||||
// set the tag column id for executor to extract correct tag value
|
||||
pExpr->param[0] = (tVariant) {.i64Key = colId, .nType = TSDB_DATA_TYPE_BIGINT, .nLen = sizeof(int64_t)};
|
||||
pExpr->param[0] = (tVariant) {.i64 = colId, .nType = TSDB_DATA_TYPE_BIGINT, .nLen = sizeof(int64_t)};
|
||||
pExpr->numOfParams = 1;
|
||||
}
|
||||
|
||||
|
@ -533,7 +533,7 @@ static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSupporter* pSupporter) {
|
|||
freeJoinSubqueryObj(pSqlObj);
|
||||
}
|
||||
|
||||
tscDestroyJoinSupporter(pSupporter);
|
||||
//tscDestroyJoinSupporter(pSupporter);
|
||||
}
|
||||
|
||||
// update the query time range according to the join results on timestamp
|
||||
|
@ -650,7 +650,7 @@ static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj*
|
|||
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
int16_t tagColId = tscGetJoinTagColIdByUid(&pSupporter->tagCond, pTableMetaInfo->pTableMeta->id.uid);
|
||||
pExpr->param->i64Key = tagColId;
|
||||
pExpr->param->i64 = tagColId;
|
||||
pExpr->numOfParams = 1;
|
||||
}
|
||||
|
||||
|
@ -1362,9 +1362,11 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
|
|||
|
||||
SJoinSupporter* pSupporter = (SJoinSupporter*)param;
|
||||
SSqlObj* pParentSql = pSupporter->pObj;
|
||||
|
||||
|
||||
// There is only one subquery and table for each subquery.
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
||||
assert(pQueryInfo->numOfTables == 1 && pSql->cmd.numOfClause == 1);
|
||||
|
||||
// retrieve actual query results from vnode during the second stage join subquery
|
||||
|
@ -1382,7 +1384,6 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
|
|||
|
||||
tscError("%p abort query, code:%s, global code:%s", pSql, tstrerror(code), tstrerror(pParentSql->res.code));
|
||||
pParentSql->res.code = code;
|
||||
|
||||
quitAllSubquery(pParentSql, pSupporter);
|
||||
tscAsyncResultOnError(pParentSql);
|
||||
|
||||
|
@ -1405,9 +1406,6 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
|
||||
// In case of consequence query from other vnode, do not wait for other query response here.
|
||||
if (!(pTableMetaInfo->vgroupIndex > 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0))) {
|
||||
if (atomic_sub_fetch_32(&pParentSql->subState.numOfRemain, 1) > 0) {
|
||||
|
@ -1547,7 +1545,7 @@ int32_t tscCreateJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter
|
|||
|
||||
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
||||
int16_t tagColId = tscGetJoinTagColIdByUid(&pSupporter->tagCond, pTableMetaInfo->pTableMeta->id.uid);
|
||||
pExpr->param->i64Key = tagColId;
|
||||
pExpr->param->i64 = tagColId;
|
||||
pExpr->numOfParams = 1;
|
||||
}
|
||||
|
||||
|
@ -1658,6 +1656,25 @@ static void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs) {
|
|||
}
|
||||
}
|
||||
|
||||
void tscLockByThread(int64_t *lockedBy) {
|
||||
int64_t tid = taosGetSelfPthreadId();
|
||||
int i = 0;
|
||||
while (atomic_val_compare_exchange_64(lockedBy, 0, tid) != 0) {
|
||||
if (++i % 100 == 0) {
|
||||
sched_yield();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tscUnlockByThread(int64_t *lockedBy) {
|
||||
int64_t tid = taosGetSelfPthreadId();
|
||||
if (atomic_val_compare_exchange_64(lockedBy, tid, 0) != tid) {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
@ -2120,6 +2137,7 @@ static SSqlObj *tscCreateSTableSubquery(SSqlObj *pSql, SRetrieveSupport *trsuppo
|
|||
return pNew;
|
||||
}
|
||||
|
||||
// todo there is are race condition in this function, while cancel is called by user.
|
||||
void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
|
||||
// the param may be null, since it may be done by other query threads. and the asyncOnError may enter in this
|
||||
// function while kill query by a user.
|
||||
|
|
|
@ -71,6 +71,7 @@ void tsSetSTableQueryCond(STagCond* pTagCond, uint64_t uid, SBufferWriter* bw) {
|
|||
|
||||
bool tscQueryTags(SQueryInfo* pQueryInfo) {
|
||||
int32_t numOfCols = (int32_t) tscSqlExprNumOfExprs(pQueryInfo);
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
int32_t functId = pExpr->functionId;
|
||||
|
@ -314,7 +315,7 @@ void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
|
|||
} else {
|
||||
for (int32_t k = 0; k < pRes->numOfRows; ++k) {
|
||||
char* p = ((char**)pRes->urow)[i] + k * pInfo->field.bytes;
|
||||
memcpy(p, &pInfo->pSqlExpr->param[1].i64Key, pInfo->field.bytes);
|
||||
memcpy(p, &pInfo->pSqlExpr->param[1].i64, pInfo->field.bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -467,6 +468,18 @@ void tscFreeRegisteredSqlObj(void *pSql) {
|
|||
|
||||
}
|
||||
|
||||
void tscFreeMetaSqlObj(int64_t *rid){
|
||||
if (RID_VALID(*rid)) {
|
||||
SSqlObj* pSql = (SSqlObj*)taosAcquireRef(tscObjRef, *rid);
|
||||
if (pSql) {
|
||||
taosRemoveRef(tscObjRef, *rid);
|
||||
taosReleaseRef(tscObjRef, *rid);
|
||||
}
|
||||
|
||||
*rid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void tscFreeSqlObj(SSqlObj* pSql) {
|
||||
if (pSql == NULL || pSql->signature != pSql) {
|
||||
return;
|
||||
|
@ -476,6 +489,9 @@ void tscFreeSqlObj(SSqlObj* pSql) {
|
|||
|
||||
pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED;
|
||||
|
||||
tscFreeMetaSqlObj(&pSql->metaRid);
|
||||
tscFreeMetaSqlObj(&pSql->svgroupRid);
|
||||
|
||||
tscFreeSubobj(pSql);
|
||||
|
||||
SSqlCmd* pCmd = &pSql->cmd;
|
||||
|
@ -504,6 +520,7 @@ void tscFreeSqlObj(SSqlObj* pSql) {
|
|||
pCmd->allocSize = 0;
|
||||
|
||||
tsem_destroy(&pSql->rspSem);
|
||||
memset(pSql, 0, sizeof(*pSql));
|
||||
free(pSql);
|
||||
}
|
||||
|
||||
|
@ -2192,7 +2209,9 @@ void tscDoQuery(SSqlObj* pSql) {
|
|||
tscProcessSql(pSql);
|
||||
} else { // secondary stage join query.
|
||||
if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) { // super table query
|
||||
tscLockByThread(&pSql->squeryLock);
|
||||
tscHandleMasterSTableQuery(pSql);
|
||||
tscUnlockByThread(&pSql->squeryLock);
|
||||
} else {
|
||||
tscProcessSql(pSql);
|
||||
}
|
||||
|
@ -2201,7 +2220,9 @@ void tscDoQuery(SSqlObj* pSql) {
|
|||
|
||||
return;
|
||||
} else if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) { // super table query
|
||||
tscLockByThread(&pSql->squeryLock);
|
||||
tscHandleMasterSTableQuery(pSql);
|
||||
tscUnlockByThread(&pSql->squeryLock);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
FIND_PATH(HEADER_GTEST_INCLUDE_DIR gtest.h /usr/include/gtest /usr/local/include/gtest)
|
||||
|
|
|
@ -162,6 +162,10 @@ TEST(testCase, parse_time) {
|
|||
|
||||
taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
EXPECT_EQ(time, -28800 * MILLISECOND_PER_SECOND);
|
||||
|
||||
char* t = "2021-01-08T02:11:40.000+00:00";
|
||||
taosParseTime(t, &time, strlen(t), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
printf("%ld\n", time);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
|
|
|
@ -36,6 +36,7 @@ extern int8_t tsEnableVnodeBak;
|
|||
extern int8_t tsEnableTelemetryReporting;
|
||||
extern char tsEmail[];
|
||||
extern char tsArbitrator[];
|
||||
extern int8_t tsArbOnline;
|
||||
|
||||
// common
|
||||
extern int tsRpcTimer;
|
||||
|
@ -62,7 +63,6 @@ extern int32_t tsRetrieveBlockingModel;// retrieve threads will be blocked
|
|||
extern int8_t tsKeepOriginalColumnName;
|
||||
|
||||
// client
|
||||
extern int32_t tsTableMetaKeepTimer;
|
||||
extern int32_t tsMaxSQLStringLen;
|
||||
extern int8_t tsTscEnableRecordSql;
|
||||
extern int32_t tsMaxNumOfOrderedResults;
|
||||
|
@ -190,7 +190,7 @@ extern int32_t monDebugFlag;
|
|||
extern int32_t uDebugFlag;
|
||||
extern int32_t rpcDebugFlag;
|
||||
extern int32_t odbcDebugFlag;
|
||||
extern int32_t qDebugFlag;
|
||||
extern uint32_t qDebugFlag;
|
||||
extern int32_t wDebugFlag;
|
||||
extern int32_t cqDebugFlag;
|
||||
extern int32_t debugFlag;
|
||||
|
|
|
@ -28,7 +28,8 @@ typedef struct tVariant {
|
|||
uint32_t nType;
|
||||
int32_t nLen; // only used for string, for number, it is useless
|
||||
union {
|
||||
int64_t i64Key;
|
||||
int64_t i64;
|
||||
uint64_t u64;
|
||||
double dKey;
|
||||
char * pz;
|
||||
wchar_t *wpz;
|
||||
|
@ -36,9 +37,9 @@ typedef struct tVariant {
|
|||
};
|
||||
} tVariant;
|
||||
|
||||
void tVariantCreate(tVariant *pVar, SStrToken *token);
|
||||
bool tVariantIsValid(tVariant *pVar);
|
||||
|
||||
void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t type);
|
||||
void tVariantCreate(tVariant *pVar, SStrToken *token);
|
||||
|
||||
void tVariantCreateFromBinary(tVariant *pVar, const char *pz, size_t len, uint32_t type);
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ int32_t tsStatusInterval = 1; // second
|
|||
int32_t tsNumOfMnodes = 3;
|
||||
int8_t tsEnableVnodeBak = 1;
|
||||
int8_t tsEnableTelemetryReporting = 1;
|
||||
int8_t tsArbOnline = 0;
|
||||
char tsEmail[TSDB_FQDN_LEN] = {0};
|
||||
|
||||
// common
|
||||
|
@ -71,7 +72,6 @@ char tsTempDir[TSDB_FILENAME_LEN] = "/tmp/";
|
|||
int32_t tsCompressMsgSize = -1;
|
||||
|
||||
// client
|
||||
int32_t tsTableMetaKeepTimer = 7200; // second
|
||||
int32_t tsMaxSQLStringLen = TSDB_MAX_SQL_LEN;
|
||||
int8_t tsTscEnableRecordSql = 0;
|
||||
|
||||
|
@ -218,7 +218,7 @@ int32_t odbcDebugFlag = 131;
|
|||
int32_t httpDebugFlag = 131;
|
||||
int32_t mqttDebugFlag = 131;
|
||||
int32_t monDebugFlag = 131;
|
||||
int32_t qDebugFlag = 131;
|
||||
uint32_t qDebugFlag = 131;
|
||||
int32_t rpcDebugFlag = 131;
|
||||
int32_t uDebugFlag = 131;
|
||||
int32_t debugFlag = 0;
|
||||
|
@ -595,16 +595,6 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.unitType = TAOS_CFG_UTYPE_SECOND;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "tableMetaKeepTimer";
|
||||
cfg.ptr = &tsTableMetaKeepTimer;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.minValue = 1;
|
||||
cfg.maxValue = 8640000;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_SECOND;
|
||||
taosInitConfigOption(cfg);
|
||||
|
||||
cfg.option = "minSlidingTime";
|
||||
cfg.ptr = &tsMinSlidingTime;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
|
@ -810,8 +800,8 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.ptr = &tsQuorum;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||
cfg.minValue = TSDB_MIN_DB_REPLICA_OPTION;
|
||||
cfg.maxValue = TSDB_MAX_DB_REPLICA_OPTION;
|
||||
cfg.minValue = TSDB_MIN_DB_QUORUM_OPTION;
|
||||
cfg.maxValue = TSDB_MAX_DB_QUORUM_OPTION;
|
||||
cfg.ptrLength = 0;
|
||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||
taosInitConfigOption(cfg);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "ttokendef.h"
|
||||
#include "tscompression.h"
|
||||
|
||||
const int32_t TYPE_BYTES[11] = {
|
||||
const int32_t TYPE_BYTES[15] = {
|
||||
-1, // TSDB_DATA_TYPE_NULL
|
||||
sizeof(int8_t), // TSDB_DATA_TYPE_BOOL
|
||||
sizeof(int8_t), // TSDB_DATA_TYPE_TINYINT
|
||||
|
@ -29,10 +29,28 @@ const int32_t TYPE_BYTES[11] = {
|
|||
sizeof(double), // TSDB_DATA_TYPE_DOUBLE
|
||||
sizeof(VarDataOffsetT), // TSDB_DATA_TYPE_BINARY
|
||||
sizeof(TSKEY), // TSDB_DATA_TYPE_TIMESTAMP
|
||||
sizeof(VarDataOffsetT) // TSDB_DATA_TYPE_NCHAR
|
||||
sizeof(VarDataOffsetT), // TSDB_DATA_TYPE_NCHAR
|
||||
sizeof(uint8_t), // TSDB_DATA_TYPE_UTINYINT
|
||||
sizeof(uint16_t), // TSDB_DATA_TYPE_USMALLINT
|
||||
sizeof(uint32_t), // TSDB_DATA_TYPE_UINT
|
||||
sizeof(uint64_t), // TSDB_DATA_TYPE_UBIGINT
|
||||
};
|
||||
|
||||
static void getStatics_bool(const TSKEY *primaryKey, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
#define DO_STATICS(__sum, __min, __max, __minIndex, __maxIndex, _list, _index) \
|
||||
do { \
|
||||
(__sum) += (_list)[(_index)]; \
|
||||
if ((__min) > (_list)[(_index)]) { \
|
||||
(__min) = (_list)[(_index)]; \
|
||||
(__minIndex) = (_index); \
|
||||
} \
|
||||
\
|
||||
if ((__max) < (_list)[(_index)]) { \
|
||||
(__max) = (_list)[(_index)]; \
|
||||
(__maxIndex) = (_index); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static void getStatics_bool(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int8_t *data = (int8_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -43,26 +61,17 @@ static void getStatics_bool(const TSKEY *primaryKey, const void *pData, int32_t
|
|||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (isNull((char *)&data[i], TSDB_DATA_TYPE_BOOL)) {
|
||||
if (data[i] == TSDB_DATA_BOOL_NULL) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
*sum += data[i];
|
||||
if (*min > data[i]) {
|
||||
*min = data[i];
|
||||
*minIndex = i;
|
||||
}
|
||||
|
||||
if (*max < data[i]) {
|
||||
*max = data[i];
|
||||
*maxIndex = i;
|
||||
}
|
||||
|
||||
DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i);
|
||||
}
|
||||
}
|
||||
|
||||
static void getStatics_i8(const TSKEY *primaryKey, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
static void getStatics_i8(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int8_t *data = (int8_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
*max = INT64_MIN;
|
||||
|
@ -72,26 +81,43 @@ static void getStatics_i8(const TSKEY *primaryKey, const void *pData, int32_t nu
|
|||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (isNull((char *)&data[i], TSDB_DATA_TYPE_TINYINT)) {
|
||||
if (((uint8_t)data[i]) == TSDB_DATA_TINYINT_NULL) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
*sum += data[i];
|
||||
if (*min > data[i]) {
|
||||
*min = data[i];
|
||||
*minIndex = i;
|
||||
}
|
||||
|
||||
if (*max < data[i]) {
|
||||
*max = data[i];
|
||||
*maxIndex = i;
|
||||
}
|
||||
|
||||
DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i);
|
||||
}
|
||||
}
|
||||
|
||||
static void getStatics_i16(const TSKEY *primaryKey, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
static void getStatics_u8(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint8_t *data = (uint8_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
uint64_t _max = 0;
|
||||
uint64_t _sum = 0;
|
||||
|
||||
*minIndex = 0;
|
||||
*maxIndex = 0;
|
||||
|
||||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint8_t)data[i]) == TSDB_DATA_UTINYINT_NULL) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
DO_STATICS(_sum, _min, _max, *minIndex, *maxIndex, data, i);
|
||||
}
|
||||
|
||||
*min = _min;
|
||||
*max = _max;
|
||||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_i16(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int16_t *data = (int16_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
*max = INT64_MIN;
|
||||
|
@ -100,39 +126,45 @@ static void getStatics_i16(const TSKEY *primaryKey, const void *pData, int32_t n
|
|||
|
||||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
||||
// int64_t lastKey = 0;
|
||||
// int16_t lastVal = TSDB_DATA_SMALLINT_NULL;
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (isNull((const char*) &data[i], TSDB_DATA_TYPE_SMALLINT)) {
|
||||
if (((uint16_t)data[i]) == TSDB_DATA_SMALLINT_NULL) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
*sum += data[i];
|
||||
if (*min > data[i]) {
|
||||
*min = data[i];
|
||||
*minIndex = i;
|
||||
}
|
||||
|
||||
if (*max < data[i]) {
|
||||
*max = data[i];
|
||||
*maxIndex = i;
|
||||
}
|
||||
|
||||
// if (isNull(&lastVal, TSDB_DATA_TYPE_SMALLINT)) {
|
||||
// lastKey = primaryKey[i];
|
||||
// lastVal = data[i];
|
||||
// } else {
|
||||
// *wsum = lastVal * (primaryKey[i] - lastKey);
|
||||
// lastKey = primaryKey[i];
|
||||
// lastVal = data[i];
|
||||
// }
|
||||
|
||||
DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void getStatics_i32(const TSKEY *primaryKey, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
static void getStatics_u16(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint16_t *data = (uint16_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
uint64_t _max = 0;
|
||||
uint64_t _sum = 0;
|
||||
|
||||
*minIndex = 0;
|
||||
*maxIndex = 0;
|
||||
|
||||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint16_t)data[i]) == TSDB_DATA_USMALLINT_NULL) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
DO_STATICS(_sum, _min, _max, *minIndex, *maxIndex, data, i);
|
||||
}
|
||||
|
||||
*min = _min;
|
||||
*max = _max;
|
||||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_i32(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int32_t *data = (int32_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
*max = INT64_MIN;
|
||||
|
@ -141,29 +173,43 @@ static void getStatics_i32(const TSKEY *primaryKey, const void *pData, int32_t n
|
|||
|
||||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
||||
// int64_t lastKey = 0;
|
||||
// int32_t lastVal = TSDB_DATA_INT_NULL;
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (isNull((const char*) &data[i], TSDB_DATA_TYPE_INT)) {
|
||||
if (((uint32_t)data[i]) == TSDB_DATA_INT_NULL) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
*sum += data[i];
|
||||
if (*min > data[i]) {
|
||||
*min = data[i];
|
||||
*minIndex = i;
|
||||
}
|
||||
|
||||
if (*max < data[i]) {
|
||||
*max = data[i];
|
||||
*maxIndex = i;
|
||||
}
|
||||
|
||||
DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i);
|
||||
}
|
||||
}
|
||||
|
||||
static void getStatics_i64(const TSKEY *primaryKey, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
static void getStatics_u32(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint32_t *data = (uint32_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
uint64_t _max = 0;
|
||||
uint64_t _sum = 0;
|
||||
|
||||
*minIndex = 0;
|
||||
*maxIndex = 0;
|
||||
|
||||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint32_t)data[i]) == TSDB_DATA_UINT_NULL) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
DO_STATICS(_sum, _min, _max, *minIndex, *maxIndex, data, i);
|
||||
}
|
||||
|
||||
*min = _min;
|
||||
*max = _max;
|
||||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_i64(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int64_t *data = (int64_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -174,52 +220,60 @@ static void getStatics_i64(const TSKEY *primaryKey, const void *pData, int32_t n
|
|||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (isNull((const char*) &data[i], TSDB_DATA_TYPE_BIGINT)) {
|
||||
if (((uint64_t)data[i]) == TSDB_DATA_BIGINT_NULL) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
*sum += data[i];
|
||||
if (*min > data[i]) {
|
||||
*min = data[i];
|
||||
*minIndex = i;
|
||||
}
|
||||
|
||||
if (*max < data[i]) {
|
||||
*max = data[i];
|
||||
*maxIndex = i;
|
||||
}
|
||||
|
||||
// if (isNull(&lastVal, TSDB_DATA_TYPE_BIGINT)) {
|
||||
// lastKey = primaryKey[i];
|
||||
// lastVal = data[i];
|
||||
// } else {
|
||||
// *wsum = lastVal * (primaryKey[i] - lastKey);
|
||||
// lastKey = primaryKey[i];
|
||||
// lastVal = data[i];
|
||||
// }
|
||||
|
||||
DO_STATICS(*sum, *min, *max, *minIndex, *maxIndex, data, i);
|
||||
}
|
||||
}
|
||||
|
||||
static void getStatics_f(const TSKEY *primaryKey, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
static void getStatics_u64(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint64_t *data = (uint64_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
uint64_t _max = 0;
|
||||
uint64_t _sum = 0;
|
||||
|
||||
*minIndex = 0;
|
||||
*maxIndex = 0;
|
||||
|
||||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint64_t)data[i]) == TSDB_DATA_UBIGINT_NULL) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
DO_STATICS(_sum, _min, _max, *minIndex, *maxIndex, data, i);
|
||||
}
|
||||
|
||||
*min = _min;
|
||||
*max = _max;
|
||||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_f(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
float *data = (float *)pData;
|
||||
float fmin = FLT_MAX;
|
||||
float fmax = -FLT_MAX;
|
||||
double dsum = 0;
|
||||
*minIndex = 0;
|
||||
*maxIndex = 0;
|
||||
float *data = (float *)pData;
|
||||
float fmin = FLT_MAX;
|
||||
float fmax = -FLT_MAX;
|
||||
double dsum = 0;
|
||||
*minIndex = 0;
|
||||
*maxIndex = 0;
|
||||
|
||||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (isNull((const char*) &data[i], TSDB_DATA_TYPE_FLOAT)) {
|
||||
if ((*(uint32_t*)&(data[i])) == TSDB_DATA_FLOAT_NULL) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
float fv = 0;
|
||||
fv = GET_FLOAT_VAL((const char*)&(data[i]));
|
||||
|
||||
float fv = GET_FLOAT_VAL((const char*)&(data[i]));
|
||||
|
||||
dsum += fv;
|
||||
if (fmin > fv) {
|
||||
fmin = fv;
|
||||
|
@ -232,28 +286,24 @@ static void getStatics_f(const TSKEY *primaryKey, const void *pData, int32_t num
|
|||
}
|
||||
}
|
||||
|
||||
double csum = 0;
|
||||
csum = GET_DOUBLE_VAL((const char *)sum);
|
||||
csum += dsum;
|
||||
|
||||
SET_DOUBLE_VAL(sum, csum);
|
||||
SET_DOUBLE_VAL(sum, dsum);
|
||||
SET_DOUBLE_VAL(max, fmax);
|
||||
SET_DOUBLE_VAL(min, fmin);
|
||||
}
|
||||
|
||||
static void getStatics_d(const TSKEY *primaryKey, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
double *data = (double *)pData;
|
||||
double dmin = DBL_MAX;
|
||||
double dmax = -DBL_MAX;
|
||||
double dsum = 0;
|
||||
*minIndex = 0;
|
||||
*maxIndex = 0;
|
||||
double dmin = DBL_MAX;
|
||||
double dmax = -DBL_MAX;
|
||||
double dsum = 0;
|
||||
*minIndex = 0;
|
||||
*maxIndex = 0;
|
||||
|
||||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (isNull((const char*) &data[i], TSDB_DATA_TYPE_DOUBLE)) {
|
||||
if ((*(uint64_t*)&(data[i])) == TSDB_DATA_DOUBLE_NULL) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -272,16 +322,12 @@ static void getStatics_d(const TSKEY *primaryKey, const void *pData, int32_t num
|
|||
}
|
||||
}
|
||||
|
||||
double csum = 0;
|
||||
csum = GET_DOUBLE_VAL((const char *)sum);
|
||||
csum += dsum;
|
||||
|
||||
SET_DOUBLE_PTR(sum, &csum);
|
||||
SET_DOUBLE_PTR(sum, &dsum);
|
||||
SET_DOUBLE_PTR(max, &dmax);
|
||||
SET_DOUBLE_PTR(min, &dmin);
|
||||
}
|
||||
|
||||
static void getStatics_bin(const TSKEY *primaryKey, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
static void getStatics_bin(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
const char* data = pData;
|
||||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
@ -301,7 +347,7 @@ static void getStatics_bin(const TSKEY *primaryKey, const void *pData, int32_t n
|
|||
*maxIndex = 0;
|
||||
}
|
||||
|
||||
static void getStatics_nchr(const TSKEY *primaryKey, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
static void getStatics_nchr(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
const char* data = pData;
|
||||
ASSERT(numOfRow <= INT16_MAX);
|
||||
|
@ -321,18 +367,22 @@ static void getStatics_nchr(const TSKEY *primaryKey, const void *pData, int32_t
|
|||
*maxIndex = 0;
|
||||
}
|
||||
|
||||
tDataTypeDescriptor tDataTypeDesc[11] = {
|
||||
{TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE", NULL, NULL, NULL},
|
||||
{TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", tsCompressBool, tsDecompressBool, getStatics_bool},
|
||||
{TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT", tsCompressTinyint, tsDecompressTinyint, getStatics_i8},
|
||||
{TSDB_DATA_TYPE_SMALLINT, 8, SHORT_BYTES, "SMALLINT", tsCompressSmallint, tsDecompressSmallint, getStatics_i16},
|
||||
{TSDB_DATA_TYPE_INT, 3, INT_BYTES, "INT", tsCompressInt, tsDecompressInt, getStatics_i32},
|
||||
{TSDB_DATA_TYPE_BIGINT, 6, LONG_BYTES, "BIGINT", tsCompressBigint, tsDecompressBigint, getStatics_i64},
|
||||
{TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT", tsCompressFloat, tsDecompressFloat, getStatics_f},
|
||||
{TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE", tsCompressDouble, tsDecompressDouble, getStatics_d},
|
||||
{TSDB_DATA_TYPE_BINARY, 6, 0, "BINARY", tsCompressString, tsDecompressString, getStatics_bin},
|
||||
{TSDB_DATA_TYPE_TIMESTAMP, 9, LONG_BYTES, "TIMESTAMP", tsCompressTimestamp, tsDecompressTimestamp, getStatics_i64},
|
||||
{TSDB_DATA_TYPE_NCHAR, 5, 8, "NCHAR", tsCompressString, tsDecompressString, getStatics_nchr},
|
||||
tDataTypeDescriptor tDataTypeDesc[15] = {
|
||||
{TSDB_DATA_TYPE_NULL, 6,1, "NOTYPE", NULL, NULL, NULL},
|
||||
{TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", tsCompressBool, tsDecompressBool, getStatics_bool},
|
||||
{TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT", tsCompressTinyint, tsDecompressTinyint, getStatics_i8},
|
||||
{TSDB_DATA_TYPE_SMALLINT, 8, SHORT_BYTES, "SMALLINT", tsCompressSmallint, tsDecompressSmallint, getStatics_i16},
|
||||
{TSDB_DATA_TYPE_INT, 3, INT_BYTES, "INT", tsCompressInt, tsDecompressInt, getStatics_i32},
|
||||
{TSDB_DATA_TYPE_BIGINT, 6, LONG_BYTES, "BIGINT", tsCompressBigint, tsDecompressBigint, getStatics_i64},
|
||||
{TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT", tsCompressFloat, tsDecompressFloat, getStatics_f},
|
||||
{TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE", tsCompressDouble, tsDecompressDouble, getStatics_d},
|
||||
{TSDB_DATA_TYPE_BINARY, 6, 0, "BINARY", tsCompressString, tsDecompressString, getStatics_bin},
|
||||
{TSDB_DATA_TYPE_TIMESTAMP, 9, LONG_BYTES, "TIMESTAMP", tsCompressTimestamp, tsDecompressTimestamp, getStatics_i64},
|
||||
{TSDB_DATA_TYPE_NCHAR, 5, 8, "NCHAR", tsCompressString, tsDecompressString, getStatics_nchr},
|
||||
{TSDB_DATA_TYPE_UTINYINT, 16, CHAR_BYTES, "TINYINT UNSIGNED", tsCompressTinyint, tsDecompressTinyint, getStatics_u8},
|
||||
{TSDB_DATA_TYPE_USMALLINT, 17, SHORT_BYTES, "SMALLINT UNSIGNED", tsCompressSmallint, tsDecompressSmallint, getStatics_u16},
|
||||
{TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", tsCompressInt, tsDecompressInt, getStatics_u32},
|
||||
{TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", tsCompressBigint, tsDecompressBigint, getStatics_u64},
|
||||
};
|
||||
|
||||
char tTokenTypeSwitcher[13] = {
|
||||
|
@ -352,7 +402,7 @@ char tTokenTypeSwitcher[13] = {
|
|||
};
|
||||
|
||||
bool isValidDataType(int32_t type) {
|
||||
return type >= TSDB_DATA_TYPE_NULL && type <= TSDB_DATA_TYPE_NCHAR;
|
||||
return type >= TSDB_DATA_TYPE_NULL && type <= TSDB_DATA_TYPE_UBIGINT;
|
||||
}
|
||||
|
||||
void setVardataNull(char* val, int32_t type) {
|
||||
|
@ -397,6 +447,26 @@ void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems) {
|
|||
*(uint64_t *)(val + i * tDataTypeDesc[type].nSize) = TSDB_DATA_BIGINT_NULL;
|
||||
}
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
for (int32_t i = 0; i < numOfElems; ++i) {
|
||||
*(uint8_t *)(val + i * tDataTypeDesc[type].nSize) = TSDB_DATA_UTINYINT_NULL;
|
||||
}
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
for (int32_t i = 0; i < numOfElems; ++i) {
|
||||
*(uint16_t *)(val + i * tDataTypeDesc[type].nSize) = TSDB_DATA_USMALLINT_NULL;
|
||||
}
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
for (int32_t i = 0; i < numOfElems; ++i) {
|
||||
*(uint32_t *)(val + i * tDataTypeDesc[type].nSize) = TSDB_DATA_UINT_NULL;
|
||||
}
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
for (int32_t i = 0; i < numOfElems; ++i) {
|
||||
*(uint64_t *)(val + i * tDataTypeDesc[type].nSize) = TSDB_DATA_UBIGINT_NULL;
|
||||
}
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
for (int32_t i = 0; i < numOfElems; ++i) {
|
||||
*(uint32_t *)(val + i * tDataTypeDesc[type].nSize) = TSDB_DATA_FLOAT_NULL;
|
||||
|
@ -422,13 +492,17 @@ void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems) {
|
|||
}
|
||||
}
|
||||
|
||||
static uint8_t nullBool = TSDB_DATA_BOOL_NULL;
|
||||
static uint8_t nullTinyInt = TSDB_DATA_TINYINT_NULL;
|
||||
static uint16_t nullSmallInt = TSDB_DATA_SMALLINT_NULL;
|
||||
static uint32_t nullInt = TSDB_DATA_INT_NULL;
|
||||
static uint64_t nullBigInt = TSDB_DATA_BIGINT_NULL;
|
||||
static uint32_t nullFloat = TSDB_DATA_FLOAT_NULL;
|
||||
static uint64_t nullDouble = TSDB_DATA_DOUBLE_NULL;
|
||||
static uint8_t nullBool = TSDB_DATA_BOOL_NULL;
|
||||
static uint8_t nullTinyInt = TSDB_DATA_TINYINT_NULL;
|
||||
static uint16_t nullSmallInt = TSDB_DATA_SMALLINT_NULL;
|
||||
static uint32_t nullInt = TSDB_DATA_INT_NULL;
|
||||
static uint64_t nullBigInt = TSDB_DATA_BIGINT_NULL;
|
||||
static uint32_t nullFloat = TSDB_DATA_FLOAT_NULL;
|
||||
static uint64_t nullDouble = TSDB_DATA_DOUBLE_NULL;
|
||||
static uint8_t nullTinyIntu = TSDB_DATA_UTINYINT_NULL;
|
||||
static uint16_t nullSmallIntu = TSDB_DATA_USMALLINT_NULL;
|
||||
static uint32_t nullIntu = TSDB_DATA_UINT_NULL;
|
||||
static uint64_t nullBigIntu = TSDB_DATA_UBIGINT_NULL;
|
||||
|
||||
static union {
|
||||
tstr str;
|
||||
|
@ -436,17 +510,25 @@ static union {
|
|||
} nullBinary = {.str = {.len = 1}}, nullNchar = {.str = {.len = 4}};
|
||||
|
||||
static void *nullValues[] = {
|
||||
&nullBool, &nullTinyInt, &nullSmallInt, &nullInt, &nullBigInt,
|
||||
&nullFloat, &nullDouble, &nullBinary, &nullBigInt, &nullNchar,
|
||||
&nullBool, &nullTinyInt, &nullSmallInt, &nullInt, &nullBigInt,
|
||||
&nullFloat, &nullDouble, &nullBinary, &nullBigInt, &nullNchar,
|
||||
&nullTinyIntu, &nullSmallIntu, &nullIntu, &nullBigIntu,
|
||||
};
|
||||
|
||||
void *getNullValue(int32_t type) {
|
||||
assert(type >= TSDB_DATA_TYPE_BOOL && type <= TSDB_DATA_TYPE_NCHAR);
|
||||
assert(type >= TSDB_DATA_TYPE_BOOL && type <= TSDB_DATA_TYPE_UBIGINT);
|
||||
return nullValues[type - 1];
|
||||
}
|
||||
|
||||
void assignVal(char *val, const char *src, int32_t len, int32_t type) {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
*((int8_t *)val) = GET_INT8_VAL(src);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
*((int16_t *)val) = GET_INT16_VAL(src);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
*((int32_t *)val) = GET_INT32_VAL(src);
|
||||
break;
|
||||
|
@ -457,17 +539,10 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
|
|||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
SET_DOUBLE_VAL(val, GET_DOUBLE_VAL(src));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
*((int64_t *)val) = GET_INT64_VAL(src);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
*((int16_t *)val) = GET_INT16_VAL(src);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
*((int8_t *)val) = GET_INT8_VAL(src);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
varDataCopy(val, src);
|
||||
break;
|
||||
|
@ -483,12 +558,14 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
|
|||
|
||||
void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf) {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
SWAP(*(int32_t *)(pLeft), *(int32_t *)(pRight), int32_t);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
SWAP(*(int64_t *)(pLeft), *(int64_t *)(pRight), int64_t);
|
||||
break;
|
||||
|
@ -497,7 +574,8 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
SWAP(*(double *)(pLeft), *(double *)(pRight), double);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT: {
|
||||
SWAP(*(int16_t *)(pLeft), *(int16_t *)(pRight), int16_t);
|
||||
break;
|
||||
}
|
||||
|
@ -508,7 +586,8 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_UTINYINT: {
|
||||
SWAP(*(int8_t *)(pLeft), *(int8_t *)(pRight), int8_t);
|
||||
break;
|
||||
}
|
||||
|
@ -521,3 +600,41 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bool issigned) {
|
||||
errno = 0;
|
||||
int32_t ret = 0;
|
||||
|
||||
char* endPtr = NULL;
|
||||
if (type == TK_FLOAT) {
|
||||
double v = strtod(z, &endPtr);
|
||||
if ((errno == ERANGE && v == HUGE_VALF) || isinf(v) || isnan(v)) {
|
||||
ret = -1;
|
||||
} else if ((issigned && (v < INT64_MIN || v > INT64_MAX)) || ((!issigned) && (v < 0 || v > UINT64_MAX))) {
|
||||
ret = -1;
|
||||
} else {
|
||||
*value = (int64_t) round(v);
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t radix = 10;
|
||||
if (type == TK_HEX) {
|
||||
radix = 16;
|
||||
} else if (type == TK_BIN) {
|
||||
radix = 2;
|
||||
}
|
||||
|
||||
// the string may be overflow according to errno
|
||||
*value = issigned? strtoll(z, &endPtr, radix):strtoul(z, &endPtr, radix);
|
||||
|
||||
// not a valid integer number, return error
|
||||
if (endPtr - z != n || errno == ERANGE) {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -21,36 +21,48 @@
|
|||
#include "tstoken.h"
|
||||
#include "ttokendef.h"
|
||||
#include "tutil.h"
|
||||
#include "ttype.h"
|
||||
|
||||
// todo support scientific expression number and oct number
|
||||
void tVariantCreate(tVariant *pVar, SStrToken *token) { tVariantCreateFromString(pVar, token->z, token->n, token->type); }
|
||||
void tVariantCreate(tVariant *pVar, SStrToken *token) {
|
||||
int32_t ret = 0;
|
||||
int32_t type = token->type;
|
||||
|
||||
void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t type) {
|
||||
memset(pVar, 0, sizeof(tVariant));
|
||||
|
||||
switch (type) {
|
||||
|
||||
switch (token->type) {
|
||||
case TSDB_DATA_TYPE_BOOL: {
|
||||
int32_t k = strncasecmp(pz, "true", 4);
|
||||
int32_t k = strncasecmp(token->z, "true", 4);
|
||||
if (k == 0) {
|
||||
pVar->i64Key = TSDB_TRUE;
|
||||
pVar->i64 = TSDB_TRUE;
|
||||
} else {
|
||||
assert(strncasecmp(pz, "false", 5) == 0);
|
||||
pVar->i64Key = TSDB_FALSE;
|
||||
assert(strncasecmp(token->z, "false", 5) == 0);
|
||||
pVar->i64 = TSDB_FALSE;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
pVar->i64Key = strtoll(pz, NULL, 10);
|
||||
case TSDB_DATA_TYPE_INT:{
|
||||
ret = tStrToInteger(token->z, token->type, token->n, &pVar->i64, true);
|
||||
if (ret != 0) {
|
||||
pVar->nType = -1; // -1 means error type
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
pVar->dKey = strtod(pz, NULL);
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
pVar->dKey = strtod(token->z, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BINARY: {
|
||||
pVar->pz = strndup(pz, len);
|
||||
pVar->pz = strndup(token->z, token->n);
|
||||
pVar->nLen = strdequote(pVar->pz);
|
||||
break;
|
||||
}
|
||||
|
@ -74,20 +86,36 @@ void tVariantCreateFromBinary(tVariant *pVar, const char *pz, size_t len, uint32
|
|||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
pVar->i64Key = GET_INT8_VAL(pz);
|
||||
pVar->i64 = GET_INT8_VAL(pz);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_UTINYINT: {
|
||||
pVar->u64 = GET_UINT8_VAL(pz);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
pVar->i64Key = GET_INT16_VAL(pz);
|
||||
pVar->i64 = GET_INT16_VAL(pz);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_USMALLINT: {
|
||||
pVar->u64 = GET_UINT16_VAL(pz);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
pVar->i64Key = GET_INT32_VAL(pz);
|
||||
pVar->i64 = GET_INT32_VAL(pz);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
pVar->u64 = GET_UINT32_VAL(pz);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
pVar->i64Key = GET_INT64_VAL(pz);
|
||||
pVar->i64 = GET_INT64_VAL(pz);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_UBIGINT: {
|
||||
pVar->u64 = GET_UINT64_VAL(pz);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
|
@ -115,7 +143,7 @@ void tVariantCreateFromBinary(tVariant *pVar, const char *pz, size_t len, uint32
|
|||
}
|
||||
|
||||
default:
|
||||
pVar->i64Key = GET_INT32_VAL(pVar);
|
||||
pVar->i64 = GET_INT32_VAL(pz);
|
||||
}
|
||||
|
||||
pVar->nType = type;
|
||||
|
@ -141,6 +169,11 @@ void tVariantDestroy(tVariant *pVar) {
|
|||
}
|
||||
}
|
||||
|
||||
bool tVariantIsValid(tVariant *pVar) {
|
||||
assert(pVar != NULL);
|
||||
return isValidDataType(pVar->nType);
|
||||
}
|
||||
|
||||
void tVariantAssign(tVariant *pDst, const tVariant *pSrc) {
|
||||
if (pSrc == NULL || pDst == NULL) return;
|
||||
|
||||
|
@ -159,8 +192,8 @@ void tVariantAssign(tVariant *pDst, const tVariant *pSrc) {
|
|||
|
||||
}
|
||||
|
||||
if (pSrc->nType >= TSDB_DATA_TYPE_BOOL && pSrc->nType <= TSDB_DATA_TYPE_DOUBLE) {
|
||||
pDst->i64Key = pSrc->i64Key;
|
||||
if (IS_NUMERIC_TYPE(pSrc->nType) || (pSrc->nType == TSDB_DATA_TYPE_BOOL)) {
|
||||
pDst->i64 = pSrc->i64;
|
||||
} else if (pSrc->nType == TSDB_DATA_TYPE_ARRAY) { // this is only for string array
|
||||
size_t num = taosArrayGetSize(pSrc->arr);
|
||||
pDst->arr = taosArrayInit(num, sizeof(char*));
|
||||
|
@ -189,30 +222,30 @@ int32_t tVariantCompare(const tVariant* p1, const tVariant* p2) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
switch (p1->nType) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
if (p1->nLen == p2->nLen) {
|
||||
return memcmp(p1->pz, p2->pz, p1->nLen);
|
||||
} else {
|
||||
return p1->nLen > p2->nLen? 1:-1;
|
||||
}
|
||||
};
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
if (p1->dKey == p2->dKey) {
|
||||
return 0;
|
||||
} else {
|
||||
return p1->dKey > p2->dKey? 1:-1;
|
||||
}
|
||||
|
||||
default:
|
||||
if (p1->i64Key == p2->i64Key) {
|
||||
return 0;
|
||||
} else {
|
||||
return p1->i64Key > p2->i64Key? 1:-1;
|
||||
}
|
||||
if (p1->nType == TSDB_DATA_TYPE_BINARY || p1->nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
if (p1->nLen == p2->nLen) {
|
||||
return memcmp(p1->pz, p2->pz, p1->nLen);
|
||||
} else {
|
||||
return p1->nLen > p2->nLen? 1:-1;
|
||||
}
|
||||
} else if (p1->nType == TSDB_DATA_TYPE_FLOAT || p1->nType == TSDB_DATA_TYPE_DOUBLE) {
|
||||
if (p1->dKey == p2->dKey) {
|
||||
return 0;
|
||||
} else {
|
||||
return p1->dKey > p2->dKey? 1:-1;
|
||||
}
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(p1->nType)) {
|
||||
if (p1->u64 == p2->u64) {
|
||||
return 0;
|
||||
} else {
|
||||
return p1->u64 > p2->u64? 1:-1;
|
||||
}
|
||||
} else {
|
||||
if (p1->i64 == p2->i64) {
|
||||
return 0;
|
||||
} else {
|
||||
return p1->i64 > p2->i64? 1:-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,11 +272,15 @@ int32_t tVariantToString(tVariant *pVar, char *dst) {
|
|||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
return sprintf(dst, "%d", (int32_t)pVar->i64Key);
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
return sprintf(dst, "%d", (int32_t)pVar->i64);
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
return sprintf(dst, "%" PRId64, pVar->i64Key);
|
||||
|
||||
return sprintf(dst, "%" PRId64, pVar->i64);
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
return sprintf(dst, "%" PRIu64, pVar->u64);
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
return sprintf(dst, "%.9lf", pVar->dKey);
|
||||
|
@ -253,121 +290,6 @@ int32_t tVariantToString(tVariant *pVar, char *dst) {
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int32_t doConvertToInteger(tVariant *pVariant, char *pDest, int32_t type, bool releaseVariantPtr) {
|
||||
if (pVariant->nType == TSDB_DATA_TYPE_NULL) {
|
||||
setNull(pDest, type, tDataTypeDesc[type].nSize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
*((int64_t *)pDest) = pVariant->i64Key;
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) {
|
||||
if ((pVariant->dKey < INT64_MIN) || (pVariant->dKey > INT64_MAX)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*((int64_t *)pDest) = (int64_t)pVariant->dKey;
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) {
|
||||
errno = 0;
|
||||
char *endPtr = NULL;
|
||||
|
||||
SStrToken token = {0};
|
||||
token.n = tSQLGetToken(pVariant->pz, &token.type);
|
||||
|
||||
if (token.type == TK_MINUS || token.type == TK_PLUS) {
|
||||
token.n = tSQLGetToken(pVariant->pz + token.n, &token.type);
|
||||
}
|
||||
|
||||
if (token.type == TK_FLOAT) {
|
||||
double v = strtod(pVariant->pz, &endPtr);
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
pVariant->nLen = 0;
|
||||
}
|
||||
|
||||
if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((v < INT64_MIN) || (v > INT64_MAX)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*((int64_t *)pDest) = (int64_t)v;
|
||||
} else if (token.type == TK_INTEGER) {
|
||||
int64_t val = strtoll(pVariant->pz, &endPtr, 10);
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
pVariant->nLen = 0;
|
||||
}
|
||||
|
||||
if (errno == ERANGE) {
|
||||
return -1; // data overflow
|
||||
}
|
||||
|
||||
*((int64_t *)pDest) = val;
|
||||
} else if (token.type == TK_NULL) {
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
pVariant->nLen = 0;
|
||||
}
|
||||
setNull(pDest, type, tDataTypeDesc[type].nSize);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
errno = 0;
|
||||
wchar_t *endPtr = NULL;
|
||||
|
||||
SStrToken token = {0};
|
||||
token.n = tSQLGetToken(pVariant->pz, &token.type);
|
||||
|
||||
if (token.type == TK_MINUS || token.type == TK_PLUS) {
|
||||
token.n = tSQLGetToken(pVariant->pz + token.n, &token.type);
|
||||
}
|
||||
|
||||
if (token.type == TK_FLOAT) {
|
||||
double v = wcstod(pVariant->wpz, &endPtr);
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
pVariant->nLen = 0;
|
||||
}
|
||||
|
||||
if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((v < INT64_MIN) || (v > INT64_MAX)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*((int64_t *)pDest) = (int64_t)v;
|
||||
} else if (token.type == TK_NULL) {
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
pVariant->nLen = 0;
|
||||
}
|
||||
setNull(pDest, type, tDataTypeDesc[type].nSize);
|
||||
} else {
|
||||
int64_t val = wcstoll(pVariant->wpz, &endPtr, 10);
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
pVariant->nLen = 0;
|
||||
}
|
||||
|
||||
if (errno == ERANGE) {
|
||||
return -1; // data overflow
|
||||
}
|
||||
|
||||
*((int64_t *)pDest) = val;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
static FORCE_INLINE int32_t convertToBoolImpl(char *pStr, int32_t len) {
|
||||
if ((strncasecmp(pStr, "true", len) == 0) && (len == 4)) {
|
||||
return TSDB_TRUE;
|
||||
|
@ -385,15 +307,18 @@ static FORCE_INLINE int32_t wcsconvertToBoolImpl(wchar_t *pstr, int32_t len) {
|
|||
return TSDB_TRUE;
|
||||
} else if (wcsncasecmp(pstr, L"false", len) == 0 && (len == 5)) {
|
||||
return TSDB_FALSE;
|
||||
} else if (memcmp(pstr, L"null", wcslen(L"null")) == 0) {
|
||||
return TSDB_DATA_BOOL_NULL;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t toBinary(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
|
||||
const int32_t INITIAL_ALLOC_SIZE = 20;
|
||||
const int32_t INITIAL_ALLOC_SIZE = 40;
|
||||
char * pBuf = NULL;
|
||||
|
||||
|
||||
// it is a in-place convert type for tVariant, local buffer is needed
|
||||
if (*pDest == pVariant->pz) {
|
||||
pBuf = calloc(1, INITIAL_ALLOC_SIZE);
|
||||
}
|
||||
|
@ -413,12 +338,12 @@ static int32_t toBinary(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
|
|||
}
|
||||
|
||||
} else {
|
||||
if (pVariant->nType >= TSDB_DATA_TYPE_TINYINT && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
sprintf(pBuf == NULL ? *pDest : pBuf, "%" PRId64, pVariant->i64Key);
|
||||
if (IS_SIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
||||
sprintf(pBuf == NULL ? *pDest : pBuf, "%" PRId64, pVariant->i64);
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) {
|
||||
sprintf(pBuf == NULL ? *pDest : pBuf, "%lf", pVariant->dKey);
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_BOOL) {
|
||||
sprintf(pBuf == NULL ? *pDest : pBuf, "%s", (pVariant->i64Key == TSDB_TRUE) ? "TRUE" : "FALSE");
|
||||
sprintf(pBuf == NULL ? *pDest : pBuf, "%s", (pVariant->i64 == TSDB_TRUE) ? "TRUE" : "FALSE");
|
||||
} else if (pVariant->nType == 0) { // null data
|
||||
setNull(pBuf == NULL ? *pDest : pBuf, TSDB_DATA_TYPE_BINARY, 0);
|
||||
}
|
||||
|
@ -432,28 +357,33 @@ static int32_t toBinary(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// todo handle the error
|
||||
static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
|
||||
char tmpBuf[40] = {0};
|
||||
|
||||
char * pDst = tmpBuf;
|
||||
int32_t nLen = 0;
|
||||
|
||||
if (pVariant->nType >= TSDB_DATA_TYPE_TINYINT && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
nLen = sprintf(pDst, "%" PRId64, pVariant->i64Key);
|
||||
|
||||
// convert the number to string, than convert it to wchar string.
|
||||
if (IS_SIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
||||
nLen = sprintf(pDst, "%" PRId64, pVariant->i64);
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
||||
nLen = sprintf(pDst, "%"PRIu64, pVariant->u64);
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) {
|
||||
nLen = sprintf(pDst, "%lf", pVariant->dKey);
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) {
|
||||
pDst = pVariant->pz;
|
||||
nLen = pVariant->nLen;
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_BOOL) {
|
||||
nLen = sprintf(pDst, "%s", (pVariant->i64Key == TSDB_TRUE) ? "TRUE" : "FALSE");
|
||||
nLen = sprintf(pDst, "%s", (pVariant->i64 == TSDB_TRUE) ? "TRUE" : "FALSE");
|
||||
}
|
||||
|
||||
if (*pDest == pVariant->pz) {
|
||||
wchar_t *pWStr = calloc(1, (nLen + 1) * TSDB_NCHAR_SIZE);
|
||||
taosMbsToUcs4(pDst, nLen, (char *)pWStr, (nLen + 1) * TSDB_NCHAR_SIZE, NULL);
|
||||
|
||||
bool ret = taosMbsToUcs4(pDst, nLen, (char *)pWStr, (nLen + 1) * TSDB_NCHAR_SIZE, NULL);
|
||||
if (!ret) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// free the binary buffer in the first place
|
||||
if (pVariant->nType == TSDB_DATA_TYPE_BINARY) {
|
||||
free(pVariant->wpz);
|
||||
|
@ -468,11 +398,15 @@ static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
|
|||
|
||||
pVariant->wpz = (wchar_t *)tmp;
|
||||
} else {
|
||||
size_t output = -1;
|
||||
taosMbsToUcs4(pDst, nLen, *pDest, (nLen + 1) * TSDB_NCHAR_SIZE, &output);
|
||||
|
||||
int32_t output = 0;
|
||||
|
||||
bool ret = taosMbsToUcs4(pDst, nLen, *pDest, (nLen + 1) * TSDB_NCHAR_SIZE, &output);
|
||||
if (!ret) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pDestSize != NULL) {
|
||||
*pDestSize = (int32_t)output;
|
||||
*pDestSize = output;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -481,38 +415,31 @@ static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) {
|
|||
|
||||
static FORCE_INLINE int32_t convertToDouble(char *pStr, int32_t len, double *value) {
|
||||
SStrToken stoken = {.z = pStr, .n = len};
|
||||
|
||||
if (TK_ILLEGAL == isValidNumber(&stoken)) {
|
||||
if (TK_ILLEGAL == tGetNumericStringType(&stoken)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*value = strtod(pStr, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result, int32_t type, int64_t lowBnd,
|
||||
int64_t upperBnd, bool releaseVariantPtr) {
|
||||
static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result, int32_t type, bool issigned, bool releaseVariantPtr) {
|
||||
if (pVariant->nType == TSDB_DATA_TYPE_NULL) {
|
||||
setNull((char *)result, type, tDataTypeDesc[type].nSize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
*result = pVariant->i64Key;
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) {
|
||||
*result = (int64_t)pVariant->dKey;
|
||||
|
||||
errno = 0;
|
||||
if (IS_SIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
||||
*result = pVariant->i64;
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
||||
*result = pVariant->u64;
|
||||
} else if (IS_FLOAT_TYPE(pVariant->nType)) {
|
||||
*result = (int64_t) pVariant->dKey;
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) {
|
||||
errno = 0;
|
||||
char *endPtr = NULL;
|
||||
|
||||
SStrToken token = {0};
|
||||
token.n = tSQLGetToken(pVariant->pz, &token.type);
|
||||
|
||||
if (token.type == TK_MINUS || token.type == TK_PLUS) {
|
||||
token.n = tSQLGetToken(pVariant->pz + token.n, &token.type);
|
||||
}
|
||||
|
||||
SStrToken token = {.z = pVariant->pz, .n = pVariant->nLen};
|
||||
/*int32_t n = */tSQLGetToken(pVariant->pz, &token.type);
|
||||
|
||||
if (token.type == TK_NULL) {
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
|
@ -522,39 +449,25 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
|
|||
setNull((char *)result, type, tDataTypeDesc[type].nSize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SStrToken sToken = {.z = pVariant->pz, .n = pVariant->nLen};
|
||||
if (TK_ILLEGAL == isValidNumber(&sToken)) {
|
||||
|
||||
// decide if it is a valid number
|
||||
token.type = tGetNumericStringType(&token);
|
||||
if (token.type == TK_ILLEGAL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (token.type == TK_FLOAT) {
|
||||
double v = strtod(pVariant->pz, &endPtr);
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
pVariant->nLen = 0;
|
||||
}
|
||||
|
||||
if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*result = (int64_t)v;
|
||||
} else if (token.type == TK_INTEGER) {
|
||||
int64_t val = strtoll(pVariant->pz, &endPtr, 10);
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
pVariant->nLen = 0;
|
||||
}
|
||||
|
||||
if (errno == ERANGE) {
|
||||
return -1; // data overflow
|
||||
}
|
||||
|
||||
*result = val;
|
||||
} else {
|
||||
|
||||
int64_t res = 0;
|
||||
int32_t t = tStrToInteger(token.z, token.type, token.n, &res, issigned);
|
||||
if (t != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
pVariant->nLen = 0;
|
||||
}
|
||||
|
||||
*result = res;
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
errno = 0;
|
||||
wchar_t *endPtr = NULL;
|
||||
|
@ -599,19 +512,35 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result
|
|||
*result = val;
|
||||
}
|
||||
}
|
||||
|
||||
if ((*result <= lowBnd) || (*result > upperBnd)) {
|
||||
return -1;
|
||||
|
||||
bool code = false;
|
||||
switch(type) {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
code = IS_VALID_TINYINT(*result); break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
code = IS_VALID_SMALLINT(*result); break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
code = IS_VALID_INT(*result); break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
code = IS_VALID_BIGINT(*result); break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
code = IS_VALID_UTINYINT(*result); break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
code = IS_VALID_USMALLINT(*result); break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
code = IS_VALID_UINT(*result); break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
code = IS_VALID_UBIGINT(*result); break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
return code? 0:-1;
|
||||
}
|
||||
|
||||
static int32_t convertToBool(tVariant *pVariant, int64_t *pDest) {
|
||||
if (pVariant->nType == TSDB_DATA_TYPE_BOOL) {
|
||||
*pDest = pVariant->i64Key; // in order to be compatible to null of bool
|
||||
} else if (pVariant->nType >= TSDB_DATA_TYPE_TINYINT && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
*pDest = ((pVariant->i64Key != 0) ? TSDB_TRUE : TSDB_FALSE);
|
||||
*pDest = pVariant->i64; // in order to be compatible to null of bool
|
||||
} else if (IS_NUMERIC_TYPE(pVariant->nType)) {
|
||||
*pDest = ((pVariant->i64 != 0) ? TSDB_TRUE : TSDB_FALSE);
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_FLOAT || pVariant->nType == TSDB_DATA_TYPE_DOUBLE) {
|
||||
*pDest = ((pVariant->dKey != 0) ? TSDB_TRUE : TSDB_FALSE);
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) {
|
||||
|
@ -638,8 +567,6 @@ static int32_t convertToBool(tVariant *pVariant, int64_t *pDest) {
|
|||
/*
|
||||
* transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType
|
||||
* to column type defined in schema
|
||||
*
|
||||
* todo handle the return value
|
||||
*/
|
||||
int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix) {
|
||||
if (pVariant == NULL || (pVariant->nType != 0 && !isValidDataType(pVariant->nType))) {
|
||||
|
@ -647,57 +574,82 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
|
|||
}
|
||||
|
||||
errno = 0; // reset global error code
|
||||
|
||||
int64_t result;
|
||||
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL: {
|
||||
int64_t dst = 0;
|
||||
if (convertToBool(pVariant, &dst) < 0) {
|
||||
if (convertToBool(pVariant, &result) < 0) {
|
||||
return -1;
|
||||
}
|
||||
*(int8_t *)payload = (int8_t)dst;
|
||||
|
||||
*(int8_t *)payload = (int8_t)result;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
int64_t result = 0;
|
||||
if (convertToInteger(pVariant, &result, type, INT8_MIN, INT8_MAX, false) < 0) {
|
||||
if (convertToInteger(pVariant, &result, type, true, false) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*((int8_t *)payload) = (int8_t)result;
|
||||
*((int8_t *)payload) = (int8_t) result;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_UTINYINT: {
|
||||
if (convertToInteger(pVariant, &result, type, false, false) < 0) {
|
||||
return -1;
|
||||
}
|
||||
*((uint8_t *)payload) = (uint8_t) result;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
int64_t result = 0;
|
||||
if (convertToInteger(pVariant, &result, type, INT16_MIN, INT16_MAX, false) < 0) {
|
||||
if (convertToInteger(pVariant, &result, type, true, false) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*((int16_t *)payload) = (int16_t)result;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_USMALLINT: {
|
||||
if (convertToInteger(pVariant, &result, type, false, false) < 0) {
|
||||
return -1;
|
||||
}
|
||||
*((uint16_t *)payload) = (uint16_t)result;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
int64_t result = 0;
|
||||
if (convertToInteger(pVariant, &result, type, INT32_MIN, INT32_MAX, false) < 0) {
|
||||
if (convertToInteger(pVariant, &result, type, true, false) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*((int32_t *)payload) = (int32_t)result;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
if (convertToInteger(pVariant, &result, type, false, false) < 0) {
|
||||
return -1;
|
||||
}
|
||||
*((uint32_t *)payload) = (uint32_t)result;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
int64_t result = 0;
|
||||
if (convertToInteger(pVariant, &result, type, INT64_MIN, INT64_MAX, false) < 0) {
|
||||
if (convertToInteger(pVariant, &result, type, true, false) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*((int64_t *)payload) = (int64_t)result;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case TSDB_DATA_TYPE_UBIGINT: {
|
||||
if (convertToInteger(pVariant, &result, type, false, false) < 0) {
|
||||
return -1;
|
||||
}
|
||||
*((uint64_t *)payload) = (uint64_t)result;
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
if (pVariant->nType == TSDB_DATA_TYPE_BINARY) {
|
||||
if (strncasecmp(TSDB_DATA_NULL_STR_L, pVariant->pz, pVariant->nLen) == 0 &&
|
||||
|
@ -706,20 +658,19 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
|
|||
return 0;
|
||||
} else {
|
||||
double value = -1;
|
||||
int32_t ret;
|
||||
ret = convertToDouble(pVariant->pz, pVariant->nLen, &value);
|
||||
int32_t ret = convertToDouble(pVariant->pz, pVariant->nLen, &value);
|
||||
if ((errno == ERANGE && (float)value == -1) || (ret != 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SET_FLOAT_VAL(payload, value);
|
||||
}
|
||||
} else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
SET_FLOAT_VAL(payload, pVariant->i64Key);
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) {
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_BOOL || IS_SIGNED_NUMERIC_TYPE(pVariant->nType) || IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
||||
SET_FLOAT_VAL(payload, pVariant->i64);
|
||||
} else if (IS_FLOAT_TYPE(pVariant->nType)) {
|
||||
SET_FLOAT_VAL(payload, pVariant->dKey);
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_NULL) {
|
||||
*((int32_t *)payload) = TSDB_DATA_FLOAT_NULL;
|
||||
*((uint32_t *)payload) = TSDB_DATA_FLOAT_NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -745,9 +696,9 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
|
|||
|
||||
SET_DOUBLE_VAL(payload, value);
|
||||
}
|
||||
} else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
SET_DOUBLE_VAL(payload, pVariant->i64Key);
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_DOUBLE || pVariant->nType == TSDB_DATA_TYPE_FLOAT) {
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_BOOL || IS_SIGNED_NUMERIC_TYPE(pVariant->nType) || IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) {
|
||||
SET_DOUBLE_VAL(payload, pVariant->i64);
|
||||
} else if (IS_FLOAT_TYPE(pVariant->nType)) {
|
||||
SET_DOUBLE_VAL(payload, pVariant->dKey);
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_NULL) {
|
||||
*((int64_t *)payload) = TSDB_DATA_DOUBLE_NULL;
|
||||
|
@ -755,9 +706,10 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
|
|||
}
|
||||
|
||||
double dv = GET_DOUBLE_VAL(payload);
|
||||
if (isinf(dv) || isnan(dv) || dv > DBL_MAX || dv < -DBL_MAX) {
|
||||
if (errno == ERANGE || isinf(dv) || isnan(dv)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -794,7 +746,7 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
|
|||
if (pVariant->nType == TSDB_DATA_TYPE_NULL) {
|
||||
*((int64_t *)payload) = TSDB_DATA_BIGINT_NULL;
|
||||
} else {
|
||||
*((int64_t *)payload) = pVariant->i64Key;
|
||||
*((int64_t *)payload) = pVariant->i64;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -805,7 +757,9 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
|
|||
*(uint32_t *)payload = TSDB_DATA_NCHAR_NULL;
|
||||
} else {
|
||||
if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) {
|
||||
toNchar(pVariant, &payload, &newlen);
|
||||
if (toNchar(pVariant, &payload, &newlen) != 0) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
wcsncpy((wchar_t *)payload, pVariant->wpz, pVariant->nLen);
|
||||
}
|
||||
|
@ -817,7 +771,9 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu
|
|||
char *p = varDataVal(payload);
|
||||
|
||||
if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) {
|
||||
toNchar(pVariant, &p, &newlen);
|
||||
if (toNchar(pVariant, &p, &newlen) != 0) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
wcsncpy((wchar_t *)p, pVariant->wpz, pVariant->nLen);
|
||||
newlen = pVariant->nLen;
|
||||
|
@ -848,7 +804,7 @@ int32_t tVariantTypeSetType(tVariant *pVariant, char type) {
|
|||
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL: { // bool
|
||||
if (convertToBool(pVariant, &pVariant->i64Key) < 0) {
|
||||
if (convertToBool(pVariant, &pVariant->i64) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -859,7 +815,7 @@ int32_t tVariantTypeSetType(tVariant *pVariant, char type) {
|
|||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
convertToInteger(pVariant, &(pVariant->i64Key), type, INT64_MIN, INT64_MAX, true);
|
||||
convertToInteger(pVariant, &(pVariant->i64), type, true, true);
|
||||
pVariant->nType = TSDB_DATA_TYPE_BIGINT;
|
||||
break;
|
||||
}
|
||||
|
@ -886,7 +842,7 @@ int32_t tVariantTypeSetType(tVariant *pVariant, char type) {
|
|||
free(pVariant->pz);
|
||||
pVariant->dKey = v;
|
||||
} else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
pVariant->dKey = (double)(pVariant->i64Key);
|
||||
pVariant->dKey = (double)(pVariant->i64);
|
||||
}
|
||||
|
||||
pVariant->nType = TSDB_DATA_TYPE_DOUBLE;
|
||||
|
@ -901,7 +857,9 @@ int32_t tVariantTypeSetType(tVariant *pVariant, char type) {
|
|||
}
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) {
|
||||
toNchar(pVariant, &pVariant->pz, &pVariant->nLen);
|
||||
if (toNchar(pVariant, &pVariant->pz, &pVariant->nLen) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
pVariant->nType = type;
|
||||
break;
|
||||
|
@ -909,6 +867,4 @@ int32_t tVariantTypeSetType(tVariant *pVariant, char type) {
|
|||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
|
||||
PROJECT(TDengine)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_LINUX_64)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_LINUX_64)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
|
|
|
@ -43,7 +43,7 @@ typedef struct {
|
|||
int32_t master;
|
||||
int32_t num; // number of continuous streams
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
char db[TSDB_DB_NAME_LEN];
|
||||
FCqWrite cqWrite;
|
||||
struct SCqObj *pHead;
|
||||
|
@ -295,6 +295,8 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) {
|
|||
|
||||
if (pObj->pStream == NULL) {
|
||||
pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, 0, pObj, NULL);
|
||||
|
||||
// TODO the pObj->pStream may be released if error happens
|
||||
if (pObj->pStream) {
|
||||
tscSetStreamDestTable(pObj->pStream, pObj->dstTable);
|
||||
pContext->num++;
|
||||
|
@ -306,11 +308,14 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) {
|
|||
}
|
||||
|
||||
static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
|
||||
SCqObj *pObj = (SCqObj *)param;
|
||||
SCqObj *pObj = (SCqObj *)param;
|
||||
if (tres == NULL && row == NULL) {
|
||||
taos_close_stream(pObj->pStream);
|
||||
|
||||
pObj->pStream = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
SCqContext *pContext = pObj->pContext;
|
||||
STSchema *pSchema = pObj->pSchema;
|
||||
if (pObj->pStream == NULL) return;
|
||||
|
@ -336,7 +341,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
|
|||
val = ((char*)val) - sizeof(VarDataLenT);
|
||||
} else if (c->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
char buf[TSDB_MAX_NCHAR_LEN];
|
||||
size_t len = taos_fetch_lengths(tres)[i];
|
||||
int32_t len = taos_fetch_lengths(tres)[i];
|
||||
taosMbsToUcs4(val, len, buf, sizeof(buf), &len);
|
||||
memcpy(val + sizeof(VarDataLenT), buf, len);
|
||||
varDataLen(val) = len;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
LIST(APPEND CQTEST_SRC ./cqtest.c)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
|
|
|
@ -160,7 +160,7 @@ static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) {
|
|||
syslog(LOG_INFO, "Shut down signal is %d", signum);
|
||||
syslog(LOG_INFO, "Shutting down TDengine service...");
|
||||
// clean the system.
|
||||
dInfo("shut down signal is %d, sender PID:%d", signum, sigInfo->si_pid);
|
||||
dInfo("shut down signal is %d, sender PID:%d cmdline:%s", signum, sigInfo->si_pid, taosGetCmdlineByPID(sigInfo->si_pid));
|
||||
|
||||
// protect the application from receive another signal
|
||||
struct sigaction act = {{0}};
|
||||
|
|
|
@ -202,13 +202,14 @@ static void *dnodeProcessVWriteQueue(void *wparam) {
|
|||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
taosGetQitem(pWorker->qall, &qtype, (void **)&pWrite);
|
||||
dTrace("msg:%p, app:%p type:%s will be processed in vwrite queue, qtype:%s hver:%" PRIu64, pWrite,
|
||||
pWrite->rpcMsg.ahandle, taosMsg[pWrite->pHead->msgType], qtypeStr[qtype], pWrite->pHead->version);
|
||||
pWrite->rpcMsg.ahandle, taosMsg[pWrite->pHead.msgType], qtypeStr[qtype], pWrite->pHead.version);
|
||||
|
||||
pWrite->code = vnodeProcessWrite(pVnode, pWrite->pHead, qtype, &pWrite->rspRet);
|
||||
pWrite->code = vnodeProcessWrite(pVnode, &pWrite->pHead, qtype, pWrite);
|
||||
if (pWrite->code <= 0) pWrite->processedCount = 1;
|
||||
if (pWrite->code == 0 && pWrite->pHead->msgType != TSDB_MSG_TYPE_SUBMIT) forceFsync = true;
|
||||
if (pWrite->code > 0) pWrite->code = 0;
|
||||
if (pWrite->code == 0 && pWrite->pHead.msgType != TSDB_MSG_TYPE_SUBMIT) forceFsync = true;
|
||||
|
||||
dTrace("msg:%p is processed in vwrite queue, result:%s", pWrite, tstrerror(pWrite->code));
|
||||
dTrace("msg:%p is processed in vwrite queue, code:0x%x", pWrite, pWrite->code);
|
||||
}
|
||||
|
||||
walFsync(vnodeGetWal(pVnode), forceFsync);
|
||||
|
@ -221,7 +222,7 @@ static void *dnodeProcessVWriteQueue(void *wparam) {
|
|||
dnodeSendRpcVWriteRsp(pVnode, pWrite, pWrite->code);
|
||||
} else {
|
||||
if (qtype == TAOS_QTYPE_FWD) {
|
||||
vnodeConfirmForward(pVnode, pWrite->pHead->version, 0);
|
||||
vnodeConfirmForward(pVnode, pWrite->pHead.version, 0);
|
||||
}
|
||||
if (pWrite->rspRet.rsp) {
|
||||
rpcFreeCont(pWrite->rspRet.rsp);
|
||||
|
|
|
@ -42,6 +42,10 @@ typedef void **TAOS_ROW;
|
|||
#define TSDB_DATA_TYPE_BINARY 8 // string
|
||||
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_NCHAR 10 // unicode string
|
||||
#define TSDB_DATA_TYPE_UTINYINT 11 // 1 byte
|
||||
#define TSDB_DATA_TYPE_USMALLINT 12 // 2 bytes
|
||||
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
|
||||
|
||||
typedef enum {
|
||||
TSDB_OPTION_LOCALE,
|
||||
|
|
|
@ -60,7 +60,7 @@ typedef struct tstr {
|
|||
|
||||
|
||||
// Bytes for each type.
|
||||
extern const int32_t TYPE_BYTES[11];
|
||||
extern const int32_t TYPE_BYTES[15];
|
||||
|
||||
// TODO: replace and remove code below
|
||||
#define CHAR_BYTES sizeof(char)
|
||||
|
@ -92,6 +92,11 @@ extern const int32_t TYPE_BYTES[11];
|
|||
#define TSDB_DATA_NCHAR_NULL 0xFFFFFFFF
|
||||
#define TSDB_DATA_BINARY_NULL 0xFF
|
||||
|
||||
#define TSDB_DATA_UTINYINT_NULL 0xFF
|
||||
#define TSDB_DATA_USMALLINT_NULL 0xFFFF
|
||||
#define TSDB_DATA_UINT_NULL 0xFFFFFFFF
|
||||
#define TSDB_DATA_UBIGINT_NULL 0xFFFFFFFFFFFFFFFFL
|
||||
|
||||
#define TSDB_DATA_NULL_STR "NULL"
|
||||
#define TSDB_DATA_NULL_STR_L "null"
|
||||
|
||||
|
@ -131,19 +136,16 @@ do { \
|
|||
(src) = (void *)((char *)src + sizeof(type));\
|
||||
} while(0)
|
||||
|
||||
#define GET_INT8_VAL(x) (*(int8_t *)(x))
|
||||
#define GET_INT16_VAL(x) (*(int16_t *)(x))
|
||||
#define GET_INT32_VAL(x) (*(int32_t *)(x))
|
||||
#define GET_INT64_VAL(x) (*(int64_t *)(x))
|
||||
#define GET_INT8_VAL(x) (*(int8_t *)(x))
|
||||
#define GET_INT16_VAL(x) (*(int16_t *)(x))
|
||||
#define GET_INT32_VAL(x) (*(int32_t *)(x))
|
||||
#define GET_INT64_VAL(x) (*(int64_t *)(x))
|
||||
#define GET_UINT8_VAL(x) (*(uint8_t*) (x))
|
||||
#define GET_UINT16_VAL(x) (*(uint16_t *)(x))
|
||||
#define GET_UINT32_VAL(x) (*(uint32_t *)(x))
|
||||
#define GET_UINT64_VAL(x) (*(uint64_t *)(x))
|
||||
|
||||
#ifdef _TD_ARM_32
|
||||
|
||||
//#define __float_align_declear() float __underlyFloat = 0.0;
|
||||
//#define __float_align_declear()
|
||||
//#define GET_FLOAT_VAL_ALIGN(x) (*(int32_t*)&(__underlyFloat) = *(int32_t*)(x); __underlyFloat);
|
||||
// notes: src must be float or double type variable !!!
|
||||
//#define SET_FLOAT_VAL_ALIGN(dst, src) (*(int32_t*) dst = *(int32_t*)src);
|
||||
//#define SET_DOUBLE_VAL_ALIGN(dst, src) (*(int64_t*) dst = *(int64_t*)src);
|
||||
|
||||
float taos_align_get_float(const char* pBuf);
|
||||
double taos_align_get_double(const char* pBuf);
|
||||
|
||||
|
@ -171,14 +173,14 @@ typedef struct tDataTypeDescriptor {
|
|||
char algorithm, char *const buffer, int bufferSize);
|
||||
int (*decompFunc)(const char *const input, int compressedSize, const int nelements, char *const output,
|
||||
int outputSize, char algorithm, char *const buffer, int bufferSize);
|
||||
void (*getStatisFunc)(const TSKEY *primaryKey, const void *pData, int32_t numofrow, int64_t *min, int64_t *max,
|
||||
int64_t *sum, int16_t *minindex, int16_t *maxindex, int16_t *numofnull);
|
||||
void (*getStatisFunc)(const void *pData, int32_t numofrow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minindex, int16_t *maxindex, int16_t *numofnull);
|
||||
} tDataTypeDescriptor;
|
||||
|
||||
extern tDataTypeDescriptor tDataTypeDesc[11];
|
||||
extern tDataTypeDescriptor tDataTypeDesc[15];
|
||||
|
||||
bool isValidDataType(int32_t type);
|
||||
//bool isNull(const char *val, int32_t type);
|
||||
|
||||
static FORCE_INLINE bool isNull(const char *val, int32_t type) {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
|
@ -200,6 +202,15 @@ static FORCE_INLINE bool isNull(const char *val, int32_t type) {
|
|||
return varDataLen(val) == sizeof(int32_t) && *(uint32_t*) varDataVal(val) == TSDB_DATA_NCHAR_NULL;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
return varDataLen(val) == sizeof(int8_t) && *(uint8_t *) varDataVal(val) == TSDB_DATA_BINARY_NULL;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
return *(uint8_t*) val == TSDB_DATA_UTINYINT_NULL;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
return *(uint16_t*) val == TSDB_DATA_USMALLINT_NULL;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
return *(uint32_t*) val == TSDB_DATA_UINT_NULL;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
return *(uint64_t*) val == TSDB_DATA_UBIGINT_NULL;
|
||||
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
|
@ -213,6 +224,10 @@ void* getNullValue(int32_t type);
|
|||
void assignVal(char *val, const char *src, int32_t len, int32_t type);
|
||||
void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf);
|
||||
|
||||
int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bool issigned);
|
||||
|
||||
#define SET_DOUBLE_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_DOUBLE_NULL)
|
||||
|
||||
// TODO: check if below is necessary
|
||||
#define TSDB_RELATION_INVALID 0
|
||||
#define TSDB_RELATION_LESS 1
|
||||
|
@ -241,10 +256,8 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
#define TSDB_USER_LEN TSDB_UNI_LEN
|
||||
|
||||
// ACCOUNT is a 32 bit positive integer
|
||||
// this is the length of its string representation
|
||||
// including the terminator zero
|
||||
#define TSDB_ACCT_LEN 11
|
||||
#define TSDB_PASSWORD_LEN TSDB_UNI_LEN
|
||||
// this is the length of its string representation, including the terminator zero
|
||||
#define TSDB_ACCT_ID_LEN 11
|
||||
|
||||
#define TSDB_MAX_COLUMNS 1024
|
||||
#define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns
|
||||
|
@ -252,7 +265,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
#define TSDB_NODE_NAME_LEN 64
|
||||
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_DB_NAME_LEN 33
|
||||
#define TSDB_TABLE_FNAME_LEN (TSDB_ACCT_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN)
|
||||
#define TSDB_TABLE_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN)
|
||||
#define TSDB_COL_NAME_LEN 65
|
||||
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64
|
||||
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
|
||||
|
@ -278,11 +291,6 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
#define TSDB_EP_LEN (TSDB_FQDN_LEN+6)
|
||||
#define TSDB_IPv4ADDR_LEN 16
|
||||
#define TSDB_FILENAME_LEN 128
|
||||
#define TSDB_METER_VNODE_BITS 20
|
||||
#define TSDB_METER_SID_MASK 0xFFFFF
|
||||
#define TSDB_SHELL_VNODE_BITS 24
|
||||
#define TSDB_SHELL_SID_MASK 0xFF
|
||||
#define TSDB_HTTP_TOKEN_LEN 20
|
||||
#define TSDB_SHOW_SQL_LEN 512
|
||||
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
||||
|
||||
|
@ -296,9 +304,6 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
#define TSDB_MQTT_TOPIC_LEN 64
|
||||
#define TSDB_MQTT_CLIENT_ID_LEN 32
|
||||
|
||||
#define TSDB_METER_STATE_OFFLINE 0
|
||||
#define TSDB_METER_STATE_ONLLINE 1
|
||||
|
||||
#define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE
|
||||
|
||||
#define TSDB_PAYLOAD_SIZE TSDB_DEFAULT_PKT_SIZE
|
||||
|
@ -318,7 +323,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
|
||||
#define TSDB_TBNAME_COLUMN_INDEX (-1)
|
||||
#define TSDB_UD_COLUMN_INDEX (-100)
|
||||
#define TSDB_MULTI_METERMETA_MAX_NUM 100000 // maximum batch size allowed to load metermeta
|
||||
#define TSDB_MULTI_TABLEMETA_MAX_NUM 100000 // maximum batch size allowed to load table meta
|
||||
|
||||
#define TSDB_MIN_CACHE_BLOCK_SIZE 1
|
||||
#define TSDB_MAX_CACHE_BLOCK_SIZE 128 // 128MB for each vnode
|
||||
|
@ -380,6 +385,9 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
#define TSDB_MIN_DB_REPLICA_OPTION 1
|
||||
#define TSDB_MAX_DB_REPLICA_OPTION 3
|
||||
#define TSDB_DEFAULT_DB_REPLICA_OPTION 1
|
||||
|
||||
#define TSDB_MIN_DB_QUORUM_OPTION 1
|
||||
#define TSDB_MAX_DB_QUORUM_OPTION 2
|
||||
#define TSDB_DEFAULT_DB_QUORUM_OPTION 1
|
||||
|
||||
#define TSDB_MAX_JOIN_TABLE_NUM 5
|
||||
|
@ -436,7 +444,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
#define TSDB_PORT_HTTP 11
|
||||
#define TSDB_PORT_ARBITRATOR 12
|
||||
|
||||
#define TSDB_MAX_WAL_SIZE (1024*1024*2)
|
||||
#define TSDB_MAX_WAL_SIZE (1024*1024*3)
|
||||
|
||||
typedef enum {
|
||||
TAOS_QTYPE_RPC = 0,
|
||||
|
|
|
@ -180,6 +180,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_NOT_EXIST, 0, 0x036A, "Tag does n
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_ALREAY_EXIST, 0, 0x036B, "Field already exists")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_NOT_EXIST, 0, 0x036C, "Field does not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STABLE_NAME, 0, 0x036D, "Super table does not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG, 0, 0x036E, "Invalid create table message")
|
||||
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_NOT_SELECTED, 0, 0x0380, "Database not specified or available")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_ALREADY_EXIST, 0, 0x0381, "Database already exists")
|
||||
|
|
|
@ -268,7 +268,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t len; // one create table message
|
||||
char tableId[TSDB_TABLE_FNAME_LEN];
|
||||
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int8_t igExists;
|
||||
int8_t getMeta;
|
||||
int16_t numOfTags;
|
||||
|
@ -290,7 +290,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char tableId[TSDB_TABLE_FNAME_LEN];
|
||||
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int16_t type; /* operation type */
|
||||
int16_t numOfCols; /* number of schema */
|
||||
int32_t tagValLen;
|
||||
|
@ -322,7 +322,7 @@ typedef struct {
|
|||
} SConnectMsg;
|
||||
|
||||
typedef struct {
|
||||
char acctId[TSDB_ACCT_LEN];
|
||||
char acctId[TSDB_ACCT_ID_LEN];
|
||||
char serverVersion[TSDB_VERSION_LEN];
|
||||
char clusterId[TSDB_CLUSTER_ID_LEN];
|
||||
int8_t writeAuth;
|
||||
|
@ -534,7 +534,7 @@ typedef struct {
|
|||
} SVnodeLoad;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int32_t cacheBlockSize; //MB
|
||||
int32_t totalBlocks;
|
||||
int32_t maxTables;
|
||||
|
@ -682,7 +682,7 @@ typedef struct {
|
|||
} SVnodeDesc;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
SVnodeCfg cfg;
|
||||
SVnodeDesc nodes[TSDB_MAX_REPLICA];
|
||||
} SCreateVnodeMsg, SAlterVnodeMsg;
|
||||
|
@ -761,7 +761,7 @@ typedef struct {
|
|||
*/
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
uint16_t payloadLen;
|
||||
char payload[];
|
||||
} SShowMsg;
|
||||
|
|
|
@ -26,7 +26,7 @@ typedef int32_t (*FCqWrite)(int32_t vgId, void *pHead, int32_t qtype, void *pMsg
|
|||
typedef struct {
|
||||
int32_t vgId;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
char db[TSDB_DB_NAME_LEN];
|
||||
FCqWrite cqWrite;
|
||||
} SCqCfg;
|
||||
|
|
|
@ -117,112 +117,114 @@
|
|||
#define TK_CACHELAST 99
|
||||
#define TK_LP 100
|
||||
#define TK_RP 101
|
||||
#define TK_TAGS 102
|
||||
#define TK_USING 103
|
||||
#define TK_AS 104
|
||||
#define TK_COMMA 105
|
||||
#define TK_NULL 106
|
||||
#define TK_SELECT 107
|
||||
#define TK_UNION 108
|
||||
#define TK_ALL 109
|
||||
#define TK_FROM 110
|
||||
#define TK_VARIABLE 111
|
||||
#define TK_INTERVAL 112
|
||||
#define TK_FILL 113
|
||||
#define TK_SLIDING 114
|
||||
#define TK_ORDER 115
|
||||
#define TK_BY 116
|
||||
#define TK_ASC 117
|
||||
#define TK_DESC 118
|
||||
#define TK_GROUP 119
|
||||
#define TK_HAVING 120
|
||||
#define TK_LIMIT 121
|
||||
#define TK_OFFSET 122
|
||||
#define TK_SLIMIT 123
|
||||
#define TK_SOFFSET 124
|
||||
#define TK_WHERE 125
|
||||
#define TK_NOW 126
|
||||
#define TK_RESET 127
|
||||
#define TK_QUERY 128
|
||||
#define TK_ADD 129
|
||||
#define TK_COLUMN 130
|
||||
#define TK_TAG 131
|
||||
#define TK_CHANGE 132
|
||||
#define TK_SET 133
|
||||
#define TK_KILL 134
|
||||
#define TK_CONNECTION 135
|
||||
#define TK_STREAM 136
|
||||
#define TK_COLON 137
|
||||
#define TK_ABORT 138
|
||||
#define TK_AFTER 139
|
||||
#define TK_ATTACH 140
|
||||
#define TK_BEFORE 141
|
||||
#define TK_BEGIN 142
|
||||
#define TK_CASCADE 143
|
||||
#define TK_CLUSTER 144
|
||||
#define TK_CONFLICT 145
|
||||
#define TK_COPY 146
|
||||
#define TK_DEFERRED 147
|
||||
#define TK_DELIMITERS 148
|
||||
#define TK_DETACH 149
|
||||
#define TK_EACH 150
|
||||
#define TK_END 151
|
||||
#define TK_EXPLAIN 152
|
||||
#define TK_FAIL 153
|
||||
#define TK_FOR 154
|
||||
#define TK_IGNORE 155
|
||||
#define TK_IMMEDIATE 156
|
||||
#define TK_INITIALLY 157
|
||||
#define TK_INSTEAD 158
|
||||
#define TK_MATCH 159
|
||||
#define TK_KEY 160
|
||||
#define TK_OF 161
|
||||
#define TK_RAISE 162
|
||||
#define TK_REPLACE 163
|
||||
#define TK_RESTRICT 164
|
||||
#define TK_ROW 165
|
||||
#define TK_STATEMENT 166
|
||||
#define TK_TRIGGER 167
|
||||
#define TK_VIEW 168
|
||||
#define TK_COUNT 169
|
||||
#define TK_SUM 170
|
||||
#define TK_AVG 171
|
||||
#define TK_MIN 172
|
||||
#define TK_MAX 173
|
||||
#define TK_FIRST 174
|
||||
#define TK_LAST 175
|
||||
#define TK_TOP 176
|
||||
#define TK_BOTTOM 177
|
||||
#define TK_STDDEV 178
|
||||
#define TK_PERCENTILE 179
|
||||
#define TK_APERCENTILE 180
|
||||
#define TK_LEASTSQUARES 181
|
||||
#define TK_HISTOGRAM 182
|
||||
#define TK_DIFF 183
|
||||
#define TK_SPREAD 184
|
||||
#define TK_TWA 185
|
||||
#define TK_INTERP 186
|
||||
#define TK_LAST_ROW 187
|
||||
#define TK_RATE 188
|
||||
#define TK_IRATE 189
|
||||
#define TK_SUM_RATE 190
|
||||
#define TK_SUM_IRATE 191
|
||||
#define TK_AVG_RATE 192
|
||||
#define TK_AVG_IRATE 193
|
||||
#define TK_TBID 194
|
||||
#define TK_SEMI 195
|
||||
#define TK_NONE 196
|
||||
#define TK_PREV 197
|
||||
#define TK_LINEAR 198
|
||||
#define TK_IMPORT 199
|
||||
#define TK_METRIC 200
|
||||
#define TK_TBNAME 201
|
||||
#define TK_JOIN 202
|
||||
#define TK_METRICS 203
|
||||
#define TK_STABLE 204
|
||||
#define TK_INSERT 205
|
||||
#define TK_INTO 206
|
||||
#define TK_VALUES 207
|
||||
#define TK_UNSIGNED 102
|
||||
#define TK_TAGS 103
|
||||
#define TK_USING 104
|
||||
#define TK_AS 105
|
||||
#define TK_COMMA 106
|
||||
#define TK_NULL 107
|
||||
#define TK_SELECT 108
|
||||
#define TK_UNION 109
|
||||
#define TK_ALL 110
|
||||
#define TK_FROM 111
|
||||
#define TK_VARIABLE 112
|
||||
#define TK_INTERVAL 113
|
||||
#define TK_FILL 114
|
||||
#define TK_SLIDING 115
|
||||
#define TK_ORDER 116
|
||||
#define TK_BY 117
|
||||
#define TK_ASC 118
|
||||
#define TK_DESC 119
|
||||
#define TK_GROUP 120
|
||||
#define TK_HAVING 121
|
||||
#define TK_LIMIT 122
|
||||
#define TK_OFFSET 123
|
||||
#define TK_SLIMIT 124
|
||||
#define TK_SOFFSET 125
|
||||
#define TK_WHERE 126
|
||||
#define TK_NOW 127
|
||||
#define TK_RESET 128
|
||||
#define TK_QUERY 129
|
||||
#define TK_ADD 130
|
||||
#define TK_COLUMN 131
|
||||
#define TK_TAG 132
|
||||
#define TK_CHANGE 133
|
||||
#define TK_SET 134
|
||||
#define TK_KILL 135
|
||||
#define TK_CONNECTION 136
|
||||
#define TK_STREAM 137
|
||||
#define TK_COLON 138
|
||||
#define TK_ABORT 139
|
||||
#define TK_AFTER 140
|
||||
#define TK_ATTACH 141
|
||||
#define TK_BEFORE 142
|
||||
#define TK_BEGIN 143
|
||||
#define TK_CASCADE 144
|
||||
#define TK_CLUSTER 145
|
||||
#define TK_CONFLICT 146
|
||||
#define TK_COPY 147
|
||||
#define TK_DEFERRED 148
|
||||
#define TK_DELIMITERS 149
|
||||
#define TK_DETACH 150
|
||||
#define TK_EACH 151
|
||||
#define TK_END 152
|
||||
#define TK_EXPLAIN 153
|
||||
#define TK_FAIL 154
|
||||
#define TK_FOR 155
|
||||
#define TK_IGNORE 156
|
||||
#define TK_IMMEDIATE 157
|
||||
#define TK_INITIALLY 158
|
||||
#define TK_INSTEAD 159
|
||||
#define TK_MATCH 160
|
||||
#define TK_KEY 161
|
||||
#define TK_OF 162
|
||||
#define TK_RAISE 163
|
||||
#define TK_REPLACE 164
|
||||
#define TK_RESTRICT 165
|
||||
#define TK_ROW 166
|
||||
#define TK_STATEMENT 167
|
||||
#define TK_TRIGGER 168
|
||||
#define TK_VIEW 169
|
||||
#define TK_COUNT 170
|
||||
#define TK_SUM 171
|
||||
#define TK_AVG 172
|
||||
#define TK_MIN 173
|
||||
#define TK_MAX 174
|
||||
#define TK_FIRST 175
|
||||
#define TK_LAST 176
|
||||
#define TK_TOP 177
|
||||
#define TK_BOTTOM 178
|
||||
#define TK_STDDEV 179
|
||||
#define TK_PERCENTILE 180
|
||||
#define TK_APERCENTILE 181
|
||||
#define TK_LEASTSQUARES 182
|
||||
#define TK_HISTOGRAM 183
|
||||
#define TK_DIFF 184
|
||||
#define TK_SPREAD 185
|
||||
#define TK_TWA 186
|
||||
#define TK_INTERP 187
|
||||
#define TK_LAST_ROW 188
|
||||
#define TK_RATE 189
|
||||
#define TK_IRATE 190
|
||||
#define TK_SUM_RATE 191
|
||||
#define TK_SUM_IRATE 192
|
||||
#define TK_AVG_RATE 193
|
||||
#define TK_AVG_IRATE 194
|
||||
#define TK_TBID 195
|
||||
#define TK_SEMI 196
|
||||
#define TK_NONE 197
|
||||
#define TK_PREV 198
|
||||
#define TK_LINEAR 199
|
||||
#define TK_IMPORT 200
|
||||
#define TK_METRIC 201
|
||||
#define TK_TBNAME 202
|
||||
#define TK_JOIN 203
|
||||
#define TK_METRICS 204
|
||||
#define TK_STABLE 205
|
||||
#define TK_INSERT 206
|
||||
#define TK_INTO 207
|
||||
#define TK_VALUES 208
|
||||
|
||||
|
||||
|
||||
#define TK_SPACE 300
|
||||
|
|
|
@ -8,27 +8,56 @@ extern "C" {
|
|||
#include "taosdef.h"
|
||||
|
||||
#define GET_TYPED_DATA(_v, _finalType, _type, _data) \
|
||||
switch (_type) { \
|
||||
case TSDB_DATA_TYPE_BOOL: \
|
||||
case TSDB_DATA_TYPE_TINYINT: \
|
||||
(_v) = (_finalType)GET_INT8_VAL(_data); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_SMALLINT: \
|
||||
(_v) = (_finalType)GET_INT16_VAL(_data); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_BIGINT: \
|
||||
(_v) = (_finalType)(GET_INT64_VAL(_data)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_FLOAT: \
|
||||
(_v) = (_finalType)GET_FLOAT_VAL(_data); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_DOUBLE: \
|
||||
(_v) = (_finalType)GET_DOUBLE_VAL(_data); \
|
||||
break; \
|
||||
default: \
|
||||
(_v) = (_finalType)GET_INT32_VAL(_data); \
|
||||
break; \
|
||||
}
|
||||
do { \
|
||||
switch (_type) { \
|
||||
case TSDB_DATA_TYPE_BOOL: \
|
||||
case TSDB_DATA_TYPE_TINYINT: \
|
||||
(_v) = (_finalType)GET_INT8_VAL(_data); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_UTINYINT: \
|
||||
(_v) = (_finalType)GET_UINT8_VAL(_data); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_SMALLINT: \
|
||||
(_v) = (_finalType)GET_INT16_VAL(_data); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_USMALLINT: \
|
||||
(_v) = (_finalType)GET_UINT16_VAL(_data); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_BIGINT: \
|
||||
(_v) = (_finalType)(GET_INT64_VAL(_data)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_UBIGINT: \
|
||||
(_v) = (_finalType)(GET_UINT64_VAL(_data)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_FLOAT: \
|
||||
(_v) = (_finalType)GET_FLOAT_VAL(_data); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_DOUBLE: \
|
||||
(_v) = (_finalType)GET_DOUBLE_VAL(_data); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_UINT: \
|
||||
(_v) = (_finalType)GET_UINT32_VAL(_data); \
|
||||
break; \
|
||||
default: \
|
||||
(_v) = (_finalType)GET_INT32_VAL(_data); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT)
|
||||
#define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT)
|
||||
#define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE)
|
||||
|
||||
#define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t)))
|
||||
|
||||
#define IS_VALID_TINYINT(_t) ((_t) > INT8_MIN && (_t) <= INT8_MAX)
|
||||
#define IS_VALID_SMALLINT(_t) ((_t) > INT16_MIN && (_t) <= INT16_MAX)
|
||||
#define IS_VALID_INT(_t) ((_t) > INT32_MIN && (_t) <= INT32_MAX)
|
||||
#define IS_VALID_BIGINT(_t) ((_t) > INT64_MIN && (_t) <= INT64_MAX)
|
||||
#define IS_VALID_UTINYINT(_t) ((_t) >= 0 && (_t) < UINT8_MAX)
|
||||
#define IS_VALID_USMALLINT(_t) ((_t) >= 0 && (_t) < UINT16_MAX)
|
||||
#define IS_VALID_UINT(_t) ((_t) >= 0 && (_t) < UINT32_MAX)
|
||||
#define IS_VALID_UBIGINT(_t) ((_t) >= 0 && (_t) < UINT64_MAX)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ typedef struct {
|
|||
SRpcMsg rpcMsg;
|
||||
SRspRet rspRet;
|
||||
char reserveForSync[24];
|
||||
SWalHead pHead[];
|
||||
SWalHead pHead;
|
||||
} SVWriteMsg;
|
||||
|
||||
// vnodeStatus
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
ADD_SUBDIRECTORY(shell)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
|
|
|
@ -603,15 +603,27 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le
|
|||
case TSDB_DATA_TYPE_TINYINT:
|
||||
printf("%*d", width, *((int8_t *)val));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
printf("%*u", width, *((uint8_t *)val));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
printf("%*d", width, *((int16_t *)val));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
printf("%*u", width, *((uint16_t *)val));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
printf("%*d", width, *((int32_t *)val));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
printf("%*u", width, *((uint32_t *)val));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
printf("%*" PRId64, width, *((int64_t *)val));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
printf("%*" PRIu64, width, *((uint64_t *)val));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
printf("%*.5f", width, GET_FLOAT_VAL(val));
|
||||
break;
|
||||
|
@ -679,15 +691,19 @@ static int calcColWidth(TAOS_FIELD* field, int precision) {
|
|||
return MAX(5, width); // 'false'
|
||||
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
return MAX(4, width); // '-127'
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
return MAX(6, width); // '-32767'
|
||||
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
return MAX(11, width); // '-2147483648'
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
return MAX(21, width); // '-9223372036854775807'
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"port": 6030,
|
||||
"user": "root",
|
||||
"password": "taosdata",
|
||||
"thread_count": 2,
|
||||
"thread_count": 4,
|
||||
"thread_count_create_tbl": 1,
|
||||
"result_file": "./insert_res.txt",
|
||||
"databases": [{
|
||||
"dbinfo": {
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
"port": 6030,
|
||||
"user": "root",
|
||||
"password": "taosdata",
|
||||
"databases": "db01",
|
||||
"super_table_query":
|
||||
"databases": "db",
|
||||
"specified_table_query":
|
||||
{"concurrent":1, "mode":"sync", "interval":5000, "restart":"yes", "keepProgress":"yes",
|
||||
"sqls": [{"sql": "select avg(c1) from stb01 where col1 > 1;", "result": "./subscribe_res0.txt"}]
|
||||
"sqls": [{"sql": "select avg(col1) from stb01 where col1 > 1;", "result": "./subscribe_res0.txt"}]
|
||||
},
|
||||
"sub_table_query":
|
||||
{"stblname": "stb01", "threads":1, "mode":"sync", "interval":10000, "restart":"yes", "keepProgress":"yes",
|
||||
"sqls": [{"sql": "select col1 from xxxx where col1 > 10;", "result": "./subscribe_res1.txt"}]
|
||||
}
|
||||
"super_table_query":
|
||||
{"stblname": "stb", "threads":1, "mode":"sync", "interval":10000, "restart":"yes", "keepProgress":"yes",
|
||||
"sqls": [{"sql": "select col1 from xxxx where col1 > 10;", "result": "./subscribe_res1.txt"}]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,9 +93,6 @@ extern char configDir[];
|
|||
#define MAX_QUERY_SQL_COUNT 10
|
||||
#define MAX_QUERY_SQL_LENGTH 256
|
||||
|
||||
|
||||
#define MAX_LINE_COUNT_IN_MEM 10000
|
||||
|
||||
typedef enum CREATE_SUB_TALBE_MOD_EN {
|
||||
PRE_CREATE_SUBTBL,
|
||||
AUTO_CREATE_SUBTBL,
|
||||
|
@ -259,6 +256,7 @@ typedef struct SDbs_S {
|
|||
bool queryMode;
|
||||
|
||||
int threadCount;
|
||||
int threadCountByCreateTbl;
|
||||
int dbCount;
|
||||
SDataBase db[MAX_DB_COUNT];
|
||||
|
||||
|
@ -1418,7 +1416,6 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, char* sTblName
|
|||
char command[BUFFER_SIZE] = "\0";
|
||||
TAOS_RES * res;
|
||||
TAOS_ROW row = NULL;
|
||||
int count = 0;
|
||||
|
||||
char* childTblName = *childTblNameOfSuperTbl;
|
||||
|
||||
|
@ -1433,12 +1430,13 @@ static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, char* sTblName
|
|||
exit(-1);
|
||||
}
|
||||
|
||||
int childTblCount = 10000;
|
||||
count = 0;
|
||||
int childTblCount = 10000;
|
||||
int count = 0;
|
||||
childTblName = (char*)calloc(1, childTblCount * TSDB_TABLE_NAME_LEN);
|
||||
char* pTblName = childTblName;
|
||||
while ((row = taos_fetch_row(res)) != NULL) {
|
||||
strncpy(pTblName, (char *)row[0], TSDB_TABLE_NAME_LEN);
|
||||
int32_t* len = taos_fetch_lengths(res);
|
||||
strncpy(pTblName, (char *)row[0], len[0]);
|
||||
//printf("==== sub table name: %s\n", pTblName);
|
||||
count++;
|
||||
if (count >= childTblCount - 1) {
|
||||
|
@ -1829,38 +1827,64 @@ static void createChildTables() {
|
|||
if ((AUTO_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) || (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists)) {
|
||||
continue;
|
||||
}
|
||||
startMultiThreadCreateChildTable(g_Dbs.db[i].superTbls[j].colsOfCreatChildTable, g_Dbs.threadCount, g_Dbs.db[i].superTbls[j].childTblCount, g_Dbs.db[i].dbName, &(g_Dbs.db[i].superTbls[j]));
|
||||
startMultiThreadCreateChildTable(g_Dbs.db[i].superTbls[j].colsOfCreatChildTable, g_Dbs.threadCountByCreateTbl, g_Dbs.db[i].superTbls[j].childTblCount, g_Dbs.db[i].dbName, &(g_Dbs.db[i].superTbls[j]));
|
||||
g_totalChildTables += g_Dbs.db[i].superTbls[j].childTblCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
static int taosGetLineNum(const char *fileName)
|
||||
{
|
||||
int lineNum = 0;
|
||||
char cmd[1024] = { 0 };
|
||||
char buf[1024] = { 0 };
|
||||
sprintf(cmd, "wc -l %s", fileName);
|
||||
|
||||
FILE *fp = popen(cmd, "r");
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "ERROR: failed to execute:%s, error:%s\n", cmd, strerror(errno));
|
||||
return lineNum;
|
||||
}
|
||||
|
||||
if (fgets(buf, sizeof(buf), fp)) {
|
||||
int index = strchr((const char*)buf, ' ') - buf;
|
||||
buf[index] = '\0';
|
||||
lineNum = atoi(buf);
|
||||
}
|
||||
pclose(fp);
|
||||
return lineNum;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
Read 10000 lines at most. If more than 10000 lines, continue to read after using
|
||||
*/
|
||||
int readTagFromCsvFileToMem(SSuperTable * supterTblInfo) {
|
||||
int readTagFromCsvFileToMem(SSuperTable * superTblInfo) {
|
||||
size_t n = 0;
|
||||
ssize_t readLen = 0;
|
||||
char * line = NULL;
|
||||
|
||||
FILE *fp = fopen(supterTblInfo->tagsFile, "r");
|
||||
FILE *fp = fopen(superTblInfo->tagsFile, "r");
|
||||
if (fp == NULL) {
|
||||
printf("Failed to open tags file: %s, reason:%s\n", supterTblInfo->tagsFile, strerror(errno));
|
||||
printf("Failed to open tags file: %s, reason:%s\n", superTblInfo->tagsFile, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (supterTblInfo->tagDataBuf) {
|
||||
free(supterTblInfo->tagDataBuf);
|
||||
supterTblInfo->tagDataBuf = NULL;
|
||||
if (superTblInfo->tagDataBuf) {
|
||||
free(superTblInfo->tagDataBuf);
|
||||
superTblInfo->tagDataBuf = NULL;
|
||||
}
|
||||
|
||||
supterTblInfo->tagDataBuf = calloc(supterTblInfo->lenOfTagOfOneRow * MAX_LINE_COUNT_IN_MEM, 1);
|
||||
if (supterTblInfo->tagDataBuf == NULL) {
|
||||
|
||||
int tagCount = 10000;
|
||||
int count = 0;
|
||||
char* tagDataBuf = calloc(1, superTblInfo->lenOfTagOfOneRow * tagCount);
|
||||
if (tagDataBuf == NULL) {
|
||||
printf("Failed to calloc, reason:%s\n", strerror(errno));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
while ((readLen = getline(&line, &n, fp)) != -1) {
|
||||
if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) {
|
||||
line[--readLen] = 0;
|
||||
|
@ -1870,20 +1894,35 @@ int readTagFromCsvFileToMem(SSuperTable * supterTblInfo) {
|
|||
continue;
|
||||
}
|
||||
|
||||
memcpy(supterTblInfo->tagDataBuf + supterTblInfo->tagSampleCount * supterTblInfo->lenOfTagOfOneRow, line, readLen);
|
||||
supterTblInfo->tagSampleCount++;
|
||||
memcpy(tagDataBuf + count * superTblInfo->lenOfTagOfOneRow, line, readLen);
|
||||
count++;
|
||||
|
||||
if (supterTblInfo->tagSampleCount >= MAX_LINE_COUNT_IN_MEM) {
|
||||
break;
|
||||
if (count >= tagCount - 1) {
|
||||
char *tmp = realloc(tagDataBuf, (size_t)tagCount*1.5*superTblInfo->lenOfTagOfOneRow);
|
||||
if (tmp != NULL) {
|
||||
tagDataBuf = tmp;
|
||||
tagCount = (int)(tagCount*1.5);
|
||||
memset(tagDataBuf + count*superTblInfo->lenOfTagOfOneRow, 0, (size_t)((tagCount-count)*superTblInfo->lenOfTagOfOneRow));
|
||||
} else {
|
||||
// exit, if allocate more memory failed
|
||||
printf("realloc fail for save tag val from %s\n", superTblInfo->tagsFile);
|
||||
tmfree(tagDataBuf);
|
||||
free(line);
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
superTblInfo->tagDataBuf = tagDataBuf;
|
||||
superTblInfo->tagSampleCount = count;
|
||||
|
||||
free(line);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int readSampleFromJsonFileToMem(SSuperTable * supterTblInfo) {
|
||||
int readSampleFromJsonFileToMem(SSuperTable * superTblInfo) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
@ -2138,6 +2177,16 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
|
|||
printf("failed to read json, threads not found");
|
||||
goto PARSE_OVER;
|
||||
}
|
||||
|
||||
cJSON* threads2 = cJSON_GetObjectItem(root, "thread_count_create_tbl");
|
||||
if (threads2 && threads2->type == cJSON_Number) {
|
||||
g_Dbs.threadCountByCreateTbl = threads2->valueint;
|
||||
} else if (!threads2) {
|
||||
g_Dbs.threadCountByCreateTbl = 1;
|
||||
} else {
|
||||
printf("failed to read json, threads2 not found");
|
||||
goto PARSE_OVER;
|
||||
}
|
||||
|
||||
cJSON* dbs = cJSON_GetObjectItem(root, "databases");
|
||||
if (!dbs || dbs->type != cJSON_Array) {
|
||||
|
@ -3008,6 +3057,10 @@ void postFreeResource() {
|
|||
free(g_Dbs.db[i].superTbls[j].sampleDataBuf);
|
||||
g_Dbs.db[i].superTbls[j].sampleDataBuf = NULL;
|
||||
}
|
||||
if (0 != g_Dbs.db[i].superTbls[j].tagDataBuf) {
|
||||
free(g_Dbs.db[i].superTbls[j].tagDataBuf);
|
||||
g_Dbs.db[i].superTbls[j].tagDataBuf = NULL;
|
||||
}
|
||||
if (0 != g_Dbs.db[i].superTbls[j].childTblName) {
|
||||
free(g_Dbs.db[i].superTbls[j].childTblName);
|
||||
g_Dbs.db[i].superTbls[j].childTblName = NULL;
|
||||
|
@ -4216,23 +4269,24 @@ void *subSubscribeProcess(void *sarg) {
|
|||
} while (0);
|
||||
|
||||
// start loop to consume result
|
||||
TAOS_RES* res = NULL;
|
||||
while (1) {
|
||||
for (int i = 0; i < g_queryInfo.subQueryInfo.sqlCount; i++) {
|
||||
if (1 == g_queryInfo.subQueryInfo.subscribeMode) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TAOS_RES* res = taos_consume(g_queryInfo.subQueryInfo.tsub[i]);
|
||||
res = taos_consume(g_queryInfo.subQueryInfo.tsub[i]);
|
||||
if (res) {
|
||||
char tmpFile[MAX_FILE_NAME_LEN*2] = {0};
|
||||
if (g_queryInfo.subQueryInfo.result[i][0] != 0) {
|
||||
sprintf(tmpFile, "%s-%d", g_queryInfo.subQueryInfo.result[i], winfo->threadID);
|
||||
}
|
||||
getResult(res, tmpFile);
|
||||
taos_free_result(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
for (int i = 0; i < g_queryInfo.subQueryInfo.sqlCount; i++) {
|
||||
taos_unsubscribe(g_queryInfo.subQueryInfo.tsub[i], g_queryInfo.subQueryInfo.subscribeKeepProgress);
|
||||
|
@ -4275,23 +4329,24 @@ void *superSubscribeProcess(void *sarg) {
|
|||
} while (0);
|
||||
|
||||
// start loop to consume result
|
||||
TAOS_RES* res = NULL;
|
||||
while (1) {
|
||||
for (int i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) {
|
||||
if (1 == g_queryInfo.superQueryInfo.subscribeMode) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TAOS_RES* res = taos_consume(g_queryInfo.superQueryInfo.tsub[i]);
|
||||
res = taos_consume(g_queryInfo.superQueryInfo.tsub[i]);
|
||||
if (res) {
|
||||
char tmpFile[MAX_FILE_NAME_LEN*2] = {0};
|
||||
if (g_queryInfo.superQueryInfo.result[i][0] != 0) {
|
||||
sprintf(tmpFile, "%s-%d", g_queryInfo.superQueryInfo.result[i], winfo->threadID);
|
||||
}
|
||||
getResult(res, tmpFile);
|
||||
taos_free_result(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
for (int i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) {
|
||||
taos_unsubscribe(g_queryInfo.superQueryInfo.tsub[i], g_queryInfo.superQueryInfo.subscribeKeepProgress);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_LINUX)
|
||||
|
|
|
@ -138,7 +138,7 @@ typedef struct SVgObj {
|
|||
int64_t createdTime;
|
||||
int32_t lbDnodeId;
|
||||
int32_t lbTime;
|
||||
char dbName[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||
char dbName[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int8_t inUse;
|
||||
int8_t accessState;
|
||||
int8_t status;
|
||||
|
@ -179,7 +179,7 @@ typedef struct {
|
|||
} SDbCfg;
|
||||
|
||||
typedef struct SDbObj {
|
||||
char name[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||
char name[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int8_t reserved0[4];
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
|
@ -259,7 +259,7 @@ typedef struct {
|
|||
int16_t bytes[TSDB_MAX_COLUMNS];
|
||||
int32_t numOfReads;
|
||||
int8_t maxReplica;
|
||||
int8_t reserved0[0];
|
||||
int8_t reserved0[1];
|
||||
uint16_t payloadLen;
|
||||
char payload[];
|
||||
} SShowObj;
|
||||
|
|
|
@ -60,7 +60,7 @@ typedef struct SSdbRow {
|
|||
int32_t (*fpReq)(SMnodeMsg *pMsg);
|
||||
int32_t (*fpRsp)(SMnodeMsg *pMsg, int32_t code);
|
||||
char reserveForSync[24];
|
||||
SWalHead pHead[];
|
||||
SWalHead pHead;
|
||||
} SSdbRow;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -316,9 +316,14 @@ static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) {
|
|||
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
}
|
||||
|
||||
if (pCfg->quorum < TSDB_MIN_DB_REPLICA_OPTION || pCfg->quorum > TSDB_MAX_DB_REPLICA_OPTION) {
|
||||
mError("invalid db option quorum:%d valid range: [%d, %d]", pCfg->quorum, TSDB_MIN_DB_REPLICA_OPTION,
|
||||
TSDB_MAX_DB_REPLICA_OPTION);
|
||||
if (pCfg->quorum > pCfg->replications) {
|
||||
mError("invalid db option quorum:%d larger than replica:%d", pCfg->quorum, pCfg->replications);
|
||||
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
}
|
||||
|
||||
if (pCfg->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCfg->quorum > TSDB_MAX_DB_QUORUM_OPTION) {
|
||||
mError("invalid db option quorum:%d valid range: [%d, %d]", pCfg->quorum, TSDB_MIN_DB_QUORUM_OPTION,
|
||||
TSDB_MAX_DB_QUORUM_OPTION);
|
||||
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
}
|
||||
|
||||
|
|
|
@ -810,6 +810,10 @@ static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
|
|||
}
|
||||
|
||||
pShow->numOfRows = mnodeGetDnodesNum();
|
||||
if (tsArbitrator[0] != 0) {
|
||||
pShow->numOfRows++;
|
||||
}
|
||||
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
pShow->pIter = NULL;
|
||||
|
||||
|
@ -821,7 +825,7 @@ static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
|
|||
static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
|
||||
int32_t numOfRows = 0;
|
||||
int32_t cols = 0;
|
||||
SDnodeObj *pDnode = NULL;
|
||||
SDnodeObj *pDnode = NULL;
|
||||
char *pWrite;
|
||||
|
||||
while (numOfRows < rows) {
|
||||
|
@ -864,10 +868,49 @@ static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, vo
|
|||
STR_TO_VARSTR(pWrite, offlineReason[pDnode->offlineReason]);
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
numOfRows++;
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
}
|
||||
|
||||
if (tsArbitrator[0] != 0) {
|
||||
cols = 0;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int16_t *)pWrite = 0;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tsArbitrator, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int16_t *)pWrite = 0;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int16_t *)pWrite = 0;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
char *status = dnodeStatus[tsArbOnline > 0 ? TAOS_DN_STATUS_READY : TAOS_DN_STATUS_OFFLINE];
|
||||
STR_TO_VARSTR(pWrite, status);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_TO_VARSTR(pWrite, "arb");
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = 0;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_TO_VARSTR(pWrite, "-");
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
|
|
|
@ -274,7 +274,7 @@ static int32_t sdbGetSyncVersion(int32_t vgId, uint64_t *fver, uint64_t *vver) {
|
|||
|
||||
// failed to forward, need revert insert
|
||||
static void sdbHandleFailedConfirm(SSdbRow *pRow) {
|
||||
SWalHead *pHead = pRow->pHead;
|
||||
SWalHead *pHead = &pRow->pHead;
|
||||
int32_t action = pHead->msgType % 10;
|
||||
|
||||
sdbError("vgId:1, row:%p:%s hver:%" PRIu64 " action:%s, failed to foward since %s", pRow->pObj,
|
||||
|
@ -1012,7 +1012,7 @@ static void sdbFreeQueue() {
|
|||
}
|
||||
|
||||
static int32_t sdbWriteToQueue(SSdbRow *pRow, int32_t qtype) {
|
||||
SWalHead *pHead = pRow->pHead;
|
||||
SWalHead *pHead = &pRow->pHead;
|
||||
|
||||
if (pHead->len > TSDB_MAX_WAL_SIZE) {
|
||||
sdbError("vgId:1, wal len:%d exceeds limit, hver:%" PRIu64, pHead->len, pHead->version);
|
||||
|
@ -1051,8 +1051,8 @@ static int32_t sdbWriteFwdToQueue(int32_t vgId, void *wparam, int32_t qtype, voi
|
|||
return TSDB_CODE_VND_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
memcpy(pRow->pHead, pHead, sizeof(SWalHead) + pHead->len);
|
||||
pRow->rowData = pRow->pHead->cont;
|
||||
memcpy(&pRow->pHead, pHead, sizeof(SWalHead) + pHead->len);
|
||||
pRow->rowData = pRow->pHead.cont;
|
||||
|
||||
int32_t code = sdbWriteToQueue(pRow, qtype);
|
||||
if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) code = 0;
|
||||
|
@ -1073,7 +1073,7 @@ static int32_t sdbWriteRowToQueue(SSdbRow *pInputRow, int32_t action) {
|
|||
memcpy(pRow, pInputRow, sizeof(SSdbRow));
|
||||
pRow->processedCount = 1;
|
||||
|
||||
SWalHead *pHead = pRow->pHead;
|
||||
SWalHead *pHead = &pRow->pHead;
|
||||
pRow->rowData = pHead->cont;
|
||||
(*pTable->fpEncode)(pRow);
|
||||
|
||||
|
@ -1103,9 +1103,9 @@ static void *sdbWorkerFp(void *pWorker) {
|
|||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
taosGetQitem(tsSdbWQall, &qtype, (void **)&pRow);
|
||||
sdbTrace("vgId:1, msg:%p, row:%p hver:%" PRIu64 ", will be processed in sdb queue", pRow->pMsg, pRow->pObj,
|
||||
pRow->pHead->version);
|
||||
pRow->pHead.version);
|
||||
|
||||
pRow->code = sdbProcessWrite((qtype == TAOS_QTYPE_RPC) ? pRow : NULL, pRow->pHead, qtype, NULL);
|
||||
pRow->code = sdbProcessWrite((qtype == TAOS_QTYPE_RPC) ? pRow : NULL, &pRow->pHead, qtype, NULL);
|
||||
if (pRow->code > 0) pRow->code = 0;
|
||||
|
||||
sdbTrace("vgId:1, msg:%p is processed in sdb queue, code:%x", pRow->pMsg, pRow->code);
|
||||
|
@ -1122,7 +1122,7 @@ static void *sdbWorkerFp(void *pWorker) {
|
|||
sdbConfirmForward(1, pRow, pRow->code);
|
||||
} else {
|
||||
if (qtype == TAOS_QTYPE_FWD) {
|
||||
syncConfirmForward(tsSdbMgmt.sync, pRow->pHead->version, pRow->code);
|
||||
syncConfirmForward(tsSdbMgmt.sync, pRow->pHead.version, pRow->code);
|
||||
}
|
||||
sdbFreeFromQueue(pRow);
|
||||
}
|
||||
|
|
|
@ -35,12 +35,9 @@
|
|||
#include "mnodeAcct.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeProfile.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeTable.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeVgroup.h"
|
||||
#include "mnodeWrite.h"
|
||||
#include "mnodeRead.h"
|
||||
|
@ -1003,7 +1000,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
SCMCreateTableMsg *pCreate1 = pMsg->rpcMsg.pCont;
|
||||
if (pCreate1->numOfTables == 0) {
|
||||
// todo return to error message
|
||||
return TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG;
|
||||
}
|
||||
|
||||
SCreateTableMsg* pCreate = (SCreateTableMsg*)((char*)pCreate1 + sizeof(SCMCreateTableMsg));
|
||||
|
@ -1032,16 +1029,39 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
|
|||
mError("msg:%p, app:%p table:%s, failed to create, no schema input", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableId);
|
||||
return TSDB_CODE_MND_INVALID_TABLE_NAME;
|
||||
}
|
||||
|
||||
memcpy(pStable->schema, pCreate->schema, numOfCols * sizeof(SSchema));
|
||||
|
||||
if (pStable->numOfColumns > TSDB_MAX_COLUMNS || pStable->numOfTags > TSDB_MAX_TAGS) {
|
||||
mError("msg:%p, app:%p table:%s, failed to create, too many columns", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableId);
|
||||
return TSDB_CODE_MND_INVALID_TABLE_NAME;
|
||||
}
|
||||
|
||||
pStable->nextColId = 0;
|
||||
|
||||
// TODO extract method to valid the schema
|
||||
int32_t schemaLen = 0;
|
||||
int32_t tagLen = 0;
|
||||
for (int32_t col = 0; col < numOfCols; col++) {
|
||||
SSchema *tschema = pStable->schema;
|
||||
tschema[col].colId = pStable->nextColId++;
|
||||
tschema[col].bytes = htons(tschema[col].bytes);
|
||||
|
||||
// todo 1. check the length of each column; 2. check the total length of all columns
|
||||
assert(tschema[col].type >= TSDB_DATA_TYPE_BOOL && tschema[col].type <= TSDB_DATA_TYPE_NCHAR);
|
||||
|
||||
if (col < pStable->numOfTables) {
|
||||
schemaLen += tschema[col].bytes;
|
||||
} else {
|
||||
tagLen += tschema[col].bytes;
|
||||
}
|
||||
|
||||
if (!isValidDataType(tschema[col].type)) {
|
||||
mError("msg:%p, app:%p table:%s, failed to create, invalid data type in schema", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableId);
|
||||
return TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG;
|
||||
}
|
||||
}
|
||||
|
||||
if (schemaLen > (TSDB_MAX_BYTES_PER_ROW || tagLen > TSDB_MAX_TAGS_LEN)) {
|
||||
mError("msg:%p, app:%p table:%s, failed to create, schema is too long", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableId);
|
||||
return TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG;
|
||||
}
|
||||
|
||||
pMsg->pTable = (STableObj *)pStable;
|
||||
|
@ -2361,6 +2381,12 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
|
|||
static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
|
||||
STableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||
|
||||
if (pMsg->rpcMsg.contLen <= sizeof(*pInfo)) {
|
||||
mError("msg:%p, app:%p table:%s, failed to auto create child table, tags not exist", pMsg, pMsg->rpcMsg.ahandle,
|
||||
pInfo->tableId);
|
||||
return TSDB_CODE_MND_TAG_NOT_EXIST;
|
||||
}
|
||||
|
||||
char* p = pInfo->tags;
|
||||
int32_t nameLen = htonl(*(int32_t*) p);
|
||||
p += sizeof(int32_t);
|
||||
|
|
|
@ -565,7 +565,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) {
|
|||
SDbObj *pDb = pMsg->pDb;
|
||||
|
||||
SVgObj *pVgroup = (SVgObj *)calloc(1, sizeof(SVgObj));
|
||||
tstrncpy(pVgroup->dbName, pDb->name, TSDB_ACCT_LEN + TSDB_DB_NAME_LEN);
|
||||
tstrncpy(pVgroup->dbName, pDb->name, TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN);
|
||||
pVgroup->numOfVnodes = pDb->cfg.replications;
|
||||
pVgroup->createdTime = taosGetTimestampMs();
|
||||
pVgroup->accessState = TSDB_VN_ALL_ACCCESS;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_LINUX)
|
||||
|
@ -10,3 +10,5 @@ ELSEIF (TD_WINDOWS)
|
|||
ENDIF ()
|
||||
|
||||
ADD_SUBDIRECTORY(src/detail)
|
||||
ADD_SUBDIRECTORY(tests)
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ extern "C" {
|
|||
|
||||
// USE_LIBICONV
|
||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, size_t *len);
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int *len);
|
||||
int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes);
|
||||
bool taosValidateEncodec(const char *encodec);
|
||||
char * taosCharsetReplace(char *charsetstr);
|
||||
|
|
|
@ -32,6 +32,7 @@ void taosPrintOsInfo();
|
|||
int taosSystem(const char * cmd) ;
|
||||
void taosKillSystem();
|
||||
bool taosGetSystemUid(char *uid);
|
||||
char *taosGetCmdlineByPID(int pid);
|
||||
|
||||
// TAOS_OS_FUNC_SYSINFO_CORE
|
||||
void taosSetCoreDump();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(.)
|
||||
|
|
|
@ -46,7 +46,7 @@ int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
|
|||
return (int32_t)(ucs4_max_len - outLen);
|
||||
}
|
||||
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, size_t *len) {
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, int32_t *len) {
|
||||
memset(ucs4, 0, ucs4_max_len);
|
||||
iconv_t cd = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||
size_t ucs4_input_len = mbsLength;
|
||||
|
@ -58,7 +58,7 @@ bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len
|
|||
|
||||
iconv_close(cd);
|
||||
if (len != NULL) {
|
||||
*len = ucs4_max_len - outLeft;
|
||||
*len = (int32_t)(ucs4_max_len - outLeft);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -92,7 +92,7 @@ int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
|
|||
return len;
|
||||
}
|
||||
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, size_t *len) {
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, int32_t *len) {
|
||||
memset(ucs4, 0, ucs4_max_len);
|
||||
mbstate_t state = {0};
|
||||
int32_t retlen = mbsnrtowcs((wchar_t *)ucs4, (const char **)&mbs, mbsLength, ucs4_max_len / 4, &state);
|
||||
|
|
|
@ -486,7 +486,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
|
|||
start = (delta / pInterval->sliding + factor) * pInterval->sliding;
|
||||
|
||||
if (pInterval->intervalUnit == 'd' || pInterval->intervalUnit == 'w') {
|
||||
/*
|
||||
/*
|
||||
* here we revised the start time of day according to the local time zone,
|
||||
* but in case of DST, the start time of one day need to be dynamically decided.
|
||||
*/
|
||||
|
@ -501,9 +501,24 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
|
|||
start += (int64_t)(timezone * TSDB_TICK_PER_SECOND(precision));
|
||||
}
|
||||
|
||||
int64_t end = start + pInterval->interval - 1;
|
||||
if (end < t) {
|
||||
start += pInterval->sliding;
|
||||
int64_t end = 0;
|
||||
|
||||
// not enough time range
|
||||
if (INT64_MAX - start > pInterval->interval - 1) {
|
||||
end = start + pInterval->interval - 1;
|
||||
|
||||
while(end < t && ((start + pInterval->sliding) <= INT64_MAX)) { // move forward to the correct time window
|
||||
start += pInterval->sliding;
|
||||
|
||||
if (INT64_MAX - start > pInterval->interval - 1) {
|
||||
end = start + pInterval->interval - 1;
|
||||
} else {
|
||||
end = INT64_MAX;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
end = INT64_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
|
|
|
@ -39,4 +39,22 @@ void osInit() {
|
|||
strcpy(tsDnodeDir, "");
|
||||
strcpy(tsMnodeDir, "");
|
||||
strcpy(tsOsName, "Linux");
|
||||
}
|
||||
}
|
||||
|
||||
char cmdline[1024];
|
||||
|
||||
char *taosGetCmdlineByPID(int pid)
|
||||
{
|
||||
sprintf(cmdline, "/proc/%d/cmdline",pid);
|
||||
FILE* f = fopen(cmdline,"r");
|
||||
if(f){
|
||||
size_t size;
|
||||
size = fread(cmdline, sizeof(char), 1024, f);
|
||||
if(size>0){
|
||||
if('\n'==cmdline[size-1])
|
||||
cmdline[size-1]='\0';
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
return cmdline;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
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)
|
||||
|
||||
IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR)
|
||||
MESSAGE(STATUS "gTest library found, build unit test")
|
||||
|
||||
INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR})
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
||||
|
||||
ADD_EXECUTABLE(osTest ${SOURCE_LIST})
|
||||
TARGET_LINK_LIBRARIES(osTest taos osdetail tutil common gtest pthread)
|
||||
ENDIF()
|
|
@ -0,0 +1,34 @@
|
|||
#include "os.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "taos.h"
|
||||
#include "tstoken.h"
|
||||
#include "tutil.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
// test function in os module
|
||||
TEST(testCase, parse_time) {
|
||||
taos_options(TSDB_OPTION_TIMEZONE, "GMT-8");
|
||||
deltaToUtcInitOnce();
|
||||
|
||||
// window: 1500000001000, 1500002000000
|
||||
// pQuery->interval: interval: 86400000, sliding:3600000
|
||||
int64_t key = 1500000001000;
|
||||
SInterval interval = {0};
|
||||
interval.interval = 86400000;
|
||||
interval.intervalUnit = 'd';
|
||||
interval.sliding = 3600000;
|
||||
interval.slidingUnit = 'h';
|
||||
|
||||
int64_t s = taosTimeTruncate(key, &interval, TSDB_TIME_PRECISION_MILLI);
|
||||
ASSERT_TRUE(s + interval.interval >= key);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
ADD_SUBDIRECTORY(monitor)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/zlib-1.2.11/inc)
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
#define HTTP_GC_TARGET_SIZE 512
|
||||
#define HTTP_WRITE_RETRY_TIMES 500
|
||||
#define HTTP_WRITE_WAIT_TIME_MS 5
|
||||
#define HTTP_SESSION_ID_LEN (TSDB_USER_LEN + TSDB_PASSWORD_LEN)
|
||||
#define HTTP_SESSION_ID_LEN (TSDB_USER_LEN + TSDB_KEY_LEN)
|
||||
|
||||
typedef enum HttpReqType {
|
||||
HTTP_REQTYPE_OTHERS = 0,
|
||||
|
@ -147,7 +147,7 @@ typedef struct HttpContext {
|
|||
uint8_t parsed;
|
||||
char ipstr[22];
|
||||
char user[TSDB_USER_LEN]; // parsed from auth token or login message
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
TAOS * taos;
|
||||
void * ppContext;
|
||||
HttpSession *session;
|
||||
|
|
|
@ -51,7 +51,7 @@ int32_t httpParseBasicAuthToken(HttpContext *pContext, char *token, int32_t len)
|
|||
|
||||
char *password = user + 1;
|
||||
int32_t pass_len = (int32_t)((base64 + outlen) - password);
|
||||
if (pass_len < 1 || pass_len >= TSDB_PASSWORD_LEN) {
|
||||
if (pass_len < 1 || pass_len >= TSDB_KEY_LEN) {
|
||||
httpError("context:%p, fd:%d, basic token:%s parse password error", pContext, pContext->fd, token);
|
||||
free(base64);
|
||||
return -1;
|
||||
|
@ -73,7 +73,7 @@ int32_t httpParseTaosdAuthToken(HttpContext *pContext, char *token, int32_t len)
|
|||
if (base64) free(base64);
|
||||
return 01;
|
||||
}
|
||||
if (outlen != (TSDB_USER_LEN + TSDB_PASSWORD_LEN)) {
|
||||
if (outlen != (TSDB_USER_LEN + TSDB_KEY_LEN)) {
|
||||
httpError("context:%p, fd:%d, taosd token:%s length error", pContext, pContext->fd, token);
|
||||
free(base64);
|
||||
return -1;
|
||||
|
@ -103,8 +103,8 @@ int32_t httpGenTaosdAuthToken(HttpContext *pContext, char *token, int32_t maxLen
|
|||
size = sizeof(pContext->pass);
|
||||
tstrncpy(buffer + sizeof(pContext->user), pContext->pass, size);
|
||||
|
||||
char *encrypt = taosDesEncode(KEY_DES_4, buffer, TSDB_USER_LEN + TSDB_PASSWORD_LEN);
|
||||
char *base64 = base64_encode((const unsigned char *)encrypt, TSDB_USER_LEN + TSDB_PASSWORD_LEN);
|
||||
char *encrypt = taosDesEncode(KEY_DES_4, buffer, TSDB_USER_LEN + TSDB_KEY_LEN);
|
||||
char *base64 = base64_encode((const unsigned char *)encrypt, TSDB_USER_LEN + TSDB_KEY_LEN);
|
||||
|
||||
size_t len = strlen(base64);
|
||||
tstrncpy(token, base64, len + 1);
|
||||
|
|
|
@ -59,11 +59,11 @@ bool gcGetUserFromUrl(HttpContext* pContext) {
|
|||
|
||||
bool gcGetPassFromUrl(HttpContext* pContext) {
|
||||
HttpParser* pParser = pContext->parser;
|
||||
if (pParser->path[GC_PASS_URL_POS].pos >= TSDB_PASSWORD_LEN || pParser->path[GC_PASS_URL_POS].pos <= 0) {
|
||||
if (pParser->path[GC_PASS_URL_POS].pos >= TSDB_KEY_LEN || pParser->path[GC_PASS_URL_POS].pos <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tstrncpy(pContext->pass, pParser->path[GC_PASS_URL_POS].str, TSDB_PASSWORD_LEN);
|
||||
tstrncpy(pContext->pass, pParser->path[GC_PASS_URL_POS].str, TSDB_KEY_LEN);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,11 +72,11 @@ bool restGetUserFromUrl(HttpContext* pContext) {
|
|||
|
||||
bool restGetPassFromUrl(HttpContext* pContext) {
|
||||
HttpParser* pParser = pContext->parser;
|
||||
if (pParser->path[REST_PASS_URL_POS].pos >= TSDB_PASSWORD_LEN || pParser->path[REST_PASS_URL_POS].pos <= 0) {
|
||||
if (pParser->path[REST_PASS_URL_POS].pos >= TSDB_KEY_LEN || pParser->path[REST_PASS_URL_POS].pos <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tstrncpy(pContext->pass, pParser->path[REST_PASS_URL_POS].str, TSDB_PASSWORD_LEN);
|
||||
tstrncpy(pContext->pass, pParser->path[REST_PASS_URL_POS].str, TSDB_KEY_LEN);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ void httpProcessMultiSql(HttpContext *pContext) {
|
|||
char *sql = httpGetCmdsString(pContext, cmd->sql);
|
||||
httpTraceL("context:%p, fd:%d, user:%s, process pos:%d, start query, sql:%s", pContext, pContext->fd, pContext->user,
|
||||
multiCmds->pos, sql);
|
||||
nPrintHttp(sql);
|
||||
nPrintHttp("%s", sql);
|
||||
taos_query_a(pContext->session->taos, sql, httpProcessMultiSqlCallBack, (void *)pContext);
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ void httpProcessSingleSqlCmd(HttpContext *pContext) {
|
|||
}
|
||||
|
||||
httpTraceL("context:%p, fd:%d, user:%s, start query, sql:%s", pContext, pContext->fd, pContext->user, sql);
|
||||
nPrintHttp(sql);
|
||||
nPrintHttp("%s", sql);
|
||||
taos_query_a(pSession->taos, sql, httpProcessSingleSqlCallBack, (void *)pContext);
|
||||
}
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@ bool tgGetUserFromUrl(HttpContext *pContext) {
|
|||
|
||||
bool tgGetPassFromUrl(HttpContext *pContext) {
|
||||
HttpParser *pParser = pContext->parser;
|
||||
if (pParser->path[TG_PASS_URL_POS].pos >= TSDB_PASSWORD_LEN || pParser->path[TG_PASS_URL_POS].pos <= 0) {
|
||||
if (pParser->path[TG_PASS_URL_POS].pos >= TSDB_KEY_LEN || pParser->path[TG_PASS_URL_POS].pos <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue