Skip to content

Commit

Permalink
Add exportToC method to RecordBatch Proxy C++ class
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed May 24, 2024
1 parent 97d60a0 commit 25344e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions matlab/src/cpp/arrow/matlab/tabular/proxy/record_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
// specific language governing permissions and limitations
// under the License.

#include "libmexclass/proxy/ProxyManager.h"

#include "arrow/c/bridge.h"
#include "arrow/matlab/array/proxy/array.h"
#include "arrow/matlab/array/proxy/wrap.h"

Expand Down Expand Up @@ -66,6 +65,7 @@ RecordBatch::RecordBatch(std::shared_ptr<arrow::RecordBatch> record_batch)
REGISTER_METHOD(RecordBatch, getColumnByName);
REGISTER_METHOD(RecordBatch, getSchema);
REGISTER_METHOD(RecordBatch, getRowAsString);
REGISTER_METHOD(RecordBatch, exportToC);
}

std::shared_ptr<arrow::RecordBatch> RecordBatch::unwrap() { return record_batch; }
Expand Down Expand Up @@ -259,4 +259,19 @@ void RecordBatch::getRowAsString(libmexclass::proxy::method::Context& context) {
context.outputs[0] = factory.createScalar(row_str_utf16);
}

void RecordBatch::exportToC(libmexclass::proxy::method::Context& context) {
namespace mda = ::matlab::data;
mda::StructArray opts = context.inputs[0];
const mda::TypedArray<uint64_t> array_address_mda = opts[0]["ArrowArrayAddress"];
const mda::TypedArray<uint64_t> schema_address_mda = opts[0]["ArrowSchemaAddress"];

auto arrow_array = reinterpret_cast<struct ArrowArray*>(uint64_t(array_address_mda[0]));
auto arrow_schema =
reinterpret_cast<struct ArrowSchema*>(uint64_t(schema_address_mda[0]));

MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
arrow::ExportRecordBatch(*record_batch, arrow_array, arrow_schema), context,
error::C_EXPORT_FAILED);
}

} // namespace arrow::matlab::tabular::proxy
1 change: 1 addition & 0 deletions matlab/src/cpp/arrow/matlab/tabular/proxy/record_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class RecordBatch : public libmexclass::proxy::Proxy {
void getColumnByName(libmexclass::proxy::method::Context& context);
void getSchema(libmexclass::proxy::method::Context& context);
void getRowAsString(libmexclass::proxy::method::Context& context);
void exportToC(libmexclass::proxy::method::Context& context);

std::shared_ptr<arrow::RecordBatch> record_batch;
};
Expand Down

0 comments on commit 25344e3

Please sign in to comment.