| 153 | } |
| 154 | |
| 155 | Status DoMain(const std::string& out_dir) { |
| 156 | ARROW_ASSIGN_OR_RAISE(auto dir_fn, PlatformFilename::FromString(out_dir)); |
| 157 | RETURN_NOT_OK(CreateDir(dir_fn)); |
| 158 | |
| 159 | int sample_num = 1; |
| 160 | auto sample_name = [&]() -> std::string { |
| 161 | return "csv-file-" + std::to_string(sample_num++); |
| 162 | }; |
| 163 | |
| 164 | ARROW_ASSIGN_OR_RAISE(auto batches, Batches()); |
| 165 | |
| 166 | auto options = WriteOptions::Defaults(); |
| 167 | RETURN_NOT_OK(options.Validate()); |
| 168 | |
| 169 | for (const auto& batch : batches) { |
| 170 | RETURN_NOT_OK(batch->ValidateFull()); |
| 171 | ARROW_ASSIGN_OR_RAISE(auto buffer, WriteRecordBatch(batch, options)); |
| 172 | |
| 173 | ARROW_ASSIGN_OR_RAISE(auto sample_fn, dir_fn.Join(sample_name())); |
| 174 | std::cerr << sample_fn.ToString() << std::endl; |
| 175 | ARROW_ASSIGN_OR_RAISE(auto file, io::FileOutputStream::Open(sample_fn.ToString())); |
| 176 | RETURN_NOT_OK(file->Write(buffer)); |
| 177 | RETURN_NOT_OK(file->Close()); |
| 178 | } |
| 179 | return Status::OK(); |
| 180 | } |
| 181 | |
| 182 | ARROW_NORETURN void Usage() { |
| 183 | std::cerr << "Usage: arrow-csv-generate-fuzz-corpus " |