Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzh_me
TDengine
提交
cbfe680f
TDengine
项目概览
lzh_me
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cbfe680f
编写于
8月 23, 2021
作者:
P
Ping Xiao
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into xiaoping/test_case
上级
e914a0e8
91ab5f22
变更
24
隐藏空白更改
内联
并排
Showing
24 changed file
with
874 addition
and
167 deletion
+874
-167
documentation20/cn/01.evaluation/docs.md
documentation20/cn/01.evaluation/docs.md
+29
-24
src/client/src/tscGlobalmerge.c
src/client/src/tscGlobalmerge.c
+1
-1
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+2
-0
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+7
-7
src/common/src/tvariant.c
src/common/src/tvariant.c
+4
-4
src/inc/taosdef.h
src/inc/taosdef.h
+2
-0
src/kit/shell/inc/shell.h
src/kit/shell/inc/shell.h
+0
-1
src/kit/shell/src/shellDarwin.c
src/kit/shell/src/shellDarwin.c
+10
-4
src/kit/shell/src/shellLinux.c
src/kit/shell/src/shellLinux.c
+17
-10
src/kit/shell/src/shellWindows.c
src/kit/shell/src/shellWindows.c
+10
-4
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+34
-82
src/kit/taosdump/taosdump.c
src/kit/taosdump/taosdump.c
+40
-12
src/os/src/linux/osSystem.c
src/os/src/linux/osSystem.c
+4
-4
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+2
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+37
-7
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+14
-5
tests/pytest/functions/function_bottom.py
tests/pytest/functions/function_bottom.py
+15
-0
tests/pytest/functions/function_derivative.py
tests/pytest/functions/function_derivative.py
+22
-0
tests/pytest/functions/function_diff.py
tests/pytest/functions/function_diff.py
+17
-0
tests/pytest/functions/function_top.py
tests/pytest/functions/function_top.py
+15
-0
tests/pytest/functions/queryTestCases.py
tests/pytest/functions/queryTestCases.py
+122
-1
tests/pytest/query/filterNoKeyword.py
tests/pytest/query/filterNoKeyword.py
+83
-0
tests/script/api/makefile
tests/script/api/makefile
+4
-1
tests/script/api/stmt_function.c
tests/script/api/stmt_function.c
+383
-0
未找到文件。
documentation20/cn/01.evaluation/docs.md
浏览文件 @
cbfe680f
...
...
@@ -2,18 +2,18 @@
## <a class="anchor" id="intro"></a>TDengine 简介
TDengine
是涛思数据面对高速增长的物联网大数据市场和技术挑战推出的创新性的大数据处理产品,它不依赖任何第三方软件,也不是优化或包装了一个开源的数据库或流式计算产品,而是在吸取众多传统关系型数据库、NoSQL
数据库、流式计算引擎、消息队列等软件的优点之后自主开发的产品,在时序空间大数据处理上,有着自己独到的优势。
TDengine
是涛思数据面对高速增长的物联网大数据市场和技术挑战推出的创新性的大数据处理产品,它不依赖任何第三方软件,也不是优化或包装了一个开源的数据库或流式计算产品,而是在吸取众多传统关系型数据库、NoSQL
数据库、流式计算引擎、消息队列等软件的优点之后自主开发的产品,在时序空间大数据处理上,有着自己独到的优势。
TDengine
的模块之一是时序数据库。但除此之外,为减少研发的复杂度、系统维护的难度,TDengine还提供缓存、消息队列、订阅、流式计算等功能,为物联网、工业互联网大数据的处理提供全栈的技术方案,是一个高效易用的物联网大数据平台。与Hadoop
等典型的大数据平台相比,它具有如下鲜明的特点:
TDengine
的模块之一是时序数据库。但除此之外,为减少研发的复杂度、系统维护的难度,TDengine 还提供缓存、消息队列、订阅、流式计算等功能,为物联网、工业互联网大数据的处理提供全栈的技术方案,是一个高效易用的物联网大数据平台。与 Hadoop
等典型的大数据平台相比,它具有如下鲜明的特点:
*
__10
倍以上的性能提升__:定义了创新的数据存储结构,单核每秒能处理至少2
万次请求,插入数百万个数据点,读出一千万以上数据点,比现有通用数据库快十倍以上。
*
__硬件或云服务成本降至
1/5__:由于超强性能,计算资源不到通用大数据方案的1/5;通过列式存储和先进的压缩算法,存储空间不到通用数据库的
1/10。
*
__全栈时序数据处理引擎__:将数据库、消息队列、缓存、流式计算等功能融为一体,应用无需再集成
Kafka/Redis/HBase/Spark/HDFS
等软件,大幅降低应用开发和维护的复杂度成本。
*
__强大的分析功能__:无论是十年前还是一秒钟前的数据,指定时间范围即可查询。数据可在时间轴上或多个设备上进行聚合。即席查询可通过
Shell, Python, R, MATLAB
随时进行。
*
__与第三方工具无缝连接__:不用一行代码,即可与
Telegraf, Grafana, EMQ, HiveMQ, Prometheus, MATLAB, R等集成。后续将支持OPC, Hadoop, Spark等, BI
工具也将无缝连接。
*
__零运维成本、零学习成本__:安装集群简单快捷,无需分库分表,实时备份。类
似标准SQL,支持RESTful, 支持Python/Java/C/C++/C#/Go/Node.js, 与MySQL
相似,零学习成本。
*
__10
倍以上的性能提升__:定义了创新的数据存储结构,单核每秒能处理至少 2
万次请求,插入数百万个数据点,读出一千万以上数据点,比现有通用数据库快十倍以上。
*
__硬件或云服务成本降至
1/5__:由于超强性能,计算资源不到通用大数据方案的 1/5;通过列式存储和先进的压缩算法,存储空间不到通用数据库的
1/10。
*
__全栈时序数据处理引擎__:将数据库、消息队列、缓存、流式计算等功能融为一体,应用无需再集成
Kafka/Redis/HBase/Spark/HDFS
等软件,大幅降低应用开发和维护的复杂度成本。
*
__强大的分析功能__:无论是十年前还是一秒钟前的数据,指定时间范围即可查询。数据可在时间轴上或多个设备上进行聚合。即席查询可通过
Shell, Python, R, MATLAB
随时进行。
*
__与第三方工具无缝连接__:不用一行代码,即可与
Telegraf, Grafana, EMQ, HiveMQ, Prometheus, MATLAB, R 等集成。后续将支持 OPC, Hadoop, Spark 等,BI
工具也将无缝连接。
*
__零运维成本、零学习成本__:安装集群简单快捷,无需分库分表,实时备份。类
标准 SQL,支持 RESTful,支持 Python/Java/C/C++/C#/Go/Node.js, 与 MySQL
相似,零学习成本。
采用
TDengine,可将典型的物联网、车联网、工业互联网大数据平台的总拥有成本大幅降低。但需要指出的是,因充分利用了物联网时序数据的特点,它无法用来处理网络爬虫、微博、微信、电商、ERP、CRM
等通用型数据。
采用
TDengine,可将典型的物联网、车联网、工业互联网大数据平台的总拥有成本大幅降低。但需要指出的是,因充分利用了物联网时序数据的特点,它无法用来处理网络爬虫、微博、微信、电商、ERP、CRM
等通用型数据。
![
TDengine技术生态图
](
page://images/eco_system.png
)
<center>
图 1. TDengine技术生态图
</center>
...
...
@@ -21,42 +21,47 @@ TDengine的模块之一是时序数据库。但除此之外,为减少研发的
## <a class="anchor" id="scenes"></a>TDengine 总体适用场景
作为一个
IOT大数据平台,TDengine的典型适用场景是在IOT范畴,而且用户有一定的数据量。本文后续的介绍主要针对这个范畴里面的系统。范畴之外的系统,比如CRM,ERP
等,不在本文讨论范围内。
作为一个
IOT 大数据平台,TDengine 的典型适用场景是在 IOT 范畴,而且用户有一定的数据量。本文后续的介绍主要针对这个范畴里面的系统。范畴之外的系统,比如 CRM,ERP
等,不在本文讨论范围内。
### 数据源特点和需求
从数据源角度,设计人员可以从下面几个角度分析TDengine在目标应用系统里面的适用性。
从数据源角度,设计人员可以从下面几个角度分析 TDengine 在目标应用系统里面的适用性。
|数据源特点和需求|不适用|可能适用|非常适用|简单说明|
|---|---|---|---|---|
|总体数据量巨大| | | √ |
TDengine
在容量方面提供出色的水平扩展功能,并且具备匹配高压缩的存储结构,达到业界最优的存储效率。|
|数据输入速度偶尔或者持续巨大| | | √ | TDengine的性能大大超过同类产品,可以在同样的硬件环境下持续处理大量的输入数据,并且提供很容易在用户环境里面运行的性能评估工具。|
|数据源数目巨大| | | √ |
TDengine
设计中包含专门针对大量数据源的优化,包括数据的写入和查询,尤其适合高效处理海量(千万或者更多量级)的数据源。|
|总体数据量巨大| | | √ |
TDengine
在容量方面提供出色的水平扩展功能,并且具备匹配高压缩的存储结构,达到业界最优的存储效率。|
|数据输入速度偶尔或者持续巨大| | | √ | TDengine
的性能大大超过同类产品,可以在同样的硬件环境下持续处理大量的输入数据,并且提供很容易在用户环境里面运行的性能评估工具。|
|数据源数目巨大| | | √ |
TDengine
设计中包含专门针对大量数据源的优化,包括数据的写入和查询,尤其适合高效处理海量(千万或者更多量级)的数据源。|
### 系统架构要求
|系统架构要求|不适用|可能适用|非常适用|简单说明|
|---|---|---|---|---|
|要求简单可靠的系统架构| | | √ |
TDengine
的系统架构非常简单可靠,自带消息队列,缓存,流式计算,监控等功能,无需集成额外的第三方产品。|
|要求容错和高可靠| | | √ |
TDengine
的集群功能,自动提供容错灾备等高可靠功能。|
|标准化规范| | | √ |
TDengine
使用标准的SQL语言提供主要功能,遵守标准化规范。|
|要求简单可靠的系统架构| | | √ |
TDengine
的系统架构非常简单可靠,自带消息队列,缓存,流式计算,监控等功能,无需集成额外的第三方产品。|
|要求容错和高可靠| | | √ |
TDengine
的集群功能,自动提供容错灾备等高可靠功能。|
|标准化规范| | | √ |
TDengine
使用标准的SQL语言提供主要功能,遵守标准化规范。|
### 系统功能需求
|系统功能需求|不适用|可能适用|非常适用|简单说明|
|---|---|---|---|---|
|要求完整的内置数据处理算法| | √ | |
TDengine
的实现了通用的数据处理算法,但是还没有做到妥善处理各行各业的所有要求,因此特殊类型的处理还需要应用层面处理。|
|需要大量的交叉查询处理| | √ | |这种类型的处理更多应该用关系型数据系统处理,或者应该考虑
TDengine
和关系型数据系统配合实现系统功能。|
|要求完整的内置数据处理算法| | √ | |
TDengine
的实现了通用的数据处理算法,但是还没有做到妥善处理各行各业的所有要求,因此特殊类型的处理还需要应用层面处理。|
|需要大量的交叉查询处理| | √ | |这种类型的处理更多应该用关系型数据系统处理,或者应该考虑
TDengine
和关系型数据系统配合实现系统功能。|
### 系统性能需求
|系统性能需求|不适用|可能适用|非常适用|简单说明|
|---|---|---|---|---|
|要求较大的总体处理能力| | | √ |
TDengine
的集群功能可以轻松地让多服务器配合达成处理能力的提升。|
|要求高速处理数据 | | | √ |
TDengine的专门为IOT
优化的存储和数据处理的设计,一般可以让系统得到超出同类产品多倍数的处理速度提升。|
|要求快速处理小粒度数据| | | √ |这方面
TDengine性能可以完全对标关系型和NoSQL
型数据处理系统。|
|要求较大的总体处理能力| | | √ |
TDengine
的集群功能可以轻松地让多服务器配合达成处理能力的提升。|
|要求高速处理数据 | | | √ |
TDengine 的专门为 IOT
优化的存储和数据处理的设计,一般可以让系统得到超出同类产品多倍数的处理速度提升。|
|要求快速处理小粒度数据| | | √ |这方面
TDengine 性能可以完全对标关系型和 NoSQL
型数据处理系统。|
### 系统维护需求
|系统维护需求|不适用|可能适用|非常适用|简单说明|
|---|---|---|---|---|
|要求系统可靠运行| | | √ |
TDengine
的系统架构非常稳定可靠,日常维护也简单便捷,对维护人员的要求简洁明了,最大程度上杜绝人为错误和事故。|
|要求系统可靠运行| | | √ |
TDengine
的系统架构非常稳定可靠,日常维护也简单便捷,对维护人员的要求简洁明了,最大程度上杜绝人为错误和事故。|
|要求运维学习成本可控| | | √ |同上。|
|要求市场有大量人才储备| √ | | |
TDengine
作为新一代产品,目前人才市场里面有经验的人员还有限。但是学习成本低,我们作为厂家也提供运维的培训和辅助服务。|
|要求市场有大量人才储备| √ | | |
TDengine
作为新一代产品,目前人才市场里面有经验的人员还有限。但是学习成本低,我们作为厂家也提供运维的培训和辅助服务。|
src/client/src/tscGlobalmerge.c
浏览文件 @
cbfe680f
...
...
@@ -643,7 +643,7 @@ static void doExecuteFinalMerge(SOperatorInfo* pOperator, int32_t numOfExpr, SSD
for
(
int32_t
j
=
0
;
j
<
numOfExpr
;
++
j
)
{
pCtx
[
j
].
pOutput
+=
(
pCtx
[
j
].
outputBytes
*
numOfRows
);
if
(
pCtx
[
j
].
functionId
==
TSDB_FUNC_TOP
||
pCtx
[
j
].
functionId
==
TSDB_FUNC_BOTTOM
)
{
pCtx
[
j
].
ptsOutputBuf
=
pCtx
[
0
].
pOutput
;
if
(
j
>
0
)
pCtx
[
j
].
ptsOutputBuf
=
pCtx
[
j
-
1
].
pOutput
;
}
}
...
...
src/client/src/tscPrepare.c
浏览文件 @
cbfe680f
...
...
@@ -206,6 +206,8 @@ static int normalStmtPrepare(STscStmt* stmt) {
return
code
;
}
start
=
i
+
token
.
n
;
}
else
if
(
token
.
type
==
TK_ILLEGAL
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
&
stmt
->
pSql
->
cmd
),
"invalid sql"
);
}
i
+=
token
.
n
;
...
...
src/client/src/tscSQLParser.c
浏览文件 @
cbfe680f
...
...
@@ -888,6 +888,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
case
TSDB_SQL_SELECT
:
{
const
char
*
msg1
=
"no nested query supported in union clause"
;
code
=
loadAllTableMeta
(
pSql
,
pInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
...
...
@@ -901,6 +902,10 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tscTrace
(
"0x%"
PRIx64
" start to parse the %dth subclause, total:%"
PRIzu
,
pSql
->
self
,
i
,
size
);
if
(
size
>
1
&&
pSqlNode
->
from
&&
pSqlNode
->
from
->
type
==
SQL_NODE_FROM_SUBQUERY
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
// normalizeSqlNode(pSqlNode); // normalize the column name in each function
if
((
code
=
validateSqlNode
(
pSql
,
pSqlNode
,
pQueryInfo
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
...
...
@@ -2603,13 +2608,12 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
// set the first column ts for diff query
if
(
functionId
==
TSDB_FUNC_DIFF
||
functionId
==
TSDB_FUNC_DERIVATIVE
)
{
colIndex
+=
1
;
SColumnIndex
indexTS
=
{.
tableIndex
=
index
.
tableIndex
,
.
columnIndex
=
0
};
SExprInfo
*
pExpr
=
tscExprAppend
(
pQueryInfo
,
TSDB_FUNC_TS_DUMMY
,
&
indexTS
,
TSDB_DATA_TYPE_TIMESTAMP
,
TSDB_KEYSIZE
,
getNewResColId
(
pCmd
),
TSDB_KEYSIZE
,
false
);
SColumnList
ids
=
createColumnList
(
1
,
0
,
0
);
insertResultField
(
pQueryInfo
,
0
,
&
ids
,
TSDB_KEYSIZE
,
TSDB_DATA_TYPE_TIMESTAMP
,
aAggs
[
TSDB_FUNC_TS_DUMMY
].
name
,
pExpr
);
insertResultField
(
pQueryInfo
,
colIndex
,
&
ids
,
TSDB_KEYSIZE
,
TSDB_DATA_TYPE_TIMESTAMP
,
aAggs
[
TSDB_FUNC_TS_DUMMY
].
name
,
pExpr
);
}
SExprInfo
*
pExpr
=
tscExprAppend
(
pQueryInfo
,
functionId
,
&
index
,
resultType
,
resultSize
,
getNewResColId
(
pCmd
),
intermediateResSize
,
false
);
...
...
@@ -2882,7 +2886,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const
int32_t
TS_COLUMN_INDEX
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
;
SColumnList
ids
=
createColumnList
(
1
,
index
.
tableIndex
,
TS_COLUMN_INDEX
);
insertResultField
(
pQueryInfo
,
TS_COLUMN_INDEX
,
&
ids
,
TSDB_KEYSIZE
,
TSDB_DATA_TYPE_TIMESTAMP
,
insertResultField
(
pQueryInfo
,
colIndex
,
&
ids
,
TSDB_KEYSIZE
,
TSDB_DATA_TYPE_TIMESTAMP
,
aAggs
[
TSDB_FUNC_TS
].
name
,
pExpr
);
colIndex
+=
1
;
// the first column is ts
...
...
@@ -4884,10 +4888,6 @@ static void cleanQueryExpr(SCondExpr* pCondExpr) {
tSqlExprDestroy
(
pCondExpr
->
pTableCond
);
}
if
(
pCondExpr
->
pTagCond
)
{
tSqlExprDestroy
(
pCondExpr
->
pTagCond
);
}
if
(
pCondExpr
->
pColumnCond
)
{
tSqlExprDestroy
(
pCondExpr
->
pColumnCond
);
}
...
...
src/common/src/tvariant.c
浏览文件 @
cbfe680f
...
...
@@ -31,12 +31,12 @@ void tVariantCreate(tVariant *pVar, SStrToken *token) {
switch
(
token
->
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
{
int32_t
k
=
strncasecmp
(
token
->
z
,
"true"
,
4
);
if
(
k
==
0
)
{
if
(
strncasecmp
(
token
->
z
,
"true"
,
4
)
==
0
)
{
pVar
->
i64
=
TSDB_TRUE
;
}
else
{
assert
(
strncasecmp
(
token
->
z
,
"false"
,
5
)
==
0
);
}
else
if
(
strncasecmp
(
token
->
z
,
"false"
,
5
)
==
0
)
{
pVar
->
i64
=
TSDB_FALSE
;
}
else
{
return
;
}
break
;
...
...
src/inc/taosdef.h
浏览文件 @
cbfe680f
...
...
@@ -87,6 +87,8 @@ extern const int32_t TYPE_BYTES[15];
#define TSDB_DEFAULT_PASS "taosdata"
#endif
#define SHELL_MAX_PASSWORD_LEN 20
#define TSDB_TRUE 1
#define TSDB_FALSE 0
#define TSDB_OK 0
...
...
src/kit/shell/inc/shell.h
浏览文件 @
cbfe680f
...
...
@@ -25,7 +25,6 @@
#define MAX_USERNAME_SIZE 64
#define MAX_DBNAME_SIZE 64
#define MAX_IP_SIZE 20
#define MAX_PASSWORD_SIZE 20
#define MAX_HISTORY_SIZE 1000
#define MAX_COMMAND_SIZE 1048586
#define HISTORY_FILE ".taos_history"
...
...
src/kit/shell/src/shellDarwin.c
浏览文件 @
cbfe680f
...
...
@@ -66,7 +66,7 @@ void printHelp() {
char
DARWINCLIENT_VERSION
[]
=
"Welcome to the TDengine shell from %s, Client Version:%s
\n
"
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.
\n\n
"
;
char
g_password
[
MAX_PASSWORD_SIZE
];
char
g_password
[
SHELL_MAX_PASSWORD_LEN
];
void
shellParseArgument
(
int
argc
,
char
*
argv
[],
SShellArguments
*
arguments
)
{
wordexp_t
full_path
;
...
...
@@ -81,19 +81,25 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
}
}
// for password
else
if
(
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
{
else
if
((
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
strcpy
(
tsOsName
,
"Darwin"
);
printf
(
DARWINCLIENT_VERSION
,
tsOsName
,
taos_get_client_info
());
if
(
strlen
(
argv
[
i
])
==
2
)
{
if
((
strlen
(
argv
[
i
])
==
2
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
printf
(
"Enter password: "
);
taosSetConsoleEcho
(
false
);
if
(
scanf
(
"%s"
,
g_password
)
>
1
)
{
fprintf
(
stderr
,
"password read error
\n
"
);
}
taosSetConsoleEcho
(
true
);
getchar
();
}
else
{
tstrncpy
(
g_password
,
(
char
*
)(
argv
[
i
]
+
2
),
MAX_PASSWORD_SIZE
);
tstrncpy
(
g_password
,
(
char
*
)(
argv
[
i
]
+
2
),
SHELL_MAX_PASSWORD_LEN
);
}
arguments
->
password
=
g_password
;
strcpy
(
argv
[
i
],
""
);
argc
-=
1
;
}
// for management port
else
if
(
strcmp
(
argv
[
i
],
"-P"
)
==
0
)
{
...
...
src/kit/shell/src/shellLinux.c
浏览文件 @
cbfe680f
...
...
@@ -47,8 +47,8 @@ static struct argp_option options[] = {
{
"thread"
,
'T'
,
"THREADNUM"
,
0
,
"Number of threads when using multi-thread to import data."
},
{
"check"
,
'k'
,
"CHECK"
,
0
,
"Check tables."
},
{
"database"
,
'd'
,
"DATABASE"
,
0
,
"Database to use when connecting to the server."
},
{
"timezone"
,
'
t
'
,
"TIMEZONE"
,
0
,
"Time zone of the shell, default is local."
},
{
"netrole"
,
'n'
,
"NETROLE"
,
0
,
"Net role when network connectivity test, default is startup, options: client|server|rpc|startup|sync."
},
{
"timezone"
,
'
z
'
,
"TIMEZONE"
,
0
,
"Time zone of the shell, default is local."
},
{
"netrole"
,
'n'
,
"NETROLE"
,
0
,
"Net role when network connectivity test, default is startup, options: client|server|rpc|startup|sync
|speen|fqdn
."
},
{
"pktlen"
,
'l'
,
"PKTLEN"
,
0
,
"Packet length used for net test, default is 1000 bytes."
},
{
0
}};
...
...
@@ -74,7 +74,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
}
break
;
case
'
t
'
:
case
'
z
'
:
arguments
->
timezone
=
arg
;
break
;
case
'u'
:
...
...
@@ -160,22 +160,29 @@ static struct argp argp = {options, parse_opt, args_doc, doc};
char
LINUXCLIENT_VERSION
[]
=
"Welcome to the TDengine shell from %s, Client Version:%s
\n
"
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.
\n\n
"
;
char
g_password
[
MAX_PASSWORD_SIZE
];
char
g_password
[
SHELL_MAX_PASSWORD_LEN
];
static
void
parse_
password
(
static
void
parse_
args
(
int
argc
,
char
*
argv
[],
SShellArguments
*
arguments
)
{
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
if
(
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
{
if
((
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
strcpy
(
tsOsName
,
"Linux"
);
printf
(
LINUXCLIENT_VERSION
,
tsOsName
,
taos_get_client_info
());
if
(
strlen
(
argv
[
i
])
==
2
)
{
if
((
strlen
(
argv
[
i
])
==
2
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
printf
(
"Enter password: "
);
taosSetConsoleEcho
(
false
);
if
(
scanf
(
"%20s"
,
g_password
)
>
1
)
{
fprintf
(
stderr
,
"password reading error
\n
"
);
}
getchar
();
taosSetConsoleEcho
(
true
);
if
(
EOF
==
getchar
())
{
fprintf
(
stderr
,
"getchar() return EOF
\n
"
);
}
}
else
{
tstrncpy
(
g_password
,
(
char
*
)(
argv
[
i
]
+
2
),
MAX_PASSWORD_SIZE
);
tstrncpy
(
g_password
,
(
char
*
)(
argv
[
i
]
+
2
),
SHELL_MAX_PASSWORD_LEN
);
strcpy
(
argv
[
i
],
"-p"
);
}
arguments
->
password
=
g_password
;
arguments
->
is_use_passwd
=
true
;
...
...
@@ -190,7 +197,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
argp_program_version
=
verType
;
if
(
argc
>
1
)
{
parse_
password
(
argc
,
argv
,
arguments
);
parse_
args
(
argc
,
argv
,
arguments
);
}
argp_parse
(
&
argp
,
argc
,
argv
,
0
,
0
,
arguments
);
...
...
src/kit/shell/src/shellWindows.c
浏览文件 @
cbfe680f
...
...
@@ -64,7 +64,7 @@ void printHelp() {
exit
(
EXIT_SUCCESS
);
}
char
g_password
[
MAX_PASSWORD_SIZE
];
char
g_password
[
SHELL_MAX_PASSWORD_LEN
];
void
shellParseArgument
(
int
argc
,
char
*
argv
[],
SShellArguments
*
arguments
)
{
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
...
...
@@ -78,20 +78,26 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
}
}
// for password
else
if
(
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
{
else
if
((
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
arguments
->
is_use_passwd
=
true
;
strcpy
(
tsOsName
,
"Windows"
);
printf
(
WINCLIENT_VERSION
,
tsOsName
,
taos_get_client_info
());
if
(
strlen
(
argv
[
i
])
==
2
)
{
if
((
strlen
(
argv
[
i
])
==
2
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
printf
(
"Enter password: "
);
taosSetConsoleEcho
(
false
);
if
(
scanf
(
"%s"
,
g_password
)
>
1
)
{
fprintf
(
stderr
,
"password read error!
\n
"
);
}
taosSetConsoleEcho
(
true
);
getchar
();
}
else
{
tstrncpy
(
g_password
,
(
char
*
)(
argv
[
i
]
+
2
),
MAX_PASSWORD_SIZE
);
tstrncpy
(
g_password
,
(
char
*
)(
argv
[
i
]
+
2
),
SHELL_MAX_PASSWORD_LEN
);
}
arguments
->
password
=
g_password
;
strcpy
(
argv
[
i
],
""
);
argc
-=
1
;
}
// for management port
else
if
(
strcmp
(
argv
[
i
],
"-P"
)
==
0
)
{
...
...
src/kit/taosdemo/taosdemo.c
浏览文件 @
cbfe680f
...
...
@@ -53,14 +53,6 @@
#include "taoserror.h"
#include "tutil.h"
#define STMT_IFACE_ENABLED 1
#define NANO_SECOND_ENABLED 1
#define SET_THREADNAME_ENABLED 1
#if SET_THREADNAME_ENABLED == 0
#define setThreadName(name)
#endif
#define REQ_EXTRA_BUF_LEN 1024
#define RESP_BUF_LEN 4096
...
...
@@ -77,7 +69,6 @@ extern char configDir[];
#define COL_BUFFER_LEN ((TSDB_COL_NAME_LEN + 15) * TSDB_MAX_COLUMNS)
#define MAX_USERNAME_SIZE 64
#define MAX_PASSWORD_SIZE 16
#define MAX_HOSTNAME_SIZE 253 // https://man7.org/linux/man-pages/man7/hostname.7.html
#define MAX_TB_NAME_SIZE 64
#define MAX_DATA_SIZE (16*TSDB_MAX_COLUMNS)+20 // max record len: 16*MAX_COLUMNS, timestamp string and ,('') need extra space
...
...
@@ -216,7 +207,7 @@ typedef struct SArguments_S {
uint16_t
port
;
uint16_t
iface
;
char
*
user
;
char
password
[
MAX_PASSWORD_SIZE
];
char
password
[
SHELL_MAX_PASSWORD_LEN
];
char
*
database
;
int
replica
;
char
*
tb_prefix
;
...
...
@@ -295,9 +286,7 @@ typedef struct SSuperTable_S {
uint64_t
lenOfTagOfOneRow
;
char
*
sampleDataBuf
;
#if STMT_IFACE_ENABLED == 1
char
*
sampleBindArray
;
#endif
//int sampleRowCount;
//int sampleUsePos;
...
...
@@ -366,7 +355,7 @@ typedef struct SDbs_S {
uint16_t
port
;
char
user
[
MAX_USERNAME_SIZE
];
char
password
[
MAX_PASSWORD_SIZE
];
char
password
[
SHELL_MAX_PASSWORD_LEN
];
char
resultFile
[
MAX_FILE_NAME_LEN
];
bool
use_metric
;
bool
insert_only
;
...
...
@@ -432,7 +421,7 @@ typedef struct SQueryMetaInfo_S {
uint16_t
port
;
struct
sockaddr_in
serv_addr
;
char
user
[
MAX_USERNAME_SIZE
];
char
password
[
MAX_PASSWORD_SIZE
];
char
password
[
SHELL_MAX_PASSWORD_LEN
];
char
dbName
[
TSDB_DB_NAME_LEN
];
char
queryMode
[
SMALL_BUFF_LEN
];
// taosc, rest
...
...
@@ -670,7 +659,21 @@ static FILE * g_fpOfInsertResult = NULL;
fprintf(stderr, "PERF: "fmt, __VA_ARGS__); } while(0)
#define errorPrint(fmt, ...) \
do { fprintf(stderr, " \033[31m"); fprintf(stderr, "ERROR: "fmt, __VA_ARGS__); fprintf(stderr, " \033[0m"); } while(0)
do {\
struct tm Tm, *ptm;\
struct timeval timeSecs; \
time_t curTime;\
gettimeofday(&timeSecs, NULL); \
curTime = timeSecs.tv_sec;\
ptm = localtime_r(&curTime, &Tm);\
fprintf(stderr, " \033[31m");\
fprintf(stderr, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " ",\
ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,\
ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec,\
taosGetSelfPthreadId());\
fprintf(stderr, "ERROR: "fmt, __VA_ARGS__);\
fprintf(stderr, " \033[0m");\
} while(0)
// for strncpy buffer overflow
#define min(a, b) (((a) < (b)) ? (a) : (b))
...
...
@@ -733,11 +736,7 @@ static void printHelp() {
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-P"
,
indent
,
"The TCP/IP port number to use for the connection. Default is 0."
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-I"
,
indent
,
#if STMT_IFACE_ENABLED == 1
"The interface (taosc, rest, and stmt) taosdemo uses. Default is 'taosc'."
);
#else
"The interface (taosc, rest) taosdemo uses. Default is 'taosc'."
);
#endif
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-d"
,
indent
,
"Destination database. Default is 'test'."
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-a"
,
indent
,
...
...
@@ -752,12 +751,13 @@ static void printHelp() {
"Query mode -- 0: SYNC, 1: ASYNC. Default is SYNC."
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-b"
,
indent
,
"The data_type of columns, default: FLOAT, INT, FLOAT."
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-w"
,
indent
,
"The length of data_type 'BINARY' or 'NCHAR'. Default is 16"
);
printf
(
"%s%s%s%s%d
\n
"
,
indent
,
"-w"
,
indent
,
"The length of data_type 'BINARY' or 'NCHAR'. Default is "
,
g_args
.
len_of_binary
);
printf
(
"%s%s%s%s%d%s%d
\n
"
,
indent
,
"-l"
,
indent
,
"The number of columns per record. Default is "
,
"The number of columns per record. De
mo mode by de
fault is "
,
DEFAULT_DATATYPE_NUM
,
". Max values is "
,
"
(float, int, float)
. Max values is "
,
MAX_NUM_COLUMNS
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
indent
,
indent
,
"All of the new column(s) type is INT. If use -b to specify column type, -l will be ignored."
);
...
...
@@ -849,10 +849,8 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
arguments
->
iface
=
TAOSC_IFACE
;
}
else
if
(
0
==
strcasecmp
(
argv
[
i
],
"rest"
))
{
arguments
->
iface
=
REST_IFACE
;
#if STMT_IFACE_ENABLED == 1
}
else
if
(
0
==
strcasecmp
(
argv
[
i
],
"stmt"
))
{
arguments
->
iface
=
STMT_IFACE
;
#endif
}
else
{
errorPrint
(
"%s"
,
"
\n\t
-I need a valid string following!
\n
"
);
exit
(
EXIT_FAILURE
);
...
...
@@ -873,7 +871,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
}
taosSetConsoleEcho
(
true
);
}
else
{
tstrncpy
(
arguments
->
password
,
(
char
*
)(
argv
[
i
]
+
2
),
MAX_PASSWORD_SIZE
);
tstrncpy
(
arguments
->
password
,
(
char
*
)(
argv
[
i
]
+
2
),
SHELL_MAX_PASSWORD_LEN
);
}
}
else
if
(
strcmp
(
argv
[
i
],
"-o"
)
==
0
)
{
if
(
argc
==
i
+
1
)
{
...
...
@@ -1694,9 +1692,7 @@ static int printfInsertMeta() {
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
[
0
]
!=
0
)
{
if
((
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"ms"
,
2
))
#if NANO_SECOND_ENABLED == 1
||
(
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"us"
,
2
))
#endif
||
(
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"ns"
,
2
)))
{
printf
(
" precision:
\033
[33m%s
\033
[0m
\n
"
,
g_Dbs
.
db
[
i
].
dbCfg
.
precision
);
...
...
@@ -1887,9 +1883,7 @@ static void printfInsertMetaToFile(FILE* fp) {
}
if
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
[
0
]
!=
0
)
{
if
((
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"ms"
,
2
))
#if NANO_SECOND_ENABLED == 1
||
(
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"ns"
,
2
))
#endif
||
(
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"us"
,
2
)))
{
fprintf
(
fp
,
" precision: %s
\n
"
,
g_Dbs
.
db
[
i
].
dbCfg
.
precision
);
...
...
@@ -2092,10 +2086,8 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
time_t
tt
;
if
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
tt
=
(
time_t
)(
val
/
1000000
);
#if NANO_SECOND_ENABLED == 1
}
if
(
precision
==
TSDB_TIME_PRECISION_NANO
)
{
tt
=
(
time_t
)(
val
/
1000000000
);
#endif
}
else
{
tt
=
(
time_t
)(
val
/
1000
);
}
...
...
@@ -2117,10 +2109,8 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
if
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
sprintf
(
buf
+
pos
,
".%06d"
,
(
int
)(
val
%
1000000
));
#if NANO_SECOND_ENABLED == 1
}
else
if
(
precision
==
TSDB_TIME_PRECISION_NANO
)
{
sprintf
(
buf
+
pos
,
".%09d"
,
(
int
)(
val
%
1000000000
));
#endif
}
else
{
sprintf
(
buf
+
pos
,
".%03d"
,
(
int
)(
val
%
1000
));
}
...
...
@@ -3181,10 +3171,8 @@ int createDatabasesAndStables(char *command) {
" fsync %d"
,
g_Dbs
.
db
[
i
].
dbCfg
.
fsync
);
}
if
((
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"ms"
,
2
))
#if NANO_SECOND_ENABLED == 1
||
(
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"ns"
,
2
))
#endif
||
(
0
==
strncasecmp
(
g_Dbs
.
db
[
i
].
dbCfg
.
precision
,
"us"
,
2
)))
{
dataLen
+=
snprintf
(
command
+
dataLen
,
BUFFER_SIZE
-
dataLen
,
...
...
@@ -3805,9 +3793,9 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
cJSON
*
password
=
cJSON_GetObjectItem
(
root
,
"password"
);
if
(
password
&&
password
->
type
==
cJSON_String
&&
password
->
valuestring
!=
NULL
)
{
tstrncpy
(
g_Dbs
.
password
,
password
->
valuestring
,
MAX_PASSWORD_SIZE
);
tstrncpy
(
g_Dbs
.
password
,
password
->
valuestring
,
SHELL_MAX_PASSWORD_LEN
);
}
else
if
(
!
password
)
{
tstrncpy
(
g_Dbs
.
password
,
"taosdata"
,
MAX_PASSWORD_SIZE
);
tstrncpy
(
g_Dbs
.
password
,
"taosdata"
,
SHELL_MAX_PASSWORD_LEN
);
}
cJSON
*
resultfile
=
cJSON_GetObjectItem
(
root
,
"result_file"
);
...
...
@@ -4263,10 +4251,8 @@ static bool getMetaFromInsertJsonFile(cJSON* root) {
g_Dbs
.
db
[
i
].
superTbls
[
j
].
iface
=
TAOSC_IFACE
;
}
else
if
(
0
==
strcasecmp
(
stbIface
->
valuestring
,
"rest"
))
{
g_Dbs
.
db
[
i
].
superTbls
[
j
].
iface
=
REST_IFACE
;
#if STMT_IFACE_ENABLED == 1
}
else
if
(
0
==
strcasecmp
(
stbIface
->
valuestring
,
"stmt"
))
{
g_Dbs
.
db
[
i
].
superTbls
[
j
].
iface
=
STMT_IFACE
;
#endif
}
else
{
errorPrint
(
"%s() LN%d, failed to read json, insert_mode %s not recognized
\n
"
,
__func__
,
__LINE__
,
stbIface
->
valuestring
);
...
...
@@ -4543,9 +4529,9 @@ static bool getMetaFromQueryJsonFile(cJSON* root) {
cJSON
*
password
=
cJSON_GetObjectItem
(
root
,
"password"
);
if
(
password
&&
password
->
type
==
cJSON_String
&&
password
->
valuestring
!=
NULL
)
{
tstrncpy
(
g_queryInfo
.
password
,
password
->
valuestring
,
MAX_PASSWORD_SIZE
);
tstrncpy
(
g_queryInfo
.
password
,
password
->
valuestring
,
SHELL_MAX_PASSWORD_LEN
);
}
else
if
(
!
password
)
{
tstrncpy
(
g_queryInfo
.
password
,
"taosdata"
,
MAX_PASSWORD_SIZE
);;
tstrncpy
(
g_queryInfo
.
password
,
"taosdata"
,
SHELL_MAX_PASSWORD_LEN
);;
}
cJSON
*
answerPrompt
=
cJSON_GetObjectItem
(
root
,
"confirm_parameter_prompt"
);
// yes, no,
...
...
@@ -5075,7 +5061,6 @@ static void postFreeResource() {
free
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
sampleDataBuf
);
g_Dbs
.
db
[
i
].
superTbls
[
j
].
sampleDataBuf
=
NULL
;
}
#if STMT_IFACE_ENABLED == 1
if
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
sampleBindArray
)
{
for
(
int
k
=
0
;
k
<
MAX_SAMPLES_ONCE_FROM_FILE
;
k
++
)
{
uintptr_t
*
tmp
=
(
uintptr_t
*
)(
*
(
uintptr_t
*
)(
...
...
@@ -5090,7 +5075,6 @@ static void postFreeResource() {
}
}
tmfree
((
char
*
)
g_Dbs
.
db
[
i
].
superTbls
[
j
].
sampleBindArray
);
#endif
if
(
0
!=
g_Dbs
.
db
[
i
].
superTbls
[
j
].
tagDataBuf
)
{
free
(
g_Dbs
.
db
[
i
].
superTbls
[
j
].
tagDataBuf
);
...
...
@@ -5232,7 +5216,8 @@ static int64_t generateStbRowData(
tmpLen
=
strlen
(
tmp
);
tstrncpy
(
pstr
+
dataLen
,
tmp
,
min
(
tmpLen
+
1
,
INT_BUFF_LEN
));
}
else
{
errorPrint
(
"Not support data type: %s
\n
"
,
stbInfo
->
columns
[
i
].
dataType
);
errorPrint
(
"Not support data type: %s
\n
"
,
stbInfo
->
columns
[
i
].
dataType
);
return
-
1
;
}
...
...
@@ -5245,8 +5230,7 @@ static int64_t generateStbRowData(
return
0
;
}
dataLen
-=
1
;
dataLen
+=
snprintf
(
pstr
+
dataLen
,
maxLen
-
dataLen
,
")"
);
tstrncpy
(
pstr
+
dataLen
-
1
,
")"
,
2
);
verbosePrint
(
"%s() LN%d, dataLen:%"
PRId64
"
\n
"
,
__func__
,
__LINE__
,
dataLen
);
verbosePrint
(
"%s() LN%d, recBuf:
\n\t
%s
\n
"
,
__func__
,
__LINE__
,
recBuf
);
...
...
@@ -5383,7 +5367,6 @@ static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k)
}
break
;
#if STMT_IFACE_ENABLED == 1
case
STMT_IFACE
:
debugPrint
(
"%s() LN%d, stmt=%p"
,
__func__
,
__LINE__
,
pThreadInfo
->
stmt
);
...
...
@@ -5396,7 +5379,6 @@ static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k)
}
affectedRows
=
k
;
break
;
#endif
default:
errorPrint
(
"%s() LN%d: unknown insert mode: %d
\n
"
,
...
...
@@ -5769,7 +5751,6 @@ static int64_t generateInterlaceDataWithoutStb(
return
k
;
}
#if STMT_IFACE_ENABLED == 1
static
int32_t
prepareStmtBindArrayByType
(
TAOS_BIND
*
bind
,
char
*
dataType
,
int32_t
dataLen
,
...
...
@@ -6604,7 +6585,6 @@ static int32_t prepareStbStmtWithSample(
return
k
;
}
#endif
static
int32_t
generateStbProgressiveData
(
SSuperTable
*
stbInfo
,
...
...
@@ -6805,7 +6785,6 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) {
int32_t
generated
;
if
(
stbInfo
)
{
if
(
stbInfo
->
iface
==
STMT_IFACE
)
{
#if STMT_IFACE_ENABLED == 1
if
(
sourceRand
)
{
generated
=
prepareStbStmtRand
(
pThreadInfo
,
...
...
@@ -6825,9 +6804,6 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) {
startTime
,
&
(
pThreadInfo
->
samplePos
));
}
#else
generated
=
-
1
;
#endif
}
else
{
generated
=
generateStbInterlaceData
(
pThreadInfo
,
...
...
@@ -6845,16 +6821,12 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) {
pThreadInfo
->
threadID
,
__func__
,
__LINE__
,
tableName
,
batchPerTbl
,
startTime
);
#if STMT_IFACE_ENABLED == 1
generated
=
prepareStmtWithoutStb
(
pThreadInfo
,
tableName
,
batchPerTbl
,
insertRows
,
i
,
startTime
);
#else
generated
=
-
1
;
#endif
}
else
{
generated
=
generateInterlaceDataWithoutStb
(
tableName
,
batchPerTbl
,
...
...
@@ -7067,7 +7039,6 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) {
int32_t
generated
;
if
(
stbInfo
)
{
if
(
stbInfo
->
iface
==
STMT_IFACE
)
{
#if STMT_IFACE_ENABLED == 1
if
(
sourceRand
)
{
generated
=
prepareStbStmtRand
(
pThreadInfo
,
...
...
@@ -7086,9 +7057,6 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) {
insertRows
,
i
,
start_time
,
&
(
pThreadInfo
->
samplePos
));
}
#else
generated
=
-
1
;
#endif
}
else
{
generated
=
generateStbProgressiveData
(
stbInfo
,
...
...
@@ -7100,16 +7068,12 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) {
}
}
else
{
if
(
g_args
.
iface
==
STMT_IFACE
)
{
#if STMT_IFACE_ENABLED == 1
generated
=
prepareStmtWithoutStb
(
pThreadInfo
,
tableName
,
g_args
.
num_of_RPR
,
insertRows
,
i
,
start_time
);
#else
generated
=
-
1
;
#endif
}
else
{
generated
=
generateProgressiveDataWithoutStb
(
tableName
,
...
...
@@ -7329,7 +7293,6 @@ static int convertHostToServAddr(char *host, uint16_t port, struct sockaddr_in *
return
0
;
}
#if STMT_IFACE_ENABLED == 1
static
int
parseSampleFileToStmt
(
SSuperTable
*
stbInfo
,
uint32_t
timePrec
)
{
stbInfo
->
sampleBindArray
=
calloc
(
1
,
sizeof
(
char
*
)
*
MAX_SAMPLES_ONCE_FROM_FILE
);
...
...
@@ -7400,7 +7363,6 @@ static int parseSampleFileToStmt(SSuperTable *stbInfo, uint32_t timePrec)
return
0
;
}
#endif
static
void
startMultiThreadInsertData
(
int
threads
,
char
*
db_name
,
char
*
precision
,
SSuperTable
*
stbInfo
)
{
...
...
@@ -7411,10 +7373,8 @@ static void startMultiThreadInsertData(int threads, char* db_name,
timePrec
=
TSDB_TIME_PRECISION_MILLI
;
}
else
if
(
0
==
strncasecmp
(
precision
,
"us"
,
2
))
{
timePrec
=
TSDB_TIME_PRECISION_MICRO
;
#if NANO_SECOND_ENABLED == 1
}
else
if
(
0
==
strncasecmp
(
precision
,
"ns"
,
2
))
{
timePrec
=
TSDB_TIME_PRECISION_NANO
;
#endif
}
else
{
errorPrint
(
"Not support precision: %s
\n
"
,
precision
);
exit
(
EXIT_FAILURE
);
...
...
@@ -7557,7 +7517,6 @@ static void startMultiThreadInsertData(int threads, char* db_name,
memset
(
pids
,
0
,
threads
*
sizeof
(
pthread_t
));
memset
(
infos
,
0
,
threads
*
sizeof
(
threadInfo
));
#if STMT_IFACE_ENABLED == 1
char
*
stmtBuffer
=
calloc
(
1
,
BUFFER_SIZE
);
assert
(
stmtBuffer
);
if
((
g_args
.
iface
==
STMT_IFACE
)
...
...
@@ -7598,7 +7557,6 @@ static void startMultiThreadInsertData(int threads, char* db_name,
parseSampleFileToStmt
(
stbInfo
,
timePrec
);
}
}
#endif
for
(
int
i
=
0
;
i
<
threads
;
i
++
)
{
threadInfo
*
pThreadInfo
=
infos
+
i
;
...
...
@@ -7626,7 +7584,6 @@ static void startMultiThreadInsertData(int threads, char* db_name,
exit
(
EXIT_FAILURE
);
}
#if STMT_IFACE_ENABLED == 1
if
((
g_args
.
iface
==
STMT_IFACE
)
||
((
stbInfo
)
&&
(
stbInfo
->
iface
==
STMT_IFACE
)))
{
...
...
@@ -7654,7 +7611,6 @@ static void startMultiThreadInsertData(int threads, char* db_name,
}
pThreadInfo
->
bind_ts
=
malloc
(
sizeof
(
int64_t
));
}
#endif
}
else
{
pThreadInfo
->
taos
=
NULL
;
}
...
...
@@ -7680,9 +7636,7 @@ static void startMultiThreadInsertData(int threads, char* db_name,
}
}
#if STMT_IFACE_ENABLED == 1
free
(
stmtBuffer
);
#endif
for
(
int
i
=
0
;
i
<
threads
;
i
++
)
{
pthread_join
(
pids
[
i
],
NULL
);
...
...
@@ -7697,12 +7651,10 @@ static void startMultiThreadInsertData(int threads, char* db_name,
for
(
int
i
=
0
;
i
<
threads
;
i
++
)
{
threadInfo
*
pThreadInfo
=
infos
+
i
;
#if STMT_IFACE_ENABLED == 1
if
(
pThreadInfo
->
stmt
)
{
taos_stmt_close
(
pThreadInfo
->
stmt
);
tmfree
((
char
*
)
pThreadInfo
->
bind_ts
);
}
#endif
tsem_destroy
(
&
(
pThreadInfo
->
lock_sem
));
taos_close
(
pThreadInfo
->
taos
);
...
...
@@ -8887,7 +8839,7 @@ static void initOfInsertMeta() {
tstrncpy
(
g_Dbs
.
host
,
"127.0.0.1"
,
MAX_HOSTNAME_SIZE
);
g_Dbs
.
port
=
6030
;
tstrncpy
(
g_Dbs
.
user
,
TSDB_DEFAULT_USER
,
MAX_USERNAME_SIZE
);
tstrncpy
(
g_Dbs
.
password
,
TSDB_DEFAULT_PASS
,
MAX_PASSWORD_SIZE
);
tstrncpy
(
g_Dbs
.
password
,
TSDB_DEFAULT_PASS
,
SHELL_MAX_PASSWORD_LEN
);
g_Dbs
.
threadCount
=
2
;
g_Dbs
.
use_metric
=
g_args
.
use_metric
;
...
...
@@ -8900,7 +8852,7 @@ static void initOfQueryMeta() {
tstrncpy
(
g_queryInfo
.
host
,
"127.0.0.1"
,
MAX_HOSTNAME_SIZE
);
g_queryInfo
.
port
=
6030
;
tstrncpy
(
g_queryInfo
.
user
,
TSDB_DEFAULT_USER
,
MAX_USERNAME_SIZE
);
tstrncpy
(
g_queryInfo
.
password
,
TSDB_DEFAULT_PASS
,
MAX_PASSWORD_SIZE
);
tstrncpy
(
g_queryInfo
.
password
,
TSDB_DEFAULT_PASS
,
SHELL_MAX_PASSWORD_LEN
);
}
static
void
setParaFromArg
()
{
...
...
@@ -8914,7 +8866,7 @@ static void setParaFromArg() {
tstrncpy
(
g_Dbs
.
user
,
g_args
.
user
,
MAX_USERNAME_SIZE
);
}
tstrncpy
(
g_Dbs
.
password
,
g_args
.
password
,
MAX_PASSWORD_SIZE
);
tstrncpy
(
g_Dbs
.
password
,
g_args
.
password
,
SHELL_MAX_PASSWORD_LEN
);
if
(
g_args
.
port
)
{
g_Dbs
.
port
=
g_args
.
port
;
...
...
src/kit/taosdump/taosdump.c
浏览文件 @
cbfe680f
...
...
@@ -62,6 +62,20 @@ typedef struct {
#define errorPrint(fmt, ...) \
do { fprintf(stderr, "\033[31m"); fprintf(stderr, "ERROR: "fmt, __VA_ARGS__); fprintf(stderr, "\033[0m"); } while(0)
static
bool
isStringNumber
(
char
*
input
)
{
int
len
=
strlen
(
input
);
if
(
0
==
len
)
{
return
false
;
}
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
if
(
!
isdigit
(
input
[
i
]))
return
false
;
}
return
true
;
}
// -------------------------- SHOW DATABASE INTERFACE-----------------------
enum
_show_db_index
{
...
...
@@ -243,19 +257,15 @@ static struct argp_option options[] = {
{
"table-batch"
,
't'
,
"TABLE_BATCH"
,
0
,
"Number of table dumpout into one output file. Default is 1."
,
3
},
{
"thread_num"
,
'T'
,
"THREAD_NUM"
,
0
,
"Number of thread for dump in file. Default is 5."
,
3
},
{
"debug"
,
'g'
,
0
,
0
,
"Print debug info."
,
8
},
{
"verbose"
,
'b'
,
0
,
0
,
"Print verbose debug info."
,
9
},
{
"performanceprint"
,
'm'
,
0
,
0
,
"Print performance debug info."
,
10
},
{
0
}
};
#define MAX_PASSWORD_SIZE 20
/* Used by main to communicate with parse_opt. */
typedef
struct
arguments
{
// connection option
char
*
host
;
char
*
user
;
char
password
[
MAX_PASSWORD_SIZE
];
char
password
[
SHELL_MAX_PASSWORD_LEN
];
uint16_t
port
;
char
cversion
[
12
];
uint16_t
mysqlFlag
;
...
...
@@ -432,7 +442,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
break
;
// dump unit option
case
'A'
:
g_args
.
all_databases
=
true
;
break
;
case
'D'
:
g_args
.
databases
=
true
;
...
...
@@ -477,6 +486,10 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
g_args
.
table_batch
=
atoi
(
arg
);
break
;
case
'T'
:
if
(
!
isStringNumber
(
arg
))
{
errorPrint
(
"%s"
,
"
\n\t
-T need a number following!
\n
"
);
exit
(
EXIT_FAILURE
);
}
g_args
.
thread_num
=
atoi
(
arg
);
break
;
case
OPT_ABORT
:
...
...
@@ -555,11 +568,14 @@ static void parse_precision_first(
}
}
static
void
parse_
password
(
static
void
parse_
args
(
int
argc
,
char
*
argv
[],
SArguments
*
arguments
)
{
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
if
(
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
{
if
(
strlen
(
argv
[
i
])
==
2
)
{
if
((
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
if
((
strlen
(
argv
[
i
])
==
2
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
printf
(
"Enter password: "
);
taosSetConsoleEcho
(
false
);
if
(
scanf
(
"%20s"
,
arguments
->
password
)
>
1
)
{
...
...
@@ -567,10 +583,22 @@ static void parse_password(
}
taosSetConsoleEcho
(
true
);
}
else
{
tstrncpy
(
arguments
->
password
,
(
char
*
)(
argv
[
i
]
+
2
),
MAX_PASSWORD_SIZE
);
tstrncpy
(
arguments
->
password
,
(
char
*
)(
argv
[
i
]
+
2
),
SHELL_MAX_PASSWORD_LEN
);
strcpy
(
argv
[
i
],
"-p"
);
}
argv
[
i
]
=
""
;
}
else
if
(
strcmp
(
argv
[
i
],
"-gg"
)
==
0
)
{
arguments
->
verbose_print
=
true
;
strcpy
(
argv
[
i
],
""
);
}
else
if
(
strcmp
(
argv
[
i
],
"-PP"
)
==
0
)
{
arguments
->
performance_print
=
true
;
strcpy
(
argv
[
i
],
""
);
}
else
if
(
strcmp
(
argv
[
i
],
"-A"
)
==
0
)
{
g_args
.
all_databases
=
true
;
}
else
{
continue
;
}
}
}
...
...
@@ -639,7 +667,7 @@ int main(int argc, char *argv[]) {
if
(
argc
>
1
)
{
parse_precision_first
(
argc
,
argv
,
&
g_args
);
parse_timestamp
(
argc
,
argv
,
&
g_args
);
parse_
password
(
argc
,
argv
,
&
g_args
);
parse_
args
(
argc
,
argv
,
&
g_args
);
}
argp_parse
(
&
argp
,
argc
,
argv
,
0
,
0
,
&
g_args
);
...
...
src/os/src/linux/osSystem.c
浏览文件 @
cbfe680f
...
...
@@ -63,12 +63,12 @@ int taosSetConsoleEcho(bool on)
}
if
(
on
)
term
.
c_lflag
|=
ECHOFLAGS
;
term
.
c_lflag
|=
ECHOFLAGS
;
else
term
.
c_lflag
&=~
ECHOFLAGS
;
term
.
c_lflag
&=
~
ECHOFLAGS
;
err
=
tcsetattr
(
STDIN_FILENO
,
TCSAFLUSH
,
&
term
);
if
(
err
==
-
1
&&
err
==
EINTR
)
{
err
=
tcsetattr
(
STDIN_FILENO
,
TCSAFLUSH
,
&
term
);
if
(
err
==
-
1
||
err
==
EINTR
)
{
perror
(
"Cannot set the attribution of the terminal"
);
return
-
1
;
}
...
...
src/query/inc/qExecutor.h
浏览文件 @
cbfe680f
...
...
@@ -597,6 +597,8 @@ bool doFilterDataBlock(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilter
void
doCompactSDataBlock
(
SSDataBlock
*
pBlock
,
int32_t
numOfRows
,
int8_t
*
p
);
SSDataBlock
*
createOutputBuf
(
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
numOfRows
);
void
copyTsColoum
(
SSDataBlock
*
pRes
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
);
void
*
destroyOutputBuf
(
SSDataBlock
*
pBlock
);
void
*
doDestroyFilterInfo
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
);
...
...
src/query/src/qExecutor.c
浏览文件 @
cbfe680f
...
...
@@ -3616,7 +3616,7 @@ void setDefaultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *pInfo, i
// set the timestamp output buffer for top/bottom/diff query
int32_t
fid
=
pCtx
[
i
].
functionId
;
if
(
fid
==
TSDB_FUNC_TOP
||
fid
==
TSDB_FUNC_BOTTOM
||
fid
==
TSDB_FUNC_DIFF
||
fid
==
TSDB_FUNC_DERIVATIVE
)
{
pCtx
[
i
].
ptsOutputBuf
=
pCtx
[
0
].
pOutput
;
if
(
i
>
0
)
pCtx
[
i
].
ptsOutputBuf
=
pCtx
[
i
-
1
].
pOutput
;
}
}
...
...
@@ -3651,7 +3651,37 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf
// re-estabilish output buffer pointer.
int32_t
functionId
=
pBInfo
->
pCtx
[
i
].
functionId
;
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
||
functionId
==
TSDB_FUNC_DIFF
||
functionId
==
TSDB_FUNC_DERIVATIVE
)
{
pBInfo
->
pCtx
[
i
].
ptsOutputBuf
=
pBInfo
->
pCtx
[
i
-
1
].
pOutput
;
if
(
i
>
0
)
pBInfo
->
pCtx
[
i
].
ptsOutputBuf
=
pBInfo
->
pCtx
[
i
-
1
].
pOutput
;
}
}
}
void
copyTsColoum
(
SSDataBlock
*
pRes
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
bool
needCopyTs
=
false
;
int32_t
tsNum
=
0
;
char
*
src
=
NULL
;
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
i
++
)
{
int32_t
functionId
=
pCtx
[
i
].
functionId
;
if
(
functionId
==
TSDB_FUNC_DIFF
||
functionId
==
TSDB_FUNC_DERIVATIVE
)
{
needCopyTs
=
true
;
if
(
i
>
0
&&
pCtx
[
i
-
1
].
functionId
==
TSDB_FUNC_TS_DUMMY
){
SColumnInfoData
*
pColRes
=
taosArrayGet
(
pRes
->
pDataBlock
,
i
-
1
);
// find ts data
src
=
pColRes
->
pData
;
}
}
else
if
(
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
tsNum
++
;
}
}
if
(
!
needCopyTs
)
return
;
if
(
tsNum
<
2
)
return
;
if
(
src
==
NULL
)
return
;
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
i
++
)
{
int32_t
functionId
=
pCtx
[
i
].
functionId
;
if
(
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
SColumnInfoData
*
pColRes
=
taosArrayGet
(
pRes
->
pDataBlock
,
i
);
memcpy
(
pColRes
->
pData
,
src
,
pColRes
->
info
.
bytes
*
pRes
->
info
.
rows
);
}
}
}
...
...
@@ -3851,7 +3881,7 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
}
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
||
functionId
==
TSDB_FUNC_DIFF
)
{
pCtx
[
i
].
ptsOutputBuf
=
pCtx
[
0
].
pOutput
;
if
(
i
>
0
)
pCtx
[
i
].
ptsOutputBuf
=
pCtx
[
i
-
1
].
pOutput
;
}
if
(
!
pResInfo
->
initialized
)
{
...
...
@@ -3912,7 +3942,7 @@ void setResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResult, SQLF
int32_t
functionId
=
pCtx
[
i
].
functionId
;
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
||
functionId
==
TSDB_FUNC_DIFF
||
functionId
==
TSDB_FUNC_DERIVATIVE
)
{
pCtx
[
i
].
ptsOutputBuf
=
pCtx
[
0
].
pOutput
;
if
(
i
>
0
)
pCtx
[
i
].
ptsOutputBuf
=
pCtx
[
i
-
1
].
pOutput
;
}
/*
...
...
@@ -5698,6 +5728,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
pRes
->
info
.
rows
=
getNumOfResult
(
pRuntimeEnv
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
if
(
pRes
->
info
.
rows
>=
pRuntimeEnv
->
resultInfo
.
threshold
)
{
copyTsColoum
(
pRes
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
clearNumOfRes
(
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
return
pRes
;
}
...
...
@@ -5723,8 +5754,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
if
(
*
newgroup
)
{
if
(
pRes
->
info
.
rows
>
0
)
{
pProjectInfo
->
existDataBlock
=
pBlock
;
clearNumOfRes
(
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
return
pInfo
->
pRes
;
break
;
}
else
{
// init output buffer for a new group data
for
(
int32_t
j
=
0
;
j
<
pOperator
->
numOfOutput
;
++
j
)
{
aAggs
[
pInfo
->
pCtx
[
j
].
functionId
].
xFinalize
(
&
pInfo
->
pCtx
[
j
]);
...
...
@@ -5754,7 +5784,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
break
;
}
}
copyTsColoum
(
pRes
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
clearNumOfRes
(
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
return
(
pInfo
->
pRes
->
info
.
rows
>
0
)
?
pInfo
->
pRes
:
NULL
;
}
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
cbfe680f
...
...
@@ -1250,8 +1250,14 @@ static int tsdbEncodeTable(void **buf, STable *pTable) {
tlen
+=
taosEncodeFixedU64
(
buf
,
TABLE_SUID
(
pTable
));
tlen
+=
tdEncodeKVRow
(
buf
,
pTable
->
tagVal
);
}
else
{
tlen
+=
taosEncodeFixedU8
(
buf
,
(
uint8_t
)
taosArrayGetSize
(
pTable
->
schema
));
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
pTable
->
schema
);
i
++
)
{
uint32_t
arraySize
=
(
uint32_t
)
taosArrayGetSize
(
pTable
->
schema
);
if
(
arraySize
>
UINT8_MAX
)
{
tlen
+=
taosEncodeFixedU8
(
buf
,
0
);
tlen
+=
taosEncodeFixedU32
(
buf
,
arraySize
);
}
else
{
tlen
+=
taosEncodeFixedU8
(
buf
,
(
uint8_t
)
arraySize
);
}
for
(
uint32_t
i
=
0
;
i
<
arraySize
;
i
++
)
{
STSchema
*
pSchema
=
taosArrayGetP
(
pTable
->
schema
,
i
);
tlen
+=
tdEncodeSchema
(
buf
,
pSchema
);
}
...
...
@@ -1284,8 +1290,11 @@ static void *tsdbDecodeTable(void *buf, STable **pRTable) {
buf
=
taosDecodeFixedU64
(
buf
,
&
TABLE_SUID
(
pTable
));
buf
=
tdDecodeKVRow
(
buf
,
&
(
pTable
->
tagVal
));
}
else
{
uint8_t
nSchemas
;
buf
=
taosDecodeFixedU8
(
buf
,
&
nSchemas
);
uint32_t
nSchemas
=
0
;
buf
=
taosDecodeFixedU8
(
buf
,
(
uint8_t
*
)
&
nSchemas
);
if
(
nSchemas
==
0
)
{
buf
=
taosDecodeFixedU32
(
buf
,
&
nSchemas
);
}
for
(
int
i
=
0
;
i
<
nSchemas
;
i
++
)
{
STSchema
*
pSchema
;
buf
=
tdDecodeSchema
(
buf
,
&
pSchema
);
...
...
@@ -1485,4 +1494,4 @@ static void tsdbFreeTableSchema(STable *pTable) {
taosArrayDestroy
(
pTable
->
schema
);
}
}
\ No newline at end of file
}
tests/pytest/functions/function_bottom.py
浏览文件 @
cbfe680f
...
...
@@ -104,6 +104,21 @@ class TDTestCase:
tdSql
.
checkRows
(
2
)
tdSql
.
checkData
(
0
,
1
,
1
)
tdSql
.
checkData
(
1
,
1
,
2
)
tdSql
.
query
(
"select ts,bottom(col1, 2),ts from test1"
)
tdSql
.
checkRows
(
2
)
tdSql
.
checkData
(
0
,
0
,
"2018-09-17 09:00:00.000"
)
tdSql
.
checkData
(
0
,
1
,
"2018-09-17 09:00:00.000"
)
tdSql
.
checkData
(
1
,
0
,
"2018-09-17 09:00:00.001"
)
tdSql
.
checkData
(
1
,
3
,
"2018-09-17 09:00:00.001"
)
tdSql
.
query
(
"select ts,bottom(col1, 2),ts from test group by tbname"
)
tdSql
.
checkRows
(
2
)
tdSql
.
checkData
(
0
,
0
,
"2018-09-17 09:00:00.000"
)
tdSql
.
checkData
(
0
,
1
,
"2018-09-17 09:00:00.000"
)
tdSql
.
checkData
(
1
,
0
,
"2018-09-17 09:00:00.001"
)
tdSql
.
checkData
(
1
,
3
,
"2018-09-17 09:00:00.001"
)
#TD-2457 bottom + interval + order by
tdSql
.
error
(
'select top(col2,1) from test interval(1y) order by col2;'
)
...
...
tests/pytest/functions/function_derivative.py
浏览文件 @
cbfe680f
...
...
@@ -54,6 +54,28 @@ class TDTestCase:
tdSql
.
query
(
"select derivative(col, 10s, 0) from stb group by tbname"
)
tdSql
.
checkRows
(
10
)
tdSql
.
query
(
"select ts,derivative(col, 10s, 1),ts from stb group by tbname"
)
tdSql
.
checkRows
(
4
)
tdSql
.
checkData
(
0
,
0
,
"2018-09-17 09:00:10.000"
)
tdSql
.
checkData
(
0
,
1
,
"2018-09-17 09:00:10.000"
)
tdSql
.
checkData
(
0
,
3
,
"2018-09-17 09:00:10.000"
)
tdSql
.
checkData
(
3
,
0
,
"2018-09-17 09:01:20.000"
)
tdSql
.
checkData
(
3
,
1
,
"2018-09-17 09:01:20.000"
)
tdSql
.
checkData
(
3
,
3
,
"2018-09-17 09:01:20.000"
)
tdSql
.
query
(
"select ts,derivative(col, 10s, 1),ts from tb1"
)
tdSql
.
checkRows
(
2
)
tdSql
.
checkData
(
0
,
0
,
"2018-09-17 09:00:10.000"
)
tdSql
.
checkData
(
0
,
1
,
"2018-09-17 09:00:10.000"
)
tdSql
.
checkData
(
0
,
3
,
"2018-09-17 09:00:10.000"
)
tdSql
.
checkData
(
1
,
0
,
"2018-09-17 09:00:20.009"
)
tdSql
.
checkData
(
1
,
1
,
"2018-09-17 09:00:20.009"
)
tdSql
.
checkData
(
1
,
3
,
"2018-09-17 09:00:20.009"
)
tdSql
.
query
(
"select ts from(select ts,derivative(col, 10s, 0) from stb group by tbname)"
)
tdSql
.
checkData
(
0
,
0
,
"2018-09-17 09:00:10.000"
)
tdSql
.
error
(
"select derivative(col, 10s, 0) from tb1 group by tbname"
)
tdSql
.
query
(
"select derivative(col, 10s, 1) from tb1"
)
...
...
tests/pytest/functions/function_diff.py
浏览文件 @
cbfe680f
...
...
@@ -94,6 +94,23 @@ class TDTestCase:
tdSql
.
error
(
"select diff(col13) from test"
)
tdSql
.
error
(
"select diff(col14) from test"
)
tdSql
.
query
(
"select ts,diff(col1),ts from test1"
)
tdSql
.
checkRows
(
10
)
tdSql
.
checkData
(
0
,
0
,
"2018-09-17 09:00:00.000"
)
tdSql
.
checkData
(
0
,
1
,
"2018-09-17 09:00:00.000"
)
tdSql
.
checkData
(
0
,
3
,
"2018-09-17 09:00:00.000"
)
tdSql
.
checkData
(
9
,
0
,
"2018-09-17 09:00:00.009"
)
tdSql
.
checkData
(
9
,
1
,
"2018-09-17 09:00:00.009"
)
tdSql
.
checkData
(
9
,
3
,
"2018-09-17 09:00:00.009"
)
tdSql
.
query
(
"select ts,diff(col1),ts from test group by tbname"
)
tdSql
.
checkRows
(
10
)
tdSql
.
checkData
(
0
,
0
,
"2018-09-17 09:00:00.000"
)
tdSql
.
checkData
(
0
,
1
,
"2018-09-17 09:00:00.000"
)
tdSql
.
checkData
(
0
,
3
,
"2018-09-17 09:00:00.000"
)
tdSql
.
checkData
(
9
,
0
,
"2018-09-17 09:00:00.009"
)
tdSql
.
checkData
(
9
,
1
,
"2018-09-17 09:00:00.009"
)
tdSql
.
checkData
(
9
,
3
,
"2018-09-17 09:00:00.009"
)
tdSql
.
query
(
"select diff(col1) from test1"
)
tdSql
.
checkRows
(
10
)
...
...
tests/pytest/functions/function_top.py
浏览文件 @
cbfe680f
...
...
@@ -117,6 +117,21 @@ class TDTestCase:
tdSql
.
checkRows
(
2
)
tdSql
.
checkData
(
0
,
1
,
8.1
)
tdSql
.
checkData
(
1
,
1
,
9.1
)
tdSql
.
query
(
"select ts,top(col1, 2),ts from test1"
)
tdSql
.
checkRows
(
2
)
tdSql
.
checkData
(
0
,
0
,
"2018-09-17 09:00:00.008"
)
tdSql
.
checkData
(
0
,
1
,
"2018-09-17 09:00:00.008"
)
tdSql
.
checkData
(
1
,
0
,
"2018-09-17 09:00:00.009"
)
tdSql
.
checkData
(
1
,
3
,
"2018-09-17 09:00:00.009"
)
tdSql
.
query
(
"select ts,top(col1, 2),ts from test group by tbname"
)
tdSql
.
checkRows
(
2
)
tdSql
.
checkData
(
0
,
0
,
"2018-09-17 09:00:00.008"
)
tdSql
.
checkData
(
0
,
1
,
"2018-09-17 09:00:00.008"
)
tdSql
.
checkData
(
1
,
0
,
"2018-09-17 09:00:00.009"
)
tdSql
.
checkData
(
1
,
3
,
"2018-09-17 09:00:00.009"
)
#TD-2563 top + super_table + interval
tdSql
.
execute
(
"create table meters(ts timestamp, c int) tags (d int)"
)
...
...
tests/pytest/functions/queryTestCases.py
浏览文件 @
cbfe680f
...
...
@@ -884,6 +884,126 @@ class TDTestCase:
pass
def
td6068
(
self
):
tdLog
.
printNoPrefix
(
"==========TD-6068=========="
)
tdSql
.
execute
(
"drop database if exists db"
)
tdSql
.
execute
(
"create database if not exists db keep 3650"
)
tdSql
.
execute
(
"use db"
)
tdSql
.
execute
(
"create stable db.stb1 (ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool) tags(t1 int)"
)
for
i
in
range
(
100
):
sql
=
f
"create table db.t
{
i
}
using db.stb1 tags(
{
i
}
)"
tdSql
.
execute
(
sql
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-10h,
{
i
}
,
{
i
+
random
.
random
()
}
, now-10h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-9h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-9h, 'a_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-8h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-8h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-7h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-7h, 'b_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-6h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-6h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', True)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
values (now-5h,
{
i
+
random
.
randint
(
1
,
10
)
}
,
{
i
+
random
.
random
()
}
, now-5h, 'c_
{
i
}
', '
{
i
-
random
.
random
()
}
', FALSE )"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-4h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-11h)"
)
tdSql
.
execute
(
f
"insert into db.t
{
i
}
(ts)values (now-450m)"
)
tdSql
.
query
(
"select ts as t,derivative(c1, 10m, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1h, 0) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1s, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c1, 1d, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c1, 1h, 0) from stb1"
)
tdSql
.
query
(
"select ts as t, derivative(c2, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c3, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(c4, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, derivative(c5, 1h, 0) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, derivative(c6, 1h, 0) from t1"
)
tdSql
.
error
(
"select ts as t, derivative(t1, 1h, 0) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, diff(c1) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
checkCols
(
4
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1) from stb1"
)
tdSql
.
query
(
"select ts as t, diff(c2) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c3) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c4) from t1"
)
tdSql
.
query
(
"select ts as t, diff(c5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
error
(
"select ts as t, diff(c6) from t1"
)
tdSql
.
error
(
"select ts as t, diff(t1) from t1"
)
tdSql
.
error
(
"select ts as t, diff(c1, c2) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, bottom(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, bottom(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, bottom(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, bottom(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, bottom(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, bottom(t1, 3) from t1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(c1, 0) from t1"
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from t1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
checkCols
(
3
)
for
i
in
range
(
5
):
data
=
tdSql
.
getData
(
i
,
0
)
tdSql
.
checkData
(
i
,
1
,
data
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1"
)
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select ts as t, top(c1, 5) from stb1 group by tbname"
)
tdSql
.
checkRows
(
500
)
tdSql
.
query
(
"select ts as t, top(c1, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select ts as t, top(c2, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c3, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c4, 5) from t1"
)
tdSql
.
query
(
"select ts as t, top(c5, 8) from t1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
error
(
"select ts as t, top(c6, 5) from t1"
)
tdSql
.
error
(
"select ts as t, top(c5, 8) as b from t1 order by b"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from t1"
)
tdSql
.
error
(
"select ts as t, top(t1, 1) from stb1"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from stb1 order by c3"
)
tdSql
.
error
(
"select ts as t, top(t1, 3) from t1 order by c3"
)
pass
def
run
(
self
):
# master branch
...
...
@@ -891,8 +1011,9 @@ class TDTestCase:
# self.td4082()
# self.td4288()
# self.td4724()
self
.
td5798
()
#
self.td5798()
# self.td5935()
self
.
td6068
()
# develop branch
# self.td4097()
...
...
tests/pytest/query/filterNoKeyword.py
0 → 100644
浏览文件 @
cbfe680f
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
taos
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
())
self
.
ts
=
1537146000000
def
run
(
self
):
tdSql
.
prepare
()
print
(
"======= Verify filter for bool, nchar and binary type ========="
)
tdLog
.
debug
(
"create table st(ts timestamp, tbcol1 bool, tbcol2 binary(10), tbcol3 nchar(20), tbcol4 tinyint, tbcol5 smallint, tbcol6 int, tbcol7 bigint, tbcol8 float, tbcol9 double) tags(tagcol1 bool, tagcol2 binary(10), tagcol3 nchar(10))"
)
tdSql
.
execute
(
"create table st(ts timestamp, tbcol1 bool, tbcol2 binary(10), tbcol3 nchar(20), tbcol4 tinyint, tbcol5 smallint, tbcol6 int, tbcol7 bigint, tbcol8 float, tbcol9 double) tags(tagcol1 bool, tagcol2 binary(10), tagcol3 nchar(10))"
)
tdSql
.
execute
(
"create table st1 using st tags(true, 'table1', '水表')"
)
for
i
in
range
(
1
,
6
):
tdSql
.
execute
(
"insert into st1 values(%d, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d, %f, %f)"
%
(
self
.
ts
+
i
,
i
%
2
,
i
,
i
,
i
,
i
,
i
,
i
,
1.0
,
1.0
))
# =============Data type keywords cannot be used in filter====================
# timestamp
tdSql
.
error
(
"select * from st where timestamp = 1629417600"
)
# bool
tdSql
.
error
(
"select * from st where bool = false"
)
#binary
tdSql
.
error
(
"select * from st where binary = 'taosdata'"
)
# nchar
tdSql
.
error
(
"select * from st where nchar = '涛思数据'"
)
# tinyint
tdSql
.
error
(
"select * from st where tinyint = 127"
)
# smallint
tdSql
.
error
(
"select * from st where smallint = 32767"
)
# int
tdSql
.
error
(
"select * from st where INTEGER = 2147483647"
)
tdSql
.
error
(
"select * from st where int = 2147483647"
)
# bigint
tdSql
.
error
(
"select * from st where bigint = 2147483647"
)
# float
tdSql
.
error
(
"select * from st where float = 3.4E38"
)
# double
tdSql
.
error
(
"select * from st where double = 1.7E308"
)
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/script/api/makefile
浏览文件 @
cbfe680f
...
...
@@ -6,7 +6,8 @@ TARGET=exe
LFLAGS
=
'-Wl,-rpath,/usr/local/taos/driver/'
-ltaos
-lpthread
-lm
-lrt
CFLAGS
=
-O0
-g
-Wall
-Wno-deprecated
-fPIC
-Wno-unused-result
-Wconversion
\
-Wno-char-subscripts
-D_REENTRANT
-Wno-format
-D_REENTRANT
-DLINUX
\
-Wno-unused-function
-D_M_X64
-I
/usr/local/taos/include
-std
=
gnu99
-Wno-unused-function
-D_M_X64
-I
/usr/local/taos/include
-std
=
gnu99
\
-fsanitize
=
address
all
:
$(TARGET)
...
...
@@ -14,8 +15,10 @@ exe:
gcc
$(CFLAGS)
./batchprepare.c
-o
$(ROOT)
batchprepare
$(LFLAGS)
gcc
$(CFLAGS)
./stmtBatchTest.c
-o
$(ROOT)
stmtBatchTest
$(LFLAGS)
gcc
$(CFLAGS)
./stmtTest.c
-o
$(ROOT)
stmtTest
$(LFLAGS)
gcc
$(CFLAGS)
./stmt_function.c
-o
$(ROOT)
stmt_function
$(LFLAGS)
clean
:
rm
$(ROOT)
batchprepare
rm
$(ROOT)
stmtBatchTest
rm
$(ROOT)
stmtTest
rm
$(ROOT)
stmt_function
tests/script/api/stmt_function.c
0 → 100644
浏览文件 @
cbfe680f
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "taos.h"
#include <sys/time.h>
#include <pthread.h>
#include <unistd.h>
#include <assert.h>
void
execute_simple_sql
(
void
*
taos
,
char
*
sql
)
{
TAOS_RES
*
result
=
taos_query
(
taos
,
sql
);
if
(
result
==
NULL
||
taos_errno
(
result
)
!=
0
)
{
printf
(
"failed to %s, Reason: %s
\n
"
,
sql
,
taos_errstr
(
result
));
taos_free_result
(
result
);
exit
(
EXIT_FAILURE
);
}
taos_free_result
(
result
);
}
void
taos_stmt_init_test
()
{
printf
(
"start taos_stmt_init test
\n
"
);
void
*
taos
=
NULL
;
TAOS_STMT
*
stmt
=
NULL
;
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
==
NULL
);
// ASM ERROR
// assert(taos_stmt_close(stmt) != 0);
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"Cannot connect to tdengine server
\n
"
);
exit
(
EXIT_FAILURE
);
}
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
assert
(
taos_stmt_close
(
stmt
)
==
0
);
printf
(
"finish taos_stmt_init test
\n
"
);
}
void
taos_stmt_preprare_test
()
{
printf
(
"start taos_stmt_prepare test
\n
"
);
char
*
stmt_sql
=
calloc
(
1
,
1048576
);
TAOS_STMT
*
stmt
=
NULL
;
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
!=
0
);
void
*
taos
=
NULL
;
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"Cannot connect to tdengine server
\n
"
);
exit
(
EXIT_FAILURE
);
}
execute_simple_sql
(
taos
,
"drop database if exists stmt_test"
);
execute_simple_sql
(
taos
,
"create database stmt_test"
);
execute_simple_sql
(
taos
,
"use stmt_test"
);
execute_simple_sql
(
taos
,
"create table super(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 smallint, c7 tinyint, c8 bool, c9 nchar(8), c10 timestamp) tags (t1 int, t2 bigint, t3 float, t4 double, t5 binary(8), t6 smallint, t7 tinyint, t8 bool, t9 nchar(8))"
);
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
// below will make client dead lock
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
==
0
);
// assert(taos_stmt_close(stmt) == 0);
// stmt = taos_stmt_init(taos);
assert
(
stmt
!=
NULL
);
sprintf
(
stmt_sql
,
"select from ?"
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
!=
0
);
assert
(
taos_stmt_close
(
stmt
)
==
0
);
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
sprintf
(
stmt_sql
,
"insert into ? values (?,?,?,?,?,?,?,?,?,?,?)"
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
==
0
);
assert
(
taos_stmt_close
(
stmt
)
==
0
);
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
sprintf
(
stmt_sql
,
"insert into super values (?,?,?,?,?,?,?,?,?,?,?)"
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
!=
0
);
assert
(
taos_stmt_close
(
stmt
)
==
0
);
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
sprintf
(
stmt_sql
,
"insert into ? values (?,?,?,?,?,?,?,?,1,?,?,?)"
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
==
0
);
assert
(
taos_stmt_close
(
stmt
)
==
0
);
free
(
stmt_sql
);
printf
(
"finish taos_stmt_prepare test
\n
"
);
}
void
taos_stmt_set_tbname_test
()
{
printf
(
"start taos_stmt_set_tbname test
\n
"
);
TAOS_STMT
*
stmt
=
NULL
;
char
*
name
=
calloc
(
1
,
200
);
// ASM ERROR
// assert(taos_stmt_set_tbname(stmt, name) != 0);
void
*
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"Cannot connect to tdengine server
\n
"
);
exit
(
EXIT_FAILURE
);
}
execute_simple_sql
(
taos
,
"drop database if exists stmt_test"
);
execute_simple_sql
(
taos
,
"create database stmt_test"
);
execute_simple_sql
(
taos
,
"use stmt_test"
);
execute_simple_sql
(
taos
,
"create table super(ts timestamp, c1 int)"
);
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
assert
(
taos_stmt_set_tbname
(
stmt
,
name
)
!=
0
);
char
*
stmt_sql
=
calloc
(
1
,
1000
);
sprintf
(
stmt_sql
,
"insert into ? values (?,?)"
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
==
0
);
sprintf
(
name
,
"super"
);
assert
(
stmt
!=
NULL
);
assert
(
taos_stmt_set_tbname
(
stmt
,
name
)
==
0
);
free
(
name
);
free
(
stmt_sql
);
taos_stmt_close
(
stmt
);
printf
(
"finish taos_stmt_set_tbname test
\n
"
);
}
void
taos_stmt_set_tbname_tags_test
()
{
printf
(
"start taos_stmt_set_tbname_tags test
\n
"
);
TAOS_STMT
*
stmt
=
NULL
;
char
*
name
=
calloc
(
1
,
20
);
TAOS_BIND
*
tags
=
calloc
(
1
,
sizeof
(
TAOS_BIND
));
// ASM ERROR
// assert(taos_stmt_set_tbname_tags(stmt, name, tags) != 0);
void
*
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"Cannot connect to tdengine server
\n
"
);
exit
(
EXIT_FAILURE
);
}
execute_simple_sql
(
taos
,
"drop database if exists stmt_test"
);
execute_simple_sql
(
taos
,
"create database stmt_test"
);
execute_simple_sql
(
taos
,
"use stmt_test"
);
execute_simple_sql
(
taos
,
"create stable super(ts timestamp, c1 int) tags (id int)"
);
execute_simple_sql
(
taos
,
"create table tb using super tags (1)"
);
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
char
*
stmt_sql
=
calloc
(
1
,
1000
);
sprintf
(
stmt_sql
,
"insert into ? using super tags (?) values (?,?)"
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
==
0
);
assert
(
taos_stmt_set_tbname_tags
(
stmt
,
name
,
tags
)
!=
0
);
sprintf
(
name
,
"tb"
);
assert
(
taos_stmt_set_tbname_tags
(
stmt
,
name
,
tags
)
!=
0
);
int
t
=
1
;
tags
->
buffer_length
=
TSDB_DATA_TYPE_INT
;
tags
->
buffer_length
=
sizeof
(
uint32_t
);
tags
->
buffer
=
&
t
;
tags
->
length
=
&
tags
->
buffer_length
;
tags
->
is_null
=
NULL
;
assert
(
taos_stmt_set_tbname_tags
(
stmt
,
name
,
tags
)
==
0
);
free
(
stmt_sql
);
free
(
name
);
free
(
tags
);
taos_stmt_close
(
stmt
);
printf
(
"finish taos_stmt_set_tbname_tags test
\n
"
);
}
void
taos_stmt_set_sub_tbname_test
()
{
printf
(
"start taos_stmt_set_sub_tbname test
\n
"
);
TAOS_STMT
*
stmt
=
NULL
;
char
*
name
=
calloc
(
1
,
200
);
// ASM ERROR
// assert(taos_stmt_set_sub_tbname(stmt, name) != 0);
void
*
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"Cannot connect to tdengine server
\n
"
);
exit
(
EXIT_FAILURE
);
}
execute_simple_sql
(
taos
,
"drop database if exists stmt_test"
);
execute_simple_sql
(
taos
,
"create database stmt_test"
);
execute_simple_sql
(
taos
,
"use stmt_test"
);
execute_simple_sql
(
taos
,
"create stable super(ts timestamp, c1 int) tags (id int)"
);
execute_simple_sql
(
taos
,
"create table tb using super tags (1)"
);
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
char
*
stmt_sql
=
calloc
(
1
,
1000
);
sprintf
(
stmt_sql
,
"insert into ? values (?,?)"
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
==
0
);
assert
(
taos_stmt_set_sub_tbname
(
stmt
,
name
)
!=
0
);
sprintf
(
name
,
"tb"
);
assert
(
taos_stmt_set_sub_tbname
(
stmt
,
name
)
==
0
);
// assert(taos_load_table_info(taos, "super, tb") == 0);
// assert(taos_stmt_set_sub_tbname(stmt, name) == 0);
free
(
name
);
free
(
stmt_sql
);
assert
(
taos_stmt_close
(
stmt
)
==
0
);
printf
(
"finish taos_stmt_set_sub_tbname test
\n
"
);
}
void
taos_stmt_bind_param_test
()
{
printf
(
"start taos_stmt_bind_param test
\n
"
);
TAOS_STMT
*
stmt
=
NULL
;
TAOS_BIND
*
binds
=
NULL
;
assert
(
taos_stmt_bind_param
(
stmt
,
binds
)
!=
0
);
void
*
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"Cannot connect to tdengine server
\n
"
);
exit
(
EXIT_FAILURE
);
}
execute_simple_sql
(
taos
,
"drop database if exists stmt_test"
);
execute_simple_sql
(
taos
,
"create database stmt_test"
);
execute_simple_sql
(
taos
,
"use stmt_test"
);
execute_simple_sql
(
taos
,
"create table super(ts timestamp, c1 int)"
);
stmt
=
taos_stmt_init
(
taos
);
char
*
stmt_sql
=
calloc
(
1
,
1000
);
sprintf
(
stmt_sql
,
"insert into ? values (?,?)"
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
==
0
);
assert
(
taos_stmt_bind_param
(
stmt
,
binds
)
!=
0
);
free
(
binds
);
TAOS_BIND
*
params
=
calloc
(
2
,
sizeof
(
TAOS_BIND
));
int64_t
ts
=
(
int64_t
)
1591060628000
;
params
[
0
].
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
params
[
0
].
buffer_length
=
sizeof
(
uint64_t
);
params
[
0
].
buffer
=
&
ts
;
params
[
0
].
length
=
&
params
[
0
].
buffer_length
;
params
[
0
].
is_null
=
NULL
;
int32_t
i
=
(
int32_t
)
21474
;
params
[
1
].
buffer_type
=
TSDB_DATA_TYPE_INT
;
params
[
1
].
buffer_length
=
sizeof
(
int32_t
);
params
[
1
].
buffer
=
&
i
;
params
[
1
].
length
=
&
params
[
1
].
buffer_length
;
params
[
1
].
is_null
=
NULL
;
assert
(
taos_stmt_bind_param
(
stmt
,
params
)
!=
0
);
assert
(
taos_stmt_set_tbname
(
stmt
,
"super"
)
==
0
);
assert
(
taos_stmt_bind_param
(
stmt
,
params
)
==
0
);
free
(
params
);
free
(
stmt_sql
);
taos_stmt_close
(
stmt
);
printf
(
"finish taos_stmt_bind_param test
\n
"
);
}
void
taos_stmt_bind_single_param_batch_test
()
{
printf
(
"start taos_stmt_bind_single_param_batch test
\n
"
);
TAOS_STMT
*
stmt
=
NULL
;
TAOS_MULTI_BIND
*
bind
=
NULL
;
assert
(
taos_stmt_bind_single_param_batch
(
stmt
,
bind
,
0
)
!=
0
);
printf
(
"finish taos_stmt_bind_single_param_batch test
\n
"
);
}
void
taos_stmt_bind_param_batch_test
()
{
printf
(
"start taos_stmt_bind_param_batch test
\n
"
);
TAOS_STMT
*
stmt
=
NULL
;
TAOS_MULTI_BIND
*
bind
=
NULL
;
assert
(
taos_stmt_bind_param_batch
(
stmt
,
bind
)
!=
0
);
printf
(
"finish taos_stmt_bind_param_batch test
\n
"
);
}
void
taos_stmt_add_batch_test
()
{
printf
(
"start taos_stmt_add_batch test
\n
"
);
TAOS_STMT
*
stmt
=
NULL
;
assert
(
taos_stmt_add_batch
(
stmt
)
!=
0
);
void
*
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"Cannot connect to tdengine server
\n
"
);
exit
(
EXIT_FAILURE
);
}
execute_simple_sql
(
taos
,
"drop database if exists stmt_test"
);
execute_simple_sql
(
taos
,
"create database stmt_test"
);
execute_simple_sql
(
taos
,
"use stmt_test"
);
execute_simple_sql
(
taos
,
"create table super(ts timestamp, c1 int)"
);
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
char
*
stmt_sql
=
calloc
(
1
,
1000
);
sprintf
(
stmt_sql
,
"insert into ? values (?,?)"
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
==
0
);
assert
(
taos_stmt_add_batch
(
stmt
)
!=
0
);
TAOS_BIND
*
params
=
calloc
(
2
,
sizeof
(
TAOS_BIND
));
int64_t
ts
=
(
int64_t
)
1591060628000
;
params
[
0
].
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
params
[
0
].
buffer_length
=
sizeof
(
uint64_t
);
params
[
0
].
buffer
=
&
ts
;
params
[
0
].
length
=
&
params
[
0
].
buffer_length
;
params
[
0
].
is_null
=
NULL
;
int32_t
i
=
(
int32_t
)
21474
;
params
[
1
].
buffer_type
=
TSDB_DATA_TYPE_INT
;
params
[
1
].
buffer_length
=
sizeof
(
int32_t
);
params
[
1
].
buffer
=
&
i
;
params
[
1
].
length
=
&
params
[
1
].
buffer_length
;
params
[
1
].
is_null
=
NULL
;
assert
(
taos_stmt_set_tbname
(
stmt
,
"super"
)
==
0
);
assert
(
taos_stmt_bind_param
(
stmt
,
params
)
==
0
);
assert
(
taos_stmt_add_batch
(
stmt
)
==
0
);
free
(
params
);
free
(
stmt_sql
);
assert
(
taos_stmt_close
(
stmt
)
==
0
);
printf
(
"finish taos_stmt_add_batch test
\n
"
);
}
void
taos_stmt_execute_test
()
{
printf
(
"start taos_stmt_execute test
\n
"
);
TAOS_STMT
*
stmt
=
NULL
;
assert
(
taos_stmt_execute
(
stmt
)
!=
0
);
void
*
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"Cannot connect to tdengine server
\n
"
);
exit
(
EXIT_FAILURE
);
}
execute_simple_sql
(
taos
,
"drop database if exists stmt_test"
);
execute_simple_sql
(
taos
,
"create database stmt_test"
);
execute_simple_sql
(
taos
,
"use stmt_test"
);
execute_simple_sql
(
taos
,
"create table super(ts timestamp, c1 int)"
);
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
assert
(
taos_stmt_execute
(
stmt
)
!=
0
);
char
*
stmt_sql
=
calloc
(
1
,
1000
);
sprintf
(
stmt_sql
,
"insert into ? values (?,?)"
);
assert
(
taos_stmt_prepare
(
stmt
,
stmt_sql
,
0
)
==
0
);
assert
(
taos_stmt_execute
(
stmt
)
!=
0
);
TAOS_BIND
*
params
=
calloc
(
2
,
sizeof
(
TAOS_BIND
));
int64_t
ts
=
(
int64_t
)
1591060628000
;
params
[
0
].
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
params
[
0
].
buffer_length
=
sizeof
(
uint64_t
);
params
[
0
].
buffer
=
&
ts
;
params
[
0
].
length
=
&
params
[
0
].
buffer_length
;
params
[
0
].
is_null
=
NULL
;
int32_t
i
=
(
int32_t
)
21474
;
params
[
1
].
buffer_type
=
TSDB_DATA_TYPE_INT
;
params
[
1
].
buffer_length
=
sizeof
(
int32_t
);
params
[
1
].
buffer
=
&
i
;
params
[
1
].
length
=
&
params
[
1
].
buffer_length
;
params
[
1
].
is_null
=
NULL
;
assert
(
taos_stmt_set_tbname
(
stmt
,
"super"
)
==
0
);
assert
(
taos_stmt_execute
(
stmt
)
!=
0
);
assert
(
taos_stmt_bind_param
(
stmt
,
params
)
==
0
);
assert
(
taos_stmt_execute
(
stmt
)
!=
0
);
assert
(
taos_stmt_add_batch
(
stmt
)
==
0
);
assert
(
taos_stmt_execute
(
stmt
)
==
0
);
free
(
params
);
free
(
stmt_sql
);
assert
(
taos_stmt_close
(
stmt
)
==
0
);
printf
(
"finish taos_stmt_execute test
\n
"
);
}
void
taos_stmt_use_result_test
()
{
printf
(
"start taos_stmt_use_result test
\n
"
);
TAOS_STMT
*
stmt
=
NULL
;
assert
(
taos_stmt_use_result
(
stmt
)
==
NULL
);
void
*
taos
=
taos_connect
(
"127.0.0.1"
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"Cannot connect to tdengine server
\n
"
);
exit
(
EXIT_FAILURE
);
}
printf
(
"finish taos_stmt_use_result test
\n
"
);
stmt
=
taos_stmt_init
(
taos
);
assert
(
stmt
!=
NULL
);
TAOS_RES
*
result
=
taos_stmt_use_result
(
stmt
);
int
rows
=
0
;
TAOS_ROW
row
;
while
((
row
=
taos_fetch_row
(
result
)))
{
rows
++
;
}
printf
(
"rows: %d
\n
"
,
rows
);
taos_free_result
(
result
);
// assert(taos_stmt_use_result(stmt) == NULL);
assert
(
taos_stmt_close
(
stmt
)
==
0
);
}
void
taos_stmt_close_test
()
{
printf
(
"start taos_stmt_close test
\n
"
);
// ASM ERROR
// TAOS_STMT *stmt = NULL;
// assert(taos_stmt_close(stmt) != 0);
printf
(
"finish taos_stmt_close test
\n
"
);
}
void
test_api_reliability
()
{
// ASM catch memory leak
taos_stmt_init_test
();
taos_stmt_preprare_test
();
taos_stmt_set_tbname_test
();
taos_stmt_set_tbname_tags_test
();
taos_stmt_set_sub_tbname_test
();
taos_stmt_bind_param_test
();
taos_stmt_bind_single_param_batch_test
();
taos_stmt_bind_param_batch_test
();
taos_stmt_add_batch_test
();
taos_stmt_execute_test
();
taos_stmt_use_result_test
();
taos_stmt_close_test
();
}
int
main
(
int
argc
,
char
*
argv
[])
{
test_api_reliability
();
return
0
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录