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.
…he#38189) ### Rationale for this change In support of adding an [`arrow.array.ListArray`](apache#37815) MATLAB class, this pull request adds a new `arrow.type.ListType` MATLAB class. ### What changes are included in this PR? 1. New `arrow.list(<type>)` MATLAB construction function. 2. New `arrow.list.ListType` MATLAB class. `ListType` has a property named `Type` which indicates the inner type of the `List`. `Type` can be set to any subclass `arrow.type.Type` (including `arrow.type.ListType`, to support nested lists). 3. New `arrow.type.ID.List` type ID enumeration value. 4. New `arrow.type.traits.ListTraits` type traits class. Some of the properties, such as `ArrayConstructor` and `ArrayProxyClassName`, are set to `missing` because they are dependent on adding [`arrow.array.ListArray`](apache#37815) first. **Example** ```matlab % Create a simple List<String> type. >> stringListType = arrow.list(arrow.string()) stringListType = ListType with properties: ID: List Type: [1x1 arrow.type.StringType] % Create a nested List<List<Boolean>> type. >> nestedListType = arrow.list(arrow.list(arrow.boolean())) nestedListType = ListType with properties: ID: List Type: [1x1 arrow.type.ListType] % Extract the first-level, inner type, which is List<Boolean>. >> innerType = nestedListType.Type innerType = ListType with properties: ID: List Type: [1x1 arrow.type.BooleanType] % Extract the second-level, nested inner type, which is Boolean. >> innerType.Type ans = BooleanType with properties: ID: Boolean ``` ### Are these changes tested? Yes. 1. Added `tListType.m`. 2. Added `tListTraits.m`. 3. Updated `tField.m` to include `arrow.list`. 4. Updated `tID.m` to include `arrow.type.ID.List`. 6. Updated `tTypeDisplay.m` to include `arrow.type.ListType`. 7. Updated `ttraits.m` to include `arrow.type.traits.ListTraits`. ### Are there any user-facing changes? Yes. Client MATLAB code can now creates instances of `arrow.type.ListType` by using the `arrow.list(<type>)` construction function. ### Future Directions 1. apache#37815 * Closes: apache#37812 Authored-by: Kevin Gurney <[email protected]> Signed-off-by: Kevin Gurney <[email protected]>
- Loading branch information
1 parent
7606103
commit 9c1c58b
Showing
18 changed files
with
463 additions
and
24 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,64 @@ | ||
// 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/list_type.h" | ||
#include "arrow/matlab/type/proxy/wrap.h" | ||
#include "libmexclass/proxy/ProxyManager.h" | ||
#include "arrow/matlab/error/error.h" | ||
|
||
namespace arrow::matlab::type::proxy { | ||
|
||
ListType::ListType(std::shared_ptr<arrow::ListType> list_type) : Type(std::move(list_type)) { | ||
REGISTER_METHOD(ListType, getValueType); | ||
} | ||
|
||
void ListType::getValueType(libmexclass::proxy::method::Context& context) { | ||
namespace mda = ::matlab::data; | ||
mda::ArrayFactory factory; | ||
|
||
const auto list_type = std::static_pointer_cast<arrow::ListType>(data_type); | ||
const auto value_type = list_type->value_type(); | ||
const auto value_type_id = static_cast<int32_t>(value_type->id()); | ||
|
||
MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto value_type_proxy, | ||
type::proxy::wrap(value_type), | ||
context, | ||
error::LIST_TYPE_FAILED_TO_CREATE_VALUE_TYPE_PROXY); | ||
const auto value_type_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(value_type_proxy); | ||
|
||
mda::StructArray output = factory.createStructArray({1, 1}, {"ValueTypeProxyID", "ValueTypeID"}); | ||
output[0]["ValueTypeProxyID"] = factory.createScalar(value_type_proxy_id); | ||
output[0]["ValueTypeID"] = factory.createScalar(value_type_id); | ||
|
||
context.outputs[0] = output; | ||
} | ||
|
||
libmexclass::proxy::MakeResult ListType::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) { | ||
namespace mda = ::matlab::data; | ||
using namespace libmexclass::proxy; | ||
using ListTypeProxy = arrow::matlab::type::proxy::ListType; | ||
|
||
mda::StructArray args = constructor_arguments[0]; | ||
const mda::TypedArray<uint64_t> value_type_proxy_id_mda = args[0]["ValueTypeProxyID"]; | ||
const auto value_type_proxy_id = value_type_proxy_id_mda[0]; | ||
const auto proxy = ProxyManager::getProxy(value_type_proxy_id); | ||
const auto value_type_proxy = std::static_pointer_cast<type::proxy::Type>(proxy); | ||
const auto value_type = value_type_proxy->unwrap(); | ||
const auto list_type = std::static_pointer_cast<arrow::ListType>(arrow::list(value_type)); | ||
return std::make_shared<ListTypeProxy>(std::move(list_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/type.h" | ||
|
||
namespace arrow::matlab::type::proxy { | ||
|
||
class ListType : public arrow::matlab::type::proxy::Type { | ||
|
||
public: | ||
ListType(std::shared_ptr<arrow::ListType> list_type); | ||
|
||
~ListType() {} | ||
|
||
void getValueType(libmexclass::proxy::method::Context& context); | ||
|
||
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
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,30 @@ | ||
% 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 ListTraits < arrow.type.traits.TypeTraits | ||
|
||
properties (Constant) | ||
ArrayConstructor = missing | ||
ArrayClassName = missing | ||
ArrayProxyClassName = missing | ||
ArrayStaticConstructor = missing | ||
TypeConstructor = @arrow.type.ListType | ||
TypeClassName = "arrow.type.ListType" | ||
TypeProxyClassName = "arrow.type.proxy.ListType" | ||
MatlabConstructor = missing | ||
MatlabClassName = missing | ||
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
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,57 @@ | ||
% 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 ListType < arrow.type.Type | ||
|
||
properties (Dependent, GetAccess=public, SetAccess=private) | ||
% The inner element type T of the List<T>. | ||
% For example: for List<UInt64>, ValueType = UInt64. | ||
ValueType | ||
end | ||
|
||
methods | ||
function obj = ListType(proxy) | ||
arguments | ||
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.ListType")} | ||
end | ||
import arrow.internal.proxy.validate | ||
[email protected](proxy); | ||
end | ||
end | ||
|
||
methods(Access = protected) | ||
function groups = getDisplayPropertyGroups(~) | ||
targets = ["ID", "ValueType"]; | ||
groups = matlab.mixin.util.PropertyGroup(targets); | ||
end | ||
end | ||
|
||
|
||
methods | ||
function valueType = get.ValueType(obj) | ||
valueTypeStruct = obj.Proxy.getValueType(); | ||
traits = arrow.type.traits.traits(arrow.type.ID(valueTypeStruct.ValueTypeID)); | ||
proxy = libmexclass.proxy.Proxy(Name=traits.TypeProxyClassName, ID=valueTypeStruct.ValueTypeProxyID); | ||
valueType = traits.TypeConstructor(proxy); | ||
end | ||
end | ||
|
||
methods (Hidden) | ||
function data = preallocateMATLABArray(~, numElements) | ||
% Preallocate an empty cell array. | ||
data = cell(numElements, 1); | ||
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,26 @@ | ||
%LIST Creates an arrow.type.ListType object | ||
|
||
% 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 listType = list(valueType) | ||
arguments | ||
valueType(1, 1) arrow.type.Type | ||
end | ||
|
||
valueTypeProxyID = valueType.Proxy.ID; | ||
args = struct(ValueTypeProxyID=valueTypeProxyID); | ||
proxy = arrow.internal.proxy.create("arrow.type.proxy.ListType", args); | ||
listType = arrow.type.ListType(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
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.