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

Function HashFixedLengthFrom

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

Source from the content-addressed store, hash-verified

257TEST(VectorHash, BasicLargeString) { RunTestVectorHash<LargeStringType>(); }
258
259void HashFixedLengthFrom(int key_length, int num_rows, int start_row) {
260 int num_rows_to_hash = num_rows - start_row;
261 auto num_bytes_aligned = arrow::bit_util::RoundUpToMultipleOf64(key_length * num_rows);
262
263 const auto hardware_flags_for_testing = HardwareFlagsForTesting();
264 ASSERT_GT(hardware_flags_for_testing.size(), 0);
265
266 std::vector<std::vector<uint32_t>> hashes32(hardware_flags_for_testing.size());
267 std::vector<std::vector<uint64_t>> hashes64(hardware_flags_for_testing.size());
268 for (auto& h : hashes32) {
269 h.resize(num_rows_to_hash);
270 }
271 for (auto& h : hashes64) {
272 h.resize(num_rows_to_hash);
273 }
274
275 FixedSizeBinaryBuilder keys_builder(fixed_size_binary(key_length));
276 for (int j = 0; j < num_rows; ++j) {
277 ASSERT_OK(keys_builder.Append(std::string(key_length, 42)));
278 }
279 ASSERT_OK_AND_ASSIGN(auto keys, keys_builder.Finish());
280 // Make sure the buffer is aligned as expected.
281 ASSERT_EQ(keys->data()->buffers[1]->capacity(), num_bytes_aligned);
282
283 constexpr int mini_batch_size = 1024;
284 std::vector<uint32_t> temp_buffer;
285 temp_buffer.resize(mini_batch_size * 4);
286
287 for (size_t i = 0; i < hardware_flags_for_testing.size(); ++i) {
288 const auto hardware_flags = hardware_flags_for_testing[i];
289 Hashing32::HashFixed(hardware_flags,
290 /*combine_hashes=*/false, num_rows_to_hash, key_length,
291 keys->data()->GetValues<uint8_t>(1) + start_row * key_length,
292 hashes32[i].data(), temp_buffer.data());
293 Hashing64::HashFixed(
294 /*combine_hashes=*/false, num_rows_to_hash, key_length,
295 keys->data()->GetValues<uint8_t>(1) + start_row * key_length, hashes64[i].data());
296 }
297
298 // Verify that all implementations (scalar, SIMD) give the same hashes.
299 for (size_t i = 1; i < hardware_flags_for_testing.size(); ++i) {
300 for (int j = 0; j < num_rows_to_hash; ++j) {
301 ASSERT_EQ(hashes32[i][j], hashes32[0][j])
302 << "scalar and simd approaches yielded different 32-bit hashes";
303 ASSERT_EQ(hashes64[i][j], hashes64[0][j])
304 << "scalar and simd approaches yielded different 64-bit hashes";
305 }
306 }
307}
308
309// Some carefully chosen cases that may cause troubles like GH-39778.
310TEST(VectorHash, FixedLengthTailByteSafety) {

Callers 1

TESTFunction · 0.85

Calls 8

RoundUpToMultipleOf64Function · 0.85
fixed_size_binaryFunction · 0.85
resizeMethod · 0.80
HardwareFlagsForTestingFunction · 0.70
sizeMethod · 0.45
AppendMethod · 0.45
capacityMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected