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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]