Skip to content

Commit

Permalink
apacheGH-37251: [MATLAB] Make arrow.type.TemporalType a "tag" class (
Browse files Browse the repository at this point in the history
…apache#37256)

### Rationale for this change

The original motivation for adding the super-class `arrow.type.TemporalType` in apache#37236 was to define a common implementation for extracting the `Unit` property from `TimestampType`, `Time32Type`, `Time64Type`, `Date32Type`, and `Date64Type`. However, this approach doesn't work because the `Unit` property on `Date32Type` and `Date64Type` is a `DateUnit`, while the `Unit` property on the other three types is a`TimeUnit`. As a result, we cannot define a shared method for extracting the `Unit` property in `TemporalType`. 

Instead, we plan on making `arrow.type.TemporalType` a "tag"-class (i.e. it has no properties or methods) so it can be used to group the "temporal" types together to ease authoring conditional logical in client code. In a future PR, we plan on adding functions like `arrow.type.isTemporal`, `arrow.type.isNumeric`, etc. so that clients don't need to query the class type information directly (i.e. call `isa(type, "arrow.type.TemporalType")`). 

```matlab
function doStuff(arrowArray)
  import arrow.*

  arrowType = arrowArray.Type;
  if type.isTemporal(arrowType)
      ...
  else if type.isNumeric(arrowType)
      ...
  else 
      ...
  end
end
```

### What changes are included in this PR?

1. Removed the `TimeUnit` property from `arrow.type.TemporalType`
2. Added `TimeUnit` back as a property on `arrow.type.TimestampType` and `arrow.type.Time32Type`

### Are these changes tested?

Yes, the existing tests cover these changes.

### Are there any user-facing changes?

No.

### Future Directions
1. apache#37232
2. apache#37229
3. apache#37230

* Closes: apache#37251

Authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
  • Loading branch information
sgilmore10 authored and loicalleyne committed Nov 13, 2023
1 parent ef606e2 commit bb9e097
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
9 changes: 0 additions & 9 deletions matlab/src/matlab/+arrow/+type/TemporalType.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,12 @@

classdef TemporalType < arrow.type.FixedWidthType

properties(Dependent, GetAccess=public, SetAccess=private)
TimeUnit
end

methods
function obj = TemporalType(proxy)
arguments
proxy(1, 1) libmexclass.proxy.Proxy
end
obj@arrow.type.FixedWidthType(proxy);
end

function timeUnit = get.TimeUnit(obj)
timeUnitValue = obj.Proxy.getTimeUnit();
timeUnit = arrow.type.TimeUnit(timeUnitValue);
end
end
end
9 changes: 9 additions & 0 deletions matlab/src/matlab/+arrow/+type/Time32Type.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

classdef Time32Type < arrow.type.TemporalType

properties(Dependent, GetAccess=public, SetAccess=private)
TimeUnit
end

methods
function obj = Time32Type(proxy)
arguments
Expand All @@ -26,6 +30,11 @@

obj@arrow.type.TemporalType(proxy);
end

function timeUnit = get.TimeUnit(obj)
timeUnitValue = obj.Proxy.getTimeUnit();
timeUnit = arrow.type.TimeUnit(timeUnitValue);
end
end

methods (Access=protected)
Expand Down
9 changes: 8 additions & 1 deletion matlab/src/matlab/+arrow/+type/TimestampType.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
%TIMESTAMPTYPE Type class for timestamp data.

% 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.
Expand All @@ -14,9 +16,9 @@
% permissions and limitations under the License.

classdef TimestampType < arrow.type.TemporalType
%TIMESTAMPTYPE Type class for timestamp data.

properties(Dependent, GetAccess=public, SetAccess=private)
TimeUnit
TimeZone
end

Expand All @@ -29,6 +31,11 @@
obj@arrow.type.TemporalType(proxy);
end

function timeUnit = get.TimeUnit(obj)
timeUnitValue = obj.Proxy.getTimeUnit();
timeUnit = arrow.type.TimeUnit(timeUnitValue);
end

function tz = get.TimeZone(obj)
tz = obj.Proxy.getTimeZone();
end
Expand Down

0 comments on commit bb9e097

Please sign in to comment.