rtpsw commented on code in PR #35953:
URL: https://github.com/apache/arrow/pull/35953#discussion_r1220185473
##########
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:
The SerialExecutor is needed for a clean interruption in case of
`use_threads=false` (see other posts here for more details). If the plan
execution is not serial then [it is
null](https://github.com/apache/arrow/pull/35953/files#diff-70e843181eb977ed11ad131f79a0f54a0bf9e30a0cb752d440658ee0cc16cc34R1043)
and not used.
--
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]