Search in sources :

Example 1 with TopNOperatorFactory

use of io.prestosql.operator.TopNOperator.TopNOperatorFactory in project hetu-core by openlookeng.

the class TestTopNOperator method testMultiFieldKeySnapshot.

@Test
public void testMultiFieldKeySnapshot() {
    List<Page> input = rowPagesBuilder(VARCHAR, BIGINT).row("a", 1L).row("b", 2L).pageBreak().row("f", 3L).row("a", 4L).pageBreak().row("d", 5L).row("d", 7L).row("e", 6L).build();
    OperatorFactory operatorFactory = topNOperatorFactory(ImmutableList.of(VARCHAR, BIGINT), 3, ImmutableList.of(0, 1), ImmutableList.of(DESC_NULLS_LAST, DESC_NULLS_LAST));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, BIGINT).row("f", 3L).row("e", 6L).row("d", 7L).build();
    assertOperatorEqualsWithSimpleStateComparison(operatorFactory, driverContext, input, expected, createExpectedMapping());
}
Also used : TopNOperatorFactory(io.prestosql.operator.TopNOperator.TopNOperatorFactory) Page(io.prestosql.spi.Page) MaterializedResult(io.prestosql.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 2 with TopNOperatorFactory

use of io.prestosql.operator.TopNOperator.TopNOperatorFactory in project hetu-core by openlookeng.

the class TestTopNOperator method testExceedMemoryLimit.

@Test
public void testExceedMemoryLimit() throws Exception {
    List<Page> input = rowPagesBuilder(BIGINT).row(1L).build();
    DriverContext smallDiverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION, new DataSize(1, BYTE)).addPipelineContext(0, true, true, false).addDriverContext();
    OperatorFactory operatorFactory = topNOperatorFactory(ImmutableList.of(BIGINT), 100, ImmutableList.of(0), ImmutableList.of(ASC_NULLS_LAST));
    try (Operator operator = operatorFactory.createOperator(smallDiverContext)) {
        operator.addInput(input.get(0));
        operator.getOutput();
        fail("must fail because of exceeding local memory limit");
    } catch (ExceededMemoryLimitException ignore) {
    // the exception could be ignored
    }
}
Also used : TopNOperatorFactory(io.prestosql.operator.TopNOperator.TopNOperatorFactory) DataSize(io.airlift.units.DataSize) Page(io.prestosql.spi.Page) ExceededMemoryLimitException(io.prestosql.ExceededMemoryLimitException) Test(org.testng.annotations.Test)

Example 3 with TopNOperatorFactory

use of io.prestosql.operator.TopNOperator.TopNOperatorFactory in project hetu-core by openlookeng.

the class TestTopNOperator method testSingleFieldKey.

@Test
public void testSingleFieldKey() {
    List<Page> input = rowPagesBuilder(BIGINT, DOUBLE).row(1L, 0.1).row(2L, 0.2).pageBreak().row(-1L, -0.1).row(4L, 0.4).pageBreak().row(5L, 0.5).row(4L, 0.41).row(6L, 0.6).pageBreak().build();
    OperatorFactory operatorFactory = topNOperatorFactory(ImmutableList.of(BIGINT, DOUBLE), 2, ImmutableList.of(0), ImmutableList.of(DESC_NULLS_LAST));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, DOUBLE).row(6L, 0.6).row(5L, 0.5).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : TopNOperatorFactory(io.prestosql.operator.TopNOperator.TopNOperatorFactory) Page(io.prestosql.spi.Page) MaterializedResult(io.prestosql.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 4 with TopNOperatorFactory

use of io.prestosql.operator.TopNOperator.TopNOperatorFactory in project hetu-core by openlookeng.

the class TestTopNOperator method testMultiFieldKey.

@Test
public void testMultiFieldKey() {
    List<Page> input = rowPagesBuilder(VARCHAR, BIGINT).row("a", 1L).row("b", 2L).pageBreak().row("f", 3L).row("a", 4L).pageBreak().row("d", 5L).row("d", 7L).row("e", 6L).build();
    OperatorFactory operatorFactory = topNOperatorFactory(ImmutableList.of(VARCHAR, BIGINT), 3, ImmutableList.of(0, 1), ImmutableList.of(DESC_NULLS_LAST, DESC_NULLS_LAST));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), VARCHAR, BIGINT).row("f", 3L).row("e", 6L).row("d", 7L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : TopNOperatorFactory(io.prestosql.operator.TopNOperator.TopNOperatorFactory) Page(io.prestosql.spi.Page) MaterializedResult(io.prestosql.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 5 with TopNOperatorFactory

use of io.prestosql.operator.TopNOperator.TopNOperatorFactory in project hetu-core by openlookeng.

the class TestTopNOperator method testReverseOrder.

@Test
public void testReverseOrder() {
    List<Page> input = rowPagesBuilder(BIGINT, DOUBLE).row(1L, 0.1).row(2L, 0.2).pageBreak().row(-1L, -0.1).row(4L, 0.4).pageBreak().row(5L, 0.5).row(4L, 0.41).row(6L, 0.6).pageBreak().build();
    OperatorFactory operatorFactory = topNOperatorFactory(ImmutableList.of(BIGINT, DOUBLE), 2, ImmutableList.of(0), ImmutableList.of(ASC_NULLS_LAST));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, DOUBLE).row(-1L, -0.1).row(1L, 0.1).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : TopNOperatorFactory(io.prestosql.operator.TopNOperator.TopNOperatorFactory) Page(io.prestosql.spi.Page) MaterializedResult(io.prestosql.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

TopNOperatorFactory (io.prestosql.operator.TopNOperator.TopNOperatorFactory)7 Test (org.testng.annotations.Test)6 Page (io.prestosql.spi.Page)5 MaterializedResult (io.prestosql.testing.MaterializedResult)4 DataSize (io.airlift.units.DataSize)1 ExceededMemoryLimitException (io.prestosql.ExceededMemoryLimitException)1 OperatorFactory (io.prestosql.operator.OperatorFactory)1 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)1 Type (io.prestosql.spi.type.Type)1