Skip to content

Commit

Permalink
Update getChunk() and getType() proxy methods to return struct arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed Aug 31, 2023
1 parent 2b2037b commit 7bfa195
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
25 changes: 14 additions & 11 deletions matlab/src/cpp/arrow/matlab/array/proxy/chunked_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "arrow/matlab/array/proxy/wrap.h"

#include "libmexclass/proxy/ProxyManager.h"
#include <iostream>

namespace arrow::matlab::array::proxy {

Expand Down Expand Up @@ -67,6 +68,7 @@ namespace arrow::matlab::array::proxy {
auto array_proxy = std::static_pointer_cast<proxy::Array>(proxy);
auto array = array_proxy->unwrap();
arrays.push_back(array);
std::cout << array->type_id() << std::endl;
}

MATLAB_ASSIGN_OR_ERROR(auto chunked_array,
Expand Down Expand Up @@ -125,14 +127,12 @@ namespace arrow::matlab::array::proxy {


const auto array_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(array_proxy);
const auto array_proxy_id_mda = factory.createScalar(array_proxy_id);
const auto array_type_id_mda = factory.createScalar(static_cast<int32_t>(array->type_id()));

context.outputs[0] = array_proxy_id_mda;
context.outputs[1] = array_type_id_mda;
const auto type_id = static_cast<int64_t>(array->type_id());

auto length_mda = factory.createScalar(chunked_array->num_chunks());
context.outputs[0] = length_mda;
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;
}


Expand All @@ -146,10 +146,13 @@ namespace arrow::matlab::array::proxy {
context,
error::ARRAY_FAILED_TO_CREATE_TYPE_PROXY);

auto type_id = type_proxy->unwrap()->id();
auto proxy_id = libmexclass::proxy::ProxyManager::manageProxy(type_proxy);

context.outputs[0] = factory.createScalar(proxy_id);
context.outputs[1] = factory.createScalar(static_cast<int64_t>(type_id));
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;
}
}
18 changes: 8 additions & 10 deletions matlab/src/matlab/+arrow/+array/ChunkedArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

classdef ChunkedArray < matlab.mixin.CustomDisplay & ...
matlab.mixin.Scalar
%UNTITLED Summary of this class goes here
% Detailed explanation goes here

properties(Hidden, SetAccess=private, GetAccess=public)
Proxy
Expand Down Expand Up @@ -48,17 +46,17 @@
end

function type = get.Type(obj)
[typeID, proxyID] = obj.Proxy.getType();
traits = arrow.type.traits.traits(arrow.type.ID(typeID));
proxy = libmexclass.proxy.Proxy(Name=traits.TypeProxyClassName, ID=proxyID);
typeStruct = obj.Proxy.getType();
traits = arrow.type.traits.traits(arrow.type.ID(typeStruct.TypeID));
proxy = libmexclass.proxy.Proxy(Name=traits.TypeProxyClassName, ID=typeStruct.ProxyID);
type = traits.TypeConstructor(proxy);
end

function array = chunk(obj, index)
index = arrow.internal.validate.index.numeric(index, "int32");
[typeID, proxyID] = obj.Proxy.getChunk(index);
traits = arrow.type.traits.traits(arrow.type.ID(typeID));
proxy = libmexclass.proxy.Proxy(Name=traits.ArrayProxyClassName, ID=proxyID);
function array = chunk(obj, idx)
idx = arrow.internal.validate.index.numeric(idx, "int32", AllowNonScalar=false);
chunkStruct = obj.Proxy.getChunk(struct(Index=idx));
traits = arrow.type.traits.traits(arrow.type.ID(chunkStruct.TypeID));
proxy = libmexclass.proxy.Proxy(Name=traits.ArrayProxyClassName, ID=chunkStruct.ProxyID);
array = traits.ArrayConstructor(proxy);
end
end
Expand Down

0 comments on commit 7bfa195

Please sign in to comment.