use of com.apple.foundationdb.record.query.plan.temp.debug.Debugger in project fdb-record-layer by FoundationDB.
the class PlannerGraphProperty method evaluateAtRef.
@Nonnull
@Override
public PlannerGraph evaluateAtRef(@Nonnull final ExpressionRef<? extends RelationalExpression> ref, @Nonnull List<PlannerGraph> memberResults) {
if (memberResults.isEmpty()) {
// should not happen -- but we don't want to bail
return PlannerGraph.builder(new PlannerGraph.ExpressionRefHeadNode(ref)).build();
}
if (removePlansIfPossible()) {
final List<PlannerGraph> filteredMemberResults = memberResults.stream().filter(graph -> graph.getRoot() instanceof PlannerGraph.WithExpression).filter(graph -> {
final RelationalExpression expression = ((PlannerGraph.WithExpression) graph.getRoot()).getExpression();
return !(expression instanceof RecordQueryPlan);
}).collect(Collectors.toList());
// if we filtered down to empty it is better to just show the physical plan, otherwise try to avoid it
if (!filteredMemberResults.isEmpty()) {
memberResults = filteredMemberResults;
}
} else if (removeLogicalExpressions()) {
final List<PlannerGraph> filteredMemberResults = memberResults.stream().filter(graph -> graph.getRoot() instanceof PlannerGraph.WithExpression).filter(graph -> ((PlannerGraph.WithExpression) graph.getRoot()).getExpression() instanceof RecordQueryPlan).collect(Collectors.toList());
// if we filtered down to empty it is better to just show the physical plan, otherwise try to avoid it
if (!filteredMemberResults.isEmpty()) {
memberResults = filteredMemberResults;
}
}
if (renderSingleGroups() || memberResults.size() > 1) {
final Node head = new PlannerGraph.ExpressionRefHeadNode(ref);
final PlannerGraph.InternalPlannerGraphBuilder plannerGraphBuilder = PlannerGraph.builder(head);
final List<PlannerGraph> memberGraphs = memberResults.stream().map(childGraph -> {
final Node root = childGraph.getRoot();
final Optional<String> debugNameOptional = Debugger.mapDebugger(debugger -> {
if (root instanceof PlannerGraph.WithExpression) {
final PlannerGraph.WithExpression withExpression = (PlannerGraph.WithExpression) root;
@Nullable final RelationalExpression expression = withExpression.getExpression();
return expression == null ? null : debugger.nameForObject(expression);
}
return null;
});
final Node member = debugNameOptional.map(PlannerGraph.ExpressionRefMemberNode::new).orElse(new PlannerGraph.ExpressionRefMemberNode());
return PlannerGraph.builder(member).addGraph(childGraph).addEdge(root, member, new PlannerGraph.GroupExpressionRefEdge()).build();
}).collect(Collectors.toList());
memberGraphs.forEach(memberGraph -> {
plannerGraphBuilder.addGraph(memberGraph);
plannerGraphBuilder.addEdge(memberGraph.getRoot(), head, new PlannerGraph.GroupExpressionRefInternalEdge());
});
return plannerGraphBuilder.build();
} else {
// !renderSingleGroups && memberResults.size() == 1
return Iterables.getOnlyElement(memberResults);
}
}
Aggregations