drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jacq...@apache.org
Subject [01/24] git commit: Enhance plan format to number operator ids and fragment ids.
Date Thu, 22 May 2014 01:14:38 GMT
Repository: incubator-drill
Updated Branches:
  refs/heads/diagnostics2 [created] c34a190fc


Enhance plan format to number operator ids and fragment ids.


Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/1bc276dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/1bc276dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/1bc276dd

Branch: refs/heads/diagnostics2
Commit: 1bc276ddf5987054098d5a9497dbe71f661c4f88
Parents: 70fab8c
Author: Jacques Nadeau <jacques@apache.org>
Authored: Fri May 16 08:47:19 2014 -0700
Committer: Jacques Nadeau <jacques@apache.org>
Committed: Mon May 19 09:11:21 2014 -0700

----------------------------------------------------------------------
 .../planner/physical/BroadcastExchangePrel.java |   2 +-
 .../exec/planner/physical/ExchangePrel.java     |  18 ++
 .../physical/HashToMergeExchangePrel.java       |   2 +-
 .../physical/HashToRandomExchangePrel.java      |   2 +-
 .../physical/OrderedPartitionExchangePrel.java  |   2 +-
 .../exec/planner/physical/PrelVisitor.java      |   1 +
 .../physical/SelectionVectorPrelVisitor.java    |   5 +
 .../physical/SingleMergeExchangePrel.java       |   2 +-
 .../planner/physical/UnionExchangePrel.java     |   2 +-
 .../physical/explain/NumberingRelWriter.java    | 193 ++++++++++++++++
 .../planner/physical/explain/PrelSequencer.java | 222 +++++++++++++++++++
 .../planner/sql/handlers/DefaultSqlHandler.java |   7 +
 12 files changed, 452 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/BroadcastExchangePrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/BroadcastExchangePrel.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/BroadcastExchangePrel.java
index a0704b7..e0f3ee1 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/BroadcastExchangePrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/BroadcastExchangePrel.java
@@ -36,7 +36,7 @@ import org.eigenbase.relopt.RelOptCost;
 import org.eigenbase.relopt.RelOptPlanner;
 import org.eigenbase.relopt.RelTraitSet;
 
-public class BroadcastExchangePrel extends SinglePrel{
+public class BroadcastExchangePrel extends ExchangePrel{
 
   public BroadcastExchangePrel(RelOptCluster cluster, RelTraitSet traitSet, RelNode input)
{
     super(cluster, traitSet, input);

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ExchangePrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ExchangePrel.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ExchangePrel.java
new file mode 100644
index 0000000..360fa80
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/ExchangePrel.java
@@ -0,0 +1,18 @@
+package org.apache.drill.exec.planner.physical;
+
+import org.eigenbase.rel.RelNode;
+import org.eigenbase.relopt.RelOptCluster;
+import org.eigenbase.relopt.RelTraitSet;
+
+public abstract class ExchangePrel extends SinglePrel{
+
+  public ExchangePrel(RelOptCluster cluster, RelTraitSet traits, RelNode child) {
+    super(cluster, traits, child);
+  }
+
+  @Override
+  public <T, X, E extends Throwable> T accept(PrelVisitor<T, X, E> logicalVisitor,
X value) throws E {
+    return logicalVisitor.visitExchange(this, value);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/HashToMergeExchangePrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/HashToMergeExchangePrel.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/HashToMergeExchangePrel.java
index 45bc390..262fd8c 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/HashToMergeExchangePrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/HashToMergeExchangePrel.java
@@ -39,7 +39,7 @@ import org.eigenbase.relopt.RelTraitSet;
 import org.eigenbase.reltype.RelDataTypeField;
 
 
-public class HashToMergeExchangePrel extends SinglePrel {
+public class HashToMergeExchangePrel extends ExchangePrel {
 
   private final List<DistributionField> distFields;
   private int numEndPoints = 0;

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/HashToRandomExchangePrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/HashToRandomExchangePrel.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/HashToRandomExchangePrel.java
index d582684..ec9ed79 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/HashToRandomExchangePrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/HashToRandomExchangePrel.java
@@ -41,7 +41,7 @@ import org.eigenbase.reltype.RelDataTypeField;
 import org.eigenbase.rex.RexNode;
 
 
-public class HashToRandomExchangePrel extends SinglePrel {
+public class HashToRandomExchangePrel extends ExchangePrel {
 
   private final List<DistributionField> fields;
 

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/OrderedPartitionExchangePrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/OrderedPartitionExchangePrel.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/OrderedPartitionExchangePrel.java
index f551a27..36a67cb 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/OrderedPartitionExchangePrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/OrderedPartitionExchangePrel.java
@@ -33,7 +33,7 @@ import org.eigenbase.relopt.RelOptCost;
 import org.eigenbase.relopt.RelOptPlanner;
 import org.eigenbase.relopt.RelTraitSet;
 
-public class OrderedPartitionExchangePrel extends SinglePrel {
+public class OrderedPartitionExchangePrel extends ExchangePrel {
 
   public OrderedPartitionExchangePrel(RelOptCluster cluster, RelTraitSet traitSet, RelNode
input) {
     super(cluster, traitSet, input);

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/PrelVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/PrelVisitor.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/PrelVisitor.java
index ab22b97..862b133 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/PrelVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/PrelVisitor.java
@@ -21,6 +21,7 @@ package org.apache.drill.exec.planner.physical;
 public interface PrelVisitor<RETURN, EXTRA, EXCEP extends Throwable> {
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PrelVisitor.class);
 
+  public RETURN visitExchange(ExchangePrel prel, EXTRA value) throws EXCEP;
   public RETURN visitPrel(Prel prel, EXTRA value) throws EXCEP;
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SelectionVectorPrelVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SelectionVectorPrelVisitor.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SelectionVectorPrelVisitor.java
index aa7e91c..224ab76 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SelectionVectorPrelVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SelectionVectorPrelVisitor.java
@@ -34,6 +34,11 @@ public class SelectionVectorPrelVisitor implements PrelVisitor<Prel,
Void, Runti
   }
 
   @Override
+  public Prel visitExchange(ExchangePrel prel, Void value) throws RuntimeException {
+    return visitPrel(prel, value);
+  }
+
+  @Override
   public Prel visitPrel(Prel prel, Void value) throws RuntimeException {
     SelectionVectorMode[] encodings = prel.getSupportedEncodings();
     List<RelNode> children = Lists.newArrayList();

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SingleMergeExchangePrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SingleMergeExchangePrel.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SingleMergeExchangePrel.java
index 9b93058..05d6e89 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SingleMergeExchangePrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/SingleMergeExchangePrel.java
@@ -38,7 +38,7 @@ import org.eigenbase.relopt.RelOptCost;
 import org.eigenbase.relopt.RelOptPlanner;
 import org.eigenbase.relopt.RelTraitSet;
 
-public class SingleMergeExchangePrel extends SinglePrel {
+public class SingleMergeExchangePrel extends ExchangePrel {
 
   private final RelCollation collation ;
 

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/UnionExchangePrel.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/UnionExchangePrel.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/UnionExchangePrel.java
index c2cf685..5d6b85d 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/UnionExchangePrel.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/UnionExchangePrel.java
@@ -35,7 +35,7 @@ import org.eigenbase.relopt.RelOptCost;
 import org.eigenbase.relopt.RelOptPlanner;
 import org.eigenbase.relopt.RelTraitSet;
 
-public class UnionExchangePrel extends SinglePrel {
+public class UnionExchangePrel extends ExchangePrel {
 
   public UnionExchangePrel(RelOptCluster cluster, RelTraitSet traitSet, RelNode input) {
     super(cluster, traitSet, input);

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/explain/NumberingRelWriter.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/explain/NumberingRelWriter.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/explain/NumberingRelWriter.java
new file mode 100644
index 0000000..6522ad9
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/explain/NumberingRelWriter.java
@@ -0,0 +1,193 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.physical.explain;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import net.hydromatic.linq4j.Ord;
+import net.hydromatic.optiq.runtime.Spacer;
+
+import org.apache.drill.exec.planner.physical.Prel;
+import org.apache.drill.exec.planner.physical.explain.PrelSequencer.OpId;
+import org.eigenbase.rel.RelNode;
+import org.eigenbase.rel.RelWriter;
+import org.eigenbase.rel.metadata.RelMetadataQuery;
+import org.eigenbase.rex.RexNode;
+import org.eigenbase.sql.SqlExplainLevel;
+import org.eigenbase.util.Pair;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Copied mostly from RelWriterImpl but customized to create user useful ids.
+ */
+class NumberingRelWriter implements RelWriter {
+  //~ Instance fields --------------------------------------------------------
+
+  protected final PrintWriter pw;
+  private final SqlExplainLevel detailLevel;
+  protected final Spacer spacer = new Spacer();
+  private final List<Pair<String, Object>> values = new ArrayList<Pair<String,
Object>>();
+
+  private final Map<Prel, OpId> ids;
+  //~ Constructors -----------------------------------------------------------
+
+  public NumberingRelWriter(Map<Prel, OpId> ids, PrintWriter pw, SqlExplainLevel detailLevel)
{
+    this.pw = pw;
+    this.ids = ids;
+    this.detailLevel = detailLevel;
+  }
+
+  //~ Methods ----------------------------------------------------------------
+
+  protected void explain_(
+      RelNode rel,
+      List<Pair<String, Object>> values) {
+    List<RelNode> inputs = rel.getInputs();
+
+    if (!RelMetadataQuery.isVisibleInExplain(
+        rel,
+        detailLevel)) {
+      // render children in place of this, at same level
+      explainInputs(inputs);
+      return;
+    }
+
+    StringBuilder s = new StringBuilder();
+    OpId id = ids.get(rel);
+    s.append(String.format("%02d-%02d",id.fragmentId, id.opId));
+    s.append("  ");
+    if(id.opId == 0){
+      for(int i =0; i < spacer.get(); i++){ s.append('-');}
+    }else{
+
+      spacer.spaces(s);
+    }
+
+    s.append("  ");
+
+    s.append(rel.getRelTypeName().replace("Prel", ""));
+    if (detailLevel != SqlExplainLevel.NO_ATTRIBUTES) {
+      int j = 0;
+      for (Pair<String, Object> value : values) {
+        if (value.right instanceof RelNode) {
+          continue;
+        }
+        if (j++ == 0) {
+          s.append("(");
+        } else {
+          s.append(", ");
+        }
+        s.append(value.left)
+            .append("=[")
+            .append(value.right)
+            .append("]");
+      }
+      if (j > 0) {
+        s.append(")");
+      }
+    }
+    if (detailLevel == SqlExplainLevel.ALL_ATTRIBUTES) {
+      s.append(": rowcount = ")
+          .append(RelMetadataQuery.getRowCount(rel))
+          .append(", cumulative cost = ")
+          .append(RelMetadataQuery.getCumulativeCost(rel));
+       s.append(", id = ").append(rel.getId());
+    }
+    pw.println(s);
+    spacer.add(2);
+    explainInputs(inputs);
+    spacer.subtract(2);
+  }
+
+  private void explainInputs(List<RelNode> inputs) {
+    for (RelNode input : inputs) {
+      input.explain(this);
+    }
+  }
+
+  public final void explain(RelNode rel, List<Pair<String, Object>> valueList)
{
+    explain_(rel, valueList);
+  }
+
+  public SqlExplainLevel getDetailLevel() {
+    return detailLevel;
+  }
+
+  public RelWriter input(String term, RelNode input) {
+    values.add(Pair.of(term, (Object) input));
+    return this;
+  }
+
+  public RelWriter item(String term, Object value) {
+    values.add(Pair.of(term, value));
+    return this;
+  }
+
+  public RelWriter itemIf(String term, Object value, boolean condition) {
+    if (condition) {
+      item(term, value);
+    }
+    return this;
+  }
+
+  public RelWriter done(RelNode node) {
+    int i = 0;
+    if (values.size() > 0 && values.get(0).left.equals("subset")) {
+      ++i;
+    }
+    for (RelNode input : node.getInputs()) {
+      assert values.get(i).right == input;
+      ++i;
+    }
+    for (RexNode expr : node.getChildExps()) {
+      assert values.get(i).right == expr;
+      ++i;
+    }
+    final List<Pair<String, Object>> valuesCopy =
+        ImmutableList.copyOf(values);
+    values.clear();
+    explain_(node, valuesCopy);
+    pw.flush();
+    return this;
+  }
+
+  public boolean nest() {
+    return false;
+  }
+
+  /**
+   * Converts the collected terms and values to a string. Does not write to
+   * the parent writer.
+   */
+  public String simple() {
+    final StringBuilder buf = new StringBuilder("(");
+    for (Ord<Pair<String, Object>> ord : Ord.zip(values)) {
+      if (ord.i > 0) {
+        buf.append(", ");
+      }
+      buf.append(ord.e.left).append("=[").append(ord.e.right).append("]");
+    }
+    buf.append(")");
+    return buf.toString();
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/explain/PrelSequencer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/explain/PrelSequencer.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/explain/PrelSequencer.java
new file mode 100644
index 0000000..169deca
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/physical/explain/PrelSequencer.java
@@ -0,0 +1,222 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.physical.explain;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+
+import org.apache.drill.exec.planner.physical.ExchangePrel;
+import org.apache.drill.exec.planner.physical.Prel;
+import org.apache.drill.exec.planner.physical.PrelVisitor;
+import org.eigenbase.rel.RelWriter;
+import org.eigenbase.sql.SqlExplainLevel;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class PrelSequencer implements PrelVisitor<Void, PrelSequencer.Frag, RuntimeException>{
+
+  private List<Frag> frags = Lists.newLinkedList();
+
+
+  public static String printWithIds(final Prel rel, SqlExplainLevel explainlevel){
+      if (rel == null) {
+        return null;
+      }
+      PrelSequencer s = new PrelSequencer();
+      final StringWriter sw = new StringWriter();
+      final RelWriter planWriter = new NumberingRelWriter(s.go(rel), new PrintWriter(sw),
explainlevel);
+      rel.explain(planWriter);
+      return sw.toString();
+
+  }
+
+
+
+  static class Frag implements Iterable<Frag>{
+    Prel root;
+    int majorFragmentId;
+    final List<Frag> children = Lists.newArrayList();
+    public Frag(Prel root) {
+      super();
+      this.root = root;
+    }
+
+    @Override
+    public Iterator<Frag> iterator() {
+      return children.iterator();
+    }
+
+    @Override
+    public int hashCode() {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((children == null) ? 0 : children.hashCode());
+      result = prime * result + majorFragmentId;
+      result = prime * result + ((root == null) ? 0 : root.hashCode());
+      return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (this == obj)
+        return true;
+      if (obj == null)
+        return false;
+      if (getClass() != obj.getClass())
+        return false;
+      Frag other = (Frag) obj;
+      if (children == null) {
+        if (other.children != null)
+          return false;
+      } else if (!children.equals(other.children))
+        return false;
+      if (majorFragmentId != other.majorFragmentId)
+        return false;
+      if (root == null) {
+        if (other.root != null)
+          return false;
+      } else if (!root.equals(other.root))
+        return false;
+      return true;
+    }
+
+    @Override
+    public String toString() {
+      final int maxLen = 10;
+      return "Frag [root=" + root + ", majorFragmentId=" + majorFragmentId + ", children="
+          + (children != null ? children.subList(0, Math.min(children.size(), maxLen)) :
null) + "]";
+    }
+
+
+  }
+
+  static class OpId{
+    int fragmentId;
+    int opId;
+    public OpId(int fragmentId, int opId) {
+      super();
+      this.fragmentId = fragmentId;
+      this.opId = opId;
+    }
+    @Override
+    public int hashCode() {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + fragmentId;
+      result = prime * result + opId;
+      return result;
+    }
+    @Override
+    public boolean equals(Object obj) {
+      if (this == obj)
+        return true;
+      if (obj == null)
+        return false;
+      if (getClass() != obj.getClass())
+        return false;
+      OpId other = (OpId) obj;
+      if (fragmentId != other.fragmentId)
+        return false;
+      if (opId != other.opId)
+        return false;
+      return true;
+    }
+    @Override
+    public String toString() {
+      return fragmentId + ":*:" + opId;
+    }
+
+
+  }
+
+  public Map<Prel, OpId> go(Prel root){
+
+    // get fragments.
+    Frag rootFrag = new Frag(root);
+    frags.add(rootFrag);
+    root.accept(this, rootFrag);
+
+    // do depth first traversal of fragments to assign major fragment ids.
+    Queue<Frag> q = Lists.newLinkedList();
+
+    q.add(rootFrag);
+    int majorFragmentId = 0;
+    while(!q.isEmpty()){
+      Frag frag = q.remove();
+
+      frag.majorFragmentId = majorFragmentId++;
+
+      for(Frag child : frag){
+        q.add(child);
+      }
+    }
+
+    // for each fragment, do a dfs of operators to assign operator ids.
+    Map<Prel, OpId> ids = Maps.newHashMap();
+    for(Frag f : frags){
+      int id = 0;
+      Queue<Prel> ops = Lists.newLinkedList();
+      ops.add(f.root);
+      while(!ops.isEmpty()){
+        Prel p = ops.remove();
+        if(p instanceof ExchangePrel && p != f.root) continue;
+        ids.put(p, new OpId(f.majorFragmentId, id++) );
+
+        List<Prel> children = Lists.reverse(Lists.newArrayList(p.iterator()));
+        for(Prel child : children){
+          ops.add(child);
+        }
+      }
+    }
+
+
+    return ids;
+
+  }
+
+
+  @Override
+  public Void visitExchange(ExchangePrel prel, Frag value) throws RuntimeException {
+    Frag newFrag = new Frag(prel);
+    frags.add(newFrag);
+    value.children.add(newFrag);
+    for(Prel child : prel){
+      child.accept(this, newFrag);
+    }
+
+    return null;
+  }
+
+  @Override
+  public Void visitPrel(Prel prel, Frag value) throws RuntimeException {
+    for(Prel children : prel){
+      children.accept(this, value);
+    }
+    return null;
+  }
+
+
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/1bc276dd/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
index 3fa9861..1cb3cfb 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DefaultSqlHandler.java
@@ -41,6 +41,7 @@ import org.apache.drill.exec.planner.physical.DrillDistributionTrait;
 import org.apache.drill.exec.planner.physical.PhysicalPlanCreator;
 import org.apache.drill.exec.planner.physical.Prel;
 import org.apache.drill.exec.planner.physical.SelectionVectorPrelVisitor;
+import org.apache.drill.exec.planner.physical.explain.PrelSequencer;
 import org.apache.drill.exec.planner.sql.DrillSqlWorker;
 import org.eigenbase.rel.RelNode;
 import org.eigenbase.relopt.RelOptUtil;
@@ -70,6 +71,12 @@ public class DefaultSqlHandler extends AbstractSqlHandler {
     }
   }
 
+  protected void log(String name, Prel node) {
+    if (logger.isDebugEnabled()) {
+      logger.debug(name + " : \n" + PrelSequencer.printWithIds(node, SqlExplainLevel.ALL_ATTRIBUTES));
+    }
+  }
+
   protected void log(String name, PhysicalPlan plan) throws JsonProcessingException {
     if (logger.isDebugEnabled()) {
       String planText = plan.unparse(context.getConfig().getMapper().writer());


Mime
View raw message