mapleFU commented on code in PR #37514:
URL: https://github.com/apache/arrow/pull/37514#discussion_r1330188092


##########
cpp/src/arrow/dataset/file_parquet_test.cc:
##########
@@ -367,6 +369,69 @@ TEST_F(TestParquetFileFormat, MultithreadedScan) {
   ASSERT_EQ(batches.size(), kNumRowGroups);
 }
 
+class AsyncBufferReader : public ::arrow::io::BufferReader {
+ public:
+  explicit AsyncBufferReader(std::shared_ptr<Buffer> buffer,
+                             const ::arrow::io::IOContext& ctx)
+      : ::arrow::io::BufferReader(std::move(buffer)), ctx_(ctx) {}
+  /// EXPERIMENTAL: Read data asynchronously.
+  Future<std::shared_ptr<Buffer>> ReadAsync(const ::arrow::io::IOContext& ctx,
+                                            int64_t position, int64_t nbytes) 
override {
+    auto self = checked_pointer_cast<AsyncBufferReader>(shared_from_this());
+    return DeferNotOk(ctx.executor()->Submit(
+        [self, position, nbytes]() { return self->ReadAt(position, nbytes); 
}));
+  }
+
+  const ::arrow::io::IOContext& io_context() const override { return ctx_; }
+
+ private:
+  ::arrow::io::IOContext ctx_;
+};
+
+TEST_F(TestParquetFileFormat, SingleThreadExecutor) {
+  ::arrow::io::IOContext default_io_context;
+  auto pool_executor =
+      
dynamic_cast<::arrow::internal::ThreadPool*>(default_io_context.executor());
+  if (pool_executor == nullptr) {
+    GTEST_SKIP();
+  }
+  auto origin_capacity = pool_executor->GetCapacity();
+  ASSERT_OK(pool_executor->SetCapacity(/*threads=*/1));
+
+  // Reset capacity for pool_executor
+  struct PoolResetGuard {
+    PoolResetGuard(::arrow::internal::ThreadPool* pool, int origin_capacity)
+        : pool(pool), origin_capacity(origin_capacity) {}
+    ~PoolResetGuard() {
+      Status s = pool->SetCapacity(origin_capacity);
+      if (!s.ok()) {
+        std::cerr << "Failed to reset pool capacity: " << s.ToString() << 
std::endl;
+      }
+    }
+
+    ::arrow::internal::ThreadPool* pool;
+    int origin_capacity;
+  };
+  PoolResetGuard guard(pool_executor, origin_capacity);

Review Comment:
   > I agree that it's odd BufferReader::ReadAsync and 
MemoryMappedFile::ReadAsync (the only overrides I see) ignore the io context 
argument
   
   I think `BufferReader::ReadAsync` is so lightweight that we can ignore 
ioContext?



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