Search in sources :

Example 61 with PlanNodeId

use of com.facebook.presto.sql.planner.plan.PlanNodeId 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)

Example 62 with PlanNodeId

use of com.facebook.presto.sql.planner.plan.PlanNodeId in project presto by prestodb.

the class TestHashSemiJoinOperator method testProbeSideNulls.

//Disabled till #6622 is fixed
@Test(dataProvider = "hashEnabledValues", enabled = false)
public void testProbeSideNulls(boolean hashEnabled) throws Exception {
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true).addDriverContext();
    // build
    OperatorContext operatorContext = driverContext.addOperatorContext(0, new PlanNodeId("test"), ValuesOperator.class.getSimpleName());
    List<Type> buildTypes = ImmutableList.of(BIGINT);
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), buildTypes);
    Operator buildOperator = new ValuesOperator(operatorContext, buildTypes, rowPagesBuilder.row(0L).row(1L).row(3L).build());
    SetBuilderOperatorFactory setBuilderOperatorFactory = new SetBuilderOperatorFactory(1, new PlanNodeId("test"), buildOperator.getTypes().get(0), 0, rowPagesBuilder.getHashChannel(), 10, new JoinCompiler());
    Operator setBuilderOperator = setBuilderOperatorFactory.createOperator(driverContext);
    Driver driver = new Driver(driverContext, buildOperator, setBuilderOperator);
    while (!driver.isFinished()) {
        driver.process();
    }
    // probe
    List<Type> probeTypes = ImmutableList.of(BIGINT);
    RowPagesBuilder rowPagesBuilderProbe = rowPagesBuilder(hashEnabled, Ints.asList(0), probeTypes);
    List<Page> probeInput = rowPagesBuilderProbe.row(0L).row((Object) null).row(1L).row(2L).build();
    HashSemiJoinOperatorFactory joinOperatorFactory = new HashSemiJoinOperatorFactory(2, new PlanNodeId("test"), setBuilderOperatorFactory.getSetProvider(), rowPagesBuilderProbe.getTypes(), 0);
    // expected
    MaterializedResult expected = resultBuilder(driverContext.getSession(), concat(probeTypes, ImmutableList.of(BOOLEAN))).row(0L, true).row(null, null).row(1L, true).row(2L, false).build();
    OperatorAssertion.assertOperatorEquals(joinOperatorFactory, driverContext, probeInput, expected, hashEnabled, ImmutableList.of(probeTypes.size()));
}
Also used : JoinCompiler(com.facebook.presto.sql.gen.JoinCompiler) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) SetBuilderOperatorFactory(com.facebook.presto.operator.SetBuilderOperator.SetBuilderOperatorFactory) Page(com.facebook.presto.spi.Page) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) Type(com.facebook.presto.spi.type.Type) MaterializedResult(com.facebook.presto.testing.MaterializedResult) HashSemiJoinOperatorFactory(com.facebook.presto.operator.HashSemiJoinOperator.HashSemiJoinOperatorFactory) Test(org.testng.annotations.Test)

Example 63 with PlanNodeId

use of com.facebook.presto.sql.planner.plan.PlanNodeId in project presto by prestodb.

the class TestHashSemiJoinOperator method testMemoryLimit.

@Test(dataProvider = "hashEnabledValues", expectedExceptions = ExceededMemoryLimitException.class, expectedExceptionsMessageRegExp = "Query exceeded local memory limit of.*")
public void testMemoryLimit(boolean hashEnabled) throws Exception {
    DriverContext driverContext = createTaskContext(executor, TEST_SESSION, new DataSize(100, BYTE)).addPipelineContext(0, true, true).addDriverContext();
    OperatorContext operatorContext = driverContext.addOperatorContext(0, new PlanNodeId("test"), ValuesOperator.class.getSimpleName());
    List<Type> buildTypes = ImmutableList.of(BIGINT);
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), buildTypes);
    Operator buildOperator = new ValuesOperator(operatorContext, buildTypes, rowPagesBuilder.addSequencePage(10000, 20).build());
    SetBuilderOperatorFactory setBuilderOperatorFactory = new SetBuilderOperatorFactory(1, new PlanNodeId("test"), buildOperator.getTypes().get(0), 0, rowPagesBuilder.getHashChannel(), 10, new JoinCompiler());
    Operator setBuilderOperator = setBuilderOperatorFactory.createOperator(driverContext);
    Driver driver = new Driver(driverContext, buildOperator, setBuilderOperator);
    while (!driver.isFinished()) {
        driver.process();
    }
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) JoinCompiler(com.facebook.presto.sql.gen.JoinCompiler) Type(com.facebook.presto.spi.type.Type) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) DataSize(io.airlift.units.DataSize) SetBuilderOperatorFactory(com.facebook.presto.operator.SetBuilderOperator.SetBuilderOperatorFactory) Test(org.testng.annotations.Test)

Example 64 with PlanNodeId

use of com.facebook.presto.sql.planner.plan.PlanNodeId in project presto by prestodb.

the class TestHashSemiJoinOperator method testBuildSideNulls.

@Test(dataProvider = "hashEnabledValues")
public void testBuildSideNulls(boolean hashEnabled) throws Exception {
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true).addDriverContext();
    // build
    OperatorContext operatorContext = driverContext.addOperatorContext(0, new PlanNodeId("test"), ValuesOperator.class.getSimpleName());
    List<Type> buildTypes = ImmutableList.of(BIGINT);
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), buildTypes);
    Operator buildOperator = new ValuesOperator(operatorContext, buildTypes, rowPagesBuilder.row(0L).row(1L).row(2L).row(2L).row(3L).row((Object) null).build());
    SetBuilderOperatorFactory setBuilderOperatorFactory = new SetBuilderOperatorFactory(1, new PlanNodeId("test"), buildOperator.getTypes().get(0), 0, rowPagesBuilder.getHashChannel(), 10, new JoinCompiler());
    Operator setBuilderOperator = setBuilderOperatorFactory.createOperator(driverContext);
    Driver driver = new Driver(driverContext, buildOperator, setBuilderOperator);
    while (!driver.isFinished()) {
        driver.process();
    }
    // probe
    List<Type> probeTypes = ImmutableList.of(BIGINT);
    RowPagesBuilder rowPagesBuilderProbe = rowPagesBuilder(hashEnabled, Ints.asList(0), probeTypes);
    List<Page> probeInput = rowPagesBuilderProbe.addSequencePage(4, 1).build();
    HashSemiJoinOperatorFactory joinOperatorFactory = new HashSemiJoinOperatorFactory(2, new PlanNodeId("test"), setBuilderOperatorFactory.getSetProvider(), rowPagesBuilderProbe.getTypes(), 0);
    // expected
    MaterializedResult expected = resultBuilder(driverContext.getSession(), concat(probeTypes, ImmutableList.of(BOOLEAN))).row(1L, true).row(2L, true).row(3L, true).row(4L, null).build();
    OperatorAssertion.assertOperatorEquals(joinOperatorFactory, driverContext, probeInput, expected, hashEnabled, ImmutableList.of(probeTypes.size()));
}
Also used : JoinCompiler(com.facebook.presto.sql.gen.JoinCompiler) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) SetBuilderOperatorFactory(com.facebook.presto.operator.SetBuilderOperator.SetBuilderOperatorFactory) Page(com.facebook.presto.spi.Page) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) Type(com.facebook.presto.spi.type.Type) MaterializedResult(com.facebook.presto.testing.MaterializedResult) HashSemiJoinOperatorFactory(com.facebook.presto.operator.HashSemiJoinOperator.HashSemiJoinOperatorFactory) Test(org.testng.annotations.Test)

Example 65 with PlanNodeId

use of com.facebook.presto.sql.planner.plan.PlanNodeId in project presto by prestodb.

the class TestLimitOperator method testLimitWithBlockView.

@Test
public void testLimitWithBlockView() throws Exception {
    List<Page> input = rowPagesBuilder(BIGINT).addSequencePage(3, 1).addSequencePage(2, 4).addSequencePage(2, 6).build();
    OperatorFactory operatorFactory = new LimitOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT), 6);
    List<Page> expected = rowPagesBuilder(BIGINT).addSequencePage(3, 1).addSequencePage(2, 4).addSequencePage(1, 6).build();
    OperatorAssertion.assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) LimitOperatorFactory(com.facebook.presto.operator.LimitOperator.LimitOperatorFactory) LimitOperatorFactory(com.facebook.presto.operator.LimitOperator.LimitOperatorFactory) Page(com.facebook.presto.spi.Page) Test(org.testng.annotations.Test)

Aggregations

PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)118 Test (org.testng.annotations.Test)76 Page (com.facebook.presto.spi.Page)70 MaterializedResult (com.facebook.presto.testing.MaterializedResult)59 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)46 Type (com.facebook.presto.spi.type.Type)40 DataSize (io.airlift.units.DataSize)25 TestingTaskContext (com.facebook.presto.testing.TestingTaskContext)24 HashBuilderOperatorFactory (com.facebook.presto.operator.HashBuilderOperator.HashBuilderOperatorFactory)16 ValuesOperatorFactory (com.facebook.presto.operator.ValuesOperator.ValuesOperatorFactory)15 ImmutableList (com.google.common.collect.ImmutableList)15 LocalExchangeSinkOperatorFactory (com.facebook.presto.operator.exchange.LocalExchangeSinkOperator.LocalExchangeSinkOperatorFactory)13 LocalExchangeSourceOperatorFactory (com.facebook.presto.operator.exchange.LocalExchangeSourceOperator.LocalExchangeSourceOperatorFactory)13 HashAggregationOperatorFactory (com.facebook.presto.operator.HashAggregationOperator.HashAggregationOperatorFactory)11 List (java.util.List)11 Split (com.facebook.presto.metadata.Split)10 OperatorAssertion.toMaterializedResult (com.facebook.presto.operator.OperatorAssertion.toMaterializedResult)10 OperatorFactory (com.facebook.presto.operator.OperatorFactory)10 Block (com.facebook.presto.spi.block.Block)10 Optional (java.util.Optional)10