| 151 | } |
| 152 | |
| 153 | Status DoMain(const std::string& out_dir) { |
| 154 | ARROW_ASSIGN_OR_RAISE(auto dir_fn, internal::PlatformFilename::FromString(out_dir)); |
| 155 | RETURN_NOT_OK(internal::CreateDir(dir_fn)); |
| 156 | |
| 157 | int sample_num = 1; |
| 158 | auto sample_file_name = [&](const std::string& name = "") -> std::string { |
| 159 | std::stringstream ss; |
| 160 | if (!name.empty()) { |
| 161 | ss << name << "-"; |
| 162 | } |
| 163 | ss << sample_num++ << ".pq"; |
| 164 | return std::move(ss).str(); |
| 165 | }; |
| 166 | |
| 167 | auto write_sample = [&](Encoding::type source_encoding, |
| 168 | Encoding::type roundtrip_encoding, FullParquetType type, |
| 169 | const BufferVector& buffers) -> Status { |
| 170 | std::stringstream ss; |
| 171 | ss << type.ToString() << "-" << ::parquet::EncodingToString(source_encoding) << "-" |
| 172 | << ::parquet::EncodingToString(roundtrip_encoding); |
| 173 | ARROW_ASSIGN_OR_RAISE(auto sample_fn, dir_fn.Join(sample_file_name(ss.str()))); |
| 174 | std::cerr << sample_fn.ToString() << std::endl; |
| 175 | ARROW_ASSIGN_OR_RAISE(auto file, io::FileOutputStream::Open(sample_fn.ToString())); |
| 176 | for (const auto& buf : buffers) { |
| 177 | RETURN_NOT_OK(file->Write(buf)); |
| 178 | } |
| 179 | return file->Close(); |
| 180 | }; |
| 181 | |
| 182 | ARROW_ASSIGN_OR_RAISE(auto all_data, SampleData()); |
| 183 | for (const auto& data : all_data) { |
| 184 | const auto descr = parquet::fuzzing::internal::MakeColumnDescriptor( |
| 185 | data.pq_type.type, data.pq_type.type_length); |
| 186 | for (const auto roundtrip_encoding : data.encodings) { |
| 187 | // We always add PLAIN as a source encoding because the fuzzer might be able |
| 188 | // to explore more search space using this encoding. |
| 189 | for (const auto source_encoding : std::set{Encoding::PLAIN, roundtrip_encoding}) { |
| 190 | BufferVector buffers; |
| 191 | FuzzEncodingHeader header( |
| 192 | source_encoding, roundtrip_encoding, &descr, /*num_values=*/ |
| 193 | static_cast<int>(data.values->length() - data.values->null_count())); |
| 194 | |
| 195 | buffers.push_back(Buffer::FromString(header.Serialize())); |
| 196 | BEGIN_PARQUET_CATCH_EXCEPTIONS |
| 197 | auto encoder = ::parquet::MakeEncoder(data.pq_type.type, source_encoding, |
| 198 | /*use_dictionary=*/false, &descr); |
| 199 | encoder->Put(*data.values); |
| 200 | buffers.push_back(encoder->FlushValues()); |
| 201 | END_PARQUET_CATCH_EXCEPTIONS |
| 202 | RETURN_NOT_OK( |
| 203 | write_sample(source_encoding, roundtrip_encoding, data.pq_type, buffers)); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | // Special-case INT96 as there is no direct Arrow equivalent to encode. |
| 209 | ARROW_ASSIGN_OR_RAISE(auto int96_data, SampleInt96()); |
| 210 | for (const auto& data : int96_data) { |
no test coverage detected