Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
694132ed
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看板
提交
694132ed
编写于
9月 18, 2021
作者:
W
wpan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support escape table name
上级
676b35c8
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
2229 addition
and
2665 deletion
+2229
-2665
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+1
-1
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+2
-2
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+1
-1
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+19
-18
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+61
-5
src/inc/ttokendef.h
src/inc/ttokendef.h
+111
-109
src/query/inc/sql.y
src/query/inc/sql.y
+41
-68
src/query/src/sql.c
src/query/src/sql.c
+1980
-2460
src/query/tests/unitTest.cpp
src/query/tests/unitTest.cpp
+1
-1
src/util/src/ttokenizer.c
src/util/src/ttokenizer.c
+12
-0
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
694132ed
...
...
@@ -240,7 +240,7 @@ void tscColumnListCopyAll(SArray* dst, const SArray* src);
void
convertQueryResult
(
SSqlRes
*
pRes
,
SQueryInfo
*
pQueryInfo
,
uint64_t
objId
,
bool
convertNchar
);
void
tscDequoteAndTrimToken
(
SStrToken
*
pToken
);
int32_t
tscValidateName
(
SStrToken
*
pToken
);
int32_t
tscValidateName
(
SStrToken
*
pToken
,
bool
escapeEnabled
);
void
tscIncStreamExecutionCount
(
void
*
pStream
);
...
...
src/client/src/tscParseInsert.c
浏览文件 @
694132ed
...
...
@@ -1137,7 +1137,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
sql
=
sToken
.
z
;
if
(
tscValidateName
(
&
tableToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
tableToken
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
return
tscInvalidOperationMsg
(
pInsertParam
->
msg
,
"invalid table name"
,
*
sqlstr
);
}
...
...
@@ -1178,7 +1178,7 @@ int validateTableName(char *tblName, int len, SStrToken* psTblToken) {
psTblToken
->
type
=
TK_ID
;
tGetToken
(
psTblToken
->
z
,
&
psTblToken
->
type
);
return
tscValidateName
(
psTblToken
);
return
tscValidateName
(
psTblToken
,
true
);
}
static
int32_t
validateDataSource
(
SInsertStatementParam
*
pInsertParam
,
int32_t
type
,
const
char
*
sql
)
{
...
...
src/client/src/tscParseLineProtocol.c
浏览文件 @
694132ed
...
...
@@ -559,7 +559,7 @@ static int32_t retrieveTableMeta(TAOS* taos, char* tableName, STableMeta** pTabl
SStrToken
tableToken
=
{.
z
=
tableNameLowerCase
,
.
n
=
(
uint32_t
)
strlen
(
tableNameLowerCase
),
.
type
=
TK_ID
};
tGetToken
(
tableNameLowerCase
,
&
tableToken
.
type
);
// Check if the table name available or not
if
(
tscValidateName
(
&
tableToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
tableToken
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
code
=
TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH
;
sprintf
(
pSql
->
cmd
.
payload
,
"table name is invalid"
);
tscFreeRegisteredSqlObj
(
pSql
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
694132ed
...
...
@@ -567,7 +567,8 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg3
=
"param name too long"
;
SStrToken
*
pzName
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
((
pInfo
->
type
!=
TSDB_SQL_DROP_DNODE
)
&&
(
tscValidateName
(
pzName
)
!=
TSDB_CODE_SUCCESS
))
{
bool
escapeEnabled
=
(
pInfo
->
type
==
TSDB_SQL_DROP_TABLE
)
?
true
:
false
;
if
((
pInfo
->
type
!=
TSDB_SQL_DROP_DNODE
)
&&
(
tscValidateName
(
pzName
,
escapeEnabled
)
!=
TSDB_CODE_SUCCESS
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -605,7 +606,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg
=
"invalid db name"
;
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pToken
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
}
...
...
@@ -652,7 +653,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
char
buf
[
TSDB_DB_NAME_LEN
]
=
{
0
};
SStrToken
token
=
taosTokenDup
(
&
pCreateDB
->
dbname
,
buf
,
tListLen
(
buf
));
if
(
tscValidateName
(
&
token
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
token
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -699,7 +700,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
if
(
tscValidateName
(
pName
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pName
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -721,7 +722,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg1
=
"invalid table name"
;
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pToken
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
// additional msg has been attached already
...
...
@@ -737,7 +738,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg1
=
"invalid table name"
;
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pToken
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -752,7 +753,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const
char
*
msg1
=
"invalid database name"
;
SStrToken
*
pToken
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pToken
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -816,7 +817,7 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
if
(
tscValidateName
(
pName
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pName
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -3206,7 +3207,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
if
(
tscValidateName
(
pDbPrefixToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pDbPrefixToken
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -5866,7 +5867,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
DEFAULT_TABLE_INDEX
);
if
(
tscValidateName
(
&
(
pAlterSQL
->
name
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
(
pAlterSQL
->
name
,
true
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -7421,7 +7422,7 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p
// if sql specifies db, use it, otherwise use default db
SStrToken
*
pzTableName
=
&
(
pCreateTable
->
name
);
if
(
tscValidateName
(
pzTableName
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pzTableName
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -7485,7 +7486,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
SCreatedTableInfo
*
pCreateTableInfo
=
taosArrayGet
(
pCreateTable
->
childTableInfo
,
j
);
SStrToken
*
pToken
=
&
pCreateTableInfo
->
stableName
;
if
(
tscValidateName
(
pToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pToken
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -7660,7 +7661,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
free
(
row
);
// table name
if
(
tscValidateName
(
&
(
pCreateTableInfo
->
name
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
(
pCreateTableInfo
->
name
,
true
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -7703,7 +7704,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
SStrToken
*
pName
=
&
(
pCreateTable
->
name
);
SSqlNode
*
pSqlNode
=
pCreateTable
->
pSelect
;
if
(
tscValidateName
(
pName
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
pName
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -7718,7 +7719,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) {
SRelElementPair
*
p1
=
taosArrayGet
(
pFromInfo
->
list
,
0
);
SStrToken
srcToken
=
{.
z
=
p1
->
tableName
.
z
,
.
n
=
p1
->
tableName
.
n
,
.
type
=
TK_STRING
};
if
(
tscValidateName
(
&
srcToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
srcToken
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -8157,7 +8158,7 @@ static int32_t getTableNameFromSqlNode(SSqlNode* pSqlNode, SArray* tableNameList
}
tscDequoteAndTrimToken
(
t
);
if
(
tscValidateName
(
t
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
t
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
msgBuf
,
msg1
);
}
...
...
@@ -8417,7 +8418,7 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
}
tscDequoteAndTrimToken
(
oriName
);
if
(
tscValidateName
(
oriName
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
oriName
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -8434,7 +8435,7 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
}
tscDequoteAndTrimToken
(
aliasName
);
if
(
tscValidateName
(
aliasName
)
!=
TSDB_CODE_SUCCESS
||
aliasName
->
n
>=
TSDB_TABLE_NAME_LEN
)
{
if
(
tscValidateName
(
aliasName
,
false
)
!=
TSDB_CODE_SUCCESS
||
aliasName
->
n
>=
TSDB_TABLE_NAME_LEN
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
...
...
src/client/src/tscUtil.c
浏览文件 @
694132ed
...
...
@@ -2788,9 +2788,55 @@ void tscDequoteAndTrimToken(SStrToken* pToken) {
pToken
->
n
=
last
-
first
;
}
int32_t
tscValidateName
(
SStrToken
*
pToken
)
{
if
(
pToken
==
NULL
||
pToken
->
z
==
NULL
||
(
pToken
->
type
!=
TK_STRING
&&
pToken
->
type
!=
TK_ID
))
{
void
tscRmEscapeAndTrimToken
(
SStrToken
*
pToken
)
{
uint32_t
first
=
0
,
last
=
pToken
->
n
;
// trim leading spaces
while
(
first
<
last
)
{
char
c
=
pToken
->
z
[
first
];
if
(
c
!=
' '
&&
c
!=
'\t'
)
{
break
;
}
first
++
;
}
// trim ending spaces
while
(
first
<
last
)
{
char
c
=
pToken
->
z
[
last
-
1
];
if
(
c
!=
' '
&&
c
!=
'\t'
)
{
break
;
}
last
--
;
}
// there are still at least two characters
if
(
first
<
last
-
1
)
{
char
c
=
pToken
->
z
[
first
];
// dequote
if
((
c
==
'`'
)
&&
c
==
pToken
->
z
[
last
-
1
])
{
first
++
;
last
--
;
}
}
// left shift the string and pad spaces
for
(
uint32_t
i
=
0
;
i
+
first
<
last
;
i
++
)
{
pToken
->
z
[
i
]
=
pToken
->
z
[
first
+
i
];
}
for
(
uint32_t
i
=
last
-
first
;
i
<
pToken
->
n
;
i
++
)
{
pToken
->
z
[
i
]
=
' '
;
}
// adjust token length
pToken
->
n
=
last
-
first
;
}
int32_t
tscValidateName
(
SStrToken
*
pToken
,
bool
escapeEnabled
)
{
if
(
pToken
==
NULL
||
pToken
->
z
==
NULL
||
(
escapeEnabled
&&
pToken
->
type
!=
TK_STRING
&&
pToken
->
type
!=
TK_ID
&&
pToken
->
type
!=
TK_ESCAPE
)
||
((
!
escapeEnabled
)
&&
pToken
->
type
!=
TK_STRING
&&
pToken
->
type
!=
TK_ID
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -2815,6 +2861,9 @@ int32_t tscValidateName(SStrToken* pToken) {
return
tscValidateName
(
pToken
);
}
}
else
if
(
escapeEnabled
&&
pToken
->
type
==
TK_ESCAPE
)
{
tscRmEscapeAndTrimToken
(
pToken
);
return
TSDB_CODE_SUCCESS
;
}
else
{
if
(
isNumber
(
pToken
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
...
...
@@ -2846,7 +2895,8 @@ int32_t tscValidateName(SStrToken* pToken) {
pToken
->
z
=
sep
+
1
;
pToken
->
n
=
(
uint32_t
)(
oldLen
-
(
sep
-
pStr
)
-
1
);
int32_t
len
=
tGetToken
(
pToken
->
z
,
&
pToken
->
type
);
if
(
len
!=
pToken
->
n
||
(
pToken
->
type
!=
TK_STRING
&&
pToken
->
type
!=
TK_ID
))
{
if
(
len
!=
pToken
->
n
||
(
escapeEnabled
&&
pToken
->
type
!=
TK_STRING
&&
pToken
->
type
!=
TK_ID
&&
pToken
->
type
!=
TK_ESCAPE
)
||
((
!
escapeEnabled
)
&&
pToken
->
type
!=
TK_STRING
&&
pToken
->
type
!=
TK_ID
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -2854,6 +2904,12 @@ int32_t tscValidateName(SStrToken* pToken) {
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
escapeEnabled
&&
pToken
->
type
==
TK_ESCAPE
)
{
tscRmEscapeAndTrimToken
(
pToken
);
}
xxxxxxxtolower
// re-build the whole name string
if
(
pStr
[
firstPartLen
]
==
TS_PATH_DELIMITER
[
0
])
{
// first part do not have quote do nothing
...
...
@@ -4981,7 +5037,7 @@ static int32_t doAddTableName(char* nextStr, char** str, SArray* pNameArray, SSq
tGetToken
(
tablename
,
&
sToken
.
type
);
// Check if the table name available or not
if
(
tscValidateName
(
&
sToken
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tscValidateName
(
&
sToken
,
true
)
!=
TSDB_CODE_SUCCESS
)
{
sprintf
(
pCmd
->
payload
,
"table name is invalid"
);
return
TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH
;
}
...
...
src/inc/ttokendef.h
浏览文件 @
694132ed
...
...
@@ -103,115 +103,117 @@
#define TK_RP 85
#define TK_IF 86
#define TK_EXISTS 87
#define TK_AS 88
#define TK_OUTPUTTYPE 89
#define TK_AGGREGATE 90
#define TK_BUFSIZE 91
#define TK_PPS 92
#define TK_TSERIES 93
#define TK_DBS 94
#define TK_STORAGE 95
#define TK_QTIME 96
#define TK_CONNS 97
#define TK_STATE 98
#define TK_COMMA 99
#define TK_KEEP 100
#define TK_CACHE 101
#define TK_REPLICA 102
#define TK_QUORUM 103
#define TK_DAYS 104
#define TK_MINROWS 105
#define TK_MAXROWS 106
#define TK_BLOCKS 107
#define TK_CTIME 108
#define TK_WAL 109
#define TK_FSYNC 110
#define TK_COMP 111
#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_NULL 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_SESSION 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_OFFSET 139
#define TK_SLIMIT 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_ABORT 156
#define TK_AFTER 157
#define TK_ATTACH 158
#define TK_BEFORE 159
#define TK_BEGIN 160
#define TK_CASCADE 161
#define TK_CLUSTER 162
#define TK_CONFLICT 163
#define TK_COPY 164
#define TK_DEFERRED 165
#define TK_DELIMITERS 166
#define TK_DETACH 167
#define TK_EACH 168
#define TK_END 169
#define TK_EXPLAIN 170
#define TK_FAIL 171
#define TK_FOR 172
#define TK_IGNORE 173
#define TK_IMMEDIATE 174
#define TK_INITIALLY 175
#define TK_INSTEAD 176
#define TK_KEY 177
#define TK_OF 178
#define TK_RAISE 179
#define TK_REPLACE 180
#define TK_RESTRICT 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_INSERT 194
#define TK_INTO 195
#define TK_VALUES 196
#define TK_ESCAPE 88
#define TK_AS 89
#define TK_OUTPUTTYPE 90
#define TK_AGGREGATE 91
#define TK_BUFSIZE 92
#define TK_PPS 93
#define TK_TSERIES 94
#define TK_DBS 95
#define TK_STORAGE 96
#define TK_QTIME 97
#define TK_CONNS 98
#define TK_STATE 99
#define TK_COMMA 100
#define TK_KEEP 101
#define TK_CACHE 102
#define TK_REPLICA 103
#define TK_QUORUM 104
#define TK_DAYS 105
#define TK_MINROWS 106
#define TK_MAXROWS 107
#define TK_BLOCKS 108
#define TK_CTIME 109
#define TK_WAL 110
#define TK_FSYNC 111
#define TK_COMP 112
#define TK_PRECISION 113
#define TK_UPDATE 114
#define TK_CACHELAST 115
#define TK_PARTITIONS 116
#define TK_UNSIGNED 117
#define TK_TAGS 118
#define TK_USING 119
#define TK_NULL 120
#define TK_NOW 121
#define TK_SELECT 122
#define TK_UNION 123
#define TK_ALL 124
#define TK_DISTINCT 125
#define TK_FROM 126
#define TK_VARIABLE 127
#define TK_INTERVAL 128
#define TK_EVERY 129
#define TK_SESSION 130
#define TK_STATE_WINDOW 131
#define TK_FILL 132
#define TK_SLIDING 133
#define TK_ORDER 134
#define TK_BY 135
#define TK_ASC 136
#define TK_GROUP 137
#define TK_HAVING 138
#define TK_LIMIT 139
#define TK_OFFSET 140
#define TK_SLIMIT 141
#define TK_SOFFSET 142
#define TK_WHERE 143
#define TK_RESET 144
#define TK_QUERY 145
#define TK_SYNCDB 146
#define TK_ADD 147
#define TK_COLUMN 148
#define TK_MODIFY 149
#define TK_TAG 150
#define TK_CHANGE 151
#define TK_SET 152
#define TK_KILL 153
#define TK_CONNECTION 154
#define TK_STREAM 155
#define TK_COLON 156
#define TK_ABORT 157
#define TK_AFTER 158
#define TK_ATTACH 159
#define TK_BEFORE 160
#define TK_BEGIN 161
#define TK_CASCADE 162
#define TK_CLUSTER 163
#define TK_CONFLICT 164
#define TK_COPY 165
#define TK_DEFERRED 166
#define TK_DELIMITERS 167
#define TK_DETACH 168
#define TK_EACH 169
#define TK_END 170
#define TK_EXPLAIN 171
#define TK_FAIL 172
#define TK_FOR 173
#define TK_IGNORE 174
#define TK_IMMEDIATE 175
#define TK_INITIALLY 176
#define TK_INSTEAD 177
#define TK_KEY 178
#define TK_OF 179
#define TK_RAISE 180
#define TK_REPLACE 181
#define TK_RESTRICT 182
#define TK_ROW 183
#define TK_STATEMENT 184
#define TK_TRIGGER 185
#define TK_VIEW 186
#define TK_IPTOKEN 187
#define TK_SEMI 188
#define TK_NONE 189
#define TK_PREV 190
#define TK_LINEAR 191
#define TK_IMPORT 192
#define TK_TBNAME 193
#define TK_JOIN 194
#define TK_INSERT 195
#define TK_INTO 196
#define TK_VALUES 197
#define TK_SPACE 300
...
...
src/query/inc/sql.y
浏览文件 @
694132ed
...
...
@@ -91,12 +91,10 @@ dbPrefix(A) ::= ids(X) DOT. {A = X; }
cpxName(A) ::= . {A.n = 0; }
cpxName(A) ::= DOT ids(Y). {A = Y; A.n += 1; }
cmd ::= SHOW CREATE TABLE ids(X) cpxName(Y). {
X.n += Y.n;
cmd ::= SHOW CREATE TABLE ftblname(X). {
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &X);
}
cmd ::= SHOW CREATE STABLE ids(X) cpxName(Y). {
X.n += Y.n;
cmd ::= SHOW CREATE STABLE ftblname(X). {
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_STABLE, 1, &X);
}
...
...
@@ -108,7 +106,7 @@ cmd ::= SHOW dbPrefix(X) TABLES. {
setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &X, 0);
}
cmd ::= SHOW dbPrefix(X) TABLES LIKE
ids
(Y). {
cmd ::= SHOW dbPrefix(X) TABLES LIKE
tblname
(Y). {
setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &X, &Y);
}
...
...
@@ -116,7 +114,7 @@ cmd ::= SHOW dbPrefix(X) STABLES. {
setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &X, 0);
}
cmd ::= SHOW dbPrefix(X) STABLES LIKE
ids
(Y). {
cmd ::= SHOW dbPrefix(X) STABLES LIKE
tblname
(Y). {
SStrToken token;
tSetDbName(&token, &X);
setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &token, &Y);
...
...
@@ -135,14 +133,12 @@ cmd ::= SHOW dbPrefix(X) VGROUPS ids(Y). {
}
//drop configure for tables
cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). {
X.n += Z.n;
cmd ::= DROP TABLE ifexists(Y) ftblname(X). {
setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y, -1, -1);
}
//drop stable
cmd ::= DROP STABLE ifexists(Y) ids(X) cpxName(Z). {
X.n += Z.n;
cmd ::= DROP STABLE ifexists(Y) ftblname(X). {
setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y, -1, TSDB_SUPER_TABLE);
}
...
...
@@ -158,12 +154,10 @@ cmd ::= DROP ACCOUNT ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_DROP_ACCT, 1,
cmd ::= USE ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_USE_DB, 1, &X);}
/////////////////////////////////THE DESCRIBE STATEMENT/////////////////////////////////////
cmd ::= DESCRIBE ids(X) cpxName(Y). {
X.n += Y.n;
cmd ::= DESCRIBE ftblname(X). {
setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
}
cmd ::= DESC ids(X) cpxName(Y). {
X.n += Y.n;
cmd ::= DESC ftblname(X). {
setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
}
/////////////////////////////////THE ALTER STATEMENT////////////////////////////////////////
...
...
@@ -198,6 +192,14 @@ ifexists(X) ::= . { X.n = 0;}
ifnotexists(X) ::= IF NOT EXISTS. { X.n = 1;}
ifnotexists(X) ::= . { X.n = 0;}
%type tblname {SStrToken}
tblname(A) ::= ids(X). {A = X; }
tblname(A) ::= ESCAPE(X). {A = X; }
%type ftblname {SStrToken}
ftblname(A) ::= tblname(X). {A = X; }
ftblname(A) ::= ids(X) DOT tblname(Y). {A = X; A.n += 1 + Y.n; }
/////////////////////////////////THE CREATE STATEMENT///////////////////////////////////////
//create option for dnode/db/user/account
cmd ::= CREATE DNODE ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &X);}
...
...
@@ -377,36 +379,30 @@ create_table_list(A) ::= create_table_list(X) create_from_stable(Z). {
}
%type create_table_args{SCreateTableSql*}
create_table_args(A) ::= ifnotexists(U)
ids(V) cpxName(Z
) LP columnlist(X) RP. {
create_table_args(A) ::= ifnotexists(U)
ftblname(V
) LP columnlist(X) RP. {
A = tSetCreateTableInfo(X, NULL, NULL, TSQL_CREATE_TABLE);
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
V.n += Z.n;
setCreatedTableName(pInfo, &V, &U);
}
// create super table
%type create_stable_args{SCreateTableSql*}
create_stable_args(A) ::= ifnotexists(U)
ids(V) cpxName(Z
) LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
create_stable_args(A) ::= ifnotexists(U)
ftblname(V
) LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
A = tSetCreateTableInfo(X, Y, NULL, TSQL_CREATE_STABLE);
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
V.n += Z.n;
setCreatedTableName(pInfo, &V, &U);
}
// create table by using super table
// create table table_name using super_table_name tags(tag_values1, tag_values2)
%type create_from_stable{SCreatedTableInfo}
create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) TAGS LP tagitemlist(Y) RP. {
X.n += F.n;
V.n += Z.n;
create_from_stable(A) ::= ifnotexists(U) ftblname(V) USING ftblname(X) TAGS LP tagitemlist(Y) RP. {
A = createNewChildTableInfo(&X, NULL, Y, &V, &U);
}
create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) LP tagNamelist(P) RP TAGS LP tagitemlist(Y) RP. {
X.n += F.n;
V.n += Z.n;
create_from_stable(A) ::= ifnotexists(U) ftblname(V) USING ftblname(X) LP tagNamelist(P) RP TAGS LP tagitemlist(Y) RP. {
A = createNewChildTableInfo(&X, P, Y, &V, &U);
}
...
...
@@ -417,11 +413,10 @@ tagNamelist(A) ::= ids(X). {A = taosArrayInit(4, sizeof(SSt
// create stream
// create table table_name as select count(*) from super_table_name interval(time)
create_table_args(A) ::= ifnotexists(U)
ids(V) cpxName(Z
) AS select(S). {
create_table_args(A) ::= ifnotexists(U)
ftblname(V
) AS select(S). {
A = tSetCreateTableInfo(NULL, NULL, S, TSQL_CREATE_STREAM);
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
V.n += Z.n;
setCreatedTableName(pInfo, &V, &U);
}
...
...
@@ -548,23 +543,19 @@ sub(A) ::= sub(X) COMMA LP union(Y) RP ids(Z).{A = addSubqueryElem(X, Y, &Z);}
%type tablelist {SRelationInfo*}
%destructor tablelist {destroyRelationInfo($$);}
tablelist(A) ::= ids(X) cpxName(Y). {
X.n += Y.n;
tablelist(A) ::= ftblname(X). {
A = setTableNameList(NULL, &X, NULL);
}
tablelist(A) ::= ids(X) cpxName(Y) ids(Z). {
X.n += Y.n;
tablelist(A) ::= ftblname(X) ids(Z). {
A = setTableNameList(NULL, &X, &Z);
}
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z). {
X.n += Z.n;
tablelist(A) ::= tablelist(Y) COMMA ftblname(X). {
A = setTableNameList(Y, &X, NULL);
}
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). {
X.n += Z.n;
tablelist(A) ::= tablelist(Y) COMMA ftblname(X) ids(F). {
A = setTableNameList(Y, &X, &F);
}
...
...
@@ -776,15 +767,12 @@ cmd ::= RESET QUERY CACHE. { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
cmd ::= SYNCDB ids(X) REPLICA.{ setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &X);}
///////////////////////////////////ALTER TABLE statement//////////////////////////////////
cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
X.n += F.n;
cmd ::= ALTER TABLE ftblname(X) ADD COLUMN columnlist(A). {
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
X.n += F.n;
cmd ::= ALTER TABLE ftblname(X) DROP COLUMN ids(A). {
toTSDBType(A.type);
SArray* K = tVariantListAppendToken(NULL, &A, -1);
...
...
@@ -792,21 +780,17 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER TABLE ids(X) cpxName(F) MODIFY COLUMN columnlist(A). {
X.n += F.n;
cmd ::= ALTER TABLE ftblname(X) MODIFY COLUMN columnlist(A). {
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1);
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;
cmd ::= ALTER TABLE ftblname(X) ADD TAG columnlist(A). {
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
X.n += Z.n;
cmd ::= ALTER TABLE ftblname(X) DROP TAG ids(Y). {
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
...
...
@@ -814,8 +798,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
X.n += F.n;
cmd ::= ALTER TABLE ftblname(X) CHANGE TAG ids(Y) ids(Z). {
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
...
...
@@ -827,8 +810,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
X.n += F.n;
cmd ::= ALTER TABLE ftblname(X) SET TAG ids(Y) EQ tagitem(Z). {
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
...
...
@@ -838,21 +820,18 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER TABLE ids(X) cpxName(F) MODIFY TAG columnlist(A). {
X.n += F.n;
cmd ::= ALTER TABLE ftblname(X) MODIFY TAG columnlist(A). {
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
///////////////////////////////////ALTER STABLE statement//////////////////////////////////
cmd ::= ALTER STABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
X.n += F.n;
cmd ::= ALTER STABLE ftblname(X) ADD COLUMN columnlist(A). {
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
X.n += F.n;
cmd ::= ALTER STABLE ftblname(X) DROP COLUMN ids(A). {
toTSDBType(A.type);
SArray* K = tVariantListAppendToken(NULL, &A, -1);
...
...
@@ -861,20 +840,17 @@ cmd ::= ALTER STABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(F) MODIFY COLUMN columnlist(A). {
X.n += F.n;
cmd ::= ALTER STABLE ftblname(X) MODIFY COLUMN columnlist(A). {
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
cmd ::= ALTER STABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
X.n += Y.n;
cmd ::= ALTER STABLE ftblname(X) ADD TAG columnlist(A). {
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
X.n += Z.n;
cmd ::= ALTER STABLE ftblname(X) DROP TAG ids(Y). {
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
...
...
@@ -883,8 +859,7 @@ cmd ::= ALTER STABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
X.n += F.n;
cmd ::= ALTER STABLE ftblname(X) CHANGE TAG ids(Y) ids(Z). {
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
...
...
@@ -896,8 +871,7 @@ cmd ::= ALTER STABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
X.n += F.n;
cmd ::= ALTER STABLE ftblname(X) SET TAG ids(Y) EQ tagitem(Z). {
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
...
...
@@ -907,8 +881,7 @@ cmd ::= ALTER STABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(F) MODIFY TAG columnlist(A). {
X.n += F.n;
cmd ::= ALTER STABLE ftblname(X) MODIFY TAG columnlist(A). {
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
...
...
src/query/src/sql.c
浏览文件 @
694132ed
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
src/query/tests/unitTest.cpp
浏览文件 @
694132ed
...
...
@@ -23,7 +23,7 @@ int32_t testValidateName(char* name) {
token
.
type
=
0
;
tGetToken
(
name
,
&
token
.
type
);
return
tscValidateName
(
&
token
);
return
tscValidateName
(
&
token
,
false
);
}
}
...
...
src/util/src/ttokenizer.c
浏览文件 @
694132ed
...
...
@@ -229,6 +229,7 @@ static SKeyword keywordTable[] = {
{
"OUTPUTTYPE"
,
TK_OUTPUTTYPE
},
{
"AGGREGATE"
,
TK_AGGREGATE
},
{
"BUFSIZE"
,
TK_BUFSIZE
},
{
"ESCAPE"
,
TK_ESCAPE
}
};
static
const
char
isIdChar
[]
=
{
...
...
@@ -442,6 +443,17 @@ uint32_t tGetToken(char* z, uint32_t* tokenId) {
break
;
}
case
'`'
:
{
for
(
i
=
1
;
z
[
i
];
i
++
)
{
if
(
z
[
i
]
==
'`'
)
{
i
++
;
*
tokenId
=
TK_ESCAPE
;
return
i
;
}
}
break
;
}
case
'.'
:
{
/*
* handle the the float number with out integer part
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录