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

Function from_record_batches

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

Source from the content-addressed store, hash-verified

119}
120
121libmexclass::proxy::MakeResult from_record_batches(const mda::StructArray& opts) {
122 using RecordBatchProxy = arrow::matlab::tabular::proxy::RecordBatch;
123 using TableProxy = arrow::matlab::tabular::proxy::Table;
124
125 size_t num_rows = 0;
126 const mda::TypedArray<uint64_t> record_batch_proxy_ids = opts[0]["RecordBatchProxyIDs"];
127
128 std::vector<std::shared_ptr<arrow::RecordBatch>> record_batches;
129 // Retrieve all of the Arrow RecordBatch Proxy instances from the libmexclass
130 // ProxyManager.
131 for (const auto& proxy_id : record_batch_proxy_ids) {
132 auto proxy = libmexclass::proxy::ProxyManager::getProxy(proxy_id);
133 auto record_batch_proxy = std::static_pointer_cast<RecordBatch>(proxy);
134 auto record_batch = record_batch_proxy->unwrap();
135 record_batches.push_back(record_batch);
136 num_rows += record_batches.back()->num_rows();
137 }
138
139 // The MATLAB client code that calls this function is responsible for pre-validating
140 // that this function is called with at least one RecordBatch.
141 auto schema = record_batches[0]->schema();
142 size_t num_columns = schema->num_fields();
143 std::vector<std::shared_ptr<ChunkedArray>> columns(num_columns);
144
145 size_t num_batches = record_batches.size();
146
147 for (size_t i = 0; i < num_columns; ++i) {
148 std::vector<std::shared_ptr<Array>> column_arrays(num_batches);
149 for (size_t j = 0; j < num_batches; ++j) {
150 column_arrays[j] = record_batches[j]->column(i);
151 }
152 columns[i] = std::make_shared<ChunkedArray>(column_arrays, schema->field(i)->type());
153 }
154 const auto table = arrow::Table::Make(std::move(schema), std::move(columns), num_rows);
155 return std::make_shared<TableProxy>(table);
156}
157} // anonymous namespace
158
159libmexclass::proxy::MakeResult Table::make(

Callers 1

makeMethod · 0.85

Calls 11

push_backMethod · 0.80
backMethod · 0.80
MakeFunction · 0.50
unwrapMethod · 0.45
num_rowsMethod · 0.45
schemaMethod · 0.45
num_fieldsMethod · 0.45
sizeMethod · 0.45
columnMethod · 0.45
typeMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected