(Doc section: RunMain)
| 89 | |
| 90 | // (Doc section: RunMain) |
| 91 | arrow::Status RunMain() { |
| 92 | // (Doc section: RunMain) |
| 93 | // (Doc section: Gen Files) |
| 94 | // Generate initial files for each format with a helper function -- don't worry, |
| 95 | // we'll also write a table in this example. |
| 96 | ARROW_RETURN_NOT_OK(GenInitialFile()); |
| 97 | // (Doc section: Gen Files) |
| 98 | |
| 99 | // (Doc section: ReadableFile Definition) |
| 100 | // First, we have to set up a ReadableFile object, which just lets us point our |
| 101 | // readers to the right data on disk. We'll be reusing this object, and rebinding |
| 102 | // it to multiple files throughout the example. |
| 103 | std::shared_ptr<arrow::io::ReadableFile> infile; |
| 104 | // (Doc section: ReadableFile Definition) |
| 105 | // (Doc section: Arrow ReadableFile Open) |
| 106 | // Get "test_in.arrow" into our file pointer |
| 107 | ARROW_ASSIGN_OR_RAISE(infile, arrow::io::ReadableFile::Open( |
| 108 | "test_in.arrow", arrow::default_memory_pool())); |
| 109 | // (Doc section: Arrow ReadableFile Open) |
| 110 | // (Doc section: Arrow Read Open) |
| 111 | // Open up the file with the IPC features of the library, gives us a reader object. |
| 112 | ARROW_ASSIGN_OR_RAISE(auto ipc_reader, arrow::ipc::RecordBatchFileReader::Open(infile)); |
| 113 | // (Doc section: Arrow Read Open) |
| 114 | // (Doc section: Arrow Read) |
| 115 | // Using the reader, we can read Record Batches. Note that this is specific to IPC; |
| 116 | // for other formats, we focus on Tables, but here, RecordBatches are used. |
| 117 | std::shared_ptr<arrow::RecordBatch> rbatch; |
| 118 | ARROW_ASSIGN_OR_RAISE(rbatch, ipc_reader->ReadRecordBatch(0)); |
| 119 | // (Doc section: Arrow Read) |
| 120 | |
| 121 | // (Doc section: Arrow Write Open) |
| 122 | // Just like with input, we get an object for the output file. |
| 123 | std::shared_ptr<arrow::io::FileOutputStream> outfile; |
| 124 | // Bind it to "test_out.arrow" |
| 125 | ARROW_ASSIGN_OR_RAISE(outfile, arrow::io::FileOutputStream::Open("test_out.arrow")); |
| 126 | // (Doc section: Arrow Write Open) |
| 127 | // (Doc section: Arrow Writer) |
| 128 | // Set up a writer with the output file -- and the schema! We're defining everything |
| 129 | // here, loading to fire. |
| 130 | ARROW_ASSIGN_OR_RAISE(std::shared_ptr<arrow::ipc::RecordBatchWriter> ipc_writer, |
| 131 | arrow::ipc::MakeFileWriter(outfile, rbatch->schema())); |
| 132 | // (Doc section: Arrow Writer) |
| 133 | // (Doc section: Arrow Write) |
| 134 | // Write the record batch. |
| 135 | ARROW_RETURN_NOT_OK(ipc_writer->WriteRecordBatch(*rbatch)); |
| 136 | // (Doc section: Arrow Write) |
| 137 | // (Doc section: Arrow Close) |
| 138 | // Specifically for IPC, the writer needs to be explicitly closed. |
| 139 | ARROW_RETURN_NOT_OK(ipc_writer->Close()); |
| 140 | // (Doc section: Arrow Close) |
| 141 | |
| 142 | // (Doc section: CSV Read Open) |
| 143 | // Bind our input file to "test_in.csv" |
| 144 | ARROW_ASSIGN_OR_RAISE(infile, arrow::io::ReadableFile::Open("test_in.csv")); |
| 145 | // (Doc section: CSV Read Open) |
| 146 | // (Doc section: CSV Table Declare) |
| 147 | std::shared_ptr<arrow::Table> csv_table; |
| 148 | // (Doc section: CSV Table Declare) |
no test coverage detected