Skip to content

Instantly share code, notes, and snippets.

@drin
Last active June 8, 2021 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drin/d9f4400670eae69f5c367b37ca8c1b24 to your computer and use it in GitHub Desktop.
Save drin/d9f4400670eae69f5c367b37ca8c1b24 to your computer and use it in GitHub Desktop.
Using Arrow in C++ and R
Package: skytethr
Title: Integration to 'Skytether-singlecell'
Version: 0.1.0
LinkingTo: cpp11, boostfs, arrow
SystemRequirements: C++11

Errors when headers are correct

/tmp/RtmpLvPZfE/file7ecb2abfb8d2/src/cpp11.cpp:4:1: error: ‘arrow’ does not name a type
 arrow::Result<BatchStreamRdrPtr> R_GetReaderForKey(cpp11::r_string table_key);
 ^~~~~
/tmp/RtmpLvPZfE/file7ecb2abfb8d2/src/cpp11.cpp: In function ‘SEXPREC* _skyteth_r_R_GetReaderForKey(SEXP)’:
/tmp/RtmpLvPZfE/file7ecb2abfb8d2/src/cpp11.cpp:7:27: error: ‘R_GetReaderForKey’ was not declared in this scope
     return cpp11::as_sexp(R_GetReaderForKey(cpp11::as_cpp<cpp11::decay_t<cpp11::r_string>>(table_key)));
                           ^~~~~~~~~~~~~~~~~
make: *** [/tmp/RtmpLvPZfE/file7ecb2abfb8d2/src/cpp11.o] Error 1
Error: Compilation failed.
Execution halted

Errors when headers are incorrect

/tmp/RtmpHXyYvK/file7eb21ed3dde0/src/skyteth_r.cpp:35:1: error: ‘arrow’ does not name a type
 arrow::Result<BatchStreamRdrPtr>
 ^~~~~
make: *** [/tmp/RtmpHXyYvK/file7eb21ed3dde0/src/skyteth_r.o] Error 1
Error: Compilation failed.
Execution halted
// ------------------------------
// Dependencies
#include "cpp11.hpp"
// ------------------------------
// Common API
[[cpp11::register]]
arrow::Result<BatchStreamRdrPtr>
R_GetReaderForKey(cpp11::r_string table_key) {
arrow::Result<BatchStreamRdrPtr> reader_result;
KineticConn kconn = KineticConn();
kconn.Connect();
if (kconn.IsConnected()) {
reader_result = kconn.GetReaderForKey(static_cast<std::string>(table_key));
kconn.Disconnect();
}
else {
reader_result = arrow::Result<BatchStreamRdrPtr>(
arrow::Status::Invalid("Could not connect to kinetic drive")
);
}
return reader_result;
}
library(arrow)
library(cpp11)
cpp_source(file='src/skyteth_r.cpp')
// ------------------------------
// Dependencies
#include "cpp11.hpp"
// These are included in the skytether headers, but copied here to be explicit
#include <arrow/api.h>
#include <arrow/io/api.h>
#include <arrow/ipc/api.h>
#include <arrow/filesystem/api.h>
#include <arrow/dataset/api.h>
#include <skytether/skytether.hpp>
#include <skytether/skytether_types.hpp>
#include <skytether/connectors/connectors.hpp>
/* Some things from the skytether headers for reference:
typedef std::vector<TablePtr> TableVector;
typedef std::shared_ptr<arrow::ipc::RecordBatchStreamReader> BatchStreamRdrPtr;
struct KineticConn {
int conn_id;
KineticConn();
bool IsConnected();
void Disconnect();
void Connect();
KBuffer* GetKey(std::string key_name);
arrow::Status PutTableBatches(std::string table_key, TablePtr table_data, int64_t batch_size);
arrow::Result<BatchStreamRdrPtr>
GetReaderForKey(std::string table_key);
};
*/
// ------------------------------
// Common API
[[cpp11::register]]
arrow::Result<BatchStreamRdrPtr>
R_GetReaderForKey(cpp11::r_string table_key) {
arrow::Result<BatchStreamRdrPtr> reader_result;
KineticConn kconn = KineticConn();
kconn.Connect();
if (kconn.IsConnected()) {
reader_result = kconn.GetReaderForKey(static_cast<std::string>(table_key));
kconn.Disconnect();
}
else {
reader_result = arrow::Result<BatchStreamRdrPtr>(
arrow::Status::Invalid("Could not connect to kinetic drive")
);
}
return reader_result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment