Kudu C++ client API
 All Classes 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 SetUnixTimeMicros(const Slice& col_name,
93  int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
94 
95  Status SetFloat(const Slice& col_name, float val) WARN_UNUSED_RESULT;
96  Status SetDouble(const Slice& col_name, double val) WARN_UNUSED_RESULT;
98 
115  Status SetBool(int col_idx, bool val) WARN_UNUSED_RESULT;
116 
117  Status SetInt8(int col_idx, int8_t val) WARN_UNUSED_RESULT;
118  Status SetInt16(int col_idx, int16_t val) WARN_UNUSED_RESULT;
119  Status SetInt32(int col_idx, int32_t val) WARN_UNUSED_RESULT;
120  Status SetInt64(int col_idx, int64_t val) WARN_UNUSED_RESULT;
121  Status SetUnixTimeMicros(int col_idx, int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
122 
123  Status SetFloat(int col_idx, float val) WARN_UNUSED_RESULT;
124  Status SetDouble(int col_idx, double val) WARN_UNUSED_RESULT;
126 
144  Status SetBinary(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
145  Status SetString(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
147 
170  Status SetBinary(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
171  Status SetString(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
173 
186  Status SetBinaryCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
187  Status SetStringCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
189 
207  Status SetStringCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
208  Status SetBinaryCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
210 
228  Status SetBinaryNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
229  Status SetStringNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
231 
254  Status SetBinaryNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
255  Status SetStringNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
257 
266  Status SetNull(const Slice& col_name) WARN_UNUSED_RESULT;
267 
276  Status SetNull(int col_idx) WARN_UNUSED_RESULT;
277 
285  Status Unset(const Slice& col_name) WARN_UNUSED_RESULT;
286 
294  Status Unset(int col_idx) WARN_UNUSED_RESULT;
295 
301  bool IsColumnSet(const Slice& col_name) const;
302 
308  bool IsColumnSet(int col_idx) const;
309 
315  bool IsNull(const Slice& col_name) const;
316 
322  bool IsNull(int col_idx) const;
323 
335  Status GetBool(const Slice& col_name, bool* val) const WARN_UNUSED_RESULT;
336 
337  Status GetInt8(const Slice& col_name, int8_t* val) const WARN_UNUSED_RESULT;
338  Status GetInt16(const Slice& col_name, int16_t* val) const WARN_UNUSED_RESULT;
339  Status GetInt32(const Slice& col_name, int32_t* val) const WARN_UNUSED_RESULT;
340  Status GetInt64(const Slice& col_name, int64_t* val) const WARN_UNUSED_RESULT;
341  Status GetUnixTimeMicros(const Slice& col_name,
342  int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
343 
344  Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
345  Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
347 
366  Status GetBool(int col_idx, bool* val) const WARN_UNUSED_RESULT;
367 
368  Status GetInt8(int col_idx, int8_t* val) const WARN_UNUSED_RESULT;
369  Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
370  Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
371  Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
372  Status GetUnixTimeMicros(int col_idx, int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
373 
374  Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
375  Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
377 
395  Status GetString(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
396  Status GetBinary(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
398 
420  Status GetString(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
421  Status GetBinary(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
423 
424  //------------------------------------------------------------
425  // Key-encoding related functions
426  //------------------------------------------------------------
427 
439  Status EncodeRowKey(std::string* encoded_key) const;
440 
447  std::string ToEncodedRowKeyOrDie() const;
448 
449  //------------------------------------------------------------
450  // Utility code
451  //------------------------------------------------------------
452 
455  bool IsKeySet() const;
456 
458  bool AllColumnsSet() const;
459 
461  std::string ToString() const;
462 
464  const Schema* schema() const { return schema_; }
465 
466  private:
467  friend class client::KuduWriteOperation; // for row_data_.
468  friend class KeyUtilTest;
469  friend class PartitionSchema;
470  friend class RowOperationsPBDecoder;
471  friend class RowOperationsPBEncoder;
472  friend class TestScanSpec;
473  template<typename KeyTypeWrapper> friend struct client::SliceKeysTestSetup;
474  template<typename KeyTypeWrapper> friend struct client::IntKeysTestSetup;
475  FRIEND_TEST(TestPartitionPruner, TestPrimaryKeyRangePruning);
476  FRIEND_TEST(TestPartitionPruner, TestPartialPrimaryKeyRangePruning);
477 
478  template<typename T>
479  Status Set(const Slice& col_name, const typename T::cpp_type& val,
480  bool owned = false);
481 
482  template<typename T>
483  Status Set(int col_idx, const typename T::cpp_type& val,
484  bool owned = false);
485 
486  // Runtime version of the generic setter.
487  Status Set(int32_t column_idx, const uint8_t* val);
488 
489  template<typename T>
490  Status Get(const Slice& col_name, typename T::cpp_type* val) const;
491 
492  template<typename T>
493  Status Get(int col_idx, typename T::cpp_type* val) const;
494 
495  template<typename T>
496  Status SetSliceCopy(const Slice& col_name, const Slice& val);
497 
498  template<typename T>
499  Status SetSliceCopy(int col_idx, const Slice& val);
500 
501  // If the given column is a variable length column whose memory is owned by this instance,
502  // deallocates the value.
503  // NOTE: Does not mutate the isset bitmap.
504  // REQUIRES: col_idx must be a variable length column.
505  void DeallocateStringIfSet(int col_idx, const ColumnSchema& col);
506 
507  // Deallocate any string/binary values whose memory is managed by this object.
508  void DeallocateOwnedStrings();
509 
510  const Schema* schema_;
511 
512  // 1-bit set for any field which has been explicitly set. This is distinct
513  // from NULL -- an "unset" field will take the server-side default on insert,
514  // whereas a field explicitly set to NULL will override the default.
515  uint8_t* isset_bitmap_;
516 
517  // 1-bit set for any variable length columns whose memory is managed by this instance.
518  // These strings need to be deallocated whenever the value is reset,
519  // or when the instance is destructed.
520  uint8_t* owned_strings_bitmap_;
521 
522  // The normal "contiguous row" format row data. Any column whose data is unset
523  // or NULL can have undefined bytes.
524  uint8_t* row_data_;
525 };
526 
527 } // namespace kudu
528 #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:464
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