Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions matlab/src/cpp/arrow/matlab/error/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,6 @@ static const char* IPC_RECORD_BATCH_READER_OPEN_FAILED =
"arrow:io:ipc:FailedToOpenRecordBatchReader";
static const char* IPC_RECORD_BATCH_READ_INVALID_INDEX = "arrow:io:ipc:InvalidIndex";
static const char* IPC_RECORD_BATCH_READ_FAILED = "arrow:io:ipc:ReadFailed";
static const char* IPC_TABLE_READ_FAILED = "arrow:io:ipc:TableReadFailed";

} // namespace arrow::matlab::error
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ RecordBatchFileReader::RecordBatchFileReader(
REGISTER_METHOD(RecordBatchFileReader, getNumRecordBatches);
REGISTER_METHOD(RecordBatchFileReader, getSchema);
REGISTER_METHOD(RecordBatchFileReader, readRecordBatchAtIndex);
REGISTER_METHOD(RecordBatchFileReader, readTable);
}

libmexclass::proxy::MakeResult RecordBatchFileReader::make(
Expand Down Expand Up @@ -125,4 +126,21 @@ void RecordBatchFileReader::readRecordBatchAtIndex(
context.outputs[0] = record_batch_proxyy_id_mda;
}

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

MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto table,
reader->ToTable(), context,
error::IPC_TABLE_READ_FAILED);
auto table_proxy = std::make_shared<TableProxy>(std::move(table));
const auto table_proxy_id =
libmexclass::proxy::ProxyManager::manageProxy(table_proxy);

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

} // namespace arrow::matlab::io::ipc::proxy
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class RecordBatchFileReader : public libmexclass::proxy::Proxy {
void getSchema(libmexclass::proxy::method::Context& context);

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

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

} // namespace arrow::matlab::io::ipc::proxy
15 changes: 15 additions & 0 deletions matlab/test/arrow/io/ipc/tRecordBatchFileReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,20 @@ function readAtIndex(testCase)
expected2 = arrow.recordBatch(t2);
testCase.verifyEqual(actual2, expected2);
end

function readTable(testCase)
% Verify readTable returns the expected table for the given
% file
// t1 = table(["Row1"; "Row2"], single([1; 2]), VariableNames=["A", "B"]);
// t2 = table(["Row3"; "Row4"], single([3; 4]), VariableNames=["A", "B"]);
expectedTable = [t1];

reader = arrow.io.ipc.RecordBatchFileReader(testCase.MultipleBatchFile);
actualTable = reader.readTable();

testCase.verifyEqual(actualTable, expectedTable);
testCase.verifyClass(actualTable, "table");
testCase.verifySize(actualTable, [4, 2]);
end
end
end
Loading