pitrou commented on a change in pull request #10817:
URL: https://github.com/apache/arrow/pull/10817#discussion_r678453391
##########
File path: cpp/src/arrow/array/builder_base.cc
##########
@@ -206,6 +207,45 @@ struct AppendScalarImpl {
return Status::OK();
}
+ Status Visit(const SparseUnionType& type) { return MakeUnionArray(type); }
+
+ Status Visit(const DenseUnionType& type) { return MakeUnionArray(type); }
+
+ template <typename T>
+ Status MakeUnionArray(const T& type) {
+ using BuilderType = typename TypeTraits<T>::BuilderType;
+
+ auto* builder = internal::checked_cast<BuilderType*>(builder_);
+ const auto count = n_repeats_ * (scalars_end_ - scalars_begin_);
+
+ RETURN_NOT_OK(builder->Reserve(count));
+
+ DCHECK_EQ(type.num_fields(), builder->num_children());
+ for (int field_index = 0; field_index < type.num_fields(); ++field_index) {
+ RETURN_NOT_OK(builder->child_builder(field_index)->Reserve(count));
+ }
+
+ for (int64_t i = 0; i < n_repeats_; i++) {
+ for (const std::shared_ptr<Scalar>* s = scalars_begin_; s !=
scalars_end_; s++) {
+ // For each scalar, 1. append the type code, 2. append the value to
+ // the corresponding child (and append null to the other children)
Review comment:
Oh, you're right, indeed. Thanks for spotting this.
--
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]