Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5b5ac34d
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
未验证
提交
5b5ac34d
编写于
3月 10, 2022
作者:
X
Xiaoyu Wang
提交者:
GitHub
3月 10, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10675 from taosdata/feature/3.0_query_integrate_wxy
TD-13747 file name organize
上级
ddbe4095
a01f8d44
变更
31
隐藏空白更改
内联
并排
Showing
31 changed file
with
660 addition
and
2362 deletion
+660
-2362
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+2
-1
source/libs/nodes/inc/nodesUtil.h
source/libs/nodes/inc/nodesUtil.h
+0
-0
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+1
-1
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+1
-1
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+1
-1
source/libs/parser/inc/insertParser.h
source/libs/parser/inc/insertParser.h
+0
-31
source/libs/parser/inc/new_sql.y
source/libs/parser/inc/new_sql.y
+0
-557
source/libs/parser/inc/parAst.h
source/libs/parser/inc/parAst.h
+2
-2
source/libs/parser/inc/parInsertData.h
source/libs/parser/inc/parInsertData.h
+0
-0
source/libs/parser/inc/parInt.h
source/libs/parser/inc/parInt.h
+1
-0
source/libs/parser/inc/parToken.h
source/libs/parser/inc/parToken.h
+0
-0
source/libs/parser/inc/parUtil.h
source/libs/parser/inc/parUtil.h
+0
-1
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+536
-926
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+2
-2
source/libs/parser/src/parAstParser.c
source/libs/parser/src/parAstParser.c
+13
-13
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+4
-5
source/libs/parser/src/parInsertData.c
source/libs/parser/src/parInsertData.c
+2
-2
source/libs/parser/src/parTokenizer.c
source/libs/parser/src/parTokenizer.c
+1
-2
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+2
-2
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+1
-1
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+12
-4
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+72
-72
source/libs/parser/test/parserAstTest.cpp
source/libs/parser/test/parserAstTest.cpp
+1
-1
source/libs/parser/test/parserInsertTest.cpp
source/libs/parser/test/parserInsertTest.cpp
+1
-2
source/libs/parser/test/tokenizerTest.cpp
source/libs/parser/test/tokenizerTest.cpp
+0
-730
source/libs/planner/inc/planInt.h
source/libs/planner/inc/planInt.h
+0
-0
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+1
-1
source/libs/planner/src/planPhysiCreater.c
source/libs/planner/src/planPhysiCreater.c
+1
-1
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+1
-1
source/libs/planner/src/planner.c
source/libs/planner/src/planner.c
+1
-1
source/libs/planner/test/plannerTest.cpp
source/libs/planner/test/plannerTest.cpp
+1
-1
未找到文件。
source/client/src/clientImpl.c
浏览文件 @
5b5ac34d
...
@@ -173,6 +173,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
...
@@ -173,6 +173,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
SCmdMsgInfo
*
pMsgInfo
=
pQuery
->
pCmdMsg
;
SCmdMsgInfo
*
pMsgInfo
=
pQuery
->
pCmdMsg
;
pRequest
->
type
=
pMsgInfo
->
msgType
;
pRequest
->
type
=
pMsgInfo
->
msgType
;
pRequest
->
body
.
requestMsg
=
(
SDataBuf
){.
pData
=
pMsgInfo
->
pMsg
,
.
len
=
pMsgInfo
->
msgLen
,
.
handle
=
NULL
};
pRequest
->
body
.
requestMsg
=
(
SDataBuf
){.
pData
=
pMsgInfo
->
pMsg
,
.
len
=
pMsgInfo
->
msgLen
,
.
handle
=
NULL
};
pMsgInfo
->
pMsg
=
NULL
;
// pMsg transferred to SMsgSendInfo management
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SMsgSendInfo
*
pSendMsg
=
buildMsgInfoImpl
(
pRequest
);
SMsgSendInfo
*
pSendMsg
=
buildMsgInfoImpl
(
pRequest
);
...
@@ -248,7 +249,7 @@ TAOS_RES* taos_query_l(TAOS* taos, const char* sql, int sqlLen) {
...
@@ -248,7 +249,7 @@ TAOS_RES* taos_query_l(TAOS* taos, const char* sql, int sqlLen) {
}
}
SRequestObj
*
pRequest
=
NULL
;
SRequestObj
*
pRequest
=
NULL
;
SQuery
*
pQuery
;
SQuery
*
pQuery
=
NULL
;
SArray
*
pNodeList
=
taosArrayInit
(
4
,
sizeof
(
struct
SQueryNodeAddr
));
SArray
*
pNodeList
=
taosArrayInit
(
4
,
sizeof
(
struct
SQueryNodeAddr
));
terrno
=
TSDB_CODE_SUCCESS
;
terrno
=
TSDB_CODE_SUCCESS
;
...
...
source/libs/nodes/inc/nodes
int
.h
→
source/libs/nodes/inc/nodes
Util
.h
浏览文件 @
5b5ac34d
文件已移动
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
5b5ac34d
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "nodes
int
.h"
#include "nodes
Util
.h"
#include "plannodes.h"
#include "plannodes.h"
#include "querynodes.h"
#include "querynodes.h"
#include "taos.h"
#include "taos.h"
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
5b5ac34d
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "nodes
int
.h"
#include "nodes
Util
.h"
#include "plannodes.h"
#include "plannodes.h"
#include "querynodes.h"
#include "querynodes.h"
#include "query.h"
#include "query.h"
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
5b5ac34d
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
*/
*/
#include "cmdnodes.h"
#include "cmdnodes.h"
#include "nodes
int
.h"
#include "nodes
Util
.h"
#include "plannodes.h"
#include "plannodes.h"
#include "querynodes.h"
#include "querynodes.h"
#include "taos.h"
#include "taos.h"
...
...
source/libs/parser/inc/insertParser.h
已删除
100644 → 0
浏览文件 @
ddbe4095
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_INSERTPARSER_H
#define TDENGINE_INSERTPARSER_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "parser.h"
int32_t
parseInsertSql
(
SParseContext
*
pContext
,
SQuery
**
pQuery
);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_INSERTPARSER_H
source/libs/parser/inc/new_sql.y
已删除
100644 → 0
浏览文件 @
ddbe4095
//lemon parser file to generate sql parse by using finite-state-machine code used to parse sql
//usage: lemon sql.y
%name NewParse
%token_prefix TK_
%token_type { SToken }
%default_type { SNode* }
%default_destructor { nodesDestroyNode($$); }
%extra_argument { SAstCreateContext* pCxt }
%include {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdbool.h>
#include "nodes.h"
#include "ttoken.h"
#include "ttokendef.h"
#include "astCreateFuncs.h"
}
%syntax_error {
if(TOKEN.z) {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
} else {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL);
}
pCxt->valid = false;
}
%left OR.
%left AND.
//%right NOT.
%left UNION ALL MINUS EXCEPT INTERSECT.
%left NK_BITAND NK_BITOR NK_LSHIFT NK_RSHIFT.
%left NK_PLUS NK_MINUS.
//%left DIVIDE TIMES.
%left NK_STAR NK_SLASH NK_REM.
%left NK_CONCAT.
//%right NK_BITNOT.
/************************************************ create/alter/drop/show user *****************************************/
cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B);}
cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B);}
cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B);}
cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); }
cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); }
/************************************************ create/drop/show dnode **********************************************/
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL);}
cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B);}
cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);}
cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);}
cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); }
%type dnode_endpoint { SToken }
%destructor dnode_endpoint { }
dnode_endpoint(A) ::= NK_STRING(B). { A = B; }
%type dnode_host_name { SToken }
%destructor dnode_host_name { }
dnode_host_name(A) ::= NK_ID(B). { A = B; }
dnode_host_name(A) ::= NK_IPTOKEN(B). { A = B; }
/************************************************ create/drop/show/use database ***************************************/
cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C);}
cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); }
cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); }
cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A);}
%type not_exists_opt { bool }
%destructor not_exists_opt { }
not_exists_opt(A) ::= IF NOT EXISTS. { A = true; }
not_exists_opt(A) ::= . { A = false; }
%type exists_opt { bool }
%destructor exists_opt { }
exists_opt(A) ::= IF EXISTS. { A = true; }
exists_opt(A) ::= . { A = false; }
%type db_options { SDatabaseOptions* }
%destructor db_options { tfree($$); }
db_options(A) ::= . { A = createDefaultDatabaseOptions(pCxt); }
db_options(A) ::= db_options(B) BLOCKS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_BLOCKS, &C); }
db_options(A) ::= db_options(B) CACHE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_CACHE, &C); }
db_options(A) ::= db_options(B) CACHELAST NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_CACHELAST, &C); }
db_options(A) ::= db_options(B) COMP NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMP, &C); }
db_options(A) ::= db_options(B) DAYS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_DAYS, &C); }
db_options(A) ::= db_options(B) FSYNC NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_FSYNC, &C); }
db_options(A) ::= db_options(B) MAXROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MAXROWS, &C); }
db_options(A) ::= db_options(B) MINROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MINROWS, &C); }
db_options(A) ::= db_options(B) KEEP NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_KEEP, &C); }
db_options(A) ::= db_options(B) PRECISION NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_PRECISION, &C); }
db_options(A) ::= db_options(B) QUORUM NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_QUORUM, &C); }
db_options(A) ::= db_options(B) REPLICA NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_REPLICA, &C); }
db_options(A) ::= db_options(B) TTL NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_TTL, &C); }
db_options(A) ::= db_options(B) WAL NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_WAL, &C); }
db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_VGROUPS, &C); }
db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLESTABLE, &C); }
db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAMMODE, &C); }
/************************************************ create/drop/show table/stable ***************************************/
cmd ::= CREATE TABLE not_exists_opt(A) full_table_name(B)
NK_LP column_def_list(C) NK_RP tags_def_opt(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);}
cmd ::= CREATE TABLE multi_create_clause(A). { pCxt->pRootNode = createCreateMultiTableStmt(pCxt, A);}
cmd ::= CREATE STABLE not_exists_opt(A) full_table_name(B)
NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);}
cmd ::= DROP TABLE multi_drop_clause(A). { pCxt->pRootNode = createDropTableStmt(pCxt, A); }
cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
cmd ::= SHOW TABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, NULL); }
cmd ::= SHOW STABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, NULL); }
%type multi_create_clause { SNodeList* }
%destructor multi_create_clause { nodesDestroyList($$); }
multi_create_clause(A) ::= create_subtable_clause(B). { A = createNodeList(pCxt, B); }
multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C). { A = addNodeToList(pCxt, B, C); }
create_subtable_clause(A) ::=
not_exists_opt(B) full_table_name(C) USING full_table_name(D)
specific_tags_opt(E) TAGS NK_LP literal_list(F) NK_RP. { A = createCreateSubTableClause(pCxt, B, C, D, E, F); }
%type multi_drop_clause { SNodeList* }
%destructor multi_drop_clause { nodesDestroyList($$); }
multi_drop_clause(A) ::= drop_table_clause(B). { A = createNodeList(pCxt, B); }
multi_drop_clause(A) ::= multi_drop_clause(B) drop_table_clause(C). { A = addNodeToList(pCxt, B, C); }
drop_table_clause(A) ::= exists_opt(B) full_table_name(C). { A = createDropTableClause(pCxt, B, C); }
%type specific_tags_opt { SNodeList* }
%destructor specific_tags_opt { nodesDestroyList($$); }
specific_tags_opt(A) ::= . { A = NULL; }
specific_tags_opt(A) ::= NK_LP col_name_list(B) NK_RP. { A = B; }
full_table_name(A) ::= table_name(B). { A = createRealTableNode(pCxt, NULL, &B, NULL); }
full_table_name(A) ::= db_name(B) NK_DOT table_name(C). { A = createRealTableNode(pCxt, &B, &C, NULL); }
%type column_def_list { SNodeList* }
%destructor column_def_list { nodesDestroyList($$); }
column_def_list(A) ::= column_def(B). { A = createNodeList(pCxt, B); }
column_def_list(A) ::= column_def_list(B) NK_COMMA column_def(C). { A = addNodeToList(pCxt, B, C); }
column_def(A) ::= column_name(B) type_name(C). { A = createColumnDefNode(pCxt, &B, C, NULL); }
column_def(A) ::= column_name(B) type_name(C) COMMENT NK_STRING(D). { A = createColumnDefNode(pCxt, &B, C, &D); }
%type type_name { SDataType }
%destructor type_name { }
type_name(A) ::= BOOL. { A = createDataType(TSDB_DATA_TYPE_BOOL); }
type_name(A) ::= TINYINT. { A = createDataType(TSDB_DATA_TYPE_TINYINT); }
type_name(A) ::= SMALLINT. { A = createDataType(TSDB_DATA_TYPE_SMALLINT); }
type_name(A) ::= INT. { A = createDataType(TSDB_DATA_TYPE_INT); }
type_name(A) ::= INTEGER. { A = createDataType(TSDB_DATA_TYPE_INT); }
type_name(A) ::= BIGINT. { A = createDataType(TSDB_DATA_TYPE_BIGINT); }
type_name(A) ::= FLOAT. { A = createDataType(TSDB_DATA_TYPE_FLOAT); }
type_name(A) ::= DOUBLE. { A = createDataType(TSDB_DATA_TYPE_DOUBLE); }
type_name(A) ::= BINARY NK_LP NK_INTEGER(B) NK_RP. { A = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &B); }
type_name(A) ::= TIMESTAMP. { A = createDataType(TSDB_DATA_TYPE_TIMESTAMP); }
type_name(A) ::= NCHAR NK_LP NK_INTEGER(B) NK_RP. { A = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &B); }
type_name(A) ::= TINYINT UNSIGNED. { A = createDataType(TSDB_DATA_TYPE_UTINYINT); }
type_name(A) ::= SMALLINT UNSIGNED. { A = createDataType(TSDB_DATA_TYPE_USMALLINT); }
type_name(A) ::= INT UNSIGNED. { A = createDataType(TSDB_DATA_TYPE_UINT); }
type_name(A) ::= BIGINT UNSIGNED. { A = createDataType(TSDB_DATA_TYPE_UBIGINT); }
type_name(A) ::= JSON. { A = createDataType(TSDB_DATA_TYPE_JSON); }
type_name(A) ::= VARCHAR NK_LP NK_INTEGER(B) NK_RP. { A = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &B); }
type_name(A) ::= MEDIUMBLOB. { A = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); }
type_name(A) ::= BLOB. { A = createDataType(TSDB_DATA_TYPE_BLOB); }
type_name(A) ::= VARBINARY NK_LP NK_INTEGER(B) NK_RP. { A = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &B); }
type_name(A) ::= DECIMAL. { A = createDataType(TSDB_DATA_TYPE_DECIMAL); }
type_name(A) ::= DECIMAL NK_LP NK_INTEGER NK_RP. { A = createDataType(TSDB_DATA_TYPE_DECIMAL); }
type_name(A) ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP. { A = createDataType(TSDB_DATA_TYPE_DECIMAL); }
%type tags_def_opt { SNodeList* }
%destructor tags_def_opt { nodesDestroyList($$); }
tags_def_opt(A) ::= . { A = NULL; }
tags_def_opt(A) ::= tags_def(B). { A = B; }
%type tags_def { SNodeList* }
%destructor tags_def { nodesDestroyList($$); }
tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP. { A = B; }
%type table_options { STableOptions* }
%destructor table_options { tfree($$); }
table_options(A) ::= . { A = createDefaultTableOptions(pCxt);}
table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { A = setTableOption(pCxt, B, TABLE_OPTION_COMMENT, &C); }
table_options(A) ::= table_options(B) KEEP NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_KEEP, &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); }
%type col_name_list { SNodeList* }
%destructor col_name_list { nodesDestroyList($$); }
col_name_list(A) ::= col_name(B). { A = createNodeList(pCxt, B); }
col_name_list(A) ::= col_name_list(B) NK_COMMA col_name(C). { A = addNodeToList(pCxt, B, C); }
col_name(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &B); }
/************************************************ show vgroups ********************************************************/
cmd ::= SHOW VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, NULL); }
cmd ::= SHOW db_name(B) NK_DOT VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &B); }
/************************************************ select **************************************************************/
cmd ::= query_expression(A). { pCxt->pRootNode = A; }
/************************************************ literal *************************************************************/
literal(A) ::= NK_INTEGER(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B)); }
literal(A) ::= NK_FLOAT(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &B)); }
literal(A) ::= NK_STRING(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B)); }
literal(A) ::= NK_BOOL(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &B)); }
literal(A) ::= TIMESTAMP(B) NK_STRING(C). { A = createRawExprNodeExt(pCxt, &B, &C, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &C)); }
literal(A) ::= duration_literal(B). { A = B; }
duration_literal(A) ::= NK_VARIABLE(B). { A = createRawExprNode(pCxt, &B, createDurationValueNode(pCxt, &B)); }
%type literal_list { SNodeList* }
%destructor literal_list { nodesDestroyList($$); }
literal_list(A) ::= literal(B). { A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); }
literal_list(A) ::= literal_list(B) NK_COMMA literal(C). { A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); }
/************************************************ names and identifiers ***********************************************/
%type db_name { SToken }
%destructor db_name { }
db_name(A) ::= NK_ID(B). { A = B; }
%type table_name { SToken }
%destructor table_name { }
table_name(A) ::= NK_ID(B). { A = B; }
%type column_name { SToken }
%destructor column_name { }
column_name(A) ::= NK_ID(B). { A = B; }
%type function_name { SToken }
%destructor function_name { }
function_name(A) ::= NK_ID(B). { A = B; }
%type table_alias { SToken }
%destructor table_alias { }
table_alias(A) ::= NK_ID(B). { A = B; }
%type column_alias { SToken }
%destructor column_alias { }
column_alias(A) ::= NK_ID(B). { A = B; }
%type user_name { SToken }
%destructor user_name { }
user_name(A) ::= NK_ID(B). { A = B; }
/************************************************ expression **********************************************************/
expression(A) ::= literal(B). { A = B; }
//expression(A) ::= NK_QUESTION(B). { A = B; }
//expression(A) ::= pseudo_column(B). { A = B; }
expression(A) ::= column_reference(B). { A = B; }
expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
expression(A) ::= function_name(B) NK_LP NK_STAR(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, createNodeList(pCxt, createColumnNode(pCxt, NULL, &C)))); }
//expression(A) ::= cast_expression(B). { A = B; }
//expression(A) ::= case_expression(B). { A = B; }
expression(A) ::= subquery(B). { A = B; }
expression(A) ::= NK_LP(B) expression(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, releaseRawExprNode(pCxt, C)); }
expression(A) ::= NK_PLUS(B) expression(C). {
SToken t = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &B, &t, releaseRawExprNode(pCxt, C));
}
expression(A) ::= NK_MINUS(B) expression(C). {
SToken t = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &B, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, C), NULL));
}
expression(A) ::= expression(B) NK_PLUS expression(C). {
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
}
expression(A) ::= expression(B) NK_MINUS expression(C). {
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
}
expression(A) ::= expression(B) NK_STAR expression(C). {
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
}
expression(A) ::= expression(B) NK_SLASH expression(C). {
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
}
expression(A) ::= expression(B) NK_REM expression(C). {
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
}
%type expression_list { SNodeList* }
%destructor expression_list { nodesDestroyList($$); }
expression_list(A) ::= expression(B). { A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); }
expression_list(A) ::= expression_list(B) NK_COMMA expression(C). { A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); }
column_reference(A) ::= column_name(B). { A = createRawExprNode(pCxt, &B, createColumnNode(pCxt, NULL, &B)); }
column_reference(A) ::= table_name(B) NK_DOT column_name(C). { A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); }
//pseudo_column(A) ::= NK_NOW. { A = createFunctionNode(pCxt, NULL, NULL); }
/************************************************ predicate ***********************************************************/
predicate(A) ::= expression(B) compare_op(C) expression(D). {
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, D);
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, C, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D)));
}
//predicate(A) ::= expression(B) compare_op sub_type expression(B).
predicate(A) ::= expression(B) BETWEEN expression(C) AND expression(D). {
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, D);
A = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, D)));
}
predicate(A) ::= expression(B) NOT BETWEEN expression(C) AND expression(D). {
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, D);
A = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D)));
}
predicate(A) ::= expression(B) IS NULL(C). {
SToken s = getTokenFromRawExprNode(pCxt, B);
A = createRawExprNodeExt(pCxt, &s, &C, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, B), NULL));
}
predicate(A) ::= expression(B) IS NOT NULL(C). {
SToken s = getTokenFromRawExprNode(pCxt, B);
A = createRawExprNodeExt(pCxt, &s, &C, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, B), NULL));
}
predicate(A) ::= expression(B) in_op(C) in_predicate_value(D). {
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, D);
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, C, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D)));
}
%type compare_op { EOperatorType }
%destructor compare_op { }
compare_op(A) ::= NK_LT. { A = OP_TYPE_LOWER_THAN; }
compare_op(A) ::= NK_GT. { A = OP_TYPE_GREATER_THAN; }
compare_op(A) ::= NK_LE. { A = OP_TYPE_LOWER_EQUAL; }
compare_op(A) ::= NK_GE. { A = OP_TYPE_GREATER_EQUAL; }
compare_op(A) ::= NK_NE. { A = OP_TYPE_NOT_EQUAL; }
compare_op(A) ::= NK_EQ. { A = OP_TYPE_EQUAL; }
compare_op(A) ::= LIKE. { A = OP_TYPE_LIKE; }
compare_op(A) ::= NOT LIKE. { A = OP_TYPE_NOT_LIKE; }
compare_op(A) ::= MATCH. { A = OP_TYPE_MATCH; }
compare_op(A) ::= NMATCH. { A = OP_TYPE_NMATCH; }
%type in_op { EOperatorType }
%destructor in_op { }
in_op(A) ::= IN. { A = OP_TYPE_IN; }
in_op(A) ::= NOT IN. { A = OP_TYPE_NOT_IN; }
in_predicate_value(A) ::= NK_LP(C) expression_list(B) NK_RP(D). { A = createRawExprNodeExt(pCxt, &C, &D, createNodeListNode(pCxt, B)); }
/************************************************ boolean_value_expression ********************************************/
boolean_value_expression(A) ::= boolean_primary(B). { A = B; }
boolean_value_expression(A) ::= NOT(C) boolean_primary(B). {
SToken e = getTokenFromRawExprNode(pCxt, B);
A = createRawExprNodeExt(pCxt, &C, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, B), NULL));
}
boolean_value_expression(A) ::=
boolean_value_expression(B) OR boolean_value_expression(C). {
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
}
boolean_value_expression(A) ::=
boolean_value_expression(B) AND boolean_value_expression(C). {
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
}
boolean_primary(A) ::= predicate(B). { A = B; }
boolean_primary(A) ::= NK_LP(C) boolean_value_expression(B) NK_RP(D). { A = createRawExprNodeExt(pCxt, &C, &D, releaseRawExprNode(pCxt, B)); }
/************************************************ common_expression ********************************************/
common_expression(A) ::= expression(B). { A = B; }
common_expression(A) ::= boolean_value_expression(B). { A = B; }
/************************************************ from_clause *********************************************************/
from_clause(A) ::= FROM table_reference_list(B). { A = B; }
table_reference_list(A) ::= table_reference(B). { A = B; }
table_reference_list(A) ::= table_reference_list(B) NK_COMMA table_reference(C). { A = createJoinTableNode(pCxt, JOIN_TYPE_INNER, B, C, NULL); }
/************************************************ table_reference *****************************************************/
table_reference(A) ::= table_primary(B). { A = B; }
table_reference(A) ::= joined_table(B). { A = B; }
table_primary(A) ::= table_name(B) alias_opt(C). { A = createRealTableNode(pCxt, NULL, &B, &C); }
table_primary(A) ::= db_name(B) NK_DOT table_name(C) alias_opt(D). { A = createRealTableNode(pCxt, &B, &C, &D); }
table_primary(A) ::= subquery(B) alias_opt(C). { A = createTempTableNode(pCxt, releaseRawExprNode(pCxt, B), &C); }
table_primary(A) ::= parenthesized_joined_table(B). { A = B; }
%type alias_opt { SToken }
%destructor alias_opt { }
alias_opt(A) ::= . { A = nil_token; }
alias_opt(A) ::= table_alias(B). { A = B; }
alias_opt(A) ::= AS table_alias(B). { A = B; }
parenthesized_joined_table(A) ::= NK_LP joined_table(B) NK_RP. { A = B; }
parenthesized_joined_table(A) ::= NK_LP parenthesized_joined_table(B) NK_RP. { A = B; }
/************************************************ joined_table ********************************************************/
joined_table(A) ::=
table_reference(B) join_type(C) JOIN table_reference(D) ON search_condition(E). { A = createJoinTableNode(pCxt, C, B, D, E); }
%type join_type { EJoinType }
%destructor join_type { }
join_type(A) ::= . { A = JOIN_TYPE_INNER; }
join_type(A) ::= INNER. { A = JOIN_TYPE_INNER; }
/************************************************ query_specification *************************************************/
query_specification(A) ::=
SELECT set_quantifier_opt(B) select_list(C) from_clause(D) where_clause_opt(E)
partition_by_clause_opt(F) twindow_clause_opt(G)
group_by_clause_opt(H) having_clause_opt(I). {
A = createSelectStmt(pCxt, B, C, D);
A = addWhereClause(pCxt, A, E);
A = addPartitionByClause(pCxt, A, F);
A = addWindowClauseClause(pCxt, A, G);
A = addGroupByClause(pCxt, A, H);
A = addHavingClause(pCxt, A, I);
}
%type set_quantifier_opt { bool }
%destructor set_quantifier_opt { }
set_quantifier_opt(A) ::= . { A = false; }
set_quantifier_opt(A) ::= DISTINCT. { A = true; }
set_quantifier_opt(A) ::= ALL. { A = false; }
%type select_list { SNodeList* }
%destructor select_list { nodesDestroyList($$); }
select_list(A) ::= NK_STAR. { A = NULL; }
select_list(A) ::= select_sublist(B). { A = B; }
%type select_sublist { SNodeList* }
%destructor select_sublist { nodesDestroyList($$); }
select_sublist(A) ::= select_item(B). { A = createNodeList(pCxt, B); }
select_sublist(A) ::= select_sublist(B) NK_COMMA select_item(C). { A = addNodeToList(pCxt, B, C); }
select_item(A) ::= common_expression(B). {
SToken t = getTokenFromRawExprNode(pCxt, B);
A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &t);
}
select_item(A) ::= common_expression(B) column_alias(C). { A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &C); }
select_item(A) ::= common_expression(B) AS column_alias(C). { A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &C); }
select_item(A) ::= table_name(B) NK_DOT NK_STAR(C). { A = createColumnNode(pCxt, &B, &C); }
where_clause_opt(A) ::= . { A = NULL; }
where_clause_opt(A) ::= WHERE search_condition(B). { A = B; }
%type partition_by_clause_opt { SNodeList* }
%destructor partition_by_clause_opt { nodesDestroyList($$); }
partition_by_clause_opt(A) ::= . { A = NULL; }
partition_by_clause_opt(A) ::= PARTITION BY expression_list(B). { A = B; }
twindow_clause_opt(A) ::= . { A = NULL; }
twindow_clause_opt(A) ::=
SESSION NK_LP column_reference(B) NK_COMMA NK_INTEGER(C) NK_RP. { A = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, B), &C); }
twindow_clause_opt(A) ::= STATE_WINDOW NK_LP column_reference(B) NK_RP. { A = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, B)); }
twindow_clause_opt(A) ::=
INTERVAL NK_LP duration_literal(B) NK_RP sliding_opt(C) fill_opt(D). { A = createIntervalWindowNode(pCxt, B, NULL, C, D); }
twindow_clause_opt(A) ::=
INTERVAL NK_LP duration_literal(B) NK_COMMA duration_literal(C) NK_RP
sliding_opt(D) fill_opt(E). { A = createIntervalWindowNode(pCxt, B, C, D, E); }
sliding_opt(A) ::= . { A = NULL; }
sliding_opt(A) ::= SLIDING NK_LP duration_literal(B) NK_RP. { A = B; }
fill_opt(A) ::= . { A = NULL; }
fill_opt(A) ::= FILL NK_LP fill_mode(B) NK_RP. { A = createFillNode(pCxt, B, NULL); }
fill_opt(A) ::= FILL NK_LP VALUE NK_COMMA literal_list(B) NK_RP. { A = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, B)); }
%type fill_mode { EFillMode }
%destructor fill_mode { }
fill_mode(A) ::= NONE. { A = FILL_MODE_NONE; }
fill_mode(A) ::= PREV. { A = FILL_MODE_PREV; }
fill_mode(A) ::= NULL. { A = FILL_MODE_NULL; }
fill_mode(A) ::= LINEAR. { A = FILL_MODE_LINEAR; }
fill_mode(A) ::= NEXT. { A = FILL_MODE_NEXT; }
%type group_by_clause_opt { SNodeList* }
%destructor group_by_clause_opt { nodesDestroyList($$); }
group_by_clause_opt(A) ::= . { A = NULL; }
group_by_clause_opt(A) ::= GROUP BY group_by_list(B). { A = B; }
%type group_by_list { SNodeList* }
%destructor group_by_list { nodesDestroyList($$); }
group_by_list(A) ::= expression(B). { A = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, B))); }
group_by_list(A) ::= group_by_list(B) NK_COMMA expression(C). { A = addNodeToList(pCxt, B, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, C))); }
having_clause_opt(A) ::= . { A = NULL; }
having_clause_opt(A) ::= HAVING search_condition(B). { A = B; }
/************************************************ query_expression ****************************************************/
query_expression(A) ::=
query_expression_body(B)
order_by_clause_opt(C) slimit_clause_opt(D) limit_clause_opt(E). {
A = addOrderByClause(pCxt, B, C);
A = addSlimitClause(pCxt, A, D);
A = addLimitClause(pCxt, A, E);
}
query_expression_body(A) ::= query_primary(B). { A = B; }
query_expression_body(A) ::=
query_expression_body(B) UNION ALL query_expression_body(D). { A = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, B, D); }
query_primary(A) ::= query_specification(B). { A = B; }
//query_primary(A) ::=
// NK_LP query_expression_body(B)
// order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP. { A = B;}
%type order_by_clause_opt { SNodeList* }
%destructor order_by_clause_opt { nodesDestroyList($$); }
order_by_clause_opt(A) ::= . { A = NULL; }
order_by_clause_opt(A) ::= ORDER BY sort_specification_list(B). { A = B; }
slimit_clause_opt(A) ::= . { A = NULL; }
slimit_clause_opt(A) ::= SLIMIT NK_INTEGER(B). { A = createLimitNode(pCxt, &B, NULL); }
slimit_clause_opt(A) ::= SLIMIT NK_INTEGER(B) SOFFSET NK_INTEGER(C). { A = createLimitNode(pCxt, &B, &C); }
slimit_clause_opt(A) ::= SLIMIT NK_INTEGER(C) NK_COMMA NK_INTEGER(B). { A = createLimitNode(pCxt, &B, &C); }
limit_clause_opt(A) ::= . { A = NULL; }
limit_clause_opt(A) ::= LIMIT NK_INTEGER(B). { A = createLimitNode(pCxt, &B, NULL); }
limit_clause_opt(A) ::= LIMIT NK_INTEGER(B) OFFSET NK_INTEGER(C). { A = createLimitNode(pCxt, &B, &C); }
limit_clause_opt(A) ::= LIMIT NK_INTEGER(C) NK_COMMA NK_INTEGER(B). { A = createLimitNode(pCxt, &B, &C); }
/************************************************ subquery ************************************************************/
subquery(A) ::= NK_LP(B) query_expression(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, C); }
/************************************************ search_condition ****************************************************/
search_condition(A) ::= common_expression(B). { A = releaseRawExprNode(pCxt, B); }
/************************************************ sort_specification_list *********************************************/
%type sort_specification_list { SNodeList* }
%destructor sort_specification_list { nodesDestroyList($$); }
sort_specification_list(A) ::= sort_specification(B). { A = createNodeList(pCxt, B); }
sort_specification_list(A) ::=
sort_specification_list(B) NK_COMMA sort_specification(C). { A = addNodeToList(pCxt, B, C); }
sort_specification(A) ::=
expression(B) ordering_specification_opt(C) null_ordering_opt(D). { A = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, B), C, D); }
%type ordering_specification_opt EOrder
%destructor ordering_specification_opt { }
ordering_specification_opt(A) ::= . { A = ORDER_ASC; }
ordering_specification_opt(A) ::= ASC. { A = ORDER_ASC; }
ordering_specification_opt(A) ::= DESC. { A = ORDER_DESC; }
%type null_ordering_opt ENullOrder
%destructor null_ordering_opt { }
null_ordering_opt(A) ::= . { A = NULL_ORDER_DEFAULT; }
null_ordering_opt(A) ::= NULLS FIRST. { A = NULL_ORDER_FIRST; }
null_ordering_opt(A) ::= NULLS LAST. { A = NULL_ORDER_LAST; }
source/libs/parser/inc/
astCreateFuncs
.h
→
source/libs/parser/inc/
parAst
.h
浏览文件 @
5b5ac34d
...
@@ -22,9 +22,9 @@ extern "C" {
...
@@ -22,9 +22,9 @@ extern "C" {
#include "cmdnodes.h"
#include "cmdnodes.h"
#include "parser.h"
#include "parser.h"
#include "parserUtil.h"
#include "parToken.h"
#include "parUtil.h"
#include "querynodes.h"
#include "querynodes.h"
#include "ttoken.h"
typedef
struct
SAstCreateContext
{
typedef
struct
SAstCreateContext
{
SParseContext
*
pQueryCxt
;
SParseContext
*
pQueryCxt
;
...
...
source/libs/parser/inc/
dataBlockMgt
.h
→
source/libs/parser/inc/
parInsertData
.h
浏览文件 @
5b5ac34d
文件已移动
source/libs/parser/inc/par
ser
Int.h
→
source/libs/parser/inc/parInt.h
浏览文件 @
5b5ac34d
...
@@ -22,6 +22,7 @@ extern "C" {
...
@@ -22,6 +22,7 @@ extern "C" {
#include "parser.h"
#include "parser.h"
int32_t
parseInsertSql
(
SParseContext
*
pContext
,
SQuery
**
pQuery
);
int32_t
doParse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
);
int32_t
doParse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
);
int32_t
doTranslate
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
);
int32_t
doTranslate
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
);
...
...
source/libs/parser/inc/
tt
oken.h
→
source/libs/parser/inc/
parT
oken.h
浏览文件 @
5b5ac34d
文件已移动
source/libs/parser/inc/par
ser
Util.h
→
source/libs/parser/inc/parUtil.h
浏览文件 @
5b5ac34d
...
@@ -22,7 +22,6 @@ extern "C" {
...
@@ -22,7 +22,6 @@ extern "C" {
#include "os.h"
#include "os.h"
#include "query.h"
#include "query.h"
#include "ttoken.h"
typedef
struct
SMsgBuf
{
typedef
struct
SMsgBuf
{
int32_t
len
;
int32_t
len
;
...
...
source/libs/parser/inc/sql.y
浏览文件 @
5b5ac34d
//lemon parser file to generate sql parse by using finite-state-machine code used to parse sql
//lemon parser file to generate sql parse by using finite-state-machine code used to parse sql
//usage: lemon sql.y
//usage: lemon sql.y
%token_prefix TK_
%token_type {SToken}
%default_type {SToken}
%extra_argument {SSqlInfo* pInfo}
%fallback ID BOOL INTEGER FLOAT STRING TIMESTAMP.
%token_prefix TK_
%token_type { SToken }
%default_type { SNode* }
%default_destructor { nodesDestroyNode($$); }
%left OR.
%extra_argument { SAstCreateContext* pCxt }
%left AND.
%right NOT.
%left EQ NE ISNULL NOTNULL IS LIKE MATCH NMATCH GLOB BETWEEN IN.
%left GT GE LT LE.
%left BITAND BITOR LSHIFT RSHIFT.
%left PLUS MINUS.
%left DIVIDE TIMES.
%left STAR SLASH REM.
%left CONCAT.
%right UMINUS UPLUS BITNOT.
%include {
%include {
#include <stdio.h>
#include <stdio.h>
...
@@ -26,920 +14,542 @@
...
@@ -26,920 +14,542 @@
#include <string.h>
#include <string.h>
#include <assert.h>
#include <assert.h>
#include <stdbool.h>
#include <stdbool.h>
#include "astGenerator.h"
#include "
tmsgtype
.h"
#include "
nodes
.h"
#include "
tt
oken.h"
#include "
parT
oken.h"
#include "ttokendef.h"
#include "ttokendef.h"
#include "tvariant.h"
#include "parAst.h"
#include "parserInt.h"
}
}
%syntax_error {
%syntax_error {
pInfo->valid = false;
int32_t outputBufLen = tListLen(pInfo->msg);
int32_t len = 0;
if(TOKEN.z) {
if(TOKEN.z) {
char msg[] = "syntax error near \"%s\"";
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
int32_t sqlLen = strlen(&TOKEN.z[0]);
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->msg, msg, tmpstr);
} else {
len = sprintf(pInfo->msg, msg, &TOKEN.z[0]);
}
} else {
len = sprintf(pInfo->msg, "Incomplete SQL statement");
}
assert(len <= outputBufLen);
}
%parse_accept {}
program ::= cmd. {}
//////////////////////////////////THE SHOW STATEMENT///////////////////////////////////////////
cmd ::= SHOW DATABASES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_DB, 0, 0);}
cmd ::= SHOW TOPICS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_TP, 0, 0);}
cmd ::= SHOW FUNCTIONS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_FUNC, 0, 0);}
cmd ::= SHOW MNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_MNODE, 0, 0);}
cmd ::= SHOW DNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_DNODE, 0, 0);}
cmd ::= SHOW ACCOUNTS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_ACCT, 0, 0);}
cmd ::= SHOW USERS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_USER, 0, 0);}
cmd ::= SHOW MODULES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_MODULE, 0, 0); }
cmd ::= SHOW QUERIES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_QUERIES, 0, 0); }
cmd ::= SHOW CONNECTIONS.{ setShowOptions(pInfo, TSDB_MGMT_TABLE_CONNS, 0, 0);}
cmd ::= SHOW STREAMS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_STREAMS, 0, 0); }
cmd ::= SHOW VARIABLES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VARIABLES, 0, 0); }
cmd ::= SHOW SCORES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_TRANS, 0, 0); }
cmd ::= SHOW GRANTS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); }
cmd ::= SHOW VNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); }
cmd ::= SHOW VNODES ids(X). { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &X, 0); }
%type dbPrefix {SToken}
dbPrefix(A) ::=. {A.n = 0; A.type = 0;}
dbPrefix(A) ::= ids(X) DOT. {A = X; }
%type cpxName {SToken}
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;
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &X);
}
cmd ::= SHOW CREATE STABLE ids(X) cpxName(Y). {
X.n += Y.n;
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_STABLE, 1, &X);
}
cmd ::= SHOW CREATE DATABASE ids(X). {
setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &X);
}
cmd ::= SHOW dbPrefix(X) TABLES. {
setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &X, 0);
}
cmd ::= SHOW dbPrefix(X) TABLES LIKE ids(Y). {
setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &X, &Y);
}
cmd ::= SHOW dbPrefix(X) STABLES. {
setShowOptions(pInfo, TSDB_MGMT_TABLE_STB, &X, 0);
}
cmd ::= SHOW dbPrefix(X) STABLES LIKE ids(Y). {
SToken token;
tSetDbName(&token, &X);
setShowOptions(pInfo, TSDB_MGMT_TABLE_STB, &token, &Y);
}
cmd ::= SHOW dbPrefix(X) VGROUPS. {
SToken token;
tSetDbName(&token, &X);
setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0);
}
cmd ::= SHOW dbPrefix(X) VGROUPS ids(Y). {
SToken token;
tSetDbName(&token, &X);
setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, &Y);
}
//drop configure for tables
cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). {
X.n += Z.n;
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;
setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y, -1, TSDB_SUPER_TABLE);
}
cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, TSDB_DB_TYPE_DEFAULT, -1); }
cmd ::= DROP TOPIC ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, TSDB_DB_TYPE_TOPIC, -1); }
cmd ::= DROP FUNCTION ids(X). { setDropFuncInfo(pInfo, TSDB_SQL_DROP_FUNCTION, &X); }
cmd ::= DROP DNODE ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X); }
cmd ::= DROP USER ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_DROP_USER, 1, &X); }
cmd ::= DROP ACCOUNT ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X); }
/////////////////////////////////THE USE STATEMENT//////////////////////////////////////////
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;
setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
}
cmd ::= DESC ids(X) cpxName(Y). {
X.n += Y.n;
setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
}
/////////////////////////////////THE ALTER STATEMENT////////////////////////////////////////
cmd ::= ALTER USER ids(X) PASS ids(Y). { setAlterUserSql(pInfo, TSDB_ALTER_USER_PASSWD, &X, &Y, NULL); }
cmd ::= ALTER USER ids(X) PRIVILEGE ids(Y). { setAlterUserSql(pInfo, TSDB_ALTER_USER_PRIVILEGES, &X, NULL, &Y);}
cmd ::= ALTER DNODE ids(X) ids(Y). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &X, &Y); }
cmd ::= ALTER DNODE ids(X) ids(Y) ids(Z). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &X, &Y, &Z); }
cmd ::= ALTER LOCAL ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &X); }
cmd ::= ALTER LOCAL ids(X) ids(Y). { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &X, &Y); }
cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
//cmd ::= ALTER TOPIC ids(X) alter_topic_optr(Y). { SToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
cmd ::= ALTER ACCOUNT ids(X) acct_optr(Z). { setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &X, NULL, &Z);}
cmd ::= ALTER ACCOUNT ids(X) PASS ids(Y) acct_optr(Z). { setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &X, &Y, &Z);}
////////////////////////////// COMPACT STATEMENT //////////////////////////////////////////////
cmd ::= COMPACT VNODES IN LP exprlist(Y) RP. { setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, Y);}
// An IDENTIFIER can be a generic identifier, or one of several keywords.
// Any non-standard keyword can also be an identifier.
// And "ids" is an identifer-or-string.
%type ids {SToken}
ids(A) ::= ID(X). {A = X; }
//ids(A) ::= STRING(X). {A = X; }
%type ifexists {SToken}
ifexists(X) ::= IF EXISTS. { X.n = 1;}
ifexists(X) ::= . { X.n = 0;}
%type ifnotexists {SToken}
ifnotexists(X) ::= IF NOT EXISTS. { X.n = 1;}
ifnotexists(X) ::= . { X.n = 0;}
/////////////////////////////////THE CREATE STATEMENT///////////////////////////////////////
//create option for dnode/db/user/account
cmd ::= CREATE DNODE ids(X) PORT ids(Y). { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 2, &X, &Y);}
cmd ::= CREATE DNODE IPTOKEN(X) PORT ids(Y). { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 2, &X, &Y);}
cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z).
{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);}
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
//cmd ::= CREATE TOPIC ifnotexists(Z) ids(X) topic_optr(Y). { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
cmd ::= CREATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) bufsize(B). { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &X, &Y, &Z, &B, 1);}
cmd ::= CREATE AGGREGATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) bufsize(B). { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &X, &Y, &Z, &B, 2);}
cmd ::= CREATE USER ids(X) PASS ids(Y). { setCreateUserSql(pInfo, &X, &Y);}
bufsize(Y) ::= . { Y.n = 0; }
bufsize(Y) ::= BUFSIZE INTEGER(X). { Y = X; }
pps(Y) ::= . { Y.n = 0; }
pps(Y) ::= PPS INTEGER(X). { Y = X; }
tseries(Y) ::= . { Y.n = 0; }
tseries(Y) ::= TSERIES INTEGER(X). { Y = X; }
dbs(Y) ::= . { Y.n = 0; }
dbs(Y) ::= DBS INTEGER(X). { Y = X; }
streams(Y) ::= . { Y.n = 0; }
streams(Y) ::= STREAMS INTEGER(X). { Y = X; }
storage(Y) ::= . { Y.n = 0; }
storage(Y) ::= STORAGE INTEGER(X). { Y = X; }
qtime(Y) ::= . { Y.n = 0; }
qtime(Y) ::= QTIME INTEGER(X). { Y = X; }
users(Y) ::= . { Y.n = 0; }
users(Y) ::= USERS INTEGER(X). { Y = X; }
conns(Y) ::= . { Y.n = 0; }
conns(Y) ::= CONNS INTEGER(X). { Y = X; }
state(Y) ::= . { Y.n = 0; }
state(Y) ::= STATE ids(X). { Y = X; }
%type acct_optr {SCreateAcctInfo}
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;
Y.maxTimeSeries = (D.n>0)?atoi(D.z):-1;
Y.maxStreams = (F.n>0)?atoi(F.z):-1;
Y.maxPointsPerSecond = (C.n>0)?atoi(C.z):-1;
Y.maxStorage = (P.n>0)?strtoll(P.z, NULL, 10):-1;
Y.maxQueryTime = (Q.n>0)?strtoll(Q.z, NULL, 10):-1;
Y.maxConnections = (L.n>0)?atoi(L.z):-1;
Y.stat = M;
}
%type intitemlist {SArray*}
%destructor intitemlist {taosArrayDestroy($$);}
%type intitem {SVariant}
intitemlist(A) ::= intitemlist(X) COMMA intitem(Y). { A = tListItemAppend(X, &Y, -1); }
intitemlist(A) ::= intitem(X). { A = tListItemAppend(NULL, &X, -1); }
intitem(A) ::= INTEGER(X). { toTSDBType(X.type); taosVariantCreate(&A, X.z, X.n, X.type); }
%type keep {SArray*}
%destructor keep {taosArrayDestroy($$);}
keep(Y) ::= KEEP intitemlist(X). { Y = X; }
cache(Y) ::= CACHE INTEGER(X). { Y = X; }
replica(Y) ::= REPLICA INTEGER(X). { Y = X; }
quorum(Y) ::= QUORUM INTEGER(X). { Y = X; }
days(Y) ::= DAYS INTEGER(X). { Y = X; }
minrows(Y) ::= MINROWS INTEGER(X). { Y = X; }
maxrows(Y) ::= MAXROWS INTEGER(X). { Y = X; }
blocks(Y) ::= BLOCKS INTEGER(X). { Y = X; }
ctime(Y) ::= CTIME INTEGER(X). { Y = X; }
wal(Y) ::= WAL INTEGER(X). { Y = X; }
fsync(Y) ::= FSYNC INTEGER(X). { Y = X; }
comp(Y) ::= COMP INTEGER(X). { Y = X; }
prec(Y) ::= PRECISION STRING(X). { Y = X; }
update(Y) ::= UPDATE INTEGER(X). { Y = X; }
cachelast(Y) ::= CACHELAST INTEGER(X). { Y = X; }
vgroups(Y) ::= VGROUPS INTEGER(X). { Y = X; }
//partitions(Y) ::= PARTITIONS INTEGER(X). { Y = X; }
stream_mode(Y) ::= STREAM MODE INTEGER(X). { Y = X; }
%type db_optr {SCreateDbInfo}
db_optr(Y) ::= . {setDefaultCreateDbOption(&Y);}
db_optr(Y) ::= db_optr(Z) cache(X). { Y = Z; Y.cacheBlockSize = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) quorum(X). { Y = Z; Y.quorum = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) days(X). { Y = Z; Y.daysPerFile = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) minrows(X). { Y = Z; Y.minRowsPerBlock = strtod(X.z, NULL); }
db_optr(Y) ::= db_optr(Z) maxrows(X). { Y = Z; Y.maxRowsPerBlock = strtod(X.z, NULL); }
db_optr(Y) ::= db_optr(Z) blocks(X). { Y = Z; Y.numOfBlocks = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) ctime(X). { Y = Z; Y.commitTime = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) comp(X). { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) prec(X). { Y = Z; Y.precision = X; }
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); }
db_optr(Y) ::= db_optr(Z) vgroups(X). { Y = Z; Y.numOfVgroups = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) stream_mode(X). { Y = Z; Y.streamMode = strtol(X.z, NULL, 10); }
//%type topic_optr {SCreateDbInfo}
//
//topic_optr(Y) ::= db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; }
//topic_optr(Y) ::= topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); }
%type alter_db_optr {SCreateDbInfo}
alter_db_optr(Y) ::= . { setDefaultCreateDbOption(&Y);}
alter_db_optr(Y) ::= alter_db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); }
alter_db_optr(Y) ::= alter_db_optr(Z) quorum(X). { Y = Z; Y.quorum = strtol(X.z, NULL, 10); }
alter_db_optr(Y) ::= alter_db_optr(Z) keep(X). { Y = Z; Y.keep = X; }
alter_db_optr(Y) ::= alter_db_optr(Z) blocks(X). { Y = Z; Y.numOfBlocks = strtol(X.z, NULL, 10); }
alter_db_optr(Y) ::= alter_db_optr(Z) comp(X). { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
alter_db_optr(Y) ::= alter_db_optr(Z) update(X). { Y = Z; Y.update = strtol(X.z, NULL, 10); }
alter_db_optr(Y) ::= alter_db_optr(Z) cachelast(X). { Y = Z; Y.cachelast = strtol(X.z, NULL, 10); }
// dynamically update the following two parameters are not allowed.
//alter_db_optr(Y) ::= alter_db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtol(X.z, NULL, 10); }
//alter_db_optr(Y) ::= alter_db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); } not support yet
//%type alter_topic_optr {SCreateDbInfo}
//alter_topic_optr(Y) ::= alter_db_optr(Z). { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; }
//alter_topic_optr(Y) ::= alter_topic_optr(Z) partitions(X). { Y = Z; Y.partitions = strtol(X.z, NULL, 10); }
%type typename {SField}
typename(A) ::= ids(X). {
X.type = 0;
tSetColumnType (&A, &X);
}
//define binary type, e.g., binary(10), nchar(10)
typename(A) ::= ids(X) LP signed(Y) RP. {
if (Y <= 0) {
X.type = 0;
tSetColumnType(&A, &X);
} else {
} else {
X.type = -Y; // negative value of name length
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL);
tSetColumnType(&A, &X);
}
}
pCxt->valid = false;
}
}
// define the unsigned number type
%left OR.
typename(A) ::= ids(X) UNSIGNED(Z). {
%left AND.
X.type = 0;
//%right NOT.
X.n = ((Z.z + Z.n) - X.z);
%left UNION ALL MINUS EXCEPT INTERSECT.
tSetColumnType (&A, &X);
%left NK_BITAND NK_BITOR NK_LSHIFT NK_RSHIFT.
}
%left NK_PLUS NK_MINUS.
//%left DIVIDE TIMES.
%type signed {int64_t}
%left NK_STAR NK_SLASH NK_REM.
signed(A) ::= INTEGER(X). { A = strtol(X.z, NULL, 10); }
%left NK_CONCAT.
signed(A) ::= PLUS INTEGER(X). { A = strtol(X.z, NULL, 10); }
//%right NK_BITNOT.
signed(A) ::= MINUS INTEGER(X). { A = -strtol(X.z, NULL, 10);}
/************************************************ create/alter/drop/show user *****************************************/
////////////////////////////////// The CREATE TABLE statement ///////////////////////////////
cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B);}
cmd ::= CREATE TABLE create_table_args. {}
cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B);}
cmd ::= CREATE TABLE create_stable_args. {}
cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B);}
cmd ::= CREATE STABLE create_stable_args. {}
cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); }
cmd ::= CREATE TABLE create_table_list(Z). { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = Z;}
cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); }
%type create_table_list{SCreateTableSql*}
/************************************************ create/drop/show dnode **********************************************/
%destructor create_table_list{destroyCreateTableSql($$);}
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL);}
create_table_list(A) ::= create_from_stable(Z). {
cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B);}
SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql));
cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);}
pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo));
cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);}
cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); }
taosArrayPush(pCreateTable->childTableInfo, &Z);
pCreateTable->type = TSDB_SQL_CREATE_TABLE;
%type dnode_endpoint { SToken }
A = pCreateTable;
%destructor dnode_endpoint { }
}
dnode_endpoint(A) ::= NK_STRING(B). { A = B; }
create_table_list(A) ::= create_table_list(X) create_from_stable(Z). {
%type dnode_host_name { SToken }
taosArrayPush(X->childTableInfo, &Z);
%destructor dnode_host_name { }
A = X;
dnode_host_name(A) ::= NK_ID(B). { A = B; }
}
dnode_host_name(A) ::= NK_IPTOKEN(B). { A = B; }
%type create_table_args{SCreateTableSql*}
/************************************************ create/drop/show/use database ***************************************/
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. {
cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C);}
A = tSetCreateTableInfo(X, NULL, NULL, TSDB_SQL_CREATE_TABLE);
cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); }
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); }
cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A);}
V.n += Z.n;
setCreatedTableName(pInfo, &V, &U);
%type not_exists_opt { bool }
}
%destructor not_exists_opt { }
not_exists_opt(A) ::= IF NOT EXISTS. { A = true; }
// create super table
not_exists_opt(A) ::= . { A = false; }
%type create_stable_args{SCreateTableSql*}
create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
%type exists_opt { bool }
A = tSetCreateTableInfo(X, Y, NULL, TSDB_SQL_CREATE_STABLE);
%destructor exists_opt { }
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_STABLE);
exists_opt(A) ::= IF EXISTS. { A = true; }
exists_opt(A) ::= . { A = false; }
V.n += Z.n;
setCreatedTableName(pInfo, &V, &U);
%type db_options { SDatabaseOptions* }
}
%destructor db_options { tfree($$); }
db_options(A) ::= . { A = createDefaultDatabaseOptions(pCxt); }
// create table by using super table
db_options(A) ::= db_options(B) BLOCKS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_BLOCKS, &C); }
// create table table_name using super_table_name tags(tag_values1, tag_values2)
db_options(A) ::= db_options(B) CACHE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_CACHE, &C); }
%type create_from_stable{SCreatedTableInfo}
db_options(A) ::= db_options(B) CACHELAST NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_CACHELAST, &C); }
create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) TAGS LP tagitemlist1(Y) RP. {
db_options(A) ::= db_options(B) COMP NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMP, &C); }
X.n += F.n;
db_options(A) ::= db_options(B) DAYS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_DAYS, &C); }
V.n += Z.n;
db_options(A) ::= db_options(B) FSYNC NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_FSYNC, &C); }
A = createNewChildTableInfo(&X, NULL, Y, &V, &U);
db_options(A) ::= db_options(B) MAXROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MAXROWS, &C); }
}
db_options(A) ::= db_options(B) MINROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MINROWS, &C); }
db_options(A) ::= db_options(B) KEEP NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_KEEP, &C); }
create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) LP tagNamelist(P) RP TAGS LP tagitemlist1(Y) RP. {
db_options(A) ::= db_options(B) PRECISION NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_PRECISION, &C); }
X.n += F.n;
db_options(A) ::= db_options(B) QUORUM NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_QUORUM, &C); }
V.n += Z.n;
db_options(A) ::= db_options(B) REPLICA NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_REPLICA, &C); }
A = createNewChildTableInfo(&X, P, Y, &V, &U);
db_options(A) ::= db_options(B) TTL NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_TTL, &C); }
}
db_options(A) ::= db_options(B) WAL NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_WAL, &C); }
db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_VGROUPS, &C); }
%type tagNamelist{SArray*}
db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLESTABLE, &C); }
%destructor tagNamelist {taosArrayDestroy($$);}
db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAMMODE, &C); }
tagNamelist(A) ::= tagNamelist(X) COMMA ids(Y). {taosArrayPush(X, &Y); A = X; }
tagNamelist(A) ::= ids(X). {A = taosArrayInit(4, sizeof(SToken)); taosArrayPush(A, &X);}
/************************************************ create/drop/show table/stable ***************************************/
cmd ::= CREATE TABLE not_exists_opt(A) full_table_name(B)
// create stream
NK_LP column_def_list(C) NK_RP tags_def_opt(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);}
// create table table_name as select count(*) from super_table_name interval(time)
cmd ::= CREATE TABLE multi_create_clause(A). { pCxt->pRootNode = createCreateMultiTableStmt(pCxt, A);}
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) AS select(S). {
cmd ::= CREATE STABLE not_exists_opt(A) full_table_name(B)
// A = tSetCreateTableInfo(NULL, NULL, S, TSQL_CREATE_STREAM);
NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);}
// setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
cmd ::= DROP TABLE multi_drop_clause(A). { pCxt->pRootNode = createDropTableStmt(pCxt, A); }
//
cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
// V.n += Z.n;
cmd ::= SHOW TABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, NULL); }
// setCreatedTableName(pInfo, &V, &U);
cmd ::= SHOW STABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, NULL); }
}
%type multi_create_clause { SNodeList* }
%type column{SField}
%destructor multi_create_clause { nodesDestroyList($$); }
%type columnlist{SArray*}
multi_create_clause(A) ::= create_subtable_clause(B). { A = createNodeList(pCxt, B); }
%destructor columnlist {taosArrayDestroy($$);}
multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C). { A = addNodeToList(pCxt, B, C); }
columnlist(A) ::= columnlist(X) COMMA column(Y). {taosArrayPush(X, &Y); A = X; }
columnlist(A) ::= column(X). {A = taosArrayInit(4, sizeof(SField)); taosArrayPush(A, &X);}
create_subtable_clause(A) ::=
not_exists_opt(B) full_table_name(C) USING full_table_name(D)
// The information used for a column is the name and type of column:
specific_tags_opt(E) TAGS NK_LP literal_list(F) NK_RP. { A = createCreateSubTableClause(pCxt, B, C, D, E, F); }
// tinyint smallint int bigint float double bool timestamp binary(x) nchar(x)
column(A) ::= ids(X) typename(Y). {
%type multi_drop_clause { SNodeList* }
tSetColumnInfo(&A, &X, &Y);
%destructor multi_drop_clause { nodesDestroyList($$); }
}
multi_drop_clause(A) ::= drop_table_clause(B). { A = createNodeList(pCxt, B); }
multi_drop_clause(A) ::= multi_drop_clause(B) drop_table_clause(C). { A = addNodeToList(pCxt, B, C); }
%type tagitemlist1 {SArray*}
%destructor tagitemlist1 {taosArrayDestroy($$);}
drop_table_clause(A) ::= exists_opt(B) full_table_name(C). { A = createDropTableClause(pCxt, B, C); }
tagitemlist1(A) ::= tagitemlist1(X) COMMA tagitem1(Y). { taosArrayPush(X, &Y); A = X;}
%type specific_tags_opt { SNodeList* }
tagitemlist1(A) ::= tagitem1(Y). { A = taosArrayInit(4, sizeof(SToken)); taosArrayPush(A, &Y); }
%destructor specific_tags_opt { nodesDestroyList($$); }
specific_tags_opt(A) ::= . { A = NULL; }
%type tagitem1 {SToken}
specific_tags_opt(A) ::= NK_LP col_name_list(B) NK_RP. { A = B; }
tagitem1(A) ::= MINUS(X) INTEGER(Y). { A.n = X.n + Y.n; A.type = Y.type; A.z = X.z;}
tagitem1(A) ::= MINUS(X) FLOAT(Y). { A.n = X.n + Y.n; A.type = Y.type; A.z = X.z;}
full_table_name(A) ::= table_name(B). { A = createRealTableNode(pCxt, NULL, &B, NULL); }
tagitem1(A) ::= PLUS(X) INTEGER(Y). { A.n = X.n + Y.n; A.type = Y.type; A.z = X.z;}
full_table_name(A) ::= db_name(B) NK_DOT table_name(C). { A = createRealTableNode(pCxt, &B, &C, NULL); }
tagitem1(A) ::= PLUS(X) FLOAT(Y). { A.n = X.n + Y.n; A.type = Y.type; A.z = X.z;}
tagitem1(A) ::= INTEGER(X). { A = X; }
%type column_def_list { SNodeList* }
tagitem1(A) ::= FLOAT(X). { A = X; }
%destructor column_def_list { nodesDestroyList($$); }
tagitem1(A) ::= STRING(X). { A = X; }
column_def_list(A) ::= column_def(B). { A = createNodeList(pCxt, B); }
tagitem1(A) ::= BOOL(X). { A = X; }
column_def_list(A) ::= column_def_list(B) NK_COMMA column_def(C). { A = addNodeToList(pCxt, B, C); }
tagitem1(A) ::= NULL(X). { A = X; }
tagitem1(A) ::= NOW(X). { A = X; }
column_def(A) ::= column_name(B) type_name(C). { A = createColumnDefNode(pCxt, &B, C, NULL); }
column_def(A) ::= column_name(B) type_name(C) COMMENT NK_STRING(D). { A = createColumnDefNode(pCxt, &B, C, &D); }
%type tagitemlist {SArray*}
%destructor tagitemlist {taosArrayDestroy($$);}
%type type_name { SDataType }
%destructor type_name { }
%type tagitem {SVariant}
type_name(A) ::= BOOL. { A = createDataType(TSDB_DATA_TYPE_BOOL); }
tagitemlist(A) ::= tagitemlist(X) COMMA tagitem(Y). { A = tListItemAppend(X, &Y, -1); }
type_name(A) ::= TINYINT. { A = createDataType(TSDB_DATA_TYPE_TINYINT); }
tagitemlist(A) ::= tagitem(X). { A = tListItemAppend(NULL, &X, -1); }
type_name(A) ::= SMALLINT. { A = createDataType(TSDB_DATA_TYPE_SMALLINT); }
type_name(A) ::= INT. { A = createDataType(TSDB_DATA_TYPE_INT); }
tagitem(A) ::= INTEGER(X). { toTSDBType(X.type); taosVariantCreate(&A, X.z, X.n, X.type); }
type_name(A) ::= INTEGER. { A = createDataType(TSDB_DATA_TYPE_INT); }
tagitem(A) ::= FLOAT(X). { toTSDBType(X.type); taosVariantCreate(&A, X.z, X.n, X.type); }
type_name(A) ::= BIGINT. { A = createDataType(TSDB_DATA_TYPE_BIGINT); }
tagitem(A) ::= STRING(X). { toTSDBType(X.type); taosVariantCreate(&A, X.z, X.n, X.type); }
type_name(A) ::= FLOAT. { A = createDataType(TSDB_DATA_TYPE_FLOAT); }
tagitem(A) ::= BOOL(X). { toTSDBType(X.type); taosVariantCreate(&A, X.z, X.n, X.type); }
type_name(A) ::= DOUBLE. { A = createDataType(TSDB_DATA_TYPE_DOUBLE); }
tagitem(A) ::= NULL(X). { X.type = 0; taosVariantCreate(&A, X.z, X.n, X.type); }
type_name(A) ::= BINARY NK_LP NK_INTEGER(B) NK_RP. { A = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &B); }
tagitem(A) ::= NOW(X). { X.type = TSDB_DATA_TYPE_TIMESTAMP; taosVariantCreate(&A, X.z, X.n, X.type);}
type_name(A) ::= TIMESTAMP. { A = createDataType(TSDB_DATA_TYPE_TIMESTAMP); }
type_name(A) ::= NCHAR NK_LP NK_INTEGER(B) NK_RP. { A = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &B); }
tagitem(A) ::= MINUS(X) INTEGER(Y).{
type_name(A) ::= TINYINT UNSIGNED. { A = createDataType(TSDB_DATA_TYPE_UTINYINT); }
X.n += Y.n;
type_name(A) ::= SMALLINT UNSIGNED. { A = createDataType(TSDB_DATA_TYPE_USMALLINT); }
X.type = Y.type;
type_name(A) ::= INT UNSIGNED. { A = createDataType(TSDB_DATA_TYPE_UINT); }
toTSDBType(X.type);
type_name(A) ::= BIGINT UNSIGNED. { A = createDataType(TSDB_DATA_TYPE_UBIGINT); }
taosVariantCreate(&A, X.z, X.n, X.type);
type_name(A) ::= JSON. { A = createDataType(TSDB_DATA_TYPE_JSON); }
}
type_name(A) ::= VARCHAR NK_LP NK_INTEGER(B) NK_RP. { A = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &B); }
type_name(A) ::= MEDIUMBLOB. { A = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); }
tagitem(A) ::= MINUS(X) FLOAT(Y). {
type_name(A) ::= BLOB. { A = createDataType(TSDB_DATA_TYPE_BLOB); }
X.n += Y.n;
type_name(A) ::= VARBINARY NK_LP NK_INTEGER(B) NK_RP. { A = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &B); }
X.type = Y.type;
type_name(A) ::= DECIMAL. { A = createDataType(TSDB_DATA_TYPE_DECIMAL); }
toTSDBType(X.type);
type_name(A) ::= DECIMAL NK_LP NK_INTEGER NK_RP. { A = createDataType(TSDB_DATA_TYPE_DECIMAL); }
taosVariantCreate(&A, X.z, X.n, X.type);
type_name(A) ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP. { A = createDataType(TSDB_DATA_TYPE_DECIMAL); }
}
%type tags_def_opt { SNodeList* }
tagitem(A) ::= PLUS(X) INTEGER(Y). {
%destructor tags_def_opt { nodesDestroyList($$); }
X.n += Y.n;
tags_def_opt(A) ::= . { A = NULL; }
X.type = Y.type;
tags_def_opt(A) ::= tags_def(B). { A = B; }
toTSDBType(X.type);
taosVariantCreate(&A, X.z, X.n, X.type);
%type tags_def { SNodeList* }
}
%destructor tags_def { nodesDestroyList($$); }
tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP. { A = B; }
tagitem(A) ::= PLUS(X) FLOAT(Y). {
X.n += Y.n;
%type table_options { STableOptions* }
X.type = Y.type;
%destructor table_options { tfree($$); }
toTSDBType(X.type);
table_options(A) ::= . { A = createDefaultTableOptions(pCxt);}
taosVariantCreate(&A, X.z, X.n, X.type);
table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { A = setTableOption(pCxt, B, TABLE_OPTION_COMMENT, &C); }
}
table_options(A) ::= table_options(B) KEEP NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_KEEP, &C); }
table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_TTL, &C); }
//////////////////////// The SELECT statement /////////////////////////////////
table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { A = setTableSmaOption(pCxt, B, C); }
%type select {SSqlNode*}
%destructor select {destroySqlNode($$);}
%type col_name_list { SNodeList* }
select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_option(K) sliding_opt(S) session_option(H) windowstate_option(D) fill_opt(F)groupby_opt(P) having_opt(N) orderby_opt(Z) slimit_opt(G) limit_opt(L). {
%destructor col_name_list { nodesDestroyList($$); }
A = tSetQuerySqlNode(&T, W, X, Y, P, Z, &K, &H, &D, &S, F, &L, &G, N);
col_name_list(A) ::= col_name(B). { A = createNodeList(pCxt, B); }
}
col_name_list(A) ::= col_name_list(B) NK_COMMA col_name(C). { A = addNodeToList(pCxt, B, C); }
select(A) ::= LP select(B) RP. {A = B;}
col_name(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &B); }
%type union {SSubclause*}
/************************************************ show vgroups ********************************************************/
%destructor union {destroyAllSqlNode($$);}
cmd ::= SHOW VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, NULL); }
union(Y) ::= select(X). { Y = setSubclause(NULL, X); }
cmd ::= SHOW db_name(B) NK_DOT VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &B); }
union(Y) ::= union(Z) UNION ALL select(X). { Y = appendSelectClause(Z, SQL_TYPE_UNIONALL, X); }
union(Y) ::= union(Z) UNION select(X). { Y = appendSelectClause(Z, SQL_TYPE_UNION, X); }
/************************************************ select **************************************************************/
cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); }
cmd ::= query_expression(A). { pCxt->pRootNode = A; }
// Support for the SQL exprssion without from & where subclauses, e.g.,
/************************************************ literal *************************************************************/
// select database()
literal(A) ::= NK_INTEGER(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B)); }
// select server_version()
literal(A) ::= NK_FLOAT(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &B)); }
// select client_version()
literal(A) ::= NK_STRING(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B)); }
// select server_state()
literal(A) ::= NK_BOOL(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &B)); }
select(A) ::= SELECT(T) selcollist(W). {
literal(A) ::= TIMESTAMP(B) NK_STRING(C). { A = createRawExprNodeExt(pCxt, &B, &C, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &C)); }
A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
literal(A) ::= duration_literal(B). { A = B; }
}
duration_literal(A) ::= NK_VARIABLE(B). { A = createRawExprNode(pCxt, &B, createDurationValueNode(pCxt, &B)); }
// selcollist is a list of expressions that are to become the return
// values of the SELECT statement. The "*" in statements like
%type literal_list { SNodeList* }
// "SELECT * FROM ..." is encoded as a special expression with an opcode of TK_ALL.
%destructor literal_list { nodesDestroyList($$); }
%type selcollist {SArray*}
literal_list(A) ::= literal(B). { A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); }
%destructor selcollist {tSqlExprListDestroy($$);}
literal_list(A) ::= literal_list(B) NK_COMMA literal(C). { A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); }
%type sclp {SArray*}
/************************************************ names and identifiers ***********************************************/
%destructor sclp {tSqlExprListDestroy($$);}
%type db_name { SToken }
sclp(A) ::= selcollist(X) COMMA. {A = X;}
%destructor db_name { }
sclp(A) ::= . {A = 0;}
db_name(A) ::= NK_ID(B). { A = B; }
selcollist(A) ::= sclp(P) distinct(Z) expr(X) as(Y). {
A = tSqlExprListAppend(P, X, Z.n? &Z:0, Y.n?&Y:0);
%type table_name { SToken }
}
%destructor table_name { }
table_name(A) ::= NK_ID(B). { A = B; }
selcollist(A) ::= sclp(P) STAR. {
tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL);
%type column_name { SToken }
A = tSqlExprListAppend(P, pNode, 0, 0);
%destructor column_name { }
}
column_name(A) ::= NK_ID(B). { A = B; }
// An option "AS <id>" phrase that can follow one of the expressions that
%type function_name { SToken }
// define the result set, or one of the tables in the FROM clause.
%destructor function_name { }
%type as {SToken}
function_name(A) ::= NK_ID(B). { A = B; }
as(X) ::= AS ids(Y). { X = Y; }
as(X) ::= ids(Y). { X = Y; }
%type table_alias { SToken }
as(X) ::= . { X.n = 0; }
%destructor table_alias { }
table_alias(A) ::= NK_ID(B). { A = B; }
%type distinct {SToken}
distinct(X) ::= DISTINCT(Y). { X = Y; }
%type column_alias { SToken }
distinct(X) ::= . { X.n = 0;}
%destructor column_alias { }
column_alias(A) ::= NK_ID(B). { A = B; }
// A complete FROM clause.
%type from {SRelationInfo*}
%type user_name { SToken }
%destructor from {destroyRelationInfo($$);}
%destructor user_name { }
from(A) ::= FROM tablelist(X). {A = X;}
user_name(A) ::= NK_ID(B). { A = B; }
from(A) ::= FROM sub(X). {A = X;}
/************************************************ expression **********************************************************/
%type sub {SRelationInfo*}
expression(A) ::= literal(B). { A = B; }
%destructor sub {destroyRelationInfo($$);}
//expression(A) ::= NK_QUESTION(B). { A = B; }
sub(A) ::= LP union(Y) RP. {A = addSubquery(NULL, Y, NULL);}
//expression(A) ::= pseudo_column(B). { A = B; }
sub(A) ::= LP union(Y) RP ids(Z). {A = addSubquery(NULL, Y, &Z);}
expression(A) ::= column_reference(B). { A = B; }
sub(A) ::= sub(X) COMMA LP union(Y) RP ids(Z).{A = addSubquery(X, Y, &Z);}
expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
expression(A) ::= function_name(B) NK_LP NK_STAR(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, createNodeList(pCxt, createColumnNode(pCxt, NULL, &C)))); }
%type tablelist {SRelationInfo*}
//expression(A) ::= cast_expression(B). { A = B; }
%destructor tablelist {destroyRelationInfo($$);}
//expression(A) ::= case_expression(B). { A = B; }
tablelist(A) ::= ids(X) cpxName(Y). {
expression(A) ::= subquery(B). { A = B; }
X.n += Y.n;
expression(A) ::= NK_LP(B) expression(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, releaseRawExprNode(pCxt, C)); }
A = setTableNameList(NULL, &X, NULL);
expression(A) ::= NK_PLUS(B) expression(C). {
}
SToken t = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &B, &t, releaseRawExprNode(pCxt, C));
tablelist(A) ::= ids(X) cpxName(Y) ids(Z). {
}
X.n += Y.n;
expression(A) ::= NK_MINUS(B) expression(C). {
A = setTableNameList(NULL, &X, &Z);
SToken t = getTokenFromRawExprNode(pCxt, C);
}
A = createRawExprNodeExt(pCxt, &B, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, C), NULL));
}
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z). {
expression(A) ::= expression(B) NK_PLUS expression(C). {
X.n += Z.n;
SToken s = getTokenFromRawExprNode(pCxt, B);
A = setTableNameList(Y, &X, NULL);
SToken e = getTokenFromRawExprNode(pCxt, C);
}
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
}
tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). {
expression(A) ::= expression(B) NK_MINUS expression(C). {
X.n += Z.n;
SToken s = getTokenFromRawExprNode(pCxt, B);
A = setTableNameList(Y, &X, &F);
SToken e = getTokenFromRawExprNode(pCxt, C);
}
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
}
// The value of interval should be the form of "number+[a,s,m,h,d,n,y]" or "now"
expression(A) ::= expression(B) NK_STAR expression(C). {
%type tmvar {SToken}
SToken s = getTokenFromRawExprNode(pCxt, B);
tmvar(A) ::= VARIABLE(X). {A = X;}
SToken e = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
%type interval_option {SIntervalVal}
}
interval_option(N) ::= intervalKey(A) LP tmvar(E) RP. {N.interval = E; N.offset.n = 0; N.token = A;}
expression(A) ::= expression(B) NK_SLASH expression(C). {
interval_option(N) ::= intervalKey(A) LP tmvar(E) COMMA tmvar(X) RP. {N.interval = E; N.offset = X; N.token = A;}
SToken s = getTokenFromRawExprNode(pCxt, B);
interval_option(N) ::= . {memset(&N, 0, sizeof(N));}
SToken e = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
%type intervalKey {int32_t}
}
intervalKey(A) ::= INTERVAL. {A = TK_INTERVAL;}
expression(A) ::= expression(B) NK_REM expression(C). {
intervalKey(A) ::= EVERY. {A = TK_EVERY; }
SToken s = getTokenFromRawExprNode(pCxt, B);
SToken e = getTokenFromRawExprNode(pCxt, C);
%type session_option {SSessionWindowVal}
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
session_option(X) ::= . {X.col.n = 0; X.gap.n = 0;}
}
session_option(X) ::= SESSION LP ids(V) cpxName(Z) COMMA tmvar(Y) RP. {
V.n += Z.n;
%type expression_list { SNodeList* }
X.col = V;
%destructor expression_list { nodesDestroyList($$); }
X.gap = Y;
expression_list(A) ::= expression(B). { A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); }
}
expression_list(A) ::= expression_list(B) NK_COMMA expression(C). { A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); }
%type windowstate_option {SWindowStateVal}
column_reference(A) ::= column_name(B). { A = createRawExprNode(pCxt, &B, createColumnNode(pCxt, NULL, &B)); }
windowstate_option(X) ::= . { X.col.n = 0; X.col.z = NULL;}
column_reference(A) ::= table_name(B) NK_DOT column_name(C). { A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); }
windowstate_option(X) ::= STATE_WINDOW LP ids(V) RP. { X.col = V; }
//pseudo_column(A) ::= NK_NOW. { A = createFunctionNode(pCxt, NULL, NULL); }
%type fill_opt {SArray*}
%destructor fill_opt {taosArrayDestroy($$);}
/************************************************ predicate ***********************************************************/
fill_opt(N) ::= . { N = 0; }
predicate(A) ::= expression(B) compare_op(C) expression(D). {
fill_opt(N) ::= FILL LP ID(Y) COMMA tagitemlist(X) RP. {
SToken s = getTokenFromRawExprNode(pCxt, B);
SVariant A = {0};
SToken e = getTokenFromRawExprNode(pCxt, D);
toTSDBType(Y.type);
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, C, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D)));
taosVariantCreate(&A, Y.z, Y.n, Y.type);
}
//predicate(A) ::= expression(B) compare_op sub_type expression(B).
tListItemInsert(X, &A, -1, 0);
predicate(A) ::= expression(B) BETWEEN expression(C) AND expression(D). {
N = X;
SToken s = getTokenFromRawExprNode(pCxt, B);
}
SToken e = getTokenFromRawExprNode(pCxt, D);
A = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, D)));
fill_opt(N) ::= FILL LP ID(Y) RP. {
}
toTSDBType(Y.type);
predicate(A) ::= expression(B) NOT BETWEEN expression(C) AND expression(D). {
N = tListItemAppendToken(NULL, &Y, -1);
SToken s = getTokenFromRawExprNode(pCxt, B);
}
SToken e = getTokenFromRawExprNode(pCxt, D);
A = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D)));
%type sliding_opt {SToken}
}
sliding_opt(K) ::= SLIDING LP tmvar(E) RP. {K = E; }
predicate(A) ::= expression(B) IS NULL(C). {
sliding_opt(K) ::= . {K.n = 0; K.z = NULL; K.type = 0; }
SToken s = getTokenFromRawExprNode(pCxt, B);
A = createRawExprNodeExt(pCxt, &s, &C, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, B), NULL));
%type orderby_opt {SArray*}
}
%destructor orderby_opt {taosArrayDestroy($$);}
predicate(A) ::= expression(B) IS NOT NULL(C). {
SToken s = getTokenFromRawExprNode(pCxt, B);
%type sortlist {SArray*}
A = createRawExprNodeExt(pCxt, &s, &C, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, B), NULL));
%destructor sortlist {taosArrayDestroy($$);}
}
predicate(A) ::= expression(B) in_op(C) in_predicate_value(D). {
%type sortitem {SVariant}
SToken s = getTokenFromRawExprNode(pCxt, B);
%destructor sortitem {taosVariantDestroy(&$$);}
SToken e = getTokenFromRawExprNode(pCxt, D);
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, C, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D)));
orderby_opt(A) ::= . {A = 0;}
}
orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
%type compare_op { EOperatorType }
sortlist(A) ::= sortlist(X) COMMA item(Y) sortorder(Z). {
%destructor compare_op { }
A = tListItemAppend(X, &Y, Z);
compare_op(A) ::= NK_LT. { A = OP_TYPE_LOWER_THAN; }
}
compare_op(A) ::= NK_GT. { A = OP_TYPE_GREATER_THAN; }
compare_op(A) ::= NK_LE. { A = OP_TYPE_LOWER_EQUAL; }
sortlist(A) ::= item(Y) sortorder(Z). {
compare_op(A) ::= NK_GE. { A = OP_TYPE_GREATER_EQUAL; }
A = tListItemAppend(NULL, &Y, Z);
compare_op(A) ::= NK_NE. { A = OP_TYPE_NOT_EQUAL; }
}
compare_op(A) ::= NK_EQ. { A = OP_TYPE_EQUAL; }
compare_op(A) ::= LIKE. { A = OP_TYPE_LIKE; }
%type item {SVariant}
compare_op(A) ::= NOT LIKE. { A = OP_TYPE_NOT_LIKE; }
item(A) ::= ids(X) cpxName(Y). {
compare_op(A) ::= MATCH. { A = OP_TYPE_MATCH; }
toTSDBType(X.type);
compare_op(A) ::= NMATCH. { A = OP_TYPE_NMATCH; }
X.n += Y.n;
%type in_op { EOperatorType }
taosVariantCreate(&A, X.z, X.n, X.type);
%destructor in_op { }
}
in_op(A) ::= IN. { A = OP_TYPE_IN; }
in_op(A) ::= NOT IN. { A = OP_TYPE_NOT_IN; }
%type sortorder {int}
sortorder(A) ::= ASC. { A = TSDB_ORDER_ASC; }
in_predicate_value(A) ::= NK_LP(C) expression_list(B) NK_RP(D). { A = createRawExprNodeExt(pCxt, &C, &D, createNodeListNode(pCxt, B)); }
sortorder(A) ::= DESC. { A = TSDB_ORDER_DESC;}
sortorder(A) ::= . { A = TSDB_ORDER_ASC; } // Ascending order by default
/************************************************ boolean_value_expression ********************************************/
boolean_value_expression(A) ::= boolean_primary(B). { A = B; }
//group by clause
boolean_value_expression(A) ::= NOT(C) boolean_primary(B). {
%type groupby_opt {SArray*}
SToken e = getTokenFromRawExprNode(pCxt, B);
%destructor groupby_opt {taosArrayDestroy($$);}
A = createRawExprNodeExt(pCxt, &C, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, B), NULL));
%type grouplist {SArray*}
}
%destructor grouplist {taosArrayDestroy($$);}
boolean_value_expression(A) ::=
boolean_value_expression(B) OR boolean_value_expression(C). {
groupby_opt(A) ::= . { A = 0;}
SToken s = getTokenFromRawExprNode(pCxt, B);
groupby_opt(A) ::= GROUP BY grouplist(X). { A = X;}
SToken e = getTokenFromRawExprNode(pCxt, C);
A = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
grouplist(A) ::= grouplist(X) COMMA item(Y). {
}
A = tListItemAppend(X, &Y, -1);
boolean_value_expression(A) ::=
}
boolean_value_expression(B) AND boolean_value_expression(C). {
SToken s = getTokenFromRawExprNode(pCxt, B);
grouplist(A) ::= item(X). {
SToken e = getTokenFromRawExprNode(pCxt, C);
A = tListItemAppend(NULL, &X, -1);
A = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
}
}
//having clause, ignore the input condition in having
boolean_primary(A) ::= predicate(B). { A = B; }
%type having_opt {tSqlExpr*}
boolean_primary(A) ::= NK_LP(C) boolean_value_expression(B) NK_RP(D). { A = createRawExprNodeExt(pCxt, &C, &D, releaseRawExprNode(pCxt, B)); }
%destructor having_opt {tSqlExprDestroy($$);}
having_opt(A) ::=. {A = 0;}
/************************************************ common_expression ********************************************/
having_opt(A) ::= HAVING expr(X). {A = X;}
common_expression(A) ::= expression(B). { A = B; }
common_expression(A) ::= boolean_value_expression(B). { A = B; }
//limit-offset subclause
%type limit_opt {SLimit}
/************************************************ from_clause *********************************************************/
limit_opt(A) ::= . {A.limit = -1; A.offset = 0;}
from_clause(A) ::= FROM table_reference_list(B). { A = B; }
limit_opt(A) ::= LIMIT signed(X). {A.limit = X; A.offset = 0;}
limit_opt(A) ::= LIMIT signed(X) OFFSET signed(Y).
table_reference_list(A) ::= table_reference(B). { A = B; }
{ A.limit = X; A.offset = Y;}
table_reference_list(A) ::= table_reference_list(B) NK_COMMA table_reference(C). { A = createJoinTableNode(pCxt, JOIN_TYPE_INNER, B, C, NULL); }
limit_opt(A) ::= LIMIT signed(X) COMMA signed(Y).
{ A.limit = Y; A.offset = X;}
/************************************************ table_reference *****************************************************/
table_reference(A) ::= table_primary(B). { A = B; }
%type slimit_opt {SLimit}
table_reference(A) ::= joined_table(B). { A = B; }
slimit_opt(A) ::= . {A.limit = -1; A.offset = 0;}
slimit_opt(A) ::= SLIMIT signed(X). {A.limit = X; A.offset = 0;}
table_primary(A) ::= table_name(B) alias_opt(C). { A = createRealTableNode(pCxt, NULL, &B, &C); }
slimit_opt(A) ::= SLIMIT signed(X) SOFFSET signed(Y).
table_primary(A) ::= db_name(B) NK_DOT table_name(C) alias_opt(D). { A = createRealTableNode(pCxt, &B, &C, &D); }
{A.limit = X; A.offset = Y;}
table_primary(A) ::= subquery(B) alias_opt(C). { A = createTempTableNode(pCxt, releaseRawExprNode(pCxt, B), &C); }
slimit_opt(A) ::= SLIMIT signed(X) COMMA signed(Y).
table_primary(A) ::= parenthesized_joined_table(B). { A = B; }
{A.limit = Y; A.offset = X;}
%type alias_opt { SToken }
%type where_opt {tSqlExpr*}
%destructor alias_opt { }
%destructor where_opt {tSqlExprDestroy($$);}
alias_opt(A) ::= . { A = nil_token; }
alias_opt(A) ::= table_alias(B). { A = B; }
where_opt(A) ::= . {A = 0;}
alias_opt(A) ::= AS table_alias(B). { A = B; }
where_opt(A) ::= WHERE expr(X). {A = X;}
parenthesized_joined_table(A) ::= NK_LP joined_table(B) NK_RP. { A = B; }
/////////////////////////// Expression Processing /////////////////////////////
parenthesized_joined_table(A) ::= NK_LP parenthesized_joined_table(B) NK_RP. { A = B; }
//
%type expr {tSqlExpr*}
/************************************************ joined_table ********************************************************/
%destructor expr {tSqlExprDestroy($$);}
joined_table(A) ::=
table_reference(B) join_type(C) JOIN table_reference(D) ON search_condition(E). { A = createJoinTableNode(pCxt, C, B, D, E); }
expr(A) ::= LP(X) expr(Y) RP(Z). {A = Y; A->exprToken.z = X.z; A->exprToken.n = (Z.z - X.z + 1);}
%type join_type { EJoinType }
expr(A) ::= ID(X). { A = tSqlExprCreateIdValue(&X, TK_ID);}
%destructor join_type { }
expr(A) ::= ID(X) DOT ID(Y). { X.n += (1+Y.n); A = tSqlExprCreateIdValue(&X, TK_ID);}
join_type(A) ::= . { A = JOIN_TYPE_INNER; }
expr(A) ::= ID(X) DOT STAR(Y). { X.n += (1+Y.n); A = tSqlExprCreateIdValue(&X, TK_ALL);}
join_type(A) ::= INNER. { A = JOIN_TYPE_INNER; }
expr(A) ::= INTEGER(X). { A = tSqlExprCreateIdValue(&X, TK_INTEGER);}
/************************************************ query_specification *************************************************/
expr(A) ::= MINUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateIdValue(&X, TK_INTEGER);}
query_specification(A) ::=
expr(A) ::= PLUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateIdValue(&X, TK_INTEGER);}
SELECT set_quantifier_opt(B) select_list(C) from_clause(D) where_clause_opt(E)
expr(A) ::= FLOAT(X). { A = tSqlExprCreateIdValue(&X, TK_FLOAT);}
partition_by_clause_opt(F) twindow_clause_opt(G)
expr(A) ::= MINUS(X) FLOAT(Y). { X.n += Y.n; X.type = TK_FLOAT; A = tSqlExprCreateIdValue(&X, TK_FLOAT);}
group_by_clause_opt(H) having_clause_opt(I). {
expr(A) ::= PLUS(X) FLOAT(Y). { X.n += Y.n; X.type = TK_FLOAT; A = tSqlExprCreateIdValue(&X, TK_FLOAT);}
A = createSelectStmt(pCxt, B, C, D);
expr(A) ::= STRING(X). { A = tSqlExprCreateIdValue(&X, TK_STRING);}
A = addWhereClause(pCxt, A, E);
expr(A) ::= NOW(X). { A = tSqlExprCreateIdValue(&X, TK_NOW); }
A = addPartitionByClause(pCxt, A, F);
expr(A) ::= VARIABLE(X). { A = tSqlExprCreateIdValue(&X, TK_VARIABLE);}
A = addWindowClauseClause(pCxt, A, G);
expr(A) ::= PLUS(X) VARIABLE(Y). { X.n += Y.n; X.type = TK_VARIABLE; A = tSqlExprCreateIdValue(&X, TK_VARIABLE);}
A = addGroupByClause(pCxt, A, H);
expr(A) ::= MINUS(X) VARIABLE(Y). { X.n += Y.n; X.type = TK_VARIABLE; A = tSqlExprCreateIdValue(&X, TK_VARIABLE);}
A = addHavingClause(pCxt, A, I);
expr(A) ::= BOOL(X). { A = tSqlExprCreateIdValue(&X, TK_BOOL);}
}
expr(A) ::= NULL(X). { A = tSqlExprCreateIdValue(&X, TK_NULL);}
%type set_quantifier_opt { bool }
// ordinary functions: min(x), max(x), top(k, 20)
%destructor set_quantifier_opt { }
expr(A) ::= ID(X) LP exprlist(Y) RP(E). { tRecordFuncName(pInfo->funcs, &X); A = tSqlExprCreateFunction(Y, &X, &E, X.type); }
set_quantifier_opt(A) ::= . { A = false; }
set_quantifier_opt(A) ::= DISTINCT. { A = true; }
// for parsing sql functions with wildcard for parameters. e.g., count(*)/first(*)/last(*) operation
set_quantifier_opt(A) ::= ALL. { A = false; }
expr(A) ::= ID(X) LP STAR RP(Y). { tRecordFuncName(pInfo->funcs, &X); A = tSqlExprCreateFunction(NULL, &X, &Y, X.type); }
%type select_list { SNodeList* }
// is (not) null expression
%destructor select_list { nodesDestroyList($$); }
expr(A) ::= expr(X) IS NULL. {A = tSqlExprCreate(X, NULL, TK_ISNULL);}
select_list(A) ::= NK_STAR. { A = NULL; }
expr(A) ::= expr(X) IS NOT NULL. {A = tSqlExprCreate(X, NULL, TK_NOTNULL);}
select_list(A) ::= select_sublist(B). { A = B; }
// relational expression
%type select_sublist { SNodeList* }
expr(A) ::= expr(X) LT expr(Y). {A = tSqlExprCreate(X, Y, TK_LT);}
%destructor select_sublist { nodesDestroyList($$); }
expr(A) ::= expr(X) GT expr(Y). {A = tSqlExprCreate(X, Y, TK_GT);}
select_sublist(A) ::= select_item(B). { A = createNodeList(pCxt, B); }
expr(A) ::= expr(X) LE expr(Y). {A = tSqlExprCreate(X, Y, TK_LE);}
select_sublist(A) ::= select_sublist(B) NK_COMMA select_item(C). { A = addNodeToList(pCxt, B, C); }
expr(A) ::= expr(X) GE expr(Y). {A = tSqlExprCreate(X, Y, TK_GE);}
expr(A) ::= expr(X) NE expr(Y). {A = tSqlExprCreate(X, Y, TK_NE);}
select_item(A) ::= common_expression(B). {
expr(A) ::= expr(X) EQ expr(Y). {A = tSqlExprCreate(X, Y, TK_EQ);}
SToken t = getTokenFromRawExprNode(pCxt, B);
A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &t);
expr(A) ::= expr(X) BETWEEN expr(Y) AND expr(Z). { tSqlExpr* X2 = tSqlExprClone(X); A = tSqlExprCreate(tSqlExprCreate(X, Y, TK_GE), tSqlExprCreate(X2, Z, TK_LE), TK_AND);}
}
select_item(A) ::= common_expression(B) column_alias(C). { A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &C); }
expr(A) ::= expr(X) AND expr(Y). {A = tSqlExprCreate(X, Y, TK_AND);}
select_item(A) ::= common_expression(B) AS column_alias(C). { A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &C); }
expr(A) ::= expr(X) OR expr(Y). {A = tSqlExprCreate(X, Y, TK_OR); }
select_item(A) ::= table_name(B) NK_DOT NK_STAR(C). { A = createColumnNode(pCxt, &B, &C); }
// binary arithmetic expression
where_clause_opt(A) ::= . { A = NULL; }
expr(A) ::= expr(X) PLUS expr(Y). {A = tSqlExprCreate(X, Y, TK_PLUS); }
where_clause_opt(A) ::= WHERE search_condition(B). { A = B; }
expr(A) ::= expr(X) MINUS expr(Y). {A = tSqlExprCreate(X, Y, TK_MINUS); }
expr(A) ::= expr(X) STAR expr(Y). {A = tSqlExprCreate(X, Y, TK_STAR); }
%type partition_by_clause_opt { SNodeList* }
expr(A) ::= expr(X) SLASH expr(Y). {A = tSqlExprCreate(X, Y, TK_DIVIDE);}
%destructor partition_by_clause_opt { nodesDestroyList($$); }
expr(A) ::= expr(X) REM expr(Y). {A = tSqlExprCreate(X, Y, TK_REM); }
partition_by_clause_opt(A) ::= . { A = NULL; }
partition_by_clause_opt(A) ::= PARTITION BY expression_list(B). { A = B; }
// like expression
expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); }
twindow_clause_opt(A) ::= . { A = NULL; }
twindow_clause_opt(A) ::=
// match expression
SESSION NK_LP column_reference(B) NK_COMMA NK_INTEGER(C) NK_RP. { A = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, B), &C); }
expr(A) ::= expr(X) MATCH expr(Y). {A = tSqlExprCreate(X, Y, TK_MATCH); }
twindow_clause_opt(A) ::= STATE_WINDOW NK_LP column_reference(B) NK_RP. { A = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, B)); }
expr(A) ::= expr(X) NMATCH expr(Y). {A = tSqlExprCreate(X, Y, TK_NMATCH); }
twindow_clause_opt(A) ::=
INTERVAL NK_LP duration_literal(B) NK_RP sliding_opt(C) fill_opt(D). { A = createIntervalWindowNode(pCxt, B, NULL, C, D); }
//in expression
twindow_clause_opt(A) ::=
expr(A) ::= expr(X) IN LP exprlist(Y) RP. {A = tSqlExprCreate(X, (tSqlExpr*)Y, TK_IN); }
INTERVAL NK_LP duration_literal(B) NK_COMMA duration_literal(C) NK_RP
sliding_opt(D) fill_opt(E). { A = createIntervalWindowNode(pCxt, B, C, D, E); }
%type exprlist {SArray*}
%destructor exprlist {tSqlExprListDestroy($$);}
sliding_opt(A) ::= . { A = NULL; }
sliding_opt(A) ::= SLIDING NK_LP duration_literal(B) NK_RP. { A = B; }
%type expritem {tSqlExpr*}
%destructor expritem {tSqlExprDestroy($$);}
fill_opt(A) ::= . { A = NULL; }
fill_opt(A) ::= FILL NK_LP fill_mode(B) NK_RP. { A = createFillNode(pCxt, B, NULL); }
exprlist(A) ::= exprlist(X) COMMA expritem(Y). {A = tSqlExprListAppend(X,Y,0, 0);}
fill_opt(A) ::= FILL NK_LP VALUE NK_COMMA literal_list(B) NK_RP. { A = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, B)); }
exprlist(A) ::= expritem(X). {A = tSqlExprListAppend(0,X,0, 0);}
expritem(A) ::= expr(X). {A = X;}
%type fill_mode { EFillMode }
expritem(A) ::= . {A = 0;}
%destructor fill_mode { }
fill_mode(A) ::= NONE. { A = FILL_MODE_NONE; }
///////////////////////////////////reset query cache//////////////////////////////////////
fill_mode(A) ::= PREV. { A = FILL_MODE_PREV; }
cmd ::= RESET QUERY CACHE. { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
fill_mode(A) ::= NULL. { A = FILL_MODE_NULL; }
fill_mode(A) ::= LINEAR. { A = FILL_MODE_LINEAR; }
///////////////////////////////////sync replica database//////////////////////////////////
fill_mode(A) ::= NEXT. { A = FILL_MODE_NEXT; }
cmd ::= SYNCDB ids(X) REPLICA.{ setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &X);}
%type group_by_clause_opt { SNodeList* }
///////////////////////////////////ALTER TABLE statement//////////////////////////////////
%destructor group_by_clause_opt { nodesDestroyList($$); }
cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
group_by_clause_opt(A) ::= . { A = NULL; }
X.n += F.n;
group_by_clause_opt(A) ::= GROUP BY group_by_list(B). { A = B; }
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
%type group_by_list { SNodeList* }
}
%destructor group_by_list { nodesDestroyList($$); }
group_by_list(A) ::= expression(B). { A = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, B))); }
cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
group_by_list(A) ::= group_by_list(B) NK_COMMA expression(C). { A = addNodeToList(pCxt, B, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, C))); }
X.n += F.n;
toTSDBType(A.type);
having_clause_opt(A) ::= . { A = NULL; }
SArray* K = tListItemAppendToken(NULL, &A, -1);
having_clause_opt(A) ::= HAVING search_condition(B). { A = B; }
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
/************************************************ query_expression ****************************************************/
}
query_expression(A) ::=
query_expression_body(B)
cmd ::= ALTER TABLE ids(X) cpxName(F) MODIFY COLUMN columnlist(A). {
order_by_clause_opt(C) slimit_clause_opt(D) limit_clause_opt(E). {
X.n += F.n;
A = addOrderByClause(pCxt, B, C);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, -1);
A = addSlimitClause(pCxt, A, D);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
A = addLimitClause(pCxt, A, E);
}
}
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
query_expression_body(A) ::= query_primary(B). { A = B; }
cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
query_expression_body(A) ::=
X.n += Y.n;
query_expression_body(B) UNION ALL query_expression_body(D). { A = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, B, D); }
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
query_primary(A) ::= query_specification(B). { A = B; }
}
//query_primary(A) ::=
cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
// NK_LP query_expression_body(B)
X.n += Z.n;
// order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP. { A = B;}
toTSDBType(Y.type);
%type order_by_clause_opt { SNodeList* }
SArray* A = tListItemAppendToken(NULL, &Y, -1);
%destructor order_by_clause_opt { nodesDestroyList($$); }
order_by_clause_opt(A) ::= . { A = NULL; }
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG, -1);
order_by_clause_opt(A) ::= ORDER BY sort_specification_list(B). { A = B; }
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
slimit_clause_opt(A) ::= . { A = NULL; }
slimit_clause_opt(A) ::= SLIMIT NK_INTEGER(B). { A = createLimitNode(pCxt, &B, NULL); }
cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
slimit_clause_opt(A) ::= SLIMIT NK_INTEGER(B) SOFFSET NK_INTEGER(C). { A = createLimitNode(pCxt, &B, &C); }
X.n += F.n;
slimit_clause_opt(A) ::= SLIMIT NK_INTEGER(C) NK_COMMA NK_INTEGER(B). { A = createLimitNode(pCxt, &B, &C); }
toTSDBType(Y.type);
limit_clause_opt(A) ::= . { A = NULL; }
SArray* A = tListItemAppendToken(NULL, &Y, -1);
limit_clause_opt(A) ::= LIMIT NK_INTEGER(B). { A = createLimitNode(pCxt, &B, NULL); }
limit_clause_opt(A) ::= LIMIT NK_INTEGER(B) OFFSET NK_INTEGER(C). { A = createLimitNode(pCxt, &B, &C); }
toTSDBType(Z.type);
limit_clause_opt(A) ::= LIMIT NK_INTEGER(C) NK_COMMA NK_INTEGER(B). { A = createLimitNode(pCxt, &B, &C); }
A = tListItemAppendToken(A, &Z, -1);
/************************************************ subquery ************************************************************/
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, -1);
subquery(A) ::= NK_LP(B) query_expression(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, C); }
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
/************************************************ search_condition ****************************************************/
search_condition(A) ::= common_expression(B). { A = releaseRawExprNode(pCxt, B); }
cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
X.n += F.n;
/************************************************ sort_specification_list *********************************************/
%type sort_specification_list { SNodeList* }
toTSDBType(Y.type);
%destructor sort_specification_list { nodesDestroyList($$); }
SArray* A = tListItemAppendToken(NULL, &Y, -1);
sort_specification_list(A) ::= sort_specification(B). { A = createNodeList(pCxt, B); }
A = tListItemAppend(A, &Z, -1);
sort_specification_list(A) ::=
sort_specification_list(B) NK_COMMA sort_specification(C). { A = addNodeToList(pCxt, B, C); }
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
sort_specification(A) ::=
}
expression(B) ordering_specification_opt(C) null_ordering_opt(D). { A = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, B), C, D); }
cmd ::= ALTER TABLE ids(X) cpxName(F) MODIFY TAG columnlist(A). {
%type ordering_specification_opt EOrder
X.n += F.n;
%destructor ordering_specification_opt { }
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, -1);
ordering_specification_opt(A) ::= . { A = ORDER_ASC; }
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
ordering_specification_opt(A) ::= ASC. { A = ORDER_ASC; }
}
ordering_specification_opt(A) ::= DESC. { A = ORDER_DESC; }
///////////////////////////////////ALTER STABLE statement//////////////////////////////////
%type null_ordering_opt ENullOrder
cmd ::= ALTER STABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
%destructor null_ordering_opt { }
X.n += F.n;
null_ordering_opt(A) ::= . { A = NULL_ORDER_DEFAULT; }
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE);
null_ordering_opt(A) ::= NULLS FIRST. { A = NULL_ORDER_FIRST; }
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
null_ordering_opt(A) ::= NULLS LAST. { A = NULL_ORDER_LAST; }
}
cmd ::= ALTER STABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
X.n += F.n;
toTSDBType(A.type);
SArray* K = tListItemAppendToken(NULL, &A, -1);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(F) MODIFY COLUMN columnlist(A). {
X.n += F.n;
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, 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;
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG, 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;
toTSDBType(Y.type);
SArray* A = tListItemAppendToken(NULL, &Y, -1);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG, TSDB_SUPER_TABLE);
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;
toTSDBType(Y.type);
SArray* A = tListItemAppendToken(NULL, &Y, -1);
toTSDBType(Z.type);
A = tListItemAppendToken(A, &Z, -1);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, TSDB_SUPER_TABLE);
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;
toTSDBType(Y.type);
SArray* A = tListItemAppendToken(NULL, &Y, -1);
A = tListItemAppend(A, &Z, -1);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(F) MODIFY TAG columnlist(A). {
X.n += F.n;
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
////////////////////////////////////////kill statement///////////////////////////////////////
cmd ::= KILL CONNECTION INTEGER(Y). {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &Y);}
cmd ::= KILL STREAM INTEGER(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); setKillSql(pInfo, TSDB_SQL_KILL_STREAM, &X);}
cmd ::= KILL QUERY INTEGER(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); setKillSql(pInfo, TSDB_SQL_KILL_QUERY, &X);}
%fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED
DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD
LIKE MATCH NMATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL
NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT TBNAME JOIN STABLE NULL INSERT INTO VALUES.
source/libs/parser/src/
astCreateFuncs
.c
→
source/libs/parser/src/
parAstCreater
.c
浏览文件 @
5b5ac34d
...
@@ -14,8 +14,8 @@
...
@@ -14,8 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "
astCreateFuncs
.h"
#include "
parAst
.h"
#include "par
ser
Util.h"
#include "parUtil.h"
#define CHECK_OUT_OF_MEM(p) \
#define CHECK_OUT_OF_MEM(p) \
do { \
do { \
...
...
source/libs/parser/src/
astParse
.c
→
source/libs/parser/src/
parAstParser
.c
浏览文件 @
5b5ac34d
...
@@ -13,28 +13,28 @@
...
@@ -13,28 +13,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "par
ser
Int.h"
#include "parInt.h"
#include "
astCreateFuncs
.h"
#include "
parAst
.h"
#include "
tt
oken.h"
#include "
parT
oken.h"
typedef
void
*
(
*
FMalloc
)(
size_t
);
typedef
void
*
(
*
FMalloc
)(
size_t
);
typedef
void
(
*
FFree
)(
void
*
);
typedef
void
(
*
FFree
)(
void
*
);
extern
void
*
New
ParseAlloc
(
FMalloc
);
extern
void
*
ParseAlloc
(
FMalloc
);
extern
void
New
Parse
(
void
*
,
int
,
SToken
,
void
*
);
extern
void
Parse
(
void
*
,
int
,
SToken
,
void
*
);
extern
void
New
ParseFree
(
void
*
,
FFree
);
extern
void
ParseFree
(
void
*
,
FFree
);
extern
void
New
ParseTrace
(
FILE
*
,
char
*
);
extern
void
ParseTrace
(
FILE
*
,
char
*
);
int32_t
doParse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
)
{
int32_t
doParse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
)
{
SAstCreateContext
cxt
;
SAstCreateContext
cxt
;
initAstCreateContext
(
pParseCxt
,
&
cxt
);
initAstCreateContext
(
pParseCxt
,
&
cxt
);
void
*
pParser
=
New
ParseAlloc
(
malloc
);
void
*
pParser
=
ParseAlloc
(
malloc
);
int32_t
i
=
0
;
int32_t
i
=
0
;
while
(
1
)
{
while
(
1
)
{
SToken
t0
=
{
0
};
SToken
t0
=
{
0
};
if
(
cxt
.
pQueryCxt
->
pSql
[
i
]
==
0
)
{
if
(
cxt
.
pQueryCxt
->
pSql
[
i
]
==
0
)
{
New
Parse
(
pParser
,
0
,
t0
,
&
cxt
);
Parse
(
pParser
,
0
,
t0
,
&
cxt
);
goto
abort_parse
;
goto
abort_parse
;
}
}
t0
.
n
=
tGetToken
((
char
*
)
&
cxt
.
pQueryCxt
->
pSql
[
i
],
&
t0
.
type
);
t0
.
n
=
tGetToken
((
char
*
)
&
cxt
.
pQueryCxt
->
pSql
[
i
],
&
t0
.
type
);
...
@@ -47,7 +47,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
...
@@ -47,7 +47,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
break
;
break
;
}
}
case
TK_NK_SEMI
:
{
case
TK_NK_SEMI
:
{
New
Parse
(
pParser
,
0
,
t0
,
&
cxt
);
Parse
(
pParser
,
0
,
t0
,
&
cxt
);
goto
abort_parse
;
goto
abort_parse
;
}
}
case
TK_NK_QUESTION
:
case
TK_NK_QUESTION
:
...
@@ -64,8 +64,8 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
...
@@ -64,8 +64,8 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
goto
abort_parse
;
goto
abort_parse
;
}
}
default:
default:
New
Parse
(
pParser
,
t0
.
type
,
t0
,
&
cxt
);
Parse
(
pParser
,
t0
.
type
,
t0
,
&
cxt
);
//
New
ParseTrace(stdout, "");
// ParseTrace(stdout, "");
if
(
!
cxt
.
valid
)
{
if
(
!
cxt
.
valid
)
{
goto
abort_parse
;
goto
abort_parse
;
}
}
...
@@ -73,7 +73,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
...
@@ -73,7 +73,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
}
}
abort_parse:
abort_parse:
New
ParseFree
(
pParser
,
free
);
ParseFree
(
pParser
,
free
);
if
(
cxt
.
valid
)
{
if
(
cxt
.
valid
)
{
*
pQuery
=
calloc
(
1
,
sizeof
(
SQuery
));
*
pQuery
=
calloc
(
1
,
sizeof
(
SQuery
));
if
(
NULL
==
*
pQuery
)
{
if
(
NULL
==
*
pQuery
)
{
...
...
source/libs/parser/src/
insertParser
.c
→
source/libs/parser/src/
parInsert
.c
浏览文件 @
5b5ac34d
...
@@ -13,13 +13,12 @@
...
@@ -13,13 +13,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "
insertParser
.h"
#include "
parInsertData
.h"
#include "parInt.h"
#include "
dataBlockMgt
.h"
#include "
parUtil
.h"
#include "par
serUtil
.h"
#include "par
Token
.h"
#include "tglobal.h"
#include "tglobal.h"
#include "ttime.h"
#include "ttime.h"
#include "ttoken.h"
#include "ttypes.h"
#include "ttypes.h"
#define NEXT_TOKEN(pSql, sToken) \
#define NEXT_TOKEN(pSql, sToken) \
...
...
source/libs/parser/src/
dataBlockMgt
.c
→
source/libs/parser/src/
parInsertData
.c
浏览文件 @
5b5ac34d
...
@@ -13,10 +13,10 @@
...
@@ -13,10 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "
dataBlockMgt
.h"
#include "
parInsertData
.h"
#include "catalog.h"
#include "catalog.h"
#include "par
ser
Util.h"
#include "parUtil.h"
#include "querynodes.h"
#include "querynodes.h"
#define IS_RAW_PAYLOAD(t) \
#define IS_RAW_PAYLOAD(t) \
...
...
source/libs/parser/src/
tt
okenizer.c
→
source/libs/parser/src/
parT
okenizer.c
浏览文件 @
5b5ac34d
...
@@ -14,10 +14,9 @@
...
@@ -14,10 +14,9 @@
*/
*/
#include "os.h"
#include "os.h"
#include "parToken.h"
#include "thash.h"
#include "thash.h"
#include "taosdef.h"
#include "taosdef.h"
#include "ttoken.h"
#include "ttokendef.h"
#include "ttokendef.h"
// All the keywords of the SQL language are stored in a hash table
// All the keywords of the SQL language are stored in a hash table
...
...
source/libs/parser/src/
astTranslate
.c
→
source/libs/parser/src/
parTranslater
.c
浏览文件 @
5b5ac34d
...
@@ -13,12 +13,12 @@
...
@@ -13,12 +13,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "par
ser
Int.h"
#include "parInt.h"
#include "catalog.h"
#include "catalog.h"
#include "cmdnodes.h"
#include "cmdnodes.h"
#include "functionMgt.h"
#include "functionMgt.h"
#include "par
ser
Util.h"
#include "parUtil.h"
#include "ttime.h"
#include "ttime.h"
static
bool
afterGroupBy
(
ESqlClause
clause
)
{
static
bool
afterGroupBy
(
ESqlClause
clause
)
{
...
...
source/libs/parser/src/par
ser
Util.c
→
source/libs/parser/src/parUtil.c
浏览文件 @
5b5ac34d
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "par
ser
Util.h"
#include "parUtil.h"
static
char
*
getSyntaxErrFormat
(
int32_t
errCode
)
{
static
char
*
getSyntaxErrFormat
(
int32_t
errCode
)
{
switch
(
errCode
)
{
switch
(
errCode
)
{
...
...
source/libs/parser/src/parser.c
浏览文件 @
5b5ac34d
...
@@ -15,9 +15,8 @@
...
@@ -15,9 +15,8 @@
#include "parser.h"
#include "parser.h"
#include "insertParser.h"
#include "parInt.h"
#include "parserInt.h"
#include "parToken.h"
#include "ttoken.h"
static
bool
isInsertSql
(
const
char
*
pStr
,
size_t
length
)
{
static
bool
isInsertSql
(
const
char
*
pStr
,
size_t
length
)
{
int32_t
index
=
0
;
int32_t
index
=
0
;
...
@@ -47,5 +46,14 @@ int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery) {
...
@@ -47,5 +46,14 @@ int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery) {
}
}
void
qDestroyQuery
(
SQuery
*
pQueryNode
)
{
void
qDestroyQuery
(
SQuery
*
pQueryNode
)
{
// todo
if
(
NULL
==
pQueryNode
)
{
return
;
}
nodesDestroyNode
(
pQueryNode
->
pRoot
);
tfree
(
pQueryNode
->
pResSchema
);
if
(
NULL
!=
pQueryNode
->
pCmdMsg
)
{
tfree
(
pQueryNode
->
pCmdMsg
->
pMsg
);
tfree
(
pQueryNode
->
pCmdMsg
);
}
tfree
(
pQueryNode
);
}
}
source/libs/parser/src/
new_
sql.c
→
source/libs/parser/src/sql.c
浏览文件 @
5b5ac34d
...
@@ -33,9 +33,9 @@
...
@@ -33,9 +33,9 @@
#include <stdbool.h>
#include <stdbool.h>
#include "nodes.h"
#include "nodes.h"
#include "
tt
oken.h"
#include "
parT
oken.h"
#include "ttokendef.h"
#include "ttokendef.h"
#include "
astCreateFuncs
.h"
#include "
parAst
.h"
/**************** End of %include directives **********************************/
/**************** End of %include directives **********************************/
/* These constants specify the various numeric values for terminal symbols
/* These constants specify the various numeric values for terminal symbols
** in a format understandable to "makeheaders". This section is blank unless
** in a format understandable to "makeheaders". This section is blank unless
...
@@ -59,7 +59,7 @@
...
@@ -59,7 +59,7 @@
** YYACTIONTYPE is the data type used for "action codes" - numbers
** YYACTIONTYPE is the data type used for "action codes" - numbers
** that indicate what to do in response to the next
** that indicate what to do in response to the next
** token.
** token.
**
New
ParseTOKENTYPE is the data type used for minor type for terminal
** ParseTOKENTYPE is the data type used for minor type for terminal
** symbols. Background: A "minor type" is a semantic
** symbols. Background: A "minor type" is a semantic
** value associated with a terminal or non-terminal
** value associated with a terminal or non-terminal
** symbols. For example, for an "ID" terminal symbol,
** symbols. For example, for an "ID" terminal symbol,
...
@@ -70,16 +70,16 @@
...
@@ -70,16 +70,16 @@
** symbols.
** symbols.
** YYMINORTYPE is the data type used for all minor types.
** YYMINORTYPE is the data type used for all minor types.
** This is typically a union of many types, one of
** This is typically a union of many types, one of
** which is
New
ParseTOKENTYPE. The entry in the union
** which is ParseTOKENTYPE. The entry in the union
** for terminal symbols is called "yy0".
** for terminal symbols is called "yy0".
** YYSTACKDEPTH is the maximum depth of the parser's stack. If
** YYSTACKDEPTH is the maximum depth of the parser's stack. If
** zero the stack is dynamically sized using realloc()
** zero the stack is dynamically sized using realloc()
**
New
ParseARG_SDECL A static variable declaration for the %extra_argument
** ParseARG_SDECL A static variable declaration for the %extra_argument
**
New
ParseARG_PDECL A parameter declaration for the %extra_argument
** ParseARG_PDECL A parameter declaration for the %extra_argument
**
New
ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter
** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter
**
New
ParseARG_STORE Code to store %extra_argument into yypParser
** ParseARG_STORE Code to store %extra_argument into yypParser
**
New
ParseARG_FETCH Code to extract %extra_argument from yypParser
** ParseARG_FETCH Code to extract %extra_argument from yypParser
**
NewParseCTX_* As New
ParseARG_ except for %extra_context
**
ParseCTX_* As
ParseARG_ except for %extra_context
** YYERRORSYMBOL is the code number of the error symbol. If not
** YYERRORSYMBOL is the code number of the error symbol. If not
** defined, then do no error processing.
** defined, then do no error processing.
** YYNSTATE the combined number of states.
** YYNSTATE the combined number of states.
...
@@ -101,10 +101,10 @@
...
@@ -101,10 +101,10 @@
#define YYCODETYPE unsigned char
#define YYCODETYPE unsigned char
#define YYNOCODE 208
#define YYNOCODE 208
#define YYACTIONTYPE unsigned short int
#define YYACTIONTYPE unsigned short int
#define
New
ParseTOKENTYPE SToken
#define ParseTOKENTYPE SToken
typedef
union
{
typedef
union
{
int
yyinit
;
int
yyinit
;
New
ParseTOKENTYPE
yy0
;
ParseTOKENTYPE
yy0
;
ENullOrder
yy9
;
ENullOrder
yy9
;
SDatabaseOptions
*
yy103
;
SDatabaseOptions
*
yy103
;
SToken
yy161
;
SToken
yy161
;
...
@@ -121,16 +121,16 @@ typedef union {
...
@@ -121,16 +121,16 @@ typedef union {
#ifndef YYSTACKDEPTH
#ifndef YYSTACKDEPTH
#define YYSTACKDEPTH 100
#define YYSTACKDEPTH 100
#endif
#endif
#define
New
ParseARG_SDECL SAstCreateContext* pCxt ;
#define ParseARG_SDECL SAstCreateContext* pCxt ;
#define
New
ParseARG_PDECL , SAstCreateContext* pCxt
#define ParseARG_PDECL , SAstCreateContext* pCxt
#define
New
ParseARG_PARAM ,pCxt
#define ParseARG_PARAM ,pCxt
#define
New
ParseARG_FETCH SAstCreateContext* pCxt =yypParser->pCxt ;
#define ParseARG_FETCH SAstCreateContext* pCxt =yypParser->pCxt ;
#define
New
ParseARG_STORE yypParser->pCxt =pCxt ;
#define ParseARG_STORE yypParser->pCxt =pCxt ;
#define
New
ParseCTX_SDECL
#define ParseCTX_SDECL
#define
New
ParseCTX_PDECL
#define ParseCTX_PDECL
#define
New
ParseCTX_PARAM
#define ParseCTX_PARAM
#define
New
ParseCTX_FETCH
#define ParseCTX_FETCH
#define
New
ParseCTX_STORE
#define ParseCTX_STORE
#define YYNSTATE 278
#define YYNSTATE 278
#define YYNRULE 236
#define YYNRULE 236
#define YYNTOKEN 134
#define YYNTOKEN 134
...
@@ -544,8 +544,8 @@ struct yyParser {
...
@@ -544,8 +544,8 @@ struct yyParser {
#ifndef YYNOERRORRECOVERY
#ifndef YYNOERRORRECOVERY
int
yyerrcnt
;
/* Shifts left before out of the error */
int
yyerrcnt
;
/* Shifts left before out of the error */
#endif
#endif
New
ParseARG_SDECL
/* A place to hold %extra_argument */
ParseARG_SDECL
/* A place to hold %extra_argument */
New
ParseCTX_SDECL
/* A place to hold %extra_context */
ParseCTX_SDECL
/* A place to hold %extra_context */
#if YYSTACKDEPTH<=0
#if YYSTACKDEPTH<=0
int
yystksz
;
/* Current side of the stack */
int
yystksz
;
/* Current side of the stack */
yyStackEntry
*
yystack
;
/* The parser's stack */
yyStackEntry
*
yystack
;
/* The parser's stack */
...
@@ -581,7 +581,7 @@ static char *yyTracePrompt = 0;
...
@@ -581,7 +581,7 @@ static char *yyTracePrompt = 0;
** Outputs:
** Outputs:
** None.
** None.
*/
*/
void
New
ParseTrace
(
FILE
*
TraceFILE
,
char
*
zTracePrompt
){
void
ParseTrace
(
FILE
*
TraceFILE
,
char
*
zTracePrompt
){
yyTraceFILE
=
TraceFILE
;
yyTraceFILE
=
TraceFILE
;
yyTracePrompt
=
zTracePrompt
;
yyTracePrompt
=
zTracePrompt
;
if
(
yyTraceFILE
==
0
)
yyTracePrompt
=
0
;
if
(
yyTraceFILE
==
0
)
yyTracePrompt
=
0
;
...
@@ -1082,7 +1082,7 @@ static int yyGrowStack(yyParser *p){
...
@@ -1082,7 +1082,7 @@ static int yyGrowStack(yyParser *p){
#endif
#endif
/* Datatype of the argument to the memory allocated passed as the
/* Datatype of the argument to the memory allocated passed as the
** second argument to
New
ParseAlloc() below. This can be changed by
** second argument to ParseAlloc() below. This can be changed by
** putting an appropriate #define in the %include section of the input
** putting an appropriate #define in the %include section of the input
** grammar.
** grammar.
*/
*/
...
@@ -1092,9 +1092,9 @@ static int yyGrowStack(yyParser *p){
...
@@ -1092,9 +1092,9 @@ static int yyGrowStack(yyParser *p){
/* Initialize a new parser that has already been allocated.
/* Initialize a new parser that has already been allocated.
*/
*/
void
NewParseInit
(
void
*
yypRawParser
New
ParseCTX_PDECL
){
void
ParseInit
(
void
*
yypRawParser
ParseCTX_PDECL
){
yyParser
*
yypParser
=
(
yyParser
*
)
yypRawParser
;
yyParser
*
yypParser
=
(
yyParser
*
)
yypRawParser
;
New
ParseCTX_STORE
ParseCTX_STORE
#ifdef YYTRACKMAXSTACKDEPTH
#ifdef YYTRACKMAXSTACKDEPTH
yypParser
->
yyhwm
=
0
;
yypParser
->
yyhwm
=
0
;
#endif
#endif
...
@@ -1118,7 +1118,7 @@ void NewParseInit(void *yypRawParser NewParseCTX_PDECL){
...
@@ -1118,7 +1118,7 @@ void NewParseInit(void *yypRawParser NewParseCTX_PDECL){
#endif
#endif
}
}
#ifndef
New
Parse_ENGINEALWAYSONSTACK
#ifndef Parse_ENGINEALWAYSONSTACK
/*
/*
** This function allocates a new parser.
** This function allocates a new parser.
** The only argument is a pointer to a function which works like
** The only argument is a pointer to a function which works like
...
@@ -1129,18 +1129,18 @@ void NewParseInit(void *yypRawParser NewParseCTX_PDECL){
...
@@ -1129,18 +1129,18 @@ void NewParseInit(void *yypRawParser NewParseCTX_PDECL){
**
**
** Outputs:
** Outputs:
** A pointer to a parser. This pointer is used in subsequent calls
** A pointer to a parser. This pointer is used in subsequent calls
** to
NewParse and New
ParseFree.
** to
Parse and
ParseFree.
*/
*/
void
*
NewParseAlloc
(
void
*
(
*
mallocProc
)(
YYMALLOCARGTYPE
)
New
ParseCTX_PDECL
){
void
*
ParseAlloc
(
void
*
(
*
mallocProc
)(
YYMALLOCARGTYPE
)
ParseCTX_PDECL
){
yyParser
*
yypParser
;
yyParser
*
yypParser
;
yypParser
=
(
yyParser
*
)(
*
mallocProc
)(
(
YYMALLOCARGTYPE
)
sizeof
(
yyParser
)
);
yypParser
=
(
yyParser
*
)(
*
mallocProc
)(
(
YYMALLOCARGTYPE
)
sizeof
(
yyParser
)
);
if
(
yypParser
){
if
(
yypParser
){
New
ParseCTX_STORE
ParseCTX_STORE
NewParseInit
(
yypParser
New
ParseCTX_PARAM
);
ParseInit
(
yypParser
ParseCTX_PARAM
);
}
}
return
(
void
*
)
yypParser
;
return
(
void
*
)
yypParser
;
}
}
#endif
/*
New
Parse_ENGINEALWAYSONSTACK */
#endif
/* Parse_ENGINEALWAYSONSTACK */
/* The following function deletes the "minor type" or semantic value
/* The following function deletes the "minor type" or semantic value
...
@@ -1155,8 +1155,8 @@ static void yy_destructor(
...
@@ -1155,8 +1155,8 @@ static void yy_destructor(
YYCODETYPE
yymajor
,
/* Type code for object to destroy */
YYCODETYPE
yymajor
,
/* Type code for object to destroy */
YYMINORTYPE
*
yypminor
/* The object to be destroyed */
YYMINORTYPE
*
yypminor
/* The object to be destroyed */
){
){
New
ParseARG_FETCH
ParseARG_FETCH
New
ParseCTX_FETCH
ParseCTX_FETCH
switch
(
yymajor
){
switch
(
yymajor
){
/* Here is inserted the actions which take place when a
/* Here is inserted the actions which take place when a
** terminal or non-terminal is destroyed. This can happen
** terminal or non-terminal is destroyed. This can happen
...
@@ -1321,7 +1321,7 @@ static void yy_pop_parser_stack(yyParser *pParser){
...
@@ -1321,7 +1321,7 @@ static void yy_pop_parser_stack(yyParser *pParser){
/*
/*
** Clear all secondary memory allocations from the parser
** Clear all secondary memory allocations from the parser
*/
*/
void
New
ParseFinalize
(
void
*
p
){
void
ParseFinalize
(
void
*
p
){
yyParser
*
pParser
=
(
yyParser
*
)
p
;
yyParser
*
pParser
=
(
yyParser
*
)
p
;
while
(
pParser
->
yytos
>
pParser
->
yystack
)
yy_pop_parser_stack
(
pParser
);
while
(
pParser
->
yytos
>
pParser
->
yystack
)
yy_pop_parser_stack
(
pParser
);
#if YYSTACKDEPTH<=0
#if YYSTACKDEPTH<=0
...
@@ -1329,7 +1329,7 @@ void NewParseFinalize(void *p){
...
@@ -1329,7 +1329,7 @@ void NewParseFinalize(void *p){
#endif
#endif
}
}
#ifndef
New
Parse_ENGINEALWAYSONSTACK
#ifndef Parse_ENGINEALWAYSONSTACK
/*
/*
** Deallocate and destroy a parser. Destructors are called for
** Deallocate and destroy a parser. Destructors are called for
** all stack elements before shutting the parser down.
** all stack elements before shutting the parser down.
...
@@ -1338,23 +1338,23 @@ void NewParseFinalize(void *p){
...
@@ -1338,23 +1338,23 @@ void NewParseFinalize(void *p){
** is defined in a %include section of the input grammar) then it is
** is defined in a %include section of the input grammar) then it is
** assumed that the input pointer is never NULL.
** assumed that the input pointer is never NULL.
*/
*/
void
New
ParseFree
(
void
ParseFree
(
void
*
p
,
/* The parser to be deleted */
void
*
p
,
/* The parser to be deleted */
void
(
*
freeProc
)(
void
*
)
/* Function used to reclaim memory */
void
(
*
freeProc
)(
void
*
)
/* Function used to reclaim memory */
){
){
#ifndef YYPARSEFREENEVERNULL
#ifndef YYPARSEFREENEVERNULL
if
(
p
==
0
)
return
;
if
(
p
==
0
)
return
;
#endif
#endif
New
ParseFinalize
(
p
);
ParseFinalize
(
p
);
(
*
freeProc
)(
p
);
(
*
freeProc
)(
p
);
}
}
#endif
/*
New
Parse_ENGINEALWAYSONSTACK */
#endif
/* Parse_ENGINEALWAYSONSTACK */
/*
/*
** Return the peak depth of the stack for a parser.
** Return the peak depth of the stack for a parser.
*/
*/
#ifdef YYTRACKMAXSTACKDEPTH
#ifdef YYTRACKMAXSTACKDEPTH
int
New
ParseStackPeak
(
void
*
p
){
int
ParseStackPeak
(
void
*
p
){
yyParser
*
pParser
=
(
yyParser
*
)
p
;
yyParser
*
pParser
=
(
yyParser
*
)
p
;
return
pParser
->
yyhwm
;
return
pParser
->
yyhwm
;
}
}
...
@@ -1378,7 +1378,7 @@ static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
...
@@ -1378,7 +1378,7 @@ static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
** Return the number of missed state/lookahead combinations.
** Return the number of missed state/lookahead combinations.
*/
*/
#if defined(YYCOVERAGE)
#if defined(YYCOVERAGE)
int
New
ParseCoverage
(
FILE
*
out
){
int
ParseCoverage
(
FILE
*
out
){
int
stateno
,
iLookAhead
,
i
;
int
stateno
,
iLookAhead
,
i
;
int
nMissed
=
0
;
int
nMissed
=
0
;
for
(
stateno
=
0
;
stateno
<
YYNSTATE
;
stateno
++
){
for
(
stateno
=
0
;
stateno
<
YYNSTATE
;
stateno
++
){
...
@@ -1500,8 +1500,8 @@ static YYACTIONTYPE yy_find_reduce_action(
...
@@ -1500,8 +1500,8 @@ static YYACTIONTYPE yy_find_reduce_action(
** The following routine is called if the stack overflows.
** The following routine is called if the stack overflows.
*/
*/
static
void
yyStackOverflow
(
yyParser
*
yypParser
){
static
void
yyStackOverflow
(
yyParser
*
yypParser
){
New
ParseARG_FETCH
ParseARG_FETCH
New
ParseCTX_FETCH
ParseCTX_FETCH
#ifndef NDEBUG
#ifndef NDEBUG
if
(
yyTraceFILE
){
if
(
yyTraceFILE
){
fprintf
(
yyTraceFILE
,
"%sStack Overflow!
\n
"
,
yyTracePrompt
);
fprintf
(
yyTraceFILE
,
"%sStack Overflow!
\n
"
,
yyTracePrompt
);
...
@@ -1512,8 +1512,8 @@ static void yyStackOverflow(yyParser *yypParser){
...
@@ -1512,8 +1512,8 @@ static void yyStackOverflow(yyParser *yypParser){
** stack every overflows */
** stack every overflows */
/******** Begin %stack_overflow code ******************************************/
/******** Begin %stack_overflow code ******************************************/
/******** End %stack_overflow code ********************************************/
/******** End %stack_overflow code ********************************************/
New
ParseARG_STORE
/* Suppress warning about unused %extra_argument var */
ParseARG_STORE
/* Suppress warning about unused %extra_argument var */
New
ParseCTX_STORE
ParseCTX_STORE
}
}
/*
/*
...
@@ -1544,7 +1544,7 @@ static void yy_shift(
...
@@ -1544,7 +1544,7 @@ static void yy_shift(
yyParser
*
yypParser
,
/* The parser to be shifted */
yyParser
*
yypParser
,
/* The parser to be shifted */
YYACTIONTYPE
yyNewState
,
/* The new state to shift in */
YYACTIONTYPE
yyNewState
,
/* The new state to shift in */
YYCODETYPE
yyMajor
,
/* The major token to shift in */
YYCODETYPE
yyMajor
,
/* The major token to shift in */
New
ParseTOKENTYPE
yyMinor
/* The minor token to shift in */
ParseTOKENTYPE
yyMinor
/* The minor token to shift in */
){
){
yyStackEntry
*
yytos
;
yyStackEntry
*
yytos
;
yypParser
->
yytos
++
;
yypParser
->
yytos
++
;
...
@@ -1840,14 +1840,14 @@ static YYACTIONTYPE yy_reduce(
...
@@ -1840,14 +1840,14 @@ static YYACTIONTYPE yy_reduce(
yyParser
*
yypParser
,
/* The parser */
yyParser
*
yypParser
,
/* The parser */
unsigned
int
yyruleno
,
/* Number of the rule by which to reduce */
unsigned
int
yyruleno
,
/* Number of the rule by which to reduce */
int
yyLookahead
,
/* Lookahead token, or YYNOCODE if none */
int
yyLookahead
,
/* Lookahead token, or YYNOCODE if none */
New
ParseTOKENTYPE
yyLookaheadToken
/* Value of the lookahead token */
ParseTOKENTYPE
yyLookaheadToken
/* Value of the lookahead token */
New
ParseCTX_PDECL
/* %extra_context */
ParseCTX_PDECL
/* %extra_context */
){
){
int
yygoto
;
/* The next state */
int
yygoto
;
/* The next state */
YYACTIONTYPE
yyact
;
/* The next action */
YYACTIONTYPE
yyact
;
/* The next action */
yyStackEntry
*
yymsp
;
/* The top of the parser's stack */
yyStackEntry
*
yymsp
;
/* The top of the parser's stack */
int
yysize
;
/* Amount to pop the stack */
int
yysize
;
/* Amount to pop the stack */
New
ParseARG_FETCH
ParseARG_FETCH
(
void
)
yyLookahead
;
(
void
)
yyLookahead
;
(
void
)
yyLookaheadToken
;
(
void
)
yyLookaheadToken
;
yymsp
=
yypParser
->
yytos
;
yymsp
=
yypParser
->
yytos
;
...
@@ -2680,8 +2680,8 @@ static YYACTIONTYPE yy_reduce(
...
@@ -2680,8 +2680,8 @@ static YYACTIONTYPE yy_reduce(
static
void
yy_parse_failed
(
static
void
yy_parse_failed
(
yyParser
*
yypParser
/* The parser */
yyParser
*
yypParser
/* The parser */
){
){
New
ParseARG_FETCH
ParseARG_FETCH
New
ParseCTX_FETCH
ParseCTX_FETCH
#ifndef NDEBUG
#ifndef NDEBUG
if
(
yyTraceFILE
){
if
(
yyTraceFILE
){
fprintf
(
yyTraceFILE
,
"%sFail!
\n
"
,
yyTracePrompt
);
fprintf
(
yyTraceFILE
,
"%sFail!
\n
"
,
yyTracePrompt
);
...
@@ -2692,8 +2692,8 @@ static void yy_parse_failed(
...
@@ -2692,8 +2692,8 @@ static void yy_parse_failed(
** parser fails */
** parser fails */
/************ Begin %parse_failure code ***************************************/
/************ Begin %parse_failure code ***************************************/
/************ End %parse_failure code *****************************************/
/************ End %parse_failure code *****************************************/
New
ParseARG_STORE
/* Suppress warning about unused %extra_argument variable */
ParseARG_STORE
/* Suppress warning about unused %extra_argument variable */
New
ParseCTX_STORE
ParseCTX_STORE
}
}
#endif
/* YYNOERRORRECOVERY */
#endif
/* YYNOERRORRECOVERY */
...
@@ -2703,10 +2703,10 @@ static void yy_parse_failed(
...
@@ -2703,10 +2703,10 @@ static void yy_parse_failed(
static
void
yy_syntax_error
(
static
void
yy_syntax_error
(
yyParser
*
yypParser
,
/* The parser */
yyParser
*
yypParser
,
/* The parser */
int
yymajor
,
/* The major type of the error token */
int
yymajor
,
/* The major type of the error token */
New
ParseTOKENTYPE
yyminor
/* The minor type of the error token */
ParseTOKENTYPE
yyminor
/* The minor type of the error token */
){
){
New
ParseARG_FETCH
ParseARG_FETCH
New
ParseCTX_FETCH
ParseCTX_FETCH
#define TOKEN yyminor
#define TOKEN yyminor
/************ Begin %syntax_error code ****************************************/
/************ Begin %syntax_error code ****************************************/
...
@@ -2717,8 +2717,8 @@ static void yy_syntax_error(
...
@@ -2717,8 +2717,8 @@ static void yy_syntax_error(
}
}
pCxt
->
valid
=
false
;
pCxt
->
valid
=
false
;
/************ End %syntax_error code ******************************************/
/************ End %syntax_error code ******************************************/
New
ParseARG_STORE
/* Suppress warning about unused %extra_argument variable */
ParseARG_STORE
/* Suppress warning about unused %extra_argument variable */
New
ParseCTX_STORE
ParseCTX_STORE
}
}
/*
/*
...
@@ -2727,8 +2727,8 @@ static void yy_syntax_error(
...
@@ -2727,8 +2727,8 @@ static void yy_syntax_error(
static
void
yy_accept
(
static
void
yy_accept
(
yyParser
*
yypParser
/* The parser */
yyParser
*
yypParser
/* The parser */
){
){
New
ParseARG_FETCH
ParseARG_FETCH
New
ParseCTX_FETCH
ParseCTX_FETCH
#ifndef NDEBUG
#ifndef NDEBUG
if
(
yyTraceFILE
){
if
(
yyTraceFILE
){
fprintf
(
yyTraceFILE
,
"%sAccept!
\n
"
,
yyTracePrompt
);
fprintf
(
yyTraceFILE
,
"%sAccept!
\n
"
,
yyTracePrompt
);
...
@@ -2742,13 +2742,13 @@ static void yy_accept(
...
@@ -2742,13 +2742,13 @@ static void yy_accept(
** parser accepts */
** parser accepts */
/*********** Begin %parse_accept code *****************************************/
/*********** Begin %parse_accept code *****************************************/
/*********** End %parse_accept code *******************************************/
/*********** End %parse_accept code *******************************************/
New
ParseARG_STORE
/* Suppress warning about unused %extra_argument variable */
ParseARG_STORE
/* Suppress warning about unused %extra_argument variable */
New
ParseCTX_STORE
ParseCTX_STORE
}
}
/* The main parser program.
/* The main parser program.
** The first argument is a pointer to a structure obtained from
** The first argument is a pointer to a structure obtained from
** "
New
ParseAlloc" which describes the current state of the parser.
** "ParseAlloc" which describes the current state of the parser.
** The second argument is the major token number. The third is
** The second argument is the major token number. The third is
** the minor token. The fourth optional argument is whatever the
** the minor token. The fourth optional argument is whatever the
** user wants (and specified in the grammar) and is available for
** user wants (and specified in the grammar) and is available for
...
@@ -2765,11 +2765,11 @@ static void yy_accept(
...
@@ -2765,11 +2765,11 @@ static void yy_accept(
** Outputs:
** Outputs:
** None.
** None.
*/
*/
void
New
Parse
(
void
Parse
(
void
*
yyp
,
/* The parser */
void
*
yyp
,
/* The parser */
int
yymajor
,
/* The major token code number */
int
yymajor
,
/* The major token code number */
New
ParseTOKENTYPE
yyminor
/* The value for the token */
ParseTOKENTYPE
yyminor
/* The value for the token */
New
ParseARG_PDECL
/* Optional %extra_argument parameter */
ParseARG_PDECL
/* Optional %extra_argument parameter */
){
){
YYMINORTYPE
yyminorunion
;
YYMINORTYPE
yyminorunion
;
YYACTIONTYPE
yyact
;
/* The parser action. */
YYACTIONTYPE
yyact
;
/* The parser action. */
...
@@ -2780,8 +2780,8 @@ void NewParse(
...
@@ -2780,8 +2780,8 @@ void NewParse(
int
yyerrorhit
=
0
;
/* True if yymajor has invoked an error */
int
yyerrorhit
=
0
;
/* True if yymajor has invoked an error */
#endif
#endif
yyParser
*
yypParser
=
(
yyParser
*
)
yyp
;
/* The parser */
yyParser
*
yypParser
=
(
yyParser
*
)
yyp
;
/* The parser */
New
ParseCTX_FETCH
ParseCTX_FETCH
New
ParseARG_STORE
ParseARG_STORE
assert
(
yypParser
->
yytos
!=
0
);
assert
(
yypParser
->
yytos
!=
0
);
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
...
@@ -2806,7 +2806,7 @@ void NewParse(
...
@@ -2806,7 +2806,7 @@ void NewParse(
yyact
=
yy_find_shift_action
((
YYCODETYPE
)
yymajor
,
yyact
);
yyact
=
yy_find_shift_action
((
YYCODETYPE
)
yymajor
,
yyact
);
if
(
yyact
>=
YY_MIN_REDUCE
){
if
(
yyact
>=
YY_MIN_REDUCE
){
yyact
=
yy_reduce
(
yypParser
,
yyact
-
YY_MIN_REDUCE
,
yymajor
,
yyact
=
yy_reduce
(
yypParser
,
yyact
-
YY_MIN_REDUCE
,
yymajor
,
yyminor
New
ParseCTX_PARAM
);
yyminor
ParseCTX_PARAM
);
}
else
if
(
yyact
<=
YY_MAX_SHIFTREDUCE
){
}
else
if
(
yyact
<=
YY_MAX_SHIFTREDUCE
){
yy_shift
(
yypParser
,
yyact
,(
YYCODETYPE
)
yymajor
,
yyminor
);
yy_shift
(
yypParser
,
yyact
,(
YYCODETYPE
)
yymajor
,
yyminor
);
#ifndef YYNOERRORRECOVERY
#ifndef YYNOERRORRECOVERY
...
@@ -2939,7 +2939,7 @@ void NewParse(
...
@@ -2939,7 +2939,7 @@ void NewParse(
** Return the fallback token corresponding to canonical token iToken, or
** Return the fallback token corresponding to canonical token iToken, or
** 0 if iToken has no fallback.
** 0 if iToken has no fallback.
*/
*/
int
New
ParseFallback
(
int
iToken
){
int
ParseFallback
(
int
iToken
){
#ifdef YYFALLBACK
#ifdef YYFALLBACK
if
(
iToken
<
(
int
)(
sizeof
(
yyFallback
)
/
sizeof
(
yyFallback
[
0
]))
){
if
(
iToken
<
(
int
)(
sizeof
(
yyFallback
)
/
sizeof
(
yyFallback
[
0
]))
){
return
yyFallback
[
iToken
];
return
yyFallback
[
iToken
];
...
...
source/libs/parser/test/parserTest.cpp
→
source/libs/parser/test/parser
Ast
Test.cpp
浏览文件 @
5b5ac34d
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include "par
ser
Int.h"
#include "parInt.h"
using
namespace
std
;
using
namespace
std
;
using
namespace
testing
;
using
namespace
testing
;
...
...
source/libs/parser/test/
insertParser
Test.cpp
→
source/libs/parser/test/
parserInsert
Test.cpp
浏览文件 @
5b5ac34d
...
@@ -15,8 +15,7 @@
...
@@ -15,8 +15,7 @@
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include "insertParser.h"
#include "parInt.h"
// #include "mockCatalog.h"
using
namespace
std
;
using
namespace
std
;
using
namespace
testing
;
using
namespace
testing
;
...
...
source/libs/parser/test/tokenizerTest.cpp
已删除
100644 → 0
浏览文件 @
ddbe4095
#if 0
#include <gtest/gtest.h>
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h"
#include "taos.h"
#include "tvariant.h"
#include "tdef.h"
#include "ttoken.h"
#include "astGenerator.h"
#include "parserUtil.h"
#include "parserInt.h"
namespace {
int32_t testValidateName(char* name) {
SToken token = {0};
token.z = name;
token.n = strlen(name);
token.type = 0;
tGetToken(name, &token.type);
return parserValidateIdToken(&token);
}
SToken createToken(char* s) {
SToken t = {0};
t.type = TK_STRING;
t.z = s;
t.n = strlen(s);
return t;
}
} // namespace
static void _init_tvariant_bool(SVariant* t) {
t->i = TSDB_FALSE;
t->nType = TSDB_DATA_TYPE_BOOL;
}
static void _init_tvariant_tinyint(SVariant* t) {
t->i = -27;
t->nType = TSDB_DATA_TYPE_TINYINT;
}
static void _init_tvariant_int(SVariant* t) {
t->i = -23997659;
t->nType = TSDB_DATA_TYPE_INT;
}
static void _init_tvariant_bigint(SVariant* t) {
t->i = -3333333333333;
t->nType = TSDB_DATA_TYPE_BIGINT;
}
static void _init_tvariant_float(SVariant* t) {
t->d = -8991212199.8987878776;
t->nType = TSDB_DATA_TYPE_FLOAT;
}
static void _init_tvariant_binary(SVariant* t) {
taosVariantDestroy(t);
t->pz = (char*)calloc(1, 20); //"2e3");
t->nType = TSDB_DATA_TYPE_BINARY;
strcpy(t->pz, "2e5");
t->nLen = strlen(t->pz);
}
static void _init_tvariant_nchar(SVariant* t) {
taosVariantDestroy(t);
t->wpz = (wchar_t*)calloc(1, 20 * TSDB_NCHAR_SIZE);
t->nType = TSDB_DATA_TYPE_NCHAR;
wcscpy(t->wpz, L"-2000000.8765");
t->nLen = twcslen(t->wpz);
}
TEST(testCase, validateToken_test) {
char t01[] = "abc";
EXPECT_EQ(testValidateName(t01), TSDB_CODE_SUCCESS);
char t110[] = "`1233abc.911`";
EXPECT_EQ(testValidateName(t110), TSDB_CODE_SUCCESS);
char t02[] = "'abc'";
EXPECT_EQ(testValidateName(t02), TSDB_CODE_TSC_INVALID_OPERATION);
char t1[] = "abc.def";
EXPECT_EQ(testValidateName(t1), TSDB_CODE_SUCCESS);
printf("%s\n", t1);
char t98[] = "abc.DeF";
EXPECT_EQ(testValidateName(t98), TSDB_CODE_SUCCESS);
EXPECT_STREQ(t98, "abc.def");
printf("%s\n", t98);
char t97[] = "257.abc";
EXPECT_EQ(testValidateName(t97), TSDB_CODE_TSC_INVALID_OPERATION);
printf("%s\n", t97);
char t96[] = "_257.aBc";
EXPECT_EQ(testValidateName(t96), TSDB_CODE_SUCCESS);
EXPECT_STREQ(t96, "_257.abc");
printf("%s\n", t96);
char t99[] = "abc . def";
EXPECT_EQ(testValidateName(t99), TSDB_CODE_TSC_INVALID_OPERATION);
printf("%s\n", t99);
char t2[] = "'abc.def'";
EXPECT_EQ(testValidateName(t2), TSDB_CODE_TSC_INVALID_OPERATION);
printf("%s\n", t2);
char t3[] = "'abc'.def";
EXPECT_EQ(testValidateName(t3), TSDB_CODE_TSC_INVALID_OPERATION);
printf("%s\n", t3);
char t4[] = "'abc'.'def'";
EXPECT_EQ(testValidateName(t4), TSDB_CODE_TSC_INVALID_OPERATION);
char t5[] = "table.'def'";
EXPECT_EQ(testValidateName(t5), TSDB_CODE_TSC_INVALID_OPERATION);
char t6[] = "'table'.'def'";
EXPECT_EQ(testValidateName(t6), TSDB_CODE_TSC_INVALID_OPERATION);
char t7[] = "'_ab1234'.'def'";
EXPECT_EQ(testValidateName(t7), TSDB_CODE_TSC_INVALID_OPERATION);
printf("%s\n", t7);
char t8[] = "'_ab&^%1234'.'def'";
EXPECT_EQ(testValidateName(t8), TSDB_CODE_TSC_INVALID_OPERATION);
char t9[] = "'_123'.'gtest中文'";
EXPECT_EQ(testValidateName(t9), TSDB_CODE_TSC_INVALID_OPERATION);
char t10[] = "abc.'gtest中文'";
EXPECT_EQ(testValidateName(t10), TSDB_CODE_TSC_INVALID_OPERATION);
char t10_1[] = "abc.'中文gtest'";
EXPECT_EQ(testValidateName(t10_1), TSDB_CODE_TSC_INVALID_OPERATION);
char t11[] = "'192.168.0.1'.abc";
EXPECT_EQ(testValidateName(t11), TSDB_CODE_TSC_INVALID_OPERATION);
char t12[] = "192.168.0.1.abc";
EXPECT_EQ(testValidateName(t12), TSDB_CODE_TSC_INVALID_OPERATION);
char t13[] = "abc.";
EXPECT_EQ(testValidateName(t13), TSDB_CODE_TSC_INVALID_OPERATION);
char t14[] = ".abc";
EXPECT_EQ(testValidateName(t14), TSDB_CODE_TSC_INVALID_OPERATION);
char t15[] = ".'abc'";
EXPECT_EQ(testValidateName(t15), TSDB_CODE_TSC_INVALID_OPERATION);
char t16[] = ".abc'";
EXPECT_EQ(testValidateName(t16), TSDB_CODE_TSC_INVALID_OPERATION);
char t17[] = "123a.\"abc\"";
EXPECT_EQ(testValidateName(t17), TSDB_CODE_TSC_INVALID_OPERATION);
printf("%s\n", t17);
char t18[] = "a.\"abc\"";
EXPECT_EQ(testValidateName(t18), TSDB_CODE_TSC_INVALID_OPERATION);
printf("%s\n", t18);
char t19[] = "'_ab1234'.'def'.'ab123'";
EXPECT_EQ(testValidateName(t19), TSDB_CODE_TSC_INVALID_OPERATION);
char t20[] = "'_ab1234*&^'";
EXPECT_EQ(testValidateName(t20), TSDB_CODE_TSC_INVALID_OPERATION);
char t21[] = "'1234_abc'";
EXPECT_EQ(testValidateName(t21), TSDB_CODE_TSC_INVALID_OPERATION);
// =======Containing capital letters=================
char t30[] = "ABC";
EXPECT_EQ(testValidateName(t30), TSDB_CODE_SUCCESS);
char t31[] = "'ABC'";
EXPECT_EQ(testValidateName(t31), TSDB_CODE_TSC_INVALID_OPERATION);
char t32[] = "ABC.def";
EXPECT_EQ(testValidateName(t32), TSDB_CODE_SUCCESS);
char t33[] = "'ABC.def";
EXPECT_EQ(testValidateName(t33), TSDB_CODE_TSC_INVALID_OPERATION);
char t33_0[] = "abc.DEF'";
EXPECT_EQ(testValidateName(t33_0), TSDB_CODE_TSC_INVALID_OPERATION);
char t34[] = "'ABC.def'";
// int32_t tmp0 = testValidateName(t34);
EXPECT_EQ(testValidateName(t34), TSDB_CODE_TSC_INVALID_OPERATION);
char t35[] = "'ABC'.def";
EXPECT_EQ(testValidateName(t35), TSDB_CODE_TSC_INVALID_OPERATION);
char t36[] = "ABC.DEF";
EXPECT_EQ(testValidateName(t36), TSDB_CODE_SUCCESS);
char t37[] = "abc.DEF";
EXPECT_EQ(testValidateName(t37), TSDB_CODE_SUCCESS);
char t37_1[] = "abc._123DEF";
EXPECT_EQ(testValidateName(t37_1), TSDB_CODE_SUCCESS);
char t38[] = "'abc'.\"DEF\"";
EXPECT_EQ(testValidateName(t38), TSDB_CODE_TSC_INVALID_OPERATION);
// do not use key words
char t39[] = "table.'DEF'";
EXPECT_EQ(testValidateName(t39), TSDB_CODE_TSC_INVALID_OPERATION);
char t40[] = "'table'.'DEF'";
EXPECT_EQ(testValidateName(t40), TSDB_CODE_TSC_INVALID_OPERATION);
char t41[] = "'_abXYZ1234'.'deFF'";
EXPECT_EQ(testValidateName(t41), TSDB_CODE_TSC_INVALID_OPERATION);
char t42[] = "'_abDEF&^%1234'.'DIef'";
EXPECT_EQ(testValidateName(t42), TSDB_CODE_TSC_INVALID_OPERATION);
char t43[] = "'_123'.'Gtest中文'";
EXPECT_EQ(testValidateName(t43), TSDB_CODE_TSC_INVALID_OPERATION);
char t44[] = "'aABC'.'Gtest中文'";
EXPECT_EQ(testValidateName(t44), TSDB_CODE_TSC_INVALID_OPERATION);
char t45[] = "'ABC'.";
EXPECT_EQ(testValidateName(t45), TSDB_CODE_TSC_INVALID_OPERATION);
char t46[] = ".'ABC'";
EXPECT_EQ(testValidateName(t46), TSDB_CODE_TSC_INVALID_OPERATION);
char t47[] = "a.\"aTWc\"";
EXPECT_EQ(testValidateName(t47), TSDB_CODE_TSC_INVALID_OPERATION);
// ================has space =================
char t60[] = " ABC ";
EXPECT_EQ(testValidateName(t60), TSDB_CODE_TSC_INVALID_OPERATION);
char t60_1[] = " ABC ";
EXPECT_EQ(testValidateName(t60_1), TSDB_CODE_TSC_INVALID_OPERATION);
char t61[] = "' ABC '";
EXPECT_EQ(testValidateName(t61), TSDB_CODE_TSC_INVALID_OPERATION);
char t61_1[] = "' ABC '";
EXPECT_EQ(testValidateName(t61_1), TSDB_CODE_TSC_INVALID_OPERATION);
char t62[] = " ABC . def ";
EXPECT_EQ(testValidateName(t62), TSDB_CODE_TSC_INVALID_OPERATION);
char t63[] = "' ABC . def ";
EXPECT_EQ(testValidateName(t63), TSDB_CODE_TSC_INVALID_OPERATION);
char t63_0[] = " abc . DEF ' ";
EXPECT_EQ(testValidateName(t63_0), TSDB_CODE_TSC_INVALID_OPERATION);
char t64[] = " ' ABC . def ' ";
// int32_t tmp1 = testValidateName(t64);
EXPECT_EQ(testValidateName(t64), TSDB_CODE_TSC_INVALID_OPERATION);
char t65[] = " ' ABC '. def ";
EXPECT_EQ(testValidateName(t65), TSDB_CODE_TSC_INVALID_OPERATION);
char t66[] = "' ABC '.' DEF '";
EXPECT_EQ(testValidateName(t66), TSDB_CODE_TSC_INVALID_OPERATION);
char t67[] = "abc . ' DEF '";
EXPECT_EQ(testValidateName(t67), TSDB_CODE_TSC_INVALID_OPERATION);
char t68[] = "' abc '.' DEF '";
EXPECT_EQ(testValidateName(t68), TSDB_CODE_TSC_INVALID_OPERATION);
// do not use key words
char t69[] = "table.'DEF'";
EXPECT_EQ(testValidateName(t69), TSDB_CODE_TSC_INVALID_OPERATION);
char t70[] = "'table'.'DEF'";
EXPECT_EQ(testValidateName(t70), TSDB_CODE_TSC_INVALID_OPERATION);
char t71[] = "'_abXYZ1234 '.' deFF '";
EXPECT_EQ(testValidateName(t71), TSDB_CODE_TSC_INVALID_OPERATION);
char t72[] = "'_abDEF&^%1234'.' DIef'";
EXPECT_EQ(testValidateName(t72), TSDB_CODE_TSC_INVALID_OPERATION);
char t73[] = "'_123'.' Gtest中文'";
EXPECT_EQ(testValidateName(t73), TSDB_CODE_TSC_INVALID_OPERATION);
char t74[] = "' aABC'.'Gtest中文'";
EXPECT_EQ(testValidateName(t74), TSDB_CODE_TSC_INVALID_OPERATION);
char t75[] = "' ABC '.";
EXPECT_EQ(testValidateName(t75), TSDB_CODE_TSC_INVALID_OPERATION);
char t76[] = ".' ABC'";
EXPECT_EQ(testValidateName(t76), TSDB_CODE_TSC_INVALID_OPERATION);
char t77[] = " a . \"aTWc\" ";
EXPECT_EQ(testValidateName(t77), TSDB_CODE_TSC_INVALID_OPERATION);
char t78[] = " a.\"aTWc \"";
EXPECT_EQ(testValidateName(t78), TSDB_CODE_TSC_INVALID_OPERATION);
// ===============muti string by space ===================
// There's no such case.
// char t160[] = "A BC";
// EXPECT_EQ(testValidateName(t160), TSDB_CODE_TSC_INVALID_OPERATION);
// printf("end:%s\n", t160);
// There's no such case.
// char t161[] = "' A BC '";
// EXPECT_EQ(testValidateName(t161), TSDB_CODE_TSC_INVALID_OPERATION);
char t162[] = " AB C . de f ";
EXPECT_EQ(testValidateName(t162), TSDB_CODE_TSC_INVALID_OPERATION);
char t163[] = "' AB C . de f ";
EXPECT_EQ(testValidateName(t163), TSDB_CODE_TSC_INVALID_OPERATION);
char t163_0[] = " ab c . DE F ' ";
EXPECT_EQ(testValidateName(t163_0), TSDB_CODE_TSC_INVALID_OPERATION);
char t164[] = " ' AB C . de f ' ";
// int32_t tmp2 = testValidateName(t164);
EXPECT_EQ(testValidateName(t164), TSDB_CODE_TSC_INVALID_OPERATION);
char t165[] = " ' A BC '. de f ";
EXPECT_EQ(testValidateName(t165), TSDB_CODE_TSC_INVALID_OPERATION);
char t166[] = "' AB C '.' DE F '";
EXPECT_EQ(testValidateName(t166), TSDB_CODE_TSC_INVALID_OPERATION);
char t167[] = "ab c . ' D EF '";
EXPECT_EQ(testValidateName(t167), TSDB_CODE_TSC_INVALID_OPERATION);
char t168[] = "' a bc '.' DE F '";
EXPECT_EQ(testValidateName(t168), TSDB_CODE_TSC_INVALID_OPERATION);
}
#if 0
TEST(testCase, tvariant_convert) {
// 1. bool data to all other data types
SVariant t = {0};
_init_tvariant_bool(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BOOL), 0);
EXPECT_EQ(t.i, 0);
_init_tvariant_bool(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_TINYINT), 0);
EXPECT_EQ(t.i, 0);
_init_tvariant_bool(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_SMALLINT), 0);
EXPECT_EQ(t.i, 0);
_init_tvariant_bool(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BIGINT), 0);
EXPECT_EQ(t.i, 0);
_init_tvariant_bool(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_FLOAT), 0);
EXPECT_EQ(t.d, 0);
_init_tvariant_bool(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_DOUBLE), 0);
EXPECT_EQ(t.d, 0);
_init_tvariant_bool(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BINARY), 0);
EXPECT_STREQ(t.pz, "FALSE");
taosVariantDestroy(&t);
_init_tvariant_bool(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_NCHAR), 0);
EXPECT_STREQ(t.wpz, L"FALSE");
taosVariantDestroy(&t);
// 2. tinyint to other data types
_init_tvariant_tinyint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BOOL), 0);
EXPECT_EQ(t.i, 1);
_init_tvariant_tinyint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_TINYINT), 0);
EXPECT_EQ(t.i, -27);
_init_tvariant_tinyint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_SMALLINT), 0);
EXPECT_EQ(t.i, -27);
_init_tvariant_tinyint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_INT), 0);
EXPECT_EQ(t.i, -27);
_init_tvariant_tinyint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BIGINT), 0);
EXPECT_EQ(t.i, -27);
_init_tvariant_tinyint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_FLOAT), 0);
EXPECT_EQ(t.d, -27);
_init_tvariant_tinyint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_DOUBLE), 0);
EXPECT_EQ(t.d, -27);
_init_tvariant_tinyint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BINARY), 0);
EXPECT_STREQ(t.pz, "-27");
taosVariantDestroy(&t);
_init_tvariant_tinyint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_NCHAR), 0);
EXPECT_STREQ(t.wpz, L"-27");
taosVariantDestroy(&t);
// 3. int to other data
// types//////////////////////////////////////////////////////////////////
_init_tvariant_int(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BOOL), 0);
EXPECT_EQ(t.i, 1);
_init_tvariant_int(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_TINYINT), 0);
_init_tvariant_int(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_SMALLINT), 0);
_init_tvariant_int(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_INT), 0);
EXPECT_EQ(t.i, -23997659);
_init_tvariant_int(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BIGINT), 0);
EXPECT_EQ(t.i, -23997659);
_init_tvariant_int(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_FLOAT), 0);
EXPECT_EQ(t.d, -23997659);
_init_tvariant_int(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_DOUBLE), 0);
EXPECT_EQ(t.d, -23997659);
_init_tvariant_int(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BINARY), 0);
EXPECT_STREQ(t.pz, "-23997659");
taosVariantDestroy(&t);
_init_tvariant_int(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_NCHAR), 0);
EXPECT_STREQ(t.wpz, L"-23997659");
taosVariantDestroy(&t);
// 4. bigint to other data
// type//////////////////////////////////////////////////////////////////////////////
_init_tvariant_bigint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BOOL), 0);
EXPECT_EQ(t.i, 1);
_init_tvariant_bigint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_TINYINT), 0);
_init_tvariant_bigint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_SMALLINT), 0);
_init_tvariant_bigint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_INT), 0);
_init_tvariant_bigint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BIGINT), 0);
EXPECT_EQ(t.i, -3333333333333);
_init_tvariant_bigint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_FLOAT), 0);
EXPECT_EQ(t.d, -3333333333333);
_init_tvariant_bigint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_DOUBLE), 0);
EXPECT_EQ(t.d, -3333333333333);
_init_tvariant_bigint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BINARY), 0);
EXPECT_STREQ(t.pz, "-3333333333333");
taosVariantDestroy(&t);
_init_tvariant_bigint(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_NCHAR), 0);
EXPECT_STREQ(t.wpz, L"-3333333333333");
taosVariantDestroy(&t);
// 5. float to other data
// types////////////////////////////////////////////////////////////////////////
_init_tvariant_float(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BOOL), 0);
EXPECT_EQ(t.i, 1);
_init_tvariant_float(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BIGINT), 0);
EXPECT_EQ(t.i, -8991212199);
_init_tvariant_float(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_FLOAT), 0);
EXPECT_DOUBLE_EQ(t.d, -8991212199.8987885);
_init_tvariant_float(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_DOUBLE), 0);
EXPECT_DOUBLE_EQ(t.d, -8991212199.8987885);
_init_tvariant_float(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BINARY), 0);
EXPECT_STREQ(t.pz, "-8991212199.898788");
taosVariantDestroy(&t);
_init_tvariant_float(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_NCHAR), 0);
EXPECT_STREQ(t.wpz, L"-8991212199.898788");
taosVariantDestroy(&t);
// 6. binary to other data types
// //////////////////////////////////////////////////////////////////
t.pz = "true";
t.nLen = strlen(t.pz);
t.nType = TSDB_DATA_TYPE_BINARY;
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BOOL), 0);
EXPECT_EQ(t.i, 1);
_init_tvariant_binary(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BOOL), -1);
_init_tvariant_binary(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BIGINT), 0);
EXPECT_EQ(t.i, 200000);
_init_tvariant_binary(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_FLOAT), 0);
EXPECT_DOUBLE_EQ(t.d, 200000);
_init_tvariant_binary(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_DOUBLE), 0);
EXPECT_DOUBLE_EQ(t.d, 200000);
_init_tvariant_binary(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BINARY), 0);
EXPECT_STREQ(t.pz, "2e5");
taosVariantDestroy(&t);
_init_tvariant_binary(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_NCHAR), 0);
EXPECT_STREQ(t.wpz, L"2e5");
taosVariantDestroy(&t);
// 7. nchar to other data types
// //////////////////////////////////////////////////////////////////
t.wpz = L"FALSE";
t.nLen = wcslen(t.wpz);
t.nType = TSDB_DATA_TYPE_NCHAR;
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BOOL), 0);
EXPECT_EQ(t.i, 0);
_init_tvariant_nchar(&t);
EXPECT_LE(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BOOL), 0);
_init_tvariant_nchar(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BIGINT), 0);
EXPECT_EQ(t.i, -2000000);
_init_tvariant_nchar(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_FLOAT), 0);
EXPECT_DOUBLE_EQ(t.d, -2000000.8765);
_init_tvariant_nchar(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_DOUBLE), 0);
EXPECT_DOUBLE_EQ(t.d, -2000000.8765);
_init_tvariant_nchar(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_BINARY), 0);
EXPECT_STREQ(t.pz, "-2000000.8765");
taosVariantDestroy(&t);
_init_tvariant_nchar(&t);
EXPECT_EQ(taosVariantTypeSetType(&t, TSDB_DATA_TYPE_NCHAR), 0);
EXPECT_STREQ(t.wpz, L"-2000000.8765");
taosVariantDestroy(&t);
}
#endif
TEST(testCase, tGetToken_Test) {
char* s = ".123 ";
uint32_t type = 0;
int32_t len = tGetToken(s, &type);
EXPECT_EQ(type, TK_FLOAT);
EXPECT_EQ(len, strlen(s) - 1);
char s1[] = "1.123e10 ";
len = tGetToken(s1, &type);
EXPECT_EQ(type, TK_FLOAT);
EXPECT_EQ(len, strlen(s1) - 1);
char s4[] = "0xff ";
len = tGetToken(s4, &type);
EXPECT_EQ(type, TK_HEX);
EXPECT_EQ(len, strlen(s4) - 1);
// invalid data type
char s2[] = "e10 ";
len = tGetToken(s2, &type);
EXPECT_FALSE(type == TK_FLOAT);
char s3[] = "1.1.1.1";
len = tGetToken(s3, &type);
EXPECT_EQ(type, TK_IPTOKEN);
EXPECT_EQ(len, strlen(s3));
char s5[] = "0x ";
len = tGetToken(s5, &type);
EXPECT_FALSE(type == TK_HEX);
}
TEST(testCase, isValidNumber_test) {
SToken t1 = createToken("123abc");
EXPECT_EQ(tGetNumericStringType(&t1), TK_ILLEGAL);
t1 = createToken("0xabc");
EXPECT_EQ(tGetNumericStringType(&t1), TK_HEX);
t1 = createToken("0b11101");
EXPECT_EQ(tGetNumericStringType(&t1), TK_BIN);
t1 = createToken(".134abc");
EXPECT_EQ(tGetNumericStringType(&t1), TK_ILLEGAL);
t1 = createToken("1e1 ");
EXPECT_EQ(tGetNumericStringType(&t1), TK_ILLEGAL);
t1 = createToken("1+2");
EXPECT_EQ(tGetNumericStringType(&t1), TK_ILLEGAL);
t1 = createToken("-0x123");
EXPECT_EQ(tGetNumericStringType(&t1), TK_HEX);
t1 = createToken("-1");
EXPECT_EQ(tGetNumericStringType(&t1), TK_INTEGER);
t1 = createToken("-0b1110");
EXPECT_EQ(tGetNumericStringType(&t1), TK_BIN);
t1 = createToken("-.234");
EXPECT_EQ(tGetNumericStringType(&t1), TK_FLOAT);
}
TEST(testCase, generateAST_test) {
SSqlInfo info = doGenerateAST("select * from t1 where ts < now");
ASSERT_EQ(info.valid, true);
SSqlInfo info1 = doGenerateAST("select * from `t.1abc` where ts<now+2h and col < 20+99");
ASSERT_EQ(info1.valid, true);
char msg[128] = {0};
SMsgBuf msgBuf = {0};
msgBuf.buf = msg;
msgBuf.len = 128;
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &msgBuf);
ASSERT_EQ(code, 0);
SSqlInfo info2 = doGenerateAST("select * from abc where ts<now+2");
SSqlNode* pNode2 = (SSqlNode*) taosArrayGetP(((SArray*)info2.sub.node), 0);
code = evaluateSqlNode(pNode2, TSDB_TIME_PRECISION_MILLI, &msgBuf);
ASSERT_NE(code, 0);
destroySqlInfo(&info);
destroySqlInfo(&info1);
destroySqlInfo(&info2);
}
TEST(testCase, evaluateAST_test) {
SSqlInfo info1 = doGenerateAST("select a, b+22 from `t.1abc` where ts<now+2h and `col` < 20 + 99");
ASSERT_EQ(info1.valid, true);
char msg[128] = {0};
SMsgBuf msgBuf = {0};
msgBuf.buf = msg;
msgBuf.len = 128;
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.sub.node), 0);
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &msgBuf);
ASSERT_EQ(code, 0);
destroySqlInfo(&info1);
}
TEST(testCase, extractMeta_test) {
SSqlInfo info1 = doGenerateAST("select a, b+22 from `t.1abc` where ts<now+2h and `col` < 20 + 99");
ASSERT_EQ(info1.valid, true);
char msg[128] = {0};
SCatalogReq req = {0};
SParseContext ctx = {0};
ctx.db = "db1";
ctx.acctId = 1;
int32_t ret = qParserExtractRequestedMetaInfo(&info1, &req, &ctx, msg, 128);
ASSERT_EQ(ret, 0);
ASSERT_EQ(taosArrayGetSize(req.pTableName), 1);
qParserCleanupMetaRequestInfo(&req);
destroySqlInfo(&info1);
}
#pragma GCC diagnostic pop
#endif
source/libs/planner/inc/plan
ner
Int.h
→
source/libs/planner/inc/planInt.h
浏览文件 @
5b5ac34d
文件已移动
source/libs/planner/src/
logicPlan
.c
→
source/libs/planner/src/
planLogicCreater
.c
浏览文件 @
5b5ac34d
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "plan
ner
Int.h"
#include "planInt.h"
#include "functionMgt.h"
#include "functionMgt.h"
...
...
source/libs/planner/src/p
hysicalPlan
.c
→
source/libs/planner/src/p
lanPhysiCreater
.c
浏览文件 @
5b5ac34d
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "plan
ner
Int.h"
#include "planInt.h"
#include "functionMgt.h"
#include "functionMgt.h"
...
...
source/libs/planner/src/
splitPlan
.c
→
source/libs/planner/src/
planSpliter
.c
浏览文件 @
5b5ac34d
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "plan
ner
Int.h"
#include "planInt.h"
#define SPLIT_FLAG_MASK(n) (1 << n)
#define SPLIT_FLAG_MASK(n) (1 << n)
...
...
source/libs/planner/src/planner.c
浏览文件 @
5b5ac34d
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
#include "planner.h"
#include "planner.h"
#include "plan
ner
Int.h"
#include "planInt.h"
int32_t
optimize
(
SPlanContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
int32_t
optimize
(
SPlanContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/planner/test/plannerTest.cpp
浏览文件 @
5b5ac34d
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include "parser.h"
#include "parser.h"
#include "plan
ner
Int.h"
#include "planInt.h"
using
namespace
std
;
using
namespace
std
;
using
namespace
testing
;
using
namespace
testing
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录