Kudu C++ client API
Loading...
Searching...
No Matches
write_op.h
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17#ifndef KUDU_CLIENT_WRITE_OP_H
18#define KUDU_CLIENT_WRITE_OP_H
19
20// NOTE: using stdint.h instead of cstdint because this file is supposed
21// to be processed by a compiler lacking C++11 support.
22#include <stdint.h>
23
24// IWYU pragma: no_include <memory>
25#include <string>
26
27#include "kudu/client/shared_ptr.h" // IWYU pragma: keep
28#include "kudu/common/partial_row.h"
29#include "kudu/util/kudu_export.h"
30
31#ifdef KUDU_HEADERS_NO_STUBS
32#include "kudu/gutil/macros.h"
33#include "kudu/gutil/port.h"
34#else
35#include "kudu/client/stubs.h"
36#endif
37
38namespace kudu {
39
40namespace client {
41
42namespace internal {
43class Batcher;
44class ErrorCollector;
45class WriteRpc;
46} // namespace internal
47
48class KuduTable;
49
66class KUDU_EXPORT KuduWriteOperation {
67 public:
69 enum Type {
70 INSERT = 1,
71 UPDATE = 2,
72 DELETE = 3,
73 UPSERT = 4,
74 INSERT_IGNORE = 5,
75 UPDATE_IGNORE = 6,
76 DELETE_IGNORE = 7,
77 UPSERT_IGNORE = 8
78 };
79 virtual ~KuduWriteOperation();
80
84 const KuduPartialRow& row() const { return row_; }
85
89 KuduPartialRow* mutable_row() { return &row_; }
90
96 virtual std::string ToString() const = 0;
97
100 const KuduTable* table() const { return table_.get(); }
101
102 protected:
104
109 explicit KuduWriteOperation(const sp::shared_ptr<KuduTable>& table);
110
112 virtual Type type() const = 0;
113
117 sp::shared_ptr<KuduTable> const table_;
118
120 KuduPartialRow row_;
121
123
124 private:
125 friend class internal::Batcher;
126 friend class internal::WriteRpc;
127 friend class internal::ErrorCollector;
128 friend class KuduSession;
129
130 // Return the number of bytes required to buffer this operation,
131 // including direct and indirect data. Once called, the result is cached
132 // so subsequent calls will return the size previously computed.
133 int64_t SizeInBuffer() const;
134
135 mutable int64_t size_in_buffer_;
136
137 DISALLOW_COPY_AND_ASSIGN(KuduWriteOperation);
138};
139
140
145class KUDU_EXPORT KuduInsert : public KuduWriteOperation {
146 public:
147 virtual ~KuduInsert();
148
150 virtual std::string ToString() const OVERRIDE { return "INSERT " + row_.ToString(); }
151
152 protected:
154
156 virtual Type type() const OVERRIDE {
157 return INSERT;
158 }
159
161
162 private:
163 friend class KuduTable;
164 explicit KuduInsert(const sp::shared_ptr<KuduTable>& table);
165};
166
167
172class KUDU_EXPORT KuduInsertIgnore : public KuduWriteOperation {
173 public:
174 virtual ~KuduInsertIgnore();
175
177 virtual std::string ToString() const OVERRIDE { return "INSERT IGNORE " + row_.ToString(); }
178
179 protected:
181
183 virtual Type type() const OVERRIDE {
184 return INSERT_IGNORE;
185 }
186
188
189 private:
190 friend class KuduTable;
191 explicit KuduInsertIgnore(const sp::shared_ptr<KuduTable>& table);
192};
193
194
198class KUDU_EXPORT KuduUpsert : public KuduWriteOperation {
199 public:
200 virtual ~KuduUpsert();
201
203 virtual std::string ToString() const OVERRIDE { return "UPSERT " + row_.ToString(); }
204
205 protected:
207
209 virtual Type type() const OVERRIDE {
210 return UPSERT;
211 }
212
214
215 private:
216 friend class KuduTable;
217 explicit KuduUpsert(const sp::shared_ptr<KuduTable>& table);
218};
219
220
225class KUDU_EXPORT KuduUpsertIgnore : public KuduWriteOperation {
226 public:
227 ~KuduUpsertIgnore() OVERRIDE;
228
230 std::string ToString() const OVERRIDE { return "UPSERT IGNORE " + row_.ToString(); }
231
232 protected:
234
236 Type type() const OVERRIDE {
237 return UPSERT_IGNORE;
238 }
239
241
242 private:
243 friend class KuduTable;
244 explicit KuduUpsertIgnore(const sp::shared_ptr<KuduTable>& table);
245};
246
247
252class KUDU_EXPORT KuduUpdate : public KuduWriteOperation {
253 public:
254 virtual ~KuduUpdate();
255
257 virtual std::string ToString() const OVERRIDE { return "UPDATE " + row_.ToString(); }
258
259 protected:
261
263 virtual Type type() const OVERRIDE {
264 return UPDATE;
265 }
266
268
269 private:
270 friend class KuduTable;
271 explicit KuduUpdate(const sp::shared_ptr<KuduTable>& table);
272};
273
279class KUDU_EXPORT KuduUpdateIgnore : public KuduWriteOperation {
280public:
281 virtual ~KuduUpdateIgnore();
282
284 virtual std::string ToString() const OVERRIDE { return "UPDATE IGNORE " + row_.ToString(); }
285
286protected:
288
290 virtual Type type() const OVERRIDE {
291 return UPDATE_IGNORE;
292 }
293
295
296private:
297 friend class KuduTable;
298 explicit KuduUpdateIgnore(const sp::shared_ptr<KuduTable>& table);
299};
300
305class KUDU_EXPORT KuduDelete : public KuduWriteOperation {
306 public:
307 virtual ~KuduDelete();
308
310 virtual std::string ToString() const OVERRIDE { return "DELETE " + row_.ToString(); }
311
312 protected:
314
316 virtual Type type() const OVERRIDE {
317 return DELETE;
318 }
319
321
322 private:
323 friend class KuduTable;
324 explicit KuduDelete(const sp::shared_ptr<KuduTable>& table);
325};
326
331class KUDU_EXPORT KuduDeleteIgnore : public KuduWriteOperation {
332public:
333 virtual ~KuduDeleteIgnore();
334
336 virtual std::string ToString() const OVERRIDE { return "DELETE IGNORE " + row_.ToString(); }
337
338protected:
340
342 virtual Type type() const OVERRIDE {
343 return DELETE_IGNORE;
344 }
345
347
348private:
349 friend class KuduTable;
350 explicit KuduDeleteIgnore(const sp::shared_ptr<KuduTable>& table);
351};
352
353} // namespace client
354} // namespace kudu
355
356#endif
A row which may only contain values for a subset of the columns.
Definition partial_row.h:72
A single row delete ignore to be sent to the cluster.
Definition write_op.h:331
virtual std::string ToString() const OVERRIDE
Definition write_op.h:336
A single row delete to be sent to the cluster.
Definition write_op.h:305
virtual std::string ToString() const OVERRIDE
Definition write_op.h:310
A single row insert ignore to be sent to the cluster, duplicate row errors are ignored.
Definition write_op.h:172
virtual std::string ToString() const OVERRIDE
Definition write_op.h:177
A single row insert to be sent to the cluster.
Definition write_op.h:145
virtual std::string ToString() const OVERRIDE
Definition write_op.h:150
Representation of a Kudu client session.
Definition client.h:2292
A representation of a table on a particular cluster.
Definition client.h:1613
A single row update ignore to be sent to the cluster, missing row errors and errors on updating immut...
Definition write_op.h:279
virtual std::string ToString() const OVERRIDE
Definition write_op.h:284
A single row update to be sent to the cluster.
Definition write_op.h:252
virtual std::string ToString() const OVERRIDE
Definition write_op.h:257
A single row upsert ignore to be sent to the cluster, errors on updating immutable cells are ignored.
Definition write_op.h:225
std::string ToString() const OVERRIDE
Definition write_op.h:230
A single row upsert to be sent to the cluster.
Definition write_op.h:198
virtual std::string ToString() const OVERRIDE
Definition write_op.h:203
A single-row write operation to be sent to a Kudu table.
Definition write_op.h:66
virtual std::string ToString() const =0
Type
Write operation types.
Definition write_op.h:69
const KuduPartialRow & row() const
Definition write_op.h:84
const KuduTable * table() const
Definition write_op.h:100
KuduPartialRow * mutable_row()
Definition write_op.h:89
Smart pointer typedefs for externally-faced code.