Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
1ecf9659
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1ecf9659
编写于
1月 20, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-225]refactor
上级
bd25e9e9
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
191 addition
and
187 deletion
+191
-187
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+70
-58
src/client/src/tscServer.c
src/client/src/tscServer.c
+12
-10
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+29
-34
src/query/inc/sql.y
src/query/inc/sql.y
+13
-13
src/query/src/qParserImpl.c
src/query/src/qParserImpl.c
+55
-60
src/query/src/sql.c
src/query/src/sql.c
+12
-12
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
1ecf9659
...
...
@@ -100,8 +100,8 @@ static int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd, SQueryInfo* pQueryI
static
int32_t
validateFunctionsInIntervalOrGroupbyQuery
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
validateArithmeticSQLExpr
(
SSqlCmd
*
pCmd
,
tSQLExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
);
static
int32_t
validateEp
(
char
*
ep
);
static
int32_t
validateDNodeConfig
(
tDCLSQL
*
pOptions
);
static
int32_t
validateLocalConfig
(
tDCLSQL
*
pOptions
);
static
int32_t
validateDNodeConfig
(
SMiscInfo
*
pOptions
);
static
int32_t
validateLocalConfig
(
SMiscInfo
*
pOptions
);
static
int32_t
validateColumnName
(
char
*
name
);
static
int32_t
setKillInfo
(
SSqlObj
*
pSql
,
struct
SSqlInfo
*
pInfo
,
int32_t
killType
);
...
...
@@ -110,7 +110,7 @@ static bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo);
static
bool
hasNormalColumnFilter
(
SQueryInfo
*
pQueryInfo
);
static
int32_t
parseLimitClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
int32_t
index
,
SQuerySQL
*
pQuerySql
,
SSqlObj
*
pSql
);
static
int32_t
parseCreateDBOptions
(
SSqlCmd
*
pCmd
,
SCreateD
B
Info
*
pCreateDbSql
);
static
int32_t
parseCreateDBOptions
(
SSqlCmd
*
pCmd
,
SCreateD
b
Info
*
pCreateDbSql
);
static
int32_t
getColumnIndexByName
(
SSqlCmd
*
pCmd
,
const
SStrToken
*
pToken
,
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
);
static
int32_t
getTableIndexByName
(
SStrToken
*
pToken
,
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
);
static
int32_t
optrToString
(
tSQLExpr
*
pExpr
,
char
**
exprString
);
...
...
@@ -239,7 +239,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
!
pInfo
->
valid
||
terrno
==
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
)
{
terrno
=
TSDB_CODE_SUCCESS
;
// clear the error number
return
tscSQLSyntaxErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
NULL
,
pInfo
->
pzErrM
sg
);
return
tscSQLSyntaxErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
NULL
,
pInfo
->
m
sg
);
}
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetailSafely
(
pCmd
,
pCmd
->
clauseIndex
);
...
...
@@ -265,20 +265,20 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg2
=
"invalid name"
;
const
char
*
msg3
=
"param name too long"
;
SStrToken
*
pzName
=
&
pInfo
->
pDCLInfo
->
a
[
0
]
;
SStrToken
*
pzName
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
)
;
if
((
pInfo
->
type
!=
TSDB_SQL_DROP_DNODE
)
&&
(
tscValidateName
(
pzName
)
!=
TSDB_CODE_SUCCESS
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
if
(
pInfo
->
type
==
TSDB_SQL_DROP_DB
)
{
assert
(
pInfo
->
pDCLInfo
->
nTokens
==
1
);
assert
(
taosArrayGetSize
(
pInfo
->
pMiscInfo
->
a
)
==
1
);
code
=
tNameSetDbName
(
&
pTableMetaInfo
->
name
,
getAccountId
(
pSql
),
pzName
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
}
else
if
(
pInfo
->
type
==
TSDB_SQL_DROP_TABLE
)
{
assert
(
pInfo
->
pDCLInfo
->
nTokens
==
1
);
assert
(
taosArrayGetSize
(
pInfo
->
pMiscInfo
->
a
)
==
1
);
code
=
tscSetTableFullName
(
pTableMetaInfo
,
pzName
,
pSql
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -300,7 +300,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
case
TSDB_SQL_USE_DB
:
{
const
char
*
msg
=
"invalid db name"
;
SStrToken
*
pToken
=
&
pInfo
->
pDCLInfo
->
a
[
0
]
;
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
)
;
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
...
...
@@ -331,7 +331,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg1
=
"invalid db name"
;
const
char
*
msg2
=
"name too long"
;
SCreateD
BInfo
*
pCreateDB
=
&
(
pInfo
->
pDCL
Info
->
dbOpt
);
SCreateD
bInfo
*
pCreateDB
=
&
(
pInfo
->
pMisc
Info
->
dbOpt
);
if
(
tscValidateName
(
&
pCreateDB
->
dbname
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -348,15 +348,15 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
break
;
}
case
TSDB_SQL_CREATE_DNODE
:
{
// todo hostname
case
TSDB_SQL_CREATE_DNODE
:
{
const
char
*
msg
=
"invalid host name (ip address)"
;
if
(
pInfo
->
pDCLInfo
->
nTokens
>
1
)
{
if
(
taosArrayGetSize
(
pInfo
->
pMiscInfo
->
a
)
>
1
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
}
SStrToken
*
pIpAddr
=
&
pInfo
->
pDCLInfo
->
a
[
0
]
;
pIpAddr
->
n
=
strdequote
(
pIpAddr
->
z
);
SStrToken
*
id
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
)
;
id
->
n
=
strdequote
(
id
->
z
);
break
;
}
...
...
@@ -366,8 +366,8 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg2
=
"invalid user/account name"
;
const
char
*
msg3
=
"name too long"
;
SStrToken
*
pName
=
&
pInfo
->
p
DCL
Info
->
user
.
user
;
SStrToken
*
pPwd
=
&
pInfo
->
p
DCL
Info
->
user
.
passwd
;
SStrToken
*
pName
=
&
pInfo
->
p
Misc
Info
->
user
.
user
;
SStrToken
*
pPwd
=
&
pInfo
->
p
Misc
Info
->
user
.
passwd
;
if
(
handlePassword
(
pCmd
,
pPwd
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
...
...
@@ -381,7 +381,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
SCreateAcct
SQL
*
pAcctOpt
=
&
pInfo
->
pDCL
Info
->
acctOpt
;
SCreateAcct
Info
*
pAcctOpt
=
&
pInfo
->
pMisc
Info
->
acctOpt
;
if
(
pAcctOpt
->
stat
.
n
>
0
)
{
if
(
pAcctOpt
->
stat
.
z
[
0
]
==
'r'
&&
pAcctOpt
->
stat
.
n
==
1
)
{
}
else
if
(
pAcctOpt
->
stat
.
z
[
0
]
==
'w'
&&
pAcctOpt
->
stat
.
n
==
1
)
{
...
...
@@ -396,10 +396,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
case
TSDB_SQL_DESCRIBE_TABLE
:
{
SStrToken
*
pToken
=
&
pInfo
->
pDCLInfo
->
a
[
0
];
const
char
*
msg1
=
"invalid table name"
;
const
char
*
msg2
=
"table name too long"
;
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -417,10 +417,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
tscGetTableMeta
(
pSql
,
pTableMetaInfo
);
}
case
TSDB_SQL_SHOW_CREATE_TABLE
:
{
SStrToken
*
pToken
=
&
pInfo
->
pDCLInfo
->
a
[
0
];
const
char
*
msg1
=
"invalid table name"
;
const
char
*
msg2
=
"table name is too long"
;
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -438,11 +438,12 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
case
TSDB_SQL_SHOW_CREATE_DATABASE
:
{
const
char
*
msg1
=
"invalid database name"
;
SStrToken
*
pToken
=
&
pInfo
->
pDCLInfo
->
a
[
0
];
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
pToken
->
n
>
TSDB_DB_NAME_LEN
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -454,29 +455,33 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg3
=
"invalid dnode ep"
;
/* validate the ip address */
tDCLSQL
*
pDCL
=
pInfo
->
pDCL
Info
;
SMiscInfo
*
pMiscInfo
=
pInfo
->
pMisc
Info
;
/* validate the parameter names and options */
if
(
validateDNodeConfig
(
p
DCL
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
validateDNodeConfig
(
p
MiscInfo
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
char
*
pMsg
=
pCmd
->
payload
;
SCfgDnodeMsg
*
pCfg
=
(
SCfgDnodeMsg
*
)
pMsg
;
pDCL
->
a
[
0
].
n
=
strdequote
(
pDCL
->
a
[
0
].
z
);
strncpy
(
pCfg
->
ep
,
pDCL
->
a
[
0
].
z
,
pDCL
->
a
[
0
].
n
);
SStrToken
*
t0
=
taosArrayGet
(
pMiscInfo
->
a
,
0
);
SStrToken
*
t1
=
taosArrayGet
(
pMiscInfo
->
a
,
1
);
SStrToken
*
t2
=
taosArrayGet
(
pMiscInfo
->
a
,
2
);
t0
->
n
=
strdequote
(
t0
->
z
);
strncpy
(
pCfg
->
ep
,
t0
->
z
,
t0
->
n
);
if
(
validateEp
(
pCfg
->
ep
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
strncpy
(
pCfg
->
config
,
pDCL
->
a
[
1
].
z
,
pDCL
->
a
[
1
].
n
);
strncpy
(
pCfg
->
config
,
t1
->
z
,
t1
->
n
);
if
(
pDCL
->
nTokens
==
3
)
{
pCfg
->
config
[
pDCL
->
a
[
1
].
n
]
=
' '
;
// add sep
strncpy
(
&
pCfg
->
config
[
pDCL
->
a
[
1
].
n
+
1
],
pDCL
->
a
[
2
].
z
,
pDCL
->
a
[
2
].
n
);
if
(
taosArrayGetSize
(
pMiscInfo
->
a
)
==
3
)
{
pCfg
->
config
[
t1
->
n
]
=
' '
;
// add sep
strncpy
(
&
pCfg
->
config
[
t1
->
n
+
1
],
t2
->
z
,
t2
->
n
);
}
break
;
...
...
@@ -491,7 +496,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pCmd
->
command
=
pInfo
->
type
;
SUserInfo
*
pUser
=
&
pInfo
->
p
DCL
Info
->
user
;
SUserInfo
*
pUser
=
&
pInfo
->
p
Misc
Info
->
user
;
SStrToken
*
pName
=
&
pUser
->
user
;
SStrToken
*
pPwd
=
&
pUser
->
passwd
;
...
...
@@ -535,18 +540,22 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
case
TSDB_SQL_CFG_LOCAL
:
{
tDCLSQL
*
pDCL
=
pInfo
->
pDCL
Info
;
const
char
*
msg
=
"invalid configure options or values"
;
SMiscInfo
*
pMiscInfo
=
pInfo
->
pMisc
Info
;
const
char
*
msg
=
"invalid configure options or values"
;
// validate the parameter names and options
if
(
validateLocalConfig
(
p
DCL
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
validateLocalConfig
(
p
MiscInfo
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
}
strncpy
(
pCmd
->
payload
,
pDCL
->
a
[
0
].
z
,
pDCL
->
a
[
0
].
n
);
if
(
pDCL
->
nTokens
==
2
)
{
pCmd
->
payload
[
pDCL
->
a
[
0
].
n
]
=
' '
;
// add sep
strncpy
(
&
pCmd
->
payload
[
pDCL
->
a
[
0
].
n
+
1
],
pDCL
->
a
[
1
].
z
,
pDCL
->
a
[
1
].
n
);
int32_t
numOfToken
=
taosArrayGetSize
(
pMiscInfo
->
a
);
SStrToken
*
t
=
taosArrayGet
(
pMiscInfo
->
a
,
0
);
SStrToken
*
t1
=
taosArrayGet
(
pMiscInfo
->
a
,
1
);
strncpy
(
pCmd
->
payload
,
t
->
z
,
t
->
n
);
if
(
numOfToken
==
2
)
{
pCmd
->
payload
[
t
->
n
]
=
' '
;
// add sep
strncpy
(
&
pCmd
->
payload
[
t
->
n
+
1
],
t1
->
z
,
t1
->
n
);
}
break
;
...
...
@@ -2587,10 +2596,10 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg6
=
"pattern string is empty"
;
/*
* database prefix in pInfo->p
DCL
Info->a[0]
* wildcard in like clause in pInfo->p
DCL
Info->a[1]
* database prefix in pInfo->p
Misc
Info->a[0]
* wildcard in like clause in pInfo->p
Misc
Info->a[1]
*/
SShowInfo
*
pShowInfo
=
&
pInfo
->
p
DCL
Info
->
showOpt
;
SShowInfo
*
pShowInfo
=
&
pInfo
->
p
Misc
Info
->
showOpt
;
int16_t
showType
=
pShowInfo
->
showType
;
if
(
showType
==
TSDB_MGMT_TABLE_TABLE
||
showType
==
TSDB_MGMT_TABLE_METRIC
||
showType
==
TSDB_MGMT_TABLE_VGROUP
)
{
// db prefix in tagCond, show table conds in payload
...
...
@@ -2655,7 +2664,7 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType) {
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
pCmd
->
command
=
pInfo
->
type
;
SStrToken
*
idStr
=
&
(
pInfo
->
p
DCLInfo
->
ip
);
SStrToken
*
idStr
=
&
(
pInfo
->
p
MiscInfo
->
id
);
if
(
idStr
->
n
>
TSDB_KILL_MSG_LEN
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -4798,7 +4807,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
int32_t
code
=
TSDB_CODE_SUCCESS
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SAlterTable
SQL
*
pAlterSQL
=
pInfo
->
pAlterInfo
;
SAlterTable
Info
*
pAlterSQL
=
pInfo
->
pAlterInfo
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
DEFAULT_TABLE_INDEX
);
...
...
@@ -5133,8 +5142,10 @@ int32_t validateEp(char* ep) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
validateDNodeConfig
(
tDCLSQL
*
pOptions
)
{
if
(
pOptions
->
nTokens
<
2
||
pOptions
->
nTokens
>
3
)
{
int32_t
validateDNodeConfig
(
SMiscInfo
*
pOptions
)
{
int32_t
numOfToken
=
taosArrayGetSize
(
pOptions
->
a
);
if
(
numOfToken
<
2
||
numOfToken
>
3
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -5152,9 +5163,9 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
{
"cqDebugFlag"
,
11
},
};
SStrToken
*
pOptionToken
=
&
pOptions
->
a
[
1
]
;
SStrToken
*
pOptionToken
=
taosArrayGet
(
pOptions
->
a
,
1
)
;
if
(
pOptions
->
nTokens
==
2
)
{
if
(
numOfToken
==
2
)
{
// reset log and reset query cache does not need value
for
(
int32_t
i
=
0
;
i
<
tokenLogEnd
;
++
i
)
{
const
SDNodeDynConfOption
*
pOption
=
&
cfgOptions
[
i
];
...
...
@@ -5164,7 +5175,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
}
}
else
if
((
strncasecmp
(
cfgOptions
[
tokenBalance
].
name
,
pOptionToken
->
z
,
pOptionToken
->
n
)
==
0
)
&&
(
cfgOptions
[
tokenBalance
].
len
==
pOptionToken
->
n
))
{
SStrToken
*
pValToken
=
&
pOptions
->
a
[
2
]
;
SStrToken
*
pValToken
=
taosArrayGet
(
pOptions
->
a
,
2
)
;
int32_t
vnodeId
=
0
;
int32_t
dnodeId
=
0
;
strdequote
(
pValToken
->
z
);
...
...
@@ -5175,14 +5186,14 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
return
TSDB_CODE_SUCCESS
;
}
else
if
((
strncasecmp
(
cfgOptions
[
tokenMonitor
].
name
,
pOptionToken
->
z
,
pOptionToken
->
n
)
==
0
)
&&
(
cfgOptions
[
tokenMonitor
].
len
==
pOptionToken
->
n
))
{
SStrToken
*
pValToken
=
&
pOptions
->
a
[
2
]
;
SStrToken
*
pValToken
=
taosArrayGet
(
pOptions
->
a
,
2
)
;
int32_t
val
=
strtol
(
pValToken
->
z
,
NULL
,
10
);
if
(
val
!=
0
&&
val
!=
1
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
// options value is invalid
}
return
TSDB_CODE_SUCCESS
;
}
else
{
SStrToken
*
pValToken
=
&
pOptions
->
a
[
2
]
;
SStrToken
*
pValToken
=
taosArrayGet
(
pOptions
->
a
,
2
)
;
int32_t
val
=
strtol
(
pValToken
->
z
,
NULL
,
10
);
if
(
val
<
0
||
val
>
256
)
{
...
...
@@ -5193,8 +5204,8 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
for
(
int32_t
i
=
tokenDebugFlag
;
i
<
tokenDebugFlagEnd
;
++
i
)
{
const
SDNodeDynConfOption
*
pOption
=
&
cfgOptions
[
i
];
// options is valid
if
((
strncasecmp
(
pOption
->
name
,
pOptionToken
->
z
,
pOptionToken
->
n
)
==
0
)
&&
(
pOption
->
len
==
pOptionToken
->
n
))
{
/* options is valid */
return
TSDB_CODE_SUCCESS
;
}
}
...
...
@@ -5203,17 +5214,18 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
return
TSDB_CODE_TSC_INVALID_SQL
;
}
int32_t
validateLocalConfig
(
tDCLSQL
*
pOptions
)
{
if
(
pOptions
->
nTokens
<
1
||
pOptions
->
nTokens
>
2
)
{
int32_t
validateLocalConfig
(
SMiscInfo
*
pOptions
)
{
int32_t
numOfToken
=
taosArrayGetSize
(
pOptions
->
a
);
if
(
numOfToken
<
1
||
numOfToken
>
2
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
SDNodeDynConfOption
LOCAL_DYNAMIC_CFG_OPTIONS
[
6
]
=
{{
"resetLog"
,
8
},
{
"rpcDebugFlag"
,
12
},
{
"tmrDebugFlag"
,
12
},
{
"cDebugFlag"
,
10
},
{
"uDebugFlag"
,
10
},
{
"debugFlag"
,
9
}};
SStrToken
*
pOptionToken
=
&
pOptions
->
a
[
0
]
;
SStrToken
*
pOptionToken
=
taosArrayGet
(
pOptions
->
a
,
0
)
;
if
(
pOptions
->
nTokens
==
1
)
{
if
(
numOfToken
==
1
)
{
// reset log does not need value
for
(
int32_t
i
=
0
;
i
<
1
;
++
i
)
{
SDNodeDynConfOption
*
pOption
=
&
LOCAL_DYNAMIC_CFG_OPTIONS
[
i
];
...
...
@@ -5222,7 +5234,7 @@ int32_t validateLocalConfig(tDCLSQL* pOptions) {
}
}
}
else
{
SStrToken
*
pValToken
=
&
pOptions
->
a
[
1
]
;
SStrToken
*
pValToken
=
taosArrayGet
(
pOptions
->
a
,
1
)
;
int32_t
val
=
strtol
(
pValToken
->
z
,
NULL
,
10
);
if
(
val
<
131
||
val
>
199
)
{
...
...
@@ -5374,7 +5386,7 @@ int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t clauseIn
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
setKeepOption
(
SSqlCmd
*
pCmd
,
SCreateDbMsg
*
pMsg
,
SCreateD
B
Info
*
pCreateDb
)
{
static
int32_t
setKeepOption
(
SSqlCmd
*
pCmd
,
SCreateDbMsg
*
pMsg
,
SCreateD
b
Info
*
pCreateDb
)
{
const
char
*
msg
=
"invalid number of options"
;
pMsg
->
daysToKeep
=
htonl
(
-
1
);
...
...
@@ -5412,7 +5424,7 @@ static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* p
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
setTimePrecision
(
SSqlCmd
*
pCmd
,
SCreateDbMsg
*
pMsg
,
SCreateD
B
Info
*
pCreateDbInfo
)
{
static
int32_t
setTimePrecision
(
SSqlCmd
*
pCmd
,
SCreateDbMsg
*
pMsg
,
SCreateD
b
Info
*
pCreateDbInfo
)
{
const
char
*
msg
=
"invalid time precision"
;
pMsg
->
precision
=
TSDB_TIME_PRECISION_MILLI
;
// millisecond by default
...
...
@@ -5436,7 +5448,7 @@ static int32_t setTimePrecision(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo
return
TSDB_CODE_SUCCESS
;
}
static
void
setCreateDBOption
(
SCreateDbMsg
*
pMsg
,
SCreateD
B
Info
*
pCreateDb
)
{
static
void
setCreateDBOption
(
SCreateDbMsg
*
pMsg
,
SCreateD
b
Info
*
pCreateDb
)
{
pMsg
->
maxTables
=
htonl
(
-
1
);
// max tables can not be set anymore
pMsg
->
cacheBlockSize
=
htonl
(
pCreateDb
->
cacheBlockSize
);
pMsg
->
totalBlocks
=
htonl
(
pCreateDb
->
numOfBlocks
);
...
...
@@ -5454,7 +5466,7 @@ static void setCreateDBOption(SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
pMsg
->
cacheLastRow
=
pCreateDb
->
cachelast
;
}
int32_t
parseCreateDBOptions
(
SSqlCmd
*
pCmd
,
SCreateD
B
Info
*
pCreateDbSql
)
{
int32_t
parseCreateDBOptions
(
SSqlCmd
*
pCmd
,
SCreateD
b
Info
*
pCreateDbSql
)
{
SCreateDbMsg
*
pMsg
=
(
SCreateDbMsg
*
)(
pCmd
->
payload
);
setCreateDBOption
(
pMsg
,
pCreateDbSql
);
...
...
src/client/src/tscServer.c
浏览文件 @
1ecf9659
...
...
@@ -309,7 +309,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
return
;
}
if
(
pEpSet
)
{
// todo update this
if
(
pEpSet
)
{
if
(
!
tscEpSetIsEqual
(
&
pSql
->
epSet
,
pEpSet
))
{
if
(
pCmd
->
command
<
TSDB_SQL_MGMT
)
{
tscUpdateVgroupInfo
(
pSql
,
pEpSet
);
...
...
@@ -1046,7 +1046,9 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
SCreateDnodeMsg
*
pCreate
=
(
SCreateDnodeMsg
*
)
pCmd
->
payload
;
strncpy
(
pCreate
->
ep
,
pInfo
->
pDCLInfo
->
a
[
0
].
z
,
pInfo
->
pDCLInfo
->
a
[
0
].
n
);
SStrToken
*
t0
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
strncpy
(
pCreate
->
ep
,
t0
->
z
,
t0
->
n
);
pCmd
->
msgType
=
TSDB_MSG_TYPE_CM_CREATE_DNODE
;
...
...
@@ -1063,13 +1065,13 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCreateAcctMsg
*
pAlterMsg
=
(
SCreateAcctMsg
*
)
pCmd
->
payload
;
SStrToken
*
pName
=
&
pInfo
->
p
DCL
Info
->
user
.
user
;
SStrToken
*
pPwd
=
&
pInfo
->
p
DCL
Info
->
user
.
passwd
;
SStrToken
*
pName
=
&
pInfo
->
p
Misc
Info
->
user
.
user
;
SStrToken
*
pPwd
=
&
pInfo
->
p
Misc
Info
->
user
.
passwd
;
strncpy
(
pAlterMsg
->
user
,
pName
->
z
,
pName
->
n
);
strncpy
(
pAlterMsg
->
pass
,
pPwd
->
z
,
pPwd
->
n
);
SCreateAcct
SQL
*
pAcctOpt
=
&
pInfo
->
pDCL
Info
->
acctOpt
;
SCreateAcct
Info
*
pAcctOpt
=
&
pInfo
->
pMisc
Info
->
acctOpt
;
pAlterMsg
->
cfg
.
maxUsers
=
htonl
(
pAcctOpt
->
maxUsers
);
pAlterMsg
->
cfg
.
maxDbs
=
htonl
(
pAcctOpt
->
maxDbs
);
...
...
@@ -1109,7 +1111,7 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCreateUserMsg
*
pAlterMsg
=
(
SCreateUserMsg
*
)
pCmd
->
payload
;
SUserInfo
*
pUser
=
&
pInfo
->
p
DCL
Info
->
user
;
SUserInfo
*
pUser
=
&
pInfo
->
p
Misc
Info
->
user
;
strncpy
(
pAlterMsg
->
user
,
pUser
->
user
.
z
,
pUser
->
user
.
n
);
pAlterMsg
->
flag
=
(
int8_t
)
pUser
->
type
;
...
...
@@ -1153,7 +1155,7 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int32_t
code
=
tNameExtractFullName
(
&
pTableMetaInfo
->
name
,
pDropDbMsg
->
db
);
assert
(
code
==
TSDB_CODE_SUCCESS
&&
pTableMetaInfo
->
name
.
type
==
TSDB_DB_NAME_T
);
pDropDbMsg
->
ignoreNotExists
=
pInfo
->
p
DCL
Info
->
existsCheck
?
1
:
0
;
pDropDbMsg
->
ignoreNotExists
=
pInfo
->
p
Misc
Info
->
existsCheck
?
1
:
0
;
pCmd
->
msgType
=
TSDB_MSG_TYPE_CM_DROP_DB
;
return
TSDB_CODE_SUCCESS
;
...
...
@@ -1172,7 +1174,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
tNameExtractFullName
(
&
pTableMetaInfo
->
name
,
pDropTableMsg
->
name
);
pDropTableMsg
->
igNotExists
=
pInfo
->
p
DCL
Info
->
existsCheck
?
1
:
0
;
pDropTableMsg
->
igNotExists
=
pInfo
->
p
Misc
Info
->
existsCheck
?
1
:
0
;
pCmd
->
msgType
=
TSDB_MSG_TYPE_CM_DROP_TABLE
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -1254,7 +1256,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
tNameGetFullDbName
(
&
pTableMetaInfo
->
name
,
pShowMsg
->
db
);
}
SShowInfo
*
pShowInfo
=
&
pInfo
->
p
DCL
Info
->
showOpt
;
SShowInfo
*
pShowInfo
=
&
pInfo
->
p
Misc
Info
->
showOpt
;
pShowMsg
->
type
=
pShowInfo
->
showType
;
if
(
pShowInfo
->
showType
!=
TSDB_MGMT_TABLE_VNODES
)
{
...
...
@@ -1420,7 +1422,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
SAlterTable
SQL
*
pAlterInfo
=
pInfo
->
pAlterInfo
;
SAlterTable
Info
*
pAlterInfo
=
pInfo
->
pAlterInfo
;
int
size
=
tscEstimateAlterTableMsgLength
(
pCmd
);
if
(
TSDB_CODE_SUCCESS
!=
tscAllocPayload
(
pCmd
,
size
))
{
tscError
(
"%p failed to malloc for alter table msg"
,
pSql
);
...
...
src/query/inc/qSqlparser.h
浏览文件 @
1ecf9659
...
...
@@ -96,15 +96,15 @@ typedef struct SCreateTableSQL {
SQuerySQL
*
pSelect
;
}
SCreateTableSQL
;
typedef
struct
SAlterTable
SQL
{
typedef
struct
SAlterTable
Info
{
SStrToken
name
;
int16_t
type
;
STagData
tagData
;
SArray
*
pAddColumns
;
// SArray<TAOS_FIELD>
SArray
*
varList
;
// set t=val or: change src dst, SArray<tVariantListItem>
}
SAlterTable
SQL
;
}
SAlterTable
Info
;
typedef
struct
SCreateD
B
Info
{
typedef
struct
SCreateD
b
Info
{
SStrToken
dbname
;
int32_t
replica
;
int32_t
cacheBlockSize
;
...
...
@@ -122,11 +122,10 @@ typedef struct SCreateDBInfo {
bool
ignoreExists
;
int8_t
update
;
int8_t
cachelast
;
SArray
*
keep
;
}
SCreateDBInfo
;
SArray
*
keep
;
}
SCreateDbInfo
;
typedef
struct
SCreateAcct
SQL
{
typedef
struct
SCreateAcct
Info
{
int32_t
maxUsers
;
int32_t
maxDbs
;
int32_t
maxTimeSeries
;
...
...
@@ -136,7 +135,7 @@ typedef struct SCreateAcctSQL {
int64_t
maxQueryTime
;
int32_t
maxConnections
;
SStrToken
stat
;
}
SCreateAcct
SQL
;
}
SCreateAcct
Info
;
typedef
struct
SShowInfo
{
uint8_t
showType
;
...
...
@@ -151,22 +150,20 @@ typedef struct SUserInfo {
int16_t
type
;
}
SUserInfo
;
typedef
struct
tDCLSQL
{
int32_t
nTokens
;
/* Number of expressions on the list */
int32_t
nAlloc
;
/* Number of entries allocated below */
SStrToken
*
a
;
/* one entry for element */
bool
existsCheck
;
typedef
struct
SMiscInfo
{
// int32_t nTokens; /* Number of expressions on the list */
// int32_t nAlloc; /* Number of entries allocated below */
// SStrToken *a; /* one entry for element */
SArray
*
a
;
// SArray<SStrToken>
bool
existsCheck
;
SUserInfo
user
;
union
{
SCreateD
BInfo
dbOpt
;
SCreateAcct
SQL
acctOpt
;
SShowInfo
showOpt
;
SStrToken
ip
;
SCreateD
bInfo
dbOpt
;
SCreateAcct
Info
acctOpt
;
SShowInfo
showOpt
;
SStrToken
id
;
};
SUserInfo
user
;
}
tDCLSQL
;
}
SMiscInfo
;
typedef
struct
SSubclauseInfo
{
// "UNION" multiple select sub-clause
SQuerySQL
**
pClause
;
...
...
@@ -176,15 +173,13 @@ typedef struct SSubclauseInfo { // "UNION" multiple select sub-clause
typedef
struct
SSqlInfo
{
int32_t
type
;
bool
valid
;
SSubclauseInfo
subclauseInfo
;
char
msg
[
256
];
union
{
SCreateTableSQL
*
pCreateTableInfo
;
SAlterTable
SQL
*
pAlterInfo
;
tDCLSQL
*
pDCL
Info
;
SCreateTableSQL
*
pCreateTableInfo
;
SAlterTable
Info
*
pAlterInfo
;
SMiscInfo
*
pMisc
Info
;
};
SSubclauseInfo
subclauseInfo
;
char
pzErrMsg
[
256
];
}
SSqlInfo
;
typedef
struct
tSQLExpr
{
...
...
@@ -250,7 +245,7 @@ SCreateTableSQL *tSetCreateSqlElems(SArray *pCols, SArray *pTags, SQuerySQL *pSe
void
tSqlExprNodeDestroy
(
tSQLExpr
*
pExpr
);
SAlterTable
SQL
*
tAlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
);
SAlterTable
Info
*
tAlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
);
SCreatedTableInfo
createNewChildTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pTagVals
,
SStrToken
*
pToken
,
SStrToken
*
igExists
);
void
destroyAllSelectClause
(
SSubclauseInfo
*
pSql
);
...
...
@@ -270,16 +265,16 @@ void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...);
void
setDropDbTableInfo
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SStrToken
*
existsCheck
);
void
setShowOptions
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
prefix
,
SStrToken
*
pPatterns
);
tDCLSQL
*
tTokenListAppend
(
tDCLSQL
*
pTokenList
,
SStrToken
*
pToken
);
SMiscInfo
*
tTokenListAppend
(
SMiscInfo
*
pTokenList
,
SStrToken
*
pToken
);
void
setCreateDBSQL
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SCreateD
B
Info
*
pDB
,
SStrToken
*
pIgExists
);
void
setCreateDBSQL
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SCreateD
b
Info
*
pDB
,
SStrToken
*
pIgExists
);
void
setCreateAcctSql
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pName
,
SStrToken
*
pPwd
,
SCreateAcct
SQL
*
pAcctInfo
);
void
setCreateAcctSql
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pName
,
SStrToken
*
pPwd
,
SCreateAcct
Info
*
pAcctInfo
);
void
setCreateUserSql
(
SSqlInfo
*
pInfo
,
SStrToken
*
pName
,
SStrToken
*
pPasswd
);
void
setKillSql
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
ip
);
void
setAlterUserSql
(
SSqlInfo
*
pInfo
,
int16_t
type
,
SStrToken
*
pName
,
SStrToken
*
pPwd
,
SStrToken
*
pPrivilege
);
void
setDefaultCreateDbOption
(
SCreateD
B
Info
*
pDBInfo
);
void
setDefaultCreateDbOption
(
SCreateD
b
Info
*
pDBInfo
);
// prefix show db.tables;
void
setDbName
(
SStrToken
*
pCpxName
,
SStrToken
*
pDb
);
...
...
src/query/inc/sql.y
浏览文件 @
1ecf9659
...
...
@@ -36,7 +36,7 @@
%syntax_error {
pInfo->valid = false;
int32_t outputBufLen = tListLen(pInfo->
pzErrM
sg);
int32_t outputBufLen = tListLen(pInfo->
m
sg);
int32_t len = 0;
if(TOKEN.z) {
...
...
@@ -46,13 +46,13 @@
if (sqlLen + sizeof(msg)/sizeof(msg[0]) + 1 > outputBufLen) {
char tmpstr[128] = {0};
memcpy(tmpstr, &TOKEN.z[0], sizeof(tmpstr)/sizeof(tmpstr[0]) - 1);
len = sprintf(pInfo->
pzErrM
sg, msg, tmpstr);
len = sprintf(pInfo->
m
sg, msg, tmpstr);
} else {
len = sprintf(pInfo->
pzErrM
sg, msg, &TOKEN.z[0]);
len = sprintf(pInfo->
m
sg, msg, &TOKEN.z[0]);
}
} else {
len = sprintf(pInfo->
pzErrM
sg, "Incomplete SQL statement");
len = sprintf(pInfo->
m
sg, "Incomplete SQL statement");
}
assert(len <= outputBufLen);
...
...
@@ -210,7 +210,7 @@ conns(Y) ::= CONNS INTEGER(X). { Y = X; }
state(Y) ::= . { Y.n = 0; }
state(Y) ::= STATE ids(X). { Y = X; }
%type acct_optr {SCreateAcct
SQL
}
%type acct_optr {SCreateAcct
Info
}
acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K) conns(L) state(M). {
Y.maxUsers = (K.n>0)?atoi(K.z):-1;
Y.maxDbs = (E.n>0)?atoi(E.z):-1;
...
...
@@ -242,7 +242,7 @@ prec(Y) ::= PRECISION STRING(X). { Y = X; }
update(Y) ::= UPDATE INTEGER(X). { Y = X; }
cachelast(Y) ::= CACHELAST INTEGER(X). { Y = X; }
%type db_optr {SCreateD
B
Info}
%type db_optr {SCreateD
b
Info}
db_optr(Y) ::= . {setDefaultCreateDbOption(&Y);}
db_optr(Y) ::= db_optr(Z) cache(X). { Y = Z; Y.cacheBlockSize = strtol(X.z, NULL, 10); }
...
...
@@ -261,7 +261,7 @@ 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 alter_db_optr {SCreateD
B
Info}
%type alter_db_optr {SCreateD
b
Info}
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); }
...
...
@@ -683,7 +683,7 @@ cmd ::= RESET QUERY CACHE. { setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
///////////////////////////////////ALTER TABLE statement//////////////////////////////////
cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
X.n += F.n;
SAlterTable
SQL
* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN);
SAlterTable
Info
* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
...
...
@@ -693,14 +693,14 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
toTSDBType(A.type);
SArray* K = tVariantListAppendToken(NULL, &A, -1);
SAlterTable
SQL
* pAlterTable = tAlterTableSqlElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN);
SAlterTable
Info
* pAlterTable = tAlterTableSqlElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
X.n += Y.n;
SAlterTable
SQL
* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN);
SAlterTable
Info
* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
...
...
@@ -709,7 +709,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
SAlterTable
SQL
* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN);
SAlterTable
Info
* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
...
...
@@ -722,7 +722,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
toTSDBType(Z.type);
A = tVariantListAppendToken(A, &Z, -1);
SAlterTable
SQL
* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN);
SAlterTable
Info
* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
...
...
@@ -733,7 +733,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
A = tVariantListAppend(A, &Z, -1);
SAlterTable
SQL
* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL);
SAlterTable
Info
* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
...
...
src/query/src/qParserImpl.c
浏览文件 @
1ecf9659
...
...
@@ -54,7 +54,7 @@ SSqlInfo qSQLParse(const char *pStr) {
case
TK_QUESTION
:
case
TK_ILLEGAL
:
{
snprintf
(
sqlInfo
.
pzErrMsg
,
tListLen
(
sqlInfo
.
pzErrM
sg
),
"unrecognized token:
\"
%s
\"
"
,
t0
.
z
);
snprintf
(
sqlInfo
.
msg
,
tListLen
(
sqlInfo
.
m
sg
),
"unrecognized token:
\"
%s
\"
"
,
t0
.
z
);
sqlInfo
.
valid
=
false
;
goto
abort_parse
;
}
...
...
@@ -585,8 +585,8 @@ SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagVal
return
info
;
}
SAlterTable
SQL
*
tAlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
)
{
SAlterTable
SQL
*
pAlterTable
=
calloc
(
1
,
sizeof
(
SAlterTableSQL
));
SAlterTable
Info
*
tAlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
)
{
SAlterTable
Info
*
pAlterTable
=
calloc
(
1
,
sizeof
(
SAlterTableInfo
));
pAlterTable
->
name
=
*
pTableName
;
pAlterTable
->
type
=
type
;
...
...
@@ -631,15 +631,15 @@ void SqlInfoDestroy(SSqlInfo *pInfo) {
tfree
(
pInfo
->
pAlterInfo
->
tagData
.
data
);
tfree
(
pInfo
->
pAlterInfo
);
}
else
{
if
(
pInfo
->
p
DCLInfo
!=
NULL
&&
pInfo
->
pDCLInfo
->
nAlloc
>
0
)
{
free
(
pInfo
->
pDCL
Info
->
a
);
if
(
pInfo
->
p
MiscInfo
!=
NULL
)
{
taosArrayDestroy
(
pInfo
->
pMisc
Info
->
a
);
}
if
(
pInfo
->
p
DCL
Info
!=
NULL
&&
pInfo
->
type
==
TSDB_SQL_CREATE_DB
)
{
taosArrayDestroyEx
(
pInfo
->
p
DCL
Info
->
dbOpt
.
keep
,
freeVariant
);
if
(
pInfo
->
p
Misc
Info
!=
NULL
&&
pInfo
->
type
==
TSDB_SQL_CREATE_DB
)
{
taosArrayDestroyEx
(
pInfo
->
p
Misc
Info
->
dbOpt
.
keep
,
freeVariant
);
}
tfree
(
pInfo
->
p
DCL
Info
);
tfree
(
pInfo
->
p
Misc
Info
);
}
}
...
...
@@ -696,57 +696,53 @@ void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken
pInfo
->
pCreateTableInfo
->
existCheck
=
(
pIfNotExists
->
n
!=
0
);
}
void
tTokenListBuyMoreSpace
(
tDCLSQL
*
pTokenList
)
{
if
(
pTokenList
->
nAlloc
<=
pTokenList
->
nTokens
)
{
//
pTokenList
->
nAlloc
=
(
pTokenList
->
nAlloc
<<
1u
)
+
4
;
pTokenList
->
a
=
realloc
(
pTokenList
->
a
,
pTokenList
->
nAlloc
*
sizeof
(
pTokenList
->
a
[
0
]));
if
(
pTokenList
->
a
==
0
)
{
pTokenList
->
nTokens
=
pTokenList
->
nAlloc
=
0
;
}
}
}
tDCLSQL
*
tTokenListAppend
(
tDCLSQL
*
pTokenList
,
SStrToken
*
pToken
)
{
if
(
pToken
==
NULL
)
return
NULL
;
if
(
pTokenList
==
NULL
)
pTokenList
=
calloc
(
1
,
sizeof
(
tDCLSQL
));
SMiscInfo
*
tTokenListAppend
(
SMiscInfo
*
pMiscInfo
,
SStrToken
*
pToken
)
{
assert
(
pToken
!=
NULL
);
tTokenListBuyMoreSpace
(
pTokenList
);
pTokenList
->
a
[
pTokenList
->
nTokens
++
]
=
*
pToken
;
if
(
pMiscInfo
==
NULL
)
{
pMiscInfo
=
calloc
(
1
,
sizeof
(
SMiscInfo
));
pMiscInfo
->
a
=
taosArrayInit
(
8
,
sizeof
(
SStrToken
));
}
return
pTokenList
;
taosArrayPush
(
pMiscInfo
->
a
,
pToken
);
return
pMiscInfo
;
}
void
setDCLSQLElems
(
SSqlInfo
*
pInfo
,
int32_t
type
,
int32_t
nParam
,
...)
{
pInfo
->
type
=
type
;
if
(
nParam
==
0
)
{
return
;
}
if
(
nParam
==
0
)
return
;
if
(
pInfo
->
pDCLInfo
==
NULL
)
pInfo
->
pDCLInfo
=
(
tDCLSQL
*
)
calloc
(
1
,
sizeof
(
tDCLSQL
));
if
(
pInfo
->
pMiscInfo
==
NULL
)
{
pInfo
->
pMiscInfo
=
(
SMiscInfo
*
)
calloc
(
1
,
sizeof
(
SMiscInfo
));
pInfo
->
pMiscInfo
->
a
=
taosArrayInit
(
4
,
sizeof
(
SStrToken
));
}
va_list
va
;
va_start
(
va
,
nParam
);
while
(
nParam
--
>
0
)
{
while
(
(
nParam
--
)
>
0
)
{
SStrToken
*
pToken
=
va_arg
(
va
,
SStrToken
*
);
pInfo
->
p
DCLInfo
=
tTokenListAppend
(
pInfo
->
pDCL
Info
,
pToken
);
pInfo
->
p
MiscInfo
=
tTokenListAppend
(
pInfo
->
pMisc
Info
,
pToken
);
}
va_end
(
va
);
}
void
setDropDbTableInfo
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SStrToken
*
existsCheck
)
{
pInfo
->
type
=
type
;
pInfo
->
p
DCLInfo
=
tTokenListAppend
(
pInfo
->
pDCL
Info
,
pToken
);
pInfo
->
p
DCL
Info
->
existsCheck
=
(
existsCheck
->
n
==
1
);
pInfo
->
p
MiscInfo
=
tTokenListAppend
(
pInfo
->
pMisc
Info
,
pToken
);
pInfo
->
p
Misc
Info
->
existsCheck
=
(
existsCheck
->
n
==
1
);
}
void
setShowOptions
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
prefix
,
SStrToken
*
pPatterns
)
{
if
(
pInfo
->
p
DCL
Info
==
NULL
)
{
pInfo
->
p
DCLInfo
=
calloc
(
1
,
sizeof
(
tDCLSQL
));
if
(
pInfo
->
p
Misc
Info
==
NULL
)
{
pInfo
->
p
MiscInfo
=
calloc
(
1
,
sizeof
(
SMiscInfo
));
}
pInfo
->
type
=
TSDB_SQL_SHOW
;
SShowInfo
*
pShowInfo
=
&
pInfo
->
p
DCL
Info
->
showOpt
;
SShowInfo
*
pShowInfo
=
&
pInfo
->
p
Misc
Info
->
showOpt
;
pShowInfo
->
showType
=
type
;
if
(
prefix
!=
NULL
&&
prefix
->
type
!=
0
)
{
...
...
@@ -762,54 +758,54 @@ void setShowOptions(SSqlInfo *pInfo, int32_t type, SStrToken* prefix, SStrToken*
}
}
void
setCreateDBSQL
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SCreateD
B
Info
*
pDB
,
SStrToken
*
pIgExists
)
{
void
setCreateDBSQL
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SCreateD
b
Info
*
pDB
,
SStrToken
*
pIgExists
)
{
pInfo
->
type
=
type
;
if
(
pInfo
->
p
DCL
Info
==
NULL
)
{
pInfo
->
p
DCLInfo
=
calloc
(
1
,
sizeof
(
tDCLSQL
));
if
(
pInfo
->
p
Misc
Info
==
NULL
)
{
pInfo
->
p
MiscInfo
=
calloc
(
1
,
sizeof
(
SMiscInfo
));
}
pInfo
->
p
DCL
Info
->
dbOpt
=
*
pDB
;
pInfo
->
p
DCL
Info
->
dbOpt
.
dbname
=
*
pToken
;
pInfo
->
p
DCL
Info
->
dbOpt
.
ignoreExists
=
pIgExists
->
n
;
// sql.y has: ifnotexists(X) ::= IF NOT EXISTS. {X.n = 1;}
pInfo
->
p
Misc
Info
->
dbOpt
=
*
pDB
;
pInfo
->
p
Misc
Info
->
dbOpt
.
dbname
=
*
pToken
;
pInfo
->
p
Misc
Info
->
dbOpt
.
ignoreExists
=
pIgExists
->
n
;
// sql.y has: ifnotexists(X) ::= IF NOT EXISTS. {X.n = 1;}
}
void
setCreateAcctSql
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pName
,
SStrToken
*
pPwd
,
SCreateAcct
SQL
*
pAcctInfo
)
{
void
setCreateAcctSql
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pName
,
SStrToken
*
pPwd
,
SCreateAcct
Info
*
pAcctInfo
)
{
pInfo
->
type
=
type
;
if
(
pInfo
->
p
DCL
Info
==
NULL
)
{
pInfo
->
p
DCLInfo
=
calloc
(
1
,
sizeof
(
tDCLSQL
));
if
(
pInfo
->
p
Misc
Info
==
NULL
)
{
pInfo
->
p
MiscInfo
=
calloc
(
1
,
sizeof
(
SMiscInfo
));
}
pInfo
->
p
DCL
Info
->
acctOpt
=
*
pAcctInfo
;
pInfo
->
p
Misc
Info
->
acctOpt
=
*
pAcctInfo
;
assert
(
pName
!=
NULL
);
pInfo
->
p
DCL
Info
->
user
.
user
=
*
pName
;
pInfo
->
p
Misc
Info
->
user
.
user
=
*
pName
;
if
(
pPwd
!=
NULL
)
{
pInfo
->
p
DCL
Info
->
user
.
passwd
=
*
pPwd
;
pInfo
->
p
Misc
Info
->
user
.
passwd
=
*
pPwd
;
}
}
void
setCreateUserSql
(
SSqlInfo
*
pInfo
,
SStrToken
*
pName
,
SStrToken
*
pPasswd
)
{
pInfo
->
type
=
TSDB_SQL_CREATE_USER
;
if
(
pInfo
->
p
DCL
Info
==
NULL
)
{
pInfo
->
p
DCLInfo
=
calloc
(
1
,
sizeof
(
tDCLSQL
));
if
(
pInfo
->
p
Misc
Info
==
NULL
)
{
pInfo
->
p
MiscInfo
=
calloc
(
1
,
sizeof
(
SMiscInfo
));
}
assert
(
pName
!=
NULL
&&
pPasswd
!=
NULL
);
pInfo
->
p
DCL
Info
->
user
.
user
=
*
pName
;
pInfo
->
p
DCL
Info
->
user
.
passwd
=
*
pPasswd
;
pInfo
->
p
Misc
Info
->
user
.
user
=
*
pName
;
pInfo
->
p
Misc
Info
->
user
.
passwd
=
*
pPasswd
;
}
void
setAlterUserSql
(
SSqlInfo
*
pInfo
,
int16_t
type
,
SStrToken
*
pName
,
SStrToken
*
pPwd
,
SStrToken
*
pPrivilege
)
{
pInfo
->
type
=
TSDB_SQL_ALTER_USER
;
if
(
pInfo
->
p
DCL
Info
==
NULL
)
{
pInfo
->
p
DCLInfo
=
calloc
(
1
,
sizeof
(
tDCLSQL
));
if
(
pInfo
->
p
Misc
Info
==
NULL
)
{
pInfo
->
p
MiscInfo
=
calloc
(
1
,
sizeof
(
SMiscInfo
));
}
assert
(
pName
!=
NULL
);
SUserInfo
*
pUser
=
&
pInfo
->
p
DCL
Info
->
user
;
SUserInfo
*
pUser
=
&
pInfo
->
p
Misc
Info
->
user
;
pUser
->
type
=
type
;
pUser
->
user
=
*
pName
;
...
...
@@ -826,18 +822,17 @@ void setAlterUserSql(SSqlInfo *pInfo, int16_t type, SStrToken *pName, SStrToken*
}
}
void
setKillSql
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
i
p
)
{
void
setKillSql
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
i
d
)
{
pInfo
->
type
=
type
;
if
(
pInfo
->
p
DCL
Info
==
NULL
)
{
pInfo
->
p
DCLInfo
=
calloc
(
1
,
sizeof
(
tDCLSQL
));
if
(
pInfo
->
p
Misc
Info
==
NULL
)
{
pInfo
->
p
MiscInfo
=
calloc
(
1
,
sizeof
(
SMiscInfo
));
}
assert
(
ip
!=
NULL
);
pInfo
->
pDCLInfo
->
ip
=
*
ip
;
assert
(
id
!=
NULL
);
pInfo
->
pMiscInfo
->
id
=
*
id
;
}
void
setDefaultCreateDbOption
(
SCreateD
B
Info
*
pDBInfo
)
{
void
setDefaultCreateDbOption
(
SCreateD
b
Info
*
pDBInfo
)
{
pDBInfo
->
compressionLevel
=
-
1
;
pDBInfo
->
walLevel
=
-
1
;
...
...
src/query/src/sql.c
浏览文件 @
1ecf9659
...
...
@@ -104,7 +104,7 @@ typedef union {
int
yyinit
;
ParseTOKENTYPE
yy0
;
SCreateTableSQL
*
yy38
;
SCreateAcct
SQL
yy71
;
SCreateAcct
Info
yy71
;
tSQLExpr
*
yy78
;
int
yy96
;
SQuerySQL
*
yy148
;
...
...
@@ -113,7 +113,7 @@ typedef union {
tSQLExprList
*
yy166
;
SLimitVal
yy167
;
TAOS_FIELD
yy183
;
SCreateD
B
Info
yy234
;
SCreateD
b
Info
yy234
;
int64_t
yy325
;
SIntervalVal
yy400
;
SArray
*
yy421
;
...
...
@@ -2865,7 +2865,7 @@ static void yy_reduce(
case
231
:
/* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
SAlterTable
SQL
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy421
,
NULL
,
TSDB_ALTER_TABLE_ADD_COLUMN
);
SAlterTable
Info
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy421
,
NULL
,
TSDB_ALTER_TABLE_ADD_COLUMN
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -2876,14 +2876,14 @@ static void yy_reduce(
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
SArray
*
K
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SAlterTable
SQL
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
K
,
TSDB_ALTER_TABLE_DROP_COLUMN
);
SAlterTable
Info
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
K
,
TSDB_ALTER_TABLE_DROP_COLUMN
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
case
233
:
/* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
SAlterTable
SQL
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy421
,
NULL
,
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
);
SAlterTable
Info
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy421
,
NULL
,
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -2894,7 +2894,7 @@ static void yy_reduce(
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
SArray
*
A
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SAlterTable
SQL
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
);
SAlterTable
Info
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -2908,7 +2908,7 @@ static void yy_reduce(
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
A
=
tVariantListAppendToken
(
A
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SAlterTable
SQL
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
5
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
);
SAlterTable
Info
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
5
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -2920,7 +2920,7 @@ static void yy_reduce(
SArray
*
A
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
2
].
minor
.
yy0
,
-
1
);
A
=
tVariantListAppend
(
A
,
&
yymsp
[
0
].
minor
.
yy430
,
-
1
);
SAlterTable
SQL
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
6
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
);
SAlterTable
Info
*
pAlterTable
=
tAlterTableSqlElems
(
&
yymsp
[
-
6
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
);
setSqlInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -2991,7 +2991,7 @@ static void yy_syntax_error(
/************ Begin %syntax_error code ****************************************/
pInfo
->
valid
=
false
;
int32_t
outputBufLen
=
tListLen
(
pInfo
->
pzErrM
sg
);
int32_t
outputBufLen
=
tListLen
(
pInfo
->
m
sg
);
int32_t
len
=
0
;
if
(
TOKEN
.
z
)
{
...
...
@@ -3001,13 +3001,13 @@ static void yy_syntax_error(
if
(
sqlLen
+
sizeof
(
msg
)
/
sizeof
(
msg
[
0
])
+
1
>
outputBufLen
)
{
char
tmpstr
[
128
]
=
{
0
};
memcpy
(
tmpstr
,
&
TOKEN
.
z
[
0
],
sizeof
(
tmpstr
)
/
sizeof
(
tmpstr
[
0
])
-
1
);
len
=
sprintf
(
pInfo
->
pzErrM
sg
,
msg
,
tmpstr
);
len
=
sprintf
(
pInfo
->
m
sg
,
msg
,
tmpstr
);
}
else
{
len
=
sprintf
(
pInfo
->
pzErrM
sg
,
msg
,
&
TOKEN
.
z
[
0
]);
len
=
sprintf
(
pInfo
->
m
sg
,
msg
,
&
TOKEN
.
z
[
0
]);
}
}
else
{
len
=
sprintf
(
pInfo
->
pzErrM
sg
,
"Incomplete SQL statement"
);
len
=
sprintf
(
pInfo
->
m
sg
,
"Incomplete SQL statement"
);
}
assert
(
len
<=
outputBufLen
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录