tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject git commit: TAJO-483: Add getParentCount(), getParents(), getParent() functions to DirectedGraph. (jihoon)
Date Wed, 08 Jan 2014 14:48:09 GMT
Updated Branches:
  refs/heads/master 7d85f3ae9 -> 3a2416766


TAJO-483: Add getParentCount(), getParents(), getParent() functions to DirectedGraph. (jihoon)


Project: http://git-wip-us.apache.org/repos/asf/incubator-tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tajo/commit/3a241676
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/3a241676
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/3a241676

Branch: refs/heads/master
Commit: 3a24167667c5b8c9242b3b584358827c5758375e
Parents: 7d85f3a
Author: Jihoon Son <jihoonson@apache.org>
Authored: Wed Jan 8 23:47:45 2014 +0900
Committer: Jihoon Son <jihoonson@apache.org>
Committed: Wed Jan 8 23:47:45 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 ++
 .../apache/tajo/engine/planner/LogicalPlan.java |  2 +-
 .../tajo/engine/planner/global/MasterPlan.java  |  4 +-
 .../engine/planner/graph/DirectedGraph.java     | 10 +++--
 .../planner/graph/SimpleDirectedGraph.java      | 44 +++++++++++++++++---
 .../planner/graph/SimpleUndirectedGraph.java    | 12 +++++-
 .../tajo/engine/planner/TestLogicalPlan.java    |  4 +-
 7 files changed, 64 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3a241676/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 3c71e57..410ce47 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -114,6 +114,9 @@ Release 0.8.0 - unreleased
 
   IMPROVEMENTS
 
+    TAJO-483: Add getParentCount(), getParents(), getParent() functions to DirectedGraph.

+    (jihoon)
+
     TAJO-433: Improve integration with Hive. (jaehwa)
 
     TAJO-471: Extract ColumnPartitonUtils class for ColumnPartition rewrite.

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3a241676/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
index 5bba89b..584fd6e 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
@@ -126,7 +126,7 @@ public class LogicalPlan {
   }
 
   public QueryBlock getParentBlock(QueryBlock block) {
-    return queryBlocks.get(queryBlockGraph.getParent(block.getName()));
+    return queryBlocks.get(queryBlockGraph.getParent(block.getName(), 0));
   }
 
   public List<QueryBlock> getChildBlocks(QueryBlock block) {

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3a241676/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/global/MasterPlan.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/global/MasterPlan.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/global/MasterPlan.java
index 2ac2bc9..f6ac2be 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/global/MasterPlan.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/global/MasterPlan.java
@@ -146,7 +146,7 @@ public class MasterPlan {
 
   public boolean isRoot(ExecutionBlock execBlock) {
     if (!execBlock.getId().equals(terminalBlock.getId())) {
-      return execBlockGraph.getParent(execBlock.getId()).equals(terminalBlock.getId());
+      return execBlockGraph.getParent(execBlock.getId(), 0).equals(terminalBlock.getId());
     } else {
       return false;
     }
@@ -173,7 +173,7 @@ public class MasterPlan {
   }
 
   public ExecutionBlock getParent(ExecutionBlock executionBlock) {
-    return execBlockMap.get(execBlockGraph.getParent(executionBlock.getId()));
+    return execBlockMap.get(execBlockGraph.getParent(executionBlock.getId(), 0));
   }
 
   public List<ExecutionBlock> getChilds(ExecutionBlock execBlock) {

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3a241676/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/DirectedGraph.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/DirectedGraph.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/DirectedGraph.java
index b6ff71b..c6f4aaa 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/DirectedGraph.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/DirectedGraph.java
@@ -45,13 +45,17 @@ public interface DirectedGraph<V, E> extends Graph<V, E> {
 
   boolean isLeaf(V v);
 
-  @Nullable V getParent(V v);
+  int getParentCount(V block);
 
-  int getChildCount(V v);
+  @Nullable V getParent(V block, int idx);
+
+  List<V> getParents(V block);
+
+  int getChildCount(V block);
 
   @Nullable V getChild(V block, int idx);
 
-  List<V> getChilds(V v);
+  List<V> getChilds(V block);
 
   /**
    * It visits all vertices in a post-order traverse way.

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3a241676/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/SimpleDirectedGraph.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/SimpleDirectedGraph.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/SimpleDirectedGraph.java
index 12f33cb..586e643 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/SimpleDirectedGraph.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/SimpleDirectedGraph.java
@@ -153,16 +153,39 @@ public class SimpleDirectedGraph<V, E> implements DirectedGraph<V,E>
{
 
   @Override
   public V getChild(V block, int idx) {
-    return getChilds(block).get(idx);
+    if (reversedEdges.containsKey(block)) {
+      int i = 0;
+      for (Map.Entry<V, E> entry: reversedEdges.get(block).entrySet()) {
+        if (idx == i++) {
+          return entry.getKey();
+        }
+      }
+    }
+    return null;
   }
 
   @Override
-  public @Nullable V getParent(V v) {
-    if (directedEdges.containsKey(v)) {
-      return directedEdges.get(v).keySet().iterator().next();
-    } else {
-      return null;
+  public @Nullable V getParent(V block, int idx) {
+    if (directedEdges.containsKey(block)) {
+      int i = 0;
+      for (Map.Entry<V, E> entry: directedEdges.get(block).entrySet()) {
+        if (idx == i++) {
+          return entry.getKey();
+        }
+      }
     }
+    return null;
+  }
+
+  @Override
+  public List<V> getParents(V block) {
+    List<V> childBlocks = new ArrayList<V>();
+    if (directedEdges.containsKey(block)) {
+      for (Map.Entry<V, E> entry: directedEdges.get(block).entrySet()) {
+        childBlocks.add(entry.getKey());
+      }
+    }
+    return childBlocks;
   }
 
   @Override
@@ -176,6 +199,15 @@ public class SimpleDirectedGraph<V, E> implements DirectedGraph<V,E>
{
   }
 
   @Override
+  public int getParentCount(V block) {
+    if (directedEdges.containsKey(block)) {
+      return directedEdges.get(block).size();
+    } else {
+      return -1;
+    }
+  }
+
+  @Override
   public void accept(V source, DirectedGraphVisitor<V> visitor) {
     Stack<V> stack = new Stack<V>();
     visitRecursive(stack, source, visitor);

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3a241676/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/SimpleUndirectedGraph.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/SimpleUndirectedGraph.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/SimpleUndirectedGraph.java
index 38a025d..3822ad7 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/SimpleUndirectedGraph.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/graph/SimpleUndirectedGraph.java
@@ -76,7 +76,17 @@ public class SimpleUndirectedGraph<V, E> extends SimpleDirectedGraph<V,
E> imple
   }
 
   @Override
-  public V getParent(V v) {
+  public V getParent(V v, int idx) {
+    throw new UnsupportedOperationException("Cannot support getParent(V v) in UndirectedGraph");
+  }
+
+  @Override
+  public int getParentCount(V v) {
+    throw new UnsupportedOperationException("Cannot support getParent(V v) in UndirectedGraph");
+  }
+
+  @Override
+  public List<V> getParents(V v) {
     throw new UnsupportedOperationException("Cannot support getParent(V v) in UndirectedGraph");
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3a241676/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlan.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlan.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlan.java
index 1b38acd..1d9df14 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlan.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlan.java
@@ -96,8 +96,8 @@ public class TestLogicalPlan {
     SimpleDirectedGraph<String, LogicalPlan.BlockEdge> graph = plan.getQueryBlockGraph();
     assertEquals(2, graph.getChildCount(root.getName()));
 
-    assertEquals(root.getName(), graph.getParent(new1.getName()));
-    assertEquals(root.getName(), graph.getParent(new2.getName()));
+    assertEquals(root.getName(), graph.getParent(new1.getName(), 0));
+    assertEquals(root.getName(), graph.getParent(new2.getName(), 0));
 
     assertTrue(graph.isRoot(root.getName()));
     assertFalse(graph.isRoot(new1.getName()));


Mime
View raw message