-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace JGraphT with scala-graph #3297
Changes from all commits
792e147
de68106
cec5b06
8f5b51b
8405cb5
7184adb
2731721
657f5fd
3e6d25f
6738e67
3612a4d
15d4c4d
ca6ad6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
package edu.uci.ics.amber.compiler.model | ||
|
||
import com.typesafe.scalalogging.LazyLogging | ||
import edu.uci.ics.amber.compiler.model.LogicalPlan.LogicalEdge | ||
import edu.uci.ics.amber.core.storage.FileResolver | ||
import edu.uci.ics.amber.operator.LogicalOp | ||
import edu.uci.ics.amber.operator.source.scan.ScanSourceOpDesc | ||
import edu.uci.ics.amber.core.virtualidentity.OperatorIdentity | ||
import edu.uci.ics.amber.core.workflow.PortIdentity | ||
import org.jgrapht.graph.DirectedAcyclicGraph | ||
import org.jgrapht.util.SupplierUtil | ||
import edu.uci.ics.amber.operator.LogicalOp | ||
import edu.uci.ics.amber.operator.source.scan.ScanSourceOpDesc | ||
import scalax.collection.OneOrMore | ||
import scalax.collection.generic.{AbstractDiEdge, MultiEdge} | ||
import scalax.collection.mutable.Graph | ||
|
||
import java.util | ||
import scala.collection.mutable.ArrayBuffer | ||
import scala.util.{Failure, Success, Try} | ||
|
||
object LogicalPlan { | ||
|
||
private def toJgraphtDAG( | ||
case class LogicalEdge(logicalLink: LogicalLink) | ||
extends AbstractDiEdge(logicalLink.fromOpId, logicalLink.toOpId) | ||
with MultiEdge { | ||
override def extendKeyBy: OneOrMore[Any] = | ||
OneOrMore.one((logicalLink.fromPortId, logicalLink.toPortId)) | ||
} | ||
|
||
private def toScalaDAG( | ||
operatorList: List[LogicalOp], | ||
links: List[LogicalLink] | ||
): DirectedAcyclicGraph[OperatorIdentity, LogicalLink] = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the |
||
val workflowDag = | ||
new DirectedAcyclicGraph[OperatorIdentity, LogicalLink]( | ||
null, // vertexSupplier | ||
SupplierUtil.createSupplier(classOf[LogicalLink]), // edgeSupplier | ||
false, // weighted | ||
true // allowMultipleEdges | ||
) | ||
operatorList.foreach(op => workflowDag.addVertex(op.operatorIdentifier)) | ||
links.foreach(l => | ||
workflowDag.addEdge( | ||
l.fromOpId, | ||
l.toOpId, | ||
l | ||
) | ||
) | ||
): Graph[OperatorIdentity, LogicalEdge] = { | ||
val workflowDag = Graph.empty[OperatorIdentity, LogicalEdge]() | ||
operatorList.foreach(op => workflowDag.add(op.operatorIdentifier)) | ||
links.foreach(l => workflowDag.add(LogicalEdge(l))) | ||
workflowDag | ||
} | ||
|
||
|
@@ -53,10 +49,15 @@ case class LogicalPlan( | |
private lazy val operatorMap: Map[OperatorIdentity, LogicalOp] = | ||
operators.map(op => (op.operatorIdentifier, op)).toMap | ||
|
||
private lazy val jgraphtDag: DirectedAcyclicGraph[OperatorIdentity, LogicalLink] = | ||
LogicalPlan.toJgraphtDAG(operators, links) | ||
private lazy val scalaDAG: Graph[OperatorIdentity, LogicalEdge] = | ||
LogicalPlan.toScalaDAG(operators, links) | ||
|
||
def getTopologicalOpIds: util.Iterator[OperatorIdentity] = jgraphtDag.iterator() | ||
def getTopologicalOpIds: Iterator[OperatorIdentity] = { | ||
scalaDAG.topologicalSort match { | ||
case Left(value) => throw new RuntimeException("topological sort failed.") | ||
case Right(value) => value.iterator.map(_.outer) | ||
} | ||
} | ||
|
||
def getOperator(opId: String): LogicalOp = operatorMap(OperatorIdentity(opId)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jgrapht is still used in many other places in the amber module. Please do a thorough check.