| 322 | } |
| 323 | |
| 324 | Result<std::string> ToCsvStringUsingWriter(const Table& data, |
| 325 | const WriteOptions& options) { |
| 326 | std::shared_ptr<io::BufferOutputStream> out; |
| 327 | ARROW_ASSIGN_OR_RAISE(out, io::BufferOutputStream::Create()); |
| 328 | // Write row-by-row |
| 329 | ARROW_ASSIGN_OR_RAISE(auto writer, MakeCSVWriter(out, data.schema(), options)); |
| 330 | TableBatchReader reader(data); |
| 331 | reader.set_chunksize(1); |
| 332 | std::shared_ptr<RecordBatch> batch; |
| 333 | RETURN_NOT_OK(reader.ReadNext(&batch)); |
| 334 | while (batch != nullptr) { |
| 335 | RETURN_NOT_OK(writer->WriteRecordBatch(*batch)); |
| 336 | RETURN_NOT_OK(reader.ReadNext(&batch)); |
| 337 | } |
| 338 | RETURN_NOT_OK(writer->Close()); |
| 339 | EXPECT_EQ(data.num_rows(), writer->stats().num_record_batches); |
| 340 | ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Buffer> buffer, out->Finish()); |
| 341 | return std::string(reinterpret_cast<const char*>(buffer->data()), buffer->size()); |
| 342 | } |
| 343 | }; |
| 344 | |
| 345 | TEST_P(TestWriteCSV, TestWrite) { |
nothing calls this directly
no test coverage detected