15
15
// specific language governing permissions and limitations
16
16
// under the License.
17
17
18
+ #include " arrow/c/bridge.h"
18
19
#include " arrow/util/utf8.h"
19
20
20
21
#include " arrow/matlab/array/proxy/array.h"
@@ -40,6 +41,7 @@ Array::Array(std::shared_ptr<arrow::Array> array) : array{std::move(array)} {
40
41
REGISTER_METHOD (Array, getType);
41
42
REGISTER_METHOD (Array, isEqual);
42
43
REGISTER_METHOD (Array, slice);
44
+ REGISTER_METHOD (Array, exportToC);
43
45
}
44
46
45
47
std::shared_ptr<arrow::Array> Array::unwrap () { return array; }
@@ -178,4 +180,17 @@ void Array::slice(libmexclass::proxy::method::Context& context) {
178
180
output[0 ][" TypeID" ] = factory.createScalar (type_id);
179
181
context.outputs [0 ] = output;
180
182
}
183
+
184
+ void Array::exportToC (libmexclass::proxy::method::Context& context) {
185
+ namespace mda = ::matlab::data;
186
+ mda::StructArray opts = context.inputs [0 ];
187
+ const mda::TypedArray<uint64_t > array_address_mda = opts[0 ][" ArrowArrayAddress" ];
188
+ const mda::TypedArray<uint64_t > schema_address_mda = opts[0 ][" ArrowSchemaAddress" ];
189
+
190
+ struct ArrowArray * arrow_array = reinterpret_cast <struct ArrowArray *>(uint64_t (array_address_mda[0 ]));
191
+ struct ArrowSchema * arrow_schema = reinterpret_cast <struct ArrowSchema *>(uint64_t (schema_address_mda[0 ]));
192
+
193
+ MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT (arrow::ExportArray (*array, arrow_array, arrow_schema), context, error::C_EXPORT_FAILED);
194
+ }
195
+
181
196
} // namespace arrow::matlab::array::proxy
0 commit comments