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
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
TEST_F(ParserShowToUseTest, showTags) {
  useDb("root", "test");

  run("SHOW TAGS FROM st1s1");
}

201
// todo SHOW topics
202 203 204 205

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

206
  run("SHOW users");
207 208
}

209 210 211 212 213
TEST_F(ParserShowToUseTest, showVariables) {
  useDb("root", "test");

  run("SHOW VARIABLES");
}
214 215 216 217

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

218
  run("SHOW VGROUPS");
219

220
  run("SHOW test.VGROUPS");
221 222
}

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

  run("SHOW VNODES 1");

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

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

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

  STrimDbReq expect = {0};

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

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

  setTrimDbReq("wxy_db");
  run("TRIM DATABASE wxy_db");
271 272 273

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

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

  run("use wxy_db");
}

}  // namespace ParserTest