Search in sources :

Example 16 with WindowOperatorFactory

use of com.facebook.presto.operator.WindowOperator.WindowOperatorFactory in project presto by prestodb.

the class TestWindowOperator method testFirstValuePartition.

@Test
public void testFirstValuePartition() throws Exception {
    List<Page> input = rowPagesBuilder(VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR).row("b", "A1", 1L, true, "").row("a", "A2", 1L, false, "").row("a", "B1", 2L, true, "").pageBreak().row("b", "C1", 2L, false, "").row("a", "C2", 3L, true, "").row("c", "A3", 1L, true, "").build();
    WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR), Ints.asList(0, 1, 2, 3), FIRST_VALUE, Ints.asList(0), Ints.asList(2), ImmutableList.copyOf(new SortOrder[] { SortOrder.ASC_NULLS_LAST }));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR).row("a", "A2", 1L, false, "A2").row("a", "B1", 2L, true, "A2").row("a", "C2", 3L, true, "A2").row("b", "A1", 1L, true, "A1").row("b", "C1", 2L, false, "A1").row("c", "A3", 1L, true, "A3").build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : WindowOperatorFactory(com.facebook.presto.operator.WindowOperator.WindowOperatorFactory) SortOrder(com.facebook.presto.spi.block.SortOrder) Page(com.facebook.presto.spi.Page) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 17 with WindowOperatorFactory

use of com.facebook.presto.operator.WindowOperator.WindowOperatorFactory in project presto by prestodb.

the class TestWindowOperator method testRowNumberPartition.

@Test
public void testRowNumberPartition() throws Exception {
    List<Page> input = rowPagesBuilder(VARCHAR, BIGINT, DOUBLE, BOOLEAN).row("b", -1L, -0.1, true).row("a", 2L, 0.3, false).row("a", 4L, 0.2, true).pageBreak().row("b", 5L, 0.4, false).row("a", 6L, 0.1, true).build();
    WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(VARCHAR, BIGINT, DOUBLE, BOOLEAN), Ints.asList(0, 1, 2, 3), ROW_NUMBER, Ints.asList(0), Ints.asList(1), ImmutableList.copyOf(new SortOrder[] { SortOrder.ASC_NULLS_LAST }));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, BIGINT, DOUBLE, BOOLEAN, BIGINT).row("a", 2L, 0.3, false, 1L).row("a", 4L, 0.2, true, 2L).row("a", 6L, 0.1, true, 3L).row("b", -1L, -0.1, true, 1L).row("b", 5L, 0.4, false, 2L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : WindowOperatorFactory(com.facebook.presto.operator.WindowOperator.WindowOperatorFactory) SortOrder(com.facebook.presto.spi.block.SortOrder) Page(com.facebook.presto.spi.Page) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 18 with WindowOperatorFactory

use of com.facebook.presto.operator.WindowOperator.WindowOperatorFactory in project presto by prestodb.

the class TestWindowOperator method testNthValuePartition.

@Test
public void testNthValuePartition() throws Exception {
    List<Page> input = rowPagesBuilder(VARCHAR, VARCHAR, BIGINT, BIGINT, BOOLEAN, VARCHAR).row("b", "A1", 1L, 2L, true, "").row("a", "A2", 1L, 3L, false, "").row("a", "B1", 2L, 2L, true, "").pageBreak().row("b", "C1", 2L, 3L, false, "").row("a", "C2", 3L, 1L, true, "").row("c", "A3", 1L, null, true, "").build();
    WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(VARCHAR, VARCHAR, BIGINT, BIGINT, BOOLEAN, VARCHAR), Ints.asList(0, 1, 2, 4), NTH_VALUE, Ints.asList(0), Ints.asList(2), ImmutableList.copyOf(new SortOrder[] { SortOrder.ASC_NULLS_LAST }));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR).row("a", "A2", 1L, false, "C2").row("a", "B1", 2L, true, "B1").row("a", "C2", 3L, true, "A2").row("b", "A1", 1L, true, "C1").row("b", "C1", 2L, false, null).row("c", "A3", 1L, true, null).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : WindowOperatorFactory(com.facebook.presto.operator.WindowOperator.WindowOperatorFactory) SortOrder(com.facebook.presto.spi.block.SortOrder) Page(com.facebook.presto.spi.Page) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 19 with WindowOperatorFactory

use of com.facebook.presto.operator.WindowOperator.WindowOperatorFactory in project presto by prestodb.

the class TestWindowOperator method testMemoryLimit.

@Test(expectedExceptions = ExceededMemoryLimitException.class, expectedExceptionsMessageRegExp = "Query exceeded per-node user memory limit of 10B.*")
public void testMemoryLimit() {
    List<Page> input = rowPagesBuilder(BIGINT, DOUBLE).row(1L, 0.1).row(2L, 0.2).pageBreak().row(-1L, -0.1).row(4L, 0.4).build();
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION, new DataSize(10, Unit.BYTE)).addPipelineContext(0, true, true, false).addDriverContext();
    WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(BIGINT, DOUBLE), Ints.asList(1), ROW_NUMBER, Ints.asList(), Ints.asList(0), ImmutableList.copyOf(new SortOrder[] { SortOrder.ASC_NULLS_LAST }), false);
    toPages(operatorFactory, driverContext, input);
}
Also used : WindowOperatorFactory(com.facebook.presto.operator.WindowOperator.WindowOperatorFactory) DataSize(io.airlift.units.DataSize) SortOrder(com.facebook.presto.common.block.SortOrder) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 20 with WindowOperatorFactory

use of com.facebook.presto.operator.WindowOperator.WindowOperatorFactory in project presto by prestodb.

the class TestWindowOperator method testNthValuePartition.

@Test(dataProvider = "spillEnabled")
public void testNthValuePartition(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
    List<Page> input = rowPagesBuilder(VARCHAR, VARCHAR, BIGINT, BIGINT, BOOLEAN, VARCHAR).row("b", "A1", 1L, 2L, true, "").row("a", "A2", 1L, 3L, false, "").row("a", "B1", 2L, 2L, true, "").pageBreak().row("b", "C1", 2L, 3L, false, "").row("a", "C2", 3L, 1L, true, "").row("c", "A3", 1L, null, true, "").build();
    WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(VARCHAR, VARCHAR, BIGINT, BIGINT, BOOLEAN, VARCHAR), Ints.asList(0, 1, 2, 4), NTH_VALUE, Ints.asList(0), Ints.asList(2), ImmutableList.copyOf(new SortOrder[] { SortOrder.ASC_NULLS_LAST }), spillEnabled);
    DriverContext driverContext = createDriverContext(memoryLimit);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, VARCHAR, BIGINT, BOOLEAN, VARCHAR).row("a", "A2", 1L, false, "C2").row("a", "B1", 2L, true, "B1").row("a", "C2", 3L, true, "A2").row("b", "A1", 1L, true, "C1").row("b", "C1", 2L, false, null).row("c", "A3", 1L, true, null).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
Also used : WindowOperatorFactory(com.facebook.presto.operator.WindowOperator.WindowOperatorFactory) SortOrder(com.facebook.presto.common.block.SortOrder) Page(com.facebook.presto.common.Page) OperatorAssertion.toMaterializedResult(com.facebook.presto.operator.OperatorAssertion.toMaterializedResult) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

WindowOperatorFactory (com.facebook.presto.operator.WindowOperator.WindowOperatorFactory)28 Test (org.testng.annotations.Test)28 MaterializedResult (com.facebook.presto.testing.MaterializedResult)27 Page (com.facebook.presto.common.Page)16 OperatorAssertion.toMaterializedResult (com.facebook.presto.operator.OperatorAssertion.toMaterializedResult)15 Page (com.facebook.presto.spi.Page)12 SortOrder (com.facebook.presto.common.block.SortOrder)11 SortOrder (com.facebook.presto.spi.block.SortOrder)7 DataSize (io.airlift.units.DataSize)1