00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef KUDU_CLIENT_SCAN_BATCH_H
00018 #define KUDU_CLIENT_SCAN_BATCH_H
00019
00020 #include <string>
00021
00022 #ifdef KUDU_HEADERS_NO_STUBS
00023 #include "kudu/gutil/macros.h"
00024 #include "kudu/gutil/port.h"
00025 #else
00026 #include "kudu/client/stubs.h"
00027 #endif
00028
00029 #include "kudu/util/kudu_export.h"
00030 #include "kudu/util/slice.h"
00031
00032 namespace kudu {
00033 class Schema;
00034
00035 namespace tools {
00036 class ReplicaDumper;
00037 }
00038
00039 namespace client {
00040 class KuduSchema;
00041
00075 class KUDU_EXPORT KuduScanBatch {
00076 public:
00081 class RowPtr;
00082
00089 class const_iterator;
00090
00092 typedef RowPtr value_type;
00093
00094 KuduScanBatch();
00095 ~KuduScanBatch();
00096
00098 int NumRows() const;
00099
00107 KuduScanBatch::RowPtr Row(int idx) const;
00108
00110 const_iterator begin() const;
00112 const_iterator end() const;
00113
00117 const KuduSchema* projection_schema() const;
00118
00119 private:
00120 class KUDU_NO_EXPORT Data;
00121 friend class KuduScanner;
00122 friend class tools::ReplicaDumper;
00123
00124 Data* data_;
00125 DISALLOW_COPY_AND_ASSIGN(KuduScanBatch);
00126 };
00127
00128 class KUDU_EXPORT KuduScanBatch::RowPtr {
00129 public:
00132 RowPtr() : schema_(NULL), row_data_(NULL) {}
00133
00137 bool IsNull(const Slice& col_name) const;
00138
00142 bool IsNull(int col_idx) const;
00143
00157 Status GetBool(const Slice& col_name, bool* val) const WARN_UNUSED_RESULT;
00158
00159 Status GetInt8(const Slice& col_name, int8_t* val) const WARN_UNUSED_RESULT;
00160 Status GetInt16(const Slice& col_name, int16_t* val) const WARN_UNUSED_RESULT;
00161 Status GetInt32(const Slice& col_name, int32_t* val) const WARN_UNUSED_RESULT;
00162 Status GetInt64(const Slice& col_name, int64_t* val) const WARN_UNUSED_RESULT;
00163 Status GetUnixTimeMicros(const Slice& col_name, int64_t* micros_since_utc_epoch)
00164 const WARN_UNUSED_RESULT;
00165
00166 Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
00167 Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
00169
00188 Status GetBool(int col_idx, bool* val) const WARN_UNUSED_RESULT;
00189
00190 Status GetInt8(int col_idx, int8_t* val) const WARN_UNUSED_RESULT;
00191 Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
00192 Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
00193 Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
00194 Status GetUnixTimeMicros(int col_idx, int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
00195
00196 Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
00197 Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
00199
00217 Status GetString(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
00218 Status GetBinary(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
00220
00242 Status GetString(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
00243 Status GetBinary(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
00245
00252 const void* cell(int col_idx) const;
00253
00255 std::string ToString() const;
00256
00257 private:
00258 friend class KuduScanBatch;
00259 template<typename KeyTypeWrapper> friend struct SliceKeysTestSetup;
00260 template<typename KeyTypeWrapper> friend struct IntKeysTestSetup;
00261
00262
00263 RowPtr(const Schema* schema,
00264 const uint8_t* row_data)
00265 : schema_(schema),
00266 row_data_(row_data) {
00267 }
00268
00269 template<typename T>
00270 Status Get(const Slice& col_name, typename T::cpp_type* val) const;
00271
00272 template<typename T>
00273 Status Get(int col_idx, typename T::cpp_type* val) const;
00274
00275 const Schema* schema_;
00276 const uint8_t* row_data_;
00277 };
00278
00279 class KUDU_EXPORT KuduScanBatch::const_iterator
00280 : public std::iterator<std::forward_iterator_tag, KuduScanBatch::RowPtr> {
00281 public:
00282 ~const_iterator() {}
00283
00285 KuduScanBatch::RowPtr operator*() const {
00286 return batch_->Row(idx_);
00287 }
00288
00292 const_iterator& operator++() {
00293 ++idx_;
00294 return *this;
00295 }
00296
00300 const_iterator operator++(int) {
00301 const_iterator tmp(batch_, idx_);
00302 ++idx_;
00303 return tmp;
00304 }
00305
00312 bool operator==(const const_iterator& other) const {
00313 return (idx_ == other.idx_) && (batch_ == other.batch_);
00314 }
00315
00323 bool operator!=(const const_iterator& other) const {
00324 return !(*this == other);
00325 }
00326
00327 private:
00328 friend class KuduScanBatch;
00329 const_iterator(const KuduScanBatch* b, int idx)
00330 : batch_(b),
00331 idx_(idx) {
00332 }
00333
00334 const KuduScanBatch* const batch_;
00335 int idx_;
00336 };
00337
00338
00339 inline KuduScanBatch::const_iterator KuduScanBatch::begin() const {
00340 return const_iterator(this, 0);
00341 }
00342
00343 inline KuduScanBatch::const_iterator KuduScanBatch::end() const {
00344 return const_iterator(this, NumRows());
00345 }
00346
00347 }
00348 }
00349
00350 #endif