Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0d719ab4
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看板
提交
0d719ab4
编写于
7月 13, 2021
作者:
S
Shenglian Zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add log and free memory
上级
bcba45e3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
142 addition
and
32 deletion
+142
-32
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+137
-28
tests/examples/c/apitest.c
tests/examples/c/apitest.c
+5
-4
未找到文件。
src/client/src/tscParseLineProtocol.c
浏览文件 @
0d719ab4
...
@@ -98,8 +98,12 @@ static int32_t getFieldBytesFromSmlKv(TAOS_SML_KV* kv, int32_t* bytes) {
...
@@ -98,8 +98,12 @@ static int32_t getFieldBytesFromSmlKv(TAOS_SML_KV* kv, int32_t* bytes) {
if
(
kv
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
kv
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
char
*
ucs
=
malloc
(
kv
->
length
*
TSDB_NCHAR_SIZE
+
1
);
char
*
ucs
=
malloc
(
kv
->
length
*
TSDB_NCHAR_SIZE
+
1
);
int32_t
bytesNeeded
=
0
;
int32_t
bytesNeeded
=
0
;
//todo check conversion succeed
bool
succ
=
taosMbsToUcs4
(
kv
->
value
,
kv
->
length
,
ucs
,
kv
->
length
*
TSDB_NCHAR_SIZE
,
&
bytesNeeded
);
taosMbsToUcs4
(
kv
->
value
,
kv
->
length
,
ucs
,
kv
->
length
*
TSDB_NCHAR_SIZE
,
&
bytesNeeded
);
if
(
!
succ
)
{
free
(
ucs
);
tscError
(
"convert nchar string to UCS4_LE failed:%s"
,
kv
->
value
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
free
(
ucs
);
free
(
ucs
);
*
bytes
=
bytesNeeded
+
VARSTR_HEADER_SIZE
;
*
bytes
=
bytesNeeded
+
VARSTR_HEADER_SIZE
;
}
else
if
(
kv
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
}
else
if
(
kv
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
...
@@ -112,17 +116,20 @@ static int32_t getFieldBytesFromSmlKv(TAOS_SML_KV* kv, int32_t* bytes) {
...
@@ -112,17 +116,20 @@ static int32_t getFieldBytesFromSmlKv(TAOS_SML_KV* kv, int32_t* bytes) {
static
int32_t
buildSmlKvSchema
(
TAOS_SML_KV
*
smlKv
,
SHashObj
*
hash
,
SArray
*
array
)
{
static
int32_t
buildSmlKvSchema
(
TAOS_SML_KV
*
smlKv
,
SHashObj
*
hash
,
SArray
*
array
)
{
SSchema
*
pField
=
NULL
;
SSchema
*
pField
=
NULL
;
SSchema
**
ppField
=
taosHashGet
(
hash
,
smlKv
->
key
,
strlen
(
smlKv
->
key
));
SSchema
**
ppField
=
taosHashGet
(
hash
,
smlKv
->
key
,
strlen
(
smlKv
->
key
));
int32_t
code
=
0
;
if
(
ppField
)
{
if
(
ppField
)
{
pField
=
*
ppField
;
pField
=
*
ppField
;
if
(
pField
->
type
!=
smlKv
->
type
)
{
if
(
pField
->
type
!=
smlKv
->
type
)
{
//TODO:
tscError
(
"type mismatch. key %s, type %d. type before %d"
,
smlKv
->
key
,
smlKv
->
type
,
pField
->
type
);
tscError
(
"type mismatch"
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
return
-
1
;
}
}
int32_t
bytes
=
0
;
int32_t
bytes
=
0
;
getFieldBytesFromSmlKv
(
smlKv
,
&
bytes
);
code
=
getFieldBytesFromSmlKv
(
smlKv
,
&
bytes
);
if
(
code
!=
0
)
{
return
code
;
}
pField
->
bytes
=
MAX
(
pField
->
bytes
,
bytes
);
pField
->
bytes
=
MAX
(
pField
->
bytes
,
bytes
);
}
else
{
}
else
{
...
@@ -133,7 +140,10 @@ static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* arra
...
@@ -133,7 +140,10 @@ static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* arra
field
.
type
=
smlKv
->
type
;
field
.
type
=
smlKv
->
type
;
int32_t
bytes
=
0
;
int32_t
bytes
=
0
;
getFieldBytesFromSmlKv
(
smlKv
,
&
bytes
);
code
=
getFieldBytesFromSmlKv
(
smlKv
,
&
bytes
);
if
(
code
!=
0
)
{
return
code
;
}
field
.
bytes
=
bytes
;
field
.
bytes
=
bytes
;
pField
=
taosArrayPush
(
array
,
&
field
);
pField
=
taosArrayPush
(
array
,
&
field
);
...
@@ -146,6 +156,7 @@ static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* arra
...
@@ -146,6 +156,7 @@ static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* arra
}
}
static
int32_t
buildDataPointSchemas
(
TAOS_SML_DATA_POINT
*
points
,
int
numPoint
,
SArray
*
stableSchemas
)
{
static
int32_t
buildDataPointSchemas
(
TAOS_SML_DATA_POINT
*
points
,
int
numPoint
,
SArray
*
stableSchemas
)
{
int32_t
code
=
0
;
SHashObj
*
sname2shema
=
taosHashInit
(
32
,
SHashObj
*
sname2shema
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
false
);
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
false
);
...
@@ -171,12 +182,20 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
...
@@ -171,12 +182,20 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
for
(
int
j
=
0
;
j
<
point
->
tagNum
;
++
j
)
{
for
(
int
j
=
0
;
j
<
point
->
tagNum
;
++
j
)
{
TAOS_SML_KV
*
tagKv
=
point
->
tags
+
j
;
TAOS_SML_KV
*
tagKv
=
point
->
tags
+
j
;
buildSmlKvSchema
(
tagKv
,
pStableSchema
->
tagHash
,
pStableSchema
->
tags
);
code
=
buildSmlKvSchema
(
tagKv
,
pStableSchema
->
tagHash
,
pStableSchema
->
tags
);
if
(
code
!=
0
)
{
tscError
(
"build data point schema failed. point no.: %d, tag key: %s"
,
i
,
tagKv
->
key
);
return
code
;
}
}
}
for
(
int
j
=
0
;
j
<
point
->
fieldNum
;
++
j
)
{
for
(
int
j
=
0
;
j
<
point
->
fieldNum
;
++
j
)
{
TAOS_SML_KV
*
fieldKv
=
point
->
fields
+
j
;
TAOS_SML_KV
*
fieldKv
=
point
->
fields
+
j
;
buildSmlKvSchema
(
fieldKv
,
pStableSchema
->
fieldHash
,
pStableSchema
->
fields
);
code
=
buildSmlKvSchema
(
fieldKv
,
pStableSchema
->
fieldHash
,
pStableSchema
->
fields
);
if
(
code
!=
0
)
{
tscError
(
"build data point schema failed. point no.: %d, tag key: %s"
,
i
,
fieldKv
->
key
);
return
code
;
}
}
}
point
->
schema
=
pStableSchema
;
point
->
schema
=
pStableSchema
;
...
@@ -190,6 +209,13 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
...
@@ -190,6 +209,13 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
}
}
taosHashCleanup
(
sname2shema
);
taosHashCleanup
(
sname2shema
);
tscDebug
(
"build point schema succeed. num of super table: %zu"
,
numStables
);
for
(
int32_t
i
=
0
;
i
<
numStables
;
++
i
)
{
SSmlSTableSchema
*
schema
=
taosArrayGet
(
stableSchemas
,
i
);
tscDebug
(
"
\t
table name: %s, tags number: %zu, fields number: %zu"
,
schema
->
sTableName
,
taosArrayGetSize
(
schema
->
tags
),
taosArrayGetSize
(
schema
->
fields
));
}
return
0
;
return
0
;
}
}
...
@@ -199,8 +225,9 @@ static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash
...
@@ -199,8 +225,9 @@ static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash
if
(
ppDbAttr
)
{
if
(
ppDbAttr
)
{
SSchema
*
dbAttr
=
*
ppDbAttr
;
SSchema
*
dbAttr
=
*
ppDbAttr
;
if
(
pointColField
->
type
!=
dbAttr
->
type
)
{
if
(
pointColField
->
type
!=
dbAttr
->
type
)
{
//todo error
tscError
(
"point type and db type mismatch. key: %s. point type: %d, db type: %d"
,
pointColField
->
name
,
return
-
5
;
pointColField
->
type
,
dbAttr
->
type
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
}
if
(
IS_VAR_DATA_TYPE
(
pointColField
->
type
)
&&
(
pointColField
->
bytes
>
dbAttr
->
bytes
))
{
if
(
IS_VAR_DATA_TYPE
(
pointColField
->
type
)
&&
(
pointColField
->
bytes
>
dbAttr
->
bytes
))
{
...
@@ -225,6 +252,7 @@ static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash
...
@@ -225,6 +252,7 @@ static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash
action
->
alterSTable
.
field
=
pointColField
;
action
->
alterSTable
.
field
=
pointColField
;
*
actionNeeded
=
true
;
*
actionNeeded
=
true
;
}
}
tscDebug
(
"generate schema action. action needed: %d, action: %d"
,
*
actionNeeded
,
action
->
action
);
return
0
;
return
0
;
}
}
...
@@ -256,12 +284,14 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) {
...
@@ -256,12 +284,14 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) {
int32_t
outBytes
=
0
;
int32_t
outBytes
=
0
;
char
*
result
=
(
char
*
)
calloc
(
1
,
capacity
);
char
*
result
=
(
char
*
)
calloc
(
1
,
capacity
);
tscDebug
(
"apply schema action: %d"
,
action
->
action
);
switch
(
action
->
action
)
{
switch
(
action
->
action
)
{
case
SCHEMA_ACTION_ADD_COLUMN
:
{
case
SCHEMA_ACTION_ADD_COLUMN
:
{
int
n
=
sprintf
(
result
,
"alter stable %s add column "
,
action
->
alterSTable
.
sTableName
);
int
n
=
sprintf
(
result
,
"alter stable %s add column "
,
action
->
alterSTable
.
sTableName
);
buildColumnDescription
(
action
->
alterSTable
.
field
,
result
+
n
,
capacity
-
n
,
&
outBytes
);
buildColumnDescription
(
action
->
alterSTable
.
field
,
result
+
n
,
capacity
-
n
,
&
outBytes
);
TAOS_RES
*
res
=
taos_query
(
taos
,
result
);
//TODO async doAsyncQuery
TAOS_RES
*
res
=
taos_query
(
taos
,
result
);
//TODO async doAsyncQuery
code
=
taos_errno
(
res
);
code
=
taos_errno
(
res
);
taos_free_result
(
res
);
break
;
break
;
}
}
case
SCHEMA_ACTION_ADD_TAG
:
{
case
SCHEMA_ACTION_ADD_TAG
:
{
...
@@ -270,6 +300,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) {
...
@@ -270,6 +300,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) {
result
+
n
,
capacity
-
n
,
&
outBytes
);
result
+
n
,
capacity
-
n
,
&
outBytes
);
TAOS_RES
*
res
=
taos_query
(
taos
,
result
);
//TODO async doAsyncQuery
TAOS_RES
*
res
=
taos_query
(
taos
,
result
);
//TODO async doAsyncQuery
code
=
taos_errno
(
res
);
code
=
taos_errno
(
res
);
taos_free_result
(
res
);
break
;
break
;
}
}
case
SCHEMA_ACTION_CHANGE_COLUMN_SIZE
:
{
case
SCHEMA_ACTION_CHANGE_COLUMN_SIZE
:
{
...
@@ -278,6 +309,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) {
...
@@ -278,6 +309,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) {
capacity
-
n
,
&
outBytes
);
capacity
-
n
,
&
outBytes
);
TAOS_RES
*
res
=
taos_query
(
taos
,
result
);
//TODO async doAsyncQuery
TAOS_RES
*
res
=
taos_query
(
taos
,
result
);
//TODO async doAsyncQuery
code
=
taos_errno
(
res
);
code
=
taos_errno
(
res
);
taos_free_result
(
res
);
break
;
break
;
}
}
case
SCHEMA_ACTION_CHANGE_TAG_SIZE
:
{
case
SCHEMA_ACTION_CHANGE_TAG_SIZE
:
{
...
@@ -286,6 +318,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) {
...
@@ -286,6 +318,7 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) {
capacity
-
n
,
&
outBytes
);
capacity
-
n
,
&
outBytes
);
TAOS_RES
*
res
=
taos_query
(
taos
,
result
);
//TODO async doAsyncQuery
TAOS_RES
*
res
=
taos_query
(
taos
,
result
);
//TODO async doAsyncQuery
code
=
taos_errno
(
res
);
code
=
taos_errno
(
res
);
taos_free_result
(
res
);
break
;
break
;
}
}
case
SCHEMA_ACTION_CREATE_STABLE
:
{
case
SCHEMA_ACTION_CREATE_STABLE
:
{
...
@@ -314,13 +347,18 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) {
...
@@ -314,13 +347,18 @@ static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) {
outBytes
=
snprintf
(
pos
,
freeBytes
,
")"
);
outBytes
=
snprintf
(
pos
,
freeBytes
,
")"
);
TAOS_RES
*
res
=
taos_query
(
taos
,
result
);
TAOS_RES
*
res
=
taos_query
(
taos
,
result
);
code
=
taos_errno
(
res
);
code
=
taos_errno
(
res
);
taos_free_result
(
res
);
break
;
break
;
}
}
default:
default:
break
;
break
;
}
}
free
(
result
);
free
(
result
);
if
(
code
!=
0
)
{
tscError
(
"apply schema action failure. %s"
,
tstrerror
(
code
));
}
return
code
;
return
code
;
}
}
...
@@ -341,11 +379,14 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) {
...
@@ -341,11 +379,14 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) {
return
TSDB_CODE_TSC_DISCONNECTED
;
return
TSDB_CODE_TSC_DISCONNECTED
;
}
}
tscDebug
(
"load table schema. super table name: %s"
,
tableName
);
char
sql
[
256
];
char
sql
[
256
];
snprintf
(
sql
,
256
,
"describe %s"
,
tableName
);
snprintf
(
sql
,
256
,
"describe %s"
,
tableName
);
TAOS_RES
*
res
=
taos_query
(
taos
,
sql
);
TAOS_RES
*
res
=
taos_query
(
taos
,
sql
);
code
=
taos_errno
(
res
);
code
=
taos_errno
(
res
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
tscError
(
"describe table failure. %s"
,
taos_errstr
(
res
));
taos_free_result
(
res
);
taos_free_result
(
res
);
return
code
;
return
code
;
}
}
...
@@ -369,16 +410,13 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) {
...
@@ -369,16 +410,13 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) {
if
((
code
=
tscSetTableFullName
(
&
sname
,
&
tableToken
,
pSql
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscSetTableFullName
(
&
sname
,
&
tableToken
,
pSql
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
}
}
char
fullTableName
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
char
fullTableName
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
memset
(
fullTableName
,
0
,
tListLen
(
fullTableName
));
memset
(
fullTableName
,
0
,
tListLen
(
fullTableName
));
tNameExtractFullName
(
&
sname
,
fullTableName
);
tNameExtractFullName
(
&
sname
,
fullTableName
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tscFreeSqlObj
(
pSql
);
tscFreeSqlObj
(
pSql
);
return
code
;
return
code
;
}
}
tscFreeSqlObj
(
pSql
);
tscFreeSqlObj
(
pSql
);
schema
->
tags
=
taosArrayInit
(
8
,
sizeof
(
SSchema
));
schema
->
tags
=
taosArrayInit
(
8
,
sizeof
(
SSchema
));
...
@@ -410,6 +448,8 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) {
...
@@ -410,6 +448,8 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) {
SSchema
*
pField
=
taosArrayPush
(
schema
->
tags
,
&
field
);
SSchema
*
pField
=
taosArrayPush
(
schema
->
tags
,
&
field
);
taosHashPut
(
schema
->
tagHash
,
field
.
name
,
strlen
(
field
.
name
),
&
pField
,
POINTER_BYTES
);
taosHashPut
(
schema
->
tagHash
,
field
.
name
,
strlen
(
field
.
name
),
&
pField
,
POINTER_BYTES
);
}
}
tscDebug
(
"load table meta succeed. %s, columns number: %d, tag number: %d, precision: %d"
,
tableName
,
tableMeta
->
tableInfo
.
numOfColumns
,
tableMeta
->
tableInfo
.
numOfTags
,
schema
->
precision
);
free
(
tableMeta
);
tableMeta
=
NULL
;
free
(
tableMeta
);
tableMeta
=
NULL
;
return
code
;
return
code
;
}
}
...
@@ -422,7 +462,6 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) {
...
@@ -422,7 +462,6 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) {
SSmlSTableSchema
dbSchema
=
{
0
};
SSmlSTableSchema
dbSchema
=
{
0
};
code
=
loadTableMeta
(
taos
,
pointSchema
->
sTableName
,
&
dbSchema
);
code
=
loadTableMeta
(
taos
,
pointSchema
->
sTableName
,
&
dbSchema
);
if
(
code
==
TSDB_CODE_MND_INVALID_TABLE_NAME
)
{
if
(
code
==
TSDB_CODE_MND_INVALID_TABLE_NAME
)
{
SSchemaAction
schemaAction
=
{
0
};
SSchemaAction
schemaAction
=
{
0
};
schemaAction
.
action
=
SCHEMA_ACTION_CREATE_STABLE
;
schemaAction
.
action
=
SCHEMA_ACTION_CREATE_STABLE
;
...
@@ -432,10 +471,12 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) {
...
@@ -432,10 +471,12 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) {
schemaAction
.
createSTable
.
fields
=
pointSchema
->
fields
;
schemaAction
.
createSTable
.
fields
=
pointSchema
->
fields
;
applySchemaAction
(
taos
,
&
schemaAction
);
applySchemaAction
(
taos
,
&
schemaAction
);
code
=
loadTableMeta
(
taos
,
pointSchema
->
sTableName
,
&
dbSchema
);
code
=
loadTableMeta
(
taos
,
pointSchema
->
sTableName
,
&
dbSchema
);
if
(
code
!=
0
)
{
pointSchema
->
precision
=
dbSchema
.
precision
;
tscError
(
"reconcile point schema failed. can not create %s"
,
pointSchema
->
sTableName
);
}
else
{
destroySmlSTableSchema
(
&
dbSchema
);
pointSchema
->
precision
=
dbSchema
.
precision
;
destroySmlSTableSchema
(
&
dbSchema
);
}
}
else
if
(
code
==
TSDB_CODE_SUCCESS
)
{
}
else
if
(
code
==
TSDB_CODE_SUCCESS
)
{
size_t
pointTagSize
=
taosArrayGetSize
(
pointSchema
->
tags
);
size_t
pointTagSize
=
taosArrayGetSize
(
pointSchema
->
tags
);
size_t
pointFieldSize
=
taosArrayGetSize
(
pointSchema
->
fields
);
size_t
pointFieldSize
=
taosArrayGetSize
(
pointSchema
->
fields
);
...
@@ -471,6 +512,7 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) {
...
@@ -471,6 +512,7 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) {
destroySmlSTableSchema
(
&
dbSchema
);
destroySmlSTableSchema
(
&
dbSchema
);
}
else
{
}
else
{
tscError
(
"load table meta error: %s"
,
tstrerror
(
code
));
return
code
;
return
code
;
}
}
}
}
...
@@ -496,11 +538,12 @@ static int32_t getChildTableName(TAOS_SML_DATA_POINT* point, char* tableName, in
...
@@ -496,11 +538,12 @@ static int32_t getChildTableName(TAOS_SML_DATA_POINT* point, char* tableName, in
MD5Update
(
&
context
,
(
uint8_t
*
)
keyJoined
,
(
uint32_t
)
len
);
MD5Update
(
&
context
,
(
uint8_t
*
)
keyJoined
,
(
uint32_t
)
len
);
MD5Final
(
&
context
);
MD5Final
(
&
context
);
*
tableNameLen
=
snprintf
(
tableName
,
*
tableNameLen
,
*
tableNameLen
=
snprintf
(
tableName
,
*
tableNameLen
,
"t
bl
_%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
,
context
.
digest
[
0
],
"t_%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
,
context
.
digest
[
0
],
context
.
digest
[
1
],
context
.
digest
[
2
],
context
.
digest
[
3
],
context
.
digest
[
4
],
context
.
digest
[
5
],
context
.
digest
[
6
],
context
.
digest
[
1
],
context
.
digest
[
2
],
context
.
digest
[
3
],
context
.
digest
[
4
],
context
.
digest
[
5
],
context
.
digest
[
6
],
context
.
digest
[
7
],
context
.
digest
[
8
],
context
.
digest
[
9
],
context
.
digest
[
10
],
context
.
digest
[
11
],
context
.
digest
[
7
],
context
.
digest
[
8
],
context
.
digest
[
9
],
context
.
digest
[
10
],
context
.
digest
[
11
],
context
.
digest
[
12
],
context
.
digest
[
13
],
context
.
digest
[
14
],
context
.
digest
[
15
]);
context
.
digest
[
12
],
context
.
digest
[
13
],
context
.
digest
[
14
],
context
.
digest
[
15
]);
taosStringBuilderDestroy
(
&
sb
);
taosStringBuilderDestroy
(
&
sb
);
tscDebug
(
"child table name: %s"
,
tableName
);
return
0
;
return
0
;
}
}
...
@@ -524,23 +567,25 @@ static int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, co
...
@@ -524,23 +567,25 @@ static int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, co
}
}
snprintf
(
sql
+
strlen
(
sql
)
-
1
,
freeBytes
-
strlen
(
sql
)
+
1
,
")"
);
snprintf
(
sql
+
strlen
(
sql
)
-
1
,
freeBytes
-
strlen
(
sql
)
+
1
,
")"
);
tscDebug
(
"create table : %s"
,
sql
);
TAOS_STMT
*
stmt
=
taos_stmt_init
(
taos
);
TAOS_STMT
*
stmt
=
taos_stmt_init
(
taos
);
int32_t
code
;
int32_t
code
;
code
=
taos_stmt_prepare
(
stmt
,
sql
,
strlen
(
sql
));
code
=
taos_stmt_prepare
(
stmt
,
sql
,
strlen
(
sql
));
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
tscError
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
return
code
;
}
}
code
=
taos_stmt_bind_param
(
stmt
,
TARRAY_GET_START
(
tagsBind
));
code
=
taos_stmt_bind_param
(
stmt
,
TARRAY_GET_START
(
tagsBind
));
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
tscError
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
return
code
;
}
}
code
=
taos_stmt_execute
(
stmt
);
code
=
taos_stmt_execute
(
stmt
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
tscError
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
return
code
;
}
}
...
@@ -565,6 +610,7 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols
...
@@ -565,6 +610,7 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols
}
}
snprintf
(
sql
+
strlen
(
sql
)
-
1
,
freeBytes
-
strlen
(
sql
)
+
1
,
")"
);
snprintf
(
sql
+
strlen
(
sql
)
-
1
,
freeBytes
-
strlen
(
sql
)
+
1
,
")"
);
tscDebug
(
"insert rows %zu into child table %s. "
,
taosArrayGetSize
(
rowsBind
),
cTableName
);
int32_t
code
=
0
;
int32_t
code
=
0
;
int32_t
try
=
0
;
int32_t
try
=
0
;
do
{
do
{
...
@@ -572,13 +618,13 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols
...
@@ -572,13 +618,13 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols
code
=
taos_stmt_prepare
(
stmt
,
sql
,
strlen
(
sql
));
code
=
taos_stmt_prepare
(
stmt
,
sql
,
strlen
(
sql
));
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
tscError
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
return
code
;
}
}
code
=
taos_stmt_set_tbname
(
stmt
,
cTableName
);
code
=
taos_stmt_set_tbname
(
stmt
,
cTableName
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
tscError
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
return
code
;
}
}
...
@@ -587,19 +633,19 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols
...
@@ -587,19 +633,19 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols
TAOS_BIND
*
colsBinds
=
taosArrayGetP
(
rowsBind
,
i
);
TAOS_BIND
*
colsBinds
=
taosArrayGetP
(
rowsBind
,
i
);
code
=
taos_stmt_bind_param
(
stmt
,
colsBinds
);
code
=
taos_stmt_bind_param
(
stmt
,
colsBinds
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
tscError
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
return
code
;
}
}
code
=
taos_stmt_add_batch
(
stmt
);
code
=
taos_stmt_add_batch
(
stmt
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
tscError
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
return
code
;
}
}
}
}
code
=
taos_stmt_execute
(
stmt
);
code
=
taos_stmt_execute
(
stmt
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
tscError
(
"%s"
,
taos_stmt_errstr
(
stmt
));
taos_stmt_close
(
stmt
);
taos_stmt_close
(
stmt
);
}
else
{
}
else
{
taos_stmt_close
(
stmt
);
taos_stmt_close
(
stmt
);
...
@@ -722,6 +768,7 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num
...
@@ -722,6 +768,7 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num
TAOS_BIND
*
bind
=
colBinds
+
j
;
TAOS_BIND
*
bind
=
colBinds
+
j
;
free
(
bind
->
length
);
free
(
bind
->
length
);
}
}
free
(
colBinds
);
}
}
taosArrayDestroy
(
rowsBind
);
taosArrayDestroy
(
rowsBind
);
taosArrayDestroy
(
cTablePoints
);
taosArrayDestroy
(
cTablePoints
);
...
@@ -734,6 +781,8 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num
...
@@ -734,6 +781,8 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num
}
}
int
taos_sml_insert
(
TAOS
*
taos
,
TAOS_SML_DATA_POINT
*
points
,
int
numPoint
)
{
int
taos_sml_insert
(
TAOS
*
taos
,
TAOS_SML_DATA_POINT
*
points
,
int
numPoint
)
{
tscDebug
(
"taos_sml_insert. number of points: %d"
,
numPoint
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
SArray
*
stableSchemas
=
taosArrayInit
(
32
,
sizeof
(
SSmlSTableSchema
));
// SArray<STableColumnsSchema>
SArray
*
stableSchemas
=
taosArrayInit
(
32
,
sizeof
(
SSmlSTableSchema
));
// SArray<STableColumnsSchema>
...
@@ -846,6 +895,30 @@ int32_t parseItemValue(SLPItem* item, LPItemKind kind) {
...
@@ -846,6 +895,30 @@ int32_t parseItemValue(SLPItem* item, LPItemKind kind) {
item
->
value
=
malloc
(
item
->
length
);
item
->
value
=
malloc
(
item
->
length
);
char
*
endptr
=
NULL
;
char
*
endptr
=
NULL
;
*
(
int64_t
*
)(
item
->
value
)
=
strtoll
(
sv
,
&
endptr
,
10
);
*
(
int64_t
*
)(
item
->
value
)
=
strtoll
(
sv
,
&
endptr
,
10
);
}
else
if
(
*
last
==
'b'
)
{
item
->
type
=
TSDB_DATA_TYPE_TINYINT
;
item
->
length
=
(
int16_t
)
tDataTypes
[
item
->
type
].
bytes
;
item
->
value
=
malloc
(
item
->
length
);
char
*
endptr
=
NULL
;
*
(
int8_t
*
)(
item
->
value
)
=
strtoll
(
sv
,
&
endptr
,
10
);
}
else
if
(
*
last
==
's'
)
{
item
->
type
=
TSDB_DATA_TYPE_SMALLINT
;
item
->
length
=
(
int16_t
)
tDataTypes
[
item
->
type
].
bytes
;
item
->
value
=
malloc
(
item
->
length
);
char
*
endptr
=
NULL
;
*
(
int16_t
*
)(
item
->
value
)
=
strtoll
(
sv
,
&
endptr
,
10
);
}
else
if
(
*
last
==
'w'
)
{
item
->
type
=
TSDB_DATA_TYPE_INT
;
item
->
length
=
(
int16_t
)
tDataTypes
[
item
->
type
].
bytes
;
item
->
value
=
malloc
(
item
->
length
);
char
*
endptr
=
NULL
;
*
(
int32_t
*
)(
item
->
value
)
=
strtoll
(
sv
,
&
endptr
,
10
);
}
else
if
(
*
last
==
'f'
)
{
item
->
type
=
TSDB_DATA_TYPE_FLOAT
;
item
->
length
=
(
int16_t
)
tDataTypes
[
item
->
type
].
bytes
;
item
->
value
=
malloc
(
item
->
length
);
char
*
endptr
=
NULL
;
*
(
float
*
)(
item
->
value
)
=
strtold
(
sv
,
&
endptr
);
}
else
{
}
else
{
item
->
type
=
TSDB_DATA_TYPE_DOUBLE
;
item
->
type
=
TSDB_DATA_TYPE_DOUBLE
;
item
->
length
=
(
int16_t
)
tDataTypes
[
item
->
type
].
bytes
;
item
->
length
=
(
int16_t
)
tDataTypes
[
item
->
type
].
bytes
;
...
@@ -1001,6 +1074,36 @@ int32_t tscParseLines(char* lines[], int numLines, SArray* points, SArray* faile
...
@@ -1001,6 +1074,36 @@ int32_t tscParseLines(char* lines[], int numLines, SArray* points, SArray* faile
return
0
;
return
0
;
}
}
void
destroyLPPoint
(
void
*
p
)
{
SLPPoint
*
lpPoint
=
p
;
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
lpPoint
->
fields
);
++
i
)
{
SLPItem
*
item
=
taosArrayGet
(
lpPoint
->
fields
,
i
);
free
(
item
->
value
);
}
taosArrayDestroy
(
lpPoint
->
fields
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
lpPoint
->
tags
);
++
i
)
{
SLPItem
*
item
=
taosArrayGet
(
lpPoint
->
tags
,
i
);
free
(
item
->
value
);
}
taosArrayDestroy
(
lpPoint
->
tags
);
}
void
destroySmlDataPoint
(
TAOS_SML_DATA_POINT
*
point
)
{
for
(
int
i
=
0
;
i
<
point
->
tagNum
;
++
i
)
{
free
((
point
->
tags
+
i
)
->
key
);
free
((
point
->
tags
+
i
)
->
value
);
}
free
(
point
->
tags
);
for
(
int
i
=
0
;
i
<
point
->
fieldNum
;
++
i
)
{
free
((
point
->
fields
+
i
)
->
key
);
free
((
point
->
fields
+
i
)
->
value
);
}
free
(
point
->
fields
);
free
(
point
->
stableName
);
free
(
point
->
childTableName
);
}
int
taos_insert_by_lines
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
)
{
int
taos_insert_by_lines
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
)
{
SArray
*
lpPoints
=
taosArrayInit
(
numLines
,
sizeof
(
SLPPoint
));
SArray
*
lpPoints
=
taosArrayInit
(
numLines
,
sizeof
(
SLPPoint
));
tscParseLines
(
lines
,
numLines
,
lpPoints
,
NULL
);
tscParseLines
(
lines
,
numLines
,
lpPoints
,
NULL
);
...
@@ -1065,6 +1168,12 @@ int taos_insert_by_lines(TAOS* taos, char* lines[], int numLines) {
...
@@ -1065,6 +1168,12 @@ int taos_insert_by_lines(TAOS* taos, char* lines[], int numLines) {
}
}
taos_sml_insert
(
taos
,
points
,
numPoints
);
taos_sml_insert
(
taos
,
points
,
numPoints
);
for
(
int
i
=
0
;
i
<
numPoints
;
++
i
)
{
destroySmlDataPoint
(
points
+
i
);
}
free
(
points
);
taosArrayDestroyEx
(
lpPoints
,
destroyLPPoint
);
return
0
;
return
0
;
}
}
tests/examples/c/apitest.c
浏览文件 @
0d719ab4
...
@@ -968,12 +968,13 @@ int32_t verify_schema_less(TAOS* taos) {
...
@@ -968,12 +968,13 @@ int32_t verify_schema_less(TAOS* taos) {
"st,t1=4i,t3=
\"
t4
\"
,t2=5,t4=5 c1=3i,c3=L
\"
passitagin
\"
,c2=true,c4=5,c5=5 1626006833640000000"
,
"st,t1=4i,t3=
\"
t4
\"
,t2=5,t4=5 c1=3i,c3=L
\"
passitagin
\"
,c2=true,c4=5,c5=5 1626006833640000000"
,
"st,t1=4i,t2=5,t3=
\"
t4
\"
c1=3i,c3=L
\"
passitagain
\"
,c2=true,c4=5 1626006833642000000"
,
"st,t1=4i,t2=5,t3=
\"
t4
\"
c1=3i,c3=L
\"
passitagain
\"
,c2=true,c4=5 1626006833642000000"
,
"ste,t2=5,t3=L
\"
ste
\"
c1=true,c2=4,c3=
\"
iam
\"
1626056811823316532"
,
"ste,t2=5,t3=L
\"
ste
\"
c1=true,c2=4,c3=
\"
iam
\"
1626056811823316532"
,
"ste,t2=5,t3=L
\"
ste2
\"
c3=
\"
iamszhou
\"
,c4=false 1626056811843316532"
"ste,t2=5,t3=L
\"
ste2
\"
c3=
\"
iamszhou
\"
,c4=false 1626056811843316532"
,
"ste,t2=5,t3=L
\"
ste2
\"
c3=
\"
iamszhou
\"
,c4=false,c5=32b,c6=64s,c7=32w,c8=88.88f 1626056812843316532"
};
};
// int code = taos_insert_by_lines(taos, lines , 5
);
int
code
=
taos_insert_by_lines
(
taos
,
lines
,
6
);
int
code
=
taos_insert_by_lines
(
taos
,
&
lines
[
0
],
1
);
//
int code = taos_insert_by_lines(taos, &lines[0], 1);
code
=
taos_insert_by_lines
(
taos
,
&
lines
[
1
],
1
);
//
code = taos_insert_by_lines(taos, &lines[1], 1);
return
code
;
return
code
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录