Skip to content

Commit 35c7cad

Browse files
committed
Implement RecordBatchFileReader::getSchema(...)
1 parent b944604 commit 35c7cad

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818
#include "arrow/io/file.h"
1919
#include "arrow/matlab/error/error.h"
2020
#include "arrow/matlab/io/ipc/proxy/record_batch_file_reader.h"
21+
#include "arrow/matlab/tabular/proxy/schema.h"
2122
#include "arrow/util/utf8.h"
2223

24+
#include "libmexclass/proxy/ProxyManager.h"
25+
2326
namespace arrow::matlab::io::ipc::proxy {
2427

2528
RecordBatchFileReader::RecordBatchFileReader(const std::shared_ptr<arrow::ipc::RecordBatchFileReader> reader)
2629
: reader{std::move(reader)} {
2730
REGISTER_METHOD(RecordBatchFileReader, getNumRecordBatches);
31+
REGISTER_METHOD(RecordBatchFileReader, getSchema);
32+
2833
}
2934

3035
libmexclass::proxy::MakeResult RecordBatchFileReader::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
@@ -58,6 +63,22 @@ void RecordBatchFileReader::getNumRecordBatches(libmexclass::proxy::method::Cont
5863
context.outputs[0] = factory.createScalar(num_batches);
5964
}
6065

66+
void RecordBatchFileReader::getSchema(libmexclass::proxy::method::Context& context) {
67+
namespace mda = ::matlab::data;
68+
using SchemaProxy = arrow::matlab::tabular::proxy::Schema;
69+
70+
auto schema = reader->schema();
71+
72+
auto schema_proxy = std::make_shared<SchemaProxy>(std::move(schema));
73+
const auto schema_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(schema_proxy);
74+
75+
mda::ArrayFactory factory;
76+
const auto schema_proxy_id_mda = factory.createScalar(schema_proxy_id);
77+
context.outputs[0] = schema_proxy_id_mda;
78+
79+
}
80+
81+
6182

6283

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class RecordBatchFileReader : public libmexclass::proxy::Proxy {
3535

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

38+
void getSchema(libmexclass::proxy::method::Context& context);
39+
40+
3841
};
3942

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

0 commit comments

Comments
 (0)