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

Function UnionFromFlatbuffer

cpp/src/arrow/ipc/metadata_internal.cc:169–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167// Union implementation
168
169Status UnionFromFlatbuffer(const flatbuf::Union* union_data,
170 const std::vector<std::shared_ptr<Field>>& children,
171 std::shared_ptr<DataType>* out) {
172 UnionMode::type mode =
173 (union_data->mode() == flatbuf::UnionMode::UnionMode_Sparse ? UnionMode::SPARSE
174 : UnionMode::DENSE);
175
176 std::vector<int8_t> type_codes;
177
178 const flatbuffers::Vector<int32_t>* fb_type_ids = union_data->typeIds();
179 if (fb_type_ids == nullptr) {
180 for (int8_t i = 0; i < static_cast<int8_t>(children.size()); ++i) {
181 type_codes.push_back(i);
182 }
183 } else {
184 for (int32_t id : (*fb_type_ids)) {
185 const auto type_code = static_cast<int8_t>(id);
186 if (id != type_code) {
187 return Status::Invalid("union type id out of bounds");
188 }
189 type_codes.push_back(type_code);
190 }
191 }
192
193 if (mode == UnionMode::SPARSE) {
194 ARROW_ASSIGN_OR_RAISE(*out, SparseUnionType::Make(children, std::move(type_codes)));
195 } else {
196 ARROW_ASSIGN_OR_RAISE(*out, DenseUnionType::Make(children, std::move(type_codes)));
197 }
198 return Status::OK();
199}
200
201#define INT_TO_FB_CASE(BIT_WIDTH, IS_SIGNED) \
202 *out_type = flatbuf::Type::Type_Int; \

Callers 1

Calls 7

push_backMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
InvalidFunction · 0.50
MakeFunction · 0.50
OKFunction · 0.50
modeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected