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
102
103 KuduScanBatch();
104 ~KuduScanBatch();
105
107 int NumRows() const;
108
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
164class KUDU_EXPORT KuduScanBatch::RowPtr {
165 public:
168 RowPtr() : schema_(NULL), row_data_(NULL) {}
169
172
174 const RowPtr* operator->() const {
175 return this;
176 }
177
180 bool IsNull(const Slice& col_name) const;
181
185 bool IsNull(int col_idx) const;
186
193 Status IsDeleted(bool* val) const WARN_UNUSED_RESULT KUDU_NO_EXPORT;
194
197
207 Status GetBool(const Slice& col_name, bool* val) const WARN_UNUSED_RESULT;
208 Status GetInt8(const Slice& col_name, int8_t* val) const WARN_UNUSED_RESULT;
209 Status GetInt16(const Slice& col_name, int16_t* val) const WARN_UNUSED_RESULT;
210 Status GetInt32(const Slice& col_name, int32_t* val) const WARN_UNUSED_RESULT;
211 Status GetInt64(const Slice& col_name, int64_t* val) const WARN_UNUSED_RESULT;
222 int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
232 Status GetDate(const Slice& col_name, int32_t* days_since_unix_epoch) const WARN_UNUSED_RESULT;
233 Status GetFloat(const Slice& col_name, float* val) const WARN_UNUSED_RESULT;
234 Status GetDouble(const Slice& col_name, double* val) const WARN_UNUSED_RESULT;
235#if KUDU_INT128_SUPPORTED
236 Status GetUnscaledDecimal(const Slice& col_name, int128_t* val) const WARN_UNUSED_RESULT;
237#endif
239
246
257 Status GetBool(int col_idx, bool* val) const WARN_UNUSED_RESULT;
258 Status GetInt8(int col_idx, int8_t* val) const WARN_UNUSED_RESULT;
259 Status GetInt16(int col_idx, int16_t* val) const WARN_UNUSED_RESULT;
260 Status GetInt32(int col_idx, int32_t* val) const WARN_UNUSED_RESULT;
261 Status GetInt64(int col_idx, int64_t* val) const WARN_UNUSED_RESULT;
272 Status GetUnixTimeMicros(int col_idx, int64_t* micros_since_utc_epoch) const WARN_UNUSED_RESULT;
283 Status GetDate(int col_idx, int32_t* days_since_unix_epoch) const WARN_UNUSED_RESULT;
284 Status GetFloat(int col_idx, float* val) const WARN_UNUSED_RESULT;
285 Status GetDouble(int col_idx, double* val) const WARN_UNUSED_RESULT;
286#if KUDU_INT128_SUPPORTED
287 Status GetUnscaledDecimal(int col_idx, int128_t* val) const WARN_UNUSED_RESULT;
288#endif
290
293
307 Status GetString(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
308 Status GetBinary(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
309 Status GetVarchar(const Slice& col_name, Slice* val) const WARN_UNUSED_RESULT;
311
314
332 Status GetString(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
333 Status GetBinary(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
334 Status GetVarchar(int col_idx, Slice* val) const WARN_UNUSED_RESULT;
336
343 const void* cell(int col_idx) const;
344
346 std::string ToString() const;
347
348 private:
349 friend class KuduScanBatch;
350 friend class tools::TableScanner;
351 template<typename KeyTypeWrapper> friend struct SliceKeysTestSetup;
352 template<typename KeyTypeWrapper> friend struct IntKeysTestSetup;
353
354 // Only invoked by KuduScanner.
355 RowPtr(const Schema* schema,
356 const uint8_t* row_data)
357 : schema_(schema),
358 row_data_(row_data) {
359 }
360
361 template<typename T>
362 Status Get(const Slice& col_name, typename T::cpp_type* val) const;
363
364 template<typename T>
365 Status Get(int col_idx, typename T::cpp_type* val) const;
366
367 const Schema* schema_;
368 const uint8_t* row_data_;
369};
370
371// std::iterator has been deprecated in C++17, but this code should still be
372// compilable by legacy C++98 compilers as well. It's also necessary to keep
373// backward compatibility with the ABI provided by earlier Kudu releases,
374// so modifiying the inheritance chain isn't an option. Instead of removing
375// the inheritance from std::iterator<...> and explicitly defining the types
376// required by the STL iterator traits, the deprecation warnings are silenced.
377#pragma GCC diagnostic push
378#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
380class KUDU_EXPORT KuduScanBatch::const_iterator
381 : public std::iterator<std::forward_iterator_tag, KuduScanBatch::RowPtr> {
382 public:
383 ~const_iterator() {}
384
387 return batch_->Row(idx_);
388 }
389
394
397 return batch_->Row(idx_);
398 }
399
403 const_iterator& operator++() {
404 ++idx_;
405 return *this;
406 }
407
411 const_iterator operator++(int) {
412 const_iterator tmp(batch_, idx_);
413 ++idx_;
414 return tmp;
415 }
416
423 bool operator==(const const_iterator& other) const {
424 return (idx_ == other.idx_) && (batch_ == other.batch_);
425 }
426
434 bool operator!=(const const_iterator& other) const {
435 return !(*this == other);
436 }
437
438 private:
439 friend class KuduScanBatch;
440 const_iterator(const KuduScanBatch* b, int idx)
441 : batch_(b),
442 idx_(idx) {
443 }
444
445 const KuduScanBatch* const batch_;
446 int idx_;
447};
448#pragma GCC diagnostic pop
449
451 return const_iterator(this, 0);
452}
453
457
458} // namespace client
459} // namespace kudu
460
461#endif
A wrapper around externally allocated data.
Definition slice.h:51
A representation of an operation's outcome.
Definition status.h:191
A handle for a single row in KuduScanBatch.
Definition scan_batch.h:164
Status GetFloat(const Slice &col_name, float *val) const WARN_UNUSED_RESULT
Status GetString(const Slice &col_name, Slice *val) const WARN_UNUSED_RESULT
Status GetInt16(int col_idx, int16_t *val) const WARN_UNUSED_RESULT
Status GetDate(int col_idx, int32_t *days_since_unix_epoch) const WARN_UNUSED_RESULT
Status IsDeleted(bool *val) const WARN_UNUSED_RESULT KUDU_NO_EXPORT
Status GetInt64(int col_idx, int64_t *val) const WARN_UNUSED_RESULT
Status GetInt8(int col_idx, int8_t *val) const WARN_UNUSED_RESULT
bool IsNull(const Slice &col_name) const
Status GetUnixTimeMicros(int col_idx, int64_t *micros_since_utc_epoch) const WARN_UNUSED_RESULT
Status GetFloat(int col_idx, float *val) const WARN_UNUSED_RESULT
Status GetString(int col_idx, Slice *val) const WARN_UNUSED_RESULT
Status GetDouble(int col_idx, double *val) const WARN_UNUSED_RESULT
Status GetInt32(int col_idx, int32_t *val) const WARN_UNUSED_RESULT
Status GetBinary(int col_idx, Slice *val) const WARN_UNUSED_RESULT
Status GetInt8(const Slice &col_name, int8_t *val) const WARN_UNUSED_RESULT
Status GetBool(const Slice &col_name, bool *val) const WARN_UNUSED_RESULT
Status GetBinary(const Slice &col_name, Slice *val) const WARN_UNUSED_RESULT
bool IsNull(int col_idx) const
Status GetVarchar(int col_idx, Slice *val) const WARN_UNUSED_RESULT
Status GetDate(const Slice &col_name, int32_t *days_since_unix_epoch) const WARN_UNUSED_RESULT
const RowPtr * operator->() const
Definition scan_batch.h:174
RowPtr()
Definition scan_batch.h:168
Status GetInt32(const Slice &col_name, int32_t *val) const WARN_UNUSED_RESULT
Status GetBool(int col_idx, bool *val) const WARN_UNUSED_RESULT
Status GetVarchar(const Slice &col_name, Slice *val) const WARN_UNUSED_RESULT
Status GetInt16(const Slice &col_name, int16_t *val) const WARN_UNUSED_RESULT
Status GetUnixTimeMicros(const Slice &col_name, int64_t *micros_since_utc_epoch) const WARN_UNUSED_RESULT
Status GetDouble(const Slice &col_name, double *val) const WARN_UNUSED_RESULT
const void * cell(int col_idx) const
Status GetInt64(const Slice &col_name, int64_t *val) const WARN_UNUSED_RESULT
Iterator to work with immutable KuduScanBatch instances.
Definition scan_batch.h:381
KuduScanBatch::RowPtr operator->() const
Definition scan_batch.h:396
const_iterator & operator++()
Definition scan_batch.h:403
const_iterator operator++(int)
Definition scan_batch.h:411
bool operator!=(const const_iterator &other) const
Definition scan_batch.h:434
bool operator==(const const_iterator &other) const
Definition scan_batch.h:423
KuduScanBatch::RowPtr operator*() const
Definition scan_batch.h:386
A batch of zero or more rows returned by a scan operation.
Definition scan_batch.h:84
KuduScanBatch::RowPtr Row(int idx) const
const_iterator end() const
Definition scan_batch.h:454
const_iterator begin() const
Definition scan_batch.h:450
const KuduSchema * projection_schema() const
RowPtr value_type
A handy typedef for the RowPtr.
Definition scan_batch.h:101
A representation of a table's schema.
Definition schema.h:688