Google Cloud Bigtable C++ Client  1.1.0
A C++ Client Library for Google Cloud Bigtable
table_config.h
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 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_CONFIG_H_
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_CONFIG_H_
17 
18 #include "google/cloud/bigtable/column_family.h"
19 #include "google/cloud/bigtable/version.h"
20 #include <google/bigtable/admin/v2/bigtable_table_admin.pb.h>
21 #include <map>
22 #include <vector>
23 
24 namespace google {
25 namespace cloud {
26 namespace bigtable {
27 inline namespace BIGTABLE_CLIENT_NS {
28 /// Specify the initial schema for a new table.
29 class TableConfig {
30  public:
31  TableConfig() : granularity_(TIMESTAMP_GRANULARITY_UNSPECIFIED) {}
32 
33  TableConfig(std::map<std::string, GcRule> column_families,
34  std::vector<std::string> initial_splits)
35  : column_families_(std::move(column_families)),
36  initial_splits_(std::move(initial_splits)),
37  granularity_(TIMESTAMP_GRANULARITY_UNSPECIFIED) {}
38 
39  /// Move the contents to the proto to create tables.
40  // Note that this function returns a copy intentionally, the object does not
41  // have the proto as a member variable, it constructs the proto from its own
42  // data structures for "reasons".
43  ::google::bigtable::admin::v2::CreateTableRequest as_proto() &&;
44 
45  using TimestampGranularity =
46  ::google::bigtable::admin::v2::Table::TimestampGranularity;
47  constexpr static TimestampGranularity MILLIS =
48  ::google::bigtable::admin::v2::Table::MILLIS;
49  constexpr static TimestampGranularity TIMESTAMP_GRANULARITY_UNSPECIFIED =
50  ::google::bigtable::admin::v2::Table::TIMESTAMP_GRANULARITY_UNSPECIFIED;
51 
52  //@{
53  /// @name Accessors and modifiers for all attributes
54  std::map<std::string, GcRule> const& column_families() const {
55  return column_families_;
56  }
57  void add_column_family(std::string column_family_name, GcRule gc_rule) {
58  column_families_.emplace(std::move(column_family_name), std::move(gc_rule));
59  }
60 
61  std::vector<std::string> const& initial_splits() const {
62  return initial_splits_;
63  }
64  void add_initial_split(std::string split) {
65  initial_splits_.emplace_back(std::move(split));
66  }
67 
68  /**
69  * Return the timestamp granularity parameter.
70  *
71  * Cloud Bigtable currently supports only millisecond granularity in the
72  * cell timestamps, both `TIMESTAMP_GRANULARITY_UNSPECIFIED` and `MILLIS`
73  * have the same effect.
74  */
75  TimestampGranularity timestamp_granularity() const { return granularity_; }
76 
77  /**
78  * Set the timestamp granularity parameter.
79  *
80  * Cloud Bigtable currently supports only millisecond granularity in the
81  * cell timestamps, both `TIMESTAMP_GRANULARITY_UNSPECIFIED` and `MILLIS`
82  * have the same effect. Creating cells with higher granularity than the
83  * supported value is rejected by the server.
84  */
85  void set_timestamp_granularity(TimestampGranularity new_value) {
86  granularity_ = new_value;
87  }
88  //@}
89 
90  private:
91  std::map<std::string, GcRule> column_families_;
92  std::vector<std::string> initial_splits_;
93  ::google::bigtable::admin::v2::Table::TimestampGranularity granularity_;
94 };
95 
96 } // namespace BIGTABLE_CLIENT_NS
97 } // namespace bigtable
98 } // namespace cloud
99 } // namespace google
100 
101 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_CONFIG_H_
#define BIGTABLE_CLIENT_NS
Definition: version.h:22