You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "sgilmore10 (via GitHub)" <gi...@apache.org> on 2023/09/01 18:22:39 UTC

[GitHub] [arrow] sgilmore10 opened a new pull request, #37525: GH-37448: [MATLAB] Add `arrow.array.ChunkedArray` class

sgilmore10 opened a new pull request, #37525:
URL: https://github.com/apache/arrow/pull/37525

   <!--
   Thanks for opening a pull request!
   If this is your first pull request you can find detailed information on how 
   to contribute here:
     * [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
     * [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
   
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
   
   Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename the pull request title in the following format?
   
       GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   In the case of PARQUET issues on JIRA the title also supports:
   
       PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   -->
   
   ### Rationale for this change
   
   In order to add an `arrow.tabular.Table` class to the MATLAB Interface, we first need to add a MATLAB class representing `arrow::ChunkedArray`s. This is required because an `arrow::Table` is backed by a vector of `arrow::ChunkedArray`s, and the output of its `column(int index)` method is an `arrow::ChunkedArray`.
   
   ### What changes are included in this PR?
   
   1. Introduced a new class called `arrow.array.ChunkedArray`. 
   2. `arrow.array.ChunkedArray` has the following properties:
       1.  `Type` - datatype of the `arrow.array.Array`s
       2. `Length` - Sum of the `arrow.array.Array` lengths 
       3. `NumChunks` - Number of `arrow.array.Array`s
   3. `arrow.array.ChunkedArray` has the following methods:
      1. `chunk(index)` - Returns the `arrow.array.Array` stored at the specified index
      2. `fromArrays(array1, array1, ..., arrayN, Type=type)` - Creates a `ChunkedArray` from the arrays provided. If `Type` is provided, all arrays are expected to have the specified `Type`.
   
   **Example Usage**
   
   ```matlab
   >> a1 = arrow.array(1:100);
   >> a2 = arrow.array(101:250);
   >> a3 = arrow.array(251:300);
   
   % Create a ChunkedArray from 3 Float64Arrays
   >> c = arrow.array.ChunkedArray.fromArrays(a1, a2, a3)
   
   c = 
   
     ChunkedArray with properties:
   
            Type: [1×1 arrow.type.Float64Type]
       NumChunks: 3
          Length: 300
   
   % Extract the first chunk and compare it to a1
   >> c1 = c.chunk(1);
   >> tf = isequal(c1, a1)
   
   tf =
   
     logical
   
      1
   
   % Create an empty ChunkedArray by providing the Type nv-pair
   >> c = arrow.array.ChunkedArray.fromArrays(Type=arrow.timestamp())
   
   c = 
   
     ChunkedArray with properties:
   
            Type: [1×1 arrow.type.TimestampType]
       NumChunks: 0
          Length: 0
   
   ```
   
   
   ### Are these changes tested?
   
   Yes. I added a new test class called `tChunkedArray.m` that contains unit tests for the new class.
   
   ### Are there any user-facing changes?
   
   Yes. Users can now create a `ChunkedArray` in the MATLAB Interface. 
   
   ### Future Directions
   
   1. In this PR, we deliberately didn't include a convenience constructor function because we're not sure if we want users to create `ChunkedArray`s themselves. We think users will mostly use `ChunkedArray` when extracting columns from `Table`s. 
   2. We will implement more methods on `ChunkedArray`, such as `flatten()` and `combineChunks()`, etc.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] kou commented on a diff in pull request #37525: GH-37448: [MATLAB] Add `arrow.array.ChunkedArray` class

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #37525:
URL: https://github.com/apache/arrow/pull/37525#discussion_r1313544092


##########
matlab/src/cpp/arrow/matlab/array/proxy/chunked_array.cc:
##########
@@ -0,0 +1,187 @@
+// 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/util/utf8.h"
+
+#include "arrow/matlab/array/proxy/chunked_array.h"
+#include "arrow/matlab/array/proxy/array.h"
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/type/proxy/wrap.h"
+#include "arrow/matlab/array/proxy/wrap.h"
+
+#include "libmexclass/proxy/ProxyManager.h"
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        libmexclass::error::Error makeEmptyChunkedArrayError() {
+            const std::string error_msg =  "Numeric indexing using the chunk method is not supported for chunked arrays with zero chunks.";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_NUMERIC_INDEX_WITH_EMPTY_CHUNKED_ARRAY, error_msg};
+        }
+
+        libmexclass::error::Error makeInvalidNumericIndexError(const int32_t matlab_index, const int32_t num_chunks) {
+            std::stringstream error_message_stream;
+            error_message_stream << "Invalid chunk index: ";
+            error_message_stream << matlab_index;
+            error_message_stream << ". Chunk index must be between 1 and the number of chunks (";
+            error_message_stream << num_chunks;
+            error_message_stream << ").";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_INVALID_NUMERIC_CHUNK_INDEX, error_message_stream.str()};
+        }
+    }
+
+    ChunkedArray::ChunkedArray(std::shared_ptr<arrow::ChunkedArray> chunked_array) : chunked_array{std::move(chunked_array)} {
+
+        // Register Proxy methods.
+        REGISTER_METHOD(ChunkedArray, getLength);
+        REGISTER_METHOD(ChunkedArray, getNumChunks);
+        REGISTER_METHOD(ChunkedArray, getChunk);
+        REGISTER_METHOD(ChunkedArray, getType);
+        REGISTER_METHOD(ChunkedArray, isEqual);
+    }
+
+
+    libmexclass::proxy::MakeResult ChunkedArray::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
+        namespace mda = ::matlab::data;
+
+        mda::StructArray opts = constructor_arguments[0];
+        const mda::TypedArray<uint64_t> array_proxy_ids = opts[0]["ArrayProxyIDs"];
+        const mda::TypedArray<uint64_t> type_proxy_id = opts[0]["TypeProxyID"];
+
+        std::vector<std::shared_ptr<arrow::Array>> arrays;
+        // Retrieve all of the Array Proxy instances from the libmexclass ProxyManager.
+        for (const auto& array_proxy_id : array_proxy_ids) {
+            auto proxy = libmexclass::proxy::ProxyManager::getProxy(array_proxy_id);
+            auto array_proxy = std::static_pointer_cast<proxy::Array>(proxy);
+            auto array = array_proxy->unwrap();
+            arrays.push_back(array);
+        }
+
+        auto proxy = libmexclass::proxy::ProxyManager::getProxy(type_proxy_id[0]);
+        auto type_proxy = std::static_pointer_cast<type::proxy::Type>(proxy);
+        auto type = type_proxy->unwrap();
+
+        MATLAB_ASSIGN_OR_ERROR(auto chunked_array, 
+                               arrow::ChunkedArray::Make(arrays, type),
+                               error::CHUNKED_ARRAY_MAKE_FAILED);
+
+        return std::make_unique<proxy::ChunkedArray>(std::move(chunked_array));
+    }
+
+    std::shared_ptr<arrow::ChunkedArray> ChunkedArray::unwrap() {
+        return chunked_array;
+    }
+
+    void ChunkedArray::getLength(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->length());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getNumChunks(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->num_chunks());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getChunk(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        
+        mda::StructArray args = context.inputs[0];
+        const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
+        const auto matlab_index = int32_t(index_mda[0]);
+        
+        // Note: MATLAB uses 1-based indexing, so subtract 1.
+        // arrow::Schema::field does not do any bounds checking.
+        const int32_t index = matlab_index - 1;
+        const auto num_chunks = chunked_array->num_chunks();
+        
+        if (num_chunks == 0) {
+            context.error = makeEmptyChunkedArrayError();
+            return;
+        }
+        
+        if (matlab_index < 1 || matlab_index > num_chunks) {
+            context.error = makeInvalidNumericIndexError(matlab_index, num_chunks);
+            return;
+        }
+
+        const auto array = chunked_array->chunk(index);
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto array_proxy,
+                                            arrow::matlab::array::proxy::wrap(array),
+                                            context,
+                                            error::UNKNOWN_PROXY_FOR_ARRAY_TYPE);
+        
+        
+        const auto array_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(array_proxy);
+        const auto type_id = static_cast<int64_t>(array->type_id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(array_proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;
+    }
+
+
+    void ChunkedArray::getType(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+
+        mda::ArrayFactory factory;
+
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto type_proxy,
+                                            type::proxy::wrap(chunked_array->type()),
+                                            context,
+                                            error::ARRAY_FAILED_TO_CREATE_TYPE_PROXY);
+
+
+        const auto proxy_id = libmexclass::proxy::ProxyManager::manageProxy(type_proxy);
+        const auto type_id = static_cast<int32_t>(type_proxy->unwrap()->id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;
+    }
+
+    void ChunkedArray::isEqual(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+
+        const mda::TypedArray<uint64_t> chunked_array_proxy_ids = context.inputs[0];
+
+        bool is_equal = true;
+        for (const auto& chunked_array_proxy_id : chunked_array_proxy_ids) {
+           // Retrieve the ChunkedArray proxy from the ProxyManager

Review Comment:
   ```suggestion
               // Retrieve the ChunkedArray proxy from the ProxyManager
   ```



##########
matlab/src/cpp/arrow/matlab/array/proxy/chunked_array.cc:
##########
@@ -0,0 +1,187 @@
+// 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/util/utf8.h"
+
+#include "arrow/matlab/array/proxy/chunked_array.h"
+#include "arrow/matlab/array/proxy/array.h"
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/type/proxy/wrap.h"
+#include "arrow/matlab/array/proxy/wrap.h"
+
+#include "libmexclass/proxy/ProxyManager.h"
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        libmexclass::error::Error makeEmptyChunkedArrayError() {
+            const std::string error_msg =  "Numeric indexing using the chunk method is not supported for chunked arrays with zero chunks.";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_NUMERIC_INDEX_WITH_EMPTY_CHUNKED_ARRAY, error_msg};
+        }
+
+        libmexclass::error::Error makeInvalidNumericIndexError(const int32_t matlab_index, const int32_t num_chunks) {
+            std::stringstream error_message_stream;
+            error_message_stream << "Invalid chunk index: ";
+            error_message_stream << matlab_index;
+            error_message_stream << ". Chunk index must be between 1 and the number of chunks (";
+            error_message_stream << num_chunks;
+            error_message_stream << ").";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_INVALID_NUMERIC_CHUNK_INDEX, error_message_stream.str()};
+        }
+    }
+
+    ChunkedArray::ChunkedArray(std::shared_ptr<arrow::ChunkedArray> chunked_array) : chunked_array{std::move(chunked_array)} {
+
+        // Register Proxy methods.
+        REGISTER_METHOD(ChunkedArray, getLength);
+        REGISTER_METHOD(ChunkedArray, getNumChunks);
+        REGISTER_METHOD(ChunkedArray, getChunk);
+        REGISTER_METHOD(ChunkedArray, getType);
+        REGISTER_METHOD(ChunkedArray, isEqual);
+    }
+
+
+    libmexclass::proxy::MakeResult ChunkedArray::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
+        namespace mda = ::matlab::data;
+
+        mda::StructArray opts = constructor_arguments[0];
+        const mda::TypedArray<uint64_t> array_proxy_ids = opts[0]["ArrayProxyIDs"];
+        const mda::TypedArray<uint64_t> type_proxy_id = opts[0]["TypeProxyID"];
+
+        std::vector<std::shared_ptr<arrow::Array>> arrays;
+        // Retrieve all of the Array Proxy instances from the libmexclass ProxyManager.
+        for (const auto& array_proxy_id : array_proxy_ids) {
+            auto proxy = libmexclass::proxy::ProxyManager::getProxy(array_proxy_id);
+            auto array_proxy = std::static_pointer_cast<proxy::Array>(proxy);
+            auto array = array_proxy->unwrap();
+            arrays.push_back(array);
+        }
+
+        auto proxy = libmexclass::proxy::ProxyManager::getProxy(type_proxy_id[0]);
+        auto type_proxy = std::static_pointer_cast<type::proxy::Type>(proxy);
+        auto type = type_proxy->unwrap();
+
+        MATLAB_ASSIGN_OR_ERROR(auto chunked_array, 
+                               arrow::ChunkedArray::Make(arrays, type),
+                               error::CHUNKED_ARRAY_MAKE_FAILED);
+
+        return std::make_unique<proxy::ChunkedArray>(std::move(chunked_array));
+    }
+
+    std::shared_ptr<arrow::ChunkedArray> ChunkedArray::unwrap() {
+        return chunked_array;
+    }
+
+    void ChunkedArray::getLength(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->length());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getNumChunks(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->num_chunks());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getChunk(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        
+        mda::StructArray args = context.inputs[0];
+        const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
+        const auto matlab_index = int32_t(index_mda[0]);
+        
+        // Note: MATLAB uses 1-based indexing, so subtract 1.
+        // arrow::Schema::field does not do any bounds checking.
+        const int32_t index = matlab_index - 1;
+        const auto num_chunks = chunked_array->num_chunks();
+        
+        if (num_chunks == 0) {
+            context.error = makeEmptyChunkedArrayError();
+            return;
+        }
+        
+        if (matlab_index < 1 || matlab_index > num_chunks) {
+            context.error = makeInvalidNumericIndexError(matlab_index, num_chunks);
+            return;
+        }
+
+        const auto array = chunked_array->chunk(index);
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto array_proxy,
+                                            arrow::matlab::array::proxy::wrap(array),
+                                            context,
+                                            error::UNKNOWN_PROXY_FOR_ARRAY_TYPE);
+        
+        
+        const auto array_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(array_proxy);
+        const auto type_id = static_cast<int64_t>(array->type_id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(array_proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;
+    }
+
+
+    void ChunkedArray::getType(libmexclass::proxy::method::Context& context) {

Review Comment:
   `Array` uses `type()` not `getType()`. Should we use `type()` here too?



##########
matlab/src/cpp/arrow/matlab/array/proxy/chunked_array.cc:
##########
@@ -0,0 +1,187 @@
+// 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/util/utf8.h"
+
+#include "arrow/matlab/array/proxy/chunked_array.h"
+#include "arrow/matlab/array/proxy/array.h"
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/type/proxy/wrap.h"
+#include "arrow/matlab/array/proxy/wrap.h"
+
+#include "libmexclass/proxy/ProxyManager.h"
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        libmexclass::error::Error makeEmptyChunkedArrayError() {
+            const std::string error_msg =  "Numeric indexing using the chunk method is not supported for chunked arrays with zero chunks.";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_NUMERIC_INDEX_WITH_EMPTY_CHUNKED_ARRAY, error_msg};
+        }
+
+        libmexclass::error::Error makeInvalidNumericIndexError(const int32_t matlab_index, const int32_t num_chunks) {
+            std::stringstream error_message_stream;
+            error_message_stream << "Invalid chunk index: ";
+            error_message_stream << matlab_index;
+            error_message_stream << ". Chunk index must be between 1 and the number of chunks (";
+            error_message_stream << num_chunks;
+            error_message_stream << ").";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_INVALID_NUMERIC_CHUNK_INDEX, error_message_stream.str()};
+        }
+    }
+
+    ChunkedArray::ChunkedArray(std::shared_ptr<arrow::ChunkedArray> chunked_array) : chunked_array{std::move(chunked_array)} {
+
+        // Register Proxy methods.
+        REGISTER_METHOD(ChunkedArray, getLength);
+        REGISTER_METHOD(ChunkedArray, getNumChunks);
+        REGISTER_METHOD(ChunkedArray, getChunk);
+        REGISTER_METHOD(ChunkedArray, getType);
+        REGISTER_METHOD(ChunkedArray, isEqual);
+    }
+
+
+    libmexclass::proxy::MakeResult ChunkedArray::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
+        namespace mda = ::matlab::data;
+
+        mda::StructArray opts = constructor_arguments[0];
+        const mda::TypedArray<uint64_t> array_proxy_ids = opts[0]["ArrayProxyIDs"];
+        const mda::TypedArray<uint64_t> type_proxy_id = opts[0]["TypeProxyID"];
+
+        std::vector<std::shared_ptr<arrow::Array>> arrays;
+        // Retrieve all of the Array Proxy instances from the libmexclass ProxyManager.
+        for (const auto& array_proxy_id : array_proxy_ids) {
+            auto proxy = libmexclass::proxy::ProxyManager::getProxy(array_proxy_id);
+            auto array_proxy = std::static_pointer_cast<proxy::Array>(proxy);
+            auto array = array_proxy->unwrap();
+            arrays.push_back(array);
+        }
+
+        auto proxy = libmexclass::proxy::ProxyManager::getProxy(type_proxy_id[0]);
+        auto type_proxy = std::static_pointer_cast<type::proxy::Type>(proxy);
+        auto type = type_proxy->unwrap();
+
+        MATLAB_ASSIGN_OR_ERROR(auto chunked_array, 
+                               arrow::ChunkedArray::Make(arrays, type),
+                               error::CHUNKED_ARRAY_MAKE_FAILED);
+
+        return std::make_unique<proxy::ChunkedArray>(std::move(chunked_array));
+    }
+
+    std::shared_ptr<arrow::ChunkedArray> ChunkedArray::unwrap() {
+        return chunked_array;
+    }
+
+    void ChunkedArray::getLength(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->length());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getNumChunks(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->num_chunks());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getChunk(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        
+        mda::StructArray args = context.inputs[0];
+        const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
+        const auto matlab_index = int32_t(index_mda[0]);
+        
+        // Note: MATLAB uses 1-based indexing, so subtract 1.
+        // arrow::Schema::field does not do any bounds checking.
+        const int32_t index = matlab_index - 1;
+        const auto num_chunks = chunked_array->num_chunks();
+        
+        if (num_chunks == 0) {
+            context.error = makeEmptyChunkedArrayError();
+            return;
+        }
+        
+        if (matlab_index < 1 || matlab_index > num_chunks) {
+            context.error = makeInvalidNumericIndexError(matlab_index, num_chunks);
+            return;
+        }
+
+        const auto array = chunked_array->chunk(index);
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto array_proxy,
+                                            arrow::matlab::array::proxy::wrap(array),
+                                            context,
+                                            error::UNKNOWN_PROXY_FOR_ARRAY_TYPE);
+        
+        
+        const auto array_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(array_proxy);
+        const auto type_id = static_cast<int64_t>(array->type_id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(array_proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;
+    }
+
+
+    void ChunkedArray::getType(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+
+        mda::ArrayFactory factory;
+
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto type_proxy,
+                                            type::proxy::wrap(chunked_array->type()),
+                                            context,
+                                            error::ARRAY_FAILED_TO_CREATE_TYPE_PROXY);
+
+
+        const auto proxy_id = libmexclass::proxy::ProxyManager::manageProxy(type_proxy);
+        const auto type_id = static_cast<int32_t>(type_proxy->unwrap()->id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;

Review Comment:
   `Array::type()` uses 2 row scalars instead of a struct array: https://github.com/apache/arrow/blob/a43206846a02028fc2ac5091c388aa65b07799c1/matlab/src/cpp/arrow/matlab/array/proxy/array.cc#L93-L94
   
   Which is preferred?



##########
matlab/src/cpp/arrow/matlab/array/proxy/chunked_array.cc:
##########
@@ -0,0 +1,187 @@
+// 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/util/utf8.h"
+
+#include "arrow/matlab/array/proxy/chunked_array.h"
+#include "arrow/matlab/array/proxy/array.h"
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/type/proxy/wrap.h"
+#include "arrow/matlab/array/proxy/wrap.h"
+
+#include "libmexclass/proxy/ProxyManager.h"
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        libmexclass::error::Error makeEmptyChunkedArrayError() {
+            const std::string error_msg =  "Numeric indexing using the chunk method is not supported for chunked arrays with zero chunks.";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_NUMERIC_INDEX_WITH_EMPTY_CHUNKED_ARRAY, error_msg};
+        }
+
+        libmexclass::error::Error makeInvalidNumericIndexError(const int32_t matlab_index, const int32_t num_chunks) {
+            std::stringstream error_message_stream;
+            error_message_stream << "Invalid chunk index: ";
+            error_message_stream << matlab_index;
+            error_message_stream << ". Chunk index must be between 1 and the number of chunks (";
+            error_message_stream << num_chunks;
+            error_message_stream << ").";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_INVALID_NUMERIC_CHUNK_INDEX, error_message_stream.str()};
+        }
+    }
+
+    ChunkedArray::ChunkedArray(std::shared_ptr<arrow::ChunkedArray> chunked_array) : chunked_array{std::move(chunked_array)} {
+
+        // Register Proxy methods.
+        REGISTER_METHOD(ChunkedArray, getLength);
+        REGISTER_METHOD(ChunkedArray, getNumChunks);
+        REGISTER_METHOD(ChunkedArray, getChunk);
+        REGISTER_METHOD(ChunkedArray, getType);
+        REGISTER_METHOD(ChunkedArray, isEqual);
+    }
+
+
+    libmexclass::proxy::MakeResult ChunkedArray::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
+        namespace mda = ::matlab::data;
+
+        mda::StructArray opts = constructor_arguments[0];
+        const mda::TypedArray<uint64_t> array_proxy_ids = opts[0]["ArrayProxyIDs"];
+        const mda::TypedArray<uint64_t> type_proxy_id = opts[0]["TypeProxyID"];
+
+        std::vector<std::shared_ptr<arrow::Array>> arrays;
+        // Retrieve all of the Array Proxy instances from the libmexclass ProxyManager.
+        for (const auto& array_proxy_id : array_proxy_ids) {
+            auto proxy = libmexclass::proxy::ProxyManager::getProxy(array_proxy_id);
+            auto array_proxy = std::static_pointer_cast<proxy::Array>(proxy);
+            auto array = array_proxy->unwrap();
+            arrays.push_back(array);
+        }
+
+        auto proxy = libmexclass::proxy::ProxyManager::getProxy(type_proxy_id[0]);
+        auto type_proxy = std::static_pointer_cast<type::proxy::Type>(proxy);
+        auto type = type_proxy->unwrap();
+
+        MATLAB_ASSIGN_OR_ERROR(auto chunked_array, 
+                               arrow::ChunkedArray::Make(arrays, type),
+                               error::CHUNKED_ARRAY_MAKE_FAILED);
+
+        return std::make_unique<proxy::ChunkedArray>(std::move(chunked_array));
+    }
+
+    std::shared_ptr<arrow::ChunkedArray> ChunkedArray::unwrap() {
+        return chunked_array;
+    }
+
+    void ChunkedArray::getLength(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->length());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getNumChunks(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->num_chunks());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getChunk(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        
+        mda::StructArray args = context.inputs[0];
+        const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
+        const auto matlab_index = int32_t(index_mda[0]);
+        
+        // Note: MATLAB uses 1-based indexing, so subtract 1.
+        // arrow::Schema::field does not do any bounds checking.
+        const int32_t index = matlab_index - 1;
+        const auto num_chunks = chunked_array->num_chunks();
+        
+        if (num_chunks == 0) {
+            context.error = makeEmptyChunkedArrayError();
+            return;
+        }
+        
+        if (matlab_index < 1 || matlab_index > num_chunks) {
+            context.error = makeInvalidNumericIndexError(matlab_index, num_chunks);
+            return;
+        }
+
+        const auto array = chunked_array->chunk(index);
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto array_proxy,
+                                            arrow::matlab::array::proxy::wrap(array),
+                                            context,
+                                            error::UNKNOWN_PROXY_FOR_ARRAY_TYPE);
+        
+        
+        const auto array_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(array_proxy);
+        const auto type_id = static_cast<int64_t>(array->type_id());

Review Comment:
   This uses `int64_t` for `arrow::Type::type` and https://github.com/apache/arrow/pull/37525/files#diff-372554407460398c1974859c73ab50b2bbae13bd3a6826a6097981a07924d534R155 uses `int32_t` for `arrow::Type::type`. Which is preferred?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] sgilmore10 commented on a diff in pull request #37525: GH-37448: [MATLAB] Add `arrow.array.ChunkedArray` class

Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #37525:
URL: https://github.com/apache/arrow/pull/37525#discussion_r1313659025


##########
matlab/src/cpp/arrow/matlab/array/proxy/chunked_array.cc:
##########
@@ -0,0 +1,187 @@
+// 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/util/utf8.h"
+
+#include "arrow/matlab/array/proxy/chunked_array.h"
+#include "arrow/matlab/array/proxy/array.h"
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/type/proxy/wrap.h"
+#include "arrow/matlab/array/proxy/wrap.h"
+
+#include "libmexclass/proxy/ProxyManager.h"
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        libmexclass::error::Error makeEmptyChunkedArrayError() {
+            const std::string error_msg =  "Numeric indexing using the chunk method is not supported for chunked arrays with zero chunks.";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_NUMERIC_INDEX_WITH_EMPTY_CHUNKED_ARRAY, error_msg};
+        }
+
+        libmexclass::error::Error makeInvalidNumericIndexError(const int32_t matlab_index, const int32_t num_chunks) {
+            std::stringstream error_message_stream;
+            error_message_stream << "Invalid chunk index: ";
+            error_message_stream << matlab_index;
+            error_message_stream << ". Chunk index must be between 1 and the number of chunks (";
+            error_message_stream << num_chunks;
+            error_message_stream << ").";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_INVALID_NUMERIC_CHUNK_INDEX, error_message_stream.str()};
+        }
+    }
+
+    ChunkedArray::ChunkedArray(std::shared_ptr<arrow::ChunkedArray> chunked_array) : chunked_array{std::move(chunked_array)} {
+
+        // Register Proxy methods.
+        REGISTER_METHOD(ChunkedArray, getLength);
+        REGISTER_METHOD(ChunkedArray, getNumChunks);
+        REGISTER_METHOD(ChunkedArray, getChunk);
+        REGISTER_METHOD(ChunkedArray, getType);
+        REGISTER_METHOD(ChunkedArray, isEqual);
+    }
+
+
+    libmexclass::proxy::MakeResult ChunkedArray::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
+        namespace mda = ::matlab::data;
+
+        mda::StructArray opts = constructor_arguments[0];
+        const mda::TypedArray<uint64_t> array_proxy_ids = opts[0]["ArrayProxyIDs"];
+        const mda::TypedArray<uint64_t> type_proxy_id = opts[0]["TypeProxyID"];
+
+        std::vector<std::shared_ptr<arrow::Array>> arrays;
+        // Retrieve all of the Array Proxy instances from the libmexclass ProxyManager.
+        for (const auto& array_proxy_id : array_proxy_ids) {
+            auto proxy = libmexclass::proxy::ProxyManager::getProxy(array_proxy_id);
+            auto array_proxy = std::static_pointer_cast<proxy::Array>(proxy);
+            auto array = array_proxy->unwrap();
+            arrays.push_back(array);
+        }
+
+        auto proxy = libmexclass::proxy::ProxyManager::getProxy(type_proxy_id[0]);
+        auto type_proxy = std::static_pointer_cast<type::proxy::Type>(proxy);
+        auto type = type_proxy->unwrap();
+
+        MATLAB_ASSIGN_OR_ERROR(auto chunked_array, 
+                               arrow::ChunkedArray::Make(arrays, type),
+                               error::CHUNKED_ARRAY_MAKE_FAILED);
+
+        return std::make_unique<proxy::ChunkedArray>(std::move(chunked_array));
+    }
+
+    std::shared_ptr<arrow::ChunkedArray> ChunkedArray::unwrap() {
+        return chunked_array;
+    }
+
+    void ChunkedArray::getLength(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->length());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getNumChunks(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->num_chunks());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getChunk(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        
+        mda::StructArray args = context.inputs[0];
+        const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
+        const auto matlab_index = int32_t(index_mda[0]);
+        
+        // Note: MATLAB uses 1-based indexing, so subtract 1.
+        // arrow::Schema::field does not do any bounds checking.
+        const int32_t index = matlab_index - 1;
+        const auto num_chunks = chunked_array->num_chunks();
+        
+        if (num_chunks == 0) {
+            context.error = makeEmptyChunkedArrayError();
+            return;
+        }
+        
+        if (matlab_index < 1 || matlab_index > num_chunks) {
+            context.error = makeInvalidNumericIndexError(matlab_index, num_chunks);
+            return;
+        }
+
+        const auto array = chunked_array->chunk(index);
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto array_proxy,
+                                            arrow::matlab::array::proxy::wrap(array),
+                                            context,
+                                            error::UNKNOWN_PROXY_FOR_ARRAY_TYPE);
+        
+        
+        const auto array_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(array_proxy);
+        const auto type_id = static_cast<int64_t>(array->type_id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(array_proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;
+    }
+
+
+    void ChunkedArray::getType(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+
+        mda::ArrayFactory factory;
+
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto type_proxy,
+                                            type::proxy::wrap(chunked_array->type()),
+                                            context,
+                                            error::ARRAY_FAILED_TO_CREATE_TYPE_PROXY);
+
+
+        const auto proxy_id = libmexclass::proxy::ProxyManager::manageProxy(type_proxy);
+        const auto type_id = static_cast<int32_t>(type_proxy->unwrap()->id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;

Review Comment:
   I think the `struct` array is preferred. With the two output parameters, you have to know if output 1 is the proxy id or the type id. I can see someone mixing up the order easily. Returning a `struct` array eliminates this risk. 
   
   I'll go ahead and make that change to `Array`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] sgilmore10 commented on a diff in pull request #37525: GH-37448: [MATLAB] Add `arrow.array.ChunkedArray` class

Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #37525:
URL: https://github.com/apache/arrow/pull/37525#discussion_r1313672684


##########
matlab/src/cpp/arrow/matlab/array/proxy/chunked_array.cc:
##########
@@ -0,0 +1,187 @@
+// 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/util/utf8.h"
+
+#include "arrow/matlab/array/proxy/chunked_array.h"
+#include "arrow/matlab/array/proxy/array.h"
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/type/proxy/wrap.h"
+#include "arrow/matlab/array/proxy/wrap.h"
+
+#include "libmexclass/proxy/ProxyManager.h"
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        libmexclass::error::Error makeEmptyChunkedArrayError() {
+            const std::string error_msg =  "Numeric indexing using the chunk method is not supported for chunked arrays with zero chunks.";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_NUMERIC_INDEX_WITH_EMPTY_CHUNKED_ARRAY, error_msg};
+        }
+
+        libmexclass::error::Error makeInvalidNumericIndexError(const int32_t matlab_index, const int32_t num_chunks) {
+            std::stringstream error_message_stream;
+            error_message_stream << "Invalid chunk index: ";
+            error_message_stream << matlab_index;
+            error_message_stream << ". Chunk index must be between 1 and the number of chunks (";
+            error_message_stream << num_chunks;
+            error_message_stream << ").";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_INVALID_NUMERIC_CHUNK_INDEX, error_message_stream.str()};
+        }
+    }
+
+    ChunkedArray::ChunkedArray(std::shared_ptr<arrow::ChunkedArray> chunked_array) : chunked_array{std::move(chunked_array)} {
+
+        // Register Proxy methods.
+        REGISTER_METHOD(ChunkedArray, getLength);
+        REGISTER_METHOD(ChunkedArray, getNumChunks);
+        REGISTER_METHOD(ChunkedArray, getChunk);
+        REGISTER_METHOD(ChunkedArray, getType);
+        REGISTER_METHOD(ChunkedArray, isEqual);
+    }
+
+
+    libmexclass::proxy::MakeResult ChunkedArray::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
+        namespace mda = ::matlab::data;
+
+        mda::StructArray opts = constructor_arguments[0];
+        const mda::TypedArray<uint64_t> array_proxy_ids = opts[0]["ArrayProxyIDs"];
+        const mda::TypedArray<uint64_t> type_proxy_id = opts[0]["TypeProxyID"];
+
+        std::vector<std::shared_ptr<arrow::Array>> arrays;
+        // Retrieve all of the Array Proxy instances from the libmexclass ProxyManager.
+        for (const auto& array_proxy_id : array_proxy_ids) {
+            auto proxy = libmexclass::proxy::ProxyManager::getProxy(array_proxy_id);
+            auto array_proxy = std::static_pointer_cast<proxy::Array>(proxy);
+            auto array = array_proxy->unwrap();
+            arrays.push_back(array);
+        }
+
+        auto proxy = libmexclass::proxy::ProxyManager::getProxy(type_proxy_id[0]);
+        auto type_proxy = std::static_pointer_cast<type::proxy::Type>(proxy);
+        auto type = type_proxy->unwrap();
+
+        MATLAB_ASSIGN_OR_ERROR(auto chunked_array, 
+                               arrow::ChunkedArray::Make(arrays, type),
+                               error::CHUNKED_ARRAY_MAKE_FAILED);
+
+        return std::make_unique<proxy::ChunkedArray>(std::move(chunked_array));
+    }
+
+    std::shared_ptr<arrow::ChunkedArray> ChunkedArray::unwrap() {
+        return chunked_array;
+    }
+
+    void ChunkedArray::getLength(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->length());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getNumChunks(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->num_chunks());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getChunk(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        
+        mda::StructArray args = context.inputs[0];
+        const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
+        const auto matlab_index = int32_t(index_mda[0]);
+        
+        // Note: MATLAB uses 1-based indexing, so subtract 1.
+        // arrow::Schema::field does not do any bounds checking.
+        const int32_t index = matlab_index - 1;
+        const auto num_chunks = chunked_array->num_chunks();
+        
+        if (num_chunks == 0) {
+            context.error = makeEmptyChunkedArrayError();
+            return;
+        }
+        
+        if (matlab_index < 1 || matlab_index > num_chunks) {
+            context.error = makeInvalidNumericIndexError(matlab_index, num_chunks);
+            return;
+        }
+
+        const auto array = chunked_array->chunk(index);
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto array_proxy,
+                                            arrow::matlab::array::proxy::wrap(array),
+                                            context,
+                                            error::UNKNOWN_PROXY_FOR_ARRAY_TYPE);
+        
+        
+        const auto array_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(array_proxy);
+        const auto type_id = static_cast<int64_t>(array->type_id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(array_proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;
+    }
+
+
+    void ChunkedArray::getType(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+
+        mda::ArrayFactory factory;
+
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto type_proxy,
+                                            type::proxy::wrap(chunked_array->type()),
+                                            context,
+                                            error::ARRAY_FAILED_TO_CREATE_TYPE_PROXY);
+
+
+        const auto proxy_id = libmexclass::proxy::ProxyManager::manageProxy(type_proxy);
+        const auto type_id = static_cast<int32_t>(type_proxy->unwrap()->id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;
+    }
+
+    void ChunkedArray::isEqual(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+
+        const mda::TypedArray<uint64_t> chunked_array_proxy_ids = context.inputs[0];
+
+        bool is_equal = true;
+        for (const auto& chunked_array_proxy_id : chunked_array_proxy_ids) {
+           // Retrieve the ChunkedArray proxy from the ProxyManager

Review Comment:
   good catch! I'll fix that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] conbench-apache-arrow[bot] commented on pull request #37525: GH-37448: [MATLAB] Add `arrow.array.ChunkedArray` class

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #37525:
URL: https://github.com/apache/arrow/pull/37525#issuecomment-1706153493

   After merging your PR, Conbench analyzed the 5 benchmarking runs that have been run so far on merge-commit 47ce129390fa9aeaa737565c3e61712e387fd8be.
   
   There were no benchmark performance regressions. 🎉
   
   The [full Conbench report](https://github.com/apache/arrow/runs/16498811774) has more details. It also includes information about possible false positives for unstable benchmarks that are known to sometimes produce them.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] sgilmore10 commented on a diff in pull request #37525: GH-37448: [MATLAB] Add `arrow.array.ChunkedArray` class

Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #37525:
URL: https://github.com/apache/arrow/pull/37525#discussion_r1313658732


##########
matlab/src/cpp/arrow/matlab/array/proxy/chunked_array.cc:
##########
@@ -0,0 +1,187 @@
+// 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/util/utf8.h"
+
+#include "arrow/matlab/array/proxy/chunked_array.h"
+#include "arrow/matlab/array/proxy/array.h"
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/type/proxy/wrap.h"
+#include "arrow/matlab/array/proxy/wrap.h"
+
+#include "libmexclass/proxy/ProxyManager.h"
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        libmexclass::error::Error makeEmptyChunkedArrayError() {
+            const std::string error_msg =  "Numeric indexing using the chunk method is not supported for chunked arrays with zero chunks.";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_NUMERIC_INDEX_WITH_EMPTY_CHUNKED_ARRAY, error_msg};
+        }
+
+        libmexclass::error::Error makeInvalidNumericIndexError(const int32_t matlab_index, const int32_t num_chunks) {
+            std::stringstream error_message_stream;
+            error_message_stream << "Invalid chunk index: ";
+            error_message_stream << matlab_index;
+            error_message_stream << ". Chunk index must be between 1 and the number of chunks (";
+            error_message_stream << num_chunks;
+            error_message_stream << ").";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_INVALID_NUMERIC_CHUNK_INDEX, error_message_stream.str()};
+        }
+    }
+
+    ChunkedArray::ChunkedArray(std::shared_ptr<arrow::ChunkedArray> chunked_array) : chunked_array{std::move(chunked_array)} {
+
+        // Register Proxy methods.
+        REGISTER_METHOD(ChunkedArray, getLength);
+        REGISTER_METHOD(ChunkedArray, getNumChunks);
+        REGISTER_METHOD(ChunkedArray, getChunk);
+        REGISTER_METHOD(ChunkedArray, getType);
+        REGISTER_METHOD(ChunkedArray, isEqual);
+    }
+
+
+    libmexclass::proxy::MakeResult ChunkedArray::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
+        namespace mda = ::matlab::data;
+
+        mda::StructArray opts = constructor_arguments[0];
+        const mda::TypedArray<uint64_t> array_proxy_ids = opts[0]["ArrayProxyIDs"];
+        const mda::TypedArray<uint64_t> type_proxy_id = opts[0]["TypeProxyID"];
+
+        std::vector<std::shared_ptr<arrow::Array>> arrays;
+        // Retrieve all of the Array Proxy instances from the libmexclass ProxyManager.
+        for (const auto& array_proxy_id : array_proxy_ids) {
+            auto proxy = libmexclass::proxy::ProxyManager::getProxy(array_proxy_id);
+            auto array_proxy = std::static_pointer_cast<proxy::Array>(proxy);
+            auto array = array_proxy->unwrap();
+            arrays.push_back(array);
+        }
+
+        auto proxy = libmexclass::proxy::ProxyManager::getProxy(type_proxy_id[0]);
+        auto type_proxy = std::static_pointer_cast<type::proxy::Type>(proxy);
+        auto type = type_proxy->unwrap();
+
+        MATLAB_ASSIGN_OR_ERROR(auto chunked_array, 
+                               arrow::ChunkedArray::Make(arrays, type),
+                               error::CHUNKED_ARRAY_MAKE_FAILED);
+
+        return std::make_unique<proxy::ChunkedArray>(std::move(chunked_array));
+    }
+
+    std::shared_ptr<arrow::ChunkedArray> ChunkedArray::unwrap() {
+        return chunked_array;
+    }
+
+    void ChunkedArray::getLength(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->length());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getNumChunks(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->num_chunks());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getChunk(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        
+        mda::StructArray args = context.inputs[0];
+        const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
+        const auto matlab_index = int32_t(index_mda[0]);
+        
+        // Note: MATLAB uses 1-based indexing, so subtract 1.
+        // arrow::Schema::field does not do any bounds checking.
+        const int32_t index = matlab_index - 1;
+        const auto num_chunks = chunked_array->num_chunks();
+        
+        if (num_chunks == 0) {
+            context.error = makeEmptyChunkedArrayError();
+            return;
+        }
+        
+        if (matlab_index < 1 || matlab_index > num_chunks) {
+            context.error = makeInvalidNumericIndexError(matlab_index, num_chunks);
+            return;
+        }
+
+        const auto array = chunked_array->chunk(index);
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto array_proxy,
+                                            arrow::matlab::array::proxy::wrap(array),
+                                            context,
+                                            error::UNKNOWN_PROXY_FOR_ARRAY_TYPE);
+        
+        
+        const auto array_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(array_proxy);
+        const auto type_id = static_cast<int64_t>(array->type_id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(array_proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;
+    }
+
+
+    void ChunkedArray::getType(libmexclass::proxy::method::Context& context) {

Review Comment:
   @kevingurney and I talked about this, and we agreed that `getType()` is a bit clearer than `type()`. We planned on updating the other proxy object methods to include "get": `getType()`, `getLength()`,`getColumnNames()`, etc. 
   
   I'll go ahead and make those changes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] sgilmore10 commented on a diff in pull request #37525: GH-37448: [MATLAB] Add `arrow.array.ChunkedArray` class

Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #37525:
URL: https://github.com/apache/arrow/pull/37525#discussion_r1313657248


##########
matlab/src/cpp/arrow/matlab/array/proxy/chunked_array.cc:
##########
@@ -0,0 +1,187 @@
+// 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/util/utf8.h"
+
+#include "arrow/matlab/array/proxy/chunked_array.h"
+#include "arrow/matlab/array/proxy/array.h"
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/type/proxy/wrap.h"
+#include "arrow/matlab/array/proxy/wrap.h"
+
+#include "libmexclass/proxy/ProxyManager.h"
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        libmexclass::error::Error makeEmptyChunkedArrayError() {
+            const std::string error_msg =  "Numeric indexing using the chunk method is not supported for chunked arrays with zero chunks.";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_NUMERIC_INDEX_WITH_EMPTY_CHUNKED_ARRAY, error_msg};
+        }
+
+        libmexclass::error::Error makeInvalidNumericIndexError(const int32_t matlab_index, const int32_t num_chunks) {
+            std::stringstream error_message_stream;
+            error_message_stream << "Invalid chunk index: ";
+            error_message_stream << matlab_index;
+            error_message_stream << ". Chunk index must be between 1 and the number of chunks (";
+            error_message_stream << num_chunks;
+            error_message_stream << ").";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_INVALID_NUMERIC_CHUNK_INDEX, error_message_stream.str()};
+        }
+    }
+
+    ChunkedArray::ChunkedArray(std::shared_ptr<arrow::ChunkedArray> chunked_array) : chunked_array{std::move(chunked_array)} {
+
+        // Register Proxy methods.
+        REGISTER_METHOD(ChunkedArray, getLength);
+        REGISTER_METHOD(ChunkedArray, getNumChunks);
+        REGISTER_METHOD(ChunkedArray, getChunk);
+        REGISTER_METHOD(ChunkedArray, getType);
+        REGISTER_METHOD(ChunkedArray, isEqual);
+    }
+
+
+    libmexclass::proxy::MakeResult ChunkedArray::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
+        namespace mda = ::matlab::data;
+
+        mda::StructArray opts = constructor_arguments[0];
+        const mda::TypedArray<uint64_t> array_proxy_ids = opts[0]["ArrayProxyIDs"];
+        const mda::TypedArray<uint64_t> type_proxy_id = opts[0]["TypeProxyID"];
+
+        std::vector<std::shared_ptr<arrow::Array>> arrays;
+        // Retrieve all of the Array Proxy instances from the libmexclass ProxyManager.
+        for (const auto& array_proxy_id : array_proxy_ids) {
+            auto proxy = libmexclass::proxy::ProxyManager::getProxy(array_proxy_id);
+            auto array_proxy = std::static_pointer_cast<proxy::Array>(proxy);
+            auto array = array_proxy->unwrap();
+            arrays.push_back(array);
+        }
+
+        auto proxy = libmexclass::proxy::ProxyManager::getProxy(type_proxy_id[0]);
+        auto type_proxy = std::static_pointer_cast<type::proxy::Type>(proxy);
+        auto type = type_proxy->unwrap();
+
+        MATLAB_ASSIGN_OR_ERROR(auto chunked_array, 
+                               arrow::ChunkedArray::Make(arrays, type),
+                               error::CHUNKED_ARRAY_MAKE_FAILED);
+
+        return std::make_unique<proxy::ChunkedArray>(std::move(chunked_array));
+    }
+
+    std::shared_ptr<arrow::ChunkedArray> ChunkedArray::unwrap() {
+        return chunked_array;
+    }
+
+    void ChunkedArray::getLength(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->length());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getNumChunks(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->num_chunks());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getChunk(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        
+        mda::StructArray args = context.inputs[0];
+        const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
+        const auto matlab_index = int32_t(index_mda[0]);
+        
+        // Note: MATLAB uses 1-based indexing, so subtract 1.
+        // arrow::Schema::field does not do any bounds checking.
+        const int32_t index = matlab_index - 1;
+        const auto num_chunks = chunked_array->num_chunks();
+        
+        if (num_chunks == 0) {
+            context.error = makeEmptyChunkedArrayError();
+            return;
+        }
+        
+        if (matlab_index < 1 || matlab_index > num_chunks) {
+            context.error = makeInvalidNumericIndexError(matlab_index, num_chunks);
+            return;
+        }
+
+        const auto array = chunked_array->chunk(index);
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto array_proxy,
+                                            arrow::matlab::array::proxy::wrap(array),
+                                            context,
+                                            error::UNKNOWN_PROXY_FOR_ARRAY_TYPE);
+        
+        
+        const auto array_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(array_proxy);
+        const auto type_id = static_cast<int64_t>(array->type_id());

Review Comment:
   Ah, I meant to use `int32_t` here. I'll update the code to use `int32_t`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] kou commented on a diff in pull request #37525: GH-37448: [MATLAB] Add `arrow.array.ChunkedArray` class

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #37525:
URL: https://github.com/apache/arrow/pull/37525#discussion_r1313558721


##########
matlab/src/cpp/arrow/matlab/array/proxy/chunked_array.cc:
##########
@@ -0,0 +1,187 @@
+// 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/util/utf8.h"
+
+#include "arrow/matlab/array/proxy/chunked_array.h"
+#include "arrow/matlab/array/proxy/array.h"
+#include "arrow/matlab/error/error.h"
+#include "arrow/matlab/type/proxy/wrap.h"
+#include "arrow/matlab/array/proxy/wrap.h"
+
+#include "libmexclass/proxy/ProxyManager.h"
+
+namespace arrow::matlab::array::proxy {
+
+    namespace {
+        libmexclass::error::Error makeEmptyChunkedArrayError() {
+            const std::string error_msg =  "Numeric indexing using the chunk method is not supported for chunked arrays with zero chunks.";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_NUMERIC_INDEX_WITH_EMPTY_CHUNKED_ARRAY, error_msg};
+        }
+
+        libmexclass::error::Error makeInvalidNumericIndexError(const int32_t matlab_index, const int32_t num_chunks) {
+            std::stringstream error_message_stream;
+            error_message_stream << "Invalid chunk index: ";
+            error_message_stream << matlab_index;
+            error_message_stream << ". Chunk index must be between 1 and the number of chunks (";
+            error_message_stream << num_chunks;
+            error_message_stream << ").";
+            return libmexclass::error::Error{error::CHUNKED_ARRAY_INVALID_NUMERIC_CHUNK_INDEX, error_message_stream.str()};
+        }
+    }
+
+    ChunkedArray::ChunkedArray(std::shared_ptr<arrow::ChunkedArray> chunked_array) : chunked_array{std::move(chunked_array)} {
+
+        // Register Proxy methods.
+        REGISTER_METHOD(ChunkedArray, getLength);
+        REGISTER_METHOD(ChunkedArray, getNumChunks);
+        REGISTER_METHOD(ChunkedArray, getChunk);
+        REGISTER_METHOD(ChunkedArray, getType);
+        REGISTER_METHOD(ChunkedArray, isEqual);
+    }
+
+
+    libmexclass::proxy::MakeResult ChunkedArray::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
+        namespace mda = ::matlab::data;
+
+        mda::StructArray opts = constructor_arguments[0];
+        const mda::TypedArray<uint64_t> array_proxy_ids = opts[0]["ArrayProxyIDs"];
+        const mda::TypedArray<uint64_t> type_proxy_id = opts[0]["TypeProxyID"];
+
+        std::vector<std::shared_ptr<arrow::Array>> arrays;
+        // Retrieve all of the Array Proxy instances from the libmexclass ProxyManager.
+        for (const auto& array_proxy_id : array_proxy_ids) {
+            auto proxy = libmexclass::proxy::ProxyManager::getProxy(array_proxy_id);
+            auto array_proxy = std::static_pointer_cast<proxy::Array>(proxy);
+            auto array = array_proxy->unwrap();
+            arrays.push_back(array);
+        }
+
+        auto proxy = libmexclass::proxy::ProxyManager::getProxy(type_proxy_id[0]);
+        auto type_proxy = std::static_pointer_cast<type::proxy::Type>(proxy);
+        auto type = type_proxy->unwrap();
+
+        MATLAB_ASSIGN_OR_ERROR(auto chunked_array, 
+                               arrow::ChunkedArray::Make(arrays, type),
+                               error::CHUNKED_ARRAY_MAKE_FAILED);
+
+        return std::make_unique<proxy::ChunkedArray>(std::move(chunked_array));
+    }
+
+    std::shared_ptr<arrow::ChunkedArray> ChunkedArray::unwrap() {
+        return chunked_array;
+    }
+
+    void ChunkedArray::getLength(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->length());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getNumChunks(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        auto length_mda = factory.createScalar(chunked_array->num_chunks());
+        context.outputs[0] = length_mda;
+    }
+
+    void ChunkedArray::getChunk(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+        mda::ArrayFactory factory;
+        
+        mda::StructArray args = context.inputs[0];
+        const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
+        const auto matlab_index = int32_t(index_mda[0]);
+        
+        // Note: MATLAB uses 1-based indexing, so subtract 1.
+        // arrow::Schema::field does not do any bounds checking.
+        const int32_t index = matlab_index - 1;
+        const auto num_chunks = chunked_array->num_chunks();
+        
+        if (num_chunks == 0) {
+            context.error = makeEmptyChunkedArrayError();
+            return;
+        }
+        
+        if (matlab_index < 1 || matlab_index > num_chunks) {
+            context.error = makeInvalidNumericIndexError(matlab_index, num_chunks);
+            return;
+        }
+
+        const auto array = chunked_array->chunk(index);
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto array_proxy,
+                                            arrow::matlab::array::proxy::wrap(array),
+                                            context,
+                                            error::UNKNOWN_PROXY_FOR_ARRAY_TYPE);
+        
+        
+        const auto array_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(array_proxy);
+        const auto type_id = static_cast<int64_t>(array->type_id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(array_proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;
+    }
+
+
+    void ChunkedArray::getType(libmexclass::proxy::method::Context& context) {
+        namespace mda = ::matlab::data;
+
+        mda::ArrayFactory factory;
+
+        MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto type_proxy,
+                                            type::proxy::wrap(chunked_array->type()),
+                                            context,
+                                            error::ARRAY_FAILED_TO_CREATE_TYPE_PROXY);
+
+
+        const auto proxy_id = libmexclass::proxy::ProxyManager::manageProxy(type_proxy);
+        const auto type_id = static_cast<int32_t>(type_proxy->unwrap()->id());
+
+        mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
+        output[0]["ProxyID"] = factory.createScalar(proxy_id);
+        output[0]["TypeID"] = factory.createScalar(type_id);
+        context.outputs[0] = output;

Review Comment:
   `Array::type()` uses 2 raw scalars instead of a struct array: https://github.com/apache/arrow/blob/a43206846a02028fc2ac5091c388aa65b07799c1/matlab/src/cpp/arrow/matlab/array/proxy/array.cc#L93-L94
   
   Which is preferred?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] kou merged pull request #37525: GH-37448: [MATLAB] Add `arrow.array.ChunkedArray` class

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #37525:
URL: https://github.com/apache/arrow/pull/37525


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org