Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0c82c253
T
TDengine
项目概览
taosdata
/
TDengine
11 个月 前同步成功
通知
1179
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0c82c253
编写于
12月 23, 2021
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-12450 perfect parser interface
上级
53928fff
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
70 addition
and
85 deletion
+70
-85
include/libs/parser/parsenodes.h
include/libs/parser/parsenodes.h
+6
-0
include/libs/parser/parser.h
include/libs/parser/parser.h
+2
-18
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+23
-28
source/libs/parser/inc/parserInt.h
source/libs/parser/inc/parserInt.h
+1
-1
source/libs/parser/src/astValidate.c
source/libs/parser/src/astValidate.c
+11
-11
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+22
-10
source/libs/parser/test/parserTests.cpp
source/libs/parser/test/parserTests.cpp
+4
-10
source/libs/planner/test/phyPlanTests.cpp
source/libs/planner/test/phyPlanTests.cpp
+1
-7
未找到文件。
include/libs/parser/parsenodes.h
浏览文件 @
0c82c253
...
...
@@ -160,6 +160,12 @@ typedef struct SInsertStmtInfo {
const
char
*
sql
;
// current sql statement position
}
SInsertStmtInfo
;
typedef
struct
SDclStmtInfo
{
int16_t
nodeType
;
char
*
pMsg
;
int32_t
msgLen
;
}
SDclStmtInfo
;
#ifdef __cplusplus
}
#endif
...
...
include/libs/parser/parser.h
浏览文件 @
0c82c253
...
...
@@ -22,14 +22,6 @@ extern "C" {
#include "parsenodes.h"
/**
* True will be returned if the input sql string is insert, false otherwise.
* @param pStr sql string
* @param length length of the sql string
* @return
*/
bool
qIsInsertSql
(
const
char
*
pStr
,
size_t
length
);
typedef
struct
SParseContext
{
SParseBasicCtx
ctx
;
void
*
pRpc
;
...
...
@@ -50,17 +42,9 @@ typedef struct SParseContext {
* @param msg extended error message if exists.
* @return error code
*/
int32_t
qParseQuerySql
(
const
char
*
pStr
,
size_t
length
,
SParseBasicCtx
*
pParseCtx
,
int32_t
*
type
,
void
**
pOutput
,
int32_t
*
outputLen
,
char
*
msg
,
int32_t
msgLen
);
int32_t
qParseQuerySql
(
SParseContext
*
pContext
,
SQueryNode
**
pQuery
);
/**
* Parse the insert sql statement.
* @param pStr sql string
* @param length length of the sql string
* @param id operator id, generated by uuid generator.
* @param msg extended error message if exists to help avoid the problem in sql statement.
* @return data in binary format to submit to vnode directly.
*/
int32_t
qParseInsertSql
(
SParseContext
*
pContext
,
struct
SInsertStmtInfo
**
pInfo
);
bool
qIsDclQuery
(
const
SQueryNode
*
pQuery
);
/**
* Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that
...
...
source/client/src/clientImpl.c
浏览文件 @
0c82c253
...
...
@@ -144,37 +144,32 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
tscDebugL
(
"0x%"
PRIx64
" SQL: %s"
,
pRequest
->
requestId
,
pRequest
->
sqlstr
);
int32_t
code
=
0
;
if
(
qIsInsertSql
(
pRequest
->
sqlstr
,
sqlLen
))
{
// todo add
}
else
{
int32_t
type
=
0
;
void
*
output
=
NULL
;
int32_t
outputLen
=
0
;
SParseBasicCtx
c
=
{.
requestId
=
pRequest
->
requestId
,
.
acctId
=
pTscObj
->
acctId
,
.
db
=
getConnectionDB
(
pTscObj
)};
code
=
qParseQuerySql
(
pRequest
->
sqlstr
,
sqlLen
,
&
c
,
&
type
,
&
output
,
&
outputLen
,
pRequest
->
msgBuf
,
ERROR_MSG_BUF_DEFAULT_SIZE
);
if
(
type
==
TSDB_SQL_CREATE_USER
||
type
==
TSDB_SQL_SHOW
||
type
==
TSDB_SQL_DROP_USER
||
type
==
TSDB_SQL_DROP_ACCT
||
type
==
TSDB_SQL_CREATE_DB
||
type
==
TSDB_SQL_CREATE_ACCT
||
type
==
TSDB_SQL_CREATE_TABLE
||
type
==
TSDB_SQL_USE_DB
)
{
pRequest
->
type
=
type
;
pRequest
->
body
.
requestMsg
=
(
SReqMsgInfo
){.
pMsg
=
output
,
.
len
=
outputLen
};
SRequestMsgBody
body
=
{
0
};
buildRequestMsgFp
[
type
](
pRequest
,
&
body
);
int64_t
transporterId
=
0
;
sendMsgToServer
(
pTscObj
->
pTransporter
,
&
pTscObj
->
pAppInfo
->
mgmtEp
.
epSet
,
&
body
,
&
transporterId
);
tsem_wait
(
&
pRequest
->
body
.
rspSem
);
destroyRequestMsgBody
(
&
body
);
}
else
{
assert
(
0
);
}
SParseContext
cxt
=
{
.
ctx
=
{.
requestId
=
pRequest
->
requestId
,
.
acctId
=
pTscObj
->
acctId
,
.
db
=
getConnectionDB
(
pTscObj
)},
.
pSql
=
pRequest
->
sqlstr
,
.
sqlLen
=
sqlLen
,
.
pMsg
=
pRequest
->
msgBuf
,
.
msgLen
=
ERROR_MSG_BUF_DEFAULT_SIZE
};
SQueryNode
*
pQuery
=
NULL
;
int32_t
code
=
qParseQuerySql
(
&
cxt
,
&
pQuery
);
if
(
qIsDclQuery
(
pQuery
))
{
SDclStmtInfo
*
pDcl
=
(
SDclStmtInfo
*
)
pQuery
;
pRequest
->
type
=
pDcl
->
nodeType
;
pRequest
->
body
.
requestMsg
=
(
SReqMsgInfo
){.
pMsg
=
pDcl
->
pMsg
,
.
len
=
pDcl
->
msgLen
};
tfree
(
c
.
db
);
SRequestMsgBody
body
=
{
0
};
buildRequestMsgFp
[
pDcl
->
nodeType
](
pRequest
,
&
body
);
int64_t
transporterId
=
0
;
sendMsgToServer
(
pTscObj
->
pTransporter
,
&
pTscObj
->
pAppInfo
->
mgmtEp
.
epSet
,
&
body
,
&
transporterId
);
tsem_wait
(
&
pRequest
->
body
.
rspSem
);
destroyRequestMsgBody
(
&
body
);
}
tfree
(
cxt
.
ctx
.
db
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pRequest
->
code
=
code
;
return
pRequest
;
...
...
source/libs/parser/inc/parserInt.h
浏览文件 @
0c82c253
...
...
@@ -68,7 +68,7 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pSqlInfo, SQ
* @param type
* @return
*/
int32_t
qParserValidateDclSqlNode
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
void
**
output
,
int32_t
*
outputLen
,
int32_t
*
type
,
char
*
msgBuf
,
int32_t
msgBufLen
);
int32_t
qParserValidateDclSqlNode
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
SDclStmtInfo
*
pDcl
,
char
*
msgBuf
,
int32_t
msgBufLen
);
/**
* Evaluate the numeric and timestamp arithmetic expression in the WHERE clause.
...
...
source/libs/parser/src/astValidate.c
浏览文件 @
0c82c253
...
...
@@ -4308,13 +4308,13 @@ int32_t doCheckForCreateTable(SSqlInfo* pInfo, SMsgBuf* pMsgBuf) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
qParserValidateDclSqlNode
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
void
**
output
,
int32_t
*
outputLen
,
int32_t
*
type
,
char
*
msgBuf
,
int32_t
msgBufLen
)
{
int32_t
qParserValidateDclSqlNode
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
SDclStmtInfo
*
pDcl
,
char
*
msgBuf
,
int32_t
msgBufLen
)
{
int32_t
code
=
0
;
SMsgBuf
m
=
{.
buf
=
msgBuf
,
.
len
=
msgBufLen
};
SMsgBuf
*
pMsgBuf
=
&
m
;
*
t
ype
=
pInfo
->
type
;
pDcl
->
nodeT
ype
=
pInfo
->
type
;
switch
(
pInfo
->
type
)
{
case
TSDB_SQL_CREATE_USER
:
...
...
@@ -4361,7 +4361,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
}
}
*
output
=
buildUserManipulationMsg
(
pInfo
,
output
Len
,
pCtx
->
requestId
,
msgBuf
,
msgBufLen
);
pDcl
->
pMsg
=
(
char
*
)
buildUserManipulationMsg
(
pInfo
,
&
pDcl
->
msg
Len
,
pCtx
->
requestId
,
msgBuf
,
msgBufLen
);
break
;
}
...
...
@@ -4397,18 +4397,18 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
}
}
*
output
=
buildAcctManipulationMsg
(
pInfo
,
output
Len
,
pCtx
->
requestId
,
msgBuf
,
msgBufLen
);
pDcl
->
pMsg
=
(
char
*
)
buildAcctManipulationMsg
(
pInfo
,
&
pDcl
->
msg
Len
,
pCtx
->
requestId
,
msgBuf
,
msgBufLen
);
break
;
}
case
TSDB_SQL_DROP_ACCT
:
case
TSDB_SQL_DROP_USER
:
{
*
output
=
buildDropUserMsg
(
pInfo
,
output
Len
,
pCtx
->
requestId
,
msgBuf
,
msgBufLen
);
pDcl
->
pMsg
=
(
char
*
)
buildDropUserMsg
(
pInfo
,
&
pDcl
->
msg
Len
,
pCtx
->
requestId
,
msgBuf
,
msgBufLen
);
break
;
}
case
TSDB_SQL_SHOW
:
{
code
=
setShowInfo
(
pInfo
,
output
,
output
Len
,
pMsgBuf
);
code
=
setShowInfo
(
pInfo
,
(
void
**
)
&
pDcl
->
pMsg
,
&
pDcl
->
msg
Len
,
pMsgBuf
);
break
;
}
...
...
@@ -4429,8 +4429,8 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
SUseDbMsg
*
pUseDbMsg
=
(
SUseDbMsg
*
)
calloc
(
1
,
sizeof
(
SUseDbMsg
));
tNameExtractFullName
(
&
n
,
pUseDbMsg
->
db
);
*
output
=
pUseDbMsg
;
*
output
Len
=
sizeof
(
SUseDbMsg
);
pDcl
->
pMsg
=
(
char
*
)
pUseDbMsg
;
pDcl
->
msg
Len
=
sizeof
(
SUseDbMsg
);
break
;
}
...
...
@@ -4458,8 +4458,8 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
strncpy
(
pCreateMsg
->
db
,
token
.
z
,
token
.
n
);
*
output
=
pCreateMsg
;
*
output
Len
=
sizeof
(
SCreateDbMsg
);
pDcl
->
pMsg
=
(
char
*
)
pCreateMsg
;
pDcl
->
msg
Len
=
sizeof
(
SCreateDbMsg
);
break
;
}
...
...
@@ -4470,7 +4470,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
if
((
code
=
doCheckForCreateTable
(
pInfo
,
pMsgBuf
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
*
output
=
buildCreateTableMsg
(
pCreateTable
,
output
Len
,
pCtx
,
pMsgBuf
);
pDcl
->
pMsg
=
(
char
*
)
buildCreateTableMsg
(
pCreateTable
,
&
pDcl
->
msg
Len
,
pCtx
,
pMsgBuf
);
}
else
if
(
pCreateTable
->
type
==
TSQL_CREATE_CTABLE
)
{
// if ((code = doCheckForCreateFromStable(pSql, pInfo)) != TSDB_CODE_SUCCESS) {
// return code;
...
...
source/libs/parser/src/parser.c
浏览文件 @
0c82c253
...
...
@@ -20,7 +20,7 @@
#include "function.h"
#include "insertParser.h"
bool
qI
sInsertSql
(
const
char
*
pStr
,
size_t
length
)
{
bool
i
sInsertSql
(
const
char
*
pStr
,
size_t
length
)
{
int32_t
index
=
0
;
do
{
...
...
@@ -31,18 +31,26 @@ bool qIsInsertSql(const char* pStr, size_t length) {
}
while
(
1
);
}
int32_t
qParseQuerySql
(
const
char
*
pStr
,
size_t
length
,
SParseBasicCtx
*
pParseCtx
,
int32_t
*
type
,
void
**
pOutput
,
int32_t
*
outputLen
,
char
*
msg
,
int32_t
msgLen
)
{
SSqlInfo
info
=
doGenerateAST
(
pStr
);
bool
qIsDclQuery
(
const
SQueryNode
*
pQuery
)
{
int16_t
type
=
pQuery
->
type
;
return
type
==
TSDB_SQL_CREATE_USER
||
type
==
TSDB_SQL_SHOW
||
type
==
TSDB_SQL_DROP_USER
||
type
==
TSDB_SQL_DROP_ACCT
||
type
==
TSDB_SQL_CREATE_DB
||
type
==
TSDB_SQL_CREATE_ACCT
||
type
==
TSDB_SQL_CREATE_TABLE
||
type
==
TSDB_SQL_USE_DB
;
}
int32_t
parseQuerySql
(
SParseContext
*
pCxt
,
SQueryNode
**
pQuery
)
{
SSqlInfo
info
=
doGenerateAST
(
pCxt
->
pSql
);
if
(
!
info
.
valid
)
{
strncpy
(
msg
,
info
.
msg
,
msgLen
);
strncpy
(
pCxt
->
pMsg
,
info
.
msg
,
pCxt
->
msgLen
);
terrno
=
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
return
terrno
;
}
if
(
!
isDqlSqlStatement
(
&
info
))
{
int32_t
code
=
qParserValidateDclSqlNode
(
&
info
,
pParseCtx
,
pOutput
,
outputLen
,
type
,
msg
,
msgLen
);
SDclStmtInfo
*
pDcl
=
calloc
(
1
,
sizeof
(
SQueryStmtInfo
));
int32_t
code
=
qParserValidateDclSqlNode
(
&
info
,
&
pCxt
->
ctx
,
pDcl
,
pCxt
->
pMsg
,
pCxt
->
msgLen
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
// do nothing
*
pQuery
=
(
SQueryNode
*
)
pDcl
;
}
}
else
{
SQueryStmtInfo
*
pQueryInfo
=
calloc
(
1
,
sizeof
(
SQueryStmtInfo
));
...
...
@@ -53,9 +61,9 @@ int32_t qParseQuerySql(const char* pStr, size_t length, SParseBasicCtx* pParseCt
struct
SCatalog
*
pCatalog
=
NULL
;
int32_t
code
=
catalogGetHandle
(
NULL
,
&
pCatalog
);
code
=
qParserValidateSqlNode
(
pCatalog
,
&
info
,
pQueryInfo
,
p
ParseCtx
->
requestId
,
msg
,
msgLen
);
code
=
qParserValidateSqlNode
(
pCatalog
,
&
info
,
pQueryInfo
,
p
Cxt
->
ctx
.
requestId
,
pCxt
->
pMsg
,
pCxt
->
msgLen
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
*
p
Output
=
pQueryInfo
;
*
p
Query
=
(
SQueryNode
*
)
pQueryInfo
;
}
}
...
...
@@ -63,8 +71,12 @@ int32_t qParseQuerySql(const char* pStr, size_t length, SParseBasicCtx* pParseCt
return
TSDB_CODE_SUCCESS
;
}
int32_t
qParseInsertSql
(
SParseContext
*
pContext
,
SInsertStmtInfo
**
pInfo
)
{
return
parseInsertSql
(
pContext
,
pInfo
);
int32_t
qParseQuerySql
(
SParseContext
*
pCxt
,
SQueryNode
**
pQuery
)
{
if
(
isInsertSql
(
pCxt
->
pSql
,
pCxt
->
sqlLen
))
{
return
parseInsertSql
(
pCxt
,
(
SInsertStmtInfo
**
)
pQuery
);
}
else
{
return
parseQuerySql
(
pCxt
,
pQuery
);
}
}
int32_t
qParserConvertSql
(
const
char
*
pStr
,
size_t
length
,
char
**
pConvertSql
)
{
...
...
source/libs/parser/test/parserTests.cpp
浏览文件 @
0c82c253
...
...
@@ -714,12 +714,9 @@ TEST(testCase, show_user_Test) {
SSqlInfo
info1
=
doGenerateAST
(
sql1
);
ASSERT_EQ
(
info1
.
valid
,
true
);
void
*
output
=
NULL
;
int32_t
type
=
0
;
int32_t
len
=
0
;
SDclStmtInfo
output
;
SParseBasicCtx
ct
=
{.
db
=
"abc"
,
.
acctId
=
1
,
.
requestId
=
1
};
int32_t
code
=
qParserValidateDclSqlNode
(
&
info1
,
&
ct
,
&
output
,
&
len
,
&
type
,
msg
,
buf
.
len
);
int32_t
code
=
qParserValidateDclSqlNode
(
&
info1
,
&
ct
,
&
output
,
msg
,
buf
.
len
);
ASSERT_EQ
(
code
,
0
);
// convert the show command to be the select query
...
...
@@ -738,12 +735,9 @@ TEST(testCase, create_user_Test) {
ASSERT_EQ
(
info1
.
valid
,
true
);
ASSERT_EQ
(
isDclSqlStatement
(
&
info1
),
true
);
void
*
output
=
NULL
;
int32_t
type
=
0
;
int32_t
len
=
0
;
SDclStmtInfo
output
;
SParseBasicCtx
ct
=
{.
db
=
"abc"
,
.
acctId
=
1
,
.
requestId
=
1
};
int32_t
code
=
qParserValidateDclSqlNode
(
&
info1
,
&
ct
,
&
output
,
&
len
,
&
type
,
msg
,
buf
.
len
);
int32_t
code
=
qParserValidateDclSqlNode
(
&
info1
,
&
ct
,
&
output
,
msg
,
buf
.
len
);
ASSERT_EQ
(
code
,
0
);
destroySqlInfo
(
&
info1
);
...
...
source/libs/planner/test/phyPlanTests.cpp
浏览文件 @
0c82c253
...
...
@@ -51,16 +51,10 @@ protected:
}
int32_t
run
(
const
string
&
db
,
const
string
&
sql
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
SParseContext
cxt
;
buildParseContext
(
db
,
sql
,
&
cxt
);
SQueryNode
*
query
;
if
(
qIsInsertSql
(
cxt
.
pSql
,
cxt
.
sqlLen
))
{
code
=
qParseInsertSql
(
&
cxt
,
(
SInsertStmtInfo
**
)
&
query
);
}
else
{
// todo
code
=
TSDB_CODE_FAILED
;
}
int32_t
code
=
qParseQuerySql
(
&
cxt
,
&
query
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
cout
<<
"error no:"
<<
code
<<
", msg:"
<<
cxt
.
pMsg
<<
endl
;
return
code
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录