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-conditional-dml-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
class TestQLConditionalDml : public QLTestBase {
22
 public:
23
0
  TestQLConditionalDml() : QLTestBase() {
24
0
  }
25
};
26
27
0
TEST_F(TestQLConditionalDml, TestQLConditionalDml) {
28
  // Init the simulated cluster.
29
0
  ASSERT_NO_FATALS(CreateSimulatedCluster());
30
31
  // Get a processor.
32
0
  TestQLProcessor *processor = GetQLProcessor();
33
34
  // Create the table 1.
35
0
  const char *create_stmt =
36
0
      "CREATE TABLE t (h1 int, h2 varchar, "
37
0
                      "r1 int, r2 varchar, "
38
0
                      "c1 int, c2 varchar, "
39
0
                      "primary key((h1, h2), r1, r2));";
40
0
  CHECK_VALID_STMT(create_stmt);
41
42
  // Test parsing of conditional DML:
43
44
  // Test insert IF NOT EXISTS
45
0
  PARSE_VALID_STMT("INSERT INTO t (h1, h2, r1, r2, c1, c2) "
46
0
                   "VALUES (1, 'a', 2, 'b', 3, 'c') IF NOT EXISTS OR c1 = 0;");
47
48
  // Test insert IF NOT EXISTS again
49
0
  PARSE_VALID_STMT("INSERT INTO t (h1, h2, r1, r2, c1, c2) "
50
0
                   "VALUES (1, 'a', 2, 'b', 3, 'c') IF NOT EXISTS AND h1 = 1;");
51
52
  // Test insert IF EXISTS
53
0
  PARSE_VALID_STMT("INSERT INTO t (k) VALUES (1) IF NOT EXISTS;");
54
55
  // Test insert IF NOT EXISTS or a column condition
56
0
  PARSE_VALID_STMT("INSERT INTO t (k, c) VALUES (1, 2) IF NOT EXISTS OR c = 1" );
57
58
  // Test insert IF NOT EXISTS and two column condition
59
0
  PARSE_VALID_STMT("INSERT INTO t (k, c) VALUES (1, 2) IF NOT EXISTS OR c >= 0 and c <= 1" );
60
61
  // Test update IF EXISTS
62
0
  PARSE_VALID_STMT("UPDATE t set c = 1 WHERE k = 1 IF EXISTS" );
63
64
  // Test update IF NOT EXISTS
65
0
  PARSE_VALID_STMT("UPDATE t set c = 1 WHERE k = 1 IF NOT EXISTS" );
66
67
  // Test update IF EXISTS and a column condition
68
0
  PARSE_VALID_STMT("UPDATE t set c = 1 WHERE k = 1 IF EXISTS AND c = 1" );
69
70
  // Test delete IF EXISTS
71
0
  PARSE_VALID_STMT("DELETE FROM t WHERE k = 1 IF EXISTS" );
72
73
  // Test delete IF EXISTS and a column condition
74
0
  PARSE_VALID_STMT("DELETE FROM t WHERE k = 1 IF EXISTS AND c = 1" );
75
76
  // Test delete IF EXISTS and 2 column conditions with paranthesis
77
0
  PARSE_VALID_STMT("DELETE FROM t WHERE k = 1 IF EXISTS AND (c = 1 OR c = 2)" );
78
0
}
79
80
} // namespace ql
81
} // namespace yb