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 #include <stdint.h>
21 
22 // IWYU pragma: no_include <memory>
23 #include <string>
24 
25 #include "kudu/client/shared_ptr.h" // IWYU pragma: keep
26 #include "kudu/common/partial_row.h"
27 #include "kudu/util/kudu_export.h"
28 
29 #ifdef KUDU_HEADERS_NO_STUBS
30 #include "kudu/gutil/macros.h"
31 #include "kudu/gutil/port.h"
32 #else
33 #include "kudu/client/stubs.h"
34 #endif
35 
36 namespace kudu {
37 
38 namespace client {
39 
40 namespace internal {
41 class Batcher;
42 class ErrorCollector;
43 class WriteRpc;
44 } // namespace internal
45 
46 class KuduTable;
47 
64 class KUDU_EXPORT KuduWriteOperation {
65  public:
67  enum Type {
68  INSERT = 1,
69  UPDATE = 2,
70  DELETE = 3,
71  UPSERT = 4,
72  INSERT_IGNORE = 5,
73  UPDATE_IGNORE = 6,
74  DELETE_IGNORE = 7
75  };
76  virtual ~KuduWriteOperation();
77 
81  const KuduPartialRow& row() const { return row_; }
82 
86  KuduPartialRow* mutable_row() { return &row_; }
87 
93  virtual std::string ToString() const = 0;
94  protected:
96 
101  explicit KuduWriteOperation(const sp::shared_ptr<KuduTable>& table);
102 
104  virtual Type type() const = 0;
105 
109  sp::shared_ptr<KuduTable> const table_;
110 
112  KuduPartialRow row_;
113 
115 
116  private:
117  friend class internal::Batcher;
118  friend class internal::WriteRpc;
119  friend class internal::ErrorCollector;
120  friend class KuduSession;
121 
122  const KuduTable* table() const { return table_.get(); }
123 
124  // Return the number of bytes required to buffer this operation,
125  // including direct and indirect data. Once called, the result is cached
126  // so subsequent calls will return the size previously computed.
127  int64_t SizeInBuffer() const;
128 
129  mutable int64_t size_in_buffer_;
130 
131  DISALLOW_COPY_AND_ASSIGN(KuduWriteOperation);
132 };
133 
134 
139 class KUDU_EXPORT KuduInsert : public KuduWriteOperation {
140  public:
141  virtual ~KuduInsert();
142 
144  virtual std::string ToString() const OVERRIDE { return "INSERT " + row_.ToString(); }
145 
146  protected:
148 
150  virtual Type type() const OVERRIDE {
151  return INSERT;
152  }
153 
155 
156  private:
157  friend class KuduTable;
158  explicit KuduInsert(const sp::shared_ptr<KuduTable>& table);
159 };
160 
161 
166 class KUDU_EXPORT KuduInsertIgnore : public KuduWriteOperation {
167  public:
168  virtual ~KuduInsertIgnore();
169 
171  virtual std::string ToString() const OVERRIDE { return "INSERT IGNORE " + row_.ToString(); }
172 
173  protected:
175 
177  virtual Type type() const OVERRIDE {
178  return INSERT_IGNORE;
179  }
180 
182 
183  private:
184  friend class KuduTable;
185  explicit KuduInsertIgnore(const sp::shared_ptr<KuduTable>& table);
186 };
187 
188 
192 class KUDU_EXPORT KuduUpsert : public KuduWriteOperation {
193  public:
194  virtual ~KuduUpsert();
195 
197  virtual std::string ToString() const OVERRIDE { return "UPSERT " + row_.ToString(); }
198 
199  protected:
201 
203  virtual Type type() const OVERRIDE {
204  return UPSERT;
205  }
206 
208 
209  private:
210  friend class KuduTable;
211  explicit KuduUpsert(const sp::shared_ptr<KuduTable>& table);
212 };
213 
214 
219 class KUDU_EXPORT KuduUpdate : public KuduWriteOperation {
220  public:
221  virtual ~KuduUpdate();
222 
224  virtual std::string ToString() const OVERRIDE { return "UPDATE " + row_.ToString(); }
225 
226  protected:
228 
230  virtual Type type() const OVERRIDE {
231  return UPDATE;
232  }
233 
235 
236  private:
237  friend class KuduTable;
238  explicit KuduUpdate(const sp::shared_ptr<KuduTable>& table);
239 };
240 
245 class KUDU_EXPORT KuduUpdateIgnore : public KuduWriteOperation {
246 public:
247  virtual ~KuduUpdateIgnore();
248 
250  virtual std::string ToString() const OVERRIDE { return "UPDATE IGNORE " + row_.ToString(); }
251 
252 protected:
254 
256  virtual Type type() const OVERRIDE {
257  return UPDATE_IGNORE;
258  }
259 
261 
262 private:
263  friend class KuduTable;
264  explicit KuduUpdateIgnore(const sp::shared_ptr<KuduTable>& table);
265 };
266 
271 class KUDU_EXPORT KuduDelete : public KuduWriteOperation {
272  public:
273  virtual ~KuduDelete();
274 
276  virtual std::string ToString() const OVERRIDE { return "DELETE " + row_.ToString(); }
277 
278  protected:
280 
282  virtual Type type() const OVERRIDE {
283  return DELETE;
284  }
285 
287 
288  private:
289  friend class KuduTable;
290  explicit KuduDelete(const sp::shared_ptr<KuduTable>& table);
291 };
292 
297 class KUDU_EXPORT KuduDeleteIgnore : public KuduWriteOperation {
298 public:
299  virtual ~KuduDeleteIgnore();
300 
302  virtual std::string ToString() const OVERRIDE { return "DELETE IGNORE " + row_.ToString(); }
303 
304 protected:
306 
308  virtual Type type() const OVERRIDE {
309  return DELETE_IGNORE;
310  }
311 
313 
314 private:
315  friend class KuduTable;
316  explicit KuduDeleteIgnore(const sp::shared_ptr<KuduTable>& table);
317 };
318 
319 } // namespace client
320 } // namespace kudu
321 
322 #endif
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:72
std::string ToString() const
A single row delete ignore to be sent to the cluster.
Definition: write_op.h:297
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:302
A single row delete to be sent to the cluster.
Definition: write_op.h:271
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:276
A single row insert ignore to be sent to the cluster, duplicate row errors are ignored.
Definition: write_op.h:166
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:171
A single row insert to be sent to the cluster.
Definition: write_op.h:139
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:144
Representation of a Kudu client session.
Definition: client.h:1943
A representation of a table on a particular cluster.
Definition: client.h:1332
A single row update ignore to be sent to the cluster, missing row errors are ignored.
Definition: write_op.h:245
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:250
A single row update to be sent to the cluster.
Definition: write_op.h:219
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:224
A single row upsert to be sent to the cluster.
Definition: write_op.h:192
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:197
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:64
virtual std::string ToString() const =0
Type
Write operation types.
Definition: write_op.h:67
KuduPartialRow * mutable_row()
Definition: write_op.h:86
const KuduPartialRow & row() const
Definition: write_op.h:81
Smart pointer typedefs for externally-faced code.