nemo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-nemo] wonook commented on a change in pull request #215: [NEMO-373] Optimize with DAG Patterns
Date Tue, 30 Apr 2019 07:35:30 GMT
wonook commented on a change in pull request #215: [NEMO-373] Optimize with DAG Patterns
URL: https://github.com/apache/incubator-nemo/pull/215#discussion_r279640833
 
 

 ##########
 File path: compiler/optimizer/src/main/java/org/apache/nemo/compiler/optimizer/OptimizerUtils.java
 ##########
 @@ -36,28 +46,72 @@ private OptimizerUtils() {
   }
 
   /**
-   * Restore the formatted string into a pair of vertex/edge id and the execution property.
+   * Restore the formatted string into a pair of vertex/edge list and the execution property.
    *
    * @param string the formatted string.
-   * @return a pair of vertex/edge id and the execution property key index.
+   * @param dag the IR DAG to observe.
+   * @return a pair of vertex/edge list and the execution property key index.
    */
-  public static Pair<String, Integer> stringToIdAndEPKeyIndex(final String string)
{
-    // Formatted into 9 digits: 0:vertex/edge 1-5:ID 5-9:EP Index.
+  public static Pair<List<Object>, Integer> stringToObjAndEPKeyIndex(final String
string, final IRDAG dag) {
+    // Formatted into 9 digits: 0:vertex/edge 1-4:ID 5-8:EP Index.
     if (string.length() != 9) {
       throw new InvalidParameterException("The metric data should follow the format of "
         + "[0]: index indicating vertex/edge, [1-4]: id of the component, and [5-8]: EP Key
index. Current: " + string);
     }
     final Integer idx = Integer.parseInt(string.substring(0, 1));
     final Integer numericId = Integer.parseInt(string.substring(1, 5));
-    final String id;
+    final List<Object> objectList = new ArrayList<>();
     if (idx == 1) {
-      id = Util.restoreVertexId(numericId);
+      final String id = Util.restoreVertexId(numericId);
+      objectList.add(dag.getVertexById(id));
     } else if (idx == 2) {
-      id = Util.restoreEdgeId(numericId);
+      final String id = Util.restoreEdgeId(numericId);
+      objectList.add(dag.getEdgeById(id));
     } else {
       throw new UnsupportedMethodException("The index " + idx + " cannot be categorized into
a vertex or an edge");
     }
-    return Pair.of(id, Integer.parseInt(string.substring(5, 9)));
+    return Pair.of(objectList, Integer.parseInt(string.substring(5, 9)));
+  }
+
+  /**
+   * Restore the formatted string into a pair of vertex/edge list and the execution property
index.
+   *
+   * @param string the formatted string, for patterns.
+   * @param dag the IR DAG to observe.
+   * @return a pair of vertex/edge list and the execution property key index.
+   */
+  public static Pair<List<Object>, Integer> patternStringToObjAndEPKeyIndex(final
String string, final IRDAG dag) {
+    // Formatted into 10 digits: 0:vertex/edge 1-3: patternID 4-5: vertex/edge 6-9:EP Index.
+    final Integer idx = Integer.parseInt(string.substring(0, 1));
+    if (string.length() != 10 || idx != 1) {
+      throw new InvalidParameterException("The metric data should follow the format of "
+        + "[0]: index indicating vertex/edge, [1-3]: id of the pattern, [4-5]: vertex/edge,
"
+        + "and [6-9]: EP Key index. Current: " + string);
+    }
+    final IRDAG subDAG = MetricUtils.getSubDAGFromIndex(Integer.parseInt(string.substring(1,
4)));
+    final IRVertex targetVertex = subDAG.getTopologicalSort().get(subDAG.getVertices().size()
- 1);
+    if (subDAG.getEdges().stream().anyMatch(e -> e.getSrc().equals(targetVertex))) {
+      throw new MetricException(targetVertex.getId() + " is not the target vertex");
+    }
+
+    final Stream<IRVertex> targetVertexFromDAG = dag.getVertices().stream()
+      .filter(v -> v.toString().equals(targetVertex.toString()))
 
 Review comment:
   Actually, thinking about it, `instanceof` does not check if both classes have the same
transform for OperatorVertices or the same source for SourceVertices. That's why I've gone
for the toString methods. I could make the code a bit more complex and compare the transform/source
classes if you think that it makes it simpler. What do you think?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message