Commits


sgilmore10 authored and GitHub committed f7b6ddbe878
GH-37591: [MATLAB] Make `arrow.type.Type` inherit from `matlab.mixin.Heterogeneous` (#37593) ### Rationale for this change We should modify `arrow.type.Type` to inherit from `matlab.mixin.Heterogeneous` so that it's possible to create a nonscalar array containing different concrete subclasses of `arrow.type.Type`. **Example** ```matlab >> float32Type = arrow.float32(); >> timestampType = arrow.timestamp(TimeZone="Pacific/Fiji"); >> typeArray = [float32Type timestampType] typeArray = 1×2 heterogeneous FixedWidthType (Float32Type, TimestampType) array with properties: ID ``` Currently, running the example above results in an error: ```matlab >> float32Type = arrow.float32(); >> timestampType = arrow.timestamp(TimeZone="Pacific/Fiji"); >> typeArray = [float32Type timestampType] Error using horzcat The following error occurred converting from arrow.type.TimestampType to arrow.type.Float32Type: Invalid argument at position 1. Value must be of type libmexclass.proxy.Proxy or be convertible to libmexclass.proxy.Proxy. ``` ### What changes are included in this PR? 1. Updated `arrow.type.Type` to inherit from `matlab.mixin.Heterogeneous`. Previously, it only inherited from `matlab.mixin.CustomDisplay`. 2. Because `arrow.type.Type` is now `heterogeneous`, its subclasses cannot override the protected method `getPropertyGroups` - which is inherited from `matlab.mixin.CustomDisplay`. This method must be `Sealed` and defined on `Type` because only `Sealed` methods can be called on nonscalar `heterogeneous` arrays. To get around this limitation, I defined a new abstract template method called `getDisplayPropertyGroups`, which `getPropertyGroups` invokes if the array is either scalar or nonscalar and `homogeneous`. Refer to [this link](https://www.mathworks.com/help/matlab/matlab_oop/custom-display-for-heterogeneous-arrays.html) for more details. **Displaying a nonscalar *heterogeneous* `arrow.type.Type`** ```matlab >> float32Type = arrow.timestamp(TimeUnit="Second"); >> timestampType = arrow.timestamp(TimeZone="Pacific/Fiji"); >> typeArray = [float32Type timestampType] typeArray = 1×2 heterogeneous FixedWidthType (Float32Type, TimestampType) array with properties: ID ``` **Displaying a nonscalar *homogeneous* `arrow.type.Type`** ```matlab >> timestampType1 = arrow.timestamp(TimeUnit="Second"); >> timestampType2 = arrow.timestamp(TimeZone="Pacific/Fiji"); >> typeArray = [timestampType1 timestampType2] typeArray = 1×2 TimestampType array with properties: ID TimeUnit TimeZone ``` ### Are these changes tested? Yes 1. Added a new test class in `test/arrow/type` called `tDisplay.m` 2. Added display unit tests for all concrete subclasses of `arrow.type.Type` if they did not already exist. 3. Added a new test class in `test/arrow/type` called `tIsEqual.m`. This class contains unit tests verifying the `isequal` method of `arrow.type.Type` behaves as expected when called on heterogeneous arrays. ### Are there any user-facing changes? Yes. Users can now create nonscalar arrays with different concrete subclasses of `arrow.type.Type`. ### Future Directions 1. Move all display unit tests to `tDisplay.m` 2. Add an `arrow.type.NumericType` class from which all numeric types inherit. This class will define `getDisplayPropertyGroups` for all numeric types. * Closes: #37591 Authored-by: Sarah Gilmore <sgilmore@mathworks.com> Signed-off-by: Kevin Gurney <kgurney@mathworks.com>