milesgranger commented on code in PR #14495:
URL: https://github.com/apache/arrow/pull/14495#discussion_r1005416999
##########
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:
I gave it a go. Seems those expected null checks already exist as C++ tests
started failing with:
`Null counts differ. Expected -1 but was 0` and similar discrepancies.
--
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]