Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5998f72b
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看板
提交
5998f72b
编写于
12月 01, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/fix/3.0_bugfix_wxy' into fix/TD-20848
上级
de87d901
4e8acca2
变更
19
展开全部
隐藏空白更改
内联
并排
Showing
19 changed file
with
3862 addition
and
3798 deletion
+3862
-3798
include/common/systable.h
include/common/systable.h
+1
-0
include/common/tmsg.h
include/common/tmsg.h
+13
-11
include/common/ttokendef.h
include/common/ttokendef.h
+278
-276
include/libs/nodes/cmdnodes.h
include/libs/nodes/cmdnodes.h
+5
-4
include/libs/nodes/nodes.h
include/libs/nodes/nodes.h
+1
-0
source/common/src/systable.c
source/common/src/systable.c
+7
-0
source/common/src/tmsg.c
source/common/src/tmsg.c
+2
-2
source/dnode/mnode/impl/src/mndUser.c
source/dnode/mnode/impl/src/mndUser.c
+16
-16
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+3
-1
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+3
-0
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+2
-2
source/libs/parser/src/parAstParser.c
source/libs/parser/src/parAstParser.c
+7
-0
source/libs/parser/src/parTokenizer.c
source/libs/parser/src/parTokenizer.c
+2
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+14
-3
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+3465
-3478
source/libs/parser/test/mockCatalog.cpp
source/libs/parser/test/mockCatalog.cpp
+6
-2
source/libs/parser/test/parAlterToBalanceTest.cpp
source/libs/parser/test/parAlterToBalanceTest.cpp
+2
-2
source/libs/parser/test/parExplainToSyncdbTest.cpp
source/libs/parser/test/parExplainToSyncdbTest.cpp
+28
-0
source/libs/parser/test/parShowToUse.cpp
source/libs/parser/test/parShowToUse.cpp
+7
-1
未找到文件。
include/common/systable.h
浏览文件 @
5998f72b
...
...
@@ -47,6 +47,7 @@ extern "C" {
#define TSDB_INS_TABLE_TOPICS "ins_topics"
#define TSDB_INS_TABLE_STREAMS "ins_streams"
#define TSDB_INS_TABLE_STREAM_TASKS "ins_stream_tasks"
#define TSDB_INS_TABLE_USER_PRIVILEGES "ins_user_privileges"
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
#define TSDB_PERFS_TABLE_SMAS "perf_smas"
...
...
include/common/tmsg.h
浏览文件 @
5998f72b
...
...
@@ -141,16 +141,18 @@ typedef enum _mgmt_table {
#define TSDB_FILL_PREV 4
#define TSDB_FILL_NEXT 5
#define TSDB_ALTER_USER_PASSWD 0x1
#define TSDB_ALTER_USER_SUPERUSER 0x2
#define TSDB_ALTER_USER_ADD_READ_DB 0x3
#define TSDB_ALTER_USER_REMOVE_READ_DB 0x4
#define TSDB_ALTER_USER_ADD_WRITE_DB 0x5
#define TSDB_ALTER_USER_REMOVE_WRITE_DB 0x6
#define TSDB_ALTER_USER_ADD_ALL_DB 0x7
#define TSDB_ALTER_USER_REMOVE_ALL_DB 0x8
#define TSDB_ALTER_USER_ENABLE 0x9
#define TSDB_ALTER_USER_SYSINFO 0xA
#define TSDB_ALTER_USER_PASSWD 0x1
#define TSDB_ALTER_USER_SUPERUSER 0x2
#define TSDB_ALTER_USER_ADD_READ_DB 0x3
#define TSDB_ALTER_USER_REMOVE_READ_DB 0x4
#define TSDB_ALTER_USER_ADD_WRITE_DB 0x5
#define TSDB_ALTER_USER_REMOVE_WRITE_DB 0x6
#define TSDB_ALTER_USER_ADD_ALL_DB 0x7
#define TSDB_ALTER_USER_REMOVE_ALL_DB 0x8
#define TSDB_ALTER_USER_ENABLE 0x9
#define TSDB_ALTER_USER_SYSINFO 0xA
#define TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC 0xB
#define TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC 0xC
#define TSDB_ALTER_USER_PRIVILEGES 0x2
...
...
@@ -620,7 +622,7 @@ typedef struct {
int8_t
enable
;
char
user
[
TSDB_USER_LEN
];
char
pass
[
TSDB_USET_PASSWORD_LEN
];
char
dbname
[
TSDB_DB_FNAME_LEN
];
char
objname
[
TSDB_DB_FNAME_LEN
];
// db or topic
}
SAlterUserReq
;
int32_t
tSerializeSAlterUserReq
(
void
*
buf
,
int32_t
bufLen
,
SAlterUserReq
*
pReq
);
...
...
include/common/ttokendef.h
浏览文件 @
5998f72b
此差异已折叠。
点击以展开。
include/libs/nodes/cmdnodes.h
浏览文件 @
5998f72b
...
...
@@ -42,9 +42,10 @@ extern "C" {
#define PRIVILEGE_TYPE_MASK(n) (1 << n)
#define PRIVILEGE_TYPE_ALL PRIVILEGE_TYPE_MASK(0)
#define PRIVILEGE_TYPE_READ PRIVILEGE_TYPE_MASK(1)
#define PRIVILEGE_TYPE_WRITE PRIVILEGE_TYPE_MASK(2)
#define PRIVILEGE_TYPE_ALL PRIVILEGE_TYPE_MASK(0)
#define PRIVILEGE_TYPE_READ PRIVILEGE_TYPE_MASK(1)
#define PRIVILEGE_TYPE_WRITE PRIVILEGE_TYPE_MASK(2)
#define PRIVILEGE_TYPE_SUBSCRIBE PRIVILEGE_TYPE_MASK(3)
#define PRIVILEGE_TYPE_TEST_MASK(val, mask) (((val) & (mask)) != 0)
...
...
@@ -423,7 +424,7 @@ typedef struct SDropFunctionStmt {
typedef
struct
SGrantStmt
{
ENodeType
type
;
char
userName
[
TSDB_USER_LEN
];
char
dbName
[
TSDB_DB_NAME_LEN
];
char
objName
[
TSDB_DB_NAME_LEN
];
// db or topic
int64_t
privileges
;
}
SGrantStmt
;
...
...
include/libs/nodes/nodes.h
浏览文件 @
5998f72b
...
...
@@ -187,6 +187,7 @@ typedef enum ENodeType {
QUERY_NODE_SHOW_TRANSACTIONS_STMT
,
QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT
,
QUERY_NODE_SHOW_VNODES_STMT
,
QUERY_NODE_SHOW_USER_PRIVILEGES_STMT
,
QUERY_NODE_SHOW_CREATE_DATABASE_STMT
,
QUERY_NODE_SHOW_CREATE_TABLE_STMT
,
QUERY_NODE_SHOW_CREATE_STABLE_STMT
,
...
...
source/common/src/systable.c
浏览文件 @
5998f72b
...
...
@@ -273,6 +273,12 @@ static const SSysDbTableSchema vnodesSchema[] = {
{.
name
=
"dnode_ep"
,
.
bytes
=
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
,
.
sysInfo
=
true
},
};
static
const
SSysDbTableSchema
userUserPrivilegesSchema
[]
=
{
{.
name
=
"user_name"
,
.
bytes
=
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
,
.
sysInfo
=
false
},
{.
name
=
"privilege"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
,
.
sysInfo
=
false
},
{.
name
=
"object_name"
,
.
bytes
=
TSDB_DB_NAME_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
,
.
sysInfo
=
false
},
};
static
const
SSysTableMeta
infosMeta
[]
=
{
{
TSDB_INS_TABLE_DNODES
,
dnodesSchema
,
tListLen
(
dnodesSchema
),
true
},
{
TSDB_INS_TABLE_MNODES
,
mnodesSchema
,
tListLen
(
mnodesSchema
),
true
},
...
...
@@ -297,6 +303,7 @@ static const SSysTableMeta infosMeta[] = {
{
TSDB_INS_TABLE_STREAMS
,
streamSchema
,
tListLen
(
streamSchema
),
false
},
{
TSDB_INS_TABLE_STREAM_TASKS
,
streamTaskSchema
,
tListLen
(
streamTaskSchema
),
false
},
{
TSDB_INS_TABLE_VNODES
,
vnodesSchema
,
tListLen
(
vnodesSchema
),
true
},
{
TSDB_INS_TABLE_USER_PRIVILEGES
,
userUserPrivilegesSchema
,
tListLen
(
userUserPrivilegesSchema
),
false
},
};
static
const
SSysDbTableSchema
connectionsSchema
[]
=
{
...
...
source/common/src/tmsg.c
浏览文件 @
5998f72b
...
...
@@ -1288,7 +1288,7 @@ int32_t tSerializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq)
if
(
tEncodeI8
(
&
encoder
,
pReq
->
enable
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
&
encoder
,
pReq
->
user
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
&
encoder
,
pReq
->
pass
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
&
encoder
,
pReq
->
db
name
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
&
encoder
,
pReq
->
obj
name
)
<
0
)
return
-
1
;
tEndEncode
(
&
encoder
);
int32_t
tlen
=
encoder
.
pos
;
...
...
@@ -1307,7 +1307,7 @@ int32_t tDeserializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq
if
(
tDecodeI8
(
&
decoder
,
&
pReq
->
enable
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
&
decoder
,
pReq
->
user
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
&
decoder
,
pReq
->
pass
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
&
decoder
,
pReq
->
db
name
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
&
decoder
,
pReq
->
obj
name
)
<
0
)
return
-
1
;
tEndDecode
(
&
decoder
);
tDecoderClear
(
&
decoder
);
...
...
source/dnode/mnode/impl/src/mndUser.c
浏览文件 @
5998f72b
...
...
@@ -507,14 +507,14 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
}
if
(
alterReq
.
alterType
==
TSDB_ALTER_USER_ADD_READ_DB
||
alterReq
.
alterType
==
TSDB_ALTER_USER_ADD_ALL_DB
)
{
if
(
strcmp
(
alterReq
.
db
name
,
"1.*"
)
!=
0
)
{
int32_t
len
=
strlen
(
alterReq
.
db
name
)
+
1
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
alterReq
.
db
name
);
if
(
strcmp
(
alterReq
.
obj
name
,
"1.*"
)
!=
0
)
{
int32_t
len
=
strlen
(
alterReq
.
obj
name
)
+
1
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
alterReq
.
obj
name
);
if
(
pDb
==
NULL
)
{
mndReleaseDb
(
pMnode
,
pDb
);
goto
_OVER
;
}
if
(
taosHashPut
(
newUser
.
readDbs
,
alterReq
.
dbname
,
len
,
alterReq
.
db
name
,
TSDB_DB_FNAME_LEN
)
!=
0
)
{
if
(
taosHashPut
(
newUser
.
readDbs
,
alterReq
.
objname
,
len
,
alterReq
.
obj
name
,
TSDB_DB_FNAME_LEN
)
!=
0
)
{
mndReleaseDb
(
pMnode
,
pDb
);
goto
_OVER
;
}
...
...
@@ -531,14 +531,14 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
}
if
(
alterReq
.
alterType
==
TSDB_ALTER_USER_ADD_WRITE_DB
||
alterReq
.
alterType
==
TSDB_ALTER_USER_ADD_ALL_DB
)
{
if
(
strcmp
(
alterReq
.
db
name
,
"1.*"
)
!=
0
)
{
int32_t
len
=
strlen
(
alterReq
.
db
name
)
+
1
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
alterReq
.
db
name
);
if
(
strcmp
(
alterReq
.
obj
name
,
"1.*"
)
!=
0
)
{
int32_t
len
=
strlen
(
alterReq
.
obj
name
)
+
1
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
alterReq
.
obj
name
);
if
(
pDb
==
NULL
)
{
mndReleaseDb
(
pMnode
,
pDb
);
goto
_OVER
;
}
if
(
taosHashPut
(
newUser
.
writeDbs
,
alterReq
.
dbname
,
len
,
alterReq
.
db
name
,
TSDB_DB_FNAME_LEN
)
!=
0
)
{
if
(
taosHashPut
(
newUser
.
writeDbs
,
alterReq
.
objname
,
len
,
alterReq
.
obj
name
,
TSDB_DB_FNAME_LEN
)
!=
0
)
{
mndReleaseDb
(
pMnode
,
pDb
);
goto
_OVER
;
}
...
...
@@ -555,28 +555,28 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
}
if
(
alterReq
.
alterType
==
TSDB_ALTER_USER_REMOVE_READ_DB
||
alterReq
.
alterType
==
TSDB_ALTER_USER_REMOVE_ALL_DB
)
{
if
(
strcmp
(
alterReq
.
db
name
,
"1.*"
)
!=
0
)
{
int32_t
len
=
strlen
(
alterReq
.
db
name
)
+
1
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
alterReq
.
db
name
);
if
(
strcmp
(
alterReq
.
obj
name
,
"1.*"
)
!=
0
)
{
int32_t
len
=
strlen
(
alterReq
.
obj
name
)
+
1
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
alterReq
.
obj
name
);
if
(
pDb
==
NULL
)
{
mndReleaseDb
(
pMnode
,
pDb
);
goto
_OVER
;
}
taosHashRemove
(
newUser
.
readDbs
,
alterReq
.
db
name
,
len
);
taosHashRemove
(
newUser
.
readDbs
,
alterReq
.
obj
name
,
len
);
}
else
{
taosHashClear
(
newUser
.
readDbs
);
}
}
if
(
alterReq
.
alterType
==
TSDB_ALTER_USER_REMOVE_WRITE_DB
||
alterReq
.
alterType
==
TSDB_ALTER_USER_REMOVE_ALL_DB
)
{
if
(
strcmp
(
alterReq
.
db
name
,
"1.*"
)
!=
0
)
{
int32_t
len
=
strlen
(
alterReq
.
db
name
)
+
1
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
alterReq
.
db
name
);
if
(
strcmp
(
alterReq
.
obj
name
,
"1.*"
)
!=
0
)
{
int32_t
len
=
strlen
(
alterReq
.
obj
name
)
+
1
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
alterReq
.
obj
name
);
if
(
pDb
==
NULL
)
{
mndReleaseDb
(
pMnode
,
pDb
);
goto
_OVER
;
}
taosHashRemove
(
newUser
.
writeDbs
,
alterReq
.
db
name
,
len
);
taosHashRemove
(
newUser
.
writeDbs
,
alterReq
.
obj
name
,
len
);
}
else
{
taosHashClear
(
newUser
.
writeDbs
);
}
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
5998f72b
...
...
@@ -424,6 +424,7 @@ SNode* nodesMakeNode(ENodeType type) {
case
QUERY_NODE_SHOW_TRANSACTIONS_STMT
:
case
QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT
:
case
QUERY_NODE_SHOW_TAGS_STMT
:
case
QUERY_NODE_SHOW_USER_PRIVILEGES_STMT
:
return
makeNode
(
type
,
sizeof
(
SShowStmt
));
case
QUERY_NODE_SHOW_TABLE_TAGS_STMT
:
return
makeNode
(
type
,
sizeof
(
SShowTableTagsStmt
));
...
...
@@ -943,7 +944,8 @@ void nodesDestroyNode(SNode* pNode) {
case
QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT
:
case
QUERY_NODE_SHOW_TRANSACTIONS_STMT
:
case
QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT
:
case
QUERY_NODE_SHOW_TAGS_STMT
:
{
case
QUERY_NODE_SHOW_TAGS_STMT
:
case
QUERY_NODE_SHOW_USER_PRIVILEGES_STMT
:
{
SShowStmt
*
pStmt
=
(
SShowStmt
*
)
pNode
;
nodesDestroyNode
(
pStmt
->
pDbName
);
nodesDestroyNode
(
pStmt
->
pTbName
);
...
...
source/libs/parser/inc/sql.y
浏览文件 @
5998f72b
...
...
@@ -101,6 +101,7 @@ cmd ::= REVOKE privileges(A) ON priv_level(B) FROM user_name(C).
%destructor privileges { }
privileges(A) ::= ALL. { A = PRIVILEGE_TYPE_ALL; }
privileges(A) ::= priv_type_list(B). { A = B; }
privileges(A) ::= SUBSCRIBE. { A = PRIVILEGE_TYPE_SUBSCRIBE; }
%type priv_type_list { int64_t }
%destructor priv_type_list { }
...
...
@@ -116,6 +117,7 @@ priv_type(A) ::= WRITE.
%destructor priv_level { }
priv_level(A) ::= NK_STAR(B) NK_DOT NK_STAR. { A = B; }
priv_level(A) ::= db_name(B) NK_DOT NK_STAR. { A = B; }
priv_level(A) ::= topic_name(B). { A = B; }
/************************************************ create/drop/alter dnode *********************************************/
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); }
...
...
@@ -393,6 +395,7 @@ col_name(A) ::= column_name(B).
/************************************************ show ****************************************************************/
cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); }
cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); }
cmd ::= SHOW USER PRIVILEGES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USER_PRIVILEGES_STMT); }
cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); }
cmd ::= SHOW db_name_cond_opt(A) TABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, A, B, OP_TYPE_LIKE); }
cmd ::= SHOW db_name_cond_opt(A) STABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, A, B, OP_TYPE_LIKE); }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
5998f72b
...
...
@@ -1815,7 +1815,7 @@ SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbN
SGrantStmt
*
pStmt
=
(
SGrantStmt
*
)
nodesMakeNode
(
QUERY_NODE_GRANT_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
privileges
=
privileges
;
COPY_STRING_FORM_ID_TOKEN
(
pStmt
->
db
Name
,
pDbName
);
COPY_STRING_FORM_ID_TOKEN
(
pStmt
->
obj
Name
,
pDbName
);
COPY_STRING_FORM_ID_TOKEN
(
pStmt
->
userName
,
pUserName
);
return
(
SNode
*
)
pStmt
;
}
...
...
@@ -1828,7 +1828,7 @@ SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDb
SRevokeStmt
*
pStmt
=
(
SRevokeStmt
*
)
nodesMakeNode
(
QUERY_NODE_REVOKE_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
privileges
=
privileges
;
COPY_STRING_FORM_ID_TOKEN
(
pStmt
->
db
Name
,
pDbName
);
COPY_STRING_FORM_ID_TOKEN
(
pStmt
->
obj
Name
,
pDbName
);
COPY_STRING_FORM_ID_TOKEN
(
pStmt
->
userName
,
pUserName
);
return
(
SNode
*
)
pStmt
;
}
...
...
source/libs/parser/src/parAstParser.c
浏览文件 @
5998f72b
...
...
@@ -504,6 +504,11 @@ static int32_t collectMetaKeyFromShowVnodes(SCollectMetaKeyCxt* pCxt, SShowVnode
pCxt
->
pMetaCache
);
}
static
int32_t
collectMetaKeyFromShowUserPrivileges
(
SCollectMetaKeyCxt
*
pCxt
,
SShowStmt
*
pStmt
)
{
return
reserveTableMetaInCache
(
pCxt
->
pParseCxt
->
acctId
,
TSDB_INFORMATION_SCHEMA_DB
,
TSDB_INS_TABLE_USER_PRIVILEGES
,
pCxt
->
pMetaCache
);
}
static
int32_t
collectMetaKeyFromShowCreateDatabase
(
SCollectMetaKeyCxt
*
pCxt
,
SShowCreateDatabaseStmt
*
pStmt
)
{
return
reserveDbCfgInCache
(
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
pCxt
->
pMetaCache
);
}
...
...
@@ -648,6 +653,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
return
collectMetaKeyFromShowDnodeVariables
(
pCxt
,
(
SShowDnodeVariablesStmt
*
)
pStmt
);
case
QUERY_NODE_SHOW_VNODES_STMT
:
return
collectMetaKeyFromShowVnodes
(
pCxt
,
(
SShowVnodesStmt
*
)
pStmt
);
case
QUERY_NODE_SHOW_USER_PRIVILEGES_STMT
:
return
collectMetaKeyFromShowUserPrivileges
(
pCxt
,
(
SShowStmt
*
)
pStmt
);
case
QUERY_NODE_SHOW_CREATE_DATABASE_STMT
:
return
collectMetaKeyFromShowCreateDatabase
(
pCxt
,
(
SShowCreateDatabaseStmt
*
)
pStmt
);
case
QUERY_NODE_SHOW_CREATE_TABLE_STMT
:
...
...
source/libs/parser/src/parTokenizer.c
浏览文件 @
5998f72b
...
...
@@ -161,6 +161,7 @@ static SKeyword keywordTable[] = {
{
"PPS"
,
TK_PPS
},
{
"PRECISION"
,
TK_PRECISION
},
{
"PREV"
,
TK_PREV
},
{
"PRIVILEGES"
,
TK_PRIVILEGES
},
{
"QNODE"
,
TK_QNODE
},
{
"QNODES"
,
TK_QNODES
},
{
"QTIME"
,
TK_QTIME
},
...
...
@@ -202,6 +203,7 @@ static SKeyword keywordTable[] = {
{
"STREAM"
,
TK_STREAM
},
{
"STREAMS"
,
TK_STREAMS
},
{
"STRICT"
,
TK_STRICT
},
{
"SUBSCRIBE"
,
TK_SUBSCRIBE
},
{
"SUBSCRIPTIONS"
,
TK_SUBSCRIPTIONS
},
{
"SUBTABLE"
,
TK_SUBTABLE
},
{
"SYSINFO"
,
TK_SYSINFO
},
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
5998f72b
...
...
@@ -251,6 +251,12 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
.
numOfShowCols
=
1
,
.
pShowCols
=
{
"*"
}
},
{
.
showType
=
QUERY_NODE_SHOW_USER_PRIVILEGES_STMT
,
.
pDbName
=
TSDB_INFORMATION_SCHEMA_DB
,
.
pTableName
=
TSDB_INS_TABLE_USER_PRIVILEGES
,
.
numOfShowCols
=
1
,
.
pShowCols
=
{
"*"
}
},
};
// clang-format on
...
...
@@ -5031,7 +5037,7 @@ static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt
alterReq
.
sysInfo
=
pStmt
->
sysinfo
;
snprintf
(
alterReq
.
pass
,
sizeof
(
alterReq
.
pass
),
"%s"
,
pStmt
->
password
);
if
(
NULL
!=
pCxt
->
pParseCxt
->
db
)
{
snprintf
(
alterReq
.
dbname
,
sizeof
(
alterReq
.
db
name
),
"%s"
,
pCxt
->
pParseCxt
->
db
);
snprintf
(
alterReq
.
objname
,
sizeof
(
alterReq
.
obj
name
),
"%s"
,
pCxt
->
pParseCxt
->
db
);
}
return
buildCmdMsg
(
pCxt
,
TDMT_MND_ALTER_USER
,
(
FSerializeFunc
)
tSerializeSAlterUserReq
,
&
alterReq
);
...
...
@@ -5710,9 +5716,11 @@ static int32_t translateGrant(STranslateContext* pCxt, SGrantStmt* pStmt) {
req
.
alterType
=
TSDB_ALTER_USER_ADD_READ_DB
;
}
else
if
(
PRIVILEGE_TYPE_TEST_MASK
(
pStmt
->
privileges
,
PRIVILEGE_TYPE_WRITE
))
{
req
.
alterType
=
TSDB_ALTER_USER_ADD_WRITE_DB
;
}
else
if
(
PRIVILEGE_TYPE_TEST_MASK
(
pStmt
->
privileges
,
PRIVILEGE_TYPE_SUBSCRIBE
))
{
req
.
alterType
=
TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC
;
}
strcpy
(
req
.
user
,
pStmt
->
userName
);
sprintf
(
req
.
dbname
,
"%d.%s"
,
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
db
Name
);
sprintf
(
req
.
objname
,
"%d.%s"
,
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
obj
Name
);
return
buildCmdMsg
(
pCxt
,
TDMT_MND_ALTER_USER
,
(
FSerializeFunc
)
tSerializeSAlterUserReq
,
&
req
);
}
...
...
@@ -5726,9 +5734,11 @@ static int32_t translateRevoke(STranslateContext* pCxt, SRevokeStmt* pStmt) {
req
.
alterType
=
TSDB_ALTER_USER_REMOVE_READ_DB
;
}
else
if
(
PRIVILEGE_TYPE_TEST_MASK
(
pStmt
->
privileges
,
PRIVILEGE_TYPE_WRITE
))
{
req
.
alterType
=
TSDB_ALTER_USER_REMOVE_WRITE_DB
;
}
else
if
(
PRIVILEGE_TYPE_TEST_MASK
(
pStmt
->
privileges
,
PRIVILEGE_TYPE_SUBSCRIBE
))
{
req
.
alterType
=
TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC
;
}
strcpy
(
req
.
user
,
pStmt
->
userName
);
sprintf
(
req
.
dbname
,
"%d.%s"
,
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
db
Name
);
sprintf
(
req
.
objname
,
"%d.%s"
,
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
obj
Name
);
return
buildCmdMsg
(
pCxt
,
TDMT_MND_ALTER_USER
,
(
FSerializeFunc
)
tSerializeSAlterUserReq
,
&
req
);
}
...
...
@@ -7504,6 +7514,7 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
case
QUERY_NODE_SHOW_CONSUMERS_STMT
:
case
QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT
:
case
QUERY_NODE_SHOW_TAGS_STMT
:
case
QUERY_NODE_SHOW_USER_PRIVILEGES_STMT
:
code
=
rewriteShow
(
pCxt
,
pQuery
);
break
;
case
QUERY_NODE_SHOW_VGROUPS_STMT
:
...
...
source/libs/parser/src/sql.c
浏览文件 @
5998f72b
此差异已折叠。
点击以展开。
source/libs/parser/test/mockCatalog.cpp
浏览文件 @
5998f72b
...
...
@@ -101,6 +101,10 @@ void generateInformationSchema(MockCatalogService* mcs) {
.
addColumn
(
"table_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_TABLE_NAME_LEN
)
.
addColumn
(
"db_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
)
.
done
();
mcs
->
createTableBuilder
(
TSDB_INFORMATION_SCHEMA_DB
,
TSDB_INS_TABLE_USER_PRIVILEGES
,
TSDB_SYSTEM_TABLE
,
2
)
.
addColumn
(
"user_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_USER_LEN
)
.
addColumn
(
"privilege"
,
TSDB_DATA_TYPE_BINARY
,
10
)
.
done
();
}
void
generatePerformanceSchema
(
MockCatalogService
*
mcs
)
{
...
...
@@ -248,8 +252,8 @@ int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, con
return
g_mockCatalogService
->
catalogGetTableDistVgInfo
(
pTableName
,
pVgList
);
}
int32_t
__catalogGetDBVgVersion
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
int32_t
*
version
,
int64_t
*
dbId
,
int
32_t
*
tableNum
,
int
64_t
*
stateTs
)
{
int32_t
__catalogGetDBVgVersion
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
int32_t
*
version
,
int64_t
*
dbId
,
int32_t
*
tableNum
,
int64_t
*
stateTs
)
{
return
0
;
}
...
...
source/libs/parser/test/parAlterToBalanceTest.cpp
浏览文件 @
5998f72b
...
...
@@ -613,7 +613,7 @@ TEST_F(ParserInitialATest, alterUser) {
if
(
nullptr
!=
pPass
)
{
strcpy
(
expect
.
pass
,
pPass
);
}
strcpy
(
expect
.
db
name
,
"test"
);
strcpy
(
expect
.
obj
name
,
"test"
);
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
...
...
@@ -627,7 +627,7 @@ TEST_F(ParserInitialATest, alterUser) {
ASSERT_EQ
(
req
.
enable
,
expect
.
enable
);
ASSERT_EQ
(
std
::
string
(
req
.
user
),
std
::
string
(
expect
.
user
));
ASSERT_EQ
(
std
::
string
(
req
.
pass
),
std
::
string
(
expect
.
pass
));
ASSERT_EQ
(
std
::
string
(
req
.
dbname
),
std
::
string
(
expect
.
db
name
));
ASSERT_EQ
(
std
::
string
(
req
.
objname
),
std
::
string
(
expect
.
obj
name
));
});
setAlterUserReq
(
"wxy"
,
TSDB_ALTER_USER_PASSWD
,
"123456"
);
...
...
source/libs/parser/test/parExplainToSyncdbTest.cpp
浏览文件 @
5998f72b
...
...
@@ -34,10 +34,38 @@ TEST_F(ParserExplainToSyncdbTest, explain) {
TEST_F
(
ParserExplainToSyncdbTest
,
grant
)
{
useDb
(
"root"
,
"test"
);
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_GRANT_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_ADD_ALL_DB
,
"wxy"
,
"0.test"
);
run
(
"GRANT ALL ON test.* TO wxy"
);
setAlterUserReq
(
TSDB_ALTER_USER_ADD_READ_DB
,
"wxy"
,
"0.test"
);
run
(
"GRANT READ ON test.* TO wxy"
);
setAlterUserReq
(
TSDB_ALTER_USER_ADD_WRITE_DB
,
"wxy"
,
"0.test"
);
run
(
"GRANT WRITE ON test.* TO wxy"
);
setAlterUserReq
(
TSDB_ALTER_USER_ADD_ALL_DB
,
"wxy"
,
"0.test"
);
run
(
"GRANT READ, WRITE ON test.* TO wxy"
);
setAlterUserReq
(
TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC
,
"wxy"
,
"0.tp1"
);
run
(
"GRANT SUBSCRIBE ON tp1 TO wxy"
);
}
TEST_F
(
ParserExplainToSyncdbTest
,
insert
)
{
...
...
source/libs/parser/test/parShowToUse.cpp
浏览文件 @
5998f72b
...
...
@@ -213,7 +213,13 @@ TEST_F(ParserShowToUseTest, showTags) {
TEST_F
(
ParserShowToUseTest
,
showUsers
)
{
useDb
(
"root"
,
"test"
);
run
(
"SHOW users"
);
run
(
"SHOW USERS"
);
}
TEST_F
(
ParserShowToUseTest
,
showUserPrivileges
)
{
useDb
(
"root"
,
"test"
);
run
(
"SHOW USER PRIVILEGES"
);
}
TEST_F
(
ParserShowToUseTest
,
showVariables
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录