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

Method Deserialize

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

Source from the content-addressed store, hash-verified

109}
110
111Result<std::shared_ptr<DataType>> FixedShapeTensorType::Deserialize(
112 std::shared_ptr<DataType> storage_type, const std::string& serialized_data) const {
113 if (storage_type->id() != Type::FIXED_SIZE_LIST) {
114 return Status::Invalid("Expected FixedSizeList storage type, got ",
115 storage_type->ToString());
116 }
117
118 auto fsl_type = internal::checked_pointer_cast<FixedSizeListType>(storage_type);
119 auto value_type = fsl_type->value_type();
120
121 simdjson::dom::parser parser;
122 ARROW_ASSIGN_OR_RAISE(auto object, internal::ParseJsonObject(parser, serialized_data));
123
124 ARROW_ASSIGN_OR_RAISE(auto shape_value,
125 internal::ResolveSimdjsonResult(object.at_key("shape"),
126 "Invalid serialized JSON data"));
127 ARROW_ASSIGN_OR_RAISE(auto shape, internal::GetJsonIntArray(shape_value, "shape"));
128 ARROW_ASSIGN_OR_RAISE(auto permutation_value,
129 internal::GetOptionalJsonField(object, "permutation"));
130
131 std::vector<int64_t> permutation;
132 if (permutation_value.has_value()) {
133 ARROW_ASSIGN_OR_RAISE(permutation,
134 internal::GetJsonIntArray(*permutation_value, "permutation"));
135
136 if (shape.size() != permutation.size()) {
137 return Status::Invalid("Invalid permutation");
138 }
139 RETURN_NOT_OK(internal::IsPermutationValid(permutation));
140 }
141
142 ARROW_ASSIGN_OR_RAISE(auto dim_names_value,
143 internal::GetOptionalJsonField(object, "dim_names"));
144
145 std::vector<std::string> dim_names;
146 if (dim_names_value.has_value()) {
147 ARROW_ASSIGN_OR_RAISE(dim_names,
148 internal::GetJsonStringArray(*dim_names_value, "dim_names"));
149
150 if (shape.size() != dim_names.size()) {
151 return Status::Invalid("Invalid dim_names");
152 }
153 }
154
155 // Validate product of shape dimensions matches storage type list_size.
156 // This check is intentionally after field parsing so that metadata-level errors
157 // (type mismatches, size mismatches) are reported first.
158 ARROW_ASSIGN_OR_RAISE(auto ext_type, FixedShapeTensorType::Make(
159 value_type, shape, permutation, dim_names));
160
161 const auto& fst_type = internal::checked_cast<const FixedShapeTensorType&>(*ext_type);
162
163 ARROW_ASSIGN_OR_RAISE(const int64_t expected_size,
164 internal::ComputeShapeProduct(fst_type.shape()));
165
166 if (expected_size != fsl_type->list_size()) {
167 return Status::Invalid("Product of shape dimensions (", expected_size,
168 ") does not match FixedSizeList size (", fsl_type->list_size(),

Callers

nothing calls this directly

Calls 15

ComputeShapeProductFunction · 0.85
is_fixed_widthFunction · 0.85
ComputeStridesFunction · 0.85
SliceTensorBufferFunction · 0.85
ArgSortFunction · 0.85
fixed_shape_tensorFunction · 0.85
FromArraysFunction · 0.85
forFunction · 0.85
SliceBufferSafeFunction · 0.85
resizeMethod · 0.80
ndimMethod · 0.80
emplace_backMethod · 0.80

Tested by

no test coverage detected