You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "kou (via GitHub)" <gi...@apache.org> on 2023/06/06 07:36:18 UTC

[GitHub] [arrow] kou commented on a diff in pull request #35918: GH-35914: [MATLAB] Integrate the latest libmexclass changes to support error-handling

kou commented on code in PR #35918:
URL: https://github.com/apache/arrow/pull/35918#discussion_r1219088042


##########
matlab/test/arrow/gateway/tGateway.m:
##########
@@ -0,0 +1,28 @@
+classdef tGateway < matlab.unittest.TestCase
+    % Tests for libmexclass.proxy.gateway error conditions.
+
+    % 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.

Review Comment:
   Could you move license header to top-level?
   
   ```suggestion
   % 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 tGateway < matlab.unittest.TestCase
       % Tests for libmexclass.proxy.gateway error conditions.
   ```



##########
matlab/src/cpp/arrow/matlab/array/proxy/numeric_array.h:
##########
@@ -42,52 +43,63 @@ const uint8_t* getUnpackedValidityBitmap(const ::matlab::data::TypedArray<bool>&
 template<typename CType>
 class NumericArray : public arrow::matlab::array::proxy::Array {
     public:
-        NumericArray(const libmexclass::proxy::FunctionArguments& constructor_arguments)
-            : arrow::matlab::array::proxy::Array(constructor_arguments) {
-            using ArrowType = typename arrow::CTypeTraits<CType>::ArrowType;
-            using BuilderType = typename arrow::CTypeTraits<CType>::BuilderType;
+        NumericArray(const std::shared_ptr<arrow::Array> numeric_array)
+            : arrow::matlab::array::proxy::Array() {
+                array = numeric_array;
+            }
 
-            // Get the mxArray from constructor arguments
-            const ::matlab::data::TypedArray<CType> numeric_mda = constructor_arguments[0];
-            const ::matlab::data::TypedArray<bool> make_copy = constructor_arguments[1];
+    
+    static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments)

Review Comment:
   Is this indent level expected?



##########
matlab/src/cpp/arrow/matlab/array/proxy/numeric_array.h:
##########
@@ -25,6 +25,7 @@
 #include "arrow/builder.h"
 #include "arrow/type_traits.h"
 
+#include "arrow/matlab/error/error.h"
 #include "arrow/matlab/array/proxy/array.h"
 #include "arrow/matlab/bit/bit_pack_matlab_logical_array.h"

Review Comment:
   How about keeping this list in alphabetical order?
   
   BTW, do you want to use `clang-format` in `matlab/` like `cpp/`, `python/` and `r/`?
   FYI: Code for `python/`: https://github.com/apache/arrow/blob/e2ae492b63245a8bc6330b10785777ab04659798/dev/archery/archery/utils/lint.py#L262-L284



##########
matlab/src/cpp/arrow/matlab/error/error.h:
##########
@@ -0,0 +1,41 @@
+// 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/status.h"
+#include "libmexclass/error/Error.h"
+
+#include <string_view>
+
+#define MATLAB_ERROR_IF_NOT_OK(expr, id)                               \
+    do {                                                               \
+        arrow::Status _status = (expr);                                \
+        if (!_status.ok()) {                                           \
+            return libmexclass::error::Error{(id), _status.message()}; \
+        }                                                              \
+    } while (0)
+
+namespace arrow::matlab::error {
+    // TODO: Make Error ID Enum class to avoid defining static constexpr
+    static const std::string APPEND_VALUES_ERROR_ID = "arrow:matlab:proxy:make:FailedToAppendValues";

Review Comment:
   Is this `static const std::string` safe in C++?
   I think that we need to use `static const char*` or `static constexpr std::string_view` instead of `static const std::string`.



##########
matlab/test/arrow/gateway/tGateway.m:
##########
@@ -0,0 +1,28 @@
+classdef tGateway < matlab.unittest.TestCase
+    % Tests for libmexclass.proxy.gateway error conditions.
+
+    % 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.
+
+    methods (Test)
+        function UnknownProxyError(testCase)
+        % Verify the gateway function errors if given the name of an
+        % unknown proxy class.

Review Comment:
   ```suggestion
               % Verify the gateway function errors if given the name of an
               % unknown proxy class.
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org