Skip to content

Commit 390a4a6

Browse files
committed
Add exportToC method to Array Proxy C++ class.
1 parent 8204552 commit 390a4a6

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

matlab/src/cpp/arrow/matlab/array/proxy/array.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
#include "arrow/c/bridge.h"
1819
#include "arrow/util/utf8.h"
1920

2021
#include "arrow/matlab/array/proxy/array.h"
@@ -40,6 +41,7 @@ Array::Array(std::shared_ptr<arrow::Array> array) : array{std::move(array)} {
4041
REGISTER_METHOD(Array, getType);
4142
REGISTER_METHOD(Array, isEqual);
4243
REGISTER_METHOD(Array, slice);
44+
REGISTER_METHOD(Array, exportToC);
4345
}
4446

4547
std::shared_ptr<arrow::Array> Array::unwrap() { return array; }
@@ -178,4 +180,17 @@ void Array::slice(libmexclass::proxy::method::Context& context) {
178180
output[0]["TypeID"] = factory.createScalar(type_id);
179181
context.outputs[0] = output;
180182
}
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+
181196
} // namespace arrow::matlab::array::proxy

matlab/src/cpp/arrow/matlab/array/proxy/array.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class Array : public libmexclass::proxy::Proxy {
4545

4646
void slice(libmexclass::proxy::method::Context& context);
4747

48+
void exportToC(libmexclass::proxy::method::Context& context);
49+
4850
std::shared_ptr<arrow::Array> array;
4951
};
5052

matlab/src/cpp/arrow/matlab/error/error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,6 @@ static const char* ARRAY_SLICE_NON_POSITIVE_OFFSET =
240240
static const char* ARRAY_SLICE_NEGATIVE_LENGTH = "arrow:array:slice:NegativeLength";
241241
static const char* ARRAY_SLICE_FAILED_TO_CREATE_ARRAY_PROXY =
242242
"arrow:array:slice:FailedToCreateArrayProxy";
243+
static const char* C_EXPORT_FAILED = "arrow:c:export:ExportFailed";
243244

244245
} // namespace arrow::matlab::error

0 commit comments

Comments
 (0)