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