Skip to content

Commit

Permalink
Add readRecordBatch method
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed Jun 12, 2024
1 parent e6a0ea1 commit 585230f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@
// under the License.

#include "arrow/io/file.h"
#include "arrow/io/interfaces.h"
#include "arrow/ipc/reader.h"
#include "arrow/matlab/error/error.h"
#include "arrow/matlab/io/ipc/proxy/record_batch_file_reader.h"
#include "arrow/matlab/tabular/proxy/record_batch.h"
#include "arrow/matlab/tabular/proxy/record_batch.h"
#include "arrow/util/utf8.h"

#include "libmexclass/proxy/ProxyManager.h"

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

RecordBatchFileReader::RecordBatchFileReader(std::shared_ptr<arrow::ipc::RecordBatchFileReader> reader) : reader{std::move(reader)} {
REGISTER_METHOD(RecordBatchFileReader, getNumRecordBatches);
REGISTER_METHOD(RecordBatchFileReader, readRecordBatch);

}

libmexclass::proxy::MakeResult RecordBatchFileReader::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
Expand Down Expand Up @@ -59,6 +63,27 @@ void RecordBatchFileReader::getNumRecordBatches(libmexclass::proxy::method::Cont
context.outputs[0] = factory.createScalar(num_batches);
}

void RecordBatchFileReader::readRecordBatch(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<int32_t> matlab_index_mda = opts[0]["Index"];
const auto matlab_index = matlab_index_mda[0];

const auto arrow_index = matlab_index - 1;

MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(const auto record_batch, reader->ReadRecordBatch(arrow_index),
context, "arrow:matlab:ipc:readfailed");

auto record_batch_proxy = std::make_shared<RecordBatchProxy>(std::move(record_batch));
const auto record_batch_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(record_batch_proxy);

mda::ArrayFactory factory;
const auto record_batch_proxyy_id_mda = factory.createScalar(record_batch_proxy_id);
context.outputs[0] = record_batch_proxyy_id_mda;
}



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

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

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

std::shared_ptr<arrow::ipc::RecordBatchFileReader> reader;

};
Expand Down

0 comments on commit 585230f

Please sign in to comment.