Skip to content

Commit

Permalink
Implement RecordBatchFileWriter::writeTable(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed Jun 13, 2024
1 parent bab0f9a commit 808de49
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "arrow/matlab/io/ipc/proxy/record_batch_file_writer.h"
#include "arrow/matlab/tabular/proxy/record_batch.h"
#include "arrow/matlab/tabular/proxy/schema.h"
#include "arrow/matlab/tabular/proxy/table.h"
#include "arrow/util/utf8.h"

#include "libmexclass/proxy/ProxyManager.h"
Expand All @@ -30,6 +31,7 @@ namespace arrow::matlab::io::ipc::proxy {
RecordBatchFileWriter::RecordBatchFileWriter(const std::shared_ptr<arrow::ipc::RecordBatchWriter> writer)
: writer{std::move(writer)} {
REGISTER_METHOD(RecordBatchFileWriter, writeRecordBatch);
REGISTER_METHOD(RecordBatchFileWriter, writeTable);
}

libmexclass::proxy::MakeResult RecordBatchFileWriter::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
Expand Down Expand Up @@ -77,4 +79,20 @@ void RecordBatchFileWriter::writeRecordBatch(libmexclass::proxy::method::Context
context, error::IPC_RECORD_BATCH_WRITE_FAILED);
}

void RecordBatchFileWriter::writeTable(libmexclass::proxy::method::Context& context) {
namespace mda = ::matlab::data;
using TableProxy = ::arrow::matlab::tabular::proxy::Table;

mda::StructArray opts = context.inputs[0];
const mda::TypedArray<uint64_t> table_proxy_id_mda = opts[0]["TableProxyID"];
const uint64_t table_proxy_id = table_proxy_id_mda[0];

auto proxy = libmexclass::proxy::ProxyManager::getProxy(table_proxy_id);
auto table_proxy = std::static_pointer_cast<TableProxy>(proxy);
auto table = table_proxy->unwrap();

MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(writer->WriteTable(*table),
context, error::IPC_RECORD_BATCH_WRITE_FAILED);
}

} // namespace arrow::matlab::io::ipc::proxy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class RecordBatchFileWriter : public libmexclass::proxy::Proxy {

void writeRecordBatch(libmexclass::proxy::method::Context& context);

void writeTable(libmexclass::proxy::method::Context& context);

};

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

0 comments on commit 808de49

Please sign in to comment.