MCPcopy Create free account
hub / github.com/apache/arrow / Deserialize

Method Deserialize

cpp/src/arrow/extension/fixed_shape_tensor.cc:107–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107Result<std::shared_ptr<DataType>> FixedShapeTensorType::Deserialize(
108 std::shared_ptr<DataType> storage_type, const std::string& serialized_data) const {
109 if (storage_type->id() != Type::FIXED_SIZE_LIST) {
110 return Status::Invalid("Expected FixedSizeList storage type, got ",
111 storage_type->ToString());
112 }
113 auto fsl_type = internal::checked_pointer_cast<FixedSizeListType>(storage_type);
114 auto value_type = fsl_type->value_type();
115 rj::Document document;
116 if (document.Parse(serialized_data.data(), serialized_data.length()).HasParseError() ||
117 !document.IsObject() || !document.HasMember("shape") ||
118 !document["shape"].IsArray()) {
119 return Status::Invalid("Invalid serialized JSON data: ", serialized_data);
120 }
121
122 std::vector<int64_t> shape;
123 for (const auto& x : document["shape"].GetArray()) {
124 if (!x.IsInt64()) {
125 return Status::Invalid("shape must contain integers, got ",
126 internal::JsonTypeName(x));
127 }
128 shape.emplace_back(x.GetInt64());
129 }
130
131 std::vector<int64_t> permutation;
132 if (document.HasMember("permutation")) {
133 const auto& json_permutation = document["permutation"];
134 if (!json_permutation.IsArray()) {
135 return Status::Invalid("permutation must be an array, got ",
136 internal::JsonTypeName(json_permutation));
137 }
138 for (const auto& x : json_permutation.GetArray()) {
139 if (!x.IsInt64()) {
140 return Status::Invalid("permutation must contain integers, got ",
141 internal::JsonTypeName(x));
142 }
143 permutation.emplace_back(x.GetInt64());
144 }
145 if (shape.size() != permutation.size()) {
146 return Status::Invalid("Invalid permutation");
147 }
148 RETURN_NOT_OK(internal::IsPermutationValid(permutation));
149 }
150 std::vector<std::string> dim_names;
151 if (document.HasMember("dim_names")) {
152 const auto& json_dim_names = document["dim_names"];
153 if (!json_dim_names.IsArray()) {
154 return Status::Invalid("dim_names must be an array, got ",
155 internal::JsonTypeName(json_dim_names));
156 }
157 for (const auto& x : json_dim_names.GetArray()) {
158 if (!x.IsString()) {
159 return Status::Invalid("dim_names must contain strings, got ",
160 internal::JsonTypeName(x));
161 }
162 dim_names.emplace_back(x.GetString());
163 }
164 if (shape.size() != dim_names.size()) {

Callers

nothing calls this directly

Calls 14

IsPermutationValidFunction · 0.85
emplace_backMethod · 0.80
JsonTypeNameFunction · 0.70
InvalidFunction · 0.50
idMethod · 0.45
ToStringMethod · 0.45
value_typeMethod · 0.45
ParseMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45
GetArrayMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected