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

Method AddField

cpp/src/arrow/type.cc:2527–2571  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2525 field_merge_options_(field_merge_options) {}
2526
2527 Status AddField(const std::shared_ptr<Field>& field) {
2528 DCHECK_NE(field, nullptr);
2529
2530 // Short-circuit, no lookup needed.
2531 if (policy_ == CONFLICT_APPEND) {
2532 return AppendField(field);
2533 }
2534
2535 auto name = field->name();
2536 constexpr int kNotFound = -1;
2537 constexpr int kDuplicateFound = -2;
2538 auto i = LookupNameIndex<kNotFound, kDuplicateFound>(name_to_index_, name);
2539
2540 if (i == kNotFound) {
2541 return AppendField(field);
2542 }
2543
2544 // From this point, there's one or more field in the builder that exists with
2545 // the same name.
2546
2547 if (policy_ == CONFLICT_IGNORE) {
2548 // The ignore policy is more generous when there's duplicate in the builder.
2549 return Status::OK();
2550 } else if (policy_ == CONFLICT_ERROR) {
2551 return Status::Invalid("Duplicate found, policy dictate to treat as an error");
2552 }
2553
2554 if (i == kDuplicateFound) {
2555 // Cannot merge/replace when there's more than one field in the builder
2556 // because we can't decide which to merge/replace.
2557 return Status::Invalid("Cannot merge field ", name,
2558 " more than one field with same name exists");
2559 }
2560
2561 DCHECK_GE(i, 0);
2562
2563 if (policy_ == CONFLICT_REPLACE) {
2564 fields_[i] = field;
2565 } else if (policy_ == CONFLICT_MERGE) {
2566 ARROW_ASSIGN_OR_RAISE(fields_[i],
2567 fields_[i]->MergeWith(field, field_merge_options_));
2568 }
2569
2570 return Status::OK();
2571 }
2572
2573 Status AppendField(const std::shared_ptr<Field>& field) {
2574 const std::string_view name = field->name();

Callers

nothing calls this directly

Calls 5

MergeWithMethod · 0.80
OKFunction · 0.70
InvalidFunction · 0.70
ARROW_ASSIGN_OR_RAISEFunction · 0.50
nameMethod · 0.45

Tested by

no test coverage detected