From bcb03cdb0ebedff8ea18c4428a659850df5ea037 Mon Sep 17 00:00:00 2001 From: Orri Erling Date: Tue, 12 Dec 2023 07:51:59 -0800 Subject: [PATCH] Faster hash modes test (#7973) Summary: AggregationTest.hashmodes covers the required cases with less data in about half the time. Less timeouts. Checks that the end state is kHash. Pull Request resolved: https://github.com/facebookincubator/velox/pull/7973 Reviewed By: kevinwilfong Differential Revision: D52055200 Pulled By: oerling fbshipit-source-id: b1af9ff0e21ceb76d09f67560034bdc382420aff --- velox/exec/HashTable.cpp | 1 + velox/exec/tests/AggregationTest.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/velox/exec/HashTable.cpp b/velox/exec/HashTable.cpp index d58be2bb30f7..7bfcfecc6dfc 100644 --- a/velox/exec/HashTable.cpp +++ b/velox/exec/HashTable.cpp @@ -1231,6 +1231,7 @@ void HashTable::rehash(bool initNormalizedKeys) { template void HashTable::setHashMode(HashMode mode, int32_t numNew) { VELOX_CHECK_NE(hashMode_, HashMode::kHash); + TestValue::adjust("facebook::velox::exec::HashTable::setHashMode", &mode); if (mode == HashMode::kArray) { const auto bytes = capacity_ * tableSlotSize(); const auto numPages = memory::AllocationTraits::numPages(bytes); diff --git a/velox/exec/tests/AggregationTest.cpp b/velox/exec/tests/AggregationTest.cpp index 01d2c3b65eba..342f1967e133 100644 --- a/velox/exec/tests/AggregationTest.cpp +++ b/velox/exec/tests/AggregationTest.cpp @@ -697,10 +697,10 @@ TEST_F(AggregationTest, hashmodes) { makeModeTestKeys(rowType, 20000, 2, 2, 2, 4, 4, 4, batches); // 20K rows with all at slightly higher cardinality, still in array range. makeModeTestKeys(rowType, 20000, 2, 2, 2, 4, 16, 4, batches); - // 100K rows with cardinality outside of array range. We transit to + // 25K rows with cardinality outside of array range. We transit to // generic hash table from normalized keys when running out of quota // for distinct string storage for the sixth key. - makeModeTestKeys(rowType, 100000, 1000000, 2, 2, 4, 4, 1000000, batches); + makeModeTestKeys(rowType, 25000, 1000000, 2, 2, 4, 4, 1000000, batches); createDuckDbTable(batches); auto op = PlanBuilder() @@ -708,10 +708,17 @@ TEST_F(AggregationTest, hashmodes) { .singleAggregation({"c0", "c1", "c2", "c3", "c4", "c5"}, {"sum(1)"}) .planNode(); + std::atomic mode{BaseHashTable::HashMode::kArray}; + SCOPED_TESTVALUE_SET( + "facebook::velox::exec::HashTable::setHashMode", + std::function([&](void* newMode) { + mode = *reinterpret_cast(newMode); + })); assertQuery( op, "SELECT c0, c1, C2, C3, C4, C5, sum(1) FROM tmp " " GROUP BY c0, c1, c2, c3, c4, c5"); + EXPECT_EQ(mode, BaseHashTable::HashMode::kHash); } TEST_F(AggregationTest, rangeToDistinct) {