Kudu C++ client API
Loading...
Searching...
No Matches
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
40namespace kudu {
41class Schema;
42
43namespace tools {
44class ReplicaDumper;
45class TableScanner;
46} // namespace tools
47
48namespace client {
49class KuduSchema;
50
84class KUDU_EXPORT KuduScanBatch {
85 public:
90 class RowPtr;
91
98 class const_iterator;
99
101 typedef RowPtr value_type;
102
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
127
136
145
153
154 private:
155 class KUDU_NO_EXPORT Data;
156 friend class KuduScanner;
157 friend class tools::ReplicaDumper;
158
159 Data* data_;
160 DISALLOW_COPY_AND_ASSIGN(KuduScanBatch);
161};
162
163class KUDU_EXPORT KuduScanBatch::RowPtr {
164 public:
167 RowPtr() : schema_(NULL), row_data_(NULL) {}
168
171
173 const RowPtr* operator->() const {
174 return this;
175 }
179 bool IsNull(const Slice& col_name) const;
180
184 bool IsNull(int col_idx) const;
185
192 Status IsDeleted(bool* val) const WARN_UNUSED_RESULT KUDU_NO_EXPORT;
193
196
206 Status GetBool(const Slice& col_name, bool* val) const WARN_UNUSED_RESULT;
207 Status GetInt8(const Slice& col_name, int8_t* val) const WARN_UNUSED_RESULT;
208 Status GetInt16(const Slice& col_name, int16_t* val) const WARN_UNUSED_RESULT;
209 Status GetInt32(const Slice& col_name, int32_t* val) const WARN_UNUSED_RESULT;
210 Status GetInt64(const Slice& col_name, int64_t* val) const WARN_UNUSED_RESULT;
221 int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
231 Status GetDate(const Slice& col_name, int32_t* days_since_unix_epoch) const WARN_UNUSED_RESULT;
232 Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
233 Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
234#if KUDU_INT128_SUPPORTED
235 Status GetUnscaledDecimal(const Slice& col_name, int128_t* val) const WARN_UNUSED_RESULT;
236#endif
238
245
256 Status GetBool(int col_idx, bool* val) const WARN_UNUSED_RESULT;
257 Status GetInt8(int col_idx, int8_t* val) const WARN_UNUSED_RESULT;
258 Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
259 Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
260 Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
271 Status GetUnixTimeMicros(int col_idx, int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
282 Status GetDate(int col_idx, int32_t* days_since_unix_epoch) const WARN_UNUSED_RESULT;
283 Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
284 Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
285#if KUDU_INT128_SUPPORTED
286 Status GetUnscaledDecimal(int col_idx, int128_t* val) const WARN_UNUSED_RESULT;
287#endif
289
292
306 Status GetString(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
307 Status GetBinary(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
308 Status GetVarchar(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
310
313
331 Status GetString(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
332 Status GetBinary(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
333 Status GetVarchar(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
335
342 const void* cell(int col_idx) const;
343
345 std::string ToString() const;
346
347 private:
348 friend class KuduScanBatch;
349 friend class tools::TableScanner;
350 template<typename KeyTypeWrapper> friend struct SliceKeysTestSetup;
351 template<typename KeyTypeWrapper> friend struct IntKeysTestSetup;
352
353 // Only invoked by KuduScanner.
354 RowPtr(const Schema* schema,
355 const uint8_t* row_data)
356 : schema_(schema),
357 row_data_(row_data) {
358 }
359
360 template<typename T>
361 Status Get(const Slice& col_name, typename T::cpp_type* val) const;
362
363 template<typename T>
364 Status Get(int col_idx, typename T::cpp_type* val) const;
365
366 const Schema* schema_;
367 const uint8_t* row_data_;
368};
369
370class KUDU_EXPORT KuduScanBatch::const_iterator
371 : public std::iterator<std::forward_iterator_tag, KuduScanBatch::RowPtr> {
372 public:
373 ~const_iterator() {}
374
376 KuduScanBatch::RowPtr operator*() const {
377 return batch_->Row(idx_);
378 }
379
384
386 KuduScanBatch::RowPtr operator->() const {
387 return batch_->Row(idx_);
388 }
389
393 const_iterator& operator++() {
394 ++idx_;
395 return *this;
396 }
397
401 const_iterator operator++(int) {
402 const_iterator tmp(batch_, idx_);
403 ++idx_;
404 return tmp;
405 }
406
413 bool operator==(const const_iterator& other) const {
414 return (idx_ == other.idx_) && (batch_ == other.batch_);
415 }
416
424 bool operator!=(const const_iterator& other) const {
425 return !(*this == other);
426 }
427
428 private:
429 friend class KuduScanBatch;
430 const_iterator(const KuduScanBatch* b, int idx)
431 : batch_(b),
432 idx_(idx) {
433 }
434
435 const KuduScanBatch* const batch_;
436 int idx_;
437};
438
439
440inline KuduScanBatch::const_iterator KuduScanBatch::begin() const {
441 return const_iterator(this, 0);
442}
443
444inline KuduScanBatch::const_iterator KuduScanBatch::end() const {
445 return const_iterator(this, NumRows());
446}
447
448} // namespace client
449} // namespace kudu
450
451#endif
A wrapper around externally allocated data.
Definition slice.h:51
A representation of an operation's outcome.
Definition status.h:165
A batch of zero or more rows returned by a scan operation.
Definition scan_batch.h:84
Status GetVarchar(int col_idx, Slice *val) const WARN_UNUSED_RESULT
const RowPtr * operator->() const
Definition scan_batch.h:173
Status GetDate(const Slice &col_name, int32_t *days_since_unix_epoch) const WARN_UNUSED_RESULT
Status GetVarchar(const Slice &col_name, Slice *val) const WARN_UNUSED_RESULT
bool operator!=(const const_iterator &other) const
Definition scan_batch.h:424
Status IsDeleted(bool *val) const WARN_UNUSED_RESULT KUDU_NO_EXPORT
Status GetBinary(const Slice &col_name, Slice *val) const WARN_UNUSED_RESULT
Status GetBool(const Slice &col_name, bool *val) const WARN_UNUSED_RESULT
KuduScanBatch::RowPtr Row(int idx) const
Status GetBool(int col_idx, bool *val) const WARN_UNUSED_RESULT
const_iterator operator++(int)
Definition scan_batch.h:401
Status GetInt64(const Slice &col_name, int64_t *val) const WARN_UNUSED_RESULT
const_iterator end() const
Definition scan_batch.h:444
KuduScanBatch::RowPtr operator*() const
Definition scan_batch.h:376
bool IsNull(int col_idx) const
const_iterator & operator++()
Definition scan_batch.h:393
const_iterator begin() const
Definition scan_batch.h:440
Status GetFloat(const Slice &col_name, float *val) const WARN_UNUSED_RESULT
KuduScanBatch::RowPtr operator->() const
Definition scan_batch.h:386
bool operator==(const const_iterator &other) const
Definition scan_batch.h:413
Status GetInt8(const Slice &col_name, int8_t *val) const WARN_UNUSED_RESULT
Status GetDouble(const Slice &col_name, double *val) const WARN_UNUSED_RESULT
Status GetInt8(int col_idx, int8_t *val) const WARN_UNUSED_RESULT
Status GetString(int col_idx, Slice *val) const WARN_UNUSED_RESULT
Status GetBinary(int col_idx, Slice *val) const WARN_UNUSED_RESULT
RowPtr()
Definition scan_batch.h:167
Status GetDouble(int col_idx, double *val) const WARN_UNUSED_RESULT
Status GetInt32(int col_idx, int32_t *val) const WARN_UNUSED_RESULT
Status GetInt64(int col_idx, int64_t *val) const WARN_UNUSED_RESULT
Status GetInt16(int col_idx, int16_t *val) const WARN_UNUSED_RESULT
Status GetInt32(const Slice &col_name, int32_t *val) const WARN_UNUSED_RESULT
std::string ToString() const
Status GetUnixTimeMicros(int col_idx, int64_t *micros_since_utc_epoch) const WARN_UNUSED_RESULT
bool IsNull(const Slice &col_name) const
const KuduSchema * projection_schema() const
Status GetString(const Slice &col_name, Slice *val) const WARN_UNUSED_RESULT
Status GetUnixTimeMicros(const Slice &col_name, int64_t *micros_since_utc_epoch) const WARN_UNUSED_RESULT
RowPtr value_type
A handy typedef for the RowPtr.
Definition scan_batch.h:101
Status GetFloat(int col_idx, float *val) const WARN_UNUSED_RESULT
const void * cell(int col_idx) const
Status GetInt16(const Slice &col_name, int16_t *val) const WARN_UNUSED_RESULT
Status GetDate(int col_idx, int32_t *days_since_unix_epoch) const WARN_UNUSED_RESULT
This class is a representation of a single scan.
Definition client.h:2712
A representation of a table's schema.
Definition schema.h:688