You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by pa...@apache.org on 2016/05/04 23:38:22 UTC

[1/4] drill git commit: DRILL-4132 Ability to submit simple type of physical plan directly to EndPoint DrillBit for execution. There are multiple changes to achieve this: 1. During physical planning split single plan into multiple based on the number of

Repository: drill
Updated Branches:
  refs/heads/master f07f32856 -> 6bba69d48


http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/java/org/apache/drill/exec/proto/beans/FragmentHandle.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/FragmentHandle.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/FragmentHandle.java
index 6d8a183..36cee7c 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/beans/FragmentHandle.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/FragmentHandle.java
@@ -50,6 +50,7 @@ public final class FragmentHandle implements Externalizable, Message<FragmentHan
     private QueryId queryId;
     private int majorFragmentId;
     private int minorFragmentId;
+    private QueryId parentQueryId;
 
     public FragmentHandle()
     {
@@ -97,6 +98,19 @@ public final class FragmentHandle implements Externalizable, Message<FragmentHan
         return this;
     }
 
+    // parentQueryId
+
+    public QueryId getParentQueryId()
+    {
+        return parentQueryId;
+    }
+
+    public FragmentHandle setParentQueryId(QueryId parentQueryId)
+    {
+        this.parentQueryId = parentQueryId;
+        return this;
+    }
+
     // java serialization
 
     public void readExternal(ObjectInput in) throws IOException
@@ -161,6 +175,10 @@ public final class FragmentHandle implements Externalizable, Message<FragmentHan
                 case 3:
                     message.minorFragmentId = input.readInt32();
                     break;
+                case 4:
+                    message.parentQueryId = input.mergeObject(message.parentQueryId, QueryId.getSchema());
+                    break;
+
                 default:
                     input.handleUnknownField(number, this);
             }   
@@ -179,6 +197,10 @@ public final class FragmentHandle implements Externalizable, Message<FragmentHan
 
         if(message.minorFragmentId != 0)
             output.writeInt32(3, message.minorFragmentId, false);
+
+        if(message.parentQueryId != null)
+             output.writeObject(4, message.parentQueryId, QueryId.getSchema(), false);
+
     }
 
     public String getFieldName(int number)
@@ -188,6 +210,7 @@ public final class FragmentHandle implements Externalizable, Message<FragmentHan
             case 1: return "queryId";
             case 2: return "majorFragmentId";
             case 3: return "minorFragmentId";
+            case 4: return "parentQueryId";
             default: return null;
         }
     }
@@ -204,6 +227,7 @@ public final class FragmentHandle implements Externalizable, Message<FragmentHan
         __fieldMap.put("queryId", 1);
         __fieldMap.put("majorFragmentId", 2);
         __fieldMap.put("minorFragmentId", 3);
+        __fieldMap.put("parentQueryId", 4);
     }
     
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetQueryPlanFragments.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetQueryPlanFragments.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetQueryPlanFragments.java
new file mode 100644
index 0000000..4c0109c
--- /dev/null
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetQueryPlanFragments.java
@@ -0,0 +1,218 @@
+/**
+ * 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.
+ */
+// Generated by http://code.google.com/p/protostuff/ ... DO NOT EDIT!
+// Generated from protobuf
+
+package org.apache.drill.exec.proto.beans;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import com.dyuproject.protostuff.GraphIOUtil;
+import com.dyuproject.protostuff.Input;
+import com.dyuproject.protostuff.Message;
+import com.dyuproject.protostuff.Output;
+import com.dyuproject.protostuff.Schema;
+import com.dyuproject.protostuff.UninitializedMessageException;
+
+public final class GetQueryPlanFragments implements Externalizable, Message<GetQueryPlanFragments>, Schema<GetQueryPlanFragments>
+{
+
+    public static Schema<GetQueryPlanFragments> getSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    public static GetQueryPlanFragments getDefaultInstance()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    static final GetQueryPlanFragments DEFAULT_INSTANCE = new GetQueryPlanFragments();
+
+    static final Boolean DEFAULT_SPLIT_PLAN = new Boolean(false);
+    
+    private String query;
+    private QueryType type;
+    private Boolean splitPlan = DEFAULT_SPLIT_PLAN;
+
+    public GetQueryPlanFragments()
+    {
+        
+    }
+
+    public GetQueryPlanFragments(
+        String query
+    )
+    {
+        this.query = query;
+    }
+
+    // getters and setters
+
+    // query
+
+    public String getQuery()
+    {
+        return query;
+    }
+
+    public GetQueryPlanFragments setQuery(String query)
+    {
+        this.query = query;
+        return this;
+    }
+
+    // type
+
+    public QueryType getType()
+    {
+        return type == null ? QueryType.SQL : type;
+    }
+
+    public GetQueryPlanFragments setType(QueryType type)
+    {
+        this.type = type;
+        return this;
+    }
+
+    // splitPlan
+
+    public Boolean getSplitPlan()
+    {
+        return splitPlan;
+    }
+
+    public GetQueryPlanFragments setSplitPlan(Boolean splitPlan)
+    {
+        this.splitPlan = splitPlan;
+        return this;
+    }
+
+    // java serialization
+
+    public void readExternal(ObjectInput in) throws IOException
+    {
+        GraphIOUtil.mergeDelimitedFrom(in, this, this);
+    }
+
+    public void writeExternal(ObjectOutput out) throws IOException
+    {
+        GraphIOUtil.writeDelimitedTo(out, this, this);
+    }
+
+    // message method
+
+    public Schema<GetQueryPlanFragments> cachedSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    // schema methods
+
+    public GetQueryPlanFragments newMessage()
+    {
+        return new GetQueryPlanFragments();
+    }
+
+    public Class<GetQueryPlanFragments> typeClass()
+    {
+        return GetQueryPlanFragments.class;
+    }
+
+    public String messageName()
+    {
+        return GetQueryPlanFragments.class.getSimpleName();
+    }
+
+    public String messageFullName()
+    {
+        return GetQueryPlanFragments.class.getName();
+    }
+
+    public boolean isInitialized(GetQueryPlanFragments message)
+    {
+        return 
+            message.query != null;
+    }
+
+    public void mergeFrom(Input input, GetQueryPlanFragments message) throws IOException
+    {
+        for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+        {
+            switch(number)
+            {
+                case 0:
+                    return;
+                case 1:
+                    message.query = input.readString();
+                    break;
+                case 2:
+                    message.type = QueryType.valueOf(input.readEnum());
+                    break;
+                case 3:
+                    message.splitPlan = input.readBool();
+                    break;
+                default:
+                    input.handleUnknownField(number, this);
+            }   
+        }
+    }
+
+
+    public void writeTo(Output output, GetQueryPlanFragments message) throws IOException
+    {
+        if(message.query == null)
+            throw new UninitializedMessageException(message);
+        output.writeString(1, message.query, false);
+
+        if(message.type != null)
+             output.writeEnum(2, message.type.number, false);
+
+        if(message.splitPlan != null && message.splitPlan != DEFAULT_SPLIT_PLAN)
+            output.writeBool(3, message.splitPlan, false);
+    }
+
+    public String getFieldName(int number)
+    {
+        switch(number)
+        {
+            case 1: return "query";
+            case 2: return "type";
+            case 3: return "splitPlan";
+            default: return null;
+        }
+    }
+
+    public int getFieldNumber(String name)
+    {
+        final Integer number = __fieldMap.get(name);
+        return number == null ? 0 : number.intValue();
+    }
+
+    private static final java.util.HashMap<String,Integer> __fieldMap = new java.util.HashMap<String,Integer>();
+    static
+    {
+        __fieldMap.put("query", 1);
+        __fieldMap.put("type", 2);
+        __fieldMap.put("splitPlan", 3);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/java/org/apache/drill/exec/proto/beans/QueryPlanFragments.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/QueryPlanFragments.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/QueryPlanFragments.java
new file mode 100644
index 0000000..c64baf8
--- /dev/null
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/QueryPlanFragments.java
@@ -0,0 +1,255 @@
+/**
+ * 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.
+ */
+// Generated by http://code.google.com/p/protostuff/ ... DO NOT EDIT!
+// Generated from protobuf
+
+package org.apache.drill.exec.proto.beans;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.dyuproject.protostuff.GraphIOUtil;
+import com.dyuproject.protostuff.Input;
+import com.dyuproject.protostuff.Message;
+import com.dyuproject.protostuff.Output;
+import com.dyuproject.protostuff.Schema;
+import com.dyuproject.protostuff.UninitializedMessageException;
+
+public final class QueryPlanFragments implements Externalizable, Message<QueryPlanFragments>, Schema<QueryPlanFragments>
+{
+
+    public static Schema<QueryPlanFragments> getSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    public static QueryPlanFragments getDefaultInstance()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    static final QueryPlanFragments DEFAULT_INSTANCE = new QueryPlanFragments();
+
+    
+    private QueryResult.QueryState status;
+    private QueryId queryId;
+    private List<PlanFragment> fragments;
+    private DrillPBError error;
+
+    public QueryPlanFragments()
+    {
+        
+    }
+
+    public QueryPlanFragments(
+        QueryResult.QueryState status
+    )
+    {
+        this.status = status;
+    }
+
+    // getters and setters
+
+    // status
+
+    public QueryResult.QueryState getStatus()
+    {
+        return status;
+    }
+
+    public QueryPlanFragments setStatus(QueryResult.QueryState status)
+    {
+        this.status = status;
+        return this;
+    }
+
+    // queryId
+
+    public QueryId getQueryId()
+    {
+        return queryId;
+    }
+
+    public QueryPlanFragments setQueryId(QueryId queryId)
+    {
+        this.queryId = queryId;
+        return this;
+    }
+
+    // fragments
+
+    public List<PlanFragment> getFragmentsList()
+    {
+        return fragments;
+    }
+
+    public QueryPlanFragments setFragmentsList(List<PlanFragment> fragments)
+    {
+        this.fragments = fragments;
+        return this;
+    }
+
+    // error
+
+    public DrillPBError getError()
+    {
+        return error;
+    }
+
+    public QueryPlanFragments setError(DrillPBError error)
+    {
+        this.error = error;
+        return this;
+    }
+
+    // java serialization
+
+    public void readExternal(ObjectInput in) throws IOException
+    {
+        GraphIOUtil.mergeDelimitedFrom(in, this, this);
+    }
+
+    public void writeExternal(ObjectOutput out) throws IOException
+    {
+        GraphIOUtil.writeDelimitedTo(out, this, this);
+    }
+
+    // message method
+
+    public Schema<QueryPlanFragments> cachedSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    // schema methods
+
+    public QueryPlanFragments newMessage()
+    {
+        return new QueryPlanFragments();
+    }
+
+    public Class<QueryPlanFragments> typeClass()
+    {
+        return QueryPlanFragments.class;
+    }
+
+    public String messageName()
+    {
+        return QueryPlanFragments.class.getSimpleName();
+    }
+
+    public String messageFullName()
+    {
+        return QueryPlanFragments.class.getName();
+    }
+
+    public boolean isInitialized(QueryPlanFragments message)
+    {
+        return 
+            message.status != null;
+    }
+
+    public void mergeFrom(Input input, QueryPlanFragments message) throws IOException
+    {
+        for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+        {
+            switch(number)
+            {
+                case 0:
+                    return;
+                case 1:
+                    message.status = QueryResult.QueryState.valueOf(input.readEnum());
+                    break;
+                case 2:
+                    message.queryId = input.mergeObject(message.queryId, QueryId.getSchema());
+                    break;
+
+                case 3:
+                    if(message.fragments == null)
+                        message.fragments = new ArrayList<PlanFragment>();
+                    message.fragments.add(input.mergeObject(null, PlanFragment.getSchema()));
+                    break;
+
+                case 4:
+                    message.error = input.mergeObject(message.error, DrillPBError.getSchema());
+                    break;
+
+                default:
+                    input.handleUnknownField(number, this);
+            }   
+        }
+    }
+
+
+    public void writeTo(Output output, QueryPlanFragments message) throws IOException
+    {
+        if(message.status == null)
+            throw new UninitializedMessageException(message);
+        output.writeEnum(1, message.status.number, false);
+
+        if(message.queryId != null)
+             output.writeObject(2, message.queryId, QueryId.getSchema(), false);
+
+
+        if(message.fragments != null)
+        {
+            for(PlanFragment fragments : message.fragments)
+            {
+                if(fragments != null)
+                    output.writeObject(3, fragments, PlanFragment.getSchema(), true);
+            }
+        }
+
+
+        if(message.error != null)
+             output.writeObject(4, message.error, DrillPBError.getSchema(), false);
+
+    }
+
+    public String getFieldName(int number)
+    {
+        switch(number)
+        {
+            case 1: return "status";
+            case 2: return "queryId";
+            case 3: return "fragments";
+            case 4: return "error";
+            default: return null;
+        }
+    }
+
+    public int getFieldNumber(String name)
+    {
+        final Integer number = __fieldMap.get(name);
+        return number == null ? 0 : number.intValue();
+    }
+
+    private static final java.util.HashMap<String,Integer> __fieldMap = new java.util.HashMap<String,Integer>();
+    static
+    {
+        __fieldMap.put("status", 1);
+        __fieldMap.put("queryId", 2);
+        __fieldMap.put("fragments", 3);
+        __fieldMap.put("error", 4);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/java/org/apache/drill/exec/proto/beans/QueryType.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/QueryType.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/QueryType.java
index 6c8f3c5..71f98f3 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/beans/QueryType.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/QueryType.java
@@ -24,7 +24,8 @@ public enum QueryType implements com.dyuproject.protostuff.EnumLite<QueryType>
 {
     SQL(1),
     LOGICAL(2),
-    PHYSICAL(3);
+    PHYSICAL(3),
+    EXECUTION(4);
     
     public final int number;
     
@@ -45,6 +46,7 @@ public enum QueryType implements com.dyuproject.protostuff.EnumLite<QueryType>
             case 1: return SQL;
             case 2: return LOGICAL;
             case 3: return PHYSICAL;
+            case 4: return EXECUTION;
             default: return null;
         }
     }

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/java/org/apache/drill/exec/proto/beans/RpcType.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/RpcType.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/RpcType.java
index 6687a86..5800183 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/beans/RpcType.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/RpcType.java
@@ -29,8 +29,10 @@ public enum RpcType implements com.dyuproject.protostuff.EnumLite<RpcType>
     CANCEL_QUERY(4),
     REQUEST_RESULTS(5),
     RESUME_PAUSED_QUERY(11),
+    GET_QUERY_PLAN_FRAGMENTS(12),
     QUERY_DATA(6),
     QUERY_HANDLE(7),
+    QUERY_PLAN_FRAGMENTS(13),
     REQ_META_FUNCTIONS(8),
     RESP_FUNCTION_LIST(9),
     QUERY_RESULT(10);
@@ -63,6 +65,8 @@ public enum RpcType implements com.dyuproject.protostuff.EnumLite<RpcType>
             case 9: return RESP_FUNCTION_LIST;
             case 10: return QUERY_RESULT;
             case 11: return RESUME_PAUSED_QUERY;
+            case 12: return GET_QUERY_PLAN_FRAGMENTS;
+            case 13: return QUERY_PLAN_FRAGMENTS;
             default: return null;
         }
     }

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/java/org/apache/drill/exec/proto/beans/RunQuery.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/RunQuery.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/RunQuery.java
index 2c3f0f5..e6035d1 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/beans/RunQuery.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/RunQuery.java
@@ -24,6 +24,8 @@ import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.List;
 
 import com.dyuproject.protostuff.GraphIOUtil;
 import com.dyuproject.protostuff.Input;
@@ -50,6 +52,7 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
     private QueryResultsMode resultsMode;
     private QueryType type;
     private String plan;
+    private List<PlanFragment> fragments;
 
     public RunQuery()
     {
@@ -97,6 +100,19 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
         return this;
     }
 
+    // fragments
+
+    public List<PlanFragment> getFragmentsList()
+    {
+        return fragments;
+    }
+
+    public RunQuery setFragmentsList(List<PlanFragment> fragments)
+    {
+        this.fragments = fragments;
+        return this;
+    }
+
     // java serialization
 
     public void readExternal(ObjectInput in) throws IOException
@@ -160,6 +176,12 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
                 case 3:
                     message.plan = input.readString();
                     break;
+                case 4:
+                    if(message.fragments == null)
+                        message.fragments = new ArrayList<PlanFragment>();
+                    message.fragments.add(input.mergeObject(null, PlanFragment.getSchema()));
+                    break;
+
                 default:
                     input.handleUnknownField(number, this);
             }   
@@ -177,6 +199,16 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
 
         if(message.plan != null)
             output.writeString(3, message.plan, false);
+
+        if(message.fragments != null)
+        {
+            for(PlanFragment fragments : message.fragments)
+            {
+                if(fragments != null)
+                    output.writeObject(4, fragments, PlanFragment.getSchema(), true);
+            }
+        }
+
     }
 
     public String getFieldName(int number)
@@ -186,6 +218,7 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
             case 1: return "resultsMode";
             case 2: return "type";
             case 3: return "plan";
+            case 4: return "fragments";
             default: return null;
         }
     }
@@ -202,6 +235,7 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
         __fieldMap.put("resultsMode", 1);
         __fieldMap.put("type", 2);
         __fieldMap.put("plan", 3);
+        __fieldMap.put("fragments", 4);
     }
     
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/protobuf/ExecutionProtos.proto
----------------------------------------------------------------------
diff --git a/protocol/src/main/protobuf/ExecutionProtos.proto b/protocol/src/main/protobuf/ExecutionProtos.proto
index 8ad8c47..36cd12b 100644
--- a/protocol/src/main/protobuf/ExecutionProtos.proto
+++ b/protocol/src/main/protobuf/ExecutionProtos.proto
@@ -11,5 +11,6 @@ message FragmentHandle {
 	optional exec.shared.QueryId query_id = 1;
 	optional int32 major_fragment_id = 2;
 	optional int32 minor_fragment_id = 3;
+	optional exec.shared.QueryId parent_query_id = 4;
 }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/protobuf/User.proto
----------------------------------------------------------------------
diff --git a/protocol/src/main/protobuf/User.proto b/protocol/src/main/protobuf/User.proto
index ceed3d8..da44955 100644
--- a/protocol/src/main/protobuf/User.proto
+++ b/protocol/src/main/protobuf/User.proto
@@ -6,6 +6,10 @@ option optimize_for = SPEED;
 
 import "SchemaDef.proto";
 import "UserBitShared.proto";
+import "BitData.proto";
+import "BitControl.proto";
+import "ExecutionProtos.proto";
+
 
 ////// UserToBit RPC ///////
 enum RpcType {
@@ -18,10 +22,12 @@ enum RpcType {
   CANCEL_QUERY = 4; // user is sending a query cancellation request to the drillbit
   REQUEST_RESULTS = 5;
   RESUME_PAUSED_QUERY = 11; // user is sending a query resume request to the drillbit
+  GET_QUERY_PLAN_FRAGMENTS = 12; // to get plan fragments from query
 
   // bit to user
   QUERY_DATA = 6; // drillbit is sending a query result data batch to the user
   QUERY_HANDLE = 7;
+  QUERY_PLAN_FRAGMENTS = 13; // return plan fragments 
 
   REQ_META_FUNCTIONS = 8;
   RESP_FUNCTION_LIST = 9;
@@ -57,6 +63,20 @@ message RunQuery {
   optional QueryResultsMode results_mode = 1;
   optional exec.shared.QueryType type = 2;
   optional string plan = 3;
+  repeated exec.bit.control.PlanFragment fragments = 4;
+}
+
+message GetQueryPlanFragments {
+  required string query = 1;
+  optional exec.shared.QueryType type = 2;
+  optional bool split_plan = 3 [default = false];
+}
+
+message QueryPlanFragments {
+  required exec.shared.QueryResult.QueryState status = 1;
+  optional exec.shared.QueryId query_id = 2;
+  repeated exec.bit.control.PlanFragment fragments = 3;
+  optional exec.shared.DrillPBError error = 4;
 }
 
 enum QueryResultsMode {

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/protobuf/UserBitShared.proto
----------------------------------------------------------------------
diff --git a/protocol/src/main/protobuf/UserBitShared.proto b/protocol/src/main/protobuf/UserBitShared.proto
index c44d2b2..2293dc0 100644
--- a/protocol/src/main/protobuf/UserBitShared.proto
+++ b/protocol/src/main/protobuf/UserBitShared.proto
@@ -18,6 +18,7 @@ enum QueryType {
   SQL = 1;
   LOGICAL = 2;
   PHYSICAL = 3;
+  EXECUTION = 4;
 }
 
 message UserCredentials {


[2/4] drill git commit: DRILL-4132 Ability to submit simple type of physical plan directly to EndPoint DrillBit for execution. There are multiple changes to achieve this: 1. During physical planning split single plan into multiple based on the number of

Posted by pa...@apache.org.
http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/java/org/apache/drill/exec/proto/UserProtos.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/UserProtos.java b/protocol/src/main/java/org/apache/drill/exec/proto/UserProtos.java
index afe8bfe..60ddc77 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/UserProtos.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/UserProtos.java
@@ -75,25 +75,41 @@ public final class UserProtos {
      */
     RESUME_PAUSED_QUERY(6, 11),
     /**
+     * <code>GET_QUERY_PLAN_FRAGMENTS = 12;</code>
+     *
+     * <pre>
+     * to get plan fragments from query
+     * </pre>
+     */
+    GET_QUERY_PLAN_FRAGMENTS(7, 12),
+    /**
      * <code>QUERY_DATA = 6;</code>
      *
      * <pre>
      * bit to user
      * </pre>
      */
-    QUERY_DATA(7, 6),
+    QUERY_DATA(8, 6),
     /**
      * <code>QUERY_HANDLE = 7;</code>
      */
-    QUERY_HANDLE(8, 7),
+    QUERY_HANDLE(9, 7),
+    /**
+     * <code>QUERY_PLAN_FRAGMENTS = 13;</code>
+     *
+     * <pre>
+     * return plan fragments 
+     * </pre>
+     */
+    QUERY_PLAN_FRAGMENTS(10, 13),
     /**
      * <code>REQ_META_FUNCTIONS = 8;</code>
      */
-    REQ_META_FUNCTIONS(9, 8),
+    REQ_META_FUNCTIONS(11, 8),
     /**
      * <code>RESP_FUNCTION_LIST = 9;</code>
      */
-    RESP_FUNCTION_LIST(10, 9),
+    RESP_FUNCTION_LIST(12, 9),
     /**
      * <code>QUERY_RESULT = 10;</code>
      *
@@ -101,7 +117,7 @@ public final class UserProtos {
      * drillbit is reporting a query status change, most likely a terminal message, to the user
      * </pre>
      */
-    QUERY_RESULT(11, 10),
+    QUERY_RESULT(13, 10),
     ;
 
     /**
@@ -145,6 +161,14 @@ public final class UserProtos {
      */
     public static final int RESUME_PAUSED_QUERY_VALUE = 11;
     /**
+     * <code>GET_QUERY_PLAN_FRAGMENTS = 12;</code>
+     *
+     * <pre>
+     * to get plan fragments from query
+     * </pre>
+     */
+    public static final int GET_QUERY_PLAN_FRAGMENTS_VALUE = 12;
+    /**
      * <code>QUERY_DATA = 6;</code>
      *
      * <pre>
@@ -157,6 +181,14 @@ public final class UserProtos {
      */
     public static final int QUERY_HANDLE_VALUE = 7;
     /**
+     * <code>QUERY_PLAN_FRAGMENTS = 13;</code>
+     *
+     * <pre>
+     * return plan fragments 
+     * </pre>
+     */
+    public static final int QUERY_PLAN_FRAGMENTS_VALUE = 13;
+    /**
      * <code>REQ_META_FUNCTIONS = 8;</code>
      */
     public static final int REQ_META_FUNCTIONS_VALUE = 8;
@@ -185,8 +217,10 @@ public final class UserProtos {
         case 4: return CANCEL_QUERY;
         case 5: return REQUEST_RESULTS;
         case 11: return RESUME_PAUSED_QUERY;
+        case 12: return GET_QUERY_PLAN_FRAGMENTS;
         case 6: return QUERY_DATA;
         case 7: return QUERY_HANDLE;
+        case 13: return QUERY_PLAN_FRAGMENTS;
         case 8: return REQ_META_FUNCTIONS;
         case 9: return RESP_FUNCTION_LIST;
         case 10: return QUERY_RESULT;
@@ -3533,6 +3567,31 @@ public final class UserProtos {
      */
     com.google.protobuf.ByteString
         getPlanBytes();
+
+    // repeated .exec.bit.control.PlanFragment fragments = 4;
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     */
+    java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> 
+        getFragmentsList();
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     */
+    org.apache.drill.exec.proto.BitControl.PlanFragment getFragments(int index);
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     */
+    int getFragmentsCount();
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     */
+    java.util.List<? extends org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> 
+        getFragmentsOrBuilderList();
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     */
+    org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder getFragmentsOrBuilder(
+        int index);
   }
   /**
    * Protobuf type {@code exec.user.RunQuery}
@@ -3612,6 +3671,14 @@ public final class UserProtos {
               plan_ = input.readBytes();
               break;
             }
+            case 34: {
+              if (!((mutable_bitField0_ & 0x00000008) == 0x00000008)) {
+                fragments_ = new java.util.ArrayList<org.apache.drill.exec.proto.BitControl.PlanFragment>();
+                mutable_bitField0_ |= 0x00000008;
+              }
+              fragments_.add(input.readMessage(org.apache.drill.exec.proto.BitControl.PlanFragment.PARSER, extensionRegistry));
+              break;
+            }
           }
         }
       } catch (com.google.protobuf.InvalidProtocolBufferException e) {
@@ -3620,6 +3687,9 @@ public final class UserProtos {
         throw new com.google.protobuf.InvalidProtocolBufferException(
             e.getMessage()).setUnfinishedMessage(this);
       } finally {
+        if (((mutable_bitField0_ & 0x00000008) == 0x00000008)) {
+          fragments_ = java.util.Collections.unmodifiableList(fragments_);
+        }
         this.unknownFields = unknownFields.build();
         makeExtensionsImmutable();
       }
@@ -3727,10 +3797,47 @@ public final class UserProtos {
       }
     }
 
+    // repeated .exec.bit.control.PlanFragment fragments = 4;
+    public static final int FRAGMENTS_FIELD_NUMBER = 4;
+    private java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> fragments_;
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     */
+    public java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> getFragmentsList() {
+      return fragments_;
+    }
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     */
+    public java.util.List<? extends org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> 
+        getFragmentsOrBuilderList() {
+      return fragments_;
+    }
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     */
+    public int getFragmentsCount() {
+      return fragments_.size();
+    }
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     */
+    public org.apache.drill.exec.proto.BitControl.PlanFragment getFragments(int index) {
+      return fragments_.get(index);
+    }
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     */
+    public org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder getFragmentsOrBuilder(
+        int index) {
+      return fragments_.get(index);
+    }
+
     private void initFields() {
       resultsMode_ = org.apache.drill.exec.proto.UserProtos.QueryResultsMode.STREAM_FULL;
       type_ = org.apache.drill.exec.proto.UserBitShared.QueryType.SQL;
       plan_ = "";
+      fragments_ = java.util.Collections.emptyList();
     }
     private byte memoizedIsInitialized = -1;
     public final boolean isInitialized() {
@@ -3753,6 +3860,9 @@ public final class UserProtos {
       if (((bitField0_ & 0x00000004) == 0x00000004)) {
         output.writeBytes(3, getPlanBytes());
       }
+      for (int i = 0; i < fragments_.size(); i++) {
+        output.writeMessage(4, fragments_.get(i));
+      }
       getUnknownFields().writeTo(output);
     }
 
@@ -3774,6 +3884,10 @@ public final class UserProtos {
         size += com.google.protobuf.CodedOutputStream
           .computeBytesSize(3, getPlanBytes());
       }
+      for (int i = 0; i < fragments_.size(); i++) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeMessageSize(4, fragments_.get(i));
+      }
       size += getUnknownFields().getSerializedSize();
       memoizedSerializedSize = size;
       return size;
@@ -3882,6 +3996,7 @@ public final class UserProtos {
       }
       private void maybeForceBuilderInitialization() {
         if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+          getFragmentsFieldBuilder();
         }
       }
       private static Builder create() {
@@ -3896,6 +4011,12 @@ public final class UserProtos {
         bitField0_ = (bitField0_ & ~0x00000002);
         plan_ = "";
         bitField0_ = (bitField0_ & ~0x00000004);
+        if (fragmentsBuilder_ == null) {
+          fragments_ = java.util.Collections.emptyList();
+          bitField0_ = (bitField0_ & ~0x00000008);
+        } else {
+          fragmentsBuilder_.clear();
+        }
         return this;
       }
 
@@ -3936,6 +4057,15 @@ public final class UserProtos {
           to_bitField0_ |= 0x00000004;
         }
         result.plan_ = plan_;
+        if (fragmentsBuilder_ == null) {
+          if (((bitField0_ & 0x00000008) == 0x00000008)) {
+            fragments_ = java.util.Collections.unmodifiableList(fragments_);
+            bitField0_ = (bitField0_ & ~0x00000008);
+          }
+          result.fragments_ = fragments_;
+        } else {
+          result.fragments_ = fragmentsBuilder_.build();
+        }
         result.bitField0_ = to_bitField0_;
         onBuilt();
         return result;
@@ -3963,6 +4093,32 @@ public final class UserProtos {
           plan_ = other.plan_;
           onChanged();
         }
+        if (fragmentsBuilder_ == null) {
+          if (!other.fragments_.isEmpty()) {
+            if (fragments_.isEmpty()) {
+              fragments_ = other.fragments_;
+              bitField0_ = (bitField0_ & ~0x00000008);
+            } else {
+              ensureFragmentsIsMutable();
+              fragments_.addAll(other.fragments_);
+            }
+            onChanged();
+          }
+        } else {
+          if (!other.fragments_.isEmpty()) {
+            if (fragmentsBuilder_.isEmpty()) {
+              fragmentsBuilder_.dispose();
+              fragmentsBuilder_ = null;
+              fragments_ = other.fragments_;
+              bitField0_ = (bitField0_ & ~0x00000008);
+              fragmentsBuilder_ = 
+                com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ?
+                   getFragmentsFieldBuilder() : null;
+            } else {
+              fragmentsBuilder_.addAllMessages(other.fragments_);
+            }
+          }
+        }
         this.mergeUnknownFields(other.getUnknownFields());
         return this;
       }
@@ -4136,6 +4292,246 @@ public final class UserProtos {
         return this;
       }
 
+      // repeated .exec.bit.control.PlanFragment fragments = 4;
+      private java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> fragments_ =
+        java.util.Collections.emptyList();
+      private void ensureFragmentsIsMutable() {
+        if (!((bitField0_ & 0x00000008) == 0x00000008)) {
+          fragments_ = new java.util.ArrayList<org.apache.drill.exec.proto.BitControl.PlanFragment>(fragments_);
+          bitField0_ |= 0x00000008;
+         }
+      }
+
+      private com.google.protobuf.RepeatedFieldBuilder<
+          org.apache.drill.exec.proto.BitControl.PlanFragment, org.apache.drill.exec.proto.BitControl.PlanFragment.Builder, org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> fragmentsBuilder_;
+
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> getFragmentsList() {
+        if (fragmentsBuilder_ == null) {
+          return java.util.Collections.unmodifiableList(fragments_);
+        } else {
+          return fragmentsBuilder_.getMessageList();
+        }
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public int getFragmentsCount() {
+        if (fragmentsBuilder_ == null) {
+          return fragments_.size();
+        } else {
+          return fragmentsBuilder_.getCount();
+        }
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public org.apache.drill.exec.proto.BitControl.PlanFragment getFragments(int index) {
+        if (fragmentsBuilder_ == null) {
+          return fragments_.get(index);
+        } else {
+          return fragmentsBuilder_.getMessage(index);
+        }
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public Builder setFragments(
+          int index, org.apache.drill.exec.proto.BitControl.PlanFragment value) {
+        if (fragmentsBuilder_ == null) {
+          if (value == null) {
+            throw new NullPointerException();
+          }
+          ensureFragmentsIsMutable();
+          fragments_.set(index, value);
+          onChanged();
+        } else {
+          fragmentsBuilder_.setMessage(index, value);
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public Builder setFragments(
+          int index, org.apache.drill.exec.proto.BitControl.PlanFragment.Builder builderForValue) {
+        if (fragmentsBuilder_ == null) {
+          ensureFragmentsIsMutable();
+          fragments_.set(index, builderForValue.build());
+          onChanged();
+        } else {
+          fragmentsBuilder_.setMessage(index, builderForValue.build());
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public Builder addFragments(org.apache.drill.exec.proto.BitControl.PlanFragment value) {
+        if (fragmentsBuilder_ == null) {
+          if (value == null) {
+            throw new NullPointerException();
+          }
+          ensureFragmentsIsMutable();
+          fragments_.add(value);
+          onChanged();
+        } else {
+          fragmentsBuilder_.addMessage(value);
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public Builder addFragments(
+          int index, org.apache.drill.exec.proto.BitControl.PlanFragment value) {
+        if (fragmentsBuilder_ == null) {
+          if (value == null) {
+            throw new NullPointerException();
+          }
+          ensureFragmentsIsMutable();
+          fragments_.add(index, value);
+          onChanged();
+        } else {
+          fragmentsBuilder_.addMessage(index, value);
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public Builder addFragments(
+          org.apache.drill.exec.proto.BitControl.PlanFragment.Builder builderForValue) {
+        if (fragmentsBuilder_ == null) {
+          ensureFragmentsIsMutable();
+          fragments_.add(builderForValue.build());
+          onChanged();
+        } else {
+          fragmentsBuilder_.addMessage(builderForValue.build());
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public Builder addFragments(
+          int index, org.apache.drill.exec.proto.BitControl.PlanFragment.Builder builderForValue) {
+        if (fragmentsBuilder_ == null) {
+          ensureFragmentsIsMutable();
+          fragments_.add(index, builderForValue.build());
+          onChanged();
+        } else {
+          fragmentsBuilder_.addMessage(index, builderForValue.build());
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public Builder addAllFragments(
+          java.lang.Iterable<? extends org.apache.drill.exec.proto.BitControl.PlanFragment> values) {
+        if (fragmentsBuilder_ == null) {
+          ensureFragmentsIsMutable();
+          super.addAll(values, fragments_);
+          onChanged();
+        } else {
+          fragmentsBuilder_.addAllMessages(values);
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public Builder clearFragments() {
+        if (fragmentsBuilder_ == null) {
+          fragments_ = java.util.Collections.emptyList();
+          bitField0_ = (bitField0_ & ~0x00000008);
+          onChanged();
+        } else {
+          fragmentsBuilder_.clear();
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public Builder removeFragments(int index) {
+        if (fragmentsBuilder_ == null) {
+          ensureFragmentsIsMutable();
+          fragments_.remove(index);
+          onChanged();
+        } else {
+          fragmentsBuilder_.remove(index);
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public org.apache.drill.exec.proto.BitControl.PlanFragment.Builder getFragmentsBuilder(
+          int index) {
+        return getFragmentsFieldBuilder().getBuilder(index);
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder getFragmentsOrBuilder(
+          int index) {
+        if (fragmentsBuilder_ == null) {
+          return fragments_.get(index);  } else {
+          return fragmentsBuilder_.getMessageOrBuilder(index);
+        }
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public java.util.List<? extends org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> 
+           getFragmentsOrBuilderList() {
+        if (fragmentsBuilder_ != null) {
+          return fragmentsBuilder_.getMessageOrBuilderList();
+        } else {
+          return java.util.Collections.unmodifiableList(fragments_);
+        }
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public org.apache.drill.exec.proto.BitControl.PlanFragment.Builder addFragmentsBuilder() {
+        return getFragmentsFieldBuilder().addBuilder(
+            org.apache.drill.exec.proto.BitControl.PlanFragment.getDefaultInstance());
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public org.apache.drill.exec.proto.BitControl.PlanFragment.Builder addFragmentsBuilder(
+          int index) {
+        return getFragmentsFieldBuilder().addBuilder(
+            index, org.apache.drill.exec.proto.BitControl.PlanFragment.getDefaultInstance());
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+       */
+      public java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment.Builder> 
+           getFragmentsBuilderList() {
+        return getFragmentsFieldBuilder().getBuilderList();
+      }
+      private com.google.protobuf.RepeatedFieldBuilder<
+          org.apache.drill.exec.proto.BitControl.PlanFragment, org.apache.drill.exec.proto.BitControl.PlanFragment.Builder, org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> 
+          getFragmentsFieldBuilder() {
+        if (fragmentsBuilder_ == null) {
+          fragmentsBuilder_ = new com.google.protobuf.RepeatedFieldBuilder<
+              org.apache.drill.exec.proto.BitControl.PlanFragment, org.apache.drill.exec.proto.BitControl.PlanFragment.Builder, org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder>(
+                  fragments_,
+                  ((bitField0_ & 0x00000008) == 0x00000008),
+                  getParentForChildren(),
+                  isClean());
+          fragments_ = null;
+        }
+        return fragmentsBuilder_;
+      }
+
       // @@protoc_insertion_point(builder_scope:exec.user.RunQuery)
     }
 
@@ -4147,78 +4543,63 @@ public final class UserProtos {
     // @@protoc_insertion_point(class_scope:exec.user.RunQuery)
   }
 
-  public interface BitToUserHandshakeOrBuilder
+  public interface GetQueryPlanFragmentsOrBuilder
       extends com.google.protobuf.MessageOrBuilder {
 
-    // optional int32 rpc_version = 2;
-    /**
-     * <code>optional int32 rpc_version = 2;</code>
-     */
-    boolean hasRpcVersion();
+    // required string query = 1;
     /**
-     * <code>optional int32 rpc_version = 2;</code>
+     * <code>required string query = 1;</code>
      */
-    int getRpcVersion();
-
-    // optional .exec.user.HandshakeStatus status = 3;
+    boolean hasQuery();
     /**
-     * <code>optional .exec.user.HandshakeStatus status = 3;</code>
+     * <code>required string query = 1;</code>
      */
-    boolean hasStatus();
+    java.lang.String getQuery();
     /**
-     * <code>optional .exec.user.HandshakeStatus status = 3;</code>
+     * <code>required string query = 1;</code>
      */
-    org.apache.drill.exec.proto.UserProtos.HandshakeStatus getStatus();
+    com.google.protobuf.ByteString
+        getQueryBytes();
 
-    // optional string errorId = 4;
-    /**
-     * <code>optional string errorId = 4;</code>
-     */
-    boolean hasErrorId();
+    // optional .exec.shared.QueryType type = 2;
     /**
-     * <code>optional string errorId = 4;</code>
+     * <code>optional .exec.shared.QueryType type = 2;</code>
      */
-    java.lang.String getErrorId();
+    boolean hasType();
     /**
-     * <code>optional string errorId = 4;</code>
+     * <code>optional .exec.shared.QueryType type = 2;</code>
      */
-    com.google.protobuf.ByteString
-        getErrorIdBytes();
+    org.apache.drill.exec.proto.UserBitShared.QueryType getType();
 
-    // optional string errorMessage = 5;
-    /**
-     * <code>optional string errorMessage = 5;</code>
-     */
-    boolean hasErrorMessage();
+    // optional bool split_plan = 3 [default = false];
     /**
-     * <code>optional string errorMessage = 5;</code>
+     * <code>optional bool split_plan = 3 [default = false];</code>
      */
-    java.lang.String getErrorMessage();
+    boolean hasSplitPlan();
     /**
-     * <code>optional string errorMessage = 5;</code>
+     * <code>optional bool split_plan = 3 [default = false];</code>
      */
-    com.google.protobuf.ByteString
-        getErrorMessageBytes();
+    boolean getSplitPlan();
   }
   /**
-   * Protobuf type {@code exec.user.BitToUserHandshake}
+   * Protobuf type {@code exec.user.GetQueryPlanFragments}
    */
-  public static final class BitToUserHandshake extends
+  public static final class GetQueryPlanFragments extends
       com.google.protobuf.GeneratedMessage
-      implements BitToUserHandshakeOrBuilder {
-    // Use BitToUserHandshake.newBuilder() to construct.
-    private BitToUserHandshake(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
+      implements GetQueryPlanFragmentsOrBuilder {
+    // Use GetQueryPlanFragments.newBuilder() to construct.
+    private GetQueryPlanFragments(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
       super(builder);
       this.unknownFields = builder.getUnknownFields();
     }
-    private BitToUserHandshake(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
+    private GetQueryPlanFragments(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
 
-    private static final BitToUserHandshake defaultInstance;
-    public static BitToUserHandshake getDefaultInstance() {
+    private static final GetQueryPlanFragments defaultInstance;
+    public static GetQueryPlanFragments getDefaultInstance() {
       return defaultInstance;
     }
 
-    public BitToUserHandshake getDefaultInstanceForType() {
+    public GetQueryPlanFragments getDefaultInstanceForType() {
       return defaultInstance;
     }
 
@@ -4228,7 +4609,7 @@ public final class UserProtos {
         getUnknownFields() {
       return this.unknownFields;
     }
-    private BitToUserHandshake(
+    private GetQueryPlanFragments(
         com.google.protobuf.CodedInputStream input,
         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
         throws com.google.protobuf.InvalidProtocolBufferException {
@@ -4251,19 +4632,1843 @@ public final class UserProtos {
               }
               break;
             }
-            case 16: {
+            case 10: {
               bitField0_ |= 0x00000001;
-              rpcVersion_ = input.readInt32();
+              query_ = input.readBytes();
               break;
             }
-            case 24: {
+            case 16: {
               int rawValue = input.readEnum();
-              org.apache.drill.exec.proto.UserProtos.HandshakeStatus value = org.apache.drill.exec.proto.UserProtos.HandshakeStatus.valueOf(rawValue);
+              org.apache.drill.exec.proto.UserBitShared.QueryType value = org.apache.drill.exec.proto.UserBitShared.QueryType.valueOf(rawValue);
               if (value == null) {
-                unknownFields.mergeVarintField(3, rawValue);
+                unknownFields.mergeVarintField(2, rawValue);
               } else {
                 bitField0_ |= 0x00000002;
-                status_ = value;
+                type_ = value;
+              }
+              break;
+            }
+            case 24: {
+              bitField0_ |= 0x00000004;
+              splitPlan_ = input.readBool();
+              break;
+            }
+          }
+        }
+      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+        throw e.setUnfinishedMessage(this);
+      } catch (java.io.IOException e) {
+        throw new com.google.protobuf.InvalidProtocolBufferException(
+            e.getMessage()).setUnfinishedMessage(this);
+      } finally {
+        this.unknownFields = unknownFields.build();
+        makeExtensionsImmutable();
+      }
+    }
+    public static final com.google.protobuf.Descriptors.Descriptor
+        getDescriptor() {
+      return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_GetQueryPlanFragments_descriptor;
+    }
+
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+        internalGetFieldAccessorTable() {
+      return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_GetQueryPlanFragments_fieldAccessorTable
+          .ensureFieldAccessorsInitialized(
+              org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.class, org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder.class);
+    }
+
+    public static com.google.protobuf.Parser<GetQueryPlanFragments> PARSER =
+        new com.google.protobuf.AbstractParser<GetQueryPlanFragments>() {
+      public GetQueryPlanFragments parsePartialFrom(
+          com.google.protobuf.CodedInputStream input,
+          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+          throws com.google.protobuf.InvalidProtocolBufferException {
+        return new GetQueryPlanFragments(input, extensionRegistry);
+      }
+    };
+
+    @java.lang.Override
+    public com.google.protobuf.Parser<GetQueryPlanFragments> getParserForType() {
+      return PARSER;
+    }
+
+    private int bitField0_;
+    // required string query = 1;
+    public static final int QUERY_FIELD_NUMBER = 1;
+    private java.lang.Object query_;
+    /**
+     * <code>required string query = 1;</code>
+     */
+    public boolean hasQuery() {
+      return ((bitField0_ & 0x00000001) == 0x00000001);
+    }
+    /**
+     * <code>required string query = 1;</code>
+     */
+    public java.lang.String getQuery() {
+      java.lang.Object ref = query_;
+      if (ref instanceof java.lang.String) {
+        return (java.lang.String) ref;
+      } else {
+        com.google.protobuf.ByteString bs = 
+            (com.google.protobuf.ByteString) ref;
+        java.lang.String s = bs.toStringUtf8();
+        if (bs.isValidUtf8()) {
+          query_ = s;
+        }
+        return s;
+      }
+    }
+    /**
+     * <code>required string query = 1;</code>
+     */
+    public com.google.protobuf.ByteString
+        getQueryBytes() {
+      java.lang.Object ref = query_;
+      if (ref instanceof java.lang.String) {
+        com.google.protobuf.ByteString b = 
+            com.google.protobuf.ByteString.copyFromUtf8(
+                (java.lang.String) ref);
+        query_ = b;
+        return b;
+      } else {
+        return (com.google.protobuf.ByteString) ref;
+      }
+    }
+
+    // optional .exec.shared.QueryType type = 2;
+    public static final int TYPE_FIELD_NUMBER = 2;
+    private org.apache.drill.exec.proto.UserBitShared.QueryType type_;
+    /**
+     * <code>optional .exec.shared.QueryType type = 2;</code>
+     */
+    public boolean hasType() {
+      return ((bitField0_ & 0x00000002) == 0x00000002);
+    }
+    /**
+     * <code>optional .exec.shared.QueryType type = 2;</code>
+     */
+    public org.apache.drill.exec.proto.UserBitShared.QueryType getType() {
+      return type_;
+    }
+
+    // optional bool split_plan = 3 [default = false];
+    public static final int SPLIT_PLAN_FIELD_NUMBER = 3;
+    private boolean splitPlan_;
+    /**
+     * <code>optional bool split_plan = 3 [default = false];</code>
+     */
+    public boolean hasSplitPlan() {
+      return ((bitField0_ & 0x00000004) == 0x00000004);
+    }
+    /**
+     * <code>optional bool split_plan = 3 [default = false];</code>
+     */
+    public boolean getSplitPlan() {
+      return splitPlan_;
+    }
+
+    private void initFields() {
+      query_ = "";
+      type_ = org.apache.drill.exec.proto.UserBitShared.QueryType.SQL;
+      splitPlan_ = false;
+    }
+    private byte memoizedIsInitialized = -1;
+    public final boolean isInitialized() {
+      byte isInitialized = memoizedIsInitialized;
+      if (isInitialized != -1) return isInitialized == 1;
+
+      if (!hasQuery()) {
+        memoizedIsInitialized = 0;
+        return false;
+      }
+      memoizedIsInitialized = 1;
+      return true;
+    }
+
+    public void writeTo(com.google.protobuf.CodedOutputStream output)
+                        throws java.io.IOException {
+      getSerializedSize();
+      if (((bitField0_ & 0x00000001) == 0x00000001)) {
+        output.writeBytes(1, getQueryBytes());
+      }
+      if (((bitField0_ & 0x00000002) == 0x00000002)) {
+        output.writeEnum(2, type_.getNumber());
+      }
+      if (((bitField0_ & 0x00000004) == 0x00000004)) {
+        output.writeBool(3, splitPlan_);
+      }
+      getUnknownFields().writeTo(output);
+    }
+
+    private int memoizedSerializedSize = -1;
+    public int getSerializedSize() {
+      int size = memoizedSerializedSize;
+      if (size != -1) return size;
+
+      size = 0;
+      if (((bitField0_ & 0x00000001) == 0x00000001)) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeBytesSize(1, getQueryBytes());
+      }
+      if (((bitField0_ & 0x00000002) == 0x00000002)) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeEnumSize(2, type_.getNumber());
+      }
+      if (((bitField0_ & 0x00000004) == 0x00000004)) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeBoolSize(3, splitPlan_);
+      }
+      size += getUnknownFields().getSerializedSize();
+      memoizedSerializedSize = size;
+      return size;
+    }
+
+    private static final long serialVersionUID = 0L;
+    @java.lang.Override
+    protected java.lang.Object writeReplace()
+        throws java.io.ObjectStreamException {
+      return super.writeReplace();
+    }
+
+    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseFrom(
+        com.google.protobuf.ByteString data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseFrom(
+        com.google.protobuf.ByteString data,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data, extensionRegistry);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseFrom(byte[] data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseFrom(
+        byte[] data,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data, extensionRegistry);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return PARSER.parseFrom(input);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      return PARSER.parseFrom(input, extensionRegistry);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseDelimitedFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return PARSER.parseDelimitedFrom(input);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseDelimitedFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      return PARSER.parseDelimitedFrom(input, extensionRegistry);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseFrom(
+        com.google.protobuf.CodedInputStream input)
+        throws java.io.IOException {
+      return PARSER.parseFrom(input);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseFrom(
+        com.google.protobuf.CodedInputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      return PARSER.parseFrom(input, extensionRegistry);
+    }
+
+    public static Builder newBuilder() { return Builder.create(); }
+    public Builder newBuilderForType() { return newBuilder(); }
+    public static Builder newBuilder(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments prototype) {
+      return newBuilder().mergeFrom(prototype);
+    }
+    public Builder toBuilder() { return newBuilder(this); }
+
+    @java.lang.Override
+    protected Builder newBuilderForType(
+        com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+      Builder builder = new Builder(parent);
+      return builder;
+    }
+    /**
+     * Protobuf type {@code exec.user.GetQueryPlanFragments}
+     */
+    public static final class Builder extends
+        com.google.protobuf.GeneratedMessage.Builder<Builder>
+       implements org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragmentsOrBuilder {
+      public static final com.google.protobuf.Descriptors.Descriptor
+          getDescriptor() {
+        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_GetQueryPlanFragments_descriptor;
+      }
+
+      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+          internalGetFieldAccessorTable() {
+        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_GetQueryPlanFragments_fieldAccessorTable
+            .ensureFieldAccessorsInitialized(
+                org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.class, org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder.class);
+      }
+
+      // Construct using org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.newBuilder()
+      private Builder() {
+        maybeForceBuilderInitialization();
+      }
+
+      private Builder(
+          com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+        super(parent);
+        maybeForceBuilderInitialization();
+      }
+      private void maybeForceBuilderInitialization() {
+        if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+        }
+      }
+      private static Builder create() {
+        return new Builder();
+      }
+
+      public Builder clear() {
+        super.clear();
+        query_ = "";
+        bitField0_ = (bitField0_ & ~0x00000001);
+        type_ = org.apache.drill.exec.proto.UserBitShared.QueryType.SQL;
+        bitField0_ = (bitField0_ & ~0x00000002);
+        splitPlan_ = false;
+        bitField0_ = (bitField0_ & ~0x00000004);
+        return this;
+      }
+
+      public Builder clone() {
+        return create().mergeFrom(buildPartial());
+      }
+
+      public com.google.protobuf.Descriptors.Descriptor
+          getDescriptorForType() {
+        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_GetQueryPlanFragments_descriptor;
+      }
+
+      public org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments getDefaultInstanceForType() {
+        return org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.getDefaultInstance();
+      }
+
+      public org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments build() {
+        org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments result = buildPartial();
+        if (!result.isInitialized()) {
+          throw newUninitializedMessageException(result);
+        }
+        return result;
+      }
+
+      public org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments buildPartial() {
+        org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments result = new org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments(this);
+        int from_bitField0_ = bitField0_;
+        int to_bitField0_ = 0;
+        if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
+          to_bitField0_ |= 0x00000001;
+        }
+        result.query_ = query_;
+        if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
+          to_bitField0_ |= 0x00000002;
+        }
+        result.type_ = type_;
+        if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
+          to_bitField0_ |= 0x00000004;
+        }
+        result.splitPlan_ = splitPlan_;
+        result.bitField0_ = to_bitField0_;
+        onBuilt();
+        return result;
+      }
+
+      public Builder mergeFrom(com.google.protobuf.Message other) {
+        if (other instanceof org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments) {
+          return mergeFrom((org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments)other);
+        } else {
+          super.mergeFrom(other);
+          return this;
+        }
+      }
+
+      public Builder mergeFrom(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments other) {
+        if (other == org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.getDefaultInstance()) return this;
+        if (other.hasQuery()) {
+          bitField0_ |= 0x00000001;
+          query_ = other.query_;
+          onChanged();
+        }
+        if (other.hasType()) {
+          setType(other.getType());
+        }
+        if (other.hasSplitPlan()) {
+          setSplitPlan(other.getSplitPlan());
+        }
+        this.mergeUnknownFields(other.getUnknownFields());
+        return this;
+      }
+
+      public final boolean isInitialized() {
+        if (!hasQuery()) {
+          
+          return false;
+        }
+        return true;
+      }
+
+      public Builder mergeFrom(
+          com.google.protobuf.CodedInputStream input,
+          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+          throws java.io.IOException {
+        org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parsedMessage = null;
+        try {
+          parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
+        } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+          parsedMessage = (org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments) e.getUnfinishedMessage();
+          throw e;
+        } finally {
+          if (parsedMessage != null) {
+            mergeFrom(parsedMessage);
+          }
+        }
+        return this;
+      }
+      private int bitField0_;
+
+      // required string query = 1;
+      private java.lang.Object query_ = "";
+      /**
+       * <code>required string query = 1;</code>
+       */
+      public boolean hasQuery() {
+        return ((bitField0_ & 0x00000001) == 0x00000001);
+      }
+      /**
+       * <code>required string query = 1;</code>
+       */
+      public java.lang.String getQuery() {
+        java.lang.Object ref = query_;
+        if (!(ref instanceof java.lang.String)) {
+          java.lang.String s = ((com.google.protobuf.ByteString) ref)
+              .toStringUtf8();
+          query_ = s;
+          return s;
+        } else {
+          return (java.lang.String) ref;
+        }
+      }
+      /**
+       * <code>required string query = 1;</code>
+       */
+      public com.google.protobuf.ByteString
+          getQueryBytes() {
+        java.lang.Object ref = query_;
+        if (ref instanceof String) {
+          com.google.protobuf.ByteString b = 
+              com.google.protobuf.ByteString.copyFromUtf8(
+                  (java.lang.String) ref);
+          query_ = b;
+          return b;
+        } else {
+          return (com.google.protobuf.ByteString) ref;
+        }
+      }
+      /**
+       * <code>required string query = 1;</code>
+       */
+      public Builder setQuery(
+          java.lang.String value) {
+        if (value == null) {
+    throw new NullPointerException();
+  }
+  bitField0_ |= 0x00000001;
+        query_ = value;
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>required string query = 1;</code>
+       */
+      public Builder clearQuery() {
+        bitField0_ = (bitField0_ & ~0x00000001);
+        query_ = getDefaultInstance().getQuery();
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>required string query = 1;</code>
+       */
+      public Builder setQueryBytes(
+          com.google.protobuf.ByteString value) {
+        if (value == null) {
+    throw new NullPointerException();
+  }
+  bitField0_ |= 0x00000001;
+        query_ = value;
+        onChanged();
+        return this;
+      }
+
+      // optional .exec.shared.QueryType type = 2;
+      private org.apache.drill.exec.proto.UserBitShared.QueryType type_ = org.apache.drill.exec.proto.UserBitShared.QueryType.SQL;
+      /**
+       * <code>optional .exec.shared.QueryType type = 2;</code>
+       */
+      public boolean hasType() {
+        return ((bitField0_ & 0x00000002) == 0x00000002);
+      }
+      /**
+       * <code>optional .exec.shared.QueryType type = 2;</code>
+       */
+      public org.apache.drill.exec.proto.UserBitShared.QueryType getType() {
+        return type_;
+      }
+      /**
+       * <code>optional .exec.shared.QueryType type = 2;</code>
+       */
+      public Builder setType(org.apache.drill.exec.proto.UserBitShared.QueryType value) {
+        if (value == null) {
+          throw new NullPointerException();
+        }
+        bitField0_ |= 0x00000002;
+        type_ = value;
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.QueryType type = 2;</code>
+       */
+      public Builder clearType() {
+        bitField0_ = (bitField0_ & ~0x00000002);
+        type_ = org.apache.drill.exec.proto.UserBitShared.QueryType.SQL;
+        onChanged();
+        return this;
+      }
+
+      // optional bool split_plan = 3 [default = false];
+      private boolean splitPlan_ ;
+      /**
+       * <code>optional bool split_plan = 3 [default = false];</code>
+       */
+      public boolean hasSplitPlan() {
+        return ((bitField0_ & 0x00000004) == 0x00000004);
+      }
+      /**
+       * <code>optional bool split_plan = 3 [default = false];</code>
+       */
+      public boolean getSplitPlan() {
+        return splitPlan_;
+      }
+      /**
+       * <code>optional bool split_plan = 3 [default = false];</code>
+       */
+      public Builder setSplitPlan(boolean value) {
+        bitField0_ |= 0x00000004;
+        splitPlan_ = value;
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>optional bool split_plan = 3 [default = false];</code>
+       */
+      public Builder clearSplitPlan() {
+        bitField0_ = (bitField0_ & ~0x00000004);
+        splitPlan_ = false;
+        onChanged();
+        return this;
+      }
+
+      // @@protoc_insertion_point(builder_scope:exec.user.GetQueryPlanFragments)
+    }
+
+    static {
+      defaultInstance = new GetQueryPlanFragments(true);
+      defaultInstance.initFields();
+    }
+
+    // @@protoc_insertion_point(class_scope:exec.user.GetQueryPlanFragments)
+  }
+
+  public interface QueryPlanFragmentsOrBuilder
+      extends com.google.protobuf.MessageOrBuilder {
+
+    // required .exec.shared.QueryResult.QueryState status = 1;
+    /**
+     * <code>required .exec.shared.QueryResult.QueryState status = 1;</code>
+     */
+    boolean hasStatus();
+    /**
+     * <code>required .exec.shared.QueryResult.QueryState status = 1;</code>
+     */
+    org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState getStatus();
+
+    // optional .exec.shared.QueryId query_id = 2;
+    /**
+     * <code>optional .exec.shared.QueryId query_id = 2;</code>
+     */
+    boolean hasQueryId();
+    /**
+     * <code>optional .exec.shared.QueryId query_id = 2;</code>
+     */
+    org.apache.drill.exec.proto.UserBitShared.QueryId getQueryId();
+    /**
+     * <code>optional .exec.shared.QueryId query_id = 2;</code>
+     */
+    org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder getQueryIdOrBuilder();
+
+    // repeated .exec.bit.control.PlanFragment fragments = 3;
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+     */
+    java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> 
+        getFragmentsList();
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+     */
+    org.apache.drill.exec.proto.BitControl.PlanFragment getFragments(int index);
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+     */
+    int getFragmentsCount();
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+     */
+    java.util.List<? extends org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> 
+        getFragmentsOrBuilderList();
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+     */
+    org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder getFragmentsOrBuilder(
+        int index);
+
+    // optional .exec.shared.DrillPBError error = 4;
+    /**
+     * <code>optional .exec.shared.DrillPBError error = 4;</code>
+     */
+    boolean hasError();
+    /**
+     * <code>optional .exec.shared.DrillPBError error = 4;</code>
+     */
+    org.apache.drill.exec.proto.UserBitShared.DrillPBError getError();
+    /**
+     * <code>optional .exec.shared.DrillPBError error = 4;</code>
+     */
+    org.apache.drill.exec.proto.UserBitShared.DrillPBErrorOrBuilder getErrorOrBuilder();
+  }
+  /**
+   * Protobuf type {@code exec.user.QueryPlanFragments}
+   */
+  public static final class QueryPlanFragments extends
+      com.google.protobuf.GeneratedMessage
+      implements QueryPlanFragmentsOrBuilder {
+    // Use QueryPlanFragments.newBuilder() to construct.
+    private QueryPlanFragments(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
+      super(builder);
+      this.unknownFields = builder.getUnknownFields();
+    }
+    private QueryPlanFragments(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
+
+    private static final QueryPlanFragments defaultInstance;
+    public static QueryPlanFragments getDefaultInstance() {
+      return defaultInstance;
+    }
+
+    public QueryPlanFragments getDefaultInstanceForType() {
+      return defaultInstance;
+    }
+
+    private final com.google.protobuf.UnknownFieldSet unknownFields;
+    @java.lang.Override
+    public final com.google.protobuf.UnknownFieldSet
+        getUnknownFields() {
+      return this.unknownFields;
+    }
+    private QueryPlanFragments(
+        com.google.protobuf.CodedInputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      initFields();
+      int mutable_bitField0_ = 0;
+      com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+          com.google.protobuf.UnknownFieldSet.newBuilder();
+      try {
+        boolean done = false;
+        while (!done) {
+          int tag = input.readTag();
+          switch (tag) {
+            case 0:
+              done = true;
+              break;
+            default: {
+              if (!parseUnknownField(input, unknownFields,
+                                     extensionRegistry, tag)) {
+                done = true;
+              }
+              break;
+            }
+            case 8: {
+              int rawValue = input.readEnum();
+              org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState value = org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState.valueOf(rawValue);
+              if (value == null) {
+                unknownFields.mergeVarintField(1, rawValue);
+              } else {
+                bitField0_ |= 0x00000001;
+                status_ = value;
+              }
+              break;
+            }
+            case 18: {
+              org.apache.drill.exec.proto.UserBitShared.QueryId.Builder subBuilder = null;
+              if (((bitField0_ & 0x00000002) == 0x00000002)) {
+                subBuilder = queryId_.toBuilder();
+              }
+              queryId_ = input.readMessage(org.apache.drill.exec.proto.UserBitShared.QueryId.PARSER, extensionRegistry);
+              if (subBuilder != null) {
+                subBuilder.mergeFrom(queryId_);
+                queryId_ = subBuilder.buildPartial();
+              }
+              bitField0_ |= 0x00000002;
+              break;
+            }
+            case 26: {
+              if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) {
+                fragments_ = new java.util.ArrayList<org.apache.drill.exec.proto.BitControl.PlanFragment>();
+                mutable_bitField0_ |= 0x00000004;
+              }
+              fragments_.add(input.readMessage(org.apache.drill.exec.proto.BitControl.PlanFragment.PARSER, extensionRegistry));
+              break;
+            }
+            case 34: {
+              org.apache.drill.exec.proto.UserBitShared.DrillPBError.Builder subBuilder = null;
+              if (((bitField0_ & 0x00000004) == 0x00000004)) {
+                subBuilder = error_.toBuilder();
+              }
+              error_ = input.readMessage(org.apache.drill.exec.proto.UserBitShared.DrillPBError.PARSER, extensionRegistry);
+              if (subBuilder != null) {
+                subBuilder.mergeFrom(error_);
+                error_ = subBuilder.buildPartial();
+              }
+              bitField0_ |= 0x00000004;
+              break;
+            }
+          }
+        }
+      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+        throw e.setUnfinishedMessage(this);
+      } catch (java.io.IOException e) {
+        throw new com.google.protobuf.InvalidProtocolBufferException(
+            e.getMessage()).setUnfinishedMessage(this);
+      } finally {
+        if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) {
+          fragments_ = java.util.Collections.unmodifiableList(fragments_);
+        }
+        this.unknownFields = unknownFields.build();
+        makeExtensionsImmutable();
+      }
+    }
+    public static final com.google.protobuf.Descriptors.Descriptor
+        getDescriptor() {
+      return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_QueryPlanFragments_descriptor;
+    }
+
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+        internalGetFieldAccessorTable() {
+      return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_QueryPlanFragments_fieldAccessorTable
+          .ensureFieldAccessorsInitialized(
+              org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.class, org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.Builder.class);
+    }
+
+    public static com.google.protobuf.Parser<QueryPlanFragments> PARSER =
+        new com.google.protobuf.AbstractParser<QueryPlanFragments>() {
+      public QueryPlanFragments parsePartialFrom(
+          com.google.protobuf.CodedInputStream input,
+          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+          throws com.google.protobuf.InvalidProtocolBufferException {
+        return new QueryPlanFragments(input, extensionRegistry);
+      }
+    };
+
+    @java.lang.Override
+    public com.google.protobuf.Parser<QueryPlanFragments> getParserForType() {
+      return PARSER;
+    }
+
+    private int bitField0_;
+    // required .exec.shared.QueryResult.QueryState status = 1;
+    public static final int STATUS_FIELD_NUMBER = 1;
+    private org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState status_;
+    /**
+     * <code>required .exec.shared.QueryResult.QueryState status = 1;</code>
+     */
+    public boolean hasStatus() {
+      return ((bitField0_ & 0x00000001) == 0x00000001);
+    }
+    /**
+     * <code>required .exec.shared.QueryResult.QueryState status = 1;</code>
+     */
+    public org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState getStatus() {
+      return status_;
+    }
+
+    // optional .exec.shared.QueryId query_id = 2;
+    public static final int QUERY_ID_FIELD_NUMBER = 2;
+    private org.apache.drill.exec.proto.UserBitShared.QueryId queryId_;
+    /**
+     * <code>optional .exec.shared.QueryId query_id = 2;</code>
+     */
+    public boolean hasQueryId() {
+      return ((bitField0_ & 0x00000002) == 0x00000002);
+    }
+    /**
+     * <code>optional .exec.shared.QueryId query_id = 2;</code>
+     */
+    public org.apache.drill.exec.proto.UserBitShared.QueryId getQueryId() {
+      return queryId_;
+    }
+    /**
+     * <code>optional .exec.shared.QueryId query_id = 2;</code>
+     */
+    public org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder getQueryIdOrBuilder() {
+      return queryId_;
+    }
+
+    // repeated .exec.bit.control.PlanFragment fragments = 3;
+    public static final int FRAGMENTS_FIELD_NUMBER = 3;
+    private java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> fragments_;
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+     */
+    public java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> getFragmentsList() {
+      return fragments_;
+    }
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+     */
+    public java.util.List<? extends org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> 
+        getFragmentsOrBuilderList() {
+      return fragments_;
+    }
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+     */
+    public int getFragmentsCount() {
+      return fragments_.size();
+    }
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+     */
+    public org.apache.drill.exec.proto.BitControl.PlanFragment getFragments(int index) {
+      return fragments_.get(index);
+    }
+    /**
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+     */
+    public org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder getFragmentsOrBuilder(
+        int index) {
+      return fragments_.get(index);
+    }
+
+    // optional .exec.shared.DrillPBError error = 4;
+    public static final int ERROR_FIELD_NUMBER = 4;
+    private org.apache.drill.exec.proto.UserBitShared.DrillPBError error_;
+    /**
+     * <code>optional .exec.shared.DrillPBError error = 4;</code>
+     */
+    public boolean hasError() {
+      return ((bitField0_ & 0x00000004) == 0x00000004);
+    }
+    /**
+     * <code>optional .exec.shared.DrillPBError error = 4;</code>
+     */
+    public org.apache.drill.exec.proto.UserBitShared.DrillPBError getError() {
+      return error_;
+    }
+    /**
+     * <code>optional .exec.shared.DrillPBError error = 4;</code>
+     */
+    public org.apache.drill.exec.proto.UserBitShared.DrillPBErrorOrBuilder getErrorOrBuilder() {
+      return error_;
+    }
+
+    private void initFields() {
+      status_ = org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState.STARTING;
+      queryId_ = org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance();
+      fragments_ = java.util.Collections.emptyList();
+      error_ = org.apache.drill.exec.proto.UserBitShared.DrillPBError.getDefaultInstance();
+    }
+    private byte memoizedIsInitialized = -1;
+    public final boolean isInitialized() {
+      byte isInitialized = memoizedIsInitialized;
+      if (isInitialized != -1) return isInitialized == 1;
+
+      if (!hasStatus()) {
+        memoizedIsInitialized = 0;
+        return false;
+      }
+      memoizedIsInitialized = 1;
+      return true;
+    }
+
+    public void writeTo(com.google.protobuf.CodedOutputStream output)
+                        throws java.io.IOException {
+      getSerializedSize();
+      if (((bitField0_ & 0x00000001) == 0x00000001)) {
+        output.writeEnum(1, status_.getNumber());
+      }
+      if (((bitField0_ & 0x00000002) == 0x00000002)) {
+        output.writeMessage(2, queryId_);
+      }
+      for (int i = 0; i < fragments_.size(); i++) {
+        output.writeMessage(3, fragments_.get(i));
+      }
+      if (((bitField0_ & 0x00000004) == 0x00000004)) {
+        output.writeMessage(4, error_);
+      }
+      getUnknownFields().writeTo(output);
+    }
+
+    private int memoizedSerializedSize = -1;
+    public int getSerializedSize() {
+      int size = memoizedSerializedSize;
+      if (size != -1) return size;
+
+      size = 0;
+      if (((bitField0_ & 0x00000001) == 0x00000001)) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeEnumSize(1, status_.getNumber());
+      }
+      if (((bitField0_ & 0x00000002) == 0x00000002)) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeMessageSize(2, queryId_);
+      }
+      for (int i = 0; i < fragments_.size(); i++) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeMessageSize(3, fragments_.get(i));
+      }
+      if (((bitField0_ & 0x00000004) == 0x00000004)) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeMessageSize(4, error_);
+      }
+      size += getUnknownFields().getSerializedSize();
+      memoizedSerializedSize = size;
+      return size;
+    }
+
+    private static final long serialVersionUID = 0L;
+    @java.lang.Override
+    protected java.lang.Object writeReplace()
+        throws java.io.ObjectStreamException {
+      return super.writeReplace();
+    }
+
+    public static org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parseFrom(
+        com.google.protobuf.ByteString data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parseFrom(
+        com.google.protobuf.ByteString data,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data, extensionRegistry);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parseFrom(byte[] data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parseFrom(
+        byte[] data,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data, extensionRegistry);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parseFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return PARSER.parseFrom(input);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parseFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      return PARSER.parseFrom(input, extensionRegistry);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parseDelimitedFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return PARSER.parseDelimitedFrom(input);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parseDelimitedFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      return PARSER.parseDelimitedFrom(input, extensionRegistry);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parseFrom(
+        com.google.protobuf.CodedInputStream input)
+        throws java.io.IOException {
+      return PARSER.parseFrom(input);
+    }
+    public static org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parseFrom(
+        com.google.protobuf.CodedInputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      return PARSER.parseFrom(input, extensionRegistry);
+    }
+
+    public static Builder newBuilder() { return Builder.create(); }
+    public Builder newBuilderForType() { return newBuilder(); }
+    public static Builder newBuilder(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments prototype) {
+      return newBuilder().mergeFrom(prototype);
+    }
+    public Builder toBuilder() { return newBuilder(this); }
+
+    @java.lang.Override
+    protected Builder newBuilderForType(
+        com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+      Builder builder = new Builder(parent);
+      return builder;
+    }
+    /**
+     * Protobuf type {@code exec.user.QueryPlanFragments}
+     */
+    public static final class Builder extends
+        com.google.protobuf.GeneratedMessage.Builder<Builder>
+       implements org.apache.drill.exec.proto.UserProtos.QueryPlanFragmentsOrBuilder {
+      public static final com.google.protobuf.Descriptors.Descriptor
+          getDescriptor() {
+        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_QueryPlanFragments_descriptor;
+      }
+
+      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+          internalGetFieldAccessorTable() {
+        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_QueryPlanFragments_fieldAccessorTable
+            .ensureFieldAccessorsInitialized(
+                org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.class, org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.Builder.class);
+      }
+
+      // Construct using org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.newBuilder()
+      private Builder() {
+        maybeForceBuilderInitialization();
+      }
+
+      private Builder(
+          com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+        super(parent);
+        maybeForceBuilderInitialization();
+      }
+      private void maybeForceBuilderInitialization() {
+        if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+          getQueryIdFieldBuilder();
+          getFragmentsFieldBuilder();
+          getErrorFieldBuilder();
+        }
+      }
+      private static Builder create() {
+        return new Builder();
+      }
+
+      public Builder clear() {
+        super.clear();
+        status_ = org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState.STARTING;
+        bitField0_ = (bitField0_ & ~0x00000001);
+        if (queryIdBuilder_ == null) {
+          queryId_ = org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance();
+        } else {
+          queryIdBuilder_.clear();
+        }
+        bitField0_ = (bitField0_ & ~0x00000002);
+        if (fragmentsBuilder_ == null) {
+          fragments_ = java.util.Collections.emptyList();
+          bitField0_ = (bitField0_ & ~0x00000004);
+        } else {
+          fragmentsBuilder_.clear();
+        }
+        if (errorBuilder_ == null) {
+          error_ = org.apache.drill.exec.proto.UserBitShared.DrillPBError.getDefaultInstance();
+        } else {
+          errorBuilder_.clear();
+        }
+        bitField0_ = (bitField0_ & ~0x00000008);
+        return this;
+      }
+
+      public Builder clone() {
+        return create().mergeFrom(buildPartial());
+      }
+
+      public com.google.protobuf.Descriptors.Descriptor
+          getDescriptorForType() {
+        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_QueryPlanFragments_descriptor;
+      }
+
+      public org.apache.drill.exec.proto.UserProtos.QueryPlanFragments getDefaultInstanceForType() {
+        return org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.getDefaultInstance();
+      }
+
+      public org.apache.drill.exec.proto.UserProtos.QueryPlanFragments build() {
+        org.apache.drill.exec.proto.UserProtos.QueryPlanFragments result = buildPartial();
+        if (!result.isInitialized()) {
+          throw newUninitializedMessageException(result);
+        }
+        return result;
+      }
+
+      public org.apache.drill.exec.proto.UserProtos.QueryPlanFragments buildPartial() {
+        org.apache.drill.exec.proto.UserProtos.QueryPlanFragments result = new org.apache.drill.exec.proto.UserProtos.QueryPlanFragments(this);
+        int from_bitField0_ = bitField0_;
+        int to_bitField0_ = 0;
+        if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
+          to_bitField0_ |= 0x00000001;
+        }
+        result.status_ = status_;
+        if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
+          to_bitField0_ |= 0x00000002;
+        }
+        if (queryIdBuilder_ == null) {
+          result.queryId_ = queryId_;
+        } else {
+          result.queryId_ = queryIdBuilder_.build();
+        }
+        if (fragmentsBuilder_ == null) {
+          if (((bitField0_ & 0x00000004) == 0x00000004)) {
+            fragments_ = java.util.Collections.unmodifiableList(fragments_);
+            bitField0_ = (bitField0_ & ~0x00000004);
+          }
+          result.fragments_ = fragments_;
+        } else {
+          result.fragments_ = fragmentsBuilder_.build();
+        }
+        if (((from_bitField0_ & 0x00000008) == 0x00000008)) {
+          to_bitField0_ |= 0x00000004;
+        }
+        if (errorBuilder_ == null) {
+          result.error_ = error_;
+        } else {
+          result.error_ = errorBuilder_.build();
+        }
+        result.bitField0_ = to_bitField0_;
+        onBuilt();
+        return result;
+      }
+
+      public Builder mergeFrom(com.google.protobuf.Message other) {
+        if (other instanceof org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) {
+          return mergeFrom((org.apache.drill.exec.proto.UserProtos.QueryPlanFragments)other);
+        } else {
+          super.mergeFrom(other);
+          return this;
+        }
+      }
+
+      public Builder mergeFrom(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments other) {
+        if (other == org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.getDefaultInstance()) return this;
+        if (other.hasStatus()) {
+          setStatus(other.getStatus());
+        }
+        if (other.hasQueryId()) {
+          mergeQueryId(other.getQueryId());
+        }
+        if (fragmentsBuilder_ == null) {
+          if (!other.fragments_.isEmpty()) {
+            if (fragments_.isEmpty()) {
+              fragments_ = other.fragments_;
+              bitField0_ = (bitField0_ & ~0x00000004);
+            } else {
+              ensureFragmentsIsMutable();
+              fragments_.addAll(other.fragments_);
+            }
+            onChanged();
+          }
+        } else {
+          if (!other.fragments_.isEmpty()) {
+            if (fragmentsBuilder_.isEmpty()) {
+              fragmentsBuilder_.dispose();
+              fragmentsBuilder_ = null;
+              fragments_ = other.fragments_;
+              bitField0_ = (bitField0_ & ~0x00000004);
+              fragmentsBuilder_ = 
+                com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ?
+                   getFragmentsFieldBuilder() : null;
+            } else {
+              fragmentsBuilder_.addAllMessages(other.fragments_);
+            }
+          }
+        }
+        if (other.hasError()) {
+          mergeError(other.getError());
+        }
+        this.mergeUnknownFields(other.getUnknownFields());
+        return this;
+      }
+
+      public final boolean isInitialized() {
+        if (!hasStatus()) {
+          
+          return false;
+        }
+        return true;
+      }
+
+      public Builder mergeFrom(
+          com.google.protobuf.CodedInputStream input,
+          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+          throws java.io.IOException {
+        org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parsedMessage = null;
+        try {
+          parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
+        } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+          parsedMessage = (org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) e.getUnfinishedMessage();
+          throw e;
+        } finally {
+          if (parsedMessage != null) {
+            mergeFrom(parsedMessage);
+          }
+        }
+        return this;
+      }
+      private int bitField0_;
+
+      // required .exec.shared.QueryResult.QueryState status = 1;
+      private org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState status_ = org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState.STARTING;
+      /**
+       * <code>required .exec.shared.QueryResult.QueryState status = 1;</code>
+       */
+      public boolean hasStatus() {
+        return ((bitField0_ & 0x00000001) == 0x00000001);
+      }
+      /**
+       * <code>required .exec.shared.QueryResult.QueryState status = 1;</code>
+       */
+      public org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState getStatus() {
+        return status_;
+      }
+      /**
+       * <code>required .exec.shared.QueryResult.QueryState status = 1;</code>
+       */
+      public Builder setStatus(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState value) {
+        if (value == null) {
+          throw new NullPointerException();
+        }
+        bitField0_ |= 0x00000001;
+        status_ = value;
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>required .exec.shared.QueryResult.QueryState status = 1;</code>
+       */
+      public Builder clearStatus() {
+        bitField0_ = (bitField0_ & ~0x00000001);
+        status_ = org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState.STARTING;
+        onChanged();
+        return this;
+      }
+
+      // optional .exec.shared.QueryId query_id = 2;
+      private org.apache.drill.exec.proto.UserBitShared.QueryId queryId_ = org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance();
+      private com.google.protobuf.SingleFieldBuilder<
+          org.apache.drill.exec.proto.UserBitShared.QueryId, org.apache.drill.exec.proto.UserBitShared.QueryId.Builder, org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder> queryIdBuilder_;
+      /**
+       * <code>optional .exec.shared.QueryId query_id = 2;</code>
+       */
+      public boolean hasQueryId() {
+        return ((bitField0_ & 0x00000002) == 0x00000002);
+      }
+      /**
+       * <code>optional .exec.shared.QueryId query_id = 2;</code>
+       */
+      public org.apache.drill.exec.proto.UserBitShared.QueryId getQueryId() {
+        if (queryIdBuilder_ == null) {
+          return queryId_;
+        } else {
+          return queryIdBuilder_.getMessage();
+        }
+      }
+      /**
+       * <code>optional .exec.shared.QueryId query_id = 2;</code>
+       */
+      public Builder setQueryId(org.apache.drill.exec.proto.UserBitShared.QueryId value) {
+        if (queryIdBuilder_ == null) {
+          if (value == null) {
+            throw new NullPointerException();
+          }
+          queryId_ = value;
+          onChanged();
+        } else {
+          queryIdBuilder_.setMessage(value);
+        }
+        bitField0_ |= 0x00000002;
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.QueryId query_id = 2;</code>
+       */
+      public Builder setQueryId(
+          org.apache.drill.exec.proto.UserBitShared.QueryId.Builder builderForValue) {
+        if (queryIdBuilder_ == null) {
+          queryId_ = builderForValue.build();
+          onChanged();
+        } else {
+          queryIdBuilder_.setMessage(builderForValue.build());
+        }
+        bitField0_ |= 0x00000002;
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.QueryId query_id = 2;</code>
+       */
+      public Builder mergeQueryId(org.apache.drill.exec.proto.UserBitShared.QueryId value) {
+        if (queryIdBuilder_ == null) {
+          if (((bitField0_ & 0x00000002) == 0x00000002) &&
+              queryId_ != org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance()) {
+            queryId_ =
+              org.apache.drill.exec.proto.UserBitShared.QueryId.newBuilder(queryId_).mergeFrom(value).buildPartial();
+          } else {
+            queryId_ = value;
+          }
+          onChanged();
+        } else {
+          queryIdBuilder_.mergeFrom(value);
+        }
+        bitField0_ |= 0x00000002;
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.QueryId query_id = 2;</code>
+       */
+      public Builder clearQueryId() {
+        if (queryIdBuilder_ == null) {
+          queryId_ = org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance();
+          onChanged();
+        } else {
+          queryIdBuilder_.clear();
+        }
+        bitField0_ = (bitField0_ & ~0x00000002);
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.QueryId query_id = 2;</code>
+       */
+      public org.apache.drill.exec.proto.UserBitShared.QueryId.Builder getQueryIdBuilder() {
+        bitField0_ |= 0x00000002;
+        onChanged();
+        return getQueryIdFieldBuilder().getBuilder();
+      }
+      /**
+       * <code>optional .exec.shared.QueryId query_id = 2;</code>
+       */
+      public org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder getQueryIdOrBuilder() {
+        if (queryIdBuilder_ != null) {
+          return queryIdBuilder_.getMessageOrBuilder();
+        } else {
+          return queryId_;
+        }
+      }
+      /**
+       * <code>optional .exec.shared.QueryId query_id = 2;</code>
+       */
+      private com.google.protobuf.SingleFieldBuilder<
+          org.apache.drill.exec.proto.UserBitShared.QueryId, org.apache.drill.exec.proto.UserBitShared.QueryId.Builder, org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder> 
+          getQueryIdFieldBuilder() {
+        if (queryIdBuilder_ == null) {
+          queryIdBuilder_ = new com.google.protobuf.SingleFieldBuilder<
+              org.apache.drill.exec.proto.UserBitShared.QueryId, org.apache.drill.exec.proto.UserBitShared.QueryId.Builder, org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder>(
+                  queryId_,
+                  getParentForChildren(),
+                  isClean());
+          queryId_ = null;
+        }
+        return queryIdBuilder_;
+      }
+
+      // repeated .exec.bit.control.PlanFragment fragments = 3;
+      private java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> fragments_ =
+        java.util.Collections.emptyList();
+      private void ensureFragmentsIsMutable() {
+        if (!((bitField0_ & 0x00000004) == 0x00000004)) {
+          fragments_ = new java.util.ArrayList<org.apache.drill.exec.proto.BitControl.PlanFragment>(fragments_);
+          bitField0_ |= 0x00000004;
+         }
+      }
+
+      private com.google.protobuf.RepeatedFieldBuilder<
+          org.apache.drill.exec.proto.BitControl.PlanFragment, org.apache.drill.exec.proto.BitControl.PlanFragment.Builder, org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> fragmentsBuilder_;
+
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> getFragmentsList() {
+        if (fragmentsBuilder_ == null) {
+          return java.util.Collections.unmodifiableList(fragments_);
+        } else {
+          return fragmentsBuilder_.getMessageList();
+        }
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public int getFragmentsCount() {
+        if (fragmentsBuilder_ == null) {
+          return fragments_.size();
+        } else {
+          return fragmentsBuilder_.getCount();
+        }
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public org.apache.drill.exec.proto.BitControl.PlanFragment getFragments(int index) {
+        if (fragmentsBuilder_ == null) {
+          return fragments_.get(index);
+        } else {
+          return fragmentsBuilder_.getMessage(index);
+        }
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public Builder setFragments(
+          int index, org.apache.drill.exec.proto.BitControl.PlanFragment value) {
+        if (fragmentsBuilder_ == null) {
+          if (value == null) {
+            throw new NullPointerException();
+          }
+          ensureFragmentsIsMutable();
+          fragments_.set(index, value);
+          onChanged();
+        } else {
+          fragmentsBuilder_.setMessage(index, value);
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public Builder setFragments(
+          int index, org.apache.drill.exec.proto.BitControl.PlanFragment.Builder builderForValue) {
+        if (fragmentsBuilder_ == null) {
+          ensureFragmentsIsMutable();
+          fragments_.set(index, builderForValue.build());
+          onChanged();
+        } else {
+          fragmentsBuilder_.setMessage(index, builderForValue.build());
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public Builder addFragments(org.apache.drill.exec.proto.BitControl.PlanFragment value) {
+        if (fragmentsBuilder_ == null) {
+          if (value == null) {
+            throw new NullPointerException();
+          }
+          ensureFragmentsIsMutable();
+          fragments_.add(value);
+          onChanged();
+        } else {
+          fragmentsBuilder_.addMessage(value);
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public Builder addFragments(
+          int index, org.apache.drill.exec.proto.BitControl.PlanFragment value) {
+        if (fragmentsBuilder_ == null) {
+          if (value == null) {
+            throw new NullPointerException();
+          }
+          ensureFragmentsIsMutable();
+          fragments_.add(index, value);
+          onChanged();
+        } else {
+          fragmentsBuilder_.addMessage(index, value);
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public Builder addFragments(
+          org.apache.drill.exec.proto.BitControl.PlanFragment.Builder builderForValue) {
+        if (fragmentsBuilder_ == null) {
+          ensureFragmentsIsMutable();
+          fragments_.add(builderForValue.build());
+          onChanged();
+        } else {
+          fragmentsBuilder_.addMessage(builderForValue.build());
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public Builder addFragments(
+          int index, org.apache.drill.exec.proto.BitControl.PlanFragment.Builder builderForValue) {
+        if (fragmentsBuilder_ == null) {
+          ensureFragmentsIsMutable();
+          fragments_.add(index, builderForValue.build());
+          onChanged();
+        } else {
+          fragmentsBuilder_.addMessage(index, builderForValue.build());
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public Builder addAllFragments(
+          java.lang.Iterable<? extends org.apache.drill.exec.proto.BitControl.PlanFragment> values) {
+        if (fragmentsBuilder_ == null) {
+          ensureFragmentsIsMutable();
+          super.addAll(values, fragments_);
+          onChanged();
+        } else {
+          fragmentsBuilder_.addAllMessages(values);
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public Builder clearFragments() {
+        if (fragmentsBuilder_ == null) {
+          fragments_ = java.util.Collections.emptyList();
+          bitField0_ = (bitField0_ & ~0x00000004);
+          onChanged();
+        } else {
+          fragmentsBuilder_.clear();
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public Builder removeFragments(int index) {
+        if (fragmentsBuilder_ == null) {
+          ensureFragmentsIsMutable();
+          fragments_.remove(index);
+          onChanged();
+        } else {
+          fragmentsBuilder_.remove(index);
+        }
+        return this;
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public org.apache.drill.exec.proto.BitControl.PlanFragment.Builder getFragmentsBuilder(
+          int index) {
+        return getFragmentsFieldBuilder().getBuilder(index);
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder getFragmentsOrBuilder(
+          int index) {
+        if (fragmentsBuilder_ == null) {
+          return fragments_.get(index);  } else {
+          return fragmentsBuilder_.getMessageOrBuilder(index);
+        }
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public java.util.List<? extends org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> 
+           getFragmentsOrBuilderList() {
+        if (fragmentsBuilder_ != null) {
+          return fragmentsBuilder_.getMessageOrBuilderList();
+        } else {
+          return java.util.Collections.unmodifiableList(fragments_);
+        }
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public org.apache.drill.exec.proto.BitControl.PlanFragment.Builder addFragmentsBuilder() {
+        return getFragmentsFieldBuilder().addBuilder(
+            org.apache.drill.exec.proto.BitControl.PlanFragment.getDefaultInstance());
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public org.apache.drill.exec.proto.BitControl.PlanFragment.Builder addFragmentsBuilder(
+          int index) {
+        return getFragmentsFieldBuilder().addBuilder(
+            index, org.apache.drill.exec.proto.BitControl.PlanFragment.getDefaultInstance());
+      }
+      /**
+       * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
+       */
+      public java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment.Builder> 
+           getFragmentsBuilderList() {
+        return getFragmentsFieldBuilder().getBuilderList();
+      }
+      private com.google.protobuf.RepeatedFieldBuilder<
+          org.apache.drill.exec.proto.BitControl.PlanFragment, org.apache.drill.exec.proto.BitControl.PlanFragment.Builder, org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> 
+          getFragmentsFieldBuilder() {
+        if (fragmentsBuilder_ == null) {
+          fragmentsBuilder_ = new com.google.protobuf.RepeatedFieldBuilder<
+              org.apache.drill.exec.proto.BitControl.PlanFragment, org.apache.drill.exec.proto.BitControl.PlanFragment.Builder, org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder>(
+                  fragments_,
+                  ((bitField0_ & 0x00000004) == 0x00000004),
+                  getParentForChildren(),
+                  isClean());
+          fragments_ = null;
+        }
+        return fragmentsBuilder_;
+      }
+
+      // optional .exec.shared.DrillPBError error = 4;
+      private org.apache.drill.exec.proto.UserBitShared.DrillPBError error_ = org.apache.drill.exec.proto.UserBitShared.DrillPBError.getDefaultInstance();
+      private com.google.protobuf.SingleFieldBuilder<
+          org.apache.drill.exec.proto.UserBitShared.DrillPBError, org.apache.drill.exec.proto.UserBitShared.DrillPBError.Builder, org.apache.drill.exec.proto.UserBitShared.DrillPBErrorOrBuilder> errorBuilder_;
+      /**
+       * <code>optional .exec.shared.DrillPBError error = 4;</code>
+       */
+      public boolean hasError() {
+        return ((bitField0_ & 0x00000008) == 0x00000008);
+      }
+      /**
+       * <code>optional .exec.shared.DrillPBError error = 4;</code>
+       */
+      public org.apache.drill.exec.proto.UserBitShared.DrillPBError getError() {
+        if (errorBuilder_ == null) {
+          return error_;
+        } else {
+          return errorBuilder_.getMessage();
+        }
+      }
+      /**
+       * <code>optional .exec.shared.DrillPBError error = 4;</code>
+       */
+      public Builder setError(org.apache.drill.exec.proto.UserBitShared.DrillPBError value) {
+        if (errorBuilder_ == null) {
+          if (value == null) {
+            throw new NullPointerException();
+          }
+          error_ = value;
+          onChanged();
+        } else {
+          errorBuilder_.setMessage(value);
+        }
+        bitField0_ |= 0x00000008;
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.DrillPBError error = 4;</code>
+       */
+      public Builder setError(
+          org.apache.drill.exec.proto.UserBitShared.DrillPBError.Builder builderForValue) {
+        if (errorBuilder_ == null) {
+          error_ = builderForValue.build();
+          onChanged();
+        } else {
+          errorBuilder_.setMessage(builderForValue.build());
+        }
+        bitField0_ |= 0x00000008;
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.DrillPBError error = 4;</code>
+       */
+      public Builder mergeError(org.apache.drill.exec.proto.UserBitShared.DrillPBError value) {
+        if (errorBuilder_ == null) {
+          if (((bitField0_ & 0x00000008) == 0x00000008) &&
+              error_ != org.apache.drill.exec.proto.UserBitShared.DrillPBError.getDefaultInstance()) {
+            error_ =
+              org.apache.drill.exec.proto.UserBitShared.DrillPBError.newBuilder(error_).mergeFrom(value).buildPartial();
+          } else {
+            error_ = value;
+          }
+          onChanged();
+        } else {
+          errorBuilder_.mergeFrom(value);
+        }
+        bitField0_ |= 0x00000008;
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.DrillPBError error = 4;</code>
+       */
+      public Builder clearError() {
+        if (errorBuilder_ == null) {
+          error_ = org.apache.drill.exec.proto.UserBitShared.DrillPBError.getDefaultInstance();
+          onChanged();
+        } else {
+          errorBuilder_.clear();
+        }
+        bitField0_

<TRUNCATED>

[3/4] drill git commit: DRILL-4132 Ability to submit simple type of physical plan directly to EndPoint DrillBit for execution. There are multiple changes to achieve this: 1. During physical planning split single plan into multiple based on the number of

Posted by pa...@apache.org.
http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/java/org/apache/drill/exec/proto/SchemaExecProtos.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/SchemaExecProtos.java b/protocol/src/main/java/org/apache/drill/exec/proto/SchemaExecProtos.java
index 1775f30..f996868 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/SchemaExecProtos.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/SchemaExecProtos.java
@@ -42,6 +42,9 @@ public final class SchemaExecProtos
                     output.writeInt32(2, message.getMajorFragmentId(), false);
                 if(message.hasMinorFragmentId())
                     output.writeInt32(3, message.getMinorFragmentId(), false);
+                if(message.hasParentQueryId())
+                    output.writeObject(4, message.getParentQueryId(), org.apache.drill.exec.proto.SchemaUserBitShared.QueryId.WRITE, false);
+
             }
             public boolean isInitialized(org.apache.drill.exec.proto.ExecProtos.FragmentHandle message)
             {
@@ -91,6 +94,10 @@ public final class SchemaExecProtos
                         case 3:
                             builder.setMinorFragmentId(input.readInt32());
                             break;
+                        case 4:
+                            builder.setParentQueryId(input.mergeObject(org.apache.drill.exec.proto.UserBitShared.QueryId.newBuilder(), org.apache.drill.exec.proto.SchemaUserBitShared.QueryId.MERGE));
+
+                            break;
                         default:
                             input.handleUnknownField(number, this);
                     }
@@ -134,6 +141,7 @@ public final class SchemaExecProtos
                 case 1: return "queryId";
                 case 2: return "majorFragmentId";
                 case 3: return "minorFragmentId";
+                case 4: return "parentQueryId";
                 default: return null;
             }
         }
@@ -148,6 +156,7 @@ public final class SchemaExecProtos
             fieldMap.put("queryId", 1);
             fieldMap.put("majorFragmentId", 2);
             fieldMap.put("minorFragmentId", 3);
+            fieldMap.put("parentQueryId", 4);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/java/org/apache/drill/exec/proto/SchemaUserProtos.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/SchemaUserProtos.java b/protocol/src/main/java/org/apache/drill/exec/proto/SchemaUserProtos.java
index 6fc43bb..10764be 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/SchemaUserProtos.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/SchemaUserProtos.java
@@ -549,6 +549,9 @@ public final class SchemaUserProtos
                     output.writeEnum(2, message.getType().getNumber(), false);
                 if(message.hasPlan())
                     output.writeString(3, message.getPlan(), false);
+                for(org.apache.drill.exec.proto.BitControl.PlanFragment fragments : message.getFragmentsList())
+                    output.writeObject(4, fragments, org.apache.drill.exec.proto.SchemaBitControl.PlanFragment.WRITE, true);
+
             }
             public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.RunQuery message)
             {
@@ -597,6 +600,10 @@ public final class SchemaUserProtos
                         case 3:
                             builder.setPlan(input.readString());
                             break;
+                        case 4:
+                            builder.addFragments(input.mergeObject(org.apache.drill.exec.proto.BitControl.PlanFragment.newBuilder(), org.apache.drill.exec.proto.SchemaBitControl.PlanFragment.MERGE));
+
+                            break;
                         default:
                             input.handleUnknownField(number, this);
                     }
@@ -640,6 +647,7 @@ public final class SchemaUserProtos
                 case 1: return "resultsMode";
                 case 2: return "type";
                 case 3: return "plan";
+                case 4: return "fragments";
                 default: return null;
             }
         }
@@ -654,6 +662,270 @@ public final class SchemaUserProtos
             fieldMap.put("resultsMode", 1);
             fieldMap.put("type", 2);
             fieldMap.put("plan", 3);
+            fieldMap.put("fragments", 4);
+        }
+    }
+
+    public static final class GetQueryPlanFragments
+    {
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.GetQueryPlanFragments.MessageSchema WRITE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.GetQueryPlanFragments.MessageSchema();
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.GetQueryPlanFragments.BuilderSchema MERGE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.GetQueryPlanFragments.BuilderSchema();
+        
+        public static class MessageSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments>
+        {
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments message) throws java.io.IOException
+            {
+                if(message.hasQuery())
+                    output.writeString(1, message.getQuery(), false);
+                if(message.hasType())
+                    output.writeEnum(2, message.getType().getNumber(), false);
+                if(message.hasSplitPlan())
+                    output.writeBool(3, message.getSplitPlan(), false);
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments message)
+            {
+                return message.isInitialized();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.GetQueryPlanFragments.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.GetQueryPlanFragments.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.class.getName();
+            }
+            //unused
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments message) throws java.io.IOException {}
+            public org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments newMessage() { return null; }
+        }
+        public static class BuilderSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder>
+        {
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder builder) throws java.io.IOException
+            {
+                for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+                {
+                    switch(number)
+                    {
+                        case 0:
+                            return;
+                        case 1:
+                            builder.setQuery(input.readString());
+                            break;
+                        case 2:
+                            builder.setType(org.apache.drill.exec.proto.UserBitShared.QueryType.valueOf(input.readEnum()));
+                            break;
+                        case 3:
+                            builder.setSplitPlan(input.readBool());
+                            break;
+                        default:
+                            input.handleUnknownField(number, this);
+                    }
+                }
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder builder)
+            {
+                return builder.isInitialized();
+            }
+            public org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder newMessage()
+            {
+                return org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.newBuilder();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.GetQueryPlanFragments.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.GetQueryPlanFragments.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.class.getName();
+            }
+            //unused
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder builder) throws java.io.IOException {}
+        }
+        public static java.lang.String getFieldName(int number)
+        {
+            switch(number)
+            {
+                case 1: return "query";
+                case 2: return "type";
+                case 3: return "splitPlan";
+                default: return null;
+            }
+        }
+        public static int getFieldNumber(java.lang.String name)
+        {
+            java.lang.Integer number = fieldMap.get(name);
+            return number == null ? 0 : number.intValue();
+        }
+        private static final java.util.HashMap<java.lang.String,java.lang.Integer> fieldMap = new java.util.HashMap<java.lang.String,java.lang.Integer>();
+        static
+        {
+            fieldMap.put("query", 1);
+            fieldMap.put("type", 2);
+            fieldMap.put("splitPlan", 3);
+        }
+    }
+
+    public static final class QueryPlanFragments
+    {
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.QueryPlanFragments.MessageSchema WRITE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.QueryPlanFragments.MessageSchema();
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.QueryPlanFragments.BuilderSchema MERGE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.QueryPlanFragments.BuilderSchema();
+        
+        public static class MessageSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.QueryPlanFragments>
+        {
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.QueryPlanFragments message) throws java.io.IOException
+            {
+                if(message.hasStatus())
+                    output.writeEnum(1, message.getStatus().getNumber(), false);
+                if(message.hasQueryId())
+                    output.writeObject(2, message.getQueryId(), org.apache.drill.exec.proto.SchemaUserBitShared.QueryId.WRITE, false);
+
+                for(org.apache.drill.exec.proto.BitControl.PlanFragment fragments : message.getFragmentsList())
+                    output.writeObject(3, fragments, org.apache.drill.exec.proto.SchemaBitControl.PlanFragment.WRITE, true);
+
+                if(message.hasError())
+                    output.writeObject(4, message.getError(), org.apache.drill.exec.proto.SchemaUserBitShared.DrillPBError.WRITE, false);
+
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments message)
+            {
+                return message.isInitialized();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.QueryPlanFragments.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.QueryPlanFragments.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.QueryPlanFragments> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.class.getName();
+            }
+            //unused
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.QueryPlanFragments message) throws java.io.IOException {}
+            public org.apache.drill.exec.proto.UserProtos.QueryPlanFragments newMessage() { return null; }
+        }
+        public static class BuilderSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.Builder>
+        {
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.Builder builder) throws java.io.IOException
+            {
+                for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+                {
+                    switch(number)
+                    {
+                        case 0:
+                            return;
+                        case 1:
+                            builder.setStatus(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState.valueOf(input.readEnum()));
+                            break;
+                        case 2:
+                            builder.setQueryId(input.mergeObject(org.apache.drill.exec.proto.UserBitShared.QueryId.newBuilder(), org.apache.drill.exec.proto.SchemaUserBitShared.QueryId.MERGE));
+
+                            break;
+                        case 3:
+                            builder.addFragments(input.mergeObject(org.apache.drill.exec.proto.BitControl.PlanFragment.newBuilder(), org.apache.drill.exec.proto.SchemaBitControl.PlanFragment.MERGE));
+
+                            break;
+                        case 4:
+                            builder.setError(input.mergeObject(org.apache.drill.exec.proto.UserBitShared.DrillPBError.newBuilder(), org.apache.drill.exec.proto.SchemaUserBitShared.DrillPBError.MERGE));
+
+                            break;
+                        default:
+                            input.handleUnknownField(number, this);
+                    }
+                }
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.Builder builder)
+            {
+                return builder.isInitialized();
+            }
+            public org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.Builder newMessage()
+            {
+                return org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.newBuilder();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.QueryPlanFragments.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.QueryPlanFragments.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.Builder> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.Builder.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.class.getName();
+            }
+            //unused
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.Builder builder) throws java.io.IOException {}
+        }
+        public static java.lang.String getFieldName(int number)
+        {
+            switch(number)
+            {
+                case 1: return "status";
+                case 2: return "queryId";
+                case 3: return "fragments";
+                case 4: return "error";
+                default: return null;
+            }
+        }
+        public static int getFieldNumber(java.lang.String name)
+        {
+            java.lang.Integer number = fieldMap.get(name);
+            return number == null ? 0 : number.intValue();
+        }
+        private static final java.util.HashMap<java.lang.String,java.lang.Integer> fieldMap = new java.util.HashMap<java.lang.String,java.lang.Integer>();
+        static
+        {
+            fieldMap.put("status", 1);
+            fieldMap.put("queryId", 2);
+            fieldMap.put("fragments", 3);
+            fieldMap.put("error", 4);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/java/org/apache/drill/exec/proto/UserBitShared.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/UserBitShared.java b/protocol/src/main/java/org/apache/drill/exec/proto/UserBitShared.java
index b0489f7..cafdfdd 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/UserBitShared.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/UserBitShared.java
@@ -133,6 +133,10 @@ public final class UserBitShared {
      * <code>PHYSICAL = 3;</code>
      */
     PHYSICAL(2, 3),
+    /**
+     * <code>EXECUTION = 4;</code>
+     */
+    EXECUTION(3, 4),
     ;
 
     /**
@@ -147,6 +151,10 @@ public final class UserBitShared {
      * <code>PHYSICAL = 3;</code>
      */
     public static final int PHYSICAL_VALUE = 3;
+    /**
+     * <code>EXECUTION = 4;</code>
+     */
+    public static final int EXECUTION_VALUE = 4;
 
 
     public final int getNumber() { return value; }
@@ -156,6 +164,7 @@ public final class UserBitShared {
         case 1: return SQL;
         case 2: return LOGICAL;
         case 3: return PHYSICAL;
+        case 4: return EXECUTION;
         default: return null;
       }
     }
@@ -20861,31 +20870,32 @@ public final class UserBitShared {
       "emas\030\003 \001(\003\"J\n\013MetricValue\022\021\n\tmetric_id\030\001" +
       " \001(\005\022\022\n\nlong_value\030\002 \001(\003\022\024\n\014double_value" +
       "\030\003 \001(\001*5\n\nRpcChannel\022\017\n\013BIT_CONTROL\020\000\022\014\n" +
-      "\010BIT_DATA\020\001\022\010\n\004USER\020\002*/\n\tQueryType\022\007\n\003SQ" +
-      "L\020\001\022\013\n\007LOGICAL\020\002\022\014\n\010PHYSICAL\020\003*\207\001\n\rFragm" +
-      "entState\022\013\n\007SENDING\020\000\022\027\n\023AWAITING_ALLOCA" +
-      "TION\020\001\022\013\n\007RUNNING\020\002\022\014\n\010FINISHED\020\003\022\r\n\tCAN",
-      "CELLED\020\004\022\n\n\006FAILED\020\005\022\032\n\026CANCELLATION_REQ" +
-      "UESTED\020\006*\335\005\n\020CoreOperatorType\022\021\n\rSINGLE_" +
-      "SENDER\020\000\022\024\n\020BROADCAST_SENDER\020\001\022\n\n\006FILTER" +
-      "\020\002\022\022\n\016HASH_AGGREGATE\020\003\022\r\n\tHASH_JOIN\020\004\022\016\n" +
-      "\nMERGE_JOIN\020\005\022\031\n\025HASH_PARTITION_SENDER\020\006" +
-      "\022\t\n\005LIMIT\020\007\022\024\n\020MERGING_RECEIVER\020\010\022\034\n\030ORD" +
-      "ERED_PARTITION_SENDER\020\t\022\013\n\007PROJECT\020\n\022\026\n\022" +
-      "UNORDERED_RECEIVER\020\013\022\020\n\014RANGE_SENDER\020\014\022\n" +
-      "\n\006SCREEN\020\r\022\034\n\030SELECTION_VECTOR_REMOVER\020\016" +
-      "\022\027\n\023STREAMING_AGGREGATE\020\017\022\016\n\nTOP_N_SORT\020",
-      "\020\022\021\n\rEXTERNAL_SORT\020\021\022\t\n\005TRACE\020\022\022\t\n\005UNION" +
-      "\020\023\022\014\n\010OLD_SORT\020\024\022\032\n\026PARQUET_ROW_GROUP_SC" +
-      "AN\020\025\022\021\n\rHIVE_SUB_SCAN\020\026\022\025\n\021SYSTEM_TABLE_" +
-      "SCAN\020\027\022\021\n\rMOCK_SUB_SCAN\020\030\022\022\n\016PARQUET_WRI" +
-      "TER\020\031\022\023\n\017DIRECT_SUB_SCAN\020\032\022\017\n\013TEXT_WRITE" +
-      "R\020\033\022\021\n\rTEXT_SUB_SCAN\020\034\022\021\n\rJSON_SUB_SCAN\020" +
-      "\035\022\030\n\024INFO_SCHEMA_SUB_SCAN\020\036\022\023\n\017COMPLEX_T" +
-      "O_JSON\020\037\022\025\n\021PRODUCER_CONSUMER\020 \022\022\n\016HBASE" +
-      "_SUB_SCAN\020!\022\n\n\006WINDOW\020\"\022\024\n\020NESTED_LOOP_J" +
-      "OIN\020#\022\021\n\rAVRO_SUB_SCAN\020$B.\n\033org.apache.d",
-      "rill.exec.protoB\rUserBitSharedH\001"
+      "\010BIT_DATA\020\001\022\010\n\004USER\020\002*>\n\tQueryType\022\007\n\003SQ" +
+      "L\020\001\022\013\n\007LOGICAL\020\002\022\014\n\010PHYSICAL\020\003\022\r\n\tEXECUT" +
+      "ION\020\004*\207\001\n\rFragmentState\022\013\n\007SENDING\020\000\022\027\n\023" +
+      "AWAITING_ALLOCATION\020\001\022\013\n\007RUNNING\020\002\022\014\n\010FI",
+      "NISHED\020\003\022\r\n\tCANCELLED\020\004\022\n\n\006FAILED\020\005\022\032\n\026C" +
+      "ANCELLATION_REQUESTED\020\006*\335\005\n\020CoreOperator" +
+      "Type\022\021\n\rSINGLE_SENDER\020\000\022\024\n\020BROADCAST_SEN" +
+      "DER\020\001\022\n\n\006FILTER\020\002\022\022\n\016HASH_AGGREGATE\020\003\022\r\n" +
+      "\tHASH_JOIN\020\004\022\016\n\nMERGE_JOIN\020\005\022\031\n\025HASH_PAR" +
+      "TITION_SENDER\020\006\022\t\n\005LIMIT\020\007\022\024\n\020MERGING_RE" +
+      "CEIVER\020\010\022\034\n\030ORDERED_PARTITION_SENDER\020\t\022\013" +
+      "\n\007PROJECT\020\n\022\026\n\022UNORDERED_RECEIVER\020\013\022\020\n\014R" +
+      "ANGE_SENDER\020\014\022\n\n\006SCREEN\020\r\022\034\n\030SELECTION_V" +
+      "ECTOR_REMOVER\020\016\022\027\n\023STREAMING_AGGREGATE\020\017",
+      "\022\016\n\nTOP_N_SORT\020\020\022\021\n\rEXTERNAL_SORT\020\021\022\t\n\005T" +
+      "RACE\020\022\022\t\n\005UNION\020\023\022\014\n\010OLD_SORT\020\024\022\032\n\026PARQU" +
+      "ET_ROW_GROUP_SCAN\020\025\022\021\n\rHIVE_SUB_SCAN\020\026\022\025" +
+      "\n\021SYSTEM_TABLE_SCAN\020\027\022\021\n\rMOCK_SUB_SCAN\020\030" +
+      "\022\022\n\016PARQUET_WRITER\020\031\022\023\n\017DIRECT_SUB_SCAN\020" +
+      "\032\022\017\n\013TEXT_WRITER\020\033\022\021\n\rTEXT_SUB_SCAN\020\034\022\021\n" +
+      "\rJSON_SUB_SCAN\020\035\022\030\n\024INFO_SCHEMA_SUB_SCAN" +
+      "\020\036\022\023\n\017COMPLEX_TO_JSON\020\037\022\025\n\021PRODUCER_CONS" +
+      "UMER\020 \022\022\n\016HBASE_SUB_SCAN\020!\022\n\n\006WINDOW\020\"\022\024" +
+      "\n\020NESTED_LOOP_JOIN\020#\022\021\n\rAVRO_SUB_SCAN\020$B",
+      ".\n\033org.apache.drill.exec.protoB\rUserBitS" +
+      "haredH\001"
     };
     com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
       new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {


[4/4] drill git commit: DRILL-4132 Ability to submit simple type of physical plan directly to EndPoint DrillBit for execution. There are multiple changes to achieve this: 1. During physical planning split single plan into multiple based on the number of

Posted by pa...@apache.org.
DRILL-4132 Ability to submit simple type of physical plan directly to EndPoint DrillBit for execution. There are multiple changes to achieve this: 1. During physical planning split single plan into multiple based on the number of minor fragments of the Leaf Major fragment. a. Removing exchange operators during planning b. Producing just root fragments (that will be also leaf fragments) 2. Each fragment can be executed against Drillbit it is assigned to, so to keep locality Design document can be found in the JIRA: DRILL-4132


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

Branch: refs/heads/master
Commit: 6bba69d485b5fafee93a5fd121a0ebc65dd3b5c1
Parents: f07f328
Author: Yuliya Feldman <yf...@maprtech.com>
Authored: Thu Feb 4 14:09:21 2016 -0800
Committer: Parth Chandra <pa...@apache.org>
Committed: Wed May 4 16:35:18 2016 -0700

----------------------------------------------------------------------
 .../apache/drill/exec/client/DrillClient.java   |   55 +
 .../planner/fragment/SimpleParallelizer.java    |   43 +-
 .../contrib/ExchangeRemoverMaterializer.java    |   96 +
 .../fragment/contrib/OperatorIdVisitor.java     |   55 +
 .../fragment/contrib/SplittingParallelizer.java |  228 ++
 .../apache/drill/exec/rpc/user/UserClient.java  |   15 +
 .../drill/exec/rpc/user/UserRpcConfig.java      |    4 +
 .../apache/drill/exec/rpc/user/UserServer.java  |    9 +-
 .../exec/util/MemoryAllocationUtilities.java    |   69 +
 .../org/apache/drill/exec/util/Utilities.java   |    2 +-
 .../apache/drill/exec/work/foreman/Foreman.java |  105 +-
 .../drill/exec/work/user/PlanSplitter.java      |  133 +
 .../apache/drill/exec/work/user/UserWorker.java |   27 +-
 .../drill/exec/DrillSeparatePlanningTest.java   |  344 +++
 .../org/apache/drill/exec/proto/ExecProtos.java |  205 +-
 .../drill/exec/proto/SchemaExecProtos.java      |    9 +
 .../drill/exec/proto/SchemaUserProtos.java      |  272 ++
 .../apache/drill/exec/proto/UserBitShared.java  |   60 +-
 .../org/apache/drill/exec/proto/UserProtos.java | 2414 +++++++++++++++++-
 .../drill/exec/proto/beans/FragmentHandle.java  |   24 +
 .../exec/proto/beans/GetQueryPlanFragments.java |  218 ++
 .../exec/proto/beans/QueryPlanFragments.java    |  255 ++
 .../drill/exec/proto/beans/QueryType.java       |    4 +-
 .../apache/drill/exec/proto/beans/RpcType.java  |    4 +
 .../apache/drill/exec/proto/beans/RunQuery.java |   34 +
 .../src/main/protobuf/ExecutionProtos.proto     |    1 +
 protocol/src/main/protobuf/User.proto           |   20 +
 protocol/src/main/protobuf/UserBitShared.proto  |    1 +
 28 files changed, 4543 insertions(+), 163 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java b/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java
index f83285e..11abbcc 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/client/DrillClient.java
@@ -18,6 +18,7 @@
 package org.apache.drill.exec.client;
 
 import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Preconditions.checkArgument;
 import static org.apache.drill.exec.proto.UserProtos.QueryResultsMode.STREAM_FULL;
 import static org.apache.drill.exec.proto.UserProtos.RunQuery.newBuilder;
 import io.netty.buffer.DrillBuf;
@@ -44,6 +45,7 @@ import org.apache.drill.exec.coord.zk.ZKClusterCoordinator;
 import org.apache.drill.exec.exception.OutOfMemoryException;
 import org.apache.drill.exec.memory.BufferAllocator;
 import org.apache.drill.exec.memory.RootAllocatorFactory;
+import org.apache.drill.exec.proto.BitControl.PlanFragment;
 import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
 import org.apache.drill.exec.proto.GeneralRPCProtos.Ack;
 import org.apache.drill.exec.proto.UserBitShared;
@@ -51,7 +53,9 @@ import org.apache.drill.exec.proto.UserBitShared.QueryId;
 import org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState;
 import org.apache.drill.exec.proto.UserBitShared.QueryType;
 import org.apache.drill.exec.proto.UserProtos;
+import org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments;
 import org.apache.drill.exec.proto.UserProtos.Property;
+import org.apache.drill.exec.proto.UserProtos.QueryPlanFragments;
 import org.apache.drill.exec.proto.UserProtos.RpcType;
 import org.apache.drill.exec.proto.UserProtos.UserProperties;
 import org.apache.drill.exec.proto.helper.QueryIdHelper;
@@ -67,6 +71,9 @@ import org.apache.drill.exec.rpc.user.QueryDataBatch;
 import org.apache.drill.exec.rpc.user.UserClient;
 import org.apache.drill.exec.rpc.user.UserResultsListener;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.google.common.base.Strings;
 import com.google.common.util.concurrent.AbstractCheckedFuture;
 import com.google.common.util.concurrent.SettableFuture;
@@ -78,6 +85,7 @@ import com.google.common.util.concurrent.SettableFuture;
 public class DrillClient implements Closeable, ConnectionThrottle {
   private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillClient.class);
 
+  private static final ObjectMapper objectMapper = new ObjectMapper();
   private final DrillConfig config;
   private UserClient client;
   private UserProperties props = null;
@@ -321,6 +329,53 @@ public class DrillClient implements Closeable, ConnectionThrottle {
     return listener.getResults();
   }
 
+  /**
+   * API to just plan a query without execution
+   * @param type
+   * @param query
+   * @param isSplitPlan - option to tell whether to return single or split plans for a query
+   * @return list of PlanFragments that can be used later on in {@link #runQuery(QueryType, List, UserResultsListener)}
+   * to run a query without additional planning
+   */
+  public DrillRpcFuture<QueryPlanFragments> planQuery(QueryType type, String query, boolean isSplitPlan) {
+    GetQueryPlanFragments runQuery = GetQueryPlanFragments.newBuilder().setQuery(query).setType(type).setSplitPlan(isSplitPlan).build();
+    return client.planQuery(runQuery);
+  }
+
+  /**
+   * Run query based on list of fragments that were supposedly produced during query planning phase
+   * @param type
+   * @param planFragments
+   * @param resultsListener
+   * @throws RpcException
+   */
+  public void runQuery(QueryType type, List<PlanFragment> planFragments, UserResultsListener resultsListener)
+      throws RpcException {
+    // QueryType can be only executional
+    checkArgument((QueryType.EXECUTION == type), "Only EXECUTION type query is supported with PlanFragments");
+    // setting Plan on RunQuery will be used for logging purposes and therefore can not be null
+    // since there is no Plan string provided we will create a JsonArray out of individual fragment Plans
+    ArrayNode jsonArray = objectMapper.createArrayNode();
+    for (PlanFragment fragment : planFragments) {
+      try {
+        jsonArray.add(objectMapper.readTree(fragment.getFragmentJson()));
+      } catch (IOException e) {
+        logger.error("Exception while trying to read PlanFragment JSON for %s", fragment.getHandle().getQueryId(), e);
+        throw new RpcException(e);
+      }
+    }
+    final String fragmentsToJsonString;
+    try {
+      fragmentsToJsonString = objectMapper.writeValueAsString(jsonArray);
+    } catch (JsonProcessingException e) {
+      logger.error("Exception while trying to get JSONString from Array of individual Fragments Json for %s", e);
+      throw new RpcException(e);
+    }
+    final UserProtos.RunQuery query = newBuilder().setType(type).addAllFragments(planFragments)
+        .setPlan(fragmentsToJsonString)
+        .setResultsMode(STREAM_FULL).build();
+    client.submitQuery(resultsListener, query);
+  }
 
   /*
    * Helper method to generate the UserCredentials message from the properties.

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/SimpleParallelizer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/SimpleParallelizer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/SimpleParallelizer.java
index 9aad9a3..47de88e 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/SimpleParallelizer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/SimpleParallelizer.java
@@ -123,7 +123,40 @@ public class SimpleParallelizer implements ParallelizationParameters {
       Collection<DrillbitEndpoint> activeEndpoints, PhysicalPlanReader reader, Fragment rootFragment,
       UserSession session, QueryContextInformation queryContextInfo) throws ExecutionSetupException {
 
-    final PlanningSet planningSet = new PlanningSet();
+    final PlanningSet planningSet = getFragmentsHelper(activeEndpoints, rootFragment);
+    return generateWorkUnit(
+        options, foremanNode, queryId, reader, rootFragment, planningSet, session, queryContextInfo);
+  }
+
+  /**
+   * Create multiple physical plans from original query planning, it will allow execute them eventually independently
+   * @param options
+   * @param foremanNode
+   * @param queryId
+   * @param activeEndpoints
+   * @param reader
+   * @param rootFragment
+   * @param session
+   * @param queryContextInfo
+   * @return
+   * @throws ExecutionSetupException
+   */
+  public List<QueryWorkUnit> getSplitFragments(OptionList options, DrillbitEndpoint foremanNode, QueryId queryId,
+      Collection<DrillbitEndpoint> activeEndpoints, PhysicalPlanReader reader, Fragment rootFragment,
+      UserSession session, QueryContextInformation queryContextInfo) throws ExecutionSetupException {
+    // no op
+    throw new UnsupportedOperationException("Use children classes");
+  }
+  /**
+   * Helper method to reuse the code for QueryWorkUnit(s) generation
+   * @param activeEndpoints
+   * @param rootFragment
+   * @return
+   * @throws ExecutionSetupException
+   */
+  protected PlanningSet getFragmentsHelper(Collection<DrillbitEndpoint> activeEndpoints, Fragment rootFragment) throws ExecutionSetupException {
+
+    PlanningSet planningSet = new PlanningSet();
 
     initFragmentWrappers(rootFragment, planningSet);
 
@@ -134,8 +167,7 @@ public class SimpleParallelizer implements ParallelizationParameters {
       parallelizeFragment(wrapper, planningSet, activeEndpoints);
     }
 
-    return generateWorkUnit(
-        options, foremanNode, queryId, reader, rootFragment, planningSet, session, queryContextInfo);
+    return planningSet;
   }
 
   // For every fragment, create a Wrapper in PlanningSet.
@@ -221,7 +253,7 @@ public class SimpleParallelizer implements ParallelizationParameters {
         .parallelizeFragment(fragmentWrapper, this, activeEndpoints);
   }
 
-  private QueryWorkUnit generateWorkUnit(OptionList options, DrillbitEndpoint foremanNode, QueryId queryId,
+  protected QueryWorkUnit generateWorkUnit(OptionList options, DrillbitEndpoint foremanNode, QueryId queryId,
       PhysicalPlanReader reader, Fragment rootNode, PlanningSet planningSet,
       UserSession session, QueryContextInformation queryContextInfo) throws ExecutionSetupException {
     List<PlanFragment> fragments = Lists.newArrayList();
@@ -297,10 +329,11 @@ public class SimpleParallelizer implements ParallelizationParameters {
     return new QueryWorkUnit(rootOperator, rootFragment, fragments);
   }
 
+
   /**
    * Designed to setup initial values for arriving fragment accounting.
    */
-  private static class CountRequiredFragments extends AbstractPhysicalVisitor<Void, List<Collector>, RuntimeException> {
+  protected static class CountRequiredFragments extends AbstractPhysicalVisitor<Void, List<Collector>, RuntimeException> {
     private static final CountRequiredFragments INSTANCE = new CountRequiredFragments();
 
     public static List<Collector> getCollectors(PhysicalOperator root) {

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/ExchangeRemoverMaterializer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/ExchangeRemoverMaterializer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/ExchangeRemoverMaterializer.java
new file mode 100644
index 0000000..e2cffd8
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/ExchangeRemoverMaterializer.java
@@ -0,0 +1,96 @@
+/**
+ * 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.fragment.contrib;
+
+import java.util.List;
+
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.exception.FragmentSetupException;
+import org.apache.drill.exec.physical.PhysicalOperatorSetupException;
+import org.apache.drill.exec.physical.base.AbstractPhysicalVisitor;
+import org.apache.drill.exec.physical.base.Exchange;
+import org.apache.drill.exec.physical.base.GroupScan;
+import org.apache.drill.exec.physical.base.PhysicalOperator;
+import org.apache.drill.exec.physical.base.Store;
+import org.apache.drill.exec.physical.base.SubScan;
+import org.apache.drill.exec.planner.fragment.Materializer;
+import org.apache.drill.exec.planner.fragment.Materializer.IndexedFragmentNode;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Materializer visitor to remove exchange(s)
+ * NOTE: this Visitor does NOT set OperatorId, as after Exchange removal all operators need renumbering
+ * Use OperatorIdVisitor on top to set correct OperatorId
+ */
+public class ExchangeRemoverMaterializer extends AbstractPhysicalVisitor<PhysicalOperator, Materializer.IndexedFragmentNode, ExecutionSetupException> {
+
+  //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ExchangeRemoverMaterializer.class);
+
+  public static final ExchangeRemoverMaterializer INSTANCE = new ExchangeRemoverMaterializer();
+
+  private ExchangeRemoverMaterializer() {
+
+  }
+
+  @Override
+  public PhysicalOperator visitExchange(Exchange exchange, IndexedFragmentNode iNode) throws ExecutionSetupException {
+    iNode.addAllocation(exchange);
+    PhysicalOperator childEx = exchange.getChild().accept(this, iNode);
+    return childEx;
+  }
+
+  @Override
+  public PhysicalOperator visitGroupScan(GroupScan groupScan, IndexedFragmentNode iNode) throws ExecutionSetupException {
+    PhysicalOperator child = groupScan.getSpecificScan(iNode.getMinorFragmentId());
+    return child;
+  }
+
+  @Override
+  public PhysicalOperator visitSubScan(SubScan subScan, IndexedFragmentNode value) throws ExecutionSetupException {
+    value.addAllocation(subScan);
+    // TODO - implement this
+    return super.visitOp(subScan, value);
+  }
+
+  @Override
+  public PhysicalOperator visitStore(Store store, IndexedFragmentNode iNode) throws ExecutionSetupException {
+    PhysicalOperator child = store.getChild().accept(this, iNode);
+
+    iNode.addAllocation(store);
+
+    try {
+      PhysicalOperator o = store.getSpecificStore(child, iNode.getMinorFragmentId());
+      return o;
+    } catch (PhysicalOperatorSetupException e) {
+      throw new FragmentSetupException("Failure while generating a specific Store materialization.", e);
+    }
+  }
+
+  @Override
+  public PhysicalOperator visitOp(PhysicalOperator op, IndexedFragmentNode iNode) throws ExecutionSetupException {
+    iNode.addAllocation(op);
+    List<PhysicalOperator> children = Lists.newArrayList();
+    for(PhysicalOperator child : op){
+      children.add(child.accept(this, iNode));
+    }
+    PhysicalOperator newOp = op.getNewWithChildren(children);
+    newOp.setCost(op.getCost());
+    return newOp;
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/OperatorIdVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/OperatorIdVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/OperatorIdVisitor.java
new file mode 100644
index 0000000..0a0f215
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/OperatorIdVisitor.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.exec.planner.fragment.contrib;
+
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.physical.base.AbstractPhysicalVisitor;
+import org.apache.drill.exec.physical.base.PhysicalOperator;
+import org.apache.drill.exec.physical.base.SubScan;
+
+/**
+ * Visitor to renumber operators - needed after materialization is done as some operators may be removed
+ * using @ExtendedMaterializerVisitor
+ *
+ */
+public class OperatorIdVisitor extends AbstractPhysicalVisitor<PhysicalOperator, Integer, ExecutionSetupException> {
+
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(OperatorIdVisitor.class);
+
+  public static final OperatorIdVisitor INSTANCE = new OperatorIdVisitor();
+
+  private OperatorIdVisitor() {
+
+  }
+
+  @Override
+  public PhysicalOperator visitSubScan(SubScan subScan, Integer parentOpId) throws ExecutionSetupException {
+    subScan.setOperatorId(Short.MAX_VALUE & parentOpId+1);
+    return subScan;
+  }
+
+  @Override
+  public PhysicalOperator visitOp(PhysicalOperator op, Integer parentOpId) throws ExecutionSetupException {
+    for(PhysicalOperator child : op){
+      child.accept(this, parentOpId+1);
+    }
+    op.setOperatorId(Short.MAX_VALUE & parentOpId+1);
+    return op;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/SplittingParallelizer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/SplittingParallelizer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/SplittingParallelizer.java
new file mode 100644
index 0000000..3488e7f
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/contrib/SplittingParallelizer.java
@@ -0,0 +1,228 @@
+/**
+ * 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.fragment.contrib;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.common.util.DrillStringUtils;
+import org.apache.drill.exec.ops.QueryContext;
+import org.apache.drill.exec.physical.base.Exchange;
+import org.apache.drill.exec.physical.base.FragmentRoot;
+import org.apache.drill.exec.physical.base.PhysicalOperator;
+import org.apache.drill.exec.planner.PhysicalPlanReader;
+import org.apache.drill.exec.planner.fragment.Fragment;
+import org.apache.drill.exec.planner.fragment.PlanningSet;
+import org.apache.drill.exec.planner.fragment.SimpleParallelizer;
+import org.apache.drill.exec.planner.fragment.Wrapper;
+import org.apache.drill.exec.planner.fragment.Materializer.IndexedFragmentNode;
+import org.apache.drill.exec.proto.BitControl.PlanFragment;
+import org.apache.drill.exec.proto.BitControl.QueryContextInformation;
+import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
+import org.apache.drill.exec.proto.ExecProtos.FragmentHandle;
+import org.apache.drill.exec.proto.UserBitShared.QueryId;
+import org.apache.drill.exec.rpc.user.UserSession;
+import org.apache.drill.exec.server.options.OptionList;
+import org.apache.drill.exec.work.QueryWorkUnit;
+import org.apache.drill.exec.work.foreman.ForemanSetupException;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+
+/**
+ * SimpleParallelizerMultiPlans class is an extension to SimpleParallelizer
+ * to help with getting PlanFragments for split plan.
+ * Split plan is essentially ability to create multiple Physical Operator plans from original Physical Operator plan
+ * to be able to run plans separately.
+ * Moving functionality specific to splitting the plan to this class
+ * allows not to pollute parent class with non-authentic functionality
+ *
+ */
+public class SplittingParallelizer extends SimpleParallelizer {
+
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SplittingParallelizer.class);
+
+  public SplittingParallelizer(QueryContext context) {
+    super(context);
+  }
+
+  /**
+   * Create multiple physical plans from original query planning, it will allow execute them eventually independently
+   * @param options
+   * @param foremanNode
+   * @param queryId
+   * @param activeEndpoints
+   * @param reader
+   * @param rootFragment
+   * @param session
+   * @param queryContextInfo
+   * @return
+   * @throws ExecutionSetupException
+   */
+  public List<QueryWorkUnit> getSplitFragments(OptionList options, DrillbitEndpoint foremanNode, QueryId queryId,
+      Collection<DrillbitEndpoint> activeEndpoints, PhysicalPlanReader reader, Fragment rootFragment,
+      UserSession session, QueryContextInformation queryContextInfo) throws ExecutionSetupException {
+
+    final PlanningSet planningSet = getFragmentsHelper(activeEndpoints, rootFragment);
+
+    return generateWorkUnits(
+        options, foremanNode, queryId, reader, rootFragment, planningSet, session, queryContextInfo);
+  }
+
+  /**
+   * Split plan into multiple plans based on parallelization
+   * Ideally it is applicable only to plans with two major fragments: Screen and UnionExchange
+   * But there could be cases where we can remove even multiple exchanges like in case of "order by"
+   * End goal is to get single major fragment: Screen with chain that ends up with a single minor fragment
+   * from Leaf Exchange. This way each plan can run independently without any exchange involvement
+   * @param options
+   * @param foremanNode - not really applicable
+   * @param queryId
+   * @param reader
+   * @param rootNode
+   * @param planningSet
+   * @param session
+   * @param queryContextInfo
+   * @return
+   * @throws ExecutionSetupException
+   */
+  private List<QueryWorkUnit> generateWorkUnits(OptionList options, DrillbitEndpoint foremanNode, QueryId queryId,
+      PhysicalPlanReader reader, Fragment rootNode, PlanningSet planningSet,
+      UserSession session, QueryContextInformation queryContextInfo) throws ExecutionSetupException {
+
+    // now we generate all the individual plan fragments and associated assignments. Note, we need all endpoints
+    // assigned before we can materialize, so we start a new loop here rather than utilizing the previous one.
+
+    List<QueryWorkUnit> workUnits = Lists.newArrayList();
+    int plansCount = 0;
+    DrillbitEndpoint[] endPoints = null;
+    long initialAllocation = 0;
+    long maxAllocation = 0;
+
+    final Iterator<Wrapper> iter = planningSet.iterator();
+    while (iter.hasNext()) {
+      Wrapper wrapper = iter.next();
+      Fragment node = wrapper.getNode();
+      boolean isLeafFragment = node.getReceivingExchangePairs().size() == 0;
+      final PhysicalOperator physicalOperatorRoot = node.getRoot();
+      // get all the needed info from leaf fragment
+      if ( (physicalOperatorRoot instanceof Exchange) &&  isLeafFragment) {
+        // need to get info about
+        // number of minor fragments
+        // assignedEndPoints
+        // allocation
+        plansCount = wrapper.getWidth();
+        initialAllocation = (wrapper.getInitialAllocation() != 0 ) ? wrapper.getInitialAllocation()/plansCount : 0;
+        maxAllocation = (wrapper.getMaxAllocation() != 0 ) ? wrapper.getMaxAllocation()/plansCount : 0;
+        endPoints = new DrillbitEndpoint[plansCount];
+        for (int mfId = 0; mfId < plansCount; mfId++) {
+          endPoints[mfId] = wrapper.getAssignedEndpoint(mfId);
+        }
+      }
+    }
+    if ( plansCount == 0 ) {
+      // no exchange, return list of single QueryWorkUnit
+      workUnits.add(generateWorkUnit(options, foremanNode, queryId, reader, rootNode, planningSet, session, queryContextInfo));
+      return workUnits;
+    }
+
+    for (Wrapper wrapper : planningSet) {
+      Fragment node = wrapper.getNode();
+      final PhysicalOperator physicalOperatorRoot = node.getRoot();
+      if ( physicalOperatorRoot instanceof Exchange ) {
+        // get to 0 MajorFragment
+        continue;
+      }
+      boolean isRootNode = rootNode == node;
+
+      if (isRootNode && wrapper.getWidth() != 1) {
+        throw new ForemanSetupException(String.format("Failure while trying to setup fragment. " +
+                "The root fragment must always have parallelization one. In the current case, the width was set to %d.",
+                wrapper.getWidth()));
+      }
+      // this fragment is always leaf, as we are removing all the exchanges
+      boolean isLeafFragment = true;
+
+      FragmentHandle handle = FragmentHandle //
+          .newBuilder() //
+          .setMajorFragmentId(wrapper.getMajorFragmentId()) //
+          .setMinorFragmentId(0) // minor fragment ID is going to be always 0, as plan will be split
+          .setQueryId(queryId) //
+          .build();
+
+      // Create a minorFragment for each major fragment.
+      for (int minorFragmentId = 0; minorFragmentId < plansCount; minorFragmentId++) {
+        // those fragments should be empty
+        List<PlanFragment> fragments = Lists.newArrayList();
+
+        PlanFragment rootFragment = null;
+        FragmentRoot rootOperator = null;
+
+        IndexedFragmentNode iNode = new IndexedFragmentNode(minorFragmentId, wrapper);
+        wrapper.resetAllocation();
+        // two visitors here
+        // 1. To remove exchange
+        // 2. To reset operator IDs as exchanges were removed
+        PhysicalOperator op = physicalOperatorRoot.accept(ExchangeRemoverMaterializer.INSTANCE, iNode).
+            accept(OperatorIdVisitor.INSTANCE, 0);
+        Preconditions.checkArgument(op instanceof FragmentRoot);
+        FragmentRoot root = (FragmentRoot) op;
+
+        // get plan as JSON
+        String plan;
+        String optionsData;
+        try {
+          plan = reader.writeJson(root);
+          optionsData = reader.writeJson(options);
+        } catch (JsonProcessingException e) {
+          throw new ForemanSetupException("Failure while trying to convert fragment into json.", e);
+        }
+
+        PlanFragment fragment = PlanFragment.newBuilder() //
+            .setForeman(endPoints[minorFragmentId]) //
+            .setFragmentJson(plan) //
+            .setHandle(handle) //
+            .setAssignment(endPoints[minorFragmentId]) //
+            .setLeafFragment(isLeafFragment) //
+            .setContext(queryContextInfo)
+            .setMemInitial(initialAllocation)//
+            .setMemMax(wrapper.getMaxAllocation()) // TODO - for some reason OOM is using leaf fragment max allocation divided by width
+            .setOptionsJson(optionsData)
+            .setCredentials(session.getCredentials())
+            .addAllCollector(CountRequiredFragments.getCollectors(root))
+            .build();
+
+        if (isRootNode) {
+          logger.debug("Root fragment:\n {}", DrillStringUtils.unescapeJava(fragment.toString()));
+          rootFragment = fragment;
+          rootOperator = root;
+        } else {
+          logger.debug("Remote fragment:\n {}", DrillStringUtils.unescapeJava(fragment.toString()));
+          throw new ForemanSetupException(String.format("There should not be non-root/remote fragment present in plan split, but there is:",
+              DrillStringUtils.unescapeJava(fragment.toString())));
+         }
+        // fragments should be always empty here
+        workUnits.add(new QueryWorkUnit(rootOperator, rootFragment, fragments));
+      }
+    }
+    return workUnits;
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserClient.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserClient.java b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserClient.java
index 5ff6a6d..86abaca 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserClient.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserClient.java
@@ -31,7 +31,9 @@ import org.apache.drill.exec.proto.UserBitShared.QueryData;
 import org.apache.drill.exec.proto.UserBitShared.QueryId;
 import org.apache.drill.exec.proto.UserBitShared.QueryResult;
 import org.apache.drill.exec.proto.UserProtos.BitToUserHandshake;
+import org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments;
 import org.apache.drill.exec.proto.UserProtos.HandshakeStatus;
+import org.apache.drill.exec.proto.UserProtos.QueryPlanFragments;
 import org.apache.drill.exec.proto.UserProtos.RpcType;
 import org.apache.drill.exec.proto.UserProtos.RunQuery;
 import org.apache.drill.exec.proto.UserProtos.UserProperties;
@@ -39,6 +41,7 @@ import org.apache.drill.exec.proto.UserProtos.UserToBitHandshake;
 import org.apache.drill.exec.rpc.Acks;
 import org.apache.drill.exec.rpc.BasicClientWithConnection;
 import org.apache.drill.exec.rpc.ConnectionThrottle;
+import org.apache.drill.exec.rpc.DrillRpcFuture;
 import org.apache.drill.exec.rpc.OutOfMemoryHandler;
 import org.apache.drill.exec.rpc.ProtobufLengthDecoder;
 import org.apache.drill.exec.rpc.Response;
@@ -100,6 +103,8 @@ public class UserClient extends BasicClientWithConnection<RpcType, UserToBitHand
         return QueryResult.getDefaultInstance();
     case RpcType.QUERY_DATA_VALUE:
       return QueryData.getDefaultInstance();
+    case RpcType.QUERY_PLAN_FRAGMENTS_VALUE:
+      return QueryPlanFragments.getDefaultInstance();
     }
     throw new RpcException(String.format("Unable to deal with RpcType of %d", rpcType));
   }
@@ -137,4 +142,14 @@ public class UserClient extends BasicClientWithConnection<RpcType, UserToBitHand
   public ProtobufLengthDecoder getDecoder(BufferAllocator allocator) {
     return new UserProtobufLengthDecoder(allocator, OutOfMemoryHandler.DEFAULT_INSTANCE);
   }
+
+  /**
+   * planQuery is an API to plan a query without query execution
+   * @param req - data necessary to plan query
+   * @return list of PlanFragments that can later on be submitted for execution
+   */
+  public DrillRpcFuture<QueryPlanFragments> planQuery(
+      GetQueryPlanFragments req) {
+    return send(RpcType.GET_QUERY_PLAN_FRAGMENTS, req, QueryPlanFragments.class);
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserRpcConfig.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserRpcConfig.java b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserRpcConfig.java
index 22d3634..f0cbb22 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserRpcConfig.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserRpcConfig.java
@@ -26,6 +26,8 @@ import org.apache.drill.exec.proto.UserBitShared.QueryData;
 import org.apache.drill.exec.proto.UserBitShared.QueryId;
 import org.apache.drill.exec.proto.UserBitShared.QueryResult;
 import org.apache.drill.exec.proto.UserProtos.BitToUserHandshake;
+import org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments;
+import org.apache.drill.exec.proto.UserProtos.QueryPlanFragments;
 import org.apache.drill.exec.proto.UserProtos.RpcType;
 import org.apache.drill.exec.proto.UserProtos.RunQuery;
 import org.apache.drill.exec.proto.UserProtos.UserToBitHandshake;
@@ -45,6 +47,8 @@ public class UserRpcConfig {
         .add(RpcType.QUERY_DATA, QueryData.class, RpcType.ACK, Ack.class) // bit to user
         .add(RpcType.QUERY_RESULT, QueryResult.class, RpcType.ACK, Ack.class) // bit to user
         .add(RpcType.RESUME_PAUSED_QUERY, QueryId.class, RpcType.ACK, Ack.class) // user to bit
+        .add(RpcType.GET_QUERY_PLAN_FRAGMENTS, GetQueryPlanFragments.class,
+          RpcType.QUERY_PLAN_FRAGMENTS, QueryPlanFragments.class) // user to bit
         .build();
   }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserServer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserServer.java b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserServer.java
index 7e90747..09bc5c8 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserServer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserServer.java
@@ -38,6 +38,7 @@ import org.apache.drill.exec.proto.GeneralRPCProtos.RpcMode;
 import org.apache.drill.exec.proto.UserBitShared.QueryId;
 import org.apache.drill.exec.proto.UserBitShared.QueryResult;
 import org.apache.drill.exec.proto.UserProtos.BitToUserHandshake;
+import org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments;
 import org.apache.drill.exec.proto.UserProtos.HandshakeStatus;
 import org.apache.drill.exec.proto.UserProtos.Property;
 import org.apache.drill.exec.proto.UserProtos.RpcType;
@@ -131,7 +132,13 @@ public class UserServer extends BasicServer<RpcType, UserServer.UserClientConnec
       } catch (final InvalidProtocolBufferException e) {
         throw new RpcException("Failure while decoding QueryId body.", e);
       }
-
+    case RpcType.GET_QUERY_PLAN_FRAGMENTS_VALUE:
+      try {
+        final GetQueryPlanFragments req = GetQueryPlanFragments.PARSER.parseFrom(new ByteBufInputStream(pBody));
+        return new Response(RpcType.QUERY_PLAN_FRAGMENTS, worker.getQueryPlan(connection, req));
+      } catch(final InvalidProtocolBufferException e) {
+        throw new RpcException("Failure while decoding GetQueryPlanFragments body.", e);
+      }
     default:
       throw new UnsupportedOperationException(String.format("UserServer received rpc of unknown type.  Type was %d.", rpcType));
     }

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/util/MemoryAllocationUtilities.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/MemoryAllocationUtilities.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/MemoryAllocationUtilities.java
new file mode 100644
index 0000000..38dfcd0
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/MemoryAllocationUtilities.java
@@ -0,0 +1,69 @@
+/**
+ * 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.util;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
+import org.apache.drill.exec.ops.QueryContext;
+import org.apache.drill.exec.physical.PhysicalPlan;
+import org.apache.drill.exec.physical.base.PhysicalOperator;
+import org.apache.drill.exec.physical.config.ExternalSort;
+import org.apache.drill.exec.server.options.OptionManager;
+
+public class MemoryAllocationUtilities {
+
+  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MemoryAllocationUtilities.class);
+
+  /**
+   * Helper method to setup SortMemoryAllocations
+   * since this method can be used in multiple places adding it in this class
+   * rather than keeping it in Foreman
+   * @param plan
+   * @param queryContext
+   */
+  public static void setupSortMemoryAllocations(final PhysicalPlan plan, final QueryContext queryContext) {
+    // look for external sorts
+    final List<ExternalSort> sortList = new LinkedList<>();
+    for (final PhysicalOperator op : plan.getSortedOperators()) {
+      if (op instanceof ExternalSort) {
+        sortList.add((ExternalSort) op);
+      }
+    }
+
+    // if there are any sorts, compute the maximum allocation, and set it on them
+    if (sortList.size() > 0) {
+      final OptionManager optionManager = queryContext.getOptions();
+      final long maxWidthPerNode = optionManager.getOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY).num_val;
+      long maxAllocPerNode = Math.min(DrillConfig.getMaxDirectMemory(),
+          queryContext.getConfig().getLong(RootAllocatorFactory.TOP_LEVEL_MAX_ALLOC));
+      maxAllocPerNode = Math.min(maxAllocPerNode,
+          optionManager.getOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY).num_val);
+      final long maxSortAlloc = maxAllocPerNode / (sortList.size() * maxWidthPerNode);
+      logger.debug("Max sort alloc: {}", maxSortAlloc);
+
+      for(final ExternalSort externalSort : sortList) {
+        externalSort.setMaxAllocation(maxSortAlloc);
+      }
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/util/Utilities.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/util/Utilities.java b/exec/java-exec/src/main/java/org/apache/drill/exec/util/Utilities.java
index 345af31..1ed8909 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/util/Utilities.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/util/Utilities.java
@@ -24,6 +24,7 @@ import org.apache.drill.exec.proto.ExecProtos;
 import org.apache.drill.exec.proto.helper.QueryIdHelper;
 
 public class Utilities {
+
   public static String getFileNameForQueryFragment(FragmentContext context, String location, String tag) {
      /*
      * From the context, get the query id, major fragment id, minor fragment id. This will be used as the file name to
@@ -66,5 +67,4 @@ public class Utilities {
       String v = Utilities.class.getPackage().getImplementationVersion();
       return v;
   }
-
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/work/foreman/Foreman.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/work/foreman/Foreman.java b/exec/java-exec/src/main/java/org/apache/drill/exec/work/foreman/Foreman.java
index 29c7971..5137cde 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/work/foreman/Foreman.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/work/foreman/Foreman.java
@@ -34,7 +34,6 @@ import java.util.concurrent.TimeUnit;
 import org.apache.drill.common.CatastrophicFailure;
 import org.apache.drill.common.EventProcessor;
 import org.apache.drill.common.concurrent.ExtendedLatch;
-import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.common.exceptions.ExecutionSetupException;
 import org.apache.drill.common.exceptions.UserException;
 import org.apache.drill.common.logical.LogicalPlan;
@@ -45,14 +44,12 @@ import org.apache.drill.exec.coord.DistributedSemaphore;
 import org.apache.drill.exec.coord.DistributedSemaphore.DistributedLease;
 import org.apache.drill.exec.exception.OptimizerException;
 import org.apache.drill.exec.exception.OutOfMemoryException;
-import org.apache.drill.exec.memory.RootAllocatorFactory;
 import org.apache.drill.exec.ops.FragmentContext;
 import org.apache.drill.exec.ops.QueryContext;
 import org.apache.drill.exec.opt.BasicOptimizer;
 import org.apache.drill.exec.physical.PhysicalPlan;
 import org.apache.drill.exec.physical.base.FragmentRoot;
 import org.apache.drill.exec.physical.base.PhysicalOperator;
-import org.apache.drill.exec.physical.config.ExternalSort;
 import org.apache.drill.exec.planner.fragment.Fragment;
 import org.apache.drill.exec.planner.fragment.MakeFragmentsVisitor;
 import org.apache.drill.exec.planner.fragment.SimpleParallelizer;
@@ -77,6 +74,7 @@ import org.apache.drill.exec.server.DrillbitContext;
 import org.apache.drill.exec.server.options.OptionManager;
 import org.apache.drill.exec.testing.ControlsInjector;
 import org.apache.drill.exec.testing.ControlsInjectorFactory;
+import org.apache.drill.exec.util.MemoryAllocationUtilities;
 import org.apache.drill.exec.util.Pointer;
 import org.apache.drill.exec.work.EndpointListener;
 import org.apache.drill.exec.work.QueryWorkUnit;
@@ -89,6 +87,7 @@ import org.codehaus.jackson.map.ObjectMapper;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Sets;
 
@@ -250,6 +249,9 @@ public class Foreman implements Runnable {
       case SQL:
         runSQL(queryRequest.getPlan());
         break;
+      case EXECUTION:
+        runFragment(queryRequest.getFragmentsList());
+        break;
       default:
         throw new IllegalStateException();
       }
@@ -394,7 +396,7 @@ public class Foreman implements Runnable {
 
   private void runPhysicalPlan(final PhysicalPlan plan) throws ExecutionSetupException {
     validatePlan(plan);
-    setupSortMemoryAllocations(plan);
+    MemoryAllocationUtilities.setupSortMemoryAllocations(plan, queryContext);
     if (queuingEnabled) {
       acquireQuerySemaphore(plan);
       moveToState(QueryState.STARTING, null);
@@ -419,6 +421,60 @@ public class Foreman implements Runnable {
     logger.debug("Fragments running.");
   }
 
+  /**
+   * This is a helper method to run query based on the list of PlanFragment that were planned
+   * at some point of time
+   * @param fragmentsList
+   * @throws ExecutionSetupException
+   */
+  private void runFragment(List<PlanFragment> fragmentsList) throws ExecutionSetupException {
+    // need to set QueryId, MinorFragment for incoming Fragments
+    PlanFragment rootFragment = null;
+    boolean isFirst = true;
+    final List<PlanFragment> planFragments = Lists.newArrayList();
+    for (PlanFragment myFragment : fragmentsList) {
+      final FragmentHandle handle = myFragment.getHandle();
+      // though we have new field in the FragmentHandle - parentQueryId
+      // it can not be used until every piece of code that creates handle is using it, as otherwise
+      // comparisons on that handle fail that causes fragment runtime failure
+      final FragmentHandle newFragmentHandle = FragmentHandle.newBuilder().setMajorFragmentId(handle.getMajorFragmentId())
+          .setMinorFragmentId(handle.getMinorFragmentId()).setQueryId(queryId)
+          .build();
+      final PlanFragment newFragment = PlanFragment.newBuilder(myFragment).setHandle(newFragmentHandle).build();
+      if (isFirst) {
+        rootFragment = newFragment;
+        isFirst = false;
+      } else {
+        planFragments.add(newFragment);
+      }
+    }
+
+    final FragmentRoot rootOperator;
+    try {
+      rootOperator = drillbitContext.getPlanReader().readFragmentOperator(rootFragment.getFragmentJson());
+    } catch (IOException e) {
+      throw new ExecutionSetupException(String.format("Unable to parse FragmentRoot from fragment: %s", rootFragment.getFragmentJson()));
+    }
+    if (queuingEnabled) {
+      acquireQuerySemaphore(rootOperator.getCost());
+      moveToState(QueryState.STARTING, null);
+    }
+    drillbitContext.getWorkBus().addFragmentStatusListener(queryId, queryManager.getFragmentStatusListener());
+    drillbitContext.getClusterCoordinator().addDrillbitStatusListener(queryManager.getDrillbitStatusListener());
+
+    logger.debug("Submitting fragments to run.");
+
+    // set up the root fragment first so we'll have incoming buffers available.
+    setupRootFragment(rootFragment, rootOperator);
+
+    setupNonRootFragments(planFragments);
+
+    moveToState(QueryState.RUNNING, null);
+    logger.debug("Fragments running.");
+  }
+
+
+
   private static void validatePlan(final PhysicalPlan plan) throws ForemanSetupException {
     if (plan.getProperties().resultMode != ResultMode.EXEC) {
       throw new ForemanSetupException(String.format(
@@ -427,32 +483,6 @@ public class Foreman implements Runnable {
     }
   }
 
-  private void setupSortMemoryAllocations(final PhysicalPlan plan) {
-    // look for external sorts
-    final List<ExternalSort> sortList = new LinkedList<>();
-    for (final PhysicalOperator op : plan.getSortedOperators()) {
-      if (op instanceof ExternalSort) {
-        sortList.add((ExternalSort) op);
-      }
-    }
-
-    // if there are any sorts, compute the maximum allocation, and set it on them
-    if (sortList.size() > 0) {
-      final OptionManager optionManager = queryContext.getOptions();
-      final long maxWidthPerNode = optionManager.getOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY).num_val;
-      long maxAllocPerNode = Math.min(DrillConfig.getMaxDirectMemory(),
-          queryContext.getConfig().getLong(RootAllocatorFactory.TOP_LEVEL_MAX_ALLOC));
-      maxAllocPerNode = Math.min(maxAllocPerNode,
-          optionManager.getOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY).num_val);
-      final long maxSortAlloc = maxAllocPerNode / (sortList.size() * maxWidthPerNode);
-      logger.debug("Max sort alloc: {}", maxSortAlloc);
-
-      for(final ExternalSort externalSort : sortList) {
-        externalSort.setMaxAllocation(maxSortAlloc);
-      }
-    }
-  }
-
   /**
    * This limits the number of "small" and "large" queries that a Drill cluster will run
    * simultaneously, if queueing is enabled. If the query is unable to run, this will block
@@ -463,13 +493,19 @@ public class Foreman implements Runnable {
    * @throws ForemanSetupException
    */
   private void acquireQuerySemaphore(final PhysicalPlan plan) throws ForemanSetupException {
-    final OptionManager optionManager = queryContext.getOptions();
-    final long queueThreshold = optionManager.getOption(ExecConstants.QUEUE_THRESHOLD_SIZE);
     double totalCost = 0;
     for (final PhysicalOperator ops : plan.getSortedOperators()) {
       totalCost += ops.getCost();
     }
 
+    acquireQuerySemaphore(totalCost);
+    return;
+  }
+
+  private void acquireQuerySemaphore(double totalCost) throws ForemanSetupException {
+    final OptionManager optionManager = queryContext.getOptions();
+    final long queueThreshold = optionManager.getOption(ExecConstants.QUEUE_THRESHOLD_SIZE);
+
     final long queueTimeout = optionManager.getOption(ExecConstants.QUEUE_TIMEOUT);
     final String queueName;
 
@@ -502,7 +538,6 @@ public class Foreman implements Runnable {
               queueName, queueTimeout / 1000)
           .build(logger);
     }
-
   }
 
   Exception getCurrentException() {
@@ -983,6 +1018,10 @@ public class Foreman implements Runnable {
    * @throws ForemanException
    */
   private void setupNonRootFragments(final Collection<PlanFragment> fragments) throws ForemanException {
+    if (fragments.isEmpty()) {
+      // nothing to do here
+      return;
+    }
     /*
      * We will send a single message to each endpoint, regardless of how many fragments will be
      * executed there. We need to start up the intermediate fragments first so that they will be

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/work/user/PlanSplitter.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/work/user/PlanSplitter.java b/exec/java-exec/src/main/java/org/apache/drill/exec/work/user/PlanSplitter.java
new file mode 100644
index 0000000..eb3e86c
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/work/user/PlanSplitter.java
@@ -0,0 +1,133 @@
+/**
+ * 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.work.user;
+
+import java.util.List;
+
+import org.apache.drill.exec.ops.QueryContext;
+import org.apache.drill.exec.physical.PhysicalPlan;
+import org.apache.drill.exec.physical.base.PhysicalOperator;
+import org.apache.drill.exec.planner.fragment.Fragment;
+import org.apache.drill.exec.planner.fragment.MakeFragmentsVisitor;
+import org.apache.drill.exec.planner.fragment.SimpleParallelizer;
+import org.apache.drill.exec.planner.fragment.contrib.SplittingParallelizer;
+import org.apache.drill.exec.planner.sql.DrillSqlWorker;
+import org.apache.drill.exec.proto.BitControl.PlanFragment;
+import org.apache.drill.exec.proto.UserBitShared.DrillPBError;
+import org.apache.drill.exec.proto.UserBitShared.QueryId;
+import org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState;
+import org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments;
+import org.apache.drill.exec.proto.UserProtos.QueryPlanFragments;
+import org.apache.drill.exec.rpc.user.UserServer.UserClientConnection;
+import org.apache.drill.exec.server.DrillbitContext;
+import org.apache.drill.exec.util.MemoryAllocationUtilities;
+import org.apache.drill.exec.util.Pointer;
+import org.apache.drill.exec.work.QueryWorkUnit;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Helper class to return PlanFragments based on the query plan
+ * or based on split query plan
+ * As of now it is only invoked once per query and therefore cheap to create PlanSplitter object
+ * on heap.
+ */
+public class PlanSplitter {
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PlanSplitter.class);
+
+
+  /**
+   * Method to plan the query and return list of fragments
+   * it will return query plan "as is" or split plans based on the req setting: split_plan
+   * @param dContext
+   * @param queryId
+   * @param req
+   * @param connection
+   * @return
+   */
+  public QueryPlanFragments planFragments(DrillbitContext dContext, QueryId queryId,
+      GetQueryPlanFragments req, UserClientConnection connection) {
+    QueryPlanFragments.Builder responseBuilder = QueryPlanFragments.newBuilder();
+    QueryContext queryContext = new QueryContext(connection.getSession(), dContext, queryId);
+
+    responseBuilder.setQueryId(queryId);
+
+    try {
+      responseBuilder.addAllFragments(getFragments(dContext, req, queryContext, queryId));
+      responseBuilder.setStatus(QueryState.COMPLETED);
+    } catch (Exception e) {
+      final String errorMessage = String.format("Failed to produce PlanFragments for query id \"%s\" with "
+          + "request to %s plan", queryId, (req.getSplitPlan() ? "split" : "no split"));
+      DrillPBError error = DrillPBError.newBuilder().setMessage(errorMessage).setErrorType(DrillPBError.ErrorType.PLAN).build();
+
+      responseBuilder.setStatus(QueryState.FAILED);
+      responseBuilder.setError(error);
+    }
+    return responseBuilder.build();
+  }
+
+  private List<PlanFragment> getFragments(final DrillbitContext dContext, final GetQueryPlanFragments req,
+      final QueryContext queryContext, final QueryId queryId) throws Exception {
+    final PhysicalPlan plan;
+    final String query = req.getQuery();
+    switch(req.getType()) {
+    case SQL:
+      final Pointer<String> textPlan = new Pointer<>();
+      plan = DrillSqlWorker.getPlan(queryContext, query, textPlan);
+      break;
+    case PHYSICAL:
+      plan = dContext.getPlanReader().readPhysicalPlan(query);
+      break;
+    default:
+      throw new IllegalStateException("Planning fragments supports only SQL or PHYSICAL QueryType");
+    }
+
+    MemoryAllocationUtilities.setupSortMemoryAllocations(plan, queryContext);
+
+    final PhysicalOperator rootOperator = plan.getSortedOperators(false).iterator().next();
+
+    final Fragment rootFragment = rootOperator.accept(MakeFragmentsVisitor.INSTANCE, null);
+    final SimpleParallelizer parallelizer = new SplittingParallelizer(queryContext);
+
+    List<PlanFragment> fragments = Lists.newArrayList();
+
+    if ( req.getSplitPlan() ) {
+      final List<QueryWorkUnit> queryWorkUnits = parallelizer.getSplitFragments(
+          queryContext.getOptions().getOptionList(), queryContext.getCurrentEndpoint(),
+          queryId, queryContext.getActiveEndpoints(), dContext.getPlanReader(), rootFragment,
+          queryContext.getSession(), queryContext.getQueryContextInfo());
+
+      for (QueryWorkUnit queryWorkUnit : queryWorkUnits) {
+        fragments.add(queryWorkUnit.getRootFragment());
+
+        List<PlanFragment> childFragments = queryWorkUnit.getFragments();
+        if (!childFragments.isEmpty()) {
+          throw new IllegalStateException("Split plans can not have more then one fragment");
+        }
+      }
+    } else {
+      final QueryWorkUnit queryWorkUnit = parallelizer.getFragments(queryContext.getOptions().getOptionList(), queryContext.getCurrentEndpoint(),
+          queryId, queryContext.getActiveEndpoints(), dContext.getPlanReader(), rootFragment,
+          queryContext.getSession(), queryContext.getQueryContextInfo());
+      fragments.add(queryWorkUnit.getRootFragment());
+      fragments.addAll(queryWorkUnit.getFragments());
+    }
+    return fragments;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/main/java/org/apache/drill/exec/work/user/UserWorker.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/work/user/UserWorker.java b/exec/java-exec/src/main/java/org/apache/drill/exec/work/user/UserWorker.java
index e8deb4d..27126d3 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/work/user/UserWorker.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/work/user/UserWorker.java
@@ -21,6 +21,8 @@ import java.util.concurrent.ThreadLocalRandom;
 
 import org.apache.drill.exec.proto.GeneralRPCProtos.Ack;
 import org.apache.drill.exec.proto.UserBitShared.QueryId;
+import org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments;
+import org.apache.drill.exec.proto.UserProtos.QueryPlanFragments;
 import org.apache.drill.exec.proto.UserProtos.RunQuery;
 import org.apache.drill.exec.rpc.Acks;
 import org.apache.drill.exec.rpc.user.UserServer.UserClientConnection;
@@ -46,14 +48,23 @@ public class UserWorker{
     this.bee = bee;
   }
 
-  public QueryId submitWork(UserClientConnection connection, RunQuery query) {
+  /**
+   * Helper method to generate QueryId
+   * @return generated QueryId
+   */
+  private QueryId queryIdGenerator() {
     ThreadLocalRandom r = ThreadLocalRandom.current();
 
     // create a new queryid where the first four bytes are a growing time (each new value comes earlier in sequence).  Last 12 bytes are random.
-    long time = (int) (System.currentTimeMillis()/1000);
-    long p1 = ((Integer.MAX_VALUE - time) << 32) + r.nextInt();
-    long p2 = r.nextLong();
-    QueryId id = QueryId.newBuilder().setPart1(p1).setPart2(p2).build();
+    final long time = (int) (System.currentTimeMillis()/1000);
+    final long p1 = ((Integer.MAX_VALUE - time) << 32) + r.nextInt();
+    final long p2 = r.nextLong();
+    final QueryId id = QueryId.newBuilder().setPart1(p1).setPart2(p2).build();
+    return id;
+  }
+
+  public QueryId submitWork(UserClientConnection connection, RunQuery query) {
+    final QueryId id = queryIdGenerator();
     incrementer.increment(connection.getSession());
     Foreman foreman = new Foreman(bee, bee.getContext(), connection, id, query);
     bee.addNewForeman(foreman);
@@ -80,4 +91,10 @@ public class UserWorker{
     return bee.getContext().getOptionManager();
   }
 
+  public QueryPlanFragments getQueryPlan(UserClientConnection connection,
+      GetQueryPlanFragments req) {
+    final QueryId queryId = queryIdGenerator();
+    final QueryPlanFragments qPlanFragments = new PlanSplitter().planFragments(bee.getContext(), queryId, req, connection);
+    return qPlanFragments;
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/exec/java-exec/src/test/java/org/apache/drill/exec/DrillSeparatePlanningTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/DrillSeparatePlanningTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/DrillSeparatePlanningTest.java
new file mode 100644
index 0000000..0481825
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/DrillSeparatePlanningTest.java
@@ -0,0 +1,344 @@
+/**
+ * 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;
+
+import static org.junit.Assert.*;
+import io.netty.buffer.DrillBuf;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.concurrent.ExecutionException;
+
+import org.apache.drill.BaseTestQuery;
+import org.apache.drill.common.DrillAutoCloseables;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.common.util.TestTools;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.client.PrintingResultsListener;
+import org.apache.drill.exec.client.QuerySubmitter.Format;
+import org.apache.drill.exec.exception.SchemaChangeException;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.proto.BitControl.PlanFragment;
+import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
+import org.apache.drill.exec.proto.UserBitShared.QueryData;
+import org.apache.drill.exec.proto.UserBitShared.QueryId;
+import org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.proto.UserProtos.QueryPlanFragments;
+import org.apache.drill.exec.record.RecordBatchLoader;
+import org.apache.drill.exec.record.VectorWrapper;
+import org.apache.drill.exec.rpc.ConnectionThrottle;
+import org.apache.drill.exec.rpc.DrillRpcFuture;
+import org.apache.drill.exec.rpc.RpcException;
+import org.apache.drill.exec.rpc.user.AwaitableUserResultsListener;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.rpc.user.UserResultsListener;
+import org.apache.drill.exec.util.VectorUtil;
+import org.apache.drill.exec.vector.ValueVector;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+/**
+ * Class to test different planning use cases (separate form query execution)
+ *
+ */
+public class DrillSeparatePlanningTest extends BaseTestQuery {
+
+  static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DrillSeparatePlanningTest.class);
+
+  static final String WORKING_PATH = TestTools.getWorkingPath();
+  static final String TEST_RES_PATH = WORKING_PATH + "/src/test/resources";
+
+  //final String query = "SELECT sales_city, COUNT(*) cnt FROM cp.`region.json` GROUP BY sales_city";
+  //final String query = "SELECT * FROM cp.`employee.json` where  employee_id > 1 and  employee_id < 1000";
+  //final String query = "SELECT o_orderkey, o_custkey FROM dfs.tmp.`multilevel` where dir0 = 1995 and o_orderkey > 100 and o_orderkey < 1000 limit 5";
+  //final String query = "SELECT sum(o_totalprice) FROM dfs.tmp.`multilevel` where dir0 = 1995 and o_orderkey > 100 and o_orderkey < 1000";
+  //final String query = "SELECT o_orderkey FROM dfs.tmp.`multilevel` order by o_orderkey";
+  //final String query = "SELECT dir1, sum(o_totalprice) FROM dfs.tmp.`multilevel` where dir0 = 1995 group by dir1 order by dir1";
+  //final String query = String.format("SELECT dir0, sum(o_totalprice) FROM dfs_test.`%s/multilevel/json` group by dir0 order by dir0", TEST_RES_PATH);
+
+
+  @Test(timeout=30000)
+  public void testSingleFragmentQuery() throws Exception {
+    final String query = "SELECT * FROM cp.`employee.json` where  employee_id > 1 and  employee_id < 1000";
+
+    QueryPlanFragments planFragments = getFragmentsHelper(query);
+
+    assertNotNull(planFragments);
+
+    assertEquals(1, planFragments.getFragmentsCount());
+    assertTrue(planFragments.getFragments(0).getLeafFragment());
+
+    getResultsHelper(planFragments);
+  }
+
+  @Test(timeout=30000)
+  public void testMultiMinorFragmentSimpleQuery() throws Exception {
+    final String query = String.format("SELECT o_orderkey FROM dfs_test.`%s/multilevel/json`", TEST_RES_PATH);
+
+    QueryPlanFragments planFragments = getFragmentsHelper(query);
+
+    assertNotNull(planFragments);
+
+    assertTrue((planFragments.getFragmentsCount() > 1));
+
+    for ( PlanFragment planFragment : planFragments.getFragmentsList()) {
+      assertTrue(planFragment.getLeafFragment());
+    }
+
+    getResultsHelper(planFragments);
+  }
+
+  @Test(timeout=30000)
+  public void testMultiMinorFragmentComplexQuery() throws Exception {
+    final String query = String.format("SELECT dir0, sum(o_totalprice) FROM dfs_test.`%s/multilevel/json` group by dir0 order by dir0", TEST_RES_PATH);
+
+    QueryPlanFragments planFragments = getFragmentsHelper(query);
+
+    assertNotNull(planFragments);
+
+    assertTrue((planFragments.getFragmentsCount() > 1));
+
+    for ( PlanFragment planFragment : planFragments.getFragmentsList()) {
+      assertTrue(planFragment.getLeafFragment());
+    }
+
+    getResultsHelper(planFragments);
+
+  }
+
+  @Test(timeout=30000)
+  public void testPlanningNoSplit() throws Exception {
+    final String query = String.format("SELECT dir0, sum(o_totalprice) FROM dfs_test.`%s/multilevel/json` group by dir0 order by dir0", TEST_RES_PATH);
+
+    updateTestCluster(2, config);
+
+    List<QueryDataBatch> results = client.runQuery(QueryType.SQL, "alter session set `planner.slice_target`=1");
+    for(QueryDataBatch batch : results) {
+      batch.release();
+    }
+
+    DrillRpcFuture<QueryPlanFragments> queryFragmentsFutures = client.planQuery(QueryType.SQL, query, false);
+
+    final QueryPlanFragments planFragments = queryFragmentsFutures.get();
+
+    assertNotNull(planFragments);
+
+    assertTrue((planFragments.getFragmentsCount() > 1));
+
+    PlanFragment rootFragment = planFragments.getFragments(0);
+    assertFalse(rootFragment.getLeafFragment());
+
+    getCombinedResultsHelper(planFragments);
+
+  }
+
+  @Test(timeout=30000)
+  public void testPlanningNegative() throws Exception {
+    final String query = String.format("SELECT dir0, sum(o_totalprice) FROM dfs_test.`%s/multilevel/json` group by dir0 order by dir0", TEST_RES_PATH);
+
+    updateTestCluster(2, config);
+    // LOGICAL is not supported
+    DrillRpcFuture<QueryPlanFragments> queryFragmentsFutures = client.planQuery(QueryType.LOGICAL, query, false);
+
+    final QueryPlanFragments planFragments = queryFragmentsFutures.get();
+
+    assertNotNull(planFragments);
+
+    assertNotNull(planFragments.getError());
+
+    assertTrue(planFragments.getFragmentsCount()==0);
+
+  }
+
+  @Test(timeout=30000)
+  public void testPlanning() throws Exception {
+    final String query = String.format("SELECT dir0, columns[3] FROM dfs_test.`%s/multilevel/csv` order by dir0", TEST_RES_PATH);
+
+    updateTestCluster(2, config);
+
+    List<QueryDataBatch> results = client.runQuery(QueryType.SQL, "alter session set `planner.slice_target`=1");
+    for(QueryDataBatch batch : results) {
+      batch.release();
+    }
+    AwaitableUserResultsListener listener =
+        new AwaitableUserResultsListener(new PrintingResultsListener(client.getConfig(), Format.TSV, VectorUtil.DEFAULT_COLUMN_WIDTH));
+    //AwaitableUserResultsListener listener =
+    //    new AwaitableUserResultsListener(new SilentListener());
+    client.runQuery(QueryType.SQL, query, listener);
+    int rows = listener.await();
+  }
+
+  private QueryPlanFragments getFragmentsHelper(final String query) throws InterruptedException, ExecutionException, RpcException {
+    updateTestCluster(2, config);
+
+    List<QueryDataBatch> results = client.runQuery(QueryType.SQL, "alter session set `planner.slice_target`=1");
+    for(QueryDataBatch batch : results) {
+      batch.release();
+    }
+
+    DrillRpcFuture<QueryPlanFragments> queryFragmentsFutures = client.planQuery(QueryType.SQL, query, true);
+
+    final QueryPlanFragments planFragments = queryFragmentsFutures.get();
+
+    for (PlanFragment fragment : planFragments.getFragmentsList()) {
+      System.out.println(fragment.getFragmentJson());
+    }
+
+    return planFragments;
+  }
+
+  private void getResultsHelper(final QueryPlanFragments planFragments) throws Exception {
+    for (PlanFragment fragment : planFragments.getFragmentsList()) {
+      DrillbitEndpoint assignedNode = fragment.getAssignment();
+      DrillClient fragmentClient = new DrillClient(true);
+      Properties props = new Properties();
+      props.setProperty("drillbit", assignedNode.getAddress() + ":" + assignedNode.getUserPort());
+      fragmentClient.connect(props);
+
+      ShowResultsUserResultsListener myListener = new ShowResultsUserResultsListener(getAllocator());
+      AwaitableUserResultsListener listenerBits =
+          new AwaitableUserResultsListener(myListener);
+      fragmentClient.runQuery(QueryType.SQL, "select hostname, user_port from sys.drillbits where `current`=true",
+          listenerBits);
+      int row = listenerBits.await();
+      assertEquals(1, row);
+      List<Map<String,String>> records = myListener.getRecords();
+      assertEquals(1, records.size());
+      Map<String,String> record = records.get(0);
+      assertEquals(2, record.size());
+      Iterator<Entry<String, String>> iter = record.entrySet().iterator();
+      Entry<String, String> entry;
+      String host = null;
+      String port = null;
+      for (int i = 0; i < 2; i++) {
+       entry = iter.next();
+       if (entry.getKey().equalsIgnoreCase("hostname")) {
+          host = entry.getValue();
+        } else if (entry.getKey().equalsIgnoreCase("user_port")) {
+          port = entry.getValue();
+        } else {
+          fail("Unknown field: " + entry.getKey());
+        }
+       }
+      assertTrue(props.getProperty("drillbit").equalsIgnoreCase(host+":" + port));
+
+      List<PlanFragment> fragmentList = Lists.newArrayList();
+      fragmentList.add(fragment);
+      //AwaitableUserResultsListener listener =
+     //     new AwaitableUserResultsListener(new PrintingResultsListener(client.getConfig(), Format.TSV, VectorUtil.DEFAULT_COLUMN_WIDTH));
+      AwaitableUserResultsListener listener =
+          new AwaitableUserResultsListener(new SilentListener());
+      fragmentClient.runQuery(QueryType.EXECUTION, fragmentList, listener);
+      int rows = listener.await();
+      fragmentClient.close();
+    }
+  }
+
+  private void getCombinedResultsHelper(final QueryPlanFragments planFragments) throws Exception {
+      ShowResultsUserResultsListener myListener = new ShowResultsUserResultsListener(getAllocator());
+      AwaitableUserResultsListener listenerBits =
+          new AwaitableUserResultsListener(myListener);
+
+      //AwaitableUserResultsListener listener =
+     //     new AwaitableUserResultsListener(new PrintingResultsListener(client.getConfig(), Format.TSV, VectorUtil.DEFAULT_COLUMN_WIDTH));
+      AwaitableUserResultsListener listener =
+          new AwaitableUserResultsListener(new SilentListener());
+      client.runQuery(QueryType.EXECUTION, planFragments.getFragmentsList(), listener);
+      int rows = listener.await();
+  }
+
+  /**
+   * Helper class to get results
+   *
+   */
+  static class ShowResultsUserResultsListener implements UserResultsListener {
+
+    private QueryId queryId;
+    private final RecordBatchLoader loader;
+    private final BufferAllocator allocator;
+    private UserException ex;
+    private List<Map<String,String>> records = Lists.newArrayList();
+
+    public ShowResultsUserResultsListener(BufferAllocator allocator) {
+      this.loader = new RecordBatchLoader(allocator);
+      this.allocator = allocator;
+    }
+
+    public QueryId getQueryId() {
+      return queryId;
+    }
+
+    public List<Map<String, String>> getRecords() {
+      return records;
+    }
+
+    public UserException getEx() {
+      return ex;
+    }
+
+    @Override
+    public void queryIdArrived(QueryId queryId) {
+     this.queryId = queryId;
+    }
+
+    @Override
+    public void submissionFailed(UserException ex) {
+      DrillAutoCloseables.closeNoChecked(allocator);
+      this.ex = ex;
+    }
+
+    @Override
+    public void dataArrived(QueryDataBatch result, ConnectionThrottle throttle) {
+      QueryData queryHeader = result.getHeader();
+      int rows = queryHeader.getRowCount();
+      try {
+        if ( result.hasData() ) {
+          DrillBuf data = result.getData();
+          loader.load(queryHeader.getDef(), data);
+          for (int i = 0; i < rows; i++) {
+             Map<String,String> record = Maps.newHashMap();
+            for (VectorWrapper<?> vw : loader) {
+              final String field = vw.getValueVector().getMetadata().getNamePart().getName();
+              final ValueVector.Accessor accessor = vw.getValueVector().getAccessor();
+              final Object value = i < accessor.getValueCount() ? accessor.getObject(i) : null;
+              final String display = value == null ? null : value.toString();
+              record.put(field, display);
+            }
+            records.add(record);
+          }
+          loader.clear();
+        }
+        result.release();
+      } catch (SchemaChangeException e) {
+        fail(e.getMessage());
+      }
+
+    }
+
+    @Override
+    public void queryCompleted(QueryState state) {
+    }
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/6bba69d4/protocol/src/main/java/org/apache/drill/exec/proto/ExecProtos.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/ExecProtos.java b/protocol/src/main/java/org/apache/drill/exec/proto/ExecProtos.java
index 7ca17f1..5b986cf 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/ExecProtos.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/ExecProtos.java
@@ -61,6 +61,20 @@ public final class ExecProtos {
      * <code>optional int32 minor_fragment_id = 3;</code>
      */
     int getMinorFragmentId();
+
+    // optional .exec.shared.QueryId parent_query_id = 4;
+    /**
+     * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+     */
+    boolean hasParentQueryId();
+    /**
+     * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+     */
+    org.apache.drill.exec.proto.UserBitShared.QueryId getParentQueryId();
+    /**
+     * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+     */
+    org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder getParentQueryIdOrBuilder();
   }
   /**
    * Protobuf type {@code exec.bit.FragmentHandle}
@@ -136,6 +150,19 @@ public final class ExecProtos {
               minorFragmentId_ = input.readInt32();
               break;
             }
+            case 34: {
+              org.apache.drill.exec.proto.UserBitShared.QueryId.Builder subBuilder = null;
+              if (((bitField0_ & 0x00000008) == 0x00000008)) {
+                subBuilder = parentQueryId_.toBuilder();
+              }
+              parentQueryId_ = input.readMessage(org.apache.drill.exec.proto.UserBitShared.QueryId.PARSER, extensionRegistry);
+              if (subBuilder != null) {
+                subBuilder.mergeFrom(parentQueryId_);
+                parentQueryId_ = subBuilder.buildPartial();
+              }
+              bitField0_ |= 0x00000008;
+              break;
+            }
           }
         }
       } catch (com.google.protobuf.InvalidProtocolBufferException e) {
@@ -230,10 +257,33 @@ public final class ExecProtos {
       return minorFragmentId_;
     }
 
+    // optional .exec.shared.QueryId parent_query_id = 4;
+    public static final int PARENT_QUERY_ID_FIELD_NUMBER = 4;
+    private org.apache.drill.exec.proto.UserBitShared.QueryId parentQueryId_;
+    /**
+     * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+     */
+    public boolean hasParentQueryId() {
+      return ((bitField0_ & 0x00000008) == 0x00000008);
+    }
+    /**
+     * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+     */
+    public org.apache.drill.exec.proto.UserBitShared.QueryId getParentQueryId() {
+      return parentQueryId_;
+    }
+    /**
+     * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+     */
+    public org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder getParentQueryIdOrBuilder() {
+      return parentQueryId_;
+    }
+
     private void initFields() {
       queryId_ = org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance();
       majorFragmentId_ = 0;
       minorFragmentId_ = 0;
+      parentQueryId_ = org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance();
     }
     private byte memoizedIsInitialized = -1;
     public final boolean isInitialized() {
@@ -256,6 +306,9 @@ public final class ExecProtos {
       if (((bitField0_ & 0x00000004) == 0x00000004)) {
         output.writeInt32(3, minorFragmentId_);
       }
+      if (((bitField0_ & 0x00000008) == 0x00000008)) {
+        output.writeMessage(4, parentQueryId_);
+      }
       getUnknownFields().writeTo(output);
     }
 
@@ -277,6 +330,10 @@ public final class ExecProtos {
         size += com.google.protobuf.CodedOutputStream
           .computeInt32Size(3, minorFragmentId_);
       }
+      if (((bitField0_ & 0x00000008) == 0x00000008)) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeMessageSize(4, parentQueryId_);
+      }
       size += getUnknownFields().getSerializedSize();
       memoizedSerializedSize = size;
       return size;
@@ -386,6 +443,7 @@ public final class ExecProtos {
       private void maybeForceBuilderInitialization() {
         if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
           getQueryIdFieldBuilder();
+          getParentQueryIdFieldBuilder();
         }
       }
       private static Builder create() {
@@ -404,6 +462,12 @@ public final class ExecProtos {
         bitField0_ = (bitField0_ & ~0x00000002);
         minorFragmentId_ = 0;
         bitField0_ = (bitField0_ & ~0x00000004);
+        if (parentQueryIdBuilder_ == null) {
+          parentQueryId_ = org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance();
+        } else {
+          parentQueryIdBuilder_.clear();
+        }
+        bitField0_ = (bitField0_ & ~0x00000008);
         return this;
       }
 
@@ -448,6 +512,14 @@ public final class ExecProtos {
           to_bitField0_ |= 0x00000004;
         }
         result.minorFragmentId_ = minorFragmentId_;
+        if (((from_bitField0_ & 0x00000008) == 0x00000008)) {
+          to_bitField0_ |= 0x00000008;
+        }
+        if (parentQueryIdBuilder_ == null) {
+          result.parentQueryId_ = parentQueryId_;
+        } else {
+          result.parentQueryId_ = parentQueryIdBuilder_.build();
+        }
         result.bitField0_ = to_bitField0_;
         onBuilt();
         return result;
@@ -473,6 +545,9 @@ public final class ExecProtos {
         if (other.hasMinorFragmentId()) {
           setMinorFragmentId(other.getMinorFragmentId());
         }
+        if (other.hasParentQueryId()) {
+          mergeParentQueryId(other.getParentQueryId());
+        }
         this.mergeUnknownFields(other.getUnknownFields());
         return this;
       }
@@ -683,6 +758,123 @@ public final class ExecProtos {
         return this;
       }
 
+      // optional .exec.shared.QueryId parent_query_id = 4;
+      private org.apache.drill.exec.proto.UserBitShared.QueryId parentQueryId_ = org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance();
+      private com.google.protobuf.SingleFieldBuilder<
+          org.apache.drill.exec.proto.UserBitShared.QueryId, org.apache.drill.exec.proto.UserBitShared.QueryId.Builder, org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder> parentQueryIdBuilder_;
+      /**
+       * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+       */
+      public boolean hasParentQueryId() {
+        return ((bitField0_ & 0x00000008) == 0x00000008);
+      }
+      /**
+       * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+       */
+      public org.apache.drill.exec.proto.UserBitShared.QueryId getParentQueryId() {
+        if (parentQueryIdBuilder_ == null) {
+          return parentQueryId_;
+        } else {
+          return parentQueryIdBuilder_.getMessage();
+        }
+      }
+      /**
+       * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+       */
+      public Builder setParentQueryId(org.apache.drill.exec.proto.UserBitShared.QueryId value) {
+        if (parentQueryIdBuilder_ == null) {
+          if (value == null) {
+            throw new NullPointerException();
+          }
+          parentQueryId_ = value;
+          onChanged();
+        } else {
+          parentQueryIdBuilder_.setMessage(value);
+        }
+        bitField0_ |= 0x00000008;
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+       */
+      public Builder setParentQueryId(
+          org.apache.drill.exec.proto.UserBitShared.QueryId.Builder builderForValue) {
+        if (parentQueryIdBuilder_ == null) {
+          parentQueryId_ = builderForValue.build();
+          onChanged();
+        } else {
+          parentQueryIdBuilder_.setMessage(builderForValue.build());
+        }
+        bitField0_ |= 0x00000008;
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+       */
+      public Builder mergeParentQueryId(org.apache.drill.exec.proto.UserBitShared.QueryId value) {
+        if (parentQueryIdBuilder_ == null) {
+          if (((bitField0_ & 0x00000008) == 0x00000008) &&
+              parentQueryId_ != org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance()) {
+            parentQueryId_ =
+              org.apache.drill.exec.proto.UserBitShared.QueryId.newBuilder(parentQueryId_).mergeFrom(value).buildPartial();
+          } else {
+            parentQueryId_ = value;
+          }
+          onChanged();
+        } else {
+          parentQueryIdBuilder_.mergeFrom(value);
+        }
+        bitField0_ |= 0x00000008;
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+       */
+      public Builder clearParentQueryId() {
+        if (parentQueryIdBuilder_ == null) {
+          parentQueryId_ = org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance();
+          onChanged();
+        } else {
+          parentQueryIdBuilder_.clear();
+        }
+        bitField0_ = (bitField0_ & ~0x00000008);
+        return this;
+      }
+      /**
+       * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+       */
+      public org.apache.drill.exec.proto.UserBitShared.QueryId.Builder getParentQueryIdBuilder() {
+        bitField0_ |= 0x00000008;
+        onChanged();
+        return getParentQueryIdFieldBuilder().getBuilder();
+      }
+      /**
+       * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+       */
+      public org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder getParentQueryIdOrBuilder() {
+        if (parentQueryIdBuilder_ != null) {
+          return parentQueryIdBuilder_.getMessageOrBuilder();
+        } else {
+          return parentQueryId_;
+        }
+      }
+      /**
+       * <code>optional .exec.shared.QueryId parent_query_id = 4;</code>
+       */
+      private com.google.protobuf.SingleFieldBuilder<
+          org.apache.drill.exec.proto.UserBitShared.QueryId, org.apache.drill.exec.proto.UserBitShared.QueryId.Builder, org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder> 
+          getParentQueryIdFieldBuilder() {
+        if (parentQueryIdBuilder_ == null) {
+          parentQueryIdBuilder_ = new com.google.protobuf.SingleFieldBuilder<
+              org.apache.drill.exec.proto.UserBitShared.QueryId, org.apache.drill.exec.proto.UserBitShared.QueryId.Builder, org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder>(
+                  parentQueryId_,
+                  getParentForChildren(),
+                  isClean());
+          parentQueryId_ = null;
+        }
+        return parentQueryIdBuilder_;
+      }
+
       // @@protoc_insertion_point(builder_scope:exec.bit.FragmentHandle)
     }
 
@@ -709,11 +901,12 @@ public final class ExecProtos {
   static {
     java.lang.String[] descriptorData = {
       "\n\025ExecutionProtos.proto\022\010exec.bit\032\022Coord" +
-      "ination.proto\032\023UserBitShared.proto\"n\n\016Fr" +
-      "agmentHandle\022&\n\010query_id\030\001 \001(\0132\024.exec.sh" +
-      "ared.QueryId\022\031\n\021major_fragment_id\030\002 \001(\005\022" +
-      "\031\n\021minor_fragment_id\030\003 \001(\005B+\n\033org.apache" +
-      ".drill.exec.protoB\nExecProtosH\001"
+      "ination.proto\032\023UserBitShared.proto\"\235\001\n\016F" +
+      "ragmentHandle\022&\n\010query_id\030\001 \001(\0132\024.exec.s" +
+      "hared.QueryId\022\031\n\021major_fragment_id\030\002 \001(\005" +
+      "\022\031\n\021minor_fragment_id\030\003 \001(\005\022-\n\017parent_qu" +
+      "ery_id\030\004 \001(\0132\024.exec.shared.QueryIdB+\n\033or" +
+      "g.apache.drill.exec.protoB\nExecProtosH\001"
     };
     com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
       new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
@@ -725,7 +918,7 @@ public final class ExecProtos {
           internal_static_exec_bit_FragmentHandle_fieldAccessorTable = new
             com.google.protobuf.GeneratedMessage.FieldAccessorTable(
               internal_static_exec_bit_FragmentHandle_descriptor,
-              new java.lang.String[] { "QueryId", "MajorFragmentId", "MinorFragmentId", });
+              new java.lang.String[] { "QueryId", "MajorFragmentId", "MinorFragmentId", "ParentQueryId", });
           return null;
         }
       };