icexelloss commented on code in PR #35953:
URL: https://github.com/apache/arrow/pull/35953#discussion_r1220134591


##########
cpp/src/arrow/acero/exec_plan.cc:
##########
@@ -1025,21 +1031,31 @@ Result<std::unique_ptr<RecordBatchReader>> 
DeclarationToReader(Declaration decla
     return Status::Invalid("Cannot use synchronous methods with a custom CPU 
executor");
   }
   std::shared_ptr<Schema> schema;
+  std::shared_ptr<BatchConverter> converter;
+  auto make_gen = [&](::arrow::internal::Executor* executor)
+      -> Result<AsyncGenerator<std::shared_ptr<RecordBatch>>> {
+    ExecContext exec_ctx(options.memory_pool, executor, 
options.function_registry);
+    ARROW_ASSIGN_OR_RAISE(
+        converter,
+        DeclarationToBatchConverter(declaration, std::move(options), executor, 
&schema));
+    return [converter] { return (*converter)(); };
+  };
+  arrow::internal::SerialExecutor* ser_exec = nullptr;
   auto batch_iterator = 
std::make_unique<Iterator<std::shared_ptr<RecordBatch>>>(
-      ::arrow::internal::IterateSynchronously<std::shared_ptr<RecordBatch>>(
-          [&](::arrow::internal::Executor* executor)
-              -> Result<AsyncGenerator<std::shared_ptr<RecordBatch>>> {
-            ExecContext exec_ctx(options.memory_pool, executor,
-                                 options.function_registry);
-            return DeclarationToRecordBatchGenerator(declaration, 
std::move(options),
-                                                     executor, &schema);
-          },
-          options.use_threads));
+      options.use_threads
+          ? 
::arrow::internal::IterateSynchronously<std::shared_ptr<RecordBatch>>(
+                std::move(make_gen), options.use_threads)
+          : arrow::internal::SerialExecutor::IterateGenerator<
+                std::shared_ptr<RecordBatch>>(std::move(make_gen), &ser_exec));
 
   struct PlanReader : RecordBatchReader {
-    PlanReader(std::shared_ptr<Schema> schema,
-               std::unique_ptr<Iterator<std::shared_ptr<RecordBatch>>> 
iterator)
-        : schema_(std::move(schema)), iterator_(std::move(iterator)) {}
+    PlanReader(std::shared_ptr<Schema> schema, std::shared_ptr<BatchConverter> 
converter,
+               std::unique_ptr<Iterator<std::shared_ptr<RecordBatch>>> 
iterator,
+               arrow::internal::SerialExecutor* ser_exec)

Review Comment:
   Why does plan reader takes a SerialExecutor? What if this is not serial 
execution?



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