Skip to content

Commit bab0f9a

Browse files
committed
Implement RecordBatchFileWriter::writeRecordBatch(...)
1 parent fdb12d0 commit bab0f9a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

matlab/src/cpp/arrow/matlab/error/error.h

+1
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,6 @@ static const char* ARRAY_SLICE_FAILED_TO_CREATE_ARRAY_PROXY =
242242
"arrow:array:slice:FailedToCreateArrayProxy";
243243
static const char* C_EXPORT_FAILED = "arrow:c:export:ExportFailed";
244244
static const char* C_IMPORT_FAILED = "arrow:c:import:ImportFailed";
245+
static const char* IPC_RECORD_BATCH_WRITE_FAILED = "arrow:io:ipc:FailedToWriteRecordBatch";
245246

246247
} // namespace arrow::matlab::error

matlab/src/cpp/arrow/matlab/io/ipc/proxy/record_batch_file_writer.cc

+19-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
namespace arrow::matlab::io::ipc::proxy {
2929

3030
RecordBatchFileWriter::RecordBatchFileWriter(const std::shared_ptr<arrow::ipc::RecordBatchWriter> writer)
31-
: writer{std::move(writer)} {}
31+
: writer{std::move(writer)} {
32+
REGISTER_METHOD(RecordBatchFileWriter, writeRecordBatch);
33+
}
3234

3335
libmexclass::proxy::MakeResult RecordBatchFileWriter::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
3436
namespace mda = ::matlab::data;
@@ -59,4 +61,20 @@ libmexclass::proxy::MakeResult RecordBatchFileWriter::make(const libmexclass::pr
5961
return std::make_shared<RecordBatchFileWriterProxy>(std::move(writer));
6062
}
6163

64+
void RecordBatchFileWriter::writeRecordBatch(libmexclass::proxy::method::Context& context) {
65+
namespace mda = ::matlab::data;
66+
using RecordBatchProxy = ::arrow::matlab::tabular::proxy::RecordBatch;
67+
68+
mda::StructArray opts = context.inputs[0];
69+
const mda::TypedArray<uint64_t> record_batch_proxy_id_mda = opts[0]["RecordBatchProxyID"];
70+
const uint64_t record_batch_proxy_id = record_batch_proxy_id_mda[0];
71+
72+
auto proxy = libmexclass::proxy::ProxyManager::getProxy(record_batch_proxy_id);
73+
auto record_batch_proxy = std::static_pointer_cast<RecordBatchProxy>(proxy);
74+
auto record_batch = record_batch_proxy->unwrap();
75+
76+
MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(writer->WriteRecordBatch(*record_batch),
77+
context, error::IPC_RECORD_BATCH_WRITE_FAILED);
78+
}
79+
6280
} // namespace arrow::matlab::io::ipc::proxy

matlab/src/cpp/arrow/matlab/io/ipc/proxy/record_batch_file_writer.h

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class RecordBatchFileWriter : public libmexclass::proxy::Proxy {
3030

3131
protected:
3232
std::shared_ptr<arrow::ipc::RecordBatchWriter> writer;
33+
34+
void writeRecordBatch(libmexclass::proxy::method::Context& context);
35+
3336
};
3437

3538
} // namespace arrow::matlab::io::ipc::proxy

0 commit comments

Comments
 (0)