1919#include " arrow/io/file.h"
2020#include " arrow/matlab/error/error.h"
2121#include " arrow/matlab/tabular/proxy/record_batch.h"
22- #include " arrow/matlab/tabular/proxy/table.h"
2322#include " arrow/matlab/tabular/proxy/schema.h"
23+ #include " arrow/matlab/tabular/proxy/table.h"
2424#include " arrow/util/utf8.h"
2525
2626#include " libmexclass/proxy/ProxyManager.h"
@@ -39,7 +39,8 @@ RecordBatchStreamReader::RecordBatchStreamReader(
3939libmexclass::proxy::MakeResult RecordBatchStreamReader::make (
4040 const libmexclass::proxy::FunctionArguments& constructor_arguments) {
4141 namespace mda = ::matlab::data;
42- using RecordBatchStreamReaderProxy = arrow::matlab::io::ipc::proxy::RecordBatchStreamReader;
42+ using RecordBatchStreamReaderProxy =
43+ arrow::matlab::io::ipc::proxy::RecordBatchStreamReader;
4344
4445 const mda::StructArray opts = constructor_arguments[0 ];
4546
@@ -74,12 +75,12 @@ void RecordBatchStreamReader::getSchema(libmexclass::proxy::method::Context& con
7475 context.outputs [0 ] = schema_proxy_id_mda;
7576}
7677
77- void RecordBatchStreamReader::readTable (
78- libmexclass::proxy::method::Context& context) {
78+ void RecordBatchStreamReader::readTable (libmexclass::proxy::method::Context& context) {
7979 namespace mda = ::matlab::data;
8080 using TableProxy = arrow::matlab::tabular::proxy::Table;
8181
82- MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT (auto table, reader->ToTable (), context, error::IPC_TABLE_READ_FAILED);
82+ MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT (auto table, reader->ToTable (), context,
83+ error::IPC_TABLE_READ_FAILED);
8384 auto table_proxy = std::make_shared<TableProxy>(table);
8485 const auto table_proxy_id = libmexclass::proxy::ProxyManager::manageProxy (table_proxy);
8586
@@ -93,20 +94,27 @@ void RecordBatchStreamReader::readRecordBatch(
9394 namespace mda = ::matlab::data;
9495 using RecordBatchProxy = arrow::matlab::tabular::proxy::RecordBatch;
9596 using namespace libmexclass ::error;
96- // If we don't have a "pre-cached" record batch to return, then try reading another record batch
97- // from the IPC Stream. If there are no more record batches in the stream, then error.
97+ // If we don't have a "pre-cached" record batch to return, then try reading another
98+ // record batch from the IPC Stream. If there are no more record batches in the stream,
99+ // then error.
98100 if (!nextRecordBatch) {
99- MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT (nextRecordBatch, reader->Next (), context, error::IPC_RECORD_BATCH_READ_FAILED);
101+ MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT (nextRecordBatch, reader->Next (), context,
102+ error::IPC_RECORD_BATCH_READ_FAILED);
100103 }
101- // Even if the read was "successful", the resulting record batch may be empty, signalling the end of the stream.
104+ // Even if the read was "successful", the resulting record batch may be empty,
105+ // signalling the end of the stream.
102106 if (!nextRecordBatch) {
103- context.error = Error{" arrow:io:ipc:EndOfStream" , " Reached end of Arrow IPC Stream. No more record batches to read." };
104- return ;
107+ context.error =
108+ Error{" arrow:io:ipc:EndOfStream" ,
109+ " Reached end of Arrow IPC Stream. No more record batches to read." };
110+ return ;
105111 }
106112 auto record_batch_proxy = std::make_shared<RecordBatchProxy>(nextRecordBatch);
107- const auto record_batch_proxy_id = libmexclass::proxy::ProxyManager::manageProxy (record_batch_proxy);
113+ const auto record_batch_proxy_id =
114+ libmexclass::proxy::ProxyManager::manageProxy (record_batch_proxy);
108115 // Once we have "consumed" the next RecordBatch, set nextRecordBatch to nullptr
109- // so that the next call to hasNextRecordBatch correctly checks whether there are more record batches remaining in the IPC Stream.
116+ // so that the next call to hasNextRecordBatch correctly checks whether there are more
117+ // record batches remaining in the IPC Stream.
110118 nextRecordBatch = nullptr ;
111119 mda::ArrayFactory factory;
112120 const auto record_batch_proxy_id_mda = factory.createScalar (record_batch_proxy_id);
@@ -118,25 +126,25 @@ void RecordBatchStreamReader::hasNextRecordBatch(
118126 namespace mda = ::matlab::data;
119127 bool has_next_record_batch = true ;
120128 if (!nextRecordBatch) {
121- // Try to read another RecordBatch from the
122- // IPC Stream.
123- auto maybe_record_batch = reader->Next ();
124- if (!maybe_record_batch.ok ()) {
125- has_next_record_batch = false ;
126- } else {
127- // If we read a RecordBatch successfully,
128- // then "cache" the RecordBatch
129- // so that we can return it on the next
130- // call to readRecordBatch.
131- nextRecordBatch = *maybe_record_batch;
132-
133- // Even if the read was "successful", the resulting
134- // record batch may be empty, signaling that
135- // the end of the IPC stream has been reached.
136- if (!nextRecordBatch) {
137- has_next_record_batch = false ;
138- }
139- }
129+ // Try to read another RecordBatch from the
130+ // IPC Stream.
131+ auto maybe_record_batch = reader->Next ();
132+ if (!maybe_record_batch.ok ()) {
133+ has_next_record_batch = false ;
134+ } else {
135+ // If we read a RecordBatch successfully,
136+ // then "cache" the RecordBatch
137+ // so that we can return it on the next
138+ // call to readRecordBatch.
139+ nextRecordBatch = *maybe_record_batch;
140+
141+ // Even if the read was "successful", the resulting
142+ // record batch may be empty, signaling that
143+ // the end of the IPC stream has been reached.
144+ if (!nextRecordBatch) {
145+ has_next_record_batch = false ;
146+ }
147+ }
140148 }
141149
142150 mda::ArrayFactory factory;
0 commit comments