milesgranger commented on code in PR #14495:
URL: https://github.com/apache/arrow/pull/14495#discussion_r1006750361


##########
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:
   Seems like it is needed, removing if/else and using 
`field_ref.FindOne(*type)` will abort when `pc.struct_field(arr, [])` (empty 
indices) with:
   ```
   pyarrow/tests/test_compute.py::test_struct_fields_options 
/home/milesg/Projects/arrow/cpp/src/arrow/type.cc:1360:  Check failed: _s.ok() 
Operation failed: maybe_field.status()
   Bad status: Invalid: empty indices cannot be traversed
   ```
   Seems like another if statement would be needed to handle that case, so 
maybe stick with 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]

Reply via email to