Skip to content

Commit

Permalink
test hashtable
Browse files Browse the repository at this point in the history
Signed-off-by: Yuan Zhou <[email protected]>
  • Loading branch information
zhouyuan committed Feb 6, 2025
1 parent bd24879 commit 98e6689
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions velox/exec/tests/HashTableTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,14 @@ class HashTableTest : public testing::TestWithParam<bool>,
std::move(otherTables),
BaseHashTable::kNoSpillInputStartPartitionBit,
executor_.get());
topTable1_ = std::unique_ptr<HashTable<true>>(dynamic_cast<HashTable<true>*>(topTable_.release()));
ASSERT_GE(
estimatedTableSize,
topTable_->rows()->pool()->usedBytes() - usedMemoryBytes);
ASSERT_EQ(topTable_->hashMode(), mode);
ASSERT_EQ(topTable_->allRows().size(), numWays);
topTable1_->rows()->pool()->usedBytes() - usedMemoryBytes);
ASSERT_EQ(topTable1_->hashMode(), mode);
ASSERT_EQ(topTable1_->allRows().size(), numWays);
uint64_t rowCount{0};
for (auto* rowContainer : topTable_->allRows()) {
for (auto* rowContainer : topTable1_->allRows()) {
rowCount += rowContainer->numRows();
}
ASSERT_EQ(rowCount, numRows);
Expand All @@ -177,13 +178,13 @@ class HashTableTest : public testing::TestWithParam<bool>,
testProbe();
testEraseEveryN(4);
testProbe();
testGroupBySpill(size, buildType, numKeys);
//testGroupBySpill(size, buildType, numKeys);
const auto memoryUsage = pool()->usedBytes();
topTable_->clear(true);
for (const auto* rowContainer : topTable_->allRows()) {
topTable1_->clear(true);
for (const auto* rowContainer : topTable1_->allRows()) {
ASSERT_EQ(rowContainer->numRows(), 0);
}
ASSERT_EQ(topTable_->numDistinct(), 0);
ASSERT_EQ(topTable1_->numDistinct(), 0);
ASSERT_LT(pool()->usedBytes(), memoryUsage);
}

Expand Down Expand Up @@ -286,20 +287,20 @@ class HashTableTest : public testing::TestWithParam<bool>,

std::string describeTable() {
std::stringstream out;
auto mode = topTable_->hashMode();
auto mode = topTable1_->hashMode();
if (mode == BaseHashTable::HashMode::kHash) {
out << "Multipart key ";
} else {
out
<< (mode == BaseHashTable::HashMode::kArray ? "Array "
: "Normalized key ");
out << "(";
for (auto& hasher : topTable_->hashers()) {
for (auto& hasher : topTable1_->hashers()) {
out << (hasher->isRange() ? "range " : "valueIds ");
}
out << ") ";
}
out << topTable_->numDistinct() << " entries";
out << topTable1_->numDistinct() << " entries";
return out.str();
}

Expand Down Expand Up @@ -455,13 +456,13 @@ class HashTableTest : public testing::TestWithParam<bool>,
}

void testProbe() {
auto lookup = std::make_unique<HashLookup>(topTable_->hashers());
auto lookup = std::make_unique<HashLookup>(topTable1_->hashers());
const auto batchSize = batches_[0]->size();
SelectivityVector rows(batchSize);
const auto mode = topTable_->hashMode();
const auto mode = topTable1_->hashMode();
SelectivityInfo hashTime;
SelectivityInfo probeTime;
auto& hashers = topTable_->hashers();
auto& hashers = topTable1_->hashers();
VectorHasher::ScratchMemory scratchMemory;
for (auto batchIndex = 0; batchIndex < batches_.size(); ++batchIndex) {
const auto& batch = batches_[batchIndex];
Expand Down Expand Up @@ -502,7 +503,7 @@ class HashTableTest : public testing::TestWithParam<bool>,
} else {
{
SelectivityTimer timer(probeTime, 0);
topTable_->joinProbe(*lookup);
topTable1_->joinProbe(*lookup);
}
for (auto i = 0; i < lookup->rows.size(); ++i) {
const auto key = lookup->rows[i];
Expand All @@ -522,7 +523,7 @@ class HashTableTest : public testing::TestWithParam<bool>,
rowOfKey_[i] = nullptr;
}
}
topTable_->erase(folly::Range<char**>(toErase.data(), toErase.size()));
topTable1_->erase(folly::Range<char**>(toErase.data(), toErase.size()));
}

void testListNullKeyRows(
Expand Down Expand Up @@ -570,6 +571,7 @@ class HashTableTest : public testing::TestWithParam<bool>,
// inserted, otherwise pointer into the RowContainer.
std::vector<char*> rowOfKey_;
std::unique_ptr<HashTable<true>> topTable_;
std::unique_ptr<HashTable<true>> topTable1_;
// Percentage of keys inserted into the table. This is for measuring
// joins that miss the table part of the time. Used in initializing
// 'isInTable_'.
Expand Down

0 comments on commit 98e6689

Please sign in to comment.