Search in sources :

Example 86 with Page

use of io.trino.spi.Page in project trino by trinodb.

the class TestHttpPageBufferClient method testMemoryExceededInAddPages.

@Test
public void testMemoryExceededInAddPages() throws Exception {
    URI location = URI.create("http://localhost:8080");
    Page page = new Page(RunLengthEncodedBlock.create(BIGINT, 1L, 100));
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(DataSize.of(10, MEGABYTE));
    CyclicBarrier requestComplete = new CyclicBarrier(2);
    TrinoException expectedException = new TrinoException(EXCEEDED_LOCAL_MEMORY_LIMIT, "Memory limit exceeded");
    AtomicBoolean addPagesCalled = new AtomicBoolean(false);
    TestingClientCallback callback = new TestingClientCallback(requestComplete) {

        @Override
        public boolean addPages(HttpPageBufferClient client, List<Slice> pages) {
            addPagesCalled.set(true);
            throw expectedException;
        }
    };
    HttpPageBufferClient client = new HttpPageBufferClient("localhost", new TestingHttpClient(processor, scheduler), DataIntegrityVerification.ABORT, DataSize.of(10, MEGABYTE), new Duration(30, TimeUnit.SECONDS), true, TASK_ID, location, callback, scheduler, pageBufferClientCallbackExecutor);
    // attempt to fetch a page
    processor.addPage(location, page);
    callback.resetStats();
    client.scheduleRequest();
    requestComplete.await(10, TimeUnit.SECONDS);
    // addPages was called
    assertTrue(addPagesCalled.get());
    // Memory exceeded failure is reported
    assertEquals(callback.getCompletedRequests(), 1);
    assertEquals(callback.getFinishedBuffers(), 0);
    assertEquals(callback.getFailedBuffers(), 1);
    assertEquals(callback.getFailure(), expectedException);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) TrinoException(io.trino.spi.TrinoException) Page(io.trino.spi.Page) List(java.util.List) ArrayList(java.util.ArrayList) Duration(io.airlift.units.Duration) URI(java.net.URI) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.testng.annotations.Test)

Example 87 with Page

use of io.trino.spi.Page in project trino by trinodb.

the class TestHttpPageBufferClient method testHappyPath.

@Test
public void testHappyPath() throws Exception {
    Page expectedPage = new Page(100);
    DataSize expectedMaxSize = DataSize.of(11, Unit.MEGABYTE);
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(expectedMaxSize);
    CyclicBarrier requestComplete = new CyclicBarrier(2);
    TestingClientCallback callback = new TestingClientCallback(requestComplete);
    URI location = URI.create("http://localhost:8080");
    HttpPageBufferClient client = new HttpPageBufferClient("localhost", new TestingHttpClient(processor, scheduler), DataIntegrityVerification.ABORT, expectedMaxSize, new Duration(1, TimeUnit.MINUTES), true, TASK_ID, location, callback, scheduler, pageBufferClientCallbackExecutor);
    assertStatus(client, location, "queued", 0, 0, 0, 0, "not scheduled");
    // fetch a page and verify
    processor.addPage(location, expectedPage);
    callback.resetStats();
    client.scheduleRequest();
    requestComplete.await(10, TimeUnit.SECONDS);
    assertEquals(callback.getPages().size(), 1);
    assertPageEquals(expectedPage, callback.getPages().get(0));
    assertEquals(callback.getCompletedRequests(), 1);
    assertEquals(callback.getFinishedBuffers(), 0);
    assertStatus(client, location, "queued", 1, 1, 1, 0, "not scheduled");
    // fetch no data and verify
    callback.resetStats();
    client.scheduleRequest();
    requestComplete.await(10, TimeUnit.SECONDS);
    assertEquals(callback.getPages().size(), 0);
    assertEquals(callback.getCompletedRequests(), 1);
    assertEquals(callback.getFinishedBuffers(), 0);
    assertStatus(client, location, "queued", 1, 2, 2, 0, "not scheduled");
    // fetch two more pages and verify
    processor.addPage(location, expectedPage);
    processor.addPage(location, expectedPage);
    callback.resetStats();
    client.scheduleRequest();
    requestComplete.await(10, TimeUnit.SECONDS);
    assertEquals(callback.getPages().size(), 2);
    assertPageEquals(expectedPage, callback.getPages().get(0));
    assertPageEquals(expectedPage, callback.getPages().get(1));
    assertEquals(callback.getCompletedRequests(), 1);
    assertEquals(callback.getFinishedBuffers(), 0);
    assertEquals(callback.getFailedBuffers(), 0);
    callback.resetStats();
    assertStatus(client, location, "queued", 3, 3, 3, 0, "not scheduled");
    // finish and verify
    callback.resetStats();
    processor.setComplete(location);
    client.scheduleRequest();
    requestComplete.await(10, TimeUnit.SECONDS);
    // get the buffer complete signal
    assertEquals(callback.getPages().size(), 0);
    assertEquals(callback.getCompletedRequests(), 1);
    // schedule the delete call to the buffer
    callback.resetStats();
    client.scheduleRequest();
    requestComplete.await(10, TimeUnit.SECONDS);
    assertEquals(callback.getFinishedBuffers(), 1);
    assertEquals(callback.getPages().size(), 0);
    assertEquals(callback.getCompletedRequests(), 0);
    assertEquals(callback.getFailedBuffers(), 0);
    assertStatus(client, location, "closed", 3, 5, 5, 0, "not scheduled");
}
Also used : DataSize(io.airlift.units.DataSize) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Page(io.trino.spi.Page) Duration(io.airlift.units.Duration) URI(java.net.URI) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.testng.annotations.Test)

Example 88 with Page

use of io.trino.spi.Page in project trino by trinodb.

the class TestLimitOperator method testLimitWithBlockView.

@Test
public void testLimitWithBlockView() {
    List<Page> input = rowPagesBuilder(BIGINT).addSequencePage(3, 1).addSequencePage(2, 4).addSequencePage(2, 6).build();
    OperatorFactory operatorFactory = new LimitOperatorFactory(0, new PlanNodeId("test"), 6);
    List<Page> expected = rowPagesBuilder(BIGINT).addSequencePage(3, 1).addSequencePage(2, 4).addSequencePage(1, 6).build();
    OperatorAssertion.assertOperatorEquals(operatorFactory, ImmutableList.of(BIGINT), driverContext, input, expected);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) LimitOperatorFactory(io.trino.operator.LimitOperator.LimitOperatorFactory) LimitOperatorFactory(io.trino.operator.LimitOperator.LimitOperatorFactory) Page(io.trino.spi.Page) SequencePageBuilder.createSequencePage(io.trino.SequencePageBuilder.createSequencePage) Test(org.testng.annotations.Test)

Example 89 with Page

use of io.trino.spi.Page in project trino by trinodb.

the class TestLimitOperator method testLimitWithPageAlignment.

@Test
public void testLimitWithPageAlignment() {
    List<Page> input = rowPagesBuilder(BIGINT).addSequencePage(3, 1).addSequencePage(2, 4).addSequencePage(2, 6).build();
    OperatorFactory operatorFactory = new LimitOperatorFactory(0, new PlanNodeId("test"), 5);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).page(createSequencePage(ImmutableList.of(BIGINT), 3, 1)).page(createSequencePage(ImmutableList.of(BIGINT), 2, 4)).build();
    OperatorAssertion.assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) LimitOperatorFactory(io.trino.operator.LimitOperator.LimitOperatorFactory) LimitOperatorFactory(io.trino.operator.LimitOperator.LimitOperatorFactory) Page(io.trino.spi.Page) SequencePageBuilder.createSequencePage(io.trino.SequencePageBuilder.createSequencePage) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 90 with Page

use of io.trino.spi.Page in project trino by trinodb.

the class TestMarkDistinctOperator method testMemoryReservationYield.

@Test(dataProvider = "dataType")
public void testMemoryReservationYield(Type type) {
    List<Page> input = createPagesWithDistinctHashKeys(type, 6_000, 600);
    OperatorFactory operatorFactory = new MarkDistinctOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(type), ImmutableList.of(0), Optional.of(1), joinCompiler, blockTypeOperators);
    // get result with yield; pick a relatively small buffer for partitionRowCount's memory usage
    GroupByHashYieldAssertion.GroupByHashYieldResult result = finishOperatorWithYieldingGroupByHash(input, type, operatorFactory, operator -> ((MarkDistinctOperator) operator).getCapacity(), 1_400_000);
    assertGreaterThan(result.getYieldCount(), 5);
    assertGreaterThan(result.getMaxReservedBytes(), 20L << 20);
    int count = 0;
    for (Page page : result.getOutput()) {
        assertEquals(page.getChannelCount(), 3);
        for (int i = 0; i < page.getPositionCount(); i++) {
            assertEquals(page.getBlock(2).getByte(i, 0), 1);
            count++;
        }
    }
    assertEquals(count, 6_000 * 600);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) MarkDistinctOperatorFactory(io.trino.operator.MarkDistinctOperator.MarkDistinctOperatorFactory) MarkDistinctOperatorFactory(io.trino.operator.MarkDistinctOperator.MarkDistinctOperatorFactory) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Aggregations

Page (io.trino.spi.Page)579 Test (org.testng.annotations.Test)334 Block (io.trino.spi.block.Block)153 Type (io.trino.spi.type.Type)127 MaterializedResult (io.trino.testing.MaterializedResult)109 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)91 RowPagesBuilder (io.trino.RowPagesBuilder)72 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)68 ImmutableList (com.google.common.collect.ImmutableList)65 ArrayList (java.util.ArrayList)48 BlockBuilder (io.trino.spi.block.BlockBuilder)46 Optional (java.util.Optional)43 TaskContext (io.trino.operator.TaskContext)42 TestingTaskContext (io.trino.testing.TestingTaskContext)41 List (java.util.List)41 DictionaryBlock (io.trino.spi.block.DictionaryBlock)38 OperatorAssertion.toMaterializedResult (io.trino.operator.OperatorAssertion.toMaterializedResult)37 Slice (io.airlift.slice.Slice)36 OperatorFactory (io.trino.operator.OperatorFactory)32 LazyBlock (io.trino.spi.block.LazyBlock)32