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

Method getFieldByIndex

matlab/src/cpp/arrow/matlab/tabular/proxy/schema.cc:61–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59std::shared_ptr<arrow::Schema> Schema::unwrap() { return schema; }
60
61void Schema::getFieldByIndex(libmexclass::proxy::method::Context& context) {
62 namespace mda = ::matlab::data;
63 using namespace libmexclass::proxy;
64 using FieldProxy = arrow::matlab::type::proxy::Field;
65 mda::ArrayFactory factory;
66
67 mda::StructArray args = context.inputs[0];
68 const mda::TypedArray<int32_t> index_mda = args[0]["Index"];
69 const auto matlab_index = int32_t(index_mda[0]);
70
71 // Validate there is at least 1 field
72 MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
73 index::validateNonEmptyContainer(schema->num_fields()), context,
74 error::INDEX_EMPTY_CONTAINER);
75
76 // Validate the matlab index provided is within the range [1, num_fields]
77 MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(
78 index::validateInRange(matlab_index, schema->num_fields()), context,
79 error::INDEX_OUT_OF_RANGE);
80
81 // Note: MATLAB uses 1-based indexing, so subtract 1.
82 // arrow::Schema::field does not do any bounds checking.
83 const int32_t index = matlab_index - 1;
84
85 auto field = schema->field(index);
86 auto field_proxy = std::make_shared<FieldProxy>(std::move(field));
87 auto field_proxy_id = ProxyManager::manageProxy(field_proxy);
88 context.outputs[0] = factory.createScalar(field_proxy_id);
89}
90
91void Schema::getFieldByName(libmexclass::proxy::method::Context& context) {
92 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