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-37229: [MATLAB] Add
arrow.type.Date32Type
class and `arrow…
….date32` construction function (apache#37348) ### Rationale for this change In support of adding `arrow.array.Date32Array`, this pull request adds a new `arrow.type.Date32Type` class and associated `arrow.date32` construction function to the MATLAB interface. ### What changes are included in this PR? 1. New `arrow.type.Date32Type` class. 2. New `arrow.date32` construction function that returns an `arrow.type.Date32Type` instance. 3. New `arrow.type.ID.Date32` type enumeration value. 4. Added an abstract `arrow.type.DateType` class which `arrow.type.Date32Type` inherits from. `arrow.type.Date64Type` will also inherit from this class to share the `DateUnit` property. This mirrors the implementation of the `Time32Type` and `Time64Type` classes inheriting from an abstract `arrow.type.TimeType` class to share the `TimeUnit` property. **Example** ```matlab >> type = arrow.date32() type = Date32Type with properties: ID: Date32 DateUnit: Day ``` ### Are these changes tested? Yes. 1. Added a new `tDate32Type` test class. 2. Updated the `tID` test class to include `arrow.type.ID.Date32`. ### Are there any user-facing changes? Yes. 1. There is a new public `arrow.type.Date32Type` class. 2. There is a new public `arrow.date32` construction function. 3. There is a new `arrow.type.ID.Date32` type enumeration value. ### Future Directions 1. apache#37230 2. Add `arrow.array.Date32Array` class. 3. Add `arrow.array.Date64Array` class. * Closes: apache#37229 Lead-authored-by: Kevin Gurney <[email protected]> Co-authored-by: Sarah Gilmore <[email protected]> Signed-off-by: Kevin Gurney <[email protected]>
- Loading branch information
1 parent
effe2ed
commit 43437a5
Showing
12 changed files
with
325 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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/date32_type.h" | ||
|
||
namespace arrow::matlab::type::proxy { | ||
|
||
Date32Type::Date32Type(std::shared_ptr<arrow::Date32Type> date32_type) : DateType(std::move(date32_type)) {} | ||
|
||
libmexclass::proxy::MakeResult Date32Type::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) { | ||
using Date32TypeProxy = arrow::matlab::type::proxy::Date32Type; | ||
|
||
const auto type = arrow::date32(); | ||
const auto date32_type = std::static_pointer_cast<arrow::Date32Type>(type); | ||
return std::make_shared<Date32TypeProxy>(std::move(date32_type)); | ||
} | ||
} |
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,36 @@ | ||
// 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/date_type.h" | ||
|
||
namespace arrow::matlab::type::proxy { | ||
|
||
class Date32Type : public arrow::matlab::type::proxy::DateType { | ||
|
||
public: | ||
Date32Type(std::shared_ptr<arrow::Date32Type> date32_type); | ||
|
||
~Date32Type() {} | ||
|
||
static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments); | ||
|
||
}; | ||
|
||
} | ||
|
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/date_type.h" | ||
|
||
namespace arrow::matlab::type::proxy { | ||
|
||
DateType::DateType(std::shared_ptr<arrow::DateType> date_type) : FixedWidthType(std::move(date_type)) { | ||
REGISTER_METHOD(DateType, getDateUnit); | ||
} | ||
|
||
void DateType::getDateUnit(libmexclass::proxy::method::Context& context) { | ||
namespace mda = ::matlab::data; | ||
mda::ArrayFactory factory; | ||
|
||
auto date_type = std::static_pointer_cast<arrow::DateType>(data_type); | ||
const auto date_unit = date_type->unit(); | ||
// Cast to uint8_t since there are only two supported DateUnit enumeration values: | ||
// Day and Millisecond | ||
auto date_unit_mda = factory.createScalar(static_cast<uint8_t>(date_unit)); | ||
context.outputs[0] = date_unit_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 DateType : public arrow::matlab::type::proxy::FixedWidthType { | ||
|
||
public: | ||
DateType(std::shared_ptr<arrow::DateType> date_type); | ||
|
||
~DateType() {} | ||
|
||
protected: | ||
void getDateUnit(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
%DATE32TYPE Type class for date32 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 Date32Type < arrow.type.DateType | ||
|
||
methods | ||
|
||
function obj = Date32Type(proxy) | ||
arguments | ||
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.Date32Type")} | ||
end | ||
import arrow.internal.proxy.validate | ||
|
||
[email protected](proxy); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
%DATETYPE Type class for date 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 DateType < arrow.type.TemporalType | ||
|
||
properties(Dependent, SetAccess=private, GetAccess=public) | ||
DateUnit | ||
end | ||
|
||
methods | ||
function obj = DateType(proxy) | ||
arguments | ||
proxy(1, 1) libmexclass.proxy.Proxy | ||
end | ||
[email protected](proxy); | ||
end | ||
|
||
function dateUnit = get.DateUnit(obj) | ||
dateUnitvalue = obj.Proxy.getDateUnit(); | ||
dateUnit = arrow.type.DateUnit(dateUnitvalue); | ||
end | ||
end | ||
|
||
methods (Access=protected) | ||
function group = getPropertyGroups(~) | ||
targets = ["ID" "DateUnit"]; | ||
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
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,20 @@ | ||
% 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. | ||
|
||
function type = date32() | ||
%DATE32 Creates an arrow.type.Date32Type object | ||
proxy = arrow.internal.proxy.create("arrow.type.proxy.Date32Type"); | ||
type = arrow.type.Date32Type(proxy); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
% 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 tDate32Type < hFixedWidthType | ||
% Test class for arrow.type.Date32Type and arrow.date32 | ||
|
||
properties | ||
ConstructionFcn = @arrow.date32 | ||
ArrowType = arrow.date32 | ||
TypeID = arrow.type.ID.Date32 | ||
BitWidth = int32(32) | ||
ClassName = "arrow.type.Date32Type" | ||
end | ||
|
||
methods(Test) | ||
function TestClass(testCase) | ||
% Verify ArrowType is an object of the expected class type. | ||
name = string(class(testCase.ArrowType)); | ||
testCase.verifyEqual(name, testCase.ClassName); | ||
end | ||
|
||
function DefaultDateUnit(testCase) | ||
% Verify the default DateUnit is Day. | ||
type = testCase.ArrowType; | ||
actualUnit = type.DateUnit; | ||
expectedUnit = arrow.type.DateUnit.Day; | ||
testCase.verifyEqual(actualUnit, expectedUnit); | ||
end | ||
|
||
function Display(testCase) | ||
% Verify the display of Date32Type objects. | ||
% | ||
% Example: | ||
% | ||
% Date32Type with properties: | ||
% | ||
% ID: Date32 | ||
% DateUnit: Day | ||
% | ||
type = testCase.ConstructionFcn(); %#ok<NASGU> | ||
classnameLink = "<a href=""matlab:helpPopup arrow.type.Date32Type"" style=""font-weight:bold"">Date32Type</a>"; | ||
header = " " + classnameLink + " with properties:" + newline; | ||
body = strjust(pad(["ID:"; "DateUnit:"])); | ||
body = body + " " + ["Date32"; "Day"]; | ||
body = " " + body; | ||
footer = string(newline); | ||
expectedDisplay = char(strjoin([header body' footer], newline)); | ||
actualDisplay = evalc('disp(type)'); | ||
testCase.verifyEqual(actualDisplay, expectedDisplay); | ||
end | ||
|
||
function DateUnitNoSetter(testCase) | ||
% Verify that an error is thrown when trying to set the value | ||
% of the DateUnit property. | ||
type = arrow.date32(); | ||
testCase.verifyError(@() setfield(type, "DateUnit", "Millisecond"), "MATLAB:class:SetProhibited"); | ||
end | ||
|
||
function InvalidProxy(testCase) | ||
% Verify that an error is thrown when a Proxy of an unexpected | ||
% type is passed to the arrow.type.Date32Type constructor. | ||
array = arrow.array([1, 2, 3]); | ||
proxy = array.Proxy; | ||
testCase.verifyError(@() arrow.type.Date32Type(proxy), "arrow:proxy:ProxyNameMismatch"); | ||
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
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