| 119 | } |
| 120 | |
| 121 | Status DoMain(bool is_stream_format, const std::string& out_dir) { |
| 122 | ARROW_ASSIGN_OR_RAISE(auto dir_fn, PlatformFilename::FromString(out_dir)); |
| 123 | RETURN_NOT_OK(CreateDir(dir_fn)); |
| 124 | |
| 125 | int sample_num = 1; |
| 126 | auto sample_name = [&]() -> std::string { |
| 127 | return "batch-" + std::to_string(sample_num++); |
| 128 | }; |
| 129 | |
| 130 | // codec 0 is uncompressed |
| 131 | std::vector<std::shared_ptr<util::Codec>> codecs(3, nullptr); |
| 132 | ARROW_ASSIGN_OR_RAISE(codecs[1], util::Codec::Create(Compression::LZ4_FRAME)); |
| 133 | ARROW_ASSIGN_OR_RAISE(codecs[2], util::Codec::Create(Compression::ZSTD)); |
| 134 | |
| 135 | ARROW_ASSIGN_OR_RAISE(auto batches, Batches()); |
| 136 | |
| 137 | // Emit a separate file for each (batch, codec) pair |
| 138 | for (const auto& batch : batches) { |
| 139 | RETURN_NOT_OK(batch->ValidateFull()); |
| 140 | for (const auto& codec : codecs) { |
| 141 | IpcWriteOptions options = IpcWriteOptions::Defaults(); |
| 142 | options.codec = codec; |
| 143 | ARROW_ASSIGN_OR_RAISE(auto buf, |
| 144 | SerializeRecordBatch(batch, options, is_stream_format)); |
| 145 | ARROW_ASSIGN_OR_RAISE(auto sample_fn, dir_fn.Join(sample_name())); |
| 146 | std::cerr << sample_fn.ToString() << std::endl; |
| 147 | ARROW_ASSIGN_OR_RAISE(auto file, io::FileOutputStream::Open(sample_fn.ToString())); |
| 148 | RETURN_NOT_OK(file->Write(buf)); |
| 149 | RETURN_NOT_OK(file->Close()); |
| 150 | } |
| 151 | } |
| 152 | return Status::OK(); |
| 153 | } |
| 154 | |
| 155 | ARROW_NORETURN void Usage() { |
| 156 | std::cerr << "Usage: arrow-ipc-generate-fuzz-corpus " |
no test coverage detected