Kudu C++ client API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
partial_row.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_COMMON_PARTIAL_ROW_H
18 #define KUDU_COMMON_PARTIAL_ROW_H
19 
20 #include <stdint.h>
21 #include <string>
22 #include <vector>
23 
24 #ifdef KUDU_HEADERS_NO_STUBS
25 #include "kudu/gutil/macros.h"
26 #include "kudu/gutil/port.h"
27 #include <gtest/gtest_prod.h>
28 #else
29 // This is a poor module interdependency, but the stubs are header-only and
30 // it's only for exported header builds, so we'll make an exception.
31 #include "kudu/client/stubs.h"
32 #endif
33 
34 #include "kudu/util/kudu_export.h"
35 #include "kudu/util/slice.h"
36 
37 namespace kudu {
38 class ColumnSchema;
39 namespace client {
40 class KuduWriteOperation;
41 template<typename KeyTypeWrapper> struct SliceKeysTestSetup;
42 template<typename KeyTypeWrapper> struct IntKeysTestSetup;
43 } // namespace client
44 
45 class Schema;
46 class PartialRowPB;
47 
53 class KUDU_EXPORT KuduPartialRow {
54  public:
58  explicit KuduPartialRow(const Schema* schema);
59 
60  virtual ~KuduPartialRow();
61 
66  KuduPartialRow(const KuduPartialRow& other);
67 
73  KuduPartialRow& operator=(KuduPartialRow other);
74 
86  Status SetBool(const Slice& col_name, bool val) WARN_UNUSED_RESULT;
87 
88  Status SetInt8(const Slice& col_name, int8_t val) WARN_UNUSED_RESULT;
89  Status SetInt16(const Slice& col_name, int16_t val) WARN_UNUSED_RESULT;
90  Status SetInt32(const Slice& col_name, int32_t val) WARN_UNUSED_RESULT;
91  Status SetInt64(const Slice& col_name, int64_t val) WARN_UNUSED_RESULT;
92  Status SetTimestamp(const Slice& col_name, int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
93 
94  Status SetFloat(const Slice& col_name, float val) WARN_UNUSED_RESULT;
95  Status SetDouble(const Slice& col_name, double val) WARN_UNUSED_RESULT;
97 
114  Status SetBool(int col_idx, bool val) WARN_UNUSED_RESULT;
115 
116  Status SetInt8(int col_idx, int8_t val) WARN_UNUSED_RESULT;
117  Status SetInt16(int col_idx, int16_t val) WARN_UNUSED_RESULT;
118  Status SetInt32(int col_idx, int32_t val) WARN_UNUSED_RESULT;
119  Status SetInt64(int col_idx, int64_t val) WARN_UNUSED_RESULT;
120  Status SetTimestamp(int col_idx, int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
121 
122  Status SetFloat(int col_idx, float val) WARN_UNUSED_RESULT;
123  Status SetDouble(int col_idx, double val) WARN_UNUSED_RESULT;
125 
143  Status SetBinary(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
144  Status SetString(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
146 
169  Status SetBinary(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
170  Status SetString(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
172 
185  Status SetBinaryCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
186  Status SetStringCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
188 
206  Status SetStringCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
207  Status SetBinaryCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
209 
227  Status SetBinaryNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
228  Status SetStringNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
230 
253  Status SetBinaryNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
254  Status SetStringNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
256 
265  Status SetNull(const Slice& col_name) WARN_UNUSED_RESULT;
266 
275  Status SetNull(int col_idx) WARN_UNUSED_RESULT;
276 
284  Status Unset(const Slice& col_name) WARN_UNUSED_RESULT;
285 
293  Status Unset(int col_idx) WARN_UNUSED_RESULT;
294 
300  bool IsColumnSet(const Slice& col_name) const;
301 
307  bool IsColumnSet(int col_idx) const;
308 
314  bool IsNull(const Slice& col_name) const;
315 
321  bool IsNull(int col_idx) const;
322 
334  Status GetBool(const Slice& col_name, bool* val) const WARN_UNUSED_RESULT;
335 
336  Status GetInt8(const Slice& col_name, int8_t* val) const WARN_UNUSED_RESULT;
337  Status GetInt16(const Slice& col_name, int16_t* val) const WARN_UNUSED_RESULT;
338  Status GetInt32(const Slice& col_name, int32_t* val) const WARN_UNUSED_RESULT;
339  Status GetInt64(const Slice& col_name, int64_t* val) const WARN_UNUSED_RESULT;
340  Status GetTimestamp(const Slice& col_name,
341  int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
342 
343  Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
344  Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
346 
365  Status GetBool(int col_idx, bool* val) const WARN_UNUSED_RESULT;
366 
367  Status GetInt8(int col_idx, int8_t* val) const WARN_UNUSED_RESULT;
368  Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
369  Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
370  Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
371  Status GetTimestamp(int col_idx, int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
372 
373  Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
374  Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
376 
394  Status GetString(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
395  Status GetBinary(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
397 
419  Status GetString(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
420  Status GetBinary(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
422 
423  //------------------------------------------------------------
424  // Key-encoding related functions
425  //------------------------------------------------------------
426 
438  Status EncodeRowKey(std::string* encoded_key) const;
439 
446  std::string ToEncodedRowKeyOrDie() const;
447 
448  //------------------------------------------------------------
449  // Utility code
450  //------------------------------------------------------------
451 
454  bool IsKeySet() const;
455 
457  bool AllColumnsSet() const;
458 
460  std::string ToString() const;
461 
463  const Schema* schema() const { return schema_; }
464 
465  private:
466  friend class client::KuduWriteOperation; // for row_data_.
467  friend class KeyUtilTest;
468  friend class PartitionSchema;
469  friend class RowOperationsPBDecoder;
470  friend class RowOperationsPBEncoder;
471  friend class TestScanSpec;
472  template<typename KeyTypeWrapper> friend struct client::SliceKeysTestSetup;
473  template<typename KeyTypeWrapper> friend struct client::IntKeysTestSetup;
474  FRIEND_TEST(TestPartitionPruner, TestPrimaryKeyRangePruning);
475  FRIEND_TEST(TestPartitionPruner, TestPartialPrimaryKeyRangePruning);
476 
477  template<typename T>
478  Status Set(const Slice& col_name, const typename T::cpp_type& val,
479  bool owned = false);
480 
481  template<typename T>
482  Status Set(int col_idx, const typename T::cpp_type& val,
483  bool owned = false);
484 
485  // Runtime version of the generic setter.
486  Status Set(int32_t column_idx, const uint8_t* val);
487 
488  template<typename T>
489  Status Get(const Slice& col_name, typename T::cpp_type* val) const;
490 
491  template<typename T>
492  Status Get(int col_idx, typename T::cpp_type* val) const;
493 
494  template<typename T>
495  Status SetSliceCopy(const Slice& col_name, const Slice& val);
496 
497  template<typename T>
498  Status SetSliceCopy(int col_idx, const Slice& val);
499 
500  // If the given column is a variable length column whose memory is owned by this instance,
501  // deallocates the value.
502  // NOTE: Does not mutate the isset bitmap.
503  // REQUIRES: col_idx must be a variable length column.
504  void DeallocateStringIfSet(int col_idx, const ColumnSchema& col);
505 
506  // Deallocate any string/binary values whose memory is managed by this object.
507  void DeallocateOwnedStrings();
508 
509  const Schema* schema_;
510 
511  // 1-bit set for any field which has been explicitly set. This is distinct
512  // from NULL -- an "unset" field will take the server-side default on insert,
513  // whereas a field explicitly set to NULL will override the default.
514  uint8_t* isset_bitmap_;
515 
516  // 1-bit set for any variable length columns whose memory is managed by this instance.
517  // These strings need to be deallocated whenever the value is reset,
518  // or when the instance is destructed.
519  uint8_t* owned_strings_bitmap_;
520 
521  // The normal "contiguous row" format row data. Any column whose data is unset
522  // or NULL can have undefined bytes.
523  uint8_t* row_data_;
524 };
525 
526 } // namespace kudu
527 #endif /* KUDU_COMMON_PARTIAL_ROW_H */
A representation of an operation's outcome.
Definition: status.h:106
Definition: partial_row.h:42
Definition: partial_row.h:41
A wrapper around externally allocated data.
Definition: slice.h:43
const Schema * schema() const
Definition: partial_row.h:463
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:55
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:53