Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4192f1ad
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
4192f1ad
编写于
12月 17, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-11818] enable create database.
上级
140de58e
变更
25
隐藏空白更改
内联
并排
Showing
25 changed file
with
406 addition
and
236 deletion
+406
-236
include/common/tname.h
include/common/tname.h
+6
-10
include/libs/qcom/query.h
include/libs/qcom/query.h
+1
-1
source/client/CMakeLists.txt
source/client/CMakeLists.txt
+3
-4
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+1
-2
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+1
-1
source/client/src/clientMsgHandler.c
source/client/src/clientMsgHandler.c
+36
-14
source/client/test/clientTests.cpp
source/client/test/clientTests.cpp
+39
-11
source/common/src/tname.c
source/common/src/tname.c
+20
-108
source/libs/CMakeLists.txt
source/libs/CMakeLists.txt
+1
-1
source/libs/catalog/CMakeLists.txt
source/libs/catalog/CMakeLists.txt
+1
-1
source/libs/parser/CMakeLists.txt
source/libs/parser/CMakeLists.txt
+1
-1
source/libs/parser/inc/astGenerator.h
source/libs/parser/inc/astGenerator.h
+2
-2
source/libs/parser/inc/astToMsg.h
source/libs/parser/inc/astToMsg.h
+2
-0
source/libs/parser/inc/parserUtil.h
source/libs/parser/inc/parserUtil.h
+1
-0
source/libs/parser/src/astGenerator.c
source/libs/parser/src/astGenerator.c
+8
-11
source/libs/parser/src/astToMsg.c
source/libs/parser/src/astToMsg.c
+141
-5
source/libs/parser/src/astValidate.c
source/libs/parser/src/astValidate.c
+104
-57
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+1
-1
source/libs/parser/src/parserUtil.c
source/libs/parser/src/parserUtil.c
+19
-0
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+4
-4
source/libs/planner/CMakeLists.txt
source/libs/planner/CMakeLists.txt
+1
-1
source/libs/qcom/CMakeLists.txt
source/libs/qcom/CMakeLists.txt
+12
-0
source/libs/qcom/inc/queryInt.h
source/libs/qcom/inc/queryInt.h
+0
-0
source/libs/qcom/src/querymsg.c
source/libs/qcom/src/querymsg.c
+0
-0
source/libs/scheduler/CMakeLists.txt
source/libs/scheduler/CMakeLists.txt
+1
-1
未找到文件。
include/common/tname.h
浏览文件 @
4192f1ad
...
...
@@ -16,7 +16,7 @@
#ifndef TDENGINE_TNAME_H
#define TDENGINE_TNAME_H
#include "taosmsg.h"
//
#include "taosmsg.h"
#define TSDB_DB_NAME_T 1
#define TSDB_TABLE_NAME_T 2
...
...
@@ -27,7 +27,7 @@
typedef
struct
SName
{
uint8_t
type
;
//db_name_t, table_name_t
char
acctId
[
TSDB_ACCT_ID_LEN
]
;
int32_t
acctId
;
char
dbname
[
TSDB_DB_NAME_LEN
];
char
tname
[
TSDB_TABLE_NAME_LEN
];
}
SName
;
...
...
@@ -38,7 +38,7 @@ int32_t tNameLen(const SName* name);
SName
*
tNameDup
(
const
SName
*
name
);
bool
t
IsValidName
(
const
SName
*
name
);
bool
t
NameIsValid
(
const
SName
*
name
);
const
char
*
tNameGetTableName
(
const
SName
*
name
);
...
...
@@ -50,14 +50,10 @@ bool tNameIsEmpty(const SName* name);
void
tNameAssign
(
SName
*
dst
,
const
SName
*
src
);
int32_t
tNameFromString
(
SName
*
dst
,
const
char
*
str
,
uint32_t
type
);
int32_t
tNameSetAcctId
(
SName
*
dst
,
const
char
*
acct
);
int32_t
tNameSetDbName
(
SName
*
dst
,
int32_t
acctId
,
const
char
*
dbName
,
size_t
nameLen
);
SSchema
*
tGetTbnameColumnSchema
(
);
int32_t
tNameFromString
(
SName
*
dst
,
const
char
*
str
,
uint32_t
type
);
#if 0
int32_t tNameSetDbName(SName* dst, const char* acct, SToken* dbToken);
#endif
int32_t
tNameSetAcctId
(
SName
*
dst
,
int32_t
acctId
);
#endif // TDENGINE_TNAME_H
include/libs/q
uery
/query.h
→
include/libs/q
com
/query.h
浏览文件 @
4192f1ad
...
...
@@ -84,9 +84,9 @@ typedef struct STableMetaOutput {
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
);
SSchema
*
tGetTbnameColumnSchema
();
extern
void
msgInit
();
extern
int32_t
qDebugFlag
;
#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0)
...
...
source/client/CMakeLists.txt
浏览文件 @
4192f1ad
...
...
@@ -2,14 +2,13 @@ aux_source_directory(src CLIENT_SRC)
add_library
(
taos
${
CLIENT_SRC
}
)
target_include_directories
(
taos
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/client"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/client"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
target_link_libraries
(
taos
PRIVATE common
INTERFACE api
PRIVATE os util common transport parser catalog function q
uery
PRIVATE os util common transport parser catalog function q
com
)
ADD_SUBDIRECTORY
(
test
)
\ No newline at end of file
source/client/inc/clientInt.h
浏览文件 @
4192f1ad
...
...
@@ -76,11 +76,10 @@ typedef struct SAppInfo {
typedef
struct
STscObj
{
char
user
[
TSDB_USER_LEN
];
char
pass
[
TSDB_PASSWORD_LEN
];
char
acctId
[
TSDB_ACCT_ID_LEN
];
char
db
[
TSDB_ACCT_ID_LEN
+
TSDB_DB_NAME_LEN
];
int32_t
acctId
;
uint32_t
connId
;
uint64_t
id
;
// ref ID returned by taosAddRef
// struct SSqlObj *sqlList;
void
*
pTransporter
;
pthread_mutex_t
mutex
;
// used to protect the operation on db
int32_t
numOfReqs
;
// number of sqlObj from this tscObj
...
...
source/client/src/clientImpl.c
浏览文件 @
4192f1ad
...
...
@@ -153,7 +153,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
void
*
output
=
NULL
;
int32_t
outputLen
=
0
;
code
=
qParseQuerySql
(
pRequest
->
sqlstr
,
sqlLen
,
pRequest
->
requestId
,
&
type
,
&
output
,
&
outputLen
,
pRequest
->
msgBuf
,
ERROR_MSG_BUF_DEFAULT_SIZE
);
if
(
type
==
TSDB_SQL_CREATE_USER
||
type
==
TSDB_SQL_SHOW
)
{
if
(
type
==
TSDB_SQL_CREATE_USER
||
type
==
TSDB_SQL_SHOW
||
type
==
TSDB_SQL_DROP_USER
||
type
==
TSDB_SQL_CREATE_DB
)
{
pRequest
->
type
=
type
;
pRequest
->
body
.
param
=
output
;
pRequest
->
body
.
paramLen
=
outputLen
;
...
...
source/client/src/clientMsgHandler.c
浏览文件 @
4192f1ad
...
...
@@ -14,6 +14,7 @@
*/
#include <catalog.h>
#include <tname.h>
#include "clientInt.h"
#include "clientLog.h"
#include "os.h"
...
...
@@ -2885,7 +2886,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg
}
int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool autocreate, bool onlyLocal) {
assert(t
IsValidName
(&pTableMetaInfo->name));
assert(t
NameIsValid
(&pTableMetaInfo->name));
char name[TSDB_TABLE_FNAME_LEN] = {0};
tNameExtractFullName(&pTableMetaInfo->name, name);
...
...
@@ -3138,7 +3139,7 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
// TODO refactor
pthread_mutex_lock
(
&
pTscObj
->
mutex
);
char
temp
[
TSDB_TABLE_FNAME_LEN
*
2
]
=
{
0
};
int32_t
len
=
sprintf
(
temp
,
"%
s
%s%s"
,
pTscObj
->
acctId
,
TS_PATH_DELIMITER
,
pTscObj
->
db
);
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
));
...
...
@@ -3153,6 +3154,7 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
}
pTscObj
->
connId
=
pConnect
->
connId
;
pTscObj
->
acctId
=
pConnect
->
acctId
;
// update the appInstInfo
pTscObj
->
pAppInfo
->
clusterId
=
pConnect
->
clusterId
;
...
...
@@ -3165,19 +3167,33 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
return
0
;
}
int32_t
buildCreateUserMsg
(
SRequestObj
*
pRequest
,
SRequestMsgBody
*
pMsgBody
)
{
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_CREATE_USER
;
pMsgBody
->
msgLen
=
sizeof
(
SCreateUserMsg
);
int32_t
doBuildMsgSupp
(
SRequestObj
*
pRequest
,
SRequestMsgBody
*
pMsgBody
)
{
pMsgBody
->
requestObjRefId
=
pRequest
->
self
;
pMsgBody
->
pData
=
pRequest
->
body
.
param
;
return
0
;
}
int32_t
buildShowMsg
(
SRequestObj
*
pRequest
,
SRequestMsgBody
*
pMsgBody
)
{
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_SHOW
;
pMsgBody
->
msgLen
=
pRequest
->
body
.
paramLen
;
pMsgBody
->
requestObjRefId
=
pRequest
->
self
;
pMsgBody
->
pData
=
pRequest
->
body
.
param
;
switch
(
pRequest
->
type
)
{
case
TSDB_SQL_CREATE_USER
:
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_CREATE_USER
;
break
;
case
TSDB_SQL_CREATE_DB
:
{
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_CREATE_DB
;
SCreateDbMsg
*
pCreateMsg
=
pRequest
->
body
.
param
;
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_SHOW
:
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_SHOW
;
break
;
}
}
STableMeta
*
createTableMetaFromMsg
(
STableMetaMsg
*
pTableMetaMsg
)
{
...
...
@@ -3283,6 +3299,9 @@ int32_t processRetrieveMnodeRsp(SRequestObj *pRequest, const char* pMsg, int32_t
return
0
;
}
int32_t
processCreateDbRsp
(
SRequestObj
*
pRequest
,
const
char
*
pMsg
,
int32_t
msgLen
)
{
// todo rsp with the vnode id list
}
void
initMsgHandleFp
()
{
#if 0
...
...
@@ -3363,11 +3382,14 @@ void initMsgHandleFp() {
buildRequestMsgFp
[
TSDB_SQL_CONNECT
]
=
buildConnectMsg
;
handleRequestRspFp
[
TSDB_SQL_CONNECT
]
=
processConnectRsp
;
buildRequestMsgFp
[
TSDB_SQL_CREATE_USER
]
=
buildCreateUserMsg
;
buildRequestMsgFp
[
TSDB_SQL_CREATE_USER
]
=
doBuildMsgSupp
;
buildRequestMsgFp
[
TSDB_SQL_SHOW
]
=
buildShowMsg
;
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
;
}
\ No newline at end of file
source/client/test/clientTests.cpp
浏览文件 @
4192f1ad
...
...
@@ -57,25 +57,38 @@ TEST(testCase, create_user_Test) {
taos_close
(
pConn
);
}
//TEST(testCase,
show
_user_Test) {
//TEST(testCase,
drop
_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_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_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
,
show_db_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
...
...
@@ -94,3 +107,18 @@ TEST(testCase, show_db_Test) {
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 abc"
);
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
);
}
source/common/src/tname.c
浏览文件 @
4192f1ad
...
...
@@ -4,9 +4,6 @@
#include "tname.h"
#include "taosmsg.h"
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS)
#define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T)
char
*
extractDBName
(
const
char
*
tableId
,
char
*
name
)
{
...
...
@@ -120,84 +117,11 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
#endif
static
struct
SSchema
_s
=
{
.
colId
=
TSDB_TBNAME_COLUMN_INDEX
,
.
type
=
TSDB_DATA_TYPE_BINARY
,
.
bytes
=
TSDB_TABLE_NAME_LEN
+
VARSTR_HEADER_SIZE
,
.
name
=
"tbname"
,
};
SSchema
*
tGetTbnameColumnSchema
()
{
return
&
_s
;
}
static
bool
doValidateSchema
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
maxLen
)
{
int32_t
rowLen
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
// 1. valid types
if
(
!
isValidDataType
(
pSchema
[
i
].
type
))
{
return
false
;
}
// 2. valid length for each type
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
pSchema
[
i
].
bytes
>
TSDB_MAX_BINARY_LEN
)
{
return
false
;
}
}
else
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pSchema
[
i
].
bytes
>
TSDB_MAX_NCHAR_LEN
)
{
return
false
;
}
}
else
{
if
(
pSchema
[
i
].
bytes
!=
tDataTypes
[
pSchema
[
i
].
type
].
bytes
)
{
return
false
;
}
}
// 3. valid column names
for
(
int32_t
j
=
i
+
1
;
j
<
numOfCols
;
++
j
)
{
if
(
strncasecmp
(
pSchema
[
i
].
name
,
pSchema
[
j
].
name
,
sizeof
(
pSchema
[
i
].
name
)
-
1
)
==
0
)
{
return
false
;
}
}
rowLen
+=
pSchema
[
i
].
bytes
;
}
return
rowLen
<=
maxLen
;
}
bool
tIsValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
)
{
if
(
!
VALIDNUMOFCOLS
(
numOfCols
))
{
return
false
;
}
if
(
!
VALIDNUMOFTAGS
(
numOfTags
))
{
return
false
;
}
/* first column must be the timestamp, which is a primary key */
if
(
pSchema
[
0
].
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
return
false
;
}
if
(
!
doValidateSchema
(
pSchema
,
numOfCols
,
TSDB_MAX_BYTES_PER_ROW
))
{
return
false
;
}
if
(
!
doValidateSchema
(
&
pSchema
[
numOfCols
],
numOfTags
,
TSDB_MAX_TAGS_LEN
))
{
return
false
;
}
return
true
;
}
int32_t
tNameExtractFullName
(
const
SName
*
name
,
char
*
dst
)
{
assert
(
name
!=
NULL
&&
dst
!=
NULL
);
// invalid full name format, abort
if
(
!
t
IsValidName
(
name
))
{
if
(
!
t
NameIsValid
(
name
))
{
return
-
1
;
}
...
...
@@ -230,7 +154,7 @@ int32_t tNameLen(const SName* name) {
}
}
bool
t
IsValidName
(
const
SName
*
name
)
{
bool
t
NameIsValid
(
const
SName
*
name
)
{
assert
(
name
!=
NULL
);
if
(
!
VALID_NAME_TYPE
(
name
->
type
))
{
...
...
@@ -265,13 +189,13 @@ int32_t tNameGetDbName(const SName* name, char* dst) {
int32_t
tNameGetFullDbName
(
const
SName
*
name
,
char
*
dst
)
{
assert
(
name
!=
NULL
&&
dst
!=
NULL
);
snprintf
(
dst
,
TSDB_ACCT_ID_LEN
+
TS_PATH_DELIMITER_LEN
+
TSDB_DB_NAME_LEN
,
// there is a over write risk
"%
s
.%s"
,
name
->
acctId
,
name
->
dbname
);
"%
d
.%s"
,
name
->
acctId
,
name
->
dbname
);
return
0
;
}
bool
tNameIsEmpty
(
const
SName
*
name
)
{
assert
(
name
!=
NULL
);
return
name
->
type
==
0
||
strlen
(
name
->
acctId
)
<
=
0
;
return
name
->
type
==
0
||
name
->
acctId
=
=
0
;
}
const
char
*
tNameGetTableName
(
const
SName
*
name
)
{
...
...
@@ -283,32 +207,23 @@ void tNameAssign(SName* dst, const SName* src) {
memcpy
(
dst
,
src
,
sizeof
(
SName
));
}
//int32_t tNameSetDbName(SName* dst, const char* acct, SStrToken* dbToken) {
// assert(dst != NULL && dbToken != NULL && acct != NULL);
//
// // too long account id or too long db name
// if (strlen(acct) >= tListLen(dst->acctId) || dbToken->n >= tListLen(dst->dbname)) {
// return -1;
// }
//
// dst->type = TSDB_DB_NAME_T;
// tstrncpy(dst->acctId, acct, tListLen(dst->acctId));
// tstrncpy(dst->dbname, dbToken->z, dbToken->n + 1);
// return 0;
//}
int32_t
tNameSetAcctId
(
SName
*
dst
,
const
char
*
acct
)
{
assert
(
dst
!=
NULL
&&
acct
!=
NULL
);
int32_t
tNameSetDbName
(
SName
*
dst
,
int32_t
acct
,
const
char
*
dbName
,
size_t
nameLen
)
{
assert
(
dst
!=
NULL
&&
dbName
!=
NULL
&&
nameLen
>
0
);
// too long account id or too long db name
if
(
strlen
(
acct
)
>=
tListLen
(
dst
->
acctId
))
{
if
(
nameLen
>=
tListLen
(
dst
->
dbname
))
{
return
-
1
;
}
tstrncpy
(
dst
->
acctId
,
acct
,
tListLen
(
dst
->
acctId
));
dst
->
type
=
TSDB_DB_NAME_T
;
dst
->
acctId
=
acct
;
tstrncpy
(
dst
->
dbname
,
dbName
,
nameLen
+
1
);
return
0
;
}
assert
(
strlen
(
dst
->
acctId
)
>
0
);
int32_t
tNameSetAcctId
(
SName
*
dst
,
int32_t
acctId
)
{
assert
(
dst
!=
NULL
&&
acct
!=
NULL
);
dst
->
acctId
=
acctId
;
return
0
;
}
...
...
@@ -325,14 +240,11 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
int32_t
len
=
(
int32_t
)(
p
-
str
);
// too long account id or too long db name
if
((
len
>=
tListLen
(
dst
->
acctId
))
||
(
len
<=
0
))
{
return
-
1
;
}
memcpy
(
dst
->
acctId
,
str
,
len
);
dst
->
acctId
[
len
]
=
0
;
assert
(
strlen
(
dst
->
acctId
)
>
0
);
// if ((len >= tListLen(dst->acctId)) || (len <= 0)) {
// return -1;
// }
// memcpy (dst->acctId, str, len);
dst
->
acctId
=
strtoll
(
str
,
NULL
,
10
);
}
if
((
type
&
T_NAME_DB
)
==
T_NAME_DB
)
{
...
...
source/libs/CMakeLists.txt
浏览文件 @
4192f1ad
...
...
@@ -10,4 +10,4 @@ add_subdirectory(catalog)
add_subdirectory
(
executor
)
add_subdirectory
(
planner
)
add_subdirectory
(
function
)
add_subdirectory
(
q
uery
)
add_subdirectory
(
q
com
)
source/libs/catalog/CMakeLists.txt
浏览文件 @
4192f1ad
...
...
@@ -8,7 +8,7 @@ target_include_directories(
target_link_libraries
(
catalog
PRIVATE os util
common transport query
PRIVATE os util
transport qcom
)
ADD_SUBDIRECTORY
(
test
)
\ No newline at end of file
source/libs/parser/CMakeLists.txt
浏览文件 @
4192f1ad
...
...
@@ -8,7 +8,7 @@ target_include_directories(
target_link_libraries
(
parser
PRIVATE os util c
ommon catalog function transport query
PRIVATE os util c
atalog function transport qcom
)
ADD_SUBDIRECTORY
(
test
)
source/libs/parser/inc/astGenerator.h
浏览文件 @
4192f1ad
...
...
@@ -171,8 +171,8 @@ typedef struct SCreateDbInfo {
int8_t
update
;
int8_t
cachelast
;
SArray
*
keep
;
int8_t
dbType
;
int16_t
partitions
;
//
int8_t dbType;
//
int16_t partitions;
}
SCreateDbInfo
;
typedef
struct
SCreateFuncInfo
{
...
...
source/libs/parser/inc/astToMsg.h
浏览文件 @
4192f1ad
...
...
@@ -5,5 +5,7 @@
#include "taosmsg.h"
SCreateUserMsg
*
buildUserManipulationMsg
(
SSqlInfo
*
pInfo
,
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
);
#endif // TDENGINE_ASTTOMSG_H
source/libs/parser/inc/parserUtil.h
浏览文件 @
4192f1ad
...
...
@@ -46,6 +46,7 @@ SInternalField* getInternalField(SFieldInfo* pFieldInfo, int32_t index);
int32_t
parserValidateIdToken
(
SToken
*
pToken
);
int32_t
parserValidatePassword
(
SToken
*
pToken
,
SMsgBuf
*
pMsgBuf
);
int32_t
parserValidateNameToken
(
SToken
*
pToken
);
int32_t
buildInvalidOperationMsg
(
SMsgBuf
*
pMsgBuf
,
const
char
*
msg
);
int32_t
buildSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
);
...
...
source/libs/parser/src/astGenerator.c
浏览文件 @
4192f1ad
...
...
@@ -948,27 +948,24 @@ void setCompactVnodeSql(SSqlInfo *pInfo, int32_t type, SArray *pParam) {
void
setDefaultCreateDbOption
(
SCreateDbInfo
*
pDBInfo
)
{
pDBInfo
->
compressionLevel
=
-
1
;
pDBInfo
->
walLevel
=
-
1
;
pDBInfo
->
walLevel
=
-
1
;
pDBInfo
->
fsyncPeriod
=
-
1
;
pDBInfo
->
commitTime
=
-
1
;
pDBInfo
->
commitTime
=
-
1
;
pDBInfo
->
maxTablesPerVnode
=
-
1
;
pDBInfo
->
cacheBlockSize
=
-
1
;
pDBInfo
->
numOfBlocks
=
-
1
;
pDBInfo
->
cacheBlockSize
=
-
1
;
pDBInfo
->
numOfBlocks
=
-
1
;
pDBInfo
->
maxRowsPerBlock
=
-
1
;
pDBInfo
->
minRowsPerBlock
=
-
1
;
pDBInfo
->
daysPerFile
=
-
1
;
pDBInfo
->
daysPerFile
=
-
1
;
pDBInfo
->
replica
=
-
1
;
pDBInfo
->
quorum
=
-
1
;
pDBInfo
->
keep
=
NULL
;
pDBInfo
->
quorum
=
-
1
;
pDBInfo
->
keep
=
NULL
;
pDBInfo
->
update
=
-
1
;
pDBInfo
->
update
=
-
1
;
pDBInfo
->
cachelast
=
-
1
;
pDBInfo
->
dbType
=
-
1
;
pDBInfo
->
partitions
=
-
1
;
memset
(
&
pDBInfo
->
precision
,
0
,
sizeof
(
SToken
));
}
...
...
source/libs/parser/src/astToMsg.c
浏览文件 @
4192f1ad
#include "parserInt.h"
#include "parserUtil.h"
SCreateUserMsg
*
buildUserManipulationMsg
(
SSqlInfo
*
pInfo
,
int64_t
id
,
char
*
msgBuf
,
int32_t
msgLen
)
{
SCreateUserMsg
*
pMsg
=
(
SCreateUserMsg
*
)
calloc
(
1
,
sizeof
(
SCreateUserMsg
));
SCreateUserMsg
*
pMsg
=
(
SCreateUserMsg
*
)
calloc
(
1
,
sizeof
(
SCreateUserMsg
));
if
(
pMsg
==
NULL
)
{
// tscError("0x%" PRIx64 " failed to malloc for query msg", id);
// tscError("0x%" PRIx64 " failed to malloc for query msg", id);
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
NULL
;
}
SUserInfo
*
pUser
=
&
pInfo
->
pMiscInfo
->
user
;
SUserInfo
*
pUser
=
&
pInfo
->
pMiscInfo
->
user
;
strncpy
(
pMsg
->
user
,
pUser
->
user
.
z
,
pUser
->
user
.
n
);
pMsg
->
type
=
pUser
->
type
;
pMsg
->
superUser
=
(
int8_t
)
pUser
->
type
;
if
(
pUser
->
type
==
TSDB_ALTER_USER_PRIVILEGES
)
{
// pMsg->privilege = (char)pCmd->count;
// pMsg->privilege = (char)pCmd->count;
}
else
{
strncpy
(
pMsg
->
pass
,
pUser
->
passwd
.
z
,
pUser
->
passwd
.
n
);
}
return
pMsg
;
}
\ No newline at end of file
}
SShowMsg
*
buildShowMsg
(
SShowInfo
*
pShowInfo
,
int64_t
id
,
char
*
msgBuf
,
int32_t
msgLen
)
{
SShowMsg
*
pShowMsg
=
calloc
(
1
,
sizeof
(
SShowMsg
));
pShowMsg
->
type
=
pShowInfo
->
showType
;
if
(
pShowInfo
->
showType
!=
TSDB_MGMT_TABLE_VNODES
)
{
SToken
*
pPattern
=
&
pShowInfo
->
pattern
;
if
(
pPattern
->
type
>
0
)
{
// only show tables support wildcard query
strncpy
(
pShowMsg
->
payload
,
pPattern
->
z
,
pPattern
->
n
);
pShowMsg
->
payloadLen
=
htons
(
pPattern
->
n
);
}
}
else
{
SToken
*
pEpAddr
=
&
pShowInfo
->
prefix
;
assert
(
pEpAddr
->
n
>
0
&&
pEpAddr
->
type
>
0
);
strncpy
(
pShowMsg
->
payload
,
pEpAddr
->
z
,
pEpAddr
->
n
);
pShowMsg
->
payloadLen
=
htons
(
pEpAddr
->
n
);
}
return
pShowMsg
;
}
static
int32_t
setKeepOption
(
SCreateDbMsg
*
pMsg
,
const
SCreateDbInfo
*
pCreateDb
,
SMsgBuf
*
pMsgBuf
)
{
const
char
*
msg1
=
"invalid number of keep options"
;
const
char
*
msg2
=
"invalid keep value"
;
const
char
*
msg3
=
"invalid keep value, should be keep0 <= keep1 <= keep2"
;
pMsg
->
daysToKeep0
=
htonl
(
-
1
);
pMsg
->
daysToKeep1
=
htonl
(
-
1
);
pMsg
->
daysToKeep2
=
htonl
(
-
1
);
SArray
*
pKeep
=
pCreateDb
->
keep
;
if
(
pKeep
!=
NULL
)
{
size_t
s
=
taosArrayGetSize
(
pKeep
);
#ifdef _STORAGE
if
(
s
>=
4
||
s
<=
0
)
{
#else
if
(
s
!=
1
)
{
#endif
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
}
// tListI* p0 = taosArrayGet(pKeep, 0);
// tVariantListItem* p1 = (s > 1) ? taosArrayGet(pKeep, 1) : p0;
// tVariantListItem* p2 = (s > 2) ? taosArrayGet(pKeep, 2) : p1;
//
// if ((int32_t)p0->pVar.i64 <= 0 || (int32_t)p1->pVar.i64 <= 0 || (int32_t)p2->pVar.i64 <= 0) {
// return buildInvalidOperationMsg(pMsgBuf, msg2);
// }
// if (!(((int32_t)p0->pVar.i64 <= (int32_t)p1->pVar.i64) && ((int32_t)p1->pVar.i64 <= (int32_t)p2->pVar.i64))) {
// return buildInvalidOperationMsg(pMsgBuf, msg3);
// }
//
// pMsg->daysToKeep0 = htonl((int32_t)p0->pVar.i64);
// pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64);
// pMsg->daysToKeep2 = htonl((int32_t)p2->pVar.i64);
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
setTimePrecision
(
SCreateDbMsg
*
pMsg
,
const
SCreateDbInfo
*
pCreateDbInfo
,
SMsgBuf
*
pMsgBuf
)
{
const
char
*
msg
=
"invalid time precision"
;
pMsg
->
precision
=
TSDB_TIME_PRECISION_MILLI
;
// millisecond by default
SToken
*
pToken
=
&
pCreateDbInfo
->
precision
;
if
(
pToken
->
n
>
0
)
{
pToken
->
n
=
strdequote
(
pToken
->
z
);
if
(
strncmp
(
pToken
->
z
,
TSDB_TIME_PRECISION_MILLI_STR
,
pToken
->
n
)
==
0
&&
strlen
(
TSDB_TIME_PRECISION_MILLI_STR
)
==
pToken
->
n
)
{
// time precision for this db: million second
pMsg
->
precision
=
TSDB_TIME_PRECISION_MILLI
;
}
else
if
(
strncmp
(
pToken
->
z
,
TSDB_TIME_PRECISION_MICRO_STR
,
pToken
->
n
)
==
0
&&
strlen
(
TSDB_TIME_PRECISION_MICRO_STR
)
==
pToken
->
n
)
{
pMsg
->
precision
=
TSDB_TIME_PRECISION_MICRO
;
}
else
if
(
strncmp
(
pToken
->
z
,
TSDB_TIME_PRECISION_NANO_STR
,
pToken
->
n
)
==
0
&&
strlen
(
TSDB_TIME_PRECISION_NANO_STR
)
==
pToken
->
n
)
{
pMsg
->
precision
=
TSDB_TIME_PRECISION_NANO
;
}
else
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
}
}
return
TSDB_CODE_SUCCESS
;
}
static
void
doSetDbOptions
(
SCreateDbMsg
*
pMsg
,
const
SCreateDbInfo
*
pCreateDb
)
{
pMsg
->
cacheBlockSize
=
htonl
(
pCreateDb
->
cacheBlockSize
);
pMsg
->
totalBlocks
=
htonl
(
pCreateDb
->
numOfBlocks
);
pMsg
->
daysPerFile
=
htonl
(
pCreateDb
->
daysPerFile
);
pMsg
->
commitTime
=
htonl
((
int32_t
)
pCreateDb
->
commitTime
);
pMsg
->
minRowsPerFileBlock
=
htonl
(
pCreateDb
->
minRowsPerBlock
);
pMsg
->
maxRowsPerFileBlock
=
htonl
(
pCreateDb
->
maxRowsPerBlock
);
pMsg
->
fsyncPeriod
=
htonl
(
pCreateDb
->
fsyncPeriod
);
pMsg
->
compression
=
pCreateDb
->
compressionLevel
;
pMsg
->
walLevel
=
(
char
)
pCreateDb
->
walLevel
;
pMsg
->
replications
=
pCreateDb
->
replica
;
pMsg
->
quorum
=
pCreateDb
->
quorum
;
pMsg
->
ignoreExist
=
pCreateDb
->
ignoreExists
;
pMsg
->
update
=
pCreateDb
->
update
;
pMsg
->
cacheLastRow
=
pCreateDb
->
cachelast
;
}
int32_t
setDbOptions
(
SCreateDbMsg
*
pCreateDbMsg
,
const
SCreateDbInfo
*
pCreateDbSql
,
SMsgBuf
*
pMsgBuf
)
{
doSetDbOptions
(
pCreateDbMsg
,
pCreateDbSql
);
if
(
setKeepOption
(
pCreateDbMsg
,
pCreateDbSql
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
setTimePrecision
(
pCreateDbMsg
,
pCreateDbSql
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// todo configurable
pCreateDbMsg
->
numOfVgroups
=
htonl
(
2
);
return
TSDB_CODE_SUCCESS
;
}
SCreateDbMsg
*
buildCreateDbMsg
(
SCreateDbInfo
*
pCreateDbInfo
,
char
*
msgBuf
,
int32_t
msgLen
)
{
SCreateDbMsg
*
pCreateMsg
=
calloc
(
1
,
sizeof
(
SCreateDbMsg
));
SMsgBuf
msg
=
{.
buf
=
msgBuf
,
.
len
=
msgLen
};
if
(
setDbOptions
(
pCreateMsg
,
pCreateDbInfo
,
&
msg
)
!=
TSDB_CODE_SUCCESS
)
{
tfree
(
pCreateMsg
);
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
return
pCreateMsg
;
}
source/libs/parser/src/astValidate.c
浏览文件 @
4192f1ad
...
...
@@ -759,11 +759,6 @@ int32_t validateIntervalNode(SQueryStmtInfo *pQueryInfo, SSqlNode* pSqlNode, SMs
// It is a time window query
pQueryInfo
->
info
.
timewindow
=
true
;
return
TSDB_CODE_SUCCESS
;
// disable it temporarily
// bool interpQuery = tscIsPointInterpQuery(pQueryInfo);
// if ((pSqlNode->interval.token == TK_EVERY && (!interpQuery)) || (pSqlNode->interval.token == TK_INTERVAL && interpQuery)) {
// return buildInvalidOperationMsg(pMsgBuf, msg4);
// }
}
int32_t
validateSessionNode
(
SQueryStmtInfo
*
pQueryInfo
,
SSessionWindowVal
*
pSession
,
int32_t
precision
,
SMsgBuf
*
pMsgBuf
)
{
...
...
@@ -3707,14 +3702,6 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer
return TSDB_CODE_SUCCESS;
}
case TSDB_SQL_SHOW: {
if (setShowInfo(pSql, pInfo) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
}
case TSDB_SQL_CREATE_FUNCTION:
case TSDB_SQL_DROP_FUNCTION: {
code = handleUserDefinedFunc(pSql, pInfo);
...
...
@@ -3725,35 +3712,6 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer
break;
}
case TSDB_SQL_ALTER_DB:
case TSDB_SQL_CREATE_DB: {
const char* msg1 = "invalid db name";
const char* msg2 = "name too long";
SCreateDbInfo* pCreateDB = &(pInfo->pMiscInfo->dbOpt);
if (pCreateDB->dbname.n >= TSDB_DB_NAME_LEN) {
return buildInvalidOperationMsg(pMsgBuf, msg2);
}
char buf[TSDB_DB_NAME_LEN] = {0};
SToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf));
if (tscValidateName(&token) != TSDB_CODE_SUCCESS) {
return buildInvalidOperationMsg(pMsgBuf, msg1);
}
int32_t ret = tNameSetDbName(&pTableMetaInfo->name, getAccountId(pSql), &token);
if (ret != TSDB_CODE_SUCCESS) {
return buildInvalidOperationMsg(pMsgBuf, msg2);
}
if (parseCreateDBOptions(pCmd, pCreateDB) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
}
case TSDB_SQL_CREATE_DNODE: {
const char* msg = "invalid host name (ip address)";
...
...
@@ -4133,28 +4091,87 @@ static int32_t setShowInfo(struct SSqlInfo* pInfo, void** output, int32_t* msgLe
}
}
SShowMsg
*
pShowMsg
=
calloc
(
1
,
sizeof
(
SShowMsg
));
pShowMsg
->
type
=
pShowInfo
->
showType
;
*
output
=
buildShowMsg
(
pShowInfo
,
0
,
pMsgBuf
->
buf
,
pMsgBuf
->
len
);
*
msgLen
=
sizeof
(
SShowMsg
)
/* + htons(pShowMsg->payloadLen)*/
;
return
TSDB_CODE_SUCCESS
;
}
// can only perform the parameters based on the macro definitation
static
int32_t
doCheckDbOptions
(
SCreateDbMsg
*
pCreate
,
SMsgBuf
*
pMsgBuf
)
{
char
msg
[
512
]
=
{
0
};
if
(
pShowInfo
->
showType
!=
TSDB_MGMT_TABLE_VNODES
)
{
SToken
*
pPattern
=
&
pShowInfo
->
pattern
;
if
(
pPattern
->
type
>
0
)
{
// only show tables support wildcard query
strncpy
(
pShowMsg
->
payload
,
pPattern
->
z
,
pPattern
->
n
);
pShowMsg
->
payloadLen
=
htons
(
pPattern
->
n
);
}
}
else
{
SToken
*
pEpAddr
=
&
pShowInfo
->
prefix
;
assert
(
pEpAddr
->
n
>
0
&&
pEpAddr
->
type
>
0
);
if
(
pCreate
->
walLevel
!=
-
1
&&
(
pCreate
->
walLevel
<
TSDB_MIN_WAL_LEVEL
||
pCreate
->
walLevel
>
TSDB_MAX_WAL_LEVEL
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option walLevel: %d, only 1-2 allowed"
,
pCreate
->
walLevel
);
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
}
strncpy
(
pShowMsg
->
payload
,
pEpAddr
->
z
,
pEpAddr
->
n
);
pShowMsg
->
payloadLen
=
htons
(
pEpAddr
->
n
);
if
(
pCreate
->
replications
!=
-
1
&&
(
pCreate
->
replications
<
TSDB_MIN_DB_REPLICA_OPTION
||
pCreate
->
replications
>
TSDB_MAX_DB_REPLICA_OPTION
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option replications: %d valid range: [%d, %d]"
,
pCreate
->
replications
,
TSDB_MIN_DB_REPLICA_OPTION
,
TSDB_MAX_DB_REPLICA_OPTION
);
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
}
int32_t
blocks
=
ntohl
(
pCreate
->
totalBlocks
);
if
(
blocks
!=
-
1
&&
(
blocks
<
TSDB_MIN_TOTAL_BLOCKS
||
blocks
>
TSDB_MAX_TOTAL_BLOCKS
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option totalBlocks: %d valid range: [%d, %d]"
,
blocks
,
TSDB_MIN_TOTAL_BLOCKS
,
TSDB_MAX_TOTAL_BLOCKS
);
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
}
if
(
pCreate
->
quorum
!=
-
1
&&
(
pCreate
->
quorum
<
TSDB_MIN_DB_QUORUM_OPTION
||
pCreate
->
quorum
>
TSDB_MAX_DB_QUORUM_OPTION
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option quorum: %d valid range: [%d, %d]"
,
pCreate
->
quorum
,
TSDB_MIN_DB_QUORUM_OPTION
,
TSDB_MAX_DB_QUORUM_OPTION
);
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
}
int32_t
val
=
htonl
(
pCreate
->
daysPerFile
);
if
(
val
!=
-
1
&&
(
val
<
TSDB_MIN_DAYS_PER_FILE
||
val
>
TSDB_MAX_DAYS_PER_FILE
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option daysPerFile: %d valid range: [%d, %d]"
,
val
,
TSDB_MIN_DAYS_PER_FILE
,
TSDB_MAX_DAYS_PER_FILE
);
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
}
val
=
htonl
(
pCreate
->
cacheBlockSize
);
if
(
val
!=
-
1
&&
(
val
<
TSDB_MIN_CACHE_BLOCK_SIZE
||
val
>
TSDB_MAX_CACHE_BLOCK_SIZE
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option cacheBlockSize: %d valid range: [%d, %d]"
,
val
,
TSDB_MIN_CACHE_BLOCK_SIZE
,
TSDB_MAX_CACHE_BLOCK_SIZE
);
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
}
if
(
pCreate
->
precision
!=
TSDB_TIME_PRECISION_MILLI
&&
pCreate
->
precision
!=
TSDB_TIME_PRECISION_MICRO
&&
pCreate
->
precision
!=
TSDB_TIME_PRECISION_NANO
)
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option timePrecision: %d valid value: [%d, %d, %d]"
,
pCreate
->
precision
,
TSDB_TIME_PRECISION_MILLI
,
TSDB_TIME_PRECISION_MICRO
,
TSDB_TIME_PRECISION_NANO
);
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
}
val
=
htonl
(
pCreate
->
commitTime
);
if
(
val
!=
-
1
&&
(
val
<
TSDB_MIN_COMMIT_TIME
||
val
>
TSDB_MAX_COMMIT_TIME
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option commitTime: %d valid range: [%d, %d]"
,
val
,
TSDB_MIN_COMMIT_TIME
,
TSDB_MAX_COMMIT_TIME
);
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
}
val
=
htonl
(
pCreate
->
fsyncPeriod
);
if
(
val
!=
-
1
&&
(
val
<
TSDB_MIN_FSYNC_PERIOD
||
val
>
TSDB_MAX_FSYNC_PERIOD
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option fsyncPeriod: %d valid range: [%d, %d]"
,
val
,
TSDB_MIN_FSYNC_PERIOD
,
TSDB_MAX_FSYNC_PERIOD
);
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
}
if
(
pCreate
->
compression
!=
-
1
&&
(
pCreate
->
compression
<
TSDB_MIN_COMP_LEVEL
||
pCreate
->
compression
>
TSDB_MAX_COMP_LEVEL
))
{
snprintf
(
msg
,
tListLen
(
msg
),
"invalid db option compression: %d valid range: [%d, %d]"
,
pCreate
->
compression
,
TSDB_MIN_COMP_LEVEL
,
TSDB_MAX_COMP_LEVEL
);
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg
);
}
*
output
=
pShowMsg
;
*
msgLen
=
sizeof
(
SShowMsg
)
+
htons
(
pShowMsg
->
payloadLen
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
qParserValidateDclSqlNode
(
SSqlInfo
*
pInfo
,
int64_t
id
,
void
**
output
,
int32_t
*
outputLen
,
int32_t
*
type
,
char
*
msgBuf
,
int32_t
msgBufLen
)
{
int32_t
code
=
0
;
...
...
@@ -4216,6 +4233,36 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, int64_t id, void** output, in
code
=
setShowInfo
(
pInfo
,
output
,
outputLen
,
pMsgBuf
);
break
;
}
case
TSDB_SQL_ALTER_DB
:
case
TSDB_SQL_CREATE_DB
:
{
const
char
*
msg1
=
"invalid db name"
;
const
char
*
msg2
=
"name too long"
;
SCreateDbInfo
*
pCreateDB
=
&
(
pInfo
->
pMiscInfo
->
dbOpt
);
if
(
pCreateDB
->
dbname
.
n
>=
TSDB_DB_NAME_LEN
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg2
);
}
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
);
}
SCreateDbMsg
*
pCreateMsg
=
buildCreateDbMsg
(
pCreateDB
,
pMsgBuf
->
buf
,
pMsgBuf
->
len
);
if
(
doCheckDbOptions
(
pCreateMsg
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
strncpy
(
pCreateMsg
->
db
,
token
.
z
,
token
.
n
);
*
output
=
pCreateMsg
;
*
outputLen
=
sizeof
(
SCreateDbMsg
);
break
;
}
default:
break
;
}
...
...
source/libs/parser/src/parser.c
浏览文件 @
4192f1ad
...
...
@@ -77,7 +77,7 @@ static int32_t tnameComparFn(const void* p1, const void* p2) {
SName
*
pn1
=
(
SName
*
)
p1
;
SName
*
pn2
=
(
SName
*
)
p2
;
int32_t
ret
=
strncmp
(
pn1
->
acctId
,
pn2
->
acctId
,
tListLen
(
pn1
->
acctId
))
;
int32_t
ret
=
pn1
->
acctId
-
pn2
->
acctId
;
if
(
ret
!=
0
)
{
return
ret
>
0
?
1
:-
1
;
}
else
{
...
...
source/libs/parser/src/parserUtil.c
浏览文件 @
4192f1ad
...
...
@@ -122,6 +122,25 @@ int32_t parserValidatePassword(SToken* pToken, SMsgBuf* pMsgBuf) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
parserValidateNameToken
(
SToken
*
pToken
)
{
if
(
pToken
==
NULL
||
pToken
->
z
==
NULL
||
pToken
->
type
!=
TK_ID
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// it is a token quoted with escape char '`'
if
(
pToken
->
z
[
0
]
==
TS_ESCAPE_CHAR
&&
pToken
->
z
[
pToken
->
n
-
1
]
==
TS_ESCAPE_CHAR
)
{
return
TSDB_CODE_SUCCESS
;
}
char
*
sep
=
strnchr
(
pToken
->
z
,
TS_PATH_DELIMITER
[
0
],
pToken
->
n
,
true
);
if
(
sep
!=
NULL
)
{
// It is a complex type, not allow
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
strntolower
(
pToken
->
z
,
pToken
->
z
,
pToken
->
n
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
buildInvalidOperationMsg
(
SMsgBuf
*
pBuf
,
const
char
*
msg
)
{
strncpy
(
pBuf
->
buf
,
msg
,
pBuf
->
len
);
return
TSDB_CODE_TSC_INVALID_OPERATION
;
...
...
source/libs/parser/src/sql.c
浏览文件 @
4192f1ad
...
...
@@ -2519,7 +2519,7 @@ static void yy_reduce(
{
yymsp
[
-
1
].
minor
.
yy0
=
yymsp
[
0
].
minor
.
yy0
;
}
break
;
case
105
:
/* db_optr ::= */
{
setDefaultCreateDbOption
(
&
yymsp
[
1
].
minor
.
yy256
);
yymsp
[
1
].
minor
.
yy256
.
dbType
=
TSDB_DB_TYPE_DEFAULT
;
}
{
setDefaultCreateDbOption
(
&
yymsp
[
1
].
minor
.
yy256
);}
break
;
case
106
:
/* db_optr ::= db_optr cache */
{
yylhsminor
.
yy256
=
yymsp
[
-
1
].
minor
.
yy256
;
yylhsminor
.
yy256
.
cacheBlockSize
=
strtol
(
yymsp
[
0
].
minor
.
yy0
.
z
,
NULL
,
10
);
}
...
...
@@ -2590,16 +2590,16 @@ static void yy_reduce(
break
;
case
121
:
/* topic_optr ::= db_optr */
case
131
:
/* alter_topic_optr ::= alter_db_optr */
yytestcase
(
yyruleno
==
131
);
{
yylhsminor
.
yy256
=
yymsp
[
0
].
minor
.
yy256
;
yylhsminor
.
yy256
.
dbType
=
TSDB_DB_TYPE_TOPIC
;
}
{
yylhsminor
.
yy256
=
yymsp
[
0
].
minor
.
yy256
;}
yymsp
[
0
].
minor
.
yy256
=
yylhsminor
.
yy256
;
break
;
case
122
:
/* topic_optr ::= topic_optr partitions */
case
132
:
/* alter_topic_optr ::= alter_topic_optr partitions */
yytestcase
(
yyruleno
==
132
);
{
yylhsminor
.
yy256
=
yymsp
[
-
1
].
minor
.
yy256
;
yylhsminor
.
yy256
.
partitions
=
strtol
(
yymsp
[
0
].
minor
.
yy0
.
z
,
NULL
,
10
);
}
{
yylhsminor
.
yy256
=
yymsp
[
-
1
].
minor
.
yy256
;
}
yymsp
[
-
1
].
minor
.
yy256
=
yylhsminor
.
yy256
;
break
;
case
123
:
/* alter_db_optr ::= */
{
setDefaultCreateDbOption
(
&
yymsp
[
1
].
minor
.
yy256
);
yymsp
[
1
].
minor
.
yy256
.
dbType
=
TSDB_DB_TYPE_DEFAULT
;
}
{
setDefaultCreateDbOption
(
&
yymsp
[
1
].
minor
.
yy256
);
}
break
;
case
133
:
/* typename ::= ids */
{
...
...
source/libs/planner/CMakeLists.txt
浏览文件 @
4192f1ad
...
...
@@ -8,7 +8,7 @@ target_include_directories(
target_link_libraries
(
planner
PRIVATE os util c
ommon cjson catalog
parser transport function query
PRIVATE os util c
atalog cjson
parser transport function query
)
ADD_SUBDIRECTORY
(
test
)
source/libs/q
uery
/CMakeLists.txt
→
source/libs/q
com
/CMakeLists.txt
浏览文件 @
4192f1ad
aux_source_directory
(
src QUERY_SRC
)
add_library
(
q
uery
${
QUERY_SRC
}
)
add_library
(
q
com
${
QUERY_SRC
}
)
target_include_directories
(
q
uery
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/q
uery
"
q
com
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/q
com
"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
target_link_libraries
(
q
uery
PRIVATE os util
common
transport
q
com
PRIVATE os util transport
)
source/libs/q
uery
/inc/queryInt.h
→
source/libs/q
com
/inc/queryInt.h
浏览文件 @
4192f1ad
文件已移动
source/libs/q
uery
/src/querymsg.c
→
source/libs/q
com
/src/querymsg.c
浏览文件 @
4192f1ad
文件已移动
source/libs/scheduler/CMakeLists.txt
浏览文件 @
4192f1ad
...
...
@@ -9,5 +9,5 @@ target_include_directories(
target_link_libraries
(
scheduler
PRIVATE os util planner
common query
PRIVATE os util planner
qcom
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录