Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
11636180
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看板
提交
11636180
编写于
3月 28, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rollup syntax and msg adjust
上级
a35e5fad
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
2293 addition
and
2103 deletion
+2293
-2103
include/common/ttokendef.h
include/common/ttokendef.h
+97
-96
include/libs/nodes/cmdnodes.h
include/libs/nodes/cmdnodes.h
+4
-0
include/util/tdef.h
include/util/tdef.h
+8
-0
source/libs/parser/inc/parAst.h
source/libs/parser/inc/parAst.h
+2
-1
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+2
-1
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+66
-7
source/libs/parser/src/parTokenizer.c
source/libs/parser/src/parTokenizer.c
+4
-1
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+127
-17
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+1980
-1978
source/libs/parser/test/parserAstTest.cpp
source/libs/parser/test/parserAstTest.cpp
+3
-2
未找到文件。
include/common/ttokendef.h
浏览文件 @
11636180
...
...
@@ -82,102 +82,103 @@
#define TK_SINGLE_STABLE 64
#define TK_STREAM_MODE 65
#define TK_RETENTIONS 66
#define TK_FILE_FACTOR 67
#define TK_NK_FLOAT 68
#define TK_TABLE 69
#define TK_NK_LP 70
#define TK_NK_RP 71
#define TK_STABLE 72
#define TK_ADD 73
#define TK_COLUMN 74
#define TK_MODIFY 75
#define TK_RENAME 76
#define TK_TAG 77
#define TK_SET 78
#define TK_NK_EQ 79
#define TK_USING 80
#define TK_TAGS 81
#define TK_NK_DOT 82
#define TK_NK_COMMA 83
#define TK_COMMENT 84
#define TK_BOOL 85
#define TK_TINYINT 86
#define TK_SMALLINT 87
#define TK_INT 88
#define TK_INTEGER 89
#define TK_BIGINT 90
#define TK_FLOAT 91
#define TK_DOUBLE 92
#define TK_BINARY 93
#define TK_TIMESTAMP 94
#define TK_NCHAR 95
#define TK_UNSIGNED 96
#define TK_JSON 97
#define TK_VARCHAR 98
#define TK_MEDIUMBLOB 99
#define TK_BLOB 100
#define TK_VARBINARY 101
#define TK_DECIMAL 102
#define TK_SMA 103
#define TK_ROLLUP 104
#define TK_SHOW 105
#define TK_DATABASES 106
#define TK_TABLES 107
#define TK_STABLES 108
#define TK_MNODES 109
#define TK_MODULES 110
#define TK_QNODES 111
#define TK_FUNCTIONS 112
#define TK_INDEXES 113
#define TK_FROM 114
#define TK_LIKE 115
#define TK_INDEX 116
#define TK_FULLTEXT 117
#define TK_FUNCTION 118
#define TK_INTERVAL 119
#define TK_TOPIC 120
#define TK_AS 121
#define TK_NK_BOOL 122
#define TK_NK_VARIABLE 123
#define TK_BETWEEN 124
#define TK_IS 125
#define TK_NULL 126
#define TK_NK_LT 127
#define TK_NK_GT 128
#define TK_NK_LE 129
#define TK_NK_GE 130
#define TK_NK_NE 131
#define TK_MATCH 132
#define TK_NMATCH 133
#define TK_IN 134
#define TK_JOIN 135
#define TK_INNER 136
#define TK_SELECT 137
#define TK_DISTINCT 138
#define TK_WHERE 139
#define TK_PARTITION 140
#define TK_BY 141
#define TK_SESSION 142
#define TK_STATE_WINDOW 143
#define TK_SLIDING 144
#define TK_FILL 145
#define TK_VALUE 146
#define TK_NONE 147
#define TK_PREV 148
#define TK_LINEAR 149
#define TK_NEXT 150
#define TK_GROUP 151
#define TK_HAVING 152
#define TK_ORDER 153
#define TK_SLIMIT 154
#define TK_SOFFSET 155
#define TK_LIMIT 156
#define TK_OFFSET 157
#define TK_ASC 158
#define TK_DESC 159
#define TK_NULLS 160
#define TK_FIRST 161
#define TK_LAST 162
#define TK_TABLE 67
#define TK_NK_LP 68
#define TK_NK_RP 69
#define TK_STABLE 70
#define TK_ADD 71
#define TK_COLUMN 72
#define TK_MODIFY 73
#define TK_RENAME 74
#define TK_TAG 75
#define TK_SET 76
#define TK_NK_EQ 77
#define TK_USING 78
#define TK_TAGS 79
#define TK_NK_DOT 80
#define TK_NK_COMMA 81
#define TK_COMMENT 82
#define TK_BOOL 83
#define TK_TINYINT 84
#define TK_SMALLINT 85
#define TK_INT 86
#define TK_INTEGER 87
#define TK_BIGINT 88
#define TK_FLOAT 89
#define TK_DOUBLE 90
#define TK_BINARY 91
#define TK_TIMESTAMP 92
#define TK_NCHAR 93
#define TK_UNSIGNED 94
#define TK_JSON 95
#define TK_VARCHAR 96
#define TK_MEDIUMBLOB 97
#define TK_BLOB 98
#define TK_VARBINARY 99
#define TK_DECIMAL 100
#define TK_SMA 101
#define TK_ROLLUP 102
#define TK_FILE_FACTOR 103
#define TK_NK_FLOAT 104
#define TK_DELAY 105
#define TK_SHOW 106
#define TK_DATABASES 107
#define TK_TABLES 108
#define TK_STABLES 109
#define TK_MNODES 110
#define TK_MODULES 111
#define TK_QNODES 112
#define TK_FUNCTIONS 113
#define TK_INDEXES 114
#define TK_FROM 115
#define TK_LIKE 116
#define TK_INDEX 117
#define TK_FULLTEXT 118
#define TK_FUNCTION 119
#define TK_INTERVAL 120
#define TK_TOPIC 121
#define TK_AS 122
#define TK_NK_BOOL 123
#define TK_NK_VARIABLE 124
#define TK_BETWEEN 125
#define TK_IS 126
#define TK_NULL 127
#define TK_NK_LT 128
#define TK_NK_GT 129
#define TK_NK_LE 130
#define TK_NK_GE 131
#define TK_NK_NE 132
#define TK_MATCH 133
#define TK_NMATCH 134
#define TK_IN 135
#define TK_JOIN 136
#define TK_INNER 137
#define TK_SELECT 138
#define TK_DISTINCT 139
#define TK_WHERE 140
#define TK_PARTITION 141
#define TK_BY 142
#define TK_SESSION 143
#define TK_STATE_WINDOW 144
#define TK_SLIDING 145
#define TK_FILL 146
#define TK_VALUE 147
#define TK_NONE 148
#define TK_PREV 149
#define TK_LINEAR 150
#define TK_NEXT 151
#define TK_GROUP 152
#define TK_HAVING 153
#define TK_ORDER 154
#define TK_SLIMIT 155
#define TK_SOFFSET 156
#define TK_LIMIT 157
#define TK_OFFSET 158
#define TK_ASC 159
#define TK_DESC 160
#define TK_NULLS 161
#define TK_FIRST 162
#define TK_LAST 163
#define TK_NK_SPACE 300
#define TK_NK_COMMENT 301
...
...
include/libs/nodes/cmdnodes.h
浏览文件 @
11636180
...
...
@@ -41,6 +41,7 @@ typedef struct SDatabaseOptions {
int32_t
numOfVgroups
;
int8_t
singleStable
;
int8_t
streamMode
;
SNodeList
*
pRetentions
;
}
SDatabaseOptions
;
typedef
struct
SCreateDatabaseStmt
{
...
...
@@ -73,6 +74,9 @@ typedef struct STableOptions {
int32_t
ttl
;
char
comments
[
TSDB_STB_COMMENT_LEN
];
SNodeList
*
pSma
;
SNodeList
*
pFuncs
;
float
filesFactor
;
int32_t
delay
;
}
STableOptions
;
typedef
struct
SColumnDefNode
{
...
...
include/util/tdef.h
浏览文件 @
11636180
...
...
@@ -369,6 +369,14 @@ typedef enum ELogicConditionType {
#define TSDB_MAX_DB_CACHE_LAST_ROW 3
#define TSDB_DEFAULT_CACHE_LAST_ROW 0
#define TSDB_MIN_DB_FILE_FACTOR 0
#define TSDB_MAX_DB_FILE_FACTOR 1
#define TSDB_DEFAULT_DB_FILE_FACTOR 0.1
#define TSDB_MIN_DB_DELAY 1
#define TSDB_MAX_DB_DELAY 10
#define TSDB_DEFAULT_DB_DELAY 2
#define TSDB_MAX_JOIN_TABLE_NUM 10
#define TSDB_MAX_UNION_CLAUSE 5
...
...
source/libs/parser/inc/parAst.h
浏览文件 @
11636180
...
...
@@ -53,7 +53,6 @@ typedef enum EDatabaseOptionType {
DB_OPTION_SINGLE_STABLE
,
DB_OPTION_STREAM_MODE
,
DB_OPTION_RETENTIONS
,
DB_OPTION_FILE_FACTOR
,
DB_OPTION_MAX
}
EDatabaseOptionType
;
...
...
@@ -63,6 +62,8 @@ typedef enum ETableOptionType {
TABLE_OPTION_TTL
,
TABLE_OPTION_COMMENT
,
TABLE_OPTION_SMA
,
TABLE_OPTION_FILE_FACTOR
,
TABLE_OPTION_DELAY
,
TABLE_OPTION_MAX
}
ETableOptionType
;
...
...
source/libs/parser/inc/sql.y
浏览文件 @
11636180
...
...
@@ -146,7 +146,6 @@ db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C).
db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLE_STABLE, &C); }
db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAM_MODE, &C); }
db_options(A) ::= db_options(B) RETENTIONS NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_RETENTIONS, &C); }
db_options(A) ::= db_options(B) FILE_FACTOR NK_FLOAT(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_FILE_FACTOR, &C); }
alter_db_options(A) ::= alter_db_option(B). { A = createDefaultAlterDatabaseOptions(pCxt); A = setDatabaseOption(pCxt, A, B.type, &B.val); }
alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setDatabaseOption(pCxt, B, C.type, &C.val); }
...
...
@@ -263,6 +262,8 @@ table_options(A) ::= table_options(B) KEEP NK_INTEGER(C).
table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_TTL, &C); }
table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { A = setTableSmaOption(pCxt, B, C); }
table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { A = setTableRollupOption(pCxt, B, C); }
table_options(A) ::= table_options(B) FILE_FACTOR NK_FLOAT(C). { A = setTableOption(pCxt, B, TABLE_OPTION_FILE_FACTOR, &C); }
table_options(A) ::= table_options(B) DELAY NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_DELAY, &C); }
alter_table_options(A) ::= alter_table_option(B). { A = createDefaultAlterTableOptions(pCxt); A = setTableOption(pCxt, A, B.type, &B.val); }
alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTableOption(pCxt, B, C.type, &C.val); }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
11636180
...
...
@@ -248,12 +248,37 @@ static SDatabaseOptions* setDbStreamMode(SAstCreateContext* pCxt, SDatabaseOptio
}
static
SDatabaseOptions
*
setDbRetentions
(
SAstCreateContext
*
pCxt
,
SDatabaseOptions
*
pOptions
,
const
SToken
*
pVal
)
{
// todo
return
pOptions
;
}
pOptions
->
pRetentions
=
nodesMakeList
();
if
(
NULL
==
pOptions
->
pRetentions
)
{
pCxt
->
valid
=
false
;
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"Out of memory"
);
return
pOptions
;
}
char
val
[
20
]
=
{
0
};
int32_t
len
=
trimString
(
pVal
->
z
,
pVal
->
n
,
val
,
sizeof
(
val
));
char
*
pStart
=
val
;
char
*
pEnd
=
val
+
len
;
int32_t
sepOrder
=
1
;
while
(
1
)
{
char
*
pPos
=
strchr
(
pStart
,
(
0
==
sepOrder
%
2
)
?
','
:
':'
);
SToken
t
=
{
.
type
=
TK_NK_VARIABLE
,
.
z
=
pStart
,
.
n
=
(
NULL
==
pPos
?
pEnd
-
pStart
:
pPos
-
pStart
)};
if
(
TSDB_CODE_SUCCESS
!=
nodesListStrictAppend
(
pOptions
->
pRetentions
,
createDurationValueNode
(
pCxt
,
&
t
)))
{
pCxt
->
valid
=
false
;
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"Out of memory"
);
return
pOptions
;
}
if
(
NULL
==
pPos
)
{
break
;
}
pStart
=
pPos
+
1
;
}
if
(
LIST_LENGTH
(
pOptions
->
pRetentions
)
%
2
!=
0
)
{
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"invalid db option retentions: %s"
,
val
);
pCxt
->
valid
=
false
;
}
static
SDatabaseOptions
*
setDbFileFactor
(
SAstCreateContext
*
pCxt
,
SDatabaseOptions
*
pOptions
,
const
SToken
*
pVal
)
{
// todo
return
pOptions
;
}
...
...
@@ -276,7 +301,6 @@ static void initSetDatabaseOptionFp() {
setDbOptionFuncs
[
DB_OPTION_SINGLE_STABLE
]
=
setDbSingleStable
;
setDbOptionFuncs
[
DB_OPTION_STREAM_MODE
]
=
setDbStreamMode
;
setDbOptionFuncs
[
DB_OPTION_RETENTIONS
]
=
setDbRetentions
;
setDbOptionFuncs
[
DB_OPTION_FILE_FACTOR
]
=
setDbFileFactor
;
}
static
STableOptions
*
setTableKeep
(
SAstCreateContext
*
pCxt
,
STableOptions
*
pOptions
,
const
SToken
*
pVal
)
{
...
...
@@ -314,10 +338,36 @@ static STableOptions* setTableComment(SAstCreateContext* pCxt, STableOptions* pO
return
pOptions
;
}
static
STableOptions
*
setTableFileFactor
(
SAstCreateContext
*
pCxt
,
STableOptions
*
pOptions
,
const
SToken
*
pVal
)
{
double
val
=
strtod
(
pVal
->
z
,
NULL
);
if
(
val
<
TSDB_MIN_DB_FILE_FACTOR
||
val
>
TSDB_MAX_DB_FILE_FACTOR
)
{
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"invalid table option file_factor: %f valid range: [%d, %d]"
,
val
,
TSDB_MIN_DB_FILE_FACTOR
,
TSDB_MAX_DB_FILE_FACTOR
);
pCxt
->
valid
=
false
;
return
pOptions
;
}
pOptions
->
filesFactor
=
val
;
return
pOptions
;
}
static
STableOptions
*
setTableDelay
(
SAstCreateContext
*
pCxt
,
STableOptions
*
pOptions
,
const
SToken
*
pVal
)
{
int64_t
val
=
strtol
(
pVal
->
z
,
NULL
,
10
);
if
(
val
<
TSDB_MIN_DB_DELAY
||
val
>
TSDB_MAX_DB_DELAY
)
{
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"invalid table option delay: %"
PRId64
" valid range: [%d, %d]"
,
val
,
TSDB_MIN_DB_DELAY
,
TSDB_MAX_DB_DELAY
);
pCxt
->
valid
=
false
;
return
pOptions
;
}
pOptions
->
delay
=
val
;
return
pOptions
;
}
static
void
initSetTableOptionFp
()
{
setTableOptionFuncs
[
TABLE_OPTION_KEEP
]
=
setTableKeep
;
setTableOptionFuncs
[
TABLE_OPTION_TTL
]
=
setTableTtl
;
setTableOptionFuncs
[
TABLE_OPTION_COMMENT
]
=
setTableComment
;
setTableOptionFuncs
[
TABLE_OPTION_FILE_FACTOR
]
=
setTableFileFactor
;
setTableOptionFuncs
[
TABLE_OPTION_DELAY
]
=
setTableDelay
;
}
void
initAstCreateContext
(
SParseContext
*
pParseCxt
,
SAstCreateContext
*
pCxt
)
{
...
...
@@ -906,6 +956,8 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
CHECK_OUT_OF_MEM
(
pOptions
);
pOptions
->
keep
=
TSDB_DEFAULT_KEEP
;
pOptions
->
ttl
=
TSDB_DEFAULT_DB_TTL_OPTION
;
pOptions
->
filesFactor
=
TSDB_DEFAULT_DB_FILE_FACTOR
;
pOptions
->
delay
=
TSDB_DEFAULT_DB_DELAY
;
return
(
SNode
*
)
pOptions
;
}
...
...
@@ -914,6 +966,8 @@ SNode* createDefaultAlterTableOptions(SAstCreateContext* pCxt) {
CHECK_OUT_OF_MEM
(
pOptions
);
pOptions
->
keep
=
-
1
;
pOptions
->
ttl
=
-
1
;
pOptions
->
filesFactor
=
-
1
;
pOptions
->
delay
=
-
1
;
return
(
SNode
*
)
pOptions
;
}
...
...
@@ -927,7 +981,12 @@ SNode* setTableSmaOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pS
}
SNode
*
setTableRollupOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SNodeList
*
pFuncs
)
{
// todo
if
(
1
!=
LIST_LENGTH
(
pFuncs
))
{
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"invalid table option rollup: only one function is allowed"
);
pCxt
->
valid
=
false
;
return
pOptions
;
}
((
STableOptions
*
)
pOptions
)
->
pFuncs
=
pFuncs
;
return
pOptions
;
}
...
...
source/libs/parser/src/parTokenizer.c
浏览文件 @
11636180
...
...
@@ -48,6 +48,7 @@ static SKeyword keywordTable[] = {
{
"DATABASE"
,
TK_DATABASE
},
{
"DATABASES"
,
TK_DATABASES
},
{
"DAYS"
,
TK_DAYS
},
{
"DELAY"
,
TK_DELAY
},
{
"DESC"
,
TK_DESC
},
{
"DISTINCT"
,
TK_DISTINCT
},
{
"DNODE"
,
TK_DNODE
},
...
...
@@ -55,7 +56,7 @@ static SKeyword keywordTable[] = {
{
"DOUBLE"
,
TK_DOUBLE
},
{
"DROP"
,
TK_DROP
},
{
"EXISTS"
,
TK_EXISTS
},
// {"FILE", TK_FILE
},
{
"FILE_FACTOR"
,
TK_FILE_FACTOR
},
{
"FILL"
,
TK_FILL
},
{
"FLOAT"
,
TK_FLOAT
},
{
"FROM"
,
TK_FROM
},
...
...
@@ -107,6 +108,8 @@ static SKeyword keywordTable[] = {
{
"QNODES"
,
TK_QNODES
},
{
"QUORUM"
,
TK_QUORUM
},
{
"REPLICA"
,
TK_REPLICA
},
{
"RETENTIONS"
,
TK_RETENTIONS
},
{
"ROLLUP"
,
TK_ROLLUP
},
{
"SELECT"
,
TK_SELECT
},
{
"SESSION"
,
TK_SESSION
},
{
"SHOW"
,
TK_SHOW
},
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
11636180
...
...
@@ -920,7 +920,35 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) {
return
code
;
}
static
void
buildCreateDbReq
(
STranslateContext
*
pCxt
,
SCreateDatabaseStmt
*
pStmt
,
SCreateDbReq
*
pReq
)
{
static
int32_t
buildCreateDbRetentions
(
const
SNodeList
*
pRetentions
,
SCreateDbReq
*
pReq
)
{
if
(
NULL
!=
pRetentions
)
{
pReq
->
pRetensions
=
taosArrayInit
(
LIST_LENGTH
(
pRetentions
)
/
2
,
sizeof
(
SRetention
));
if
(
NULL
==
pReq
->
pRetensions
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
SValueNode
*
pFreq
=
NULL
;
SValueNode
*
pKeep
=
NULL
;
SNode
*
pNode
=
NULL
;
int32_t
index
=
0
;
FOREACH
(
pNode
,
pRetentions
)
{
if
(
0
==
index
%
2
)
{
pFreq
=
(
SValueNode
*
)
pNode
;
}
else
{
pKeep
=
(
SValueNode
*
)
pNode
;
SRetention
retention
=
{
.
freq
=
pFreq
->
datum
.
i
,
.
freqUnit
=
pFreq
->
unit
,
.
keep
=
pKeep
->
datum
.
i
,
.
keepUnit
=
pKeep
->
unit
};
taosArrayPush
(
pReq
->
pRetensions
,
&
retention
);
}
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
buildCreateDbReq
(
STranslateContext
*
pCxt
,
SCreateDatabaseStmt
*
pStmt
,
SCreateDbReq
*
pReq
)
{
SName
name
=
{
0
};
tNameSetDbName
(
&
name
,
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
strlen
(
pStmt
->
dbName
));
tNameGetFullDbName
(
&
name
,
pReq
->
db
);
...
...
@@ -944,27 +972,45 @@ static void buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt
pReq
->
cacheLastRow
=
pStmt
->
pOptions
->
cachelast
;
pReq
->
ignoreExist
=
pStmt
->
ignoreExists
;
pReq
->
streamMode
=
pStmt
->
pOptions
->
streamMode
;
return
;
return
buildCreateDbRetentions
(
pStmt
->
pOptions
->
pRetentions
,
pReq
);
}
static
int32_t
checkCreateDatabase
(
STranslateContext
*
pCxt
,
SCreateDatabaseStmt
*
pStmt
)
{
if
(
NULL
!=
pStmt
->
pOptions
->
pRetentions
)
{
SNode
*
pNode
=
NULL
;
FOREACH
(
pNode
,
pStmt
->
pOptions
->
pRetentions
)
{
if
(
DEAL_RES_ERROR
==
translateValue
(
pCxt
,
(
SValueNode
*
)
pNode
))
{
return
pCxt
->
errCode
;
}
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateCreateDatabase
(
STranslateContext
*
pCxt
,
SCreateDatabaseStmt
*
pStmt
)
{
SCreateDbReq
createReq
=
{
0
};
buildCreateDbReq
(
pCxt
,
pStmt
,
&
createReq
);
pCxt
->
pCmdMsg
=
taosMemoryMalloc
(
sizeof
(
SCmdMsgInfo
)
);
if
(
NULL
==
pCxt
->
pCmdMsg
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
int32_t
code
=
checkCreateDatabase
(
pCxt
,
pStmt
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
buildCreateDbReq
(
pCxt
,
pStmt
,
&
createReq
)
;
}
pCxt
->
pCmdMsg
->
epSet
=
pCxt
->
pParseCxt
->
mgmtEpSet
;
pCxt
->
pCmdMsg
->
msgType
=
TDMT_MND_CREATE_DB
;
pCxt
->
pCmdMsg
->
msgLen
=
tSerializeSCreateDbReq
(
NULL
,
0
,
&
createReq
);
pCxt
->
pCmdMsg
->
pMsg
=
taosMemoryMalloc
(
pCxt
->
pCmdMsg
->
msgLen
);
if
(
NULL
==
pCxt
->
pCmdMsg
->
pMsg
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pCxt
->
pCmdMsg
=
taosMemoryMalloc
(
sizeof
(
SCmdMsgInfo
));
if
(
NULL
==
pCxt
->
pCmdMsg
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pCxt
->
pCmdMsg
->
epSet
=
pCxt
->
pParseCxt
->
mgmtEpSet
;
pCxt
->
pCmdMsg
->
msgType
=
TDMT_MND_CREATE_DB
;
pCxt
->
pCmdMsg
->
msgLen
=
tSerializeSCreateDbReq
(
NULL
,
0
,
&
createReq
);
pCxt
->
pCmdMsg
->
pMsg
=
taosMemoryMalloc
(
pCxt
->
pCmdMsg
->
msgLen
);
if
(
NULL
==
pCxt
->
pCmdMsg
->
pMsg
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
tSerializeSCreateDbReq
(
pCxt
->
pCmdMsg
->
pMsg
,
pCxt
->
pCmdMsg
->
msgLen
,
&
createReq
);
}
tSerializeSCreateDbReq
(
pCxt
->
pCmdMsg
->
pMsg
,
pCxt
->
pCmdMsg
->
msgLen
,
&
createReq
);
return
TSDB_CODE_SUCCESS
;
return
code
;
}
static
int32_t
translateDropDatabase
(
STranslateContext
*
pCxt
,
SDropDatabaseStmt
*
pStmt
)
{
...
...
@@ -1035,7 +1081,7 @@ static int32_t calcTypeBytes(SDataType dt) {
}
}
static
int32_t
columnNodeToField
(
SNodeList
*
pList
,
SArray
**
pArray
)
{
static
int32_t
column
Def
NodeToField
(
SNodeList
*
pList
,
SArray
**
pArray
)
{
*
pArray
=
taosArrayInit
(
LIST_LENGTH
(
pList
),
sizeof
(
SField
));
SNode
*
pNode
;
FOREACH
(
pNode
,
pList
)
{
...
...
@@ -1047,13 +1093,77 @@ static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
columnNodeToField
(
SNodeList
*
pList
,
SArray
**
pArray
)
{
if
(
NULL
==
pList
)
{
return
TSDB_CODE_SUCCESS
;
}
*
pArray
=
taosArrayInit
(
LIST_LENGTH
(
pList
),
sizeof
(
SField
));
SNode
*
pNode
;
FOREACH
(
pNode
,
pList
)
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
SField
field
=
{
.
type
=
pCol
->
node
.
resType
.
type
,
.
bytes
=
calcTypeBytes
(
pCol
->
node
.
resType
)
};
strcpy
(
field
.
name
,
pCol
->
colName
);
taosArrayPush
(
*
pArray
,
&
field
);
}
return
TSDB_CODE_SUCCESS
;
}
static
const
SColumnDefNode
*
findColDef
(
const
SNodeList
*
pCols
,
const
SColumnNode
*
pCol
)
{
SNode
*
pColDef
=
NULL
;
FOREACH
(
pColDef
,
pCols
)
{
if
(
0
==
strcmp
(
pCol
->
colName
,
((
SColumnDefNode
*
)
pColDef
)
->
colName
))
{
return
(
SColumnDefNode
*
)
pColDef
;
}
}
return
NULL
;
}
static
int32_t
checkCreateTable
(
STranslateContext
*
pCxt
,
SCreateTableStmt
*
pStmt
)
{
if
(
NULL
!=
pStmt
->
pOptions
->
pSma
)
{
SNode
*
pNode
=
NULL
;
FOREACH
(
pNode
,
pStmt
->
pOptions
->
pSma
)
{
SColumnNode
*
pSmaCol
=
(
SColumnNode
*
)
pNode
;
const
SColumnDefNode
*
pColDef
=
findColDef
(
pStmt
->
pCols
,
pSmaCol
);
if
(
NULL
==
pColDef
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_COLUMN
,
pSmaCol
->
colName
);
}
pSmaCol
->
node
.
resType
=
pColDef
->
dataType
;
}
}
if
(
NULL
!=
pStmt
->
pOptions
->
pFuncs
)
{
SFunctionNode
*
pFunc
=
nodesListGetNode
(
pStmt
->
pOptions
->
pFuncs
,
0
);
if
(
TSDB_CODE_SUCCESS
!=
fmGetFuncInfo
(
pFunc
->
functionName
,
&
pFunc
->
funcId
,
&
pFunc
->
funcType
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_INVALID_FUNTION
,
pFunc
->
functionName
);
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
getAggregationMethod
(
SNodeList
*
pFuncs
)
{
if
(
NULL
==
pFuncs
)
{
return
-
1
;
}
return
((
SFunctionNode
*
)
nodesListGetNode
(
pFuncs
,
0
))
->
funcId
;
}
static
int32_t
translateCreateSuperTable
(
STranslateContext
*
pCxt
,
SCreateTableStmt
*
pStmt
)
{
int32_t
code
=
checkCreateTable
(
pCxt
,
pStmt
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
SMCreateStbReq
createReq
=
{
0
};
createReq
.
igExists
=
pStmt
->
ignoreExists
;
columnNodeToField
(
pStmt
->
pCols
,
&
createReq
.
pColumns
);
columnNodeToField
(
pStmt
->
pTags
,
&
createReq
.
pTags
);
createReq
.
aggregationMethod
=
getAggregationMethod
(
pStmt
->
pOptions
->
pFuncs
);
createReq
.
xFilesFactor
=
pStmt
->
pOptions
->
filesFactor
;
createReq
.
delay
=
pStmt
->
pOptions
->
delay
;
columnDefNodeToField
(
pStmt
->
pCols
,
&
createReq
.
pColumns
);
columnDefNodeToField
(
pStmt
->
pTags
,
&
createReq
.
pTags
);
columnNodeToField
(
pStmt
->
pOptions
->
pSma
,
&
createReq
.
pSmas
);
createReq
.
numOfColumns
=
LIST_LENGTH
(
pStmt
->
pCols
);
createReq
.
numOfTags
=
LIST_LENGTH
(
pStmt
->
pTags
);
createReq
.
numOfSmas
=
LIST_LENGTH
(
pStmt
->
pOptions
->
pSma
);
SName
tableName
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
pCxt
->
pParseCxt
->
acctId
};
strcpy
(
tableName
.
dbname
,
pStmt
->
dbName
);
...
...
source/libs/parser/src/sql.c
浏览文件 @
11636180
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
source/libs/parser/test/parserAstTest.cpp
浏览文件 @
11636180
...
...
@@ -416,6 +416,7 @@ TEST_F(ParserTest, createDatabase) {
"VGROUPS 100 "
"SINGLE_STABLE 0 "
"STREAM_MODE 1 "
"RETENTIONS '15s:7d,1m:21d,15m:5y'"
);
ASSERT_TRUE
(
run
());
}
...
...
@@ -469,7 +470,7 @@ TEST_F(ParserTest, createTable) {
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) "
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, "
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) "
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)"
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)
ROLLUP (min) FILE_FACTOR 0.1 DELAY 2
"
);
ASSERT_TRUE
(
run
());
...
...
@@ -491,7 +492,7 @@ TEST_F(ParserTest, createTable) {
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) "
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, "
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) "
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)"
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)
ROLLUP (min) FILE_FACTOR 0.1 DELAY 2
"
);
ASSERT_TRUE
(
run
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录