You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "sgilmore10 (via GitHub)" <gi...@apache.org> on 2023/09/14 16:30:30 UTC
[GitHub] [arrow] sgilmore10 opened a new pull request, #37725: GH-37654: [MATLAB] Add `Fields` property to `arrow.type.Type` MATLAB class
sgilmore10 opened a new pull request, #37725:
URL: https://github.com/apache/arrow/pull/37725
### Rationale for this change
In order to implement `arrow.array.StructType`, we need to add a property called `Fields` to `arrow.type.Type`. This property will be a N-by-1 `arrow.type.Field` array. Adding `Fields` will let users inspect the `Type`s contained by a `StructType` object.
### What changes are included in this PR?
1. Added `Fields` as a property to `arrow.type.Type`. `Fields` is a 1xN `arrow.type.Field` array, where `N` is the number of fields.
2. Added method `field(idx)` to `arrow.type.Type`. This method accepts a numeric index and returns the `arrow.type.Field` stored at the specified index.
### Are these changes tested?
1. Yes, updated `hFixedWidthType.m` and `tStringType.m` to verify the behavior of the new property and method.
2. Currently, all of the concrete `arrow.type.Type`s do not have any fields. This means the `Fields` property is always a 0x0 `arrow.type.Field` array. Once we implement `StructType`, we will be able to test having a nonempty `Fields` property.
### Are there any user-facing changes?
Yes, users can now extract fields from an `arrow.type.Type` object.
### Future Directions
1. #37724
2. #37653
--
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
[GitHub] [arrow] sgilmore10 commented on a diff in pull request #37725: GH-37654: [MATLAB] Add `Fields` property to `arrow.type.Type` MATLAB class
Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #37725:
URL: https://github.com/apache/arrow/pull/37725#discussion_r1327470470
##########
matlab/src/matlab/+arrow/+type/Type.m:
##########
@@ -41,6 +42,29 @@
function typeID = get.ID(obj)
typeID = arrow.type.ID(obj.Proxy.getTypeID());
end
+
+ function F = field(obj, idx)
Review Comment:
Added an issue to track this: #37740
--
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
[GitHub] [arrow] sgilmore10 commented on a diff in pull request #37725: GH-37654: [MATLAB] Add `Fields` property to `arrow.type.Type` MATLAB class
Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #37725:
URL: https://github.com/apache/arrow/pull/37725#discussion_r1327617303
##########
matlab/src/cpp/arrow/matlab/type/proxy/type.cc:
##########
@@ -47,6 +52,36 @@ namespace arrow::matlab::type::proxy {
context.outputs[0] = num_fields_mda;
}
+ void Type::getFieldByIndex(libmexclass::proxy::method::Context& context) {
+ namespace mda = ::matlab::data;
+ mda::ArrayFactory factory;
+
+ mda::StructArray args = context.inputs[0];
+ const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
+ const auto matlab_index = int32_t(index_mda[0]);
+
+ // Validate there is at least 1 field
+ MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
+ index::validateNonEmptyFields(data_type->num_fields()),
+ context,
+ error::INDEX_EMPTY_CONTAINER);
+
+ // Validate the matlab index provided is within the range [1, num_fields]
+ MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
+ index::validateNumericFieldIndexInRange(matlab_index, data_type->num_fields()),
+ context,
+ error::INDEX_OUT_OF_RANGE);
+
+ // Note: MATLAB uses 1-based indexing, so subtract 1.
+ // arrow::Schema::field does not do any bounds checking.
Review Comment:
Fixed!
--
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
[GitHub] [arrow] sgilmore10 commented on a diff in pull request #37725: GH-37654: [MATLAB] Add `Fields` property to `arrow.type.Type` MATLAB class
Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #37725:
URL: https://github.com/apache/arrow/pull/37725#discussion_r1327438030
##########
matlab/src/matlab/+arrow/+type/Type.m:
##########
@@ -41,6 +42,29 @@
function typeID = get.ID(obj)
typeID = arrow.type.ID(obj.Proxy.getTypeID());
end
+
+ function F = field(obj, idx)
Review Comment:
That's a good point. However, if we renamed `field` to `getField`, it would be inconsistent with other method names, such as `column`, `chunk`, etc. I'll make an issue and link it below to consider the naming of these methods.
##########
matlab/src/cpp/arrow/matlab/error/error.h:
##########
@@ -195,6 +192,6 @@ namespace arrow::matlab::error {
static const char* CHUNKED_ARRAY_MAKE_FAILED = "arrow:chunkedarray:MakeFailed";
static const char* CHUNKED_ARRAY_NUMERIC_INDEX_WITH_EMPTY_CHUNKED_ARRAY = "arrow:chunkedarray:NumericIndexWithEmptyChunkedArray";
static const char* CHUNKED_ARRAY_INVALID_NUMERIC_CHUNK_INDEX = "arrow:chunkedarray:InvalidNumericChunkIndex";
-
-
+ static const char* ARROW_NUMERIC_INDEX_ZERO_FIELDS = "arrow:index:NumericIndexWithZeroFields";
+ static const char* ARROW_INVALID_NUMERIC_FIELD_INDEX = "arrow:index:InvalidNumericFieldIndex";
Review Comment:
Will do!
--
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
[GitHub] [arrow] sgilmore10 commented on a diff in pull request #37725: GH-37654: [MATLAB] Add `Fields` property to `arrow.type.Type` MATLAB class
Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #37725:
URL: https://github.com/apache/arrow/pull/37725#discussion_r1327612882
##########
matlab/src/cpp/arrow/matlab/index/validate.cc:
##########
@@ -0,0 +1,56 @@
+// 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/index/validate.h"
+
+#include <sstream>
+
+namespace arrow::matlab::index {
+
+ namespace {
+ std::string makeZeroFieldsErrorMessage() {
+ return "Numeric indexing using the field method is not supported for objects with zero fields.";
+ }
+
+ std::string makeInvalidNumericFieldIndexErrorMessage(const int32_t matlab_index, const int32_t num_fields) {
+ std::stringstream error_message_stream;
+ error_message_stream << "Invalid field index: ";
+ // matlab uses 1-based indexing
+ error_message_stream << matlab_index;
+ error_message_stream << ". Field index must be between 1 and the number of fields (";
+ error_message_stream << num_fields;
+ error_message_stream << ").";
+ return error_message_stream.str();
+ }
+ } // anonymous namespace
+
+ arrow::Status validateNonEmptyFields(const int32_t num_fields) {
+ if (num_fields == 0) {
+ const auto msg = makeZeroFieldsErrorMessage();
+ return arrow::Status::Invalid(std::move(msg));
+ }
+ return arrow::Status::OK();
+ }
+
+ arrow::Status validateNumericFieldIndexInRange(const int32_t matlab_index, const int32_t num_fields) {
+ if (matlab_index < 1 || matlab_index > num_fields) {
+ const auto msg = makeInvalidNumericFieldIndexErrorMessage(matlab_index, num_fields);
Review Comment:
Good point! I'll also rename the `validateNumericFieldIndexInRange` to `validateInRange`.
--
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
[GitHub] [arrow] sgilmore10 commented on a diff in pull request #37725: GH-37654: [MATLAB] Add `Fields` property to `arrow.type.Type` MATLAB class
Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #37725:
URL: https://github.com/apache/arrow/pull/37725#discussion_r1327614294
##########
matlab/src/cpp/arrow/matlab/index/validate.cc:
##########
@@ -0,0 +1,56 @@
+// 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/index/validate.h"
+
+#include <sstream>
+
+namespace arrow::matlab::index {
+
+ namespace {
+ std::string makeZeroFieldsErrorMessage() {
+ return "Numeric indexing using the field method is not supported for objects with zero fields.";
+ }
+
+ std::string makeInvalidNumericFieldIndexErrorMessage(const int32_t matlab_index, const int32_t num_fields) {
+ std::stringstream error_message_stream;
+ error_message_stream << "Invalid field index: ";
+ // matlab uses 1-based indexing
+ error_message_stream << matlab_index;
+ error_message_stream << ". Field index must be between 1 and the number of fields (";
+ error_message_stream << num_fields;
+ error_message_stream << ").";
+ return error_message_stream.str();
+ }
+ } // anonymous namespace
+
+ arrow::Status validateNonEmptyFields(const int32_t num_fields) {
+ if (num_fields == 0) {
+ const auto msg = makeZeroFieldsErrorMessage();
+ return arrow::Status::Invalid(std::move(msg));
+ }
+ return arrow::Status::OK();
+ }
+
+ arrow::Status validateNumericFieldIndexInRange(const int32_t matlab_index, const int32_t num_fields) {
+ if (matlab_index < 1 || matlab_index > num_fields) {
+ const auto msg = makeInvalidNumericFieldIndexErrorMessage(matlab_index, num_fields);
Review Comment:
I'll also rename `validateNonEmptyFields `to `validateNonEmptyContainer`.
--
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
[GitHub] [arrow] kevingurney commented on a diff in pull request #37725: GH-37654: [MATLAB] Add `Fields` property to `arrow.type.Type` MATLAB class
Posted by "kevingurney (via GitHub)" <gi...@apache.org>.
kevingurney commented on code in PR #37725:
URL: https://github.com/apache/arrow/pull/37725#discussion_r1327604159
##########
matlab/src/cpp/arrow/matlab/type/proxy/type.cc:
##########
@@ -47,6 +52,36 @@ namespace arrow::matlab::type::proxy {
context.outputs[0] = num_fields_mda;
}
+ void Type::getFieldByIndex(libmexclass::proxy::method::Context& context) {
+ namespace mda = ::matlab::data;
+ mda::ArrayFactory factory;
+
+ mda::StructArray args = context.inputs[0];
+ const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
+ const auto matlab_index = int32_t(index_mda[0]);
+
+ // Validate there is at least 1 field
+ MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
+ index::validateNonEmptyFields(data_type->num_fields()),
+ context,
+ error::INDEX_EMPTY_CONTAINER);
+
+ // Validate the matlab index provided is within the range [1, num_fields]
+ MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
+ index::validateNumericFieldIndexInRange(matlab_index, data_type->num_fields()),
+ context,
+ error::INDEX_OUT_OF_RANGE);
+
+ // Note: MATLAB uses 1-based indexing, so subtract 1.
+ // arrow::Schema::field does not do any bounds checking.
Review Comment:
arrow::Schema::field -> arrow::DataType::field
##########
matlab/src/cpp/arrow/matlab/index/validate.cc:
##########
@@ -0,0 +1,56 @@
+// 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/index/validate.h"
+
+#include <sstream>
+
+namespace arrow::matlab::index {
+
+ namespace {
+ std::string makeZeroFieldsErrorMessage() {
+ return "Numeric indexing using the field method is not supported for objects with zero fields.";
+ }
+
+ std::string makeInvalidNumericFieldIndexErrorMessage(const int32_t matlab_index, const int32_t num_fields) {
+ std::stringstream error_message_stream;
+ error_message_stream << "Invalid field index: ";
+ // matlab uses 1-based indexing
+ error_message_stream << matlab_index;
+ error_message_stream << ". Field index must be between 1 and the number of fields (";
+ error_message_stream << num_fields;
+ error_message_stream << ").";
+ return error_message_stream.str();
+ }
+ } // anonymous namespace
+
+ arrow::Status validateNonEmptyFields(const int32_t num_fields) {
+ if (num_fields == 0) {
+ const auto msg = makeZeroFieldsErrorMessage();
+ return arrow::Status::Invalid(std::move(msg));
+ }
+ return arrow::Status::OK();
+ }
+
+ arrow::Status validateNumericFieldIndexInRange(const int32_t matlab_index, const int32_t num_fields) {
+ if (matlab_index < 1 || matlab_index > num_fields) {
+ const auto msg = makeInvalidNumericFieldIndexErrorMessage(matlab_index, num_fields);
Review Comment:
Now that you've updated the error message IDs, it may make sense to update the function names too:
`makeInvalidNumericFieldIndexErrorMessage` -> `makeIndexOutOfRangeErrorMessage`
--
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
[GitHub] [arrow] kevingurney merged pull request #37725: GH-37654: [MATLAB] Add `Fields` property to `arrow.type.Type` MATLAB class
Posted by "kevingurney (via GitHub)" <gi...@apache.org>.
kevingurney merged PR #37725:
URL: https://github.com/apache/arrow/pull/37725
--
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
[GitHub] [arrow] kevingurney commented on pull request #37725: GH-37654: [MATLAB] Add `Fields` property to `arrow.type.Type` MATLAB class
Posted by "kevingurney (via GitHub)" <gi...@apache.org>.
kevingurney commented on PR #37725:
URL: https://github.com/apache/arrow/pull/37725#issuecomment-1721686833
+1
--
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
[GitHub] [arrow] conbench-apache-arrow[bot] commented on pull request #37725: GH-37654: [MATLAB] Add `Fields` property to `arrow.type.Type` MATLAB class
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #37725:
URL: https://github.com/apache/arrow/pull/37725#issuecomment-1722104621
After merging your PR, Conbench analyzed the 5 benchmarking runs that have been run so far on merge-commit e32e87529e0810572821b0e11afbe1562f1e7edd.
There were no benchmark performance regressions. 🎉
The [full Conbench report](https://github.com/apache/arrow/runs/16846916843) has more details.
--
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
[GitHub] [arrow] kou commented on a diff in pull request #37725: GH-37654: [MATLAB] Add `Fields` property to `arrow.type.Type` MATLAB class
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #37725:
URL: https://github.com/apache/arrow/pull/37725#discussion_r1326861806
##########
matlab/src/matlab/+arrow/+type/Type.m:
##########
@@ -41,6 +42,29 @@
function typeID = get.ID(obj)
typeID = arrow.type.ID(obj.Proxy.getTypeID());
end
+
+ function F = field(obj, idx)
Review Comment:
`getField` may be better.
##########
matlab/src/cpp/arrow/matlab/error/error.h:
##########
@@ -195,6 +192,6 @@ namespace arrow::matlab::error {
static const char* CHUNKED_ARRAY_MAKE_FAILED = "arrow:chunkedarray:MakeFailed";
static const char* CHUNKED_ARRAY_NUMERIC_INDEX_WITH_EMPTY_CHUNKED_ARRAY = "arrow:chunkedarray:NumericIndexWithEmptyChunkedArray";
static const char* CHUNKED_ARRAY_INVALID_NUMERIC_CHUNK_INDEX = "arrow:chunkedarray:InvalidNumericChunkIndex";
-
-
+ static const char* ARROW_NUMERIC_INDEX_ZERO_FIELDS = "arrow:index:NumericIndexWithZeroFields";
+ static const char* ARROW_INVALID_NUMERIC_FIELD_INDEX = "arrow:index:InvalidNumericFieldIndex";
Review Comment:
`INDEX_XXX = "..."` may be better because (most) other constant names have the `XXX` part in `arrow:XXX:YYY` and doesn't have `ARROW_` prefix.
--
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