dahbka-lis opened a new issue, #47859:
URL: https://github.com/apache/arrow/issues/47859
### Describe the bug, including details regarding any error messages,
version, and platform.
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:
```cpp
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); // Error
```
The validation
[here](https://github.com/apache/arrow/blob/main/cpp/src/arrow/type.cc#L1232)
will not be passed because `type_codes` is empty for `fields.size() == 128`,
but `fields` is not empty.
Otherwise:
- I can create `dense_union` type with non-empty `type_codes` vector created
by std::iota(0, 128), check the example below.
- Unions from `pyarrow` support at most 128 codes and not 127.
```cpp
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); // OK
```
### Component(s)
C++
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]