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 06b0e4f7db GH-37251: [MATLAB] Make `arrow.type.TemporalType` a "tag" 
class  (#37256)
06b0e4f7db is described below

commit 06b0e4f7db15c4ee88bf31a9238aa28bbf858081
Author: sgilmore10 <[email protected]>
AuthorDate: Mon Aug 21 11:17:44 2023 -0400

    GH-37251: [MATLAB] Make `arrow.type.TemporalType` a "tag" class  (#37256)
    
    
    
    ### Rationale for this change
    
    The original motivation for adding the super-class 
`arrow.type.TemporalType` in #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 ` [...]
    
    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. #37232
    2. #37229
    3. #37230
    
    * Closes: #37251
    
    Authored-by: Sarah Gilmore <[email protected]>
    Signed-off-by: Kevin Gurney <[email protected]>
---
 matlab/src/matlab/+arrow/+type/TemporalType.m  | 9 ---------
 matlab/src/matlab/+arrow/+type/Time32Type.m    | 9 +++++++++
 matlab/src/matlab/+arrow/+type/TimestampType.m | 9 ++++++++-
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/matlab/src/matlab/+arrow/+type/TemporalType.m 
b/matlab/src/matlab/+arrow/+type/TemporalType.m
index a3d093fb6d..9c0769c38e 100644
--- a/matlab/src/matlab/+arrow/+type/TemporalType.m
+++ b/matlab/src/matlab/+arrow/+type/TemporalType.m
@@ -17,10 +17,6 @@
 
 classdef TemporalType < arrow.type.FixedWidthType
 
-    properties(Dependent, GetAccess=public, SetAccess=private)
-        TimeUnit
-    end
-
     methods
         function obj = TemporalType(proxy)
             arguments
@@ -28,10 +24,5 @@ classdef TemporalType < arrow.type.FixedWidthType
             end
             [email protected](proxy);
         end
-
-        function timeUnit = get.TimeUnit(obj)
-            timeUnitValue = obj.Proxy.getTimeUnit();
-            timeUnit = arrow.type.TimeUnit(timeUnitValue);
-        end
     end
 end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/Time32Type.m 
b/matlab/src/matlab/+arrow/+type/Time32Type.m
index 9d2c709ad3..b03f943b5b 100644
--- a/matlab/src/matlab/+arrow/+type/Time32Type.m
+++ b/matlab/src/matlab/+arrow/+type/Time32Type.m
@@ -17,6 +17,10 @@
 
 classdef Time32Type < arrow.type.TemporalType
 
+    properties(Dependent, GetAccess=public, SetAccess=private)
+        TimeUnit
+    end
+
     methods
         function obj = Time32Type(proxy)
             arguments
@@ -26,6 +30,11 @@ classdef Time32Type < arrow.type.TemporalType
 
             [email protected](proxy);
         end
+
+        function timeUnit = get.TimeUnit(obj)
+            timeUnitValue = obj.Proxy.getTimeUnit();
+            timeUnit = arrow.type.TimeUnit(timeUnitValue);
+        end
     end
 
     methods (Access=protected)
diff --git a/matlab/src/matlab/+arrow/+type/TimestampType.m 
b/matlab/src/matlab/+arrow/+type/TimestampType.m
index 2333818208..cb47743148 100644
--- a/matlab/src/matlab/+arrow/+type/TimestampType.m
+++ b/matlab/src/matlab/+arrow/+type/TimestampType.m
@@ -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.
@@ -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
 
@@ -29,6 +31,11 @@ classdef TimestampType < arrow.type.TemporalType
             [email protected](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

Reply via email to