use of com.facebook.presto.sql.planner.plan.PlanNodeId in project presto by prestodb.
the class SqlTask method createTaskInfo.
private TaskInfo createTaskInfo(TaskHolder taskHolder) {
TaskStats taskStats = getTaskStats(taskHolder);
Set<PlanNodeId> noMoreSplits = getNoMoreSplits(taskHolder);
TaskStatus taskStatus = createTaskStatus(taskHolder);
return new TaskInfo(taskStatus, lastHeartbeat.get(), outputBuffer.getInfo(), noMoreSplits, taskStats, needsPlan.get(), taskStatus.getState().isDone());
}
use of com.facebook.presto.sql.planner.plan.PlanNodeId in project presto by prestodb.
the class HttpRemoteTask method addSplits.
@Override
public synchronized void addSplits(Multimap<PlanNodeId, Split> splitsBySource) {
requireNonNull(splitsBySource, "splitsBySource is null");
// only add pending split if not done
if (getTaskStatus().getState().isDone()) {
return;
}
for (Entry<PlanNodeId, Collection<Split>> entry : splitsBySource.asMap().entrySet()) {
PlanNodeId sourceId = entry.getKey();
Collection<Split> splits = entry.getValue();
checkState(!noMoreSplits.contains(sourceId), "noMoreSplits has already been set for %s", sourceId);
int added = 0;
for (Split split : splits) {
if (pendingSplits.put(sourceId, new ScheduledSplit(nextSplitId.getAndIncrement(), sourceId, split))) {
added++;
}
}
if (planFragment.isPartitionedSources(sourceId)) {
pendingSourceSplitCount += added;
partitionedSplitCountTracker.setPartitionedSplitCount(getPartitionedSplitCount());
}
needsUpdate.set(true);
}
updateSplitQueueSpace();
scheduleUpdate();
}
use of com.facebook.presto.sql.planner.plan.PlanNodeId in project presto by prestodb.
the class PlanPrinter method textDistributedPlan.
public static String textDistributedPlan(List<StageInfo> stages, Metadata metadata, Session session) {
StringBuilder builder = new StringBuilder();
List<StageInfo> allStages = stages.stream().flatMap(stage -> getAllStages(Optional.of(stage)).stream()).collect(toImmutableList());
for (StageInfo stageInfo : allStages) {
Map<PlanNodeId, PlanNodeStats> aggregatedStats = new HashMap<>();
List<PlanNodeStats> planNodeStats = stageInfo.getTasks().stream().map(TaskInfo::getStats).flatMap(taskStats -> getPlanNodeStats(taskStats).stream()).collect(toList());
for (PlanNodeStats stats : planNodeStats) {
aggregatedStats.merge(stats.getPlanNodeId(), stats, PlanNodeStats::merge);
}
builder.append(formatFragment(metadata, session, stageInfo.getPlan(), Optional.of(stageInfo.getStageStats()), Optional.of(aggregatedStats)));
}
return builder.toString();
}
use of com.facebook.presto.sql.planner.plan.PlanNodeId in project presto by prestodb.
the class JoinGraph method joinWith.
private JoinGraph joinWith(JoinGraph other, List<JoinNode.EquiJoinClause> joinClauses, Context context, PlanNodeId newRoot) {
for (PlanNode node : other.nodes) {
checkState(!edges.containsKey(node.getId()), format("Node [%s] appeared in two JoinGraphs", node));
}
List<PlanNode> nodes = ImmutableList.<PlanNode>builder().addAll(this.nodes).addAll(other.nodes).build();
ImmutableMultimap.Builder<PlanNodeId, Edge> edges = ImmutableMultimap.<PlanNodeId, Edge>builder().putAll(this.edges).putAll(other.edges);
List<Expression> joinedFilters = ImmutableList.<Expression>builder().addAll(this.filters).addAll(other.filters).build();
for (JoinNode.EquiJoinClause edge : joinClauses) {
Symbol leftSymbol = edge.getLeft();
Symbol rightSymbol = edge.getRight();
checkState(context.containsSymbol(leftSymbol));
checkState(context.containsSymbol(rightSymbol));
PlanNode left = context.getSymbolSource(leftSymbol);
PlanNode right = context.getSymbolSource(rightSymbol);
edges.put(left.getId(), new Edge(right, leftSymbol, rightSymbol));
edges.put(right.getId(), new Edge(left, rightSymbol, leftSymbol));
}
return new JoinGraph(nodes, edges.build(), newRoot, joinedFilters, Optional.empty());
}
use of com.facebook.presto.sql.planner.plan.PlanNodeId in project presto by prestodb.
the class LocalQueryRunner method createDrivers.
public List<Driver> createDrivers(Session session, @Language("SQL") String sql, OutputFactory outputFactory, TaskContext taskContext) {
Plan plan = createPlan(session, sql);
if (printPlan) {
System.out.println(PlanPrinter.textLogicalPlan(plan.getRoot(), plan.getTypes(), metadata, session));
}
SubPlan subplan = PlanFragmenter.createSubPlans(session, metadata, plan);
if (!subplan.getChildren().isEmpty()) {
throw new AssertionError("Expected subplan to have no children");
}
LocalExecutionPlanner executionPlanner = new LocalExecutionPlanner(metadata, sqlParser, Optional.empty(), pageSourceManager, indexManager, nodePartitioningManager, pageSinkManager, null, expressionCompiler, joinFilterFunctionCompiler, new IndexJoinLookupStats(), // make sure tests fail if compiler breaks
new CompilerConfig().setInterpreterEnabled(false), new TaskManagerConfig().setTaskConcurrency(4), spillerFactory, blockEncodingSerde, new PagesIndex.TestingFactory(), new JoinCompiler(), new LookupJoinOperators(new JoinProbeCompiler()));
// plan query
LocalExecutionPlan localExecutionPlan = executionPlanner.plan(session, subplan.getFragment().getRoot(), subplan.getFragment().getPartitioningScheme().getOutputLayout(), plan.getTypes(), outputFactory);
// generate sources
List<TaskSource> sources = new ArrayList<>();
long sequenceId = 0;
for (TableScanNode tableScan : findTableScanNodes(subplan.getFragment().getRoot())) {
TableLayoutHandle layout = tableScan.getLayout().get();
SplitSource splitSource = splitManager.getSplits(session, layout);
ImmutableSet.Builder<ScheduledSplit> scheduledSplits = ImmutableSet.builder();
while (!splitSource.isFinished()) {
for (Split split : getFutureValue(splitSource.getNextBatch(1000))) {
scheduledSplits.add(new ScheduledSplit(sequenceId++, tableScan.getId(), split));
}
}
sources.add(new TaskSource(tableScan.getId(), scheduledSplits.build(), true));
}
// create drivers
List<Driver> drivers = new ArrayList<>();
Map<PlanNodeId, DriverFactory> driverFactoriesBySource = new HashMap<>();
for (DriverFactory driverFactory : localExecutionPlan.getDriverFactories()) {
for (int i = 0; i < driverFactory.getDriverInstances().orElse(1); i++) {
if (driverFactory.getSourceId().isPresent()) {
checkState(driverFactoriesBySource.put(driverFactory.getSourceId().get(), driverFactory) == null);
} else {
DriverContext driverContext = taskContext.addPipelineContext(driverFactory.getPipelineId(), driverFactory.isInputDriver(), driverFactory.isOutputDriver()).addDriverContext();
Driver driver = driverFactory.createDriver(driverContext);
drivers.add(driver);
}
}
}
// add sources to the drivers
for (TaskSource source : sources) {
DriverFactory driverFactory = driverFactoriesBySource.get(source.getPlanNodeId());
checkState(driverFactory != null);
for (ScheduledSplit split : source.getSplits()) {
DriverContext driverContext = taskContext.addPipelineContext(driverFactory.getPipelineId(), driverFactory.isInputDriver(), driverFactory.isOutputDriver()).addDriverContext();
Driver driver = driverFactory.createDriver(driverContext);
driver.updateSource(new TaskSource(split.getPlanNodeId(), ImmutableSet.of(split), true));
drivers.add(driver);
}
}
for (DriverFactory driverFactory : localExecutionPlan.getDriverFactories()) {
driverFactory.close();
}
return ImmutableList.copyOf(drivers);
}
Aggregations