You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2023/06/23 19:53:56 UTC

[arrow] branch main updated: GH-36251: [MATLAB] Add `Type` property to `arrow.array.Array` (#36270)

This is an automated email from the ASF dual-hosted git repository.

kou 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 6fc44889cc GH-36251: [MATLAB] Add `Type` property to `arrow.array.Array` (#36270)
6fc44889cc is described below

commit 6fc44889cccf056865f382bd3b37094bc730ea4a
Author: sgilmore10 <74...@users.noreply.github.com>
AuthorDate: Fri Jun 23 15:53:49 2023 -0400

    GH-36251: [MATLAB] Add `Type` property to `arrow.array.Array` (#36270)
    
    ### Rationale for this change
    
    Now that we've added the `arrow.type.Type` class hierarchy to the interface, we should add a property named `Type` to the base `arrow.array.Array` class.
    
    ### What changes are included in this PR?
    
    All concrete subclasses of the `arrow.array.Array` define a property named `Type`:
    
    ```matlab
    >> a = arrow.array.Float64Array([1 2 3 4])
    
    a =
    
    [
      1,
      2,
      3,
      4
    ]
    >> a.Type
    
    ans =
    
      Float64Type with properties:
    
                ID: Float64
          BitWidth: 64
         NumFields: 0
        NumBuffers: 2
    ```
    
    ### Are these changes tested?
    Yes, we added test cases in `hNumeric.m` and `tBooleanArray.m`.
    
    ### Are there any user-facing changes?
    
    Yes.
    
    ### Note
    
    1. I noticed that the `tInt16Array.m` test class did not define the `NullSubstitutionValue` property. This meant the test class was abstract, so its tests were not running. That was my mistake. We'll think about ways to verify all the appropriate tests are running in CI.
    2. As @ kou mentioned, we think it may be worth creating "Type" C++ proxy classes, especially when we start implementing nested array types. For now, we'll leave them as MATLAB-only classes, but will probably change their implementation soon.
    3. Thank you to @ kevingurney for the help!
    * Closes: #36251
    
    Authored-by: Sarah Gilmore <sg...@mathworks.com>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 matlab/src/matlab/+arrow/+array/Array.m        | 36 ++++++++++++++------------
 matlab/src/matlab/+arrow/+array/BooleanArray.m |  4 +++
 matlab/src/matlab/+arrow/+array/Float32Array.m |  4 +++
 matlab/src/matlab/+arrow/+array/Float64Array.m |  4 +++
 matlab/src/matlab/+arrow/+array/Int16Array.m   |  4 +++
 matlab/src/matlab/+arrow/+array/Int32Array.m   |  4 +++
 matlab/src/matlab/+arrow/+array/Int64Array.m   |  4 +++
 matlab/src/matlab/+arrow/+array/Int8Array.m    |  4 +++
 matlab/src/matlab/+arrow/+array/UInt16Array.m  |  4 +++
 matlab/src/matlab/+arrow/+array/UInt32Array.m  |  4 +++
 matlab/src/matlab/+arrow/+array/UInt64Array.m  |  4 +++
 matlab/src/matlab/+arrow/+array/UInt8Array.m   |  4 +++
 matlab/test/arrow/array/hNumericArray.m        |  8 ++++++
 matlab/test/arrow/array/tBooleanArray.m        | 10 ++++++-
 matlab/test/arrow/array/tFloat32Array.m        |  1 +
 matlab/test/arrow/array/tFloat64Array.m        |  1 +
 matlab/test/arrow/array/tInt16Array.m          |  2 ++
 matlab/test/arrow/array/tInt32Array.m          |  1 +
 matlab/test/arrow/array/tInt64Array.m          |  1 +
 matlab/test/arrow/array/tInt8Array.m           |  1 +
 matlab/test/arrow/array/tUInt16Array.m         |  1 +
 matlab/test/arrow/array/tUInt32Array.m         |  1 +
 matlab/test/arrow/array/tUInt64Array.m         |  1 +
 matlab/test/arrow/array/tUInt8Array.m          |  1 +
 24 files changed, 92 insertions(+), 17 deletions(-)

diff --git a/matlab/src/matlab/+arrow/+array/Array.m b/matlab/src/matlab/+arrow/+array/Array.m
index 7c3b5403d4..9b8796c33b 100644
--- a/matlab/src/matlab/+arrow/+array/Array.m
+++ b/matlab/src/matlab/+arrow/+array/Array.m
@@ -1,21 +1,21 @@
+% Licensed to the Apache Software Foundation (ASF) under one or more
+% contributor license agreements.  See the NOTICE file distributed with
+% this work for additional information regarding copyright ownership.
+% The ASF licenses this file to you under the Apache License, Version
+% 2.0 (the "License"); you may not use this file except in compliance
+% with the License.  You may obtain a copy of the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS,
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+% implied.  See the License for the specific language governing
+% permissions and limitations under the License.
+    
 classdef (Abstract) Array < matlab.mixin.CustomDisplay & ...
                             matlab.mixin.Scalar
-    % arrow.array.Array
-
-    % Licensed to the Apache Software Foundation (ASF) under one or more
-    % contributor license agreements.  See the NOTICE file distributed with
-    % this work for additional information regarding copyright ownership.
-    % The ASF licenses this file to you under the Apache License, Version
-    % 2.0 (the "License"); you may not use this file except in compliance
-    % with the License.  You may obtain a copy of the License at
-    %
-    %   http://www.apache.org/licenses/LICENSE-2.0
-    %
-    % Unless required by applicable law or agreed to in writing, software
-    % distributed under the License is distributed on an "AS IS" BASIS,
-    % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-    % implied.  See the License for the specific language governing
-    % permissions and limitations under the License.
+% arrow.array.Array
 
     properties (GetAccess=public, SetAccess=private, Hidden)
         Proxy
@@ -25,6 +25,10 @@ classdef (Abstract) Array < matlab.mixin.CustomDisplay & ...
         Length
         Valid % Validity bitmap
     end
+
+    properties(Abstract, SetAccess=private, GetAccess=public)
+        Type(1, 1) arrow.type.Type
+    end
     
     methods
         function obj = Array(varargin)
diff --git a/matlab/src/matlab/+arrow/+array/BooleanArray.m b/matlab/src/matlab/+arrow/+array/BooleanArray.m
index f4d341efce..e5c4cc527e 100644
--- a/matlab/src/matlab/+arrow/+array/BooleanArray.m
+++ b/matlab/src/matlab/+arrow/+array/BooleanArray.m
@@ -20,6 +20,10 @@ classdef BooleanArray < arrow.array.Array
         NullSubstitionValue = false;
     end
 
+    properties(SetAccess=private, GetAccess=public)
+        Type = arrow.type.BooleanType
+    end
+
     methods
         function obj = BooleanArray(data, opts)
             arguments
diff --git a/matlab/src/matlab/+arrow/+array/Float32Array.m b/matlab/src/matlab/+arrow/+array/Float32Array.m
index c6be563d86..29f23393a4 100644
--- a/matlab/src/matlab/+arrow/+array/Float32Array.m
+++ b/matlab/src/matlab/+arrow/+array/Float32Array.m
@@ -20,6 +20,10 @@ classdef Float32Array < arrow.array.NumericArray
         NullSubstitutionValue = single(NaN);
     end
 
+    properties(SetAccess=private, GetAccess=public)
+        Type = arrow.type.Float32Type
+    end
+
     methods
         function obj = Float32Array(data, varargin)
             obj@arrow.array.NumericArray(data, "single", ...
diff --git a/matlab/src/matlab/+arrow/+array/Float64Array.m b/matlab/src/matlab/+arrow/+array/Float64Array.m
index ff43ebc053..ab92715864 100644
--- a/matlab/src/matlab/+arrow/+array/Float64Array.m
+++ b/matlab/src/matlab/+arrow/+array/Float64Array.m
@@ -20,6 +20,10 @@ classdef Float64Array < arrow.array.NumericArray
         NullSubstitutionValue = NaN;
     end
 
+    properties(SetAccess=private, GetAccess=public)
+        Type = arrow.type.Float64Type
+    end
+
     methods
         function obj = Float64Array(data, varargin)
             obj@arrow.array.NumericArray(data, "double", ...
diff --git a/matlab/src/matlab/+arrow/+array/Int16Array.m b/matlab/src/matlab/+arrow/+array/Int16Array.m
index 533f0c9ef5..23716d5f59 100644
--- a/matlab/src/matlab/+arrow/+array/Int16Array.m
+++ b/matlab/src/matlab/+arrow/+array/Int16Array.m
@@ -20,6 +20,10 @@ classdef Int16Array < arrow.array.NumericArray
         NullSubstitutionValue = int16(0)
     end
 
+    properties(SetAccess=private, GetAccess=public)
+        Type = arrow.type.Int16Type
+    end
+
     methods
         function obj = Int16Array(data, varargin)
             obj@arrow.array.NumericArray(data, "int16", ...
diff --git a/matlab/src/matlab/+arrow/+array/Int32Array.m b/matlab/src/matlab/+arrow/+array/Int32Array.m
index 0f977fb90f..8844576ae1 100644
--- a/matlab/src/matlab/+arrow/+array/Int32Array.m
+++ b/matlab/src/matlab/+arrow/+array/Int32Array.m
@@ -20,6 +20,10 @@ classdef Int32Array < arrow.array.NumericArray
         NullSubstitutionValue = int32(0)
     end
 
+    properties(SetAccess=private, GetAccess=public)
+        Type = arrow.type.Int32Type
+    end
+
     methods
         function obj = Int32Array(data, varargin)
               obj@arrow.array.NumericArray(data, "int32", ...
diff --git a/matlab/src/matlab/+arrow/+array/Int64Array.m b/matlab/src/matlab/+arrow/+array/Int64Array.m
index 94cad56519..9f72c5f2a6 100644
--- a/matlab/src/matlab/+arrow/+array/Int64Array.m
+++ b/matlab/src/matlab/+arrow/+array/Int64Array.m
@@ -20,6 +20,10 @@ classdef Int64Array < arrow.array.NumericArray
         NullSubstitutionValue = int64(0);
     end
 
+    properties(SetAccess=private, GetAccess=public)
+        Type = arrow.type.Int64Type
+    end
+
     methods
         function obj = Int64Array(data, varargin)
           obj@arrow.array.NumericArray(data, "int64", ...
diff --git a/matlab/src/matlab/+arrow/+array/Int8Array.m b/matlab/src/matlab/+arrow/+array/Int8Array.m
index 83a14caa27..f9774f6527 100644
--- a/matlab/src/matlab/+arrow/+array/Int8Array.m
+++ b/matlab/src/matlab/+arrow/+array/Int8Array.m
@@ -20,6 +20,10 @@ classdef Int8Array < arrow.array.NumericArray
         NullSubstitutionValue = int8(0);
     end
 
+    properties(SetAccess=private, GetAccess=public)
+        Type = arrow.type.Int8Type
+    end
+
     methods
         function obj = Int8Array(data, varargin)
              obj@arrow.array.NumericArray(data, "int8", ...
diff --git a/matlab/src/matlab/+arrow/+array/UInt16Array.m b/matlab/src/matlab/+arrow/+array/UInt16Array.m
index 4862ca20b9..3732df3c76 100644
--- a/matlab/src/matlab/+arrow/+array/UInt16Array.m
+++ b/matlab/src/matlab/+arrow/+array/UInt16Array.m
@@ -20,6 +20,10 @@ classdef UInt16Array < arrow.array.NumericArray
         NullSubstitutionValue = uint16(0)
     end
 
+    properties(SetAccess=private, GetAccess=public)
+        Type = arrow.type.UInt16Type
+    end
+
     methods
         function obj = UInt16Array(data, varargin)
             obj@arrow.array.NumericArray(data, "uint16", ...
diff --git a/matlab/src/matlab/+arrow/+array/UInt32Array.m b/matlab/src/matlab/+arrow/+array/UInt32Array.m
index 782b001099..183d4df082 100644
--- a/matlab/src/matlab/+arrow/+array/UInt32Array.m
+++ b/matlab/src/matlab/+arrow/+array/UInt32Array.m
@@ -20,6 +20,10 @@ classdef UInt32Array < arrow.array.NumericArray
         NullSubstitutionValue = uint32(0)
     end
 
+    properties(SetAccess=private, GetAccess=public)
+        Type = arrow.type.UInt32Type
+    end
+
     methods
         function obj = UInt32Array(data, varargin)
             obj@arrow.array.NumericArray(data, "uint32", ...
diff --git a/matlab/src/matlab/+arrow/+array/UInt64Array.m b/matlab/src/matlab/+arrow/+array/UInt64Array.m
index 9e25ce4987..af828978ce 100644
--- a/matlab/src/matlab/+arrow/+array/UInt64Array.m
+++ b/matlab/src/matlab/+arrow/+array/UInt64Array.m
@@ -20,6 +20,10 @@ classdef UInt64Array < arrow.array.NumericArray
         NullSubstitutionValue = uint64(0)
     end
 
+    properties(SetAccess=private, GetAccess=public)
+        Type = arrow.type.UInt64Type
+    end
+
     methods
         function obj = UInt64Array(data, varargin)
             obj@arrow.array.NumericArray(data, "uint64", ...
diff --git a/matlab/src/matlab/+arrow/+array/UInt8Array.m b/matlab/src/matlab/+arrow/+array/UInt8Array.m
index 8bad2401bd..b5dc664ea1 100644
--- a/matlab/src/matlab/+arrow/+array/UInt8Array.m
+++ b/matlab/src/matlab/+arrow/+array/UInt8Array.m
@@ -20,6 +20,10 @@ classdef UInt8Array < arrow.array.NumericArray
         NullSubstitutionValue = uint8(0)
     end
 
+    properties(SetAccess=private, GetAccess=public)
+        Type = arrow.type.UInt8Type
+    end
+
     methods
         function obj = UInt8Array(data, varargin)
             obj@arrow.array.NumericArray(data, "uint8", ...
diff --git a/matlab/test/arrow/array/hNumericArray.m b/matlab/test/arrow/array/hNumericArray.m
index 42c839a0c8..4df50de7d2 100644
--- a/matlab/test/arrow/array/hNumericArray.m
+++ b/matlab/test/arrow/array/hNumericArray.m
@@ -24,6 +24,7 @@ classdef hNumericArray < matlab.unittest.TestCase
         MaxValue (1, 1)
         MinValue (1, 1)
         NullSubstitutionValue(1, 1)
+        ArrowType(1, 1)
     end
 
     properties (TestParameter)
@@ -157,5 +158,12 @@ classdef hNumericArray < matlab.unittest.TestCase
             tc.verifyEqual(toMATLAB(arrowArray), expectedData);
             tc.verifyEqual(arrowArray.Valid, [false; true; false; true]);
         end
+
+        function TestArrowType(tc)
+        % Verify the array has the expected arrow.type.Type object
+            data = tc.MatlabArrayFcn([1 2 3 4]);
+            arrowArray = tc.ArrowArrayConstructor(data);
+            tc.verifyEqual(arrowArray.Type, tc.ArrowType);
+        end
     end
 end
diff --git a/matlab/test/arrow/array/tBooleanArray.m b/matlab/test/arrow/array/tBooleanArray.m
index 2e8719a1e7..0d7f723ace 100644
--- a/matlab/test/arrow/array/tBooleanArray.m
+++ b/matlab/test/arrow/array/tBooleanArray.m
@@ -21,7 +21,8 @@ classdef tBooleanArray < matlab.unittest.TestCase
         ArrowArrayConstructor = @arrow.array.BooleanArray
         MatlabArrayFcn = @logical
         MatlabConversionFcn = @logical
-        NullSubstitutionValue(1, 1) = false
+        NullSubstitutionValue = false
+        ArrowType = arrow.type.BooleanType
     end
 
     methods(TestClassSetup)
@@ -140,5 +141,12 @@ classdef tBooleanArray < matlab.unittest.TestCase
             fcn = @() tc.ArrowArrayConstructor(data);
             tc.verifyError(fcn, "MATLAB:expectedNonsparse");
         end
+
+        function TestArrowType(tc)
+        % Verify the array has the expected arrow.type.Type object
+            data = tc.MatlabArrayFcn([true false]);
+            arrowArray = tc.ArrowArrayConstructor(data);
+            tc.verifyEqual(arrowArray.Type, tc.ArrowType);
+        end
     end
 end
diff --git a/matlab/test/arrow/array/tFloat32Array.m b/matlab/test/arrow/array/tFloat32Array.m
index 8e21adb0a1..0266fa6181 100644
--- a/matlab/test/arrow/array/tFloat32Array.m
+++ b/matlab/test/arrow/array/tFloat32Array.m
@@ -24,6 +24,7 @@ classdef tFloat32Array < hNumericArray
         MaxValue = realmax("single")
         MinValue = realmin("single")
         NullSubstitutionValue = single(NaN)
+        ArrowType = arrow.type.Float32Type
     end
 
     methods(Test)
diff --git a/matlab/test/arrow/array/tFloat64Array.m b/matlab/test/arrow/array/tFloat64Array.m
index 68c411da24..d956d33c68 100755
--- a/matlab/test/arrow/array/tFloat64Array.m
+++ b/matlab/test/arrow/array/tFloat64Array.m
@@ -24,6 +24,7 @@ classdef tFloat64Array < hNumericArray
         MaxValue = realmax("double")
         MinValue = realmin("double")
         NullSubstitutionValue = NaN
+        ArrowType = arrow.type.Float64Type
     end
 
     methods(Test)
diff --git a/matlab/test/arrow/array/tInt16Array.m b/matlab/test/arrow/array/tInt16Array.m
index 02c1e7c410..58193e076c 100644
--- a/matlab/test/arrow/array/tInt16Array.m
+++ b/matlab/test/arrow/array/tInt16Array.m
@@ -23,6 +23,8 @@ classdef tInt16Array < hNumericArray
         MatlabArrayFcn = @int16 % int16 function
         MaxValue = intmax("int16")
         MinValue = intmin("int16")
+        NullSubstitutionValue = int16(0)
+        ArrowType = arrow.type.Int16Type
     end
 
 end
diff --git a/matlab/test/arrow/array/tInt32Array.m b/matlab/test/arrow/array/tInt32Array.m
index a3ca28b832..59255c1272 100644
--- a/matlab/test/arrow/array/tInt32Array.m
+++ b/matlab/test/arrow/array/tInt32Array.m
@@ -24,5 +24,6 @@ classdef tInt32Array < hNumericArray
         MaxValue = intmax("int32")
         MinValue = intmin("int32")
         NullSubstitutionValue = int32(0)
+        ArrowType = arrow.type.Int32Type
     end
 end
diff --git a/matlab/test/arrow/array/tInt64Array.m b/matlab/test/arrow/array/tInt64Array.m
index 846460b576..289b4fcf3e 100644
--- a/matlab/test/arrow/array/tInt64Array.m
+++ b/matlab/test/arrow/array/tInt64Array.m
@@ -24,5 +24,6 @@ classdef tInt64Array < hNumericArray
         MaxValue = intmax("int64")
         MinValue = intmin("int64")
         NullSubstitutionValue = int64(0)
+        ArrowType = arrow.type.Int64Type
     end
 end
diff --git a/matlab/test/arrow/array/tInt8Array.m b/matlab/test/arrow/array/tInt8Array.m
index f8c1cf1574..9ae1eb8cc4 100644
--- a/matlab/test/arrow/array/tInt8Array.m
+++ b/matlab/test/arrow/array/tInt8Array.m
@@ -24,6 +24,7 @@ classdef tInt8Array < hNumericArray
         MaxValue = intmax("int8")
         MinValue = intmin("int8")
         NullSubstitutionValue = int8(0)
+        ArrowType = arrow.type.Int8Type
     end
 
 end
diff --git a/matlab/test/arrow/array/tUInt16Array.m b/matlab/test/arrow/array/tUInt16Array.m
index 5a9eb0ba9c..b79a753694 100644
--- a/matlab/test/arrow/array/tUInt16Array.m
+++ b/matlab/test/arrow/array/tUInt16Array.m
@@ -24,5 +24,6 @@ classdef tUInt16Array < hNumericArray
         MaxValue = intmax("uint16")
         MinValue = intmin("uint16")
         NullSubstitutionValue = uint16(0)
+        ArrowType = arrow.type.UInt16Type
     end
 end
diff --git a/matlab/test/arrow/array/tUInt32Array.m b/matlab/test/arrow/array/tUInt32Array.m
index f018f20305..157cad9417 100644
--- a/matlab/test/arrow/array/tUInt32Array.m
+++ b/matlab/test/arrow/array/tUInt32Array.m
@@ -24,5 +24,6 @@ classdef tUInt32Array < hNumericArray
         MaxValue = intmax("uint32")
         MinValue = intmin("uint32")
         NullSubstitutionValue = uint32(0)
+        ArrowType = arrow.type.UInt32Type
     end
 end
diff --git a/matlab/test/arrow/array/tUInt64Array.m b/matlab/test/arrow/array/tUInt64Array.m
index be4437ad13..41e479e816 100644
--- a/matlab/test/arrow/array/tUInt64Array.m
+++ b/matlab/test/arrow/array/tUInt64Array.m
@@ -24,5 +24,6 @@ classdef tUInt64Array < hNumericArray
         MaxValue = intmax("uint64")
         MinValue = intmin("uint64")
         NullSubstitutionValue = uint64(0)
+        ArrowType = arrow.type.UInt64Type
     end
 end
diff --git a/matlab/test/arrow/array/tUInt8Array.m b/matlab/test/arrow/array/tUInt8Array.m
index e43d646b82..4aca2cced1 100644
--- a/matlab/test/arrow/array/tUInt8Array.m
+++ b/matlab/test/arrow/array/tUInt8Array.m
@@ -24,5 +24,6 @@ classdef tUInt8Array < hNumericArray
         MaxValue = intmax("uint8")
         MinValue = intmin("uint8")
         NullSubstitutionValue = uint8(0)
+        ArrowType = arrow.type.UInt8Type
     end
 end