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

Function ReadSchema

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

Source from the content-addressed store, hash-verified

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

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