Skip to content

Commit 25344e3

Browse files
committed
Add exportToC method to RecordBatch Proxy C++ class
1 parent 97d60a0 commit 25344e3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

matlab/src/cpp/arrow/matlab/tabular/proxy/record_batch.cc

+17-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
#include "libmexclass/proxy/ProxyManager.h"
19-
18+
#include "arrow/c/bridge.h"
2019
#include "arrow/matlab/array/proxy/array.h"
2120
#include "arrow/matlab/array/proxy/wrap.h"
2221

@@ -66,6 +65,7 @@ RecordBatch::RecordBatch(std::shared_ptr<arrow::RecordBatch> record_batch)
6665
REGISTER_METHOD(RecordBatch, getColumnByName);
6766
REGISTER_METHOD(RecordBatch, getSchema);
6867
REGISTER_METHOD(RecordBatch, getRowAsString);
68+
REGISTER_METHOD(RecordBatch, exportToC);
6969
}
7070

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

262+
void RecordBatch::exportToC(libmexclass::proxy::method::Context& context) {
263+
namespace mda = ::matlab::data;
264+
mda::StructArray opts = context.inputs[0];
265+
const mda::TypedArray<uint64_t> array_address_mda = opts[0]["ArrowArrayAddress"];
266+
const mda::TypedArray<uint64_t> schema_address_mda = opts[0]["ArrowSchemaAddress"];
267+
268+
auto arrow_array = reinterpret_cast<struct ArrowArray*>(uint64_t(array_address_mda[0]));
269+
auto arrow_schema =
270+
reinterpret_cast<struct ArrowSchema*>(uint64_t(schema_address_mda[0]));
271+
272+
MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
273+
arrow::ExportRecordBatch(*record_batch, arrow_array, arrow_schema), context,
274+
error::C_EXPORT_FAILED);
275+
}
276+
262277
} // namespace arrow::matlab::tabular::proxy

matlab/src/cpp/arrow/matlab/tabular/proxy/record_batch.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class RecordBatch : public libmexclass::proxy::Proxy {
4343
void getColumnByName(libmexclass::proxy::method::Context& context);
4444
void getSchema(libmexclass::proxy::method::Context& context);
4545
void getRowAsString(libmexclass::proxy::method::Context& context);
46+
void exportToC(libmexclass::proxy::method::Context& context);
4647

4748
std::shared_ptr<arrow::RecordBatch> record_batch;
4849
};

0 commit comments

Comments
 (0)