use of com.facebook.presto.RowPagesBuilder in project presto by prestodb.
the class TestNestedLoopJoinOperator method testEmptyBuildPage.
@Test
public void testEmptyBuildPage() throws Exception {
TaskContext taskContext = createTaskContext();
// build
List<Type> buildTypes = ImmutableList.of(VARCHAR);
RowPagesBuilder buildPages = rowPagesBuilder(buildTypes).pageBreak();
NestedLoopJoinPagesSupplier nestedLoopJoinPagesSupplier = buildPageSource(taskContext, buildPages);
// probe
List<Type> probeTypes = ImmutableList.of(VARCHAR);
RowPagesBuilder probePages = rowPagesBuilder(probeTypes);
List<Page> probeInput = probePages.row("A").row("B").pageBreak().build();
NestedLoopJoinOperatorFactory joinOperatorFactory = new NestedLoopJoinOperatorFactory(3, new PlanNodeId("test"), nestedLoopJoinPagesSupplier, ImmutableList.of(VARCHAR));
// expected
MaterializedResult expected = resultBuilder(taskContext.getSession(), concat(probeTypes, buildPages.getTypes())).build();
assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true).addDriverContext(), probeInput, expected);
}
use of com.facebook.presto.RowPagesBuilder in project presto by prestodb.
the class TestNestedLoopJoinOperator method testNestedLoopJoin.
@Test
public void testNestedLoopJoin() throws Exception {
TaskContext taskContext = createTaskContext();
// build
RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(VARCHAR, BIGINT, BIGINT)).addSequencePage(3, 20, 30, 40);
NestedLoopJoinPagesSupplier nestedLoopJoinPagesSupplier = buildPageSource(taskContext, buildPages);
// probe
RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(VARCHAR, BIGINT, BIGINT));
List<Page> probeInput = probePages.addSequencePage(2, 0, 1000, 2000).build();
NestedLoopJoinOperatorFactory joinOperatorFactory = new NestedLoopJoinOperatorFactory(3, new PlanNodeId("test"), nestedLoopJoinPagesSupplier, ImmutableList.of(VARCHAR, BIGINT, BIGINT));
// expected
MaterializedResult expected = resultBuilder(taskContext.getSession(), concat(probePages.getTypes(), buildPages.getTypes())).row("0", 1000L, 2000L, "20", 30L, 40L).row("0", 1000L, 2000L, "21", 31L, 41L).row("0", 1000L, 2000L, "22", 32L, 42L).row("1", 1001L, 2001L, "20", 30L, 40L).row("1", 1001L, 2001L, "21", 31L, 41L).row("1", 1001L, 2001L, "22", 32L, 42L).build();
assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true).addDriverContext(), probeInput, expected);
// Test probe pages has more rows
buildPages = rowPagesBuilder(ImmutableList.of(VARCHAR, BIGINT, BIGINT)).addSequencePage(2, 20, 30, 40);
nestedLoopJoinPagesSupplier = buildPageSource(taskContext, buildPages);
joinOperatorFactory = new NestedLoopJoinOperatorFactory(3, new PlanNodeId("test"), nestedLoopJoinPagesSupplier, ImmutableList.of(VARCHAR, BIGINT, BIGINT));
// probe
probePages = rowPagesBuilder(ImmutableList.of(VARCHAR, BIGINT, BIGINT));
probeInput = probePages.addSequencePage(3, 0, 1000, 2000).build();
// expected
expected = resultBuilder(taskContext.getSession(), concat(probePages.getTypes(), buildPages.getTypes())).row("0", 1000L, 2000L, "20", 30L, 40L).row("1", 1001L, 2001L, "20", 30L, 40L).row("2", 1002L, 2002L, "20", 30L, 40L).row("0", 1000L, 2000L, "21", 31L, 41L).row("1", 1001L, 2001L, "21", 31L, 41L).row("2", 1002L, 2002L, "21", 31L, 41L).build();
assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true).addDriverContext(), probeInput, expected);
}
use of com.facebook.presto.RowPagesBuilder in project presto by prestodb.
the class TestNestedLoopJoinOperator method testCrossJoinWithNullOnBothSides.
@Test
public void testCrossJoinWithNullOnBothSides() throws Exception {
TaskContext taskContext = createTaskContext();
// build
List<Type> buildTypes = ImmutableList.of(VARCHAR);
RowPagesBuilder buildPages = rowPagesBuilder(buildTypes).row("a").row((String) null).row("b").row("c").row((String) null);
NestedLoopJoinPagesSupplier nestedLoopJoinPagesSupplier = buildPageSource(taskContext, buildPages);
// probe
List<Type> probeTypes = ImmutableList.of(VARCHAR);
RowPagesBuilder probePages = rowPagesBuilder(probeTypes);
List<Page> probeInput = probePages.row("A").row("B").row((String) null).row("C").build();
NestedLoopJoinOperatorFactory joinOperatorFactory = new NestedLoopJoinOperatorFactory(3, new PlanNodeId("test"), nestedLoopJoinPagesSupplier, ImmutableList.of(VARCHAR));
// expected
MaterializedResult expected = resultBuilder(taskContext.getSession(), concat(probeTypes, buildPages.getTypes())).row("A", "a").row("A", null).row("A", "b").row("A", "c").row("A", null).row("B", "a").row("B", null).row("B", "b").row("B", "c").row("B", null).row(null, "a").row(null, null).row(null, "b").row(null, "c").row(null, null).row("C", "a").row("C", null).row("C", "b").row("C", "c").row("C", null).build();
assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true).addDriverContext(), probeInput, expected);
}
use of com.facebook.presto.RowPagesBuilder in project presto by prestodb.
the class TestNestedLoopJoinOperator method testBuildMultiplePages.
@Test
public void testBuildMultiplePages() throws Exception {
TaskContext taskContext = createTaskContext();
// build
List<Type> buildTypes = ImmutableList.of(VARCHAR);
RowPagesBuilder buildPages = rowPagesBuilder(buildTypes).row("a").pageBreak().row((String) null).row("b").row("c").pageBreak().row("d");
NestedLoopJoinPagesSupplier nestedLoopJoinPagesSupplier = buildPageSource(taskContext, buildPages);
// probe
List<Type> probeTypes = ImmutableList.of(VARCHAR);
RowPagesBuilder probePages = rowPagesBuilder(probeTypes);
List<Page> probeInput = probePages.row("A").row("B").build();
NestedLoopJoinOperatorFactory joinOperatorFactory = new NestedLoopJoinOperatorFactory(3, new PlanNodeId("test"), nestedLoopJoinPagesSupplier, ImmutableList.of(VARCHAR));
// expected
MaterializedResult expected = resultBuilder(taskContext.getSession(), concat(probeTypes, buildPages.getTypes())).row("A", "a").row("B", "a").row("A", null).row("A", "b").row("A", "c").row("B", null).row("B", "b").row("B", "c").row("A", "d").row("B", "d").build();
assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true).addDriverContext(), probeInput, expected);
}
use of com.facebook.presto.RowPagesBuilder in project presto by prestodb.
the class TestRowNumberOperator method testRowNumberPartitioned.
@Test(dataProvider = "hashEnabledValues")
public void testRowNumberPartitioned(boolean hashEnabled) throws Exception {
DriverContext driverContext = getDriverContext();
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), BIGINT, DOUBLE);
List<Page> input = rowPagesBuilder.row(1L, 0.3).row(2L, 0.2).row(3L, 0.1).row(3L, 0.19).pageBreak().row(1L, 0.4).pageBreak().row(1L, 0.5).row(1L, 0.6).row(2L, 0.7).row(2L, 0.8).row(2L, 0.9).build();
RowNumberOperator.RowNumberOperatorFactory operatorFactory = new RowNumberOperator.RowNumberOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT, DOUBLE), Ints.asList(1, 0), Ints.asList(0), ImmutableList.of(BIGINT), Optional.of(10), rowPagesBuilder.getHashChannel(), 10, joinCompiler);
MaterializedResult expectedPartition1 = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT).row(0.3, 1L).row(0.4, 1L).row(0.5, 1L).row(0.6, 1L).build();
MaterializedResult expectedPartition2 = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT).row(0.2, 2L).row(0.7, 2L).row(0.8, 2L).row(0.9, 2L).build();
MaterializedResult expectedPartition3 = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT).row(0.1, 3L).row(0.19, 3L).build();
List<Page> pages = toPages(operatorFactory, driverContext, input);
Block rowNumberColumn = getRowNumberColumn(pages);
assertEquals(rowNumberColumn.getPositionCount(), 10);
pages = stripRowNumberColumn(pages);
MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(DOUBLE, BIGINT), pages);
ImmutableSet<?> actualSet = ImmutableSet.copyOf(actual.getMaterializedRows());
ImmutableSet<?> expectedPartition1Set = ImmutableSet.copyOf(expectedPartition1.getMaterializedRows());
ImmutableSet<?> expectedPartition2Set = ImmutableSet.copyOf(expectedPartition2.getMaterializedRows());
ImmutableSet<?> expectedPartition3Set = ImmutableSet.copyOf(expectedPartition3.getMaterializedRows());
assertEquals(Sets.intersection(expectedPartition1Set, actualSet).size(), 4);
assertEquals(Sets.intersection(expectedPartition2Set, actualSet).size(), 4);
assertEquals(Sets.intersection(expectedPartition3Set, actualSet).size(), 2);
}
Aggregations