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

Function ReadSchema

cpp/src/arrow/ipc/read_write_test.cc:1335–1391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1333};
1334
1335struct StreamWriterHelper {
1336 static constexpr bool kIsFileFormat = false;
1337
1338 Status Init(const std::shared_ptr<Schema>& schema, const IpcWriteOptions& options) {
1339 ARROW_ASSIGN_OR_RAISE(buffer_, AllocateResizableBuffer(0));
1340 sink_.reset(new io::BufferOutputStream(buffer_));
1341 ARROW_ASSIGN_OR_RAISE(writer_, MakeStreamWriter(sink_.get(), schema, options));
1342 return Status::OK();
1343 }
1344
1345 Status WriteBatch(const std::shared_ptr<RecordBatch>& batch,
1346 const std::shared_ptr<const KeyValueMetadata>& metadata = nullptr) {
1347 RETURN_NOT_OK(writer_->WriteRecordBatch(*batch, metadata));
1348 return Status::OK();
1349 }
1350
1351 Status WriteTable(const RecordBatchVector& batches) {
1352 ARROW_ASSIGN_OR_RAISE(auto table, Table::FromRecordBatches(batches));
1353 return writer_->WriteTable(*table);
1354 }
1355
1356 Status Finish(WriteStats* out_stats = nullptr) {
1357 RETURN_NOT_OK(writer_->Close());
1358 if (out_stats) {
1359 *out_stats = writer_->stats();
1360 }
1361 return sink_->Close();
1362 }
1363
1364 virtual Status ReadBatches(const IpcReadOptions& options,
1365 RecordBatchVector* out_batches,
1366 ReadStats* out_stats = nullptr,
1367 MetadataVector* out_metadata_list = nullptr) {
1368 auto buf_reader = std::make_shared<io::BufferReader>(buffer_);
1369 ARROW_ASSIGN_OR_RAISE(auto reader, RecordBatchStreamReader::Open(buf_reader, options))
1370 if (out_metadata_list) {
1371 while (true) {
1372 ARROW_ASSIGN_OR_RAISE(auto chunk_with_metadata, reader->ReadNext());
1373 if (chunk_with_metadata.batch == nullptr) {
1374 break;
1375 }
1376 out_batches->push_back(chunk_with_metadata.batch);
1377 out_metadata_list->push_back(chunk_with_metadata.custom_metadata);
1378 }
1379 } else {
1380 ARROW_ASSIGN_OR_RAISE(*out_batches, reader->ToRecordBatches());
1381 }
1382
1383 if (out_stats) {
1384 *out_stats = reader->stats();
1385 }
1386 return Status::OK();
1387 }
1388
1389 Status ReadSchema(std::shared_ptr<Schema>* out) {
1390 return ReadSchema(ipc::IpcReadOptions::Defaults(), out);
1391 }
1392

Callers 3

TEST_FFunction · 0.70
DoSchemaRoundTripMethod · 0.70
ReadSchemaMethod · 0.70

Calls 3

DefaultsFunction · 0.50
OKFunction · 0.50
schemaMethod · 0.45

Tested by

no test coverage detected