YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/test/ql-alter-table-test.cc
Line
Count
Source (jump to first uncovered line)
1
//--------------------------------------------------------------------------------------------------
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
// in compliance with the License.  You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software distributed under the License
10
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
// or implied.  See the License for the specific language governing permissions and limitations
12
// under the License.
13
//
14
//--------------------------------------------------------------------------------------------------
15
16
#include "yb/yql/cql/ql/test/ql-test-base.h"
17
18
namespace yb {
19
namespace ql {
20
21
0
TEST_F(QLTestBase, TestQLAlterTableRemoveIndexedColumn) {
22
  // Init the simulated cluster.
23
0
  ASSERT_NO_FATALS(CreateSimulatedCluster());
24
25
  // Get an available processor.
26
0
  TestQLProcessor *processor = GetQLProcessor();
27
28
0
  EXEC_VALID_STMT("CREATE TABLE t(h int, r int, v int, v1 int, PRIMARY KEY(h, r)) "
29
0
                  "WITH transactions = { 'enabled' : true };");
30
0
  EXEC_VALID_STMT("ALTER TABLE t DROP v1;");
31
0
  EXEC_VALID_STMT("CREATE UNIQUE INDEX t_idx ON t(r, v);");
32
  // Check hash key column can't be dropped
33
0
  EXEC_INVALID_STMT_WITH_ERROR("ALTER TABLE t DROP h;",
34
0
      "Alter key column. Can't alter key column");
35
  // Check indexed range key column can't be dropped
36
0
  EXEC_INVALID_STMT_WITH_ERROR("ALTER TABLE t DROP r;",
37
0
      "Feature Not Yet Implemented. Can't drop column used in an index. "
38
0
      "Remove 't_idx' index first and try again");
39
  // Check indexed column can't be dropped
40
0
  EXEC_INVALID_STMT_WITH_ERROR("ALTER TABLE t DROP v;",
41
0
      "Feature Not Yet Implemented. Can't drop column used in an index. "
42
0
      "Remove 't_idx' index first and try again");
43
0
  EXEC_VALID_STMT("DROP INDEX t_idx;");
44
  // Check range key column can't be dropped
45
0
  EXEC_INVALID_STMT_WITH_ERROR("ALTER TABLE t DROP r;",
46
0
      "Execution Error. cannot remove a key column");
47
0
  EXEC_VALID_STMT("ALTER TABLE t DROP v;");
48
0
}
49
50
0
TEST_F(QLTestBase, TestQLAlterTableRemoveIndexedColumnExpr) {
51
  // Init the simulated cluster.
52
0
      ASSERT_NO_FATALS(CreateSimulatedCluster());
53
54
  // Get an available processor.
55
0
  TestQLProcessor *processor = GetQLProcessor();
56
57
0
  EXEC_VALID_STMT("CREATE TABLE t(h int, r int, v jsonb, PRIMARY KEY(h, r)) "
58
0
                  "WITH transactions = { 'enabled' : true };");
59
0
  EXEC_VALID_STMT("CREATE INDEX t_idx ON t(v->>'b') INCLUDE (r);");
60
  // Check indexed range key column can't be dropped
61
0
  EXEC_INVALID_STMT_WITH_ERROR("ALTER TABLE t DROP r;",
62
0
      "Feature Not Yet Implemented. Can't drop column used in an index. "
63
0
      "Remove 't_idx' index first and try again");
64
  // Check indexed column can't be dropped
65
0
  EXEC_INVALID_STMT_WITH_ERROR("ALTER TABLE t DROP v;",
66
0
      "Feature Not Yet Implemented. Can't drop column used in an index. "
67
0
      "Remove 't_idx' index first and try again");
68
0
  EXEC_VALID_STMT("DROP INDEX t_idx;");
69
  // Check range key column can't be dropped
70
0
  EXEC_INVALID_STMT_WITH_ERROR("ALTER TABLE t DROP r;",
71
0
      "Execution Error. cannot remove a key column");
72
0
  EXEC_VALID_STMT("ALTER TABLE t DROP v;");
73
0
}
74
75
} // namespace ql
76
} // namespace yb