Skip to content

Commit

Permalink
ARROW-6724: [C++] Allow simpler BufferOutputStream creation
Browse files Browse the repository at this point in the history
Make the initial capacity argument optional.

Closes apache#6327 from pitrou/ARROW-6724-bufferoutstream-simpler-ctor and squashes the following commits:

b563f46 <Antoine Pitrou> ARROW-6724:  Allow simpler BufferOutputStream creation

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Micah Kornfield <emkornfield@gmail.com>
  • Loading branch information
pitrou authored and emkornfield committed Feb 3, 2020
1 parent 49aada2 commit af24bb7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
7 changes: 2 additions & 5 deletions cpp/src/arrow/dataset/file_ipc_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@
namespace arrow {
namespace dataset {

constexpr int64_t kDefaultOutputStreamSize = 1024;
constexpr int64_t kBatchSize = 1UL << 12;
constexpr int64_t kBatchRepetitions = 1 << 5;
constexpr int64_t kNumRows = kBatchSize * kBatchRepetitions;

class ArrowIpcWriterMixin : public ::testing::Test {
public:
std::shared_ptr<Buffer> Write(std::vector<RecordBatchReader*> readers) {
EXPECT_OK_AND_ASSIGN(auto sink, io::BufferOutputStream::Create(
kDefaultOutputStreamSize, default_memory_pool()));
EXPECT_OK_AND_ASSIGN(auto sink, io::BufferOutputStream::Create());
auto writer_schema = readers[0]->schema();

EXPECT_OK_AND_ASSIGN(auto writer,
Expand All @@ -69,8 +67,7 @@ class ArrowIpcWriterMixin : public ::testing::Test {
}

std::shared_ptr<Buffer> Write(const Table& table) {
EXPECT_OK_AND_ASSIGN(auto sink, io::BufferOutputStream::Create(
kDefaultOutputStreamSize, default_memory_pool()));
EXPECT_OK_AND_ASSIGN(auto sink, io::BufferOutputStream::Create());

EXPECT_OK_AND_ASSIGN(auto writer,
ipc::RecordBatchFileWriter::Open(sink.get(), table.schema()));
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/extension_type_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ TEST_F(TestExtensionType, ExtensionTypeTest) {

auto RoundtripBatch = [](const std::shared_ptr<RecordBatch>& batch,
std::shared_ptr<RecordBatch>* out) {
ASSERT_OK_AND_ASSIGN(auto out_stream, io::BufferOutputStream::Create(1024));
ASSERT_OK_AND_ASSIGN(auto out_stream, io::BufferOutputStream::Create());
ASSERT_OK(ipc::WriteRecordBatchStream({batch}, ipc::IpcOptions::Defaults(),
out_stream.get()));

Expand Down Expand Up @@ -255,7 +255,7 @@ TEST_F(TestExtensionType, UnrecognizedExtension) {

// Write full IPC stream including schema, then unregister type, then read
// and ensure that a plain instance of the storage type is created
ASSERT_OK_AND_ASSIGN(auto out_stream, io::BufferOutputStream::Create(1024));
ASSERT_OK_AND_ASSIGN(auto out_stream, io::BufferOutputStream::Create());
ASSERT_OK(ipc::WriteRecordBatchStream({batch}, ipc::IpcOptions::Defaults(),
out_stream.get()));

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/io/compressed_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void CheckCompressedInputStream(Codec* codec, const std::vector<uint8_t>& data)
void CheckCompressedOutputStream(Codec* codec, const std::vector<uint8_t>& data,
bool do_flush) {
// Create compressed output stream
ASSERT_OK_AND_ASSIGN(auto buffer_writer, BufferOutputStream::Create(1024));
ASSERT_OK_AND_ASSIGN(auto buffer_writer, BufferOutputStream::Create());
ASSERT_OK_AND_ASSIGN(auto stream, CompressedOutputStream::Make(codec, buffer_writer));
ASSERT_OK_AND_EQ(0, stream->Tell());

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/io/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ARROW_EXPORT BufferOutputStream : public OutputStream {
/// \param[in,out] pool a MemoryPool to use for allocations
/// \return the created stream
static Result<std::shared_ptr<BufferOutputStream>> Create(
int64_t initial_capacity, MemoryPool* pool = default_memory_pool());
int64_t initial_capacity = 4096, MemoryPool* pool = default_memory_pool());

ARROW_DEPRECATED("Use Result-returning overload")
static Status Create(int64_t initial_capacity, MemoryPool* pool,
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/ipc/feather_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void CheckBatches(const RecordBatch& expected, const RecordBatch& result) {
class TestTableReader : public ::testing::Test {
public:
void SetUp() {
ASSERT_OK_AND_ASSIGN(stream_, io::BufferOutputStream::Create(1024));
ASSERT_OK_AND_ASSIGN(stream_, io::BufferOutputStream::Create());
ASSERT_OK(TableWriter::Open(stream_, &writer_));
}

Expand Down Expand Up @@ -356,7 +356,7 @@ TEST_F(TestTableReader, ReadNames) {
class TestTableWriter : public ::testing::Test {
public:
void SetUp() {
ASSERT_OK_AND_ASSIGN(stream_, io::BufferOutputStream::Create(1024));
ASSERT_OK_AND_ASSIGN(stream_, io::BufferOutputStream::Create());
ASSERT_OK(TableWriter::Open(stream_, &writer_));
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/parquet/reader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ TEST(TestFileReader, BufferedReads) {
std::shared_ptr<WriterProperties> writer_props =
WriterProperties::Builder().write_batch_size(64)->data_pagesize(128)->build();

ASSERT_OK_AND_ASSIGN(auto out_file, arrow::io::BufferOutputStream::Create(1024));
ASSERT_OK_AND_ASSIGN(auto out_file, arrow::io::BufferOutputStream::Create());
std::shared_ptr<ParquetFileWriter> file_writer =
ParquetFileWriter::Open(out_file, schema, writer_props);

Expand Down

0 comments on commit af24bb7

Please sign in to comment.