Fix NoSuchElementException when scheduling empty split
@@ -22,7 +22,6 @@ import com.facebook.presto.split.SplitSource;
import com.facebook.presto.sql.planner.plan.PlanNodeId;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.FutureCallback;
@@ -36,6 +35,8 @@ import java.util.Set;
import static com.facebook.presto.execution.scheduler.ScheduleResult.BlockedReason.SPLIT_QUEUES_FULL;
import static com.facebook.presto.execution.scheduler.ScheduleResult.BlockedReason.WAITING_FOR_SOURCE;
+import static com.facebook.presto.spi.StandardErrorCode.NO_NODES_AVAILABLE;
+import static com.facebook.presto.util.Failures.checkCondition;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.util.concurrent.Futures.nonCancellationPropagating;
@@ -169,11 +170,14 @@ public class SourcePartitionedScheduler
{
state = State.SPLITS_SCHEDULED;
+ List<Node> nodes = splitPlacementPolicy.allNodes();
+ checkCondition(!nodes.isEmpty(), NO_NODES_AVAILABLE, "No nodes available to run query");
+ Node node = nodes.iterator().next();
+
Split emptySplit = new Split(
splitSource.getConnectorId(),
splitSource.getTransactionHandle(),
new EmptySplit(splitSource.getConnectorId()));
- Node node = Iterables.getLast(splitPlacementPolicy.allNodes());
Set<RemoteTask> emptyTask = assignSplits(ImmutableMultimap.of(node, emptySplit));
return new ScheduleResult(false, emptyTask, 1);
}
