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  };
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  friend class KuduSession;
119 
120  const KuduTable* table() const { return table_.get(); }
121 
122  // Return the number of bytes required to buffer this operation,
123  // including direct and indirect data. Once called, the result is cached
124  // so subsequent calls will return the size previously computed.
125  int64_t SizeInBuffer() const;
126 
127  mutable int64_t size_in_buffer_;
128 
129  DISALLOW_COPY_AND_ASSIGN(KuduWriteOperation);
130 };
131 
132 
137 class KUDU_EXPORT KuduInsert : public KuduWriteOperation {
138  public:
139  virtual ~KuduInsert();
140 
142  virtual std::string ToString() const OVERRIDE { return "INSERT " + row_.ToString(); }
143 
144  protected:
146 
148  virtual Type type() const OVERRIDE {
149  return INSERT;
150  }
151 
153 
154  private:
155  friend class KuduTable;
156  explicit KuduInsert(const sp::shared_ptr<KuduTable>& table);
157 };
158 
159 
164 class KUDU_EXPORT KuduInsertIgnore : public KuduWriteOperation {
165  public:
166  virtual ~KuduInsertIgnore();
167 
169  virtual std::string ToString() const OVERRIDE { return "INSERT IGNORE " + row_.ToString(); }
170 
171  protected:
173 
175  virtual Type type() const OVERRIDE {
176  return INSERT_IGNORE;
177  }
178 
180 
181  private:
182  friend class KuduTable;
183  explicit KuduInsertIgnore(const sp::shared_ptr<KuduTable>& table);
184 };
185 
186 
190 class KUDU_EXPORT KuduUpsert : public KuduWriteOperation {
191  public:
192  virtual ~KuduUpsert();
193 
195  virtual std::string ToString() const OVERRIDE { return "UPSERT " + row_.ToString(); }
196 
197  protected:
199 
201  virtual Type type() const OVERRIDE {
202  return UPSERT;
203  }
204 
206 
207  private:
208  friend class KuduTable;
209  explicit KuduUpsert(const sp::shared_ptr<KuduTable>& table);
210 };
211 
212 
217 class KUDU_EXPORT KuduUpdate : public KuduWriteOperation {
218  public:
219  virtual ~KuduUpdate();
220 
222  virtual std::string ToString() const OVERRIDE { return "UPDATE " + row_.ToString(); }
223 
224  protected:
226 
228  virtual Type type() const OVERRIDE {
229  return UPDATE;
230  }
231 
233 
234  private:
235  friend class KuduTable;
236  explicit KuduUpdate(const sp::shared_ptr<KuduTable>& table);
237 };
238 
239 
244 class KUDU_EXPORT KuduDelete : public KuduWriteOperation {
245  public:
246  virtual ~KuduDelete();
247 
249  virtual std::string ToString() const OVERRIDE { return "DELETE " + row_.ToString(); }
250 
251  protected:
253 
255  virtual Type type() const OVERRIDE {
256  return DELETE;
257  }
258 
260 
261  private:
262  friend class KuduTable;
263  explicit KuduDelete(const sp::shared_ptr<KuduTable>& table);
264 };
265 
266 } // namespace client
267 } // namespace kudu
268 
269 #endif
kudu::client::KuduSession
Representation of a Kudu client session.
Definition: client.h:1638
kudu::client::KuduWriteOperation::mutable_row
KuduPartialRow * mutable_row()
Definition: write_op.h:84
kudu::client::KuduUpsert::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:195
KuduPartialRow::ToString
std::string ToString() const
shared_ptr.h
Smart pointer typedefs for externally-faced code.
kudu::client::KuduUpdate::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:222
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:217
kudu::client::KuduWriteOperation::row
const KuduPartialRow & row() const
Definition: write_op.h:79
kudu::client::KuduWriteOperation::ToString
virtual std::string ToString() const =0
kudu::client::KuduInsertIgnore::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:169
kudu::client::KuduUpsert
A single row upsert to be sent to the cluster.
Definition: write_op.h:190
kudu::client::KuduWriteOperation
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:64
kudu::client::KuduInsert::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:142
kudu::client::KuduWriteOperation::Type
Type
Write operation types.
Definition: write_op.h:67
kudu::client::KuduTable
A representation of a table on a particular cluster.
Definition: client.h:1037
kudu::client::KuduDelete::ToString
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:249
kudu::client::KuduDelete
A single row delete to be sent to the cluster.
Definition: write_op.h:244
kudu::client::KuduInsert
A single row insert to be sent to the cluster.
Definition: write_op.h:137
kudu::client::KuduInsertIgnore
A single row insert ignore to be sent to the cluster, duplicate row errors are ignored.
Definition: write_op.h:164