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


##########
cpp/src/arrow/compute/key_hash_test.cc:
##########
@@ -311,5 +311,38 @@ TEST(VectorHash, FixedLengthTailByteSafety) {
   HashFixedLengthFrom(/*key_length=*/19, /*num_rows=*/64, /*start_row=*/63);
 }
 
+TEST(HashBatch, AllocTempStackAsNeeded) {
+  auto arr = arrow::ArrayFromJSON(arrow::int32(), "[9,2,6]");
+  const auto batch_size = static_cast<int32_t>(arr->length());
+  arrow::compute::ExecBatch exec_batch({arr}, batch_size);
+  auto ctx = arrow::compute::default_exec_context();
+  std::vector<arrow::compute::KeyColumnArray> temp_column_arrays;
+
+  // alloc stack by HashBatch internal
+  std::vector<uint32_t> h1(batch_size);
+  ASSERT_OK(arrow::compute::Hashing32::HashBatch(
+      exec_batch, h1.data(), temp_column_arrays, 
ctx->cpu_info()->hardware_flags(),
+      nullptr, 0, batch_size));
+
+  util::TempVectorStack stack;
+  std::vector<uint32_t> h2(batch_size);
+
+  // alloc stack overflow in HashBatch
+  ASSERT_OK(stack.Init(default_memory_pool(), batch_size));
+  ASSERT_NOT_OK(arrow::compute::Hashing32::HashBatch(
+      exec_batch, h2.data(), temp_column_arrays, 
ctx->cpu_info()->hardware_flags(),
+      &stack, 0, batch_size));
+
+  // alloc stack normally in HashBatch

Review Comment:
   ```suggestion
   // HashBatch using big enough pre-allocated buffer.
   ```



##########
cpp/src/arrow/compute/key_hash_test.cc:
##########
@@ -311,5 +311,38 @@ TEST(VectorHash, FixedLengthTailByteSafety) {
   HashFixedLengthFrom(/*key_length=*/19, /*num_rows=*/64, /*start_row=*/63);
 }
 
+TEST(HashBatch, AllocTempStackAsNeeded) {
+  auto arr = arrow::ArrayFromJSON(arrow::int32(), "[9,2,6]");
+  const auto batch_size = static_cast<int32_t>(arr->length());
+  arrow::compute::ExecBatch exec_batch({arr}, batch_size);
+  auto ctx = arrow::compute::default_exec_context();
+  std::vector<arrow::compute::KeyColumnArray> temp_column_arrays;
+
+  // alloc stack by HashBatch internal

Review Comment:
   ```suggestion
     // HashBatch using internally allocated buffer.
   ```



##########
cpp/src/arrow/compute/key_hash_test.cc:
##########
@@ -311,5 +311,38 @@ TEST(VectorHash, FixedLengthTailByteSafety) {
   HashFixedLengthFrom(/*key_length=*/19, /*num_rows=*/64, /*start_row=*/63);
 }
 
+TEST(HashBatch, AllocTempStackAsNeeded) {
+  auto arr = arrow::ArrayFromJSON(arrow::int32(), "[9,2,6]");
+  const auto batch_size = static_cast<int32_t>(arr->length());
+  arrow::compute::ExecBatch exec_batch({arr}, batch_size);
+  auto ctx = arrow::compute::default_exec_context();
+  std::vector<arrow::compute::KeyColumnArray> temp_column_arrays;
+
+  // alloc stack by HashBatch internal
+  std::vector<uint32_t> h1(batch_size);
+  ASSERT_OK(arrow::compute::Hashing32::HashBatch(
+      exec_batch, h1.data(), temp_column_arrays, 
ctx->cpu_info()->hardware_flags(),
+      nullptr, 0, batch_size));
+
+  util::TempVectorStack stack;
+  std::vector<uint32_t> h2(batch_size);
+
+  // alloc stack overflow in HashBatch

Review Comment:
   ```suggestion
     // HashBatch using pre-allocated buffer of insufficient size raises stack 
overflow.
   ```



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