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

Function from_arrays

matlab/src/cpp/arrow/matlab/tabular/proxy/table.cc:85–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83
84namespace {
85libmexclass::proxy::MakeResult from_arrays(const mda::StructArray& opts) {
86 using ArrayProxy = arrow::matlab::array::proxy::Array;
87 using TableProxy = arrow::matlab::tabular::proxy::Table;
88
89 const mda::TypedArray<uint64_t> arrow_array_proxy_ids = opts[0]["ArrayProxyIDs"];
90 const mda::StringArray column_names = opts[0]["ColumnNames"];
91
92 std::vector<std::shared_ptr<arrow::Array>> arrow_arrays;
93 // Retrieve all of the Arrow Array Proxy instances from the libmexclass ProxyManager.
94 for (const auto& arrow_array_proxy_id : arrow_array_proxy_ids) {
95 auto proxy = libmexclass::proxy::ProxyManager::getProxy(arrow_array_proxy_id);
96 auto arrow_array_proxy = std::static_pointer_cast<ArrayProxy>(proxy);
97 auto arrow_array = arrow_array_proxy->unwrap();
98 arrow_arrays.push_back(arrow_array);
99 }
100
101 std::vector<std::shared_ptr<Field>> fields;
102 for (size_t i = 0; i < arrow_arrays.size(); ++i) {
103 const auto type = arrow_arrays[i]->type();
104 const auto column_name_utf16 = std::u16string(column_names[i]);
105 MATLAB_ASSIGN_OR_ERROR(const auto column_name_utf8,
106 arrow::util::UTF16StringToUTF8(column_name_utf16),
107 error::UNICODE_CONVERSION_ERROR_ID);
108 fields.push_back(std::make_shared<arrow::Field>(column_name_utf8, type));
109 }
110
111 arrow::SchemaBuilder schema_builder;
112 MATLAB_ERROR_IF_NOT_OK(schema_builder.AddFields(fields),
113 error::SCHEMA_BUILDER_ADD_FIELDS_ERROR_ID);
114 MATLAB_ASSIGN_OR_ERROR(const auto schema, schema_builder.Finish(),
115 error::SCHEMA_BUILDER_FINISH_ERROR_ID);
116 const auto num_rows = arrow_arrays.size() == 0 ? 0 : arrow_arrays[0]->length();
117 const auto table = arrow::Table::Make(schema, arrow_arrays, num_rows);
118 return std::make_shared<TableProxy>(table);
119}
120
121libmexclass::proxy::MakeResult from_record_batches(const mda::StructArray& opts) {
122 using RecordBatchProxy = arrow::matlab::tabular::proxy::RecordBatch;

Callers 1

makeMethod · 0.85

Calls 7

push_backMethod · 0.80
AddFieldsMethod · 0.80
MakeFunction · 0.50
unwrapMethod · 0.45
sizeMethod · 0.45
typeMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected