Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f0044d82
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
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,发现更多精彩内容 >>
提交
f0044d82
编写于
12月 31, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-11818]support create multiple tables.
上级
df9e82ee
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
151 addition
and
79 deletion
+151
-79
include/common/tmsgtype.h
include/common/tmsgtype.h
+2
-1
include/libs/parser/parsenodes.h
include/libs/parser/parsenodes.h
+2
-2
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+1
-1
source/libs/parser/inc/parserInt.h
source/libs/parser/inc/parserInt.h
+3
-1
source/libs/parser/src/dCDAstProcess.c
source/libs/parser/src/dCDAstProcess.c
+96
-43
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+21
-8
source/libs/parser/test/parserTests.cpp
source/libs/parser/test/parserTests.cpp
+4
-6
source/libs/planner/inc/plannerInt.h
source/libs/planner/inc/plannerInt.h
+1
-1
source/libs/planner/src/logicPlan.c
source/libs/planner/src/logicPlan.c
+10
-5
source/libs/planner/src/physicalPlan.c
source/libs/planner/src/physicalPlan.c
+11
-11
未找到文件。
include/common/tmsgtype.h
浏览文件 @
f0044d82
...
...
@@ -40,8 +40,9 @@ enum {
// the SQL below is for mgmt node
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_MGMT
,
"mgmt"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_CREATE_DB
,
"create-db"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_CREATE_STABLE
,
"create-stable"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_CREATE_TABLE
,
"create-table"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_CREATE_FUNCTION
,
"create-function"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_CREATE_FUNCTION
,
"create-function"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_DROP_DB
,
"drop-db"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_DROP_TABLE
,
"drop-table"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_DROP_FUNCTION
,
"drop-function"
)
...
...
include/libs/parser/parsenodes.h
浏览文件 @
f0044d82
...
...
@@ -27,7 +27,7 @@ extern "C" {
#include "tname.h"
#include "tvariant.h"
/*
/*
*
* The first field of a node of any type is guaranteed to be the int16_t.
* Hence the type of any node can be gotten by casting it to SQueryNode.
*/
...
...
@@ -157,7 +157,7 @@ typedef struct SVgDataBlocks {
typedef
struct
SInsertStmtInfo
{
int16_t
nodeType
;
SArray
*
pDataBlocks
;
// data block for each vgroup, SArray<SVgDataBlocks*>.
int8_t
schemaAttache
;
// denote if submit block is built with table schema or not
int8_t
schemaAttache
;
// denote if submit block is built with table schema or not
uint8_t
payloadType
;
// EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
uint32_t
insertType
;
// insert data from [file|sql statement| bound statement]
const
char
*
sql
;
// current sql statement position
...
...
source/client/src/clientImpl.c
浏览文件 @
f0044d82
...
...
@@ -202,7 +202,7 @@ int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) {
}
int32_t
scheduleQuery
(
SRequestObj
*
pRequest
,
SQueryDag
*
pDag
,
void
**
pJob
)
{
if
(
TSDB_SQL_INSERT
==
pRequest
->
type
)
{
if
(
TSDB_SQL_INSERT
==
pRequest
->
type
||
TSDB_SQL_CREATE_TABLE
==
pRequest
->
type
)
{
return
scheduleExecJob
(
pRequest
->
pTscObj
->
pTransporter
,
NULL
/*todo appInfo.xxx*/
,
pDag
,
pJob
,
&
pRequest
->
affectedRows
);
}
return
scheduleAsyncExecJob
(
pRequest
->
pTscObj
->
pTransporter
,
NULL
/*todo appInfo.xxx*/
,
pDag
,
pJob
);
...
...
source/libs/parser/inc/parserInt.h
浏览文件 @
f0044d82
...
...
@@ -68,7 +68,9 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pSqlInfo, SQ
* @param type
* @return
*/
int32_t
qParserValidateDclSqlNode
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
SDclStmtInfo
*
pDcl
,
char
*
msgBuf
,
int32_t
msgBufLen
);
SDclStmtInfo
*
qParserValidateDclSqlNode
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
char
*
msgBuf
,
int32_t
msgBufLen
);
SInsertStmtInfo
*
qParserValidateCreateTbSqlNode
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
char
*
msgBuf
,
int32_t
msgBufLen
);
/**
* Evaluate the numeric and timestamp arithmetic expression in the WHERE clause.
...
...
source/libs/parser/src/dCDAstProcess.c
浏览文件 @
f0044d82
...
...
@@ -326,8 +326,7 @@ typedef struct SVgroupTablesBatch {
SVgroupInfo
info
;
}
SVgroupTablesBatch
;
int32_t
doCheckForCreateCTable
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
SMsgBuf
*
pMsgBuf
,
char
**
pOutput
,
int32_t
*
len
,
SEpSet
*
pEpSet
)
{
int32_t
doCheckForCreateCTable
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
SMsgBuf
*
pMsgBuf
,
char
**
pOutput
,
int32_t
*
len
)
{
const
char
*
msg1
=
"invalid table name"
;
const
char
*
msg2
=
"tags number not matched"
;
const
char
*
msg3
=
"tag value too long"
;
...
...
@@ -359,7 +358,11 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p
size_t
numOfInputTag
=
taosArrayGetSize
(
pValList
);
STableMeta
*
pSuperTableMeta
=
NULL
;
catalogGetTableMeta
(
pCtx
->
pCatalog
,
pCtx
->
pTransporter
,
&
pCtx
->
mgmtEpSet
,
&
name
,
&
pSuperTableMeta
);
code
=
catalogGetTableMeta
(
pCtx
->
pCatalog
,
pCtx
->
pTransporter
,
&
pCtx
->
mgmtEpSet
,
&
name
,
&
pSuperTableMeta
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
assert
(
pSuperTableMeta
!=
NULL
);
// too long tag values will return invalid sql, not be truncated automatically
...
...
@@ -501,14 +504,6 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p
req
.
ctbCfg
.
suid
=
pSuperTableMeta
->
suid
;
req
.
ctbCfg
.
pTag
=
row
;
// pEpSet->inUse = info.inUse;
// pEpSet->numOfEps = info.numOfEps;
// for (int32_t i = 0; i < pEpSet->numOfEps; ++i) {
// pEpSet->port[i] = info.epAddr[i].port;
// tstrncpy(pEpSet->fqdn[i], info.epAddr[i].fqdn, tListLen(pEpSet->fqdn[i]));
// }
// ((SMsgHead*)(*pOutput))->vgId = htonl(info.vgId);
// ((SMsgHead*)(*pOutput))->contLen = htonl(serLen);
SVgroupTablesBatch
*
pTableBatch
=
taosHashGet
(
pVgroupHashmap
,
&
info
.
vgId
,
sizeof
(
info
.
vgId
));
if
(
pTableBatch
==
NULL
)
{
SVgroupTablesBatch
tBatch
=
{
0
};
...
...
@@ -525,12 +520,12 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p
}
// TODO: serialize and
SArray
*
pBufArray
=
taosArrayInit
(
taosHashGetSize
(
pVgroupHashmap
),
sizeof
(
void
*
));
SVgroupTablesBatch
**
ppTbBatch
=
NULL
;
SArray
*
pBufArray
=
taosArrayInit
(
taosHashGetSize
(
pVgroupHashmap
),
sizeof
(
void
*
));
SVgroupTablesBatch
*
pTbBatch
=
NULL
;
do
{
ppTbBatch
=
taosHashIterate
(
pVgroupHashmap
,
ppTbBatch
);
if
(
ppTbBatch
==
NULL
)
break
;
SVgroupTablesBatch
*
pTbBatch
=
*
ppTbBatch
;
pTbBatch
=
taosHashIterate
(
pVgroupHashmap
,
pTbBatch
);
if
(
pTbBatch
==
NULL
)
break
;
int
tlen
=
sizeof
(
SMsgHead
)
+
tSVCreateTbBatchReqSerialize
(
NULL
,
&
(
pTbBatch
->
req
));
void
*
buf
=
malloc
(
tlen
);
...
...
@@ -544,17 +539,29 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p
void
*
pBuf
=
POINTER_SHIFT
(
buf
,
sizeof
(
SMsgHead
));
tSVCreateTbBatchReqSerialize
(
&
pBuf
,
&
(
pTbBatch
->
req
));
taosArrayPush
(
pBufArray
,
&
buf
);
SVgDataBlocks
*
pVgData
=
calloc
(
1
,
sizeof
(
SVgDataBlocks
));
pVgData
->
vg
=
pTbBatch
->
info
;
pVgData
->
pData
=
buf
;
pVgData
->
size
=
tlen
;
pVgData
->
numOfTables
=
(
int32_t
)
taosArrayGetSize
(
pTbBatch
->
req
.
pArray
);
taosArrayPush
(
pBufArray
,
&
pVgData
);
}
while
(
true
);
SInsertStmtInfo
*
pStmtInfo
=
calloc
(
1
,
sizeof
(
SInsertStmtInfo
));
pStmtInfo
->
nodeType
=
TSDB_SQL_CREATE_TABLE
;
pStmtInfo
->
pDataBlocks
=
pBufArray
;
*
pOutput
=
pStmtInfo
;
*
len
=
sizeof
(
SInsertStmtInfo
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
qParserValidateDclSqlNode
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
SDclStmtInfo
*
pDcl
,
char
*
msgBuf
,
int32_t
msgBufLen
)
{
SDclStmtInfo
*
qParserValidateDclSqlNode
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
char
*
msgBuf
,
int32_t
msgBufLen
)
{
int32_t
code
=
0
;
SDclStmtInfo
*
pDcl
=
calloc
(
1
,
sizeof
(
SDclStmtInfo
));
SMsgBuf
m
=
{.
buf
=
msgBuf
,
.
len
=
msgBufLen
};
SMsgBuf
*
pMsgBuf
=
&
m
;
...
...
@@ -571,21 +578,25 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
SToken
*
pPwd
=
&
pUser
->
passwd
;
if
(
pName
->
n
>=
TSDB_USER_LEN
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg3
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg3
);
goto
_error
;
}
if
(
parserValidateIdToken
(
pName
)
!=
TSDB_CODE_SUCCESS
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg2
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg2
);
goto
_error
;
}
if
(
pInfo
->
type
==
TSDB_SQL_CREATE_USER
)
{
if
(
parserValidatePassword
(
pPwd
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
code
=
TSDB_CODE_TSC_INVALID_OPERATION
;
goto
_error
;
}
}
else
{
if
(
pUser
->
type
==
TSDB_ALTER_USER_PASSWD
)
{
if
(
parserValidatePassword
(
pPwd
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
code
=
TSDB_CODE_TSC_INVALID_OPERATION
;
goto
_error
;
}
}
else
if
(
pUser
->
type
==
TSDB_ALTER_USER_PRIVILEGES
)
{
assert
(
pPwd
->
type
==
TSDB_DATA_TYPE_NULL
);
...
...
@@ -596,10 +607,12 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
}
else
if
(
strncasecmp
(
pPrivilege
->
z
,
"normal"
,
4
)
==
0
&&
pPrivilege
->
n
==
4
)
{
// pCmd->count = 2;
}
else
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg4
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg4
);
goto
_error
;
}
}
else
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
goto
_error
;
}
}
...
...
@@ -618,15 +631,18 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
SToken
*
pPwd
=
&
pInfo
->
pMiscInfo
->
user
.
passwd
;
if
(
parserValidatePassword
(
pPwd
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
code
=
TSDB_CODE_TSC_INVALID_OPERATION
;
goto
_error
;
}
if
(
pName
->
n
>=
TSDB_USER_LEN
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg3
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg3
);
goto
_error
;
}
if
(
parserValidateNameToken
(
pName
)
!=
TSDB_CODE_SUCCESS
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg2
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg2
);
goto
_error
;
}
SCreateAcctInfo
*
pAcctOpt
=
&
pInfo
->
pMiscInfo
->
acctOpt
;
...
...
@@ -636,7 +652,8 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
}
else
if
(
strncmp
(
pAcctOpt
->
stat
.
z
,
"all"
,
3
)
==
0
&&
pAcctOpt
->
stat
.
n
==
3
)
{
}
else
if
(
strncmp
(
pAcctOpt
->
stat
.
z
,
"no"
,
2
)
==
0
&&
pAcctOpt
->
stat
.
n
==
2
)
{
}
else
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
goto
_error
;
}
}
...
...
@@ -655,6 +672,10 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
case
TSDB_SQL_SHOW
:
{
SShowInfo
*
pShowInfo
=
&
pInfo
->
pMiscInfo
->
showOpt
;
code
=
setShowInfo
(
pShowInfo
,
pCtx
,
(
void
**
)
&
pDcl
->
pMsg
,
&
pDcl
->
msgLen
,
&
pDcl
->
epSet
,
&
pDcl
->
pExtension
,
pMsgBuf
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
pDcl
->
msgType
=
(
pShowInfo
->
showType
==
TSDB_MGMT_TABLE_TABLE
)
?
TDMT_VND_SHOW_TABLES
:
TDMT_MND_SHOW
;
break
;
}
...
...
@@ -664,13 +685,15 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
SToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
parserValidateNameToken
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
goto
_error
;
}
SName
n
=
{
0
};
int32_t
ret
=
tNameSetDbName
(
&
n
,
pCtx
->
acctId
,
pToken
->
z
,
pToken
->
n
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
goto
_error
;
}
SUseDbMsg
*
pUseDbMsg
=
(
SUseDbMsg
*
)
calloc
(
1
,
sizeof
(
SUseDbMsg
));
...
...
@@ -689,19 +712,22 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
SCreateDbInfo
*
pCreateDB
=
&
(
pInfo
->
pMiscInfo
->
dbOpt
);
if
(
pCreateDB
->
dbname
.
n
>=
TSDB_DB_NAME_LEN
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg2
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg2
);
goto
_error
;
}
char
buf
[
TSDB_DB_NAME_LEN
]
=
{
0
};
SToken
token
=
taosTokenDup
(
&
pCreateDB
->
dbname
,
buf
,
tListLen
(
buf
));
if
(
parserValidateNameToken
(
&
token
)
!=
TSDB_CODE_SUCCESS
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
goto
_error
;
}
SCreateDbMsg
*
pCreateMsg
=
buildCreateDbMsg
(
pCreateDB
,
pCtx
,
pMsgBuf
);
if
(
doCheckDbOptions
(
pCreateMsg
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
code
=
TSDB_CODE_TSC_INVALID_OPERATION
;
goto
_error
;
}
pDcl
->
pMsg
=
(
char
*
)
pCreateMsg
;
...
...
@@ -719,7 +745,8 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
SName
name
=
{
0
};
code
=
tNameSetDbName
(
&
name
,
pCtx
->
acctId
,
dbName
->
z
,
dbName
->
n
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
code
=
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
goto
_error
;
}
SDropDbMsg
*
pDropDbMsg
=
(
SDropDbMsg
*
)
calloc
(
1
,
sizeof
(
SDropDbMsg
));
...
...
@@ -731,7 +758,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
pDcl
->
msgType
=
TDMT_MND_DROP_DB
;
pDcl
->
msgLen
=
sizeof
(
SDropDbMsg
);
pDcl
->
pMsg
=
(
char
*
)
pDropDbMsg
;
return
TSDB_CODE_SUCCESS
;
break
;
}
case
TSDB_SQL_CREATE_TABLE
:
{
...
...
@@ -739,14 +766,16 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
if
(
pCreateTable
->
type
==
TSQL_CREATE_TABLE
||
pCreateTable
->
type
==
TSQL_CREATE_STABLE
)
{
if
((
code
=
doCheckForCreateTable
(
pInfo
,
pMsgBuf
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
terrno
=
code
;
goto
_error
;
}
pDcl
->
pMsg
=
(
char
*
)
buildCreateTableMsg
(
pCreateTable
,
&
pDcl
->
msgLen
,
pCtx
,
pMsgBuf
);
pDcl
->
msgType
=
(
pCreateTable
->
type
==
TSQL_CREATE_TABLE
)
?
TDMT_VND_CREATE_TABLE
:
TDMT_MND_CREATE_STB
;
}
else
if
(
pCreateTable
->
type
==
TSQL_CREATE_CTABLE
)
{
if
((
code
=
doCheckForCreateCTable
(
pInfo
,
pCtx
,
pMsgBuf
,
&
pDcl
->
pMsg
,
&
pDcl
->
msgLen
,
&
pDcl
->
epSet
))
!=
if
((
code
=
doCheckForCreateCTable
(
pInfo
,
pCtx
,
pMsgBuf
,
&
pDcl
->
pMsg
,
&
pDcl
->
msgLen
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
goto
_error
;
}
pDcl
->
msgType
=
TDMT_VND_CREATE_TABLE
;
...
...
@@ -761,7 +790,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
case
TSDB_SQL_DROP_TABLE
:
{
pDcl
->
pMsg
=
(
char
*
)
buildDropStableMsg
(
pInfo
,
&
pDcl
->
msgLen
,
pCtx
,
pMsgBuf
);
if
(
pDcl
->
pMsg
==
NULL
)
{
code
=
terrno
;
goto
_error
;
}
pDcl
->
msgType
=
TDMT_MND_DROP_STB
;
...
...
@@ -771,7 +800,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
case
TSDB_SQL_CREATE_DNODE
:
{
pDcl
->
pMsg
=
(
char
*
)
buildCreateDnodeMsg
(
pInfo
,
&
pDcl
->
msgLen
,
pMsgBuf
);
if
(
pDcl
->
pMsg
==
NULL
)
{
code
=
terrno
;
goto
_error
;
}
pDcl
->
msgType
=
TDMT_MND_CREATE_DNODE
;
...
...
@@ -781,7 +810,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
case
TSDB_SQL_DROP_DNODE
:
{
pDcl
->
pMsg
=
(
char
*
)
buildDropDnodeMsg
(
pInfo
,
&
pDcl
->
msgLen
,
pMsgBuf
);
if
(
pDcl
->
pMsg
==
NULL
)
{
code
=
terrno
;
goto
_error
;
}
pDcl
->
msgType
=
TDMT_MND_DROP_DNODE
;
...
...
@@ -792,5 +821,29 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SDclStm
break
;
}
return
code
;
return
pDcl
;
_error:
terrno
=
code
;
tfree
(
pDcl
);
return
NULL
;
}
SInsertStmtInfo
*
qParserValidateCreateTbSqlNode
(
SSqlInfo
*
pInfo
,
SParseBasicCtx
*
pCtx
,
char
*
msgBuf
,
int32_t
msgBufLen
)
{
SCreateTableSql
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
assert
(
pCreateTable
->
type
==
TSQL_CREATE_CTABLE
);
SMsgBuf
m
=
{.
buf
=
msgBuf
,
.
len
=
msgBufLen
};
SMsgBuf
*
pMsgBuf
=
&
m
;
SInsertStmtInfo
*
pInsertStmt
=
NULL
;
int32_t
msgLen
=
0
;
int32_t
code
=
doCheckForCreateCTable
(
pInfo
,
pCtx
,
pMsgBuf
,
(
char
**
)
&
pInsertStmt
,
&
msgLen
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tfree
(
pInsertStmt
);
return
NULL
;
}
return
pInsertStmt
;
}
\ No newline at end of file
source/libs/parser/src/parser.c
浏览文件 @
f0044d82
...
...
@@ -32,7 +32,7 @@ bool isInsertSql(const char* pStr, size_t length) {
}
bool
qIsDdlQuery
(
const
SQueryNode
*
pQuery
)
{
return
TSDB_SQL_INSERT
!=
pQuery
->
type
&&
TSDB_SQL_SELECT
!=
pQuery
->
type
;
return
TSDB_SQL_INSERT
!=
pQuery
->
type
&&
TSDB_SQL_SELECT
!=
pQuery
->
type
&&
TSDB_SQL_CREATE_TABLE
!=
pQuery
->
type
;
}
int32_t
parseQuerySql
(
SParseContext
*
pCxt
,
SQueryNode
**
pQuery
)
{
...
...
@@ -44,16 +44,29 @@ int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) {
}
if
(
!
isDqlSqlStatement
(
&
info
))
{
SDclStmtInfo
*
pDcl
=
calloc
(
1
,
sizeof
(
SDclStmtInfo
));
if
(
NULL
==
pDcl
)
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
// set correct error code.
return
terrno
;
bool
toVnode
=
false
;
if
(
info
.
type
==
TSDB_SQL_CREATE_TABLE
)
{
SCreateTableSql
*
pCreateSql
=
info
.
pCreateTableInfo
;
if
(
pCreateSql
->
type
==
TSQL_CREATE_CTABLE
||
pCreateSql
->
type
==
TSQL_CREATE_TABLE
)
{
toVnode
=
true
;
}
}
pDcl
->
nodeType
=
info
.
type
;
int32_t
code
=
qParserValidateDclSqlNode
(
&
info
,
&
pCxt
->
ctx
,
pDcl
,
pCxt
->
pMsg
,
pCxt
->
msgLen
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
if
(
toVnode
)
{
SInsertStmtInfo
*
pInsertInfo
=
qParserValidateCreateTbSqlNode
(
&
info
,
&
pCxt
->
ctx
,
pCxt
->
pMsg
,
pCxt
->
msgLen
);
if
(
pInsertInfo
==
NULL
)
{
return
terrno
;
}
*
pQuery
=
(
SQueryNode
*
)
pInsertInfo
;
}
else
{
SDclStmtInfo
*
pDcl
=
qParserValidateDclSqlNode
(
&
info
,
&
pCxt
->
ctx
,
pCxt
->
pMsg
,
pCxt
->
msgLen
);
if
(
pDcl
==
NULL
)
{
return
terrno
;
}
*
pQuery
=
(
SQueryNode
*
)
pDcl
;
pDcl
->
nodeType
=
info
.
type
;
}
}
else
{
SQueryStmtInfo
*
pQueryInfo
=
calloc
(
1
,
sizeof
(
SQueryStmtInfo
));
...
...
source/libs/parser/test/parserTests.cpp
浏览文件 @
f0044d82
...
...
@@ -714,10 +714,9 @@ TEST(testCase, show_user_Test) {
SSqlInfo
info1
=
doGenerateAST
(
sql1
);
ASSERT_EQ
(
info1
.
valid
,
true
);
SDclStmtInfo
output
;
SParseBasicCtx
ct
=
{.
requestId
=
1
,
.
acctId
=
1
,
.
db
=
"abc"
,
.
pTransporter
=
NULL
};
int32_t
code
=
qParserValidateDclSqlNode
(
&
info1
,
&
ct
,
&
outpu
t
,
msg
,
buf
.
len
);
ASSERT_
EQ
(
code
,
0
);
SDclStmtInfo
*
output
=
qParserValidateDclSqlNode
(
&
info1
,
&
c
t
,
msg
,
buf
.
len
);
ASSERT_
NE
(
output
,
nullptr
);
// convert the show command to be the select query
// select name, privilege, create_time, account from information_schema.users;
...
...
@@ -735,10 +734,9 @@ TEST(testCase, create_user_Test) {
ASSERT_EQ
(
info1
.
valid
,
true
);
ASSERT_EQ
(
isDclSqlStatement
(
&
info1
),
true
);
SDclStmtInfo
output
;
SParseBasicCtx
ct
=
{.
requestId
=
1
,
.
acctId
=
1
,
.
db
=
"abc"
};
int32_t
code
=
qParserValidateDclSqlNode
(
&
info1
,
&
ct
,
&
outpu
t
,
msg
,
buf
.
len
);
ASSERT_
EQ
(
code
,
0
);
SDclStmtInfo
*
output
=
qParserValidateDclSqlNode
(
&
info1
,
&
c
t
,
msg
,
buf
.
len
);
ASSERT_
NE
(
output
,
nullptr
);
destroySqlInfo
(
&
info1
);
}
\ No newline at end of file
source/libs/planner/inc/plannerInt.h
浏览文件 @
f0044d82
...
...
@@ -40,7 +40,7 @@ extern "C" {
#define QNODE_SESSIONWINDOW 12
#define QNODE_STATEWINDOW 13
#define QNODE_FILL 14
#define QNODE_
INSERT
15
#define QNODE_
MODIFY
15
typedef
struct
SQueryDistPlanNodeInfo
{
bool
stableQuery
;
// super table query or not
...
...
source/libs/planner/src/logicPlan.c
浏览文件 @
f0044d82
...
...
@@ -37,15 +37,19 @@ int32_t optimizeQueryPlan(struct SQueryPlanNode* pQueryNode) {
return
0
;
}
int32_t
createInsertPlan
(
const
SInsertStmtInfo
*
pInsert
,
SQueryPlanNode
**
pQueryPlan
)
{
static
int32_t
createInsertPlan
(
const
SQueryNode
*
pNode
,
SQueryPlanNode
**
pQueryPlan
)
{
SInsertStmtInfo
*
pInsert
=
(
SInsertStmtInfo
*
)
pNode
;
*
pQueryPlan
=
calloc
(
1
,
sizeof
(
SQueryPlanNode
));
SArray
*
blocks
=
taosArrayInit
(
taosArrayGetSize
(
pInsert
->
pDataBlocks
),
POINTER_BYTES
);
if
(
NULL
==
*
pQueryPlan
||
NULL
==
blocks
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
(
*
pQueryPlan
)
->
info
.
type
=
QNODE_INSERT
;
(
*
pQueryPlan
)
->
info
.
type
=
QNODE_MODIFY
;
taosArrayAddAll
(
blocks
,
pInsert
->
pDataBlocks
);
(
*
pQueryPlan
)
->
pExtInfo
=
blocks
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -62,13 +66,14 @@ int32_t createQueryPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) {
case
TSDB_SQL_SELECT
:
{
return
createSelectPlan
((
const
SQueryStmtInfo
*
)
pNode
,
pQueryPlan
);
}
case
TSDB_SQL_INSERT
:
return
createInsertPlan
((
const
SInsertStmtInfo
*
)
pNode
,
pQueryPlan
);
case
TSDB_SQL_CREATE_TABLE
:
return
createInsertPlan
(
pNode
,
pQueryPlan
);
default:
return
TSDB_CODE_FAILED
;
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
queryPlanToSql
(
struct
SQueryPlanNode
*
pQueryNode
,
char
**
sql
)
{
...
...
source/libs/planner/src/physicalPlan.c
浏览文件 @
f0044d82
...
...
@@ -34,7 +34,7 @@ static const char* gOpName[] = {
#undef INCLUDE_AS_NAME
};
static
void
*
va
i
lidPointer
(
void
*
p
)
{
static
void
*
validPointer
(
void
*
p
)
{
if
(
NULL
==
p
)
{
THROW
(
TSDB_CODE_TSC_OUT_OF_MEMORY
);
}
...
...
@@ -76,7 +76,7 @@ int32_t dsinkNameToDsinkType(const char* name) {
}
static
SDataSink
*
initDataSink
(
int32_t
type
,
int32_t
size
)
{
SDataSink
*
sink
=
(
SDataSink
*
)
va
i
lidPointer
(
calloc
(
1
,
size
));
SDataSink
*
sink
=
(
SDataSink
*
)
validPointer
(
calloc
(
1
,
size
));
sink
->
info
.
type
=
type
;
sink
->
info
.
name
=
dsinkTypeToDsinkName
(
type
);
return
sink
;
...
...
@@ -121,7 +121,7 @@ static bool cloneExprArray(SArray** dst, SArray* src) {
}
static
SPhyNode
*
initPhyNode
(
SQueryPlanNode
*
pPlanNode
,
int32_t
type
,
int32_t
size
)
{
SPhyNode
*
node
=
(
SPhyNode
*
)
va
i
lidPointer
(
calloc
(
1
,
size
));
SPhyNode
*
node
=
(
SPhyNode
*
)
validPointer
(
calloc
(
1
,
size
));
node
->
info
.
type
=
type
;
node
->
info
.
name
=
opTypeToOpName
(
type
);
if
(
!
cloneExprArray
(
&
node
->
pTargets
,
pPlanNode
->
pExpr
)
||
!
toDataBlockSchema
(
pPlanNode
,
&
(
node
->
targetSchema
)))
{
...
...
@@ -184,7 +184,7 @@ static SPhyNode* createMultiTableScanNode(SQueryPlanNode* pPlanNode, SQueryTable
}
static
SSubplan
*
initSubplan
(
SPlanContext
*
pCxt
,
int32_t
type
)
{
SSubplan
*
subplan
=
va
i
lidPointer
(
calloc
(
1
,
sizeof
(
SSubplan
)));
SSubplan
*
subplan
=
validPointer
(
calloc
(
1
,
sizeof
(
SSubplan
)));
subplan
->
id
=
pCxt
->
nextId
;
++
(
pCxt
->
nextId
.
subplanId
);
subplan
->
type
=
type
;
...
...
@@ -192,15 +192,15 @@ static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) {
if
(
NULL
!=
pCxt
->
pCurrentSubplan
)
{
subplan
->
level
=
pCxt
->
pCurrentSubplan
->
level
+
1
;
if
(
NULL
==
pCxt
->
pCurrentSubplan
->
pChildern
)
{
pCxt
->
pCurrentSubplan
->
pChildern
=
va
i
lidPointer
(
taosArrayInit
(
TARRAY_MIN_SIZE
,
POINTER_BYTES
));
pCxt
->
pCurrentSubplan
->
pChildern
=
validPointer
(
taosArrayInit
(
TARRAY_MIN_SIZE
,
POINTER_BYTES
));
}
taosArrayPush
(
pCxt
->
pCurrentSubplan
->
pChildern
,
&
subplan
);
subplan
->
pParents
=
va
i
lidPointer
(
taosArrayInit
(
TARRAY_MIN_SIZE
,
POINTER_BYTES
));
subplan
->
pParents
=
validPointer
(
taosArrayInit
(
TARRAY_MIN_SIZE
,
POINTER_BYTES
));
taosArrayPush
(
subplan
->
pParents
,
&
pCxt
->
pCurrentSubplan
);
}
SArray
*
currentLevel
;
if
(
subplan
->
level
>=
taosArrayGetSize
(
pCxt
->
pDag
->
pSubplans
))
{
currentLevel
=
va
i
lidPointer
(
taosArrayInit
(
TARRAY_MIN_SIZE
,
POINTER_BYTES
));
currentLevel
=
validPointer
(
taosArrayInit
(
TARRAY_MIN_SIZE
,
POINTER_BYTES
));
taosArrayPush
(
pCxt
->
pDag
->
pSubplans
,
&
currentLevel
);
}
else
{
currentLevel
=
taosArrayGetP
(
pCxt
->
pDag
->
pSubplans
,
subplan
->
level
);
...
...
@@ -272,7 +272,7 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) {
case
QNODE_TABLESCAN
:
node
=
createTableScanNode
(
pCxt
,
pPlanNode
);
break
;
case
QNODE_
INSERT
:
case
QNODE_
MODIFY
:
// Insert is not an operator in a physical plan.
break
;
default:
...
...
@@ -306,7 +306,7 @@ static void splitInsertSubplan(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) {
}
static
void
createSubplanByLevel
(
SPlanContext
*
pCxt
,
SQueryPlanNode
*
pRoot
)
{
if
(
QNODE_
INSERT
==
pRoot
->
info
.
type
)
{
if
(
QNODE_
MODIFY
==
pRoot
->
info
.
type
)
{
splitInsertSubplan
(
pCxt
,
pRoot
);
}
else
{
SSubplan
*
subplan
=
initSubplan
(
pCxt
,
QUERY_TYPE_MERGE
);
...
...
@@ -321,12 +321,12 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD
TRY
(
TSDB_MAX_TAG_CONDITIONS
)
{
SPlanContext
context
=
{
.
pCatalog
=
pCatalog
,
.
pDag
=
va
i
lidPointer
(
calloc
(
1
,
sizeof
(
SQueryDag
))),
.
pDag
=
validPointer
(
calloc
(
1
,
sizeof
(
SQueryDag
))),
.
pCurrentSubplan
=
NULL
,
.
nextId
=
{
0
}
// todo queryid
};
*
pDag
=
context
.
pDag
;
context
.
pDag
->
pSubplans
=
va
i
lidPointer
(
taosArrayInit
(
TARRAY_MIN_SIZE
,
POINTER_BYTES
));
context
.
pDag
->
pSubplans
=
validPointer
(
taosArrayInit
(
TARRAY_MIN_SIZE
,
POINTER_BYTES
));
createSubplanByLevel
(
&
context
,
pQueryNode
);
}
CATCH
(
code
)
{
CLEANUP_EXECUTE
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录