Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4fa52dc6
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看板
提交
4fa52dc6
编写于
5月 01, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor:fix schemaless error & add unit test cases
上级
ec97d053
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
177 addition
and
26 deletion
+177
-26
cmake/cmake.define
cmake/cmake.define
+1
-1
include/libs/parser/parser.h
include/libs/parser/parser.h
+1
-1
source/client/src/clientMain.c
source/client/src/clientMain.c
+0
-5
source/client/src/clientSml.c
source/client/src/clientSml.c
+23
-14
source/client/test/CMakeLists.txt
source/client/test/CMakeLists.txt
+17
-4
source/client/test/smlTest.cpp
source/client/test/smlTest.cpp
+134
-0
source/libs/scalar/test/scalar/scalarTests.cpp
source/libs/scalar/test/scalar/scalarTests.cpp
+1
-1
未找到文件。
cmake/cmake.define
浏览文件 @
4fa52dc6
...
...
@@ -56,7 +56,7 @@ ELSE ()
MESSAGE(STATUS "Will compile with Address Sanitizer!")
ELSE ()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W
error -Werror=return-typ
e -fPIC -gdwarf-2 -g3")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W
no-literal-suffix -Werror=return-type -fpermissiv
e -fPIC -gdwarf-2 -g3")
ENDIF ()
MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}")
...
...
include/libs/parser/parser.h
浏览文件 @
4fa52dc6
...
...
@@ -98,7 +98,7 @@ int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char*
void
*
smlInitHandle
(
SQuery
*
pQuery
);
void
smlDestroyHandle
(
void
*
pHandle
);
int32_t
smlBindData
(
void
*
handle
,
SArray
*
tags
,
SArray
*
cols
,
STableMeta
*
pTableMeta
,
char
*
msgBuf
,
int16_t
msgBufLen
);
int32_t
smlBindData
(
void
*
handle
,
SArray
*
tags
,
SArray
*
cols
Format
,
SHashObj
*
colsHash
,
SArray
*
cols
,
bool
format
,
STableMeta
*
pTableMeta
,
char
*
msgBuf
,
int16_t
msgBufLen
);
int32_t
smlBuildOutput
(
void
*
handle
,
SHashObj
*
pVgHash
);
#ifdef __cplusplus
...
...
source/client/src/clientMain.c
浏览文件 @
4fa52dc6
...
...
@@ -758,8 +758,3 @@ int taos_stmt_close(TAOS_STMT *stmt) {
return
stmtClose
(
stmt
);
}
TAOS_RES
*
taos_schemaless_insert
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
,
int
protocol
,
int
precision
)
{
// TODO
return
NULL
;
}
source/client/src/clientSml.c
浏览文件 @
4fa52dc6
#include <clientInt.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
...
...
@@ -15,6 +14,7 @@
#include "ttypes.h"
#include "tcommon.h"
#include "catalog.h"
#include "clientInt.h"
//=================================================================================================
#define SPACE ' '
...
...
@@ -971,7 +971,7 @@ static int32_t smlParseString(const char* sql, SSmlLineInfo *elements, SSmlMsgBu
if
(
!
elements
->
cols
)
{
smlBuildInvalidDataMsg
(
msg
,
"invalid columns"
,
elements
->
cols
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
}
bool
isInQuote
=
false
;
while
(
*
sql
!=
'\0'
)
{
...
...
@@ -983,12 +983,18 @@ static int32_t smlParseString(const char* sql, SSmlLineInfo *elements, SSmlMsgBu
}
sql
++
;
}
if
(
isInQuote
){
smlBuildInvalidDataMsg
(
msg
,
"only one quote"
,
elements
->
cols
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
elements
->
colsLen
=
sql
-
elements
->
cols
;
// parse ts,ts can be empty
while
(
*
sql
!=
'\0'
)
{
if
(
*
sql
!=
SPACE
)
{
if
(
*
sql
!=
SPACE
&&
elements
->
timestamp
==
NULL
)
{
elements
->
timestamp
=
sql
;
}
if
(
*
sql
==
SPACE
&&
elements
->
timestamp
!=
NULL
){
break
;
}
sql
++
;
...
...
@@ -1321,7 +1327,7 @@ static SSmlTableInfo* smlBuildTableInfo(bool format){
goto
cleanup
;
}
tag
->
columnsHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
false
);
tag
->
columnsHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
if
(
tag
->
columnsHash
==
NULL
)
{
uError
(
"SML:smlParseLine failed to allocate memory"
);
goto
cleanup
;
...
...
@@ -1365,7 +1371,7 @@ static int32_t smlDealCols(SSmlTableInfo* oneTable, bool dataFormat, SArray *col
if
(
dataFormat
){
taosArrayPush
(
oneTable
->
colsFormat
,
&
cols
);
}
else
{
SHashObj
*
kvHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
false
);
SHashObj
*
kvHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
if
(
!
kvHash
){
uError
(
"SML:smlDealCols failed to allocate memory"
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
...
...
@@ -1381,6 +1387,7 @@ static int32_t smlDealCols(SSmlTableInfo* oneTable, bool dataFormat, SArray *col
}
taosArrayPush
(
oneTable
->
cols
,
&
kvHash
);
}
return
TSDB_CODE_SUCCESS
;
}
static
SSmlSTableMeta
*
smlBuildSTableMeta
(){
...
...
@@ -1388,13 +1395,13 @@ static SSmlSTableMeta* smlBuildSTableMeta(){
if
(
!
meta
){
return
NULL
;
}
meta
->
tagHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
false
);
meta
->
tagHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
if
(
meta
->
tagHash
==
NULL
)
{
uError
(
"SML:smlBuildSTableMeta failed to allocate memory"
);
goto
cleanup
;
}
meta
->
fieldHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
false
);
meta
->
fieldHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
if
(
meta
->
fieldHash
==
NULL
)
{
uError
(
"SML:smlBuildSTableMeta failed to allocate memory"
);
goto
cleanup
;
...
...
@@ -1528,6 +1535,7 @@ static void smlDestroyInfo(SSmlHandle* info){
}
static
SSmlHandle
*
smlBuildSmlInfo
(
TAOS
*
taos
,
SRequestObj
*
request
,
SMLProtocolType
protocol
,
int8_t
precision
,
bool
dataFormat
){
int32_t
code
=
TSDB_CODE_SUCCESS
;
SSmlHandle
*
info
=
taosMemoryMalloc
(
sizeof
(
SSmlHandle
));
if
(
NULL
==
info
)
{
return
NULL
;
...
...
@@ -1550,7 +1558,7 @@ static SSmlHandle* smlBuildSmlInfo(TAOS* taos, SRequestObj* request, SMLProtocol
((
SVnodeModifOpStmt
*
)(
info
->
pQuery
->
pRoot
))
->
payloadType
=
PAYLOAD_TYPE_KV
;
info
->
taos
=
taos
;
int32_t
code
=
catalogGetHandle
(
info
->
taos
->
pAppInfo
->
clusterId
,
&
info
->
pCatalog
);
code
=
catalogGetHandle
(
info
->
taos
->
pAppInfo
->
clusterId
,
&
info
->
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
){
uError
(
"SML:0x%"
PRIx64
" get catalog error %d"
,
info
->
id
,
code
);
goto
cleanup
;
...
...
@@ -1564,9 +1572,9 @@ static SSmlHandle* smlBuildSmlInfo(TAOS* taos, SRequestObj* request, SMLProtocol
info
->
msgBuf
.
len
=
ERROR_MSG_BUF_DEFAULT_SIZE
;
info
->
exec
=
smlInitHandle
(
info
->
pQuery
);
info
->
childTables
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
false
);
info
->
superTables
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
false
);
info
->
pVgHash
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
false
);
info
->
childTables
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
info
->
superTables
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
info
->
pVgHash
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_NO_LOCK
);
if
(
NULL
==
info
->
exec
||
NULL
==
info
->
childTables
||
NULL
==
info
->
superTables
||
NULL
==
info
->
pVgHash
){
...
...
@@ -1653,7 +1661,6 @@ static int smlInsertLines(SSmlHandle *info, char* lines[], int numLines) {
uDebug
(
"SML:0x%"
PRIx64
" smlInsertLines finish inserting %d lines."
,
info
->
id
,
numLines
);
cleanup:
smlDestroyInfo
(
info
);
return
code
;
}
...
...
@@ -1681,12 +1688,12 @@ cleanup:
TAOS_RES
*
taos_schemaless_insert
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
,
int
protocol
,
int
precision
,
bool
dataFormat
)
{
SRequestObj
*
request
=
createRequest
(
taos
,
NULL
,
NULL
,
TSDB_SQL_INSERT
);
if
(
!
request
){
goto
end
;
return
NULL
;
}
SSmlHandle
*
info
=
smlBuildSmlInfo
(
taos
,
request
,
protocol
,
precision
,
dataFormat
);
if
(
!
info
){
goto
end
;
return
(
TAOS_RES
*
)
request
;
}
switch
(
protocol
)
{
...
...
@@ -1703,7 +1710,9 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr
default:
break
;
}
smlDestroyInfo
(
info
);
end:
return
(
TAOS_RES
*
)
request
;
}
source/client/test/CMakeLists.txt
浏览文件 @
4fa52dc6
...
...
@@ -17,14 +17,27 @@ TARGET_LINK_LIBRARIES(
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom
)
ADD_EXECUTABLE
(
smlTest smlTest.cpp
)
TARGET_LINK_LIBRARIES
(
smlTest
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom
)
TARGET_INCLUDE_DIRECTORIES
(
clientTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/
libs/
client/"
PRIVATE
"
${
TD_SOURCE_DIR
}
/source/
libs/
client/inc"
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/client/"
PRIVATE
"
${
TD_SOURCE_DIR
}
/source/client/inc"
)
TARGET_INCLUDE_DIRECTORIES
(
tmqTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/
libs/
client/"
PRIVATE
"
${
TD_SOURCE_DIR
}
/source/
libs/
client/inc"
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/client/"
PRIVATE
"
${
TD_SOURCE_DIR
}
/source/client/inc"
)
TARGET_INCLUDE_DIRECTORIES
(
smlTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/client/"
PRIVATE
"
${
TD_SOURCE_DIR
}
/source/client/inc"
)
source/client/test/smlTest.cpp
0 → 100644
浏览文件 @
4fa52dc6
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include <taoserror.h>
#include <tglobal.h>
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#include "../src/clientSml.c"
#include "taos.h"
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
TEST
(
testCase
,
sml_Test
)
{
char
msg
[
256
]
=
{
0
};
SSmlMsgBuf
msgBuf
;
msgBuf
.
buf
=
msg
;
msgBuf
.
len
=
256
;
SSmlLineInfo
elements
=
{
0
};
//case 1
char
*
sql
=
"st,t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000 ,32,c=3"
;
int
ret
=
smlParseString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
measure
,
sql
);
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st,t1=3,t2=4,t3=t3"
));
ASSERT_EQ
(
elements
.
tags
,
sql
+
elements
.
measureLen
+
1
);
ASSERT_EQ
(
elements
.
tagsLen
,
strlen
(
"t1=3,t2=4,t3=t3"
));
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
1
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
"c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64"
));
ASSERT_EQ
(
elements
.
timestamp
,
sql
+
elements
.
measureTagsLen
+
1
+
elements
.
colsLen
+
1
);
ASSERT_EQ
(
elements
.
timestampLen
,
strlen
(
"1626006833639000000"
));
// case 2 false
sql
=
"st,t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2,c2=false,c4=4f64 1626006833639000000"
;
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_NE
(
ret
,
0
);
// case 3 false
sql
=
"st, t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2,c2=false,c4=4f64 1626006833639000000"
;
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
2
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
"t1=3,t2=4,t3=t3"
));
// case 4 tag is null
sql
=
"st, c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000"
;
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
measure
,
sql
);
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
tags
,
sql
+
elements
.
measureLen
+
1
);
ASSERT_EQ
(
elements
.
tagsLen
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
2
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
"c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64"
));
ASSERT_EQ
(
elements
.
timestamp
,
sql
+
elements
.
measureTagsLen
+
2
+
elements
.
colsLen
+
1
);
ASSERT_EQ
(
elements
.
timestampLen
,
strlen
(
"1626006833639000000"
));
// case 5 tag is null
sql
=
" st c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000 "
;
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseString
(
sql
,
&
elements
,
&
msgBuf
);
sql
++
;
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
measure
,
sql
);
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
tags
,
sql
+
elements
.
measureLen
);
ASSERT_EQ
(
elements
.
tagsLen
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
3
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
"c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64"
));
ASSERT_EQ
(
elements
.
timestamp
,
sql
+
elements
.
measureTagsLen
+
3
+
elements
.
colsLen
+
2
);
ASSERT_EQ
(
elements
.
timestampLen
,
strlen
(
"1626006833639000000"
));
// case 6
sql
=
" st c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 "
;
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
// case 7
sql
=
" st , "
;
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseString
(
sql
,
&
elements
,
&
msgBuf
);
sql
++
;
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
3
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
","
));
// case 8 false
sql
=
", st , "
;
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_NE
(
ret
,
0
);
}
source/libs/scalar/test/scalar/scalarTests.cpp
浏览文件 @
4fa52dc6
...
...
@@ -127,7 +127,7 @@ void scltMakeValueNode(SNode **pNode, int32_t dataType, void *value) {
*
pNode
=
(
SNode
*
)
vnode
;
}
void
scltMakeColumnNode
(
SNode
**
pNode
,
SSDataBlock
**
block
,
int32_t
dataType
,
int32_t
dataBytes
,
int32_t
ro
n
wNum
,
void
*
value
)
{
void
scltMakeColumnNode
(
SNode
**
pNode
,
SSDataBlock
**
block
,
int32_t
dataType
,
int32_t
dataBytes
,
int32_t
rowNum
,
void
*
value
)
{
SNode
*
node
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN
);
SColumnNode
*
rnode
=
(
SColumnNode
*
)
node
;
rnode
->
node
.
resType
.
type
=
dataType
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录