Skip to content

Commit

Permalink
Create datatype proxy from existing ID in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed Jul 7, 2023
1 parent 126fd99 commit fdf34ce
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 10 deletions.
2 changes: 2 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace arrow::matlab::array::proxy {
REGISTER_METHOD(Array, toMATLAB);
REGISTER_METHOD(Array, length);
REGISTER_METHOD(Array, valid);
REGISTER_METHOD(Array, createDataTypeProxy);

}

std::shared_ptr<arrow::Array> Array::getArray() {
Expand Down
2 changes: 2 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Array : public libmexclass::proxy::Proxy {

virtual void toMATLAB(libmexclass::proxy::method::Context& context) = 0;

virtual void createDataTypeProxy(libmexclass::proxy::method::Context& context) = 0;

std::shared_ptr<arrow::Array> array;
};

Expand Down
5 changes: 5 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/boolean_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ namespace arrow::matlab::array::proxy {
context.outputs[0] = logical_array_mda;
}

void BooleanArray::createDataTypeProxy(libmexclass::proxy::method::Context& context) {

}


}
1 change: 1 addition & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/boolean_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace arrow::matlab::array::proxy {
protected:
void toMATLAB(libmexclass::proxy::method::Context& context) override;

void createDataTypeProxy(libmexclass::proxy::method::Context& context) override;
};

}
19 changes: 17 additions & 2 deletions matlab/src/cpp/arrow/matlab/array/proxy/numeric_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "arrow/matlab/bit/unpack.h"
#include "arrow/matlab/type/proxy/primitive_ctype.h"

#include "arrow/matlab/proxy/extract.h"

#include "libmexclass/proxy/Proxy.h"

namespace arrow::matlab::array::proxy {
Expand All @@ -47,15 +49,13 @@ class NumericArray : public arrow::matlab::array::proxy::Array {

using ArrowType = typename arrow::CTypeTraits<CType>::ArrowType;
using BuilderType = typename arrow::CTypeTraits<CType>::BuilderType;
using NumericTypeProxy = type::proxy::PrimitiveCType<CType>;

mda::StructArray opts = constructor_arguments[0];

// Get the mxArray from constructor arguments
const mda::TypedArray<CType> numeric_mda = opts[0]["MatlabArray"];
const mda::TypedArray<bool> valid_mda = opts[0]["Valid"];
const mda::TypedArray<bool> make_copy = opts[0]["DeepCopy"];
const mda::TypedArray<uint64_t> type_proxy_id_mda = opts[0]["TypeProxyID"];

// Get raw pointer of mxArray
auto it(numeric_mda.cbegin());
Expand Down Expand Up @@ -105,6 +105,21 @@ class NumericArray : public arrow::matlab::array::proxy::Array {
::matlab::data::TypedArray<CType> result = factory.createArray({num_elements, 1}, data_begin, data_end);
context.outputs[0] = result;
}

void createDataTypeProxy(libmexclass::proxy::method::Context& context) override {
namespace mda = ::matlab::data;
using NumericType = typename arrow::CTypeTraits<CType>::ArrowType;
using NumericTypeProxy = type::proxy::PrimitiveCType<CType>;

mda::ArrayFactory factory;

const auto type = array->type();
const auto numeric_type = std::static_pointer_cast<NumericType>(type);
auto numeric_type_proxy = std::make_shared<NumericTypeProxy>(numeric_type);
const auto id = libmexclass::proxy::ProxyManager::manageProxy(numeric_type_proxy);
context.outputs[0] = factory.createScalar(id);
}

};

}
3 changes: 3 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,7 @@ namespace arrow::matlab::array::proxy {
mda::TypedArray<int64_t> result = factory.createArray({num_elements, 1}, data_begin, data_end);
context.outputs[0] = result;
}

void TimestampArray::createDataTypeProxy(libmexclass::proxy::method::Context& context) {
}
}
3 changes: 3 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class TimestampArray : public arrow::matlab::array::proxy::Array {
protected:

void toMATLAB(libmexclass::proxy::method::Context& context) override;

void createDataTypeProxy(libmexclass::proxy::method::Context& context) override;

};

}
6 changes: 3 additions & 3 deletions matlab/src/matlab/+arrow/+array/Float64Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

methods
function obj = Float64Array(data, varargin)
type = arrow.type.Float64Type;
[email protected](data, "double", ...
"arrow.array.proxy.Float64Array", type.Proxy.ID, varargin{:});
obj.Type = type;
"arrow.array.proxy.Float64Array", varargin{:});
type_proxy_id = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.Float64Type(type_proxy_id);
end

function data = double(obj)
Expand Down
5 changes: 2 additions & 3 deletions matlab/src/matlab/+arrow/+array/NumericArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@
end

methods
function obj = NumericArray(data, type, proxyName, typeProxyID, opts, nullOpts)
function obj = NumericArray(data, type, proxyName, opts, nullOpts)
arguments
data
type(1, 1) string
proxyName(1, 1) string
typeProxyID(1, 1) uint64
opts.DeepCopy(1, 1) logical = false
nullOpts.InferNulls(1, 1) logical = true
nullOpts.Valid
end
arrow.args.validateTypeAndShape(data, type);
validElements = arrow.args.parseValidElements(data, nullOpts);
opts = struct(MatlabArray=data, Valid=validElements, TypeProxyID=typeProxyID, DeepCopy=opts.DeepCopy);
opts = struct(MatlabArray=data, Valid=validElements, DeepCopy=opts.DeepCopy);
[email protected]("Name", proxyName, "ConstructorArguments", {opts});
obj.MatlabArray = cast(obj.MatlabArray, type);
% Store a reference to the array if not doing a deep copy
Expand Down
12 changes: 10 additions & 2 deletions matlab/src/matlab/+arrow/+type/Float64Type.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@
%FLOAT64Type Type class for float64 data.

methods
function obj = Float64Type()
[email protected]("Name", "arrow.type.proxy.Float64Type", "ConstructorArguments", {})
function obj = Float64Type(ID)
arguments
ID = missing
end
if ismissing(ID)
args = {"Name", "arrow.type.proxy.Float64Type", "ConstructorArguments", {}};
else
args = {"Name", "arrow.type.proxy.Float64Type", "ID", ID};
end
[email protected](args{:});
end
end
end

0 comments on commit fdf34ce

Please sign in to comment.