00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 #ifndef KUDU_COMMON_PARTIAL_ROW_H
00018 #define KUDU_COMMON_PARTIAL_ROW_H
00019 
00020 #include <stdint.h>
00021 #include <string>
00022 #include <vector>
00023 
00024 #ifdef KUDU_HEADERS_NO_STUBS
00025 #include "kudu/gutil/macros.h"
00026 #include "kudu/gutil/port.h"
00027 #include <gtest/gtest_prod.h>
00028 #else
00029 
00030 
00031 #include "kudu/client/stubs.h"
00032 #endif
00033 
00034 #include "kudu/util/kudu_export.h"
00035 #include "kudu/util/slice.h"
00036 
00037 namespace kudu {
00038 class ColumnSchema;
00039 namespace client {
00040 class KuduWriteOperation;
00041 template<typename KeyTypeWrapper> struct SliceKeysTestSetup;
00042 template<typename KeyTypeWrapper> struct IntKeysTestSetup;
00043 } 
00044 
00045 class Schema;
00046 class PartialRowPB;
00047 
00053 class KUDU_EXPORT KuduPartialRow {
00054  public:
00058   explicit KuduPartialRow(const Schema* schema);
00059 
00060   virtual ~KuduPartialRow();
00061 
00066   KuduPartialRow(const KuduPartialRow& other);
00067 
00073   KuduPartialRow& operator=(KuduPartialRow other);
00074 
00086   Status SetBool(const Slice& col_name, bool val) WARN_UNUSED_RESULT;
00087 
00088   Status SetInt8(const Slice& col_name, int8_t val) WARN_UNUSED_RESULT;
00089   Status SetInt16(const Slice& col_name, int16_t val) WARN_UNUSED_RESULT;
00090   Status SetInt32(const Slice& col_name, int32_t val) WARN_UNUSED_RESULT;
00091   Status SetInt64(const Slice& col_name, int64_t val) WARN_UNUSED_RESULT;
00092   Status SetUnixTimeMicros(const Slice& col_name,
00093                            int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
00094 
00095   Status SetFloat(const Slice& col_name, float val) WARN_UNUSED_RESULT;
00096   Status SetDouble(const Slice& col_name, double val) WARN_UNUSED_RESULT;
00098 
00115   Status SetBool(int col_idx, bool val) WARN_UNUSED_RESULT;
00116 
00117   Status SetInt8(int col_idx, int8_t val) WARN_UNUSED_RESULT;
00118   Status SetInt16(int col_idx, int16_t val) WARN_UNUSED_RESULT;
00119   Status SetInt32(int col_idx, int32_t val) WARN_UNUSED_RESULT;
00120   Status SetInt64(int col_idx, int64_t val) WARN_UNUSED_RESULT;
00121   Status SetUnixTimeMicros(int col_idx, int64_t micros_since_utc_epoch) WARN_UNUSED_RESULT;
00122 
00123   Status SetFloat(int col_idx, float val) WARN_UNUSED_RESULT;
00124   Status SetDouble(int col_idx, double val) WARN_UNUSED_RESULT;
00126 
00144   Status SetBinary(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
00145   Status SetString(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
00147 
00170   Status SetBinary(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
00171   Status SetString(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
00173 
00186   Status SetBinaryCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
00187   Status SetStringCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
00189 
00207   Status SetStringCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
00208   Status SetBinaryCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
00210 
00228   Status SetBinaryNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
00229   Status SetStringNoCopy(const Slice& col_name, const Slice& val) WARN_UNUSED_RESULT;
00231 
00254   Status SetBinaryNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
00255   Status SetStringNoCopy(int col_idx, const Slice& val) WARN_UNUSED_RESULT;
00257 
00266   Status SetNull(const Slice& col_name) WARN_UNUSED_RESULT;
00267 
00276   Status SetNull(int col_idx) WARN_UNUSED_RESULT;
00277 
00285   Status Unset(const Slice& col_name) WARN_UNUSED_RESULT;
00286 
00294   Status Unset(int col_idx) WARN_UNUSED_RESULT;
00295 
00301   bool IsColumnSet(const Slice& col_name) const;
00302 
00308   bool IsColumnSet(int col_idx) const;
00309 
00315   bool IsNull(const Slice& col_name) const;
00316 
00322   bool IsNull(int col_idx) const;
00323 
00335   Status GetBool(const Slice& col_name, bool* val) const WARN_UNUSED_RESULT;
00336 
00337   Status GetInt8(const Slice& col_name, int8_t* val) const WARN_UNUSED_RESULT;
00338   Status GetInt16(const Slice& col_name, int16_t* val) const WARN_UNUSED_RESULT;
00339   Status GetInt32(const Slice& col_name, int32_t* val) const WARN_UNUSED_RESULT;
00340   Status GetInt64(const Slice& col_name, int64_t* val) const WARN_UNUSED_RESULT;
00341   Status GetUnixTimeMicros(const Slice& col_name,
00342                       int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
00343 
00344   Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
00345   Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
00347 
00366   Status GetBool(int col_idx, bool* val) const WARN_UNUSED_RESULT;
00367 
00368   Status GetInt8(int col_idx, int8_t* val) const WARN_UNUSED_RESULT;
00369   Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
00370   Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
00371   Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
00372   Status GetUnixTimeMicros(int col_idx, int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
00373 
00374   Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
00375   Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
00377 
00395   Status GetString(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
00396   Status GetBinary(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
00398 
00420   Status GetString(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
00421   Status GetBinary(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
00423 
00424   
00425   
00426   
00427 
00439   Status EncodeRowKey(std::string* encoded_key) const;
00440 
00447   std::string ToEncodedRowKeyOrDie() const;
00448 
00449   
00450   
00451   
00452 
00455   bool IsKeySet() const;
00456 
00458   bool AllColumnsSet() const;
00459 
00461   std::string ToString() const;
00462 
00464   const Schema* schema() const { return schema_; }
00465 
00466  private:
00467   friend class client::KuduWriteOperation;   
00468   friend class KeyUtilTest;
00469   friend class PartitionSchema;
00470   friend class RowOperationsPBDecoder;
00471   friend class RowOperationsPBEncoder;
00472   friend class TestScanSpec;
00473   template<typename KeyTypeWrapper> friend struct client::SliceKeysTestSetup;
00474   template<typename KeyTypeWrapper> friend struct client::IntKeysTestSetup;
00475   FRIEND_TEST(TestPartitionPruner, TestPrimaryKeyRangePruning);
00476   FRIEND_TEST(TestPartitionPruner, TestPartialPrimaryKeyRangePruning);
00477 
00478   template<typename T>
00479   Status Set(const Slice& col_name, const typename T::cpp_type& val,
00480              bool owned = false);
00481 
00482   template<typename T>
00483   Status Set(int col_idx, const typename T::cpp_type& val,
00484              bool owned = false);
00485 
00486   
00487   Status Set(int32_t column_idx, const uint8_t* val);
00488 
00489   template<typename T>
00490   Status Get(const Slice& col_name, typename T::cpp_type* val) const;
00491 
00492   template<typename T>
00493   Status Get(int col_idx, typename T::cpp_type* val) const;
00494 
00495   template<typename T>
00496   Status SetSliceCopy(const Slice& col_name, const Slice& val);
00497 
00498   template<typename T>
00499   Status SetSliceCopy(int col_idx, const Slice& val);
00500 
00501   
00502   
00503   
00504   
00505   void DeallocateStringIfSet(int col_idx, const ColumnSchema& col);
00506 
00507   
00508   void DeallocateOwnedStrings();
00509 
00510   const Schema* schema_;
00511 
00512   
00513   
00514   
00515   uint8_t* isset_bitmap_;
00516 
00517   
00518   
00519   
00520   uint8_t* owned_strings_bitmap_;
00521 
00522   
00523   
00524   uint8_t* row_data_;
00525 };
00526 
00527 } 
00528 #endif