Search in sources :

Example 6 with LocalExchangeSinkFactory

use of com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactory in project presto by prestodb.

the class TestLocalExchange method writeUnblockWhenAllReadersFinish.

@Test
public void writeUnblockWhenAllReadersFinish() {
    ImmutableList<BigintType> types = ImmutableList.of(BIGINT);
    LocalExchange exchange = new LocalExchange(FIXED_BROADCAST_DISTRIBUTION, 2, types, ImmutableList.of(), Optional.empty());
    assertEquals(exchange.getBufferCount(), 2);
    assertExchangeTotalBufferedBytes(exchange, 0);
    LocalExchangeSinkFactory sinkFactory = exchange.createSinkFactory();
    LocalExchangeSink sinkA = sinkFactory.createSink();
    assertSinkCanWrite(sinkA);
    LocalExchangeSink sinkB = sinkFactory.createSink();
    assertSinkCanWrite(sinkB);
    sinkFactory.close();
    sinkFactory.noMoreSinkFactories();
    LocalExchangeSource sourceA = exchange.getSource(0);
    assertSource(sourceA, 0);
    LocalExchangeSource sourceB = exchange.getSource(1);
    assertSource(sourceB, 0);
    sourceA.finish();
    assertSourceFinished(sourceA);
    assertSinkCanWrite(sinkA);
    assertSinkCanWrite(sinkB);
    sourceB.finish();
    assertSourceFinished(sourceB);
    assertSinkFinished(sinkA);
    assertSinkFinished(sinkB);
}
Also used : LocalExchangeSinkFactory(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactory) BigintType(com.facebook.presto.spi.type.BigintType) Test(org.testng.annotations.Test)

Example 7 with LocalExchangeSinkFactory

use of com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactory in project presto by prestodb.

the class TestLocalExchange method testGatherSingleWriter.

@Test
public void testGatherSingleWriter() {
    LocalExchange exchange = new LocalExchange(SINGLE_DISTRIBUTION, 8, TYPES, ImmutableList.of(), Optional.empty(), new DataSize(retainedSizeOfPages(99), BYTE));
    assertEquals(exchange.getBufferCount(), 1);
    assertExchangeTotalBufferedBytes(exchange, 0);
    LocalExchangeSinkFactory sinkFactory = exchange.createSinkFactory();
    LocalExchangeSource source = exchange.getSource(0);
    assertSource(source, 0);
    LocalExchangeSink sink = sinkFactory.createSink();
    sinkFactory.close();
    sinkFactory.noMoreSinkFactories();
    assertSinkCanWrite(sink);
    assertSource(source, 0);
    // add the first page which should cause the reader to unblock
    ListenableFuture<?> readFuture = source.waitForReading();
    assertFalse(readFuture.isDone());
    sink.addPage(createPage(0));
    assertTrue(readFuture.isDone());
    assertExchangeTotalBufferedBytes(exchange, 1);
    assertSource(source, 1);
    sink.addPage(createPage(1));
    assertSource(source, 2);
    assertExchangeTotalBufferedBytes(exchange, 2);
    assertRemovePage(source, createPage(0));
    assertSource(source, 1);
    assertExchangeTotalBufferedBytes(exchange, 1);
    assertRemovePage(source, createPage(1));
    assertSource(source, 0);
    assertExchangeTotalBufferedBytes(exchange, 0);
    sink.addPage(createPage(2));
    sink.addPage(createPage(3));
    assertSource(source, 2);
    assertExchangeTotalBufferedBytes(exchange, 2);
    sink.finish();
    assertSinkFinished(sink);
    assertSource(source, 2);
    assertRemovePage(source, createPage(2));
    assertSource(source, 1);
    assertSinkFinished(sink);
    assertExchangeTotalBufferedBytes(exchange, 1);
    assertRemovePage(source, createPage(3));
    assertSourceFinished(source);
    assertExchangeTotalBufferedBytes(exchange, 0);
}
Also used : LocalExchangeSinkFactory(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactory) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Aggregations

LocalExchangeSinkFactory (com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactory)7 Test (org.testng.annotations.Test)7 DataSize (io.airlift.units.DataSize)3 Page (com.facebook.presto.spi.Page)2 ExceededMemoryLimitException (com.facebook.presto.ExceededMemoryLimitException)1 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)1 RowPagesBuilder.rowPagesBuilder (com.facebook.presto.RowPagesBuilder.rowPagesBuilder)1 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)1 HashBuilderOperatorFactory (com.facebook.presto.operator.HashBuilderOperator.HashBuilderOperatorFactory)1 OperatorAssertion.assertOperatorEquals (com.facebook.presto.operator.OperatorAssertion.assertOperatorEquals)1 ValuesOperatorFactory (com.facebook.presto.operator.ValuesOperator.ValuesOperatorFactory)1 LocalExchange (com.facebook.presto.operator.exchange.LocalExchange)1 LocalExchangeSinkOperatorFactory (com.facebook.presto.operator.exchange.LocalExchangeSinkOperator.LocalExchangeSinkOperatorFactory)1 LocalExchangeSourceOperatorFactory (com.facebook.presto.operator.exchange.LocalExchangeSourceOperator.LocalExchangeSourceOperatorFactory)1 Block (com.facebook.presto.spi.block.Block)1 BigintType (com.facebook.presto.spi.type.BigintType)1 BIGINT (com.facebook.presto.spi.type.BigintType.BIGINT)1 Type (com.facebook.presto.spi.type.Type)1 VARCHAR (com.facebook.presto.spi.type.VarcharType.VARCHAR)1 JoinFilterFunctionFactory (com.facebook.presto.sql.gen.JoinFilterFunctionCompiler.JoinFilterFunctionFactory)1