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

Method Make

cpp/src/arrow/csv/writer.cc:506–537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

504class 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);

Callers

nothing calls this directly

Calls 14

CountQuotesFunction · 0.85
MakePopulatorFunction · 0.85
WriteHeaderMethod · 0.80
InvalidFunction · 0.50
ARROW_ASSIGN_OR_RAISEFunction · 0.50
AllocateBufferFunction · 0.50
ValidateMethod · 0.45
lengthMethod · 0.45
mutable_dataMethod · 0.45
dataMethod · 0.45
num_fieldsMethod · 0.45

Tested by

no test coverage detected