Skip to content

Commit fdb12d0

Browse files
committed
Implement RecordBatchFileWriter::make(...)
1 parent 6860ac2 commit fdb12d0

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,48 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
#include "arrow/io/file.h"
19+
#include "arrow/matlab/error/error.h"
1820
#include "arrow/matlab/io/ipc/proxy/record_batch_file_writer.h"
21+
#include "arrow/matlab/tabular/proxy/record_batch.h"
22+
#include "arrow/matlab/tabular/proxy/schema.h"
23+
#include "arrow/util/utf8.h"
24+
25+
#include "libmexclass/proxy/ProxyManager.h"
26+
1927

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

2230
RecordBatchFileWriter::RecordBatchFileWriter(const std::shared_ptr<arrow::ipc::RecordBatchWriter> writer)
2331
: writer{std::move(writer)} {}
2432

2533
libmexclass::proxy::MakeResult RecordBatchFileWriter::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
26-
return libmexclass::error::Error{"arrow:matlab:NotImplemented", "Not Implemented"};
34+
namespace mda = ::matlab::data;
35+
using RecordBatchFileWriterProxy = arrow::matlab::io::ipc::proxy::RecordBatchFileWriter;
36+
using SchemaProxy = arrow::matlab::tabular::proxy::Schema;
37+
38+
const mda::StructArray opts = constructor_arguments[0];
39+
40+
const mda::StringArray filename_mda = opts[0]["Filename"];
41+
const auto filename_utf16 = std::u16string(filename_mda[0]);
42+
MATLAB_ASSIGN_OR_ERROR(const auto filename_utf8,
43+
arrow::util::UTF16StringToUTF8(filename_utf16),
44+
error::UNICODE_CONVERSION_ERROR_ID);
45+
46+
const mda::TypedArray<uint64_t> arrow_schema_proxy_id_mda = opts[0]["SchemaProxyID"];
47+
auto proxy = libmexclass::proxy::ProxyManager::getProxy(arrow_schema_proxy_id_mda[0]);
48+
auto arrow_schema_proxy = std::static_pointer_cast<SchemaProxy>(proxy);
49+
auto arrow_schema = arrow_schema_proxy->unwrap();
50+
51+
MATLAB_ASSIGN_OR_ERROR(auto output_stream,
52+
arrow::io::FileOutputStream::Open(filename_utf8),
53+
error::FAILED_TO_OPEN_FILE_FOR_WRITE);
54+
55+
MATLAB_ASSIGN_OR_ERROR(auto writer,
56+
arrow::ipc::MakeFileWriter(output_stream, arrow_schema),
57+
"arrow:matlab:MakeFailed");
58+
59+
return std::make_shared<RecordBatchFileWriterProxy>(std::move(writer));
2760
}
61+
2862
} // namespace arrow::matlab::io::ipc::proxy

0 commit comments

Comments
 (0)