Kudu C++ client API
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 
38 namespace kudu {
39 
40 namespace client {
41 
42 namespace internal {
43 class Batcher;
44 class ErrorCollector;
45 class WriteRpc;
46 } // namespace internal
47 
48 class KuduTable;
49 
66 class 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  };
78  virtual ~KuduWriteOperation();
79 
83  const KuduPartialRow& row() const { return row_; }
84 
88  KuduPartialRow* mutable_row() { return &row_; }
89 
95  virtual std::string ToString() const = 0;
96 
97  const KuduTable* table() const { return table_.get(); }
98 
99  protected:
101 
106  explicit KuduWriteOperation(const sp::shared_ptr<KuduTable>& table);
107 
109  virtual Type type() const = 0;
110 
114  sp::shared_ptr<KuduTable> const table_;
115 
117  KuduPartialRow row_;
118 
120 
121  private:
122  friend class internal::Batcher;
123  friend class internal::WriteRpc;
124  friend class internal::ErrorCollector;
125  friend class KuduSession;
126 
127  // Return the number of bytes required to buffer this operation,
128  // including direct and indirect data. Once called, the result is cached
129  // so subsequent calls will return the size previously computed.
130  int64_t SizeInBuffer() const;
131 
132  mutable int64_t size_in_buffer_;
133 
134  DISALLOW_COPY_AND_ASSIGN(KuduWriteOperation);
135 };
136 
137 
142 class KUDU_EXPORT KuduInsert : public KuduWriteOperation {
143  public:
144  virtual ~KuduInsert();
145 
147  virtual std::string ToString() const OVERRIDE { return "INSERT " + row_.ToString(); }
148 
149  protected:
151 
153  virtual Type type() const OVERRIDE {
154  return INSERT;
155  }
156 
158 
159  private:
160  friend class KuduTable;
161  explicit KuduInsert(const sp::shared_ptr<KuduTable>& table);
162 };
163 
164 
169 class KUDU_EXPORT KuduInsertIgnore : public KuduWriteOperation {
170  public:
171  virtual ~KuduInsertIgnore();
172 
174  virtual std::string ToString() const OVERRIDE { return "INSERT IGNORE " + row_.ToString(); }
175 
176  protected:
178 
180  virtual Type type() const OVERRIDE {
181  return INSERT_IGNORE;
182  }
183 
185 
186  private:
187  friend class KuduTable;
188  explicit KuduInsertIgnore(const sp::shared_ptr<KuduTable>& table);
189 };
190 
191 
195 class KUDU_EXPORT KuduUpsert : public KuduWriteOperation {
196  public:
197  virtual ~KuduUpsert();
198 
200  virtual std::string ToString() const OVERRIDE { return "UPSERT " + row_.ToString(); }
201 
202  protected:
204 
206  virtual Type type() const OVERRIDE {
207  return UPSERT;
208  }
209 
211 
212  private:
213  friend class KuduTable;
214  explicit KuduUpsert(const sp::shared_ptr<KuduTable>& table);
215 };
216 
217 
222 class KUDU_EXPORT KuduUpdate : public KuduWriteOperation {
223  public:
224  virtual ~KuduUpdate();
225 
227  virtual std::string ToString() const OVERRIDE { return "UPDATE " + row_.ToString(); }
228 
229  protected:
231 
233  virtual Type type() const OVERRIDE {
234  return UPDATE;
235  }
236 
238 
239  private:
240  friend class KuduTable;
241  explicit KuduUpdate(const sp::shared_ptr<KuduTable>& table);
242 };
243 
248 class KUDU_EXPORT KuduUpdateIgnore : public KuduWriteOperation {
249 public:
250  virtual ~KuduUpdateIgnore();
251 
253  virtual std::string ToString() const OVERRIDE { return "UPDATE IGNORE " + row_.ToString(); }
254 
255 protected:
257 
259  virtual Type type() const OVERRIDE {
260  return UPDATE_IGNORE;
261  }
262 
264 
265 private:
266  friend class KuduTable;
267  explicit KuduUpdateIgnore(const sp::shared_ptr<KuduTable>& table);
268 };
269 
274 class KUDU_EXPORT KuduDelete : public KuduWriteOperation {
275  public:
276  virtual ~KuduDelete();
277 
279  virtual std::string ToString() const OVERRIDE { return "DELETE " + row_.ToString(); }
280 
281  protected:
283 
285  virtual Type type() const OVERRIDE {
286  return DELETE;
287  }
288 
290 
291  private:
292  friend class KuduTable;
293  explicit KuduDelete(const sp::shared_ptr<KuduTable>& table);
294 };
295 
300 class KUDU_EXPORT KuduDeleteIgnore : public KuduWriteOperation {
301 public:
302  virtual ~KuduDeleteIgnore();
303 
305  virtual std::string ToString() const OVERRIDE { return "DELETE IGNORE " + row_.ToString(); }
306 
307 protected:
309 
311  virtual Type type() const OVERRIDE {
312  return DELETE_IGNORE;
313  }
314 
316 
317 private:
318  friend class KuduTable;
319  explicit KuduDeleteIgnore(const sp::shared_ptr<KuduTable>& table);
320 };
321 
322 } // namespace client
323 } // namespace kudu
324 
325 #endif
kudu::client::KuduSession
Representation of a Kudu client session.
Definition: client.h:2176
kudu::client::KuduWriteOperation::mutable_row
KuduPartialRow * mutable_row()
Definition: write_op.h:88
kudu::client::KuduUpsert::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:200
kudu::client::KuduDeleteIgnore
A single row delete ignore to be sent to the cluster.
Definition: write_op.h:300
shared_ptr.h
Smart pointer typedefs for externally-faced code.
kudu::client::KuduUpdate::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:227
KuduPartialRow
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:72
kudu::client::KuduUpdate
A single row update to be sent to the cluster.
Definition: write_op.h:222
kudu::client::KuduWriteOperation::row
const KuduPartialRow & row() const
Definition: write_op.h:83
kudu::client::KuduWriteOperation::ToString
virtual std::string ToString() const =0
kudu::client::KuduInsertIgnore::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:174
kudu::client::KuduUpsert
A single row upsert to be sent to the cluster.
Definition: write_op.h:195
kudu::client::KuduWriteOperation
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:66
kudu::client::KuduInsert::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:147
kudu::client::KuduDeleteIgnore::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:305
kudu::client::KuduWriteOperation::Type
Type
Write operation types.
Definition: write_op.h:69
kudu::client::KuduTable
A representation of a table on a particular cluster.
Definition: client.h:1521
kudu::client::KuduUpdateIgnore::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:253
kudu::client::KuduDelete::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:279
kudu::client::KuduDelete
A single row delete to be sent to the cluster.
Definition: write_op.h:274
kudu::client::KuduInsert
A single row insert to be sent to the cluster.
Definition: write_op.h:142
kudu::client::KuduInsertIgnore
A single row insert ignore to be sent to the cluster, duplicate row errors are ignored.
Definition: write_op.h:169
kudu::client::KuduUpdateIgnore
A single row update ignore to be sent to the cluster, missing row errors are ignored.
Definition: write_op.h:248