Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
13d8bb83
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
13d8bb83
编写于
9月 13, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' into feature/szhou/regex-nmatch
上级
e15abb2e
3fd7e351
变更
25
显示空白变更内容
内联
并排
Showing
25 changed file
with
2079 addition
and
103 deletion
+2079
-103
src/client/CMakeLists.txt
src/client/CMakeLists.txt
+8
-8
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+5
-4
src/client/src/tscParseOpenTSDB.c
src/client/src/tscParseOpenTSDB.c
+556
-7
src/connector/python/taos/cinterface.py
src/connector/python/taos/cinterface.py
+7
-1
src/connector/python/taos/connection.py
src/connector/python/taos/connection.py
+19
-0
src/connector/python/taos/error.py
src/connector/python/taos/error.py
+11
-1
src/inc/taos.h
src/inc/taos.h
+2
-0
src/inc/taoserror.h
src/inc/taoserror.h
+3
-0
src/util/src/terror.c
src/util/src/terror.c
+3
-0
tests/examples/JDBC/JDBCDemo/pom.xml
tests/examples/JDBC/JDBCDemo/pom.xml
+1
-1
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcDemo.java
...JDBCDemo/src/main/java/com/taosdata/example/JdbcDemo.java
+7
-11
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java
...o/src/main/java/com/taosdata/example/JdbcRestfulDemo.java
+11
-12
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java
...emo/src/main/java/com/taosdata/example/SubscribeDemo.java
+1
-2
tests/examples/JDBC/springbootdemo/pom.xml
tests/examples/JDBC/springbootdemo/pom.xml
+6
-3
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/SpringbootdemoApplication.java
...ata/example/springbootdemo/SpringbootdemoApplication.java
+1
-1
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/controller/WeatherController.java
.../example/springbootdemo/controller/WeatherController.java
+5
-19
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.java
...om/taosdata/example/springbootdemo/dao/WeatherMapper.java
+2
-0
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml
...com/taosdata/example/springbootdemo/dao/WeatherMapper.xml
+43
-11
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/domain/Weather.java
...a/com/taosdata/example/springbootdemo/domain/Weather.java
+9
-0
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/service/WeatherService.java
...osdata/example/springbootdemo/service/WeatherService.java
+18
-0
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/util/TaosAspect.java
.../com/taosdata/example/springbootdemo/util/TaosAspect.java
+36
-0
tests/examples/JDBC/springbootdemo/src/main/resources/application.properties
.../springbootdemo/src/main/resources/application.properties
+4
-6
tests/examples/c/apitest.c
tests/examples/c/apitest.c
+751
-14
tests/examples/c/makefile
tests/examples/c/makefile
+2
-2
tests/pytest/insert/insertJSONPayload.py
tests/pytest/insert/insertJSONPayload.py
+568
-0
未找到文件。
src/client/CMakeLists.txt
浏览文件 @
13d8bb83
...
@@ -13,13 +13,13 @@ IF (TD_LINUX)
...
@@ -13,13 +13,13 @@ IF (TD_LINUX)
# set the static lib name
# set the static lib name
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos_static common query trpc tutil pthread m rt
${
VAR_TSZ
}
)
TARGET_LINK_LIBRARIES
(
taos_static common query trpc tutil pthread m rt
cJson
${
VAR_TSZ
}
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES OUTPUT_NAME
"taos_static"
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES OUTPUT_NAME
"taos_static"
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1
)
# generate dynamic library (*.so)
# generate dynamic library (*.so)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos common query trpc tutil pthread m rt
)
TARGET_LINK_LIBRARIES
(
taos common query trpc tutil pthread m rt
cJson
)
IF
(
TD_LINUX_64
)
IF
(
TD_LINUX_64
)
TARGET_LINK_LIBRARIES
(
taos lua
)
TARGET_LINK_LIBRARIES
(
taos lua
)
ENDIF
()
ENDIF
()
...
@@ -39,13 +39,13 @@ ELSEIF (TD_DARWIN)
...
@@ -39,13 +39,13 @@ ELSEIF (TD_DARWIN)
# set the static lib name
# set the static lib name
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos_static common query trpc tutil pthread m lua
)
TARGET_LINK_LIBRARIES
(
taos_static common query trpc tutil pthread m lua
cJson
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES OUTPUT_NAME
"taos_static"
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES OUTPUT_NAME
"taos_static"
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1
)
# generate dynamic library (*.dylib)
# generate dynamic library (*.dylib)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos common query trpc tutil pthread m lua
)
TARGET_LINK_LIBRARIES
(
taos common query trpc tutil pthread m lua
cJson
)
SET_TARGET_PROPERTIES
(
taos PROPERTIES CLEAN_DIRECT_OUTPUT 1
)
SET_TARGET_PROPERTIES
(
taos PROPERTIES CLEAN_DIRECT_OUTPUT 1
)
#set version of .dylib
#set version of .dylib
...
@@ -63,26 +63,26 @@ ELSEIF (TD_WINDOWS)
...
@@ -63,26 +63,26 @@ ELSEIF (TD_WINDOWS)
CONFIGURE_FILE
(
"
${
TD_COMMUNITY_DIR
}
/src/client/src/taos.rc.in"
"
${
TD_COMMUNITY_DIR
}
/src/client/src/taos.rc"
)
CONFIGURE_FILE
(
"
${
TD_COMMUNITY_DIR
}
/src/client/src/taos.rc.in"
"
${
TD_COMMUNITY_DIR
}
/src/client/src/taos.rc"
)
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos_static trpc tutil query
)
TARGET_LINK_LIBRARIES
(
taos_static trpc tutil query
cJson
)
# generate dynamic library (*.dll)
# generate dynamic library (*.dll)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
${
TD_COMMUNITY_DIR
}
/src/client/src/taos.rc
)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
${
TD_COMMUNITY_DIR
}
/src/client/src/taos.rc
)
IF
(
NOT TD_GODLL
)
IF
(
NOT TD_GODLL
)
SET_TARGET_PROPERTIES
(
taos PROPERTIES LINK_FLAGS /DEF:
${
TD_COMMUNITY_DIR
}
/src/client/src/taos.def
)
SET_TARGET_PROPERTIES
(
taos PROPERTIES LINK_FLAGS /DEF:
${
TD_COMMUNITY_DIR
}
/src/client/src/taos.def
)
ENDIF
()
ENDIF
()
TARGET_LINK_LIBRARIES
(
taos trpc tutil query lua
)
TARGET_LINK_LIBRARIES
(
taos trpc tutil query lua
cJson
)
ELSEIF
(
TD_DARWIN
)
ELSEIF
(
TD_DARWIN
)
SET
(
CMAKE_MACOSX_RPATH 1
)
SET
(
CMAKE_MACOSX_RPATH 1
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/deps/jni/linux
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/deps/jni/linux
)
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
ADD_LIBRARY
(
taos_static STATIC
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos_static query trpc tutil pthread m lua
)
TARGET_LINK_LIBRARIES
(
taos_static query trpc tutil pthread m lua
cJson
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES OUTPUT_NAME
"taos_static"
)
SET_TARGET_PROPERTIES
(
taos_static PROPERTIES OUTPUT_NAME
"taos_static"
)
# generate dynamic library (*.dylib)
# generate dynamic library (*.dylib)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
)
ADD_LIBRARY
(
taos SHARED
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taos query trpc tutil pthread m lua
)
TARGET_LINK_LIBRARIES
(
taos query trpc tutil pthread m lua
cJson
)
SET_TARGET_PROPERTIES
(
taos PROPERTIES CLEAN_DIRECT_OUTPUT 1
)
SET_TARGET_PROPERTIES
(
taos PROPERTIES CLEAN_DIRECT_OUTPUT 1
)
...
...
src/client/src/tscParseLineProtocol.c
浏览文件 @
13d8bb83
...
@@ -2128,11 +2128,12 @@ int32_t tscParseLines(char* lines[], int numLines, SArray* points, SArray* faile
...
@@ -2128,11 +2128,12 @@ int32_t tscParseLines(char* lines[], int numLines, SArray* points, SArray* faile
int
taos_insert_lines
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
)
{
int
taos_insert_lines
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
SSmlLinesInfo
*
info
=
calloc
(
1
,
sizeof
(
SSmlLinesInfo
));
SSmlLinesInfo
*
info
=
t
calloc
(
1
,
sizeof
(
SSmlLinesInfo
));
info
->
id
=
genLinesSmlId
();
info
->
id
=
genLinesSmlId
();
if
(
numLines
<=
0
||
numLines
>
65536
)
{
if
(
numLines
<=
0
||
numLines
>
65536
)
{
tscError
(
"SML:0x%"
PRIx64
" taos_insert_lines numLines should be between 1 and 65536. numLines: %d"
,
info
->
id
,
numLines
);
tscError
(
"SML:0x%"
PRIx64
" taos_insert_lines numLines should be between 1 and 65536. numLines: %d"
,
info
->
id
,
numLines
);
tfree
(
info
);
code
=
TSDB_CODE_TSC_APP_ERROR
;
code
=
TSDB_CODE_TSC_APP_ERROR
;
return
code
;
return
code
;
}
}
...
@@ -2140,7 +2141,7 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) {
...
@@ -2140,7 +2141,7 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) {
for
(
int
i
=
0
;
i
<
numLines
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numLines
;
++
i
)
{
if
(
lines
[
i
]
==
NULL
)
{
if
(
lines
[
i
]
==
NULL
)
{
tscError
(
"SML:0x%"
PRIx64
" taos_insert_lines line %d is NULL"
,
info
->
id
,
i
);
tscError
(
"SML:0x%"
PRIx64
" taos_insert_lines line %d is NULL"
,
info
->
id
,
i
);
free
(
info
);
t
free
(
info
);
code
=
TSDB_CODE_TSC_APP_ERROR
;
code
=
TSDB_CODE_TSC_APP_ERROR
;
return
code
;
return
code
;
}
}
...
@@ -2149,7 +2150,7 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) {
...
@@ -2149,7 +2150,7 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) {
SArray
*
lpPoints
=
taosArrayInit
(
numLines
,
sizeof
(
TAOS_SML_DATA_POINT
));
SArray
*
lpPoints
=
taosArrayInit
(
numLines
,
sizeof
(
TAOS_SML_DATA_POINT
));
if
(
lpPoints
==
NULL
)
{
if
(
lpPoints
==
NULL
)
{
tscError
(
"SML:0x%"
PRIx64
" taos_insert_lines failed to allocate memory"
,
info
->
id
);
tscError
(
"SML:0x%"
PRIx64
" taos_insert_lines failed to allocate memory"
,
info
->
id
);
free
(
info
);
t
free
(
info
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
}
...
@@ -2177,7 +2178,7 @@ cleanup:
...
@@ -2177,7 +2178,7 @@ cleanup:
taosArrayDestroy
(
lpPoints
);
taosArrayDestroy
(
lpPoints
);
free
(
info
);
t
free
(
info
);
return
code
;
return
code
;
}
}
src/client/src/tscParseOpenTSDB.c
浏览文件 @
13d8bb83
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include "cJSON.h"
#include "hash.h"
#include "hash.h"
#include "taos.h"
#include "taos.h"
...
@@ -12,9 +13,12 @@
...
@@ -12,9 +13,12 @@
#include "tscParseLine.h"
#include "tscParseLine.h"
#define MAX_TELNET_FILEDS_NUM 2
#define OTD_MAX_FIELDS_NUM 2
#define OTS_TIMESTAMP_COLUMN_NAME "ts"
#define OTD_JSON_SUB_FIELDS_NUM 2
#define OTS_METRIC_VALUE_COLUMN_NAME "value"
#define OTD_JSON_FIELDS_NUM 4
#define OTD_TIMESTAMP_COLUMN_NAME "ts"
#define OTD_METRIC_VALUE_COLUMN_NAME "value"
/* telnet style API parser */
/* telnet style API parser */
static
uint64_t
HandleId
=
0
;
static
uint64_t
HandleId
=
0
;
...
@@ -77,12 +81,12 @@ static int32_t parseTelnetTimeStamp(TAOS_SML_KV **pTS, int *num_kvs, const char
...
@@ -77,12 +81,12 @@ static int32_t parseTelnetTimeStamp(TAOS_SML_KV **pTS, int *num_kvs, const char
const
char
*
start
,
*
cur
;
const
char
*
start
,
*
cur
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int
len
=
0
;
int
len
=
0
;
char
key
[]
=
OT
S
_TIMESTAMP_COLUMN_NAME
;
char
key
[]
=
OT
D
_TIMESTAMP_COLUMN_NAME
;
char
*
value
=
NULL
;
char
*
value
=
NULL
;
start
=
cur
=
*
index
;
start
=
cur
=
*
index
;
//allocate fields for timestamp and value
//allocate fields for timestamp and value
*
pTS
=
tcalloc
(
MAX_TELNET_FILE
DS_NUM
,
sizeof
(
TAOS_SML_KV
));
*
pTS
=
tcalloc
(
OTD_MAX_FIEL
DS_NUM
,
sizeof
(
TAOS_SML_KV
));
while
(
*
cur
!=
'\0'
)
{
while
(
*
cur
!=
'\0'
)
{
if
(
*
cur
==
' '
)
{
if
(
*
cur
==
' '
)
{
...
@@ -123,7 +127,7 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch
...
@@ -123,7 +127,7 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch
const
char
*
start
,
*
cur
;
const
char
*
start
,
*
cur
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int
len
=
0
;
int
len
=
0
;
char
key
[]
=
OT
S
_METRIC_VALUE_COLUMN_NAME
;
char
key
[]
=
OT
D
_METRIC_VALUE_COLUMN_NAME
;
char
*
value
=
NULL
;
char
*
value
=
NULL
;
start
=
cur
=
*
index
;
start
=
cur
=
*
index
;
...
@@ -405,7 +409,7 @@ cleanup:
...
@@ -405,7 +409,7 @@ cleanup:
tscDebug
(
"OTD:0x%"
PRIx64
" taos_insert_telnet_lines finish inserting %d lines. code: %d"
,
info
->
id
,
numLines
,
code
);
tscDebug
(
"OTD:0x%"
PRIx64
" taos_insert_telnet_lines finish inserting %d lines. code: %d"
,
info
->
id
,
numLines
,
code
);
points
=
TARRAY_GET_START
(
lpPoints
);
points
=
TARRAY_GET_START
(
lpPoints
);
numPoints
=
taosArrayGetSize
(
lpPoints
);
numPoints
=
taosArrayGetSize
(
lpPoints
);
for
(
int
i
=
0
;
i
<
numPoints
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numPoints
;
++
i
)
{
destroySmlDataPoint
(
points
+
i
);
destroySmlDataPoint
(
points
+
i
);
}
}
...
@@ -422,3 +426,548 @@ int taos_telnet_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
...
@@ -422,3 +426,548 @@ int taos_telnet_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
tfree
(
info
);
tfree
(
info
);
return
code
;
return
code
;
}
}
/* telnet style API parser */
int32_t
parseMetricFromJSON
(
cJSON
*
root
,
TAOS_SML_DATA_POINT
*
pSml
,
SSmlLinesInfo
*
info
)
{
cJSON
*
metric
=
cJSON_GetObjectItem
(
root
,
"metric"
);
if
(
!
cJSON_IsString
(
metric
))
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
size_t
stableLen
=
strlen
(
metric
->
valuestring
);
if
(
stableLen
>
TSDB_TABLE_NAME_LEN
)
{
tscError
(
"OTD:0x%"
PRIx64
" Metric cannot exceeds 193 characters in JSON"
,
info
->
id
);
return
TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH
;
}
pSml
->
stableName
=
tcalloc
(
stableLen
+
1
,
sizeof
(
char
));
if
(
pSml
->
stableName
==
NULL
){
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
if
(
isdigit
(
metric
->
valuestring
[
0
]))
{
tscError
(
"OTD:0x%"
PRIx64
" Metric cannnot start with digit in JSON"
,
info
->
id
);
tfree
(
pSml
->
stableName
);
return
TSDB_CODE_TSC_INVALID_JSON
;
}
tstrncpy
(
pSml
->
stableName
,
metric
->
valuestring
,
stableLen
+
1
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
parseTimestampFromJSONObj
(
cJSON
*
root
,
int64_t
*
tsVal
,
SSmlLinesInfo
*
info
)
{
int32_t
size
=
cJSON_GetArraySize
(
root
);
if
(
size
!=
OTD_JSON_SUB_FIELDS_NUM
)
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
cJSON
*
value
=
cJSON_GetObjectItem
(
root
,
"value"
);
if
(
!
cJSON_IsNumber
(
value
))
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
cJSON
*
type
=
cJSON_GetObjectItem
(
root
,
"type"
);
if
(
!
cJSON_IsString
(
type
))
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
*
tsVal
=
value
->
valueint
;
//if timestamp value is 0 use current system time
if
(
*
tsVal
==
0
)
{
*
tsVal
=
taosGetTimestampNs
();
return
TSDB_CODE_SUCCESS
;
}
size_t
typeLen
=
strlen
(
type
->
valuestring
);
if
(
typeLen
==
1
&&
type
->
valuestring
[
0
]
==
's'
)
{
//seconds
*
tsVal
=
(
int64_t
)(
*
tsVal
*
1e9
);
}
else
if
(
typeLen
==
2
&&
type
->
valuestring
[
1
]
==
's'
)
{
switch
(
type
->
valuestring
[
0
])
{
case
'm'
:
//milliseconds
*
tsVal
=
convertTimePrecision
(
*
tsVal
,
TSDB_TIME_PRECISION_MILLI
,
TSDB_TIME_PRECISION_NANO
);
break
;
case
'u'
:
//microseconds
*
tsVal
=
convertTimePrecision
(
*
tsVal
,
TSDB_TIME_PRECISION_MICRO
,
TSDB_TIME_PRECISION_NANO
);
break
;
case
'n'
:
//nanoseconds
*
tsVal
=
*
tsVal
*
1
;
break
;
default:
return
TSDB_CODE_TSC_INVALID_JSON
;
}
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
parseTimestampFromJSON
(
cJSON
*
root
,
TAOS_SML_KV
**
pTS
,
int
*
num_kvs
,
SSmlLinesInfo
*
info
)
{
//Timestamp must be the first KV to parse
assert
(
*
num_kvs
==
0
);
int64_t
tsVal
;
char
key
[]
=
OTD_TIMESTAMP_COLUMN_NAME
;
cJSON
*
timestamp
=
cJSON_GetObjectItem
(
root
,
"timestamp"
);
if
(
cJSON_IsNumber
(
timestamp
))
{
//timestamp value 0 indicates current system time
if
(
timestamp
->
valueint
==
0
)
{
tsVal
=
taosGetTimestampNs
();
}
else
{
tsVal
=
convertTimePrecision
(
timestamp
->
valueint
,
TSDB_TIME_PRECISION_MICRO
,
TSDB_TIME_PRECISION_NANO
);
}
}
else
if
(
cJSON_IsObject
(
timestamp
))
{
int32_t
ret
=
parseTimestampFromJSONObj
(
timestamp
,
&
tsVal
,
info
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"OTD:0x%"
PRIx64
" Failed to parse timestamp from JSON Obj"
,
info
->
id
);
return
ret
;
}
}
else
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
//allocate fields for timestamp and value
*
pTS
=
tcalloc
(
OTD_MAX_FIELDS_NUM
,
sizeof
(
TAOS_SML_KV
));
(
*
pTS
)
->
key
=
tcalloc
(
sizeof
(
key
),
1
);
memcpy
((
*
pTS
)
->
key
,
key
,
sizeof
(
key
));
(
*
pTS
)
->
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
(
*
pTS
)
->
length
=
(
int16_t
)
tDataTypes
[(
*
pTS
)
->
type
].
bytes
;
(
*
pTS
)
->
value
=
tcalloc
((
*
pTS
)
->
length
,
1
);
memcpy
((
*
pTS
)
->
value
,
&
tsVal
,
(
*
pTS
)
->
length
);
*
num_kvs
+=
1
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
convertJSONBool
(
TAOS_SML_KV
*
pVal
,
char
*
typeStr
,
int64_t
valueInt
,
SSmlLinesInfo
*
info
)
{
if
(
strcasecmp
(
typeStr
,
"bool"
)
!=
0
)
{
tscError
(
"OTD:0x%"
PRIx64
" invalid type(%s) for JSON Bool"
,
info
->
id
,
typeStr
);
return
TSDB_CODE_TSC_INVALID_JSON_TYPE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_BOOL
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
bool
*
)(
pVal
->
value
)
=
valueInt
?
true
:
false
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
convertJSONNumber
(
TAOS_SML_KV
*
pVal
,
char
*
typeStr
,
cJSON
*
value
,
SSmlLinesInfo
*
info
)
{
//tinyint
if
(
strcasecmp
(
typeStr
,
"i8"
)
==
0
||
strcasecmp
(
typeStr
,
"tinyint"
)
==
0
)
{
if
(
!
IS_VALID_TINYINT
(
value
->
valueint
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%"
PRId64
") cannot fit in type(tinyint)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_TINYINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int8_t
*
)(
pVal
->
value
)
=
(
int8_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//smallint
if
(
strcasecmp
(
typeStr
,
"i16"
)
==
0
||
strcasecmp
(
typeStr
,
"smallint"
)
==
0
)
{
if
(
!
IS_VALID_SMALLINT
(
value
->
valueint
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%"
PRId64
") cannot fit in type(smallint)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_SMALLINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int16_t
*
)(
pVal
->
value
)
=
(
int16_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//int
if
(
strcasecmp
(
typeStr
,
"i32"
)
==
0
||
strcasecmp
(
typeStr
,
"int"
)
==
0
)
{
if
(
!
IS_VALID_INT
(
value
->
valueint
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%"
PRId64
") cannot fit in type(int)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_INT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int32_t
*
)(
pVal
->
value
)
=
(
int32_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//bigint
if
(
strcasecmp
(
typeStr
,
"i64"
)
==
0
||
strcasecmp
(
typeStr
,
"bigint"
)
==
0
)
{
if
(
!
IS_VALID_BIGINT
(
value
->
valueint
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%"
PRId64
") cannot fit in type(bigint)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_BIGINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int64_t
*
)(
pVal
->
value
)
=
(
int64_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//float
if
(
strcasecmp
(
typeStr
,
"f32"
)
==
0
||
strcasecmp
(
typeStr
,
"float"
)
==
0
)
{
if
(
!
IS_VALID_FLOAT
(
value
->
valuedouble
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%f) cannot fit in type(float)"
,
info
->
id
,
value
->
valuedouble
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_FLOAT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
float
*
)(
pVal
->
value
)
=
(
float
)(
value
->
valuedouble
);
return
TSDB_CODE_SUCCESS
;
}
//double
if
(
strcasecmp
(
typeStr
,
"f64"
)
==
0
||
strcasecmp
(
typeStr
,
"double"
)
==
0
)
{
if
(
!
IS_VALID_DOUBLE
(
value
->
valuedouble
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%f) cannot fit in type(double)"
,
info
->
id
,
value
->
valuedouble
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_DOUBLE
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
double
*
)(
pVal
->
value
)
=
(
double
)(
value
->
valuedouble
);
return
TSDB_CODE_SUCCESS
;
}
//if reach here means type is unsupported
tscError
(
"OTD:0x%"
PRIx64
" invalid type(%s) for JSON Number"
,
info
->
id
,
typeStr
);
return
TSDB_CODE_TSC_INVALID_JSON_TYPE
;
}
int32_t
convertJSONString
(
TAOS_SML_KV
*
pVal
,
char
*
typeStr
,
cJSON
*
value
,
SSmlLinesInfo
*
info
)
{
if
(
strcasecmp
(
typeStr
,
"binary"
)
==
0
)
{
pVal
->
type
=
TSDB_DATA_TYPE_BINARY
;
}
else
if
(
strcasecmp
(
typeStr
,
"nchar"
)
==
0
)
{
pVal
->
type
=
TSDB_DATA_TYPE_NCHAR
;
}
else
{
tscError
(
"OTD:0x%"
PRIx64
" invalid type(%s) for JSON String"
,
info
->
id
,
typeStr
);
return
TSDB_CODE_TSC_INVALID_JSON_TYPE
;
}
pVal
->
length
=
(
int16_t
)
strlen
(
value
->
valuestring
);
pVal
->
value
=
tcalloc
(
pVal
->
length
+
1
,
1
);
memcpy
(
pVal
->
value
,
value
->
valuestring
,
pVal
->
length
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
parseValueFromJSONObj
(
cJSON
*
root
,
TAOS_SML_KV
*
pVal
,
SSmlLinesInfo
*
info
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int32_t
size
=
cJSON_GetArraySize
(
root
);
if
(
size
!=
OTD_JSON_SUB_FIELDS_NUM
)
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
cJSON
*
value
=
cJSON_GetObjectItem
(
root
,
"value"
);
if
(
value
==
NULL
)
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
cJSON
*
type
=
cJSON_GetObjectItem
(
root
,
"type"
);
if
(
!
cJSON_IsString
(
type
))
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
switch
(
value
->
type
)
{
case
cJSON_True
:
case
cJSON_False
:
{
ret
=
convertJSONBool
(
pVal
,
type
->
valuestring
,
value
->
valueint
,
info
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
break
;
}
case
cJSON_Number
:
{
ret
=
convertJSONNumber
(
pVal
,
type
->
valuestring
,
value
,
info
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
break
;
}
case
cJSON_String
:
{
ret
=
convertJSONString
(
pVal
,
type
->
valuestring
,
value
,
info
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
break
;
}
default:
return
TSDB_CODE_TSC_INVALID_JSON_TYPE
;
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
parseValueFromJSON
(
cJSON
*
root
,
TAOS_SML_KV
*
pVal
,
SSmlLinesInfo
*
info
)
{
int
type
=
root
->
type
;
switch
(
type
)
{
case
cJSON_True
:
case
cJSON_False
:
{
pVal
->
type
=
TSDB_DATA_TYPE_BOOL
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
bool
*
)(
pVal
->
value
)
=
root
->
valueint
?
true
:
false
;
break
;
}
case
cJSON_Number
:
{
//convert default JSON Number type to float
pVal
->
type
=
TSDB_DATA_TYPE_FLOAT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
float
*
)(
pVal
->
value
)
=
(
float
)(
root
->
valuedouble
);
break
;
}
case
cJSON_String
:
{
//convert default JSON String type to nchar
pVal
->
type
=
TSDB_DATA_TYPE_NCHAR
;
//pVal->length = wcslen((wchar_t *)root->valuestring) * TSDB_NCHAR_SIZE;
pVal
->
length
=
(
int16_t
)
strlen
(
root
->
valuestring
);
pVal
->
value
=
tcalloc
(
pVal
->
length
+
1
,
1
);
memcpy
(
pVal
->
value
,
root
->
valuestring
,
pVal
->
length
);
break
;
}
case
cJSON_Object
:
{
int32_t
ret
=
parseValueFromJSONObj
(
root
,
pVal
,
info
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"OTD:0x%"
PRIx64
" Failed to parse timestamp from JSON Obj"
,
info
->
id
);
return
ret
;
}
break
;
}
default:
return
TSDB_CODE_TSC_INVALID_JSON
;
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
parseMetricValueFromJSON
(
cJSON
*
root
,
TAOS_SML_KV
**
pKVs
,
int
*
num_kvs
,
SSmlLinesInfo
*
info
)
{
//skip timestamp
TAOS_SML_KV
*
pVal
=
*
pKVs
+
1
;
char
key
[]
=
OTD_METRIC_VALUE_COLUMN_NAME
;
cJSON
*
metricVal
=
cJSON_GetObjectItem
(
root
,
"value"
);
if
(
metricVal
==
NULL
)
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
int32_t
ret
=
parseValueFromJSON
(
metricVal
,
pVal
,
info
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
pVal
->
key
=
tcalloc
(
sizeof
(
key
),
1
);
memcpy
(
pVal
->
key
,
key
,
sizeof
(
key
));
*
num_kvs
+=
1
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
parseTagsFromJSON
(
cJSON
*
root
,
TAOS_SML_KV
**
pKVs
,
int
*
num_kvs
,
char
**
childTableName
,
SSmlLinesInfo
*
info
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
cJSON
*
tags
=
cJSON_GetObjectItem
(
root
,
"tags"
);
if
(
tags
==
NULL
||
tags
->
type
!=
cJSON_Object
)
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
//only pick up the first ID value as child table name
cJSON
*
id
=
cJSON_GetObjectItem
(
tags
,
"ID"
);
if
(
id
!=
NULL
)
{
size_t
idLen
=
strlen
(
id
->
valuestring
);
ret
=
isValidChildTableName
(
id
->
valuestring
,
(
int16_t
)
idLen
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
*
childTableName
=
tcalloc
(
idLen
+
1
,
sizeof
(
char
));
memcpy
(
*
childTableName
,
id
->
valuestring
,
idLen
);
//remove all ID fields from tags list no case sensitive
while
(
id
!=
NULL
)
{
cJSON_DeleteItemFromObject
(
tags
,
"ID"
);
id
=
cJSON_GetObjectItem
(
tags
,
"ID"
);
}
}
int32_t
tagNum
=
cJSON_GetArraySize
(
tags
);
//at least one tag pair required
if
(
tagNum
<=
0
)
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
//allocate memory for tags
*
pKVs
=
tcalloc
(
tagNum
,
sizeof
(
TAOS_SML_KV
));
TAOS_SML_KV
*
pkv
=
*
pKVs
;
for
(
int32_t
i
=
0
;
i
<
tagNum
;
++
i
)
{
cJSON
*
tag
=
cJSON_GetArrayItem
(
tags
,
i
);
if
(
tag
==
NULL
)
{
return
TSDB_CODE_TSC_INVALID_JSON
;
}
//key
size_t
keyLen
=
strlen
(
tag
->
string
);
pkv
->
key
=
tcalloc
(
keyLen
+
1
,
sizeof
(
char
));
strncpy
(
pkv
->
key
,
tag
->
string
,
keyLen
);
//value
ret
=
parseValueFromJSON
(
tag
,
pkv
,
info
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
*
num_kvs
+=
1
;
pkv
++
;
}
return
ret
;
}
int32_t
tscParseJSONPayload
(
cJSON
*
root
,
TAOS_SML_DATA_POINT
*
pSml
,
SSmlLinesInfo
*
info
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
if
(
!
cJSON_IsObject
(
root
))
{
tscError
(
"OTD:0x%"
PRIx64
" data point needs to be JSON object"
,
info
->
id
);
return
TSDB_CODE_TSC_INVALID_JSON
;
}
int32_t
size
=
cJSON_GetArraySize
(
root
);
//outmost json fields has to be exactly 4
if
(
size
!=
OTD_JSON_FIELDS_NUM
)
{
tscError
(
"OTD:0x%"
PRIx64
" Invalid number of JSON fields in data point %d"
,
info
->
id
,
size
);
return
TSDB_CODE_TSC_INVALID_JSON
;
}
//Parse metric
ret
=
parseMetricFromJSON
(
root
,
pSml
,
info
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"OTD:0x%"
PRIx64
" Unable to parse metric from JSON payload"
,
info
->
id
);
return
ret
;
}
tscDebug
(
"OTD:0x%"
PRIx64
" Parse metric from JSON payload finished"
,
info
->
id
);
//Parse timestamp
ret
=
parseTimestampFromJSON
(
root
,
&
pSml
->
fields
,
&
pSml
->
fieldNum
,
info
);
if
(
ret
)
{
tscError
(
"OTD:0x%"
PRIx64
" Unable to parse timestamp from JSON payload"
,
info
->
id
);
return
ret
;
}
tscDebug
(
"OTD:0x%"
PRIx64
" Parse timestamp from JSON payload finished"
,
info
->
id
);
//Parse metric value
ret
=
parseMetricValueFromJSON
(
root
,
&
pSml
->
fields
,
&
pSml
->
fieldNum
,
info
);
if
(
ret
)
{
tscError
(
"OTD:0x%"
PRIx64
" Unable to parse metric value from JSON payload"
,
info
->
id
);
return
ret
;
}
tscDebug
(
"OTD:0x%"
PRIx64
" Parse metric value from JSON payload finished"
,
info
->
id
);
//Parse tags
ret
=
parseTagsFromJSON
(
root
,
&
pSml
->
tags
,
&
pSml
->
tagNum
,
&
pSml
->
childTableName
,
info
);
if
(
ret
)
{
tscError
(
"OTD:0x%"
PRIx64
" Unable to parse tags from JSON payload"
,
info
->
id
);
return
ret
;
}
tscDebug
(
"OTD:0x%"
PRIx64
" Parse tags from JSON payload finished"
,
info
->
id
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
tscParseMultiJSONPayload
(
char
*
payload
,
SArray
*
points
,
SSmlLinesInfo
*
info
)
{
int32_t
payloadNum
,
ret
;
ret
=
TSDB_CODE_SUCCESS
;
if
(
payload
==
NULL
)
{
tscError
(
"OTD:0x%"
PRIx64
" empty JSON Payload"
,
info
->
id
);
return
TSDB_CODE_TSC_INVALID_JSON
;
}
cJSON
*
root
=
cJSON_Parse
(
payload
);
//multiple data points must be sent in JSON array
if
(
cJSON_IsObject
(
root
))
{
payloadNum
=
1
;
}
else
if
(
cJSON_IsArray
(
root
))
{
payloadNum
=
cJSON_GetArraySize
(
root
);
}
else
{
tscError
(
"OTD:0x%"
PRIx64
" Invalid JSON Payload"
,
info
->
id
);
ret
=
TSDB_CODE_TSC_INVALID_JSON
;
goto
PARSE_JSON_OVER
;
}
for
(
int32_t
i
=
0
;
i
<
payloadNum
;
++
i
)
{
TAOS_SML_DATA_POINT
point
=
{
0
};
cJSON
*
dataPoint
=
(
payloadNum
==
1
)
?
root
:
cJSON_GetArrayItem
(
root
,
i
);
ret
=
tscParseJSONPayload
(
dataPoint
,
&
point
,
info
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"OTD:0x%"
PRIx64
" JSON data point parse failed"
,
info
->
id
);
destroySmlDataPoint
(
&
point
);
goto
PARSE_JSON_OVER
;
}
else
{
tscDebug
(
"OTD:0x%"
PRIx64
" JSON data point parse success"
,
info
->
id
);
}
taosArrayPush
(
points
,
&
point
);
}
PARSE_JSON_OVER:
cJSON_Delete
(
root
);
return
ret
;
}
int
taos_insert_json_payload
(
TAOS
*
taos
,
char
*
payload
)
{
int32_t
code
=
0
;
SSmlLinesInfo
*
info
=
tcalloc
(
1
,
sizeof
(
SSmlLinesInfo
));
info
->
id
=
genUID
();
if
(
payload
==
NULL
)
{
tscError
(
"OTD:0x%"
PRIx64
" taos_insert_json_payload payload is NULL"
,
info
->
id
);
tfree
(
info
);
code
=
TSDB_CODE_TSC_APP_ERROR
;
return
code
;
}
SArray
*
lpPoints
=
taosArrayInit
(
1
,
sizeof
(
TAOS_SML_DATA_POINT
));
if
(
lpPoints
==
NULL
)
{
tscError
(
"OTD:0x%"
PRIx64
" taos_insert_json_payload failed to allocate memory"
,
info
->
id
);
tfree
(
info
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
tscDebug
(
"OTD:0x%"
PRIx64
" taos_insert_telnet_lines begin inserting %d points"
,
info
->
id
,
1
);
code
=
tscParseMultiJSONPayload
(
payload
,
lpPoints
,
info
);
size_t
numPoints
=
taosArrayGetSize
(
lpPoints
);
if
(
code
!=
0
)
{
goto
cleanup
;
}
TAOS_SML_DATA_POINT
*
points
=
TARRAY_GET_START
(
lpPoints
);
code
=
tscSmlInsert
(
taos
,
points
,
(
int
)
numPoints
,
info
);
if
(
code
!=
0
)
{
tscError
(
"OTD:0x%"
PRIx64
" taos_insert_json_payload error: %s"
,
info
->
id
,
tstrerror
((
code
)));
}
cleanup:
tscDebug
(
"OTD:0x%"
PRIx64
" taos_insert_json_payload finish inserting 1 Point. code: %d"
,
info
->
id
,
code
);
points
=
TARRAY_GET_START
(
lpPoints
);
numPoints
=
taosArrayGetSize
(
lpPoints
);
for
(
int
i
=
0
;
i
<
numPoints
;
++
i
)
{
destroySmlDataPoint
(
points
+
i
);
}
taosArrayDestroy
(
lpPoints
);
tfree
(
info
);
return
code
;
}
src/connector/python/taos/cinterface.py
浏览文件 @
13d8bb83
...
@@ -835,8 +835,14 @@ def taos_insert_telnet_lines(connection, lines):
...
@@ -835,8 +835,14 @@ def taos_insert_telnet_lines(connection, lines):
p_lines
=
lines_type
(
*
lines
)
p_lines
=
lines_type
(
*
lines
)
errno
=
_libtaos
.
taos_insert_telnet_lines
(
connection
,
p_lines
,
num_of_lines
)
errno
=
_libtaos
.
taos_insert_telnet_lines
(
connection
,
p_lines
,
num_of_lines
)
if
errno
!=
0
:
if
errno
!=
0
:
raise
LinesError
(
"insert telnet lines error"
,
errno
)
raise
Telnet
LinesError
(
"insert telnet lines error"
,
errno
)
def
taos_insert_json_payload
(
connection
,
payload
):
# type: (c_void_p, list[str] | tuple(str)) -> None
payload
=
payload
.
encode
(
"utf-8"
)
errno
=
_libtaos
.
taos_insert_json_payload
(
connection
,
payload
)
if
errno
!=
0
:
raise
JsonPayloadError
(
"insert json payload error"
,
errno
)
class
CTaosInterface
(
object
):
class
CTaosInterface
(
object
):
def
__init__
(
self
,
config
=
None
):
def
__init__
(
self
,
config
=
None
):
...
...
src/connector/python/taos/connection.py
浏览文件 @
13d8bb83
...
@@ -154,6 +154,25 @@ class TaosConnection(object):
...
@@ -154,6 +154,25 @@ class TaosConnection(object):
"""
"""
return
taos_insert_telnet_lines
(
self
.
_conn
,
lines
)
return
taos_insert_telnet_lines
(
self
.
_conn
,
lines
)
def
insert_json_payload
(
self
,
payload
):
"""OpenTSDB HTTP JSON format support
## Example
"{
"metric": "cpu_load_0",
"timestamp": 1626006833610123,
"value": 55.5,
"tags":
{
"host": "ubuntu",
"interface": "eth0",
"Id": "tb0"
}
}"
"""
return
taos_insert_json_payload
(
self
.
_conn
,
payload
)
def
cursor
(
self
):
def
cursor
(
self
):
# type: () -> TaosCursor
# type: () -> TaosCursor
"""Return a new Cursor object using the connection."""
"""Return a new Cursor object using the connection."""
...
...
src/connector/python/taos/error.py
浏览文件 @
13d8bb83
...
@@ -84,3 +84,13 @@ class LinesError(DatabaseError):
...
@@ -84,3 +84,13 @@ class LinesError(DatabaseError):
"""taos_insert_lines errors."""
"""taos_insert_lines errors."""
pass
pass
class
TelnetLinesError
(
DatabaseError
):
"""taos_insert_telnet_lines errors."""
pass
class
JsonPayloadError
(
DatabaseError
):
"""taos_insert_json_payload errors."""
pass
src/inc/taos.h
浏览文件 @
13d8bb83
...
@@ -174,6 +174,8 @@ DLL_EXPORT int taos_insert_lines(TAOS* taos, char* lines[], int numLines);
...
@@ -174,6 +174,8 @@ DLL_EXPORT int taos_insert_lines(TAOS* taos, char* lines[], int numLines);
DLL_EXPORT
int
taos_insert_telnet_lines
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
);
DLL_EXPORT
int
taos_insert_telnet_lines
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
);
DLL_EXPORT
int
taos_insert_json_payload
(
TAOS
*
taos
,
char
*
payload
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
src/inc/taoserror.h
浏览文件 @
13d8bb83
...
@@ -108,6 +108,9 @@ int32_t* taosGetErrno();
...
@@ -108,6 +108,9 @@ int32_t* taosGetErrno();
#define TSDB_CODE_TSC_INVALID_TAG_LENGTH TAOS_DEF_ERROR_CODE(0, 0x021E) //"Invalid tag length")
#define TSDB_CODE_TSC_INVALID_TAG_LENGTH TAOS_DEF_ERROR_CODE(0, 0x021E) //"Invalid tag length")
#define TSDB_CODE_TSC_INVALID_COLUMN_LENGTH TAOS_DEF_ERROR_CODE(0, 0x021F) //"Invalid column length")
#define TSDB_CODE_TSC_INVALID_COLUMN_LENGTH TAOS_DEF_ERROR_CODE(0, 0x021F) //"Invalid column length")
#define TSDB_CODE_TSC_DUP_TAG_NAMES TAOS_DEF_ERROR_CODE(0, 0x0220) //"duplicated tag names")
#define TSDB_CODE_TSC_DUP_TAG_NAMES TAOS_DEF_ERROR_CODE(0, 0x0220) //"duplicated tag names")
#define TSDB_CODE_TSC_INVALID_JSON TAOS_DEF_ERROR_CODE(0, 0x0221) //"Invalid JSON format")
#define TSDB_CODE_TSC_INVALID_JSON_TYPE TAOS_DEF_ERROR_CODE(0, 0x0222) //"Invalid JSON data type")
#define TSDB_CODE_TSC_VALUE_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x0223) //"Value out of range")
// mnode
// mnode
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed")
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed")
...
...
src/util/src/terror.c
浏览文件 @
13d8bb83
...
@@ -116,6 +116,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DUP_COL_NAMES, "duplicated column nam
...
@@ -116,6 +116,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DUP_COL_NAMES, "duplicated column nam
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSC_INVALID_TAG_LENGTH
,
"Invalid tag length"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSC_INVALID_TAG_LENGTH
,
"Invalid tag length"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSC_INVALID_COLUMN_LENGTH
,
"Invalid column length"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSC_INVALID_COLUMN_LENGTH
,
"Invalid column length"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSC_DUP_TAG_NAMES
,
"duplicated tag names"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSC_DUP_TAG_NAMES
,
"duplicated tag names"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSC_INVALID_JSON
,
"Invalid JSON format"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSC_INVALID_JSON_TYPE
,
"Invalid JSON data type"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
,
"Value out of range"
)
// mnode
// mnode
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_MSG_NOT_PROCESSED
,
"Message not processed"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_MSG_NOT_PROCESSED
,
"Message not processed"
)
...
...
tests/examples/JDBC/JDBCDemo/pom.xml
浏览文件 @
13d8bb83
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
<dependency>
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.3
1
</version>
<version>
2.0.3
4
</version>
</dependency>
</dependency>
</dependencies>
</dependencies>
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcDemo.java
浏览文件 @
13d8bb83
...
@@ -7,6 +7,9 @@ public class JdbcDemo {
...
@@ -7,6 +7,9 @@ public class JdbcDemo {
private
static
String
host
;
private
static
String
host
;
private
static
final
String
dbName
=
"test"
;
private
static
final
String
dbName
=
"test"
;
private
static
final
String
tbName
=
"weather"
;
private
static
final
String
tbName
=
"weather"
;
private
static
final
String
user
=
"root"
;
private
static
final
String
password
=
"taosdata"
;
private
Connection
connection
;
private
Connection
connection
;
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
@@ -30,10 +33,9 @@ public class JdbcDemo {
...
@@ -30,10 +33,9 @@ public class JdbcDemo {
}
}
private
void
init
()
{
private
void
init
()
{
final
String
url
=
"jdbc:TAOS://"
+
host
+
":6030/?user=
root&password=taosdata"
;
final
String
url
=
"jdbc:TAOS://"
+
host
+
":6030/?user=
"
+
user
+
"&password="
+
password
;
// get connection
// get connection
try
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Properties
properties
=
new
Properties
();
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"charset"
,
"UTF-8"
);
properties
.
setProperty
(
"charset"
,
"UTF-8"
);
properties
.
setProperty
(
"locale"
,
"en_US.UTF-8"
);
properties
.
setProperty
(
"locale"
,
"en_US.UTF-8"
);
...
@@ -42,8 +44,7 @@ public class JdbcDemo {
...
@@ -42,8 +44,7 @@ public class JdbcDemo {
connection
=
DriverManager
.
getConnection
(
url
,
properties
);
connection
=
DriverManager
.
getConnection
(
url
,
properties
);
if
(
connection
!=
null
)
if
(
connection
!=
null
)
System
.
out
.
println
(
"[ OK ] Connection established."
);
System
.
out
.
println
(
"[ OK ] Connection established."
);
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
"[ ERROR! ] Connection establish failed."
);
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
...
@@ -74,7 +75,7 @@ public class JdbcDemo {
...
@@ -74,7 +75,7 @@ public class JdbcDemo {
}
}
private
void
select
()
{
private
void
select
()
{
final
String
sql
=
"select * from "
+
dbName
+
"."
+
tbName
;
final
String
sql
=
"select * from "
+
dbName
+
"."
+
tbName
;
executeQuery
(
sql
);
executeQuery
(
sql
);
}
}
...
@@ -89,8 +90,6 @@ public class JdbcDemo {
...
@@ -89,8 +90,6 @@ public class JdbcDemo {
}
}
}
}
/************************************************************************/
private
void
executeQuery
(
String
sql
)
{
private
void
executeQuery
(
String
sql
)
{
long
start
=
System
.
currentTimeMillis
();
long
start
=
System
.
currentTimeMillis
();
try
(
Statement
statement
=
connection
.
createStatement
())
{
try
(
Statement
statement
=
connection
.
createStatement
())
{
...
@@ -117,7 +116,6 @@ public class JdbcDemo {
...
@@ -117,7 +116,6 @@ public class JdbcDemo {
}
}
}
}
private
void
printSql
(
String
sql
,
boolean
succeed
,
long
cost
)
{
private
void
printSql
(
String
sql
,
boolean
succeed
,
long
cost
)
{
System
.
out
.
println
(
"[ "
+
(
succeed
?
"OK"
:
"ERROR!"
)
+
" ] time cost: "
+
cost
+
" ms, execute statement ====> "
+
sql
);
System
.
out
.
println
(
"[ "
+
(
succeed
?
"OK"
:
"ERROR!"
)
+
" ] time cost: "
+
cost
+
" ms, execute statement ====> "
+
sql
);
}
}
...
@@ -132,7 +130,6 @@ public class JdbcDemo {
...
@@ -132,7 +130,6 @@ public class JdbcDemo {
long
end
=
System
.
currentTimeMillis
();
long
end
=
System
.
currentTimeMillis
();
printSql
(
sql
,
false
,
(
end
-
start
));
printSql
(
sql
,
false
,
(
end
-
start
));
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
...
@@ -141,5 +138,4 @@ public class JdbcDemo {
...
@@ -141,5 +138,4 @@ public class JdbcDemo {
System
.
exit
(
0
);
System
.
exit
(
0
);
}
}
}
}
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java
浏览文件 @
13d8bb83
...
@@ -4,14 +4,15 @@ import java.sql.*;
...
@@ -4,14 +4,15 @@ import java.sql.*;
import
java.util.Properties
;
import
java.util.Properties
;
public
class
JdbcRestfulDemo
{
public
class
JdbcRestfulDemo
{
private
static
final
String
host
=
"127.0.0.1"
;
private
static
final
String
host
=
"localhost"
;
private
static
final
String
dbname
=
"test"
;
private
static
final
String
user
=
"root"
;
private
static
final
String
password
=
"taosdata"
;
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
try
{
try
{
// load JDBC-restful driver
Class
.
forName
(
"com.taosdata.jdbc.rs.RestfulDriver"
);
// use port 6041 in url when use JDBC-restful
// use port 6041 in url when use JDBC-restful
String
url
=
"jdbc:TAOS-RS://"
+
host
+
":6041/?user=
root&password=taosdata"
;
String
url
=
"jdbc:TAOS-RS://"
+
host
+
":6041/?user=
"
+
user
+
"&password="
+
password
;
Properties
properties
=
new
Properties
();
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"charset"
,
"UTF-8"
);
properties
.
setProperty
(
"charset"
,
"UTF-8"
);
...
@@ -21,12 +22,12 @@ public class JdbcRestfulDemo {
...
@@ -21,12 +22,12 @@ public class JdbcRestfulDemo {
Connection
conn
=
DriverManager
.
getConnection
(
url
,
properties
);
Connection
conn
=
DriverManager
.
getConnection
(
url
,
properties
);
Statement
stmt
=
conn
.
createStatement
();
Statement
stmt
=
conn
.
createStatement
();
stmt
.
execute
(
"drop database if exists
restful_test"
);
stmt
.
execute
(
"drop database if exists
"
+
dbname
);
stmt
.
execute
(
"create database if not exists
restful_test"
);
stmt
.
execute
(
"create database if not exists
"
+
dbname
);
stmt
.
execute
(
"use
restful_test"
);
stmt
.
execute
(
"use
"
+
dbname
);
stmt
.
execute
(
"create table
restful_test
.weather(ts timestamp, temperature float) tags(location nchar(64))"
);
stmt
.
execute
(
"create table
"
+
dbname
+
"
.weather(ts timestamp, temperature float) tags(location nchar(64))"
);
stmt
.
executeUpdate
(
"insert into t1 using
restful_test
.weather tags('北京') values(now, 18.2)"
);
stmt
.
executeUpdate
(
"insert into t1 using
"
+
dbname
+
"
.weather tags('北京') values(now, 18.2)"
);
ResultSet
rs
=
stmt
.
executeQuery
(
"select * from
restful_test
.weather"
);
ResultSet
rs
=
stmt
.
executeQuery
(
"select * from
"
+
dbname
+
"
.weather"
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
ResultSetMetaData
meta
=
rs
.
getMetaData
();
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
...
@@ -38,8 +39,6 @@ public class JdbcRestfulDemo {
...
@@ -38,8 +39,6 @@ public class JdbcRestfulDemo {
rs
.
close
();
rs
.
close
();
stmt
.
close
();
stmt
.
close
();
conn
.
close
();
conn
.
close
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java
浏览文件 @
13d8bb83
...
@@ -34,9 +34,8 @@ public class SubscribeDemo {
...
@@ -34,9 +34,8 @@ public class SubscribeDemo {
System
.
out
.
println
(
usage
);
System
.
out
.
println
(
usage
);
return
;
return
;
}
}
/*********************************************************************************************/
try
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Properties
properties
=
new
Properties
();
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
...
...
tests/examples/JDBC/springbootdemo/pom.xml
浏览文件 @
13d8bb83
...
@@ -60,12 +60,15 @@
...
@@ -60,12 +60,15 @@
</exclusions>
</exclusions>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.28
</version>
<version>
2.0.34
</version>
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/src/main/resources/taos-jdbcdriver-2.0.28-dist.jar</systemPath>-->
</dependency>
</dependency>
<dependency>
<dependency>
...
...
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/SpringbootdemoApplication.java
浏览文件 @
13d8bb83
...
@@ -4,7 +4,7 @@ import org.mybatis.spring.annotation.MapperScan;
...
@@ -4,7 +4,7 @@ import org.mybatis.spring.annotation.MapperScan;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@MapperScan
(
basePackages
=
{
"com.taosdata.example.springbootdemo
.dao
"
})
@MapperScan
(
basePackages
=
{
"com.taosdata.example.springbootdemo"
})
@SpringBootApplication
@SpringBootApplication
public
class
SpringbootdemoApplication
{
public
class
SpringbootdemoApplication
{
...
...
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/controller/WeatherController.java
浏览文件 @
13d8bb83
...
@@ -15,35 +15,21 @@ public class WeatherController {
...
@@ -15,35 +15,21 @@ public class WeatherController {
@Autowired
@Autowired
private
WeatherService
weatherService
;
private
WeatherService
weatherService
;
/**
@GetMapping
(
"/lastOne"
)
* create database and table
public
Weather
lastOne
()
{
*
return
weatherService
.
lastOne
();
* @return
}
*/
@GetMapping
(
"/init"
)
@GetMapping
(
"/init"
)
public
int
init
()
{
public
int
init
()
{
return
weatherService
.
init
();
return
weatherService
.
init
();
}
}
/**
* Pagination Query
*
* @param limit
* @param offset
* @return
*/
@GetMapping
(
"/{limit}/{offset}"
)
@GetMapping
(
"/{limit}/{offset}"
)
public
List
<
Weather
>
queryWeather
(
@PathVariable
Long
limit
,
@PathVariable
Long
offset
)
{
public
List
<
Weather
>
queryWeather
(
@PathVariable
Long
limit
,
@PathVariable
Long
offset
)
{
return
weatherService
.
query
(
limit
,
offset
);
return
weatherService
.
query
(
limit
,
offset
);
}
}
/**
* upload single weather info
*
* @param temperature
* @param humidity
* @return
*/
@PostMapping
(
"/{temperature}/{humidity}"
)
@PostMapping
(
"/{temperature}/{humidity}"
)
public
int
saveWeather
(
@PathVariable
float
temperature
,
@PathVariable
float
humidity
)
{
public
int
saveWeather
(
@PathVariable
float
temperature
,
@PathVariable
float
humidity
)
{
return
weatherService
.
save
(
temperature
,
humidity
);
return
weatherService
.
save
(
temperature
,
humidity
);
...
...
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.java
浏览文件 @
13d8bb83
...
@@ -8,6 +8,8 @@ import java.util.Map;
...
@@ -8,6 +8,8 @@ import java.util.Map;
public
interface
WeatherMapper
{
public
interface
WeatherMapper
{
Map
<
String
,
Object
>
lastOne
();
void
dropDB
();
void
dropDB
();
void
createDB
();
void
createDB
();
...
...
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml
浏览文件 @
13d8bb83
...
@@ -9,20 +9,48 @@
...
@@ -9,20 +9,48 @@
<result
column=
"humidity"
jdbcType=
"FLOAT"
property=
"humidity"
/>
<result
column=
"humidity"
jdbcType=
"FLOAT"
property=
"humidity"
/>
</resultMap>
</resultMap>
<select
id=
"lastOne"
resultType=
"java.util.Map"
>
select last_row(*), location, groupid
from test.weather
</select>
<update
id=
"dropDB"
>
<update
id=
"dropDB"
>
drop database if exists test
drop
database if exists test
</update>
</update>
<update
id=
"createDB"
>
<update
id=
"createDB"
>
create database if not exists test
create
database if not exists test
</update>
</update>
<update
id=
"createSuperTable"
>
<update
id=
"createSuperTable"
>
create table if not exists test.weather(ts timestamp, temperature float, humidity float) tags(location nchar(64), groupId int)
create table if not exists test.weather
(
ts
timestamp,
temperature
float,
humidity
float,
note
binary
(
64
)) tags
(
location nchar
(
64
), groupId int)
</update>
</update>
<update
id=
"createTable"
parameterType=
"com.taosdata.example.springbootdemo.domain.Weather"
>
<update
id=
"createTable"
parameterType=
"com.taosdata.example.springbootdemo.domain.Weather"
>
create table if not exists test.t#{groupId} using test.weather tags(#{location}, #{groupId})
create table if not exists test.t#{groupId} using test.weather tags
(
#{location},
#{groupId}
)
</update>
</update>
<select
id=
"select"
resultMap=
"BaseResultMap"
>
<select
id=
"select"
resultMap=
"BaseResultMap"
>
...
@@ -36,25 +64,29 @@
...
@@ -36,25 +64,29 @@
</select>
</select>
<insert
id=
"insert"
parameterType=
"com.taosdata.example.springbootdemo.domain.Weather"
>
<insert
id=
"insert"
parameterType=
"com.taosdata.example.springbootdemo.domain.Weather"
>
insert into test.t#{groupId} (ts, temperature, humidity) values (#{ts}, ${temperature}, ${humidity})
insert into test.t#{groupId} (ts, temperature, humidity, note)
values (#{ts}, ${temperature}, ${humidity}, #{note})
</insert>
</insert>
<select
id=
"getSubTables"
resultType=
"String"
>
<select
id=
"getSubTables"
resultType=
"String"
>
select tbname from test.weather
select tbname
from test.weather
</select>
</select>
<select
id=
"count"
resultType=
"int"
>
<select
id=
"count"
resultType=
"int"
>
select count(*) from test.weather
select count(*)
from test.weather
</select>
</select>
<resultMap
id=
"avgResultSet"
type=
"com.taosdata.example.springbootdemo.domain.Weather"
>
<resultMap
id=
"avgResultSet"
type=
"com.taosdata.example.springbootdemo.domain.Weather"
>
<id
column=
"ts"
jdbcType=
"TIMESTAMP"
property=
"ts"
/>
<id
column=
"ts"
jdbcType=
"TIMESTAMP"
property=
"ts"
/>
<result
column=
"avg(temperature)"
jdbcType=
"FLOAT"
property=
"temperature"
/>
<result
column=
"avg(temperature)"
jdbcType=
"FLOAT"
property=
"temperature"
/>
<result
column=
"avg(humidity)"
jdbcType=
"FLOAT"
property=
"humidity"
/>
<result
column=
"avg(humidity)"
jdbcType=
"FLOAT"
property=
"humidity"
/>
</resultMap>
</resultMap>
<select
id=
"avg"
resultMap=
"avgResultSet"
>
<select
id=
"avg"
resultMap=
"avgResultSet"
>
select avg(temperature), avg(humidity)from test.weather interval(1m)
select avg(temperature), avg(humidity)
from test.weather interval(1m)
</select>
</select>
</mapper>
</mapper>
\ No newline at end of file
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/domain/Weather.java
浏览文件 @
13d8bb83
...
@@ -11,6 +11,7 @@ public class Weather {
...
@@ -11,6 +11,7 @@ public class Weather {
private
Float
temperature
;
private
Float
temperature
;
private
Float
humidity
;
private
Float
humidity
;
private
String
location
;
private
String
location
;
private
String
note
;
private
int
groupId
;
private
int
groupId
;
public
Weather
()
{
public
Weather
()
{
...
@@ -61,4 +62,12 @@ public class Weather {
...
@@ -61,4 +62,12 @@ public class Weather {
public
void
setGroupId
(
int
groupId
)
{
public
void
setGroupId
(
int
groupId
)
{
this
.
groupId
=
groupId
;
this
.
groupId
=
groupId
;
}
}
public
String
getNote
()
{
return
note
;
}
public
void
setNote
(
String
note
)
{
this
.
note
=
note
;
}
}
}
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/service/WeatherService.java
浏览文件 @
13d8bb83
...
@@ -29,6 +29,7 @@ public class WeatherService {
...
@@ -29,6 +29,7 @@ public class WeatherService {
Weather
weather
=
new
Weather
(
new
Timestamp
(
ts
+
(
thirtySec
*
i
)),
30
*
random
.
nextFloat
(),
random
.
nextInt
(
100
));
Weather
weather
=
new
Weather
(
new
Timestamp
(
ts
+
(
thirtySec
*
i
)),
30
*
random
.
nextFloat
(),
random
.
nextInt
(
100
));
weather
.
setLocation
(
locations
[
random
.
nextInt
(
locations
.
length
)]);
weather
.
setLocation
(
locations
[
random
.
nextInt
(
locations
.
length
)]);
weather
.
setGroupId
(
i
%
locations
.
length
);
weather
.
setGroupId
(
i
%
locations
.
length
);
weather
.
setNote
(
"note-"
+
i
);
weatherMapper
.
createTable
(
weather
);
weatherMapper
.
createTable
(
weather
);
count
+=
weatherMapper
.
insert
(
weather
);
count
+=
weatherMapper
.
insert
(
weather
);
}
}
...
@@ -58,4 +59,21 @@ public class WeatherService {
...
@@ -58,4 +59,21 @@ public class WeatherService {
public
List
<
Weather
>
avg
()
{
public
List
<
Weather
>
avg
()
{
return
weatherMapper
.
avg
();
return
weatherMapper
.
avg
();
}
}
public
Weather
lastOne
()
{
Map
<
String
,
Object
>
result
=
weatherMapper
.
lastOne
();
long
ts
=
(
long
)
result
.
get
(
"ts"
);
float
temperature
=
(
float
)
result
.
get
(
"temperature"
);
float
humidity
=
(
float
)
result
.
get
(
"humidity"
);
String
note
=
(
String
)
result
.
get
(
"note"
);
int
groupId
=
(
int
)
result
.
get
(
"groupid"
);
String
location
=
(
String
)
result
.
get
(
"location"
);
Weather
weather
=
new
Weather
(
new
Timestamp
(
ts
),
temperature
,
humidity
);
weather
.
setNote
(
note
);
weather
.
setGroupId
(
groupId
);
weather
.
setLocation
(
location
);
return
weather
;
}
}
}
tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/util/TaosAspect.java
0 → 100644
浏览文件 @
13d8bb83
package
com.taosdata.example.springbootdemo.util
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.springframework.stereotype.Component
;
import
java.sql.Timestamp
;
import
java.util.Map
;
@Aspect
@Component
public
class
TaosAspect
{
@Around
(
"execution(java.util.Map<String,Object> com.taosdata.example.springbootdemo.dao.*.*(..))"
)
public
Object
handleType
(
ProceedingJoinPoint
joinPoint
)
{
Map
<
String
,
Object
>
result
=
null
;
try
{
result
=
(
Map
<
String
,
Object
>)
joinPoint
.
proceed
();
for
(
String
key
:
result
.
keySet
())
{
Object
obj
=
result
.
get
(
key
);
if
(
obj
instanceof
byte
[])
{
obj
=
new
String
((
byte
[])
obj
);
result
.
put
(
key
,
obj
);
}
if
(
obj
instanceof
Timestamp
)
{
obj
=
((
Timestamp
)
obj
).
getTime
();
result
.
put
(
key
,
obj
);
}
}
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
}
tests/examples/JDBC/springbootdemo/src/main/resources/application.properties
浏览文件 @
13d8bb83
# datasource config - JDBC-JNI
# datasource config - JDBC-JNI
#spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver
#spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver
#spring.datasource.url=jdbc:TAOS://
127.0.0.1:6030/test
?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
#spring.datasource.url=jdbc:TAOS://
localhost:6030/
?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
#spring.datasource.username=root
#spring.datasource.username=root
#spring.datasource.password=taosdata
#spring.datasource.password=taosdata
# datasource config - JDBC-RESTful
# datasource config - JDBC-RESTful
spring.datasource.driver-class-name
=
com.taosdata.jdbc.rs.RestfulDriver
spring.datasource.driver-class-name
=
com.taosdata.jdbc.rs.RestfulDriver
spring.datasource.url
=
jdbc:TAOS-RS://
master
:6041/test?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
spring.datasource.url
=
jdbc:TAOS-RS://
localhsot
:6041/test?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
spring.datasource.username
=
root
spring.datasource.username
=
root
spring.datasource.password
=
taosdata
spring.datasource.password
=
taosdata
spring.datasource.druid.initial-size
=
5
spring.datasource.druid.initial-size
=
5
spring.datasource.druid.min-idle
=
5
spring.datasource.druid.min-idle
=
5
spring.datasource.druid.max-active
=
5
spring.datasource.druid.max-active
=
5
spring.datasource.druid.max-wait
=
30000
spring.datasource.druid.max-wait
=
30000
spring.datasource.druid.validation-query
=
select server_status();
spring.datasource.druid.validation-query
=
select server_status();
spring.aop.auto
=
true
spring.aop.proxy-target-class
=
true
#mybatis
#mybatis
mybatis.mapper-locations
=
classpath:mapper/*.xml
mybatis.mapper-locations
=
classpath:mapper/*.xml
logging.level.com.taosdata.jdbc.springbootdemo.dao
=
debug
logging.level.com.taosdata.jdbc.springbootdemo.dao
=
debug
tests/examples/c/apitest.c
浏览文件 @
13d8bb83
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
// to compile: gcc -o apitest apitest.c -ltaos
// to compile: gcc -o apitest apitest.c -ltaos
#include "taoserror.h"
#include "taoserror.h"
#include "cJSON.h"
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -1020,7 +1021,7 @@ int32_t verify_schema_less(TAOS* taos) {
...
@@ -1020,7 +1021,7 @@ int32_t verify_schema_less(TAOS* taos) {
void
verify_telnet_insert
(
TAOS
*
taos
)
{
void
verify_telnet_insert
(
TAOS
*
taos
)
{
TAOS_RES
*
result
;
TAOS_RES
*
result
;
result
=
taos_query
(
taos
,
"drop database if exists
test
;"
);
result
=
taos_query
(
taos
,
"drop database if exists
db
;"
);
taos_free_result
(
result
);
taos_free_result
(
result
);
usleep
(
100000
);
usleep
(
100000
);
result
=
taos_query
(
taos
,
"create database db precision 'ms';"
);
result
=
taos_query
(
taos
,
"create database db precision 'ms';"
);
...
@@ -1038,7 +1039,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1038,7 +1039,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines0
,
3
);
code
=
taos_insert_telnet_lines
(
taos
,
lines0
,
3
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines0
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
/* timestamp */
/* timestamp */
...
@@ -1052,7 +1053,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1052,7 +1053,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines1
,
6
);
code
=
taos_insert_telnet_lines
(
taos
,
lines1
,
6
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines1
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
/* metric value */
/* metric value */
...
@@ -1063,7 +1064,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1063,7 +1064,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines2_0
,
2
);
code
=
taos_insert_telnet_lines
(
taos
,
lines2_0
,
2
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines2_0
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
//smallint
//smallint
...
@@ -1073,7 +1074,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1073,7 +1074,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines2_1
,
2
);
code
=
taos_insert_telnet_lines
(
taos
,
lines2_1
,
2
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines2_1
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
//int
//int
...
@@ -1083,7 +1084,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1083,7 +1084,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines2_2
,
2
);
code
=
taos_insert_telnet_lines
(
taos
,
lines2_2
,
2
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines2_2
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
//bigint
//bigint
...
@@ -1093,7 +1094,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1093,7 +1094,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines2_3
,
2
);
code
=
taos_insert_telnet_lines
(
taos
,
lines2_3
,
2
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines2_3
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
//float
//float
...
@@ -1112,7 +1113,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1112,7 +1113,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines2_4
,
11
);
code
=
taos_insert_telnet_lines
(
taos
,
lines2_4
,
11
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines2_4
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
//double
//double
...
@@ -1130,7 +1131,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1130,7 +1131,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines2_5
,
10
);
code
=
taos_insert_telnet_lines
(
taos
,
lines2_5
,
10
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines2_5
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
//bool
//bool
...
@@ -1148,7 +1149,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1148,7 +1149,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines2_6
,
10
);
code
=
taos_insert_telnet_lines
(
taos
,
lines2_6
,
10
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines2_6
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
//binary
//binary
...
@@ -1159,7 +1160,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1159,7 +1160,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines2_7
,
3
);
code
=
taos_insert_telnet_lines
(
taos
,
lines2_7
,
3
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines2_7
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
//nchar
//nchar
...
@@ -1169,7 +1170,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1169,7 +1170,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines2_8
,
2
);
code
=
taos_insert_telnet_lines
(
taos
,
lines2_8
,
2
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines2_8
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
/* tags */
/* tags */
...
@@ -1180,7 +1181,7 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1180,7 +1181,7 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines3_0
,
2
);
code
=
taos_insert_telnet_lines
(
taos
,
lines3_0
,
2
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines3_0
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
//tag ID as child table name
//tag ID as child table name
...
@@ -1191,12 +1192,745 @@ void verify_telnet_insert(TAOS* taos) {
...
@@ -1191,12 +1192,745 @@ void verify_telnet_insert(TAOS* taos) {
};
};
code
=
taos_insert_telnet_lines
(
taos
,
lines3_1
,
3
);
code
=
taos_insert_telnet_lines
(
taos
,
lines3_1
,
3
);
if
(
code
)
{
if
(
code
)
{
printf
(
"code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
printf
(
"
lines3_1
code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
}
return
;
return
;
}
}
void
verify_json_insert
(
TAOS
*
taos
)
{
TAOS_RES
*
result
;
result
=
taos_query
(
taos
,
"drop database if exists db;"
);
taos_free_result
(
result
);
usleep
(
100000
);
result
=
taos_query
(
taos
,
"create database db precision 'ms';"
);
taos_free_result
(
result
);
usleep
(
100000
);
(
void
)
taos_select_db
(
taos
,
"db"
);
int32_t
code
=
0
;
char
*
message
=
"{ \
\"
metric
\"
:
\"
cpu_load_0
\"
, \
\"
timestamp
\"
: 1626006833610123, \
\"
value
\"
: 55.5, \
\"
tags
\"
: \
{ \
\"
host
\"
:
\"
ubuntu
\"
, \
\"
interface1
\"
:
\"
eth0
\"
, \
\"
Id
\"
:
\"
tb0
\"
\
} \
}"
;
code
=
taos_insert_json_payload
(
taos
,
message
);
if
(
code
)
{
printf
(
"payload_0 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
char
*
message1
=
"[ \
{ \
\"
metric
\"
:
\"
cpu_load_1
\"
, \
\"
timestamp
\"
: 1626006833610123, \
\"
value
\"
: 55.5, \
\"
tags
\"
: \
{ \
\"
host
\"
:
\"
ubuntu
\"
, \
\"
interface
\"
:
\"
eth1
\"
, \
\"
Id
\"
:
\"
tb1
\"
\
} \
}, \
{ \
\"
metric
\"
:
\"
cpu_load_2
\"
, \
\"
timestamp
\"
: 1626006833610123, \
\"
value
\"
: 55.5, \
\"
tags
\"
: \
{ \
\"
host
\"
:
\"
ubuntu
\"
, \
\"
interface
\"
:
\"
eth2
\"
, \
\"
Id
\"
:
\"
tb2
\"
\
} \
} \
]"
;
code
=
taos_insert_json_payload
(
taos
,
message1
);
if
(
code
)
{
printf
(
"payload_1 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
char
*
message2
=
"[ \
{ \
\"
metric
\"
:
\"
cpu_load_3
\"
, \
\"
timestamp
\"
: \
{ \
\"
value
\"
: 1626006833610123, \
\"
type
\"
:
\"
us
\"
\
}, \
\"
value
\"
: \
{ \
\"
value
\"
: 55, \
\"
type
\"
:
\"
int
\"
\
}, \
\"
tags
\"
: \
{ \
\"
host
\"
: \
{ \
\"
value
\"
:
\"
ubuntu
\"
, \
\"
type
\"
:
\"
binary
\"
\
}, \
\"
interface
\"
: \
{ \
\"
value
\"
:
\"
eth3
\"
, \
\"
type
\"
:
\"
nchar
\"
\
}, \
\"
ID
\"
:
\"
tb3
\"
, \
\"
port
\"
: \
{ \
\"
value
\"
: 4040, \
\"
type
\"
:
\"
int
\"
\
} \
} \
}, \
{ \
\"
metric
\"
:
\"
cpu_load_4
\"
, \
\"
timestamp
\"
: 1626006833610123, \
\"
value
\"
: 66.6, \
\"
tags
\"
: \
{ \
\"
host
\"
:
\"
ubuntu
\"
, \
\"
interface
\"
:
\"
eth4
\"
, \
\"
Id
\"
:
\"
tb4
\"
\
} \
} \
]"
;
code
=
taos_insert_json_payload
(
taos
,
message2
);
if
(
code
)
{
printf
(
"payload_2 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
cJSON
*
payload
,
*
tags
;
char
*
payload_str
;
/* Default format */
//number
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb0_0"
);
cJSON_AddNumberToObject
(
payload
,
"timestamp"
,
1626006833610123
);
cJSON_AddNumberToObject
(
payload
,
"value"
,
10
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload0_0 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//true
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb0_1"
);
cJSON_AddNumberToObject
(
payload
,
"timestamp"
,
1626006833610123
);
cJSON_AddTrueToObject
(
payload
,
"value"
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload0_1 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//false
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb0_2"
);
cJSON_AddNumberToObject
(
payload
,
"timestamp"
,
1626006833610123
);
cJSON_AddFalseToObject
(
payload
,
"value"
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload0_2 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//string
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb0_3"
);
cJSON_AddNumberToObject
(
payload
,
"timestamp"
,
1626006833610123
);
cJSON_AddStringToObject
(
payload
,
"value"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload0_3 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//timestamp 0 -> current time
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb0_4"
);
cJSON_AddNumberToObject
(
payload
,
"timestamp"
,
0
);
cJSON_AddNumberToObject
(
payload
,
"value"
,
123
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload0_4 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//ID
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb0_5"
);
cJSON_AddNumberToObject
(
payload
,
"timestamp"
,
0
);
cJSON_AddNumberToObject
(
payload
,
"value"
,
123
);
tags
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
tags
,
"ID"
,
"tb0_5"
);
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddStringToObject
(
tags
,
"iD"
,
"tb000"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddStringToObject
(
tags
,
"id"
,
"tb555"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload0_5 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
/* Nested format */
//timestamp
cJSON
*
timestamp
;
//seconds
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb1_0"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"s"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
cJSON_AddNumberToObject
(
payload
,
"value"
,
10
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload1_0 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//milleseconds
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb1_1"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833610
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"ms"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
cJSON_AddNumberToObject
(
payload
,
"value"
,
10
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload1_1 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//microseconds
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb1_2"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833610123
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"us"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
cJSON_AddNumberToObject
(
payload
,
"value"
,
10
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload1_2 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//nanoseconds
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb1_3"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833610123321
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"ns"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
cJSON_AddNumberToObject
(
payload
,
"value"
,
10
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload1_3 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//now
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb1_4"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
0
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"ns"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
cJSON_AddNumberToObject
(
payload
,
"value"
,
10
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload1_4 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//metric value
cJSON
*
metric_val
;
//bool
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb2_0"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"s"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
metric_val
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
metric_val
,
"value"
);
cJSON_AddStringToObject
(
metric_val
,
"type"
,
"bool"
);
cJSON_AddItemToObject
(
payload
,
"value"
,
metric_val
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload2_0 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//tinyint
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb2_1"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"s"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
metric_val
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
metric_val
,
"value"
,
127
);
cJSON_AddStringToObject
(
metric_val
,
"type"
,
"tinyint"
);
cJSON_AddItemToObject
(
payload
,
"value"
,
metric_val
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload2_1 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//smallint
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb2_2"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"s"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
metric_val
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
metric_val
,
"value"
,
32767
);
cJSON_AddStringToObject
(
metric_val
,
"type"
,
"smallint"
);
cJSON_AddItemToObject
(
payload
,
"value"
,
metric_val
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload2_2 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//int
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb2_3"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"s"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
metric_val
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
metric_val
,
"value"
,
2147483647
);
cJSON_AddStringToObject
(
metric_val
,
"type"
,
"int"
);
cJSON_AddItemToObject
(
payload
,
"value"
,
metric_val
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload2_3 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//bigint
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb2_4"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"s"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
metric_val
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
metric_val
,
"value"
,
9223372036854775807
);
cJSON_AddStringToObject
(
metric_val
,
"type"
,
"bigint"
);
cJSON_AddItemToObject
(
payload
,
"value"
,
metric_val
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload2_4 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//float
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb2_5"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"s"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
metric_val
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
metric_val
,
"value"
,
11
.
12345
);
cJSON_AddStringToObject
(
metric_val
,
"type"
,
"float"
);
cJSON_AddItemToObject
(
payload
,
"value"
,
metric_val
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload2_5 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//double
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb2_6"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"s"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
metric_val
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
metric_val
,
"value"
,
22
.
123456789
);
cJSON_AddStringToObject
(
metric_val
,
"type"
,
"double"
);
cJSON_AddItemToObject
(
payload
,
"value"
,
metric_val
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload2_6 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//binary
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb2_7"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"s"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
metric_val
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
metric_val
,
"value"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddStringToObject
(
metric_val
,
"type"
,
"binary"
);
cJSON_AddItemToObject
(
payload
,
"value"
,
metric_val
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload2_7 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//nchar
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb2_8"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"s"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
metric_val
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
metric_val
,
"value"
,
"你好"
);
cJSON_AddStringToObject
(
metric_val
,
"type"
,
"nchar"
);
cJSON_AddItemToObject
(
payload
,
"value"
,
metric_val
);
tags
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tags
,
"t1"
);
cJSON_AddFalseToObject
(
tags
,
"t2"
);
cJSON_AddNumberToObject
(
tags
,
"t3"
,
10
);
cJSON_AddStringToObject
(
tags
,
"t4"
,
"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload2_8 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
//tag value
cJSON
*
tag
;
payload
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
payload
,
"metric"
,
"stb3_0"
);
timestamp
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
timestamp
,
"value"
,
1626006833
);
cJSON_AddStringToObject
(
timestamp
,
"type"
,
"s"
);
cJSON_AddItemToObject
(
payload
,
"timestamp"
,
timestamp
);
metric_val
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
metric_val
,
"value"
,
"hello"
);
cJSON_AddStringToObject
(
metric_val
,
"type"
,
"nchar"
);
cJSON_AddItemToObject
(
payload
,
"value"
,
metric_val
);
tags
=
cJSON_CreateObject
();
tag
=
cJSON_CreateObject
();
cJSON_AddTrueToObject
(
tag
,
"value"
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"bool"
);
cJSON_AddItemToObject
(
tags
,
"t1"
,
tag
);
tag
=
cJSON_CreateObject
();
cJSON_AddFalseToObject
(
tag
,
"value"
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"bool"
);
cJSON_AddItemToObject
(
tags
,
"t2"
,
tag
);
tag
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
tag
,
"value"
,
127
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"tinyint"
);
cJSON_AddItemToObject
(
tags
,
"t3"
,
tag
);
tag
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
tag
,
"value"
,
32767
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"smallint"
);
cJSON_AddItemToObject
(
tags
,
"t4"
,
tag
);
tag
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
tag
,
"value"
,
2147483647
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"int"
);
cJSON_AddItemToObject
(
tags
,
"t5"
,
tag
);
tag
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
tag
,
"value"
,
9223372036854775807
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"bigint"
);
cJSON_AddItemToObject
(
tags
,
"t6"
,
tag
);
tag
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
tag
,
"value"
,
11
.
12345
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"float"
);
cJSON_AddItemToObject
(
tags
,
"t7"
,
tag
);
tag
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
tag
,
"value"
,
22
.
1234567890
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"double"
);
cJSON_AddItemToObject
(
tags
,
"t8"
,
tag
);
tag
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
tag
,
"value"
,
"binary_val"
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"binary"
);
cJSON_AddItemToObject
(
tags
,
"t9"
,
tag
);
tag
=
cJSON_CreateObject
();
cJSON_AddStringToObject
(
tag
,
"value"
,
"你好"
);
cJSON_AddStringToObject
(
tag
,
"type"
,
"nchar"
);
cJSON_AddItemToObject
(
tags
,
"t10"
,
tag
);
cJSON_AddItemToObject
(
payload
,
"tags"
,
tags
);
payload_str
=
cJSON_Print
(
payload
);
//printf("%s\n", payload_str);
code
=
taos_insert_json_payload
(
taos
,
payload_str
);
if
(
code
)
{
printf
(
"payload3_0 code: %d, %s.
\n
"
,
code
,
tstrerror
(
code
));
}
free
(
payload_str
);
cJSON_Delete
(
payload
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
const
char
*
host
=
"127.0.0.1"
;
const
char
*
host
=
"127.0.0.1"
;
const
char
*
user
=
"root"
;
const
char
*
user
=
"root"
;
...
@@ -1220,6 +1954,9 @@ int main(int argc, char *argv[]) {
...
@@ -1220,6 +1954,9 @@ int main(int argc, char *argv[]) {
printf
(
"************ verify telnet-insert *************
\n
"
);
printf
(
"************ verify telnet-insert *************
\n
"
);
verify_telnet_insert
(
taos
);
verify_telnet_insert
(
taos
);
printf
(
"************ verify json-insert *************
\n
"
);
verify_json_insert
(
taos
);
printf
(
"************ verify query *************
\n
"
);
printf
(
"************ verify query *************
\n
"
);
verify_query
(
taos
);
verify_query
(
taos
);
...
...
tests/examples/c/makefile
浏览文件 @
13d8bb83
...
@@ -6,8 +6,8 @@ TARGET=exe
...
@@ -6,8 +6,8 @@ TARGET=exe
LFLAGS
=
'-Wl,-rpath,/usr/local/taos/driver/'
-ltaos
-lpthread
-lm
-lrt
LFLAGS
=
'-Wl,-rpath,/usr/local/taos/driver/'
-ltaos
-lpthread
-lm
-lrt
CFLAGS
=
-O3
-g
-Wall
-Wno-deprecated
-fPIC
-Wno-unused-result
-Wconversion
\
CFLAGS
=
-O3
-g
-Wall
-Wno-deprecated
-fPIC
-Wno-unused-result
-Wconversion
\
-Wno-char-subscripts
-D_REENTRANT
-Wno-format
-D_REENTRANT
-DLINUX
\
-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
\
-I
../../../deps/cJson/inc
all
:
$(TARGET)
all
:
$(TARGET)
exe
:
exe
:
...
...
tests/pytest/insert/insertJSONPayload.py
0 → 100644
浏览文件 @
13d8bb83
###################################################################
# Copyright (c) 2021 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
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
(),
logSql
)
self
.
_conn
=
conn
def
run
(
self
):
print
(
"running {}"
.
format
(
__file__
))
tdSql
.
execute
(
"drop database if exists test"
)
tdSql
.
execute
(
"create database if not exists test precision 'us'"
)
tdSql
.
execute
(
'use test'
)
### Default format ###
### metric value ###
print
(
"============= step1 : test metric value types ================"
)
payload
=
'''
{
"metric": "stb0_0",
"timestamp": 1626006833610123,
"value": 10,
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb0_0"
)
tdSql
.
checkData
(
1
,
1
,
"FLOAT"
)
payload
=
'''
{
"metric": "stb0_1",
"timestamp": 1626006833610123,
"value": true,
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb0_1"
)
tdSql
.
checkData
(
1
,
1
,
"BOOL"
)
payload
=
'''
{
"metric": "stb0_2",
"timestamp": 1626006833610123,
"value": false,
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb0_2"
)
tdSql
.
checkData
(
1
,
1
,
"BOOL"
)
payload
=
'''
{
"metric": "stb0_3",
"timestamp": 1626006833610123,
"value": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>",
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb0_3"
)
tdSql
.
checkData
(
1
,
1
,
"NCHAR"
)
### timestamp 0 ###
payload
=
'''
{
"metric": "stb0_4",
"timestamp": 0,
"value": 123,
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
### ID ###
payload
=
'''
{
"metric": "stb0_5",
"timestamp": 0,
"value": 123,
"tags": {
"ID": "tb0_5",
"t1": true,
"iD": "tb000",
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>",
"id": "tb555"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"select tbname from stb0_5"
)
tdSql
.
checkData
(
0
,
0
,
"tb0_5"
)
### Nested format ###
### timestamp ###
#seconds
payload
=
'''
{
"metric": "stb1_0",
"timestamp": {
"value": 1626006833,
"type": "s"
},
"value": 10,
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"select ts from stb1_0"
)
tdSql
.
checkData
(
0
,
0
,
"2021-07-11 20:33:53.000000"
)
#milliseconds
payload
=
'''
{
"metric": "stb1_1",
"timestamp": {
"value": 1626006833610,
"type": "ms"
},
"value": 10,
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"select ts from stb1_1"
)
tdSql
.
checkData
(
0
,
0
,
"2021-07-11 20:33:53.610000"
)
#microseconds
payload
=
'''
{
"metric": "stb1_2",
"timestamp": {
"value": 1626006833610123,
"type": "us"
},
"value": 10,
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"select ts from stb1_2"
)
tdSql
.
checkData
(
0
,
0
,
"2021-07-11 20:33:53.610123"
)
#nanoseconds
payload
=
'''
{
"metric": "stb1_3",
"timestamp": {
"value": 1.6260068336101233e+18,
"type": "ns"
},
"value": 10,
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"select ts from stb1_3"
)
tdSql
.
checkData
(
0
,
0
,
"2021-07-11 20:33:53.610123"
)
#now
tdSql
.
execute
(
'use test'
)
payload
=
'''
{
"metric": "stb1_4",
"timestamp": {
"value": 0,
"type": "ns"
},
"value": 10,
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
### metric value ###
payload
=
'''
{
"metric": "stb2_0",
"timestamp": {
"value": 1626006833,
"type": "s"
},
"value": {
"value": true,
"type": "bool"
},
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb2_0"
)
tdSql
.
checkData
(
1
,
1
,
"BOOL"
)
payload
=
'''
{
"metric": "stb2_1",
"timestamp": {
"value": 1626006833,
"type": "s"
},
"value": {
"value": 127,
"type": "tinyint"
},
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb2_1"
)
tdSql
.
checkData
(
1
,
1
,
"TINYINT"
)
payload
=
'''
{
"metric": "stb2_2",
"timestamp": {
"value": 1626006833,
"type": "s"
},
"value": {
"value": 32767,
"type": "smallint"
},
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb2_2"
)
tdSql
.
checkData
(
1
,
1
,
"SMALLINT"
)
payload
=
'''
{
"metric": "stb2_3",
"timestamp": {
"value": 1626006833,
"type": "s"
},
"value": {
"value": 2147483647,
"type": "int"
},
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb2_3"
)
tdSql
.
checkData
(
1
,
1
,
"INT"
)
payload
=
'''
{
"metric": "stb2_4",
"timestamp": {
"value": 1626006833,
"type": "s"
},
"value": {
"value": 9.2233720368547758e+18,
"type": "bigint"
},
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb2_4"
)
tdSql
.
checkData
(
1
,
1
,
"BIGINT"
)
payload
=
'''
{
"metric": "stb2_5",
"timestamp": {
"value": 1626006833,
"type": "s"
},
"value": {
"value": 11.12345,
"type": "float"
},
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb2_5"
)
tdSql
.
checkData
(
1
,
1
,
"FLOAT"
)
payload
=
'''
{
"metric": "stb2_6",
"timestamp": {
"value": 1626006833,
"type": "s"
},
"value": {
"value": 22.123456789,
"type": "double"
},
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb2_6"
)
tdSql
.
checkData
(
1
,
1
,
"DOUBLE"
)
payload
=
'''
{
"metric": "stb2_7",
"timestamp": {
"value": 1626006833,
"type": "s"
},
"value": {
"value": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>",
"type": "binary"
},
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb2_7"
)
tdSql
.
checkData
(
1
,
1
,
"BINARY"
)
payload
=
'''
{
"metric": "stb2_8",
"timestamp": {
"value": 1626006833,
"type": "s"
},
"value": {
"value": "你好",
"type": "nchar"
},
"tags": {
"t1": true,
"t2": false,
"t3": 10,
"t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb2_8"
)
tdSql
.
checkData
(
1
,
1
,
"NCHAR"
)
### tag value ###
payload
=
'''
{
"metric": "stb3_0",
"timestamp": {
"value": 1626006833,
"type": "s"
},
"value": {
"value": "hello",
"type": "nchar"
},
"tags": {
"t1": {
"value": true,
"type": "bool"
},
"t2": {
"value": 127,
"type": "tinyint"
},
"t3": {
"value": 32767,
"type": "smallint"
},
"t4": {
"value": 2147483647,
"type": "int"
},
"t5": {
"value": 9.2233720368547758e+18,
"type": "bigint"
},
"t6": {
"value": 11.12345,
"type": "float"
},
"t7": {
"value": 22.123456789,
"type": "double"
},
"t8": {
"value": "binary_val",
"type": "binary"
},
"t9": {
"value": "你好",
"type": "nchar"
}
}
}
'''
code
=
self
.
_conn
.
insert_json_payload
(
payload
)
print
(
"insert_json_payload result {}"
.
format
(
code
))
tdSql
.
query
(
"describe stb3_0"
)
tdSql
.
checkData
(
2
,
1
,
"BOOL"
)
tdSql
.
checkData
(
3
,
1
,
"TINYINT"
)
tdSql
.
checkData
(
4
,
1
,
"SMALLINT"
)
tdSql
.
checkData
(
5
,
1
,
"INT"
)
tdSql
.
checkData
(
6
,
1
,
"BIGINT"
)
tdSql
.
checkData
(
7
,
1
,
"FLOAT"
)
tdSql
.
checkData
(
8
,
1
,
"DOUBLE"
)
tdSql
.
checkData
(
9
,
1
,
"BINARY"
)
tdSql
.
checkData
(
10
,
1
,
"NCHAR"
)
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录