forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-37262: [MATLAB] Add an abstract class called `arrow.type.Tim…
…eType` (apache#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. apache#37232 2. apache#37229 3. apache#37230 * Closes: apache#37262 Authored-by: Sarah Gilmore <sgilmore@mathworks.com> Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
- Loading branch information
1 parent
bb9e097
commit 45e8448
Showing
7 changed files
with
123 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#include "arrow/matlab/type/proxy/time_type.h" | ||
|
||
namespace arrow::matlab::type::proxy { | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#pragma once | ||
|
||
#include "arrow/matlab/type/proxy/fixed_width_type.h" | ||
|
||
namespace arrow::matlab::type::proxy { | ||
|
||
class TimeType : public arrow::matlab::type::proxy::FixedWidthType { | ||
|
||
public: | ||
TimeType(std::shared_ptr<arrow::TimeType> time_type); | ||
|
||
~TimeType() {} | ||
|
||
protected: | ||
void getTimeUnit(libmexclass::proxy::method::Context& context); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
%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 | ||
% this work for additional information regarding copyright ownership. | ||
% The ASF licenses this file to you under the Apache License, Version | ||
% 2.0 (the "License"); you may not use this file except in compliance | ||
% with the License. You may obtain a copy of the License at | ||
% | ||
% http://www.apache.org/licenses/LICENSE-2.0 | ||
% | ||
% Unless required by applicable law or agreed to in writing, software | ||
% distributed under the License is distributed on an "AS IS" BASIS, | ||
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
% implied. See the License for the specific language governing | ||
% permissions and limitations under the License. | ||
|
||
classdef TimeType < arrow.type.TemporalType | ||
|
||
properties(Dependent, SetAccess=private, GetAccess=public) | ||
TimeUnit | ||
end | ||
|
||
methods | ||
function obj = TimeType(proxy) | ||
arguments | ||
proxy(1, 1) libmexclass.proxy.Proxy | ||
end | ||
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) | ||
function group = getPropertyGroups(~) | ||
targets = ["ID" "TimeUnit"]; | ||
group = matlab.mixin.util.PropertyGroup(targets); | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters