Kudu C++ client API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  friend class KuduSession;
119 
120  // Create and encode the key for this write (key must be set)
121  //
122  // Caller takes ownership of the allocated memory.
123  EncodedKey* CreateKey() const;
124 
125  const KuduTable* table() const { return table_.get(); }
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 
167 class KUDU_EXPORT KuduUpsert : public KuduWriteOperation {
168  public:
169  virtual ~KuduUpsert();
170 
172  virtual std::string ToString() const OVERRIDE { return "UPSERT " + row_.ToString(); }
173 
174  protected:
176 
178  virtual Type type() const OVERRIDE {
179  return UPSERT;
180  }
181 
183 
184  private:
185  friend class KuduTable;
186  explicit KuduUpsert(const sp::shared_ptr<KuduTable>& table);
187 };
188 
189 
194 class KUDU_EXPORT KuduUpdate : public KuduWriteOperation {
195  public:
196  virtual ~KuduUpdate();
197 
199  virtual std::string ToString() const OVERRIDE { return "UPDATE " + row_.ToString(); }
200 
201  protected:
203 
205  virtual Type type() const OVERRIDE {
206  return UPDATE;
207  }
208 
210 
211  private:
212  friend class KuduTable;
213  explicit KuduUpdate(const sp::shared_ptr<KuduTable>& table);
214 };
215 
216 
221 class KUDU_EXPORT KuduDelete : public KuduWriteOperation {
222  public:
223  virtual ~KuduDelete();
224 
226  virtual std::string ToString() const OVERRIDE { return "DELETE " + row_.ToString(); }
227 
228  protected:
230 
232  virtual Type type() const OVERRIDE {
233  return DELETE;
234  }
235 
237 
238  private:
239  friend class KuduTable;
240  explicit KuduDelete(const sp::shared_ptr<KuduTable>& table);
241 };
242 
243 } // namespace client
244 } // namespace kudu
245 
246 #endif
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:199
A single row update to be sent to the cluster.
Definition: write_op.h:194
A single row insert to be sent to the cluster.
Definition: write_op.h:142
A single row upsert to be sent to the cluster.
Definition: write_op.h:167
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:147
Smart pointer typedefs for externally-faced code.
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:172
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:226
const KuduPartialRow & row() const
Definition: write_op.h:79
A representation of a table on a particular cluster.
Definition: client.h:954
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:65
KuduPartialRow * mutable_row()
Definition: write_op.h:84
Type
Write operation types.
Definition: write_op.h:68
A single row delete to be sent to the cluster.
Definition: write_op.h:221
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:68
Representation of a Kudu client session.
Definition: client.h:1419