Repository: arrow Updated Branches: refs/heads/master ac540758c -> 2a12482b2
ARROW-1094: [C++] Always truncate buffer read in ReadableFile::Read if actual number of bytes less than request Author: Wes McKinney <wes.mckin...@twosigma.com> Closes #737 from wesm/ARROW-1094 and squashes the following commits: fcb613fb [Wes McKinney] Always truncate buffer read in ReadableFile::Read if less than requested Project: http://git-wip-us.apache.org/repos/asf/arrow/repo Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/2a12482b Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/2a12482b Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/2a12482b Branch: refs/heads/master Commit: 2a12482b21df0f28bfc53fca114795f4f74d1617 Parents: ac54075 Author: Wes McKinney <wes.mckin...@twosigma.com> Authored: Tue Jun 6 16:52:45 2017 -0400 Committer: Wes McKinney <wes.mckin...@twosigma.com> Committed: Tue Jun 6 16:52:45 2017 -0400 ---------------------------------------------------------------------- cpp/src/arrow/io/file.cc | 5 +---- cpp/src/arrow/io/io-file-test.cc | 9 +++++++++ cpp/src/arrow/ipc/writer.cc | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/arrow/blob/2a12482b/cpp/src/arrow/io/file.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/io/file.cc b/cpp/src/arrow/io/file.cc index eb4b9fc..c4c797c 100644 --- a/cpp/src/arrow/io/file.cc +++ b/cpp/src/arrow/io/file.cc @@ -412,10 +412,7 @@ class ReadableFile::ReadableFileImpl : public OSFile { int64_t bytes_read = 0; RETURN_NOT_OK(Read(nbytes, &bytes_read, buffer->mutable_data())); - - // XXX: heuristic - if (bytes_read < nbytes / 2) { RETURN_NOT_OK(buffer->Resize(bytes_read)); } - + if (bytes_read < nbytes) { RETURN_NOT_OK(buffer->Resize(bytes_read)); } *out = buffer; return Status::OK(); } http://git-wip-us.apache.org/repos/asf/arrow/blob/2a12482b/cpp/src/arrow/io/io-file-test.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/io/io-file-test.cc b/cpp/src/arrow/io/io-file-test.cc index a5784de..3450bae 100644 --- a/cpp/src/arrow/io/io-file-test.cc +++ b/cpp/src/arrow/io/io-file-test.cc @@ -251,6 +251,15 @@ TEST_F(TestReadableFile, Read) { ASSERT_OK(file_->Read(10, &bytes_read, buffer)); ASSERT_EQ(4, bytes_read); ASSERT_EQ(0, std::memcmp(buffer, "data", 4)); + + // Test incomplete read, ARROW-1094 + std::shared_ptr<Buffer> buf; + int64_t size; + ASSERT_OK(file_->GetSize(&size)); + + ASSERT_OK(file_->Seek(1)); + ASSERT_OK(file_->Read(size, &buf)); + ASSERT_EQ(size - 1, buf->size()); } TEST_F(TestReadableFile, ReadAt) { http://git-wip-us.apache.org/repos/asf/arrow/blob/2a12482b/cpp/src/arrow/ipc/writer.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/ipc/writer.cc b/cpp/src/arrow/ipc/writer.cc index 4f5edf2..5d4b94a 100644 --- a/cpp/src/arrow/ipc/writer.cc +++ b/cpp/src/arrow/ipc/writer.cc @@ -757,8 +757,8 @@ class RecordBatchFileWriter::RecordBatchFileWriterImpl Status Start() override { // It is only necessary to align to 8-byte boundary at the start of the file - RETURN_NOT_OK(Write(reinterpret_cast<const uint8_t*>(kArrowMagicBytes), - strlen(kArrowMagicBytes))); + RETURN_NOT_OK(Write( + reinterpret_cast<const uint8_t*>(kArrowMagicBytes), strlen(kArrowMagicBytes))); RETURN_NOT_OK(Align(8)); // We write the schema at the start of the file (and the end). This also