| 121 | } |
| 122 | |
| 123 | Result<std::shared_ptr<DataType>> VariableShapeTensorType::Deserialize( |
| 124 | std::shared_ptr<DataType> storage_type, const std::string& serialized_data) const { |
| 125 | if (storage_type->id() != Type::STRUCT) { |
| 126 | return Status::Invalid("Expected Struct storage type, got ", |
| 127 | storage_type->ToString()); |
| 128 | } |
| 129 | if (storage_type->num_fields() != 2) { |
| 130 | return Status::Invalid("Expected Struct storage type with 2 fields, got ", |
| 131 | storage_type->num_fields()); |
| 132 | } |
| 133 | if (storage_type->field(0)->type()->id() != Type::LIST) { |
| 134 | return Status::Invalid("Expected List storage type, got ", |
| 135 | storage_type->field(0)->type()->ToString()); |
| 136 | } |
| 137 | if (storage_type->field(1)->type()->id() != Type::FIXED_SIZE_LIST) { |
| 138 | return Status::Invalid("Expected FixedSizeList storage type, got ", |
| 139 | storage_type->field(1)->type()->ToString()); |
| 140 | } |
| 141 | if (internal::checked_cast<const FixedSizeListType&>(*storage_type->field(1)->type()) |
| 142 | .value_type() != int32()) { |
| 143 | return Status::Invalid("Expected FixedSizeList value type int32, got ", |
| 144 | storage_type->field(1)->type()->ToString()); |
| 145 | } |
| 146 | |
| 147 | const auto value_type = storage_type->field(0)->type()->field(0)->type(); |
| 148 | const int32_t ndim = |
| 149 | internal::checked_cast<const FixedSizeListType&>(*storage_type->field(1)->type()) |
| 150 | .list_size(); |
| 151 | |
| 152 | rj::Document document; |
| 153 | if (document.Parse(serialized_data.data(), serialized_data.length()).HasParseError() || |
| 154 | !document.IsObject()) { |
| 155 | return Status::Invalid("Invalid serialized JSON data: ", serialized_data); |
| 156 | } |
| 157 | |
| 158 | std::vector<int64_t> permutation; |
| 159 | if (document.HasMember("permutation")) { |
| 160 | const auto& json_permutation = document["permutation"]; |
| 161 | if (!json_permutation.IsArray()) { |
| 162 | return Status::Invalid("permutation must be an array, got ", |
| 163 | internal::JsonTypeName(json_permutation)); |
| 164 | } |
| 165 | permutation.reserve(ndim); |
| 166 | for (const auto& x : json_permutation.GetArray()) { |
| 167 | if (!x.IsInt64()) { |
| 168 | return Status::Invalid("permutation must contain integers, got ", |
| 169 | internal::JsonTypeName(x)); |
| 170 | } |
| 171 | permutation.emplace_back(x.GetInt64()); |
| 172 | } |
| 173 | RETURN_NOT_OK(internal::IsPermutationValid(permutation)); |
| 174 | } |
| 175 | std::vector<std::string> dim_names; |
| 176 | if (document.HasMember("dim_names")) { |
| 177 | const auto& json_dim_names = document["dim_names"]; |
| 178 | if (!json_dim_names.IsArray()) { |
| 179 | return Status::Invalid("dim_names must be an array, got ", |
| 180 | internal::JsonTypeName(json_dim_names)); |
nothing calls this directly
no test coverage detected