parShowToUse.cpp 6.9 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 {

22
class ParserShowToUseTest : public ParserDdlTest {};
23

24 25 26
// todo SHOW accounts
// todo SHOW apps
// todo SHOW connections
27

28 29 30 31 32 33 34 35 36
TEST_F(ParserShowToUseTest, showCluster) {
  useDb("root", "test");

  setCheckDdlFunc(
      [&](const SQuery* pQuery, ParserStage stage) { ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_SELECT_STMT); });

  run("SHOW CLUSTER");
}

37 38 39 40 41 42 43 44 45
TEST_F(ParserShowToUseTest, showConsumers) {
  useDb("root", "test");

  setCheckDdlFunc(
      [&](const SQuery* pQuery, ParserStage stage) { ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_SELECT_STMT); });

  run("SHOW CONSUMERS");
}

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
TEST_F(ParserShowToUseTest, showCreateDatabase) {
  useDb("root", "test");

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_SHOW_CREATE_DATABASE_STMT);
    ASSERT_EQ(pQuery->execMode, QUERY_EXEC_MODE_LOCAL);
    ASSERT_TRUE(pQuery->haveResultSet);
    ASSERT_NE(((SShowCreateDatabaseStmt*)pQuery->pRoot)->pCfg, nullptr);
  });

  run("SHOW CREATE DATABASE test");
}

TEST_F(ParserShowToUseTest, showCreateSTable) {
  useDb("root", "test");

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_SHOW_CREATE_STABLE_STMT);
    ASSERT_EQ(pQuery->execMode, QUERY_EXEC_MODE_LOCAL);
    ASSERT_TRUE(pQuery->haveResultSet);
X
Xiaoyu Wang 已提交
66 67
    ASSERT_NE(((SShowCreateTableStmt*)pQuery->pRoot)->pDbCfg, nullptr);
    ASSERT_NE(((SShowCreateTableStmt*)pQuery->pRoot)->pTableCfg, nullptr);
68 69 70 71 72 73 74 75 76 77 78 79
  });

  run("SHOW CREATE STABLE st1");
}

TEST_F(ParserShowToUseTest, showCreateTable) {
  useDb("root", "test");

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_SHOW_CREATE_TABLE_STMT);
    ASSERT_EQ(pQuery->execMode, QUERY_EXEC_MODE_LOCAL);
    ASSERT_TRUE(pQuery->haveResultSet);
X
Xiaoyu Wang 已提交
80 81
    ASSERT_NE(((SShowCreateTableStmt*)pQuery->pRoot)->pDbCfg, nullptr);
    ASSERT_NE(((SShowCreateTableStmt*)pQuery->pRoot)->pTableCfg, nullptr);
82 83 84 85
  });

  run("SHOW CREATE TABLE t1");
}
86 87 88 89

TEST_F(ParserShowToUseTest, showDatabases) {
  useDb("root", "test");

90
  run("SHOW databases");
91 92 93 94 95
}

TEST_F(ParserShowToUseTest, showDnodes) {
  useDb("root", "test");

96
  run("SHOW dnodes");
97 98
}

99 100 101 102
TEST_F(ParserShowToUseTest, showDnodeVariables) {
  useDb("root", "test");

  run("SHOW DNODE 1 VARIABLES");
103 104

  run("SHOW DNODE 1 VARIABLES LIKE '%debug%'");
105 106
}

107 108 109
TEST_F(ParserShowToUseTest, showFunctions) {
  useDb("root", "test");

110
  run("SHOW functions");
111 112
}

113
// todo SHOW licence
114

115 116 117 118 119 120
TEST_F(ParserShowToUseTest, showLocalVariables) {
  useDb("root", "test");

  run("SHOW LOCAL VARIABLES");
}

121 122 123
TEST_F(ParserShowToUseTest, showIndexes) {
  useDb("root", "test");

124
  run("SHOW indexes from t1");
125

126
  run("SHOW indexes from t1 from test");
127 128 129 130 131
}

TEST_F(ParserShowToUseTest, showMnodes) {
  useDb("root", "test");

132
  run("SHOW mnodes");
133 134 135 136 137
}

TEST_F(ParserShowToUseTest, showQnodes) {
  useDb("root", "test");

138
  run("SHOW qnodes");
139 140
}

141 142
// todo SHOW queries
// todo SHOW scores
143 144 145 146

TEST_F(ParserShowToUseTest, showStables) {
  useDb("root", "test");

147
  run("SHOW stables");
148

149
  run("SHOW test.stables");
150

151
  run("SHOW stables like 'c%'");
152

153
  run("SHOW test.stables like 'c%'");
154 155 156 157 158
}

TEST_F(ParserShowToUseTest, showStreams) {
  useDb("root", "test");

159 160 161
  run("SHOW streams");
}

162 163 164 165 166 167 168 169 170
TEST_F(ParserShowToUseTest, showSubscriptions) {
  useDb("root", "test");

  setCheckDdlFunc(
      [&](const SQuery* pQuery, ParserStage stage) { ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_SELECT_STMT); });

  run("SHOW SUBSCRIPTIONS");
}

171 172 173 174
TEST_F(ParserShowToUseTest, showTransactions) {
  useDb("root", "test");

  run("SHOW TRANSACTIONS");
175 176 177 178 179
}

TEST_F(ParserShowToUseTest, showTables) {
  useDb("root", "test");

180
  run("SHOW tables");
181

182
  run("SHOW test.tables");
183

184
  run("SHOW tables like 'c%'");
185

186
  run("SHOW test.tables like 'c%'");
187 188
}

189 190 191 192 193 194
TEST_F(ParserShowToUseTest, showTableDistributed) {
  useDb("root", "test");

  run("SHOW TABLE DISTRIBUTED st1");
}

195 196 197 198 199 200 201
TEST_F(ParserShowToUseTest, showTableTags) {
  useDb("root", "test");

  run("SHOW TABLE TAGS FROM st1");

  run("SHOW TABLE TAGS tag1, tag2 FROM st1");

202
  run("SHOW TABLE TAGS TBNAME, _TAGS, tag3 FROM st1");
203 204
}

205 206 207 208 209 210
TEST_F(ParserShowToUseTest, showTags) {
  useDb("root", "test");

  run("SHOW TAGS FROM st1s1");
}

211
// todo SHOW topics
212 213 214 215

TEST_F(ParserShowToUseTest, showUsers) {
  useDb("root", "test");

216 217 218 219 220 221 222
  run("SHOW USERS");
}

TEST_F(ParserShowToUseTest, showUserPrivileges) {
  useDb("root", "test");

  run("SHOW USER PRIVILEGES");
223 224
}

225 226 227 228 229
TEST_F(ParserShowToUseTest, showVariables) {
  useDb("root", "test");

  run("SHOW VARIABLES");
}
230 231 232 233

TEST_F(ParserShowToUseTest, showVgroups) {
  useDb("root", "test");

234
  run("SHOW VGROUPS");
235

236
  run("SHOW test.VGROUPS");
237 238
}

239 240 241 242 243 244 245
TEST_F(ParserShowToUseTest, showVnodes) {
  useDb("root", "test");

  run("SHOW VNODES 1");

  run("SHOW VNODES 'node1:7030'");
}
246

247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
TEST_F(ParserShowToUseTest, splitVgroup) {
  useDb("root", "test");

  SSplitVgroupReq expect = {0};

  auto setSplitVgroupReqFunc = [&](int32_t vgId) { expect.vgId = vgId; };

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_SPLIT_VGROUP_STMT);
    ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_SPLIT_VGROUP);
    SSplitVgroupReq req = {0};
    ASSERT_EQ(tDeserializeSSplitVgroupReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
    ASSERT_EQ(req.vgId, expect.vgId);
  });

  setSplitVgroupReqFunc(15);
  run("SPLIT VGROUP 15");
}
265

X
Xiaoyu Wang 已提交
266 267 268 269 270
TEST_F(ParserShowToUseTest, trimDatabase) {
  useDb("root", "test");

  STrimDbReq expect = {0};

271 272 273 274
  auto setTrimDbReq = [&](const char* pDb, int32_t maxSpeed = 0) {
    snprintf(expect.db, sizeof(expect.db), "0.%s", pDb);
    expect.maxSpeed = maxSpeed;
  };
X
Xiaoyu Wang 已提交
275 276 277 278 279 280 281

  setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
    ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_TRIM_DATABASE_STMT);
    ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_TRIM_DB);
    STrimDbReq req = {0};
    ASSERT_EQ(tDeserializeSTrimDbReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
    ASSERT_EQ(std::string(req.db), std::string(expect.db));
282
    ASSERT_EQ(req.maxSpeed, expect.maxSpeed);
X
Xiaoyu Wang 已提交
283 284 285 286
  });

  setTrimDbReq("wxy_db");
  run("TRIM DATABASE wxy_db");
287 288 289

  setTrimDbReq("wxy_db", 100);
  run("TRIM DATABASE wxy_db MAX_SPEED 100");
X
Xiaoyu Wang 已提交
290 291
}

292 293 294 295 296 297 298
TEST_F(ParserShowToUseTest, useDatabase) {
  useDb("root", "test");

  run("use wxy_db");
}

}  // namespace ParserTest