MCPcopy Create free account
hub / github.com/bytedance/bolt / TEST_F

Function TEST_F

bolt/exec/tests/VectorHasherTest.cpp:176–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174};
175
176TEST_F(VectorHasherTest, flat) {
177 auto hasher = exec::VectorHasher::create(BIGINT(), 1);
178 ASSERT_EQ(hasher->channel(), 1);
179 ASSERT_EQ(hasher->typeKind(), TypeKind::BIGINT);
180
181 auto vector = BaseVector::create(BIGINT(), 100, pool());
182 auto flatVector = vector->asFlatVector<int64_t>();
183 for (int32_t i = 0; i < 100; i++) {
184 if (i % 5 == 0) {
185 flatVector->setNull(i, true);
186 } else {
187 flatVector->set(i, i);
188 }
189 }
190
191 raw_vector<uint64_t> hashes(100);
192 std::fill(hashes.begin(), hashes.end(), 0);
193 hasher->decode(*vector, oddRows_);
194 hasher->hash(oddRows_, false, hashes);
195 for (int32_t i = 0; i < 100; i++) {
196 if (i % 2 == 0) {
197 EXPECT_EQ(hashes[i], 0);
198 } else if (i % 5 == 0) {
199 EXPECT_EQ(hashes[i], exec::VectorHasher::kNullHash) << "at " << i;
200 } else {
201 EXPECT_EQ(hashes[i], folly::hasher<int64_t>()(i)) << "at " << i;
202 }
203 }
204
205 hasher->decode(*vector, allRows_);
206 hasher->hash(allRows_, false, hashes);
207 for (int32_t i = 0; i < 100; i++) {
208 if (i % 5 == 0) {
209 EXPECT_EQ(hashes[i], exec::VectorHasher::kNullHash) << "at " << i;
210 } else {
211 EXPECT_EQ(hashes[i], folly::hasher<int64_t>()(i)) << "at " << i;
212 }
213 }
214
215 // Test precompute methods for single null value.
216 hasher->precompute(*vector);
217 hasher->hashPrecomputed(allRows_, false, hashes);
218 for (int32_t i = 0; i < 100; i++) {
219 EXPECT_EQ(exec::VectorHasher::kNullHash, hashes[i]);
220 }
221
222 // Test precompute methods for single value '7'.
223 flatVector->set(0, 7);
224 hasher->precompute(*vector);
225 hasher->hashPrecomputed(allRows_, false, hashes);
226 auto expected = folly::hasher<int64_t>()(7);
227 for (int32_t i = 0; i < 100; i++) {
228 EXPECT_EQ(expected, hashes[i]);
229 }
230
231 // Test precompute methods for mixed value '7' with value '55'.
232 flatVector->set(0, 55);
233 hasher->precompute(*vector);

Callers

nothing calls this directly

Calls 15

hashMixFunction · 0.85
UNKNOWNFunction · 0.85
wrapInDictionaryFunction · 0.85
hashPrecomputedMethod · 0.80
setValidMethod · 0.80
updateBoundsMethod · 0.80
enableValueIdsMethod · 0.80
enableValueRangeMethod · 0.80
lookupValueIdsMethod · 0.80
countSelectedMethod · 0.80
setValidRangeMethod · 0.80
mayUseValueIdsMethod · 0.80

Tested by

no test coverage detected