Skip to content

Commit 2eff6ab

Browse files
committed
Add functionality for converting mlarrow record batches to pyarrow record batches
1 parent 3a477ff commit 2eff6ab

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
function pyarrowArray = mlarrow2pyarrow(mlarrowArray)
2-
[cArrayWrapper, cSchemaWrapper] = pyrunfile(fullfile(pwd, "+internal/FFIWrapper.py"), ["cArrayWrapper" "cSchemaWrapper"]);
2+
folder = fileparts(mfilename("fullpath"));
3+
4+
[cArrayWrapper, cSchemaWrapper] = pyrunfile(fullfile(folder, "+internal/FFIWrapper.py"), ["cArrayWrapper" "cSchemaWrapper"]);
35

46
cArrayAddress = uint64(cArrayWrapper.getAddress());
57
cSchemaAdress = uint64(cSchemaWrapper.getAddress());
68

79
mlarrowArray.exportToC(cArrayAddress, cSchemaAdress);
810

9-
dummyArray = py.pyarrow.array([1 2]);
10-
importFunc = py.getattr(dummyArray, "_import_from_c");
11-
pyarrowArray = importFunc(cArrayAddress, cSchemaAdress);
11+
if isa(mlarrowArray, "arrow.array.Array")
12+
dummyArray = py.pyarrow.array([1 2]);
13+
importFunc = py.getattr(dummyArray, "_import_from_c");
14+
pyarrowArray = importFunc(cArrayAddress, cSchemaAdress);
15+
else
16+
dummyArray = py.pyarrow.array([1 2]);
17+
dummyRB = py.pyarrow.record_batch(py.list({dummyArray}), names={'Var1'});
18+
importFunc = py.getattr(dummyRB, "_import_from_c");
19+
pyarrowArray = importFunc(cArrayAddress, cSchemaAdress);
20+
end
1221
end
1322

matlab/src/matlab/+arrow/+c/pyarrow2mlarrow.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
exportFunc = py.getattr(pyarrowArray, "_export_to_c");
66
exportFunc(cArray.Address, cSchema.Address);
77

8-
mlarrowArray = arrow.array.Array.importFromC(cArray, cSchema);
9-
8+
if isa(pyarrowArray, "py.pyarrow.lib.Array")
9+
mlarrowArray = arrow.array.Array.importFromC(cArray, cSchema);
10+
else
11+
importer = arrow.c.internal.RecordBatchImporter();
12+
mlarrowArray = importer.import(cArray, cSchema);
13+
end
1014
end

matlab/src/matlab/+arrow/+tabular/RecordBatch.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,15 @@ function displayScalarObject(obj)
144144
end
145145

146146
methods(Hidden)
147-
function exportToC(cArrayAddress, cSchemaAddress)
148-
obj.Proxy.exportToC(cArrayAddress, cSchemaAddress);
147+
function exportToC(obj, cArrayAddress, cSchemaAddress)
148+
arguments
149+
obj(1, 1) arrow.tabular.RecordBatch
150+
cArrayAddress(1, 1) uint64
151+
cSchemaAddress(1, 1) uint64
152+
end
153+
args = struct(ArrowArrayAddress=cArrayAddress,...
154+
ArrowSchemaAddress=cSchemaAddress);
155+
obj.Proxy.exportToC(args);
149156
end
150157
end
151158
end

0 commit comments

Comments
 (0)