You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by ja...@apache.org on 2013/04/14 04:35:06 UTC

[2/9] Add flatten and join test executions. Abstract graph classes. Update storage engine definition to be a map. Move plan properties to use enum for plan type. Remove unused tests/resources. Update sql parser for change in storage engine definitio

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/defs/OrderDef.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/defs/OrderDef.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/defs/OrderDef.java
new file mode 100644
index 0000000..b0aa61d
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/defs/OrderDef.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.common.logical.defs;
+
+import org.apache.drill.common.expression.LogicalExpression;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class OrderDef {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(OrderDef.class);
+
+  private final Direction direction;
+  private final LogicalExpression expr;
+
+  @JsonCreator
+  public OrderDef(@JsonProperty("order") Direction direction, @JsonProperty("expr") LogicalExpression expr) {
+    this.expr = expr;
+    // default to ascending unless desc is provided.
+    this.direction = direction == null ? Direction.ASC : direction;
+  }
+  
+  @JsonIgnore
+  public Direction getDirection() {
+    return direction;
+  }
+
+  public LogicalExpression getExpr() {
+    return expr;
+  }
+
+  public String getOrder() {
+    return direction.description;
+  }
+
+  public static enum Direction {
+    ASC("asc"), DESC("desc");
+    public final String description;
+
+    Direction(String d) {
+      description = d;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/defs/PartitionDef.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/defs/PartitionDef.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/defs/PartitionDef.java
new file mode 100644
index 0000000..12047d5
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/defs/PartitionDef.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.common.logical.defs;
+
+import org.apache.drill.common.expression.LogicalExpression;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class PartitionDef {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PartitionDef.class);
+
+  private final PartitionType partitionType;
+  private final LogicalExpression[] expressions;
+  private final LogicalExpression[] starts;
+  
+  @JsonCreator
+  public PartitionDef(@JsonProperty("partitionType") PartitionType partitionType, @JsonProperty("exprs") LogicalExpression[] expressions, @JsonProperty("starts") LogicalExpression[] starts) {
+    this.partitionType = partitionType;
+    this.expressions = expressions;
+    this.starts = starts;
+  }
+
+  public PartitionType getPartitionType() {
+    return partitionType;
+  }
+
+  public LogicalExpression[] getExpressions() {
+    return expressions;
+  }
+
+  public LogicalExpression[] getStarts() {
+    return starts;
+  }
+  
+
+  public static enum PartitionType{ 
+    RANDOM, HASH, ORDERED;
+  };
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/AdjacencyList.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/AdjacencyList.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/AdjacencyList.java
deleted file mode 100644
index e896b3d..0000000
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/AdjacencyList.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*******************************************************************************
- * 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.common.logical.graph;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Multimaps;
-
-
-public class AdjacencyList<N extends Node<?>> {
-  private Set<N> allNodes = new HashSet<N>();
-  private ListMultimap<N, Edge<N>> adjacencies = ArrayListMultimap.create();
-
-  public void addEdge(N source, N target, int weight) {
-    adjacencies.put(source, new Edge<N>(source, target, weight));
-    allNodes.add(source);
-    allNodes.add(target);
-  }
-
-  public void clearVisited(){
-    for (Edge<N> e : adjacencies.values()) {
-      e.from.visited = false;
-      e.to.visited = false;
-    }
-  }
-  
-  public List<Edge<N>> getAdjacent(N source) {
-    return adjacencies.get(source);
-  }
-
-  
-  public void printEdges(){
-    for (Edge<N> e : adjacencies.values()) {
-      System.out.println(e.from.index + " -> " + e.to.index);
-    }
-  }
-  
-  
-//  public void reverseEdge(Edge<N> e) {
-//    adjacencies.get(e.from).remove(e);
-//    addEdge(e.to, e.from, e.weight);
-//  }
-
-//  public void reverseGraph() {
-//    adjacencies = getReversedList().adjacencies;
-//  }
-
-  public AdjacencyList<N> getReversedList() {
-    AdjacencyList<N> newlist = new AdjacencyList<N>();
-    for (Edge<N> e : adjacencies.values()) {
-      newlist.addEdge(e.to, e.from, e.weight);
-    }
-    return newlist;
-  }
-
-  public Set<N> getNodeSet() {
-    return adjacencies.keySet();
-  }
-
-  /**
-   * Get a list of nodes that have no outbound edges.
-   * @return
-   */
-  public Collection<N> getTerminalNodes(){
-    // we have to use the allNodes list as otherwise destination only nodes won't be found.
-    List<N> nodes = new LinkedList<N>(allNodes);
-    
-    for(Iterator<N> i = nodes.iterator(); i.hasNext(); ){
-      final N n = i.next();
-      
-      // remove any nodes that have one or more outbound edges.
-      List<Edge<N>> adjList = this.getAdjacent(n);
-      if(adjList != null && !adjList.isEmpty()) i.remove();
-     
-    }
-    return nodes;
-  }
-  
-  /**
-   * Get a list of all nodes that have no incoming edges.
-   * @return
-   */
-  public Collection<N> getStartNodes(){
-    Set<N> nodes = new HashSet<N>(getNodeSet());
-    for(Edge<N> e : adjacencies.values()){
-      nodes.remove(e.to);
-    }
-    return nodes;
-  }
-  
-  public Collection<Edge<N>> getAllEdges() {
-    return adjacencies.values();
-  }
-  
-  
-  public void fix(){
-    adjacencies = Multimaps.unmodifiableListMultimap(adjacencies);
-    allNodes =  Collections.unmodifiableSet(allNodes);
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/Edge.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/Edge.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/Edge.java
deleted file mode 100644
index 599c9eb..0000000
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/Edge.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * 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.common.logical.graph;
-
-
-public class Edge<N> implements Comparable<Edge<N>> {
-
-  final N from, to;
-  final int weight;
-
-  public Edge(final N argFrom, final N argTo, final int argWeight) {
-    from = argFrom;
-    to = argTo;
-    weight = argWeight;
-  }
-
-  public int compareTo(final Edge<N> argEdge) {
-    return weight - argEdge.weight;
-  }
-
-  @Override
-  public String toString() {
-    return "Edge [from=" + from + ", to=" + to + "]";
-  }
-  
-  
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/GraphAlgos.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/GraphAlgos.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/GraphAlgos.java
deleted file mode 100644
index ed3c00b..0000000
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/GraphAlgos.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * 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.common.logical.graph;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class GraphAlgos {
-  static final Logger logger = LoggerFactory.getLogger(GraphAlgos.class);
-
-  public static class TopoSorter<N extends Node<?>> {
-    final List<N> sorted = new LinkedList<N>();
-    final AdjacencyList<N> rGraph;
-
-    private TopoSorter(AdjacencyList<N> graph) {
-      graph.clearVisited();
-      
-      this.rGraph = graph.getReversedList();
-      Collection<N> sourceNodes = rGraph.getStartNodes();
-
-      for (N n : sourceNodes) {
-        visit(n);
-      }
-    }
-
-    private void visit(N n) {
-      if (n.visited)
-        return;
-
-      n.visited = true;
-      List<Edge<N>> edges = rGraph.getAdjacent(n);
-      if (edges != null) {
-        for (Edge<N> e : edges) {
-          visit(e.to);
-        }
-      }
-
-      sorted.add(n);
-
-    }
-
-    /**
-     * Execute a depth-first sort on the reversed DAG.
-     * 
-     * @param graph
-     *          The adjacency list for the DAG.
-     * @param sourceNodes
-     *          List of nodes that
-     * @return
-     */
-    public static <N extends Node<?>> List<N> sort(AdjacencyList<N> graph) {
-      TopoSorter<N> ts = new TopoSorter<N>(graph);
-      return ts.sorted;
-    }
-  }
-
-  public static <N extends Node<?>> List<List<N>> checkDirected(AdjacencyList<N> graph) {
-    Tarjan<N> t = new Tarjan<N>();
-    List<List<N>> subgraphs = t.executeTarjan(graph);
-    for (Iterator<List<N>> i = subgraphs.iterator(); i.hasNext();) {
-      List<N> l = i.next();
-      if (l.size() == 1)  i.remove();
-    }
-    return subgraphs;
-  }
-
-  public static class Tarjan<N extends Node<?>> {
-
-    private int index = 0;
-    private List<N> stack = new LinkedList<N>();
-    private List<List<N>> SCC = new LinkedList<List<N>>();
-
-    public List<List<N>> executeTarjan(AdjacencyList<N> graph) {
-      SCC.clear();
-      index = 0;
-      stack.clear();
-      if (graph != null) {
-        List<N> nodeList = new LinkedList<N>(graph.getNodeSet());
-        for (N node : nodeList) {
-          if (node.index == -1) {
-            tarjan(node, graph);
-          }
-        }
-      }
-      return SCC;
-    }
-
-    private List<List<N>> tarjan(N v, AdjacencyList<N> list) {
-      v.index = index;
-      v.lowlink = index;
-      index++;
-      stack.add(0, v);
-      List<Edge<N>> l = list.getAdjacent(v);
-      if (l != null) {
-        for (Edge<N> e : l) {
-          N n = e.to;
-          if (n.index == -1) {
-            tarjan(n, list);
-            v.lowlink = Math.min(v.lowlink, n.lowlink);
-          } else if (stack.contains(n)) {
-            v.lowlink = Math.min(v.lowlink, n.index);
-          }
-        }
-      }
-      if (v.lowlink == v.index) {
-        N n;
-        List<N> component = new LinkedList<N>();
-        do {
-          n = stack.remove(0);
-          component.add(n);
-        } while (n != v);
-        SCC.add(component);
-      }
-      return SCC;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/Node.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/Node.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/Node.java
deleted file mode 100644
index d446b3f..0000000
--- a/sandbox/prototype/common/src/main/java/org/apache/drill/common/logical/graph/Node.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * 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.common.logical.graph;
-
-
-public class Node<T> implements Comparable<Node<T>> {
-  final T nodeValue;
-  boolean visited = false; // used for Kosaraju's algorithm and Edmonds's
-                           // algorithm
-  int lowlink = -1; // used for Tarjan's algorithm
-  int index = -1; // used for Tarjan's algorithm
-
-  public Node(final T operator) {
-    if(operator == null) throw new IllegalArgumentException("Operator node was null.");
-    this.nodeValue = operator;
-  }
-
-  public int compareTo(final Node<T> argNode) {
-    // just do an identity compare since elsewhere you should ensure that only one node exists for each nodeValue.
-    return argNode == this ? 0 : -1;
-  }
-  
-  @Override
-  public int hashCode() {
-    return nodeValue.hashCode(); 
-  }
-
-  public T getNodeValue(){
-    return nodeValue;
-  }
-
-  @Override
-  public String toString() {
-    return "Node [val=" + nodeValue + "]";
-  }
-
-  
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/FieldSet.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/FieldSet.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/FieldSet.java
new file mode 100644
index 0000000..05fc49d
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/FieldSet.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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.common.physical;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+
+import org.apache.drill.common.physical.FieldSet.De;
+import org.apache.drill.common.physical.FieldSet.Se;
+
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import com.google.common.collect.Lists;
+
+@JsonSerialize(using = Se.class)
+@JsonDeserialize(using = De.class)
+public class FieldSet {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(FieldSet.class);
+  
+  private List<RecordField> incoming = Lists.newArrayList();
+  private List<RecordField> outgoing = Lists.newArrayList();
+  
+  public FieldSet(Iterable<RecordField> fields){
+    for(RecordField f : fields){
+      if(f.getRoute().isIn()){
+        incoming.add(f);
+      }
+      
+      if(f.getRoute().isOut()){
+        outgoing.add(f);
+      }
+    }
+  }
+  
+
+  public static class De extends StdDeserializer<FieldSet> {
+    
+    public De() {
+      super(FieldSet.class);
+    }
+
+    @Override
+    public FieldSet deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
+        JsonProcessingException {
+      Iterable<RecordField> fields = jp.readValueAs(new TypeReference<List<RecordField>>(){});
+      logger.debug("Fields {}", fields);
+      return new FieldSet(fields);
+    }
+
+  }
+
+  public static class Se extends StdSerializer<FieldSet> {
+
+    public Se() {
+      super(FieldSet.class);
+    }
+
+    @Override
+    public void serialize(FieldSet value, JsonGenerator jgen, SerializerProvider provider) throws IOException,
+        JsonGenerationException {
+      HashSet<RecordField> fields = new HashSet<RecordField>();
+      for(RecordField f: value.incoming){
+        fields.add(f);
+      }
+      for(RecordField f: value.outgoing){
+        fields.add(f);
+      }
+      jgen.writeObject(Lists.newArrayList(fields));
+    }
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/POPConfig.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/POPConfig.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/POPConfig.java
new file mode 100644
index 0000000..39a91f2
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/POPConfig.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.common.physical;
+
+public class POPConfig {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(POPConfig.class);
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/POPCost.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/POPCost.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/POPCost.java
new file mode 100644
index 0000000..b2ee440
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/POPCost.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.common.physical;
+
+public class POPCost {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(POPCost.class);
+  
+  long outputRecordCount;
+  long outputRecordSize;
+  
+  
+  public POPCost(long outputRecordCount, long outputRecordSize) {
+    super();
+    this.outputRecordCount = outputRecordCount;
+    this.outputRecordSize = outputRecordSize;
+  }
+
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/PhysicalPlan.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/PhysicalPlan.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/PhysicalPlan.java
new file mode 100644
index 0000000..0ef5164
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/PhysicalPlan.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * 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.common.physical;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.drill.common.PlanProperties;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.graph.Graph;
+import org.apache.drill.common.graph.GraphAlgos;
+import org.apache.drill.common.logical.StorageEngineConfig;
+import org.apache.drill.common.physical.pop.PhysicalOperator;
+import org.apache.drill.common.physical.pop.SinkPOP;
+import org.apache.drill.common.physical.pop.SourcePOP;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
+
+@JsonPropertyOrder({ "head", "storage", "graph" })
+public class PhysicalPlan {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PhysicalPlan.class);
+  
+  Map<String, StorageEngineConfig> storageEngines;
+  PlanProperties properties;
+  Graph<PhysicalOperator, SinkPOP, SourcePOP> graph;
+  
+  @JsonCreator
+  public PhysicalPlan(@JsonProperty("head") PlanProperties properties, @JsonProperty("storage") Map<String, StorageEngineConfig> storageEngines, @JsonProperty("graph") List<PhysicalOperator> operators){
+    this.storageEngines = storageEngines;
+    this.properties = properties;
+    this.graph = Graph.newGraph(operators, SinkPOP.class, SourcePOP.class);
+  }
+  
+  @JsonProperty("graph")
+  public List<PhysicalOperator> getSortedOperators(){
+    List<PhysicalOperator> list = GraphAlgos.TopoSorter.sort(graph);
+    // reverse the list so that nested references are flattened rather than nested.
+    return Lists.reverse(list);
+  }
+  
+  
+  @JsonProperty("storage")
+  public Map<String, StorageEngineConfig> getStorageEngines() {
+    return storageEngines;
+  }
+
+  @JsonProperty("head")
+  public PlanProperties getProperties() {
+    return properties;
+  }
+
+  /** Parses a physical plan. */
+  public static PhysicalPlan parse(DrillConfig config, String planString) {
+    ObjectMapper mapper = config.getMapper();
+    try {
+      PhysicalPlan plan = mapper.readValue(planString, PhysicalPlan.class);
+      return plan;
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  /** Converts a physical plan to a string. (Opposite of {@link #parse}.) */
+  public String unparse(DrillConfig config) {
+    try {
+      return config.getMapper().writeValueAsString(this);
+    } catch (JsonProcessingException e) {
+      throw new RuntimeException(e);
+    }
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/ReadEntry.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/ReadEntry.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/ReadEntry.java
new file mode 100644
index 0000000..47cfb5c
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/ReadEntry.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.common.physical;
+
+/** 
+ * Describes a chunk of read work that will be done.
+ */
+public interface ReadEntry {
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/RecordField.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/RecordField.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/RecordField.java
new file mode 100644
index 0000000..821f286
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/RecordField.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * 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.common.physical;
+
+import org.apache.drill.common.expression.types.DataType;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class RecordField {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(RecordField.class);
+
+  
+  private String name;
+  private DataType type;
+  private Route route;
+  
+  @JsonCreator
+  public RecordField(@JsonProperty("name") String name, @JsonProperty("type") DataType type, @JsonProperty("route") Route route) {
+    super();
+    this.name = name;
+    this.type = type;
+    this.route = route;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public DataType getType() {
+    return type;
+  }
+
+  public Route getRoute() {
+    return route;
+  }
+  
+  
+  
+  public static enum Route {
+    IN(true, false), 
+    OUT(false, true), 
+    THROUGH(true, true), 
+    OPAQUE(true, true);
+    
+    final boolean in;
+    final boolean out;
+    
+    Route(boolean in, boolean out){
+      this.in = in;
+      this.out = out;
+    }
+
+    public boolean isIn() {
+      return in;
+    }
+
+    public boolean isOut() {
+      return out;
+    }
+    
+  }  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/SetSpec.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/SetSpec.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/SetSpec.java
new file mode 100644
index 0000000..5250dbb
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/SetSpec.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.common.physical;
+
+import java.util.List;
+
+import org.apache.drill.common.expression.types.DataType;
+import org.apache.drill.common.physical.props.PhysicalProp;
+
+public class SetSpec {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SetSpec.class);
+
+  private List<Field> fields;
+  private List<PhysicalProp> traits;
+
+  public class Field {
+    public String name;
+    public DataType type;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/StitchDef.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/StitchDef.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/StitchDef.java
new file mode 100644
index 0000000..d9a7d33
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/StitchDef.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.common.physical;
+
+import org.apache.drill.common.expression.LogicalExpression;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class StitchDef {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(StitchDef.class);
+  
+  public static enum StitchMode {RANDOM, NWAY, BLOCK} 
+  
+  private StitchMode mode;
+  private LogicalExpression[] exprs;
+  
+  @JsonCreator 
+  public StitchDef(@JsonProperty("pattern") StitchMode mode, @JsonProperty("exprs") LogicalExpression[] exprs) {
+    super();
+    this.mode = mode;
+    this.exprs = exprs;
+  }
+
+  public StitchMode getMode() {
+    return mode;
+  }
+
+  public LogicalExpression[] getExprs() {
+    return exprs;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/ExchangePOP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/ExchangePOP.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/ExchangePOP.java
new file mode 100644
index 0000000..4c1f08a
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/ExchangePOP.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * 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.common.physical.pop;
+
+import java.util.Iterator;
+
+import org.apache.drill.common.defs.PartitionDef;
+import org.apache.drill.common.physical.FieldSet;
+import org.apache.drill.common.physical.StitchDef;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+
+@JsonTypeName("exchange")
+public class ExchangePOP extends SingleChildPOP{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ExchangePOP.class);
+  
+  private PartitionDef partition;
+  private StitchDef stitch;
+  
+  @JsonCreator
+  public ExchangePOP(@JsonProperty("fields") FieldSet fields, @JsonProperty("partition") PartitionDef partition, @JsonProperty("stitch") StitchDef stitch) {
+    super(fields);
+    this.partition = partition;
+    this.stitch = stitch;
+  }
+
+  
+  
+  public PartitionDef getPartition() {
+    return partition;
+  }
+
+  public StitchDef getStitch() {
+    return stitch;
+  }
+
+
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/POPBase.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/POPBase.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/POPBase.java
new file mode 100644
index 0000000..5d44e2a
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/POPBase.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * 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.common.physical.pop;
+
+import org.apache.drill.common.config.CommonConstants;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.graph.GraphVisitor;
+import org.apache.drill.common.physical.FieldSet;
+import org.apache.drill.common.physical.POPCost;
+import org.apache.drill.common.util.PathScanner;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public abstract class POPBase implements PhysicalOperator{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(POPBase.class);
+  
+  private FieldSet fieldSet;
+  
+  
+  public POPBase(FieldSet fieldSet){
+    this.fieldSet = fieldSet;
+  }
+  
+  public synchronized static Class<?>[] getSubTypes(DrillConfig config){
+    Class<?>[] ops = PathScanner.scanForImplementationsArr(PhysicalOperator.class, config.getStringList(CommonConstants.PHYSICAL_OPERATOR_SCAN_PACKAGES));
+    logger.debug("Adding Physical Operator sub types: {}", ((Object) ops) );
+    return ops;
+  }
+  
+  @JsonProperty("fields")
+  public FieldSet getFieldSet(){
+    return fieldSet;
+  }
+
+  @Override
+  public void accept(GraphVisitor<PhysicalOperator> visitor) {
+    visitor.enter(this);
+    if(this.iterator() == null) throw new IllegalArgumentException("Null iterator for pop." + this);
+    for(PhysicalOperator o : this){
+      o.accept(visitor);  
+    }
+    visitor.leave(this);
+  }
+
+  @Override
+  public POPCost getCost() {
+    return null;
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/PhysicalOperator.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/PhysicalOperator.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/PhysicalOperator.java
new file mode 100644
index 0000000..0a8927a
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/PhysicalOperator.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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.common.physical.pop;
+
+import org.apache.drill.common.graph.GraphValue;
+import org.apache.drill.common.physical.FieldSet;
+import org.apache.drill.common.physical.POPCost;
+
+import com.fasterxml.jackson.annotation.JsonIdentityInfo;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.ObjectIdGenerators;
+
+@JsonPropertyOrder({"@id"})
+@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property="pop")
+public interface PhysicalOperator extends GraphValue<PhysicalOperator>{
+  public FieldSet getFieldSet();
+  public POPCost getCost();
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/QuickNWaySortPOP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/QuickNWaySortPOP.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/QuickNWaySortPOP.java
new file mode 100644
index 0000000..f7fcdb0
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/QuickNWaySortPOP.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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.common.physical.pop;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.drill.common.defs.OrderDef;
+import org.apache.drill.common.physical.FieldSet;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+
+@JsonTypeName("quicknwaysort")
+public class QuickNWaySortPOP extends SingleChildPOP{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(QuickNWaySortPOP.class);
+  
+  private List<OrderDef> orderings;
+
+  @JsonCreator
+  public QuickNWaySortPOP(@JsonProperty("fields") FieldSet fieldSet, @JsonProperty("orderings") List<OrderDef> orderings) {
+    super(fieldSet);
+    this.orderings = orderings;
+  }
+
+  @JsonProperty("orderings")
+  public List<OrderDef> getOrderings() {
+    return orderings;
+  }
+
+
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/ScanPOP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/ScanPOP.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/ScanPOP.java
new file mode 100644
index 0000000..30cb2b0
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/ScanPOP.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * 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.common.physical.pop;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.drill.common.JSONOptions;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.physical.FieldSet;
+import org.apache.drill.common.physical.ReadEntry;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
+
+@JsonTypeName("scan")
+public class ScanPOP extends POPBase implements SourcePOP{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ScanPOP.class);
+  
+  private List<JSONOptions> readEntries;
+  private String storageEngine;
+  
+  @JsonCreator
+  public ScanPOP(@JsonProperty("storageengine") String storageEngine, @JsonProperty("entries") List<JSONOptions> readEntries, @JsonProperty("fields") FieldSet fieldSet) {
+    super(fieldSet);
+    this.storageEngine = storageEngine;
+    this.readEntries = readEntries;
+  }
+
+  @JsonProperty("entries")
+  public List<JSONOptions> getReadEntries() {
+    return readEntries;
+  }
+  
+  public <T extends ReadEntry> List<T> getReadEntries(DrillConfig config, Class<T> clazz){
+    List<T> e = Lists.newArrayList();
+    for(JSONOptions o : readEntries){
+      e.add(o.getWith(config,  clazz));
+    }
+    return e;
+  }
+
+  @Override
+  public Iterator<PhysicalOperator> iterator() {
+    return Iterators.emptyIterator();
+  }
+
+  public static org.slf4j.Logger getLogger() {
+    return logger;
+  }
+
+  @JsonProperty("storageengine")
+  public String getStorageEngine() {
+    return storageEngine;
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SingleChildPOP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SingleChildPOP.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SingleChildPOP.java
new file mode 100644
index 0000000..cf0c08b
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SingleChildPOP.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.common.physical.pop;
+
+import java.util.Iterator;
+
+import org.apache.drill.common.physical.FieldSet;
+
+import com.google.common.collect.Iterators;
+
+public abstract class SingleChildPOP extends POPBase{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SingleChildPOP.class);
+  
+  public PhysicalOperator child;
+
+  public SingleChildPOP(FieldSet fieldSet) {
+    super(fieldSet);
+  }
+
+  @Override
+  public Iterator<PhysicalOperator> iterator() {
+    return Iterators.singletonIterator(child);
+  }
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SinkPOP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SinkPOP.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SinkPOP.java
new file mode 100644
index 0000000..da0dcd6
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SinkPOP.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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.common.physical.pop;
+
+public interface SinkPOP extends PhysicalOperator{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SinkPOP.class);
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SourcePOP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SourcePOP.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SourcePOP.java
new file mode 100644
index 0000000..1b7c8e9
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/SourcePOP.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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.common.physical.pop;
+
+public interface SourcePOP extends PhysicalOperator{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SourcePOP.class);
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/StorePOP.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/StorePOP.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/StorePOP.java
new file mode 100644
index 0000000..2fbaa99
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/pop/StorePOP.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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.common.physical.pop;
+
+import java.util.List;
+
+import org.apache.drill.common.JSONOptions;
+import org.apache.drill.common.defs.PartitionDef;
+import org.apache.drill.common.physical.FieldSet;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+
+@JsonTypeName("store")
+public class StorePOP extends SingleChildPOP implements SinkPOP{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(StorePOP.class);
+
+  public static enum StoreMode {SYSTEM_CHOICE, PREDEFINED_PARTITIONS};
+  
+  private StoreMode mode;
+  private PartitionDef partitioning;
+  
+  @JsonCreator
+  public StorePOP(@JsonProperty("storageengine") String storageEngineName, @JsonProperty("fields") FieldSet fieldSet, @JsonProperty("mode") StoreMode mode, @JsonProperty("entries") List<JSONOptions> entries) {
+    super(fieldSet);
+  }
+
+  public StoreMode getMode() {
+    return mode;
+  }
+
+  public PartitionDef getPartitioning() {
+    return partitioning;
+  }
+
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/OrderProp.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/OrderProp.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/OrderProp.java
new file mode 100644
index 0000000..5e618e7
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/OrderProp.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.common.physical.props;
+
+import org.apache.drill.common.logical.defs.OrderDef;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+
+@JsonTypeName("ordered")
+public class OrderProp implements PhysicalProp{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(OrderProp.class);
+  
+  private final OrderDef[] orderings;
+
+  @JsonCreator
+  public OrderProp(@JsonProperty("fields") OrderDef[] orderings) {
+    super();
+    this.orderings = orderings;
+  }
+  
+  @JsonProperty("fields")
+  public OrderDef[] getOrderings(){
+    return orderings;
+  }
+  
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/PartitionProp.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/PartitionProp.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/PartitionProp.java
new file mode 100644
index 0000000..d855b73
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/PartitionProp.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.common.physical.props;
+
+import org.apache.drill.common.expression.LogicalExpression;
+import org.apache.drill.common.logical.defs.PartitionDef;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+
+@JsonTypeName("partitioned")
+public class PartitionProp extends PartitionDef implements PhysicalProp{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PartitionProp.class);
+
+  @JsonCreator
+  public PartitionProp(@JsonProperty("partitionType") PartitionType partitionType, @JsonProperty("exprs") LogicalExpression[] expressions, @JsonProperty("starts") LogicalExpression[] starts) {
+    super(partitionType, expressions, starts);
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/PhysicalProp.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/PhysicalProp.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/PhysicalProp.java
new file mode 100644
index 0000000..0776d66
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/PhysicalProp.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.common.physical.props;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property="trait")
+public interface PhysicalProp {
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/SegmentProp.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/SegmentProp.java b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/SegmentProp.java
new file mode 100644
index 0000000..d76fe48
--- /dev/null
+++ b/sandbox/prototype/common/src/main/java/org/apache/drill/common/physical/props/SegmentProp.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.common.physical.props;
+
+import org.apache.drill.common.expression.FieldReference;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+
+@JsonTypeName("segmented")
+public class SegmentProp implements PhysicalProp{
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SegmentProp.class);
+  
+  private FieldReference segments;
+
+  @JsonCreator
+  public SegmentProp(@JsonProperty("segments") FieldReference segments) {
+    super();
+    this.segments = segments;
+  }
+
+  public FieldReference getSegments() {
+    return segments;
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/main/resources/drill-default.conf
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/main/resources/drill-default.conf b/sandbox/prototype/common/src/main/resources/drill-default.conf
index 1b51bfd..760a6d2 100644
--- a/sandbox/prototype/common/src/main/resources/drill-default.conf
+++ b/sandbox/prototype/common/src/main/resources/drill-default.conf
@@ -1,6 +1,11 @@
-drill.logical: {
-  operator.packages: ["org.apache.drill.common.logical.data"],
-  expression.packages: ["org.apache.drill.common.expression"],
-  function.packages: ["org.apache.drill.common.expression"],
-  storage.packages: []
-}
\ No newline at end of file
+drill: {
+  logical: {
+    operator.packages: ["org.apache.drill.common.logical.data"],
+    expression.packages: ["org.apache.drill.common.expression"],
+    function.packages: ["org.apache.drill.common.expression"],
+    storage.packages: []
+  },
+  physical: {
+    operator.packages: ["org.apache.drill.common.physical.pop"]
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/test/java/org/apache/drill/ExpressionTest.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/test/java/org/apache/drill/ExpressionTest.java b/sandbox/prototype/common/src/test/java/org/apache/drill/ExpressionTest.java
deleted file mode 100644
index d0ce6fb..0000000
--- a/sandbox/prototype/common/src/test/java/org/apache/drill/ExpressionTest.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.apache.drill;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-public class ExpressionTest {
-  
-  @Test
-  public void do1(){
-    assertTrue(true);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/test/java/org/apache/drill/common/physical/ParsePhysicalPlan.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/test/java/org/apache/drill/common/physical/ParsePhysicalPlan.java b/sandbox/prototype/common/src/test/java/org/apache/drill/common/physical/ParsePhysicalPlan.java
new file mode 100644
index 0000000..9656823
--- /dev/null
+++ b/sandbox/prototype/common/src/test/java/org/apache/drill/common/physical/ParsePhysicalPlan.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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.common.physical;
+
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.util.FileUtils;
+import org.junit.Test;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+
+public class ParsePhysicalPlan {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ParsePhysicalPlan.class);
+  
+  
+  @Test 
+  public void parseSimplePlan() throws Exception{
+    DrillConfig c = DrillConfig.create();
+    PhysicalPlan plan = PhysicalPlan.parse(c, Files.toString(FileUtils.getResourceAsFile("/dsort-physical.json"), Charsets.UTF_8));
+    System.out.println(plan.unparse(c));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/test/java/org/apache/drill/storage/MockStorageEngineConfig.java
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/test/java/org/apache/drill/storage/MockStorageEngineConfig.java b/sandbox/prototype/common/src/test/java/org/apache/drill/storage/MockStorageEngineConfig.java
index 9f2d9cb..bc24b2e 100644
--- a/sandbox/prototype/common/src/test/java/org/apache/drill/storage/MockStorageEngineConfig.java
+++ b/sandbox/prototype/common/src/test/java/org/apache/drill/storage/MockStorageEngineConfig.java
@@ -31,8 +31,8 @@ public class MockStorageEngineConfig extends StorageEngineConfigBase{
   private String url;
   
   @JsonCreator
-  public MockStorageEngineConfig(@JsonProperty("name") String name, @JsonProperty("url") String url) {
-    super(name);
+  public MockStorageEngineConfig(@JsonProperty("url") String url) {
+    this.url = url;
   }
 
   public String getUrl() {

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/test/resources/dsort-physical.json
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/test/resources/dsort-physical.json b/sandbox/prototype/common/src/test/resources/dsort-physical.json
new file mode 100644
index 0000000..3c57a0a
--- /dev/null
+++ b/sandbox/prototype/common/src/test/resources/dsort-physical.json
@@ -0,0 +1,76 @@
+{
+    head:{
+        type:"APACHE_DRILL_PHYSICAL",
+        version:"1",
+        generator:{
+            type:"manual"
+        }
+    },
+    storage:{
+        fs1:{
+            type:"mock"
+        }
+    },
+    graph:[
+        {
+            @id:1,
+            pop:"scan",
+            storageengine:"fs1",
+            entries:[{}],
+            fields:[
+                { "name":"key", route: "OUT", type:"LATE"},
+                { "name":"value", route: "OUT", type:"LATE"}
+            ]
+        },
+        {
+            @id:2,
+            child: 1,
+            pop:"quicknwaysort",
+            orderings:[
+                {
+                    order: "DESC",
+                    expr: "data.key"
+                }
+            ],
+            fields:[
+                { "name":"key", route: "THROUGH", type:"LATE"},
+                { "name":"value", route: "OPAQUE", type:"LATE"}
+            ]
+
+        },
+        {
+            @id:3,
+            child: 2,
+            pop:"exchange",
+            partition:{
+                mode:"RANGE",
+                exprs:["key"]
+            },
+            stitch:{
+                mode:"RANDOM"
+            },
+            fields:[
+                { "name":"key", route: "THROUGH", type:"LATE"},
+                { "name":"value", route: "OPAQUE", type:"LATE"}
+            ]
+        },
+        {
+            @id:4,
+            child:3,
+            pop: "store",
+            mode: "SYSTEM_CHOICE",
+            storageengine: "fs1",
+            entries:[
+                {
+                    path:"/sort/sorted/${partition_number}.seq",
+                    key:"Text",
+                    type:"JAVA_SEQUENCE"
+                }
+            ],
+            fields:[
+                { "name":"key", route: "IN", type:"LATE"},
+                { "name":"value", route: "IN", type:"LATE"}
+            ] 
+        }           
+    ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/test/resources/example1.sql
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/test/resources/example1.sql b/sandbox/prototype/common/src/test/resources/example1.sql
deleted file mode 100644
index 8e4a413..0000000
--- a/sandbox/prototype/common/src/test/resources/example1.sql
+++ /dev/null
@@ -1,136 +0,0 @@
-
-// data: row per event, each row includes a user value and a day value.
-
-select 'day', count(distinct 'user') as cnt from events, group by day ;
-
-/* Logical Plan
-scan data 
-	group by day{
-		group by user{
-		}combine as user
-		transform 1 as userCnt
-		aggregate sum(userCnt) as cnt
-	}combine as day
-project day, cnt
-
-*/
-
-
-/* Physical Plan (simple)
-scan day, user
-hash_aggregate(day+user, 1 as cnt1)
-hash_aggregate(day, sum(cnt1) as cnt)
-*/
-
-
-/* Physical Plan (distributed-small)
-scan day, user
-streaming_aggregate(day+user, 1 as ignore, partition(day+user) )
-exchange()
-hash_aggregate(day+user, 1 as cnt1)
-streaming_aggregate(day, sum(cnt))
-exchange()
-hash_aggregate(day, sum(cnt))
-union_all()
-*/
-
-
-/* Physical Plan (distributed-large)
-scan day, user
-streaming_aggregate(day+user, 1 as ignore, partition(day+user) )
-exchange()
-hash_aggregate(day+user, 1 as cnt1)
-streaming_aggregate(day, sum(cnt), partition(day))
-exchange()
-hash_aggregate(day, sum(cnt))
-exchange()
-union_all()
-*/
-
-
-/* Physical Plan (distributed-large-rack-aware)
-scan day, user
-streaming_aggregate(day+user, 1 as ignore, rack-partition(day), partition(user))
-exchange()
-hash_aggregate(user, 1 as cnt1)
-streaming_aggregate(day, sum(cnt), partition(day))
-exchange()
-hash_aggregate(day, sum(cnt))
-exchange()
-union_all()
-*/
-
-
-
-
-### Goal
-For each day, what is the total number of unique visitors.
-
-### Data Source
-#### events table
-`record: { user: "1", interaction: "add to cart", datetime: "12/1/2011 3:45pm" }`
-
-
-### SQL Query
-<pre><code>
-SELECT 
-  CONVERT(date, e.datatime) AS 'day', 
-  COUNT(DISTINCT 'e.user') as cnt 
-  FROM events e
-  GROUP BY day 
-</code></pre>
-
-### Logical Query (pseudo)
-<pre><code>scan data 
-        transform convert(date, data.datetime) as day
-	group by day{
-		group by user{
-		}combine as user
-		transform 1 as userCnt
-		aggregate sum(userCnt) as cnt
-	}combine as day
-project day, cnt</code></pre>
-
-
-### Physical Query (pseudo)
-#### Simple
-<pre><code>scan convert(date, datetime) as day, user
-hash_aggregate(day+user, 1 as cnt1)
-hash_aggregate(day, sum(cnt1) as cnt)
-</code></pre>
-
-
-#### Physical Plan (distributed-small)
-<pre><code>scan convert(date, datetime) as day, user
-streaming_aggregate(day+user, 1 as ignore, partition(day+user) )
-exchange()
-hash_aggregate(day+user, 1 as cnt1)
-streaming_aggregate(day, sum(cnt))
-exchange()
-hash_aggregate(day, sum(cnt))
-union_all()
-</code></pre>
-
-#### Physical Plan (distributed-large)
-<pre><code>scan convert(date, datetime) as day, user
-streaming_aggregate(day+user, 1 as ignore, partition(day+user) )
-exchange()
-hash_aggregate(day+user, 1 as cnt1)
-streaming_aggregate(day, sum(cnt), partition(day))
-exchange()
-hash_aggregate(day, sum(cnt))
-exchange()
-union_all()
-</code></pre>
-
-####Physical Plan (distributed-large-rack-aware)
-<pre><code>scan convert(date, datetime) as day, user
-streaming_aggregate(day+user, 1 as ignore, rack-partition(day), partition(user))
-exchange()
-hash_aggregate(user, 1 as cnt1)
-streaming_aggregate(day, sum(cnt), partition(day))
-exchange()
-hash_aggregate(day, sum(cnt))
-exchange()
-union_all()
-</code></pre>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/test/resources/example2.sql
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/test/resources/example2.sql b/sandbox/prototype/common/src/test/resources/example2.sql
deleted file mode 100644
index 843ff62..0000000
--- a/sandbox/prototype/common/src/test/resources/example2.sql
+++ /dev/null
@@ -1,98 +0,0 @@
-// give me all users who have an out of state phone number.
-
-
-SELECT c.id, FLATTEN( LEFT(c.number, 3)) AS prefix 
-	FROM contacts c
-	JOIN areacodes a ON c.state != a.state AND c.prefix == a.prefix
-	GROUP BY c.id, c.state, count(1) as prefixCount
-	ORDER by c.id, c.state;
-
-	
-	
-	
-/*Logical
- * 
-
-scan contacts c
-	explode(c.number){
-	transform( left(c.number, 3), prefix)
-	}flatten(prefix)
-scan areacodes a
-join a,c, (c.state != a.state && c.prefix == a.prefix)
-group c.id, c.state{{
-		aggregate(count(1) as prefixCount)
-		}combine(c.state)
-	}combine(c.id)
-order(c.id, c.state)
-	
-	
-*/
-	
-/* 
-  
-  
-//Physical Simple 
-scan areacodes a, a.prefix, a.state
-scan contacts c, c.id, c.number
-materialize( LEFT(c.number, 3) as prefix)
-loop_join a,c on {conditions}
-hash_aggregate(c.id+c.state, count(1))
-
-
-// Physical distributed		
-scan areacodes a, a.prefix, a.state
-scan contacts c, c.id, c.number
-materialize( LEFT(c.number, 3) as prefix)
-partition(a, a.prefix)
-partition(c, c.prefix)
-loop_join
-	
-	
-/* Physical Plan (simple)
-scan day, user
-hash_aggregate(day+user, 1 as cnt1)
-hash_aggregate(day, sum(cnt1) as cnt)
-*/
-	
-	
-### Goal
-Generate a list of user ids who have at least one out of state phone number.
-
-### Data Source
-#### contacts table
-`record: { id: "1", number: [ "415-555-1212", "408-555-1212" ] }`
-
-#### areacode table
-
-`record: {prefix: "503", state: "OR" }`
-
-### Drill Query
-<pre><code>SELECT c.id, FLATTEN( LEFT(c.number, 3)) AS prefix 
-	FROM contacts c
-	JOIN areacodes a ON c.state != a.state AND c.prefix == a.prefix
-	GROUP BY c.id, c.state, count(1) as prefixCount
-	ORDER by c.id, c.state;
-</code></pre>
-
-### Logical Query (pseudo)
-<pre><code>scan contacts c
-	explode(c.number){
-	transform( left(c.number, 3), prefix)
-	}flatten(prefix)
-scan areacodes a
-join a,c, (c.state != a.state && c.prefix == a.prefix)
-group c.id, c.state{{
-		aggregate(count(1) as prefixCount)
-		}combine(c.state)
-	}combine(c.id)
-order(c.id, c.state)
-</code></pre>
-
-
-### Physical Query (pseudo)
-#### Simple
-scan areacodes a, a.prefix, a.state
-scan contacts c, c.id, c.number
-materialize( LEFT(c.number, 3) as prefix)
-loop_join a,c on {conditions}
-hash_aggregate(c.id+c.state, count(1))

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/test/resources/example3.sql
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/test/resources/example3.sql b/sandbox/prototype/common/src/test/resources/example3.sql
deleted file mode 100644
index 7022261..0000000
--- a/sandbox/prototype/common/src/test/resources/example3.sql
+++ /dev/null
@@ -1,3 +0,0 @@
-// Goal
-
-select user, 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2a6e1b33/sandbox/prototype/common/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/sandbox/prototype/common/src/test/resources/logback.xml b/sandbox/prototype/common/src/test/resources/logback.xml
index fbccc38..b79b811 100644
--- a/sandbox/prototype/common/src/test/resources/logback.xml
+++ b/sandbox/prototype/common/src/test/resources/logback.xml
@@ -16,31 +16,30 @@
     </encoder>
   </appender>
 
+<!-- 
   <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
     <file>/logs/test-common.log</file>
     <encoder>
       <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
     </encoder>
     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-	    <!-- daily rollover -->
 	    <fileNamePattern>/logs/test-common.%d{yyyy-MM-dd}.log</fileNamePattern>
-	    <!-- keep 30 days' worth of history -->
 	    <maxHistory>30</maxHistory>
     </rollingPolicy>
   </appender>
-  
+  --> 
   <logger name="org.apache.drill" additivity="false">
     <level value="debug" />
     <appender-ref ref="SOCKET" />
     <appender-ref ref="STDOUT" />
-    <appender-ref ref="FILE" />
+<!--     <appender-ref ref="FILE" /> -->
   </logger>
 
   <root>
     <level value="error" />
     <appender-ref ref="SOCKET" />
     <appender-ref ref="STDOUT" />
-    <appender-ref ref="FILE" />
+<!--     <appender-ref ref="FILE" /> -->
   </root>
 
 </configuration>
\ No newline at end of file