parShowToUse.cpp 5.2 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, showConsumers) {
  useDb("root", "test");

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

  run("SHOW CONSUMERS");
}

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
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);
D
dapan1121 已提交
57
    ASSERT_NE(((SShowCreateTableStmt*)pQuery->pRoot)->pCfg, nullptr);
58 59 60 61 62 63 64 65 66 67 68 69
  });

  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);
D
dapan1121 已提交
70
    ASSERT_NE(((SShowCreateTableStmt*)pQuery->pRoot)->pCfg, nullptr);
71 72 73 74
  });

  run("SHOW CREATE TABLE t1");
}
75 76 77 78

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

79
  run("SHOW databases");
80 81 82 83 84
}

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

85
  run("SHOW dnodes");
86 87
}

88 89 90 91 92 93
TEST_F(ParserShowToUseTest, showDnodeVariables) {
  useDb("root", "test");

  run("SHOW DNODE 1 VARIABLES");
}

94 95 96
TEST_F(ParserShowToUseTest, showFunctions) {
  useDb("root", "test");

97
  run("SHOW functions");
98 99
}

100
// todo SHOW licence
101

102 103 104 105 106 107
TEST_F(ParserShowToUseTest, showLocalVariables) {
  useDb("root", "test");

  run("SHOW LOCAL VARIABLES");
}

108 109 110
TEST_F(ParserShowToUseTest, showIndexes) {
  useDb("root", "test");

111
  run("SHOW indexes from t1");
112

113
  run("SHOW indexes from t1 from test");
114 115 116 117 118
}

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

119
  run("SHOW mnodes");
120 121 122 123 124
}

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

125
  run("SHOW modules");
126 127 128 129 130
}

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

131
  run("SHOW qnodes");
132 133
}

134 135
// todo SHOW queries
// todo SHOW scores
136 137 138 139

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

140
  run("SHOW stables");
141

142
  run("SHOW test.stables");
143

144
  run("SHOW stables like 'c%'");
145

146
  run("SHOW test.stables like 'c%'");
147 148 149 150 151
}

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

152 153 154
  run("SHOW streams");
}

155 156 157 158 159 160 161 162 163
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");
}

164 165 166 167
TEST_F(ParserShowToUseTest, showTransactions) {
  useDb("root", "test");

  run("SHOW TRANSACTIONS");
168 169 170 171 172
}

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

173
  run("SHOW tables");
174

175
  run("SHOW test.tables");
176

177
  run("SHOW tables like 'c%'");
178

179
  run("SHOW test.tables like 'c%'");
180 181
}

182
// todo SHOW topics
183 184 185 186

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

187
  run("SHOW users");
188 189
}

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

  run("SHOW VARIABLES");
}
195 196 197 198

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

199
  run("SHOW vgroups");
200

201
  run("SHOW test.vgroups");
202 203
}

204
// todo SHOW vnodes
205

206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
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");
}
224 225 226 227 228 229 230 231

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

  run("use wxy_db");
}

}  // namespace ParserTest