Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
784975da
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看板
未验证
提交
784975da
编写于
12月 23, 2021
作者:
S
Shengliang Guan
提交者:
GitHub
12月 23, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9320 from taosdata/feature/3.0_liaohj
Feature/3.0 liaohj
上级
1ce9487f
3d2e4569
变更
21
展开全部
隐藏空白更改
内联
并排
Showing
21 changed file
with
2071 addition
and
1998 deletion
+2071
-1998
include/common/taosmsg.h
include/common/taosmsg.h
+15
-6
include/libs/catalog/catalog.h
include/libs/catalog/catalog.h
+2
-2
include/libs/parser/parsenodes.h
include/libs/parser/parsenodes.h
+1
-1
include/libs/qcom/query.h
include/libs/qcom/query.h
+1
-1
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+3
-4
source/client/src/clientEnv.c
source/client/src/clientEnv.c
+13
-4
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+48
-19
source/client/src/clientMsgHandler.c
source/client/src/clientMsgHandler.c
+40
-86
source/client/test/clientTests.cpp
source/client/test/clientTests.cpp
+211
-90
source/libs/catalog/inc/catalogInt.h
source/libs/catalog/inc/catalogInt.h
+0
-3
source/libs/catalog/src/catalog.c
source/libs/catalog/src/catalog.c
+3
-3
source/libs/catalog/test/catalogTests.cpp
source/libs/catalog/test/catalogTests.cpp
+1
-1
source/libs/parser/inc/astToMsg.h
source/libs/parser/inc/astToMsg.h
+2
-1
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+13
-12
source/libs/parser/inc/ttokendef.h
source/libs/parser/inc/ttokendef.h
+82
-82
source/libs/parser/src/astToMsg.c
source/libs/parser/src/astToMsg.c
+41
-14
source/libs/parser/src/astValidate.c
source/libs/parser/src/astValidate.c
+54
-16
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+1533
-1571
source/libs/parser/src/ttokenizer.c
source/libs/parser/src/ttokenizer.c
+1
-1
source/libs/qcom/src/querymsg.c
source/libs/qcom/src/querymsg.c
+1
-76
src/query/inc/sql.y
src/query/inc/sql.y
+6
-5
未找到文件。
include/common/taosmsg.h
浏览文件 @
784975da
...
...
@@ -308,17 +308,25 @@ typedef struct {
char
data
[];
}
SMDCreateTableMsg
;
//typedef struct {
// int32_t len; // one create table message
// char tableName[TSDB_TABLE_FNAME_LEN];
// int16_t numOfColumns;
// int16_t sqlLen; // the length of SQL, it starts after schema , sql is a null-terminated string
// int8_t igExists;
// int8_t rspMeta;
// int8_t reserved[16];
// char schema[];
//} SCreateTableMsg;
typedef
struct
{
int32_t
len
;
// one create table message
char
tableName
[
TSDB_TABLE_FNAME_LEN
];
int16_t
numOfTags
;
int16_t
numOfColumns
;
int16_t
sqlLen
;
// the length of SQL, it starts after schema , sql is a null-terminated string
int16_t
numOfTags
;
int8_t
igExists
;
int8_t
rspMeta
;
int8_t
reserved
[
16
];
char
schema
[];
}
SCreateTableMsg
;
}
SCreate
C
TableMsg
;
typedef
struct
{
char
name
[
TSDB_TABLE_FNAME_LEN
];
...
...
@@ -326,7 +334,7 @@ typedef struct {
int32_t
numOfTags
;
int32_t
numOfColumns
;
SSchema
pSchema
[];
}
SCreateStbMsg
;
}
SCreateStbMsg
,
SCreateTableMsg
;
typedef
struct
{
char
name
[
TSDB_TABLE_FNAME_LEN
];
...
...
@@ -369,6 +377,7 @@ typedef struct {
typedef
struct
{
SMsgHead
head
;
char
name
[
TSDB_TABLE_FNAME_LEN
];
int8_t
ignoreNotExists
;
}
SDropTableMsg
;
typedef
struct
{
...
...
include/libs/catalog/catalog.h
浏览文件 @
784975da
...
...
@@ -115,14 +115,14 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const S
/**
* Get a table's vgroup from its name's hash value.
* @param pCatalog (input, got with catalogGetHandle)
* @param p
Rpc
(input, rpc object)
* @param p
Transporter
(input, rpc object)
* @param pMgmtEps (input, mnode EPs)
* @param pDBName (input, full db name)
* @param pTableName (input, table name, NOT including db name)
* @param vgInfo (output, vgroup info)
* @return error code
*/
int32_t
catalogGetTableHashVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
pDBName
,
const
char
*
pTableName
,
SVgroupInfo
*
vgInfo
);
int32_t
catalogGetTableHashVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pTransporter
,
const
SEpSet
*
pMgmtEps
,
const
char
*
pDBName
,
const
char
*
pTableName
,
SVgroupInfo
*
vgInfo
);
/**
...
...
include/libs/parser/parsenodes.h
浏览文件 @
784975da
...
...
@@ -40,7 +40,7 @@ typedef struct SQueryNode {
typedef
struct
SField
{
char
name
[
TSDB_COL_NAME_LEN
];
uint8_t
type
;
int
16
_t
bytes
;
int
32
_t
bytes
;
}
SField
;
typedef
struct
SParseBasicCtx
{
...
...
include/libs/qcom/query.h
浏览文件 @
784975da
...
...
@@ -107,7 +107,7 @@ int32_t cleanupTaskQueue();
int32_t
taosAsyncExec
(
__async_exec_fn_t
execFn
,
void
*
execParam
,
int32_t
*
code
);
SSchema
*
tGetTbnameColumnSchema
();
void
msgInit
();
void
initQueryModuleMsgHandle
();
extern
int32_t
(
*
queryBuildMsg
[
TSDB_MSG_TYPE_MAX
])(
void
*
input
,
char
**
msg
,
int32_t
msgSize
,
int32_t
*
msgLen
);
extern
int32_t
(
*
queryProcessMsgRsp
[
TSDB_MSG_TYPE_MAX
])(
void
*
output
,
char
*
msg
,
int32_t
msgSize
);
...
...
source/client/inc/clientInt.h
浏览文件 @
784975da
...
...
@@ -137,15 +137,14 @@ typedef struct SRequestMsgBody {
extern
SAppInfo
appInfo
;
extern
int32_t
tscReqRef
;
extern
void
*
tscQhandle
;
extern
int32_t
tscConnRef
;
extern
int
(
*
buildRequestMsgFp
[
TSDB_SQL_MAX
])(
SRequestObj
*
pRequest
,
SRequestMsgBody
*
pMsgBody
);
extern
int
(
*
handleRequestRspFp
[
TSDB_
SQL
_MAX
])(
SRequestObj
*
pRequest
,
const
char
*
pMsg
,
int32_t
msgLen
);
SRequestMsgBody
buildRequestMsgImpl
(
SRequestObj
*
pRequest
);
extern
int
(
*
handleRequestRspFp
[
TSDB_
MSG_TYPE
_MAX
])(
SRequestObj
*
pRequest
,
const
char
*
pMsg
,
int32_t
msgLen
);
int
taos_init
();
void
*
createTscObj
(
const
char
*
user
,
const
char
*
auth
,
const
char
*
ip
,
uint32_t
port
,
SAppInstInfo
*
pAppInfo
);
void
*
createTscObj
(
const
char
*
user
,
const
char
*
auth
,
const
char
*
db
,
SAppInstInfo
*
pAppInfo
);
void
destroyTscObj
(
void
*
pObj
);
void
*
createRequest
(
STscObj
*
pObj
,
__taos_async_fn_t
fp
,
void
*
param
,
int32_t
type
);
...
...
source/client/src/clientEnv.c
浏览文件 @
784975da
...
...
@@ -13,11 +13,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "taosmsg.h"
#include "query.h"
#include <catalog.h>
#include "clientInt.h"
#include "clientLog.h"
#include "os.h"
#include "query.h"
#include "taosmsg.h"
#include "tcache.h"
#include "tconfig.h"
#include "tglobal.h"
...
...
@@ -129,7 +130,7 @@ void destroyTscObj(void *pObj) {
tfree
(
pTscObj
);
}
void
*
createTscObj
(
const
char
*
user
,
const
char
*
auth
,
const
char
*
ip
,
uint32_t
port
,
SAppInstInfo
*
pAppInfo
)
{
void
*
createTscObj
(
const
char
*
user
,
const
char
*
auth
,
const
char
*
db
,
SAppInstInfo
*
pAppInfo
)
{
STscObj
*
pObj
=
(
STscObj
*
)
calloc
(
1
,
sizeof
(
STscObj
));
if
(
NULL
==
pObj
)
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
...
...
@@ -144,6 +145,10 @@ void* createTscObj(const char* user, const char* auth, const char *ip, uint32_t
tstrncpy
(
pObj
->
user
,
user
,
sizeof
(
pObj
->
user
));
memcpy
(
pObj
->
pass
,
auth
,
TSDB_PASSWORD_LEN
);
if
(
db
!=
NULL
)
{
tstrncpy
(
pObj
->
db
,
db
,
tListLen
(
pObj
->
db
));
}
pthread_mutex_init
(
&
pObj
->
mutex
,
NULL
);
pObj
->
id
=
taosAddRef
(
tscConnRef
,
pObj
);
...
...
@@ -220,9 +225,13 @@ void taos_init_imp(void) {
taosInitNotes
();
initMsgHandleFp
();
initQueryModuleMsgHandle
();
rpcInit
();
SCatalogCfg
cfg
=
{.
enableVgroupCache
=
true
,
.
maxDBCacheNum
=
100
,
.
maxTblCacheNum
=
100
};
catalogInit
(
&
cfg
);
tscDebug
(
"starting to initialize TAOS driver, local ep: %s"
,
tsLocalEp
);
taosSetCoreDump
(
true
);
...
...
source/client/src/clientImpl.c
浏览文件 @
784975da
...
...
@@ -154,17 +154,52 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
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
)
{
if
(
type
==
TSDB_MSG_TYPE_CREATE_USER
||
type
==
TSDB_MSG_TYPE_SHOW
||
type
==
TSDB_MSG_TYPE_DROP_USER
||
type
==
TSDB_MSG_TYPE_DROP_ACCT
||
type
==
TSDB_MSG_TYPE_CREATE_DB
||
type
==
TSDB_MSG_TYPE_CREATE_ACCT
||
type
==
TSDB_MSG_TYPE_CREATE_TABLE
||
type
==
TSDB_MSG_TYPE_CREATE_STB
||
type
==
TSDB_MSG_TYPE_USE_DB
||
type
==
TSDB_MSG_TYPE_DROP_DB
||
type
==
TSDB_MSG_TYPE_DROP_STB
)
{
pRequest
->
type
=
type
;
pRequest
->
body
.
requestMsg
=
(
SReqMsgInfo
){.
pMsg
=
output
,
.
len
=
outputLen
};
SRequestMsgBody
body
=
{
0
}
;
buildRequestMsgFp
[
type
](
pRequest
,
&
body
)
;
SRequestMsgBody
body
=
buildRequestMsgImpl
(
pRequest
)
;
SEpSet
*
pEpSet
=
&
pTscObj
->
pAppInfo
->
mgmtEp
.
epSet
;
int64_t
transporterId
=
0
;
sendMsgToServer
(
pTscObj
->
pTransporter
,
&
pTscObj
->
pAppInfo
->
mgmtEp
.
epSet
,
&
body
,
&
transporterId
);
if
(
type
==
TSDB_MSG_TYPE_CREATE_TABLE
)
{
struct
SCatalog
*
pCatalog
=
NULL
;
char
buf
[
12
]
=
{
0
};
sprintf
(
buf
,
"%d"
,
pTscObj
->
pAppInfo
->
clusterId
);
code
=
catalogGetHandle
(
buf
,
&
pCatalog
);
if
(
code
!=
0
)
{
pRequest
->
code
=
code
;
return
pRequest
;
}
SCreateTableMsg
*
pMsg
=
body
.
msgInfo
.
pMsg
;
SName
t
=
{
0
};
tNameFromString
(
&
t
,
pMsg
->
name
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
char
db
[
TSDB_DB_NAME_LEN
+
TS_PATH_DELIMITER_LEN
+
TSDB_ACCT_ID_LEN
]
=
{
0
};
tNameGetFullDbName
(
&
t
,
db
);
SVgroupInfo
info
=
{
0
};
catalogGetTableHashVgroup
(
pCatalog
,
pTscObj
->
pTransporter
,
pEpSet
,
db
,
tNameGetTableName
(
&
t
),
&
info
);
int64_t
transporterId
=
0
;
SEpSet
ep
=
{
0
};
ep
.
inUse
=
info
.
inUse
;
ep
.
numOfEps
=
info
.
numOfEps
;
for
(
int32_t
i
=
0
;
i
<
ep
.
numOfEps
;
++
i
)
{
ep
.
port
[
i
]
=
info
.
epAddr
[
i
].
port
;
tstrncpy
(
ep
.
fqdn
[
i
],
info
.
epAddr
[
i
].
fqdn
,
tListLen
(
ep
.
fqdn
[
i
]));
}
sendMsgToServer
(
pTscObj
->
pTransporter
,
&
ep
,
&
body
,
&
transporterId
);
}
else
{
int64_t
transporterId
=
0
;
sendMsgToServer
(
pTscObj
->
pTransporter
,
pEpSet
,
&
body
,
&
transporterId
);
}
tsem_wait
(
&
pRequest
->
body
.
rspSem
);
destroyRequestMsgBody
(
&
body
);
...
...
@@ -220,13 +255,13 @@ int initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSe
}
STscObj
*
taosConnectImpl
(
const
char
*
ip
,
const
char
*
user
,
const
char
*
auth
,
const
char
*
db
,
uint16_t
port
,
__taos_async_fn_t
fp
,
void
*
param
,
SAppInstInfo
*
pAppInfo
)
{
STscObj
*
pTscObj
=
createTscObj
(
user
,
auth
,
ip
,
port
,
pAppInfo
);
STscObj
*
pTscObj
=
createTscObj
(
user
,
auth
,
db
,
pAppInfo
);
if
(
NULL
==
pTscObj
)
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
pTscObj
;
}
SRequestObj
*
pRequest
=
createRequest
(
pTscObj
,
fp
,
param
,
TSDB_
SQL
_CONNECT
);
SRequestObj
*
pRequest
=
createRequest
(
pTscObj
,
fp
,
param
,
TSDB_
MSG_TYPE
_CONNECT
);
if
(
pRequest
==
NULL
)
{
destroyTscObj
(
pTscObj
);
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
...
...
@@ -268,16 +303,11 @@ static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody)
return
-
1
;
}
// TODO refactor full_name
char
*
db
;
// ugly code to move the space
STscObj
*
pObj
=
pRequest
->
pTscObj
;
pthread_mutex_lock
(
&
pObj
->
mutex
);
db
=
strstr
(
pObj
->
db
,
TS_PATH_DELIMITER
);
db
=
(
db
==
NULL
)
?
pObj
->
db
:
db
+
1
;
char
*
db
=
getConnectionDB
(
pObj
)
;
tstrncpy
(
pConnect
->
db
,
db
,
sizeof
(
pConnect
->
db
));
pthread_mutex_unlock
(
&
pObj
->
mutex
);
tfree
(
db
);
pConnect
->
pid
=
htonl
(
appInfo
.
pid
);
pConnect
->
startTime
=
htobe64
(
appInfo
.
startTime
);
...
...
@@ -395,10 +425,9 @@ void* doFetchRow(SRequestObj* pRequest) {
SReqResultInfo
*
pResultInfo
=
&
pRequest
->
body
.
resInfo
;
if
(
pResultInfo
->
pData
==
NULL
||
pResultInfo
->
current
>=
pResultInfo
->
numOfRows
)
{
pRequest
->
type
=
TSDB_
SQL_RETRIEVE_MNOD
E
;
pRequest
->
type
=
TSDB_
MSG_TYPE_SHOW_RETRIEV
E
;
SRequestMsgBody
body
=
{
0
};
buildRequestMsgFp
[
pRequest
->
type
](
pRequest
,
&
body
);
SRequestMsgBody
body
=
buildRequestMsgImpl
(
pRequest
);
int64_t
transporterId
=
0
;
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
...
...
source/client/src/clientMsgHandler.c
浏览文件 @
784975da
...
...
@@ -21,8 +21,7 @@
#include "tmsgtype.h"
#include "trpc.h"
int
(
*
buildRequestMsgFp
[
TSDB_SQL_MAX
])(
SRequestObj
*
pRequest
,
SRequestMsgBody
*
pMsgBody
)
=
{
0
};
int
(
*
handleRequestRspFp
[
TSDB_SQL_MAX
])(
SRequestObj
*
pRequest
,
const
char
*
pMsg
,
int32_t
msgLen
);
int
(
*
handleRequestRspFp
[
TSDB_MSG_TYPE_MAX
])(
SRequestObj
*
pRequest
,
const
char
*
pMsg
,
int32_t
msgLen
);
int32_t
buildConnectMsg
(
SRequestObj
*
pRequest
,
SRequestMsgBody
*
pMsgBody
)
{
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_CONNECT
;
...
...
@@ -67,15 +66,6 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
pConnect
->
epSet
.
port
[
i
]
=
htons
(
pConnect
->
epSet
.
port
[
i
]);
}
// TODO refactor
pthread_mutex_lock
(
&
pTscObj
->
mutex
);
char
temp
[
TSDB_TABLE_FNAME_LEN
*
2
]
=
{
0
};
int32_t
len
=
sprintf
(
temp
,
"%d%s%s"
,
pTscObj
->
acctId
,
TS_PATH_DELIMITER
,
pTscObj
->
db
);
assert
(
len
<=
sizeof
(
pTscObj
->
db
));
tstrncpy
(
pTscObj
->
db
,
temp
,
sizeof
(
pTscObj
->
db
));
pthread_mutex_unlock
(
&
pTscObj
->
mutex
);
if
(
!
isEpsetEqual
(
&
pTscObj
->
pAppInfo
->
mgmtEp
.
epSet
,
&
pConnect
->
epSet
))
{
updateEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
,
&
pConnect
->
epSet
);
}
...
...
@@ -96,47 +86,35 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
return
0
;
}
int32_t
doBuildMsgSupp
(
SRequestObj
*
pRequest
,
SRequestMsgBody
*
pMsgBody
)
{
static
int32_t
buildRetrieveMnodeMsg
(
SRequestObj
*
pRequest
,
SRequestMsgBody
*
pMsgBody
)
{
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_SHOW_RETRIEVE
;
pMsgBody
->
msgInfo
.
len
=
sizeof
(
SRetrieveTableMsg
);
pMsgBody
->
requestObjRefId
=
pRequest
->
self
;
pMsgBody
->
msgInfo
=
pRequest
->
body
.
requestMsg
;
switch
(
pRequest
->
type
)
{
case
TSDB_SQL_CREATE_USER
:
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_CREATE_USER
;
break
;
case
TSDB_SQL_DROP_USER
:
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_DROP_USER
;
break
;
case
TSDB_SQL_CREATE_ACCT
:
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_CREATE_ACCT
;
break
;
case
TSDB_SQL_DROP_ACCT
:
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_DROP_ACCT
;
break
;
case
TSDB_SQL_CREATE_DB
:
{
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_CREATE_DB
;
SCreateDbMsg
*
pCreateMsg
=
pRequest
->
body
.
requestMsg
.
pMsg
;
SName
name
=
{
0
};
int32_t
ret
=
tNameSetDbName
(
&
name
,
pRequest
->
pTscObj
->
acctId
,
pCreateMsg
->
db
,
strnlen
(
pCreateMsg
->
db
,
tListLen
(
pCreateMsg
->
db
)));
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
-
1
;
}
tNameGetFullDbName
(
&
name
,
pCreateMsg
->
db
);
break
;
}
case
TSDB_SQL_USE_DB
:
{
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_USE_DB
;
break
;
}
case
TSDB_SQL_CREATE_TABLE
:
{
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_CREATE_STB
;
break
;
}
case
TSDB_SQL_SHOW
:
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_SHOW
;
break
;
SRetrieveTableMsg
*
pRetrieveMsg
=
calloc
(
1
,
sizeof
(
SRetrieveTableMsg
));
if
(
pRetrieveMsg
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
pRetrieveMsg
->
showId
=
htonl
(
pRequest
->
body
.
execId
);
pMsgBody
->
msgInfo
.
pMsg
=
pRetrieveMsg
;
return
TSDB_CODE_SUCCESS
;
}
SRequestMsgBody
buildRequestMsgImpl
(
SRequestObj
*
pRequest
)
{
if
(
pRequest
->
type
==
TSDB_MSG_TYPE_SHOW_RETRIEVE
)
{
SRequestMsgBody
body
=
{
0
};
buildRetrieveMnodeMsg
(
pRequest
,
&
body
);
return
body
;
}
else
{
assert
(
pRequest
!=
NULL
);
SRequestMsgBody
body
=
{
.
requestObjRefId
=
pRequest
->
self
,
.
msgInfo
=
pRequest
->
body
.
requestMsg
,
.
msgType
=
pRequest
->
type
,
.
requestId
=
pRequest
->
requestId
,
};
return
body
;
}
}
...
...
@@ -175,18 +153,6 @@ int32_t processShowRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen)
return
0
;
}
int
buildRetrieveMnodeMsg
(
SRequestObj
*
pRequest
,
SRequestMsgBody
*
pMsgBody
)
{
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_SHOW_RETRIEVE
;
pMsgBody
->
msgInfo
.
len
=
sizeof
(
SRetrieveTableMsg
);
pMsgBody
->
requestObjRefId
=
pRequest
->
self
;
SRetrieveTableMsg
*
pRetrieveMsg
=
calloc
(
1
,
sizeof
(
SRetrieveTableMsg
));
pRetrieveMsg
->
showId
=
htonl
(
pRequest
->
body
.
execId
);
pMsgBody
->
msgInfo
.
pMsg
=
pRetrieveMsg
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
processRetrieveMnodeRsp
(
SRequestObj
*
pRequest
,
const
char
*
pMsg
,
int32_t
msgLen
)
{
assert
(
msgLen
>=
sizeof
(
SRetrieveTableRsp
));
...
...
@@ -227,6 +193,10 @@ int32_t processCreateTableRsp(SRequestObj *pRequest, const char* pMsg, int32_t m
assert
(
pMsg
!=
NULL
);
}
int32_t
processDropDbRsp
(
SRequestObj
*
pRequest
,
const
char
*
pMsg
,
int32_t
msgLen
)
{
// todo: Remove cache in catalog cache.
}
void
initMsgHandleFp
()
{
#if 0
tscBuildMsg[TSDB_SQL_SELECT] = tscBuildQueryMsg;
...
...
@@ -303,27 +273,11 @@ void initMsgHandleFp() {
tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp;
#endif
buildRequestMsgFp
[
TSDB_SQL_CONNECT
]
=
buildConnectMsg
;
handleRequestRspFp
[
TSDB_SQL_CONNECT
]
=
processConnectRsp
;
buildRequestMsgFp
[
TSDB_SQL_CREATE_USER
]
=
doBuildMsgSupp
;
buildRequestMsgFp
[
TSDB_SQL_DROP_USER
]
=
doBuildMsgSupp
;
buildRequestMsgFp
[
TSDB_SQL_CREATE_ACCT
]
=
doBuildMsgSupp
;
buildRequestMsgFp
[
TSDB_SQL_DROP_ACCT
]
=
doBuildMsgSupp
;
buildRequestMsgFp
[
TSDB_SQL_SHOW
]
=
doBuildMsgSupp
;
handleRequestRspFp
[
TSDB_SQL_SHOW
]
=
processShowRsp
;
buildRequestMsgFp
[
TSDB_SQL_RETRIEVE_MNODE
]
=
buildRetrieveMnodeMsg
;
handleRequestRspFp
[
TSDB_SQL_RETRIEVE_MNODE
]
=
processRetrieveMnodeRsp
;
buildRequestMsgFp
[
TSDB_SQL_CREATE_DB
]
=
doBuildMsgSupp
;
handleRequestRspFp
[
TSDB_SQL_CREATE_DB
]
=
processCreateDbRsp
;
buildRequestMsgFp
[
TSDB_SQL_USE_DB
]
=
doBuildMsgSupp
;
handleRequestRspFp
[
TSDB_SQL_USE_DB
]
=
processUseDbRsp
;
buildRequestMsgFp
[
TSDB_SQL_CREATE_TABLE
]
=
doBuildMsgSupp
;
handleRequestRspFp
[
TSDB_SQL_CREATE_TABLE
]
=
processCreateTableRsp
;
handleRequestRspFp
[
TSDB_MSG_TYPE_CONNECT
]
=
processConnectRsp
;
handleRequestRspFp
[
TSDB_MSG_TYPE_SHOW
]
=
processShowRsp
;
handleRequestRspFp
[
TSDB_MSG_TYPE_SHOW_RETRIEVE
]
=
processRetrieveMnodeRsp
;
handleRequestRspFp
[
TSDB_MSG_TYPE_CREATE_DB
]
=
processCreateDbRsp
;
handleRequestRspFp
[
TSDB_MSG_TYPE_USE_DB
]
=
processUseDbRsp
;
handleRequestRspFp
[
TSDB_MSG_TYPE_CREATE_TABLE
]
=
processCreateTableRsp
;
handleRequestRspFp
[
TSDB_MSG_TYPE_DROP_DB
]
=
processDropDbRsp
;
}
\ No newline at end of file
source/client/test/clientTests.cpp
浏览文件 @
784975da
...
...
@@ -22,11 +22,24 @@
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#include "../inc/clientInt.h"
#include "taos.h"
#include "tglobal.h"
#include "../inc/clientInt.h"
namespace
{
void
showDB
(
TAOS
*
pConn
)
{
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"show databases"
);
TAOS_ROW
pRow
=
NULL
;
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pRes
);
int32_t
numOfFields
=
taos_num_fields
(
pRes
);
char
str
[
512
]
=
{
0
};
while
((
pRow
=
taos_fetch_row
(
pRes
))
!=
NULL
)
{
int32_t
code
=
taos_print_row
(
str
,
pRow
,
pFields
,
numOfFields
);
printf
(
"%s
\n
"
,
str
);
}
}
}
// namespace
int
main
(
int
argc
,
char
**
argv
)
{
...
...
@@ -34,92 +47,208 @@ int main(int argc, char** argv) {
return
RUN_ALL_TESTS
();
}
TEST
(
testCase
,
driverInit_Test
)
{
taos_init
();
}
TEST
(
testCase
,
driverInit_Test
)
{
taos_init
();
}
TEST
(
testCase
,
connect_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
// TEST(testCase, connect_Test) {
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
//// assert(pConn != NULL);
// taos_close(pConn);
//}
//
// TEST(testCase, create_user_Test) {
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
taos_close
(
pConn
);
}
TEST
(
testCase
,
create_user_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
//
// TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'");
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
// }
//
// taos_free_result(pRes);
// taos_close(pConn);
//}
//
// TEST(testCase, create_account_Test) {
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
//
// TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'");
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
// }
//
// taos_free_result(pRes);
// taos_close(pConn);
//}
//
// TEST(testCase, drop_account_Test) {
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
//
// TAOS_RES* pRes = taos_query(pConn, "drop account aabc");
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
// }
//
// taos_free_result(pRes);
// taos_close(pConn);
//}
//
// TEST(testCase, show_user_Test) {
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
//// assert(pConn != NULL);
//
// TAOS_RES* pRes = taos_query(pConn, "show users");
// TAOS_ROW pRow = NULL;
//
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
// int32_t numOfFields = taos_num_fields(pRes);
//
// char str[512] = {0};
// while((pRow = taos_fetch_row(pRes)) != NULL) {
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
// printf("%s\n", str);
// }
//
// taos_close(pConn);
//}
//
// TEST(testCase, drop_user_Test) {
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
//
// TAOS_RES* pRes = taos_query(pConn, "drop user abc");
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
// }
//
// taos_free_result(pRes);
// taos_close(pConn);
//}
//
// TEST(testCase, show_db_Test) {
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
//// assert(pConn != NULL);
//
// TAOS_RES* pRes = taos_query(pConn, "show databases");
// TAOS_ROW pRow = NULL;
//
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
// int32_t numOfFields = taos_num_fields(pRes);
//
// char str[512] = {0};
// while((pRow = taos_fetch_row(pRes)) != NULL) {
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
// printf("%s\n", str);
// }
//
// taos_close(pConn);
//}
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"create user abc pass 'abc'"
);
if
(
taos_errno
(
pRes
)
!=
TSDB_CODE_SUCCESS
)
{
printf
(
"failed to create user, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_free_result
(
pRes
);
taos_close
(
pConn
);
}
TEST
(
testCase
,
create_account_Test
)
{
TEST
(
testCase
,
create_db_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"create
account aabc pass 'abc'
"
);
if
(
taos_errno
(
pRes
)
!=
TSDB_CODE_SUCCESS
)
{
printf
(
"
failed to create user
, reason:%s
\n
"
,
taos_errstr
(
pRes
));
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"create
database abc1
"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"
error in create db
, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_free_result
(
pRes
);
taos_close
(
pConn
);
}
TEST
(
testCase
,
drop_account_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pRes
);
ASSERT_TRUE
(
pFields
==
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"drop account aabc"
);
if
(
taos_errno
(
pRes
)
!=
TSDB_CODE_SUCCESS
)
{
printf
(
"failed to create user, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
int32_t
numOfFields
=
taos_num_fields
(
pRes
);
ASSERT_EQ
(
numOfFields
,
0
);
taos_free_result
(
pRes
);
taos_close
(
pConn
);
}
TEST
(
testCase
,
show_user_T
est
)
{
TEST
(
testCase
,
use_db_t
est
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
//
assert(pConn != NULL);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"show users"
);
TAOS_ROW
pRow
=
NULL
;
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"use abc1"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"error in use db, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pRes
);
int32_t
numOfFields
=
taos_num_fields
(
pRes
);
ASSERT_TRUE
(
pFields
==
NULL
);
char
str
[
512
]
=
{
0
};
while
((
pRow
=
taos_fetch_row
(
pRes
))
!=
NULL
)
{
int32_t
code
=
taos_print_row
(
str
,
pRow
,
pFields
,
numOfFields
);
printf
(
"%s
\n
"
,
str
);
}
int32_t
numOfFields
=
taos_num_fields
(
pRes
);
ASSERT_EQ
(
numOfFields
,
0
);
taos_close
(
pConn
);
}
TEST
(
testCase
,
drop_
user_T
est
)
{
TEST
(
testCase
,
drop_
db_t
est
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"drop user abc"
);
if
(
taos_errno
(
pRes
)
!=
TSDB_CODE_SUCCESS
)
{
printf
(
"failed to create user, reason:%s
\n
"
,
taos_errstr
(
pRes
));
showDB
(
pConn
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"drop database abc1"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"failed to drop db, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_free_result
(
pRes
);
showDB
(
pConn
);
taos_close
(
pConn
);
}
TEST
(
testCase
,
show_db
_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
// TEST(testCase, create_stable
_Test) {
//
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
//
// TAOS_RES* pRes = taos_query(pConn, "create database abc1");
// if (taos_errno(pRes) != 0) {
// printf("error in create db, reason:%s\n", taos_errstr(pRes));
// }
// taos_free_result(pRes);
//
// pRes = taos_query(pConn, "use abc1");
// if (taos_errno(pRes) != 0) {
// printf("error in use db, reason:%s\n", taos_errstr(pRes));
// }
// taos_free_result(pRes);
//
// pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)");
// if (taos_errno(pRes) != 0) {
// printf("error in create stable, reason:%s\n", taos_errstr(pRes));
// }
//
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
// ASSERT_TRUE(pFields == NULL);
//
// int32_t numOfFields = taos_num_fields(pRes);
// ASSERT_EQ(numOfFields, 0);
//
// taos_free_result(pRes);
// taos_close(pConn);
//}
TEST
(
testCase
,
create_table_Test
)
{
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
//
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
// taos_free_result(pRes);
//
// pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)");
// taos_free_result(pRes);
//
// taos_close(pConn);
}
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"show databases"
);
TEST
(
testCase
,
create_ctable_Test
)
{}
TEST
(
testCase
,
show_stable_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"show stables"
);
TAOS_ROW
pRow
=
NULL
;
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pRes
);
...
...
@@ -131,53 +260,45 @@ TEST(testCase, show_db_Test) {
printf
(
"%s
\n
"
,
str
);
}
taos_close
(
pConn
);
}
TEST
(
testCase
,
create_db_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"create database abc1"
);
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pRes
);
ASSERT_TRUE
(
pFields
==
NULL
);
int32_t
numOfFields
=
taos_num_fields
(
pRes
);
ASSERT_EQ
(
numOfFields
,
0
);
taos_close
(
pConn
);
}
TEST
(
testCase
,
use_db_test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"use abc1"
);
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pRes
);
ASSERT_TRUE
(
pFields
==
NULL
);
int32_t
numOfFields
=
taos_num_fields
(
pRes
);
ASSERT_EQ
(
numOfFields
,
0
);
taos_free_result
(
pRes
);
taos_close
(
pConn
);
}
TEST
(
testCase
,
create
_stable_Test
)
{
TEST
(
testCase
,
drop
_stable_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"use abc1"
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"create database abc1"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"error in creating db, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_free_result
(
pRes
);
pRes
=
taos_query
(
pConn
,
"create stable st1(ts timestamp, k int) tags(a int)"
);
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pRes
);
ASSERT_TRUE
(
pFields
==
NULL
);
pRes
=
taos_query
(
pConn
,
"use abc1"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"error in using db, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_free_result
(
pRes
);
int32_t
numOfFields
=
taos_num_fields
(
pRes
);
ASSERT_EQ
(
numOfFields
,
0
);
pRes
=
taos_query
(
pConn
,
"drop stable st1"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"failed to drop stable, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_free_result
(
pRes
);
taos_close
(
pConn
);
}
//TEST(testCase, show_table_Test) {
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
//
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
// taos_free_result(pRes);
//
// pRes = taos_query(pConn, "show tables");
// taos_free_result(pRes);
//
// taos_close(pConn);
//}
source/libs/catalog/inc/catalogInt.h
浏览文件 @
784975da
...
...
@@ -59,8 +59,6 @@ typedef struct SCatalogMgmt {
typedef
uint32_t
(
*
tableNameHashFp
)(
const
char
*
,
uint32_t
);
extern
int32_t
ctgDebugFlag
;
#define ctgFatal(...) do { if (ctgDebugFlag & DEBUG_FATAL) { taosPrintLog("CTG FATAL ", ctgDebugFlag, __VA_ARGS__); }} while(0)
#define ctgError(...) do { if (ctgDebugFlag & DEBUG_ERROR) { taosPrintLog("CTG ERROR ", ctgDebugFlag, __VA_ARGS__); }} while(0)
#define ctgWarn(...) do { if (ctgDebugFlag & DEBUG_WARN) { taosPrintLog("CTG WARN ", ctgDebugFlag, __VA_ARGS__); }} while(0)
...
...
@@ -75,7 +73,6 @@ extern int32_t ctgDebugFlag;
#define CTG_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { ctgError(__VA_ARGS__); terrno = _code; return _code; } } while (0)
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
#ifdef __cplusplus
}
#endif
...
...
source/libs/catalog/src/catalog.c
浏览文件 @
784975da
...
...
@@ -371,7 +371,7 @@ int32_t catalogInit(SCatalogCfg *cfg) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
catalogGetHandle
(
const
char
*
clusterId
,
struct
SCatalog
**
catalogHandle
)
{
int32_t
catalogGetHandle
(
const
char
*
clusterId
,
struct
SCatalog
**
catalogHandle
)
{
if
(
NULL
==
clusterId
||
NULL
==
catalogHandle
)
{
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
);
}
...
...
@@ -565,12 +565,12 @@ _return:
}
int32_t
catalogGetTableHashVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
p
Rpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
pDBName
,
const
char
*
pTableName
,
SVgroupInfo
*
pVgroup
)
{
int32_t
catalogGetTableHashVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
p
Transporter
,
const
SEpSet
*
pMgmtEps
,
const
char
*
pDBName
,
const
char
*
pTableName
,
SVgroupInfo
*
pVgroup
)
{
SDBVgroupInfo
dbInfo
=
{
0
};
int32_t
code
=
0
;
int32_t
vgId
=
0
;
CTG_ERR_RET
(
catalogGetDBVgroup
(
pCatalog
,
p
Rpc
,
pMgmtEps
,
pDBName
,
false
,
&
dbInfo
));
CTG_ERR_RET
(
catalogGetDBVgroup
(
pCatalog
,
p
Transporter
,
pMgmtEps
,
pDBName
,
false
,
&
dbInfo
));
if
(
dbInfo
.
vgVersion
<
0
||
NULL
==
dbInfo
.
vgInfo
)
{
ctgError
(
"db[%s] vgroup cache invalid, vgroup version:%d, vgInfo:%p"
,
pDBName
,
dbInfo
.
vgVersion
,
dbInfo
.
vgInfo
);
...
...
source/libs/catalog/test/catalogTests.cpp
浏览文件 @
784975da
...
...
@@ -99,7 +99,7 @@ TEST(testCase, normalCase) {
void
*
mockPointer
=
(
void
*
)
0x1
;
SVgroupInfo
vgInfo
=
{
0
};
msgInit
();
initQueryModuleMsgHandle
();
sendCreateDbMsg
(
pConn
->
pTransporter
,
&
pConn
->
pAppInfo
->
mgmtEp
.
epSet
);
...
...
source/libs/parser/inc/astToMsg.h
浏览文件 @
784975da
...
...
@@ -8,7 +8,8 @@ SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in
SCreateAcctMsg
*
buildAcctManipulationMsg
(
SSqlInfo
*
pInfo
,
int32_t
*
outputLen
,
int64_t
id
,
char
*
msgBuf
,
int32_t
msgLen
);
SDropUserMsg
*
buildDropUserMsg
(
SSqlInfo
*
pInfo
,
int32_t
*
outputLen
,
int64_t
id
,
char
*
msgBuf
,
int32_t
msgLen
);
SShowMsg
*
buildShowMsg
(
SShowInfo
*
pShowInfo
,
int64_t
id
,
char
*
msgBuf
,
int32_t
msgLen
);
SCreateDbMsg
*
buildCreateDbMsg
(
SCreateDbInfo
*
pCreateDbInfo
,
char
*
msgBuf
,
int32_t
msgLen
);
SCreateDbMsg
*
buildCreateDbMsg
(
SCreateDbInfo
*
pCreateDbInfo
,
SParseBasicCtx
*
pCtx
,
SMsgBuf
*
pMsgBuf
);
SCreateStbMsg
*
buildCreateTableMsg
(
SCreateTableSql
*
pCreateTableSql
,
int32_t
*
len
,
SParseBasicCtx
*
pParseCtx
,
SMsgBuf
*
pMsgBuf
);
SDropTableMsg
*
buildDropTableMsg
(
SSqlInfo
*
pInfo
,
int32_t
*
len
,
SParseBasicCtx
*
pParseCtx
,
SMsgBuf
*
pMsgBuf
);
#endif // TDENGINE_ASTTOMSG_H
source/libs/parser/inc/sql.y
浏览文件 @
784975da
...
...
@@ -31,6 +31,7 @@
#include "ttoken.h"
#include "ttokendef.h"
#include "tvariant.h"
#include "parserInt.h"
}
%syntax_error {
...
...
@@ -173,7 +174,7 @@ cmd ::= ALTER DNODE ids(X) ids(Y) ids(Z). { setDCLSqlElems(pInfo, TSDB_SQL
cmd ::= ALTER LOCAL ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &X); }
cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &X, &Y); }
cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
cmd ::= ALTER TOPIC ids(X) alter_topic_optr(Y). { SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
//
cmd ::= ALTER TOPIC ids(X) alter_topic_optr(Y). { SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
cmd ::= ALTER ACCOUNT ids(X) acct_optr(Z). { setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &X, NULL, &Z);}
cmd ::= ALTER ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). { setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &X, &Y, &Z);}
...
...
@@ -203,7 +204,7 @@ cmd ::= CREATE DNODE ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE
cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z).
{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);}
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
cmd ::= CREATE TOPIC ifnotexists(Z) ids(X) topic_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
//
cmd ::= CREATE TOPIC ifnotexists(Z) ids(X) topic_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
cmd ::= CREATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) bufsize(B). { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &X, &Y, &Z, &B, 1);}
cmd ::= CREATE AGGREGATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) bufsize(B). { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &X, &Y, &Z, &B, 2);}
cmd ::= CREATE USER ids(X) PASS ids(Y). { setCreateUserSql(pInfo, &X, &Y);}
...
...
@@ -278,10 +279,10 @@ comp(Y) ::= COMP INTEGER(X). { Y = X; }
prec(Y) ::= PRECISION STRING(X). { Y = X; }
update(Y) ::= UPDATE INTEGER(X). { Y = X; }
cachelast(Y) ::= CACHELAST INTEGER(X). { Y = X; }
partitions(Y) ::= PARTITIONS INTEGER(X). { Y = X; }
//
partitions(Y) ::= PARTITIONS INTEGER(X). { Y = X; }
%type db_optr {SCreateDbInfo}
db_optr(Y) ::= . {setDefaultCreateDbOption(&Y);
Y.dbType = TSDB_DB_TYPE_DEFAULT;
}
db_optr(Y) ::= . {setDefaultCreateDbOption(&Y);}
db_optr(Y) ::= db_optr(Z) cache(X). { Y = Z; Y.cacheBlockSize = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); }
...
...
@@ -299,13 +300,13 @@ db_optr(Y) ::= db_optr(Z) keep(X). { Y = Z; Y.keep = X; }
db_optr(Y) ::= db_optr(Z) update(X). { Y = Z; Y.update = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) cachelast(X). { Y = Z; Y.cachelast = strtol(X.z, NULL, 10); }
%type topic_optr {SCreateDbInfo}
topic_optr(Y) ::= db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; }
topic_optr(Y) ::= topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); }
//
%type topic_optr {SCreateDbInfo}
//
//
topic_optr(Y) ::= db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; }
//
topic_optr(Y) ::= topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); }
%type alter_db_optr {SCreateDbInfo}
alter_db_optr(Y) ::= . { setDefaultCreateDbOption(&Y);
Y.dbType = TSDB_DB_TYPE_DEFAULT;
}
alter_db_optr(Y) ::= . { setDefaultCreateDbOption(&Y);}
alter_db_optr(Y) ::= alter_db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); }
alter_db_optr(Y) ::= alter_db_optr(Z) quorum(X). { Y = Z; Y.quorum = strtol(X.z, NULL, 10); }
...
...
@@ -319,10 +320,10 @@ alter_db_optr(Y) ::= alter_db_optr(Z) cachelast(X). { Y = Z; Y.cachelast = str
//alter_db_optr(Y) ::= alter_db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtol(X.z, NULL, 10); }
//alter_db_optr(Y) ::= alter_db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); } not support yet
%type alter_topic_optr {SCreateDbInfo}
//
%type alter_topic_optr {SCreateDbInfo}
alter_topic_optr(Y) ::= alter_db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; }
alter_topic_optr(Y) ::= alter_topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); }
//
alter_topic_optr(Y) ::= alter_db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; }
//
alter_topic_optr(Y) ::= alter_topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); }
%type typename {SField}
typename(A) ::= ids(X). {
...
...
source/libs/parser/inc/ttokendef.h
浏览文件 @
784975da
...
...
@@ -130,88 +130,88 @@
#define TK_PRECISION 112
#define TK_UPDATE 113
#define TK_CACHELAST 114
#define TK_
PARTITIONS
115
#define TK_
UNSIGNED
116
#define TK_
TAGS
117
#define TK_
USING
118
#define TK_N
ULL
119
#define TK_
NOW
120
#define TK_
SELECT
121
#define TK_
UNION
122
#define TK_
ALL
123
#define TK_
DISTINCT
124
#define TK_
FROM
125
#define TK_
VARIABLE
126
#define TK_
INTERVAL
127
#define TK_
EVERY
128
#define TK_S
ESSION
129
#define TK_
STATE_WINDOW
130
#define TK_
FILL
131
#define TK_
SLIDING
132
#define TK_
ORDER
133
#define TK_
BY
134
#define TK_
ASC
135
#define TK_
GROUP
136
#define TK_
HAVING
137
#define TK_
LIMIT
138
#define TK_
OFFSE
T 139
#define TK_S
LIMIT
140
#define TK_
SOFFSET
141
#define TK_
WHERE
142
#define TK_
RESET
143
#define TK_
QUERY
144
#define TK_
SYNCDB
145
#define TK_
ADD
146
#define TK_
COLUMN
147
#define TK_
MODIFY
148
#define TK_
TAG
149
#define TK_
CHANGE
150
#define TK_
SET
151
#define TK_
KILL
152
#define TK_
CONNECTION
153
#define TK_
STREAM
154
#define TK_
COLON
155
#define TK_A
BORT
156
#define TK_A
FTER
157
#define TK_
ATTACH
158
#define TK_BE
FORE
159
#define TK_
BEGIN
160
#define TK_C
ASCADE
161
#define TK_C
LUSTER
162
#define TK_CO
NFLICT
163
#define TK_
COPY
164
#define TK_DE
FERRED
165
#define TK_DE
LIMITERS
166
#define TK_
DETACH
167
#define TK_E
ACH
168
#define TK_E
ND
169
#define TK_
EXPLAIN
170
#define TK_F
AIL
171
#define TK_
FOR
172
#define TK_I
GNORE
173
#define TK_I
MMEDIATE
174
#define TK_IN
ITIALLY
175
#define TK_
INSTEAD
176
#define TK_
KEY
177
#define TK_
OF
178
#define TK_R
AISE
179
#define TK_RE
PLACE
180
#define TK_R
ESTRICT
181
#define TK_
ROW
182
#define TK_
STATEMENT
183
#define TK_
TRIGGER
184
#define TK_
VIEW
185
#define TK_
IPTOKEN
186
#define TK_
SEMI
187
#define TK_
NONE
188
#define TK_
PREV
189
#define TK_
LINEAR
190
#define TK_
IMPORT
191
#define TK_
TBNAME
192
#define TK_
JOIN
193
#define TK_IN
SERT
194
#define TK_
INTO
195
#define TK_VALUES 196
#define TK_
UNSIGNED
115
#define TK_
TAGS
116
#define TK_
USING
117
#define TK_
NULL
118
#define TK_N
OW
119
#define TK_
SELECT
120
#define TK_
UNION
121
#define TK_
ALL
122
#define TK_
DISTINCT
123
#define TK_
FROM
124
#define TK_
VARIABLE
125
#define TK_
INTERVAL
126
#define TK_
EVERY
127
#define TK_
SESSION
128
#define TK_S
TATE_WINDOW
129
#define TK_
FILL
130
#define TK_
SLIDING
131
#define TK_
ORDER
132
#define TK_
BY
133
#define TK_
ASC
134
#define TK_
GROUP
135
#define TK_
HAVING
136
#define TK_
LIMIT
137
#define TK_
OFFSET
138
#define TK_
SLIMI
T 139
#define TK_S
OFFSET
140
#define TK_
WHERE
141
#define TK_
RESET
142
#define TK_
QUERY
143
#define TK_
SYNCDB
144
#define TK_
ADD
145
#define TK_
COLUMN
146
#define TK_
MODIFY
147
#define TK_
TAG
148
#define TK_
CHANGE
149
#define TK_
SET
150
#define TK_
KILL
151
#define TK_
CONNECTION
152
#define TK_
STREAM
153
#define TK_
COLON
154
#define TK_
ABORT
155
#define TK_A
FTER
156
#define TK_A
TTACH
157
#define TK_
BEFORE
158
#define TK_BE
GIN
159
#define TK_
CASCADE
160
#define TK_C
LUSTER
161
#define TK_C
ONFLICT
162
#define TK_CO
PY
163
#define TK_
DEFERRED
164
#define TK_DE
LIMITERS
165
#define TK_DE
TACH
166
#define TK_
EACH
167
#define TK_E
ND
168
#define TK_E
XPLAIN
169
#define TK_
FAIL
170
#define TK_F
OR
171
#define TK_
IGNORE
172
#define TK_I
MMEDIATE
173
#define TK_I
NITIALLY
174
#define TK_IN
STEAD
175
#define TK_
KEY
176
#define TK_
OF
177
#define TK_
RAISE
178
#define TK_R
EPLACE
179
#define TK_RE
STRICT
180
#define TK_R
OW
181
#define TK_
STATEMENT
182
#define TK_
TRIGGER
183
#define TK_
VIEW
184
#define TK_
IPTOKEN
185
#define TK_
SEMI
186
#define TK_
NONE
187
#define TK_
PREV
188
#define TK_
LINEAR
189
#define TK_
IMPORT
190
#define TK_
TBNAME
191
#define TK_
JOIN
192
#define TK_
INSERT
193
#define TK_IN
TO
194
#define TK_
VALUES
195
#define TK_SPACE 300
...
...
source/libs/parser/src/astToMsg.c
浏览文件 @
784975da
...
...
@@ -207,17 +207,23 @@ int32_t setDbOptions(SCreateDbMsg* pCreateDbMsg, const SCreateDbInfo* pCreateDbS
return
TSDB_CODE_SUCCESS
;
}
SCreateDbMsg
*
buildCreateDbMsg
(
SCreateDbInfo
*
pCreateDbInfo
,
char
*
msgBuf
,
int32_t
msgLen
)
{
SCreateDbMsg
*
buildCreateDbMsg
(
SCreateDbInfo
*
pCreateDbInfo
,
SParseBasicCtx
*
pCtx
,
SMsgBuf
*
pMsgBuf
)
{
SCreateDbMsg
*
pCreateMsg
=
calloc
(
1
,
sizeof
(
SCreateDbMsg
));
SMsgBuf
msg
=
{.
buf
=
msgBuf
,
.
len
=
msgLen
};
if
(
setDbOptions
(
pCreateMsg
,
pCreateDbInfo
,
&
msg
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
setDbOptions
(
pCreateMsg
,
pCreateDbInfo
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
tfree
(
pCreateMsg
);
terrno
=
TSDB_CODE_TSC_INVALID_OPERATION
;
return
NULL
;
}
SName
name
=
{
0
};
int32_t
ret
=
tNameSetDbName
(
&
name
,
pCtx
->
acctId
,
pCreateDbInfo
->
dbname
.
z
,
pCreateDbInfo
->
dbname
.
n
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
ret
;
return
NULL
;
}
tNameGetFullDbName
(
&
name
,
pCreateMsg
->
db
);
return
pCreateMsg
;
}
...
...
@@ -263,14 +269,17 @@ int32_t createSName(SName* pName, SToken* pTableName, SParseBasicCtx* pParseCtx,
SCreateStbMsg
*
buildCreateTableMsg
(
SCreateTableSql
*
pCreateTableSql
,
int32_t
*
len
,
SParseBasicCtx
*
pParseCtx
,
SMsgBuf
*
pMsgBuf
)
{
SSchema
*
pSchema
;
int32_t
numOfTags
=
0
;
int32_t
numOfCols
=
(
int32_t
)
taosArrayGetSize
(
pCreateTableSql
->
colInfo
.
pColumns
);
int32_t
numOfTags
=
(
int32_t
)
taosArrayGetSize
(
pCreateTableSql
->
colInfo
.
pTagColumns
);
if
(
pCreateTableSql
->
colInfo
.
pTagColumns
!=
NULL
)
{
numOfTags
=
(
int32_t
)
taosArrayGetSize
(
pCreateTableSql
->
colInfo
.
pTagColumns
);
}
SCreateStbMsg
*
pCreateTableMsg
=
(
SCreateStbMsg
*
)
calloc
(
1
,
sizeof
(
SCreateStbMsg
)
+
(
numOfCols
+
numOfTags
)
*
sizeof
(
SSchema
));
char
*
pMsg
=
NULL
;
int
8_t
t
ype
=
pCreateTableSql
->
type
;
if
(
t
ype
==
TSQL_CREATE_
TABLE
)
{
// create by using super table, tags value
int
32_t
tableT
ype
=
pCreateTableSql
->
type
;
if
(
t
ableType
!=
TSQL_CREATE_TABLE
&&
tableType
!=
TSQL_CREATE_S
TABLE
)
{
// create by using super table, tags value
#if 0
SArray* list = pInfo->pCreateTableInfo->childTableInfo;
...
...
@@ -309,15 +318,13 @@ SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* le
return
NULL
;
}
pCreateTableMsg
->
igExists
=
pCreateTableSql
->
existCheck
?
1
:
0
;
pCreateTableMsg
->
igExists
=
pCreateTableSql
->
existCheck
?
1
:
0
;
pCreateTableMsg
->
numOfColumns
=
htonl
(
numOfCols
);
pCreateTableMsg
->
numOfTags
=
htonl
(
numOfTags
);
pCreateTableMsg
->
numOfTags
=
htonl
(
numOfTags
);
pSchema
=
(
SSchema
*
)
pCreateTableMsg
->
pSchema
;
for
(
int
i
=
0
;
i
<
numOfCols
;
++
i
)
{
TAOS_FIELD
*
pField
=
taosArrayGet
(
pCreateTableSql
->
colInfo
.
pColumns
,
i
);
SField
*
pField
=
taosArrayGet
(
pCreateTableSql
->
colInfo
.
pColumns
,
i
);
pSchema
->
type
=
pField
->
type
;
pSchema
->
bytes
=
htonl
(
pField
->
bytes
);
strcpy
(
pSchema
->
name
,
pField
->
name
);
...
...
@@ -326,8 +333,7 @@ SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* le
}
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
TAOS_FIELD
*
pField
=
taosArrayGet
(
pCreateTableSql
->
colInfo
.
pTagColumns
,
i
);
SField
*
pField
=
taosArrayGet
(
pCreateTableSql
->
colInfo
.
pTagColumns
,
i
);
pSchema
->
type
=
pField
->
type
;
pSchema
->
bytes
=
htonl
(
pField
->
bytes
);
strcpy
(
pSchema
->
name
,
pField
->
name
);
...
...
@@ -343,3 +349,24 @@ SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* le
return
pCreateTableMsg
;
}
SDropTableMsg
*
buildDropTableMsg
(
SSqlInfo
*
pInfo
,
int32_t
*
len
,
SParseBasicCtx
*
pParseCtx
,
SMsgBuf
*
pMsgBuf
)
{
SToken
*
tableName
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
SName
name
=
{
0
};
int32_t
code
=
createSName
(
&
name
,
tableName
,
pParseCtx
,
pMsgBuf
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
buildInvalidOperationMsg
(
pMsgBuf
,
"invalid table name"
);
return
NULL
;
}
SDropTableMsg
*
pDropTableMsg
=
(
SDropTableMsg
*
)
calloc
(
1
,
sizeof
(
SDropTableMsg
));
code
=
tNameExtractFullName
(
&
name
,
pDropTableMsg
->
name
);
assert
(
code
==
TSDB_CODE_SUCCESS
&&
name
.
type
==
TSDB_TABLE_NAME_T
);
pDropTableMsg
->
ignoreNotExists
=
pInfo
->
pMiscInfo
->
existsCheck
?
1
:
0
;
*
len
=
sizeof
(
SDropTableMsg
);
return
pDropTableMsg
;
}
source/libs/parser/src/astValidate.c
浏览文件 @
784975da
...
...
@@ -4028,7 +4028,7 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer
}
// todo remove it
static
int32_t
setShowInfo
(
struct
SSqlInfo
*
pInfo
,
void
**
output
,
int32_t
*
msg
Len
,
SMsgBuf
*
pMsgBuf
)
{
static
int32_t
setShowInfo
(
SShowInfo
*
pShowInfo
,
SParseBasicCtx
*
pCtx
,
void
**
output
,
int32_t
*
output
Len
,
SMsgBuf
*
pMsgBuf
)
{
const
char
*
msg1
=
"invalid name"
;
const
char
*
msg2
=
"wildcard string should be less than %d characters"
;
const
char
*
msg3
=
"database name too long"
;
...
...
@@ -4040,9 +4040,8 @@ static int32_t setShowInfo(struct SSqlInfo* pInfo, void** output, int32_t* msgLe
* database prefix in pInfo->pMiscInfo->a[0]
* wildcard in like clause in pInfo->pMiscInfo->a[1]
*/
SShowInfo
*
pShowInfo
=
&
pInfo
->
pMiscInfo
->
showOpt
;
int16_t
showType
=
pShowInfo
->
showType
;
if
(
showType
==
TSDB_MGMT_TABLE_
TABLE
||
showType
==
TSDB_MGMT_TABLE_VGROUP
)
{
if
(
showType
==
TSDB_MGMT_TABLE_
STB
||
showType
==
TSDB_MGMT_TABLE_VGROUP
)
{
SToken
*
pDbPrefixToken
=
&
pShowInfo
->
prefix
;
if
(
pDbPrefixToken
->
type
!=
0
)
{
if
(
pDbPrefixToken
->
n
>=
TSDB_DB_NAME_LEN
)
{
// db name is too long
...
...
@@ -4091,8 +4090,8 @@ static int32_t setShowInfo(struct SSqlInfo* pInfo, void** output, int32_t* msgLe
}
}
*
output
=
buildShowMsg
(
pShowInfo
,
0
,
pMsgBuf
->
buf
,
pMsgBuf
->
len
);
*
msg
Len
=
sizeof
(
SShowMsg
)
/* + htons(pShowMsg->payloadLen)*/
;
*
output
=
buildShowMsg
(
pShowInfo
,
pCtx
->
requestId
,
pMsgBuf
->
buf
,
pMsgBuf
->
len
);
*
output
Len
=
sizeof
(
SShowMsg
)
/* + htons(pShowMsg->payloadLen)*/
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -4246,7 +4245,7 @@ static int32_t validateTableColumnInfo(SArray* pFieldList, SMsgBuf* pMsgBuf) {
const
char
*
msg8
=
"illegal number of columns"
;
// first column must be timestamp
TAOS_FIELD
*
pField
=
taosArrayGet
(
pFieldList
,
0
);
SField
*
pField
=
taosArrayGet
(
pFieldList
,
0
);
if
(
pField
->
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
}
...
...
@@ -4274,7 +4273,7 @@ static int32_t validateTagParams(SArray* pTagsList, SArray* pFieldList, SMsgBuf*
// field name must be unique
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
TAOS_FIELD
*
p
=
taosArrayGet
(
pTagsList
,
i
);
SField
*
p
=
taosArrayGet
(
pTagsList
,
i
);
if
(
has
(
pFieldList
,
0
,
p
->
name
)
==
true
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg3
);
}
...
...
@@ -4295,7 +4294,6 @@ int32_t doCheckForCreateTable(SSqlInfo* pInfo, SMsgBuf* pMsgBuf) {
// if sql specifies db, use it, otherwise use default db
SToken
*
pzTableName
=
&
(
pCreateTable
->
name
);
bool
dbIncluded
=
false
;
if
(
parserValidateNameToken
(
pzTableName
)
!=
TSDB_CODE_SUCCESS
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
}
...
...
@@ -4314,8 +4312,6 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
SMsgBuf
m
=
{.
buf
=
msgBuf
,
.
len
=
msgBufLen
};
SMsgBuf
*
pMsgBuf
=
&
m
;
*
type
=
pInfo
->
type
;
switch
(
pInfo
->
type
)
{
case
TSDB_SQL_CREATE_USER
:
case
TSDB_SQL_ALTER_USER
:
{
...
...
@@ -4362,6 +4358,7 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
}
*
output
=
buildUserManipulationMsg
(
pInfo
,
outputLen
,
pCtx
->
requestId
,
msgBuf
,
msgBufLen
);
*
type
=
(
pInfo
->
type
==
TSDB_SQL_CREATE_USER
)
?
TSDB_MSG_TYPE_CREATE_USER
:
TSDB_MSG_TYPE_ALTER_USER
;
break
;
}
...
...
@@ -4398,17 +4395,20 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
}
*
output
=
buildAcctManipulationMsg
(
pInfo
,
outputLen
,
pCtx
->
requestId
,
msgBuf
,
msgBufLen
);
*
type
=
(
pInfo
->
type
==
TSDB_SQL_CREATE_ACCT
)
?
TSDB_MSG_TYPE_CREATE_ACCT
:
TSDB_MSG_TYPE_ALTER_ACCT
;
break
;
}
case
TSDB_SQL_DROP_ACCT
:
case
TSDB_SQL_DROP_USER
:
{
*
output
=
buildDropUserMsg
(
pInfo
,
outputLen
,
pCtx
->
requestId
,
msgBuf
,
msgBufLen
);
*
type
=
(
pInfo
->
type
==
TSDB_SQL_DROP_ACCT
)
?
TSDB_MSG_TYPE_DROP_ACCT
:
TSDB_MSG_TYPE_DROP_USER
;
break
;
}
case
TSDB_SQL_SHOW
:
{
code
=
setShowInfo
(
pInfo
,
output
,
outputLen
,
pMsgBuf
);
code
=
setShowInfo
(
&
pInfo
->
pMiscInfo
->
showOpt
,
pCtx
,
output
,
outputLen
,
pMsgBuf
);
*
type
=
TSDB_MSG_TYPE_SHOW
;
break
;
}
...
...
@@ -4429,8 +4429,9 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
SUseDbMsg
*
pUseDbMsg
=
(
SUseDbMsg
*
)
calloc
(
1
,
sizeof
(
SUseDbMsg
));
tNameExtractFullName
(
&
n
,
pUseDbMsg
->
db
);
*
output
=
pUseDbMsg
;
*
output
=
pUseDbMsg
;
*
outputLen
=
sizeof
(
SUseDbMsg
);
*
type
=
TSDB_MSG_TYPE_USE_DB
;
break
;
}
...
...
@@ -4451,18 +4452,41 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
}
SCreateDbMsg
*
pCreateMsg
=
buildCreateDbMsg
(
pCreateDB
,
p
MsgBuf
->
buf
,
pMsgBuf
->
len
);
SCreateDbMsg
*
pCreateMsg
=
buildCreateDbMsg
(
pCreateDB
,
p
Ctx
,
pMsgBuf
);
if
(
doCheckDbOptions
(
pCreateMsg
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
strncpy
(
pCreateMsg
->
db
,
token
.
z
,
token
.
n
);
*
output
=
pCreateMsg
;
*
output
=
pCreateMsg
;
*
outputLen
=
sizeof
(
SCreateDbMsg
);
*
type
=
(
pInfo
->
type
==
TSDB_SQL_CREATE_DB
)
?
TSDB_MSG_TYPE_CREATE_DB
:
TSDB_MSG_TYPE_ALTER_DB
;
break
;
}
case
TSDB_SQL_DROP_DB
:
{
const
char
*
msg1
=
"invalid database name"
;
assert
(
taosArrayGetSize
(
pInfo
->
pMiscInfo
->
a
)
==
1
);
SToken
*
dbName
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
SName
name
=
{
0
};
code
=
tNameSetDbName
(
&
name
,
pCtx
->
acctId
,
dbName
->
z
,
dbName
->
n
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
}
SDropDbMsg
*
pDropDbMsg
=
(
SDropDbMsg
*
)
calloc
(
1
,
sizeof
(
SDropDbMsg
));
code
=
tNameExtractFullName
(
&
name
,
pDropDbMsg
->
db
);
pDropDbMsg
->
ignoreNotExists
=
pInfo
->
pMiscInfo
->
existsCheck
?
1
:
0
;
assert
(
code
==
TSDB_CODE_SUCCESS
&&
name
.
type
==
TSDB_DB_NAME_T
);
*
type
=
TSDB_MSG_TYPE_DROP_DB
;
*
outputLen
=
sizeof
(
SDropDbMsg
);
*
output
=
pDropDbMsg
;
return
TSDB_CODE_SUCCESS
;
}
case
TSDB_SQL_CREATE_TABLE
:
{
SCreateTableSql
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
...
...
@@ -4470,7 +4494,9 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
if
((
code
=
doCheckForCreateTable
(
pInfo
,
pMsgBuf
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
*
output
=
buildCreateTableMsg
(
pCreateTable
,
outputLen
,
pCtx
,
pMsgBuf
);
*
type
=
(
pCreateTable
->
type
==
TSQL_CREATE_TABLE
)
?
TSDB_MSG_TYPE_CREATE_TABLE
:
TSDB_MSG_TYPE_CREATE_STB
;
}
else
if
(
pCreateTable
->
type
==
TSQL_CREATE_CTABLE
)
{
// if ((code = doCheckForCreateFromStable(pSql, pInfo)) != TSDB_CODE_SUCCESS) {
// return code;
...
...
@@ -4483,6 +4509,18 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, void**
break
;
}
case
TSDB_SQL_DROP_TABLE
:
{
*
output
=
buildDropTableMsg
(
pInfo
,
outputLen
,
pCtx
,
pMsgBuf
);
if
(
output
==
NULL
)
{
return
terrno
;
}
*
type
=
TSDB_MSG_TYPE_DROP_STB
;
return
TSDB_CODE_SUCCESS
;
break
;
}
default:
break
;
}
...
...
source/libs/parser/src/sql.c
浏览文件 @
784975da
此差异已折叠。
点击以展开。
source/libs/parser/src/ttokenizer.c
浏览文件 @
784975da
...
...
@@ -217,7 +217,7 @@ static SKeyword keywordTable[] = {
{
"UNION"
,
TK_UNION
},
{
"CACHELAST"
,
TK_CACHELAST
},
{
"DISTINCT"
,
TK_DISTINCT
},
{
"PARTITIONS"
,
TK_PARTITIONS
},
//
{"PARTITIONS", TK_PARTITIONS},
{
"TOPIC"
,
TK_TOPIC
},
{
"TOPICS"
,
TK_TOPICS
},
{
"COMPACT"
,
TK_COMPACT
},
...
...
source/libs/qcom/src/querymsg.c
浏览文件 @
784975da
此差异已折叠。
点击以展开。
src/query/inc/sql.y
浏览文件 @
784975da
...
...
@@ -32,6 +32,7 @@
#include "ttokendef.h"
#include "tutil.h"
#include "tvariant.h"
#include "parserInt.h"
}
%syntax_error {
...
...
@@ -302,8 +303,8 @@ db_optr(Y) ::= db_optr(Z) cachelast(X). { Y = Z; Y.cachelast = strtol(X.z,
%type topic_optr {SCreateDbInfo}
topic_optr(Y) ::= db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; }
topic_optr(Y) ::= topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); }
//
topic_optr(Y) ::= db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; }
//
topic_optr(Y) ::= topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); }
%type alter_db_optr {SCreateDbInfo}
alter_db_optr(Y) ::= . { setDefaultCreateDbOption(&Y); Y.dbType = TSDB_DB_TYPE_DEFAULT;}
...
...
@@ -325,7 +326,7 @@ alter_db_optr(Y) ::= alter_db_optr(Z) cachelast(X). { Y = Z; Y.cachelast = str
alter_topic_optr(Y) ::= alter_db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; }
alter_topic_optr(Y) ::= alter_topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); }
%type typename {
TAOS_FIELD
}
%type typename {
SField
}
typename(A) ::= ids(X). {
X.type = 0;
tSetColumnType (&A, &X);
...
...
@@ -425,11 +426,11 @@ create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) AS select(S). {
setCreatedTableName(pInfo, &V, &U);
}
%type column{
TAOS_FIELD
}
%type column{
SField
}
%type columnlist{SArray*}
%destructor columnlist {taosArrayDestroy($$);}
columnlist(A) ::= columnlist(X) COMMA column(Y). {taosArrayPush(X, &Y); A = X; }
columnlist(A) ::= column(X). {A = taosArrayInit(4, sizeof(
TAOS_FIELD
)); taosArrayPush(A, &X);}
columnlist(A) ::= column(X). {A = taosArrayInit(4, sizeof(
SField
)); taosArrayPush(A, &X);}
// The information used for a column is the name and type of column:
// tinyint smallint int bigint float double bool timestamp binary(x) nchar(x)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录