MCPcopy Create free account
hub / github.com/apache/arrow / RunSingle

Method RunSingle

cpp/src/arrow/compute/key_hash_test.cc:101–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99 public:
100 template <typename Type>
101 static void RunSingle(random::pcg32_fast* random, bool use_32bit_hash,
102 bool use_varlen_input, int min_length, int max_length) {
103 using ArrayType = typename TypeTraits<Type>::ArrayType;
104 using OffsetType = typename TypeTraits<Type>::OffsetType;
105 using offset_t = typename std::make_unsigned<typename OffsetType::c_type>::type;
106
107 constexpr int min_num_unique = 100;
108 constexpr int max_num_unique = 1000;
109 constexpr int min_num_rows = 4000;
110 constexpr int max_num_rows = 8000;
111
112 std::uniform_int_distribution<int> num_unique_gen(min_num_unique, max_num_unique);
113 std::uniform_int_distribution<int> num_rows_gen(min_num_rows, max_num_rows);
114
115 int num_unique = num_unique_gen(*random);
116 int num_rows = num_rows_gen(*random);
117
118 SCOPED_TRACE("num_bits = " + std::to_string(use_32bit_hash ? 32 : 64) +
119 " varlen = " + std::string(use_varlen_input ? "yes" : "no") +
120 " num_unique " + std::to_string(num_unique) + " num_rows " +
121 std::to_string(num_rows) + " min_length " + std::to_string(min_length) +
122 " max_length " + std::to_string(max_length));
123
124 // The hash can only support 2^(length_in_bits-1) unique values
125 if (max_length == 1) {
126 num_unique &= 0x7f;
127 }
128
129 std::uniform_int_distribution<int> fixed_length_gen(min_length, max_length);
130 int fixed_length = use_varlen_input ? 0 : std::max(2, fixed_length_gen(*random));
131 if (!use_varlen_input) {
132 min_length = max_length = fixed_length;
133 }
134
135 ASSERT_OK_AND_ASSIGN(
136 std::shared_ptr<ArrayType> uniques,
137 GenerateUniqueRandomBinary<Type>(random, num_unique, min_length, max_length));
138 ASSERT_OK_AND_ASSIGN(auto sampled,
139 SampleUniqueBinary<Type>(random, num_rows, *uniques));
140 const std::vector<int>& row_ids = sampled.first;
141 const std::shared_ptr<ArrayType>& keys_array = sampled.second;
142 const uint8_t* keys = keys_array->raw_data();
143 const offset_t* key_offsets =
144 reinterpret_cast<const offset_t*>(keys_array->raw_value_offsets());
145
146 // For each tested hardware flags, we will compute the hashes and check
147 // them for consistency.
148 const auto hardware_flags_for_testing = HardwareFlagsForTesting();
149 ASSERT_GT(hardware_flags_for_testing.size(), 0);
150 std::vector<std::vector<uint32_t>> hashes32(hardware_flags_for_testing.size());
151 std::vector<std::vector<uint64_t>> hashes64(hardware_flags_for_testing.size());
152 for (auto& h : hashes32) {
153 h.resize(num_rows);
154 }
155 for (auto& h : hashes64) {
156 h.resize(num_rows);
157 }
158

Callers

nothing calls this directly

Calls 9

to_stringFunction · 0.85
raw_dataMethod · 0.80
resizeMethod · 0.80
ASSERT_OK_AND_ASSIGNFunction · 0.70
HardwareFlagsForTestingFunction · 0.70
raw_value_offsetsMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected