Skip to content

Commit

Permalink
GH-37049: [MATLAB] Update feather Reader and Writer objects to wo…
Browse files Browse the repository at this point in the history
…rk directly with `arrow.tabular.RecordBatch`s instead of MATLAB `table`s (#37052)

### Rationale for this change

After thinking about how to re-implement `featherread` and `featherwrite`, we realized it would be better if the `Reader` and `Writer` classes worked directly with `arrow.tabular.RecordBatch`s instead of MATLAB `table`s. 

### What changes are included in this PR?

1. Updated `read` method of `arrow.internal.io.feather.Reader` to return an `arrow.tabular.RecordBatch` rather than a MATLAB `table`.
2. Updated `write` method of `arrow.internal.io.feather.Writer` to accept an `arrow.tabular.RecordBatch` rather than a MATLAB `table`.

### Are these changes tested?

Yes.

1. Updated `feather/tRoundTrip.m` to reflect the changes to the `Reader` and `Writer` classes.

### Are there any user-facing changes?

1. No

These are internal APIs.
* Closes: #37049

Authored-by: Kevin Gurney <kgurney@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
  • Loading branch information
kevingurney authored Aug 7, 2023
1 parent 56c1f3e commit feb10f3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
3 changes: 1 addition & 2 deletions matlab/src/matlab/+arrow/+internal/+io/+feather/Reader.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@
obj.Proxy = arrow.internal.proxy.create("arrow.io.feather.proxy.Reader", args);
end

function T = read(obj)
function recordBatch = read(obj)
recordBatchProxyID = obj.Proxy.read();
proxy = libmexclass.proxy.Proxy(Name="arrow.tabular.proxy.RecordBatch", ID=recordBatchProxyID);
recordBatch = arrow.tabular.RecordBatch(proxy);
T = recordBatch.toMATLAB();
end

function filename = get.Filename(obj)
Expand Down
5 changes: 2 additions & 3 deletions matlab/src/matlab/+arrow/+internal/+io/+feather/Writer.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
obj.Proxy = arrow.internal.proxy.create(proxyName, args);
end

function write(obj, T)
rb = arrow.recordbatch(T);
args = struct(RecordBatchProxyID=rb.Proxy.ID);
function write(obj, recordBatch)
args = struct(RecordBatchProxyID=recordBatch.Proxy.ID);
obj.Proxy.write(args);
end

Expand Down
3 changes: 2 additions & 1 deletion matlab/src/matlab/featherwrite.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function featherwrite(filename, t)
t table
end

recordBatch = arrow.recordbatch(t);
writer = arrow.internal.io.feather.Writer(filename);
writer.write(t);
writer.write(recordBatch);
end
30 changes: 15 additions & 15 deletions matlab/test/arrow/io/feather/tRoundTrip.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ function addFeatherFunctionsToMATLABPath(testCase)
methods(Test)
function Basic(testCase)
import matlab.unittest.fixtures.TemporaryFolderFixture

import arrow.internal.io.feather.*

fixture = testCase.applyFixture(TemporaryFolderFixture);
filename = fullfile(fixture.Folder, "temp.feather");

DoubleVar = [10; 20; 30; 40];
SingleVar = single([10; 15; 20; 25]);
tWrite = table(DoubleVar, SingleVar);

featherwrite(tWrite, filename);
tRead = featherread(filename);
testCase.verifyEqual(tWrite, tRead);

tableWrite = table(DoubleVar, SingleVar);
recordBatchWrite = arrow.recordbatch(tableWrite);

writer = Writer(filename);
writer.write(recordBatchWrite);

reader = arrow.internal.io.feather.Reader(filename);
recordBatchRead = reader.read();

tableRead = table(recordBatchRead);

testCase.verifyEqual(tableWrite, tableRead);
end
end
end

function featherwrite(T, filename)
writer = arrow.internal.io.feather.Writer(filename);
writer.write(T);
end

function T = featherread(filename)
reader = arrow.internal.io.feather.Reader(filename);
T = reader.read();
end

0 comments on commit feb10f3

Please sign in to comment.