| 407 | #endif |
| 408 | |
| 409 | TEST(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 |
nothing calls this directly
no test coverage detected