| 24 | namespace dataset { |
| 25 | |
| 26 | Status CheckProjectable(const Schema& from, const Schema& to) { |
| 27 | for (const auto& to_field : to.fields()) { |
| 28 | ARROW_ASSIGN_OR_RAISE(auto from_field, FieldRef(to_field->name()).GetOneOrNone(from)); |
| 29 | |
| 30 | if (from_field == nullptr) { |
| 31 | if (to_field->nullable()) continue; |
| 32 | |
| 33 | return Status::TypeError("field ", to_field->ToString(), |
| 34 | " is not nullable and does not exist in origin schema ", |
| 35 | from); |
| 36 | } |
| 37 | |
| 38 | if (from_field->type()->id() == Type::NA) { |
| 39 | // promotion from null to any type is supported |
| 40 | if (to_field->nullable()) continue; |
| 41 | |
| 42 | return Status::TypeError("field ", to_field->ToString(), |
| 43 | " is not nullable but has type ", NullType(), |
| 44 | " in origin schema ", from); |
| 45 | } |
| 46 | |
| 47 | if (!from_field->type()->Equals(to_field->type())) { |
| 48 | return Status::TypeError("fields had matching names but differing types. From: ", |
| 49 | from_field->ToString(), " To: ", to_field->ToString()); |
| 50 | } |
| 51 | |
| 52 | if (from_field->nullable() && !to_field->nullable()) { |
| 53 | return Status::TypeError("field ", to_field->ToString(), |
| 54 | " is not nullable but is not required in origin schema ", |
| 55 | from); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return Status::OK(); |
| 60 | } |
| 61 | |
| 62 | } // namespace dataset |
| 63 | } // namespace arrow |