Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ac34cde0
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看板
提交
ac34cde0
编写于
7月 04, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: increase the validity check of the rollup parameter in the create table statement
上级
047f6593
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
151 addition
and
72 deletion
+151
-72
source/common/src/tmsg.c
source/common/src/tmsg.c
+6
-4
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+50
-12
source/libs/parser/test/mockCatalog.cpp
source/libs/parser/test/mockCatalog.cpp
+37
-32
source/libs/parser/test/mockCatalogService.cpp
source/libs/parser/test/mockCatalogService.cpp
+28
-0
source/libs/parser/test/mockCatalogService.h
source/libs/parser/test/mockCatalogService.h
+2
-0
source/libs/parser/test/parInitialATest.cpp
source/libs/parser/test/parInitialATest.cpp
+2
-2
source/libs/parser/test/parInitialCTest.cpp
source/libs/parser/test/parInitialCTest.cpp
+26
-22
未找到文件。
source/common/src/tmsg.c
浏览文件 @
ac34cde0
...
...
@@ -2679,10 +2679,12 @@ int32_t tDeserializeSDbCfgRsp(void *buf, int32_t bufLen, SDbCfgRsp *pRsp) {
if
(
tDecodeI8
(
&
decoder
,
&
pRsp
->
strict
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
&
decoder
,
&
pRsp
->
cacheLastRow
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
pRsp
->
numOfRetensions
)
<
0
)
return
-
1
;
pRsp
->
pRetensions
=
taosArrayInit
(
pRsp
->
numOfRetensions
,
sizeof
(
SRetention
));
if
(
pRsp
->
pRetensions
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
if
(
pRsp
->
numOfRetensions
>
0
)
{
pRsp
->
pRetensions
=
taosArrayInit
(
pRsp
->
numOfRetensions
,
sizeof
(
SRetention
));
if
(
pRsp
->
pRetensions
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
}
for
(
int32_t
i
=
0
;
i
<
pRsp
->
numOfRetensions
;
++
i
)
{
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
ac34cde0
...
...
@@ -3215,13 +3215,30 @@ static bool validRollupFunc(const char* pFunc) {
return
false
;
}
static
int32_t
checkTableRollupOption
(
STranslateContext
*
pCxt
,
SNodeList
*
pFuncs
)
{
static
int32_t
checkTableRollupOption
(
STranslateContext
*
pCxt
,
SNodeList
*
pFuncs
,
bool
createStable
,
SDbCfgInfo
*
pDbCfg
)
{
if
(
NULL
==
pFuncs
)
{
if
(
NULL
!=
pDbCfg
->
pRetensions
)
{
return
generateSyntaxErrMsgExt
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TABLE_OPTION
,
"To create a super table in a database with the retensions parameter configured, "
"the 'ROLLUP' option must be present"
);
}
return
TSDB_CODE_SUCCESS
;
}
if
(
1
!=
LIST_LENGTH
(
pFuncs
)
||
!
validRollupFunc
(((
SFunctionNode
*
)
nodesListGetNode
(
pFuncs
,
0
))
->
functionName
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ROLLUP_OPTION
);
if
(
!
createStable
||
NULL
==
pDbCfg
->
pRetensions
)
{
return
generateSyntaxErrMsgExt
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TABLE_OPTION
,
"Invalid option rollup: Only supported for create super table in databases "
"configured with the 'RETENTIONS' option"
);
}
if
(
1
!=
LIST_LENGTH
(
pFuncs
))
{
return
generateSyntaxErrMsgExt
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ROLLUP_OPTION
,
"Invalid option rollup: only one function is allowed"
);
}
const
char
*
pFunc
=
((
SFunctionNode
*
)
nodesListGetNode
(
pFuncs
,
0
))
->
functionName
;
if
(
!
validRollupFunc
(
pFunc
))
{
return
generateSyntaxErrMsgExt
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ROLLUP_OPTION
,
"Invalid option rollup: %s function is not supported"
,
pFunc
);
}
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -3358,11 +3375,18 @@ static int32_t getTableMaxDelayOption(STranslateContext* pCxt, SValueNode* pVal,
pMaxDelay
);
}
static
int32_t
checkTableMaxDelayOption
(
STranslateContext
*
pCxt
,
STableOptions
*
pOptions
)
{
static
int32_t
checkTableMaxDelayOption
(
STranslateContext
*
pCxt
,
STableOptions
*
pOptions
,
bool
createStable
,
SDbCfgInfo
*
pDbCfg
)
{
if
(
NULL
==
pOptions
->
pMaxDelay
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
!
createStable
||
NULL
==
pDbCfg
->
pRetensions
)
{
return
generateSyntaxErrMsgExt
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TABLE_OPTION
,
"Invalid option maxdelay: Only supported for create super table in databases "
"configured with the 'RETENTIONS' option"
);
}
if
(
LIST_LENGTH
(
pOptions
->
pMaxDelay
)
>
2
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TABLE_OPTION
,
"maxdelay"
);
}
...
...
@@ -3381,11 +3405,18 @@ static int32_t getTableWatermarkOption(STranslateContext* pCxt, SValueNode* pVal
pMaxDelay
);
}
static
int32_t
checkTableWatermarkOption
(
STranslateContext
*
pCxt
,
STableOptions
*
pOptions
)
{
static
int32_t
checkTableWatermarkOption
(
STranslateContext
*
pCxt
,
STableOptions
*
pOptions
,
bool
createStable
,
SDbCfgInfo
*
pDbCfg
)
{
if
(
NULL
==
pOptions
->
pWatermark
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
!
createStable
||
NULL
==
pDbCfg
->
pRetensions
)
{
return
generateSyntaxErrMsgExt
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TABLE_OPTION
,
"Invalid option watermark: Only supported for create super table in databases "
"configured with the 'RETENTIONS' option"
);
}
if
(
LIST_LENGTH
(
pOptions
->
pWatermark
)
>
2
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TABLE_OPTION
,
"watermark"
);
}
...
...
@@ -3399,13 +3430,20 @@ static int32_t checkTableWatermarkOption(STranslateContext* pCxt, STableOptions*
return
code
;
}
static
int32_t
checkCreateTable
(
STranslateContext
*
pCxt
,
SCreateTableStmt
*
pStmt
)
{
int32_t
code
=
checkTableMaxDelayOption
(
pCxt
,
pStmt
->
pOptions
);
static
int32_t
checkCreateTable
(
STranslateContext
*
pCxt
,
SCreateTableStmt
*
pStmt
,
bool
createStable
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
SDbCfgInfo
dbCfg
=
{
0
};
if
(
createStable
)
{
code
=
getDBCfg
(
pCxt
,
pStmt
->
dbName
,
&
dbCfg
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkTableMaxDelayOption
(
pCxt
,
pStmt
->
pOptions
,
createStable
,
&
dbCfg
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkTableWatermarkOption
(
pCxt
,
pStmt
->
pOptions
);
code
=
checkTableWatermarkOption
(
pCxt
,
pStmt
->
pOptions
,
createStable
,
&
dbCfg
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkTableRollupOption
(
pCxt
,
pStmt
->
pOptions
->
pRollupFuncs
);
code
=
checkTableRollupOption
(
pCxt
,
pStmt
->
pOptions
->
pRollupFuncs
,
createStable
,
&
dbCfg
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkTableSmaOption
(
pCxt
,
pStmt
);
...
...
@@ -3684,7 +3722,7 @@ static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStm
static
int32_t
translateCreateSuperTable
(
STranslateContext
*
pCxt
,
SCreateTableStmt
*
pStmt
)
{
SMCreateStbReq
createReq
=
{
0
};
int32_t
code
=
checkCreateTable
(
pCxt
,
pStmt
);
int32_t
code
=
checkCreateTable
(
pCxt
,
pStmt
,
true
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
buildCreateStbReq
(
pCxt
,
pStmt
,
&
createReq
);
}
...
...
@@ -4267,7 +4305,7 @@ static void getSourceDatabase(SNode* pStmt, int32_t acctId, char* pDbFName) {
static
int32_t
addWstartTsToCreateStreamQuery
(
SNode
*
pStmt
)
{
SSelectStmt
*
pSelect
=
(
SSelectStmt
*
)
pStmt
;
SNode
*
pProj
=
nodesListGetNode
(
pSelect
->
pProjectionList
,
0
);
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pProj
)
&&
FUNCTION_TYPE_WSTARTTS
==
((
SFunctionNode
*
)
pProj
)
->
funcType
)
{
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pProj
)
&&
0
==
strcmp
(
"_wstartts"
,
((
SFunctionNode
*
)
pProj
)
->
functionName
)
)
{
return
TSDB_CODE_SUCCESS
;
}
SFunctionNode
*
pFunc
=
(
SFunctionNode
*
)
nodesMakeNode
(
QUERY_NODE_FUNCTION
);
...
...
@@ -5258,7 +5296,7 @@ static int32_t buildCreateTableDataBlock(int32_t acctId, const SCreateTableStmt*
static
int32_t
rewriteCreateTable
(
STranslateContext
*
pCxt
,
SQuery
*
pQuery
)
{
SCreateTableStmt
*
pStmt
=
(
SCreateTableStmt
*
)
pQuery
->
pRoot
;
int32_t
code
=
checkCreateTable
(
pCxt
,
pStmt
);
int32_t
code
=
checkCreateTable
(
pCxt
,
pStmt
,
false
);
SVgroupInfo
info
=
{
0
};
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
getTableHashVgroup
(
pCxt
,
pStmt
->
dbName
,
pStmt
->
tableName
,
&
info
);
...
...
source/libs/parser/test/mockCatalog.cpp
浏览文件 @
ac34cde0
...
...
@@ -159,7 +159,7 @@ void generatePerformanceSchema(MockCatalogService* mcs) {
* c4 | column | DOUBLE | 8 |
* c5 | column | DOUBLE | 8 |
*/
void
generateTestT
1
(
MockCatalogService
*
mcs
)
{
void
generateTestT
ables
(
MockCatalogService
*
mcs
)
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"t1"
,
TSDB_NORMAL_TABLE
,
6
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
)
.
setVgid
(
1
)
...
...
@@ -183,23 +183,7 @@ void generateTestT1(MockCatalogService* mcs) {
* tag2 | tag | VARCHAR | 20 |
* tag3 | tag | TIMESTAMP | 8 |
* Child Table: st1s1, st1s2
*/
void
generateTestST1
(
MockCatalogService
*
mcs
)
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"st1"
,
TSDB_SUPER_TABLE
,
3
,
3
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
)
.
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
)
.
addColumn
(
"c1"
,
TSDB_DATA_TYPE_INT
)
.
addColumn
(
"c2"
,
TSDB_DATA_TYPE_BINARY
,
20
)
.
addTag
(
"tag1"
,
TSDB_DATA_TYPE_INT
)
.
addTag
(
"tag2"
,
TSDB_DATA_TYPE_BINARY
,
20
)
.
addTag
(
"tag3"
,
TSDB_DATA_TYPE_TIMESTAMP
);
builder
.
done
();
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s1"
,
1
);
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s2"
,
2
);
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s3"
,
1
);
}
/*
*
* Super Table: st2
* Field | Type | DataType | Bytes |
* ==========================================================================
...
...
@@ -209,16 +193,32 @@ void generateTestST1(MockCatalogService* mcs) {
* jtag | tag | json | -- |
* Child Table: st2s1, st2s2
*/
void
generateTestST2
(
MockCatalogService
*
mcs
)
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"st2"
,
TSDB_SUPER_TABLE
,
3
,
1
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
)
.
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
)
.
addColumn
(
"c1"
,
TSDB_DATA_TYPE_INT
)
.
addColumn
(
"c2"
,
TSDB_DATA_TYPE_BINARY
,
20
)
.
addTag
(
"jtag"
,
TSDB_DATA_TYPE_JSON
);
builder
.
done
();
mcs
->
createSubTable
(
"test"
,
"st2"
,
"st2s1"
,
1
);
mcs
->
createSubTable
(
"test"
,
"st2"
,
"st2s2"
,
2
);
void
generateTestStables
(
MockCatalogService
*
mcs
)
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"st1"
,
TSDB_SUPER_TABLE
,
3
,
3
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
)
.
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
)
.
addColumn
(
"c1"
,
TSDB_DATA_TYPE_INT
)
.
addColumn
(
"c2"
,
TSDB_DATA_TYPE_BINARY
,
20
)
.
addTag
(
"tag1"
,
TSDB_DATA_TYPE_INT
)
.
addTag
(
"tag2"
,
TSDB_DATA_TYPE_BINARY
,
20
)
.
addTag
(
"tag3"
,
TSDB_DATA_TYPE_TIMESTAMP
);
builder
.
done
();
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s1"
,
1
);
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s2"
,
2
);
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s3"
,
1
);
}
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"st2"
,
TSDB_SUPER_TABLE
,
3
,
1
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
)
.
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
)
.
addColumn
(
"c1"
,
TSDB_DATA_TYPE_INT
)
.
addColumn
(
"c2"
,
TSDB_DATA_TYPE_BINARY
,
20
)
.
addTag
(
"jtag"
,
TSDB_DATA_TYPE_JSON
);
builder
.
done
();
mcs
->
createSubTable
(
"test"
,
"st2"
,
"st2s1"
,
1
);
mcs
->
createSubTable
(
"test"
,
"st2"
,
"st2s2"
,
2
);
}
}
void
generateFunctions
(
MockCatalogService
*
mcs
)
{
...
...
@@ -233,6 +233,11 @@ void generateDnodes(MockCatalogService* mcs) {
mcs
->
createDnode
(
3
,
"host3"
,
7030
);
}
void
generateDatabases
(
MockCatalogService
*
mcs
)
{
mcs
->
createDatabase
(
"test"
);
mcs
->
createDatabase
(
"rollup_db"
,
true
);
}
}
// namespace
int32_t
__catalogGetHandle
(
const
char
*
clusterId
,
struct
SCatalog
**
catalogHandle
)
{
return
0
;
}
...
...
@@ -262,7 +267,7 @@ int32_t __catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char
}
int32_t
__catalogGetDBCfg
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
dbFName
,
SDbCfgInfo
*
pDbCfg
)
{
return
0
;
return
g_mockCatalogService
->
catalogGetDBCfg
(
dbFName
,
pDbCfg
)
;
}
int32_t
__catalogChkAuth
(
SCatalog
*
pCtg
,
SRequestConnInfo
*
pConn
,
const
char
*
user
,
const
char
*
dbFName
,
AUTH_TYPE
type
,
...
...
@@ -359,11 +364,11 @@ void initMetaDataEnv() {
}
void
generateMetaData
()
{
generateDatabases
(
g_mockCatalogService
.
get
());
generateInformationSchema
(
g_mockCatalogService
.
get
());
generatePerformanceSchema
(
g_mockCatalogService
.
get
());
generateTestT1
(
g_mockCatalogService
.
get
());
generateTestST1
(
g_mockCatalogService
.
get
());
generateTestST2
(
g_mockCatalogService
.
get
());
generateTestTables
(
g_mockCatalogService
.
get
());
generateTestStables
(
g_mockCatalogService
.
get
());
generateFunctions
(
g_mockCatalogService
.
get
());
generateDnodes
(
g_mockCatalogService
.
get
());
g_mockCatalogService
->
showTables
();
...
...
source/libs/parser/test/mockCatalogService.cpp
浏览文件 @
ac34cde0
...
...
@@ -140,6 +140,17 @@ class MockCatalogServiceImpl {
return
TSDB_CODE_SUCCESS
;
}
int32_t
catalogGetDBCfg
(
const
char
*
pDbFName
,
SDbCfgInfo
*
pDbCfg
)
const
{
std
::
string
dbFName
(
pDbFName
);
DbCfgCache
::
const_iterator
it
=
dbCfg_
.
find
(
dbFName
.
substr
(
std
::
string
(
pDbFName
).
find_last_of
(
'.'
)
+
1
));
if
(
dbCfg_
.
end
()
==
it
)
{
return
TSDB_CODE_FAILED
;
}
memcpy
(
pDbCfg
,
&
(
it
->
second
),
sizeof
(
SDbCfgInfo
));
return
TSDB_CODE_SUCCESS
;
}
int32_t
catalogGetUdfInfo
(
const
std
::
string
&
funcName
,
SFuncInfo
*
pInfo
)
const
{
auto
it
=
udf_
.
find
(
funcName
);
if
(
udf_
.
end
()
==
it
)
{
...
...
@@ -323,12 +334,21 @@ class MockCatalogServiceImpl {
dnode_
.
insert
(
std
::
make_pair
(
dnodeId
,
epSet
));
}
void
createDatabase
(
const
std
::
string
&
db
,
bool
rollup
)
{
SDbCfgInfo
cfg
=
{
0
};
if
(
rollup
)
{
cfg
.
pRetensions
=
taosArrayInit
(
TARRAY_MIN_SIZE
,
sizeof
(
SRetention
));
}
dbCfg_
.
insert
(
std
::
make_pair
(
db
,
cfg
));
}
private:
typedef
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
MockTableMeta
>>
TableMetaCache
;
typedef
std
::
map
<
std
::
string
,
TableMetaCache
>
DbMetaCache
;
typedef
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
SFuncInfo
>>
UdfMetaCache
;
typedef
std
::
map
<
std
::
string
,
std
::
vector
<
STableIndexInfo
>>
IndexMetaCache
;
typedef
std
::
map
<
int32_t
,
SEpSet
>
DnodeCache
;
typedef
std
::
map
<
std
::
string
,
SDbCfgInfo
>
DbCfgCache
;
uint64_t
getNextId
()
{
return
id_
++
;
}
...
...
@@ -486,6 +506,7 @@ class MockCatalogServiceImpl {
for
(
int32_t
i
=
0
;
i
<
ndbs
;
++
i
)
{
SMetaRes
res
=
{
0
};
res
.
pRes
=
taosMemoryCalloc
(
1
,
sizeof
(
SDbCfgInfo
));
res
.
code
=
catalogGetDBCfg
((
const
char
*
)
taosArrayGet
(
pDbCfgReq
,
i
),
(
SDbCfgInfo
*
)
res
.
pRes
);
taosArrayPush
(
*
pDbCfgData
,
&
res
);
}
}
...
...
@@ -576,6 +597,7 @@ class MockCatalogServiceImpl {
UdfMetaCache
udf_
;
IndexMetaCache
index_
;
DnodeCache
dnode_
;
DbCfgCache
dbCfg_
;
};
MockCatalogService
::
MockCatalogService
()
:
impl_
(
new
MockCatalogServiceImpl
())
{}
...
...
@@ -605,6 +627,8 @@ void MockCatalogService::createDnode(int32_t dnodeId, const std::string& host, i
impl_
->
createDnode
(
dnodeId
,
host
,
port
);
}
void
MockCatalogService
::
createDatabase
(
const
std
::
string
&
db
,
bool
rollup
)
{
impl_
->
createDatabase
(
db
,
rollup
);
}
int32_t
MockCatalogService
::
catalogGetTableMeta
(
const
SName
*
pTableName
,
STableMeta
**
pTableMeta
)
const
{
return
impl_
->
catalogGetTableMeta
(
pTableName
,
pTableMeta
);
}
...
...
@@ -621,6 +645,10 @@ int32_t MockCatalogService::catalogGetDBVgInfo(const char* pDbFName, SArray** pV
return
impl_
->
catalogGetDBVgInfo
(
pDbFName
,
pVgList
);
}
int32_t
MockCatalogService
::
catalogGetDBCfg
(
const
char
*
pDbFName
,
SDbCfgInfo
*
pDbCfg
)
const
{
return
impl_
->
catalogGetDBCfg
(
pDbFName
,
pDbCfg
);
}
int32_t
MockCatalogService
::
catalogGetUdfInfo
(
const
std
::
string
&
funcName
,
SFuncInfo
*
pInfo
)
const
{
return
impl_
->
catalogGetUdfInfo
(
funcName
,
pInfo
);
}
...
...
source/libs/parser/test/mockCatalogService.h
浏览文件 @
ac34cde0
...
...
@@ -63,11 +63,13 @@ class MockCatalogService {
void
createFunction
(
const
std
::
string
&
func
,
int8_t
funcType
,
int8_t
outputType
,
int32_t
outputLen
,
int32_t
bufSize
);
void
createSmaIndex
(
const
SMCreateSmaReq
*
pReq
);
void
createDnode
(
int32_t
dnodeId
,
const
std
::
string
&
host
,
int16_t
port
);
void
createDatabase
(
const
std
::
string
&
db
,
bool
rollup
=
false
);
int32_t
catalogGetTableMeta
(
const
SName
*
pTableName
,
STableMeta
**
pTableMeta
)
const
;
int32_t
catalogGetTableHashVgroup
(
const
SName
*
pTableName
,
SVgroupInfo
*
vgInfo
)
const
;
int32_t
catalogGetTableDistVgInfo
(
const
SName
*
pTableName
,
SArray
**
pVgList
)
const
;
int32_t
catalogGetDBVgInfo
(
const
char
*
pDbFName
,
SArray
**
pVgList
)
const
;
int32_t
catalogGetDBCfg
(
const
char
*
pDbFName
,
SDbCfgInfo
*
pDbCfg
)
const
;
int32_t
catalogGetUdfInfo
(
const
std
::
string
&
funcName
,
SFuncInfo
*
pInfo
)
const
;
int32_t
catalogGetTableIndex
(
const
SName
*
pTableName
,
SArray
**
pIndexes
)
const
;
int32_t
catalogGetDnodeList
(
SArray
**
pDnodes
)
const
;
...
...
source/libs/parser/test/parInitialATest.cpp
浏览文件 @
ac34cde0
...
...
@@ -38,9 +38,9 @@ TEST_F(ParserInitialATest, alterDnode) {
TEST_F
(
ParserInitialATest
,
alterDatabase
)
{
useDb
(
"root"
,
"test"
);
run
(
"ALTER DATABASE
wxy_db
CACHELAST 1 FSYNC 200 WAL 1"
);
run
(
"ALTER DATABASE
test
CACHELAST 1 FSYNC 200 WAL 1"
);
run
(
"ALTER DATABASE
wxy_db
KEEP 2400"
);
run
(
"ALTER DATABASE
test
KEEP 2400"
);
}
TEST_F
(
ParserInitialATest
,
alterLocal
)
{
...
...
source/libs/parser/test/parInitialCTest.cpp
浏览文件 @
ac34cde0
...
...
@@ -359,11 +359,11 @@ TEST_F(ParserInitialCTest, createStable) {
memset
(
&
expect
,
0
,
sizeof
(
SMCreateStbReq
));
};
auto
setCreateStbReqFunc
=
[
&
](
const
char
*
p
Tbname
,
int8_t
igExists
=
0
,
int64_t
delay1
=
-
1
,
int64_t
delay2
=
-
1
,
int64_t
watermark1
=
TSDB_DEFAULT_ROLLUP_WATERMARK
,
auto
setCreateStbReqFunc
=
[
&
](
const
char
*
p
DbName
,
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
,
int32_t
ttl
=
TSDB_DEFAULT_TABLE_TTL
,
const
char
*
pComment
=
nullptr
)
{
int32_t
len
=
snprintf
(
expect
.
name
,
sizeof
(
expect
.
name
),
"0.
test.%s"
,
pTbn
ame
);
int32_t
len
=
snprintf
(
expect
.
name
,
sizeof
(
expect
.
name
),
"0.
%s.%s"
,
pDbName
,
pTbN
ame
);
expect
.
name
[
len
]
=
'\0'
;
expect
.
igExists
=
igExists
;
expect
.
delay1
=
delay1
;
...
...
@@ -454,14 +454,14 @@ TEST_F(ParserInitialCTest, createStable) {
tFreeSMCreateStbReq
(
&
req
);
});
setCreateStbReqFunc
(
"t1"
);
setCreateStbReqFunc
(
"t
est"
,
"t
1"
);
addFieldToCreateStbReqFunc
(
true
,
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
);
addFieldToCreateStbReqFunc
(
true
,
"c1"
,
TSDB_DATA_TYPE_INT
);
addFieldToCreateStbReqFunc
(
false
,
"id"
,
TSDB_DATA_TYPE_INT
);
run
(
"CREATE STABLE t1(ts TIMESTAMP, c1 INT) TAGS(id INT)"
);
clearCreateStbReq
();
setCreateStbReqFunc
(
"t1"
,
1
,
100
*
MILLISECOND_PER_SECOND
,
10
*
MILLISECOND_PER_MINUTE
,
10
,
setCreateStbReqFunc
(
"
rollup_db"
,
"
t1"
,
1
,
100
*
MILLISECOND_PER_SECOND
,
10
*
MILLISECOND_PER_MINUTE
,
10
,
1
*
MILLISECOND_PER_MINUTE
,
100
,
"test create table"
);
addFieldToCreateStbReqFunc
(
true
,
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
,
0
,
0
);
addFieldToCreateStbReqFunc
(
true
,
"c1"
,
TSDB_DATA_TYPE_INT
);
...
...
@@ -493,7 +493,7 @@ TEST_F(ParserInitialCTest, createStable) {
addFieldToCreateStbReqFunc
(
false
,
"a13"
,
TSDB_DATA_TYPE_BOOL
);
addFieldToCreateStbReqFunc
(
false
,
"a14"
,
TSDB_DATA_TYPE_NCHAR
,
30
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
);
addFieldToCreateStbReqFunc
(
false
,
"a15"
,
TSDB_DATA_TYPE_VARCHAR
,
50
+
VARSTR_HEADER_SIZE
);
run
(
"CREATE STABLE IF NOT EXISTS
test
.t1("
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, "
"c13 NCHAR(30), c14 VARCHAR(50)) "
...
...
@@ -507,12 +507,13 @@ TEST_F(ParserInitialCTest, createStable) {
TEST_F
(
ParserInitialCTest
,
createStableSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
run
(
"CREATE STABLE stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(CEIL)"
,
TSDB_CODE_PAR_INVALID_ROLLUP_OPTION
);
run
(
"CREATE STABLE rollup_db.stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(CEIL)"
,
TSDB_CODE_PAR_INVALID_ROLLUP_OPTION
);
run
(
"CREATE STABLE stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(MAX) MAX_DELAY 0s WATERMARK 1m"
,
run
(
"CREATE STABLE
rollup_db.
stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(MAX) MAX_DELAY 0s WATERMARK 1m"
,
TSDB_CODE_PAR_INVALID_RANGE_OPTION
);
run
(
"CREATE STABLE stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(MAX) MAX_DELAY 10s WATERMARK 18m"
,
run
(
"CREATE STABLE
rollup_db.
stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(MAX) MAX_DELAY 10s WATERMARK 18m"
,
TSDB_CODE_PAR_INVALID_RANGE_OPTION
);
}
...
...
@@ -561,30 +562,33 @@ TEST_F(ParserInitialCTest, createStream) {
tFreeSCMCreateStreamReq
(
&
req
);
});
setCreateStreamReqFunc
(
"s1"
,
"test"
,
"create stream s1 as select
* from t1
"
);
run
(
"CREATE STREAM s1 AS SELECT
* FROM t1
"
);
setCreateStreamReqFunc
(
"s1"
,
"test"
,
"create stream s1 as select
count(*) from t1 interval(10s)
"
);
run
(
"CREATE STREAM s1 AS SELECT
COUNT(*) FROM t1 INTERVAL(10S)
"
);
clearCreateStreamReq
();
setCreateStreamReqFunc
(
"s1"
,
"test"
,
"create stream if not exists s1 as select * from t1"
,
nullptr
,
1
);
run
(
"CREATE STREAM IF NOT EXISTS s1 AS SELECT * FROM t1"
);
setCreateStreamReqFunc
(
"s1"
,
"test"
,
"create stream if not exists s1 as select count(*) from t1 interval(10s)"
,
nullptr
,
1
);
run
(
"CREATE STREAM IF NOT EXISTS s1 AS SELECT COUNT(*) FROM t1 INTERVAL(10S)"
);
clearCreateStreamReq
();
setCreateStreamReqFunc
(
"s1"
,
"test"
,
"create stream s1 into st1 as select
* from t1
"
,
"st1"
);
run
(
"CREATE STREAM s1 INTO st1 AS SELECT
* FROM t1
"
);
setCreateStreamReqFunc
(
"s1"
,
"test"
,
"create stream s1 into st1 as select
count(*) from t1 interval(10s)
"
,
"st1"
);
run
(
"CREATE STREAM s1 INTO st1 AS SELECT
COUNT(*) FROM t1 INTERVAL(10S)
"
);
clearCreateStreamReq
();
setCreateStreamReqFunc
(
"s1"
,
"test"
,
"create stream if not exists s1 trigger max_delay 20s watermark 10s ignore expired into st1 as select * from t1"
,
"st1"
,
1
,
STREAM_TRIGGER_MAX_DELAY
,
20
*
MILLISECOND_PER_SECOND
,
10
*
MILLISECOND_PER_SECOND
,
1
);
run
(
"CREATE STREAM IF NOT EXISTS s1 TRIGGER MAX_DELAY 20s WATERMARK 10s IGNORE EXPIRED INTO st1 AS SELECT * FROM t1"
);
setCreateStreamReqFunc
(
"s1"
,
"test"
,
"create stream if not exists s1 trigger max_delay 20s watermark 10s ignore expired into st1 "
"as select count(*) from t1 interval(10s)"
,
"st1"
,
1
,
STREAM_TRIGGER_MAX_DELAY
,
20
*
MILLISECOND_PER_SECOND
,
10
*
MILLISECOND_PER_SECOND
,
1
);
run
(
"CREATE STREAM IF NOT EXISTS s1 TRIGGER MAX_DELAY 20s WATERMARK 10s IGNORE EXPIRED INTO st1 AS SELECT COUNT(*) "
"FROM t1 INTERVAL(10S)"
);
clearCreateStreamReq
();
}
TEST_F
(
ParserInitialCTest
,
createStreamSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
run
(
"CREATE STREAM s1 AS SELECT PERCENTILE(c1, 30) FROM t1"
,
TSDB_CODE_PAR_STREAM_NOT_ALLOWED_FUNC
);
run
(
"CREATE STREAM s1 AS SELECT PERCENTILE(c1, 30) FROM t1
INTERVAL(10S)
"
,
TSDB_CODE_PAR_STREAM_NOT_ALLOWED_FUNC
);
}
TEST_F
(
ParserInitialCTest
,
createTable
)
{
...
...
@@ -598,7 +602,7 @@ TEST_F(ParserInitialCTest, createTable) {
"c13 NCHAR(30), c15 VARCHAR(50)) "
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)"
);
run
(
"CREATE TABLE IF NOT EXISTS
test
.t1("
run
(
"CREATE TABLE 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, "
"c13 NCHAR(30), c14 VARCHAR(50)) "
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录