| 1049 | } |
| 1050 | |
| 1051 | Result<std::shared_ptr<DataType>> MapType::Make(std::shared_ptr<Field> value_field, |
| 1052 | bool keys_sorted) { |
| 1053 | const auto& value_type = *value_field->type(); |
| 1054 | if (value_field->nullable() || value_type.id() != Type::STRUCT) { |
| 1055 | return Status::TypeError("Map entry field should be non-nullable struct"); |
| 1056 | } |
| 1057 | const auto& struct_type = checked_cast<const StructType&>(value_type); |
| 1058 | if (struct_type.num_fields() != 2) { |
| 1059 | return Status::TypeError("Map entry field should have two children (got ", |
| 1060 | struct_type.num_fields(), ")"); |
| 1061 | } |
| 1062 | if (struct_type.field(0)->nullable()) { |
| 1063 | return Status::TypeError("Map key field should be non-nullable"); |
| 1064 | } |
| 1065 | return std::make_shared<MapType>(std::move(value_field), keys_sorted); |
| 1066 | } |
| 1067 | |
| 1068 | std::string MapType::ToString(bool show_metadata) const { |
| 1069 | std::stringstream s; |