| 399 | } |
| 400 | |
| 401 | void ScanTest( |
| 402 | bool quadratic, int initial_size, int rows_to_insert, int additional_rows) { |
| 403 | HashTable* hash_table; |
| 404 | ASSERT_TRUE(CreateHashTable(quadratic, initial_size, &hash_table)); |
| 405 | |
| 406 | int total_rows = rows_to_insert + additional_rows; |
| 407 | scoped_ptr<HashTableCtx> ht_ctx; |
| 408 | Status status = HashTableCtx::Create(&pool_, runtime_state_, build_exprs_, |
| 409 | probe_exprs_, false /* !stores_nulls_ */, |
| 410 | vector<bool>(build_exprs_.size(), false), 1, 0, 1, &mem_pool_, &mem_pool_, |
| 411 | &mem_pool_, &ht_ctx); |
| 412 | EXPECT_OK(status); |
| 413 | EXPECT_OK(ht_ctx->Open(runtime_state_)); |
| 414 | |
| 415 | // Add 1 row with val 1, 2 with val 2, etc. |
| 416 | bool success; |
| 417 | vector<TupleRow*> build_rows; |
| 418 | ProbeTestData* probe_rows = new ProbeTestData[total_rows]; |
| 419 | probe_rows[0].probe_row = CreateTupleRow(0); |
| 420 | for (int val = 1; val <= rows_to_insert; ++val) { |
| 421 | EXPECT_OK(hash_table->CheckAndResize(val, ht_ctx.get(), &success)); |
| 422 | EXPECT_TRUE(success) << " failed to resize: " << val; |
| 423 | probe_rows[val].probe_row = CreateTupleRow(val); |
| 424 | for (int i = 0; i < val; ++i) { |
| 425 | TupleRow* row = CreateTupleRow(val); |
| 426 | if (!ht_ctx->EvalAndHashBuild(row)) continue; |
| 427 | BufferedTupleStream::FlatRowPtr dummy_flat_row = nullptr; |
| 428 | EXPECT_TRUE(hash_table->stores_tuples_); |
| 429 | ASSERT_TRUE(hash_table->Insert(ht_ctx.get(), dummy_flat_row, row, &status)); |
| 430 | ASSERT_OK(status); |
| 431 | build_rows.push_back(row); |
| 432 | probe_rows[val].expected_build_rows.push_back(row); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | // Add some more probe rows that aren't there. |
| 437 | for (int val = rows_to_insert; val < rows_to_insert + additional_rows; ++val) { |
| 438 | probe_rows[val].probe_row = CreateTupleRow(val); |
| 439 | } |
| 440 | |
| 441 | // Test that all the builds were found. |
| 442 | ProbeTest(hash_table, ht_ctx.get(), probe_rows, total_rows, true); |
| 443 | |
| 444 | // Resize and try again. |
| 445 | int target_size = BitUtil::RoundUpToPowerOfTwo(2 * total_rows); |
| 446 | EXPECT_OK(ResizeTable(hash_table, target_size, ht_ctx.get(), &success)); |
| 447 | EXPECT_TRUE(success); |
| 448 | EXPECT_EQ(hash_table->num_buckets(), target_size); |
| 449 | ProbeTest(hash_table, ht_ctx.get(), probe_rows, total_rows, true); |
| 450 | |
| 451 | target_size = BitUtil::RoundUpToPowerOfTwo(total_rows + 1); |
| 452 | EXPECT_OK(ResizeTable(hash_table, target_size, ht_ctx.get(), &success)); |
| 453 | EXPECT_TRUE(success); |
| 454 | EXPECT_EQ(hash_table->num_buckets(), target_size); |
| 455 | ProbeTest(hash_table, ht_ctx.get(), probe_rows, total_rows, true); |
| 456 | |
| 457 | delete [] probe_rows; |
| 458 | ht_ctx->Close(runtime_state_); |
nothing calls this directly
no test coverage detected