未验证 提交 c20d5741 编写于 作者: H haojun Liao 提交者: GitHub

Merge pull request #4938 from taosdata/feature/TD-2671

[TD-2671]<fix>:support create/drop/alter stable
...@@ -264,6 +264,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -264,6 +264,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
case TSDB_SQL_DROP_DB: { case TSDB_SQL_DROP_DB: {
const char* msg2 = "invalid name"; const char* msg2 = "invalid name";
const char* msg3 = "param name too long"; const char* msg3 = "param name too long";
const char* msg4 = "table is not super table";
SStrToken* pzName = &pInfo->pDCLInfo->a[0]; SStrToken* pzName = &pInfo->pDCLInfo->a[0];
if ((pInfo->type != TSDB_SQL_DROP_DNODE) && (tscValidateName(pzName) != TSDB_CODE_SUCCESS)) { if ((pInfo->type != TSDB_SQL_DROP_DNODE) && (tscValidateName(pzName) != TSDB_CODE_SUCCESS)) {
...@@ -285,6 +286,18 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -285,6 +286,18 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if(code != TSDB_CODE_SUCCESS) { if(code != TSDB_CODE_SUCCESS) {
return code; return code;
} }
if (pInfo->pDCLInfo->tableType == TSDB_SUPER_TABLE) {
code = tscGetTableMeta(pSql, pTableMetaInfo);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
if (!UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
}
}
} else if (pInfo->type == TSDB_SQL_DROP_DNODE) { } else if (pInfo->type == TSDB_SQL_DROP_DNODE) {
pzName->n = strdequote(pzName->z); pzName->n = strdequote(pzName->z);
strncpy(pTableMetaInfo->name, pzName->z, pzName->n); strncpy(pTableMetaInfo->name, pzName->z, pzName->n);
...@@ -4794,6 +4807,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4794,6 +4807,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const char* msg17 = "invalid column name"; const char* msg17 = "invalid column name";
const char* msg18 = "primary timestamp column cannot be dropped"; const char* msg18 = "primary timestamp column cannot be dropped";
const char* msg19 = "invalid new tag name"; const char* msg19 = "invalid new tag name";
const char* msg20 = "table is not super table";
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
...@@ -4819,6 +4833,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -4819,6 +4833,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
if (pAlterSQL->tableType == TSDB_SUPER_TABLE && !(UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo))) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg20);
}
if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN || pAlterSQL->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN || if (pAlterSQL->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN || pAlterSQL->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN ||
pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) { pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) {
if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) { if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) {
......
...@@ -2193,7 +2193,7 @@ int tscProcessDropTableRsp(SSqlObj *pSql) { ...@@ -2193,7 +2193,7 @@ int tscProcessDropTableRsp(SSqlObj *pSql) {
tscDebug("%p remove table meta after drop table:%s, numOfRemain:%d", pSql, pTableMetaInfo->name, tscDebug("%p remove table meta after drop table:%s, numOfRemain:%d", pSql, pTableMetaInfo->name,
(int32_t) taosHashGetSize(tscTableMetaInfo)); (int32_t) taosHashGetSize(tscTableMetaInfo));
assert(pTableMetaInfo->pTableMeta == NULL); pTableMetaInfo->pTableMeta = NULL;
return 0; return 0;
} }
......
...@@ -82,151 +82,154 @@ ...@@ -82,151 +82,154 @@
#define TK_STABLES 64 #define TK_STABLES 64
#define TK_VGROUPS 65 #define TK_VGROUPS 65
#define TK_DROP 66 #define TK_DROP 66
#define TK_DNODE 67 #define TK_STABLE 67
#define TK_USER 68 #define TK_DNODE 68
#define TK_ACCOUNT 69 #define TK_USER 69
#define TK_USE 70 #define TK_ACCOUNT 70
#define TK_DESCRIBE 71 #define TK_USE 71
#define TK_ALTER 72 #define TK_DESCRIBE 72
#define TK_PASS 73 #define TK_ALTER 73
#define TK_PRIVILEGE 74 #define TK_PASS 74
#define TK_LOCAL 75 #define TK_PRIVILEGE 75
#define TK_IF 76 #define TK_LOCAL 76
#define TK_EXISTS 77 #define TK_IF 77
#define TK_PPS 78 #define TK_EXISTS 78
#define TK_TSERIES 79 #define TK_PPS 79
#define TK_DBS 80 #define TK_TSERIES 80
#define TK_STORAGE 81 #define TK_DBS 81
#define TK_QTIME 82 #define TK_STORAGE 82
#define TK_CONNS 83 #define TK_QTIME 83
#define TK_STATE 84 #define TK_CONNS 84
#define TK_KEEP 85 #define TK_STATE 85
#define TK_CACHE 86 #define TK_KEEP 86
#define TK_REPLICA 87 #define TK_CACHE 87
#define TK_QUORUM 88 #define TK_REPLICA 88
#define TK_DAYS 89 #define TK_QUORUM 89
#define TK_MINROWS 90 #define TK_DAYS 90
#define TK_MAXROWS 91 #define TK_MINROWS 91
#define TK_BLOCKS 92 #define TK_MAXROWS 92
#define TK_CTIME 93 #define TK_BLOCKS 93
#define TK_WAL 94 #define TK_CTIME 94
#define TK_FSYNC 95 #define TK_WAL 95
#define TK_COMP 96 #define TK_FSYNC 96
#define TK_PRECISION 97 #define TK_COMP 97
#define TK_UPDATE 98 #define TK_PRECISION 98
#define TK_CACHELAST 99 #define TK_UPDATE 99
#define TK_LP 100 #define TK_CACHELAST 100
#define TK_RP 101 #define TK_LP 101
#define TK_UNSIGNED 102 #define TK_RP 102
#define TK_TAGS 103 #define TK_UNSIGNED 103
#define TK_USING 104 #define TK_TAGS 104
#define TK_AS 105 #define TK_USING 105
#define TK_COMMA 106 #define TK_AS 106
#define TK_NULL 107 #define TK_COMMA 107
#define TK_SELECT 108 #define TK_NULL 108
#define TK_UNION 109 #define TK_SELECT 109
#define TK_ALL 110 #define TK_UNION 110
#define TK_FROM 111 #define TK_ALL 111
#define TK_VARIABLE 112 #define TK_FROM 112
#define TK_INTERVAL 113 #define TK_VARIABLE 113
#define TK_FILL 114 #define TK_INTERVAL 114
#define TK_SLIDING 115 #define TK_FILL 115
#define TK_ORDER 116 #define TK_SLIDING 116
#define TK_BY 117 #define TK_ORDER 117
#define TK_ASC 118 #define TK_BY 118
#define TK_DESC 119 #define TK_ASC 119
#define TK_GROUP 120 #define TK_DESC 120
#define TK_HAVING 121 #define TK_GROUP 121
#define TK_LIMIT 122 #define TK_HAVING 122
#define TK_OFFSET 123 #define TK_LIMIT 123
#define TK_SLIMIT 124 #define TK_OFFSET 124
#define TK_SOFFSET 125 #define TK_SLIMIT 125
#define TK_WHERE 126 #define TK_SOFFSET 126
#define TK_NOW 127 #define TK_WHERE 127
#define TK_RESET 128 #define TK_NOW 128
#define TK_QUERY 129 #define TK_RESET 129
#define TK_ADD 130 #define TK_QUERY 130
#define TK_COLUMN 131 #define TK_ADD 131
#define TK_TAG 132 #define TK_COLUMN 132
#define TK_CHANGE 133 #define TK_TAG 133
#define TK_SET 134 #define TK_CHANGE 134
#define TK_KILL 135 #define TK_SET 135
#define TK_CONNECTION 136 #define TK_KILL 136
#define TK_STREAM 137 #define TK_CONNECTION 137
#define TK_COLON 138 #define TK_STREAM 138
#define TK_ABORT 139 #define TK_COLON 139
#define TK_AFTER 140 #define TK_ABORT 140
#define TK_ATTACH 141 #define TK_AFTER 141
#define TK_BEFORE 142 #define TK_ATTACH 142
#define TK_BEGIN 143 #define TK_BEFORE 143
#define TK_CASCADE 144 #define TK_BEGIN 144
#define TK_CLUSTER 145 #define TK_CASCADE 145
#define TK_CONFLICT 146 #define TK_CLUSTER 146
#define TK_COPY 147 #define TK_CONFLICT 147
#define TK_DEFERRED 148 #define TK_COPY 148
#define TK_DELIMITERS 149 #define TK_DEFERRED 149
#define TK_DETACH 150 #define TK_DELIMITERS 150
#define TK_EACH 151 #define TK_DETACH 151
#define TK_END 152 #define TK_EACH 152
#define TK_EXPLAIN 153 #define TK_END 153
#define TK_FAIL 154 #define TK_EXPLAIN 154
#define TK_FOR 155 #define TK_FAIL 155
#define TK_IGNORE 156 #define TK_FOR 156
#define TK_IMMEDIATE 157 #define TK_IGNORE 157
#define TK_INITIALLY 158 #define TK_IMMEDIATE 158
#define TK_INSTEAD 159 #define TK_INITIALLY 159
#define TK_MATCH 160 #define TK_INSTEAD 160
#define TK_KEY 161 #define TK_MATCH 161
#define TK_OF 162 #define TK_KEY 162
#define TK_RAISE 163 #define TK_OF 163
#define TK_REPLACE 164 #define TK_RAISE 164
#define TK_RESTRICT 165 #define TK_REPLACE 165
#define TK_ROW 166 #define TK_RESTRICT 166
#define TK_STATEMENT 167 #define TK_ROW 167
#define TK_TRIGGER 168 #define TK_STATEMENT 168
#define TK_VIEW 169 #define TK_TRIGGER 169
#define TK_COUNT 170 #define TK_VIEW 170
#define TK_SUM 171 #define TK_COUNT 171
#define TK_AVG 172 #define TK_SUM 172
#define TK_MIN 173 #define TK_AVG 173
#define TK_MAX 174 #define TK_MIN 174
#define TK_FIRST 175 #define TK_MAX 175
#define TK_LAST 176 #define TK_FIRST 176
#define TK_TOP 177 #define TK_LAST 177
#define TK_BOTTOM 178 #define TK_TOP 178
#define TK_STDDEV 179 #define TK_BOTTOM 179
#define TK_PERCENTILE 180 #define TK_STDDEV 180
#define TK_APERCENTILE 181 #define TK_PERCENTILE 181
#define TK_LEASTSQUARES 182 #define TK_APERCENTILE 182
#define TK_HISTOGRAM 183 #define TK_LEASTSQUARES 183
#define TK_DIFF 184 #define TK_HISTOGRAM 184
#define TK_SPREAD 185 #define TK_DIFF 185
#define TK_TWA 186 #define TK_SPREAD 186
#define TK_INTERP 187 #define TK_TWA 187
#define TK_LAST_ROW 188 #define TK_INTERP 188
#define TK_RATE 189 #define TK_LAST_ROW 189
#define TK_IRATE 190 #define TK_RATE 190
#define TK_SUM_RATE 191 #define TK_IRATE 191
#define TK_SUM_IRATE 192 #define TK_SUM_RATE 192
#define TK_AVG_RATE 193 #define TK_SUM_IRATE 193
#define TK_AVG_IRATE 194 #define TK_AVG_RATE 194
#define TK_TBID 195 #define TK_AVG_IRATE 195
#define TK_SEMI 196 #define TK_TBID 196
#define TK_NONE 197 #define TK_SEMI 197
#define TK_PREV 198 #define TK_NONE 198
#define TK_LINEAR 199 #define TK_PREV 199
#define TK_IMPORT 200 #define TK_LINEAR 200
#define TK_METRIC 201 #define TK_IMPORT 201
#define TK_TBNAME 202 #define TK_METRIC 202
#define TK_JOIN 203 #define TK_TBNAME 203
#define TK_METRICS 204 #define TK_JOIN 204
#define TK_STABLE 205 #define TK_METRICS 205
#define TK_INSERT 206 #define TK_INSERT 206
#define TK_INTO 207 #define TK_INTO 207
#define TK_VALUES 208 #define TK_VALUES 208
#define TK_SPACE 300 #define TK_SPACE 300
#define TK_COMMENT 301 #define TK_COMMENT 301
#define TK_ILLEGAL 302 #define TK_ILLEGAL 302
......
...@@ -98,6 +98,7 @@ typedef struct SCreateTableSQL { ...@@ -98,6 +98,7 @@ typedef struct SCreateTableSQL {
typedef struct SAlterTableSQL { typedef struct SAlterTableSQL {
SStrToken name; SStrToken name;
int16_t tableType;
int16_t type; int16_t type;
STagData tagData; STagData tagData;
SArray *pAddColumns; // SArray<TAOS_FIELD> SArray *pAddColumns; // SArray<TAOS_FIELD>
...@@ -156,6 +157,7 @@ typedef struct tDCLSQL { ...@@ -156,6 +157,7 @@ typedef struct tDCLSQL {
int32_t nAlloc; /* Number of entries allocated below */ int32_t nAlloc; /* Number of entries allocated below */
SStrToken *a; /* one entry for element */ SStrToken *a; /* one entry for element */
bool existsCheck; bool existsCheck;
int16_t tableType;
union { union {
SCreateDBInfo dbOpt; SCreateDBInfo dbOpt;
...@@ -250,7 +252,7 @@ SCreateTableSQL *tSetCreateSqlElems(SArray *pCols, SArray *pTags, SQuerySQL *pSe ...@@ -250,7 +252,7 @@ SCreateTableSQL *tSetCreateSqlElems(SArray *pCols, SArray *pTags, SQuerySQL *pSe
void tSqlExprNodeDestroy(tSQLExpr *pExpr); void tSqlExprNodeDestroy(tSQLExpr *pExpr);
SAlterTableSQL * tAlterTableSqlElems(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type); SAlterTableSQL * tAlterTableSqlElems(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableTable);
SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagVals, SStrToken *pToken, SStrToken* igExists); SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagVals, SStrToken *pToken, SStrToken* igExists);
void destroyAllSelectClause(SSubclauseInfo *pSql); void destroyAllSelectClause(SSubclauseInfo *pSql);
...@@ -267,7 +269,7 @@ void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken ...@@ -267,7 +269,7 @@ void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken
void SqlInfoDestroy(SSqlInfo *pInfo); void SqlInfoDestroy(SSqlInfo *pInfo);
void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...); void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParams, ...);
void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken, SStrToken* existsCheck); void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken, SStrToken* existsCheck,int16_t tableType);
void setShowOptions(SSqlInfo *pInfo, int32_t type, SStrToken* prefix, SStrToken* pPatterns); void setShowOptions(SSqlInfo *pInfo, int32_t type, SStrToken* prefix, SStrToken* pPatterns);
tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SStrToken *pToken); tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SStrToken *pToken);
......
...@@ -131,10 +131,16 @@ cmd ::= SHOW dbPrefix(X) VGROUPS ids(Y). { ...@@ -131,10 +131,16 @@ cmd ::= SHOW dbPrefix(X) VGROUPS ids(Y). {
//drop configure for tables //drop configure for tables
cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). { cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). {
X.n += Z.n; X.n += Z.n;
setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y); setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y, -1);
} }
cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y); } //drop stable
cmd ::= DROP STABLE ifexists(Y) ids(X) cpxName(Z). {
X.n += Z.n;
setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y, TSDB_SUPER_TABLE);
}
cmd ::= DROP DATABASE ifexists(Y) ids(X). { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, -1); }
cmd ::= DROP DNODE ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X); } cmd ::= DROP DNODE ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X); }
cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_USER, 1, &X); } cmd ::= DROP USER ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_USER, 1, &X); }
cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X); } cmd ::= DROP ACCOUNT ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X); }
...@@ -305,6 +311,8 @@ signed(A) ::= MINUS INTEGER(X). { A = -strtol(X.z, NULL, 10);} ...@@ -305,6 +311,8 @@ signed(A) ::= MINUS INTEGER(X). { A = -strtol(X.z, NULL, 10);}
////////////////////////////////// The CREATE TABLE statement /////////////////////////////// ////////////////////////////////// The CREATE TABLE statement ///////////////////////////////
cmd ::= CREATE TABLE create_table_args. {} cmd ::= CREATE TABLE create_table_args. {}
cmd ::= CREATE TABLE create_stable_args. {}
cmd ::= CREATE STABLE create_stable_args. {}
cmd ::= CREATE TABLE create_table_list(Z). { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = Z;} cmd ::= CREATE TABLE create_table_list(Z). { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = Z;}
%type create_table_list{SCreateTableSQL*} %type create_table_list{SCreateTableSQL*}
...@@ -333,7 +341,8 @@ create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. { ...@@ -333,7 +341,8 @@ create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. {
} }
// create super table // create super table
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. { %type create_stable_args{SCreateTableSQL*}
create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
A = tSetCreateSqlElems(X, Y, NULL, TSQL_CREATE_STABLE); A = tSetCreateSqlElems(X, Y, NULL, TSQL_CREATE_STABLE);
setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
...@@ -683,7 +692,7 @@ cmd ::= RESET QUERY CACHE. { setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} ...@@ -683,7 +692,7 @@ cmd ::= RESET QUERY CACHE. { setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
///////////////////////////////////ALTER TABLE statement////////////////////////////////// ///////////////////////////////////ALTER TABLE statement//////////////////////////////////
cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). { cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
X.n += F.n; X.n += F.n;
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
...@@ -693,14 +702,14 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). { ...@@ -693,14 +702,14 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
toTSDBType(A.type); toTSDBType(A.type);
SArray* K = tVariantListAppendToken(NULL, &A, -1); SArray* K = tVariantListAppendToken(NULL, &A, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
//////////////////////////////////ALTER TAGS statement///////////////////////////////////// //////////////////////////////////ALTER TAGS statement/////////////////////////////////////
cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A). { cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
X.n += Y.n; X.n += Y.n;
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). { cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
...@@ -709,7 +718,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). { ...@@ -709,7 +718,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
toTSDBType(Y.type); toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1); SArray* A = tVariantListAppendToken(NULL, &Y, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
...@@ -722,7 +731,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). { ...@@ -722,7 +731,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
toTSDBType(Z.type); toTSDBType(Z.type);
A = tVariantListAppendToken(A, &Z, -1); A = tVariantListAppendToken(A, &Z, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN); SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
...@@ -733,7 +742,54 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). { ...@@ -733,7 +742,54 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
SArray* A = tVariantListAppendToken(NULL, &Y, -1); SArray* A = tVariantListAppendToken(NULL, &Y, -1);
A = tVariantListAppend(A, &Z, -1); A = tVariantListAppend(A, &Z, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL); SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
///////////////////////////////////ALTER STABLE statement//////////////////////////////////
cmd ::= ALTER STABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
X.n += F.n;
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
X.n += F.n;
toTSDBType(A.type);
SArray* K = tVariantListAppendToken(NULL, &A, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
cmd ::= ALTER STABLE ids(X) cpxName(Y) ADD TAG columnlist(A). {
X.n += Y.n;
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
X.n += Z.n;
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
X.n += F.n;
toTSDBType(Y.type);
SArray* A = tVariantListAppendToken(NULL, &Y, -1);
toTSDBType(Z.type);
A = tVariantListAppendToken(A, &Z, -1);
SAlterTableSQL* pAlterTable = tAlterTableSqlElems(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, TSDB_SUPER_TABLE);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
} }
......
...@@ -585,11 +585,12 @@ SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagVal ...@@ -585,11 +585,12 @@ SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagVal
return info; return info;
} }
SAlterTableSQL *tAlterTableSqlElems(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type) { SAlterTableSQL *tAlterTableSqlElems(SStrToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableType) {
SAlterTableSQL *pAlterTable = calloc(1, sizeof(SAlterTableSQL)); SAlterTableSQL *pAlterTable = calloc(1, sizeof(SAlterTableSQL));
pAlterTable->name = *pTableName; pAlterTable->name = *pTableName;
pAlterTable->type = type; pAlterTable->type = type;
pAlterTable->tableType = tableType;
if (type == TSDB_ALTER_TABLE_ADD_COLUMN || type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) { if (type == TSDB_ALTER_TABLE_ADD_COLUMN || type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) {
pAlterTable->pAddColumns = pCols; pAlterTable->pAddColumns = pCols;
...@@ -733,9 +734,10 @@ void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) { ...@@ -733,9 +734,10 @@ void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) {
va_end(va); va_end(va);
} }
void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken, SStrToken* existsCheck) { void setDropDbTableInfo(SSqlInfo *pInfo, int32_t type, SStrToken* pToken, SStrToken* existsCheck, int16_t tableType) {
pInfo->type = type; pInfo->type = type;
pInfo->pDCLInfo = tTokenListAppend(pInfo->pDCLInfo, pToken); pInfo->pDCLInfo = tTokenListAppend(pInfo->pDCLInfo, pToken);
pInfo->pDCLInfo->tableType = tableType;
pInfo->pDCLInfo->existsCheck = (existsCheck->n == 1); pInfo->pDCLInfo->existsCheck = (existsCheck->n == 1);
} }
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册