Search in sources :

Example 1 with OrderByOperatorFactory

use of io.trino.operator.OrderByOperator.OrderByOperatorFactory in project trino by trinodb.

the class TestOrderByOperator method testMultipleOutputPages.

@Test(dataProvider = "spillEnabled")
public void testMultipleOutputPages(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
    // make operator produce multiple pages during finish phase
    int numberOfRows = 80_000;
    List<Page> input = rowPagesBuilder(BIGINT, DOUBLE).addSequencePage(numberOfRows, 0, 0).build();
    OrderByOperatorFactory operatorFactory = new OrderByOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT, DOUBLE), ImmutableList.of(1), 10, ImmutableList.of(0), ImmutableList.of(DESC_NULLS_LAST), new PagesIndex.TestingFactory(false), spillEnabled, Optional.of(spillerFactory), new OrderingCompiler(typeOperators));
    DriverContext driverContext = createDriverContext(memoryLimit);
    MaterializedResult.Builder expectedBuilder = resultBuilder(driverContext.getSession(), DOUBLE);
    for (int i = 0; i < numberOfRows; ++i) {
        expectedBuilder.row((double) numberOfRows - i - 1);
    }
    MaterializedResult expected = expectedBuilder.build();
    List<Page> pages = toPages(operatorFactory, driverContext, input, revokeMemoryWhenAddingPages);
    assertGreaterThan(pages.size(), 1, "Expected more than one output page");
    MaterializedResult actual = toMaterializedResult(driverContext.getSession(), expected.getTypes(), pages);
    assertEquals(actual.getMaterializedRows(), expected.getMaterializedRows());
    assertTrue(spillEnabled == (spillerFactory.getSpillsCount() > 0), format("Spill state mismatch. Expected spill: %s, spill count: %s", spillEnabled, spillerFactory.getSpillsCount()));
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) OrderByOperatorFactory(io.trino.operator.OrderByOperator.OrderByOperatorFactory) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.trino.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Example 2 with OrderByOperatorFactory

use of io.trino.operator.OrderByOperator.OrderByOperatorFactory in project trino by trinodb.

the class TestOrderByOperator method testMemoryLimit.

@Test
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, DataSize.ofBytes(10)).addPipelineContext(0, true, true, false).addDriverContext();
    OrderByOperatorFactory operatorFactory = new OrderByOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT, DOUBLE), ImmutableList.of(1), 10, ImmutableList.of(0), ImmutableList.of(ASC_NULLS_LAST), new PagesIndex.TestingFactory(false), false, Optional.of(spillerFactory), new OrderingCompiler(typeOperators));
    assertThatThrownBy(() -> toPages(operatorFactory, driverContext, input)).isInstanceOf(ExceededMemoryLimitException.class).hasMessageMatching("Query exceeded per-node memory limit of 10B.*");
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) OrderByOperatorFactory(io.trino.operator.OrderByOperator.OrderByOperatorFactory) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) Page(io.trino.spi.Page) ExceededMemoryLimitException(io.trino.ExceededMemoryLimitException) Test(org.testng.annotations.Test)

Example 3 with OrderByOperatorFactory

use of io.trino.operator.OrderByOperator.OrderByOperatorFactory in project trino by trinodb.

the class TestOrderByOperator method testReverseOrder.

@Test(dataProvider = "spillEnabled")
public void testReverseOrder(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
    List<Page> input = rowPagesBuilder(BIGINT, DOUBLE).row(1L, 0.1).row(2L, 0.2).pageBreak().row(-1L, -0.1).row(4L, 0.4).build();
    OrderByOperatorFactory operatorFactory = new OrderByOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT, DOUBLE), ImmutableList.of(0), 10, ImmutableList.of(0), ImmutableList.of(DESC_NULLS_LAST), new PagesIndex.TestingFactory(false), spillEnabled, Optional.of(spillerFactory), new OrderingCompiler(typeOperators));
    DriverContext driverContext = createDriverContext(memoryLimit);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).row(4L).row(2L).row(1L).row(-1L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) OrderByOperatorFactory(io.trino.operator.OrderByOperator.OrderByOperatorFactory) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.trino.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Example 4 with OrderByOperatorFactory

use of io.trino.operator.OrderByOperator.OrderByOperatorFactory in project trino by trinodb.

the class TestOrderByOperator method testMultiFieldKey.

@Test(dataProvider = "spillEnabled")
public void testMultiFieldKey(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
    List<Page> input = rowPagesBuilder(VARCHAR, BIGINT).row("a", 1L).row("b", 2L).pageBreak().row("b", 3L).row("a", 4L).build();
    OrderByOperatorFactory operatorFactory = new OrderByOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(VARCHAR, BIGINT), ImmutableList.of(0, 1), 10, ImmutableList.of(0, 1), ImmutableList.of(ASC_NULLS_LAST, DESC_NULLS_LAST), new PagesIndex.TestingFactory(false), spillEnabled, Optional.of(spillerFactory), new OrderingCompiler(typeOperators));
    DriverContext driverContext = createDriverContext(memoryLimit);
    MaterializedResult expected = MaterializedResult.resultBuilder(driverContext.getSession(), VARCHAR, BIGINT).row("a", 4L).row("a", 1L).row("b", 3L).row("b", 2L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) OrderByOperatorFactory(io.trino.operator.OrderByOperator.OrderByOperatorFactory) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.trino.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Example 5 with OrderByOperatorFactory

use of io.trino.operator.OrderByOperator.OrderByOperatorFactory in project trino by trinodb.

the class TestOrderByOperator method testSingleFieldKey.

@Test(dataProvider = "spillEnabled")
public void testSingleFieldKey(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
    List<Page> input = rowPagesBuilder(BIGINT, DOUBLE).row(1L, 0.1).row(2L, 0.2).pageBreak().row(-1L, -0.1).row(4L, 0.4).build();
    OrderByOperatorFactory operatorFactory = new OrderByOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT, DOUBLE), ImmutableList.of(1), 10, ImmutableList.of(0), ImmutableList.of(ASC_NULLS_LAST), new PagesIndex.TestingFactory(false), spillEnabled, Optional.of(spillerFactory), new OrderingCompiler(typeOperators));
    DriverContext driverContext = createDriverContext(memoryLimit);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), DOUBLE).row(-0.1).row(0.1).row(0.2).row(0.4).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) OrderByOperatorFactory(io.trino.operator.OrderByOperator.OrderByOperatorFactory) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.trino.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Aggregations

OrderByOperatorFactory (io.trino.operator.OrderByOperator.OrderByOperatorFactory)6 OrderingCompiler (io.trino.sql.gen.OrderingCompiler)6 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)6 Page (io.trino.spi.Page)5 Test (org.testng.annotations.Test)5 OperatorAssertion.toMaterializedResult (io.trino.operator.OperatorAssertion.toMaterializedResult)4 MaterializedResult (io.trino.testing.MaterializedResult)4 ExceededMemoryLimitException (io.trino.ExceededMemoryLimitException)1 LimitOperatorFactory (io.trino.operator.LimitOperator.LimitOperatorFactory)1 OperatorFactory (io.trino.operator.OperatorFactory)1 PagesIndex (io.trino.operator.PagesIndex)1 Type (io.trino.spi.type.Type)1