Skip to content

Commit

Permalink
Re-implement proxy::RecordBatchFileWriter to inherit from proxy::Reco…
Browse files Browse the repository at this point in the history
…rdBatchWriter
  • Loading branch information
sgilmore10 committed Dec 3, 2024
1 parent 2e7c2f2 commit b4eba33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
// specific language governing permissions and limitations
// under the License.

#include "arrow/matlab/io/ipc/proxy/record_batch_file_writer.h"
#include "arrow/io/file.h"
#include "arrow/matlab/error/error.h"
#include "arrow/matlab/tabular/proxy/record_batch.h"
#include "arrow/matlab/io/ipc/proxy/record_batch_file_writer.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 @@ -29,11 +27,7 @@ namespace arrow::matlab::io::ipc::proxy {

RecordBatchFileWriter::RecordBatchFileWriter(
const std::shared_ptr<arrow::ipc::RecordBatchWriter> writer)
: writer{std::move(writer)} {
REGISTER_METHOD(RecordBatchFileWriter, close);
REGISTER_METHOD(RecordBatchFileWriter, writeRecordBatch);
REGISTER_METHOD(RecordBatchFileWriter, writeTable);
}
: RecordBatchWriter(std::move(writer)) {}

libmexclass::proxy::MakeResult RecordBatchFileWriter::make(
const libmexclass::proxy::FunctionArguments& constructor_arguments) {
Expand Down Expand Up @@ -65,43 +59,4 @@ libmexclass::proxy::MakeResult RecordBatchFileWriter::make(
return std::make_shared<RecordBatchFileWriterProxy>(std::move(writer));
}

void RecordBatchFileWriter::writeRecordBatch(
libmexclass::proxy::method::Context& context) {
namespace mda = ::matlab::data;
using RecordBatchProxy = ::arrow::matlab::tabular::proxy::RecordBatch;

mda::StructArray opts = context.inputs[0];
const mda::TypedArray<uint64_t> record_batch_proxy_id_mda =
opts[0]["RecordBatchProxyID"];
const uint64_t record_batch_proxy_id = record_batch_proxy_id_mda[0];

auto proxy = libmexclass::proxy::ProxyManager::getProxy(record_batch_proxy_id);
auto record_batch_proxy = std::static_pointer_cast<RecordBatchProxy>(proxy);
auto record_batch = record_batch_proxy->unwrap();

MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(writer->WriteRecordBatch(*record_batch), 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);
}

void RecordBatchFileWriter::close(libmexclass::proxy::method::Context& context) {
MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(writer->Close(), context,
error::IPC_RECORD_BATCH_WRITE_CLOSE_FAILED);
}

} // namespace arrow::matlab::io::ipc::proxy
} // namespace arrow::matlab::io::ipc::proxy
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,21 @@
// under the License.

#include "arrow/ipc/writer.h"
#include "arrow/matlab/io/ipc/proxy/record_batch_writer.h"

#include "libmexclass/proxy/Proxy.h"

namespace arrow::matlab::io::ipc::proxy {

class RecordBatchFileWriter : public libmexclass::proxy::Proxy {
class RecordBatchFileWriter : public RecordBatchWriter {
public:
RecordBatchFileWriter(std::shared_ptr<arrow::ipc::RecordBatchWriter> writer);

~RecordBatchFileWriter() = default;
virtual ~RecordBatchFileWriter() = default;

static libmexclass::proxy::MakeResult make(
const libmexclass::proxy::FunctionArguments& constructor_arguments);

protected:
std::shared_ptr<arrow::ipc::RecordBatchWriter> writer;

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

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

void close(libmexclass::proxy::method::Context& context);
};

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

0 comments on commit b4eba33

Please sign in to comment.