pitrou commented on code in PR #40484:
URL: https://github.com/apache/arrow/pull/40484#discussion_r1543407480


##########
cpp/src/arrow/compute/key_hash.cc:
##########
@@ -378,20 +378,40 @@ void Hashing32::HashFixed(int64_t hardware_flags, bool 
combine_hashes, uint32_t
   }
 }
 
-void Hashing32::HashMultiColumn(const std::vector<KeyColumnArray>& cols,
-                                LightContext* ctx, uint32_t* hashes) {
-  uint32_t num_rows = static_cast<uint32_t>(cols[0].length());
-
-  constexpr uint32_t max_batch_size = util::MiniBatch::kMiniBatchLength;
+Status Hashing32::HashMultiColumn(const std::vector<KeyColumnArray>& cols,
+                                  LightContext* ctx, uint32_t* hashes) {
+  auto num_rows = static_cast<uint32_t>(cols[0].length());
+  // The max_batch_size represents the number of rows to be processed in each 
iteration,
+  // and it is used to allocate enough space for the allocated TempVectorStack.
+  const auto max_batch_size =
+      std::min(num_rows, 
static_cast<uint32_t>(util::MiniBatch::kMiniBatchLength));
+
+  // pre calculate alloc size in TempVectorStack for hash_temp_buf, 
null_hash_temp_buf
+  // and null_indices_buf
+  const auto alloc_hash_temp_buf =
+      util::TempVectorStack::EstimateAllocationSize(max_batch_size * 
sizeof(uint32_t));
+  const auto alloc_for_null_indices_buf =
+      util::TempVectorStack::EstimateAllocationSize(max_batch_size * 
sizeof(uint16_t));
+  const auto alloc_size = alloc_hash_temp_buf * 2 + alloc_for_null_indices_buf;
+
+  std::unique_ptr<util::TempVectorStack> temp_stack(nullptr);
+  auto stack = ctx->stack;
+  if (!stack) {

Review Comment:
   It was probably a mistake to not mark them internal explicitly (we should 
just do that), but they were not meant to be exposed publicly.
   
   As for `ARROW_EXPORT`, it marks them as exporting by the DLL, which doesn't 
mean that it's ok for non-Arrow code to call them. This can be simply because 
the internal code using these functions is itself located in another Arrow DLL, 
as there are several of them.



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