Search in sources :

Example 1 with XxHash64

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));
}
Also used : Page(com.facebook.presto.spi.Page) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) BigintOperators(com.facebook.presto.type.BigintOperators) DataProvider(org.testng.annotations.DataProvider) MaterializedResult.resultBuilder(com.facebook.presto.testing.MaterializedResult.resultBuilder) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) ImmutableList(com.google.common.collect.ImmutableList) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) ExecutorService(java.util.concurrent.ExecutorService) AfterClass(org.testng.annotations.AfterClass) TestingTaskContext.createTaskContext(com.facebook.presto.testing.TestingTaskContext.createTaskContext) BeforeClass(org.testng.annotations.BeforeClass) XxHash64(io.airlift.slice.XxHash64) Ints(com.google.common.primitives.Ints) MaterializedResult(com.facebook.presto.testing.MaterializedResult) List(java.util.List) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) RowPagesBuilder.rowPagesBuilder(com.facebook.presto.RowPagesBuilder.rowPagesBuilder) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) Page(com.facebook.presto.spi.Page) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 2 with XxHash64

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));
}
Also used : Page(com.facebook.presto.spi.Page) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) BigintOperators(com.facebook.presto.type.BigintOperators) DataProvider(org.testng.annotations.DataProvider) MaterializedResult.resultBuilder(com.facebook.presto.testing.MaterializedResult.resultBuilder) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) ImmutableList(com.google.common.collect.ImmutableList) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) ExecutorService(java.util.concurrent.ExecutorService) AfterClass(org.testng.annotations.AfterClass) TestingTaskContext.createTaskContext(com.facebook.presto.testing.TestingTaskContext.createTaskContext) BeforeClass(org.testng.annotations.BeforeClass) XxHash64(io.airlift.slice.XxHash64) Ints(com.google.common.primitives.Ints) MaterializedResult(com.facebook.presto.testing.MaterializedResult) List(java.util.List) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) RowPagesBuilder.rowPagesBuilder(com.facebook.presto.RowPagesBuilder.rowPagesBuilder) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) Page(com.facebook.presto.spi.Page) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) HashPartitionMaskOperatorFactory(com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

RowPagesBuilder (com.facebook.presto.RowPagesBuilder)2 RowPagesBuilder.rowPagesBuilder (com.facebook.presto.RowPagesBuilder.rowPagesBuilder)2 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)2 HashPartitionMaskOperatorFactory (com.facebook.presto.operator.HashPartitionMaskOperator.HashPartitionMaskOperatorFactory)2 Page (com.facebook.presto.spi.Page)2 BIGINT (com.facebook.presto.spi.type.BigintType.BIGINT)2 BOOLEAN (com.facebook.presto.spi.type.BooleanType.BOOLEAN)2 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)2 MaterializedResult (com.facebook.presto.testing.MaterializedResult)2 MaterializedResult.resultBuilder (com.facebook.presto.testing.MaterializedResult.resultBuilder)2 TestingTaskContext.createTaskContext (com.facebook.presto.testing.TestingTaskContext.createTaskContext)2 BigintOperators (com.facebook.presto.type.BigintOperators)2 ImmutableList (com.google.common.collect.ImmutableList)2 Ints (com.google.common.primitives.Ints)2 Threads.daemonThreadsNamed (io.airlift.concurrent.Threads.daemonThreadsNamed)2 XxHash64 (io.airlift.slice.XxHash64)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 ExecutorService (java.util.concurrent.ExecutorService)2