This is an automated email from the ASF dual-hosted git repository.
adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 96f4cbe KUDU-1561 Implemented operator->() in
KuduScanBatch::const_iterator
96f4cbe is described below
commit 96f4cbe7dc62f68910f42da2f161e953e4bcabee
Author: Volodymyr Verovkin <[email protected]>
AuthorDate: Wed Sep 11 23:46:54 2019 -0700
KUDU-1561 Implemented operator->() in KuduScanBatch::const_iterator
operator->() requires returning pointer or object which overloads access
via pointer operator (operator->() again).
Since KuduScanBatch::const_iterator does to keep current
KuduScanBatch::RowPtr, we cannot return pointer to it in operator ->.
Instead, we return KuduScanBatch::RowPtr which implements pointer trait
(operator->).
Change-Id: Ib5ddd99073d6a93337c184bee8b930cabeeda145
Reviewed-on: http://gerrit.cloudera.org:8080/14219
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <[email protected]>
---
src/kudu/client/client-test.cc | 11 +++++++++++
src/kudu/client/scan_batch.h | 17 +++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/src/kudu/client/client-test.cc b/src/kudu/client/client-test.cc
index cfc5d59..bc0de7e 100644
--- a/src/kudu/client/client-test.cc
+++ b/src/kudu/client/client-test.cc
@@ -5615,6 +5615,17 @@ TEST_F(ClientTest, TestBatchScanConstIterator) {
CHECK_EQ(ref_count, count);
}
+ // Check access to row via indirection operator *
+ // and member access through pointer operator ->
+ {
+ KuduScanBatch::const_iterator it(batch.begin());
+ ASSERT_TRUE(it != batch.end());
+ int32_t x = 0, y = 0;
+ ASSERT_OK((*it).GetInt32(0, &x));
+ ASSERT_OK(it->GetInt32(0, &y));
+ ASSERT_EQ(x, y);
+ }
+
{
KuduScanBatch::const_iterator it_pre(batch.begin());
KuduScanBatch::const_iterator it_post(batch.begin());
diff --git a/src/kudu/client/scan_batch.h b/src/kudu/client/scan_batch.h
index 6a127e2..fd211f5 100644
--- a/src/kudu/client/scan_batch.h
+++ b/src/kudu/client/scan_batch.h
@@ -162,6 +162,13 @@ class KUDU_EXPORT KuduScanBatch::RowPtr {
/// a properly-initialized value.
RowPtr() : schema_(NULL), row_data_(NULL) {}
+ /// Overloaded operator -> to support pointer trait
+ /// for access via const_iterator.
+
+ /// @return Pointer to the row
+ const RowPtr* operator->() const {
+ return this;
+ }
/// @param [in] col_name
/// Name of the column.
/// @return @c true iff the specified column of the row has @c NULL value.
@@ -334,6 +341,16 @@ class KUDU_EXPORT KuduScanBatch::const_iterator
return batch_->Row(idx_);
}
+ /// @note Since iterator does not keep current KuduScanBatch::RowPtr,
+ /// we cannot return pointer to it.
+ /// Instead we return KuduScanBatch::RowPtr,
+ /// which implements pointer operator ->
+
+ /// @return The row in the batch the iterator is pointing at.
+ KuduScanBatch::RowPtr operator->() const {
+ return batch_->Row(idx_);
+ }
+
/// Prefix increment operator: advances the iterator to the next position.
///
/// @return The reference to the iterator, pointing to the next position.