15
15
// specific language governing permissions and limitations
16
16
// under the License.
17
17
18
+ #include " arrow/io/file.h"
19
+ #include " arrow/matlab/error/error.h"
18
20
#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
+
19
27
20
28
namespace arrow ::matlab::io::ipc::proxy {
21
29
22
30
RecordBatchFileWriter::RecordBatchFileWriter (const std::shared_ptr<arrow::ipc::RecordBatchWriter> writer)
23
31
: writer{std::move (writer)} {}
24
32
25
33
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));
27
60
}
61
+
28
62
} // namespace arrow::matlab::io::ipc::proxy
0 commit comments