Search in sources :

Example 21 with ScheduledSplit

use of com.facebook.presto.execution.ScheduledSplit in project presto by prestodb.

the class TestPrestoSparkSourceDistributionSplitAssigner method testAssignSplitsToPartitionWithRandomSplitSizes.

@Test
public void testAssignSplitsToPartitionWithRandomSplitSizes() {
    DataSize maxSplitDataSizePerPartition = new DataSize(2048, BYTE);
    int initialPartitionCount = 3;
    int minSparkInputPartitionCountForAutoTune = 2;
    int maxSparkInputPartitionCountForAutoTune = 5;
    int maxSplitSizeInBytes = 2048;
    AtomicInteger sequenceId = new AtomicInteger();
    for (int i = 0; i < 3; ++i) {
        List<Long> splitSizes = new ArrayList<>(1000);
        for (int j = 0; j < 1000; j++) {
            splitSizes.add(ThreadLocalRandom.current().nextLong((long) (maxSplitSizeInBytes * 1.2)));
        }
        PrestoSparkSplitAssigner assigner = new PrestoSparkSourceDistributionSplitAssigner(new PlanNodeId("test"), createSplitSource(splitSizes), 333, maxSplitDataSizePerPartition.toBytes(), initialPartitionCount, true, minSparkInputPartitionCountForAutoTune, maxSparkInputPartitionCountForAutoTune);
        HashMultimap<Integer, ScheduledSplit> actualAssignment = HashMultimap.create();
        while (true) {
            Optional<SetMultimap<Integer, ScheduledSplit>> assignment = assigner.getNextBatch();
            if (!assignment.isPresent()) {
                break;
            }
            actualAssignment.putAll(assignment.get());
        }
        long expectedSizeInBytes = splitSizes.stream().mapToLong(Long::longValue).sum();
        long actualTotalSizeInBytes = actualAssignment.values().stream().mapToLong(split -> split.getSplit().getConnectorSplit().getSplitSizeInBytes().orElseThrow(() -> new IllegalArgumentException("split size is expected to be present"))).sum();
        // check if all splits got assigned
        assertEquals(expectedSizeInBytes, actualTotalSizeInBytes);
    }
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) ConnectorPartitionHandle(com.facebook.presto.spi.connector.ConnectorPartitionHandle) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ArrayList(java.util.ArrayList) NOT_PARTITIONED(com.facebook.presto.spi.connector.NotPartitionedPartitionHandle.NOT_PARTITIONED) OptionalLong(java.util.OptionalLong) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HashMultimap(com.google.common.collect.HashMultimap) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) SplitSource(com.facebook.presto.split.SplitSource) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Lifespan(com.facebook.presto.execution.Lifespan) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) HostAddress(com.facebook.presto.spi.HostAddress) NodeSelectionStrategy(com.facebook.presto.spi.schedule.NodeSelectionStrategy) Ints.min(com.google.common.primitives.Ints.min) TestingTransactionHandle(com.facebook.presto.testing.TestingTransactionHandle) NodeProvider(com.facebook.presto.spi.NodeProvider) SetMultimap(com.google.common.collect.SetMultimap) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) DataSize(io.airlift.units.DataSize) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Split(com.facebook.presto.metadata.Split) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) Comparator(java.util.Comparator) BYTE(io.airlift.units.DataSize.Unit.BYTE) ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) ArrayList(java.util.ArrayList) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SetMultimap(com.google.common.collect.SetMultimap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataSize(io.airlift.units.DataSize) OptionalLong(java.util.OptionalLong) Test(org.testng.annotations.Test)

Aggregations

ScheduledSplit (com.facebook.presto.execution.ScheduledSplit)21 TaskSource (com.facebook.presto.execution.TaskSource)14 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)14 Split (com.facebook.presto.metadata.Split)8 ArrayList (java.util.ArrayList)8 Duration (io.airlift.units.Duration)5 Optional (java.util.Optional)5 Type (com.facebook.presto.common.type.Type)4 Lifespan (com.facebook.presto.execution.Lifespan)4 Driver (com.facebook.presto.operator.Driver)4 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)4 FixedPageSource (com.facebook.presto.spi.FixedPageSource)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 Map (java.util.Map)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 DriverFactory (com.facebook.presto.operator.DriverFactory)3 SerializedPrestoSparkTaskSource (com.facebook.presto.spark.classloader_interface.SerializedPrestoSparkTaskSource)3 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)3