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 <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. Once called, the result is cached
113  // so subsequent calls will return the size previously computed.
114  int64_t SizeInBuffer() const;
115 
116  mutable int64_t size_in_buffer_;
117 
118  DISALLOW_COPY_AND_ASSIGN(KuduWriteOperation);
119 };
120 
121 
126 class KUDU_EXPORT KuduInsert : public KuduWriteOperation {
127  public:
128  virtual ~KuduInsert();
129 
131  virtual std::string ToString() const OVERRIDE { return "INSERT " + row_.ToString(); }
132 
133  protected:
135 
137  virtual Type type() const OVERRIDE {
138  return INSERT;
139  }
140 
142 
143  private:
144  friend class KuduTable;
145  explicit KuduInsert(const sp::shared_ptr<KuduTable>& table);
146 };
147 
151 class KUDU_EXPORT KuduUpsert : public KuduWriteOperation {
152  public:
153  virtual ~KuduUpsert();
154 
156  virtual std::string ToString() const OVERRIDE { return "UPSERT " + row_.ToString(); }
157 
158  protected:
160 
162  virtual Type type() const OVERRIDE {
163  return UPSERT;
164  }
165 
167 
168  private:
169  friend class KuduTable;
170  explicit KuduUpsert(const sp::shared_ptr<KuduTable>& table);
171 };
172 
173 
178 class KUDU_EXPORT KuduUpdate : public KuduWriteOperation {
179  public:
180  virtual ~KuduUpdate();
181 
183  virtual std::string ToString() const OVERRIDE { return "UPDATE " + row_.ToString(); }
184 
185  protected:
187 
189  virtual Type type() const OVERRIDE {
190  return UPDATE;
191  }
192 
194 
195  private:
196  friend class KuduTable;
197  explicit KuduUpdate(const sp::shared_ptr<KuduTable>& table);
198 };
199 
200 
205 class KUDU_EXPORT KuduDelete : public KuduWriteOperation {
206  public:
207  virtual ~KuduDelete();
208 
210  virtual std::string ToString() const OVERRIDE { return "DELETE " + row_.ToString(); }
211 
212  protected:
214 
216  virtual Type type() const OVERRIDE {
217  return DELETE;
218  }
219 
221 
222  private:
223  friend class KuduTable;
224  explicit KuduDelete(const sp::shared_ptr<KuduTable>& table);
225 };
226 
227 } // namespace client
228 } // namespace kudu
229 
230 #endif
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:183
A single row update to be sent to the cluster.
Definition: write_op.h:178
A single row insert to be sent to the cluster.
Definition: write_op.h:126
A single row upsert to be sent to the cluster.
Definition: write_op.h:151
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:131
Smart pointer typedefs for externally-faced code.
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:156
virtual std::string ToString() const OVERRIDE
Definition: write_op.h:210
const KuduPartialRow & row() const
Definition: write_op.h:69
A representation of a table on a particular cluster.
Definition: client.h:787
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:205
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:53