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

Function TEST

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

Source from the content-addressed store, hash-verified

407#endif
408
409TEST(TestWriteCSV, EmptyBatchShouldNotPolluteOutput) {
410 auto schema = arrow::schema({field("col1", utf8())});
411 auto empty_batch = RecordBatchFromJSON(schema, "[]");
412 auto batch_a = RecordBatchFromJSON(schema, R"([{"col1": "a"}])");
413 auto batch_b = RecordBatchFromJSON(schema, R"([{"col1": "b"}])");
414
415 struct TestParam {
416 std::shared_ptr<Table> table;
417 std::string expected_output;
418 };
419
420 std::vector<TestParam> test_params = {
421 // Empty batch in the beginning
422 {Table::FromRecordBatches(schema, {empty_batch, batch_a, batch_b}).ValueOrDie(),
423 "\"col1\"\n\"a\"\n\"b\"\n"},
424 // Empty batch in the middle
425 {Table::FromRecordBatches(schema, {batch_a, empty_batch, batch_b}).ValueOrDie(),
426 "\"col1\"\n\"a\"\n\"b\"\n"},
427 // Empty batch in the end
428 {Table::FromRecordBatches(schema, {batch_a, batch_b, empty_batch}).ValueOrDie(),
429 "\"col1\"\n\"a\"\n\"b\"\n"},
430 };
431
432 for (const auto& param : test_params) {
433 ASSERT_OK_AND_ASSIGN(auto out, io::BufferOutputStream::Create());
434 ASSERT_OK(WriteCSV(*param.table, WriteOptions::Defaults(), out.get()));
435 ASSERT_OK_AND_ASSIGN(auto buffer, out->Finish());
436 EXPECT_EQ(buffer->ToString(), param.expected_output);
437 }
438}
439
440} // namespace csv
441} // namespace arrow

Callers

nothing calls this directly

Calls 8

RecordBatchFromJSONFunction · 0.85
WriteCSVFunction · 0.85
ValueOrDieMethod · 0.80
schemaFunction · 0.50
fieldFunction · 0.50
DefaultsFunction · 0.50
getMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected