| 42 | }; |
| 43 | |
| 44 | TEST_F(HashPartitionFunctionTest, function) { |
| 45 | const int numRows = 10'000; |
| 46 | auto vector = makeRowVector( |
| 47 | {makeFlatVector<int32_t>(numRows, [](auto row) { return row * 100 / 3; }), |
| 48 | makeFlatVector<int32_t>(numRows, [](auto row) { return row * 128; })}); |
| 49 | auto rowType = asRowType(vector->type()); |
| 50 | |
| 51 | // The test case the two hash partition functions having the same config. |
| 52 | { |
| 53 | std::vector<uint32_t> partitionsWithoutBits(numRows); |
| 54 | HashPartitionFunction functionWithoutBits(4, rowType, {0}); |
| 55 | functionWithoutBits.partition(*vector, partitionsWithoutBits); |
| 56 | EXPECT_EQ(4, functionWithoutBits.numPartitions()); |
| 57 | |
| 58 | std::vector<uint32_t> partitionsWithBits(numRows); |
| 59 | HashPartitionFunction functionWithBits(HashBitRange{0, 2}, rowType, {0}); |
| 60 | functionWithBits.partition(*vector, partitionsWithBits); |
| 61 | EXPECT_EQ(partitionsWithoutBits, partitionsWithBits); |
| 62 | EXPECT_EQ(4, functionWithBits.numPartitions()); |
| 63 | } |
| 64 | |
| 65 | // The test case the two hash partition functions with different configs. |
| 66 | { |
| 67 | std::vector<uint32_t> partitionsWithoutBits(numRows); |
| 68 | HashPartitionFunction functionWithoutBits(4, rowType, {0}); |
| 69 | functionWithoutBits.partition(*vector, partitionsWithoutBits); |
| 70 | EXPECT_EQ(4, functionWithoutBits.numPartitions()); |
| 71 | |
| 72 | std::vector<uint32_t> partitionsWithBits(numRows); |
| 73 | HashPartitionFunction functionWithBits(HashBitRange{0, 3}, rowType, {0}); |
| 74 | functionWithBits.partition(*vector, partitionsWithBits); |
| 75 | EXPECT_NE(partitionsWithoutBits, partitionsWithBits); |
| 76 | EXPECT_EQ(8, functionWithBits.numPartitions()); |
| 77 | } |
| 78 | |
| 79 | // The test case the two hash partition functions with different configs. |
| 80 | { |
| 81 | std::vector<uint32_t> partitionsWithoutBits(numRows); |
| 82 | HashPartitionFunction functionWithoutBits(4, rowType, {0}); |
| 83 | functionWithoutBits.partition(*vector, partitionsWithoutBits); |
| 84 | EXPECT_EQ(4, functionWithoutBits.numPartitions()); |
| 85 | |
| 86 | std::vector<uint32_t> partitionsWithBits(numRows); |
| 87 | HashPartitionFunction functionWithBits(HashBitRange{29, 31}, rowType, {0}); |
| 88 | functionWithBits.partition(*vector, partitionsWithBits); |
| 89 | EXPECT_NE(partitionsWithoutBits, partitionsWithBits); |
| 90 | EXPECT_EQ(4, functionWithBits.numPartitions()); |
| 91 | } |
| 92 | |
| 93 | // The test case the two hash partition functions with different configs. |
| 94 | { |
| 95 | std::vector<uint32_t> partitionsWithBits1(numRows); |
| 96 | HashPartitionFunction functionWithBits1(HashBitRange{40, 42}, rowType, {0}); |
| 97 | functionWithBits1.partition(*vector, partitionsWithBits1); |
| 98 | EXPECT_EQ(4, functionWithBits1.numPartitions()); |
| 99 | |
| 100 | std::vector<uint32_t> partitionsWithBits2(numRows); |
| 101 | HashPartitionFunction functionWithBits2(HashBitRange{29, 31}, rowType, {0}); |
nothing calls this directly
no test coverage detected