Skip to content

Commit fe2d926

Browse files
authored
apacheGH-41803: [MATLAB] Add C Data Interface format import/export functionality for arrow.tabular.RecordBatch (apache#41817)
### Rationale for this change This pull requests adds two new APIs for importing and exporting `arrow.tabular.RecordBatch` instances using the C Data Interface format. **Example:** ```matlab >> T = table((1:3)', ["A"; "B"; "C"]); >> expected = arrow.recordBatch(T) expected = Arrow RecordBatch with 3 rows and 2 columns: Schema: Var1: Float64 | Var2: String First Row: 1 | "A" >> cArray = arrow.c.Array(); >> cSchema = arrow.c.Schema(); % Export the RecordBatch to C Data Interface Format >> expected.export(cArray.Address, cSchema.Address); % Import the RecordBatch from C Data Interface Format >> actual = arrow.tabular.RecordBatch.import(cArray, cSchema) actual = Arrow RecordBatch with 3 rows and 2 columns: Schema: Var1: Float64 | Var2: String First Row: 1 | "A" % The RecordBatch is the same after round-tripping to the C Data Interface format >> isequal(actual, expected) ans = logical 1 ``` ### What changes are included in this PR? 1. Added a new method `arrow.tabular.RecordBatch.export` for exporting `RecordBatch` objects to the C Data Interface format. 2. Added a new static method `arrow.tabular.RecordBatch.import` for importing `RecordBatch` objects from the C Data Interface format. 3. Added a new internal class `arrow.c.internal.RecordBatchImporter` for importing `RecordBatch` objects from the C Data Interface format. ### Are these changes tested? Yes. 1. Added a new test file `matlab/test/arrow/c/tRoundtripRecordBatch.m` which has basic round-trip tests for importing and exporting `RecordBatch` objects. ### Are there any user-facing changes? Yes. 1. Two new user-facing methods were added to `arrow.tabular.RecordBatch`. The first is `arrow.tabular.RecordBatch.export(cArrowArrayAddress, cArrowSchemaAddress)`. The second is `arrow.tabular.RecordBatch.import(cArray, cSchema)`. These APIs can be used to export/import `RecordBatch` objects using the C Data Interface format. ### Future Directions 1. Add integration tests for sharing data between MATLAB/mlarrow and Python/pyarrow running in the same process using the [MATLAB interface to Python](https://www.mathworks.com/help/matlab/call-python-libraries.html). 2. Add support for the Arrow [C stream interface format](https://arrow.apache.org/docs/format/CStreamInterface.html). ### Notes 1. Thanks to @ kevingurney for the help with this feature! * GitHub Issue: apache#41803 Authored-by: Sarah Gilmore <sgilmore@mathworks.com> Signed-off-by: Sarah Gilmore <sgilmore@mathworks.com>
1 parent f904928 commit fe2d926

File tree

9 files changed

+420
-54
lines changed

9 files changed

+420
-54
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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/c/bridge.h"
19+
20+
#include "arrow/matlab/c/proxy/record_batch_importer.h"
21+
#include "arrow/matlab/error/error.h"
22+
#include "arrow/matlab/tabular/proxy/record_batch.h"
23+
24+
#include "libmexclass/proxy/ProxyManager.h"
25+
26+
namespace arrow::matlab::c::proxy {
27+
28+
RecordBatchImporter::RecordBatchImporter() {
29+
REGISTER_METHOD(RecordBatchImporter, import);
30+
}
31+
32+
libmexclass::proxy::MakeResult RecordBatchImporter::make(
33+
const libmexclass::proxy::FunctionArguments& constructor_arguments) {
34+
return std::make_shared<RecordBatchImporter>();
35+
}
36+
37+
void RecordBatchImporter::import(libmexclass::proxy::method::Context& context) {
38+
namespace mda = ::matlab::data;
39+
using namespace libmexclass::proxy;
40+
using RecordBatchProxy = arrow::matlab::tabular::proxy::RecordBatch;
41+
42+
mda::StructArray args = context.inputs[0];
43+
const mda::TypedArray<uint64_t> arrow_array_address_mda = args[0]["ArrowArrayAddress"];
44+
const mda::TypedArray<uint64_t> arrow_schema_address_mda =
45+
args[0]["ArrowSchemaAddress"];
46+
47+
const auto arrow_array_address = uint64_t(arrow_array_address_mda[0]);
48+
const auto arrow_schema_address = uint64_t(arrow_schema_address_mda[0]);
49+
50+
auto arrow_array = reinterpret_cast<struct ArrowArray*>(arrow_array_address);
51+
auto arrow_schema = reinterpret_cast<struct ArrowSchema*>(arrow_schema_address);
52+
53+
MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto record_batch,
54+
arrow::ImportRecordBatch(arrow_array, arrow_schema),
55+
context, error::C_IMPORT_FAILED);
56+
57+
auto record_batch_proxy = std::make_shared<RecordBatchProxy>(std::move(record_batch));
58+
59+
mda::ArrayFactory factory;
60+
const auto record_batch_proxy_id = ProxyManager::manageProxy(record_batch_proxy);
61+
const auto record_batch_proxy_id_mda = factory.createScalar(record_batch_proxy_id);
62+
63+
context.outputs[0] = record_batch_proxy_id_mda;
64+
}
65+
66+
} // namespace arrow::matlab::c::proxy
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
#pragma once
19+
20+
#include "libmexclass/proxy/Proxy.h"
21+
22+
namespace arrow::matlab::c::proxy {
23+
24+
class RecordBatchImporter : public libmexclass::proxy::Proxy {
25+
public:
26+
RecordBatchImporter();
27+
28+
~RecordBatchImporter() = default;
29+
30+
static libmexclass::proxy::MakeResult make(
31+
const libmexclass::proxy::FunctionArguments& constructor_arguments);
32+
33+
protected:
34+
void import(libmexclass::proxy::method::Context& context);
35+
};
36+
37+
} // namespace arrow::matlab::c::proxy

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

+53-51
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "arrow/matlab/buffer/proxy/buffer.h"
2828
#include "arrow/matlab/c/proxy/array.h"
2929
#include "arrow/matlab/c/proxy/array_importer.h"
30+
#include "arrow/matlab/c/proxy/record_batch_importer.h"
3031
#include "arrow/matlab/c/proxy/schema.h"
3132
#include "arrow/matlab/error/error.h"
3233
#include "arrow/matlab/io/csv/proxy/table_reader.h"
@@ -54,57 +55,58 @@ namespace arrow::matlab::proxy {
5455
libmexclass::proxy::MakeResult Factory::make_proxy(
5556
const ClassName& class_name, const FunctionArguments& constructor_arguments) {
5657
// clang-format off
57-
REGISTER_PROXY(arrow.array.proxy.Float32Array , arrow::matlab::array::proxy::NumericArray<arrow::FloatType>);
58-
REGISTER_PROXY(arrow.array.proxy.Float64Array , arrow::matlab::array::proxy::NumericArray<arrow::DoubleType>);
59-
REGISTER_PROXY(arrow.array.proxy.UInt8Array , arrow::matlab::array::proxy::NumericArray<arrow::UInt8Type>);
60-
REGISTER_PROXY(arrow.array.proxy.UInt16Array , arrow::matlab::array::proxy::NumericArray<arrow::UInt16Type>);
61-
REGISTER_PROXY(arrow.array.proxy.UInt32Array , arrow::matlab::array::proxy::NumericArray<arrow::UInt32Type>);
62-
REGISTER_PROXY(arrow.array.proxy.UInt64Array , arrow::matlab::array::proxy::NumericArray<arrow::UInt64Type>);
63-
REGISTER_PROXY(arrow.array.proxy.Int8Array , arrow::matlab::array::proxy::NumericArray<arrow::Int8Type>);
64-
REGISTER_PROXY(arrow.array.proxy.Int16Array , arrow::matlab::array::proxy::NumericArray<arrow::Int16Type>);
65-
REGISTER_PROXY(arrow.array.proxy.Int32Array , arrow::matlab::array::proxy::NumericArray<arrow::Int32Type>);
66-
REGISTER_PROXY(arrow.array.proxy.Int64Array , arrow::matlab::array::proxy::NumericArray<arrow::Int64Type>);
67-
REGISTER_PROXY(arrow.array.proxy.BooleanArray , arrow::matlab::array::proxy::BooleanArray);
68-
REGISTER_PROXY(arrow.array.proxy.StringArray , arrow::matlab::array::proxy::StringArray);
69-
REGISTER_PROXY(arrow.array.proxy.StructArray , arrow::matlab::array::proxy::StructArray);
70-
REGISTER_PROXY(arrow.array.proxy.ListArray , arrow::matlab::array::proxy::ListArray);
71-
REGISTER_PROXY(arrow.array.proxy.TimestampArray, arrow::matlab::array::proxy::NumericArray<arrow::TimestampType>);
72-
REGISTER_PROXY(arrow.array.proxy.Time32Array , arrow::matlab::array::proxy::NumericArray<arrow::Time32Type>);
73-
REGISTER_PROXY(arrow.array.proxy.Time64Array , arrow::matlab::array::proxy::NumericArray<arrow::Time64Type>);
74-
REGISTER_PROXY(arrow.array.proxy.Date32Array , arrow::matlab::array::proxy::NumericArray<arrow::Date32Type>);
75-
REGISTER_PROXY(arrow.array.proxy.Date64Array , arrow::matlab::array::proxy::NumericArray<arrow::Date64Type>);
76-
REGISTER_PROXY(arrow.array.proxy.ChunkedArray , arrow::matlab::array::proxy::ChunkedArray);
77-
REGISTER_PROXY(arrow.buffer.proxy.Buffer , arrow::matlab::buffer::proxy::Buffer);
78-
REGISTER_PROXY(arrow.tabular.proxy.RecordBatch , arrow::matlab::tabular::proxy::RecordBatch);
79-
REGISTER_PROXY(arrow.tabular.proxy.Table , arrow::matlab::tabular::proxy::Table);
80-
REGISTER_PROXY(arrow.tabular.proxy.Schema , arrow::matlab::tabular::proxy::Schema);
81-
REGISTER_PROXY(arrow.type.proxy.Field , arrow::matlab::type::proxy::Field);
82-
REGISTER_PROXY(arrow.type.proxy.Float32Type , arrow::matlab::type::proxy::PrimitiveCType<float>);
83-
REGISTER_PROXY(arrow.type.proxy.Float64Type , arrow::matlab::type::proxy::PrimitiveCType<double>);
84-
REGISTER_PROXY(arrow.type.proxy.UInt8Type , arrow::matlab::type::proxy::PrimitiveCType<uint8_t>);
85-
REGISTER_PROXY(arrow.type.proxy.UInt16Type , arrow::matlab::type::proxy::PrimitiveCType<uint16_t>);
86-
REGISTER_PROXY(arrow.type.proxy.UInt32Type , arrow::matlab::type::proxy::PrimitiveCType<uint32_t>);
87-
REGISTER_PROXY(arrow.type.proxy.UInt64Type , arrow::matlab::type::proxy::PrimitiveCType<uint64_t>);
88-
REGISTER_PROXY(arrow.type.proxy.Int8Type , arrow::matlab::type::proxy::PrimitiveCType<int8_t>);
89-
REGISTER_PROXY(arrow.type.proxy.Int16Type , arrow::matlab::type::proxy::PrimitiveCType<int16_t>);
90-
REGISTER_PROXY(arrow.type.proxy.Int32Type , arrow::matlab::type::proxy::PrimitiveCType<int32_t>);
91-
REGISTER_PROXY(arrow.type.proxy.Int64Type , arrow::matlab::type::proxy::PrimitiveCType<int64_t>);
92-
REGISTER_PROXY(arrow.type.proxy.BooleanType , arrow::matlab::type::proxy::PrimitiveCType<bool>);
93-
REGISTER_PROXY(arrow.type.proxy.StringType , arrow::matlab::type::proxy::StringType);
94-
REGISTER_PROXY(arrow.type.proxy.TimestampType , arrow::matlab::type::proxy::TimestampType);
95-
REGISTER_PROXY(arrow.type.proxy.Time32Type , arrow::matlab::type::proxy::Time32Type);
96-
REGISTER_PROXY(arrow.type.proxy.Time64Type , arrow::matlab::type::proxy::Time64Type);
97-
REGISTER_PROXY(arrow.type.proxy.Date32Type , arrow::matlab::type::proxy::Date32Type);
98-
REGISTER_PROXY(arrow.type.proxy.Date64Type , arrow::matlab::type::proxy::Date64Type);
99-
REGISTER_PROXY(arrow.type.proxy.StructType , arrow::matlab::type::proxy::StructType);
100-
REGISTER_PROXY(arrow.type.proxy.ListType , arrow::matlab::type::proxy::ListType);
101-
REGISTER_PROXY(arrow.io.feather.proxy.Writer , arrow::matlab::io::feather::proxy::Writer);
102-
REGISTER_PROXY(arrow.io.feather.proxy.Reader , arrow::matlab::io::feather::proxy::Reader);
103-
REGISTER_PROXY(arrow.io.csv.proxy.TableWriter , arrow::matlab::io::csv::proxy::TableWriter);
104-
REGISTER_PROXY(arrow.io.csv.proxy.TableReader , arrow::matlab::io::csv::proxy::TableReader);
105-
REGISTER_PROXY(arrow.c.proxy.Array , arrow::matlab::c::proxy::Array);
106-
REGISTER_PROXY(arrow.c.proxy.ArrayImporter , arrow::matlab::c::proxy::ArrayImporter);
107-
REGISTER_PROXY(arrow.c.proxy.Schema , arrow::matlab::c::proxy::Schema);
58+
REGISTER_PROXY(arrow.array.proxy.Float32Array , arrow::matlab::array::proxy::NumericArray<arrow::FloatType>);
59+
REGISTER_PROXY(arrow.array.proxy.Float64Array , arrow::matlab::array::proxy::NumericArray<arrow::DoubleType>);
60+
REGISTER_PROXY(arrow.array.proxy.UInt8Array , arrow::matlab::array::proxy::NumericArray<arrow::UInt8Type>);
61+
REGISTER_PROXY(arrow.array.proxy.UInt16Array , arrow::matlab::array::proxy::NumericArray<arrow::UInt16Type>);
62+
REGISTER_PROXY(arrow.array.proxy.UInt32Array , arrow::matlab::array::proxy::NumericArray<arrow::UInt32Type>);
63+
REGISTER_PROXY(arrow.array.proxy.UInt64Array , arrow::matlab::array::proxy::NumericArray<arrow::UInt64Type>);
64+
REGISTER_PROXY(arrow.array.proxy.Int8Array , arrow::matlab::array::proxy::NumericArray<arrow::Int8Type>);
65+
REGISTER_PROXY(arrow.array.proxy.Int16Array , arrow::matlab::array::proxy::NumericArray<arrow::Int16Type>);
66+
REGISTER_PROXY(arrow.array.proxy.Int32Array , arrow::matlab::array::proxy::NumericArray<arrow::Int32Type>);
67+
REGISTER_PROXY(arrow.array.proxy.Int64Array , arrow::matlab::array::proxy::NumericArray<arrow::Int64Type>);
68+
REGISTER_PROXY(arrow.array.proxy.BooleanArray , arrow::matlab::array::proxy::BooleanArray);
69+
REGISTER_PROXY(arrow.array.proxy.StringArray , arrow::matlab::array::proxy::StringArray);
70+
REGISTER_PROXY(arrow.array.proxy.StructArray , arrow::matlab::array::proxy::StructArray);
71+
REGISTER_PROXY(arrow.array.proxy.ListArray , arrow::matlab::array::proxy::ListArray);
72+
REGISTER_PROXY(arrow.array.proxy.TimestampArray , arrow::matlab::array::proxy::NumericArray<arrow::TimestampType>);
73+
REGISTER_PROXY(arrow.array.proxy.Time32Array , arrow::matlab::array::proxy::NumericArray<arrow::Time32Type>);
74+
REGISTER_PROXY(arrow.array.proxy.Time64Array , arrow::matlab::array::proxy::NumericArray<arrow::Time64Type>);
75+
REGISTER_PROXY(arrow.array.proxy.Date32Array , arrow::matlab::array::proxy::NumericArray<arrow::Date32Type>);
76+
REGISTER_PROXY(arrow.array.proxy.Date64Array , arrow::matlab::array::proxy::NumericArray<arrow::Date64Type>);
77+
REGISTER_PROXY(arrow.array.proxy.ChunkedArray , arrow::matlab::array::proxy::ChunkedArray);
78+
REGISTER_PROXY(arrow.buffer.proxy.Buffer , arrow::matlab::buffer::proxy::Buffer);
79+
REGISTER_PROXY(arrow.tabular.proxy.RecordBatch , arrow::matlab::tabular::proxy::RecordBatch);
80+
REGISTER_PROXY(arrow.tabular.proxy.Table , arrow::matlab::tabular::proxy::Table);
81+
REGISTER_PROXY(arrow.tabular.proxy.Schema , arrow::matlab::tabular::proxy::Schema);
82+
REGISTER_PROXY(arrow.type.proxy.Field , arrow::matlab::type::proxy::Field);
83+
REGISTER_PROXY(arrow.type.proxy.Float32Type , arrow::matlab::type::proxy::PrimitiveCType<float>);
84+
REGISTER_PROXY(arrow.type.proxy.Float64Type , arrow::matlab::type::proxy::PrimitiveCType<double>);
85+
REGISTER_PROXY(arrow.type.proxy.UInt8Type , arrow::matlab::type::proxy::PrimitiveCType<uint8_t>);
86+
REGISTER_PROXY(arrow.type.proxy.UInt16Type , arrow::matlab::type::proxy::PrimitiveCType<uint16_t>);
87+
REGISTER_PROXY(arrow.type.proxy.UInt32Type , arrow::matlab::type::proxy::PrimitiveCType<uint32_t>);
88+
REGISTER_PROXY(arrow.type.proxy.UInt64Type , arrow::matlab::type::proxy::PrimitiveCType<uint64_t>);
89+
REGISTER_PROXY(arrow.type.proxy.Int8Type , arrow::matlab::type::proxy::PrimitiveCType<int8_t>);
90+
REGISTER_PROXY(arrow.type.proxy.Int16Type , arrow::matlab::type::proxy::PrimitiveCType<int16_t>);
91+
REGISTER_PROXY(arrow.type.proxy.Int32Type , arrow::matlab::type::proxy::PrimitiveCType<int32_t>);
92+
REGISTER_PROXY(arrow.type.proxy.Int64Type , arrow::matlab::type::proxy::PrimitiveCType<int64_t>);
93+
REGISTER_PROXY(arrow.type.proxy.BooleanType , arrow::matlab::type::proxy::PrimitiveCType<bool>);
94+
REGISTER_PROXY(arrow.type.proxy.StringType , arrow::matlab::type::proxy::StringType);
95+
REGISTER_PROXY(arrow.type.proxy.TimestampType , arrow::matlab::type::proxy::TimestampType);
96+
REGISTER_PROXY(arrow.type.proxy.Time32Type , arrow::matlab::type::proxy::Time32Type);
97+
REGISTER_PROXY(arrow.type.proxy.Time64Type , arrow::matlab::type::proxy::Time64Type);
98+
REGISTER_PROXY(arrow.type.proxy.Date32Type , arrow::matlab::type::proxy::Date32Type);
99+
REGISTER_PROXY(arrow.type.proxy.Date64Type , arrow::matlab::type::proxy::Date64Type);
100+
REGISTER_PROXY(arrow.type.proxy.StructType , arrow::matlab::type::proxy::StructType);
101+
REGISTER_PROXY(arrow.type.proxy.ListType , arrow::matlab::type::proxy::ListType);
102+
REGISTER_PROXY(arrow.io.feather.proxy.Writer , arrow::matlab::io::feather::proxy::Writer);
103+
REGISTER_PROXY(arrow.io.feather.proxy.Reader , arrow::matlab::io::feather::proxy::Reader);
104+
REGISTER_PROXY(arrow.io.csv.proxy.TableWriter , arrow::matlab::io::csv::proxy::TableWriter);
105+
REGISTER_PROXY(arrow.io.csv.proxy.TableReader , arrow::matlab::io::csv::proxy::TableReader);
106+
REGISTER_PROXY(arrow.c.proxy.Array , arrow::matlab::c::proxy::Array);
107+
REGISTER_PROXY(arrow.c.proxy.ArrayImporter , arrow::matlab::c::proxy::ArrayImporter);
108+
REGISTER_PROXY(arrow.c.proxy.Schema , arrow::matlab::c::proxy::Schema);
109+
REGISTER_PROXY(arrow.c.proxy.RecordBatchImporter , arrow::matlab::c::proxy::RecordBatchImporter);
108110
// clang-format on
109111

110112
return libmexclass::error::Error{error::UNKNOWN_PROXY_ERROR_ID,

matlab/src/cpp/arrow/matlab/tabular/proxy/record_batch.cc

+17-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
#include "libmexclass/proxy/ProxyManager.h"
19-
18+
#include "arrow/c/bridge.h"
2019
#include "arrow/matlab/array/proxy/array.h"
2120
#include "arrow/matlab/array/proxy/wrap.h"
2221

@@ -66,6 +65,7 @@ RecordBatch::RecordBatch(std::shared_ptr<arrow::RecordBatch> record_batch)
6665
REGISTER_METHOD(RecordBatch, getColumnByName);
6766
REGISTER_METHOD(RecordBatch, getSchema);
6867
REGISTER_METHOD(RecordBatch, getRowAsString);
68+
REGISTER_METHOD(RecordBatch, exportToC);
6969
}
7070

7171
std::shared_ptr<arrow::RecordBatch> RecordBatch::unwrap() { return record_batch; }
@@ -259,4 +259,19 @@ void RecordBatch::getRowAsString(libmexclass::proxy::method::Context& context) {
259259
context.outputs[0] = factory.createScalar(row_str_utf16);
260260
}
261261

262+
void RecordBatch::exportToC(libmexclass::proxy::method::Context& context) {
263+
namespace mda = ::matlab::data;
264+
mda::StructArray opts = context.inputs[0];
265+
const mda::TypedArray<uint64_t> array_address_mda = opts[0]["ArrowArrayAddress"];
266+
const mda::TypedArray<uint64_t> schema_address_mda = opts[0]["ArrowSchemaAddress"];
267+
268+
auto arrow_array = reinterpret_cast<struct ArrowArray*>(uint64_t(array_address_mda[0]));
269+
auto arrow_schema =
270+
reinterpret_cast<struct ArrowSchema*>(uint64_t(schema_address_mda[0]));
271+
272+
MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
273+
arrow::ExportRecordBatch(*record_batch, arrow_array, arrow_schema), context,
274+
error::C_EXPORT_FAILED);
275+
}
276+
262277
} // namespace arrow::matlab::tabular::proxy

matlab/src/cpp/arrow/matlab/tabular/proxy/record_batch.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class RecordBatch : public libmexclass::proxy::Proxy {
4343
void getColumnByName(libmexclass::proxy::method::Context& context);
4444
void getSchema(libmexclass::proxy::method::Context& context);
4545
void getRowAsString(libmexclass::proxy::method::Context& context);
46+
void exportToC(libmexclass::proxy::method::Context& context);
4647

4748
std::shared_ptr<arrow::RecordBatch> record_batch;
4849
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
%RECORDBATCHIMPORTER Imports Arrow RecordBatch using the C Data Interface
2+
% Format.
3+
4+
% Licensed to the Apache Software Foundation (ASF) under one or more
5+
% contributor license agreements. See the NOTICE file distributed with
6+
% this work for additional information regarding copyright ownership.
7+
% The ASF licenses this file to you under the Apache License, Version
8+
% 2.0 (the "License"); you may not use this file except in compliance
9+
% with the License. You may obtain a copy of the License at
10+
%
11+
% http://www.apache.org/licenses/LICENSE-2.0
12+
%
13+
% Unless required by applicable law or agreed to in writing, software
14+
% distributed under the License is distributed on an "AS IS" BASIS,
15+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16+
% implied. See the License for the specific language governing
17+
% permissions and limitations under the License.
18+
19+
classdef RecordBatchImporter
20+
21+
properties (Hidden, SetAccess=private, GetAccess=public)
22+
Proxy
23+
end
24+
25+
methods
26+
27+
function obj = RecordBatchImporter()
28+
proxyName = "arrow.c.proxy.RecordBatchImporter";
29+
proxy = arrow.internal.proxy.create(proxyName, struct());
30+
obj.Proxy = proxy;
31+
end
32+
33+
function recordBatch = import(obj, cArray, cSchema)
34+
arguments
35+
obj(1, 1) arrow.c.internal.RecordBatchImporter
36+
cArray(1, 1) arrow.c.Array
37+
cSchema(1, 1) arrow.c.Schema
38+
end
39+
args = struct(...
40+
ArrowArrayAddress=cArray.Address,...
41+
ArrowSchemaAddress=cSchema.Address...
42+
);
43+
proxyID = obj.Proxy.import(args);
44+
proxyName = "arrow.tabular.proxy.RecordBatch";
45+
proxy = libmexclass.proxy.Proxy(Name=proxyName, ID=proxyID);
46+
recordBatch = arrow.tabular.RecordBatch(proxy);
47+
end
48+
49+
end
50+
51+
end
52+

0 commit comments

Comments
 (0)