You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/05/27 16:06:48 UTC

[GitHub] [arrow] bkietz commented on a change in pull request #7279: ARROW-8938: [R] Provide binding for arrow::compute::CallFunction

bkietz commented on a change in pull request #7279:
URL: https://github.com/apache/arrow/pull/7279#discussion_r431263416



##########
File path: r/src/compute.cpp
##########
@@ -223,4 +205,66 @@ std::shared_ptr<arrow::Table> Table__FilterChunked(
   }
   return tab;
 }
+
+arrow::Datum to_datum(SEXP x) {
+  // TODO: this is repetitive, can we DRY it out?
+  if (Rf_inherits(x, "ArrowObject") && Rf_inherits(x, "Array")) {
+    Rcpp::ConstReferenceSmartPtrInputParameter<std::shared_ptr<arrow::Array>> obj(x);
+    return static_cast<std::shared_ptr<arrow::Array>>(obj);
+  } else if (Rf_inherits(x, "ArrowObject") && Rf_inherits(x, "ChunkedArray")) {
+    Rcpp::ConstReferenceSmartPtrInputParameter<std::shared_ptr<arrow::ChunkedArray>> obj(x);
+    return static_cast<std::shared_ptr<arrow::ChunkedArray>>(obj);
+  } else if (Rf_inherits(x, "ArrowObject") && Rf_inherits(x, "RecordBatch")) {
+    Rcpp::ConstReferenceSmartPtrInputParameter<std::shared_ptr<arrow::RecordBatch>> obj(x);
+    return static_cast<std::shared_ptr<arrow::RecordBatch>>(obj);
+  } else if (Rf_inherits(x, "ArrowObject") && Rf_inherits(x, "Table")) {
+    Rcpp::ConstReferenceSmartPtrInputParameter<std::shared_ptr<arrow::Table>> obj(x);
+    return static_cast<std::shared_ptr<arrow::Table>>(obj);
+  } else {
+    // TODO: scalar?

Review comment:
       I would recommend refactoring that function into `std::shared_ptr<Scalar> to_scalar(SEXP)`. That function need not be exported (same logic as `Datum`; `SEXP` already holds whatever value). The climax of `to_scalar` should be a call to `arrow::MakeScalar`.
   
   After this:
   ```c++
   std::shared_ptr<ds::Expression> dataset___expr__scalar(SEXP x) {
     return ds::scalar(to_scalar(x));
   }
   ```




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org