jorisvandenbossche commented on code in PR #14495:
URL: https://github.com/apache/arrow/pull/14495#discussion_r1004543920
##########
cpp/src/arrow/compute/kernels/scalar_nested.cc:
##########
@@ -252,6 +266,35 @@ struct StructFieldFunctor {
return Status::OK();
}
+ static Result<std::shared_ptr<Array>> ApplyFieldRef(KernelContext* ctx,
+ const FieldRef&
field_ref,
+ std::shared_ptr<Array>
current) {
+ if (current->type_id() != Type::STRUCT) {
+ return Status::Invalid("Not a StructArray: ", current->ToString(),
+ "\nMaybe a bad FieldRef? ", field_ref.ToString());
+ }
+
+ if (field_ref.IsName()) {
+ const auto& array = checked_cast<const StructArray&>(*current);
+ current = array.GetFieldByName(*field_ref.name());
+ if (current == nullptr) {
+ return Status::Invalid("Field not found in struct: '",
*field_ref.name(), "'");
+ }
+ } else if (field_ref.IsFieldPath()) {
+ for (const auto& idx : field_ref.field_path()->indices()) {
+ ARROW_RETURN_NOT_OK(CheckIndex(idx, *current->type()));
+ const auto& array = checked_cast<const StructArray&>(*current);
+ ARROW_ASSIGN_OR_RAISE(current, array.GetFlattenedField(idx,
ctx->memory_pool()));
+ }
Review Comment:
Hmm, but the GetFlattenedField ensures that null bitmaps are combined, which
is maybe not the case for FieldPath::Get() (since that doesn't use
GetFlattenedField, it's unlikely that it takes that into account)
(it would also be good to have tests for this situation, in case that
wouldn't yet be the case)
--
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]