YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/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
3
    : client_(client), namespace_name_(namespace_name), namespace_id_(namespace_id) {}
26
27
0
YBNamespaceAlterer::~YBNamespaceAlterer() {}
28
29
3
Status YBNamespaceAlterer::Alter(CoarseTimePoint deadline) {
30
3
  master::AlterNamespaceRequestPB req;
31
3
  RETURN_NOT_OK(ToRequest(&req));
32
3
  return client_->data_->AlterNamespace(client_, req, client_->PatchAdminDeadline(deadline));
33
3
}
34
35
3
YBNamespaceAlterer* YBNamespaceAlterer::RenameTo(const std::string& new_name) {
36
3
  rename_to_ = new_name;
37
3
  return this;
38
3
}
39
40
3
YBNamespaceAlterer* YBNamespaceAlterer::SetDatabaseType(YQLDatabase type) {
41
3
  database_type_ = type;
42
3
  return this;
43
3
}
44
45
3
Status YBNamespaceAlterer::ToRequest(master::AlterNamespaceRequestPB* req) {
46
3
  req->mutable_namespace_()->set_name(namespace_name_);
47
3
  if (!namespace_id_.empty()) {
48
3
    req->mutable_namespace_()->set_id(namespace_id_);
49
3
  }
50
3
  if (database_type_) {
51
3
    req->mutable_namespace_()->set_database_type(*database_type_);
52
3
  }
53
3
  if (!rename_to_) {
54
0
    return STATUS(InvalidArgument, "Cannot alter namespace without specifying new name");
55
0
  }
56
3
  req->set_new_name(*rename_to_);
57
3
  return Status::OK();
58
3
}
59
60
}  // namespace client
61
}  // namespace yb