Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion r/R/query-engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
do_exec_plan <- function(.data) {
plan <- ExecPlan$create()
final_node <- plan$Build(.data)
tab <- plan$Run(final_node)
tab <- plan$Run(final_node)$read_table()

# If arrange() created $temp_columns, make sure to omit them from the result
# We can't currently handle this in the ExecPlan itself because sorting
Expand Down
2 changes: 1 addition & 1 deletion r/src/arrowExports.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions r/src/compute-exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::shared_ptr<compute::ExecNode> MakeExecNodeOrStop(
}

// [[arrow::export]]
std::shared_ptr<arrow::Table> ExecPlan_run(
std::shared_ptr<arrow::RecordBatchReader> ExecPlan_run(
const std::shared_ptr<compute::ExecPlan>& plan,
const std::shared_ptr<compute::ExecNode>& final_node, cpp11::list sort_options) {
// For now, don't require R to construct SinkNodes.
Expand All @@ -77,11 +77,21 @@ std::shared_ptr<arrow::Table> ExecPlan_run(
StopIfNotOk(plan->Validate());
StopIfNotOk(plan->StartProducing());

std::shared_ptr<arrow::RecordBatchReader> sink_reader = compute::MakeGeneratorReader(
final_node->output_schema(), std::move(sink_gen), gc_memory_pool());

plan->finished().Wait();
return ValueOrStop(arrow::Table::FromRecordBatchReader(sink_reader.get()));
// If the generator is destroyed before being completely drained, inform plan
std::shared_ptr<void> stop_producing{nullptr, [plan](...) {
bool not_finished_yet =
plan->finished().TryAddCallback([&plan] {
return [plan](const arrow::Status&) {};
});

if (not_finished_yet) {
plan->StopProducing();
}
}};

return compute::MakeGeneratorReader(
final_node->output_schema(),
[stop_producing, plan, sink_gen] { return sink_gen(); }, gc_memory_pool());
}

#if defined(ARROW_R_WITH_DATASET)
Expand Down