| 119 | } |
| 120 | |
| 121 | libmexclass::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 | |
| 159 | libmexclass::proxy::MakeResult Table::make( |