未验证 提交 ed67234d 编写于 作者: X Xiaoyu Wang 提交者: GitHub

Merge pull request #10602 from taosdata/feature/3.0_query_integrate_wxy

TD-13881 implement create/alter/drop/show user, create/drop/show dnode, drop database, show stables and drop table
......@@ -913,6 +913,8 @@ int32_t tDeserializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq*
typedef struct {
int32_t dnodeId;
char fqdn[TSDB_FQDN_LEN];
int32_t port;
} SDropDnodeReq;
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
......
......@@ -34,110 +34,121 @@
#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_SINGLE_STABLE 40
#define TK_STREAM_MODE 41
#define TK_USE 42
#define TK_TABLE 43
#define TK_NK_LP 44
#define TK_NK_RP 45
#define TK_STABLE 46
#define TK_USING 47
#define TK_TAGS 48
#define TK_NK_ID 49
#define TK_NK_DOT 50
#define TK_NK_COMMA 51
#define TK_COMMENT 52
#define TK_BOOL 53
#define TK_TINYINT 54
#define TK_SMALLINT 55
#define TK_INT 56
#define TK_INTEGER 57
#define TK_BIGINT 58
#define TK_FLOAT 59
#define TK_DOUBLE 60
#define TK_BINARY 61
#define TK_TIMESTAMP 62
#define TK_NCHAR 63
#define TK_UNSIGNED 64
#define TK_JSON 65
#define TK_VARCHAR 66
#define TK_MEDIUMBLOB 67
#define TK_BLOB 68
#define TK_VARBINARY 69
#define TK_DECIMAL 70
#define TK_SMA 71
#define TK_SHOW 72
#define TK_DATABASES 73
#define TK_TABLES 74
#define TK_NK_FLOAT 75
#define TK_NK_BOOL 76
#define TK_NK_VARIABLE 77
#define TK_BETWEEN 78
#define TK_IS 79
#define TK_NULL 80
#define TK_NK_LT 81
#define TK_NK_GT 82
#define TK_NK_LE 83
#define TK_NK_GE 84
#define TK_NK_NE 85
#define TK_NK_EQ 86
#define TK_LIKE 87
#define TK_MATCH 88
#define TK_NMATCH 89
#define TK_IN 90
#define TK_FROM 91
#define TK_AS 92
#define TK_JOIN 93
#define TK_ON 94
#define TK_INNER 95
#define TK_SELECT 96
#define TK_DISTINCT 97
#define TK_WHERE 98
#define TK_PARTITION 99
#define TK_BY 100
#define TK_SESSION 101
#define TK_STATE_WINDOW 102
#define TK_INTERVAL 103
#define TK_SLIDING 104
#define TK_FILL 105
#define TK_VALUE 106
#define TK_NONE 107
#define TK_PREV 108
#define TK_LINEAR 109
#define TK_NEXT 110
#define TK_GROUP 111
#define TK_HAVING 112
#define TK_ORDER 113
#define TK_SLIMIT 114
#define TK_SOFFSET 115
#define TK_LIMIT 116
#define TK_OFFSET 117
#define TK_ASC 118
#define TK_DESC 119
#define TK_NULLS 120
#define TK_FIRST 121
#define TK_LAST 122
#define TK_USER 19
#define TK_PASS 20
#define TK_NK_STRING 21
#define TK_ALTER 22
#define TK_PRIVILEGE 23
#define TK_DROP 24
#define TK_SHOW 25
#define TK_USERS 26
#define TK_DNODE 27
#define TK_PORT 28
#define TK_NK_INTEGER 29
#define TK_DNODES 30
#define TK_NK_ID 31
#define TK_NK_IPTOKEN 32
#define TK_DATABASE 33
#define TK_DATABASES 34
#define TK_USE 35
#define TK_IF 36
#define TK_NOT 37
#define TK_EXISTS 38
#define TK_BLOCKS 39
#define TK_CACHE 40
#define TK_CACHELAST 41
#define TK_COMP 42
#define TK_DAYS 43
#define TK_FSYNC 44
#define TK_MAXROWS 45
#define TK_MINROWS 46
#define TK_KEEP 47
#define TK_PRECISION 48
#define TK_QUORUM 49
#define TK_REPLICA 50
#define TK_TTL 51
#define TK_WAL 52
#define TK_VGROUPS 53
#define TK_SINGLE_STABLE 54
#define TK_STREAM_MODE 55
#define TK_TABLE 56
#define TK_NK_LP 57
#define TK_NK_RP 58
#define TK_STABLE 59
#define TK_TABLES 60
#define TK_STABLES 61
#define TK_USING 62
#define TK_TAGS 63
#define TK_NK_DOT 64
#define TK_NK_COMMA 65
#define TK_COMMENT 66
#define TK_BOOL 67
#define TK_TINYINT 68
#define TK_SMALLINT 69
#define TK_INT 70
#define TK_INTEGER 71
#define TK_BIGINT 72
#define TK_FLOAT 73
#define TK_DOUBLE 74
#define TK_BINARY 75
#define TK_TIMESTAMP 76
#define TK_NCHAR 77
#define TK_UNSIGNED 78
#define TK_JSON 79
#define TK_VARCHAR 80
#define TK_MEDIUMBLOB 81
#define TK_BLOB 82
#define TK_VARBINARY 83
#define TK_DECIMAL 84
#define TK_SMA 85
#define TK_NK_FLOAT 86
#define TK_NK_BOOL 87
#define TK_NK_VARIABLE 88
#define TK_BETWEEN 89
#define TK_IS 90
#define TK_NULL 91
#define TK_NK_LT 92
#define TK_NK_GT 93
#define TK_NK_LE 94
#define TK_NK_GE 95
#define TK_NK_NE 96
#define TK_NK_EQ 97
#define TK_LIKE 98
#define TK_MATCH 99
#define TK_NMATCH 100
#define TK_IN 101
#define TK_FROM 102
#define TK_AS 103
#define TK_JOIN 104
#define TK_ON 105
#define TK_INNER 106
#define TK_SELECT 107
#define TK_DISTINCT 108
#define TK_WHERE 109
#define TK_PARTITION 110
#define TK_BY 111
#define TK_SESSION 112
#define TK_STATE_WINDOW 113
#define TK_INTERVAL 114
#define TK_SLIDING 115
#define TK_FILL 116
#define TK_VALUE 117
#define TK_NONE 118
#define TK_PREV 119
#define TK_LINEAR 120
#define TK_NEXT 121
#define TK_GROUP 122
#define TK_HAVING 123
#define TK_ORDER 124
#define TK_SLIMIT 125
#define TK_SOFFSET 126
#define TK_LIMIT 127
#define TK_OFFSET 128
#define TK_ASC 129
#define TK_DESC 130
#define TK_NULLS 131
#define TK_FIRST 132
#define TK_LAST 133
#define TK_NK_SPACE 300
#define TK_NK_COMMENT 301
......@@ -155,9 +166,8 @@
#define TK_NOW 504
#define TK_VALUES 507
#define TK_IMPORT 507
#define TK_SEMI 508
#define TK_IPTOKEN 509
#define TK_NK_SEMI 508
#define TK_NIL 65535
#define TK_NK_NIL 65535
#endif /*_TD_COMMON_TOKEN_H_*/
......@@ -54,6 +54,12 @@ typedef struct SUseDatabaseStmt {
char dbName[TSDB_DB_NAME_LEN];
} SUseDatabaseStmt;
typedef struct SDropDatabaseStmt {
ENodeType type;
char dbName[TSDB_DB_NAME_LEN];
bool ignoreNotExists;
} SDropDatabaseStmt;
typedef struct STableOptions {
int32_t keep;
int32_t ttl;
......@@ -94,6 +100,49 @@ typedef struct SCreateMultiTableStmt {
SNodeList* pSubTables;
} SCreateMultiTableStmt;
typedef struct SDropTableClause {
ENodeType type;
char dbName[TSDB_DB_NAME_LEN];
char tableName[TSDB_TABLE_NAME_LEN];
bool ignoreNotExists;
} SDropTableClause;
typedef struct SDropTableStmt {
ENodeType type;
SNodeList* pTables;
} SDropTableStmt;
typedef struct SCreateUserStmt {
ENodeType type;
char useName[TSDB_USER_LEN];
char password[TSDB_USET_PASSWORD_LEN];
} SCreateUserStmt;
typedef struct SAlterUserStmt {
ENodeType type;
char useName[TSDB_USER_LEN];
char password[TSDB_USET_PASSWORD_LEN];
int8_t alterType;
} SAlterUserStmt;
typedef struct SDropUserStmt {
ENodeType type;
char useName[TSDB_USER_LEN];
} SDropUserStmt;
typedef struct SCreateDnodeStmt {
ENodeType type;
char fqdn[TSDB_FQDN_LEN];
int32_t port;
} SCreateDnodeStmt;
typedef struct SDropDnodeStmt {
ENodeType type;
int32_t dnodeId;
char fqdn[TSDB_FQDN_LEN];
int32_t port;
} SDropDnodeStmt;
#ifdef __cplusplus
}
#endif
......
......@@ -72,12 +72,24 @@ typedef enum ENodeType {
QUERY_NODE_SELECT_STMT,
QUERY_NODE_VNODE_MODIF_STMT,
QUERY_NODE_CREATE_DATABASE_STMT,
QUERY_NODE_DROP_DATABASE_STMT,
QUERY_NODE_SHOW_DATABASES_STMT, // temp
QUERY_NODE_CREATE_TABLE_STMT,
QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
QUERY_NODE_CREATE_MULTI_TABLE_STMT,
QUERY_NODE_USE_DATABASE_STMT,
QUERY_NODE_SHOW_DATABASES_STMT, // temp
QUERY_NODE_DROP_TABLE_CLAUSE,
QUERY_NODE_DROP_TABLE_STMT,
QUERY_NODE_SHOW_TABLES_STMT, // temp
QUERY_NODE_SHOW_STABLES_STMT,
QUERY_NODE_CREATE_USER_STMT,
QUERY_NODE_ALTER_USER_STMT,
QUERY_NODE_DROP_USER_STMT,
QUERY_NODE_SHOW_USERS_STMT,
QUERY_NODE_USE_DATABASE_STMT,
QUERY_NODE_CREATE_DNODE_STMT,
QUERY_NODE_DROP_DNODE_STMT,
QUERY_NODE_SHOW_DNODES_STMT,
QUERY_NODE_SHOW_VGROUPS_STMT,
// logic plan node
QUERY_NODE_LOGIC_PLAN_SCAN,
......
......@@ -457,6 +457,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SCH_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2502)
//parser
#define TSDB_CODE_PAR_SYNTAX_ERROR TAOS_DEF_ERROR_CODE(0, 0x2600)
#define TSDB_CODE_PAR_INVALID_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2601)
#define TSDB_CODE_PAR_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x2602)
#define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603)
......@@ -471,6 +472,11 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_NOT_SINGLE_GROUP TAOS_DEF_ERROR_CODE(0, 0x260C)
#define TSDB_CODE_PAR_TAGS_NOT_MATCHED TAOS_DEF_ERROR_CODE(0, 0x260D)
#define TSDB_CODE_PAR_INVALID_TAG_NAME TAOS_DEF_ERROR_CODE(0, 0x260E)
#define TSDB_CODE_PAR_INCOMPLETE_SQL TAOS_DEF_ERROR_CODE(0, 0x260F)
#define TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG TAOS_DEF_ERROR_CODE(0, 0x2610)
#define TSDB_CODE_PAR_PASSWD_EMPTY TAOS_DEF_ERROR_CODE(0, 0x2611)
#define TSDB_CODE_PAR_INVALID_PORT TAOS_DEF_ERROR_CODE(0, 0x2612)
#define TSDB_CODE_PAR_INVALID_ENDPOINT TAOS_DEF_ERROR_CODE(0, 0x2613)
#ifdef __cplusplus
}
......
......@@ -1007,11 +1007,32 @@ int32_t tDeserializeSMCreateDropQSBNodeReq(void *buf, int32_t bufLen, SMCreateQn
}
int32_t tSerializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq) {
return tSerializeSMCreateDropQSBNodeReq(buf, bufLen, (SMCreateQnodeReq *)pReq);
SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
if (tStartEncode(&encoder) < 0) return -1;
if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
if (tEncodeCStr(&encoder, pReq->fqdn) < 0) return -1;
if (tEncodeI32(&encoder, pReq->port) < 0) return -1;
tEndEncode(&encoder);
int32_t tlen = encoder.pos;
tCoderClear(&encoder);
return tlen;
}
int32_t tDeserializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq) {
return tDeserializeSMCreateDropQSBNodeReq(buf, bufLen, (SMCreateQnodeReq *)pReq);
SCoder decoder = {0};
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
if (tStartDecode(&decoder) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
if (tDecodeCStrTo(&decoder, pReq->fqdn) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->port) < 0) return -1;
tEndDecode(&decoder);
tCoderClear(&decoder);
return 0;
}
int32_t tSerializeSMCreateDropMnodeReq(void *buf, int32_t bufLen, SMCreateMnodeReq *pReq) {
......
......@@ -82,17 +82,41 @@ SNodeptr nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(SVnodeModifOpStmt));
case QUERY_NODE_CREATE_DATABASE_STMT:
return makeNode(type, sizeof(SCreateDatabaseStmt));
case QUERY_NODE_DROP_DATABASE_STMT:
return makeNode(type, sizeof(SDropDatabaseStmt));
case QUERY_NODE_SHOW_DATABASES_STMT:
return makeNode(type, sizeof(SNode));
case QUERY_NODE_CREATE_TABLE_STMT:
return makeNode(type, sizeof(SCreateTableStmt));
case QUERY_NODE_CREATE_SUBTABLE_CLAUSE:
return makeNode(type, sizeof(SCreateSubTableClause));
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
return makeNode(type, sizeof(SCreateMultiTableStmt));
case QUERY_NODE_DROP_TABLE_CLAUSE:
return makeNode(type, sizeof(SDropTableClause));
case QUERY_NODE_DROP_TABLE_STMT:
return makeNode(type, sizeof(SDropTableStmt));
case QUERY_NODE_SHOW_TABLES_STMT:
case QUERY_NODE_SHOW_STABLES_STMT:
return makeNode(type, sizeof(SNode));
case QUERY_NODE_CREATE_USER_STMT:
return makeNode(type, sizeof(SCreateUserStmt));
case QUERY_NODE_ALTER_USER_STMT:
return makeNode(type, sizeof(SAlterUserStmt));
case QUERY_NODE_DROP_USER_STMT:
return makeNode(type, sizeof(SDropUserStmt));
case QUERY_NODE_SHOW_USERS_STMT:
return makeNode(type, sizeof(SNode));
case QUERY_NODE_USE_DATABASE_STMT:
return makeNode(type, sizeof(SUseDatabaseStmt));
case QUERY_NODE_SHOW_DATABASES_STMT:
case QUERY_NODE_SHOW_TABLES_STMT:
return makeNode(type, sizeof(SNode));;
case QUERY_NODE_CREATE_DNODE_STMT:
return makeNode(type, sizeof(SCreateDnodeStmt));
case QUERY_NODE_DROP_DNODE_STMT:
return makeNode(type, sizeof(SDropDnodeStmt));
case QUERY_NODE_SHOW_DNODES_STMT:
return makeNode(type, sizeof(SNode));
case QUERY_NODE_SHOW_VGROUPS_STMT:
return makeNode(type, sizeof(SNode));
case QUERY_NODE_LOGIC_PLAN_SCAN:
return makeNode(type, sizeof(SScanLogicNode));
case QUERY_NODE_LOGIC_PLAN_JOIN:
......
......@@ -22,20 +22,48 @@ extern "C" {
#include "cmdnodes.h"
#include "parser.h"
#include "parserUtil.h"
#include "querynodes.h"
#include "ttoken.h"
typedef struct SAstCreateContext {
SParseContext* pQueryCxt;
SMsgBuf msgBuf;
bool notSupport;
bool valid;
SNode* pRootNode;
} SAstCreateContext;
typedef struct STokenPair {
SToken first;
SToken second;
} STokenPair;
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;
typedef enum ETableOptionType {
TABLE_OPTION_KEEP = 0,
TABLE_OPTION_TTL,
TABLE_OPTION_COMMENT,
TABLE_OPTION_SMA,
TABLE_OPTION_MAX
} ETableOptionType;
extern SToken nil_token;
......@@ -81,53 +109,28 @@ 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);
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* createDefaultDatabaseOptions(SAstCreateContext* pCxt);
SDatabaseOptions* setDatabaseOption(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, EDatabaseOptionType type, const SToken* pVal);
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SDatabaseOptions* pOptions);
typedef enum ETableOptionType {
TABLE_OPTION_KEEP = 0,
TABLE_OPTION_TTL,
TABLE_OPTION_COMMENT,
TABLE_OPTION_SMA,
TABLE_OPTION_MAX
} ETableOptionType;
SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pDbName);
STableOptions* createDefaultTableOptions(SAstCreateContext* pCxt);
STableOptions* setTableOption(SAstCreateContext* pCxt, STableOptions* pOptions, ETableOptionType type, const SToken* pVal);
STableOptions* setTableSmaOption(SAstCreateContext* pCxt, STableOptions* pOptions, SNodeList* pSma);
SNode* createColumnDefNode(SAstCreateContext* pCxt, const SToken* pColName, SDataType dataType, const SToken* pComment);
SDataType createDataType(uint8_t type);
SDataType createVarLenDataType(uint8_t type, const SToken* pLen);
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, const STokenPair* pFullTableName, SNodeList* pCols, SNodeList* pTags, STableOptions* pOptions);
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists,
const STokenPair* pFullTableName, const STokenPair* pUseFullTableName, SNodeList* pSpecificTags, SNodeList* pValsOfTags);
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, STableOptions* pOptions);
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags);
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables);
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables);
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName);
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type);
SNode* createCreateUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, const SToken* pPassword);
SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int8_t alterType, const SToken* pVal);
SNode* createDropUserStmt(SAstCreateContext* pCxt, const SToken* pUserName);
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort);
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode);
#ifdef __cplusplus
}
......
......@@ -25,18 +25,9 @@
%syntax_error {
if(TOKEN.z) {
char msg[] = "syntax error near \"%s\"";
int32_t sqlLen = strlen(&TOKEN.z[0]);
if (sqlLen + sizeof(msg)/sizeof(msg[0]) + 1 > pCxt->pQueryCxt->msgLen) {
char tmpstr[128] = {0};
memcpy(tmpstr, &TOKEN.z[0], sizeof(tmpstr)/sizeof(tmpstr[0]) - 1);
sprintf(pCxt->pQueryCxt->pMsg, msg, tmpstr);
} else {
sprintf(pCxt->pQueryCxt->pMsg, msg, &TOKEN.z[0]);
}
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
} else {
sprintf(pCxt->pQueryCxt->pMsg, "Incomplete SQL statement");
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL);
}
pCxt->valid = false;
}
......@@ -52,12 +43,43 @@
%left NK_CONCAT.
//%right NK_BITNOT.
/************************************************ create database *****************************************************/
cmd ::= CREATE DATABASE exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C);}
/************************************************ 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); }
/************************************************ 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); }
%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); }
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 NOT EXISTS. { A = true; }
exists_opt(A) ::= IF EXISTS. { A = true; }
exists_opt(A) ::= . { A = false; }
%type db_options { SDatabaseOptions* }
......@@ -81,17 +103,15 @@ db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C).
db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLESTABLE, &C); }
db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAMMODE, &C); }
/************************************************ create database *****************************************************/
cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A);}
/************************************************ create table/stable *************************************************/
cmd ::= CREATE TABLE 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);}
/************************************************ 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 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 ::= 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 ::= SHOW TABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT); }
cmd ::= SHOW STABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT); }
%type multi_create_clause { SNodeList* }
%destructor multi_create_clause { nodesDestroyList($$); }
......@@ -99,18 +119,23 @@ multi_create_clause(A) ::= create_subtable_clause(B).
multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C). { A = addNodeToList(pCxt, B, C); }
create_subtable_clause(A) ::=
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); }
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; }
%type full_table_name { STokenPair }
%destructor full_table_name { }
full_table_name(A) ::= NK_ID(B). { STokenPair t = { .first = nil_token, .second = B }; A = t; }
full_table_name(A) ::= NK_ID(B) NK_DOT NK_ID(C). { STokenPair t = { .first = B, .second = C }; A = t; }
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($$); }
......@@ -171,8 +196,7 @@ col_name_list(A) ::= col_name_list(B) NK_COMMA col_name(C).
col_name(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &B); }
/************************************************ show ***************************************************************/
cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); }
cmd ::= SHOW TABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT); }
cmd ::= SHOW VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT); }
/************************************************ select *************************************************************/
cmd ::= query_expression(A). { pCxt->pRootNode = A; }
......@@ -217,6 +241,10 @@ table_alias(A) ::= NK_ID(B).
%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; }
......
......@@ -29,6 +29,7 @@ typedef struct SMsgBuf {
char *buf;
} SMsgBuf;
int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...);
int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg);
int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr);
......
......@@ -33,7 +33,7 @@
} \
} while (0)
SToken nil_token = { .type = TK_NIL, .n = 0, .z = NULL };
SToken nil_token = { .type = TK_NK_NIL, .n = 0, .z = NULL };
typedef SDatabaseOptions* (*FSetDatabaseOption)(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal);
static FSetDatabaseOption setDbOptionFuncs[DB_OPTION_MAX];
......@@ -309,6 +309,8 @@ static void initSetTableOptionFp() {
void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) {
pCxt->pQueryCxt = pParseCxt;
pCxt->msgBuf.buf = pParseCxt->pMsg;
pCxt->msgBuf.len = pParseCxt->msgLen;
pCxt->notSupport = false;
pCxt->valid = true;
pCxt->pRootNode = NULL;
......@@ -316,6 +318,84 @@ void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) {
initSetTableOptionFp();
}
static bool checkUserName(SAstCreateContext* pCxt, const SToken* pUserName) {
if (NULL == pUserName) {
return false;
}
if (pUserName->n >= TSDB_USER_LEN) {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
pCxt->valid = false;
}
return pCxt->valid;
}
static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, char* pPassword) {
if (NULL == pPasswordToken) {
return false;
}
if (pPasswordToken->n >= (TSDB_USET_PASSWORD_LEN - 2)) {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
pCxt->valid = false;
return false;
}
strncpy(pPassword, pPasswordToken->z, pPasswordToken->n);
strdequote(pPassword);
if (strtrim(pPassword) <= 0) {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_PASSWD_EMPTY);
pCxt->valid = false;
}
return pCxt->valid;
}
static bool checkAndSplitEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* pFqdn, int32_t* pPort) {
if (NULL == pEp) {
return false;
}
if (pEp->n >= TSDB_FQDN_LEN + 2 + 6) { // format 'fqdn:port'
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
pCxt->valid = false;
}
char ep[TSDB_FQDN_LEN + 2 + 6];
strncpy(ep, pEp->z, pEp->n);
strdequote(ep);
strtrim(ep);
char* pColon = strchr(ep, ':');
if (NULL == pColon) {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ENDPOINT);
pCxt->valid = false;
}
strncpy(pFqdn, ep, pColon - ep);
*pPort = strtol(pColon + 1, NULL, 10);
if (*pPort >= UINT16_MAX || *pPort <= 0) {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT);
pCxt->valid = false;
}
return pCxt->valid;
}
static bool checkFqdn(SAstCreateContext* pCxt, const SToken* pFqdn) {
if (NULL == pFqdn) {
return false;
}
if (pFqdn->n >= TSDB_FQDN_LEN) {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
pCxt->valid = false;
}
return pCxt->valid;
}
static bool checkPort(SAstCreateContext* pCxt, const SToken* pPortToken, int32_t* pPort) {
if (NULL == pPortToken) {
return false;
}
*pPort = strtol(pPortToken->z, NULL, 10);
if (*pPort >= UINT16_MAX || *pPort <= 0) {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT);
pCxt->valid = false;
}
return pCxt->valid;
}
static bool checkDbName(SAstCreateContext* pCxt, const SToken* pDbName) {
if (NULL == pDbName) {
return true;
......@@ -487,7 +567,7 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, const SToken* pDbName, const
} else {
strcpy(realTable->table.dbName, pCxt->pQueryCxt->db);
}
if (NULL != pTableAlias && TK_NIL != pTableAlias->type) {
if (NULL != pTableAlias && TK_NK_NIL != pTableAlias->type) {
strncpy(realTable->table.tableAlias, pTableAlias->z, pTableAlias->n);
} else {
strncpy(realTable->table.tableAlias, pTableName->z, pTableName->n);
......@@ -500,7 +580,7 @@ SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, const STok
STempTableNode* tempTable = (STempTableNode*)nodesMakeNode(QUERY_NODE_TEMP_TABLE);
CHECK_OUT_OF_MEM(tempTable);
tempTable->pSubquery = pSubquery;
if (NULL != pTableAlias && TK_NIL != pTableAlias->type) {
if (NULL != pTableAlias && TK_NK_NIL != pTableAlias->type) {
strncpy(tempTable->table.tableAlias, pTableAlias->z, pTableAlias->n);
}
return (SNode*)tempTable;
......@@ -700,6 +780,17 @@ SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, cons
return (SNode*)pStmt;
}
SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pDbName) {
if (!checkDbName(pCxt, pDbName)) {
return NULL;
}
SDropDatabaseStmt* pStmt = (SDropDatabaseStmt*)nodesMakeNode(QUERY_NODE_DROP_DATABASE_STMT);
CHECK_OUT_OF_MEM(pStmt);
strncpy(pStmt->dbName, pDbName->z, pDbName->n);
pStmt->ignoreNotExists = ignoreNotExists;
return (SNode*)pStmt;
}
STableOptions* createDefaultTableOptions(SAstCreateContext* pCxt) {
STableOptions* pOptions = calloc(1, sizeof(STableOptions));
CHECK_OUT_OF_MEM(pOptions);
......@@ -739,41 +830,32 @@ SDataType createVarLenDataType(uint8_t type, const SToken* pLen) {
}
SNode* createCreateTableStmt(SAstCreateContext* pCxt,
bool ignoreExists, const STokenPair* pFullTableName, SNodeList* pCols, SNodeList* pTags, STableOptions* pOptions) {
bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, STableOptions* pOptions) {
SCreateTableStmt* pStmt = (SCreateTableStmt*)nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT);
CHECK_OUT_OF_MEM(pStmt);
if (TK_NIL != pFullTableName->first.type) {
strncpy(pStmt->dbName, pFullTableName->first.z, pFullTableName->first.n);
} else {
strcpy(pStmt->dbName, pCxt->pQueryCxt->db);
}
strncpy(pStmt->tableName, pFullTableName->second.z, pFullTableName->second.n);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
pStmt->ignoreExists = ignoreExists;
pStmt->pCols = pCols;
pStmt->pTags = pTags;
pStmt->options = *pOptions;
nodesDestroyNode(pRealTable);
return (SNode*)pStmt;
}
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists,
const STokenPair* pFullTableName, const STokenPair* pUseFullTableName, SNodeList* pSpecificTags, SNodeList* pValsOfTags) {
SNode* createCreateSubTableClause(SAstCreateContext* pCxt,
bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags) {
SCreateSubTableClause* pStmt = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_CLAUSE);
CHECK_OUT_OF_MEM(pStmt);
if (TK_NIL != pFullTableName->first.type) {
strncpy(pStmt->dbName, pFullTableName->first.z, pFullTableName->first.n);
} else {
strcpy(pStmt->dbName, pCxt->pQueryCxt->db);
}
strncpy(pStmt->tableName, pFullTableName->second.z, pFullTableName->second.n);
if (TK_NIL != pUseFullTableName->first.type) {
strncpy(pStmt->useDbName, pUseFullTableName->first.z, pUseFullTableName->first.n);
} else {
strcpy(pStmt->useDbName, pCxt->pQueryCxt->db);
}
strncpy(pStmt->useTableName, pUseFullTableName->second.z, pUseFullTableName->second.n);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
strcpy(pStmt->useDbName, ((SRealTableNode*)pUseRealTable)->table.dbName);
strcpy(pStmt->useTableName, ((SRealTableNode*)pUseRealTable)->table.tableName);
pStmt->ignoreExists = ignoreExists;
pStmt->pSpecificTags = pSpecificTags;
pStmt->pValsOfTags = pValsOfTags;
nodesDestroyNode(pRealTable);
nodesDestroyNode(pUseRealTable);
return (SNode*)pStmt;
}
......@@ -784,6 +866,23 @@ SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables
return (SNode*)pStmt;
}
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable) {
SDropTableClause* pStmt = nodesMakeNode(QUERY_NODE_DROP_TABLE_CLAUSE);
CHECK_OUT_OF_MEM(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
pStmt->ignoreNotExists = ignoreNotExists;
nodesDestroyNode(pRealTable);
return (SNode*)pStmt;
}
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables) {
SDropTableStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_TABLE_STMT);
CHECK_OUT_OF_MEM(pStmt);
pStmt->pTables = pTables;
return (SNode*)pStmt;
}
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
SUseDatabaseStmt* pStmt = (SUseDatabaseStmt*)nodesMakeNode(QUERY_NODE_USE_DATABASE_STMT);
CHECK_OUT_OF_MEM(pStmt);
......@@ -796,3 +895,79 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type) {
CHECK_OUT_OF_MEM(pStmt);
return pStmt;
}
SNode* createCreateUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, const SToken* pPassword) {
char password[TSDB_USET_PASSWORD_LEN] = {0};
if (!checkUserName(pCxt, pUserName) || !checkPassword(pCxt, pPassword, password)) {
return NULL;
}
SCreateUserStmt* pStmt = (SCreateUserStmt*)nodesMakeNode(QUERY_NODE_CREATE_USER_STMT);
CHECK_OUT_OF_MEM(pStmt);
strncpy(pStmt->useName, pUserName->z, pUserName->n);
strcpy(pStmt->password, password);
return (SNode*)pStmt;
}
SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int8_t alterType, const SToken* pVal) {
if (!checkUserName(pCxt, pUserName)) {
return NULL;
}
SAlterUserStmt* pStmt = (SAlterUserStmt*)nodesMakeNode(QUERY_NODE_ALTER_USER_STMT);
CHECK_OUT_OF_MEM(pStmt);
strncpy(pStmt->useName, pUserName->z, pUserName->n);
if (TSDB_ALTER_USER_PASSWD == alterType) {
char password[TSDB_USET_PASSWORD_LEN] = {0};
if (!checkPassword(pCxt, pVal, password)) {
nodesDestroyNode(pStmt);
return NULL;
}
strcpy(pStmt->password, password);
}
pStmt->alterType = alterType;
return (SNode*)pStmt;
}
SNode* createDropUserStmt(SAstCreateContext* pCxt, const SToken* pUserName) {
if (!checkUserName(pCxt, pUserName)) {
return NULL;
}
SDropUserStmt* pStmt = (SDropUserStmt*)nodesMakeNode(QUERY_NODE_DROP_USER_STMT);
CHECK_OUT_OF_MEM(pStmt);
strncpy(pStmt->useName, pUserName->z, pUserName->n);
return (SNode*)pStmt;
}
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort) {
int32_t port = 0;
char fqdn[TSDB_FQDN_LEN] = {0};
if (NULL == pPort) {
if (!checkAndSplitEndpoint(pCxt, pFqdn, fqdn, &port)) {
return NULL;
}
} else if (!checkFqdn(pCxt, pFqdn) || !checkPort(pCxt, pPort, &port)) {
return NULL;
}
SCreateDnodeStmt* pStmt = (SCreateDnodeStmt*)nodesMakeNode(QUERY_NODE_CREATE_DNODE_STMT);
CHECK_OUT_OF_MEM(pStmt);
if (NULL == pPort) {
strcpy(pStmt->fqdn, fqdn);
} else {
strncpy(pStmt->fqdn, pFqdn->z, pFqdn->n);
}
pStmt->port = port;
return (SNode*)pStmt;
}
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
SDropDnodeStmt* pStmt = (SDropDnodeStmt*)nodesMakeNode(QUERY_NODE_DROP_DNODE_STMT);
CHECK_OUT_OF_MEM(pStmt);
if (TK_NK_INTEGER == pDnode->type) {
pStmt->dnodeId = strtol(pDnode->z, NULL, 10);
} else {
if (!checkAndSplitEndpoint(pCxt, pDnode, pStmt->fqdn, &pStmt->port)) {
nodesDestroyNode(pStmt);
return NULL;
}
}
return (SNode*)pStmt;
}
......@@ -46,7 +46,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
case TK_NK_COMMENT: {
break;
}
case TK_SEMI: {
case TK_NK_SEMI: {
NewParse(pParser, 0, t0, &cxt);
goto abort_parse;
}
......
此差异已折叠。
......@@ -15,6 +15,63 @@
#include "parserUtil.h"
static char* getSyntaxErrFormat(int32_t errCode) {
switch (errCode) {
case TSDB_CODE_PAR_SYNTAX_ERROR:
return "syntax error near \"%s\"";
case TSDB_CODE_PAR_INCOMPLETE_SQL:
return "Incomplete SQL statement";
case TSDB_CODE_PAR_INVALID_COLUMN:
return "Invalid column name : %s";
case TSDB_CODE_PAR_TABLE_NOT_EXIST:
return "Table does not exist : %s";
case TSDB_CODE_PAR_AMBIGUOUS_COLUMN:
return "Column ambiguously defined : %s";
case TSDB_CODE_PAR_WRONG_VALUE_TYPE:
return "Invalid value type : %s";
case TSDB_CODE_PAR_INVALID_FUNTION:
return "Invalid function name : %s";
case TSDB_CODE_PAR_FUNTION_PARA_NUM:
return "Invalid number of arguments : %s";
case TSDB_CODE_PAR_FUNTION_PARA_TYPE:
return "Inconsistent datatypes : %s";
case TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION:
return "There mustn't be aggregation";
case TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT:
return "ORDER BY item must be the number of a SELECT-list expression";
case TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION:
return "Not a GROUP BY expression";
case TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION:
return "Not SELECTed expression";
case TSDB_CODE_PAR_NOT_SINGLE_GROUP:
return "Not a single-group group function";
case TSDB_CODE_PAR_TAGS_NOT_MATCHED:
return "tags number not matched";
case TSDB_CODE_PAR_INVALID_TAG_NAME:
return "invalid tag name : %s";
case TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG:
return "name or password too long";
case TSDB_CODE_PAR_PASSWD_EMPTY:
return "password can not be empty";
case TSDB_CODE_PAR_INVALID_PORT:
return "port should be an integer that is less than 65535 and greater than 0";
case TSDB_CODE_PAR_INVALID_ENDPOINT:
return "endpoint should be in the format of 'fqdn:port'";
case TSDB_CODE_OUT_OF_MEMORY:
return "Out of memory";
default:
return "Unknown error";
}
}
int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...) {
va_list vArgList;
va_start(vArgList, errCode);
vsnprintf(pBuf->buf, pBuf->len, getSyntaxErrFormat(errCode), vArgList);
va_end(vArgList);
return errCode;
}
int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) {
strncpy(pBuf->buf, msg, pBuf->len);
return TSDB_CODE_TSC_INVALID_OPERATION;
......
......@@ -30,6 +30,7 @@ typedef struct SKeyword {
// keywords in sql string
static SKeyword keywordTable[] = {
{"ALL", TK_ALL},
{"ALTER", TK_ALTER},
{"AND", TK_AND},
{"AS", TK_AS},
{"ASC", TK_ASC},
......@@ -49,7 +50,10 @@ static SKeyword keywordTable[] = {
{"DAYS", TK_DAYS},
{"DESC", TK_DESC},
{"DISTINCT", TK_DISTINCT},
{"DNODE", TK_DNODE},
{"DNODES", TK_DNODES},
{"DOUBLE", TK_DOUBLE},
{"DROP", TK_DROP},
{"EXISTS", TK_EXISTS},
// {"FILE", TK_FILE},
{"FILL", TK_FILL},
......@@ -85,11 +89,14 @@ static SKeyword keywordTable[] = {
{"NOW", TK_NOW},
{"NULL", TK_NULL},
{"OFFSET", TK_OFFSET},
{"PRECISION", TK_PRECISION},
{"PREV", TK_PREV},
{"ON", TK_ON},
{"OR", TK_OR},
{"ORDER", TK_ORDER},
{"PASS", TK_PASS},
{"PORT", TK_PORT},
{"PRECISION", TK_PRECISION},
{"PRIVILEGE", TK_PRIVILEGE},
{"PREV", TK_PREV},
{"QUORUM", TK_QUORUM},
{"REPLICA", TK_REPLICA},
{"SELECT", TK_SELECT},
......@@ -102,6 +109,7 @@ static SKeyword keywordTable[] = {
{"SMALLINT", TK_SMALLINT},
{"SOFFSET", TK_SOFFSET},
{"STABLE", TK_STABLE},
{"STABLES", TK_STABLES},
{"STATE_WINDOW", TK_STATE_WINDOW},
{"STREAM_MODE", TK_STREAM_MODE},
{"TABLE", TK_TABLE},
......@@ -113,6 +121,8 @@ static SKeyword keywordTable[] = {
{"UNION", TK_UNION},
{"UNSIGNED", TK_UNSIGNED},
{"USE", TK_USE},
{"USER", TK_USER},
{"USERS", TK_USERS},
{"USING", TK_USING},
{"VALUES", TK_VALUES},
{"VARCHAR", TK_VARCHAR},
......@@ -145,9 +155,7 @@ static SKeyword keywordTable[] = {
// {"UPLUS", TK_UPLUS},
// {"BITNOT", TK_BITNOT},
// {"MNODES", TK_MNODES},
// {"DNODES", TK_DNODES},
// {"ACCOUNTS", TK_ACCOUNTS},
// {"USERS", TK_USERS},
// {"MODULES", TK_MODULES},
// {"QUERIES", TK_QUERIES},
// {"CONNECTIONS", TK_CONNECTIONS},
......@@ -156,16 +164,9 @@ static SKeyword keywordTable[] = {
// {"SCORES", TK_SCORES},
// {"GRANTS", TK_GRANTS},
// {"DOT", TK_DOT},
// {"STABLES", TK_STABLES},
// {"DROP", TK_DROP},
// {"DNODE", TK_DNODE},
// {"USER", TK_USER},
// {"ACCOUNT", TK_ACCOUNT},
// {"DESCRIBE", TK_DESCRIBE},
// {"SYNCDB", TK_SYNCDB},
// {"ALTER", TK_ALTER},
// {"PASS", TK_PASS},
// {"PRIVILEGE", TK_PRIVILEGE},
// {"LOCAL", TK_LOCAL},
// {"PPS", TK_PPS},
// {"TSERIES", TK_TSERIES},
......@@ -235,7 +236,6 @@ static SKeyword keywordTable[] = {
// {"OUTPUTTYPE", TK_OUTPUTTYPE},
// {"AGGREGATE", TK_AGGREGATE},
// {"BUFSIZE", TK_BUFSIZE},
// {"PORT", TK_PORT},
// {"MODE", TK_MODE},
};
......@@ -330,7 +330,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
return 1;
}
case ';': {
*tokenId = TK_SEMI;
*tokenId = TK_NK_SEMI;
return 1;
}
case '+': {
......@@ -537,7 +537,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
}
if (seg == 4) { // ip address
*tokenId = TK_IPTOKEN;
*tokenId = TK_NK_IPTOKEN;
return i;
}
......@@ -648,7 +648,7 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) {
#endif
}
if (t0.type == TK_SEMI) {
if (t0.type == TK_NK_SEMI) {
t0.n = 0;
return t0;
}
......
......@@ -37,8 +37,8 @@ void generateTestT1(MockCatalogService* mcs) {
void generateTestST1(MockCatalogService* mcs) {
ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 2)
.setPrecision(TSDB_TIME_PRECISION_MILLI).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
.addTag("tag1", TSDB_DATA_TYPE_INT).addTag("tag2", TSDB_DATA_TYPE_BINARY, 20)
.addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20);
.addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
.addTag("tag1", TSDB_DATA_TYPE_INT).addTag("tag2", TSDB_DATA_TYPE_BINARY, 20);
builder.done();
mcs->createSubTable("test", "st1", "st1s1", 1);
mcs->createSubTable("test", "st1", "st1s2", 2);
......@@ -62,6 +62,10 @@ int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pM
return mockCatalogService->catalogGetTableDistVgInfo(pTableName, pVgList);
}
int32_t __catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t *tableNum) {
return 0;
}
void initMetaDataEnv() {
mockCatalogService.reset(new MockCatalogService());
......@@ -102,6 +106,14 @@ void initMetaDataEnv() {
stub.set(f.second, __catalogGetTableDistVgInfo);
}
}
{
AddrAny any("libcatalog.so");
std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^catalogGetDBVgVersion$", result);
for (const auto& f : result) {
stub.set(f.second, __catalogGetDBVgVersion);
}
}
}
void generateMetaData() {
......
......@@ -113,6 +113,7 @@ public:
const char* tname = tNameGetTableName(pTableName);
int32_t code = copyTableSchemaMeta(db, tname, &table);
if (TSDB_CODE_SUCCESS != code) {
std::cout << "db : " << db << ", table :" << tname << std::endl;
return code;
}
*pTableMeta = table.release();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册