You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@parquet.apache.org by we...@apache.org on 2016/04/22 16:24:45 UTC

parquet-cpp git commit: PARQUET-587: Implement BufferReader::Read(int64_t, uint8_t*)

Repository: parquet-cpp
Updated Branches:
  refs/heads/master 49a5c1a8c -> aa31d025d


PARQUET-587: Implement BufferReader::Read(int64_t,uint8_t*)

 * Add unit test for BufferReader

Author: Uwe L. Korn <uw...@xhochy.com>

Closes #88 from xhochy/parquet-587 and squashes the following commits:

f34d8b7 [Uwe L. Korn] Test reading past the end of the buffer
623f9cd [Uwe L. Korn] Implement BufferReader::Read(int64_t,uint8_t*)


Project: http://git-wip-us.apache.org/repos/asf/parquet-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/parquet-cpp/commit/aa31d025
Tree: http://git-wip-us.apache.org/repos/asf/parquet-cpp/tree/aa31d025
Diff: http://git-wip-us.apache.org/repos/asf/parquet-cpp/diff/aa31d025

Branch: refs/heads/master
Commit: aa31d025d0018aee94cc679c3aea56cfa884bc94
Parents: 49a5c1a
Author: Uwe L. Korn <uw...@xhochy.com>
Authored: Fri Apr 22 10:24:31 2016 -0400
Committer: Wes McKinney <we...@apache.org>
Committed: Fri Apr 22 10:24:31 2016 -0400

----------------------------------------------------------------------
 src/parquet/util/input-output-test.cc | 31 ++++++++++++++++++++++++++++++
 src/parquet/util/input.cc             |  6 ++++--
 2 files changed, 35 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/parquet-cpp/blob/aa31d025/src/parquet/util/input-output-test.cc
----------------------------------------------------------------------
diff --git a/src/parquet/util/input-output-test.cc b/src/parquet/util/input-output-test.cc
index 86af9bc..3e15183 100644
--- a/src/parquet/util/input-output-test.cc
+++ b/src/parquet/util/input-output-test.cc
@@ -50,6 +50,37 @@ TEST(TestInMemoryOutputStream, Basics) {
   ASSERT_TRUE(data_buf.Equals(*buffer));
 }
 
+TEST(TestBufferedReader, Basics) {
+  std::vector<uint8_t> data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
+  auto buffer = std::make_shared<Buffer>(data.data(), data.size());
+  BufferReader reader(buffer);
+
+  uint8_t out[4];
+  ASSERT_EQ(4, reader.Read(4, out));
+  ASSERT_EQ(4, reader.Tell());
+  ASSERT_EQ(0, out[0]);
+  ASSERT_EQ(1, out[1]);
+  ASSERT_EQ(2, out[2]);
+  ASSERT_EQ(3, out[3]);
+
+  reader.Seek(8);
+  ASSERT_EQ(8, reader.Tell());
+
+  auto out_buffer = reader.Read(5);
+  ASSERT_EQ(8, out_buffer->data()[0]);
+  ASSERT_EQ(9, out_buffer->data()[1]);
+  ASSERT_EQ(10, out_buffer->data()[2]);
+  ASSERT_EQ(11, out_buffer->data()[3]);
+  ASSERT_EQ(12, out_buffer->data()[4]);
+
+  // Read past the end of the buffer
+  ASSERT_EQ(13, reader.Tell());
+  ASSERT_EQ(0, reader.Read(4, out));
+  ASSERT_EQ(0, reader.Read(4)->size());
+
+  reader.Close();
+}
+
 static bool file_exists(const std::string& path) {
   return std::ifstream(path.c_str()).good();
 }

http://git-wip-us.apache.org/repos/asf/parquet-cpp/blob/aa31d025/src/parquet/util/input.cc
----------------------------------------------------------------------
diff --git a/src/parquet/util/input.cc b/src/parquet/util/input.cc
index 245aac3..2a0eda3 100644
--- a/src/parquet/util/input.cc
+++ b/src/parquet/util/input.cc
@@ -199,8 +199,10 @@ void BufferReader::Seek(int64_t pos) {
 }
 
 int64_t BufferReader::Read(int64_t nbytes, uint8_t* out) {
-  ParquetException::NYI("not implemented");
-  return 0;
+  int64_t bytes_available = std::min(nbytes, size_ - pos_);
+  memcpy(out, Head(), bytes_available);
+  pos_ += bytes_available;
+  return bytes_available;
 }
 
 std::shared_ptr<Buffer> BufferReader::Read(int64_t nbytes) {