parShowToUse.cpp 6.6 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 103 104
TEST_F(ParserShowToUseTest, showDnodeVariables) {
  useDb("root", "test");

  run("SHOW DNODE 1 VARIABLES");
}

105 106 107
TEST_F(ParserShowToUseTest, showFunctions) {
  useDb("root", "test");

108
  run("SHOW functions");
109 110
}

111
// todo SHOW licence
112

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

  run("SHOW LOCAL VARIABLES");
}

119 120 121
TEST_F(ParserShowToUseTest, showIndexes) {
  useDb("root", "test");

122
  run("SHOW indexes from t1");
123

124
  run("SHOW indexes from t1 from test");
125 126 127 128 129
}

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

130
  run("SHOW mnodes");
131 132 133 134 135
}

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

136
  run("SHOW modules");
137 138 139 140 141
}

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

142
  run("SHOW qnodes");
143 144
}

145 146
// todo SHOW queries
// todo SHOW scores
147 148 149 150

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

151
  run("SHOW stables");
152

153
  run("SHOW test.stables");
154

155
  run("SHOW stables like 'c%'");
156

157
  run("SHOW test.stables like 'c%'");
158 159 160 161 162
}

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

163 164 165
  run("SHOW streams");
}

166 167 168 169 170 171 172 173 174
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");
}

175 176 177 178
TEST_F(ParserShowToUseTest, showTransactions) {
  useDb("root", "test");

  run("SHOW TRANSACTIONS");
179 180 181 182 183
}

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

184
  run("SHOW tables");
185

186
  run("SHOW test.tables");
187

188
  run("SHOW tables like 'c%'");
189

190
  run("SHOW test.tables like 'c%'");
191 192
}

193 194 195 196 197 198
TEST_F(ParserShowToUseTest, showTableDistributed) {
  useDb("root", "test");

  run("SHOW TABLE DISTRIBUTED st1");
}

199
// todo SHOW topics
200 201 202 203

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

204
  run("SHOW users");
205 206
}

207 208 209 210 211
TEST_F(ParserShowToUseTest, showVariables) {
  useDb("root", "test");

  run("SHOW VARIABLES");
}
212 213 214 215

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

216
  run("SHOW vgroups");
217

218
  run("SHOW test.vgroups");
219 220
}

221 222 223 224 225 226 227
TEST_F(ParserShowToUseTest, showVnodes) {
  useDb("root", "test");

  run("SHOW VNODES 1");

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

229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
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");
}
247

X
Xiaoyu Wang 已提交
248 249 250 251 252
TEST_F(ParserShowToUseTest, trimDatabase) {
  useDb("root", "test");

  STrimDbReq expect = {0};

253 254 255 256
  auto setTrimDbReq = [&](const char* pDb, int32_t maxSpeed = 0) {
    snprintf(expect.db, sizeof(expect.db), "0.%s", pDb);
    expect.maxSpeed = maxSpeed;
  };
X
Xiaoyu Wang 已提交
257 258 259 260 261 262 263

  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));
264
    ASSERT_EQ(req.maxSpeed, expect.maxSpeed);
X
Xiaoyu Wang 已提交
265 266 267 268
  });

  setTrimDbReq("wxy_db");
  run("TRIM DATABASE wxy_db");
269 270 271

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

274 275 276 277 278 279 280
TEST_F(ParserShowToUseTest, useDatabase) {
  useDb("root", "test");

  run("use wxy_db");
}

}  // namespace ParserTest