This test inserts the build rows [0->5) to hash table. It validates that they are all there using a full table scan. It also validates that Find() is correct testing for probe rows that are both there and not. The hash table is resized a few times and the scans/finds are tested again.
| 330 | // testing for probe rows that are both there and not. |
| 331 | // The hash table is resized a few times and the scans/finds are tested again. |
| 332 | void BasicTest(bool quadratic, int initial_num_buckets) { |
| 333 | TupleRow* build_rows[5]; |
| 334 | TupleRow* scan_rows[5] = {0}; |
| 335 | for (int i = 0; i < 5; ++i) build_rows[i] = CreateTupleRow(i); |
| 336 | |
| 337 | ProbeTestData probe_rows[10]; |
| 338 | for (int i = 0; i < 10; ++i) { |
| 339 | probe_rows[i].probe_row = CreateTupleRow(i); |
| 340 | if (i < 5) probe_rows[i].expected_build_rows.push_back(build_rows[i]); |
| 341 | } |
| 342 | |
| 343 | // Create the hash table and insert the build rows |
| 344 | HashTable* hash_table; |
| 345 | ASSERT_TRUE(CreateHashTable(quadratic, initial_num_buckets, &hash_table)); |
| 346 | scoped_ptr<HashTableCtx> ht_ctx; |
| 347 | Status status = HashTableCtx::Create(&pool_, runtime_state_, build_exprs_, |
| 348 | probe_exprs_, false /* !stores_nulls_ */, |
| 349 | vector<bool>(build_exprs_.size(), false), 1, 0, 1, &mem_pool_, &mem_pool_, |
| 350 | &mem_pool_, &ht_ctx); |
| 351 | EXPECT_OK(status); |
| 352 | EXPECT_OK(ht_ctx->Open(runtime_state_)); |
| 353 | bool success; |
| 354 | EXPECT_OK(hash_table->CheckAndResize(5, ht_ctx.get(), &success)); |
| 355 | ASSERT_TRUE(success); |
| 356 | for (int i = 0; i < 5; ++i) { |
| 357 | if (!ht_ctx->EvalAndHashBuild(build_rows[i])) continue; |
| 358 | BufferedTupleStream::FlatRowPtr dummy_flat_row = nullptr; |
| 359 | EXPECT_TRUE(hash_table->stores_tuples_); |
| 360 | bool inserted = |
| 361 | hash_table->Insert(ht_ctx.get(), dummy_flat_row, build_rows[i], &status); |
| 362 | EXPECT_TRUE(inserted); |
| 363 | ASSERT_OK(status); |
| 364 | } |
| 365 | EXPECT_EQ(hash_table->size(), 5); |
| 366 | |
| 367 | // Do a full table scan and validate returned pointers |
| 368 | FullScan(hash_table, ht_ctx.get(), 0, 5, true, scan_rows, build_rows); |
| 369 | ProbeTest(hash_table, ht_ctx.get(), probe_rows, 10, false); |
| 370 | |
| 371 | // Double the size of the hash table and scan again. |
| 372 | EXPECT_OK(ResizeTable(hash_table, 2048, ht_ctx.get(), &success)); |
| 373 | EXPECT_TRUE(success); |
| 374 | EXPECT_EQ(hash_table->num_buckets(), 2048); |
| 375 | EXPECT_EQ(hash_table->size(), 5); |
| 376 | memset(scan_rows, 0, sizeof(scan_rows)); |
| 377 | FullScan(hash_table, ht_ctx.get(), 0, 5, true, scan_rows, build_rows); |
| 378 | ProbeTest(hash_table, ht_ctx.get(), probe_rows, 10, false); |
| 379 | |
| 380 | // Try to shrink and scan again. |
| 381 | EXPECT_OK(ResizeTable(hash_table, 64, ht_ctx.get(), &success)); |
| 382 | EXPECT_TRUE(success); |
| 383 | EXPECT_EQ(hash_table->num_buckets(), 64); |
| 384 | EXPECT_EQ(hash_table->size(), 5); |
| 385 | memset(scan_rows, 0, sizeof(scan_rows)); |
| 386 | FullScan(hash_table, ht_ctx.get(), 0, 5, true, scan_rows, build_rows); |
| 387 | ProbeTest(hash_table, ht_ctx.get(), probe_rows, 10, false); |
| 388 | |
| 389 | // Resize to 8, which is the smallest value to fit the number of filled buckets. |
nothing calls this directly
no test coverage detected