amol- commented on code in PR #44447:
URL: https://github.com/apache/arrow/pull/44447#discussion_r1875954163


##########
cpp/src/arrow/array/util.cc:
##########
@@ -915,6 +917,71 @@ Result<std::shared_ptr<Array>> 
MakeEmptyArray(std::shared_ptr<DataType> type,
   return builder->Finish();
 }
 
+Result<std::shared_ptr<Array>> MakeMaskArray(const std::vector<int64_t>& 
indices,
+                                             int64_t length, MemoryPool* pool) 
{
+  ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateBitmap(length, pool));
+  bit_util::SetBitsTo(buffer->mutable_data(), 0, length, false);
+  for (int64_t index : indices) {
+    if (index < 0 || index >= length) {
+      return Status::IndexError("Index out of bounds: ", index);
+    }
+    bit_util::SetBit(buffer->mutable_data(), index);
+  }
+  return std::make_shared<BooleanArray>(length, buffer);
+}
+
+template <typename IndexType>
+Result<std::shared_ptr<Array>> MakeMaskArrayImpl(
+    const std::shared_ptr<NumericArray<IndexType>>& indices, int64_t length,
+    MemoryPool* pool) {
+  ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateBitmap(length, pool));
+  bit_util::SetBitsTo(buffer->mutable_data(), 0, length, false);
+  for (int64_t i = 0; i < indices->length(); ++i) {
+    int64_t index = indices->Value(i);
+    if (index < 0 || index >= length) {
+      return Status::IndexError("Index out of bounds: ", index);
+    }
+    bit_util::SetBit(buffer->mutable_data(), index);
+  }
+  return std::make_shared<BooleanArray>(length, buffer);
+}
+
+Result<std::shared_ptr<Array>> MakeMaskArray(const std::shared_ptr<Array>& 
indices,
+                                             int64_t length, MemoryPool* pool) 
{
+  if (indices->null_count() > 0) {
+    return Status::Invalid("Indices array must not contain null values");
+  }

Review Comment:
   I don't see a reason why it would make sense to accept null values, it 
verifies if there are null values and rejects the array in case there are 
because there doesn't seem to be a case where it would make sense to have nulls 
in an array of indices. 
   If the user has an array containing nulls it can be used by passing it to 
`compute.drop_null` before using `MakeMaskArray`.



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