zanmato1984 commented on code in PR #50423:
URL: https://github.com/apache/arrow/pull/50423#discussion_r3626210706


##########
cpp/src/arrow/compute/kernels/pivot_internal.cc:
##########
@@ -75,6 +79,19 @@ struct ConcretePivotWiderKeyMapper : public 
PivotWiderKeyMapper {
       }
       Unreachable("Grouper doesn't agree with std::unordered_set");
     }
+    // GH-48679: the fast grouper implementation may produce non-monotonic
+    // group ids, for example [0,1,2,4,3] rather than [0,1,2,3,4].
+    // Therefore, we need to produce a mapping a mapping of group ids to key 
indices.

Review Comment:
   Nit:
   ```suggestion
       // Therefore, we need to produce a mapping of group ids to key indices.
   ```



##########
cpp/src/arrow/compute/kernels/pivot_internal.cc:
##########
@@ -75,6 +79,19 @@ struct ConcretePivotWiderKeyMapper : public 
PivotWiderKeyMapper {
       }
       Unreachable("Grouper doesn't agree with std::unordered_set");
     }
+    // GH-48679: the fast grouper implementation may produce non-monotonic
+    // group ids, for example [0,1,2,4,3] rather than [0,1,2,3,4].
+    // Therefore, we need to produce a mapping a mapping of group ids to key 
indices.
+    auto key_indices_to_group_ids_data = key_indices_to_group_ids.array();
+    // InversePermutation doesn't allow unsigned integers, patch to signed.
+    DCHECK_EQ(key_indices_to_group_ids_data->type->id(), Type::UINT32);
+    key_indices_to_group_ids_data->type = int32();
+    ARROW_ASSIGN_OR_RAISE(group_ids_to_key_indices_,
+                          InversePermutation(key_indices_to_group_ids_data,
+                                             
InversePermutationOptions::Defaults(), ctx));
+    group_ids_to_key_indices_.array()->type = uint32();

Review Comment:
   Non-blocking: would it be a bit cleaner to copy the ArrayData before 
patching the type? This avoids mutating the Datum's ArrayData in place while 
still sharing the underlying buffers.
   ```suggestion
       auto key_indices_to_group_ids_data = 
key_indices_to_group_ids.array()->Copy();
       // InversePermutation doesn't allow unsigned integers, patch to signed.
       DCHECK_EQ(key_indices_to_group_ids_data->type->id(), Type::UINT32);
       key_indices_to_group_ids_data->type = int32();
       ARROW_ASSIGN_OR_RAISE(group_ids_to_key_indices_,
                             InversePermutation(key_indices_to_group_ids_data,
                                                
InversePermutationOptions::Defaults(), ctx));
       auto group_ids_to_key_indices_data = 
group_ids_to_key_indices_.array()->Copy();
       group_ids_to_key_indices_data->type = uint32();
       group_ids_to_key_indices_ = Datum(group_ids_to_key_indices_data);
   ```



-- 
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