| 504 | class CSVWriterImpl : public ipc::RecordBatchWriter { |
| 505 | public: |
| 506 | static Result<std::shared_ptr<CSVWriterImpl>> Make( |
| 507 | io::OutputStream* sink, std::shared_ptr<io::OutputStream> owned_sink, |
| 508 | std::shared_ptr<Schema> schema, const WriteOptions& options) { |
| 509 | RETURN_NOT_OK(options.Validate()); |
| 510 | // Reject null string values that contain quotes. |
| 511 | if (CountQuotes(options.null_string) != 0) { |
| 512 | return Status::Invalid("Null string cannot contain quotes."); |
| 513 | } |
| 514 | |
| 515 | ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Buffer> null_string, |
| 516 | arrow::AllocateBuffer(options.null_string.length())); |
| 517 | memcpy(null_string->mutable_data(), options.null_string.data(), |
| 518 | options.null_string.length()); |
| 519 | |
| 520 | std::vector<std::unique_ptr<ColumnPopulator>> populators(schema->num_fields()); |
| 521 | std::string delimiter(1, options.delimiter); |
| 522 | for (int col = 0; col < schema->num_fields(); col++) { |
| 523 | const std::string& end_chars = |
| 524 | col < schema->num_fields() - 1 ? delimiter : options.eol; |
| 525 | ARROW_ASSIGN_OR_RAISE( |
| 526 | populators[col], |
| 527 | MakePopulator(*schema->field(col), end_chars, options.delimiter, null_string, |
| 528 | options.quoting_style, options.io_context.pool())); |
| 529 | } |
| 530 | auto writer = std::make_shared<CSVWriterImpl>( |
| 531 | sink, std::move(owned_sink), std::move(schema), std::move(populators), options); |
| 532 | RETURN_NOT_OK(writer->PrepareForContentsWrite()); |
| 533 | if (options.include_header) { |
| 534 | RETURN_NOT_OK(writer->WriteHeader()); |
| 535 | } |
| 536 | return writer; |
| 537 | } |
| 538 | |
| 539 | Status WriteRecordBatch(const RecordBatch& batch) override { |
| 540 | RecordBatchIterator iterator = RecordBatchSliceIterator(batch, options_.batch_size); |
nothing calls this directly
no test coverage detected