Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
aee50c89
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看板
提交
aee50c89
编写于
7月 12, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add unit test
上级
56819eaf
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
139 addition
and
23 deletion
+139
-23
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+26
-20
tests/examples/c/apitest.c
tests/examples/c/apitest.c
+15
-3
tests/tsim/inc/sim.h
tests/tsim/inc/sim.h
+4
-0
tests/tsim/src/simExe.c
tests/tsim/src/simExe.c
+46
-0
tests/tsim/src/simParse.c
tests/tsim/src/simParse.c
+48
-0
未找到文件。
src/client/src/tscParseLineProtocol.c
浏览文件 @
aee50c89
...
...
@@ -65,6 +65,11 @@ int compareSmlColKv(const void* p1, const void* p2) {
}
int32_t
loadTableMeta
(
TAOS
*
taos
,
char
*
tableName
,
SSmlSTableSchema
*
schema
)
{
schema
->
tags
=
taosArrayInit
(
8
,
sizeof
(
SSchema
));
schema
->
fields
=
taosArrayInit
(
64
,
sizeof
(
SSchema
));
schema
->
tagHash
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
false
);
schema
->
fieldHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
false
);
int32_t
code
=
0
;
STscObj
*
pObj
=
(
STscObj
*
)
taos
;
...
...
@@ -203,7 +208,7 @@ int32_t addTaosFieldToHashAndArray(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* a
pField
->
bytes
=
MAX
(
pField
->
bytes
,
bytes
);
}
else
{
SSchema
field
;
SSchema
field
=
{
0
}
;
size_t
tagKeyLen
=
strlen
(
smlKv
->
key
);
strncpy
(
field
.
name
,
smlKv
->
key
,
tagKeyLen
);
field
.
name
[
tagKeyLen
]
=
'\0'
;
...
...
@@ -371,7 +376,7 @@ int32_t getChildTableName(TAOS_SML_DATA_POINT* point, char* tableName, int* tabl
MD5Update
(
&
context
,
(
uint8_t
*
)
keyJoined
,
(
uint32_t
)
len
);
MD5Final
(
&
context
);
*
tableNameLen
=
snprintf
(
tableName
,
*
tableNameLen
,
"tbl%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
,
context
.
digest
[
0
],
"tbl
_
%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
[
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
]);
...
...
@@ -418,14 +423,15 @@ int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, const cha
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
}
TAOS_RES
*
res
=
taos_stmt_use_result
(
stmt
);
return
taos_errno
(
res
);
taos_stmt_close
(
stmt
);
return
0
;
}
int32_t
insertBatch
(
TAOS
*
taos
,
char
*
cTableName
,
SArray
*
colsSchema
,
SArray
*
rowsBind
)
{
size_t
numCols
=
taosArrayGetSize
(
colsSchema
);
char
sql
[
TSDB_MAX_BINARY_LEN
];
int32_t
freeBytes
=
TSDB_MAX_BINARY_LEN
;
char
sql
[
4096
];
int32_t
freeBytes
=
4096
;
sprintf
(
sql
,
"insert into ? ("
);
for
(
int
i
=
0
;
i
<
numCols
;
++
i
)
{
...
...
@@ -454,8 +460,8 @@ int32_t insertBatch(TAOS* taos, char* cTableName, SArray* colsSchema, SArray* r
}
size_t
rows
=
taosArrayGetSize
(
rowsBind
);
for
(
int32_t
i
=
0
;
i
<
rows
;
++
i
)
{
SArray
*
colBind
=
taosArrayGetP
(
rowsBind
,
i
);
code
=
taos_stmt_bind_param
(
stmt
,
TARRAY_GET_START
(
colBind
)
);
TAOS_BIND
*
colsBinds
=
taosArrayGetP
(
rowsBind
,
i
);
code
=
taos_stmt_bind_param
(
stmt
,
colsBinds
);
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
...
...
@@ -472,8 +478,10 @@ int32_t insertBatch(TAOS* taos, char* cTableName, SArray* colsSchema, SArray* r
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
}
TAOS_RES
*
res
=
taos_stmt_use_result
(
stmt
);
return
taos_errno
(
res
);
taos_stmt_close
(
stmt
);
return
code
;
}
int32_t
insertPoints
(
TAOS
*
taos
,
TAOS_SML_DATA_POINT
*
points
,
int32_t
numPoints
)
{
...
...
@@ -526,7 +534,6 @@ int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints)
TAOS_SML_DATA_POINT
*
point
=
taosArrayGetP
(
cTablePoints
,
0
);
int32_t
numTags
=
taosArrayGetSize
(
point
->
schema
->
tags
);
int32_t
numCols
=
taosArrayGetSize
(
point
->
schema
->
fields
);
char
*
ctableName
=
point
->
childTableName
;
SArray
*
tagBinds
=
taosArrayInit
(
numTags
,
sizeof
(
TAOS_BIND
));
taosArraySetSize
(
tagBinds
,
numTags
);
...
...
@@ -551,16 +558,15 @@ int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints)
for
(
int
i
=
0
;
i
<
rows
;
++
i
)
{
point
=
taosArrayGetP
(
cTablePoints
,
i
);
SArray
*
colBinds
=
taosArrayInit
(
numCols
,
sizeof
(
TAOS_BIND
));
taosArraySetSize
(
colBinds
,
numCols
);
TAOS_BIND
*
colBinds
=
calloc
(
numCols
,
sizeof
(
TAOS_BIND
));
for
(
int
j
=
0
;
j
<
numCols
;
++
j
)
{
TAOS_BIND
*
bind
=
taosArrayGet
(
colBinds
,
j
)
;
TAOS_BIND
*
bind
=
colBinds
+
j
;
bind
->
is_null
=
&
isNullColBind
;
}
for
(
int
j
=
0
;
j
<
point
->
fieldNum
;
++
j
)
{
TAOS_SML_KV
*
kv
=
point
->
fields
+
j
;
int32_t
idx
=
TARRAY_ELEM_IDX
(
point
->
schema
->
fields
,
kv
->
schema
);
TAOS_BIND
*
bind
=
taosArrayGet
(
colBinds
,
idx
)
;
TAOS_BIND
*
bind
=
colBinds
+
idx
;
bind
->
buffer_type
=
kv
->
type
;
bind
->
length
=
malloc
(
sizeof
(
uintptr_t
*
));
*
bind
->
length
=
kv
->
length
;
...
...
@@ -571,7 +577,7 @@ int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints)
}
creatChildTableIfNotExists
(
taos
,
point
->
childTableName
,
point
->
stableName
,
point
->
schema
->
tags
,
tagBinds
);
insertBatch
(
taos
,
ct
ableName
,
point
->
schema
->
fields
,
rowsBind
);
insertBatch
(
taos
,
point
->
childT
ableName
,
point
->
schema
->
fields
,
rowsBind
);
pCTablePoints
=
taosHashIterate
(
cname2points
,
pCTablePoints
);
}
...
...
@@ -621,10 +627,6 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
for
(
int
i
=
0
;
i
<
numStable
;
++
i
)
{
SSmlSTableSchema
*
pointSchema
=
taosArrayGet
(
stableArray
,
i
);
SSmlSTableSchema
dbSchema
=
{
0
};
dbSchema
.
tags
=
taosArrayInit
(
8
,
sizeof
(
SSchema
));
dbSchema
.
fields
=
taosArrayInit
(
64
,
sizeof
(
SSchema
));
dbSchema
.
tagHash
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
false
);
dbSchema
.
fieldHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
false
);
code
=
loadTableMeta
(
taos
,
pointSchema
->
sTableName
,
&
dbSchema
);
...
...
@@ -652,6 +654,8 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
generateSchemaAction
(
pointTag
,
dbTagHash
,
true
,
pointSchema
->
sTableName
,
&
schemaAction
,
&
actionNeeded
);
if
(
actionNeeded
)
{
applySchemaAction
(
taos
,
&
schemaAction
);
code
=
loadTableMeta
(
taos
,
pointSchema
->
sTableName
,
&
dbSchema
);
pointSchema
->
precision
=
dbSchema
.
precision
;
}
}
...
...
@@ -666,6 +670,8 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
generateSchemaAction
(
pointCol
,
dbFieldHash
,
false
,
pointSchema
->
sTableName
,
&
schemaAction
,
&
actionNeeded
);
if
(
actionNeeded
)
{
applySchemaAction
(
taos
,
&
schemaAction
);
code
=
loadTableMeta
(
taos
,
pointSchema
->
sTableName
,
&
dbSchema
);
pointSchema
->
precision
=
dbSchema
.
precision
;
}
}
...
...
tests/examples/c/apitest.c
浏览文件 @
aee50c89
...
...
@@ -965,12 +965,24 @@ int32_t verify_schema_less(TAOS* taos) {
char
*
lines
[]
=
{
"st,t1=3i,t2=4,t3=
\"
t3
\"
c1=3i,c3=L
\"
passit
\"
,c2=false,c4=4 1626006833639000000"
,
"st,t1=4i,t
2=5,t3=
\"
t4
\"
c1=3i,c3=L
\"
passitagain
\"
,c2=true,c4=5 1626006833640000000"
,
"st,t1=4i,t
3=
\"
t4
\"
,t2=5,t4=5
c1=3i,c3=L
\"
passitagain
\"
,c2=true,c4=5 1626006833640000000"
,
"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
\"
ste2
\"
c3=
\"
iamszhou
\"
,c4=false 1626056811843316532"
};
int
code
=
taos_insert_by_lines
(
taos
,
lines
,
5
);
// int code = taos_insert_by_lines(taos, lines , 5);
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[2]), 1);
//
// code = taos_insert_by_lines(taos, &(lines[3]), 1);
//
// code = taos_insert_by_lines(taos, &(lines[4]), 1);
return
code
;
}
...
...
@@ -980,7 +992,7 @@ int main(int argc, char *argv[]) {
const
char
*
passwd
=
"taosdata"
;
taos_options
(
TSDB_OPTION_TIMEZONE
,
"GMT-8"
);
taos_options
(
TSDB_OPTION_CONFIGDIR
,
"/etc/taos"
);
TAOS
*
taos
=
taos_connect
(
host
,
user
,
passwd
,
""
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"
\033
[31mfailed to connect to db, reason:%s
\033
[0m
\n
"
,
taos_errstr
(
taos
));
...
...
tests/tsim/inc/sim.h
浏览文件 @
aee50c89
...
...
@@ -87,6 +87,8 @@ enum {
SIM_CMD_RESTFUL
,
SIM_CMD_TEST
,
SIM_CMD_RETURN
,
SIM_CMD_LINE_INSERT
,
SIM_CMD_LINE_INSERT_ERROR
,
SIM_CMD_END
};
...
...
@@ -172,6 +174,8 @@ bool simExecuteSqlCmd(SScript *script, char *option);
bool
simExecuteSqlErrorCmd
(
SScript
*
script
,
char
*
rest
);
bool
simExecuteSqlSlowCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteRestfulCmd
(
SScript
*
script
,
char
*
rest
);
bool
simExecuteLineInsertCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteLineInsertErrorCmd
(
SScript
*
script
,
char
*
option
);
void
simVisuallizeOption
(
SScript
*
script
,
char
*
src
,
char
*
dst
);
#endif
\ No newline at end of file
tests/tsim/src/simExe.c
浏览文件 @
aee50c89
...
...
@@ -1067,3 +1067,49 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return
false
;
}
bool
simExecuteLineInsertCmd
(
SScript
*
script
,
char
*
rest
)
{
char
buf
[
TSDB_MAX_BINARY_LEN
];
simVisuallizeOption
(
script
,
rest
,
buf
);
rest
=
buf
;
SCmdLine
*
line
=
&
script
->
lines
[
script
->
linePos
];
simInfo
(
"script:%s, %s"
,
script
->
fileName
,
rest
);
simLogSql
(
buf
,
true
);
char
*
lines
[]
=
{
rest
};
int32_t
ret
=
taos_insert_by_lines
(
script
->
taos
,
lines
,
1
);
if
(
ret
==
TSDB_CODE_SUCCESS
)
{
simDebug
(
"script:%s, taos:%p, %s executed. success."
,
script
->
fileName
,
script
->
taos
,
rest
);
script
->
linePos
++
;
return
true
;
}
else
{
sprintf
(
script
->
error
,
"lineNum: %d. line: %s failed, ret:%d:%s"
,
line
->
lineNum
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
return
false
;
}
}
bool
simExecuteLineInsertErrorCmd
(
SScript
*
script
,
char
*
rest
)
{
char
buf
[
TSDB_MAX_BINARY_LEN
];
simVisuallizeOption
(
script
,
rest
,
buf
);
rest
=
buf
;
SCmdLine
*
line
=
&
script
->
lines
[
script
->
linePos
];
simInfo
(
"script:%s, %s"
,
script
->
fileName
,
rest
);
simLogSql
(
buf
,
true
);
char
*
lines
[]
=
{
rest
};
int32_t
ret
=
taos_insert_by_lines
(
script
->
taos
,
lines
,
1
);
if
(
ret
==
TSDB_CODE_SUCCESS
)
{
sprintf
(
script
->
error
,
"script:%s, taos:%p, %s executed. expect failed, but success."
,
script
->
fileName
,
script
->
taos
,
rest
);
script
->
linePos
++
;
return
false
;
}
else
{
simDebug
(
"lineNum: %d. line: %s failed, ret:%d:%s. Expect failed, so success"
,
line
->
lineNum
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
return
true
;
}
}
tests/tsim/src/simParse.c
浏览文件 @
aee50c89
...
...
@@ -838,6 +838,38 @@ bool simParseRunBackCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
return
true
;
}
bool
simParseLineInsertCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
int32_t
expLen
;
rest
++
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_LINE_INSERT
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
cmdLine
[
numOfLines
].
optionOffset
=
optionOffset
;
expLen
=
(
int32_t
)
strlen
(
rest
);
memcpy
(
optionBuffer
+
optionOffset
,
rest
,
expLen
);
optionOffset
+=
expLen
+
1
;
*
(
optionBuffer
+
optionOffset
-
1
)
=
0
;
numOfLines
++
;
return
true
;
}
bool
simParseLineInsertErrorCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
int32_t
expLen
;
rest
++
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_LINE_INSERT
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
cmdLine
[
numOfLines
].
optionOffset
=
optionOffset
;
expLen
=
(
int32_t
)
strlen
(
rest
);
memcpy
(
optionBuffer
+
optionOffset
,
rest
,
expLen
);
optionOffset
+=
expLen
+
1
;
*
(
optionBuffer
+
optionOffset
-
1
)
=
0
;
numOfLines
++
;
return
true
;
}
void
simInitsimCmdList
()
{
int32_t
cmdno
;
memset
(
simCmdList
,
0
,
SIM_CMD_END
*
sizeof
(
SCommand
));
...
...
@@ -1049,4 +1081,20 @@ void simInitsimCmdList() {
simCmdList
[
cmdno
].
parseCmd
=
simParseReturnCmd
;
simCmdList
[
cmdno
].
executeCmd
=
simExecuteReturnCmd
;
simAddCmdIntoHash
(
&
(
simCmdList
[
cmdno
]));
cmdno
=
SIM_CMD_LINE_INSERT
;
simCmdList
[
cmdno
].
cmdno
=
cmdno
;
strcpy
(
simCmdList
[
cmdno
].
name
,
"line_insert"
);
simCmdList
[
cmdno
].
nlen
=
(
int16_t
)
strlen
(
simCmdList
[
cmdno
].
name
);
simCmdList
[
cmdno
].
parseCmd
=
simParseLineInsertCmd
;
simCmdList
[
cmdno
].
executeCmd
=
simExecuteLineInsertCmd
;
simAddCmdIntoHash
(
&
(
simCmdList
[
cmdno
]));
cmdno
=
SIM_CMD_LINE_INSERT_ERROR
;
simCmdList
[
cmdno
].
cmdno
=
cmdno
;
strcpy
(
simCmdList
[
cmdno
].
name
,
"line_insert_error"
);
simCmdList
[
cmdno
].
nlen
=
(
int16_t
)
strlen
(
simCmdList
[
cmdno
].
name
);
simCmdList
[
cmdno
].
parseCmd
=
simParseLineInsertErrorCmd
;
simCmdList
[
cmdno
].
executeCmd
=
simExecuteLineInsertErrorCmd
;
simAddCmdIntoHash
(
&
(
simCmdList
[
cmdno
]));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录