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

Method FromRecordBatches

cpp/src/arrow/table.cc:287–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285}
286
287Result<std::shared_ptr<Table>> Table::FromRecordBatches(
288 std::shared_ptr<Schema> schema,
289 const std::vector<std::shared_ptr<RecordBatch>>& batches) {
290 const int nbatches = static_cast<int>(batches.size());
291 const int ncolumns = static_cast<int>(schema->num_fields());
292
293 int64_t num_rows = 0;
294 for (int i = 0; i < nbatches; ++i) {
295 if (!batches[i]->schema()->Equals(*schema, false)) {
296 return Status::Invalid("Schema at index ", static_cast<int>(i),
297 " was different: \n", schema->ToString(), "\nvs\n",
298 batches[i]->schema()->ToString());
299 }
300 num_rows += batches[i]->num_rows();
301 }
302
303 std::vector<std::shared_ptr<ChunkedArray>> columns(ncolumns);
304 std::vector<std::shared_ptr<Array>> column_arrays(nbatches);
305
306 for (int i = 0; i < ncolumns; ++i) {
307 for (int j = 0; j < nbatches; ++j) {
308 column_arrays[j] = batches[j]->column(i);
309 }
310 columns[i] = std::make_shared<ChunkedArray>(column_arrays, schema->field(i)->type());
311 }
312
313 return Table::Make(std::move(schema), std::move(columns), num_rows);
314}
315
316Result<std::shared_ptr<Table>> Table::FromRecordBatches(
317 const std::vector<std::shared_ptr<RecordBatch>>& batches) {

Callers

nothing calls this directly

Calls 11

InvalidFunction · 0.70
MakeFunction · 0.70
sizeMethod · 0.45
num_fieldsMethod · 0.45
EqualsMethod · 0.45
schemaMethod · 0.45
ToStringMethod · 0.45
num_rowsMethod · 0.45
columnMethod · 0.45
typeMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected