Fokko commented on code in PR #36846:
URL: https://github.com/apache/arrow/pull/36846#discussion_r1277708614
##########
cpp/src/arrow/type.cc:
##########
@@ -327,17 +707,30 @@ Result<std::shared_ptr<Field>> Field::MergeWith(const
Field& other,
return Copy();
}
- if (options.promote_nullability) {
- if (type()->Equals(other.type())) {
- return Copy()->WithNullable(nullable() || other.nullable());
+ auto maybe_promoted_type = MergeTypes(type_, other.type(), options);
+ if (!maybe_promoted_type.ok()) {
+ return maybe_promoted_type.status().WithMessage(
+ "Unable to merge: Field ", name(),
+ " has incompatible types: ", type()->ToString(), " vs ",
other.type()->ToString(),
+ ": ", maybe_promoted_type.status().message());
+ }
+ auto promoted_type = *std::move(maybe_promoted_type);
+ if (promoted_type) {
+ bool nullable = nullable_;
+ if (options.promote_nullability) {
+ nullable = nullable || other.nullable() || type_->id() == Type::NA ||
+ other.type()->id() == Type::NA;
+ } else if (nullable_ != other.nullable()) {
+ return Status::TypeError("Unable to merge: Field ", name(),
+ " has incompatible nullability: ", nullable_, "
vs ",
+ other.nullable());
}
- std::shared_ptr<Field> promoted = MaybePromoteNullTypes(*this, other);
- if (promoted) return promoted;
- }
- return Status::Invalid("Unable to merge: Field ", name(),
- " has incompatible types: ", type()->ToString(), " vs
",
- other.type()->ToString());
+ return std::make_shared<Field>(name_, promoted_type, nullable, metadata_);
+ }
+ return Status::TypeError("Unable to merge: Field ", name(),
Review Comment:
I would argue that this would be a `TypeError`, but I'm afraid we can't just
change this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]