use of edu.snu.mist.client.datastreams.MISTStream in project mist by snuspl.
the class OperatorChainDagGenerator method generateOperatorChainDAG.
/**
* Generate OperatorChain DAG according to the logic described above.
* @return the OperatorChain DAG
* The chain is represented as a list and AvroVertexSerializable can be serialized by avro
*/
public DAG<List<MISTStream>, MISTEdge> generateOperatorChainDAG() {
final DAG<OperatorChain, MISTEdge> chainDag = new AdjacentListDAG<>();
final Map<MISTStream, OperatorChain> vertexChainMap = new HashMap<>();
// from the root operators which are following sources.
for (final MISTStream source : optimizedDag.getRootVertices()) {
final Map<MISTStream, MISTEdge> rootEdges = optimizedDag.getEdges(source);
// This chaining group is a wrapper for List, for equality check
final OperatorChain srcChain = new OperatorChain();
// Partition Source
srcChain.chain.add(source);
chainDag.addVertex(srcChain);
vertexChainMap.put(source, srcChain);
for (final Map.Entry<MISTStream, MISTEdge> entry : rootEdges.entrySet()) {
final MISTStream nextVertex = entry.getKey();
final MISTEdge edge = entry.getValue();
final OperatorChain nextChain = getOperatorChain(nextVertex, vertexChainMap, chainDag);
chainDag.addEdge(srcChain, nextChain, edge);
chainingInDfsOrder(nextChain, nextVertex, chainDag, vertexChainMap);
}
}
// Convert to List<AvroVertexSerializable> for AvroOperatorChainDag
final DAG<List<MISTStream>, MISTEdge> result = new AdjacentListDAG<>();
final Queue<OperatorChain> queue = new LinkedList<>();
final Iterator<OperatorChain> iterator = GraphUtils.topologicalSort(chainDag);
while (iterator.hasNext()) {
final OperatorChain queryPartition = iterator.next();
queue.add(queryPartition);
result.addVertex(queryPartition.chain);
}
for (final OperatorChain operatorChain : queue) {
final Map<OperatorChain, MISTEdge> edges = chainDag.getEdges(operatorChain);
for (final Map.Entry<OperatorChain, MISTEdge> edge : edges.entrySet()) {
result.addEdge(operatorChain.chain, edge.getKey().chain, edge.getValue());
}
}
return result;
}
Aggregations