| 35 | constexpr double true_and_unique_probability = 0.2; |
| 36 | |
| 37 | static ExecBatch MakeRandomExecBatch(const DataTypeVector& types, int64_t num_rows, |
| 38 | double null_probability, |
| 39 | int64_t alignment = kDefaultBufferAlignment, |
| 40 | MemoryPool* memory_pool = nullptr) { |
| 41 | random::RandomArrayGenerator rng(kSeed); |
| 42 | auto num_types = static_cast<int>(types.size()); |
| 43 | |
| 44 | // clang-format off |
| 45 | // For unique probability: |
| 46 | // The proportion of Unique determines the number of groups. |
| 47 | // 1. In most scenarios, unique has a small proportion and exists |
| 48 | // 2. In GroupBy/HashJoin are sometimes used for deduplication and |
| 49 | // in that use case the key is mostly unique |
| 50 | auto metadata = key_value_metadata( |
| 51 | { |
| 52 | "null_probability", |
| 53 | "true_probability", // for boolean type |
| 54 | "unique" // for string type |
| 55 | }, |
| 56 | { |
| 57 | internal::ToChars(null_probability), |
| 58 | internal::ToChars(true_and_unique_probability), |
| 59 | internal::ToChars(static_cast<int32_t>(num_rows * |
| 60 | true_and_unique_probability)) |
| 61 | }); |
| 62 | // clang-format on |
| 63 | |
| 64 | std::vector<Datum> values; |
| 65 | values.resize(num_types); |
| 66 | for (int i = 0; i < num_types; ++i) { |
| 67 | // The "unique" cardinality knob isn't honored for view types, so generate the |
| 68 | // plain equivalent and cast it (outside the timed loop) to match {utf8}. |
| 69 | const auto& type = types[i]; |
| 70 | const bool is_view = is_binary_view_like(*type); |
| 71 | std::shared_ptr<DataType> gen_type = type; |
| 72 | if (is_view) { |
| 73 | gen_type = type->id() == Type::STRING_VIEW ? utf8() : binary(); |
| 74 | } |
| 75 | auto field = ::arrow::field("", gen_type, metadata); |
| 76 | Datum value = rng.ArrayOf(*field, num_rows, alignment, memory_pool); |
| 77 | if (is_view) { |
| 78 | ASSIGN_OR_ABORT(value, compute::Cast(value, type)); |
| 79 | } |
| 80 | values[i] = std::move(value); |
| 81 | } |
| 82 | |
| 83 | return ExecBatch(std::move(values), num_rows); |
| 84 | } |
| 85 | |
| 86 | static void GrouperBenchmark(benchmark::State& state, const ExecSpan& span, |
| 87 | ExecContext* ctx = nullptr) { |
no test coverage detected