parAlterToBalanceTest.cpp 32.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "parTestUtil.h"

using namespace std;

namespace ParserTest {

X
Xiaoyu Wang 已提交
22
class ParserInitialATest : public ParserDdlTest {};
23

X
Xiaoyu Wang 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*
 * ALTER ACCOUNT account_name alter_account_options
 *
 * alter_account_options:
 *     alter_account_option ...
 *
 * alter_account_option: {
 *     PASS value
 *   | PPS value
 *   | TSERIES value
 *   | STORAGE value
 *   | STREAMS value
 *   | QTIME value
 *   | DBS value
 *   | USERS value
 *   | CONNS value
 *   | STATE value
 * }
 */
43 44 45
TEST_F(ParserInitialATest, alterAccount) {
  useDb("root", "test");

X
Xiaoyu Wang 已提交
46
  run("ALTER ACCOUNT ac_wxy PASS '123456'", TSDB_CODE_PAR_EXPRIE_STATEMENT, PARSER_STAGE_PARSE);
47 48
}

49 50 51 52
/*
 * ALTER DNODE dnode_id 'config' ['value']
 * ALTER ALL DNODES 'config' ['value']
 */
53 54 55
TEST_F(ParserInitialATest, alterDnode) {
  useDb("root", "test");

56 57 58 59 60 61 62 63 64 65 66 67 68 69
  SMCfgDnodeReq expect = {0};

  auto clearCfgDnodeReq = [&]() { memset(&expect, 0, sizeof(SMCfgDnodeReq)); };

  auto setCfgDnodeReq = [&](int32_t dnodeId, const char* pConfig, const char* pValue = nullptr) {
    expect.dnodeId = dnodeId;
    strcpy(expect.config, pConfig);
    if (nullptr != pValue) {
      strcpy(expect.value, pValue);
    }
  };

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_ALTER_DNODE_STMT);
X
Xiaoyu Wang 已提交
70
    ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_CONFIG_DNODE);
71 72 73 74 75 76 77 78
    SMCfgDnodeReq req = {0};
    ASSERT_EQ(tDeserializeSMCfgDnodeReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
    ASSERT_EQ(req.dnodeId, expect.dnodeId);
    ASSERT_EQ(std::string(req.config), std::string(expect.config));
    ASSERT_EQ(std::string(req.value), std::string(expect.value));
  });

  setCfgDnodeReq(1, "resetLog");
79
  run("ALTER DNODE 1 'resetLog'");
80 81 82 83 84
  clearCfgDnodeReq();

  setCfgDnodeReq(2, "debugFlag", "134");
  run("ALTER DNODE 2 'debugFlag' '134'");
  clearCfgDnodeReq();
85

86 87 88 89 90 91 92
  setCfgDnodeReq(-1, "resetQueryCache");
  run("ALTER ALL DNODES 'resetQueryCache'");
  clearCfgDnodeReq();

  setCfgDnodeReq(-1, "qDebugflag", "135");
  run("ALTER ALL DNODES 'qDebugflag' '135'");
  clearCfgDnodeReq();
93 94
}

95 96 97 98 99 100 101
/*
 * ALTER DATABASE db_name [alter_database_options]
 *
 * alter_database_options:
 *     alter_database_option ...
 *
 * alter_database_option: {
102
 *     BUFFER int_value                                          -- range [3, 16384], default 96, unit MB
103 104
 *   | CACHEMODEL {'none' | 'last_row' | 'last_value' | 'both'}  -- default 'none'
 *   | CACHESIZE int_value                                       -- range [1, 65536], default 1, unit MB
X
Xiaoyu Wang 已提交
105
 *   | WAL_FSYNC_PERIOD int_value                                -- rang [0, 180000], default 3000, unit ms
106
 *   | KEEP {int_value | duration_value}                         -- rang [1, 365000], default 3650, unit day
H
Hongze Cheng 已提交
107
 *   | PAGES int_value                                           -- rang [64, INT32_MAX], default 256, unit page
108
 *   | REPLICA int_value                                         -- todo: enum 1, 3, default 1, unit replica
X
Xiaoyu Wang 已提交
109
 *   | WAL_LEVEL int_value                                       -- enum 1, 2, default 1
X
Xiaoyu Wang 已提交
110
 *   | STT_TRIGGER int_value                                     -- rang [1, 16], default 8
111
 *   | MINROWS int_value                                         -- rang [10, 1000], default 100
112 113
 *   | WAL_RETENTION_PERIOD int_value                            -- rang [-1, INT32_MAX], default 0
 *   | WAL_RETENTION_SIZE int_value                              -- rang [-1, INT32_MAX], default 0
114
 */
115 116 117
TEST_F(ParserInitialATest, alterDatabase) {
  useDb("root", "test");

118 119 120 121 122 123 124 125 126 127 128 129 130
  SAlterDbReq expect = {0};

  auto clearAlterDbReq = [&]() { memset(&expect, 0, sizeof(SAlterDbReq)); };

  auto initAlterDb = [&](const char* pDb) {
    snprintf(expect.db, sizeof(expect.db), "0.%s", pDb);
    expect.buffer = -1;
    expect.pageSize = -1;
    expect.pages = -1;
    expect.daysPerFile = -1;
    expect.daysToKeep0 = -1;
    expect.daysToKeep1 = -1;
    expect.daysToKeep2 = -1;
131
    expect.walFsyncPeriod = -1;
132 133 134 135 136
    expect.walLevel = -1;
    expect.strict = -1;
    expect.cacheLast = -1;
    expect.cacheLastSize = -1;
    expect.replications = -1;
137
    expect.sstTrigger = -1;
138
    expect.minRows = -1;
139 140
    expect.walRetentionPeriod = -2;
    expect.walRetentionSize = -2;
141 142 143 144 145 146 147 148 149 150 151
  };
  auto setAlterDbBuffer = [&](int32_t buffer) { expect.buffer = buffer; };
  auto setAlterDbPageSize = [&](int32_t pageSize) { expect.pageSize = pageSize; };
  auto setAlterDbPages = [&](int32_t pages) { expect.pages = pages; };
  auto setAlterDbCacheSize = [&](int32_t cacheSize) { expect.cacheLastSize = cacheSize; };
  auto setAlterDbDuration = [&](int32_t duration) { expect.daysPerFile = duration; };
  auto setAlterDbKeep = [&](int32_t daysToKeep0, int32_t daysToKeep1 = -1, int32_t daysToKeep2 = -1) {
    expect.daysToKeep0 = daysToKeep0;
    expect.daysToKeep1 = (-1 == daysToKeep1 ? expect.daysToKeep0 : daysToKeep1);
    expect.daysToKeep2 = (-1 == daysToKeep1 ? expect.daysToKeep1 : daysToKeep2);
  };
152
  auto setAlterDbFsync = [&](int32_t fsync) { expect.walFsyncPeriod = fsync; };
153 154 155 156
  auto setAlterDbWal = [&](int8_t wal) { expect.walLevel = wal; };
  auto setAlterDbStrict = [&](int8_t strict) { expect.strict = strict; };
  auto setAlterDbCacheModel = [&](int8_t cacheModel) { expect.cacheLast = cacheModel; };
  auto setAlterDbReplica = [&](int8_t replications) { expect.replications = replications; };
X
Xiaoyu Wang 已提交
157
  auto setAlterDbSttTrigger = [&](int8_t sstTrigger) { expect.sstTrigger = sstTrigger; };
158
  auto setAlterDbMinRows = [&](int32_t minRows) { expect.minRows = minRows; };
159 160 161 162
  auto setAlterDbWalRetentionPeriod = [&](int32_t walRetentionPeriod) {
    expect.walRetentionPeriod = walRetentionPeriod;
  };
  auto setAlterDbWalRetentionSize = [&](int32_t walRetentionSize) { expect.walRetentionSize = walRetentionSize; };
163 164 165

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_ALTER_DATABASE_STMT);
X
Xiaoyu Wang 已提交
166
    ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_ALTER_DB);
167 168 169 170 171 172 173 174 175 176
    SAlterDbReq req = {0};
    ASSERT_EQ(tDeserializeSAlterDbReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
    ASSERT_EQ(std::string(req.db), std::string(expect.db));
    ASSERT_EQ(req.buffer, expect.buffer);
    ASSERT_EQ(req.pageSize, expect.pageSize);
    ASSERT_EQ(req.pages, expect.pages);
    ASSERT_EQ(req.cacheLastSize, expect.cacheLastSize);
    ASSERT_EQ(req.daysToKeep0, expect.daysToKeep0);
    ASSERT_EQ(req.daysToKeep1, expect.daysToKeep1);
    ASSERT_EQ(req.daysToKeep2, expect.daysToKeep2);
177
    ASSERT_EQ(req.walFsyncPeriod, expect.walFsyncPeriod);
178 179 180 181
    ASSERT_EQ(req.walLevel, expect.walLevel);
    ASSERT_EQ(req.strict, expect.strict);
    ASSERT_EQ(req.cacheLast, expect.cacheLast);
    ASSERT_EQ(req.replications, expect.replications);
182
    ASSERT_EQ(req.sstTrigger, expect.sstTrigger);
183
    ASSERT_EQ(req.minRows, expect.minRows);
184 185
    ASSERT_EQ(req.walRetentionPeriod, expect.walRetentionPeriod);
    ASSERT_EQ(req.walRetentionSize, expect.walRetentionSize);
186 187 188 189 190 191 192 193 194 195 196
  });

  const int32_t MINUTE_PER_DAY = MILLISECOND_PER_DAY / MILLISECOND_PER_MINUTE;
  const int32_t MINUTE_PER_HOUR = MILLISECOND_PER_HOUR / MILLISECOND_PER_MINUTE;

  initAlterDb("test");
  setAlterDbCacheSize(32);
  setAlterDbKeep(10 * MINUTE_PER_DAY);
  setAlterDbFsync(200);
  setAlterDbWal(1);
  setAlterDbCacheModel(TSDB_CACHE_MODEL_LAST_ROW);
X
Xiaoyu Wang 已提交
197
  setAlterDbSttTrigger(16);
198 199
  setAlterDbBuffer(16);
  setAlterDbPages(128);
X
Xiaoyu Wang 已提交
200
  setAlterDbReplica(3);
201 202
  setAlterDbWalRetentionPeriod(10);
  setAlterDbWalRetentionSize(20);
203
  run("ALTER DATABASE test BUFFER 16 CACHEMODEL 'last_row' CACHESIZE 32 WAL_FSYNC_PERIOD 200 KEEP 10 PAGES 128 "
204
      "REPLICA 3 WAL_LEVEL 1 STT_TRIGGER 16 WAL_RETENTION_PERIOD 10 WAL_RETENTION_SIZE 20");
205 206 207 208 209 210 211 212 213
  clearAlterDbReq();

  initAlterDb("test");
  setAlterDbBuffer(3);
  run("ALTER DATABASE test BUFFER 3");
  setAlterDbBuffer(64);
  run("ALTER DATABASE test BUFFER 64");
  setAlterDbBuffer(16384);
  run("ALTER DATABASE test BUFFER 16384");
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
  clearAlterDbReq();

  initAlterDb("test");
  setAlterDbCacheModel(TSDB_CACHE_MODEL_NONE);
  run("ALTER DATABASE test CACHEMODEL 'none'");
  setAlterDbCacheModel(TSDB_CACHE_MODEL_LAST_ROW);
  run("ALTER DATABASE test CACHEMODEL 'last_row'");
  setAlterDbCacheModel(TSDB_CACHE_MODEL_LAST_VALUE);
  run("ALTER DATABASE test CACHEMODEL 'last_value'");
  setAlterDbCacheModel(TSDB_CACHE_MODEL_BOTH);
  run("ALTER DATABASE test CACHEMODEL 'both'");
  clearAlterDbReq();

  initAlterDb("test");
  setAlterDbCacheSize(1);
  run("ALTER DATABASE test CACHESIZE 1");
  setAlterDbCacheSize(64);
  run("ALTER DATABASE test CACHESIZE 64");
  setAlterDbCacheSize(65536);
  run("ALTER DATABASE test CACHESIZE 65536");
  clearAlterDbReq();

  initAlterDb("test");
  setAlterDbFsync(0);
X
Xiaoyu Wang 已提交
238
  run("ALTER DATABASE test WAL_FSYNC_PERIOD 0");
239
  setAlterDbFsync(1000);
X
Xiaoyu Wang 已提交
240
  run("ALTER DATABASE test WAL_FSYNC_PERIOD 1000");
241
  setAlterDbFsync(180000);
X
Xiaoyu Wang 已提交
242
  run("ALTER DATABASE test WAL_FSYNC_PERIOD 180000");
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
  clearAlterDbReq();

  initAlterDb("test");
  setAlterDbKeep(1 * MINUTE_PER_DAY);
  run("ALTER DATABASE test KEEP 1");
  setAlterDbKeep(30 * MINUTE_PER_DAY);
  run("ALTER DATABASE test KEEP 30");
  setAlterDbKeep(365000 * MINUTE_PER_DAY);
  run("ALTER DATABASE test KEEP 365000");
  setAlterDbKeep(1440);
  run("ALTER DATABASE test KEEP 1440m");
  setAlterDbKeep(14400);
  run("ALTER DATABASE test KEEP 14400m");
  setAlterDbKeep(525600000);
  run("ALTER DATABASE test KEEP 525600000m");
  setAlterDbKeep(5 * MINUTE_PER_DAY, 35 * MINUTE_PER_DAY, 500 * MINUTE_PER_DAY);
  run("ALTER DATABASE test KEEP 5,35,500");
  setAlterDbKeep(14400, 2400 * MINUTE_PER_HOUR, 1500 * MINUTE_PER_DAY);
  run("ALTER DATABASE test KEEP 14400m,2400h,1500d");
  clearAlterDbReq();

264 265 266 267 268 269 270 271 272
  initAlterDb("test");
  setAlterDbPages(64);
  run("ALTER DATABASE test PAGES 64");
  setAlterDbPages(1024);
  run("ALTER DATABASE test PAGES 1024");
  setAlterDbPages(16384);
  run("ALTER DATABASE test PAGES 16384");
  clearAlterDbReq();

273 274
  initAlterDb("test");
  setAlterDbWal(1);
X
Xiaoyu Wang 已提交
275
  run("ALTER DATABASE test WAL_LEVEL 1");
276
  setAlterDbWal(2);
X
Xiaoyu Wang 已提交
277
  run("ALTER DATABASE test WAL_LEVEL 2");
278
  clearAlterDbReq();
X
Xiaoyu Wang 已提交
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294

  initAlterDb("test");
  setAlterDbReplica(1);
  run("ALTER DATABASE test REPLICA 1");
  setAlterDbReplica(3);
  run("ALTER DATABASE test REPLICA 3");
  clearAlterDbReq();

  initAlterDb("test");
  setAlterDbSttTrigger(1);
  run("ALTER DATABASE test STT_TRIGGER 1");
  setAlterDbSttTrigger(4);
  run("ALTER DATABASE test STT_TRIGGER 4");
  setAlterDbSttTrigger(16);
  run("ALTER DATABASE test STT_TRIGGER 16");
  clearAlterDbReq();
295 296 297 298 299 300 301 302 303

  initAlterDb("test");
  setAlterDbMinRows(10);
  run("ALTER DATABASE test MINROWS 10");
  setAlterDbMinRows(50);
  run("ALTER DATABASE test MINROWS 50");
  setAlterDbMinRows(1000);
  run("ALTER DATABASE test MINROWS 1000");
  clearAlterDbReq();
304 305 306 307 308 309 310 311 312 313 314 315 316 317

  initAlterDb("test");
  setAlterDbWalRetentionPeriod(-1);
  run("ALTER DATABASE test WAL_RETENTION_PERIOD -1");
  setAlterDbWalRetentionPeriod(50);
  run("ALTER DATABASE test WAL_RETENTION_PERIOD 50");
  clearAlterDbReq();

  initAlterDb("test");
  setAlterDbWalRetentionSize(-1);
  run("ALTER DATABASE test WAL_RETENTION_SIZE -1");
  setAlterDbWalRetentionSize(50);
  run("ALTER DATABASE test WAL_RETENTION_SIZE 50");
  clearAlterDbReq();
318 319 320 321
}

TEST_F(ParserInitialATest, alterDatabaseSemanticCheck) {
  useDb("root", "test");
X
Xiaoyu Wang 已提交
322

323 324
  run("ALTER DATABASE test BUFFER 2", TSDB_CODE_PAR_INVALID_DB_OPTION);
  run("ALTER DATABASE test BUFFER 16385", TSDB_CODE_PAR_INVALID_DB_OPTION);
325 326 327 328
  run("ALTER DATABASE test CACHEMODEL 'other'", TSDB_CODE_PAR_INVALID_DB_OPTION);
  run("ALTER DATABASE test CACHESIZE 0", TSDB_CODE_PAR_INVALID_DB_OPTION);
  run("ALTER DATABASE test CACHESIZE 65537", TSDB_CODE_PAR_INVALID_DB_OPTION);
  // The syntax limits it to only positive numbers
X
Xiaoyu Wang 已提交
329 330
  run("ALTER DATABASE test WAL_FSYNC_PERIOD -1", TSDB_CODE_PAR_SYNTAX_ERROR, PARSER_STAGE_PARSE);
  run("ALTER DATABASE test WAL_FSYNC_PERIOD 180001", TSDB_CODE_PAR_INVALID_DB_OPTION);
331 332 333 334
  run("ALTER DATABASE test KEEP 0", TSDB_CODE_PAR_INVALID_DB_OPTION);
  run("ALTER DATABASE test KEEP 365001", TSDB_CODE_PAR_INVALID_DB_OPTION);
  run("ALTER DATABASE test KEEP 1000000000s", TSDB_CODE_PAR_INVALID_DB_OPTION);
  run("ALTER DATABASE test KEEP 1w", TSDB_CODE_PAR_INVALID_DB_OPTION);
335
  run("ALTER DATABASE test PAGES 63", TSDB_CODE_PAR_INVALID_DB_OPTION);
X
Xiaoyu Wang 已提交
336 337
  run("ALTER DATABASE test WAL_LEVEL 0", TSDB_CODE_PAR_INVALID_DB_OPTION);
  run("ALTER DATABASE test WAL_LEVEL 3", TSDB_CODE_PAR_INVALID_DB_OPTION);
X
Xiaoyu Wang 已提交
338
  run("ALTER DATABASE test REPLICA 2", TSDB_CODE_PAR_INVALID_DB_OPTION);
339 340
  run("ALTER DATABASE test STT_TRIGGER 0", TSDB_CODE_PAR_INVALID_DB_OPTION);
  run("ALTER DATABASE test STT_TRIGGER 17", TSDB_CODE_PAR_INVALID_DB_OPTION);
341
  // Regardless of the specific sentence
X
Xiaoyu Wang 已提交
342
  run("ALTER DATABASE db WAL_LEVEL 0     # td-14436", TSDB_CODE_PAR_SYNTAX_ERROR, PARSER_STAGE_PARSE);
343 344
}

345
/*
X
Xiaoyu Wang 已提交
346
 * ALTER LOCAL 'config' ['value']
347
 */
348 349 350 351 352 353 354 355 356 357
TEST_F(ParserInitialATest, alterLocal) {
  useDb("root", "test");

  pair<string, string> expect;

  auto clearAlterLocal = [&]() {
    expect.first.clear();
    expect.second.clear();
  };

358
  auto setAlterLocal = [&](const char* pConfig, const char* pValue = nullptr) {
359 360 361 362 363 364 365 366 367 368 369 370 371 372
    expect.first.assign(pConfig);
    if (nullptr != pValue) {
      expect.second.assign(pValue);
    }
  };

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_ALTER_LOCAL_STMT);
    ASSERT_EQ(pQuery->execMode, QUERY_EXEC_MODE_LOCAL);
    SAlterLocalStmt* pStmt = (SAlterLocalStmt*)pQuery->pRoot;
    ASSERT_EQ(string(pStmt->config), expect.first);
    ASSERT_EQ(string(pStmt->value), expect.second);
  });

373
  setAlterLocal("resetlog");
374 375 376
  run("ALTER LOCAL 'resetlog'");
  clearAlterLocal();

377
  setAlterLocal("querypolicy", "2");
378 379 380 381
  run("ALTER LOCAL 'querypolicy' '2'");
  clearAlterLocal();
}

382
/*
383
 * ALTER STABLE [db_name.]tb_name alter_table_clause
384 385 386 387 388 389
 *
 * alter_table_clause: {
 *     alter_table_options
 *   | ADD COLUMN col_name column_type
 *   | DROP COLUMN col_name
 *   | MODIFY COLUMN col_name column_type
X
Xiaoyu Wang 已提交
390 391 392 393 394 395
 *   | RENAME COLUMN old_col_name new_col_name  -- only normal table
 *   | ADD TAG tag_name tag_type                -- only super table
 *   | DROP TAG tag_name                        -- only super table
 *   | MODIFY TAG tag_name tag_type             -- only super table
 *   | RENAME TAG old_tag_name new_tag_name     -- only super table
 *   | SET TAG tag_name = new_tag_value         -- only child table
396 397 398 399 400 401
 * }
 *
 * alter_table_options:
 *     alter_table_option ...
 *
 * alter_table_option: {
X
Xiaoyu Wang 已提交
402
 *    TTL int_value                             -- only child/normal table
403
 *  | COMMENT 'string_value'
404 405
 * }
 */
X
Xiaoyu Wang 已提交
406
TEST_F(ParserInitialATest, alterSTable) {
407 408
  useDb("root", "test");

X
Xiaoyu Wang 已提交
409 410
  SMAlterStbReq expect = {0};

411 412 413 414 415
  auto clearAlterStbReq = [&]() {
    tFreeSMAltertbReq(&expect);
    memset(&expect, 0, sizeof(SMAlterStbReq));
  };

416 417 418
  auto setAlterStbReq = [&](const char* pTbname, int8_t alterType, int32_t numOfFields = 0,
                            const char* pField1Name = nullptr, int8_t field1Type = 0, int32_t field1Bytes = 0,
                            const char* pField2Name = nullptr, const char* pComment = nullptr) {
X
Xiaoyu Wang 已提交
419 420 421 422
    int32_t len = snprintf(expect.name, sizeof(expect.name), "0.test.%s", pTbname);
    expect.name[len] = '\0';
    expect.alterType = alterType;
    if (nullptr != pComment) {
423
      expect.comment = taosStrdup(pComment);
wmmhello's avatar
wmmhello 已提交
424
      expect.commentLen = strlen(pComment);
X
Xiaoyu Wang 已提交
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
    }

    expect.numOfFields = numOfFields;
    if (NULL == expect.pFields) {
      expect.pFields = taosArrayInit(2, sizeof(TAOS_FIELD));
      TAOS_FIELD field = {0};
      taosArrayPush(expect.pFields, &field);
      taosArrayPush(expect.pFields, &field);
    }

    TAOS_FIELD* pField = (TAOS_FIELD*)taosArrayGet(expect.pFields, 0);
    if (NULL != pField1Name) {
      strcpy(pField->name, pField1Name);
      pField->name[strlen(pField1Name)] = '\0';
    } else {
      memset(pField, 0, sizeof(TAOS_FIELD));
    }
    pField->type = field1Type;
    pField->bytes = field1Bytes > 0 ? field1Bytes : (field1Type > 0 ? tDataTypes[field1Type].bytes : 0);

    pField = (TAOS_FIELD*)taosArrayGet(expect.pFields, 1);
    if (NULL != pField2Name) {
      strcpy(pField->name, pField2Name);
      pField->name[strlen(pField2Name)] = '\0';
    } else {
      memset(pField, 0, sizeof(TAOS_FIELD));
    }
    pField->type = 0;
    pField->bytes = 0;
  };

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
457
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_ALTER_SUPER_TABLE_STMT);
X
Xiaoyu Wang 已提交
458
    ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_ALTER_STB);
X
Xiaoyu Wang 已提交
459
    SMAlterStbReq req = {0};
X
Xiaoyu Wang 已提交
460
    ASSERT_EQ(tDeserializeSMAlterStbReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
X
Xiaoyu Wang 已提交
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
    ASSERT_EQ(std::string(req.name), std::string(expect.name));
    ASSERT_EQ(req.alterType, expect.alterType);
    ASSERT_EQ(req.numOfFields, expect.numOfFields);
    if (expect.numOfFields > 0) {
      TAOS_FIELD* pField = (TAOS_FIELD*)taosArrayGet(req.pFields, 0);
      TAOS_FIELD* pExpectField = (TAOS_FIELD*)taosArrayGet(expect.pFields, 0);
      ASSERT_EQ(std::string(pField->name), std::string(pExpectField->name));
      ASSERT_EQ(pField->type, pExpectField->type);
      ASSERT_EQ(pField->bytes, pExpectField->bytes);
    }
    if (expect.numOfFields > 1) {
      TAOS_FIELD* pField = (TAOS_FIELD*)taosArrayGet(req.pFields, 1);
      TAOS_FIELD* pExpectField = (TAOS_FIELD*)taosArrayGet(expect.pFields, 1);
      ASSERT_EQ(std::string(pField->name), std::string(pExpectField->name));
      ASSERT_EQ(pField->type, pExpectField->type);
      ASSERT_EQ(pField->bytes, pExpectField->bytes);
    }
478
    tFreeSMAltertbReq(&req);
X
Xiaoyu Wang 已提交
479 480
  });

481
  setAlterStbReq("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, "test");
482
  run("ALTER STABLE st1 COMMENT 'test'");
483
  clearAlterStbReq();
X
Xiaoyu Wang 已提交
484

485
  setAlterStbReq("st1", TSDB_ALTER_TABLE_ADD_COLUMN, 1, "cc1", TSDB_DATA_TYPE_BIGINT);
486
  run("ALTER STABLE st1 ADD COLUMN cc1 BIGINT");
487
  clearAlterStbReq();
X
Xiaoyu Wang 已提交
488

489
  setAlterStbReq("st1", TSDB_ALTER_TABLE_DROP_COLUMN, 1, "c1");
490
  run("ALTER STABLE st1 DROP COLUMN c1");
491
  clearAlterStbReq();
X
Xiaoyu Wang 已提交
492

493
  setAlterStbReq("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, 1, "c2", TSDB_DATA_TYPE_VARCHAR, 30 + VARSTR_HEADER_SIZE);
494
  run("ALTER STABLE st1 MODIFY COLUMN c2 VARCHAR(30)");
495
  clearAlterStbReq();
X
Xiaoyu Wang 已提交
496

497
  setAlterStbReq("st1", TSDB_ALTER_TABLE_ADD_TAG, 1, "tag11", TSDB_DATA_TYPE_BIGINT);
498
  run("ALTER STABLE st1 ADD TAG tag11 BIGINT");
499
  clearAlterStbReq();
X
Xiaoyu Wang 已提交
500

501
  setAlterStbReq("st1", TSDB_ALTER_TABLE_DROP_TAG, 1, "tag1");
502
  run("ALTER STABLE st1 DROP TAG tag1");
503
  clearAlterStbReq();
X
Xiaoyu Wang 已提交
504

505
  setAlterStbReq("st1", TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, 1, "tag2", TSDB_DATA_TYPE_VARCHAR, 30 + VARSTR_HEADER_SIZE);
506
  run("ALTER STABLE st1 MODIFY TAG tag2 VARCHAR(30)");
507
  clearAlterStbReq();
X
Xiaoyu Wang 已提交
508

509
  setAlterStbReq("st1", TSDB_ALTER_TABLE_UPDATE_TAG_NAME, 2, "tag1", 0, 0, "tag11");
510
  run("ALTER STABLE st1 RENAME TAG tag1 tag11");
511
  clearAlterStbReq();
X
Xiaoyu Wang 已提交
512 513
}

X
Xiaoyu Wang 已提交
514 515 516
TEST_F(ParserInitialATest, alterSTableSemanticCheck) {
  useDb("root", "test");

517 518 519
  run("ALTER STABLE st1 RENAME COLUMN c1 cc1", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
  run("ALTER STABLE st1 MODIFY COLUMN c2 NCHAR(10)", TSDB_CODE_PAR_INVALID_MODIFY_COL);
  run("ALTER STABLE st1 MODIFY TAG tag2 NCHAR(10)", TSDB_CODE_PAR_INVALID_MODIFY_COL);
520 521
  run("ALTER STABLE st1 SET TAG tag1 = 10", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
  run("ALTER STABLE st1 TTL 10", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
X
Xiaoyu Wang 已提交
522 523
}

X
Xiaoyu Wang 已提交
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
/*
 * ALTER TABLE [db_name.]tb_name alter_table_clause
 *
 * alter_table_clause: {
 *     alter_table_options
 *   | ADD COLUMN col_name column_type
 *   | DROP COLUMN col_name
 *   | MODIFY COLUMN col_name column_type
 *   | RENAME COLUMN old_col_name new_col_name  -- only normal table
 *   | ADD TAG tag_name tag_type                -- only super table
 *   | DROP TAG tag_name                        -- only super table
 *   | MODIFY TAG tag_name tag_type             -- only super table
 *   | RENAME TAG old_tag_name new_tag_name     -- only super table
 *   | SET TAG tag_name = new_tag_value         -- only child table
 * }
 *
 * alter_table_options:
 *     alter_table_option ...
 *
 * alter_table_option: {
 *    TTL int_value                             -- only child/normal table
 *  | COMMENT 'string_value'
 * }
 */
X
Xiaoyu Wang 已提交
548 549 550
TEST_F(ParserInitialATest, alterTable) {
  useDb("root", "test");

X
Xiaoyu Wang 已提交
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
  // normal/child table
  {
    SVAlterTbReq expect = {0};

    auto clearAlterTbReq = [&]() {
      free(expect.tbName);
      free(expect.colName);
      free(expect.colNewName);
      free(expect.tagName);
      memset(&expect, 0, sizeof(SVAlterTbReq));
    };

    auto setAlterTableCol = [&](const char* pTbname, int8_t alterType, const char* pColName, int8_t dataType = 0,
                                int32_t dataBytes = 0, const char* pNewColName = nullptr) {
      expect.tbName = strdup(pTbname);
      expect.action = alterType;
      expect.colName = strdup(pColName);

      switch (alterType) {
        case TSDB_ALTER_TABLE_ADD_COLUMN:
          expect.type = dataType;
          expect.flags = COL_SMA_ON;
          expect.bytes = dataBytes > 0 ? dataBytes : (dataType > 0 ? tDataTypes[dataType].bytes : 0);
          break;
        case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
          expect.colModBytes = dataBytes;
          break;
        case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME:
          expect.colNewName = strdup(pNewColName);
          break;
        default:
          break;
      }
    };

    auto setAlterTableTag = [&](const char* pTbname, const char* pTagName, uint8_t* pNewVal, uint32_t bytes) {
      expect.tbName = strdup(pTbname);
      expect.action = TSDB_ALTER_TABLE_UPDATE_TAG_VAL;
      expect.tagName = strdup(pTagName);

      expect.isNull = (nullptr == pNewVal);
      expect.nTagVal = bytes;
      expect.pTagVal = pNewVal;
    };

    auto setAlterTableOptions = [&](const char* pTbname, int32_t ttl, char* pComment = nullptr) {
      expect.tbName = strdup(pTbname);
      expect.action = TSDB_ALTER_TABLE_UPDATE_OPTIONS;
      if (-1 != ttl) {
        expect.updateTTL = true;
        expect.newTTL = ttl;
      }
      if (nullptr != pComment) {
        expect.newCommentLen = strlen(pComment);
        expect.newComment = pComment;
      }
    };

    setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
      ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_VNODE_MODIFY_STMT);
      SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)pQuery->pRoot;

      ASSERT_EQ(pStmt->sqlNodeType, QUERY_NODE_ALTER_TABLE_STMT);
      ASSERT_NE(pStmt->pDataBlocks, nullptr);
      ASSERT_EQ(taosArrayGetSize(pStmt->pDataBlocks), 1);
      SVgDataBlocks* pVgData = (SVgDataBlocks*)taosArrayGetP(pStmt->pDataBlocks, 0);
      void*          pBuf = POINTER_SHIFT(pVgData->pData, sizeof(SMsgHead));
      SVAlterTbReq   req = {0};
      SDecoder       coder = {0};
      tDecoderInit(&coder, (uint8_t*)pBuf, pVgData->size);
      ASSERT_EQ(tDecodeSVAlterTbReq(&coder, &req), TSDB_CODE_SUCCESS);

      ASSERT_EQ(std::string(req.tbName), std::string(expect.tbName));
      ASSERT_EQ(req.action, expect.action);
      if (nullptr != expect.colName) {
        ASSERT_EQ(std::string(req.colName), std::string(expect.colName));
      }
      ASSERT_EQ(req.type, expect.type);
      ASSERT_EQ(req.flags, expect.flags);
      ASSERT_EQ(req.bytes, expect.bytes);
      ASSERT_EQ(req.colModBytes, expect.colModBytes);
      if (nullptr != expect.colNewName) {
        ASSERT_EQ(std::string(req.colNewName), std::string(expect.colNewName));
      }
      if (nullptr != expect.tagName) {
        ASSERT_EQ(std::string(req.tagName), std::string(expect.tagName));
      }
      ASSERT_EQ(req.isNull, expect.isNull);
      ASSERT_EQ(req.nTagVal, expect.nTagVal);
640 641 642
      if (nullptr != req.pTagVal) {
        ASSERT_EQ(memcmp(req.pTagVal, expect.pTagVal, expect.nTagVal), 0);
      }
X
Xiaoyu Wang 已提交
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
      ASSERT_EQ(req.updateTTL, expect.updateTTL);
      ASSERT_EQ(req.newTTL, expect.newTTL);
      if (nullptr != expect.newComment) {
        ASSERT_EQ(std::string(req.newComment), std::string(expect.newComment));
        ASSERT_EQ(req.newCommentLen, strlen(req.newComment));
        ASSERT_EQ(expect.newCommentLen, strlen(expect.newComment));
      }

      tDecoderClear(&coder);
    });

    setAlterTableOptions("t1", 10, nullptr);
    run("ALTER TABLE t1 TTL 10");
    clearAlterTbReq();

    setAlterTableOptions("t1", -1, (char*)"test");
    run("ALTER TABLE t1 COMMENT 'test'");
    clearAlterTbReq();

    setAlterTableCol("t1", TSDB_ALTER_TABLE_ADD_COLUMN, "cc1", TSDB_DATA_TYPE_BIGINT);
    run("ALTER TABLE t1 ADD COLUMN cc1 BIGINT");
    clearAlterTbReq();

    setAlterTableCol("t1", TSDB_ALTER_TABLE_DROP_COLUMN, "c1");
    run("ALTER TABLE t1 DROP COLUMN c1");
    clearAlterTbReq();

    setAlterTableCol("t1", TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, "c2", TSDB_DATA_TYPE_VARCHAR, 30 + VARSTR_HEADER_SIZE);
    run("ALTER TABLE t1 MODIFY COLUMN c2 VARCHAR(30)");
    clearAlterTbReq();

    setAlterTableCol("t1", TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, "c1", 0, 0, "cc1");
    run("ALTER TABLE t1 RENAME COLUMN c1 cc1");
    clearAlterTbReq();

    int32_t val = 10;
    setAlterTableTag("st1s1", "tag1", (uint8_t*)&val, sizeof(val));
    run("ALTER TABLE st1s1 SET TAG tag1=10");
    clearAlterTbReq();
  }

  // super table
  {
    SMAlterStbReq expect = {0};

    auto clearAlterStbReq = [&]() {
      tFreeSMAltertbReq(&expect);
      memset(&expect, 0, sizeof(SMAlterStbReq));
    };

    auto setAlterStbReq = [&](const char* pTbname, int8_t alterType, int32_t numOfFields = 0,
                              const char* pField1Name = nullptr, int8_t field1Type = 0, int32_t field1Bytes = 0,
                              const char* pField2Name = nullptr, const char* pComment = nullptr) {
      int32_t len = snprintf(expect.name, sizeof(expect.name), "0.test.%s", pTbname);
      expect.name[len] = '\0';
      expect.alterType = alterType;
      if (nullptr != pComment) {
        expect.comment = strdup(pComment);
        expect.commentLen = strlen(pComment);
      }

      expect.numOfFields = numOfFields;
      if (NULL == expect.pFields) {
        expect.pFields = taosArrayInit(2, sizeof(TAOS_FIELD));
        TAOS_FIELD field = {0};
        taosArrayPush(expect.pFields, &field);
        taosArrayPush(expect.pFields, &field);
      }

      TAOS_FIELD* pField = (TAOS_FIELD*)taosArrayGet(expect.pFields, 0);
      if (NULL != pField1Name) {
        strcpy(pField->name, pField1Name);
        pField->name[strlen(pField1Name)] = '\0';
      } else {
        memset(pField, 0, sizeof(TAOS_FIELD));
      }
      pField->type = field1Type;
      pField->bytes = field1Bytes > 0 ? field1Bytes : (field1Type > 0 ? tDataTypes[field1Type].bytes : 0);

      pField = (TAOS_FIELD*)taosArrayGet(expect.pFields, 1);
      if (NULL != pField2Name) {
        strcpy(pField->name, pField2Name);
        pField->name[strlen(pField2Name)] = '\0';
      } else {
        memset(pField, 0, sizeof(TAOS_FIELD));
      }
      pField->type = 0;
      pField->bytes = 0;
    };

    setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
      ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_ALTER_TABLE_STMT);
      ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_ALTER_STB);
      SMAlterStbReq req = {0};
      ASSERT_EQ(tDeserializeSMAlterStbReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
      ASSERT_EQ(std::string(req.name), std::string(expect.name));
      ASSERT_EQ(req.alterType, expect.alterType);
      ASSERT_EQ(req.numOfFields, expect.numOfFields);
      if (expect.numOfFields > 0) {
        TAOS_FIELD* pField = (TAOS_FIELD*)taosArrayGet(req.pFields, 0);
        TAOS_FIELD* pExpectField = (TAOS_FIELD*)taosArrayGet(expect.pFields, 0);
        ASSERT_EQ(std::string(pField->name), std::string(pExpectField->name));
        ASSERT_EQ(pField->type, pExpectField->type);
        ASSERT_EQ(pField->bytes, pExpectField->bytes);
      }
      if (expect.numOfFields > 1) {
        TAOS_FIELD* pField = (TAOS_FIELD*)taosArrayGet(req.pFields, 1);
        TAOS_FIELD* pExpectField = (TAOS_FIELD*)taosArrayGet(expect.pFields, 1);
        ASSERT_EQ(std::string(pField->name), std::string(pExpectField->name));
        ASSERT_EQ(pField->type, pExpectField->type);
        ASSERT_EQ(pField->bytes, pExpectField->bytes);
      }
      tFreeSMAltertbReq(&req);
    });

    setAlterStbReq("st1", TSDB_ALTER_TABLE_ADD_TAG, 1, "tag11", TSDB_DATA_TYPE_BIGINT);
    run("ALTER TABLE st1 ADD TAG tag11 BIGINT");
    clearAlterStbReq();

    setAlterStbReq("st1", TSDB_ALTER_TABLE_DROP_TAG, 1, "tag1");
    run("ALTER TABLE st1 DROP TAG tag1");
    clearAlterStbReq();

    setAlterStbReq("st1", TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, 1, "tag2", TSDB_DATA_TYPE_VARCHAR,
                   30 + VARSTR_HEADER_SIZE);
    run("ALTER TABLE st1 MODIFY TAG tag2 VARCHAR(30)");
    clearAlterStbReq();

    setAlterStbReq("st1", TSDB_ALTER_TABLE_UPDATE_TAG_NAME, 2, "tag1", 0, 0, "tag11");
    run("ALTER TABLE st1 RENAME TAG tag1 tag11");
    clearAlterStbReq();
  }
775
}
776

X
Xiaoyu Wang 已提交
777 778 779 780
TEST_F(ParserInitialATest, alterTableSemanticCheck) {
  useDb("root", "test");

  run("ALTER TABLE st1s1 RENAME COLUMN c1 cc1", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
781 782 783 784
  run("ALTER TABLE st1s1 ADD TAG tag11 BIGINT", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
  run("ALTER TABLE st1s1 DROP TAG tag1", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
  run("ALTER TABLE st1s1 MODIFY TAG tag2 VARCHAR(30)", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
  run("ALTER TABLE st1s1 RENAME TAG tag1 tag11", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
X
Xiaoyu Wang 已提交
785
  run("ALTER TABLE st1s1 SET TAG tag2 =  '123456789012345678901'", TSDB_CODE_PAR_WRONG_VALUE_TYPE);
X
Xiaoyu Wang 已提交
786 787
}

788
/*
X
Xiaoyu Wang 已提交
789
 * ALTER USER user_name alter_user_clause
790 791 792 793 794 795 796
 *
 * alter_user_clause: {
 *    PASS str_value
 *  | ENABLE int_value
 *  | SYSINFO int_value
 * }
 */
797 798 799
TEST_F(ParserInitialATest, alterUser) {
  useDb("root", "test");

X
Xiaoyu Wang 已提交
800
  SAlterUserReq expect = {0};
801

X
Xiaoyu Wang 已提交
802 803 804 805 806 807 808 809 810 811 812 813
  auto clearAlterUserReq = [&]() { memset(&expect, 0, sizeof(SAlterUserReq)); };

  auto setAlterUserReq = [&](const char* pUser, int8_t alterType, const char* pPass = nullptr, int8_t sysInfo = 0,
                             int8_t enable = 0) {
    strcpy(expect.user, pUser);
    expect.alterType = alterType;
    expect.superUser = 0;
    expect.sysInfo = sysInfo;
    expect.enable = enable;
    if (nullptr != pPass) {
      strcpy(expect.pass, pPass);
    }
814
    strcpy(expect.objname, "test");
X
Xiaoyu Wang 已提交
815 816 817 818
  };

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_ALTER_USER_STMT);
X
Xiaoyu Wang 已提交
819
    ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_ALTER_USER);
X
Xiaoyu Wang 已提交
820 821 822 823 824 825 826 827 828
    SAlterUserReq req = {0};
    ASSERT_TRUE(TSDB_CODE_SUCCESS == tDeserializeSAlterUserReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req));

    ASSERT_EQ(req.alterType, expect.alterType);
    ASSERT_EQ(req.superUser, expect.superUser);
    ASSERT_EQ(req.sysInfo, expect.sysInfo);
    ASSERT_EQ(req.enable, expect.enable);
    ASSERT_EQ(std::string(req.user), std::string(expect.user));
    ASSERT_EQ(std::string(req.pass), std::string(expect.pass));
829
    ASSERT_EQ(std::string(req.objname), std::string(expect.objname));
X
Xiaoyu Wang 已提交
830 831 832 833 834 835 836 837 838 839 840 841 842
  });

  setAlterUserReq("wxy", TSDB_ALTER_USER_PASSWD, "123456");
  run("ALTER USER wxy PASS '123456'");
  clearAlterUserReq();

  setAlterUserReq("wxy", TSDB_ALTER_USER_ENABLE, nullptr, 0, 1);
  run("ALTER USER wxy ENABLE 1");
  clearAlterUserReq();

  setAlterUserReq("wxy", TSDB_ALTER_USER_SYSINFO, nullptr, 1);
  run("ALTER USER wxy SYSINFO 1");
  clearAlterUserReq();
843 844
}

845 846 847
/*
 * BALANCE VGROUP
 */
X
Xiaoyu Wang 已提交
848 849 850 851 852 853 854 855 856 857 858 859 860
TEST_F(ParserInitialATest, balanceVgroup) {
  useDb("root", "test");

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_BALANCE_VGROUP_STMT);
    ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_BALANCE_VGROUP);
    SBalanceVgroupReq req = {0};
    ASSERT_EQ(tDeserializeSBalanceVgroupReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
  });

  run("BALANCE VGROUP");
}

861 862 863
/*
 * BALANCE VGROUP LEADER
 */
X
Xiaoyu Wang 已提交
864
TEST_F(ParserInitialATest, balanceVgroupLeader) {
865 866 867 868 869
  useDb("root", "test");

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_BALANCE_VGROUP_LEADER_STMT);
    ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_BALANCE_VGROUP_LEADER);
X
Xiaoyu Wang 已提交
870 871
    SBalanceVgroupLeaderReq req = {0};
    ASSERT_EQ(tDeserializeSBalanceVgroupLeaderReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req),
872 873 874 875 876 877
              TSDB_CODE_SUCCESS);
  });

  run("BALANCE VGROUP LEADER");
}

D
dapan1121 已提交
878
}  // namespace ParserTest