use of io.airlift.slice.XxHash64 in project presto by prestodb.
the class TestHashPartitionMaskOperator method testHashPartitionMaskWithMask.
@Test(dataProvider = "hashEnabledValues")
public void testHashPartitionMaskWithMask(boolean hashEnabled) throws Exception {
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), BIGINT, BOOLEAN, BOOLEAN);
List<Page> input = rowPagesBuilder.addSequencePage(ROW_COUNT, 0, 0, 1).build();
OperatorFactory operatorFactory = new HashPartitionMaskOperatorFactory(0, new PlanNodeId("test"), PARTITION_COUNT, rowPagesBuilder.getTypes(), ImmutableList.of(1, 2), ImmutableList.of(0), rowPagesBuilder.getHashChannel());
int[] rowPartition = new int[ROW_COUNT];
Arrays.fill(rowPartition, -1);
for (int partition = 0; partition < PARTITION_COUNT; partition++) {
MaterializedResult.Builder expected = resultBuilder(TEST_SESSION, BIGINT, BOOLEAN, BOOLEAN, BOOLEAN);
for (int i = 0; i < ROW_COUNT; i++) {
long rawHash = BigintOperators.hashCode(i);
// mix the bits so we don't use the same hash used to distribute between stages
rawHash = XxHash64.hash(Long.reverse(rawHash));
rawHash &= Long.MAX_VALUE;
boolean active = (rawHash % PARTITION_COUNT == partition);
boolean maskValue = i % 2 == 0;
expected.row((long) i, active && maskValue, active && !maskValue, active);
if (active) {
assertEquals(rowPartition[i], -1);
rowPartition[i] = partition;
}
}
OperatorAssertion.assertOperatorEqualsIgnoreOrder(operatorFactory, createDriverContext(), input, expected.build(), hashEnabled, Optional.of(3));
}
assertTrue(IntStream.of(rowPartition).noneMatch(partition -> partition == -1));
}
use of io.airlift.slice.XxHash64 in project presto by prestodb.
the class TestHashPartitionMaskOperator method testHashPartitionMask.
@Test(dataProvider = "hashEnabledValues")
public void testHashPartitionMask(boolean hashEnabled) throws Exception {
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), BIGINT);
List<Page> input = rowPagesBuilder.addSequencePage(ROW_COUNT, 0).build();
OperatorFactory operatorFactory = new HashPartitionMaskOperatorFactory(0, new PlanNodeId("test"), PARTITION_COUNT, rowPagesBuilder.getTypes(), ImmutableList.of(), ImmutableList.of(0), rowPagesBuilder.getHashChannel());
int[] rowPartition = new int[ROW_COUNT];
Arrays.fill(rowPartition, -1);
for (int partition = 0; partition < PARTITION_COUNT; partition++) {
MaterializedResult.Builder expected = resultBuilder(TEST_SESSION, BIGINT, BOOLEAN);
for (int i = 0; i < ROW_COUNT; i++) {
long rawHash = BigintOperators.hashCode(i);
// mix the bits so we don't use the same hash used to distribute between stages
rawHash = XxHash64.hash(Long.reverse(rawHash));
rawHash &= Long.MAX_VALUE;
boolean active = (rawHash % PARTITION_COUNT == partition);
expected.row((long) i, active);
if (active) {
assertEquals(rowPartition[i], -1);
rowPartition[i] = partition;
}
}
OperatorAssertion.assertOperatorEqualsIgnoreOrder(operatorFactory, createDriverContext(), input, expected.build(), hashEnabled, Optional.of(1));
}
assertTrue(IntStream.of(rowPartition).noneMatch(partition -> partition == -1));
}
Aggregations