Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MATLAB] Make arrow.type.Type inherit from matlab.mixin.Heterogeneous #37591

Closed
sgilmore10 opened this issue Sep 6, 2023 · 1 comment · Fixed by #37593
Closed

[MATLAB] Make arrow.type.Type inherit from matlab.mixin.Heterogeneous #37591

sgilmore10 opened this issue Sep 6, 2023 · 1 comment · Fixed by #37593

Comments

@sgilmore10
Copy link
Member

sgilmore10 commented Sep 6, 2023

Describe the enhancement requested

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

>> 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:

>> 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.

Component(s)

MATLAB

@sgilmore10
Copy link
Member Author

take

kevingurney pushed a commit that referenced this issue Sep 6, 2023
…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>
@kevingurney kevingurney added this to the 14.0.0 milestone Sep 6, 2023
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
…mixin.Heterogeneous` (apache#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: apache#37591

Authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
dgreiss pushed a commit to dgreiss/arrow that referenced this issue Feb 19, 2024
…mixin.Heterogeneous` (apache#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: apache#37591

Authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants