Search in sources :

Example 1 with Cluster

use of com.apple.foundationdb.record.query.plan.temp.explain.GraphExporter.Cluster in project fdb-record-layer by FoundationDB.

the class PlannerGraphProperty method exportToDot.

/**
 * Creates a serialized format of this graph as a dot-compatible definition.
 * @param plannerGraph the planner graph we should export to dot
 * @param queryPlannerNodes set of nodes which is a subset of nodes of {@code plannerGraph} which represents the
 *        actual query graph
 * @param clusteringFunction function to partition the planner graph into clusters. Clusters are not isolated
 *        sub-graphs in this context. It is possible and often desirable for a use case to define edges between
 *        nodes of clusters. Clusters are used by the dot exporter to
 *        <ul>
 *            <li>assign common attributes to all nodes and edges, e.g. like a common gray background</li>
 *            <li>assign a name that is displayed displayed</li>
 *            <li>cause the layout algorithm to pack the nodes in a cluster if they were one big node</li>
 *        </ul>
 * @return the graph as string in dot format.
 */
@Nonnull
public static String exportToDot(@Nonnull final AbstractPlannerGraph<Node, Edge> plannerGraph, @Nonnull final Set<Node> queryPlannerNodes, @Nonnull final Function<GraphExporter.ClusterProvider<Node, Edge>, Collection<Cluster<Node, Edge>>> clusteringFunction) {
    final GraphExporter<Node, Edge> exporter = new DotExporter<>(new CountingIdProvider<>(), Node::getAttributes, Edge::getAttributes, ImmutableMap.of("fontname", Attribute.dot("courier"), "rankdir", Attribute.dot("BT"), "splines", Attribute.dot("false")), (network, nodes) -> {
        final ImmutableList.Builder<Cluster<Node, Edge>> clusterBuilder = ImmutableList.builder();
        clusterBuilder.addAll(clustersForGroups(plannerGraph.getNetwork(), queryPlannerNodes));
        clusterBuilder.addAll(clusteringFunction.apply(PlannerGraphProperty::clustersForGroups));
        return clusterBuilder.build();
    });
    // export as string
    final Writer writer = new StringWriter();
    exporter.exportGraph(plannerGraph.getNetwork(), writer);
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) ImmutableList(com.google.common.collect.ImmutableList) Node(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph.Node) Cluster(com.apple.foundationdb.record.query.plan.temp.explain.GraphExporter.Cluster) PartialMatchEdge(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph.PartialMatchEdge) Edge(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph.Edge) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Nonnull(javax.annotation.Nonnull)

Aggregations

Cluster (com.apple.foundationdb.record.query.plan.temp.explain.GraphExporter.Cluster)1 Edge (com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph.Edge)1 Node (com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph.Node)1 PartialMatchEdge (com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph.PartialMatchEdge)1 ImmutableList (com.google.common.collect.ImmutableList)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Nonnull (javax.annotation.Nonnull)1