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 e90c316030 GH-37045: [MATLAB] Implement featherwrite in terms of 
arrow.internal.io.feather.Writer (#37047)
e90c316030 is described below

commit e90c3160301351d68e19c5f76f001ba5cc71bdfb
Author: sgilmore10 <74676073+sgilmor...@users.noreply.github.com>
AuthorDate: Mon Aug 7 16:38:43 2023 -0400

    GH-37045: [MATLAB] Implement featherwrite in terms of 
arrow.internal.io.feather.Writer (#37047)
    
    
    
    ### Rationale for this change
    
    Now that #37043 is merged, we can re-implement `featherwrite` in terms of 
the new `arrow.internal.io.feather.Writer` class. Once this change is made, we 
can delete the legacy build infrastructure and featherwrite MEX code.
    
    ### What changes are included in this PR?
    
    1. Re-implemented `featherwrite` using `arrow.internal.io.feather.Writer`.
    
    ### Are these changes tested?
    
    1. Yes, the existing tests in `tfeather.m` cover these changes.
    2. I had to update some of the expected error message IDs in `tfeather.m` 
because the new implementation throws errors with different IDs.
    3. `featherwrite` used to export the real part of MATLAB complex numeric 
arrays. The new version of `featherwrite` now errors if the input table 
contains complex data because feather/Arrow itself does not support complex 
numeric data. We think this is the right decision. Writing out only the real 
part is lossy.
    
    ### Are there any user-facing changes?
    
    Yes, `featherwrite` no longer supports writing complex numeric arrays.
    
    ### Future Directions
    
    1. Once this PR is merged, we will remove the legacy build infrastructure 
and MEX code.
    * Closes: #37045
    
    Authored-by: Sarah Gilmore <sgilm...@mathworks.com>
    Signed-off-by: Kevin Gurney <kgur...@mathworks.com>
---
 matlab/src/matlab/featherwrite.m | 22 ++++++----------------
 matlab/test/tfeather.m           | 11 +++++------
 2 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/matlab/src/matlab/featherwrite.m b/matlab/src/matlab/featherwrite.m
index c59f7f4236..cc3f45e954 100644
--- a/matlab/src/matlab/featherwrite.m
+++ b/matlab/src/matlab/featherwrite.m
@@ -23,21 +23,11 @@ function featherwrite(filename, t)
 % specific language governing permissions and limitations
 % under the License.
 
-import arrow.util.table2mlarrow;
+    arguments
+        filename(1, 1) string {mustBeNonmissing, mustBeNonzeroLengthText}
+        t table
+    end
 
-% Validate input arguments.
-narginchk(2, 2);
-filename = convertStringsToChars(filename);
-if ~ischar(filename)
-    error('MATLAB:arrow:InvalidFilenameDatatype', ...
-        'Filename must be a character vector or string scalar.');
-end
-if ~istable(t)
-    error('MATLAB:arrow:InvalidInputTable', 't must be a table.');
-end
-
-[variables, metadata] = table2mlarrow(t);
-
-% Write the table to a Feather file.
-arrow.cpp.call('featherwrite', filename, variables, metadata);
+    writer = arrow.internal.io.feather.Writer(filename);
+    writer.write(t);
 end
diff --git a/matlab/test/tfeather.m b/matlab/test/tfeather.m
index a32b78fdcd..e4c988e1dd 100755
--- a/matlab/test/tfeather.m
+++ b/matlab/test/tfeather.m
@@ -164,7 +164,7 @@ classdef tfeather < matlab.unittest.TestCase
             
             t = createTable;
             
-            testCase.verifyError(@() featherwrite({filename}, t), 
'MATLAB:arrow:InvalidFilenameDatatype');
+            testCase.verifyError(@() featherwrite({table}, t), 
'MATLAB:validation:UnableToConvert');
             testCase.verifyError(@() featherread({filename}), 
'MATLAB:arrow:InvalidFilenameDatatype');
         end
 
@@ -178,7 +178,7 @@ classdef tfeather < matlab.unittest.TestCase
         end
 
         function ErrorIfTooFewInputs(testCase)
-            testCase.verifyError(@() featherwrite(), 
'MATLAB:narginchk:notEnoughInputs');
+            testCase.verifyError(@() featherwrite(), 'MATLAB:minrhs');
             testCase.verifyError(@() featherread(), 
'MATLAB:narginchk:notEnoughInputs');
         end
         
@@ -193,7 +193,7 @@ classdef tfeather < matlab.unittest.TestCase
             
             t = table(age, smoker, height, weight, bloodPressure);
             
-            testCase.verifyError(@() featherwrite(filename, t), 
'MATLAB:arrow:UnsupportedVariableType');
+            testCase.verifyError(@() featherwrite(filename, t), 
'arrow:array:InvalidShape');
         end
         
         function UnsupportedMATLABDatatypes(testCase)
@@ -205,7 +205,7 @@ classdef tfeather < matlab.unittest.TestCase
                                         calendarDuration(5, 3, 2)];
             actualTable = addvars(actualTable, calendarDurationVariable);
 
-            testCase.verifyError(@() featherwrite(filename, actualTable) 
,'MATLAB:arrow:UnsupportedVariableType');
+            testCase.verifyError(@() featherwrite(filename, actualTable) 
,'arrow:array:UnsupportedMATLABType');
         end
         
         function NumericComplexUnsupported(testCase)
@@ -216,8 +216,7 @@ classdef tfeather < matlab.unittest.TestCase
             actualTable.double(2) = exp(9) + 5i;
             actualTable.int64(2) = 1.0418e+03;
            
-            expectedTable = featherRoundTrip(filename, actualTable);
-            testCase.verifyNotEqual(actualTable, expectedTable);
+            testCase.verifyError(@() featherwrite(filename, actualTable) 
,'arrow:array:ComplexNumeric');
         end
     end
 end

Reply via email to