MCPcopy Create free account
hub / github.com/apache/arrow / getFieldByIndex

Method getFieldByIndex

matlab/src/cpp/arrow/matlab/type/proxy/type.cc:52–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52void Type::getFieldByIndex(libmexclass::proxy::method::Context& context) {
53 namespace mda = ::matlab::data;
54 mda::ArrayFactory factory;
55
56 mda::StructArray args = context.inputs[0];
57 const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
58 const auto matlab_index = int32_t(index_mda[0]);
59
60 // Validate there is at least 1 field
61 MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
62 index::validateNonEmptyContainer(data_type->num_fields()), context,
63 error::INDEX_EMPTY_CONTAINER);
64
65 // Validate the matlab index provided is within the range [1, num_fields]
66 MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
67 index::validateInRange(matlab_index, data_type->num_fields()), context,
68 error::INDEX_OUT_OF_RANGE);
69
70 // Note: MATLAB uses 1-based indexing, so subtract 1.
71 // arrow::DataType::field does not do any bounds checking.
72 const int32_t index = matlab_index - 1;
73
74 auto field = data_type->field(index);
75 auto field_proxy = std::make_shared<proxy::Field>(std::move(field));
76 auto field_proxy_id = libmexclass::proxy::ProxyManager::manageProxy(field_proxy);
77 context.outputs[0] = factory.createScalar(field_proxy_id);
78}
79
80void Type::isEqual(libmexclass::proxy::method::Context& context) {
81 namespace mda = ::matlab::data;

Callers

nothing calls this directly

Calls 4

validateInRangeFunction · 0.85
num_fieldsMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected