paleolimbot commented on code in PR #13397:
URL: https://github.com/apache/arrow/pull/13397#discussion_r914993195


##########
r/src/compute-exec.cpp:
##########
@@ -109,9 +109,50 @@ std::shared_ptr<arrow::RecordBatchReader> ExecPlan_run(
     auto kv = strings_to_kvm(metadata);
     out_schema = out_schema->WithMetadata(kv);
   }
-  return compute::MakeGeneratorReader(
+
+  std::pair<std::shared_ptr<compute::ExecPlan>, 
std::shared_ptr<arrow::RecordBatchReader>>
+      out;
+  out.first = plan;
+  out.second = compute::MakeGeneratorReader(
       out_schema, [stop_producing, plan, sink_gen] { return sink_gen(); },
       gc_memory_pool());
+  return out;
+}
+
+// [[arrow::export]]
+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,
+    cpp11::strings metadata, int64_t head = -1) {
+  auto prepared_plan = ExecPlan_prepare(plan, final_node, sort_options, 
metadata, head);
+  StopIfNotOk(prepared_plan.first->StartProducing());
+  return prepared_plan.second;
+}
+
+// [[arrow::export]]
+std::shared_ptr<arrow::Table> ExecPlan_read_table(
+    const std::shared_ptr<compute::ExecPlan>& plan,
+    const std::shared_ptr<compute::ExecNode>& final_node, cpp11::list 
sort_options,
+    cpp11::strings metadata, int64_t head = -1, bool on_old_windows = false) {
+  auto prepared_plan = ExecPlan_prepare(plan, final_node, sort_options, 
metadata, head);
+#if !defined(HAS_SAFE_CALL_INTO_R)
+  StopIfNotOk(prepared_plan.first->StartProducing());
+  return ValueOrStop(prepared_plan.second->ToTable());
+#else
+  if (on_old_windows) {
+    StopIfNotOk(prepared_plan.first->StartProducing());
+    return ValueOrStop(prepared_plan.second->ToTable());
+  }
+
+  const auto& io_context = arrow::io::default_io_context();

Review Comment:
   This pattern lives in a few places and should probably get consolidated into 
safe-call-into-r.h. There are a few other changes to R-code-from-C++ evaluation 
(like maybe better error messages or consolidating the HAS_SAFE_CALL_INTO_R and 
on_old_windows arguments into a single runtime function)...should I do those 
here or do it in a separate JIRA/PR?



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