You need to sign in or sign up before continuing.
parShowToUse.cpp 4.7 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 37 38 39 40 41 42 43 44 45 46 47

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 已提交
48
    ASSERT_NE(((SShowCreateTableStmt*)pQuery->pRoot)->pCfg, nullptr);
49 50 51 52 53 54 55 56 57 58 59 60
  });

  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 已提交
61
    ASSERT_NE(((SShowCreateTableStmt*)pQuery->pRoot)->pCfg, nullptr);
62 63 64 65
  });

  run("SHOW CREATE TABLE t1");
}
66 67 68 69

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

70
  run("SHOW databases");
71 72 73 74 75
}

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

76
  run("SHOW dnodes");
77 78
}

79 80 81 82 83 84
TEST_F(ParserShowToUseTest, showDnodeVariables) {
  useDb("root", "test");

  run("SHOW DNODE 1 VARIABLES");
}

85 86 87
TEST_F(ParserShowToUseTest, showFunctions) {
  useDb("root", "test");

88
  run("SHOW functions");
89 90
}

91
// todo SHOW licence
92

93 94 95 96 97 98
TEST_F(ParserShowToUseTest, showLocalVariables) {
  useDb("root", "test");

  run("SHOW LOCAL VARIABLES");
}

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

102
  run("SHOW indexes from t1");
103

104
  run("SHOW indexes from t1 from test");
105 106 107 108 109
}

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

110
  run("SHOW mnodes");
111 112 113 114 115
}

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

116
  run("SHOW modules");
117 118 119 120 121
}

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

122
  run("SHOW qnodes");
123 124
}

125 126
// todo SHOW queries
// todo SHOW scores
127 128 129 130

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

131
  run("SHOW stables");
132

133
  run("SHOW test.stables");
134

135
  run("SHOW stables like 'c%'");
136

137
  run("SHOW test.stables like 'c%'");
138 139 140 141 142
}

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

143 144 145 146 147 148 149
  run("SHOW streams");
}

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

  run("SHOW TRANSACTIONS");
150 151 152 153 154
}

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

155
  run("SHOW tables");
156

157
  run("SHOW test.tables");
158

159
  run("SHOW tables like 'c%'");
160

161
  run("SHOW test.tables like 'c%'");
162 163
}

164
// todo SHOW topics
165 166 167 168

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

169
  run("SHOW users");
170 171
}

172 173 174 175 176
TEST_F(ParserShowToUseTest, showVariables) {
  useDb("root", "test");

  run("SHOW VARIABLES");
}
177 178 179 180

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

181
  run("SHOW vgroups");
182

183
  run("SHOW test.vgroups");
184 185
}

186
// todo SHOW vnodes
187

188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
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");
}
206 207 208 209 210 211 212 213

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

  run("use wxy_db");
}

}  // namespace ParserTest