Skip to content

Commit

Permalink
Add StringType proxy class
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed Jul 6, 2023
1 parent 05b343d commit d89a6d2
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 16 deletions.
2 changes: 2 additions & 0 deletions matlab/src/cpp/arrow/matlab/proxy/factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "arrow/matlab/tabular/proxy/record_batch.h"
#include "arrow/matlab/error/error.h"
#include "arrow/matlab/type/proxy/primitive_ctype.h"
#include "arrow/matlab/type/proxy/string_type.h"
#include "arrow/matlab/type/proxy/timestamp_type.h"

#include "factory.h"
Expand Down Expand Up @@ -54,6 +55,7 @@ libmexclass::proxy::MakeResult Factory::make_proxy(const ClassName& class_name,
REGISTER_PROXY(arrow.type.proxy.Int32Type , arrow::matlab::type::proxy::PrimitiveCType<int32_t>);
REGISTER_PROXY(arrow.type.proxy.Int64Type , arrow::matlab::type::proxy::PrimitiveCType<int64_t>);
REGISTER_PROXY(arrow.type.proxy.BooleanType , arrow::matlab::type::proxy::PrimitiveCType<bool>);
REGISTER_PROXY(arrow.type.proxy.StringType , arrow::matlab::type::proxy::StringType);
REGISTER_PROXY(arrow.type.proxy.TimestampType , arrow::matlab::type::proxy::TimestampType);

return libmexclass::error::Error{error::UNKNOWN_PROXY_ERROR_ID, "Did not find matching C++ proxy for " + class_name};
Expand Down
27 changes: 27 additions & 0 deletions matlab/src/cpp/arrow/matlab/type/proxy/string_type.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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/string_type.h"

namespace arrow::matlab::type::proxy {

StringType::StringType(std::shared_ptr<arrow::StringType> string_type) : Type(string_type) {}

libmexclass::proxy::MakeResult StringType::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
return std::make_shared<StringType>(std::static_pointer_cast<arrow::StringType>(arrow::utf8()));
}
}
35 changes: 35 additions & 0 deletions matlab/src/cpp/arrow/matlab/type/proxy/string_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.

#pragma once

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

namespace arrow::matlab::type::proxy {

class StringType : public arrow::matlab::type::proxy::Type {

public:
StringType(std::shared_ptr<arrow::StringType> string_type);

~StringType() {}

static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments);
};

}

14 changes: 5 additions & 9 deletions matlab/src/matlab/+arrow/+type/StringType.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@
classdef StringType < arrow.type.Type
%STRINGTYPE Type class for string data.

properties(SetAccess = protected)
ID = arrow.type.ID.String
end

properties(Constant)
NumFields = 0
NumBuffers = 3
end

methods
function obj = StringType()
obj@arrow.type.Type("Name", "arrow.type.proxy.StringType", "ConstructorArguments", {});
end
end
end

2 changes: 1 addition & 1 deletion matlab/test/arrow/array/tStringArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function TestArrowType(tc)
% Verify the array has the expected arrow.type.Type object
data = tc.MatlabArrayFcn(["A", "B"]);
arrowArray = tc.ArrowArrayConstructor(data);
tc.verifyEqual(arrowArray.Type, tc.ArrowType);
tc.verifyEqual(arrowArray.Type.ID, tc.ArrowType.ID);
end

function Unicode(tc)
Expand Down
7 changes: 1 addition & 6 deletions matlab/test/arrow/type/tStringType.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ function Basic(tc)
tc.verifyEqual(type.ID, arrow.type.ID.String);
end

function NumBuffers(tc)
type = arrow.type.StringType;
tc.verifyEqual(type.NumBuffers, 3);
end

function NumFields(tc)
type = arrow.type.StringType;
tc.verifyEqual(type.NumFields, 0);
tc.verifyEqual(type.NumFields, int32(0));
end

end
Expand Down
1 change: 1 addition & 0 deletions matlab/tools/cmake/BuildMatlabArrowInterface.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_SOURCES "${CMAKE_SOURCE_DIR}/src/cpp/a
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/time_unit.cc"
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/proxy/type.cc"
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/proxy/fixed_width_type.cc"
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/proxy/string_type.cc"
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/type/proxy/timestamp_type.cc")

set(MATLAB_ARROW_LIBMEXCLASS_CLIENT_PROXY_FACTORY_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy")
Expand Down

0 comments on commit d89a6d2

Please sign in to comment.