Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
30065f30
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看板
未验证
提交
30065f30
编写于
12月 26, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
12月 26, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19109 from taosdata/enh/3.0_planner_optimize
enh: improve unit tests
上级
686a1a15
6a679eee
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
701 addition
and
263 deletion
+701
-263
source/libs/parser/test/parAlterToBalanceTest.cpp
source/libs/parser/test/parAlterToBalanceTest.cpp
+300
-141
source/libs/parser/test/parExplainToSyncdbTest.cpp
source/libs/parser/test/parExplainToSyncdbTest.cpp
+31
-3
source/libs/parser/test/parInitialCTest.cpp
source/libs/parser/test/parInitialCTest.cpp
+332
-116
source/libs/parser/test/parInitialDTest.cpp
source/libs/parser/test/parInitialDTest.cpp
+38
-3
未找到文件。
source/libs/parser/test/parAlterToBalanceTest.cpp
浏览文件 @
30065f30
...
...
@@ -21,6 +21,25 @@ namespace ParserTest {
class
ParserInitialATest
:
public
ParserDdlTest
{};
/*
* ALTER ACCOUNT account_name alter_account_options
*
* alter_account_options:
* alter_account_option ...
*
* alter_account_option: {
* PASS value
* | PPS value
* | TSERIES value
* | STORAGE value
* | STREAMS value
* | QTIME value
* | DBS value
* | USERS value
* | CONNS value
* | STATE value
* }
*/
TEST_F
(
ParserInitialATest
,
alterAccount
)
{
useDb
(
"root"
,
"test"
);
...
...
@@ -48,6 +67,7 @@ TEST_F(ParserInitialATest, alterDnode) {
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_ALTER_DNODE_STMT
);
ASSERT_EQ
(
pQuery
->
pCmdMsg
->
msgType
,
TDMT_MND_CONFIG_DNODE
);
SMCfgDnodeReq
req
=
{
0
};
ASSERT_EQ
(
tDeserializeSMCfgDnodeReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
req
.
dnodeId
,
expect
.
dnodeId
);
...
...
@@ -86,9 +106,8 @@ TEST_F(ParserInitialATest, alterDnode) {
* | KEEP {int_value | duration_value} -- rang [1, 365000], default 3650, unit day
* | PAGES int_value -- rang [64, INT32_MAX], default 256, unit page
* | REPLICA int_value -- todo: enum 1, 3, default 1, unit replica
* | STRICT {'off' | 'on'} -- todo: default 'off'
* | WAL_LEVEL int_value -- enum 1, 2, default 1
* | S
S
T_TRIGGER int_value -- rang [1, 16], default 8
* | S
T
T_TRIGGER int_value -- rang [1, 16], default 8
* }
*/
TEST_F
(
ParserInitialATest
,
alterDatabase
)
{
...
...
@@ -130,10 +149,11 @@ TEST_F(ParserInitialATest, alterDatabase) {
auto
setAlterDbStrict
=
[
&
](
int8_t
strict
)
{
expect
.
strict
=
strict
;
};
auto
setAlterDbCacheModel
=
[
&
](
int8_t
cacheModel
)
{
expect
.
cacheLast
=
cacheModel
;
};
auto
setAlterDbReplica
=
[
&
](
int8_t
replications
)
{
expect
.
replications
=
replications
;
};
auto
setAlterDbS
s
tTrigger
=
[
&
](
int8_t
sstTrigger
)
{
expect
.
sstTrigger
=
sstTrigger
;
};
auto
setAlterDbS
t
tTrigger
=
[
&
](
int8_t
sstTrigger
)
{
expect
.
sstTrigger
=
sstTrigger
;
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_ALTER_DATABASE_STMT
);
ASSERT_EQ
(
pQuery
->
pCmdMsg
->
msgType
,
TDMT_MND_ALTER_DB
);
SAlterDbReq
req
=
{
0
};
ASSERT_EQ
(
tDeserializeSAlterDbReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
std
::
string
(
req
.
db
),
std
::
string
(
expect
.
db
));
...
...
@@ -161,11 +181,12 @@ TEST_F(ParserInitialATest, alterDatabase) {
setAlterDbFsync
(
200
);
setAlterDbWal
(
1
);
setAlterDbCacheModel
(
TSDB_CACHE_MODEL_LAST_ROW
);
setAlterDbS
s
tTrigger
(
16
);
setAlterDbS
t
tTrigger
(
16
);
setAlterDbBuffer
(
16
);
setAlterDbPages
(
128
);
setAlterDbReplica
(
3
);
run
(
"ALTER DATABASE test BUFFER 16 CACHEMODEL 'last_row' CACHESIZE 32 WAL_FSYNC_PERIOD 200 KEEP 10 PAGES 128 "
"WAL_LEVEL 1 STT_TRIGGER 16"
);
"
REPLICA 3
WAL_LEVEL 1 STT_TRIGGER 16"
);
clearAlterDbReq
();
initAlterDb
(
"test"
);
...
...
@@ -240,6 +261,22 @@ TEST_F(ParserInitialATest, alterDatabase) {
setAlterDbWal
(
2
);
run
(
"ALTER DATABASE test WAL_LEVEL 2"
);
clearAlterDbReq
();
initAlterDb
(
"test"
);
setAlterDbReplica
(
1
);
run
(
"ALTER DATABASE test REPLICA 1"
);
setAlterDbReplica
(
3
);
run
(
"ALTER DATABASE test REPLICA 3"
);
clearAlterDbReq
();
initAlterDb
(
"test"
);
setAlterDbSttTrigger
(
1
);
run
(
"ALTER DATABASE test STT_TRIGGER 1"
);
setAlterDbSttTrigger
(
4
);
run
(
"ALTER DATABASE test STT_TRIGGER 4"
);
setAlterDbSttTrigger
(
16
);
run
(
"ALTER DATABASE test STT_TRIGGER 16"
);
clearAlterDbReq
();
}
TEST_F
(
ParserInitialATest
,
alterDatabaseSemanticCheck
)
{
...
...
@@ -260,6 +297,7 @@ TEST_F(ParserInitialATest, alterDatabaseSemanticCheck) {
run
(
"ALTER DATABASE test PAGES 63"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test WAL_LEVEL 0"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test WAL_LEVEL 3"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test REPLICA 2"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test STT_TRIGGER 0"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
run
(
"ALTER DATABASE test STT_TRIGGER 17"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
// Regardless of the specific sentence
...
...
@@ -267,7 +305,7 @@ TEST_F(ParserInitialATest, alterDatabaseSemanticCheck) {
}
/*
* ALTER LOCAL
dnode_id
'config' ['value']
* ALTER LOCAL 'config' ['value']
*/
TEST_F
(
ParserInitialATest
,
alterLocal
)
{
useDb
(
"root"
,
"test"
);
...
...
@@ -311,19 +349,19 @@ TEST_F(ParserInitialATest, alterLocal) {
* | ADD COLUMN col_name column_type
* | DROP COLUMN col_name
* | MODIFY COLUMN col_name column_type
* | RENAME COLUMN old_col_name new_col_name -- normal table
* | ADD TAG tag_name tag_type -- super table
* | DROP TAG tag_name -- super table
* | MODIFY TAG tag_name tag_type -- super table
* | RENAME TAG old_tag_name new_tag_name -- super table
* | SET TAG tag_name = new_tag_value -- child table
* | RENAME COLUMN old_col_name new_col_name --
only
normal table
* | ADD TAG tag_name tag_type --
only
super table
* | DROP TAG tag_name --
only
super table
* | MODIFY TAG tag_name tag_type --
only
super table
* | RENAME TAG old_tag_name new_tag_name --
only
super table
* | SET TAG tag_name = new_tag_value --
only
child table
* }
*
* alter_table_options:
* alter_table_option ...
*
* alter_table_option: {
* TTL int_value -- child/normal table
* TTL int_value --
only
child/normal table
* | COMMENT 'string_value'
* }
*/
...
...
@@ -379,6 +417,7 @@ TEST_F(ParserInitialATest, alterSTable) {
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_ALTER_SUPER_TABLE_STMT
);
ASSERT_EQ
(
pQuery
->
pCmdMsg
->
msgType
,
TDMT_MND_ALTER_STB
);
SMAlterStbReq
req
=
{
0
};
ASSERT_EQ
(
tDeserializeSMAlterStbReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
std
::
string
(
req
.
name
),
std
::
string
(
expect
.
name
));
...
...
@@ -444,136 +483,255 @@ TEST_F(ParserInitialATest, alterSTableSemanticCheck) {
run
(
"ALTER STABLE st1 TTL 10"
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
);
}
/*
* ALTER TABLE [db_name.]tb_name alter_table_clause
*
* alter_table_clause: {
* alter_table_options
* | ADD COLUMN col_name column_type
* | DROP COLUMN col_name
* | MODIFY COLUMN col_name column_type
* | RENAME COLUMN old_col_name new_col_name -- only normal table
* | ADD TAG tag_name tag_type -- only super table
* | DROP TAG tag_name -- only super table
* | MODIFY TAG tag_name tag_type -- only super table
* | RENAME TAG old_tag_name new_tag_name -- only super table
* | SET TAG tag_name = new_tag_value -- only child table
* }
*
* alter_table_options:
* alter_table_option ...
*
* alter_table_option: {
* TTL int_value -- only child/normal table
* | COMMENT 'string_value'
* }
*/
TEST_F
(
ParserInitialATest
,
alterTable
)
{
useDb
(
"root"
,
"test"
);
SVAlterTbReq
expect
=
{
0
};
auto
clearAlterTbReq
=
[
&
]()
{
free
(
expect
.
tbName
);
free
(
expect
.
colName
);
free
(
expect
.
colNewName
);
free
(
expect
.
tagName
);
memset
(
&
expect
,
0
,
sizeof
(
SVAlterTbReq
));
};
auto
setAlterTableCol
=
[
&
](
const
char
*
pTbname
,
int8_t
alterType
,
const
char
*
pColName
,
int8_t
dataType
=
0
,
int32_t
dataBytes
=
0
,
const
char
*
pNewColName
=
nullptr
)
{
expect
.
tbName
=
strdup
(
pTbname
);
expect
.
action
=
alterType
;
expect
.
colName
=
strdup
(
pColName
);
switch
(
alterType
)
{
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
expect
.
type
=
dataType
;
expect
.
flags
=
COL_SMA_ON
;
expect
.
bytes
=
dataBytes
>
0
?
dataBytes
:
(
dataType
>
0
?
tDataTypes
[
dataType
].
bytes
:
0
);
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
expect
.
colModBytes
=
dataBytes
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
expect
.
colNewName
=
strdup
(
pNewColName
);
break
;
default:
break
;
}
};
auto
setAlterTableTag
=
[
&
](
const
char
*
pTbname
,
const
char
*
pTagName
,
uint8_t
*
pNewVal
,
uint32_t
bytes
)
{
expect
.
tbName
=
strdup
(
pTbname
);
expect
.
action
=
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
;
expect
.
tagName
=
strdup
(
pTagName
);
expect
.
isNull
=
(
nullptr
==
pNewVal
);
expect
.
nTagVal
=
bytes
;
expect
.
pTagVal
=
pNewVal
;
};
auto
setAlterTableOptions
=
[
&
](
const
char
*
pTbname
,
int32_t
ttl
,
char
*
pComment
=
nullptr
)
{
expect
.
tbName
=
strdup
(
pTbname
);
expect
.
action
=
TSDB_ALTER_TABLE_UPDATE_OPTIONS
;
if
(
-
1
!=
ttl
)
{
expect
.
updateTTL
=
true
;
expect
.
newTTL
=
ttl
;
}
if
(
nullptr
!=
pComment
)
{
expect
.
newCommentLen
=
strlen
(
pComment
);
expect
.
newComment
=
pComment
;
}
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_VNODE_MODIFY_STMT
);
SVnodeModifyOpStmt
*
pStmt
=
(
SVnodeModifyOpStmt
*
)
pQuery
->
pRoot
;
ASSERT_EQ
(
pStmt
->
sqlNodeType
,
QUERY_NODE_ALTER_TABLE_STMT
);
ASSERT_NE
(
pStmt
->
pDataBlocks
,
nullptr
);
ASSERT_EQ
(
taosArrayGetSize
(
pStmt
->
pDataBlocks
),
1
);
SVgDataBlocks
*
pVgData
=
(
SVgDataBlocks
*
)
taosArrayGetP
(
pStmt
->
pDataBlocks
,
0
);
void
*
pBuf
=
POINTER_SHIFT
(
pVgData
->
pData
,
sizeof
(
SMsgHead
));
SVAlterTbReq
req
=
{
0
};
SDecoder
coder
=
{
0
};
tDecoderInit
(
&
coder
,
(
uint8_t
*
)
pBuf
,
pVgData
->
size
);
ASSERT_EQ
(
tDecodeSVAlterTbReq
(
&
coder
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
std
::
string
(
req
.
tbName
),
std
::
string
(
expect
.
tbName
));
ASSERT_EQ
(
req
.
action
,
expect
.
action
);
if
(
nullptr
!=
expect
.
colName
)
{
ASSERT_EQ
(
std
::
string
(
req
.
colName
),
std
::
string
(
expect
.
colName
));
}
ASSERT_EQ
(
req
.
type
,
expect
.
type
);
ASSERT_EQ
(
req
.
flags
,
expect
.
flags
);
ASSERT_EQ
(
req
.
bytes
,
expect
.
bytes
);
ASSERT_EQ
(
req
.
colModBytes
,
expect
.
colModBytes
);
if
(
nullptr
!=
expect
.
colNewName
)
{
ASSERT_EQ
(
std
::
string
(
req
.
colNewName
),
std
::
string
(
expect
.
colNewName
));
}
if
(
nullptr
!=
expect
.
tagName
)
{
ASSERT_EQ
(
std
::
string
(
req
.
tagName
),
std
::
string
(
expect
.
tagName
));
}
ASSERT_EQ
(
req
.
isNull
,
expect
.
isNull
);
ASSERT_EQ
(
req
.
nTagVal
,
expect
.
nTagVal
);
ASSERT_EQ
(
memcmp
(
req
.
pTagVal
,
expect
.
pTagVal
,
expect
.
nTagVal
),
0
);
ASSERT_EQ
(
req
.
updateTTL
,
expect
.
updateTTL
);
ASSERT_EQ
(
req
.
newTTL
,
expect
.
newTTL
);
if
(
nullptr
!=
expect
.
newComment
)
{
ASSERT_EQ
(
std
::
string
(
req
.
newComment
),
std
::
string
(
expect
.
newComment
));
ASSERT_EQ
(
req
.
newCommentLen
,
strlen
(
req
.
newComment
));
ASSERT_EQ
(
expect
.
newCommentLen
,
strlen
(
expect
.
newComment
));
}
tDecoderClear
(
&
coder
);
});
setAlterTableOptions
(
"t1"
,
10
,
nullptr
);
run
(
"ALTER TABLE t1 TTL 10"
);
clearAlterTbReq
();
setAlterTableOptions
(
"t1"
,
-
1
,
(
char
*
)
"test"
);
run
(
"ALTER TABLE t1 COMMENT 'test'"
);
clearAlterTbReq
();
setAlterTableCol
(
"t1"
,
TSDB_ALTER_TABLE_ADD_COLUMN
,
"cc1"
,
TSDB_DATA_TYPE_BIGINT
);
run
(
"ALTER TABLE t1 ADD COLUMN cc1 BIGINT"
);
clearAlterTbReq
();
setAlterTableCol
(
"t1"
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
"c1"
);
run
(
"ALTER TABLE t1 DROP COLUMN c1"
);
clearAlterTbReq
();
setAlterTableCol
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
,
"c2"
,
TSDB_DATA_TYPE_VARCHAR
,
30
+
VARSTR_HEADER_SIZE
);
run
(
"ALTER TABLE t1 MODIFY COLUMN c2 VARCHAR(30)"
);
clearAlterTbReq
();
setAlterTableCol
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
,
"c1"
,
0
,
0
,
"cc1"
);
run
(
"ALTER TABLE t1 RENAME COLUMN c1 cc1"
);
clearAlterTbReq
();
int32_t
val
=
10
;
setAlterTableTag
(
"st1s1"
,
"tag1"
,
(
uint8_t
*
)
&
val
,
sizeof
(
val
));
run
(
"ALTER TABLE st1s1 SET TAG tag1=10"
);
clearAlterTbReq
();
// normal/child table
{
SVAlterTbReq
expect
=
{
0
};
auto
clearAlterTbReq
=
[
&
]()
{
free
(
expect
.
tbName
);
free
(
expect
.
colName
);
free
(
expect
.
colNewName
);
free
(
expect
.
tagName
);
memset
(
&
expect
,
0
,
sizeof
(
SVAlterTbReq
));
};
auto
setAlterTableCol
=
[
&
](
const
char
*
pTbname
,
int8_t
alterType
,
const
char
*
pColName
,
int8_t
dataType
=
0
,
int32_t
dataBytes
=
0
,
const
char
*
pNewColName
=
nullptr
)
{
expect
.
tbName
=
strdup
(
pTbname
);
expect
.
action
=
alterType
;
expect
.
colName
=
strdup
(
pColName
);
switch
(
alterType
)
{
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
expect
.
type
=
dataType
;
expect
.
flags
=
COL_SMA_ON
;
expect
.
bytes
=
dataBytes
>
0
?
dataBytes
:
(
dataType
>
0
?
tDataTypes
[
dataType
].
bytes
:
0
);
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
expect
.
colModBytes
=
dataBytes
;
break
;
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
expect
.
colNewName
=
strdup
(
pNewColName
);
break
;
default:
break
;
}
};
auto
setAlterTableTag
=
[
&
](
const
char
*
pTbname
,
const
char
*
pTagName
,
uint8_t
*
pNewVal
,
uint32_t
bytes
)
{
expect
.
tbName
=
strdup
(
pTbname
);
expect
.
action
=
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
;
expect
.
tagName
=
strdup
(
pTagName
);
expect
.
isNull
=
(
nullptr
==
pNewVal
);
expect
.
nTagVal
=
bytes
;
expect
.
pTagVal
=
pNewVal
;
};
auto
setAlterTableOptions
=
[
&
](
const
char
*
pTbname
,
int32_t
ttl
,
char
*
pComment
=
nullptr
)
{
expect
.
tbName
=
strdup
(
pTbname
);
expect
.
action
=
TSDB_ALTER_TABLE_UPDATE_OPTIONS
;
if
(
-
1
!=
ttl
)
{
expect
.
updateTTL
=
true
;
expect
.
newTTL
=
ttl
;
}
if
(
nullptr
!=
pComment
)
{
expect
.
newCommentLen
=
strlen
(
pComment
);
expect
.
newComment
=
pComment
;
}
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_VNODE_MODIFY_STMT
);
SVnodeModifyOpStmt
*
pStmt
=
(
SVnodeModifyOpStmt
*
)
pQuery
->
pRoot
;
ASSERT_EQ
(
pStmt
->
sqlNodeType
,
QUERY_NODE_ALTER_TABLE_STMT
);
ASSERT_NE
(
pStmt
->
pDataBlocks
,
nullptr
);
ASSERT_EQ
(
taosArrayGetSize
(
pStmt
->
pDataBlocks
),
1
);
SVgDataBlocks
*
pVgData
=
(
SVgDataBlocks
*
)
taosArrayGetP
(
pStmt
->
pDataBlocks
,
0
);
void
*
pBuf
=
POINTER_SHIFT
(
pVgData
->
pData
,
sizeof
(
SMsgHead
));
SVAlterTbReq
req
=
{
0
};
SDecoder
coder
=
{
0
};
tDecoderInit
(
&
coder
,
(
uint8_t
*
)
pBuf
,
pVgData
->
size
);
ASSERT_EQ
(
tDecodeSVAlterTbReq
(
&
coder
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
std
::
string
(
req
.
tbName
),
std
::
string
(
expect
.
tbName
));
ASSERT_EQ
(
req
.
action
,
expect
.
action
);
if
(
nullptr
!=
expect
.
colName
)
{
ASSERT_EQ
(
std
::
string
(
req
.
colName
),
std
::
string
(
expect
.
colName
));
}
ASSERT_EQ
(
req
.
type
,
expect
.
type
);
ASSERT_EQ
(
req
.
flags
,
expect
.
flags
);
ASSERT_EQ
(
req
.
bytes
,
expect
.
bytes
);
ASSERT_EQ
(
req
.
colModBytes
,
expect
.
colModBytes
);
if
(
nullptr
!=
expect
.
colNewName
)
{
ASSERT_EQ
(
std
::
string
(
req
.
colNewName
),
std
::
string
(
expect
.
colNewName
));
}
if
(
nullptr
!=
expect
.
tagName
)
{
ASSERT_EQ
(
std
::
string
(
req
.
tagName
),
std
::
string
(
expect
.
tagName
));
}
ASSERT_EQ
(
req
.
isNull
,
expect
.
isNull
);
ASSERT_EQ
(
req
.
nTagVal
,
expect
.
nTagVal
);
ASSERT_EQ
(
memcmp
(
req
.
pTagVal
,
expect
.
pTagVal
,
expect
.
nTagVal
),
0
);
ASSERT_EQ
(
req
.
updateTTL
,
expect
.
updateTTL
);
ASSERT_EQ
(
req
.
newTTL
,
expect
.
newTTL
);
if
(
nullptr
!=
expect
.
newComment
)
{
ASSERT_EQ
(
std
::
string
(
req
.
newComment
),
std
::
string
(
expect
.
newComment
));
ASSERT_EQ
(
req
.
newCommentLen
,
strlen
(
req
.
newComment
));
ASSERT_EQ
(
expect
.
newCommentLen
,
strlen
(
expect
.
newComment
));
}
tDecoderClear
(
&
coder
);
});
setAlterTableOptions
(
"t1"
,
10
,
nullptr
);
run
(
"ALTER TABLE t1 TTL 10"
);
clearAlterTbReq
();
setAlterTableOptions
(
"t1"
,
-
1
,
(
char
*
)
"test"
);
run
(
"ALTER TABLE t1 COMMENT 'test'"
);
clearAlterTbReq
();
setAlterTableCol
(
"t1"
,
TSDB_ALTER_TABLE_ADD_COLUMN
,
"cc1"
,
TSDB_DATA_TYPE_BIGINT
);
run
(
"ALTER TABLE t1 ADD COLUMN cc1 BIGINT"
);
clearAlterTbReq
();
setAlterTableCol
(
"t1"
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
"c1"
);
run
(
"ALTER TABLE t1 DROP COLUMN c1"
);
clearAlterTbReq
();
setAlterTableCol
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
,
"c2"
,
TSDB_DATA_TYPE_VARCHAR
,
30
+
VARSTR_HEADER_SIZE
);
run
(
"ALTER TABLE t1 MODIFY COLUMN c2 VARCHAR(30)"
);
clearAlterTbReq
();
setAlterTableCol
(
"t1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
,
"c1"
,
0
,
0
,
"cc1"
);
run
(
"ALTER TABLE t1 RENAME COLUMN c1 cc1"
);
clearAlterTbReq
();
int32_t
val
=
10
;
setAlterTableTag
(
"st1s1"
,
"tag1"
,
(
uint8_t
*
)
&
val
,
sizeof
(
val
));
run
(
"ALTER TABLE st1s1 SET TAG tag1=10"
);
clearAlterTbReq
();
}
// super table
{
SMAlterStbReq
expect
=
{
0
};
auto
clearAlterStbReq
=
[
&
]()
{
tFreeSMAltertbReq
(
&
expect
);
memset
(
&
expect
,
0
,
sizeof
(
SMAlterStbReq
));
};
auto
setAlterStbReq
=
[
&
](
const
char
*
pTbname
,
int8_t
alterType
,
int32_t
numOfFields
=
0
,
const
char
*
pField1Name
=
nullptr
,
int8_t
field1Type
=
0
,
int32_t
field1Bytes
=
0
,
const
char
*
pField2Name
=
nullptr
,
const
char
*
pComment
=
nullptr
)
{
int32_t
len
=
snprintf
(
expect
.
name
,
sizeof
(
expect
.
name
),
"0.test.%s"
,
pTbname
);
expect
.
name
[
len
]
=
'\0'
;
expect
.
alterType
=
alterType
;
if
(
nullptr
!=
pComment
)
{
expect
.
comment
=
strdup
(
pComment
);
expect
.
commentLen
=
strlen
(
pComment
);
}
expect
.
numOfFields
=
numOfFields
;
if
(
NULL
==
expect
.
pFields
)
{
expect
.
pFields
=
taosArrayInit
(
2
,
sizeof
(
TAOS_FIELD
));
TAOS_FIELD
field
=
{
0
};
taosArrayPush
(
expect
.
pFields
,
&
field
);
taosArrayPush
(
expect
.
pFields
,
&
field
);
}
TAOS_FIELD
*
pField
=
(
TAOS_FIELD
*
)
taosArrayGet
(
expect
.
pFields
,
0
);
if
(
NULL
!=
pField1Name
)
{
strcpy
(
pField
->
name
,
pField1Name
);
pField
->
name
[
strlen
(
pField1Name
)]
=
'\0'
;
}
else
{
memset
(
pField
,
0
,
sizeof
(
TAOS_FIELD
));
}
pField
->
type
=
field1Type
;
pField
->
bytes
=
field1Bytes
>
0
?
field1Bytes
:
(
field1Type
>
0
?
tDataTypes
[
field1Type
].
bytes
:
0
);
pField
=
(
TAOS_FIELD
*
)
taosArrayGet
(
expect
.
pFields
,
1
);
if
(
NULL
!=
pField2Name
)
{
strcpy
(
pField
->
name
,
pField2Name
);
pField
->
name
[
strlen
(
pField2Name
)]
=
'\0'
;
}
else
{
memset
(
pField
,
0
,
sizeof
(
TAOS_FIELD
));
}
pField
->
type
=
0
;
pField
->
bytes
=
0
;
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_ALTER_TABLE_STMT
);
ASSERT_EQ
(
pQuery
->
pCmdMsg
->
msgType
,
TDMT_MND_ALTER_STB
);
SMAlterStbReq
req
=
{
0
};
ASSERT_EQ
(
tDeserializeSMAlterStbReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
std
::
string
(
req
.
name
),
std
::
string
(
expect
.
name
));
ASSERT_EQ
(
req
.
alterType
,
expect
.
alterType
);
ASSERT_EQ
(
req
.
numOfFields
,
expect
.
numOfFields
);
if
(
expect
.
numOfFields
>
0
)
{
TAOS_FIELD
*
pField
=
(
TAOS_FIELD
*
)
taosArrayGet
(
req
.
pFields
,
0
);
TAOS_FIELD
*
pExpectField
=
(
TAOS_FIELD
*
)
taosArrayGet
(
expect
.
pFields
,
0
);
ASSERT_EQ
(
std
::
string
(
pField
->
name
),
std
::
string
(
pExpectField
->
name
));
ASSERT_EQ
(
pField
->
type
,
pExpectField
->
type
);
ASSERT_EQ
(
pField
->
bytes
,
pExpectField
->
bytes
);
}
if
(
expect
.
numOfFields
>
1
)
{
TAOS_FIELD
*
pField
=
(
TAOS_FIELD
*
)
taosArrayGet
(
req
.
pFields
,
1
);
TAOS_FIELD
*
pExpectField
=
(
TAOS_FIELD
*
)
taosArrayGet
(
expect
.
pFields
,
1
);
ASSERT_EQ
(
std
::
string
(
pField
->
name
),
std
::
string
(
pExpectField
->
name
));
ASSERT_EQ
(
pField
->
type
,
pExpectField
->
type
);
ASSERT_EQ
(
pField
->
bytes
,
pExpectField
->
bytes
);
}
tFreeSMAltertbReq
(
&
req
);
});
setAlterStbReq
(
"st1"
,
TSDB_ALTER_TABLE_ADD_TAG
,
1
,
"tag11"
,
TSDB_DATA_TYPE_BIGINT
);
run
(
"ALTER TABLE st1 ADD TAG tag11 BIGINT"
);
clearAlterStbReq
();
setAlterStbReq
(
"st1"
,
TSDB_ALTER_TABLE_DROP_TAG
,
1
,
"tag1"
);
run
(
"ALTER TABLE st1 DROP TAG tag1"
);
clearAlterStbReq
();
setAlterStbReq
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES
,
1
,
"tag2"
,
TSDB_DATA_TYPE_VARCHAR
,
30
+
VARSTR_HEADER_SIZE
);
run
(
"ALTER TABLE st1 MODIFY TAG tag2 VARCHAR(30)"
);
clearAlterStbReq
();
setAlterStbReq
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_TAG_NAME
,
2
,
"tag1"
,
0
,
0
,
"tag11"
);
run
(
"ALTER TABLE st1 RENAME TAG tag1 tag11"
);
clearAlterStbReq
();
}
}
TEST_F
(
ParserInitialATest
,
alterTableSemanticCheck
)
{
...
...
@@ -588,7 +746,7 @@ TEST_F(ParserInitialATest, alterTableSemanticCheck) {
}
/*
* ALTER USER user_name
PASS str_valu
e
* ALTER USER user_name
alter_user_claus
e
*
* alter_user_clause: {
* PASS str_value
...
...
@@ -618,6 +776,7 @@ TEST_F(ParserInitialATest, alterUser) {
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_ALTER_USER_STMT
);
ASSERT_EQ
(
pQuery
->
pCmdMsg
->
msgType
,
TDMT_MND_ALTER_USER
);
SAlterUserReq
req
=
{
0
};
ASSERT_TRUE
(
TSDB_CODE_SUCCESS
==
tDeserializeSAlterUserReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
));
...
...
source/libs/parser/test/parExplainToSyncdbTest.cpp
浏览文件 @
30065f30
...
...
@@ -52,8 +52,8 @@ TEST_F(ParserExplainToSyncdbTest, grant) {
ASSERT_EQ
(
string
(
req
.
objname
),
string
(
expect
.
objname
));
});
setAlterUserReq
(
TSDB_ALTER_USER_ADD_ALL_DB
,
"wxy"
,
"0.
test
"
);
run
(
"GRANT ALL ON
test
.* TO wxy"
);
setAlterUserReq
(
TSDB_ALTER_USER_ADD_ALL_DB
,
"wxy"
,
"0.
*
"
);
run
(
"GRANT ALL ON
*
.* TO wxy"
);
setAlterUserReq
(
TSDB_ALTER_USER_ADD_READ_DB
,
"wxy"
,
"0.test"
);
run
(
"GRANT READ ON test.* TO wxy"
);
...
...
@@ -138,10 +138,38 @@ TEST_F(ParserExplainToSyncdbTest, redistributeVgroup) {
TEST_F
(
ParserExplainToSyncdbTest
,
revoke
)
{
useDb
(
"root"
,
"test"
);
run
(
"REVOKE ALL ON test.* FROM wxy"
);
SAlterUserReq
expect
=
{
0
};
auto
setAlterUserReq
=
[
&
](
int8_t
alterType
,
const
string
&
user
,
const
string
&
obj
)
{
expect
.
alterType
=
alterType
;
snprintf
(
expect
.
user
,
sizeof
(
expect
.
user
),
"%s"
,
user
.
c_str
());
snprintf
(
expect
.
objname
,
sizeof
(
expect
.
objname
),
"%s"
,
obj
.
c_str
());
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_REVOKE_STMT
);
ASSERT_EQ
(
pQuery
->
pCmdMsg
->
msgType
,
TDMT_MND_ALTER_USER
);
SAlterUserReq
req
=
{
0
};
ASSERT_EQ
(
tDeserializeSAlterUserReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
req
.
alterType
,
expect
.
alterType
);
ASSERT_EQ
(
string
(
req
.
user
),
string
(
expect
.
user
));
ASSERT_EQ
(
string
(
req
.
objname
),
string
(
expect
.
objname
));
});
setAlterUserReq
(
TSDB_ALTER_USER_REMOVE_ALL_DB
,
"wxy"
,
"0.*"
);
run
(
"REVOKE ALL ON *.* FROM wxy"
);
setAlterUserReq
(
TSDB_ALTER_USER_REMOVE_READ_DB
,
"wxy"
,
"0.test"
);
run
(
"REVOKE READ ON test.* FROM wxy"
);
setAlterUserReq
(
TSDB_ALTER_USER_REMOVE_WRITE_DB
,
"wxy"
,
"0.test"
);
run
(
"REVOKE WRITE ON test.* FROM wxy"
);
setAlterUserReq
(
TSDB_ALTER_USER_REMOVE_ALL_DB
,
"wxy"
,
"0.test"
);
run
(
"REVOKE READ, WRITE ON test.* FROM wxy"
);
setAlterUserReq
(
TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC
,
"wxy"
,
"0.tp1"
);
run
(
"REVOKE SUBSCRIBE ON tp1 FROM wxy"
);
}
// todo syncdb
...
...
source/libs/parser/test/parInitialCTest.cpp
浏览文件 @
30065f30
...
...
@@ -21,12 +21,35 @@ namespace ParserTest {
class
ParserInitialCTest
:
public
ParserDdlTest
{};
/*
* CREATE ACCOUNT account_name PASS value [create_account_options]
*
* create_account_options:
* create_account_option ...
*
* create_account_option: {
* PPS value
* | TSERIES value
* | STORAGE value
* | STREAMS value
* | QTIME value
* | DBS value
* | USERS value
* | CONNS value
* | STATE value
* }
*/
TEST_F
(
ParserInitialCTest
,
createAccount
)
{
useDb
(
"root"
,
"test"
);
run
(
"CREATE ACCOUNT ac_wxy PASS '123456'"
,
TSDB_CODE_PAR_EXPRIE_STATEMENT
,
PARSER_STAGE_PARSE
);
}
/*
* CREATE BNODE ON DNODE dnode_id
* the server does not support it temporarily
*/
/*
* CREATE DATABASE [IF NOT EXISTS] db_name [database_options]
*
...
...
@@ -68,7 +91,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
memset
(
&
expect
,
0
,
sizeof
(
SCreateDbReq
));
};
auto
setCreateDbReq
Func
=
[
&
](
const
char
*
pDbname
,
int8_t
igExists
=
0
)
{
auto
setCreateDbReq
=
[
&
](
const
char
*
pDbname
,
int8_t
igExists
=
0
)
{
int32_t
len
=
snprintf
(
expect
.
db
,
sizeof
(
expect
.
db
),
"0.%s"
,
pDbname
);
expect
.
db
[
len
]
=
'\0'
;
expect
.
ignoreExist
=
igExists
;
...
...
@@ -102,28 +125,28 @@ TEST_F(ParserInitialCTest, createDatabase) {
expect
.
tsdbPageSize
=
TSDB_DEFAULT_TSDB_PAGESIZE
;
};
auto
setDbBuffer
Func
=
[
&
](
int32_t
buffer
)
{
expect
.
buffer
=
buffer
;
};
auto
setDbCachelast
Func
=
[
&
](
int8_t
cachelast
)
{
expect
.
cacheLast
=
cachelast
;
};
auto
setDbBuffer
=
[
&
](
int32_t
buffer
)
{
expect
.
buffer
=
buffer
;
};
auto
setDbCachelast
=
[
&
](
int8_t
cachelast
)
{
expect
.
cacheLast
=
cachelast
;
};
auto
setDbCachelastSize
=
[
&
](
int8_t
cachelastSize
)
{
expect
.
cacheLastSize
=
cachelastSize
;
};
auto
setDbCompression
Func
=
[
&
](
int8_t
compressionLevel
)
{
expect
.
compression
=
compressionLevel
;
};
auto
setDbDays
Func
=
[
&
](
int32_t
daysPerFile
)
{
expect
.
daysPerFile
=
daysPerFile
;
};
auto
setDbFsync
Func
=
[
&
](
int32_t
fsyncPeriod
)
{
expect
.
walFsyncPeriod
=
fsyncPeriod
;
};
auto
setDbMaxRows
Func
=
[
&
](
int32_t
maxRowsPerBlock
)
{
expect
.
maxRows
=
maxRowsPerBlock
;
};
auto
setDbMinRows
Func
=
[
&
](
int32_t
minRowsPerBlock
)
{
expect
.
minRows
=
minRowsPerBlock
;
};
auto
setDbKeep
Func
=
[
&
](
int32_t
keep0
,
int32_t
keep1
=
0
,
int32_t
keep2
=
0
)
{
auto
setDbCompression
=
[
&
](
int8_t
compressionLevel
)
{
expect
.
compression
=
compressionLevel
;
};
auto
setDbDays
=
[
&
](
int32_t
daysPerFile
)
{
expect
.
daysPerFile
=
daysPerFile
;
};
auto
setDbFsync
=
[
&
](
int32_t
fsyncPeriod
)
{
expect
.
walFsyncPeriod
=
fsyncPeriod
;
};
auto
setDbMaxRows
=
[
&
](
int32_t
maxRowsPerBlock
)
{
expect
.
maxRows
=
maxRowsPerBlock
;
};
auto
setDbMinRows
=
[
&
](
int32_t
minRowsPerBlock
)
{
expect
.
minRows
=
minRowsPerBlock
;
};
auto
setDbKeep
=
[
&
](
int32_t
keep0
,
int32_t
keep1
=
0
,
int32_t
keep2
=
0
)
{
expect
.
daysToKeep0
=
keep0
;
expect
.
daysToKeep1
=
0
==
keep1
?
expect
.
daysToKeep0
:
keep1
;
expect
.
daysToKeep2
=
0
==
keep2
?
expect
.
daysToKeep1
:
keep2
;
};
auto
setDbPages
Func
=
[
&
](
int32_t
pages
)
{
expect
.
pages
=
pages
;
};
auto
setDbPageSize
Func
=
[
&
](
int32_t
pagesize
)
{
expect
.
pageSize
=
pagesize
;
};
auto
setDbPrecision
Func
=
[
&
](
int8_t
precision
)
{
expect
.
precision
=
precision
;
};
auto
setDbReplica
Func
=
[
&
](
int8_t
replica
)
{
expect
.
replications
=
replica
;
};
auto
setDbStricta
Func
=
[
&
](
int8_t
strict
)
{
expect
.
strict
=
strict
;
};
auto
setDbWalLevel
Func
=
[
&
](
int8_t
walLevel
)
{
expect
.
walLevel
=
walLevel
;
};
auto
setDbVgroups
Func
=
[
&
](
int32_t
numOfVgroups
)
{
expect
.
numOfVgroups
=
numOfVgroups
;
};
auto
setDbSingleStable
Func
=
[
&
](
int8_t
singleStable
)
{
expect
.
numOfStables
=
singleStable
;
};
auto
addDbRetention
Func
=
[
&
](
int64_t
freq
,
int64_t
keep
,
int8_t
freqUnit
,
int8_t
keepUnit
)
{
auto
setDbPages
=
[
&
](
int32_t
pages
)
{
expect
.
pages
=
pages
;
};
auto
setDbPageSize
=
[
&
](
int32_t
pagesize
)
{
expect
.
pageSize
=
pagesize
;
};
auto
setDbPrecision
=
[
&
](
int8_t
precision
)
{
expect
.
precision
=
precision
;
};
auto
setDbReplica
=
[
&
](
int8_t
replica
)
{
expect
.
replications
=
replica
;
};
auto
setDbStricta
=
[
&
](
int8_t
strict
)
{
expect
.
strict
=
strict
;
};
auto
setDbWalLevel
=
[
&
](
int8_t
walLevel
)
{
expect
.
walLevel
=
walLevel
;
};
auto
setDbVgroups
=
[
&
](
int32_t
numOfVgroups
)
{
expect
.
numOfVgroups
=
numOfVgroups
;
};
auto
setDbSingleStable
=
[
&
](
int8_t
singleStable
)
{
expect
.
numOfStables
=
singleStable
;
};
auto
addDbRetention
=
[
&
](
int64_t
freq
,
int64_t
keep
,
int8_t
freqUnit
,
int8_t
keepUnit
)
{
SRetention
retention
=
{
0
};
retention
.
freq
=
freq
;
retention
.
keep
=
keep
;
...
...
@@ -135,7 +158,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
taosArrayPush
(
expect
.
pRetensions
,
&
retention
);
++
expect
.
numOfRetensions
;
};
auto
setDbSchemaless
Func
=
[
&
](
int8_t
schemaless
)
{
expect
.
schemaless
=
schemaless
;
};
auto
setDbSchemaless
=
[
&
](
int8_t
schemaless
)
{
expect
.
schemaless
=
schemaless
;
};
auto
setDbWalRetentionPeriod
=
[
&
](
int32_t
walRetentionPeriod
)
{
expect
.
walRetentionPeriod
=
walRetentionPeriod
;
};
auto
setDbWalRetentionSize
=
[
&
](
int32_t
walRetentionSize
)
{
expect
.
walRetentionSize
=
walRetentionSize
;
};
auto
setDbWalRollPeriod
=
[
&
](
int32_t
walRollPeriod
)
{
expect
.
walRollPeriod
=
walRollPeriod
;
};
...
...
@@ -147,6 +170,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_CREATE_DATABASE_STMT
);
ASSERT_EQ
(
pQuery
->
pCmdMsg
->
msgType
,
TDMT_MND_CREATE_DB
);
SCreateDbReq
req
=
{
0
};
ASSERT_TRUE
(
TSDB_CODE_SUCCESS
==
tDeserializeSCreateDbReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
));
...
...
@@ -195,32 +219,32 @@ TEST_F(ParserInitialCTest, createDatabase) {
tFreeSCreateDbReq
(
&
req
);
});
setCreateDbReq
Func
(
"wxy_db"
);
setCreateDbReq
(
"wxy_db"
);
run
(
"CREATE DATABASE wxy_db"
);
clearCreateDbReq
();
setCreateDbReq
Func
(
"wxy_db"
,
1
);
setDbBuffer
Func
(
64
);
setDbCachelast
Func
(
2
);
setCreateDbReq
(
"wxy_db"
,
1
);
setDbBuffer
(
64
);
setDbCachelast
(
2
);
setDbCachelastSize
(
20
);
setDbCompression
Func
(
1
);
setDbDays
Func
(
100
*
1440
);
setDbFsync
Func
(
100
);
setDbMaxRows
Func
(
1000
);
setDbMinRows
Func
(
100
);
setDbKeep
Func
(
1440
*
1440
);
setDbPages
Func
(
96
);
setDbPageSize
Func
(
8
);
setDbPrecision
Func
(
TSDB_TIME_PRECISION_NANO
);
setDbReplica
Func
(
3
);
addDbRetention
Func
(
15
*
MILLISECOND_PER_SECOND
,
7
*
MILLISECOND_PER_DAY
,
TIME_UNIT_SECOND
,
TIME_UNIT_DAY
);
addDbRetention
Func
(
1
*
MILLISECOND_PER_MINUTE
,
21
*
MILLISECOND_PER_DAY
,
TIME_UNIT_MINUTE
,
TIME_UNIT_DAY
);
addDbRetention
Func
(
15
*
MILLISECOND_PER_MINUTE
,
500
*
MILLISECOND_PER_DAY
,
TIME_UNIT_MINUTE
,
TIME_UNIT_DAY
);
// setDbStricta
Func
(1);
setDbWalLevel
Func
(
2
);
setDbVgroups
Func
(
100
);
setDbSingleStable
Func
(
1
);
setDbSchemaless
Func
(
1
);
setDbCompression
(
1
);
setDbDays
(
100
*
1440
);
setDbFsync
(
100
);
setDbMaxRows
(
1000
);
setDbMinRows
(
100
);
setDbKeep
(
1440
*
1440
);
setDbPages
(
96
);
setDbPageSize
(
8
);
setDbPrecision
(
TSDB_TIME_PRECISION_NANO
);
setDbReplica
(
3
);
addDbRetention
(
15
*
MILLISECOND_PER_SECOND
,
7
*
MILLISECOND_PER_DAY
,
TIME_UNIT_SECOND
,
TIME_UNIT_DAY
);
addDbRetention
(
1
*
MILLISECOND_PER_MINUTE
,
21
*
MILLISECOND_PER_DAY
,
TIME_UNIT_MINUTE
,
TIME_UNIT_DAY
);
addDbRetention
(
15
*
MILLISECOND_PER_MINUTE
,
500
*
MILLISECOND_PER_DAY
,
TIME_UNIT_MINUTE
,
TIME_UNIT_DAY
);
// setDbStricta(1);
setDbWalLevel
(
2
);
setDbVgroups
(
100
);
setDbSingleStable
(
1
);
setDbSchemaless
(
1
);
setDbWalRetentionPeriod
(
-
1
);
setDbWalRetentionSize
(
-
1
);
setDbWalRollPeriod
(
10
);
...
...
@@ -259,16 +283,16 @@ TEST_F(ParserInitialCTest, createDatabase) {
"TSDB_PAGESIZE 32"
);
clearCreateDbReq
();
setCreateDbReq
Func
(
"wxy_db"
,
1
);
setDbDays
Func
(
100
);
setDbKeep
Func
(
1440
,
300
*
60
,
400
*
1440
);
setCreateDbReq
(
"wxy_db"
,
1
);
setDbDays
(
100
);
setDbKeep
(
1440
,
300
*
60
,
400
*
1440
);
run
(
"CREATE DATABASE IF NOT EXISTS wxy_db "
"DURATION 100m "
"KEEP 1440m,300h,400d "
);
clearCreateDbReq
();
setCreateDbReq
Func
(
"wxy_db"
,
1
);
setDbReplica
Func
(
3
);
setCreateDbReq
(
"wxy_db"
,
1
);
setDbReplica
(
3
);
setDbWalRetentionPeriod
(
TSDB_REPS_DEF_DB_WAL_RET_PERIOD
);
setDbWalRetentionSize
(
TSDB_REPS_DEF_DB_WAL_RET_SIZE
);
setDbWalRollPeriod
(
TSDB_REPS_DEF_DB_WAL_ROLL_PERIOD
);
...
...
@@ -287,6 +311,9 @@ TEST_F(ParserInitialCTest, createDatabaseSemanticCheck) {
run
(
"create database db2 retentions 15s:7d,5m:21d,10m:10d"
,
TSDB_CODE_PAR_INVALID_DB_OPTION
);
}
/*
* CREATE DNODE {dnode_endpoint | dnode_host_name PORT port_val}
*/
TEST_F
(
ParserInitialCTest
,
createDnode
)
{
useDb
(
"root"
,
"test"
);
...
...
@@ -294,7 +321,7 @@ TEST_F(ParserInitialCTest, createDnode) {
auto
clearCreateDnodeReq
=
[
&
]()
{
memset
(
&
expect
,
0
,
sizeof
(
SCreateDnodeReq
));
};
auto
setCreateDnodeReq
Func
=
[
&
](
const
char
*
pFqdn
,
int32_t
port
=
tsServerPort
)
{
auto
setCreateDnodeReq
=
[
&
](
const
char
*
pFqdn
,
int32_t
port
=
tsServerPort
)
{
strcpy
(
expect
.
fqdn
,
pFqdn
);
expect
.
port
=
port
;
};
...
...
@@ -308,39 +335,41 @@ TEST_F(ParserInitialCTest, createDnode) {
ASSERT_EQ
(
req
.
port
,
expect
.
port
);
});
setCreateDnodeReq
Func
(
"abc1"
,
7030
);
setCreateDnodeReq
(
"abc1"
,
7030
);
run
(
"CREATE DNODE 'abc1' PORT 7030"
);
clearCreateDnodeReq
();
setCreateDnodeReq
Func
(
"1.1.1.1"
,
8030
);
setCreateDnodeReq
(
"1.1.1.1"
,
8030
);
run
(
"CREATE DNODE 1.1.1.1 PORT 8030"
);
clearCreateDnodeReq
();
setCreateDnodeReq
Func
(
"host1"
,
9030
);
setCreateDnodeReq
(
"host1"
,
9030
);
run
(
"CREATE DNODE host1 PORT 9030"
);
clearCreateDnodeReq
();
setCreateDnodeReq
Func
(
"abc2"
,
7040
);
setCreateDnodeReq
(
"abc2"
,
7040
);
run
(
"CREATE DNODE 'abc2:7040'"
);
clearCreateDnodeReq
();
setCreateDnodeReq
Func
(
"1.1.1.2"
);
setCreateDnodeReq
(
"1.1.1.2"
);
run
(
"CREATE DNODE 1.1.1.2"
);
clearCreateDnodeReq
();
setCreateDnodeReq
Func
(
"host2"
);
setCreateDnodeReq
(
"host2"
);
run
(
"CREATE DNODE host2"
);
clearCreateDnodeReq
();
}
// CREATE [AGGREGATE] FUNCTION [IF NOT EXISTS] func_name AS library_path OUTPUTTYPE type_name [BUFSIZE value]
/*
* CREATE [AGGREGATE] FUNCTION [IF NOT EXISTS] func_name AS library_path OUTPUTTYPE type_name [BUFSIZE value]
*/
TEST_F
(
ParserInitialCTest
,
createFunction
)
{
useDb
(
"root"
,
"test"
);
SCreateFuncReq
expect
=
{
0
};
auto
setCreateFuncReq
Func
=
[
&
](
const
char
*
pUdfName
,
int8_t
outputType
,
int32_t
outputBytes
=
0
,
int8_t
funcType
=
TSDB_FUNC_TYPE_SCALAR
,
int8_t
igExists
=
0
,
int32_t
bufSize
=
0
)
{
auto
setCreateFuncReq
=
[
&
](
const
char
*
pUdfName
,
int8_t
outputType
,
int32_t
outputBytes
=
0
,
int8_t
funcType
=
TSDB_FUNC_TYPE_SCALAR
,
int8_t
igExists
=
0
,
int32_t
bufSize
=
0
)
{
memset
(
&
expect
,
0
,
sizeof
(
SCreateFuncReq
));
strcpy
(
expect
.
name
,
pUdfName
);
expect
.
igExists
=
igExists
;
...
...
@@ -365,13 +394,69 @@ TEST_F(ParserInitialCTest, createFunction) {
ASSERT_EQ
(
req
.
bufSize
,
expect
.
bufSize
);
});
setCreateFuncReq
Func
(
"udf1"
,
TSDB_DATA_TYPE_INT
);
setCreateFuncReq
(
"udf1"
,
TSDB_DATA_TYPE_INT
);
// run("CREATE FUNCTION udf1 AS './build/lib/libudf1.so' OUTPUTTYPE INT");
setCreateFuncReq
Func
(
"udf2"
,
TSDB_DATA_TYPE_DOUBLE
,
0
,
TSDB_FUNC_TYPE_AGGREGATE
,
1
,
8
);
setCreateFuncReq
(
"udf2"
,
TSDB_DATA_TYPE_DOUBLE
,
0
,
TSDB_FUNC_TYPE_AGGREGATE
,
1
,
8
);
// run("CREATE AGGREGATE FUNCTION IF NOT EXISTS udf2 AS './build/lib/libudf2.so' OUTPUTTYPE DOUBLE BUFSIZE 8");
}
/*
* CREATE MNODE ON DNODE dnode_id
*/
TEST_F
(
ParserInitialCTest
,
createMnode
)
{
useDb
(
"root"
,
"test"
);
SMCreateMnodeReq
expect
=
{
0
};
auto
setCreateMnodeReq
=
[
&
](
int32_t
dnodeId
)
{
expect
.
dnodeId
=
dnodeId
;
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_CREATE_MNODE_STMT
);
SMCreateMnodeReq
req
=
{
0
};
ASSERT_TRUE
(
TSDB_CODE_SUCCESS
==
tDeserializeSCreateDropMQSNodeReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
));
ASSERT_EQ
(
req
.
dnodeId
,
expect
.
dnodeId
);
});
setCreateMnodeReq
(
1
);
run
(
"CREATE MNODE ON DNODE 1"
);
}
/*
* CREATE QNODE ON DNODE dnode_id
*/
TEST_F
(
ParserInitialCTest
,
createQnode
)
{
useDb
(
"root"
,
"test"
);
SMCreateQnodeReq
expect
=
{
0
};
auto
setCreateQnodeReq
=
[
&
](
int32_t
dnodeId
)
{
expect
.
dnodeId
=
dnodeId
;
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_CREATE_QNODE_STMT
);
SMCreateQnodeReq
req
=
{
0
};
ASSERT_TRUE
(
TSDB_CODE_SUCCESS
==
tDeserializeSCreateDropMQSNodeReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
));
ASSERT_EQ
(
req
.
dnodeId
,
expect
.
dnodeId
);
});
setCreateQnodeReq
(
1
);
run
(
"CREATE QNODE ON DNODE 1"
);
}
/*
* CREATE SMA INDEX index_name ON tb_name index_option
*
* index_option:
* FUNCTION(functions) INTERVAL(interval_val [, interval_offset]) [SLIDING(sliding_val)]
* [WATERMARK(watermark_val)] [MAX_DELAY(max_delay_val)]
*
* functions:
* function [, function] ...
*/
TEST_F
(
ParserInitialCTest
,
createSmaIndex
)
{
useDb
(
"root"
,
"test"
);
...
...
@@ -439,24 +524,39 @@ TEST_F(ParserInitialCTest, createSmaIndex) {
"DELETE_MARK 1000s"
);
}
TEST_F
(
ParserInitialCTest
,
createMnode
)
{
/*
* CREATE SNODE ON DNODE dnode_id
*/
TEST_F
(
ParserInitialCTest
,
createSnode
)
{
useDb
(
"root"
,
"test"
);
run
(
"CREATE MNODE ON DNODE 1"
);
}
SMCreateSnodeReq
expect
=
{
0
};
TEST_F
(
ParserInitialCTest
,
createQnode
)
{
useDb
(
"root"
,
"test"
);
auto
setCreateSnodeReq
=
[
&
](
int32_t
dnodeId
)
{
expect
.
dnodeId
=
dnodeId
;
};
run
(
"CREATE QNODE ON DNODE 1"
);
}
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_CREATE_SNODE_STMT
);
SMCreateSnodeReq
req
=
{
0
};
ASSERT_TRUE
(
TSDB_CODE_SUCCESS
==
tDeserializeSCreateDropMQSNodeReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
));
TEST_F
(
ParserInitialCTest
,
createSnode
)
{
useDb
(
"root"
,
"test"
);
ASSERT_EQ
(
req
.
dnodeId
,
expect
.
dnodeId
);
}
);
setCreateSnodeReq
(
1
);
run
(
"CREATE SNODE ON DNODE 1"
);
}
/*
* CREATE STABLE [IF NOT EXISTS] stb_name (create_definition [, create_definitionn] ...)
* TAGS (create_definition [, create_definition] ...) [table_options]
*
* create_definition:
* col_name column_definition
*
* column_definition:
* type_name [COMMENT 'string_value']
*/
TEST_F
(
ParserInitialCTest
,
createStable
)
{
useDb
(
"root"
,
"test"
);
...
...
@@ -467,7 +567,7 @@ TEST_F(ParserInitialCTest, createStable) {
memset
(
&
expect
,
0
,
sizeof
(
SMCreateStbReq
));
};
auto
setCreateStbReq
Func
=
auto
setCreateStbReq
=
[
&
](
const
char
*
pDbName
,
const
char
*
pTbName
,
int8_t
igExists
=
0
,
int64_t
delay1
=
-
1
,
int64_t
delay2
=
-
1
,
int64_t
watermark1
=
TSDB_DEFAULT_ROLLUP_WATERMARK
,
int64_t
watermark2
=
TSDB_DEFAULT_ROLLUP_WATERMARK
,
int64_t
deleteMark1
=
TSDB_DEFAULT_ROLLUP_DELETE_MARK
,
int64_t
deleteMark2
=
TSDB_DEFAULT_ROLLUP_DELETE_MARK
,
...
...
@@ -488,8 +588,8 @@ TEST_F(ParserInitialCTest, createStable) {
}
};
auto
addFieldToCreateStbReq
Func
=
[
&
](
bool
col
,
const
char
*
pFieldName
,
uint8_t
type
,
int32_t
bytes
=
0
,
int8_t
flags
=
COL_SMA_ON
)
{
auto
addFieldToCreateStbReq
=
[
&
](
bool
col
,
const
char
*
pFieldName
,
uint8_t
type
,
int32_t
bytes
=
0
,
int8_t
flags
=
COL_SMA_ON
)
{
SField
field
=
{
0
};
strcpy
(
field
.
name
,
pFieldName
);
field
.
type
=
type
;
...
...
@@ -565,46 +665,46 @@ TEST_F(ParserInitialCTest, createStable) {
tFreeSMCreateStbReq
(
&
req
);
});
setCreateStbReq
Func
(
"test"
,
"t1"
);
addFieldToCreateStbReq
Func
(
true
,
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
);
addFieldToCreateStbReq
Func
(
true
,
"c1"
,
TSDB_DATA_TYPE_INT
);
addFieldToCreateStbReq
Func
(
false
,
"id"
,
TSDB_DATA_TYPE_INT
);
setCreateStbReq
(
"test"
,
"t1"
);
addFieldToCreateStbReq
(
true
,
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
);
addFieldToCreateStbReq
(
true
,
"c1"
,
TSDB_DATA_TYPE_INT
);
addFieldToCreateStbReq
(
false
,
"id"
,
TSDB_DATA_TYPE_INT
);
run
(
"CREATE STABLE t1(ts TIMESTAMP, c1 INT) TAGS(id INT)"
);
clearCreateStbReq
();
setCreateStbReq
Func
(
"rollup_db"
,
"t1"
,
1
,
100
*
MILLISECOND_PER_SECOND
,
10
*
MILLISECOND_PER_MINUTE
,
10
,
1
*
MILLISECOND_PER_MINUTE
,
1000
*
MILLISECOND_PER_SECOND
,
200
*
MILLISECOND_PER_MINUTE
,
100
,
"test create table"
);
addFieldToCreateStbReq
Func
(
true
,
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
,
0
,
0
);
addFieldToCreateStbReq
Func
(
true
,
"c1"
,
TSDB_DATA_TYPE_INT
);
addFieldToCreateStbReq
Func
(
true
,
"c2"
,
TSDB_DATA_TYPE_UINT
);
addFieldToCreateStbReq
Func
(
true
,
"c3"
,
TSDB_DATA_TYPE_BIGINT
);
addFieldToCreateStbReq
Func
(
true
,
"c4"
,
TSDB_DATA_TYPE_UBIGINT
,
0
,
0
);
addFieldToCreateStbReq
Func
(
true
,
"c5"
,
TSDB_DATA_TYPE_FLOAT
,
0
,
0
);
addFieldToCreateStbReq
Func
(
true
,
"c6"
,
TSDB_DATA_TYPE_DOUBLE
,
0
,
0
);
addFieldToCreateStbReq
Func
(
true
,
"c7"
,
TSDB_DATA_TYPE_BINARY
,
20
+
VARSTR_HEADER_SIZE
,
0
);
addFieldToCreateStbReq
Func
(
true
,
"c8"
,
TSDB_DATA_TYPE_SMALLINT
,
0
,
0
);
addFieldToCreateStbReq
Func
(
true
,
"c9"
,
TSDB_DATA_TYPE_USMALLINT
,
0
,
0
);
addFieldToCreateStbReq
Func
(
true
,
"c10"
,
TSDB_DATA_TYPE_TINYINT
,
0
,
0
);
addFieldToCreateStbReq
Func
(
true
,
"c11"
,
TSDB_DATA_TYPE_UTINYINT
,
0
,
0
);
addFieldToCreateStbReq
Func
(
true
,
"c12"
,
TSDB_DATA_TYPE_BOOL
,
0
,
0
);
addFieldToCreateStbReq
Func
(
true
,
"c13"
,
TSDB_DATA_TYPE_NCHAR
,
30
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
,
0
);
addFieldToCreateStbReq
Func
(
true
,
"c14"
,
TSDB_DATA_TYPE_VARCHAR
,
50
+
VARSTR_HEADER_SIZE
,
0
);
addFieldToCreateStbReq
Func
(
false
,
"a1"
,
TSDB_DATA_TYPE_TIMESTAMP
);
addFieldToCreateStbReq
Func
(
false
,
"a2"
,
TSDB_DATA_TYPE_INT
);
addFieldToCreateStbReq
Func
(
false
,
"a3"
,
TSDB_DATA_TYPE_UINT
);
addFieldToCreateStbReq
Func
(
false
,
"a4"
,
TSDB_DATA_TYPE_BIGINT
);
addFieldToCreateStbReq
Func
(
false
,
"a5"
,
TSDB_DATA_TYPE_UBIGINT
);
addFieldToCreateStbReq
Func
(
false
,
"a6"
,
TSDB_DATA_TYPE_FLOAT
);
addFieldToCreateStbReq
Func
(
false
,
"a7"
,
TSDB_DATA_TYPE_DOUBLE
);
addFieldToCreateStbReq
Func
(
false
,
"a8"
,
TSDB_DATA_TYPE_BINARY
,
20
+
VARSTR_HEADER_SIZE
);
addFieldToCreateStbReq
Func
(
false
,
"a9"
,
TSDB_DATA_TYPE_SMALLINT
);
addFieldToCreateStbReq
Func
(
false
,
"a10"
,
TSDB_DATA_TYPE_USMALLINT
);
addFieldToCreateStbReq
Func
(
false
,
"a11"
,
TSDB_DATA_TYPE_TINYINT
);
addFieldToCreateStbReq
Func
(
false
,
"a12"
,
TSDB_DATA_TYPE_UTINYINT
);
addFieldToCreateStbReq
Func
(
false
,
"a13"
,
TSDB_DATA_TYPE_BOOL
);
addFieldToCreateStbReq
Func
(
false
,
"a14"
,
TSDB_DATA_TYPE_NCHAR
,
30
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
);
addFieldToCreateStbReq
Func
(
false
,
"a15"
,
TSDB_DATA_TYPE_VARCHAR
,
50
+
VARSTR_HEADER_SIZE
);
setCreateStbReq
(
"rollup_db"
,
"t1"
,
1
,
100
*
MILLISECOND_PER_SECOND
,
10
*
MILLISECOND_PER_MINUTE
,
10
,
1
*
MILLISECOND_PER_MINUTE
,
1000
*
MILLISECOND_PER_SECOND
,
200
*
MILLISECOND_PER_MINUTE
,
100
,
"test create table"
);
addFieldToCreateStbReq
(
true
,
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
,
0
,
0
);
addFieldToCreateStbReq
(
true
,
"c1"
,
TSDB_DATA_TYPE_INT
);
addFieldToCreateStbReq
(
true
,
"c2"
,
TSDB_DATA_TYPE_UINT
);
addFieldToCreateStbReq
(
true
,
"c3"
,
TSDB_DATA_TYPE_BIGINT
);
addFieldToCreateStbReq
(
true
,
"c4"
,
TSDB_DATA_TYPE_UBIGINT
,
0
,
0
);
addFieldToCreateStbReq
(
true
,
"c5"
,
TSDB_DATA_TYPE_FLOAT
,
0
,
0
);
addFieldToCreateStbReq
(
true
,
"c6"
,
TSDB_DATA_TYPE_DOUBLE
,
0
,
0
);
addFieldToCreateStbReq
(
true
,
"c7"
,
TSDB_DATA_TYPE_BINARY
,
20
+
VARSTR_HEADER_SIZE
,
0
);
addFieldToCreateStbReq
(
true
,
"c8"
,
TSDB_DATA_TYPE_SMALLINT
,
0
,
0
);
addFieldToCreateStbReq
(
true
,
"c9"
,
TSDB_DATA_TYPE_USMALLINT
,
0
,
0
);
addFieldToCreateStbReq
(
true
,
"c10"
,
TSDB_DATA_TYPE_TINYINT
,
0
,
0
);
addFieldToCreateStbReq
(
true
,
"c11"
,
TSDB_DATA_TYPE_UTINYINT
,
0
,
0
);
addFieldToCreateStbReq
(
true
,
"c12"
,
TSDB_DATA_TYPE_BOOL
,
0
,
0
);
addFieldToCreateStbReq
(
true
,
"c13"
,
TSDB_DATA_TYPE_NCHAR
,
30
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
,
0
);
addFieldToCreateStbReq
(
true
,
"c14"
,
TSDB_DATA_TYPE_VARCHAR
,
50
+
VARSTR_HEADER_SIZE
,
0
);
addFieldToCreateStbReq
(
false
,
"a1"
,
TSDB_DATA_TYPE_TIMESTAMP
);
addFieldToCreateStbReq
(
false
,
"a2"
,
TSDB_DATA_TYPE_INT
);
addFieldToCreateStbReq
(
false
,
"a3"
,
TSDB_DATA_TYPE_UINT
);
addFieldToCreateStbReq
(
false
,
"a4"
,
TSDB_DATA_TYPE_BIGINT
);
addFieldToCreateStbReq
(
false
,
"a5"
,
TSDB_DATA_TYPE_UBIGINT
);
addFieldToCreateStbReq
(
false
,
"a6"
,
TSDB_DATA_TYPE_FLOAT
);
addFieldToCreateStbReq
(
false
,
"a7"
,
TSDB_DATA_TYPE_DOUBLE
);
addFieldToCreateStbReq
(
false
,
"a8"
,
TSDB_DATA_TYPE_BINARY
,
20
+
VARSTR_HEADER_SIZE
);
addFieldToCreateStbReq
(
false
,
"a9"
,
TSDB_DATA_TYPE_SMALLINT
);
addFieldToCreateStbReq
(
false
,
"a10"
,
TSDB_DATA_TYPE_USMALLINT
);
addFieldToCreateStbReq
(
false
,
"a11"
,
TSDB_DATA_TYPE_TINYINT
);
addFieldToCreateStbReq
(
false
,
"a12"
,
TSDB_DATA_TYPE_UTINYINT
);
addFieldToCreateStbReq
(
false
,
"a13"
,
TSDB_DATA_TYPE_BOOL
);
addFieldToCreateStbReq
(
false
,
"a14"
,
TSDB_DATA_TYPE_NCHAR
,
30
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
);
addFieldToCreateStbReq
(
false
,
"a15"
,
TSDB_DATA_TYPE_VARCHAR
,
50
+
VARSTR_HEADER_SIZE
);
run
(
"CREATE STABLE IF NOT EXISTS rollup_db.t1("
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), "
"c8 SMALLINT, c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, "
...
...
@@ -630,6 +730,20 @@ TEST_F(ParserInitialCTest, createStableSemanticCheck) {
TSDB_CODE_PAR_INVALID_TABLE_OPTION
);
}
/*
* CREATE STREAM [IF NOT EXISTS] stream_name [stream_options]
* INTO stb_name [TAGS (create_definition [, create_definition] ...)] [SUBTABLE (expr)] AS subquery
*
* stream_options:
* stream_option ...
*
* stream_option: {
* TRIGGER [AT_ONCE | WINDOW_CLOSE | MAX_DELAY time]
* | WATERMARK time
* | IGNORE EXPIRED value
* | FILL_HISTORY value
* }
*/
TEST_F
(
ParserInitialCTest
,
createStream
)
{
useDb
(
"root"
,
"test"
);
...
...
@@ -734,9 +848,103 @@ TEST_F(ParserInitialCTest, createStreamSemanticCheck) {
TSDB_CODE_PAR_STREAM_NOT_ALLOWED_FUNC
);
}
/*
* CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definitionn] ...) [table_options]
*
* CREATE TABLE create_subtable_clause
*
* CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definitionn] ...)
* [TAGS (create_definition [, create_definitionn] ...)]
* [table_options]
*
* create_subtable_clause: {
* create_subtable_clause [create_subtable_clause] ...
* | [IF NOT EXISTS] [db_name.]tb_name USING [db_name.]stb_name [(tag_name [, tag_name] ...)]
* TAGS (tag_value [, tag_value] ...)
* }
*
* create_definition:
* col_name column_definition
*
* column_definition:
* type_name [comment 'string_value']
*
* table_options:
* table_option ...
*
* table_option: {
* COMMENT 'string_value'
* | WATERMARK duration[,duration]
* | MAX_DELAY duration[,duration]
* | ROLLUP(func_name [, func_name] ...)
* | SMA(col_name [, col_name] ...)
* | TTL value
* }
*/
TEST_F
(
ParserInitialCTest
,
createTable
)
{
useDb
(
"root"
,
"test"
);
SVCreateTbBatchReq
expect
=
{
0
};
auto
addCreateTbReq
=
[
&
](
const
char
*
pName
,
bool
ignoreExists
=
false
,
int32_t
ttl
=
TSDB_DEFAULT_TABLE_TTL
,
const
char
*
pComment
=
nullptr
)
{
SVCreateTbReq
req
=
{
0
};
req
.
name
=
strdup
(
pName
);
if
(
ignoreExists
)
{
req
.
flags
|=
TD_CREATE_IF_NOT_EXISTS
;
}
req
.
ttl
=
ttl
;
if
(
nullptr
!=
pComment
)
{
req
.
comment
=
strdup
(
pComment
);
req
.
commentLen
=
strlen
(
pComment
);
}
++
expect
.
nReqs
;
if
(
nullptr
==
expect
.
pArray
)
{
expect
.
pArray
=
taosArrayInit
(
TARRAY_MIN_SIZE
,
sizeof
(
SVCreateTbReq
));
}
taosArrayPush
(
expect
.
pArray
,
&
req
);
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
return
;
// todo
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_VNODE_MODIFY_STMT
);
SVnodeModifyOpStmt
*
pStmt
=
(
SVnodeModifyOpStmt
*
)
pQuery
->
pRoot
;
ASSERT_EQ
(
pStmt
->
sqlNodeType
,
QUERY_NODE_CREATE_TABLE_STMT
);
ASSERT_NE
(
pStmt
->
pDataBlocks
,
nullptr
);
int32_t
numOfBlocks
=
taosArrayGetSize
(
pStmt
->
pDataBlocks
);
for
(
int32_t
i
=
0
;
i
<
numOfBlocks
;
++
i
)
{
SVgDataBlocks
*
pVgData
=
(
SVgDataBlocks
*
)
taosArrayGetP
(
pStmt
->
pDataBlocks
,
i
);
void
*
pBuf
=
POINTER_SHIFT
(
pVgData
->
pData
,
sizeof
(
SMsgHead
));
SVCreateTbBatchReq
req
=
{
0
};
SDecoder
coder
=
{
0
};
tDecoderInit
(
&
coder
,
(
uint8_t
*
)
pBuf
,
pVgData
->
size
);
ASSERT_EQ
(
tDecodeSVCreateTbBatchReq
(
&
coder
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
req
.
nReqs
,
expect
.
nReqs
);
for
(
int32_t
j
=
0
;
j
<
req
.
nReqs
;
++
j
)
{
SVCreateTbReq
*
pReq
=
req
.
pReqs
+
j
;
SVCreateTbReq
*
pExpect
=
(
SVCreateTbReq
*
)
taosArrayGet
(
expect
.
pArray
,
j
);
ASSERT_EQ
(
pReq
->
flags
,
pExpect
->
flags
);
ASSERT_EQ
(
std
::
string
(
pReq
->
name
),
std
::
string
(
pExpect
->
name
));
ASSERT_EQ
(
pReq
->
uid
,
pExpect
->
uid
);
ASSERT_EQ
(
pReq
->
ctime
,
pExpect
->
ctime
);
ASSERT_EQ
(
pReq
->
ttl
,
pExpect
->
ttl
);
ASSERT_EQ
(
pReq
->
commentLen
,
pExpect
->
commentLen
);
ASSERT_EQ
(
std
::
string
(
pReq
->
comment
),
std
::
string
(
pExpect
->
comment
));
ASSERT_EQ
(
pReq
->
type
,
pExpect
->
type
);
if
(
TD_NORMAL_TABLE
==
pExpect
->
type
)
{
ASSERT_EQ
(
pReq
->
ntb
.
schemaRow
.
version
,
pExpect
->
ntb
.
schemaRow
.
version
);
ASSERT_EQ
(
pReq
->
ntb
.
schemaRow
.
nCols
,
pExpect
->
ntb
.
schemaRow
.
nCols
);
}
else
if
(
TD_CHILD_TABLE
==
pExpect
->
type
)
{
ASSERT_EQ
(
std
::
string
(
pReq
->
ctb
.
stbName
),
std
::
string
(
pExpect
->
ctb
.
stbName
));
ASSERT_EQ
(
pReq
->
ctb
.
tagNum
,
pExpect
->
ctb
.
tagNum
);
ASSERT_EQ
(
pReq
->
ctb
.
suid
,
pExpect
->
ctb
.
suid
);
}
}
tDecoderClear
(
&
coder
);
}
});
run
(
"CREATE TABLE t1(ts TIMESTAMP, c1 INT)"
);
run
(
"CREATE TABLE IF NOT EXISTS test.t1("
...
...
@@ -761,7 +969,7 @@ TEST_F(ParserInitialCTest, createTable) {
"IF NOT EXISTS test.t2 USING test.st1 (tag1, tag2) TAGS(2, 'abc') "
"IF NOT EXISTS test.t3 USING test.st1 (tag1, tag2) TAGS(3, 'abc') "
);
//
run("CREATE TABLE IF NOT EXISTS t1 USING st1 TAGS(1, 'wxy', NOW + 1S)");
run
(
"CREATE TABLE IF NOT EXISTS t1 USING st1 TAGS(1, 'wxy', NOW + 1S)"
);
}
TEST_F
(
ParserInitialCTest
,
createTableSemanticCheck
)
{
...
...
@@ -779,6 +987,11 @@ TEST_F(ParserInitialCTest, createTableSemanticCheck) {
run
(
sql
,
TSDB_CODE_PAR_TOO_MANY_COLUMNS
);
}
/*
* CREATE TOPIC [IF NOT EXISTS] topic_name AS subquery
*
* CREATE TOPIC [IF NOT EXISTS] topic_name [WITH META] AS {DATABASE db_name | STABLE stb_name }
*/
TEST_F
(
ParserInitialCTest
,
createTopic
)
{
useDb
(
"root"
,
"test"
);
...
...
@@ -786,8 +999,8 @@ TEST_F(ParserInitialCTest, createTopic) {
auto
clearCreateTopicReq
=
[
&
]()
{
memset
(
&
expect
,
0
,
sizeof
(
SCMCreateTopicReq
));
};
auto
setCreateTopicReq
Func
=
[
&
](
const
char
*
pTopicName
,
int8_t
igExists
,
const
char
*
pSql
,
const
char
*
pAst
,
const
char
*
pDbName
=
nullptr
,
const
char
*
pTbname
=
nullptr
,
int8_t
withMeta
=
0
)
{
auto
setCreateTopicReq
=
[
&
](
const
char
*
pTopicName
,
int8_t
igExists
,
const
char
*
pSql
,
const
char
*
pAst
,
const
char
*
pDbName
=
nullptr
,
const
char
*
pTbname
=
nullptr
,
int8_t
withMeta
=
0
)
{
snprintf
(
expect
.
name
,
sizeof
(
expect
.
name
),
"0.%s"
,
pTopicName
);
expect
.
igExists
=
igExists
;
expect
.
sql
=
(
char
*
)
pSql
;
...
...
@@ -831,31 +1044,34 @@ TEST_F(ParserInitialCTest, createTopic) {
tFreeSCMCreateTopicReq
(
&
req
);
});
setCreateTopicReq
Func
(
"tp1"
,
0
,
"create topic tp1 as select * from t1"
,
"ast"
);
setCreateTopicReq
(
"tp1"
,
0
,
"create topic tp1 as select * from t1"
,
"ast"
);
run
(
"CREATE TOPIC tp1 AS SELECT * FROM t1"
);
clearCreateTopicReq
();
setCreateTopicReq
Func
(
"tp1"
,
1
,
"create topic if not exists tp1 as select ts, ceil(c1) from t1"
,
"ast"
);
setCreateTopicReq
(
"tp1"
,
1
,
"create topic if not exists tp1 as select ts, ceil(c1) from t1"
,
"ast"
);
run
(
"CREATE TOPIC IF NOT EXISTS tp1 AS SELECT ts, CEIL(c1) FROM t1"
);
clearCreateTopicReq
();
setCreateTopicReq
Func
(
"tp1"
,
0
,
"create topic tp1 as database test"
,
nullptr
,
"test"
);
setCreateTopicReq
(
"tp1"
,
0
,
"create topic tp1 as database test"
,
nullptr
,
"test"
);
run
(
"CREATE TOPIC tp1 AS DATABASE test"
);
clearCreateTopicReq
();
setCreateTopicReq
Func
(
"tp1"
,
0
,
"create topic tp1 with meta as database test"
,
nullptr
,
"test"
,
nullptr
,
1
);
setCreateTopicReq
(
"tp1"
,
0
,
"create topic tp1 with meta as database test"
,
nullptr
,
"test"
,
nullptr
,
1
);
run
(
"CREATE TOPIC tp1 WITH META AS DATABASE test"
);
clearCreateTopicReq
();
setCreateTopicReq
Func
(
"tp1"
,
1
,
"create topic if not exists tp1 as stable st1"
,
nullptr
,
"test"
,
"st1"
);
setCreateTopicReq
(
"tp1"
,
1
,
"create topic if not exists tp1 as stable st1"
,
nullptr
,
"test"
,
"st1"
);
run
(
"CREATE TOPIC IF NOT EXISTS tp1 AS STABLE st1"
);
clearCreateTopicReq
();
setCreateTopicReq
Func
(
"tp1"
,
1
,
"create topic if not exists tp1 with meta as stable st1"
,
nullptr
,
"test"
,
"st1"
,
1
);
setCreateTopicReq
(
"tp1"
,
1
,
"create topic if not exists tp1 with meta as stable st1"
,
nullptr
,
"test"
,
"st1"
,
1
);
run
(
"CREATE TOPIC IF NOT EXISTS tp1 WITH META AS STABLE st1"
);
clearCreateTopicReq
();
}
/*
* CREATE USER use_name PASS password [SYSINFO value]
*/
TEST_F
(
ParserInitialCTest
,
createUser
)
{
useDb
(
"root"
,
"test"
);
...
...
source/libs/parser/test/parInitialDTest.cpp
浏览文件 @
30065f30
...
...
@@ -99,7 +99,7 @@ TEST_F(ParserInitialDTest, dropDnode) {
expect
.
force
=
force
;
};
auto
setDropDnodeReqByEndpoint
=
[
&
](
const
char
*
pFqdn
,
int32_t
port
,
bool
force
=
false
)
{
auto
setDropDnodeReqByEndpoint
=
[
&
](
const
char
*
pFqdn
,
int32_t
port
=
tsServerPort
,
bool
force
=
false
)
{
strcpy
(
expect
.
fqdn
,
pFqdn
);
expect
.
port
=
port
;
expect
.
force
=
force
;
...
...
@@ -131,6 +131,14 @@ TEST_F(ParserInitialDTest, dropDnode) {
setDropDnodeReqByEndpoint
(
"host2"
,
8030
,
true
);
run
(
"DROP DNODE 'host2:8030' FORCE"
);
clearDropDnodeReq
();
setDropDnodeReqByEndpoint
(
"host1"
);
run
(
"DROP DNODE host1"
);
clearDropDnodeReq
();
setDropDnodeReqByEndpoint
(
"host2"
,
tsServerPort
,
true
);
run
(
"DROP DNODE host2 FORCE"
);
clearDropDnodeReq
();
}
// todo DROP function
...
...
@@ -174,7 +182,21 @@ TEST_F(ParserInitialDTest, dropMnode) {
TEST_F
(
ParserInitialDTest
,
dropQnode
)
{
useDb
(
"root"
,
"test"
);
run
(
"DROP qnode on dnode 1"
);
SMDropQnodeReq
expect
=
{
0
};
auto
setDropQnodeReq
=
[
&
](
int32_t
dnodeId
)
{
expect
.
dnodeId
=
dnodeId
;
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_DROP_QNODE_STMT
);
SMDropQnodeReq
req
=
{
0
};
ASSERT_TRUE
(
TSDB_CODE_SUCCESS
==
tDeserializeSCreateDropMQSNodeReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
));
ASSERT_EQ
(
req
.
dnodeId
,
expect
.
dnodeId
);
});
setDropQnodeReq
(
1
);
run
(
"DROP QNODE ON DNODE 1"
);
}
TEST_F
(
ParserInitialDTest
,
dropSnode
)
{
...
...
@@ -237,7 +259,20 @@ TEST_F(ParserInitialDTest, dropUser) {
login
(
"root"
);
useDb
(
"root"
,
"test"
);
run
(
"DROP user wxy"
);
SDropUserReq
expect
=
{
0
};
auto
setDropUserReq
=
[
&
](
const
char
*
pUser
)
{
sprintf
(
expect
.
user
,
"%s"
,
pUser
);
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_DROP_USER_STMT
);
SDropUserReq
req
=
{
0
};
ASSERT_TRUE
(
TSDB_CODE_SUCCESS
==
tDeserializeSDropUserReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
));
ASSERT_EQ
(
std
::
string
(
req
.
user
),
std
::
string
(
expect
.
user
));
});
setDropUserReq
(
"wxy"
);
run
(
"DROP USER wxy"
);
}
}
// namespace ParserTest
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录