forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-36853: [MATLAB] Add utility to create proxies from existing …
…`arrow::DataType` objects (apache#36873) ### Rationale for this change There will be many places in the MATLAB interface code base in which we will have to wrap an `arrow::DataType` object within a subclass of `arrow::matlab::type::proxy::Type`. To avoid code duplicaiton, we should add a utility function called `wrap` that accepts a pointer to an `arrow::DataType` object and returns a pointer to a `arrow::matlab::type::proxy::Type` object. ### What changes are included in this PR? 1. Added a new function with the following signature: ```cpp arrow::Result<std::shared_ptr<arrow::matlab::type::proxy::Type>> wrap(const std::shared_ptr<arrow::DataType>& datatype); ``` 2. Updated the `type` methods of `arrow::matlab::type::proxy::Field` and `arrow::matlab::array::proxy::Array` to use `wrap`. ### Are these changes tested? No new tests needed. ### Are there any user-facing changes? No * Closes: apache#36853 Lead-authored-by: Sarah Gilmore <[email protected]> Co-authored-by: sgilmore10 <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Kevin Gurney <[email protected]>
- Loading branch information
1 parent
8503c86
commit 9fe23da
Showing
12 changed files
with
101 additions
and
72 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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/wrap.h" | ||
|
||
#include "arrow/matlab/type/proxy/primitive_ctype.h" | ||
#include "arrow/matlab/type/proxy/timestamp_type.h" | ||
#include "arrow/matlab/type/proxy/string_type.h" | ||
|
||
namespace arrow::matlab::type::proxy { | ||
|
||
arrow::Result<std::shared_ptr<type::proxy::Type>> wrap(const std::shared_ptr<arrow::DataType>& type) { | ||
using ID = arrow::Type::type; | ||
switch (type->id()) { | ||
case ID::BOOL: | ||
return std::make_shared<PrimitiveCType<bool>>(std::static_pointer_cast<arrow::BooleanType>(type)); | ||
case ID::UINT8: | ||
return std::make_shared<PrimitiveCType<uint8_t>>(std::static_pointer_cast<arrow::UInt8Type>(type)); | ||
case ID::UINT16: | ||
return std::make_shared<PrimitiveCType<uint16_t>>(std::static_pointer_cast<arrow::UInt16Type>(type)); | ||
case ID::UINT32: | ||
return std::make_shared<PrimitiveCType<uint32_t>>(std::static_pointer_cast<arrow::UInt32Type>(type)); | ||
case ID::UINT64: | ||
return std::make_shared<PrimitiveCType<uint64_t>>(std::static_pointer_cast<arrow::UInt64Type>(type)); | ||
case ID::INT8: | ||
return std::make_shared<PrimitiveCType<int8_t>>(std::static_pointer_cast<arrow::Int8Type>(type)); | ||
case ID::INT16: | ||
return std::make_shared<PrimitiveCType<int16_t>>(std::static_pointer_cast<arrow::Int16Type>(type)); | ||
case ID::INT32: | ||
return std::make_shared<PrimitiveCType<int32_t>>(std::static_pointer_cast<arrow::Int32Type>(type)); | ||
case ID::INT64: | ||
return std::make_shared<PrimitiveCType<int64_t>>(std::static_pointer_cast<arrow::Int64Type>(type)); | ||
case ID::FLOAT: | ||
return std::make_shared<PrimitiveCType<float>>(std::static_pointer_cast<arrow::FloatType>(type)); | ||
case ID::DOUBLE: | ||
return std::make_shared<PrimitiveCType<double>>(std::static_pointer_cast<arrow::DoubleType>(type)); | ||
case ID::TIMESTAMP: | ||
return std::make_shared<TimestampType>(std::static_pointer_cast<arrow::TimestampType>(type)); | ||
case ID::STRING: | ||
return std::make_shared<StringType>(std::static_pointer_cast<arrow::StringType>(type)); | ||
default: | ||
return arrow::Status::NotImplemented("Unsupported DataType: " + type->ToString()); | ||
} | ||
} | ||
} |
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/type.h" | ||
#include "arrow/result.h" | ||
|
||
#include "arrow/matlab/type/proxy/type.h" | ||
|
||
namespace arrow::matlab::type::proxy { | ||
|
||
arrow::Result<std::shared_ptr<Type>> wrap(const std::shared_ptr<arrow::DataType>& 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