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 #include <string>
23 
24 #include "kudu/client/shared_ptr.h" // IWYU pragma: keep
25 #include "kudu/common/partial_row.h"
26 #include "kudu/util/kudu_export.h"
27 
28 #ifdef KUDU_HEADERS_NO_STUBS
29 #include "kudu/gutil/macros.h"
30 #include "kudu/gutil/port.h"
31 #else
32 #include "kudu/client/stubs.h"
33 #endif
34 
35 namespace kudu {
36 
37 class EncodedKey;
38 
39 namespace client {
40 
41 namespace internal {
42 class Batcher;
43 class ErrorCollector;
44 class WriteRpc;
45 } // namespace internal
46 
47 class KuduTable;
48 
65 class KUDU_EXPORT KuduWriteOperation {
66  public:
68  enum Type {
69  INSERT = 1,
70  UPDATE = 2,
71  DELETE = 3,
72  UPSERT = 4
73  };
74  virtual ~KuduWriteOperation();
75 
79  const KuduPartialRow& row() const { return row_; }
80 
84  KuduPartialRow* mutable_row() { return &row_; }
85 
91  virtual std::string ToString() const = 0;
92  protected:
94 
99  explicit KuduWriteOperation(const sp::shared_ptr<KuduTable>& table);
100 
102  virtual Type type() const = 0;
103 
107  sp::shared_ptr<KuduTable> const table_;
108 
110  KuduPartialRow row_;
111 
113 
114  private:
115  friend class internal::Batcher;
116  friend class internal::WriteRpc;
117  friend class internal::ErrorCollector;
118 
119  // Create and encode the key for this write (key must be set)
120  //
121  // Caller takes ownership of the allocated memory.
122  EncodedKey* CreateKey() const;
123 
124  const KuduTable* table() const { return table_.get(); }
125 
126  // Return the number of bytes required to buffer this operation,
127  // including direct and indirect data. Once called, the result is cached
128  // so subsequent calls will return the size previously computed.
129  int64_t SizeInBuffer() const;
130 
131  mutable int64_t size_in_buffer_;
132 
133  DISALLOW_COPY_AND_ASSIGN(KuduWriteOperation);
134 };
135 
136 
141 class KUDU_EXPORT KuduInsert : public KuduWriteOperation {
142  public:
143  virtual ~KuduInsert();
144 
146  virtual std::string ToString() const OVERRIDE { return "INSERT " + row_.ToString(); }
147 
148  protected:
150 
152  virtual Type type() const OVERRIDE {
153  return INSERT;
154  }
155 
157 
158  private:
159  friend class KuduTable;
160  explicit KuduInsert(const sp::shared_ptr<KuduTable>& table);
161 };
162 
166 class KUDU_EXPORT KuduUpsert : public KuduWriteOperation {
167  public:
168  virtual ~KuduUpsert();
169 
171  virtual std::string ToString() const OVERRIDE { return "UPSERT " + row_.ToString(); }
172 
173  protected:
175 
177  virtual Type type() const OVERRIDE {
178  return UPSERT;
179  }
180 
182 
183  private:
184  friend class KuduTable;
185  explicit KuduUpsert(const sp::shared_ptr<KuduTable>& table);
186 };
187 
188 
193 class KUDU_EXPORT KuduUpdate : public KuduWriteOperation {
194  public:
195  virtual ~KuduUpdate();
196 
198  virtual std::string ToString() const OVERRIDE { return "UPDATE " + row_.ToString(); }
199 
200  protected:
202 
204  virtual Type type() const OVERRIDE {
205  return UPDATE;
206  }
207 
209 
210  private:
211  friend class KuduTable;
212  explicit KuduUpdate(const sp::shared_ptr<KuduTable>& table);
213 };
214 
215 
220 class KUDU_EXPORT KuduDelete : public KuduWriteOperation {
221  public:
222  virtual ~KuduDelete();
223 
225  virtual std::string ToString() const OVERRIDE { return "DELETE " + row_.ToString(); }
226 
227  protected:
229 
231  virtual Type type() const OVERRIDE {
232  return DELETE;
233  }
234 
236 
237  private:
238  friend class KuduTable;
239  explicit KuduDelete(const sp::shared_ptr<KuduTable>& table);
240 };
241 
242 } // namespace client
243 } // namespace kudu
244 
245 #endif
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:64
A single row update to be sent to the cluster.
Definition: write_op.h:193
Definition: callbacks.h:28
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:141
Smart pointer typedefs for externally-faced code.
A single row upsert to be sent to the cluster.
Definition: write_op.h:166
Type
Write operation types.
Definition: write_op.h:68
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:198
A single row delete to be sent to the cluster.
Definition: write_op.h:220
A representation of a table on a particular cluster.
Definition: client.h:920
KuduPartialRow * mutable_row()
Definition: write_op.h:84
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:65
const KuduPartialRow & row() const
Definition: write_op.h:79
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:146
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:225