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 <string>
21 
22 #include "kudu/client/shared_ptr.h"
23 #include "kudu/common/partial_row.h"
24 #include "kudu/util/kudu_export.h"
25 
26 namespace kudu {
27 
28 class EncodedKey;
29 
30 namespace client {
31 
32 namespace internal {
33 class Batcher;
34 class ErrorCollector;
35 class WriteRpc;
36 } // namespace internal
37 
38 class KuduTable;
39 
56 class KUDU_EXPORT KuduWriteOperation {
57  public:
59  enum Type {
60  INSERT = 1,
61  UPDATE = 2,
62  DELETE = 3,
63  UPSERT = 4
64  };
65  virtual ~KuduWriteOperation();
66 
70  const KuduPartialRow& row() const { return row_; }
71 
75  KuduPartialRow* mutable_row() { return &row_; }
76 
82  virtual std::string ToString() const = 0;
83  protected:
85 
90  explicit KuduWriteOperation(const sp::shared_ptr<KuduTable>& table);
91 
93  virtual Type type() const = 0;
94 
98  sp::shared_ptr<KuduTable> const table_;
99 
101  KuduPartialRow row_;
102 
104 
105  private:
106  friend class internal::Batcher;
107  friend class internal::WriteRpc;
108  friend class internal::ErrorCollector;
109 
110  // Create and encode the key for this write (key must be set)
111  //
112  // Caller takes ownership of the allocated memory.
113  EncodedKey* CreateKey() const;
114 
115  const KuduTable* table() const { return table_.get(); }
116 
117  // Return the number of bytes required to buffer this operation,
118  // including direct and indirect data. Once called, the result is cached
119  // so subsequent calls will return the size previously computed.
120  int64_t SizeInBuffer() const;
121 
122  mutable int64_t size_in_buffer_;
123 
124  DISALLOW_COPY_AND_ASSIGN(KuduWriteOperation);
125 };
126 
127 
132 class KUDU_EXPORT KuduInsert : public KuduWriteOperation {
133  public:
134  virtual ~KuduInsert();
135 
137  virtual std::string ToString() const OVERRIDE { return "INSERT " + row_.ToString(); }
138 
139  protected:
141 
143  virtual Type type() const OVERRIDE {
144  return INSERT;
145  }
146 
148 
149  private:
150  friend class KuduTable;
151  explicit KuduInsert(const sp::shared_ptr<KuduTable>& table);
152 };
153 
157 class KUDU_EXPORT KuduUpsert : public KuduWriteOperation {
158  public:
159  virtual ~KuduUpsert();
160 
162  virtual std::string ToString() const OVERRIDE { return "UPSERT " + row_.ToString(); }
163 
164  protected:
166 
168  virtual Type type() const OVERRIDE {
169  return UPSERT;
170  }
171 
173 
174  private:
175  friend class KuduTable;
176  explicit KuduUpsert(const sp::shared_ptr<KuduTable>& table);
177 };
178 
179 
184 class KUDU_EXPORT KuduUpdate : public KuduWriteOperation {
185  public:
186  virtual ~KuduUpdate();
187 
189  virtual std::string ToString() const OVERRIDE { return "UPDATE " + row_.ToString(); }
190 
191  protected:
193 
195  virtual Type type() const OVERRIDE {
196  return UPDATE;
197  }
198 
200 
201  private:
202  friend class KuduTable;
203  explicit KuduUpdate(const sp::shared_ptr<KuduTable>& table);
204 };
205 
206 
211 class KUDU_EXPORT KuduDelete : public KuduWriteOperation {
212  public:
213  virtual ~KuduDelete();
214 
216  virtual std::string ToString() const OVERRIDE { return "DELETE " + row_.ToString(); }
217 
218  protected:
220 
222  virtual Type type() const OVERRIDE {
223  return DELETE;
224  }
225 
227 
228  private:
229  friend class KuduTable;
230  explicit KuduDelete(const sp::shared_ptr<KuduTable>& table);
231 };
232 
233 } // namespace client
234 } // namespace kudu
235 
236 #endif
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:189
A single row update to be sent to the cluster.
Definition: write_op.h:184
Definition: callbacks.h:28
A single row insert to be sent to the cluster.
Definition: write_op.h:132
A single row upsert to be sent to the cluster.
Definition: write_op.h:157
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:137
Smart pointer typedefs for externally-faced code.
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:162
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:216
const KuduPartialRow & row() const
Definition: write_op.h:70
A representation of a table on a particular cluster.
Definition: client.h:802
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:56
KuduPartialRow * mutable_row()
Definition: write_op.h:75
Type
Write operation types.
Definition: write_op.h:59
A single row delete to be sent to the cluster.
Definition: write_op.h:211
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:55