MCPcopy Create free account
hub / github.com/apache/arrow / ToCsvStringUsingWriter

Method ToCsvStringUsingWriter

cpp/src/arrow/csv/writer_test.cc:324–342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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
345TEST_P(TestWriteCSV, TestWrite) {

Callers

nothing calls this directly

Calls 10

set_chunksizeMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.50
ReadNextMethod · 0.45
WriteRecordBatchMethod · 0.45
CloseMethod · 0.45
num_rowsMethod · 0.45
statsMethod · 0.45
FinishMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected