-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Closed
Copy link
Description
There is a bug for creating union types with empty type_codes. If fields.size() == 128 (kMaxTypeCode + 1) and type_codes is empty, static_cast<int8_t> returns -128 and internal::Iota generates an empty vector of type codes, but the expected vector is [0, 1, 2, ..., 127], where 127 is kMaxTypeCode.
Example:
std::vector<std::shared_ptr<Field>> fields;
for (int32_t i = 0; i <= UnionType::kMaxTypeCode; i++) {
fields.push_back(field(std::to_string(i), int32()));
}
auto type = dense_union(fields); // ErrorThe validation here will not be passed because type_codes is empty for fields.size() == 128, but fields is not empty.
Otherwise:
- I can create
dense_uniontype with non-emptytype_codesvector created by std::iota(0, 128), check the example below. - Unions from
pyarrowsupport at most 128 codes and not 127.
std::vector<std::shared_ptr<Field>> fields;
for (int32_t i = 0; i <= UnionType::kMaxTypeCode; i++) {
fields.push_back(field(std::to_string(i), int32()));
}
std::vector<int8_t> type_codes(fields.size());
std::iota(type_codes.begin(), type_codes.end(), 0);
auto type = dense_union(fields, type_codes); // OKComponent(s)
C++