kevingurney commented on code in PR #37749: URL: https://github.com/apache/arrow/pull/37749#discussion_r1328727371
########## matlab/src/matlab/+arrow/+type/+traits/StructTraits.m: ########## @@ -0,0 +1,36 @@ +% 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. + +classdef StructTraits < arrow.type.traits.TypeTraits + + properties (Constant) + % TODO: When arrow.array.StructArray is implemented, set these + % proeprties appropriately + ArrayConstructor = missing + ArrayClassName = missing + ArrayProxyClassName = missing + ArrayStaticConstructor = missing + + TypeConstructor = @arrow.type.StructType + TypeClassName = "arrow.type.StructType" + TypeProxyClassName = "arrow.type.proxy.StructType" + + % TODO: When arrow.array.StructArray is implemented, set these + % proeprties appropriately Review Comment: proeprties -> properties ########## matlab/test/arrow/type/tStructType.m: ########## @@ -0,0 +1,190 @@ +% TSTRUCTTYPE Unit tests for arrow.type.StructType + +% 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. + +classdef tStructType < matlab.unittest.TestCase + + properties (Constant) + Field1 = arrow.field("A", arrow.float64()) + Field2 = arrow.field("C", arrow.boolean()) + Field3 = arrow.field("B", arrow.timestamp(TimeUnit="Microsecond", TimeZone="America/New_York")); + end + + methods (Test) + function Basic(tc) + % Verify arrow.struct() returns an arrow.type.StructType + % object. + type = arrow.struct(tc.Field1); + className = string(class(type)); + tc.verifyEqual(className, "arrow.type.StructType"); + tc.verifyEqual(type.ID, arrow.type.ID.Struct); + end + + function TooFewInputsError(tc) + % Verify arrow.struct() errors if given zero input arguments. + fcn = @() arrow.struct(); + tc.verifyError(fcn, "arrow:struct:TooFewInputs"); + end + + function InvalidInputTypeError(tc) + % Verify arrow.struct() errors if any one of the input + % arguments is not an arrow.type.Field object. + fcn = @() arrow.struct(1); + tc.verifyError(fcn, "MATLAB:validation:UnableToConvert"); + end + + function EmptyFieldError(tc) + % Verify arrow.struct() errors if given an empty + % array arrow.type.Field as one of its inputs. Review Comment: empty array -> empty `arrow.type.Field` array ########## matlab/src/matlab/+arrow/+type/+traits/StructTraits.m: ########## @@ -0,0 +1,36 @@ +% 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. + +classdef StructTraits < arrow.type.traits.TypeTraits + + properties (Constant) + % TODO: When arrow.array.StructArray is implemented, set these + % proeprties appropriately Review Comment: proeprties -> properties ########## matlab/src/cpp/arrow/matlab/type/proxy/struct_type.cc: ########## @@ -0,0 +1,44 @@ +// 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/struct_type.h" +#include "arrow/matlab/type/proxy/field.h" +#include "libmexclass/proxy/ProxyManager.h" + +namespace arrow::matlab::type::proxy { + + StructType::StructType(std::shared_ptr<arrow::StructType> struct_type) : Type(std::move(struct_type)) {} + + libmexclass::proxy::MakeResult StructType::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) { + namespace mda = ::matlab::data; + using StructTypeProxy = arrow::matlab::type::proxy::StructType; + + mda::StructArray args = constructor_arguments[0]; + const mda::TypedArray<uint64_t> field_proxy_ids_mda = args[0]["FieldProxyIDs"]; + + std::vector<std::shared_ptr<arrow::Field>> fields; Review Comment: Should we call `reserve` here to request to avoid potentially repeatedly dynamically resizing the vector as we push back more fields? ########## matlab/test/arrow/type/tStructType.m: ########## @@ -0,0 +1,190 @@ +% TSTRUCTTYPE Unit tests for arrow.type.StructType + +% 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. + +classdef tStructType < matlab.unittest.TestCase + + properties (Constant) + Field1 = arrow.field("A", arrow.float64()) + Field2 = arrow.field("C", arrow.boolean()) + Field3 = arrow.field("B", arrow.timestamp(TimeUnit="Microsecond", TimeZone="America/New_York")); + end + + methods (Test) + function Basic(tc) + % Verify arrow.struct() returns an arrow.type.StructType + % object. + type = arrow.struct(tc.Field1); + className = string(class(type)); + tc.verifyEqual(className, "arrow.type.StructType"); + tc.verifyEqual(type.ID, arrow.type.ID.Struct); + end + + function TooFewInputsError(tc) + % Verify arrow.struct() errors if given zero input arguments. + fcn = @() arrow.struct(); + tc.verifyError(fcn, "arrow:struct:TooFewInputs"); + end + + function InvalidInputTypeError(tc) + % Verify arrow.struct() errors if any one of the input + % arguments is not an arrow.type.Field object. + fcn = @() arrow.struct(1); + tc.verifyError(fcn, "MATLAB:validation:UnableToConvert"); + end + + function EmptyFieldError(tc) + % Verify arrow.struct() errors if given an empty + % array arrow.type.Field as one of its inputs. + fcn = @() arrow.struct(tc.Field1, arrow.type.Field.empty(0, 0)); + tc.verifyError(fcn, "MATLAB:validators:mustBeNonempty"); + end + + function NumFieldsGetter(tc) + % Verify the NumFields getter returns the expected value. + type = arrow.struct(tc.Field1); + tc.verifyEqual(type.NumFields, int32(1)); + + type = arrow.struct(tc.Field1, tc.Field2); + tc.verifyEqual(type.NumFields, int32(2)); + + type = arrow.struct(tc.Field1, tc.Field2, tc.Field3); + tc.verifyEqual(type.NumFields, int32(3)); + end + + function NumFieldsNoSetter(tc) + % Verify the NumFields property is not settable. + type = arrow.struct(tc.Field1); + fcn = @() setfield(type, "NumFields", 20); + tc.verifyError(fcn, "MATLAB:class:SetProhibited"); + end + + function FieldsGetter(tc) + % Verify the Fields getter returns the expected + % arrow.type.Field array. + type = arrow.struct(tc.Field1, tc.Field2, tc.Field3); + actual = type.Fields; + expected = [tc.Field1, tc.Field2, tc.Field3]; + tc.verifyEqual(actual, expected); + end + + function FieldsNoSetter(tc) + % Verify the Fields property is not settable. + type = arrow.struct(tc.Field1, tc.Field2, tc.Field3); + fcn = @() setfield(type, "Fields", tc.Field3); + tc.verifyError(fcn, "MATLAB:class:SetProhibited"); + end + + function IDGetter(tc) + % Verify the ID getter returns the expected enum value. + type = arrow.struct(tc.Field1); + actual = type.ID; + expected = arrow.type.ID.Struct; + tc.verifyEqual(actual, expected); + end + + function IDNoSetter(tc) + % Verify the ID property is not settable. + type = arrow.struct(tc.Field1); + fcn = @() setfield(type, "ID", arrow.type.ID.Boolean); + tc.verifyError(fcn, "MATLAB:class:SetProhibited"); + end + + function FieldMethod(tc) + % Verify the field method returns the expected arrow.type.Field + % with respect to the index provided. + type = arrow.struct(tc.Field1, tc.Field2, tc.Field3); + + % Extract the 1st field + actual1 = type.field(1); + expected1 = tc.Field1; + tc.verifyEqual(actual1, expected1); + + % Extract the 2nd field + actual2 = type.field(2); + expected2 = tc.Field2; + tc.verifyEqual(actual2, expected2); + + % Extract the 3rd field + actual3 = type.field(3); + expected3 = tc.Field3; + tc.verifyEqual(actual3, expected3); + end + + function FieldIndexOutOfRangeError(tc) + % Verify field() throws an error if provided an index that + % exceeds NumFields. + type = arrow.struct(tc.Field1, tc.Field2, tc.Field3); + fcn = @() type.field(100); + tc.verifyError(fcn, "arrow:index:OutOfRange"); + end + + function FieldIndexNonScalarError(tc) + % Verify field() throws an error if provided a nonscalar array + % of indices. + type = arrow.struct(tc.Field1, tc.Field2, tc.Field3); + fcn = @() type.field([1 2]); + tc.verifyError(fcn, "arrow:badsubscript:NonScalar"); + end + + function FieldIndexNonNumberError(tc) + % Verify field() throws an error if not provided a number as Review Comment: "not provided a number as the integer" -> "not provided a number as the index" ########## matlab/src/matlab/+arrow/+type/StructType.m: ########## @@ -0,0 +1,42 @@ +% 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. + +classdef StructType < arrow.type.Type + + methods + function obj = StructType(proxy) + arguments + proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.StructType")} + end + import arrow.internal.proxy.validate + [email protected](proxy); + end + end + + methods(Access = protected) + function groups = getDisplayPropertyGroups(obj) + targets = ["ID", "Fields"]; + groups = matlab.mixin.util.PropertyGroup(targets); + end + end + + methods(Hidden) + % TODO: Consider using a mixin approach to add this behavior Review Comment: It would be helpful to provide more context here describing what is being suggested by this comment. ########## matlab/src/matlab/+arrow/+type/StructType.m: ########## @@ -0,0 +1,42 @@ +% 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. + +classdef StructType < arrow.type.Type + + methods + function obj = StructType(proxy) + arguments + proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.StructType")} + end + import arrow.internal.proxy.validate + [email protected](proxy); + end + end + + methods(Access = protected) + function groups = getDisplayPropertyGroups(obj) + targets = ["ID", "Fields"]; + groups = matlab.mixin.util.PropertyGroup(targets); + end + end + + methods(Hidden) Review Comment: Just stylistic preference - could we add a space between `methods` and `(Hidden)`? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
