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 class EncodedKey;
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  };
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  // Create and encode the key for this write (key must be set)
123  //
124  // Caller takes ownership of the allocated memory.
125  EncodedKey* CreateKey() const;
126 
127  const KuduTable* table() const { return table_.get(); }
128 
129  // Return the number of bytes required to buffer this operation,
130  // including direct and indirect data. Once called, the result is cached
131  // so subsequent calls will return the size previously computed.
132  int64_t SizeInBuffer() const;
133 
134  mutable int64_t size_in_buffer_;
135 
136  DISALLOW_COPY_AND_ASSIGN(KuduWriteOperation);
137 };
138 
139 
144 class KUDU_EXPORT KuduInsert : public KuduWriteOperation {
145  public:
146  virtual ~KuduInsert();
147 
149  virtual std::string ToString() const OVERRIDE { return "INSERT " + row_.ToString(); }
150 
151  protected:
153 
155  virtual Type type() const OVERRIDE {
156  return INSERT;
157  }
158 
160 
161  private:
162  friend class KuduTable;
163  explicit KuduInsert(const sp::shared_ptr<KuduTable>& table);
164 };
165 
166 
171 class KUDU_EXPORT KuduInsertIgnore : public KuduWriteOperation {
172  public:
173  virtual ~KuduInsertIgnore();
174 
176  virtual std::string ToString() const OVERRIDE { return "INSERT IGNORE " + row_.ToString(); }
177 
178  protected:
180 
182  virtual Type type() const OVERRIDE {
183  return INSERT_IGNORE;
184  }
185 
187 
188  private:
189  friend class KuduTable;
190  explicit KuduInsertIgnore(const sp::shared_ptr<KuduTable>& table);
191 };
192 
193 
197 class KUDU_EXPORT KuduUpsert : public KuduWriteOperation {
198  public:
199  virtual ~KuduUpsert();
200 
202  virtual std::string ToString() const OVERRIDE { return "UPSERT " + row_.ToString(); }
203 
204  protected:
206 
208  virtual Type type() const OVERRIDE {
209  return UPSERT;
210  }
211 
213 
214  private:
215  friend class KuduTable;
216  explicit KuduUpsert(const sp::shared_ptr<KuduTable>& table);
217 };
218 
219 
224 class KUDU_EXPORT KuduUpdate : public KuduWriteOperation {
225  public:
226  virtual ~KuduUpdate();
227 
229  virtual std::string ToString() const OVERRIDE { return "UPDATE " + row_.ToString(); }
230 
231  protected:
233 
235  virtual Type type() const OVERRIDE {
236  return UPDATE;
237  }
238 
240 
241  private:
242  friend class KuduTable;
243  explicit KuduUpdate(const sp::shared_ptr<KuduTable>& table);
244 };
245 
246 
251 class KUDU_EXPORT KuduDelete : public KuduWriteOperation {
252  public:
253  virtual ~KuduDelete();
254 
256  virtual std::string ToString() const OVERRIDE { return "DELETE " + row_.ToString(); }
257 
258  protected:
260 
262  virtual Type type() const OVERRIDE {
263  return DELETE;
264  }
265 
267 
268  private:
269  friend class KuduTable;
270  explicit KuduDelete(const sp::shared_ptr<KuduTable>& table);
271 };
272 
273 } // namespace client
274 } // namespace kudu
275 
276 #endif
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:229
A single row update to be sent to the cluster.
Definition: write_op.h:224
A single row insert ignore to be sent to the cluster, duplicate row errors are ignored.
Definition: write_op.h:171
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:176
Definition: callbacks.h:28
A single row insert to be sent to the cluster.
Definition: write_op.h:144
A single row upsert to be sent to the cluster.
Definition: write_op.h:197
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:149
Smart pointer typedefs for externally-faced code.
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:202
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:256
const KuduPartialRow & row() const
Definition: write_op.h:81
A representation of a table on a particular cluster.
Definition: client.h:1020
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:66
KuduPartialRow * mutable_row()
Definition: write_op.h:86
Type
Write operation types.
Definition: write_op.h:69
A single row delete to be sent to the cluster.
Definition: write_op.h:251
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:72
Representation of a Kudu client session.
Definition: client.h:1599