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/int128.h"
36 #include "kudu/util/kudu_export.h"
37 #include "kudu/util/slice.h"
38 #include "kudu/util/status.h"
39 
40 namespace kudu {
41 class Schema;
42 
43 namespace tools {
44 class ReplicaDumper;
45 class TableScanner;
46 } // namespace tools
47 
48 namespace client {
49 class KuduSchema;
50 
84 class KUDU_EXPORT KuduScanBatch {
85  public:
90  class RowPtr;
91 
98  class const_iterator;
99 
101  typedef RowPtr value_type;
102 
103  KuduScanBatch();
104  ~KuduScanBatch();
105 
107  int NumRows() const;
108 
116  KuduScanBatch::RowPtr Row(int idx) const;
117 
119  const_iterator begin() const;
121  const_iterator end() const;
122 
126  const KuduSchema* projection_schema() const;
127 
135  //
142  Slice direct_data() const;
143 
147  Slice indirect_data() const;
149 
150  private:
151  class KUDU_NO_EXPORT Data;
152  friend class KuduScanner;
153  friend class tools::ReplicaDumper;
154 
155  Data* data_;
156  DISALLOW_COPY_AND_ASSIGN(KuduScanBatch);
157 };
158 
159 class KUDU_EXPORT KuduScanBatch::RowPtr {
160  public:
163  RowPtr() : schema_(NULL), row_data_(NULL) {}
164 
168  bool IsNull(const Slice& col_name) const;
169 
173  bool IsNull(int col_idx) const;
174 
181  Status IsDeleted(bool* val) const WARN_UNUSED_RESULT KUDU_NO_EXPORT;
182 
196  Status GetBool(const Slice& col_name, bool* val) const WARN_UNUSED_RESULT;
197 
198  Status GetInt8(const Slice& col_name, int8_t* val) const WARN_UNUSED_RESULT;
199  Status GetInt16(const Slice& col_name, int16_t* val) const WARN_UNUSED_RESULT;
200  Status GetInt32(const Slice& col_name, int32_t* val) const WARN_UNUSED_RESULT;
201  Status GetInt64(const Slice& col_name, int64_t* val) const WARN_UNUSED_RESULT;
202  Status GetUnixTimeMicros(const Slice& col_name, int64_t* micros_since_utc_epoch)
203  const WARN_UNUSED_RESULT;
204 
205  Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
206  Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
207 
208 #if KUDU_INT128_SUPPORTED
209  Status GetUnscaledDecimal(const Slice& col_name, int128_t* val) const WARN_UNUSED_RESULT;
210 #endif
211 
231  Status GetBool(int col_idx, bool* val) const WARN_UNUSED_RESULT;
232 
233  Status GetInt8(int col_idx, int8_t* val) const WARN_UNUSED_RESULT;
234  Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
235  Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
236  Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
237  Status GetUnixTimeMicros(int col_idx, int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
238 
239  Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
240  Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
241 
242 #if KUDU_INT128_SUPPORTED
243  Status GetUnscaledDecimal(int col_idx, int128_t* val) const WARN_UNUSED_RESULT;
244 #endif
245 
264  Status GetString(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
265  Status GetBinary(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
267 
289  Status GetString(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
290  Status GetBinary(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
292 
299  const void* cell(int col_idx) const;
300 
302  std::string ToString() const;
303 
304  private:
305  friend class KuduScanBatch;
306  friend class tools::TableScanner;
307  template<typename KeyTypeWrapper> friend struct SliceKeysTestSetup;
308  template<typename KeyTypeWrapper> friend struct IntKeysTestSetup;
309 
310  // Only invoked by KuduScanner.
311  RowPtr(const Schema* schema,
312  const uint8_t* row_data)
313  : schema_(schema),
314  row_data_(row_data) {
315  }
316 
317  template<typename T>
318  Status Get(const Slice& col_name, typename T::cpp_type* val) const;
319 
320  template<typename T>
321  Status Get(int col_idx, typename T::cpp_type* val) const;
322 
323  const Schema* schema_;
324  const uint8_t* row_data_;
325 };
326 
327 class KUDU_EXPORT KuduScanBatch::const_iterator
328  : public std::iterator<std::forward_iterator_tag, KuduScanBatch::RowPtr> {
329  public:
330  ~const_iterator() {}
331 
334  return batch_->Row(idx_);
335  }
336 
340  const_iterator& operator++() {
341  ++idx_;
342  return *this;
343  }
344 
348  const_iterator operator++(int) {
349  const_iterator tmp(batch_, idx_);
350  ++idx_;
351  return tmp;
352  }
353 
360  bool operator==(const const_iterator& other) const {
361  return (idx_ == other.idx_) && (batch_ == other.batch_);
362  }
363 
371  bool operator!=(const const_iterator& other) const {
372  return !(*this == other);
373  }
374 
375  private:
376  friend class KuduScanBatch;
377  const_iterator(const KuduScanBatch* b, int idx)
378  : batch_(b),
379  idx_(idx) {
380  }
381 
382  const KuduScanBatch* const batch_;
383  int idx_;
384 };
385 
386 
387 inline KuduScanBatch::const_iterator KuduScanBatch::begin() const {
388  return const_iterator(this, 0);
389 }
390 
391 inline KuduScanBatch::const_iterator KuduScanBatch::end() const {
392  return const_iterator(this, NumRows());
393 }
394 
395 } // namespace client
396 } // namespace kudu
397 
398 #endif
A representation of a table&#39;s schema.
Definition: schema.h:531
A representation of an operation&#39;s outcome.
Definition: status.h:145
const_iterator begin() const
Definition: scan_batch.h:387
RowPtr value_type
A handy typedef for the RowPtr.
Definition: scan_batch.h:98
RowPtr()
Definition: scan_batch.h:163
KuduScanBatch::RowPtr operator*() const
Definition: scan_batch.h:333
A wrapper around externally allocated data.
Definition: slice.h:50
This class is a representation of a single scan.
Definition: client.h:1832
bool operator==(const const_iterator &other) const
Definition: scan_batch.h:360
const_iterator operator++(int)
Definition: scan_batch.h:348
bool operator!=(const const_iterator &other) const
Definition: scan_batch.h:371
const_iterator & operator++()
Definition: scan_batch.h:340
const_iterator end() const
Definition: scan_batch.h:391
A batch of zero or more rows returned by a scan operation.
Definition: scan_batch.h:84