milesgranger commented on code in PR #14495:
URL: https://github.com/apache/arrow/pull/14495#discussion_r1006946204
##########
cpp/src/arrow/compute/kernels/scalar_nested.cc:
##########
@@ -271,11 +318,30 @@ struct StructFieldFunctor {
Result<TypeHolder> ResolveStructFieldType(KernelContext* ctx,
const std::vector<TypeHolder>&
types) {
- const auto& options = OptionsWrapper<StructFieldOptions>::Get(ctx);
+ const auto& field_ref =
OptionsWrapper<StructFieldOptions>::Get(ctx).field_ref;
const DataType* type = types.front().type;
- for (const auto& index : options.indices) {
- RETURN_NOT_OK(StructFieldFunctor::CheckIndex(index, *type));
- type = type->field(index)->type().get();
+
+ if (field_ref.IsName()) {
+ for (const auto& path : field_ref.FindAll(*type)) {
+ for (const auto& index : path.indices()) {
+ RETURN_NOT_OK(StructFieldFunctor::CheckIndex(index, *type));
+ type = type->field(index)->type().get();
+ }
+ }
+ } else {
+ DCHECK(field_ref.IsFieldPath() || field_ref.IsNested());
+
+ FieldPath field_path;
+ if (field_ref.IsNested()) {
+ ARROW_ASSIGN_OR_RAISE(field_path, field_ref.FindOne(*type));
+ } else {
+ field_path = *field_ref.field_path();
+ }
Review Comment:
The empty index case was in the Python tests.
I suppose it may be useful if only to serve the purpose of idempotent
behavior, similar to `[:]` or `start==stop` -> empty lists in the `list_slice`
kernel. Albeit those are unique to slicing.
--
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]