15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_MUTATIONS_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_MUTATIONS_H
18#include "google/cloud/bigtable/cell.h"
19#include "google/cloud/bigtable/row_key.h"
20#include "google/cloud/bigtable/version.h"
21#include "google/cloud/grpc_error_delegate.h"
22#include "google/cloud/internal/big_endian.h"
23#include "google/cloud/status.h"
24#include "google/cloud/status_or.h"
25#include "absl/meta/type_traits.h"
26#include <google/bigtable/v2/bigtable.pb.h>
27#include <google/bigtable/v2/data.pb.h>
28#include <google/protobuf/util/message_differencer.h>
29#include <grpcpp/grpcpp.h>
38GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
40
41
42
43
44
50
51
52
53
54
58template <
typename ColumnType,
typename ValueType>
60 std::chrono::milliseconds timestamp, ValueType&& value) {
62 auto& set_cell = *m
.op.mutable_set_cell();
63 set_cell.set_family_name(std::move(family));
64 set_cell.set_column_qualifier(std::forward<ColumnType>(column));
65 set_cell.set_timestamp_micros(
66 std::chrono::duration_cast<std::chrono::microseconds>(timestamp).count());
67 set_cell.set_value(std::forward<ValueType>(value));
72template <
typename ColumnType>
74 std::chrono::milliseconds timestamp, std::int64_t value) {
76 auto& set_cell = *m
.op.mutable_set_cell();
77 set_cell.set_family_name(std::move(family));
78 set_cell.set_column_qualifier(std::forward<ColumnType>(column));
79 set_cell.set_timestamp_micros(
80 std::chrono::duration_cast<std::chrono::microseconds>(timestamp).count());
81 set_cell.set_value(
google::
cloud::internal::EncodeBigEndian(value));
86
87
88
89
90template <
typename ColumnType,
typename ValueType>
91Mutation SetCell(std::string family, ColumnType&& column, ValueType&& value) {
93 auto& set_cell = *m
.op.mutable_set_cell();
94 set_cell.set_family_name(std::move(family));
95 set_cell.set_column_qualifier(std::forward<ColumnType>(column));
97 set_cell.set_value(std::forward<ValueType>(value));
102
103
104
105
106
107template <
typename ColumnType>
108Mutation SetCell(std::string family, ColumnType&& column, std::int64_t value) {
110 auto& set_cell = *m
.op.mutable_set_cell();
111 set_cell.set_family_name(std::move(family));
112 set_cell.set_column_qualifier(std::forward<ColumnType>(column));
114 set_cell.set_value(
google::
cloud::internal::EncodeBigEndian(value));
119
120
121
122
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2,
170 std::chrono::duration<Rep1, Period1> timestamp_begin,
171 std::chrono::duration<Rep2, Period2> timestamp_end) {
173 auto& d = *m
.op.mutable_delete_from_column();
174 d.set_family_name(std::move(family));
175 d.set_column_qualifier(std::forward<ColumnType>(column));
176 d.mutable_time_range()->set_start_timestamp_micros(
177 std::chrono::duration_cast<std::chrono::microseconds>(timestamp_begin)
179 d.mutable_time_range()->set_end_timestamp_micros(
180 std::chrono::duration_cast<std::chrono::microseconds>(timestamp_end)
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214template <
typename Rep1,
typename Period1,
typename ColumnType>
216 std::string family, ColumnType&& column,
217 std::chrono::duration<Rep1, Period1> timestamp_begin) {
219 auto& d = *m
.op.mutable_delete_from_column();
220 d.set_family_name(std::move(family));
221 d.set_column_qualifier(std::forward<ColumnType>(column));
222 d.mutable_time_range()->set_start_timestamp_micros(
223 std::chrono::duration_cast<std::chrono::microseconds>(timestamp_begin)
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257template <
typename Rep2,
typename Period2,
typename ColumnType>
259 std::string family, ColumnType&& column,
260 std::chrono::duration<Rep2, Period2> timestamp_end) {
262 auto& d = *m
.op.mutable_delete_from_column();
263 d.set_family_name(std::move(family));
264 d.set_column_qualifier(std::forward<ColumnType>(column));
265 d.mutable_time_range()->set_end_timestamp_micros(
266 std::chrono::duration_cast<std::chrono::microseconds>(timestamp_end)
272template <
typename ColumnType>
275 auto& d = *m
.op.mutable_delete_from_column();
276 d.set_family_name(std::move(family));
277 d.set_column_qualifier(std::forward<ColumnType>(column));
289
290
291
292
293
294
295
299 template <
typename RowKey,
301 typename std::enable_if<
302 std::is_constructible<RowKeyType, RowKey>::value,
int>::type = 0
307 request_.set_row_key(RowKeyType(std::forward<RowKey>(row_key)));
311 template <
typename RowKey>
313 request_.set_row_key(std::forward<RowKey>(row_key));
314 for (
auto&& i : list) {
315 *request_.add_mutations() = i
.op;
320 template <
typename RowKey,
typename... M,
322 typename std::enable_if<
323 std::is_constructible<RowKeyType, RowKey>::value,
int>::type = 0
328 absl::conjunction<std::is_convertible<M,
Mutation>...>::value,
329 "The arguments passed to SingleRowMutation(std::string, ...) must be "
330 "convertible to Mutation");
331 request_.set_row_key(std::forward<RowKey>(row_key));
332 emplace_many(std::forward<M>(m)...);
337 ::
google::bigtable::v2::MutateRowsRequest::Entry entry) {
339 swap(*request_.mutable_row_key(), *entry.mutable_row_key());
340 swap(*request_.mutable_mutations(), *entry.mutable_mutations());
345 : request_(std::move(request)) {}
349 *request_.add_mutations() = std::move(mut
.op);
354 RowKeyType
const&
row_key()
const {
return request_.row_key(); }
365 return google::protobuf::util::MessageDifferencer::Equivalent(a.request_,
374 void MoveTo(
google::bigtable::v2::MutateRowsRequest::Entry* entry) {
375 entry->set_row_key(std::move(*request_.mutable_row_key()));
376 *entry->mutable_mutations() = std::move(*request_.mutable_mutations());
380 void MoveTo(
google::bigtable::v2::MutateRowRequest& request) {
381 request.set_row_key(std::move(*request_.mutable_row_key()));
382 *request.mutable_mutations() = std::move(*request_.mutable_mutations());
386 void Clear() { request_.Clear(); }
390 template <
typename... M>
391 void emplace_many(
Mutation first, M&&... tail) {
393 emplace_many(std::forward<M>(tail)...);
398 ::
google::bigtable::v2::MutateRowRequest request_;
402
403
404
405
406
407
408
412 : status_
(std::move(status)
), original_index_(index) {}
424 return a.status_
== b.status_ && a.original_index_ == b.original_index_;
445
446
451 : std::runtime_error(msg), failures_(std::move(failures)) {}
455 : std::runtime_error(msg),
456 failures_(std::move(failures)),
457 status_(std::move(status)) {}
460
461
462
463
464
465
466
467
468
469
473
474
475
476
477
478 grpc::Status
const&
status()
const {
return status_; }
482 grpc::Status status_;
486
487
488
489
490
491
498 template <
typename Iterator>
502 "The iterator value type must be convertible to SingleRowMutation");
503 for (
auto i = begin; i != end; ++i) {
524 template <
typename... M,
526 typename std::enable_if<absl::conjunction<std::is_convertible<
533 emplace_many(std::forward<M>(m)...);
555 void MoveTo(
google::bigtable::v2::MutateRowsRequest* request) {
556 request_.Swap(request);
561 bool empty()
const {
return request_.entries().empty(); }
564 std::size_t
size()
const {
return request_.entries().size(); }
568 return request_.ByteSizeLong();
572 template <
typename... M>
575 emplace_many(std::forward<M>(tail)...);
580 google::bigtable::v2::MutateRowsRequest request_;
583GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Status & operator=(Status &&) noexcept
friend friend bool operator==(Status const &a, Status const &b)
Status(Status &&) noexcept
Represent a set of mutations across multiple rows.
Definition: mutations.h:492
bool empty() const
Return true if there are no mutations in this set.
Definition: mutations.h:561
BulkMutation(std::initializer_list< SingleRowMutation > list)
Create a multi-row mutation from a initializer list.
Definition: mutations.h:509
BulkMutation(SingleRowMutation mutation)
Create a multi-row mutation from a SingleRowMutation.
Definition: mutations.h:513
BulkMutation(Iterator begin, Iterator end)
Create a multi-row mutation from a range of SingleRowMutations.
Definition: mutations.h:499
BulkMutation(SingleRowMutation m1, SingleRowMutation m2)
Create a multi-row mutation from two SingleRowMutation.
Definition: mutations.h:518
BulkMutation & emplace_back(FailedMutation fm)
Definition: mutations.h:543
void MoveTo(google::bigtable::v2::MutateRowsRequest *request)
Move the contents into a bigtable::v2::MutateRowsRequest.
Definition: mutations.h:555
BulkMutation()=default
Create an empty set of mutations.
BulkMutation & emplace_back(SingleRowMutation mut)
Definition: mutations.h:537
std::size_t size() const
Return the number of mutations in this set.
Definition: mutations.h:564
BulkMutation(M &&... m)
Create a multi-row mutation from a variadic list.
Definition: mutations.h:532
std::size_t estimated_size_in_bytes() const
Return the estimated size in bytes of all the mutations in this set.
Definition: mutations.h:567
BulkMutation & push_back(SingleRowMutation mut)
Definition: mutations.h:549
The in-memory representation of a Bigtable cell.
Definition: cell.h:90
A SingleRowMutation that failed.
Definition: mutations.h:409
FailedMutation(google::cloud::Status status, int index)
Definition: mutations.h:411
FailedMutation(google::rpc::Status const &status, int index)
Definition: mutations.h:414
friend bool operator==(FailedMutation const &a, FailedMutation const &b) noexcept
Definition: mutations.h:422
FailedMutation & operator=(FailedMutation const &)=default
google::cloud::Status const & status() const
Definition: mutations.h:433
FailedMutation(FailedMutation const &)=default
FailedMutation(FailedMutation &&)=default
friend bool operator!=(FailedMutation const &a, FailedMutation const &b) noexcept
Definition: mutations.h:426
FailedMutation & operator=(FailedMutation &&)=default
int original_index() const
Definition: mutations.h:434
Report unrecoverable errors in a partially completed mutation.
Definition: mutations.h:447
std::vector< FailedMutation > const & failures() const
The details of each mutation failure.
Definition: mutations.h:470
PermanentMutationFailure(char const *msg, std::vector< FailedMutation > failures)
Definition: mutations.h:449
grpc::Status const & status() const
The grpc::Status of the request.
Definition: mutations.h:478
PermanentMutationFailure(char const *msg, grpc::Status status, std::vector< FailedMutation > failures)
Definition: mutations.h:453
Represent a single row mutation.
Definition: mutations.h:296
SingleRowMutation(RowKey &&row_key)
Create an empty mutation.
Definition: mutations.h:306
void MoveTo(google::bigtable::v2::MutateRowsRequest::Entry *entry)
Move the contents into a bigtable::v2::MutateRowsRequest::Entry.
Definition: mutations.h:374
void Clear()
Remove the contents of the mutation.
Definition: mutations.h:386
SingleRowMutation & operator=(SingleRowMutation &&)=default
SingleRowMutation(SingleRowMutation &&)=default
friend bool operator==(SingleRowMutation const &a, SingleRowMutation const &b) noexcept
Definition: mutations.h:363
SingleRowMutation & emplace_back(Mutation mut)
Definition: mutations.h:348
void MoveTo(google::bigtable::v2::MutateRowRequest &request)
Transfer the contents to request.
Definition: mutations.h:380
RowKeyType const & row_key() const
Definition: mutations.h:354
SingleRowMutation(RowKey &&row_key, std::initializer_list< Mutation > list)
Create a row mutation from a initializer list.
Definition: mutations.h:312
SingleRowMutation(::google::bigtable::v2::MutateRowRequest request)
Create a row mutation from gRPC proto.
Definition: mutations.h:344
SingleRowMutation & operator=(SingleRowMutation const &)=default
SingleRowMutation(SingleRowMutation const &)=default
SingleRowMutation(::google::bigtable::v2::MutateRowsRequest::Entry entry)
Create a row mutation from gRPC proto.
Definition: mutations.h:336
friend bool operator!=(SingleRowMutation const &a, SingleRowMutation const &b) noexcept
Definition: mutations.h:368
SingleRowMutation(RowKey &&row_key, M &&... m)
Create a single-row multiple-cell mutation from a variadic list.
Definition: mutations.h:326
The main interface to interact with data in a Cloud Bigtable table.
Definition: table.h:166
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28
Mutation SetCell(std::string family, ColumnType &&column, std::chrono::milliseconds timestamp, std::int64_t value)
Create a mutation to store a 64-bit big endian integer value.
Definition: mutations.h:73
Mutation DeleteFromColumn(std::string family, ColumnType &&column)
Delete all the values for the column.
Definition: mutations.h:273
Mutation DeleteFromFamily(std::string family)
Create a mutation to delete all the cells in a column family.
constexpr std::int64_t ServerSetTimestamp()
A magic value where the server sets the timestamp.
Definition: mutations.h:55
Mutation SetCell(Cell)
Create a mutation to set a cell value based on a bigtable::Cell.
Mutation SetCell(std::string family, ColumnType &&column, std::chrono::milliseconds timestamp, ValueType &&value)
Create a mutation to set a cell value.
Definition: mutations.h:59
Mutation DeleteFromColumnStartingFrom(std::string family, ColumnType &&column, std::chrono::duration< Rep1, Period1 > timestamp_begin)
Delete all the values for the column.
Definition: mutations.h:215
Mutation DeleteFromColumn(std::string family, ColumnType &&column, std::chrono::duration< Rep1, Period1 > timestamp_begin, std::chrono::duration< Rep2, Period2 > timestamp_end)
Definition: mutations.h:169
Mutation SetCell(std::string family, ColumnType &&column, std::int64_t value)
Create a mutation to store a 64-bit big endian integer value.
Definition: mutations.h:108
Mutation DeleteFromRow()
Create a mutation to delete all the cells in a row.
Mutation DeleteFromColumnEndingAt(std::string family, ColumnType &&column, std::chrono::duration< Rep2, Period2 > timestamp_end)
Delete all the values for the column.
Definition: mutations.h:258
Mutation SetCell(std::string family, ColumnType &&column, ValueType &&value)
Create a mutation to set a cell value where the server sets the time.
Definition: mutations.h:91
google::cloud::Status MakeStatusFromRpcError(google::rpc::Status const &proto)
Represent a single change to a specific row in a Table.
Definition: mutations.h:45
google::bigtable::v2::Mutation op
Definition: mutations.h:46