Kudu C++ client API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scan_batch.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_CLIENT_SCAN_BATCH_H
18 #define KUDU_CLIENT_SCAN_BATCH_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 <cstddef>
25 #include <iterator>
26 #include <string>
27 
28 #ifdef KUDU_HEADERS_NO_STUBS
29 #include "kudu/gutil/macros.h"
30 #include "kudu/gutil/port.h"
31 #else
32 #include "kudu/client/stubs.h"
33 #endif
34 
35 #include "kudu/util/kudu_export.h"
36 #include "kudu/util/slice.h"
37 #include "kudu/util/status.h"
38 
39 namespace kudu {
40 class Schema;
41 
42 namespace tools {
43 class ReplicaDumper;
44 } // namespace tools
45 
46 namespace client {
47 class KuduSchema;
48 
82 class KUDU_EXPORT KuduScanBatch {
83  public:
88  class RowPtr;
89 
96  class const_iterator;
97 
99  typedef RowPtr value_type;
100 
101  KuduScanBatch();
102  ~KuduScanBatch();
103 
105  int NumRows() const;
106 
114  KuduScanBatch::RowPtr Row(int idx) const;
115 
117  const_iterator begin() const;
119  const_iterator end() const;
120 
124  const KuduSchema* projection_schema() const;
125 
133  //
140  Slice direct_data() const;
141 
145  Slice indirect_data() const;
147 
148  private:
149  class KUDU_NO_EXPORT Data;
150  friend class KuduScanner;
151  friend class tools::ReplicaDumper;
152 
153  Data* data_;
154  DISALLOW_COPY_AND_ASSIGN(KuduScanBatch);
155 };
156 
157 class KUDU_EXPORT KuduScanBatch::RowPtr {
158  public:
161  RowPtr() : schema_(NULL), row_data_(NULL) {}
162 
166  bool IsNull(const Slice& col_name) const;
167 
171  bool IsNull(int col_idx) const;
172 
186  Status GetBool(const Slice& col_name, bool* val) const WARN_UNUSED_RESULT;
187 
188  Status GetInt8(const Slice& col_name, int8_t* val) const WARN_UNUSED_RESULT;
189  Status GetInt16(const Slice& col_name, int16_t* val) const WARN_UNUSED_RESULT;
190  Status GetInt32(const Slice& col_name, int32_t* val) const WARN_UNUSED_RESULT;
191  Status GetInt64(const Slice& col_name, int64_t* val) const WARN_UNUSED_RESULT;
192  Status GetUnixTimeMicros(const Slice& col_name, int64_t* micros_since_utc_epoch)
193  const WARN_UNUSED_RESULT;
194 
195  Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
196  Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
198 
217  Status GetBool(int col_idx, bool* val) const WARN_UNUSED_RESULT;
218 
219  Status GetInt8(int col_idx, int8_t* val) const WARN_UNUSED_RESULT;
220  Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
221  Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
222  Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
223  Status GetUnixTimeMicros(int col_idx, int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
224 
225  Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
226  Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
228 
246  Status GetString(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
247  Status GetBinary(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
249 
271  Status GetString(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
272  Status GetBinary(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
274 
281  const void* cell(int col_idx) const;
282 
284  std::string ToString() const;
285 
286  private:
287  friend class KuduScanBatch;
288  template<typename KeyTypeWrapper> friend struct SliceKeysTestSetup;
289  template<typename KeyTypeWrapper> friend struct IntKeysTestSetup;
290 
291  // Only invoked by KuduScanner.
292  RowPtr(const Schema* schema,
293  const uint8_t* row_data)
294  : schema_(schema),
295  row_data_(row_data) {
296  }
297 
298  template<typename T>
299  Status Get(const Slice& col_name, typename T::cpp_type* val) const;
300 
301  template<typename T>
302  Status Get(int col_idx, typename T::cpp_type* val) const;
303 
304  const Schema* schema_;
305  const uint8_t* row_data_;
306 };
307 
308 class KUDU_EXPORT KuduScanBatch::const_iterator
309  : public std::iterator<std::forward_iterator_tag, KuduScanBatch::RowPtr> {
310  public:
311  ~const_iterator() {}
312 
315  return batch_->Row(idx_);
316  }
317 
321  const_iterator& operator++() {
322  ++idx_;
323  return *this;
324  }
325 
329  const_iterator operator++(int) {
330  const_iterator tmp(batch_, idx_);
331  ++idx_;
332  return tmp;
333  }
334 
341  bool operator==(const const_iterator& other) const {
342  return (idx_ == other.idx_) && (batch_ == other.batch_);
343  }
344 
352  bool operator!=(const const_iterator& other) const {
353  return !(*this == other);
354  }
355 
356  private:
357  friend class KuduScanBatch;
358  const_iterator(const KuduScanBatch* b, int idx)
359  : batch_(b),
360  idx_(idx) {
361  }
362 
363  const KuduScanBatch* const batch_;
364  int idx_;
365 };
366 
367 
368 inline KuduScanBatch::const_iterator KuduScanBatch::begin() const {
369  return const_iterator(this, 0);
370 }
371 
372 inline KuduScanBatch::const_iterator KuduScanBatch::end() const {
373  return const_iterator(this, NumRows());
374 }
375 
376 } // namespace client
377 } // namespace kudu
378 
379 #endif
A representation of a table&#39;s schema.
Definition: schema.h:431
A representation of an operation&#39;s outcome.
Definition: status.h:135
const_iterator begin() const
Definition: scan_batch.h:368
RowPtr value_type
A handy typedef for the RowPtr.
Definition: scan_batch.h:96
RowPtr()
Definition: scan_batch.h:161
KuduScanBatch::RowPtr operator*() const
Definition: scan_batch.h:314
A wrapper around externally allocated data.
Definition: slice.h:47
This class is a representation of a single scan.
Definition: client.h:1701
bool operator==(const const_iterator &other) const
Definition: scan_batch.h:341
const_iterator operator++(int)
Definition: scan_batch.h:329
bool operator!=(const const_iterator &other) const
Definition: scan_batch.h:352
const_iterator & operator++()
Definition: scan_batch.h:321
const_iterator end() const
Definition: scan_batch.h:372
A batch of zero or more rows returned by a scan operation.
Definition: scan_batch.h:82