Search in sources :

Example 11 with SortOrder

use of io.trino.spi.connector.SortOrder in project trino by trinodb.

the class TestWindowOperator method testLeadPartition.

@Test(dataProvider = "spillEnabled")
public void testLeadPartition(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
    List<Page> input = rowPagesBuilder(VARCHAR, VARCHAR, BIGINT, BIGINT, VARCHAR, BOOLEAN, VARCHAR).row("b", "A1", 1L, 1L, "D", true, "").row("a", "A2", 1L, 2L, "D", false, "").row("a", "B1", 2L, 2L, "D", true, "").pageBreak().row("b", "C1", 2L, 1L, "D", false, "").row("a", "C2", 3L, 2L, "D", true, "").row("c", "A3", 1L, 1L, "D", true, "").build();
    WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(VARCHAR, VARCHAR, BIGINT, BIGINT, VARCHAR, BOOLEAN, VARCHAR), Ints.asList(0, 1, 2, 5), LEAD, 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, "D").row("a", "C2", 3L, true, "D").row("b", "A1", 1L, true, "C1").row("b", "C1", 2L, false, "D").row("c", "A3", 1L, true, "D").build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
Also used : WindowOperatorFactory(io.trino.operator.WindowOperator.WindowOperatorFactory) SortOrder(io.trino.spi.connector.SortOrder) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.trino.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Example 12 with SortOrder

use of io.trino.spi.connector.SortOrder in project trino by trinodb.

the class TestWindowOperator method testRowNumberArbitrary.

@Test
public void testRowNumberArbitrary() {
    List<Page> input = rowPagesBuilder(BIGINT).row(1L).row(3L).row(5L).row(7L).pageBreak().row(2L).row(4L).row(6L).row(8L).build();
    WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(BIGINT), Ints.asList(0), ROW_NUMBER, Ints.asList(), Ints.asList(), ImmutableList.copyOf(new SortOrder[] {}), false);
    DriverContext driverContext = createDriverContext();
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT).row(1L, 1L).row(3L, 2L).row(5L, 3L).row(7L, 4L).row(2L, 5L).row(4L, 6L).row(6L, 7L).row(8L, 8L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : WindowOperatorFactory(io.trino.operator.WindowOperator.WindowOperatorFactory) SortOrder(io.trino.spi.connector.SortOrder) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.trino.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Example 13 with SortOrder

use of io.trino.spi.connector.SortOrder in project trino by trinodb.

the class TestWindowOperator method testLagPartition.

@Test(dataProvider = "spillEnabled")
public void testLagPartition(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
    List<Page> input = rowPagesBuilder(VARCHAR, VARCHAR, BIGINT, BIGINT, VARCHAR, BOOLEAN, VARCHAR).row("b", "A1", 1L, 1L, "D", true, "").row("a", "A2", 1L, 2L, "D", false, "").row("a", "B1", 2L, 2L, "D", true, "").pageBreak().row("b", "C1", 2L, 1L, "D", false, "").row("a", "C2", 3L, 2L, "D", true, "").row("c", "A3", 1L, 1L, "D", true, "").build();
    WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(VARCHAR, VARCHAR, BIGINT, BIGINT, VARCHAR, BOOLEAN, VARCHAR), Ints.asList(0, 1, 2, 5), LAG, 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, "D").row("a", "B1", 2L, true, "D").row("a", "C2", 3L, true, "A2").row("b", "A1", 1L, true, "D").row("b", "C1", 2L, false, "A1").row("c", "A3", 1L, true, "D").build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
Also used : WindowOperatorFactory(io.trino.operator.WindowOperator.WindowOperatorFactory) SortOrder(io.trino.spi.connector.SortOrder) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.trino.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Example 14 with SortOrder

use of io.trino.spi.connector.SortOrder in project trino by trinodb.

the class TestWindowOperator method testMemoryLimit.

@Test(expectedExceptions = ExceededMemoryLimitException.class, expectedExceptionsMessageRegExp = "Query exceeded per-node 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, DataSize.ofBytes(10)).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(io.trino.operator.WindowOperator.WindowOperatorFactory) SortOrder(io.trino.spi.connector.SortOrder) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 15 with SortOrder

use of io.trino.spi.connector.SortOrder in project trino by trinodb.

the class TestWindowOperator method testRowNumber.

@Test(dataProvider = "spillEnabled")
public void testRowNumber(boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimit) {
    List<Page> input = rowPagesBuilder(BIGINT, DOUBLE).row(2L, 0.3).row(4L, 0.2).row(6L, 0.1).pageBreak().row(-1L, -0.1).row(5L, 0.4).build();
    WindowOperatorFactory operatorFactory = createFactoryUnbounded(ImmutableList.of(BIGINT, DOUBLE), Ints.asList(1, 0), ROW_NUMBER, Ints.asList(), Ints.asList(0), ImmutableList.copyOf(new SortOrder[] { SortOrder.ASC_NULLS_LAST }), spillEnabled);
    DriverContext driverContext = createDriverContext(memoryLimit);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT, BIGINT).row(-0.1, -1L, 1L).row(0.3, 2L, 2L).row(0.2, 4L, 3L).row(0.4, 5L, 4L).row(0.1, 6L, 5L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected, revokeMemoryWhenAddingPages);
}
Also used : WindowOperatorFactory(io.trino.operator.WindowOperator.WindowOperatorFactory) SortOrder(io.trino.spi.connector.SortOrder) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.trino.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Aggregations

SortOrder (io.trino.spi.connector.SortOrder)20 Page (io.trino.spi.Page)14 Test (org.testng.annotations.Test)13 WindowOperatorFactory (io.trino.operator.WindowOperator.WindowOperatorFactory)12 OperatorAssertion.toMaterializedResult (io.trino.operator.OperatorAssertion.toMaterializedResult)11 MaterializedResult (io.trino.testing.MaterializedResult)11 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 Type (io.trino.spi.type.Type)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)2 MethodDefinition (io.airlift.bytecode.MethodDefinition)2 Parameter (io.airlift.bytecode.Parameter)2 BytecodeExpression (io.airlift.bytecode.expression.BytecodeExpression)2 LabelNode (io.airlift.bytecode.instruction.LabelNode)2 SelectExpression (io.trino.sql.analyzer.Analysis.SelectExpression)2 OrderingScheme.sortItemToSortOrder (io.trino.sql.planner.OrderingScheme.sortItemToSortOrder)2 Symbol (io.trino.sql.planner.Symbol)2 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)2