You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ve...@apache.org on 2016/08/08 20:49:49 UTC

[1/4] drill git commit: DRILL-4729: Add support for prepared statement implementation on server side

Repository: drill
Updated Branches:
  refs/heads/master ef6e522c9 -> 14f6ec7dd


http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/ColumnSearchability.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/ColumnSearchability.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/ColumnSearchability.java
new file mode 100644
index 0000000..826a896
--- /dev/null
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/ColumnSearchability.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.
+ */
+// Generated by http://code.google.com/p/protostuff/ ... DO NOT EDIT!
+// Generated from protobuf
+
+package org.apache.drill.exec.proto.beans;
+
+public enum ColumnSearchability implements com.dyuproject.protostuff.EnumLite<ColumnSearchability>
+{
+    UNKNOWN_SEARCHABILITY(0),
+    NONE(1),
+    CHAR(2),
+    NUMBER(3),
+    ALL(4);
+    
+    public final int number;
+    
+    private ColumnSearchability (int number)
+    {
+        this.number = number;
+    }
+    
+    public int getNumber()
+    {
+        return number;
+    }
+    
+    public static ColumnSearchability valueOf(int number)
+    {
+        switch(number) 
+        {
+            case 0: return UNKNOWN_SEARCHABILITY;
+            case 1: return NONE;
+            case 2: return CHAR;
+            case 3: return NUMBER;
+            case 4: return ALL;
+            default: return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/ColumnUpdatability.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/ColumnUpdatability.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/ColumnUpdatability.java
new file mode 100644
index 0000000..09adb4f
--- /dev/null
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/ColumnUpdatability.java
@@ -0,0 +1,51 @@
+/**
+ * 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;
+
+public enum ColumnUpdatability implements com.dyuproject.protostuff.EnumLite<ColumnUpdatability>
+{
+    UNKNOWN_UPDATABILITY(0),
+    READ_ONLY(1),
+    WRITABLE(2);
+    
+    public final int number;
+    
+    private ColumnUpdatability (int number)
+    {
+        this.number = number;
+    }
+    
+    public int getNumber()
+    {
+        return number;
+    }
+    
+    public static ColumnUpdatability valueOf(int number)
+    {
+        switch(number) 
+        {
+            case 0: return UNKNOWN_UPDATABILITY;
+            case 1: return READ_ONLY;
+            case 2: return WRITABLE;
+            default: return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/CreatePreparedStatementReq.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/CreatePreparedStatementReq.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/CreatePreparedStatementReq.java
new file mode 100644
index 0000000..dc86da5
--- /dev/null
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/CreatePreparedStatementReq.java
@@ -0,0 +1,163 @@
+/**
+ * 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;
+
+public final class CreatePreparedStatementReq implements Externalizable, Message<CreatePreparedStatementReq>, Schema<CreatePreparedStatementReq>
+{
+
+    public static Schema<CreatePreparedStatementReq> getSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    public static CreatePreparedStatementReq getDefaultInstance()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    static final CreatePreparedStatementReq DEFAULT_INSTANCE = new CreatePreparedStatementReq();
+
+    
+    private String sqlQuery;
+
+    public CreatePreparedStatementReq()
+    {
+        
+    }
+
+    // getters and setters
+
+    // sqlQuery
+
+    public String getSqlQuery()
+    {
+        return sqlQuery;
+    }
+
+    public CreatePreparedStatementReq setSqlQuery(String sqlQuery)
+    {
+        this.sqlQuery = sqlQuery;
+        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<CreatePreparedStatementReq> cachedSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    // schema methods
+
+    public CreatePreparedStatementReq newMessage()
+    {
+        return new CreatePreparedStatementReq();
+    }
+
+    public Class<CreatePreparedStatementReq> typeClass()
+    {
+        return CreatePreparedStatementReq.class;
+    }
+
+    public String messageName()
+    {
+        return CreatePreparedStatementReq.class.getSimpleName();
+    }
+
+    public String messageFullName()
+    {
+        return CreatePreparedStatementReq.class.getName();
+    }
+
+    public boolean isInitialized(CreatePreparedStatementReq message)
+    {
+        return true;
+    }
+
+    public void mergeFrom(Input input, CreatePreparedStatementReq message) throws IOException
+    {
+        for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+        {
+            switch(number)
+            {
+                case 0:
+                    return;
+                case 1:
+                    message.sqlQuery = input.readString();
+                    break;
+                default:
+                    input.handleUnknownField(number, this);
+            }   
+        }
+    }
+
+
+    public void writeTo(Output output, CreatePreparedStatementReq message) throws IOException
+    {
+        if(message.sqlQuery != null)
+            output.writeString(1, message.sqlQuery, false);
+    }
+
+    public String getFieldName(int number)
+    {
+        switch(number)
+        {
+            case 1: return "sqlQuery";
+            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("sqlQuery", 1);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/CreatePreparedStatementResp.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/CreatePreparedStatementResp.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/CreatePreparedStatementResp.java
new file mode 100644
index 0000000..afa3ea8
--- /dev/null
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/CreatePreparedStatementResp.java
@@ -0,0 +1,211 @@
+/**
+ * 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;
+
+public final class CreatePreparedStatementResp implements Externalizable, Message<CreatePreparedStatementResp>, Schema<CreatePreparedStatementResp>
+{
+
+    public static Schema<CreatePreparedStatementResp> getSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    public static CreatePreparedStatementResp getDefaultInstance()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    static final CreatePreparedStatementResp DEFAULT_INSTANCE = new CreatePreparedStatementResp();
+
+    
+    private RequestStatus status;
+    private PreparedStatement preparedStatement;
+    private DrillPBError error;
+
+    public CreatePreparedStatementResp()
+    {
+        
+    }
+
+    // getters and setters
+
+    // status
+
+    public RequestStatus getStatus()
+    {
+        return status == null ? RequestStatus.UNKNOWN_STATUS : status;
+    }
+
+    public CreatePreparedStatementResp setStatus(RequestStatus status)
+    {
+        this.status = status;
+        return this;
+    }
+
+    // preparedStatement
+
+    public PreparedStatement getPreparedStatement()
+    {
+        return preparedStatement;
+    }
+
+    public CreatePreparedStatementResp setPreparedStatement(PreparedStatement preparedStatement)
+    {
+        this.preparedStatement = preparedStatement;
+        return this;
+    }
+
+    // error
+
+    public DrillPBError getError()
+    {
+        return error;
+    }
+
+    public CreatePreparedStatementResp 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<CreatePreparedStatementResp> cachedSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    // schema methods
+
+    public CreatePreparedStatementResp newMessage()
+    {
+        return new CreatePreparedStatementResp();
+    }
+
+    public Class<CreatePreparedStatementResp> typeClass()
+    {
+        return CreatePreparedStatementResp.class;
+    }
+
+    public String messageName()
+    {
+        return CreatePreparedStatementResp.class.getSimpleName();
+    }
+
+    public String messageFullName()
+    {
+        return CreatePreparedStatementResp.class.getName();
+    }
+
+    public boolean isInitialized(CreatePreparedStatementResp message)
+    {
+        return true;
+    }
+
+    public void mergeFrom(Input input, CreatePreparedStatementResp message) throws IOException
+    {
+        for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+        {
+            switch(number)
+            {
+                case 0:
+                    return;
+                case 1:
+                    message.status = RequestStatus.valueOf(input.readEnum());
+                    break;
+                case 2:
+                    message.preparedStatement = input.mergeObject(message.preparedStatement, PreparedStatement.getSchema());
+                    break;
+
+                case 3:
+                    message.error = input.mergeObject(message.error, DrillPBError.getSchema());
+                    break;
+
+                default:
+                    input.handleUnknownField(number, this);
+            }   
+        }
+    }
+
+
+    public void writeTo(Output output, CreatePreparedStatementResp message) throws IOException
+    {
+        if(message.status != null)
+             output.writeEnum(1, message.status.number, false);
+
+        if(message.preparedStatement != null)
+             output.writeObject(2, message.preparedStatement, PreparedStatement.getSchema(), false);
+
+
+        if(message.error != null)
+             output.writeObject(3, message.error, DrillPBError.getSchema(), false);
+
+    }
+
+    public String getFieldName(int number)
+    {
+        switch(number)
+        {
+            case 1: return "status";
+            case 2: return "preparedStatement";
+            case 3: 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("preparedStatement", 2);
+        __fieldMap.put("error", 3);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetCatalogsResp.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetCatalogsResp.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetCatalogsResp.java
index d71062d..d6b9475 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetCatalogsResp.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetCatalogsResp.java
@@ -64,7 +64,7 @@ public final class GetCatalogsResp implements Externalizable, Message<GetCatalog
 
     public RequestStatus getStatus()
     {
-        return status == null ? RequestStatus.UNKNOWN : status;
+        return status == null ? RequestStatus.UNKNOWN_STATUS : status;
     }
 
     public GetCatalogsResp setStatus(RequestStatus status)

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetColumnsResp.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetColumnsResp.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetColumnsResp.java
index dc22c85..f527719 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetColumnsResp.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetColumnsResp.java
@@ -64,7 +64,7 @@ public final class GetColumnsResp implements Externalizable, Message<GetColumnsR
 
     public RequestStatus getStatus()
     {
-        return status == null ? RequestStatus.UNKNOWN : status;
+        return status == null ? RequestStatus.UNKNOWN_STATUS : status;
     }
 
     public GetColumnsResp setStatus(RequestStatus status)

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetSchemasResp.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetSchemasResp.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetSchemasResp.java
index 3dc5e84..f604abc 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetSchemasResp.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetSchemasResp.java
@@ -64,7 +64,7 @@ public final class GetSchemasResp implements Externalizable, Message<GetSchemasR
 
     public RequestStatus getStatus()
     {
-        return status == null ? RequestStatus.UNKNOWN : status;
+        return status == null ? RequestStatus.UNKNOWN_STATUS : status;
     }
 
     public GetSchemasResp setStatus(RequestStatus status)

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetTablesResp.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetTablesResp.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetTablesResp.java
index c62ed3c..b06cf0c 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetTablesResp.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/GetTablesResp.java
@@ -64,7 +64,7 @@ public final class GetTablesResp implements Externalizable, Message<GetTablesRes
 
     public RequestStatus getStatus()
     {
-        return status == null ? RequestStatus.UNKNOWN : status;
+        return status == null ? RequestStatus.UNKNOWN_STATUS : status;
     }
 
     public GetTablesResp setStatus(RequestStatus status)

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/PreparedStatement.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/PreparedStatement.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/PreparedStatement.java
new file mode 100644
index 0000000..9ec4e8f
--- /dev/null
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/PreparedStatement.java
@@ -0,0 +1,199 @@
+/**
+ * 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;
+
+public final class PreparedStatement implements Externalizable, Message<PreparedStatement>, Schema<PreparedStatement>
+{
+
+    public static Schema<PreparedStatement> getSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    public static PreparedStatement getDefaultInstance()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    static final PreparedStatement DEFAULT_INSTANCE = new PreparedStatement();
+
+    
+    private List<ResultColumnMetadata> columns;
+    private PreparedStatementHandle serverHandle;
+
+    public PreparedStatement()
+    {
+        
+    }
+
+    // getters and setters
+
+    // columns
+
+    public List<ResultColumnMetadata> getColumnsList()
+    {
+        return columns;
+    }
+
+    public PreparedStatement setColumnsList(List<ResultColumnMetadata> columns)
+    {
+        this.columns = columns;
+        return this;
+    }
+
+    // serverHandle
+
+    public PreparedStatementHandle getServerHandle()
+    {
+        return serverHandle;
+    }
+
+    public PreparedStatement setServerHandle(PreparedStatementHandle serverHandle)
+    {
+        this.serverHandle = serverHandle;
+        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<PreparedStatement> cachedSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    // schema methods
+
+    public PreparedStatement newMessage()
+    {
+        return new PreparedStatement();
+    }
+
+    public Class<PreparedStatement> typeClass()
+    {
+        return PreparedStatement.class;
+    }
+
+    public String messageName()
+    {
+        return PreparedStatement.class.getSimpleName();
+    }
+
+    public String messageFullName()
+    {
+        return PreparedStatement.class.getName();
+    }
+
+    public boolean isInitialized(PreparedStatement message)
+    {
+        return true;
+    }
+
+    public void mergeFrom(Input input, PreparedStatement message) throws IOException
+    {
+        for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+        {
+            switch(number)
+            {
+                case 0:
+                    return;
+                case 1:
+                    if(message.columns == null)
+                        message.columns = new ArrayList<ResultColumnMetadata>();
+                    message.columns.add(input.mergeObject(null, ResultColumnMetadata.getSchema()));
+                    break;
+
+                case 2:
+                    message.serverHandle = input.mergeObject(message.serverHandle, PreparedStatementHandle.getSchema());
+                    break;
+
+                default:
+                    input.handleUnknownField(number, this);
+            }   
+        }
+    }
+
+
+    public void writeTo(Output output, PreparedStatement message) throws IOException
+    {
+        if(message.columns != null)
+        {
+            for(ResultColumnMetadata columns : message.columns)
+            {
+                if(columns != null)
+                    output.writeObject(1, columns, ResultColumnMetadata.getSchema(), true);
+            }
+        }
+
+
+        if(message.serverHandle != null)
+             output.writeObject(2, message.serverHandle, PreparedStatementHandle.getSchema(), false);
+
+    }
+
+    public String getFieldName(int number)
+    {
+        switch(number)
+        {
+            case 1: return "columns";
+            case 2: return "serverHandle";
+            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("columns", 1);
+        __fieldMap.put("serverHandle", 2);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/PreparedStatementHandle.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/PreparedStatementHandle.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/PreparedStatementHandle.java
new file mode 100644
index 0000000..c35c7ce
--- /dev/null
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/PreparedStatementHandle.java
@@ -0,0 +1,164 @@
+/**
+ * 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.ByteString;
+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;
+
+public final class PreparedStatementHandle implements Externalizable, Message<PreparedStatementHandle>, Schema<PreparedStatementHandle>
+{
+
+    public static Schema<PreparedStatementHandle> getSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    public static PreparedStatementHandle getDefaultInstance()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    static final PreparedStatementHandle DEFAULT_INSTANCE = new PreparedStatementHandle();
+
+    
+    private ByteString serverInfo;
+
+    public PreparedStatementHandle()
+    {
+        
+    }
+
+    // getters and setters
+
+    // serverInfo
+
+    public ByteString getServerInfo()
+    {
+        return serverInfo;
+    }
+
+    public PreparedStatementHandle setServerInfo(ByteString serverInfo)
+    {
+        this.serverInfo = serverInfo;
+        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<PreparedStatementHandle> cachedSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    // schema methods
+
+    public PreparedStatementHandle newMessage()
+    {
+        return new PreparedStatementHandle();
+    }
+
+    public Class<PreparedStatementHandle> typeClass()
+    {
+        return PreparedStatementHandle.class;
+    }
+
+    public String messageName()
+    {
+        return PreparedStatementHandle.class.getSimpleName();
+    }
+
+    public String messageFullName()
+    {
+        return PreparedStatementHandle.class.getName();
+    }
+
+    public boolean isInitialized(PreparedStatementHandle message)
+    {
+        return true;
+    }
+
+    public void mergeFrom(Input input, PreparedStatementHandle message) throws IOException
+    {
+        for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+        {
+            switch(number)
+            {
+                case 0:
+                    return;
+                case 1:
+                    message.serverInfo = input.readBytes();
+                    break;
+                default:
+                    input.handleUnknownField(number, this);
+            }   
+        }
+    }
+
+
+    public void writeTo(Output output, PreparedStatementHandle message) throws IOException
+    {
+        if(message.serverInfo != null)
+            output.writeBytes(1, message.serverInfo, false);
+    }
+
+    public String getFieldName(int number)
+    {
+        switch(number)
+        {
+            case 1: return "serverInfo";
+            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("serverInfo", 1);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 71f98f3..7a4320d 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
@@ -25,7 +25,8 @@ public enum QueryType implements com.dyuproject.protostuff.EnumLite<QueryType>
     SQL(1),
     LOGICAL(2),
     PHYSICAL(3),
-    EXECUTION(4);
+    EXECUTION(4),
+    PREPARED_STATEMENT(5);
     
     public final int number;
     
@@ -47,6 +48,7 @@ public enum QueryType implements com.dyuproject.protostuff.EnumLite<QueryType>
             case 2: return LOGICAL;
             case 3: return PHYSICAL;
             case 4: return EXECUTION;
+            case 5: return PREPARED_STATEMENT;
             default: return null;
         }
     }

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/RequestStatus.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/RequestStatus.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/RequestStatus.java
index f526ab5..2e08a4a 100644
--- a/protocol/src/main/java/org/apache/drill/exec/proto/beans/RequestStatus.java
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/RequestStatus.java
@@ -22,9 +22,10 @@ package org.apache.drill.exec.proto.beans;
 
 public enum RequestStatus implements com.dyuproject.protostuff.EnumLite<RequestStatus>
 {
-    UNKNOWN(0),
+    UNKNOWN_STATUS(0),
     OK(1),
-    FAILED(2);
+    FAILED(2),
+    TIMEOUT(3);
     
     public final int number;
     
@@ -42,9 +43,10 @@ public enum RequestStatus implements com.dyuproject.protostuff.EnumLite<RequestS
     {
         switch(number) 
         {
-            case 0: return UNKNOWN;
+            case 0: return UNKNOWN_STATUS;
             case 1: return OK;
             case 2: return FAILED;
+            case 3: return TIMEOUT;
             default: return null;
         }
     }

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/ResultColumnMetadata.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/ResultColumnMetadata.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/ResultColumnMetadata.java
new file mode 100644
index 0000000..7af4ed5
--- /dev/null
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/ResultColumnMetadata.java
@@ -0,0 +1,559 @@
+/**
+ * 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;
+
+public final class ResultColumnMetadata implements Externalizable, Message<ResultColumnMetadata>, Schema<ResultColumnMetadata>
+{
+
+    public static Schema<ResultColumnMetadata> getSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    public static ResultColumnMetadata getDefaultInstance()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    static final ResultColumnMetadata DEFAULT_INSTANCE = new ResultColumnMetadata();
+
+    
+    private String catalogName;
+    private String schemaName;
+    private String tableName;
+    private String columnName;
+    private String label;
+    private String dataType;
+    private Boolean isNullable;
+    private int precision;
+    private int scale;
+    private Boolean signed;
+    private int displaySize;
+    private Boolean isAliased;
+    private ColumnSearchability searchability;
+    private ColumnUpdatability updatability;
+    private Boolean autoIncrement;
+    private Boolean caseSensitivity;
+    private Boolean sortable;
+    private String className;
+    private Boolean isCurrency;
+
+    public ResultColumnMetadata()
+    {
+        
+    }
+
+    // getters and setters
+
+    // catalogName
+
+    public String getCatalogName()
+    {
+        return catalogName;
+    }
+
+    public ResultColumnMetadata setCatalogName(String catalogName)
+    {
+        this.catalogName = catalogName;
+        return this;
+    }
+
+    // schemaName
+
+    public String getSchemaName()
+    {
+        return schemaName;
+    }
+
+    public ResultColumnMetadata setSchemaName(String schemaName)
+    {
+        this.schemaName = schemaName;
+        return this;
+    }
+
+    // tableName
+
+    public String getTableName()
+    {
+        return tableName;
+    }
+
+    public ResultColumnMetadata setTableName(String tableName)
+    {
+        this.tableName = tableName;
+        return this;
+    }
+
+    // columnName
+
+    public String getColumnName()
+    {
+        return columnName;
+    }
+
+    public ResultColumnMetadata setColumnName(String columnName)
+    {
+        this.columnName = columnName;
+        return this;
+    }
+
+    // label
+
+    public String getLabel()
+    {
+        return label;
+    }
+
+    public ResultColumnMetadata setLabel(String label)
+    {
+        this.label = label;
+        return this;
+    }
+
+    // dataType
+
+    public String getDataType()
+    {
+        return dataType;
+    }
+
+    public ResultColumnMetadata setDataType(String dataType)
+    {
+        this.dataType = dataType;
+        return this;
+    }
+
+    // isNullable
+
+    public Boolean getIsNullable()
+    {
+        return isNullable;
+    }
+
+    public ResultColumnMetadata setIsNullable(Boolean isNullable)
+    {
+        this.isNullable = isNullable;
+        return this;
+    }
+
+    // precision
+
+    public int getPrecision()
+    {
+        return precision;
+    }
+
+    public ResultColumnMetadata setPrecision(int precision)
+    {
+        this.precision = precision;
+        return this;
+    }
+
+    // scale
+
+    public int getScale()
+    {
+        return scale;
+    }
+
+    public ResultColumnMetadata setScale(int scale)
+    {
+        this.scale = scale;
+        return this;
+    }
+
+    // signed
+
+    public Boolean getSigned()
+    {
+        return signed;
+    }
+
+    public ResultColumnMetadata setSigned(Boolean signed)
+    {
+        this.signed = signed;
+        return this;
+    }
+
+    // displaySize
+
+    public int getDisplaySize()
+    {
+        return displaySize;
+    }
+
+    public ResultColumnMetadata setDisplaySize(int displaySize)
+    {
+        this.displaySize = displaySize;
+        return this;
+    }
+
+    // isAliased
+
+    public Boolean getIsAliased()
+    {
+        return isAliased;
+    }
+
+    public ResultColumnMetadata setIsAliased(Boolean isAliased)
+    {
+        this.isAliased = isAliased;
+        return this;
+    }
+
+    // searchability
+
+    public ColumnSearchability getSearchability()
+    {
+        return searchability == null ? ColumnSearchability.UNKNOWN_SEARCHABILITY : searchability;
+    }
+
+    public ResultColumnMetadata setSearchability(ColumnSearchability searchability)
+    {
+        this.searchability = searchability;
+        return this;
+    }
+
+    // updatability
+
+    public ColumnUpdatability getUpdatability()
+    {
+        return updatability == null ? ColumnUpdatability.UNKNOWN_UPDATABILITY : updatability;
+    }
+
+    public ResultColumnMetadata setUpdatability(ColumnUpdatability updatability)
+    {
+        this.updatability = updatability;
+        return this;
+    }
+
+    // autoIncrement
+
+    public Boolean getAutoIncrement()
+    {
+        return autoIncrement;
+    }
+
+    public ResultColumnMetadata setAutoIncrement(Boolean autoIncrement)
+    {
+        this.autoIncrement = autoIncrement;
+        return this;
+    }
+
+    // caseSensitivity
+
+    public Boolean getCaseSensitivity()
+    {
+        return caseSensitivity;
+    }
+
+    public ResultColumnMetadata setCaseSensitivity(Boolean caseSensitivity)
+    {
+        this.caseSensitivity = caseSensitivity;
+        return this;
+    }
+
+    // sortable
+
+    public Boolean getSortable()
+    {
+        return sortable;
+    }
+
+    public ResultColumnMetadata setSortable(Boolean sortable)
+    {
+        this.sortable = sortable;
+        return this;
+    }
+
+    // className
+
+    public String getClassName()
+    {
+        return className;
+    }
+
+    public ResultColumnMetadata setClassName(String className)
+    {
+        this.className = className;
+        return this;
+    }
+
+    // isCurrency
+
+    public Boolean getIsCurrency()
+    {
+        return isCurrency;
+    }
+
+    public ResultColumnMetadata setIsCurrency(Boolean isCurrency)
+    {
+        this.isCurrency = isCurrency;
+        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<ResultColumnMetadata> cachedSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    // schema methods
+
+    public ResultColumnMetadata newMessage()
+    {
+        return new ResultColumnMetadata();
+    }
+
+    public Class<ResultColumnMetadata> typeClass()
+    {
+        return ResultColumnMetadata.class;
+    }
+
+    public String messageName()
+    {
+        return ResultColumnMetadata.class.getSimpleName();
+    }
+
+    public String messageFullName()
+    {
+        return ResultColumnMetadata.class.getName();
+    }
+
+    public boolean isInitialized(ResultColumnMetadata message)
+    {
+        return true;
+    }
+
+    public void mergeFrom(Input input, ResultColumnMetadata message) throws IOException
+    {
+        for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+        {
+            switch(number)
+            {
+                case 0:
+                    return;
+                case 1:
+                    message.catalogName = input.readString();
+                    break;
+                case 2:
+                    message.schemaName = input.readString();
+                    break;
+                case 3:
+                    message.tableName = input.readString();
+                    break;
+                case 4:
+                    message.columnName = input.readString();
+                    break;
+                case 5:
+                    message.label = input.readString();
+                    break;
+                case 6:
+                    message.dataType = input.readString();
+                    break;
+                case 7:
+                    message.isNullable = input.readBool();
+                    break;
+                case 8:
+                    message.precision = input.readInt32();
+                    break;
+                case 9:
+                    message.scale = input.readInt32();
+                    break;
+                case 10:
+                    message.signed = input.readBool();
+                    break;
+                case 11:
+                    message.displaySize = input.readInt32();
+                    break;
+                case 12:
+                    message.isAliased = input.readBool();
+                    break;
+                case 13:
+                    message.searchability = ColumnSearchability.valueOf(input.readEnum());
+                    break;
+                case 14:
+                    message.updatability = ColumnUpdatability.valueOf(input.readEnum());
+                    break;
+                case 15:
+                    message.autoIncrement = input.readBool();
+                    break;
+                case 16:
+                    message.caseSensitivity = input.readBool();
+                    break;
+                case 17:
+                    message.sortable = input.readBool();
+                    break;
+                case 18:
+                    message.className = input.readString();
+                    break;
+                case 20:
+                    message.isCurrency = input.readBool();
+                    break;
+                default:
+                    input.handleUnknownField(number, this);
+            }   
+        }
+    }
+
+
+    public void writeTo(Output output, ResultColumnMetadata message) throws IOException
+    {
+        if(message.catalogName != null)
+            output.writeString(1, message.catalogName, false);
+
+        if(message.schemaName != null)
+            output.writeString(2, message.schemaName, false);
+
+        if(message.tableName != null)
+            output.writeString(3, message.tableName, false);
+
+        if(message.columnName != null)
+            output.writeString(4, message.columnName, false);
+
+        if(message.label != null)
+            output.writeString(5, message.label, false);
+
+        if(message.dataType != null)
+            output.writeString(6, message.dataType, false);
+
+        if(message.isNullable != null)
+            output.writeBool(7, message.isNullable, false);
+
+        if(message.precision != 0)
+            output.writeInt32(8, message.precision, false);
+
+        if(message.scale != 0)
+            output.writeInt32(9, message.scale, false);
+
+        if(message.signed != null)
+            output.writeBool(10, message.signed, false);
+
+        if(message.displaySize != 0)
+            output.writeInt32(11, message.displaySize, false);
+
+        if(message.isAliased != null)
+            output.writeBool(12, message.isAliased, false);
+
+        if(message.searchability != null)
+             output.writeEnum(13, message.searchability.number, false);
+
+        if(message.updatability != null)
+             output.writeEnum(14, message.updatability.number, false);
+
+        if(message.autoIncrement != null)
+            output.writeBool(15, message.autoIncrement, false);
+
+        if(message.caseSensitivity != null)
+            output.writeBool(16, message.caseSensitivity, false);
+
+        if(message.sortable != null)
+            output.writeBool(17, message.sortable, false);
+
+        if(message.className != null)
+            output.writeString(18, message.className, false);
+
+        if(message.isCurrency != null)
+            output.writeBool(20, message.isCurrency, false);
+    }
+
+    public String getFieldName(int number)
+    {
+        switch(number)
+        {
+            case 1: return "catalogName";
+            case 2: return "schemaName";
+            case 3: return "tableName";
+            case 4: return "columnName";
+            case 5: return "label";
+            case 6: return "dataType";
+            case 7: return "isNullable";
+            case 8: return "precision";
+            case 9: return "scale";
+            case 10: return "signed";
+            case 11: return "displaySize";
+            case 12: return "isAliased";
+            case 13: return "searchability";
+            case 14: return "updatability";
+            case 15: return "autoIncrement";
+            case 16: return "caseSensitivity";
+            case 17: return "sortable";
+            case 18: return "className";
+            case 20: return "isCurrency";
+            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("catalogName", 1);
+        __fieldMap.put("schemaName", 2);
+        __fieldMap.put("tableName", 3);
+        __fieldMap.put("columnName", 4);
+        __fieldMap.put("label", 5);
+        __fieldMap.put("dataType", 6);
+        __fieldMap.put("isNullable", 7);
+        __fieldMap.put("precision", 8);
+        __fieldMap.put("scale", 9);
+        __fieldMap.put("signed", 10);
+        __fieldMap.put("displaySize", 11);
+        __fieldMap.put("isAliased", 12);
+        __fieldMap.put("searchability", 13);
+        __fieldMap.put("updatability", 14);
+        __fieldMap.put("autoIncrement", 15);
+        __fieldMap.put("caseSensitivity", 16);
+        __fieldMap.put("sortable", 17);
+        __fieldMap.put("className", 18);
+        __fieldMap.put("isCurrency", 20);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 ff4f4bc..923a76a 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
@@ -34,6 +34,7 @@ public enum RpcType implements com.dyuproject.protostuff.EnumLite<RpcType>
     GET_SCHEMAS(15),
     GET_TABLES(16),
     GET_COLUMNS(17),
+    CREATE_PREPARED_STATEMENT(22),
     QUERY_DATA(6),
     QUERY_HANDLE(7),
     QUERY_PLAN_FRAGMENTS(13),
@@ -41,6 +42,7 @@ public enum RpcType implements com.dyuproject.protostuff.EnumLite<RpcType>
     SCHEMAS(19),
     TABLES(20),
     COLUMNS(21),
+    PREPARED_STATEMENT(23),
     REQ_META_FUNCTIONS(8),
     RESP_FUNCTION_LIST(9),
     QUERY_RESULT(10);
@@ -83,6 +85,8 @@ public enum RpcType implements com.dyuproject.protostuff.EnumLite<RpcType>
             case 19: return SCHEMAS;
             case 20: return TABLES;
             case 21: return COLUMNS;
+            case 22: return CREATE_PREPARED_STATEMENT;
+            case 23: return PREPARED_STATEMENT;
             default: return null;
         }
     }

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 e6035d1..d338b4d 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
@@ -53,6 +53,7 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
     private QueryType type;
     private String plan;
     private List<PlanFragment> fragments;
+    private PreparedStatementHandle preparedStatementHandle;
 
     public RunQuery()
     {
@@ -113,6 +114,19 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
         return this;
     }
 
+    // preparedStatementHandle
+
+    public PreparedStatementHandle getPreparedStatementHandle()
+    {
+        return preparedStatementHandle;
+    }
+
+    public RunQuery setPreparedStatementHandle(PreparedStatementHandle preparedStatementHandle)
+    {
+        this.preparedStatementHandle = preparedStatementHandle;
+        return this;
+    }
+
     // java serialization
 
     public void readExternal(ObjectInput in) throws IOException
@@ -182,6 +196,10 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
                     message.fragments.add(input.mergeObject(null, PlanFragment.getSchema()));
                     break;
 
+                case 5:
+                    message.preparedStatementHandle = input.mergeObject(message.preparedStatementHandle, PreparedStatementHandle.getSchema());
+                    break;
+
                 default:
                     input.handleUnknownField(number, this);
             }   
@@ -209,6 +227,10 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
             }
         }
 
+
+        if(message.preparedStatementHandle != null)
+             output.writeObject(5, message.preparedStatementHandle, PreparedStatementHandle.getSchema(), false);
+
     }
 
     public String getFieldName(int number)
@@ -219,6 +241,7 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
             case 2: return "type";
             case 3: return "plan";
             case 4: return "fragments";
+            case 5: return "preparedStatementHandle";
             default: return null;
         }
     }
@@ -236,6 +259,7 @@ public final class RunQuery implements Externalizable, Message<RunQuery>, Schema
         __fieldMap.put("type", 2);
         __fieldMap.put("plan", 3);
         __fieldMap.put("fragments", 4);
+        __fieldMap.put("preparedStatementHandle", 5);
     }
     
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/java/org/apache/drill/exec/proto/beans/ServerPreparedStatementState.java
----------------------------------------------------------------------
diff --git a/protocol/src/main/java/org/apache/drill/exec/proto/beans/ServerPreparedStatementState.java b/protocol/src/main/java/org/apache/drill/exec/proto/beans/ServerPreparedStatementState.java
new file mode 100644
index 0000000..ad2118c
--- /dev/null
+++ b/protocol/src/main/java/org/apache/drill/exec/proto/beans/ServerPreparedStatementState.java
@@ -0,0 +1,163 @@
+/**
+ * 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;
+
+public final class ServerPreparedStatementState implements Externalizable, Message<ServerPreparedStatementState>, Schema<ServerPreparedStatementState>
+{
+
+    public static Schema<ServerPreparedStatementState> getSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    public static ServerPreparedStatementState getDefaultInstance()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    static final ServerPreparedStatementState DEFAULT_INSTANCE = new ServerPreparedStatementState();
+
+    
+    private String sqlQuery;
+
+    public ServerPreparedStatementState()
+    {
+        
+    }
+
+    // getters and setters
+
+    // sqlQuery
+
+    public String getSqlQuery()
+    {
+        return sqlQuery;
+    }
+
+    public ServerPreparedStatementState setSqlQuery(String sqlQuery)
+    {
+        this.sqlQuery = sqlQuery;
+        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<ServerPreparedStatementState> cachedSchema()
+    {
+        return DEFAULT_INSTANCE;
+    }
+
+    // schema methods
+
+    public ServerPreparedStatementState newMessage()
+    {
+        return new ServerPreparedStatementState();
+    }
+
+    public Class<ServerPreparedStatementState> typeClass()
+    {
+        return ServerPreparedStatementState.class;
+    }
+
+    public String messageName()
+    {
+        return ServerPreparedStatementState.class.getSimpleName();
+    }
+
+    public String messageFullName()
+    {
+        return ServerPreparedStatementState.class.getName();
+    }
+
+    public boolean isInitialized(ServerPreparedStatementState message)
+    {
+        return true;
+    }
+
+    public void mergeFrom(Input input, ServerPreparedStatementState message) throws IOException
+    {
+        for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+        {
+            switch(number)
+            {
+                case 0:
+                    return;
+                case 1:
+                    message.sqlQuery = input.readString();
+                    break;
+                default:
+                    input.handleUnknownField(number, this);
+            }   
+        }
+    }
+
+
+    public void writeTo(Output output, ServerPreparedStatementState message) throws IOException
+    {
+        if(message.sqlQuery != null)
+            output.writeString(1, message.sqlQuery, false);
+    }
+
+    public String getFieldName(int number)
+    {
+        switch(number)
+        {
+            case 1: return "sqlQuery";
+            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("sqlQuery", 1);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/protobuf/ExecutionProtos.proto
----------------------------------------------------------------------
diff --git a/protocol/src/main/protobuf/ExecutionProtos.proto b/protocol/src/main/protobuf/ExecutionProtos.proto
index 36cd12b..58ca5ad 100644
--- a/protocol/src/main/protobuf/ExecutionProtos.proto
+++ b/protocol/src/main/protobuf/ExecutionProtos.proto
@@ -14,3 +14,12 @@ message FragmentHandle {
 	optional exec.shared.QueryId parent_query_id = 4;
 }
 
+/*
+ * Prepared statement state on server side. Clients do not
+ * need to know the contents. They just need to submit it back to
+ * server when executing the prepared statement.
+ */
+message ServerPreparedStatementState {
+  optional string sql_query = 1;
+}
+

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/protobuf/User.proto
----------------------------------------------------------------------
diff --git a/protocol/src/main/protobuf/User.proto b/protocol/src/main/protobuf/User.proto
index 6af6fcf..3bb1495 100644
--- a/protocol/src/main/protobuf/User.proto
+++ b/protocol/src/main/protobuf/User.proto
@@ -27,6 +27,7 @@ enum RpcType {
   GET_SCHEMAS = 15; // user is requesting metadata of schema(s)
   GET_TABLES = 16; // user is requesting metadata of table(s)
   GET_COLUMNS = 17; // user is requesting metadata of column(s)
+  CREATE_PREPARED_STATEMENT = 22; // user is sending a request to create prepared statement
 
   // bit to user
   QUERY_DATA = 6; // drillbit is sending a query result data batch to the user
@@ -36,6 +37,7 @@ enum RpcType {
   SCHEMAS = 19; // return schema metadata in response to GET_SCHEMAS
   TABLES = 20; // return table metadata in response to GET_TABLES
   COLUMNS = 21; // return column metadata in response to GET_COLUMNS
+  PREPARED_STATEMENT = 23; // return preparated statement in response to CREATE_PREPARED_STATEMENT
 
   REQ_META_FUNCTIONS = 8;
   RESP_FUNCTION_LIST = 9;
@@ -67,13 +69,6 @@ message RequestResults {
   optional int32 maximum_responses = 2;
 }
 
-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;
@@ -111,9 +106,14 @@ message BitToUserHandshake {
  * Enum indicating the request status.
  */
 enum RequestStatus {
-  UNKNOWN = 0;
+  UNKNOWN_STATUS = 0;
   OK = 1;
   FAILED = 2;
+
+  /**
+   * Request timed out. Futher attempts can change any API specific parameters and retry or just retry the request.
+   */
+  TIMEOUT = 3;
 }
 
 /*
@@ -244,4 +244,194 @@ message GetColumnsResp {
   optional RequestStatus status = 1;
   repeated ColumnMetadata columns = 2;
   optional exec.shared.DrillPBError error = 3;
-}
\ No newline at end of file
+}
+
+/*
+ * Request message to create a prepared statement. Currently prepared
+ * statement only accepts a SQL query. Query parameter support is not
+ * included in current implementation.
+ */
+message CreatePreparedStatementReq {
+  optional string sql_query = 1;
+}
+
+/*
+ * How a column can be used in WHERE clause
+ */
+enum ColumnSearchability {
+  UNKNOWN_SEARCHABILITY = 0;
+  NONE = 1; // can't be used in WHERE clause
+  CHAR = 2; // can be used in WHERE clause but only with LIKE predicate
+  NUMBER = 3; // can be used in a WHERE clause with all the comparison operators except LIKE
+  ALL = 4; // can be used in a WHERE clause with all the comparison operators
+}
+
+/*
+ * Whether a column can be updatable.
+ */
+enum ColumnUpdatability {
+  UNKNOWN_UPDATABILITY = 0;
+  READ_ONLY = 1;
+  WRITABLE = 2;
+}
+
+/*
+ * Metadata of a column in query result set
+ */
+message ResultColumnMetadata {
+  /*
+   * Designated column's catalog name. Empty string if not applicable.
+   * Defaults to "DRILL" as drill has only one catalog.
+   */
+  optional string catalog_name = 1;
+
+  /*
+   * Designated column's schema name. Not set if not applicable. Initial implementation
+   * defaults to no value as we use LIMIT 0 queries to get the schema and schema info
+   * is lost. If we derive the schema from plan, we may get the right value.
+   */
+  optional string schema_name = 2;
+
+  /*
+   * Designated column's table name. Not set if not applicable. Initial implementation
+   * defaults to no value as we use LIMIT 0 queries to get the schema and table info
+   * is lost. If we derive the schema from query plan, we may get the right value.
+   */
+  optional string table_name = 3;
+  optional string column_name = 4; // column name
+
+  /*
+   * Column label name for display or print purposes.
+   * Ex. a column named "empName" might be labeled as "Employee Name".
+   */
+  optional string label = 5;
+
+  /*
+   * Data type in string format. Value is SQL standard type.
+   */
+  optional string data_type = 6;
+
+  optional bool is_nullable = 7;
+
+  /*
+   * For numeric data, this is the maximum precision.
+   * For character data, this is the length in characters.
+   * For datetime datatypes, this is the length in characters of the String representation
+   *    (assuming the maximum allowed precision of the fractional seconds component).
+   * For binary data, this is the length in bytes.
+   * For all other types 0 is returned where the column size is not applicable.
+   */
+  optional int32 precision = 8;
+
+  /*
+   * Column's number of digits to right of the decimal point.
+   * 0 is returned for types where the scale is not applicable
+   */
+  optional int32 scale = 9;
+
+  /*
+   * Indicates whether values in the designated column are signed numbers.
+   */
+  optional bool signed = 10;
+
+  /*
+   * Maximum number of characters required to display data from the column.
+   */
+  optional int32 display_size = 11;
+
+  /*
+   * Is the column an aliased column. Initial implementation defaults to
+   * true as we derive schema from LIMIT 0 query and not the query plan.
+   */
+  optional bool is_aliased = 12;
+
+  optional ColumnSearchability searchability = 13;
+
+  /*
+   * Defaults to READ_ONLU
+   */
+  optional ColumnUpdatability updatability = 14;
+
+  /*
+   * whether the designated column is automatically incremented.
+   */
+  optional bool auto_increment = 15;
+
+  /*
+   * Whether column's case matters for collations and comparisons. Defaults to true.
+   */
+  optional bool case_sensitivity = 16;
+
+  /*
+   * whether the column can be used in ORDER BY clause
+   */
+  optional bool sortable = 17;
+
+  /*
+   * A fully-qualified name of the Java class whose instances are created
+   * if the method ResultSet.getObject is called to retrieve
+   * a value from the column. Applicable only to JDBC clients.
+   */
+  optional string class_name = 18;
+
+  /*
+   * Is the data type a currency type? For JDBC only.
+   */
+  optional bool is_currency = 20;
+}
+
+/*
+ * Server state of prepared statement. Contents are opaque to
+ * client. Client just need to submit this object in RunQuery to
+ * the prepared statement.
+ */
+message PreparedStatementHandle {
+  optional bytes server_info = 1;
+}
+
+/*
+ * Prepared statement. It contains the query metadata and handle to prepared
+ * statement state on server.
+ */
+message PreparedStatement {
+  repeated ResultColumnMetadata columns = 1;
+
+  /*
+   * In order to execute the prepared statement,
+   * clients need to submit this object in RunQuery message.
+   */
+  optional PreparedStatementHandle server_handle = 2;
+}
+
+/*
+ * Response message for CreatePreparedStatementReq.
+ */
+message CreatePreparedStatementResp {
+  optional RequestStatus status = 1;
+  optional PreparedStatement prepared_statement = 2;
+  optional exec.shared.DrillPBError error = 3;
+}
+
+/*
+ * Request message for running a query.
+ */
+message RunQuery {
+  optional QueryResultsMode results_mode = 1;
+  optional exec.shared.QueryType type = 2;
+
+  /*
+   * Input for query type LOGICAL, PHYSICAL or SQL.
+   */
+  optional string plan = 3;
+
+  /*
+   * Input for query type EXECUTION. Input is a set of executable fragments.
+   */
+  repeated exec.bit.control.PlanFragment fragments = 4;
+
+  /*
+   * Input for query type PREPARED_STATEMENT. Input is a prepared statement handle
+   * to state on server side which is returned in response to CreatePreparedStatementReq.
+   */
+  optional PreparedStatementHandle prepared_statement_handle = 5;
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/protocol/src/main/protobuf/UserBitShared.proto
----------------------------------------------------------------------
diff --git a/protocol/src/main/protobuf/UserBitShared.proto b/protocol/src/main/protobuf/UserBitShared.proto
index 2293dc0..cfbdbe6 100644
--- a/protocol/src/main/protobuf/UserBitShared.proto
+++ b/protocol/src/main/protobuf/UserBitShared.proto
@@ -19,6 +19,9 @@ enum QueryType {
   LOGICAL = 2;
   PHYSICAL = 3;
   EXECUTION = 4;
+
+  /* Input is a prepared statement */
+  PREPARED_STATEMENT = 5;
 }
 
 message UserCredentials {


[4/4] drill git commit: DRILL-4729: Add support for prepared statement implementation on server side

Posted by ve...@apache.org.
DRILL-4729: Add support for prepared statement implementation on server side

+ Add following APIs for Drill Java client
  - DrillRpcFuture<CreatePreparedStatementResp> createPreparedStatement(final String query)
  - void executePreparedStatement(final PreparedStatement preparedStatement, UserResultsListener resultsListener)
  - List<QueryDataBatch> executePreparedStatement(final PreparedStatement preparedStatement) (for testing purpose)

+ Separated out the interface from UserClientConnection. It makes it easy to have wrappers which need to
  tap the messages and data going to the actual client.

+ Implement CREATE_PREPARED_STATEMENT and handle RunQuery with PreparedStatement

+ Test changes to support prepared statement as query type

+ Add tests in TestPreparedStatementProvider

this closes #530


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

Branch: refs/heads/master
Commit: 14f6ec7dd9b010de6c884431e443eb788ce54339
Parents: ef6e522
Author: vkorukanti <ve...@dremio.com>
Authored: Mon Jun 13 11:20:25 2016 -0700
Committer: vkorukanti <ve...@dremio.com>
Committed: Mon Aug 8 13:47:49 2016 -0700

----------------------------------------------------------------------
 .../org/apache/drill/common/types/Types.java    |    41 +
 .../org/apache/drill/exec/ExecConstants.java    |     7 +
 .../apache/drill/exec/client/DrillClient.java   |    77 +-
 .../apache/drill/exec/rpc/user/UserClient.java  |     3 +
 .../drill/exec/rpc/user/UserRpcConfig.java      |     4 +
 .../apache/drill/exec/rpc/user/UserServer.java  |    99 +-
 .../server/options/SystemOptionManager.java     |     3 +-
 .../apache/drill/exec/work/foreman/Foreman.java |    46 +-
 .../work/prepare/PreparedStatementProvider.java |   400 +
 .../apache/drill/exec/work/user/UserWorker.java |     7 +
 .../java/org/apache/drill/BaseTestQuery.java    |    18 +-
 .../java/org/apache/drill/DrillTestWrapper.java |     8 +-
 .../test/java/org/apache/drill/TestBuilder.java |    37 +-
 .../prepare/TestPreparedStatementProvider.java  |   222 +
 .../org/apache/drill/exec/proto/ExecProtos.java |   502 +-
 .../drill/exec/proto/SchemaExecProtos.java      |   111 +
 .../drill/exec/proto/SchemaUserProtos.java      |   988 +-
 .../apache/drill/exec/proto/UserBitShared.java  |    67 +-
 .../org/apache/drill/exec/proto/UserProtos.java | 25966 +++++++++++------
 .../exec/proto/beans/ColumnSearchability.java   |    55 +
 .../exec/proto/beans/ColumnUpdatability.java    |    51 +
 .../proto/beans/CreatePreparedStatementReq.java |   163 +
 .../beans/CreatePreparedStatementResp.java      |   211 +
 .../drill/exec/proto/beans/GetCatalogsResp.java |     2 +-
 .../drill/exec/proto/beans/GetColumnsResp.java  |     2 +-
 .../drill/exec/proto/beans/GetSchemasResp.java  |     2 +-
 .../drill/exec/proto/beans/GetTablesResp.java   |     2 +-
 .../exec/proto/beans/PreparedStatement.java     |   199 +
 .../proto/beans/PreparedStatementHandle.java    |   164 +
 .../drill/exec/proto/beans/QueryType.java       |     4 +-
 .../drill/exec/proto/beans/RequestStatus.java   |     8 +-
 .../exec/proto/beans/ResultColumnMetadata.java  |   559 +
 .../apache/drill/exec/proto/beans/RpcType.java  |     4 +
 .../apache/drill/exec/proto/beans/RunQuery.java |    24 +
 .../beans/ServerPreparedStatementState.java     |   163 +
 .../src/main/protobuf/ExecutionProtos.proto     |     9 +
 protocol/src/main/protobuf/User.proto           |   208 +-
 protocol/src/main/protobuf/UserBitShared.proto  |     3 +
 38 files changed, 20685 insertions(+), 9754 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/common/src/main/java/org/apache/drill/common/types/Types.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/types/Types.java b/common/src/main/java/org/apache/drill/common/types/Types.java
index 74b313e..504b876 100644
--- a/common/src/main/java/org/apache/drill/common/types/Types.java
+++ b/common/src/main/java/org/apache/drill/common/types/Types.java
@@ -591,4 +591,45 @@ public class Types {
     return type != null ? "MajorType[" + TextFormat.shortDebugString(type) + "]" : "null";
   }
 
+  /**
+   * Get the <code>precision</code> of given type.
+   * @param majorType
+   * @return
+   */
+  public static int getPrecision(MajorType majorType) {
+    MinorType type = majorType.getMinorType();
+
+    if (type == MinorType.VARBINARY || type == MinorType.VARCHAR) {
+      return 65536;
+    }
+
+    if (majorType.hasPrecision()) {
+      return majorType.getPrecision();
+    }
+
+    return 0;
+  }
+
+  /**
+   * Get the <code>scale</code> of given type.
+   * @param majorType
+   * @return
+   */
+  public static int getScale(MajorType majorType) {
+    if (majorType.hasScale()) {
+      return majorType.getScale();
+    }
+
+    return 0;
+  }
+
+  /**
+   * Is the given type column be used in ORDER BY clause?
+   * @param type
+   * @return
+   */
+  public static boolean isSortable(MinorType type) {
+    // Currently only map and list columns are not sortable.
+    return type != MinorType.MAP && type != MinorType.LIST;
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java
index 64931a2..d6a210a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ExecConstants.java
@@ -330,4 +330,11 @@ public interface ExecConstants {
   String CODE_GEN_EXP_IN_METHOD_SIZE = "exec.java.compiler.exp_in_method_size";
   LongValidator CODE_GEN_EXP_IN_METHOD_SIZE_VALIDATOR = new LongValidator(CODE_GEN_EXP_IN_METHOD_SIZE, 50);
 
+  /**
+   * Timeout for create prepare statement request. If the request exceeds this timeout, then request is timed out.
+   * Default value is 10mins.
+   */
+  String CREATE_PREPARE_STATEMENT_TIMEOUT_MILLIS = "prepare.statement.create_timeout_ms";
+  OptionValidator CREATE_PREPARE_STATEMENT_TIMEOUT_MILLIS_VALIDATOR =
+      new PositiveLongValidator(CREATE_PREPARE_STATEMENT_TIMEOUT_MILLIS, Integer.MAX_VALUE, 10000);
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 8063778..e81a4fb 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
@@ -53,6 +53,8 @@ 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.CreatePreparedStatementReq;
+import org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp;
 import org.apache.drill.exec.proto.UserProtos.GetCatalogsResp;
 import org.apache.drill.exec.proto.UserProtos.GetCatalogsReq;
 import org.apache.drill.exec.proto.UserProtos.GetColumnsReq;
@@ -63,9 +65,11 @@ import org.apache.drill.exec.proto.UserProtos.GetSchemasResp;
 import org.apache.drill.exec.proto.UserProtos.GetTablesReq;
 import org.apache.drill.exec.proto.UserProtos.GetTablesResp;
 import org.apache.drill.exec.proto.UserProtos.LikeFilter;
+import org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle;
 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.RunQuery;
 import org.apache.drill.exec.proto.UserProtos.UserProperties;
 import org.apache.drill.exec.proto.helper.QueryIdHelper;
 import org.apache.drill.exec.rpc.BasicClientWithConnection.ServerConnection;
@@ -83,6 +87,7 @@ 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.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
 import com.google.common.util.concurrent.AbstractCheckedFuture;
 import com.google.common.util.concurrent.SettableFuture;
@@ -325,13 +330,22 @@ public class DrillClient implements Closeable, ConnectionThrottle {
   }
 
   /**
-   * Submits a Logical plan for direct execution (bypasses parsing)
+   * Submits a string based query plan for execution and returns the result batches. Supported query types are:
+   * <p><ul>
+   *  <li>{@link QueryType#LOGICAL}
+   *  <li>{@link QueryType#PHYSICAL}
+   *  <li>{@link QueryType#SQL}
+   * </ul>
    *
-   * @param plan the plan to execute
+   * @param type Query type
+   * @param plan Query to execute
    * @return a handle for the query result
    * @throws RpcException
    */
   public List<QueryDataBatch> runQuery(QueryType type, String plan) throws RpcException {
+    checkArgument(type == QueryType.LOGICAL || type == QueryType.PHYSICAL || type == QueryType.SQL,
+        String.format("Only query types %s, %s and %s are supported in this API",
+            QueryType.LOGICAL, QueryType.PHYSICAL, QueryType.SQL));
     final UserProtos.RunQuery query = newBuilder().setResultsMode(STREAM_FULL).setType(type).setPlan(plan).build();
     final ListHoldingResultsListener listener = new ListHoldingResultsListener(query);
     client.submitQuery(listener, query);
@@ -352,7 +366,8 @@ public class DrillClient implements Closeable, ConnectionThrottle {
   }
 
   /**
-   * Run query based on list of fragments that were supposedly produced during query planning phase
+   * Run query based on list of fragments that were supposedly produced during query planning phase. Supported
+   * query type is {@link QueryType#EXECUTION}
    * @param type
    * @param planFragments
    * @param resultsListener
@@ -512,6 +527,62 @@ public class DrillClient implements Closeable, ConnectionThrottle {
   }
 
   /**
+   * Create a prepared statement for given <code>query</code>.
+   *
+   * @param query
+   * @return
+   */
+  public DrillRpcFuture<CreatePreparedStatementResp> createPreparedStatement(final String query) {
+    final CreatePreparedStatementReq req =
+        CreatePreparedStatementReq.newBuilder()
+            .setSqlQuery(query)
+            .build();
+
+    return client.send(RpcType.CREATE_PREPARED_STATEMENT, req, CreatePreparedStatementResp.class);
+  }
+
+  /**
+   * Execute the given prepared statement.
+   *
+   * @param preparedStatementHandle Prepared statement handle returned in response to
+   *                                {@link #createPreparedStatement(String)}.
+   * @param resultsListener {@link UserResultsListener} instance for listening for query results.
+   */
+  public void executePreparedStatement(final PreparedStatementHandle preparedStatementHandle,
+      final UserResultsListener resultsListener) {
+    final RunQuery runQuery = newBuilder()
+        .setResultsMode(STREAM_FULL)
+        .setType(QueryType.PREPARED_STATEMENT)
+        .setPreparedStatementHandle(preparedStatementHandle)
+        .build();
+    client.submitQuery(resultsListener, runQuery);
+  }
+
+  /**
+   * Execute the given prepared statement and return the results.
+   *
+   * @param preparedStatementHandle Prepared statement handle returned in response to
+   *                                {@link #createPreparedStatement(String)}.
+   * @return List of {@link QueryDataBatch}s. It is responsibility of the caller to release query data batches.
+   * @throws RpcException
+   */
+  @VisibleForTesting
+  public List<QueryDataBatch> executePreparedStatement(final PreparedStatementHandle preparedStatementHandle)
+      throws RpcException {
+    final RunQuery runQuery = newBuilder()
+        .setResultsMode(STREAM_FULL)
+        .setType(QueryType.PREPARED_STATEMENT)
+        .setPreparedStatementHandle(preparedStatementHandle)
+        .build();
+
+    final ListHoldingResultsListener resultsListener = new ListHoldingResultsListener(runQuery);
+
+    client.submitQuery(resultsListener, runQuery);
+
+    return resultsListener.getResults();
+  }
+
+  /**
    * Submits a Logical plan for direct execution (bypasses parsing)
    *
    * @param  plan  the plan to execute

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 5106787..c89ed0c 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,6 +31,7 @@ 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.CreatePreparedStatementResp;
 import org.apache.drill.exec.proto.UserProtos.GetCatalogsResp;
 import org.apache.drill.exec.proto.UserProtos.GetColumnsResp;
 import org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments;
@@ -117,6 +118,8 @@ public class UserClient extends BasicClientWithConnection<RpcType, UserToBitHand
       return GetTablesResp.getDefaultInstance();
     case RpcType.COLUMNS_VALUE:
       return GetColumnsResp.getDefaultInstance();
+    case RpcType.PREPARED_STATEMENT_VALUE:
+      return CreatePreparedStatementResp.getDefaultInstance();
     }
     throw new RpcException(String.format("Unable to deal with RpcType of %d", rpcType));
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 809ac65..c520744 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.CreatePreparedStatementReq;
+import org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp;
 import org.apache.drill.exec.proto.UserProtos.GetCatalogsResp;
 import org.apache.drill.exec.proto.UserProtos.GetCatalogsReq;
 import org.apache.drill.exec.proto.UserProtos.GetColumnsReq;
@@ -61,6 +63,8 @@ public class UserRpcConfig {
         .add(RpcType.GET_SCHEMAS, GetSchemasReq.class, RpcType.SCHEMAS, GetSchemasResp.class) // user to bit
         .add(RpcType.GET_TABLES, GetTablesReq.class, RpcType.TABLES, GetTablesResp.class) // user to bit
         .add(RpcType.GET_COLUMNS, GetColumnsReq.class, RpcType.COLUMNS, GetColumnsResp.class) // user to bit
+        .add(RpcType.CREATE_PREPARED_STATEMENT, CreatePreparedStatementReq.class,
+            RpcType.PREPARED_STATEMENT, CreatePreparedStatementResp.class) // user to bit
         .build();
   }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 adf7ec4..9a15d96 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
@@ -19,11 +19,14 @@ package org.apache.drill.exec.rpc.user;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufInputStream;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 
 import java.io.IOException;
+import java.net.SocketAddress;
 import java.util.UUID;
 import java.util.concurrent.Executor;
 
@@ -38,6 +41,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.CreatePreparedStatementReq;
 import org.apache.drill.exec.proto.UserProtos.GetCatalogsReq;
 import org.apache.drill.exec.proto.UserProtos.GetColumnsReq;
 import org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments;
@@ -58,6 +62,7 @@ import org.apache.drill.exec.rpc.Response;
 import org.apache.drill.exec.rpc.ResponseSender;
 import org.apache.drill.exec.rpc.RpcException;
 import org.apache.drill.exec.rpc.RpcOutcomeListener;
+import org.apache.drill.exec.rpc.user.UserServer.UserClientConnectionImpl;
 import org.apache.drill.exec.rpc.user.security.UserAuthenticationException;
 import org.apache.drill.exec.rpc.user.security.UserAuthenticator;
 import org.apache.drill.exec.rpc.user.security.UserAuthenticatorFactory;
@@ -66,7 +71,7 @@ import org.apache.drill.exec.work.user.UserWorker;
 import com.google.protobuf.InvalidProtocolBufferException;
 import com.google.protobuf.MessageLite;
 
-public class UserServer extends BasicServer<RpcType, UserServer.UserClientConnection> {
+public class UserServer extends BasicServer<RpcType, UserClientConnectionImpl> {
   private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(UserServer.class);
 
   final UserWorker worker;
@@ -106,7 +111,7 @@ public class UserServer extends BasicServer<RpcType, UserServer.UserClientConnec
   }
 
   @Override
-  protected void handle(UserClientConnection connection, int rpcType, ByteBuf pBody, ByteBuf dBody,
+  protected void handle(UserClientConnectionImpl connection, int rpcType, ByteBuf pBody, ByteBuf dBody,
       ResponseSender responseSender) throws RpcException {
     switch (rpcType) {
 
@@ -180,16 +185,69 @@ public class UserServer extends BasicServer<RpcType, UserServer.UserClientConnec
       } catch (final InvalidProtocolBufferException e) {
         throw new RpcException("Failure while decoding GetColumnsReq body.", e);
       }
+    case RpcType.CREATE_PREPARED_STATEMENT_VALUE:
+      try {
+        final CreatePreparedStatementReq req =
+            CreatePreparedStatementReq.PARSER.parseFrom(new ByteBufInputStream(pBody));
+        worker.submitPreparedStatementWork(connection, req, responseSender);
+        break;
+      } catch (final InvalidProtocolBufferException e) {
+        throw new RpcException("Failure while decoding CreatePreparedStatementReq body.", e);
+      }
     default:
       throw new UnsupportedOperationException(String.format("UserServer received rpc of unknown type.  Type was %d.", rpcType));
     }
   }
 
-  public class UserClientConnection extends RemoteConnection {
+  /**
+   * Interface for getting user session properties and interacting with user connection. Separating this interface from
+   * {@link RemoteConnection} implementation for user connection:
+   * <p><ul>
+   *   <li> Connection is passed to Foreman and Screen operators. Instead passing this interface exposes few details.
+   *   <li> Makes it easy to have wrappers around user connection which can be helpful to tap the messages and data
+   *        going to the actual client.
+   * </ul>
+   */
+  public interface UserClientConnection {
+    /**
+     * @return User session object.
+     */
+    UserSession getSession();
+
+    /**
+     * Send query result outcome to client. Outcome is returned through <code>listener</code>
+     * @param listener
+     * @param result
+     */
+    void sendResult(RpcOutcomeListener<Ack> listener, QueryResult result);
+
+    /**
+     * Send query data to client. Outcome is returned through <code>listener</code>
+     * @param listener
+     * @param result
+     */
+    void sendData(RpcOutcomeListener<Ack> listener, QueryWritableBatch result);
+
+    /**
+     * Returns the {@link ChannelFuture} which will be notified when this
+     * channel is closed.  This method always returns the same future instance.
+     */
+    ChannelFuture getChannelClosureFuture();
+
+    /**
+     * @return Return the client node address.
+     */
+    SocketAddress getRemoteAddress();
+  }
+
+  /**
+   * {@link RemoteConnection} implementation for user connection. Also implements {@link UserClientConnection}.
+   */
+  public class UserClientConnectionImpl extends RemoteConnection implements UserClientConnection {
 
     private UserSession session;
 
-    public UserClientConnection(SocketChannel channel) {
+    public UserClientConnectionImpl(SocketChannel channel) {
       super(channel, "user client");
     }
 
@@ -197,7 +255,7 @@ public class UserServer extends BasicServer<RpcType, UserServer.UserClientConnec
       getChannel().pipeline().remove(BasicServer.TIMEOUT_HANDLER);
     }
 
-    void setUser(UserToBitHandshake inbound) throws IOException {
+    void setUser(final UserToBitHandshake inbound) throws IOException {
       session = UserSession.Builder.newBuilder()
           .withCredentials(inbound.getCredentials())
           .withOptionManager(worker.getSystemOptions())
@@ -210,38 +268,47 @@ public class UserServer extends BasicServer<RpcType, UserServer.UserClientConnec
       }
     }
 
+    @Override
     public UserSession getSession(){
       return session;
     }
 
-    public void sendResult(RpcOutcomeListener<Ack> listener, QueryResult result, boolean allowInEventThread){
+    @Override
+    public void sendResult(final RpcOutcomeListener<Ack> listener, final QueryResult result) {
       logger.trace("Sending result to client with {}", result);
-      send(listener, this, RpcType.QUERY_RESULT, result, Ack.class, allowInEventThread);
-    }
-
-    public void sendData(RpcOutcomeListener<Ack> listener, QueryWritableBatch result){
-      sendData(listener, result, false);
+      send(listener, this, RpcType.QUERY_RESULT, result, Ack.class, true);
     }
 
-    public void sendData(RpcOutcomeListener<Ack> listener, QueryWritableBatch result, boolean allowInEventThread){
+    @Override
+    public void sendData(final RpcOutcomeListener<Ack> listener, final QueryWritableBatch result) {
       logger.trace("Sending data to client with {}", result);
-      send(listener, this, RpcType.QUERY_DATA, result.getHeader(), Ack.class, allowInEventThread, result.getBuffers());
+      send(listener, this, RpcType.QUERY_DATA, result.getHeader(), Ack.class, false, result.getBuffers());
     }
+
     @Override
     public BufferAllocator getAllocator() {
       return alloc;
     }
 
+    @Override
+    public ChannelFuture getChannelClosureFuture() {
+      return getChannel().closeFuture();
+    }
+
+    @Override
+    public SocketAddress getRemoteAddress() {
+      return getChannel().remoteAddress();
+    }
   }
 
   @Override
-  public UserClientConnection initRemoteConnection(SocketChannel channel) {
+  public UserClientConnectionImpl initRemoteConnection(SocketChannel channel) {
     super.initRemoteConnection(channel);
-    return new UserClientConnection(channel);
+    return new UserClientConnectionImpl(channel);
   }
 
   @Override
-  protected ServerHandshakeHandler<UserToBitHandshake> getHandshakeHandler(final UserClientConnection connection) {
+  protected ServerHandshakeHandler<UserToBitHandshake> getHandshakeHandler(final UserClientConnectionImpl connection) {
 
     return new ServerHandshakeHandler<UserToBitHandshake>(RpcType.HANDSHAKE, UserToBitHandshake.PARSER){
 

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SystemOptionManager.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SystemOptionManager.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SystemOptionManager.java
index 3053c85..71d9f0a 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SystemOptionManager.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/options/SystemOptionManager.java
@@ -145,7 +145,8 @@ public class SystemOptionManager extends BaseOptionManager implements AutoClosea
       ExecConstants.IMPLICIT_SUFFIX_COLUMN_LABEL_VALIDATOR,
       ExecConstants.IMPLICIT_FQN_COLUMN_LABEL_VALIDATOR,
       ExecConstants.IMPLICIT_FILEPATH_COLUMN_LABEL_VALIDATOR,
-      ExecConstants.CODE_GEN_EXP_IN_METHOD_SIZE_VALIDATOR
+      ExecConstants.CODE_GEN_EXP_IN_METHOD_SIZE_VALIDATOR,
+      ExecConstants.CREATE_PREPARE_STATEMENT_TIMEOUT_MILLIS_VALIDATOR
     };
     final Map<String, OptionValidator> tmp = new HashMap<>();
     for (final OptionValidator validator : validators) {

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 2829ac1..808ba07 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
@@ -61,10 +61,12 @@ import org.apache.drill.exec.proto.BitControl.InitializeFragments;
 import org.apache.drill.exec.proto.BitControl.PlanFragment;
 import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint;
 import org.apache.drill.exec.proto.ExecProtos.FragmentHandle;
+import org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState;
 import org.apache.drill.exec.proto.GeneralRPCProtos.Ack;
 import org.apache.drill.exec.proto.UserBitShared.QueryId;
 import org.apache.drill.exec.proto.UserBitShared.QueryResult;
 import org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState;
+import org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle;
 import org.apache.drill.exec.proto.UserProtos.RunQuery;
 import org.apache.drill.exec.proto.helper.QueryIdHelper;
 import org.apache.drill.exec.rpc.BaseRpcOutcomeListener;
@@ -92,6 +94,7 @@ import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Sets;
+import com.google.protobuf.InvalidProtocolBufferException;
 
 /**
  * Foreman manages all the fragments (local and remote) for a single query where this
@@ -162,7 +165,7 @@ public class Foreman implements Runnable {
     this.drillbitContext = drillbitContext;
 
     initiatingClient = connection;
-    this.closeFuture = initiatingClient.getChannel().closeFuture();
+    closeFuture = initiatingClient.getChannelClosureFuture();
     closeFuture.addListener(closeListener);
 
     queryContext = new QueryContext(connection.getSession(), drillbitContext, queryId);
@@ -254,11 +257,18 @@ public class Foreman implements Runnable {
         parseAndRunPhysicalPlan(queryRequest.getPlan());
         break;
       case SQL:
-        runSQL(queryRequest.getPlan());
+        final String sql = queryRequest.getPlan();
+        // log query id and query text before starting any real work. Also, put
+        // them together such that it is easy to search based on query id
+        logger.info("Query text for query id {}: {}", this.queryIdString, sql);
+        runSQL(sql);
         break;
       case EXECUTION:
         runFragment(queryRequest.getFragmentsList());
         break;
+      case PREPARED_STATEMENT:
+        runPreparedStatement(queryRequest.getPreparedStatementHandle());
+        break;
       default:
         throw new IllegalStateException();
       }
@@ -484,7 +494,31 @@ public class Foreman implements Runnable {
     logger.debug("Fragments running.");
   }
 
+  /**
+   * Helper method to execute the query in prepared statement. Current implementation takes the query from opaque
+   * object of the <code>preparedStatement</code> and submits as a new query.
+   *
+   * @param preparedStatementHandle
+   * @throws ExecutionSetupException
+   */
+  private void runPreparedStatement(final PreparedStatementHandle preparedStatementHandle)
+      throws ExecutionSetupException {
+    final ServerPreparedStatementState serverState;
+
+    try {
+      serverState =
+          ServerPreparedStatementState.PARSER.parseFrom(preparedStatementHandle.getServerInfo());
+    } catch (final InvalidProtocolBufferException ex) {
+      throw UserException.parseError(ex)
+          .message("Failed to parse the prepared statement handle. " +
+              "Make sure the handle is same as one returned from create prepared statement call.")
+          .build(logger);
+    }
 
+    final String sql = serverState.getSqlQuery();
+    logger.info("Prepared statement query for QueryId {} : {}", queryId, sql);
+    runSQL(sql);
+  }
 
   private static void validatePlan(final PhysicalPlan plan) throws ForemanSetupException {
     if (plan.getProperties().resultMode != ResultMode.EXEC) {
@@ -734,7 +768,7 @@ public class Foreman implements Runnable {
             new Date(System.currentTimeMillis()),
             state,
             queryContext.getSession().getCredentials().getUserName(),
-            initiatingClient.getChannel().remoteAddress());
+            initiatingClient.getRemoteAddress());
         queryLogger.info(MAPPER.writeValueAsString(q));
       } catch (Exception e) {
         logger.error("Failure while recording query information to query log.", e);
@@ -805,7 +839,7 @@ public class Foreman implements Runnable {
        */
       try {
         // send whatever result we ended up with
-        initiatingClient.sendResult(responseListener, resultBuilder.build(), true);
+        initiatingClient.sendResult(responseListener, resultBuilder.build());
       } catch(final Exception e) {
         addException(e);
         logger.warn("Exception sending result to client", resultException);
@@ -970,10 +1004,6 @@ public class Foreman implements Runnable {
   }
 
   private void runSQL(final String sql) throws ExecutionSetupException {
-    // log query id and query text before starting any real work. Also, put
-    // them together such that it is easy to search based on query id
-    logger.info("Query text for query id {}: {}", this.queryIdString, sql);
-
     final Pointer<String> textPlan = new Pointer<>();
     final PhysicalPlan plan = DrillSqlWorker.getPlan(queryContext, sql, textPlan);
     queryManager.setPlanText(textPlan.value);

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/exec/java-exec/src/main/java/org/apache/drill/exec/work/prepare/PreparedStatementProvider.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/work/prepare/PreparedStatementProvider.java b/exec/java-exec/src/main/java/org/apache/drill/exec/work/prepare/PreparedStatementProvider.java
new file mode 100644
index 0000000..982d8a3
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/work/prepare/PreparedStatementProvider.java
@@ -0,0 +1,400 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.prepare;
+
+import static org.apache.drill.exec.ExecConstants.CREATE_PREPARE_STATEMENT_TIMEOUT_MILLIS;
+import static org.apache.drill.exec.proto.UserProtos.RequestStatus.FAILED;
+import static org.apache.drill.exec.proto.UserProtos.RequestStatus.OK;
+import static org.apache.drill.exec.proto.UserProtos.RequestStatus.TIMEOUT;
+
+import org.apache.drill.common.exceptions.ErrorHelper;
+import org.apache.drill.common.types.TypeProtos.DataMode;
+import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.types.TypeProtos.MinorType;
+import org.apache.drill.common.types.Types;
+import org.apache.drill.exec.physical.impl.materialize.QueryWritableBatch;
+import org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState;
+import org.apache.drill.exec.proto.GeneralRPCProtos.Ack;
+import org.apache.drill.exec.proto.UserBitShared.DrillPBError;
+import org.apache.drill.exec.proto.UserBitShared.DrillPBError.ErrorType;
+import org.apache.drill.exec.proto.UserBitShared.QueryId;
+import org.apache.drill.exec.proto.UserBitShared.QueryResult;
+import org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.proto.UserBitShared.SerializedField;
+import org.apache.drill.exec.proto.UserProtos.ColumnSearchability;
+import org.apache.drill.exec.proto.UserProtos.ColumnUpdatability;
+import org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq;
+import org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp;
+import org.apache.drill.exec.proto.UserProtos.PreparedStatement;
+import org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle;
+import org.apache.drill.exec.proto.UserProtos.RequestStatus;
+import org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata;
+import org.apache.drill.exec.proto.UserProtos.RpcType;
+import org.apache.drill.exec.proto.UserProtos.RunQuery;
+import org.apache.drill.exec.rpc.Acks;
+import org.apache.drill.exec.rpc.Response;
+import org.apache.drill.exec.rpc.ResponseSender;
+import org.apache.drill.exec.rpc.RpcOutcomeListener;
+import org.apache.drill.exec.rpc.user.UserServer.UserClientConnection;
+import org.apache.drill.exec.rpc.user.UserSession;
+import org.apache.drill.exec.store.ischema.InfoSchemaConstants;
+import org.apache.drill.exec.work.user.UserWorker;
+import org.joda.time.Period;
+
+import com.google.common.collect.ImmutableMap;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelFuture;
+import java.math.BigDecimal;
+import java.net.SocketAddress;
+import java.sql.Date;
+import java.sql.ResultSetMetaData;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Contains worker {@link Runnable} for creating a prepared statement and helper methods.
+ */
+public class PreparedStatementProvider {
+  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PreparedStatementProvider.class);
+
+  /**
+   * Static list of mappings from {@link MinorType} to JDBC ResultSet class name (to be returned through
+   * {@link ResultSetMetaData#getColumnClassName(int)}.
+   */
+  private static final Map<MinorType, String> DRILL_TYPE_TO_JDBC_CLASSNAME = ImmutableMap.<MinorType, String>builder()
+      .put(MinorType.INT, Integer.class.getName())
+      .put(MinorType.BIGINT, Long.class.getName())
+      .put(MinorType.FLOAT4, Float.class.getName())
+      .put(MinorType.FLOAT8, Double.class.getName())
+      .put(MinorType.VARCHAR, String.class.getName())
+      .put(MinorType.BIT, Boolean.class.getName())
+      .put(MinorType.DATE, Date.class.getName())
+      .put(MinorType.DECIMAL9, BigDecimal.class.getName())
+      .put(MinorType.DECIMAL18, BigDecimal.class.getName())
+      .put(MinorType.DECIMAL28SPARSE, BigDecimal.class.getName())
+      .put(MinorType.DECIMAL38SPARSE, BigDecimal.class.getName())
+      .put(MinorType.TIME, Time.class.getName())
+      .put(MinorType.TIMESTAMP, Timestamp.class.getName())
+      .put(MinorType.VARBINARY, byte[].class.getName())
+      .put(MinorType.INTERVALYEAR, Period.class.getName())
+      .put(MinorType.INTERVALDAY, Period.class.getName())
+      .put(MinorType.MAP, Object.class.getName())
+      .put(MinorType.LIST, Object.class.getName())
+      .put(MinorType.UNION, Object.class.getName())
+      .build();
+
+  /**
+   * Runnable that creates a prepared statement for given {@link CreatePreparedStatementReq} and
+   * sends the response at the end.
+   */
+  public static class PreparedStatementWorker implements Runnable {
+    private final UserClientConnection connection;
+    private final UserWorker userWorker;
+    private final ResponseSender responseSender;
+    private final CreatePreparedStatementReq req;
+
+    public PreparedStatementWorker(final UserClientConnection connection, final UserWorker userWorker,
+        final ResponseSender responseSender, final CreatePreparedStatementReq req) {
+      this.connection = connection;
+      this.userWorker = userWorker;
+      this.responseSender = responseSender;
+      this.req = req;
+    }
+
+    @Override
+    public void run() {
+      final CreatePreparedStatementResp.Builder respBuilder = CreatePreparedStatementResp.newBuilder();
+      try {
+        UserClientConnectionWrapper wrapper = new UserClientConnectionWrapper(connection);
+
+        final RunQuery limit0Query =
+            RunQuery.newBuilder()
+                .setType(QueryType.SQL)
+                .setPlan(String.format("SELECT * FROM (%s) LIMIT 0", req.getSqlQuery()))
+                .build();
+
+        final QueryId limit0QueryId = userWorker.submitWork(wrapper, limit0Query);
+
+        final long timeoutMillis =
+            userWorker.getSystemOptions().getOption(CREATE_PREPARE_STATEMENT_TIMEOUT_MILLIS).num_val;
+
+        try {
+          if (!wrapper.await(timeoutMillis)) {
+            logger.error("LIMIT 0 query (QueryId: {}) for prepared statement took longer than {} ms. Cancelling.",
+                limit0QueryId, timeoutMillis);
+            userWorker.cancelQuery(limit0QueryId);
+            final String errorMsg = String.format(
+                "LIMIT 0 query (QueryId: %s) for prepared statement took longer than %d ms. " +
+                    "Query cancellation requested.\n" +
+                    "Retry after changing the option '%s' to a higher value.",
+                limit0QueryId, timeoutMillis, CREATE_PREPARE_STATEMENT_TIMEOUT_MILLIS);
+            setErrorHelper(respBuilder, TIMEOUT, null, errorMsg, ErrorType.SYSTEM);
+            return;
+          }
+        } catch (InterruptedException ex) {
+          setErrorHelper(respBuilder, FAILED, ex, "Prepared statement creation interrupted.", ErrorType.SYSTEM);
+          return;
+        }
+
+        if (wrapper.getError() != null) {
+          setErrorHelper(respBuilder, wrapper.getError(), "Failed to get result set schema for prepare statement.");
+          return;
+        }
+
+        final PreparedStatement.Builder prepStmtBuilder = PreparedStatement.newBuilder();
+
+        for (SerializedField field : wrapper.getFields()) {
+          prepStmtBuilder.addColumns(serializeColumn(field));
+        }
+
+        prepStmtBuilder.setServerHandle(
+            PreparedStatementHandle.newBuilder()
+                .setServerInfo(
+                    ServerPreparedStatementState.newBuilder()
+                        .setSqlQuery(req.getSqlQuery())
+                        .build().toByteString()
+                )
+        );
+
+        respBuilder.setStatus(OK);
+        respBuilder.setPreparedStatement(prepStmtBuilder.build());
+      } catch (Throwable e) {
+        setErrorHelper(respBuilder, FAILED, e, "Failed to create prepared statement.", ErrorType.SYSTEM);
+      } finally {
+        responseSender.send(new Response(RpcType.PREPARED_STATEMENT, respBuilder.build()));
+      }
+    }
+  }
+
+  /**
+   * Helper method to create {@link DrillPBError} and set it in <code>respBuilder</code>
+   */
+  private static void setErrorHelper(final CreatePreparedStatementResp.Builder respBuilder, final RequestStatus status,
+      final Throwable ex, final String message, final ErrorType errorType) {
+    respBuilder.setStatus(status);
+    final String errorId = UUID.randomUUID().toString();
+    if (ex != null) {
+      logger.error("{} ErrorId: {}", message, errorId, ex);
+    } else {
+      logger.error("{} ErrorId: {}", message, errorId);
+    }
+
+    final DrillPBError.Builder builder = DrillPBError.newBuilder();
+    builder.setErrorType(errorType);
+    builder.setErrorId(errorId);
+    builder.setMessage(message);
+
+    if (ex != null) {
+      builder.setException(ErrorHelper.getWrapper(ex));
+    }
+
+    respBuilder.setError(builder.build());
+  }
+
+  /**
+   * Helper method to log error and set given {@link DrillPBError} in <code>respBuilder</code>
+   */
+  private static void setErrorHelper(final CreatePreparedStatementResp.Builder respBuilder, final DrillPBError error,
+      final String message) {
+    respBuilder.setStatus(FAILED);
+    final String errorId = UUID.randomUUID().toString();
+    logger.error("{} ErrorId: {}", message, errorId);
+
+    respBuilder.setError(error);
+  }
+
+  /**
+   * Decorator around {@link UserClientConnection} to tap the query results for LIMIT 0 query.
+   */
+  private static class UserClientConnectionWrapper implements UserClientConnection {
+    private final UserClientConnection inner;
+    private final CountDownLatch latch = new CountDownLatch(1);
+
+    private volatile DrillPBError error;
+    private volatile List<SerializedField> fields;
+
+    UserClientConnectionWrapper(UserClientConnection inner) {
+      this.inner = inner;
+    }
+
+    @Override
+    public UserSession getSession() {
+      return inner.getSession();
+    }
+
+    @Override
+    public ChannelFuture getChannelClosureFuture() {
+      return inner.getChannelClosureFuture();
+    }
+
+    @Override
+    public SocketAddress getRemoteAddress() {
+      return inner.getRemoteAddress();
+    }
+
+    @Override
+    public void sendResult(RpcOutcomeListener<Ack> listener, QueryResult result) {
+      // Release the wait latch if the query is terminated.
+      final QueryState state = result.getQueryState();
+      if (state == QueryState.FAILED || state  == QueryState.CANCELED || state == QueryState.COMPLETED) {
+        if (state == QueryState.FAILED) {
+          error = result.getError(0);
+        }
+        latch.countDown();
+      }
+
+      listener.success(Acks.OK, null);
+    }
+
+    @Override
+    public void sendData(RpcOutcomeListener<Ack> listener, QueryWritableBatch result) {
+      // Save the query results schema and release the buffers.
+      if (fields == null) {
+        fields = result.getHeader().getDef().getFieldList();
+      }
+
+      for(ByteBuf buf : result.getBuffers()) {
+        buf.release();
+      }
+
+      listener.success(Acks.OK, null);
+    }
+
+    /**
+     * Wait until the query has completed.
+     * @throws InterruptedException
+     */
+    boolean await(final long timeoutMillis) throws InterruptedException {
+      return latch.await(timeoutMillis, TimeUnit.MILLISECONDS);
+    }
+
+    /**
+     * @return Any error returned in query execution.
+     */
+    DrillPBError getError() {
+      return error;
+    }
+
+    /**
+     * @return Schema returned in query result batch.
+     */
+    List<SerializedField> getFields() {
+      return fields;
+    }
+  }
+
+  /**
+   * Serialize the given {@link SerializedField} into a {@link ResultColumnMetadata}.
+   * @param field
+   * @return
+   */
+  private static ResultColumnMetadata serializeColumn(SerializedField field) {
+    final ResultColumnMetadata.Builder builder = ResultColumnMetadata.newBuilder();
+    final MajorType majorType = field.getMajorType();
+    final MinorType minorType = majorType.getMinorType();
+
+    /**
+     * Defaults to "DRILL" as drill has as only one catalog.
+     */
+    builder.setCatalogName(InfoSchemaConstants.IS_CATALOG_NAME);
+
+    /**
+     * Designated column's schema name. Empty string if not applicable. Initial implementation defaults to empty string
+     * as we use LIMIT 0 queries to get the schema and schema info is lost. If we derive the schema from plan, we may
+     * get the right value.
+     */
+    builder.setSchemaName("");
+
+    /**
+     * Designated column's table name. Not set if not applicable. Initial implementation defaults to empty string as
+     * we use LIMIT 0 queries to get the schema and table info is lost. If we derive the table from plan, we may get
+     * the right value.
+     */
+    builder.setTableName("");
+
+    builder.setColumnName(field.getNamePart().getName());
+
+    /**
+     * Column label name for display or print purposes.
+     * Ex. a column named "empName" might be labeled as "Employee Name".
+     * Initial implementation defaults to same value as column name.
+     */
+    builder.setLabel(field.getNamePart().getName());
+
+    /**
+     * Data type in string format. Value is SQL standard type.
+     */
+    builder.setDataType(Types.getSqlTypeName(majorType));
+
+    builder.setIsNullable(majorType.getMode() == DataMode.OPTIONAL);
+
+    /**
+     * For numeric data, this is the maximum precision.
+     * For character data, this is the length in characters.
+     * For datetime datatypes, this is the length in characters of the String representation
+     *    (assuming the maximum allowed precision of the fractional seconds component).
+     * For binary data, this is the length in bytes.
+     * For all other types 0 is returned where the column size is not applicable.
+     */
+    builder.setPrecision(Types.getPrecision(field.getMajorType()));
+
+    /**
+     * Column's number of digits to right of the decimal point. 0 is returned for types where the scale is not applicable
+     */
+    builder.setScale(Types.getScale(majorType));
+
+    /**
+     * Indicates whether values in the designated column are signed numbers.
+     */
+    builder.setSigned(Types.isNumericType(majorType));
+
+    /**
+     * Maximum number of characters required to display data from the column. Initial implementation hard coded to 10.
+     */
+    builder.setDisplaySize(10);
+
+    /**
+     * Is the column an aliased column. Initial implementation defaults to true as we derive schema from LIMIT 0 query and
+     * not plan
+     */
+    builder.setIsAliased(true);
+
+    builder.setSearchability(ColumnSearchability.ALL);
+    builder.setUpdatability(ColumnUpdatability.READ_ONLY);
+    builder.setAutoIncrement(false);
+    builder.setCaseSensitivity(false);
+    builder.setSortable(Types.isSortable(minorType));
+
+    /**
+     * Returns the fully-qualified name of the Java class whose instances are manufactured if the method
+     * ResultSet.getObject is called to retrieve a value from the column. Applicable only to JDBC clients.
+     */
+    builder.setClassName(DRILL_TYPE_TO_JDBC_CLASSNAME.get(minorType));
+
+    builder.setIsCurrency(false);
+
+    return builder.build();
+  }
+}

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 cc614d2..c1fa7a0 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,7 @@ 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.CreatePreparedStatementReq;
 import org.apache.drill.exec.proto.UserProtos.GetCatalogsReq;
 import org.apache.drill.exec.proto.UserProtos.GetColumnsReq;
 import org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments;
@@ -37,6 +38,7 @@ import org.apache.drill.exec.server.options.OptionManager;
 import org.apache.drill.exec.work.WorkManager.WorkerBee;
 import org.apache.drill.exec.work.foreman.Foreman;
 import org.apache.drill.exec.work.metadata.MetadataProvider;
+import org.apache.drill.exec.work.prepare.PreparedStatementProvider.PreparedStatementWorker;
 
 public class UserWorker{
   static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(UserWorker.class);
@@ -118,4 +120,9 @@ public class UserWorker{
   public void submitColumnsMetadataWork(UserSession session, GetColumnsReq req, ResponseSender sender) {
     bee.addNewWork(MetadataProvider.columns(session, bee.getContext(), req, sender));
   }
+
+  public void submitPreparedStatementWork(final UserClientConnection connection, final CreatePreparedStatementReq req,
+      final ResponseSender sender) {
+    bee.addNewWork(new PreparedStatementWorker(connection, this, sender, req));
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
index 7ab73dc..3eded52 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/BaseTestQuery.java
@@ -43,6 +43,7 @@ import org.apache.drill.exec.proto.UserBitShared;
 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.PreparedStatementHandle;
 import org.apache.drill.exec.record.RecordBatchLoader;
 import org.apache.drill.exec.rpc.ConnectionThrottle;
 import org.apache.drill.exec.rpc.user.AwaitableUserResultsListener;
@@ -293,9 +294,20 @@ public class BaseTestQuery extends ExecTest {
     return testRunAndReturn(QueryType.PHYSICAL, physical);
   }
 
-  public static List<QueryDataBatch>  testRunAndReturn(QueryType type, String query) throws Exception{
-    query = QueryTestUtil.normalizeQuery(query);
-    return client.runQuery(type, query);
+  public static List<QueryDataBatch>  testRunAndReturn(QueryType type, Object query) throws Exception{
+    if (type == QueryType.PREPARED_STATEMENT) {
+      Preconditions.checkArgument(query instanceof PreparedStatementHandle,
+          "Expected an instance of PreparedStatement as input query");
+      return testPreparedStatement((PreparedStatementHandle)query);
+    } else {
+      Preconditions.checkArgument(query instanceof String, "Expected a string as input query");
+      query = QueryTestUtil.normalizeQuery((String)query);
+      return client.runQuery(type, (String)query);
+    }
+  }
+
+  public static List<QueryDataBatch> testPreparedStatement(PreparedStatementHandle handle) throws Exception {
+    return client.executePreparedStatement(handle);
   }
 
   public static int testRunAndPrint(final QueryType type, final String query) throws Exception {

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/exec/java-exec/src/test/java/org/apache/drill/DrillTestWrapper.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/DrillTestWrapper.java b/exec/java-exec/src/test/java/org/apache/drill/DrillTestWrapper.java
index 2a9c03d..9df9139 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/DrillTestWrapper.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/DrillTestWrapper.java
@@ -81,8 +81,10 @@ public class DrillTestWrapper {
   // for the baseline data. In this case there needs to be a call back into the TestBuilder once we know the type information
   // from the test query.
   private TestBuilder testBuilder;
-  // test query to run
-  private String query;
+  /**
+   * Test query to run. Type of object depends on the {@link #queryType}
+   */
+  private Object query;
   // The type of query provided
   private UserBitShared.QueryType queryType;
   // The type of query provided for the baseline
@@ -106,7 +108,7 @@ public class DrillTestWrapper {
 
   private int expectedNumBatches;
 
-  public DrillTestWrapper(TestBuilder testBuilder, BufferAllocator allocator, String query, QueryType queryType,
+  public DrillTestWrapper(TestBuilder testBuilder, BufferAllocator allocator, Object query, QueryType queryType,
                           String baselineOptionSettingQueries, String testOptionSettingQueries,
                           QueryType baselineQueryType, boolean ordered, boolean highPerformanceComparison,
                           List<Map<String, Object>> baselineRecords, int expectedNumBatches) {

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/exec/java-exec/src/test/java/org/apache/drill/TestBuilder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestBuilder.java b/exec/java-exec/src/test/java/org/apache/drill/TestBuilder.java
index b073371..8acf936 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestBuilder.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestBuilder.java
@@ -36,6 +36,8 @@ import org.apache.drill.common.types.TypeProtos;
 import org.apache.drill.common.types.Types;
 import org.apache.drill.exec.memory.BufferAllocator;
 import org.apache.drill.exec.proto.UserBitShared;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle;
 import org.apache.drill.exec.util.JsonStringArrayList;
 import org.apache.drill.exec.util.JsonStringHashMap;
 import org.apache.drill.exec.util.Text;
@@ -45,8 +47,10 @@ import com.google.common.base.Preconditions;
 
 public class TestBuilder {
 
-  // test query to run
-  private String query;
+  /**
+   * Test query to rung. Type of object depends on the {@link #queryType}
+   */
+  private Object query;
   // the type of query for the test
   private UserBitShared.QueryType queryType;
   // should the validation enforce ordering
@@ -85,7 +89,7 @@ public class TestBuilder {
     reset();
   }
 
-  public TestBuilder(BufferAllocator allocator, String query, UserBitShared.QueryType queryType, Boolean ordered,
+  public TestBuilder(BufferAllocator allocator, Object query, UserBitShared.QueryType queryType, Boolean ordered,
                      boolean approximateEquality, Map<SchemaPath, TypeProtos.MajorType> baselineTypeMap,
                      String baselineOptionSettingQueries, String testOptionSettingQueries, boolean highPerformanceComparison,
                      int expectedNumBatches) {
@@ -141,6 +145,12 @@ public class TestBuilder {
     return sqlQuery(String.format(query, replacements));
   }
 
+  public TestBuilder preparedStatement(PreparedStatementHandle preparedStatementHandle) {
+    queryType = QueryType.PREPARED_STATEMENT;
+    query = preparedStatementHandle;
+    return this;
+  }
+
   public TestBuilder sqlQueryFromFile(String queryFile) throws IOException {
     String query = BaseTestQuery.getFile(queryFile);
     this.query = query;
@@ -210,7 +220,7 @@ public class TestBuilder {
     }
   }
 
-  String getValidationQuery() throws Exception {
+  Object getValidationQuery() throws Exception {
     throw new RuntimeException("Must provide some kind of baseline, either a baseline file or another query");
   }
 
@@ -354,7 +364,7 @@ public class TestBuilder {
   }
 
   // provide a SQL query to validate against
-  public BaselineQueryTestBuilder sqlBaselineQuery(String baselineQuery) {
+  public BaselineQueryTestBuilder sqlBaselineQuery(Object baselineQuery) {
     return new BaselineQueryTestBuilder(baselineQuery, UserBitShared.QueryType.SQL, allocator, query, queryType, ordered, approximateEquality,
         baselineTypeMap, baselineOptionSettingQueries, testOptionSettingQueries, highPerformanceComparison, expectedNumBatches);
   }
@@ -403,7 +413,7 @@ public class TestBuilder {
     // that come out of the test query drive interpretation of baseline
     private TypeProtos.MajorType[] baselineTypes;
 
-    CSVTestBuilder(String baselineFile, BufferAllocator allocator, String query, UserBitShared.QueryType queryType, Boolean ordered,
+    CSVTestBuilder(String baselineFile, BufferAllocator allocator, Object query, UserBitShared.QueryType queryType, Boolean ordered,
                    boolean approximateEquality, Map<SchemaPath, TypeProtos.MajorType> baselineTypeMap,
                    String baselineOptionSettingQueries, String testOptionSettingQueries, boolean highPerformanceComparison,
                    int expectedNumBatches) {
@@ -494,7 +504,7 @@ public class TestBuilder {
 
   public class SchemaTestBuilder extends TestBuilder {
     private List<Pair<SchemaPath, TypeProtos.MajorType>> expectedSchema;
-    SchemaTestBuilder(BufferAllocator allocator, String query, UserBitShared.QueryType queryType,
+    SchemaTestBuilder(BufferAllocator allocator, Object query, UserBitShared.QueryType queryType,
         String baselineOptionSettingQueries, String testOptionSettingQueries, List<Pair<SchemaPath, TypeProtos.MajorType>> expectedSchema) {
       super(allocator, query, queryType, false, false, null, baselineOptionSettingQueries, testOptionSettingQueries, false, -1);
       expectsEmptyResultSet();
@@ -535,7 +545,7 @@ public class TestBuilder {
     // path to the baseline file that will be inserted into the validation query
     private String baselineFilePath;
 
-    JSONTestBuilder(String baselineFile, BufferAllocator allocator, String query, UserBitShared.QueryType queryType, Boolean ordered,
+    JSONTestBuilder(String baselineFile, BufferAllocator allocator, Object query, UserBitShared.QueryType queryType, Boolean ordered,
                     boolean approximateEquality, Map<SchemaPath, TypeProtos.MajorType> baselineTypeMap,
                     String baselineOptionSettingQueries, String testOptionSettingQueries, boolean highPerformanceComparison,
                     int expectedNumBatches) {
@@ -559,11 +569,14 @@ public class TestBuilder {
 
   public class BaselineQueryTestBuilder extends TestBuilder {
 
-    private String baselineQuery;
+    /**
+     * Baseline query. Type of object depends on {@link #baselineQueryType}
+     */
+    private Object baselineQuery;
     private UserBitShared.QueryType baselineQueryType;
 
-    BaselineQueryTestBuilder(String baselineQuery, UserBitShared.QueryType baselineQueryType, BufferAllocator allocator,
-                             String query, UserBitShared.QueryType queryType, Boolean ordered,
+    BaselineQueryTestBuilder(Object baselineQuery, UserBitShared.QueryType baselineQueryType, BufferAllocator allocator,
+                             Object query, UserBitShared.QueryType queryType, Boolean ordered,
                              boolean approximateEquality, Map<SchemaPath, TypeProtos.MajorType> baselineTypeMap,
                              String baselineOptionSettingQueries, String testOptionSettingQueries, boolean highPerformanceComparison,
                              int expectedNumBatches) {
@@ -574,7 +587,7 @@ public class TestBuilder {
     }
 
     @Override
-    String getValidationQuery() {
+    Object getValidationQuery() {
       return baselineQuery;
     }
 

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/exec/java-exec/src/test/java/org/apache/drill/exec/work/prepare/TestPreparedStatementProvider.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/work/prepare/TestPreparedStatementProvider.java b/exec/java-exec/src/test/java/org/apache/drill/exec/work/prepare/TestPreparedStatementProvider.java
new file mode 100644
index 0000000..5a78cc9
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/work/prepare/TestPreparedStatementProvider.java
@@ -0,0 +1,222 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.prepare;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.drill.BaseTestQuery;
+import org.apache.drill.exec.proto.UserBitShared.DrillPBError.ErrorType;
+import org.apache.drill.exec.proto.UserProtos.ColumnSearchability;
+import org.apache.drill.exec.proto.UserProtos.ColumnUpdatability;
+import org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp;
+import org.apache.drill.exec.proto.UserProtos.PreparedStatement;
+import org.apache.drill.exec.proto.UserProtos.RequestStatus;
+import org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata;
+import org.apache.drill.exec.store.ischema.InfoSchemaConstants;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+import java.sql.Date;
+import java.util.List;
+
+/**
+ * Tests for creating and executing prepared statements.
+ */
+public class TestPreparedStatementProvider extends BaseTestQuery {
+  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestPreparedStatementProvider.class);
+
+  /**
+   * Simple query.
+   * @throws Exception
+   */
+  @Test
+  public void simple() throws Exception {
+    String query = "SELECT * FROM cp.`region.json` ORDER BY region_id LIMIT 1";
+    PreparedStatement preparedStatement = createPrepareStmt(query, false, null);
+
+    List<ExpectedColumnResult> expMetadata = ImmutableList.of(
+        new ExpectedColumnResult("region_id", "BIGINT", true, 0, 0, true, Long.class.getName()),
+        new ExpectedColumnResult("sales_city", "CHARACTER VARYING", true, 65536, 0, false, String.class.getName()),
+        new ExpectedColumnResult("sales_state_province", "CHARACTER VARYING", true, 65536, 0, false, String.class.getName()),
+        new ExpectedColumnResult("sales_district", "CHARACTER VARYING", true, 65536, 0, false, String.class.getName()),
+        new ExpectedColumnResult("sales_region", "CHARACTER VARYING", true, 65536, 0, false, String.class.getName()),
+        new ExpectedColumnResult("sales_country", "CHARACTER VARYING", true, 65536, 0, false, String.class.getName()),
+        new ExpectedColumnResult("sales_district_id", "BIGINT", true, 0, 0, true, Long.class.getName())
+    );
+
+    verifyMetadata(expMetadata, preparedStatement.getColumnsList());
+
+    testBuilder()
+        .unOrdered()
+        .preparedStatement(preparedStatement.getServerHandle())
+        .baselineColumns("region_id", "sales_city", "sales_state_province", "sales_district",
+            "sales_region", "sales_country", "sales_district_id")
+        .baselineValues(0L, "None", "None", "No District", "No Region", "No Country", 0L)
+        .go();
+  }
+
+  /**
+   * Create a prepared statement for a query that has GROUP BY clause in it
+   */
+  @Test
+  public void groupByQuery() throws Exception {
+    String query = "SELECT sales_city, count(*) as cnt FROM cp.`region.json` " +
+        "GROUP BY sales_city ORDER BY sales_city DESC LIMIT 1";
+    PreparedStatement preparedStatement = createPrepareStmt(query, false, null);
+
+    List<ExpectedColumnResult> expMetadata = ImmutableList.of(
+        new ExpectedColumnResult("sales_city", "CHARACTER VARYING", true, 65536, 0, false, String.class.getName()),
+        new ExpectedColumnResult("cnt", "BIGINT", false, 0, 0, true, Long.class.getName())
+    );
+
+    verifyMetadata(expMetadata, preparedStatement.getColumnsList());
+
+    testBuilder()
+        .unOrdered()
+        .preparedStatement(preparedStatement.getServerHandle())
+        .baselineColumns("sales_city", "cnt")
+        .baselineValues("Yakima", 1L)
+        .go();
+  }
+
+  /**
+   * Create a prepared statement for a query that joins two tables and has ORDER BY clause.
+   */
+  @Test
+  public void joinOrderByQuery() throws Exception {
+    String query = "SELECT l.l_quantity, l.l_shipdate, o.o_custkey FROM cp.`tpch/lineitem.parquet` l JOIN cp.`tpch/orders.parquet` o " +
+        "ON l.l_orderkey = o.o_orderkey LIMIT 2";
+
+    PreparedStatement preparedStatement = createPrepareStmt(query, false, null);
+
+    List<ExpectedColumnResult> expMetadata = ImmutableList.of(
+        new ExpectedColumnResult("l_quantity", "DOUBLE", false, 0, 0, true, Double.class.getName()),
+        new ExpectedColumnResult("l_shipdate", "DATE", false, 0, 0, false, Date.class.getName()),
+        new ExpectedColumnResult("o_custkey", "INTEGER", false, 0, 0, true, Integer.class.getName())
+    );
+
+    verifyMetadata(expMetadata, preparedStatement.getColumnsList());
+  }
+
+  /**
+   * Pass an invalid query to the create prepare statement request and expect a parser failure.
+   * @throws Exception
+   */
+  @Test
+  public void invalidQueryParserError() throws Exception {
+    createPrepareStmt("BLAH BLAH", true, ErrorType.PARSE);
+  }
+
+  /**
+   * Pass an invalid query to the create prepare statement request and expect a validation failure.
+   * @throws Exception
+   */
+  @Test
+  public void invalidQueryValidationError() throws Exception {
+    createPrepareStmt("SELECT * sdflkgdh", true, ErrorType.PARSE /** Drill returns incorrect error for parse error*/);
+  }
+
+  /* Helper method which creates a prepared statement for given query. */
+  private static PreparedStatement createPrepareStmt(String query, boolean expectFailure, ErrorType errorType) throws Exception {
+    CreatePreparedStatementResp resp = client.createPreparedStatement(query).get();
+
+    assertEquals(expectFailure ? RequestStatus.FAILED : RequestStatus.OK, resp.getStatus());
+
+    if (expectFailure) {
+      assertEquals(errorType, resp.getError().getErrorType());
+    } else {
+      logger.error("Prepared statement creation failed: {}", resp.getError().getMessage());
+    }
+
+    return resp.getPreparedStatement();
+  }
+
+  private static class ExpectedColumnResult {
+    final String columnName;
+    final String type;
+    final boolean nullable;
+    final int precision;
+    final int scale;
+    final boolean signed;
+    final String className;
+
+    ExpectedColumnResult(String columnName, String type, boolean nullable, int precision, int scale, boolean signed,
+        String className) {
+      this.columnName = columnName;
+      this.type = type;
+      this.nullable = nullable;
+      this.precision = precision;
+      this.scale = scale;
+      this.signed = signed;
+      this.className = className;
+    }
+
+    boolean isEqualsTo(ResultColumnMetadata result) {
+      return
+          result.getCatalogName().equals(InfoSchemaConstants.IS_CATALOG_NAME) &&
+          result.getSchemaName().isEmpty() &&
+          result.getTableName().isEmpty() &&
+          result.getColumnName().equals(columnName) &&
+          result.getLabel().equals(columnName) &&
+          result.getDataType().equals(type) &&
+          result.getIsNullable() == nullable &&
+          result.getPrecision() == precision &&
+          result.getScale() == scale &&
+          result.getSigned() == signed &&
+          result.getDisplaySize() == 10 &&
+          result.getClassName().equals(className) &&
+          result.getSearchability() == ColumnSearchability.ALL &&
+          result.getAutoIncrement() == false &&
+          result.getCaseSensitivity() == false &&
+          result.getUpdatability() == ColumnUpdatability.READ_ONLY &&
+          result.getIsAliased() == true &&
+          result.getIsCurrency() == false;
+    }
+
+    @Override
+    public String toString() {
+      return "ExpectedColumnResult[" +
+          "columnName='" + columnName + '\'' +
+          ", type='" + type + '\'' +
+          ", nullable=" + nullable +
+          ", precision=" + precision +
+          ", scale=" + scale +
+          ", signed=" + signed +
+          ", className='" + className + '\'' +
+          ']';
+    }
+  }
+
+  private static void verifyMetadata(List<ExpectedColumnResult> expMetadata,
+      List<ResultColumnMetadata> actMetadata) {
+    assertEquals(expMetadata.size(), actMetadata.size());
+
+    for(ExpectedColumnResult exp : expMetadata) {
+      boolean found = false;
+      for(ResultColumnMetadata act : actMetadata) {
+        found = exp.isEqualsTo(act);
+        if (found) {
+          break;
+        }
+      }
+      assertTrue("Failed to find the expected column metadata: " + exp, found);
+    }
+  }
+}


[3/4] drill git commit: DRILL-4729: Add support for prepared statement implementation on server side

Posted by ve...@apache.org.
http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 5b986cf..acfdcb7 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
@@ -886,11 +886,501 @@ public final class ExecProtos {
     // @@protoc_insertion_point(class_scope:exec.bit.FragmentHandle)
   }
 
+  public interface ServerPreparedStatementStateOrBuilder
+      extends com.google.protobuf.MessageOrBuilder {
+
+    // optional string sql_query = 1;
+    /**
+     * <code>optional string sql_query = 1;</code>
+     */
+    boolean hasSqlQuery();
+    /**
+     * <code>optional string sql_query = 1;</code>
+     */
+    java.lang.String getSqlQuery();
+    /**
+     * <code>optional string sql_query = 1;</code>
+     */
+    com.google.protobuf.ByteString
+        getSqlQueryBytes();
+  }
+  /**
+   * Protobuf type {@code exec.bit.ServerPreparedStatementState}
+   *
+   * <pre>
+   *
+   * Prepared statement state on server side. Clients do not
+   * need to know the contents. They just need to submit it back to
+   * server when executing the prepared statement.
+   * </pre>
+   */
+  public static final class ServerPreparedStatementState extends
+      com.google.protobuf.GeneratedMessage
+      implements ServerPreparedStatementStateOrBuilder {
+    // Use ServerPreparedStatementState.newBuilder() to construct.
+    private ServerPreparedStatementState(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
+      super(builder);
+      this.unknownFields = builder.getUnknownFields();
+    }
+    private ServerPreparedStatementState(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
+
+    private static final ServerPreparedStatementState defaultInstance;
+    public static ServerPreparedStatementState getDefaultInstance() {
+      return defaultInstance;
+    }
+
+    public ServerPreparedStatementState getDefaultInstanceForType() {
+      return defaultInstance;
+    }
+
+    private final com.google.protobuf.UnknownFieldSet unknownFields;
+    @java.lang.Override
+    public final com.google.protobuf.UnknownFieldSet
+        getUnknownFields() {
+      return this.unknownFields;
+    }
+    private ServerPreparedStatementState(
+        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 10: {
+              bitField0_ |= 0x00000001;
+              sqlQuery_ = input.readBytes();
+              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.ExecProtos.internal_static_exec_bit_ServerPreparedStatementState_descriptor;
+    }
+
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+        internalGetFieldAccessorTable() {
+      return org.apache.drill.exec.proto.ExecProtos.internal_static_exec_bit_ServerPreparedStatementState_fieldAccessorTable
+          .ensureFieldAccessorsInitialized(
+              org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.class, org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.Builder.class);
+    }
+
+    public static com.google.protobuf.Parser<ServerPreparedStatementState> PARSER =
+        new com.google.protobuf.AbstractParser<ServerPreparedStatementState>() {
+      public ServerPreparedStatementState parsePartialFrom(
+          com.google.protobuf.CodedInputStream input,
+          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+          throws com.google.protobuf.InvalidProtocolBufferException {
+        return new ServerPreparedStatementState(input, extensionRegistry);
+      }
+    };
+
+    @java.lang.Override
+    public com.google.protobuf.Parser<ServerPreparedStatementState> getParserForType() {
+      return PARSER;
+    }
+
+    private int bitField0_;
+    // optional string sql_query = 1;
+    public static final int SQL_QUERY_FIELD_NUMBER = 1;
+    private java.lang.Object sqlQuery_;
+    /**
+     * <code>optional string sql_query = 1;</code>
+     */
+    public boolean hasSqlQuery() {
+      return ((bitField0_ & 0x00000001) == 0x00000001);
+    }
+    /**
+     * <code>optional string sql_query = 1;</code>
+     */
+    public java.lang.String getSqlQuery() {
+      java.lang.Object ref = sqlQuery_;
+      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()) {
+          sqlQuery_ = s;
+        }
+        return s;
+      }
+    }
+    /**
+     * <code>optional string sql_query = 1;</code>
+     */
+    public com.google.protobuf.ByteString
+        getSqlQueryBytes() {
+      java.lang.Object ref = sqlQuery_;
+      if (ref instanceof java.lang.String) {
+        com.google.protobuf.ByteString b = 
+            com.google.protobuf.ByteString.copyFromUtf8(
+                (java.lang.String) ref);
+        sqlQuery_ = b;
+        return b;
+      } else {
+        return (com.google.protobuf.ByteString) ref;
+      }
+    }
+
+    private void initFields() {
+      sqlQuery_ = "";
+    }
+    private byte memoizedIsInitialized = -1;
+    public final boolean isInitialized() {
+      byte isInitialized = memoizedIsInitialized;
+      if (isInitialized != -1) return isInitialized == 1;
+
+      memoizedIsInitialized = 1;
+      return true;
+    }
+
+    public void writeTo(com.google.protobuf.CodedOutputStream output)
+                        throws java.io.IOException {
+      getSerializedSize();
+      if (((bitField0_ & 0x00000001) == 0x00000001)) {
+        output.writeBytes(1, getSqlQueryBytes());
+      }
+      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, getSqlQueryBytes());
+      }
+      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.ExecProtos.ServerPreparedStatementState parseFrom(
+        com.google.protobuf.ByteString data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data);
+    }
+    public static org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState 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.ExecProtos.ServerPreparedStatementState parseFrom(byte[] data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return PARSER.parseFrom(data);
+    }
+    public static org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState 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.ExecProtos.ServerPreparedStatementState parseFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return PARSER.parseFrom(input);
+    }
+    public static org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState 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.ExecProtos.ServerPreparedStatementState parseDelimitedFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return PARSER.parseDelimitedFrom(input);
+    }
+    public static org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState 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.ExecProtos.ServerPreparedStatementState parseFrom(
+        com.google.protobuf.CodedInputStream input)
+        throws java.io.IOException {
+      return PARSER.parseFrom(input);
+    }
+    public static org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState 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.ExecProtos.ServerPreparedStatementState 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.bit.ServerPreparedStatementState}
+     *
+     * <pre>
+     *
+     * Prepared statement state on server side. Clients do not
+     * need to know the contents. They just need to submit it back to
+     * server when executing the prepared statement.
+     * </pre>
+     */
+    public static final class Builder extends
+        com.google.protobuf.GeneratedMessage.Builder<Builder>
+       implements org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementStateOrBuilder {
+      public static final com.google.protobuf.Descriptors.Descriptor
+          getDescriptor() {
+        return org.apache.drill.exec.proto.ExecProtos.internal_static_exec_bit_ServerPreparedStatementState_descriptor;
+      }
+
+      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+          internalGetFieldAccessorTable() {
+        return org.apache.drill.exec.proto.ExecProtos.internal_static_exec_bit_ServerPreparedStatementState_fieldAccessorTable
+            .ensureFieldAccessorsInitialized(
+                org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.class, org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.Builder.class);
+      }
+
+      // Construct using org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.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();
+        sqlQuery_ = "";
+        bitField0_ = (bitField0_ & ~0x00000001);
+        return this;
+      }
+
+      public Builder clone() {
+        return create().mergeFrom(buildPartial());
+      }
+
+      public com.google.protobuf.Descriptors.Descriptor
+          getDescriptorForType() {
+        return org.apache.drill.exec.proto.ExecProtos.internal_static_exec_bit_ServerPreparedStatementState_descriptor;
+      }
+
+      public org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState getDefaultInstanceForType() {
+        return org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.getDefaultInstance();
+      }
+
+      public org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState build() {
+        org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState result = buildPartial();
+        if (!result.isInitialized()) {
+          throw newUninitializedMessageException(result);
+        }
+        return result;
+      }
+
+      public org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState buildPartial() {
+        org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState result = new org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState(this);
+        int from_bitField0_ = bitField0_;
+        int to_bitField0_ = 0;
+        if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
+          to_bitField0_ |= 0x00000001;
+        }
+        result.sqlQuery_ = sqlQuery_;
+        result.bitField0_ = to_bitField0_;
+        onBuilt();
+        return result;
+      }
+
+      public Builder mergeFrom(com.google.protobuf.Message other) {
+        if (other instanceof org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState) {
+          return mergeFrom((org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState)other);
+        } else {
+          super.mergeFrom(other);
+          return this;
+        }
+      }
+
+      public Builder mergeFrom(org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState other) {
+        if (other == org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.getDefaultInstance()) return this;
+        if (other.hasSqlQuery()) {
+          bitField0_ |= 0x00000001;
+          sqlQuery_ = other.sqlQuery_;
+          onChanged();
+        }
+        this.mergeUnknownFields(other.getUnknownFields());
+        return this;
+      }
+
+      public final boolean isInitialized() {
+        return true;
+      }
+
+      public Builder mergeFrom(
+          com.google.protobuf.CodedInputStream input,
+          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+          throws java.io.IOException {
+        org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState parsedMessage = null;
+        try {
+          parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
+        } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+          parsedMessage = (org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState) e.getUnfinishedMessage();
+          throw e;
+        } finally {
+          if (parsedMessage != null) {
+            mergeFrom(parsedMessage);
+          }
+        }
+        return this;
+      }
+      private int bitField0_;
+
+      // optional string sql_query = 1;
+      private java.lang.Object sqlQuery_ = "";
+      /**
+       * <code>optional string sql_query = 1;</code>
+       */
+      public boolean hasSqlQuery() {
+        return ((bitField0_ & 0x00000001) == 0x00000001);
+      }
+      /**
+       * <code>optional string sql_query = 1;</code>
+       */
+      public java.lang.String getSqlQuery() {
+        java.lang.Object ref = sqlQuery_;
+        if (!(ref instanceof java.lang.String)) {
+          java.lang.String s = ((com.google.protobuf.ByteString) ref)
+              .toStringUtf8();
+          sqlQuery_ = s;
+          return s;
+        } else {
+          return (java.lang.String) ref;
+        }
+      }
+      /**
+       * <code>optional string sql_query = 1;</code>
+       */
+      public com.google.protobuf.ByteString
+          getSqlQueryBytes() {
+        java.lang.Object ref = sqlQuery_;
+        if (ref instanceof String) {
+          com.google.protobuf.ByteString b = 
+              com.google.protobuf.ByteString.copyFromUtf8(
+                  (java.lang.String) ref);
+          sqlQuery_ = b;
+          return b;
+        } else {
+          return (com.google.protobuf.ByteString) ref;
+        }
+      }
+      /**
+       * <code>optional string sql_query = 1;</code>
+       */
+      public Builder setSqlQuery(
+          java.lang.String value) {
+        if (value == null) {
+    throw new NullPointerException();
+  }
+  bitField0_ |= 0x00000001;
+        sqlQuery_ = value;
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>optional string sql_query = 1;</code>
+       */
+      public Builder clearSqlQuery() {
+        bitField0_ = (bitField0_ & ~0x00000001);
+        sqlQuery_ = getDefaultInstance().getSqlQuery();
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>optional string sql_query = 1;</code>
+       */
+      public Builder setSqlQueryBytes(
+          com.google.protobuf.ByteString value) {
+        if (value == null) {
+    throw new NullPointerException();
+  }
+  bitField0_ |= 0x00000001;
+        sqlQuery_ = value;
+        onChanged();
+        return this;
+      }
+
+      // @@protoc_insertion_point(builder_scope:exec.bit.ServerPreparedStatementState)
+    }
+
+    static {
+      defaultInstance = new ServerPreparedStatementState(true);
+      defaultInstance.initFields();
+    }
+
+    // @@protoc_insertion_point(class_scope:exec.bit.ServerPreparedStatementState)
+  }
+
   private static com.google.protobuf.Descriptors.Descriptor
     internal_static_exec_bit_FragmentHandle_descriptor;
   private static
     com.google.protobuf.GeneratedMessage.FieldAccessorTable
       internal_static_exec_bit_FragmentHandle_fieldAccessorTable;
+  private static com.google.protobuf.Descriptors.Descriptor
+    internal_static_exec_bit_ServerPreparedStatementState_descriptor;
+  private static
+    com.google.protobuf.GeneratedMessage.FieldAccessorTable
+      internal_static_exec_bit_ServerPreparedStatementState_fieldAccessorTable;
 
   public static com.google.protobuf.Descriptors.FileDescriptor
       getDescriptor() {
@@ -905,8 +1395,10 @@ public final class ExecProtos {
       "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"
+      "ery_id\030\004 \001(\0132\024.exec.shared.QueryId\"1\n\034Se" +
+      "rverPreparedStatementState\022\021\n\tsql_query\030" +
+      "\001 \001(\tB+\n\033org.apache.drill.exec.protoB\nEx" +
+      "ecProtosH\001"
     };
     com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
       new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
@@ -919,6 +1411,12 @@ public final class ExecProtos {
             com.google.protobuf.GeneratedMessage.FieldAccessorTable(
               internal_static_exec_bit_FragmentHandle_descriptor,
               new java.lang.String[] { "QueryId", "MajorFragmentId", "MinorFragmentId", "ParentQueryId", });
+          internal_static_exec_bit_ServerPreparedStatementState_descriptor =
+            getDescriptor().getMessageTypes().get(1);
+          internal_static_exec_bit_ServerPreparedStatementState_fieldAccessorTable = new
+            com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+              internal_static_exec_bit_ServerPreparedStatementState_descriptor,
+              new java.lang.String[] { "SqlQuery", });
           return null;
         }
       };

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 f996868..bfbbf7a 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
@@ -160,4 +160,115 @@ public final class SchemaExecProtos
         }
     }
 
+    public static final class ServerPreparedStatementState
+    {
+        public static final org.apache.drill.exec.proto.SchemaExecProtos.ServerPreparedStatementState.MessageSchema WRITE =
+            new org.apache.drill.exec.proto.SchemaExecProtos.ServerPreparedStatementState.MessageSchema();
+        public static final org.apache.drill.exec.proto.SchemaExecProtos.ServerPreparedStatementState.BuilderSchema MERGE =
+            new org.apache.drill.exec.proto.SchemaExecProtos.ServerPreparedStatementState.BuilderSchema();
+        
+        public static class MessageSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState>
+        {
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState message) throws java.io.IOException
+            {
+                if(message.hasSqlQuery())
+                    output.writeString(1, message.getSqlQuery(), false);
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState message)
+            {
+                return message.isInitialized();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaExecProtos.ServerPreparedStatementState.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaExecProtos.ServerPreparedStatementState.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState> typeClass()
+            {
+                return org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.class.getName();
+            }
+            //unused
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState message) throws java.io.IOException {}
+            public org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState newMessage() { return null; }
+        }
+        public static class BuilderSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.Builder>
+        {
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.Builder builder) throws java.io.IOException
+            {
+                for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+                {
+                    switch(number)
+                    {
+                        case 0:
+                            return;
+                        case 1:
+                            builder.setSqlQuery(input.readString());
+                            break;
+                        default:
+                            input.handleUnknownField(number, this);
+                    }
+                }
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.Builder builder)
+            {
+                return builder.isInitialized();
+            }
+            public org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.Builder newMessage()
+            {
+                return org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.newBuilder();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaExecProtos.ServerPreparedStatementState.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaExecProtos.ServerPreparedStatementState.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.Builder> typeClass()
+            {
+                return org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.Builder.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.class.getName();
+            }
+            //unused
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.ExecProtos.ServerPreparedStatementState.Builder builder) throws java.io.IOException {}
+        }
+        public static java.lang.String getFieldName(int number)
+        {
+            switch(number)
+            {
+                case 1: return "sqlQuery";
+                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("sqlQuery", 1);
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 9c91d1d..833869b 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
@@ -532,140 +532,6 @@ public final class SchemaUserProtos
         }
     }
 
-    public static final class RunQuery
-    {
-        public static final org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.MessageSchema WRITE =
-            new org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.MessageSchema();
-        public static final org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.BuilderSchema MERGE =
-            new org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.BuilderSchema();
-        
-        public static class MessageSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.RunQuery>
-        {
-            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.RunQuery message) throws java.io.IOException
-            {
-                if(message.hasResultsMode())
-                    output.writeEnum(1, message.getResultsMode().getNumber(), false);
-                if(message.hasType())
-                    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)
-            {
-                return message.isInitialized();
-            }
-            public java.lang.String getFieldName(int number)
-            {
-                return org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.getFieldName(number);
-            }
-            public int getFieldNumber(java.lang.String name)
-            {
-                return org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.getFieldNumber(name);
-            }
-            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.RunQuery> typeClass()
-            {
-                return org.apache.drill.exec.proto.UserProtos.RunQuery.class;
-            }
-            public java.lang.String messageName()
-            {
-                return org.apache.drill.exec.proto.UserProtos.RunQuery.class.getSimpleName();
-            }
-            public java.lang.String messageFullName()
-            {
-                return org.apache.drill.exec.proto.UserProtos.RunQuery.class.getName();
-            }
-            //unused
-            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.RunQuery message) throws java.io.IOException {}
-            public org.apache.drill.exec.proto.UserProtos.RunQuery newMessage() { return null; }
-        }
-        public static class BuilderSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.RunQuery.Builder>
-        {
-            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.RunQuery.Builder builder) throws java.io.IOException
-            {
-                for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
-                {
-                    switch(number)
-                    {
-                        case 0:
-                            return;
-                        case 1:
-                            builder.setResultsMode(org.apache.drill.exec.proto.UserProtos.QueryResultsMode.valueOf(input.readEnum()));
-                            break;
-                        case 2:
-                            builder.setType(org.apache.drill.exec.proto.UserBitShared.QueryType.valueOf(input.readEnum()));
-                            break;
-                        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);
-                    }
-                }
-            }
-            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.RunQuery.Builder builder)
-            {
-                return builder.isInitialized();
-            }
-            public org.apache.drill.exec.proto.UserProtos.RunQuery.Builder newMessage()
-            {
-                return org.apache.drill.exec.proto.UserProtos.RunQuery.newBuilder();
-            }
-            public java.lang.String getFieldName(int number)
-            {
-                return org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.getFieldName(number);
-            }
-            public int getFieldNumber(java.lang.String name)
-            {
-                return org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.getFieldNumber(name);
-            }
-            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.RunQuery.Builder> typeClass()
-            {
-                return org.apache.drill.exec.proto.UserProtos.RunQuery.Builder.class;
-            }
-            public java.lang.String messageName()
-            {
-                return org.apache.drill.exec.proto.UserProtos.RunQuery.class.getSimpleName();
-            }
-            public java.lang.String messageFullName()
-            {
-                return org.apache.drill.exec.proto.UserProtos.RunQuery.class.getName();
-            }
-            //unused
-            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.RunQuery.Builder builder) throws java.io.IOException {}
-        }
-        public static java.lang.String getFieldName(int number)
-        {
-            switch(number)
-            {
-                case 1: return "resultsMode";
-                case 2: return "type";
-                case 3: return "plan";
-                case 4: return "fragments";
-                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("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 =
@@ -2813,4 +2679,858 @@ public final class SchemaUserProtos
         }
     }
 
+    public static final class CreatePreparedStatementReq
+    {
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementReq.MessageSchema WRITE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementReq.MessageSchema();
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementReq.BuilderSchema MERGE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementReq.BuilderSchema();
+        
+        public static class MessageSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq>
+        {
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq message) throws java.io.IOException
+            {
+                if(message.hasSqlQuery())
+                    output.writeString(1, message.getSqlQuery(), false);
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq message)
+            {
+                return message.isInitialized();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementReq.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementReq.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.class.getName();
+            }
+            //unused
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq message) throws java.io.IOException {}
+            public org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq newMessage() { return null; }
+        }
+        public static class BuilderSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.Builder>
+        {
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.Builder builder) throws java.io.IOException
+            {
+                for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+                {
+                    switch(number)
+                    {
+                        case 0:
+                            return;
+                        case 1:
+                            builder.setSqlQuery(input.readString());
+                            break;
+                        default:
+                            input.handleUnknownField(number, this);
+                    }
+                }
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.Builder builder)
+            {
+                return builder.isInitialized();
+            }
+            public org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.Builder newMessage()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.newBuilder();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementReq.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementReq.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.Builder> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.Builder.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.class.getName();
+            }
+            //unused
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementReq.Builder builder) throws java.io.IOException {}
+        }
+        public static java.lang.String getFieldName(int number)
+        {
+            switch(number)
+            {
+                case 1: return "sqlQuery";
+                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("sqlQuery", 1);
+        }
+    }
+
+    public static final class ResultColumnMetadata
+    {
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.ResultColumnMetadata.MessageSchema WRITE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.ResultColumnMetadata.MessageSchema();
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.ResultColumnMetadata.BuilderSchema MERGE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.ResultColumnMetadata.BuilderSchema();
+        
+        public static class MessageSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata>
+        {
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata message) throws java.io.IOException
+            {
+                if(message.hasCatalogName())
+                    output.writeString(1, message.getCatalogName(), false);
+                if(message.hasSchemaName())
+                    output.writeString(2, message.getSchemaName(), false);
+                if(message.hasTableName())
+                    output.writeString(3, message.getTableName(), false);
+                if(message.hasColumnName())
+                    output.writeString(4, message.getColumnName(), false);
+                if(message.hasLabel())
+                    output.writeString(5, message.getLabel(), false);
+                if(message.hasDataType())
+                    output.writeString(6, message.getDataType(), false);
+                if(message.hasIsNullable())
+                    output.writeBool(7, message.getIsNullable(), false);
+                if(message.hasPrecision())
+                    output.writeInt32(8, message.getPrecision(), false);
+                if(message.hasScale())
+                    output.writeInt32(9, message.getScale(), false);
+                if(message.hasSigned())
+                    output.writeBool(10, message.getSigned(), false);
+                if(message.hasDisplaySize())
+                    output.writeInt32(11, message.getDisplaySize(), false);
+                if(message.hasIsAliased())
+                    output.writeBool(12, message.getIsAliased(), false);
+                if(message.hasSearchability())
+                    output.writeEnum(13, message.getSearchability().getNumber(), false);
+                if(message.hasUpdatability())
+                    output.writeEnum(14, message.getUpdatability().getNumber(), false);
+                if(message.hasAutoIncrement())
+                    output.writeBool(15, message.getAutoIncrement(), false);
+                if(message.hasCaseSensitivity())
+                    output.writeBool(16, message.getCaseSensitivity(), false);
+                if(message.hasSortable())
+                    output.writeBool(17, message.getSortable(), false);
+                if(message.hasClassName())
+                    output.writeString(18, message.getClassName(), false);
+                if(message.hasIsCurrency())
+                    output.writeBool(20, message.getIsCurrency(), false);
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata message)
+            {
+                return message.isInitialized();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.ResultColumnMetadata.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.ResultColumnMetadata.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.class.getName();
+            }
+            //unused
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata message) throws java.io.IOException {}
+            public org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata newMessage() { return null; }
+        }
+        public static class BuilderSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.Builder>
+        {
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.Builder builder) throws java.io.IOException
+            {
+                for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+                {
+                    switch(number)
+                    {
+                        case 0:
+                            return;
+                        case 1:
+                            builder.setCatalogName(input.readString());
+                            break;
+                        case 2:
+                            builder.setSchemaName(input.readString());
+                            break;
+                        case 3:
+                            builder.setTableName(input.readString());
+                            break;
+                        case 4:
+                            builder.setColumnName(input.readString());
+                            break;
+                        case 5:
+                            builder.setLabel(input.readString());
+                            break;
+                        case 6:
+                            builder.setDataType(input.readString());
+                            break;
+                        case 7:
+                            builder.setIsNullable(input.readBool());
+                            break;
+                        case 8:
+                            builder.setPrecision(input.readInt32());
+                            break;
+                        case 9:
+                            builder.setScale(input.readInt32());
+                            break;
+                        case 10:
+                            builder.setSigned(input.readBool());
+                            break;
+                        case 11:
+                            builder.setDisplaySize(input.readInt32());
+                            break;
+                        case 12:
+                            builder.setIsAliased(input.readBool());
+                            break;
+                        case 13:
+                            builder.setSearchability(org.apache.drill.exec.proto.UserProtos.ColumnSearchability.valueOf(input.readEnum()));
+                            break;
+                        case 14:
+                            builder.setUpdatability(org.apache.drill.exec.proto.UserProtos.ColumnUpdatability.valueOf(input.readEnum()));
+                            break;
+                        case 15:
+                            builder.setAutoIncrement(input.readBool());
+                            break;
+                        case 16:
+                            builder.setCaseSensitivity(input.readBool());
+                            break;
+                        case 17:
+                            builder.setSortable(input.readBool());
+                            break;
+                        case 18:
+                            builder.setClassName(input.readString());
+                            break;
+                        case 20:
+                            builder.setIsCurrency(input.readBool());
+                            break;
+                        default:
+                            input.handleUnknownField(number, this);
+                    }
+                }
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.Builder builder)
+            {
+                return builder.isInitialized();
+            }
+            public org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.Builder newMessage()
+            {
+                return org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.newBuilder();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.ResultColumnMetadata.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.ResultColumnMetadata.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.Builder> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.Builder.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.class.getName();
+            }
+            //unused
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.Builder builder) throws java.io.IOException {}
+        }
+        public static java.lang.String getFieldName(int number)
+        {
+            switch(number)
+            {
+                case 1: return "catalogName";
+                case 2: return "schemaName";
+                case 3: return "tableName";
+                case 4: return "columnName";
+                case 5: return "label";
+                case 6: return "dataType";
+                case 7: return "isNullable";
+                case 8: return "precision";
+                case 9: return "scale";
+                case 10: return "signed";
+                case 11: return "displaySize";
+                case 12: return "isAliased";
+                case 13: return "searchability";
+                case 14: return "updatability";
+                case 15: return "autoIncrement";
+                case 16: return "caseSensitivity";
+                case 17: return "sortable";
+                case 18: return "className";
+                case 20: return "isCurrency";
+                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("catalogName", 1);
+            fieldMap.put("schemaName", 2);
+            fieldMap.put("tableName", 3);
+            fieldMap.put("columnName", 4);
+            fieldMap.put("label", 5);
+            fieldMap.put("dataType", 6);
+            fieldMap.put("isNullable", 7);
+            fieldMap.put("precision", 8);
+            fieldMap.put("scale", 9);
+            fieldMap.put("signed", 10);
+            fieldMap.put("displaySize", 11);
+            fieldMap.put("isAliased", 12);
+            fieldMap.put("searchability", 13);
+            fieldMap.put("updatability", 14);
+            fieldMap.put("autoIncrement", 15);
+            fieldMap.put("caseSensitivity", 16);
+            fieldMap.put("sortable", 17);
+            fieldMap.put("className", 18);
+            fieldMap.put("isCurrency", 20);
+        }
+    }
+
+    public static final class PreparedStatementHandle
+    {
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.MessageSchema WRITE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.MessageSchema();
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.BuilderSchema MERGE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.BuilderSchema();
+        
+        public static class MessageSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle>
+        {
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle message) throws java.io.IOException
+            {
+                if(message.hasServerInfo())
+                    output.writeByteArray(1, message.getServerInfo().toByteArray(), false);
+
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle message)
+            {
+                return message.isInitialized();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.class.getName();
+            }
+            //unused
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle message) throws java.io.IOException {}
+            public org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle newMessage() { return null; }
+        }
+        public static class BuilderSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.Builder>
+        {
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.Builder builder) throws java.io.IOException
+            {
+                for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+                {
+                    switch(number)
+                    {
+                        case 0:
+                            return;
+                        case 1:
+                            builder.setServerInfo(com.google.protobuf.ByteString.copyFrom(input.readByteArray()));
+                            break;
+                        default:
+                            input.handleUnknownField(number, this);
+                    }
+                }
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.Builder builder)
+            {
+                return builder.isInitialized();
+            }
+            public org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.Builder newMessage()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.newBuilder();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.Builder> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.Builder.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.class.getName();
+            }
+            //unused
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.Builder builder) throws java.io.IOException {}
+        }
+        public static java.lang.String getFieldName(int number)
+        {
+            switch(number)
+            {
+                case 1: return "serverInfo";
+                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("serverInfo", 1);
+        }
+    }
+
+    public static final class PreparedStatement
+    {
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatement.MessageSchema WRITE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatement.MessageSchema();
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatement.BuilderSchema MERGE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatement.BuilderSchema();
+        
+        public static class MessageSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.PreparedStatement>
+        {
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.PreparedStatement message) throws java.io.IOException
+            {
+                for(org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata columns : message.getColumnsList())
+                    output.writeObject(1, columns, org.apache.drill.exec.proto.SchemaUserProtos.ResultColumnMetadata.WRITE, true);
+
+                if(message.hasServerHandle())
+                    output.writeObject(2, message.getServerHandle(), org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.WRITE, false);
+
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.PreparedStatement message)
+            {
+                return message.isInitialized();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatement.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatement.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.PreparedStatement> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatement.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatement.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatement.class.getName();
+            }
+            //unused
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.PreparedStatement message) throws java.io.IOException {}
+            public org.apache.drill.exec.proto.UserProtos.PreparedStatement newMessage() { return null; }
+        }
+        public static class BuilderSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.PreparedStatement.Builder>
+        {
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.PreparedStatement.Builder builder) throws java.io.IOException
+            {
+                for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+                {
+                    switch(number)
+                    {
+                        case 0:
+                            return;
+                        case 1:
+                            builder.addColumns(input.mergeObject(org.apache.drill.exec.proto.UserProtos.ResultColumnMetadata.newBuilder(), org.apache.drill.exec.proto.SchemaUserProtos.ResultColumnMetadata.MERGE));
+
+                            break;
+                        case 2:
+                            builder.setServerHandle(input.mergeObject(org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.newBuilder(), org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.MERGE));
+
+                            break;
+                        default:
+                            input.handleUnknownField(number, this);
+                    }
+                }
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.PreparedStatement.Builder builder)
+            {
+                return builder.isInitialized();
+            }
+            public org.apache.drill.exec.proto.UserProtos.PreparedStatement.Builder newMessage()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatement.newBuilder();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatement.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatement.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.PreparedStatement.Builder> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatement.Builder.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatement.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.PreparedStatement.class.getName();
+            }
+            //unused
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.PreparedStatement.Builder builder) throws java.io.IOException {}
+        }
+        public static java.lang.String getFieldName(int number)
+        {
+            switch(number)
+            {
+                case 1: return "columns";
+                case 2: return "serverHandle";
+                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("columns", 1);
+            fieldMap.put("serverHandle", 2);
+        }
+    }
+
+    public static final class CreatePreparedStatementResp
+    {
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementResp.MessageSchema WRITE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementResp.MessageSchema();
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementResp.BuilderSchema MERGE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementResp.BuilderSchema();
+        
+        public static class MessageSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp>
+        {
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp message) throws java.io.IOException
+            {
+                if(message.hasStatus())
+                    output.writeEnum(1, message.getStatus().getNumber(), false);
+                if(message.hasPreparedStatement())
+                    output.writeObject(2, message.getPreparedStatement(), org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatement.WRITE, false);
+
+                if(message.hasError())
+                    output.writeObject(3, message.getError(), org.apache.drill.exec.proto.SchemaUserBitShared.DrillPBError.WRITE, false);
+
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp message)
+            {
+                return message.isInitialized();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementResp.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementResp.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.class.getName();
+            }
+            //unused
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp message) throws java.io.IOException {}
+            public org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp newMessage() { return null; }
+        }
+        public static class BuilderSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.Builder>
+        {
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.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.UserProtos.RequestStatus.valueOf(input.readEnum()));
+                            break;
+                        case 2:
+                            builder.setPreparedStatement(input.mergeObject(org.apache.drill.exec.proto.UserProtos.PreparedStatement.newBuilder(), org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatement.MERGE));
+
+                            break;
+                        case 3:
+                            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.CreatePreparedStatementResp.Builder builder)
+            {
+                return builder.isInitialized();
+            }
+            public org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.Builder newMessage()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.newBuilder();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementResp.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.CreatePreparedStatementResp.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.Builder> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.Builder.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.class.getName();
+            }
+            //unused
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.CreatePreparedStatementResp.Builder builder) throws java.io.IOException {}
+        }
+        public static java.lang.String getFieldName(int number)
+        {
+            switch(number)
+            {
+                case 1: return "status";
+                case 2: return "preparedStatement";
+                case 3: 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("preparedStatement", 2);
+            fieldMap.put("error", 3);
+        }
+    }
+
+    public static final class RunQuery
+    {
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.MessageSchema WRITE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.MessageSchema();
+        public static final org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.BuilderSchema MERGE =
+            new org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.BuilderSchema();
+        
+        public static class MessageSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.RunQuery>
+        {
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.RunQuery message) throws java.io.IOException
+            {
+                if(message.hasResultsMode())
+                    output.writeEnum(1, message.getResultsMode().getNumber(), false);
+                if(message.hasType())
+                    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);
+
+                if(message.hasPreparedStatementHandle())
+                    output.writeObject(5, message.getPreparedStatementHandle(), org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.WRITE, false);
+
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.RunQuery message)
+            {
+                return message.isInitialized();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.RunQuery> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.RunQuery.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.RunQuery.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.RunQuery.class.getName();
+            }
+            //unused
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.RunQuery message) throws java.io.IOException {}
+            public org.apache.drill.exec.proto.UserProtos.RunQuery newMessage() { return null; }
+        }
+        public static class BuilderSchema implements com.dyuproject.protostuff.Schema<org.apache.drill.exec.proto.UserProtos.RunQuery.Builder>
+        {
+            public void mergeFrom(com.dyuproject.protostuff.Input input, org.apache.drill.exec.proto.UserProtos.RunQuery.Builder builder) throws java.io.IOException
+            {
+                for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
+                {
+                    switch(number)
+                    {
+                        case 0:
+                            return;
+                        case 1:
+                            builder.setResultsMode(org.apache.drill.exec.proto.UserProtos.QueryResultsMode.valueOf(input.readEnum()));
+                            break;
+                        case 2:
+                            builder.setType(org.apache.drill.exec.proto.UserBitShared.QueryType.valueOf(input.readEnum()));
+                            break;
+                        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;
+                        case 5:
+                            builder.setPreparedStatementHandle(input.mergeObject(org.apache.drill.exec.proto.UserProtos.PreparedStatementHandle.newBuilder(), org.apache.drill.exec.proto.SchemaUserProtos.PreparedStatementHandle.MERGE));
+
+                            break;
+                        default:
+                            input.handleUnknownField(number, this);
+                    }
+                }
+            }
+            public boolean isInitialized(org.apache.drill.exec.proto.UserProtos.RunQuery.Builder builder)
+            {
+                return builder.isInitialized();
+            }
+            public org.apache.drill.exec.proto.UserProtos.RunQuery.Builder newMessage()
+            {
+                return org.apache.drill.exec.proto.UserProtos.RunQuery.newBuilder();
+            }
+            public java.lang.String getFieldName(int number)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.getFieldName(number);
+            }
+            public int getFieldNumber(java.lang.String name)
+            {
+                return org.apache.drill.exec.proto.SchemaUserProtos.RunQuery.getFieldNumber(name);
+            }
+            public java.lang.Class<org.apache.drill.exec.proto.UserProtos.RunQuery.Builder> typeClass()
+            {
+                return org.apache.drill.exec.proto.UserProtos.RunQuery.Builder.class;
+            }
+            public java.lang.String messageName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.RunQuery.class.getSimpleName();
+            }
+            public java.lang.String messageFullName()
+            {
+                return org.apache.drill.exec.proto.UserProtos.RunQuery.class.getName();
+            }
+            //unused
+            public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.UserProtos.RunQuery.Builder builder) throws java.io.IOException {}
+        }
+        public static java.lang.String getFieldName(int number)
+        {
+            switch(number)
+            {
+                case 1: return "resultsMode";
+                case 2: return "type";
+                case 3: return "plan";
+                case 4: return "fragments";
+                case 5: return "preparedStatementHandle";
+                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("resultsMode", 1);
+            fieldMap.put("type", 2);
+            fieldMap.put("plan", 3);
+            fieldMap.put("fragments", 4);
+            fieldMap.put("preparedStatementHandle", 5);
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 cafdfdd..c970af0 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
@@ -137,6 +137,14 @@ public final class UserBitShared {
      * <code>EXECUTION = 4;</code>
      */
     EXECUTION(3, 4),
+    /**
+     * <code>PREPARED_STATEMENT = 5;</code>
+     *
+     * <pre>
+     * Input is a prepared statement 
+     * </pre>
+     */
+    PREPARED_STATEMENT(4, 5),
     ;
 
     /**
@@ -155,6 +163,14 @@ public final class UserBitShared {
      * <code>EXECUTION = 4;</code>
      */
     public static final int EXECUTION_VALUE = 4;
+    /**
+     * <code>PREPARED_STATEMENT = 5;</code>
+     *
+     * <pre>
+     * Input is a prepared statement 
+     * </pre>
+     */
+    public static final int PREPARED_STATEMENT_VALUE = 5;
 
 
     public final int getNumber() { return value; }
@@ -165,6 +181,7 @@ public final class UserBitShared {
         case 2: return LOGICAL;
         case 3: return PHYSICAL;
         case 4: return EXECUTION;
+        case 5: return PREPARED_STATEMENT;
         default: return null;
       }
     }
@@ -20870,32 +20887,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" +
+      "\010BIT_DATA\020\001\022\010\n\004USER\020\002*V\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"
+      "ION\020\004\022\026\n\022PREPARED_STATEMENT\020\005*\207\001\n\rFragme" +
+      "ntState\022\013\n\007SENDING\020\000\022\027\n\023AWAITING_ALLOCAT",
+      "ION\020\001\022\013\n\007RUNNING\020\002\022\014\n\010FINISHED\020\003\022\r\n\tCANC" +
+      "ELLED\020\004\022\n\n\006FAILED\020\005\022\032\n\026CANCELLATION_REQU" +
+      "ESTED\020\006*\335\005\n\020CoreOperatorType\022\021\n\rSINGLE_S" +
+      "ENDER\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\n" +
+      "MERGE_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\030ORDE" +
+      "RED_PARTITION_SENDER\020\t\022\013\n\007PROJECT\020\n\022\026\n\022U" +
+      "NORDERED_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_SCA" +
+      "N\020\025\022\021\n\rHIVE_SUB_SCAN\020\026\022\025\n\021SYSTEM_TABLE_S" +
+      "CAN\020\027\022\021\n\rMOCK_SUB_SCAN\020\030\022\022\n\016PARQUET_WRIT" +
+      "ER\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_CONSUMER\020 \022\022\n\016HBASE_" +
+      "SUB_SCAN\020!\022\n\n\006WINDOW\020\"\022\024\n\020NESTED_LOOP_JO",
+      "IN\020#\022\021\n\rAVRO_SUB_SCAN\020$B.\n\033org.apache.dr" +
+      "ill.exec.protoB\rUserBitSharedH\001"
     };
     com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
       new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {


[2/4] drill git commit: DRILL-4729: Add support for prepared statement implementation on server side

Posted by ve...@apache.org.
http://git-wip-us.apache.org/repos/asf/drill/blob/14f6ec7d/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 1bd4641..54fe315 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
@@ -115,17 +115,25 @@ public final class UserProtos {
      */
     GET_COLUMNS(11, 17),
     /**
+     * <code>CREATE_PREPARED_STATEMENT = 22;</code>
+     *
+     * <pre>
+     * user is sending a request to create prepared statement
+     * </pre>
+     */
+    CREATE_PREPARED_STATEMENT(12, 22),
+    /**
      * <code>QUERY_DATA = 6;</code>
      *
      * <pre>
      * bit to user
      * </pre>
      */
-    QUERY_DATA(12, 6),
+    QUERY_DATA(13, 6),
     /**
      * <code>QUERY_HANDLE = 7;</code>
      */
-    QUERY_HANDLE(13, 7),
+    QUERY_HANDLE(14, 7),
     /**
      * <code>QUERY_PLAN_FRAGMENTS = 13;</code>
      *
@@ -133,7 +141,7 @@ public final class UserProtos {
      * return plan fragments
      * </pre>
      */
-    QUERY_PLAN_FRAGMENTS(14, 13),
+    QUERY_PLAN_FRAGMENTS(15, 13),
     /**
      * <code>CATALOGS = 18;</code>
      *
@@ -141,7 +149,7 @@ public final class UserProtos {
      * return catalogs metadata in response to GET_CATALOGS
      * </pre>
      */
-    CATALOGS(15, 18),
+    CATALOGS(16, 18),
     /**
      * <code>SCHEMAS = 19;</code>
      *
@@ -149,7 +157,7 @@ public final class UserProtos {
      * return schema metadata in response to GET_SCHEMAS
      * </pre>
      */
-    SCHEMAS(16, 19),
+    SCHEMAS(17, 19),
     /**
      * <code>TABLES = 20;</code>
      *
@@ -157,7 +165,7 @@ public final class UserProtos {
      * return table metadata in response to GET_TABLES
      * </pre>
      */
-    TABLES(17, 20),
+    TABLES(18, 20),
     /**
      * <code>COLUMNS = 21;</code>
      *
@@ -165,15 +173,23 @@ public final class UserProtos {
      * return column metadata in response to GET_COLUMNS
      * </pre>
      */
-    COLUMNS(18, 21),
+    COLUMNS(19, 21),
+    /**
+     * <code>PREPARED_STATEMENT = 23;</code>
+     *
+     * <pre>
+     * return preparated statement in response to CREATE_PREPARED_STATEMENT
+     * </pre>
+     */
+    PREPARED_STATEMENT(20, 23),
     /**
      * <code>REQ_META_FUNCTIONS = 8;</code>
      */
-    REQ_META_FUNCTIONS(19, 8),
+    REQ_META_FUNCTIONS(21, 8),
     /**
      * <code>RESP_FUNCTION_LIST = 9;</code>
      */
-    RESP_FUNCTION_LIST(20, 9),
+    RESP_FUNCTION_LIST(22, 9),
     /**
      * <code>QUERY_RESULT = 10;</code>
      *
@@ -181,7 +197,7 @@ public final class UserProtos {
      * drillbit is reporting a query status change, most likely a terminal message, to the user
      * </pre>
      */
-    QUERY_RESULT(21, 10),
+    QUERY_RESULT(23, 10),
     ;
 
     /**
@@ -265,6 +281,14 @@ public final class UserProtos {
      */
     public static final int GET_COLUMNS_VALUE = 17;
     /**
+     * <code>CREATE_PREPARED_STATEMENT = 22;</code>
+     *
+     * <pre>
+     * user is sending a request to create prepared statement
+     * </pre>
+     */
+    public static final int CREATE_PREPARED_STATEMENT_VALUE = 22;
+    /**
      * <code>QUERY_DATA = 6;</code>
      *
      * <pre>
@@ -317,6 +341,14 @@ public final class UserProtos {
      */
     public static final int COLUMNS_VALUE = 21;
     /**
+     * <code>PREPARED_STATEMENT = 23;</code>
+     *
+     * <pre>
+     * return preparated statement in response to CREATE_PREPARED_STATEMENT
+     * </pre>
+     */
+    public static final int PREPARED_STATEMENT_VALUE = 23;
+    /**
      * <code>REQ_META_FUNCTIONS = 8;</code>
      */
     public static final int REQ_META_FUNCTIONS_VALUE = 8;
@@ -350,6 +382,7 @@ public final class UserProtos {
         case 15: return GET_SCHEMAS;
         case 16: return GET_TABLES;
         case 17: return GET_COLUMNS;
+        case 22: return CREATE_PREPARED_STATEMENT;
         case 6: return QUERY_DATA;
         case 7: return QUERY_HANDLE;
         case 13: return QUERY_PLAN_FRAGMENTS;
@@ -357,6 +390,7 @@ public final class UserProtos {
         case 19: return SCHEMAS;
         case 20: return TABLES;
         case 21: return COLUMNS;
+        case 23: return PREPARED_STATEMENT;
         case 8: return REQ_META_FUNCTIONS;
         case 9: return RESP_FUNCTION_LIST;
         case 10: return QUERY_RESULT;
@@ -635,9 +669,9 @@ public final class UserProtos {
   public enum RequestStatus
       implements com.google.protobuf.ProtocolMessageEnum {
     /**
-     * <code>UNKNOWN = 0;</code>
+     * <code>UNKNOWN_STATUS = 0;</code>
      */
-    UNKNOWN(0, 0),
+    UNKNOWN_STATUS(0, 0),
     /**
      * <code>OK = 1;</code>
      */
@@ -646,12 +680,21 @@ public final class UserProtos {
      * <code>FAILED = 2;</code>
      */
     FAILED(2, 2),
+    /**
+     * <code>TIMEOUT = 3;</code>
+     *
+     * <pre>
+     **
+     * Request timed out. Futher attempts can change any API specific parameters and retry or just retry the request.
+     * </pre>
+     */
+    TIMEOUT(3, 3),
     ;
 
     /**
-     * <code>UNKNOWN = 0;</code>
+     * <code>UNKNOWN_STATUS = 0;</code>
      */
-    public static final int UNKNOWN_VALUE = 0;
+    public static final int UNKNOWN_STATUS_VALUE = 0;
     /**
      * <code>OK = 1;</code>
      */
@@ -660,15 +703,25 @@ public final class UserProtos {
      * <code>FAILED = 2;</code>
      */
     public static final int FAILED_VALUE = 2;
+    /**
+     * <code>TIMEOUT = 3;</code>
+     *
+     * <pre>
+     **
+     * Request timed out. Futher attempts can change any API specific parameters and retry or just retry the request.
+     * </pre>
+     */
+    public static final int TIMEOUT_VALUE = 3;
 
 
     public final int getNumber() { return value; }
 
     public static RequestStatus valueOf(int value) {
       switch (value) {
-        case 0: return UNKNOWN;
+        case 0: return UNKNOWN_STATUS;
         case 1: return OK;
         case 2: return FAILED;
+        case 3: return TIMEOUT;
         default: return null;
       }
     }
@@ -720,6 +773,248 @@ public final class UserProtos {
     // @@protoc_insertion_point(enum_scope:exec.user.RequestStatus)
   }
 
+  /**
+   * Protobuf enum {@code exec.user.ColumnSearchability}
+   *
+   * <pre>
+   *
+   * How a column can be used in WHERE clause
+   * </pre>
+   */
+  public enum ColumnSearchability
+      implements com.google.protobuf.ProtocolMessageEnum {
+    /**
+     * <code>UNKNOWN_SEARCHABILITY = 0;</code>
+     */
+    UNKNOWN_SEARCHABILITY(0, 0),
+    /**
+     * <code>NONE = 1;</code>
+     *
+     * <pre>
+     * can't be used in WHERE clause
+     * </pre>
+     */
+    NONE(1, 1),
+    /**
+     * <code>CHAR = 2;</code>
+     *
+     * <pre>
+     * can be used in WHERE clause but only with LIKE predicate
+     * </pre>
+     */
+    CHAR(2, 2),
+    /**
+     * <code>NUMBER = 3;</code>
+     *
+     * <pre>
+     * can be used in a WHERE clause with all the comparison operators except LIKE
+     * </pre>
+     */
+    NUMBER(3, 3),
+    /**
+     * <code>ALL = 4;</code>
+     *
+     * <pre>
+     * can be used in a WHERE clause with all the comparison operators
+     * </pre>
+     */
+    ALL(4, 4),
+    ;
+
+    /**
+     * <code>UNKNOWN_SEARCHABILITY = 0;</code>
+     */
+    public static final int UNKNOWN_SEARCHABILITY_VALUE = 0;
+    /**
+     * <code>NONE = 1;</code>
+     *
+     * <pre>
+     * can't be used in WHERE clause
+     * </pre>
+     */
+    public static final int NONE_VALUE = 1;
+    /**
+     * <code>CHAR = 2;</code>
+     *
+     * <pre>
+     * can be used in WHERE clause but only with LIKE predicate
+     * </pre>
+     */
+    public static final int CHAR_VALUE = 2;
+    /**
+     * <code>NUMBER = 3;</code>
+     *
+     * <pre>
+     * can be used in a WHERE clause with all the comparison operators except LIKE
+     * </pre>
+     */
+    public static final int NUMBER_VALUE = 3;
+    /**
+     * <code>ALL = 4;</code>
+     *
+     * <pre>
+     * can be used in a WHERE clause with all the comparison operators
+     * </pre>
+     */
+    public static final int ALL_VALUE = 4;
+
+
+    public final int getNumber() { return value; }
+
+    public static ColumnSearchability valueOf(int value) {
+      switch (value) {
+        case 0: return UNKNOWN_SEARCHABILITY;
+        case 1: return NONE;
+        case 2: return CHAR;
+        case 3: return NUMBER;
+        case 4: return ALL;
+        default: return null;
+      }
+    }
+
+    public static com.google.protobuf.Internal.EnumLiteMap<ColumnSearchability>
+        internalGetValueMap() {
+      return internalValueMap;
+    }
+    private static com.google.protobuf.Internal.EnumLiteMap<ColumnSearchability>
+        internalValueMap =
+          new com.google.protobuf.Internal.EnumLiteMap<ColumnSearchability>() {
+            public ColumnSearchability findValueByNumber(int number) {
+              return ColumnSearchability.valueOf(number);
+            }
+          };
+
+    public final com.google.protobuf.Descriptors.EnumValueDescriptor
+        getValueDescriptor() {
+      return getDescriptor().getValues().get(index);
+    }
+    public final com.google.protobuf.Descriptors.EnumDescriptor
+        getDescriptorForType() {
+      return getDescriptor();
+    }
+    public static final com.google.protobuf.Descriptors.EnumDescriptor
+        getDescriptor() {
+      return org.apache.drill.exec.proto.UserProtos.getDescriptor().getEnumTypes().get(4);
+    }
+
+    private static final ColumnSearchability[] VALUES = values();
+
+    public static ColumnSearchability valueOf(
+        com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
+      if (desc.getType() != getDescriptor()) {
+        throw new java.lang.IllegalArgumentException(
+          "EnumValueDescriptor is not for this type.");
+      }
+      return VALUES[desc.getIndex()];
+    }
+
+    private final int index;
+    private final int value;
+
+    private ColumnSearchability(int index, int value) {
+      this.index = index;
+      this.value = value;
+    }
+
+    // @@protoc_insertion_point(enum_scope:exec.user.ColumnSearchability)
+  }
+
+  /**
+   * Protobuf enum {@code exec.user.ColumnUpdatability}
+   *
+   * <pre>
+   *
+   * Whether a column can be updatable.
+   * </pre>
+   */
+  public enum ColumnUpdatability
+      implements com.google.protobuf.ProtocolMessageEnum {
+    /**
+     * <code>UNKNOWN_UPDATABILITY = 0;</code>
+     */
+    UNKNOWN_UPDATABILITY(0, 0),
+    /**
+     * <code>READ_ONLY = 1;</code>
+     */
+    READ_ONLY(1, 1),
+    /**
+     * <code>WRITABLE = 2;</code>
+     */
+    WRITABLE(2, 2),
+    ;
+
+    /**
+     * <code>UNKNOWN_UPDATABILITY = 0;</code>
+     */
+    public static final int UNKNOWN_UPDATABILITY_VALUE = 0;
+    /**
+     * <code>READ_ONLY = 1;</code>
+     */
+    public static final int READ_ONLY_VALUE = 1;
+    /**
+     * <code>WRITABLE = 2;</code>
+     */
+    public static final int WRITABLE_VALUE = 2;
+
+
+    public final int getNumber() { return value; }
+
+    public static ColumnUpdatability valueOf(int value) {
+      switch (value) {
+        case 0: return UNKNOWN_UPDATABILITY;
+        case 1: return READ_ONLY;
+        case 2: return WRITABLE;
+        default: return null;
+      }
+    }
+
+    public static com.google.protobuf.Internal.EnumLiteMap<ColumnUpdatability>
+        internalGetValueMap() {
+      return internalValueMap;
+    }
+    private static com.google.protobuf.Internal.EnumLiteMap<ColumnUpdatability>
+        internalValueMap =
+          new com.google.protobuf.Internal.EnumLiteMap<ColumnUpdatability>() {
+            public ColumnUpdatability findValueByNumber(int number) {
+              return ColumnUpdatability.valueOf(number);
+            }
+          };
+
+    public final com.google.protobuf.Descriptors.EnumValueDescriptor
+        getValueDescriptor() {
+      return getDescriptor().getValues().get(index);
+    }
+    public final com.google.protobuf.Descriptors.EnumDescriptor
+        getDescriptorForType() {
+      return getDescriptor();
+    }
+    public static final com.google.protobuf.Descriptors.EnumDescriptor
+        getDescriptor() {
+      return org.apache.drill.exec.proto.UserProtos.getDescriptor().getEnumTypes().get(5);
+    }
+
+    private static final ColumnUpdatability[] VALUES = values();
+
+    public static ColumnUpdatability valueOf(
+        com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
+      if (desc.getType() != getDescriptor()) {
+        throw new java.lang.IllegalArgumentException(
+          "EnumValueDescriptor is not for this type.");
+      }
+      return VALUES[desc.getIndex()];
+    }
+
+    private final int index;
+    private final int value;
+
+    private ColumnUpdatability(int index, int value) {
+      this.index = index;
+      this.value = value;
+    }
+
+    // @@protoc_insertion_point(enum_scope:exec.user.ColumnUpdatability)
+  }
+
   public interface PropertyOrBuilder
       extends com.google.protobuf.MessageOrBuilder {
 
@@ -3762,18 +4057,23 @@ public final class UserProtos {
     // @@protoc_insertion_point(class_scope:exec.user.RequestResults)
   }
 
-  public interface RunQueryOrBuilder
+  public interface GetQueryPlanFragmentsOrBuilder
       extends com.google.protobuf.MessageOrBuilder {
 
-    // optional .exec.user.QueryResultsMode results_mode = 1;
+    // required string query = 1;
     /**
-     * <code>optional .exec.user.QueryResultsMode results_mode = 1;</code>
+     * <code>required string query = 1;</code>
      */
-    boolean hasResultsMode();
+    boolean hasQuery();
     /**
-     * <code>optional .exec.user.QueryResultsMode results_mode = 1;</code>
+     * <code>required string query = 1;</code>
      */
-    org.apache.drill.exec.proto.UserProtos.QueryResultsMode getResultsMode();
+    java.lang.String getQuery();
+    /**
+     * <code>required string query = 1;</code>
+     */
+    com.google.protobuf.ByteString
+        getQueryBytes();
 
     // optional .exec.shared.QueryType type = 2;
     /**
@@ -3785,65 +4085,35 @@ public final class UserProtos {
      */
     org.apache.drill.exec.proto.UserBitShared.QueryType getType();
 
-    // optional string plan = 3;
-    /**
-     * <code>optional string plan = 3;</code>
-     */
-    boolean hasPlan();
-    /**
-     * <code>optional string plan = 3;</code>
-     */
-    java.lang.String getPlan();
-    /**
-     * <code>optional string plan = 3;</code>
-     */
-    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();
+    // optional bool split_plan = 3 [default = false];
     /**
-     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     * <code>optional bool split_plan = 3 [default = false];</code>
      */
-    java.util.List<? extends org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> 
-        getFragmentsOrBuilderList();
+    boolean hasSplitPlan();
     /**
-     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     * <code>optional bool split_plan = 3 [default = false];</code>
      */
-    org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder getFragmentsOrBuilder(
-        int index);
+    boolean getSplitPlan();
   }
   /**
-   * Protobuf type {@code exec.user.RunQuery}
+   * Protobuf type {@code exec.user.GetQueryPlanFragments}
    */
-  public static final class RunQuery extends
+  public static final class GetQueryPlanFragments extends
       com.google.protobuf.GeneratedMessage
-      implements RunQueryOrBuilder {
-    // Use RunQuery.newBuilder() to construct.
-    private RunQuery(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 RunQuery(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
+    private GetQueryPlanFragments(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
 
-    private static final RunQuery defaultInstance;
-    public static RunQuery getDefaultInstance() {
+    private static final GetQueryPlanFragments defaultInstance;
+    public static GetQueryPlanFragments getDefaultInstance() {
       return defaultInstance;
     }
 
-    public RunQuery getDefaultInstanceForType() {
+    public GetQueryPlanFragments getDefaultInstanceForType() {
       return defaultInstance;
     }
 
@@ -3853,7 +4123,7 @@ public final class UserProtos {
         getUnknownFields() {
       return this.unknownFields;
     }
-    private RunQuery(
+    private GetQueryPlanFragments(
         com.google.protobuf.CodedInputStream input,
         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
         throws com.google.protobuf.InvalidProtocolBufferException {
@@ -3876,15 +4146,9 @@ public final class UserProtos {
               }
               break;
             }
-            case 8: {
-              int rawValue = input.readEnum();
-              org.apache.drill.exec.proto.UserProtos.QueryResultsMode value = org.apache.drill.exec.proto.UserProtos.QueryResultsMode.valueOf(rawValue);
-              if (value == null) {
-                unknownFields.mergeVarintField(1, rawValue);
-              } else {
-                bitField0_ |= 0x00000001;
-                resultsMode_ = value;
-              }
+            case 10: {
+              bitField0_ |= 0x00000001;
+              query_ = input.readBytes();
               break;
             }
             case 16: {
@@ -3898,17 +4162,9 @@ public final class UserProtos {
               }
               break;
             }
-            case 26: {
+            case 24: {
               bitField0_ |= 0x00000004;
-              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));
+              splitPlan_ = input.readBool();
               break;
             }
           }
@@ -3919,87 +4175,52 @@ 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();
       }
     }
     public static final com.google.protobuf.Descriptors.Descriptor
         getDescriptor() {
-      return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_RunQuery_descriptor;
+      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_RunQuery_fieldAccessorTable
+      return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_GetQueryPlanFragments_fieldAccessorTable
           .ensureFieldAccessorsInitialized(
-              org.apache.drill.exec.proto.UserProtos.RunQuery.class, org.apache.drill.exec.proto.UserProtos.RunQuery.Builder.class);
+              org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.class, org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder.class);
     }
 
-    public static com.google.protobuf.Parser<RunQuery> PARSER =
-        new com.google.protobuf.AbstractParser<RunQuery>() {
-      public RunQuery parsePartialFrom(
+    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 RunQuery(input, extensionRegistry);
+        return new GetQueryPlanFragments(input, extensionRegistry);
       }
     };
 
     @java.lang.Override
-    public com.google.protobuf.Parser<RunQuery> getParserForType() {
+    public com.google.protobuf.Parser<GetQueryPlanFragments> getParserForType() {
       return PARSER;
     }
 
     private int bitField0_;
-    // optional .exec.user.QueryResultsMode results_mode = 1;
-    public static final int RESULTS_MODE_FIELD_NUMBER = 1;
-    private org.apache.drill.exec.proto.UserProtos.QueryResultsMode resultsMode_;
+    // required string query = 1;
+    public static final int QUERY_FIELD_NUMBER = 1;
+    private java.lang.Object query_;
     /**
-     * <code>optional .exec.user.QueryResultsMode results_mode = 1;</code>
+     * <code>required string query = 1;</code>
      */
-    public boolean hasResultsMode() {
+    public boolean hasQuery() {
       return ((bitField0_ & 0x00000001) == 0x00000001);
     }
     /**
-     * <code>optional .exec.user.QueryResultsMode results_mode = 1;</code>
-     */
-    public org.apache.drill.exec.proto.UserProtos.QueryResultsMode getResultsMode() {
-      return resultsMode_;
-    }
-
-    // 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 string plan = 3;
-    public static final int PLAN_FIELD_NUMBER = 3;
-    private java.lang.Object plan_;
-    /**
-     * <code>optional string plan = 3;</code>
-     */
-    public boolean hasPlan() {
-      return ((bitField0_ & 0x00000004) == 0x00000004);
-    }
-    /**
-     * <code>optional string plan = 3;</code>
+     * <code>required string query = 1;</code>
      */
-    public java.lang.String getPlan() {
-      java.lang.Object ref = plan_;
+    public java.lang.String getQuery() {
+      java.lang.Object ref = query_;
       if (ref instanceof java.lang.String) {
         return (java.lang.String) ref;
       } else {
@@ -4007,75 +4228,74 @@ public final class UserProtos {
             (com.google.protobuf.ByteString) ref;
         java.lang.String s = bs.toStringUtf8();
         if (bs.isValidUtf8()) {
-          plan_ = s;
+          query_ = s;
         }
         return s;
       }
     }
     /**
-     * <code>optional string plan = 3;</code>
+     * <code>required string query = 1;</code>
      */
     public com.google.protobuf.ByteString
-        getPlanBytes() {
-      java.lang.Object ref = plan_;
+        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);
-        plan_ = b;
+        query_ = b;
         return b;
       } else {
         return (com.google.protobuf.ByteString) ref;
       }
     }
 
-    // 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_;
-    }
+    // optional .exec.shared.QueryType type = 2;
+    public static final int TYPE_FIELD_NUMBER = 2;
+    private org.apache.drill.exec.proto.UserBitShared.QueryType type_;
     /**
-     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     * <code>optional .exec.shared.QueryType type = 2;</code>
      */
-    public java.util.List<? extends org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder> 
-        getFragmentsOrBuilderList() {
-      return fragments_;
+    public boolean hasType() {
+      return ((bitField0_ & 0x00000002) == 0x00000002);
     }
     /**
-     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     * <code>optional .exec.shared.QueryType type = 2;</code>
      */
-    public int getFragmentsCount() {
-      return fragments_.size();
+    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>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     * <code>optional bool split_plan = 3 [default = false];</code>
      */
-    public org.apache.drill.exec.proto.BitControl.PlanFragment getFragments(int index) {
-      return fragments_.get(index);
+    public boolean hasSplitPlan() {
+      return ((bitField0_ & 0x00000004) == 0x00000004);
     }
     /**
-     * <code>repeated .exec.bit.control.PlanFragment fragments = 4;</code>
+     * <code>optional bool split_plan = 3 [default = false];</code>
      */
-    public org.apache.drill.exec.proto.BitControl.PlanFragmentOrBuilder getFragmentsOrBuilder(
-        int index) {
-      return fragments_.get(index);
+    public boolean getSplitPlan() {
+      return splitPlan_;
     }
 
     private void initFields() {
-      resultsMode_ = org.apache.drill.exec.proto.UserProtos.QueryResultsMode.STREAM_FULL;
+      query_ = "";
       type_ = org.apache.drill.exec.proto.UserBitShared.QueryType.SQL;
-      plan_ = "";
-      fragments_ = java.util.Collections.emptyList();
+      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;
     }
@@ -4084,16 +4304,13 @@ public final class UserProtos {
                         throws java.io.IOException {
       getSerializedSize();
       if (((bitField0_ & 0x00000001) == 0x00000001)) {
-        output.writeEnum(1, resultsMode_.getNumber());
+        output.writeBytes(1, getQueryBytes());
       }
       if (((bitField0_ & 0x00000002) == 0x00000002)) {
         output.writeEnum(2, type_.getNumber());
       }
       if (((bitField0_ & 0x00000004) == 0x00000004)) {
-        output.writeBytes(3, getPlanBytes());
-      }
-      for (int i = 0; i < fragments_.size(); i++) {
-        output.writeMessage(4, fragments_.get(i));
+        output.writeBool(3, splitPlan_);
       }
       getUnknownFields().writeTo(output);
     }
@@ -4106,7 +4323,7 @@ public final class UserProtos {
       size = 0;
       if (((bitField0_ & 0x00000001) == 0x00000001)) {
         size += com.google.protobuf.CodedOutputStream
-          .computeEnumSize(1, resultsMode_.getNumber());
+          .computeBytesSize(1, getQueryBytes());
       }
       if (((bitField0_ & 0x00000002) == 0x00000002)) {
         size += com.google.protobuf.CodedOutputStream
@@ -4114,11 +4331,7 @@ public final class UserProtos {
       }
       if (((bitField0_ & 0x00000004) == 0x00000004)) {
         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));
+          .computeBoolSize(3, splitPlan_);
       }
       size += getUnknownFields().getSerializedSize();
       memoizedSerializedSize = size;
@@ -4132,53 +4345,53 @@ public final class UserProtos {
       return super.writeReplace();
     }
 
-    public static org.apache.drill.exec.proto.UserProtos.RunQuery parseFrom(
+    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.RunQuery parseFrom(
+    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.RunQuery parseFrom(byte[] data)
+    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.RunQuery parseFrom(
+    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.RunQuery parseFrom(java.io.InputStream input)
+    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.RunQuery parseFrom(
+    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.RunQuery parseDelimitedFrom(java.io.InputStream input)
+    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.RunQuery parseDelimitedFrom(
+    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.RunQuery parseFrom(
+    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.RunQuery parseFrom(
+    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseFrom(
         com.google.protobuf.CodedInputStream input,
         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
         throws java.io.IOException {
@@ -4187,7 +4400,7 @@ public final class UserProtos {
 
     public static Builder newBuilder() { return Builder.create(); }
     public Builder newBuilderForType() { return newBuilder(); }
-    public static Builder newBuilder(org.apache.drill.exec.proto.UserProtos.RunQuery prototype) {
+    public static Builder newBuilder(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments prototype) {
       return newBuilder().mergeFrom(prototype);
     }
     public Builder toBuilder() { return newBuilder(this); }
@@ -4199,24 +4412,24 @@ public final class UserProtos {
       return builder;
     }
     /**
-     * Protobuf type {@code exec.user.RunQuery}
+     * 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.RunQueryOrBuilder {
+       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_RunQuery_descriptor;
+        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_RunQuery_fieldAccessorTable
+        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_GetQueryPlanFragments_fieldAccessorTable
             .ensureFieldAccessorsInitialized(
-                org.apache.drill.exec.proto.UserProtos.RunQuery.class, org.apache.drill.exec.proto.UserProtos.RunQuery.Builder.class);
+                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.RunQuery.newBuilder()
+      // Construct using org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.newBuilder()
       private Builder() {
         maybeForceBuilderInitialization();
       }
@@ -4228,7 +4441,6 @@ public final class UserProtos {
       }
       private void maybeForceBuilderInitialization() {
         if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
-          getFragmentsFieldBuilder();
         }
       }
       private static Builder create() {
@@ -4237,18 +4449,12 @@ public final class UserProtos {
 
       public Builder clear() {
         super.clear();
-        resultsMode_ = org.apache.drill.exec.proto.UserProtos.QueryResultsMode.STREAM_FULL;
+        query_ = "";
         bitField0_ = (bitField0_ & ~0x00000001);
         type_ = org.apache.drill.exec.proto.UserBitShared.QueryType.SQL;
         bitField0_ = (bitField0_ & ~0x00000002);
-        plan_ = "";
+        splitPlan_ = false;
         bitField0_ = (bitField0_ & ~0x00000004);
-        if (fragmentsBuilder_ == null) {
-          fragments_ = java.util.Collections.emptyList();
-          bitField0_ = (bitField0_ & ~0x00000008);
-        } else {
-          fragmentsBuilder_.clear();
-        }
         return this;
       }
 
@@ -4258,29 +4464,29 @@ public final class UserProtos {
 
       public com.google.protobuf.Descriptors.Descriptor
           getDescriptorForType() {
-        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_RunQuery_descriptor;
+        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_GetQueryPlanFragments_descriptor;
       }
 
-      public org.apache.drill.exec.proto.UserProtos.RunQuery getDefaultInstanceForType() {
-        return org.apache.drill.exec.proto.UserProtos.RunQuery.getDefaultInstance();
+      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.RunQuery build() {
-        org.apache.drill.exec.proto.UserProtos.RunQuery result = buildPartial();
+      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.RunQuery buildPartial() {
-        org.apache.drill.exec.proto.UserProtos.RunQuery result = new org.apache.drill.exec.proto.UserProtos.RunQuery(this);
+      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.resultsMode_ = resultsMode_;
+        result.query_ = query_;
         if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
           to_bitField0_ |= 0x00000002;
         }
@@ -4288,74 +4494,43 @@ public final class UserProtos {
         if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
           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.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.RunQuery) {
-          return mergeFrom((org.apache.drill.exec.proto.UserProtos.RunQuery)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.RunQuery other) {
-        if (other == org.apache.drill.exec.proto.UserProtos.RunQuery.getDefaultInstance()) return this;
-        if (other.hasResultsMode()) {
-          setResultsMode(other.getResultsMode());
+      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.hasPlan()) {
-          bitField0_ |= 0x00000004;
-          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_);
-            }
-          }
+        if (other.hasSplitPlan()) {
+          setSplitPlan(other.getSplitPlan());
         }
         this.mergeUnknownFields(other.getUnknownFields());
         return this;
       }
 
       public final boolean isInitialized() {
+        if (!hasQuery()) {
+          
+          return false;
+        }
         return true;
       }
 
@@ -4363,11 +4538,11 @@ public final class UserProtos {
           com.google.protobuf.CodedInputStream input,
           com.google.protobuf.ExtensionRegistryLite extensionRegistry)
           throws java.io.IOException {
-        org.apache.drill.exec.proto.UserProtos.RunQuery parsedMessage = null;
+        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.RunQuery) e.getUnfinishedMessage();
+          parsedMessage = (org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments) e.getUnfinishedMessage();
           throw e;
         } finally {
           if (parsedMessage != null) {
@@ -4378,38 +4553,76 @@ public final class UserProtos {
       }
       private int bitField0_;
 
-      // optional .exec.user.QueryResultsMode results_mode = 1;
-      private org.apache.drill.exec.proto.UserProtos.QueryResultsMode resultsMode_ = org.apache.drill.exec.proto.UserProtos.QueryResultsMode.STREAM_FULL;
+      // required string query = 1;
+      private java.lang.Object query_ = "";
       /**
-       * <code>optional .exec.user.QueryResultsMode results_mode = 1;</code>
+       * <code>required string query = 1;</code>
        */
-      public boolean hasResultsMode() {
+      public boolean hasQuery() {
         return ((bitField0_ & 0x00000001) == 0x00000001);
       }
       /**
-       * <code>optional .exec.user.QueryResultsMode results_mode = 1;</code>
+       * <code>required string query = 1;</code>
        */
-      public org.apache.drill.exec.proto.UserProtos.QueryResultsMode getResultsMode() {
-        return resultsMode_;
+      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>optional .exec.user.QueryResultsMode results_mode = 1;</code>
+       * <code>required string query = 1;</code>
        */
-      public Builder setResultsMode(org.apache.drill.exec.proto.UserProtos.QueryResultsMode value) {
-        if (value == null) {
-          throw new NullPointerException();
+      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;
         }
-        bitField0_ |= 0x00000001;
-        resultsMode_ = value;
+      }
+      /**
+       * <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>optional .exec.user.QueryResultsMode results_mode = 1;</code>
+       * <code>required string query = 1;</code>
        */
-      public Builder clearResultsMode() {
+      public Builder clearQuery() {
         bitField0_ = (bitField0_ & ~0x00000001);
-        resultsMode_ = org.apache.drill.exec.proto.UserProtos.QueryResultsMode.STREAM_FULL;
+        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;
       }
@@ -4450,388 +4663,135 @@ public final class UserProtos {
         return this;
       }
 
-      // optional string plan = 3;
-      private java.lang.Object plan_ = "";
+      // optional bool split_plan = 3 [default = false];
+      private boolean splitPlan_ ;
       /**
-       * <code>optional string plan = 3;</code>
+       * <code>optional bool split_plan = 3 [default = false];</code>
        */
-      public boolean hasPlan() {
+      public boolean hasSplitPlan() {
         return ((bitField0_ & 0x00000004) == 0x00000004);
       }
       /**
-       * <code>optional string plan = 3;</code>
-       */
-      public java.lang.String getPlan() {
-        java.lang.Object ref = plan_;
-        if (!(ref instanceof java.lang.String)) {
-          java.lang.String s = ((com.google.protobuf.ByteString) ref)
-              .toStringUtf8();
-          plan_ = s;
-          return s;
-        } else {
-          return (java.lang.String) ref;
-        }
-      }
-      /**
-       * <code>optional string plan = 3;</code>
+       * <code>optional bool split_plan = 3 [default = false];</code>
        */
-      public com.google.protobuf.ByteString
-          getPlanBytes() {
-        java.lang.Object ref = plan_;
-        if (ref instanceof String) {
-          com.google.protobuf.ByteString b = 
-              com.google.protobuf.ByteString.copyFromUtf8(
-                  (java.lang.String) ref);
-          plan_ = b;
-          return b;
-        } else {
-          return (com.google.protobuf.ByteString) ref;
-        }
+      public boolean getSplitPlan() {
+        return splitPlan_;
       }
       /**
-       * <code>optional string plan = 3;</code>
+       * <code>optional bool split_plan = 3 [default = false];</code>
        */
-      public Builder setPlan(
-          java.lang.String value) {
-        if (value == null) {
-    throw new NullPointerException();
-  }
-  bitField0_ |= 0x00000004;
-        plan_ = value;
+      public Builder setSplitPlan(boolean value) {
+        bitField0_ |= 0x00000004;
+        splitPlan_ = value;
         onChanged();
         return this;
       }
       /**
-       * <code>optional string plan = 3;</code>
+       * <code>optional bool split_plan = 3 [default = false];</code>
        */
-      public Builder clearPlan() {
+      public Builder clearSplitPlan() {
         bitField0_ = (bitField0_ & ~0x00000004);
-        plan_ = getDefaultInstance().getPlan();
+        splitPlan_ = false;
         onChanged();
         return this;
       }
-      /**
-       * <code>optional string plan = 3;</code>
-       */
-      public Builder setPlanBytes(
-          com.google.protobuf.ByteString value) {
-        if (value == null) {
-    throw new NullPointerException();
+
+      // @@protoc_insertion_point(builder_scope:exec.user.GetQueryPlanFragments)
+    }
+
+    static {
+      defaultInstance = new GetQueryPlanFragments(true);
+      defaultInstance.initFields();
+    }
+
+    // @@protoc_insertion_point(class_scope:exec.user.GetQueryPlanFragments)
   }
-  bitField0_ |= 0x00000004;
-        plan_ = value;
-        onChanged();
-        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;
-         }
-      }
+  public interface QueryPlanFragmentsOrBuilder
+      extends com.google.protobuf.MessageOrBuilder {
 
-      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_;
+    // 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();
 
-      /**
-       * <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)
-    }
-
-    static {
-      defaultInstance = new RunQuery(true);
-      defaultInstance.initFields();
-    }
-
-    // @@protoc_insertion_point(class_scope:exec.user.RunQuery)
-  }
-
-  public interface GetQueryPlanFragmentsOrBuilder
-      extends com.google.protobuf.MessageOrBuilder {
-
-    // required string query = 1;
+    // optional .exec.shared.QueryId query_id = 2;
     /**
-     * <code>required string query = 1;</code>
+     * <code>optional .exec.shared.QueryId query_id = 2;</code>
      */
-    boolean hasQuery();
+    boolean hasQueryId();
     /**
-     * <code>required string query = 1;</code>
+     * <code>optional .exec.shared.QueryId query_id = 2;</code>
      */
-    java.lang.String getQuery();
+    org.apache.drill.exec.proto.UserBitShared.QueryId getQueryId();
     /**
-     * <code>required string query = 1;</code>
+     * <code>optional .exec.shared.QueryId query_id = 2;</code>
      */
-    com.google.protobuf.ByteString
-        getQueryBytes();
+    org.apache.drill.exec.proto.UserBitShared.QueryIdOrBuilder getQueryIdOrBuilder();
 
-    // optional .exec.shared.QueryType type = 2;
+    // repeated .exec.bit.control.PlanFragment fragments = 3;
     /**
-     * <code>optional .exec.shared.QueryType type = 2;</code>
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
      */
-    boolean hasType();
+    java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> 
+        getFragmentsList();
     /**
-     * <code>optional .exec.shared.QueryType type = 2;</code>
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
      */
-    org.apache.drill.exec.proto.UserBitShared.QueryType getType();
-
-    // optional bool split_plan = 3 [default = false];
+    org.apache.drill.exec.proto.BitControl.PlanFragment getFragments(int index);
     /**
-     * <code>optional bool split_plan = 3 [default = false];</code>
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
      */
-    boolean hasSplitPlan();
+    int getFragmentsCount();
     /**
-     * <code>optional bool split_plan = 3 [default = false];</code>
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
      */
-    boolean getSplitPlan();
-  }
-  /**
-   * Protobuf type {@code exec.user.GetQueryPlanFragments}
-   */
-  public static final class GetQueryPlanFragments extends
-      com.google.protobuf.GeneratedMessage
-      implements GetQueryPlanFragmentsOrBuilder {
-    // Use GetQueryPlanFragments.newBuilder() to construct.
-    private GetQueryPlanFragments(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
-      super(builder);
-      this.unknownFields = builder.getUnknownFields();
-    }
-    private GetQueryPlanFragments(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
+    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);
 
-    private static final GetQueryPlanFragments defaultInstance;
-    public static GetQueryPlanFragments getDefaultInstance() {
+    // 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 GetQueryPlanFragments getDefaultInstanceForType() {
+    public QueryPlanFragments getDefaultInstanceForType() {
       return defaultInstance;
     }
 
@@ -4841,7 +4801,7 @@ public final class UserProtos {
         getUnknownFields() {
       return this.unknownFields;
     }
-    private GetQueryPlanFragments(
+    private QueryPlanFragments(
         com.google.protobuf.CodedInputStream input,
         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
         throws com.google.protobuf.InvalidProtocolBufferException {
@@ -4864,25 +4824,49 @@ public final class UserProtos {
               }
               break;
             }
-            case 10: {
-              bitField0_ |= 0x00000001;
-              query_ = input.readBytes();
-              break;
-            }
-            case 16: {
+            case 8: {
               int rawValue = input.readEnum();
-              org.apache.drill.exec.proto.UserBitShared.QueryType value = org.apache.drill.exec.proto.UserBitShared.QueryType.valueOf(rawValue);
+              org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState value = org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState.valueOf(rawValue);
               if (value == null) {
-                unknownFields.mergeVarintField(2, rawValue);
+                unknownFields.mergeVarintField(1, rawValue);
               } else {
-                bitField0_ |= 0x00000002;
-                type_ = value;
+                bitField0_ |= 0x00000001;
+                status_ = value;
               }
               break;
             }
-            case 24: {
+            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;
-              splitPlan_ = input.readBool();
               break;
             }
           }
@@ -4893,124 +4877,149 @@ public final class UserProtos {
         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_GetQueryPlanFragments_descriptor;
+      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_GetQueryPlanFragments_fieldAccessorTable
+      return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_QueryPlanFragments_fieldAccessorTable
           .ensureFieldAccessorsInitialized(
-              org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.class, org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder.class);
+              org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.class, org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.Builder.class);
     }
 
-    public static com.google.protobuf.Parser<GetQueryPlanFragments> PARSER =
-        new com.google.protobuf.AbstractParser<GetQueryPlanFragments>() {
-      public GetQueryPlanFragments parsePartialFrom(
+    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 GetQueryPlanFragments(input, extensionRegistry);
+        return new QueryPlanFragments(input, extensionRegistry);
       }
     };
 
     @java.lang.Override
-    public com.google.protobuf.Parser<GetQueryPlanFragments> getParserForType() {
+    public com.google.protobuf.Parser<QueryPlanFragments> getParserForType() {
       return PARSER;
     }
 
     private int bitField0_;
-    // required string query = 1;
-    public static final int QUERY_FIELD_NUMBER = 1;
-    private java.lang.Object query_;
+    // 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 string query = 1;</code>
+     * <code>required .exec.shared.QueryResult.QueryState status = 1;</code>
      */
-    public boolean hasQuery() {
+    public boolean hasStatus() {
       return ((bitField0_ & 0x00000001) == 0x00000001);
     }
     /**
-     * <code>required string query = 1;</code>
+     * <code>required .exec.shared.QueryResult.QueryState status = 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;
-      }
+    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>required string query = 1;</code>
+     * <code>optional .exec.shared.QueryId query_id = 2;</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;
-      }
+    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_;
     }
 
-    // optional .exec.shared.QueryType type = 2;
-    public static final int TYPE_FIELD_NUMBER = 2;
-    private org.apache.drill.exec.proto.UserBitShared.QueryType type_;
+    // 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>optional .exec.shared.QueryType type = 2;</code>
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
      */
-    public boolean hasType() {
-      return ((bitField0_ & 0x00000002) == 0x00000002);
+    public java.util.List<org.apache.drill.exec.proto.BitControl.PlanFragment> getFragmentsList() {
+      return fragments_;
     }
     /**
-     * <code>optional .exec.shared.QueryType type = 2;</code>
+     * <code>repeated .exec.bit.control.PlanFragment fragments = 3;</code>
      */
-    public org.apache.drill.exec.proto.UserBitShared.QueryType getType() {
-      return type_;
+    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 bool split_plan = 3 [default = false];
-    public static final int SPLIT_PLAN_FIELD_NUMBER = 3;
-    private boolean splitPlan_;
+    // 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 bool split_plan = 3 [default = false];</code>
+     * <code>optional .exec.shared.DrillPBError error = 4;</code>
      */
-    public boolean hasSplitPlan() {
+    public boolean hasError() {
       return ((bitField0_ & 0x00000004) == 0x00000004);
     }
     /**
-     * <code>optional bool split_plan = 3 [default = false];</code>
+     * <code>optional .exec.shared.DrillPBError error = 4;</code>
      */
-    public boolean getSplitPlan() {
-      return splitPlan_;
+    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() {
-      query_ = "";
-      type_ = org.apache.drill.exec.proto.UserBitShared.QueryType.SQL;
-      splitPlan_ = false;
+      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 (!hasQuery()) {
+      if (!hasStatus()) {
         memoizedIsInitialized = 0;
         return false;
       }
@@ -5022,13 +5031,16 @@ public final class UserProtos {
                         throws java.io.IOException {
       getSerializedSize();
       if (((bitField0_ & 0x00000001) == 0x00000001)) {
-        output.writeBytes(1, getQueryBytes());
+        output.writeEnum(1, status_.getNumber());
       }
       if (((bitField0_ & 0x00000002) == 0x00000002)) {
-        output.writeEnum(2, type_.getNumber());
+        output.writeMessage(2, queryId_);
+      }
+      for (int i = 0; i < fragments_.size(); i++) {
+        output.writeMessage(3, fragments_.get(i));
       }
       if (((bitField0_ & 0x00000004) == 0x00000004)) {
-        output.writeBool(3, splitPlan_);
+        output.writeMessage(4, error_);
       }
       getUnknownFields().writeTo(output);
     }
@@ -5041,17 +5053,21 @@ public final class UserProtos {
       size = 0;
       if (((bitField0_ & 0x00000001) == 0x00000001)) {
         size += com.google.protobuf.CodedOutputStream
-          .computeBytesSize(1, getQueryBytes());
+          .computeEnumSize(1, status_.getNumber());
       }
       if (((bitField0_ & 0x00000002) == 0x00000002)) {
         size += com.google.protobuf.CodedOutputStream
-          .computeEnumSize(2, type_.getNumber());
+          .computeMessageSize(2, queryId_);
       }
-      if (((bitField0_ & 0x00000004) == 0x00000004)) {
+      for (int i = 0; i < fragments_.size(); i++) {
         size += com.google.protobuf.CodedOutputStream
-          .computeBoolSize(3, splitPlan_);
+          .computeMessageSize(3, fragments_.get(i));
       }
-      size += getUnknownFields().getSerializedSize();
+      if (((bitField0_ & 0x00000004) == 0x00000004)) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeMessageSize(4, error_);
+      }
+      size += getUnknownFields().getSerializedSize();
       memoizedSerializedSize = size;
       return size;
     }
@@ -5063,53 +5079,53 @@ public final class UserProtos {
       return super.writeReplace();
     }
 
-    public static org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments parseFrom(
+    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.GetQueryPlanFragments parseFrom(
+    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.GetQueryPlanFragments parseFrom(byte[] data)
+    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.GetQueryPlanFragments parseFrom(
+    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.GetQueryPlanFragments parseFrom(java.io.InputStream input)
+    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.GetQueryPlanFragments parseFrom(
+    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.GetQueryPlanFragments parseDelimitedFrom(java.io.InputStream input)
+    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.GetQueryPlanFragments parseDelimitedFrom(
+    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.GetQueryPlanFragments parseFrom(
+    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.GetQueryPlanFragments parseFrom(
+    public static org.apache.drill.exec.proto.UserProtos.QueryPlanFragments parseFrom(
         com.google.protobuf.CodedInputStream input,
         com.google.protobuf.ExtensionRegistryLite extensionRegistry)
         throws java.io.IOException {
@@ -5118,7 +5134,7 @@ public final class UserProtos {
 
     public static Builder newBuilder() { return Builder.create(); }
     public Builder newBuilderForType() { return newBuilder(); }
-    public static Builder newBuilder(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments prototype) {
+    public static Builder newBuilder(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments prototype) {
       return newBuilder().mergeFrom(prototype);
     }
     public Builder toBuilder() { return newBuilder(this); }
@@ -5130,24 +5146,24 @@ public final class UserProtos {
       return builder;
     }
     /**
-     * Protobuf type {@code exec.user.GetQueryPlanFragments}
+     * 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.GetQueryPlanFragmentsOrBuilder {
+       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_GetQueryPlanFragments_descriptor;
+        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_GetQueryPlanFragments_fieldAccessorTable
+        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_QueryPlanFragments_fieldAccessorTable
             .ensureFieldAccessorsInitialized(
-                org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.class, org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.Builder.class);
+                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.GetQueryPlanFragments.newBuilder()
+      // Construct using org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.newBuilder()
       private Builder() {
         maybeForceBuilderInitialization();
       }
@@ -5159,6 +5175,9 @@ public final class UserProtos {
       }
       private void maybeForceBuilderInitialization() {
         if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+          getQueryIdFieldBuilder();
+          getFragmentsFieldBuilder();
+          getErrorFieldBuilder();
         }
       }
       private static Builder create() {
@@ -5167,12 +5186,26 @@ public final class UserProtos {
 
       public Builder clear() {
         super.clear();
-        query_ = "";
+        status_ = org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState.STARTING;
         bitField0_ = (bitField0_ & ~0x00000001);
-        type_ = org.apache.drill.exec.proto.UserBitShared.QueryType.SQL;
+        if (queryIdBuilder_ == null) {
+          queryId_ = org.apache.drill.exec.proto.UserBitShared.QueryId.getDefaultInstance();
+        } else {
+          queryIdBuilder_.clear();
+        }
         bitField0_ = (bitField0_ & ~0x00000002);
-        splitPlan_ = false;
-        bitField0_ = (bitField0_ & ~0x00000004);
+        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;
       }
 
@@ -5182,70 +5215,111 @@ public final class UserProtos {
 
       public com.google.protobuf.Descriptors.Descriptor
           getDescriptorForType() {
-        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_GetQueryPlanFragments_descriptor;
+        return org.apache.drill.exec.proto.UserProtos.internal_static_exec_user_QueryPlanFragments_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.QueryPlanFragments getDefaultInstanceForType() {
+        return org.apache.drill.exec.proto.UserProtos.QueryPlanFragments.getDefaultInstance();
       }
 
-      public org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments build() {
-        org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments result = buildPartial();
+      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.GetQueryPlanFragments buildPartial() {
-        org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments result = new org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments(this);
+      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.query_ = query_;
+        result.status_ = status_;
         if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
           to_bitField0_ |= 0x00000002;
         }
-        result.type_ = type_;
-        if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
+        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;
         }
-        result.splitPlan_ = splitPlan_;
+        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.GetQueryPlanFragments) {
-          return mergeFrom((org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments)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.GetQueryPlanFragments other) {
-        if (other == org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments.getDefaultInstance()) return this;
-        if (other.hasQuery()) {
-          bitField0_ |= 0x00000001;
-          query_ = other.query_;
-

<TRUNCATED>