| 53 | } |
| 54 | |
| 55 | FieldVector GenerateTestFields(int num_fields, int mean_name_length) { |
| 56 | const std::shared_ptr<DataType> types[] = {boolean(), int64(), float64(), utf8()}; |
| 57 | |
| 58 | std::default_random_engine engine(kSeed); |
| 59 | |
| 60 | std::poisson_distribution<int> length_dist(mean_name_length); |
| 61 | std::uniform_int_distribution<uint16_t> char_dist(32, 126); |
| 62 | std::uniform_int_distribution<size_t> type_dist(0, std::size(types) - 1); |
| 63 | |
| 64 | std::unordered_set<std::string> names; |
| 65 | names.reserve(num_fields); |
| 66 | |
| 67 | while (static_cast<int>(names.size()) < num_fields) { |
| 68 | auto length = length_dist(engine); |
| 69 | if (!length) continue; |
| 70 | std::string name(length, '\0'); |
| 71 | for (auto& ch : name) ch = static_cast<char>(char_dist(engine)); |
| 72 | names.emplace(std::move(name)); |
| 73 | } |
| 74 | |
| 75 | FieldVector fields; |
| 76 | fields.reserve(num_fields); |
| 77 | for (const auto& name : names) { |
| 78 | fields.push_back(field(name, types[type_dist(engine)])); |
| 79 | } |
| 80 | |
| 81 | return fields; |
| 82 | } |
| 83 | |
| 84 | FieldVector TestFields() { return {field("int", int32()), field("str", utf8())}; } |
| 85 | |