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
+ // Licensed to the Apache Software Foundation (ASF) under one
19
+ // or more contributor license agreements. See the NOTICE file
20
+ // distributed with this work for additional information
21
+ // regarding copyright ownership. The ASF licenses this file
22
+ // to you under the Apache License, Version 2.0 (the
23
+ // "License"); you may not use this file except in compliance
24
+ // with the License. You may obtain a copy of the License at
25
+ //
26
+ // http://www.apache.org/licenses/LICENSE-2.0
27
+ //
28
+ // Unless required by applicable law or agreed to in writing,
29
+ // software distributed under the License is distributed on an
30
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
31
+ // KIND, either express or implied. See the License for the
32
+ // specific language governing permissions and limitations
33
+ // under the License.
34
+
35
+ #include " arrow/record_batch.h"
36
+ #include " arrow/c/bridge.h"
37
+
38
+ #include " arrow/matlab/c/proxy/record_batch_importer.h"
39
+ #include " arrow/matlab/tabular/proxy/record_batch.h"
40
+ #include " arrow/matlab/error/error.h"
41
+
42
+ #include " libmexclass/proxy/ProxyManager.h"
43
+
44
+ namespace arrow ::matlab::c::proxy {
45
+
46
+ RecordBatchImporter::RecordBatchImporter () {
47
+ // Register Proxy methods.
48
+ REGISTER_METHOD (RecordBatchImporter, importFromC);
49
+ }
50
+
51
+ libmexclass::proxy::MakeResult RecordBatchImporter::make (const libmexclass::proxy::FunctionArguments& constructor_arguments) {
52
+ return std::make_shared<RecordBatchImporter>();
53
+ }
54
+
55
+ void RecordBatchImporter::importFromC (libmexclass::proxy::method::Context& context) {
56
+ namespace mda = ::matlab::data;
57
+ using namespace libmexclass ::proxy;
58
+ using RecordBatchProxy = arrow::matlab::tabular::proxy::RecordBatch;
59
+
60
+ mda::StructArray args = context.inputs [0 ];
61
+ const mda::TypedArray<uint64_t > array_address_mda = args[0 ][" ArrowArrayAddress" ];
62
+ const mda::TypedArray<uint64_t > schema_address_mda = args[0 ][" ArrowSchemaAddress" ];
63
+
64
+ const auto array_address = uint64_t (array_address_mda[0 ]);
65
+ const auto schema_address = uint64_t (schema_address_mda[0 ]);
66
+
67
+ struct ArrowArray * arrow_array = reinterpret_cast <struct ArrowArray *>(array_address);
68
+ struct ArrowSchema * arrow_schema = reinterpret_cast <struct ArrowSchema *>(schema_address);
69
+
70
+ MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT (std::shared_ptr<arrow::RecordBatch> record_batch,
71
+ arrow::ImportRecordBatch (arrow_array, arrow_schema),
72
+ context, " arrow:c:ImportFailed" );
73
+
74
+ auto record_batch_proxy = std::make_shared<RecordBatchProxy>(record_batch);
75
+
76
+ mda::ArrayFactory factory;
77
+ const auto record_batch_proxy_id = ProxyManager::manageProxy (record_batch_proxy);
78
+ const auto record_batch_proxy_id_mda = factory.createScalar (record_batch_proxy_id);
79
+ context.outputs [0 ] = record_batch_proxy_id_mda;
80
+ }
81
+
82
+ } // namespace arrow::matlab::c::proxy
0 commit comments