Skip to content

Commit

Permalink
Implement getValues() method on ListArray proxy C++ class
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed Oct 11, 2023
1 parent f07977e commit 528168f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions matlab/src/cpp/arrow/matlab/array/proxy/list_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "arrow/matlab/array/proxy/list_array.h"
#include "arrow/matlab/array/proxy/wrap.h"

#include "arrow/matlab/error/error.h"
#include "libmexclass/proxy/ProxyManager.h"

namespace arrow::matlab::array::proxy {
Expand All @@ -31,7 +31,25 @@ namespace arrow::matlab::array::proxy {

void ListArray::getValues(libmexclass::proxy::method::Context& context) {
namespace mda = ::matlab::data;
// STUB METHOD

auto list_array = std::static_pointer_cast<arrow::ListArray>(array);
auto value_array = list_array->values();

// Wrap the array within a proxy object if possible.
MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(auto value_array_proxy,
proxy::wrap(value_array),
context, error::UNKNOWN_PROXY_FOR_ARRAY_TYPE);
const auto value_array_proxy_id = ProxyManager::manageProxy(value_array_proxy);
const auto type_id = value_array->type_id();

// Return a struct with two fields: ProxyID and TypeID. The MATLAB
// layer will use these values to construct the appropriate MATLAB
// arrow.array.Array subclass.
mda::ArrayFactory factory;
mda::StructArray output = factory.createStructArray({1, 1}, {"ProxyID", "TypeID"});
output[0]["ProxyID"] = factory.createScalar(field_array_proxy_id);
output[0]["TypeID"] = factory.createScalar(static_cast<int32_t>(type_id));
context.outputs[0] = output;
}

void ListArray::getOffsets(libmexclass::proxy::method::Context& context) {
Expand Down

0 comments on commit 528168f

Please sign in to comment.