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 // NOTE: using stdint.h instead of cstdint because this file is supposed
21 // to be processed by a compiler lacking C++11 support.
22 #include <stdint.h>
23 
24 #include <string>
25 
26 #ifdef KUDU_HEADERS_NO_STUBS
27 #include <gtest/gtest_prod.h>
28 
29 #include "kudu/gutil/port.h"
30 #else
31 // This is a poor module interdependency, but the stubs are header-only and
32 // it's only for exported header builds, so we'll make an exception.
33 #include "kudu/client/stubs.h"
34 #endif
35 
36 #include "kudu/util/int128.h"
37 #include "kudu/util/kudu_export.h"
38 #include "kudu/util/slice.h"
39 #include "kudu/util/status.h"
40 
42 namespace kudu {
43 class ColumnSchema;
44 namespace client {
45 class KuduWriteOperation;
46 template<typename KeyTypeWrapper> struct SliceKeysTestSetup;// IWYU pragma: keep
47 template<typename KeyTypeWrapper> struct IntKeysTestSetup; // IWYU pragma: keep
48 } // namespace client
49 
50 namespace tablet {
51  template<typename KeyTypeWrapper> struct SliceTypeRowOps; // IWYU pragma: keep
52  template<typename KeyTypeWrapper> struct NumTypeRowOps; // IWYU pragma: keep
53 } // namespace tablet
54 
55 namespace tools {
56 class TableScanner;
57 } // namespace tools
58 
60 
61 class Schema;
62 
68 class KUDU_EXPORT KuduPartialRow {
69  public:
73  explicit KuduPartialRow(const Schema* schema);
74 
75  virtual ~KuduPartialRow();
76 
81  KuduPartialRow(const KuduPartialRow& other);
82 
88  KuduPartialRow& operator=(KuduPartialRow other);
89 
101  Status SetBool(const Slice& col_name, bool val) WARN_UNUSED_RESULT;
102 
103  Status SetInt8(const Slice& col_name, int8_t val) WARN_UNUSED_RESULT;
104  Status SetInt16(const Slice& col_name, int16_t val) WARN_UNUSED_RESULT;
105  Status SetInt32(const Slice& col_name, int32_t val) WARN_UNUSED_RESULT;
106  Status SetInt64(const Slice& col_name, int64_t val) WARN_UNUSED_RESULT;
107  Status SetUnixTimeMicros(const Slice& col_name,
108  int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
109 
110  Status SetFloat(const Slice& col_name, float val) WARN_UNUSED_RESULT;
111  Status SetDouble(const Slice& col_name, double val) WARN_UNUSED_RESULT;
112 #if KUDU_INT128_SUPPORTED
113  Status SetUnscaledDecimal(const Slice& col_name, int128_t val) WARN_UNUSED_RESULT;
114 #endif
115 
133  Status SetBool(int col_idx, bool val) WARN_UNUSED_RESULT;
134 
135  Status SetInt8(int col_idx, int8_t val) WARN_UNUSED_RESULT;
136  Status SetInt16(int col_idx, int16_t val) WARN_UNUSED_RESULT;
137  Status SetInt32(int col_idx, int32_t val) WARN_UNUSED_RESULT;
138  Status SetInt64(int col_idx, int64_t val) WARN_UNUSED_RESULT;
139  Status SetUnixTimeMicros(int col_idx, int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
140 
141  Status SetFloat(int col_idx, float val) WARN_UNUSED_RESULT;
142  Status SetDouble(int col_idx, double val) WARN_UNUSED_RESULT;
143 #if KUDU_INT128_SUPPORTED
144  Status SetUnscaledDecimal(int col_idx, int128_t val) WARN_UNUSED_RESULT;
145 #endif
146 
165  Status SetBinary(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
166  Status SetString(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
168 
191  Status SetBinary(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
192  Status SetString(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
194 
207  Status SetBinaryCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
208  Status SetStringCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
210 
228  Status SetStringCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
229  Status SetBinaryCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
231 
249  Status SetBinaryNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
250  Status SetStringNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
252 
275  Status SetBinaryNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
276  Status SetStringNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
278 
287  Status SetNull(const Slice& col_name) WARN_UNUSED_RESULT;
288 
297  Status SetNull(int col_idx) WARN_UNUSED_RESULT;
298 
306  Status Unset(const Slice& col_name) WARN_UNUSED_RESULT;
307 
315  Status Unset(int col_idx) WARN_UNUSED_RESULT;
316 
322  bool IsColumnSet(const Slice& col_name) const;
323 
329  bool IsColumnSet(int col_idx) const;
330 
336  bool IsNull(const Slice& col_name) const;
337 
343  bool IsNull(int col_idx) const;
344 
356  Status GetBool(const Slice& col_name, bool* val) const WARN_UNUSED_RESULT;
357 
358  Status GetInt8(const Slice& col_name, int8_t* val) const WARN_UNUSED_RESULT;
359  Status GetInt16(const Slice& col_name, int16_t* val) const WARN_UNUSED_RESULT;
360  Status GetInt32(const Slice& col_name, int32_t* val) const WARN_UNUSED_RESULT;
361  Status GetInt64(const Slice& col_name, int64_t* val) const WARN_UNUSED_RESULT;
362  Status GetUnixTimeMicros(const Slice& col_name,
363  int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
364 
365  Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
366  Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
367 #if KUDU_INT128_SUPPORTED
368  // NOTE: The non-const version of this function is kept for backwards compatibility.
369  Status GetUnscaledDecimal(const Slice& col_name, int128_t* val) WARN_UNUSED_RESULT;
370  Status GetUnscaledDecimal(const Slice& col_name, int128_t* val) const WARN_UNUSED_RESULT;
371 #endif
372 
392  Status GetBool(int col_idx, bool* val) const WARN_UNUSED_RESULT;
393 
394  Status GetInt8(int col_idx, int8_t* val) const WARN_UNUSED_RESULT;
395  Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
396  Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
397  Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
398  Status GetUnixTimeMicros(int col_idx, int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
399 
400  Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
401  Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
402 #if KUDU_INT128_SUPPORTED
403  // NOTE: The non-const version of this function is kept for backwards compatibility.
404  Status GetUnscaledDecimal(int col_idx, int128_t* val) WARN_UNUSED_RESULT;
405  Status GetUnscaledDecimal(int col_idx, int128_t* val) const WARN_UNUSED_RESULT;
406 #endif
407 
426  Status GetString(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
427  Status GetBinary(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
429 
451  Status GetString(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
452  Status GetBinary(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
454 
455  //------------------------------------------------------------
456  // Key-encoding related functions
457  //------------------------------------------------------------
458 
470  Status EncodeRowKey(std::string* encoded_key) const;
471 
478  std::string ToEncodedRowKeyOrDie() const;
479 
480  //------------------------------------------------------------
481  // Utility code
482  //------------------------------------------------------------
483 
486  bool IsKeySet() const;
487 
489  bool AllColumnsSet() const;
490 
496  std::string ToString() const;
497 
499  const Schema* schema() const { return schema_; }
500 
501  private:
502  friend class client::KuduWriteOperation; // for row_data_.
503  friend class KeyUtilTest;
504  friend class PartitionSchema;
505  friend class RowOperationsPBDecoder;
506  friend class RowOperationsPBEncoder;
507  friend class tools::TableScanner;
508  friend class TestScanSpec;
509  template<typename KeyTypeWrapper> friend struct client::SliceKeysTestSetup;
510  template<typename KeyTypeWrapper> friend struct client::IntKeysTestSetup;
511  template<typename KeyTypeWrapper> friend struct tablet::SliceTypeRowOps;
512  template<typename KeyTypeWrapper> friend struct tablet::NumTypeRowOps;
513  FRIEND_TEST(KeyUtilTest, TestIncrementInt128PrimaryKey);
514  FRIEND_TEST(PartitionPrunerTest, TestIntPartialPrimaryKeyRangePruning);
515  FRIEND_TEST(PartitionPrunerTest, TestPartialPrimaryKeyRangePruning);
516  FRIEND_TEST(PartitionPrunerTest, TestPrimaryKeyRangePruning);
517 
518  template<typename T>
519  Status Set(const Slice& col_name, const typename T::cpp_type& val,
520  bool owned = false);
521 
522  template<typename T>
523  Status Set(int col_idx, const typename T::cpp_type& val,
524  bool owned = false);
525 
526  // Runtime version of the generic setter.
527  Status Set(int32_t column_idx, const uint8_t* val);
528 
529  template<typename T>
530  Status Get(const Slice& col_name, typename T::cpp_type* val) const;
531 
532  template<typename T>
533  Status Get(int col_idx, typename T::cpp_type* val) const;
534 
535  template<typename T>
536  Status SetSliceCopy(const Slice& col_name, const Slice& val);
537 
538  template<typename T>
539  Status SetSliceCopy(int col_idx, const Slice& val);
540 
541  // If the given column is a variable length column whose memory is owned by this instance,
542  // deallocates the value.
543  // NOTE: Does not mutate the isset bitmap.
544  // REQUIRES: col_idx must be a variable length column.
545  void DeallocateStringIfSet(int col_idx, const ColumnSchema& col);
546 
547  // Deallocate any string/binary values whose memory is managed by this object.
548  void DeallocateOwnedStrings();
549 
550  const Schema* schema_;
551 
552  // 1-bit set for any field which has been explicitly set. This is distinct
553  // from NULL -- an "unset" field will take the server-side default on insert,
554  // whereas a field explicitly set to NULL will override the default.
555  uint8_t* isset_bitmap_;
556 
557  // 1-bit set for any variable length columns whose memory is managed by this instance.
558  // These strings need to be deallocated whenever the value is reset,
559  // or when the instance is destructed.
560  uint8_t* owned_strings_bitmap_;
561 
562  // The normal "contiguous row" format row data. Any column whose data is unset
563  // or NULL can have undefined bytes.
564  uint8_t* row_data_;
565 };
566 
567 } // namespace kudu
568 #endif /* KUDU_COMMON_PARTIAL_ROW_H */
const Schema * schema() const
Definition: partial_row.h:499
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:68