| 756 | } |
| 757 | |
| 758 | Result<std::shared_ptr<DataType>> MergeTypes(std::shared_ptr<DataType> promoted_type, |
| 759 | std::shared_ptr<DataType> other_type, |
| 760 | const Field::MergeOptions& options) { |
| 761 | if (promoted_type->Equals(*other_type)) return promoted_type; |
| 762 | |
| 763 | bool promoted = false; |
| 764 | if (options.promote_nullability) { |
| 765 | if (promoted_type->id() == Type::NA) { |
| 766 | return other_type; |
| 767 | } else if (other_type->id() == Type::NA) { |
| 768 | return promoted_type; |
| 769 | } |
| 770 | } else if (promoted_type->id() == Type::NA || other_type->id() == Type::NA) { |
| 771 | return Status::TypeError( |
| 772 | "Cannot merge type with null unless promote_nullability=true"); |
| 773 | } |
| 774 | |
| 775 | if (options.promote_dictionary && is_dictionary(promoted_type->id()) && |
| 776 | is_dictionary(other_type->id())) { |
| 777 | return MergeDictionaryTypes(promoted_type, other_type, options); |
| 778 | } |
| 779 | |
| 780 | ARROW_ASSIGN_OR_RAISE(auto maybe_promoted, |
| 781 | MaybeMergeTemporalTypes(promoted_type, other_type, options)); |
| 782 | if (maybe_promoted) return maybe_promoted; |
| 783 | |
| 784 | ARROW_ASSIGN_OR_RAISE(maybe_promoted, |
| 785 | MaybeMergeNumericTypes(promoted_type, other_type, options)); |
| 786 | if (maybe_promoted) return maybe_promoted; |
| 787 | |
| 788 | ARROW_ASSIGN_OR_RAISE(maybe_promoted, |
| 789 | MaybeMergeBinaryTypes(promoted_type, other_type, options)); |
| 790 | if (maybe_promoted) return maybe_promoted; |
| 791 | |
| 792 | ARROW_ASSIGN_OR_RAISE(maybe_promoted, |
| 793 | MaybeMergeListTypes(promoted_type, other_type, options)); |
| 794 | if (maybe_promoted) return maybe_promoted; |
| 795 | |
| 796 | return promoted ? promoted_type : nullptr; |
| 797 | } |
| 798 | } // namespace |
| 799 | |
| 800 | Result<std::shared_ptr<Field>> Field::MergeWith(const Field& other, |
no test coverage detected