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 // 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 ClientTest_TestProjectionPredicatesFuzz_Test;
46 class KuduWriteOperation;
47 namespace internal {
48 class WriteRpc;
49 } // namespace internal
50 template<typename KeyTypeWrapper> struct SliceKeysTestSetup;// IWYU pragma: keep
51 template<typename KeyTypeWrapper> struct IntKeysTestSetup; // IWYU pragma: keep
52 } // namespace client
53 
54 namespace tablet {
55  template<typename KeyTypeWrapper> struct SliceTypeRowOps; // IWYU pragma: keep
56  template<typename KeyTypeWrapper> struct NumTypeRowOps; // IWYU pragma: keep
57 } // namespace tablet
58 
59 namespace tools {
60 class TableScanner;
61 } // namespace tools
62 
64 
65 class Schema;
66 
72 class KUDU_EXPORT KuduPartialRow {
73  public:
77  explicit KuduPartialRow(const Schema* schema);
78 
79  virtual ~KuduPartialRow();
80 
86 
93 
96 
104  Status SetBool(const Slice& col_name, bool val) WARN_UNUSED_RESULT;
105  Status SetInt8(const Slice& col_name, int8_t val) WARN_UNUSED_RESULT;
106  Status SetInt16(const Slice& col_name, int16_t val) WARN_UNUSED_RESULT;
107  Status SetInt32(const Slice& col_name, int32_t val) WARN_UNUSED_RESULT;
108  Status SetInt64(const Slice& col_name, int64_t val) WARN_UNUSED_RESULT;
116  Status SetUnixTimeMicros(const Slice& col_name,
117  int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
125  Status SetDate(const Slice& col_name, int32_t days_since_unix_epoch) WARN_UNUSED_RESULT;
126  Status SetFloat(const Slice& col_name, float val) WARN_UNUSED_RESULT;
127  Status SetDouble(const Slice& col_name, double val) WARN_UNUSED_RESULT;
128 #if KUDU_INT128_SUPPORTED
129  Status SetUnscaledDecimal(const Slice& col_name, int128_t val) WARN_UNUSED_RESULT;
130 #endif
131 
140 
146  Status SetBool(int col_idx, bool val) WARN_UNUSED_RESULT;
147 
148  Status SetInt8(int col_idx, int8_t val) WARN_UNUSED_RESULT;
149  Status SetInt16(int col_idx, int16_t val) WARN_UNUSED_RESULT;
150  Status SetInt32(int col_idx, int32_t val) WARN_UNUSED_RESULT;
151  Status SetInt64(int col_idx, int64_t val) WARN_UNUSED_RESULT;
152 
158  Status SetUnixTimeMicros(int col_idx, int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
159 
165  Status SetDate(int col_idx, int32_t days_since_unix_epoch) WARN_UNUSED_RESULT;
166 
167  Status SetFloat(int col_idx, float val) WARN_UNUSED_RESULT;
168  Status SetDouble(int col_idx, double val) WARN_UNUSED_RESULT;
169 #if KUDU_INT128_SUPPORTED
170  Status SetUnscaledDecimal(int col_idx, int128_t val) WARN_UNUSED_RESULT;
171 #endif
172 
176 
190  Status SetBinary(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
191  Status SetString(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
193 
203  Status SetVarchar(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
204 
207 
226  Status SetBinary(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
227  Status SetString(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
229 
243  Status SetVarchar(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
244 
247 
256  Status SetBinaryCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
257  Status SetStringCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
259 
262 
276  Status SetStringCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
277  Status SetBinaryCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
279 
282 
296  Status SetBinaryNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
297  Status SetStringNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
299 
305 
324  Status SetVarcharNoCopyUnsafe(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
325 
349  Status SetVarcharNoCopyUnsafe(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
351 
354 
373  Status SetBinaryNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
374  Status SetStringNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
376 
385  Status SetNull(const Slice& col_name) WARN_UNUSED_RESULT;
386 
395  Status SetNull(int col_idx) WARN_UNUSED_RESULT;
396 
404  Status Unset(const Slice& col_name) WARN_UNUSED_RESULT;
405 
413  Status Unset(int col_idx) WARN_UNUSED_RESULT;
414 
420  bool IsColumnSet(const Slice& col_name) const;
421 
427  bool IsColumnSet(int col_idx) const;
428 
434  bool IsNull(const Slice& col_name) const;
435 
441  bool IsNull(int col_idx) const;
442 
445 
457  Status GetBool(const Slice& col_name, bool* val) const WARN_UNUSED_RESULT;
458 
459  Status GetInt8(const Slice& col_name, int8_t* val) const WARN_UNUSED_RESULT;
460  Status GetInt16(const Slice& col_name, int16_t* val) const WARN_UNUSED_RESULT;
461  Status GetInt32(const Slice& col_name, int32_t* val) const WARN_UNUSED_RESULT;
462  Status GetInt64(const Slice& col_name, int64_t* val) const WARN_UNUSED_RESULT;
463 
473  Status GetUnixTimeMicros(const Slice& col_name,
474  int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
475 
485  Status GetDate(const Slice& col_name, int32_t* days_since_unix_epoch) const WARN_UNUSED_RESULT;
486  Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
487  Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
488 #if KUDU_INT128_SUPPORTED
489  // NOTE: The non-const version of this function is kept for backwards compatibility.
490  Status GetUnscaledDecimal(const Slice& col_name, int128_t* val) WARN_UNUSED_RESULT;
491  Status GetUnscaledDecimal(const Slice& col_name, int128_t* val) const WARN_UNUSED_RESULT;
492 #endif
493 
502 
514  Status GetBool(int col_idx, bool* val) const WARN_UNUSED_RESULT;
515  Status GetInt8(int col_idx, int8_t* val) const WARN_UNUSED_RESULT;
516  Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
517  Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
518  Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
519 
529  Status GetUnixTimeMicros(int col_idx, int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
530 
540  Status GetDate(int col_idx, int32_t* days_since_unix_epoch) const WARN_UNUSED_RESULT;
541  Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
542  Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
543 #if KUDU_INT128_SUPPORTED
544  // NOTE: The non-const version of this function is kept for backwards compatibility.
545  Status GetUnscaledDecimal(int col_idx, int128_t* val) WARN_UNUSED_RESULT;
546  Status GetUnscaledDecimal(int col_idx, int128_t* val) const WARN_UNUSED_RESULT;
547 #endif
548 
552 
566  Status GetString(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
567  Status GetBinary(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
568  Status GetVarchar(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
570 
573 
591  Status GetString(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
592  Status GetBinary(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
593  Status GetVarchar(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
595 
596  //------------------------------------------------------------
597  // Key-encoding related functions
598  //------------------------------------------------------------
599 
611  Status EncodeRowKey(std::string* encoded_key) const;
612 
619  std::string ToEncodedRowKeyOrDie() const;
620 
621  //------------------------------------------------------------
622  // Utility code
623  //------------------------------------------------------------
624 
627  bool IsKeySet() const;
628 
630  bool AllColumnsSet() const;
631 
637  std::string ToString() const;
638 
640  const Schema* schema() const { return schema_; }
641 
642  private:
643  friend class client::KuduWriteOperation; // for row_data_.
644  friend class client::internal::WriteRpc; // for row_data_.
645  friend class KeyUtilTest;
646  friend class PartitionSchema;
647  friend class RowOperationsPBDecoder;
648  friend class RowOperationsPBEncoder;
649  friend class tools::TableScanner;
650  friend class TestScanSpec;
651  template<typename KeyTypeWrapper> friend struct client::SliceKeysTestSetup;
652  template<typename KeyTypeWrapper> friend struct client::IntKeysTestSetup;
653  template<typename KeyTypeWrapper> friend struct tablet::SliceTypeRowOps;
654  template<typename KeyTypeWrapper> friend struct tablet::NumTypeRowOps;
655  FRIEND_TEST(client::ClientTest, TestProjectionPredicatesFuzz);
656  FRIEND_TEST(KeyUtilTest, TestIncrementInt128PrimaryKey);
657  FRIEND_TEST(PartitionPrunerTest, TestIntPartialPrimaryKeyRangePruning);
658  FRIEND_TEST(PartitionPrunerTest, TestPartialPrimaryKeyRangePruning);
659  FRIEND_TEST(PartitionPrunerTest, TestPrimaryKeyRangePruning);
660  FRIEND_TEST(RowOperationsTest, ProjectionTestWholeSchemaSpecified);
661  FRIEND_TEST(RowOperationsTest, TestProjectUpdates);
662  FRIEND_TEST(RowOperationsTest, TestProjectDeletes);
663 
664  template<typename T>
665  Status Set(const Slice& col_name, const typename T::cpp_type& val,
666  bool owned = false);
667 
668  template<typename T>
669  Status Set(int col_idx, const typename T::cpp_type& val,
670  bool owned = false);
671 
672  // Runtime version of the generic setter.
673  Status Set(int32_t column_idx, const uint8_t* val);
674 
675  template<typename T>
676  Status Get(const Slice& col_name, typename T::cpp_type* val) const;
677 
678  template<typename T>
679  Status Get(int col_idx, typename T::cpp_type* val) const;
680 
681  template<typename T>
682  Status SetSliceCopy(const Slice& col_name, const Slice& val);
683 
684  template<typename T>
685  Status SetSliceCopy(int col_idx, const Slice& val);
686 
687  // If the given column is a variable length column whose memory is owned by this instance,
688  // deallocates the value.
689  // NOTE: Does not mutate the isset bitmap.
690  // REQUIRES: col_idx must be a variable length column.
691  void DeallocateStringIfSet(int col_idx, const ColumnSchema& col);
692 
693  // Deallocate any string/binary values whose memory is managed by this object.
694  void DeallocateOwnedStrings();
695 
696  const Schema* schema_;
697 
698  // 1-bit set for any field which has been explicitly set. This is distinct
699  // from NULL -- an "unset" field will take the server-side default on insert,
700  // whereas a field explicitly set to NULL will override the default.
701  uint8_t* isset_bitmap_;
702 
703  // 1-bit set for any variable length columns whose memory is managed by this instance.
704  // These strings need to be deallocated whenever the value is reset,
705  // or when the instance is destructed.
706  uint8_t* owned_strings_bitmap_;
707 
708  // The normal "contiguous row" format row data. Any column whose data is unset
709  // or NULL can have undefined bytes.
710  uint8_t* row_data_;
711 };
712 
713 } // namespace kudu
714 #endif /* KUDU_COMMON_PARTIAL_ROW_H */
KuduPartialRow::SetNull
Status SetNull(int col_idx) WARN_UNUSED_RESULT
KuduPartialRow::SetUnixTimeMicros
Status SetUnixTimeMicros(const Slice &col_name, int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT
KuduPartialRow::SetStringNoCopy
Status SetStringNoCopy(const Slice &col_name, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::GetInt64
Status GetInt64(const Slice &col_name, int64_t *val) const WARN_UNUSED_RESULT
KuduPartialRow::SetInt8
Status SetInt8(int col_idx, int8_t val) WARN_UNUSED_RESULT
KuduPartialRow::GetString
Status GetString(const Slice &col_name, Slice *val) const WARN_UNUSED_RESULT
KuduPartialRow::SetBinaryNoCopy
Status SetBinaryNoCopy(const Slice &col_name, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::Unset
Status Unset(const Slice &col_name) WARN_UNUSED_RESULT
KuduPartialRow::GetVarchar
Status GetVarchar(const Slice &col_name, Slice *val) const WARN_UNUSED_RESULT
KuduPartialRow::GetFloat
Status GetFloat(int col_idx, float *val) const WARN_UNUSED_RESULT
KuduPartialRow::SetInt32
Status SetInt32(int col_idx, int32_t val) WARN_UNUSED_RESULT
KuduPartialRow::SetFloat
Status SetFloat(const Slice &col_name, float val) WARN_UNUSED_RESULT
KuduPartialRow::IsKeySet
bool IsKeySet() const
KuduPartialRow::SetVarchar
Status SetVarchar(const Slice &col_name, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::GetInt16
Status GetInt16(const Slice &col_name, int16_t *val) const WARN_UNUSED_RESULT
KuduPartialRow::ToString
std::string ToString() const
KuduPartialRow::SetDate
Status SetDate(const Slice &col_name, int32_t days_since_unix_epoch) WARN_UNUSED_RESULT
KuduPartialRow::SetBinaryCopy
Status SetBinaryCopy(int col_idx, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::GetDouble
Status GetDouble(const Slice &col_name, double *val) const WARN_UNUSED_RESULT
KuduPartialRow::GetBool
Status GetBool(int col_idx, bool *val) const WARN_UNUSED_RESULT
KuduPartialRow::IsColumnSet
bool IsColumnSet(int col_idx) const
KuduPartialRow::SetInt16
Status SetInt16(int col_idx, int16_t val) WARN_UNUSED_RESULT
KuduPartialRow::SetInt8
Status SetInt8(const Slice &col_name, int8_t val) WARN_UNUSED_RESULT
KuduPartialRow::SetInt32
Status SetInt32(const Slice &col_name, int32_t val) WARN_UNUSED_RESULT
KuduPartialRow::SetVarcharNoCopyUnsafe
Status SetVarcharNoCopyUnsafe(const Slice &col_name, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::KuduPartialRow
KuduPartialRow(const KuduPartialRow &other)
KuduPartialRow
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:72
KuduPartialRow::GetInt16
Status GetInt16(int col_idx, int16_t *val) const WARN_UNUSED_RESULT
KuduPartialRow::Unset
Status Unset(int col_idx) WARN_UNUSED_RESULT
KuduPartialRow::SetBinaryCopy
Status SetBinaryCopy(const Slice &col_name, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::SetDate
Status SetDate(int col_idx, int32_t days_since_unix_epoch) WARN_UNUSED_RESULT
KuduPartialRow::SetBool
Status SetBool(const Slice &col_name, bool val) WARN_UNUSED_RESULT
KuduPartialRow::SetDouble
Status SetDouble(int col_idx, double val) WARN_UNUSED_RESULT
KuduPartialRow::GetFloat
Status GetFloat(const Slice &col_name, float *val) const WARN_UNUSED_RESULT
KuduPartialRow::GetDate
Status GetDate(int col_idx, int32_t *days_since_unix_epoch) const WARN_UNUSED_RESULT
KuduPartialRow::GetInt64
Status GetInt64(int col_idx, int64_t *val) const WARN_UNUSED_RESULT
KuduPartialRow::schema
const Schema * schema() const
Definition: partial_row.h:640
KuduPartialRow::SetStringNoCopy
Status SetStringNoCopy(int col_idx, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::SetFloat
Status SetFloat(int col_idx, float val) WARN_UNUSED_RESULT
KuduPartialRow::GetVarchar
Status GetVarchar(int col_idx, Slice *val) const WARN_UNUSED_RESULT
KuduPartialRow::SetBinary
Status SetBinary(int col_idx, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::GetBinary
Status GetBinary(int col_idx, Slice *val) const WARN_UNUSED_RESULT
KuduPartialRow::GetUnixTimeMicros
Status GetUnixTimeMicros(int col_idx, int64_t *micros_since_utc_epoch) const WARN_UNUSED_RESULT
KuduPartialRow::SetBinaryNoCopy
Status SetBinaryNoCopy(int col_idx, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::SetBinary
Status SetBinary(const Slice &col_name, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::GetBinary
Status GetBinary(const Slice &col_name, Slice *val) const WARN_UNUSED_RESULT
KuduPartialRow::SetStringCopy
Status SetStringCopy(int col_idx, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::IsNull
bool IsNull(int col_idx) const
KuduPartialRow::SetVarcharNoCopyUnsafe
Status SetVarcharNoCopyUnsafe(int col_idx, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::SetBool
Status SetBool(int col_idx, bool val) WARN_UNUSED_RESULT
KuduPartialRow::GetBool
Status GetBool(const Slice &col_name, bool *val) const WARN_UNUSED_RESULT
KuduPartialRow::operator=
KuduPartialRow & operator=(KuduPartialRow other)
KuduPartialRow::SetStringCopy
Status SetStringCopy(const Slice &col_name, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::GetInt32
Status GetInt32(const Slice &col_name, int32_t *val) const WARN_UNUSED_RESULT
KuduPartialRow::GetDouble
Status GetDouble(int col_idx, double *val) const WARN_UNUSED_RESULT
KuduPartialRow::GetDate
Status GetDate(const Slice &col_name, int32_t *days_since_unix_epoch) const WARN_UNUSED_RESULT
KuduPartialRow::GetUnixTimeMicros
Status GetUnixTimeMicros(const Slice &col_name, int64_t *micros_since_utc_epoch) const WARN_UNUSED_RESULT
KuduPartialRow::GetString
Status GetString(int col_idx, Slice *val) const WARN_UNUSED_RESULT
KuduPartialRow::GetInt8
Status GetInt8(int col_idx, int8_t *val) const WARN_UNUSED_RESULT
KuduPartialRow::SetInt64
Status SetInt64(int col_idx, int64_t val) WARN_UNUSED_RESULT
KuduPartialRow::SetInt16
Status SetInt16(const Slice &col_name, int16_t val) WARN_UNUSED_RESULT
KuduPartialRow::EncodeRowKey
Status EncodeRowKey(std::string *encoded_key) const
KuduPartialRow::ToEncodedRowKeyOrDie
std::string ToEncodedRowKeyOrDie() const
KuduPartialRow::KuduPartialRow
KuduPartialRow(const Schema *schema)
KuduPartialRow::SetDouble
Status SetDouble(const Slice &col_name, double val) WARN_UNUSED_RESULT
KuduPartialRow::SetString
Status SetString(const Slice &col_name, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::SetString
Status SetString(int col_idx, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::IsNull
bool IsNull(const Slice &col_name) const
KuduPartialRow::GetInt8
Status GetInt8(const Slice &col_name, int8_t *val) const WARN_UNUSED_RESULT
KuduPartialRow::SetInt64
Status SetInt64(const Slice &col_name, int64_t val) WARN_UNUSED_RESULT
KuduPartialRow::GetInt32
Status GetInt32(int col_idx, int32_t *val) const WARN_UNUSED_RESULT
KuduPartialRow::SetVarchar
Status SetVarchar(int col_idx, const Slice &val) WARN_UNUSED_RESULT
KuduPartialRow::AllColumnsSet
bool AllColumnsSet() const
KuduPartialRow::SetUnixTimeMicros
Status SetUnixTimeMicros(int col_idx, int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT
KuduPartialRow::IsColumnSet
bool IsColumnSet(const Slice &col_name) const
KuduPartialRow::SetNull
Status SetNull(const Slice &col_name) WARN_UNUSED_RESULT
status.h