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

Method getFieldByIndex

matlab/src/cpp/arrow/matlab/array/proxy/struct_array.cc:92–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92void StructArray::getFieldByIndex(libmexclass::proxy::method::Context& context) {
93 namespace mda = ::matlab::data;
94 using namespace libmexclass::proxy;
95
96 mda::StructArray args = context.inputs[0];
97 const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
98 const auto matlab_index = int32_t(index_mda[0]);
99
100 auto struct_array = std::static_pointer_cast<arrow::StructArray>(array);
101
102 const auto num_fields = struct_array->type()->num_fields();
103
104 // Validate there is at least 1 field
105 MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(index::validateNonEmptyContainer(num_fields),
106 context, error::INDEX_EMPTY_CONTAINER);
107
108 // Validate the matlab index provided is within the range [1, num_fields]
109 MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(index::validateInRange(matlab_index, num_fields),
110 context, error::INDEX_OUT_OF_RANGE);
111
112 // Note: MATLAB uses 1-based indexing, so subtract 1.
113 const int32_t index = matlab_index - 1;
114
115 auto field_array = struct_array->field(index);
116 MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(context.outputs[0],
117 arrow::matlab::proxy::wrap_and_manage(field_array),
118 context, error::UNKNOWN_PROXY_FOR_ARRAY_TYPE);
119}
120
121void StructArray::getFieldByName(libmexclass::proxy::method::Context& context) {
122 namespace mda = ::matlab::data;

Callers

nothing calls this directly

Calls 6

validateInRangeFunction · 0.85
wrap_and_manageFunction · 0.85
num_fieldsMethod · 0.45
typeMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected