TD-13705 parser integrate and CREATE DATABASE implement
This commit is contained in:
parent
649905f4ee
commit
195ff4f52f
|
@ -16,269 +16,101 @@
|
|||
#ifndef TDENGINE_TTOKENDEF_H
|
||||
#define TDENGINE_TTOKENDEF_H
|
||||
|
||||
#define TK_ID 1
|
||||
#define TK_BOOL 2
|
||||
#define TK_INTEGER 3
|
||||
#define TK_FLOAT 4
|
||||
#define TK_STRING 5
|
||||
#define TK_TIMESTAMP 6
|
||||
#define TK_OR 7
|
||||
#define TK_AND 8
|
||||
#define TK_NOT 9
|
||||
#define TK_EQ 10
|
||||
#define TK_NE 11
|
||||
#define TK_ISNULL 12
|
||||
#define TK_NOTNULL 13
|
||||
#define TK_IS 14
|
||||
#define TK_LIKE 15
|
||||
#define TK_MATCH 16
|
||||
#define TK_NMATCH 17
|
||||
#define TK_GLOB 18
|
||||
#define TK_BETWEEN 19
|
||||
#define TK_IN 20
|
||||
#define TK_GT 21
|
||||
#define TK_GE 22
|
||||
#define TK_LT 23
|
||||
#define TK_LE 24
|
||||
#define TK_BITAND 25
|
||||
#define TK_BITOR 26
|
||||
#define TK_LSHIFT 27
|
||||
#define TK_RSHIFT 28
|
||||
#define TK_PLUS 29
|
||||
#define TK_MINUS 30
|
||||
#define TK_DIVIDE 31
|
||||
#define TK_TIMES 32
|
||||
#define TK_STAR 33
|
||||
#define TK_SLASH 34
|
||||
#define TK_REM 35
|
||||
#define TK_CONCAT 36
|
||||
#define TK_UMINUS 37
|
||||
#define TK_UPLUS 38
|
||||
#define TK_BITNOT 39
|
||||
#define TK_SHOW 40
|
||||
#define TK_DATABASES 41
|
||||
#define TK_TOPICS 42
|
||||
#define TK_FUNCTIONS 43
|
||||
#define TK_MNODES 44
|
||||
#define TK_DNODES 45
|
||||
#define TK_ACCOUNTS 46
|
||||
#define TK_USERS 47
|
||||
#define TK_MODULES 48
|
||||
#define TK_QUERIES 49
|
||||
#define TK_CONNECTIONS 50
|
||||
#define TK_STREAMS 51
|
||||
#define TK_VARIABLES 52
|
||||
#define TK_SCORES 53
|
||||
#define TK_GRANTS 54
|
||||
#define TK_VNODES 55
|
||||
#define TK_DOT 56
|
||||
#define TK_CREATE 57
|
||||
#define TK_TABLE 58
|
||||
#define TK_STABLE 59
|
||||
#define TK_DATABASE 60
|
||||
#define TK_TABLES 61
|
||||
#define TK_STABLES 62
|
||||
#define TK_VGROUPS 63
|
||||
#define TK_DROP 64
|
||||
#define TK_TOPIC 65
|
||||
#define TK_FUNCTION 66
|
||||
#define TK_DNODE 67
|
||||
#define TK_USER 68
|
||||
#define TK_ACCOUNT 69
|
||||
#define TK_USE 70
|
||||
#define TK_DESCRIBE 71
|
||||
#define TK_DESC 72
|
||||
#define TK_ALTER 73
|
||||
#define TK_PASS 74
|
||||
#define TK_PRIVILEGE 75
|
||||
#define TK_LOCAL 76
|
||||
#define TK_COMPACT 77
|
||||
#define TK_LP 78
|
||||
#define TK_RP 79
|
||||
#define TK_IF 80
|
||||
#define TK_EXISTS 81
|
||||
#define TK_PORT 82
|
||||
#define TK_IPTOKEN 83
|
||||
#define TK_AS 84
|
||||
#define TK_OUTPUTTYPE 85
|
||||
#define TK_AGGREGATE 86
|
||||
#define TK_BUFSIZE 87
|
||||
#define TK_PPS 88
|
||||
#define TK_TSERIES 89
|
||||
#define TK_DBS 90
|
||||
#define TK_STORAGE 91
|
||||
#define TK_QTIME 92
|
||||
#define TK_CONNS 93
|
||||
#define TK_STATE 94
|
||||
#define TK_COMMA 95
|
||||
#define TK_KEEP 96
|
||||
#define TK_CACHE 97
|
||||
#define TK_REPLICA 98
|
||||
#define TK_QUORUM 99
|
||||
#define TK_DAYS 100
|
||||
#define TK_MINROWS 101
|
||||
#define TK_MAXROWS 102
|
||||
#define TK_BLOCKS 103
|
||||
#define TK_CTIME 104
|
||||
#define TK_WAL 105
|
||||
#define TK_FSYNC 106
|
||||
#define TK_COMP 107
|
||||
#define TK_PRECISION 108
|
||||
#define TK_UPDATE 109
|
||||
#define TK_CACHELAST 110
|
||||
#define TK_STREAM 111
|
||||
#define TK_MODE 112
|
||||
#define TK_UNSIGNED 113
|
||||
#define TK_TAGS 114
|
||||
#define TK_USING 115
|
||||
#define TK_NULL 116
|
||||
#define TK_NOW 117
|
||||
#define TK_SELECT 118
|
||||
#define TK_UNION 119
|
||||
#define TK_ALL 120
|
||||
#define TK_DISTINCT 121
|
||||
#define TK_FROM 122
|
||||
#define TK_VARIABLE 123
|
||||
#define TK_INTERVAL 124
|
||||
#define TK_EVERY 125
|
||||
#define TK_SESSION 126
|
||||
#define TK_STATE_WINDOW 127
|
||||
#define TK_FILL 128
|
||||
#define TK_SLIDING 129
|
||||
#define TK_ORDER 130
|
||||
#define TK_BY 131
|
||||
#define TK_ASC 132
|
||||
#define TK_GROUP 133
|
||||
#define TK_HAVING 134
|
||||
#define TK_LIMIT 135
|
||||
#define TK_OFFSET 136
|
||||
#define TK_SLIMIT 137
|
||||
#define TK_SOFFSET 138
|
||||
#define TK_WHERE 139
|
||||
#define TK_RESET 140
|
||||
#define TK_QUERY 141
|
||||
#define TK_SYNCDB 142
|
||||
#define TK_ADD 143
|
||||
#define TK_COLUMN 144
|
||||
#define TK_MODIFY 145
|
||||
#define TK_TAG 146
|
||||
#define TK_CHANGE 147
|
||||
#define TK_SET 148
|
||||
#define TK_KILL 149
|
||||
#define TK_CONNECTION 150
|
||||
#define TK_COLON 151
|
||||
#define TK_ABORT 152
|
||||
#define TK_AFTER 153
|
||||
#define TK_ATTACH 154
|
||||
#define TK_BEFORE 155
|
||||
#define TK_BEGIN 156
|
||||
#define TK_CASCADE 157
|
||||
#define TK_CLUSTER 158
|
||||
#define TK_CONFLICT 159
|
||||
#define TK_COPY 160
|
||||
#define TK_DEFERRED 161
|
||||
#define TK_DELIMITERS 162
|
||||
#define TK_DETACH 163
|
||||
#define TK_EACH 164
|
||||
#define TK_END 165
|
||||
#define TK_EXPLAIN 166
|
||||
#define TK_FAIL 167
|
||||
#define TK_FOR 168
|
||||
#define TK_IGNORE 169
|
||||
#define TK_IMMEDIATE 170
|
||||
#define TK_INITIALLY 171
|
||||
#define TK_INSTEAD 172
|
||||
#define TK_KEY 173
|
||||
#define TK_OF 174
|
||||
#define TK_RAISE 175
|
||||
#define TK_REPLACE 176
|
||||
#define TK_RESTRICT 177
|
||||
#define TK_ROW 178
|
||||
#define TK_STATEMENT 179
|
||||
#define TK_TRIGGER 180
|
||||
#define TK_VIEW 181
|
||||
#define TK_SEMI 182
|
||||
#define TK_NONE 183
|
||||
#define TK_PREV 184
|
||||
#define TK_LINEAR 185
|
||||
#define TK_IMPORT 186
|
||||
#define TK_TBNAME 187
|
||||
#define TK_JOIN 188
|
||||
#define TK_INSERT 189
|
||||
#define TK_INTO 190
|
||||
#define TK_VALUES 191
|
||||
|
||||
#define NEW_TK_OR 1
|
||||
#define NEW_TK_AND 2
|
||||
#define NEW_TK_UNION 3
|
||||
#define NEW_TK_ALL 4
|
||||
#define NEW_TK_MINUS 5
|
||||
#define NEW_TK_EXCEPT 6
|
||||
#define NEW_TK_INTERSECT 7
|
||||
#define NEW_TK_NK_PLUS 8
|
||||
#define NEW_TK_NK_MINUS 9
|
||||
#define NEW_TK_NK_STAR 10
|
||||
#define NEW_TK_NK_SLASH 11
|
||||
#define NEW_TK_NK_REM 12
|
||||
#define NEW_TK_SHOW 13
|
||||
#define NEW_TK_DATABASES 14
|
||||
#define NEW_TK_NK_INTEGER 15
|
||||
#define NEW_TK_NK_FLOAT 16
|
||||
#define NEW_TK_NK_STRING 17
|
||||
#define NEW_TK_NK_BOOL 18
|
||||
#define NEW_TK_TIMESTAMP 19
|
||||
#define NEW_TK_NK_VARIABLE 20
|
||||
#define NEW_TK_NK_COMMA 21
|
||||
#define NEW_TK_NK_ID 22
|
||||
#define NEW_TK_NK_LP 23
|
||||
#define NEW_TK_NK_RP 24
|
||||
#define NEW_TK_NK_DOT 25
|
||||
#define NEW_TK_BETWEEN 26
|
||||
#define NEW_TK_NOT 27
|
||||
#define NEW_TK_IS 28
|
||||
#define NEW_TK_NULL 29
|
||||
#define NEW_TK_NK_LT 30
|
||||
#define NEW_TK_NK_GT 31
|
||||
#define NEW_TK_NK_LE 32
|
||||
#define NEW_TK_NK_GE 33
|
||||
#define NEW_TK_NK_NE 34
|
||||
#define NEW_TK_NK_EQ 35
|
||||
#define NEW_TK_LIKE 36
|
||||
#define NEW_TK_MATCH 37
|
||||
#define NEW_TK_NMATCH 38
|
||||
#define NEW_TK_IN 39
|
||||
#define NEW_TK_FROM 40
|
||||
#define NEW_TK_AS 41
|
||||
#define NEW_TK_JOIN 42
|
||||
#define NEW_TK_ON 43
|
||||
#define NEW_TK_INNER 44
|
||||
#define NEW_TK_SELECT 45
|
||||
#define NEW_TK_DISTINCT 46
|
||||
#define NEW_TK_WHERE 47
|
||||
#define NEW_TK_PARTITION 48
|
||||
#define NEW_TK_BY 49
|
||||
#define NEW_TK_SESSION 50
|
||||
#define NEW_TK_STATE_WINDOW 51
|
||||
#define NEW_TK_INTERVAL 52
|
||||
#define NEW_TK_SLIDING 53
|
||||
#define NEW_TK_FILL 54
|
||||
#define NEW_TK_VALUE 55
|
||||
#define NEW_TK_NONE 56
|
||||
#define NEW_TK_PREV 57
|
||||
#define NEW_TK_LINEAR 58
|
||||
#define NEW_TK_NEXT 59
|
||||
#define NEW_TK_GROUP 60
|
||||
#define NEW_TK_HAVING 61
|
||||
#define NEW_TK_ORDER 62
|
||||
#define NEW_TK_SLIMIT 63
|
||||
#define NEW_TK_SOFFSET 64
|
||||
#define NEW_TK_LIMIT 65
|
||||
#define NEW_TK_OFFSET 66
|
||||
#define NEW_TK_ASC 67
|
||||
#define NEW_TK_DESC 68
|
||||
#define NEW_TK_NULLS 69
|
||||
#define NEW_TK_FIRST 70
|
||||
#define NEW_TK_LAST 71
|
||||
#define TK_OR 1
|
||||
#define TK_AND 2
|
||||
#define TK_UNION 3
|
||||
#define TK_ALL 4
|
||||
#define TK_MINUS 5
|
||||
#define TK_EXCEPT 6
|
||||
#define TK_INTERSECT 7
|
||||
#define TK_NK_BITAND 8
|
||||
#define TK_NK_BITOR 9
|
||||
#define TK_NK_LSHIFT 10
|
||||
#define TK_NK_RSHIFT 11
|
||||
#define TK_NK_PLUS 12
|
||||
#define TK_NK_MINUS 13
|
||||
#define TK_NK_STAR 14
|
||||
#define TK_NK_SLASH 15
|
||||
#define TK_NK_REM 16
|
||||
#define TK_NK_CONCAT 17
|
||||
#define TK_CREATE 18
|
||||
#define TK_DATABASE 19
|
||||
#define TK_IF 20
|
||||
#define TK_NOT 21
|
||||
#define TK_EXISTS 22
|
||||
#define TK_BLOCKS 23
|
||||
#define TK_NK_INTEGER 24
|
||||
#define TK_CACHE 25
|
||||
#define TK_CACHELAST 26
|
||||
#define TK_COMP 27
|
||||
#define TK_DAYS 28
|
||||
#define TK_FSYNC 29
|
||||
#define TK_MAXROWS 30
|
||||
#define TK_MINROWS 31
|
||||
#define TK_KEEP 32
|
||||
#define TK_PRECISION 33
|
||||
#define TK_NK_STRING 34
|
||||
#define TK_QUORUM 35
|
||||
#define TK_REPLICA 36
|
||||
#define TK_TTL 37
|
||||
#define TK_WAL 38
|
||||
#define TK_VGROUPS 39
|
||||
#define TK_SINGLESTABLE 40
|
||||
#define TK_STREAMMODE 41
|
||||
#define TK_NK_FLOAT 42
|
||||
#define TK_NK_BOOL 43
|
||||
#define TK_TIMESTAMP 44
|
||||
#define TK_NK_VARIABLE 45
|
||||
#define TK_NK_COMMA 46
|
||||
#define TK_NK_ID 47
|
||||
#define TK_NK_LP 48
|
||||
#define TK_NK_RP 49
|
||||
#define TK_NK_DOT 50
|
||||
#define TK_BETWEEN 51
|
||||
#define TK_IS 52
|
||||
#define TK_NULL 53
|
||||
#define TK_NK_LT 54
|
||||
#define TK_NK_GT 55
|
||||
#define TK_NK_LE 56
|
||||
#define TK_NK_GE 57
|
||||
#define TK_NK_NE 58
|
||||
#define TK_NK_EQ 59
|
||||
#define TK_LIKE 60
|
||||
#define TK_MATCH 61
|
||||
#define TK_NMATCH 62
|
||||
#define TK_IN 63
|
||||
#define TK_FROM 64
|
||||
#define TK_AS 65
|
||||
#define TK_JOIN 66
|
||||
#define TK_ON 67
|
||||
#define TK_INNER 68
|
||||
#define TK_SELECT 69
|
||||
#define TK_DISTINCT 70
|
||||
#define TK_WHERE 71
|
||||
#define TK_PARTITION 72
|
||||
#define TK_BY 73
|
||||
#define TK_SESSION 74
|
||||
#define TK_STATE_WINDOW 75
|
||||
#define TK_INTERVAL 76
|
||||
#define TK_SLIDING 77
|
||||
#define TK_FILL 78
|
||||
#define TK_VALUE 79
|
||||
#define TK_NONE 80
|
||||
#define TK_PREV 81
|
||||
#define TK_LINEAR 82
|
||||
#define TK_NEXT 83
|
||||
#define TK_GROUP 84
|
||||
#define TK_HAVING 85
|
||||
#define TK_ORDER 86
|
||||
#define TK_SLIMIT 87
|
||||
#define TK_SOFFSET 88
|
||||
#define TK_LIMIT 89
|
||||
#define TK_OFFSET 90
|
||||
#define TK_ASC 91
|
||||
#define TK_DESC 92
|
||||
#define TK_NULLS 93
|
||||
#define TK_FIRST 94
|
||||
#define TK_LAST 95
|
||||
|
||||
#define TK_SPACE 300
|
||||
#define TK_COMMENT 301
|
||||
|
@ -289,6 +121,18 @@
|
|||
#define TK_FILE 306
|
||||
#define TK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query
|
||||
|
||||
#define TK_NK_COLON 500
|
||||
#define TK_NK_BITNOT 501
|
||||
#define TK_INSERT 502
|
||||
#define TK_INTO 503
|
||||
#define TK_NOW 504
|
||||
#define TK_TAGS 505
|
||||
#define TK_USING 506
|
||||
#define TK_VALUES 507
|
||||
#define TK_IMPORT 507
|
||||
#define TK_SEMI 508
|
||||
#define TK_IPTOKEN 509
|
||||
|
||||
#define TK_NIL 65535
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_NODES_SHOW_STMTS_H_
|
||||
#define _TD_NODES_SHOW_STMTS_H_
|
||||
#ifndef _TD_PLANN_NODES_H_
|
||||
#define _TD_PLANN_NODES_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -22,17 +22,35 @@ extern "C" {
|
|||
|
||||
#include "nodes.h"
|
||||
|
||||
typedef enum EShowStmtType {
|
||||
SHOW_TYPE_DATABASE = 1
|
||||
} EShowStmtType;
|
||||
typedef struct SDatabaseOptions {
|
||||
int32_t numOfBlocks;
|
||||
int32_t cacheBlockSize;
|
||||
int8_t cachelast;
|
||||
int32_t compressionLevel;
|
||||
int32_t daysPerFile;
|
||||
int32_t fsyncPeriod;
|
||||
int32_t maxRowsPerBlock;
|
||||
int32_t minRowsPerBlock;
|
||||
int32_t keep;
|
||||
int32_t precision;
|
||||
int32_t quorum;
|
||||
int32_t replica;
|
||||
int32_t ttl;
|
||||
int32_t walLevel;
|
||||
int32_t numOfVgroups;
|
||||
int8_t singleStable;
|
||||
int8_t streamMode;
|
||||
} SDatabaseOptions;
|
||||
|
||||
typedef struct SShowStmt {
|
||||
ENodeType type; // QUERY_NODE_SHOW_STMT
|
||||
EShowStmtType showType;
|
||||
} SShowStmt;
|
||||
typedef struct SCreateDatabaseStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
bool ignoreExists;
|
||||
SDatabaseOptions options;
|
||||
} SCreateDatabaseStmt;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_NODES_SHOW_STMTS_H_*/
|
||||
#endif /*_TD_PLANN_NODES_H_*/
|
|
@ -71,6 +71,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_SELECT_STMT,
|
||||
QUERY_NODE_SHOW_STMT,
|
||||
QUERY_NODE_VNODE_MODIF_STMT,
|
||||
QUERY_NODE_CREATE_DATABASE_STMT,
|
||||
|
||||
// logic plan node
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN,
|
||||
|
|
|
@ -35,11 +35,19 @@ typedef struct SParseContext {
|
|||
struct SCatalog *pCatalog;
|
||||
} SParseContext;
|
||||
|
||||
typedef struct SCmdMsgInfo {
|
||||
int16_t msgType;
|
||||
SEpSet epSet;
|
||||
char* pMsg;
|
||||
int32_t msgLen;
|
||||
} SCmdMsgInfo;
|
||||
|
||||
typedef struct SQuery {
|
||||
bool isCmd;
|
||||
SNode* pRoot;
|
||||
int32_t numOfResCols;
|
||||
SSchema* pResSchema;
|
||||
SCmdMsgInfo* pCmdMsg;
|
||||
} SQuery;
|
||||
|
||||
int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery);
|
||||
|
|
|
@ -338,6 +338,17 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_MAX_DB_CACHE_LAST_ROW 3
|
||||
#define TSDB_DEFAULT_CACHE_LAST_ROW 0
|
||||
|
||||
#define TSDB_MIN_DB_TTL_OPTION 1
|
||||
#define TSDB_DEFAULT_DB_TTL_OPTION 0
|
||||
|
||||
#define TSDB_MIN_DB_SINGLE_STABLE_OPTION 0
|
||||
#define TSDB_MAX_DB_SINGLE_STABLE_OPTION 1
|
||||
#define TSDB_DEFAULT_DB_SINGLE_STABLE_OPTION 0
|
||||
|
||||
#define TSDB_MIN_DB_STREAM_MODE_OPTION 0
|
||||
#define TSDB_MAX_DB_STREAM_MODE_OPTION 1
|
||||
#define TSDB_DEFAULT_DB_STREAM_MODE_OPTION 0
|
||||
|
||||
#define TSDB_MAX_JOIN_TABLE_NUM 10
|
||||
#define TSDB_MAX_UNION_CLAUSE 5
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery) {
|
|||
}
|
||||
|
||||
code = qParseQuerySql(&cxt, pQuery);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (TSDB_CODE_SUCCESS == code && !((*pQuery)->isCmd)) {
|
||||
setResSchemaInfo(&pRequest->body.resInfo, (*pQuery)->pResSchema, (*pQuery)->numOfResCols);
|
||||
}
|
||||
|
||||
|
@ -170,28 +170,16 @@ int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery) {
|
|||
}
|
||||
|
||||
int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
||||
// SDclStmtInfo* pDcl = (SDclStmtInfo*)pQuery;
|
||||
// pRequest->type = pDcl->msgType;
|
||||
// pRequest->body.requestMsg = (SDataBuf){.pData = pDcl->pMsg, .len = pDcl->msgLen, .handle = NULL};
|
||||
SCmdMsgInfo* pMsgInfo = pQuery->pCmdMsg;
|
||||
pRequest->type = pMsgInfo->msgType;
|
||||
pRequest->body.requestMsg = (SDataBuf){.pData = pMsgInfo->pMsg, .len = pMsgInfo->msgLen, .handle = NULL};
|
||||
|
||||
// STscObj* pTscObj = pRequest->pTscObj;
|
||||
// SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest);
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest);
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pMsgInfo->epSet, &transporterId, pSendMsg);
|
||||
|
||||
// int64_t transporterId = 0;
|
||||
// if (pDcl->msgType == TDMT_VND_CREATE_TABLE || pDcl->msgType == TDMT_VND_SHOW_TABLES) {
|
||||
// if (pDcl->msgType == TDMT_VND_SHOW_TABLES) {
|
||||
// SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo;
|
||||
// if (pShowReqInfo->pArray == NULL) {
|
||||
// pShowReqInfo->currentIndex = 0; // set the first vnode/ then iterate the next vnode
|
||||
// pShowReqInfo->pArray = pDcl->pExtension;
|
||||
// }
|
||||
// }
|
||||
// asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pDcl->epSet, &transporterId, pSendMsg);
|
||||
// } else {
|
||||
// asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pDcl->epSet, &transporterId, pSendMsg);
|
||||
// }
|
||||
|
||||
// tsem_wait(&pRequest->body.rspSem);
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -200,6 +200,9 @@ SNode* nodesListGetNode(SNodeList* pList, int32_t index) {
|
|||
}
|
||||
|
||||
void nodesDestroyList(SNodeList* pList) {
|
||||
if (NULL == pList) {
|
||||
return;
|
||||
}
|
||||
SListCell* pNext = pList->pHead;
|
||||
while (NULL != pNext) {
|
||||
pNext = nodesListErase(pList, pNext);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "nodesShowStmts.h"
|
||||
#include "cmdnodes.h"
|
||||
#include "parser.h"
|
||||
#include "querynodes.h"
|
||||
#include "ttoken.h"
|
||||
|
@ -34,6 +34,8 @@ typedef struct SAstCreateContext {
|
|||
|
||||
extern SToken nil_token;
|
||||
|
||||
void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt);
|
||||
|
||||
SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* pNode);
|
||||
SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const SToken* pEnd, SNode* pNode);
|
||||
SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode);
|
||||
|
@ -74,7 +76,33 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit);
|
|||
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
|
||||
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
|
||||
|
||||
SNode* createShowStmt(SAstCreateContext* pCxt, EShowStmtType type);
|
||||
SDatabaseOptions* createDefaultDatabaseOptions(SAstCreateContext* pCxt);
|
||||
|
||||
typedef enum EDatabaseOptionType {
|
||||
DB_OPTION_BLOCKS = 0,
|
||||
DB_OPTION_CACHE,
|
||||
DB_OPTION_CACHELAST,
|
||||
DB_OPTION_COMP,
|
||||
DB_OPTION_DAYS,
|
||||
DB_OPTION_FSYNC,
|
||||
DB_OPTION_MAXROWS,
|
||||
DB_OPTION_MINROWS,
|
||||
DB_OPTION_KEEP,
|
||||
DB_OPTION_PRECISION,
|
||||
DB_OPTION_QUORUM,
|
||||
DB_OPTION_REPLICA,
|
||||
DB_OPTION_TTL,
|
||||
DB_OPTION_WAL,
|
||||
DB_OPTION_VGROUPS,
|
||||
DB_OPTION_SINGLESTABLE,
|
||||
DB_OPTION_STREAMMODE,
|
||||
|
||||
DB_OPTION_MAX
|
||||
} EDatabaseOptionType;
|
||||
|
||||
SDatabaseOptions* setDatabaseOption(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, EDatabaseOptionType type, const SToken* pVal);
|
||||
|
||||
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SDatabaseOptions* pOptions);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
%name NewParse
|
||||
|
||||
%token_prefix NEW_TK_
|
||||
%token_prefix TK_
|
||||
%token_type { SToken }
|
||||
%default_type { SNode* }
|
||||
%default_destructor { PARSER_DESTRUCTOR_TRACE; nodesDestroyNode($$); }
|
||||
|
@ -57,14 +57,44 @@
|
|||
%left AND.
|
||||
//%right NOT.
|
||||
%left UNION ALL MINUS EXCEPT INTERSECT.
|
||||
//%left BITAND BITOR LSHIFT RSHIFT.
|
||||
%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 CONCAT.
|
||||
//%right UMINUS UPLUS BITNOT.
|
||||
%left NK_CONCAT.
|
||||
//%right NK_BITNOT.
|
||||
|
||||
cmd ::= SHOW DATABASES. { PARSER_TRACE; createShowStmt(pCxt, SHOW_TYPE_DATABASE); }
|
||||
/************************************************ create database *****************************************************/
|
||||
cmd ::= CREATE DATABASE exists_opt(A) db_name(B) db_options(C). { PARSER_TRACE; pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C);}
|
||||
|
||||
%type exists_opt { bool }
|
||||
exists_opt(A) ::= IF NOT 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(X)(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) SINGLESTABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLESTABLE, &C); }
|
||||
db_options(A) ::= db_options(B) STREAMMODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAMMODE, &C); }
|
||||
|
||||
//cmd ::= SHOW DATABASES. { PARSER_TRACE; createShowStmt(pCxt, SHOW_TYPE_DATABASE); }
|
||||
|
||||
/************************************************ select *************************************************************/
|
||||
cmd ::= query_expression(A). { PARSER_TRACE; pCxt->pRootNode = A; }
|
||||
|
||||
/************************************************ literal *************************************************************/
|
||||
|
|
|
@ -36,7 +36,7 @@ typedef struct SToken {
|
|||
* @return
|
||||
*/
|
||||
#define isNumber(tk) \
|
||||
((tk)->type == TK_INTEGER || (tk)->type == TK_FLOAT || (tk)->type == TK_HEX || (tk)->type == TK_BIN)
|
||||
((tk)->type == TK_NK_INTEGER || (tk)->type == TK_NK_FLOAT || (tk)->type == TK_HEX || (tk)->type == TK_BIN)
|
||||
|
||||
/**
|
||||
* tokenizer for sql string
|
||||
|
@ -102,7 +102,7 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
|
|||
}
|
||||
}
|
||||
|
||||
type = TK_FLOAT;
|
||||
type = TK_NK_FLOAT;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
|
|||
case '7':
|
||||
case '8':
|
||||
case '9': {
|
||||
type = TK_INTEGER;
|
||||
type = TK_NK_INTEGER;
|
||||
for (; isdigit(z[i]); i++) {
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
|
|||
}
|
||||
|
||||
seg++;
|
||||
type = TK_FLOAT;
|
||||
type = TK_NK_FLOAT;
|
||||
}
|
||||
|
||||
if (seg > 1) {
|
||||
|
@ -158,7 +158,7 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
|
|||
i++;
|
||||
}
|
||||
|
||||
type = TK_FLOAT;
|
||||
type = TK_NK_FLOAT;
|
||||
}
|
||||
|
||||
goto _end;
|
||||
|
|
|
@ -34,6 +34,243 @@
|
|||
|
||||
SToken nil_token = { .type = TK_NIL, .n = 0, .z = NULL };
|
||||
|
||||
typedef SDatabaseOptions* (*FSetDatabaseOption)(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal);
|
||||
|
||||
static FSetDatabaseOption setDbOptionFuncs[DB_OPTION_MAX];
|
||||
|
||||
static SDatabaseOptions* setDbBlocks(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_TOTAL_BLOCKS || val > TSDB_MAX_TOTAL_BLOCKS) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option totalBlocks: %d valid range: [%d, %d]", val, TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->numOfBlocks = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbCache(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option cacheBlockSize: %d valid range: [%d, %d]", val, TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->cacheBlockSize = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbCacheLast(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_DB_CACHE_LAST_ROW || val > TSDB_MAX_DB_CACHE_LAST_ROW) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option cacheLast: %d valid range: [%d, %d]", val, TSDB_MIN_DB_CACHE_LAST_ROW, TSDB_MAX_DB_CACHE_LAST_ROW);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->cachelast = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbComp(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_COMP_LEVEL || val > TSDB_MAX_COMP_LEVEL) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option compression: %d valid range: [%d, %d]", val, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->compressionLevel = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbDays(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_DAYS_PER_FILE || val > TSDB_MAX_DAYS_PER_FILE) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option daysPerFile: %d valid range: [%d, %d]", val, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->daysPerFile = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbFsync(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_FSYNC_PERIOD || val > TSDB_MAX_FSYNC_PERIOD) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option fsyncPeriod: %d valid range: [%d, %d]", val, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->fsyncPeriod = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbMaxRows(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_MAX_ROW_FBLOCK || val > TSDB_MAX_MAX_ROW_FBLOCK) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option maxRowsPerBlock: %d valid range: [%d, %d]", val, TSDB_MIN_MAX_ROW_FBLOCK, TSDB_MAX_MAX_ROW_FBLOCK);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->maxRowsPerBlock = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbMinRows(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_MIN_ROW_FBLOCK || val > TSDB_MAX_MIN_ROW_FBLOCK) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option minRowsPerBlock: %d valid range: [%d, %d]", val, TSDB_MIN_MIN_ROW_FBLOCK, TSDB_MAX_MIN_ROW_FBLOCK);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->minRowsPerBlock = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbKeep(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_KEEP || val > TSDB_MAX_KEEP) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option keep: %d valid range: [%d, %d]", val, TSDB_MIN_KEEP, TSDB_MAX_KEEP);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->keep = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbPrecision(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
if (0 == strncmp(pVal->z, TSDB_TIME_PRECISION_MILLI_STR, pVal->n) && strlen(TSDB_TIME_PRECISION_MILLI_STR) == pVal->n) {
|
||||
pOptions->precision = TSDB_TIME_PRECISION_MILLI;
|
||||
} else if (0 == strncmp(pVal->z, TSDB_TIME_PRECISION_MICRO_STR, pVal->n) && strlen(TSDB_TIME_PRECISION_MICRO_STR) == pVal->n) {
|
||||
pOptions->precision = TSDB_TIME_PRECISION_MICRO;
|
||||
} else if (0 == strncmp(pVal->z, TSDB_TIME_PRECISION_NANO_STR, pVal->n) && strlen(TSDB_TIME_PRECISION_NANO_STR) == pVal->n) {
|
||||
pOptions->precision = TSDB_TIME_PRECISION_NANO;
|
||||
} else {
|
||||
char tmp[10];
|
||||
strncpy(tmp, pVal->z, pVal->n);
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option precision: %s", tmp);
|
||||
pCxt->valid = false;
|
||||
}
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbQuorum(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_DB_QUORUM_OPTION || val > TSDB_MAX_DB_QUORUM_OPTION) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option quorum: %d valid range: [%d, %d]", val, TSDB_MIN_DB_QUORUM_OPTION, TSDB_MAX_DB_QUORUM_OPTION);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->quorum = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbReplica(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_DB_REPLICA_OPTION || val > TSDB_MAX_DB_REPLICA_OPTION) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option replications: %d valid range: [%d, %d]", val, TSDB_MIN_DB_REPLICA_OPTION, TSDB_MAX_DB_REPLICA_OPTION);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->replica = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbTtl(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_DB_TTL_OPTION) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option ttl: %d, should be greater than or equal to %d", val, TSDB_MIN_DB_TTL_OPTION);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->ttl = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbWal(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_WAL_LEVEL || val > TSDB_MAX_WAL_LEVEL) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option walLevel: %d, only 1-2 allowed", val);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->walLevel = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbVgroups(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_VNODES_PER_DB || val > TSDB_MAX_VNODES_PER_DB) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid db option vgroups: %d valid range: [%d, %d]", val, TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->numOfVgroups = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbSingleStable(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_DB_SINGLE_STABLE_OPTION || val > TSDB_MAX_DB_SINGLE_STABLE_OPTION) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option singleStable: %d, only 0-1 allowed", val);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->singleStable = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbStreamMode(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
int64_t val = strtol(pVal->z, NULL, 10);
|
||||
if (val < TSDB_MIN_DB_STREAM_MODE_OPTION || val > TSDB_MAX_DB_STREAM_MODE_OPTION) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option streamMode: %d, only 0-1 allowed", val);
|
||||
pCxt->valid = false;
|
||||
return pOptions;
|
||||
}
|
||||
pOptions->streamMode = val;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static void initSetDatabaseOptionFp() {
|
||||
setDbOptionFuncs[DB_OPTION_BLOCKS] = setDbBlocks;
|
||||
setDbOptionFuncs[DB_OPTION_CACHE] = setDbCache;
|
||||
setDbOptionFuncs[DB_OPTION_CACHELAST] = setDbCacheLast;
|
||||
setDbOptionFuncs[DB_OPTION_COMP] = setDbComp;
|
||||
setDbOptionFuncs[DB_OPTION_DAYS] = setDbDays;
|
||||
setDbOptionFuncs[DB_OPTION_FSYNC] = setDbFsync;
|
||||
setDbOptionFuncs[DB_OPTION_MAXROWS] = setDbMaxRows;
|
||||
setDbOptionFuncs[DB_OPTION_MINROWS] = setDbMinRows;
|
||||
setDbOptionFuncs[DB_OPTION_KEEP] = setDbKeep;
|
||||
setDbOptionFuncs[DB_OPTION_PRECISION] = setDbPrecision;
|
||||
setDbOptionFuncs[DB_OPTION_QUORUM] = setDbQuorum;
|
||||
setDbOptionFuncs[DB_OPTION_REPLICA] = setDbReplica;
|
||||
setDbOptionFuncs[DB_OPTION_TTL] = setDbTtl;
|
||||
setDbOptionFuncs[DB_OPTION_WAL] = setDbWal;
|
||||
setDbOptionFuncs[DB_OPTION_VGROUPS] = setDbVgroups;
|
||||
setDbOptionFuncs[DB_OPTION_SINGLESTABLE] = setDbSingleStable;
|
||||
setDbOptionFuncs[DB_OPTION_STREAMMODE] = setDbStreamMode;
|
||||
}
|
||||
|
||||
void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) {
|
||||
pCxt->pQueryCxt = pParseCxt;
|
||||
pCxt->notSupport = false;
|
||||
pCxt->valid = true;
|
||||
pCxt->pRootNode = NULL;
|
||||
initSetDatabaseOptionFp();
|
||||
}
|
||||
|
||||
static bool checkDbName(SAstCreateContext* pCxt, const SToken* pDbName) {
|
||||
if (NULL == pDbName) {
|
||||
return true;
|
||||
|
@ -376,9 +613,41 @@ SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode*
|
|||
return (SNode*)setOp;
|
||||
}
|
||||
|
||||
SNode* createShowStmt(SAstCreateContext* pCxt, EShowStmtType type) {
|
||||
SShowStmt* show = (SShowStmt*)nodesMakeNode(QUERY_NODE_SHOW_STMT);
|
||||
CHECK_OUT_OF_MEM(show);
|
||||
show->showType = type;
|
||||
return (SNode*)show;
|
||||
SDatabaseOptions* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
|
||||
SDatabaseOptions* pOptions = calloc(1, sizeof(SDatabaseOptions));
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->numOfBlocks = TSDB_DEFAULT_TOTAL_BLOCKS;
|
||||
pOptions->cacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE;
|
||||
pOptions->cachelast = TSDB_DEFAULT_CACHE_LAST_ROW;
|
||||
pOptions->compressionLevel = TSDB_DEFAULT_COMP_LEVEL;
|
||||
pOptions->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE;
|
||||
pOptions->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD;
|
||||
pOptions->maxRowsPerBlock = TSDB_DEFAULT_MAX_ROW_FBLOCK;
|
||||
pOptions->minRowsPerBlock = TSDB_DEFAULT_MIN_ROW_FBLOCK;
|
||||
pOptions->keep = TSDB_DEFAULT_KEEP;
|
||||
pOptions->precision = TSDB_TIME_PRECISION_MILLI;
|
||||
pOptions->quorum = TSDB_DEFAULT_DB_QUORUM_OPTION;
|
||||
pOptions->replica = TSDB_DEFAULT_DB_REPLICA_OPTION;
|
||||
pOptions->ttl = TSDB_DEFAULT_DB_TTL_OPTION;
|
||||
pOptions->walLevel = TSDB_DEFAULT_WAL_LEVEL;
|
||||
pOptions->numOfVgroups = TSDB_DEFAULT_VN_PER_DB;
|
||||
pOptions->singleStable = TSDB_DEFAULT_DB_SINGLE_STABLE_OPTION;
|
||||
pOptions->streamMode = TSDB_DEFAULT_DB_STREAM_MODE_OPTION;
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
SDatabaseOptions* setDatabaseOption(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, EDatabaseOptionType type, const SToken* pVal) {
|
||||
return setDbOptionFuncs[type](pCxt, pOptions, pVal);
|
||||
}
|
||||
|
||||
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SDatabaseOptions* pOptions) {
|
||||
if (!checkDbName(pCxt, pDbName)) {
|
||||
return NULL;
|
||||
}
|
||||
SCreateDatabaseStmt* pStmt = (SCreateDatabaseStmt*)nodesMakeNode(QUERY_NODE_CREATE_DATABASE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strncpy(pStmt->dbName, pDbName->z, pDbName->n);
|
||||
pStmt->ignoreExists = ignoreExists;
|
||||
pStmt->options = *pOptions;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
|
|
@ -26,150 +26,6 @@ extern void NewParse(void*, int, SToken, void*);
|
|||
extern void NewParseFree(void*, FFree);
|
||||
extern void NewParseTrace(FILE*, char*);
|
||||
|
||||
static uint32_t toNewTokenId(uint32_t tokenId) {
|
||||
switch (tokenId) {
|
||||
case TK_OR:
|
||||
return NEW_TK_OR;
|
||||
case TK_AND:
|
||||
return NEW_TK_AND;
|
||||
case TK_UNION:
|
||||
return NEW_TK_UNION;
|
||||
case TK_ALL:
|
||||
return NEW_TK_ALL;
|
||||
case TK_MINUS:
|
||||
return NEW_TK_NK_MINUS;
|
||||
case TK_PLUS:
|
||||
return NEW_TK_NK_PLUS;
|
||||
case TK_STAR:
|
||||
return NEW_TK_NK_STAR;
|
||||
case TK_SLASH:
|
||||
return NEW_TK_NK_SLASH;
|
||||
case TK_REM:
|
||||
return NEW_TK_NK_REM;
|
||||
case TK_SHOW:
|
||||
return NEW_TK_SHOW;
|
||||
case TK_DATABASES:
|
||||
return NEW_TK_DATABASES;
|
||||
case TK_INTEGER:
|
||||
return NEW_TK_NK_INTEGER;
|
||||
case TK_FLOAT:
|
||||
return NEW_TK_NK_FLOAT;
|
||||
case TK_STRING:
|
||||
return NEW_TK_NK_STRING;
|
||||
case TK_BOOL:
|
||||
return NEW_TK_NK_BOOL;
|
||||
case TK_TIMESTAMP:
|
||||
return NEW_TK_TIMESTAMP;
|
||||
case TK_VARIABLE:
|
||||
return NEW_TK_NK_VARIABLE;
|
||||
case TK_COMMA:
|
||||
return NEW_TK_NK_COMMA;
|
||||
case TK_ID:
|
||||
return NEW_TK_NK_ID;
|
||||
case TK_LP:
|
||||
return NEW_TK_NK_LP;
|
||||
case TK_RP:
|
||||
return NEW_TK_NK_RP;
|
||||
case TK_DOT:
|
||||
return NEW_TK_NK_DOT;
|
||||
case TK_BETWEEN:
|
||||
return NEW_TK_BETWEEN;
|
||||
case TK_NOT:
|
||||
return NEW_TK_NOT;
|
||||
case TK_IS:
|
||||
return NEW_TK_IS;
|
||||
case TK_NULL:
|
||||
return NEW_TK_NULL;
|
||||
case TK_LT:
|
||||
return NEW_TK_NK_LT;
|
||||
case TK_GT:
|
||||
return NEW_TK_NK_GT;
|
||||
case TK_LE:
|
||||
return NEW_TK_NK_LE;
|
||||
case TK_GE:
|
||||
return NEW_TK_NK_GE;
|
||||
case TK_NE:
|
||||
return NEW_TK_NK_NE;
|
||||
case TK_EQ:
|
||||
return NEW_TK_NK_EQ;
|
||||
case TK_LIKE:
|
||||
return NEW_TK_LIKE;
|
||||
case TK_MATCH:
|
||||
return NEW_TK_MATCH;
|
||||
case TK_NMATCH:
|
||||
return NEW_TK_NMATCH;
|
||||
case TK_IN:
|
||||
return NEW_TK_IN;
|
||||
case TK_SELECT:
|
||||
return NEW_TK_SELECT;
|
||||
case TK_DISTINCT:
|
||||
return NEW_TK_DISTINCT;
|
||||
case TK_WHERE:
|
||||
return NEW_TK_WHERE;
|
||||
case TK_AS:
|
||||
return NEW_TK_AS;
|
||||
case TK_FROM:
|
||||
return NEW_TK_FROM;
|
||||
case TK_JOIN:
|
||||
return NEW_TK_JOIN;
|
||||
// case TK_PARTITION:
|
||||
// return NEW_TK_PARTITION;
|
||||
case TK_SESSION:
|
||||
return NEW_TK_SESSION;
|
||||
case TK_STATE_WINDOW:
|
||||
return NEW_TK_STATE_WINDOW;
|
||||
case TK_INTERVAL:
|
||||
return NEW_TK_INTERVAL;
|
||||
case TK_SLIDING:
|
||||
return NEW_TK_SLIDING;
|
||||
case TK_FILL:
|
||||
return NEW_TK_FILL;
|
||||
// case TK_VALUE:
|
||||
// return NEW_TK_VALUE;
|
||||
case TK_NONE:
|
||||
return NEW_TK_NONE;
|
||||
case TK_PREV:
|
||||
return NEW_TK_PREV;
|
||||
case TK_LINEAR:
|
||||
return NEW_TK_LINEAR;
|
||||
// case TK_NEXT:
|
||||
// return NEW_TK_NEXT;
|
||||
case TK_GROUP:
|
||||
return NEW_TK_GROUP;
|
||||
case TK_HAVING:
|
||||
return NEW_TK_HAVING;
|
||||
case TK_ORDER:
|
||||
return NEW_TK_ORDER;
|
||||
case TK_BY:
|
||||
return NEW_TK_BY;
|
||||
case TK_ASC:
|
||||
return NEW_TK_ASC;
|
||||
case TK_DESC:
|
||||
return NEW_TK_DESC;
|
||||
case TK_SLIMIT:
|
||||
return NEW_TK_SLIMIT;
|
||||
case TK_SOFFSET:
|
||||
return NEW_TK_SOFFSET;
|
||||
case TK_LIMIT:
|
||||
return NEW_TK_LIMIT;
|
||||
case TK_OFFSET:
|
||||
return NEW_TK_OFFSET;
|
||||
case TK_SPACE:
|
||||
case NEW_TK_ON:
|
||||
case NEW_TK_INNER:
|
||||
break;
|
||||
default:
|
||||
printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!tokenId = %d\n", tokenId);
|
||||
}
|
||||
return tokenId;
|
||||
}
|
||||
|
||||
static uint32_t getToken(const char* z, uint32_t* tokenId) {
|
||||
uint32_t n = tGetToken(z, tokenId);
|
||||
*tokenId = toNewTokenId(*tokenId);
|
||||
return n;
|
||||
}
|
||||
|
||||
static bool isCmd(const SNode* pRootNode) {
|
||||
if (NULL == pRootNode) {
|
||||
return true;
|
||||
|
@ -184,7 +40,8 @@ static bool isCmd(const SNode* pRootNode) {
|
|||
}
|
||||
|
||||
int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
|
||||
SAstCreateContext cxt = { .pQueryCxt = pParseCxt, .notSupport = false, .valid = true, .pRootNode = NULL};
|
||||
SAstCreateContext cxt;
|
||||
initAstCreateContext(pParseCxt, &cxt);
|
||||
void *pParser = NewParseAlloc(malloc);
|
||||
int32_t i = 0;
|
||||
while (1) {
|
||||
|
@ -193,7 +50,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
|
|||
NewParse(pParser, 0, t0, &cxt);
|
||||
goto abort_parse;
|
||||
}
|
||||
t0.n = getToken((char *)&cxt.pQueryCxt->pSql[i], &t0.type);
|
||||
t0.n = tGetToken((char *)&cxt.pQueryCxt->pSql[i], &t0.type);
|
||||
t0.z = (char *)(cxt.pQueryCxt->pSql + i);
|
||||
i += t0.n;
|
||||
|
||||
|
@ -202,10 +59,6 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
|
|||
case TK_COMMENT: {
|
||||
break;
|
||||
}
|
||||
case TK_SEMI: {
|
||||
NewParse(pParser, 0, t0, &cxt);
|
||||
goto abort_parse;
|
||||
}
|
||||
case TK_QUESTION:
|
||||
case TK_ILLEGAL: {
|
||||
snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unrecognized token: \"%s\"", t0.z);
|
||||
|
@ -221,7 +74,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
|
|||
}
|
||||
default:
|
||||
NewParse(pParser, t0.type, t0, &cxt);
|
||||
// NewParseTrace(stdout, "");
|
||||
NewParseTrace(stdout, "");
|
||||
if (!cxt.valid) {
|
||||
goto abort_parse;
|
||||
}
|
||||
|
@ -232,6 +85,9 @@ abort_parse:
|
|||
NewParseFree(pParser, free);
|
||||
if (cxt.valid) {
|
||||
*pQuery = calloc(1, sizeof(SQuery));
|
||||
if (NULL == *pQuery) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
(*pQuery)->isCmd = isCmd(cxt.pRootNode);
|
||||
(*pQuery)->pRoot = cxt.pRootNode;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "parserInt.h"
|
||||
|
||||
#include "catalog.h"
|
||||
#include "cmdnodes.h"
|
||||
#include "functionMgt.h"
|
||||
#include "parserUtil.h"
|
||||
#include "ttime.h"
|
||||
|
@ -36,6 +37,7 @@ typedef struct STranslateContext {
|
|||
int32_t currLevel;
|
||||
ESqlClause currClause;
|
||||
SSelectStmt* pCurrStmt;
|
||||
SCmdMsgInfo* pCmdMsg;
|
||||
} STranslateContext;
|
||||
|
||||
static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode);
|
||||
|
@ -278,9 +280,12 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) {
|
|||
return found ? DEAL_RES_CONTINUE : translateColumnWithoutPrefix(pCxt, pCol);
|
||||
}
|
||||
|
||||
static int32_t trimStringCopy(const char* src, int32_t len, char* dst) {
|
||||
varDataSetLen(dst, len);
|
||||
char* dstVal = varDataVal(dst);
|
||||
static int32_t trimStringCopy(const char* src, int32_t len, bool format, char* dst) {
|
||||
char* dstVal = dst;
|
||||
if (format) {
|
||||
varDataSetLen(dst, len);
|
||||
dstVal = varDataVal(dst);
|
||||
}
|
||||
// delete escape character: \\, \', \"
|
||||
char delim = src[0];
|
||||
int32_t cnt = 0;
|
||||
|
@ -346,7 +351,7 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
|
|||
generateSyntaxErrMsg(pCxt, TSDB_CODE_OUT_OF_MEMORY);
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
trimStringCopy(pVal->literal, n, pVal->datum.p);
|
||||
trimStringCopy(pVal->literal, n, true, pVal->datum.p);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
|
@ -356,7 +361,7 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
|
|||
generateSyntaxErrMsg(pCxt, TSDB_CODE_OUT_OF_MEMORY);
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
int32_t len = trimStringCopy(pVal->literal, n, tmp);
|
||||
int32_t len = trimStringCopy(pVal->literal, n, false, tmp);
|
||||
if (taosParseTime(tmp, &pVal->datum.i, len, pVal->node.resType.precision, tsDaylight) != TSDB_CODE_SUCCESS) {
|
||||
tfree(tmp);
|
||||
generateSyntaxErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal);
|
||||
|
@ -777,12 +782,62 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static void buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt, SCreateDbReq* pReq) {
|
||||
SName name = {0};
|
||||
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
|
||||
tNameGetFullDbName(&name, pReq->db);
|
||||
pReq->numOfVgroups = pStmt->options.numOfVgroups;
|
||||
pReq->cacheBlockSize = pStmt->options.cacheBlockSize;
|
||||
pReq->totalBlocks = pStmt->options.numOfBlocks;
|
||||
pReq->daysPerFile = pStmt->options.daysPerFile;
|
||||
pReq->daysToKeep0 = pStmt->options.keep;
|
||||
pReq->daysToKeep1 = -1;
|
||||
pReq->daysToKeep2 = -1;
|
||||
pReq->minRows = pStmt->options.minRowsPerBlock;
|
||||
pReq->maxRows = pStmt->options.maxRowsPerBlock;
|
||||
pReq->commitTime = -1;
|
||||
pReq->fsyncPeriod = pStmt->options.fsyncPeriod;
|
||||
pReq->walLevel = pStmt->options.walLevel;
|
||||
pReq->precision = pStmt->options.precision;
|
||||
pReq->compression = pStmt->options.compressionLevel;
|
||||
pReq->replications = pStmt->options.replica;
|
||||
pReq->quorum = pStmt->options.quorum;
|
||||
pReq->update = -1;
|
||||
pReq->cacheLastRow = pStmt->options.cachelast;
|
||||
pReq->ignoreExist = pStmt->ignoreExists;
|
||||
pReq->streamMode = pStmt->options.streamMode;
|
||||
return;
|
||||
}
|
||||
|
||||
static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt) {
|
||||
SCreateDbReq createReq = {0};
|
||||
buildCreateDbReq(pCxt, pStmt, &createReq);
|
||||
|
||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||
if (NULL== pCxt->pCmdMsg) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||
pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DB;
|
||||
pCxt->pCmdMsg->msgLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
|
||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
tSerializeSCreateDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pNode)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
code = translateSelect(pCxt, (SSelectStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_CREATE_DATABASE_STMT:
|
||||
code = translateCreateDatabase(pCxt, (SCreateDatabaseStmt*)pNode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -820,6 +875,14 @@ int32_t setReslutSchema(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void destroyTranslateContext(STranslateContext* pCxt) {
|
||||
taosArrayDestroy(pCxt->pNsLevel);
|
||||
if (NULL != pCxt->pCmdMsg) {
|
||||
tfree(pCxt->pCmdMsg->pMsg);
|
||||
tfree(pCxt->pCmdMsg);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t doTranslate(SParseContext* pParseCxt, SQuery* pQuery) {
|
||||
STranslateContext cxt = {
|
||||
.pParseCxt = pParseCxt,
|
||||
|
@ -833,8 +896,14 @@ int32_t doTranslate(SParseContext* pParseCxt, SQuery* pQuery) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateQuery(&cxt, pQuery->pRoot);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && !pQuery->isCmd) {
|
||||
code = setReslutSchema(&cxt, pQuery);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (pQuery->isCmd) {
|
||||
pQuery->pCmdMsg = cxt.pCmdMsg;
|
||||
cxt.pCmdMsg = NULL;
|
||||
} else {
|
||||
code = setReslutSchema(&cxt, pQuery);
|
||||
}
|
||||
}
|
||||
destroyTranslateContext(&cxt);
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -263,7 +263,7 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time
|
|||
|
||||
if (pToken->type == TK_NOW) {
|
||||
ts = taosGetTimestamp(timePrec);
|
||||
} else if (pToken->type == TK_INTEGER) {
|
||||
} else if (pToken->type == TK_NK_INTEGER) {
|
||||
bool isSigned = false;
|
||||
toInteger(pToken->z, pToken->n, 10, &ts, &isSigned);
|
||||
} else { // parse the RFC-3339/ISO-8601 timestamp format string
|
||||
|
@ -294,7 +294,7 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time
|
|||
sToken = tStrGetToken(pTokenEnd, &index, false);
|
||||
pTokenEnd += index;
|
||||
|
||||
if (sToken.type == TK_MINUS || sToken.type == TK_PLUS) {
|
||||
if (sToken.type == TK_MINUS || sToken.type == TK_NK_PLUS) {
|
||||
index = 0;
|
||||
valueToken = tStrGetToken(pTokenEnd, &index, false);
|
||||
pTokenEnd += index;
|
||||
|
@ -308,7 +308,7 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time
|
|||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
if (sToken.type == TK_PLUS) {
|
||||
if (sToken.type == TK_NK_PLUS) {
|
||||
ts += interval;
|
||||
} else {
|
||||
ts = ts - interval;
|
||||
|
@ -322,9 +322,9 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t checkAndTrimValue(SToken* pToken, uint32_t type, char* tmpTokenBuf, SMsgBuf* pMsgBuf) {
|
||||
if ((pToken->type != TK_NOW && pToken->type != TK_INTEGER && pToken->type != TK_STRING && pToken->type != TK_FLOAT && pToken->type != TK_BOOL &&
|
||||
if ((pToken->type != TK_NOW && pToken->type != TK_NK_INTEGER && pToken->type != TK_NK_STRING && pToken->type != TK_NK_FLOAT && pToken->type != TK_NK_BOOL &&
|
||||
pToken->type != TK_NULL && pToken->type != TK_HEX && pToken->type != TK_OCT && pToken->type != TK_BIN) ||
|
||||
(pToken->n == 0) || (pToken->type == TK_RP)) {
|
||||
(pToken->n == 0) || (pToken->type == TK_NK_RP)) {
|
||||
return buildSyntaxErrMsg(pMsgBuf, "invalid data or symbol", pToken->z);
|
||||
}
|
||||
|
||||
|
@ -363,7 +363,7 @@ static FORCE_INLINE int32_t checkAndTrimValue(SToken* pToken, uint32_t type, cha
|
|||
}
|
||||
|
||||
static bool isNullStr(SToken *pToken) {
|
||||
return (pToken->type == TK_NULL) || ((pToken->type == TK_STRING) && (pToken->n != 0) &&
|
||||
return (pToken->type == TK_NULL) || ((pToken->type == TK_NK_STRING) && (pToken->n != 0) &&
|
||||
(strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0));
|
||||
}
|
||||
|
||||
|
@ -400,7 +400,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
|
||||
switch (pSchema->type) {
|
||||
case TSDB_DATA_TYPE_BOOL: {
|
||||
if ((pToken->type == TK_BOOL || pToken->type == TK_STRING) && (pToken->n != 0)) {
|
||||
if ((pToken->type == TK_NK_BOOL || pToken->type == TK_NK_STRING) && (pToken->n != 0)) {
|
||||
if (strncmp(pToken->z, "true", pToken->n) == 0) {
|
||||
return func(&TRUE_VALUE, pSchema->bytes, param);
|
||||
} else if (strncmp(pToken->z, "false", pToken->n) == 0) {
|
||||
|
@ -408,9 +408,9 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
} else {
|
||||
return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z);
|
||||
}
|
||||
} else if (pToken->type == TK_INTEGER) {
|
||||
} else if (pToken->type == TK_NK_INTEGER) {
|
||||
return func(((strtoll(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param);
|
||||
} else if (pToken->type == TK_FLOAT) {
|
||||
} else if (pToken->type == TK_NK_FLOAT) {
|
||||
return func(((strtod(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param);
|
||||
} else {
|
||||
return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z);
|
||||
|
@ -592,7 +592,7 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo*
|
|||
while (1) {
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
|
||||
if (TK_RP == sToken.type) {
|
||||
if (TK_NK_RP == sToken.type) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -692,7 +692,7 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken)
|
|||
|
||||
// pSql -> [(tag1_name, ...)] TAGS (tag1_value, ...)
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
if (TK_LP == sToken.type) {
|
||||
if (TK_NK_LP == sToken.type) {
|
||||
CHECK_CODE(parseBoundColumns(pCxt, &pCxt->tags, pTagsSchema));
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
}
|
||||
|
@ -702,7 +702,7 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken)
|
|||
}
|
||||
// pSql -> (tag1_value, ...)
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
if (TK_LP != sToken.type) {
|
||||
if (TK_NK_LP != sToken.type) {
|
||||
return buildSyntaxErrMsg(&pCxt->msg, "( is expected", sToken.z);
|
||||
}
|
||||
CHECK_CODE(parseTagsClause(pCxt, pTagsSchema, getTableInfo(pCxt->pTableMeta).precision));
|
||||
|
@ -766,7 +766,7 @@ static int32_t parseValues(SInsertParseContext* pCxt, STableDataBlocks* pDataBlo
|
|||
while (1) {
|
||||
int32_t index = 0;
|
||||
NEXT_TOKEN_KEEP_SQL(pCxt->pSql, sToken, index);
|
||||
if (TK_LP != sToken.type) {
|
||||
if (TK_NK_LP != sToken.type) {
|
||||
break;
|
||||
}
|
||||
pCxt->pSql += index;
|
||||
|
@ -783,7 +783,7 @@ static int32_t parseValues(SInsertParseContext* pCxt, STableDataBlocks* pDataBlo
|
|||
pDataBlock->size += extendedRowSize; //len;
|
||||
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
if (TK_RP != sToken.type) {
|
||||
if (TK_NK_RP != sToken.type) {
|
||||
return buildSyntaxErrMsg(&pCxt->msg, ") expected", sToken.z);
|
||||
}
|
||||
|
||||
|
@ -882,7 +882,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
|||
CHECK_CODE(getDataBlockFromList(pCxt->pTableBlockHashObj, pCxt->pTableMeta->uid, TSDB_DEFAULT_PAYLOAD_SIZE,
|
||||
sizeof(SSubmitBlk), getTableInfo(pCxt->pTableMeta).rowSize, pCxt->pTableMeta, &dataBuf, NULL));
|
||||
|
||||
if (TK_LP == sToken.type) {
|
||||
if (TK_NK_LP == sToken.type) {
|
||||
// pSql -> field1_name, ...)
|
||||
CHECK_CODE(parseBoundColumns(pCxt, &dataBuf->boundColumnInfo, getTableColumnSchema(pCxt->pTableMeta)));
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
|
@ -899,7 +899,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
|||
if (TK_FILE == sToken.type) {
|
||||
// pSql -> csv_file_path
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
if (0 == sToken.n || (TK_STRING != sToken.type && TK_ID != sToken.type)) {
|
||||
if (0 == sToken.n || (TK_NK_STRING != sToken.type && TK_NK_ID != sToken.type)) {
|
||||
return buildSyntaxErrMsg(&pCxt->msg, "file path is required following keyword FILE", sToken.z);
|
||||
}
|
||||
// todo
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,257 +13,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include "astGenerator.h"
|
||||
#include "parserInt.h"
|
||||
#include "parserUtil.h"
|
||||
#include "ttoken.h"
|
||||
#include "function.h"
|
||||
#include "insertParser.h"
|
||||
|
||||
bool isInsertSql(const char* pStr, size_t length) {
|
||||
int32_t index = 0;
|
||||
|
||||
do {
|
||||
SToken t0 = tStrGetToken((char*) pStr, &index, false);
|
||||
if (t0.type != TK_LP) {
|
||||
return t0.type == TK_INSERT || t0.type == TK_IMPORT;
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
|
||||
bool qIsDdlQuery(const SQueryNode* pQueryNode) {
|
||||
return TSDB_SQL_INSERT != pQueryNode->type && TSDB_SQL_SELECT != pQueryNode->type && TSDB_SQL_CREATE_TABLE != pQueryNode->type;
|
||||
}
|
||||
|
||||
int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SSqlInfo info = doGenerateAST(pCxt->pSql);
|
||||
if (!info.valid) {
|
||||
strncpy(pCxt->pMsg, info.msg, pCxt->msgLen);
|
||||
code = TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!isDqlSqlStatement(&info)) {
|
||||
if (info.type == TSDB_SQL_CREATE_TABLE) {
|
||||
SVnodeModifOpStmtInfo * pModifStmtInfo = qParserValidateCreateTbSqlNode(&info, pCxt, pCxt->pMsg, pCxt->msgLen);
|
||||
if (pModifStmtInfo == NULL) {
|
||||
code = terrno;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
*pQuery = (SQueryNode*)pModifStmtInfo;
|
||||
} else {
|
||||
SDclStmtInfo* pDcl = qParserValidateDclSqlNode(&info, pCxt, pCxt->pMsg, pCxt->msgLen);
|
||||
if (pDcl == NULL) {
|
||||
code = terrno;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
*pQuery = (SQueryNode*)pDcl;
|
||||
pDcl->nodeType = info.type;
|
||||
}
|
||||
} else {
|
||||
SQueryStmtInfo* pQueryInfo = createQueryInfo();
|
||||
if (pQueryInfo == NULL) {
|
||||
code = TSDB_CODE_QRY_OUT_OF_MEMORY; // set correct error code.
|
||||
goto _end;
|
||||
}
|
||||
|
||||
code = qParserValidateSqlNode(pCxt, &info, pQueryInfo, pCxt->pMsg, pCxt->msgLen);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
*pQuery = (SQueryNode*)pQueryInfo;
|
||||
} else {
|
||||
goto _end;
|
||||
}
|
||||
}
|
||||
|
||||
_end:
|
||||
destroySqlInfo(&info);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t qParseQuerySql(SParseContext* pCxt, SQueryNode** pQueryNode) {
|
||||
if (isInsertSql(pCxt->pSql, pCxt->sqlLen)) {
|
||||
return parseInsertSql(pCxt, (SVnodeModifOpStmtInfo**)pQueryNode);
|
||||
} else {
|
||||
return parseQuerySql(pCxt, pQueryNode);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t qParserConvertSql(const char* pStr, size_t length, char** pConvertSql) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t getTableNameFromSqlNode(SSqlNode* pSqlNode, SArray* tableNameList, SParseContext *pCtx, SMsgBuf* pMsgBuf);
|
||||
|
||||
static int32_t tnameComparFn(const void* p1, const void* p2) {
|
||||
SName* pn1 = (SName*)p1;
|
||||
SName* pn2 = (SName*)p2;
|
||||
|
||||
int32_t ret = pn1->acctId - pn2->acctId;
|
||||
if (ret != 0) {
|
||||
return ret > 0? 1:-1;
|
||||
} else {
|
||||
ret = strncmp(pn1->dbname, pn2->dbname, tListLen(pn1->dbname));
|
||||
if (ret != 0) {
|
||||
return ret > 0? 1:-1;
|
||||
} else {
|
||||
ret = strncmp(pn1->tname, pn2->tname, tListLen(pn1->tname));
|
||||
if (ret != 0) {
|
||||
return ret > 0? 1:-1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t getTableNameFromSubquery(SSqlNode* pSqlNode, SArray* tableNameList, SParseContext *pCtx, SMsgBuf* pMsgBuf) {
|
||||
int32_t numOfSub = (int32_t)taosArrayGetSize(pSqlNode->from->list);
|
||||
|
||||
for (int32_t j = 0; j < numOfSub; ++j) {
|
||||
SRelElement* sub = taosArrayGet(pSqlNode->from->list, j);
|
||||
|
||||
int32_t num = (int32_t)taosArrayGetSize(sub->pSubquery->node);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SSqlNode* p = taosArrayGetP(sub->pSubquery->node, i);
|
||||
if (p->from->type == SQL_FROM_NODE_TABLES) {
|
||||
int32_t code = getTableNameFromSqlNode(p, tableNameList, pCtx, pMsgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
getTableNameFromSubquery(p, tableNameList, pCtx, pMsgBuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t getTableNameFromSqlNode(SSqlNode* pSqlNode, SArray* tableNameList, SParseContext *pParseCtx, SMsgBuf* pMsgBuf) {
|
||||
const char* msg1 = "invalid table name";
|
||||
|
||||
int32_t numOfTables = (int32_t) taosArrayGetSize(pSqlNode->from->list);
|
||||
assert(pSqlNode->from->type == SQL_FROM_NODE_TABLES);
|
||||
|
||||
for(int32_t j = 0; j < numOfTables; ++j) {
|
||||
SRelElement* item = taosArrayGet(pSqlNode->from->list, j);
|
||||
|
||||
SToken* t = &item->tableName;
|
||||
if (t->type == TK_INTEGER || t->type == TK_FLOAT || t->type == TK_STRING) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
if (parserValidateIdToken(t) != TSDB_CODE_SUCCESS) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
SName name = {0};
|
||||
int32_t code = createSName(&name, t, pParseCtx, pMsgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
taosArrayPush(tableNameList, &name);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void freePtrElem(void* p) {
|
||||
tfree(*(char**)p);
|
||||
}
|
||||
|
||||
int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SCatalogReq* pMetaInfo, SParseContext *pCtx, char* msg, int32_t msgBufLen) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SMsgBuf msgBuf = {.buf = msg, .len = msgBufLen};
|
||||
|
||||
pMetaInfo->pTableName = taosArrayInit(4, sizeof(SName));
|
||||
pMetaInfo->pUdf = taosArrayInit(4, POINTER_BYTES);
|
||||
|
||||
size_t size = taosArrayGetSize(pSqlInfo->sub.node);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlNode* pSqlNode = taosArrayGetP(pSqlInfo->sub.node, i);
|
||||
if (pSqlNode->from == NULL) {
|
||||
return buildInvalidOperationMsg(&msgBuf, "invalid from clause");
|
||||
}
|
||||
|
||||
// load the table meta in the FROM clause
|
||||
if (pSqlNode->from->type == SQL_FROM_NODE_TABLES) {
|
||||
code = getTableNameFromSqlNode(pSqlNode, pMetaInfo->pTableName, pCtx, &msgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
code = getTableNameFromSubquery(pSqlNode, pMetaInfo->pTableName, pCtx, &msgBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
taosArraySort(pMetaInfo->pTableName, tnameComparFn);
|
||||
taosArrayRemoveDuplicate(pMetaInfo->pTableName, tnameComparFn, NULL);
|
||||
|
||||
size_t funcSize = 0;
|
||||
if (pSqlInfo->funcs) {
|
||||
funcSize = taosArrayGetSize(pSqlInfo->funcs);
|
||||
}
|
||||
|
||||
if (funcSize > 0) {
|
||||
for (size_t i = 0; i < funcSize; ++i) {
|
||||
SToken* t = taosArrayGet(pSqlInfo->funcs, i);
|
||||
assert(t != NULL);
|
||||
|
||||
if (t->n >= TSDB_FUNC_NAME_LEN) {
|
||||
return buildSyntaxErrMsg(&msgBuf, "too long function name", t->z);
|
||||
}
|
||||
|
||||
// Let's assume that it is an UDF/UDAF, if it is not a built-in function.
|
||||
bool scalarFunc = false;
|
||||
if (qIsBuiltinFunction(t->z, t->n, &scalarFunc) < 0) {
|
||||
char* fname = strndup(t->z, t->n);
|
||||
taosArrayPush(pMetaInfo->pUdf, &fname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void qParserCleanupMetaRequestInfo(SCatalogReq* pMetaReq) {
|
||||
if (pMetaReq == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosArrayDestroy(pMetaReq->pTableName);
|
||||
taosArrayDestroy(pMetaReq->pUdf);
|
||||
}
|
||||
|
||||
void qDestroyQuery(SQueryNode* pQueryNode) {
|
||||
if (NULL == pQueryNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t type = queryNodeType(pQueryNode);
|
||||
if (type == TSDB_SQL_INSERT || type == TSDB_SQL_CREATE_TABLE) {
|
||||
SVnodeModifOpStmtInfo* pModifInfo = (SVnodeModifOpStmtInfo*)pQueryNode;
|
||||
taosArrayDestroy(pModifInfo->pDataBlocks);
|
||||
|
||||
tfree(pQueryNode);
|
||||
} else if (type == TSDB_SQL_SELECT) {
|
||||
SQueryStmtInfo* pQueryStmtInfo = (SQueryStmtInfo*) pQueryNode;
|
||||
destroyQueryInfo(pQueryStmtInfo);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
#include "insertParser.h"
|
||||
|
@ -275,7 +24,7 @@ static bool isInsertSql(const char* pStr, size_t length) {
|
|||
|
||||
do {
|
||||
SToken t0 = tStrGetToken((char*) pStr, &index, false);
|
||||
if (t0.type != TK_LP) {
|
||||
if (t0.type != TK_NK_LP) {
|
||||
return t0.type == TK_INSERT || t0.type == TK_IMPORT;
|
||||
}
|
||||
} while (1);
|
||||
|
@ -300,5 +49,3 @@ int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery) {
|
|||
void qDestroyQuery(SQuery* pQueryNode) {
|
||||
// todo
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,7 +46,7 @@ int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char*
|
|||
}
|
||||
|
||||
int32_t parserValidateIdToken(SToken* pToken) {
|
||||
if (pToken == NULL || pToken->z == NULL || pToken->type != TK_ID) {
|
||||
if (pToken == NULL || pToken->z == NULL || pToken->type != TK_NK_ID) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ int32_t parserValidateIdToken(SToken* pToken) {
|
|||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
if (pToken->type != TK_ID) {
|
||||
if (pToken->type != TK_NK_ID) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ int32_t parserValidateIdToken(SToken* pToken) {
|
|||
pToken->z = sep + 1;
|
||||
pToken->n = (uint32_t)(oldLen - (sep - pStr) - 1);
|
||||
int32_t len = tGetToken(pToken->z, &pToken->type);
|
||||
if (len != pToken->n || pToken->type != TK_ID) {
|
||||
if (len != pToken->n || pToken->type != TK_NK_ID) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,91 +29,91 @@ typedef struct SKeyword {
|
|||
|
||||
// keywords in sql string
|
||||
static SKeyword keywordTable[] = {
|
||||
{"ID", TK_ID},
|
||||
{"BOOL", TK_BOOL},
|
||||
// {"ID", TK_ID},
|
||||
// {"BOOL", TK_BOOL},
|
||||
// {"TINYINT", TK_TINYINT},
|
||||
// {"SMALLINT", TK_SMALLINT},
|
||||
{"INTEGER", TK_INTEGER},
|
||||
{"INT", TK_INTEGER},
|
||||
// {"INTEGER", TK_INTEGER},
|
||||
// {"INT", TK_INTEGER},
|
||||
// {"BIGINT", TK_BIGINT},
|
||||
{"FLOAT", TK_FLOAT},
|
||||
// {"FLOAT", TK_FLOAT},
|
||||
// {"DOUBLE", TK_DOUBLE},
|
||||
{"STRING", TK_STRING},
|
||||
// {"STRING", TK_STRING},
|
||||
{"TIMESTAMP", TK_TIMESTAMP},
|
||||
// {"BINARY", TK_BINARY},
|
||||
// {"NCHAR", TK_NCHAR},
|
||||
{"OR", TK_OR},
|
||||
{"AND", TK_AND},
|
||||
{"NOT", TK_NOT},
|
||||
{"EQ", TK_EQ},
|
||||
{"NE", TK_NE},
|
||||
{"ISNULL", TK_ISNULL},
|
||||
{"NOTNULL", TK_NOTNULL},
|
||||
// {"EQ", TK_EQ},
|
||||
// {"NE", TK_NE},
|
||||
// {"ISNULL", TK_ISNULL},
|
||||
// {"NOTNULL", TK_NOTNULL},
|
||||
{"IS", TK_IS},
|
||||
{"LIKE", TK_LIKE},
|
||||
{"MATCH", TK_MATCH},
|
||||
{"GLOB", TK_GLOB},
|
||||
// {"GLOB", TK_GLOB},
|
||||
{"BETWEEN", TK_BETWEEN},
|
||||
{"IN", TK_IN},
|
||||
{"GT", TK_GT},
|
||||
{"GE", TK_GE},
|
||||
{"LT", TK_LT},
|
||||
{"LE", TK_LE},
|
||||
{"BITAND", TK_BITAND},
|
||||
{"BITOR", TK_BITOR},
|
||||
{"LSHIFT", TK_LSHIFT},
|
||||
{"RSHIFT", TK_RSHIFT},
|
||||
{"PLUS", TK_PLUS},
|
||||
// {"GT", TK_GT},
|
||||
// {"GE", TK_GE},
|
||||
// {"LT", TK_LT},
|
||||
// {"LE", TK_LE},
|
||||
// {"BITAND", TK_BITAND},
|
||||
// {"BITOR", TK_BITOR},
|
||||
// {"LSHIFT", TK_LSHIFT},
|
||||
// {"RSHIFT", TK_RSHIFT},
|
||||
// {"PLUS", TK_PLUS},
|
||||
{"MINUS", TK_MINUS},
|
||||
{"DIVIDE", TK_DIVIDE},
|
||||
{"TIMES", TK_TIMES},
|
||||
{"STAR", TK_STAR},
|
||||
{"SLASH", TK_SLASH},
|
||||
{"REM ", TK_REM},
|
||||
{"||", TK_CONCAT},
|
||||
{"UMINUS", TK_UMINUS},
|
||||
{"UPLUS", TK_UPLUS},
|
||||
{"BITNOT", TK_BITNOT},
|
||||
{"SHOW", TK_SHOW},
|
||||
{"DATABASES", TK_DATABASES},
|
||||
{"MNODES", TK_MNODES},
|
||||
{"DNODES", TK_DNODES},
|
||||
{"ACCOUNTS", TK_ACCOUNTS},
|
||||
{"USERS", TK_USERS},
|
||||
{"MODULES", TK_MODULES},
|
||||
{"QUERIES", TK_QUERIES},
|
||||
{"CONNECTIONS", TK_CONNECTIONS},
|
||||
{"STREAMS", TK_STREAMS},
|
||||
{"VARIABLES", TK_VARIABLES},
|
||||
{"SCORES", TK_SCORES},
|
||||
{"GRANTS", TK_GRANTS},
|
||||
{"DOT", TK_DOT},
|
||||
{"TABLES", TK_TABLES},
|
||||
{"STABLES", TK_STABLES},
|
||||
// {"DIVIDE", TK_DIVIDE},
|
||||
// {"TIMES", TK_TIMES},
|
||||
// {"STAR", TK_STAR},
|
||||
// {"SLASH", TK_SLASH},
|
||||
// {"REM ", TK_REM},
|
||||
// {"||", TK_CONCAT},
|
||||
// {"UMINUS", TK_UMINUS},
|
||||
// {"UPLUS", TK_UPLUS},
|
||||
// {"BITNOT", TK_BITNOT},
|
||||
// {"SHOW", TK_SHOW},
|
||||
// {"DATABASES", TK_DATABASES},
|
||||
// {"MNODES", TK_MNODES},
|
||||
// {"DNODES", TK_DNODES},
|
||||
// {"ACCOUNTS", TK_ACCOUNTS},
|
||||
// {"USERS", TK_USERS},
|
||||
// {"MODULES", TK_MODULES},
|
||||
// {"QUERIES", TK_QUERIES},
|
||||
// {"CONNECTIONS", TK_CONNECTIONS},
|
||||
// {"STREAMS", TK_STREAMS},
|
||||
// {"VARIABLES", TK_VARIABLES},
|
||||
// {"SCORES", TK_SCORES},
|
||||
// {"GRANTS", TK_GRANTS},
|
||||
// {"DOT", TK_DOT},
|
||||
// {"TABLES", TK_TABLES},
|
||||
// {"STABLES", TK_STABLES},
|
||||
{"VGROUPS", TK_VGROUPS},
|
||||
{"DROP", TK_DROP},
|
||||
{"TABLE", TK_TABLE},
|
||||
// {"DROP", TK_DROP},
|
||||
// {"TABLE", TK_TABLE},
|
||||
{"DATABASE", TK_DATABASE},
|
||||
{"DNODE", TK_DNODE},
|
||||
{"USER", TK_USER},
|
||||
{"ACCOUNT", TK_ACCOUNT},
|
||||
{"USE", TK_USE},
|
||||
{"DESCRIBE", TK_DESCRIBE},
|
||||
{"SYNCDB", TK_SYNCDB},
|
||||
{"ALTER", TK_ALTER},
|
||||
{"PASS", TK_PASS},
|
||||
{"PRIVILEGE", TK_PRIVILEGE},
|
||||
{"LOCAL", TK_LOCAL},
|
||||
// {"DNODE", TK_DNODE},
|
||||
// {"USER", TK_USER},
|
||||
// {"ACCOUNT", TK_ACCOUNT},
|
||||
// {"USE", TK_USE},
|
||||
// {"DESCRIBE", TK_DESCRIBE},
|
||||
// {"SYNCDB", TK_SYNCDB},
|
||||
// {"ALTER", TK_ALTER},
|
||||
// {"PASS", TK_PASS},
|
||||
// {"PRIVILEGE", TK_PRIVILEGE},
|
||||
// {"LOCAL", TK_LOCAL},
|
||||
{"IF", TK_IF},
|
||||
{"EXISTS", TK_EXISTS},
|
||||
{"CREATE", TK_CREATE},
|
||||
{"PPS", TK_PPS},
|
||||
{"TSERIES", TK_TSERIES},
|
||||
{"DBS", TK_DBS},
|
||||
{"STORAGE", TK_STORAGE},
|
||||
{"QTIME", TK_QTIME},
|
||||
{"CONNS", TK_CONNS},
|
||||
{"STATE", TK_STATE},
|
||||
// {"PPS", TK_PPS},
|
||||
// {"TSERIES", TK_TSERIES},
|
||||
// {"DBS", TK_DBS},
|
||||
// {"STORAGE", TK_STORAGE},
|
||||
// {"QTIME", TK_QTIME},
|
||||
// {"CONNS", TK_CONNS},
|
||||
// {"STATE", TK_STATE},
|
||||
{"KEEP", TK_KEEP},
|
||||
{"REPLICA", TK_REPLICA},
|
||||
{"QUORUM", TK_QUORUM},
|
||||
|
@ -122,23 +122,23 @@ static SKeyword keywordTable[] = {
|
|||
{"MAXROWS", TK_MAXROWS},
|
||||
{"BLOCKS", TK_BLOCKS},
|
||||
{"CACHE", TK_CACHE},
|
||||
{"CTIME", TK_CTIME},
|
||||
// {"CTIME", TK_CTIME},
|
||||
{"WAL", TK_WAL},
|
||||
{"FSYNC", TK_FSYNC},
|
||||
{"COMP", TK_COMP},
|
||||
{"PRECISION", TK_PRECISION},
|
||||
{"LP", TK_LP},
|
||||
{"RP", TK_RP},
|
||||
{"UNSIGNED", TK_UNSIGNED},
|
||||
// {"LP", TK_LP},
|
||||
// {"RP", TK_RP},
|
||||
// {"UNSIGNED", TK_UNSIGNED},
|
||||
{"TAGS", TK_TAGS},
|
||||
{"USING", TK_USING},
|
||||
{"AS", TK_AS},
|
||||
{"COMMA", TK_COMMA},
|
||||
// {"COMMA", TK_COMMA},
|
||||
{"NULL", TK_NULL},
|
||||
{"SELECT", TK_SELECT},
|
||||
{"EVERY", TK_EVERY},
|
||||
// {"EVERY", TK_EVERY},
|
||||
{"FROM", TK_FROM},
|
||||
{"VARIABLE", TK_VARIABLE},
|
||||
// {"VARIABLE", TK_VARIABLE},
|
||||
{"INTERVAL", TK_INTERVAL},
|
||||
{"SESSION", TK_SESSION},
|
||||
{"STATE_WINDOW", TK_STATE_WINDOW},
|
||||
|
@ -159,78 +159,78 @@ static SKeyword keywordTable[] = {
|
|||
{"INSERT", TK_INSERT},
|
||||
{"INTO", TK_INTO},
|
||||
{"VALUES", TK_VALUES},
|
||||
{"UPDATE", TK_UPDATE},
|
||||
{"RESET", TK_RESET},
|
||||
{"QUERY", TK_QUERY},
|
||||
{"ADD", TK_ADD},
|
||||
{"COLUMN", TK_COLUMN},
|
||||
{"TAG", TK_TAG},
|
||||
{"CHANGE", TK_CHANGE},
|
||||
{"SET", TK_SET},
|
||||
{"KILL", TK_KILL},
|
||||
{"CONNECTION", TK_CONNECTION},
|
||||
{"COLON", TK_COLON},
|
||||
{"STREAM", TK_STREAM},
|
||||
{"ABORT", TK_ABORT},
|
||||
{"AFTER", TK_AFTER},
|
||||
{"ATTACH", TK_ATTACH},
|
||||
{"BEFORE", TK_BEFORE},
|
||||
{"BEGIN", TK_BEGIN},
|
||||
{"CASCADE", TK_CASCADE},
|
||||
{"CLUSTER", TK_CLUSTER},
|
||||
{"CONFLICT", TK_CONFLICT},
|
||||
{"COPY", TK_COPY},
|
||||
{"DEFERRED", TK_DEFERRED},
|
||||
{"DELIMITERS", TK_DELIMITERS},
|
||||
{"DETACH", TK_DETACH},
|
||||
{"EACH", TK_EACH},
|
||||
{"END", TK_END},
|
||||
{"EXPLAIN", TK_EXPLAIN},
|
||||
{"FAIL", TK_FAIL},
|
||||
{"FOR", TK_FOR},
|
||||
{"IGNORE", TK_IGNORE},
|
||||
{"IMMEDIATE", TK_IMMEDIATE},
|
||||
{"INITIALLY", TK_INITIALLY},
|
||||
{"INSTEAD", TK_INSTEAD},
|
||||
// {"UPDATE", TK_UPDATE},
|
||||
// {"RESET", TK_RESET},
|
||||
// {"QUERY", TK_QUERY},
|
||||
// {"ADD", TK_ADD},
|
||||
// {"COLUMN", TK_COLUMN},
|
||||
// {"TAG", TK_TAG},
|
||||
// {"CHANGE", TK_CHANGE},
|
||||
// {"SET", TK_SET},
|
||||
// {"KILL", TK_KILL},
|
||||
// {"CONNECTION", TK_CONNECTION},
|
||||
// {"COLON", TK_COLON},
|
||||
// {"STREAM", TK_STREAM},
|
||||
// {"ABORT", TK_ABORT},
|
||||
// {"AFTER", TK_AFTER},
|
||||
// {"ATTACH", TK_ATTACH},
|
||||
// {"BEFORE", TK_BEFORE},
|
||||
// {"BEGIN", TK_BEGIN},
|
||||
// {"CASCADE", TK_CASCADE},
|
||||
// {"CLUSTER", TK_CLUSTER},
|
||||
// {"CONFLICT", TK_CONFLICT},
|
||||
// {"COPY", TK_COPY},
|
||||
// {"DEFERRED", TK_DEFERRED},
|
||||
// {"DELIMITERS", TK_DELIMITERS},
|
||||
// {"DETACH", TK_DETACH},
|
||||
// {"EACH", TK_EACH},
|
||||
// {"END", TK_END},
|
||||
// {"EXPLAIN", TK_EXPLAIN},
|
||||
// {"FAIL", TK_FAIL},
|
||||
// {"FOR", TK_FOR},
|
||||
// {"IGNORE", TK_IGNORE},
|
||||
// {"IMMEDIATE", TK_IMMEDIATE},
|
||||
// {"INITIALLY", TK_INITIALLY},
|
||||
// {"INSTEAD", TK_INSTEAD},
|
||||
{"MATCH", TK_MATCH},
|
||||
{"NMATCH", TK_NMATCH},
|
||||
{"KEY", TK_KEY},
|
||||
{"OF", TK_OF},
|
||||
{"RAISE", TK_RAISE},
|
||||
{"REPLACE", TK_REPLACE},
|
||||
{"RESTRICT", TK_RESTRICT},
|
||||
{"ROW", TK_ROW},
|
||||
{"STATEMENT", TK_STATEMENT},
|
||||
{"TRIGGER", TK_TRIGGER},
|
||||
{"VIEW", TK_VIEW},
|
||||
// {"KEY", TK_KEY},
|
||||
// {"OF", TK_OF},
|
||||
// {"RAISE", TK_RAISE},
|
||||
// {"REPLACE", TK_REPLACE},
|
||||
// {"RESTRICT", TK_RESTRICT},
|
||||
// {"ROW", TK_ROW},
|
||||
// {"STATEMENT", TK_STATEMENT},
|
||||
// {"TRIGGER", TK_TRIGGER},
|
||||
// {"VIEW", TK_VIEW},
|
||||
{"ALL", TK_ALL},
|
||||
{"SEMI", TK_SEMI},
|
||||
// {"SEMI", TK_SEMI},
|
||||
{"NONE", TK_NONE},
|
||||
{"PREV", TK_PREV},
|
||||
{"LINEAR", TK_LINEAR},
|
||||
{"IMPORT", TK_IMPORT},
|
||||
{"TBNAME", TK_TBNAME},
|
||||
// {"TBNAME", TK_TBNAME},
|
||||
{"JOIN", TK_JOIN},
|
||||
{"STABLE", TK_STABLE},
|
||||
// {"STABLE", TK_STABLE},
|
||||
{"FILE", TK_FILE},
|
||||
{"VNODES", TK_VNODES},
|
||||
// {"VNODES", TK_VNODES},
|
||||
{"UNION", TK_UNION},
|
||||
{"CACHELAST", TK_CACHELAST},
|
||||
{"DISTINCT", TK_DISTINCT},
|
||||
// {"PARTITIONS", TK_PARTITIONS},
|
||||
{"TOPIC", TK_TOPIC},
|
||||
{"TOPICS", TK_TOPICS},
|
||||
{"COMPACT", TK_COMPACT},
|
||||
{"MODIFY", TK_MODIFY},
|
||||
{"FUNCTION", TK_FUNCTION},
|
||||
{"FUNCTIONS", TK_FUNCTIONS},
|
||||
{"OUTPUTTYPE", TK_OUTPUTTYPE},
|
||||
{"AGGREGATE", TK_AGGREGATE},
|
||||
{"BUFSIZE", TK_BUFSIZE},
|
||||
{"PORT", TK_PORT},
|
||||
{"INNER", NEW_TK_INNER},
|
||||
{"ON", NEW_TK_ON},
|
||||
{"MODE", TK_MODE},
|
||||
// {"TOPIC", TK_TOPIC},
|
||||
// {"TOPICS", TK_TOPICS},
|
||||
// {"COMPACT", TK_COMPACT},
|
||||
// {"MODIFY", TK_MODIFY},
|
||||
// {"FUNCTION", TK_FUNCTION},
|
||||
// {"FUNCTIONS", TK_FUNCTIONS},
|
||||
// {"OUTPUTTYPE", TK_OUTPUTTYPE},
|
||||
// {"AGGREGATE", TK_AGGREGATE},
|
||||
// {"BUFSIZE", TK_BUFSIZE},
|
||||
// {"PORT", TK_PORT},
|
||||
{"INNER", TK_INNER},
|
||||
{"ON", TK_ON},
|
||||
// {"MODE", TK_MODE},
|
||||
};
|
||||
|
||||
static const char isIdChar[] = {
|
||||
|
@ -265,7 +265,7 @@ static int32_t tKeywordCode(const char* z, int n) {
|
|||
|
||||
char key[512] = {0};
|
||||
if (n > tListLen(key)) { // too long token, can not be any other token type
|
||||
return TK_ID;
|
||||
return TK_NK_ID;
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < n; ++j) {
|
||||
|
@ -281,7 +281,7 @@ static int32_t tKeywordCode(const char* z, int n) {
|
|||
}
|
||||
|
||||
SKeyword** pKey = (SKeyword**)taosHashGet(keywordHashTable, key, n);
|
||||
return (pKey != NULL)? (*pKey)->type:TK_ID;
|
||||
return (pKey != NULL)? (*pKey)->type:TK_NK_ID;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -302,7 +302,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
return i;
|
||||
}
|
||||
case ':': {
|
||||
*tokenId = TK_COLON;
|
||||
*tokenId = TK_NK_COLON;
|
||||
return 1;
|
||||
}
|
||||
case '-': {
|
||||
|
@ -316,11 +316,11 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
return 1;
|
||||
}
|
||||
case '(': {
|
||||
*tokenId = TK_LP;
|
||||
*tokenId = TK_NK_LP;
|
||||
return 1;
|
||||
}
|
||||
case ')': {
|
||||
*tokenId = TK_RP;
|
||||
*tokenId = TK_NK_RP;
|
||||
return 1;
|
||||
}
|
||||
case ';': {
|
||||
|
@ -328,16 +328,16 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
return 1;
|
||||
}
|
||||
case '+': {
|
||||
*tokenId = TK_PLUS;
|
||||
*tokenId = TK_NK_PLUS;
|
||||
return 1;
|
||||
}
|
||||
case '*': {
|
||||
*tokenId = TK_STAR;
|
||||
*tokenId = TK_NK_STAR;
|
||||
return 1;
|
||||
}
|
||||
case '/': {
|
||||
if (z[1] != '*' || z[2] == 0) {
|
||||
*tokenId = TK_SLASH;
|
||||
*tokenId = TK_NK_SLASH;
|
||||
return 1;
|
||||
}
|
||||
for (i = 3; z[i] && (z[i] != '/' || z[i - 1] != '*'); i++) {
|
||||
|
@ -347,37 +347,37 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
return i;
|
||||
}
|
||||
case '%': {
|
||||
*tokenId = TK_REM;
|
||||
*tokenId = TK_NK_REM;
|
||||
return 1;
|
||||
}
|
||||
case '=': {
|
||||
*tokenId = TK_EQ;
|
||||
*tokenId = TK_NK_EQ;
|
||||
return 1 + (z[1] == '=');
|
||||
}
|
||||
case '<': {
|
||||
if (z[1] == '=') {
|
||||
*tokenId = TK_LE;
|
||||
*tokenId = TK_NK_LE;
|
||||
return 2;
|
||||
} else if (z[1] == '>') {
|
||||
*tokenId = TK_NE;
|
||||
*tokenId = TK_NK_NE;
|
||||
return 2;
|
||||
} else if (z[1] == '<') {
|
||||
*tokenId = TK_LSHIFT;
|
||||
*tokenId = TK_NK_LSHIFT;
|
||||
return 2;
|
||||
} else {
|
||||
*tokenId = TK_LT;
|
||||
*tokenId = TK_NK_LT;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
case '>': {
|
||||
if (z[1] == '=') {
|
||||
*tokenId = TK_GE;
|
||||
*tokenId = TK_NK_GE;
|
||||
return 2;
|
||||
} else if (z[1] == '>') {
|
||||
*tokenId = TK_RSHIFT;
|
||||
*tokenId = TK_NK_RSHIFT;
|
||||
return 2;
|
||||
} else {
|
||||
*tokenId = TK_GT;
|
||||
*tokenId = TK_NK_GT;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -386,29 +386,29 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
*tokenId = TK_ILLEGAL;
|
||||
return 2;
|
||||
} else {
|
||||
*tokenId = TK_NE;
|
||||
*tokenId = TK_NK_NE;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
case '|': {
|
||||
if (z[1] != '|') {
|
||||
*tokenId = TK_BITOR;
|
||||
*tokenId = TK_NK_BITOR;
|
||||
return 1;
|
||||
} else {
|
||||
*tokenId = TK_CONCAT;
|
||||
*tokenId = TK_NK_CONCAT;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
case ',': {
|
||||
*tokenId = TK_COMMA;
|
||||
*tokenId = TK_NK_COMMA;
|
||||
return 1;
|
||||
}
|
||||
case '&': {
|
||||
*tokenId = TK_BITAND;
|
||||
*tokenId = TK_NK_BITAND;
|
||||
return 1;
|
||||
}
|
||||
case '~': {
|
||||
*tokenId = TK_BITNOT;
|
||||
*tokenId = TK_NK_BITNOT;
|
||||
return 1;
|
||||
}
|
||||
case '?': {
|
||||
|
@ -439,7 +439,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
if (z[i]) i++;
|
||||
|
||||
if (strEnd) {
|
||||
*tokenId = (delim == '`')? TK_ID:TK_STRING;
|
||||
*tokenId = (delim == '`')? TK_NK_ID:TK_NK_STRING;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -463,10 +463,10 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
}
|
||||
}
|
||||
|
||||
*tokenId = TK_FLOAT;
|
||||
*tokenId = TK_NK_FLOAT;
|
||||
return i;
|
||||
} else {
|
||||
*tokenId = TK_DOT;
|
||||
*tokenId = TK_NK_DOT;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
case '7':
|
||||
case '8':
|
||||
case '9': {
|
||||
*tokenId = TK_INTEGER;
|
||||
*tokenId = TK_NK_INTEGER;
|
||||
for (i = 1; isdigit(z[i]); i++) {
|
||||
}
|
||||
|
||||
|
@ -515,7 +515,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
z[i] == 'B' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' ||
|
||||
z[i] == 'Y' || z[i] == 'W') &&
|
||||
(isIdChar[(uint8_t)z[i + 1]] == 0)) {
|
||||
*tokenId = TK_VARIABLE;
|
||||
*tokenId = TK_NK_VARIABLE;
|
||||
i += 1;
|
||||
return i;
|
||||
}
|
||||
|
@ -526,7 +526,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
while (isdigit(z[i])) {
|
||||
i++;
|
||||
}
|
||||
*tokenId = TK_FLOAT;
|
||||
*tokenId = TK_NK_FLOAT;
|
||||
seg++;
|
||||
}
|
||||
|
||||
|
@ -541,14 +541,14 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
while (isdigit(z[i])) {
|
||||
i++;
|
||||
}
|
||||
*tokenId = TK_FLOAT;
|
||||
*tokenId = TK_NK_FLOAT;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
case '[': {
|
||||
for (i = 1; z[i] && z[i - 1] != ']'; i++) {
|
||||
}
|
||||
*tokenId = TK_ID;
|
||||
*tokenId = TK_NK_ID;
|
||||
return i;
|
||||
}
|
||||
case 'T':
|
||||
|
@ -559,7 +559,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
}
|
||||
|
||||
if ((i == 4 && strncasecmp(z, "true", 4) == 0) || (i == 5 && strncasecmp(z, "false", 5) == 0)) {
|
||||
*tokenId = TK_BOOL;
|
||||
*tokenId = TK_NK_BOOL;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -655,7 +655,7 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) {
|
|||
len = tGetToken(&str[*i + t0.n + 1], &type);
|
||||
|
||||
// only id and string are valid
|
||||
if ((TK_STRING != t0.type) && (TK_ID != t0.type)) {
|
||||
if ((TK_NK_STRING != t0.type) && (TK_NK_ID != t0.type)) {
|
||||
t0.type = TK_ILLEGAL;
|
||||
t0.n = 0;
|
||||
|
||||
|
@ -666,9 +666,9 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) {
|
|||
|
||||
} else {
|
||||
// support parse the -/+number format
|
||||
if ((isPrevOptr) && (t0.type == TK_MINUS || t0.type == TK_PLUS)) {
|
||||
if ((isPrevOptr) && (t0.type == TK_MINUS || t0.type == TK_NK_PLUS)) {
|
||||
len = tGetToken(&str[*i + t0.n], &type);
|
||||
if (type == TK_INTEGER || type == TK_FLOAT) {
|
||||
if (type == TK_NK_INTEGER || type == TK_NK_FLOAT) {
|
||||
t0.type = type;
|
||||
t0.n += len;
|
||||
}
|
||||
|
@ -682,7 +682,7 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) {
|
|||
}
|
||||
|
||||
bool taosIsKeyWordToken(const char* z, int32_t len) {
|
||||
return (tKeywordCode((char*)z, len) != TK_ID);
|
||||
return (tKeywordCode((char*)z, len) != TK_NK_ID);
|
||||
}
|
||||
|
||||
void taosCleanupKeywordsTable() {
|
||||
|
|
|
@ -612,10 +612,10 @@ TEST_F(ParserTest, selectSemanticError) {
|
|||
setDatabase("root", "test");
|
||||
|
||||
// TSDB_CODE_PAR_INVALID_COLUMN
|
||||
bind("SELECT c1, c3 FROM t1");
|
||||
bind("SELECT c1, cc1 FROM t1");
|
||||
ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_INVALID_COLUMN));
|
||||
|
||||
bind("SELECT t1.c1, t1.c3 FROM t1");
|
||||
bind("SELECT t1.c1, t1.cc1 FROM t1");
|
||||
ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_INVALID_COLUMN));
|
||||
|
||||
// TSDB_CODE_PAR_TABLE_NOT_EXIST
|
||||
|
|
Loading…
Reference in New Issue