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

Method Deserialize

cpp/src/arrow/extension/variable_shape_tensor.cc:127–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127Result<std::shared_ptr<DataType>> VariableShapeTensorType::Deserialize(
128 std::shared_ptr<DataType> storage_type, const std::string& serialized_data) const {
129 if (storage_type->id() != Type::STRUCT) {
130 return Status::Invalid("Expected Struct storage type, got ",
131 storage_type->ToString());
132 }
133 if (storage_type->num_fields() != 2) {
134 return Status::Invalid("Expected Struct storage type with 2 fields, got ",
135 storage_type->num_fields());
136 }
137 if (storage_type->field(0)->type()->id() != Type::LIST) {
138 return Status::Invalid("Expected List storage type, got ",
139 storage_type->field(0)->type()->ToString());
140 }
141 if (storage_type->field(1)->type()->id() != Type::FIXED_SIZE_LIST) {
142 return Status::Invalid("Expected FixedSizeList storage type, got ",
143 storage_type->field(1)->type()->ToString());
144 }
145 if (internal::checked_cast<const FixedSizeListType&>(*storage_type->field(1)->type())
146 .value_type() != int32()) {
147 return Status::Invalid("Expected FixedSizeList value type int32, got ",
148 storage_type->field(1)->type()->ToString());
149 }
150
151 const auto value_type = storage_type->field(0)->type()->field(0)->type();
152 const int32_t ndim =
153 internal::checked_cast<const FixedSizeListType&>(*storage_type->field(1)->type())
154 .list_size();
155
156 simdjson::dom::parser parser;
157 ARROW_ASSIGN_OR_RAISE(auto object, internal::ParseJsonObject(parser, serialized_data));
158
159 ARROW_ASSIGN_OR_RAISE(auto permutation_value,
160 internal::GetOptionalJsonField(object, "permutation"));
161
162 std::vector<int64_t> permutation;
163 if (permutation_value.has_value()) {
164 ARROW_ASSIGN_OR_RAISE(permutation,
165 internal::GetJsonIntArray(*permutation_value, "permutation"));
166
167 if (permutation.size() != static_cast<size_t>(ndim)) {
168 return Status::Invalid("Invalid permutation");
169 }
170 RETURN_NOT_OK(internal::IsPermutationValid(permutation));
171 }
172
173 ARROW_ASSIGN_OR_RAISE(auto dim_names_value,
174 internal::GetOptionalJsonField(object, "dim_names"));
175
176 std::vector<std::string> dim_names;
177 if (dim_names_value.has_value()) {
178 ARROW_ASSIGN_OR_RAISE(dim_names,
179 internal::GetJsonStringArray(*dim_names_value, "dim_names"));
180
181 if (dim_names.size() != static_cast<size_t>(ndim)) {
182 return Status::Invalid("Invalid dim_names");
183 }
184 }

Callers

nothing calls this directly

Calls 15

ComputeStridesFunction · 0.85
SliceTensorBufferFunction · 0.85
is_fixed_widthFunction · 0.85
IsPermutationValidFunction · 0.85
resizeMethod · 0.80
ndimMethod · 0.80
push_backMethod · 0.80
MoveValueUnsafeMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
MakeFunction · 0.70
InvalidFunction · 0.50
idMethod · 0.45

Tested by

no test coverage detected