-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### Rationale for this change Now that `arrow.type.Time64Type` class has been added to the MATLAB Interface (#37287), we can add the `arrow.array.Time64Array` class. ### What changes are included in this PR? 1. New `arrow.array.Time64Array` class. 2. New `arrow.type.traits.Time64Traits` class. 3. Enhanced `arrow.array(data)` to return a `arrow.array.Time64Array` instance if the input `data` is a MATLAB `duration` array. The MATLAB `duration` type represents length of time in fixed-length units. 4. Enhanced `arrow.type.traits.traits(id)` to return an `arrow.type.traits.Time64Traits` instance if `id` is an `arrow.type.ID.Time64` value or equal to the string `"duration".` 5. Updated the test utility `arrow.internal.test.tabular.createAllSupportedArrayTypes()` to include an `arrow.array.Time64Array` instance in its output. 6. Updated the test utility `arrow.internal.test.tabular.createTableWithSupportedTypes()` to include a `duration` variable on the returned `table`. 7. Updated the README.md to include `Time32Array` and `Time64Array`. **Example Usage** ```matlab % Create a duration array >> ms = milliseconds([100 150 1001]) ms = 1×3 duration array 0.1 sec 0.15 sec 1.001 sec % Create an arrow.type.Time64Array >> time = arrow.array(ms) time = [ 00:00:00.100000, 00:00:00.150000, 00:00:01.001000 ] % Create a duration array from an arrow.array.Time64Array >> data = duration(time) data = 3×1 duration array 0.1 sec 0.15 sec 1.001 sec ``` ### Are these changes tested? Yes. 1. Added a new test class `tTime64Array.m`. 2. Added a new test class `tTime64Traits.m` 3. Added new test cases to `tArray.m` and `ttraits.m` ### Are there any user-facing changes? Yes. Users can now create `arrow.array.Time64Array`s from MATLAB `duration`s * Closes: #37337 Authored-by: Sarah Gilmore <[email protected]> Signed-off-by: Kevin Gurney <[email protected]>
- Loading branch information
1 parent
fa0af70
commit faccbef
Showing
28 changed files
with
667 additions
and
111 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,28 @@ | ||
// 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/array/proxy/time64_array.h" | ||
#include "arrow/matlab/array/proxy/time_array.h" | ||
|
||
namespace arrow::matlab::array::proxy { | ||
|
||
// Specialization of NumericArray::Make for arrow::Time64Type | ||
template <> | ||
libmexclass::proxy::MakeResult Time64Array::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) { | ||
return make_time_array<arrow::Time64Type>(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,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. | ||
|
||
#pragma once | ||
|
||
#include "arrow/matlab/array/proxy/numeric_array.h" | ||
|
||
#include "arrow/matlab/api/visibility.h" | ||
|
||
namespace arrow::matlab::array::proxy { | ||
|
||
using Time64Array = NumericArray<arrow::Time64Type>; | ||
|
||
// Specialization of NumericArray::Make for arrow::Time64Type | ||
template<> | ||
ARROW_MATLAB_EXPORT libmexclass::proxy::MakeResult Time64Array::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,72 @@ | ||
// 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/array/proxy/numeric_array.h" | ||
|
||
#include "arrow/matlab/type/time_unit.h" | ||
#include "arrow/util/utf8.h" | ||
#include "arrow/type_traits.h" | ||
|
||
namespace arrow::matlab::array::proxy { | ||
|
||
template <typename ArrowType> | ||
using is_time = arrow::is_time_type<ArrowType>; | ||
|
||
template <typename ArrowType> | ||
using enable_if_time = std::enable_if_t<is_time<ArrowType>::value, bool>; | ||
|
||
template <typename ArrowType, enable_if_time<ArrowType> = true> | ||
libmexclass::proxy::MakeResult make_time_array(const libmexclass::proxy::FunctionArguments& constructor_arguments) { | ||
namespace mda = ::matlab::data; | ||
using namespace arrow::matlab::type; | ||
using MatlabBuffer = arrow::matlab::buffer::MatlabBuffer; | ||
using TimeArray = arrow::NumericArray<ArrowType>; | ||
using TimeArrayProxy = proxy::NumericArray<ArrowType>; | ||
using CType = typename arrow::TypeTraits<ArrowType>::CType; | ||
|
||
mda::StructArray opts = constructor_arguments[0]; | ||
|
||
const mda::TypedArray<CType> time_mda = opts[0]["MatlabArray"]; | ||
const mda::TypedArray<bool> validity_bitmap_mda = opts[0]["Valid"]; | ||
const mda::TypedArray<mda::MATLABString> time_unit_mda = opts[0]["TimeUnit"]; | ||
|
||
// extract the time unit | ||
const std::u16string& time_unit_utf16 = time_unit_mda[0]; | ||
MATLAB_ASSIGN_OR_ERROR(const auto time_unit, | ||
timeUnitFromString(time_unit_utf16), | ||
error::UKNOWN_TIME_UNIT_ERROR_ID); | ||
|
||
MATLAB_ERROR_IF_NOT_OK(validateTimeUnit<ArrowType>(time_unit), | ||
error::INVALID_TIME_UNIT); | ||
|
||
// create the ArrowType | ||
const auto data_type = std::make_shared<ArrowType>(time_unit); | ||
|
||
auto array_length = static_cast<size_t>(time_mda.getNumberOfElements()); | ||
auto data_buffer = std::make_shared<MatlabBuffer>(time_mda); | ||
|
||
// Pack the validity bitmap values. | ||
MATLAB_ASSIGN_OR_ERROR(auto packed_validity_bitmap, | ||
bit::packValid(validity_bitmap_mda), | ||
error::BITPACK_VALIDITY_BITMAP_ERROR_ID); | ||
|
||
auto array_data = arrow::ArrayData::Make(data_type, array_length, {packed_validity_bitmap, data_buffer}); | ||
auto time_array = std::static_pointer_cast<TimeArray>(arrow::MakeArray(array_data)); | ||
return std::make_shared<TimeArrayProxy>(std::move(time_array)); | ||
|
||
} | ||
} |
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
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
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
Oops, something went wrong.