Reverting the merge of asterix_stabilization_result_distribution until the tests in the corresponding hyracks branch pass.

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization@1282 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
index 4062392..1eb37cd 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/common/APIFramework.java
@@ -146,8 +146,7 @@
 
     public enum DisplayFormat {
         TEXT,
-        HTML,
-        JSON
+        HTML
     }
 
     public static Pair<Query, Integer> reWriteQuery(List<FunctionDecl> declaredFunctions,
@@ -321,7 +320,7 @@
         if (!pc.isGenerateJobSpec()) {
             return null;
         }
-
+        
         AlgebricksPartitionConstraint clusterLocs = queryMetadataProvider.getClusterLocations();
         builder.setBinaryBooleanInspectorFactory(format.getBinaryBooleanInspectorFactory());
         builder.setBinaryIntegerInspectorFactory(format.getBinaryIntegerInspectorFactory());
@@ -332,16 +331,7 @@
         builder.setHashFunctionFactoryProvider(format.getBinaryHashFunctionFactoryProvider());
         builder.setHashFunctionFamilyProvider(format.getBinaryHashFunctionFamilyProvider());
         builder.setNullWriterFactory(format.getNullWriterFactory());
-
-        switch (pdf) {
-            case JSON:
-                builder.setPrinterProvider(format.getJSONPrinterFactoryProvider());
-                break;
-            default:
-                builder.setPrinterProvider(format.getPrinterFactoryProvider());
-                break;
-        }
-
+        builder.setPrinterProvider(format.getPrinterFactoryProvider());
         builder.setSerializerDeserializerProvider(format.getSerdeProvider());
         builder.setTypeTraitProvider(format.getTypeTraitProvider());
         builder.setNormalizedKeyComputerFactoryProvider(format.getNormalizedKeyComputerFactoryProvider());
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
index 2122ada..034e1f4 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
@@ -18,6 +18,7 @@
 import edu.uci.ics.asterix.aql.parser.AQLParser;
 import edu.uci.ics.asterix.aql.parser.ParseException;
 import edu.uci.ics.asterix.aql.translator.AqlTranslator;
+import edu.uci.ics.asterix.aql.translator.QueryResult;
 import edu.uci.ics.asterix.metadata.MetadataManager;
 import edu.uci.ics.hyracks.api.client.HyracksConnection;
 import edu.uci.ics.hyracks.api.client.IHyracksClientConnection;
@@ -27,292 +28,8 @@
 
     private static final String HYRACKS_CONNECTION_ATTR = "edu.uci.ics.asterix.HYRACKS_CONNECTION";
 
-    private static final String HTML_HEADER_TEMPLATE = "<!DOCTYPE html>"
-            + "<html lang=\"en\">"
-            + "<head>"
-            + "<meta name=\"description\" content=\"ASTERIX WEB PAGE\" />"
-            + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"
-            + "<link href='http://fonts.googleapis.com/css?family=Bitter|PT+Sans+Caption|Open+Sans' rel='stylesheet' type='text/css'>"
-            + "<script src=\"http://code.jquery.com/jquery.min.js\"></script>"
-            + "<script src=\"http://www.jacklmoore.com/autosize/jquery.autosize.js\"></script>"
-            + "  "
-            + "<link href=\"http://twitter.github.com/bootstrap/assets/css/bootstrap.css\" rel=\"stylesheet\" type=\"text/css\" />"
-            + "<link href=\"http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css\" rel=\"stylesheet\">"
-            + ""
-            + "  "
-            + "<script src=\"http://twitter.github.com/bootstrap/assets/js/bootstrap.js\"></script>"
-            + ""
-            + "<script type=\"text/javascript\">"
-            + "$(document).ready(function(){"
-            + "   $('textarea').autosize();"
-            + "});"
-            + "</script>"
-            + ""
-            + "<meta charset=utf-8 />"
-            + "<title>ASTERIX Demo</title>"
-            + "<style id=\"jsbin-css\">"
-            + "body {"
-            + "    background: none repeat scroll 0 0 white;"
-            + "    color: #222222;"
-            + "    font-family: 'Bitter';"
-            + "    font-size: 14px;"
-            + "    line-height: 17px;"
-            + "    width: 100%;"
-            + "}"
-            + ""
-            + ".content {"
-            + "    margin-top: 70px;"
-            + "}"
-            + ""
-            + "label.query, label.result {"
-            + "    font-size: 24px;"
-            + "    padding-bottom: 10px;"
-            + "    font-weight: bold;"
-            + "}"
-            + ""
-            + "div.host {"
-            + "    float: left;"
-            + "    margin: 0 100px 0 10px;"
-            + "}"
-            + ""
-            + "div.port {"
-            + "}"
-            + ""
-            + "div.left {"
-            + "    float: left;"
-            + "    width: 320px;"
-            + "    padding: 0 20px 0 10px;"
-            + "}"
-            + ""
-            + "div.right {"
-            + "}"
-            + ""
-            + "button.btn {"
-            + "    clear: both;"
-            + "    float: left;"
-            + "    margin: 20px 0 0 10px;;"
-            + "}"
-            + ""
-            + "textarea.query {"
-            + "    -webkit-box-sizing: border-box;"
-            + "    -moz-box-sizing: border-box;"
-            + "    -ms-box-sizing: border-box;"
-            + "    box-sizing: border-box;"
-            + "    font-size: 16px;"
-            + "    line-height: 20px;"
-            + "    font-family: bitter, helvetica;"
-            + "    width: 100%;"
-            + "    padding: 10px;"
-            + "    color: #999;"
-            + "    resize: none;"
-            + "    border: 10px solid #eee;"
-            + "}"
-            + ""
-            + "textarea.query:focus {"
-            + "    outline: none;"
-            + "    color: #333;"
-            + "}"
-            + ""
-            + "label {"
-            + "    padding-top: 10px;"
-            + "}"
-            + ""
-            + "input[type=text] {"
-            + "    height: 20px;"
-            + "}"
-            + ""
-            + ""
-            + "div.output label.heading {"
-            + "    font-size: 24px;"
-            + "    margin-top: 2px;"
-            + "    padding-bottom: 10px;"
-            + "    font-weight: bold;"
-            + "}"
-            + ""
-            + "div.output .message {"
-            + "    -webkit-box-sizing: border-box;"
-            + "    -moz-box-sizing: border-box;"
-            + "    -ms-box-sizing: border-box;"
-            + "    box-sizing: border-box;"
-            + "    -webkit-border-radius: 4px 4px 4px 4px;"
-            + "    -moz-border-radius: 4px 4px 4px 4px;"
-            + "    -ms-border-radius: 4px 4px 4px 4px;"
-            + "    border-radius: 4px 4px 4px 4px;"
-            + "    color: #000;"
-            + "    resize: none;"
-            + "    border: 1px solid #eee;"
-            + "}"
-            + ""
-            + "div.error label.heading {"
-            + "    color: #ff2020;"
-            + "    font-size: 24px;"
-            + "    margin-top: 2px;"
-            + "    padding-bottom: 10px;"
-            + "    font-weight: bold;"
-            + "}"
-            + ""
-            + "div.error .message {"
-            + "    -webkit-box-sizing: border-box;"
-            + "    -moz-box-sizing: border-box;"
-            + "    -ms-box-sizing: border-box;"
-            + "    box-sizing: border-box;"
-            + "    border-color: rgba(82, 168, 236, 0.8);"
-            + "    outline: 0;"
-            + "    outline: thin dotted 9;"
-            + ""
-            + "    -webkit-box-shadow: inset 0 1px 1px rgba(250, 0, 0, 0.075), 0 0 8px rgba(255, 0, 0, 0.8);"
-            + "    -moz-box-shadow: inset 0 1px 1px rgba(250, 0, 0, 0.075), 0 0 8px rgba(255, 0, 0, 1.0);"
-            + "    box-shadow: inset 0 1px 1px rgba(250, 0, 0, 0.075), 0 0 8px rgba(255, 0, 0, 1.0);"
-            + "    color: #000;"
-            + "    resize: none;"
-            + "    border: 1px solid #eee;"
-            + "    margin-top: 7px;"
-            + "    padding: 20px 20px 20px 20px;"
-            + "}"
-            + ""
-            + ".footer {"
-            + "   margin-top: 40px;"
-            + "}"
-            + ""
-            + ".footer .line {"
-            + "    border-top: 1px solid #EEEEEE;"
-            + "    bottom: 20px;"
-            + "    height: 10px;"
-            + "    left: 0;"
-            + "    position: fixed;"
-            + "    width: 100%;"
-            + "}"
-            + ""
-            + ".footer .content {"
-            + "    background: none repeat scroll 0 0 #FFFFFF;"
-            + "    bottom: 0;"
-            + "    color: #666666;"
-            + "    font-size: 12px;"
-            + "    height: 25px;"
-            + "    left: 0;"
-            + "    padding-top: 5px;"
-            + "    position: fixed;"
-            + "    width: 100%;"
-            + "}"
-            + ""
-            + ".footer .content .left {"
-            + "    padding-left: 20px;"
-            + "    float: left;"
-            + "}"
-            + ""
-            + ".footer .content .right {"
-            + "    padding-right: 20px;"
-            + "    float: right;"
-            + "}</style></head>"
-            + "<body>"
-            + "  <div class=\"navbar navbar-inverse navbar-fixed-top\">"
-            + "    <div class=\"navbar-inner\">"
-            + "      <div class=\"container\">"
-            + "        <a class=\"btn btn-navbar\" data-toggle=\"collapse\" data-target=\".nav-collapse\">"
-            + "          <span class=\"icon-bar\"></span>"
-            + "          <span class=\"icon-bar\"></span>"
-            + "          <span class=\"icon-bar\"></span>"
-            + "        </a>"
-            + "        <a class=\"brand\" href=\"#\">ASTERIX</a>"
-            + "        <div class=\"nav-collapse collapse\">"
-            + "          <ul class=\"nav\">"
-            + "            <li><a href=\"#\">Open source</a></li>"
-            + "            <li><a href=\"#about\">File issues</a></li>"
-            + "            <li><a href=\"#contact\">Contact</a></li>"
-            + "          </ul>"
-            + "        </div><!--/.nav-collapse -->"
-            + "      </div>"
-            + "    </div>"
-            + "  </div>"
-            + "";
-    private static final String HTML_FORM_CONTENT_TEMPLATE = "  <div class=\"content\">"
-            + "    <div class=\"container\">"
-            + "      <div class=\"row-fluid\">"
-            + "        <div class=\"span6\">"
-            + "          <form class=\"form-horizontal\" method=\"post\">"
-            + "            <div>"
-            + "              <label class=\"query\">Query</label>"
-            + "              <textarea rows=\"20\" name=\"query\" class=\"query\" value=\"%s\" placeholder=\"Type your AQL query ...\"></textarea>"
-            + "            </div>"
-            + "            <div>"
-            + "              <div class=\"host\">"
-            + "                <label>Host</label><input type=\"text\" name=\"hyracks-ip\" placeholder=\"IP Address or hostname\"/>"
-            + "              </div>"
-            + "              <div class=\"port\">"
-            + "                <label>Port</label><input type=\"text\" name=\"hyracks-port\" placeholder=\"Port number\"/>"
-            + "              </div>"
-            + "            </div>"
-            + "            <div>"
-            + "              <div class=\"left\">"
-            + "                <label class=\"checkbox\"><input type=\"checkbox\" name=\"print-expr-tree\" value=\"true\" /> Print parsed expressions</label>"
-            + "              </div>"
-            + "              <div class=\"right\">"
-            + "                <label class=\"checkbox\"><input type=\"checkbox\" name=\"print-rewritten-expr-tree\" value=\"true\" /> Print rewritten expressions</label>"
-            + "              </div>"
-            + "            </div>"
-            + "            <div>"
-            + "              <div class=\"left\">"
-            + "                <label class=\"checkbox\"><input type=\"checkbox\" name=\"print-logical-plan\" value=\"true\" /> Print logical plan</label>"
-            + "              </div>"
-            + "              <div class=\"right\">"
-            + "                <label class=\"checkbox\"><input type=\"checkbox\" name=\"print-optimized-logical-plan\" value=\"true\" /> Print optimized logical plan</label>"
-            + "              </div>"
-            + "            </div>"
-            + "            <div>"
-            + "              <div class=\"left\">"
-            + "                <label class=\"checkbox\"><input type=\"checkbox\" name=\"print-job\" value=\"true\" /> Print hyracks job</label>"
-            + "              </div>"
-            + "              <div class=\"right\">"
-            + "                <label class=\"checkbox\"><input type=\"checkbox\" name=\"display-result\" value=\"true\" /> Display error/results</label>"
-            + "              </div>"
-            + "            </div>"
-            + "            <button type=\"submit\" class=\"btn btn-danger\">Execute</button>"
-            + "          </form>"
-            + "        </div>";
-
-    private static final String HTML_EMPTY_OUTPUT_TEMPLATE = "        <div class=\"span6\">"
-            + "          <div class=\"output\">"
-            + "            <label class=\"heading\">Output</label>"
-            + "            <div class=\"message\">"
-            + "            </div>"
-            + "          </div>"
-            + "        </div>";
-
-    private static final String HTML_OUTPUT_TEMPLATE = "<div class=\"span6\">"
-            + "  <div class=\"output\">"
-            + "    <label class=\"heading\">Output</label>"
-            + "    <table class=\"table table-bordered table-striped\">"
-            + "      %s"
-            + "    </table>"
-            + "  </div>"
-            + "</div>";
-
-    private static final String HTML_FOOTER_TEMPLATE = "      </div>"
-            + "    </div>"
-            + "  </div>"
-            + "  <div class=\"footer\">"
-            + "    <section class=\"line\"><hr></section>"
-            + "    <section class=\"content\">"
-            + "      <section class=\"left\">"
-            + "        Developed by ASTERIX group"
-            + "      </section>"
-            + "      <section class=\"right\">"
-            + "        &copy; Copyright 2012 University of California, Irvine"
-            + "      </section>"
-            + "    </section>"
-            + "  </div>"
-            + "</body>"
-            + "</html>";
-
     @Override
     public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
-        DisplayFormat format = DisplayFormat.HTML;
-        if (request.getContentType().equals("application/json")) {
-            format = DisplayFormat.JSON;
-        } else if (request.getContentType().equals("text/plain")) {
-            format = DisplayFormat.TEXT;
-        }
-
         String query = request.getParameter("query");
         String printExprParam = request.getParameter("print-expr-tree");
         String printRewrittenExprParam = request.getParameter("print-rewritten-expr-tree");
@@ -343,13 +60,34 @@
                     isSet(printRewrittenExprParam), isSet(printLogicalPlanParam),
                     isSet(printOptimizedLogicalPlanParam), false, true, isSet(printJob));
             MetadataManager.INSTANCE.init();
-            AqlTranslator aqlTranslator = new AqlTranslator(aqlStatements, out, sessionConfig, format);
+            AqlTranslator aqlTranslator = new AqlTranslator(aqlStatements, out, sessionConfig, DisplayFormat.HTML);
+            List<QueryResult> executionResults = null;
             double duration = 0;
             long startTime = System.currentTimeMillis();
-            aqlTranslator.compileAndExecute(hcc, false);
+            executionResults = aqlTranslator.compileAndExecute(hcc);
             long endTime = System.currentTimeMillis();
             duration = (endTime - startTime) / 1000.00;
             out.println("<PRE>Duration of all jobs: " + duration + "</PRE>");
+
+            int queryCount = 1;
+            out.println("<H1>Result:</H1>");
+            out.println("<PRE>");
+            for (QueryResult result : executionResults) {
+                out.println("Query:" + queryCount++ + ":" + " " + result.getResultPath());
+            }
+            out.println("Duration: " + duration);
+            out.println("</PRE>");
+
+            queryCount = 1;
+            if (isSet(strDisplayResult)) {
+                out.println("<PRE>");
+                for (QueryResult result : executionResults) {
+                    out.println("Query:" + queryCount++ + ":" + " " + result.getResultPath());
+                    displayFile(new File(result.getResultPath()), out);
+                    out.println();
+                }
+                out.println("</PRE>");
+            }
         } catch (ParseException pe) {
             String message = pe.getMessage();
             message = message.replace("<", "&lt");
@@ -372,8 +110,21 @@
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
         PrintWriter out = response.getWriter();
         response.setContentType("text/html");
-        final String form = HTML_HEADER_TEMPLATE + String.format(HTML_FORM_CONTENT_TEMPLATE, "")
-                + HTML_EMPTY_OUTPUT_TEMPLATE + HTML_FOOTER_TEMPLATE;
+        final String form = "<form method=\"post\">"
+                + "<center><textarea cols=\"80\" rows=\"25\" name=\"query\" ></textarea><br/>"
+                + "IP Address: <input type = \"text\" name = \"hyracks-ip\" size=\"15\" maxlength=\"35\" value=\"localhost\" /><br/>"
+                + "Port: <input type = \"text\" name = \"hyracks-port\" size=\"5\" maxlength=\"5\" value=\"1098\" /><br/>"
+                + "<input type = \"checkbox\" name = \"print-expr-tree\" value=\"true\" />print parsed expressions<P>"
+                + "<input type = \"checkbox\" name = \"print-rewritten-expr-tree\" value=\"true\" />print rewritten expressions<P>"
+                + "<input type = \"checkbox\" name = \"print-logical-plan\" value=\"true\" checked/>print logical plan<P>"
+                + "<input type = \"checkbox\" name = \"print-optimized-logical-plan\" value=\"true\" checked/>print optimized logical plan<P>"
+                + "<input type = \"checkbox\" name = \"print-job\" value=\"true\" checked/>print Hyracks job<P>"
+                + "<input type = \"checkbox\" name = \"display-result\" value=\"true\" checked/>display NFS file<P>"
+                // +
+                // "<input type = \"checkbox\" name = \"serialize-as-xml\" value=\"true\">serialize as XML<P>"
+                // +
+                // "<input type = \"checkbox\" name = \"show-tuples\" value=\"true\">show the entire tuples<P>"
+                + "<input type=\"submit\"/>" + "</center>" + "</form>";
         out.println(form);
     }
 
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/DDLAPIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/DDLAPIServlet.java
deleted file mode 100644
index 1ae3054..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/DDLAPIServlet.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed 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 from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.http.servlet;
-
-import java.util.Arrays;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import edu.uci.ics.asterix.aql.base.Statement;
-import edu.uci.ics.asterix.aql.base.Statement.Kind;
-
-public class DDLAPIServlet extends RESTAPIServlet {
-    private static final long serialVersionUID = 1L;
-
-    protected String getQueryParameter(HttpServletRequest request) {
-        return request.getParameter("ddl");
-    }
-
-    protected List<Statement.Kind> getAllowedStatements() {
-        Kind[] statementsArray = { Kind.DATAVERSE_DECL, Kind.DATAVERSE_DROP, Kind.FUNCTION_DECL, Kind.NODEGROUP_DECL,
-                Kind.NODEGROUP_DROP, Kind.TYPE_DECL, Kind.TYPE_DROP, Kind.CREATE_INDEX, Kind.INDEX_DECL,
-                Kind.CREATE_DATAVERSE, Kind.INDEX_DROP, Kind.CREATE_FUNCTION, Kind.FUNCTION_DROP };
-        return Arrays.asList(statementsArray);
-    }
-
-    protected String getErrorMessage() {
-        return "Invalid statement: Non-DDL statement %s to the DDL API.";
-    }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/HyracksProperties.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/HyracksProperties.java
deleted file mode 100644
index c5b532a..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/HyracksProperties.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed 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 from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.http.servlet;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-public class HyracksProperties {
-    private final InputStream is;
-
-    private final Properties properties;
-
-    private static String HYRACKS_IP = "127.0.0.1";
-
-    private static int HYRACKS_PORT = 1098;
-
-    public HyracksProperties() throws IOException {
-        is = HyracksProperties.class.getClassLoader().getResourceAsStream("hyracks-deployment.properties");
-        properties = new Properties();
-        properties.load(is);
-    }
-
-    public String getHyracksIPAddress() {
-        String strIP = properties.getProperty("cc.ip");
-        if (strIP == null) {
-            strIP = HYRACKS_IP;
-        }
-        return strIP;
-    }
-
-    public int getHyracksPort() {
-        String strPort = properties.getProperty("cc.port");
-        int port = HYRACKS_PORT;
-        if (strPort != null) {
-            port = Integer.parseInt(strPort);
-        }
-        return port;
-    }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryAPIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryAPIServlet.java
deleted file mode 100644
index a893bd6..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryAPIServlet.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed 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 from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.http.servlet;
-
-import java.util.Arrays;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import edu.uci.ics.asterix.aql.base.Statement;
-import edu.uci.ics.asterix.aql.base.Statement.Kind;
-
-public class QueryAPIServlet extends RESTAPIServlet {
-    private static final long serialVersionUID = 1L;
-
-    protected String getQueryParameter(HttpServletRequest request) {
-        return request.getParameter("query");
-    }
-
-    protected List<Statement.Kind> getAllowedStatements() {
-        Kind[] statementsArray = { Kind.DATAVERSE_DECL, Kind.QUERY, Kind.SET, Kind.WRITE, Kind.BEGIN_FEED,
-                Kind.CONTROL_FEED };
-        return Arrays.asList(statementsArray);
-    }
-
-    protected String getErrorMessage() {
-        return "Invalid statement: Non-query statement %s to the query API.";
-    }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryResultAPIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryResultAPIServlet.java
deleted file mode 100644
index 2b0aff4..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryResultAPIServlet.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed 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 from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.http.servlet;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.nio.ByteBuffer;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-import edu.uci.ics.asterix.result.ResultReader;
-import edu.uci.ics.asterix.result.ResultUtils;
-import edu.uci.ics.hyracks.api.client.HyracksConnection;
-import edu.uci.ics.hyracks.api.client.IHyracksClientConnection;
-import edu.uci.ics.hyracks.api.dataset.ResultSetId;
-import edu.uci.ics.hyracks.api.job.JobId;
-
-public class QueryResultAPIServlet extends HttpServlet {
-    private static final long serialVersionUID = 1L;
-
-    private static final String HYRACKS_CONNECTION_ATTR = "edu.uci.ics.asterix.HYRACKS_CONNECTION";
-
-    @Override
-    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
-        String strHandle = request.getParameter("handle");
-        PrintWriter out = response.getWriter();
-        response.setContentType("text/html");
-        ServletContext context = getServletContext();
-        IHyracksClientConnection hcc;
-        try {
-            HyracksProperties hp = new HyracksProperties();
-            String strIP = hp.getHyracksIPAddress();
-            int port = hp.getHyracksPort();
-
-            synchronized (context) {
-                hcc = (IHyracksClientConnection) context.getAttribute(HYRACKS_CONNECTION_ATTR);
-                if (hcc == null) {
-                    hcc = new HyracksConnection(strIP, port);
-                    context.setAttribute(HYRACKS_CONNECTION_ATTR, hcc);
-                }
-            }
-            JSONObject handleObj = new JSONObject(strHandle);
-            JSONArray handle = handleObj.getJSONArray("handle");
-            JobId jobId = new JobId(handle.getLong(0));
-            ResultSetId rsId = new ResultSetId(handle.getLong(1));
-            ByteBuffer buffer = ByteBuffer.allocate(ResultReader.FRAME_SIZE);
-            /* TODO(madhusudancs): We need to find a way to JSON serialize default format obtained from
-             * metadataProvider in the AQLTranslator and store it as part of the result handle.
-             */
-            ResultReader resultReader = new ResultReader(hcc);
-            resultReader.open(jobId, rsId);
-            buffer.clear();
-            JSONObject jsonResponse = new JSONObject();
-            JSONArray results = new JSONArray();
-            while (resultReader.read(buffer) > 0) {
-                results.put(ResultUtils.getJSONFromBuffer(buffer, resultReader.getFrameTupleAccessor()));
-            }
-            jsonResponse.put("results", results);
-            out.write(jsonResponse.toString());
-
-        } catch (Exception e) {
-            out.println(e.getMessage());
-            e.printStackTrace(out);
-        }
-    }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryStatusAPIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryStatusAPIServlet.java
deleted file mode 100644
index f36e4e3..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryStatusAPIServlet.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed 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 from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.http.servlet;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-import edu.uci.ics.asterix.result.ResultReader;
-import edu.uci.ics.hyracks.api.client.HyracksConnection;
-import edu.uci.ics.hyracks.api.client.IHyracksClientConnection;
-import edu.uci.ics.hyracks.api.dataset.ResultSetId;
-import edu.uci.ics.hyracks.api.job.JobId;
-
-public class QueryStatusAPIServlet extends HttpServlet {
-    private static final long serialVersionUID = 1L;
-
-    private static final String HYRACKS_CONNECTION_ATTR = "edu.uci.ics.asterix.HYRACKS_CONNECTION";
-
-    @Override
-    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
-        String strHandle = request.getParameter("handle");
-        PrintWriter out = response.getWriter();
-        response.setContentType("text/html");
-        ServletContext context = getServletContext();
-        IHyracksClientConnection hcc;
-        try {
-            HyracksProperties hp = new HyracksProperties();
-            String strIP = hp.getHyracksIPAddress();
-            int port = hp.getHyracksPort();
-
-            synchronized (context) {
-                hcc = (IHyracksClientConnection) context.getAttribute(HYRACKS_CONNECTION_ATTR);
-                if (hcc == null) {
-                    hcc = new HyracksConnection(strIP, port);
-                    context.setAttribute(HYRACKS_CONNECTION_ATTR, hcc);
-                }
-            }
-            JSONObject handleObj = new JSONObject(strHandle);
-            JSONArray handle = handleObj.getJSONArray("handle");
-            JobId jobId = new JobId(handle.getLong(0));
-            ResultSetId rsId = new ResultSetId(handle.getLong(1));
-
-            /* TODO(madhusudancs): We need to find a way to JSON serialize default format obtained from
-             * metadataProvider in the AQLTranslator and store it as part of the result handle.
-             */
-            ResultReader resultReader = new ResultReader(hcc);
-            resultReader.open(jobId, rsId);
-
-            JSONObject jsonResponse = new JSONObject();
-            String status;
-            switch (resultReader.getStatus()) {
-                case RUNNING:
-                    status = "RUNNING";
-                    break;
-                case FAILED:
-                    status = "ERROR";
-                    break;
-                case SUCCESS:
-                    status = "SUCCESS";
-                    break;
-                default:
-                    status = "ERROR";
-                    break;
-            }
-            jsonResponse.put("status", status);
-            out.write(jsonResponse.toString());
-
-        } catch (Exception e) {
-            out.println(e.getMessage());
-            e.printStackTrace(out);
-        }
-    }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/RESTAPIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/RESTAPIServlet.java
deleted file mode 100644
index f0aa3c5..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/RESTAPIServlet.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed 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 from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.http.servlet;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.util.List;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.json.JSONObject;
-
-import edu.uci.ics.asterix.api.common.APIFramework.DisplayFormat;
-import edu.uci.ics.asterix.api.common.SessionConfig;
-import edu.uci.ics.asterix.aql.base.Statement;
-import edu.uci.ics.asterix.aql.base.Statement.Kind;
-import edu.uci.ics.asterix.aql.parser.AQLParser;
-import edu.uci.ics.asterix.aql.parser.ParseException;
-import edu.uci.ics.asterix.aql.translator.AqlTranslator;
-import edu.uci.ics.asterix.metadata.MetadataManager;
-import edu.uci.ics.asterix.result.ResultUtils;
-import edu.uci.ics.hyracks.api.client.HyracksConnection;
-import edu.uci.ics.hyracks.api.client.IHyracksClientConnection;
-
-abstract class RESTAPIServlet extends HttpServlet {
-    private static final long serialVersionUID = 1L;
-
-    private static final String HYRACKS_CONNECTION_ATTR = "edu.uci.ics.asterix.HYRACKS_CONNECTION";
-
-    @Override
-    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
-        PrintWriter out = response.getWriter();
-
-        DisplayFormat format = DisplayFormat.HTML;
-
-        String contentType = request.getContentType();
-
-        if ((contentType == null) || (contentType.equals("text/plain"))) {
-            format = DisplayFormat.TEXT;
-        } else if (contentType.equals("application/json")) {
-            format = DisplayFormat.JSON;
-        }
-
-        String query = getQueryParameter(request);
-        boolean asyncResults = isAsync(request);
-
-        response.setContentType("application/json");
-        ServletContext context = getServletContext();
-        IHyracksClientConnection hcc;
-
-        try {
-            HyracksProperties hp = new HyracksProperties();
-            String strIP = hp.getHyracksIPAddress();
-            int port = hp.getHyracksPort();
-
-            synchronized (context) {
-                hcc = (IHyracksClientConnection) context.getAttribute(HYRACKS_CONNECTION_ATTR);
-                if (hcc == null) {
-                    hcc = new HyracksConnection(strIP, port);
-                    context.setAttribute(HYRACKS_CONNECTION_ATTR, hcc);
-                }
-            }
-
-            AQLParser parser = new AQLParser(query);
-            List<Statement> aqlStatements = parser.Statement();
-            if (checkForbiddenStatements(aqlStatements, out)) {
-                return;
-            }
-            SessionConfig sessionConfig = new SessionConfig(port, true, false, false, false, false, false, true, false);
-
-            MetadataManager.INSTANCE.init();
-
-            AqlTranslator aqlTranslator = new AqlTranslator(aqlStatements, out, sessionConfig, format);
-
-            aqlTranslator.compileAndExecute(hcc, asyncResults);
-
-        } catch (ParseException pe) {
-            StringBuilder errorMessage = new StringBuilder();
-            String message = pe.getMessage();
-            message = message.replace("<", "&lt");
-            message = message.replace(">", "&gt");
-            errorMessage.append("SyntaxError:" + message + "\n");
-            int pos = message.indexOf("line");
-            if (pos > 0) {
-                int columnPos = message.indexOf(",", pos + 1 + "line".length());
-                int lineNo = Integer.parseInt(message.substring(pos + "line".length() + 1, columnPos));
-                String line = query.split("\n")[lineNo - 1];
-                errorMessage.append("==> " + line + "\n");
-            }
-            JSONObject errorResp = ResultUtils.getErrorResponse(2, errorMessage.toString());
-            out.write(errorResp.toString());
-        } catch (Exception e) {
-            StringBuilder errorMessage = new StringBuilder();
-            errorMessage.append(e.getMessage());
-            JSONObject errorResp = ResultUtils.getErrorResponse(99, errorMessage.toString());
-            out.write(errorResp.toString());
-        }
-    }
-
-    private boolean checkForbiddenStatements(List<Statement> aqlStatements, PrintWriter out) {
-        for (Statement st : aqlStatements) {
-            if (!getAllowedStatements().contains(st.getKind())) {
-                JSONObject errorResp = ResultUtils.getErrorResponse(1, String.format(getErrorMessage(), st.getKind()));
-                out.write(errorResp.toString());
-                return true;
-            }
-        }
-        return false;
-    }
-
-    protected boolean isAsync(HttpServletRequest request) {
-        String mode = request.getParameter("mode");
-        boolean asyncResults = false;
-        if (mode != null && mode.equals("asynchronous")) {
-            asyncResults = true;
-        }
-        return asyncResults;
-    }
-
-    protected abstract String getQueryParameter(HttpServletRequest request);
-
-    protected abstract List<Kind> getAllowedStatements();
-
-    protected abstract String getErrorMessage();
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/UpdateAPIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/UpdateAPIServlet.java
deleted file mode 100644
index 7336876..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/UpdateAPIServlet.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2009-2011 by The Regents of the University of California
- * Licensed 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 from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.api.http.servlet;
-
-import java.util.Arrays;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import edu.uci.ics.asterix.aql.base.Statement;
-import edu.uci.ics.asterix.aql.base.Statement.Kind;
-
-public class UpdateAPIServlet extends RESTAPIServlet {
-    private static final long serialVersionUID = 1L;
-
-    protected String getQueryParameter(HttpServletRequest request) {
-        return request.getParameter("statements");
-    }
-
-    protected List<Statement.Kind> getAllowedStatements() {
-        Kind[] statementsArray = { Kind.DATAVERSE_DECL, Kind.DATASET_DECL, Kind.DATASET_DROP, Kind.DELETE, Kind.INSERT,
-                Kind.UPDATE, Kind.DML_CMD_LIST, Kind.LOAD_FROM_FILE, Kind.WRITE_FROM_QUERY_RESULT };
-        return Arrays.asList(statementsArray);
-    }
-
-    protected String getErrorMessage() {
-        return "Invalid statement: Non-Update statement %s to the Update API.";
-    }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/java/AsterixJavaClient.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/java/AsterixJavaClient.java
index fb09299..7e72d94 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/java/AsterixJavaClient.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/java/AsterixJavaClient.java
@@ -52,7 +52,7 @@
         int ch;
         StringBuilder builder = new StringBuilder();
         while ((ch = queryText.read()) != -1) {
-            builder.append((char) ch);
+            builder.append((char)ch);
         }
         AQLParser parser = new AQLParser(builder.toString());
         List<Statement> aqlStatements;
@@ -68,7 +68,7 @@
                 generateBinaryRuntime, printJob);
 
         AqlTranslator aqlTranslator = new AqlTranslator(aqlStatements, writer, pc, DisplayFormat.TEXT);
-        aqlTranslator.compileAndExecute(hcc, false);
+        aqlTranslator.compileAndExecute(hcc);
         writer.flush();
     }
 
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
index d6d9382..66239e2 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
@@ -16,7 +16,6 @@
 
 import java.io.File;
 import java.io.PrintWriter;
-import java.nio.ByteBuffer;
 import java.rmi.RemoteException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -24,15 +23,12 @@
 import java.util.Map;
 
 import org.json.JSONException;
-import org.json.JSONArray;
-import org.json.JSONObject;
 
 import edu.uci.ics.asterix.api.common.APIFramework;
 import edu.uci.ics.asterix.api.common.APIFramework.DisplayFormat;
 import edu.uci.ics.asterix.api.common.Job;
 import edu.uci.ics.asterix.api.common.SessionConfig;
 import edu.uci.ics.asterix.aql.base.Statement;
-import edu.uci.ics.asterix.aql.base.Statement.Kind;
 import edu.uci.ics.asterix.aql.expression.BeginFeedStatement;
 import edu.uci.ics.asterix.aql.expression.ControlFeedStatement;
 import edu.uci.ics.asterix.aql.expression.CreateDataverseStatement;
@@ -68,7 +64,6 @@
 import edu.uci.ics.asterix.file.FeedOperations;
 import edu.uci.ics.asterix.file.IndexOperations;
 import edu.uci.ics.asterix.formats.base.IDataFormat;
-import edu.uci.ics.asterix.formats.nontagged.AqlResultSerializerFactoryProvider;
 import edu.uci.ics.asterix.metadata.IDatasetDetails;
 import edu.uci.ics.asterix.metadata.MetadataException;
 import edu.uci.ics.asterix.metadata.MetadataManager;
@@ -86,8 +81,6 @@
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.types.IAType;
 import edu.uci.ics.asterix.om.types.TypeSignature;
-import edu.uci.ics.asterix.result.ResultUtils;
-import edu.uci.ics.asterix.result.ResultReader;
 import edu.uci.ics.asterix.transaction.management.exception.ACIDException;
 import edu.uci.ics.asterix.transaction.management.service.transaction.TransactionIDFactory;
 import edu.uci.ics.asterix.translator.AbstractAqlTranslator;
@@ -106,10 +99,8 @@
 import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
 import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression.FunctionKind;
 import edu.uci.ics.hyracks.algebricks.data.IAWriterFactory;
-import edu.uci.ics.hyracks.algebricks.data.IResultSerializerFactoryProvider;
 import edu.uci.ics.hyracks.algebricks.runtime.writers.PrinterBasedWriterFactory;
 import edu.uci.ics.hyracks.api.client.IHyracksClientConnection;
-import edu.uci.ics.hyracks.api.dataset.ResultSetId;
 import edu.uci.ics.hyracks.api.io.FileReference;
 import edu.uci.ics.hyracks.api.job.JobId;
 import edu.uci.ics.hyracks.api.job.JobSpecification;
@@ -149,20 +140,18 @@
 
     /**
      * Compiles and submits for execution a list of AQL statements.
-     *
+     * 
      * @param hcc
-     *            A Hyracks client connection that is used to submit a jobspec to Hyracks.
-     * @param asyncResults
-     *            True if the results should be read asynchronously or false if we should wait for results to be read.
-     * @return A List<QueryResult> containing a QueryResult instance corresponding to each submitted query.
+     *            AHyracks client connection that is used to submit a jobspec to
+     *            Hyracks.
+     * @return A List<QueryResult> containing a QueryResult instance
+     *         corresponding to each submitted query.
      * @throws Exception
      */
-    public List<QueryResult> compileAndExecute(IHyracksClientConnection hcc, boolean asyncResults) throws Exception {
-        int resultSetIdCounter = 0;
+    public List<QueryResult> compileAndExecute(IHyracksClientConnection hcc) throws Exception {
         List<QueryResult> executionResult = new ArrayList<QueryResult>();
         FileSplit outputFile = null;
         IAWriterFactory writerFactory = PrinterBasedWriterFactory.INSTANCE;
-        IResultSerializerFactoryProvider resultSerializerFactoryProvider = AqlResultSerializerFactoryProvider.INSTANCE;
         Map<String, String> config = new HashMap<String, String>();
         List<JobSpecification> jobsToExecute = new ArrayList<JobSpecification>();
 
@@ -171,7 +160,6 @@
             MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
             AqlMetadataProvider metadataProvider = new AqlMetadataProvider(mdTxnCtx, activeDefaultDataverse);
             metadataProvider.setWriterFactory(writerFactory);
-            metadataProvider.setResultSerializerFactoryProvider(resultSerializerFactoryProvider);
             metadataProvider.setOutputFile(outputFile);
             metadataProvider.setConfig(config);
             jobsToExecute.clear();
@@ -264,7 +252,6 @@
                     }
 
                     case QUERY: {
-                        metadataProvider.setResultSetId(new ResultSetId(resultSetIdCounter++));
                         executionResult.add(handleQuery(metadataProvider, (Query) stmt, hcc, jobsToExecute));
                         break;
                     }
@@ -288,30 +275,7 @@
             // Following jobs are run under a separate transaction, that is
             // committed/aborted by the JobEventListener
             for (JobSpecification jobspec : jobsToExecute) {
-                JobId jobId = runJob(hcc, jobspec);
-                if (stmt.getKind() == Kind.QUERY) {
-                    JSONObject response = new JSONObject();
-
-                    if (asyncResults) {
-                        JSONArray handle = new JSONArray();
-                        handle.put(jobId.getId());
-                        handle.put(metadataProvider.getResultSetId().getId());
-                        response.put("handle", handle);
-                    } else {
-                        ByteBuffer buffer = ByteBuffer.allocate(ResultReader.FRAME_SIZE);
-                        ResultReader resultReader = new ResultReader(hcc);
-                        resultReader.open(jobId, metadataProvider.getResultSetId());
-                        buffer.clear();
-                        JSONArray results = new JSONArray();
-                        while (resultReader.read(buffer) > 0) {
-                            results.put(ResultUtils.getJSONFromBuffer(buffer, resultReader.getFrameTupleAccessor()));
-                            buffer.clear();
-                        }
-                        response.put("results", results);
-                    }
-                    out.write(response.toString());
-                }
-                hcc.waitForCompletion(jobId);
+                runJob(hcc, jobspec);
             }
         }
         return executionResult;
@@ -429,8 +393,7 @@
         if (dd.getDatasetType() == DatasetType.INTERNAL || dd.getDatasetType() == DatasetType.FEED) {
             Dataverse dataverse = MetadataManager.INSTANCE.getDataverse(metadataProvider.getMetadataTxnContext(),
                     dataverseName);
-            JobId jobId = runJob(hcc, DatasetOperations.createDatasetJobSpec(dataverse, datasetName, metadataProvider));
-            hcc.waitForCompletion(jobId);
+            runJob(hcc, DatasetOperations.createDatasetJobSpec(dataverse, datasetName, metadataProvider));
         }
     }
 
@@ -468,8 +431,7 @@
                     index.getDatasetName(), index.getKeyFieldNames(), index.getGramLength(), index.getIndexType());
             JobSpecification loadIndexJobSpec = IndexOperations
                     .buildSecondaryIndexLoadingJobSpec(cis, metadataProvider);
-            JobId jobId = runJob(hcc, loadIndexJobSpec);
-            hcc.waitForCompletion(jobId);
+            runJob(hcc, loadIndexJobSpec);
         }
     }
 
@@ -702,9 +664,9 @@
         CompiledWriteFromQueryResultStatement clfrqs = new CompiledWriteFromQueryResultStatement(dataverseName, st1
                 .getDatasetName().getValue(), st1.getQuery(), st1.getVarCounter());
 
-        JobSpecification compiled = rewriteCompileQuery(metadataProvider, clfrqs.getQuery(), clfrqs);
-        if (compiled != null) {
-            jobsToExecute.add(compiled);
+        Pair<JobSpecification, FileSplit> compiled = rewriteCompileQuery(metadataProvider, clfrqs.getQuery(), clfrqs);
+        if (compiled.first != null) {
+            jobsToExecute.add(compiled.first);
         }
     }
 
@@ -716,10 +678,9 @@
                 : activeDefaultDataverse.getDataverseName() : stmtInsert.getDataverseName().getValue();
         CompiledInsertStatement clfrqs = new CompiledInsertStatement(dataverseName, stmtInsert.getDatasetName()
                 .getValue(), stmtInsert.getQuery(), stmtInsert.getVarCounter());
-
-        JobSpecification compiled = rewriteCompileQuery(metadataProvider, clfrqs.getQuery(), clfrqs);
-        if (compiled != null) {
-            jobsToExecute.add(compiled);
+        Pair<JobSpecification, FileSplit> compiled = rewriteCompileQuery(metadataProvider, clfrqs.getQuery(), clfrqs);
+        if (compiled.first != null) {
+            jobsToExecute.add(compiled.first);
         }
     }
 
@@ -732,13 +693,13 @@
         CompiledDeleteStatement clfrqs = new CompiledDeleteStatement(stmtDelete.getVariableExpr(), dataverseName,
                 stmtDelete.getDatasetName().getValue(), stmtDelete.getCondition(), stmtDelete.getDieClause(),
                 stmtDelete.getVarCounter(), metadataProvider);
-        JobSpecification compiled = rewriteCompileQuery(metadataProvider, clfrqs.getQuery(), clfrqs);
-        if (compiled != null) {
-            jobsToExecute.add(compiled);
+        Pair<JobSpecification, FileSplit> compiled = rewriteCompileQuery(metadataProvider, clfrqs.getQuery(), clfrqs);
+        if (compiled.first != null) {
+            jobsToExecute.add(compiled.first);
         }
     }
 
-    private JobSpecification rewriteCompileQuery(AqlMetadataProvider metadataProvider, Query query,
+    private Pair<JobSpecification, FileSplit> rewriteCompileQuery(AqlMetadataProvider metadataProvider, Query query,
             ICompiledDmlStatement stmt) throws AsterixException, RemoteException, AlgebricksException, JSONException,
             ACIDException {
 
@@ -754,7 +715,9 @@
         JobSpecification spec = APIFramework.compileQuery(declaredFunctions, metadataProvider, query,
                 reWrittenQuery.second, stmt == null ? null : stmt.getDatasetName(), sessionConfig, out, pdf, stmt);
 
-        return spec;
+        Pair<JobSpecification, FileSplit> compiled = new Pair<JobSpecification, FileSplit>(spec,
+                metadataProvider.getOutputFile());
+        return compiled;
 
     }
 
@@ -778,10 +741,9 @@
         }
         bfs.initialize(metadataProvider.getMetadataTxnContext(), dataset);
         cbfs.setQuery(bfs.getQuery());
-
-        JobSpecification compiled = rewriteCompileQuery(metadataProvider, bfs.getQuery(), cbfs);
-        if (compiled != null) {
-            jobsToExecute.add(compiled);
+        Pair<JobSpecification, FileSplit> compiled = rewriteCompileQuery(metadataProvider, bfs.getQuery(), cbfs);
+        if (compiled.first != null) {
+            jobsToExecute.add(compiled.first);
         }
     }
 
@@ -797,13 +759,12 @@
 
     private QueryResult handleQuery(AqlMetadataProvider metadataProvider, Query query, IHyracksClientConnection hcc,
             List<JobSpecification> jobsToExecute) throws Exception {
-        JobSpecification compiled = rewriteCompileQuery(metadataProvider, query, null);
-        if (compiled != null) {
-            GlobalConfig.ASTERIX_LOGGER.info(compiled.toJSON().toString(1));
-            jobsToExecute.add(compiled);
+        Pair<JobSpecification, FileSplit> compiled = rewriteCompileQuery(metadataProvider, query, null);
+        if (compiled.first != null) {
+            GlobalConfig.ASTERIX_LOGGER.info(compiled.first.toJSON().toString(1));
+            jobsToExecute.add(compiled.first);
         }
-
-        return new QueryResult(query, metadataProvider.getResultSetId());
+        return new QueryResult(query, compiled.second.getLocalFile().getFile().getAbsolutePath());
     }
 
     private void runCreateIndexJob(IHyracksClientConnection hcc, CreateIndexStatement stmtCreateIndex,
@@ -822,8 +783,7 @@
             throw new AsterixException("Failed to create job spec for creating index '"
                     + stmtCreateIndex.getDatasetName() + "." + stmtCreateIndex.getIndexName() + "'");
         }
-        JobId jobId = runJob(hcc, spec);
-        hcc.waitForCompletion(jobId);
+        runJob(hcc, spec);
     }
 
     private void handleCreateNodeGroupStatement(AqlMetadataProvider metadataProvider, Statement stmt,
@@ -846,16 +806,14 @@
         }
     }
 
-    private JobId runJob(IHyracksClientConnection hcc, JobSpecification spec) throws Exception {
-        JobId[] jobIds = executeJobArray(hcc, new Job[] { new Job(spec) }, out, pdf);
-        return jobIds[0];
+    private void runJob(IHyracksClientConnection hcc, JobSpecification spec) throws Exception {
+        executeJobArray(hcc, new Job[] { new Job(spec) }, out, pdf);
     }
 
     private void compileIndexDropStatement(IHyracksClientConnection hcc, String dataverseName, String datasetName,
             String indexName, AqlMetadataProvider metadataProvider) throws Exception {
         CompiledIndexDropStatement cds = new CompiledIndexDropStatement(dataverseName, datasetName, indexName);
-        JobId jobId = runJob(hcc, IndexOperations.buildDropSecondaryIndexJobSpec(cds, metadataProvider));
-        hcc.waitForCompletion(jobId);
+        runJob(hcc, IndexOperations.buildDropSecondaryIndexJobSpec(cds, metadataProvider));
         MetadataManager.INSTANCE.dropIndex(metadataProvider.getMetadataTxnContext(), dataverseName, datasetName,
                 indexName);
     }
@@ -867,24 +825,20 @@
         Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx, dataverseName, datasetName);
         if (ds.getDatasetType() == DatasetType.INTERNAL || ds.getDatasetType() == DatasetType.FEED) {
             JobSpecification[] jobSpecs = DatasetOperations.createDropDatasetJobSpec(cds, metadataProvider);
-            for (JobSpecification spec : jobSpecs) {
-                JobId jobId = runJob(hcc, spec);
-                hcc.waitForCompletion(jobId);
-            }
+            for (JobSpecification spec : jobSpecs)
+                runJob(hcc, spec);
         }
         MetadataManager.INSTANCE.dropDataset(mdTxnCtx, dataverseName, datasetName);
     }
 
-    public JobId[] executeJobArray(IHyracksClientConnection hcc, Job[] jobs, PrintWriter out, DisplayFormat pdf)
+    public void executeJobArray(IHyracksClientConnection hcc, Job[] jobs, PrintWriter out, DisplayFormat pdf)
             throws Exception {
-        JobId[] startedJobIds = new JobId[jobs.length];
         for (int i = 0; i < jobs.length; i++) {
             JobSpecification spec = jobs[i].getJobSpec();
             spec.setMaxReattempts(0);
             JobId jobId = hcc.startJob(GlobalConfig.HYRACKS_APP_NAME, spec);
-            startedJobIds[i] = jobId;
+            hcc.waitForCompletion(jobId);
         }
-        return startedJobIds;
     }
 
     private static IDataFormat getDataFormat(MetadataTransactionContext mdTxnCtx, String dataverseName)
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/QueryResult.java b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/QueryResult.java
index 8d6b35e..0b4a2cf 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/QueryResult.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/QueryResult.java
@@ -16,35 +16,23 @@
 
 import edu.uci.ics.asterix.aql.base.Statement;
 import edu.uci.ics.asterix.aql.expression.Query;
-import edu.uci.ics.hyracks.api.dataset.ResultSetId;
-import edu.uci.ics.hyracks.api.job.JobId;
 
 public class QueryResult {
 
     private final Query query;
+    private final String resultPath;
 
-    private final ResultSetId resultSetId;
-
-    private JobId jobId;
-
-    public QueryResult(Query statement, ResultSetId resultSetId) {
+    public QueryResult(Query statement, String resultPath) {
         this.query = statement;
-        this.resultSetId = resultSetId;
-    }
-
-    public void setJobId(JobId jobId) {
-        this.jobId = jobId;
-    }
-
-    public JobId getJobId() {
-        return jobId;
+        this.resultPath = resultPath;
     }
 
     public Statement getStatement() {
         return query;
     }
 
-    public ResultSetId getResultSetId() {
-        return resultSetId;
+    public String getResultPath() {
+        return resultPath;
     }
+
 }
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java
index 0c25e34..9b29427 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/hyracks/bootstrap/CCBootstrapImpl.java
@@ -23,11 +23,6 @@
 
 import edu.uci.ics.asterix.api.http.servlet.APIServlet;
 import edu.uci.ics.asterix.common.api.AsterixAppContextInfoImpl;
-import edu.uci.ics.asterix.api.http.servlet.DDLAPIServlet;
-import edu.uci.ics.asterix.api.http.servlet.QueryAPIServlet;
-import edu.uci.ics.asterix.api.http.servlet.QueryResultAPIServlet;
-import edu.uci.ics.asterix.api.http.servlet.QueryStatusAPIServlet;
-import edu.uci.ics.asterix.api.http.servlet.UpdateAPIServlet;
 import edu.uci.ics.asterix.common.config.GlobalConfig;
 import edu.uci.ics.asterix.metadata.MetadataManager;
 import edu.uci.ics.asterix.metadata.api.IAsterixStateProxy;
@@ -45,10 +40,7 @@
 
     private static final int DEFAULT_WEB_SERVER_PORT = 19001;
 
-    private static final int DEFAULT_JSON_API_SERVER_PORT = 19101;
-
     private Server webServer;
-    private Server jsonAPIServer;
     private static IAsterixStateProxy proxy;
     private ICCApplicationContext appCtx;
 
@@ -67,10 +59,6 @@
         setupWebServer();
         webServer.start();
 
-        // Setup and start the web interface
-        setupJSONAPIServer();
-        jsonAPIServer.start();
-
         AsterixAppContextInfoImpl.initialize(appCtx);
     }
 
@@ -102,22 +90,4 @@
         webServer.setHandler(context);
         context.addServlet(new ServletHolder(new APIServlet()), "/*");
     }
-
-    private void setupJSONAPIServer() throws Exception {
-        String portStr = System.getProperty(GlobalConfig.JSON_API_SERVER_PORT_PROPERTY);
-        int port = DEFAULT_JSON_API_SERVER_PORT;
-        if (portStr != null) {
-            port = Integer.parseInt(portStr);
-        }
-        jsonAPIServer = new Server(port);
-
-        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
-        context.setContextPath("/");
-        jsonAPIServer.setHandler(context);
-        context.addServlet(new ServletHolder(new QueryAPIServlet()), "/query");
-        context.addServlet(new ServletHolder(new QueryStatusAPIServlet()), "/query/status");
-        context.addServlet(new ServletHolder(new QueryResultAPIServlet()), "/query/result");
-        context.addServlet(new ServletHolder(new UpdateAPIServlet()), "/update");
-        context.addServlet(new ServletHolder(new DDLAPIServlet()), "/ddl");
-    }
-}
+}
\ No newline at end of file
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultFrameTupleAccessor.java b/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultFrameTupleAccessor.java
deleted file mode 100644
index 9d4712b0..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultFrameTupleAccessor.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * Licensed 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 from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.result;
-
-import java.io.DataInputStream;
-import java.nio.ByteBuffer;
-
-import edu.uci.ics.hyracks.api.comm.FrameHelper;
-import edu.uci.ics.hyracks.api.comm.IFrameTupleAccessor;
-import edu.uci.ics.hyracks.dataflow.common.comm.util.ByteBufferInputStream;
-
-public class ResultFrameTupleAccessor implements IFrameTupleAccessor {
-
-    private final int frameSize;
-    private ByteBuffer buffer;
-
-    public ResultFrameTupleAccessor(int frameSize) {
-        this.frameSize = frameSize;
-    }
-
-    @Override
-    public void reset(ByteBuffer buffer) {
-        this.buffer = buffer;
-    }
-
-    @Override
-    public ByteBuffer getBuffer() {
-        return buffer;
-    }
-
-    @Override
-    public int getTupleCount() {
-        return buffer.getInt(FrameHelper.getTupleCountOffset(frameSize));
-    }
-
-    @Override
-    public int getTupleStartOffset(int tupleIndex) {
-        return tupleIndex == 0 ? 0 : buffer.getInt(FrameHelper.getTupleCountOffset(frameSize) - 4 * tupleIndex);
-    }
-
-    @Override
-    public int getTupleEndOffset(int tupleIndex) {
-        return buffer.getInt(FrameHelper.getTupleCountOffset(frameSize) - 4 * (tupleIndex + 1));
-    }
-
-    @Override
-    public int getFieldStartOffset(int tupleIndex, int fIdx) {
-        return fIdx == 0 ? 0 : buffer.getInt(getTupleStartOffset(tupleIndex) + (fIdx - 1) * 4);
-    }
-
-    @Override
-    public int getFieldEndOffset(int tupleIndex, int fIdx) {
-        return buffer.getInt(getTupleStartOffset(tupleIndex) + fIdx * 4);
-    }
-
-    @Override
-    public int getFieldLength(int tupleIndex, int fIdx) {
-        return getFieldEndOffset(tupleIndex, fIdx) - getFieldStartOffset(tupleIndex, fIdx);
-    }
-
-    @Override
-    public int getFieldSlotsLength() {
-        return getFieldCount() * 4;
-    }
-
-    public void prettyPrint() {
-        ByteBufferInputStream bbis = new ByteBufferInputStream();
-        DataInputStream dis = new DataInputStream(bbis);
-        int tc = getTupleCount();
-        System.err.println("TC: " + tc);
-        for (int i = 0; i < tc; ++i) {
-            System.err.print(i + ":(" + getTupleStartOffset(i) + ", " + getTupleEndOffset(i) + ")[");
-
-            bbis.setByteBuffer(buffer, getTupleStartOffset(i));
-            System.err.print(dis);
-
-            System.err.println("]");
-        }
-    }
-
-    @Override
-    public int getFieldCount() {
-        return 1;
-    }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultReader.java b/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultReader.java
deleted file mode 100644
index a366abd..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultReader.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * Licensed 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 from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.result;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-import edu.uci.ics.hyracks.api.client.IHyracksClientConnection;
-import edu.uci.ics.hyracks.api.comm.IFrameTupleAccessor;
-import edu.uci.ics.hyracks.api.dataset.DatasetDirectoryRecord.Status;
-import edu.uci.ics.hyracks.api.dataset.IHyracksDataset;
-import edu.uci.ics.hyracks.api.dataset.ResultSetId;
-import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
-import edu.uci.ics.hyracks.api.job.JobId;
-import edu.uci.ics.hyracks.client.dataset.DatasetClientContext;
-import edu.uci.ics.hyracks.client.dataset.HyracksDataset;
-
-public class ResultReader {
-    private final DatasetClientContext datasetClientCtx;
-
-    private final IHyracksDataset hyracksDataset;
-
-    private IFrameTupleAccessor frameTupleAccessor;
-
-    // Number of parallel result reader buffers
-    private static final int NUM_READERS = 1;
-
-    // 32K buffer size;
-    public static final int FRAME_SIZE = 32768;
-
-    public ResultReader(IHyracksClientConnection hcc) throws Exception {
-        datasetClientCtx = new DatasetClientContext(FRAME_SIZE);
-        hyracksDataset = new HyracksDataset(hcc, datasetClientCtx, NUM_READERS);
-    }
-
-    public void open(JobId jobId, ResultSetId resultSetId) throws IOException, ClassNotFoundException {
-        hyracksDataset.open(jobId, resultSetId);
-
-        frameTupleAccessor = new ResultFrameTupleAccessor(datasetClientCtx.getFrameSize());
-    }
-
-    public Status getStatus() {
-        return hyracksDataset.getResultStatus();
-    }
-
-    public int read(ByteBuffer buffer) throws HyracksDataException {
-        return hyracksDataset.read(buffer);
-    }
-
-    public IFrameTupleAccessor getFrameTupleAccessor() {
-        return frameTupleAccessor;
-    }
-}
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java b/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java
deleted file mode 100644
index e923821..0000000
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/result/ResultUtils.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2009-2010 by The Regents of the University of California
- * Licensed 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 from
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package edu.uci.ics.asterix.result;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import edu.uci.ics.hyracks.api.comm.IFrameTupleAccessor;
-import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
-import edu.uci.ics.hyracks.dataflow.common.comm.util.ByteBufferInputStream;
-
-public class ResultUtils {
-    public static JSONArray getJSONFromBuffer(ByteBuffer buffer, IFrameTupleAccessor fta) throws HyracksDataException {
-        JSONArray resultRecords = new JSONArray();
-        ByteBufferInputStream bbis = new ByteBufferInputStream();
-
-        try {
-            fta.reset(buffer);
-            for (int tIndex = 0; tIndex < fta.getTupleCount(); tIndex++) {
-                int start = fta.getTupleStartOffset(tIndex);
-                int length = fta.getTupleEndOffset(tIndex) - start;
-                bbis.setByteBuffer(buffer, start);
-                byte[] recordBytes = new byte[length];
-                bbis.read(recordBytes, 0, length);
-                resultRecords.put(new String(recordBytes, 0, length));
-            }
-        } finally {
-            try {
-                bbis.close();
-            } catch (IOException e) {
-                throw new HyracksDataException(e);
-            }
-        }
-        return resultRecords;
-    }
-
-    public static JSONObject getErrorResponse(int errorCode, String errorMessage) {
-        JSONObject errorResp = new JSONObject();
-        JSONArray errorArray = new JSONArray();
-        errorArray.put(errorCode);
-        errorArray.put(errorMessage);
-        try {
-            errorResp.put("error-code", errorArray);
-        } catch (JSONException e) {
-            // TODO(madhusudancs): Figure out what to do when JSONException occurs while building the results.
-        }
-        return errorResp;
-    }
-}
diff --git a/asterix-app/src/main/resources/hyracks-deployment.properties b/asterix-app/src/main/resources/hyracks-deployment.properties
index a333d38..a8a943e 100644
--- a/asterix-app/src/main/resources/hyracks-deployment.properties
+++ b/asterix-app/src/main/resources/hyracks-deployment.properties
@@ -1,4 +1,2 @@
 cc.bootstrap.class=edu.uci.ics.asterix.hyracks.bootstrap.CCBootstrapImpl
-nc.bootstrap.class=edu.uci.ics.asterix.hyracks.bootstrap.NCBootstrapImpl
-cc.ip=127.0.0.1
-cc.port=1098
+nc.bootstrap.class=edu.uci.ics.asterix.hyracks.bootstrap.NCBootstrapImpl
\ No newline at end of file