Kudu C++ client API
 All Classes Namespaces 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 <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 WriteRpc;
35 } // namespace internal
36 
37 class KuduTable;
38 
55 class KUDU_EXPORT KuduWriteOperation {
56  public:
58  enum Type {
59  INSERT = 1,
60  UPDATE = 2,
61  DELETE = 3,
62  UPSERT = 4
63  };
64  virtual ~KuduWriteOperation();
65 
69  const KuduPartialRow& row() const { return row_; }
70 
74  KuduPartialRow* mutable_row() { return &row_; }
75 
77  virtual std::string ToString() const = 0;
78  protected:
80 
85  explicit KuduWriteOperation(const sp::shared_ptr<KuduTable>& table);
86 
88  virtual Type type() const = 0;
89 
93  sp::shared_ptr<KuduTable> const table_;
94 
96  KuduPartialRow row_;
97 
99 
100  private:
101  friend class internal::Batcher;
102  friend class internal::WriteRpc;
103 
104  // Create and encode the key for this write (key must be set)
105  //
106  // Caller takes ownership of the allocated memory.
107  EncodedKey* CreateKey() const;
108 
109  const KuduTable* table() const { return table_.get(); }
110 
111  // Return the number of bytes required to buffer this operation,
112  // including direct and indirect data.
113  int64_t SizeInBuffer() const;
114 
115  DISALLOW_COPY_AND_ASSIGN(KuduWriteOperation);
116 };
117 
118 
123 class KUDU_EXPORT KuduInsert : public KuduWriteOperation {
124  public:
125  virtual ~KuduInsert();
126 
128  virtual std::string ToString() const OVERRIDE { return "INSERT " + row_.ToString(); }
129 
130  protected:
132 
134  virtual Type type() const OVERRIDE {
135  return INSERT;
136  }
137 
139 
140  private:
141  friend class KuduTable;
142  explicit KuduInsert(const sp::shared_ptr<KuduTable>& table);
143 };
144 
148 class KUDU_EXPORT KuduUpsert : public KuduWriteOperation {
149  public:
150  virtual ~KuduUpsert();
151 
153  virtual std::string ToString() const OVERRIDE { return "UPSERT " + row_.ToString(); }
154 
155  protected:
157 
159  virtual Type type() const OVERRIDE {
160  return UPSERT;
161  }
162 
164 
165  private:
166  friend class KuduTable;
167  explicit KuduUpsert(const sp::shared_ptr<KuduTable>& table);
168 };
169 
170 
175 class KUDU_EXPORT KuduUpdate : public KuduWriteOperation {
176  public:
177  virtual ~KuduUpdate();
178 
180  virtual std::string ToString() const OVERRIDE { return "UPDATE " + row_.ToString(); }
181 
182  protected:
184 
186  virtual Type type() const OVERRIDE {
187  return UPDATE;
188  }
189 
191 
192  private:
193  friend class KuduTable;
194  explicit KuduUpdate(const sp::shared_ptr<KuduTable>& table);
195 };
196 
197 
202 class KUDU_EXPORT KuduDelete : public KuduWriteOperation {
203  public:
204  virtual ~KuduDelete();
205 
207  virtual std::string ToString() const OVERRIDE { return "DELETE " + row_.ToString(); }
208 
209  protected:
211 
213  virtual Type type() const OVERRIDE {
214  return DELETE;
215  }
216 
218 
219  private:
220  friend class KuduTable;
221  explicit KuduDelete(const sp::shared_ptr<KuduTable>& table);
222 };
223 
224 } // namespace client
225 } // namespace kudu
226 
227 #endif
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:180
A single row update to be sent to the cluster.
Definition: write_op.h:175
A single row insert to be sent to the cluster.
Definition: write_op.h:123
A single row upsert to be sent to the cluster.
Definition: write_op.h:148
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:128
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:153
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:207
const KuduPartialRow & row() const
Definition: write_op.h:69
A representation of a table on a particular cluster.
Definition: client.h:648
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:55
KuduPartialRow * mutable_row()
Definition: write_op.h:74
Type
Write operation types.
Definition: write_op.h:58
A single row delete to be sent to the cluster.
Definition: write_op.h:202
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:53