bkietz commented on code in PR #36018:
URL: https://github.com/apache/arrow/pull/36018#discussion_r1254369336
##########
cpp/src/arrow/array/data.cc:
##########
@@ -384,26 +382,31 @@ void ArraySpan::FillFromScalar(const Scalar& value) {
this->child_data[i].FillFromScalar(*scalar.value[i]);
}
} else if (is_union(type_id)) {
+ // Dense union needs scratch space to store both offsets and a type code
+ struct UnionScratchSpace {
+ alignas(int64_t) uint8_t type_code;
+ alignas(int64_t) uint8_t offsets[sizeof(int32_t) * 2];
+ };
+ static_assert(sizeof(UnionScratchSpace) <=
sizeof(UnionScalar::scratch_space_));
+ auto* union_scratch_space =
+ new (checked_cast<const UnionScalar&>(value).scratch_space_)
UnionScratchSpace{};
Review Comment:
I was using `new` to explicitly create the UnionScratchSpace. The
reinterpret_cast would probably be fine, but technically doesn't implicitly
start the lifetime of the UnionScratchSpace object until c++20 where it's [part
of the object model](https://eel.is/c++draft/basic.memobj#intro.object-10) that
implicit lifetime types may be used this way. Would you prefer:
```suggestion
auto* union_scratch_space = [&] {
UnionScratchSpace union_scratch_space{...initializers...};
std::memcpy(checked_cast<const UnionScalar&>(value).scratch_space_,
&union_scratch_space,
sizeof(UnionScratchSpace));
return reinterpret_cast<UnionScratchSpace*>(checked_cast<const
UnionScalar&>(value).scratch_space_);
}();
```
--
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]