YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/client/namespace_alterer.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#include "yb/client/namespace_alterer.h"
15
16
#include "yb/client/client-internal.h"
17
18
#include "yb/master/master_ddl.pb.h"
19
20
namespace yb {
21
namespace client {
22
23
YBNamespaceAlterer::YBNamespaceAlterer(
24
    YBClient* client, const std::string& namespace_name, const std::string& namespace_id)
25
0
    : client_(client), namespace_name_(namespace_name), namespace_id_(namespace_id) {}
26
27
0
YBNamespaceAlterer::~YBNamespaceAlterer() {}
28
29
0
Status YBNamespaceAlterer::Alter(CoarseTimePoint deadline) {
30
0
  master::AlterNamespaceRequestPB req;
31
0
  RETURN_NOT_OK(ToRequest(&req));
32
0
  return client_->data_->AlterNamespace(client_, req, client_->PatchAdminDeadline(deadline));
33
0
}
34
35
0
YBNamespaceAlterer* YBNamespaceAlterer::RenameTo(const std::string& new_name) {
36
0
  rename_to_ = new_name;
37
0
  return this;
38
0
}
39
40
0
YBNamespaceAlterer* YBNamespaceAlterer::SetDatabaseType(YQLDatabase type) {
41
0
  database_type_ = type;
42
0
  return this;
43
0
}
44
45
0
Status YBNamespaceAlterer::ToRequest(master::AlterNamespaceRequestPB* req) {
46
0
  req->mutable_namespace_()->set_name(namespace_name_);
47
0
  if (!namespace_id_.empty()) {
48
0
    req->mutable_namespace_()->set_id(namespace_id_);
49
0
  }
50
0
  if (database_type_) {
51
0
    req->mutable_namespace_()->set_database_type(*database_type_);
52
0
  }
53
0
  if (!rename_to_) {
54
0
    return STATUS(InvalidArgument, "Cannot alter namespace without specifying new name");
55
0
  }
56
0
  req->set_new_name(*rename_to_);
57
0
  return Status::OK();
58
0
}
59
60
}  // namespace client
61
}  // namespace yb