MCPcopy Create free account
hub / github.com/apache/arrow / read

Method read

matlab/src/cpp/arrow/matlab/io/feather/proxy/reader.cc:53–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53void Reader::read(libmexclass::proxy::method::Context& context) {
54 namespace mda = ::matlab::data;
55 using namespace libmexclass::proxy;
56 using RecordBatchProxy = arrow::matlab::tabular::proxy::RecordBatch;
57
58 mda::ArrayFactory factory;
59
60 // Create a file input stream.
61 MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(
62 auto source, arrow::io::ReadableFile::Open(filename, arrow::default_memory_pool()),
63 context, error::FAILED_TO_OPEN_FILE_FOR_READ);
64
65 // Create a Reader from the file input stream.
66 MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto reader,
67 arrow::ipc::feather::Reader::Open(source), context,
68 error::FEATHER_FAILED_TO_CREATE_READER);
69
70 // Error if not Feather V1.
71 const auto version = reader->version();
72 if (version == ipc::feather::kFeatherV2Version) {
73 MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
74 Status::NotImplemented("Support for Feather V2 has not been implemented."),
75 context, error::FEATHER_VERSION_2);
76 } else if (version != ipc::feather::kFeatherV1Version) {
77 MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
78 Status::Invalid("Unknown Feather format version."), context,
79 error::FEATHER_VERSION_UNKNOWN);
80 }
81
82 // Read a Table from the file.
83 std::shared_ptr<arrow::Table> table = nullptr;
84 MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(reader->Read(&table), context,
85 error::FEATHER_FAILED_TO_READ_TABLE);
86
87 // Combine all the chunks of the Table into a single RecordBatch.
88 MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(
89 const auto record_batch, table->CombineChunksToBatch(arrow::default_memory_pool()),
90 context, error::FEATHER_FAILED_TO_READ_RECORD_BATCH);
91
92 // Create a Proxy from the first RecordBatch.
93 auto record_batch_proxy = std::make_shared<RecordBatchProxy>(record_batch);
94 const auto record_batch_proxy_id = ProxyManager::manageProxy(record_batch_proxy);
95
96 const auto record_batch_proxy_id_mda = factory.createScalar(record_batch_proxy_id);
97
98 context.outputs[0] = record_batch_proxy_id_mda;
99}
100
101void Reader::getFilename(libmexclass::proxy::method::Context& context) {
102 namespace mda = ::matlab::data;

Callers

nothing calls this directly

Calls 4

NotImplementedFunction · 0.50
InvalidFunction · 0.50
versionMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected