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 49599366f3 GH-37262: [MATLAB] Add an abstract class called 
`arrow.type.TimeType` (#37279)
49599366f3 is described below

commit 49599366f367561a06be66b768ecfa1965895313
Author: sgilmore10 <[email protected]>
AuthorDate: Mon Aug 21 12:08:25 2023 -0400

    GH-37262: [MATLAB] Add an abstract class called `arrow.type.TimeType` 
(#37279)
    
    
    
    ### Rationale for this change
    
    To reduce code duplication within `Time32Type` and `Time64Type`, we should 
add an abstract class called `arrow.type.TimeType` that implements  the getter 
method for the `TimeUnit` property. This class hierarchy will mirror the class 
hierarchy in the C++ arrow implementation.
    
    ### What changes are included in this PR?
    
    1. Defined a new C++ proxy class for called 
`arrow::matlab::type::proxy::TimeType`. This class defines a `getTimeUnit` 
method.
    2. Modified the C++ proxy class `Time32Type` to inherit from 
`arrow::matlab::type::proxy::TimeType`. Removed the `getTimeUnit` method from 
this class because it's now defined on `TimeType`.
    3. Added a new MATLAB class called `arrow.type.TimeType`. It has one 
method: `get.TimeUnit`.
    4. Modified `arrow.type.Time32Type` to inherit from `arrow.type.TimeType` 
and removed its `get.TimeUnit` method.
    
    ### 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: #37262
    
    Authored-by: Sarah Gilmore <[email protected]>
    Signed-off-by: Kevin Gurney <[email protected]>
---
 .../src/cpp/arrow/matlab/type/proxy/time32_type.cc | 16 +---------
 .../src/cpp/arrow/matlab/type/proxy/time32_type.h  |  7 ++---
 .../type/proxy/{time32_type.h => time_type.cc}     | 34 ++++++++++------------
 .../type/proxy/{time32_type.h => time_type.h}      | 10 ++-----
 matlab/src/matlab/+arrow/+type/Time32Type.m        | 20 ++-----------
 .../+arrow/+type/{Time32Type.m => TimeType.m}      | 18 +++++-------
 matlab/tools/cmake/BuildMatlabArrowInterface.cmake |  1 +
 7 files changed, 33 insertions(+), 73 deletions(-)

diff --git a/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.cc 
b/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.cc
index 30323f4400..7b2313d6c3 100644
--- a/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.cc
+++ b/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.cc
@@ -22,9 +22,7 @@
 
 namespace arrow::matlab::type::proxy {
 
-    Time32Type::Time32Type(std::shared_ptr<arrow::Time32Type> time32_type) : 
FixedWidthType(std::move(time32_type)) {
-        REGISTER_METHOD(Time32Type, getTimeUnit);
-    }
+    Time32Type::Time32Type(std::shared_ptr<arrow::Time32Type> time32_type) : 
TimeType(std::move(time32_type)) {}
 
     libmexclass::proxy::MakeResult Time32Type::make(const 
libmexclass::proxy::FunctionArguments& constructor_arguments) {
         namespace mda = ::matlab::data;
@@ -45,16 +43,4 @@ namespace arrow::matlab::type::proxy {
         auto time_type = std::static_pointer_cast<arrow::Time32Type>(type);
         return std::make_shared<Time32TypeProxy>(std::move(time_type));
     }
-
-    void Time32Type::getTimeUnit(libmexclass::proxy::method::Context& context) 
{
-        namespace mda = ::matlab::data;
-        mda::ArrayFactory factory;
-
-        auto time32_type = 
std::static_pointer_cast<arrow::Time32Type>(data_type);
-        const auto timeunit = time32_type->unit();
-        // Cast to uint8_t since there are only four supported TimeUnit 
enumeration values:
-        // Nanosecond, Microsecond, Millisecond, Second
-        auto timeunit_mda = 
factory.createScalar(static_cast<uint8_t>(timeunit));
-        context.outputs[0] = timeunit_mda;
-    }
 }
diff --git a/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.h 
b/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.h
index 3c9ba2bc8f..cf1a9c9fa4 100644
--- a/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.h
+++ b/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.h
@@ -17,12 +17,11 @@
 
 #pragma once
 
-#include "arrow/matlab/type/proxy/fixed_width_type.h"
-#include "arrow/type_traits.h"
+#include "arrow/matlab/type/proxy/time_type.h"
 
 namespace arrow::matlab::type::proxy {
 
-class Time32Type : public arrow::matlab::type::proxy::FixedWidthType {
+class Time32Type : public arrow::matlab::type::proxy::TimeType {
 
     public:
         Time32Type(std::shared_ptr<arrow::Time32Type> time32_type);
@@ -31,8 +30,6 @@ class Time32Type : public 
arrow::matlab::type::proxy::FixedWidthType {
 
         static libmexclass::proxy::MakeResult make(const 
libmexclass::proxy::FunctionArguments& constructor_arguments);
 
-    protected:
-        void getTimeUnit(libmexclass::proxy::method::Context& context);
 };
 
 }
diff --git a/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.h 
b/matlab/src/cpp/arrow/matlab/type/proxy/time_type.cc
similarity index 52%
copy from matlab/src/cpp/arrow/matlab/type/proxy/time32_type.h
copy to matlab/src/cpp/arrow/matlab/type/proxy/time_type.cc
index 3c9ba2bc8f..1cc92834b9 100644
--- a/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.h
+++ b/matlab/src/cpp/arrow/matlab/type/proxy/time_type.cc
@@ -15,25 +15,23 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#pragma once
-
-#include "arrow/matlab/type/proxy/fixed_width_type.h"
-#include "arrow/type_traits.h"
+#include "arrow/matlab/type/proxy/time_type.h"
 
 namespace arrow::matlab::type::proxy {
 
-class Time32Type : public arrow::matlab::type::proxy::FixedWidthType {
-
-    public:
-        Time32Type(std::shared_ptr<arrow::Time32Type> time32_type);
-
-        ~Time32Type() {}
-
-        static libmexclass::proxy::MakeResult make(const 
libmexclass::proxy::FunctionArguments& constructor_arguments);
-
-    protected:
-        void getTimeUnit(libmexclass::proxy::method::Context& context);
-};
-
+    TimeType::TimeType(std::shared_ptr<arrow::TimeType> time_type) : 
FixedWidthType(std::move(time_type)) {
+        REGISTER_METHOD(TimeType, getTimeUnit);
+    }
+
+    void TimeType::getTimeUnit(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+
+        auto time_type = std::static_pointer_cast<arrow::TimeType>(data_type);
+        const auto timeunit = time_type->unit();
+        // Cast to uint8_t since there are only four supported TimeUnit 
enumeration values:
+        // Nanosecond, Microsecond, Millisecond, Second
+        auto timeunit_mda = 
factory.createScalar(static_cast<uint8_t>(timeunit));
+        context.outputs[0] = timeunit_mda;
+    }
 }
-
diff --git a/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.h 
b/matlab/src/cpp/arrow/matlab/type/proxy/time_type.h
similarity index 76%
copy from matlab/src/cpp/arrow/matlab/type/proxy/time32_type.h
copy to matlab/src/cpp/arrow/matlab/type/proxy/time_type.h
index 3c9ba2bc8f..05521b9c36 100644
--- a/matlab/src/cpp/arrow/matlab/type/proxy/time32_type.h
+++ b/matlab/src/cpp/arrow/matlab/type/proxy/time_type.h
@@ -18,22 +18,18 @@
 #pragma once
 
 #include "arrow/matlab/type/proxy/fixed_width_type.h"
-#include "arrow/type_traits.h"
 
 namespace arrow::matlab::type::proxy {
 
-class Time32Type : public arrow::matlab::type::proxy::FixedWidthType {
+class TimeType : public arrow::matlab::type::proxy::FixedWidthType {
 
     public:
-        Time32Type(std::shared_ptr<arrow::Time32Type> time32_type);
+        TimeType(std::shared_ptr<arrow::TimeType> time_type);
 
-        ~Time32Type() {}
-
-        static libmexclass::proxy::MakeResult make(const 
libmexclass::proxy::FunctionArguments& constructor_arguments);
+        ~TimeType() {}
 
     protected:
         void getTimeUnit(libmexclass::proxy::method::Context& context);
 };
 
 }
-
diff --git a/matlab/src/matlab/+arrow/+type/Time32Type.m 
b/matlab/src/matlab/+arrow/+type/Time32Type.m
index b03f943b5b..50253ee6d1 100644
--- a/matlab/src/matlab/+arrow/+type/Time32Type.m
+++ b/matlab/src/matlab/+arrow/+type/Time32Type.m
@@ -15,11 +15,7 @@
 % implied.  See the License for the specific language governing
 % permissions and limitations under the License.
 
-classdef Time32Type < arrow.type.TemporalType
-
-    properties(Dependent, GetAccess=public, SetAccess=private)
-        TimeUnit
-    end
+classdef Time32Type < arrow.type.TimeType
 
     methods
         function obj = Time32Type(proxy)
@@ -28,19 +24,7 @@ classdef Time32Type < arrow.type.TemporalType
             end
             import arrow.internal.proxy.validate
 
-            [email protected](proxy);
-        end
-
-        function timeUnit = get.TimeUnit(obj)
-            timeUnitValue = obj.Proxy.getTimeUnit();
-            timeUnit = arrow.type.TimeUnit(timeUnitValue);
-        end
-    end
-
-    methods (Access=protected)
-        function group = getPropertyGroups(~)
-          targets = ["ID" "TimeUnit"];
-          group = matlab.mixin.util.PropertyGroup(targets);
+            [email protected](proxy);
         end
     end
 
diff --git a/matlab/src/matlab/+arrow/+type/Time32Type.m 
b/matlab/src/matlab/+arrow/+type/TimeType.m
similarity index 72%
copy from matlab/src/matlab/+arrow/+type/Time32Type.m
copy to matlab/src/matlab/+arrow/+type/TimeType.m
index b03f943b5b..59d9387889 100644
--- a/matlab/src/matlab/+arrow/+type/Time32Type.m
+++ b/matlab/src/matlab/+arrow/+type/TimeType.m
@@ -1,4 +1,4 @@
-%TIME32TYPE Type class for time32 data.
+%TIMETYPE Type class for time data.
 
 % Licensed to the Apache Software Foundation (ASF) under one or more
 % contributor license agreements.  See the NOTICE file distributed with
@@ -15,19 +15,17 @@
 % implied.  See the License for the specific language governing
 % permissions and limitations under the License.
 
-classdef Time32Type < arrow.type.TemporalType
+classdef TimeType < arrow.type.TemporalType
 
-    properties(Dependent, GetAccess=public, SetAccess=private)
+    properties(Dependent, SetAccess=private, GetAccess=public)
         TimeUnit
     end
 
     methods
-        function obj = Time32Type(proxy)
+        function obj = TimeType(proxy)
             arguments
-                proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, 
"arrow.type.proxy.Time32Type")}
+                proxy(1, 1) libmexclass.proxy.Proxy
             end
-            import arrow.internal.proxy.validate
-
             [email protected](proxy);
         end
 
@@ -39,9 +37,9 @@ classdef Time32Type < arrow.type.TemporalType
 
     methods (Access=protected)
         function group = getPropertyGroups(~)
-          targets = ["ID" "TimeUnit"];
-          group = matlab.mixin.util.PropertyGroup(targets);
+            targets = ["ID" "TimeUnit"];
+            group = matlab.mixin.util.PropertyGroup(targets);
         end
     end
 
-end
+end
\ No newline at end of file
diff --git a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake 
b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake
index 44fe9e562d..30d942b86b 100644
--- a/matlab/tools/cmake/BuildMatlabArrowInterface.cmake
+++ b/matlab/tools/cmake/BuildMatlabArrowInterface.cmake
@@ -55,6 +55,7 @@ set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_SOURCES 
"${CMAKE_SOURCE_DIR}/src/cpp/a
                                                   
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/proxy/fixed_width_type.cc"
                                                   
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/proxy/string_type.cc"
                                                   
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/proxy/timestamp_type.cc"
+                                                  
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/proxy/time_type.cc"
                                                   
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/proxy/time32_type.cc"
                                                   
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/proxy/field.cc"
                                                   
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/proxy/wrap.cc"

Reply via email to