Kudu C++ client API
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 
38 namespace kudu {
39 class ColumnSchema;
40 namespace client {
41 class KuduWriteOperation;
42 template<typename KeyTypeWrapper> struct SliceKeysTestSetup;
43 template<typename KeyTypeWrapper> struct IntKeysTestSetup;
44 } // namespace client
45 
46 namespace tablet {
47  template<typename KeyTypeWrapper> struct SliceTypeRowOps;
48  template<typename KeyTypeWrapper> struct NumTypeRowOps;
49 } // namespace tablet
50 
52 
53 class Schema;
54 class PartialRowPB;
55 
61 class KUDU_EXPORT KuduPartialRow {
62  public:
66  explicit KuduPartialRow(const Schema* schema);
67 
68  virtual ~KuduPartialRow();
69 
74  KuduPartialRow(const KuduPartialRow& other);
75 
81  KuduPartialRow& operator=(KuduPartialRow other);
82 
94  Status SetBool(const Slice& col_name, bool val) WARN_UNUSED_RESULT;
95 
96  Status SetInt8(const Slice& col_name, int8_t val) WARN_UNUSED_RESULT;
97  Status SetInt16(const Slice& col_name, int16_t val) WARN_UNUSED_RESULT;
98  Status SetInt32(const Slice& col_name, int32_t val) WARN_UNUSED_RESULT;
99  Status SetInt64(const Slice& col_name, int64_t val) WARN_UNUSED_RESULT;
100  Status SetUnixTimeMicros(const Slice& col_name,
101  int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
102 
103  Status SetFloat(const Slice& col_name, float val) WARN_UNUSED_RESULT;
104  Status SetDouble(const Slice& col_name, double val) WARN_UNUSED_RESULT;
106 
123  Status SetBool(int col_idx, bool val) WARN_UNUSED_RESULT;
124 
125  Status SetInt8(int col_idx, int8_t val) WARN_UNUSED_RESULT;
126  Status SetInt16(int col_idx, int16_t val) WARN_UNUSED_RESULT;
127  Status SetInt32(int col_idx, int32_t val) WARN_UNUSED_RESULT;
128  Status SetInt64(int col_idx, int64_t val) WARN_UNUSED_RESULT;
129  Status SetUnixTimeMicros(int col_idx, int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
130 
131  Status SetFloat(int col_idx, float val) WARN_UNUSED_RESULT;
132  Status SetDouble(int col_idx, double val) WARN_UNUSED_RESULT;
134 
152  Status SetBinary(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
153  Status SetString(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
155 
178  Status SetBinary(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
179  Status SetString(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
181 
194  Status SetBinaryCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
195  Status SetStringCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
197 
215  Status SetStringCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
216  Status SetBinaryCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
218 
236  Status SetBinaryNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
237  Status SetStringNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
239 
262  Status SetBinaryNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
263  Status SetStringNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
265 
274  Status SetNull(const Slice& col_name) WARN_UNUSED_RESULT;
275 
284  Status SetNull(int col_idx) WARN_UNUSED_RESULT;
285 
293  Status Unset(const Slice& col_name) WARN_UNUSED_RESULT;
294 
302  Status Unset(int col_idx) WARN_UNUSED_RESULT;
303 
309  bool IsColumnSet(const Slice& col_name) const;
310 
316  bool IsColumnSet(int col_idx) const;
317 
323  bool IsNull(const Slice& col_name) const;
324 
330  bool IsNull(int col_idx) const;
331 
343  Status GetBool(const Slice& col_name, bool* val) const WARN_UNUSED_RESULT;
344 
345  Status GetInt8(const Slice& col_name, int8_t* val) const WARN_UNUSED_RESULT;
346  Status GetInt16(const Slice& col_name, int16_t* val) const WARN_UNUSED_RESULT;
347  Status GetInt32(const Slice& col_name, int32_t* val) const WARN_UNUSED_RESULT;
348  Status GetInt64(const Slice& col_name, int64_t* val) const WARN_UNUSED_RESULT;
349  Status GetUnixTimeMicros(const Slice& col_name,
350  int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
351 
352  Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
353  Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
355 
374  Status GetBool(int col_idx, bool* val) const WARN_UNUSED_RESULT;
375 
376  Status GetInt8(int col_idx, int8_t* val) const WARN_UNUSED_RESULT;
377  Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
378  Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
379  Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
380  Status GetUnixTimeMicros(int col_idx, int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
381 
382  Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
383  Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
385 
403  Status GetString(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
404  Status GetBinary(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
406 
428  Status GetString(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
429  Status GetBinary(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
431 
432  //------------------------------------------------------------
433  // Key-encoding related functions
434  //------------------------------------------------------------
435 
447  Status EncodeRowKey(std::string* encoded_key) const;
448 
455  std::string ToEncodedRowKeyOrDie() const;
456 
457  //------------------------------------------------------------
458  // Utility code
459  //------------------------------------------------------------
460 
463  bool IsKeySet() const;
464 
466  bool AllColumnsSet() const;
467 
473  std::string ToString() const;
474 
476  const Schema* schema() const { return schema_; }
477 
478  private:
479  friend class client::KuduWriteOperation; // for row_data_.
480  friend class KeyUtilTest;
481  friend class PartitionSchema;
482  friend class RowOperationsPBDecoder;
483  friend class RowOperationsPBEncoder;
484  friend class TestScanSpec;
485  template<typename KeyTypeWrapper> friend struct client::SliceKeysTestSetup;
486  template<typename KeyTypeWrapper> friend struct client::IntKeysTestSetup;
487  template<typename KeyTypeWrapper> friend struct tablet::SliceTypeRowOps;
488  template<typename KeyTypeWrapper> friend struct tablet::NumTypeRowOps;
489  FRIEND_TEST(PartitionPrunerTest, TestPrimaryKeyRangePruning);
490  FRIEND_TEST(PartitionPrunerTest, TestPartialPrimaryKeyRangePruning);
491 
492  template<typename T>
493  Status Set(const Slice& col_name, const typename T::cpp_type& val,
494  bool owned = false);
495 
496  template<typename T>
497  Status Set(int col_idx, const typename T::cpp_type& val,
498  bool owned = false);
499 
500  // Runtime version of the generic setter.
501  Status Set(int32_t column_idx, const uint8_t* val);
502 
503  template<typename T>
504  Status Get(const Slice& col_name, typename T::cpp_type* val) const;
505 
506  template<typename T>
507  Status Get(int col_idx, typename T::cpp_type* val) const;
508 
509  template<typename T>
510  Status SetSliceCopy(const Slice& col_name, const Slice& val);
511 
512  template<typename T>
513  Status SetSliceCopy(int col_idx, const Slice& val);
514 
515  // If the given column is a variable length column whose memory is owned by this instance,
516  // deallocates the value.
517  // NOTE: Does not mutate the isset bitmap.
518  // REQUIRES: col_idx must be a variable length column.
519  void DeallocateStringIfSet(int col_idx, const ColumnSchema& col);
520 
521  // Deallocate any string/binary values whose memory is managed by this object.
522  void DeallocateOwnedStrings();
523 
524  const Schema* schema_;
525 
526  // 1-bit set for any field which has been explicitly set. This is distinct
527  // from NULL -- an "unset" field will take the server-side default on insert,
528  // whereas a field explicitly set to NULL will override the default.
529  uint8_t* isset_bitmap_;
530 
531  // 1-bit set for any variable length columns whose memory is managed by this instance.
532  // These strings need to be deallocated whenever the value is reset,
533  // or when the instance is destructed.
534  uint8_t* owned_strings_bitmap_;
535 
536  // The normal "contiguous row" format row data. Any column whose data is unset
537  // or NULL can have undefined bytes.
538  uint8_t* row_data_;
539 };
540 
541 } // namespace kudu
542 #endif /* KUDU_COMMON_PARTIAL_ROW_H */
Definition: callbacks.h:28
const Schema * schema() const
Definition: partial_row.h:476
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:61