(Doc section: GenInitialFile)
| 30 | |
| 31 | // (Doc section: GenInitialFile) |
| 32 | arrow::Status GenInitialFile() { |
| 33 | // Make a couple 8-bit integer arrays and a 16-bit integer array -- just like |
| 34 | // basic Arrow example. |
| 35 | arrow::Int8Builder int8builder; |
| 36 | int8_t days_raw[5] = {1, 12, 17, 23, 28}; |
| 37 | ARROW_RETURN_NOT_OK(int8builder.AppendValues(days_raw, 5)); |
| 38 | std::shared_ptr<arrow::Array> days; |
| 39 | ARROW_ASSIGN_OR_RAISE(days, int8builder.Finish()); |
| 40 | |
| 41 | int8_t months_raw[5] = {1, 3, 5, 7, 1}; |
| 42 | ARROW_RETURN_NOT_OK(int8builder.AppendValues(months_raw, 5)); |
| 43 | std::shared_ptr<arrow::Array> months; |
| 44 | ARROW_ASSIGN_OR_RAISE(months, int8builder.Finish()); |
| 45 | |
| 46 | arrow::Int16Builder int16builder; |
| 47 | int16_t years_raw[5] = {1990, 2000, 1995, 2000, 1995}; |
| 48 | ARROW_RETURN_NOT_OK(int16builder.AppendValues(years_raw, 5)); |
| 49 | std::shared_ptr<arrow::Array> years; |
| 50 | ARROW_ASSIGN_OR_RAISE(years, int16builder.Finish()); |
| 51 | |
| 52 | // Get a vector of our Arrays |
| 53 | std::vector<std::shared_ptr<arrow::Array>> columns = {days, months, years}; |
| 54 | |
| 55 | // Make a schema to initialize the Table with |
| 56 | std::shared_ptr<arrow::Field> field_day, field_month, field_year; |
| 57 | std::shared_ptr<arrow::Schema> schema; |
| 58 | |
| 59 | field_day = arrow::field("Day", arrow::int8()); |
| 60 | field_month = arrow::field("Month", arrow::int8()); |
| 61 | field_year = arrow::field("Year", arrow::int16()); |
| 62 | |
| 63 | schema = arrow::schema({field_day, field_month, field_year}); |
| 64 | // With the schema and data, create a Table |
| 65 | std::shared_ptr<arrow::Table> table; |
| 66 | table = arrow::Table::Make(schema, columns); |
| 67 | |
| 68 | // Write out test files in IPC, CSV, and Parquet for the example to use. |
| 69 | std::shared_ptr<arrow::io::FileOutputStream> outfile; |
| 70 | ARROW_ASSIGN_OR_RAISE(outfile, arrow::io::FileOutputStream::Open("test_in.arrow")); |
| 71 | ARROW_ASSIGN_OR_RAISE(std::shared_ptr<arrow::ipc::RecordBatchWriter> ipc_writer, |
| 72 | arrow::ipc::MakeFileWriter(outfile, schema)); |
| 73 | ARROW_RETURN_NOT_OK(ipc_writer->WriteTable(*table)); |
| 74 | ARROW_RETURN_NOT_OK(ipc_writer->Close()); |
| 75 | |
| 76 | ARROW_ASSIGN_OR_RAISE(outfile, arrow::io::FileOutputStream::Open("test_in.csv")); |
| 77 | ARROW_ASSIGN_OR_RAISE(auto csv_writer, |
| 78 | arrow::csv::MakeCSVWriter(outfile, table->schema())); |
| 79 | ARROW_RETURN_NOT_OK(csv_writer->WriteTable(*table)); |
| 80 | ARROW_RETURN_NOT_OK(csv_writer->Close()); |
| 81 | |
| 82 | ARROW_ASSIGN_OR_RAISE(outfile, arrow::io::FileOutputStream::Open("test_in.parquet")); |
| 83 | PARQUET_THROW_NOT_OK( |
| 84 | parquet::arrow::WriteTable(*table, arrow::default_memory_pool(), outfile, 5)); |
| 85 | |
| 86 | return arrow::Status::OK(); |
| 87 | } |
| 88 | // (Doc section: GenInitialFile) |
| 89 |
no test coverage detected