pitrou commented on a change in pull request #10817:
URL: https://github.com/apache/arrow/pull/10817#discussion_r678468116
##########
File path: cpp/src/arrow/array/util.cc
##########
@@ -613,18 +614,85 @@ class RepeatedArrayFactory {
return Status::OK();
}
- Status Visit(const ExtensionType& type) {
- return Status::NotImplemented("construction from scalar of type ",
*scalar_.type);
+ Status Visit(const SparseUnionType& type) {
+ const auto& union_scalar = checked_cast<const UnionScalar&>(scalar_);
+ const auto& union_type = checked_cast<const UnionType&>(*scalar_.type);
+ const auto scalar_type_code = union_scalar.type_code;
+ const auto scalar_child_id = union_type.child_ids()[scalar_type_code];
+
+ // Create child arrays: most of them are all-null, except for the child
array
+ // for the given type code (if the scalar is valid).
+ ArrayVector fields;
+ for (int i = 0; i < type.num_fields(); ++i) {
+ fields.emplace_back();
+ if (i == scalar_child_id && scalar_.is_valid) {
+ ARROW_ASSIGN_OR_RAISE(fields.back(),
+ MakeArrayFromScalar(*union_scalar.value,
length_, pool_));
+ } else {
+ ARROW_ASSIGN_OR_RAISE(
+ fields.back(), MakeArrayOfNull(union_type.field(i)->type(),
length_, pool_));
+ }
+ }
+
+ ARROW_ASSIGN_OR_RAISE(auto type_codes_buffer,
CreateUnionTypeCodes(scalar_type_code));
+
+ out_ = std::make_shared<SparseUnionArray>(scalar_.type, length_,
std::move(fields),
+ std::move(type_codes_buffer));
+ return Status::OK();
}
Status Visit(const DenseUnionType& type) {
- return Status::NotImplemented("construction from scalar of type ",
*scalar_.type);
+ const auto& union_scalar = checked_cast<const UnionScalar&>(scalar_);
+ const auto& union_type = checked_cast<const UnionType&>(*scalar_.type);
+ const auto scalar_type_code = union_scalar.type_code;
+ const auto scalar_child_id = union_type.child_ids()[scalar_type_code];
+
+ // Create child arrays: all of them are empty, except for the child array
+ // for the given type code (if length > 0).
+ ArrayVector fields;
+ for (int i = 0; i < type.num_fields(); ++i) {
+ fields.emplace_back();
+ if (i == scalar_child_id && length_ > 0) {
+ if (scalar_.is_valid) {
+ // One valid element (will be referenced by multiple offsets)
Review comment:
Opened https://issues.apache.org/jira/browse/ARROW-13479
--
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]