Google Cloud Bigtable C++ Client  1.1.0
A C++ Client Library for Google Cloud Bigtable
table_config.cc
Go to the documentation of this file.
1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // 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
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "google/cloud/bigtable/table_config.h"
16 
17 namespace google {
18 namespace cloud {
19 namespace bigtable {
20 inline namespace BIGTABLE_CLIENT_NS {
21 // NOLINTNEXTLINE(readability-identifier-naming)
23  // As a challenge, we implement the strong exception guarantee in this
24  // function.
25  // First create a temporary value to hold intermediate computations.
26  ::google::bigtable::admin::v2::CreateTableRequest tmp;
27  auto& table = *tmp.mutable_table();
28  // Make sure there are nodes to receive all the values in column_families_.
29  auto& families = *table.mutable_column_families();
30  for (auto const& kv : column_families_) {
31  families[kv.first].mutable_gc_rule()->Clear();
32  }
33  // Make sure there is space to receive all the values in initial_splits_.
34  tmp.mutable_initial_splits()->Reserve(
35  static_cast<int>(initial_splits_.size()));
36  // Copy the granularity.
37  table.set_granularity(timestamp_granularity());
38 
39  // None of the operations that follow can fail, they are all `noexcept`:
40  for (auto& kv : column_families_) {
41  *families[kv.first].mutable_gc_rule() = std::move(kv.second).as_proto();
42  }
43  for (auto& split : initial_splits_) {
44  tmp.add_initial_splits()->set_key(std::move(split));
45  }
46  initial_splits_.clear();
47  column_families_.clear();
48  granularity_ = TIMESTAMP_GRANULARITY_UNSPECIFIED;
49  return tmp;
50 }
51 
52 // Disable clang-tidy warnings for these two definitions. clang-tidy is confused
53 // it claims, for example:
54 // error: redundant 'MILLIS' declaration
55 // [readability-redundant-declaration,-warnings-as-errors]
56 // But these are not declarations, these are definitions of variables that are
57 // odr-used in at least the tests:
58 // http://en.cppreference.com/w/cpp/language/definition
59 // In C++17 these would be inline variables and we would not care, but alas! we
60 // are sticking to C++11 (for good reasons).
64 
65 } // namespace BIGTABLE_CLIENT_NS
66 } // namespace bigtable
67 } // namespace cloud
68 } // namespace google
static constexpr TimestampGranularity TIMESTAMP_GRANULARITY_UNSPECIFIED
Definition: table_config.h:49
::google::bigtable::admin::v2::CreateTableRequest as_proto() &&
Move the contents to the proto to create tables.
Definition: table_config.cc:22
#define BIGTABLE_CLIENT_NS
Definition: version.h:22
static constexpr TimestampGranularity MILLIS
Definition: table_config.h:47
Specify the initial schema for a new table.
Definition: table_config.h:29
Contains all the Cloud Bigtable C++ client APIs.