diff --git a/cpp/src/arrow/io/buffered.cc b/cpp/src/arrow/io/buffered.cc index 16b969617e58e..cc9b6b3c6c3e1 100644 --- a/cpp/src/arrow/io/buffered.cc +++ b/cpp/src/arrow/io/buffered.cc @@ -144,6 +144,8 @@ class BufferedOutputStream::Impl : public BufferedBase { RETURN_NOT_OK(FlushUnlocked()); DCHECK_EQ(buffer_pos_, 0); if (nbytes >= buffer_size_) { + // Invalidate cached raw pos + raw_pos_ = -1; // Direct write if (buffer) { return raw_->Write(buffer); diff --git a/cpp/src/arrow/io/buffered_test.cc b/cpp/src/arrow/io/buffered_test.cc index 1fefc261b1d33..c1bc8931b4375 100644 --- a/cpp/src/arrow/io/buffered_test.cc +++ b/cpp/src/arrow/io/buffered_test.cc @@ -296,6 +296,19 @@ TEST_F(TestBufferedOutputStream, Tell) { AssertTell(0); } +TEST_F(TestBufferedOutputStream, Tell2) { + OpenBuffered(); + AssertTell(0); + + const std::string datastr = GenerateRandomData(10000); + const char* d = datastr.data(); + + ASSERT_OK(buffered_->Write(d, 5000)); + AssertTell(5000); + + ASSERT_OK(buffered_->Close()); +} + TEST_F(TestBufferedOutputStream, TruncatesFile) { OpenBuffered();