Search in sources :

Example 6 with LocalExchangeFactory

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

the class TestLocalExchange method testRandom.

@Test(dataProvider = "executionStrategy")
public void testRandom(PipelineExecutionStrategy executionStrategy) {
    LocalExchangeFactory localExchangeFactory = new LocalExchangeFactory(partitioningProviderManager, session, FIXED_ARBITRARY_DISTRIBUTION, 2, TYPES, ImmutableList.of(), Optional.empty(), executionStrategy, LOCAL_EXCHANGE_MAX_BUFFERED_BYTES);
    LocalExchangeSinkFactoryId localExchangeSinkFactoryId = localExchangeFactory.newSinkFactoryId();
    localExchangeFactory.noMoreSinkFactories();
    run(localExchangeFactory, executionStrategy, exchange -> {
        assertEquals(exchange.getBufferCount(), 2);
        assertExchangeTotalBufferedBytes(exchange, 0);
        LocalExchangeSinkFactory sinkFactory = exchange.getSinkFactory(localExchangeSinkFactoryId);
        LocalExchangeSink sink = sinkFactory.createSink();
        assertSinkCanWrite(sink);
        sinkFactory.close();
        sinkFactory.noMoreSinkFactories();
        LocalExchangeSource sourceA = exchange.getSource(0);
        assertSource(sourceA, 0);
        LocalExchangeSource sourceB = exchange.getSource(1);
        assertSource(sourceB, 0);
        for (int i = 0; i < 100; i++) {
            Page page = createPage(0);
            sink.addPage(page);
            assertExchangeTotalBufferedBytes(exchange, i + 1);
            LocalExchangeBufferInfo bufferInfoA = sourceA.getBufferInfo();
            LocalExchangeBufferInfo bufferInfoB = sourceB.getBufferInfo();
            assertEquals(bufferInfoA.getBufferedBytes() + bufferInfoB.getBufferedBytes(), retainedSizeOfPages(i + 1));
            assertEquals(bufferInfoA.getBufferedPages() + bufferInfoB.getBufferedPages(), i + 1);
        }
        // we should get ~50 pages per source, but we should get at least some pages in each buffer
        assertTrue(sourceA.getBufferInfo().getBufferedPages() > 0);
        assertTrue(sourceB.getBufferInfo().getBufferedPages() > 0);
        assertExchangeTotalBufferedBytes(exchange, 100);
    });
}
Also used : LocalExchangeSinkFactory(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactory) Page(com.facebook.presto.common.Page) LocalExchangeFactory(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeFactory) LocalExchangeSinkFactoryId(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactoryId) Test(org.testng.annotations.Test)

Example 7 with LocalExchangeFactory

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

the class TestLocalExchange method testGatherSingleWriter.

@Test(dataProvider = "executionStrategy")
public void testGatherSingleWriter(PipelineExecutionStrategy executionStrategy) {
    LocalExchangeFactory localExchangeFactory = new LocalExchangeFactory(partitioningProviderManager, session, SINGLE_DISTRIBUTION, 8, TYPES, ImmutableList.of(), Optional.empty(), executionStrategy, new DataSize(retainedSizeOfPages(99), BYTE));
    LocalExchangeSinkFactoryId localExchangeSinkFactoryId = localExchangeFactory.newSinkFactoryId();
    localExchangeFactory.noMoreSinkFactories();
    run(localExchangeFactory, executionStrategy, exchange -> {
        assertEquals(exchange.getBufferCount(), 1);
        assertExchangeTotalBufferedBytes(exchange, 0);
        LocalExchangeSinkFactory sinkFactory = exchange.getSinkFactory(localExchangeSinkFactoryId);
        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) LocalExchangeFactory(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeFactory) LocalExchangeSinkFactoryId(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactoryId) Test(org.testng.annotations.Test)

Example 8 with LocalExchangeFactory

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

the class TestLocalExchange method testPartition.

@Test(dataProvider = "executionStrategy")
public void testPartition(PipelineExecutionStrategy executionStrategy) {
    LocalExchangeFactory localExchangeFactory = new LocalExchangeFactory(partitioningProviderManager, session, FIXED_HASH_DISTRIBUTION, 2, TYPES, ImmutableList.of(0), Optional.empty(), executionStrategy, LOCAL_EXCHANGE_MAX_BUFFERED_BYTES);
    LocalExchangeSinkFactoryId localExchangeSinkFactoryId = localExchangeFactory.newSinkFactoryId();
    localExchangeFactory.noMoreSinkFactories();
    run(localExchangeFactory, executionStrategy, exchange -> {
        assertEquals(exchange.getBufferCount(), 2);
        assertExchangeTotalBufferedBytes(exchange, 0);
        LocalExchangeSinkFactory sinkFactory = exchange.getSinkFactory(localExchangeSinkFactoryId);
        LocalExchangeSink sink = sinkFactory.createSink();
        assertSinkCanWrite(sink);
        sinkFactory.close();
        sinkFactory.noMoreSinkFactories();
        LocalExchangeSource sourceA = exchange.getSource(0);
        assertSource(sourceA, 0);
        LocalExchangeSource sourceB = exchange.getSource(1);
        assertSource(sourceB, 0);
        sink.addPage(createPage(0));
        assertSource(sourceA, 1);
        assertSource(sourceB, 1);
        assertTrue(exchange.getBufferedBytes() >= retainedSizeOfPages(1));
        sink.addPage(createPage(0));
        assertSource(sourceA, 2);
        assertSource(sourceB, 2);
        assertTrue(exchange.getBufferedBytes() >= retainedSizeOfPages(2));
        assertPartitionedRemovePage(sourceA, 0, 2);
        assertSource(sourceA, 1);
        assertSource(sourceB, 2);
        assertPartitionedRemovePage(sourceA, 0, 2);
        assertSource(sourceA, 0);
        assertSource(sourceB, 2);
        sink.finish();
        assertSinkFinished(sink);
        assertSourceFinished(sourceA);
        assertSource(sourceB, 2);
        assertPartitionedRemovePage(sourceB, 1, 2);
        assertSourceFinished(sourceA);
        assertSource(sourceB, 1);
        assertPartitionedRemovePage(sourceB, 1, 2);
        assertSourceFinished(sourceA);
        assertSourceFinished(sourceB);
        assertExchangeTotalBufferedBytes(exchange, 0);
    });
}
Also used : LocalExchangeSinkFactory(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactory) LocalExchangeFactory(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeFactory) LocalExchangeSinkFactoryId(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactoryId) Test(org.testng.annotations.Test)

Example 9 with LocalExchangeFactory

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

the class TestLocalExchange method writeUnblockWhenAllReadersFinish.

@Test(dataProvider = "executionStrategy")
public void writeUnblockWhenAllReadersFinish(PipelineExecutionStrategy executionStrategy) {
    ImmutableList<Type> types = ImmutableList.of(BIGINT);
    LocalExchangeFactory localExchangeFactory = new LocalExchangeFactory(partitioningProviderManager, session, FIXED_BROADCAST_DISTRIBUTION, 2, types, ImmutableList.of(), Optional.empty(), executionStrategy, LOCAL_EXCHANGE_MAX_BUFFERED_BYTES);
    LocalExchangeSinkFactoryId localExchangeSinkFactoryId = localExchangeFactory.newSinkFactoryId();
    localExchangeFactory.noMoreSinkFactories();
    run(localExchangeFactory, executionStrategy, exchange -> {
        assertEquals(exchange.getBufferCount(), 2);
        assertExchangeTotalBufferedBytes(exchange, 0);
        LocalExchangeSinkFactory sinkFactory = exchange.getSinkFactory(localExchangeSinkFactoryId);
        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) Type(com.facebook.presto.common.type.Type) LocalExchangeFactory(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeFactory) LocalExchangeSinkFactoryId(com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactoryId) Test(org.testng.annotations.Test)

Aggregations

LocalExchangeFactory (com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeFactory)9 LocalExchangeSinkFactoryId (com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactoryId)8 Test (org.testng.annotations.Test)8 LocalExchangeSinkFactory (com.facebook.presto.operator.exchange.LocalExchange.LocalExchangeSinkFactory)7 DataSize (io.airlift.units.DataSize)4 Page (com.facebook.presto.common.Page)1 Type (com.facebook.presto.common.type.Type)1 HashBuilderOperatorFactory (com.facebook.presto.operator.HashBuilderOperator.HashBuilderOperatorFactory)1 ValuesOperatorFactory (com.facebook.presto.operator.ValuesOperator.ValuesOperatorFactory)1 LocalExchangeSinkOperatorFactory (com.facebook.presto.operator.exchange.LocalExchangeSinkOperator.LocalExchangeSinkOperatorFactory)1 LocalExchangeSourceOperatorFactory (com.facebook.presto.operator.exchange.LocalExchangeSourceOperator.LocalExchangeSourceOperatorFactory)1 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)1 JoinFilterFunctionFactory (com.facebook.presto.sql.gen.JoinFilterFunctionCompiler.JoinFilterFunctionFactory)1 OptionalInt (java.util.OptionalInt)1