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

Function MakeWriteNode

cpp/src/arrow/dataset/file_base.cc:495–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493namespace {
494
495Result<acero::ExecNode*> MakeWriteNode(acero::ExecPlan* plan,
496 std::vector<acero::ExecNode*> inputs,
497 const acero::ExecNodeOptions& options) {
498 if (inputs.size() != 1) {
499 return Status::Invalid("Write SinkNode requires exactly 1 input, got ",
500 inputs.size());
501 }
502
503 const WriteNodeOptions write_node_options =
504 checked_cast<const WriteNodeOptions&>(options);
505 std::shared_ptr<Schema> custom_schema = write_node_options.custom_schema;
506 const std::shared_ptr<const KeyValueMetadata>& custom_metadata =
507 write_node_options.custom_metadata;
508 const FileSystemDatasetWriteOptions& write_options = write_node_options.write_options;
509
510 const std::shared_ptr<Schema>& input_schema = inputs[0]->output_schema();
511
512 if (custom_schema != nullptr) {
513 if (custom_metadata) {
514 return Status::TypeError(
515 "Do not provide both custom_metadata and custom_schema. If custom_schema is "
516 "used then custom_schema->metadata should be used instead of custom_metadata");
517 }
518
519 if (custom_schema->num_fields() != input_schema->num_fields()) {
520 return Status::TypeError(
521 "The provided custom_schema did not have the same number of fields as the "
522 "data. The custom schema can only be used to add metadata / nullability to "
523 "fields and cannot change the type or number of fields.");
524 }
525 for (int field_idx = 0; field_idx < input_schema->num_fields(); field_idx++) {
526 if (!input_schema->field(field_idx)->type()->Equals(
527 custom_schema->field(field_idx)->type())) {
528 return Status::TypeError("The provided custom_schema specified type ",
529 custom_schema->field(field_idx)->type()->ToString(),
530 " for field ", field_idx, "and the input data has type ",
531 input_schema->field(field_idx),
532 "The custom schema can only be used to add metadata / "
533 "nullability to fields and "
534 "cannot change the type or number of fields.");
535 }
536 }
537 }
538
539 if (custom_metadata) {
540 custom_schema = input_schema->WithMetadata(custom_metadata);
541 }
542
543 if (!write_options.partitioning) {
544 return Status::Invalid("Must provide partitioning");
545 }
546
547 std::shared_ptr<DatasetWritingSinkNodeConsumer> consumer =
548 std::make_shared<DatasetWritingSinkNodeConsumer>(custom_schema, write_options);
549
550 ARROW_ASSIGN_OR_RAISE(
551 auto node,
552 // to preserve order explicitly, sequence the exec batches

Callers

nothing calls this directly

Calls 9

InvalidFunction · 0.50
TypeErrorFunction · 0.50
sizeMethod · 0.45
num_fieldsMethod · 0.45
EqualsMethod · 0.45
typeMethod · 0.45
fieldMethod · 0.45
ToStringMethod · 0.45
WithMetadataMethod · 0.45

Tested by

no test coverage detected