This is an automated email from the ASF dual-hosted git repository.
kevingurney pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new feb10f357d GH-37049: [MATLAB] Update feather `Reader` and `Writer`
objects to work directly with `arrow.tabular.RecordBatch`s instead of MATLAB
`table`s (#37052)
feb10f357d is described below
commit feb10f357d824a1bdadbed59b82403da13b42d28
Author: Kevin Gurney <[email protected]>
AuthorDate: Mon Aug 7 17:19:33 2023 -0400
GH-37049: [MATLAB] Update feather `Reader` and `Writer` objects to work
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 <[email protected]>
Signed-off-by: Kevin Gurney <[email protected]>
---
.../matlab/+arrow/+internal/+io/+feather/Reader.m | 3 +--
.../matlab/+arrow/+internal/+io/+feather/Writer.m | 5 ++--
matlab/src/matlab/featherwrite.m | 3 ++-
matlab/test/arrow/io/feather/tRoundTrip.m | 30 +++++++++++-----------
4 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/matlab/src/matlab/+arrow/+internal/+io/+feather/Reader.m
b/matlab/src/matlab/+arrow/+internal/+io/+feather/Reader.m
index 80da7294d2..6cd7864676 100644
--- a/matlab/src/matlab/+arrow/+internal/+io/+feather/Reader.m
+++ b/matlab/src/matlab/+arrow/+internal/+io/+feather/Reader.m
@@ -36,11 +36,10 @@ classdef Reader
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)
diff --git a/matlab/src/matlab/+arrow/+internal/+io/+feather/Writer.m
b/matlab/src/matlab/+arrow/+internal/+io/+feather/Writer.m
index 37c785f10a..64872ba4a0 100644
--- a/matlab/src/matlab/+arrow/+internal/+io/+feather/Writer.m
+++ b/matlab/src/matlab/+arrow/+internal/+io/+feather/Writer.m
@@ -35,9 +35,8 @@ classdef Writer < matlab.mixin.Scalar
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
diff --git a/matlab/src/matlab/featherwrite.m b/matlab/src/matlab/featherwrite.m
index cc3f45e954..879edd8afc 100644
--- a/matlab/src/matlab/featherwrite.m
+++ b/matlab/src/matlab/featherwrite.m
@@ -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
diff --git a/matlab/test/arrow/io/feather/tRoundTrip.m
b/matlab/test/arrow/io/feather/tRoundTrip.m
index e735d196c1..f361a4543b 100644
--- a/matlab/test/arrow/io/feather/tRoundTrip.m
+++ b/matlab/test/arrow/io/feather/tRoundTrip.m
@@ -31,27 +31,27 @@ classdef tRoundTrip < matlab.unittest.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
\ No newline at end of file