提交 d351e55a 编写于 作者: D dapan1121

Merge remote-tracking branch 'origin/3.0_query_integrate' into feature/scheduler

......@@ -40,116 +40,121 @@
#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_DNODE 25
#define TK_PORT 26
#define TK_NK_INTEGER 27
#define TK_NK_ID 28
#define TK_NK_IPTOKEN 29
#define TK_DATABASE 30
#define TK_USE 31
#define TK_IF 32
#define TK_NOT 33
#define TK_EXISTS 34
#define TK_BLOCKS 35
#define TK_CACHE 36
#define TK_CACHELAST 37
#define TK_COMP 38
#define TK_DAYS 39
#define TK_FSYNC 40
#define TK_MAXROWS 41
#define TK_MINROWS 42
#define TK_KEEP 43
#define TK_PRECISION 44
#define TK_QUORUM 45
#define TK_REPLICA 46
#define TK_TTL 47
#define TK_WAL 48
#define TK_VGROUPS 49
#define TK_SINGLE_STABLE 50
#define TK_STREAM_MODE 51
#define TK_TABLE 52
#define TK_NK_LP 53
#define TK_NK_RP 54
#define TK_STABLE 55
#define TK_USING 56
#define TK_TAGS 57
#define TK_NK_DOT 58
#define TK_NK_COMMA 59
#define TK_COMMENT 60
#define TK_BOOL 61
#define TK_TINYINT 62
#define TK_SMALLINT 63
#define TK_INT 64
#define TK_INTEGER 65
#define TK_BIGINT 66
#define TK_FLOAT 67
#define TK_DOUBLE 68
#define TK_BINARY 69
#define TK_TIMESTAMP 70
#define TK_NCHAR 71
#define TK_UNSIGNED 72
#define TK_JSON 73
#define TK_VARCHAR 74
#define TK_MEDIUMBLOB 75
#define TK_BLOB 76
#define TK_VARBINARY 77
#define TK_DECIMAL 78
#define TK_SMA 79
#define TK_SHOW 80
#define TK_DNODES 81
#define TK_USERS 82
#define TK_DATABASES 83
#define TK_TABLES 84
#define TK_STABLES 85
#define TK_MNODES 86
#define TK_NK_FLOAT 87
#define TK_NK_BOOL 88
#define TK_NK_VARIABLE 89
#define TK_BETWEEN 90
#define TK_IS 91
#define TK_NULL 92
#define TK_NK_LT 93
#define TK_NK_GT 94
#define TK_NK_LE 95
#define TK_NK_GE 96
#define TK_NK_NE 97
#define TK_NK_EQ 98
#define TK_LIKE 99
#define TK_MATCH 100
#define TK_NMATCH 101
#define TK_IN 102
#define TK_FROM 103
#define TK_AS 104
#define TK_JOIN 105
#define TK_ON 106
#define TK_INNER 107
#define TK_SELECT 108
#define TK_DISTINCT 109
#define TK_WHERE 110
#define TK_PARTITION 111
#define TK_BY 112
#define TK_SESSION 113
#define TK_STATE_WINDOW 114
#define TK_INTERVAL 115
#define TK_SLIDING 116
#define TK_FILL 117
#define TK_VALUE 118
#define TK_NONE 119
#define TK_PREV 120
#define TK_LINEAR 121
#define TK_NEXT 122
#define TK_GROUP 123
#define TK_HAVING 124
#define TK_ORDER 125
#define TK_SLIMIT 126
#define TK_SOFFSET 127
#define TK_LIMIT 128
#define TK_OFFSET 129
#define TK_ASC 130
#define TK_DESC 131
#define TK_NULLS 132
#define TK_FIRST 133
#define TK_LAST 134
#define TK_MODULES 87
#define TK_QNODES 88
#define TK_FUNCTIONS 89
#define TK_INDEXES 90
#define TK_FROM 91
#define TK_STREAMS 92
#define TK_LIKE 93
#define TK_NK_FLOAT 94
#define TK_NK_BOOL 95
#define TK_NK_VARIABLE 96
#define TK_BETWEEN 97
#define TK_IS 98
#define TK_NULL 99
#define TK_NK_LT 100
#define TK_NK_GT 101
#define TK_NK_LE 102
#define TK_NK_GE 103
#define TK_NK_NE 104
#define TK_NK_EQ 105
#define TK_MATCH 106
#define TK_NMATCH 107
#define TK_IN 108
#define TK_AS 109
#define TK_JOIN 110
#define TK_ON 111
#define TK_INNER 112
#define TK_SELECT 113
#define TK_DISTINCT 114
#define TK_WHERE 115
#define TK_PARTITION 116
#define TK_BY 117
#define TK_SESSION 118
#define TK_STATE_WINDOW 119
#define TK_INTERVAL 120
#define TK_SLIDING 121
#define TK_FILL 122
#define TK_VALUE 123
#define TK_NONE 124
#define TK_PREV 125
#define TK_LINEAR 126
#define TK_NEXT 127
#define TK_GROUP 128
#define TK_HAVING 129
#define TK_ORDER 130
#define TK_SLIMIT 131
#define TK_SOFFSET 132
#define TK_LIMIT 133
#define TK_OFFSET 134
#define TK_ASC 135
#define TK_DESC 136
#define TK_NULLS 137
#define TK_FIRST 138
#define TK_LAST 139
#define TK_NK_SPACE 300
#define TK_NK_COMMENT 301
......
......@@ -152,7 +152,8 @@ typedef struct SDropDnodeStmt {
typedef struct SShowStmt {
ENodeType type;
char dbName[TSDB_DB_NAME_LEN];
SNode* pDbName; // SValueNode
SNode* pTbNamePattern; // SValueNode
} SShowStmt;
#ifdef __cplusplus
......
......@@ -74,25 +74,30 @@ typedef enum ENodeType {
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_DROP_TABLE_CLAUSE,
QUERY_NODE_DROP_TABLE_STMT,
QUERY_NODE_DROP_SUPER_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_DATABASES_STMT,
QUERY_NODE_SHOW_TABLES_STMT,
QUERY_NODE_SHOW_STABLES_STMT,
QUERY_NODE_SHOW_USERS_STMT,
QUERY_NODE_SHOW_DNODES_STMT,
QUERY_NODE_SHOW_VGROUPS_STMT,
QUERY_NODE_SHOW_MNODES_STMT,
QUERY_NODE_SHOW_MODULES_STMT,
QUERY_NODE_SHOW_QNODES_STMT,
QUERY_NODE_SHOW_FUNCTIONS_STMT,
QUERY_NODE_SHOW_INDEXES_STMT,
QUERY_NODE_SHOW_STREAMS_STMT,
// logic plan node
QUERY_NODE_LOGIC_PLAN_SCAN,
......
......@@ -217,7 +217,7 @@ typedef struct SSubplan {
ESubplanType subplanType;
int32_t msgType; // message type for subplan, used to denote the send message type to vnode.
int32_t level; // the execution level of current subplan, starting from 0 in a top-down manner.
char dbFName[TSDB_DB_FNAME_LEN];
char dbFName[TSDB_DB_FNAME_LEN];
SQueryNodeAddr execNode; // for the scan/modify subplan, the optional execution node
SQueryNodeStat execNodeStat; // only for scan subplan
SNodeList* pChildren; // the datasource subplan,from which to fetch the result
......
......@@ -64,7 +64,7 @@ static const SInfosTableSchema userFuncSchema[] = {{.name = "name", .b
{.name = "precision", .bytes = 2, .type = TSDB_DATA_TYPE_BINARY},
{.name = "status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY},
};
static const SInfosTableSchema userIdxSchema[] = {{.name = "table_database", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
static const SInfosTableSchema userIdxSchema[] = {{.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
{.name = "table_name", .bytes = 192, .type = TSDB_DATA_TYPE_BINARY},
{.name = "index_database", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
{.name = "index_name", .bytes = 192, .type = TSDB_DATA_TYPE_BINARY},
......@@ -112,6 +112,7 @@ static const SInfosTableSchema userUsersSchema[] = {{.name = "user_name", .
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
};
static const SInfosTableSchema vgroupsSchema[] = {{.name = "vg_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
{.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
{.name = "tables", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
{.name = "status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY},
{.name = "onlines", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
......
......@@ -31,6 +31,9 @@
#define COPY_CHAR_POINT_FIELD(fldname) \
do { \
if (NULL == (pSrc)->fldname) { \
break; \
} \
(pDst)->fldname = strdup((pSrc)->fldname); \
} while (0)
......
......@@ -85,9 +85,7 @@ SNodeptr nodesMakeNode(ENodeType type) {
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(SShowStmt));
return makeNode(type, sizeof(SDropDatabaseStmt));
case QUERY_NODE_CREATE_TABLE_STMT:
return makeNode(type, sizeof(SCreateTableStmt));
case QUERY_NODE_CREATE_SUBTABLE_CLAUSE:
......@@ -100,27 +98,30 @@ SNodeptr nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(SDropTableStmt));
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
return makeNode(type, sizeof(SDropSuperTableStmt));
case QUERY_NODE_SHOW_TABLES_STMT:
case QUERY_NODE_SHOW_STABLES_STMT:
return makeNode(type, sizeof(SShowStmt));
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(SShowStmt));
case QUERY_NODE_USE_DATABASE_STMT:
return makeNode(type, sizeof(SUseDatabaseStmt));
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_DATABASES_STMT:
case QUERY_NODE_SHOW_TABLES_STMT:
case QUERY_NODE_SHOW_STABLES_STMT:
case QUERY_NODE_SHOW_USERS_STMT:
case QUERY_NODE_SHOW_DNODES_STMT:
return makeNode(type, sizeof(SShowStmt));
case QUERY_NODE_SHOW_VGROUPS_STMT:
case QUERY_NODE_SHOW_MNODES_STMT:
case QUERY_NODE_SHOW_MODULES_STMT:
case QUERY_NODE_SHOW_QNODES_STMT:
case QUERY_NODE_SHOW_FUNCTIONS_STMT:
case QUERY_NODE_SHOW_INDEXES_STMT:
case QUERY_NODE_SHOW_STREAMS_STMT:
return makeNode(type, sizeof(SShowStmt));
case QUERY_NODE_LOGIC_PLAN_SCAN:
return makeNode(type, sizeof(SScanLogicNode));
......
......@@ -126,7 +126,7 @@ SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNod
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables);
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName);
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDbName);
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern);
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);
......
......@@ -41,19 +41,17 @@
%left NK_CONCAT.
//%right NK_BITNOT.
/************************************************ create/alter/drop/show user *****************************************/
/************************************************ create/alter/drop user **********************************************/
cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B);}
cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B);}
cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B);}
cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); }
cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); }
/************************************************ create/drop/show dnode **********************************************/
/************************************************ create/drop dnode ***************************************************/
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL);}
cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B);}
cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);}
cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);}
cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); }
%type dnode_endpoint { SToken }
%destructor dnode_endpoint { }
......@@ -64,10 +62,9 @@ dnode_endpoint(A) ::= NK_STRING(B).
dnode_host_name(A) ::= NK_ID(B). { A = B; }
dnode_host_name(A) ::= NK_IPTOKEN(B). { A = B; }
/************************************************ create/drop/show/use database ***************************************/
/************************************************ create/drop/use database ********************************************/
cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C);}
cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); }
cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); }
cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A);}
%type not_exists_opt { bool }
......@@ -101,7 +98,7 @@ 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/drop/show table/stable ***************************************/
/************************************************ create/drop 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);}
......@@ -109,8 +106,6 @@ cmd ::= CREATE STABLE not_exists_opt(A) full_table_name(B)
NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);}
cmd ::= DROP TABLE multi_drop_clause(A). { pCxt->pRootNode = createDropTableStmt(pCxt, A); }
cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
cmd ::= SHOW TABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, NULL); }
cmd ::= SHOW STABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, NULL); }
%type multi_create_clause { SNodeList* }
%destructor multi_create_clause { nodesDestroyList($$); }
......@@ -194,12 +189,30 @@ 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 vgroups ********************************************************/
cmd ::= SHOW VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, NULL); }
cmd ::= SHOW db_name(B) NK_DOT VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &B); }
/************************************************ show vgroups ********************************************************/
cmd ::= SHOW MNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL); }
/************************************************ show ****************************************************************/
cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); }
cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL, NULL); }
cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); }
cmd ::= SHOW db_name_cond_opt(A) TABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, A, B); }
cmd ::= SHOW db_name_cond_opt(A) STABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, A, B); }
cmd ::= SHOW db_name_cond_opt(A) VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, A, NULL); }
cmd ::= SHOW MNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); }
cmd ::= SHOW MODULES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT, NULL, NULL); }
cmd ::= SHOW QNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL, NULL); }
cmd ::= SHOW FUNCTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); }
cmd ::= SHOW INDEXES FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, A, B); }
cmd ::= SHOW STREAMS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); }
db_name_cond_opt(A) ::= . { A = NULL; }
db_name_cond_opt(A) ::= db_name(B) NK_DOT. { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); }
like_pattern_opt(A) ::= . { A = NULL; }
like_pattern_opt(A) ::= LIKE NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); }
table_name_cond(A) ::= table_name(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); }
from_db_opt(A) ::= . { A = NULL; }
from_db_opt(A) ::= FROM db_name(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); }
/************************************************ select **************************************************************/
cmd ::= query_expression(A). { pCxt->pRootNode = A; }
......
......@@ -21,6 +21,7 @@
do { \
if (NULL == (p)) { \
pCxt->valid = false; \
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); \
return NULL; \
} \
} while (0)
......@@ -903,17 +904,11 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
return (SNode*)pStmt;
}
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDbName) {
if (!checkDbName(pCxt, pDbName, false)) {
return NULL;
}
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern) {
SShowStmt* pStmt = nodesMakeNode(type);;
CHECK_OUT_OF_MEM(pStmt);
if (NULL != pDbName) {
strncpy(pStmt->dbName, pDbName->z, pDbName->n);
} else if (NULL != pCxt->pQueryCxt->db) {
strcpy(pStmt->dbName, pCxt->pQueryCxt->db);
}
pStmt->pDbName = pDbName;
pStmt->pTbNamePattern = pTbNamePattern;
return (SNode*)pStmt;
}
......
......@@ -59,11 +59,13 @@ static SKeyword keywordTable[] = {
{"FLOAT", TK_FLOAT},
{"FROM", TK_FROM},
{"FSYNC", TK_FSYNC},
{"FUNCTIONS", TK_FUNCTIONS},
{"GROUP", TK_GROUP},
{"HAVING", TK_HAVING},
{"IF", TK_IF},
{"IMPORT", TK_IMPORT},
{"IN", TK_IN},
{"INDEXES", TK_INDEXES},
{"INNER", TK_INNER},
{"INT", TK_INT},
{"INSERT", TK_INSERT},
......@@ -82,6 +84,7 @@ static SKeyword keywordTable[] = {
{"MINROWS", TK_MINROWS},
{"MINUS", TK_MINUS},
{"MNODES", TK_MNODES},
{"MODULES", TK_MODULES},
{"NCHAR", TK_NCHAR},
{"NMATCH", TK_NMATCH},
{"NONE", TK_NONE},
......@@ -97,6 +100,7 @@ static SKeyword keywordTable[] = {
{"PRECISION", TK_PRECISION},
{"PRIVILEGE", TK_PRIVILEGE},
{"PREV", TK_PREV},
{"QNODES", TK_QNODES},
{"QUORUM", TK_QUORUM},
{"REPLICA", TK_REPLICA},
{"SELECT", TK_SELECT},
......@@ -111,6 +115,7 @@ static SKeyword keywordTable[] = {
{"STABLE", TK_STABLE},
{"STABLES", TK_STABLES},
{"STATE_WINDOW", TK_STATE_WINDOW},
{"STREAMS", TK_STREAMS},
{"STREAM_MODE", TK_STREAM_MODE},
{"TABLE", TK_TABLE},
{"TABLES", TK_TABLES},
......@@ -155,10 +160,8 @@ static SKeyword keywordTable[] = {
// {"UPLUS", TK_UPLUS},
// {"BITNOT", TK_BITNOT},
// {"ACCOUNTS", TK_ACCOUNTS},
// {"MODULES", TK_MODULES},
// {"QUERIES", TK_QUERIES},
// {"CONNECTIONS", TK_CONNECTIONS},
// {"STREAMS", TK_STREAMS},
// {"VARIABLES", TK_VARIABLES},
// {"SCORES", TK_SCORES},
// {"GRANTS", TK_GRANTS},
......@@ -231,7 +234,6 @@ static SKeyword keywordTable[] = {
// {"COMPACT", TK_COMPACT},
// {"MODIFY", TK_MODIFY},
// {"FUNCTION", TK_FUNCTION},
// {"FUNCTIONS", TK_FUNCTIONS},
// {"OUTPUTTYPE", TK_OUTPUTTYPE},
// {"AGGREGATE", TK_AGGREGATE},
// {"BUFSIZE", TK_BUFSIZE},
......
......@@ -1149,12 +1149,12 @@ static int32_t nodeTypeToShowType(ENodeType nt) {
static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) {
SShowReq showReq = { .type = nodeTypeToShowType(nodeType(pStmt)) };
if ('\0' != pStmt->dbName[0]) {
SName name = {0};
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
char dbFname[TSDB_DB_FNAME_LEN] = {0};
tNameGetFullDbName(&name, showReq.db);
}
// if ('\0' != pStmt->dbName[0]) {
// SName name = {0};
// tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
// char dbFname[TSDB_DB_FNAME_LEN] = {0};
// tNameGetFullDbName(&name, showReq.db);
// }
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
if (NULL== pCxt->pCmdMsg) {
......@@ -1302,25 +1302,142 @@ static void destroyTranslateContext(STranslateContext* pCxt) {
}
}
static int32_t rewriteShowDatabase(STranslateContext* pCxt, SQuery* pQuery) {
SSelectStmt* pStmt = nodesMakeNode(QUERY_NODE_SELECT_STMT);
if (NULL == pStmt) {
static const char* getSysTableName(ENodeType type) {
switch (type) {
case QUERY_NODE_SHOW_DATABASES_STMT:
return TSDB_INS_TABLE_USER_DATABASES;
case QUERY_NODE_SHOW_TABLES_STMT:
return TSDB_INS_TABLE_USER_TABLES;
case QUERY_NODE_SHOW_STABLES_STMT:
return TSDB_INS_TABLE_USER_STABLES;
case QUERY_NODE_SHOW_USERS_STMT:
return TSDB_INS_TABLE_USER_USERS;
case QUERY_NODE_SHOW_DNODES_STMT:
return TSDB_INS_TABLE_DNODES;
case QUERY_NODE_SHOW_VGROUPS_STMT:
return TSDB_INS_TABLE_VGROUPS;
case QUERY_NODE_SHOW_MNODES_STMT:
return TSDB_INS_TABLE_MNODES;
case QUERY_NODE_SHOW_MODULES_STMT:
return TSDB_INS_TABLE_MODULES;
case QUERY_NODE_SHOW_QNODES_STMT:
return TSDB_INS_TABLE_QNODES;
case QUERY_NODE_SHOW_FUNCTIONS_STMT:
return TSDB_INS_TABLE_USER_FUNCTIONS;
case QUERY_NODE_SHOW_INDEXES_STMT:
return TSDB_INS_TABLE_USER_INDEXES;
case QUERY_NODE_SHOW_STREAMS_STMT:
return TSDB_INS_TABLE_USER_STREAMS;
default:
break;
}
return NULL;
}
static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt) {
SSelectStmt* pSelect = nodesMakeNode(QUERY_NODE_SELECT_STMT);
if (NULL == pSelect) {
return TSDB_CODE_OUT_OF_MEMORY;
}
SRealTableNode* pTable = nodesMakeNode(QUERY_NODE_REAL_TABLE);
if (NULL == pTable) {
nodesDestroyNode(pStmt);
nodesDestroyNode(pSelect);
return TSDB_CODE_OUT_OF_MEMORY;
}
strcpy(pTable->table.dbName, TSDB_INFORMATION_SCHEMA_DB);
strcpy(pTable->table.tableName, TSDB_INS_TABLE_USER_DATABASES);
pStmt->pFromTable = (SNode*)pTable;
strcpy(pTable->table.tableName, getSysTableName(showType));
pSelect->pFromTable = (SNode*)pTable;
*pStmt = pSelect;
nodesDestroyNode(pQuery->pRoot);
pQuery->pRoot = (SNode*)pStmt;
return TSDB_CODE_SUCCESS;
}
static int32_t createOperatorNode(EOperatorType opType, const char* pColName, SNode* pRight, SNode** pOp) {
if (NULL == pRight) {
return TSDB_CODE_SUCCESS;
}
SOperatorNode* pOper = nodesMakeNode(QUERY_NODE_OPERATOR);
if (NULL == pOper) {
return TSDB_CODE_OUT_OF_MEMORY;
}
pOper->opType = OP_TYPE_LIKE;
pOper->pLeft = nodesMakeNode(QUERY_NODE_COLUMN);
pOper->pRight = nodesCloneNode(pRight);
if (NULL == pOper->pLeft || NULL == pOper->pRight) {
nodesDestroyNode(pOper);
return TSDB_CODE_OUT_OF_MEMORY;
}
strcpy(((SColumnNode*)pOper->pLeft)->colName, pColName);
*pOp = (SNode*)pOper;
return TSDB_CODE_SUCCESS;
}
static const char* getTbNameColName(ENodeType type) {
return (QUERY_NODE_SHOW_STABLES_STMT == type ? "stable_name" : "table_name");
}
static int32_t createLogicCondNode(SNode* pCond1, SNode* pCond2, SNode** pCond) {
SLogicConditionNode* pCondition = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
if (NULL == pCondition) {
return TSDB_CODE_OUT_OF_MEMORY;
}
pCondition->condType = LOGIC_COND_TYPE_AND;
pCondition->pParameterList = nodesMakeList();
if (NULL == pCondition->pParameterList) {
nodesDestroyNode(pCondition);
return TSDB_CODE_OUT_OF_MEMORY;
}
if (TSDB_CODE_SUCCESS != nodesListAppend(pCondition->pParameterList, pCond1) ||
TSDB_CODE_SUCCESS != nodesListAppend(pCondition->pParameterList, pCond2)) {
nodesDestroyNode(pCondition);
return TSDB_CODE_OUT_OF_MEMORY;
}
*pCond = (SNode*)pCondition;
return TSDB_CODE_SUCCESS;
}
static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect) {
SNode* pDbCond = NULL;
SNode* pTbCond = NULL;
if (TSDB_CODE_SUCCESS != createOperatorNode(OP_TYPE_EQUAL, "db_name", pShow->pDbName, &pDbCond) ||
TSDB_CODE_SUCCESS != createOperatorNode(OP_TYPE_LIKE, getTbNameColName(nodeType(pShow)), pShow->pTbNamePattern, &pTbCond)) {
nodesDestroyNode(pDbCond);
nodesDestroyNode(pTbCond);
return TSDB_CODE_OUT_OF_MEMORY;
}
if (NULL != pDbCond && NULL != pTbCond) {
if (TSDB_CODE_SUCCESS != createLogicCondNode(pDbCond, pTbCond, &pSelect->pWhere)) {
nodesDestroyNode(pDbCond);
nodesDestroyNode(pTbCond);
return TSDB_CODE_OUT_OF_MEMORY;
}
} else {
pSelect->pWhere = (NULL == pDbCond ? pTbCond : pDbCond);
}
return TSDB_CODE_SUCCESS;
}
static int32_t rewriteShow(STranslateContext* pCxt, SQuery* pQuery) {
SSelectStmt* pStmt = NULL;
int32_t code = createSelectStmtForShow(nodeType(pQuery->pRoot), &pStmt);
if (TSDB_CODE_SUCCESS == code) {
code = createShowCondition((SShowStmt*)pQuery->pRoot, pStmt);
}
if (TSDB_CODE_SUCCESS == code) {
nodesDestroyNode(pQuery->pRoot);
pQuery->pRoot = (SNode*)pStmt;
}
return code;
}
typedef struct SVgroupTablesBatch {
SVCreateTbBatchReq req;
SVgroupInfo info;
......@@ -1685,7 +1802,18 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
int32_t code = TSDB_CODE_SUCCESS;
switch (nodeType(pQuery->pRoot)) {
case QUERY_NODE_SHOW_DATABASES_STMT:
code = rewriteShowDatabase(pCxt, pQuery);
case QUERY_NODE_SHOW_TABLES_STMT:
case QUERY_NODE_SHOW_STABLES_STMT:
case QUERY_NODE_SHOW_USERS_STMT:
case QUERY_NODE_SHOW_DNODES_STMT:
case QUERY_NODE_SHOW_VGROUPS_STMT:
case QUERY_NODE_SHOW_MNODES_STMT:
case QUERY_NODE_SHOW_MODULES_STMT:
case QUERY_NODE_SHOW_QNODES_STMT:
case QUERY_NODE_SHOW_FUNCTIONS_STMT:
case QUERY_NODE_SHOW_INDEXES_STMT:
case QUERY_NODE_SHOW_STREAMS_STMT:
code = rewriteShow(pCxt, pQuery);
break;
case QUERY_NODE_CREATE_TABLE_STMT:
if (NULL == ((SCreateTableStmt*)pQuery->pRoot)->pTags) {
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -26,6 +26,64 @@
#include "mockCatalog.h"
namespace {
void generateInformationSchema(MockCatalogService* mcs) {
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnodes", TSDB_NORMAL_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "mnodes", TSDB_NORMAL_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "modules", TSDB_NORMAL_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "qnodes", TSDB_NORMAL_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_databases", TSDB_NORMAL_TABLE, 1).addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_functions", TSDB_NORMAL_TABLE, 1).addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_indexes", TSDB_NORMAL_TABLE, 2)
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_stables", TSDB_NORMAL_TABLE, 2)
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("stable_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_streams", TSDB_NORMAL_TABLE, 1).addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_tables", TSDB_NORMAL_TABLE, 2)
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_table_distributed", TSDB_NORMAL_TABLE, 1).addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_users", TSDB_NORMAL_TABLE, 1).addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN);
builder.done();
}
{
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "vgroups", TSDB_NORMAL_TABLE, 1).addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
builder.done();
}
}
void generateTestT1(MockCatalogService* mcs) {
ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6)
.setPrecision(TSDB_TIME_PRECISION_MILLI).setVgid(1).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
......@@ -74,6 +132,7 @@ void initMetaDataEnv() {
stub.set(catalogGetTableMeta, __catalogGetTableMeta);
stub.set(catalogGetTableHashVgroup, __catalogGetTableHashVgroup);
stub.set(catalogGetTableDistVgInfo, __catalogGetTableDistVgInfo);
stub.set(catalogGetDBVgVersion, __catalogGetDBVgVersion);
// {
// AddrAny any("libcatalog.so");
// std::map<std::string,void*> result;
......@@ -117,6 +176,7 @@ void initMetaDataEnv() {
}
void generateMetaData() {
generateInformationSchema(mockCatalogService.get());
generateTestT1(mockCatalogService.get());
generateTestST1(mockCatalogService.get());
mockCatalogService->showTables();
......
......@@ -295,6 +295,13 @@ TEST_F(ParserTest, createUser) {
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showUsers) {
setDatabase("root", "test");
bind("show users");
ASSERT_TRUE(run());
}
TEST_F(ParserTest, createDnode) {
setDatabase("root", "test");
......@@ -305,6 +312,13 @@ TEST_F(ParserTest, createDnode) {
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showDnodes) {
setDatabase("root", "test");
bind("show dnodes");
ASSERT_TRUE(run());
}
TEST_F(ParserTest, createDatabase) {
setDatabase("root", "test");
......@@ -333,7 +347,7 @@ TEST_F(ParserTest, createDatabase) {
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showDatabase) {
TEST_F(ParserTest, showDatabases) {
setDatabase("root", "test");
bind("show databases");
......@@ -391,3 +405,90 @@ TEST_F(ParserTest, createTable) {
);
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showTables) {
setDatabase("root", "test");
// bind("show tables");
// ASSERT_TRUE(run());
// bind("show test.tables");
// ASSERT_TRUE(run());
bind("show tables like 'c%'");
ASSERT_TRUE(run());
bind("show test.tables like 'c%'");
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showStables) {
setDatabase("root", "test");
bind("show stables");
ASSERT_TRUE(run());
bind("show test.stables");
ASSERT_TRUE(run());
bind("show stables like 'c%'");
ASSERT_TRUE(run());
bind("show test.stables like 'c%'");
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showVgroups) {
setDatabase("root", "test");
bind("show vgroups");
ASSERT_TRUE(run());
bind("show test.vgroups");
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showMnodes) {
setDatabase("root", "test");
bind("show mnodes");
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showModules) {
setDatabase("root", "test");
bind("show modules");
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showQnodes) {
setDatabase("root", "test");
bind("show qnodes");
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showFunctions) {
setDatabase("root", "test");
bind("show functions");
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showIndexes) {
setDatabase("root", "test");
bind("show indexes from t1");
ASSERT_TRUE(run());
bind("show indexes from t1 from test");
ASSERT_TRUE(run());
}
TEST_F(ParserTest, showStreams) {
setDatabase("root", "test");
bind("show streams");
ASSERT_TRUE(run());
}
......@@ -131,7 +131,7 @@ private:
TEST_F(InsertTest, singleTableSingleRowTest) {
setDatabase("root", "test");
bind("insert into t1 values (now, 1, \"beijing\")");
bind("insert into t1 values (now, 1, 'beijing', 3, 4, 5)");
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
dumpReslut();
checkReslut(1, 1);
......@@ -141,7 +141,7 @@ TEST_F(InsertTest, singleTableSingleRowTest) {
TEST_F(InsertTest, singleTableMultiRowTest) {
setDatabase("root", "test");
bind("insert into t1 values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")");
bind("insert into t1 values (now, 1, 'beijing', 3, 4, 5)(now+1s, 2, 'shanghai', 6, 7, 8)(now+2s, 3, 'guangzhou', 9, 10, 11)");
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
dumpReslut();
checkReslut(1, 3);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册