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/ptree/pt_truncate.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
// Treenode definitions for TRUNCATE statements.
16
//--------------------------------------------------------------------------------------------------
17
18
#include "yb/yql/cql/ql/ptree/pt_truncate.h"
19
20
#include "yb/client/table.h"
21
22
#include "yb/yql/cql/ql/ptree/pt_option.h"
23
#include "yb/yql/cql/ql/ptree/sem_context.h"
24
#include "yb/yql/cql/ql/ptree/yb_location.h"
25
26
DECLARE_bool(use_cassandra_authentication);
27
DECLARE_bool(ycql_require_drop_privs_for_truncate);
28
29
namespace yb {
30
namespace ql {
31
32
PTTruncateStmt::PTTruncateStmt(MemoryContext *memctx,
33
                               YBLocation::SharedPtr loc,
34
                               PTQualifiedNameListNode::SharedPtr names)
35
3.04k
    : TreeNode(memctx, loc), names_(names) {
36
3.04k
}
37
38
3.04k
PTTruncateStmt::~PTTruncateStmt() {
39
3.04k
}
40
41
3.04k
Status PTTruncateStmt::Analyze(SemContext *sem_context) {
42
3.04k
  if (names_->size() > 1) {
43
0
    return sem_context->Error(names_, "Only one table name is allowed in a truncate statement",
44
0
                              ErrorCode::CQL_STATEMENT_INVALID);
45
0
  }
46
47
  // Processing table name.
48
3.04k
  bool is_system_ignored = false;
49
3.04k
  RETURN_NOT_OK(name()->AnalyzeName(sem_context, ObjectType::TABLE));
50
51
  // Permissions check happen in LookupTable if flag use_cassandra_authentication is enabled.
52
3.04k
  if (FLAGS_ycql_require_drop_privs_for_truncate) {
53
21
    return sem_context->LookupTable(yb_table_name(), name()->loc(), true /* write_table */,
54
21
                                    PermissionType::DROP_PERMISSION,
55
21
                                    &table_, &is_system_ignored);
56
21
  }
57
3.02k
  return sem_context->LookupTable(yb_table_name(), name()->loc(), true /* write_table */,
58
3.02k
                                  PermissionType::MODIFY_PERMISSION,
59
3.02k
                                  &table_, &is_system_ignored);
60
3.02k
}
61
62
0
void PTTruncateStmt::PrintSemanticAnalysisResult(SemContext *sem_context) {
63
0
  VLOG(3) << "SEMANTIC ANALYSIS RESULT (" << *loc_ << "):\n TRUNCATE "
64
0
          << yb_table_name().ToString();
65
0
}
66
67
3.02k
const std::string& PTTruncateStmt::table_id() const {
68
3.02k
  return table_->id();
69
3.02k
}
70
71
}  // namespace ql
72
}  // namespace yb