16
16
// under the License.
17
17
18
18
#include " arrow/util/utf8.h"
19
+ #include " arrow/c/bridge.h"
19
20
20
21
#include " arrow/matlab/array/proxy/array.h"
21
22
#include " arrow/matlab/array/proxy/wrap.h"
28
29
29
30
#include " libmexclass/proxy/ProxyManager.h"
30
31
32
+ #include < memory>
31
33
#include < sstream>
32
34
33
35
namespace arrow ::matlab::array::proxy {
@@ -40,6 +42,7 @@ Array::Array(std::shared_ptr<arrow::Array> array) : array{std::move(array)} {
40
42
REGISTER_METHOD (Array, getType);
41
43
REGISTER_METHOD (Array, isEqual);
42
44
REGISTER_METHOD (Array, slice);
45
+ REGISTER_METHOD (Array, exportToC);
43
46
}
44
47
45
48
std::shared_ptr<arrow::Array> Array::unwrap () { return array; }
@@ -178,4 +181,20 @@ void Array::slice(libmexclass::proxy::method::Context& context) {
178
181
output[0 ][" TypeID" ] = factory.createScalar (type_id);
179
182
context.outputs [0 ] = output;
180
183
}
184
+
185
+ void Array::exportToC (libmexclass::proxy::method::Context& context) {
186
+ namespace mda = ::matlab::data;
187
+
188
+ struct ArrowArray * arrow_array = new ArrowArray ();
189
+ struct ArrowSchema * arrow_schema = new ArrowSchema ();
190
+
191
+ MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT (
192
+ arrow::ExportArray (*array, arrow_array, arrow_schema), context, " arrow:cdata:error" );
193
+
194
+ mda::ArrayFactory factory;
195
+ mda::StructArray output = factory.createStructArray ({1 , 1 }, {" ArrowArrayAddress" , " ArrowSchemaAddress" });
196
+ output[0 ][" ArrowArrayAddress" ] = factory.createScalar (reinterpret_cast <uint64_t >(arrow_array));
197
+ output[0 ][" ArrowSchemaAddress" ] = factory.createScalar (reinterpret_cast <uint64_t >(arrow_schema));
198
+ }
199
+
181
200
} // namespace arrow::matlab::array::proxy
0 commit comments