1
+ // Licensed to the Apache Software Foundation (ASF) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The ASF licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+
18
+ #include " arrow/io/file.h"
19
+ #include " arrow/io/interfaces.h"
20
+ #include " arrow/ipc/reader.h"
21
+ #include " arrow/matlab/error/error.h"
22
+ #include " arrow/matlab/io/ipc/proxy/record_batch_file_reader.h"
23
+ #include " arrow/util/utf8.h"
24
+
25
+
26
+ namespace arrow ::matlab::io::ipc::proxy {
27
+
28
+ RecordBatchFileReader::RecordBatchFileReader (std::shared_ptr<arrow::ipc::RecordBatchFileReader> reader) : reader{std::move (reader)} {
29
+ REGISTER_METHOD (RecordBatchFileReader, getNumRecordBatches);
30
+ }
31
+
32
+ libmexclass::proxy::MakeResult RecordBatchFileReader::make (const libmexclass::proxy::FunctionArguments& constructor_arguments) {
33
+ namespace mda = ::matlab::data;
34
+ using RecordBatchFileReaderProxy = arrow::matlab::io::ipc::proxy::RecordBatchFileReader;
35
+
36
+ mda::StructArray opts = constructor_arguments[0 ];
37
+ const mda::StringArray filename_mda = opts[0 ][" Filename" ];
38
+
39
+ const auto filename_utf16 = std::u16string (filename_mda[0 ]);
40
+ MATLAB_ASSIGN_OR_ERROR (const auto filename_utf8,
41
+ arrow::util::UTF16StringToUTF8 (filename_utf16),
42
+ error::UNICODE_CONVERSION_ERROR_ID);
43
+
44
+ MATLAB_ASSIGN_OR_ERROR (auto input_stream,
45
+ arrow::io::ReadableFile::Open (filename_utf8),
46
+ error::FAILED_TO_OPEN_FILE_FOR_WRITE);
47
+
48
+ MATLAB_ASSIGN_OR_ERROR (auto reader,
49
+ arrow::ipc::RecordBatchFileReader::Open (input_stream),
50
+ " arrow:matlab:MakeFailed" );
51
+
52
+ return std::make_shared<RecordBatchFileReaderProxy>(std::move (reader));
53
+ }
54
+
55
+ void RecordBatchFileReader::getNumRecordBatches (libmexclass::proxy::method::Context& context) {
56
+ namespace mda = ::matlab::data;
57
+ mda::ArrayFactory factory;
58
+ const auto num_batches = reader->num_record_batches ();
59
+ context.outputs [0 ] = factory.createScalar (num_batches);
60
+ }
61
+
62
+
63
+
64
+ } // namespace arrow::matlab::io::ipc::proxy
0 commit comments